@wordpress/annotations 3.32.0 → 3.32.1-next.47f435fc9.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 (37) hide show
  1. package/build/block/index.js +17 -30
  2. package/build/block/index.js.map +7 -1
  3. package/build/format/annotation.js +85 -116
  4. package/build/format/annotation.js.map +7 -1
  5. package/build/format/index.js +5 -18
  6. package/build/format/index.js.map +7 -1
  7. package/build/index.js +28 -13
  8. package/build/index.js.map +7 -1
  9. package/build/store/actions.js +41 -75
  10. package/build/store/actions.js.map +7 -1
  11. package/build/store/constants.js +27 -12
  12. package/build/store/constants.js.map +7 -1
  13. package/build/store/index.js +44 -36
  14. package/build/store/index.js.map +7 -1
  15. package/build/store/reducer.js +75 -76
  16. package/build/store/reducer.js.map +7 -1
  17. package/build/store/selectors.js +56 -80
  18. package/build/store/selectors.js.map +7 -1
  19. package/build-module/block/index.js +17 -27
  20. package/build-module/block/index.js.map +7 -1
  21. package/build-module/format/annotation.js +61 -108
  22. package/build-module/format/annotation.js.map +7 -1
  23. package/build-module/format/index.js +4 -14
  24. package/build-module/format/index.js.map +7 -1
  25. package/build-module/index.js +7 -7
  26. package/build-module/index.js.map +7 -1
  27. package/build-module/store/actions.js +19 -70
  28. package/build-module/store/actions.js.map +7 -1
  29. package/build-module/store/constants.js +5 -7
  30. package/build-module/store/constants.js.map +7 -1
  31. package/build-module/store/index.js +10 -26
  32. package/build-module/store/index.js.map +7 -1
  33. package/build-module/store/reducer.js +54 -71
  34. package/build-module/store/reducer.js.map +7 -1
  35. package/build-module/store/selectors.js +33 -75
  36. package/build-module/store/selectors.js.map +7 -1
  37. package/package.json +13 -7
@@ -1,34 +1,21 @@
1
- "use strict";
2
-
3
- var _hooks = require("@wordpress/hooks");
4
- var _data = require("@wordpress/data");
5
- var _constants = require("../store/constants");
6
- /**
7
- * WordPress dependencies
8
- */
9
-
10
- /**
11
- * Internal dependencies
12
- */
13
-
14
- /**
15
- * Adds annotation className to the block-list-block component.
16
- *
17
- * @param {Object} OriginalComponent The original BlockListBlock component.
18
- * @return {Object} The enhanced component.
19
- */
20
- const addAnnotationClassName = OriginalComponent => {
21
- return (0, _data.withSelect)((select, {
22
- clientId,
23
- className
24
- }) => {
25
- const annotations = select(_constants.STORE_NAME).__experimentalGetAnnotationsForBlock(clientId);
1
+ var import_hooks = require("@wordpress/hooks");
2
+ var import_data = require("@wordpress/data");
3
+ var import_constants = require("../store/constants");
4
+ const addAnnotationClassName = (OriginalComponent) => {
5
+ return (0, import_data.withSelect)((select, { clientId, className }) => {
6
+ const annotations = select(import_constants.STORE_NAME).__experimentalGetAnnotationsForBlock(
7
+ clientId
8
+ );
26
9
  return {
27
- className: annotations.map(annotation => {
28
- return 'is-annotated-by-' + annotation.source;
29
- }).concat(className).filter(Boolean).join(' ')
10
+ className: annotations.map((annotation) => {
11
+ return "is-annotated-by-" + annotation.source;
12
+ }).concat(className).filter(Boolean).join(" ")
30
13
  };
31
14
  })(OriginalComponent);
32
15
  };
33
- (0, _hooks.addFilter)('editor.BlockListBlock', 'core/annotations', addAnnotationClassName);
34
- //# sourceMappingURL=index.js.map
16
+ (0, import_hooks.addFilter)(
17
+ "editor.BlockListBlock",
18
+ "core/annotations",
19
+ addAnnotationClassName
20
+ );
21
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_hooks","require","_data","_constants","addAnnotationClassName","OriginalComponent","withSelect","select","clientId","className","annotations","STORE_NAME","__experimentalGetAnnotationsForBlock","map","annotation","source","concat","filter","Boolean","join","addFilter"],"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":";;AAGA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAKA,IAAAE,UAAA,GAAAF,OAAA;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMG,sBAAsB,GAAKC,iBAAiB,IAAM;EACvD,OAAO,IAAAC,gBAAU,EAAE,CAAEC,MAAM,EAAE;IAAEC,QAAQ;IAAEC;EAAU,CAAC,KAAM;IACzD,MAAMC,WAAW,GAChBH,MAAM,CAAEI,qBAAW,CAAC,CAACC,oCAAoC,CACxDJ,QACD,CAAC;IAEF,OAAO;MACNC,SAAS,EAAEC,WAAW,CACpBG,GAAG,CAAIC,UAAU,IAAM;QACvB,OAAO,kBAAkB,GAAGA,UAAU,CAACC,MAAM;MAC9C,CAAE,CAAC,CACFC,MAAM,CAAEP,SAAU,CAAC,CACnBQ,MAAM,CAAEC,OAAQ,CAAC,CACjBC,IAAI,CAAE,GAAI;IACb,CAAC;EACF,CAAE,CAAC,CAAEd,iBAAkB,CAAC;AACzB,CAAC;AAED,IAAAe,gBAAS,EACR,uBAAuB,EACvB,kBAAkB,EAClBhB,sBACD,CAAC","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/block/index.js"],
4
+ "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"],
5
+ "mappings": "AAGA,mBAA0B;AAC1B,kBAA2B;AAK3B,uBAA2B;AAO3B,MAAM,yBAAyB,CAAE,sBAAuB;AACvD,aAAO,wBAAY,CAAE,QAAQ,EAAE,UAAU,UAAU,MAAO;AACzD,UAAM,cACL,OAAQ,2BAAW,EAAE;AAAA,MACpB;AAAA,IACD;AAED,WAAO;AAAA,MACN,WAAW,YACT,IAAK,CAAE,eAAgB;AACvB,eAAO,qBAAqB,WAAW;AAAA,MACxC,CAAE,EACD,OAAQ,SAAU,EAClB,OAAQ,OAAQ,EAChB,KAAM,GAAI;AAAA,IACb;AAAA,EACD,CAAE,EAAG,iBAAkB;AACxB;AAAA,IAEA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AACD;",
6
+ "names": []
7
+ }
@@ -1,177 +1,140 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var annotation_exports = {};
19
+ __export(annotation_exports, {
20
+ annotation: () => annotation,
21
+ applyAnnotations: () => applyAnnotations,
22
+ removeAnnotations: () => removeAnnotations
5
23
  });
6
- exports.annotation = void 0;
7
- exports.applyAnnotations = applyAnnotations;
8
- exports.removeAnnotations = removeAnnotations;
9
- var _i18n = require("@wordpress/i18n");
10
- var _richText = require("@wordpress/rich-text");
11
- var _constants = require("../store/constants");
12
- /**
13
- * WordPress dependencies
14
- */
15
-
16
- const FORMAT_NAME = 'core/annotation';
17
- const ANNOTATION_ATTRIBUTE_PREFIX = 'annotation-text-';
18
- /**
19
- * Internal dependencies
20
- */
21
-
22
- /**
23
- * Applies given annotations to the given record.
24
- *
25
- * @param {Object} record The record to apply annotations to.
26
- * @param {Array} annotations The annotation to apply.
27
- * @return {Object} A record with the annotations applied.
28
- */
24
+ module.exports = __toCommonJS(annotation_exports);
25
+ var import_i18n = require("@wordpress/i18n");
26
+ var import_rich_text = require("@wordpress/rich-text");
27
+ var import_constants = require("../store/constants");
28
+ const FORMAT_NAME = "core/annotation";
29
+ const ANNOTATION_ATTRIBUTE_PREFIX = "annotation-text-";
29
30
  function applyAnnotations(record, annotations = []) {
30
- annotations.forEach(annotation => {
31
- let {
32
- start,
33
- end
34
- } = annotation;
31
+ annotations.forEach((annotation2) => {
32
+ let { start, end } = annotation2;
35
33
  if (start > record.text.length) {
36
34
  start = record.text.length;
37
35
  }
38
36
  if (end > record.text.length) {
39
37
  end = record.text.length;
40
38
  }
41
- const className = ANNOTATION_ATTRIBUTE_PREFIX + annotation.source;
42
- const id = ANNOTATION_ATTRIBUTE_PREFIX + annotation.id;
43
- record = (0, _richText.applyFormat)(record, {
44
- type: FORMAT_NAME,
45
- attributes: {
46
- className,
47
- id
48
- }
49
- }, start, end);
39
+ const className = ANNOTATION_ATTRIBUTE_PREFIX + annotation2.source;
40
+ const id = ANNOTATION_ATTRIBUTE_PREFIX + annotation2.id;
41
+ record = (0, import_rich_text.applyFormat)(
42
+ record,
43
+ {
44
+ type: FORMAT_NAME,
45
+ attributes: {
46
+ className,
47
+ id
48
+ }
49
+ },
50
+ start,
51
+ end
52
+ );
50
53
  });
51
54
  return record;
52
55
  }
53
-
54
- /**
55
- * Removes annotations from the given record.
56
- *
57
- * @param {Object} record Record to remove annotations from.
58
- * @return {Object} The cleaned record.
59
- */
60
56
  function removeAnnotations(record) {
61
- return (0, _richText.removeFormat)(record, 'core/annotation', 0, record.text.length);
57
+ return (0, import_rich_text.removeFormat)(record, "core/annotation", 0, record.text.length);
62
58
  }
63
-
64
- /**
65
- * Retrieves the positions of annotations inside an array of formats.
66
- *
67
- * @param {Array} formats Formats with annotations in there.
68
- * @return {Object} ID keyed positions of annotations.
69
- */
70
59
  function retrieveAnnotationPositions(formats) {
71
60
  const positions = {};
72
61
  formats.forEach((characterFormats, i) => {
73
62
  characterFormats = characterFormats || [];
74
- characterFormats = characterFormats.filter(format => format.type === FORMAT_NAME);
75
- characterFormats.forEach(format => {
76
- let {
77
- id
78
- } = format.attributes;
79
- id = id.replace(ANNOTATION_ATTRIBUTE_PREFIX, '');
63
+ characterFormats = characterFormats.filter(
64
+ (format) => format.type === FORMAT_NAME
65
+ );
66
+ characterFormats.forEach((format) => {
67
+ let { id } = format.attributes;
68
+ id = id.replace(ANNOTATION_ATTRIBUTE_PREFIX, "");
80
69
  if (!positions.hasOwnProperty(id)) {
81
70
  positions[id] = {
82
71
  start: i
83
72
  };
84
73
  }
85
-
86
- // Annotations refer to positions between characters.
87
- // Formats refer to the character themselves.
88
- // So we need to adjust for that here.
89
74
  positions[id].end = i + 1;
90
75
  });
91
76
  });
92
77
  return positions;
93
78
  }
94
-
95
- /**
96
- * Updates annotations in the state based on positions retrieved from RichText.
97
- *
98
- * @param {Array} annotations The annotations that are currently applied.
99
- * @param {Array} positions The current positions of the given annotations.
100
- * @param {Object} actions
101
- * @param {Function} actions.removeAnnotation Function to remove an annotation from the state.
102
- * @param {Function} actions.updateAnnotationRange Function to update an annotation range in the state.
103
- */
104
- function updateAnnotationsWithPositions(annotations, positions, {
105
- removeAnnotation,
106
- updateAnnotationRange
107
- }) {
108
- annotations.forEach(currentAnnotation => {
79
+ function updateAnnotationsWithPositions(annotations, positions, { removeAnnotation, updateAnnotationRange }) {
80
+ annotations.forEach((currentAnnotation) => {
109
81
  const position = positions[currentAnnotation.id];
110
- // If we cannot find an annotation, delete it.
111
82
  if (!position) {
112
- // Apparently the annotation has been removed, so remove it from the state:
113
- // Remove...
114
83
  removeAnnotation(currentAnnotation.id);
115
84
  return;
116
85
  }
117
- const {
118
- start,
119
- end
120
- } = currentAnnotation;
86
+ const { start, end } = currentAnnotation;
121
87
  if (start !== position.start || end !== position.end) {
122
- updateAnnotationRange(currentAnnotation.id, position.start, position.end);
88
+ updateAnnotationRange(
89
+ currentAnnotation.id,
90
+ position.start,
91
+ position.end
92
+ );
123
93
  }
124
94
  });
125
95
  }
126
- const annotation = exports.annotation = {
96
+ const annotation = {
127
97
  name: FORMAT_NAME,
128
- title: (0, _i18n.__)('Annotation'),
129
- tagName: 'mark',
130
- className: 'annotation-text',
98
+ title: (0, import_i18n.__)("Annotation"),
99
+ tagName: "mark",
100
+ className: "annotation-text",
131
101
  attributes: {
132
- className: 'class',
133
- id: 'id'
102
+ className: "class",
103
+ id: "id"
134
104
  },
135
105
  edit() {
136
106
  return null;
137
107
  },
138
- __experimentalGetPropsForEditableTreePreparation(select, {
139
- richTextIdentifier,
140
- blockClientId
141
- }) {
108
+ __experimentalGetPropsForEditableTreePreparation(select, { richTextIdentifier, blockClientId }) {
142
109
  return {
143
- annotations: select(_constants.STORE_NAME).__experimentalGetAnnotationsForRichText(blockClientId, richTextIdentifier)
110
+ annotations: select(
111
+ import_constants.STORE_NAME
112
+ ).__experimentalGetAnnotationsForRichText(
113
+ blockClientId,
114
+ richTextIdentifier
115
+ )
144
116
  };
145
117
  },
146
- __experimentalCreatePrepareEditableTree({
147
- annotations
148
- }) {
118
+ __experimentalCreatePrepareEditableTree({ annotations }) {
149
119
  return (formats, text) => {
150
120
  if (annotations.length === 0) {
151
121
  return formats;
152
122
  }
153
- let record = {
154
- formats,
155
- text
156
- };
123
+ let record = { formats, text };
157
124
  record = applyAnnotations(record, annotations);
158
125
  return record.formats;
159
126
  };
160
127
  },
161
128
  __experimentalGetPropsForEditableTreeChangeHandler(dispatch) {
162
129
  return {
163
- removeAnnotation: dispatch(_constants.STORE_NAME).__experimentalRemoveAnnotation,
164
- updateAnnotationRange: dispatch(_constants.STORE_NAME).__experimentalUpdateAnnotationRange
130
+ removeAnnotation: dispatch(import_constants.STORE_NAME).__experimentalRemoveAnnotation,
131
+ updateAnnotationRange: dispatch(import_constants.STORE_NAME).__experimentalUpdateAnnotationRange
165
132
  };
166
133
  },
167
134
  __experimentalCreateOnChangeEditableValue(props) {
168
- return formats => {
135
+ return (formats) => {
169
136
  const positions = retrieveAnnotationPositions(formats);
170
- const {
171
- removeAnnotation,
172
- updateAnnotationRange,
173
- annotations
174
- } = props;
137
+ const { removeAnnotation, updateAnnotationRange, annotations } = props;
175
138
  updateAnnotationsWithPositions(annotations, positions, {
176
139
  removeAnnotation,
177
140
  updateAnnotationRange
@@ -179,4 +142,10 @@ const annotation = exports.annotation = {
179
142
  };
180
143
  }
181
144
  };
182
- //# sourceMappingURL=annotation.js.map
145
+ // Annotate the CommonJS export names for ESM import in node:
146
+ 0 && (module.exports = {
147
+ annotation,
148
+ applyAnnotations,
149
+ removeAnnotations
150
+ });
151
+ //# sourceMappingURL=annotation.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_i18n","require","_richText","_constants","FORMAT_NAME","ANNOTATION_ATTRIBUTE_PREFIX","applyAnnotations","record","annotations","forEach","annotation","start","end","text","length","className","source","id","applyFormat","type","attributes","removeAnnotations","removeFormat","retrieveAnnotationPositions","formats","positions","characterFormats","i","filter","format","replace","hasOwnProperty","updateAnnotationsWithPositions","removeAnnotation","updateAnnotationRange","currentAnnotation","position","exports","name","title","__","tagName","edit","__experimentalGetPropsForEditableTreePreparation","select","richTextIdentifier","blockClientId","STORE_NAME","__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":";;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAQA,IAAAE,UAAA,GAAAF,OAAA;AAZA;AACA;AACA;;AAIA,MAAMG,WAAW,GAAG,iBAAiB;AAErC,MAAMC,2BAA2B,GAAG,kBAAkB;AACtD;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,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,GAAGV,2BAA2B,GAAGK,UAAU,CAACM,MAAM;IACjE,MAAMC,EAAE,GAAGZ,2BAA2B,GAAGK,UAAU,CAACO,EAAE;IAEtDV,MAAM,GAAG,IAAAW,qBAAW,EACnBX,MAAM,EACN;MACCY,IAAI,EAAEf,WAAW;MACjBgB,UAAU,EAAE;QACXL,SAAS;QACTE;MACD;IACD,CAAC,EACDN,KAAK,EACLC,GACD,CAAC;EACF,CAAE,CAAC;EAEH,OAAOL,MAAM;AACd;;AAEA;AACA;AACA;AACA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tB,CAAC;EACF,CAAC;EACD0B,kDAAkDA,CAAEC,QAAQ,EAAG;IAC9D,OAAO;MACNlB,gBAAgB,EACfkB,QAAQ,CAAEJ,qBAAW,CAAC,CAACK,8BAA8B;MACtDlB,qBAAqB,EACpBiB,QAAQ,CAAEJ,qBAAW,CAAC,CAACM;IACzB,CAAC;EACF,CAAC;EACDC,yCAAyCA,CAAEC,KAAK,EAAG;IAClD,OAAS/B,OAAO,IAAM;MACrB,MAAMC,SAAS,GAAGF,2BAA2B,CAAEC,OAAQ,CAAC;MACxD,MAAM;QAAES,gBAAgB;QAAEC,qBAAqB;QAAE1B;MAAY,CAAC,GAC7D+C,KAAK;MAENvB,8BAA8B,CAAExB,WAAW,EAAEiB,SAAS,EAAE;QACvDQ,gBAAgB;QAChBC;MACD,CAAE,CAAC;IACJ,CAAC;EACF;AACD,CAAC","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/format/annotation.js"],
4
+ "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"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmB;AACnB,uBAA0C;AAQ1C,uBAA2B;AAN3B,MAAM,cAAc;AAEpB,MAAM,8BAA8B;AAa7B,SAAS,iBAAkB,QAAQ,cAAc,CAAC,GAAI;AAC5D,cAAY,QAAS,CAAEA,gBAAgB;AACtC,QAAI,EAAE,OAAO,IAAI,IAAIA;AAErB,QAAK,QAAQ,OAAO,KAAK,QAAS;AACjC,cAAQ,OAAO,KAAK;AAAA,IACrB;AAEA,QAAK,MAAM,OAAO,KAAK,QAAS;AAC/B,YAAM,OAAO,KAAK;AAAA,IACnB;AAEA,UAAM,YAAY,8BAA8BA,YAAW;AAC3D,UAAM,KAAK,8BAA8BA,YAAW;AAEpD,iBAAS;AAAA,MACR;AAAA,MACA;AAAA,QACC,MAAM;AAAA,QACN,YAAY;AAAA,UACX;AAAA,UACA;AAAA,QACD;AAAA,MACD;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD,CAAE;AAEF,SAAO;AACR;AAQO,SAAS,kBAAmB,QAAS;AAC3C,aAAO,+BAAc,QAAQ,mBAAmB,GAAG,OAAO,KAAK,MAAO;AACvE;AAQA,SAAS,4BAA6B,SAAU;AAC/C,QAAM,YAAY,CAAC;AAEnB,UAAQ,QAAS,CAAE,kBAAkB,MAAO;AAC3C,uBAAmB,oBAAoB,CAAC;AACxC,uBAAmB,iBAAiB;AAAA,MACnC,CAAE,WAAY,OAAO,SAAS;AAAA,IAC/B;AACA,qBAAiB,QAAS,CAAE,WAAY;AACvC,UAAI,EAAE,GAAG,IAAI,OAAO;AACpB,WAAK,GAAG,QAAS,6BAA6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AAA,MACN,kBACC,SAAU,2BAAW,EAAE;AAAA,MACxB,uBACC,SAAU,2BAAW,EAAE;AAAA,IACzB;AAAA,EACD;AAAA,EACA,0CAA2C,OAAQ;AAClD,WAAO,CAAE,YAAa;AACrB,YAAM,YAAY,4BAA6B,OAAQ;AACvD,YAAM,EAAE,kBAAkB,uBAAuB,YAAY,IAC5D;AAED,qCAAgC,aAAa,WAAW;AAAA,QACvD;AAAA,QACA;AAAA,MACD,CAAE;AAAA,IACH;AAAA,EACD;AACD;",
6
+ "names": ["annotation"]
7
+ }
@@ -1,18 +1,5 @@
1
- "use strict";
2
-
3
- var _richText = require("@wordpress/rich-text");
4
- var _annotation = require("./annotation");
5
- /**
6
- * WordPress dependencies
7
- */
8
-
9
- /**
10
- * Internal dependencies
11
- */
12
-
13
- const {
14
- name,
15
- ...settings
16
- } = _annotation.annotation;
17
- (0, _richText.registerFormatType)(name, settings);
18
- //# sourceMappingURL=index.js.map
1
+ var import_rich_text = require("@wordpress/rich-text");
2
+ var import_annotation = require("./annotation");
3
+ const { name, ...settings } = import_annotation.annotation;
4
+ (0, import_rich_text.registerFormatType)(name, settings);
5
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_richText","require","_annotation","name","settings","annotation","registerFormatType"],"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":";;AAGA,IAAAA,SAAA,GAAAC,OAAA;AAKA,IAAAC,WAAA,GAAAD,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA,MAAM;EAAEE,IAAI;EAAE,GAAGC;AAAS,CAAC,GAAGC,sBAAU;AAExC,IAAAC,4BAAkB,EAAEH,IAAI,EAAEC,QAAS,CAAC","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/format/index.js"],
4
+ "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"],
5
+ "mappings": "AAGA,uBAAmC;AAKnC,wBAA2B;AAE3B,MAAM,EAAE,MAAM,GAAG,SAAS,IAAI;AAAA,IAE9B,qCAAoB,MAAM,QAAS;",
6
+ "names": []
7
+ }
package/build/index.js CHANGED
@@ -1,15 +1,30 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "store", {
7
- enumerable: true,
8
- get: function () {
9
- return _store.store;
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
14
  }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var index_exports = {};
19
+ __export(index_exports, {
20
+ store: () => import_store.store
21
+ });
22
+ module.exports = __toCommonJS(index_exports);
23
+ var import_format = require("./format");
24
+ var import_block = require("./block");
25
+ var import_store = require("./store");
26
+ // Annotate the CommonJS export names for ESM import in node:
27
+ 0 && (module.exports = {
28
+ store
11
29
  });
12
- require("./format");
13
- require("./block");
14
- var _store = require("./store");
15
- //# sourceMappingURL=index.js.map
30
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["require","_store"],"sources":["@wordpress/annotations/src/index.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport './format';\nimport './block';\n\nexport { store } from './store';\n"],"mappings":";;;;;;;;;;;AAGAA,OAAA;AACAA,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.js"],
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport './format';\nimport './block';\n\nexport { store } from './store';\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAO;AACP,mBAAO;AAEP,mBAAsB;",
6
+ "names": []
7
+ }
@@ -1,109 +1,75 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var actions_exports = {};
19
+ __export(actions_exports, {
20
+ __experimentalAddAnnotation: () => __experimentalAddAnnotation,
21
+ __experimentalRemoveAnnotation: () => __experimentalRemoveAnnotation,
22
+ __experimentalRemoveAnnotationsBySource: () => __experimentalRemoveAnnotationsBySource,
23
+ __experimentalUpdateAnnotationRange: () => __experimentalUpdateAnnotationRange
5
24
  });
6
- exports.__experimentalAddAnnotation = __experimentalAddAnnotation;
7
- exports.__experimentalRemoveAnnotation = __experimentalRemoveAnnotation;
8
- exports.__experimentalRemoveAnnotationsBySource = __experimentalRemoveAnnotationsBySource;
9
- exports.__experimentalUpdateAnnotationRange = __experimentalUpdateAnnotationRange;
10
- var _uuid = require("uuid");
11
- /**
12
- * External dependencies
13
- */
14
-
15
- /**
16
- * @typedef WPAnnotationRange
17
- *
18
- * @property {number} start The offset where the annotation should start.
19
- * @property {number} end The offset where the annotation should end.
20
- */
21
-
22
- /**
23
- * Adds an annotation to a block.
24
- *
25
- * The `block` attribute refers to a block ID that needs to be annotated.
26
- * `isBlockAnnotation` controls whether or not the annotation is a block
27
- * annotation. The `source` is the source of the annotation, this will be used
28
- * to identity groups of annotations.
29
- *
30
- * The `range` property is only relevant if the selector is 'range'.
31
- *
32
- * @param {Object} annotation The annotation to add.
33
- * @param {string} annotation.blockClientId The blockClientId to add the annotation to.
34
- * @param {string} annotation.richTextIdentifier Identifier for the RichText instance the annotation applies to.
35
- * @param {WPAnnotationRange} annotation.range The range at which to apply this annotation.
36
- * @param {string} [annotation.selector="range"] The way to apply this annotation.
37
- * @param {string} [annotation.source="default"] The source that added the annotation.
38
- * @param {string} [annotation.id] The ID the annotation should have. Generates a UUID by default.
39
- *
40
- * @return {Object} Action object.
41
- */
25
+ module.exports = __toCommonJS(actions_exports);
26
+ var import_uuid = require("uuid");
42
27
  function __experimentalAddAnnotation({
43
28
  blockClientId,
44
29
  richTextIdentifier = null,
45
30
  range = null,
46
- selector = 'range',
47
- source = 'default',
48
- id = (0, _uuid.v4)()
31
+ selector = "range",
32
+ source = "default",
33
+ id = (0, import_uuid.v4)()
49
34
  }) {
50
35
  const action = {
51
- type: 'ANNOTATION_ADD',
36
+ type: "ANNOTATION_ADD",
52
37
  id,
53
38
  blockClientId,
54
39
  richTextIdentifier,
55
40
  source,
56
41
  selector
57
42
  };
58
- if (selector === 'range') {
43
+ if (selector === "range") {
59
44
  action.range = range;
60
45
  }
61
46
  return action;
62
47
  }
63
-
64
- /**
65
- * Removes an annotation with a specific ID.
66
- *
67
- * @param {string} annotationId The annotation to remove.
68
- *
69
- * @return {Object} Action object.
70
- */
71
48
  function __experimentalRemoveAnnotation(annotationId) {
72
49
  return {
73
- type: 'ANNOTATION_REMOVE',
50
+ type: "ANNOTATION_REMOVE",
74
51
  annotationId
75
52
  };
76
53
  }
77
-
78
- /**
79
- * Updates the range of an annotation.
80
- *
81
- * @param {string} annotationId ID of the annotation to update.
82
- * @param {number} start The start of the new range.
83
- * @param {number} end The end of the new range.
84
- *
85
- * @return {Object} Action object.
86
- */
87
54
  function __experimentalUpdateAnnotationRange(annotationId, start, end) {
88
55
  return {
89
- type: 'ANNOTATION_UPDATE_RANGE',
56
+ type: "ANNOTATION_UPDATE_RANGE",
90
57
  annotationId,
91
58
  start,
92
59
  end
93
60
  };
94
61
  }
95
-
96
- /**
97
- * Removes all annotations of a specific source.
98
- *
99
- * @param {string} source The source to remove.
100
- *
101
- * @return {Object} Action object.
102
- */
103
62
  function __experimentalRemoveAnnotationsBySource(source) {
104
63
  return {
105
- type: 'ANNOTATION_REMOVE_SOURCE',
64
+ type: "ANNOTATION_REMOVE_SOURCE",
106
65
  source
107
66
  };
108
67
  }
109
- //# sourceMappingURL=actions.js.map
68
+ // Annotate the CommonJS export names for ESM import in node:
69
+ 0 && (module.exports = {
70
+ __experimentalAddAnnotation,
71
+ __experimentalRemoveAnnotation,
72
+ __experimentalRemoveAnnotationsBySource,
73
+ __experimentalUpdateAnnotationRange
74
+ });
75
+ //# sourceMappingURL=actions.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_uuid","require","__experimentalAddAnnotation","blockClientId","richTextIdentifier","range","selector","source","id","uuid","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":";;;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA;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;AACO,SAASC,2BAA2BA,CAAE;EAC5CC,aAAa;EACbC,kBAAkB,GAAG,IAAI;EACzBC,KAAK,GAAG,IAAI;EACZC,QAAQ,GAAG,OAAO;EAClBC,MAAM,GAAG,SAAS;EAClBC,EAAE,GAAG,IAAAC,QAAI,EAAC;AACX,CAAC,EAAG;EACH,MAAMC,MAAM,GAAG;IACdC,IAAI,EAAE,gBAAgB;IACtBH,EAAE;IACFL,aAAa;IACbC,kBAAkB;IAClBG,MAAM;IACND;EACD,CAAC;EAED,IAAKA,QAAQ,KAAK,OAAO,EAAG;IAC3BI,MAAM,CAACL,KAAK,GAAGA,KAAK;EACrB;EAEA,OAAOK,MAAM;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,8BAA8BA,CAAEC,YAAY,EAAG;EAC9D,OAAO;IACNF,IAAI,EAAE,mBAAmB;IACzBE;EACD,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,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;AACO,SAASC,uCAAuCA,CAAEV,MAAM,EAAG;EACjE,OAAO;IACNI,IAAI,EAAE,0BAA0B;IAChCJ;EACD,CAAC;AACF","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/store/actions.js"],
4
+ "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"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA2B;AA6BpB,SAAS,4BAA6B;AAAA,EAC5C;AAAA,EACA,qBAAqB;AAAA,EACrB,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,SAAS;AAAA,EACT,SAAK,YAAAA,IAAK;AACX,GAAI;AACH,QAAM,SAAS;AAAA,IACd,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAEA,MAAK,aAAa,SAAU;AAC3B,WAAO,QAAQ;AAAA,EAChB;AAEA,SAAO;AACR;AASO,SAAS,+BAAgC,cAAe;AAC9D,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,EACD;AACD;AAWO,SAAS,oCACf,cACA,OACA,KACC;AACD,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AASO,SAAS,wCAAyC,QAAS;AACjE,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,EACD;AACD;",
6
+ "names": ["uuid"]
7
+ }