You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1013 lines
31 KiB

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