@wordpress/block-editor
Version:
42 lines (41 loc) • 1.39 kB
JavaScript
// packages/block-editor/src/components/rich-text/with-deprecations.js
import { forwardRef } from "@wordpress/element";
import { children as childrenSource } from "@wordpress/blocks";
import { __unstableCreateElement } from "@wordpress/rich-text";
import deprecated from "@wordpress/deprecated";
import RichTextMultiline from "./multiline.mjs";
import { jsx } from "react/jsx-runtime";
function withDeprecations(Component) {
return forwardRef((props, ref) => {
let value = props.value;
let onChange = props.onChange;
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/"
});
value = childrenSource.toHTML(props.value);
onChange = (newValue) => props.onChange(
childrenSource.fromDOM(
__unstableCreateElement(document, newValue).childNodes
)
);
}
const NewComponent = props.multiline ? RichTextMultiline : Component;
return /* @__PURE__ */ jsx(
NewComponent,
{
...props,
value,
onChange,
ref
}
);
});
}
export {
withDeprecations
};
//# sourceMappingURL=with-deprecations.mjs.map