@wordpress/annotations 3.32.0 → 3.32.1-next.b8c8708f3.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,52 +1,20 @@
1
- /**
2
- * Filters an array based on the predicate, but keeps the reference the same if
3
- * the array hasn't changed.
4
- *
5
- * @param {Array} collection The collection to filter.
6
- * @param {Function} predicate Function that determines if the item should stay
7
- * in the array.
8
- * @return {Array} Filtered array.
9
- */
10
1
  function filterWithReference(collection, predicate) {
11
2
  const filteredCollection = collection.filter(predicate);
12
3
  return collection.length === filteredCollection.length ? collection : filteredCollection;
13
4
  }
14
-
15
- /**
16
- * Creates a new object with the same keys, but with `callback()` called as
17
- * a transformer function on each of the values.
18
- *
19
- * @param {Object} obj The object to transform.
20
- * @param {Function} callback The function to transform each object value.
21
- * @return {Array} Transformed object.
22
- */
23
- const mapValues = (obj, callback) => Object.entries(obj).reduce((acc, [key, value]) => ({
24
- ...acc,
25
- [key]: callback(value)
26
- }), {});
27
-
28
- /**
29
- * Verifies whether the given annotations is a valid annotation.
30
- *
31
- * @param {Object} annotation The annotation to verify.
32
- * @return {boolean} Whether the given annotation is valid.
33
- */
5
+ const mapValues = (obj, callback) => Object.entries(obj).reduce(
6
+ (acc, [key, value]) => ({
7
+ ...acc,
8
+ [key]: callback(value)
9
+ }),
10
+ {}
11
+ );
34
12
  function isValidAnnotationRange(annotation) {
35
- return typeof annotation.start === 'number' && typeof annotation.end === 'number' && annotation.start <= annotation.end;
13
+ return typeof annotation.start === "number" && typeof annotation.end === "number" && annotation.start <= annotation.end;
36
14
  }
37
-
38
- /**
39
- * Reducer managing annotations.
40
- *
41
- * @param {Object} state The annotations currently shown in the editor.
42
- * @param {Object} action Dispatched action.
43
- *
44
- * @return {Array} Updated state.
45
- */
46
- export function annotations(state = {}, action) {
47
- var _state$blockClientId;
15
+ function annotations(state = {}, action) {
48
16
  switch (action.type) {
49
- case 'ANNOTATION_ADD':
17
+ case "ANNOTATION_ADD":
50
18
  const blockClientId = action.blockClientId;
51
19
  const newAnnotation = {
52
20
  id: action.id,
@@ -56,46 +24,61 @@ export function annotations(state = {}, action) {
56
24
  selector: action.selector,
57
25
  range: action.range
58
26
  };
59
- if (newAnnotation.selector === 'range' && !isValidAnnotationRange(newAnnotation.range)) {
27
+ if (newAnnotation.selector === "range" && !isValidAnnotationRange(newAnnotation.range)) {
60
28
  return state;
61
29
  }
62
- const previousAnnotationsForBlock = (_state$blockClientId = state?.[blockClientId]) !== null && _state$blockClientId !== void 0 ? _state$blockClientId : [];
30
+ const previousAnnotationsForBlock = state?.[blockClientId] ?? [];
63
31
  return {
64
32
  ...state,
65
- [blockClientId]: [...previousAnnotationsForBlock, newAnnotation]
33
+ [blockClientId]: [
34
+ ...previousAnnotationsForBlock,
35
+ newAnnotation
36
+ ]
66
37
  };
67
- case 'ANNOTATION_REMOVE':
68
- return mapValues(state, annotationsForBlock => {
69
- return filterWithReference(annotationsForBlock, annotation => {
70
- return annotation.id !== action.annotationId;
71
- });
38
+ case "ANNOTATION_REMOVE":
39
+ return mapValues(state, (annotationsForBlock) => {
40
+ return filterWithReference(
41
+ annotationsForBlock,
42
+ (annotation) => {
43
+ return annotation.id !== action.annotationId;
44
+ }
45
+ );
72
46
  });
73
- case 'ANNOTATION_UPDATE_RANGE':
74
- return mapValues(state, annotationsForBlock => {
47
+ case "ANNOTATION_UPDATE_RANGE":
48
+ return mapValues(state, (annotationsForBlock) => {
75
49
  let hasChangedRange = false;
76
- const newAnnotations = annotationsForBlock.map(annotation => {
77
- if (annotation.id === action.annotationId) {
78
- hasChangedRange = true;
79
- return {
80
- ...annotation,
81
- range: {
82
- start: action.start,
83
- end: action.end
84
- }
85
- };
50
+ const newAnnotations = annotationsForBlock.map(
51
+ (annotation) => {
52
+ if (annotation.id === action.annotationId) {
53
+ hasChangedRange = true;
54
+ return {
55
+ ...annotation,
56
+ range: {
57
+ start: action.start,
58
+ end: action.end
59
+ }
60
+ };
61
+ }
62
+ return annotation;
86
63
  }
87
- return annotation;
88
- });
64
+ );
89
65
  return hasChangedRange ? newAnnotations : annotationsForBlock;
90
66
  });
91
- case 'ANNOTATION_REMOVE_SOURCE':
92
- return mapValues(state, annotationsForBlock => {
93
- return filterWithReference(annotationsForBlock, annotation => {
94
- return annotation.source !== action.source;
95
- });
67
+ case "ANNOTATION_REMOVE_SOURCE":
68
+ return mapValues(state, (annotationsForBlock) => {
69
+ return filterWithReference(
70
+ annotationsForBlock,
71
+ (annotation) => {
72
+ return annotation.source !== action.source;
73
+ }
74
+ );
96
75
  });
97
76
  }
98
77
  return state;
99
78
  }
100
- export default annotations;
101
- //# sourceMappingURL=reducer.js.map
79
+ var reducer_default = annotations;
80
+ export {
81
+ annotations,
82
+ reducer_default as default
83
+ };
84
+ //# sourceMappingURL=reducer.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["filterWithReference","collection","predicate","filteredCollection","filter","length","mapValues","obj","callback","Object","entries","reduce","acc","key","value","isValidAnnotationRange","annotation","start","end","annotations","state","action","_state$blockClientId","type","blockClientId","newAnnotation","id","richTextIdentifier","source","selector","range","previousAnnotationsForBlock","annotationsForBlock","annotationId","hasChangedRange","newAnnotations","map"],"sources":["@wordpress/annotations/src/store/reducer.js"],"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"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,mBAAmBA,CAAEC,UAAU,EAAEC,SAAS,EAAG;EACrD,MAAMC,kBAAkB,GAAGF,UAAU,CAACG,MAAM,CAAEF,SAAU,CAAC;EAEzD,OAAOD,UAAU,CAACI,MAAM,KAAKF,kBAAkB,CAACE,MAAM,GACnDJ,UAAU,GACVE,kBAAkB;AACtB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMG,SAAS,GAAGA,CAAEC,GAAG,EAAEC,QAAQ,KAChCC,MAAM,CAACC,OAAO,CAAEH,GAAI,CAAC,CAACI,MAAM,CAC3B,CAAEC,GAAG,EAAE,CAAEC,GAAG,EAAEC,KAAK,CAAE,MAAQ;EAC5B,GAAGF,GAAG;EACN,CAAEC,GAAG,GAAIL,QAAQ,CAAEM,KAAM;AAC1B,CAAC,CAAE,EACH,CAAC,CACF,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,sBAAsBA,CAAEC,UAAU,EAAG;EAC7C,OACC,OAAOA,UAAU,CAACC,KAAK,KAAK,QAAQ,IACpC,OAAOD,UAAU,CAACE,GAAG,KAAK,QAAQ,IAClCF,UAAU,CAACC,KAAK,IAAID,UAAU,CAACE,GAA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AAKA,UAAU,CAACU,EAAE,KAAKL,MAAM,CAACY,YAAY,EAAG;YAC5CC,eAAe,GAAG,IAAI;YACtB,OAAO;cACN,GAAGlB,UAAU;cACbc,KAAK,EAAE;gBACNb,KAAK,EAAEI,MAAM,CAACJ,KAAK;gBACnBC,GAAG,EAAEG,MAAM,CAACH;cACb;YACD,CAAC;UACF;UAEA,OAAOF,UAAU;QAClB,CACD,CAAC;QAED,OAAOkB,eAAe,GAAGC,cAAc,GAAGH,mBAAmB;MAC9D,CAAE,CAAC;IAEJ,KAAK,0BAA0B;MAC9B,OAAO1B,SAAS,CAAEc,KAAK,EAAIY,mBAAmB,IAAM;QACnD,OAAOhC,mBAAmB,CACzBgC,mBAAmB,EACjBhB,UAAU,IAAM;UACjB,OAAOA,UAAU,CAACY,MAAM,KAAKP,MAAM,CAACO,MAAM;QAC3C,CACD,CAAC;MACF,CAAE,CAAC;EACL;EAEA,OAAOR,KAAK;AACb;AAEA,eAAeD,WAAW","ignoreList":[]}
1
+ {
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": "AASA,SAAS,oBAAqB,YAAY,WAAY;AACrD,QAAM,qBAAqB,WAAW,OAAQ,SAAU;AAExD,SAAO,WAAW,WAAW,mBAAmB,SAC7C,aACA;AACJ;AAUA,MAAM,YAAY,CAAE,KAAK,aACxB,OAAO,QAAS,GAAI,EAAE;AAAA,EACrB,CAAE,KAAK,CAAE,KAAK,KAAM,OAAS;AAAA,IAC5B,GAAG;AAAA,IACH,CAAE,GAAI,GAAG,SAAU,KAAM;AAAA,EAC1B;AAAA,EACA,CAAC;AACF;AAQD,SAAS,uBAAwB,YAAa;AAC7C,SACC,OAAO,WAAW,UAAU,YAC5B,OAAO,WAAW,QAAQ,YAC1B,WAAW,SAAS,WAAW;AAEjC;AAUO,SAAS,YAAa,QAAQ,CAAC,GAAG,QAAS;AACjD,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK;AACJ,YAAM,gBAAgB,OAAO;AAC7B,YAAM,gBAAgB;AAAA,QACrB,IA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- */
4
- import { createSelector } from '@wordpress/data';
5
-
6
- /**
7
- * Shared reference to an empty array for cases where it is important to avoid
8
- * returning a new array reference on every invocation, as in a connected or
9
- * other pure component which performs `shouldComponentUpdate` check on props.
10
- * This should be used as a last resort, since the normalized data should be
11
- * maintained by the reducer result in state.
12
- *
13
- * @type {Array}
14
- */
1
+ import { createSelector } from "@wordpress/data";
15
2
  const EMPTY_ARRAY = [];
16
-
17
- /**
18
- * Returns the annotations for a specific client ID.
19
- *
20
- * @param {Object} state Editor state.
21
- * @param {string} clientId The ID of the block to get the annotations for.
22
- *
23
- * @return {Array} The annotations applicable to this block.
24
- */
25
- export const __experimentalGetAnnotationsForBlock = createSelector((state, blockClientId) => {
26
- var _state$blockClientId;
27
- return ((_state$blockClientId = state?.[blockClientId]) !== null && _state$blockClientId !== void 0 ? _state$blockClientId : []).filter(annotation => {
28
- return annotation.selector === 'block';
29
- });
30
- }, (state, blockClientId) => {
31
- var _state$blockClientId2;
32
- return [(_state$blockClientId2 = state?.[blockClientId]) !== null && _state$blockClientId2 !== void 0 ? _state$blockClientId2 : EMPTY_ARRAY];
33
- });
34
- export function __experimentalGetAllAnnotationsForBlock(state, blockClientId) {
35
- var _state$blockClientId3;
36
- return (_state$blockClientId3 = state?.[blockClientId]) !== null && _state$blockClientId3 !== void 0 ? _state$blockClientId3 : EMPTY_ARRAY;
3
+ const __experimentalGetAnnotationsForBlock = createSelector(
4
+ (state, blockClientId) => {
5
+ return (state?.[blockClientId] ?? []).filter((annotation) => {
6
+ return annotation.selector === "block";
7
+ });
8
+ },
9
+ (state, blockClientId) => [state?.[blockClientId] ?? EMPTY_ARRAY]
10
+ );
11
+ function __experimentalGetAllAnnotationsForBlock(state, blockClientId) {
12
+ return state?.[blockClientId] ?? EMPTY_ARRAY;
37
13
  }
38
-
39
- /**
40
- * Returns the annotations that apply to the given RichText instance.
41
- *
42
- * Both a blockClientId and a richTextIdentifier are required. This is because
43
- * a block might have multiple `RichText` components. This does mean that every
44
- * block needs to implement annotations itself.
45
- *
46
- * @param {Object} state Editor state.
47
- * @param {string} blockClientId The client ID for the block.
48
- * @param {string} richTextIdentifier Unique identifier that identifies the given RichText.
49
- * @return {Array} All the annotations relevant for the `RichText`.
50
- */
51
- export const __experimentalGetAnnotationsForRichText = createSelector((state, blockClientId, richTextIdentifier) => {
52
- var _state$blockClientId4;
53
- return ((_state$blockClientId4 = state?.[blockClientId]) !== null && _state$blockClientId4 !== void 0 ? _state$blockClientId4 : []).filter(annotation => {
54
- return annotation.selector === 'range' && richTextIdentifier === annotation.richTextIdentifier;
55
- }).map(annotation => {
56
- const {
57
- range,
58
- ...other
59
- } = annotation;
60
- return {
61
- ...range,
62
- ...other
63
- };
64
- });
65
- }, (state, blockClientId) => {
66
- var _state$blockClientId5;
67
- return [(_state$blockClientId5 = state?.[blockClientId]) !== null && _state$blockClientId5 !== void 0 ? _state$blockClientId5 : EMPTY_ARRAY];
68
- });
69
-
70
- /**
71
- * Returns all annotations in the editor state.
72
- *
73
- * @param {Object} state Editor state.
74
- * @return {Array} All annotations currently applied.
75
- */
76
- export function __experimentalGetAnnotations(state) {
14
+ const __experimentalGetAnnotationsForRichText = createSelector(
15
+ (state, blockClientId, richTextIdentifier) => {
16
+ return (state?.[blockClientId] ?? []).filter((annotation) => {
17
+ return annotation.selector === "range" && richTextIdentifier === annotation.richTextIdentifier;
18
+ }).map((annotation) => {
19
+ const { range, ...other } = annotation;
20
+ return {
21
+ ...range,
22
+ ...other
23
+ };
24
+ });
25
+ },
26
+ (state, blockClientId) => [state?.[blockClientId] ?? EMPTY_ARRAY]
27
+ );
28
+ function __experimentalGetAnnotations(state) {
77
29
  return Object.values(state).flat();
78
30
  }
79
- //# sourceMappingURL=selectors.js.map
31
+ export {
32
+ __experimentalGetAllAnnotationsForBlock,
33
+ __experimentalGetAnnotations,
34
+ __experimentalGetAnnotationsForBlock,
35
+ __experimentalGetAnnotationsForRichText
36
+ };
37
+ //# sourceMappingURL=selectors.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["createSelector","EMPTY_ARRAY","__experimentalGetAnnotationsForBlock","state","blockClientId","_state$blockClientId","filter","annotation","selector","_state$blockClientId2","__experimentalGetAllAnnotationsForBlock","_state$blockClientId3","__experimentalGetAnnotationsForRichText","richTextIdentifier","_state$blockClientId4","map","range","other","_state$blockClientId5","__experimentalGetAnnotations","Object","values","flat"],"sources":["@wordpress/annotations/src/store/selectors.js"],"sourcesContent":["/**\n * 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"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,cAAc,QAAQ,iBAAiB;;AAEhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAW,GAAG,EAAE;;AAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,oCAAoC,GAAGF,cAAc,CACjE,CAAEG,KAAK,EAAEC,aAAa,KAAM;EAAA,IAAAC,oBAAA;EAC3B,OAAO,EAAAA,oBAAA,GAAEF,KAAK,GAAIC,aAAa,CAAE,cAAAC,oBAAA,cAAAA,oBAAA,GAAI,EAAE,EAAGC,MAAM,CAAIC,UAAU,IAAM;IACnE,OAAOA,UAAU,CAACC,QAAQ,KAAK,OAAO;EACvC,CAAE,CAAC;AACJ,CAAC,EACD,CAAEL,KAAK,EAAEC,aAAa;EAAA,IAAAK,qBAAA;EAAA,OAAM,EAAAA,qBAAA,GAAEN,KAAK,GAAIC,aAAa,CAAE,cAAAK,qBAAA,cAAAA,qBAAA,GAAIR,WAAW,CAAE;AAAA,CACxE,CAAC;AAED,OAAO,SAASS,uCAAuCA,CACtDP,KAAK,EACLC,aAAa,EACZ;EAAA,IAAAO,qBAAA;EACD,QAAAA,qBAAA,GAAOR,KAAK,GAAIC,aAAa,CAAE,cAAAO,qBAAA,cAAAA,qBAAA,GAAIV,WAAW;AAC/C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMW,uCAAuC,GAAGZ,cAAc,CACpE,CAAEG,KAAK,EAAEC,aAAa,EAAES,kBAAkB,KAAM;EAAA,IAAAC,qBAAA;EAC/C,OAAO,EAAAA,qBAAA,GAAEX,KAAK,GAAIC,aAAa,CAAE,cAAAU,qBAAA,cAAAA,qBAAA,GAAI,EAAE,EACrCR,MAAM,CAAIC,UAAU,IAAM;IAC1B,OACCA,UAAU,CAACC,QAAQ,KAAK,OAAO,IAC/BK,kBAAkB,KAAKN,UAAU,CAACM,kBAAkB;EAEtD,CAAE,CAAC,CACFE,GAAG,CAAIR,UAAU,IAAM;IACvB,MAAM;MAAES,KAAK;MAAE,GAAGC;IAAM,CAAC,GAAGV,UAAU;IAEtC,OAAO;MACN,GAAGS,KAAK;MACR,GAAGC;IACJ,CAAC;EACF,CAAE,CAAC;AACL,CAAC,EACD,CAAEd,KAAK,EAAEC,aAAa;EAAA,IAAAc,qBAAA;EAAA,OAAM,EAAAA,qBAAA,GAAEf,KAAK,GAAIC,aAAa,CAAE,cAAAc,qBAAA,cAAAA,qBAAA,GAAIjB,WAAW,CAAE;AAAA,CACxE,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASkB,4BAA4BA,CAAEhB,KAAK,EAAG;EACrD,OAAOiB,MAAM,CAACC,MAAM,CAAElB,KAAM,CAAC,CAACmB,IAAI,CAAC,CAAC;AACrC","ignoreList":[]}
1
+ {
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": "AAGA,SAAS,sBAAsB;AAW/B,MAAM,cAAc,CAAC;AAUd,MAAM,uCAAuC;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,MAAM,0CAA0C;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;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/annotations",
3
- "version": "3.32.0",
3
+ "version": "3.32.1-next.b8c8708f3.0",
4
4
  "description": "Annotate content in the Gutenberg editor.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -24,14 +24,20 @@
24
24
  },
25
25
  "main": "build/index.js",
26
26
  "module": "build-module/index.js",
27
+ "exports": {
28
+ ".": {
29
+ "import": "./build-module/index.js",
30
+ "require": "./build/index.js"
31
+ },
32
+ "./package.json": "./package.json"
33
+ },
27
34
  "react-native": "src/index",
28
35
  "wpScript": true,
29
36
  "dependencies": {
30
- "@babel/runtime": "7.25.7",
31
- "@wordpress/data": "^10.32.0",
32
- "@wordpress/hooks": "^4.32.0",
33
- "@wordpress/i18n": "^6.5.0",
34
- "@wordpress/rich-text": "^7.32.0",
37
+ "@wordpress/data": "^10.32.1-next.b8c8708f3.0",
38
+ "@wordpress/hooks": "^4.32.1-next.b8c8708f3.0",
39
+ "@wordpress/i18n": "^6.5.1-next.b8c8708f3.0",
40
+ "@wordpress/rich-text": "^7.32.1-next.b8c8708f3.0",
35
41
  "uuid": "^9.0.1"
36
42
  },
37
43
  "peerDependencies": {
@@ -40,5 +46,5 @@
40
46
  "publishConfig": {
41
47
  "access": "public"
42
48
  },
43
- "gitHead": "a030b4c0e0695239b942c7dc18511782b64f10ed"
49
+ "gitHead": "67cfd7e661931aeb0d06bec894599d287a4f8d0f"
44
50
  }