@wordpress/annotations 2.34.0 → 2.35.1
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 +2 -0
- package/build/block/index.js +4 -6
- package/build/block/index.js.map +1 -1
- package/build/format/annotation.js +12 -16
- package/build/format/annotation.js.map +1 -1
- package/build/store/actions.js +8 -9
- package/build/store/actions.js.map +1 -1
- package/build/store/reducer.js +5 -11
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +5 -5
- package/build/store/selectors.js.map +1 -1
- package/build-module/block/index.js +4 -6
- package/build-module/block/index.js.map +1 -1
- package/build-module/format/annotation.js +12 -16
- package/build-module/format/annotation.js.map +1 -1
- package/build-module/store/actions.js +8 -9
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +5 -11
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +5 -5
- package/build-module/store/selectors.js.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
package/build/block/index.js
CHANGED
|
@@ -21,12 +21,10 @@ var _constants = require("../store/constants");
|
|
|
21
21
|
* @return {Object} The enhanced component.
|
|
22
22
|
*/
|
|
23
23
|
const addAnnotationClassName = OriginalComponent => {
|
|
24
|
-
return (0, _data.withSelect)((select,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
} = _ref;
|
|
29
|
-
|
|
24
|
+
return (0, _data.withSelect)((select, {
|
|
25
|
+
clientId,
|
|
26
|
+
className
|
|
27
|
+
}) => {
|
|
30
28
|
const annotations = select(_constants.STORE_NAME).__experimentalGetAnnotationsForBlock(clientId);
|
|
31
29
|
|
|
32
30
|
return {
|
package/build/block/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/annotations/src/block/index.js"],"names":["addAnnotationClassName","OriginalComponent","select","clientId","className","annotations","STORE_NAME","__experimentalGetAnnotationsForBlock","map","annotation","source","concat","filter","Boolean","join"],"mappings":";;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,sBAAsB,GAAKC,iBAAF,IAAyB;AACvD,SAAO,sBAAY,CAAEC,MAAF,
|
|
1
|
+
{"version":3,"sources":["@wordpress/annotations/src/block/index.js"],"names":["addAnnotationClassName","OriginalComponent","select","clientId","className","annotations","STORE_NAME","__experimentalGetAnnotationsForBlock","map","annotation","source","concat","filter","Boolean","join"],"mappings":";;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,sBAAsB,GAAKC,iBAAF,IAAyB;AACvD,SAAO,sBAAY,CAAEC,MAAF,EAAU;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,GAAV,KAAuC;AACzD,UAAMC,WAAW,GAChBH,MAAM,CAAEI,qBAAF,CAAN,CAAqBC,oCAArB,CACCJ,QADD,CADD;;AAKA,WAAO;AACNC,MAAAA,SAAS,EAAEC,WAAW,CACpBG,GADS,CACFC,UAAF,IAAkB;AACvB,eAAO,qBAAqBA,UAAU,CAACC,MAAvC;AACA,OAHS,EAITC,MAJS,CAIDP,SAJC,EAKTQ,MALS,CAKDC,OALC,EAMTC,IANS,CAMH,GANG;AADL,KAAP;AASA,GAfM,EAeFb,iBAfE,CAAP;AAgBA,CAjBD;;AAmBA,sBACC,uBADD,EAEC,kBAFD,EAGCD,sBAHD","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"]}
|
|
@@ -29,8 +29,7 @@ const ANNOTATION_ATTRIBUTE_PREFIX = 'annotation-text-';
|
|
|
29
29
|
* @param {Array} annotations The annotation to apply.
|
|
30
30
|
* @return {Object} A record with the annotations applied.
|
|
31
31
|
*/
|
|
32
|
-
function applyAnnotations(record) {
|
|
33
|
-
let annotations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
32
|
+
function applyAnnotations(record, annotations = []) {
|
|
34
33
|
annotations.forEach(annotation => {
|
|
35
34
|
let {
|
|
36
35
|
start,
|
|
@@ -112,11 +111,10 @@ function retrieveAnnotationPositions(formats) {
|
|
|
112
111
|
*/
|
|
113
112
|
|
|
114
113
|
|
|
115
|
-
function updateAnnotationsWithPositions(annotations, positions,
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
} = _ref;
|
|
114
|
+
function updateAnnotationsWithPositions(annotations, positions, {
|
|
115
|
+
removeAnnotation,
|
|
116
|
+
updateAnnotationRange
|
|
117
|
+
}) {
|
|
120
118
|
annotations.forEach(currentAnnotation => {
|
|
121
119
|
const position = positions[currentAnnotation.id]; // If we cannot find an annotation, delete it.
|
|
122
120
|
|
|
@@ -152,20 +150,18 @@ const annotation = {
|
|
|
152
150
|
return null;
|
|
153
151
|
},
|
|
154
152
|
|
|
155
|
-
__experimentalGetPropsForEditableTreePreparation(select,
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
} = _ref2;
|
|
153
|
+
__experimentalGetPropsForEditableTreePreparation(select, {
|
|
154
|
+
richTextIdentifier,
|
|
155
|
+
blockClientId
|
|
156
|
+
}) {
|
|
160
157
|
return {
|
|
161
158
|
annotations: select(_constants.STORE_NAME).__experimentalGetAnnotationsForRichText(blockClientId, richTextIdentifier)
|
|
162
159
|
};
|
|
163
160
|
},
|
|
164
161
|
|
|
165
|
-
__experimentalCreatePrepareEditableTree(
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
} = _ref3;
|
|
162
|
+
__experimentalCreatePrepareEditableTree({
|
|
163
|
+
annotations
|
|
164
|
+
}) {
|
|
169
165
|
return (formats, text) => {
|
|
170
166
|
if (annotations.length === 0) {
|
|
171
167
|
return formats;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/annotations/src/format/annotation.js"],"names":["FORMAT_NAME","ANNOTATION_ATTRIBUTE_PREFIX","applyAnnotations","record","annotations","forEach","annotation","start","end","text","length","className","source","id","type","attributes","removeAnnotations","retrieveAnnotationPositions","formats","positions","characterFormats","i","filter","format","replace","hasOwnProperty","updateAnnotationsWithPositions","removeAnnotation","updateAnnotationRange","currentAnnotation","position","name","title","tagName","edit","__experimentalGetPropsForEditableTreePreparation","select","richTextIdentifier","blockClientId","STORE_NAME","__experimentalGetAnnotationsForRichText","__experimentalCreatePrepareEditableTree","__experimentalGetPropsForEditableTreeChangeHandler","dispatch","__experimentalRemoveAnnotation","__experimentalUpdateAnnotationRange","__experimentalCreateOnChangeEditableValue","props"],"mappings":";;;;;;;;;AAGA;;AACA;;AAQA;;AAZA;AACA;AACA;AAIA,MAAMA,WAAW,GAAG,iBAApB;AAEA,MAAMC,2BAA2B,GAAG,kBAApC;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,gBAAT,CAA2BC,MAA3B,EAAsD;AAAA,MAAnBC,WAAmB,uEAAL,EAAK;AAC5DA,EAAAA,WAAW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C,EAAAA,yCAAyC,CAAEC,KAAF,EAAU;AAClD,WAAS7B,OAAF,IAAe;AACrB,YAAMC,SAAS,GAAGF,2BAA2B,CAAEC,OAAF,CAA7C;AACA,YAAM;AAAES,QAAAA,gBAAF;AAAoBC,QAAAA,qBAApB;AAA2CxB,QAAAA;AAA3C,UACL2C,KADD;AAGArB,MAAAA,8BAA8B,CAAEtB,WAAF,EAAee,SAAf,EAA0B;AACvDQ,QAAAA,gBADuD;AAEvDC,QAAAA;AAFuD,OAA1B,CAA9B;AAIA,KATD;AAUA;;AAvDwB,CAAnB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { applyFormat, removeFormat } from '@wordpress/rich-text';\n\nconst FORMAT_NAME = 'core/annotation';\n\nconst ANNOTATION_ATTRIBUTE_PREFIX = 'annotation-text-';\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../store/constants';\n\n/**\n * Applies given annotations to the given record.\n *\n * @param {Object} record The record to apply annotations to.\n * @param {Array} annotations The annotation to apply.\n * @return {Object} A record with the annotations applied.\n */\nexport function applyAnnotations( record, annotations = [] ) {\n\tannotations.forEach( ( annotation ) => {\n\t\tlet { start, end } = annotation;\n\n\t\tif ( start > record.text.length ) {\n\t\t\tstart = record.text.length;\n\t\t}\n\n\t\tif ( end > record.text.length ) {\n\t\t\tend = record.text.length;\n\t\t}\n\n\t\tconst className = ANNOTATION_ATTRIBUTE_PREFIX + annotation.source;\n\t\tconst id = ANNOTATION_ATTRIBUTE_PREFIX + annotation.id;\n\n\t\trecord = applyFormat(\n\t\t\trecord,\n\t\t\t{\n\t\t\t\ttype: FORMAT_NAME,\n\t\t\t\tattributes: {\n\t\t\t\t\tclassName,\n\t\t\t\t\tid,\n\t\t\t\t},\n\t\t\t},\n\t\t\tstart,\n\t\t\tend\n\t\t);\n\t} );\n\n\treturn record;\n}\n\n/**\n * Removes annotations from the given record.\n *\n * @param {Object} record Record to remove annotations from.\n * @return {Object} The cleaned record.\n */\nexport function removeAnnotations( record ) {\n\treturn removeFormat( record, 'core/annotation', 0, record.text.length );\n}\n\n/**\n * Retrieves the positions of annotations inside an array of formats.\n *\n * @param {Array} formats Formats with annotations in there.\n * @return {Object} ID keyed positions of annotations.\n */\nfunction retrieveAnnotationPositions( formats ) {\n\tconst positions = {};\n\n\tformats.forEach( ( characterFormats, i ) => {\n\t\tcharacterFormats = characterFormats || [];\n\t\tcharacterFormats = characterFormats.filter(\n\t\t\t( format ) => format.type === FORMAT_NAME\n\t\t);\n\t\tcharacterFormats.forEach( ( format ) => {\n\t\t\tlet { id } = format.attributes;\n\t\t\tid = id.replace( ANNOTATION_ATTRIBUTE_PREFIX, '' );\n\n\t\t\tif ( ! positions.hasOwnProperty( id ) ) {\n\t\t\t\tpositions[ id ] = {\n\t\t\t\t\tstart: i,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Annotations refer to positions between characters.\n\t\t\t// Formats refer to the character themselves.\n\t\t\t// So we need to adjust for that here.\n\t\t\tpositions[ id ].end = i + 1;\n\t\t} );\n\t} );\n\n\treturn positions;\n}\n\n/**\n * Updates annotations in the state based on positions retrieved from RichText.\n *\n * @param {Array} annotations The annotations that are currently applied.\n * @param {Array} positions The current positions of the given annotations.\n * @param {Object} actions\n * @param {Function} actions.removeAnnotation Function to remove an annotation from the state.\n * @param {Function} actions.updateAnnotationRange Function to update an annotation range in the state.\n */\nfunction updateAnnotationsWithPositions(\n\tannotations,\n\tpositions,\n\t{ removeAnnotation, updateAnnotationRange }\n) {\n\tannotations.forEach( ( currentAnnotation ) => {\n\t\tconst position = positions[ currentAnnotation.id ];\n\t\t// If we cannot find an annotation, delete it.\n\t\tif ( ! position ) {\n\t\t\t// Apparently the annotation has been removed, so remove it from the state:\n\t\t\t// Remove...\n\t\t\tremoveAnnotation( currentAnnotation.id );\n\t\t\treturn;\n\t\t}\n\n\t\tconst { start, end } = currentAnnotation;\n\t\tif ( start !== position.start || end !== position.end ) {\n\t\t\tupdateAnnotationRange(\n\t\t\t\tcurrentAnnotation.id,\n\t\t\t\tposition.start,\n\t\t\t\tposition.end\n\t\t\t);\n\t\t}\n\t} );\n}\n\nexport const annotation = {\n\tname: FORMAT_NAME,\n\ttitle: __( 'Annotation' ),\n\ttagName: 'mark',\n\tclassName: 'annotation-text',\n\tattributes: {\n\t\tclassName: 'class',\n\t\tid: 'id',\n\t},\n\tedit() {\n\t\treturn null;\n\t},\n\t__experimentalGetPropsForEditableTreePreparation(\n\t\tselect,\n\t\t{ richTextIdentifier, blockClientId }\n\t) {\n\t\treturn {\n\t\t\tannotations: select(\n\t\t\t\tSTORE_NAME\n\t\t\t).__experimentalGetAnnotationsForRichText(\n\t\t\t\tblockClientId,\n\t\t\t\trichTextIdentifier\n\t\t\t),\n\t\t};\n\t},\n\t__experimentalCreatePrepareEditableTree( { annotations } ) {\n\t\treturn ( formats, text ) => {\n\t\t\tif ( annotations.length === 0 ) {\n\t\t\t\treturn formats;\n\t\t\t}\n\n\t\t\tlet record = { formats, text };\n\t\t\trecord = applyAnnotations( record, annotations );\n\t\t\treturn record.formats;\n\t\t};\n\t},\n\t__experimentalGetPropsForEditableTreeChangeHandler( dispatch ) {\n\t\treturn {\n\t\t\tremoveAnnotation:\n\t\t\t\tdispatch( STORE_NAME ).__experimentalRemoveAnnotation,\n\t\t\tupdateAnnotationRange:\n\t\t\t\tdispatch( STORE_NAME ).__experimentalUpdateAnnotationRange,\n\t\t};\n\t},\n\t__experimentalCreateOnChangeEditableValue( props ) {\n\t\treturn ( formats ) => {\n\t\t\tconst positions = retrieveAnnotationPositions( formats );\n\t\t\tconst { removeAnnotation, updateAnnotationRange, annotations } =\n\t\t\t\tprops;\n\n\t\t\tupdateAnnotationsWithPositions( annotations, positions, {\n\t\t\t\tremoveAnnotation,\n\t\t\t\tupdateAnnotationRange,\n\t\t\t} );\n\t\t};\n\t},\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/annotations/src/format/annotation.js"],"names":["FORMAT_NAME","ANNOTATION_ATTRIBUTE_PREFIX","applyAnnotations","record","annotations","forEach","annotation","start","end","text","length","className","source","id","type","attributes","removeAnnotations","retrieveAnnotationPositions","formats","positions","characterFormats","i","filter","format","replace","hasOwnProperty","updateAnnotationsWithPositions","removeAnnotation","updateAnnotationRange","currentAnnotation","position","name","title","tagName","edit","__experimentalGetPropsForEditableTreePreparation","select","richTextIdentifier","blockClientId","STORE_NAME","__experimentalGetAnnotationsForRichText","__experimentalCreatePrepareEditableTree","__experimentalGetPropsForEditableTreeChangeHandler","dispatch","__experimentalRemoveAnnotation","__experimentalUpdateAnnotationRange","__experimentalCreateOnChangeEditableValue","props"],"mappings":";;;;;;;;;AAGA;;AACA;;AAQA;;AAZA;AACA;AACA;AAIA,MAAMA,WAAW,GAAG,iBAApB;AAEA,MAAMC,2BAA2B,GAAG,kBAApC;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,gBAAT,CAA2BC,MAA3B,EAAmCC,WAAW,GAAG,EAAjD,EAAsD;AAC5DA,EAAAA,WAAW,CAACC,OAAZ,CAAuBC,UAAF,IAAkB;AACtC,QAAI;AAAEC,MAAAA,KAAF;AAASC,MAAAA;AAAT,QAAiBF,UAArB;;AAEA,QAAKC,KAAK,GAAGJ,MAAM,CAACM,IAAP,CAAYC,MAAzB,EAAkC;AACjCH,MAAAA,KAAK,GAAGJ,MAAM,CAACM,IAAP,CAAYC,MAApB;AACA;;AAED,QAAKF,GAAG,GAAGL,MAAM,CAACM,IAAP,CAAYC,MAAvB,EAAgC;AAC/BF,MAAAA,GAAG,GAAGL,MAAM,CAACM,IAAP,CAAYC,MAAlB;AACA;;AAED,UAAMC,SAAS,GAAGV,2BAA2B,GAAGK,UAAU,CAACM,MAA3D;AACA,UAAMC,EAAE,GAAGZ,2BAA2B,GAAGK,UAAU,CAACO,EAApD;AAEAV,IAAAA,MAAM,GAAG,2BACRA,MADQ,EAER;AACCW,MAAAA,IAAI,EAAEd,WADP;AAECe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AAP;AAQA,GAxBwB;;AAyBzBI,EAAAA,uCAAuC,CAAE;AAAErC,IAAAA;AAAF,GAAF,EAAoB;AAC1D,WAAO,CAAEc,OAAF,EAAWT,IAAX,KAAqB;AAC3B,UAAKL,WAAW,CAACM,MAAZ,KAAuB,CAA5B,EAAgC;AAC/B,eAAOQ,OAAP;AACA;;AAED,UAAIf,MAAM,GAAG;AAAEe,QAAAA,OAAF;AAAWT,QAAAA;AAAX,OAAb;AACAN,MAAAA,MAAM,GAAGD,gBAAgB,CAAEC,MAAF,EAAUC,WAAV,CAAzB;AACA,aAAOD,MAAM,CAACe,OAAd;AACA,KARD;AASA,GAnCwB;;AAoCzBwB,EAAAA,kDAAkD,CAAEC,QAAF,EAAa;AAC9D,WAAO;AACNhB,MAAAA,gBAAgB,EACfgB,QAAQ,CAAEJ,qBAAF,CAAR,CAAuBK,8BAFlB;AAGNhB,MAAAA,qBAAqB,EACpBe,QAAQ,CAAEJ,qBAAF,CAAR,CAAuBM;AAJlB,KAAP;AAMA,GA3CwB;;AA4CzBC,EAAAA,yCAAyC,CAAEC,KAAF,EAAU;AAClD,WAAS7B,OAAF,IAAe;AACrB,YAAMC,SAAS,GAAGF,2BAA2B,CAAEC,OAAF,CAA7C;AACA,YAAM;AAAES,QAAAA,gBAAF;AAAoBC,QAAAA,qBAApB;AAA2CxB,QAAAA;AAA3C,UACL2C,KADD;AAGArB,MAAAA,8BAA8B,CAAEtB,WAAF,EAAee,SAAf,EAA0B;AACvDQ,QAAAA,gBADuD;AAEvDC,QAAAA;AAFuD,OAA1B,CAA9B;AAIA,KATD;AAUA;;AAvDwB,CAAnB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { applyFormat, removeFormat } from '@wordpress/rich-text';\n\nconst FORMAT_NAME = 'core/annotation';\n\nconst ANNOTATION_ATTRIBUTE_PREFIX = 'annotation-text-';\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../store/constants';\n\n/**\n * Applies given annotations to the given record.\n *\n * @param {Object} record The record to apply annotations to.\n * @param {Array} annotations The annotation to apply.\n * @return {Object} A record with the annotations applied.\n */\nexport function applyAnnotations( record, annotations = [] ) {\n\tannotations.forEach( ( annotation ) => {\n\t\tlet { start, end } = annotation;\n\n\t\tif ( start > record.text.length ) {\n\t\t\tstart = record.text.length;\n\t\t}\n\n\t\tif ( end > record.text.length ) {\n\t\t\tend = record.text.length;\n\t\t}\n\n\t\tconst className = ANNOTATION_ATTRIBUTE_PREFIX + annotation.source;\n\t\tconst id = ANNOTATION_ATTRIBUTE_PREFIX + annotation.id;\n\n\t\trecord = applyFormat(\n\t\t\trecord,\n\t\t\t{\n\t\t\t\ttype: FORMAT_NAME,\n\t\t\t\tattributes: {\n\t\t\t\t\tclassName,\n\t\t\t\t\tid,\n\t\t\t\t},\n\t\t\t},\n\t\t\tstart,\n\t\t\tend\n\t\t);\n\t} );\n\n\treturn record;\n}\n\n/**\n * Removes annotations from the given record.\n *\n * @param {Object} record Record to remove annotations from.\n * @return {Object} The cleaned record.\n */\nexport function removeAnnotations( record ) {\n\treturn removeFormat( record, 'core/annotation', 0, record.text.length );\n}\n\n/**\n * Retrieves the positions of annotations inside an array of formats.\n *\n * @param {Array} formats Formats with annotations in there.\n * @return {Object} ID keyed positions of annotations.\n */\nfunction retrieveAnnotationPositions( formats ) {\n\tconst positions = {};\n\n\tformats.forEach( ( characterFormats, i ) => {\n\t\tcharacterFormats = characterFormats || [];\n\t\tcharacterFormats = characterFormats.filter(\n\t\t\t( format ) => format.type === FORMAT_NAME\n\t\t);\n\t\tcharacterFormats.forEach( ( format ) => {\n\t\t\tlet { id } = format.attributes;\n\t\t\tid = id.replace( ANNOTATION_ATTRIBUTE_PREFIX, '' );\n\n\t\t\tif ( ! positions.hasOwnProperty( id ) ) {\n\t\t\t\tpositions[ id ] = {\n\t\t\t\t\tstart: i,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Annotations refer to positions between characters.\n\t\t\t// Formats refer to the character themselves.\n\t\t\t// So we need to adjust for that here.\n\t\t\tpositions[ id ].end = i + 1;\n\t\t} );\n\t} );\n\n\treturn positions;\n}\n\n/**\n * Updates annotations in the state based on positions retrieved from RichText.\n *\n * @param {Array} annotations The annotations that are currently applied.\n * @param {Array} positions The current positions of the given annotations.\n * @param {Object} actions\n * @param {Function} actions.removeAnnotation Function to remove an annotation from the state.\n * @param {Function} actions.updateAnnotationRange Function to update an annotation range in the state.\n */\nfunction updateAnnotationsWithPositions(\n\tannotations,\n\tpositions,\n\t{ removeAnnotation, updateAnnotationRange }\n) {\n\tannotations.forEach( ( currentAnnotation ) => {\n\t\tconst position = positions[ currentAnnotation.id ];\n\t\t// If we cannot find an annotation, delete it.\n\t\tif ( ! position ) {\n\t\t\t// Apparently the annotation has been removed, so remove it from the state:\n\t\t\t// Remove...\n\t\t\tremoveAnnotation( currentAnnotation.id );\n\t\t\treturn;\n\t\t}\n\n\t\tconst { start, end } = currentAnnotation;\n\t\tif ( start !== position.start || end !== position.end ) {\n\t\t\tupdateAnnotationRange(\n\t\t\t\tcurrentAnnotation.id,\n\t\t\t\tposition.start,\n\t\t\t\tposition.end\n\t\t\t);\n\t\t}\n\t} );\n}\n\nexport const annotation = {\n\tname: FORMAT_NAME,\n\ttitle: __( 'Annotation' ),\n\ttagName: 'mark',\n\tclassName: 'annotation-text',\n\tattributes: {\n\t\tclassName: 'class',\n\t\tid: 'id',\n\t},\n\tedit() {\n\t\treturn null;\n\t},\n\t__experimentalGetPropsForEditableTreePreparation(\n\t\tselect,\n\t\t{ richTextIdentifier, blockClientId }\n\t) {\n\t\treturn {\n\t\t\tannotations: select(\n\t\t\t\tSTORE_NAME\n\t\t\t).__experimentalGetAnnotationsForRichText(\n\t\t\t\tblockClientId,\n\t\t\t\trichTextIdentifier\n\t\t\t),\n\t\t};\n\t},\n\t__experimentalCreatePrepareEditableTree( { annotations } ) {\n\t\treturn ( formats, text ) => {\n\t\t\tif ( annotations.length === 0 ) {\n\t\t\t\treturn formats;\n\t\t\t}\n\n\t\t\tlet record = { formats, text };\n\t\t\trecord = applyAnnotations( record, annotations );\n\t\t\treturn record.formats;\n\t\t};\n\t},\n\t__experimentalGetPropsForEditableTreeChangeHandler( dispatch ) {\n\t\treturn {\n\t\t\tremoveAnnotation:\n\t\t\t\tdispatch( STORE_NAME ).__experimentalRemoveAnnotation,\n\t\t\tupdateAnnotationRange:\n\t\t\t\tdispatch( STORE_NAME ).__experimentalUpdateAnnotationRange,\n\t\t};\n\t},\n\t__experimentalCreateOnChangeEditableValue( props ) {\n\t\treturn ( formats ) => {\n\t\t\tconst positions = retrieveAnnotationPositions( formats );\n\t\t\tconst { removeAnnotation, updateAnnotationRange, annotations } =\n\t\t\t\tprops;\n\n\t\t\tupdateAnnotationsWithPositions( annotations, positions, {\n\t\t\t\tremoveAnnotation,\n\t\t\t\tupdateAnnotationRange,\n\t\t\t} );\n\t\t};\n\t},\n};\n"]}
|
package/build/store/actions.js
CHANGED
|
@@ -41,15 +41,14 @@ var _uuid = require("uuid");
|
|
|
41
41
|
*
|
|
42
42
|
* @return {Object} Action object.
|
|
43
43
|
*/
|
|
44
|
-
function __experimentalAddAnnotation(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
} = _ref;
|
|
44
|
+
function __experimentalAddAnnotation({
|
|
45
|
+
blockClientId,
|
|
46
|
+
richTextIdentifier = null,
|
|
47
|
+
range = null,
|
|
48
|
+
selector = 'range',
|
|
49
|
+
source = 'default',
|
|
50
|
+
id = (0, _uuid.v4)()
|
|
51
|
+
}) {
|
|
53
52
|
const action = {
|
|
54
53
|
type: 'ANNOTATION_ADD',
|
|
55
54
|
id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/annotations/src/store/actions.js"],"names":["__experimentalAddAnnotation","blockClientId","richTextIdentifier","range","selector","source","id","action","type","__experimentalRemoveAnnotation","annotationId","__experimentalUpdateAnnotationRange","start","end","__experimentalRemoveAnnotationsBySource"],"mappings":";;;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,2BAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/annotations/src/store/actions.js"],"names":["__experimentalAddAnnotation","blockClientId","richTextIdentifier","range","selector","source","id","action","type","__experimentalRemoveAnnotation","annotationId","__experimentalUpdateAnnotationRange","start","end","__experimentalRemoveAnnotationsBySource"],"mappings":";;;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,2BAAT,CAAsC;AAC5CC,EAAAA,aAD4C;AAE5CC,EAAAA,kBAAkB,GAAG,IAFuB;AAG5CC,EAAAA,KAAK,GAAG,IAHoC;AAI5CC,EAAAA,QAAQ,GAAG,OAJiC;AAK5CC,EAAAA,MAAM,GAAG,SALmC;AAM5CC,EAAAA,EAAE,GAAG;AANuC,CAAtC,EAOH;AACH,QAAMC,MAAM,GAAG;AACdC,IAAAA,IAAI,EAAE,gBADQ;AAEdF,IAAAA,EAFc;AAGdL,IAAAA,aAHc;AAIdC,IAAAA,kBAJc;AAKdG,IAAAA,MALc;AAMdD,IAAAA;AANc,GAAf;;AASA,MAAKA,QAAQ,KAAK,OAAlB,EAA4B;AAC3BG,IAAAA,MAAM,CAACJ,KAAP,GAAeA,KAAf;AACA;;AAED,SAAOI,MAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,8BAAT,CAAyCC,YAAzC,EAAwD;AAC9D,SAAO;AACNF,IAAAA,IAAI,EAAE,mBADA;AAENE,IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,mCAAT,CACND,YADM,EAENE,KAFM,EAGNC,GAHM,EAIL;AACD,SAAO;AACNL,IAAAA,IAAI,EAAE,yBADA;AAENE,IAAAA,YAFM;AAGNE,IAAAA,KAHM;AAINC,IAAAA;AAJM,GAAP;AAMA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,uCAAT,CAAkDT,MAAlD,EAA2D;AACjE,SAAO;AACNG,IAAAA,IAAI,EAAE,0BADA;AAENH,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport { v4 as uuid } from 'uuid';\n\n/**\n * @typedef WPAnnotationRange\n *\n * @property {number} start The offset where the annotation should start.\n * @property {number} end The offset where the annotation should end.\n */\n\n/**\n * Adds an annotation to a block.\n *\n * The `block` attribute refers to a block ID that needs to be annotated.\n * `isBlockAnnotation` controls whether or not the annotation is a block\n * annotation. The `source` is the source of the annotation, this will be used\n * to identity groups of annotations.\n *\n * The `range` property is only relevant if the selector is 'range'.\n *\n * @param {Object} annotation The annotation to add.\n * @param {string} annotation.blockClientId The blockClientId to add the annotation to.\n * @param {string} annotation.richTextIdentifier Identifier for the RichText instance the annotation applies to.\n * @param {WPAnnotationRange} annotation.range The range at which to apply this annotation.\n * @param {string} [annotation.selector=\"range\"] The way to apply this annotation.\n * @param {string} [annotation.source=\"default\"] The source that added the annotation.\n * @param {string} [annotation.id] The ID the annotation should have. Generates a UUID by default.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalAddAnnotation( {\n\tblockClientId,\n\trichTextIdentifier = null,\n\trange = null,\n\tselector = 'range',\n\tsource = 'default',\n\tid = uuid(),\n} ) {\n\tconst action = {\n\t\ttype: 'ANNOTATION_ADD',\n\t\tid,\n\t\tblockClientId,\n\t\trichTextIdentifier,\n\t\tsource,\n\t\tselector,\n\t};\n\n\tif ( selector === 'range' ) {\n\t\taction.range = range;\n\t}\n\n\treturn action;\n}\n\n/**\n * Removes an annotation with a specific ID.\n *\n * @param {string} annotationId The annotation to remove.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalRemoveAnnotation( annotationId ) {\n\treturn {\n\t\ttype: 'ANNOTATION_REMOVE',\n\t\tannotationId,\n\t};\n}\n\n/**\n * Updates the range of an annotation.\n *\n * @param {string} annotationId ID of the annotation to update.\n * @param {number} start The start of the new range.\n * @param {number} end The end of the new range.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalUpdateAnnotationRange(\n\tannotationId,\n\tstart,\n\tend\n) {\n\treturn {\n\t\ttype: 'ANNOTATION_UPDATE_RANGE',\n\t\tannotationId,\n\t\tstart,\n\t\tend,\n\t};\n}\n\n/**\n * Removes all annotations of a specific source.\n *\n * @param {string} source The source to remove.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalRemoveAnnotationsBySource( source ) {\n\treturn {\n\t\ttype: 'ANNOTATION_REMOVE_SOURCE',\n\t\tsource,\n\t};\n}\n"]}
|
package/build/store/reducer.js
CHANGED
|
@@ -29,12 +29,9 @@ function filterWithReference(collection, predicate) {
|
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
const mapValues = (obj, callback) => Object.entries(obj).reduce((acc,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
[key]: callback(value)
|
|
36
|
-
};
|
|
37
|
-
}, {});
|
|
32
|
+
const mapValues = (obj, callback) => Object.entries(obj).reduce((acc, [key, value]) => ({ ...acc,
|
|
33
|
+
[key]: callback(value)
|
|
34
|
+
}), {});
|
|
38
35
|
/**
|
|
39
36
|
* Verifies whether the given annotations is a valid annotation.
|
|
40
37
|
*
|
|
@@ -56,12 +53,9 @@ function isValidAnnotationRange(annotation) {
|
|
|
56
53
|
*/
|
|
57
54
|
|
|
58
55
|
|
|
59
|
-
function annotations() {
|
|
56
|
+
function annotations(state = {}, action) {
|
|
60
57
|
var _state$blockClientId;
|
|
61
58
|
|
|
62
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
63
|
-
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
64
|
-
|
|
65
59
|
switch (action.type) {
|
|
66
60
|
case 'ANNOTATION_ADD':
|
|
67
61
|
const blockClientId = action.blockClientId;
|
|
@@ -78,7 +72,7 @@ function annotations() {
|
|
|
78
72
|
return state;
|
|
79
73
|
}
|
|
80
74
|
|
|
81
|
-
const previousAnnotationsForBlock = (_state$blockClientId = state
|
|
75
|
+
const previousAnnotationsForBlock = (_state$blockClientId = state?.[blockClientId]) !== null && _state$blockClientId !== void 0 ? _state$blockClientId : [];
|
|
82
76
|
return { ...state,
|
|
83
77
|
[blockClientId]: [...previousAnnotationsForBlock, newAnnotation]
|
|
84
78
|
};
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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,EAAO,CAAEC,GAAF,EAAOC,KAAP,CAAP,MAA6B,EAC5B,GAAGF,GADyB;AAE5B,GAAEC,GAAF,GAASL,QAAQ,CAAEM,KAAF;AAFW,CAA7B,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,UAAU,CAACE,GAHhC;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,WAAT,CAAsBC,KAAK,GAAG,EAA9B,EAAkCC,MAAlC,EAA2C;AAAA;;AACjD,UAASA,MAAM,CAACC,IAAhB;AACC,SAAK,gBAAL;AACC,YAAMC,aAAa,GAAGF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AAA,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"]}
|
package/build/store/selectors.js
CHANGED
|
@@ -37,13 +37,13 @@ const EMPTY_ARRAY = [];
|
|
|
37
37
|
const __experimentalGetAnnotationsForBlock = (0, _rememo.default)((state, blockClientId) => {
|
|
38
38
|
var _state$blockClientId;
|
|
39
39
|
|
|
40
|
-
return ((_state$blockClientId = state
|
|
40
|
+
return ((_state$blockClientId = state?.[blockClientId]) !== null && _state$blockClientId !== void 0 ? _state$blockClientId : []).filter(annotation => {
|
|
41
41
|
return annotation.selector === 'block';
|
|
42
42
|
});
|
|
43
43
|
}, (state, blockClientId) => {
|
|
44
44
|
var _state$blockClientId2;
|
|
45
45
|
|
|
46
|
-
return [(_state$blockClientId2 = state
|
|
46
|
+
return [(_state$blockClientId2 = state?.[blockClientId]) !== null && _state$blockClientId2 !== void 0 ? _state$blockClientId2 : EMPTY_ARRAY];
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
exports.__experimentalGetAnnotationsForBlock = __experimentalGetAnnotationsForBlock;
|
|
@@ -51,7 +51,7 @@ exports.__experimentalGetAnnotationsForBlock = __experimentalGetAnnotationsForBl
|
|
|
51
51
|
function __experimentalGetAllAnnotationsForBlock(state, blockClientId) {
|
|
52
52
|
var _state$blockClientId3;
|
|
53
53
|
|
|
54
|
-
return (_state$blockClientId3 = state
|
|
54
|
+
return (_state$blockClientId3 = state?.[blockClientId]) !== null && _state$blockClientId3 !== void 0 ? _state$blockClientId3 : EMPTY_ARRAY;
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
* Returns the annotations that apply to the given RichText instance.
|
|
@@ -70,7 +70,7 @@ function __experimentalGetAllAnnotationsForBlock(state, blockClientId) {
|
|
|
70
70
|
const __experimentalGetAnnotationsForRichText = (0, _rememo.default)((state, blockClientId, richTextIdentifier) => {
|
|
71
71
|
var _state$blockClientId4;
|
|
72
72
|
|
|
73
|
-
return ((_state$blockClientId4 = state
|
|
73
|
+
return ((_state$blockClientId4 = state?.[blockClientId]) !== null && _state$blockClientId4 !== void 0 ? _state$blockClientId4 : []).filter(annotation => {
|
|
74
74
|
return annotation.selector === 'range' && richTextIdentifier === annotation.richTextIdentifier;
|
|
75
75
|
}).map(annotation => {
|
|
76
76
|
const {
|
|
@@ -84,7 +84,7 @@ const __experimentalGetAnnotationsForRichText = (0, _rememo.default)((state, blo
|
|
|
84
84
|
}, (state, blockClientId) => {
|
|
85
85
|
var _state$blockClientId5;
|
|
86
86
|
|
|
87
|
-
return [(_state$blockClientId5 = state
|
|
87
|
+
return [(_state$blockClientId5 = state?.[blockClientId]) !== null && _state$blockClientId5 !== void 0 ? _state$blockClientId5 : EMPTY_ARRAY];
|
|
88
88
|
});
|
|
89
89
|
/**
|
|
90
90
|
* Returns all annotations in the editor state.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/annotations/src/store/selectors.js"],"names":["EMPTY_ARRAY","__experimentalGetAnnotationsForBlock","state","blockClientId","filter","annotation","selector","__experimentalGetAllAnnotationsForBlock","__experimentalGetAnnotationsForRichText","richTextIdentifier","map","range","other","__experimentalGetAnnotations","Object","values","flat"],"mappings":";;;;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,WAAW,GAAG,EAApB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,MAAMC,oCAAoC,GAAG,qBACnD,CAAEC,KAAF,EAASC,aAAT,KAA4B;AAAA;;AAC3B,SAAO,yBAAED,
|
|
1
|
+
{"version":3,"sources":["@wordpress/annotations/src/store/selectors.js"],"names":["EMPTY_ARRAY","__experimentalGetAnnotationsForBlock","state","blockClientId","filter","annotation","selector","__experimentalGetAllAnnotationsForBlock","__experimentalGetAnnotationsForRichText","richTextIdentifier","map","range","other","__experimentalGetAnnotations","Object","values","flat"],"mappings":";;;;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,WAAW,GAAG,EAApB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,MAAMC,oCAAoC,GAAG,qBACnD,CAAEC,KAAF,EAASC,aAAT,KAA4B;AAAA;;AAC3B,SAAO,yBAAED,KAAK,GAAIC,aAAJ,CAAP,uEAA8B,EAA9B,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,KAAK,GAAIC,aAAJ,CAAP,yEAA8BH,WAA9B,CAA5B;AAAA,CANmD,CAA7C;;;;AASA,SAASO,uCAAT,CACNL,KADM,EAENC,aAFM,EAGL;AAAA;;AACD,kCAAOD,KAAK,GAAIC,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,KAAK,GAAIC,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,KAAK,GAAIC,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"]}
|
|
@@ -16,12 +16,10 @@ import { STORE_NAME } from '../store/constants';
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
const addAnnotationClassName = OriginalComponent => {
|
|
19
|
-
return withSelect((select,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
} = _ref;
|
|
24
|
-
|
|
19
|
+
return withSelect((select, {
|
|
20
|
+
clientId,
|
|
21
|
+
className
|
|
22
|
+
}) => {
|
|
25
23
|
const annotations = select(STORE_NAME).__experimentalGetAnnotationsForBlock(clientId);
|
|
26
24
|
|
|
27
25
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/annotations/src/block/index.js"],"names":["addFilter","withSelect","STORE_NAME","addAnnotationClassName","OriginalComponent","select","clientId","className","annotations","__experimentalGetAnnotationsForBlock","map","annotation","source","concat","filter","Boolean","join"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,kBAA1B;AACA,SAASC,UAAT,QAA2B,iBAA3B;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,oBAA3B;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,sBAAsB,GAAKC,iBAAF,IAAyB;AACvD,SAAOH,UAAU,CAAE,CAAEI,MAAF,
|
|
1
|
+
{"version":3,"sources":["@wordpress/annotations/src/block/index.js"],"names":["addFilter","withSelect","STORE_NAME","addAnnotationClassName","OriginalComponent","select","clientId","className","annotations","__experimentalGetAnnotationsForBlock","map","annotation","source","concat","filter","Boolean","join"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,kBAA1B;AACA,SAASC,UAAT,QAA2B,iBAA3B;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,oBAA3B;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,sBAAsB,GAAKC,iBAAF,IAAyB;AACvD,SAAOH,UAAU,CAAE,CAAEI,MAAF,EAAU;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,GAAV,KAAuC;AACzD,UAAMC,WAAW,GAChBH,MAAM,CAAEH,UAAF,CAAN,CAAqBO,oCAArB,CACCH,QADD,CADD;;AAKA,WAAO;AACNC,MAAAA,SAAS,EAAEC,WAAW,CACpBE,GADS,CACFC,UAAF,IAAkB;AACvB,eAAO,qBAAqBA,UAAU,CAACC,MAAvC;AACA,OAHS,EAITC,MAJS,CAIDN,SAJC,EAKTO,MALS,CAKDC,OALC,EAMTC,IANS,CAMH,GANG;AADL,KAAP;AASA,GAfgB,CAAV,CAeFZ,iBAfE,CAAP;AAgBA,CAjBD;;AAmBAJ,SAAS,CACR,uBADQ,EAER,kBAFQ,EAGRG,sBAHQ,CAAT","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { withSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../store/constants';\n/**\n * Adds annotation className to the block-list-block component.\n *\n * @param {Object} OriginalComponent The original BlockListBlock component.\n * @return {Object} The enhanced component.\n */\nconst addAnnotationClassName = ( OriginalComponent ) => {\n\treturn withSelect( ( select, { clientId, className } ) => {\n\t\tconst annotations =\n\t\t\tselect( STORE_NAME ).__experimentalGetAnnotationsForBlock(\n\t\t\t\tclientId\n\t\t\t);\n\n\t\treturn {\n\t\t\tclassName: annotations\n\t\t\t\t.map( ( annotation ) => {\n\t\t\t\t\treturn 'is-annotated-by-' + annotation.source;\n\t\t\t\t} )\n\t\t\t\t.concat( className )\n\t\t\t\t.filter( Boolean )\n\t\t\t\t.join( ' ' ),\n\t\t};\n\t} )( OriginalComponent );\n};\n\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/annotations',\n\taddAnnotationClassName\n);\n"]}
|
|
@@ -18,8 +18,7 @@ import { STORE_NAME } from '../store/constants';
|
|
|
18
18
|
* @return {Object} A record with the annotations applied.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
export function applyAnnotations(record) {
|
|
22
|
-
let annotations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
21
|
+
export function applyAnnotations(record, annotations = []) {
|
|
23
22
|
annotations.forEach(annotation => {
|
|
24
23
|
let {
|
|
25
24
|
start,
|
|
@@ -99,11 +98,10 @@ function retrieveAnnotationPositions(formats) {
|
|
|
99
98
|
*/
|
|
100
99
|
|
|
101
100
|
|
|
102
|
-
function updateAnnotationsWithPositions(annotations, positions,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
} = _ref;
|
|
101
|
+
function updateAnnotationsWithPositions(annotations, positions, {
|
|
102
|
+
removeAnnotation,
|
|
103
|
+
updateAnnotationRange
|
|
104
|
+
}) {
|
|
107
105
|
annotations.forEach(currentAnnotation => {
|
|
108
106
|
const position = positions[currentAnnotation.id]; // If we cannot find an annotation, delete it.
|
|
109
107
|
|
|
@@ -139,20 +137,18 @@ export const annotation = {
|
|
|
139
137
|
return null;
|
|
140
138
|
},
|
|
141
139
|
|
|
142
|
-
__experimentalGetPropsForEditableTreePreparation(select,
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
} = _ref2;
|
|
140
|
+
__experimentalGetPropsForEditableTreePreparation(select, {
|
|
141
|
+
richTextIdentifier,
|
|
142
|
+
blockClientId
|
|
143
|
+
}) {
|
|
147
144
|
return {
|
|
148
145
|
annotations: select(STORE_NAME).__experimentalGetAnnotationsForRichText(blockClientId, richTextIdentifier)
|
|
149
146
|
};
|
|
150
147
|
},
|
|
151
148
|
|
|
152
|
-
__experimentalCreatePrepareEditableTree(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
} = _ref3;
|
|
149
|
+
__experimentalCreatePrepareEditableTree({
|
|
150
|
+
annotations
|
|
151
|
+
}) {
|
|
156
152
|
return (formats, text) => {
|
|
157
153
|
if (annotations.length === 0) {
|
|
158
154
|
return formats;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/annotations/src/format/annotation.js"],"names":["__","applyFormat","removeFormat","FORMAT_NAME","ANNOTATION_ATTRIBUTE_PREFIX","STORE_NAME","applyAnnotations","record","annotations","forEach","annotation","start","end","text","length","className","source","id","type","attributes","removeAnnotations","retrieveAnnotationPositions","formats","positions","characterFormats","i","filter","format","replace","hasOwnProperty","updateAnnotationsWithPositions","removeAnnotation","updateAnnotationRange","currentAnnotation","position","name","title","tagName","edit","__experimentalGetPropsForEditableTreePreparation","select","richTextIdentifier","blockClientId","__experimentalGetAnnotationsForRichText","__experimentalCreatePrepareEditableTree","__experimentalGetPropsForEditableTreeChangeHandler","dispatch","__experimentalRemoveAnnotation","__experimentalUpdateAnnotationRange","__experimentalCreateOnChangeEditableValue","props"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;A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D,gBAAgB,CAAEC,MAAF,EAAUC,WAAV,CAAzB;AACA,aAAOD,MAAM,CAACe,OAAd;AACA,KARD;AASA,GAnCwB;;AAoCzBuB,EAAAA,kDAAkD,CAAEC,QAAF,EAAa;AAC9D,WAAO;AACNf,MAAAA,gBAAgB,EACfe,QAAQ,CAAEzC,UAAF,CAAR,CAAuB0C,8BAFlB;AAGNf,MAAAA,qBAAqB,EACpBc,QAAQ,CAAEzC,UAAF,CAAR,CAAuB2C;AAJlB,KAAP;AAMA,GA3CwB;;AA4CzBC,EAAAA,yCAAyC,CAAEC,KAAF,EAAU;AAClD,WAAS5B,OAAF,IAAe;AACrB,YAAMC,SAAS,GAAGF,2BAA2B,CAAEC,OAAF,CAA7C;AACA,YAAM;AAAES,QAAAA,gBAAF;AAAoBC,QAAAA,qBAApB;AAA2CxB,QAAAA;AAA3C,UACL0C,KADD;AAGApB,MAAAA,8BAA8B,CAAEtB,WAAF,EAAee,SAAf,EAA0B;AACvDQ,QAAAA,gBADuD;AAEvDC,QAAAA;AAFuD,OAA1B,CAA9B;AAIA,KATD;AAUA;;AAvDwB,CAAnB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { applyFormat, removeFormat } from '@wordpress/rich-text';\n\nconst FORMAT_NAME = 'core/annotation';\n\nconst ANNOTATION_ATTRIBUTE_PREFIX = 'annotation-text-';\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../store/constants';\n\n/**\n * Applies given annotations to the given record.\n *\n * @param {Object} record The record to apply annotations to.\n * @param {Array} annotations The annotation to apply.\n * @return {Object} A record with the annotations applied.\n */\nexport function applyAnnotations( record, annotations = [] ) {\n\tannotations.forEach( ( annotation ) => {\n\t\tlet { start, end } = annotation;\n\n\t\tif ( start > record.text.length ) {\n\t\t\tstart = record.text.length;\n\t\t}\n\n\t\tif ( end > record.text.length ) {\n\t\t\tend = record.text.length;\n\t\t}\n\n\t\tconst className = ANNOTATION_ATTRIBUTE_PREFIX + annotation.source;\n\t\tconst id = ANNOTATION_ATTRIBUTE_PREFIX + annotation.id;\n\n\t\trecord = applyFormat(\n\t\t\trecord,\n\t\t\t{\n\t\t\t\ttype: FORMAT_NAME,\n\t\t\t\tattributes: {\n\t\t\t\t\tclassName,\n\t\t\t\t\tid,\n\t\t\t\t},\n\t\t\t},\n\t\t\tstart,\n\t\t\tend\n\t\t);\n\t} );\n\n\treturn record;\n}\n\n/**\n * Removes annotations from the given record.\n *\n * @param {Object} record Record to remove annotations from.\n * @return {Object} The cleaned record.\n */\nexport function removeAnnotations( record ) {\n\treturn removeFormat( record, 'core/annotation', 0, record.text.length );\n}\n\n/**\n * Retrieves the positions of annotations inside an array of formats.\n *\n * @param {Array} formats Formats with annotations in there.\n * @return {Object} ID keyed positions of annotations.\n */\nfunction retrieveAnnotationPositions( formats ) {\n\tconst positions = {};\n\n\tformats.forEach( ( characterFormats, i ) => {\n\t\tcharacterFormats = characterFormats || [];\n\t\tcharacterFormats = characterFormats.filter(\n\t\t\t( format ) => format.type === FORMAT_NAME\n\t\t);\n\t\tcharacterFormats.forEach( ( format ) => {\n\t\t\tlet { id } = format.attributes;\n\t\t\tid = id.replace( ANNOTATION_ATTRIBUTE_PREFIX, '' );\n\n\t\t\tif ( ! positions.hasOwnProperty( id ) ) {\n\t\t\t\tpositions[ id ] = {\n\t\t\t\t\tstart: i,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Annotations refer to positions between characters.\n\t\t\t// Formats refer to the character themselves.\n\t\t\t// So we need to adjust for that here.\n\t\t\tpositions[ id ].end = i + 1;\n\t\t} );\n\t} );\n\n\treturn positions;\n}\n\n/**\n * Updates annotations in the state based on positions retrieved from RichText.\n *\n * @param {Array} annotations The annotations that are currently applied.\n * @param {Array} positions The current positions of the given annotations.\n * @param {Object} actions\n * @param {Function} actions.removeAnnotation Function to remove an annotation from the state.\n * @param {Function} actions.updateAnnotationRange Function to update an annotation range in the state.\n */\nfunction updateAnnotationsWithPositions(\n\tannotations,\n\tpositions,\n\t{ removeAnnotation, updateAnnotationRange }\n) {\n\tannotations.forEach( ( currentAnnotation ) => {\n\t\tconst position = positions[ currentAnnotation.id ];\n\t\t// If we cannot find an annotation, delete it.\n\t\tif ( ! position ) {\n\t\t\t// Apparently the annotation has been removed, so remove it from the state:\n\t\t\t// Remove...\n\t\t\tremoveAnnotation( currentAnnotation.id );\n\t\t\treturn;\n\t\t}\n\n\t\tconst { start, end } = currentAnnotation;\n\t\tif ( start !== position.start || end !== position.end ) {\n\t\t\tupdateAnnotationRange(\n\t\t\t\tcurrentAnnotation.id,\n\t\t\t\tposition.start,\n\t\t\t\tposition.end\n\t\t\t);\n\t\t}\n\t} );\n}\n\nexport const annotation = {\n\tname: FORMAT_NAME,\n\ttitle: __( 'Annotation' ),\n\ttagName: 'mark',\n\tclassName: 'annotation-text',\n\tattributes: {\n\t\tclassName: 'class',\n\t\tid: 'id',\n\t},\n\tedit() {\n\t\treturn null;\n\t},\n\t__experimentalGetPropsForEditableTreePreparation(\n\t\tselect,\n\t\t{ richTextIdentifier, blockClientId }\n\t) {\n\t\treturn {\n\t\t\tannotations: select(\n\t\t\t\tSTORE_NAME\n\t\t\t).__experimentalGetAnnotationsForRichText(\n\t\t\t\tblockClientId,\n\t\t\t\trichTextIdentifier\n\t\t\t),\n\t\t};\n\t},\n\t__experimentalCreatePrepareEditableTree( { annotations } ) {\n\t\treturn ( formats, text ) => {\n\t\t\tif ( annotations.length === 0 ) {\n\t\t\t\treturn formats;\n\t\t\t}\n\n\t\t\tlet record = { formats, text };\n\t\t\trecord = applyAnnotations( record, annotations );\n\t\t\treturn record.formats;\n\t\t};\n\t},\n\t__experimentalGetPropsForEditableTreeChangeHandler( dispatch ) {\n\t\treturn {\n\t\t\tremoveAnnotation:\n\t\t\t\tdispatch( STORE_NAME ).__experimentalRemoveAnnotation,\n\t\t\tupdateAnnotationRange:\n\t\t\t\tdispatch( STORE_NAME ).__experimentalUpdateAnnotationRange,\n\t\t};\n\t},\n\t__experimentalCreateOnChangeEditableValue( props ) {\n\t\treturn ( formats ) => {\n\t\t\tconst positions = retrieveAnnotationPositions( formats );\n\t\t\tconst { removeAnnotation, updateAnnotationRange, annotations } =\n\t\t\t\tprops;\n\n\t\t\tupdateAnnotationsWithPositions( annotations, positions, {\n\t\t\t\tremoveAnnotation,\n\t\t\t\tupdateAnnotationRange,\n\t\t\t} );\n\t\t};\n\t},\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/annotations/src/format/annotation.js"],"names":["__","applyFormat","removeFormat","FORMAT_NAME","ANNOTATION_ATTRIBUTE_PREFIX","STORE_NAME","applyAnnotations","record","annotations","forEach","annotation","start","end","text","length","className","source","id","type","attributes","removeAnnotations","retrieveAnnotationPositions","formats","positions","characterFormats","i","filter","format","replace","hasOwnProperty","updateAnnotationsWithPositions","removeAnnotation","updateAnnotationRange","currentAnnotation","position","name","title","tagName","edit","__experimentalGetPropsForEditableTreePreparation","select","richTextIdentifier","blockClientId","__experimentalGetAnnotationsForRichText","__experimentalCreatePrepareEditableTree","__experimentalGetPropsForEditableTreeChangeHandler","dispatch","__experimentalRemoveAnnotation","__experimentalUpdateAnnotationRange","__experimentalCreateOnChangeEditableValue","props"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,WAAT,EAAsBC,YAAtB,QAA0C,sBAA1C;AAEA,MAAMC,WAAW,GAAG,iBAApB;AAEA,MAAMC,2BAA2B,GAAG,kBAApC;AACA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,oBAA3B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,gBAAT,CAA2BC,MAA3B,EAAmCC,WAAW,GAAG,EAAjD,EAAsD;AAC5DA,EAAAA,WAAW,CAACC,OAAZ,CAAuBC,UAAF,IAAkB;AACtC,QAAI;AAAEC,MAAAA,KAAF;AAASC,MAAAA;AAAT,QAAiBF,UAArB;;AAEA,QAAKC,KAAK,GAAGJ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AF,CAA7C;AACA,YAAM;AAAES,QAAAA,gBAAF;AAAoBC,QAAAA,qBAApB;AAA2CxB,QAAAA;AAA3C,UACL0C,KADD;AAGApB,MAAAA,8BAA8B,CAAEtB,WAAF,EAAee,SAAf,EAA0B;AACvDQ,QAAAA,gBADuD;AAEvDC,QAAAA;AAFuD,OAA1B,CAA9B;AAIA,KATD;AAUA;;AAvDwB,CAAnB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { applyFormat, removeFormat } from '@wordpress/rich-text';\n\nconst FORMAT_NAME = 'core/annotation';\n\nconst ANNOTATION_ATTRIBUTE_PREFIX = 'annotation-text-';\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../store/constants';\n\n/**\n * Applies given annotations to the given record.\n *\n * @param {Object} record The record to apply annotations to.\n * @param {Array} annotations The annotation to apply.\n * @return {Object} A record with the annotations applied.\n */\nexport function applyAnnotations( record, annotations = [] ) {\n\tannotations.forEach( ( annotation ) => {\n\t\tlet { start, end } = annotation;\n\n\t\tif ( start > record.text.length ) {\n\t\t\tstart = record.text.length;\n\t\t}\n\n\t\tif ( end > record.text.length ) {\n\t\t\tend = record.text.length;\n\t\t}\n\n\t\tconst className = ANNOTATION_ATTRIBUTE_PREFIX + annotation.source;\n\t\tconst id = ANNOTATION_ATTRIBUTE_PREFIX + annotation.id;\n\n\t\trecord = applyFormat(\n\t\t\trecord,\n\t\t\t{\n\t\t\t\ttype: FORMAT_NAME,\n\t\t\t\tattributes: {\n\t\t\t\t\tclassName,\n\t\t\t\t\tid,\n\t\t\t\t},\n\t\t\t},\n\t\t\tstart,\n\t\t\tend\n\t\t);\n\t} );\n\n\treturn record;\n}\n\n/**\n * Removes annotations from the given record.\n *\n * @param {Object} record Record to remove annotations from.\n * @return {Object} The cleaned record.\n */\nexport function removeAnnotations( record ) {\n\treturn removeFormat( record, 'core/annotation', 0, record.text.length );\n}\n\n/**\n * Retrieves the positions of annotations inside an array of formats.\n *\n * @param {Array} formats Formats with annotations in there.\n * @return {Object} ID keyed positions of annotations.\n */\nfunction retrieveAnnotationPositions( formats ) {\n\tconst positions = {};\n\n\tformats.forEach( ( characterFormats, i ) => {\n\t\tcharacterFormats = characterFormats || [];\n\t\tcharacterFormats = characterFormats.filter(\n\t\t\t( format ) => format.type === FORMAT_NAME\n\t\t);\n\t\tcharacterFormats.forEach( ( format ) => {\n\t\t\tlet { id } = format.attributes;\n\t\t\tid = id.replace( ANNOTATION_ATTRIBUTE_PREFIX, '' );\n\n\t\t\tif ( ! positions.hasOwnProperty( id ) ) {\n\t\t\t\tpositions[ id ] = {\n\t\t\t\t\tstart: i,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Annotations refer to positions between characters.\n\t\t\t// Formats refer to the character themselves.\n\t\t\t// So we need to adjust for that here.\n\t\t\tpositions[ id ].end = i + 1;\n\t\t} );\n\t} );\n\n\treturn positions;\n}\n\n/**\n * Updates annotations in the state based on positions retrieved from RichText.\n *\n * @param {Array} annotations The annotations that are currently applied.\n * @param {Array} positions The current positions of the given annotations.\n * @param {Object} actions\n * @param {Function} actions.removeAnnotation Function to remove an annotation from the state.\n * @param {Function} actions.updateAnnotationRange Function to update an annotation range in the state.\n */\nfunction updateAnnotationsWithPositions(\n\tannotations,\n\tpositions,\n\t{ removeAnnotation, updateAnnotationRange }\n) {\n\tannotations.forEach( ( currentAnnotation ) => {\n\t\tconst position = positions[ currentAnnotation.id ];\n\t\t// If we cannot find an annotation, delete it.\n\t\tif ( ! position ) {\n\t\t\t// Apparently the annotation has been removed, so remove it from the state:\n\t\t\t// Remove...\n\t\t\tremoveAnnotation( currentAnnotation.id );\n\t\t\treturn;\n\t\t}\n\n\t\tconst { start, end } = currentAnnotation;\n\t\tif ( start !== position.start || end !== position.end ) {\n\t\t\tupdateAnnotationRange(\n\t\t\t\tcurrentAnnotation.id,\n\t\t\t\tposition.start,\n\t\t\t\tposition.end\n\t\t\t);\n\t\t}\n\t} );\n}\n\nexport const annotation = {\n\tname: FORMAT_NAME,\n\ttitle: __( 'Annotation' ),\n\ttagName: 'mark',\n\tclassName: 'annotation-text',\n\tattributes: {\n\t\tclassName: 'class',\n\t\tid: 'id',\n\t},\n\tedit() {\n\t\treturn null;\n\t},\n\t__experimentalGetPropsForEditableTreePreparation(\n\t\tselect,\n\t\t{ richTextIdentifier, blockClientId }\n\t) {\n\t\treturn {\n\t\t\tannotations: select(\n\t\t\t\tSTORE_NAME\n\t\t\t).__experimentalGetAnnotationsForRichText(\n\t\t\t\tblockClientId,\n\t\t\t\trichTextIdentifier\n\t\t\t),\n\t\t};\n\t},\n\t__experimentalCreatePrepareEditableTree( { annotations } ) {\n\t\treturn ( formats, text ) => {\n\t\t\tif ( annotations.length === 0 ) {\n\t\t\t\treturn formats;\n\t\t\t}\n\n\t\t\tlet record = { formats, text };\n\t\t\trecord = applyAnnotations( record, annotations );\n\t\t\treturn record.formats;\n\t\t};\n\t},\n\t__experimentalGetPropsForEditableTreeChangeHandler( dispatch ) {\n\t\treturn {\n\t\t\tremoveAnnotation:\n\t\t\t\tdispatch( STORE_NAME ).__experimentalRemoveAnnotation,\n\t\t\tupdateAnnotationRange:\n\t\t\t\tdispatch( STORE_NAME ).__experimentalUpdateAnnotationRange,\n\t\t};\n\t},\n\t__experimentalCreateOnChangeEditableValue( props ) {\n\t\treturn ( formats ) => {\n\t\t\tconst positions = retrieveAnnotationPositions( formats );\n\t\t\tconst { removeAnnotation, updateAnnotationRange, annotations } =\n\t\t\t\tprops;\n\n\t\t\tupdateAnnotationsWithPositions( annotations, positions, {\n\t\t\t\tremoveAnnotation,\n\t\t\t\tupdateAnnotationRange,\n\t\t\t} );\n\t\t};\n\t},\n};\n"]}
|
|
@@ -30,15 +30,14 @@ import { v4 as uuid } from 'uuid';
|
|
|
30
30
|
* @return {Object} Action object.
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
|
-
export function __experimentalAddAnnotation(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
} = _ref;
|
|
33
|
+
export function __experimentalAddAnnotation({
|
|
34
|
+
blockClientId,
|
|
35
|
+
richTextIdentifier = null,
|
|
36
|
+
range = null,
|
|
37
|
+
selector = 'range',
|
|
38
|
+
source = 'default',
|
|
39
|
+
id = uuid()
|
|
40
|
+
}) {
|
|
42
41
|
const action = {
|
|
43
42
|
type: 'ANNOTATION_ADD',
|
|
44
43
|
id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/annotations/src/store/actions.js"],"names":["v4","uuid","__experimentalAddAnnotation","blockClientId","richTextIdentifier","range","selector","source","id","action","type","__experimentalRemoveAnnotation","annotationId","__experimentalUpdateAnnotationRange","start","end","__experimentalRemoveAnnotationsBySource"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,IAAIC,IAAf,QAA2B,MAA3B;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,2BAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/annotations/src/store/actions.js"],"names":["v4","uuid","__experimentalAddAnnotation","blockClientId","richTextIdentifier","range","selector","source","id","action","type","__experimentalRemoveAnnotation","annotationId","__experimentalUpdateAnnotationRange","start","end","__experimentalRemoveAnnotationsBySource"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,IAAIC,IAAf,QAA2B,MAA3B;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,2BAAT,CAAsC;AAC5CC,EAAAA,aAD4C;AAE5CC,EAAAA,kBAAkB,GAAG,IAFuB;AAG5CC,EAAAA,KAAK,GAAG,IAHoC;AAI5CC,EAAAA,QAAQ,GAAG,OAJiC;AAK5CC,EAAAA,MAAM,GAAG,SALmC;AAM5CC,EAAAA,EAAE,GAAGP,IAAI;AANmC,CAAtC,EAOH;AACH,QAAMQ,MAAM,GAAG;AACdC,IAAAA,IAAI,EAAE,gBADQ;AAEdF,IAAAA,EAFc;AAGdL,IAAAA,aAHc;AAIdC,IAAAA,kBAJc;AAKdG,IAAAA,MALc;AAMdD,IAAAA;AANc,GAAf;;AASA,MAAKA,QAAQ,KAAK,OAAlB,EAA4B;AAC3BG,IAAAA,MAAM,CAACJ,KAAP,GAAeA,KAAf;AACA;;AAED,SAAOI,MAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,8BAAT,CAAyCC,YAAzC,EAAwD;AAC9D,SAAO;AACNF,IAAAA,IAAI,EAAE,mBADA;AAENE,IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,mCAAT,CACND,YADM,EAENE,KAFM,EAGNC,GAHM,EAIL;AACD,SAAO;AACNL,IAAAA,IAAI,EAAE,yBADA;AAENE,IAAAA,YAFM;AAGNE,IAAAA,KAHM;AAINC,IAAAA;AAJM,GAAP;AAMA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,uCAAT,CAAkDT,MAAlD,EAA2D;AACjE,SAAO;AACNG,IAAAA,IAAI,EAAE,0BADA;AAENH,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport { v4 as uuid } from 'uuid';\n\n/**\n * @typedef WPAnnotationRange\n *\n * @property {number} start The offset where the annotation should start.\n * @property {number} end The offset where the annotation should end.\n */\n\n/**\n * Adds an annotation to a block.\n *\n * The `block` attribute refers to a block ID that needs to be annotated.\n * `isBlockAnnotation` controls whether or not the annotation is a block\n * annotation. The `source` is the source of the annotation, this will be used\n * to identity groups of annotations.\n *\n * The `range` property is only relevant if the selector is 'range'.\n *\n * @param {Object} annotation The annotation to add.\n * @param {string} annotation.blockClientId The blockClientId to add the annotation to.\n * @param {string} annotation.richTextIdentifier Identifier for the RichText instance the annotation applies to.\n * @param {WPAnnotationRange} annotation.range The range at which to apply this annotation.\n * @param {string} [annotation.selector=\"range\"] The way to apply this annotation.\n * @param {string} [annotation.source=\"default\"] The source that added the annotation.\n * @param {string} [annotation.id] The ID the annotation should have. Generates a UUID by default.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalAddAnnotation( {\n\tblockClientId,\n\trichTextIdentifier = null,\n\trange = null,\n\tselector = 'range',\n\tsource = 'default',\n\tid = uuid(),\n} ) {\n\tconst action = {\n\t\ttype: 'ANNOTATION_ADD',\n\t\tid,\n\t\tblockClientId,\n\t\trichTextIdentifier,\n\t\tsource,\n\t\tselector,\n\t};\n\n\tif ( selector === 'range' ) {\n\t\taction.range = range;\n\t}\n\n\treturn action;\n}\n\n/**\n * Removes an annotation with a specific ID.\n *\n * @param {string} annotationId The annotation to remove.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalRemoveAnnotation( annotationId ) {\n\treturn {\n\t\ttype: 'ANNOTATION_REMOVE',\n\t\tannotationId,\n\t};\n}\n\n/**\n * Updates the range of an annotation.\n *\n * @param {string} annotationId ID of the annotation to update.\n * @param {number} start The start of the new range.\n * @param {number} end The end of the new range.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalUpdateAnnotationRange(\n\tannotationId,\n\tstart,\n\tend\n) {\n\treturn {\n\t\ttype: 'ANNOTATION_UPDATE_RANGE',\n\t\tannotationId,\n\t\tstart,\n\t\tend,\n\t};\n}\n\n/**\n * Removes all annotations of a specific source.\n *\n * @param {string} source The source to remove.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalRemoveAnnotationsBySource( source ) {\n\treturn {\n\t\ttype: 'ANNOTATION_REMOVE_SOURCE',\n\t\tsource,\n\t};\n}\n"]}
|
|
@@ -21,12 +21,9 @@ function filterWithReference(collection, predicate) {
|
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
const mapValues = (obj, callback) => Object.entries(obj).reduce((acc,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
[key]: callback(value)
|
|
28
|
-
};
|
|
29
|
-
}, {});
|
|
24
|
+
const mapValues = (obj, callback) => Object.entries(obj).reduce((acc, [key, value]) => ({ ...acc,
|
|
25
|
+
[key]: callback(value)
|
|
26
|
+
}), {});
|
|
30
27
|
/**
|
|
31
28
|
* Verifies whether the given annotations is a valid annotation.
|
|
32
29
|
*
|
|
@@ -48,12 +45,9 @@ function isValidAnnotationRange(annotation) {
|
|
|
48
45
|
*/
|
|
49
46
|
|
|
50
47
|
|
|
51
|
-
export function annotations() {
|
|
48
|
+
export function annotations(state = {}, action) {
|
|
52
49
|
var _state$blockClientId;
|
|
53
50
|
|
|
54
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
55
|
-
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
56
|
-
|
|
57
51
|
switch (action.type) {
|
|
58
52
|
case 'ANNOTATION_ADD':
|
|
59
53
|
const blockClientId = action.blockClientId;
|
|
@@ -70,7 +64,7 @@ export function annotations() {
|
|
|
70
64
|
return state;
|
|
71
65
|
}
|
|
72
66
|
|
|
73
|
-
const previousAnnotationsForBlock = (_state$blockClientId = state
|
|
67
|
+
const previousAnnotationsForBlock = (_state$blockClientId = state?.[blockClientId]) !== null && _state$blockClientId !== void 0 ? _state$blockClientId : [];
|
|
74
68
|
return { ...state,
|
|
75
69
|
[blockClientId]: [...previousAnnotationsForBlock, newAnnotation]
|
|
76
70
|
};
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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,EAAO,CAAEC,GAAF,EAAOC,KAAP,CAAP,MAA6B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,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;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"]}
|
|
@@ -25,18 +25,18 @@ const EMPTY_ARRAY = [];
|
|
|
25
25
|
export const __experimentalGetAnnotationsForBlock = createSelector((state, blockClientId) => {
|
|
26
26
|
var _state$blockClientId;
|
|
27
27
|
|
|
28
|
-
return ((_state$blockClientId = state
|
|
28
|
+
return ((_state$blockClientId = state?.[blockClientId]) !== null && _state$blockClientId !== void 0 ? _state$blockClientId : []).filter(annotation => {
|
|
29
29
|
return annotation.selector === 'block';
|
|
30
30
|
});
|
|
31
31
|
}, (state, blockClientId) => {
|
|
32
32
|
var _state$blockClientId2;
|
|
33
33
|
|
|
34
|
-
return [(_state$blockClientId2 = state
|
|
34
|
+
return [(_state$blockClientId2 = state?.[blockClientId]) !== null && _state$blockClientId2 !== void 0 ? _state$blockClientId2 : EMPTY_ARRAY];
|
|
35
35
|
});
|
|
36
36
|
export function __experimentalGetAllAnnotationsForBlock(state, blockClientId) {
|
|
37
37
|
var _state$blockClientId3;
|
|
38
38
|
|
|
39
|
-
return (_state$blockClientId3 = state
|
|
39
|
+
return (_state$blockClientId3 = state?.[blockClientId]) !== null && _state$blockClientId3 !== void 0 ? _state$blockClientId3 : EMPTY_ARRAY;
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* Returns the annotations that apply to the given RichText instance.
|
|
@@ -54,7 +54,7 @@ export function __experimentalGetAllAnnotationsForBlock(state, blockClientId) {
|
|
|
54
54
|
export const __experimentalGetAnnotationsForRichText = createSelector((state, blockClientId, richTextIdentifier) => {
|
|
55
55
|
var _state$blockClientId4;
|
|
56
56
|
|
|
57
|
-
return ((_state$blockClientId4 = state
|
|
57
|
+
return ((_state$blockClientId4 = state?.[blockClientId]) !== null && _state$blockClientId4 !== void 0 ? _state$blockClientId4 : []).filter(annotation => {
|
|
58
58
|
return annotation.selector === 'range' && richTextIdentifier === annotation.richTextIdentifier;
|
|
59
59
|
}).map(annotation => {
|
|
60
60
|
const {
|
|
@@ -68,7 +68,7 @@ export const __experimentalGetAnnotationsForRichText = createSelector((state, bl
|
|
|
68
68
|
}, (state, blockClientId) => {
|
|
69
69
|
var _state$blockClientId5;
|
|
70
70
|
|
|
71
|
-
return [(_state$blockClientId5 = state
|
|
71
|
+
return [(_state$blockClientId5 = state?.[blockClientId]) !== null && _state$blockClientId5 !== void 0 ? _state$blockClientId5 : EMPTY_ARRAY];
|
|
72
72
|
});
|
|
73
73
|
/**
|
|
74
74
|
* Returns all annotations in the editor state.
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,KAAK,GAAIC,aAAJ,CAAP,uEAA8B,EAA9B,EAAmCC,MAAnC,CAA6CC,UAAF,IAAkB;AACnE,WAAOA,UAAU,CAACC,QAAX,KAAwB,OAA/B;AACA,GAFM,CAAP;AAGA,CALgE,EAMjE,CAAEJ,KAAF,EAASC,aAAT;AAAA;;AAAA,SAA4B,0BAAED,KAAK,GAAIC,aAAJ,CAAP,yEAA8BH,WAA9B,CAA5B;AAAA,CANiE,CAA3D;AASP,OAAO,SAASO,uCAAT,CACNL,KADM,EAENC,aAFM,EAGL;AAAA;;AACD,kCAAOD,KAAK,GAAIC,aAAJ,CAAZ,yEAAmCH,WAAnC;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMQ,uCAAuC,GAAGT,cAAc,CACpE,CAAEG,KAAF,EAASC,aAAT,EAAwBM,kBAAxB,KAAgD;AAAA;;AAC/C,SAAO,0BAAEP,KAAK,GAAIC,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,CAjBmE,EAkBpE,CAAEV,KAAF,EAASC,aAAT;AAAA;;AAAA,SAA4B,0BAAED,KAAK,GAAIC,aAAJ,CAAP,yEAA8BH,WAA9B,CAA5B;AAAA,CAlBoE,CAA9D;AAqBP;AACA;AACA;AACA;AACA;AACA;;AACA,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.
|
|
3
|
+
"version": "2.35.1",
|
|
4
4
|
"description": "Annotate content in the Gutenberg editor.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -26,15 +26,15 @@
|
|
|
26
26
|
"react-native": "src/index",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@babel/runtime": "^7.16.0",
|
|
29
|
-
"@wordpress/data": "^9.
|
|
30
|
-
"@wordpress/hooks": "^3.
|
|
31
|
-
"@wordpress/i18n": "^4.
|
|
32
|
-
"@wordpress/rich-text": "^6.
|
|
29
|
+
"@wordpress/data": "^9.5.1",
|
|
30
|
+
"@wordpress/hooks": "^3.35.1",
|
|
31
|
+
"@wordpress/i18n": "^4.35.1",
|
|
32
|
+
"@wordpress/rich-text": "^6.12.1",
|
|
33
33
|
"rememo": "^4.0.2",
|
|
34
34
|
"uuid": "^8.3.0"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "ce5639111c30763dbdf07f40eeb136ea6030ecf1"
|
|
40
40
|
}
|