@ctzhian/tiptap 2.5.1 → 2.6.0
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/dist/Editor/demo.js +1 -1
- package/dist/EditorMarkdown/index.js +7 -3
- package/dist/asset/css/index.css +16 -0
- package/dist/component/CustomBubbleMenu/index.js +2 -67
- package/dist/component/Icons/{flip-horizontal-2-line-icon.d.ts → flip-grid-icon.d.ts} +1 -1
- package/dist/component/Icons/{flip-horizontal-2-line-icon.js → flip-grid-icon.js} +3 -3
- package/dist/component/Icons/flip-left-line-icon.d.ts +6 -0
- package/dist/component/Icons/flip-left-line-icon.js +13 -0
- package/dist/component/Icons/flip-right-line-icon.d.ts +6 -0
- package/dist/component/Icons/flip-right-line-icon.js +13 -0
- package/dist/component/Icons/index.d.ts +3 -1
- package/dist/component/Icons/index.js +3 -1
- package/dist/component/Toolbar/EditorInsert/index.js +67 -56
- package/dist/contants/enums.d.ts +1 -0
- package/dist/contants/enums.js +11 -4
- package/dist/contants/markdown-placeholder.d.ts +1 -1
- package/dist/contants/markdown-placeholder.js +1 -1
- package/dist/contants/slash-commands.js +84 -72
- package/dist/extension/component/FlipGrid/ColumnView.d.ts +4 -0
- package/dist/extension/component/FlipGrid/ColumnView.js +191 -0
- package/dist/extension/component/FlipGrid/index.d.ts +4 -0
- package/dist/extension/component/FlipGrid/index.js +284 -0
- package/dist/extension/component/FlipGrid/utils.d.ts +24 -0
- package/dist/extension/component/FlipGrid/utils.js +180 -0
- package/dist/extension/component/SlashCommandsList/index.js +1 -1
- package/dist/extension/component/UploadProgress/index.d.ts +1 -1
- package/dist/extension/index.js +2 -2
- package/dist/extension/node/Alert.js +2 -3
- package/dist/extension/node/FileHandler.d.ts +1 -1
- package/dist/extension/node/FlipGrid.d.ts +14 -0
- package/dist/extension/node/FlipGrid.js +131 -0
- package/dist/extension/node/Table.d.ts +1 -1
- package/dist/extension/node/index.d.ts +1 -0
- package/dist/extension/node/index.js +1 -0
- package/package.json +15 -16
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { AttachmentLineIcon, BilibiliLineIcon, CodeBoxLineIcon, CodeLineIcon, DoubleQuotesLIcon, EmotionLineIcon, FlowChartIcon, FunctionsIcon, H1Icon, H2Icon, H3Icon, ImageLineIcon, Information2LineIcon, LinkIcon, ListCheck2Icon, ListOrdered2Icon, ListUnorderedIcon, MenuFold2FillIcon, MovieLineIcon, Music2LineIcon, SeparatorIcon, SquareRootIcon, Table2Icon, WindowFillIcon } from "../component/Icons";
|
|
2
|
+
import { AttachmentLineIcon, BilibiliLineIcon, CodeBoxLineIcon, CodeLineIcon, DoubleQuotesLIcon, EmotionLineIcon, FlipGridIcon, FlowChartIcon, FunctionsIcon, H1Icon, H2Icon, H3Icon, ImageLineIcon, Information2LineIcon, LinkIcon, ListCheck2Icon, ListOrdered2Icon, ListUnorderedIcon, MenuFold2FillIcon, MovieLineIcon, Music2LineIcon, SeparatorIcon, SquareRootIcon, Table2Icon, WindowFillIcon } from "../component/Icons";
|
|
3
3
|
export var slashCommands = [{
|
|
4
4
|
title: '标题1',
|
|
5
5
|
shortcutKey: ['ctrl', 'alt', '1'],
|
|
@@ -110,9 +110,8 @@ export var slashCommands = [{
|
|
|
110
110
|
editor.chain().focus().deleteRange(range).toggleTaskList().run();
|
|
111
111
|
}
|
|
112
112
|
}, {
|
|
113
|
-
title: '
|
|
114
|
-
|
|
115
|
-
icon: /*#__PURE__*/React.createElement(LinkIcon, {
|
|
113
|
+
title: '分割线',
|
|
114
|
+
icon: /*#__PURE__*/React.createElement(SeparatorIcon, {
|
|
116
115
|
sx: {
|
|
117
116
|
fontSize: '1rem'
|
|
118
117
|
}
|
|
@@ -120,14 +119,12 @@ export var slashCommands = [{
|
|
|
120
119
|
command: function command(_ref7) {
|
|
121
120
|
var editor = _ref7.editor,
|
|
122
121
|
range = _ref7.range;
|
|
123
|
-
editor.chain().focus().deleteRange(range).
|
|
124
|
-
href: ''
|
|
125
|
-
}).run();
|
|
122
|
+
editor.chain().focus().deleteRange(range).setHorizontalRule().run();
|
|
126
123
|
}
|
|
127
124
|
}, {
|
|
128
|
-
title: '
|
|
129
|
-
shortcutKey: ['ctrl', '
|
|
130
|
-
icon: /*#__PURE__*/React.createElement(
|
|
125
|
+
title: '链接',
|
|
126
|
+
shortcutKey: ['ctrl', '1'],
|
|
127
|
+
icon: /*#__PURE__*/React.createElement(LinkIcon, {
|
|
131
128
|
sx: {
|
|
132
129
|
fontSize: '1rem'
|
|
133
130
|
}
|
|
@@ -135,12 +132,13 @@ export var slashCommands = [{
|
|
|
135
132
|
command: function command(_ref8) {
|
|
136
133
|
var editor = _ref8.editor,
|
|
137
134
|
range = _ref8.range;
|
|
138
|
-
editor.chain().focus().deleteRange(range).
|
|
135
|
+
editor.chain().focus().deleteRange(range).setInlineLink({
|
|
136
|
+
href: ''
|
|
137
|
+
}).run();
|
|
139
138
|
}
|
|
140
139
|
}, {
|
|
141
|
-
title: '
|
|
142
|
-
|
|
143
|
-
icon: /*#__PURE__*/React.createElement(CodeBoxLineIcon, {
|
|
140
|
+
title: '表情',
|
|
141
|
+
icon: /*#__PURE__*/React.createElement(EmotionLineIcon, {
|
|
144
142
|
sx: {
|
|
145
143
|
fontSize: '1rem'
|
|
146
144
|
}
|
|
@@ -148,12 +146,12 @@ export var slashCommands = [{
|
|
|
148
146
|
command: function command(_ref9) {
|
|
149
147
|
var editor = _ref9.editor,
|
|
150
148
|
range = _ref9.range;
|
|
151
|
-
editor.chain().
|
|
149
|
+
editor.chain().deleteRange(range).insertContentAt(range.from, ' : ').focus(range.from + 2).run();
|
|
152
150
|
}
|
|
153
151
|
}, {
|
|
154
|
-
title: '
|
|
155
|
-
shortcutKey: ['ctrl', '
|
|
156
|
-
icon: /*#__PURE__*/React.createElement(
|
|
152
|
+
title: '行内代码',
|
|
153
|
+
shortcutKey: ['ctrl', 'E'],
|
|
154
|
+
icon: /*#__PURE__*/React.createElement(CodeLineIcon, {
|
|
157
155
|
sx: {
|
|
158
156
|
fontSize: '1rem'
|
|
159
157
|
}
|
|
@@ -161,12 +159,12 @@ export var slashCommands = [{
|
|
|
161
159
|
command: function command(_ref10) {
|
|
162
160
|
var editor = _ref10.editor,
|
|
163
161
|
range = _ref10.range;
|
|
164
|
-
editor.chain().focus().deleteRange(range).
|
|
162
|
+
editor.chain().focus().deleteRange(range).setMark('code').run();
|
|
165
163
|
}
|
|
166
164
|
}, {
|
|
167
|
-
title: '
|
|
168
|
-
shortcutKey: ['ctrl', '
|
|
169
|
-
icon: /*#__PURE__*/React.createElement(
|
|
165
|
+
title: '代码块',
|
|
166
|
+
shortcutKey: ['ctrl', 'alt', 'C'],
|
|
167
|
+
icon: /*#__PURE__*/React.createElement(CodeBoxLineIcon, {
|
|
170
168
|
sx: {
|
|
171
169
|
fontSize: '1rem'
|
|
172
170
|
}
|
|
@@ -174,11 +172,12 @@ export var slashCommands = [{
|
|
|
174
172
|
command: function command(_ref11) {
|
|
175
173
|
var editor = _ref11.editor,
|
|
176
174
|
range = _ref11.range;
|
|
177
|
-
editor.chain().focus().deleteRange(range).
|
|
175
|
+
editor.chain().focus().deleteRange(range).toggleCodeBlock().run();
|
|
178
176
|
}
|
|
179
177
|
}, {
|
|
180
|
-
title: '
|
|
181
|
-
|
|
178
|
+
title: '引用',
|
|
179
|
+
shortcutKey: ['ctrl', 'shift', 'B'],
|
|
180
|
+
icon: /*#__PURE__*/React.createElement(DoubleQuotesLIcon, {
|
|
182
181
|
sx: {
|
|
183
182
|
fontSize: '1rem'
|
|
184
183
|
}
|
|
@@ -186,14 +185,11 @@ export var slashCommands = [{
|
|
|
186
185
|
command: function command(_ref12) {
|
|
187
186
|
var editor = _ref12.editor,
|
|
188
187
|
range = _ref12.range;
|
|
189
|
-
editor.chain().focus().deleteRange(range).
|
|
190
|
-
code: '',
|
|
191
|
-
width: '100%'
|
|
192
|
-
}).run();
|
|
188
|
+
editor.chain().focus().deleteRange(range).toggleBlockquote().run();
|
|
193
189
|
}
|
|
194
190
|
}, {
|
|
195
|
-
title: '
|
|
196
|
-
icon: /*#__PURE__*/React.createElement(
|
|
191
|
+
title: '分栏',
|
|
192
|
+
icon: /*#__PURE__*/React.createElement(FlipGridIcon, {
|
|
197
193
|
sx: {
|
|
198
194
|
fontSize: '1rem'
|
|
199
195
|
}
|
|
@@ -201,11 +197,12 @@ export var slashCommands = [{
|
|
|
201
197
|
command: function command(_ref13) {
|
|
202
198
|
var editor = _ref13.editor,
|
|
203
199
|
range = _ref13.range;
|
|
204
|
-
editor.chain().
|
|
200
|
+
editor.chain().focus().deleteRange(range).setFlipGrid().run();
|
|
205
201
|
}
|
|
206
202
|
}, {
|
|
207
|
-
title: '
|
|
208
|
-
|
|
203
|
+
title: '折叠面板',
|
|
204
|
+
shortcutKey: ['ctrl', '8'],
|
|
205
|
+
icon: /*#__PURE__*/React.createElement(MenuFold2FillIcon, {
|
|
209
206
|
sx: {
|
|
210
207
|
fontSize: '1rem'
|
|
211
208
|
}
|
|
@@ -213,11 +210,11 @@ export var slashCommands = [{
|
|
|
213
210
|
command: function command(_ref14) {
|
|
214
211
|
var editor = _ref14.editor,
|
|
215
212
|
range = _ref14.range;
|
|
216
|
-
editor.chain().focus().deleteRange(range).
|
|
213
|
+
editor.chain().focus().deleteRange(range).setDetails().run();
|
|
217
214
|
}
|
|
218
215
|
}, {
|
|
219
|
-
title: '
|
|
220
|
-
icon: /*#__PURE__*/React.createElement(
|
|
216
|
+
title: '流程图',
|
|
217
|
+
icon: /*#__PURE__*/React.createElement(FlowChartIcon, {
|
|
221
218
|
sx: {
|
|
222
219
|
fontSize: '1rem'
|
|
223
220
|
}
|
|
@@ -225,6 +222,21 @@ export var slashCommands = [{
|
|
|
225
222
|
command: function command(_ref15) {
|
|
226
223
|
var editor = _ref15.editor,
|
|
227
224
|
range = _ref15.range;
|
|
225
|
+
editor.chain().focus().deleteRange(range).setFlow({
|
|
226
|
+
code: '',
|
|
227
|
+
width: '100%'
|
|
228
|
+
}).run();
|
|
229
|
+
}
|
|
230
|
+
}, {
|
|
231
|
+
title: 'Bilibili 视频',
|
|
232
|
+
icon: /*#__PURE__*/React.createElement(BilibiliLineIcon, {
|
|
233
|
+
sx: {
|
|
234
|
+
fontSize: '1rem'
|
|
235
|
+
}
|
|
236
|
+
}),
|
|
237
|
+
command: function command(_ref16) {
|
|
238
|
+
var editor = _ref16.editor,
|
|
239
|
+
range = _ref16.range;
|
|
228
240
|
editor.chain().focus().deleteRange(range).setIframe({
|
|
229
241
|
src: '',
|
|
230
242
|
width: '100%',
|
|
@@ -239,9 +251,9 @@ export var slashCommands = [{
|
|
|
239
251
|
fontSize: '1rem'
|
|
240
252
|
}
|
|
241
253
|
}),
|
|
242
|
-
command: function command(
|
|
243
|
-
var editor =
|
|
244
|
-
range =
|
|
254
|
+
command: function command(_ref17) {
|
|
255
|
+
var editor = _ref17.editor,
|
|
256
|
+
range = _ref17.range;
|
|
245
257
|
editor.chain().focus().deleteRange(range).setIframe({
|
|
246
258
|
src: '',
|
|
247
259
|
width: '100%',
|
|
@@ -257,10 +269,10 @@ export var slashCommands = [{
|
|
|
257
269
|
fontSize: '1rem'
|
|
258
270
|
}
|
|
259
271
|
}),
|
|
260
|
-
command: function command(
|
|
261
|
-
var editor =
|
|
262
|
-
range =
|
|
263
|
-
attrs =
|
|
272
|
+
command: function command(_ref18) {
|
|
273
|
+
var editor = _ref18.editor,
|
|
274
|
+
range = _ref18.range,
|
|
275
|
+
attrs = _ref18.attrs;
|
|
264
276
|
editor.chain().focus().deleteRange(range).insertTable({
|
|
265
277
|
rows: attrs.rows || 3,
|
|
266
278
|
cols: attrs.cols || 4,
|
|
@@ -274,10 +286,10 @@ export var slashCommands = [{
|
|
|
274
286
|
fontSize: '1rem'
|
|
275
287
|
}
|
|
276
288
|
}),
|
|
277
|
-
command: function command(
|
|
278
|
-
var editor =
|
|
279
|
-
range =
|
|
280
|
-
attrs =
|
|
289
|
+
command: function command(_ref19) {
|
|
290
|
+
var editor = _ref19.editor,
|
|
291
|
+
range = _ref19.range,
|
|
292
|
+
attrs = _ref19.attrs;
|
|
281
293
|
editor.chain().focus().deleteRange(range).toggleAlert({
|
|
282
294
|
type: (attrs === null || attrs === void 0 ? void 0 : attrs.type) || 'icon',
|
|
283
295
|
variant: (attrs === null || attrs === void 0 ? void 0 : attrs.variant) || 'info'
|
|
@@ -290,9 +302,9 @@ export var slashCommands = [{
|
|
|
290
302
|
fontSize: '1rem'
|
|
291
303
|
}
|
|
292
304
|
}),
|
|
293
|
-
command: function command(
|
|
294
|
-
var editor =
|
|
295
|
-
range =
|
|
305
|
+
command: function command(_ref20) {
|
|
306
|
+
var editor = _ref20.editor,
|
|
307
|
+
range = _ref20.range;
|
|
296
308
|
editor.chain().focus().deleteRange(range).setDetails().run();
|
|
297
309
|
}
|
|
298
310
|
}, {
|
|
@@ -302,9 +314,9 @@ export var slashCommands = [{
|
|
|
302
314
|
fontSize: '1rem'
|
|
303
315
|
}
|
|
304
316
|
}),
|
|
305
|
-
command: function command(
|
|
306
|
-
var editor =
|
|
307
|
-
range =
|
|
317
|
+
command: function command(_ref21) {
|
|
318
|
+
var editor = _ref21.editor,
|
|
319
|
+
range = _ref21.range;
|
|
308
320
|
editor.chain().focus().deleteRange(range).toggleCodeBlock().run();
|
|
309
321
|
}
|
|
310
322
|
}, {
|
|
@@ -314,9 +326,9 @@ export var slashCommands = [{
|
|
|
314
326
|
fontSize: '1rem'
|
|
315
327
|
}
|
|
316
328
|
}),
|
|
317
|
-
command: function command(
|
|
318
|
-
var editor =
|
|
319
|
-
range =
|
|
329
|
+
command: function command(_ref22) {
|
|
330
|
+
var editor = _ref22.editor,
|
|
331
|
+
range = _ref22.range;
|
|
320
332
|
editor.chain().focus().deleteRange(range).setInlineMath({
|
|
321
333
|
latex: ''
|
|
322
334
|
}).run();
|
|
@@ -328,9 +340,9 @@ export var slashCommands = [{
|
|
|
328
340
|
fontSize: '1rem'
|
|
329
341
|
}
|
|
330
342
|
}),
|
|
331
|
-
command: function command(
|
|
332
|
-
var editor =
|
|
333
|
-
range =
|
|
343
|
+
command: function command(_ref23) {
|
|
344
|
+
var editor = _ref23.editor,
|
|
345
|
+
range = _ref23.range;
|
|
334
346
|
editor.chain().focus().deleteRange(range).setBlockMath({
|
|
335
347
|
latex: ''
|
|
336
348
|
}).run();
|
|
@@ -342,9 +354,9 @@ export var slashCommands = [{
|
|
|
342
354
|
fontSize: '1rem'
|
|
343
355
|
}
|
|
344
356
|
}),
|
|
345
|
-
command: function command(
|
|
346
|
-
var editor =
|
|
347
|
-
range =
|
|
357
|
+
command: function command(_ref24) {
|
|
358
|
+
var editor = _ref24.editor,
|
|
359
|
+
range = _ref24.range;
|
|
348
360
|
editor.chain().focus().deleteRange(range).setImage({
|
|
349
361
|
src: '',
|
|
350
362
|
width: 760
|
|
@@ -357,9 +369,9 @@ export var slashCommands = [{
|
|
|
357
369
|
fontSize: '1rem'
|
|
358
370
|
}
|
|
359
371
|
}),
|
|
360
|
-
command: function command(
|
|
361
|
-
var editor =
|
|
362
|
-
range =
|
|
372
|
+
command: function command(_ref25) {
|
|
373
|
+
var editor = _ref25.editor,
|
|
374
|
+
range = _ref25.range;
|
|
363
375
|
editor.chain().focus().deleteRange(range).setVideo({
|
|
364
376
|
src: '',
|
|
365
377
|
width: 760
|
|
@@ -372,9 +384,9 @@ export var slashCommands = [{
|
|
|
372
384
|
fontSize: '1rem'
|
|
373
385
|
}
|
|
374
386
|
}),
|
|
375
|
-
command: function command(
|
|
376
|
-
var editor =
|
|
377
|
-
range =
|
|
387
|
+
command: function command(_ref26) {
|
|
388
|
+
var editor = _ref26.editor,
|
|
389
|
+
range = _ref26.range;
|
|
378
390
|
editor.chain().focus().deleteRange(range).setAudio({
|
|
379
391
|
src: ''
|
|
380
392
|
}).run();
|
|
@@ -386,9 +398,9 @@ export var slashCommands = [{
|
|
|
386
398
|
fontSize: '1rem'
|
|
387
399
|
}
|
|
388
400
|
}),
|
|
389
|
-
command: function command(
|
|
390
|
-
var editor =
|
|
391
|
-
range =
|
|
401
|
+
command: function command(_ref27) {
|
|
402
|
+
var editor = _ref27.editor,
|
|
403
|
+
range = _ref27.range;
|
|
392
404
|
editor.chain().focus().deleteRange(range).setInlineAttachment({
|
|
393
405
|
url: '',
|
|
394
406
|
title: '',
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { HoverPopover } from "../../../component/HoverPopover";
|
|
2
|
+
import { DeleteLineIcon, FlipLeftLineIcon, FlipRightLineIcon } from "../../../component/Icons";
|
|
3
|
+
import { ToolbarItem } from "../../../component/Toolbar";
|
|
4
|
+
import { Divider, Stack } from '@mui/material';
|
|
5
|
+
import { NodeViewContent, NodeViewWrapper } from '@tiptap/react';
|
|
6
|
+
import React, { useEffect, useMemo, useRef } from 'react';
|
|
7
|
+
import { MAX_COLUMNS, MIN_WIDTH } from "../../node/FlipGrid";
|
|
8
|
+
import { applyFlipGridWidths, collectWidths, findChildIndex, findFlipGridAncestor, normalizeWithMin } from "./utils";
|
|
9
|
+
var ColumnView = function ColumnView(_ref) {
|
|
10
|
+
var node = _ref.node,
|
|
11
|
+
editor = _ref.editor,
|
|
12
|
+
getPos = _ref.getPos;
|
|
13
|
+
var widths = useMemo(function () {
|
|
14
|
+
var pos = typeof getPos === 'function' ? getPos() : getPos;
|
|
15
|
+
if (typeof pos !== 'number') return [];
|
|
16
|
+
var $pos = editor.state.doc.resolve(pos);
|
|
17
|
+
var found = findFlipGridAncestor($pos);
|
|
18
|
+
if (!found) return [];
|
|
19
|
+
var parent = found.node;
|
|
20
|
+
var list = collectWidths(parent);
|
|
21
|
+
var total = list.reduce(function (acc, cur) {
|
|
22
|
+
return acc + cur;
|
|
23
|
+
}, 0);
|
|
24
|
+
if (!Number.isFinite(total) || total <= 0 || total > 100000) {
|
|
25
|
+
var fallback = parent.childCount > 0 ? 100 / parent.childCount : 0;
|
|
26
|
+
return normalizeWithMin(new Array(parent.childCount).fill(fallback), MIN_WIDTH);
|
|
27
|
+
}
|
|
28
|
+
return normalizeWithMin(list, MIN_WIDTH);
|
|
29
|
+
}, [node, getPos]);
|
|
30
|
+
var applyWidths = function applyWidths(nextWidths, insertAt, removeIndex, focusIndex) {
|
|
31
|
+
var state = editor.state,
|
|
32
|
+
view = editor.view;
|
|
33
|
+
var pos = typeof getPos === 'function' ? getPos() : getPos;
|
|
34
|
+
if (typeof pos !== 'number') return false;
|
|
35
|
+
var $pos = state.doc.resolve(pos);
|
|
36
|
+
var found = findFlipGridAncestor($pos);
|
|
37
|
+
if (!found) {
|
|
38
|
+
console.warn('[FlipGrid] parent not found for applyWidths', {
|
|
39
|
+
pos: pos,
|
|
40
|
+
depth: $pos.depth
|
|
41
|
+
});
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
var parent = found.node,
|
|
45
|
+
parentDepth = found.depth;
|
|
46
|
+
var parentPos = $pos.start(parentDepth) - 1;
|
|
47
|
+
if (!Number.isFinite(parentPos) || parentPos < 0) return false;
|
|
48
|
+
var tr = state.tr;
|
|
49
|
+
var _applyFlipGridWidths = applyFlipGridWidths({
|
|
50
|
+
tr: tr,
|
|
51
|
+
parentNode: parent,
|
|
52
|
+
parentPos: parentPos,
|
|
53
|
+
nextWidths: nextWidths,
|
|
54
|
+
minWidth: MIN_WIDTH,
|
|
55
|
+
insertAt: insertAt,
|
|
56
|
+
removeIndex: removeIndex,
|
|
57
|
+
selection: state.selection,
|
|
58
|
+
focusIndex: focusIndex
|
|
59
|
+
}),
|
|
60
|
+
changed = _applyFlipGridWidths.changed;
|
|
61
|
+
if (changed) {
|
|
62
|
+
view.dispatch(tr);
|
|
63
|
+
if (typeof focusIndex === 'number') {
|
|
64
|
+
view.focus();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return changed;
|
|
68
|
+
};
|
|
69
|
+
var handleInsert = function handleInsert(direction) {
|
|
70
|
+
if (!editor.isEditable) return;
|
|
71
|
+
var pos = typeof getPos === 'function' ? getPos() : getPos;
|
|
72
|
+
if (typeof pos !== 'number') return;
|
|
73
|
+
var $pos = editor.state.doc.resolve(pos);
|
|
74
|
+
var found = findFlipGridAncestor($pos);
|
|
75
|
+
if (!found) {
|
|
76
|
+
console.warn('[FlipGrid] parent not found for insert', {
|
|
77
|
+
pos: pos,
|
|
78
|
+
depth: $pos.depth
|
|
79
|
+
});
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
var parent = found.node,
|
|
83
|
+
parentDepth = found.depth;
|
|
84
|
+
var colIndex = findChildIndex(parent, node);
|
|
85
|
+
if (colIndex < 0) return;
|
|
86
|
+
if (parent.childCount >= MAX_COLUMNS) return;
|
|
87
|
+
var insertIndex = direction === 'left' ? colIndex : colIndex + 1;
|
|
88
|
+
var currentWidths = collectWidths(parent);
|
|
89
|
+
var newWidth = Math.max(MIN_WIDTH, Number((100 / (parent.childCount + 1)).toFixed(2)));
|
|
90
|
+
var shrinkFactor = (100 - newWidth) / 100;
|
|
91
|
+
var nextWidths = currentWidths.map(function (w) {
|
|
92
|
+
return w * shrinkFactor;
|
|
93
|
+
});
|
|
94
|
+
nextWidths.splice(insertIndex, 0, newWidth);
|
|
95
|
+
applyWidths(nextWidths, insertIndex, undefined, insertIndex);
|
|
96
|
+
};
|
|
97
|
+
var handleDelete = function handleDelete() {
|
|
98
|
+
if (!editor.isEditable) return;
|
|
99
|
+
var pos = typeof getPos === 'function' ? getPos() : getPos;
|
|
100
|
+
if (typeof pos !== 'number') return;
|
|
101
|
+
var $pos = editor.state.doc.resolve(pos);
|
|
102
|
+
var found = findFlipGridAncestor($pos);
|
|
103
|
+
if (!found) {
|
|
104
|
+
console.warn('[FlipGrid] parent not found for delete', {
|
|
105
|
+
pos: pos,
|
|
106
|
+
depth: $pos.depth
|
|
107
|
+
});
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
var parent = found.node,
|
|
111
|
+
parentDepth = found.depth;
|
|
112
|
+
if (parent.childCount <= 2) return;
|
|
113
|
+
var colIndex = findChildIndex(parent, node);
|
|
114
|
+
if (colIndex < 0) return;
|
|
115
|
+
var currentWidths = collectWidths(parent);
|
|
116
|
+
var nextWidths = currentWidths.filter(function (_, idx) {
|
|
117
|
+
return idx !== colIndex;
|
|
118
|
+
});
|
|
119
|
+
var targetFocus = Math.max(0, Math.min(colIndex - 1, nextWidths.length - 1));
|
|
120
|
+
applyWidths(nextWidths, undefined, colIndex, targetFocus);
|
|
121
|
+
};
|
|
122
|
+
var wrapperRef = useRef(null);
|
|
123
|
+
useEffect(function () {
|
|
124
|
+
var _ref2, _node$attrs$width;
|
|
125
|
+
var parent = (_ref2 = wrapperRef.current || null) === null || _ref2 === void 0 ? void 0 : _ref2.parentElement;
|
|
126
|
+
if (!parent) return;
|
|
127
|
+
parent.style.width = "".concat((_node$attrs$width = node.attrs.width) !== null && _node$attrs$width !== void 0 ? _node$attrs$width : 0, "%");
|
|
128
|
+
}, [node.attrs.width]);
|
|
129
|
+
return /*#__PURE__*/React.createElement(NodeViewWrapper, {
|
|
130
|
+
as: "div",
|
|
131
|
+
ref: wrapperRef,
|
|
132
|
+
"data-type": "flip-grid-column",
|
|
133
|
+
style: {
|
|
134
|
+
width: '100%',
|
|
135
|
+
height: '100%',
|
|
136
|
+
position: 'relative'
|
|
137
|
+
}
|
|
138
|
+
}, editor.isEditable ? /*#__PURE__*/React.createElement(HoverPopover, {
|
|
139
|
+
placement: "top",
|
|
140
|
+
offset: 4,
|
|
141
|
+
actions: /*#__PURE__*/React.createElement(Stack, {
|
|
142
|
+
direction: 'row',
|
|
143
|
+
alignItems: 'center',
|
|
144
|
+
sx: {
|
|
145
|
+
p: 0.5
|
|
146
|
+
}
|
|
147
|
+
}, /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
148
|
+
icon: /*#__PURE__*/React.createElement(FlipLeftLineIcon, {
|
|
149
|
+
sx: {
|
|
150
|
+
fontSize: '1rem'
|
|
151
|
+
}
|
|
152
|
+
}),
|
|
153
|
+
text: "\u5DE6\u4FA7\u63D2\u5165",
|
|
154
|
+
onClick: function onClick() {
|
|
155
|
+
return handleInsert('left');
|
|
156
|
+
}
|
|
157
|
+
}), /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
158
|
+
icon: /*#__PURE__*/React.createElement(FlipRightLineIcon, {
|
|
159
|
+
sx: {
|
|
160
|
+
fontSize: '1rem'
|
|
161
|
+
}
|
|
162
|
+
}),
|
|
163
|
+
text: "\u53F3\u4FA7\u63D2\u5165",
|
|
164
|
+
onClick: function onClick() {
|
|
165
|
+
return handleInsert('right');
|
|
166
|
+
}
|
|
167
|
+
}), widths.length > 2 && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Divider, {
|
|
168
|
+
orientation: "vertical",
|
|
169
|
+
flexItem: true,
|
|
170
|
+
sx: {
|
|
171
|
+
height: '1rem',
|
|
172
|
+
mx: 0.5,
|
|
173
|
+
alignSelf: 'center',
|
|
174
|
+
borderColor: 'divider'
|
|
175
|
+
}
|
|
176
|
+
}), /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
177
|
+
icon: /*#__PURE__*/React.createElement(DeleteLineIcon, {
|
|
178
|
+
sx: {
|
|
179
|
+
fontSize: '1rem'
|
|
180
|
+
}
|
|
181
|
+
}),
|
|
182
|
+
tip: "\u5220\u9664\u5F53\u524D\u680F",
|
|
183
|
+
onClick: handleDelete
|
|
184
|
+
})))
|
|
185
|
+
}, /*#__PURE__*/React.createElement(NodeViewContent, {
|
|
186
|
+
className: "flip-grid-column-inner"
|
|
187
|
+
})) : /*#__PURE__*/React.createElement(NodeViewContent, {
|
|
188
|
+
className: "flip-grid-column-inner"
|
|
189
|
+
}));
|
|
190
|
+
};
|
|
191
|
+
export default ColumnView;
|