PluginProbe
Gutenberg / 15.1.1
Gutenberg v15.1.1
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
gutenberg / build / annotations / index.js

index.js in Gutenberg 15.1.1, at build/annotations/index.js

1,053 lines 31.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /******/ (function() { // webpackBootstrap
2 /******/ "use strict";
3 /******/ // The require scope
4 /******/ var __webpack_require__ = {};
5 /******/
6 /************************************************************************/
7 /******/ /* webpack/runtime/define property getters */
8 /******/ !function() {
9 /******/ // define getter functions for harmony exports
10 /******/ __webpack_require__.d = function(exports, definition) {
11 /******/ for(var key in definition) {
12 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
13 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
14 /******/ }
15 /******/ }
16 /******/ };
17 /******/ }();
18 /******/
19 /******/ /* webpack/runtime/hasOwnProperty shorthand */
20 /******/ !function() {
21 /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
22 /******/ }();
23 /******/
24 /******/ /* webpack/runtime/make namespace object */
25 /******/ !function() {
26 /******/ // define __esModule on exports
27 /******/ __webpack_require__.r = function(exports) {
28 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
29 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
30 /******/ }
31 /******/ Object.defineProperty(exports, '__esModule', { value: true });
32 /******/ };
33 /******/ }();
34 /******/
35 /************************************************************************/
36 var __webpack_exports__ = {};
37 // ESM COMPAT FLAG
38 __webpack_require__.r(__webpack_exports__);
39
40 // EXPORTS
41 __webpack_require__.d(__webpack_exports__, {
42 "store": function() { return /* reexport */ store; }
43 });
44
45 // NAMESPACE OBJECT: ./packages/annotations/build-module/store/selectors.js
46 var selectors_namespaceObject = {};
47 __webpack_require__.r(selectors_namespaceObject);
48 __webpack_require__.d(selectors_namespaceObject, {
49 "__experimentalGetAllAnnotationsForBlock": function() { return __experimentalGetAllAnnotationsForBlock; },
50 "__experimentalGetAnnotations": function() { return __experimentalGetAnnotations; },
51 "__experimentalGetAnnotationsForBlock": function() { return __experimentalGetAnnotationsForBlock; },
52 "__experimentalGetAnnotationsForRichText": function() { return __experimentalGetAnnotationsForRichText; }
53 });
54
55 // NAMESPACE OBJECT: ./packages/annotations/build-module/store/actions.js
56 var actions_namespaceObject = {};
57 __webpack_require__.r(actions_namespaceObject);
58 __webpack_require__.d(actions_namespaceObject, {
59 "__experimentalAddAnnotation": function() { return __experimentalAddAnnotation; },
60 "__experimentalRemoveAnnotation": function() { return __experimentalRemoveAnnotation; },
61 "__experimentalRemoveAnnotationsBySource": function() { return __experimentalRemoveAnnotationsBySource; },
62 "__experimentalUpdateAnnotationRange": function() { return __experimentalUpdateAnnotationRange; }
63 });
64
65 ;// CONCATENATED MODULE: external ["wp","richText"]
66 var external_wp_richText_namespaceObject = window["wp"]["richText"];
67 ;// CONCATENATED MODULE: external ["wp","i18n"]
68 var external_wp_i18n_namespaceObject = window["wp"]["i18n"];
69 ;// CONCATENATED MODULE: ./packages/annotations/build-module/store/constants.js
70 /**
71 * The identifier for the data store.
72 *
73 * @type {string}
74 */
75 const STORE_NAME = 'core/annotations';
76
77 ;// CONCATENATED MODULE: ./packages/annotations/build-module/format/annotation.js
78 /**
79 * WordPress dependencies
80 */
81
82
83 const FORMAT_NAME = 'core/annotation';
84 const ANNOTATION_ATTRIBUTE_PREFIX = 'annotation-text-';
85 /**
86 * Internal dependencies
87 */
88
89
90 /**
91 * Applies given annotations to the given record.
92 *
93 * @param {Object} record The record to apply annotations to.
94 * @param {Array} annotations The annotation to apply.
95 * @return {Object} A record with the annotations applied.
96 */
97
98 function applyAnnotations(record) {
99 let annotations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
100 annotations.forEach(annotation => {
101 let {
102 start,
103 end
104 } = annotation;
105
106 if (start > record.text.length) {
107 start = record.text.length;
108 }
109
110 if (end > record.text.length) {
111 end = record.text.length;
112 }
113
114 const className = ANNOTATION_ATTRIBUTE_PREFIX + annotation.source;
115 const id = ANNOTATION_ATTRIBUTE_PREFIX + annotation.id;
116 record = (0,external_wp_richText_namespaceObject.applyFormat)(record, {
117 type: FORMAT_NAME,
118 attributes: {
119 className,
120 id
121 }
122 }, start, end);
123 });
124 return record;
125 }
126 /**
127 * Removes annotations from the given record.
128 *
129 * @param {Object} record Record to remove annotations from.
130 * @return {Object} The cleaned record.
131 */
132
133 function removeAnnotations(record) {
134 return removeFormat(record, 'core/annotation', 0, record.text.length);
135 }
136 /**
137 * Retrieves the positions of annotations inside an array of formats.
138 *
139 * @param {Array} formats Formats with annotations in there.
140 * @return {Object} ID keyed positions of annotations.
141 */
142
143 function retrieveAnnotationPositions(formats) {
144 const positions = {};
145 formats.forEach((characterFormats, i) => {
146 characterFormats = characterFormats || [];
147 characterFormats = characterFormats.filter(format => format.type === FORMAT_NAME);
148 characterFormats.forEach(format => {
149 let {
150 id
151 } = format.attributes;
152 id = id.replace(ANNOTATION_ATTRIBUTE_PREFIX, '');
153
154 if (!positions.hasOwnProperty(id)) {
155 positions[id] = {
156 start: i
157 };
158 } // Annotations refer to positions between characters.
159 // Formats refer to the character themselves.
160 // So we need to adjust for that here.
161
162
163 positions[id].end = i + 1;
164 });
165 });
166 return positions;
167 }
168 /**
169 * Updates annotations in the state based on positions retrieved from RichText.
170 *
171 * @param {Array} annotations The annotations that are currently applied.
172 * @param {Array} positions The current positions of the given annotations.
173 * @param {Object} actions
174 * @param {Function} actions.removeAnnotation Function to remove an annotation from the state.
175 * @param {Function} actions.updateAnnotationRange Function to update an annotation range in the state.
176 */
177
178
179 function updateAnnotationsWithPositions(annotations, positions, _ref) {
180 let {
181 removeAnnotation,
182 updateAnnotationRange
183 } = _ref;
184 annotations.forEach(currentAnnotation => {
185 const position = positions[currentAnnotation.id]; // If we cannot find an annotation, delete it.
186
187 if (!position) {
188 // Apparently the annotation has been removed, so remove it from the state:
189 // Remove...
190 removeAnnotation(currentAnnotation.id);
191 return;
192 }
193
194 const {
195 start,
196 end
197 } = currentAnnotation;
198
199 if (start !== position.start || end !== position.end) {
200 updateAnnotationRange(currentAnnotation.id, position.start, position.end);
201 }
202 });
203 }
204
205 const annotation = {
206 name: FORMAT_NAME,
207 title: (0,external_wp_i18n_namespaceObject.__)('Annotation'),
208 tagName: 'mark',
209 className: 'annotation-text',
210 attributes: {
211 className: 'class',
212 id: 'id'
213 },
214
215 edit() {
216 return null;
217 },
218
219 __experimentalGetPropsForEditableTreePreparation(select, _ref2) {
220 let {
221 richTextIdentifier,
222 blockClientId
223 } = _ref2;
224 return {
225 annotations: select(STORE_NAME).__experimentalGetAnnotationsForRichText(blockClientId, richTextIdentifier)
226 };
227 },
228
229 __experimentalCreatePrepareEditableTree(_ref3) {
230 let {
231 annotations
232 } = _ref3;
233 return (formats, text) => {
234 if (annotations.length === 0) {
235 return formats;
236 }
237
238 let record = {
239 formats,
240 text
241 };
242 record = applyAnnotations(record, annotations);
243 return record.formats;
244 };
245 },
246
247 __experimentalGetPropsForEditableTreeChangeHandler(dispatch) {
248 return {
249 removeAnnotation: dispatch(STORE_NAME).__experimentalRemoveAnnotation,
250 updateAnnotationRange: dispatch(STORE_NAME).__experimentalUpdateAnnotationRange
251 };
252 },
253
254 __experimentalCreateOnChangeEditableValue(props) {
255 return formats => {
256 const positions = retrieveAnnotationPositions(formats);
257 const {
258 removeAnnotation,
259 updateAnnotationRange,
260 annotations
261 } = props;
262 updateAnnotationsWithPositions(annotations, positions, {
263 removeAnnotation,
264 updateAnnotationRange
265 });
266 };
267 }
268
269 };
270
271 ;// CONCATENATED MODULE: ./packages/annotations/build-module/format/index.js
272 /**
273 * WordPress dependencies
274 */
275
276 /**
277 * Internal dependencies
278 */
279
280
281 const {
282 name: format_name,
283 ...settings
284 } = annotation;
285 (0,external_wp_richText_namespaceObject.registerFormatType)(format_name, settings);
286
287 ;// CONCATENATED MODULE: external ["wp","hooks"]
288 var external_wp_hooks_namespaceObject = window["wp"]["hooks"];
289 ;// CONCATENATED MODULE: external ["wp","data"]
290 var external_wp_data_namespaceObject = window["wp"]["data"];
291 ;// CONCATENATED MODULE: ./packages/annotations/build-module/block/index.js
292 /**
293 * WordPress dependencies
294 */
295
296
297 /**
298 * Internal dependencies
299 */
300
301
302 /**
303 * Adds annotation className to the block-list-block component.
304 *
305 * @param {Object} OriginalComponent The original BlockListBlock component.
306 * @return {Object} The enhanced component.
307 */
308
309 const addAnnotationClassName = OriginalComponent => {
310 return (0,external_wp_data_namespaceObject.withSelect)((select, _ref) => {
311 let {
312 clientId,
313 className
314 } = _ref;
315
316 const annotations = select(STORE_NAME).__experimentalGetAnnotationsForBlock(clientId);
317
318 return {
319 className: annotations.map(annotation => {
320 return 'is-annotated-by-' + annotation.source;
321 }).concat(className).filter(Boolean).join(' ')
322 };
323 })(OriginalComponent);
324 };
325
326 (0,external_wp_hooks_namespaceObject.addFilter)('editor.BlockListBlock', 'core/annotations', addAnnotationClassName);
327
328 ;// CONCATENATED MODULE: ./packages/annotations/build-module/store/reducer.js
329 /**
330 * Filters an array based on the predicate, but keeps the reference the same if
331 * the array hasn't changed.
332 *
333 * @param {Array} collection The collection to filter.
334 * @param {Function} predicate Function that determines if the item should stay
335 * in the array.
336 * @return {Array} Filtered array.
337 */
338 function filterWithReference(collection, predicate) {
339 const filteredCollection = collection.filter(predicate);
340 return collection.length === filteredCollection.length ? collection : filteredCollection;
341 }
342 /**
343 * Creates a new object with the same keys, but with `callback()` called as
344 * a transformer function on each of the values.
345 *
346 * @param {Object} obj The object to transform.
347 * @param {Function} callback The function to transform each object value.
348 * @return {Array} Transformed object.
349 */
350
351
352 const mapValues = (obj, callback) => Object.entries(obj).reduce((acc, _ref) => {
353 let [key, value] = _ref;
354 return { ...acc,
355 [key]: callback(value)
356 };
357 }, {});
358 /**
359 * Verifies whether the given annotations is a valid annotation.
360 *
361 * @param {Object} annotation The annotation to verify.
362 * @return {boolean} Whether the given annotation is valid.
363 */
364
365
366 function isValidAnnotationRange(annotation) {
367 return typeof annotation.start === 'number' && typeof annotation.end === 'number' && annotation.start <= annotation.end;
368 }
369 /**
370 * Reducer managing annotations.
371 *
372 * @param {Object} state The annotations currently shown in the editor.
373 * @param {Object} action Dispatched action.
374 *
375 * @return {Array} Updated state.
376 */
377
378
379 function annotations() {
380 var _state$blockClientId;
381
382 let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
383 let action = arguments.length > 1 ? arguments[1] : undefined;
384
385 switch (action.type) {
386 case 'ANNOTATION_ADD':
387 const blockClientId = action.blockClientId;
388 const newAnnotation = {
389 id: action.id,
390 blockClientId,
391 richTextIdentifier: action.richTextIdentifier,
392 source: action.source,
393 selector: action.selector,
394 range: action.range
395 };
396
397 if (newAnnotation.selector === 'range' && !isValidAnnotationRange(newAnnotation.range)) {
398 return state;
399 }
400
401 const previousAnnotationsForBlock = (_state$blockClientId = state === null || state === void 0 ? void 0 : state[blockClientId]) !== null && _state$blockClientId !== void 0 ? _state$blockClientId : [];
402 return { ...state,
403 [blockClientId]: [...previousAnnotationsForBlock, newAnnotation]
404 };
405
406 case 'ANNOTATION_REMOVE':
407 return mapValues(state, annotationsForBlock => {
408 return filterWithReference(annotationsForBlock, annotation => {
409 return annotation.id !== action.annotationId;
410 });
411 });
412
413 case 'ANNOTATION_UPDATE_RANGE':
414 return mapValues(state, annotationsForBlock => {
415 let hasChangedRange = false;
416 const newAnnotations = annotationsForBlock.map(annotation => {
417 if (annotation.id === action.annotationId) {
418 hasChangedRange = true;
419 return { ...annotation,
420 range: {
421 start: action.start,
422 end: action.end
423 }
424 };
425 }
426
427 return annotation;
428 });
429 return hasChangedRange ? newAnnotations : annotationsForBlock;
430 });
431
432 case 'ANNOTATION_REMOVE_SOURCE':
433 return mapValues(state, annotationsForBlock => {
434 return filterWithReference(annotationsForBlock, annotation => {
435 return annotation.source !== action.source;
436 });
437 });
438 }
439
440 return state;
441 }
442 /* harmony default export */ var reducer = (annotations);
443
444 ;// CONCATENATED MODULE: ./node_modules/rememo/es/rememo.js
445
446
447 /** @typedef {(...args: any[]) => *[]} GetDependants */
448
449 /** @typedef {() => void} Clear */
450
451 /**
452 * @typedef {{
453 * getDependants: GetDependants,
454 * clear: Clear
455 * }} EnhancedSelector
456 */
457
458 /**
459 * Internal cache entry.
460 *
461 * @typedef CacheNode
462 *
463 * @property {?CacheNode|undefined} [prev] Previous node.
464 * @property {?CacheNode|undefined} [next] Next node.
465 * @property {*[]} args Function arguments for cache entry.
466 * @property {*} val Function result.
467 */
468
469 /**
470 * @typedef Cache
471 *
472 * @property {Clear} clear Function to clear cache.
473 * @property {boolean} [isUniqueByDependants] Whether dependants are valid in
474 * considering cache uniqueness. A cache is unique if dependents are all arrays
475 * or objects.
476 * @property {CacheNode?} [head] Cache head.
477 * @property {*[]} [lastDependants] Dependants from previous invocation.
478 */
479
480 /**
481 * Arbitrary value used as key for referencing cache object in WeakMap tree.
482 *
483 * @type {{}}
484 */
485 var LEAF_KEY = {};
486
487 /**
488 * Returns the first argument as the sole entry in an array.
489 *
490 * @template T
491 *
492 * @param {T} value Value to return.
493 *
494 * @return {[T]} Value returned as entry in array.
495 */
496 function arrayOf(value) {
497 return [value];
498 }
499
500 /**
501 * Returns true if the value passed is object-like, or false otherwise. A value
502 * is object-like if it can support property assignment, e.g. object or array.
503 *
504 * @param {*} value Value to test.
505 *
506 * @return {boolean} Whether value is object-like.
507 */
508 function isObjectLike(value) {
509 return !!value && 'object' === typeof value;
510 }
511
512 /**
513 * Creates and returns a new cache object.
514 *
515 * @return {Cache} Cache object.
516 */
517 function createCache() {
518 /** @type {Cache} */
519 var cache = {
520 clear: function () {
521 cache.head = null;
522 },
523 };
524
525 return cache;
526 }
527
528 /**
529 * Returns true if entries within the two arrays are strictly equal by
530 * reference from a starting index.
531 *
532 * @param {*[]} a First array.
533 * @param {*[]} b Second array.
534 * @param {number} fromIndex Index from which to start comparison.
535 *
536 * @return {boolean} Whether arrays are shallowly equal.
537 */
538 function isShallowEqual(a, b, fromIndex) {
539 var i;
540
541 if (a.length !== b.length) {
542 return false;
543 }
544
545 for (i = fromIndex; i < a.length; i++) {
546 if (a[i] !== b[i]) {
547 return false;
548 }
549 }
550
551 return true;
552 }
553
554 /**
555 * Returns a memoized selector function. The getDependants function argument is
556 * called before the memoized selector and is expected to return an immutable
557 * reference or array of references on which the selector depends for computing
558 * its own return value. The memoize cache is preserved only as long as those
559 * dependant references remain the same. If getDependants returns a different
560 * reference(s), the cache is cleared and the selector value regenerated.
561 *
562 * @template {(...args: *[]) => *} S
563 *
564 * @param {S} selector Selector function.
565 * @param {GetDependants=} getDependants Dependant getter returning an array of
566 * references used in cache bust consideration.
567 */
568 /* harmony default export */ function rememo(selector, getDependants) {
569 /** @type {WeakMap<*,*>} */
570 var rootCache;
571
572 /** @type {GetDependants} */
573 var normalizedGetDependants = getDependants ? getDependants : arrayOf;
574
575 /**
576 * Returns the cache for a given dependants array. When possible, a WeakMap
577 * will be used to create a unique cache for each set of dependants. This
578 * is feasible due to the nature of WeakMap in allowing garbage collection
579 * to occur on entries where the key object is no longer referenced. Since
580 * WeakMap requires the key to be an object, this is only possible when the
581 * dependant is object-like. The root cache is created as a hierarchy where
582 * each top-level key is the first entry in a dependants set, the value a
583 * WeakMap where each key is the next dependant, and so on. This continues
584 * so long as the dependants are object-like. If no dependants are object-
585 * like, then the cache is shared across all invocations.
586 *
587 * @see isObjectLike
588 *
589 * @param {*[]} dependants Selector dependants.
590 *
591 * @return {Cache} Cache object.
592 */
593 function getCache(dependants) {
594 var caches = rootCache,
595 isUniqueByDependants = true,
596 i,
597 dependant,
598 map,
599 cache;
600
601 for (i = 0; i < dependants.length; i++) {
602 dependant = dependants[i];
603
604 // Can only compose WeakMap from object-like key.
605 if (!isObjectLike(dependant)) {
606 isUniqueByDependants = false;
607 break;
608 }
609
610 // Does current segment of cache already have a WeakMap?
611 if (caches.has(dependant)) {
612 // Traverse into nested WeakMap.
613 caches = caches.get(dependant);
614 } else {
615 // Create, set, and traverse into a new one.
616 map = new WeakMap();
617 caches.set(dependant, map);
618 caches = map;
619 }
620 }
621
622 // We use an arbitrary (but consistent) object as key for the last item
623 // in the WeakMap to serve as our running cache.
624 if (!caches.has(LEAF_KEY)) {
625 cache = createCache();
626 cache.isUniqueByDependants = isUniqueByDependants;
627 caches.set(LEAF_KEY, cache);
628 }
629
630 return caches.get(LEAF_KEY);
631 }
632
633 /**
634 * Resets root memoization cache.
635 */
636 function clear() {
637 rootCache = new WeakMap();
638 }
639
640 /* eslint-disable jsdoc/check-param-names */
641 /**
642 * The augmented selector call, considering first whether dependants have
643 * changed before passing it to underlying memoize function.
644 *
645 * @param {*} source Source object for derivation.
646 * @param {...*} extraArgs Additional arguments to pass to selector.
647 *
648 * @return {*} Selector result.
649 */
650 /* eslint-enable jsdoc/check-param-names */
651 function callSelector(/* source, ...extraArgs */) {
652 var len = arguments.length,
653 cache,
654 node,
655 i,
656 args,
657 dependants;
658
659 // Create copy of arguments (avoid leaking deoptimization).
660 args = new Array(len);
661 for (i = 0; i < len; i++) {
662 args[i] = arguments[i];
663 }
664
665 dependants = normalizedGetDependants.apply(null, args);
666 cache = getCache(dependants);
667
668 // If not guaranteed uniqueness by dependants (primitive type), shallow
669 // compare against last dependants and, if references have changed,
670 // destroy cache to recalculate result.
671 if (!cache.isUniqueByDependants) {
672 if (
673 cache.lastDependants &&
674 !isShallowEqual(dependants, cache.lastDependants, 0)
675 ) {
676 cache.clear();
677 }
678
679 cache.lastDependants = dependants;
680 }
681
682 node = cache.head;
683 while (node) {
684 // Check whether node arguments match arguments
685 if (!isShallowEqual(node.args, args, 1)) {
686 node = node.next;
687 continue;
688 }
689
690 // At this point we can assume we've found a match
691
692 // Surface matched node to head if not already
693 if (node !== cache.head) {
694 // Adjust siblings to point to each other.
695 /** @type {CacheNode} */ (node.prev).next = node.next;
696 if (node.next) {
697 node.next.prev = node.prev;
698 }
699
700 node.next = cache.head;
701 node.prev = null;
702 /** @type {CacheNode} */ (cache.head).prev = node;
703 cache.head = node;
704 }
705
706 // Return immediately
707 return node.val;
708 }
709
710 // No cached value found. Continue to insertion phase:
711
712 node = /** @type {CacheNode} */ ({
713 // Generate the result from original function
714 val: selector.apply(null, args),
715 });
716
717 // Avoid including the source object in the cache.
718 args[0] = null;
719 node.args = args;
720
721 // Don't need to check whether node is already head, since it would
722 // have been returned above already if it was
723
724 // Shift existing head down list
725 if (cache.head) {
726 cache.head.prev = node;
727 node.next = cache.head;
728 }
729
730 cache.head = node;
731
732 return node.val;
733 }
734
735 callSelector.getDependants = normalizedGetDependants;
736 callSelector.clear = clear;
737 clear();
738
739 return /** @type {S & EnhancedSelector} */ (callSelector);
740 }
741
742 ;// CONCATENATED MODULE: ./packages/annotations/build-module/store/selectors.js
743 /**
744 * External dependencies
745 */
746
747 /**
748 * Shared reference to an empty array for cases where it is important to avoid
749 * returning a new array reference on every invocation, as in a connected or
750 * other pure component which performs `shouldComponentUpdate` check on props.
751 * This should be used as a last resort, since the normalized data should be
752 * maintained by the reducer result in state.
753 *
754 * @type {Array}
755 */
756
757 const EMPTY_ARRAY = [];
758 /**
759 * Returns the annotations for a specific client ID.
760 *
761 * @param {Object} state Editor state.
762 * @param {string} clientId The ID of the block to get the annotations for.
763 *
764 * @return {Array} The annotations applicable to this block.
765 */
766
767 const __experimentalGetAnnotationsForBlock = rememo((state, blockClientId) => {
768 var _state$blockClientId;
769
770 return ((_state$blockClientId = state === null || state === void 0 ? void 0 : state[blockClientId]) !== null && _state$blockClientId !== void 0 ? _state$blockClientId : []).filter(annotation => {
771 return annotation.selector === 'block';
772 });
773 }, (state, blockClientId) => {
774 var _state$blockClientId2;
775
776 return [(_state$blockClientId2 = state === null || state === void 0 ? void 0 : state[blockClientId]) !== null && _state$blockClientId2 !== void 0 ? _state$blockClientId2 : EMPTY_ARRAY];
777 });
778 function __experimentalGetAllAnnotationsForBlock(state, blockClientId) {
779 var _state$blockClientId3;
780
781 return (_state$blockClientId3 = state === null || state === void 0 ? void 0 : state[blockClientId]) !== null && _state$blockClientId3 !== void 0 ? _state$blockClientId3 : EMPTY_ARRAY;
782 }
783 /**
784 * Returns the annotations that apply to the given RichText instance.
785 *
786 * Both a blockClientId and a richTextIdentifier are required. This is because
787 * a block might have multiple `RichText` components. This does mean that every
788 * block needs to implement annotations itself.
789 *
790 * @param {Object} state Editor state.
791 * @param {string} blockClientId The client ID for the block.
792 * @param {string} richTextIdentifier Unique identifier that identifies the given RichText.
793 * @return {Array} All the annotations relevant for the `RichText`.
794 */
795
796 const __experimentalGetAnnotationsForRichText = rememo((state, blockClientId, richTextIdentifier) => {
797 var _state$blockClientId4;
798
799 return ((_state$blockClientId4 = state === null || state === void 0 ? void 0 : state[blockClientId]) !== null && _state$blockClientId4 !== void 0 ? _state$blockClientId4 : []).filter(annotation => {
800 return annotation.selector === 'range' && richTextIdentifier === annotation.richTextIdentifier;
801 }).map(annotation => {
802 const {
803 range,
804 ...other
805 } = annotation;
806 return { ...range,
807 ...other
808 };
809 });
810 }, (state, blockClientId) => {
811 var _state$blockClientId5;
812
813 return [(_state$blockClientId5 = state === null || state === void 0 ? void 0 : state[blockClientId]) !== null && _state$blockClientId5 !== void 0 ? _state$blockClientId5 : EMPTY_ARRAY];
814 });
815 /**
816 * Returns all annotations in the editor state.
817 *
818 * @param {Object} state Editor state.
819 * @return {Array} All annotations currently applied.
820 */
821
822 function __experimentalGetAnnotations(state) {
823 return Object.values(state).flat();
824 }
825
826 ;// CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/rng.js
827 // Unique ID creation requires a high quality random # generator. In the browser we therefore
828 // require the crypto API and do not support built-in fallback to lower quality random number
829 // generators (like Math.random()).
830 // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also,
831 // find the complete implementation of crypto (msCrypto) on IE11.
832 var getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);
833 var rnds8 = new Uint8Array(16);
834 function rng() {
835 if (!getRandomValues) {
836 throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
837 }
838
839 return getRandomValues(rnds8);
840 }
841 ;// CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/regex.js
842 /* harmony default export */ var regex = (/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i);
843 ;// CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/validate.js
844
845
846 function validate(uuid) {
847 return typeof uuid === 'string' && regex.test(uuid);
848 }
849
850 /* harmony default export */ var esm_browser_validate = (validate);
851 ;// CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/stringify.js
852
853 /**
854 * Convert array of 16 byte values to UUID string format of the form:
855 * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
856 */
857
858 var byteToHex = [];
859
860 for (var i = 0; i < 256; ++i) {
861 byteToHex.push((i + 0x100).toString(16).substr(1));
862 }
863
864 function stringify(arr) {
865 var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
866 // Note: Be careful editing this code! It's been tuned for performance
867 // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
868 var uuid = (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(); // Consistency check for valid UUID. If this throws, it's likely due to one
869 // of the following:
870 // - One or more input array values don't map to a hex octet (leading to
871 // "undefined" in the uuid)
872 // - Invalid input values for the RFC `version` or `variant` fields
873
874 if (!esm_browser_validate(uuid)) {
875 throw TypeError('Stringified UUID is invalid');
876 }
877
878 return uuid;
879 }
880
881 /* harmony default export */ var esm_browser_stringify = (stringify);
882 ;// CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/v4.js
883
884
885
886 function v4(options, buf, offset) {
887 options = options || {};
888 var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
889
890 rnds[6] = rnds[6] & 0x0f | 0x40;
891 rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
892
893 if (buf) {
894 offset = offset || 0;
895
896 for (var i = 0; i < 16; ++i) {
897 buf[offset + i] = rnds[i];
898 }
899
900 return buf;
901 }
902
903 return esm_browser_stringify(rnds);
904 }
905
906 /* harmony default export */ var esm_browser_v4 = (v4);
907 ;// CONCATENATED MODULE: ./packages/annotations/build-module/store/actions.js
908 /**
909 * External dependencies
910 */
911
912 /**
913 * @typedef WPAnnotationRange
914 *
915 * @property {number} start The offset where the annotation should start.
916 * @property {number} end The offset where the annotation should end.
917 */
918
919 /**
920 * Adds an annotation to a block.
921 *
922 * The `block` attribute refers to a block ID that needs to be annotated.
923 * `isBlockAnnotation` controls whether or not the annotation is a block
924 * annotation. The `source` is the source of the annotation, this will be used
925 * to identity groups of annotations.
926 *
927 * The `range` property is only relevant if the selector is 'range'.
928 *
929 * @param {Object} annotation The annotation to add.
930 * @param {string} annotation.blockClientId The blockClientId to add the annotation to.
931 * @param {string} annotation.richTextIdentifier Identifier for the RichText instance the annotation applies to.
932 * @param {WPAnnotationRange} annotation.range The range at which to apply this annotation.
933 * @param {string} [annotation.selector="range"] The way to apply this annotation.
934 * @param {string} [annotation.source="default"] The source that added the annotation.
935 * @param {string} [annotation.id] The ID the annotation should have. Generates a UUID by default.
936 *
937 * @return {Object} Action object.
938 */
939
940 function __experimentalAddAnnotation(_ref) {
941 let {
942 blockClientId,
943 richTextIdentifier = null,
944 range = null,
945 selector = 'range',
946 source = 'default',
947 id = esm_browser_v4()
948 } = _ref;
949 const action = {
950 type: 'ANNOTATION_ADD',
951 id,
952 blockClientId,
953 richTextIdentifier,
954 source,
955 selector
956 };
957
958 if (selector === 'range') {
959 action.range = range;
960 }
961
962 return action;
963 }
964 /**
965 * Removes an annotation with a specific ID.
966 *
967 * @param {string} annotationId The annotation to remove.
968 *
969 * @return {Object} Action object.
970 */
971
972 function __experimentalRemoveAnnotation(annotationId) {
973 return {
974 type: 'ANNOTATION_REMOVE',
975 annotationId
976 };
977 }
978 /**
979 * Updates the range of an annotation.
980 *
981 * @param {string} annotationId ID of the annotation to update.
982 * @param {number} start The start of the new range.
983 * @param {number} end The end of the new range.
984 *
985 * @return {Object} Action object.
986 */
987
988 function __experimentalUpdateAnnotationRange(annotationId, start, end) {
989 return {
990 type: 'ANNOTATION_UPDATE_RANGE',
991 annotationId,
992 start,
993 end
994 };
995 }
996 /**
997 * Removes all annotations of a specific source.
998 *
999 * @param {string} source The source to remove.
1000 *
1001 * @return {Object} Action object.
1002 */
1003
1004 function __experimentalRemoveAnnotationsBySource(source) {
1005 return {
1006 type: 'ANNOTATION_REMOVE_SOURCE',
1007 source
1008 };
1009 }
1010
1011 ;// CONCATENATED MODULE: ./packages/annotations/build-module/store/index.js
1012 /**
1013 * WordPress dependencies
1014 */
1015
1016 /**
1017 * Internal dependencies
1018 */
1019
1020
1021
1022
1023 /**
1024 * Module Constants
1025 */
1026
1027
1028 /**
1029 * Store definition for the annotations namespace.
1030 *
1031 * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
1032 *
1033 * @type {Object}
1034 */
1035
1036 const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, {
1037 reducer: reducer,
1038 selectors: selectors_namespaceObject,
1039 actions: actions_namespaceObject
1040 });
1041 (0,external_wp_data_namespaceObject.register)(store);
1042
1043 ;// CONCATENATED MODULE: ./packages/annotations/build-module/index.js
1044 /**
1045 * Internal dependencies
1046 */
1047
1048
1049
1050
1051 (window.wp = window.wp || {}).annotations = __webpack_exports__;
1052 /******/ })()
1053 ;