@ncds/ui-admin 1.8.28-alpha.3 → 1.8.28-alpha.4
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/cjs/assets/scripts/table/rowSpanBlock.js +97 -0
- package/dist/cjs/src/components/data-display/table/Table.js +135 -57
- package/dist/cjs/src/components/data-display/table/__tests__/Table.dnd.dragCell.test.js +7 -2
- package/dist/cjs/src/components/data-display/table/__tests__/Table.dnd.test.js +13 -8
- package/dist/cjs/src/components/data-display/table/__tests__/Table.rowGroup.test.js +54 -0
- package/dist/cjs/src/components/data-display/table/__tests__/Table.rowGroupDnd.test.js +212 -0
- package/dist/cjs/src/components/data-display/table/__tests__/dnd-context.test.js +5 -2
- package/dist/cjs/src/components/data-display/table/__tests__/tableSelectableStyle.test.js +75 -0
- package/dist/cjs/src/components/data-display/table/dnd-context.js +4 -1
- package/dist/cjs/src/components/data-display/table/dnd-move.js +46 -0
- package/dist/cjs/src/components/data-display/table/dnd-preview.js +8 -3
- package/dist/cjs/src/generated/scoped-css.js +1 -1
- package/dist/esm/assets/scripts/table/rowSpanBlock.js +85 -0
- package/dist/esm/src/components/data-display/table/Table.js +135 -57
- package/dist/esm/src/components/data-display/table/__tests__/Table.dnd.dragCell.test.js +7 -2
- package/dist/esm/src/components/data-display/table/__tests__/Table.dnd.test.js +13 -8
- package/dist/esm/src/components/data-display/table/__tests__/Table.rowGroup.test.js +51 -0
- package/dist/esm/src/components/data-display/table/__tests__/Table.rowGroupDnd.test.js +210 -0
- package/dist/esm/src/components/data-display/table/__tests__/dnd-context.test.js +5 -2
- package/dist/esm/src/components/data-display/table/__tests__/tableSelectableStyle.test.js +72 -0
- package/dist/esm/src/components/data-display/table/dnd-context.js +4 -1
- package/dist/esm/src/components/data-display/table/dnd-move.js +38 -0
- package/dist/esm/src/components/data-display/table/dnd-preview.js +8 -3
- package/dist/esm/src/generated/scoped-css.js +1 -1
- package/dist/temp/assets/scripts/table/rowSpanBlock.d.ts +29 -0
- package/dist/temp/assets/scripts/table/rowSpanBlock.js +77 -0
- package/dist/temp/src/components/data-display/table/Table.d.ts +7 -3
- package/dist/temp/src/components/data-display/table/Table.js +107 -47
- package/dist/temp/src/components/data-display/table/__tests__/Table.dnd.dragCell.test.js +10 -2
- package/dist/temp/src/components/data-display/table/__tests__/Table.dnd.test.js +16 -8
- package/dist/temp/src/components/data-display/table/__tests__/Table.rowGroup.test.d.ts +1 -0
- package/dist/temp/src/components/data-display/table/__tests__/Table.rowGroup.test.js +52 -0
- package/dist/temp/src/components/data-display/table/__tests__/Table.rowGroupDnd.test.d.ts +1 -0
- package/dist/temp/src/components/data-display/table/__tests__/Table.rowGroupDnd.test.js +137 -0
- package/dist/temp/src/components/data-display/table/__tests__/dnd-context.test.js +2 -2
- package/dist/temp/src/components/data-display/table/__tests__/tableSelectableStyle.test.d.ts +1 -0
- package/dist/temp/src/components/data-display/table/__tests__/tableSelectableStyle.test.js +71 -0
- package/dist/temp/src/components/data-display/table/dnd-context.d.ts +3 -0
- package/dist/temp/src/components/data-display/table/dnd-context.js +1 -0
- package/dist/temp/src/components/data-display/table/dnd-move.d.ts +17 -0
- package/dist/temp/src/components/data-display/table/dnd-move.js +31 -0
- package/dist/temp/src/components/data-display/table/dnd-preview.d.ts +5 -1
- package/dist/temp/src/components/data-display/table/dnd-preview.js +7 -3
- package/dist/temp/src/components/data-display/table/types.d.ts +14 -5
- package/dist/temp/src/generated/scoped-css.js +1 -1
- package/dist/types/assets/scripts/table/rowSpanBlock.d.ts +29 -0
- package/dist/types/src/components/data-display/table/Table.d.ts +7 -3
- package/dist/types/src/components/data-display/table/__tests__/Table.rowGroup.test.d.ts +1 -0
- package/dist/types/src/components/data-display/table/__tests__/Table.rowGroupDnd.test.d.ts +1 -0
- package/dist/types/src/components/data-display/table/__tests__/tableSelectableStyle.test.d.ts +1 -0
- package/dist/types/src/components/data-display/table/dnd-context.d.ts +3 -0
- package/dist/types/src/components/data-display/table/dnd-move.d.ts +17 -0
- package/dist/types/src/components/data-display/table/dnd-preview.d.ts +5 -1
- package/dist/types/src/components/data-display/table/types.d.ts +14 -5
- package/dist/ui-admin/assets/styles/style.css +60 -4
- package/package.json +1 -1
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
/**
|
|
3
|
+
* 묶음은 스타일 레이어이므로 드래그앤드롭 동작이 묶음 유무와 무관해야 한다.
|
|
4
|
+
* 드롭 자체는 실제 포인터 이벤트가 필요해 jsdom 으로 재현할 수 없어, 감시 등록 횟수와 콜백 전달만 고정한다.
|
|
5
|
+
*/
|
|
6
|
+
import { createElement } from 'react';
|
|
7
|
+
import { createRoot } from 'react-dom/client';
|
|
8
|
+
import { act } from 'react-dom/test-utils';
|
|
9
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
10
|
+
const monitorCalls = [];
|
|
11
|
+
vi.mock('@atlaskit/pragmatic-drag-and-drop/element/adapter', () => ({
|
|
12
|
+
dropTargetForElements: () => () => undefined,
|
|
13
|
+
draggable: () => () => undefined,
|
|
14
|
+
monitorForElements: args => {
|
|
15
|
+
monitorCalls.push(args);
|
|
16
|
+
return () => undefined;
|
|
17
|
+
}
|
|
18
|
+
}));
|
|
19
|
+
vi.mock('@atlaskit/pragmatic-drag-and-drop/element/disable-native-drag-preview', () => ({
|
|
20
|
+
disableNativeDragPreview: () => undefined
|
|
21
|
+
}));
|
|
22
|
+
vi.mock('@atlaskit/pragmatic-drag-and-drop-auto-scroll/element', () => ({
|
|
23
|
+
autoScrollForElements: () => () => undefined
|
|
24
|
+
}));
|
|
25
|
+
vi.mock('@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge', () => ({
|
|
26
|
+
attachClosestEdge: data => data,
|
|
27
|
+
extractClosestEdge: () => 'bottom'
|
|
28
|
+
}));
|
|
29
|
+
import { planMoveIds } from '../dnd-move';
|
|
30
|
+
const {
|
|
31
|
+
Table
|
|
32
|
+
} = await import('../Table');
|
|
33
|
+
let container;
|
|
34
|
+
let root;
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
monitorCalls.length = 0;
|
|
37
|
+
container = document.createElement('div');
|
|
38
|
+
document.body.appendChild(container);
|
|
39
|
+
act(() => {
|
|
40
|
+
root = createRoot(container);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
afterEach(() => {
|
|
44
|
+
act(() => {
|
|
45
|
+
root.unmount();
|
|
46
|
+
});
|
|
47
|
+
container.remove();
|
|
48
|
+
});
|
|
49
|
+
const rowProps = id => ({
|
|
50
|
+
key: id,
|
|
51
|
+
dragId: id,
|
|
52
|
+
children: /*#__PURE__*/createElement(Table.Cell, null, id)
|
|
53
|
+
});
|
|
54
|
+
const row = id => /*#__PURE__*/createElement(Table.Row, rowProps(id));
|
|
55
|
+
const groupProps = (key, onRowDrop, ids) => ({
|
|
56
|
+
key,
|
|
57
|
+
onRowDrop,
|
|
58
|
+
children: ids.map(row)
|
|
59
|
+
});
|
|
60
|
+
const group = (key, onRowDrop, ids) => /*#__PURE__*/createElement(Table.RowGroup, groupProps(key, onRowDrop, ids));
|
|
61
|
+
const bodyProps = (onRowDrop, ids) => ({
|
|
62
|
+
onRowDrop,
|
|
63
|
+
children: ids.map(row)
|
|
64
|
+
});
|
|
65
|
+
const plainBodyProps = ids => ({
|
|
66
|
+
children: ids.map(row)
|
|
67
|
+
});
|
|
68
|
+
const tableProps = children => ({
|
|
69
|
+
type: 'horizontal',
|
|
70
|
+
draggable: true,
|
|
71
|
+
children
|
|
72
|
+
});
|
|
73
|
+
const renderTable = children => {
|
|
74
|
+
act(() => {
|
|
75
|
+
root.render(/*#__PURE__*/createElement(Table, tableProps(children)));
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
describe('Table.RowGroup — 드래그앤드롭', () => {
|
|
79
|
+
it('묶음이 여러 개여도 드롭 감시는 한 번만 등록된다', () => {
|
|
80
|
+
const onRowDrop = vi.fn();
|
|
81
|
+
renderTable([group('g1', onRowDrop, ['a', 'b']), group('g2', onRowDrop, ['c', 'd']), group('g3', onRowDrop, ['e'])]);
|
|
82
|
+
expect(monitorCalls).toHaveLength(1);
|
|
83
|
+
});
|
|
84
|
+
it('묶음에 넘긴 onRowDrop 이 드롭 1회에 1번만 호출된다', () => {
|
|
85
|
+
const onRowDrop = vi.fn();
|
|
86
|
+
renderTable([group('g1', onRowDrop, ['a', 'b']), group('g2', onRowDrop, ['c', 'd'])]);
|
|
87
|
+
for (const call of monitorCalls) {
|
|
88
|
+
call.onDrop({
|
|
89
|
+
source: {
|
|
90
|
+
data: {
|
|
91
|
+
id: 'a'
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
location: {
|
|
95
|
+
current: {
|
|
96
|
+
dropTargets: [{
|
|
97
|
+
data: {
|
|
98
|
+
id: 'c'
|
|
99
|
+
}
|
|
100
|
+
}]
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
expect(onRowDrop).toHaveBeenCalledTimes(1);
|
|
106
|
+
expect(onRowDrop).toHaveBeenCalledWith('a', 'c', 'bottom', ['a']);
|
|
107
|
+
});
|
|
108
|
+
it('다중 선택 드래그는 고른 행과 그 병합 블록을 모두 넘긴다', () => {
|
|
109
|
+
const onRowDrop = vi.fn();
|
|
110
|
+
renderTable(/*#__PURE__*/createElement(Table.Body, bodyProps(onRowDrop, ['a', 'b', 'c', 'd'])));
|
|
111
|
+
const rows = Array.from(container.querySelectorAll('tbody tr'));
|
|
112
|
+
// a 가 b 를 덮고, c 는 혼자다 — a·c 를 고르면 b 도 따라와야 한다
|
|
113
|
+
rows[0].cells[0].rowSpan = 2;
|
|
114
|
+
rows[0].classList.add('ncua-table__row--selected');
|
|
115
|
+
rows[2].classList.add('ncua-table__row--selected');
|
|
116
|
+
monitorCalls[0].onDrop({
|
|
117
|
+
source: {
|
|
118
|
+
data: {
|
|
119
|
+
id: 'a',
|
|
120
|
+
moveIds: planMoveIds(rows[0])
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
location: {
|
|
124
|
+
current: {
|
|
125
|
+
dropTargets: [{
|
|
126
|
+
data: {
|
|
127
|
+
id: 'd'
|
|
128
|
+
}
|
|
129
|
+
}]
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
expect(onRowDrop).toHaveBeenCalledWith('a', 'd', 'bottom', ['a', 'b', 'c']);
|
|
134
|
+
});
|
|
135
|
+
it('고르지 않은 행을 잡으면 그 행의 블록만 넘긴다', () => {
|
|
136
|
+
const onRowDrop = vi.fn();
|
|
137
|
+
renderTable(/*#__PURE__*/createElement(Table.Body, bodyProps(onRowDrop, ['a', 'b', 'c', 'd'])));
|
|
138
|
+
const rows = Array.from(container.querySelectorAll('tbody tr'));
|
|
139
|
+
rows[0].cells[0].rowSpan = 2;
|
|
140
|
+
rows[2].classList.add('ncua-table__row--selected');
|
|
141
|
+
monitorCalls[0].onDrop({
|
|
142
|
+
source: {
|
|
143
|
+
data: {
|
|
144
|
+
id: 'a',
|
|
145
|
+
moveIds: planMoveIds(rows[0])
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
location: {
|
|
149
|
+
current: {
|
|
150
|
+
dropTargets: [{
|
|
151
|
+
data: {
|
|
152
|
+
id: 'd'
|
|
153
|
+
}
|
|
154
|
+
}]
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
expect(onRowDrop).toHaveBeenCalledWith('a', 'd', 'bottom', ['a', 'b']);
|
|
159
|
+
});
|
|
160
|
+
it('onRowDrop 을 거두면 드롭이 더 이상 호출되지 않는다', () => {
|
|
161
|
+
const onRowDrop = vi.fn();
|
|
162
|
+
const drop = () => monitorCalls[0].onDrop({
|
|
163
|
+
source: {
|
|
164
|
+
data: {
|
|
165
|
+
id: 'a'
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
location: {
|
|
169
|
+
current: {
|
|
170
|
+
dropTargets: [{
|
|
171
|
+
data: {
|
|
172
|
+
id: 'b'
|
|
173
|
+
}
|
|
174
|
+
}]
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
renderTable(/*#__PURE__*/createElement(Table.Body, bodyProps(onRowDrop, ['a', 'b'])));
|
|
179
|
+
drop();
|
|
180
|
+
expect(onRowDrop).toHaveBeenCalledTimes(1);
|
|
181
|
+
act(() => {
|
|
182
|
+
root.render(/*#__PURE__*/createElement(Table, tableProps(/*#__PURE__*/createElement(Table.Body, plainBodyProps(['a', 'b'])))));
|
|
183
|
+
});
|
|
184
|
+
drop();
|
|
185
|
+
expect(onRowDrop).toHaveBeenCalledTimes(1);
|
|
186
|
+
});
|
|
187
|
+
it('Table.Body 의 onRowDrop 동작은 묶음 도입 전과 같다', () => {
|
|
188
|
+
const onRowDrop = vi.fn();
|
|
189
|
+
renderTable(/*#__PURE__*/createElement(Table.Body, bodyProps(onRowDrop, ['a', 'b'])));
|
|
190
|
+
expect(monitorCalls).toHaveLength(1);
|
|
191
|
+
monitorCalls[0].onDrop({
|
|
192
|
+
source: {
|
|
193
|
+
data: {
|
|
194
|
+
id: 'a'
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
location: {
|
|
198
|
+
current: {
|
|
199
|
+
dropTargets: [{
|
|
200
|
+
data: {
|
|
201
|
+
id: 'b'
|
|
202
|
+
}
|
|
203
|
+
}]
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
expect(onRowDrop).toHaveBeenCalledTimes(1);
|
|
208
|
+
expect(onRowDrop).toHaveBeenCalledWith('a', 'b', 'bottom', ['a']);
|
|
209
|
+
});
|
|
210
|
+
});
|
|
@@ -46,13 +46,16 @@ describe('dnd-context — Provider 밖 기본값 (RSD-05)', () => {
|
|
|
46
46
|
});
|
|
47
47
|
expect(() => row?.setIsDragging(true)).not.toThrow();
|
|
48
48
|
});
|
|
49
|
-
it('RSD-05 TableDndContext 기본값은 드래그 비활성 · 빈 tableId
|
|
49
|
+
it('RSD-05 TableDndContext 기본값은 드래그 비활성 · 빈 tableId · 비어 있는 드롭 핸들러 자리다', () => {
|
|
50
50
|
const {
|
|
51
51
|
table
|
|
52
52
|
} = readDefaults();
|
|
53
53
|
expect(table).toEqual({
|
|
54
54
|
isDraggable: false,
|
|
55
|
-
tableId: ''
|
|
55
|
+
tableId: '',
|
|
56
|
+
onRowDropRef: {
|
|
57
|
+
current: undefined
|
|
58
|
+
}
|
|
56
59
|
});
|
|
57
60
|
});
|
|
58
61
|
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { compile as compileSass } from 'sass';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
// box-shadow 는 jsdom 에서 계산되지 않으므로, 컴파일된 CSS 에서 규칙을 검사한다.
|
|
5
|
+
// (page-title/__tests__/pageTitleStyle.test.ts 와 같은 방식)
|
|
6
|
+
const TABLE_SCSS_PATH = path.resolve(__dirname, '../../../../../assets/styles/components/table/_index.scss');
|
|
7
|
+
const compiledTableCss = compileSass(TABLE_SCSS_PATH).css;
|
|
8
|
+
/** 선택자 → 선언 목록. 같은 선택자가 여러 규칙에 나오면 선언을 이어 붙인다. */
|
|
9
|
+
const parseRules = css => {
|
|
10
|
+
const rules = new Map();
|
|
11
|
+
for (const [, selectorList, body] of css.matchAll(/([^{}]+)\{([^{}]*)\}/g)) {
|
|
12
|
+
const declarations = body.split(';').map(declaration => declaration.trim().replace(/\s+/g, ' ')).filter(Boolean);
|
|
13
|
+
for (const selector of selectorList.split(',').map(selector => selector.trim().replace(/\s+/g, ' '))) {
|
|
14
|
+
rules.set(selector, [...(rules.get(selector) ?? []), ...declarations]);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return rules;
|
|
18
|
+
};
|
|
19
|
+
const rules = parseRules(compiledTableCss);
|
|
20
|
+
const declarationsOf = selector => rules.get(selector) ?? [];
|
|
21
|
+
const SELECTABLE = '.ncua-table--selectable';
|
|
22
|
+
const IN_DATA_GRID = '.ncua-table--in-data-grid.ncua-table--selectable';
|
|
23
|
+
const UNSELECTED_ROW = '.ncua-table__body .ncua-table__row:not(.ncua-table__row--selected)';
|
|
24
|
+
const HEADER_FIRST_CELL = '.ncua-table__header-cell:first-child';
|
|
25
|
+
const COMPENSATION_LINE = 'box-shadow: inset 1px 0 0 0 var(--gray-100)';
|
|
26
|
+
const NO_SHADOW = 'box-shadow: none';
|
|
27
|
+
describe('Table selectable — 좌측 border 보상선', () => {
|
|
28
|
+
it('행(tr)이 보상선을 갖는다 — 병합 셀이 덮은 행의 첫 셀은 표 왼쪽 끝이 아니다', () => {
|
|
29
|
+
// Given: 컴파일된 Table CSS 에서
|
|
30
|
+
// When: selectable 의 보상 규칙을 찾으면
|
|
31
|
+
const declarations = declarationsOf(`${SELECTABLE} ${UNSELECTED_ROW}`);
|
|
32
|
+
// Then: 셀이 아니라 행 전체에 보상선을 둔다
|
|
33
|
+
expect(declarations).toContain(COMPENSATION_LINE);
|
|
34
|
+
});
|
|
35
|
+
it('헤더 첫 칸도 보상선을 갖는다', () => {
|
|
36
|
+
// Given/When: 헤더 첫 칸 규칙을 찾으면
|
|
37
|
+
// Then: 기존 보상선이 그대로다
|
|
38
|
+
expect(declarationsOf(`${SELECTABLE} ${HEADER_FIRST_CELL}`)).toContain(COMPENSATION_LINE);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
describe('Table selectable — DataGrid 안에서는 보상선을 거둔다', () => {
|
|
42
|
+
it('행(tr)의 보상선이 제거된다 — DataGrid wrapper 가 외곽 border 를 담당한다', () => {
|
|
43
|
+
// Given: 컴파일된 Table CSS 에서
|
|
44
|
+
// When: in-data-grid 조합의 행 규칙을 찾으면
|
|
45
|
+
const declarations = declarationsOf(`${IN_DATA_GRID} ${UNSELECTED_ROW}`);
|
|
46
|
+
// Then: 보상선을 지워 DataGrid 외곽선과 겹치지 않는다
|
|
47
|
+
expect(declarations).toContain(NO_SHADOW);
|
|
48
|
+
});
|
|
49
|
+
it('헤더 첫 칸의 보상선이 제거된다', () => {
|
|
50
|
+
// Given/When: in-data-grid 조합의 헤더 첫 칸 규칙을 찾으면
|
|
51
|
+
// Then: 보상선을 지운다
|
|
52
|
+
expect(declarationsOf(`${IN_DATA_GRID} ${HEADER_FIRST_CELL}`)).toContain(NO_SHADOW);
|
|
53
|
+
});
|
|
54
|
+
it('보상선을 받는 모든 자리에 제거 규칙이 대응한다 — 한쪽만 넓어지면 선이 남는다', () => {
|
|
55
|
+
// Given: 보상선을 받는 selectable 선택자를 모두 모으고
|
|
56
|
+
const compensated = [...rules].filter(_ref => {
|
|
57
|
+
let [selector, declarations] = _ref;
|
|
58
|
+
return selector.startsWith(SELECTABLE) && declarations.includes(COMPENSATION_LINE);
|
|
59
|
+
}).map(_ref2 => {
|
|
60
|
+
let [selector] = _ref2;
|
|
61
|
+
return selector;
|
|
62
|
+
});
|
|
63
|
+
// When: 각 선택자의 in-data-grid 대응 규칙을 찾으면
|
|
64
|
+
const uncovered = compensated.filter(selector => {
|
|
65
|
+
const counterpart = selector.replace(SELECTABLE, IN_DATA_GRID);
|
|
66
|
+
return !declarationsOf(counterpart).includes(NO_SHADOW);
|
|
67
|
+
});
|
|
68
|
+
// Then: 대응 없이 남는 자리가 없다
|
|
69
|
+
expect(compensated.length).toBeGreaterThan(0);
|
|
70
|
+
expect(uncovered).toEqual([]);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { createContext } from 'react';
|
|
2
2
|
const TableDndContext = /*#__PURE__*/createContext({
|
|
3
3
|
isDraggable: false,
|
|
4
|
-
tableId: ''
|
|
4
|
+
tableId: '',
|
|
5
|
+
onRowDropRef: {
|
|
6
|
+
current: undefined
|
|
7
|
+
}
|
|
5
8
|
});
|
|
6
9
|
const RowDndContext = /*#__PURE__*/createContext({
|
|
7
10
|
dragId: undefined,
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { computeRowSpanBlock, expandRowsToBlocks, locateRow as locateInBody, readRowSpans } from '../../../../assets/scripts/table/rowSpanBlock';
|
|
2
|
+
const DRAG_ID_ATTRIBUTE = 'data-draggable-id';
|
|
3
|
+
const toDragIds = rows => rows.map(row => row.getAttribute(DRAG_ID_ATTRIBUTE)).filter(id => id !== null);
|
|
4
|
+
/** 행 위치는 `tbody` 기준이라 묶음이 여러 개면 서로 겹친다 — 어느 `tbody` 인지 함께 본다 */
|
|
5
|
+
export const locateRow = rowEl => {
|
|
6
|
+
const located = locateInBody(rowEl);
|
|
7
|
+
const table = located?.body.closest('table');
|
|
8
|
+
if (!located || !table) return null;
|
|
9
|
+
return {
|
|
10
|
+
...located,
|
|
11
|
+
bodyIndex: Array.from(table.tBodies).indexOf(located.body)
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
/** 병합이 덮는 행은 따로 옮길 수 없다. 드래그 단위를 그 행이 속한 병합 블록으로 넓힌다. */
|
|
15
|
+
export const findRowSpanBlock = rowEl => {
|
|
16
|
+
const located = locateRow(rowEl);
|
|
17
|
+
if (!located) return null;
|
|
18
|
+
const {
|
|
19
|
+
body,
|
|
20
|
+
bodyIndex,
|
|
21
|
+
index
|
|
22
|
+
} = located;
|
|
23
|
+
const block = computeRowSpanBlock(readRowSpans(body), index);
|
|
24
|
+
return {
|
|
25
|
+
...block,
|
|
26
|
+
bodyIndex,
|
|
27
|
+
rows: Array.from(body.rows).slice(block.start, block.end + 1)
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
/** 이번 드래그로 옮겨야 하는 행 전부. 고른 행이 여럿이면 각자의 병합 블록까지 끌고 온다. */
|
|
31
|
+
export const planMoveIds = rowEl => {
|
|
32
|
+
const tableEl = rowEl.closest('table');
|
|
33
|
+
const selectedRows = tableEl ? Array.from(tableEl.querySelectorAll('tbody > .ncua-table__row--selected')) : [];
|
|
34
|
+
const isMultiSelect = selectedRows.length > 1 && selectedRows.includes(rowEl);
|
|
35
|
+
const rows = isMultiSelect ? expandRowsToBlocks(selectedRows) : findRowSpanBlock(rowEl)?.rows ?? [rowEl];
|
|
36
|
+
return toDragIds(rows);
|
|
37
|
+
};
|
|
38
|
+
export { DRAG_ID_ATTRIBUTE };
|
|
@@ -87,11 +87,16 @@ const buildRowCard = _ref => {
|
|
|
87
87
|
wrapper.appendChild(table);
|
|
88
88
|
return wrapper;
|
|
89
89
|
};
|
|
90
|
-
|
|
90
|
+
/**
|
|
91
|
+
* @param rows 미리보기에 그릴 행. 병합 묶음은 한 건이라도 행이 여러 개다
|
|
92
|
+
* @param itemCount 옮기는 건수. 병합 묶음은 행 수와 다르므로, 생략하면 행 수를 건수로 본다
|
|
93
|
+
*/
|
|
94
|
+
const buildDragPreview = function (rows, rowRect) {
|
|
95
|
+
let itemCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : rows.length;
|
|
91
96
|
const visibleCount = Math.min(rows.length, PREVIEW_MAX_ROWS);
|
|
92
97
|
const hasSummary = rows.length > visibleCount;
|
|
93
98
|
const totalCards = visibleCount + (hasSummary ? 1 : 0);
|
|
94
|
-
const isMulti =
|
|
99
|
+
const isMulti = itemCount > 1;
|
|
95
100
|
const parentTable = rows[0]?.closest('table') ?? null;
|
|
96
101
|
const rowWidth = Math.round(rowRect.width);
|
|
97
102
|
const rowHeight = Math.round(rowRect.height);
|
|
@@ -101,7 +106,7 @@ const buildDragPreview = (rows, rowRect) => {
|
|
|
101
106
|
width: `${PREVIEW_BADGE_HALF + rowWidth}px`,
|
|
102
107
|
height: `${PREVIEW_BADGE_HALF + rowHeight + PREVIEW_STACK_OFFSET * (totalCards - 1)}px`
|
|
103
108
|
});
|
|
104
|
-
if (isMulti) container.appendChild(buildCountBadge(
|
|
109
|
+
if (isMulti) container.appendChild(buildCountBadge(itemCount));
|
|
105
110
|
if (hasSummary) container.appendChild(buildSummaryCard(rowRect));
|
|
106
111
|
// 뒤쪽 행 카드부터 렌더해서 앞쪽이 위로 올라오게
|
|
107
112
|
for (let i = visibleCount - 1; i >= 0; i--) {
|