@vuu-ui/vuu-layout 0.0.27

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 (117) hide show
  1. package/README.md +1 -0
  2. package/package.json +30 -0
  3. package/src/Component.css +2 -0
  4. package/src/Component.tsx +20 -0
  5. package/src/DraggableLayout.css +18 -0
  6. package/src/DraggableLayout.tsx +29 -0
  7. package/src/__tests__/flexbox-utils.spec.js +90 -0
  8. package/src/action-buttons/action-buttons.css +12 -0
  9. package/src/action-buttons/action-buttons.tsx +30 -0
  10. package/src/action-buttons/index.ts +1 -0
  11. package/src/chest-of-drawers/Chest.css +36 -0
  12. package/src/chest-of-drawers/Chest.tsx +42 -0
  13. package/src/chest-of-drawers/Drawer.css +153 -0
  14. package/src/chest-of-drawers/Drawer.tsx +118 -0
  15. package/src/chest-of-drawers/index.ts +2 -0
  16. package/src/common-types.ts +9 -0
  17. package/src/debug.ts +16 -0
  18. package/src/dialog/Dialog.css +16 -0
  19. package/src/dialog/Dialog.tsx +59 -0
  20. package/src/dialog/index.ts +1 -0
  21. package/src/drag-drop/BoxModel.ts +546 -0
  22. package/src/drag-drop/DragState.ts +222 -0
  23. package/src/drag-drop/Draggable.ts +282 -0
  24. package/src/drag-drop/DropMenu.css +70 -0
  25. package/src/drag-drop/DropMenu.tsx +68 -0
  26. package/src/drag-drop/DropTarget.ts +392 -0
  27. package/src/drag-drop/DropTargetRenderer.css +40 -0
  28. package/src/drag-drop/DropTargetRenderer.tsx +284 -0
  29. package/src/drag-drop/dragDropTypes.ts +49 -0
  30. package/src/drag-drop/index.ts +4 -0
  31. package/src/editable-label/EditableLabel.css +28 -0
  32. package/src/editable-label/EditableLabel.tsx +99 -0
  33. package/src/editable-label/index.ts +1 -0
  34. package/src/flexbox/Flexbox.css +45 -0
  35. package/src/flexbox/Flexbox.tsx +70 -0
  36. package/src/flexbox/FlexboxLayout.jsx +26 -0
  37. package/src/flexbox/FluidGrid.css +134 -0
  38. package/src/flexbox/FluidGrid.tsx +84 -0
  39. package/src/flexbox/FluidGridLayout.tsx +10 -0
  40. package/src/flexbox/Splitter.css +140 -0
  41. package/src/flexbox/Splitter.tsx +135 -0
  42. package/src/flexbox/flexbox-utils.ts +128 -0
  43. package/src/flexbox/flexboxTypes.ts +63 -0
  44. package/src/flexbox/index.ts +4 -0
  45. package/src/flexbox/useResponsiveSizing.ts +85 -0
  46. package/src/flexbox/useSplitterResizing.ts +272 -0
  47. package/src/index.ts +20 -0
  48. package/src/layout-action.ts +21 -0
  49. package/src/layout-header/ActionButton.tsx +23 -0
  50. package/src/layout-header/Header.css +8 -0
  51. package/src/layout-header/Header.tsx +222 -0
  52. package/src/layout-header/index.ts +1 -0
  53. package/src/layout-provider/LayoutProvider.tsx +160 -0
  54. package/src/layout-provider/LayoutProviderContext.ts +17 -0
  55. package/src/layout-provider/index.ts +2 -0
  56. package/src/layout-provider/useLayoutDragDrop.ts +241 -0
  57. package/src/layout-reducer/flexUtils.ts +281 -0
  58. package/src/layout-reducer/index.ts +4 -0
  59. package/src/layout-reducer/insert-layout-element.ts +365 -0
  60. package/src/layout-reducer/layout-reducer.ts +255 -0
  61. package/src/layout-reducer/layoutTypes.ts +151 -0
  62. package/src/layout-reducer/layoutUtils.ts +302 -0
  63. package/src/layout-reducer/remove-layout-element.ts +240 -0
  64. package/src/layout-reducer/replace-layout-element.ts +118 -0
  65. package/src/layout-reducer/resize-flex-children.ts +56 -0
  66. package/src/layout-reducer/wrap-layout-element.ts +317 -0
  67. package/src/layout-view/View.css +58 -0
  68. package/src/layout-view/View.tsx +149 -0
  69. package/src/layout-view/ViewContext.ts +31 -0
  70. package/src/layout-view/index.ts +4 -0
  71. package/src/layout-view/useView.tsx +104 -0
  72. package/src/layout-view/useViewActionDispatcher.ts +133 -0
  73. package/src/layout-view/useViewResize.ts +53 -0
  74. package/src/layout-view/viewTypes.ts +37 -0
  75. package/src/palette/Palette.css +37 -0
  76. package/src/palette/Palette.tsx +140 -0
  77. package/src/palette/PaletteUitk.css +9 -0
  78. package/src/palette/PaletteUitk.tsx +79 -0
  79. package/src/palette/index.ts +2 -0
  80. package/src/placeholder/Placeholder.css +10 -0
  81. package/src/placeholder/Placeholder.tsx +39 -0
  82. package/src/placeholder/index.ts +1 -0
  83. package/src/registry/ComponentRegistry.ts +35 -0
  84. package/src/registry/index.ts +1 -0
  85. package/src/responsive/OverflowMenu.css +31 -0
  86. package/src/responsive/OverflowMenu.jsx +56 -0
  87. package/src/responsive/breakpoints.ts +48 -0
  88. package/src/responsive/index.ts +4 -0
  89. package/src/responsive/measureMinimumNodeSize.ts +23 -0
  90. package/src/responsive/overflowUtils.js +14 -0
  91. package/src/responsive/use-breakpoints.ts +100 -0
  92. package/src/responsive/useOverflowObserver.ts +606 -0
  93. package/src/responsive/useResizeObserver.ts +154 -0
  94. package/src/responsive/utils.ts +37 -0
  95. package/src/stack/Stack.css +39 -0
  96. package/src/stack/Stack.tsx +160 -0
  97. package/src/stack/StackLayout.tsx +137 -0
  98. package/src/stack/index.ts +3 -0
  99. package/src/stack/stackTypes.ts +19 -0
  100. package/src/tabs/TabPanel.css +12 -0
  101. package/src/tabs/TabPanel.tsx +17 -0
  102. package/src/tabs/index.ts +1 -0
  103. package/src/tools/config-wrapper/ConfigWrapper.jsx +53 -0
  104. package/src/tools/config-wrapper/index.js +1 -0
  105. package/src/tools/devtools-box/layout-configurator.css +112 -0
  106. package/src/tools/devtools-box/layout-configurator.jsx +369 -0
  107. package/src/tools/devtools-tree/layout-tree-viewer.css +15 -0
  108. package/src/tools/devtools-tree/layout-tree-viewer.jsx +36 -0
  109. package/src/tools/index.js +3 -0
  110. package/src/use-persistent-state.ts +115 -0
  111. package/src/utils/componentFromLayout.tsx +30 -0
  112. package/src/utils/index.ts +6 -0
  113. package/src/utils/pathUtils.ts +294 -0
  114. package/src/utils/propUtils.ts +24 -0
  115. package/src/utils/refUtils.ts +16 -0
  116. package/src/utils/styleUtils.ts +14 -0
  117. package/src/utils/typeOf.ts +22 -0
@@ -0,0 +1,112 @@
1
+ [data-design-mode='true'] .Component {
2
+ filter: grayscale(100%);
3
+ opacity: 0.4;
4
+ }
5
+
6
+ [data-design-mode='true'] .Component:after {
7
+ color: black;
8
+ content: 'Component';
9
+ height: 12px;
10
+ background-color: yellow;
11
+ }
12
+
13
+ .LayoutConfigurator {
14
+ --margin-color: #f3cea5;
15
+ --border-color: #fddda0;
16
+ --padding-color: #c6d092;
17
+ --content-color: #8cb6c0;
18
+ display: flex;
19
+ flex-direction: column;
20
+ align-items: stretch;
21
+ background-color: var(--margin-color);
22
+ }
23
+
24
+ .LayoutConfigurator .layout-outer {
25
+ flex: 1 1 auto;
26
+ display: flex;
27
+ flex-direction: column;
28
+ align-items: stretch;
29
+ }
30
+
31
+ .LayoutBox {
32
+ --hw-control-font-size: 13px;
33
+ --hw-text-input-bg: rgba(255, 255, 255, 0.3);
34
+ --hwTextInput-padding: 3px;
35
+ --hw-text-input-position: absolute;
36
+ --hwTextInput-width: 30px;
37
+
38
+ flex: 1 1 auto;
39
+ }
40
+
41
+ .LayoutBox > .layout-top {
42
+ flex: 0 0 40px;
43
+ padding-left: 12px;
44
+ display: flex;
45
+ flex-direction: row;
46
+ align-items: center;
47
+ position: relative;
48
+ }
49
+
50
+ .LayoutBox > .layout-bottom {
51
+ flex: 0 0 40px;
52
+ position: relative;
53
+ display: flex;
54
+ flex-direction: row;
55
+ align-items: center;
56
+ }
57
+
58
+ .LayoutBox > .layout-inner > .layout-right,
59
+ .LayoutBox > .layout-inner > .layout-left {
60
+ flex: 0 0 40px;
61
+ display: flex;
62
+ flex-direction: column;
63
+ justify-content: center;
64
+ align-items: center;
65
+ }
66
+
67
+ .layout-top,
68
+ .layout-bottom {
69
+ --hw-text-input-margin: 0 0 0 -15px;
70
+ }
71
+
72
+ .layout-top > .layout-input,
73
+ .layout-bottom > .layout-input {
74
+ left: 50%;
75
+ }
76
+
77
+ .LayoutBox > .layout-inner {
78
+ flex: 1 1 auto;
79
+ display: flex;
80
+ flex-direction: row;
81
+ align-items: stretch;
82
+ }
83
+
84
+ .LayoutBox.layout-margin {
85
+ background-color: var(--margin-color);
86
+ border: dashed 2px black;
87
+ }
88
+
89
+ .LayoutBox.layout-border {
90
+ background-color: var(--border-color);
91
+ border: solid 2px black;
92
+ }
93
+
94
+ .LayoutBox.layout-padding {
95
+ background-color: var(--padding-color);
96
+ border: dashed 2px black;
97
+ }
98
+
99
+ .LayoutBox .layout-content {
100
+ flex: 1 1 auto;
101
+ background-color: var(--content-color);
102
+ border: solid 2px #808080;
103
+ }
104
+
105
+ .LayoutBox .layout-title {
106
+ color: #161616;
107
+ font-size: 11px;
108
+ left: 4px;
109
+ line-height: 15px;
110
+ position: absolute;
111
+ top: 1px;
112
+ }
@@ -0,0 +1,369 @@
1
+ import "./layout-configurator.css";
2
+ import { FormField, Input } from "@heswell/uitk-core";
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 "@vuu-ui/ui-controls";
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,3 @@
1
+ export * from './config-wrapper';
2
+ export * from './devtools-box/layout-configurator';
3
+ export * from './devtools-tree/layout-tree-viewer';
@@ -0,0 +1,115 @@
1
+ import { useCallback } from "react";
2
+
3
+ const persistentState = new Map<string, any>();
4
+ const sessionState = new Map<string, any>();
5
+
6
+ // These is not exported by package, only available within
7
+ // layout. Used by LayoutProvider for layout serialization.
8
+ export const getPersistentState = (id: string) => persistentState.get(id);
9
+ export const hasPersistentState = (id: string) => persistentState.has(id);
10
+ export const setPersistentState = (id: string, value: any) =>
11
+ persistentState.set(id, value);
12
+
13
+ export const usePersistentState = () => {
14
+ //TODO create single set of methods that operate on either session or state
15
+
16
+ const loadSessionState = useCallback((id, key) => {
17
+ const state = sessionState.get(id);
18
+ if (state) {
19
+ if (key !== undefined && state[key] !== undefined) {
20
+ return state[key];
21
+ } else if (key !== undefined) {
22
+ return undefined;
23
+ } else {
24
+ return state;
25
+ }
26
+ }
27
+ }, []);
28
+
29
+ const saveSessionState = useCallback((id, key, data) => {
30
+ if (key === undefined) {
31
+ sessionState.set(id, data);
32
+ } else if (sessionState.has(id)) {
33
+ const state = sessionState.get(id);
34
+ sessionState.set(id, {
35
+ ...state,
36
+ [key]: data,
37
+ });
38
+ } else {
39
+ sessionState.set(id, { [key]: data });
40
+ }
41
+ }, []);
42
+
43
+ const purgeSessionState = useCallback((id: string, key?: string) => {
44
+ if (sessionState.has(id)) {
45
+ if (key === undefined) {
46
+ sessionState.delete(id);
47
+ } else {
48
+ const state = sessionState.get(id);
49
+ if (state[key]) {
50
+ const { [key]: _doomedState, ...rest } = sessionState.get(id);
51
+ if (Object.keys(rest).length > 0) {
52
+ sessionState.set(id, rest);
53
+ } else {
54
+ sessionState.delete(id);
55
+ }
56
+ }
57
+ }
58
+ }
59
+ }, []);
60
+
61
+ const loadState = useCallback((id: string, key?: string) => {
62
+ const state = persistentState.get(id);
63
+ if (state) {
64
+ if (key !== undefined) {
65
+ return state[key];
66
+ } else {
67
+ return state;
68
+ }
69
+ }
70
+ }, []);
71
+
72
+ const saveState = useCallback(
73
+ (id: string, key: string | undefined, data: any) => {
74
+ if (key === undefined) {
75
+ persistentState.set(id, data);
76
+ } else if (persistentState.has(id)) {
77
+ const state = persistentState.get(id);
78
+ persistentState.set(id, {
79
+ ...state,
80
+ [key]: data,
81
+ });
82
+ } else {
83
+ persistentState.set(id, { [key]: data });
84
+ }
85
+ },
86
+ []
87
+ );
88
+
89
+ const purgeState = useCallback((id: string, key?: string) => {
90
+ if (persistentState.has(id)) {
91
+ if (key === undefined) {
92
+ persistentState.delete(id);
93
+ } else {
94
+ const state = persistentState.get(id);
95
+ if (state[key]) {
96
+ const { [key]: _doomedState, ...rest } = persistentState.get(id);
97
+ if (Object.keys(rest).length > 0) {
98
+ persistentState.set(id, rest);
99
+ } else {
100
+ persistentState.delete(id);
101
+ }
102
+ }
103
+ }
104
+ }
105
+ }, []);
106
+
107
+ return {
108
+ loadSessionState,
109
+ loadState,
110
+ saveSessionState,
111
+ saveState,
112
+ purgeState,
113
+ purgeSessionState,
114
+ };
115
+ };
@@ -0,0 +1,30 @@
1
+ import React from 'react';
2
+ import { LayoutJSON } from '../layout-reducer';
3
+ import { ComponentRegistry } from '../registry/ComponentRegistry';
4
+
5
+ export function componentFromLayout(layoutModel: LayoutJSON) {
6
+
7
+ const { id, type, props, children: layoutChildren } = layoutModel;
8
+ const ReactType = getComponentType(type);
9
+ let children =
10
+ !layoutChildren || layoutChildren.length === 0
11
+ ? null
12
+ : layoutChildren.length === 1
13
+ ? componentFromLayout(layoutChildren[0])
14
+ : layoutChildren.map(componentFromLayout);
15
+
16
+ return (
17
+ <ReactType {...props} key={id}>
18
+ {children}
19
+ </ReactType>
20
+ );
21
+ }
22
+
23
+ // support for built-in react ttpes (div etc) removed here
24
+ function getComponentType(type: string) {
25
+ const reactType = ComponentRegistry[type];
26
+ if (reactType === undefined){
27
+ throw Error('componentFromLayout: unknown component type: ' + type);
28
+ }
29
+ return reactType;
30
+ }
@@ -0,0 +1,6 @@
1
+ export * from "./styleUtils";
2
+ export * from "./pathUtils";
3
+ export * from "./propUtils";
4
+ export * from "./typeOf";
5
+ export * from "./componentFromLayout";
6
+ export * from "./refUtils";