annotations.js 38 KB

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