@wordpress/annotations 3.32.0 → 3.32.1-next.ff1cebbba.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 +17 -30
- package/build/block/index.js.map +7 -1
- package/build/format/annotation.js +85 -116
- package/build/format/annotation.js.map +7 -1
- package/build/format/index.js +5 -18
- package/build/format/index.js.map +7 -1
- package/build/index.js +28 -13
- package/build/index.js.map +7 -1
- package/build/store/actions.js +41 -75
- package/build/store/actions.js.map +7 -1
- package/build/store/constants.js +27 -12
- package/build/store/constants.js.map +7 -1
- package/build/store/index.js +44 -36
- package/build/store/index.js.map +7 -1
- package/build/store/reducer.js +75 -76
- package/build/store/reducer.js.map +7 -1
- package/build/store/selectors.js +56 -80
- package/build/store/selectors.js.map +7 -1
- package/build-module/block/index.js +17 -27
- package/build-module/block/index.js.map +7 -1
- package/build-module/format/annotation.js +61 -108
- package/build-module/format/annotation.js.map +7 -1
- package/build-module/format/index.js +4 -14
- package/build-module/format/index.js.map +7 -1
- package/build-module/index.js +7 -7
- package/build-module/index.js.map +7 -1
- package/build-module/store/actions.js +19 -70
- package/build-module/store/actions.js.map +7 -1
- package/build-module/store/constants.js +5 -7
- package/build-module/store/constants.js.map +7 -1
- package/build-module/store/index.js +10 -26
- package/build-module/store/index.js.map +7 -1
- package/build-module/store/reducer.js +54 -71
- package/build-module/store/reducer.js.map +7 -1
- package/build-module/store/selectors.js +33 -75
- package/build-module/store/selectors.js.map +7 -1
- package/package.json +13 -7
|
@@ -1,150 +1,102 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* Internal dependencies
|
|
10
|
-
*/
|
|
11
|
-
import { STORE_NAME } from '../store/constants';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Applies given annotations to the given record.
|
|
15
|
-
*
|
|
16
|
-
* @param {Object} record The record to apply annotations to.
|
|
17
|
-
* @param {Array} annotations The annotation to apply.
|
|
18
|
-
* @return {Object} A record with the annotations applied.
|
|
19
|
-
*/
|
|
20
|
-
export function applyAnnotations(record, annotations = []) {
|
|
21
|
-
annotations.forEach(annotation => {
|
|
22
|
-
let {
|
|
23
|
-
start,
|
|
24
|
-
end
|
|
25
|
-
} = annotation;
|
|
1
|
+
import { __ } from "@wordpress/i18n";
|
|
2
|
+
import { applyFormat, removeFormat } from "@wordpress/rich-text";
|
|
3
|
+
const FORMAT_NAME = "core/annotation";
|
|
4
|
+
const ANNOTATION_ATTRIBUTE_PREFIX = "annotation-text-";
|
|
5
|
+
import { STORE_NAME } from "../store/constants";
|
|
6
|
+
function applyAnnotations(record, annotations = []) {
|
|
7
|
+
annotations.forEach((annotation2) => {
|
|
8
|
+
let { start, end } = annotation2;
|
|
26
9
|
if (start > record.text.length) {
|
|
27
10
|
start = record.text.length;
|
|
28
11
|
}
|
|
29
12
|
if (end > record.text.length) {
|
|
30
13
|
end = record.text.length;
|
|
31
14
|
}
|
|
32
|
-
const className = ANNOTATION_ATTRIBUTE_PREFIX +
|
|
33
|
-
const id = ANNOTATION_ATTRIBUTE_PREFIX +
|
|
34
|
-
record = applyFormat(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
15
|
+
const className = ANNOTATION_ATTRIBUTE_PREFIX + annotation2.source;
|
|
16
|
+
const id = ANNOTATION_ATTRIBUTE_PREFIX + annotation2.id;
|
|
17
|
+
record = applyFormat(
|
|
18
|
+
record,
|
|
19
|
+
{
|
|
20
|
+
type: FORMAT_NAME,
|
|
21
|
+
attributes: {
|
|
22
|
+
className,
|
|
23
|
+
id
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
start,
|
|
27
|
+
end
|
|
28
|
+
);
|
|
41
29
|
});
|
|
42
30
|
return record;
|
|
43
31
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
* Removes annotations from the given record.
|
|
47
|
-
*
|
|
48
|
-
* @param {Object} record Record to remove annotations from.
|
|
49
|
-
* @return {Object} The cleaned record.
|
|
50
|
-
*/
|
|
51
|
-
export function removeAnnotations(record) {
|
|
52
|
-
return removeFormat(record, 'core/annotation', 0, record.text.length);
|
|
32
|
+
function removeAnnotations(record) {
|
|
33
|
+
return removeFormat(record, "core/annotation", 0, record.text.length);
|
|
53
34
|
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Retrieves the positions of annotations inside an array of formats.
|
|
57
|
-
*
|
|
58
|
-
* @param {Array} formats Formats with annotations in there.
|
|
59
|
-
* @return {Object} ID keyed positions of annotations.
|
|
60
|
-
*/
|
|
61
35
|
function retrieveAnnotationPositions(formats) {
|
|
62
36
|
const positions = {};
|
|
63
37
|
formats.forEach((characterFormats, i) => {
|
|
64
38
|
characterFormats = characterFormats || [];
|
|
65
|
-
characterFormats = characterFormats.filter(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
} = format.attributes;
|
|
70
|
-
id = id.replace(ANNOTATION_ATTRIBUTE_PREFIX,
|
|
39
|
+
characterFormats = characterFormats.filter(
|
|
40
|
+
(format) => format.type === FORMAT_NAME
|
|
41
|
+
);
|
|
42
|
+
characterFormats.forEach((format) => {
|
|
43
|
+
let { id } = format.attributes;
|
|
44
|
+
id = id.replace(ANNOTATION_ATTRIBUTE_PREFIX, "");
|
|
71
45
|
if (!positions.hasOwnProperty(id)) {
|
|
72
46
|
positions[id] = {
|
|
73
47
|
start: i
|
|
74
48
|
};
|
|
75
49
|
}
|
|
76
|
-
|
|
77
|
-
// Annotations refer to positions between characters.
|
|
78
|
-
// Formats refer to the character themselves.
|
|
79
|
-
// So we need to adjust for that here.
|
|
80
50
|
positions[id].end = i + 1;
|
|
81
51
|
});
|
|
82
52
|
});
|
|
83
53
|
return positions;
|
|
84
54
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
* Updates annotations in the state based on positions retrieved from RichText.
|
|
88
|
-
*
|
|
89
|
-
* @param {Array} annotations The annotations that are currently applied.
|
|
90
|
-
* @param {Array} positions The current positions of the given annotations.
|
|
91
|
-
* @param {Object} actions
|
|
92
|
-
* @param {Function} actions.removeAnnotation Function to remove an annotation from the state.
|
|
93
|
-
* @param {Function} actions.updateAnnotationRange Function to update an annotation range in the state.
|
|
94
|
-
*/
|
|
95
|
-
function updateAnnotationsWithPositions(annotations, positions, {
|
|
96
|
-
removeAnnotation,
|
|
97
|
-
updateAnnotationRange
|
|
98
|
-
}) {
|
|
99
|
-
annotations.forEach(currentAnnotation => {
|
|
55
|
+
function updateAnnotationsWithPositions(annotations, positions, { removeAnnotation, updateAnnotationRange }) {
|
|
56
|
+
annotations.forEach((currentAnnotation) => {
|
|
100
57
|
const position = positions[currentAnnotation.id];
|
|
101
|
-
// If we cannot find an annotation, delete it.
|
|
102
58
|
if (!position) {
|
|
103
|
-
// Apparently the annotation has been removed, so remove it from the state:
|
|
104
|
-
// Remove...
|
|
105
59
|
removeAnnotation(currentAnnotation.id);
|
|
106
60
|
return;
|
|
107
61
|
}
|
|
108
|
-
const {
|
|
109
|
-
start,
|
|
110
|
-
end
|
|
111
|
-
} = currentAnnotation;
|
|
62
|
+
const { start, end } = currentAnnotation;
|
|
112
63
|
if (start !== position.start || end !== position.end) {
|
|
113
|
-
updateAnnotationRange(
|
|
64
|
+
updateAnnotationRange(
|
|
65
|
+
currentAnnotation.id,
|
|
66
|
+
position.start,
|
|
67
|
+
position.end
|
|
68
|
+
);
|
|
114
69
|
}
|
|
115
70
|
});
|
|
116
71
|
}
|
|
117
|
-
|
|
72
|
+
const annotation = {
|
|
118
73
|
name: FORMAT_NAME,
|
|
119
|
-
title: __(
|
|
120
|
-
tagName:
|
|
121
|
-
className:
|
|
74
|
+
title: __("Annotation"),
|
|
75
|
+
tagName: "mark",
|
|
76
|
+
className: "annotation-text",
|
|
122
77
|
attributes: {
|
|
123
|
-
className:
|
|
124
|
-
id:
|
|
78
|
+
className: "class",
|
|
79
|
+
id: "id"
|
|
125
80
|
},
|
|
126
81
|
edit() {
|
|
127
82
|
return null;
|
|
128
83
|
},
|
|
129
|
-
__experimentalGetPropsForEditableTreePreparation(select, {
|
|
130
|
-
richTextIdentifier,
|
|
131
|
-
blockClientId
|
|
132
|
-
}) {
|
|
84
|
+
__experimentalGetPropsForEditableTreePreparation(select, { richTextIdentifier, blockClientId }) {
|
|
133
85
|
return {
|
|
134
|
-
annotations: select(
|
|
86
|
+
annotations: select(
|
|
87
|
+
STORE_NAME
|
|
88
|
+
).__experimentalGetAnnotationsForRichText(
|
|
89
|
+
blockClientId,
|
|
90
|
+
richTextIdentifier
|
|
91
|
+
)
|
|
135
92
|
};
|
|
136
93
|
},
|
|
137
|
-
__experimentalCreatePrepareEditableTree({
|
|
138
|
-
annotations
|
|
139
|
-
}) {
|
|
94
|
+
__experimentalCreatePrepareEditableTree({ annotations }) {
|
|
140
95
|
return (formats, text) => {
|
|
141
96
|
if (annotations.length === 0) {
|
|
142
97
|
return formats;
|
|
143
98
|
}
|
|
144
|
-
let record = {
|
|
145
|
-
formats,
|
|
146
|
-
text
|
|
147
|
-
};
|
|
99
|
+
let record = { formats, text };
|
|
148
100
|
record = applyAnnotations(record, annotations);
|
|
149
101
|
return record.formats;
|
|
150
102
|
};
|
|
@@ -156,13 +108,9 @@ export const annotation = {
|
|
|
156
108
|
};
|
|
157
109
|
},
|
|
158
110
|
__experimentalCreateOnChangeEditableValue(props) {
|
|
159
|
-
return formats => {
|
|
111
|
+
return (formats) => {
|
|
160
112
|
const positions = retrieveAnnotationPositions(formats);
|
|
161
|
-
const {
|
|
162
|
-
removeAnnotation,
|
|
163
|
-
updateAnnotationRange,
|
|
164
|
-
annotations
|
|
165
|
-
} = props;
|
|
113
|
+
const { removeAnnotation, updateAnnotationRange, annotations } = props;
|
|
166
114
|
updateAnnotationsWithPositions(annotations, positions, {
|
|
167
115
|
removeAnnotation,
|
|
168
116
|
updateAnnotationRange
|
|
@@ -170,4 +118,9 @@ export const annotation = {
|
|
|
170
118
|
};
|
|
171
119
|
}
|
|
172
120
|
};
|
|
173
|
-
|
|
121
|
+
export {
|
|
122
|
+
annotation,
|
|
123
|
+
applyAnnotations,
|
|
124
|
+
removeAnnotations
|
|
125
|
+
};
|
|
126
|
+
//# sourceMappingURL=annotation.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/format/annotation.js"],
|
|
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;AAE1C,MAAM,cAAc;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A,IACH;AAAA,EACD;AACD;",
|
|
6
|
+
"names": ["annotation"]
|
|
7
|
+
}
|
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { registerFormatType } from '@wordpress/rich-text';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { annotation } from './annotation';
|
|
10
|
-
const {
|
|
11
|
-
name,
|
|
12
|
-
...settings
|
|
13
|
-
} = annotation;
|
|
1
|
+
import { registerFormatType } from "@wordpress/rich-text";
|
|
2
|
+
import { annotation } from "./annotation";
|
|
3
|
+
const { name, ...settings } = annotation;
|
|
14
4
|
registerFormatType(name, settings);
|
|
15
|
-
//# sourceMappingURL=index.js.map
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/format/index.js"],
|
|
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,MAAM,EAAE,MAAM,GAAG,SAAS,IAAI;AAE9B,mBAAoB,MAAM,QAAS;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build-module/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import "./format";
|
|
2
|
+
import "./block";
|
|
3
|
+
import { store } from "./store";
|
|
4
|
+
export {
|
|
5
|
+
store
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.js"],
|
|
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;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,100 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
import { v4 as uuid } from 'uuid';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @typedef WPAnnotationRange
|
|
8
|
-
*
|
|
9
|
-
* @property {number} start The offset where the annotation should start.
|
|
10
|
-
* @property {number} end The offset where the annotation should end.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Adds an annotation to a block.
|
|
15
|
-
*
|
|
16
|
-
* The `block` attribute refers to a block ID that needs to be annotated.
|
|
17
|
-
* `isBlockAnnotation` controls whether or not the annotation is a block
|
|
18
|
-
* annotation. The `source` is the source of the annotation, this will be used
|
|
19
|
-
* to identity groups of annotations.
|
|
20
|
-
*
|
|
21
|
-
* The `range` property is only relevant if the selector is 'range'.
|
|
22
|
-
*
|
|
23
|
-
* @param {Object} annotation The annotation to add.
|
|
24
|
-
* @param {string} annotation.blockClientId The blockClientId to add the annotation to.
|
|
25
|
-
* @param {string} annotation.richTextIdentifier Identifier for the RichText instance the annotation applies to.
|
|
26
|
-
* @param {WPAnnotationRange} annotation.range The range at which to apply this annotation.
|
|
27
|
-
* @param {string} [annotation.selector="range"] The way to apply this annotation.
|
|
28
|
-
* @param {string} [annotation.source="default"] The source that added the annotation.
|
|
29
|
-
* @param {string} [annotation.id] The ID the annotation should have. Generates a UUID by default.
|
|
30
|
-
*
|
|
31
|
-
* @return {Object} Action object.
|
|
32
|
-
*/
|
|
33
|
-
export function __experimentalAddAnnotation({
|
|
1
|
+
import { v4 as uuid } from "uuid";
|
|
2
|
+
function __experimentalAddAnnotation({
|
|
34
3
|
blockClientId,
|
|
35
4
|
richTextIdentifier = null,
|
|
36
5
|
range = null,
|
|
37
|
-
selector =
|
|
38
|
-
source =
|
|
6
|
+
selector = "range",
|
|
7
|
+
source = "default",
|
|
39
8
|
id = uuid()
|
|
40
9
|
}) {
|
|
41
10
|
const action = {
|
|
42
|
-
type:
|
|
11
|
+
type: "ANNOTATION_ADD",
|
|
43
12
|
id,
|
|
44
13
|
blockClientId,
|
|
45
14
|
richTextIdentifier,
|
|
46
15
|
source,
|
|
47
16
|
selector
|
|
48
17
|
};
|
|
49
|
-
if (selector ===
|
|
18
|
+
if (selector === "range") {
|
|
50
19
|
action.range = range;
|
|
51
20
|
}
|
|
52
21
|
return action;
|
|
53
22
|
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Removes an annotation with a specific ID.
|
|
57
|
-
*
|
|
58
|
-
* @param {string} annotationId The annotation to remove.
|
|
59
|
-
*
|
|
60
|
-
* @return {Object} Action object.
|
|
61
|
-
*/
|
|
62
|
-
export function __experimentalRemoveAnnotation(annotationId) {
|
|
23
|
+
function __experimentalRemoveAnnotation(annotationId) {
|
|
63
24
|
return {
|
|
64
|
-
type:
|
|
25
|
+
type: "ANNOTATION_REMOVE",
|
|
65
26
|
annotationId
|
|
66
27
|
};
|
|
67
28
|
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Updates the range of an annotation.
|
|
71
|
-
*
|
|
72
|
-
* @param {string} annotationId ID of the annotation to update.
|
|
73
|
-
* @param {number} start The start of the new range.
|
|
74
|
-
* @param {number} end The end of the new range.
|
|
75
|
-
*
|
|
76
|
-
* @return {Object} Action object.
|
|
77
|
-
*/
|
|
78
|
-
export function __experimentalUpdateAnnotationRange(annotationId, start, end) {
|
|
29
|
+
function __experimentalUpdateAnnotationRange(annotationId, start, end) {
|
|
79
30
|
return {
|
|
80
|
-
type:
|
|
31
|
+
type: "ANNOTATION_UPDATE_RANGE",
|
|
81
32
|
annotationId,
|
|
82
33
|
start,
|
|
83
34
|
end
|
|
84
35
|
};
|
|
85
36
|
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Removes all annotations of a specific source.
|
|
89
|
-
*
|
|
90
|
-
* @param {string} source The source to remove.
|
|
91
|
-
*
|
|
92
|
-
* @return {Object} Action object.
|
|
93
|
-
*/
|
|
94
|
-
export function __experimentalRemoveAnnotationsBySource(source) {
|
|
37
|
+
function __experimentalRemoveAnnotationsBySource(source) {
|
|
95
38
|
return {
|
|
96
|
-
type:
|
|
39
|
+
type: "ANNOTATION_REMOVE_SOURCE",
|
|
97
40
|
source
|
|
98
41
|
};
|
|
99
42
|
}
|
|
100
|
-
|
|
43
|
+
export {
|
|
44
|
+
__experimentalAddAnnotation,
|
|
45
|
+
__experimentalRemoveAnnotation,
|
|
46
|
+
__experimentalRemoveAnnotationsBySource,
|
|
47
|
+
__experimentalUpdateAnnotationRange
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=actions.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/store/actions.js"],
|
|
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;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export const STORE_NAME = 'core/annotations';
|
|
7
|
-
//# sourceMappingURL=constants.js.map
|
|
1
|
+
const STORE_NAME = "core/annotations";
|
|
2
|
+
export {
|
|
3
|
+
STORE_NAME
|
|
4
|
+
};
|
|
5
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/store/constants.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * The identifier for the data store.\n *\n * @type {string}\n */\nexport const STORE_NAME = 'core/annotations';\n"],
|
|
5
|
+
"mappings": "AAKO,MAAM,aAAa;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,31 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import reducer from './reducer';
|
|
10
|
-
import * as selectors from './selectors';
|
|
11
|
-
import * as actions from './actions';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Module Constants
|
|
15
|
-
*/
|
|
16
|
-
import { STORE_NAME } from './constants';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Store definition for the annotations namespace.
|
|
20
|
-
*
|
|
21
|
-
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
|
|
22
|
-
*
|
|
23
|
-
* @type {Object}
|
|
24
|
-
*/
|
|
25
|
-
export const store = createReduxStore(STORE_NAME, {
|
|
1
|
+
import { register, createReduxStore } from "@wordpress/data";
|
|
2
|
+
import reducer from "./reducer";
|
|
3
|
+
import * as selectors from "./selectors";
|
|
4
|
+
import * as actions from "./actions";
|
|
5
|
+
import { STORE_NAME } from "./constants";
|
|
6
|
+
const store = createReduxStore(STORE_NAME, {
|
|
26
7
|
reducer,
|
|
27
8
|
selectors,
|
|
28
9
|
actions
|
|
29
10
|
});
|
|
30
11
|
register(store);
|
|
31
|
-
|
|
12
|
+
export {
|
|
13
|
+
store
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/store/index.js"],
|
|
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,MAAM,QAAQ,iBAAkB,YAAY;AAAA,EAClD;AAAA,EACA;AAAA,EACA;AACD,CAAE;AAEF,SAAU,KAAM;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|