@wordpress/annotations 2.8.0 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 2.11.0 (2022-06-15)
6
+
7
+ ## 2.10.0 (2022-06-01)
8
+
9
+ ## 2.9.0 (2022-05-18)
10
+
5
11
  ## 2.8.0 (2022-05-04)
6
12
 
7
13
  ## 2.7.0 (2022-04-21)
@@ -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,GAAGH,MAAM,CACzBI,qBADyB,CAAN,CAElBC,oCAFkB,CAEoBJ,QAFpB,CAApB;;AAIA,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,GAdM,EAcFb,iBAdE,CAAP;AAeA,CAhBD;;AAkBA,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 = select(\n\t\t\tSTORE_NAME\n\t\t).__experimentalGetAnnotationsForBlock( clientId );\n\n\t\treturn {\n\t\t\tclassName: annotations\n\t\t\t\t.map( ( annotation ) => {\n\t\t\t\t\treturn 'is-annotated-by-' + annotation.source;\n\t\t\t\t} )\n\t\t\t\t.concat( className )\n\t\t\t\t.filter( Boolean )\n\t\t\t\t.join( ' ' ),\n\t\t};\n\t} )( OriginalComponent );\n};\n\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/annotations',\n\taddAnnotationClassName\n);\n"]}
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,M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,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,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,M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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 +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,GAAGH,MAAM,CACzBH,UADyB,CAAN,CAElBO,oCAFkB,CAEoBH,QAFpB,CAApB;;AAIA,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,GAdgB,CAAV,CAcFZ,iBAdE,CAAP;AAeA,CAhBD;;AAkBAJ,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 = select(\n\t\t\tSTORE_NAME\n\t\t).__experimentalGetAnnotationsForBlock( clientId );\n\n\t\treturn {\n\t\t\tclassName: annotations\n\t\t\t\t.map( ( annotation ) => {\n\t\t\t\t\treturn 'is-annotated-by-' + annotation.source;\n\t\t\t\t} )\n\t\t\t\t.concat( className )\n\t\t\t\t.filter( Boolean )\n\t\t\t\t.join( ' ' ),\n\t\t};\n\t} )( OriginalComponent );\n};\n\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/annotations',\n\taddAnnotationClassName\n);\n"]}
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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K;AAGLxB,QAAAA;AAHK,UAIF0C,KAJJ;AAMApB,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":["__","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,E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D,kBAJY;AADP,KAAP;AAQA,GAxBwB;;AAyBzBG,EAAAA,uCAAuC,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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/annotations",
3
- "version": "2.8.0",
3
+ "version": "2.11.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,12 @@
26
26
  "react-native": "src/index",
27
27
  "dependencies": {
28
28
  "@babel/runtime": "^7.16.0",
29
- "@wordpress/data": "^6.8.0",
30
- "@wordpress/hooks": "^3.8.0",
31
- "@wordpress/i18n": "^4.8.0",
32
- "@wordpress/rich-text": "^5.6.0",
29
+ "@wordpress/data": "^6.11.0",
30
+ "@wordpress/hooks": "^3.11.0",
31
+ "@wordpress/i18n": "^4.11.0",
32
+ "@wordpress/rich-text": "^5.9.0",
33
33
  "lodash": "^4.17.21",
34
- "rememo": "^3.0.0",
34
+ "rememo": "^4.0.0",
35
35
  "uuid": "^8.3.0"
36
36
  },
37
37
  "peerDependencies": {
@@ -40,5 +40,5 @@
40
40
  "publishConfig": {
41
41
  "access": "public"
42
42
  },
43
- "gitHead": "4631d515033397fcfeda77e5755960253caef9bf"
43
+ "gitHead": "48d5f37dfb52d2e77c8eeb662f9874cf141b8c6b"
44
44
  }
@@ -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 = select(
20
- STORE_NAME
21
- ).__experimentalGetAnnotationsForBlock( clientId );
19
+ const annotations =
20
+ select( STORE_NAME ).__experimentalGetAnnotationsForBlock(
21
+ clientId
22
+ );
22
23
 
23
24
  return {
24
25
  className: annotations
@@ -168,20 +168,17 @@ export const annotation = {
168
168
  },
169
169
  __experimentalGetPropsForEditableTreeChangeHandler( dispatch ) {
170
170
  return {
171
- removeAnnotation: dispatch( STORE_NAME )
172
- .__experimentalRemoveAnnotation,
173
- updateAnnotationRange: dispatch( STORE_NAME )
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
- removeAnnotation,
182
- updateAnnotationRange,
183
- annotations,
184
- } = props;
180
+ const { removeAnnotation, updateAnnotationRange, annotations } =
181
+ props;
185
182
 
186
183
  updateAnnotationsWithPositions( annotations, positions, {
187
184
  removeAnnotation,