@wordpress/annotations 2.2.4 → 2.2.8-next.33ec3857e2.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/build/block/index.js +6 -4
- package/build/block/index.js.map +1 -1
- package/build/format/annotation.js +17 -13
- package/build/format/annotation.js.map +1 -1
- package/build/store/actions.js +10 -9
- package/build/store/actions.js.map +1 -1
- package/build/store/index.js +4 -2
- package/build/store/index.js.map +1 -1
- package/build/store/reducer.js +4 -1
- package/build/store/reducer.js.map +1 -1
- package/build-module/block/index.js +6 -4
- package/build-module/block/index.js.map +1 -1
- package/build-module/format/annotation.js +16 -12
- package/build-module/format/annotation.js.map +1 -1
- package/build-module/store/actions.js +9 -8
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +4 -1
- package/build-module/store/reducer.js.map +1 -1
- package/package.json +7 -7
package/build/block/index.js
CHANGED
|
@@ -21,10 +21,12 @@ var _constants = require("../store/constants");
|
|
|
21
21
|
* @return {Object} The enhanced component.
|
|
22
22
|
*/
|
|
23
23
|
const addAnnotationClassName = OriginalComponent => {
|
|
24
|
-
return (0, _data.withSelect)((select, {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
return (0, _data.withSelect)((select, _ref) => {
|
|
25
|
+
let {
|
|
26
|
+
clientId,
|
|
27
|
+
className
|
|
28
|
+
} = _ref;
|
|
29
|
+
|
|
28
30
|
const annotations = select(_constants.STORE_NAME).__experimentalGetAnnotationsForBlock(clientId);
|
|
29
31
|
|
|
30
32
|
return {
|
package/build/block/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/annotations/src/block/index.js"],"names":["addAnnotationClassName","OriginalComponent","select","clientId","className","annotations","STORE_NAME","__experimentalGetAnnotationsForBlock","map","annotation","source","concat","filter","Boolean","join"],"mappings":";;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,sBAAsB,GAAKC,iBAAF,IAAyB;AACvD,SAAO,sBAAY,CAAEC,MAAF,
|
|
1
|
+
{"version":3,"sources":["@wordpress/annotations/src/block/index.js"],"names":["addAnnotationClassName","OriginalComponent","select","clientId","className","annotations","STORE_NAME","__experimentalGetAnnotationsForBlock","map","annotation","source","concat","filter","Boolean","join"],"mappings":";;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,sBAAsB,GAAKC,iBAAF,IAAyB;AACvD,SAAO,sBAAY,CAAEC,MAAF,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"]}
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.annotation = void 0;
|
|
6
7
|
exports.applyAnnotations = applyAnnotations;
|
|
7
8
|
exports.removeAnnotations = removeAnnotations;
|
|
8
|
-
exports.annotation = void 0;
|
|
9
9
|
|
|
10
10
|
var _i18n = require("@wordpress/i18n");
|
|
11
11
|
|
|
@@ -29,7 +29,8 @@ const ANNOTATION_ATTRIBUTE_PREFIX = 'annotation-text-';
|
|
|
29
29
|
* @param {Array} annotations The annotation to apply.
|
|
30
30
|
* @return {Object} A record with the annotations applied.
|
|
31
31
|
*/
|
|
32
|
-
function applyAnnotations(record
|
|
32
|
+
function applyAnnotations(record) {
|
|
33
|
+
let annotations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
33
34
|
annotations.forEach(annotation => {
|
|
34
35
|
let {
|
|
35
36
|
start,
|
|
@@ -111,10 +112,11 @@ function retrieveAnnotationPositions(formats) {
|
|
|
111
112
|
*/
|
|
112
113
|
|
|
113
114
|
|
|
114
|
-
function updateAnnotationsWithPositions(annotations, positions, {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
function updateAnnotationsWithPositions(annotations, positions, _ref) {
|
|
116
|
+
let {
|
|
117
|
+
removeAnnotation,
|
|
118
|
+
updateAnnotationRange
|
|
119
|
+
} = _ref;
|
|
118
120
|
annotations.forEach(currentAnnotation => {
|
|
119
121
|
const position = positions[currentAnnotation.id]; // If we cannot find an annotation, delete it.
|
|
120
122
|
|
|
@@ -150,18 +152,20 @@ const annotation = {
|
|
|
150
152
|
return null;
|
|
151
153
|
},
|
|
152
154
|
|
|
153
|
-
__experimentalGetPropsForEditableTreePreparation(select, {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
__experimentalGetPropsForEditableTreePreparation(select, _ref2) {
|
|
156
|
+
let {
|
|
157
|
+
richTextIdentifier,
|
|
158
|
+
blockClientId
|
|
159
|
+
} = _ref2;
|
|
157
160
|
return {
|
|
158
161
|
annotations: select(_constants.STORE_NAME).__experimentalGetAnnotationsForRichText(blockClientId, richTextIdentifier)
|
|
159
162
|
};
|
|
160
163
|
},
|
|
161
164
|
|
|
162
|
-
__experimentalCreatePrepareEditableTree({
|
|
163
|
-
|
|
164
|
-
|
|
165
|
+
__experimentalCreatePrepareEditableTree(_ref3) {
|
|
166
|
+
let {
|
|
167
|
+
annotations
|
|
168
|
+
} = _ref3;
|
|
165
169
|
return (formats, text) => {
|
|
166
170
|
if (annotations.length === 0) {
|
|
167
171
|
return formats;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/annotations/src/format/annotation.js"],"names":["FORMAT_NAME","ANNOTATION_ATTRIBUTE_PREFIX","applyAnnotations","record","annotations","forEach","annotation","start","end","text","length","className","source","id","type","attributes","removeAnnotations","retrieveAnnotationPositions","formats","positions","characterFormats","i","filter","format","replace","hasOwnProperty","updateAnnotationsWithPositions","removeAnnotation","updateAnnotationRange","currentAnnotation","position","name","title","tagName","edit","__experimentalGetPropsForEditableTreePreparation","select","richTextIdentifier","blockClientId","STORE_NAME","__experimentalGetAnnotationsForRichText","__experimentalCreatePrepareEditableTree","__experimentalGetPropsForEditableTreeChangeHandler","dispatch","__experimentalRemoveAnnotation","__experimentalUpdateAnnotationRange","__experimentalCreateOnChangeEditableValue","props"],"mappings":";;;;;;;;;AAGA;;AACA;;AAQA;;AAZA;AACA;AACA;AAIA,MAA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AO;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,MAAM,CAACM,IAAP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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"]}
|
package/build/store/actions.js
CHANGED
|
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.__experimentalAddAnnotation = __experimentalAddAnnotation;
|
|
7
7
|
exports.__experimentalRemoveAnnotation = __experimentalRemoveAnnotation;
|
|
8
|
-
exports.__experimentalUpdateAnnotationRange = __experimentalUpdateAnnotationRange;
|
|
9
8
|
exports.__experimentalRemoveAnnotationsBySource = __experimentalRemoveAnnotationsBySource;
|
|
9
|
+
exports.__experimentalUpdateAnnotationRange = __experimentalUpdateAnnotationRange;
|
|
10
10
|
|
|
11
11
|
var _uuid = require("uuid");
|
|
12
12
|
|
|
@@ -41,14 +41,15 @@ var _uuid = require("uuid");
|
|
|
41
41
|
*
|
|
42
42
|
* @return {Object} Action object.
|
|
43
43
|
*/
|
|
44
|
-
function __experimentalAddAnnotation({
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
44
|
+
function __experimentalAddAnnotation(_ref) {
|
|
45
|
+
let {
|
|
46
|
+
blockClientId,
|
|
47
|
+
richTextIdentifier = null,
|
|
48
|
+
range = null,
|
|
49
|
+
selector = 'range',
|
|
50
|
+
source = 'default',
|
|
51
|
+
id = (0, _uuid.v4)()
|
|
52
|
+
} = _ref;
|
|
52
53
|
const action = {
|
|
53
54
|
type: 'ANNOTATION_ADD',
|
|
54
55
|
id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/annotations/src/store/actions.js"],"names":["__experimentalAddAnnotation","blockClientId","richTextIdentifier","range","selector","source","id","action","type","__experimentalRemoveAnnotation","annotationId","__experimentalUpdateAnnotationRange","start","end","__experimentalRemoveAnnotationsBySource"],"mappings":";;;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,2BAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/annotations/src/store/actions.js"],"names":["__experimentalAddAnnotation","blockClientId","richTextIdentifier","range","selector","source","id","action","type","__experimentalRemoveAnnotation","annotationId","__experimentalUpdateAnnotationRange","start","end","__experimentalRemoveAnnotationsBySource"],"mappings":";;;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,2BAAT,OAOH;AAAA,MAPyC;AAC5CC,IAAAA,aAD4C;AAE5CC,IAAAA,kBAAkB,GAAG,IAFuB;AAG5CC,IAAAA,KAAK,GAAG,IAHoC;AAI5CC,IAAAA,QAAQ,GAAG,OAJiC;AAK5CC,IAAAA,MAAM,GAAG,SALmC;AAM5CC,IAAAA,EAAE,GAAG;AANuC,GAOzC;AACH,QAAMC,MAAM,GAAG;AACdC,IAAAA,IAAI,EAAE,gBADQ;AAEdF,IAAAA,EAFc;AAGdL,IAAAA,aAHc;AAIdC,IAAAA,kBAJc;AAKdG,IAAAA,MALc;AAMdD,IAAAA;AANc,GAAf;;AASA,MAAKA,QAAQ,KAAK,OAAlB,EAA4B;AAC3BG,IAAAA,MAAM,CAACJ,KAAP,GAAeA,KAAf;AACA;;AAED,SAAOI,MAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,8BAAT,CAAyCC,YAAzC,EAAwD;AAC9D,SAAO;AACNF,IAAAA,IAAI,EAAE,mBADA;AAENE,IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,mCAAT,CACND,YADM,EAENE,KAFM,EAGNC,GAHM,EAIL;AACD,SAAO;AACNL,IAAAA,IAAI,EAAE,yBADA;AAENE,IAAAA,YAFM;AAGNE,IAAAA,KAHM;AAINC,IAAAA;AAJM,GAAP;AAMA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,uCAAT,CAAkDT,MAAlD,EAA2D;AACjE,SAAO;AACNG,IAAAA,IAAI,EAAE,0BADA;AAENH,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport { v4 as uuid } from 'uuid';\n\n/**\n * @typedef WPAnnotationRange\n *\n * @property {number} start The offset where the annotation should start.\n * @property {number} end The offset where the annotation should end.\n */\n\n/**\n * Adds an annotation to a block.\n *\n * The `block` attribute refers to a block ID that needs to be annotated.\n * `isBlockAnnotation` controls whether or not the annotation is a block\n * annotation. The `source` is the source of the annotation, this will be used\n * to identity groups of annotations.\n *\n * The `range` property is only relevant if the selector is 'range'.\n *\n * @param {Object} annotation The annotation to add.\n * @param {string} annotation.blockClientId The blockClientId to add the annotation to.\n * @param {string} annotation.richTextIdentifier Identifier for the RichText instance the annotation applies to.\n * @param {WPAnnotationRange} annotation.range The range at which to apply this annotation.\n * @param {string} [annotation.selector=\"range\"] The way to apply this annotation.\n * @param {string} [annotation.source=\"default\"] The source that added the annotation.\n * @param {string} [annotation.id] The ID the annotation should have. Generates a UUID by default.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalAddAnnotation( {\n\tblockClientId,\n\trichTextIdentifier = null,\n\trange = null,\n\tselector = 'range',\n\tsource = 'default',\n\tid = uuid(),\n} ) {\n\tconst action = {\n\t\ttype: 'ANNOTATION_ADD',\n\t\tid,\n\t\tblockClientId,\n\t\trichTextIdentifier,\n\t\tsource,\n\t\tselector,\n\t};\n\n\tif ( selector === 'range' ) {\n\t\taction.range = range;\n\t}\n\n\treturn action;\n}\n\n/**\n * Removes an annotation with a specific ID.\n *\n * @param {string} annotationId The annotation to remove.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalRemoveAnnotation( annotationId ) {\n\treturn {\n\t\ttype: 'ANNOTATION_REMOVE',\n\t\tannotationId,\n\t};\n}\n\n/**\n * Updates the range of an annotation.\n *\n * @param {string} annotationId ID of the annotation to update.\n * @param {number} start The start of the new range.\n * @param {number} end The end of the new range.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalUpdateAnnotationRange(\n\tannotationId,\n\tstart,\n\tend\n) {\n\treturn {\n\t\ttype: 'ANNOTATION_UPDATE_RANGE',\n\t\tannotationId,\n\t\tstart,\n\t\tend,\n\t};\n}\n\n/**\n * Removes all annotations of a specific source.\n *\n * @param {string} source The source to remove.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalRemoveAnnotationsBySource( source ) {\n\treturn {\n\t\ttype: 'ANNOTATION_REMOVE_SOURCE',\n\t\tsource,\n\t};\n}\n"]}
|
package/build/store/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|
4
|
-
|
|
5
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
6
4
|
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -19,6 +17,10 @@ var actions = _interopRequireWildcard(require("./actions"));
|
|
|
19
17
|
|
|
20
18
|
var _constants = require("./constants");
|
|
21
19
|
|
|
20
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
21
|
+
|
|
22
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
23
|
+
|
|
22
24
|
/**
|
|
23
25
|
* WordPress dependencies
|
|
24
26
|
*/
|
package/build/store/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/annotations/src/store/index.js"],"names":["store","STORE_NAME","reducer","selectors","actions"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["@wordpress/annotations/src/store/index.js"],"names":["store","STORE_NAME","reducer","selectors","actions"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AAKA;;;;;;AAfA;AACA;AACA;;AAGA;AACA;AACA;;AAKA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,KAAK,GAAG,4BAAkBC,qBAAlB,EAA8B;AAClDC,EAAAA,OAAO,EAAPA,gBADkD;AAElDC,EAAAA,SAFkD;AAGlDC,EAAAA;AAHkD,CAA9B,CAAd;;AAMP,oBAAUJ,KAAV","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { register, createReduxStore } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as actions from './actions';\n\n/**\n * Module Constants\n */\nimport { STORE_NAME } from './constants';\n\n/**\n * Store definition for the annotations namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n *\n * @type {Object}\n */\nexport const store = createReduxStore( STORE_NAME, {\n\treducer,\n\tselectors,\n\tactions,\n} );\n\nregister( store );\n"]}
|
package/build/store/reducer.js
CHANGED
|
@@ -46,9 +46,12 @@ function isValidAnnotationRange(annotation) {
|
|
|
46
46
|
*/
|
|
47
47
|
|
|
48
48
|
|
|
49
|
-
function annotations(
|
|
49
|
+
function annotations() {
|
|
50
50
|
var _state$blockClientId;
|
|
51
51
|
|
|
52
|
+
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
53
|
+
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
54
|
+
|
|
52
55
|
switch (action.type) {
|
|
53
56
|
case 'ANNOTATION_ADD':
|
|
54
57
|
const blockClientId = action.blockClientId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/annotations/src/store/reducer.js"],"names":["filterWithReference","collection","predicate","filteredCollection","filter","length","isValidAnnotationRange","annotation","start","end","annotations","state","action","type","blockClientId","newAnnotation","id","richTextIdentifier","source","selector","range","previousAnnotationsForBlock","annotationsForBlock","annotationId","hasChangedRange","newAnnotations","map"],"mappings":";;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,mBAAT,CAA8BC,UAA9B,EAA0CC,SAA1C,EAAsD;AACrD,QAAMC,kBAAkB,GAAGF,UAAU,CAACG,MAAX,CAAmBF,SAAnB,CAA3B;AAEA,SAAOD,UAAU,CAACI,MAAX,KAAsBF,kBAAkB,CAACE,MAAzC,GACJJ,UADI,GAEJE,kBAFH;AAGA;AAED;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASG,sBAAT,CAAiCC,UAAjC,EAA8C;AAC7C,SACC,sBAAUA,UAAU,CAACC,KAArB,KACA,sBAAUD,UAAU,CAACE,GAArB,CADA,IAEAF,UAAU,CAACC,KAAX,IAAoBD,UAAU,CAACE,GAHhC;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,WAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/annotations/src/store/reducer.js"],"names":["filterWithReference","collection","predicate","filteredCollection","filter","length","isValidAnnotationRange","annotation","start","end","annotations","state","action","type","blockClientId","newAnnotation","id","richTextIdentifier","source","selector","range","previousAnnotationsForBlock","annotationsForBlock","annotationId","hasChangedRange","newAnnotations","map"],"mappings":";;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,mBAAT,CAA8BC,UAA9B,EAA0CC,SAA1C,EAAsD;AACrD,QAAMC,kBAAkB,GAAGF,UAAU,CAACG,MAAX,CAAmBF,SAAnB,CAA3B;AAEA,SAAOD,UAAU,CAACI,MAAX,KAAsBF,kBAAkB,CAACE,MAAzC,GACJJ,UADI,GAEJE,k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AACW,YAAhC;AACA,SAJwB,CAA1B;AAMA,OAPM,CAAP;;AASD,SAAK,yBAAL;AACC,aAAO,uBAAWZ,KAAX,EAAoBW,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,OArBM,CAAP;;AAuBD,SAAK,0BAAL;AACC,aAAO,uBAAWX,KAAX,EAAoBW,mBAAF,IAA2B;AACnD,eAAOtB,mBAAmB,CACzBsB,mBADyB,EAEvBf,UAAF,IAAkB;AACjB,iBAAOA,UAAU,CAACW,MAAX,KAAsBN,MAAM,CAACM,MAApC;AACA,SAJwB,CAA1B;AAMA,OAPM,CAAP;AAhEF;;AA0EA,SAAOP,KAAP;AACA;;eAEcD,W","sourcesContent":["/**\n * External dependencies\n */\nimport { isNumber, mapValues } from 'lodash';\n\n/**\n * Filters an array based on the predicate, but keeps the reference the same if\n * the array hasn't changed.\n *\n * @param {Array} collection The collection to filter.\n * @param {Function} predicate Function that determines if the item should stay\n * in the array.\n * @return {Array} Filtered array.\n */\nfunction filterWithReference( collection, predicate ) {\n\tconst filteredCollection = collection.filter( predicate );\n\n\treturn collection.length === filteredCollection.length\n\t\t? collection\n\t\t: filteredCollection;\n}\n\n/**\n * Verifies whether the given annotations is a valid annotation.\n *\n * @param {Object} annotation The annotation to verify.\n * @return {boolean} Whether the given annotation is valid.\n */\nfunction isValidAnnotationRange( annotation ) {\n\treturn (\n\t\tisNumber( annotation.start ) &&\n\t\tisNumber( annotation.end ) &&\n\t\tannotation.start <= annotation.end\n\t);\n}\n\n/**\n * Reducer managing annotations.\n *\n * @param {Object} state The annotations currently shown in the editor.\n * @param {Object} action Dispatched action.\n *\n * @return {Array} Updated state.\n */\nexport function annotations( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'ANNOTATION_ADD':\n\t\t\tconst blockClientId = action.blockClientId;\n\t\t\tconst newAnnotation = {\n\t\t\t\tid: action.id,\n\t\t\t\tblockClientId,\n\t\t\t\trichTextIdentifier: action.richTextIdentifier,\n\t\t\t\tsource: action.source,\n\t\t\t\tselector: action.selector,\n\t\t\t\trange: action.range,\n\t\t\t};\n\n\t\t\tif (\n\t\t\t\tnewAnnotation.selector === 'range' &&\n\t\t\t\t! isValidAnnotationRange( newAnnotation.range )\n\t\t\t) {\n\t\t\t\treturn state;\n\t\t\t}\n\n\t\t\tconst previousAnnotationsForBlock = state?.[ blockClientId ] ?? [];\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ blockClientId ]: [\n\t\t\t\t\t...previousAnnotationsForBlock,\n\t\t\t\t\tnewAnnotation,\n\t\t\t\t],\n\t\t\t};\n\n\t\tcase 'ANNOTATION_REMOVE':\n\t\t\treturn mapValues( state, ( annotationsForBlock ) => {\n\t\t\t\treturn filterWithReference(\n\t\t\t\t\tannotationsForBlock,\n\t\t\t\t\t( annotation ) => {\n\t\t\t\t\t\treturn annotation.id !== action.annotationId;\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} );\n\n\t\tcase 'ANNOTATION_UPDATE_RANGE':\n\t\t\treturn mapValues( state, ( annotationsForBlock ) => {\n\t\t\t\tlet hasChangedRange = false;\n\n\t\t\t\tconst newAnnotations = annotationsForBlock.map(\n\t\t\t\t\t( annotation ) => {\n\t\t\t\t\t\tif ( annotation.id === action.annotationId ) {\n\t\t\t\t\t\t\thasChangedRange = true;\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t...annotation,\n\t\t\t\t\t\t\t\trange: {\n\t\t\t\t\t\t\t\t\tstart: action.start,\n\t\t\t\t\t\t\t\t\tend: action.end,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn annotation;\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\treturn hasChangedRange ? newAnnotations : annotationsForBlock;\n\t\t\t} );\n\n\t\tcase 'ANNOTATION_REMOVE_SOURCE':\n\t\t\treturn mapValues( state, ( annotationsForBlock ) => {\n\t\t\t\treturn filterWithReference(\n\t\t\t\t\tannotationsForBlock,\n\t\t\t\t\t( annotation ) => {\n\t\t\t\t\t\treturn annotation.source !== action.source;\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} );\n\t}\n\n\treturn state;\n}\n\nexport default annotations;\n"]}
|
|
@@ -16,10 +16,12 @@ import { STORE_NAME } from '../store/constants';
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
const addAnnotationClassName = OriginalComponent => {
|
|
19
|
-
return withSelect((select, {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
return withSelect((select, _ref) => {
|
|
20
|
+
let {
|
|
21
|
+
clientId,
|
|
22
|
+
className
|
|
23
|
+
} = _ref;
|
|
24
|
+
|
|
23
25
|
const annotations = select(STORE_NAME).__experimentalGetAnnotationsForBlock(clientId);
|
|
24
26
|
|
|
25
27
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/annotations/src/block/index.js"],"names":["addFilter","withSelect","STORE_NAME","addAnnotationClassName","OriginalComponent","select","clientId","className","annotations","__experimentalGetAnnotationsForBlock","map","annotation","source","concat","filter","Boolean","join"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,kBAA1B;AACA,SAASC,UAAT,QAA2B,iBAA3B;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,oBAA3B;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,sBAAsB,GAAKC,iBAAF,IAAyB;AACvD,SAAOH,UAAU,CAAE,CAAEI,MAAF,
|
|
1
|
+
{"version":3,"sources":["@wordpress/annotations/src/block/index.js"],"names":["addFilter","withSelect","STORE_NAME","addAnnotationClassName","OriginalComponent","select","clientId","className","annotations","__experimentalGetAnnotationsForBlock","map","annotation","source","concat","filter","Boolean","join"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,kBAA1B;AACA,SAASC,UAAT,QAA2B,iBAA3B;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,oBAA3B;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,sBAAsB,GAAKC,iBAAF,IAAyB;AACvD,SAAOH,UAAU,CAAE,CAAEI,MAAF,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"]}
|
|
@@ -18,7 +18,8 @@ import { STORE_NAME } from '../store/constants';
|
|
|
18
18
|
* @return {Object} A record with the annotations applied.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
export function applyAnnotations(record
|
|
21
|
+
export function applyAnnotations(record) {
|
|
22
|
+
let annotations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
22
23
|
annotations.forEach(annotation => {
|
|
23
24
|
let {
|
|
24
25
|
start,
|
|
@@ -98,10 +99,11 @@ function retrieveAnnotationPositions(formats) {
|
|
|
98
99
|
*/
|
|
99
100
|
|
|
100
101
|
|
|
101
|
-
function updateAnnotationsWithPositions(annotations, positions, {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
function updateAnnotationsWithPositions(annotations, positions, _ref) {
|
|
103
|
+
let {
|
|
104
|
+
removeAnnotation,
|
|
105
|
+
updateAnnotationRange
|
|
106
|
+
} = _ref;
|
|
105
107
|
annotations.forEach(currentAnnotation => {
|
|
106
108
|
const position = positions[currentAnnotation.id]; // If we cannot find an annotation, delete it.
|
|
107
109
|
|
|
@@ -137,18 +139,20 @@ export const annotation = {
|
|
|
137
139
|
return null;
|
|
138
140
|
},
|
|
139
141
|
|
|
140
|
-
__experimentalGetPropsForEditableTreePreparation(select, {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
__experimentalGetPropsForEditableTreePreparation(select, _ref2) {
|
|
143
|
+
let {
|
|
144
|
+
richTextIdentifier,
|
|
145
|
+
blockClientId
|
|
146
|
+
} = _ref2;
|
|
144
147
|
return {
|
|
145
148
|
annotations: select(STORE_NAME).__experimentalGetAnnotationsForRichText(blockClientId, richTextIdentifier)
|
|
146
149
|
};
|
|
147
150
|
},
|
|
148
151
|
|
|
149
|
-
__experimentalCreatePrepareEditableTree({
|
|
150
|
-
|
|
151
|
-
|
|
152
|
+
__experimentalCreatePrepareEditableTree(_ref3) {
|
|
153
|
+
let {
|
|
154
|
+
annotations
|
|
155
|
+
} = _ref3;
|
|
152
156
|
return (formats, text) => {
|
|
153
157
|
if (annotations.length === 0) {
|
|
154
158
|
return formats;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/annotations/src/format/annotation.js"],"names":["__","applyFormat","removeFormat","FORMAT_NAME","ANNOTATION_ATTRIBUTE_PREFIX","STORE_NAME","applyAnnotations","record","annotations","forEach","annotation","start","end","text","length","className","source","id","type","attributes","removeAnnotations","retrieveAnnotationPositions","formats","positions","characterFormats","i","filter","format","replace","hasOwnProperty","updateAnnotationsWithPositions","removeAnnotation","updateAnnotationRange","currentAnnotation","position","name","title","tagName","edit","__experimentalGetPropsForEditableTreePreparation","select","richTextIdentifier","blockClientId","__experimentalGetAnnotationsForRichText","__experimentalCreatePrepareEditableTree","__experimentalGetPropsForEditableTreeChangeHandler","dispatch","__experimentalRemoveAnnotation","__experimentalUpdateAnnotationRange","__experimentalCreateOnChangeEditableValue","props"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,WAAT,EAAsBC,YAAtB,QAA0C,sBAA1C;AAEA,MAAMC,WAAW,GAAG,iBAApB;AAEA,MAAMC,2BAA2B,GAAG,kBAApC;AACA;AAC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a;AAC9D,WAAO;AACNf,MAAAA,gBAAgB,EAAEe,QAAQ,CAAEzC,UAAF,CAAR,CAChB0C,8BAFI;AAGNf,MAAAA,qBAAqB,EAAEc,QAAQ,CAAEzC,UAAF,CAAR,CACrB2C;AAJI,KAAP;AAMA,GA3CwB;;AA4CzBC,EAAAA,yCAAyC,CAAEC,KAAF,EAAU;AAClD,WAAS5B,OAAF,IAAe;AACrB,YAAMC,SAAS,GAAGF,2BAA2B,CAAEC,OAAF,CAA7C;AACA,YAAM;AACLS,QAAAA,gBADK;AAELC,QAAAA,qBAFK;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;A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JJ;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"]}
|
|
@@ -30,14 +30,15 @@ import { v4 as uuid } from 'uuid';
|
|
|
30
30
|
* @return {Object} Action object.
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
|
-
export function __experimentalAddAnnotation({
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
export function __experimentalAddAnnotation(_ref) {
|
|
34
|
+
let {
|
|
35
|
+
blockClientId,
|
|
36
|
+
richTextIdentifier = null,
|
|
37
|
+
range = null,
|
|
38
|
+
selector = 'range',
|
|
39
|
+
source = 'default',
|
|
40
|
+
id = uuid()
|
|
41
|
+
} = _ref;
|
|
41
42
|
const action = {
|
|
42
43
|
type: 'ANNOTATION_ADD',
|
|
43
44
|
id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/annotations/src/store/actions.js"],"names":["v4","uuid","__experimentalAddAnnotation","blockClientId","richTextIdentifier","range","selector","source","id","action","type","__experimentalRemoveAnnotation","annotationId","__experimentalUpdateAnnotationRange","start","end","__experimentalRemoveAnnotationsBySource"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,IAAIC,IAAf,QAA2B,MAA3B;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,2BAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/annotations/src/store/actions.js"],"names":["v4","uuid","__experimentalAddAnnotation","blockClientId","richTextIdentifier","range","selector","source","id","action","type","__experimentalRemoveAnnotation","annotationId","__experimentalUpdateAnnotationRange","start","end","__experimentalRemoveAnnotationsBySource"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,IAAIC,IAAf,QAA2B,MAA3B;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,2BAAT,OAOH;AAAA,MAPyC;AAC5CC,IAAAA,aAD4C;AAE5CC,IAAAA,kBAAkB,GAAG,IAFuB;AAG5CC,IAAAA,KAAK,GAAG,IAHoC;AAI5CC,IAAAA,QAAQ,GAAG,OAJiC;AAK5CC,IAAAA,MAAM,GAAG,SALmC;AAM5CC,IAAAA,EAAE,GAAGP,IAAI;AANmC,GAOzC;AACH,QAAMQ,MAAM,GAAG;AACdC,IAAAA,IAAI,EAAE,gBADQ;AAEdF,IAAAA,EAFc;AAGdL,IAAAA,aAHc;AAIdC,IAAAA,kBAJc;AAKdG,IAAAA,MALc;AAMdD,IAAAA;AANc,GAAf;;AASA,MAAKA,QAAQ,KAAK,OAAlB,EAA4B;AAC3BG,IAAAA,MAAM,CAACJ,KAAP,GAAeA,KAAf;AACA;;AAED,SAAOI,MAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,8BAAT,CAAyCC,YAAzC,EAAwD;AAC9D,SAAO;AACNF,IAAAA,IAAI,EAAE,mBADA;AAENE,IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,mCAAT,CACND,YADM,EAENE,KAFM,EAGNC,GAHM,EAIL;AACD,SAAO;AACNL,IAAAA,IAAI,EAAE,yBADA;AAENE,IAAAA,YAFM;AAGNE,IAAAA,KAHM;AAINC,IAAAA;AAJM,GAAP;AAMA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,uCAAT,CAAkDT,MAAlD,EAA2D;AACjE,SAAO;AACNG,IAAAA,IAAI,EAAE,0BADA;AAENH,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport { v4 as uuid } from 'uuid';\n\n/**\n * @typedef WPAnnotationRange\n *\n * @property {number} start The offset where the annotation should start.\n * @property {number} end The offset where the annotation should end.\n */\n\n/**\n * Adds an annotation to a block.\n *\n * The `block` attribute refers to a block ID that needs to be annotated.\n * `isBlockAnnotation` controls whether or not the annotation is a block\n * annotation. The `source` is the source of the annotation, this will be used\n * to identity groups of annotations.\n *\n * The `range` property is only relevant if the selector is 'range'.\n *\n * @param {Object} annotation The annotation to add.\n * @param {string} annotation.blockClientId The blockClientId to add the annotation to.\n * @param {string} annotation.richTextIdentifier Identifier for the RichText instance the annotation applies to.\n * @param {WPAnnotationRange} annotation.range The range at which to apply this annotation.\n * @param {string} [annotation.selector=\"range\"] The way to apply this annotation.\n * @param {string} [annotation.source=\"default\"] The source that added the annotation.\n * @param {string} [annotation.id] The ID the annotation should have. Generates a UUID by default.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalAddAnnotation( {\n\tblockClientId,\n\trichTextIdentifier = null,\n\trange = null,\n\tselector = 'range',\n\tsource = 'default',\n\tid = uuid(),\n} ) {\n\tconst action = {\n\t\ttype: 'ANNOTATION_ADD',\n\t\tid,\n\t\tblockClientId,\n\t\trichTextIdentifier,\n\t\tsource,\n\t\tselector,\n\t};\n\n\tif ( selector === 'range' ) {\n\t\taction.range = range;\n\t}\n\n\treturn action;\n}\n\n/**\n * Removes an annotation with a specific ID.\n *\n * @param {string} annotationId The annotation to remove.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalRemoveAnnotation( annotationId ) {\n\treturn {\n\t\ttype: 'ANNOTATION_REMOVE',\n\t\tannotationId,\n\t};\n}\n\n/**\n * Updates the range of an annotation.\n *\n * @param {string} annotationId ID of the annotation to update.\n * @param {number} start The start of the new range.\n * @param {number} end The end of the new range.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalUpdateAnnotationRange(\n\tannotationId,\n\tstart,\n\tend\n) {\n\treturn {\n\t\ttype: 'ANNOTATION_UPDATE_RANGE',\n\t\tannotationId,\n\t\tstart,\n\t\tend,\n\t};\n}\n\n/**\n * Removes all annotations of a specific source.\n *\n * @param {string} source The source to remove.\n *\n * @return {Object} Action object.\n */\nexport function __experimentalRemoveAnnotationsBySource( source ) {\n\treturn {\n\t\ttype: 'ANNOTATION_REMOVE_SOURCE',\n\t\tsource,\n\t};\n}\n"]}
|
|
@@ -37,9 +37,12 @@ function isValidAnnotationRange(annotation) {
|
|
|
37
37
|
*/
|
|
38
38
|
|
|
39
39
|
|
|
40
|
-
export function annotations(
|
|
40
|
+
export function annotations() {
|
|
41
41
|
var _state$blockClientId;
|
|
42
42
|
|
|
43
|
+
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
44
|
+
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
45
|
+
|
|
43
46
|
switch (action.type) {
|
|
44
47
|
case 'ANNOTATION_ADD':
|
|
45
48
|
const blockClientId = action.blockClientId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/annotations/src/store/reducer.js"],"names":["isNumber","mapValues","filterWithReference","collection","predicate","filteredCollection","filter","length","isValidAnnotationRange","annotation","start","end","annotations","state","action","type","blockClientId","newAnnotation","id","richTextIdentifier","source","selector","range","previousAnnotationsForBlock","annotationsForBlock","annotationId","hasChangedRange","newAnnotations","map"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,QAAT,EAAmBC,SAAnB,QAAoC,QAApC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,mBAAT,CAA8BC,UAA9B,EAA0CC,SAA1C,EAAsD;AACrD,QAAMC,kBAAkB,GAAGF,UAAU,CAACG,MAAX,CAAmBF,SAAnB,CAA3B;AAEA,SAAOD,UAAU,CAACI,MAAX,KAAsBF,kBAAkB,CAACE,MAAzC,GACJJ,UADI,GAEJE,kBAFH;AAGA;AAED;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASG,sBAAT,CAAiCC,UAAjC,EAA8C;AAC7C,SACCT,QAAQ,CAAES,UAAU,CAACC,KAAb,CAAR,IACAV,QAAQ,CAAES,UAAU,CAACE,GAAb,CADR,IAEAF,UAAU,CAACC,KAAX,IAAoBD,UAAU,CAACE,GAHhC;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,OAAO,SAASC,WAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/annotations/src/store/reducer.js"],"names":["isNumber","mapValues","filterWithReference","collection","predicate","filteredCollection","filter","length","isValidAnnotationRange","annotation","start","end","annotations","state","action","type","blockClientId","newAnnotation","id","richTextIdentifier","source","selector","range","previousAnnotationsForBlock","annotationsForBlock","annotationId","hasChangedRange","newAnnotations","map"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,QAAT,EAAmBC,SAAnB,QAAoC,QAApC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,mBAAT,CAA8BC,UAA9B,EAA0CC,SAA1C,EAAsD;AACrD,QAAMC,kBAAkB,GAAGF,UAAU,CAACG,MAAX,CAAmBF,SAAnB,CAA3B;AAEA,SAAOD,UAAU,CAACI,MAAX,KAAsBF,kBAAkB,CAACE,MAAzC,GACJJ,UADI,GAEJE,kBAFH;AAGA;AAED;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASG,sBAAT,CAAiCC,UAAjC,EAA8C;AAC7C,SACCT,QAAQ,CAAES,UAAU,CAACC,KAAb,CAAR,IACAV,QAAQ,CAAES,UAAU,CAACE,GAAb,CADR,IAEAF,UAAU,CAACC,KAAX,IAAoBD,UAAU,CAACE,GAHhC;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,OAAO,SAASC,WAAT,GAA2C;AAAA;;AAAA,MAArBC,KAAqB,uEAAb,EAAa;AAAA,MAATC,MAAS;;AACjD,UAASA,MAAM,CAACC,IAAhB;AACC,SAAK,gBAAL;AACC,YAAMC,aAAa,GAAGF,MAAM,CAACE,aAA7B;AACA,YAAMC,aAAa,GAAG;AACrBC,QAAAA,EAAE,EAAEJ,MAAM,CAACI,EADU;AAErBF,QAAAA,aAFqB;AAGrBG,QAAAA,kBAAkB,EAAEL,MAAM,CAACK,kBAHN;AAIrBC,QAAAA,MAAM,EAAEN,MAAM,CAACM,MAJM;AAKrBC,QAAAA,QAAQ,EAAEP,MAAM,CAACO,QALI;AAMrBC,QAAAA,KAAK,EAAER,MAAM,CAACQ;AANO,OAAtB;;AASA,UACCL,aAAa,C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ACjB,iBAAOA,UAAU,CAACW,MAAX,KAAsBN,MAAM,CAACM,MAApC;AACA,SAJwB,CAA1B;AAMA,OAPe,CAAhB;AAhEF;;AA0EA,SAAOP,KAAP;AACA;AAED,eAAeD,WAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { isNumber, mapValues } from 'lodash';\n\n/**\n * Filters an array based on the predicate, but keeps the reference the same if\n * the array hasn't changed.\n *\n * @param {Array} collection The collection to filter.\n * @param {Function} predicate Function that determines if the item should stay\n * in the array.\n * @return {Array} Filtered array.\n */\nfunction filterWithReference( collection, predicate ) {\n\tconst filteredCollection = collection.filter( predicate );\n\n\treturn collection.length === filteredCollection.length\n\t\t? collection\n\t\t: filteredCollection;\n}\n\n/**\n * Verifies whether the given annotations is a valid annotation.\n *\n * @param {Object} annotation The annotation to verify.\n * @return {boolean} Whether the given annotation is valid.\n */\nfunction isValidAnnotationRange( annotation ) {\n\treturn (\n\t\tisNumber( annotation.start ) &&\n\t\tisNumber( annotation.end ) &&\n\t\tannotation.start <= annotation.end\n\t);\n}\n\n/**\n * Reducer managing annotations.\n *\n * @param {Object} state The annotations currently shown in the editor.\n * @param {Object} action Dispatched action.\n *\n * @return {Array} Updated state.\n */\nexport function annotations( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'ANNOTATION_ADD':\n\t\t\tconst blockClientId = action.blockClientId;\n\t\t\tconst newAnnotation = {\n\t\t\t\tid: action.id,\n\t\t\t\tblockClientId,\n\t\t\t\trichTextIdentifier: action.richTextIdentifier,\n\t\t\t\tsource: action.source,\n\t\t\t\tselector: action.selector,\n\t\t\t\trange: action.range,\n\t\t\t};\n\n\t\t\tif (\n\t\t\t\tnewAnnotation.selector === 'range' &&\n\t\t\t\t! isValidAnnotationRange( newAnnotation.range )\n\t\t\t) {\n\t\t\t\treturn state;\n\t\t\t}\n\n\t\t\tconst previousAnnotationsForBlock = state?.[ blockClientId ] ?? [];\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ blockClientId ]: [\n\t\t\t\t\t...previousAnnotationsForBlock,\n\t\t\t\t\tnewAnnotation,\n\t\t\t\t],\n\t\t\t};\n\n\t\tcase 'ANNOTATION_REMOVE':\n\t\t\treturn mapValues( state, ( annotationsForBlock ) => {\n\t\t\t\treturn filterWithReference(\n\t\t\t\t\tannotationsForBlock,\n\t\t\t\t\t( annotation ) => {\n\t\t\t\t\t\treturn annotation.id !== action.annotationId;\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} );\n\n\t\tcase 'ANNOTATION_UPDATE_RANGE':\n\t\t\treturn mapValues( state, ( annotationsForBlock ) => {\n\t\t\t\tlet hasChangedRange = false;\n\n\t\t\t\tconst newAnnotations = annotationsForBlock.map(\n\t\t\t\t\t( annotation ) => {\n\t\t\t\t\t\tif ( annotation.id === action.annotationId ) {\n\t\t\t\t\t\t\thasChangedRange = true;\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t...annotation,\n\t\t\t\t\t\t\t\trange: {\n\t\t\t\t\t\t\t\t\tstart: action.start,\n\t\t\t\t\t\t\t\t\tend: action.end,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn annotation;\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\treturn hasChangedRange ? newAnnotations : annotationsForBlock;\n\t\t\t} );\n\n\t\tcase 'ANNOTATION_REMOVE_SOURCE':\n\t\t\treturn mapValues( state, ( annotationsForBlock ) => {\n\t\t\t\treturn filterWithReference(\n\t\t\t\t\tannotationsForBlock,\n\t\t\t\t\t( annotation ) => {\n\t\t\t\t\t\treturn annotation.source !== action.source;\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} );\n\t}\n\n\treturn state;\n}\n\nexport default annotations;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/annotations",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.8-next.33ec3857e2.0",
|
|
4
4
|
"description": "Annotate content in the Gutenberg editor.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
"module": "build-module/index.js",
|
|
26
26
|
"react-native": "src/index",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@babel/runtime": "^7.
|
|
29
|
-
"@wordpress/data": "^6.1.
|
|
30
|
-
"@wordpress/hooks": "^3.2.
|
|
31
|
-
"@wordpress/i18n": "^4.2.
|
|
32
|
-
"@wordpress/rich-text": "^5.0.
|
|
28
|
+
"@babel/runtime": "^7.16.0",
|
|
29
|
+
"@wordpress/data": "^6.1.6-next.33ec3857e2.0",
|
|
30
|
+
"@wordpress/hooks": "^3.2.3-next.33ec3857e2.0",
|
|
31
|
+
"@wordpress/i18n": "^4.2.5-next.33ec3857e2.0",
|
|
32
|
+
"@wordpress/rich-text": "^5.0.7-next.33ec3857e2.0",
|
|
33
33
|
"lodash": "^4.17.21",
|
|
34
34
|
"rememo": "^3.0.0",
|
|
35
35
|
"uuid": "^8.3.0"
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "51c7917ea7fac72953702f24d6daac87d99e7617"
|
|
41
41
|
}
|