MCPcopy Index your code
hub / github.com/resend/react-email / wrapInContainer

Function wrapInContainer

packages/editor/src/extensions/container.tsx:19–48  ·  view source on GitHub ↗
(state: EditorState)

Source from the content-addressed store, hash-verified

17}
18
19function wrapInContainer(state: EditorState) {
20 const { doc } = state;
21 const containerType = state.schema.nodes.container;
22
23 const contentNodes: PmNode[] = [];
24 const globalContentNodes: PmNode[] = [];
25
26 doc.forEach((node) => {
27 if (node.type.name === 'globalContent') {
28 globalContentNodes.push(node);
29 } else {
30 contentNodes.push(node);
31 }
32 });
33
34 const containerContent =
35 contentNodes.length > 0
36 ? contentNodes
37 : [state.schema.nodes.paragraph.create()];
38
39 const containerNode = containerType.create(null, containerContent);
40
41 const newDocContent = [...globalContentNodes, containerNode];
42
43 const tr = state.tr;
44 tr.replaceWith(0, doc.content.size, newDocContent);
45 tr.setMeta('addToHistory', false);
46
47 return tr;
48}
49
50export interface ContainerOptions {
51 HTMLAttributes: Record<string, unknown>;

Callers 2

addProseMirrorPluginsFunction · 0.85
appendTransactionFunction · 0.85

Calls 3

forEachMethod · 0.80
pushMethod · 0.80
createMethod · 0.45

Tested by

no test coverage detected