@vuu-ui/vuu-layout 0.5.9 → 0.5.10
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/package.json +10 -13
- package/src/Component.css +0 -0
- package/src/Component.tsx +20 -0
- package/src/DraggableLayout.css +18 -0
- package/src/DraggableLayout.tsx +26 -0
- package/src/__tests__/flexbox-utils.spec.js +90 -0
- package/src/chest-of-drawers/Chest.css +36 -0
- package/src/chest-of-drawers/Chest.tsx +42 -0
- package/src/chest-of-drawers/Drawer.css +159 -0
- package/src/chest-of-drawers/Drawer.tsx +118 -0
- package/src/chest-of-drawers/index.ts +2 -0
- package/src/common-types.ts +9 -0
- package/src/debug.ts +16 -0
- package/src/drag-drop/BoxModel.ts +551 -0
- package/src/drag-drop/DragState.ts +219 -0
- package/src/drag-drop/Draggable.ts +282 -0
- package/src/drag-drop/DropMenu.css +71 -0
- package/src/drag-drop/DropMenu.tsx +61 -0
- package/src/drag-drop/DropTarget.ts +393 -0
- package/src/drag-drop/DropTargetRenderer.css +40 -0
- package/src/drag-drop/DropTargetRenderer.tsx +277 -0
- package/src/drag-drop/dragDropTypes.ts +47 -0
- package/src/drag-drop/index.ts +5 -0
- package/src/editable-label/EditableLabel.css +28 -0
- package/src/editable-label/EditableLabel.tsx +99 -0
- package/src/editable-label/index.ts +1 -0
- package/src/flexbox/Flexbox.css +45 -0
- package/src/flexbox/Flexbox.tsx +70 -0
- package/src/flexbox/FlexboxLayout.tsx +28 -0
- package/src/flexbox/FluidGrid.css +134 -0
- package/src/flexbox/FluidGrid.tsx +82 -0
- package/src/flexbox/FluidGridLayout.tsx +9 -0
- package/src/flexbox/Splitter.css +140 -0
- package/src/flexbox/Splitter.tsx +127 -0
- package/src/flexbox/flexbox-utils.ts +128 -0
- package/src/flexbox/flexboxTypes.ts +68 -0
- package/src/flexbox/index.ts +5 -0
- package/src/flexbox/useResponsiveSizing.ts +82 -0
- package/src/flexbox/useSplitterResizing.ts +270 -0
- package/src/index.ts +19 -0
- package/src/layout-action.ts +21 -0
- package/src/layout-header/ActionButton.tsx +23 -0
- package/src/layout-header/Header.css +8 -0
- package/src/layout-header/Header.tsx +216 -0
- package/src/layout-header/index.ts +1 -0
- package/src/layout-provider/LayoutProvider.tsx +161 -0
- package/src/layout-provider/LayoutProviderContext.ts +17 -0
- package/src/layout-provider/index.ts +3 -0
- package/src/layout-provider/useLayoutDragDrop.ts +210 -0
- package/src/layout-reducer/flexUtils.ts +276 -0
- package/src/layout-reducer/index.ts +5 -0
- package/src/layout-reducer/insert-layout-element.ts +365 -0
- package/src/layout-reducer/layout-reducer.ts +237 -0
- package/src/layout-reducer/layoutTypes.ts +159 -0
- package/src/layout-reducer/layoutUtils.ts +288 -0
- package/src/layout-reducer/remove-layout-element.ts +226 -0
- package/src/layout-reducer/replace-layout-element.ts +113 -0
- package/src/layout-reducer/resize-flex-children.ts +55 -0
- package/src/layout-reducer/wrap-layout-element.ts +307 -0
- package/src/layout-view/View.css +61 -0
- package/src/layout-view/View.tsx +143 -0
- package/src/layout-view/ViewContext.ts +30 -0
- package/src/layout-view/index.ts +5 -0
- package/src/layout-view/useView.tsx +104 -0
- package/src/layout-view/useViewActionDispatcher.ts +123 -0
- package/src/layout-view/useViewResize.ts +53 -0
- package/src/layout-view/viewTypes.ts +35 -0
- package/src/palette/Palette.css +33 -0
- package/src/palette/Palette.tsx +140 -0
- package/src/palette/PaletteSalt.css +9 -0
- package/src/palette/PaletteSalt.tsx +79 -0
- package/src/palette/index.ts +3 -0
- package/src/placeholder/Placeholder.css +10 -0
- package/src/placeholder/Placeholder.tsx +38 -0
- package/src/placeholder/index.ts +1 -0
- package/src/registry/ComponentRegistry.ts +44 -0
- package/src/registry/index.ts +1 -0
- package/src/responsive/breakpoints.ts +62 -0
- package/src/responsive/index.ts +3 -0
- package/src/responsive/measureMinimumNodeSize.ts +23 -0
- package/src/responsive/overflowUtils.js +14 -0
- package/src/responsive/use-breakpoints.ts +101 -0
- package/src/responsive/useResizeObserver.ts +154 -0
- package/src/responsive/utils.ts +37 -0
- package/src/stack/Stack.css +39 -0
- package/src/stack/Stack.tsx +173 -0
- package/src/stack/StackLayout.tsx +119 -0
- package/src/stack/index.ts +4 -0
- package/src/stack/stackTypes.ts +22 -0
- package/src/tabs/TabPanel.css +12 -0
- package/src/tabs/TabPanel.tsx +17 -0
- package/src/tabs/index.ts +1 -0
- package/src/tools/config-wrapper/ConfigWrapper.tsx +55 -0
- package/src/tools/config-wrapper/index.ts +1 -0
- package/src/tools/devtools-box/layout-configurator.css +112 -0
- package/src/tools/devtools-box/layout-configurator.jsx +369 -0
- package/src/tools/devtools-tree/layout-tree-viewer.css +15 -0
- package/src/tools/devtools-tree/layout-tree-viewer.jsx +36 -0
- package/src/tools/index.ts +4 -0
- package/src/use-persistent-state.ts +112 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/pathUtils.ts +283 -0
- package/src/utils/propUtils.ts +26 -0
- package/src/utils/refUtils.ts +16 -0
- package/src/utils/styleUtils.ts +13 -0
- package/src/utils/typeOf.ts +25 -0
- package/tsconfig-emit-types.json +11 -0
- package/LICENSE +0 -201
- package/cjs/index.js +0 -20
- package/cjs/index.js.map +0 -7
- package/esm/index.js +0 -20
- package/esm/index.js.map +0 -7
- package/index.css +0 -2
- package/index.css.map +0 -7
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import "./layout-configurator.css";
|
|
2
|
+
import { FormField, Input } from "@heswell/salt-lab";
|
|
3
|
+
|
|
4
|
+
const NO_STYLE = {};
|
|
5
|
+
|
|
6
|
+
const DIMENSIONS = {
|
|
7
|
+
margin: {
|
|
8
|
+
top: "marginTop",
|
|
9
|
+
right: "marginRight",
|
|
10
|
+
bottom: "marginBottom",
|
|
11
|
+
left: "marginLeft",
|
|
12
|
+
},
|
|
13
|
+
border: {
|
|
14
|
+
top: "borderTopWidth",
|
|
15
|
+
right: "borderRightWidth",
|
|
16
|
+
bottom: "borderBottomWidth",
|
|
17
|
+
left: "borderLeftWidth",
|
|
18
|
+
},
|
|
19
|
+
padding: {
|
|
20
|
+
top: "paddingTop",
|
|
21
|
+
right: "paddingRight",
|
|
22
|
+
bottom: "paddingBottom",
|
|
23
|
+
left: "paddingLeft",
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const LayoutBox = ({ feature, children, style, onChange }) => {
|
|
28
|
+
return (
|
|
29
|
+
<div className={`LayoutBox layout-${feature} layout-outer`}>
|
|
30
|
+
<div className={`layout-top`}>
|
|
31
|
+
<span className="layout-title">{feature}</span>
|
|
32
|
+
<FormField className="layout-input" style={{ width: 30 }}>
|
|
33
|
+
<Input
|
|
34
|
+
value={style.top}
|
|
35
|
+
onChange={(evt, value) => onChange(feature, "top", value)}
|
|
36
|
+
/>
|
|
37
|
+
</FormField>
|
|
38
|
+
</div>
|
|
39
|
+
<div className={`layout-inner`}>
|
|
40
|
+
<div className={`layout-left`}>
|
|
41
|
+
<FormField className="layout-input" style={{ width: 30 }}>
|
|
42
|
+
<Input
|
|
43
|
+
value={style.left}
|
|
44
|
+
onChange={(evt, value) => onChange(feature, "left", value)}
|
|
45
|
+
/>
|
|
46
|
+
</FormField>
|
|
47
|
+
</div>
|
|
48
|
+
{children}
|
|
49
|
+
<div className={`layout-right`}>
|
|
50
|
+
<FormField className="layout-input" style={{ width: 30 }}>
|
|
51
|
+
<Input
|
|
52
|
+
value={style.right}
|
|
53
|
+
onChange={(evt, value) => onChange(feature, "right", value)}
|
|
54
|
+
/>
|
|
55
|
+
</FormField>
|
|
56
|
+
</div>
|
|
57
|
+
</div>
|
|
58
|
+
<div className={`layout-bottom`}>
|
|
59
|
+
<FormField className="layout-input" style={{ width: 30 }}>
|
|
60
|
+
<Input
|
|
61
|
+
value={style.bottom}
|
|
62
|
+
onChange={(evt, value) => onChange(feature, "bottom", value)}
|
|
63
|
+
/>
|
|
64
|
+
</FormField>
|
|
65
|
+
</div>
|
|
66
|
+
</div>
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const MARGIN_STYLES = {
|
|
71
|
+
margin: true,
|
|
72
|
+
marginTop: true,
|
|
73
|
+
marginRight: true,
|
|
74
|
+
marginBottom: true,
|
|
75
|
+
marginLeft: true,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export const PADDING_STYLES = {
|
|
79
|
+
padding: true,
|
|
80
|
+
paddingTop: true,
|
|
81
|
+
paddingRight: true,
|
|
82
|
+
paddingBottom: true,
|
|
83
|
+
paddingLeft: true,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const BORDER_STYLES = {
|
|
87
|
+
border: true,
|
|
88
|
+
borderColor: true,
|
|
89
|
+
borderWidth: true,
|
|
90
|
+
borderTopWidth: true,
|
|
91
|
+
borderRightWidth: true,
|
|
92
|
+
borderBottomWidth: true,
|
|
93
|
+
borderLeftWidth: true,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const CSS_DIGIT = "(\\d+)(?:px)?";
|
|
97
|
+
const CSS_MEASURE = `^(?:${CSS_DIGIT}(?:\\s${CSS_DIGIT}(?:\\s${CSS_DIGIT}(?:\\s${CSS_DIGIT})?)?)?)$`;
|
|
98
|
+
const CSS_REX = new RegExp(CSS_MEASURE);
|
|
99
|
+
const BORDER_REX = /^(?:(\d+)(?:px)\ssolid\s([a-zA-Z,0-9().]+))$/;
|
|
100
|
+
|
|
101
|
+
export const LayoutConfigurator = ({
|
|
102
|
+
height,
|
|
103
|
+
managedStyle,
|
|
104
|
+
onChange,
|
|
105
|
+
style,
|
|
106
|
+
width,
|
|
107
|
+
}) => {
|
|
108
|
+
const state = normalizeStyle(managedStyle);
|
|
109
|
+
|
|
110
|
+
const handleChange = (feature, dimension, strValue) => {
|
|
111
|
+
const value = parseInt(strValue || "0", 10);
|
|
112
|
+
const property = DIMENSIONS[feature][dimension];
|
|
113
|
+
onChange(property, value);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const {
|
|
117
|
+
marginTop: mt = 0,
|
|
118
|
+
marginRight: mr = 0,
|
|
119
|
+
marginBottom: mb = 0,
|
|
120
|
+
marginLeft: ml = 0,
|
|
121
|
+
} = state;
|
|
122
|
+
const {
|
|
123
|
+
borderTopWidth: bt = 0,
|
|
124
|
+
borderRightWidth: br = 0,
|
|
125
|
+
borderBottomWidth: bb = 0,
|
|
126
|
+
borderLeftWidth: bl = 0,
|
|
127
|
+
} = state;
|
|
128
|
+
const {
|
|
129
|
+
paddingTop: pt = 0,
|
|
130
|
+
paddingRight: pr = 0,
|
|
131
|
+
paddingBottom: pb = 0,
|
|
132
|
+
paddingLeft: pl = 0,
|
|
133
|
+
} = state;
|
|
134
|
+
return (
|
|
135
|
+
<div className="LayoutConfigurator" style={{ width, height, ...style }}>
|
|
136
|
+
<LayoutBox
|
|
137
|
+
feature="margin"
|
|
138
|
+
style={{ top: mt, right: mr, bottom: mb, left: ml }}
|
|
139
|
+
onChange={handleChange}
|
|
140
|
+
>
|
|
141
|
+
<LayoutBox
|
|
142
|
+
feature="border"
|
|
143
|
+
style={{ top: bt, right: br, bottom: bb, left: bl }}
|
|
144
|
+
onChange={handleChange}
|
|
145
|
+
>
|
|
146
|
+
<LayoutBox
|
|
147
|
+
feature="padding"
|
|
148
|
+
style={{ top: pt, right: pr, bottom: pb, left: pl }}
|
|
149
|
+
onChange={handleChange}
|
|
150
|
+
>
|
|
151
|
+
<div className="layout-content" />
|
|
152
|
+
</LayoutBox>
|
|
153
|
+
</LayoutBox>
|
|
154
|
+
</LayoutBox>
|
|
155
|
+
</div>
|
|
156
|
+
);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// TODO merge the following two functions
|
|
160
|
+
export function XXXnormalizeStyles(
|
|
161
|
+
layoutStyle = NO_STYLE,
|
|
162
|
+
visualStyle = NO_STYLE
|
|
163
|
+
) {
|
|
164
|
+
const {
|
|
165
|
+
margin,
|
|
166
|
+
marginTop,
|
|
167
|
+
marginRight,
|
|
168
|
+
marginBottom,
|
|
169
|
+
marginLeft,
|
|
170
|
+
padding,
|
|
171
|
+
paddingTop,
|
|
172
|
+
paddingRight,
|
|
173
|
+
paddingBottom,
|
|
174
|
+
paddingLeft,
|
|
175
|
+
...style
|
|
176
|
+
} = layoutStyle;
|
|
177
|
+
|
|
178
|
+
if (typeof margin === "number") {
|
|
179
|
+
style.marginTop =
|
|
180
|
+
style.marginRight =
|
|
181
|
+
style.marginBottom =
|
|
182
|
+
style.marginLeft =
|
|
183
|
+
margin;
|
|
184
|
+
} else if (typeof margin === "string") {
|
|
185
|
+
const match = CSS_REX.exec(margin);
|
|
186
|
+
if (match === null) {
|
|
187
|
+
console.error(`Invalid css value for margin '${margin}'`);
|
|
188
|
+
} else {
|
|
189
|
+
const [, pos1, pos2, pos3, pos4] = match;
|
|
190
|
+
const pos123 = pos1 && pos2 && pos3;
|
|
191
|
+
if (pos123 && pos4) {
|
|
192
|
+
style.marginTop = parseInt(pos1, 10);
|
|
193
|
+
style.marginRight = parseInt(pos2, 10);
|
|
194
|
+
style.marginBottom = parseInt(pos3, 10);
|
|
195
|
+
style.marginLeft = parseInt(pos4, 10);
|
|
196
|
+
} else if (pos123) {
|
|
197
|
+
style.marginTop = parseInt(pos1, 10);
|
|
198
|
+
style.marginRight = style.marginLeft = parseInt(pos2, 10);
|
|
199
|
+
style.marginBottom = parseInt(pos3, 10);
|
|
200
|
+
} else if (pos1 && pos2) {
|
|
201
|
+
style.marginTop = style.marginBottom = parseInt(pos1, 10);
|
|
202
|
+
style.marginRight = style.marginLeft = parseInt(pos2, 10);
|
|
203
|
+
} else {
|
|
204
|
+
style.marginTop =
|
|
205
|
+
style.marginRight =
|
|
206
|
+
style.marginBottom =
|
|
207
|
+
style.marginLeft =
|
|
208
|
+
parseInt(pos1, 10);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (typeof marginTop === "number") style.marginTop = marginTop;
|
|
213
|
+
if (typeof marginRight === "number") style.marginRight = marginRight;
|
|
214
|
+
if (typeof marginBottom === "number") style.marginBottom = marginBottom;
|
|
215
|
+
if (typeof marginLeft === "number") style.marginLeft = marginLeft;
|
|
216
|
+
|
|
217
|
+
if (typeof padding === "number") {
|
|
218
|
+
style.paddingTop =
|
|
219
|
+
style.paddingRight =
|
|
220
|
+
style.paddingBottom =
|
|
221
|
+
style.paddingLeft =
|
|
222
|
+
padding;
|
|
223
|
+
} else if (typeof padding === "string") {
|
|
224
|
+
const match = CSS_REX.exec(padding);
|
|
225
|
+
if (match === null) {
|
|
226
|
+
console.error(`Invalid css value for padding '${padding}'`);
|
|
227
|
+
} else {
|
|
228
|
+
const [, pos1, pos2, pos3, pos4] = match;
|
|
229
|
+
const pos123 = pos1 && pos2 && pos3;
|
|
230
|
+
if (pos123 && pos4) {
|
|
231
|
+
style.paddingTop = parseInt(pos1, 10);
|
|
232
|
+
style.paddingRight = parseInt(pos2, 10);
|
|
233
|
+
style.paddingBottom = parseInt(pos3, 10);
|
|
234
|
+
style.paddingLeft = parseInt(pos4, 10);
|
|
235
|
+
} else if (pos123) {
|
|
236
|
+
style.paddingTop = parseInt(pos1, 10);
|
|
237
|
+
style.paddingRight = style.paddingLeft = parseInt(pos2, 10);
|
|
238
|
+
style.paddingBottom = parseInt(pos3, 10);
|
|
239
|
+
} else if (pos1 && pos2) {
|
|
240
|
+
style.paddingTop = style.paddingBottom = parseInt(pos1, 10);
|
|
241
|
+
style.paddingRight = style.paddingLeft = parseInt(pos2, 10);
|
|
242
|
+
} else {
|
|
243
|
+
style.paddingTop =
|
|
244
|
+
style.paddingRight =
|
|
245
|
+
style.paddingBottom =
|
|
246
|
+
style.paddinggLeft =
|
|
247
|
+
parseInt(pos1, 10);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (typeof paddingTop === "number") style.paddingTop = paddingTop;
|
|
252
|
+
if (typeof paddingRight === "number") style.paddingRight = paddingRight;
|
|
253
|
+
if (typeof paddingBottom === "number") style.paddingBottom = paddingBottom;
|
|
254
|
+
if (typeof paddingLeft === "number") style.paddingLeft = paddingLeft;
|
|
255
|
+
|
|
256
|
+
return normalizeStyle(style, visualStyle);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function normalizeStyle(managedStyle = NO_STYLE) {
|
|
260
|
+
const style = { ...managedStyle };
|
|
261
|
+
|
|
262
|
+
// if (BORDER_LIST.some(bs => style[bs])) {
|
|
263
|
+
let match;
|
|
264
|
+
|
|
265
|
+
let {
|
|
266
|
+
border,
|
|
267
|
+
borderWidth,
|
|
268
|
+
borderTopWidth,
|
|
269
|
+
borderRightWidth,
|
|
270
|
+
borderBottomWidth,
|
|
271
|
+
borderLeftWidth,
|
|
272
|
+
borderColor,
|
|
273
|
+
margin,
|
|
274
|
+
marginTop,
|
|
275
|
+
marginRight,
|
|
276
|
+
marginBottom,
|
|
277
|
+
marginLeft,
|
|
278
|
+
padding,
|
|
279
|
+
paddingTop,
|
|
280
|
+
paddingRight,
|
|
281
|
+
paddingBottom,
|
|
282
|
+
paddingLeft,
|
|
283
|
+
...rest
|
|
284
|
+
} = style;
|
|
285
|
+
|
|
286
|
+
let marginStyles = {};
|
|
287
|
+
let paddingStyles = {};
|
|
288
|
+
|
|
289
|
+
if (typeof margin === "number") {
|
|
290
|
+
style.marginTop =
|
|
291
|
+
style.marginRight =
|
|
292
|
+
style.marginBottom =
|
|
293
|
+
style.marginLeft =
|
|
294
|
+
margin;
|
|
295
|
+
marginStyles = {
|
|
296
|
+
marginTop: margin,
|
|
297
|
+
marginRight: margin,
|
|
298
|
+
marginBottom: margin,
|
|
299
|
+
marginLeft: margin,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (typeof padding === "number") {
|
|
304
|
+
style.paddingTop =
|
|
305
|
+
style.paddingRight =
|
|
306
|
+
style.paddingBottom =
|
|
307
|
+
style.paddingLeft =
|
|
308
|
+
padding;
|
|
309
|
+
paddingStyles = {
|
|
310
|
+
paddingTop: padding,
|
|
311
|
+
paddingRight: padding,
|
|
312
|
+
paddingBottom: padding,
|
|
313
|
+
paddingLeft: padding,
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (
|
|
318
|
+
border ||
|
|
319
|
+
borderWidth ||
|
|
320
|
+
borderTopWidth ||
|
|
321
|
+
borderRightWidth ||
|
|
322
|
+
borderBottomWidth ||
|
|
323
|
+
borderLeftWidth
|
|
324
|
+
) {
|
|
325
|
+
if (typeof border === "string" && (match = BORDER_REX.exec(border))) {
|
|
326
|
+
// what if both border and borderWidth are specified ?
|
|
327
|
+
[, borderWidth, borderColor] = match;
|
|
328
|
+
borderWidth = parseInt(borderWidth, 10);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (borderWidth) {
|
|
332
|
+
borderTopWidth =
|
|
333
|
+
borderTopWidth === undefined ? borderWidth : borderTopWidth;
|
|
334
|
+
borderRightWidth =
|
|
335
|
+
borderRightWidth === undefined ? borderWidth : borderRightWidth;
|
|
336
|
+
borderBottomWidth =
|
|
337
|
+
borderBottomWidth === undefined ? borderWidth : borderBottomWidth;
|
|
338
|
+
borderLeftWidth =
|
|
339
|
+
borderLeftWidth === undefined ? borderWidth : borderLeftWidth;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
borderColor = borderColor || "black";
|
|
343
|
+
const boxShadow = `
|
|
344
|
+
${borderColor} ${borderLeftWidth || 0}px ${
|
|
345
|
+
borderTopWidth || 0
|
|
346
|
+
}px 0 0 inset,
|
|
347
|
+
${borderColor} ${-borderRightWidth || 0}px ${
|
|
348
|
+
-borderBottomWidth || 0
|
|
349
|
+
}px 0 0 inset`;
|
|
350
|
+
|
|
351
|
+
return {
|
|
352
|
+
...rest,
|
|
353
|
+
...marginStyles,
|
|
354
|
+
...paddingStyles,
|
|
355
|
+
borderTopWidth,
|
|
356
|
+
borderRightWidth,
|
|
357
|
+
borderBottomWidth,
|
|
358
|
+
borderLeftWidth,
|
|
359
|
+
borderColor,
|
|
360
|
+
borderStyle: "solid",
|
|
361
|
+
boxShadow,
|
|
362
|
+
};
|
|
363
|
+
} else {
|
|
364
|
+
return style;
|
|
365
|
+
}
|
|
366
|
+
// } else {
|
|
367
|
+
// return style;
|
|
368
|
+
// }
|
|
369
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
.hwLayoutTreeViewer {
|
|
2
|
+
}
|
|
3
|
+
|
|
4
|
+
.hwLayoutTreeNode {
|
|
5
|
+
cursor: default;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.hwLayoutTreeNode:hover {
|
|
9
|
+
background-color: rgba(255, 255, 255, 0.2);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.hwLayoutTreeNode[aria-selected='true'] {
|
|
13
|
+
background-color: cornflowerblue;
|
|
14
|
+
color: white;
|
|
15
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import cx from "classnames";
|
|
3
|
+
import { typeOf } from "../../utils";
|
|
4
|
+
|
|
5
|
+
import "./layout-tree-viewer.css";
|
|
6
|
+
import { Tree } from "@heswell/salt-lab";
|
|
7
|
+
|
|
8
|
+
const classBaseTree = "hwLayoutTreeViewer";
|
|
9
|
+
|
|
10
|
+
const toTreeJson = (component, path = "0") => {
|
|
11
|
+
return {
|
|
12
|
+
label: typeOf(component),
|
|
13
|
+
path,
|
|
14
|
+
childNodes: React.Children.map(component.props.children, (child, i) =>
|
|
15
|
+
toTreeJson(child, path ? `${path}.${i}` : `${i}`)
|
|
16
|
+
),
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const LayoutTreeViewer = ({ layout, onSelect, style }) => {
|
|
21
|
+
const treeJson = [toTreeJson(layout)];
|
|
22
|
+
|
|
23
|
+
const handleSelection = (evt, [{ path }]) => {
|
|
24
|
+
onSelect(path);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<div className={cx(classBaseTree)} style={style}>
|
|
29
|
+
<Tree
|
|
30
|
+
source={treeJson}
|
|
31
|
+
groupSelection="single"
|
|
32
|
+
onSelectionChange={handleSelection}
|
|
33
|
+
/>
|
|
34
|
+
</div>
|
|
35
|
+
);
|
|
36
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
|
|
4
|
+
const persistentState = new Map<string, any>();
|
|
5
|
+
const sessionState = new Map<string, any>();
|
|
6
|
+
|
|
7
|
+
export const getPersistentState = (id: string) => persistentState.get(id);
|
|
8
|
+
export const hasPersistentState = (id: string) => persistentState.has(id);
|
|
9
|
+
export const setPersistentState = (id: string, value: any) =>
|
|
10
|
+
persistentState.set(id, value);
|
|
11
|
+
|
|
12
|
+
export const usePersistentState = () => {
|
|
13
|
+
|
|
14
|
+
const loadSessionState = useCallback((id, key) => {
|
|
15
|
+
const state = sessionState.get(id);
|
|
16
|
+
if (state) {
|
|
17
|
+
if (key !== undefined && state[key] !== undefined) {
|
|
18
|
+
return state[key];
|
|
19
|
+
}
|
|
20
|
+
if (key !== undefined) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return state;
|
|
24
|
+
}
|
|
25
|
+
}, []);
|
|
26
|
+
|
|
27
|
+
const saveSessionState = useCallback((id, key, data) => {
|
|
28
|
+
if (key === undefined) {
|
|
29
|
+
sessionState.set(id, data);
|
|
30
|
+
} else if (sessionState.has(id)) {
|
|
31
|
+
const state = sessionState.get(id);
|
|
32
|
+
sessionState.set(id, {
|
|
33
|
+
...state,
|
|
34
|
+
[key]: data,
|
|
35
|
+
});
|
|
36
|
+
} else {
|
|
37
|
+
sessionState.set(id, { [key]: data });
|
|
38
|
+
}
|
|
39
|
+
}, []);
|
|
40
|
+
|
|
41
|
+
const purgeSessionState = useCallback((id: string, key?: string) => {
|
|
42
|
+
if (sessionState.has(id)) {
|
|
43
|
+
if (key === undefined) {
|
|
44
|
+
sessionState.delete(id);
|
|
45
|
+
} else {
|
|
46
|
+
const state = sessionState.get(id);
|
|
47
|
+
if (state[key]) {
|
|
48
|
+
const { [key]: _doomedState, ...rest } = sessionState.get(id);
|
|
49
|
+
if (Object.keys(rest).length > 0) {
|
|
50
|
+
sessionState.set(id, rest);
|
|
51
|
+
} else {
|
|
52
|
+
sessionState.delete(id);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}, []);
|
|
58
|
+
|
|
59
|
+
const loadState = useCallback((id: string, key?: string) => {
|
|
60
|
+
const state = persistentState.get(id);
|
|
61
|
+
if (state) {
|
|
62
|
+
if (key !== undefined) {
|
|
63
|
+
return state[key];
|
|
64
|
+
}
|
|
65
|
+
return state;
|
|
66
|
+
}
|
|
67
|
+
}, []);
|
|
68
|
+
|
|
69
|
+
const saveState = useCallback(
|
|
70
|
+
(id: string, key: string | undefined, data: any) => {
|
|
71
|
+
if (key === undefined) {
|
|
72
|
+
persistentState.set(id, data);
|
|
73
|
+
} else if (persistentState.has(id)) {
|
|
74
|
+
const state = persistentState.get(id);
|
|
75
|
+
persistentState.set(id, {
|
|
76
|
+
...state,
|
|
77
|
+
[key]: data,
|
|
78
|
+
});
|
|
79
|
+
} else {
|
|
80
|
+
persistentState.set(id, { [key]: data });
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
[]
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const purgeState = useCallback((id: string, key?: string) => {
|
|
87
|
+
if (persistentState.has(id)) {
|
|
88
|
+
if (key === undefined) {
|
|
89
|
+
persistentState.delete(id);
|
|
90
|
+
} else {
|
|
91
|
+
const state = persistentState.get(id);
|
|
92
|
+
if (state[key]) {
|
|
93
|
+
const { [key]: _doomedState, ...rest } = persistentState.get(id);
|
|
94
|
+
if (Object.keys(rest).length > 0) {
|
|
95
|
+
persistentState.set(id, rest);
|
|
96
|
+
} else {
|
|
97
|
+
persistentState.delete(id);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}, []);
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
loadSessionState,
|
|
106
|
+
loadState,
|
|
107
|
+
saveSessionState,
|
|
108
|
+
saveState,
|
|
109
|
+
purgeState,
|
|
110
|
+
purgeSessionState,
|
|
111
|
+
};
|
|
112
|
+
};
|