@wordpress/block-editor
Version:
28 lines (27 loc) • 960 B
JavaScript
// packages/block-editor/src/utils/selection.js
import { RichTextData } from "@wordpress/rich-text";
var START_OF_SELECTED_AREA = "\x86";
function retrieveSelectedAttribute(blockAttributes) {
if (!blockAttributes) {
return;
}
return Object.keys(blockAttributes).find((name) => {
const value = blockAttributes[name];
return (typeof value === "string" || value instanceof RichTextData) && // To do: refactor this to use rich text's selection instead, so we
// no longer have to use on this hack inserting a special character.
value.toString().indexOf(START_OF_SELECTED_AREA) !== -1;
});
}
function findRichTextAttributeKey(blockType) {
for (const [key, value] of Object.entries(blockType.attributes)) {
if (value.source === "rich-text" || value.source === "html") {
return key;
}
}
}
export {
START_OF_SELECTED_AREA,
findRichTextAttributeKey,
retrieveSelectedAttribute
};
//# sourceMappingURL=selection.js.map