@wordpress/annotations 2.39.0 → 2.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/block/index.js +0 -5
  3. package/build/block/index.js.map +1 -1
  4. package/build/format/annotation.js +9 -29
  5. package/build/format/annotation.js.map +1 -1
  6. package/build/format/index.js +1 -2
  7. package/build/format/index.js.map +1 -1
  8. package/build/index.js +0 -3
  9. package/build/index.js.map +1 -1
  10. package/build/store/actions.js +3 -10
  11. package/build/store/actions.js.map +1 -1
  12. package/build/store/constants.js +0 -1
  13. package/build/store/constants.js.map +1 -1
  14. package/build/store/index.js +0 -9
  15. package/build/store/index.js.map +1 -1
  16. package/build/store/reducer.js +9 -19
  17. package/build/store/reducer.js.map +1 -1
  18. package/build/store/selectors.js +5 -17
  19. package/build/store/selectors.js.map +1 -1
  20. package/build-module/block/index.js +1 -4
  21. package/build-module/block/index.js.map +1 -1
  22. package/build-module/format/annotation.js +9 -25
  23. package/build-module/format/annotation.js.map +1 -1
  24. package/build-module/format/index.js +1 -1
  25. package/build-module/format/index.js.map +1 -1
  26. package/build-module/index.js.map +1 -1
  27. package/build-module/store/actions.js +4 -6
  28. package/build-module/store/actions.js.map +1 -1
  29. package/build-module/store/constants.js.map +1 -1
  30. package/build-module/store/index.js +3 -3
  31. package/build-module/store/index.js.map +1 -1
  32. package/build-module/store/reducer.js +9 -17
  33. package/build-module/store/reducer.js.map +1 -1
  34. package/build-module/store/selectors.js +6 -10
  35. package/build-module/store/selectors.js.map +1 -1
  36. package/package.json +9 -6
@@ -1,16 +1,13 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.__experimentalGetAllAnnotationsForBlock = __experimentalGetAllAnnotationsForBlock;
9
8
  exports.__experimentalGetAnnotations = __experimentalGetAnnotations;
10
9
  exports.__experimentalGetAnnotationsForRichText = exports.__experimentalGetAnnotationsForBlock = void 0;
11
-
12
10
  var _rememo = _interopRequireDefault(require("rememo"));
13
-
14
11
  /**
15
12
  * External dependencies
16
13
  */
@@ -25,6 +22,7 @@ var _rememo = _interopRequireDefault(require("rememo"));
25
22
  * @type {Array}
26
23
  */
27
24
  const EMPTY_ARRAY = [];
25
+
28
26
  /**
29
27
  * Returns the annotations for a specific client ID.
30
28
  *
@@ -33,26 +31,21 @@ const EMPTY_ARRAY = [];
33
31
  *
34
32
  * @return {Array} The annotations applicable to this block.
35
33
  */
36
-
37
34
  const __experimentalGetAnnotationsForBlock = (0, _rememo.default)((state, blockClientId) => {
38
35
  var _state$blockClientId;
39
-
40
36
  return ((_state$blockClientId = state?.[blockClientId]) !== null && _state$blockClientId !== void 0 ? _state$blockClientId : []).filter(annotation => {
41
37
  return annotation.selector === 'block';
42
38
  });
43
39
  }, (state, blockClientId) => {
44
40
  var _state$blockClientId2;
45
-
46
41
  return [(_state$blockClientId2 = state?.[blockClientId]) !== null && _state$blockClientId2 !== void 0 ? _state$blockClientId2 : EMPTY_ARRAY];
47
42
  });
48
-
49
43
  exports.__experimentalGetAnnotationsForBlock = __experimentalGetAnnotationsForBlock;
50
-
51
44
  function __experimentalGetAllAnnotationsForBlock(state, blockClientId) {
52
45
  var _state$blockClientId3;
53
-
54
46
  return (_state$blockClientId3 = state?.[blockClientId]) !== null && _state$blockClientId3 !== void 0 ? _state$blockClientId3 : EMPTY_ARRAY;
55
47
  }
48
+
56
49
  /**
57
50
  * Returns the annotations that apply to the given RichText instance.
58
51
  *
@@ -65,11 +58,8 @@ function __experimentalGetAllAnnotationsForBlock(state, blockClientId) {
65
58
  * @param {string} richTextIdentifier Unique identifier that identifies the given RichText.
66
59
  * @return {Array} All the annotations relevant for the `RichText`.
67
60
  */
68
-
69
-
70
61
  const __experimentalGetAnnotationsForRichText = (0, _rememo.default)((state, blockClientId, richTextIdentifier) => {
71
62
  var _state$blockClientId4;
72
-
73
63
  return ((_state$blockClientId4 = state?.[blockClientId]) !== null && _state$blockClientId4 !== void 0 ? _state$blockClientId4 : []).filter(annotation => {
74
64
  return annotation.selector === 'range' && richTextIdentifier === annotation.richTextIdentifier;
75
65
  }).map(annotation => {
@@ -77,25 +67,23 @@ const __experimentalGetAnnotationsForRichText = (0, _rememo.default)((state, blo
77
67
  range,
78
68
  ...other
79
69
  } = annotation;
80
- return { ...range,
70
+ return {
71
+ ...range,
81
72
  ...other
82
73
  };
83
74
  });
84
75
  }, (state, blockClientId) => {
85
76
  var _state$blockClientId5;
86
-
87
77
  return [(_state$blockClientId5 = state?.[blockClientId]) !== null && _state$blockClientId5 !== void 0 ? _state$blockClientId5 : EMPTY_ARRAY];
88
78
  });
79
+
89
80
  /**
90
81
  * Returns all annotations in the editor state.
91
82
  *
92
83
  * @param {Object} state Editor state.
93
84
  * @return {Array} All annotations currently applied.
94
85
  */
95
-
96
-
97
86
  exports.__experimentalGetAnnotationsForRichText = __experimentalGetAnnotationsForRichText;
98
-
99
87
  function __experimentalGetAnnotations(state) {
100
88
  return Object.values(state).flat();
101
89
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/annotations/src/store/selectors.js"],"names":["EMPTY_ARRAY","__experimentalGetAnnotationsForBlock","state","blockClientId","filter","annotation","selector","__experimentalGetAllAnnotationsForBlock","__experimentalGetAnnotationsForRichText","richTextIdentifier","map","range","other","__experimentalGetAnnotations","Object","values","flat"],"mappings":";;;;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,WAAW,GAAG,EAApB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,MAAMC,oCAAoC,GAAG,qBACnD,CAAEC,KAAF,EAASC,aAAT,KAA4B;AAAA;;AAC3B,SAAO,yBAAED,KAAK,GAAIC,aAAJ,CAAP,uEAA8B,EAA9B,E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Shared reference to an empty array for cases where it is important to avoid\n * returning a new array reference on every invocation, as in a connected or\n * other pure component which performs `shouldComponentUpdate` check on props.\n * This should be used as a last resort, since the normalized data should be\n * maintained by the reducer result in state.\n *\n * @type {Array}\n */\nconst EMPTY_ARRAY = [];\n\n/**\n * Returns the annotations for a specific client ID.\n *\n * @param {Object} state Editor state.\n * @param {string} clientId The ID of the block to get the annotations for.\n *\n * @return {Array} The annotations applicable to this block.\n */\nexport const __experimentalGetAnnotationsForBlock = createSelector(\n\t( state, blockClientId ) => {\n\t\treturn ( state?.[ blockClientId ] ?? [] ).filter( ( annotation ) => {\n\t\t\treturn annotation.selector === 'block';\n\t\t} );\n\t},\n\t( state, blockClientId ) => [ state?.[ blockClientId ] ?? EMPTY_ARRAY ]\n);\n\nexport function __experimentalGetAllAnnotationsForBlock(\n\tstate,\n\tblockClientId\n) {\n\treturn state?.[ blockClientId ] ?? EMPTY_ARRAY;\n}\n\n/**\n * Returns the annotations that apply to the given RichText instance.\n *\n * Both a blockClientId and a richTextIdentifier are required. This is because\n * a block might have multiple `RichText` components. This does mean that every\n * block needs to implement annotations itself.\n *\n * @param {Object} state Editor state.\n * @param {string} blockClientId The client ID for the block.\n * @param {string} richTextIdentifier Unique identifier that identifies the given RichText.\n * @return {Array} All the annotations relevant for the `RichText`.\n */\nexport const __experimentalGetAnnotationsForRichText = createSelector(\n\t( state, blockClientId, richTextIdentifier ) => {\n\t\treturn ( state?.[ blockClientId ] ?? [] )\n\t\t\t.filter( ( annotation ) => {\n\t\t\t\treturn (\n\t\t\t\t\tannotation.selector === 'range' &&\n\t\t\t\t\trichTextIdentifier === annotation.richTextIdentifier\n\t\t\t\t);\n\t\t\t} )\n\t\t\t.map( ( annotation ) => {\n\t\t\t\tconst { range, ...other } = annotation;\n\n\t\t\t\treturn {\n\t\t\t\t\t...range,\n\t\t\t\t\t...other,\n\t\t\t\t};\n\t\t\t} );\n\t},\n\t( state, blockClientId ) => [ state?.[ blockClientId ] ?? EMPTY_ARRAY ]\n);\n\n/**\n * Returns all annotations in the editor state.\n *\n * @param {Object} state Editor state.\n * @return {Array} All annotations currently applied.\n */\nexport function __experimentalGetAnnotations( state ) {\n\treturn Object.values( state ).flat();\n}\n"]}
1
+ {"version":3,"names":["_rememo","_interopRequireDefault","require","EMPTY_ARRAY","__experimentalGetAnnotationsForBlock","createSelector","state","blockClientId","_state$blockClientId","filter","annotation","selector","_state$blockClientId2","exports","__experimentalGetAllAnnotationsForBlock","_state$blockClientId3","__experimentalGetAnnotationsForRichText","richTextIdentifier","_state$blockClientId4","map","range","other","_state$blockClientId5","__experimentalGetAnnotations","Object","values","flat"],"sources":["@wordpress/annotations/src/store/selectors.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport createSelector from 'rememo';\n\n/**\n * Shared reference to an empty array for cases where it is important to avoid\n * returning a new array reference on every invocation, as in a connected or\n * other pure component which performs `shouldComponentUpdate` check on props.\n * This should be used as a last resort, since the normalized data should be\n * maintained by the reducer result in state.\n *\n * @type {Array}\n */\nconst EMPTY_ARRAY = [];\n\n/**\n * Returns the annotations for a specific client ID.\n *\n * @param {Object} state Editor state.\n * @param {string} clientId The ID of the block to get the annotations for.\n *\n * @return {Array} The annotations applicable to this block.\n */\nexport const __experimentalGetAnnotationsForBlock = createSelector(\n\t( state, blockClientId ) => {\n\t\treturn ( state?.[ blockClientId ] ?? [] ).filter( ( annotation ) => {\n\t\t\treturn annotation.selector === 'block';\n\t\t} );\n\t},\n\t( state, blockClientId ) => [ state?.[ blockClientId ] ?? EMPTY_ARRAY ]\n);\n\nexport function __experimentalGetAllAnnotationsForBlock(\n\tstate,\n\tblockClientId\n) {\n\treturn state?.[ blockClientId ] ?? EMPTY_ARRAY;\n}\n\n/**\n * Returns the annotations that apply to the given RichText instance.\n *\n * Both a blockClientId and a richTextIdentifier are required. This is because\n * a block might have multiple `RichText` components. This does mean that every\n * block needs to implement annotations itself.\n *\n * @param {Object} state Editor state.\n * @param {string} blockClientId The client ID for the block.\n * @param {string} richTextIdentifier Unique identifier that identifies the given RichText.\n * @return {Array} All the annotations relevant for the `RichText`.\n */\nexport const __experimentalGetAnnotationsForRichText = createSelector(\n\t( state, blockClientId, richTextIdentifier ) => {\n\t\treturn ( state?.[ blockClientId ] ?? [] )\n\t\t\t.filter( ( annotation ) => {\n\t\t\t\treturn (\n\t\t\t\t\tannotation.selector === 'range' &&\n\t\t\t\t\trichTextIdentifier === annotation.richTextIdentifier\n\t\t\t\t);\n\t\t\t} )\n\t\t\t.map( ( annotation ) => {\n\t\t\t\tconst { range, ...other } = annotation;\n\n\t\t\t\treturn {\n\t\t\t\t\t...range,\n\t\t\t\t\t...other,\n\t\t\t\t};\n\t\t\t} );\n\t},\n\t( state, blockClientId ) => [ state?.[ blockClientId ] ?? EMPTY_ARRAY ]\n);\n\n/**\n * Returns all annotations in the editor state.\n *\n * @param {Object} state Editor state.\n * @return {Array} All annotations currently applied.\n */\nexport function __experimentalGetAnnotations( state ) {\n\treturn Object.values( state ).flat();\n}\n"],"mappings":";;;;;;;;;AAGA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAW,GAAG,EAAE;;AAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,oCAAoC,GAAG,IAAAC,eAAc,EACjE,CAAEC,KAAK,EAAEC,aAAa,KAAM;EAAA,IAAAC,oBAAA;EAC3B,OAAO,EAAAA,oBAAA,GAAEF,KAAK,GAAIC,aAAa,CAAE,cAAAC,oBAAA,cAAAA,oBAAA,GAAI,EAAE,EAAGC,MAAM,CAAIC,UAAU,IAAM;IACnE,OAAOA,UAAU,CAACC,QAAQ,KAAK,OAAO;EACvC,CAAE,CAAC;AACJ,CAAC,EACD,CAAEL,KAAK,EAAEC,aAAa;EAAA,IAAAK,qBAAA;EAAA,OAAM,EAAAA,qBAAA,GAAEN,KAAK,GAAIC,aAAa,C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ACoB,IAAI,CAAC,CAAC;AACrC"}
@@ -3,10 +3,10 @@
3
3
  */
4
4
  import { addFilter } from '@wordpress/hooks';
5
5
  import { withSelect } from '@wordpress/data';
6
+
6
7
  /**
7
8
  * Internal dependencies
8
9
  */
9
-
10
10
  import { STORE_NAME } from '../store/constants';
11
11
  /**
12
12
  * Adds annotation className to the block-list-block component.
@@ -14,14 +14,12 @@ import { STORE_NAME } from '../store/constants';
14
14
  * @param {Object} OriginalComponent The original BlockListBlock component.
15
15
  * @return {Object} The enhanced component.
16
16
  */
17
-
18
17
  const addAnnotationClassName = OriginalComponent => {
19
18
  return withSelect((select, {
20
19
  clientId,
21
20
  className
22
21
  }) => {
23
22
  const annotations = select(STORE_NAME).__experimentalGetAnnotationsForBlock(clientId);
24
-
25
23
  return {
26
24
  className: annotations.map(annotation => {
27
25
  return 'is-annotated-by-' + annotation.source;
@@ -29,6 +27,5 @@ const addAnnotationClassName = OriginalComponent => {
29
27
  };
30
28
  })(OriginalComponent);
31
29
  };
32
-
33
30
  addFilter('editor.BlockListBlock', 'core/annotations', addAnnotationClassName);
34
31
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/annotations/src/block/index.js"],"names":["addFilter","withSelect","STORE_NAME","addAnnotationClassName","OriginalComponent","select","clientId","className","annotations","__experimentalGetAnnotationsForBlock","map","annotation","source","concat","filter","Boolean","join"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,kBAA1B;AACA,SAASC,UAAT,QAA2B,iBAA3B;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,oBAA3B;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,sBAAsB,GAAKC,iBAAF,IAAyB;AACvD,SAAOH,UAAU,CAAE,CAAEI,MAAF,EAAU;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,GAAV,KAAuC;AACzD,UAAMC,WAAW,GAChBH,MAAM,CAAEH,UAAF,CAAN,CAAqBO,oCAArB,CACCH,QADD,CADD;;AAKA,WAAO;AACNC,MAAAA,SAAS,EAAEC,WAAW,CACpBE,GADS,CACFC,UAAF,IAAkB;AACvB,eAAO,qBAAqBA,UAAU,CAACC,MAAvC;AACA,OAHS,EAITC,MAJS,CAIDN,SAJC,EAKTO,MALS,CAKDC,OALC,EAMTC,IANS,CAMH,GANG;AADL,KAAP;AASA,GAfgB,CAAV,CAeFZ,iBAfE,CAAP;AAgBA,CAjBD;;AAmBAJ,SAAS,CACR,uBADQ,EAER,kBAFQ,EAGRG,sBAHQ,CAAT","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { withSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../store/constants';\n/**\n * Adds annotation className to the block-list-block component.\n *\n * @param {Object} OriginalComponent The original BlockListBlock component.\n * @return {Object} The enhanced component.\n */\nconst addAnnotationClassName = ( OriginalComponent ) => {\n\treturn withSelect( ( select, { clientId, className } ) => {\n\t\tconst annotations =\n\t\t\tselect( STORE_NAME ).__experimentalGetAnnotationsForBlock(\n\t\t\t\tclientId\n\t\t\t);\n\n\t\treturn {\n\t\t\tclassName: annotations\n\t\t\t\t.map( ( annotation ) => {\n\t\t\t\t\treturn 'is-annotated-by-' + annotation.source;\n\t\t\t\t} )\n\t\t\t\t.concat( className )\n\t\t\t\t.filter( Boolean )\n\t\t\t\t.join( ' ' ),\n\t\t};\n\t} )( OriginalComponent );\n};\n\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/annotations',\n\taddAnnotationClassName\n);\n"]}
1
+ {"version":3,"names":["addFilter","withSelect","STORE_NAME","addAnnotationClassName","OriginalComponent","select","clientId","className","annotations","__experimentalGetAnnotationsForBlock","map","annotation","source","concat","filter","Boolean","join"],"sources":["@wordpress/annotations/src/block/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { withSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../store/constants';\n/**\n * Adds annotation className to the block-list-block component.\n *\n * @param {Object} OriginalComponent The original BlockListBlock component.\n * @return {Object} The enhanced component.\n */\nconst addAnnotationClassName = ( OriginalComponent ) => {\n\treturn withSelect( ( select, { clientId, className } ) => {\n\t\tconst annotations =\n\t\t\tselect( STORE_NAME ).__experimentalGetAnnotationsForBlock(\n\t\t\t\tclientId\n\t\t\t);\n\n\t\treturn {\n\t\t\tclassName: annotations\n\t\t\t\t.map( ( annotation ) => {\n\t\t\t\t\treturn 'is-annotated-by-' + annotation.source;\n\t\t\t\t} )\n\t\t\t\t.concat( className )\n\t\t\t\t.filter( Boolean )\n\t\t\t\t.join( ' ' ),\n\t\t};\n\t} )( OriginalComponent );\n};\n\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/annotations',\n\taddAnnotationClassName\n);\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,UAAU,QAAQ,iBAAiB;;AAE5C;AACA;AACA;AACA,SAASC,UAAU,QAAQ,oBAAoB;AAC/C;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,sBAAsB,GAAKC,iBAAiB,IAAM;EACvD,OAAOH,UAAU,CAAE,CAAEI,MAAM,EAAE;IAAEC,QAAQ;IAAEC;EAAU,CAAC,KAAM;IACzD,MAAMC,WAAW,GAChBH,MAAM,CAAEH,UAAW,CAAC,CAACO,oCAAoC,CACxDH,QACD,CAAC;IAEF,OAAO;MACNC,SAAS,EAAEC,WAAW,CACpBE,GAAG,CAAIC,UAAU,IAAM;QACvB,OAAO,kBAAkB,GAAGA,UAAU,CAACC,MAAM;MAC9C,CAAE,CAAC,CACFC,MAAM,CAAEN,SAAU,CAAC,CACnBO,MAAM,CAAEC,OAAQ,CAAC,CACjBC,IAAI,CAAE,GAAI;IACb,CAAC;EACF,CAAE,CAAC,CAAEZ,iBAAkB,CAAC;AACzB,CAAC;AAEDJ,SAAS,CACR,uBAAuB,EACvB,kBAAkB,EAClBG,sBACD,CAAC"}
@@ -8,8 +8,8 @@ const ANNOTATION_ATTRIBUTE_PREFIX = 'annotation-text-';
8
8
  /**
9
9
  * Internal dependencies
10
10
  */
11
-
12
11
  import { STORE_NAME } from '../store/constants';
12
+
13
13
  /**
14
14
  * Applies given annotations to the given record.
15
15
  *
@@ -17,22 +17,18 @@ import { STORE_NAME } from '../store/constants';
17
17
  * @param {Array} annotations The annotation to apply.
18
18
  * @return {Object} A record with the annotations applied.
19
19
  */
20
-
21
20
  export function applyAnnotations(record, annotations = []) {
22
21
  annotations.forEach(annotation => {
23
22
  let {
24
23
  start,
25
24
  end
26
25
  } = annotation;
27
-
28
26
  if (start > record.text.length) {
29
27
  start = record.text.length;
30
28
  }
31
-
32
29
  if (end > record.text.length) {
33
30
  end = record.text.length;
34
31
  }
35
-
36
32
  const className = ANNOTATION_ATTRIBUTE_PREFIX + annotation.source;
37
33
  const id = ANNOTATION_ATTRIBUTE_PREFIX + annotation.id;
38
34
  record = applyFormat(record, {
@@ -45,23 +41,23 @@ export function applyAnnotations(record, annotations = []) {
45
41
  });
46
42
  return record;
47
43
  }
44
+
48
45
  /**
49
46
  * Removes annotations from the given record.
50
47
  *
51
48
  * @param {Object} record Record to remove annotations from.
52
49
  * @return {Object} The cleaned record.
53
50
  */
54
-
55
51
  export function removeAnnotations(record) {
56
52
  return removeFormat(record, 'core/annotation', 0, record.text.length);
57
53
  }
54
+
58
55
  /**
59
56
  * Retrieves the positions of annotations inside an array of formats.
60
57
  *
61
58
  * @param {Array} formats Formats with annotations in there.
62
59
  * @return {Object} ID keyed positions of annotations.
63
60
  */
64
-
65
61
  function retrieveAnnotationPositions(formats) {
66
62
  const positions = {};
67
63
  formats.forEach((characterFormats, i) => {
@@ -72,21 +68,21 @@ function retrieveAnnotationPositions(formats) {
72
68
  id
73
69
  } = format.attributes;
74
70
  id = id.replace(ANNOTATION_ATTRIBUTE_PREFIX, '');
75
-
76
71
  if (!positions.hasOwnProperty(id)) {
77
72
  positions[id] = {
78
73
  start: i
79
74
  };
80
- } // Annotations refer to positions between characters.
75
+ }
76
+
77
+ // Annotations refer to positions between characters.
81
78
  // Formats refer to the character themselves.
82
79
  // So we need to adjust for that here.
83
-
84
-
85
80
  positions[id].end = i + 1;
86
81
  });
87
82
  });
88
83
  return positions;
89
84
  }
85
+
90
86
  /**
91
87
  * Updates annotations in the state based on positions retrieved from RichText.
92
88
  *
@@ -96,33 +92,28 @@ function retrieveAnnotationPositions(formats) {
96
92
  * @param {Function} actions.removeAnnotation Function to remove an annotation from the state.
97
93
  * @param {Function} actions.updateAnnotationRange Function to update an annotation range in the state.
98
94
  */
99
-
100
-
101
95
  function updateAnnotationsWithPositions(annotations, positions, {
102
96
  removeAnnotation,
103
97
  updateAnnotationRange
104
98
  }) {
105
99
  annotations.forEach(currentAnnotation => {
106
- const position = positions[currentAnnotation.id]; // If we cannot find an annotation, delete it.
107
-
100
+ const position = positions[currentAnnotation.id];
101
+ // If we cannot find an annotation, delete it.
108
102
  if (!position) {
109
103
  // Apparently the annotation has been removed, so remove it from the state:
110
104
  // Remove...
111
105
  removeAnnotation(currentAnnotation.id);
112
106
  return;
113
107
  }
114
-
115
108
  const {
116
109
  start,
117
110
  end
118
111
  } = currentAnnotation;
119
-
120
112
  if (start !== position.start || end !== position.end) {
121
113
  updateAnnotationRange(currentAnnotation.id, position.start, position.end);
122
114
  }
123
115
  });
124
116
  }
125
-
126
117
  export const annotation = {
127
118
  name: FORMAT_NAME,
128
119
  title: __('Annotation'),
@@ -132,11 +123,9 @@ export const annotation = {
132
123
  className: 'class',
133
124
  id: 'id'
134
125
  },
135
-
136
126
  edit() {
137
127
  return null;
138
128
  },
139
-
140
129
  __experimentalGetPropsForEditableTreePreparation(select, {
141
130
  richTextIdentifier,
142
131
  blockClientId
@@ -145,7 +134,6 @@ export const annotation = {
145
134
  annotations: select(STORE_NAME).__experimentalGetAnnotationsForRichText(blockClientId, richTextIdentifier)
146
135
  };
147
136
  },
148
-
149
137
  __experimentalCreatePrepareEditableTree({
150
138
  annotations
151
139
  }) {
@@ -153,7 +141,6 @@ export const annotation = {
153
141
  if (annotations.length === 0) {
154
142
  return formats;
155
143
  }
156
-
157
144
  let record = {
158
145
  formats,
159
146
  text
@@ -162,14 +149,12 @@ export const annotation = {
162
149
  return record.formats;
163
150
  };
164
151
  },
165
-
166
152
  __experimentalGetPropsForEditableTreeChangeHandler(dispatch) {
167
153
  return {
168
154
  removeAnnotation: dispatch(STORE_NAME).__experimentalRemoveAnnotation,
169
155
  updateAnnotationRange: dispatch(STORE_NAME).__experimentalUpdateAnnotationRange
170
156
  };
171
157
  },
172
-
173
158
  __experimentalCreateOnChangeEditableValue(props) {
174
159
  return formats => {
175
160
  const positions = retrieveAnnotationPositions(formats);
@@ -184,6 +169,5 @@ export const annotation = {
184
169
  });
185
170
  };
186
171
  }
187
-
188
172
  };
189
173
  //# sourceMappingURL=annotation.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/annotations/src/format/annotation.js"],"names":["__","applyFormat","removeFormat","FORMAT_NAME","ANNOTATION_ATTRIBUTE_PREFIX","STORE_NAME","applyAnnotations","record","annotations","forEach","annotation","start","end","text","length","className","source","id","type","attributes","removeAnnotations","retrieveAnnotationPositions","formats","positions","characterFormats","i","filter","format","replace","hasOwnProperty","updateAnnotationsWithPositions","removeAnnotation","updateAnnotationRange","currentAnnotation","position","name","title","tagName","edit","__experimentalGetPropsForEditableTreePreparation","select","richTextIdentifier","blockClientId","__experimentalGetAnnotationsForRichText","__experimentalCreatePrepareEditableTree","__experimentalGetPropsForEditableTreeChangeHandler","dispatch","__experimentalRemoveAnnotation","__experimentalUpdateAnnotationRange","__experimentalCreateOnChangeEditableValue","props"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,WAAT,EAAsBC,YAAtB,QAA0C,sBAA1C;AAEA,MAAMC,WAAW,GAAG,iBA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;;AAoCzBuB,EAAAA,kDAAkD,CAAEC,QAAF,EAAa;AAC9D,WAAO;AACNf,MAAAA,gBAAgB,EACfe,QAAQ,CAAEzC,UAAF,CAAR,CAAuB0C,8BAFlB;AAGNf,MAAAA,qBAAqB,EACpBc,QAAQ,CAAEzC,UAAF,CAAR,CAAuB2C;AAJlB,KAAP;AAMA,GA3CwB;;AA4CzBC,EAAAA,yCAAyC,CAAEC,KAAF,EAAU;AAClD,WAAS5B,OAAF,IAAe;AACrB,YAAMC,SAAS,GAAGF,2BAA2B,CAAEC,OAAF,CAA7C;AACA,YAAM;AAAES,QAAAA,gBAAF;AAAoBC,QAAAA,qBAApB;AAA2CxB,QAAAA;AAA3C,UACL0C,KADD;AAGApB,MAAAA,8BAA8B,CAAEtB,WAAF,EAAee,SAAf,EAA0B;AACvDQ,QAAAA,gBADuD;AAEvDC,QAAAA;AAFuD,OAA1B,CAA9B;AAIA,KATD;AAUA;;AAvDwB,CAAnB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { applyFormat, removeFormat } from '@wordpress/rich-text';\n\nconst FORMAT_NAME = 'core/annotation';\n\nconst ANNOTATION_ATTRIBUTE_PREFIX = 'annotation-text-';\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../store/constants';\n\n/**\n * Applies given annotations to the given record.\n *\n * @param {Object} record The record to apply annotations to.\n * @param {Array} annotations The annotation to apply.\n * @return {Object} A record with the annotations applied.\n */\nexport function applyAnnotations( record, annotations = [] ) {\n\tannotations.forEach( ( annotation ) => {\n\t\tlet { start, end } = annotation;\n\n\t\tif ( start > record.text.length ) {\n\t\t\tstart = record.text.length;\n\t\t}\n\n\t\tif ( end > record.text.length ) {\n\t\t\tend = record.text.length;\n\t\t}\n\n\t\tconst className = ANNOTATION_ATTRIBUTE_PREFIX + annotation.source;\n\t\tconst id = ANNOTATION_ATTRIBUTE_PREFIX + annotation.id;\n\n\t\trecord = applyFormat(\n\t\t\trecord,\n\t\t\t{\n\t\t\t\ttype: FORMAT_NAME,\n\t\t\t\tattributes: {\n\t\t\t\t\tclassName,\n\t\t\t\t\tid,\n\t\t\t\t},\n\t\t\t},\n\t\t\tstart,\n\t\t\tend\n\t\t);\n\t} );\n\n\treturn record;\n}\n\n/**\n * Removes annotations from the given record.\n *\n * @param {Object} record Record to remove annotations from.\n * @return {Object} The cleaned record.\n */\nexport function removeAnnotations( record ) {\n\treturn removeFormat( record, 'core/annotation', 0, record.text.length );\n}\n\n/**\n * Retrieves the positions of annotations inside an array of formats.\n *\n * @param {Array} formats Formats with annotations in there.\n * @return {Object} ID keyed positions of annotations.\n */\nfunction retrieveAnnotationPositions( formats ) {\n\tconst positions = {};\n\n\tformats.forEach( ( characterFormats, i ) => {\n\t\tcharacterFormats = characterFormats || [];\n\t\tcharacterFormats = characterFormats.filter(\n\t\t\t( format ) => format.type === FORMAT_NAME\n\t\t);\n\t\tcharacterFormats.forEach( ( format ) => {\n\t\t\tlet { id } = format.attributes;\n\t\t\tid = id.replace( ANNOTATION_ATTRIBUTE_PREFIX, '' );\n\n\t\t\tif ( ! positions.hasOwnProperty( id ) ) {\n\t\t\t\tpositions[ id ] = {\n\t\t\t\t\tstart: i,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Annotations refer to positions between characters.\n\t\t\t// Formats refer to the character themselves.\n\t\t\t// So we need to adjust for that here.\n\t\t\tpositions[ id ].end = i + 1;\n\t\t} );\n\t} );\n\n\treturn positions;\n}\n\n/**\n * Updates annotations in the state based on positions retrieved from RichText.\n *\n * @param {Array} annotations The annotations that are currently applied.\n * @param {Array} positions The current positions of the given annotations.\n * @param {Object} actions\n * @param {Function} actions.removeAnnotation Function to remove an annotation from the state.\n * @param {Function} actions.updateAnnotationRange Function to update an annotation range in the state.\n */\nfunction updateAnnotationsWithPositions(\n\tannotations,\n\tpositions,\n\t{ removeAnnotation, updateAnnotationRange }\n) {\n\tannotations.forEach( ( currentAnnotation ) => {\n\t\tconst position = positions[ currentAnnotation.id ];\n\t\t// If we cannot find an annotation, delete it.\n\t\tif ( ! position ) {\n\t\t\t// Apparently the annotation has been removed, so remove it from the state:\n\t\t\t// Remove...\n\t\t\tremoveAnnotation( currentAnnotation.id );\n\t\t\treturn;\n\t\t}\n\n\t\tconst { start, end } = currentAnnotation;\n\t\tif ( start !== position.start || end !== position.end ) {\n\t\t\tupdateAnnotationRange(\n\t\t\t\tcurrentAnnotation.id,\n\t\t\t\tposition.start,\n\t\t\t\tposition.end\n\t\t\t);\n\t\t}\n\t} );\n}\n\nexport const annotation = {\n\tname: FORMAT_NAME,\n\ttitle: __( 'Annotation' ),\n\ttagName: 'mark',\n\tclassName: 'annotation-text',\n\tattributes: {\n\t\tclassName: 'class',\n\t\tid: 'id',\n\t},\n\tedit() {\n\t\treturn null;\n\t},\n\t__experimentalGetPropsForEditableTreePreparation(\n\t\tselect,\n\t\t{ richTextIdentifier, blockClientId }\n\t) {\n\t\treturn {\n\t\t\tannotations: select(\n\t\t\t\tSTORE_NAME\n\t\t\t).__experimentalGetAnnotationsForRichText(\n\t\t\t\tblockClientId,\n\t\t\t\trichTextIdentifier\n\t\t\t),\n\t\t};\n\t},\n\t__experimentalCreatePrepareEditableTree( { annotations } ) {\n\t\treturn ( formats, text ) => {\n\t\t\tif ( annotations.length === 0 ) {\n\t\t\t\treturn formats;\n\t\t\t}\n\n\t\t\tlet record = { formats, text };\n\t\t\trecord = applyAnnotations( record, annotations );\n\t\t\treturn record.formats;\n\t\t};\n\t},\n\t__experimentalGetPropsForEditableTreeChangeHandler( dispatch ) {\n\t\treturn {\n\t\t\tremoveAnnotation:\n\t\t\t\tdispatch( STORE_NAME ).__experimentalRemoveAnnotation,\n\t\t\tupdateAnnotationRange:\n\t\t\t\tdispatch( STORE_NAME ).__experimentalUpdateAnnotationRange,\n\t\t};\n\t},\n\t__experimentalCreateOnChangeEditableValue( props ) {\n\t\treturn ( formats ) => {\n\t\t\tconst positions = retrieveAnnotationPositions( formats );\n\t\t\tconst { removeAnnotation, updateAnnotationRange, annotations } =\n\t\t\t\tprops;\n\n\t\t\tupdateAnnotationsWithPositions( annotations, positions, {\n\t\t\t\tremoveAnnotation,\n\t\t\t\tupdateAnnotationRange,\n\t\t\t} );\n\t\t};\n\t},\n};\n"]}
1
+ {"version":3,"names":["__","applyFormat","removeFormat","FORMAT_NAME","ANNOTATION_ATTRIBUTE_PREFIX","STORE_NAME","applyAnnotations","record","annotations","forEach","annotation","start","end","text","length","className","source","id","type","attributes","removeAnnotations","retrieveAnnotationPositions","formats","positions","characterFormats","i","filter","format","replace","hasOwnProperty","updateAnnotationsWithPositions","removeAnnotation","updateAnnotationRange","currentAnnotation","position","name","title","tagName","edit","__experimentalGetPropsForEditableTreePreparation","select","richTextIdentifier","blockClientId","__experimentalGetAnnotationsForRichText","__experimentalCreatePrepareEditableTree","__experimentalGetPropsForEditableTreeChangeHandler","dispatch","__experimentalRemoveAnnotation","__experimentalUpdateAnnotationRange","__experimentalCreateOnChangeEditableValue","props"],"sources":["@wordpress/annotations/src/format/annotation.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { applyFormat, removeFormat } from '@wordpress/rich-text';\n\nconst FORMAT_NAME = 'core/annotation';\n\nconst ANNOTATION_ATTRIBUTE_PREFIX = 'annotation-text-';\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../store/constants';\n\n/**\n * Applies given annotations to the given record.\n *\n * @param {Object} record The record to apply annotations to.\n * @param {Array} annotations The annotation to apply.\n * @return {Object} A record with the annotations applied.\n */\nexport function applyAnnotations( record, annotations = [] ) {\n\tannotations.forEach( ( annotation ) => {\n\t\tlet { start, end } = annotation;\n\n\t\tif ( start > record.text.length ) {\n\t\t\tstart = record.text.length;\n\t\t}\n\n\t\tif ( end > record.text.length ) {\n\t\t\tend = record.text.length;\n\t\t}\n\n\t\tconst className = ANNOTATION_ATTRIBUTE_PREFIX + annotation.source;\n\t\tconst id = ANNOTATION_ATTRIBUTE_PREFIX + annotation.id;\n\n\t\trecord = applyFormat(\n\t\t\trecord,\n\t\t\t{\n\t\t\t\ttype: FORMAT_NAME,\n\t\t\t\tattributes: {\n\t\t\t\t\tclassName,\n\t\t\t\t\tid,\n\t\t\t\t},\n\t\t\t},\n\t\t\tstart,\n\t\t\tend\n\t\t);\n\t} );\n\n\treturn record;\n}\n\n/**\n * Removes annotations from the given record.\n *\n * @param {Object} record Record to remove annotations from.\n * @return {Object} The cleaned record.\n */\nexport function removeAnnotations( record ) {\n\treturn removeFormat( record, 'core/annotation', 0, record.text.length );\n}\n\n/**\n * Retrieves the positions of annotations inside an array of formats.\n *\n * @param {Array} formats Formats with annotations in there.\n * @return {Object} ID keyed positions of annotations.\n */\nfunction retrieveAnnotationPositions( formats ) {\n\tconst positions = {};\n\n\tformats.forEach( ( characterFormats, i ) => {\n\t\tcharacterFormats = characterFormats || [];\n\t\tcharacterFormats = characterFormats.filter(\n\t\t\t( format ) => format.type === FORMAT_NAME\n\t\t);\n\t\tcharacterFormats.forEach( ( format ) => {\n\t\t\tlet { id } = format.attributes;\n\t\t\tid = id.replace( ANNOTATION_ATTRIBUTE_PREFIX, '' );\n\n\t\t\tif ( ! positions.hasOwnProperty( id ) ) {\n\t\t\t\tpositions[ id ] = {\n\t\t\t\t\tstart: i,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Annotations refer to positions between characters.\n\t\t\t// Formats refer to the character themselves.\n\t\t\t// So we need to adjust for that here.\n\t\t\tpositions[ id ].end = i + 1;\n\t\t} );\n\t} );\n\n\treturn positions;\n}\n\n/**\n * Updates annotations in the state based on positions retrieved from RichText.\n *\n * @param {Array} annotations The annotations that are currently applied.\n * @param {Array} positions The current positions of the given annotations.\n * @param {Object} actions\n * @param {Function} actions.removeAnnotation Function to remove an annotation from the state.\n * @param {Function} actions.updateAnnotationRange Function to update an annotation range in the state.\n */\nfunction updateAnnotationsWithPositions(\n\tannotations,\n\tpositions,\n\t{ removeAnnotation, updateAnnotationRange }\n) {\n\tannotations.forEach( ( currentAnnotation ) => {\n\t\tconst position = positions[ currentAnnotation.id ];\n\t\t// If we cannot find an annotation, delete it.\n\t\tif ( ! position ) {\n\t\t\t// Apparently the annotation has been removed, so remove it from the state:\n\t\t\t// Remove...\n\t\t\tremoveAnnotation( currentAnnotation.id );\n\t\t\treturn;\n\t\t}\n\n\t\tconst { start, end } = currentAnnotation;\n\t\tif ( start !== position.start || end !== position.end ) {\n\t\t\tupdateAnnotationRange(\n\t\t\t\tcurrentAnnotation.id,\n\t\t\t\tposition.start,\n\t\t\t\tposition.end\n\t\t\t);\n\t\t}\n\t} );\n}\n\nexport const annotation = {\n\tname: FORMAT_NAME,\n\ttitle: __( 'Annotation' ),\n\ttagName: 'mark',\n\tclassName: 'annotation-text',\n\tattributes: {\n\t\tclassName: 'class',\n\t\tid: 'id',\n\t},\n\tedit() {\n\t\treturn null;\n\t},\n\t__experimentalGetPropsForEditableTreePreparation(\n\t\tselect,\n\t\t{ richTextIdentifier, blockClientId }\n\t) {\n\t\treturn {\n\t\t\tannotations: select(\n\t\t\t\tSTORE_NAME\n\t\t\t).__experimentalGetAnnotationsForRichText(\n\t\t\t\tblockClientId,\n\t\t\t\trichTextIdentifier\n\t\t\t),\n\t\t};\n\t},\n\t__experimentalCreatePrepareEditableTree( { annotations } ) {\n\t\treturn ( formats, text ) => {\n\t\t\tif ( annotations.length === 0 ) {\n\t\t\t\treturn formats;\n\t\t\t}\n\n\t\t\tlet record = { formats, text };\n\t\t\trecord = applyAnnotations( record, annotations );\n\t\t\treturn record.formats;\n\t\t};\n\t},\n\t__experimentalGetPropsForEditableTreeChangeHandler( dispatch ) {\n\t\treturn {\n\t\t\tremoveAnnotation:\n\t\t\t\tdispatch( STORE_NAME ).__experimentalRemoveAnnotation,\n\t\t\tupdateAnnotationRange:\n\t\t\t\tdispatch( STORE_NAME ).__experimentalUpdateAnnotationRange,\n\t\t};\n\t},\n\t__experimentalCreateOnChangeEditableValue( props ) {\n\t\treturn ( formats ) => {\n\t\t\tconst positions = retrieveAnnotationPositions( formats );\n\t\t\tconst { removeAnnotation, updateAnnotationRange, annotations } =\n\t\t\t\tprops;\n\n\t\t\tupdateAnnotationsWithPositions( annotations, positions, {\n\t\t\t\tremoveAnnotation,\n\t\t\t\tupdateAnnotationRange,\n\t\t\t} );\n\t\t};\n\t},\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,WAAW,EAAEC,YAAY,QAAQ,sBAAsB;AAEhE,MAAMC,WAAW,GAAG,iBAAiB;AAErC,MAAMC,2BAA2B,GAAG,kBAAkB;AACtD;AACA;AACA;AACA,SAASC,UAAU,QAAQ,oBAAoB;;AAE/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAAEC,MAAM,EAAEC,WAAW,GAAG,EAAE,EAAG;EAC5DA,WAAW,CAACC,OAAO,CAAIC,UAAU,IAAM;IACtC,IAAI;MAAEC,KAAK;MAAEC;IAAI,CAAC,GAAGF,UAAU;IAE/B,IAAKC,KAAK,GAAGJ,MAAM,CAACM,IAAI,CAACC,MAAM,EAAG;MACjCH,KAAK,GAAGJ,MAAM,CAACM,IAAI,CAACC,MAAM;IAC3B;IAEA,IAAKF,GAAG,GAAGL,MAAM,CAACM,IAAI,CAACC,MAAM,EAAG;MAC/BF,GAAG,GAAGL,MAAM,CAACM,IAAI,CAACC,MAAM;IACzB;IAEA,MAAMC,SAAS,GAAGX,2BAA2B,GAAGM,UAAU,CAACM,MAAM;IACjE,MAAMC,EAAE,GAAGb,2BAA2B,GAAGM,UAAU,CAACO,EAAE;IAEtDV,MAAM,GAAGN,WAAW,CACnBM,MAAM,EACN;MACCW,IAAI,EAAEf,WAAW;MACjBgB,UAAU,EAAE;QACXJ,SAAS;QACTE;MACD;IACD,CAAC,EACDN,KAAK,EACLC,GACD,CAAC;EACF,CAAE,CAAC;EAEH,OAAOL,MAAM;AACd;;AAEA;AACA;AACA;AAC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CAAEC,QAAQ,EAAG;IAC9D,OAAO;MACNf,gBAAgB,EACfe,QAAQ,CAAEzC,UAAW,CAAC,CAAC0C,8BAA8B;MACtDf,qBAAqB,EACpBc,QAAQ,CAAEzC,UAAW,CAAC,CAAC2C;IACzB,CAAC;EACF,CAAC;EACDC,yCAAyCA,CAAEC,KAAK,EAAG;IAClD,OAAS5B,OAAO,IAAM;MACrB,MAAMC,SAAS,GAAGF,2BAA2B,CAAEC,OAAQ,CAAC;MACxD,MAAM;QAAES,gBAAgB;QAAEC,qBAAqB;QAAExB;MAAY,CAAC,GAC7D0C,KAAK;MAENpB,8BAA8B,CAAEtB,WAAW,EAAEe,SAAS,EAAE;QACvDQ,gBAAgB;QAChBC;MACD,CAAE,CAAC;IACJ,CAAC;EACF;AACD,CAAC"}
@@ -2,10 +2,10 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { registerFormatType } from '@wordpress/rich-text';
5
+
5
6
  /**
6
7
  * Internal dependencies
7
8
  */
8
-
9
9
  import { annotation } from './annotation';
10
10
  const {
11
11
  name,
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/annotations/src/format/index.js"],"names":["registerFormatType","annotation","name","settings"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,kBAAT,QAAmC,sBAAnC;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,cAA3B;AAEA,MAAM;AAAEC,EAAAA,IAAF;AAAQ,KAAGC;AAAX,IAAwBF,UAA9B;AAEAD,kBAAkB,CAAEE,IAAF,EAAQC,QAAR,CAAlB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { registerFormatType } from '@wordpress/rich-text';\n\n/**\n * Internal dependencies\n */\nimport { annotation } from './annotation';\n\nconst { name, ...settings } = annotation;\n\nregisterFormatType( name, settings );\n"]}
1
+ {"version":3,"names":["registerFormatType","annotation","name","settings"],"sources":["@wordpress/annotations/src/format/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { registerFormatType } from '@wordpress/rich-text';\n\n/**\n * Internal dependencies\n */\nimport { annotation } from './annotation';\n\nconst { name, ...settings } = annotation;\n\nregisterFormatType( name, settings );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,kBAAkB,QAAQ,sBAAsB;;AAEzD;AACA;AACA;AACA,SAASC,UAAU,QAAQ,cAAc;AAEzC,MAAM;EAAEC,IAAI;EAAE,GAAGC;AAAS,CAAC,GAAGF,UAAU;AAExCD,kBAAkB,CAAEE,IAAI,EAAEC,QAAS,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/annotations/src/index.js"],"names":["store"],"mappings":"AAAA;AACA;AACA;AACA,OAAO,UAAP;AACA,OAAO,SAAP;AAEA,SAASA,KAAT,QAAsB,SAAtB","sourcesContent":["/**\n * Internal dependencies\n */\nimport './format';\nimport './block';\n\nexport { store } from './store';\n"]}
1
+ {"version":3,"names":["store"],"sources":["@wordpress/annotations/src/index.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport './format';\nimport './block';\n\nexport { store } from './store';\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAO,UAAU;AACjB,OAAO,SAAS;AAEhB,SAASA,KAAK,QAAQ,SAAS"}
@@ -2,6 +2,7 @@
2
2
  * External dependencies
3
3
  */
4
4
  import { v4 as uuid } from 'uuid';
5
+
5
6
  /**
6
7
  * @typedef WPAnnotationRange
7
8
  *
@@ -29,7 +30,6 @@ import { v4 as uuid } from 'uuid';
29
30
  *
30
31
  * @return {Object} Action object.
31
32
  */
32
-
33
33
  export function __experimentalAddAnnotation({
34
34
  blockClientId,
35
35
  richTextIdentifier = null,
@@ -46,13 +46,12 @@ export function __experimentalAddAnnotation({
46
46
  source,
47
47
  selector
48
48
  };
49
-
50
49
  if (selector === 'range') {
51
50
  action.range = range;
52
51
  }
53
-
54
52
  return action;
55
53
  }
54
+
56
55
  /**
57
56
  * Removes an annotation with a specific ID.
58
57
  *
@@ -60,13 +59,13 @@ export function __experimentalAddAnnotation({
60
59
  *
61
60
  * @return {Object} Action object.
62
61
  */
63
-
64
62
  export function __experimentalRemoveAnnotation(annotationId) {
65
63
  return {
66
64
  type: 'ANNOTATION_REMOVE',
67
65
  annotationId
68
66
  };
69
67
  }
68
+
70
69
  /**
71
70
  * Updates the range of an annotation.
72
71
  *
@@ -76,7 +75,6 @@ export function __experimentalRemoveAnnotation(annotationId) {
76
75
  *
77
76
  * @return {Object} Action object.
78
77
  */
79
-
80
78
  export function __experimentalUpdateAnnotationRange(annotationId, start, end) {
81
79
  return {
82
80
  type: 'ANNOTATION_UPDATE_RANGE',
@@ -85,6 +83,7 @@ export function __experimentalUpdateAnnotationRange(annotationId, start, end) {
85
83
  end
86
84
  };
87
85
  }
86
+
88
87
  /**
89
88
  * Removes all annotations of a specific source.
90
89
  *
@@ -92,7 +91,6 @@ export function __experimentalUpdateAnnotationRange(annotationId, start, end) {
92
91
  *
93
92
  * @return {Object} Action object.
94
93
  */
95
-
96
94
  export function __experimentalRemoveAnnotationsBySource(source) {
97
95
  return {
98
96
  type: 'ANNOTATION_REMOVE_SOURCE',
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/annotations/src/store/actions.js"],"names":["v4","uuid","__experimentalAddAnnotation","blockClientId","richTextIdentifier","range","selector","source","id","action","type","__experimentalRemoveAnnotation","annotationId","__experimentalUpdateAnnotationRange","start","end","__experimentalRemoveAnnotationsBySource"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,IAAIC,IAAf,QAA2B,MAA3B;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,2BAAT,CAAsC;AAC5CC,EAAAA,aAD4C;AAE5CC,EAAAA,kBAAkB,GAAG,IAFuB;AAG5CC,EAAAA,KAAK,GAAG,IAHoC;AAI5CC,EAAAA,QAAQ,GAAG,OAJiC;AAK5CC,EAAAA,MAAM,GAAG,SALmC;AAM5CC,EAAAA,EAAE,GAAGP,IAAI;AANmC,CAAtC,EAOH;AACH,QAAMQ,MAAM,GAAG;AACdC,IAAAA,IAAI,EAAE,gBADQ;AAEdF,IAAAA,EAFc;AAGdL,IAAAA,aAHc;AAIdC,IAAAA,kBAJc;AAKdG,IAAAA,MALc;AAMdD,IAAAA;AANc,GAAf;;AASA,MAAKA,QAAQ,KAAK,OAAlB,EAA4B;AAC3BG,IAAAA,MAAM,CAACJ,KAAP,GAAeA,KAAf;AACA;;AAED,SAAOI,MAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,8BAAT,CAAyCC,YAAzC,EAAwD;AAC9D,SAAO;AACNF,IAAAA,IAAI,EAAE,mBADA;AAENE,IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,mCAAT,CACND,YADM,EAENE,KAFM,EAGNC,GAHM,EAIL;AACD,SAAO;AACNL,IAAAA,IAAI,EAAE,yBADA;AAENE,IAAAA,YAFM;AAGNE,IAAAA,KAHM;AAINC,IAAAA;AAJM,GAAP;AAMA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,uCAAT,CAAkDT,MAAlD,EAA2D;AACjE,SAAO;AACNG,IAAAA,IAAI,EAAE,0BADA;AAENH,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport { v4 as uuid } from 'uuid';\n\n/**\n * @typedef WPAnnotationRange\n *\n * @property {number} start The offset where the annotation should start.\n * @property {number} end The offset where the annotation should end.\n */\n\n/**\n * Adds an annotation to a block.\n *\n * The `block` attribute refers to a block ID that needs to be annotated.\n * `isBlockAnnotation` controls whether or not the annotation is a block\n * annotation. The `source` is the source of the annotation, this will be used\n * to identity groups of annotations.\n *\n * The `range` property is only relevant if the selector is 'range'.\n *\n * @param {Object} annotation The annotation to add.\n * @param {string} annotation.blockClientId The blockClientId to add the annotation to.\n * @param {string} annotation.richTextIdentifier Identifier for the RichText instance the annotation applies to.\n * @param {WPAnnotationRange} annotation.range The range at which to apply this annotation.\n * @param {string} [annotation.selector=\"range\"] The way to apply this annotation.\n * @param {string} [annotation.source=\"default\"] The source that added the annotation.\n * @param {string} [annotation.id] The ID the annotation should have. Generates a UUID by default.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalAddAnnotation( {\n\tblockClientId,\n\trichTextIdentifier = null,\n\trange = null,\n\tselector = 'range',\n\tsource = 'default',\n\tid = uuid(),\n} ) {\n\tconst action = {\n\t\ttype: 'ANNOTATION_ADD',\n\t\tid,\n\t\tblockClientId,\n\t\trichTextIdentifier,\n\t\tsource,\n\t\tselector,\n\t};\n\n\tif ( selector === 'range' ) {\n\t\taction.range = range;\n\t}\n\n\treturn action;\n}\n\n/**\n * Removes an annotation with a specific ID.\n *\n * @param {string} annotationId The annotation to remove.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalRemoveAnnotation( annotationId ) {\n\treturn {\n\t\ttype: 'ANNOTATION_REMOVE',\n\t\tannotationId,\n\t};\n}\n\n/**\n * Updates the range of an annotation.\n *\n * @param {string} annotationId ID of the annotation to update.\n * @param {number} start The start of the new range.\n * @param {number} end The end of the new range.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalUpdateAnnotationRange(\n\tannotationId,\n\tstart,\n\tend\n) {\n\treturn {\n\t\ttype: 'ANNOTATION_UPDATE_RANGE',\n\t\tannotationId,\n\t\tstart,\n\t\tend,\n\t};\n}\n\n/**\n * Removes all annotations of a specific source.\n *\n * @param {string} source The source to remove.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalRemoveAnnotationsBySource( source ) {\n\treturn {\n\t\ttype: 'ANNOTATION_REMOVE_SOURCE',\n\t\tsource,\n\t};\n}\n"]}
1
+ {"version":3,"names":["v4","uuid","__experimentalAddAnnotation","blockClientId","richTextIdentifier","range","selector","source","id","action","type","__experimentalRemoveAnnotation","annotationId","__experimentalUpdateAnnotationRange","start","end","__experimentalRemoveAnnotationsBySource"],"sources":["@wordpress/annotations/src/store/actions.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { v4 as uuid } from 'uuid';\n\n/**\n * @typedef WPAnnotationRange\n *\n * @property {number} start The offset where the annotation should start.\n * @property {number} end The offset where the annotation should end.\n */\n\n/**\n * Adds an annotation to a block.\n *\n * The `block` attribute refers to a block ID that needs to be annotated.\n * `isBlockAnnotation` controls whether or not the annotation is a block\n * annotation. The `source` is the source of the annotation, this will be used\n * to identity groups of annotations.\n *\n * The `range` property is only relevant if the selector is 'range'.\n *\n * @param {Object} annotation The annotation to add.\n * @param {string} annotation.blockClientId The blockClientId to add the annotation to.\n * @param {string} annotation.richTextIdentifier Identifier for the RichText instance the annotation applies to.\n * @param {WPAnnotationRange} annotation.range The range at which to apply this annotation.\n * @param {string} [annotation.selector=\"range\"] The way to apply this annotation.\n * @param {string} [annotation.source=\"default\"] The source that added the annotation.\n * @param {string} [annotation.id] The ID the annotation should have. Generates a UUID by default.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalAddAnnotation( {\n\tblockClientId,\n\trichTextIdentifier = null,\n\trange = null,\n\tselector = 'range',\n\tsource = 'default',\n\tid = uuid(),\n} ) {\n\tconst action = {\n\t\ttype: 'ANNOTATION_ADD',\n\t\tid,\n\t\tblockClientId,\n\t\trichTextIdentifier,\n\t\tsource,\n\t\tselector,\n\t};\n\n\tif ( selector === 'range' ) {\n\t\taction.range = range;\n\t}\n\n\treturn action;\n}\n\n/**\n * Removes an annotation with a specific ID.\n *\n * @param {string} annotationId The annotation to remove.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalRemoveAnnotation( annotationId ) {\n\treturn {\n\t\ttype: 'ANNOTATION_REMOVE',\n\t\tannotationId,\n\t};\n}\n\n/**\n * Updates the range of an annotation.\n *\n * @param {string} annotationId ID of the annotation to update.\n * @param {number} start The start of the new range.\n * @param {number} end The end of the new range.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalUpdateAnnotationRange(\n\tannotationId,\n\tstart,\n\tend\n) {\n\treturn {\n\t\ttype: 'ANNOTATION_UPDATE_RANGE',\n\t\tannotationId,\n\t\tstart,\n\t\tend,\n\t};\n}\n\n/**\n * Removes all annotations of a specific source.\n *\n * @param {string} source The source to remove.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalRemoveAnnotationsBySource( source ) {\n\treturn {\n\t\ttype: 'ANNOTATION_REMOVE_SOURCE',\n\t\tsource,\n\t};\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,IAAIC,IAAI,QAAQ,MAAM;;AAEjC;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,2BAA2BA,CAAE;EAC5CC,aAAa;EACbC,kBAAkB,GAAG,IAAI;EACzBC,KAAK,GAAG,IAAI;EACZC,QAAQ,GAAG,OAAO;EAClBC,MAAM,GAAG,SAAS;EAClBC,EAAE,GAAGP,IAAI,CAAC;AACX,CAAC,EAAG;EACH,MAAMQ,MAAM,GAAG;IACdC,IAAI,EAAE,gBAAgB;IACtBF,EAAE;IACFL,aAAa;IACbC,kBAAkB;IAClBG,MAAM;IACND;EACD,CAAC;EAED,IAAKA,QAAQ,KAAK,OAAO,EAAG;IAC3BG,MAAM,CAACJ,KAAK,GAAGA,KAAK;EACrB;EAEA,OAAOI,MAAM;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,8BAA8BA,CAAEC,YAAY,EAAG;EAC9D,OAAO;IACNF,IAAI,EAAE,mBAAmB;IACzBE;EACD,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,mCAAmCA,CAClDD,YAAY,EACZE,KAAK,EACLC,GAAG,EACF;EACD,OAAO;IACNL,IAAI,EAAE,yBAAyB;IAC/BE,YAAY;IACZE,KAAK;IACLC;EACD,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,uCAAuCA,CAAET,MAAM,EAAG;EACjE,OAAO;IACNG,IAAI,EAAE,0BAA0B;IAChCH;EACD,CAAC;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/annotations/src/store/constants.js"],"names":["STORE_NAME"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,UAAU,GAAG,kBAAnB","sourcesContent":["/**\n * The identifier for the data store.\n *\n * @type {string}\n */\nexport const STORE_NAME = 'core/annotations';\n"]}
1
+ {"version":3,"names":["STORE_NAME"],"sources":["@wordpress/annotations/src/store/constants.js"],"sourcesContent":["/**\n * The identifier for the data store.\n *\n * @type {string}\n */\nexport const STORE_NAME = 'core/annotations';\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,UAAU,GAAG,kBAAkB"}
@@ -2,18 +2,19 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { register, createReduxStore } from '@wordpress/data';
5
+
5
6
  /**
6
7
  * Internal dependencies
7
8
  */
8
-
9
9
  import reducer from './reducer';
10
10
  import * as selectors from './selectors';
11
11
  import * as actions from './actions';
12
+
12
13
  /**
13
14
  * Module Constants
14
15
  */
15
-
16
16
  import { STORE_NAME } from './constants';
17
+
17
18
  /**
18
19
  * Store definition for the annotations namespace.
19
20
  *
@@ -21,7 +22,6 @@ import { STORE_NAME } from './constants';
21
22
  *
22
23
  * @type {Object}
23
24
  */
24
-
25
25
  export const store = createReduxStore(STORE_NAME, {
26
26
  reducer,
27
27
  selectors,
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/annotations/src/store/index.js"],"names":["register","createReduxStore","reducer","selectors","actions","STORE_NAME","store"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,QAAT,EAAmBC,gBAAnB,QAA2C,iBAA3C;AAEA;AACA;AACA;;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,OAAO,KAAKC,SAAZ,MAA2B,aAA3B;AACA,OAAO,KAAKC,OAAZ,MAAyB,WAAzB;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,aAA3B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,KAAK,GAAGL,gBAAgB,CAAEI,UAAF,EAAc;AAClDH,EAAAA,OADkD;AAElDC,EAAAA,SAFkD;AAGlDC,EAAAA;AAHkD,CAAd,CAA9B;AAMPJ,QAAQ,CAAEM,KAAF,CAAR","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { register, createReduxStore } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as actions from './actions';\n\n/**\n * Module Constants\n */\nimport { STORE_NAME } from './constants';\n\n/**\n * Store definition for the annotations namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n *\n * @type {Object}\n */\nexport const store = createReduxStore( STORE_NAME, {\n\treducer,\n\tselectors,\n\tactions,\n} );\n\nregister( store );\n"]}
1
+ {"version":3,"names":["register","createReduxStore","reducer","selectors","actions","STORE_NAME","store"],"sources":["@wordpress/annotations/src/store/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { register, createReduxStore } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as actions from './actions';\n\n/**\n * Module Constants\n */\nimport { STORE_NAME } from './constants';\n\n/**\n * Store definition for the annotations namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n *\n * @type {Object}\n */\nexport const store = createReduxStore( STORE_NAME, {\n\treducer,\n\tselectors,\n\tactions,\n} );\n\nregister( store );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,QAAQ,EAAEC,gBAAgB,QAAQ,iBAAiB;;AAE5D;AACA;AACA;AACA,OAAOC,OAAO,MAAM,WAAW;AAC/B,OAAO,KAAKC,SAAS,MAAM,aAAa;AACxC,OAAO,KAAKC,OAAO,MAAM,WAAW;;AAEpC;AACA;AACA;AACA,SAASC,UAAU,QAAQ,aAAa;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,KAAK,GAAGL,gBAAgB,CAAEI,UAAU,EAAE;EAClDH,OAAO;EACPC,SAAS;EACTC;AACD,CAAE,CAAC;AAEHJ,QAAQ,CAAEM,KAAM,CAAC"}
@@ -11,6 +11,7 @@ function filterWithReference(collection, predicate) {
11
11
  const filteredCollection = collection.filter(predicate);
12
12
  return collection.length === filteredCollection.length ? collection : filteredCollection;
13
13
  }
14
+
14
15
  /**
15
16
  * Creates a new object with the same keys, but with `callback()` called as
16
17
  * a transformer function on each of the values.
@@ -19,22 +20,21 @@ function filterWithReference(collection, predicate) {
19
20
  * @param {Function} callback The function to transform each object value.
20
21
  * @return {Array} Transformed object.
21
22
  */
22
-
23
-
24
- const mapValues = (obj, callback) => Object.entries(obj).reduce((acc, [key, value]) => ({ ...acc,
23
+ const mapValues = (obj, callback) => Object.entries(obj).reduce((acc, [key, value]) => ({
24
+ ...acc,
25
25
  [key]: callback(value)
26
26
  }), {});
27
+
27
28
  /**
28
29
  * Verifies whether the given annotations is a valid annotation.
29
30
  *
30
31
  * @param {Object} annotation The annotation to verify.
31
32
  * @return {boolean} Whether the given annotation is valid.
32
33
  */
33
-
34
-
35
34
  function isValidAnnotationRange(annotation) {
36
35
  return typeof annotation.start === 'number' && typeof annotation.end === 'number' && annotation.start <= annotation.end;
37
36
  }
37
+
38
38
  /**
39
39
  * Reducer managing annotations.
40
40
  *
@@ -43,11 +43,8 @@ function isValidAnnotationRange(annotation) {
43
43
  *
44
44
  * @return {Array} Updated state.
45
45
  */
46
-
47
-
48
46
  export function annotations(state = {}, action) {
49
47
  var _state$blockClientId;
50
-
51
48
  switch (action.type) {
52
49
  case 'ANNOTATION_ADD':
53
50
  const blockClientId = action.blockClientId;
@@ -59,42 +56,38 @@ export function annotations(state = {}, action) {
59
56
  selector: action.selector,
60
57
  range: action.range
61
58
  };
62
-
63
59
  if (newAnnotation.selector === 'range' && !isValidAnnotationRange(newAnnotation.range)) {
64
60
  return state;
65
61
  }
66
-
67
62
  const previousAnnotationsForBlock = (_state$blockClientId = state?.[blockClientId]) !== null && _state$blockClientId !== void 0 ? _state$blockClientId : [];
68
- return { ...state,
63
+ return {
64
+ ...state,
69
65
  [blockClientId]: [...previousAnnotationsForBlock, newAnnotation]
70
66
  };
71
-
72
67
  case 'ANNOTATION_REMOVE':
73
68
  return mapValues(state, annotationsForBlock => {
74
69
  return filterWithReference(annotationsForBlock, annotation => {
75
70
  return annotation.id !== action.annotationId;
76
71
  });
77
72
  });
78
-
79
73
  case 'ANNOTATION_UPDATE_RANGE':
80
74
  return mapValues(state, annotationsForBlock => {
81
75
  let hasChangedRange = false;
82
76
  const newAnnotations = annotationsForBlock.map(annotation => {
83
77
  if (annotation.id === action.annotationId) {
84
78
  hasChangedRange = true;
85
- return { ...annotation,
79
+ return {
80
+ ...annotation,
86
81
  range: {
87
82
  start: action.start,
88
83
  end: action.end
89
84
  }
90
85
  };
91
86
  }
92
-
93
87
  return annotation;
94
88
  });
95
89
  return hasChangedRange ? newAnnotations : annotationsForBlock;
96
90
  });
97
-
98
91
  case 'ANNOTATION_REMOVE_SOURCE':
99
92
  return mapValues(state, annotationsForBlock => {
100
93
  return filterWithReference(annotationsForBlock, annotation => {
@@ -102,7 +95,6 @@ export function annotations(state = {}, action) {
102
95
  });
103
96
  });
104
97
  }
105
-
106
98
  return state;
107
99
  }
108
100
  export default annotations;