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 +68 -88 23.2.222.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 = {};
@@ -353,43 +347,47 @@
353 347 __experimentalRemoveAnnotationsBySource: () => __experimentalRemoveAnnotationsBySource,
354 348 __experimentalUpdateAnnotationRange: () => __experimentalUpdateAnnotationRange
355 349 });
356 350
357 - // node_modules/uuid/dist/stringify.js
351 + // node_modules/uuid/dist/esm-browser/rng.js
352 + var getRandomValues;
353 + var rnds8 = new Uint8Array(16);
354 + function rng() {
355 + if (!getRandomValues) {
356 + getRandomValues = typeof crypto !== "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
357 + if (!getRandomValues) {
358 + throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
359 + }
360 + }
361 + return getRandomValues(rnds8);
362 + }
363 +
364 + // node_modules/uuid/dist/esm-browser/stringify.js
358 365 var byteToHex = [];
359 366 for (let i = 0; i < 256; ++i) {
360 367 byteToHex.push((i + 256).toString(16).slice(1));
361 368 }
362 369 function unsafeStringify(arr, offset = 0) {
363 - return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
370 + return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
364 371 }
365 372
366 - // node_modules/uuid/dist/rng.js
367 - var rnds8 = new Uint8Array(16);
368 - function rng() {
369 - return crypto.getRandomValues(rnds8);
370 - }
373 + // node_modules/uuid/dist/esm-browser/native.js
374 + var randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
375 + var native_default = {
376 + randomUUID
377 + };
371 378
372 - // node_modules/uuid/dist/v4.js
379 + // node_modules/uuid/dist/esm-browser/v4.js
373 380 function v4(options, buf, offset) {
374 - if (!buf && !options && crypto.randomUUID) {
375 - return crypto.randomUUID();
381 + if (native_default.randomUUID && !buf && !options) {
382 + return native_default.randomUUID();
376 383 }
377 - return _v4(options, buf, offset);
378 - }
379 - function _v4(options, buf, offset) {
380 384 options = options || {};
381 - const rnds = options.random ?? options.rng?.() ?? rng();
382 - if (rnds.length < 16) {
383 - throw new Error("Random bytes length must be >= 16");
384 - }
385 + const rnds = options.random || (options.rng || rng)();
385 386 rnds[6] = rnds[6] & 15 | 64;
386 387 rnds[8] = rnds[8] & 63 | 128;
387 388 if (buf) {
388 389 offset = offset || 0;
389 - if (offset < 0 || offset + 16 > buf.length) {
390 - throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
391 - }
392 390 for (let i = 0; i < 16; ++i) {
393 391 buf[offset + i] = rnds[i];
394 392 }
395 393 return buf;
@@ -414,9 +412,9 @@
414 412 richTextIdentifier,
415 413 source,
416 414 selector
417 415 };
418 - if (selector === "range" && range !== null) {
416 + if (selector === "range") {
419 417 action.range = range;
420 418 }
421 419 return action;
422 420 }
@@ -441,31 +439,13 @@
441 439 };
442 440 }
443 441
444 442 // packages/annotations/build-module/store/index.mjs
445 - var store = (0, import_data2.createReduxStore)(STORE_NAME, {
443 + var store = (0, import_data3.createReduxStore)(STORE_NAME, {
446 444 reducer: reducer_default,
447 445 selectors: selectors_exports,
448 446 actions: actions_exports
449 447 });
450 - (0, import_data2.register)(store);
451 -
452 - // packages/annotations/build-module/block/index.mjs
453 - var addAnnotationClassName = (OriginalComponent) => {
454 - return (0, import_data3.withSelect)((select, ownProps) => {
455 - const { clientId, className } = ownProps;
456 - const annotations2 = select(store).__experimentalGetAnnotationsForBlock(clientId);
457 - return {
458 - className: annotations2.map((annotation2) => {
459 - return "is-annotated-by-" + annotation2.source;
460 - }).concat(className || "").filter(Boolean).join(" ")
461 - };
462 - })(OriginalComponent);
463 - };
464 - (0, import_hooks.addFilter)(
465 - "editor.BlockListBlock",
466 - "core/annotations",
467 - addAnnotationClassName
468 - );
448 + (0, import_data3.register)(store);
469 449 return __toCommonJS(index_exports);
470 450 })();
471 451 //# sourceMappingURL=index.js.map