| 1 |
var wp; |
| 2 |
(wp ||= {}).annotations = (() => { |
| 3 |
var __create = Object.create; |
| 4 |
var __defProp = Object.defineProperty; |
| 5 |
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; |
| 6 |
var __getOwnPropNames = Object.getOwnPropertyNames; |
| 7 |
var __getProtoOf = Object.getPrototypeOf; |
| 8 |
var __hasOwnProp = Object.prototype.hasOwnProperty; |
| 9 |
var __commonJS = (cb, mod) => function __require() { |
| 10 |
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; |
| 11 |
}; |
| 12 |
var __export = (target, all) => { |
| 13 |
for (var name2 in all) |
| 14 |
__defProp(target, name2, { get: all[name2], enumerable: true }); |
| 15 |
}; |
| 16 |
var __copyProps = (to, from, except, desc) => { |
| 17 |
if (from && typeof from === "object" || typeof from === "function") { |
| 18 |
for (let key of __getOwnPropNames(from)) |
| 19 |
if (!__hasOwnProp.call(to, key) && key !== except) |
| 20 |
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); |
| 21 |
} |
| 22 |
return to; |
| 23 |
}; |
| 24 |
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( |
| 25 |
// If the importer is in node compatibility mode or this is not an ESM |
| 26 |
// file that has been converted to a CommonJS file using a Babel- |
| 27 |
// compatible transform (i.e. "__esModule" has not been set), then set |
| 28 |
// "default" to the CommonJS "module.exports" for node compatibility. |
| 29 |
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, |
| 30 |
mod |
| 31 |
)); |
| 32 |
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); |
| 33 |
|
| 34 |
// package-external:@wordpress/rich-text |
| 35 |
var require_rich_text = __commonJS({ |
| 36 |
"package-external:@wordpress/rich-text"(exports, module) { |
| 37 |
module.exports = window.wp.richText; |
| 38 |
} |
| 39 |
}); |
| 40 |
|
| 41 |
// package-external:@wordpress/i18n |
| 42 |
var require_i18n = __commonJS({ |
| 43 |
"package-external:@wordpress/i18n"(exports, module) { |
| 44 |
module.exports = window.wp.i18n; |
| 45 |
} |
| 46 |
}); |
| 47 |
|
| 48 |
// package-external:@wordpress/hooks |
| 49 |
var require_hooks = __commonJS({ |
| 50 |
"package-external:@wordpress/hooks"(exports, module) { |
| 51 |
module.exports = window.wp.hooks; |
| 52 |
} |
| 53 |
}); |
| 54 |
|
| 55 |
// package-external:@wordpress/data |
| 56 |
var require_data = __commonJS({ |
| 57 |
"package-external:@wordpress/data"(exports, module) { |
| 58 |
module.exports = window.wp.data; |
| 59 |
} |
| 60 |
}); |
| 61 |
|
| 62 |
// packages/annotations/build-module/index.mjs |
| 63 |
var index_exports = {}; |
| 64 |
__export(index_exports, { |
| 65 |
store: () => store |
| 66 |
}); |
| 67 |
|
| 68 |
// packages/annotations/build-module/format/index.mjs |
| 69 |
var import_rich_text2 = __toESM(require_rich_text(), 1); |
| 70 |
|
| 71 |
// packages/annotations/build-module/format/annotation.mjs |
| 72 |
var import_i18n = __toESM(require_i18n(), 1); |
| 73 |
var import_rich_text = __toESM(require_rich_text(), 1); |
| 74 |
|
| 75 |
// packages/annotations/build-module/store/constants.mjs |
| 76 |
var STORE_NAME = "core/annotations"; |
| 77 |
|
| 78 |
// packages/annotations/build-module/format/annotation.mjs |
| 79 |
var FORMAT_NAME = "core/annotation"; |
| 80 |
var ANNOTATION_ATTRIBUTE_PREFIX = "annotation-text-"; |
| 81 |
function applyAnnotations(record, annotations2 = []) { |
| 82 |
annotations2.forEach((annotation2) => { |
| 83 |
let { start, end } = annotation2; |
| 84 |
if (start > record.text.length) { |
| 85 |
start = record.text.length; |
| 86 |
} |
| 87 |
if (end > record.text.length) { |
| 88 |
end = record.text.length; |
| 89 |
} |
| 90 |
const className = ANNOTATION_ATTRIBUTE_PREFIX + annotation2.source; |
| 91 |
const id = ANNOTATION_ATTRIBUTE_PREFIX + annotation2.id; |
| 92 |
record = (0, import_rich_text.applyFormat)( |
| 93 |
record, |
| 94 |
{ |
| 95 |
type: FORMAT_NAME, |
| 96 |
attributes: { |
| 97 |
className, |
| 98 |
id |
| 99 |
} |
| 100 |
}, |
| 101 |
start, |
| 102 |
end |
| 103 |
); |
| 104 |
}); |
| 105 |
return record; |
| 106 |
} |
| 107 |
function retrieveAnnotationPositions(formats) { |
| 108 |
const positions = {}; |
| 109 |
formats.forEach((characterFormats, i) => { |
| 110 |
characterFormats = characterFormats || []; |
| 111 |
characterFormats = characterFormats.filter( |
| 112 |
(format) => format.type === FORMAT_NAME |
| 113 |
); |
| 114 |
characterFormats.forEach((format) => { |
| 115 |
let { id } = format.attributes; |
| 116 |
id = id.replace(ANNOTATION_ATTRIBUTE_PREFIX, ""); |
| 117 |
if (!positions.hasOwnProperty(id)) { |
| 118 |
positions[id] = { |
| 119 |
start: i |
| 120 |
}; |
| 121 |
} |
| 122 |
positions[id].end = i + 1; |
| 123 |
}); |
| 124 |
}); |
| 125 |
return positions; |
| 126 |
} |
| 127 |
function updateAnnotationsWithPositions(annotations2, positions, { removeAnnotation, updateAnnotationRange }) { |
| 128 |
annotations2.forEach((currentAnnotation) => { |
| 129 |
const position = positions[currentAnnotation.id]; |
| 130 |
if (!position) { |
| 131 |
removeAnnotation(currentAnnotation.id); |
| 132 |
return; |
| 133 |
} |
| 134 |
const { start, end } = currentAnnotation; |
| 135 |
if (start !== position.start || end !== position.end) { |
| 136 |
updateAnnotationRange( |
| 137 |
currentAnnotation.id, |
| 138 |
position.start, |
| 139 |
position.end |
| 140 |
); |
| 141 |
} |
| 142 |
}); |
| 143 |
} |
| 144 |
var annotation = { |
| 145 |
name: FORMAT_NAME, |
| 146 |
title: (0, import_i18n.__)("Annotation"), |
| 147 |
tagName: "mark", |
| 148 |
className: "annotation-text", |
| 149 |
attributes: { |
| 150 |
className: "class", |
| 151 |
id: "id" |
| 152 |
}, |
| 153 |
edit() { |
| 154 |
return null; |
| 155 |
}, |
| 156 |
__experimentalGetPropsForEditableTreePreparation(select, { richTextIdentifier, blockClientId }) { |
| 157 |
return { |
| 158 |
annotations: select( |
| 159 |
STORE_NAME |
| 160 |
).__experimentalGetAnnotationsForRichText( |
| 161 |
blockClientId, |
| 162 |
richTextIdentifier |
| 163 |
) |
| 164 |
}; |
| 165 |
}, |
| 166 |
__experimentalCreatePrepareEditableTree({ annotations: annotations2 }) { |
| 167 |
return (formats, text) => { |
| 168 |
if (annotations2.length === 0) { |
| 169 |
return formats; |
| 170 |
} |
| 171 |
let record = { formats, text }; |
| 172 |
record = applyAnnotations(record, annotations2); |
| 173 |
return record.formats; |
| 174 |
}; |
| 175 |
}, |
| 176 |
__experimentalGetPropsForEditableTreeChangeHandler(dispatch) { |
| 177 |
return { |
| 178 |
removeAnnotation: dispatch(STORE_NAME).__experimentalRemoveAnnotation, |
| 179 |
updateAnnotationRange: dispatch(STORE_NAME).__experimentalUpdateAnnotationRange |
| 180 |
}; |
| 181 |
}, |
| 182 |
__experimentalCreateOnChangeEditableValue(props) { |
| 183 |
return (formats) => { |
| 184 |
const positions = retrieveAnnotationPositions(formats); |
| 185 |
const { removeAnnotation, updateAnnotationRange, annotations: annotations2 } = props; |
| 186 |
updateAnnotationsWithPositions(annotations2, positions, { |
| 187 |
removeAnnotation, |
| 188 |
updateAnnotationRange |
| 189 |
}); |
| 190 |
}; |
| 191 |
} |
| 192 |
}; |
| 193 |
|
| 194 |
// packages/annotations/build-module/format/index.mjs |
| 195 |
var { name, ...settings } = annotation; |
| 196 |
(0, import_rich_text2.registerFormatType)(name, settings); |
| 197 |
|
| 198 |
// packages/annotations/build-module/block/index.mjs |
| 199 |
var import_hooks = __toESM(require_hooks(), 1); |
| 200 |
var import_data = __toESM(require_data(), 1); |
| 201 |
var addAnnotationClassName = (OriginalComponent) => { |
| 202 |
return (0, import_data.withSelect)((select, { clientId, className }) => { |
| 203 |
const annotations2 = select(STORE_NAME).__experimentalGetAnnotationsForBlock( |
| 204 |
clientId |
| 205 |
); |
| 206 |
return { |
| 207 |
className: annotations2.map((annotation2) => { |
| 208 |
return "is-annotated-by-" + annotation2.source; |
| 209 |
}).concat(className).filter(Boolean).join(" ") |
| 210 |
}; |
| 211 |
})(OriginalComponent); |
| 212 |
}; |
| 213 |
(0, import_hooks.addFilter)( |
| 214 |
"editor.BlockListBlock", |
| 215 |
"core/annotations", |
| 216 |
addAnnotationClassName |
| 217 |
); |
| 218 |
|
| 219 |
// packages/annotations/build-module/store/index.mjs |
| 220 |
var import_data3 = __toESM(require_data(), 1); |
| 221 |
|
| 222 |
// packages/annotations/build-module/store/reducer.mjs |
| 223 |
function filterWithReference(collection, predicate) { |
| 224 |
const filteredCollection = collection.filter(predicate); |
| 225 |
return collection.length === filteredCollection.length ? collection : filteredCollection; |
| 226 |
} |
| 227 |
var mapValues = (obj, callback) => Object.entries(obj).reduce( |
| 228 |
(acc, [key, value]) => ({ |
| 229 |
...acc, |
| 230 |
[key]: callback(value) |
| 231 |
}), |
| 232 |
{} |
| 233 |
); |
| 234 |
function isValidAnnotationRange(annotation2) { |
| 235 |
return typeof annotation2.start === "number" && typeof annotation2.end === "number" && annotation2.start <= annotation2.end; |
| 236 |
} |
| 237 |
function annotations(state = {}, action) { |
| 238 |
switch (action.type) { |
| 239 |
case "ANNOTATION_ADD": |
| 240 |
const blockClientId = action.blockClientId; |
| 241 |
const newAnnotation = { |
| 242 |
id: action.id, |
| 243 |
blockClientId, |
| 244 |
richTextIdentifier: action.richTextIdentifier, |
| 245 |
source: action.source, |
| 246 |
selector: action.selector, |
| 247 |
range: action.range |
| 248 |
}; |
| 249 |
if (newAnnotation.selector === "range" && !isValidAnnotationRange(newAnnotation.range)) { |
| 250 |
return state; |
| 251 |
} |
| 252 |
const previousAnnotationsForBlock = state?.[blockClientId] ?? []; |
| 253 |
return { |
| 254 |
...state, |
| 255 |
[blockClientId]: [ |
| 256 |
...previousAnnotationsForBlock, |
| 257 |
newAnnotation |
| 258 |
] |
| 259 |
}; |
| 260 |
case "ANNOTATION_REMOVE": |
| 261 |
return mapValues(state, (annotationsForBlock) => { |
| 262 |
return filterWithReference( |
| 263 |
annotationsForBlock, |
| 264 |
(annotation2) => { |
| 265 |
return annotation2.id !== action.annotationId; |
| 266 |
} |
| 267 |
); |
| 268 |
}); |
| 269 |
case "ANNOTATION_UPDATE_RANGE": |
| 270 |
return mapValues(state, (annotationsForBlock) => { |
| 271 |
let hasChangedRange = false; |
| 272 |
const newAnnotations = annotationsForBlock.map( |
| 273 |
(annotation2) => { |
| 274 |
if (annotation2.id === action.annotationId) { |
| 275 |
hasChangedRange = true; |
| 276 |
return { |
| 277 |
...annotation2, |
| 278 |
range: { |
| 279 |
start: action.start, |
| 280 |
end: action.end |
| 281 |
} |
| 282 |
}; |
| 283 |
} |
| 284 |
return annotation2; |
| 285 |
} |
| 286 |
); |
| 287 |
return hasChangedRange ? newAnnotations : annotationsForBlock; |
| 288 |
}); |
| 289 |
case "ANNOTATION_REMOVE_SOURCE": |
| 290 |
return mapValues(state, (annotationsForBlock) => { |
| 291 |
return filterWithReference( |
| 292 |
annotationsForBlock, |
| 293 |
(annotation2) => { |
| 294 |
return annotation2.source !== action.source; |
| 295 |
} |
| 296 |
); |
| 297 |
}); |
| 298 |
} |
| 299 |
return state; |
| 300 |
} |
| 301 |
var reducer_default = annotations; |
| 302 |
|
| 303 |
// packages/annotations/build-module/store/selectors.mjs |
| 304 |
var selectors_exports = {}; |
| 305 |
__export(selectors_exports, { |
| 306 |
__experimentalGetAllAnnotationsForBlock: () => __experimentalGetAllAnnotationsForBlock, |
| 307 |
__experimentalGetAnnotations: () => __experimentalGetAnnotations, |
| 308 |
__experimentalGetAnnotationsForBlock: () => __experimentalGetAnnotationsForBlock, |
| 309 |
__experimentalGetAnnotationsForRichText: () => __experimentalGetAnnotationsForRichText |
| 310 |
}); |
| 311 |
var import_data2 = __toESM(require_data(), 1); |
| 312 |
var EMPTY_ARRAY = []; |
| 313 |
var __experimentalGetAnnotationsForBlock = (0, import_data2.createSelector)( |
| 314 |
(state, blockClientId) => { |
| 315 |
return (state?.[blockClientId] ?? []).filter((annotation2) => { |
| 316 |
return annotation2.selector === "block"; |
| 317 |
}); |
| 318 |
}, |
| 319 |
(state, blockClientId) => [state?.[blockClientId] ?? EMPTY_ARRAY] |
| 320 |
); |
| 321 |
function __experimentalGetAllAnnotationsForBlock(state, blockClientId) { |
| 322 |
return state?.[blockClientId] ?? EMPTY_ARRAY; |
| 323 |
} |
| 324 |
var __experimentalGetAnnotationsForRichText = (0, import_data2.createSelector)( |
| 325 |
(state, blockClientId, richTextIdentifier) => { |
| 326 |
return (state?.[blockClientId] ?? []).filter((annotation2) => { |
| 327 |
return annotation2.selector === "range" && richTextIdentifier === annotation2.richTextIdentifier; |
| 328 |
}).map((annotation2) => { |
| 329 |
const { range, ...other } = annotation2; |
| 330 |
return { |
| 331 |
...range, |
| 332 |
...other |
| 333 |
}; |
| 334 |
}); |
| 335 |
}, |
| 336 |
(state, blockClientId) => [state?.[blockClientId] ?? EMPTY_ARRAY] |
| 337 |
); |
| 338 |
function __experimentalGetAnnotations(state) { |
| 339 |
return Object.values(state).flat(); |
| 340 |
} |
| 341 |
|
| 342 |
// packages/annotations/build-module/store/actions.mjs |
| 343 |
var actions_exports = {}; |
| 344 |
__export(actions_exports, { |
| 345 |
__experimentalAddAnnotation: () => __experimentalAddAnnotation, |
| 346 |
__experimentalRemoveAnnotation: () => __experimentalRemoveAnnotation, |
| 347 |
__experimentalRemoveAnnotationsBySource: () => __experimentalRemoveAnnotationsBySource, |
| 348 |
__experimentalUpdateAnnotationRange: () => __experimentalUpdateAnnotationRange |
| 349 |
}); |
| 350 |
|
| 351 |
// node_modules/uuid/dist/esm-browser/rng.js |
| 352 |
var getRandomValues; |
| 353 |
var rnds8 = new Uint8Array(16); |
| 354 |
function rng() { |
| 355 |
if (!getRandomValues) { |
| 356 |
getRandomValues = typeof crypto !== "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto); |
| 357 |
if (!getRandomValues) { |
| 358 |
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported"); |
| 359 |
} |
| 360 |
} |
| 361 |
return getRandomValues(rnds8); |
| 362 |
} |
| 363 |
|
| 364 |
// node_modules/uuid/dist/esm-browser/stringify.js |
| 365 |
var byteToHex = []; |
| 366 |
for (let i = 0; i < 256; ++i) { |
| 367 |
byteToHex.push((i + 256).toString(16).slice(1)); |
| 368 |
} |
| 369 |
function unsafeStringify(arr, offset = 0) { |
| 370 |
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]]; |
| 371 |
} |
| 372 |
|
| 373 |
// node_modules/uuid/dist/esm-browser/native.js |
| 374 |
var randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto); |
| 375 |
var native_default = { |
| 376 |
randomUUID |
| 377 |
}; |
| 378 |
|
| 379 |
// node_modules/uuid/dist/esm-browser/v4.js |
| 380 |
function v4(options, buf, offset) { |
| 381 |
if (native_default.randomUUID && !buf && !options) { |
| 382 |
return native_default.randomUUID(); |
| 383 |
} |
| 384 |
options = options || {}; |
| 385 |
const rnds = options.random || (options.rng || rng)(); |
| 386 |
rnds[6] = rnds[6] & 15 | 64; |
| 387 |
rnds[8] = rnds[8] & 63 | 128; |
| 388 |
if (buf) { |
| 389 |
offset = offset || 0; |
| 390 |
for (let i = 0; i < 16; ++i) { |
| 391 |
buf[offset + i] = rnds[i]; |
| 392 |
} |
| 393 |
return buf; |
| 394 |
} |
| 395 |
return unsafeStringify(rnds); |
| 396 |
} |
| 397 |
var v4_default = v4; |
| 398 |
|
| 399 |
// packages/annotations/build-module/store/actions.mjs |
| 400 |
function __experimentalAddAnnotation({ |
| 401 |
blockClientId, |
| 402 |
richTextIdentifier = null, |
| 403 |
range = null, |
| 404 |
selector = "range", |
| 405 |
source = "default", |
| 406 |
id = v4_default() |
| 407 |
}) { |
| 408 |
const action = { |
| 409 |
type: "ANNOTATION_ADD", |
| 410 |
id, |
| 411 |
blockClientId, |
| 412 |
richTextIdentifier, |
| 413 |
source, |
| 414 |
selector |
| 415 |
}; |
| 416 |
if (selector === "range") { |
| 417 |
action.range = range; |
| 418 |
} |
| 419 |
return action; |
| 420 |
} |
| 421 |
function __experimentalRemoveAnnotation(annotationId) { |
| 422 |
return { |
| 423 |
type: "ANNOTATION_REMOVE", |
| 424 |
annotationId |
| 425 |
}; |
| 426 |
} |
| 427 |
function __experimentalUpdateAnnotationRange(annotationId, start, end) { |
| 428 |
return { |
| 429 |
type: "ANNOTATION_UPDATE_RANGE", |
| 430 |
annotationId, |
| 431 |
start, |
| 432 |
end |
| 433 |
}; |
| 434 |
} |
| 435 |
function __experimentalRemoveAnnotationsBySource(source) { |
| 436 |
return { |
| 437 |
type: "ANNOTATION_REMOVE_SOURCE", |
| 438 |
source |
| 439 |
}; |
| 440 |
} |
| 441 |
|
| 442 |
// packages/annotations/build-module/store/index.mjs |
| 443 |
var store = (0, import_data3.createReduxStore)(STORE_NAME, { |
| 444 |
reducer: reducer_default, |
| 445 |
selectors: selectors_exports, |
| 446 |
actions: actions_exports |
| 447 |
}); |
| 448 |
(0, import_data3.register)(store); |
| 449 |
return __toCommonJS(index_exports); |
| 450 |
})(); |
| 451 |
//# sourceMappingURL=index.js.map |
| 452 |
|