@wordpress/dom
Version:
DOM utilities module for WordPress.
168 lines (167 loc) • 4.1 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var phrasing_content_exports = {};
__export(phrasing_content_exports, {
getPhrasingContentSchema: () => getPhrasingContentSchema,
isPhrasingContent: () => isPhrasingContent,
isTextContent: () => isTextContent
});
module.exports = __toCommonJS(phrasing_content_exports);
const textContentSchema = {
strong: {},
em: {},
s: {},
del: {},
ins: {},
a: { attributes: ["href", "target", "rel", "id"] },
code: {},
abbr: { attributes: ["title"] },
sub: {},
sup: {},
br: {},
small: {},
// To do: fix blockquote.
// cite: {},
q: { attributes: ["cite"] },
dfn: { attributes: ["title"] },
data: { attributes: ["value"] },
time: { attributes: ["datetime"] },
var: {},
samp: {},
kbd: {},
i: {},
b: {},
u: {},
mark: {},
ruby: {},
rt: {},
rp: {},
bdi: { attributes: ["dir"] },
bdo: { attributes: ["dir"] },
wbr: {},
"#text": {}
};
const excludedElements = ["#text", "br"];
Object.keys(textContentSchema).filter((element) => !excludedElements.includes(element)).forEach((tag) => {
const { [tag]: removedTag, ...restSchema } = textContentSchema;
textContentSchema[tag].children = restSchema;
});
const embeddedContentSchema = {
audio: {
attributes: [
"src",
"preload",
"autoplay",
"mediagroup",
"loop",
"muted"
]
},
canvas: { attributes: ["width", "height"] },
embed: { attributes: ["src", "type", "width", "height"] },
img: {
attributes: [
"alt",
"src",
"srcset",
"usemap",
"ismap",
"width",
"height"
]
},
object: {
attributes: [
"data",
"type",
"name",
"usemap",
"form",
"width",
"height"
]
},
video: {
attributes: [
"src",
"poster",
"preload",
"playsinline",
"autoplay",
"mediagroup",
"loop",
"muted",
"controls",
"width",
"height"
]
},
math: {
attributes: ["display", "xmlns"],
children: "*"
}
};
const phrasingContentSchema = {
...textContentSchema,
...embeddedContentSchema
};
function getPhrasingContentSchema(context) {
if (context !== "paste") {
return phrasingContentSchema;
}
const {
u,
// Used to mark misspelling. Shouldn't be pasted.
abbr,
// Invisible.
data,
// Invisible.
time,
// Invisible.
wbr,
// Invisible.
bdi,
// Invisible.
bdo,
// Invisible.
...remainingContentSchema
} = {
...phrasingContentSchema,
// We shouldn't paste potentially sensitive information which is not
// visible to the user when pasted, so strip the attributes.
ins: { children: phrasingContentSchema.ins.children },
del: { children: phrasingContentSchema.del.children }
};
return remainingContentSchema;
}
function isPhrasingContent(node) {
const tag = node.nodeName.toLowerCase();
return getPhrasingContentSchema().hasOwnProperty(tag) || tag === "span";
}
function isTextContent(node) {
const tag = node.nodeName.toLowerCase();
return textContentSchema.hasOwnProperty(tag) || tag === "span";
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getPhrasingContentSchema,
isPhrasingContent,
isTextContent
});
//# sourceMappingURL=phrasing-content.js.map