PluginProbe
Gutenberg / 22.7.0
Gutenberg v22.7.0
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
← All changes | build/scripts/annotations/index.js +44 -68 23.1.0 → 22.7.0 View file →
@@ -1,5 +1,4 @@
1 -"use strict";
2 1 var wp;
3 2 (wp ||= {}).annotations = (() => {
4 3 var __create = Object.create;
5 4 var __defProp = Object.defineProperty;
@@ -81,11 +80,8 @@
81 80 var ANNOTATION_ATTRIBUTE_PREFIX = "annotation-text-";
82 81 function applyAnnotations(record, annotations2 = []) {
83 82 annotations2.forEach((annotation2) => {
84 83 let { start, end } = annotation2;
85 - if (typeof start !== "number" || typeof end !== "number") {
86 - return;
87 - }
88 84 if (start > record.text.length) {
89 85 start = record.text.length;
90 86 }
91 87 if (end > record.text.length) {
@@ -127,12 +123,9 @@
127 123 });
128 124 });
129 125 return positions;
130 126 }
131 - function updateAnnotationsWithPositions(annotations2, positions, {
132 - removeAnnotation,
133 - updateAnnotationRange
134 - }) {
127 + function updateAnnotationsWithPositions(annotations2, positions, { removeAnnotation, updateAnnotationRange }) {
135 128 annotations2.forEach((currentAnnotation) => {
136 129 const position = positions[currentAnnotation.id];
137 130 if (!position) {
138 131 removeAnnotation(currentAnnotation.id);
@@ -138,13 +131,13 @@
138 131 removeAnnotation(currentAnnotation.id);
139 132 return;
140 133 }
141 134 const { start, end } = currentAnnotation;
142 - if (typeof start === "number" && typeof end === "number" && (start !== position.start || end !== (position.end ?? position.start))) {
135 + if (start !== position.start || end !== position.end) {
143 136 updateAnnotationRange(
144 137 currentAnnotation.id,
145 138 position.start,
146 - position.end ?? position.start
139 + position.end
147 140 );
148 141 }
149 142 });
150 143 }
@@ -156,14 +149,12 @@
156 149 attributes: {
157 150 className: "class",
158 151 id: "id"
159 152 },
160 - interactive: false,
161 - object: false,
162 - edit: () => {
153 + edit() {
163 154 return null;
164 155 },
165 - __experimentalGetPropsForEditableTreePreparation: (select, { richTextIdentifier, blockClientId }) => {
156 + __experimentalGetPropsForEditableTreePreparation(select, { richTextIdentifier, blockClientId }) {
166 157 return {
167 158 annotations: select(
168 159 STORE_NAME
169 160 ).__experimentalGetAnnotationsForRichText(
@@ -171,31 +162,25 @@
171 162 richTextIdentifier
172 163 )
173 164 };
174 165 },
175 - __experimentalCreatePrepareEditableTree: ({ annotations: annotations2 }) => {
166 + __experimentalCreatePrepareEditableTree({ annotations: annotations2 }) {
176 167 return (formats, text) => {
177 168 if (annotations2.length === 0) {
178 169 return formats;
179 170 }
180 - let record = {
181 - formats,
182 - text,
183 - replacements: [],
184 - start: 0,
185 - end: 0
186 - };
171 + let record = { formats, text };
187 172 record = applyAnnotations(record, annotations2);
188 173 return record.formats;
189 174 };
190 175 },
191 - __experimentalGetPropsForEditableTreeChangeHandler: (dispatch) => {
176 + __experimentalGetPropsForEditableTreeChangeHandler(dispatch) {
192 177 return {
193 178 removeAnnotation: dispatch(STORE_NAME).__experimentalRemoveAnnotation,
194 179 updateAnnotationRange: dispatch(STORE_NAME).__experimentalUpdateAnnotationRange
195 180 };
196 181 },
197 - __experimentalCreateOnChangeEditableValue: (props) => {
182 + __experimentalCreateOnChangeEditableValue(props) {
198 183 return (formats) => {
199 184 const positions = retrieveAnnotationPositions(formats);
200 185 const { removeAnnotation, updateAnnotationRange, annotations: annotations2 } = props;
201 186 updateAnnotationsWithPositions(annotations2, positions, {
@@ -211,12 +196,29 @@
211 196 (0, import_rich_text2.registerFormatType)(name, settings);
212 197
213 198 // packages/annotations/build-module/block/index.mjs
214 199 var import_hooks = __toESM(require_hooks(), 1);
215 - var import_data3 = __toESM(require_data(), 1);
200 + var import_data = __toESM(require_data(), 1);
201 + var addAnnotationClassName = (OriginalComponent) => {
202 + return (0, import_data.withSelect)((select, { clientId, className }) => {
203 + const annotations2 = select(STORE_NAME).__experimentalGetAnnotationsForBlock(
204 + clientId
205 + );
206 + return {
207 + className: annotations2.map((annotation2) => {
208 + return "is-annotated-by-" + annotation2.source;
209 + }).concat(className).filter(Boolean).join(" ")
210 + };
211 + })(OriginalComponent);
212 + };
213 + (0, import_hooks.addFilter)(
214 + "editor.BlockListBlock",
215 + "core/annotations",
216 + addAnnotationClassName
217 + );
216 218
217 219 // packages/annotations/build-module/store/index.mjs
218 - var import_data2 = __toESM(require_data(), 1);
220 + var import_data3 = __toESM(require_data(), 1);
219 221
220 222 // packages/annotations/build-module/store/reducer.mjs
221 223 function filterWithReference(collection, predicate) {
222 224 const filteredCollection = collection.filter(predicate);
@@ -221,21 +223,17 @@
221 223 function filterWithReference(collection, predicate) {
222 224 const filteredCollection = collection.filter(predicate);
223 225 return collection.length === filteredCollection.length ? collection : filteredCollection;
224 226 }
225 - var mapValues = (obj, callback) => Object.entries(obj).reduce((acc, [key, value]) => {
226 - if (value === void 0) {
227 - return acc;
228 - }
229 - return {
227 + var mapValues = (obj, callback) => Object.entries(obj).reduce(
228 + (acc, [key, value]) => ({
230 229 ...acc,
231 230 [key]: callback(value)
232 - };
233 - }, {});
231 + }),
232 + {}
233 + );
234 234 function isValidAnnotationRange(annotation2) {
235 - return Boolean(
236 - annotation2.range && typeof annotation2.range.start === "number" && typeof annotation2.range.end === "number" && annotation2.range.start <= annotation2.range.end
237 - );
235 + return typeof annotation2.start === "number" && typeof annotation2.end === "number" && annotation2.start <= annotation2.end;
238 236 }
239 237 function annotations(state = {}, action) {
240 238 switch (action.type) {
241 239 case "ANNOTATION_ADD":
@@ -247,9 +245,9 @@
247 245 source: action.source,
248 246 selector: action.selector,
249 247 range: action.range
250 248 };
251 - if (newAnnotation.selector === "range" && !isValidAnnotationRange(newAnnotation)) {
249 + if (newAnnotation.selector === "range" && !isValidAnnotationRange(newAnnotation.range)) {
252 250 return state;
253 251 }
254 252 const previousAnnotationsForBlock = state?.[blockClientId] ?? [];
255 253 return {
@@ -309,24 +307,22 @@
309 307 __experimentalGetAnnotations: () => __experimentalGetAnnotations,
310 308 __experimentalGetAnnotationsForBlock: () => __experimentalGetAnnotationsForBlock,
311 309 __experimentalGetAnnotationsForRichText: () => __experimentalGetAnnotationsForRichText
312 310 });
313 - var import_data = __toESM(require_data(), 1);
311 + var import_data2 = __toESM(require_data(), 1);
314 312 var EMPTY_ARRAY = [];
315 - var __experimentalGetAnnotationsForBlock = (0, import_data.createSelector)(
313 + var __experimentalGetAnnotationsForBlock = (0, import_data2.createSelector)(
316 314 (state, blockClientId) => {
317 315 return (state?.[blockClientId] ?? []).filter((annotation2) => {
318 316 return annotation2.selector === "block";
319 317 });
320 318 },
321 - (state, blockClientId) => [
322 - state?.[blockClientId] ?? EMPTY_ARRAY
323 - ]
319 + (state, blockClientId) => [state?.[blockClientId] ?? EMPTY_ARRAY]
324 320 );
325 321 function __experimentalGetAllAnnotationsForBlock(state, blockClientId) {
326 322 return state?.[blockClientId] ?? EMPTY_ARRAY;
327 323 }
328 - var __experimentalGetAnnotationsForRichText = (0, import_data.createSelector)(
324 + var __experimentalGetAnnotationsForRichText = (0, import_data2.createSelector)(
329 325 (state, blockClientId, richTextIdentifier) => {
330 326 return (state?.[blockClientId] ?? []).filter((annotation2) => {
331 327 return annotation2.selector === "range" && richTextIdentifier === annotation2.richTextIdentifier;
332 328 }).map((annotation2) => {
@@ -336,14 +332,12 @@
336 332 ...other
337 333 };
338 334 });
339 335 },
340 - (state, blockClientId) => [
341 - state?.[blockClientId] ?? EMPTY_ARRAY
342 - ]
336 + (state, blockClientId) => [state?.[blockClientId] ?? EMPTY_ARRAY]
343 337 );
344 338 function __experimentalGetAnnotations(state) {
345 - return Object.values(state).filter((arr) => Boolean(arr)).flat();
339 + return Object.values(state).flat();
346 340 }
347 341
348 342 // packages/annotations/build-module/store/actions.mjs
349 343 var actions_exports = {};
@@ -418,9 +412,9 @@
418 412 richTextIdentifier,
419 413 source,
420 414 selector
421 415 };
422 - if (selector === "range" && range !== null) {
416 + if (selector === "range") {
423 417 action.range = range;
424 418 }
425 419 return action;
426 420 }
@@ -445,31 +439,13 @@
445 439 };
446 440 }
447 441
448 442 // packages/annotations/build-module/store/index.mjs
449 - var store = (0, import_data2.createReduxStore)(STORE_NAME, {
443 + var store = (0, import_data3.createReduxStore)(STORE_NAME, {
450 444 reducer: reducer_default,
451 445 selectors: selectors_exports,
452 446 actions: actions_exports
453 447 });
454 - (0, import_data2.register)(store);
455 -
456 - // packages/annotations/build-module/block/index.mjs
457 - var addAnnotationClassName = (OriginalComponent) => {
458 - return (0, import_data3.withSelect)((select, ownProps) => {
459 - const { clientId, className } = ownProps;
460 - const annotations2 = select(store).__experimentalGetAnnotationsForBlock(clientId);
461 - return {
462 - className: annotations2.map((annotation2) => {
463 - return "is-annotated-by-" + annotation2.source;
464 - }).concat(className || "").filter(Boolean).join(" ")
465 - };
466 - })(OriginalComponent);
467 - };
468 - (0, import_hooks.addFilter)(
469 - "editor.BlockListBlock",
470 - "core/annotations",
471 - addAnnotationClassName
472 - );
448 + (0, import_data3.register)(store);
473 449 return __toCommonJS(index_exports);
474 450 })();
475 451 //# sourceMappingURL=index.js.map