@wordpress/annotations 3.43.1-next.v.202604091042.0 → 3.44.1-next.v.202604201441.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 (75) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/block/index.cjs +8 -7
  3. package/build/block/index.cjs.map +3 -3
  4. package/build/format/annotation.cjs +25 -10
  5. package/build/format/annotation.cjs.map +3 -3
  6. package/build/format/index.cjs +3 -1
  7. package/build/format/index.cjs.map +3 -3
  8. package/build/index.cjs +2 -1
  9. package/build/index.cjs.map +2 -2
  10. package/build/store/actions.cjs +3 -2
  11. package/build/store/actions.cjs.map +3 -3
  12. package/build/store/constants.cjs +2 -1
  13. package/build/store/constants.cjs.map +3 -3
  14. package/build/store/index.cjs +2 -1
  15. package/build/store/index.cjs.map +3 -3
  16. package/build/store/reducer.cjs +13 -8
  17. package/build/store/reducer.cjs.map +3 -3
  18. package/build/store/selectors.cjs +9 -4
  19. package/build/store/selectors.cjs.map +3 -3
  20. package/build/types.cjs +19 -0
  21. package/build/types.cjs.map +7 -0
  22. package/build-module/block/index.mjs +6 -7
  23. package/build-module/block/index.mjs.map +3 -3
  24. package/build-module/format/annotation.mjs +24 -10
  25. package/build-module/format/annotation.mjs.map +3 -3
  26. package/build-module/format/index.mjs +1 -1
  27. package/build-module/format/index.mjs.map +3 -3
  28. package/build-module/index.mjs +1 -1
  29. package/build-module/index.mjs.map +1 -1
  30. package/build-module/store/actions.mjs +2 -2
  31. package/build-module/store/actions.mjs.map +3 -3
  32. package/build-module/store/constants.mjs +1 -1
  33. package/build-module/store/constants.mjs.map +3 -3
  34. package/build-module/store/index.mjs +1 -1
  35. package/build-module/store/index.mjs.map +3 -3
  36. package/build-module/store/reducer.mjs +12 -8
  37. package/build-module/store/reducer.mjs.map +3 -3
  38. package/build-module/store/selectors.mjs +8 -4
  39. package/build-module/store/selectors.mjs.map +3 -3
  40. package/build-module/types.mjs +1 -0
  41. package/build-module/types.mjs.map +7 -0
  42. package/build-types/block/index.d.ts +2 -0
  43. package/build-types/block/index.d.ts.map +1 -0
  44. package/build-types/format/annotation.d.ts +19 -0
  45. package/build-types/format/annotation.d.ts.map +1 -0
  46. package/build-types/format/index.d.ts +2 -0
  47. package/build-types/format/index.d.ts.map +1 -0
  48. package/build-types/index.d.ts +7 -0
  49. package/build-types/index.d.ts.map +1 -0
  50. package/build-types/store/actions.d.ts +48 -0
  51. package/build-types/store/actions.d.ts.map +1 -0
  52. package/build-types/store/constants.d.ts +5 -0
  53. package/build-types/store/constants.d.ts.map +1 -0
  54. package/build-types/store/index.d.ts +9 -0
  55. package/build-types/store/index.d.ts.map +1 -0
  56. package/build-types/store/reducer.d.ts +14 -0
  57. package/build-types/store/reducer.d.ts.map +1 -0
  58. package/build-types/store/selectors.d.ts +34 -0
  59. package/build-types/store/selectors.d.ts.map +1 -0
  60. package/build-types/types.d.ts +113 -0
  61. package/build-types/types.d.ts.map +1 -0
  62. package/package.json +8 -6
  63. package/src/block/index.ts +52 -0
  64. package/src/format/{annotation.js → annotation.ts} +69 -34
  65. package/src/format/{index.js → index.ts} +1 -1
  66. package/src/store/actions.ts +105 -0
  67. package/src/store/{constants.js → constants.ts} +0 -2
  68. package/src/store/{index.js → index.ts} +0 -2
  69. package/src/store/{reducer.js → reducer.ts} +58 -34
  70. package/src/store/{selectors.js → selectors.ts} +36 -22
  71. package/src/store/test/{reducer.js → reducer.ts} +17 -5
  72. package/src/types.ts +133 -0
  73. package/src/block/index.js +0 -40
  74. package/src/store/actions.js +0 -105
  75. /package/src/{index.js → index.ts} +0 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 3.44.0 (2026-04-15)
6
+
5
7
  ## 3.43.0 (2026-04-01)
6
8
 
7
9
  ## 3.42.0 (2026-03-18)
@@ -1,16 +1,17 @@
1
- // packages/annotations/src/block/index.js
1
+ "use strict";
2
+
3
+ // packages/annotations/src/block/index.ts
2
4
  var import_hooks = require("@wordpress/hooks");
3
5
  var import_data = require("@wordpress/data");
4
- var import_constants = require("../store/constants.cjs");
6
+ var import_store = require("../store/index.cjs");
5
7
  var addAnnotationClassName = (OriginalComponent) => {
6
- return (0, import_data.withSelect)((select, { clientId, className }) => {
7
- const annotations = select(import_constants.STORE_NAME).__experimentalGetAnnotationsForBlock(
8
- clientId
9
- );
8
+ return (0, import_data.withSelect)((select, ownProps) => {
9
+ const { clientId, className } = ownProps;
10
+ const annotations = select(import_store.store).__experimentalGetAnnotationsForBlock(clientId);
10
11
  return {
11
12
  className: annotations.map((annotation) => {
12
13
  return "is-annotated-by-" + annotation.source;
13
- }).concat(className).filter(Boolean).join(" ")
14
+ }).concat(className || "").filter(Boolean).join(" ")
14
15
  };
15
16
  })(OriginalComponent);
16
17
  };
@@ -1,7 +1,7 @@
1
1
  {
2
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,IAAM,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;",
3
+ "sources": ["../../src/block/index.ts"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport type { ComponentType } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { withSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store } from '../store';\nimport type { Annotation } from '../types';\n\ninterface BlockListBlockProps {\n\tclientId: string;\n\tclassName?: string;\n\t[ key: string ]: unknown;\n}\n\n/**\n * Adds annotation className to the block-list-block component.\n *\n * @param OriginalComponent The original BlockListBlock component.\n * @return The enhanced component.\n */\nconst addAnnotationClassName = ( OriginalComponent: ComponentType< any > ) => {\n\treturn withSelect( ( select, ownProps ) => {\n\t\tconst { clientId, className } = ownProps as BlockListBlockProps;\n\t\tconst annotations: Annotation[] =\n\t\t\tselect( store ).__experimentalGetAnnotationsForBlock( clientId );\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": ";;;AAQA,mBAA0B;AAC1B,kBAA2B;AAK3B,mBAAsB;AAetB,IAAM,yBAAyB,CAAE,sBAA6C;AAC7E,aAAO,wBAAY,CAAE,QAAQ,aAAc;AAC1C,UAAM,EAAE,UAAU,UAAU,IAAI;AAChC,UAAM,cACL,OAAQ,kBAAM,EAAE,qCAAsC,QAAS;AAEhE,WAAO;AAAA,MACN,WAAW,YACT,IAAK,CAAE,eAAgB;AACvB,eAAO,qBAAqB,WAAW;AAAA,MACxC,CAAE,EACD,OAAQ,aAAa,EAAG,EACxB,OAAQ,OAAQ,EAChB,KAAM,GAAI;AAAA,IACb;AAAA,EACD,CAAE,EAAG,iBAAkB;AACxB;AAAA,IAEA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AACD;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -16,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
16
17
  };
17
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
19
 
19
- // packages/annotations/src/format/annotation.js
20
+ // packages/annotations/src/format/annotation.ts
20
21
  var annotation_exports = {};
21
22
  __export(annotation_exports, {
22
23
  annotation: () => annotation,
@@ -32,6 +33,9 @@ var ANNOTATION_ATTRIBUTE_PREFIX = "annotation-text-";
32
33
  function applyAnnotations(record, annotations = []) {
33
34
  annotations.forEach((annotation2) => {
34
35
  let { start, end } = annotation2;
36
+ if (typeof start !== "number" || typeof end !== "number") {
37
+ return;
38
+ }
35
39
  if (start > record.text.length) {
36
40
  start = record.text.length;
37
41
  }
@@ -78,7 +82,10 @@ function retrieveAnnotationPositions(formats) {
78
82
  });
79
83
  return positions;
80
84
  }
81
- function updateAnnotationsWithPositions(annotations, positions, { removeAnnotation, updateAnnotationRange }) {
85
+ function updateAnnotationsWithPositions(annotations, positions, {
86
+ removeAnnotation,
87
+ updateAnnotationRange
88
+ }) {
82
89
  annotations.forEach((currentAnnotation) => {
83
90
  const position = positions[currentAnnotation.id];
84
91
  if (!position) {
@@ -86,11 +93,11 @@ function updateAnnotationsWithPositions(annotations, positions, { removeAnnotati
86
93
  return;
87
94
  }
88
95
  const { start, end } = currentAnnotation;
89
- if (start !== position.start || end !== position.end) {
96
+ if (typeof start === "number" && typeof end === "number" && (start !== position.start || end !== (position.end ?? position.start))) {
90
97
  updateAnnotationRange(
91
98
  currentAnnotation.id,
92
99
  position.start,
93
- position.end
100
+ position.end ?? position.start
94
101
  );
95
102
  }
96
103
  });
@@ -104,10 +111,12 @@ var annotation = {
104
111
  className: "class",
105
112
  id: "id"
106
113
  },
107
- edit() {
114
+ interactive: false,
115
+ object: false,
116
+ edit: () => {
108
117
  return null;
109
118
  },
110
- __experimentalGetPropsForEditableTreePreparation(select, { richTextIdentifier, blockClientId }) {
119
+ __experimentalGetPropsForEditableTreePreparation: (select, { richTextIdentifier, blockClientId }) => {
111
120
  return {
112
121
  annotations: select(
113
122
  import_constants.STORE_NAME
@@ -117,23 +126,29 @@ var annotation = {
117
126
  )
118
127
  };
119
128
  },
120
- __experimentalCreatePrepareEditableTree({ annotations }) {
129
+ __experimentalCreatePrepareEditableTree: ({ annotations }) => {
121
130
  return (formats, text) => {
122
131
  if (annotations.length === 0) {
123
132
  return formats;
124
133
  }
125
- let record = { formats, text };
134
+ let record = {
135
+ formats,
136
+ text,
137
+ replacements: [],
138
+ start: 0,
139
+ end: 0
140
+ };
126
141
  record = applyAnnotations(record, annotations);
127
142
  return record.formats;
128
143
  };
129
144
  },
130
- __experimentalGetPropsForEditableTreeChangeHandler(dispatch) {
145
+ __experimentalGetPropsForEditableTreeChangeHandler: (dispatch) => {
131
146
  return {
132
147
  removeAnnotation: dispatch(import_constants.STORE_NAME).__experimentalRemoveAnnotation,
133
148
  updateAnnotationRange: dispatch(import_constants.STORE_NAME).__experimentalUpdateAnnotationRange
134
149
  };
135
150
  },
136
- __experimentalCreateOnChangeEditableValue(props) {
151
+ __experimentalCreateOnChangeEditableValue: (props) => {
137
152
  return (formats) => {
138
153
  const positions = retrieveAnnotationPositions(formats);
139
154
  const { removeAnnotation, updateAnnotationRange, annotations } = props;
@@ -1,7 +1,7 @@
1
1
  {
2
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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MACD,CAAE;AAAA,IACH;AAAA,EACD;AACD;",
3
+ "sources": ["../../src/format/annotation.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { applyFormat, removeFormat } from '@wordpress/rich-text';\nimport type { RichTextValue } from '@wordpress/rich-text';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../store/constants';\nimport type { Annotation, AnnotationFormat } from '../types';\n\nconst FORMAT_NAME = 'core/annotation';\n\nconst ANNOTATION_ATTRIBUTE_PREFIX = 'annotation-text-';\n\n/**\n * Applies given annotations to the given record.\n *\n * @param record The record to apply annotations to.\n * @param annotations The annotation to apply.\n * @return A record with the annotations applied.\n */\nexport function applyAnnotations(\n\trecord: RichTextValue,\n\tannotations: Annotation[] = []\n): RichTextValue {\n\tannotations.forEach( ( annotation ) => {\n\t\tlet { start, end } = annotation;\n\n\t\tif ( typeof start !== 'number' || typeof end !== 'number' ) {\n\t\t\treturn;\n\t\t}\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} as any,\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 record Record to remove annotations from.\n * @return The cleaned record.\n */\nexport function removeAnnotations( record: RichTextValue ): RichTextValue {\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 formats Formats with annotations in there.\n * @return ID keyed positions of annotations.\n */\nfunction retrieveAnnotationPositions(\n\tformats: any[][]\n): Record< string, { start: number; end?: number } > {\n\tconst positions: Record< string, { start: number; end?: number } > = {};\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 annotations The annotations that are currently applied.\n * @param positions The current positions of the given annotations.\n * @param actions\n * @param actions.removeAnnotation Function to remove an annotation from the state.\n * @param actions.updateAnnotationRange Function to update an annotation range in the state.\n */\nfunction updateAnnotationsWithPositions(\n\tannotations: Annotation[],\n\tpositions: Record< string, { start: number; end?: number } >,\n\t{\n\t\tremoveAnnotation,\n\t\tupdateAnnotationRange,\n\t}: {\n\t\tremoveAnnotation: ( annotationId: string ) => void;\n\t\tupdateAnnotationRange: (\n\t\t\tannotationId: string,\n\t\t\tstart: number,\n\t\t\tend: number\n\t\t) => void;\n\t}\n): void {\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 (\n\t\t\ttypeof start === 'number' &&\n\t\t\ttypeof end === 'number' &&\n\t\t\t( start !== position.start ||\n\t\t\t\tend !== ( position.end ?? position.start ) )\n\t\t) {\n\t\t\tupdateAnnotationRange(\n\t\t\t\tcurrentAnnotation.id,\n\t\t\t\tposition.start,\n\t\t\t\tposition.end ?? position.start\n\t\t\t);\n\t\t}\n\t} );\n}\n\nexport const annotation: AnnotationFormat = {\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\tinteractive: false,\n\tobject: false,\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: RichTextValue = {\n\t\t\t\tformats,\n\t\t\t\ttext,\n\t\t\t\treplacements: [],\n\t\t\t\tstart: 0,\n\t\t\t\tend: 0,\n\t\t\t};\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;AAM1C,uBAA2B;AAG3B,IAAM,cAAc;AAEpB,IAAM,8BAA8B;AAS7B,SAAS,iBACf,QACA,cAA4B,CAAC,GACb;AAChB,cAAY,QAAS,CAAEA,gBAAgB;AACtC,QAAI,EAAE,OAAO,IAAI,IAAIA;AAErB,QAAK,OAAO,UAAU,YAAY,OAAO,QAAQ,UAAW;AAC3D;AAAA,IACD;AAEA,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,QAAuC;AACzE,aAAO,+BAAc,QAAQ,mBAAmB,GAAG,OAAO,KAAK,MAAO;AACvE;AAQA,SAAS,4BACR,SACoD;AACpD,QAAM,YAA+D,CAAC;AAEtE,UAAQ,QAAS,CAAE,kBAAkB,MAAO;AAC3C,uBAAmB,oBAAoB,CAAC;AACxC,uBAAmB,iBAAiB;AAAA,MACnC,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EAAE,YAAY,MAAO;AAC/D,WAAO,CAAE,SAAS,SAAU;AAC3B,UAAK,YAAY,WAAW,GAAI;AAC/B,eAAO;AAAA,MACR;AAEA,UAAI,SAAwB;AAAA,QAC3B;AAAA,QACA;AAAA,QACA,cAAc,CAAC;AAAA,QACf,OAAO;AAAA,QACP,KAAK;AAAA,MACN;AACA,eAAS,iBAAkB,QAAQ,WAAY;AAC/C,aAAO,OAAO;AAAA,IACf;AAAA,EACD;AAAA,EACA,oDAAoD,CAAE,aAAc;AACnE,WAAO;AAAA,MACN,kBACC,SAAU,2BAAW,EAAE;AAAA,MACxB,uBACC,SAAU,2BAAW,EAAE;AAAA,IACzB;AAAA,EACD;AAAA,EACA,2CAA2C,CAAE,UAAW;AACvD,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
6
  "names": ["annotation"]
7
7
  }
@@ -1,4 +1,6 @@
1
- // packages/annotations/src/format/index.js
1
+ "use strict";
2
+
3
+ // packages/annotations/src/format/index.ts
2
4
  var import_rich_text = require("@wordpress/rich-text");
3
5
  var import_annotation = require("./annotation.cjs");
4
6
  var { name, ...settings } = import_annotation.annotation;
@@ -1,7 +1,7 @@
1
1
  {
2
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,IAAM,EAAE,MAAM,GAAG,SAAS,IAAI;AAAA,IAE9B,qCAAoB,MAAM,QAAS;",
3
+ "sources": ["../../src/format/index.ts"],
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 as any );\n"],
5
+ "mappings": ";;;AAGA,uBAAmC;AAKnC,wBAA2B;AAE3B,IAAM,EAAE,MAAM,GAAG,SAAS,IAAI;AAAA,IAE9B,qCAAoB,MAAM,QAAgB;",
6
6
  "names": []
7
7
  }
package/build/index.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -16,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
16
17
  };
17
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
19
 
19
- // packages/annotations/src/index.js
20
+ // packages/annotations/src/index.ts
20
21
  var index_exports = {};
21
22
  __export(index_exports, {
22
23
  store: () => import_store.store
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/index.js"],
3
+ "sources": ["../src/index.ts"],
4
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;",
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAO;AACP,mBAAO;AAEP,mBAAsB;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -16,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
16
17
  };
17
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
19
 
19
- // packages/annotations/src/store/actions.js
20
+ // packages/annotations/src/store/actions.ts
20
21
  var actions_exports = {};
21
22
  __export(actions_exports, {
22
23
  __experimentalAddAnnotation: () => __experimentalAddAnnotation,
@@ -42,7 +43,7 @@ function __experimentalAddAnnotation({
42
43
  source,
43
44
  selector
44
45
  };
45
- if (selector === "range") {
46
+ if (selector === "range" && range !== null) {
46
47
  action.range = range;
47
48
  }
48
49
  return action;
@@ -1,7 +1,7 @@
1
1
  {
2
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;",
3
+ "sources": ["../../src/store/actions.ts"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport { v4 as uuid } from 'uuid';\n\n/**\n * Internal dependencies\n */\nimport type { AddAnnotationParameters, AnnotationAction } from '../types';\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 identify groups of annotations.\n *\n * The `range` property is only relevant if the selector is 'range'.\n *\n * @param annotation The annotation to add.\n * @param annotation.blockClientId The blockClientId to add the annotation to.\n * @param annotation.richTextIdentifier Identifier for the RichText instance the annotation applies to.\n * @param annotation.range The range at which to apply this annotation.\n * @param annotation.selector The way to apply this annotation.\n * @param annotation.source The source that added the annotation.\n * @param annotation.id The ID the annotation should have. Generates a UUID by default.\n * @return Action object.\n */\nexport function __experimentalAddAnnotation( {\n\tblockClientId,\n\trichTextIdentifier = null,\n\trange = null,\n\tselector = 'range',\n\tsource = 'default',\n\tid = uuid(),\n}: AddAnnotationParameters ): AnnotationAction {\n\tconst action: AnnotationAction = {\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' && range !== null ) {\n\t\t(\n\t\t\taction as Extract< AnnotationAction, { type: 'ANNOTATION_ADD' } >\n\t\t ).range = range;\n\t}\n\n\treturn action;\n}\n\n/**\n * Removes an annotation with a specific ID.\n *\n * @param annotationId The annotation to remove.\n * @return Action object.\n */\nexport function __experimentalRemoveAnnotation(\n\tannotationId: string\n): AnnotationAction {\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 annotationId ID of the annotation to update.\n * @param start The start of the new range.\n * @param end The end of the new range.\n * @return Action object.\n */\nexport function __experimentalUpdateAnnotationRange(\n\tannotationId: string,\n\tstart: number,\n\tend: number\n): AnnotationAction {\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 source The source to remove.\n * @return Action object.\n */\nexport function __experimentalRemoveAnnotationsBySource(\n\tsource: string\n): AnnotationAction {\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;AA0BpB,SAAS,4BAA6B;AAAA,EAC5C;AAAA,EACA,qBAAqB;AAAA,EACrB,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,SAAS;AAAA,EACT,SAAK,YAAAA,IAAK;AACX,GAA+C;AAC9C,QAAM,SAA2B;AAAA,IAChC,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAEA,MAAK,aAAa,WAAW,UAAU,MAAO;AAC7C,IACC,OACE,QAAQ;AAAA,EACZ;AAEA,SAAO;AACR;AAQO,SAAS,+BACf,cACmB;AACnB,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,EACD;AACD;AAUO,SAAS,oCACf,cACA,OACA,KACmB;AACnB,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAQO,SAAS,wCACf,QACmB;AACnB,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,EACD;AACD;",
6
6
  "names": ["uuid"]
7
7
  }
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -16,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
16
17
  };
17
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
19
 
19
- // packages/annotations/src/store/constants.js
20
+ // packages/annotations/src/store/constants.ts
20
21
  var constants_exports = {};
21
22
  __export(constants_exports, {
22
23
  STORE_NAME: () => STORE_NAME
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/store/constants.js"],
4
- "sourcesContent": ["/**\n * The identifier for the data store.\n *\n * @type {string}\n */\nexport const STORE_NAME = 'core/annotations';\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,IAAM,aAAa;",
3
+ "sources": ["../../src/store/constants.ts"],
4
+ "sourcesContent": ["/**\n * The identifier for the data store.\n */\nexport const STORE_NAME = 'core/annotations';\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,IAAM,aAAa;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -26,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
27
  ));
27
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
29
 
29
- // packages/annotations/src/store/index.js
30
+ // packages/annotations/src/store/index.ts
30
31
  var store_exports = {};
31
32
  __export(store_exports, {
32
33
  store: () => store
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/store/index.js"],
4
- "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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA2C;AAK3C,qBAAoB;AACpB,gBAA2B;AAC3B,cAAyB;AAKzB,uBAA2B;AASpB,IAAM,YAAQ,8BAAkB,6BAAY;AAAA,EAClD,wBAAAA;AAAA,EACA;AAAA,EACA;AACD,CAAE;AAAA,IAEF,sBAAU,KAAM;",
3
+ "sources": ["../../src/store/index.ts"],
4
+ "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 */\nexport const store = createReduxStore( STORE_NAME, {\n\treducer,\n\tselectors,\n\tactions,\n} );\n\nregister( store );\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA2C;AAK3C,qBAAoB;AACpB,gBAA2B;AAC3B,cAAyB;AAKzB,uBAA2B;AAOpB,IAAM,YAAQ,8BAAkB,6BAAY;AAAA,EAClD,wBAAAA;AAAA,EACA;AAAA,EACA;AACD,CAAE;AAAA,IAEF,sBAAU,KAAM;",
6
6
  "names": ["reducer"]
7
7
  }
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -16,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
16
17
  };
17
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
19
 
19
- // packages/annotations/src/store/reducer.js
20
+ // packages/annotations/src/store/reducer.ts
20
21
  var reducer_exports = {};
21
22
  __export(reducer_exports, {
22
23
  annotations: () => annotations,
@@ -27,15 +28,19 @@ function filterWithReference(collection, predicate) {
27
28
  const filteredCollection = collection.filter(predicate);
28
29
  return collection.length === filteredCollection.length ? collection : filteredCollection;
29
30
  }
30
- var mapValues = (obj, callback) => Object.entries(obj).reduce(
31
- (acc, [key, value]) => ({
31
+ var mapValues = (obj, callback) => Object.entries(obj).reduce((acc, [key, value]) => {
32
+ if (value === void 0) {
33
+ return acc;
34
+ }
35
+ return {
32
36
  ...acc,
33
37
  [key]: callback(value)
34
- }),
35
- {}
36
- );
38
+ };
39
+ }, {});
37
40
  function isValidAnnotationRange(annotation) {
38
- return typeof annotation.start === "number" && typeof annotation.end === "number" && annotation.start <= annotation.end;
41
+ return Boolean(
42
+ annotation.range && typeof annotation.range.start === "number" && typeof annotation.range.end === "number" && annotation.range.start <= annotation.range.end
43
+ );
39
44
  }
40
45
  function annotations(state = {}, action) {
41
46
  switch (action.type) {
@@ -49,7 +54,7 @@ function annotations(state = {}, action) {
49
54
  selector: action.selector,
50
55
  range: action.range
51
56
  };
52
- if (newAnnotation.selector === "range" && !isValidAnnotationRange(newAnnotation.range)) {
57
+ if (newAnnotation.selector === "range" && !isValidAnnotationRange(newAnnotation)) {
53
58
  return state;
54
59
  }
55
60
  const previousAnnotationsForBlock = state?.[blockClientId] ?? [];
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/store/reducer.js"],
4
- "sourcesContent": ["/**\n * Filters an array based on the predicate, but keeps the reference the same if\n * the array hasn't changed.\n *\n * @param {Array} collection The collection to filter.\n * @param {Function} predicate Function that determines if the item should stay\n * in the array.\n * @return {Array} Filtered array.\n */\nfunction filterWithReference( collection, predicate ) {\n\tconst filteredCollection = collection.filter( predicate );\n\n\treturn collection.length === filteredCollection.length\n\t\t? collection\n\t\t: filteredCollection;\n}\n\n/**\n * Creates a new object with the same keys, but with `callback()` called as\n * a transformer function on each of the values.\n *\n * @param {Object} obj The object to transform.\n * @param {Function} callback The function to transform each object value.\n * @return {Array} Transformed object.\n */\nconst mapValues = ( obj, callback ) =>\n\tObject.entries( obj ).reduce(\n\t\t( acc, [ key, value ] ) => ( {\n\t\t\t...acc,\n\t\t\t[ key ]: callback( value ),\n\t\t} ),\n\t\t{}\n\t);\n\n/**\n * Verifies whether the given annotations is a valid annotation.\n *\n * @param {Object} annotation The annotation to verify.\n * @return {boolean} Whether the given annotation is valid.\n */\nfunction isValidAnnotationRange( annotation ) {\n\treturn (\n\t\ttypeof annotation.start === 'number' &&\n\t\ttypeof annotation.end === 'number' &&\n\t\tannotation.start <= annotation.end\n\t);\n}\n\n/**\n * Reducer managing annotations.\n *\n * @param {Object} state The annotations currently shown in the editor.\n * @param {Object} action Dispatched action.\n *\n * @return {Array} Updated state.\n */\nexport function annotations( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'ANNOTATION_ADD':\n\t\t\tconst blockClientId = action.blockClientId;\n\t\t\tconst newAnnotation = {\n\t\t\t\tid: action.id,\n\t\t\t\tblockClientId,\n\t\t\t\trichTextIdentifier: action.richTextIdentifier,\n\t\t\t\tsource: action.source,\n\t\t\t\tselector: action.selector,\n\t\t\t\trange: action.range,\n\t\t\t};\n\n\t\t\tif (\n\t\t\t\tnewAnnotation.selector === 'range' &&\n\t\t\t\t! isValidAnnotationRange( newAnnotation.range )\n\t\t\t) {\n\t\t\t\treturn state;\n\t\t\t}\n\n\t\t\tconst previousAnnotationsForBlock = state?.[ blockClientId ] ?? [];\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ blockClientId ]: [\n\t\t\t\t\t...previousAnnotationsForBlock,\n\t\t\t\t\tnewAnnotation,\n\t\t\t\t],\n\t\t\t};\n\n\t\tcase 'ANNOTATION_REMOVE':\n\t\t\treturn mapValues( state, ( annotationsForBlock ) => {\n\t\t\t\treturn filterWithReference(\n\t\t\t\t\tannotationsForBlock,\n\t\t\t\t\t( annotation ) => {\n\t\t\t\t\t\treturn annotation.id !== action.annotationId;\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} );\n\n\t\tcase 'ANNOTATION_UPDATE_RANGE':\n\t\t\treturn mapValues( state, ( annotationsForBlock ) => {\n\t\t\t\tlet hasChangedRange = false;\n\n\t\t\t\tconst newAnnotations = annotationsForBlock.map(\n\t\t\t\t\t( annotation ) => {\n\t\t\t\t\t\tif ( annotation.id === action.annotationId ) {\n\t\t\t\t\t\t\thasChangedRange = true;\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t...annotation,\n\t\t\t\t\t\t\t\trange: {\n\t\t\t\t\t\t\t\t\tstart: action.start,\n\t\t\t\t\t\t\t\t\tend: action.end,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn annotation;\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\treturn hasChangedRange ? newAnnotations : annotationsForBlock;\n\t\t\t} );\n\n\t\tcase 'ANNOTATION_REMOVE_SOURCE':\n\t\t\treturn mapValues( state, ( annotationsForBlock ) => {\n\t\t\t\treturn filterWithReference(\n\t\t\t\t\tannotationsForBlock,\n\t\t\t\t\t( annotation ) => {\n\t\t\t\t\t\treturn annotation.source !== action.source;\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} );\n\t}\n\n\treturn state;\n}\n\nexport default annotations;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAA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AM,iBAAiB,oBAAoB;AAAA,UAC1C,CAAE,eAAgB;AACjB,gBAAK,WAAW,OAAO,OAAO,cAAe;AAC5C,gCAAkB;AAClB,qBAAO;AAAA,gBACN,GAAG;AAAA,gBACH,OAAO;AAAA,kBACN,OAAO,OAAO;AAAA,kBACd,KAAK,OAAO;AAAA,gBACb;AAAA,cACD;AAAA,YACD;AAEA,mBAAO;AAAA,UACR;AAAA,QACD;AAEA,eAAO,kBAAkB,iBAAiB;AAAA,MAC3C,CAAE;AAAA,IAEH,KAAK;AACJ,aAAO,UAAW,OAAO,CAAE,wBAAyB;AACnD,eAAO;AAAA,UACN;AAAA,UACA,CAAE,eAAgB;AACjB,mBAAO,WAAW,WAAW,OAAO;AAAA,UACrC;AAAA,QACD;AAAA,MACD,CAAE;AAAA,EACJ;AAEA,SAAO;AACR;AAEA,IAAO,kBAAQ;",
3
+ "sources": ["../../src/store/reducer.ts"],
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type {\n\tAnnotationAction,\n\tAnnotationsState,\n\tAnnotation,\n\tAnnotationRange,\n} from '../types';\n\n/**\n * Filters an array based on the predicate, but keeps the reference the same if\n * the array hasn't changed.\n *\n * @param collection The collection to filter.\n * @param predicate Function that determines if the item should stay\n * in the array.\n * @return Filtered array.\n */\nfunction filterWithReference< T >(\n\tcollection: T[],\n\tpredicate: ( item: T ) => boolean\n): T[] {\n\tconst filteredCollection = collection.filter( predicate );\n\n\treturn collection.length === filteredCollection.length\n\t\t? collection\n\t\t: filteredCollection;\n}\n\n/**\n * Creates a new object with the same keys, but with `callback()` called as\n * a transformer function on each of the values.\n *\n * @param obj The object to transform.\n * @param callback The function to transform each object value.\n * @return Transformed object.\n */\nconst mapValues = < T, U >(\n\tobj: Partial< Record< string, T > >,\n\tcallback: ( value: T ) => U\n): Partial< Record< string, U > > =>\n\tObject.entries( obj ).reduce( ( acc, [ key, value ] ) => {\n\t\tif ( value === undefined ) {\n\t\t\treturn acc;\n\t\t}\n\t\treturn {\n\t\t\t...acc,\n\t\t\t[ key ]: callback( value ),\n\t\t};\n\t}, {} );\n\n/**\n * Verifies whether the given annotations is a valid annotation.\n *\n * @param annotation The annotation to verify.\n * @param annotation.range The range property of the annotation.\n * @return Whether the given annotation is valid.\n */\nfunction isValidAnnotationRange( annotation: {\n\trange?: AnnotationRange | null;\n} ): boolean {\n\treturn Boolean(\n\t\tannotation.range &&\n\t\t\ttypeof annotation.range.start === 'number' &&\n\t\t\ttypeof annotation.range.end === 'number' &&\n\t\t\tannotation.range.start <= annotation.range.end\n\t);\n}\n\n/**\n * Reducer managing annotations.\n *\n * @param state The annotations currently shown in the editor.\n * @param action Dispatched action.\n * @return Updated state.\n */\nexport function annotations(\n\tstate: AnnotationsState = {},\n\taction: AnnotationAction\n): AnnotationsState {\n\tswitch ( action.type ) {\n\t\tcase 'ANNOTATION_ADD':\n\t\t\tconst blockClientId = action.blockClientId;\n\t\t\tconst newAnnotation: Annotation = {\n\t\t\t\tid: action.id,\n\t\t\t\tblockClientId,\n\t\t\t\trichTextIdentifier: action.richTextIdentifier,\n\t\t\t\tsource: action.source,\n\t\t\t\tselector: action.selector,\n\t\t\t\trange: action.range,\n\t\t\t};\n\n\t\t\tif (\n\t\t\t\tnewAnnotation.selector === 'range' &&\n\t\t\t\t! isValidAnnotationRange( newAnnotation )\n\t\t\t) {\n\t\t\t\treturn state;\n\t\t\t}\n\n\t\t\tconst previousAnnotationsForBlock = state?.[ blockClientId ] ?? [];\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ blockClientId ]: [\n\t\t\t\t\t...previousAnnotationsForBlock,\n\t\t\t\t\tnewAnnotation,\n\t\t\t\t],\n\t\t\t};\n\n\t\tcase 'ANNOTATION_REMOVE':\n\t\t\treturn mapValues( state, ( annotationsForBlock: Annotation[] ) => {\n\t\t\t\treturn filterWithReference(\n\t\t\t\t\tannotationsForBlock,\n\t\t\t\t\t( annotation: Annotation ) => {\n\t\t\t\t\t\treturn annotation.id !== action.annotationId;\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} );\n\n\t\tcase 'ANNOTATION_UPDATE_RANGE':\n\t\t\treturn mapValues( state, ( annotationsForBlock: Annotation[] ) => {\n\t\t\t\tlet hasChangedRange = false;\n\n\t\t\t\tconst newAnnotations = annotationsForBlock.map(\n\t\t\t\t\t( annotation: Annotation ) => {\n\t\t\t\t\t\tif ( annotation.id === action.annotationId ) {\n\t\t\t\t\t\t\thasChangedRange = true;\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t...annotation,\n\t\t\t\t\t\t\t\trange: {\n\t\t\t\t\t\t\t\t\tstart: action.start,\n\t\t\t\t\t\t\t\t\tend: action.end,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn annotation;\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\treturn hasChangedRange ? newAnnotations : annotationsForBlock;\n\t\t\t} );\n\n\t\tcase 'ANNOTATION_REMOVE_SOURCE':\n\t\t\treturn mapValues( state, ( annotationsForBlock: Annotation[] ) => {\n\t\t\t\treturn filterWithReference(\n\t\t\t\t\tannotationsForBlock,\n\t\t\t\t\t( annotation: Annotation ) => {\n\t\t\t\t\t\treturn annotation.source !== action.source;\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} );\n\t}\n\n\treturn state;\n}\n\nexport default annotations;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmBA,SAAS,oBACR,YACA,WACM;AACN,QAAM,qBAAqB,WAAW,OAAQ,SAAU;AAExD,SAAO,WAAW,WAAW,mBAAmB,SAC7C,aACA;AACJ;AAUA,IAAM,YAAY,CACjB,KACA,aAEA,OAAO,QAAS,GAAI,EAAE,OAAQ,CAAE,KAAK,CAAE,KAAK,KAAM,MAAO;AACxD,MAAK,UAAU,QAAY;AAC1B,WAAO;AAAA,EACR;AACA,SA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AO;AAAA,gBACb;AAAA,cACD;AAAA,YACD;AAEA,mBAAO;AAAA,UACR;AAAA,QACD;AAEA,eAAO,kBAAkB,iBAAiB;AAAA,MAC3C,CAAE;AAAA,IAEH,KAAK;AACJ,aAAO,UAAW,OAAO,CAAE,wBAAuC;AACjE,eAAO;AAAA,UACN;AAAA,UACA,CAAE,eAA4B;AAC7B,mBAAO,WAAW,WAAW,OAAO;AAAA,UACrC;AAAA,QACD;AAAA,MACD,CAAE;AAAA,EACJ;AAEA,SAAO;AACR;AAEA,IAAO,kBAAQ;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -16,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
16
17
  };
17
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
19
 
19
- // packages/annotations/src/store/selectors.js
20
+ // packages/annotations/src/store/selectors.ts
20
21
  var selectors_exports = {};
21
22
  __export(selectors_exports, {
22
23
  __experimentalGetAllAnnotationsForBlock: () => __experimentalGetAllAnnotationsForBlock,
@@ -33,7 +34,9 @@ var __experimentalGetAnnotationsForBlock = (0, import_data.createSelector)(
33
34
  return annotation.selector === "block";
34
35
  });
35
36
  },
36
- (state, blockClientId) => [state?.[blockClientId] ?? EMPTY_ARRAY]
37
+ (state, blockClientId) => [
38
+ state?.[blockClientId] ?? EMPTY_ARRAY
39
+ ]
37
40
  );
38
41
  function __experimentalGetAllAnnotationsForBlock(state, blockClientId) {
39
42
  return state?.[blockClientId] ?? EMPTY_ARRAY;
@@ -50,10 +53,12 @@ var __experimentalGetAnnotationsForRichText = (0, import_data.createSelector)(
50
53
  };
51
54
  });
52
55
  },
53
- (state, blockClientId) => [state?.[blockClientId] ?? EMPTY_ARRAY]
56
+ (state, blockClientId) => [
57
+ state?.[blockClientId] ?? EMPTY_ARRAY
58
+ ]
54
59
  );
55
60
  function __experimentalGetAnnotations(state) {
56
- return Object.values(state).flat();
61
+ return Object.values(state).filter((arr) => Boolean(arr)).flat();
57
62
  }
58
63
  // Annotate the CommonJS export names for ESM import in node:
59
64
  0 && (module.exports = {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/store/selectors.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createSelector } from '@wordpress/data';\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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA+B;AAW/B,IAAM,cAAc,CAAC;AAUd,IAAM,2CAAuC;AAAA,EACnD,CAAE,OAAO,kBAAmB;AAC3B,YAAS,QAAS,aAAc,KAAK,CAAC,GAAI,OAAQ,CAAE,eAAgB;AACnE,aAAO,WAAW,aAAa;AAAA,IAChC,CAAE;AAAA,EACH;AAAA,EACA,CAAE,OAAO,kBAAmB,CAAE,QAAS,aAAc,KAAK,WAAY;AACvE;AAEO,SAAS,wCACf,OACA,eACC;AACD,SAAO,QAAS,aAAc,KAAK;AACpC;AAcO,IAAM,8CAA0C;AAAA,EACtD,CAAE,OAAO,eAAe,uBAAwB;AAC/C,YAAS,QAAS,aAAc,KAAK,CAAC,GACpC,OAAQ,CAAE,eAAgB;AAC1B,aACC,WAAW,aAAa,WACxB,uBAAuB,WAAW;AAAA,IAEpC,CAAE,EACD,IAAK,CAAE,eAAgB;AACvB,YAAM,EAAE,OAAO,GAAG,MAAM,IAAI;AAE5B,aAAO;AAAA,QACN,GAAG;AAAA,QACH,GAAG;AAAA,MACJ;AAAA,IACD,CAAE;AAAA,EACJ;AAAA,EACA,CAAE,OAAO,kBAAmB,CAAE,QAAS,aAAc,KAAK,WAAY;AACvE;AAQO,SAAS,6BAA8B,OAAQ;AACrD,SAAO,OAAO,OAAQ,KAAM,EAAE,KAAK;AACpC;",
3
+ "sources": ["../../src/store/selectors.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createSelector } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport type { AnnotationsState, Annotation } from '../types';\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 */\nconst EMPTY_ARRAY: Annotation[] = [];\n\n/**\n * Returns the annotations for a specific client ID.\n *\n * @param state Editor state.\n * @param blockClientId The ID of the block to get the annotations for.\n * @return The annotations applicable to this block.\n */\nexport const __experimentalGetAnnotationsForBlock = createSelector(\n\t( state: AnnotationsState, blockClientId: string ): Annotation[] => {\n\t\treturn ( state?.[ blockClientId ] ?? [] ).filter( ( annotation ) => {\n\t\t\treturn annotation.selector === 'block';\n\t\t} );\n\t},\n\t( state: AnnotationsState, blockClientId: string ) => [\n\t\tstate?.[ blockClientId ] ?? EMPTY_ARRAY,\n\t]\n);\n\nexport function __experimentalGetAllAnnotationsForBlock(\n\tstate: AnnotationsState,\n\tblockClientId: string\n): Annotation[] {\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 state Editor state.\n * @param blockClientId The client ID for the block.\n * @param richTextIdentifier Unique identifier that identifies the given RichText.\n * @return All the annotations relevant for the `RichText`.\n */\nexport const __experimentalGetAnnotationsForRichText = createSelector(\n\t(\n\t\tstate: AnnotationsState,\n\t\tblockClientId: string,\n\t\trichTextIdentifier: string\n\t): Annotation[] => {\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: AnnotationsState, blockClientId: string ) => [\n\t\tstate?.[ blockClientId ] ?? EMPTY_ARRAY,\n\t]\n);\n\n/**\n * Returns all annotations in the editor state.\n *\n * @param state Editor state.\n * @return All annotations currently applied.\n */\nexport function __experimentalGetAnnotations(\n\tstate: AnnotationsState\n): Annotation[] {\n\treturn Object.values( state )\n\t\t.filter( ( arr ): arr is Annotation[] => Boolean( arr ) )\n\t\t.flat();\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA+B;AAc/B,IAAM,cAA4B,CAAC;AAS5B,IAAM,2CAAuC;AAAA,EACnD,CAAE,OAAyB,kBAAyC;AACnE,YAAS,QAAS,aAAc,KAAK,CAAC,GAAI,OAAQ,CAAE,eAAgB;AACnE,aAAO,WAAW,aAAa;AAAA,IAChC,CAAE;AAAA,EACH;AAAA,EACA,CAAE,OAAyB,kBAA2B;AAAA,IACrD,QAAS,aAAc,KAAK;AAAA,EAC7B;AACD;AAEO,SAAS,wCACf,OACA,eACe;AACf,SAAO,QAAS,aAAc,KAAK;AACpC;AAcO,IAAM,8CAA0C;AAAA,EACtD,CACC,OACA,eACA,uBACkB;AAClB,YAAS,QAAS,aAAc,KAAK,CAAC,GACpC,OAAQ,CAAE,eAAgB;AAC1B,aACC,WAAW,aAAa,WACxB,uBAAuB,WAAW;AAAA,IAEpC,CAAE,EACD,IAAK,CAAE,eAAgB;AACvB,YAAM,EAAE,OAAO,GAAG,MAAM,IAAI;AAE5B,aAAO;AAAA,QACN,GAAG;AAAA,QACH,GAAG;AAAA,MACJ;AAAA,IACD,CAAE;AAAA,EACJ;AAAA,EACA,CAAE,OAAyB,kBAA2B;AAAA,IACrD,QAAS,aAAc,KAAK;AAAA,EAC7B;AACD;AAQO,SAAS,6BACf,OACe;AACf,SAAO,OAAO,OAAQ,KAAM,EAC1B,OAAQ,CAAE,QAA8B,QAAS,GAAI,CAAE,EACvD,KAAK;AACR;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // packages/annotations/src/types.ts
17
+ var types_exports = {};
18
+ module.exports = __toCommonJS(types_exports);
19
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/types.ts"],
4
+ "sourcesContent": ["/**\n * Represents a range in text content.\n */\nexport interface AnnotationRange {\n\t/** The offset where the annotation should start. */\n\tstart: number;\n\t/** The offset where the annotation should end. */\n\tend: number;\n}\n\n/**\n * Represents an annotation selector type.\n */\nexport type AnnotationSelector = 'range' | 'block';\n\n/**\n * Base annotation interface.\n */\nexport interface Annotation {\n\t/** Unique identifier for the annotation. */\n\tid: string;\n\t/** The block client ID this annotation applies to. */\n\tblockClientId: string;\n\t/** The source that created this annotation. */\n\tsource: string;\n\t/** The type of selector used for this annotation. */\n\tselector: AnnotationSelector;\n\t/** Rich text identifier for range annotations. */\n\trichTextIdentifier?: string | null;\n\t/** Range for range-based annotations. */\n\trange?: AnnotationRange | null;\n\t/** Start position for annotations returned from selectors. */\n\tstart?: number;\n\t/** End position for annotations returned from selectors. */\n\tend?: number;\n}\n\n/**\n * Parameters for adding an annotation.\n */\nexport interface AddAnnotationParameters {\n\t/** The blockClientId to add the annotation to. */\n\tblockClientId: string;\n\t/** Identifier for the RichText instance the annotation applies to. */\n\trichTextIdentifier?: string | null;\n\t/** The range at which to apply this annotation. */\n\trange?: AnnotationRange | null;\n\t/** The way to apply this annotation. */\n\tselector?: AnnotationSelector;\n\t/** The source that added the annotation. */\n\tsource?: string;\n\t/** The ID the annotation should have. Generates a UUID by default. */\n\tid?: string;\n}\n\n/**\n * Store state interface.\n */\nexport type AnnotationsState = Partial< Record< string, Annotation[] > >;\n\n/**\n * Action types.\n */\nexport type AnnotationAction =\n\t| {\n\t\t\ttype: 'ANNOTATION_ADD';\n\t\t\tid: string;\n\t\t\tblockClientId: string;\n\t\t\trichTextIdentifier: string | null;\n\t\t\tsource: string;\n\t\t\tselector: AnnotationSelector;\n\t\t\trange?: AnnotationRange;\n\t }\n\t| {\n\t\t\ttype: 'ANNOTATION_REMOVE';\n\t\t\tannotationId: string;\n\t }\n\t| {\n\t\t\ttype: 'ANNOTATION_UPDATE_RANGE';\n\t\t\tannotationId: string;\n\t\t\tstart: number;\n\t\t\tend: number;\n\t }\n\t| {\n\t\t\ttype: 'ANNOTATION_REMOVE_SOURCE';\n\t\t\tsource: string;\n\t };\n\n/**\n * Format registration interface for annotations.\n */\nexport interface AnnotationFormat {\n\tname: string;\n\ttitle: string;\n\ttagName: string;\n\tclassName: string;\n\tattributes: {\n\t\tclassName: string;\n\t\tid: string;\n\t};\n\tinteractive: boolean;\n\tobject: boolean;\n\tedit: () => null;\n\t__experimentalGetPropsForEditableTreePreparation: (\n\t\tselect: any,\n\t\tprops: {\n\t\t\trichTextIdentifier: string;\n\t\t\tblockClientId: string;\n\t\t}\n\t) => {\n\t\tannotations: Annotation[];\n\t};\n\t__experimentalCreatePrepareEditableTree: ( props: {\n\t\tannotations: Annotation[];\n\t} ) => ( formats: any[], text: string ) => any[];\n\t__experimentalGetPropsForEditableTreeChangeHandler: ( dispatch: any ) => {\n\t\tremoveAnnotation: ( annotationId: string ) => void;\n\t\tupdateAnnotationRange: (\n\t\t\tannotationId: string,\n\t\t\tstart: number,\n\t\t\tend: number\n\t\t) => void;\n\t};\n\t__experimentalCreateOnChangeEditableValue: ( props: {\n\t\tremoveAnnotation: ( annotationId: string ) => void;\n\t\tupdateAnnotationRange: (\n\t\t\tannotationId: string,\n\t\t\tstart: number,\n\t\t\tend: number\n\t\t) => void;\n\t\tannotations: Annotation[];\n\t} ) => ( formats: any[] ) => void;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
6
+ "names": []
7
+ }
@@ -1,16 +1,15 @@
1
- // packages/annotations/src/block/index.js
1
+ // packages/annotations/src/block/index.ts
2
2
  import { addFilter } from "@wordpress/hooks";
3
3
  import { withSelect } from "@wordpress/data";
4
- import { STORE_NAME } from "../store/constants.mjs";
4
+ import { store } from "../store/index.mjs";
5
5
  var addAnnotationClassName = (OriginalComponent) => {
6
- return withSelect((select, { clientId, className }) => {
7
- const annotations = select(STORE_NAME).__experimentalGetAnnotationsForBlock(
8
- clientId
9
- );
6
+ return withSelect((select, ownProps) => {
7
+ const { clientId, className } = ownProps;
8
+ const annotations = select(store).__experimentalGetAnnotationsForBlock(clientId);
10
9
  return {
11
10
  className: annotations.map((annotation) => {
12
11
  return "is-annotated-by-" + annotation.source;
13
- }).concat(className).filter(Boolean).join(" ")
12
+ }).concat(className || "").filter(Boolean).join(" ")
14
13
  };
15
14
  })(OriginalComponent);
16
15
  };
@@ -1,7 +1,7 @@
1
1
  {
2
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,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAK3B,SAAS,kBAAkB;AAO3B,IAAM,yBAAyB,CAAE,sBAAuB;AACvD,SAAO,WAAY,CAAE,QAAQ,EAAE,UAAU,UAAU,MAAO;AACzD,UAAM,cACL,OAAQ,UAAW,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;AAEA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AACD;",
3
+ "sources": ["../../src/block/index.ts"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport type { ComponentType } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { withSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store } from '../store';\nimport type { Annotation } from '../types';\n\ninterface BlockListBlockProps {\n\tclientId: string;\n\tclassName?: string;\n\t[ key: string ]: unknown;\n}\n\n/**\n * Adds annotation className to the block-list-block component.\n *\n * @param OriginalComponent The original BlockListBlock component.\n * @return The enhanced component.\n */\nconst addAnnotationClassName = ( OriginalComponent: ComponentType< any > ) => {\n\treturn withSelect( ( select, ownProps ) => {\n\t\tconst { clientId, className } = ownProps as BlockListBlockProps;\n\t\tconst annotations: Annotation[] =\n\t\t\tselect( store ).__experimentalGetAnnotationsForBlock( clientId );\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": ";AAQA,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAK3B,SAAS,aAAa;AAetB,IAAM,yBAAyB,CAAE,sBAA6C;AAC7E,SAAO,WAAY,CAAE,QAAQ,aAAc;AAC1C,UAAM,EAAE,UAAU,UAAU,IAAI;AAChC,UAAM,cACL,OAAQ,KAAM,EAAE,qCAAsC,QAAS;AAEhE,WAAO;AAAA,MACN,WAAW,YACT,IAAK,CAAE,eAAgB;AACvB,eAAO,qBAAqB,WAAW;AAAA,MACxC,CAAE,EACD,OAAQ,aAAa,EAAG,EACxB,OAAQ,OAAQ,EAChB,KAAM,GAAI;AAAA,IACb;AAAA,EACD,CAAE,EAAG,iBAAkB;AACxB;AAEA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AACD;",
6
6
  "names": []
7
7
  }