@lofcz/platejs-layout 52.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) Ziad Beyens, Dylan Schiemann, Joe Anderson, Felix Feng
4
+
5
+ Unless otherwise specified in a LICENSE file within an individual package directory,
6
+ this license applies to all files in this repository outside of those package directories.
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in
16
+ all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # Plate Column plugin
@@ -0,0 +1,84 @@
1
+ import { ElementApi, KEYS, PathApi, createSlatePlugin } from "platejs";
2
+
3
+ //#region src/lib/withColumn.ts
4
+ const withColumn = ({ editor, tf: { normalizeNode, selectAll }, type }) => ({ transforms: {
5
+ normalizeNode([n, path]) {
6
+ if (ElementApi.isElement(n) && n.type === editor.getType(KEYS.columnGroup)) {
7
+ const node = n;
8
+ const firstChild = node.children[0];
9
+ if (node.children.length === 1 && firstChild.type === editor.getType(KEYS.p)) editor.tf.unwrapNodes({ at: PathApi.child(path, 0) });
10
+ if (!node.children.some((child) => ElementApi.isElement(child) && child.type === type)) {
11
+ editor.tf.removeNodes({ at: path });
12
+ return;
13
+ }
14
+ if (node.children.length < 2) {
15
+ editor.tf.withoutNormalizing(() => {
16
+ editor.tf.unwrapNodes({ at: path });
17
+ editor.tf.unwrapNodes({ at: path });
18
+ });
19
+ return;
20
+ }
21
+ editor.tf.withoutNormalizing(() => {
22
+ const totalColumns = node.children.length;
23
+ let widths = node.children.map((col) => {
24
+ const parsed = Number.parseFloat(col.width);
25
+ return Number.isNaN(parsed) ? 0 : parsed;
26
+ });
27
+ const sum = widths.reduce((acc, w) => acc + w, 0);
28
+ if (sum !== 100) {
29
+ const adjustment = (100 - sum) / totalColumns;
30
+ widths = widths.map((w) => w + adjustment);
31
+ widths.forEach((w, i) => {
32
+ const columnPath = path.concat([i]);
33
+ editor.tf.setNodes({ width: `${w}%` }, { at: columnPath });
34
+ });
35
+ }
36
+ });
37
+ }
38
+ if (ElementApi.isElement(n) && n.type === type) {
39
+ if (n.children.length === 0) {
40
+ editor.tf.removeNodes({ at: path });
41
+ return;
42
+ }
43
+ }
44
+ return normalizeNode([n, path]);
45
+ },
46
+ selectAll: () => {
47
+ const apply = () => {
48
+ const at = editor.selection;
49
+ if (!at) return;
50
+ const column = editor.api.above({ match: { type } });
51
+ if (!column) return;
52
+ let targetPath = column[1];
53
+ if (editor.api.isStart(editor.api.start(at), targetPath) && editor.api.isEnd(editor.api.end(at), targetPath)) targetPath = PathApi.parent(targetPath);
54
+ if (targetPath.length === 0) return;
55
+ editor.tf.select(targetPath);
56
+ return true;
57
+ };
58
+ if (apply()) return true;
59
+ return selectAll();
60
+ }
61
+ } });
62
+
63
+ //#endregion
64
+ //#region src/lib/BaseColumnPlugin.ts
65
+ const BaseColumnItemPlugin = createSlatePlugin({
66
+ key: KEYS.column,
67
+ node: {
68
+ isContainer: true,
69
+ isElement: true,
70
+ isStrictSiblings: true
71
+ }
72
+ }).overrideEditor(withColumn);
73
+ const BaseColumnPlugin = createSlatePlugin({
74
+ key: KEYS.columnGroup,
75
+ node: {
76
+ isContainer: true,
77
+ isElement: true
78
+ },
79
+ plugins: [BaseColumnItemPlugin]
80
+ });
81
+
82
+ //#endregion
83
+ export { BaseColumnPlugin as n, withColumn as r, BaseColumnItemPlugin as t };
84
+ //# sourceMappingURL=BaseColumnPlugin-BFM6r9Zm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseColumnPlugin-BFM6r9Zm.js","names":["OverrideEditor","TColumnElement","TColumnGroupElement","ElementApi","KEYS","PathApi","withColumn","editor","tf","normalizeNode","selectAll","type","transforms","n","path","isElement","getType","columnGroup","node","firstChild","children","length","p","unwrapNodes","at","child","some","removeNodes","withoutNormalizing","totalColumns","widths","map","col","parsed","Number","parseFloat","width","isNaN","sum","reduce","acc","w","diff","adjustment","forEach","i","columnPath","concat","setNodes","apply","selection","column","api","above","match","targetPath","isStart","start","isEnd","end","parent","select","createSlatePlugin","KEYS","withColumn","BaseColumnItemPlugin","key","column","node","isContainer","isElement","isStrictSiblings","overrideEditor","BaseColumnPlugin","columnGroup","plugins"],"sources":["../src/lib/withColumn.ts","../src/lib/BaseColumnPlugin.ts"],"sourcesContent":["import {\n type OverrideEditor,\n type TColumnElement,\n type TColumnGroupElement,\n ElementApi,\n KEYS,\n PathApi,\n} from 'platejs';\n\nexport const withColumn: OverrideEditor = ({\n editor,\n tf: { normalizeNode, selectAll },\n type,\n}) => ({\n transforms: {\n normalizeNode([n, path]) {\n // If it's a column group, ensure it has valid children\n if (\n ElementApi.isElement(n) &&\n n.type === editor.getType(KEYS.columnGroup)\n ) {\n const node = n as TColumnGroupElement;\n\n // If the first child is a p, unwrap it\n const firstChild = node.children[0];\n if (\n node.children.length === 1 &&\n firstChild.type === editor.getType(KEYS.p)\n ) {\n editor.tf.unwrapNodes({ at: PathApi.child(path, 0) });\n }\n\n // If no columns found, unwrap the column group\n if (\n !node.children.some(\n (child) => ElementApi.isElement(child) && child.type === type\n )\n ) {\n editor.tf.removeNodes({ at: path });\n\n return;\n }\n // If only one column remains, unwrap the group (optional logic)\n if (node.children.length < 2) {\n editor.tf.withoutNormalizing(() => {\n editor.tf.unwrapNodes({ at: path });\n editor.tf.unwrapNodes({ at: path });\n });\n\n return;\n }\n\n // PERF: only run when the number of columns changes\n editor.tf.withoutNormalizing(() => {\n // Add new width normalization logic\n const totalColumns = node.children.length;\n let widths = node.children.map((col) => {\n const parsed = Number.parseFloat(col.width);\n\n return Number.isNaN(parsed) ? 0 : parsed;\n });\n\n const sum = widths.reduce((acc, w) => acc + w, 0);\n\n if (sum !== 100) {\n const diff = 100 - sum;\n const adjustment = diff / totalColumns;\n\n widths = widths.map((w) => w + adjustment);\n\n // Update the columns with the new widths\n widths.forEach((w, i) => {\n const columnPath = path.concat([i]);\n editor.tf.setNodes<TColumnElement>(\n { width: `${w}%` },\n { at: columnPath }\n );\n });\n }\n });\n }\n // If it's a column, ensure it has at least one block (optional)\n if (ElementApi.isElement(n) && n.type === type) {\n const node = n as TColumnElement;\n\n // node.children.forEach((child, index) => {\n // if (TextApi.isText(child)) {\n // editor.tf.wrapNodes(\n // { children: [], type: editor.getType(KEYS.p) },\n // {\n // at: PathApi.child(path, index),\n // }\n // );\n // }\n // });\n\n if (node.children.length === 0) {\n editor.tf.removeNodes({ at: path });\n\n return;\n }\n }\n\n return normalizeNode([n, path]);\n },\n selectAll: () => {\n const apply = () => {\n const at = editor.selection;\n\n if (!at) return;\n\n const column = editor.api.above({\n match: { type },\n });\n\n if (!column) return;\n\n let targetPath = column[1];\n\n if (\n editor.api.isStart(editor.api.start(at), targetPath) &&\n editor.api.isEnd(editor.api.end(at), targetPath)\n ) {\n targetPath = PathApi.parent(targetPath);\n }\n\n if (targetPath.length === 0) return;\n\n editor.tf.select(targetPath);\n\n return true;\n };\n\n if (apply()) return true;\n\n return selectAll();\n },\n },\n});\n","import { createSlatePlugin, KEYS } from 'platejs';\n\nimport { withColumn } from './withColumn';\n\nexport const BaseColumnItemPlugin = createSlatePlugin({\n key: KEYS.column,\n node: { isContainer: true, isElement: true, isStrictSiblings: true },\n}).overrideEditor(withColumn);\n\nexport const BaseColumnPlugin = createSlatePlugin({\n key: KEYS.columnGroup,\n node: { isContainer: true, isElement: true },\n plugins: [BaseColumnItemPlugin],\n});\n"],"mappings":";;;AASA,MAAaM,cAA8B,EACzCC,QACAC,IAAI,EAAEC,eAAeC,aACrBC,YACK,EACLC,YAAY;CACVH,cAAc,CAACI,GAAGC,OAAO;AAEvB,MACEX,WAAWY,UAAUF,EAAE,IACvBA,EAAEF,SAASJ,OAAOS,QAAQZ,KAAKa,YAAY,EAC3C;GACA,MAAMC,OAAOL;GAGb,MAAMM,aAAaD,KAAKE,SAAS;AACjC,OACEF,KAAKE,SAASC,WAAW,KACzBF,WAAWR,SAASJ,OAAOS,QAAQZ,KAAKkB,EAAE,CAE1Cf,QAAOC,GAAGe,YAAY,EAAEC,IAAInB,QAAQoB,MAAMX,MAAM,EAAC,EAAG,CAAC;AAIvD,OACE,CAACI,KAAKE,SAASM,MACZD,UAAUtB,WAAWY,UAAUU,MAAM,IAAIA,MAAMd,SAASA,KAC1D,EACD;AACAJ,WAAOC,GAAGmB,YAAY,EAAEH,IAAIV,MAAM,CAAC;AAEnC;;AAGF,OAAII,KAAKE,SAASC,SAAS,GAAG;AAC5Bd,WAAOC,GAAGoB,yBAAyB;AACjCrB,YAAOC,GAAGe,YAAY,EAAEC,IAAIV,MAAM,CAAC;AACnCP,YAAOC,GAAGe,YAAY,EAAEC,IAAIV,MAAM,CAAC;MACnC;AAEF;;AAIFP,UAAOC,GAAGoB,yBAAyB;IAEjC,MAAMC,eAAeX,KAAKE,SAASC;IACnC,IAAIS,SAASZ,KAAKE,SAASW,KAAKC,QAAQ;KACtC,MAAMC,SAASC,OAAOC,WAAWH,IAAII,MAA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AAauD,uBAAuBH,kBAAkB;CACpDI,KAAKH,KAAKI;CACVC,MAAM;EAAEC,aAAa;EAAMC,WAAW;EAAMC,kBAAkB;EAAK;CACpE,CAAC,CAACC,eAAeR,WAAW;AAE7B,MAAaS,mBAAmBX,kBAAkB;CAChDI,KAAKH,KAAKW;CACVN,MAAM;EAAEC,aAAa;EAAMC,WAAW;EAAM;CAC5CK,SAAS,CAACV,qBAAoB;CAC/B,CAAC"}
@@ -0,0 +1,69 @@
1
+ import { At, InsertNodesOptions, NodeEntry, OverrideEditor, ReplaceNodesOptions, SlateEditor, TColumnGroupElement, TNode } from "platejs";
2
+
3
+ //#region src/lib/BaseColumnPlugin.d.ts
4
+ declare const BaseColumnItemPlugin: any;
5
+ declare const BaseColumnPlugin: any;
6
+ //#endregion
7
+ //#region src/lib/withColumn.d.ts
8
+ declare const withColumn: OverrideEditor;
9
+ //#endregion
10
+ //#region src/lib/transforms/insertColumn.d.ts
11
+ declare const insertColumn: (editor: SlateEditor, {
12
+ width,
13
+ ...options
14
+ }?: {
15
+ width?: string;
16
+ } & InsertNodesOptions) => void;
17
+ //#endregion
18
+ //#region src/lib/transforms/insertColumnGroup.d.ts
19
+ declare const insertColumnGroup: (editor: SlateEditor, {
20
+ columns,
21
+ select: selectProp,
22
+ ...options
23
+ }?: InsertNodesOptions & {
24
+ columns?: number;
25
+ }) => void;
26
+ //#endregion
27
+ //#region src/lib/transforms/moveMiddleColumn.d.ts
28
+ /**
29
+ * Move the middle column to the left if direction is 'left', or to the right if
30
+ * 'right'. If the middle node is empty, return false and remove it.
31
+ */
32
+ declare const moveMiddleColumn: <N extends TNode>(editor: SlateEditor, [node, path]: NodeEntry<N>, options?: {
33
+ direction: "left" | "right";
34
+ }) => false | undefined;
35
+ //#endregion
36
+ //#region src/lib/transforms/resizeColumn.d.ts
37
+ declare function resizeColumn(columnGroup: TColumnGroupElement, columnId: string, newWidthPercent: number): TColumnGroupElement;
38
+ //#endregion
39
+ //#region src/lib/transforms/setColumns.d.ts
40
+ declare const setColumns: (editor: SlateEditor, {
41
+ at,
42
+ columns,
43
+ widths
44
+ }: {
45
+ /** Column group path */
46
+ at?: At;
47
+ columns?: number;
48
+ widths?: string[];
49
+ }) => void;
50
+ //#endregion
51
+ //#region src/lib/transforms/toggleColumnGroup.d.ts
52
+ declare const toggleColumnGroup: (editor: SlateEditor, {
53
+ at,
54
+ columns,
55
+ widths
56
+ }?: Partial<ReplaceNodesOptions> & {
57
+ columns?: number;
58
+ widths?: string[];
59
+ }) => void;
60
+ //#endregion
61
+ //#region src/lib/utils/columnsToWidths.d.ts
62
+ declare const columnsToWidths: ({
63
+ columns
64
+ }?: {
65
+ columns?: number;
66
+ }) => string[];
67
+ //#endregion
68
+ export { BaseColumnItemPlugin, BaseColumnPlugin, columnsToWidths, insertColumn, insertColumnGroup, moveMiddleColumn, resizeColumn, setColumns, toggleColumnGroup, withColumn };
69
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/lib/BaseColumnPlugin.ts","../src/lib/withColumn.ts","../src/lib/transforms/insertColumn.ts","../src/lib/transforms/insertColumnGroup.ts","../src/lib/transforms/moveMiddleColumn.ts","../src/lib/transforms/resizeColumn.ts","../src/lib/transforms/setColumns.ts","../src/lib/transforms/toggleColumnGroup.ts","../src/lib/utils/columnsToWidths.ts"],"sourcesContent":[],"mappings":";;;cAIa;cAKA;;;cCAA,YAAY;;;cCLZ,uBACH;;;AFDG,CAAA;;AAAb,CAAA,GEEsD,kBFFzC,EAAA,GAGgB,IAAA;;;cGChB,4BACH;;UACR;;AHNF,CAAA,GGUK;;AHVL,CAAA,EAAA,GAAa,IAAA;;;;;AAAb;AAKA;cIGa,6BAA8B,eACjC,2BACM,UAAU;;;;;iBCZV,YAAA,cACD,iEAGZ;;;cCKU,qBACH;;;;;;ENRG,EAAA,CAAA,EMeJ,ENfI;EAKA,OAAA,CAAA,EAAA,MAAA;;;;;cOFA,4BACH;;;;APCV,CAAA,GOIK,QAAQ;;EPTA,MAAA,CAAA,EAAA,MAAA,EAAA;AAKb,CAAA,EAAA,GAAa,IAAA;;;cQTA"}
package/dist/index.js ADDED
@@ -0,0 +1,190 @@
1
+ import { n as BaseColumnPlugin, r as withColumn, t as BaseColumnItemPlugin } from "./BaseColumnPlugin-BFM6r9Zm.js";
2
+ import { KEYS, NodeApi } from "platejs";
3
+
4
+ //#region src/lib/transforms/insertColumn.ts
5
+ const insertColumn = (editor, { width = "33%", ...options } = {}) => {
6
+ editor.tf.insertNodes({
7
+ children: [editor.api.create.block()],
8
+ type: editor.getType(KEYS.column),
9
+ width
10
+ }, options);
11
+ };
12
+
13
+ //#endregion
14
+ //#region src/lib/transforms/insertColumnGroup.ts
15
+ const insertColumnGroup = (editor, { columns = 2, select: selectProp, ...options } = {}) => {
16
+ const width = 100 / columns;
17
+ editor.tf.withoutNormalizing(() => {
18
+ editor.tf.insertNodes({
19
+ children: new Array(columns).fill(null).map(() => ({
20
+ children: [editor.api.create.block()],
21
+ type: editor.getType(KEYS.column),
22
+ width: `${width}%`
23
+ })),
24
+ type: editor.getType(KEYS.columnGroup)
25
+ }, options);
26
+ if (selectProp) {
27
+ const entry = editor.api.node({
28
+ at: options.at,
29
+ match: { type: editor.getType(KEYS.column) }
30
+ });
31
+ if (!entry) return;
32
+ editor.tf.select(entry[1].concat([0]));
33
+ }
34
+ });
35
+ };
36
+
37
+ //#endregion
38
+ //#region src/lib/transforms/moveMiddleColumn.ts
39
+ /**
40
+ * Move the middle column to the left if direction is 'left', or to the right if
41
+ * 'right'. If the middle node is empty, return false and remove it.
42
+ */
43
+ const moveMiddleColumn = (editor, [node, path], options) => {
44
+ if ((options?.direction || "left") === "left") {
45
+ const DESCENDANT_PATH = [1];
46
+ const middleChildNode = NodeApi.get(node, DESCENDANT_PATH);
47
+ if (!middleChildNode) return false;
48
+ const isEmpty = NodeApi.string(middleChildNode) === "";
49
+ const middleChildPathRef = editor.api.pathRef(path.concat(DESCENDANT_PATH));
50
+ if (isEmpty) {
51
+ editor.tf.removeNodes({ at: middleChildPathRef.current });
52
+ return false;
53
+ }
54
+ const firstNode = NodeApi.descendant(node, [0]);
55
+ if (!firstNode) return false;
56
+ const firstLast = path.concat([0, firstNode.children.length]);
57
+ editor.tf.moveNodes({
58
+ at: middleChildPathRef.current,
59
+ to: firstLast
60
+ });
61
+ editor.tf.unwrapNodes({ at: middleChildPathRef.current });
62
+ middleChildPathRef.unref();
63
+ }
64
+ };
65
+
66
+ //#endregion
67
+ //#region src/lib/transforms/resizeColumn.ts
68
+ function resizeColumn(columnGroup, columnId, newWidthPercent) {
69
+ const widths = columnGroup.children.map((col) => col.width ? Number.parseFloat(col.width) : 0);
70
+ if (widths.reduce((sum, w) => sum + w, 0) === 0) {
71
+ const evenWidth = 100 / columnGroup.children.length;
72
+ columnGroup.children.forEach((col) => {
73
+ col.width = `${evenWidth}%`;
74
+ });
75
+ return columnGroup;
76
+ }
77
+ const index = columnGroup.children.findIndex((col) => col.id === columnId);
78
+ if (index === -1) return columnGroup;
79
+ widths[index] = newWidthPercent;
80
+ let totalAfter = widths.reduce((sum, w) => sum + w, 0);
81
+ const diff = 100 - totalAfter;
82
+ if (diff !== 0) {
83
+ const siblingIndex = (index + 1) % widths.length;
84
+ widths[siblingIndex] = Math.max(widths[siblingIndex] + diff, 0);
85
+ }
86
+ totalAfter = widths.reduce((sum, w) => sum + w, 0);
87
+ if (Math.round(totalAfter) !== 100) {
88
+ const scale = 100 / totalAfter;
89
+ for (let i = 0; i < widths.length; i++) widths[i] = Number.parseFloat((widths[i] * scale).toFixed(2));
90
+ }
91
+ columnGroup.children.forEach((col, i) => {
92
+ col.width = `${widths[i]}%`;
93
+ });
94
+ return columnGroup;
95
+ }
96
+
97
+ //#endregion
98
+ //#region src/lib/utils/columnsToWidths.ts
99
+ const columnsToWidths = ({ columns = 2 } = {}) => new Array(columns).fill(null).map(() => `${100 / columns}%`);
100
+
101
+ //#endregion
102
+ //#region src/lib/transforms/setColumns.ts
103
+ const setColumns = (editor, { at, columns, widths }) => {
104
+ editor.tf.withoutNormalizing(() => {
105
+ if (!at) return;
106
+ widths = widths ?? columnsToWidths({ columns });
107
+ if (widths.length === 0) return;
108
+ const columnGroup = editor.api.node(at);
109
+ if (!columnGroup) return;
110
+ const [{ children }, path] = columnGroup;
111
+ const currentCount = children.length;
112
+ const targetCount = widths.length;
113
+ if (currentCount === targetCount) {
114
+ widths.forEach((width, i) => {
115
+ editor.tf.setNodes({ width }, { at: path.concat([i]) });
116
+ });
117
+ return;
118
+ }
119
+ if (targetCount > currentCount) {
120
+ const columnsToAdd = targetCount - currentCount;
121
+ const insertPath = path.concat([currentCount]);
122
+ const newColumns = new Array(columnsToAdd).fill(null).map((_, i) => ({
123
+ children: [editor.api.create.block()],
124
+ type: editor.getType(KEYS.column),
125
+ width: widths[currentCount + i] || `${100 / targetCount}%`
126
+ }));
127
+ editor.tf.insertNodes(newColumns, { at: insertPath });
128
+ widths.forEach((width, i) => {
129
+ editor.tf.setNodes({ width }, { at: path.concat([i]) });
130
+ });
131
+ return;
132
+ }
133
+ if (targetCount < currentCount) {
134
+ const keepColumnIndex = targetCount - 1;
135
+ const keepColumnPath = path.concat([keepColumnIndex]);
136
+ const keepColumnNode = NodeApi.get(editor, keepColumnPath);
137
+ if (!keepColumnNode) return;
138
+ const to = keepColumnPath.concat([keepColumnNode.children.length]);
139
+ for (let i = currentCount - 1; i > keepColumnIndex; i--) {
140
+ const columnPath = path.concat([i]);
141
+ const columnEntry = editor.api.node(columnPath);
142
+ if (!columnEntry) continue;
143
+ editor.tf.moveNodes({
144
+ at: columnEntry[1],
145
+ children: true,
146
+ to
147
+ });
148
+ }
149
+ for (let i = currentCount - 1; i > keepColumnIndex; i--) editor.tf.removeNodes({ at: path.concat([i]) });
150
+ widths.forEach((width, i) => {
151
+ editor.tf.setNodes({ width }, { at: path.concat([i]) });
152
+ });
153
+ }
154
+ });
155
+ };
156
+
157
+ //#endregion
158
+ //#region src/lib/transforms/toggleColumnGroup.ts
159
+ const toggleColumnGroup = (editor, { at, columns = 2, widths } = {}) => {
160
+ const entry = editor.api.block({ at });
161
+ const columnGroupEntry = editor.api.block({
162
+ above: true,
163
+ at,
164
+ match: { type: editor.getType(KEYS.columnGroup) }
165
+ });
166
+ if (!entry) return;
167
+ const [node, path] = entry;
168
+ if (columnGroupEntry) setColumns(editor, {
169
+ at: columnGroupEntry[1],
170
+ columns,
171
+ widths
172
+ });
173
+ else {
174
+ const columnWidths = widths || columnsToWidths({ columns });
175
+ const nodes = {
176
+ children: new Array(columns).fill(null).map((_, index) => ({
177
+ children: [index === 0 ? node : editor.api.create.block()],
178
+ type: editor.getType(KEYS.column),
179
+ width: columnWidths[index]
180
+ })),
181
+ type: editor.getType(KEYS.columnGroup)
182
+ };
183
+ editor.tf.replaceNodes(nodes, { at: path });
184
+ editor.tf.select(editor.api.start(path.concat([0])));
185
+ }
186
+ };
187
+
188
+ //#endregion
189
+ export { BaseColumnItemPlugin, BaseColumnPlugin, columnsToWidths, insertColumn, insertColumnGroup, moveMiddleColumn, resizeColumn, setColumns, toggleColumnGroup, withColumn };
190
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["InsertNodesOptions","SlateEditor","TColumnElement","KEYS","insertColumn","editor","width","options","tf","insertNodes","children","api","create","block","type","getType","column","InsertNodesOptions","SlateEditor","TColumnGroupElement","KEYS","insertColumnGroup","editor","columns","select","selectProp","options","width","tf","withoutNormalizing","insertNodes","children","Array","fill","map","api","create","block","type","getType","column","columnGroup","entry","node","at","match","concat","NodeEntry","SlateEditor","TColumnElement","TNode","NodeApi","moveMiddleColumn","editor","node","path","N","options","direction","DESCENDANT_PATH","middleChildNode","get","isEmpty","string","middleChildPathRef","api","pathRef","concat","tf","removeNodes","at","current","firstNode","descendant","firstLast","children","length","moveNodes","to","unwrapNodes","unref","TColumnGroupElement","resizeColumn","columnGroup","columnId","newWidthPercent","widths","children","map","col","width","Number","parseFloat","totalBefore","reduce","sum","w","evenWidth","length","forEach","index","findIndex","id","totalAfter","diff","siblingIndex","Math","max","round","scale","i","toFixed","columnsToWidths","columns","Array","fill","map","At","SlateEditor","TColumnElement","TColumnGroupElement","NodeApi","KEYS","columnsToWidths","setColumns","editor","at","columns","widths","tf","withoutNormalizing","length","columnGroup","api","node","children","path","currentCount","targetCount","forEach","width","i","setNodes","concat","columnsToAdd","insertPath","newColumns","Array","fill","map","_","create","block","type","getType","column","insertNodes","keepColumnIndex","keepColumnPath","keepColumnNode","get","to","columnPath","columnEntry","moveNodes","removeNodes","ReplaceNodesOptions","SlateEditor","TElement","KEYS","columnsToWidths","setColumns","toggleColumnGroup","editor","at","columns","widths","Partial","entry","api","block","columnGroupEntry","above","match","type","getType","columnGroup","node","path","columnWidths","nodes","children","Array","fill","map","_","index","create","column","width","tf","replaceNodes","select","start","concat"],"sources":["../src/lib/transforms/insertColumn.ts","../src/lib/transforms/insertColumnGroup.ts","../src/lib/transforms/moveMiddleColumn.ts","../src/lib/transforms/resizeColumn.ts","../src/lib/utils/columnsToWidths.ts","../src/lib/transforms/setColumns.ts","../src/lib/transforms/toggleColumnGroup.ts"],"sourcesContent":["import type { InsertNodesOptions, SlateEditor, TColumnElement } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\nexport const insertColumn = (\n editor: SlateEditor,\n { width = '33%', ...options }: { width?: string } & InsertNodesOptions = {}\n) => {\n editor.tf.insertNodes<TColumnElement>(\n {\n children: [editor.api.create.block()],\n type: editor.getType(KEYS.column) as any,\n width,\n },\n options as any\n );\n};\n","import type {\n InsertNodesOptions,\n SlateEditor,\n TColumnGroupElement,\n} from 'platejs';\n\nimport { KEYS } from 'platejs';\n\nexport const insertColumnGroup = (\n editor: SlateEditor,\n {\n columns = 2,\n select: selectProp,\n ...options\n }: InsertNodesOptions & {\n columns?: number;\n } = {}\n) => {\n const width = 100 / columns;\n\n editor.tf.withoutNormalizing(() => {\n editor.tf.insertNodes<TColumnGroupElement>(\n {\n children: new Array(columns).fill(null).map(() => ({\n children: [editor.api.create.block()],\n type: editor.getType(KEYS.column) as any,\n width: `${width}%`,\n })),\n type: editor.getType(KEYS.columnGroup) as any,\n },\n options\n );\n\n if (selectProp) {\n const entry = editor.api.node({\n at: options.at,\n match: { type: editor.getType(KEYS.column) },\n });\n\n if (!entry) return;\n\n editor.tf.select(entry[1].concat([0]));\n }\n });\n};\n","import {\n type NodeEntry,\n type SlateEditor,\n type TColumnElement,\n type TNode,\n NodeApi,\n} from 'platejs';\n\n/**\n * Move the middle column to the left if direction is 'left', or to the right if\n * 'right'. If the middle node is empty, return false and remove it.\n */\nexport const moveMiddleColumn = <N extends TNode>(\n editor: SlateEditor,\n [node, path]: NodeEntry<N>,\n options?: {\n direction: 'left' | 'right';\n }\n) => {\n const direction = options?.direction || 'left';\n\n if (direction === 'left') {\n const DESCENDANT_PATH = [1];\n\n const middleChildNode = NodeApi.get<TColumnElement>(node, DESCENDANT_PATH);\n\n if (!middleChildNode) return false;\n\n // Check emptiness using Api.string\n const isEmpty = NodeApi.string(middleChildNode) === '';\n\n const middleChildPathRef = editor.api.pathRef(path.concat(DESCENDANT_PATH));\n\n if (isEmpty) {\n editor.tf.removeNodes({ at: middleChildPathRef.current! });\n\n return false;\n }\n\n const firstNode = NodeApi.descendant<TColumnElement>(node, [0]);\n\n if (!firstNode) return false;\n\n const firstLast = path.concat([0, firstNode.children.length]);\n\n editor.tf.moveNodes({ at: middleChildPathRef.current!, to: firstLast });\n editor.tf.unwrapNodes({ at: middleChildPathRef.current! });\n middleChildPathRef.unref();\n }\n};\n","import type { TColumnGroupElement } from 'platejs';\n\nexport function resizeColumn(\n columnGroup: TColumnGroupElement,\n columnId: string,\n newWidthPercent: number\n): TColumnGroupElement {\n // Convert widths to numbers for easier math\n const widths = columnGroup.children.map((col) =>\n col.width ? Number.parseFloat(col.width) : 0\n );\n\n const totalBefore = widths.reduce((sum, w) => sum + w, 0);\n\n // fallback if columns do not sum to 100: normalize them\n if (totalBefore === 0) {\n // distribute evenly if no widths\n const evenWidth = 100 / columnGroup.children.length;\n columnGroup.children.forEach((col) => {\n col.width = `${evenWidth}%`;\n });\n\n return columnGroup;\n }\n\n const index = columnGroup.children.findIndex((col) => col.id === columnId);\n\n if (index === -1) return columnGroup; // Column not found\n\n // Set the new width for the target column\n widths[index] = newWidthPercent;\n\n // Calculate the difference from total (ideally 100)\n let totalAfter = widths.reduce((sum, w) => sum + w, 0);\n\n // If total is off from 100%, adjust siblings\n // For simplicity, assume totalAfter < 100%. Add leftover to the next column.\n // You can make this logic more balanced if needed.\n const diff = 100 - totalAfter;\n\n if (diff !== 0) {\n // Find a sibling to adjust. For a simple strategy, pick the next column.\n const siblingIndex = (index + 1) % widths.length;\n widths[siblingIndex] = Math.max(widths[siblingIndex] + diff, 0);\n }\n\n // Normalize again if rounding introduced a small error\n totalAfter = widths.reduce((sum, w) => sum + w, 0);\n\n if (Math.round(totalAfter) !== 100) {\n // If you want a perfectly balanced approach:\n // Scale all widths so they sum exactly to 100\n const scale = 100 / totalAfter;\n\n for (let i = 0; i < widths.length; i++) {\n widths[i] = Number.parseFloat((widths[i] * scale).toFixed(2));\n }\n }\n\n // Update the column widths\n columnGroup.children.forEach((col, i) => {\n col.width = `${widths[i]}%`;\n });\n\n return columnGroup;\n}\n","export const columnsToWidths = ({ columns = 2 }: { columns?: number } = {}) =>\n new Array(columns).fill(null).map(() => `${100 / columns}%`);\n","import {\n type At,\n type SlateEditor,\n type TColumnElement,\n type TColumnGroupElement,\n NodeApi,\n} from 'platejs';\nimport { KEYS } from 'platejs';\n\nimport { columnsToWidths } from '../utils/columnsToWidths';\n\nexport const setColumns = (\n editor: SlateEditor,\n {\n at,\n columns,\n widths,\n }: {\n /** Column group path */\n at?: At;\n columns?: number;\n widths?: string[];\n }\n) => {\n editor.tf.withoutNormalizing(() => {\n if (!at) return;\n\n widths = widths ?? columnsToWidths({ columns });\n\n // If widths is empty, do nothing.\n if (widths.length === 0) {\n return;\n }\n\n const columnGroup = editor.api.node<TColumnGroupElement>(at);\n\n if (!columnGroup) return;\n\n const [{ children }, path] = columnGroup;\n\n const currentCount = children.length;\n const targetCount = widths.length;\n\n if (currentCount === targetCount) {\n // Same number of columns: just set widths directly\n widths.forEach((width, i) => {\n editor.tf.setNodes<TColumnElement>({ width }, { at: path.concat([i]) });\n });\n\n return;\n }\n if (targetCount > currentCount) {\n // Need more columns than we have: insert extra columns at the end\n const columnsToAdd = targetCount - currentCount;\n const insertPath = path.concat([currentCount]);\n\n // Insert the extra columns\n const newColumns = new Array(columnsToAdd).fill(null).map((_, i) => ({\n children: [editor.api.create.block()],\n type: editor.getType(KEYS.column),\n width: widths![currentCount + i] || `${100 / targetCount}%`,\n }));\n\n editor.tf.insertNodes(newColumns, { at: insertPath });\n\n // Just ensure final widths match exactly\n widths.forEach((width, i) => {\n editor.tf.setNodes<TColumnElement>({ width }, { at: path.concat([i]) });\n });\n\n return;\n }\n if (targetCount < currentCount) {\n // Need fewer columns than we have: merge extra columns into the last kept column\n const keepColumnIndex = targetCount - 1;\n const keepColumnPath = path.concat([keepColumnIndex]);\n const keepColumnNode = NodeApi.get<TColumnElement>(\n editor,\n keepColumnPath\n );\n\n if (!keepColumnNode) return;\n\n const to = keepColumnPath.concat([keepColumnNode.children.length]);\n\n // Move content from columns beyond keepIndex into keepIndex column\n for (let i = currentCount - 1; i > keepColumnIndex; i--) {\n const columnPath = path.concat([i]);\n const columnEntry = editor.api.node<TColumnElement>(columnPath);\n\n if (!columnEntry) continue;\n\n editor.tf.moveNodes({\n at: columnEntry[1],\n children: true,\n to,\n });\n }\n\n // Remove the now-empty extra columns\n // Removing from the end to avoid path shifts\n for (let i = currentCount - 1; i > keepColumnIndex; i--) {\n editor.tf.removeNodes({ at: path.concat([i]) });\n }\n\n // Set the final widths\n widths.forEach((width, i) => {\n editor.tf.setNodes<TColumnElement>({ width }, { at: path.concat([i]) });\n });\n }\n });\n};\n","import type { ReplaceNodesOptions, SlateEditor, TElement } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\nimport { columnsToWidths } from '../utils/columnsToWidths';\nimport { setColumns } from './setColumns';\n\nexport const toggleColumnGroup = (\n editor: SlateEditor,\n {\n at,\n columns = 2,\n widths,\n }: Partial<ReplaceNodesOptions> & {\n columns?: number;\n widths?: string[];\n } = {}\n) => {\n const entry = editor.api.block({ at });\n const columnGroupEntry = editor.api.block({\n above: true,\n at,\n match: { type: editor.getType(KEYS.columnGroup) },\n });\n\n if (!entry) return;\n\n const [node, path] = entry;\n\n // Check if the node is already a column_group\n if (columnGroupEntry) {\n // Node is already a column_group, just update the columns using setColumns\n setColumns(editor, { at: columnGroupEntry[1], columns, widths });\n } else {\n // Node is not a column_group, wrap it in a column_group\n const columnWidths = widths || columnsToWidths({ columns });\n\n const nodes = {\n children: new Array(columns).fill(null).map((_, index) => ({\n children: [index === 0 ? node : editor.api.create.block()],\n type: editor.getType(KEYS.column) as any,\n width: columnWidths[index],\n })),\n type: editor.getType(KEYS.columnGroup) as any,\n } as TElement;\n\n editor.tf.replaceNodes(nodes, {\n at: path,\n });\n\n editor.tf.select(editor.api.start(path.concat([0]))!);\n }\n};\n"],"mappings":";;;;AAIA,MAAaI,gBACXC,QACA,EAAEC,QAAQ,OAAO,GAAGC,YAAqD,EAAE,KACxE;AACHF,QAAOG,GAAGC,YACR;EACEC,UAAU,CAACL,OAAOM,IAAIC,OAAOC,OAAO,CAAC;EACrCC,MAAMT,OAAOU,QAAQZ,KAAKa,OAAO;EACjCV;EACD,EACDC,QACD;;;;;ACPH,MAAac,qBACXC,QACA,EACEC,UAAU,GACVC,QAAQC,YACR,GAAGC,YAGD,EAAE,KACH;CACH,MAAMC,QAAQ,MAAMJ;AAEpBD,QAAOM,GAAGC,yBAAyB;AACjCP,SAAOM,GAAGE,YACR;GACEC,UAAU,IAAIC,MAAMT,QAAQ,CAACU,KAAK,KAAK,CAACC,WAAW;IACjDH,UAAU,CAACT,OAAOa,IAAIC,OAAOC,OAAO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S,CAAC;EAE3D,MAAMe,QAAQ;GACZC,UAAU,IAAIC,MAAMjB,QAAQ,CAACkB,KAAK,KAAK,CAACC,KAAKC,GAAGC,WAAW;IACzDL,UAAU,CAACK,UAAU,IAAIT,OAAOd,OAAOM,IAAIkB,OAAOjB,OAAO,CAAC;IAC1DI,MAAMX,OAAOY,QAAQhB,KAAK6B,OAAO;IACjCC,OAAOV,aAAaO;IACrB,EAAE;GACHZ,MAAMX,OAAOY,QAAQhB,KAAKiB,YAAY;GACvC;AAEDb,SAAO2B,GAAGC,aAAaX,OAAO,EAC5BhB,IAAIc,MACL,CAAC;AAEFf,SAAO2B,GAAGE,OAAO7B,OAAOM,IAAIwB,MAAMf,KAAKgB,OAAO,CAAC,EAAE,CAAC,CAAC,CAAE"}
@@ -0,0 +1,10 @@
1
+ //#region src/react/ColumnPlugin.d.ts
2
+ declare const ColumnItemPlugin: any;
3
+ /** Enables support for columns with React-specific features. */
4
+ declare const ColumnPlugin: any;
5
+ //#endregion
6
+ //#region src/react/hooks/useDebouncePopoverOpen.d.ts
7
+ declare const useDebouncePopoverOpen: () => any;
8
+ //#endregion
9
+ export { ColumnItemPlugin, ColumnPlugin, useDebouncePopoverOpen };
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/react/ColumnPlugin.tsx","../../src/react/hooks/useDebouncePopoverOpen.ts"],"sourcesContent":[],"mappings":";cAIa;AAAb;AAGa,cAAA,YAEX,EAAA,GAAA;;;cCPW"}
@@ -0,0 +1,30 @@
1
+ import { n as BaseColumnPlugin, t as BaseColumnItemPlugin } from "../BaseColumnPlugin-BFM6r9Zm.js";
2
+ import { toPlatePlugin, useEditorSelector, useReadOnly, useSelected } from "platejs/react";
3
+ import { c } from "react-compiler-runtime";
4
+
5
+ //#region src/react/ColumnPlugin.tsx
6
+ const ColumnItemPlugin = toPlatePlugin(BaseColumnItemPlugin);
7
+ /** Enables support for columns with React-specific features. */
8
+ const ColumnPlugin = toPlatePlugin(BaseColumnPlugin, { plugins: [ColumnItemPlugin] });
9
+
10
+ //#endregion
11
+ //#region src/react/hooks/useDebouncePopoverOpen.ts
12
+ const useDebouncePopoverOpen = () => {
13
+ const $ = c(1);
14
+ const readOnly = useReadOnly();
15
+ const selected = useSelected();
16
+ let t0;
17
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
18
+ t0 = [];
19
+ $[0] = t0;
20
+ } else t0 = $[0];
21
+ const selectionCollapsed = useEditorSelector(_temp, t0);
22
+ return !readOnly && selected && selectionCollapsed;
23
+ };
24
+ function _temp(editor) {
25
+ return editor.api.isCollapsed();
26
+ }
27
+
28
+ //#endregion
29
+ export { ColumnItemPlugin, ColumnPlugin, useDebouncePopoverOpen };
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["toPlatePlugin","BaseColumnItemPlugin","BaseColumnPlugin","ColumnItemPlugin","ColumnPlugin","plugins","useEditorSelector","useReadOnly","useSelected","useDebouncePopoverOpen","$","_c","readOnly","selected","t0","Symbol","for","selectionCollapsed","_temp","editor","api","isCollapsed"],"sources":["../../src/react/ColumnPlugin.tsx","../../src/react/hooks/useDebouncePopoverOpen.ts"],"sourcesContent":["import { toPlatePlugin } from 'platejs/react';\n\nimport { BaseColumnItemPlugin, BaseColumnPlugin } from '../lib';\n\nexport const ColumnItemPlugin = toPlatePlugin(BaseColumnItemPlugin);\n\n/** Enables support for columns with React-specific features. */\nexport const ColumnPlugin = toPlatePlugin(BaseColumnPlugin, {\n plugins: [ColumnItemPlugin],\n});\n","import { useEditorSelector, useReadOnly, useSelected } from 'platejs/react';\n\nexport const useDebouncePopoverOpen = () => {\n const readOnly = useReadOnly();\n const selected = useSelected();\n\n const selectionCollapsed = useEditorSelector(\n (editor) => editor.api.isCollapsed(),\n []\n );\n\n // TODO:should add debounce\n return !readOnly && selected && selectionCollapsed;\n};\n"],"mappings":";;;;;AAIA,MAAaG,mBAAmBH,cAAcC,qBAAqB;;AAGnE,MAAaG,eAAeJ,cAAcE,kBAAkB,EAC1DG,SAAS,CAACF,iBAAgB,EAC3B,CAAC;;;;ACPF,MAAaM,+BAAyB;CAAA,MAAAC,IAAAC,EAAA,EAAA;CACpC,MAAAC,WAAiBL,aAAa;CAC9B,MAAAM,WAAiBL,aAAa;CAAC,IAAAM;AAAA,KAAAJ,EAAA,OAAAK,OAAAC,IAAA,4BAAA,EAAA;AAI7BF,OAAA,EAAE;AAAAJ,IAAA,KAAAI;OAAAA,MAAAJ,EAAA;CAFJ,MAAAO,qBAA2BX,kBACzBY,OACAJ,GACD;AAAC,QAGK,CAACF,YAADC,YAAAI;;AAV6B,SAAAC,MAAAC,QAAA;AAAA,QAKtBA,OAAMC,IAAIC,aAAc"}
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@lofcz/platejs-layout",
3
+ "version": "52.0.11",
4
+ "description": "Layout plugin for Plate",
5
+ "keywords": [
6
+ "plate",
7
+ "plugin",
8
+ "slate"
9
+ ],
10
+ "homepage": "https://platejs.org",
11
+ "bugs": {
12
+ "url": "https://github.com/udecode/plate/issues"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/lofcz/plate.git",
17
+ "directory": "packages/layout"
18
+ },
19
+ "license": "MIT",
20
+ "sideEffects": false,
21
+ "exports": {
22
+ ".": "./dist/index.js",
23
+ "./react": "./dist/react/index.js",
24
+ "./package.json": "./package.json"
25
+ },
26
+ "main": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
28
+ "files": [
29
+ "dist/**/*"
30
+ ],
31
+ "devDependencies": {
32
+ "@plate/scripts": "1.0.0"
33
+ },
34
+ "peerDependencies": {
35
+ "platejs": ">=52.0.11",
36
+ "react": ">=18.0.0",
37
+ "react-dom": ">=18.0.0"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "type": "module",
43
+ "module": "./dist/index.js",
44
+ "dependencies": {
45
+ "react-compiler-runtime": "^1.0.0"
46
+ },
47
+ "scripts": {
48
+ "brl": "plate-pkg p:brl",
49
+ "build": "plate-pkg p:build",
50
+ "build:watch": "plate-pkg p:build:watch",
51
+ "clean": "plate-pkg p:clean",
52
+ "lint": "plate-pkg p:lint",
53
+ "lint:fix": "plate-pkg p:lint:fix",
54
+ "test": "plate-pkg p:test",
55
+ "test:watch": "plate-pkg p:test:watch",
56
+ "typecheck": "plate-pkg p:typecheck"
57
+ }
58
+ }