quill-table-up 3.1.2 → 3.2.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/README.md +7 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +168 -146
- package/dist/index.js +47 -47
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +52 -52
- package/dist/index.umd.js.map +1 -1
- package/package.json +22 -24
- package/src/__tests__/e2e/custom-creator.test.ts +44 -44
- package/src/__tests__/e2e/editor-page.ts +77 -77
- package/src/__tests__/e2e/table-align.test.ts +104 -104
- package/src/__tests__/e2e/table-blots.test.ts +169 -169
- package/src/__tests__/e2e/table-caption.test.ts +134 -134
- package/src/__tests__/e2e/table-clipboard.test.ts +20 -20
- package/src/__tests__/e2e/table-hack.test.ts +151 -151
- package/src/__tests__/e2e/table-keyboard-handler.test.ts +12 -3
- package/src/__tests__/e2e/table-menu.test.ts +172 -172
- package/src/__tests__/e2e/table-resize.test.ts +654 -9
- package/src/__tests__/e2e/table-scrollbar.test.ts +144 -144
- package/src/__tests__/e2e/table-selection.test.ts +563 -563
- package/src/__tests__/e2e/types.d.ts +7 -7
- package/src/__tests__/e2e/utils.ts +52 -52
- package/src/__tests__/unit/table-blots.test.ts +720 -720
- package/src/__tests__/unit/table-caption.test.ts +234 -234
- package/src/__tests__/unit/table-cell-merge.test.ts +724 -724
- package/src/__tests__/unit/table-clipboard.test.ts +2176 -2176
- package/src/__tests__/unit/table-hack.test.ts +1014 -1014
- package/src/__tests__/unit/table-insert.test.ts +926 -926
- package/src/__tests__/unit/table-redo-undo.test.ts +2429 -2429
- package/src/__tests__/unit/table-remove.test.ts +343 -343
- package/src/__tests__/unit/utils.test-d.ts +49 -49
- package/src/__tests__/unit/utils.test.ts +711 -711
- package/src/__tests__/unit/utils.ts +307 -307
- package/src/__tests__/unit/vitest.d.ts +14 -14
- package/src/formats/container-format.ts +107 -107
- package/src/formats/overrides/block-embed.ts +72 -72
- package/src/formats/overrides/block.ts +95 -95
- package/src/formats/overrides/index.ts +3 -3
- package/src/formats/overrides/scroll.ts +70 -70
- package/src/formats/table-body-format.ts +52 -52
- package/src/formats/table-caption-format.ts +116 -116
- package/src/formats/table-cell-format.ts +304 -304
- package/src/formats/table-cell-inner-format.ts +403 -398
- package/src/formats/table-colgroup-format.ts +136 -136
- package/src/formats/table-foot-format.ts +7 -7
- package/src/formats/table-head-format.ts +7 -7
- package/src/formats/table-main-format.ts +1 -1
- package/src/formats/table-row-format.ts +218 -210
- package/src/formats/utils.ts +6 -6
- package/src/index.ts +19 -19
- package/src/modules/index.ts +7 -7
- package/src/modules/table-align.ts +131 -131
- package/src/modules/table-clipboard/table-clipboard.ts +6 -8
- package/src/modules/table-dom-selector.ts +33 -33
- package/src/modules/table-menu/constants.ts +223 -223
- package/src/modules/table-menu/index.ts +4 -4
- package/src/modules/table-menu/table-menu-common.ts +330 -329
- package/src/modules/table-menu/table-menu-contextmenu.ts +111 -118
- package/src/modules/table-menu/table-menu-select.ts +96 -94
- package/src/modules/table-resize/index.ts +5 -5
- package/src/modules/table-resize/table-resize-box.ts +714 -363
- package/src/modules/table-resize/table-resize-common.ts +246 -382
- package/src/modules/table-resize/table-resize-drag.ts +241 -0
- package/src/modules/table-resize/table-resize-line.ts +244 -182
- package/src/modules/table-resize/table-resize-scale.ts +174 -173
- package/src/modules/table-resize/utils.ts +84 -3
- package/src/modules/table-scrollbar.ts +292 -292
- package/src/modules/table-selection.ts +613 -669
- package/src/style/button.less +45 -45
- package/src/style/color-picker.less +136 -136
- package/src/style/dialog.less +53 -53
- package/src/style/functions.less +9 -9
- package/src/style/index.less +120 -120
- package/src/style/input.less +64 -64
- package/src/style/select-box.less +52 -52
- package/src/style/table-creator.less +56 -56
- package/src/style/table-menu.less +125 -125
- package/src/style/table-resize-scale.less +31 -31
- package/src/style/table-resize.less +249 -202
- package/src/style/table-scrollbar.less +49 -49
- package/src/style/table-selection.less +23 -23
- package/src/style/tooltip.less +19 -19
- package/src/style/variables.less +1 -1
- package/src/svg/arrow-up-down.svg +11 -11
- package/src/svg/convert-cell.svg +7 -7
- package/src/table-up.ts +1360 -1360
- package/src/types.d.ts +4 -4
- package/src/utils/bem.ts +23 -23
- package/src/utils/blot-helper.ts +101 -105
- package/src/utils/color.ts +109 -109
- package/src/utils/components/button.ts +22 -22
- package/src/utils/components/color-picker.ts +236 -236
- package/src/utils/components/dialog.ts +83 -41
- package/src/utils/components/index.ts +6 -6
- package/src/utils/components/input.ts +74 -74
- package/src/utils/components/table/creator.ts +89 -89
- package/src/utils/components/table/index.ts +2 -2
- package/src/utils/components/table/select-box.ts +78 -78
- package/src/utils/components/tooltip.ts +179 -189
- package/src/utils/constants.ts +125 -124
- package/src/utils/drag-helper.ts +112 -0
- package/src/utils/index.ts +15 -14
- package/src/utils/is.ts +9 -9
- package/src/utils/position.ts +60 -60
- package/src/utils/resize-observer-helper.ts +47 -47
- package/src/utils/scroll.ts +145 -47
- package/src/utils/style-helper.ts +47 -47
- package/src/utils/transformer.ts +10 -10
- package/src/utils/transition-event-helper.ts +8 -8
- package/src/utils/types.ts +156 -157
- package/src/utils/utils.ts +12 -12
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
import { createBEM } from '../bem';
|
|
2
|
-
|
|
3
|
-
interface InputOptions {
|
|
4
|
-
type?: string;
|
|
5
|
-
value?: string;
|
|
6
|
-
max?: number;
|
|
7
|
-
min?: number;
|
|
8
|
-
[key: string]: any;
|
|
9
|
-
}
|
|
10
|
-
export function createInputItem(label: string, options: InputOptions) {
|
|
11
|
-
const bem = createBEM('input');
|
|
12
|
-
options.type || (options.type = 'text');
|
|
13
|
-
options.value || (options.value = '');
|
|
14
|
-
|
|
15
|
-
const inputItem = document.createElement('div');
|
|
16
|
-
inputItem.classList.add(bem.be('item'));
|
|
17
|
-
|
|
18
|
-
if (label) {
|
|
19
|
-
const inputLabel = document.createElement('span');
|
|
20
|
-
inputLabel.classList.add(bem.be('label'));
|
|
21
|
-
inputLabel.textContent = label;
|
|
22
|
-
inputItem.appendChild(inputLabel);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const inputInput = document.createElement('div');
|
|
26
|
-
inputInput.classList.add(bem.be('input'));
|
|
27
|
-
const input = document.createElement('input');
|
|
28
|
-
for (const key in options) {
|
|
29
|
-
input.setAttribute(key, options[key]);
|
|
30
|
-
}
|
|
31
|
-
if (options.max || options.min) {
|
|
32
|
-
input.addEventListener('blur', () => {
|
|
33
|
-
if (options.max && options.max <= Number(input.value)) {
|
|
34
|
-
input.value = String(options.max);
|
|
35
|
-
}
|
|
36
|
-
if (options.min && options.min >= Number(input.value)) {
|
|
37
|
-
input.value = String(options.min);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
inputInput.appendChild(input);
|
|
43
|
-
inputItem.appendChild(inputInput);
|
|
44
|
-
|
|
45
|
-
input.addEventListener('focus', () => {
|
|
46
|
-
inputInput.classList.add('focus');
|
|
47
|
-
});
|
|
48
|
-
input.addEventListener('blur', () => {
|
|
49
|
-
inputInput.classList.remove('focus');
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const errorTip = (msg: string) => {
|
|
53
|
-
let errorTip: HTMLElement;
|
|
54
|
-
if (inputInput.classList.contains('error')) {
|
|
55
|
-
errorTip = inputInput.querySelector(`.${bem.be('error-tip')}`)!;
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
errorTip = document.createElement('span');
|
|
59
|
-
errorTip.classList.add(bem.be('error-tip'));
|
|
60
|
-
inputInput.appendChild(errorTip);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
errorTip.textContent = msg;
|
|
64
|
-
inputInput.classList.add('error');
|
|
65
|
-
|
|
66
|
-
const removeError = () => {
|
|
67
|
-
inputInput.classList.remove('error');
|
|
68
|
-
errorTip.remove();
|
|
69
|
-
};
|
|
70
|
-
return { removeError };
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
return { item: inputItem, input, errorTip };
|
|
74
|
-
}
|
|
1
|
+
import { createBEM } from '../bem';
|
|
2
|
+
|
|
3
|
+
interface InputOptions {
|
|
4
|
+
type?: string;
|
|
5
|
+
value?: string;
|
|
6
|
+
max?: number;
|
|
7
|
+
min?: number;
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}
|
|
10
|
+
export function createInputItem(label: string, options: InputOptions) {
|
|
11
|
+
const bem = createBEM('input');
|
|
12
|
+
options.type || (options.type = 'text');
|
|
13
|
+
options.value || (options.value = '');
|
|
14
|
+
|
|
15
|
+
const inputItem = document.createElement('div');
|
|
16
|
+
inputItem.classList.add(bem.be('item'));
|
|
17
|
+
|
|
18
|
+
if (label) {
|
|
19
|
+
const inputLabel = document.createElement('span');
|
|
20
|
+
inputLabel.classList.add(bem.be('label'));
|
|
21
|
+
inputLabel.textContent = label;
|
|
22
|
+
inputItem.appendChild(inputLabel);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const inputInput = document.createElement('div');
|
|
26
|
+
inputInput.classList.add(bem.be('input'));
|
|
27
|
+
const input = document.createElement('input');
|
|
28
|
+
for (const key in options) {
|
|
29
|
+
input.setAttribute(key, options[key]);
|
|
30
|
+
}
|
|
31
|
+
if (options.max || options.min) {
|
|
32
|
+
input.addEventListener('blur', () => {
|
|
33
|
+
if (options.max && options.max <= Number(input.value)) {
|
|
34
|
+
input.value = String(options.max);
|
|
35
|
+
}
|
|
36
|
+
if (options.min && options.min >= Number(input.value)) {
|
|
37
|
+
input.value = String(options.min);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
inputInput.appendChild(input);
|
|
43
|
+
inputItem.appendChild(inputInput);
|
|
44
|
+
|
|
45
|
+
input.addEventListener('focus', () => {
|
|
46
|
+
inputInput.classList.add('focus');
|
|
47
|
+
});
|
|
48
|
+
input.addEventListener('blur', () => {
|
|
49
|
+
inputInput.classList.remove('focus');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const errorTip = (msg: string) => {
|
|
53
|
+
let errorTip: HTMLElement;
|
|
54
|
+
if (inputInput.classList.contains('error')) {
|
|
55
|
+
errorTip = inputInput.querySelector(`.${bem.be('error-tip')}`)!;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
errorTip = document.createElement('span');
|
|
59
|
+
errorTip.classList.add(bem.be('error-tip'));
|
|
60
|
+
inputInput.appendChild(errorTip);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
errorTip.textContent = msg;
|
|
64
|
+
inputInput.classList.add('error');
|
|
65
|
+
|
|
66
|
+
const removeError = () => {
|
|
67
|
+
inputInput.classList.remove('error');
|
|
68
|
+
errorTip.remove();
|
|
69
|
+
};
|
|
70
|
+
return { removeError };
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
return { item: inputItem, input, errorTip };
|
|
74
|
+
}
|
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
import type { TableCreatorTextOptions } from '../../types';
|
|
2
|
-
import { createBEM } from '../../bem';
|
|
3
|
-
import { createButton } from '../button';
|
|
4
|
-
import { createDialog } from '../dialog';
|
|
5
|
-
import { createInputItem } from '../input';
|
|
6
|
-
|
|
7
|
-
interface TableCreatorOptions extends Omit<TableCreatorTextOptions, 'customBtnText'> {
|
|
8
|
-
row: number;
|
|
9
|
-
col: number;
|
|
10
|
-
}
|
|
11
|
-
export async function showTableCreator(options: Partial<TableCreatorOptions> = {}) {
|
|
12
|
-
const bem = createBEM('creator');
|
|
13
|
-
const box = document.createElement('div');
|
|
14
|
-
box.classList.add(bem.b());
|
|
15
|
-
const inputContent = document.createElement('div');
|
|
16
|
-
inputContent.classList.add(bem.be('input'));
|
|
17
|
-
|
|
18
|
-
const {
|
|
19
|
-
item: rowItem,
|
|
20
|
-
input: rowInput,
|
|
21
|
-
errorTip: rowErrorTip,
|
|
22
|
-
} = createInputItem(options.rowText || 'Row', { type: 'number', value: String(options.row || ''), max: 99 });
|
|
23
|
-
const {
|
|
24
|
-
item: colItem,
|
|
25
|
-
input: colInput,
|
|
26
|
-
errorTip: colErrorTip,
|
|
27
|
-
} = createInputItem(options.colText || 'Column', { type: 'number', value: String(options.col || ''), max: 99 });
|
|
28
|
-
|
|
29
|
-
inputContent.appendChild(rowItem);
|
|
30
|
-
inputContent.appendChild(colItem);
|
|
31
|
-
box.appendChild(inputContent);
|
|
32
|
-
|
|
33
|
-
const control = document.createElement('div');
|
|
34
|
-
control.classList.add(bem.be('control'));
|
|
35
|
-
|
|
36
|
-
const confirmBtn = createButton({ type: 'confirm', content: options.confirmText || 'Confirm' });
|
|
37
|
-
const cancelBtn = createButton({ type: 'default', content: options.cancelText || 'Cancel' });
|
|
38
|
-
|
|
39
|
-
control.appendChild(confirmBtn);
|
|
40
|
-
control.appendChild(cancelBtn);
|
|
41
|
-
box.appendChild(control);
|
|
42
|
-
|
|
43
|
-
const validateInput = (row: number = Number(rowInput.value), col: number = Number(colInput.value)) => {
|
|
44
|
-
if (Number.isNaN(row) || row <= 0) {
|
|
45
|
-
rowErrorTip(options.notPositiveNumberError || 'Please enter a positive integer');
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
if (Number.isNaN(col) || col <= 0) {
|
|
49
|
-
colErrorTip(options.notPositiveNumberError || 'Please enter a positive integer');
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
return { row, col };
|
|
53
|
-
};
|
|
54
|
-
const keyboardClose = (e: KeyboardEvent) => {
|
|
55
|
-
if (e.key === 'Escape') {
|
|
56
|
-
close();
|
|
57
|
-
document.removeEventListener('keydown', keyboardClose);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
return new Promise<{ row: number; col: number }>((resolve, reject) => {
|
|
62
|
-
const { close } = createDialog({ child: box, beforeClose: reject });
|
|
63
|
-
rowInput.focus();
|
|
64
|
-
|
|
65
|
-
for (const input of [rowInput, colInput]) {
|
|
66
|
-
input.addEventListener('keydown', (e) => {
|
|
67
|
-
if (e.key === 'Enter') {
|
|
68
|
-
const result = validateInput();
|
|
69
|
-
if (result) {
|
|
70
|
-
resolve(result);
|
|
71
|
-
close();
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
confirmBtn.addEventListener('click',
|
|
77
|
-
const result = validateInput();
|
|
78
|
-
if (result) {
|
|
79
|
-
resolve(result);
|
|
80
|
-
close();
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
document.addEventListener('keydown', keyboardClose);
|
|
84
|
-
cancelBtn.addEventListener('click', close);
|
|
85
|
-
})
|
|
86
|
-
.finally(() => {
|
|
87
|
-
document.removeEventListener('keydown', keyboardClose);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
1
|
+
import type { TableCreatorTextOptions } from '../../types';
|
|
2
|
+
import { createBEM } from '../../bem';
|
|
3
|
+
import { createButton } from '../button';
|
|
4
|
+
import { createDialog } from '../dialog';
|
|
5
|
+
import { createInputItem } from '../input';
|
|
6
|
+
|
|
7
|
+
interface TableCreatorOptions extends Omit<TableCreatorTextOptions, 'customBtnText'> {
|
|
8
|
+
row: number;
|
|
9
|
+
col: number;
|
|
10
|
+
}
|
|
11
|
+
export async function showTableCreator(options: Partial<TableCreatorOptions> = {}) {
|
|
12
|
+
const bem = createBEM('creator');
|
|
13
|
+
const box = document.createElement('div');
|
|
14
|
+
box.classList.add(bem.b());
|
|
15
|
+
const inputContent = document.createElement('div');
|
|
16
|
+
inputContent.classList.add(bem.be('input'));
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
item: rowItem,
|
|
20
|
+
input: rowInput,
|
|
21
|
+
errorTip: rowErrorTip,
|
|
22
|
+
} = createInputItem(options.rowText || 'Row', { type: 'number', value: String(options.row || ''), max: 99 });
|
|
23
|
+
const {
|
|
24
|
+
item: colItem,
|
|
25
|
+
input: colInput,
|
|
26
|
+
errorTip: colErrorTip,
|
|
27
|
+
} = createInputItem(options.colText || 'Column', { type: 'number', value: String(options.col || ''), max: 99 });
|
|
28
|
+
|
|
29
|
+
inputContent.appendChild(rowItem);
|
|
30
|
+
inputContent.appendChild(colItem);
|
|
31
|
+
box.appendChild(inputContent);
|
|
32
|
+
|
|
33
|
+
const control = document.createElement('div');
|
|
34
|
+
control.classList.add(bem.be('control'));
|
|
35
|
+
|
|
36
|
+
const confirmBtn = createButton({ type: 'confirm', content: options.confirmText || 'Confirm' });
|
|
37
|
+
const cancelBtn = createButton({ type: 'default', content: options.cancelText || 'Cancel' });
|
|
38
|
+
|
|
39
|
+
control.appendChild(confirmBtn);
|
|
40
|
+
control.appendChild(cancelBtn);
|
|
41
|
+
box.appendChild(control);
|
|
42
|
+
|
|
43
|
+
const validateInput = (row: number = Number(rowInput.value), col: number = Number(colInput.value)) => {
|
|
44
|
+
if (Number.isNaN(row) || row <= 0) {
|
|
45
|
+
rowErrorTip(options.notPositiveNumberError || 'Please enter a positive integer');
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (Number.isNaN(col) || col <= 0) {
|
|
49
|
+
colErrorTip(options.notPositiveNumberError || 'Please enter a positive integer');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
return { row, col };
|
|
53
|
+
};
|
|
54
|
+
const keyboardClose = (e: KeyboardEvent) => {
|
|
55
|
+
if (e.key === 'Escape') {
|
|
56
|
+
close();
|
|
57
|
+
document.removeEventListener('keydown', keyboardClose);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return new Promise<{ row: number; col: number }>((resolve, reject) => {
|
|
62
|
+
const { close } = createDialog({ child: box, beforeClose: reject });
|
|
63
|
+
rowInput.focus();
|
|
64
|
+
|
|
65
|
+
for (const input of [rowInput, colInput]) {
|
|
66
|
+
input.addEventListener('keydown', (e) => {
|
|
67
|
+
if (e.key === 'Enter') {
|
|
68
|
+
const result = validateInput();
|
|
69
|
+
if (result) {
|
|
70
|
+
resolve(result);
|
|
71
|
+
close();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
confirmBtn.addEventListener('click', () => {
|
|
77
|
+
const result = validateInput();
|
|
78
|
+
if (result) {
|
|
79
|
+
resolve(result);
|
|
80
|
+
close();
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
document.addEventListener('keydown', keyboardClose);
|
|
84
|
+
cancelBtn.addEventListener('click', close);
|
|
85
|
+
})
|
|
86
|
+
.finally(() => {
|
|
87
|
+
document.removeEventListener('keydown', keyboardClose);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './creator';
|
|
2
|
-
export * from './select-box';
|
|
1
|
+
export * from './creator';
|
|
2
|
+
export * from './select-box';
|
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
import type { TableCreatorTextOptions } from '../../types';
|
|
2
|
-
import { createBEM } from '../../bem';
|
|
3
|
-
import { showTableCreator } from './creator';
|
|
4
|
-
|
|
5
|
-
interface TableSelectOptions {
|
|
6
|
-
row: number;
|
|
7
|
-
col: number;
|
|
8
|
-
onSelect: (row: number, col: number) => void;
|
|
9
|
-
customBtn: boolean;
|
|
10
|
-
texts: Partial<TableCreatorTextOptions>;
|
|
11
|
-
}
|
|
12
|
-
export function createSelectBox(options: Partial<TableSelectOptions> = {}) {
|
|
13
|
-
const bem = createBEM('select-box');
|
|
14
|
-
const selectDom = document.createElement('div');
|
|
15
|
-
selectDom.classList.add(bem.b());
|
|
16
|
-
|
|
17
|
-
const selectBlock = document.createElement('div');
|
|
18
|
-
selectBlock.classList.add(bem.be('block'));
|
|
19
|
-
for (let r = 0; r < (options.row || 8); r++) {
|
|
20
|
-
for (let c = 0; c < (options.col || 8); c++) {
|
|
21
|
-
const selectItem = document.createElement('div');
|
|
22
|
-
selectItem.classList.add(bem.be('item'));
|
|
23
|
-
selectItem.dataset.row = String(r + 1);
|
|
24
|
-
selectItem.dataset.col = String(c + 1);
|
|
25
|
-
selectBlock.appendChild(selectItem);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
const updateSelectBlockItems = () => {
|
|
29
|
-
const { row, col } = selectDom.dataset;
|
|
30
|
-
for (const item of Array.from(selectBlock.querySelectorAll('.active'))) {
|
|
31
|
-
item.classList.remove('active');
|
|
32
|
-
}
|
|
33
|
-
if (!row || !col) return;
|
|
34
|
-
const childs = Array.from(selectBlock.children) as HTMLElement[];
|
|
35
|
-
for (
|
|
36
|
-
const { row: childRow, col: childCol } =
|
|
37
|
-
if (childRow! > row && childCol! > col) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
selectBlock.addEventListener('mousemove', (e) => {
|
|
44
|
-
if (!e.target) return;
|
|
45
|
-
const { row, col } = (e.target as HTMLElement).dataset;
|
|
46
|
-
if (!row || !col) return;
|
|
47
|
-
selectDom.dataset.row = row;
|
|
48
|
-
selectDom.dataset.col = col;
|
|
49
|
-
updateSelectBlockItems();
|
|
50
|
-
});
|
|
51
|
-
selectBlock.addEventListener('mouseleave', () => {
|
|
52
|
-
selectDom.removeAttribute('data-row');
|
|
53
|
-
selectDom.removeAttribute('data-col');
|
|
54
|
-
updateSelectBlockItems();
|
|
55
|
-
});
|
|
56
|
-
selectBlock.addEventListener('click', () => {
|
|
57
|
-
const { row, col } = selectDom.dataset;
|
|
58
|
-
if (!row || !col) return;
|
|
59
|
-
options.onSelect
|
|
60
|
-
});
|
|
61
|
-
selectDom.appendChild(selectBlock);
|
|
62
|
-
|
|
63
|
-
if (options.customBtn) {
|
|
64
|
-
const texts = options.texts || {};
|
|
65
|
-
const selectCustom = document.createElement('div');
|
|
66
|
-
selectCustom.classList.add(bem.be('custom'));
|
|
67
|
-
selectCustom.textContent = texts.customBtnText || 'Custom';
|
|
68
|
-
selectCustom.addEventListener('click', async () => {
|
|
69
|
-
const res = await showTableCreator(texts);
|
|
70
|
-
if (res) {
|
|
71
|
-
options.onSelect
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
selectDom.appendChild(selectCustom);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return selectDom;
|
|
78
|
-
}
|
|
1
|
+
import type { TableCreatorTextOptions } from '../../types';
|
|
2
|
+
import { createBEM } from '../../bem';
|
|
3
|
+
import { showTableCreator } from './creator';
|
|
4
|
+
|
|
5
|
+
interface TableSelectOptions {
|
|
6
|
+
row: number;
|
|
7
|
+
col: number;
|
|
8
|
+
onSelect: (row: number, col: number) => void;
|
|
9
|
+
customBtn: boolean;
|
|
10
|
+
texts: Partial<TableCreatorTextOptions>;
|
|
11
|
+
}
|
|
12
|
+
export function createSelectBox(options: Partial<TableSelectOptions> = {}) {
|
|
13
|
+
const bem = createBEM('select-box');
|
|
14
|
+
const selectDom = document.createElement('div');
|
|
15
|
+
selectDom.classList.add(bem.b());
|
|
16
|
+
|
|
17
|
+
const selectBlock = document.createElement('div');
|
|
18
|
+
selectBlock.classList.add(bem.be('block'));
|
|
19
|
+
for (let r = 0; r < (options.row || 8); r++) {
|
|
20
|
+
for (let c = 0; c < (options.col || 8); c++) {
|
|
21
|
+
const selectItem = document.createElement('div');
|
|
22
|
+
selectItem.classList.add(bem.be('item'));
|
|
23
|
+
selectItem.dataset.row = String(r + 1);
|
|
24
|
+
selectItem.dataset.col = String(c + 1);
|
|
25
|
+
selectBlock.appendChild(selectItem);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const updateSelectBlockItems = () => {
|
|
29
|
+
const { row, col } = selectDom.dataset;
|
|
30
|
+
for (const item of Array.from(selectBlock.querySelectorAll('.active'))) {
|
|
31
|
+
item.classList.remove('active');
|
|
32
|
+
}
|
|
33
|
+
if (!row || !col) return;
|
|
34
|
+
const childs = Array.from(selectBlock.children) as HTMLElement[];
|
|
35
|
+
for (const child of childs) {
|
|
36
|
+
const { row: childRow, col: childCol } = child.dataset;
|
|
37
|
+
if (childRow! > row && childCol! > col) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
child.classList.toggle('active', childRow! <= row && childCol! <= col);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
selectBlock.addEventListener('mousemove', (e) => {
|
|
44
|
+
if (!e.target) return;
|
|
45
|
+
const { row, col } = (e.target as HTMLElement).dataset;
|
|
46
|
+
if (!row || !col) return;
|
|
47
|
+
selectDom.dataset.row = row;
|
|
48
|
+
selectDom.dataset.col = col;
|
|
49
|
+
updateSelectBlockItems();
|
|
50
|
+
});
|
|
51
|
+
selectBlock.addEventListener('mouseleave', () => {
|
|
52
|
+
selectDom.removeAttribute('data-row');
|
|
53
|
+
selectDom.removeAttribute('data-col');
|
|
54
|
+
updateSelectBlockItems();
|
|
55
|
+
});
|
|
56
|
+
selectBlock.addEventListener('click', () => {
|
|
57
|
+
const { row, col } = selectDom.dataset;
|
|
58
|
+
if (!row || !col) return;
|
|
59
|
+
options.onSelect?.(Number(row), Number(col));
|
|
60
|
+
});
|
|
61
|
+
selectDom.appendChild(selectBlock);
|
|
62
|
+
|
|
63
|
+
if (options.customBtn) {
|
|
64
|
+
const texts = options.texts || {};
|
|
65
|
+
const selectCustom = document.createElement('div');
|
|
66
|
+
selectCustom.classList.add(bem.be('custom'));
|
|
67
|
+
selectCustom.textContent = texts.customBtnText || 'Custom';
|
|
68
|
+
selectCustom.addEventListener('click', async () => {
|
|
69
|
+
const res = await showTableCreator(texts);
|
|
70
|
+
if (res) {
|
|
71
|
+
options.onSelect?.(res.row, res.col);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
selectDom.appendChild(selectCustom);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return selectDom;
|
|
78
|
+
}
|