@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
package/build/store/constants.js
CHANGED
|
@@ -1,13 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var constants_exports = {};
|
|
19
|
+
__export(constants_exports, {
|
|
20
|
+
STORE_NAME: () => STORE_NAME
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
//# sourceMappingURL=constants.js.map
|
|
22
|
+
module.exports = __toCommonJS(constants_exports);
|
|
23
|
+
const STORE_NAME = "core/annotations";
|
|
24
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
25
|
+
0 && (module.exports = {
|
|
26
|
+
STORE_NAME
|
|
27
|
+
});
|
|
28
|
+
//# 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": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,MAAM,aAAa;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build/store/index.js
CHANGED
|
@@ -1,40 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var store_exports = {};
|
|
29
|
+
__export(store_exports, {
|
|
30
|
+
store: () => store
|
|
6
31
|
});
|
|
7
|
-
exports
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var selectors =
|
|
11
|
-
var actions =
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* WordPress dependencies
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Internal dependencies
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Module Constants
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Store definition for the annotations namespace.
|
|
29
|
-
*
|
|
30
|
-
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
|
|
31
|
-
*
|
|
32
|
-
* @type {Object}
|
|
33
|
-
*/
|
|
34
|
-
const store = exports.store = (0, _data.createReduxStore)(_constants.STORE_NAME, {
|
|
35
|
-
reducer: _reducer.default,
|
|
32
|
+
module.exports = __toCommonJS(store_exports);
|
|
33
|
+
var import_data = require("@wordpress/data");
|
|
34
|
+
var import_reducer = __toESM(require("./reducer"));
|
|
35
|
+
var selectors = __toESM(require("./selectors"));
|
|
36
|
+
var actions = __toESM(require("./actions"));
|
|
37
|
+
var import_constants = require("./constants");
|
|
38
|
+
const store = (0, import_data.createReduxStore)(import_constants.STORE_NAME, {
|
|
39
|
+
reducer: import_reducer.default,
|
|
36
40
|
selectors,
|
|
37
41
|
actions
|
|
38
42
|
});
|
|
39
|
-
(0,
|
|
40
|
-
|
|
43
|
+
(0, import_data.register)(store);
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
store
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
package/build/store/index.js.map
CHANGED
|
@@ -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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA2C;AAK3C,qBAAoB;AACpB,gBAA2B;AAC3B,cAAyB;AAKzB,uBAA2B;AASpB,MAAM,YAAQ,8BAAkB,6BAAY;AAAA,EAClD,wBAAAA;AAAA,EACA;AAAA,EACA;AACD,CAAE;AAAA,IAEF,sBAAU,KAAM;",
|
|
6
|
+
"names": ["reducer"]
|
|
7
|
+
}
|
package/build/store/reducer.js
CHANGED
|
@@ -1,59 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var reducer_exports = {};
|
|
19
|
+
__export(reducer_exports, {
|
|
20
|
+
annotations: () => annotations,
|
|
21
|
+
default: () => reducer_default
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
/**
|
|
9
|
-
* Filters an array based on the predicate, but keeps the reference the same if
|
|
10
|
-
* the array hasn't changed.
|
|
11
|
-
*
|
|
12
|
-
* @param {Array} collection The collection to filter.
|
|
13
|
-
* @param {Function} predicate Function that determines if the item should stay
|
|
14
|
-
* in the array.
|
|
15
|
-
* @return {Array} Filtered array.
|
|
16
|
-
*/
|
|
23
|
+
module.exports = __toCommonJS(reducer_exports);
|
|
17
24
|
function filterWithReference(collection, predicate) {
|
|
18
25
|
const filteredCollection = collection.filter(predicate);
|
|
19
26
|
return collection.length === filteredCollection.length ? collection : filteredCollection;
|
|
20
27
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
* @return {Array} Transformed object.
|
|
29
|
-
*/
|
|
30
|
-
const mapValues = (obj, callback) => Object.entries(obj).reduce((acc, [key, value]) => ({
|
|
31
|
-
...acc,
|
|
32
|
-
[key]: callback(value)
|
|
33
|
-
}), {});
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Verifies whether the given annotations is a valid annotation.
|
|
37
|
-
*
|
|
38
|
-
* @param {Object} annotation The annotation to verify.
|
|
39
|
-
* @return {boolean} Whether the given annotation is valid.
|
|
40
|
-
*/
|
|
28
|
+
const mapValues = (obj, callback) => Object.entries(obj).reduce(
|
|
29
|
+
(acc, [key, value]) => ({
|
|
30
|
+
...acc,
|
|
31
|
+
[key]: callback(value)
|
|
32
|
+
}),
|
|
33
|
+
{}
|
|
34
|
+
);
|
|
41
35
|
function isValidAnnotationRange(annotation) {
|
|
42
|
-
return typeof annotation.start ===
|
|
36
|
+
return typeof annotation.start === "number" && typeof annotation.end === "number" && annotation.start <= annotation.end;
|
|
43
37
|
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Reducer managing annotations.
|
|
47
|
-
*
|
|
48
|
-
* @param {Object} state The annotations currently shown in the editor.
|
|
49
|
-
* @param {Object} action Dispatched action.
|
|
50
|
-
*
|
|
51
|
-
* @return {Array} Updated state.
|
|
52
|
-
*/
|
|
53
38
|
function annotations(state = {}, action) {
|
|
54
|
-
var _state$blockClientId;
|
|
55
39
|
switch (action.type) {
|
|
56
|
-
case
|
|
40
|
+
case "ANNOTATION_ADD":
|
|
57
41
|
const blockClientId = action.blockClientId;
|
|
58
42
|
const newAnnotation = {
|
|
59
43
|
id: action.id,
|
|
@@ -63,46 +47,61 @@ function annotations(state = {}, action) {
|
|
|
63
47
|
selector: action.selector,
|
|
64
48
|
range: action.range
|
|
65
49
|
};
|
|
66
|
-
if (newAnnotation.selector ===
|
|
50
|
+
if (newAnnotation.selector === "range" && !isValidAnnotationRange(newAnnotation.range)) {
|
|
67
51
|
return state;
|
|
68
52
|
}
|
|
69
|
-
const previousAnnotationsForBlock =
|
|
53
|
+
const previousAnnotationsForBlock = state?.[blockClientId] ?? [];
|
|
70
54
|
return {
|
|
71
55
|
...state,
|
|
72
|
-
[blockClientId]: [
|
|
56
|
+
[blockClientId]: [
|
|
57
|
+
...previousAnnotationsForBlock,
|
|
58
|
+
newAnnotation
|
|
59
|
+
]
|
|
73
60
|
};
|
|
74
|
-
case
|
|
75
|
-
return mapValues(state, annotationsForBlock => {
|
|
76
|
-
return filterWithReference(
|
|
77
|
-
|
|
78
|
-
|
|
61
|
+
case "ANNOTATION_REMOVE":
|
|
62
|
+
return mapValues(state, (annotationsForBlock) => {
|
|
63
|
+
return filterWithReference(
|
|
64
|
+
annotationsForBlock,
|
|
65
|
+
(annotation) => {
|
|
66
|
+
return annotation.id !== action.annotationId;
|
|
67
|
+
}
|
|
68
|
+
);
|
|
79
69
|
});
|
|
80
|
-
case
|
|
81
|
-
return mapValues(state, annotationsForBlock => {
|
|
70
|
+
case "ANNOTATION_UPDATE_RANGE":
|
|
71
|
+
return mapValues(state, (annotationsForBlock) => {
|
|
82
72
|
let hasChangedRange = false;
|
|
83
|
-
const newAnnotations = annotationsForBlock.map(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
73
|
+
const newAnnotations = annotationsForBlock.map(
|
|
74
|
+
(annotation) => {
|
|
75
|
+
if (annotation.id === action.annotationId) {
|
|
76
|
+
hasChangedRange = true;
|
|
77
|
+
return {
|
|
78
|
+
...annotation,
|
|
79
|
+
range: {
|
|
80
|
+
start: action.start,
|
|
81
|
+
end: action.end
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return annotation;
|
|
93
86
|
}
|
|
94
|
-
|
|
95
|
-
});
|
|
87
|
+
);
|
|
96
88
|
return hasChangedRange ? newAnnotations : annotationsForBlock;
|
|
97
89
|
});
|
|
98
|
-
case
|
|
99
|
-
return mapValues(state, annotationsForBlock => {
|
|
100
|
-
return filterWithReference(
|
|
101
|
-
|
|
102
|
-
|
|
90
|
+
case "ANNOTATION_REMOVE_SOURCE":
|
|
91
|
+
return mapValues(state, (annotationsForBlock) => {
|
|
92
|
+
return filterWithReference(
|
|
93
|
+
annotationsForBlock,
|
|
94
|
+
(annotation) => {
|
|
95
|
+
return annotation.source !== action.source;
|
|
96
|
+
}
|
|
97
|
+
);
|
|
103
98
|
});
|
|
104
99
|
}
|
|
105
100
|
return state;
|
|
106
101
|
}
|
|
107
|
-
var
|
|
108
|
-
|
|
102
|
+
var reducer_default = annotations;
|
|
103
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
104
|
+
0 && (module.exports = {
|
|
105
|
+
annotations
|
|
106
|
+
});
|
|
107
|
+
//# sourceMappingURL=reducer.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/store/reducer.js"],
|
|
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": ";;;;;;;;;;;;;;;;;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,MAAM,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
|
+
"names": []
|
|
7
|
+
}
|
package/build/store/selectors.js
CHANGED
|
@@ -1,87 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var selectors_exports = {};
|
|
19
|
+
__export(selectors_exports, {
|
|
20
|
+
__experimentalGetAllAnnotationsForBlock: () => __experimentalGetAllAnnotationsForBlock,
|
|
21
|
+
__experimentalGetAnnotations: () => __experimentalGetAnnotations,
|
|
22
|
+
__experimentalGetAnnotationsForBlock: () => __experimentalGetAnnotationsForBlock,
|
|
23
|
+
__experimentalGetAnnotationsForRichText: () => __experimentalGetAnnotationsForRichText
|
|
5
24
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
exports.__experimentalGetAnnotationsForRichText = exports.__experimentalGetAnnotationsForBlock = void 0;
|
|
9
|
-
var _data = require("@wordpress/data");
|
|
10
|
-
/**
|
|
11
|
-
* WordPress dependencies
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Shared reference to an empty array for cases where it is important to avoid
|
|
16
|
-
* returning a new array reference on every invocation, as in a connected or
|
|
17
|
-
* other pure component which performs `shouldComponentUpdate` check on props.
|
|
18
|
-
* This should be used as a last resort, since the normalized data should be
|
|
19
|
-
* maintained by the reducer result in state.
|
|
20
|
-
*
|
|
21
|
-
* @type {Array}
|
|
22
|
-
*/
|
|
25
|
+
module.exports = __toCommonJS(selectors_exports);
|
|
26
|
+
var import_data = require("@wordpress/data");
|
|
23
27
|
const EMPTY_ARRAY = [];
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
*/
|
|
33
|
-
const __experimentalGetAnnotationsForBlock = exports.__experimentalGetAnnotationsForBlock = (0, _data.createSelector)((state, blockClientId) => {
|
|
34
|
-
var _state$blockClientId;
|
|
35
|
-
return ((_state$blockClientId = state?.[blockClientId]) !== null && _state$blockClientId !== void 0 ? _state$blockClientId : []).filter(annotation => {
|
|
36
|
-
return annotation.selector === 'block';
|
|
37
|
-
});
|
|
38
|
-
}, (state, blockClientId) => {
|
|
39
|
-
var _state$blockClientId2;
|
|
40
|
-
return [(_state$blockClientId2 = state?.[blockClientId]) !== null && _state$blockClientId2 !== void 0 ? _state$blockClientId2 : EMPTY_ARRAY];
|
|
41
|
-
});
|
|
28
|
+
const __experimentalGetAnnotationsForBlock = (0, import_data.createSelector)(
|
|
29
|
+
(state, blockClientId) => {
|
|
30
|
+
return (state?.[blockClientId] ?? []).filter((annotation) => {
|
|
31
|
+
return annotation.selector === "block";
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
(state, blockClientId) => [state?.[blockClientId] ?? EMPTY_ARRAY]
|
|
35
|
+
);
|
|
42
36
|
function __experimentalGetAllAnnotationsForBlock(state, blockClientId) {
|
|
43
|
-
|
|
44
|
-
return (_state$blockClientId3 = state?.[blockClientId]) !== null && _state$blockClientId3 !== void 0 ? _state$blockClientId3 : EMPTY_ARRAY;
|
|
37
|
+
return state?.[blockClientId] ?? EMPTY_ARRAY;
|
|
45
38
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
var _state$blockClientId4;
|
|
61
|
-
return ((_state$blockClientId4 = state?.[blockClientId]) !== null && _state$blockClientId4 !== void 0 ? _state$blockClientId4 : []).filter(annotation => {
|
|
62
|
-
return annotation.selector === 'range' && richTextIdentifier === annotation.richTextIdentifier;
|
|
63
|
-
}).map(annotation => {
|
|
64
|
-
const {
|
|
65
|
-
range,
|
|
66
|
-
...other
|
|
67
|
-
} = annotation;
|
|
68
|
-
return {
|
|
69
|
-
...range,
|
|
70
|
-
...other
|
|
71
|
-
};
|
|
72
|
-
});
|
|
73
|
-
}, (state, blockClientId) => {
|
|
74
|
-
var _state$blockClientId5;
|
|
75
|
-
return [(_state$blockClientId5 = state?.[blockClientId]) !== null && _state$blockClientId5 !== void 0 ? _state$blockClientId5 : EMPTY_ARRAY];
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Returns all annotations in the editor state.
|
|
80
|
-
*
|
|
81
|
-
* @param {Object} state Editor state.
|
|
82
|
-
* @return {Array} All annotations currently applied.
|
|
83
|
-
*/
|
|
39
|
+
const __experimentalGetAnnotationsForRichText = (0, import_data.createSelector)(
|
|
40
|
+
(state, blockClientId, richTextIdentifier) => {
|
|
41
|
+
return (state?.[blockClientId] ?? []).filter((annotation) => {
|
|
42
|
+
return annotation.selector === "range" && richTextIdentifier === annotation.richTextIdentifier;
|
|
43
|
+
}).map((annotation) => {
|
|
44
|
+
const { range, ...other } = annotation;
|
|
45
|
+
return {
|
|
46
|
+
...range,
|
|
47
|
+
...other
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
(state, blockClientId) => [state?.[blockClientId] ?? EMPTY_ARRAY]
|
|
52
|
+
);
|
|
84
53
|
function __experimentalGetAnnotations(state) {
|
|
85
54
|
return Object.values(state).flat();
|
|
86
55
|
}
|
|
87
|
-
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
__experimentalGetAllAnnotationsForBlock,
|
|
59
|
+
__experimentalGetAnnotations,
|
|
60
|
+
__experimentalGetAnnotationsForBlock,
|
|
61
|
+
__experimentalGetAnnotationsForRichText
|
|
62
|
+
});
|
|
63
|
+
//# sourceMappingURL=selectors.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/store/selectors.js"],
|
|
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": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA+B;AAW/B,MAAM,cAAc,CAAC;AAUd,MAAM,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,MAAM,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
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,31 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*/
|
|
10
|
-
import { STORE_NAME } from '../store/constants';
|
|
11
|
-
/**
|
|
12
|
-
* Adds annotation className to the block-list-block component.
|
|
13
|
-
*
|
|
14
|
-
* @param {Object} OriginalComponent The original BlockListBlock component.
|
|
15
|
-
* @return {Object} The enhanced component.
|
|
16
|
-
*/
|
|
17
|
-
const addAnnotationClassName = OriginalComponent => {
|
|
18
|
-
return withSelect((select, {
|
|
19
|
-
clientId,
|
|
20
|
-
className
|
|
21
|
-
}) => {
|
|
22
|
-
const annotations = select(STORE_NAME).__experimentalGetAnnotationsForBlock(clientId);
|
|
1
|
+
import { addFilter } from "@wordpress/hooks";
|
|
2
|
+
import { withSelect } from "@wordpress/data";
|
|
3
|
+
import { STORE_NAME } from "../store/constants";
|
|
4
|
+
const addAnnotationClassName = (OriginalComponent) => {
|
|
5
|
+
return withSelect((select, { clientId, className }) => {
|
|
6
|
+
const annotations = select(STORE_NAME).__experimentalGetAnnotationsForBlock(
|
|
7
|
+
clientId
|
|
8
|
+
);
|
|
23
9
|
return {
|
|
24
|
-
className: annotations.map(annotation => {
|
|
25
|
-
return
|
|
26
|
-
}).concat(className).filter(Boolean).join(
|
|
10
|
+
className: annotations.map((annotation) => {
|
|
11
|
+
return "is-annotated-by-" + annotation.source;
|
|
12
|
+
}).concat(className).filter(Boolean).join(" ")
|
|
27
13
|
};
|
|
28
14
|
})(OriginalComponent);
|
|
29
15
|
};
|
|
30
|
-
addFilter(
|
|
31
|
-
|
|
16
|
+
addFilter(
|
|
17
|
+
"editor.BlockListBlock",
|
|
18
|
+
"core/annotations",
|
|
19
|
+
addAnnotationClassName
|
|
20
|
+
);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/block/index.js"],
|
|
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,MAAM,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
|
+
"names": []
|
|
7
|
+
}
|