@wordpress/annotations 2.11.0 → 2.14.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 2.14.0 (2022-07-27)
6
+
7
+ ## 2.13.0 (2022-07-13)
8
+
9
+ ## 2.12.0 (2022-06-29)
10
+
5
11
  ## 2.11.0 (2022-06-15)
6
12
 
7
13
  ## 2.10.0 (2022-06-01)
@@ -6,12 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.annotations = annotations;
7
7
  exports.default = void 0;
8
8
 
9
- var _lodash = require("lodash");
10
-
11
- /**
12
- * External dependencies
13
- */
14
-
15
9
  /**
16
10
  * Filters an array based on the predicate, but keeps the reference the same if
17
11
  * the array hasn't changed.
@@ -25,6 +19,22 @@ function filterWithReference(collection, predicate) {
25
19
  const filteredCollection = collection.filter(predicate);
26
20
  return collection.length === filteredCollection.length ? collection : filteredCollection;
27
21
  }
22
+ /**
23
+ * Creates a new object with the same keys, but with `callback()` called as
24
+ * a transformer function on each of the values.
25
+ *
26
+ * @param {Object} obj The object to transform.
27
+ * @param {Function} callback The function to transform each object value.
28
+ * @return {Array} Transformed object.
29
+ */
30
+
31
+
32
+ const mapValues = (obj, callback) => Object.entries(obj).reduce((acc, _ref) => {
33
+ let [key, value] = _ref;
34
+ return { ...acc,
35
+ [key]: callback(value)
36
+ };
37
+ }, {});
28
38
  /**
29
39
  * Verifies whether the given annotations is a valid annotation.
30
40
  *
@@ -34,7 +44,7 @@ function filterWithReference(collection, predicate) {
34
44
 
35
45
 
36
46
  function isValidAnnotationRange(annotation) {
37
- return (0, _lodash.isNumber)(annotation.start) && (0, _lodash.isNumber)(annotation.end) && annotation.start <= annotation.end;
47
+ return typeof annotation.start === 'number' && typeof annotation.end === 'number' && annotation.start <= annotation.end;
38
48
  }
39
49
  /**
40
50
  * Reducer managing annotations.
@@ -74,14 +84,14 @@ function annotations() {
74
84
  };
75
85
 
76
86
  case 'ANNOTATION_REMOVE':
77
- return (0, _lodash.mapValues)(state, annotationsForBlock => {
87
+ return mapValues(state, annotationsForBlock => {
78
88
  return filterWithReference(annotationsForBlock, annotation => {
79
89
  return annotation.id !== action.annotationId;
80
90
  });
81
91
  });
82
92
 
83
93
  case 'ANNOTATION_UPDATE_RANGE':
84
- return (0, _lodash.mapValues)(state, annotationsForBlock => {
94
+ return mapValues(state, annotationsForBlock => {
85
95
  let hasChangedRange = false;
86
96
  const newAnnotations = annotationsForBlock.map(annotation => {
87
97
  if (annotation.id === action.annotationId) {
@@ -100,7 +110,7 @@ function annotations() {
100
110
  });
101
111
 
102
112
  case 'ANNOTATION_REMOVE_SOURCE':
103
- return (0, _lodash.mapValues)(state, annotationsForBlock => {
113
+ return mapValues(state, annotationsForBlock => {
104
114
  return filterWithReference(annotationsForBlock, annotation => {
105
115
  return annotation.source !== action.source;
106
116
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/annotations/src/store/reducer.js"],"names":["filterWithReference","collection","predicate","filteredCollection","filter","length","isValidAnnotationRange","annotation","start","end","annotations","state","action","type","blockClientId","newAnnotation","id","richTextIdentifier","source","selector","range","previousAnnotationsForBlock","annotationsForBlock","annotationId","hasChangedRange","newAnnotations","map"],"mappings":";;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,mBAAT,CAA8BC,UAA9B,EAA0CC,SAA1C,EAAsD;AACrD,QAAMC,kBAAkB,GAAGF,UAAU,CAACG,MAAX,CAAmBF,SAAnB,CAA3B;AAEA,SAAOD,UAAU,CAACI,MAAX,KAAsBF,kBAAkB,CAACE,MAAzC,GACJJ,UADI,GAEJE,kBAFH;AAGA;AAED;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASG,sBAAT,CAAiCC,UAAjC,EAA8C;AAC7C,SACC,sBAAUA,UAAU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,IAA2B;AACnD,YAAIE,eAAe,GAAG,KAAtB;AAEA,cAAMC,cAAc,GAAGH,mBAAmB,CAACI,GAApB,CACpBnB,UAAF,IAAkB;AACjB,cAAKA,UAAU,CAACS,EAAX,KAAkBJ,MAAM,CAACW,YAA9B,EAA6C;AAC5CC,YAAAA,eAAe,GAAG,IAAlB;AACA,mBAAO,EACN,GAAGjB,UADG;AAENa,cAAAA,KAAK,EAAE;AACNZ,gBAAAA,KAAK,EAAEI,MAAM,CAACJ,KADR;AAENC,gBAAAA,GAAG,EAAEG,MAAM,CAACH;AAFN;AAFD,aAAP;AAOA;;AAED,iBAAOF,UAAP;AACA,SAdqB,CAAvB;AAiBA,eAAOiB,eAAe,GAAGC,cAAH,GAAoBH,mBAA1C;AACA,OArBM,CAAP;;AAuBD,SAAK,0BAAL;AACC,aAAO,uBAAWX,KAAX,EAAoBW,mBAAF,IAA2B;AACnD,eAAOtB,mBAAmB,CACzBsB,mBADyB,EAEvBf,UAAF,IAAkB;AACjB,iBAAOA,UAAU,CAACW,MAAX,KAAsBN,MAAM,CAACM,MAApC;AACA,SAJwB,CAA1B;AAMA,OAPM,CAAP;AAhEF;;AA0EA,SAAOP,KAAP;AACA;;eAEcD,W","sourcesContent":["/**\n * External dependencies\n */\nimport { isNumber, mapValues } from 'lodash';\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 {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 * 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\tisNumber( annotation.start ) &&\n\t\tisNumber( annotation.end ) &&\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"]}
1
+ {"version":3,"sources":["@wordpress/annotations/src/store/reducer.js"],"names":["filterWithReference","collection","predicate","filteredCollection","filter","length","mapValues","obj","callback","Object","entries","reduce","acc","key","value","isValidAnnotationRange","annotation","start","end","annotations","state","action","type","blockClientId","newAnnotation","id","richTextIdentifier","source","selector","range","previousAnnotationsForBlock","annotationsForBlock","annotationId","hasChangedRange","newAnnotations","map"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,mBAAT,CAA8BC,UAA9B,EAA0CC,SAA1C,EAAsD;AACrD,QAAMC,kBAAkB,GAAGF,UAAU,CAACG,MAAX,CAAmBF,SAAnB,CAA3B;AAEA,SAAOD,UAAU,CAACI,MAAX,KAAsBF,kBAAkB,CAACE,MAAzC,GACJJ,UADI,GAEJE,kBAFH;AAGA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,MAAMG,SAAS,GAAG,CAAEC,GAAF,EAAOC,QAAP,KACjBC,MAAM,CAACC,OAAP,CAAgBH,GAAhB,EAAsBI,MAAtB,CACC,CAAEC,GAAF;AAAA,MAAO,CAAEC,GAAF,EAAOC,KAAP,CAAP;AAAA,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EAAWW,mBAAF,IAA2B;AACnD,eAAO/B,mBAAmB,CACzB+B,mBADyB,EAEvBf,UAAF,IAAkB;AACjB,iBAAOA,UAAU,CAACS,EAAX,KAAkBJ,MAAM,CAACW,YAAhC;AACA,SAJwB,CAA1B;AAMA,OAPe,CAAhB;;AASD,SAAK,yBAAL;AACC,aAAO1B,SAAS,CAAEc,KAAF,EAAWW,mBAAF,IAA2B;AACnD,YAAIE,eAAe,GAAG,KAAtB;AAEA,cAAMC,cAAc,GAAGH,mBAAmB,CAACI,GAApB,CACpBnB,UAAF,IAAkB;AACjB,cAAKA,UAAU,CAACS,EAAX,KAAkBJ,MAAM,CAACW,YAA9B,EAA6C;AAC5CC,YAAAA,eAAe,GAAG,IAAlB;AACA,mBAAO,EACN,GAAGjB,UADG;AAENa,cAAAA,KAAK,EAAE;AACNZ,gBAAAA,KAAK,EAAEI,MAAM,CAACJ,KADR;AAENC,gBAAAA,GAAG,EAAEG,MAAM,CAACH;AAFN;AAFD,aAAP;AAOA;;AAED,iBAAOF,UAAP;AACA,SAdqB,CAAvB;AAiBA,eAAOiB,eAAe,GAAGC,cAAH,GAAoBH,mBAA1C;AACA,OArBe,CAAhB;;AAuBD,SAAK,0BAAL;AACC,aAAOzB,SAAS,CAAEc,KAAF,EAAWW,mBAAF,IAA2B;AACnD,eAAO/B,mBAAmB,CACzB+B,mBADyB,EAEvBf,UAAF,IAAkB;AACjB,iBAAOA,UAAU,CAACW,MAAX,KAAsBN,MAAM,CAACM,MAApC;AACA,SAJwB,CAA1B;AAMA,OAPe,CAAhB;AAhEF;;AA0EA,SAAOP,KAAP;AACA;;eAEcD,W","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"]}
@@ -11,8 +11,6 @@ exports.__experimentalGetAnnotationsForRichText = exports.__experimentalGetAnnot
11
11
 
12
12
  var _rememo = _interopRequireDefault(require("rememo"));
13
13
 
14
- var _lodash = require("lodash");
15
-
16
14
  /**
17
15
  * External dependencies
18
16
  */
@@ -99,8 +97,6 @@ const __experimentalGetAnnotationsForRichText = (0, _rememo.default)((state, blo
99
97
  exports.__experimentalGetAnnotationsForRichText = __experimentalGetAnnotationsForRichText;
100
98
 
101
99
  function __experimentalGetAnnotations(state) {
102
- return (0, _lodash.flatMap)(state, annotations => {
103
- return annotations;
104
- });
100
+ return Object.values(state).flat();
105
101
  }
106
102
  //# sourceMappingURL=selectors.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/annotations/src/store/selectors.js"],"names":["EMPTY_ARRAY","__experimentalGetAnnotationsForBlock","state","blockClientId","filter","annotation","selector","__experimentalGetAllAnnotationsForBlock","__experimentalGetAnnotationsForRichText","richTextIdentifier","map","range","other","__experimentalGetAnnotations","annotations"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,WAAW,GAAG,EAApB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,MAAMC,oCAAoC,GAAG,qBACnD,CAAEC,KAAF,EAASC,aAAT,KAA4B;AAAA;;AAC3B,SAAO,yBAAED,KAAF,aAAEA,KAAF,uBAAEA,KAAK,CAAIC,aAAJ,CAAP,uEAA8B,EAA9B,EAAmCC,MAAnC,CAA6CC,UAAF,IAAkB;AACnE,WAAOA,UAAU,CAACC,QAAX,KAAwB,OAA/B;AACA,GAFM,CAAP;AAGA,CALkD,EAMnD,CAAEJ,KAAF,EAASC,aAAT;AAAA;;AAAA,SAA4B,0BAAED,KAAF,aAAEA,KAAF,uBAAEA,KAAK,CAAIC,aAAJ,CAAP,yEAA8BH,WAA9B,CAA5B;AAAA,CANmD,CAA7C;;;;AASA,SAASO,uCAAT,CACNL,KADM,EAENC,aAFM,EAGL;AAAA;;AACD,kCAAOD,KAAP,aAAOA,KAAP,uBAAOA,KAAK,CAAIC,aAAJ,CAAZ,yEAAmCH,WAAnC;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMQ,uCAAuC,GAAG,qBACtD,CAAEN,KAAF,EAASC,aAAT,EAAwBM,kBAAxB,KAAgD;AAAA;;AAC/C,SAAO,0BAAEP,KAAF,aAAEA,KAAF,uBAAEA,KAAK,CAAIC,aAAJ,CAAP,yEAA8B,EAA9B,EACLC,MADK,CACKC,UAAF,IAAkB;AAC1B,WACCA,UAAU,CAACC,QAAX,KAAwB,OAAxB,IACAG,kBAAkB,KAAKJ,UAAU,CAACI,kBAFnC;AAIA,GANK,EAOLC,GAPK,CAOEL,UAAF,IAAkB;AACvB,UAAM;AAAEM,MAAAA,KAAF;AAAS,SAAGC;AAAZ,QAAsBP,UAA5B;AAEA,WAAO,EACN,GAAGM,KADG;AAEN,SAAGC;AAFG,KAAP;AAIA,GAdK,CAAP;AAeA,CAjBqD,EAkBtD,CAAEV,KAAF,EAASC,aAAT;AAAA;;AAAA,SAA4B,0BAAED,KAAF,aAAEA,KAAF,uBAAEA,KAAK,CAAIC,aAAJ,CAAP,yEAA8BH,WAA9B,CAA5B;AAAA,CAlBsD,CAAhD;AAqBP;AACA;AACA;AACA;AACA;AACA;;;;;AACO,SAASa,4BAAT,CAAuCX,KAAvC,EAA+C;AACrD,SAAO,qBAASA,KAAT,EAAkBY,WAAF,IAAmB;AACzC,WAAOA,WAAP;AACA,GAFM,CAAP;AAGA","sourcesContent":["/**\n * External dependencies\n */\nimport createSelector from 'rememo';\nimport { flatMap } from 'lodash';\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 flatMap( state, ( annotations ) => {\n\t\treturn annotations;\n\t} );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/annotations/src/store/selectors.js"],"names":["EMPTY_ARRAY","__experimentalGetAnnotationsForBlock","state","blockClientId","filter","annotation","selector","__experimentalGetAllAnnotationsForBlock","__experimentalGetAnnotationsForRichText","richTextIdentifier","map","range","other","__experimentalGetAnnotations","Object","values","flat"],"mappings":";;;;;;;;;;;AA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AGC;AAFG,KAAP;AAIA,GAdK,CAAP;AAeA,CAjBqD,EAkBtD,CAAEV,KAAF,EAASC,aAAT;AAAA;;AAAA,SAA4B,0BAAED,KAAF,aAAEA,KAAF,uBAAEA,KAAK,CAAIC,aAAJ,CAAP,yEAA8BH,WAA9B,CAA5B;AAAA,CAlBsD,CAAhD;AAqBP;AACA;AACA;AACA;AACA;AACA;;;;;AACO,SAASa,4BAAT,CAAuCX,KAAvC,EAA+C;AACrD,SAAOY,MAAM,CAACC,MAAP,CAAeb,KAAf,EAAuBc,IAAvB,EAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport createSelector from 'rememo';\n\n/**\n * Shared reference to an empty array for cases where it is important to avoid\n * returning a new array reference on every invocation, as in a connected or\n * other pure component which performs `shouldComponentUpdate` check on props.\n * This should be used as a last resort, since the normalized data should be\n * maintained by the reducer result in state.\n *\n * @type {Array}\n */\nconst EMPTY_ARRAY = [];\n\n/**\n * Returns the annotations for a specific client ID.\n *\n * @param {Object} state Editor state.\n * @param {string} clientId The ID of the block to get the annotations for.\n *\n * @return {Array} The annotations applicable to this block.\n */\nexport const __experimentalGetAnnotationsForBlock = createSelector(\n\t( state, blockClientId ) => {\n\t\treturn ( state?.[ blockClientId ] ?? [] ).filter( ( annotation ) => {\n\t\t\treturn annotation.selector === 'block';\n\t\t} );\n\t},\n\t( state, blockClientId ) => [ state?.[ blockClientId ] ?? EMPTY_ARRAY ]\n);\n\nexport function __experimentalGetAllAnnotationsForBlock(\n\tstate,\n\tblockClientId\n) {\n\treturn state?.[ blockClientId ] ?? EMPTY_ARRAY;\n}\n\n/**\n * Returns the annotations that apply to the given RichText instance.\n *\n * Both a blockClientId and a richTextIdentifier are required. This is because\n * a block might have multiple `RichText` components. This does mean that every\n * block needs to implement annotations itself.\n *\n * @param {Object} state Editor state.\n * @param {string} blockClientId The client ID for the block.\n * @param {string} richTextIdentifier Unique identifier that identifies the given RichText.\n * @return {Array} All the annotations relevant for the `RichText`.\n */\nexport const __experimentalGetAnnotationsForRichText = createSelector(\n\t( state, blockClientId, richTextIdentifier ) => {\n\t\treturn ( state?.[ blockClientId ] ?? [] )\n\t\t\t.filter( ( annotation ) => {\n\t\t\t\treturn (\n\t\t\t\t\tannotation.selector === 'range' &&\n\t\t\t\t\trichTextIdentifier === annotation.richTextIdentifier\n\t\t\t\t);\n\t\t\t} )\n\t\t\t.map( ( annotation ) => {\n\t\t\t\tconst { range, ...other } = annotation;\n\n\t\t\t\treturn {\n\t\t\t\t\t...range,\n\t\t\t\t\t...other,\n\t\t\t\t};\n\t\t\t} );\n\t},\n\t( state, blockClientId ) => [ state?.[ blockClientId ] ?? EMPTY_ARRAY ]\n);\n\n/**\n * Returns all annotations in the editor state.\n *\n * @param {Object} state Editor state.\n * @return {Array} All annotations currently applied.\n */\nexport function __experimentalGetAnnotations( state ) {\n\treturn Object.values( state ).flat();\n}\n"]}
@@ -1,7 +1,3 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { isNumber, mapValues } from 'lodash';
5
1
  /**
6
2
  * Filters an array based on the predicate, but keeps the reference the same if
7
3
  * the array hasn't changed.
@@ -11,11 +7,26 @@ import { isNumber, mapValues } from 'lodash';
11
7
  * in the array.
12
8
  * @return {Array} Filtered array.
13
9
  */
14
-
15
10
  function filterWithReference(collection, predicate) {
16
11
  const filteredCollection = collection.filter(predicate);
17
12
  return collection.length === filteredCollection.length ? collection : filteredCollection;
18
13
  }
14
+ /**
15
+ * Creates a new object with the same keys, but with `callback()` called as
16
+ * a transformer function on each of the values.
17
+ *
18
+ * @param {Object} obj The object to transform.
19
+ * @param {Function} callback The function to transform each object value.
20
+ * @return {Array} Transformed object.
21
+ */
22
+
23
+
24
+ const mapValues = (obj, callback) => Object.entries(obj).reduce((acc, _ref) => {
25
+ let [key, value] = _ref;
26
+ return { ...acc,
27
+ [key]: callback(value)
28
+ };
29
+ }, {});
19
30
  /**
20
31
  * Verifies whether the given annotations is a valid annotation.
21
32
  *
@@ -25,7 +36,7 @@ function filterWithReference(collection, predicate) {
25
36
 
26
37
 
27
38
  function isValidAnnotationRange(annotation) {
28
- return isNumber(annotation.start) && isNumber(annotation.end) && annotation.start <= annotation.end;
39
+ return typeof annotation.start === 'number' && typeof annotation.end === 'number' && annotation.start <= annotation.end;
29
40
  }
30
41
  /**
31
42
  * Reducer managing annotations.
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/annotations/src/store/reducer.js"],"names":["isNumber","mapValues","filterWithReference","collection","predicate","filteredCollection","filter","length","isValidAnnotationRange","annotation","start","end","annotations","state","action","type","blockClientId","newAnnotation","id","richTextIdentifier","source","selector","range","previousAnnotationsForBlock","annotationsForBlock","annotationId","hasChangedRange","newAnnotations","map"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,QAAT,EAAmBC,SAAnB,QAAoC,QAApC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,mBAAT,CAA8BC,UAA9B,EAA0CC,SAA1C,EAAsD;AACrD,QAAMC,kBAAkB,GAAGF,UAAU,CAACG,MAAX,CAAmBF,SAAnB,CAA3B;AAEA,SAAOD,UAAU,CAACI,MAAX,KAAsBF,kBAAkB,CAACE,MAAzC,GACJJ,UADI,GAEJE,kBAFH;AAGA;AAED;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASG,sBAAT,CAAiCC,UAAjC,EAA8C;AAC7C,SACCT,QAAQ,CAAES,UAAU,CAACC,KAAb,CAAR,IACAV,QAAQ,CAAES,UAAU,CAACE,GAAb,CADR,IAEAF,UAAU,CAACC,KAAX,IAAoBD,UAAU,CAACE,GAHhC;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,OAAO,SAASC,WAAT,GAA2C;AAAA;;AAAA,MAArBC,KAAqB,uEAAb,EAAa;AAAA,MAATC,MAAS;;AACjD,UAASA,MAAM,CAACC,IAAhB;AACC,SAAK,gBAAL;AACC,YAAMC,aAAa,GAAGF,MAAM,CAACE,aAA7B;AACA,YAAMC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,GAAG,EAAEG,MAAM,CAACH;AAFN;AAFD,aAAP;AAOA;;AAED,iBAAOF,UAAP;AACA,SAdqB,CAAvB;AAiBA,eAAOiB,eAAe,GAAGC,cAAH,GAAoBH,mBAA1C;AACA,OArBe,CAAhB;;AAuBD,SAAK,0BAAL;AACC,aAAOvB,SAAS,CAAEY,KAAF,EAAWW,mBAAF,IAA2B;AACnD,eAAOtB,mBAAmB,CACzBsB,mBADyB,EAEvBf,UAAF,IAAkB;AACjB,iBAAOA,UAAU,CAACW,MAAX,KAAsBN,MAAM,CAACM,MAApC;AACA,SAJwB,CAA1B;AAMA,OAPe,CAAhB;AAhEF;;AA0EA,SAAOP,KAAP;AACA;AAED,eAAeD,WAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { isNumber, mapValues } from 'lodash';\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 {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 * 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\tisNumber( annotation.start ) &&\n\t\tisNumber( annotation.end ) &&\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"]}
1
+ {"version":3,"sources":["@wordpress/annotations/src/store/reducer.js"],"names":["filterWithReference","collection","predicate","filteredCollection","filter","length","mapValues","obj","callback","Object","entries","reduce","acc","key","value","isValidAnnotationRange","annotation","start","end","annotations","state","action","type","blockClientId","newAnnotation","id","richTextIdentifier","source","selector","range","previousAnnotationsForBlock","annotationsForBlock","annotationId","hasChangedRange","newAnnotations","map"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,mBAAT,CAA8BC,UAA9B,EAA0CC,SAA1C,EAAsD;AACrD,QAAMC,kBAAkB,GAAGF,UAAU,CAACG,MAAX,CAAmBF,SAAnB,CAA3B;AAEA,SAAOD,UAAU,CAACI,MAAX,KAAsBF,kBAAkB,CAACE,MAAzC,GACJJ,UADI,GAEJE,kBAFH;AAGA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,MAAMG,SAAS,GAAG,CAAEC,GAAF,EAAOC,QAAP,KACjBC,MAAM,CAACC,OAAP,CAAgBH,GAAhB,EAAsBI,MAAtB,CACC,CAAEC,GAAF;AAAA,MAAO,CAAEC,GAAF,EAAOC,KAAP,CAAP;AAAA,SAA6B,EAC5B,GAAGF,GADyB;AAE5B,KAAEC,GAAF,GAASL,QAAQ,CAAEM,KAAF;AAFW,GAA7B;AAAA,CADD,EAKC,EALD,CADD;AASA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASC,sBAAT,CAAiCC,UAAjC,EAA8C;AAC7C,SACC,OAAOA,UAAU,CAACC,KAAlB,KAA4B,QAA5B,IACA,OAAOD,UAAU,CAACE,GAAlB,KAA0B,QAD1B,IAEAF,UAAU,CAACC,KAAX,IAAoBD,U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mBAAmB,CAACI,GAApB,CACpBnB,UAAF,IAAkB;AACjB,cAAKA,UAAU,CAACS,EAAX,KAAkBJ,MAAM,CAACW,YAA9B,EAA6C;AAC5CC,YAAAA,eAAe,GAAG,IAAlB;AACA,mBAAO,EACN,GAAGjB,UADG;AAENa,cAAAA,KAAK,EAAE;AACNZ,gBAAAA,KAAK,EAAEI,MAAM,CAACJ,KADR;AAENC,gBAAAA,GAAG,EAAEG,MAAM,CAACH;AAFN;AAFD,aAAP;AAOA;;AAED,iBAAOF,UAAP;AACA,SAdqB,CAAvB;AAiBA,eAAOiB,eAAe,GAAGC,cAAH,GAAoBH,mBAA1C;AACA,OArBe,CAAhB;;AAuBD,SAAK,0BAAL;AACC,aAAOzB,SAAS,CAAEc,KAAF,EAAWW,mBAAF,IAA2B;AACnD,eAAO/B,mBAAmB,CACzB+B,mBADyB,EAEvBf,UAAF,IAAkB;AACjB,iBAAOA,UAAU,CAACW,MAAX,KAAsBN,MAAM,CAACM,MAApC;AACA,SAJwB,CAA1B;AAMA,OAPe,CAAhB;AAhEF;;AA0EA,SAAOP,KAAP;AACA;AAED,eAAeD,WAAf","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"]}
@@ -2,7 +2,6 @@
2
2
  * External dependencies
3
3
  */
4
4
  import createSelector from 'rememo';
5
- import { flatMap } from 'lodash';
6
5
  /**
7
6
  * Shared reference to an empty array for cases where it is important to avoid
8
7
  * returning a new array reference on every invocation, as in a connected or
@@ -79,8 +78,6 @@ export const __experimentalGetAnnotationsForRichText = createSelector((state, bl
79
78
  */
80
79
 
81
80
  export function __experimentalGetAnnotations(state) {
82
- return flatMap(state, annotations => {
83
- return annotations;
84
- });
81
+ return Object.values(state).flat();
85
82
  }
86
83
  //# sourceMappingURL=selectors.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/annotations/src/store/selectors.js"],"names":["createSelector","flatMap","EMPTY_ARRAY","__experimentalGetAnnotationsForBlock","state","blockClientId","filter","annotation","selector","__experimentalGetAllAnnotationsForBlock","__experimentalGetAnnotationsForRichText","richTextIdentifier","map","range","other","__experimentalGetAnnotations","annotations"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AAEM,MAAAA,KAAF;AAAS,SAAGC;AAAZ,QAAsBP,UAA5B;AAEA,WAAO,EACN,GAAGM,KADG;AAEN,SAAGC;AAFG,KAAP;AAIA,GAdK,CAAP;AAeA,CAjBmE,EAkBpE,CAAEV,KAAF,EAASC,aAAT;AAAA;;AAAA,SAA4B,0BAAED,KAAF,aAAEA,KAAF,uBAAEA,KAAK,CAAIC,aAAJ,CAAP,yEAA8BH,WAA9B,CAA5B;AAAA,CAlBoE,CAA9D;AAqBP;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASa,4BAAT,CAAuCX,KAAvC,EAA+C;AACrD,SAAOH,OAAO,CAAEG,KAAF,EAAWY,WAAF,IAAmB;AACzC,WAAOA,WAAP;AACA,GAFa,CAAd;AAGA","sourcesContent":["/**\n * External dependencies\n */\nimport createSelector from 'rememo';\nimport { flatMap } from 'lodash';\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 flatMap( state, ( annotations ) => {\n\t\treturn annotations;\n\t} );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/annotations/src/store/selectors.js"],"names":["createSelector","EMPTY_ARRAY","__experimentalGetAnnotationsForBlock","state","blockClientId","filter","annotation","selector","__experimentalGetAllAnnotationsForBlock","__experimentalGetAnnotationsForRichText","richTextIdentifier","map","range","other","__experimentalGetAnnotations","Object","values","flat"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,cAAP,MAA2B,QAA3B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,WAAW,GAAG,EAApB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,oCAAoC,GAAGF,cAAc,CACjE,CAAEG,KAAF,EAASC,aAAT,KAA4B;AAAA;;AAC3B,SAAO,yBAAED,KAAF,aAAEA,KAAF,uBAAEA,KA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OAAO,SAASa,4BAAT,CAAuCX,KAAvC,EAA+C;AACrD,SAAOY,MAAM,CAACC,MAAP,CAAeb,KAAf,EAAuBc,IAAvB,EAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport createSelector from 'rememo';\n\n/**\n * Shared reference to an empty array for cases where it is important to avoid\n * returning a new array reference on every invocation, as in a connected or\n * other pure component which performs `shouldComponentUpdate` check on props.\n * This should be used as a last resort, since the normalized data should be\n * maintained by the reducer result in state.\n *\n * @type {Array}\n */\nconst EMPTY_ARRAY = [];\n\n/**\n * Returns the annotations for a specific client ID.\n *\n * @param {Object} state Editor state.\n * @param {string} clientId The ID of the block to get the annotations for.\n *\n * @return {Array} The annotations applicable to this block.\n */\nexport const __experimentalGetAnnotationsForBlock = createSelector(\n\t( state, blockClientId ) => {\n\t\treturn ( state?.[ blockClientId ] ?? [] ).filter( ( annotation ) => {\n\t\t\treturn annotation.selector === 'block';\n\t\t} );\n\t},\n\t( state, blockClientId ) => [ state?.[ blockClientId ] ?? EMPTY_ARRAY ]\n);\n\nexport function __experimentalGetAllAnnotationsForBlock(\n\tstate,\n\tblockClientId\n) {\n\treturn state?.[ blockClientId ] ?? EMPTY_ARRAY;\n}\n\n/**\n * Returns the annotations that apply to the given RichText instance.\n *\n * Both a blockClientId and a richTextIdentifier are required. This is because\n * a block might have multiple `RichText` components. This does mean that every\n * block needs to implement annotations itself.\n *\n * @param {Object} state Editor state.\n * @param {string} blockClientId The client ID for the block.\n * @param {string} richTextIdentifier Unique identifier that identifies the given RichText.\n * @return {Array} All the annotations relevant for the `RichText`.\n */\nexport const __experimentalGetAnnotationsForRichText = createSelector(\n\t( state, blockClientId, richTextIdentifier ) => {\n\t\treturn ( state?.[ blockClientId ] ?? [] )\n\t\t\t.filter( ( annotation ) => {\n\t\t\t\treturn (\n\t\t\t\t\tannotation.selector === 'range' &&\n\t\t\t\t\trichTextIdentifier === annotation.richTextIdentifier\n\t\t\t\t);\n\t\t\t} )\n\t\t\t.map( ( annotation ) => {\n\t\t\t\tconst { range, ...other } = annotation;\n\n\t\t\t\treturn {\n\t\t\t\t\t...range,\n\t\t\t\t\t...other,\n\t\t\t\t};\n\t\t\t} );\n\t},\n\t( state, blockClientId ) => [ state?.[ blockClientId ] ?? EMPTY_ARRAY ]\n);\n\n/**\n * Returns all annotations in the editor state.\n *\n * @param {Object} state Editor state.\n * @return {Array} All annotations currently applied.\n */\nexport function __experimentalGetAnnotations( state ) {\n\treturn Object.values( state ).flat();\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/annotations",
3
- "version": "2.11.0",
3
+ "version": "2.14.0",
4
4
  "description": "Annotate content in the Gutenberg editor.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -26,11 +26,10 @@
26
26
  "react-native": "src/index",
27
27
  "dependencies": {
28
28
  "@babel/runtime": "^7.16.0",
29
- "@wordpress/data": "^6.11.0",
30
- "@wordpress/hooks": "^3.11.0",
31
- "@wordpress/i18n": "^4.11.0",
32
- "@wordpress/rich-text": "^5.9.0",
33
- "lodash": "^4.17.21",
29
+ "@wordpress/data": "^6.14.0",
30
+ "@wordpress/hooks": "^3.14.0",
31
+ "@wordpress/i18n": "^4.14.0",
32
+ "@wordpress/rich-text": "^5.12.0",
34
33
  "rememo": "^4.0.0",
35
34
  "uuid": "^8.3.0"
36
35
  },
@@ -40,5 +39,5 @@
40
39
  "publishConfig": {
41
40
  "access": "public"
42
41
  },
43
- "gitHead": "48d5f37dfb52d2e77c8eeb662f9874cf141b8c6b"
42
+ "gitHead": "0315dbc240cb2aa146d7c1bafd251f004b88300e"
44
43
  }
@@ -1,8 +1,3 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { isNumber, mapValues } from 'lodash';
5
-
6
1
  /**
7
2
  * Filters an array based on the predicate, but keeps the reference the same if
8
3
  * the array hasn't changed.
@@ -20,6 +15,23 @@ function filterWithReference( collection, predicate ) {
20
15
  : filteredCollection;
21
16
  }
22
17
 
18
+ /**
19
+ * Creates a new object with the same keys, but with `callback()` called as
20
+ * a transformer function on each of the values.
21
+ *
22
+ * @param {Object} obj The object to transform.
23
+ * @param {Function} callback The function to transform each object value.
24
+ * @return {Array} Transformed object.
25
+ */
26
+ const mapValues = ( obj, callback ) =>
27
+ Object.entries( obj ).reduce(
28
+ ( acc, [ key, value ] ) => ( {
29
+ ...acc,
30
+ [ key ]: callback( value ),
31
+ } ),
32
+ {}
33
+ );
34
+
23
35
  /**
24
36
  * Verifies whether the given annotations is a valid annotation.
25
37
  *
@@ -28,8 +40,8 @@ function filterWithReference( collection, predicate ) {
28
40
  */
29
41
  function isValidAnnotationRange( annotation ) {
30
42
  return (
31
- isNumber( annotation.start ) &&
32
- isNumber( annotation.end ) &&
43
+ typeof annotation.start === 'number' &&
44
+ typeof annotation.end === 'number' &&
33
45
  annotation.start <= annotation.end
34
46
  );
35
47
  }
@@ -2,7 +2,6 @@
2
2
  * External dependencies
3
3
  */
4
4
  import createSelector from 'rememo';
5
- import { flatMap } from 'lodash';
6
5
 
7
6
  /**
8
7
  * Shared reference to an empty array for cases where it is important to avoid
@@ -79,7 +78,5 @@ export const __experimentalGetAnnotationsForRichText = createSelector(
79
78
  * @return {Array} All annotations currently applied.
80
79
  */
81
80
  export function __experimentalGetAnnotations( state ) {
82
- return flatMap( state, ( annotations ) => {
83
- return annotations;
84
- } );
81
+ return Object.values( state ).flat();
85
82
  }