@ctzhian/tiptap 2.5.2 → 2.6.1
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/asset/css/index.css +16 -0
- package/dist/component/CustomBubbleMenu/index.js +1 -1
- 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 +2 -0
- package/dist/component/Icons/index.js +2 -0
- package/dist/component/Toolbar/EditorInsert/index.js +13 -9
- 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/Attachment.js +4 -4
- package/dist/extension/node/FlipGrid.d.ts +14 -0
- package/dist/extension/node/FlipGrid.js +131 -0
- package/dist/extension/node/index.d.ts +1 -0
- package/dist/extension/node/index.js +1 -0
- package/package.json +1 -2
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
4
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
5
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
6
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
9
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
10
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
11
|
+
import { alpha, Box, useTheme } from '@mui/material';
|
|
12
|
+
import { NodeViewContent, NodeViewWrapper } from '@tiptap/react';
|
|
13
|
+
import React, { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
14
|
+
import { DEFAULT_GAP, MIN_WIDTH } from "../../node/FlipGrid";
|
|
15
|
+
import { applyFlipGridWidths, collectWidths, normalizeWithMin } from "./utils";
|
|
16
|
+
var clampPair = function clampPair(left, right, delta) {
|
|
17
|
+
var nextLeft = Math.min(Math.max(left + delta, MIN_WIDTH), left + right - MIN_WIDTH);
|
|
18
|
+
var nextRight = left + right - nextLeft;
|
|
19
|
+
return [nextLeft, nextRight];
|
|
20
|
+
};
|
|
21
|
+
var FlipGridView = function FlipGridView(_ref) {
|
|
22
|
+
var node = _ref.node,
|
|
23
|
+
editor = _ref.editor,
|
|
24
|
+
getPos = _ref.getPos;
|
|
25
|
+
var theme = useTheme();
|
|
26
|
+
var containerRef = useRef(null);
|
|
27
|
+
var cleanupRef = useRef(null);
|
|
28
|
+
var _useState = useState(false),
|
|
29
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
30
|
+
hovering = _useState2[0],
|
|
31
|
+
setHovering = _useState2[1];
|
|
32
|
+
var _useState3 = useState(null),
|
|
33
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
34
|
+
hoverGapIndex = _useState4[0],
|
|
35
|
+
setHoverGapIndex = _useState4[1];
|
|
36
|
+
var _useState5 = useState(null),
|
|
37
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
38
|
+
dragIndex = _useState6[0],
|
|
39
|
+
setDragIndex = _useState6[1];
|
|
40
|
+
var _useState7 = useState(false),
|
|
41
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
42
|
+
showPercents = _useState8[0],
|
|
43
|
+
setShowPercents = _useState8[1];
|
|
44
|
+
var _useState9 = useState(1),
|
|
45
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
46
|
+
containerWidth = _useState10[0],
|
|
47
|
+
setContainerWidth = _useState10[1];
|
|
48
|
+
var _useState11 = useState(function () {
|
|
49
|
+
var parsed = parseFloat(DEFAULT_GAP || '0');
|
|
50
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
51
|
+
}),
|
|
52
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
53
|
+
gapPx = _useState12[0],
|
|
54
|
+
setGapPx = _useState12[1];
|
|
55
|
+
var widths = useMemo(function () {
|
|
56
|
+
return collectWidths(node);
|
|
57
|
+
}, [node]);
|
|
58
|
+
var safeWidths = useMemo(function () {
|
|
59
|
+
return normalizeWithMin(widths, MIN_WIDTH);
|
|
60
|
+
}, [widths]);
|
|
61
|
+
useLayoutEffect(function () {
|
|
62
|
+
var element = containerRef.current;
|
|
63
|
+
if (!element) return;
|
|
64
|
+
var updateMetrics = function updateMetrics() {
|
|
65
|
+
var content = element.querySelector('[data-node-view-content-react]') || element.querySelector('[data-node-view-content]');
|
|
66
|
+
var contentWidth = content === null || content === void 0 ? void 0 : content.getBoundingClientRect().width;
|
|
67
|
+
var nextWidth = Math.max(1, contentWidth || element.getBoundingClientRect().width || 1);
|
|
68
|
+
var gapValue = content ? getComputedStyle(content).gap : DEFAULT_GAP;
|
|
69
|
+
var parsedGap = parseFloat(gapValue || '0');
|
|
70
|
+
var nextGap = Number.isFinite(parsedGap) ? parsedGap : 0;
|
|
71
|
+
setContainerWidth(function (prev) {
|
|
72
|
+
return prev !== nextWidth ? nextWidth : prev;
|
|
73
|
+
});
|
|
74
|
+
setGapPx(function (prev) {
|
|
75
|
+
return prev !== nextGap ? nextGap : prev;
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
updateMetrics();
|
|
79
|
+
var observer = new ResizeObserver(updateMetrics);
|
|
80
|
+
observer.observe(element);
|
|
81
|
+
return function () {
|
|
82
|
+
observer.disconnect();
|
|
83
|
+
};
|
|
84
|
+
}, []);
|
|
85
|
+
var layout = useMemo(function () {
|
|
86
|
+
var gapsTotal = gapPx * Math.max(0, safeWidths.length - 1);
|
|
87
|
+
var availableWidth = Math.max(1, containerWidth - gapsTotal);
|
|
88
|
+
var widthsPx = safeWidths.map(function (w) {
|
|
89
|
+
return w / 100 * availableWidth;
|
|
90
|
+
});
|
|
91
|
+
var accPx = 0;
|
|
92
|
+
var handlePercents = [];
|
|
93
|
+
var labelPercents = [];
|
|
94
|
+
widthsPx.forEach(function (w, idx) {
|
|
95
|
+
var startPx = accPx;
|
|
96
|
+
var labelPx = startPx + w;
|
|
97
|
+
labelPercents.push(labelPx / containerWidth * 100);
|
|
98
|
+
accPx += w;
|
|
99
|
+
if (idx < widthsPx.length - 1) {
|
|
100
|
+
var centerPx = accPx + gapPx / 2;
|
|
101
|
+
handlePercents.push(centerPx / containerWidth * 100);
|
|
102
|
+
accPx += gapPx;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
return {
|
|
106
|
+
handlePercents: handlePercents,
|
|
107
|
+
labelPercents: labelPercents
|
|
108
|
+
};
|
|
109
|
+
}, [safeWidths, node.childCount, gapPx, containerWidth]);
|
|
110
|
+
var applyWidths = function applyWidths(nextWidths, insertAt) {
|
|
111
|
+
if (!(editor !== null && editor !== void 0 && editor.state)) return;
|
|
112
|
+
var position = typeof getPos === 'function' ? getPos() : getPos;
|
|
113
|
+
if (typeof position !== 'number') return;
|
|
114
|
+
var tr = editor.state.tr;
|
|
115
|
+
var _applyFlipGridWidths = applyFlipGridWidths({
|
|
116
|
+
tr: tr,
|
|
117
|
+
parentNode: node,
|
|
118
|
+
parentPos: position,
|
|
119
|
+
nextWidths: nextWidths,
|
|
120
|
+
minWidth: MIN_WIDTH,
|
|
121
|
+
insertAt: insertAt,
|
|
122
|
+
selection: editor.state.selection
|
|
123
|
+
}),
|
|
124
|
+
changed = _applyFlipGridWidths.changed;
|
|
125
|
+
if (changed) {
|
|
126
|
+
editor.view.dispatch(tr);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
useEffect(function () {
|
|
130
|
+
if (widths.length !== safeWidths.length) {
|
|
131
|
+
applyWidths(safeWidths);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
var diff = widths.some(function (w, idx) {
|
|
135
|
+
return Math.abs(w - safeWidths[idx]) > 0.01;
|
|
136
|
+
});
|
|
137
|
+
if (diff) {
|
|
138
|
+
applyWidths(safeWidths);
|
|
139
|
+
}
|
|
140
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
141
|
+
}, [widths, safeWidths]);
|
|
142
|
+
var handleResizeStart = function handleResizeStart(index, event) {
|
|
143
|
+
var _containerRef$current;
|
|
144
|
+
event.preventDefault();
|
|
145
|
+
event.stopPropagation();
|
|
146
|
+
if (!editor.isEditable) return;
|
|
147
|
+
var containerWidth = ((_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.getBoundingClientRect().width) || 1;
|
|
148
|
+
var startX = event.clientX;
|
|
149
|
+
var startWidths = _toConsumableArray(safeWidths);
|
|
150
|
+
setDragIndex(index);
|
|
151
|
+
setShowPercents(true);
|
|
152
|
+
var rafId = null;
|
|
153
|
+
var handleMouseMove = function handleMouseMove(e) {
|
|
154
|
+
if (rafId) return;
|
|
155
|
+
rafId = requestAnimationFrame(function () {
|
|
156
|
+
rafId = null;
|
|
157
|
+
var deltaPx = e.clientX - startX;
|
|
158
|
+
var deltaPercent = deltaPx / containerWidth * 100;
|
|
159
|
+
var _clampPair = clampPair(startWidths[index], startWidths[index + 1], deltaPercent),
|
|
160
|
+
_clampPair2 = _slicedToArray(_clampPair, 2),
|
|
161
|
+
nextLeft = _clampPair2[0],
|
|
162
|
+
nextRight = _clampPair2[1];
|
|
163
|
+
var nextWidths = _toConsumableArray(startWidths);
|
|
164
|
+
nextWidths[index] = nextLeft;
|
|
165
|
+
nextWidths[index + 1] = nextRight;
|
|
166
|
+
applyWidths(nextWidths);
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
var handleMouseUp = function handleMouseUp() {
|
|
170
|
+
setDragIndex(null);
|
|
171
|
+
setShowPercents(false);
|
|
172
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
173
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
|
174
|
+
if (rafId) {
|
|
175
|
+
cancelAnimationFrame(rafId);
|
|
176
|
+
rafId = null;
|
|
177
|
+
}
|
|
178
|
+
cleanupRef.current = null;
|
|
179
|
+
};
|
|
180
|
+
document.addEventListener('mousemove', handleMouseMove);
|
|
181
|
+
document.addEventListener('mouseup', handleMouseUp);
|
|
182
|
+
cleanupRef.current = function () {
|
|
183
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
184
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
useEffect(function () {
|
|
188
|
+
return function () {
|
|
189
|
+
var _cleanupRef$current;
|
|
190
|
+
(_cleanupRef$current = cleanupRef.current) === null || _cleanupRef$current === void 0 || _cleanupRef$current.call(cleanupRef);
|
|
191
|
+
};
|
|
192
|
+
}, []);
|
|
193
|
+
var showHandles = (editor === null || editor === void 0 ? void 0 : editor.isEditable) && (hovering || dragIndex !== null || hoverGapIndex !== null);
|
|
194
|
+
return /*#__PURE__*/React.createElement(NodeViewWrapper, {
|
|
195
|
+
ref: containerRef,
|
|
196
|
+
as: "div",
|
|
197
|
+
onMouseEnter: function onMouseEnter() {
|
|
198
|
+
return setHovering(true);
|
|
199
|
+
},
|
|
200
|
+
onMouseLeave: function onMouseLeave() {
|
|
201
|
+
return !dragIndex && setHovering(false);
|
|
202
|
+
},
|
|
203
|
+
"data-type": "flip-grid",
|
|
204
|
+
style: {
|
|
205
|
+
position: 'relative'
|
|
206
|
+
}
|
|
207
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
208
|
+
sx: {
|
|
209
|
+
'.flip-grid-content > div[data-node-view-content-react]': {
|
|
210
|
+
display: 'flex',
|
|
211
|
+
gap: DEFAULT_GAP,
|
|
212
|
+
alignItems: 'stretch',
|
|
213
|
+
position: 'relative'
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}, /*#__PURE__*/React.createElement(NodeViewContent, {
|
|
217
|
+
className: "flip-grid-content"
|
|
218
|
+
})), (editor === null || editor === void 0 ? void 0 : editor.isEditable) && /*#__PURE__*/React.createElement(React.Fragment, null, layout.handlePercents.map(function (percent, index) {
|
|
219
|
+
var gapActive = dragIndex !== null || hoverGapIndex === index;
|
|
220
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
221
|
+
key: index,
|
|
222
|
+
sx: {
|
|
223
|
+
position: 'absolute',
|
|
224
|
+
left: "".concat(percent, "%"),
|
|
225
|
+
width: gapPx,
|
|
226
|
+
top: 0,
|
|
227
|
+
bottom: 0,
|
|
228
|
+
transform: 'translateX(-50%)',
|
|
229
|
+
display: 'flex',
|
|
230
|
+
alignItems: 'center',
|
|
231
|
+
justifyContent: 'center',
|
|
232
|
+
pointerEvents: 'auto',
|
|
233
|
+
zIndex: 2,
|
|
234
|
+
':hover > div': {
|
|
235
|
+
bgcolor: alpha(theme.palette.primary.main, 0.7)
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
onMouseEnter: function onMouseEnter() {
|
|
239
|
+
return setHoverGapIndex(index);
|
|
240
|
+
},
|
|
241
|
+
onMouseLeave: function onMouseLeave() {
|
|
242
|
+
return setHoverGapIndex(null);
|
|
243
|
+
}
|
|
244
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
245
|
+
sx: {
|
|
246
|
+
position: 'absolute',
|
|
247
|
+
left: '50%',
|
|
248
|
+
height: 'calc(100% - 16px)',
|
|
249
|
+
width: 2,
|
|
250
|
+
minHeight: 16,
|
|
251
|
+
borderRadius: '4px',
|
|
252
|
+
cursor: 'ew-resize',
|
|
253
|
+
opacity: showHandles && gapActive ? 1 : 0,
|
|
254
|
+
transition: 'opacity 0.2s ease',
|
|
255
|
+
pointerEvents: 'auto',
|
|
256
|
+
transform: 'translate(-50%, 0)'
|
|
257
|
+
},
|
|
258
|
+
onMouseDown: function onMouseDown(e) {
|
|
259
|
+
return handleResizeStart(index, e);
|
|
260
|
+
}
|
|
261
|
+
}));
|
|
262
|
+
}), showPercents && layout.labelPercents.map(function (offset, idx) {
|
|
263
|
+
var _safeWidths$idx;
|
|
264
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
265
|
+
key: "percent-".concat(idx),
|
|
266
|
+
sx: {
|
|
267
|
+
position: 'absolute',
|
|
268
|
+
top: 4,
|
|
269
|
+
left: "calc(".concat(offset, "% - 4px)"),
|
|
270
|
+
transform: 'translate(-100%, 0)',
|
|
271
|
+
px: 0.75,
|
|
272
|
+
py: 0.25,
|
|
273
|
+
borderRadius: '4px',
|
|
274
|
+
bgcolor: 'rgba(0,0,0,0.5)',
|
|
275
|
+
color: '#fff',
|
|
276
|
+
fontSize: '10px',
|
|
277
|
+
lineHeight: 1.2,
|
|
278
|
+
pointerEvents: 'none',
|
|
279
|
+
whiteSpace: 'nowrap'
|
|
280
|
+
}
|
|
281
|
+
}, "".concat(Math.round((_safeWidths$idx = safeWidths[idx]) !== null && _safeWidths$idx !== void 0 ? _safeWidths$idx : 0), "%"));
|
|
282
|
+
})));
|
|
283
|
+
};
|
|
284
|
+
export default FlipGridView;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Node as PMNode, ResolvedPos } from '@tiptap/pm/model';
|
|
2
|
+
import type { Selection, Transaction } from '@tiptap/pm/state';
|
|
3
|
+
export declare const normalizeWithMin: (widths: number[], minWidth: number) => number[];
|
|
4
|
+
export declare const findFlipGridAncestor: ($pos: ResolvedPos) => {
|
|
5
|
+
node: PMNode;
|
|
6
|
+
depth: number;
|
|
7
|
+
} | null;
|
|
8
|
+
export declare const findChildIndex: (parent: PMNode, node: PMNode) => number;
|
|
9
|
+
export declare const collectWidths: (parent: PMNode) => number[];
|
|
10
|
+
type AdjustParams = {
|
|
11
|
+
tr: Transaction;
|
|
12
|
+
parentNode: PMNode;
|
|
13
|
+
parentPos: number;
|
|
14
|
+
nextWidths: number[];
|
|
15
|
+
minWidth: number;
|
|
16
|
+
insertAt?: number;
|
|
17
|
+
removeIndex?: number;
|
|
18
|
+
selection?: Selection;
|
|
19
|
+
focusIndex?: number;
|
|
20
|
+
};
|
|
21
|
+
export declare const applyFlipGridWidths: ({ tr, parentNode, parentPos, nextWidths, minWidth, insertAt, removeIndex, selection, focusIndex, }: AdjustParams) => {
|
|
22
|
+
changed: boolean;
|
|
23
|
+
};
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
import { TextSelection } from '@tiptap/pm/state';
|
|
8
|
+
export var normalizeWithMin = function normalizeWithMin(widths, minWidth) {
|
|
9
|
+
var total = widths.reduce(function (acc, cur) {
|
|
10
|
+
return acc + cur;
|
|
11
|
+
}, 0) || 1;
|
|
12
|
+
var normalized = widths.map(function (w) {
|
|
13
|
+
return w / total * 100;
|
|
14
|
+
});
|
|
15
|
+
var deficit = 0;
|
|
16
|
+
normalized = normalized.map(function (w) {
|
|
17
|
+
if (w < minWidth) {
|
|
18
|
+
deficit += minWidth - w;
|
|
19
|
+
return minWidth;
|
|
20
|
+
}
|
|
21
|
+
return w;
|
|
22
|
+
});
|
|
23
|
+
if (deficit > 0) {
|
|
24
|
+
var adjustable = normalized.map(function (w, idx) {
|
|
25
|
+
return {
|
|
26
|
+
w: w,
|
|
27
|
+
idx: idx
|
|
28
|
+
};
|
|
29
|
+
}).filter(function (item) {
|
|
30
|
+
return item.w > minWidth;
|
|
31
|
+
});
|
|
32
|
+
var adjustableTotal = adjustable.reduce(function (acc, cur) {
|
|
33
|
+
return acc + (cur.w - minWidth);
|
|
34
|
+
}, 0);
|
|
35
|
+
if (adjustableTotal > 0) {
|
|
36
|
+
adjustable.forEach(function (item) {
|
|
37
|
+
var reduceValue = deficit * ((item.w - minWidth) / adjustableTotal);
|
|
38
|
+
normalized[item.idx] = Math.max(minWidth, item.w - reduceValue);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
var finalTotal = normalized.reduce(function (acc, cur) {
|
|
43
|
+
return acc + cur;
|
|
44
|
+
}, 0) || 1;
|
|
45
|
+
return normalized.map(function (w) {
|
|
46
|
+
return Number((w / finalTotal * 100).toFixed(2));
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
export var findFlipGridAncestor = function findFlipGridAncestor($pos) {
|
|
50
|
+
for (var d = $pos.depth; d >= 0; d -= 1) {
|
|
51
|
+
var _candidate$type;
|
|
52
|
+
var candidate = $pos.node(d);
|
|
53
|
+
if ((candidate === null || candidate === void 0 || (_candidate$type = candidate.type) === null || _candidate$type === void 0 ? void 0 : _candidate$type.name) === 'flipGrid') {
|
|
54
|
+
return {
|
|
55
|
+
node: candidate,
|
|
56
|
+
depth: d
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
};
|
|
62
|
+
export var findChildIndex = function findChildIndex(parent, node) {
|
|
63
|
+
for (var i = 0; i < parent.childCount; i += 1) {
|
|
64
|
+
if (parent.child(i) === node) return i;
|
|
65
|
+
}
|
|
66
|
+
return -1;
|
|
67
|
+
};
|
|
68
|
+
export var collectWidths = function collectWidths(parent) {
|
|
69
|
+
var list = [];
|
|
70
|
+
for (var i = 0; i < parent.childCount; i += 1) {
|
|
71
|
+
var _child$attrs$width;
|
|
72
|
+
var child = parent.child(i);
|
|
73
|
+
var raw = Number((_child$attrs$width = child.attrs.width) !== null && _child$attrs$width !== void 0 ? _child$attrs$width : 0);
|
|
74
|
+
list.push(Number.isFinite(raw) ? raw : 0);
|
|
75
|
+
}
|
|
76
|
+
return list;
|
|
77
|
+
};
|
|
78
|
+
export var applyFlipGridWidths = function applyFlipGridWidths(_ref) {
|
|
79
|
+
var tr = _ref.tr,
|
|
80
|
+
parentNode = _ref.parentNode,
|
|
81
|
+
parentPos = _ref.parentPos,
|
|
82
|
+
nextWidths = _ref.nextWidths,
|
|
83
|
+
minWidth = _ref.minWidth,
|
|
84
|
+
insertAt = _ref.insertAt,
|
|
85
|
+
removeIndex = _ref.removeIndex,
|
|
86
|
+
selection = _ref.selection,
|
|
87
|
+
focusIndex = _ref.focusIndex;
|
|
88
|
+
if (parentPos < 0) return {
|
|
89
|
+
changed: false
|
|
90
|
+
};
|
|
91
|
+
var mappedWidths = normalizeWithMin(nextWidths, minWidth);
|
|
92
|
+
var colType = tr.doc.type.schema.nodes.flipGridColumn;
|
|
93
|
+
var paragraphType = tr.doc.type.schema.nodes.paragraph;
|
|
94
|
+
if (!colType || !paragraphType) return {
|
|
95
|
+
changed: false
|
|
96
|
+
};
|
|
97
|
+
var onlyResize = mappedWidths.length === parentNode.childCount && typeof insertAt === 'undefined' && typeof removeIndex === 'undefined';
|
|
98
|
+
if (onlyResize) {
|
|
99
|
+
var basePos = parentPos + 1;
|
|
100
|
+
var offset = 0;
|
|
101
|
+
for (var i = 0; i < parentNode.childCount; i += 1) {
|
|
102
|
+
var child = parentNode.child(i);
|
|
103
|
+
var childPos = basePos + offset;
|
|
104
|
+
tr.setNodeMarkup(childPos, undefined, _objectSpread(_objectSpread({}, child.attrs || {}), {}, {
|
|
105
|
+
width: Number(mappedWidths[i].toFixed(2))
|
|
106
|
+
}));
|
|
107
|
+
offset += child.nodeSize;
|
|
108
|
+
}
|
|
109
|
+
if (tr.docChanged) {
|
|
110
|
+
if (typeof focusIndex === 'number') {
|
|
111
|
+
var _parentAfter$type;
|
|
112
|
+
var parentAfter = tr.doc.nodeAt(parentPos);
|
|
113
|
+
if ((parentAfter === null || parentAfter === void 0 || (_parentAfter$type = parentAfter.type) === null || _parentAfter$type === void 0 ? void 0 : _parentAfter$type.name) === 'flipGrid' && focusIndex >= 0 && focusIndex < parentAfter.childCount) {
|
|
114
|
+
var offsetToCol = 0;
|
|
115
|
+
for (var _i = 0; _i < focusIndex; _i += 1) {
|
|
116
|
+
offsetToCol += parentAfter.child(_i).nodeSize;
|
|
117
|
+
}
|
|
118
|
+
var colStart = parentPos + 1 + offsetToCol;
|
|
119
|
+
var textPos = colStart + 2; // column start + 1 (para start) + 1 (text)
|
|
120
|
+
var safePos = Math.min(tr.doc.content.size, Math.max(0, textPos));
|
|
121
|
+
tr.setSelection(TextSelection.near(tr.doc.resolve(safePos)));
|
|
122
|
+
} else if (selection) {
|
|
123
|
+
var mappedSelection = selection.map(tr.doc, tr.mapping);
|
|
124
|
+
tr.setSelection(mappedSelection);
|
|
125
|
+
}
|
|
126
|
+
} else if (selection) {
|
|
127
|
+
var _mappedSelection = selection.map(tr.doc, tr.mapping);
|
|
128
|
+
tr.setSelection(_mappedSelection);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
changed: tr.docChanged
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
var children = [];
|
|
136
|
+
var sourceIndex = 0;
|
|
137
|
+
for (var _i2 = 0; _i2 < mappedWidths.length; _i2 += 1) {
|
|
138
|
+
var shouldInsertNew = typeof insertAt === 'number' && _i2 === insertAt;
|
|
139
|
+
if (!shouldInsertNew && typeof removeIndex === 'number') {
|
|
140
|
+
while (sourceIndex === removeIndex) {
|
|
141
|
+
sourceIndex += 1;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
var existing = shouldInsertNew ? null : sourceIndex < parentNode.childCount ? parentNode.child(sourceIndex) : null;
|
|
145
|
+
if (!shouldInsertNew) {
|
|
146
|
+
sourceIndex += 1;
|
|
147
|
+
}
|
|
148
|
+
var content = existing ? existing.content : paragraphType.createAndFill();
|
|
149
|
+
children.push(colType.create(_objectSpread(_objectSpread({}, (existing === null || existing === void 0 ? void 0 : existing.attrs) || {}), {}, {
|
|
150
|
+
width: Number(mappedWidths[_i2].toFixed(2))
|
|
151
|
+
}), content || undefined));
|
|
152
|
+
}
|
|
153
|
+
var newNode = parentNode.type.create(parentNode.attrs, children, parentNode.marks);
|
|
154
|
+
tr.replaceRangeWith(parentPos, parentPos + parentNode.nodeSize, newNode);
|
|
155
|
+
if (tr.docChanged) {
|
|
156
|
+
if (typeof focusIndex === 'number') {
|
|
157
|
+
var _parentAfter$type2;
|
|
158
|
+
var _parentAfter = tr.doc.nodeAt(parentPos);
|
|
159
|
+
if ((_parentAfter === null || _parentAfter === void 0 || (_parentAfter$type2 = _parentAfter.type) === null || _parentAfter$type2 === void 0 ? void 0 : _parentAfter$type2.name) === 'flipGrid' && focusIndex >= 0 && focusIndex < _parentAfter.childCount) {
|
|
160
|
+
var _offsetToCol = 0;
|
|
161
|
+
for (var _i3 = 0; _i3 < focusIndex; _i3 += 1) {
|
|
162
|
+
_offsetToCol += _parentAfter.child(_i3).nodeSize;
|
|
163
|
+
}
|
|
164
|
+
var _colStart = parentPos + 1 + _offsetToCol;
|
|
165
|
+
var _textPos = _colStart + 2; // column start + 1 (para start) + 1 (text)
|
|
166
|
+
var _safePos = Math.min(tr.doc.content.size, Math.max(0, _textPos));
|
|
167
|
+
tr.setSelection(TextSelection.near(tr.doc.resolve(_safePos)));
|
|
168
|
+
} else if (selection) {
|
|
169
|
+
var _mappedSelection2 = selection.map(tr.doc, tr.mapping);
|
|
170
|
+
tr.setSelection(_mappedSelection2);
|
|
171
|
+
}
|
|
172
|
+
} else if (selection) {
|
|
173
|
+
var _mappedSelection3 = selection.map(tr.doc, tr.mapping);
|
|
174
|
+
tr.setSelection(_mappedSelection3);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
changed: tr.docChanged
|
|
179
|
+
};
|
|
180
|
+
};
|
|
@@ -25,7 +25,7 @@ var SlashCommandsList = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
25
25
|
}, /*#__PURE__*/React.createElement(Stack, {
|
|
26
26
|
direction: 'row',
|
|
27
27
|
flexWrap: 'wrap'
|
|
28
|
-
}, items.slice(0,
|
|
28
|
+
}, items.slice(0, 17).map(function (item, index) {
|
|
29
29
|
return /*#__PURE__*/React.createElement(ToolbarItem, {
|
|
30
30
|
key: index,
|
|
31
31
|
shortcutKey: (item === null || item === void 0 ? void 0 : item.shortcutKey) || [],
|
|
@@ -7,6 +7,6 @@ export interface UploadProgressAttributes {
|
|
|
7
7
|
tempId: string;
|
|
8
8
|
}
|
|
9
9
|
export declare const getFileIcon: (fileType: string) => React.JSX.Element;
|
|
10
|
-
export declare const getFileTypeText: (fileType: string) => "
|
|
10
|
+
export declare const getFileTypeText: (fileType: string) => "视频" | "音频" | "图片" | "文件";
|
|
11
11
|
declare const UploadProgressView: React.FC<NodeViewProps>;
|
|
12
12
|
export default UploadProgressView;
|
package/dist/extension/index.js
CHANGED
|
@@ -14,7 +14,7 @@ import StarterKit from '@tiptap/starter-kit';
|
|
|
14
14
|
import { PLACEHOLDER } from "../contants/placeholder";
|
|
15
15
|
import { AiWritingExtension, ImeComposition, SlashCommands, StructuredDiffExtension } from "./extension";
|
|
16
16
|
import { CodeExtension } from "./mark/Code";
|
|
17
|
-
import { AlertExtension, AudioExtension, BlockAttachmentExtension, BlockLinkExtension, CodeBlockLowlightExtension, CustomBlockMathExtension, CustomHorizontalRule, CustomInlineMathExtension, CustomSubscript, CustomSuperscript, DetailsContentExtension, DetailsExtension, DetailsSummaryExtension, EmojiExtension, FileHandlerExtension, FlowExtension, IframeExtension, ImageExtension, Indent, InlineAttachmentExtension, InlineLinkExtension, InlineUploadProgressExtension, ListExtension, MentionExtension, TableExtension, TableOfContents, UploadProgressExtension, VerticalAlign, VideoExtension, YamlFormat, YoutubeExtension } from "./node";
|
|
17
|
+
import { AlertExtension, AudioExtension, BlockAttachmentExtension, BlockLinkExtension, CodeBlockLowlightExtension, CustomBlockMathExtension, CustomHorizontalRule, CustomInlineMathExtension, CustomSubscript, CustomSuperscript, DetailsContentExtension, DetailsExtension, DetailsSummaryExtension, EmojiExtension, FileHandlerExtension, FlipGridColumnExtension, FlipGridExtension, FlowExtension, IframeExtension, ImageExtension, Indent, InlineAttachmentExtension, InlineLinkExtension, InlineUploadProgressExtension, ListExtension, MentionExtension, TableExtension, TableOfContents, UploadProgressExtension, VerticalAlign, VideoExtension, YamlFormat, YoutubeExtension } from "./node";
|
|
18
18
|
export var getExtensions = function getExtensions(_ref) {
|
|
19
19
|
var limit = _ref.limit,
|
|
20
20
|
exclude = _ref.exclude,
|
|
@@ -48,7 +48,7 @@ export var getExtensions = function getExtensions(_ref) {
|
|
|
48
48
|
}
|
|
49
49
|
}), YamlFormat, TextStyleKit, CodeExtension, ListExtension, EmojiExtension, AlertExtension, CustomSubscript, DetailsExtension, CustomSuperscript, DetailsContentExtension, DetailsSummaryExtension, CodeBlockLowlightExtension, InlineUploadProgressExtension, CustomHorizontalRule].concat(_toConsumableArray(TableExtension({
|
|
50
50
|
editable: editable
|
|
51
|
-
})), [CustomBlockMathExtension({
|
|
51
|
+
})), [FlipGridColumnExtension, FlipGridExtension, CustomBlockMathExtension({
|
|
52
52
|
onError: onError
|
|
53
53
|
}), CustomInlineMathExtension({
|
|
54
54
|
onError: onError
|
|
@@ -22,7 +22,7 @@ export var InlineAttachmentExtension = function InlineAttachmentExtension(props)
|
|
|
22
22
|
url: {
|
|
23
23
|
default: '',
|
|
24
24
|
parseHTML: function parseHTML(element) {
|
|
25
|
-
return withBaseUrl(element.getAttribute('data-url') || '', props.baseUrl);
|
|
25
|
+
return withBaseUrl(element.getAttribute('data-url') || element.getAttribute('href') || '', props.baseUrl);
|
|
26
26
|
},
|
|
27
27
|
renderHTML: function renderHTML(attributes) {
|
|
28
28
|
return {
|
|
@@ -33,7 +33,7 @@ export var InlineAttachmentExtension = function InlineAttachmentExtension(props)
|
|
|
33
33
|
title: {
|
|
34
34
|
default: '',
|
|
35
35
|
parseHTML: function parseHTML(element) {
|
|
36
|
-
return element.getAttribute('data-title');
|
|
36
|
+
return element.getAttribute('data-title') || element.getAttribute('title') || element.getAttribute('aria-label') || element.textContent;
|
|
37
37
|
},
|
|
38
38
|
renderHTML: function renderHTML(attributes) {
|
|
39
39
|
return {
|
|
@@ -154,7 +154,7 @@ export var BlockAttachmentExtension = function BlockAttachmentExtension(props) {
|
|
|
154
154
|
url: {
|
|
155
155
|
default: '',
|
|
156
156
|
parseHTML: function parseHTML(element) {
|
|
157
|
-
return withBaseUrl(element.getAttribute('data-url') || '', props.baseUrl);
|
|
157
|
+
return withBaseUrl(element.getAttribute('data-url') || element.getAttribute('href') || '', props.baseUrl);
|
|
158
158
|
},
|
|
159
159
|
renderHTML: function renderHTML(attributes) {
|
|
160
160
|
if (!attributes.url) return {};
|
|
@@ -166,7 +166,7 @@ export var BlockAttachmentExtension = function BlockAttachmentExtension(props) {
|
|
|
166
166
|
title: {
|
|
167
167
|
default: '',
|
|
168
168
|
parseHTML: function parseHTML(element) {
|
|
169
|
-
return element.getAttribute('data-title');
|
|
169
|
+
return element.getAttribute('data-title') || element.getAttribute('title') || element.getAttribute('aria-label') || element.textContent;
|
|
170
170
|
},
|
|
171
171
|
renderHTML: function renderHTML(attributes) {
|
|
172
172
|
return {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Node } from '@tiptap/core';
|
|
2
|
+
export declare const MIN_WIDTH = 5;
|
|
3
|
+
export declare const MAX_COLUMNS = 10;
|
|
4
|
+
export declare const DEFAULT_GAP = "16px";
|
|
5
|
+
declare module '@tiptap/core' {
|
|
6
|
+
interface Commands<ReturnType> {
|
|
7
|
+
flipGrid: {
|
|
8
|
+
setFlipGrid: (columns?: number) => ReturnType;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export declare const FlipGridColumnExtension: Node<any, any>;
|
|
13
|
+
export declare const FlipGridExtension: Node<any, any>;
|
|
14
|
+
export default FlipGridExtension;
|