@vuu-ui/vuu-layout 0.13.7 → 0.13.9

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 (245) hide show
  1. package/cjs/index.js +5513 -113
  2. package/cjs/index.js.map +1 -1
  3. package/esm/index.js +5436 -32
  4. package/esm/index.js.map +1 -1
  5. package/package.json +9 -9
  6. package/cjs/Component.js +0 -14
  7. package/cjs/Component.js.map +0 -1
  8. package/cjs/LayoutContainer.css.js +0 -6
  9. package/cjs/LayoutContainer.css.js.map +0 -1
  10. package/cjs/LayoutContainer.js +0 -33
  11. package/cjs/LayoutContainer.js.map +0 -1
  12. package/cjs/dock-layout/DockLayout.css.js +0 -6
  13. package/cjs/dock-layout/DockLayout.css.js.map +0 -1
  14. package/cjs/dock-layout/DockLayout.js +0 -41
  15. package/cjs/dock-layout/DockLayout.js.map +0 -1
  16. package/cjs/dock-layout/Drawer.css.js +0 -6
  17. package/cjs/dock-layout/Drawer.css.js.map +0 -1
  18. package/cjs/dock-layout/Drawer.js +0 -95
  19. package/cjs/dock-layout/Drawer.js.map +0 -1
  20. package/cjs/drag-drop/BoxModel.js +0 -416
  21. package/cjs/drag-drop/BoxModel.js.map +0 -1
  22. package/cjs/drag-drop/DragState.js +0 -161
  23. package/cjs/drag-drop/DragState.js.map +0 -1
  24. package/cjs/drag-drop/Draggable.js +0 -192
  25. package/cjs/drag-drop/Draggable.js.map +0 -1
  26. package/cjs/drag-drop/DropTarget.js +0 -257
  27. package/cjs/drag-drop/DropTarget.js.map +0 -1
  28. package/cjs/drag-drop/DropTargetRenderer.js +0 -218
  29. package/cjs/drag-drop/DropTargetRenderer.js.map +0 -1
  30. package/cjs/flexbox/Flexbox.css.js +0 -6
  31. package/cjs/flexbox/Flexbox.css.js.map +0 -1
  32. package/cjs/flexbox/Flexbox.js +0 -69
  33. package/cjs/flexbox/Flexbox.js.map +0 -1
  34. package/cjs/flexbox/FlexboxLayout.js +0 -30
  35. package/cjs/flexbox/FlexboxLayout.js.map +0 -1
  36. package/cjs/flexbox/Splitter.css.js +0 -6
  37. package/cjs/flexbox/Splitter.css.js.map +0 -1
  38. package/cjs/flexbox/Splitter.js +0 -122
  39. package/cjs/flexbox/Splitter.js.map +0 -1
  40. package/cjs/flexbox/flexbox-utils.js +0 -95
  41. package/cjs/flexbox/flexbox-utils.js.map +0 -1
  42. package/cjs/flexbox/useSplitterResizing.js +0 -198
  43. package/cjs/flexbox/useSplitterResizing.js.map +0 -1
  44. package/cjs/layout-action.js +0 -24
  45. package/cjs/layout-action.js.map +0 -1
  46. package/cjs/layout-header/Header.css.js +0 -6
  47. package/cjs/layout-header/Header.css.js.map +0 -1
  48. package/cjs/layout-header/Header.js +0 -152
  49. package/cjs/layout-header/Header.js.map +0 -1
  50. package/cjs/layout-header/useHeader.js +0 -86
  51. package/cjs/layout-header/useHeader.js.map +0 -1
  52. package/cjs/layout-provider/LayoutProvider.js +0 -306
  53. package/cjs/layout-provider/LayoutProvider.js.map +0 -1
  54. package/cjs/layout-provider/LayoutProviderContext.js +0 -23
  55. package/cjs/layout-provider/LayoutProviderContext.js.map +0 -1
  56. package/cjs/layout-provider/useLayoutDragDrop.js +0 -177
  57. package/cjs/layout-provider/useLayoutDragDrop.js.map +0 -1
  58. package/cjs/layout-reducer/flexUtils.js +0 -227
  59. package/cjs/layout-reducer/flexUtils.js.map +0 -1
  60. package/cjs/layout-reducer/insert-layout-element.js +0 -286
  61. package/cjs/layout-reducer/insert-layout-element.js.map +0 -1
  62. package/cjs/layout-reducer/layout-reducer.js +0 -202
  63. package/cjs/layout-reducer/layout-reducer.js.map +0 -1
  64. package/cjs/layout-reducer/layoutTypes.js +0 -40
  65. package/cjs/layout-reducer/layoutTypes.js.map +0 -1
  66. package/cjs/layout-reducer/layoutUtils.js +0 -237
  67. package/cjs/layout-reducer/layoutUtils.js.map +0 -1
  68. package/cjs/layout-reducer/move-layout-element.js +0 -31
  69. package/cjs/layout-reducer/move-layout-element.js.map +0 -1
  70. package/cjs/layout-reducer/remove-layout-element.js +0 -237
  71. package/cjs/layout-reducer/remove-layout-element.js.map +0 -1
  72. package/cjs/layout-reducer/replace-layout-element.js +0 -96
  73. package/cjs/layout-reducer/replace-layout-element.js.map +0 -1
  74. package/cjs/layout-reducer/resize-flex-children.js +0 -62
  75. package/cjs/layout-reducer/resize-flex-children.js.map +0 -1
  76. package/cjs/layout-reducer/wrap-layout-element.js +0 -211
  77. package/cjs/layout-reducer/wrap-layout-element.js.map +0 -1
  78. package/cjs/layout-view/View.css.js +0 -6
  79. package/cjs/layout-view/View.css.js.map +0 -1
  80. package/cjs/layout-view/View.js +0 -167
  81. package/cjs/layout-view/View.js.map +0 -1
  82. package/cjs/layout-view/useView.js +0 -91
  83. package/cjs/layout-view/useView.js.map +0 -1
  84. package/cjs/layout-view/useViewBroadcastChannel.js +0 -35
  85. package/cjs/layout-view/useViewBroadcastChannel.js.map +0 -1
  86. package/cjs/layout-view/useViewResize.js +0 -42
  87. package/cjs/layout-view/useViewResize.js.map +0 -1
  88. package/cjs/layout-view-actions/ViewContext.js +0 -16
  89. package/cjs/layout-view-actions/ViewContext.js.map +0 -1
  90. package/cjs/layout-view-actions/useViewActionDispatcher.js +0 -129
  91. package/cjs/layout-view-actions/useViewActionDispatcher.js.map +0 -1
  92. package/cjs/palette/Palette.css.js +0 -6
  93. package/cjs/palette/Palette.css.js.map +0 -1
  94. package/cjs/palette/Palette.js +0 -132
  95. package/cjs/palette/Palette.js.map +0 -1
  96. package/cjs/placeholder/LayoutStartPanel.css.js +0 -6
  97. package/cjs/placeholder/LayoutStartPanel.css.js.map +0 -1
  98. package/cjs/placeholder/LayoutStartPanel.js +0 -56
  99. package/cjs/placeholder/LayoutStartPanel.js.map +0 -1
  100. package/cjs/placeholder/Placeholder.css.js +0 -6
  101. package/cjs/placeholder/Placeholder.css.js.map +0 -1
  102. package/cjs/placeholder/Placeholder.js +0 -34
  103. package/cjs/placeholder/Placeholder.js.map +0 -1
  104. package/cjs/responsive/useResizeObserver.js +0 -118
  105. package/cjs/responsive/useResizeObserver.js.map +0 -1
  106. package/cjs/responsive/utils.js +0 -34
  107. package/cjs/responsive/utils.js.map +0 -1
  108. package/cjs/stack/Stack.css.js +0 -6
  109. package/cjs/stack/Stack.css.js.map +0 -1
  110. package/cjs/stack/Stack.js +0 -150
  111. package/cjs/stack/Stack.js.map +0 -1
  112. package/cjs/stack/StackLayout.js +0 -118
  113. package/cjs/stack/StackLayout.js.map +0 -1
  114. package/cjs/use-persistent-state.js +0 -112
  115. package/cjs/use-persistent-state.js.map +0 -1
  116. package/cjs/utils/pathUtils.js +0 -293
  117. package/cjs/utils/pathUtils.js.map +0 -1
  118. package/cjs/utils/propUtils.js +0 -27
  119. package/cjs/utils/propUtils.js.map +0 -1
  120. package/cjs/utils/refUtils.js +0 -12
  121. package/cjs/utils/refUtils.js.map +0 -1
  122. package/cjs/utils/styleUtils.js +0 -15
  123. package/cjs/utils/styleUtils.js.map +0 -1
  124. package/cjs/utils/typeOf.js +0 -27
  125. package/cjs/utils/typeOf.js.map +0 -1
  126. package/esm/Component.js +0 -12
  127. package/esm/Component.js.map +0 -1
  128. package/esm/LayoutContainer.css.js +0 -4
  129. package/esm/LayoutContainer.css.js.map +0 -1
  130. package/esm/LayoutContainer.js +0 -31
  131. package/esm/LayoutContainer.js.map +0 -1
  132. package/esm/dock-layout/DockLayout.css.js +0 -4
  133. package/esm/dock-layout/DockLayout.css.js.map +0 -1
  134. package/esm/dock-layout/DockLayout.js +0 -39
  135. package/esm/dock-layout/DockLayout.js.map +0 -1
  136. package/esm/dock-layout/Drawer.css.js +0 -4
  137. package/esm/dock-layout/Drawer.css.js.map +0 -1
  138. package/esm/dock-layout/Drawer.js +0 -93
  139. package/esm/dock-layout/Drawer.js.map +0 -1
  140. package/esm/drag-drop/BoxModel.js +0 -409
  141. package/esm/drag-drop/BoxModel.js.map +0 -1
  142. package/esm/drag-drop/DragState.js +0 -159
  143. package/esm/drag-drop/DragState.js.map +0 -1
  144. package/esm/drag-drop/Draggable.js +0 -190
  145. package/esm/drag-drop/Draggable.js.map +0 -1
  146. package/esm/drag-drop/DropTarget.js +0 -253
  147. package/esm/drag-drop/DropTarget.js.map +0 -1
  148. package/esm/drag-drop/DropTargetRenderer.js +0 -216
  149. package/esm/drag-drop/DropTargetRenderer.js.map +0 -1
  150. package/esm/flexbox/Flexbox.css.js +0 -4
  151. package/esm/flexbox/Flexbox.css.js.map +0 -1
  152. package/esm/flexbox/Flexbox.js +0 -67
  153. package/esm/flexbox/Flexbox.js.map +0 -1
  154. package/esm/flexbox/FlexboxLayout.js +0 -28
  155. package/esm/flexbox/FlexboxLayout.js.map +0 -1
  156. package/esm/flexbox/Splitter.css.js +0 -4
  157. package/esm/flexbox/Splitter.css.js.map +0 -1
  158. package/esm/flexbox/Splitter.js +0 -120
  159. package/esm/flexbox/Splitter.js.map +0 -1
  160. package/esm/flexbox/flexbox-utils.js +0 -89
  161. package/esm/flexbox/flexbox-utils.js.map +0 -1
  162. package/esm/flexbox/useSplitterResizing.js +0 -196
  163. package/esm/flexbox/useSplitterResizing.js.map +0 -1
  164. package/esm/layout-action.js +0 -22
  165. package/esm/layout-action.js.map +0 -1
  166. package/esm/layout-header/Header.css.js +0 -4
  167. package/esm/layout-header/Header.css.js.map +0 -1
  168. package/esm/layout-header/Header.js +0 -150
  169. package/esm/layout-header/Header.js.map +0 -1
  170. package/esm/layout-header/useHeader.js +0 -84
  171. package/esm/layout-header/useHeader.js.map +0 -1
  172. package/esm/layout-provider/LayoutProvider.js +0 -299
  173. package/esm/layout-provider/LayoutProvider.js.map +0 -1
  174. package/esm/layout-provider/LayoutProviderContext.js +0 -20
  175. package/esm/layout-provider/LayoutProviderContext.js.map +0 -1
  176. package/esm/layout-provider/useLayoutDragDrop.js +0 -175
  177. package/esm/layout-provider/useLayoutDragDrop.js.map +0 -1
  178. package/esm/layout-reducer/flexUtils.js +0 -218
  179. package/esm/layout-reducer/flexUtils.js.map +0 -1
  180. package/esm/layout-reducer/insert-layout-element.js +0 -282
  181. package/esm/layout-reducer/insert-layout-element.js.map +0 -1
  182. package/esm/layout-reducer/layout-reducer.js +0 -200
  183. package/esm/layout-reducer/layout-reducer.js.map +0 -1
  184. package/esm/layout-reducer/layoutTypes.js +0 -36
  185. package/esm/layout-reducer/layoutTypes.js.map +0 -1
  186. package/esm/layout-reducer/layoutUtils.js +0 -226
  187. package/esm/layout-reducer/layoutUtils.js.map +0 -1
  188. package/esm/layout-reducer/move-layout-element.js +0 -29
  189. package/esm/layout-reducer/move-layout-element.js.map +0 -1
  190. package/esm/layout-reducer/remove-layout-element.js +0 -235
  191. package/esm/layout-reducer/remove-layout-element.js.map +0 -1
  192. package/esm/layout-reducer/replace-layout-element.js +0 -92
  193. package/esm/layout-reducer/replace-layout-element.js.map +0 -1
  194. package/esm/layout-reducer/resize-flex-children.js +0 -59
  195. package/esm/layout-reducer/resize-flex-children.js.map +0 -1
  196. package/esm/layout-reducer/wrap-layout-element.js +0 -209
  197. package/esm/layout-reducer/wrap-layout-element.js.map +0 -1
  198. package/esm/layout-view/View.css.js +0 -4
  199. package/esm/layout-view/View.css.js.map +0 -1
  200. package/esm/layout-view/View.js +0 -165
  201. package/esm/layout-view/View.js.map +0 -1
  202. package/esm/layout-view/useView.js +0 -89
  203. package/esm/layout-view/useView.js.map +0 -1
  204. package/esm/layout-view/useViewBroadcastChannel.js +0 -33
  205. package/esm/layout-view/useViewBroadcastChannel.js.map +0 -1
  206. package/esm/layout-view/useViewResize.js +0 -40
  207. package/esm/layout-view/useViewResize.js.map +0 -1
  208. package/esm/layout-view-actions/ViewContext.js +0 -12
  209. package/esm/layout-view-actions/ViewContext.js.map +0 -1
  210. package/esm/layout-view-actions/useViewActionDispatcher.js +0 -127
  211. package/esm/layout-view-actions/useViewActionDispatcher.js.map +0 -1
  212. package/esm/palette/Palette.css.js +0 -4
  213. package/esm/palette/Palette.css.js.map +0 -1
  214. package/esm/palette/Palette.js +0 -129
  215. package/esm/palette/Palette.js.map +0 -1
  216. package/esm/placeholder/LayoutStartPanel.css.js +0 -4
  217. package/esm/placeholder/LayoutStartPanel.css.js.map +0 -1
  218. package/esm/placeholder/LayoutStartPanel.js +0 -54
  219. package/esm/placeholder/LayoutStartPanel.js.map +0 -1
  220. package/esm/placeholder/Placeholder.css.js +0 -4
  221. package/esm/placeholder/Placeholder.css.js.map +0 -1
  222. package/esm/placeholder/Placeholder.js +0 -32
  223. package/esm/placeholder/Placeholder.js.map +0 -1
  224. package/esm/responsive/useResizeObserver.js +0 -112
  225. package/esm/responsive/useResizeObserver.js.map +0 -1
  226. package/esm/responsive/utils.js +0 -31
  227. package/esm/responsive/utils.js.map +0 -1
  228. package/esm/stack/Stack.css.js +0 -4
  229. package/esm/stack/Stack.css.js.map +0 -1
  230. package/esm/stack/Stack.js +0 -148
  231. package/esm/stack/Stack.js.map +0 -1
  232. package/esm/stack/StackLayout.js +0 -116
  233. package/esm/stack/StackLayout.js.map +0 -1
  234. package/esm/use-persistent-state.js +0 -107
  235. package/esm/use-persistent-state.js.map +0 -1
  236. package/esm/utils/pathUtils.js +0 -280
  237. package/esm/utils/pathUtils.js.map +0 -1
  238. package/esm/utils/propUtils.js +0 -23
  239. package/esm/utils/propUtils.js.map +0 -1
  240. package/esm/utils/refUtils.js +0 -10
  241. package/esm/utils/refUtils.js.map +0 -1
  242. package/esm/utils/styleUtils.js +0 -13
  243. package/esm/utils/styleUtils.js.map +0 -1
  244. package/esm/utils/typeOf.js +0 -23
  245. package/esm/utils/typeOf.js.map +0 -1
@@ -1,200 +0,0 @@
1
- import { isContainer } from '@vuu-ui/vuu-utils';
2
- import React from 'react';
3
- import { followPath, findTarget, followPathToParent } from '../utils/pathUtils.js';
4
- import { getProps, getProp } from '../utils/propUtils.js';
5
- import { typeOf } from '../utils/typeOf.js';
6
- import { getIntrinsicSize } from './flexUtils.js';
7
- import { getInsertTabBeforeAfter, insertIntoContainer, insertBesideChild } from './insert-layout-element.js';
8
- import { moveChild } from './move-layout-element.js';
9
- import { LayoutActionType } from './layoutTypes.js';
10
- import { removeChild } from './remove-layout-element.js';
11
- import { replaceChild, swapChild, _replaceChild } from './replace-layout-element.js';
12
- import { resizeFlexChild, resizeFlexChildren } from './resize-flex-children.js';
13
- import { wrap } from './wrap-layout-element.js';
14
-
15
- const layoutReducer = (state, action) => {
16
- switch (action.type) {
17
- case LayoutActionType.ADD:
18
- return addChild(state, action);
19
- case LayoutActionType.DRAG_DROP:
20
- return dragDrop(state, action);
21
- case "collapse":
22
- case "expand":
23
- return setChildProps(state, action);
24
- case LayoutActionType.REMOVE:
25
- return removeChild(state, action);
26
- case LayoutActionType.REPLACE:
27
- return replaceChild(state, action);
28
- case LayoutActionType.SET_PROP:
29
- return setProp(state, action);
30
- case LayoutActionType.SET_PROPS:
31
- return setProps(state, action);
32
- case LayoutActionType.SET_TITLE:
33
- return setProp(state, {
34
- type: "set-prop",
35
- path: action.path,
36
- propName: "title",
37
- propValue: action.title
38
- });
39
- case LayoutActionType.SPLITTER_RESIZE:
40
- return resizeFlexChildren(state, action);
41
- case LayoutActionType.LAYOUT_RESIZE:
42
- return resizeFlexChild(state, action);
43
- case LayoutActionType.SWITCH_TAB:
44
- return switchTab(state, action);
45
- case LayoutActionType.MOVE_CHILD:
46
- return moveChild(state, action);
47
- default:
48
- return state;
49
- }
50
- };
51
- const switchTab = (state, { path, nextIdx }) => {
52
- const target = followPath(state, path, true);
53
- const replacement = React.cloneElement(target, {
54
- active: nextIdx
55
- });
56
- return swapChild(state, target, replacement);
57
- };
58
- const setProp = (state, { path, propName, propValue }) => {
59
- const target = followPath(state, path, true);
60
- const replacement = React.cloneElement(target, {
61
- [propName]: propValue
62
- });
63
- return swapChild(state, target, replacement);
64
- };
65
- const setProps = (state, { path, props }) => {
66
- const target = followPath(state, path, true);
67
- const replacement = React.cloneElement(target, props);
68
- return swapChild(state, target, replacement);
69
- };
70
- const setChildProps = (state, { path, type }) => {
71
- if (path) {
72
- const target = followPath(state, path, true);
73
- return swapChild(state, target, target, type);
74
- } else {
75
- return state;
76
- }
77
- };
78
- const dragDrop = (layoutRoot, action) => {
79
- const {
80
- draggedReactElement: newComponent,
81
- dragInstructions,
82
- dropTarget
83
- } = action;
84
- const existingComponent = dropTarget.component;
85
- const { pos } = dropTarget;
86
- const destinationTabstrip = pos?.position?.Header && typeOf(existingComponent) === "Stack";
87
- const { id, version } = getProps(newComponent);
88
- const intrinsicSize = getIntrinsicSize(newComponent);
89
- let newLayoutRoot;
90
- if (destinationTabstrip) {
91
- const [targetTab, insertionPosition] = getInsertTabBeforeAfter(
92
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
93
- existingComponent,
94
- pos
95
- );
96
- if (targetTab === void 0) {
97
- newLayoutRoot = insertIntoContainer(
98
- layoutRoot,
99
- existingComponent,
100
- newComponent
101
- );
102
- } else {
103
- newLayoutRoot = insertBesideChild(
104
- layoutRoot,
105
- targetTab,
106
- newComponent,
107
- insertionPosition
108
- );
109
- }
110
- } else if (!intrinsicSize && pos?.position?.Centre) {
111
- newLayoutRoot = _replaceChild(
112
- layoutRoot,
113
- existingComponent,
114
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
115
- newComponent
116
- );
117
- } else {
118
- newLayoutRoot = dropLayoutIntoContainer(
119
- layoutRoot,
120
- dropTarget,
121
- newComponent
122
- );
123
- }
124
- if (dragInstructions.DoNotRemove) {
125
- return newLayoutRoot;
126
- }
127
- const finalTarget = findTarget(
128
- newLayoutRoot,
129
- (props) => props.id === id && props.version === version
130
- );
131
- const finalPath = getProp(finalTarget, "path");
132
- return removeChild(newLayoutRoot, { path: finalPath, type: "remove" });
133
- };
134
- const addChild = (layoutRoot, { path: containerPath, component }) => {
135
- return insertIntoContainer(
136
- layoutRoot,
137
- followPath(layoutRoot, containerPath),
138
- component
139
- );
140
- };
141
- const dropLayoutIntoContainer = (layoutRoot, dropTarget, newComponent) => {
142
- const { component, pos, clientRect, dropRect } = dropTarget;
143
- const existingComponent = component;
144
- const existingComponentPath = getProp(existingComponent, "path");
145
- if (existingComponentPath === "0.0") {
146
- return wrap(
147
- layoutRoot,
148
- existingComponent,
149
- newComponent,
150
- pos
151
- );
152
- }
153
- const targetContainer = followPathToParent(
154
- layoutRoot,
155
- existingComponentPath
156
- );
157
- if (withTheGrain(pos, targetContainer)) {
158
- const insertionPosition = pos.position.SouthOrEast ? "after" : "before";
159
- return insertBesideChild(
160
- layoutRoot,
161
- existingComponent,
162
- newComponent,
163
- insertionPosition,
164
- pos,
165
- clientRect,
166
- dropRect
167
- );
168
- }
169
- if (!withTheGrain(pos, targetContainer)) {
170
- return wrap(
171
- layoutRoot,
172
- existingComponent,
173
- newComponent,
174
- pos,
175
- clientRect,
176
- dropRect
177
- );
178
- }
179
- if (isContainer(typeOf(targetContainer))) {
180
- return wrap(layoutRoot, existingComponent, newComponent, pos);
181
- }
182
- throw Error(`no support right now for position = ${pos.position}`);
183
- };
184
- const withTheGrain = (pos, container) => {
185
- if (pos.position.Centre) {
186
- return isTerrace(container) || isTower(container);
187
- }
188
- return pos.position.NorthOrSouth ? isTower(container) : pos.position.EastOrWest ? isTerrace(container) : false;
189
- };
190
- const isTower = (container) => {
191
- const { style } = container.props;
192
- return typeOf(container) === "Flexbox" && style.flexDirection === "column";
193
- };
194
- const isTerrace = (container) => {
195
- const { style } = container.props;
196
- return typeOf(container) === "Flexbox" && style.flexDirection !== "column";
197
- };
198
-
199
- export { layoutReducer };
200
- //# sourceMappingURL=layout-reducer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"layout-reducer.js","sources":["../../src/layout-reducer/layout-reducer.ts"],"sourcesContent":["import { isContainer } from \"@vuu-ui/vuu-utils\";\nimport React, { ReactElement } from \"react\";\nimport { DropPos } from \"../drag-drop/dragDropTypes\";\nimport { DropTarget } from \"../drag-drop/DropTarget\";\nimport {\n findTarget,\n followPath,\n followPathToParent,\n getProp,\n getProps,\n typeOf,\n} from \"../utils\";\nimport { getIntrinsicSize } from \"./flexUtils\";\nimport {\n getInsertTabBeforeAfter,\n insertBesideChild,\n insertIntoContainer,\n} from \"./insert-layout-element\";\nimport { moveChild } from \"./move-layout-element\";\nimport {\n AddAction,\n CollapseAction,\n DragDropAction,\n ExpandAction,\n LayoutActionType,\n LayoutReducerAction,\n SetPropAction,\n SetPropsAction,\n SwitchTabAction,\n} from \"./layoutTypes\";\nimport { LayoutProps } from \"./layoutUtils\";\nimport { removeChild } from \"./remove-layout-element\";\nimport {\n replaceChild,\n swapChild,\n _replaceChild,\n} from \"./replace-layout-element\";\nimport { resizeFlexChild, resizeFlexChildren } from \"./resize-flex-children\";\nimport { wrap } from \"./wrap-layout-element\";\n\nexport const layoutReducer = (\n state: ReactElement,\n action: LayoutReducerAction,\n): ReactElement => {\n switch (action.type) {\n case LayoutActionType.ADD:\n return addChild(state, action);\n case LayoutActionType.DRAG_DROP:\n return dragDrop(state, action);\n case \"collapse\":\n case \"expand\":\n return setChildProps(state, action);\n case LayoutActionType.REMOVE:\n return removeChild(state, action);\n case LayoutActionType.REPLACE:\n return replaceChild(state, action);\n case LayoutActionType.SET_PROP:\n return setProp(state, action);\n case LayoutActionType.SET_PROPS:\n return setProps(state, action);\n case LayoutActionType.SET_TITLE:\n return setProp(state, {\n type: \"set-prop\",\n path: action.path,\n propName: \"title\",\n propValue: action.title,\n });\n case LayoutActionType.SPLITTER_RESIZE:\n return resizeFlexChildren(state, action);\n case LayoutActionType.LAYOUT_RESIZE:\n return resizeFlexChild(state, action);\n case LayoutActionType.SWITCH_TAB:\n return switchTab(state, action);\n case LayoutActionType.MOVE_CHILD:\n return moveChild(state, action);\n default:\n return state;\n }\n};\n\nconst switchTab = (state: ReactElement, { path, nextIdx }: SwitchTabAction) => {\n const target = followPath(state, path, true);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const replacement = React.cloneElement<any>(target, {\n active: nextIdx,\n });\n return swapChild(state, target, replacement);\n};\n\nconst setProp = (\n state: ReactElement,\n { path, propName, propValue }: SetPropAction,\n) => {\n const target = followPath(state, path, true);\n const replacement = React.cloneElement(target, {\n [propName]: propValue,\n });\n return swapChild(state, target, replacement);\n};\n\nconst setProps = (state: ReactElement, { path, props }: SetPropsAction) => {\n const target = followPath(state, path, true);\n const replacement = React.cloneElement(target, props);\n return swapChild(state, target, replacement);\n};\n\nconst setChildProps = (\n state: ReactElement,\n { path, type }: CollapseAction | ExpandAction,\n) => {\n if (path) {\n const target = followPath(state, path, true);\n return swapChild(state, target, target, type);\n } else {\n return state;\n }\n};\n\nconst dragDrop = (\n layoutRoot: ReactElement,\n action: DragDropAction,\n): ReactElement => {\n const {\n draggedReactElement: newComponent,\n dragInstructions,\n dropTarget,\n } = action;\n const existingComponent = dropTarget.component as ReactElement;\n const { pos } = dropTarget;\n const destinationTabstrip =\n pos?.position?.Header && typeOf(existingComponent) === \"Stack\";\n const { id, version } = getProps(newComponent);\n const intrinsicSize = getIntrinsicSize(newComponent);\n let newLayoutRoot: ReactElement;\n if (destinationTabstrip) {\n const [targetTab, insertionPosition] = getInsertTabBeforeAfter(\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n existingComponent!,\n pos,\n );\n if (targetTab === undefined) {\n newLayoutRoot = insertIntoContainer(\n layoutRoot,\n existingComponent,\n newComponent,\n );\n } else {\n newLayoutRoot = insertBesideChild(\n layoutRoot,\n targetTab,\n newComponent,\n insertionPosition,\n );\n }\n } else if (!intrinsicSize && pos?.position?.Centre) {\n newLayoutRoot = _replaceChild(\n layoutRoot,\n existingComponent as ReactElement,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n newComponent as any,\n );\n } else {\n newLayoutRoot = dropLayoutIntoContainer(\n layoutRoot,\n dropTarget as DropTarget,\n newComponent,\n );\n }\n\n if (dragInstructions.DoNotRemove) {\n return newLayoutRoot;\n }\n\n const finalTarget = findTarget(\n newLayoutRoot,\n (props: LayoutProps) => props.id === id && props.version === version,\n ) as ReactElement;\n const finalPath = getProp(finalTarget, \"path\");\n return removeChild(newLayoutRoot, { path: finalPath, type: \"remove\" });\n};\n\nconst addChild = (\n layoutRoot: ReactElement,\n { path: containerPath, component }: AddAction,\n) => {\n return insertIntoContainer(\n layoutRoot,\n followPath(layoutRoot, containerPath) as ReactElement,\n component,\n );\n};\n\nconst dropLayoutIntoContainer = (\n layoutRoot: ReactElement,\n dropTarget: DropTarget,\n newComponent: ReactElement,\n): ReactElement => {\n const { component, pos, clientRect, dropRect } = dropTarget;\n const existingComponent = component as ReactElement;\n\n const existingComponentPath = getProp(existingComponent, \"path\");\n\n if (existingComponentPath === \"0.0\") {\n return wrap(\n layoutRoot,\n existingComponent as ReactElement,\n newComponent,\n pos,\n );\n }\n\n const targetContainer = followPathToParent(\n layoutRoot,\n existingComponentPath,\n ) as ReactElement;\n\n if (withTheGrain(pos, targetContainer)) {\n const insertionPosition = pos.position.SouthOrEast ? \"after\" : \"before\";\n return insertBesideChild(\n layoutRoot,\n existingComponent,\n newComponent,\n insertionPosition,\n pos,\n clientRect,\n dropRect,\n );\n }\n\n if (!withTheGrain(pos, targetContainer)) {\n return wrap(\n layoutRoot,\n existingComponent,\n newComponent,\n pos,\n clientRect,\n dropRect,\n );\n }\n\n if (isContainer(typeOf(targetContainer) as string)) {\n return wrap(layoutRoot, existingComponent, newComponent, pos);\n }\n\n throw Error(`no support right now for position = ${pos.position}`);\n};\n\nconst withTheGrain = (pos: DropPos, container: ReactElement) => {\n if (pos.position.Centre) {\n return isTerrace(container) || isTower(container);\n }\n\n return pos.position.NorthOrSouth\n ? isTower(container)\n : pos.position.EastOrWest\n ? isTerrace(container)\n : false;\n};\n\nconst isTower = (container: ReactElement) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const { style } = container.props as any;\n return typeOf(container) === \"Flexbox\" && style.flexDirection === \"column\";\n};\n\nconst isTerrace = (container: ReactElement) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const { style } = container.props as any;\n return typeOf(container) === \"Flexbox\" && style.flexDirection !== \"column\";\n};\n"],"names":[],"mappings":";;;;;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AAA,QAAA;AACpE,CAAA;AAEA,MAAM,SAAA,GAAY,CAAC,SAA4B,KAAA;AAE7C,EAAM,MAAA,EAAE,KAAM,EAAA,GAAI,SAAU,CAAA,KAAA;AAC5B,EAAA,OAAO,MAAO,CAAA,SAAS,CAAM,KAAA,SAAA,IAAa,MAAM,aAAkB,KAAA,QAAA;AACpE,CAAA;;;;"}
@@ -1,36 +0,0 @@
1
- const LayoutActionType = {
2
- ADD: "add",
3
- DRAG_START: "drag-start",
4
- DRAG_DROP: "drag-drop",
5
- LAYOUT_RESIZE: "layout-resize",
6
- MAXIMIZE: "maximize",
7
- MINIMIZE: "minimize",
8
- MOVE_CHILD: "move-child",
9
- QUERY: "query",
10
- REMOVE: "remove",
11
- REPLACE: "replace",
12
- RESTORE: "restore",
13
- SET_PROP: "set-prop",
14
- SET_PROPS: "set-props",
15
- SET_TITLE: "set-title",
16
- SPLITTER_RESIZE: "splitter-resize",
17
- SWITCH_TAB: "switch-tab",
18
- TEAROUT: "tearout"
19
- };
20
- const isApplicationLevelChange = (layoutChangeReason) => [
21
- "switch-active-layout",
22
- "open-layout",
23
- "close-layout",
24
- "rename-layout"
25
- ].includes(layoutChangeReason);
26
- const isLayoutLevelChange = (layoutChangeReason) => [
27
- "switch-active-tab",
28
- "edit-feature-title",
29
- "save-feature-props",
30
- "remove-component",
31
- "resize-component",
32
- "drag-drop-operation"
33
- ].includes(layoutChangeReason);
34
-
35
- export { LayoutActionType, isApplicationLevelChange, isLayoutLevelChange };
36
- //# sourceMappingURL=layoutTypes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"layoutTypes.js","sources":["../../src/layout-reducer/layoutTypes.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { LayoutJSON } from \"@vuu-ui/vuu-utils\";\nimport { ReactElement } from \"react\";\nimport { DragDropRect, DragInstructions } from \"../drag-drop\";\nimport { DropTarget } from \"../drag-drop/DropTarget\";\n\nexport type layoutType = \"Flexbox\" | \"View\" | \"LayoutContainer\" | \"Stack\";\n\n// TODO duplicated in layout-action\nexport const LayoutActionType = {\n ADD: \"add\",\n DRAG_START: \"drag-start\",\n DRAG_DROP: \"drag-drop\",\n LAYOUT_RESIZE: \"layout-resize\",\n MAXIMIZE: \"maximize\",\n MINIMIZE: \"minimize\",\n MOVE_CHILD: \"move-child\",\n QUERY: \"query\",\n REMOVE: \"remove\",\n REPLACE: \"replace\",\n RESTORE: \"restore\",\n SET_PROP: \"set-prop\",\n SET_PROPS: \"set-props\",\n SET_TITLE: \"set-title\",\n SPLITTER_RESIZE: \"splitter-resize\",\n SWITCH_TAB: \"switch-tab\",\n TEAROUT: \"tearout\",\n} as const;\n\nexport type AddAction = {\n component: any;\n path: string;\n type: typeof LayoutActionType.ADD;\n};\n\nexport type DragDropAction = {\n draggedReactElement: ReactElement;\n dragInstructions: any;\n dropTarget: Partial<DropTarget>;\n type: typeof LayoutActionType.DRAG_DROP;\n};\n\nexport type MaximizeAction = {\n path?: string;\n type: typeof LayoutActionType.MAXIMIZE;\n};\n\nexport type CollapseAction = {\n path?: string;\n type: \"collapse\";\n};\n\nexport type ExpandAction = {\n path?: string;\n type: \"expand\";\n};\n\nexport type MoveChildAction = {\n fromIndex: number;\n toIndex: number;\n path: string;\n type: typeof LayoutActionType.MOVE_CHILD;\n};\n\nexport type QueryAction = {\n path?: string;\n query: string;\n type: typeof LayoutActionType.QUERY;\n};\n\nexport type RemoveAction = {\n path?: string;\n type: typeof LayoutActionType.REMOVE;\n};\n\nexport type ReplaceAction = {\n replacement: any;\n target: any;\n type: typeof LayoutActionType.REPLACE;\n};\n\nexport type RestoreAction = {\n path?: string;\n type: typeof LayoutActionType.RESTORE;\n};\n\nexport type SetPropAction = {\n path: string;\n propName: string;\n propValue: string | number | boolean;\n type: typeof LayoutActionType.SET_PROP;\n};\n\nexport type SetPropsAction = {\n path: string;\n props: { [key: string]: unknown };\n type: typeof LayoutActionType.SET_PROPS;\n};\n\nexport type SetTitleAction = {\n path: string;\n title: string;\n type: typeof LayoutActionType.SET_TITLE;\n};\n\nexport type SplitterResizeAction = {\n path: string;\n sizes: { currentSize: number; flexBasis: number }[];\n type: typeof LayoutActionType.SPLITTER_RESIZE;\n};\n\nexport type LayoutResizeAction = {\n path: string;\n size: number;\n type: typeof LayoutActionType.LAYOUT_RESIZE;\n};\n\nexport type SwitchTabAction = {\n id?: string;\n nextIdx: number;\n path: string;\n type: typeof LayoutActionType.SWITCH_TAB;\n};\n\nexport type TearoutAction = {\n path?: string;\n type: typeof LayoutActionType.TEAROUT;\n};\n\nexport type LayoutReducerAction =\n | AddAction\n | DragDropAction\n | LayoutResizeAction\n | CollapseAction\n | ExpandAction\n | MoveChildAction\n | RemoveAction\n | ReplaceAction\n | RestoreAction\n | SetPropAction\n | SetPropsAction\n | SetTitleAction\n | SplitterResizeAction\n | SwitchTabAction;\n\nexport type MousedownViewAction = {\n preDragActivity?: unknown;\n index?: number;\n type: \"mousedown\";\n};\n\nexport type DragStartAction = {\n payload?: ReactElement;\n dragContainerPath?: string;\n dragElement?: HTMLElement;\n dragRect: DragDropRect;\n dropTargets?: string[];\n evt: MouseEvent;\n instructions?: DragInstructions;\n path: string;\n type: typeof LayoutActionType.DRAG_START;\n};\n\nexport type LayoutLevelChange =\n | \"add-component\"\n | \"drag-drop-operation\"\n | \"edit-feature-title\"\n | \"remove-component\"\n | \"resize-component\"\n | \"switch-active-tab\"\n | \"save-feature-props\";\n\nexport type ApplicationLevelChange =\n | \"switch-active-layout\"\n | \"open-layout\"\n | \"close-layout\"\n | \"rename-layout\"\n | \"resize-application-chrome\";\n\nexport type LayoutChangeReason = LayoutLevelChange | ApplicationLevelChange;\n\nexport type LayoutChangeHandler = (\n layout: LayoutJSON,\n layoutChangeReason: LayoutChangeReason,\n) => void;\n\nexport const isApplicationLevelChange = (\n layoutChangeReason: LayoutChangeReason,\n): layoutChangeReason is ApplicationLevelChange =>\n [\n \"switch-active-layout\",\n \"open-layout\",\n \"close-layout\",\n \"rename-layout\",\n ].includes(layoutChangeReason);\n\nexport const isLayoutLevelChange = (\n layoutChangeReason: LayoutChangeReason,\n): layoutChangeReason is LayoutLevelChange =>\n [\n \"switch-active-tab\",\n \"edit-feature-title\",\n \"save-feature-props\",\n \"remove-component\",\n \"resize-component\",\n \"drag-drop-operation\",\n ].includes(layoutChangeReason);\n"],"names":[],"mappings":"AASO,MAAM,gBAAmB,GAAA;AAAA,EAC9B,GAAK,EAAA,KAAA;AAAA,EACL,UAAY,EAAA,YAAA;AAAA,EACZ,SAAW,EAAA,WAAA;AAAA,EACX,aAAe,EAAA,eAAA;AAAA,EACf,QAAU,EAAA,UAAA;AAAA,EACV,QAAU,EAAA,UAAA;AAAA,EACV,UAAY,EAAA,YAAA;AAAA,EACZ,KAAO,EAAA,OAAA;AAAA,EACP,MAAQ,EAAA,QAAA;AAAA,EACR,OAAS,EAAA,SAAA;AAAA,EACT,OAAS,EAAA,SAAA;AAAA,EACT,QAAU,EAAA,UAAA;AAAA,EACV,SAAW,EAAA,WAAA;AAAA,EACX,SAAW,EAAA,WAAA;AAAA,EACX,eAAiB,EAAA,iBAAA;AAAA,EACjB,UAAY,EAAA,YAAA;AAAA,EACZ,OAAS,EAAA;AACX;AA+Ja,MAAA,wBAAA,GAA2B,CACtC,kBAEA,KAAA;AAAA,EACE,sBAAA;AAAA,EACA,aAAA;AAAA,EACA,cAAA;AAAA,EACA;AACF,CAAA,CAAE,SAAS,kBAAkB;AAElB,MAAA,mBAAA,GAAsB,CACjC,kBAEA,KAAA;AAAA,EACE,mBAAA;AAAA,EACA,oBAAA;AAAA,EACA,oBAAA;AAAA,EACA,kBAAA;AAAA,EACA,kBAAA;AAAA,EACA;AACF,CAAA,CAAE,SAAS,kBAAkB;;;;"}
@@ -1,226 +0,0 @@
1
- import { isContainer, getLayoutComponent, uuid, isLayoutComponent } from '@vuu-ui/vuu-utils';
2
- import React, { cloneElement } from 'react';
3
- import { setPersistentState, hasPersistentState, getPersistentState } from '../use-persistent-state.js';
4
- import { followPathToParent } from '../utils/pathUtils.js';
5
- import { getProps } from '../utils/propUtils.js';
6
- import { expandFlex } from '../utils/styleUtils.js';
7
- import { typeOf } from '../utils/typeOf.js';
8
-
9
- const getManagedDimension = (style) => style.flexDirection === "column" ? ["height", "width"] : ["width", "height"];
10
- const theKidHasNoStyle = {};
11
- const applyLayoutProps = (component, path = "0") => {
12
- const [layoutProps, children] = getChildLayoutProps(
13
- typeOf(component),
14
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
- component.props,
16
- path
17
- );
18
- return React.cloneElement(component, layoutProps, children);
19
- };
20
- const cloneElementAddLayoutProps = (layoutElement, previousLayout) => {
21
- const type = typeOf(layoutElement);
22
- const [layoutProps, children] = getChildLayoutProps(
23
- type,
24
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
- layoutElement.props,
26
- "0",
27
- void 0,
28
- previousLayout
29
- );
30
- return cloneElement(layoutElement, layoutProps, children);
31
- };
32
- const applyLayout = (type, props, previousLayout) => {
33
- const [layoutProps, children] = getChildLayoutProps(
34
- type,
35
- props,
36
- "0",
37
- void 0,
38
- previousLayout
39
- );
40
- return {
41
- ...props,
42
- ...layoutProps,
43
- type,
44
- children
45
- };
46
- };
47
- function getLayoutProps(type, props, path = "0", parentType = null, previousLayout) {
48
- const {
49
- active: prevActive = 0,
50
- "data-path": dataPath,
51
- path: prevPath = dataPath,
52
- id: prevId,
53
- style: prevStyle
54
- } = getProps(previousLayout);
55
- const prevMatch = typeOf(previousLayout) === type && path === prevPath;
56
- const id = prevMatch ? prevId : props.id ?? uuid();
57
- const active = type === "Stack" ? props.active ?? prevActive : void 0;
58
- const key = id;
59
- const style = prevMatch ? prevStyle : getStyle(type, props, parentType);
60
- return isLayoutComponent(type) ? { id, key, path, style, type, active } : { id, key, style, "data-path": path };
61
- }
62
- function getChildLayoutProps(type, props, path, parentType = null, previousLayout) {
63
- const layoutProps = getLayoutProps(
64
- type,
65
- props,
66
- path,
67
- parentType,
68
- previousLayout
69
- );
70
- if (props.layout && !previousLayout) {
71
- return [layoutProps, [layoutFromJson(props.layout, `${path}.0`)]];
72
- }
73
- const previousChildren = (
74
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
75
- previousLayout?.children ?? // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
- previousLayout?.props?.children
77
- );
78
- const hasDynamicChildren = props.dropTarget && previousChildren;
79
- const children = hasDynamicChildren ? previousChildren : getLayoutChildren(type, props.children, path, previousChildren);
80
- return [layoutProps, children];
81
- }
82
- function getLayoutChildren(type, children, path = "0", previousChildren) {
83
- const kids = Array.isArray(children) ? children : React.isValidElement(children) ? [children] : [];
84
- return isContainer(type) ? kids.map((child, i) => {
85
- const childType = typeOf(child);
86
- const previousType = typeOf(previousChildren?.[i]);
87
- if (!previousType || childType === previousType) {
88
- const [layoutProps, children2] = getChildLayoutProps(
89
- childType,
90
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
91
- child.props,
92
- `${path}.${i}`,
93
- type,
94
- previousChildren?.[i]
95
- );
96
- return React.cloneElement(child, layoutProps, children2);
97
- }
98
- return previousChildren?.[i];
99
- }) : children;
100
- }
101
- const getStyle = (type, props, parentType) => {
102
- let { style = theKidHasNoStyle } = props;
103
- if (type === "Flexbox") {
104
- style = {
105
- flexDirection: props.column ? "column" : "row",
106
- ...style,
107
- display: "flex"
108
- };
109
- }
110
- if (style.flex) {
111
- const { flex, ...otherStyles } = style;
112
- style = {
113
- ...otherStyles,
114
- ...expandFlex(typeof flex === "number" ? flex : 0)
115
- };
116
- } else if (parentType === "Stack") {
117
- style = {
118
- ...style,
119
- ...expandFlex(1)
120
- };
121
- } else if (parentType === "Flexbox" && (style.width || style.height) && style.flexBasis === void 0) {
122
- style = {
123
- ...style,
124
- flexBasis: "auto",
125
- flexGrow: 0,
126
- flexShrink: 0
127
- };
128
- }
129
- return style;
130
- };
131
- function layoutFromJson({ active, id = uuid(), type, children, props, state }, path) {
132
- const componentType = type.match(/^[a-z]/) ? type : getLayoutComponent(type);
133
- if (componentType === void 0) {
134
- throw Error(
135
- `layoutUtils unable to create component from JSON, unknown type ${type}`
136
- );
137
- }
138
- if (state) {
139
- setPersistentState(id, state);
140
- }
141
- return React.createElement(
142
- componentType,
143
- {
144
- active,
145
- id,
146
- ...props,
147
- key: id,
148
- path
149
- },
150
- children ? children.map((child, i) => layoutFromJson(child, `${path}.${i}`)) : void 0
151
- );
152
- }
153
- function layoutToJSON(component) {
154
- return componentToJson(component);
155
- }
156
- function componentToJson(component) {
157
- const type = typeOf(component);
158
- const { id, children, type: _omit, ...props } = getProps(component);
159
- const state = hasPersistentState(id) ? getPersistentState(id) : void 0;
160
- return {
161
- id,
162
- type,
163
- props: serializeProps(props),
164
- state,
165
- children: React.Children.map(children, componentToJson)
166
- };
167
- }
168
- function serializeProps(props) {
169
- if (props) {
170
- const { path, ...otherProps } = props;
171
- const result = {};
172
- for (const [key, value] of Object.entries(otherProps)) {
173
- result[key] = serializeValue(value);
174
- }
175
- return result;
176
- }
177
- }
178
- function serializeValue(value) {
179
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
180
- return value;
181
- } else if (Array.isArray(value)) {
182
- return value.map(serializeValue);
183
- } else if (typeof value === "object" && value !== null) {
184
- const result = {};
185
- for (const [k, v] of Object.entries(value)) {
186
- result[k] = serializeValue(v);
187
- }
188
- return result;
189
- }
190
- }
191
- const layoutQuery = (query, path, layoutRoot) => {
192
- if (path && layoutRoot) {
193
- const parentElement = followPathToParent(layoutRoot, path);
194
- if (parentElement) {
195
- const { id: parentContainerId } = getProps(parentElement);
196
- const parentContainerType = typeOf(parentElement);
197
- return {
198
- parentContainerId,
199
- parentContainerType
200
- };
201
- }
202
- return {
203
- parentContainerType: "Stack",
204
- parentContainerId: "blah"
205
- };
206
- }
207
- };
208
- const getDefaultTabLabel = (component, tabIndex, existingLabels = []) => {
209
- let label = (
210
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
211
- component.props?.title ?? // eslint-disable-next-line @typescript-eslint/no-explicit-any
212
- component.props?.["data-tab-title"] ?? existingLabels[tabIndex]
213
- );
214
- if (label) {
215
- return label;
216
- } else {
217
- let count = tabIndex;
218
- do {
219
- label = `Tab ${++count}`;
220
- } while (existingLabels.includes(label));
221
- return label;
222
- }
223
- };
224
-
225
- export { applyLayout, applyLayoutProps, cloneElementAddLayoutProps, componentToJson, getDefaultTabLabel, getManagedDimension, layoutFromJson, layoutQuery, layoutToJSON, serializeProps };
226
- //# sourceMappingURL=layoutUtils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"layoutUtils.js","sources":["../../src/layout-reducer/layoutUtils.ts"],"sourcesContent":["import {\n LayoutJSON,\n LayoutModel,\n dimension,\n getLayoutComponent,\n isContainer,\n isLayoutComponent,\n uuid,\n} from \"@vuu-ui/vuu-utils\";\nimport React, { CSSProperties, ReactElement, cloneElement } from \"react\";\nimport { TabLabelFactory } from \"../stack\";\nimport {\n getPersistentState,\n hasPersistentState,\n setPersistentState,\n} from \"../use-persistent-state\";\nimport { expandFlex, followPathToParent, getProps, typeOf } from \"../utils\";\nimport { layoutType } from \"./layoutTypes\";\n\ninterface ComponentWithId {\n id: string;\n [key: string]: unknown;\n}\n\nexport const getManagedDimension = (\n style: CSSProperties,\n): [dimension, dimension] =>\n style.flexDirection === \"column\" ? [\"height\", \"width\"] : [\"width\", \"height\"];\n\nconst theKidHasNoStyle: CSSProperties = {};\n\nexport const applyLayoutProps = (component: ReactElement, path = \"0\") => {\n const [layoutProps, children] = getChildLayoutProps(\n typeOf(component) as string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n component.props as any,\n path,\n );\n return React.cloneElement(component, layoutProps, children);\n};\n\nexport interface LayoutProps extends ComponentWithId {\n active?: number;\n \"data-path\"?: string;\n children?: ReactElement[];\n column?: boolean;\n dropTarget?: boolean;\n key: string;\n layout?: LayoutJSON;\n path?: string;\n resizeable?: boolean;\n style: CSSProperties;\n type?: string;\n version?: number;\n}\n\n/**\n * parse the declarative JSX and clone adding layout attributes\n */\nexport const cloneElementAddLayoutProps = (\n layoutElement: ReactElement,\n previousLayout?: ReactElement,\n): ReactElement => {\n const type = typeOf(layoutElement) as string;\n const [layoutProps, children] = getChildLayoutProps(\n type,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n layoutElement.props as any,\n \"0\",\n undefined,\n previousLayout,\n );\n return cloneElement(layoutElement, layoutProps, children);\n};\n\nexport const applyLayout = (\n type: layoutType,\n props: LayoutProps,\n previousLayout?: LayoutModel,\n): LayoutModel => {\n const [layoutProps, children] = getChildLayoutProps(\n type,\n props,\n \"0\",\n undefined,\n previousLayout,\n );\n return {\n ...props,\n ...layoutProps,\n type,\n children,\n };\n};\n\nfunction getLayoutProps(\n type: string,\n props: LayoutProps,\n path = \"0\",\n parentType: string | null = null,\n previousLayout?: LayoutModel,\n): LayoutProps {\n const {\n active: prevActive = 0,\n \"data-path\": dataPath,\n path: prevPath = dataPath,\n id: prevId,\n style: prevStyle,\n } = getProps(previousLayout);\n\n const prevMatch = typeOf(previousLayout) === type && path === prevPath;\n const id = prevMatch ? prevId : (props.id ?? uuid());\n const active = type === \"Stack\" ? (props.active ?? prevActive) : undefined;\n\n const key = id;\n const style = prevMatch ? prevStyle : getStyle(type, props, parentType);\n return isLayoutComponent(type)\n ? { id, key, path, style, type, active }\n : { id, key, style, \"data-path\": path };\n}\n\nfunction getChildLayoutProps(\n type: string,\n props: LayoutProps,\n path: string,\n parentType: string | null = null,\n previousLayout?: LayoutModel,\n): [LayoutProps, ReactElement[]] {\n const layoutProps = getLayoutProps(\n type,\n props,\n path,\n parentType,\n previousLayout,\n );\n\n if (props.layout && !previousLayout) {\n return [layoutProps, [layoutFromJson(props.layout, `${path}.0`)]];\n }\n\n const previousChildren =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (previousLayout as any)?.children ??\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (previousLayout as any)?.props?.children;\n const hasDynamicChildren = props.dropTarget && previousChildren;\n const children = hasDynamicChildren\n ? previousChildren\n : getLayoutChildren(type, props.children, path, previousChildren);\n return [layoutProps, children];\n}\n\nfunction getLayoutChildren(\n type: string,\n children?: ReactElement[],\n path = \"0\",\n previousChildren?: ReactElement[],\n) {\n const kids = Array.isArray(children)\n ? children\n : React.isValidElement(children)\n ? [children]\n : [];\n return isContainer(type)\n ? kids.map((child, i) => {\n const childType = typeOf(child) as string;\n const previousType = typeOf(previousChildren?.[i]);\n\n if (!previousType || childType === previousType) {\n const [layoutProps, children] = getChildLayoutProps(\n childType,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n child.props as any,\n `${path}.${i}`,\n type,\n previousChildren?.[i],\n );\n return React.cloneElement(child, layoutProps, children);\n }\n\n return previousChildren?.[i];\n })\n : children;\n}\n\nconst getStyle = (\n type: string,\n props: LayoutProps,\n parentType?: string | null,\n) => {\n let { style = theKidHasNoStyle } = props;\n if (type === \"Flexbox\") {\n style = {\n flexDirection: props.column ? \"column\" : \"row\",\n ...style,\n display: \"flex\",\n };\n }\n\n if (style.flex) {\n const { flex, ...otherStyles } = style;\n style = {\n ...otherStyles,\n ...expandFlex(typeof flex === \"number\" ? flex : 0),\n };\n } else if (parentType === \"Stack\") {\n style = {\n ...style,\n ...expandFlex(1),\n };\n } else if (\n parentType === \"Flexbox\" &&\n (style.width || style.height) &&\n style.flexBasis === undefined\n ) {\n style = {\n ...style,\n flexBasis: \"auto\",\n flexGrow: 0,\n flexShrink: 0,\n };\n }\n\n return style;\n};\n\nexport function layoutFromJson(\n { active, id = uuid(), type, children, props, state }: LayoutJSON,\n path: string,\n): ReactElement {\n const componentType = type.match(/^[a-z]/) ? type : getLayoutComponent(type);\n\n if (componentType === undefined) {\n throw Error(\n `layoutUtils unable to create component from JSON, unknown type ${type}`,\n );\n }\n\n if (state) {\n setPersistentState(id, state);\n }\n\n return React.createElement(\n componentType,\n {\n active,\n id,\n ...props,\n key: id,\n path,\n },\n children\n ? children.map((child, i) => layoutFromJson(child, `${path}.${i}`))\n : undefined,\n );\n}\n\nexport function layoutToJSON(component: ReactElement) {\n return componentToJson(component);\n}\n\nexport function componentToJson(component: ReactElement): LayoutJSON {\n const type = typeOf(component) as string;\n const { id, children, type: _omit, ...props } = getProps(component);\n\n const state = hasPersistentState(id) ? getPersistentState(id) : undefined;\n\n return {\n id,\n type,\n props: serializeProps(props as LayoutProps),\n state,\n children: React.Children.map(children, componentToJson),\n };\n}\n\nexport function serializeProps(props?: LayoutProps) {\n if (props) {\n const { path, ...otherProps } = props;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const result: { [key: string]: any } = {};\n for (const [key, value] of Object.entries(otherProps)) {\n result[key] = serializeValue(value);\n }\n return result;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction serializeValue(value: unknown): any {\n if (\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\"\n ) {\n return value;\n } else if (Array.isArray(value)) {\n return value.map(serializeValue);\n } else if (typeof value === \"object\" && value !== null) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const result: { [key: string]: any } = {};\n for (const [k, v] of Object.entries(value)) {\n result[k] = serializeValue(v);\n }\n return result;\n }\n}\n\n// This is experimental and the only query we support to start off with is\n// PARENT_CONTAINER\nexport type LayoutQuery = \"PARENT_CONTAINER\";\n\nexport const layoutQuery = (\n query: LayoutQuery,\n path?: string,\n layoutRoot?: ReactElement,\n) => {\n if (path && layoutRoot) {\n const parentElement = followPathToParent(layoutRoot, path);\n if (parentElement) {\n const { id: parentContainerId } = getProps(parentElement);\n const parentContainerType = typeOf(parentElement);\n return {\n parentContainerId,\n parentContainerType,\n };\n }\n return {\n parentContainerType: \"Stack\",\n parentContainerId: \"blah\",\n };\n }\n};\n\nexport const getDefaultTabLabel: TabLabelFactory = (\n component,\n tabIndex,\n existingLabels = [],\n): string => {\n let label =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (component.props as any)?.title ??\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (component.props as any)?.[\"data-tab-title\"] ??\n existingLabels[tabIndex];\n if (label) {\n return label;\n } else {\n let count = tabIndex;\n do {\n label = `Tab ${++count}`;\n } while (existingLabels.includes(label));\n return label;\n }\n};\n"],"names":["children"],"mappings":";;;;;;;;AAwBO,MAAM,mBAAsB,GAAA,CACjC,KAEA,KAAA,KAAA,CAAM,aAAkB,KAAA,QAAA,GAAW,CAAC,QAAA,EAAU,OAAO,CAAA,GAAI,CAAC,OAAA,EAAS,QAAQ;AAE7E,MAAM,mBAAkC,EAAC;AAElC,MAAM,gBAAmB,GAAA,CAAC,SAAyB,EAAA,IAAA,GAAO,GAAQ,KAAA;AACvE,EAAM,MAAA,CAAC,WAAa,EAAA,QAAQ,CAAI,GAAA,mBAAA;AAAA,IAC9B,OAAO,SAAS,CAAA;AAAA;AAAA,IAEhB,SAAU,CAAA,KAAA;AAAA,IACV;AAAA,GACF;AACA,EAAA,OAAO,KAAM,CAAA,YAAA,CAAa,SAAW,EAAA,WAAA,EAAa,QAAQ,CAAA;AAC5D;AAoBa,MAAA,0BAAA,GAA6B,CACxC,aAAA,EACA,cACiB,KAAA;AACjB,EAAM,MAAA,IAAA,GAAO,OAAO,aAAa,CAAA;AACjC,EAAM,MAAA,CAAC,WAAa,EAAA,QAAQ,CAAI,GAAA,mBAAA;AAAA,IAC9B,IAAA;AAAA;AAAA,IAEA,aAAc,CAAA,KAAA;AAAA,IACd,GAAA;AAAA,IACA,KAAA,CAAA;AAAA,IACA;AAAA,GACF;AACA,EAAO,OAAA,YAAA,CAAa,aAAe,EAAA,WAAA,EAAa,QAAQ,CAAA;AAC1D;AAEO,MAAM,WAAc,GAAA,CACzB,IACA,EAAA,KAAA,EACA,cACgB,KAAA;AAChB,EAAM,MAAA,CAAC,WAAa,EAAA,QAAQ,CAAI,GAAA,mBAAA;AAAA,IAC9B,IAAA;AAAA,IACA,KAAA;AAAA,IACA,GAAA;AAAA,IACA,KAAA,CAAA;AAAA,IACA;AAAA,GACF;AACA,EA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AAI,SAAS,aAAa,CAAA;AACxD,MAAM,MAAA,mBAAA,GAAsB,OAAO,aAAa,CAAA;AAChD,MAAO,OAAA;AAAA,QACL,iBAAA;AAAA,QACA;AAAA,OACF;AAAA;AAEF,IAAO,OAAA;AAAA,MACL,mBAAqB,EAAA,OAAA;AAAA,MACrB,iBAAmB,EAAA;AAAA,KACrB;AAAA;AAEJ;AAEO,MAAM,qBAAsC,CACjD,SAAA,EACA,QACA,EAAA,cAAA,GAAiB,EACN,KAAA;AACX,EAAI,IAAA,KAAA;AAAA;AAAA,IAED,UAAU,KAAe,EAAA,KAAA;AAAA,IAEzB,SAAU,CAAA,KAAA,GAAgB,gBAAgB,CAAA,IAC3C,eAAe,QAAQ;AAAA,GAAA;AACzB,EAAA,IAAI,KAAO,EAAA;AACT,IAAO,OAAA,KAAA;AAAA,GACF,MAAA;AACL,IAAA,IAAI,KAAQ,GAAA,QAAA;AACZ,IAAG,GAAA;AACD,MAAQ,KAAA,GAAA,CAAA,IAAA,EAAO,EAAE,KAAK,CAAA,CAAA;AAAA,KACxB,QAAS,cAAe,CAAA,QAAA,CAAS,KAAK,CAAA;AACtC,IAAO,OAAA,KAAA;AAAA;AAEX;;;;"}
@@ -1,29 +0,0 @@
1
- import { cloneElement } from 'react';
2
- import { followPath } from '../utils/pathUtils.js';
3
- import { getProps } from '../utils/propUtils.js';
4
- import { swapChild } from './replace-layout-element.js';
5
-
6
- function moveChild(layoutRoot, { fromIndex, path, toIndex }) {
7
- const target = followPath(layoutRoot, path, true);
8
- const { children } = getProps(target);
9
- const replacementChildren = moveChildWithinChildren(
10
- children,
11
- fromIndex,
12
- toIndex
13
- );
14
- const replacement = cloneElement(target, void 0, replacementChildren);
15
- return swapChild(layoutRoot, target, replacement);
16
- }
17
- function moveChildWithinChildren(children, fromIndex, toIndex) {
18
- const newChildren = children.slice();
19
- const [child] = newChildren.splice(fromIndex, 1);
20
- if (toIndex === -1) {
21
- return newChildren.concat(child);
22
- } else {
23
- newChildren.splice(toIndex, 0, child);
24
- return newChildren;
25
- }
26
- }
27
-
28
- export { moveChild };
29
- //# sourceMappingURL=move-layout-element.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"move-layout-element.js","sources":["../../src/layout-reducer/move-layout-element.ts"],"sourcesContent":["import { cloneElement, ReactElement } from \"react\";\nimport { followPath, getProps } from \"../utils\";\nimport { MoveChildAction } from \"./layoutTypes\";\nimport { swapChild } from \"./replace-layout-element\";\n\nexport function moveChild(\n layoutRoot: ReactElement,\n { fromIndex, path, toIndex }: MoveChildAction\n) {\n const target = followPath(layoutRoot, path, true);\n const { children } = getProps(target);\n const replacementChildren = moveChildWithinChildren(\n children,\n fromIndex,\n toIndex\n );\n const replacement = cloneElement(target, undefined, replacementChildren);\n return swapChild(layoutRoot, target, replacement);\n}\n\nfunction moveChildWithinChildren(\n children: ReactElement[],\n fromIndex: number,\n toIndex: number\n) {\n const newChildren = children.slice();\n const [child] = newChildren.splice(fromIndex, 1);\n if (toIndex === -1) {\n return newChildren.concat(child);\n } else {\n newChildren.splice(toIndex, 0, child);\n return newChildren;\n }\n}\n"],"names":[],"mappings":";;;;;AAKO,SAAS,UACd,UACA,EAAA,EAAE,SAAW,EAAA,IAAA,EAAM,SACnB,EAAA;AACA,EAAA,MAAM,MAAS,GAAA,UAAA,CAAW,UAAY,EAAA,IAAA,EAAM,IAAI,CAAA;AAChD,EAAA,MAAM,EAAE,QAAA,EAAa,GAAA,QAAA,CAAS,MAAM,CAAA;AACpC,EAAA,MAAM,mBAAsB,GAAA,uBAAA;AAAA,IAC1B,QAAA;AAAA,IACA,SAAA;AAAA,IACA;AAAA,GACF;AACA,EAAA,MAAM,WAAc,GAAA,YAAA,CAAa,MAAQ,EAAA,KAAA,CAAA,EAAW,mBAAmB,CAAA;AACvE,EAAO,OAAA,SAAA,CAAU,UAAY,EAAA,MAAA,EAAQ,WAAW,CAAA;AAClD;AAEA,SAAS,uBAAA,CACP,QACA,EAAA,SAAA,EACA,OACA,EAAA;AACA,EAAM,MAAA,WAAA,GAAc,SAAS,KAAM,EAAA;AACnC,EAAA,MAAM,CAAC,KAAK,CAAA,GAAI,WAAY,CAAA,MAAA,CAAO,WAAW,CAAC,CAAA;AAC/C,EAAA,IAAI,YAAY,CAAI,CAAA,EAAA;AAClB,IAAO,OAAA,WAAA,CAAY,OAAO,KAAK,CAAA;AAAA,GAC1B,MAAA;AACL,IAAY,WAAA,CAAA,MAAA,CAAO,OAAS,EAAA,CAAA,EAAG,KAAK,CAAA;AACpC,IAAO,OAAA,WAAA;AAAA;AAEX;;;;"}