@wordpress/annotations 3.34.0 → 3.34.1-next.2f1c7c01b.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 +2 -1
- package/build/block/index.js.map +1 -1
- package/build/format/annotation.js +5 -3
- package/build/format/annotation.js.map +1 -1
- package/build/format/index.js +2 -1
- package/build/format/index.js.map +1 -1
- package/build/index.js +2 -0
- package/build/index.js.map +1 -1
- package/build/store/actions.js +2 -0
- package/build/store/actions.js.map +1 -1
- package/build/store/constants.js +3 -1
- package/build/store/constants.js.map +1 -1
- package/build/store/index.js +3 -1
- package/build/store/index.js.map +1 -1
- package/build/store/reducer.js +3 -1
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +5 -3
- package/build/store/selectors.js.map +1 -1
- package/build-module/block/index.js +2 -1
- package/build-module/block/index.js.map +1 -1
- package/build-module/format/annotation.js +4 -3
- package/build-module/format/annotation.js.map +1 -1
- package/build-module/format/index.js +2 -1
- package/build-module/format/index.js.map +1 -1
- package/build-module/index.js +1 -0
- package/build-module/index.js.map +1 -1
- package/build-module/store/actions.js +1 -0
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/constants.js +2 -1
- package/build-module/store/constants.js.map +1 -1
- package/build-module/store/index.js +2 -1
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/reducer.js +2 -1
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +4 -3
- package/build-module/store/selectors.js.map +1 -1
- package/package.json +6 -6
package/build/block/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
// packages/annotations/src/block/index.js
|
|
1
2
|
var import_hooks = require("@wordpress/hooks");
|
|
2
3
|
var import_data = require("@wordpress/data");
|
|
3
4
|
var import_constants = require("../store/constants");
|
|
4
|
-
|
|
5
|
+
var addAnnotationClassName = (OriginalComponent) => {
|
|
5
6
|
return (0, import_data.withSelect)((select, { clientId, className }) => {
|
|
6
7
|
const annotations = select(import_constants.STORE_NAME).__experimentalGetAnnotationsForBlock(
|
|
7
8
|
clientId
|
package/build/block/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/block/index.js"],
|
|
4
4
|
"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"],
|
|
5
|
-
"mappings": "AAGA,mBAA0B;AAC1B,kBAA2B;AAK3B,uBAA2B;AAO3B,
|
|
5
|
+
"mappings": ";AAGA,mBAA0B;AAC1B,kBAA2B;AAK3B,uBAA2B;AAO3B,IAAM,yBAAyB,CAAE,sBAAuB;AACvD,aAAO,wBAAY,CAAE,QAAQ,EAAE,UAAU,UAAU,MAAO;AACzD,UAAM,cACL,OAAQ,2BAAW,EAAE;AAAA,MACpB;AAAA,IACD;AAED,WAAO;AAAA,MACN,WAAW,YACT,IAAK,CAAE,eAAgB;AACvB,eAAO,qBAAqB,WAAW;AAAA,MACxC,CAAE,EACD,OAAQ,SAAU,EAClB,OAAQ,OAAQ,EAChB,KAAM,GAAI;AAAA,IACb;AAAA,EACD,CAAE,EAAG,iBAAkB;AACxB;AAAA,IAEA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -15,6 +15,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
return to;
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// packages/annotations/src/format/annotation.js
|
|
18
20
|
var annotation_exports = {};
|
|
19
21
|
__export(annotation_exports, {
|
|
20
22
|
annotation: () => annotation,
|
|
@@ -25,8 +27,8 @@ module.exports = __toCommonJS(annotation_exports);
|
|
|
25
27
|
var import_i18n = require("@wordpress/i18n");
|
|
26
28
|
var import_rich_text = require("@wordpress/rich-text");
|
|
27
29
|
var import_constants = require("../store/constants");
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
var FORMAT_NAME = "core/annotation";
|
|
31
|
+
var ANNOTATION_ATTRIBUTE_PREFIX = "annotation-text-";
|
|
30
32
|
function applyAnnotations(record, annotations = []) {
|
|
31
33
|
annotations.forEach((annotation2) => {
|
|
32
34
|
let { start, end } = annotation2;
|
|
@@ -93,7 +95,7 @@ function updateAnnotationsWithPositions(annotations, positions, { removeAnnotati
|
|
|
93
95
|
}
|
|
94
96
|
});
|
|
95
97
|
}
|
|
96
|
-
|
|
98
|
+
var annotation = {
|
|
97
99
|
name: FORMAT_NAME,
|
|
98
100
|
title: (0, import_i18n.__)("Annotation"),
|
|
99
101
|
tagName: "mark",
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/format/annotation.js"],
|
|
4
4
|
"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"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": ["annotation"]
|
|
7
7
|
}
|
package/build/format/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
// packages/annotations/src/format/index.js
|
|
1
2
|
var import_rich_text = require("@wordpress/rich-text");
|
|
2
3
|
var import_annotation = require("./annotation");
|
|
3
|
-
|
|
4
|
+
var { name, ...settings } = import_annotation.annotation;
|
|
4
5
|
(0, import_rich_text.registerFormatType)(name, settings);
|
|
5
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/format/index.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { registerFormatType } from '@wordpress/rich-text';\n\n/**\n * Internal dependencies\n */\nimport { annotation } from './annotation';\n\nconst { name, ...settings } = annotation;\n\nregisterFormatType( name, settings );\n"],
|
|
5
|
-
"mappings": "AAGA,uBAAmC;AAKnC,wBAA2B;AAE3B,
|
|
5
|
+
"mappings": ";AAGA,uBAAmC;AAKnC,wBAA2B;AAE3B,IAAM,EAAE,MAAM,GAAG,SAAS,IAAI;AAAA,IAE9B,qCAAoB,MAAM,QAAS;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/index.js
CHANGED
|
@@ -15,6 +15,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
return to;
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// packages/annotations/src/index.js
|
|
18
20
|
var index_exports = {};
|
|
19
21
|
__export(index_exports, {
|
|
20
22
|
store: () => import_store.store
|
package/build/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport './format';\nimport './block';\n\nexport { store } from './store';\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAO;AACP,mBAAO;AAEP,mBAAsB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/store/actions.js
CHANGED
|
@@ -15,6 +15,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
return to;
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// packages/annotations/src/store/actions.js
|
|
18
20
|
var actions_exports = {};
|
|
19
21
|
__export(actions_exports, {
|
|
20
22
|
__experimentalAddAnnotation: () => __experimentalAddAnnotation,
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/store/actions.js"],
|
|
4
4
|
"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"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA2B;AA6BpB,SAAS,4BAA6B;AAAA,EAC5C;AAAA,EACA,qBAAqB;AAAA,EACrB,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,SAAS;AAAA,EACT,SAAK,YAAAA,IAAK;AACX,GAAI;AACH,QAAM,SAAS;AAAA,IACd,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAEA,MAAK,aAAa,SAAU;AAC3B,WAAO,QAAQ;AAAA,EAChB;AAEA,SAAO;AACR;AASO,SAAS,+BAAgC,cAAe;AAC9D,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,EACD;AACD;AAWO,SAAS,oCACf,cACA,OACA,KACC;AACD,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AASO,SAAS,wCAAyC,QAAS;AACjE,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,EACD;AACD;",
|
|
6
6
|
"names": ["uuid"]
|
|
7
7
|
}
|
package/build/store/constants.js
CHANGED
|
@@ -15,12 +15,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
return to;
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// packages/annotations/src/store/constants.js
|
|
18
20
|
var constants_exports = {};
|
|
19
21
|
__export(constants_exports, {
|
|
20
22
|
STORE_NAME: () => STORE_NAME
|
|
21
23
|
});
|
|
22
24
|
module.exports = __toCommonJS(constants_exports);
|
|
23
|
-
|
|
25
|
+
var STORE_NAME = "core/annotations";
|
|
24
26
|
// Annotate the CommonJS export names for ESM import in node:
|
|
25
27
|
0 && (module.exports = {
|
|
26
28
|
STORE_NAME
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/store/constants.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * The identifier for the data store.\n *\n * @type {string}\n */\nexport const STORE_NAME = 'core/annotations';\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,IAAM,aAAa;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/store/index.js
CHANGED
|
@@ -25,6 +25,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
mod
|
|
26
26
|
));
|
|
27
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// packages/annotations/src/store/index.js
|
|
28
30
|
var store_exports = {};
|
|
29
31
|
__export(store_exports, {
|
|
30
32
|
store: () => store
|
|
@@ -35,7 +37,7 @@ var import_reducer = __toESM(require("./reducer"));
|
|
|
35
37
|
var selectors = __toESM(require("./selectors"));
|
|
36
38
|
var actions = __toESM(require("./actions"));
|
|
37
39
|
var import_constants = require("./constants");
|
|
38
|
-
|
|
40
|
+
var store = (0, import_data.createReduxStore)(import_constants.STORE_NAME, {
|
|
39
41
|
reducer: import_reducer.default,
|
|
40
42
|
selectors,
|
|
41
43
|
actions
|
package/build/store/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/store/index.js"],
|
|
4
4
|
"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"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA2C;AAK3C,qBAAoB;AACpB,gBAA2B;AAC3B,cAAyB;AAKzB,uBAA2B;AASpB,IAAM,YAAQ,8BAAkB,6BAAY;AAAA,EAClD,wBAAAA;AAAA,EACA;AAAA,EACA;AACD,CAAE;AAAA,IAEF,sBAAU,KAAM;",
|
|
6
6
|
"names": ["reducer"]
|
|
7
7
|
}
|
package/build/store/reducer.js
CHANGED
|
@@ -15,6 +15,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
return to;
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// packages/annotations/src/store/reducer.js
|
|
18
20
|
var reducer_exports = {};
|
|
19
21
|
__export(reducer_exports, {
|
|
20
22
|
annotations: () => annotations,
|
|
@@ -25,7 +27,7 @@ function filterWithReference(collection, predicate) {
|
|
|
25
27
|
const filteredCollection = collection.filter(predicate);
|
|
26
28
|
return collection.length === filteredCollection.length ? collection : filteredCollection;
|
|
27
29
|
}
|
|
28
|
-
|
|
30
|
+
var mapValues = (obj, callback) => Object.entries(obj).reduce(
|
|
29
31
|
(acc, [key, value]) => ({
|
|
30
32
|
...acc,
|
|
31
33
|
[key]: callback(value)
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/store/reducer.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * Filters an array based on the predicate, but keeps the reference the same if\n * the array hasn't changed.\n *\n * @param {Array} collection The collection to filter.\n * @param {Function} predicate Function that determines if the item should stay\n * in the array.\n * @return {Array} Filtered array.\n */\nfunction filterWithReference( collection, predicate ) {\n\tconst filteredCollection = collection.filter( predicate );\n\n\treturn collection.length === filteredCollection.length\n\t\t? collection\n\t\t: filteredCollection;\n}\n\n/**\n * Creates a new object with the same keys, but with `callback()` called as\n * a transformer function on each of the values.\n *\n * @param {Object} obj The object to transform.\n * @param {Function} callback The function to transform each object value.\n * @return {Array} Transformed object.\n */\nconst mapValues = ( obj, callback ) =>\n\tObject.entries( obj ).reduce(\n\t\t( acc, [ key, value ] ) => ( {\n\t\t\t...acc,\n\t\t\t[ key ]: callback( value ),\n\t\t} ),\n\t\t{}\n\t);\n\n/**\n * Verifies whether the given annotations is a valid annotation.\n *\n * @param {Object} annotation The annotation to verify.\n * @return {boolean} Whether the given annotation is valid.\n */\nfunction isValidAnnotationRange( annotation ) {\n\treturn (\n\t\ttypeof annotation.start === 'number' &&\n\t\ttypeof annotation.end === 'number' &&\n\t\tannotation.start <= annotation.end\n\t);\n}\n\n/**\n * Reducer managing annotations.\n *\n * @param {Object} state The annotations currently shown in the editor.\n * @param {Object} action Dispatched action.\n *\n * @return {Array} Updated state.\n */\nexport function annotations( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'ANNOTATION_ADD':\n\t\t\tconst blockClientId = action.blockClientId;\n\t\t\tconst newAnnotation = {\n\t\t\t\tid: action.id,\n\t\t\t\tblockClientId,\n\t\t\t\trichTextIdentifier: action.richTextIdentifier,\n\t\t\t\tsource: action.source,\n\t\t\t\tselector: action.selector,\n\t\t\t\trange: action.range,\n\t\t\t};\n\n\t\t\tif (\n\t\t\t\tnewAnnotation.selector === 'range' &&\n\t\t\t\t! isValidAnnotationRange( newAnnotation.range )\n\t\t\t) {\n\t\t\t\treturn state;\n\t\t\t}\n\n\t\t\tconst previousAnnotationsForBlock = state?.[ blockClientId ] ?? [];\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ blockClientId ]: [\n\t\t\t\t\t...previousAnnotationsForBlock,\n\t\t\t\t\tnewAnnotation,\n\t\t\t\t],\n\t\t\t};\n\n\t\tcase 'ANNOTATION_REMOVE':\n\t\t\treturn mapValues( state, ( annotationsForBlock ) => {\n\t\t\t\treturn filterWithReference(\n\t\t\t\t\tannotationsForBlock,\n\t\t\t\t\t( annotation ) => {\n\t\t\t\t\t\treturn annotation.id !== action.annotationId;\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} );\n\n\t\tcase 'ANNOTATION_UPDATE_RANGE':\n\t\t\treturn mapValues( state, ( annotationsForBlock ) => {\n\t\t\t\tlet hasChangedRange = false;\n\n\t\t\t\tconst newAnnotations = annotationsForBlock.map(\n\t\t\t\t\t( annotation ) => {\n\t\t\t\t\t\tif ( annotation.id === action.annotationId ) {\n\t\t\t\t\t\t\thasChangedRange = true;\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t...annotation,\n\t\t\t\t\t\t\t\trange: {\n\t\t\t\t\t\t\t\t\tstart: action.start,\n\t\t\t\t\t\t\t\t\tend: action.end,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn annotation;\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\treturn hasChangedRange ? newAnnotations : annotationsForBlock;\n\t\t\t} );\n\n\t\tcase 'ANNOTATION_REMOVE_SOURCE':\n\t\t\treturn mapValues( state, ( annotationsForBlock ) => {\n\t\t\t\treturn filterWithReference(\n\t\t\t\t\tannotationsForBlock,\n\t\t\t\t\t( annotation ) => {\n\t\t\t\t\t\treturn annotation.source !== action.source;\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} );\n\t}\n\n\treturn state;\n}\n\nexport default annotations;\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,SAAS,oBAAqB,YAAY,WAAY;AACrD,QAAM,qBAAqB,WAAW,OAAQ,SAAU;AAExD,SAAO,WAAW,WAAW,mBAAmB,SAC7C,aACA;AACJ;AAUA,IAAM,YAAY,CAAE,KAAK,aACxB,OAAO,QAAS,GAAI,EAAE;AAAA,EACrB,CAAE,KAAK,CAAE,KAAK,KAAM,OAAS;AAAA,IAC5B,GAAG;AAAA,IACH,CAAE,GAAI,GAAG,SAAU,KAAM;AAAA,EAC1B;AAAA,EACA,CAAC;AACF;AAQD,SAAS,uBAAwB,YAAa;AAC7C,SACC,OAAO,WAAW,UAAU,YAC5B,OAAO,WAAW,QAAQ,YAC1B,WAAW,SAAS,WAAW;AAEjC;AAUO,SAAS,YAAa,QAAQ,CAAC,GAAG,QAAS;AACjD,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK;AACJ,YAAM,gBAAgB,OAAO;AAC7B,YAAM,gBAAgB;AAAA,QACrB,IAAI,OAAO;AAAA,QACX;AAAA,QACA,oBAAoB,OAAO;AAAA,QAC3B,QAAQ,OAAO;AAAA,QACf,UAAU,OAAO;AAAA,QACjB,OAAO,OAAO;AAAA,MACf;AAEA,UACC,cAAc,aAAa,WAC3B,CAAE,uBAAwB,cAAc,KAAM,GAC7C;AACD,eAAO;AAAA,MACR;AAEA,YAAM,8BAA8B,QAAS,aAAc,KAAK,CAAC;AAEjE,aAAO;AAAA,QACN,GAAG;AAAA,QACH,CAAE,aAAc,GAAG;AAAA,UAClB,GAAG;AAAA,UACH;AAAA,QACD;AAAA,MACD;AAAA,IAED,KAAK;AACJ,aAAO,UAAW,OAAO,CAAE,wBAAyB;AACnD,eAAO;AAAA,UACN;AAAA,UACA,CAAE,eAAgB;AACjB,mBAAO,WAAW,OAAO,OAAO;AAAA,UACjC;AAAA,QACD;AAAA,MACD,CAAE;AAAA,IAEH,KAAK;AACJ,aAAO,UAAW,OAAO,CAAE,wBAAyB;AACnD,YAAI,kBAAkB;AAEtB,cAAM,iBAAiB,oBAAoB;AAAA,UAC1C,CAAE,eAAgB;AACjB,gBAAK,WAAW,OAAO,OAAO,cAAe;AAC5C,gCAAkB;AAClB,qBAAO;AAAA,gBACN,GAAG;AAAA,gBACH,OAAO;AAAA,kBACN,OAAO,OAAO;AAAA,kBACd,KAAK,OAAO;AAAA,gBACb;AAAA,cACD;AAAA,YACD;AAEA,mBAAO;AAAA,UACR;AAAA,QACD;AAEA,eAAO,kBAAkB,iBAAiB;AAAA,MAC3C,CAAE;AAAA,IAEH,KAAK;AACJ,aAAO,UAAW,OAAO,CAAE,wBAAyB;AACnD,eAAO;AAAA,UACN;AAAA,UACA,CAAE,eAAgB;AACjB,mBAAO,WAAW,WAAW,OAAO;AAAA,UACrC;AAAA,QACD;AAAA,MACD,CAAE;AAAA,EACJ;AAEA,SAAO;AACR;AAEA,IAAO,kBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/store/selectors.js
CHANGED
|
@@ -15,6 +15,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
return to;
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// packages/annotations/src/store/selectors.js
|
|
18
20
|
var selectors_exports = {};
|
|
19
21
|
__export(selectors_exports, {
|
|
20
22
|
__experimentalGetAllAnnotationsForBlock: () => __experimentalGetAllAnnotationsForBlock,
|
|
@@ -24,8 +26,8 @@ __export(selectors_exports, {
|
|
|
24
26
|
});
|
|
25
27
|
module.exports = __toCommonJS(selectors_exports);
|
|
26
28
|
var import_data = require("@wordpress/data");
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
var EMPTY_ARRAY = [];
|
|
30
|
+
var __experimentalGetAnnotationsForBlock = (0, import_data.createSelector)(
|
|
29
31
|
(state, blockClientId) => {
|
|
30
32
|
return (state?.[blockClientId] ?? []).filter((annotation) => {
|
|
31
33
|
return annotation.selector === "block";
|
|
@@ -36,7 +38,7 @@ const __experimentalGetAnnotationsForBlock = (0, import_data.createSelector)(
|
|
|
36
38
|
function __experimentalGetAllAnnotationsForBlock(state, blockClientId) {
|
|
37
39
|
return state?.[blockClientId] ?? EMPTY_ARRAY;
|
|
38
40
|
}
|
|
39
|
-
|
|
41
|
+
var __experimentalGetAnnotationsForRichText = (0, import_data.createSelector)(
|
|
40
42
|
(state, blockClientId, richTextIdentifier) => {
|
|
41
43
|
return (state?.[blockClientId] ?? []).filter((annotation) => {
|
|
42
44
|
return annotation.selector === "range" && richTextIdentifier === annotation.richTextIdentifier;
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/store/selectors.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createSelector } from '@wordpress/data';\n\n/**\n * Shared reference to an empty array for cases where it is important to avoid\n * returning a new array reference on every invocation, as in a connected or\n * other pure component which performs `shouldComponentUpdate` check on props.\n * This should be used as a last resort, since the normalized data should be\n * maintained by the reducer result in state.\n *\n * @type {Array}\n */\nconst EMPTY_ARRAY = [];\n\n/**\n * Returns the annotations for a specific client ID.\n *\n * @param {Object} state Editor state.\n * @param {string} clientId The ID of the block to get the annotations for.\n *\n * @return {Array} The annotations applicable to this block.\n */\nexport const __experimentalGetAnnotationsForBlock = createSelector(\n\t( state, blockClientId ) => {\n\t\treturn ( state?.[ blockClientId ] ?? [] ).filter( ( annotation ) => {\n\t\t\treturn annotation.selector === 'block';\n\t\t} );\n\t},\n\t( state, blockClientId ) => [ state?.[ blockClientId ] ?? EMPTY_ARRAY ]\n);\n\nexport function __experimentalGetAllAnnotationsForBlock(\n\tstate,\n\tblockClientId\n) {\n\treturn state?.[ blockClientId ] ?? EMPTY_ARRAY;\n}\n\n/**\n * Returns the annotations that apply to the given RichText instance.\n *\n * Both a blockClientId and a richTextIdentifier are required. This is because\n * a block might have multiple `RichText` components. This does mean that every\n * block needs to implement annotations itself.\n *\n * @param {Object} state Editor state.\n * @param {string} blockClientId The client ID for the block.\n * @param {string} richTextIdentifier Unique identifier that identifies the given RichText.\n * @return {Array} All the annotations relevant for the `RichText`.\n */\nexport const __experimentalGetAnnotationsForRichText = createSelector(\n\t( state, blockClientId, richTextIdentifier ) => {\n\t\treturn ( state?.[ blockClientId ] ?? [] )\n\t\t\t.filter( ( annotation ) => {\n\t\t\t\treturn (\n\t\t\t\t\tannotation.selector === 'range' &&\n\t\t\t\t\trichTextIdentifier === annotation.richTextIdentifier\n\t\t\t\t);\n\t\t\t} )\n\t\t\t.map( ( annotation ) => {\n\t\t\t\tconst { range, ...other } = annotation;\n\n\t\t\t\treturn {\n\t\t\t\t\t...range,\n\t\t\t\t\t...other,\n\t\t\t\t};\n\t\t\t} );\n\t},\n\t( state, blockClientId ) => [ state?.[ blockClientId ] ?? EMPTY_ARRAY ]\n);\n\n/**\n * Returns all annotations in the editor state.\n *\n * @param {Object} state Editor state.\n * @return {Array} All annotations currently applied.\n */\nexport function __experimentalGetAnnotations( state ) {\n\treturn Object.values( state ).flat();\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA+B;AAW/B,IAAM,cAAc,CAAC;AAUd,IAAM,2CAAuC;AAAA,EACnD,CAAE,OAAO,kBAAmB;AAC3B,YAAS,QAAS,aAAc,KAAK,CAAC,GAAI,OAAQ,CAAE,eAAgB;AACnE,aAAO,WAAW,aAAa;AAAA,IAChC,CAAE;AAAA,EACH;AAAA,EACA,CAAE,OAAO,kBAAmB,CAAE,QAAS,aAAc,KAAK,WAAY;AACvE;AAEO,SAAS,wCACf,OACA,eACC;AACD,SAAO,QAAS,aAAc,KAAK;AACpC;AAcO,IAAM,8CAA0C;AAAA,EACtD,CAAE,OAAO,eAAe,uBAAwB;AAC/C,YAAS,QAAS,aAAc,KAAK,CAAC,GACpC,OAAQ,CAAE,eAAgB;AAC1B,aACC,WAAW,aAAa,WACxB,uBAAuB,WAAW;AAAA,IAEpC,CAAE,EACD,IAAK,CAAE,eAAgB;AACvB,YAAM,EAAE,OAAO,GAAG,MAAM,IAAI;AAE5B,aAAO;AAAA,QACN,GAAG;AAAA,QACH,GAAG;AAAA,MACJ;AAAA,IACD,CAAE;AAAA,EACJ;AAAA,EACA,CAAE,OAAO,kBAAmB,CAAE,QAAS,aAAc,KAAK,WAAY;AACvE;AAQO,SAAS,6BAA8B,OAAQ;AACrD,SAAO,OAAO,OAAQ,KAAM,EAAE,KAAK;AACpC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
// packages/annotations/src/block/index.js
|
|
1
2
|
import { addFilter } from "@wordpress/hooks";
|
|
2
3
|
import { withSelect } from "@wordpress/data";
|
|
3
4
|
import { STORE_NAME } from "../store/constants";
|
|
4
|
-
|
|
5
|
+
var addAnnotationClassName = (OriginalComponent) => {
|
|
5
6
|
return withSelect((select, { clientId, className }) => {
|
|
6
7
|
const annotations = select(STORE_NAME).__experimentalGetAnnotationsForBlock(
|
|
7
8
|
clientId
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/block/index.js"],
|
|
4
4
|
"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"],
|
|
5
|
-
"mappings": "AAGA,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAK3B,SAAS,kBAAkB;AAO3B,
|
|
5
|
+
"mappings": ";AAGA,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAK3B,SAAS,kBAAkB;AAO3B,IAAM,yBAAyB,CAAE,sBAAuB;AACvD,SAAO,WAAY,CAAE,QAAQ,EAAE,UAAU,UAAU,MAAO;AACzD,UAAM,cACL,OAAQ,UAAW,EAAE;AAAA,MACpB;AAAA,IACD;AAED,WAAO;AAAA,MACN,WAAW,YACT,IAAK,CAAE,eAAgB;AACvB,eAAO,qBAAqB,WAAW;AAAA,MACxC,CAAE,EACD,OAAQ,SAAU,EAClB,OAAQ,OAAQ,EAChB,KAAM,GAAI;AAAA,IACb;AAAA,EACD,CAAE,EAAG,iBAAkB;AACxB;AAEA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
// packages/annotations/src/format/annotation.js
|
|
1
2
|
import { __ } from "@wordpress/i18n";
|
|
2
3
|
import { applyFormat, removeFormat } from "@wordpress/rich-text";
|
|
3
|
-
const FORMAT_NAME = "core/annotation";
|
|
4
|
-
const ANNOTATION_ATTRIBUTE_PREFIX = "annotation-text-";
|
|
5
4
|
import { STORE_NAME } from "../store/constants";
|
|
5
|
+
var FORMAT_NAME = "core/annotation";
|
|
6
|
+
var ANNOTATION_ATTRIBUTE_PREFIX = "annotation-text-";
|
|
6
7
|
function applyAnnotations(record, annotations = []) {
|
|
7
8
|
annotations.forEach((annotation2) => {
|
|
8
9
|
let { start, end } = annotation2;
|
|
@@ -69,7 +70,7 @@ function updateAnnotationsWithPositions(annotations, positions, { removeAnnotati
|
|
|
69
70
|
}
|
|
70
71
|
});
|
|
71
72
|
}
|
|
72
|
-
|
|
73
|
+
var annotation = {
|
|
73
74
|
name: FORMAT_NAME,
|
|
74
75
|
title: __("Annotation"),
|
|
75
76
|
tagName: "mark",
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/format/annotation.js"],
|
|
4
4
|
"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"],
|
|
5
|
-
"mappings": "AAGA,SAAS,UAAU;AACnB,SAAS,aAAa,oBAAoB;
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": ["annotation"]
|
|
7
7
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
// packages/annotations/src/format/index.js
|
|
1
2
|
import { registerFormatType } from "@wordpress/rich-text";
|
|
2
3
|
import { annotation } from "./annotation";
|
|
3
|
-
|
|
4
|
+
var { name, ...settings } = annotation;
|
|
4
5
|
registerFormatType(name, settings);
|
|
5
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/format/index.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { registerFormatType } from '@wordpress/rich-text';\n\n/**\n * Internal dependencies\n */\nimport { annotation } from './annotation';\n\nconst { name, ...settings } = annotation;\n\nregisterFormatType( name, settings );\n"],
|
|
5
|
-
"mappings": "AAGA,SAAS,0BAA0B;AAKnC,SAAS,kBAAkB;AAE3B,
|
|
5
|
+
"mappings": ";AAGA,SAAS,0BAA0B;AAKnC,SAAS,kBAAkB;AAE3B,IAAM,EAAE,MAAM,GAAG,SAAS,IAAI;AAE9B,mBAAoB,MAAM,QAAS;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build-module/index.js
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport './format';\nimport './block';\n\nexport { store } from './store';\n"],
|
|
5
|
-
"mappings": "AAGA,OAAO;AACP,OAAO;AAEP,SAAS,aAAa;",
|
|
5
|
+
"mappings": ";AAGA,OAAO;AACP,OAAO;AAEP,SAAS,aAAa;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/store/actions.js"],
|
|
4
4
|
"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"],
|
|
5
|
-
"mappings": "AAGA,SAAS,MAAM,YAAY;AA6BpB,SAAS,4BAA6B;AAAA,EAC5C;AAAA,EACA,qBAAqB;AAAA,EACrB,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,SAAS;AAAA,EACT,KAAK,KAAK;AACX,GAAI;AACH,QAAM,SAAS;AAAA,IACd,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAEA,MAAK,aAAa,SAAU;AAC3B,WAAO,QAAQ;AAAA,EAChB;AAEA,SAAO;AACR;AASO,SAAS,+BAAgC,cAAe;AAC9D,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,EACD;AACD;AAWO,SAAS,oCACf,cACA,OACA,KACC;AACD,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AASO,SAAS,wCAAyC,QAAS;AACjE,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,EACD;AACD;",
|
|
5
|
+
"mappings": ";AAGA,SAAS,MAAM,YAAY;AA6BpB,SAAS,4BAA6B;AAAA,EAC5C;AAAA,EACA,qBAAqB;AAAA,EACrB,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,SAAS;AAAA,EACT,KAAK,KAAK;AACX,GAAI;AACH,QAAM,SAAS;AAAA,IACd,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAEA,MAAK,aAAa,SAAU;AAC3B,WAAO,QAAQ;AAAA,EAChB;AAEA,SAAO;AACR;AASO,SAAS,+BAAgC,cAAe;AAC9D,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,EACD;AACD;AAWO,SAAS,oCACf,cACA,OACA,KACC;AACD,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AASO,SAAS,wCAAyC,QAAS;AACjE,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/store/constants.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * The identifier for the data store.\n *\n * @type {string}\n */\nexport const STORE_NAME = 'core/annotations';\n"],
|
|
5
|
-
"mappings": "AAKO,
|
|
5
|
+
"mappings": ";AAKO,IAAM,aAAa;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
// packages/annotations/src/store/index.js
|
|
1
2
|
import { register, createReduxStore } from "@wordpress/data";
|
|
2
3
|
import reducer from "./reducer";
|
|
3
4
|
import * as selectors from "./selectors";
|
|
4
5
|
import * as actions from "./actions";
|
|
5
6
|
import { STORE_NAME } from "./constants";
|
|
6
|
-
|
|
7
|
+
var store = createReduxStore(STORE_NAME, {
|
|
7
8
|
reducer,
|
|
8
9
|
selectors,
|
|
9
10
|
actions
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/store/index.js"],
|
|
4
4
|
"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"],
|
|
5
|
-
"mappings": "AAGA,SAAS,UAAU,wBAAwB;AAK3C,OAAO,aAAa;AACpB,YAAY,eAAe;AAC3B,YAAY,aAAa;AAKzB,SAAS,kBAAkB;AASpB,
|
|
5
|
+
"mappings": ";AAGA,SAAS,UAAU,wBAAwB;AAK3C,OAAO,aAAa;AACpB,YAAY,eAAe;AAC3B,YAAY,aAAa;AAKzB,SAAS,kBAAkB;AASpB,IAAM,QAAQ,iBAAkB,YAAY;AAAA,EAClD;AAAA,EACA;AAAA,EACA;AACD,CAAE;AAEF,SAAU,KAAM;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
// packages/annotations/src/store/reducer.js
|
|
1
2
|
function filterWithReference(collection, predicate) {
|
|
2
3
|
const filteredCollection = collection.filter(predicate);
|
|
3
4
|
return collection.length === filteredCollection.length ? collection : filteredCollection;
|
|
4
5
|
}
|
|
5
|
-
|
|
6
|
+
var mapValues = (obj, callback) => Object.entries(obj).reduce(
|
|
6
7
|
(acc, [key, value]) => ({
|
|
7
8
|
...acc,
|
|
8
9
|
[key]: callback(value)
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/store/reducer.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * Filters an array based on the predicate, but keeps the reference the same if\n * the array hasn't changed.\n *\n * @param {Array} collection The collection to filter.\n * @param {Function} predicate Function that determines if the item should stay\n * in the array.\n * @return {Array} Filtered array.\n */\nfunction filterWithReference( collection, predicate ) {\n\tconst filteredCollection = collection.filter( predicate );\n\n\treturn collection.length === filteredCollection.length\n\t\t? collection\n\t\t: filteredCollection;\n}\n\n/**\n * Creates a new object with the same keys, but with `callback()` called as\n * a transformer function on each of the values.\n *\n * @param {Object} obj The object to transform.\n * @param {Function} callback The function to transform each object value.\n * @return {Array} Transformed object.\n */\nconst mapValues = ( obj, callback ) =>\n\tObject.entries( obj ).reduce(\n\t\t( acc, [ key, value ] ) => ( {\n\t\t\t...acc,\n\t\t\t[ key ]: callback( value ),\n\t\t} ),\n\t\t{}\n\t);\n\n/**\n * Verifies whether the given annotations is a valid annotation.\n *\n * @param {Object} annotation The annotation to verify.\n * @return {boolean} Whether the given annotation is valid.\n */\nfunction isValidAnnotationRange( annotation ) {\n\treturn (\n\t\ttypeof annotation.start === 'number' &&\n\t\ttypeof annotation.end === 'number' &&\n\t\tannotation.start <= annotation.end\n\t);\n}\n\n/**\n * Reducer managing annotations.\n *\n * @param {Object} state The annotations currently shown in the editor.\n * @param {Object} action Dispatched action.\n *\n * @return {Array} Updated state.\n */\nexport function annotations( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'ANNOTATION_ADD':\n\t\t\tconst blockClientId = action.blockClientId;\n\t\t\tconst newAnnotation = {\n\t\t\t\tid: action.id,\n\t\t\t\tblockClientId,\n\t\t\t\trichTextIdentifier: action.richTextIdentifier,\n\t\t\t\tsource: action.source,\n\t\t\t\tselector: action.selector,\n\t\t\t\trange: action.range,\n\t\t\t};\n\n\t\t\tif (\n\t\t\t\tnewAnnotation.selector === 'range' &&\n\t\t\t\t! isValidAnnotationRange( newAnnotation.range )\n\t\t\t) {\n\t\t\t\treturn state;\n\t\t\t}\n\n\t\t\tconst previousAnnotationsForBlock = state?.[ blockClientId ] ?? [];\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ blockClientId ]: [\n\t\t\t\t\t...previousAnnotationsForBlock,\n\t\t\t\t\tnewAnnotation,\n\t\t\t\t],\n\t\t\t};\n\n\t\tcase 'ANNOTATION_REMOVE':\n\t\t\treturn mapValues( state, ( annotationsForBlock ) => {\n\t\t\t\treturn filterWithReference(\n\t\t\t\t\tannotationsForBlock,\n\t\t\t\t\t( annotation ) => {\n\t\t\t\t\t\treturn annotation.id !== action.annotationId;\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} );\n\n\t\tcase 'ANNOTATION_UPDATE_RANGE':\n\t\t\treturn mapValues( state, ( annotationsForBlock ) => {\n\t\t\t\tlet hasChangedRange = false;\n\n\t\t\t\tconst newAnnotations = annotationsForBlock.map(\n\t\t\t\t\t( annotation ) => {\n\t\t\t\t\t\tif ( annotation.id === action.annotationId ) {\n\t\t\t\t\t\t\thasChangedRange = true;\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t...annotation,\n\t\t\t\t\t\t\t\trange: {\n\t\t\t\t\t\t\t\t\tstart: action.start,\n\t\t\t\t\t\t\t\t\tend: action.end,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn annotation;\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\treturn hasChangedRange ? newAnnotations : annotationsForBlock;\n\t\t\t} );\n\n\t\tcase 'ANNOTATION_REMOVE_SOURCE':\n\t\t\treturn mapValues( state, ( annotationsForBlock ) => {\n\t\t\t\treturn filterWithReference(\n\t\t\t\t\tannotationsForBlock,\n\t\t\t\t\t( annotation ) => {\n\t\t\t\t\t\treturn annotation.source !== action.source;\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} );\n\t}\n\n\treturn state;\n}\n\nexport default annotations;\n"],
|
|
5
|
-
"mappings": "AASA,SAAS,oBAAqB,YAAY,WAAY;AACrD,QAAM,qBAAqB,WAAW,OAAQ,SAAU;AAExD,SAAO,WAAW,WAAW,mBAAmB,SAC7C,aACA;AACJ;AAUA,
|
|
5
|
+
"mappings": ";AASA,SAAS,oBAAqB,YAAY,WAAY;AACrD,QAAM,qBAAqB,WAAW,OAAQ,SAAU;AAExD,SAAO,WAAW,WAAW,mBAAmB,SAC7C,aACA;AACJ;AAUA,IAAM,YAAY,CAAE,KAAK,aACxB,OAAO,QAAS,GAAI,EAAE;AAAA,EACrB,CAAE,KAAK,CAAE,KAAK,KAAM,OAAS;AAAA,IAC5B,GAAG;AAAA,IACH,CAAE,GAAI,GAAG,SAAU,KAAM;AAAA,EAC1B;AAAA,EACA,CAAC;AACF;AAQD,SAAS,uBAAwB,YAAa;AAC7C,SACC,OAAO,WAAW,UAAU,YAC5B,OAAO,WAAW,QAAQ,YAC1B,WAAW,SAAS,WAAW;AAEjC;AAUO,SAAS,YAAa,QAAQ,CAAC,GAAG,QAAS;AACjD,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK;AACJ,YAAM,gBAAgB,OAAO;AAC7B,YAAM,gBAAgB;AAAA,QACrB,IAAI,OAAO;AAAA,QACX;AAAA,QACA,oBAAoB,OAAO;AAAA,QAC3B,QAAQ,OAAO;AAAA,QACf,UAAU,OAAO;AAAA,QACjB,OAAO,OAAO;AAAA,MACf;AAEA,UACC,cAAc,aAAa,WAC3B,CAAE,uBAAwB,cAAc,KAAM,GAC7C;AACD,eAAO;AAAA,MACR;AAEA,YAAM,8BAA8B,QAAS,aAAc,KAAK,CAAC;AAEjE,aAAO;AAAA,QACN,GAAG;AAAA,QACH,CAAE,aAAc,GAAG;AAAA,UAClB,GAAG;AAAA,UACH;AAAA,QACD;AAAA,MACD;AAAA,IAED,KAAK;AACJ,aAAO,UAAW,OAAO,CAAE,wBAAyB;AACnD,eAAO;AAAA,UACN;AAAA,UACA,CAAE,eAAgB;AACjB,mBAAO,WAAW,OAAO,OAAO;AAAA,UACjC;AAAA,QACD;AAAA,MACD,CAAE;AAAA,IAEH,KAAK;AACJ,aAAO,UAAW,OAAO,CAAE,wBAAyB;AACnD,YAAI,kBAAkB;AAEtB,cAAM,iBAAiB,oBAAoB;AAAA,UAC1C,CAAE,eAAgB;AACjB,gBAAK,WAAW,OAAO,OAAO,cAAe;AAC5C,gCAAkB;AAClB,qBAAO;AAAA,gBACN,GAAG;AAAA,gBACH,OAAO;AAAA,kBACN,OAAO,OAAO;AAAA,kBACd,KAAK,OAAO;AAAA,gBACb;AAAA,cACD;AAAA,YACD;AAEA,mBAAO;AAAA,UACR;AAAA,QACD;AAEA,eAAO,kBAAkB,iBAAiB;AAAA,MAC3C,CAAE;AAAA,IAEH,KAAK;AACJ,aAAO,UAAW,OAAO,CAAE,wBAAyB;AACnD,eAAO;AAAA,UACN;AAAA,UACA,CAAE,eAAgB;AACjB,mBAAO,WAAW,WAAW,OAAO;AAAA,UACrC;AAAA,QACD;AAAA,MACD,CAAE;AAAA,EACJ;AAEA,SAAO;AACR;AAEA,IAAO,kBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
// packages/annotations/src/store/selectors.js
|
|
1
2
|
import { createSelector } from "@wordpress/data";
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
var EMPTY_ARRAY = [];
|
|
4
|
+
var __experimentalGetAnnotationsForBlock = createSelector(
|
|
4
5
|
(state, blockClientId) => {
|
|
5
6
|
return (state?.[blockClientId] ?? []).filter((annotation) => {
|
|
6
7
|
return annotation.selector === "block";
|
|
@@ -11,7 +12,7 @@ const __experimentalGetAnnotationsForBlock = createSelector(
|
|
|
11
12
|
function __experimentalGetAllAnnotationsForBlock(state, blockClientId) {
|
|
12
13
|
return state?.[blockClientId] ?? EMPTY_ARRAY;
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
+
var __experimentalGetAnnotationsForRichText = createSelector(
|
|
15
16
|
(state, blockClientId, richTextIdentifier) => {
|
|
16
17
|
return (state?.[blockClientId] ?? []).filter((annotation) => {
|
|
17
18
|
return annotation.selector === "range" && richTextIdentifier === annotation.richTextIdentifier;
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/store/selectors.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createSelector } from '@wordpress/data';\n\n/**\n * Shared reference to an empty array for cases where it is important to avoid\n * returning a new array reference on every invocation, as in a connected or\n * other pure component which performs `shouldComponentUpdate` check on props.\n * This should be used as a last resort, since the normalized data should be\n * maintained by the reducer result in state.\n *\n * @type {Array}\n */\nconst EMPTY_ARRAY = [];\n\n/**\n * Returns the annotations for a specific client ID.\n *\n * @param {Object} state Editor state.\n * @param {string} clientId The ID of the block to get the annotations for.\n *\n * @return {Array} The annotations applicable to this block.\n */\nexport const __experimentalGetAnnotationsForBlock = createSelector(\n\t( state, blockClientId ) => {\n\t\treturn ( state?.[ blockClientId ] ?? [] ).filter( ( annotation ) => {\n\t\t\treturn annotation.selector === 'block';\n\t\t} );\n\t},\n\t( state, blockClientId ) => [ state?.[ blockClientId ] ?? EMPTY_ARRAY ]\n);\n\nexport function __experimentalGetAllAnnotationsForBlock(\n\tstate,\n\tblockClientId\n) {\n\treturn state?.[ blockClientId ] ?? EMPTY_ARRAY;\n}\n\n/**\n * Returns the annotations that apply to the given RichText instance.\n *\n * Both a blockClientId and a richTextIdentifier are required. This is because\n * a block might have multiple `RichText` components. This does mean that every\n * block needs to implement annotations itself.\n *\n * @param {Object} state Editor state.\n * @param {string} blockClientId The client ID for the block.\n * @param {string} richTextIdentifier Unique identifier that identifies the given RichText.\n * @return {Array} All the annotations relevant for the `RichText`.\n */\nexport const __experimentalGetAnnotationsForRichText = createSelector(\n\t( state, blockClientId, richTextIdentifier ) => {\n\t\treturn ( state?.[ blockClientId ] ?? [] )\n\t\t\t.filter( ( annotation ) => {\n\t\t\t\treturn (\n\t\t\t\t\tannotation.selector === 'range' &&\n\t\t\t\t\trichTextIdentifier === annotation.richTextIdentifier\n\t\t\t\t);\n\t\t\t} )\n\t\t\t.map( ( annotation ) => {\n\t\t\t\tconst { range, ...other } = annotation;\n\n\t\t\t\treturn {\n\t\t\t\t\t...range,\n\t\t\t\t\t...other,\n\t\t\t\t};\n\t\t\t} );\n\t},\n\t( state, blockClientId ) => [ state?.[ blockClientId ] ?? EMPTY_ARRAY ]\n);\n\n/**\n * Returns all annotations in the editor state.\n *\n * @param {Object} state Editor state.\n * @return {Array} All annotations currently applied.\n */\nexport function __experimentalGetAnnotations( state ) {\n\treturn Object.values( state ).flat();\n}\n"],
|
|
5
|
-
"mappings": "AAGA,SAAS,sBAAsB;AAW/B,
|
|
5
|
+
"mappings": ";AAGA,SAAS,sBAAsB;AAW/B,IAAM,cAAc,CAAC;AAUd,IAAM,uCAAuC;AAAA,EACnD,CAAE,OAAO,kBAAmB;AAC3B,YAAS,QAAS,aAAc,KAAK,CAAC,GAAI,OAAQ,CAAE,eAAgB;AACnE,aAAO,WAAW,aAAa;AAAA,IAChC,CAAE;AAAA,EACH;AAAA,EACA,CAAE,OAAO,kBAAmB,CAAE,QAAS,aAAc,KAAK,WAAY;AACvE;AAEO,SAAS,wCACf,OACA,eACC;AACD,SAAO,QAAS,aAAc,KAAK;AACpC;AAcO,IAAM,0CAA0C;AAAA,EACtD,CAAE,OAAO,eAAe,uBAAwB;AAC/C,YAAS,QAAS,aAAc,KAAK,CAAC,GACpC,OAAQ,CAAE,eAAgB;AAC1B,aACC,WAAW,aAAa,WACxB,uBAAuB,WAAW;AAAA,IAEpC,CAAE,EACD,IAAK,CAAE,eAAgB;AACvB,YAAM,EAAE,OAAO,GAAG,MAAM,IAAI;AAE5B,aAAO;AAAA,QACN,GAAG;AAAA,QACH,GAAG;AAAA,MACJ;AAAA,IACD,CAAE;AAAA,EACJ;AAAA,EACA,CAAE,OAAO,kBAAmB,CAAE,QAAS,aAAc,KAAK,WAAY;AACvE;AAQO,SAAS,6BAA8B,OAAQ;AACrD,SAAO,OAAO,OAAQ,KAAM,EAAE,KAAK;AACpC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/annotations",
|
|
3
|
-
"version": "3.34.0",
|
|
3
|
+
"version": "3.34.1-next.2f1c7c01b.0",
|
|
4
4
|
"description": "Annotate content in the Gutenberg editor.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"react-native": "src/index",
|
|
35
35
|
"wpScript": true,
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@wordpress/data": "^10.34.0",
|
|
38
|
-
"@wordpress/hooks": "^4.34.0",
|
|
39
|
-
"@wordpress/i18n": "^6.7.0",
|
|
40
|
-
"@wordpress/rich-text": "^7.34.0",
|
|
37
|
+
"@wordpress/data": "^10.34.1-next.2f1c7c01b.0",
|
|
38
|
+
"@wordpress/hooks": "^4.34.1-next.2f1c7c01b.0",
|
|
39
|
+
"@wordpress/i18n": "^6.7.1-next.2f1c7c01b.0",
|
|
40
|
+
"@wordpress/rich-text": "^7.34.1-next.2f1c7c01b.0",
|
|
41
41
|
"uuid": "^9.0.1"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "c6ddcdf455bc02567a2c9e03de6862a2061b85e8"
|
|
50
50
|
}
|