Skip to content

Commit

Permalink
Fixed headings hierarchy updates - fixes #3
Browse files Browse the repository at this point in the history
The hierarchy now updates whenever the DOM changes
  • Loading branch information
felixgirault committed Jun 18, 2021
1 parent eacf91b commit 55a2f8b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/helpers/components/HeadingsHierarchy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import renderIf from 'render-if';
*
*/
const HeadingsHierarchy = ({items}) => (
<div className="HeadingsHierarchy Widget">
<div className="HeadingsHierarchy Widget" aria-live="polite">
<h4 className="HeadingsHierarchy-title">
<FormattedMessage id="HeadingsHierarchy.title" />
</h4>
Expand Down
27 changes: 23 additions & 4 deletions src/helpers/helpers/headingsHierarchy.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
import {debounce} from 'lodash';
import {sendMessage} from '../../common/api/runtime';
import getHeadingsHierarchy from '../api/getHeadingsHierarchy';
import {GET} from '../actions/headingsHierarchy';
import HeadingsHierarchyContainer from '../components/HeadingsHierarchyContainer';



/**
*
*/
const sendHierarchy = () =>
sendMessage({
type: GET,
payload: getHeadingsHierarchy()
});

/**
*
*/
const observer = new MutationObserver(
debounce(sendHierarchy, 300)
);

/**
*
*/
Expand All @@ -23,13 +40,15 @@ export const describe = (intl) =>
*
*/
export const apply = () => {
sendMessage({
type: GET,
payload: getHeadingsHierarchy()
sendHierarchy();
observer.observe(document.body, {
childList: true
});
};

/**
*
*/
export const revert = () => {};
export const revert = () => {
observer.disconnect();
};

0 comments on commit 55a2f8b

Please sign in to comment.