@antscorp/antsomi-ui 1.3.3-beta.3 → 1.3.3-beta.30

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.
Files changed (106) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/public/icons/stars_slider.png +0 -0
  3. package/es/assets/images/stars_slider.png +0 -0
  4. package/es/components/atoms/Button/index.d.ts +1 -8
  5. package/es/components/atoms/Flex/Flex.d.ts +2 -0
  6. package/es/components/atoms/Flex/Flex.js +1 -0
  7. package/es/components/atoms/Flex/index.d.ts +1 -0
  8. package/es/components/atoms/Flex/index.js +1 -0
  9. package/es/components/atoms/Input/Input.d.ts +14 -3
  10. package/es/components/atoms/Input/Input.js +7 -3
  11. package/es/components/atoms/InputDynamic/EditCaretPositioning.d.ts +2 -0
  12. package/es/components/atoms/InputDynamic/EditCaretPositioning.js +89 -0
  13. package/es/components/atoms/InputDynamic/InputDynamic.d.ts +29 -0
  14. package/es/components/atoms/InputDynamic/InputDynamic.js +320 -0
  15. package/es/components/atoms/InputDynamic/PopupShortLink.d.ts +16 -0
  16. package/es/components/atoms/InputDynamic/PopupShortLink.js +98 -0
  17. package/es/components/atoms/InputDynamic/index.d.ts +2 -0
  18. package/es/components/atoms/InputDynamic/index.js +1 -0
  19. package/es/components/atoms/InputDynamic/styled.d.ts +12 -0
  20. package/es/components/atoms/InputDynamic/styled.js +279 -0
  21. package/es/components/atoms/InputDynamic/utils.d.ts +22 -0
  22. package/es/components/atoms/InputDynamic/utils.js +751 -0
  23. package/es/components/atoms/Pagination/index.d.ts +1 -0
  24. package/es/components/atoms/Popover/Popover.d.ts +1 -1
  25. package/es/components/atoms/Popover/styled.d.ts +1 -1
  26. package/es/components/atoms/Progress/Progress.d.ts +1 -1
  27. package/es/components/atoms/Radio/index.d.ts +3 -3
  28. package/es/components/atoms/RateV2/RateV2.d.ts +18 -0
  29. package/es/components/atoms/RateV2/RateV2.js +73 -0
  30. package/es/components/atoms/RateV2/index.d.ts +1 -0
  31. package/es/components/atoms/RateV2/index.js +1 -0
  32. package/es/components/atoms/RequiredLabel/index.d.ts +1 -0
  33. package/es/components/atoms/RequiredLabel/index.js +4 -3
  34. package/es/components/atoms/Slider/index.d.ts +2 -1
  35. package/es/components/atoms/Slider/index.js +7 -14
  36. package/es/components/atoms/SliderV2/index.d.ts +6 -0
  37. package/es/components/atoms/SliderV2/index.js +21 -0
  38. package/es/components/atoms/Space/Space.d.ts +1 -1
  39. package/es/components/atoms/Spin/styled.d.ts +1 -1
  40. package/es/components/atoms/Statistic/Statistic.d.ts +1 -4
  41. package/es/components/atoms/index.d.ts +6 -0
  42. package/es/components/atoms/index.js +4 -0
  43. package/es/components/common/ConfigProvider/GlobalStyle.js +69 -2
  44. package/es/components/molecules/Collapse/Collapse.d.ts +3 -3
  45. package/es/components/molecules/Collapse/Collapse.js +9 -0
  46. package/es/components/molecules/ColorSetting/styled.d.ts +1 -8
  47. package/es/components/molecules/FontSetting/constants.d.ts +3 -0
  48. package/es/components/molecules/FontSetting/constants.js +22 -0
  49. package/es/components/molecules/FontSetting/index.d.ts +10 -4
  50. package/es/components/molecules/FontSetting/index.js +36 -35
  51. package/es/components/molecules/FontSetting/types.d.ts +1 -1
  52. package/es/components/molecules/Form/Form.d.ts +1 -0
  53. package/es/components/molecules/Form/Form.js +1 -0
  54. package/es/components/molecules/Form/index.d.ts +1 -0
  55. package/es/components/molecules/Form/index.js +1 -0
  56. package/es/components/molecules/IconSelection/styled.d.ts +1 -8
  57. package/es/components/molecules/Modal/Modal.d.ts +2 -2
  58. package/es/components/molecules/Modal/index.d.ts +1 -0
  59. package/es/components/molecules/Modal/styled.d.ts +1 -1
  60. package/es/components/molecules/ModalV2/ModalV2.d.ts +5 -0
  61. package/es/components/molecules/ModalV2/ModalV2.js +26 -0
  62. package/es/components/molecules/ModalV2/index.d.ts +2 -0
  63. package/es/components/molecules/ModalV2/index.js +1 -0
  64. package/es/components/molecules/ModalV2/styled.d.ts +7 -0
  65. package/es/components/molecules/ModalV2/styled.js +22 -0
  66. package/es/components/molecules/Popconfirm/Popconfirm.d.ts +1 -1
  67. package/es/components/molecules/PreviewModal/PreviewModal.d.ts +7 -0
  68. package/es/components/molecules/PreviewModal/PreviewModal.js +30 -0
  69. package/es/components/molecules/PreviewModal/index.d.ts +2 -0
  70. package/es/components/molecules/PreviewModal/index.js +1 -0
  71. package/es/components/molecules/PreviewModal/styled.d.ts +4 -0
  72. package/es/components/molecules/PreviewModal/styled.js +39 -0
  73. package/es/components/molecules/ResizeGrid/ResizeGrid.d.ts +3 -0
  74. package/es/components/molecules/ResizeGrid/ResizeGrid.js +640 -0
  75. package/es/components/molecules/ResizeGrid/components/Cell/Cell.d.ts +3 -0
  76. package/es/components/molecules/ResizeGrid/components/Cell/Cell.js +85 -0
  77. package/es/components/molecules/ResizeGrid/components/Cell/index.d.ts +1 -0
  78. package/es/components/molecules/ResizeGrid/components/Cell/index.js +1 -0
  79. package/es/components/molecules/ResizeGrid/components/Cell/styled.d.ts +3 -0
  80. package/es/components/molecules/ResizeGrid/components/Cell/styled.js +80 -0
  81. package/es/components/molecules/ResizeGrid/constant.d.ts +35 -0
  82. package/es/components/molecules/ResizeGrid/constant.js +111 -0
  83. package/es/components/molecules/ResizeGrid/index.d.ts +2 -0
  84. package/es/components/molecules/ResizeGrid/index.js +1 -0
  85. package/es/components/molecules/ResizeGrid/styled.d.ts +10 -0
  86. package/es/components/molecules/ResizeGrid/styled.js +55 -0
  87. package/es/components/molecules/ResizeGrid/types.d.ts +144 -0
  88. package/es/components/molecules/ResizeGrid/types.js +1 -0
  89. package/es/components/molecules/Select/Select.d.ts +6 -4
  90. package/es/components/molecules/Select/Select.js +23 -2
  91. package/es/components/molecules/TreeSelect/TreeSelect.d.ts +3 -4
  92. package/es/components/molecules/index.d.ts +6 -0
  93. package/es/components/molecules/index.js +4 -0
  94. package/es/components/organism/Help/styled.d.ts +6 -16
  95. package/es/components/organism/Table/ExplorePivotTable/styled.d.ts +1 -0
  96. package/es/constants/theme.js +30 -3
  97. package/es/hooks/useDeepCompareEffect.d.ts +1 -0
  98. package/es/hooks/useDeepCompareEffect.js +21 -0
  99. package/es/locales/en/translation.json +2 -1
  100. package/es/locales/i18n.d.ts +2 -0
  101. package/es/locales/translations.d.ts +1 -0
  102. package/es/locales/vi/translation.json +2 -1
  103. package/es/test.js +164 -66
  104. package/es/utils/common.d.ts +2 -0
  105. package/es/utils/common.js +16 -0
  106. package/package.json +8 -4
@@ -0,0 +1,640 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
21
+ import React, { useState, useRef, useEffect } from 'react';
22
+ import { Cell } from './components/Cell';
23
+ import { GRID_TEMPLATE, MIN_SIZE, THREADHOLD, buildGrid } from './constant';
24
+ import { StyledGrid, StyledMiddleLayer, StyledBGLayer, StyledLine } from './styled';
25
+ import { useDeepCompareEffect } from '../../../hooks/useDeepCompareEffect';
26
+ const defaultProps = {
27
+ containerStyle: {},
28
+ cellBorder: '1px dotted',
29
+ cellStyle: {},
30
+ cellActiveStyle: { background: '#2f79bf80' },
31
+ isPreviewMode: false,
32
+ isCompact: false,
33
+ delayUpdate: 100,
34
+ selectColor: '#2f79bf80',
35
+ };
36
+ export const ResizeGrid = props => {
37
+ const { containerStyle, cellBorder, cellStyle, cellActiveStyle, isPreviewMode, renderCell, grid: initGrid, image, imageSize, imagePosition, isCompact, onChange, delayUpdate, selectColor, } = props;
38
+ const [grid, setGrid] = useState(buildGrid(initGrid || GRID_TEMPLATE.GRID_2_3));
39
+ const startRef = useRef(null);
40
+ const startCellRef = useRef(null);
41
+ const selectRef = useRef(null);
42
+ const selectEndRef = useRef(null);
43
+ const gridRef = useRef();
44
+ const containerRef = useRef(null);
45
+ const verticalLineRef = useRef(null);
46
+ const horizontalLineRef = useRef(null);
47
+ const cellsRef = useRef({});
48
+ const cordinatesRef = useRef({});
49
+ const onChangeTimoutRef = useRef();
50
+ const onChangeDelayRef = useRef();
51
+ const acceptUpdateRef = useRef(false);
52
+ const ctrlKeyRef = useRef(false);
53
+ // console.log('grid', grid)
54
+ const handleChangeGrid = () => {
55
+ clearTimeout(onChangeTimoutRef.current);
56
+ onChangeTimoutRef.current = setTimeout(() => {
57
+ if (containerRef.current && cellsRef.current && cellsRef.current[0]) {
58
+ const container = containerRef.current.getBoundingClientRect();
59
+ // Object.values(cordinatesRef.current);
60
+ const childs = Object.values(cellsRef.current).map(cell => {
61
+ if (!cell || !cell.current)
62
+ return;
63
+ const childBox = cell.current.getBoundingClientRect();
64
+ return {
65
+ width: childBox.width,
66
+ height: childBox.height,
67
+ x: childBox.x - container.x,
68
+ y: childBox.y - container.y,
69
+ };
70
+ });
71
+ if (typeof onChange === 'function') {
72
+ onChange(grid, childs);
73
+ acceptUpdateRef.current = false;
74
+ clearTimeout(onChangeDelayRef.current);
75
+ onChangeDelayRef.current = setTimeout(() => {
76
+ acceptUpdateRef.current = true;
77
+ }, delayUpdate);
78
+ }
79
+ }
80
+ }, 300);
81
+ };
82
+ const isFollow = (cell, line, isCol = true) => isCol
83
+ ? (cell.colEnd !== line || !cell.width) && (cell.colStart !== line || !cell.width)
84
+ : (cell.rowEnd !== line || !cell.height) && (cell.rowStart !== line || !cell.height);
85
+ const notFollow = (cell, line, isCol = true) => !isFollow(cell, line, isCol);
86
+ useEffect(() => {
87
+ handleChangeGrid();
88
+ // eslint-disable-next-line react-hooks/exhaustive-deps
89
+ }, [grid]);
90
+ useDeepCompareEffect(() => {
91
+ if (acceptUpdateRef.current && (initGrid === null || initGrid === void 0 ? void 0 : initGrid.rows) && (initGrid === null || initGrid === void 0 ? void 0 : initGrid.cols)) {
92
+ setGrid(buildGrid(initGrid));
93
+ resetBackgroundCellRef();
94
+ }
95
+ // eslint-disable-next-line react-hooks/exhaustive-deps
96
+ }, [initGrid]);
97
+ useEffect(() => {
98
+ const handleMove = e => {
99
+ // Resize Grid
100
+ if (startRef.current && gridRef.current && containerRef.current) {
101
+ const { type, line } = startRef.current;
102
+ const idx = line - 1;
103
+ const { gridTemplateRows, gridTemplateColumns, rows, cols, childs } = gridRef.current;
104
+ if (idx <= 0 || (type === 'row' && idx >= rows) || (type === 'column' && idx >= cols))
105
+ return;
106
+ const { clientX, clientY } = e;
107
+ if (type === 'row') {
108
+ const gridHeight = containerRef.current.offsetHeight;
109
+ const yDistant = clientY - startRef.current.clientY;
110
+ const yPercentDistant = (100 * yDistant) / gridHeight;
111
+ const minPercent = (100 * MIN_SIZE) / gridHeight;
112
+ // console.log('move Y', clientY, yDistant, yPercentDistant);
113
+ const newArr = [...gridTemplateRows];
114
+ newArr[idx - 1] += yPercentDistant;
115
+ newArr[idx] -= yPercentDistant;
116
+ if (newArr[idx - 1] >= minPercent && newArr[idx] >= minPercent) {
117
+ const newChilds = JSON.parse(JSON.stringify(childs));
118
+ let isValidChildSize = true;
119
+ newChilds.forEach((child, idx) => {
120
+ var _a, _b;
121
+ if (isValidChildSize && notFollow(child, (_a = startRef.current) === null || _a === void 0 ? void 0 : _a.line, false)) {
122
+ if (child.rowStart === ((_b = startRef.current) === null || _b === void 0 ? void 0 : _b.line)) {
123
+ if (child.transformY) {
124
+ child.transformY = +child.transformY - yDistant;
125
+ }
126
+ else {
127
+ child.height = +child.height - yDistant;
128
+ }
129
+ }
130
+ else {
131
+ child.transformY && !child.movedBottom && (child.height = +child.height + yDistant);
132
+ }
133
+ // console.log('check...', startRef.current.line, child.transformY, yDistant, +child.transformY - yDistant)
134
+ if (child.height < MIN_SIZE) {
135
+ isValidChildSize = false;
136
+ }
137
+ }
138
+ });
139
+ isValidChildSize &&
140
+ setGrid(Object.assign(Object.assign({}, gridRef.current), { gridTemplateRows: newArr, childs: newChilds }));
141
+ }
142
+ }
143
+ else {
144
+ const xDistant = clientX - startRef.current.clientX;
145
+ const gridWidth = containerRef.current.offsetWidth;
146
+ const xPercentDistant = (100 * xDistant) / gridWidth;
147
+ const minPercent = (100 * MIN_SIZE) / gridWidth;
148
+ // console.log('move X', clientX, xDistant, xPercentDistant);
149
+ const newArr = [...gridTemplateColumns];
150
+ newArr[idx - 1] += xPercentDistant;
151
+ newArr[idx] -= xPercentDistant;
152
+ if (newArr[idx - 1] >= minPercent && newArr[idx] >= minPercent) {
153
+ const newChilds = JSON.parse(JSON.stringify(childs));
154
+ let isValidChildSize = true;
155
+ newChilds.forEach(child => {
156
+ if (isValidChildSize && notFollow(child, line)) {
157
+ if (child.colStart === line) {
158
+ if (child.transformX) {
159
+ child.transformX = +child.transformX - xDistant;
160
+ }
161
+ else {
162
+ child.width = +child.width - xDistant;
163
+ }
164
+ }
165
+ else {
166
+ child.transformX && !child.movedRight && (child.width = +child.width + xDistant);
167
+ }
168
+ // console.log('check...', startRef.current.line, child.transformX, xDistant, +child.transformX - xDistant)
169
+ if (child.width < MIN_SIZE) {
170
+ isValidChildSize = false;
171
+ }
172
+ }
173
+ });
174
+ isValidChildSize &&
175
+ setGrid(Object.assign(Object.assign({}, gridRef.current), { gridTemplateColumns: newArr, childs: newChilds }));
176
+ }
177
+ }
178
+ }
179
+ //-------------------------------------------
180
+ // Resize Cell
181
+ if (startCellRef.current && gridRef.current) {
182
+ const { clientX: startClientX, clientY: startClientY, direction, isRevert, leftCells, rightCells, } = startCellRef.current;
183
+ // const { rowStart, rowEnd, colStart, colEnd, transformX, transformY } = cell;
184
+ // const { gridTemplateRows, gridTemplateColumns, rows, cols, childs } = gridRef.current;
185
+ // if (
186
+ // idx < 0 ||
187
+ // (direction === 'top' && rowStart === 1) ||
188
+ // (direction === 'right' && colEnd === cols + 1) ||
189
+ // (direction === 'bottom' && rowEnd === rows + 1) ||
190
+ // (direction === 'left' && colStart === 1)
191
+ // )
192
+ // return;
193
+ const { clientX, clientY } = e;
194
+ if (['top', 'bottom'].includes(direction)) {
195
+ // const cellHeight = cellRef.current.offsetHeight;
196
+ const yDistant = clientY - startClientY;
197
+ // console.log('move Y', clientY, yDistant);
198
+ let isValid = true;
199
+ const mapNewSizeTop = {};
200
+ const mapNewSizeBottom = {};
201
+ Object.keys(leftCells).forEach(cellIdx => {
202
+ const cell = leftCells[cellIdx];
203
+ const newHeight = (cell.height || 0) + yDistant;
204
+ if (newHeight < MIN_SIZE) {
205
+ isValid = false;
206
+ }
207
+ mapNewSizeTop[cellIdx] = newHeight;
208
+ });
209
+ Object.keys(rightCells).forEach(cellIdx => {
210
+ const nextCell = rightCells[cellIdx];
211
+ const newHeightNextCell = (nextCell.height || 0) - yDistant;
212
+ if (newHeightNextCell < MIN_SIZE) {
213
+ isValid = false;
214
+ }
215
+ mapNewSizeBottom[cellIdx] = [newHeightNextCell, nextCell];
216
+ });
217
+ if (isValid) {
218
+ const newChilds = [...gridRef.current.childs];
219
+ Object.keys(mapNewSizeTop).forEach(cellIdx => {
220
+ newChilds[cellIdx] = Object.assign(Object.assign({}, newChilds[cellIdx]), { height: mapNewSizeTop[cellIdx], movedBottom: true });
221
+ });
222
+ Object.keys(mapNewSizeBottom).forEach(cellIdx => {
223
+ newChilds[cellIdx] = Object.assign(Object.assign({}, newChilds[cellIdx]), { height: mapNewSizeBottom[cellIdx][0], transformY: (mapNewSizeBottom[cellIdx][1].transformY || 0) + yDistant, movedTop: true });
224
+ });
225
+ setGrid(Object.assign(Object.assign({}, gridRef.current), { childs: newChilds }));
226
+ }
227
+ }
228
+ else {
229
+ // const cellWidth = cellRef.current.offsetWidth;
230
+ const xDistant = clientX - startClientX;
231
+ // console.log('move X', clientX, xDistant);
232
+ let isValid = true;
233
+ const mapNewSizeLeft = {};
234
+ const mapNewSizeRight = {};
235
+ const leftKeys = Object.keys(leftCells);
236
+ leftKeys.forEach(cellIdx => {
237
+ const cell = leftCells[cellIdx];
238
+ const newWidth = (cell.width || 0) + xDistant;
239
+ if (newWidth < MIN_SIZE) {
240
+ isValid = false;
241
+ }
242
+ else if (gridRef.current) {
243
+ const cellCordinate = cordinatesRef.current[cellIdx];
244
+ // const cell = gridRef.current.childs[cellIdx];
245
+ const newXEnd = cellCordinate.x + newWidth;
246
+ const nearestCells = Object.entries(cordinatesRef.current).filter(cor => gridRef.current &&
247
+ !leftKeys.includes(cor[0]) &&
248
+ gridRef.current.childs[cor[0]].rowStart !== cell.rowStart &&
249
+ (Math.abs(cor[1].x - newXEnd) <= THREADHOLD ||
250
+ Math.abs(cor[1].xEnd - newXEnd) <= THREADHOLD));
251
+ // console.log('nearestCells', nearestCells, newXEnd, leftKeys, cordinatesRef.current);
252
+ // if (nearestCells.length) {
253
+ // const nearestX =
254
+ // Math.abs(nearestCells[0][1].x - newXEnd) <= THREADHOLD
255
+ // ? nearestCells[0][1].x
256
+ // : nearestCells[0][1].xEnd;
257
+ // lineVertical(true, nearestX);
258
+ // } else {
259
+ // lineVertical(false);
260
+ // }
261
+ mapNewSizeLeft[cellIdx] = newWidth;
262
+ }
263
+ });
264
+ Object.keys(rightCells).forEach(cellIdx => {
265
+ const nextCell = rightCells[cellIdx];
266
+ const newWidthNextCell = (nextCell.width || 0) - xDistant;
267
+ if (newWidthNextCell < MIN_SIZE) {
268
+ isValid = false;
269
+ }
270
+ mapNewSizeRight[cellIdx] = [newWidthNextCell, nextCell];
271
+ });
272
+ if (isValid) {
273
+ const newChilds = [...gridRef.current.childs];
274
+ Object.keys(mapNewSizeLeft).forEach(cellIdx => {
275
+ newChilds[cellIdx] = Object.assign(Object.assign({}, newChilds[cellIdx]), { width: mapNewSizeLeft[cellIdx], movedRight: true });
276
+ });
277
+ Object.keys(mapNewSizeRight).forEach(cellIdx => {
278
+ newChilds[cellIdx] = Object.assign(Object.assign({}, newChilds[cellIdx]), { width: mapNewSizeRight[cellIdx][0], transformX: (mapNewSizeRight[cellIdx][1].transformX || 0) + xDistant, movedLeft: true });
279
+ });
280
+ setGrid(Object.assign(Object.assign({}, gridRef.current), { childs: newChilds }));
281
+ }
282
+ }
283
+ }
284
+ //------------------------------------------
285
+ // if (selectRef.current) {}
286
+ };
287
+ const handleUp = () => {
288
+ startRef.current = null;
289
+ startCellRef.current = null;
290
+ };
291
+ const isMac = () => navigator.platform.indexOf('Mac') >= 0;
292
+ window.addEventListener('mousemove', handleMove);
293
+ window.addEventListener('mouseup', handleUp);
294
+ const handleKeyDown = e => {
295
+ if (!ctrlKeyRef.current && ((isMac() && e.metaKey) || (!isMac() && e.key === 'Control'))) {
296
+ ctrlKeyRef.current = true;
297
+ // console.log('ctrlKeyRef', ctrlKeyRef.current);
298
+ }
299
+ };
300
+ const handleKeyUp = () => {
301
+ ctrlKeyRef.current = false;
302
+ // console.log('ctrlKeyRef', ctrlKeyRef.current);
303
+ };
304
+ window.addEventListener('keydown', handleKeyDown);
305
+ window.addEventListener('keyup', handleKeyUp);
306
+ return () => {
307
+ window.removeEventListener('mousemove', handleMove);
308
+ window.removeEventListener('mouseup', handleUp);
309
+ window.removeEventListener('keydown', handleKeyDown);
310
+ window.removeEventListener('keyup', handleKeyUp);
311
+ };
312
+ }, []);
313
+ // const rebaseCordinate = (x, y, ...rest) => {
314
+ // if (containerRef.current) {
315
+ // const container = containerRef.current.getBoundingClientRect();
316
+ // console.log('rebased', x - container.x, y - container.y, ...rest);
317
+ // }
318
+ // };
319
+ const activeCell = ({ idx }) => {
320
+ setGrid(prev => (Object.assign(Object.assign({}, prev), { childs: prev.childs.map((c, i) => (Object.assign(Object.assign({}, c), { active: i === idx }))) })));
321
+ };
322
+ const floorSize = size => Math.floor(size);
323
+ const findResizeCells = ({ type, line, direction, idx,
324
+ // cell,
325
+ isRevert, leftCols = [], rightCols = [], dones = [], level = 0, }) => {
326
+ // left is current cell and right is the opposite
327
+ if (dones.includes(idx)) {
328
+ return null;
329
+ }
330
+ const { childs } = grid;
331
+ const cellBox = cordinatesRef.current[idx];
332
+ dones.push(idx);
333
+ if (level === 0 && !leftCols.length) {
334
+ leftCols.push(idx);
335
+ }
336
+ let isEnd = true;
337
+ if (type === 'column') {
338
+ childs.forEach((cell, i) => {
339
+ if (((direction === 'left' && cell.colEnd === line) ||
340
+ (direction === 'right' && cell.colStart === line)) &&
341
+ !(floorSize(cordinatesRef.current[i].y) >= floorSize(cellBox.yEnd) ||
342
+ floorSize(cordinatesRef.current[i].yEnd) <= floorSize(cellBox.y))) {
343
+ if (!rightCols.includes(i)) {
344
+ rightCols.push(i);
345
+ // const cellIRef = cellsRef.current[i];
346
+ // if (cellIRef.current) {
347
+ // cellIRef.current.style.background = 'green';
348
+ // }
349
+ isEnd = false;
350
+ }
351
+ // else if (direction === 'right' && !leftCols.includes(i)) {
352
+ // leftCols.push(i);
353
+ // const cellIRef = cellsRef.current[i];
354
+ // if (cellIRef.current) {
355
+ // cellIRef.current.style.background = 'blue';
356
+ // }
357
+ // isEnd = false;
358
+ // }
359
+ }
360
+ });
361
+ }
362
+ else {
363
+ childs.forEach((cell, i) => {
364
+ if (((direction === 'top' && cell.rowEnd === line) ||
365
+ (direction === 'bottom' && cell.rowStart === line)) &&
366
+ !(floorSize(cordinatesRef.current[i].x) >= floorSize(cellBox.xEnd) ||
367
+ floorSize(cordinatesRef.current[i].xEnd) <= floorSize(cellBox.x))) {
368
+ if (!rightCols.includes(i)) {
369
+ rightCols.push(i);
370
+ // const cellIRef = cellsRef.current[i];
371
+ // if (cellIRef.current) {
372
+ // cellIRef.current.style.background = 'green';
373
+ // }
374
+ isEnd = false;
375
+ }
376
+ // else if (direction === 'bottom' && !leftCols.includes(i)) {
377
+ // leftCols.push(i);
378
+ // const cellIRef = cellsRef.current[i];
379
+ // if (cellIRef.current) {
380
+ // cellIRef.current.style.background = 'blue';
381
+ // }
382
+ // isEnd = false;
383
+ // }
384
+ }
385
+ });
386
+ }
387
+ // console.log(' find', direction, idx, leftCols, rightCols, dones, cordinatesRef.current);
388
+ if (!isEnd) {
389
+ // console.log('continue find', leftCols, rightCols);
390
+ rightCols
391
+ .filter(i => !dones.includes(i))
392
+ .forEach(i => {
393
+ findResizeCells({
394
+ type,
395
+ line,
396
+ direction: { left: 'right', right: 'left', top: 'bottom', bottom: 'top' }[direction] || '',
397
+ idx: i,
398
+ isRevert,
399
+ leftCols: rightCols,
400
+ rightCols: leftCols,
401
+ dones,
402
+ level: level + 1,
403
+ });
404
+ });
405
+ }
406
+ return { leftCols, rightCols };
407
+ };
408
+ const handleDownCell = (e, type, line, idx, direction, cell, cellRef) => {
409
+ const { clientX, clientY } = e;
410
+ // rebaseCordinate(clientX, clientY, type, line);
411
+ const isRevert = ['top', 'left'].includes(direction);
412
+ // let newIdx = isRevert ? idx - 1 : idx;
413
+ // let nextCellIdx = isRevert ? idx - 1 : idx + 1;
414
+ const leftCols = [idx];
415
+ const rightCols = [];
416
+ findResizeCells({ type, line, direction, idx, isRevert, leftCols, rightCols });
417
+ // console.log('change cell', leftCols, rightCols);
418
+ // if (['top', 'bottom'].includes(direction)) {
419
+ // nextCellIdx = grid.childs.findIndex(
420
+ // b =>
421
+ // b.colStart === cell.colStart &&
422
+ // ((isRevert && b.rowEnd === cell.rowStart) || (!isRevert && b.rowStart === cell.rowEnd)),
423
+ // );
424
+ // newIdx = isRevert ? nextCellIdx : idx;
425
+ // }
426
+ // if (nextCellIdx < 0) return;
427
+ if (!leftCols.length || !rightCols.length)
428
+ return;
429
+ const leftCells = {};
430
+ const rightCells = {};
431
+ leftCols.forEach(i => {
432
+ var _a, _b;
433
+ const cell = grid.childs[i];
434
+ const cellRef = cellsRef.current[i];
435
+ leftCells[i] = Object.assign({ width: cell.width || ((_a = cellRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth) || 0, height: cell.height || ((_b = cellRef.current) === null || _b === void 0 ? void 0 : _b.clientHeight) || 0, transformX: cell.transformX || 0, transformY: cell.transformY || 0, idx: i, cellRef }, cell);
436
+ });
437
+ rightCols.forEach(i => {
438
+ var _a, _b;
439
+ const cell = grid.childs[i];
440
+ const cellRef = cellsRef.current[i];
441
+ rightCells[i] = Object.assign({ width: cell.width || ((_a = cellRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth) || 0, height: cell.height || ((_b = cellRef.current) === null || _b === void 0 ? void 0 : _b.clientHeight) || 0, transformX: cell.transformX || 0, transformY: cell.transformY || 0, idx: i, cellRef }, cell);
442
+ });
443
+ const newDirection = isRevert
444
+ ? {
445
+ left: 'right',
446
+ right: 'left',
447
+ top: 'bottom',
448
+ bottom: 'top',
449
+ }[direction]
450
+ : direction;
451
+ startCellRef.current = {
452
+ clientX,
453
+ clientY,
454
+ // idx: newIdx,
455
+ direction: newDirection,
456
+ isRevert,
457
+ leftCells: isRevert ? rightCells : leftCells,
458
+ rightCells: !isRevert ? rightCells : leftCells,
459
+ };
460
+ // console.log('down cell', clientX, clientY, idx, direction, cell, cellRef);
461
+ gridRef.current = grid;
462
+ };
463
+ const handleDown = (e, type, line, idx, direction, cell, cellRef) => {
464
+ const { clientX, clientY } = e;
465
+ // rebaseCordinate(clientX, clientY, type, line);
466
+ startRef.current = { clientX, clientY, type, line };
467
+ // const isRevert = ['top', 'left'].includes(direction);
468
+ // const { leftCols, rightCols } = findResizeCells({ type, line, direction, idx, isRevert });
469
+ // console.log('change cell', leftCols, rightCols);
470
+ // console.log('down', type, line, clientX, clientY);
471
+ gridRef.current = JSON.parse(JSON.stringify(grid));
472
+ };
473
+ const handleUp = (e, direction, idx) => {
474
+ // console.log('up', direction, idx, e);
475
+ startRef.current = null;
476
+ startCellRef.current = null;
477
+ };
478
+ const downSelect = (idx, cell) => {
479
+ // console.log('dow select', idx, cell);
480
+ !cell.active && activeCell({ idx });
481
+ selectRef.current = { idx, cell };
482
+ gridRef.current = grid;
483
+ };
484
+ const unMerge = (cell, idx) => {
485
+ const { colStart, colEnd, rowStart, rowEnd } = cell;
486
+ if (colStart + 1 === colEnd && rowStart + 1 === rowEnd) {
487
+ return;
488
+ }
489
+ const newChilds = [...grid.childs];
490
+ for (let i = rowStart; i < rowEnd; i++) {
491
+ for (let j = colStart; j < colEnd; j++) {
492
+ const rStart = i;
493
+ const cStart = j;
494
+ const rEnd = rStart + 1;
495
+ const cEnd = cStart + 1;
496
+ // console.log('merge', i, j, rStart, cStart, rEnd, cEnd)
497
+ const newChild = {
498
+ colStart: cStart,
499
+ colEnd: cEnd,
500
+ rowStart: rStart,
501
+ rowEnd: rEnd,
502
+ };
503
+ if (i === rowStart && j === colStart) {
504
+ newChilds[idx] = newChild;
505
+ }
506
+ else if (rStart !== rowStart ||
507
+ rEnd !== rowEnd ||
508
+ cStart !== colStart ||
509
+ cEnd !== colEnd) {
510
+ newChilds.splice(idx, 0, newChild);
511
+ }
512
+ }
513
+ }
514
+ setGrid(prev => (Object.assign(Object.assign({}, prev), { childs: newChilds })));
515
+ };
516
+ function resetBackgroundCellRef() {
517
+ Object.values(cellsRef.current).forEach(r => {
518
+ if (r.current) {
519
+ r.current.style.background = 'unset';
520
+ }
521
+ });
522
+ }
523
+ const upSelect = (idx, cell) => {
524
+ // console.log('up select', idx, cell);
525
+ if (selectRef.current &&
526
+ selectEndRef.current &&
527
+ gridRef.current &&
528
+ selectRef.current.idx !== selectEndRef.current.idx &&
529
+ (selectEndRef.current.cell.rowEnd > selectRef.current.cell.rowEnd ||
530
+ selectEndRef.current.cell.colEnd > selectRef.current.cell.colEnd)) {
531
+ resetBackgroundCellRef();
532
+ // console.log('merge', selectRef.current, selectEndRef.current)
533
+ const { cell: cellStart, idx: idxStart } = selectRef.current;
534
+ const { cell: cellEnd, idx: idxEnd, hCells } = selectEndRef.current;
535
+ const newChilds = JSON.parse(JSON.stringify(gridRef.current.childs));
536
+ newChilds[idxStart].rowEnd = cellEnd.rowEnd;
537
+ newChilds[idxStart].colEnd = cellEnd.colEnd;
538
+ delete newChilds[idxStart].width;
539
+ delete newChilds[idxStart].height;
540
+ hCells.reverse().forEach(i => {
541
+ if (i !== idxStart) {
542
+ newChilds.splice(i, 1);
543
+ delete cellsRef.current[i];
544
+ delete cordinatesRef.current[i];
545
+ }
546
+ });
547
+ setGrid(Object.assign(Object.assign({}, gridRef.current), { childs: newChilds }));
548
+ }
549
+ selectRef.current = null;
550
+ selectEndRef.current = null;
551
+ };
552
+ const hoverSelect = (idx, cell) => {
553
+ if (selectRef.current && gridRef.current) {
554
+ // console.log('hover select', idx, cell);
555
+ const { cell: cellStart, idx: idxStart } = selectRef.current;
556
+ const hCells = [];
557
+ gridRef.current.childs.forEach((child, i) => {
558
+ if (child.rowStart >= cellStart.rowStart &&
559
+ child.rowEnd <= cell.rowEnd &&
560
+ child.colStart >= cellStart.colStart &&
561
+ child.colEnd <= cell.colEnd) {
562
+ hCells.push(i);
563
+ }
564
+ });
565
+ // console.log('hCells', hCells)
566
+ resetBackgroundCellRef();
567
+ hCells.forEach(i => {
568
+ const cellRef = cellsRef.current[i];
569
+ if (cellRef && cellRef.current) {
570
+ cellRef.current.style.background = selectColor || 'unset';
571
+ }
572
+ });
573
+ selectEndRef.current = { cell, idx, hCells };
574
+ gridRef.current = grid;
575
+ }
576
+ };
577
+ const setRef = (idx, ref) => {
578
+ cellsRef.current[idx] = ref;
579
+ // console.log('cellsRef.current', cellsRef.current)
580
+ };
581
+ const setCordinate = (idx) => __awaiter(void 0, void 0, void 0, function* () {
582
+ var _b;
583
+ // while(!cellsRef[idx]) {
584
+ // await new Promise(r => {setTimeout(r, 100)});
585
+ // console.log('wait', idx, cellsRef[idx])
586
+ // }
587
+ // console.log('set corr', idx, cellsRef.current[idx], cellsRef)
588
+ if (containerRef.current) {
589
+ const container = containerRef.current.getBoundingClientRect();
590
+ const childRef = cellsRef.current[idx];
591
+ const childBox = (_b = childRef.current) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect();
592
+ if (childBox) {
593
+ const cordinate = {
594
+ width: childBox.width,
595
+ height: childBox.height,
596
+ x: childBox.x - container.x,
597
+ y: childBox.y - container.y,
598
+ xEnd: childBox.x - container.x + childBox.width,
599
+ yEnd: childBox.y - container.y + childBox.height,
600
+ };
601
+ cordinatesRef.current[idx] = cordinate;
602
+ // console.log('set cor', idx, cordinate);
603
+ }
604
+ }
605
+ });
606
+ const renderGrid = (style) => {
607
+ const { gridTemplateColumns, gridTemplateRows, childs } = grid;
608
+ // console.log('grid', { gridTemplateColumns, gridTemplateRows, childs });
609
+ return (React.createElement("div", { className: "grid-container", ref: containerRef, style: Object.assign({ gridTemplateColumns: gridTemplateColumns.map(fr => `${fr}%`).join(' '), gridTemplateRows: gridTemplateRows.map(fr => `${fr}%`).join(' ') }, style) }, childs.map((cell, idx) => (React.createElement(Cell, { key: `${cell.rowStart}-${cell.colStart}-${cell.rowEnd}-${cell.colEnd}`, idx: idx, cell: cell, down: handleDown, downCell: handleDownCell, up: handleUp, setRef: setRef, setCordinate: setCordinate, downSelect: downSelect, upSelect: upSelect, hoverSelect: hoverSelect, unMerge: unMerge, renderCell: renderCell, borderStyle: cellBorder, style: cellStyle, activeStyle: cellActiveStyle, isPreviewMode: isPreviewMode, rowPercentage: grid.gridTemplateRows[cell.rowStart - 1], colPercentage: grid.gridTemplateColumns[cell.colStart - 1], ctrlKeyRef: ctrlKeyRef })))));
610
+ };
611
+ function lineVertical(isShow = true, left = 0) {
612
+ if (verticalLineRef.current) {
613
+ verticalLineRef.current.style.display = isShow ? 'block' : 'none';
614
+ if (isShow) {
615
+ verticalLineRef.current.style.left = `${left}px`;
616
+ }
617
+ }
618
+ }
619
+ function lineHorizontal(isShow = true, top = 0) {
620
+ if (horizontalLineRef.current) {
621
+ horizontalLineRef.current.style.display = isShow ? 'block' : 'none';
622
+ if (isShow) {
623
+ horizontalLineRef.current.style.top = `${top}px`;
624
+ }
625
+ }
626
+ }
627
+ const _a = containerStyle || {}, { border, borderTop, borderRight, borderBottom, borderLeft } = _a, rest = __rest(_a, ["border", "borderTop", "borderRight", "borderBottom", "borderLeft"]);
628
+ const renderLines = () => (React.createElement(React.Fragment, null,
629
+ React.createElement(StyledLine, { ref: verticalLineRef, className: "vertical" }),
630
+ React.createElement(StyledLine, { ref: horizontalLineRef, className: "horizontal" })));
631
+ return (React.createElement(StyledGrid, { className: "grid-wrapper", isCompact: !!isCompact },
632
+ React.createElement(StyledBGLayer, { style: {
633
+ backgroundImage: image ? `url(${image})` : 'unset',
634
+ backgroundSize: imageSize === 'fill' ? '100% 100%' : imageSize,
635
+ backgroundPosition: imagePosition,
636
+ } }),
637
+ React.createElement(StyledMiddleLayer, { style: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (border && { border })), (borderTop && { borderTop })), (borderRight && { borderRight })), (borderBottom && { borderBottom })), (borderLeft && { borderLeft })) }),
638
+ renderGrid(rest)));
639
+ };
640
+ ResizeGrid.defaultProps = defaultProps;
@@ -0,0 +1,3 @@
1
+ import { FC } from 'react';
2
+ import { CellProps } from '../../types';
3
+ export declare const Cell: FC<CellProps>;