@wordpress/block-editor
Version:
42 lines (41 loc) • 1.33 kB
JavaScript
// packages/block-editor/src/components/rich-text/content.js
import { RawHTML } from "@wordpress/element";
import { children as childrenSource } from "@wordpress/blocks";
import deprecated from "@wordpress/deprecated";
import RichText from "./";
import { getMultilineTag } from "./utils";
import { jsx } from "react/jsx-runtime";
function valueToHTMLString(value, multiline) {
if (RichText.isEmpty(value)) {
const multilineTag = getMultilineTag(multiline);
return multilineTag ? `<${multilineTag}></${multilineTag}>` : "";
}
if (Array.isArray(value)) {
deprecated("wp.blockEditor.RichText value prop as children type", {
since: "6.1",
version: "6.3",
alternative: "value prop as string",
link: "https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/introducing-attributes-and-editable-fields/"
});
return childrenSource.toHTML(value);
}
if (typeof value === "string") {
return value;
}
return value.toHTMLString();
}
function Content({
value,
tagName: Tag,
multiline,
format,
...props
}) {
value = /* @__PURE__ */ jsx(RawHTML, { children: valueToHTMLString(value, multiline) });
return Tag ? /* @__PURE__ */ jsx(Tag, { ...props, children: value }) : value;
}
export {
Content,
valueToHTMLString
};
//# sourceMappingURL=content.js.map