MCPcopy
hub / github.com/udecode/plate / insertColumnGroup

Function insertColumnGroup

packages/layout/src/lib/transforms/insertColumnGroup.ts:9–45  ·  view source on GitHub ↗
(
  editor: SlateEditor,
  {
    columns = 2,
    select: selectProp,
    ...options
  }: InsertNodesOptions & {
    columns?: number;
  } = {}
)

Source from the content-addressed store, hash-verified

7import { KEYS } from 'platejs';
8
9export const insertColumnGroup = (
10 editor: SlateEditor,
11 {
12 columns = 2,
13 select: selectProp,
14 ...options
15 }: InsertNodesOptions & {
16 columns?: number;
17 } = {}
18) => {
19 const width = 100 / columns;
20
21 editor.tf.withoutNormalizing(() => {
22 editor.tf.insertNodes<TColumnGroupElement>(
23 {
24 children: new Array(columns).fill(null).map(() => ({
25 children: [editor.api.create.block()],
26 type: editor.getType(KEYS.column) as any,
27 width: `${width}%`,
28 })),
29 type: editor.getType(KEYS.columnGroup) as any,
30 },
31 options
32 );
33
34 if (selectProp) {
35 const entry = editor.api.node({
36 at: options.at,
37 match: { type: editor.getType(KEYS.column) },
38 });
39
40 if (!entry) return;
41
42 editor.tf.select(entry[1].concat([0]));
43 }
44 });
45};

Callers 4

transforms.tsFile · 0.90
transforms.tsFile · 0.90

Calls 1

selectMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…