e-virt-table 1.3.26 → 1.4.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/index.cjs.js +16 -5
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +2990 -2520
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +16 -5
- package/dist/index.umd.js.map +1 -1
- package/dist/lib/Autofill.js +3 -2
- package/dist/lib/Autofill.js.map +1 -1
- package/dist/lib/BaseCell.d.ts +15 -2
- package/dist/lib/BaseCell.js +55 -15
- package/dist/lib/BaseCell.js.map +1 -1
- package/dist/lib/Body.d.ts +8 -0
- package/dist/lib/Body.js +230 -0
- package/dist/lib/Body.js.map +1 -1
- package/dist/lib/Cell.d.ts +9 -18
- package/dist/lib/Cell.js +143 -181
- package/dist/lib/Cell.js.map +1 -1
- package/dist/lib/CellHeader.d.ts +9 -2
- package/dist/lib/CellHeader.js +77 -44
- package/dist/lib/CellHeader.js.map +1 -1
- package/dist/lib/CellImage.d.ts +15 -0
- package/dist/lib/CellImage.js +72 -0
- package/dist/lib/CellImage.js.map +1 -0
- package/dist/lib/Config.d.ts +18 -3
- package/dist/lib/Config.js +72 -25
- package/dist/lib/Config.js.map +1 -1
- package/dist/lib/Context.d.ts +5 -1
- package/dist/lib/Context.js +22 -3
- package/dist/lib/Context.js.map +1 -1
- package/dist/lib/ContextMenu.js +10 -2
- package/dist/lib/ContextMenu.js.map +1 -1
- package/dist/lib/DOMTreeMenu.js +1 -1
- package/dist/lib/DOMTreeMenu.js.map +1 -1
- package/dist/lib/Database.d.ts +1 -0
- package/dist/lib/Database.js +105 -94
- package/dist/lib/Database.js.map +1 -1
- package/dist/lib/EVirtTable.d.ts +5 -0
- package/dist/lib/EVirtTable.js +23 -0
- package/dist/lib/EVirtTable.js.map +1 -1
- package/dist/lib/Editor.d.ts +1 -0
- package/dist/lib/Editor.js +20 -3
- package/dist/lib/Editor.js.map +1 -1
- package/dist/lib/Empty.d.ts +2 -0
- package/dist/lib/Empty.js +11 -2
- package/dist/lib/Empty.js.map +1 -1
- package/dist/lib/EventTable.d.ts +0 -13
- package/dist/lib/EventTable.js +33 -221
- package/dist/lib/EventTable.js.map +1 -1
- package/dist/lib/Header.d.ts +2 -0
- package/dist/lib/Header.js +46 -2
- package/dist/lib/Header.js.map +1 -1
- package/dist/lib/Icons.d.ts +8 -7
- package/dist/lib/Icons.js +22 -10
- package/dist/lib/Icons.js.map +1 -1
- package/dist/lib/Loading.d.ts +3 -0
- package/dist/lib/Loading.js +18 -4
- package/dist/lib/Loading.js.map +1 -1
- package/dist/lib/Locale.d.ts +7 -0
- package/dist/lib/Locale.js +26 -0
- package/dist/lib/Locale.js.map +1 -0
- package/dist/lib/Paint.d.ts +6 -0
- package/dist/lib/Paint.js +217 -67
- package/dist/lib/Paint.js.map +1 -1
- package/dist/lib/Selector.js +13 -12
- package/dist/lib/Selector.js.map +1 -1
- package/dist/lib/TextSelector.d.ts +89 -0
- package/dist/lib/TextSelector.js +270 -0
- package/dist/lib/TextSelector.js.map +1 -0
- package/dist/lib/TreeUtil.d.ts +6 -8
- package/dist/lib/TreeUtil.js +49 -40
- package/dist/lib/TreeUtil.js.map +1 -1
- package/dist/lib/lang/en-US.d.ts +25 -0
- package/dist/lib/lang/en-US.js +25 -0
- package/dist/lib/lang/en-US.js.map +1 -0
- package/dist/lib/lang/zh-CN.d.ts +25 -0
- package/dist/lib/lang/zh-CN.js +25 -0
- package/dist/lib/lang/zh-CN.js.map +1 -0
- package/dist/lib/types.d.ts +25 -3
- package/dist/lib/util.d.ts +2 -1
- package/dist/lib/util.js +5 -1
- package/dist/lib/util.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { Align } from './types';
|
|
2
|
+
import type Context from './Context';
|
|
3
|
+
export type TextSelectionRange = {
|
|
4
|
+
start: number;
|
|
5
|
+
end: number;
|
|
6
|
+
};
|
|
7
|
+
export type TextGlyph = {
|
|
8
|
+
char: string;
|
|
9
|
+
index: number;
|
|
10
|
+
line: number;
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
};
|
|
16
|
+
export type TextLineItem = {
|
|
17
|
+
char: string;
|
|
18
|
+
sourceIndex: number;
|
|
19
|
+
ellipsis?: boolean;
|
|
20
|
+
};
|
|
21
|
+
export type TextLayoutLine = {
|
|
22
|
+
items: TextLineItem[];
|
|
23
|
+
text: string;
|
|
24
|
+
caretIndex: number;
|
|
25
|
+
lineIndex: number;
|
|
26
|
+
drawX: number;
|
|
27
|
+
drawY: number;
|
|
28
|
+
width: number;
|
|
29
|
+
segments: TextLineSegment[];
|
|
30
|
+
};
|
|
31
|
+
export type TextLineSegment = {
|
|
32
|
+
char: string;
|
|
33
|
+
itemIndex: number;
|
|
34
|
+
sourceIndex: number;
|
|
35
|
+
x: number;
|
|
36
|
+
width: number;
|
|
37
|
+
};
|
|
38
|
+
export type TextLayout = {
|
|
39
|
+
text: string;
|
|
40
|
+
chars: string[];
|
|
41
|
+
glyphs: TextGlyph[];
|
|
42
|
+
lines: TextLayoutLine[];
|
|
43
|
+
box: {
|
|
44
|
+
x: number;
|
|
45
|
+
y: number;
|
|
46
|
+
width: number;
|
|
47
|
+
height: number;
|
|
48
|
+
};
|
|
49
|
+
contentBox: {
|
|
50
|
+
x: number;
|
|
51
|
+
y: number;
|
|
52
|
+
width: number;
|
|
53
|
+
height: number;
|
|
54
|
+
};
|
|
55
|
+
contentY: number;
|
|
56
|
+
lineHeight: number;
|
|
57
|
+
font: string;
|
|
58
|
+
color: string;
|
|
59
|
+
align: Align;
|
|
60
|
+
ellipsis: boolean;
|
|
61
|
+
};
|
|
62
|
+
export default class TextSelector {
|
|
63
|
+
private ctx;
|
|
64
|
+
private layouts;
|
|
65
|
+
private activeCellKey;
|
|
66
|
+
private selectionStart;
|
|
67
|
+
private selectionEnd;
|
|
68
|
+
private dragging;
|
|
69
|
+
constructor(ctx: Context);
|
|
70
|
+
private init;
|
|
71
|
+
/**
|
|
72
|
+
* 命中测试,返回字符索引
|
|
73
|
+
*/
|
|
74
|
+
private hitTestText;
|
|
75
|
+
registerLayout(cellKey: string, layout: TextLayout): void;
|
|
76
|
+
clearLayouts(): void;
|
|
77
|
+
draw(): void;
|
|
78
|
+
private getCanvasCtx;
|
|
79
|
+
/**
|
|
80
|
+
* 绘制文字选中高亮
|
|
81
|
+
*/
|
|
82
|
+
private drawTextSelection;
|
|
83
|
+
private getCellKey;
|
|
84
|
+
private getCellLayout;
|
|
85
|
+
private getSelectionRange;
|
|
86
|
+
private getSelectedText;
|
|
87
|
+
private clearSelection;
|
|
88
|
+
destroy(): void;
|
|
89
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
export default class TextSelector {
|
|
2
|
+
constructor(ctx) {
|
|
3
|
+
Object.defineProperty(this, "ctx", {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
configurable: true,
|
|
6
|
+
writable: true,
|
|
7
|
+
value: void 0
|
|
8
|
+
});
|
|
9
|
+
Object.defineProperty(this, "layouts", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: new Map()
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(this, "activeCellKey", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: ''
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(this, "selectionStart", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: null
|
|
26
|
+
});
|
|
27
|
+
Object.defineProperty(this, "selectionEnd", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true,
|
|
31
|
+
value: null
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(this, "dragging", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true,
|
|
37
|
+
value: false
|
|
38
|
+
});
|
|
39
|
+
this.ctx = ctx;
|
|
40
|
+
this.init();
|
|
41
|
+
}
|
|
42
|
+
init() {
|
|
43
|
+
this.ctx.on('registerTextLayout', (cellKey, layout) => {
|
|
44
|
+
this.registerLayout(cellKey, layout);
|
|
45
|
+
});
|
|
46
|
+
this.ctx.on('mousedown', (e) => {
|
|
47
|
+
if (!this.ctx.config.ENABLE_TEXT_SELECTION) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (!this.ctx.isTarget(e)) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (this.ctx.editing || this.ctx.finding) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const cell = this.ctx.focusCell;
|
|
57
|
+
if (!cell || cell.cellType !== 'body') {
|
|
58
|
+
this.clearSelection();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const layout = this.getCellLayout(cell);
|
|
62
|
+
if (!layout) {
|
|
63
|
+
this.clearSelection();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const { offsetX, offsetY } = this.ctx.getOffset(e);
|
|
67
|
+
const index = this.hitTestText(layout, offsetX, offsetY);
|
|
68
|
+
if (index === null) {
|
|
69
|
+
this.clearSelection();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
this.activeCellKey = this.getCellKey(cell);
|
|
73
|
+
this.selectionStart = index;
|
|
74
|
+
this.selectionEnd = index;
|
|
75
|
+
this.dragging = true;
|
|
76
|
+
this.ctx.textSelecting = true;
|
|
77
|
+
this.ctx.textSelectionStr = this.getSelectedText();
|
|
78
|
+
this.ctx.emit('drawView');
|
|
79
|
+
});
|
|
80
|
+
this.ctx.on('mousemove', (e) => {
|
|
81
|
+
if (!this.ctx.config.ENABLE_TEXT_SELECTION || !this.dragging) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const cell = this.ctx.focusCell;
|
|
85
|
+
if (!cell) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const layout = this.getCellLayout(cell);
|
|
89
|
+
if (!layout) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const { offsetX, offsetY } = this.ctx.getOffset(e);
|
|
93
|
+
const index = this.hitTestText(layout, offsetX, offsetY);
|
|
94
|
+
if (index === null) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
this.selectionEnd = index;
|
|
98
|
+
this.ctx.textSelectionStr = this.getSelectedText();
|
|
99
|
+
this.ctx.emit('drawView');
|
|
100
|
+
});
|
|
101
|
+
this.ctx.on('mouseup', () => {
|
|
102
|
+
this.dragging = false;
|
|
103
|
+
this.ctx.textSelecting = false;
|
|
104
|
+
this.ctx.textSelectionStr = this.getSelectedText();
|
|
105
|
+
if (this.ctx.textSelectionStr) {
|
|
106
|
+
this.ctx.emit('drawView');
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
this.ctx.on('keydown', (e) => {
|
|
110
|
+
if (!this.ctx.config.ENABLE_TEXT_SELECTION) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (this.ctx.editing || this.ctx.finding) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if ((e.ctrlKey && e.code === 'KeyC') || (e.metaKey && e.code === 'KeyC')) {
|
|
117
|
+
const text = this.getSelectedText();
|
|
118
|
+
if (!text) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
e.preventDefault();
|
|
122
|
+
if (navigator.clipboard) {
|
|
123
|
+
navigator.clipboard.writeText(text).catch((error) => console.error('Copy Failure:', error));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
this.ctx.on('outsideMousedown', () => {
|
|
128
|
+
this.clearSelection();
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* 命中测试,返回字符索引
|
|
133
|
+
*/
|
|
134
|
+
hitTestText(layout, mouseX, mouseY) {
|
|
135
|
+
const { contentBox, lines, glyphs, contentY, lineHeight } = layout;
|
|
136
|
+
if (mouseX < contentBox.x ||
|
|
137
|
+
mouseX > contentBox.x + contentBox.width ||
|
|
138
|
+
mouseY < contentBox.y ||
|
|
139
|
+
mouseY > contentBox.y + contentBox.height) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
const relativeY = mouseY - contentY;
|
|
143
|
+
const lineIndex = Math.max(0, Math.min(Math.floor(relativeY / lineHeight), lines.length - 1));
|
|
144
|
+
const line = lines[lineIndex];
|
|
145
|
+
const lineGlyphs = glyphs.filter((glyph) => glyph.line === lineIndex);
|
|
146
|
+
if (!lineGlyphs.length) {
|
|
147
|
+
return line.caretIndex;
|
|
148
|
+
}
|
|
149
|
+
if (mouseX <= lineGlyphs[0].x) {
|
|
150
|
+
return lineGlyphs[0].index;
|
|
151
|
+
}
|
|
152
|
+
for (const glyph of lineGlyphs) {
|
|
153
|
+
if (mouseX < glyph.x + glyph.width / 2) {
|
|
154
|
+
return glyph.index;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return lineGlyphs[lineGlyphs.length - 1].index + 1;
|
|
158
|
+
}
|
|
159
|
+
registerLayout(cellKey, layout) {
|
|
160
|
+
this.layouts.set(cellKey, layout);
|
|
161
|
+
}
|
|
162
|
+
clearLayouts() {
|
|
163
|
+
this.layouts.clear();
|
|
164
|
+
}
|
|
165
|
+
draw() {
|
|
166
|
+
if (!this.ctx.config.ENABLE_TEXT_SELECTION) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const range = this.getSelectionRange();
|
|
170
|
+
if (!range) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const layout = this.layouts.get(this.activeCellKey);
|
|
174
|
+
if (!layout) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
this.drawTextSelection(layout, range);
|
|
178
|
+
}
|
|
179
|
+
getCanvasCtx() {
|
|
180
|
+
const ctx = this.ctx.canvasElement.getContext('2d');
|
|
181
|
+
if (!ctx) {
|
|
182
|
+
throw new Error('canvas context not found');
|
|
183
|
+
}
|
|
184
|
+
return ctx;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* 绘制文字选中高亮
|
|
188
|
+
*/
|
|
189
|
+
drawTextSelection(layout, range, selectedColor = '#fff', selectionBgColor = '#3b82f6') {
|
|
190
|
+
if (range.start >= range.end) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const byLine = new Map();
|
|
194
|
+
layout.glyphs.forEach((glyph) => {
|
|
195
|
+
if (glyph.index < 0 || glyph.index < range.start || glyph.index >= range.end) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (!byLine.has(glyph.line)) {
|
|
199
|
+
byLine.set(glyph.line, []);
|
|
200
|
+
}
|
|
201
|
+
byLine.get(glyph.line).push(glyph);
|
|
202
|
+
});
|
|
203
|
+
const ctx = this.getCanvasCtx();
|
|
204
|
+
ctx.save();
|
|
205
|
+
ctx.fillStyle = selectionBgColor;
|
|
206
|
+
byLine.forEach((lineGlyphs) => {
|
|
207
|
+
const first = lineGlyphs[0];
|
|
208
|
+
const last = lineGlyphs[lineGlyphs.length - 1];
|
|
209
|
+
ctx.fillRect(first.x, first.y, last.x + last.width - first.x, first.height);
|
|
210
|
+
});
|
|
211
|
+
ctx.font = layout.font;
|
|
212
|
+
ctx.textBaseline = 'top';
|
|
213
|
+
ctx.textAlign = 'left';
|
|
214
|
+
ctx.fillStyle = selectedColor;
|
|
215
|
+
layout.lines.forEach((line) => {
|
|
216
|
+
const selectedItems = line.items.filter((item) => item.sourceIndex >= 0 && item.sourceIndex >= range.start && item.sourceIndex < range.end);
|
|
217
|
+
if (!selectedItems.length) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const firstSelected = selectedItems[0];
|
|
221
|
+
const colIndex = line.items.indexOf(firstSelected);
|
|
222
|
+
const selectedText = selectedItems.map((item) => item.char).join('');
|
|
223
|
+
const prefix = line.items
|
|
224
|
+
.slice(0, colIndex)
|
|
225
|
+
.map((item) => item.char)
|
|
226
|
+
.join('');
|
|
227
|
+
const drawX = line.drawX + ctx.measureText(prefix).width;
|
|
228
|
+
ctx.fillText(selectedText, drawX, line.drawY);
|
|
229
|
+
});
|
|
230
|
+
ctx.restore();
|
|
231
|
+
}
|
|
232
|
+
getCellKey(cell) {
|
|
233
|
+
return `${cell.rowIndex}-${cell.colIndex}`;
|
|
234
|
+
}
|
|
235
|
+
getCellLayout(cell) {
|
|
236
|
+
return this.layouts.get(this.getCellKey(cell));
|
|
237
|
+
}
|
|
238
|
+
getSelectionRange() {
|
|
239
|
+
if (this.selectionStart === null || this.selectionEnd === null) {
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
start: Math.min(this.selectionStart, this.selectionEnd),
|
|
244
|
+
end: Math.max(this.selectionStart, this.selectionEnd),
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
getSelectedText() {
|
|
248
|
+
const range = this.getSelectionRange();
|
|
249
|
+
if (!range || range.start >= range.end) {
|
|
250
|
+
return '';
|
|
251
|
+
}
|
|
252
|
+
const layout = this.layouts.get(this.activeCellKey);
|
|
253
|
+
if (!layout) {
|
|
254
|
+
return '';
|
|
255
|
+
}
|
|
256
|
+
return layout.chars.slice(range.start, range.end).join('');
|
|
257
|
+
}
|
|
258
|
+
clearSelection() {
|
|
259
|
+
this.activeCellKey = '';
|
|
260
|
+
this.selectionStart = null;
|
|
261
|
+
this.selectionEnd = null;
|
|
262
|
+
this.dragging = false;
|
|
263
|
+
this.ctx.textSelectionStr = '';
|
|
264
|
+
}
|
|
265
|
+
destroy() {
|
|
266
|
+
this.layouts.clear();
|
|
267
|
+
this.clearSelection();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
//# sourceMappingURL=TextSelector.js.map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AAI,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,GAAG,EAAE,CAAC;YACrC,OAAO,EAAE,CAAC;QACd,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QACpD,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,OAAO,EAAE,CAAC;QACd,CAAC;QACD,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC/D,CAAC;IAEO,cAAc;QAClB,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;QACxB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC3B,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACtB,IAAI,CAAC,GAAG,CAAC,gBAAgB,GAAG,EAAE,CAAC;IACnC,CAAC;IAED,OAAO;QACH,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACrB,IAAI,CAAC,cAAc,EAAE,CAAC;IAC1B,CAAC;CACJ"}
|
package/dist/lib/TreeUtil.d.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
type
|
|
1
|
+
export type TreeUtilPosition = 'none' | 'before' | 'after' | 'inside';
|
|
2
2
|
interface TreeConfig {
|
|
3
3
|
key?: string;
|
|
4
4
|
childrenKey?: string;
|
|
5
5
|
}
|
|
6
|
-
export declare class TreeUtil
|
|
6
|
+
export declare class TreeUtil {
|
|
7
7
|
private root;
|
|
8
8
|
private key;
|
|
9
9
|
private childrenKey;
|
|
10
|
-
constructor(initialData:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/** 移动节点 */
|
|
14
|
-
treeMove(sourceNode: T, targetNode: T, position: Position): void;
|
|
15
|
-
/** 在树中找到节点及其父节点 */
|
|
10
|
+
constructor(initialData: any[], config?: TreeConfig);
|
|
11
|
+
getTree(): any[];
|
|
12
|
+
treeMove(sourceKey: any, targetKey: any, position: TreeUtilPosition): void;
|
|
16
13
|
private findNodeWithParent;
|
|
14
|
+
private isDescendant;
|
|
17
15
|
}
|
|
18
16
|
export {};
|
package/dist/lib/TreeUtil.js
CHANGED
|
@@ -22,64 +22,73 @@ export class TreeUtil {
|
|
|
22
22
|
this.key = config?.key || 'key';
|
|
23
23
|
this.childrenKey = config?.childrenKey || 'children';
|
|
24
24
|
}
|
|
25
|
-
/** 获取当前树 */
|
|
26
25
|
getTree() {
|
|
27
26
|
return this.root;
|
|
28
27
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const sourceInfo = this.findNodeWithParent(this.root, sourceNode[this.key]);
|
|
33
|
-
if (!sourceInfo)
|
|
34
|
-
throw new Error('Source node not found');
|
|
35
|
-
const { parent: sourceParent, index: sourceIndex, node: sourceFound } = sourceInfo;
|
|
36
|
-
if (sourceParent) {
|
|
37
|
-
const childrenArr = sourceParent[this.childrenKey];
|
|
38
|
-
childrenArr.splice(sourceIndex, 1);
|
|
39
|
-
if (childrenArr.length === 0) {
|
|
40
|
-
delete sourceParent[this.childrenKey];
|
|
41
|
-
}
|
|
28
|
+
treeMove(sourceKey, targetKey, position) {
|
|
29
|
+
if (position === 'none') {
|
|
30
|
+
return;
|
|
42
31
|
}
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
if (sourceKey === targetKey) {
|
|
33
|
+
return;
|
|
45
34
|
}
|
|
46
|
-
|
|
47
|
-
|
|
35
|
+
const sourceInfo = this.findNodeWithParent(this.root, sourceKey);
|
|
36
|
+
if (!sourceInfo)
|
|
37
|
+
return;
|
|
38
|
+
const targetInfo = this.findNodeWithParent(this.root, targetKey);
|
|
48
39
|
if (!targetInfo)
|
|
49
|
-
|
|
50
|
-
const { parent:
|
|
51
|
-
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
targetParent[this.childrenKey].splice(targetIndex, 0, sourceFound);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
this.root.splice(targetIndex, 0, sourceFound);
|
|
58
|
-
}
|
|
40
|
+
return;
|
|
41
|
+
const { parent: sourceParent, index: sourceIndex, node: sourceNode } = sourceInfo;
|
|
42
|
+
const { parent: targetParent, index: targetIndex, node: targetNode } = targetInfo;
|
|
43
|
+
if (this.isDescendant(sourceNode, targetKey)) {
|
|
44
|
+
return;
|
|
59
45
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
46
|
+
const sourceArray = sourceParent ? sourceParent[this.childrenKey] : this.root;
|
|
47
|
+
sourceArray.splice(sourceIndex, 1);
|
|
48
|
+
if (sourceParent && sourceArray.length === 0) {
|
|
49
|
+
delete sourceParent[this.childrenKey];
|
|
50
|
+
}
|
|
51
|
+
if (position === 'inside') {
|
|
52
|
+
if (!Array.isArray(targetNode[this.childrenKey])) {
|
|
53
|
+
targetNode[this.childrenKey] = [];
|
|
66
54
|
}
|
|
55
|
+
targetNode[this.childrenKey].push(sourceNode);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const targetArray = targetParent ? targetParent[this.childrenKey] : this.root;
|
|
59
|
+
let insertIndex = targetIndex;
|
|
60
|
+
if (sourceParent === targetParent && sourceIndex < targetIndex) {
|
|
61
|
+
insertIndex--;
|
|
67
62
|
}
|
|
63
|
+
if (position === 'after')
|
|
64
|
+
insertIndex++;
|
|
65
|
+
targetArray.splice(insertIndex, 0, sourceNode);
|
|
68
66
|
}
|
|
69
|
-
|
|
70
|
-
findNodeWithParent(tree, nodeId, parent = null) {
|
|
67
|
+
findNodeWithParent(tree, nodeKey, parent = null) {
|
|
71
68
|
for (let i = 0; i < tree.length; i++) {
|
|
72
69
|
const node = tree[i];
|
|
73
|
-
if (node[this.key] ===
|
|
70
|
+
if (node[this.key] === nodeKey)
|
|
74
71
|
return { parent, index: i, node };
|
|
75
|
-
|
|
76
|
-
if (
|
|
77
|
-
const found = this.findNodeWithParent(
|
|
72
|
+
const children = node[this.childrenKey];
|
|
73
|
+
if (Array.isArray(children)) {
|
|
74
|
+
const found = this.findNodeWithParent(children, nodeKey, node);
|
|
78
75
|
if (found)
|
|
79
76
|
return found;
|
|
80
77
|
}
|
|
81
78
|
}
|
|
82
79
|
return null;
|
|
83
80
|
}
|
|
81
|
+
isDescendant(node, targetKey) {
|
|
82
|
+
const children = node[this.childrenKey];
|
|
83
|
+
if (!Array.isArray(children))
|
|
84
|
+
return false;
|
|
85
|
+
for (const child of children) {
|
|
86
|
+
if (child[this.key] === targetKey)
|
|
87
|
+
return true;
|
|
88
|
+
if (this.isDescendant(child, targetKey))
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
84
93
|
}
|
|
85
94
|
//# sourceMappingURL=TreeUtil.js.map
|
package/dist/lib/TreeUtil.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeUtil.js","sourceRoot":"","sources":["../../src/TreeUtil.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TreeUtil.js","sourceRoot":"","sources":["../../src/TreeUtil.ts"],"names":[],"mappings":"AAaA,MAAM,OAAO,QAAQ;IAKnB,YAAY,WAAkB,EAAE,MAAmB;QAJ3C;;;;;WAAY;QACZ;;;;;WAAY;QACZ;;;;;WAAoB;QAG1B,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,GAAG,GAAG,MAAM,EAAE,GAAG,IAAI,KAAK,CAAC;QAChC,IAAI,CAAC,WAAW,GAAG,MAAM,EAAE,WAAW,IAAI,UAAU,CAAC;IACvD,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,QAAQ,CAAC,SAAc,EAAE,SAAc,EAAE,QAA0B;QACjE,IAAI,QAAQ,KA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I,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACxC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;YAAE,OAAO,KAAK,CAAC;QAC3C,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;YAC7B,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,SAAS;gBAAE,OAAO,IAAI,CAAC;YAC/C,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,SAAS,CAAC;gBAAE,OAAO,IAAI,CAAC;QACvD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
numberErrorTip: string;
|
|
3
|
+
emptyText: string;
|
|
4
|
+
loadingText: string;
|
|
5
|
+
copy: string;
|
|
6
|
+
cut: string;
|
|
7
|
+
paste: string;
|
|
8
|
+
clearSelected: string;
|
|
9
|
+
fixedLeft: string;
|
|
10
|
+
fixedRight: string;
|
|
11
|
+
fixedNone: string;
|
|
12
|
+
hide: string;
|
|
13
|
+
visible: string;
|
|
14
|
+
resetHeader: string;
|
|
15
|
+
invalidNumber: string;
|
|
16
|
+
mergeCellNoFill: string;
|
|
17
|
+
mergeCellNoCopy: string;
|
|
18
|
+
mergeCellNoPaste: string;
|
|
19
|
+
numberTruncated: string;
|
|
20
|
+
batchSetItemValueError: string;
|
|
21
|
+
numberMin: string;
|
|
22
|
+
numberMax: string;
|
|
23
|
+
stringMaxlength: string;
|
|
24
|
+
};
|
|
25
|
+
export default _default;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
numberErrorTip: 'Only numbers are allowed',
|
|
3
|
+
emptyText: 'No Data',
|
|
4
|
+
loadingText: 'Loading...',
|
|
5
|
+
copy: 'Copy',
|
|
6
|
+
cut: 'Cut',
|
|
7
|
+
paste: 'Paste',
|
|
8
|
+
clearSelected: 'Clear Selected',
|
|
9
|
+
fixedLeft: 'Fixed Left',
|
|
10
|
+
fixedRight: 'Fixed Right',
|
|
11
|
+
fixedNone: 'Unfixed',
|
|
12
|
+
hide: 'Hide',
|
|
13
|
+
visible: 'Visible',
|
|
14
|
+
resetHeader: 'Reset Default',
|
|
15
|
+
invalidNumber: 'Please enter a numeric value',
|
|
16
|
+
mergeCellNoFill: 'Merged cells cannot be filled',
|
|
17
|
+
mergeCellNoCopy: 'Merged cells cannot be copied',
|
|
18
|
+
mergeCellNoPaste: 'Merged cells cannot be pasted',
|
|
19
|
+
numberTruncated: 'The input number has been truncated to {precision} decimal places',
|
|
20
|
+
batchSetItemValueError: 'Batch set item value error',
|
|
21
|
+
numberMin: 'The input value is less than {min}, automatically adjusted to {min}',
|
|
22
|
+
numberMax: 'The input value is greater than {max}, automatically adjusted to {max}',
|
|
23
|
+
stringMaxlength: 'The input value exceeds {maxlength} characters, automatically truncated',
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=en-US.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"en-US.js","sourceRoot":"","sources":["../../../src/lang/en-US.ts"],"names":[],"mappings":"AAAA,eAAe;IACX,cAAc,EAAE,0BAA0B;IAC1C,SAAS,EAAE,SAAS;IACpB,WAAW,EAAE,YAAY;IACzB,IAAI,EAAE,MAAM;IACZ,GAAG,EAAE,KAAK;IACV,KAAK,EAAE,OAAO;IACd,aAAa,EAAE,gBAAgB;IAC/B,SAAS,EAAE,YAAY;IACvB,UAAU,EAAE,aAAa;IACzB,SAAS,EAAE,SAAS;IACpB,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,SAAS;IAClB,WAAW,EAAE,eAAe;IAC5B,aAAa,EAAE,8BAA8B;IAC7C,eAAe,EAAE,+BAA+B;IAChD,eAAe,EAAE,+BAA+B;IAChD,gBAAgB,EAAE,+BAA+B;IACjD,eAAe,EAAE,mEAAmE;IACpF,sBAAsB,EAAE,4BAA4B;IACpD,SAAS,EAAE,qEAAqE;IAChF,SAAS,EAAE,wEAAwE;IACnF,eAAe,EAAE,yEAAyE;CAC7F,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
numberErrorTip: string;
|
|
3
|
+
emptyText: string;
|
|
4
|
+
loadingText: string;
|
|
5
|
+
copy: string;
|
|
6
|
+
cut: string;
|
|
7
|
+
paste: string;
|
|
8
|
+
clearSelected: string;
|
|
9
|
+
fixedLeft: string;
|
|
10
|
+
fixedRight: string;
|
|
11
|
+
fixedNone: string;
|
|
12
|
+
hide: string;
|
|
13
|
+
visible: string;
|
|
14
|
+
resetHeader: string;
|
|
15
|
+
invalidNumber: string;
|
|
16
|
+
mergeCellNoFill: string;
|
|
17
|
+
mergeCellNoCopy: string;
|
|
18
|
+
mergeCellNoPaste: string;
|
|
19
|
+
numberTruncated: string;
|
|
20
|
+
batchSetItemValueError: string;
|
|
21
|
+
numberMin: string;
|
|
22
|
+
numberMax: string;
|
|
23
|
+
stringMaxlength: string;
|
|
24
|
+
};
|
|
25
|
+
export default _default;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
numberErrorTip: '只允许输入数字',
|
|
3
|
+
emptyText: '暂无数据',
|
|
4
|
+
loadingText: '加载中...',
|
|
5
|
+
copy: '复制',
|
|
6
|
+
cut: '剪切',
|
|
7
|
+
paste: '粘贴',
|
|
8
|
+
clearSelected: '清空选中内容',
|
|
9
|
+
fixedLeft: '左固定',
|
|
10
|
+
fixedRight: '右固定',
|
|
11
|
+
fixedNone: '取消固定',
|
|
12
|
+
hide: '隐藏',
|
|
13
|
+
visible: '显示',
|
|
14
|
+
resetHeader: '恢复默认',
|
|
15
|
+
invalidNumber: '请输入数字类型',
|
|
16
|
+
mergeCellNoFill: '合并单元格不能填充',
|
|
17
|
+
mergeCellNoCopy: '合并单元格不能复制',
|
|
18
|
+
mergeCellNoPaste: '合并单元格不能粘贴',
|
|
19
|
+
numberTruncated: '输入的数字已截取至小数点后{precision}位',
|
|
20
|
+
batchSetItemValueError: '批量赋值错误',
|
|
21
|
+
numberMin: '输入值小于{min},已自动调整为{min}',
|
|
22
|
+
numberMax: '输入值大于{max},已自动调整为{max}',
|
|
23
|
+
stringMaxlength: '输入值超过{maxlength}个字符,已自动截取',
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=zh-CN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zh-CN.js","sourceRoot":"","sources":["../../../src/lang/zh-CN.ts"],"names":[],"mappings":"AAAA,eAAe;IACX,cAAc,EAAE,SAAS;IACzB,SAAS,EAAE,MAAM;IACjB,WAAW,EAAE,QAAQ;IACrB,IAAI,EAAE,IAAI;IACV,GAAG,EAAE,IAAI;IACT,KAAK,EAAE,IAAI;IACX,aAAa,EAAE,QAAQ;IACvB,SAAS,EAAE,KAAK;IAChB,UAAU,EAAE,KAAK;IACjB,SAAS,EAAE,MAAM;IACjB,IAAI,EAAE,IAAI;IACV,OAAO,EAAE,IAAI;IACb,WAAW,EAAE,MAAM;IACnB,aAAa,EAAE,SAAS;IACxB,eAAe,EAAE,WAAW;IAC5B,eAAe,EAAE,WAAW;IAC5B,gBAAgB,EAAE,WAAW;IAC7B,eAAe,EAAE,2BAA2B;IAC5C,sBAAsB,EAAE,QAAQ;IAChC,SAAS,EAAE,wBAAwB;IACnC,SAAS,EAAE,wBAAwB;IACnC,eAAe,EAAE,2BAA2B;CAC/C,CAAC"}
|