This commit is contained in:
Hanson.xyz Dev
2026-01-04 17:50:08 -06:00
parent 7e45ce0756
commit acc8ac87a0
4131 changed files with 232562 additions and 250244 deletions
+152 -370
View File
@@ -67,161 +67,109 @@ const external_wp_richText_namespaceObject = window["wp"]["richText"];
;// external ["wp","i18n"]
const external_wp_i18n_namespaceObject = window["wp"]["i18n"];
;// ./node_modules/@wordpress/annotations/build-module/store/constants.js
/**
* The identifier for the data store.
*
* @type {string}
*/
const STORE_NAME = 'core/annotations';
const STORE_NAME = "core/annotations";
;// ./node_modules/@wordpress/annotations/build-module/format/annotation.js
/**
* WordPress dependencies
*/
const FORMAT_NAME = 'core/annotation';
const ANNOTATION_ATTRIBUTE_PREFIX = 'annotation-text-';
/**
* Internal dependencies
*/
const FORMAT_NAME = "core/annotation";
const ANNOTATION_ATTRIBUTE_PREFIX = "annotation-text-";
/**
* Applies given annotations to the given record.
*
* @param {Object} record The record to apply annotations to.
* @param {Array} annotations The annotation to apply.
* @return {Object} A record with the annotations applied.
*/
function applyAnnotations(record, annotations = []) {
annotations.forEach(annotation => {
let {
start,
end
} = annotation;
annotations.forEach((annotation2) => {
let { start, end } = annotation2;
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);
const className = ANNOTATION_ATTRIBUTE_PREFIX + annotation2.source;
const id = ANNOTATION_ATTRIBUTE_PREFIX + annotation2.id;
record = (0,external_wp_richText_namespaceObject.applyFormat)(
record,
{
type: FORMAT_NAME,
attributes: {
className,
id
}
},
start,
end
);
});
return record;
}
/**
* Removes annotations from the given record.
*
* @param {Object} record Record to remove annotations from.
* @return {Object} The cleaned record.
*/
function removeAnnotations(record) {
return removeFormat(record, 'core/annotation', 0, record.text.length);
return removeFormat(record, "core/annotation", 0, record.text.length);
}
/**
* Retrieves the positions of annotations inside an array of formats.
*
* @param {Array} formats Formats with annotations in there.
* @return {Object} ID keyed positions of annotations.
*/
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, '');
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
};
}
// Annotations refer to positions between characters.
// Formats refer to the character themselves.
// So we need to adjust for that here.
positions[id].end = i + 1;
});
});
return positions;
}
/**
* Updates annotations in the state based on positions retrieved from RichText.
*
* @param {Array} annotations The annotations that are currently applied.
* @param {Array} positions The current positions of the given annotations.
* @param {Object} actions
* @param {Function} actions.removeAnnotation Function to remove an annotation from the state.
* @param {Function} actions.updateAnnotationRange Function to update an annotation range in the state.
*/
function updateAnnotationsWithPositions(annotations, positions, {
removeAnnotation,
updateAnnotationRange
}) {
annotations.forEach(currentAnnotation => {
function updateAnnotationsWithPositions(annotations, positions, { removeAnnotation, updateAnnotationRange }) {
annotations.forEach((currentAnnotation) => {
const position = positions[currentAnnotation.id];
// If we cannot find an annotation, delete it.
if (!position) {
// Apparently the annotation has been removed, so remove it from the state:
// Remove...
removeAnnotation(currentAnnotation.id);
return;
}
const {
start,
end
} = currentAnnotation;
const { start, end } = currentAnnotation;
if (start !== position.start || end !== position.end) {
updateAnnotationRange(currentAnnotation.id, position.start, 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',
title: (0,external_wp_i18n_namespaceObject.__)("Annotation"),
tagName: "mark",
className: "annotation-text",
attributes: {
className: 'class',
id: 'id'
className: "class",
id: "id"
},
edit() {
return null;
},
__experimentalGetPropsForEditableTreePreparation(select, {
richTextIdentifier,
blockClientId
}) {
__experimentalGetPropsForEditableTreePreparation(select, { richTextIdentifier, blockClientId }) {
return {
annotations: select(STORE_NAME).__experimentalGetAnnotationsForRichText(blockClientId, richTextIdentifier)
annotations: select(
STORE_NAME
).__experimentalGetAnnotationsForRichText(
blockClientId,
richTextIdentifier
)
};
},
__experimentalCreatePrepareEditableTree({
annotations
}) {
__experimentalCreatePrepareEditableTree({ annotations }) {
return (formats, text) => {
if (annotations.length === 0) {
return formats;
}
let record = {
formats,
text
};
let record = { formats, text };
record = applyAnnotations(record, annotations);
return record.formats;
};
@@ -233,13 +181,9 @@ const annotation = {
};
},
__experimentalCreateOnChangeEditableValue(props) {
return formats => {
return (formats) => {
const positions = retrieveAnnotationPositions(formats);
const {
removeAnnotation,
updateAnnotationRange,
annotations
} = props;
const { removeAnnotation, updateAnnotationRange, annotations } = props;
updateAnnotationsWithPositions(annotations, positions, {
removeAnnotation,
updateAnnotationRange
@@ -248,20 +192,11 @@ const annotation = {
}
};
;// ./node_modules/@wordpress/annotations/build-module/format/index.js
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
const {
name: format_name,
...settings
} = annotation;
const { name: format_name, ...settings } = annotation;
(0,external_wp_richText_namespaceObject.registerFormatType)(format_name, settings);
;// external ["wp","hooks"]
@@ -269,87 +204,45 @@ const external_wp_hooks_namespaceObject = window["wp"]["hooks"];
;// external ["wp","data"]
const external_wp_data_namespaceObject = window["wp"]["data"];
;// ./node_modules/@wordpress/annotations/build-module/block/index.js
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
/**
* Adds annotation className to the block-list-block component.
*
* @param {Object} OriginalComponent The original BlockListBlock component.
* @return {Object} The enhanced component.
*/
const addAnnotationClassName = OriginalComponent => {
return (0,external_wp_data_namespaceObject.withSelect)((select, {
clientId,
className
}) => {
const annotations = select(STORE_NAME).__experimentalGetAnnotationsForBlock(clientId);
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(' ')
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);
(0,external_wp_hooks_namespaceObject.addFilter)(
"editor.BlockListBlock",
"core/annotations",
addAnnotationClassName
);
;// ./node_modules/@wordpress/annotations/build-module/store/reducer.js
/**
* Filters an array based on the predicate, but keeps the reference the same if
* the array hasn't changed.
*
* @param {Array} collection The collection to filter.
* @param {Function} predicate Function that determines if the item should stay
* in the array.
* @return {Array} Filtered array.
*/
function filterWithReference(collection, predicate) {
const filteredCollection = collection.filter(predicate);
return collection.length === filteredCollection.length ? collection : filteredCollection;
}
/**
* Creates a new object with the same keys, but with `callback()` called as
* a transformer function on each of the values.
*
* @param {Object} obj The object to transform.
* @param {Function} callback The function to transform each object value.
* @return {Array} Transformed object.
*/
const mapValues = (obj, callback) => Object.entries(obj).reduce((acc, [key, value]) => ({
...acc,
[key]: callback(value)
}), {});
/**
* Verifies whether the given annotations is a valid annotation.
*
* @param {Object} annotation The annotation to verify.
* @return {boolean} Whether the given annotation is valid.
*/
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;
return typeof annotation.start === "number" && typeof annotation.end === "number" && annotation.start <= annotation.end;
}
/**
* Reducer managing annotations.
*
* @param {Object} state The annotations currently shown in the editor.
* @param {Object} action Dispatched action.
*
* @return {Array} Updated state.
*/
function annotations(state = {}, action) {
var _state$blockClientId;
switch (action.type) {
case 'ANNOTATION_ADD':
case "ANNOTATION_ADD":
const blockClientId = action.blockClientId;
const newAnnotation = {
id: action.id,
@@ -359,129 +252,94 @@ function annotations(state = {}, action) {
selector: action.selector,
range: action.range
};
if (newAnnotation.selector === 'range' && !isValidAnnotationRange(newAnnotation.range)) {
if (newAnnotation.selector === "range" && !isValidAnnotationRange(newAnnotation.range)) {
return state;
}
const previousAnnotationsForBlock = (_state$blockClientId = state?.[blockClientId]) !== null && _state$blockClientId !== void 0 ? _state$blockClientId : [];
const previousAnnotationsForBlock = state?.[blockClientId] ?? [];
return {
...state,
[blockClientId]: [...previousAnnotationsForBlock, newAnnotation]
[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
}
};
case "ANNOTATION_REMOVE":
return mapValues(state, (annotationsForBlock) => {
return filterWithReference(
annotationsForBlock,
(annotation) => {
return annotation.id !== action.annotationId;
}
return annotation;
});
);
});
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;
});
case "ANNOTATION_REMOVE_SOURCE":
return mapValues(state, (annotationsForBlock) => {
return filterWithReference(
annotationsForBlock,
(annotation) => {
return annotation.source !== action.source;
}
);
});
}
return state;
}
/* harmony default export */ const reducer = (annotations);
var reducer_default = annotations;
;// ./node_modules/@wordpress/annotations/build-module/store/selectors.js
/**
* WordPress dependencies
*/
/**
* Shared reference to an empty array for cases where it is important to avoid
* returning a new array reference on every invocation, as in a connected or
* other pure component which performs `shouldComponentUpdate` check on props.
* This should be used as a last resort, since the normalized data should be
* maintained by the reducer result in state.
*
* @type {Array}
*/
const EMPTY_ARRAY = [];
/**
* Returns the annotations for a specific client ID.
*
* @param {Object} state Editor state.
* @param {string} clientId The ID of the block to get the annotations for.
*
* @return {Array} The annotations applicable to this block.
*/
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];
});
const __experimentalGetAnnotationsForBlock = (0,external_wp_data_namespaceObject.createSelector)(
(state, blockClientId) => {
return (state?.[blockClientId] ?? []).filter((annotation) => {
return annotation.selector === "block";
});
},
(state, blockClientId) => [state?.[blockClientId] ?? EMPTY_ARRAY]
);
function __experimentalGetAllAnnotationsForBlock(state, blockClientId) {
var _state$blockClientId3;
return (_state$blockClientId3 = state?.[blockClientId]) !== null && _state$blockClientId3 !== void 0 ? _state$blockClientId3 : EMPTY_ARRAY;
return state?.[blockClientId] ?? EMPTY_ARRAY;
}
/**
* Returns the annotations that apply to the given RichText instance.
*
* Both a blockClientId and a richTextIdentifier are required. This is because
* a block might have multiple `RichText` components. This does mean that every
* block needs to implement annotations itself.
*
* @param {Object} state Editor state.
* @param {string} blockClientId The client ID for the block.
* @param {string} richTextIdentifier Unique identifier that identifies the given RichText.
* @return {Array} All the annotations relevant for the `RichText`.
*/
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];
});
/**
* Returns all annotations in the editor state.
*
* @param {Object} state Editor state.
* @return {Array} All annotations currently applied.
*/
const __experimentalGetAnnotationsForRichText = (0,external_wp_data_namespaceObject.createSelector)(
(state, blockClientId, richTextIdentifier) => {
return (state?.[blockClientId] ?? []).filter((annotation) => {
return annotation.selector === "range" && richTextIdentifier === annotation.richTextIdentifier;
}).map((annotation) => {
const { range, ...other } = annotation;
return {
...range,
...other
};
});
},
(state, blockClientId) => [state?.[blockClientId] ?? EMPTY_ARRAY]
);
function __experimentalGetAnnotations(state) {
return Object.values(state).flat();
}
;// ./node_modules/@wordpress/annotations/node_modules/uuid/dist/esm-browser/native.js
const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
/* harmony default export */ const esm_browser_native = ({
@@ -571,142 +429,66 @@ function v4(options, buf, offset) {
/* harmony default export */ const esm_browser_v4 = (v4);
;// ./node_modules/@wordpress/annotations/build-module/store/actions.js
/**
* External dependencies
*/
/**
* @typedef WPAnnotationRange
*
* @property {number} start The offset where the annotation should start.
* @property {number} end The offset where the annotation should end.
*/
/**
* Adds an annotation to a block.
*
* The `block` attribute refers to a block ID that needs to be annotated.
* `isBlockAnnotation` controls whether or not the annotation is a block
* annotation. The `source` is the source of the annotation, this will be used
* to identity groups of annotations.
*
* The `range` property is only relevant if the selector is 'range'.
*
* @param {Object} annotation The annotation to add.
* @param {string} annotation.blockClientId The blockClientId to add the annotation to.
* @param {string} annotation.richTextIdentifier Identifier for the RichText instance the annotation applies to.
* @param {WPAnnotationRange} annotation.range The range at which to apply this annotation.
* @param {string} [annotation.selector="range"] The way to apply this annotation.
* @param {string} [annotation.source="default"] The source that added the annotation.
* @param {string} [annotation.id] The ID the annotation should have. Generates a UUID by default.
*
* @return {Object} Action object.
*/
function __experimentalAddAnnotation({
blockClientId,
richTextIdentifier = null,
range = null,
selector = 'range',
source = 'default',
selector = "range",
source = "default",
id = esm_browser_v4()
}) {
const action = {
type: 'ANNOTATION_ADD',
type: "ANNOTATION_ADD",
id,
blockClientId,
richTextIdentifier,
source,
selector
};
if (selector === 'range') {
if (selector === "range") {
action.range = range;
}
return action;
}
/**
* Removes an annotation with a specific ID.
*
* @param {string} annotationId The annotation to remove.
*
* @return {Object} Action object.
*/
function __experimentalRemoveAnnotation(annotationId) {
return {
type: 'ANNOTATION_REMOVE',
type: "ANNOTATION_REMOVE",
annotationId
};
}
/**
* Updates the range of an annotation.
*
* @param {string} annotationId ID of the annotation to update.
* @param {number} start The start of the new range.
* @param {number} end The end of the new range.
*
* @return {Object} Action object.
*/
function __experimentalUpdateAnnotationRange(annotationId, start, end) {
return {
type: 'ANNOTATION_UPDATE_RANGE',
type: "ANNOTATION_UPDATE_RANGE",
annotationId,
start,
end
};
}
/**
* Removes all annotations of a specific source.
*
* @param {string} source The source to remove.
*
* @return {Object} Action object.
*/
function __experimentalRemoveAnnotationsBySource(source) {
return {
type: 'ANNOTATION_REMOVE_SOURCE',
type: "ANNOTATION_REMOVE_SOURCE",
source
};
}
;// ./node_modules/@wordpress/annotations/build-module/store/index.js
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
/**
* Module Constants
*/
/**
* Store definition for the annotations namespace.
*
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
*
* @type {Object}
*/
const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, {
reducer: reducer,
reducer: reducer_default,
selectors: selectors_namespaceObject,
actions: actions_namespaceObject
});
(0,external_wp_data_namespaceObject.register)(store);
;// ./node_modules/@wordpress/annotations/build-module/index.js
/**
* Internal dependencies
*/