annotations.js 31 KB

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