(
editor: SlateEditor,
{
columns = 2,
select: selectProp,
...options
}: InsertNodesOptions & {
columns?: number;
} = {}
)
| 7 | import { KEYS } from 'platejs'; |
| 8 | |
| 9 | export 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 | }; |
no test coverage detected
searching dependent graphs…