| | (() => { |
| | "use strict"; |
| | |
| | var __webpack_require__ = {}; |
| | |
| | |
| | |
| | (() => { |
| | |
| | __webpack_require__.d = (exports, definition) => { |
| | for(var key in definition) { |
| | if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
| | Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
| | } |
| | } |
| | }; |
| | })(); |
| | |
| | |
| | (() => { |
| | __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) |
| | })(); |
| | |
| | |
| | (() => { |
| | |
| | __webpack_require__.r = (exports) => { |
| | if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
| | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
| | } |
| | Object.defineProperty(exports, '__esModule', { value: true }); |
| | }; |
| | })(); |
| | |
| | |
| | var __webpack_exports__ = {}; |
| | |
| | __webpack_require__.r(__webpack_exports__); |
| |
|
| | |
| | __webpack_require__.d(__webpack_exports__, { |
| | store: () => ( store) |
| | }); |
| |
|
| | |
| | var selectors_namespaceObject = {}; |
| | __webpack_require__.r(selectors_namespaceObject); |
| | __webpack_require__.d(selectors_namespaceObject, { |
| | __experimentalGetAllAnnotationsForBlock: () => (__experimentalGetAllAnnotationsForBlock), |
| | __experimentalGetAnnotations: () => (__experimentalGetAnnotations), |
| | __experimentalGetAnnotationsForBlock: () => (__experimentalGetAnnotationsForBlock), |
| | __experimentalGetAnnotationsForRichText: () => (__experimentalGetAnnotationsForRichText) |
| | }); |
| |
|
| | |
| | var actions_namespaceObject = {}; |
| | __webpack_require__.r(actions_namespaceObject); |
| | __webpack_require__.d(actions_namespaceObject, { |
| | __experimentalAddAnnotation: () => (__experimentalAddAnnotation), |
| | __experimentalRemoveAnnotation: () => (__experimentalRemoveAnnotation), |
| | __experimentalRemoveAnnotationsBySource: () => (__experimentalRemoveAnnotationsBySource), |
| | __experimentalUpdateAnnotationRange: () => (__experimentalUpdateAnnotationRange) |
| | }); |
| |
|
| | ; |
| | const external_wp_richText_namespaceObject = window["wp"]["richText"]; |
| | ; |
| | const external_wp_i18n_namespaceObject = window["wp"]["i18n"]; |
| | ; |
| | |
| | |
| | |
| | |
| | |
| | const STORE_NAME = 'core/annotations'; |
| |
|
| | ; |
| | |
| | |
| | |
| |
|
| |
|
| | const FORMAT_NAME = 'core/annotation'; |
| | const ANNOTATION_ATTRIBUTE_PREFIX = 'annotation-text-'; |
| | |
| | |
| | |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | function applyAnnotations(record, annotations = []) { |
| | annotations.forEach(annotation => { |
| | let { |
| | start, |
| | end |
| | } = annotation; |
| | if (start > record.text.length) { |
| | start = record.text.length; |
| | } |
| | if (end > record.text.length) { |
| | end = record.text.length; |
| | } |
| | const className = ANNOTATION_ATTRIBUTE_PREFIX + annotation.source; |
| | const id = ANNOTATION_ATTRIBUTE_PREFIX + annotation.id; |
| | record = (0,external_wp_richText_namespaceObject.applyFormat)(record, { |
| | type: FORMAT_NAME, |
| | attributes: { |
| | className, |
| | id |
| | } |
| | }, start, end); |
| | }); |
| | return record; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | function removeAnnotations(record) { |
| | return removeFormat(record, 'core/annotation', 0, record.text.length); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | function retrieveAnnotationPositions(formats) { |
| | const positions = {}; |
| | formats.forEach((characterFormats, i) => { |
| | characterFormats = characterFormats || []; |
| | characterFormats = characterFormats.filter(format => format.type === FORMAT_NAME); |
| | characterFormats.forEach(format => { |
| | let { |
| | id |
| | } = format.attributes; |
| | id = id.replace(ANNOTATION_ATTRIBUTE_PREFIX, ''); |
| | if (!positions.hasOwnProperty(id)) { |
| | positions[id] = { |
| | start: i |
| | }; |
| | } |
| |
|
| | |
| | |
| | |
| | positions[id].end = i + 1; |
| | }); |
| | }); |
| | return positions; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | function updateAnnotationsWithPositions(annotations, positions, { |
| | removeAnnotation, |
| | updateAnnotationRange |
| | }) { |
| | annotations.forEach(currentAnnotation => { |
| | const position = positions[currentAnnotation.id]; |
| | |
| | if (!position) { |
| | |
| | |
| | removeAnnotation(currentAnnotation.id); |
| | return; |
| | } |
| | const { |
| | start, |
| | end |
| | } = currentAnnotation; |
| | if (start !== position.start || end !== position.end) { |
| | updateAnnotationRange(currentAnnotation.id, position.start, position.end); |
| | } |
| | }); |
| | } |
| | const annotation = { |
| | name: FORMAT_NAME, |
| | title: (0,external_wp_i18n_namespaceObject.__)('Annotation'), |
| | tagName: 'mark', |
| | className: 'annotation-text', |
| | attributes: { |
| | className: 'class', |
| | id: 'id' |
| | }, |
| | edit() { |
| | return null; |
| | }, |
| | __experimentalGetPropsForEditableTreePreparation(select, { |
| | richTextIdentifier, |
| | blockClientId |
| | }) { |
| | return { |
| | annotations: select(STORE_NAME).__experimentalGetAnnotationsForRichText(blockClientId, richTextIdentifier) |
| | }; |
| | }, |
| | __experimentalCreatePrepareEditableTree({ |
| | annotations |
| | }) { |
| | return (formats, text) => { |
| | if (annotations.length === 0) { |
| | return formats; |
| | } |
| | let record = { |
| | formats, |
| | text |
| | }; |
| | record = applyAnnotations(record, annotations); |
| | return record.formats; |
| | }; |
| | }, |
| | __experimentalGetPropsForEditableTreeChangeHandler(dispatch) { |
| | return { |
| | removeAnnotation: dispatch(STORE_NAME).__experimentalRemoveAnnotation, |
| | updateAnnotationRange: dispatch(STORE_NAME).__experimentalUpdateAnnotationRange |
| | }; |
| | }, |
| | __experimentalCreateOnChangeEditableValue(props) { |
| | return formats => { |
| | const positions = retrieveAnnotationPositions(formats); |
| | const { |
| | removeAnnotation, |
| | updateAnnotationRange, |
| | annotations |
| | } = props; |
| | updateAnnotationsWithPositions(annotations, positions, { |
| | removeAnnotation, |
| | updateAnnotationRange |
| | }); |
| | }; |
| | } |
| | }; |
| |
|
| | ; |
| | |
| | |
| | |
| |
|
| |
|
| | |
| | |
| | |
| |
|
| | const { |
| | name: format_name, |
| | ...settings |
| | } = annotation; |
| | (0,external_wp_richText_namespaceObject.registerFormatType)(format_name, settings); |
| |
|
| | ; |
| | const external_wp_hooks_namespaceObject = window["wp"]["hooks"]; |
| | ; |
| | const external_wp_data_namespaceObject = window["wp"]["data"]; |
| | ; |
| | |
| | |
| | |
| |
|
| |
|
| |
|
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | const addAnnotationClassName = OriginalComponent => { |
| | return (0,external_wp_data_namespaceObject.withSelect)((select, { |
| | clientId, |
| | className |
| | }) => { |
| | const annotations = select(STORE_NAME).__experimentalGetAnnotationsForBlock(clientId); |
| | return { |
| | className: annotations.map(annotation => { |
| | return 'is-annotated-by-' + annotation.source; |
| | }).concat(className).filter(Boolean).join(' ') |
| | }; |
| | })(OriginalComponent); |
| | }; |
| | (0,external_wp_hooks_namespaceObject.addFilter)('editor.BlockListBlock', 'core/annotations', addAnnotationClassName); |
| |
|
| | ; |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | function filterWithReference(collection, predicate) { |
| | const filteredCollection = collection.filter(predicate); |
| | return collection.length === filteredCollection.length ? collection : filteredCollection; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | const mapValues = (obj, callback) => Object.entries(obj).reduce((acc, [key, value]) => ({ |
| | ...acc, |
| | [key]: callback(value) |
| | }), {}); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | function isValidAnnotationRange(annotation) { |
| | return typeof annotation.start === 'number' && typeof annotation.end === 'number' && annotation.start <= annotation.end; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | function annotations(state = {}, action) { |
| | var _state$blockClientId; |
| | switch (action.type) { |
| | case 'ANNOTATION_ADD': |
| | const blockClientId = action.blockClientId; |
| | const newAnnotation = { |
| | id: action.id, |
| | blockClientId, |
| | richTextIdentifier: action.richTextIdentifier, |
| | source: action.source, |
| | selector: action.selector, |
| | range: action.range |
| | }; |
| | if (newAnnotation.selector === 'range' && !isValidAnnotationRange(newAnnotation.range)) { |
| | return state; |
| | } |
| | const previousAnnotationsForBlock = (_state$blockClientId = state?.[blockClientId]) !== null && _state$blockClientId !== void 0 ? _state$blockClientId : []; |
| | return { |
| | ...state, |
| | [blockClientId]: [...previousAnnotationsForBlock, newAnnotation] |
| | }; |
| | case 'ANNOTATION_REMOVE': |
| | return mapValues(state, annotationsForBlock => { |
| | return filterWithReference(annotationsForBlock, annotation => { |
| | return annotation.id !== action.annotationId; |
| | }); |
| | }); |
| | case 'ANNOTATION_UPDATE_RANGE': |
| | return mapValues(state, annotationsForBlock => { |
| | let hasChangedRange = false; |
| | const newAnnotations = annotationsForBlock.map(annotation => { |
| | if (annotation.id === action.annotationId) { |
| | hasChangedRange = true; |
| | return { |
| | ...annotation, |
| | range: { |
| | start: action.start, |
| | end: action.end |
| | } |
| | }; |
| | } |
| | return annotation; |
| | }); |
| | return hasChangedRange ? newAnnotations : annotationsForBlock; |
| | }); |
| | case 'ANNOTATION_REMOVE_SOURCE': |
| | return mapValues(state, annotationsForBlock => { |
| | return filterWithReference(annotationsForBlock, annotation => { |
| | return annotation.source !== action.source; |
| | }); |
| | }); |
| | } |
| | return state; |
| | } |
| | const reducer = (annotations); |
| |
|
| | ; |
| | |
| | |
| | |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | const EMPTY_ARRAY = []; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | const __experimentalGetAnnotationsForBlock = (0,external_wp_data_namespaceObject.createSelector)((state, blockClientId) => { |
| | var _state$blockClientId; |
| | return ((_state$blockClientId = state?.[blockClientId]) !== null && _state$blockClientId !== void 0 ? _state$blockClientId : []).filter(annotation => { |
| | return annotation.selector === 'block'; |
| | }); |
| | }, (state, blockClientId) => { |
| | var _state$blockClientId2; |
| | return [(_state$blockClientId2 = state?.[blockClientId]) !== null && _state$blockClientId2 !== void 0 ? _state$blockClientId2 : EMPTY_ARRAY]; |
| | }); |
| | function __experimentalGetAllAnnotationsForBlock(state, blockClientId) { |
| | var _state$blockClientId3; |
| | return (_state$blockClientId3 = state?.[blockClientId]) !== null && _state$blockClientId3 !== void 0 ? _state$blockClientId3 : EMPTY_ARRAY; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | const __experimentalGetAnnotationsForRichText = (0,external_wp_data_namespaceObject.createSelector)((state, blockClientId, richTextIdentifier) => { |
| | var _state$blockClientId4; |
| | return ((_state$blockClientId4 = state?.[blockClientId]) !== null && _state$blockClientId4 !== void 0 ? _state$blockClientId4 : []).filter(annotation => { |
| | return annotation.selector === 'range' && richTextIdentifier === annotation.richTextIdentifier; |
| | }).map(annotation => { |
| | const { |
| | range, |
| | ...other |
| | } = annotation; |
| | return { |
| | ...range, |
| | ...other |
| | }; |
| | }); |
| | }, (state, blockClientId) => { |
| | var _state$blockClientId5; |
| | return [(_state$blockClientId5 = state?.[blockClientId]) !== null && _state$blockClientId5 !== void 0 ? _state$blockClientId5 : EMPTY_ARRAY]; |
| | }); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | function __experimentalGetAnnotations(state) { |
| | return Object.values(state).flat(); |
| | } |
| |
|
| | ; |
| | const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto); |
| | const esm_browser_native = ({ |
| | randomUUID |
| | }); |
| | ; |
| | |
| | |
| | |
| | let getRandomValues; |
| | const rnds8 = new Uint8Array(16); |
| | function rng() { |
| | |
| | if (!getRandomValues) { |
| | |
| | getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto); |
| |
|
| | if (!getRandomValues) { |
| | throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported'); |
| | } |
| | } |
| |
|
| | return getRandomValues(rnds8); |
| | } |
| | ; |
| |
|
| | |
| | |
| | |
| | |
| |
|
| | const byteToHex = []; |
| |
|
| | for (let i = 0; i < 256; ++i) { |
| | byteToHex.push((i + 0x100).toString(16).slice(1)); |
| | } |
| |
|
| | function unsafeStringify(arr, offset = 0) { |
| | |
| | |
| | return 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]]; |
| | } |
| |
|
| | function stringify(arr, offset = 0) { |
| | const uuid = unsafeStringify(arr, offset); |
| | |
| | |
| | |
| | |
| |
|
| | if (!validate(uuid)) { |
| | throw TypeError('Stringified UUID is invalid'); |
| | } |
| |
|
| | return uuid; |
| | } |
| |
|
| | const esm_browser_stringify = (( null && (stringify))); |
| | ; |
| |
|
| |
|
| |
|
| |
|
| | function v4(options, buf, offset) { |
| | if (esm_browser_native.randomUUID && !buf && !options) { |
| | return esm_browser_native.randomUUID(); |
| | } |
| |
|
| | options = options || {}; |
| | const rnds = options.random || (options.rng || rng)(); |
| |
|
| | rnds[6] = rnds[6] & 0x0f | 0x40; |
| | rnds[8] = rnds[8] & 0x3f | 0x80; |
| |
|
| | if (buf) { |
| | offset = offset || 0; |
| |
|
| | for (let i = 0; i < 16; ++i) { |
| | buf[offset + i] = rnds[i]; |
| | } |
| |
|
| | return buf; |
| | } |
| |
|
| | return unsafeStringify(rnds); |
| | } |
| |
|
| | const esm_browser_v4 = (v4); |
| | ; |
| | |
| | |
| | |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | function __experimentalAddAnnotation({ |
| | blockClientId, |
| | richTextIdentifier = null, |
| | range = null, |
| | selector = 'range', |
| | source = 'default', |
| | id = esm_browser_v4() |
| | }) { |
| | const action = { |
| | type: 'ANNOTATION_ADD', |
| | id, |
| | blockClientId, |
| | richTextIdentifier, |
| | source, |
| | selector |
| | }; |
| | if (selector === 'range') { |
| | action.range = range; |
| | } |
| | return action; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | function __experimentalRemoveAnnotation(annotationId) { |
| | return { |
| | type: 'ANNOTATION_REMOVE', |
| | annotationId |
| | }; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | function __experimentalUpdateAnnotationRange(annotationId, start, end) { |
| | return { |
| | type: 'ANNOTATION_UPDATE_RANGE', |
| | annotationId, |
| | start, |
| | end |
| | }; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | function __experimentalRemoveAnnotationsBySource(source) { |
| | return { |
| | type: 'ANNOTATION_REMOVE_SOURCE', |
| | source |
| | }; |
| | } |
| |
|
| | ; |
| | |
| | |
| | |
| |
|
| |
|
| | |
| | |
| | |
| |
|
| |
|
| |
|
| |
|
| | |
| | |
| | |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, { |
| | reducer: reducer, |
| | selectors: selectors_namespaceObject, |
| | actions: actions_namespaceObject |
| | }); |
| | (0,external_wp_data_namespaceObject.register)(store); |
| |
|
| | ; |
| | |
| | |
| | |
| |
|
| |
|
| |
|
| |
|
| | (window.wp = window.wp || {}).annotations = __webpack_exports__; |
| | })() |
| | ; |