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