annotations.js 32 KB

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