publ-echo-test 0.0.113 → 0.0.115

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.
@@ -37,7 +37,7 @@ import { bottom, cloneLayoutItem, compact, getAllCollisions, getBoundingArea, ge
37
37
  import { calcGridColWidth, calcXY, resolveRowHeight, } from "../GridItem/utils/calculateUtils";
38
38
  import GridItem from "../GridItem/GridItem";
39
39
  import isEqual from "../../external-lib/lodash.isEqual";
40
- import { findAllChildrenComponentIds, findChildrenComponentIds, findGroupBlocks, getBlockIdByComponentId, getBlockSpecificType, zIndexMap } from "./group";
40
+ import { findAllChildrenCbIds, findDirectChildrenBlockIds, findGroupBlocks, formatBlockIdToCbId, getBlockSpecificType, zIndexMap } from "./group";
41
41
  import GroupItem from "../GridItem/GroupItem";
42
42
  import OutsideClickHandler from "../GridItem/OutsideClickHandler";
43
43
  var layoutClassName = "react-grid-layout";
@@ -57,8 +57,8 @@ var ReactGridLayout = function (_a) {
57
57
  var _6 = useState(), droppingDOMNode = _6[0], setDroppingDOMNode = _6[1];
58
58
  var _7 = useState(), droppingPosition = _7[0], setDroppingPosition = _7[1];
59
59
  var _8 = useState(false), isMounted = _8[0], setIsMounted = _8[1];
60
- var editableItems = blockStructure ? findChildrenComponentIds(blockStructure.children, editingGroupBlock) : [];
61
- var editingGroupAllChildren = (blockStructure && editingGroupBlock) ? findAllChildrenComponentIds(blockStructure.children, editingGroupBlock).map(function (i) { return i.toString(); }) : [];
60
+ var editableItems = blockStructure ? findDirectChildrenBlockIds(blockStructure, editingGroupBlock) : [];
61
+ var editingGroupAllChildren = (blockStructure && editingGroupBlock) ? findAllChildrenCbIds(blockStructure, editingGroupBlock).map(function (i) { return i.toString(); }) : [];
62
62
  var _9 = useState([]), oldGroupChildren = _9[0], setOldGroupChildren = _9[1];
63
63
  var _10 = useState(function () {
64
64
  return synchronizeLayoutWithChildren(props.layout || [], children, cols, compactType, allowOverlap);
@@ -147,7 +147,7 @@ var ReactGridLayout = function (_a) {
147
147
  if (!blockStructure) {
148
148
  return;
149
149
  }
150
- var childrenIds = findAllChildrenComponentIds(blockStructure.children, i).map(function (i) { return i.toString(); });
150
+ var childrenIds = findAllChildrenCbIds(blockStructure, i).map(function (i) { return i.toString(); });
151
151
  var children_1 = childrenIds.map(function (id) {
152
152
  var item = getLayoutItem(layout, id);
153
153
  return cloneLayoutItem(item);
@@ -174,7 +174,7 @@ var ReactGridLayout = function (_a) {
174
174
  if (!blockStructure) {
175
175
  return;
176
176
  }
177
- var children_2 = findChildrenComponentIds(blockStructure.children, i).map(function (id) {
177
+ var children_2 = findDirectChildrenBlockIds(blockStructure, i).map(function (id) {
178
178
  var item = getLayoutItem(layout, id);
179
179
  return cloneLayoutItem(item);
180
180
  });
@@ -515,7 +515,7 @@ var ReactGridLayout = function (_a) {
515
515
  var originalKey = String(child.key).split(".$");
516
516
  return originalKey[1] === l.i;
517
517
  });
518
- var isInBulk = blockStructure && (bulkIds === null || bulkIds === void 0 ? void 0 : bulkIds.includes(getBlockIdByComponentId(blockStructure.children, Number(activeDrag.i))));
518
+ var isInBulk = blockStructure && (bulkIds === null || bulkIds === void 0 ? void 0 : bulkIds.includes(formatBlockIdToCbId(Number(activeDrag.i))));
519
519
  if (!item) {
520
520
  return null;
521
521
  }
@@ -544,7 +544,7 @@ var ReactGridLayout = function (_a) {
544
544
  var bounded = draggable && isBounded && l.isBounded !== false;
545
545
  var editable = editableItems.includes(l.i);
546
546
  var z = l.z || 0;
547
- var isInBulk = blockStructure && (bulkIds === null || bulkIds === void 0 ? void 0 : bulkIds.includes(getBlockIdByComponentId(blockStructure.children, Number(l.i))));
547
+ var isInBulk = blockStructure && (bulkIds === null || bulkIds === void 0 ? void 0 : bulkIds.includes(formatBlockIdToCbId(Number(activeDrag === null || activeDrag === void 0 ? void 0 : activeDrag.i))));
548
548
  var isRoot = editingGroupBlock === 'ROOT';
549
549
  var baseZ = function () {
550
550
  if (isInBulk) {
@@ -639,7 +639,7 @@ var ReactGridLayout = function (_a) {
639
639
  if (!blockStructure) {
640
640
  return;
641
641
  }
642
- var childrenIds = findAllChildrenComponentIds(blockStructure.children, block.blockId).map(function (i) { return i.toString(); });
642
+ var childrenIds = findAllChildrenCbIds(blockStructure, block.blockId).map(function (i) { return i.toString(); });
643
643
  var groupItem = getBoundingArea(layout, childrenIds);
644
644
  // const draggable =
645
645
  // typeof l.isDraggable === "boolean"
@@ -698,7 +698,7 @@ var ReactGridLayout = function (_a) {
698
698
  // resizeHandle={resizeHandle}
699
699
  isHiddenVisibility: isHiddenVisibility, customColWidth: colWidth, autoResize: false, onContextGroup: handleClickContextGroup, children: _jsx("div", { onClick: handleClick, onDoubleClick: handleDoubleClick }) }, block.blockId) }));
700
700
  };
701
- var currentGroupBlocks = blockStructure ? findGroupBlocks(blockStructure.children, editingGroupBlock) : [];
701
+ var currentGroupBlocks = blockStructure ? findGroupBlocks(blockStructure, editingGroupBlock) : [];
702
702
  return (_jsxs("div", { ref: innerRef, className: mergedClassName, style: mergedStyle, onDrop: isDroppable ? onDropHandler : noop, onDragLeave: isDroppable ? onDragLeaveHandler : noop, onDragEnter: isDroppable ? onDragEnterHandler : noop, onDragOver: isDroppable ? onDragOverHandler : noop, children: [currentGroupBlocks.map(function (each) { return processGroup(each); }), React.Children.map(children, function (child) { return processGridItem(child); }), placeholder(), activeDrag && _jsx("div", { className: "grid-guide-line-center" }), activeDrag && (_jsx("div", { className: "grid-placeholder", style: {
703
703
  marginTop: margin[1] + "px",
704
704
  marginBottom: margin[1] + "px",
@@ -6,6 +6,7 @@ export declare const zIndexMap: {
6
6
  ROOT: number;
7
7
  };
8
8
  export declare function getBlockSpecificType(block: Block): "ROOT" | "BULK" | "COMPONENT_BLOCK" | "GROUP_BLOCK";
9
+ export type SectionPedigree = RootBlock;
9
10
  export type Block = ComponentBlock | GroupBlock | RootBlock;
10
11
  export type ZOrder = {
11
12
  [platform in "mobile" | "desktop"]: {
@@ -40,21 +41,13 @@ export type BulkBlockInternal = {
40
41
  zOrderMobileInternal: number;
41
42
  children: (ComponentBlock | GroupBlock)[];
42
43
  };
43
- export declare const findBlockByBlockId: (blocks: Block[], blockId: string) => Block | null;
44
- export declare const findChildrenComponentIds: (blockStructure: Block[], targetId: string) => string[];
45
- export declare const findAllChildrenIds: (blockStructure: Block[], targetId: string, depth?: 'current' | 'deep') => string[];
46
- export declare const findAllChildrenComponentIds: (blockStructure: Block[], targetId: string) => number[];
47
- export declare const findAllParentGroups: (blockStructure: Block[], targetId: string) => GroupBlock[];
48
- export declare const findGroupBlocks: (blockStructure: Block[], targetId: string) => GroupBlock[];
49
- export declare const findAllChildrenCbIds: (blockStructure: Block[]) => number[];
50
- export declare const findParentGroupByGroupId: (blockStructure: Block[], targetId: string) => string | null;
51
- export declare const addBlockToRoot: (blockStructure: Block[], newBlock: Block) => Block[];
52
- export declare const addBulkToTarget: (blockStructure: RootBlock, targetId: string, bulkIds: string[]) => RootBlock;
53
- export declare const getBlockWorkDirPath: (blockStructure: Block[], blockId: string) => string | null;
54
- export declare const getBlockIdByComponentId: (blockStructure: Block[], componentId: number) => string | null;
55
- export declare const blockStructure: RootBlock;
56
- export declare const mapComponentBlockIdsToBlockIds: (blockStructure: Block[]) => {
57
- CB_ID: Record<number, string>;
58
- BLOCK_ID: Record<string, number>;
59
- };
60
- export declare const findAccessibleChildrenBlocks: (blockStructure: Block[], targetGroupId: string, blockIds: string[]) => string[];
44
+ export declare const findBlockByBlockId: (block: Block, blockId: string) => Block | null;
45
+ export declare const findDirectChildrenCbIds: (block: Block, targetId: string) => number[];
46
+ export declare const findAllChildrenCbIds: (block: Block, targetId: string) => number[];
47
+ export declare const findAllChildrenBlockIds: (block: Block, targetId: string) => string[];
48
+ export declare const findDirectChildrenBlockIds: (block: Block, targetId: string) => string[];
49
+ export declare const findGroupBlocks: (blockStructure: Block, targetId: string) => GroupBlock[];
50
+ export declare const addBulkToTarget: (block: Block, targetId: string, bulkBlockIds: string[]) => Block;
51
+ export declare const getBlockWorkDirPath: (block: Block, blockId: string) => string | null;
52
+ export declare function formatBlockIdToCbId(cbId: number): string;
53
+ export declare function formatCbIdToBlockId(cbId: string): number | null;
@@ -1,14 +1,3 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
1
  var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13
2
  if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14
3
  if (ar || !(i in from)) {
@@ -35,14 +24,45 @@ export function getBlockSpecificType(block) {
35
24
  return block.type;
36
25
  }
37
26
  var deepClone = function (blocks) { return JSON.parse(JSON.stringify(blocks)); };
38
- export var findBlockByBlockId = function (blocks, blockId) {
39
- for (var _i = 0, blocks_1 = blocks; _i < blocks_1.length; _i++) {
40
- var block = blocks_1[_i];
41
- if (block.blockId === blockId) {
42
- return block;
27
+ var collectChildrenCbIds = function (block, depth) {
28
+ var ids = [];
29
+ if ('children' in block && block.children) {
30
+ for (var _i = 0, _a = block.children; _i < _a.length; _i++) {
31
+ var child = _a[_i];
32
+ if (child.type === 'COMPONENT_BLOCK') {
33
+ ids.push(child.componentBlockId);
34
+ }
35
+ if (depth === 'deep' && child.type === 'GROUP_BLOCK') {
36
+ ids = ids.concat(collectChildrenCbIds(child, depth));
37
+ }
38
+ }
39
+ }
40
+ return ids;
41
+ };
42
+ var collectChildrenBlockIds = function (block, depth) {
43
+ var ids = [];
44
+ if ('children' in block && block.children) {
45
+ for (var _i = 0, _a = block.children; _i < _a.length; _i++) {
46
+ var child = _a[_i];
47
+ ids.push(child.blockId);
48
+ if (depth === 'deep') {
49
+ ids = ids.concat(collectChildrenBlockIds(child, depth));
50
+ }
43
51
  }
44
- if (block.type === 'GROUP_BLOCK' && block.children) {
45
- var found = findBlockByBlockId(block.children, blockId);
52
+ }
53
+ return ids;
54
+ };
55
+ export var findBlockByBlockId = function (block, blockId) {
56
+ if (block.type !== 'GROUP_BLOCK' || block.children.length === 0) {
57
+ return null;
58
+ }
59
+ for (var _i = 0, _a = block.children; _i < _a.length; _i++) {
60
+ var child = _a[_i];
61
+ if (child.blockId === blockId) {
62
+ return child;
63
+ }
64
+ if (child.type === 'GROUP_BLOCK' && child.children) {
65
+ var found = findBlockByBlockId(child, blockId);
46
66
  if (found) {
47
67
  return found;
48
68
  }
@@ -50,84 +70,34 @@ export var findBlockByBlockId = function (blocks, blockId) {
50
70
  }
51
71
  return null;
52
72
  };
53
- export var findChildrenComponentIds = function (blockStructure, targetId) {
54
- var targetBlock = findBlockByBlockId(blockStructure, targetId);
73
+ export var findDirectChildrenCbIds = function (block, targetId) {
74
+ var targetBlock = findBlockByBlockId(block, targetId);
55
75
  if (!targetBlock || targetBlock.type !== 'GROUP_BLOCK') {
56
76
  return [];
57
77
  }
58
- var blockCBChildren = targetBlock.children.filter(function (child) { return child.type === 'COMPONENT_BLOCK'; });
59
- return blockCBChildren.map(function (cb) { return cb.componentBlockId.toString(); });
78
+ return collectChildrenCbIds(targetBlock, 'current');
60
79
  };
61
- export var findAllChildrenIds = function (blockStructure, targetId, depth) {
62
- if (depth === void 0) { depth = 'deep'; }
63
- var collectChildrenIds = function (block) {
64
- var ids = [];
65
- if ('children' in block && block.children) {
66
- for (var _i = 0, _a = block.children; _i < _a.length; _i++) {
67
- var child = _a[_i];
68
- ids.push(child.blockId);
69
- if (depth === 'deep') {
70
- ids = ids.concat(collectChildrenIds(child));
71
- }
72
- }
73
- }
74
- return ids;
75
- };
76
- var targetBlock = findBlockByBlockId(blockStructure, targetId);
77
- return targetBlock ? collectChildrenIds(targetBlock) : [];
80
+ export var findAllChildrenCbIds = function (block, targetId) {
81
+ var targetBlock = findBlockByBlockId(block, targetId);
82
+ if (!targetBlock || targetBlock.type !== 'GROUP_BLOCK') {
83
+ return [];
84
+ }
85
+ return collectChildrenCbIds(targetBlock, 'deep');
78
86
  };
79
- export var findAllChildrenComponentIds = function (blockStructure, targetId) {
80
- var collectComponentIds = function (block) {
81
- var ids = [];
82
- if ('children' in block && block.children) {
83
- for (var _i = 0, _a = block.children; _i < _a.length; _i++) {
84
- var child = _a[_i];
85
- if (child.type === 'COMPONENT_BLOCK') {
86
- ids.push(child.componentBlockId);
87
- }
88
- ids = ids.concat(collectComponentIds(child));
89
- }
90
- }
91
- return ids;
92
- };
93
- var targetBlock = findBlockByBlockId(blockStructure, targetId);
94
- return targetBlock ? collectComponentIds(targetBlock) : [];
87
+ export var findAllChildrenBlockIds = function (block, targetId) {
88
+ var targetBlock = findBlockByBlockId(block, targetId);
89
+ if (!targetBlock || targetBlock.type !== 'GROUP_BLOCK') {
90
+ return [];
91
+ }
92
+ return collectChildrenBlockIds(targetBlock, 'deep');
95
93
  };
96
- export var findAllParentGroups = function (blockStructure, targetId) {
97
- var findParentGroups = function (blocks, id, parents) {
98
- if (parents === void 0) { parents = []; }
99
- for (var _i = 0, blocks_2 = blocks; _i < blocks_2.length; _i++) {
100
- var block = blocks_2[_i];
101
- if (block.blockId === id && block.type === 'GROUP_BLOCK') {
102
- return parents;
103
- }
104
- if ('children' in block && block.children) {
105
- var result = findParentGroups(block.children, id, block.type === 'GROUP_BLOCK' ? __spreadArray(__spreadArray([], parents, true), [block], false) : parents);
106
- if (result) {
107
- return result;
108
- }
109
- }
110
- }
111
- return null;
112
- };
113
- return findParentGroups(blockStructure, targetId) || [];
94
+ export var findDirectChildrenBlockIds = function (block, targetId) {
95
+ var targetBlock = findBlockByBlockId(block, targetId);
96
+ if (!targetBlock || targetBlock.type !== 'GROUP_BLOCK') {
97
+ return [];
98
+ }
99
+ return collectChildrenBlockIds(targetBlock, 'current');
114
100
  };
115
- // export const findAllChildrenButGroup = (blockStructure: Block[], targetId: string): string[] => {
116
- // const collectChildrenIds = (block: Block): string[] => {
117
- // let ids: string[] = [];
118
- // if ('children' in block && block.children) {
119
- // for (const child of block.children) {
120
- // if (child.type !== 'GROUP_BLOCK') {
121
- // ids.push(child.blockId);
122
- // }
123
- // ids = ids.concat(collectChildrenIds(child));
124
- // }
125
- // }
126
- // return ids;
127
- // };
128
- // const targetBlock = findBlockById(blockStructure, targetId);
129
- // return targetBlock ? collectChildrenIds(targetBlock) : [];
130
- // };
131
101
  export var findGroupBlocks = function (blockStructure, targetId) {
132
102
  var targetBlock = findBlockByBlockId(blockStructure, targetId);
133
103
  var groupBlocks = [];
@@ -159,74 +129,76 @@ export var findGroupBlocks = function (blockStructure, targetId) {
159
129
  }
160
130
  return groupBlocks;
161
131
  };
162
- export var findAllChildrenCbIds = function (blockStructure) {
163
- var collectComponentBlockIds = function (blocks) {
164
- var ids = [];
165
- for (var _i = 0, blocks_3 = blocks; _i < blocks_3.length; _i++) {
166
- var block = blocks_3[_i];
167
- if (block.type === 'COMPONENT_BLOCK') {
168
- ids.push(block.componentBlockId);
169
- }
170
- if ('children' in block && block.children) {
171
- ids = ids.concat(collectComponentBlockIds(block.children));
172
- }
173
- }
174
- return ids;
175
- };
176
- return collectComponentBlockIds(blockStructure);
177
- };
178
- export var findParentGroupByGroupId = function (blockStructure, targetId) {
179
- var findParentGroup = function (blocks, id, parent) {
180
- if (parent === void 0) { parent = null; }
181
- for (var _i = 0, blocks_4 = blocks; _i < blocks_4.length; _i++) {
182
- var block = blocks_4[_i];
183
- if (block.blockId === id && block.type === 'GROUP_BLOCK') {
184
- return parent ? parent.blockId : null;
185
- }
186
- if ('children' in block && block.children) {
187
- var result = findParentGroup(block.children, id, block.type === 'GROUP_BLOCK' ? block : parent);
188
- if (result) {
189
- return result;
190
- }
191
- }
192
- }
193
- return null;
194
- };
195
- return findParentGroup(blockStructure, targetId);
196
- };
197
- export var addBlockToRoot = function (blockStructure, newBlock) {
198
- return blockStructure.map(function (block) {
199
- if (block.blockId === 'ROOT' && block.type === 'GROUP_BLOCK') {
200
- return __assign(__assign({}, block), { children: block.children ? __spreadArray(__spreadArray([], block.children, true), [newBlock], false) : [newBlock] });
201
- }
202
- return block;
203
- });
204
- };
205
- export var addBulkToTarget = function (blockStructure, targetId, bulkIds // componentBlockId
206
- ) {
207
- var structure = deepClone(blockStructure);
208
- var targetBlock = findBlockByBlockId(structure.children, targetId);
132
+ // export const findAllComponentBlockIds = (blockStructure: Block[]): number[] => {
133
+ // const collectComponentBlockIds = (blocks: Block[]): number[] => {
134
+ // let ids: number[] = [];
135
+ // for (const block of blocks) {
136
+ // if (block.type === 'COMPONENT_BLOCK') {
137
+ // ids.push(block.componentBlockId);
138
+ // }
139
+ // if ('children' in block && block.children) {
140
+ // ids = ids.concat(collectComponentBlockIds(block.children));
141
+ // }
142
+ // }
143
+ // return ids;
144
+ // };
145
+ // return collectComponentBlockIds(blockStructure);
146
+ // };
147
+ // export const findParentGroupByGroupId = (blockStructure: Block[], targetId: string): string | null => {
148
+ // const findParentGroup = (
149
+ // blocks: Block[],
150
+ // id: string,
151
+ // parent: GroupBlock | null = null
152
+ // ): string | null => {
153
+ // for (const block of blocks) {
154
+ // if (block.blockId === id && block.type === 'GROUP_BLOCK') {
155
+ // return parent ? parent.blockId : null;
156
+ // }
157
+ // if ('children' in block && block.children) {
158
+ // const result = findParentGroup(block.children, id, block.type === 'GROUP_BLOCK' ? block : parent);
159
+ // if (result) {
160
+ // return result;
161
+ // }
162
+ // }
163
+ // }
164
+ // return null;
165
+ // };
166
+ // return findParentGroup(blockStructure, targetId);
167
+ // };
168
+ // export const addBlockToRoot = (block: RootBlock, newBlock: Block): Block[] => {
169
+ // return block.map(block => {
170
+ // if (block.blockId === 'ROOT' && block.type === 'GROUP_BLOCK') {
171
+ // return {
172
+ // ...block,
173
+ // children: block.children ? [...block.children, newBlock] : [newBlock]
174
+ // };
175
+ // }
176
+ // return block;
177
+ // });
178
+ // };
179
+ export var addBulkToTarget = function (block, targetId, bulkBlockIds) {
180
+ var blockCopy = deepClone(block);
181
+ var targetBlock = findBlockByBlockId(blockCopy, targetId);
209
182
  if (!targetBlock || targetBlock.type !== 'GROUP_BLOCK' || !targetBlock.children) {
210
- return blockStructure;
183
+ return block;
211
184
  }
212
185
  var bulkBlocks = targetBlock.children.filter(function (child) {
213
- if (child.type === 'COMPONENT_BLOCK' && bulkIds.includes(child.blockId.toString())) {
186
+ if (child.type === 'COMPONENT_BLOCK' && bulkBlockIds.includes(child.blockId.toString())) {
214
187
  return true;
215
188
  }
216
- if (child.type === 'GROUP_BLOCK' && bulkIds.includes(child.blockId)) {
189
+ if (child.type === 'GROUP_BLOCK' && bulkBlockIds.includes(child.blockId)) {
217
190
  return true;
218
191
  }
219
192
  return false;
220
193
  });
221
- if (bulkBlocks.length !== bulkIds.length) {
222
- window.alert('Some bulkIds do not exist as children of the target block.');
223
- return blockStructure;
194
+ if (bulkBlocks.length !== bulkBlockIds.length) {
195
+ return block;
224
196
  }
225
197
  if (bulkBlocks.length === 0) {
226
- return blockStructure;
198
+ return block;
227
199
  }
228
200
  // Remove bulk blocks from target's children
229
- targetBlock.children = targetBlock.children.filter(function (child) { return !bulkIds.includes(child.blockId); });
201
+ targetBlock.children = targetBlock.children.filter(function (child) { return !bulkBlockIds.includes(child.blockId); });
230
202
  // Create the new bulkBlock
231
203
  var bulkBlock = {
232
204
  blockId: 'BULK',
@@ -237,241 +209,69 @@ export var addBulkToTarget = function (blockStructure, targetId, bulkIds // comp
237
209
  };
238
210
  // Add the bulkBlock to the target's children
239
211
  targetBlock.children.push(bulkBlock);
240
- return structure;
241
- };
242
- export var getBlockWorkDirPath = function (blockStructure, blockId) {
243
- var findPath = function (blocks, id, path) {
244
- for (var _i = 0, blocks_5 = blocks; _i < blocks_5.length; _i++) {
245
- var block = blocks_5[_i];
246
- var currentPath = __spreadArray(__spreadArray([], path, true), [block.blockId], false);
247
- if (block.blockId === id) {
248
- return currentPath;
249
- }
250
- if ('children' in block && block.children) {
251
- var result = findPath(block.children, id, currentPath);
252
- if (result) {
253
- return result;
254
- }
255
- }
256
- }
257
- return null;
258
- };
259
- var path = findPath(blockStructure, blockId, ['']);
260
- return path ? path.join('/') : null;
212
+ return blockCopy;
261
213
  };
262
- export var getBlockIdByComponentId = function (blockStructure, componentId) {
263
- var findBlock = function (blocks) {
264
- for (var _i = 0, blocks_6 = blocks; _i < blocks_6.length; _i++) {
265
- var block = blocks_6[_i];
266
- if (block.type === 'COMPONENT_BLOCK' && block.componentBlockId === componentId) {
267
- return block.blockId;
268
- }
269
- if ('children' in block && block.children) {
270
- var result = findBlock(block.children);
271
- if (result) {
272
- return result;
273
- }
274
- }
275
- }
214
+ var findPath = function (block, id, path) {
215
+ if (block.type === 'COMPONENT_BLOCK') {
276
216
  return null;
277
- };
278
- return findBlock(blockStructure);
279
- };
280
- export var blockStructure = {
281
- blockId: 'ROOT',
282
- type: 'GROUP_BLOCK',
283
- zOrderDesktopInternal: null,
284
- zOrderMobileInternal: null,
285
- children: [
286
- {
287
- blockId: 'GB_2',
288
- type: 'GROUP_BLOCK',
289
- zOrderDesktopInternal: null,
290
- zOrderMobileInternal: null,
291
- children: [
292
- {
293
- blockId: 'GB_3',
294
- type: 'GROUP_BLOCK',
295
- zOrderDesktopInternal: null,
296
- zOrderMobileInternal: null,
297
- children: [
298
- {
299
- blockId: 'CB_4',
300
- type: 'COMPONENT_BLOCK',
301
- zOrderDesktopInternal: null,
302
- zOrderMobileInternal: null,
303
- componentBlockId: 4
304
- },
305
- {
306
- blockId: 'CB_5',
307
- type: 'COMPONENT_BLOCK',
308
- zOrderDesktopInternal: null,
309
- zOrderMobileInternal: null,
310
- componentBlockId: 5
311
- },
312
- {
313
- blockId: 'GB_6',
314
- type: 'GROUP_BLOCK',
315
- zOrderDesktopInternal: null,
316
- zOrderMobileInternal: null,
317
- children: [
318
- {
319
- blockId: 'CB_7',
320
- type: 'COMPONENT_BLOCK',
321
- zOrderDesktopInternal: null,
322
- zOrderMobileInternal: null,
323
- componentBlockId: 7
324
- },
325
- {
326
- blockId: 'CB_8',
327
- type: 'COMPONENT_BLOCK',
328
- zOrderDesktopInternal: null,
329
- zOrderMobileInternal: null,
330
- componentBlockId: 8
331
- },
332
- {
333
- blockId: 'GB_9',
334
- type: 'GROUP_BLOCK',
335
- zOrderDesktopInternal: null,
336
- zOrderMobileInternal: null,
337
- children: [
338
- {
339
- blockId: 'CB_10',
340
- type: 'COMPONENT_BLOCK',
341
- zOrderDesktopInternal: null,
342
- zOrderMobileInternal: null,
343
- componentBlockId: 10
344
- },
345
- {
346
- blockId: 'CB_11',
347
- type: 'COMPONENT_BLOCK',
348
- zOrderDesktopInternal: null,
349
- zOrderMobileInternal: null,
350
- componentBlockId: 11
351
- }
352
- ]
353
- }
354
- ]
355
- }
356
- ]
357
- },
358
- {
359
- blockId: 'GB_12',
360
- type: 'GROUP_BLOCK',
361
- zOrderDesktopInternal: null,
362
- zOrderMobileInternal: null,
363
- children: [
364
- {
365
- blockId: 'CB_13',
366
- type: 'COMPONENT_BLOCK',
367
- zOrderDesktopInternal: null,
368
- zOrderMobileInternal: null,
369
- componentBlockId: 13
370
- },
371
- {
372
- blockId: 'CB_14',
373
- type: 'COMPONENT_BLOCK',
374
- zOrderDesktopInternal: null,
375
- zOrderMobileInternal: null,
376
- componentBlockId: 14
377
- }
378
- ]
379
- },
380
- {
381
- blockId: 'CB_15',
382
- type: 'COMPONENT_BLOCK',
383
- zOrderDesktopInternal: null,
384
- zOrderMobileInternal: null,
385
- componentBlockId: 15
386
- },
387
- {
388
- blockId: 'CB_16',
389
- type: 'COMPONENT_BLOCK',
390
- zOrderDesktopInternal: null,
391
- zOrderMobileInternal: null,
392
- componentBlockId: 16
393
- }
394
- ]
395
- },
396
- {
397
- blockId: 'GB_17',
398
- type: 'GROUP_BLOCK',
399
- zOrderDesktopInternal: null,
400
- zOrderMobileInternal: null,
401
- children: [
402
- {
403
- blockId: 'CB_18',
404
- type: 'COMPONENT_BLOCK',
405
- zOrderDesktopInternal: null,
406
- zOrderMobileInternal: null,
407
- componentBlockId: 18
408
- }
409
- ]
410
- },
411
- {
412
- blockId: 'CB_19',
413
- type: 'COMPONENT_BLOCK',
414
- zOrderDesktopInternal: null,
415
- zOrderMobileInternal: null,
416
- componentBlockId: 19
417
- },
418
- {
419
- blockId: 'CB_20',
420
- type: 'COMPONENT_BLOCK',
421
- zOrderDesktopInternal: null,
422
- zOrderMobileInternal: null,
423
- componentBlockId: 20
424
- }
425
- ]
426
- };
427
- export var mapComponentBlockIdsToBlockIds = function (blockStructure) {
428
- var cbToBlockMap = {};
429
- var blockToCbMap = {};
430
- var traverse = function (blocks) {
431
- for (var _i = 0, blocks_7 = blocks; _i < blocks_7.length; _i++) {
432
- var block = blocks_7[_i];
433
- if (block.type === 'COMPONENT_BLOCK') {
434
- cbToBlockMap[block.componentBlockId] = block.blockId;
435
- blockToCbMap[block.blockId] = block.componentBlockId;
436
- }
437
- if ('children' in block && block.children) {
438
- traverse(block.children);
439
- }
440
- }
441
- };
442
- traverse(blockStructure);
443
- return { CB_ID: cbToBlockMap, BLOCK_ID: blockToCbMap };
444
- };
445
- export var findAccessibleChildrenBlocks = function (blockStructure, targetGroupId, blockIds) {
446
- var targetBlock = findBlockByBlockId(blockStructure, targetGroupId);
447
- if (!targetBlock || !('children' in targetBlock) || !targetBlock.children) {
448
- return [];
449
217
  }
450
- var result = new Set();
451
- var traverse = function (block, rootId) {
452
- if ('children' in block && block.children) {
453
- for (var _i = 0, _a = block.children; _i < _a.length; _i++) {
454
- var child = _a[_i];
455
- if (blockIds.includes(child.blockId)) {
456
- result.add(rootId);
457
- return true; // Stop traversal for this branch
458
- }
459
- if (traverse(child, rootId)) {
460
- result.add(rootId);
461
- return true; // Stop traversal for this branch
462
- }
463
- }
464
- }
465
- return false;
466
- };
467
- for (var _i = 0, _a = targetBlock.children; _i < _a.length; _i++) {
218
+ for (var _i = 0, _a = block.children; _i < _a.length; _i++) {
468
219
  var child = _a[_i];
469
- if (blockIds.includes(child.blockId)) {
470
- result.add(child.blockId);
220
+ var currentPath = __spreadArray(__spreadArray([], path, true), [child.blockId], false);
221
+ if (child.blockId === id) {
222
+ return currentPath;
471
223
  }
472
- else {
473
- traverse(child, child.blockId);
224
+ if ('children' in block && block.children) {
225
+ var result = findPath(block, id, currentPath);
226
+ if (result) {
227
+ return result;
228
+ }
474
229
  }
475
230
  }
476
- return Array.from(result);
231
+ return null;
232
+ };
233
+ export var getBlockWorkDirPath = function (block, blockId) {
234
+ var path = findPath(block, blockId, ['']);
235
+ return path ? path.join('/') : null;
477
236
  };
237
+ export function formatBlockIdToCbId(cbId) {
238
+ return "CB_".concat(cbId);
239
+ }
240
+ export function formatCbIdToBlockId(cbId) {
241
+ var match = cbId.match(/^CB_(\d+)$/);
242
+ return match ? parseInt(match[1], 10) : null;
243
+ }
244
+ // export const findAccessibleChildrenBlocks = (
245
+ // block: Block,
246
+ // targetGroupId: string,
247
+ // blockIds: string[]
248
+ // ): string[] => {
249
+ // const targetBlock = findBlockByBlockId(block, targetGroupId);
250
+ // if (!targetBlock || !('children' in targetBlock) || !targetBlock.children) {
251
+ // return [];
252
+ // }
253
+ // const result = new Set<string>();
254
+ // const traverse = (block: Block, rootId: string): boolean => {
255
+ // if ('children' in block && block.children) {
256
+ // for (const child of block.children) {
257
+ // if (blockIds.includes(child.blockId)) {
258
+ // result.add(rootId);
259
+ // return true; // Stop traversal for this branch
260
+ // }
261
+ // if (traverse(child, rootId)) {
262
+ // result.add(rootId);
263
+ // return true; // Stop traversal for this branch
264
+ // }
265
+ // }
266
+ // }
267
+ // return false;
268
+ // };
269
+ // for (const child of targetBlock.children) {
270
+ // if (blockIds.includes(child.blockId)) {
271
+ // result.add(child.blockId);
272
+ // } else {
273
+ // traverse(child, child.blockId);
274
+ // }
275
+ // }
276
+ // return Array.from(result);
277
+ // };
@@ -1,7 +1,7 @@
1
1
  import { DragEvent, ReactElement, RefObject } from "react";
2
2
  import { ResizeHandleAxis, ResizeHandleType } from "../Resizable/types";
3
3
  import { ResizeEventType } from "../GridItem/types";
4
- import { RootBlock } from "./group";
4
+ import { Block } from "./group";
5
5
  export type CompactType = "vertical" | "horizontal";
6
6
  export type LayoutItem = {
7
7
  w: number;
@@ -79,7 +79,7 @@ export type ReactGridLayoutProps = {
79
79
  minNbRow?: number;
80
80
  customColWidth?: number;
81
81
  onFitToContent?: OnFitContentCallBack;
82
- blockStructure?: RootBlock;
82
+ blockStructure?: Block;
83
83
  onDoubleClickGroup?: (e: React.MouseEvent, id: string, type: string) => void;
84
84
  selectedGroupBlock?: 'ROOT' | string;
85
85
  editingGroupBlock?: 'ROOT' | string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "publ-echo-test",
3
- "version": "0.0.113",
3
+ "version": "0.0.115",
4
4
  "private": false,
5
5
  "main": "dist/lib/index.js",
6
6
  "types": "dist/lib/index.d.js",