@wordpress/annotations 2.9.0 → 2.12.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 +6 -0
- package/build/block/index.js.map +1 -1
- package/build/format/annotation.js.map +1 -1
- package/build/store/reducer.js +20 -10
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +1 -5
- package/build/store/selectors.js.map +1 -1
- package/build-module/block/index.js.map +1 -1
- package/build-module/format/annotation.js.map +1 -1
- package/build-module/store/reducer.js +17 -6
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +1 -4
- package/build-module/store/selectors.js.map +1 -1
- package/package.json +7 -8
- package/src/block/index.js +4 -3
- package/src/format/annotation.js +6 -9
- package/src/store/reducer.js +19 -7
- package/src/store/selectors.js +1 -4
package/CHANGELOG.md
CHANGED
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,WAAuC;AAAA,QAA7B;AAAEC,MAAAA,QAAF;AAAYC,MAAAA;AAAZ,KAA6B;;AACzD,UAAMC,WAAW,
|
|
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,WAAuC;AAAA,QAA7B;AAAEC,MAAAA,QAAF;AAAYC,MAAAA;AAAZ,KAA6B;;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"]}
|
|
@@ -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,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,EA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C,uCAFW,CAGZF,aAHY,EAIZD,kBAJY;AADP,KAAP;AAQA,GAxBwB;;AAyBzBI,EAAAA,uCAAuC,QAAoB;AAAA,QAAlB;AAAErC,MAAAA;AAAF,KAAkB;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,EAAEgB,QAAQ,CAAEJ,qBAAF,CAAR,CAChBK,8BAFI;AAGNhB,MAAAA,qBAAqB,EAAEe,QAAQ,CAAEJ,qBAAF,CAAR,CACrBM;AAJI,KAAP;AAMA,GA3CwB;;AA4CzBC,EAAAA,yCAAyC,CAAEC,KAAF,EAAU;AAClD,WAAS7B,OAAF,IAAe;AACrB,YAAMC,SAAS,GAAGF,2BAA2B,CAAEC,OAAF,CAA7C;AACA,YAAM;AACLS,QAAAA,gBADK;AAELC,QAAAA,qBAFK;AAGLxB,QAAAA;AAHK,UAIF2C,KAJJ;AAMArB,MAAAA,8BAA8B,CAAEtB,WAAF,EAAee,SAAf,EAA0B;AACvDQ,QAAAA,gBADuD;AAEvDC,QAAAA;AAFuD,OAA1B,CAA9B;AAIA,KAZD;AAaA;;AA1DwB,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: dispatch( STORE_NAME )\n\t\t\t\t.__experimentalRemoveAnnotation,\n\t\t\tupdateAnnotationRange: dispatch( STORE_NAME )\n\t\t\t\t.__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 {\n\t\t\t\tremoveAnnotation,\n\t\t\t\tupdateAnnotationRange,\n\t\t\t\tannotations,\n\t\t\t} = props;\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,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A,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/reducer.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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":";;;;;;;;
|
|
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;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AAOzB,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
|
@@ -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 (
|
|
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","
|
|
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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AeA,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 +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,WAAuC;AAAA,QAA7B;AAAEC,MAAAA,QAAF;AAAYC,MAAAA;AAAZ,KAA6B;;AACzD,UAAMC,WAAW,
|
|
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,WAAuC;AAAA,QAA7B;AAAEC,MAAAA,QAAF;AAAYC,MAAAA;AAAZ,KAA6B;;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"]}
|
|
@@ -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;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,EAAsD;AAAA,MAAnBC,WAAmB,uEAAL,EAAK;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,GAAG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CAAEtB,WAAF,EAAee,SAAf,EAA0B;AACvDQ,QAAAA,gBADuD;AAEvDC,QAAAA;AAFuD,OAA1B,CAA9B;AAIA,KAZD;AAaA;;AA1DwB,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: dispatch( STORE_NAME )\n\t\t\t\t.__experimentalRemoveAnnotation,\n\t\t\tupdateAnnotationRange: dispatch( STORE_NAME )\n\t\t\t\t.__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 {\n\t\t\t\tremoveAnnotation,\n\t\t\t\tupdateAnnotationRange,\n\t\t\t\tannotations,\n\t\t\t} = props;\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,EAAsD;AAAA,MAAnBC,WAAmB,uEAAL,EAAK;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,GAAGX,2BAA2B,GAAGM,UAAU,CAACM,MAA3D;AACA,UAAMC,EAAE,GAAGb,2BAA2B,GAAGM,UAAU,CAACO,EAApD;AAEAV,IAAAA,MAAM,GAAGN,WAAW,CACnBM,MADmB,EAEnB;AACCW,MAAAA,IAAI,EAAEf,WADP;AAECgB,MAAAA,UAAU,EAAE;AACXJ,QAAAA,SADW;AAEXE,QAAAA;AAFW;AAFb,KAFm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AAuC,QAAoB;AAAA,QAAlB;AAAEpC,MAAAA;AAAF,KAAkB;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;;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,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
|
|
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":["
|
|
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,M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QD,SAAK,mBAAL;AACC,aAAOlB,SAAS,CAAEc,KAAF,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;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
|
|
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","
|
|
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,KAAK,CAAIC,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,KAAF,aAAEA,KAAF,uBAAEA,KAAK,CAAIC,aAAJ,CAAP,yEAA8BH,WAA9B,CAA5B;AAAA,CANiE,CAA3D;AASP,OAAO,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;;AACA,OAAO,MAAMQ,uCAAuC,GAAGT,cAAc,CACpE,CAAEG,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,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,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.12.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,12 +26,11 @@
|
|
|
26
26
|
"react-native": "src/index",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@babel/runtime": "^7.16.0",
|
|
29
|
-
"@wordpress/data": "^6.
|
|
30
|
-
"@wordpress/hooks": "^3.
|
|
31
|
-
"@wordpress/i18n": "^4.
|
|
32
|
-
"@wordpress/rich-text": "^5.
|
|
33
|
-
"
|
|
34
|
-
"rememo": "^3.0.0",
|
|
29
|
+
"@wordpress/data": "^6.12.0",
|
|
30
|
+
"@wordpress/hooks": "^3.12.0",
|
|
31
|
+
"@wordpress/i18n": "^4.12.0",
|
|
32
|
+
"@wordpress/rich-text": "^5.10.0",
|
|
33
|
+
"rememo": "^4.0.0",
|
|
35
34
|
"uuid": "^8.3.0"
|
|
36
35
|
},
|
|
37
36
|
"peerDependencies": {
|
|
@@ -40,5 +39,5 @@
|
|
|
40
39
|
"publishConfig": {
|
|
41
40
|
"access": "public"
|
|
42
41
|
},
|
|
43
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "a80eeb62ec7cb1418b9915c277e084a29d6665e3"
|
|
44
43
|
}
|
package/src/block/index.js
CHANGED
|
@@ -16,9 +16,10 @@ import { STORE_NAME } from '../store/constants';
|
|
|
16
16
|
*/
|
|
17
17
|
const addAnnotationClassName = ( OriginalComponent ) => {
|
|
18
18
|
return withSelect( ( select, { clientId, className } ) => {
|
|
19
|
-
const annotations =
|
|
20
|
-
STORE_NAME
|
|
21
|
-
|
|
19
|
+
const annotations =
|
|
20
|
+
select( STORE_NAME ).__experimentalGetAnnotationsForBlock(
|
|
21
|
+
clientId
|
|
22
|
+
);
|
|
22
23
|
|
|
23
24
|
return {
|
|
24
25
|
className: annotations
|
package/src/format/annotation.js
CHANGED
|
@@ -168,20 +168,17 @@ export const annotation = {
|
|
|
168
168
|
},
|
|
169
169
|
__experimentalGetPropsForEditableTreeChangeHandler( dispatch ) {
|
|
170
170
|
return {
|
|
171
|
-
removeAnnotation:
|
|
172
|
-
.__experimentalRemoveAnnotation,
|
|
173
|
-
updateAnnotationRange:
|
|
174
|
-
.__experimentalUpdateAnnotationRange,
|
|
171
|
+
removeAnnotation:
|
|
172
|
+
dispatch( STORE_NAME ).__experimentalRemoveAnnotation,
|
|
173
|
+
updateAnnotationRange:
|
|
174
|
+
dispatch( STORE_NAME ).__experimentalUpdateAnnotationRange,
|
|
175
175
|
};
|
|
176
176
|
},
|
|
177
177
|
__experimentalCreateOnChangeEditableValue( props ) {
|
|
178
178
|
return ( formats ) => {
|
|
179
179
|
const positions = retrieveAnnotationPositions( formats );
|
|
180
|
-
const {
|
|
181
|
-
|
|
182
|
-
updateAnnotationRange,
|
|
183
|
-
annotations,
|
|
184
|
-
} = props;
|
|
180
|
+
const { removeAnnotation, updateAnnotationRange, annotations } =
|
|
181
|
+
props;
|
|
185
182
|
|
|
186
183
|
updateAnnotationsWithPositions( annotations, positions, {
|
|
187
184
|
removeAnnotation,
|
package/src/store/reducer.js
CHANGED
|
@@ -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
|
-
|
|
32
|
-
|
|
43
|
+
typeof annotation.start === 'number' &&
|
|
44
|
+
typeof annotation.end === 'number' &&
|
|
33
45
|
annotation.start <= annotation.end
|
|
34
46
|
);
|
|
35
47
|
}
|
package/src/store/selectors.js
CHANGED
|
@@ -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
|
|
83
|
-
return annotations;
|
|
84
|
-
} );
|
|
81
|
+
return Object.values( state ).flat();
|
|
85
82
|
}
|