Brak opisu

annotations.js 34KB

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