@vuu-ui/vuu-layout 0.13.7 → 0.13.8

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,235 +0,0 @@
1
- import { VuuShellLocation } from '@vuu-ui/vuu-utils';
2
- import React from 'react';
3
- import { followPath, followPathToParent, nextStep, resetPath } from '../utils/pathUtils.js';
4
- import { getProps, getProp } from '../utils/propUtils.js';
5
- import { typeOf } from '../utils/typeOf.js';
6
- import { createPlaceHolder } from './flexUtils.js';
7
- import { layoutFromJson } from './layoutUtils.js';
8
- import { swapChild } from './replace-layout-element.js';
9
-
10
- function removeChild(layoutRoot, { path }) {
11
- const target = followPath(layoutRoot, path);
12
- let targetParent = followPathToParent(layoutRoot, path);
13
- if (targetParent === null) {
14
- return layoutRoot;
15
- }
16
- const { children } = getProps(targetParent);
17
- if (
18
- // this is very specific to explicitly sized components
19
- children.length > 1 && typeOf(targetParent) !== "Stack" && allOtherChildrenArePlaceholders(children, path)
20
- ) {
21
- const {
22
- style: { flexBasis, display, flexDirection, ...style }
23
- } = getProps(targetParent);
24
- let containerPath = getProp(targetParent, "path");
25
- let newLayout = swapChild(
26
- layoutRoot,
27
- targetParent,
28
- createPlaceHolder(containerPath, flexBasis, style)
29
- );
30
- while (targetParent = followPathToParent(newLayout, containerPath)) {
31
- if (getProp(targetParent, "path") === "0") {
32
- break;
33
- }
34
- const { children: children2 } = getProps(targetParent);
35
- if (allOtherChildrenArePlaceholders(children2)) {
36
- containerPath = getProp(targetParent, "path");
37
- const {
38
- style: { flexBasis: flexBasis2, display: display2, flexDirection: flexDirection2, ...style2 }
39
- } = getProps(targetParent);
40
- newLayout = swapChild(
41
- layoutRoot,
42
- targetParent,
43
- createPlaceHolder(containerPath, flexBasis2, style2)
44
- );
45
- } else if (hasAdjacentPlaceholders(children2)) {
46
- newLayout = collapsePlaceholders(
47
- layoutRoot,
48
- targetParent
49
- );
50
- } else {
51
- break;
52
- }
53
- }
54
- return newLayout;
55
- }
56
- return _removeChild(layoutRoot, target);
57
- }
58
- function _removeChild(container, child) {
59
- const props = getProps(container);
60
- const { children: componentChildren, path, preserve } = props;
61
- let { active, id: containerId } = props;
62
- const { idx, finalStep } = nextStep(path, getProp(child, "path"));
63
- const type = typeOf(container);
64
- let children = componentChildren.slice();
65
- if (finalStep) {
66
- children.splice(idx, 1);
67
- if (active !== void 0 && active >= idx) {
68
- active = Math.max(0, active - 1);
69
- }
70
- if (children.length === 0 && preserve && type === "Stack") {
71
- const {
72
- path: path2,
73
- style: { flexBasis }
74
- } = getProps(child);
75
- const placeHolder = containerId === VuuShellLocation.Workspace ? layoutFromJson(
76
- {
77
- props: {
78
- style: { flexGrow: 1, flexShrink: 1, flexBasis },
79
- title: "Tab 1"
80
- },
81
- type: "Placeholder"
82
- },
83
- path2
84
- ) : createPlaceHolder(path2, flexBasis);
85
- children.push(placeHolder);
86
- } else if (children.length === 1 && !preserve && path !== "0" && type.match(/Flexbox|Stack/)) {
87
- return unwrap(container, children[0]);
88
- }
89
- if (!children.some(isFlexible) && children.some(canBeMadeFlexible)) {
90
- children = makeFlexible(children);
91
- }
92
- } else {
93
- children[idx] = _removeChild(children[idx], child);
94
- }
95
- children = children.map((child2, i) => resetPath(child2, `${path}.${i}`));
96
- return React.cloneElement(container, { active }, children);
97
- }
98
- function unwrap(container, child) {
99
- const type = typeOf(container);
100
- const {
101
- path,
102
- style: { flexBasis, flexGrow, flexShrink, width, height }
103
- } = getProps(container);
104
- let unwrappedChild = resetPath(child, path);
105
- if (path === "0") {
106
- unwrappedChild = React.cloneElement(unwrappedChild, {
107
- style: {
108
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
109
- ...child.props.style,
110
- width,
111
- height
112
- }
113
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
114
- });
115
- } else if (type === "Flexbox") {
116
- const dim = (
117
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
118
- container.props.style.flexDirection === "column" ? "height" : "width"
119
- );
120
- const {
121
- style: { [dim]: size, ...style }
122
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
123
- } = unwrappedChild.props;
124
- unwrappedChild = React.cloneElement(unwrappedChild, {
125
- flexFill: void 0,
126
- style: {
127
- ...style,
128
- flexGrow,
129
- flexShrink,
130
- flexBasis,
131
- width,
132
- height
133
- }
134
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
135
- });
136
- }
137
- return unwrappedChild;
138
- }
139
- const isFlexible = (element) => {
140
- return element.props.style?.flexGrow > 0;
141
- };
142
- const canBeMadeFlexible = (element) => {
143
- if (element.props.style) {
144
- const { width, height, flexGrow } = element.props.style;
145
- return flexGrow === 0 && typeof width !== "number" && typeof height !== "number";
146
- } else {
147
- return false;
148
- }
149
- };
150
- const makeFlexible = (children) => {
151
- return children.map(
152
- (child) => canBeMadeFlexible(child) ? React.cloneElement(child, {
153
- style: {
154
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
155
- ...child.props.style,
156
- flexGrow: 1
157
- }
158
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
159
- }) : child
160
- );
161
- };
162
- const hasAdjacentPlaceholders = (children) => {
163
- if (children && children.length > 0) {
164
- let wasPlaceholder = getProp(children[0], "placeholder");
165
- let isPlaceholder = false;
166
- for (let i = 1; i < children.length; i++) {
167
- isPlaceholder = getProp(children[i], "placeholder");
168
- if (wasPlaceholder && isPlaceholder) {
169
- return true;
170
- }
171
- wasPlaceholder = isPlaceholder;
172
- }
173
- }
174
- };
175
- const collapsePlaceholders = (container, target) => {
176
- const { children: componentChildren, path } = getProps(container);
177
- const { idx, finalStep } = nextStep(path, getProp(target, "path"));
178
- let children = componentChildren.slice();
179
- if (finalStep) {
180
- children[idx] = _collapsePlaceHolders(target);
181
- } else {
182
- children[idx] = collapsePlaceholders(children[idx], target);
183
- }
184
- children = children.map((child, i) => resetPath(child, `${path}.${i}`));
185
- return React.cloneElement(container, void 0, children);
186
- };
187
- const _collapsePlaceHolders = (container) => {
188
- const { children } = getProps(container);
189
- const newChildren = [];
190
- const placeholders = [];
191
- for (let i = 0; i < children.length; i++) {
192
- if (getProp(children[i], "placeholder")) {
193
- placeholders.push(children[i]);
194
- } else {
195
- if (placeholders.length === 1) {
196
- newChildren.push(placeholders.pop());
197
- } else if (placeholders.length > 0) {
198
- newChildren.push(mergePlaceholders(placeholders));
199
- placeholders.length = 0;
200
- }
201
- newChildren.push(children[i]);
202
- }
203
- }
204
- if (placeholders.length === 1) {
205
- newChildren.push(placeholders.pop());
206
- } else if (placeholders.length > 0) {
207
- newChildren.push(mergePlaceholders(placeholders));
208
- }
209
- const containerPath = getProp(container, "path");
210
- return React.cloneElement(
211
- container,
212
- void 0,
213
- newChildren.map((child, i) => resetPath(child, `${containerPath}.${i}`))
214
- );
215
- };
216
- const mergePlaceholders = ([placeholder, ...placeholders]) => {
217
- const targetStyle = getProp(placeholder, "style");
218
- let { flexBasis, flexGrow, flexShrink } = targetStyle;
219
- for (const placeholder2 of placeholders) {
220
- const { style } = placeholder2.props;
221
- flexBasis += style.flexBasis;
222
- flexGrow = Math.max(flexGrow, style.flexGrow);
223
- flexShrink = Math.max(flexShrink, style.flexShrink);
224
- }
225
- return React.cloneElement(placeholder, {
226
- style: { ...targetStyle, flexBasis, flexGrow, flexShrink }
227
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
228
- });
229
- };
230
- const allOtherChildrenArePlaceholders = (children, path) => children.every(
231
- (child) => getProp(child, "placeholder") || path && getProp(child, "path") === path
232
- );
233
-
234
- export { removeChild };
235
- //# sourceMappingURL=remove-layout-element.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"remove-layout-element.js","sources":["../../src/layout-reducer/remove-layout-element.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-non-null-assertion */\nimport { VuuShellLocation } from \"@vuu-ui/vuu-utils\";\nimport React, { ReactElement } from \"react\";\nimport {\n followPath,\n followPathToParent,\n getProp,\n getProps,\n nextStep,\n resetPath,\n typeOf,\n} from \"../utils\";\nimport { createPlaceHolder } from \"./flexUtils\";\nimport { RemoveAction } from \"./layoutTypes\";\nimport { layoutFromJson } from \"./layoutUtils\";\nimport { swapChild } from \"./replace-layout-element\";\n\nexport function removeChild(layoutRoot: ReactElement, { path }: RemoveAction) {\n const target = followPath(layoutRoot, path!) as ReactElement;\n let targetParent = followPathToParent(layoutRoot, path!);\n if (targetParent === null) {\n return layoutRoot;\n }\n const { children } = getProps(targetParent);\n if (\n // this is very specific to explicitly sized components\n children.length > 1 &&\n typeOf(targetParent) !== \"Stack\" &&\n allOtherChildrenArePlaceholders(children, path)\n ) {\n const {\n style: { flexBasis, display, flexDirection, ...style },\n } = getProps(targetParent);\n let containerPath = getProp(targetParent, \"path\");\n let newLayout = swapChild(\n layoutRoot,\n targetParent,\n createPlaceHolder(containerPath, flexBasis, style),\n );\n while ((targetParent = followPathToParent(newLayout, containerPath))) {\n if (getProp(targetParent, \"path\") === \"0\") {\n break;\n }\n const { children } = getProps(targetParent);\n if (allOtherChildrenArePlaceholders(children)) {\n containerPath = getProp(targetParent, \"path\");\n const {\n style: { flexBasis, display, flexDirection, ...style },\n } = getProps(targetParent);\n newLayout = swapChild(\n layoutRoot,\n targetParent,\n createPlaceHolder(containerPath, flexBasis, style),\n );\n } else if (hasAdjacentPlaceholders(children)) {\n newLayout = collapsePlaceholders(\n layoutRoot,\n targetParent as ReactElement,\n );\n } else {\n break;\n }\n }\n return newLayout;\n }\n return _removeChild(layoutRoot, target);\n}\n\nfunction _removeChild(\n container: ReactElement,\n child: ReactElement,\n): ReactElement {\n const props = getProps(container);\n const { children: componentChildren, path, preserve } = props;\n let { active, id: containerId } = props;\n const { idx, finalStep } = nextStep(path, getProp(child, \"path\"));\n const type = typeOf(container) as string;\n let children = componentChildren.slice() as ReactElement[];\n\n if (finalStep) {\n children.splice(idx, 1);\n\n if (active !== undefined && active >= idx) {\n active = Math.max(0, active - 1);\n }\n\n if (children.length === 0 && preserve && type === \"Stack\") {\n const {\n path,\n style: { flexBasis },\n } = getProps(child);\n const placeHolder =\n containerId === VuuShellLocation.Workspace\n ? layoutFromJson(\n {\n props: {\n style: { flexGrow: 1, flexShrink: 1, flexBasis },\n title: \"Tab 1\",\n },\n type: \"Placeholder\",\n },\n path,\n )\n : createPlaceHolder(path, flexBasis);\n children.push(placeHolder);\n } else if (\n children.length === 1 &&\n !preserve &&\n path !== \"0\" &&\n type.match(/Flexbox|Stack/)\n ) {\n return unwrap(container, children[0]);\n }\n\n if (!children.some(isFlexible) && children.some(canBeMadeFlexible)) {\n children = makeFlexible(children);\n }\n } else {\n children[idx] = _removeChild(children[idx], child) as ReactElement;\n }\n\n children = children.map((child, i) => resetPath(child, `${path}.${i}`));\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return React.cloneElement(container, { active } as any, children);\n}\n\nfunction unwrap(container: ReactElement, child: ReactElement) {\n const type = typeOf(container);\n const {\n path,\n style: { flexBasis, flexGrow, flexShrink, width, height },\n } = getProps(container);\n\n let unwrappedChild = resetPath(child, path);\n if (path === \"0\") {\n unwrappedChild = React.cloneElement(unwrappedChild, {\n style: {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ...(child.props as any).style,\n width,\n height,\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any);\n } else if (type === \"Flexbox\") {\n const dim =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (container.props as any).style.flexDirection === \"column\"\n ? \"height\"\n : \"width\";\n const {\n style: { [dim]: size, ...style },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } = unwrappedChild.props as any;\n unwrappedChild = React.cloneElement(unwrappedChild, {\n flexFill: undefined,\n style: {\n ...style,\n flexGrow,\n flexShrink,\n flexBasis,\n width,\n height,\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any);\n }\n return unwrappedChild;\n}\n\nconst isFlexible = (element: ReactElement) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (element.props as any).style?.flexGrow > 0;\n};\n\nconst canBeMadeFlexible = (element: ReactElement) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((element.props as any).style) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const { width, height, flexGrow } = (element.props as any).style;\n return (\n flexGrow === 0 && typeof width !== \"number\" && typeof height !== \"number\"\n );\n } else {\n return false;\n }\n};\n\nconst makeFlexible = (children: ReactElement[]) => {\n return children.map((child) =>\n canBeMadeFlexible(child)\n ? React.cloneElement(child, {\n style: {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ...(child.props as any).style,\n flexGrow: 1,\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any)\n : child,\n );\n};\n\nconst hasAdjacentPlaceholders = (children: ReactElement[]) => {\n if (children && children.length > 0) {\n let wasPlaceholder = getProp(children[0], \"placeholder\");\n let isPlaceholder = false;\n for (let i = 1; i < children.length; i++) {\n isPlaceholder = getProp(children[i], \"placeholder\");\n if (wasPlaceholder && isPlaceholder) {\n return true;\n }\n wasPlaceholder = isPlaceholder;\n }\n }\n};\n\nconst collapsePlaceholders = (\n container: ReactElement,\n target: ReactElement,\n) => {\n const { children: componentChildren, path } = getProps(container);\n const { idx, finalStep } = nextStep(path, getProp(target, \"path\"));\n let children = componentChildren.slice() as ReactElement[];\n if (finalStep) {\n children[idx] = _collapsePlaceHolders(target);\n } else {\n children[idx] = collapsePlaceholders(children[idx], target) as ReactElement;\n }\n\n children = children.map((child, i) => resetPath(child, `${path}.${i}`));\n return React.cloneElement(container, undefined, children);\n};\n\nconst _collapsePlaceHolders = (container: ReactElement) => {\n const { children } = getProps(container);\n const newChildren = [];\n const placeholders: ReactElement[] = [];\n\n for (let i = 0; i < children.length; i++) {\n if (getProp(children[i], \"placeholder\")) {\n placeholders.push(children[i]);\n } else {\n if (placeholders.length === 1) {\n newChildren.push(placeholders.pop());\n } else if (placeholders.length > 0) {\n newChildren.push(mergePlaceholders(placeholders));\n placeholders.length = 0;\n }\n newChildren.push(children[i]);\n }\n }\n\n if (placeholders.length === 1) {\n newChildren.push(placeholders.pop());\n } else if (placeholders.length > 0) {\n newChildren.push(mergePlaceholders(placeholders));\n }\n\n const containerPath = getProp(container, \"path\");\n return React.cloneElement(\n container,\n undefined,\n newChildren.map((child, i) => resetPath(child, `${containerPath}.${i}`)),\n );\n};\n\nconst mergePlaceholders = ([placeholder, ...placeholders]: ReactElement[]) => {\n const targetStyle = getProp(placeholder, \"style\");\n let { flexBasis, flexGrow, flexShrink } = targetStyle;\n for (const placeholder of placeholders) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const { style } = placeholder.props as any;\n flexBasis += style.flexBasis;\n flexGrow = Math.max(flexGrow, style.flexGrow);\n flexShrink = Math.max(flexShrink, style.flexShrink);\n }\n return React.cloneElement(placeholder, {\n style: { ...targetStyle, flexBasis, flexGrow, flexShrink },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any);\n};\n\nconst allOtherChildrenArePlaceholders = (\n children: ReactElement[],\n path?: string,\n) =>\n children.every(\n (child) =>\n getProp(child, \"placeholder\") ||\n (path && getProp(child, \"path\") === path),\n );\n"],"names":["children","flexBasis","display","flexDirection","style","path","child","placeholder"],"mappings":";;;;;;;;;AAiBO,SAAS,WAAY,CAAA,UAAA,EAA0B,EAAE,IAAA,EAAsB,EAAA;AAC5E,EAAM,MAAA,MAAA,GAAS,UAAW,CAAA,UAAA,EAAY,IAAK,CAAA;AAC3C,EAAI,IAAA,YAAA,GAAe,kBAAmB,CAAA,UAAA,EAAY,IAAK,CAAA;AACvD,EAAA,IAAI,iBAAiB,IAAM,EAAA;AACzB,IAAO,OAAA,UAAA;AAAA;AAET,EAAA,MAAM,EAAE,QAAA,EAAa,GAAA,QAAA,CAAS,YAAY,CAAA;AAC1C,EAAA;AAAA;AAAA,IAEE,QAAA,CAAS,SAAS,CAClB,IAAA,MAAA,CAAO,YAAY,CAAM,KAAA,OAAA,IACzB,+BAAgC,CAAA,QAAA,EAAU,IAAI;AAAA,IAC9C;AACA,IAAM,MAAA;AAAA,MACJ,OAAO,EAAE,SAAA,EAAW,OAAS,EAAA,aAAA,EAAe,GAAG,KAAM;AAAA,KACvD,GAAI,SAAS,YAAY,CAAA;AACzB,IAAI,IAAA,aAAA,GAAgB,OAAQ,CAAA,YAAA,EAAc,MAAM,CAAA;AAChD,IAAA,IAAI,SAAY,GAAA,SAAA;AAAA,MACd,UAAA;AAAA,MACA,YAAA;AAAA,MACA,iBAAA,CAAkB,aAAe,EAAA,SAAA,EAAW,KAAK;AAAA,KACnD;AACA,IAAA,OAAQ,YAAe,GAAA,kBAAA,CAAmB,SAAW,EAAA,aAAa,CAAI,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AAI,CAAC,CAAA,CAAE,CAAC;AAAA,GACzE;AACF,CAAA;AAEA,MAAM,iBAAoB,GAAA,CAAC,CAAC,WAAA,EAAgB,eAAY,CAAsB,KAAA;AAC5E,EAAM,MAAA,WAAA,GAAc,OAAQ,CAAA,WAAA,EAAa,OAAO,CAAA;AAChD,EAAA,IAAI,EAAE,SAAA,EAAW,QAAU,EAAA,UAAA,EAAe,GAAA,WAAA;AAC1C,EAAA,KAAA,MAAWC,gBAAe,YAAc,EAAA;AAEtC,IAAM,MAAA,EAAE,KAAM,EAAA,GAAIA,YAAY,CAAA,KAAA;AAC9B,IAAA,SAAA,IAAa,KAAM,CAAA,SAAA;AACnB,IAAA,QAAA,GAAW,IAAK,CAAA,GAAA,CAAI,QAAU,EAAA,KAAA,CAAM,QAAQ,CAAA;AAC5C,IAAA,UAAA,GAAa,IAAK,CAAA,GAAA,CAAI,UAAY,EAAA,KAAA,CAAM,UAAU,CAAA;AAAA;AAEpD,EAAO,OAAA,KAAA,CAAM,aAAa,WAAa,EAAA;AAAA,IACrC,OAAO,EAAE,GAAG,WAAa,EAAA,SAAA,EAAW,UAAU,UAAW;AAAA;AAAA,GAEnD,CAAA;AACV,CAAA;AAEA,MAAM,+BAAkC,GAAA,CACtC,QACA,EAAA,IAAA,KAEA,QAAS,CAAA,KAAA;AAAA,EACP,CAAC,KACC,KAAA,OAAA,CAAQ,KAAO,EAAA,aAAa,KAC3B,IAAQ,IAAA,OAAA,CAAQ,KAAO,EAAA,MAAM,CAAM,KAAA;AACxC,CAAA;;;;"}
@@ -1,92 +0,0 @@
1
- import React from 'react';
2
- import { nextStep } from '../utils/pathUtils.js';
3
- import { getProp, getProps } from '../utils/propUtils.js';
4
- import { applyLayoutProps } from './layoutUtils.js';
5
-
6
- function replaceChild(model, { target, replacement }) {
7
- return _replaceChild(model, target, replacement);
8
- }
9
- function _replaceChild(model, child, replacement) {
10
- const path = getProp(child, "path");
11
- const resizeable = getProp(child, "resizeable");
12
- const { style } = getProps(child);
13
- const newChild = applyLayoutProps(
14
- React.cloneElement(replacement, {
15
- resizeable,
16
- style: {
17
- ...style,
18
- ...replacement.props.style
19
- }
20
- }),
21
- path
22
- );
23
- return swapChild(model, child, newChild);
24
- }
25
- function swapChild(model, child, replacement, op) {
26
- if (model === child) {
27
- return replacement;
28
- }
29
- const { idx, finalStep } = nextStep(
30
- getProp(model, "path"),
31
- getProp(child, "path")
32
- );
33
- const modelChildren = model.props.children;
34
- const children = modelChildren.slice();
35
- if (finalStep) {
36
- if (!op) {
37
- children[idx] = replacement;
38
- } else if (op === "collapse") {
39
- children[idx] = collapse(model, children[idx]);
40
- } else if (op === "expand") {
41
- children[idx] = expand(children[idx]);
42
- }
43
- } else {
44
- children[idx] = swapChild(children[idx], child, replacement, op);
45
- }
46
- return React.cloneElement(model, void 0, children);
47
- }
48
- function collapse(parent, child) {
49
- const { style: parentStyle } = getProps(parent);
50
- const { style: childStyle } = getProps(child);
51
- const { width, height, flexBasis, flexShrink, flexGrow, ...rest } = childStyle;
52
- const restoreStyle = {
53
- width,
54
- height,
55
- flexBasis,
56
- flexShrink,
57
- flexGrow
58
- };
59
- const style = {
60
- ...rest,
61
- flexBasis: 0,
62
- flexGrow: 0,
63
- flexShrink: 0
64
- };
65
- const collapsed = parentStyle.flexDirection === "row" ? "vertical" : parentStyle.flexDirection === "column" ? "horizontal" : false;
66
- if (collapsed) {
67
- return React.cloneElement(child, {
68
- collapsed,
69
- restoreStyle,
70
- style
71
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
72
- });
73
- }
74
- return child;
75
- }
76
- function expand(child) {
77
- const { style: childStyle, restoreStyle } = getProps(child);
78
- const { flexBasis, flexShrink, flexGrow, ...rest } = childStyle;
79
- const style = {
80
- ...rest,
81
- ...restoreStyle
82
- };
83
- return React.cloneElement(child, {
84
- collapsed: false,
85
- style,
86
- restoreStyle: void 0
87
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
88
- });
89
- }
90
-
91
- export { _replaceChild, replaceChild, swapChild };
92
- //# sourceMappingURL=replace-layout-element.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"replace-layout-element.js","sources":["../../src/layout-reducer/replace-layout-element.ts"],"sourcesContent":["import React, { ReactElement } from \"react\";\nimport { getProp, getProps, nextStep } from \"../utils\";\nimport { ReplaceAction } from \"./layoutTypes\";\nimport { applyLayoutProps, LayoutProps } from \"./layoutUtils\";\n\nexport function replaceChild(\n model: ReactElement,\n { target, replacement }: ReplaceAction,\n) {\n return _replaceChild(model, target, replacement);\n}\n\nexport function _replaceChild(\n model: ReactElement,\n child: ReactElement,\n replacement: ReactElement<LayoutProps>,\n) {\n const path = getProp(child, \"path\");\n const resizeable = getProp(child, \"resizeable\");\n const { style } = getProps(child);\n const newChild = applyLayoutProps(\n React.cloneElement(replacement, {\n resizeable,\n style: {\n ...style,\n ...replacement.props.style,\n },\n }),\n path,\n );\n\n return swapChild(model, child, newChild);\n}\n\nexport function swapChild(\n model: ReactElement,\n child: ReactElement,\n replacement: ReactElement,\n op?: \"collapse\" | \"expand\",\n): ReactElement {\n if (model === child) {\n return replacement;\n }\n\n const { idx, finalStep } = nextStep(\n getProp(model, \"path\"),\n getProp(child, \"path\"),\n );\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const modelChildren = (model.props as any).children as ReactElement[];\n const children = modelChildren.slice();\n\n if (finalStep) {\n if (!op) {\n children[idx] = replacement;\n } else if (op === \"collapse\") {\n children[idx] = collapse(model, children[idx]);\n } else if (op === \"expand\") {\n children[idx] = expand(children[idx]);\n }\n } else {\n children[idx] = swapChild(children[idx], child, replacement, op);\n }\n return React.cloneElement(model, undefined, children);\n}\n\nfunction collapse(parent: ReactElement, child: ReactElement) {\n const { style: parentStyle } = getProps(parent);\n const { style: childStyle } = getProps(child);\n\n const { width, height, flexBasis, flexShrink, flexGrow, ...rest } =\n childStyle;\n\n const restoreStyle = {\n width,\n height,\n flexBasis,\n flexShrink,\n flexGrow,\n };\n\n const style = {\n ...rest,\n flexBasis: 0,\n flexGrow: 0,\n flexShrink: 0,\n };\n const collapsed =\n parentStyle.flexDirection === \"row\"\n ? \"vertical\"\n : parentStyle.flexDirection === \"column\"\n ? \"horizontal\"\n : false;\n\n if (collapsed) {\n return React.cloneElement(child, {\n collapsed,\n restoreStyle,\n style,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any);\n }\n return child;\n}\n\nfunction expand(child: ReactElement) {\n const { style: childStyle, restoreStyle } = getProps(child);\n\n const { flexBasis, flexShrink, flexGrow, ...rest } = childStyle;\n\n const style = {\n ...rest,\n ...restoreStyle,\n };\n\n return React.cloneElement(child, {\n collapsed: false,\n style,\n restoreStyle: undefined,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any);\n}\n"],"names":[],"mappings":";;;;;AAKO,SAAS,YACd,CAAA,KAAA,EACA,EAAE,MAAA,EAAQ,aACV,EAAA;AACA,EAAO,OAAA,aAAA,CAAc,KAAO,EAAA,MAAA,EAAQ,WAAW,CAAA;AACjD;AAEgB,SAAA,aAAA,CACd,KACA,EAAA,KAAA,EACA,WACA,EAAA;AACA,EAAM,MAAA,IAAA,GAAO,OAAQ,CAAA,KAAA,EAAO,MAAM,CAAA;AAClC,EAAM,MAAA,UAAA,GAAa,OAAQ,CAAA,KAAA,EAAO,YAAY,CAAA;AAC9C,EAAA,MAAM,EAAE,KAAA,EAAU,GAAA,QAAA,CAAS,KAAK,CAAA;AAChC,EAAA,MAAM,QAAW,GAAA,gBAAA;AAAA,IACf,KAAA,CAAM,aAAa,WAAa,EAAA;AAAA,MAC9B,UAAA;AAAA,MACA,KAAO,EAAA;AAAA,QACL,GAAG,KAAA;AAAA,QACH,GAAG,YAAY,KAAM,CAAA;AAAA;AACvB,KACD,CAAA;AAAA,IACD;AAAA,GACF;AAEA,EAAO,OAAA,SAAA,CAAU,KAAO,EAAA,KAAA,EAAO,QAAQ,CAAA;AACzC;AAEO,SAAS,SACd,CAAA,KAAA,EACA,KACA,EAAA,WAAA,EACA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;AAEF,EAAA,MAAM,YAAe,GAAA;AAAA,IACnB,KAAA;AAAA,IACA,MAAA;AAAA,IACA,SAAA;AAAA,IACA,UAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,MAAM,KAAQ,GAAA;AAAA,IACZ,GAAG,IAAA;AAAA,IACH,SAAW,EAAA,CAAA;AAAA,IACX,QAAU,EAAA,CAAA;AAAA,IACV,UAAY,EAAA;AAAA,GACd;AACA,EAAM,MAAA,SAAA,GACJ,YAAY,aAAkB,KAAA,KAAA,GAC1B,aACA,WAAY,CAAA,aAAA,KAAkB,WAC5B,YACA,GAAA,KAAA;AAER,EAAA,IAAI,SAAW,EAAA;AACb,IAAO,OAAA,KAAA,CAAM,aAAa,KAAO,EAAA;AAAA,MAC/B,SAAA;AAAA,MACA,YAAA;AAAA,MACA;AAAA;AAAA,KAEM,CAAA;AAAA;AAEV,EAAO,OAAA,KAAA;AACT;AAEA,SAAS,OAAO,KAAqB,EAAA;AACnC,EAAA,MAAM,EAAE,KAAO,EAAA,UAAA,EAAY,YAAa,EAAA,GAAI,SAAS,KAAK,CAAA;AAE1D,EAAA,MAAM,EAAE,SAAW,EAAA,UAAA,EAAY,QAAU,EAAA,GAAG,MAAS,GAAA,UAAA;AAErD,EAAA,MAAM,KAAQ,GAAA;AAAA,IACZ,GAAG,IAAA;AAAA,IACH,GAAG;AAAA,GACL;AAEA,EAAO,OAAA,KAAA,CAAM,aAAa,KAAO,EAAA;AAAA,IAC/B,SAAW,EAAA,KAAA;AAAA,IACX,KAAA;AAAA,IACA,YAAc,EAAA,KAAA;AAAA;AAAA,GAER,CAAA;AACV;;;;"}
@@ -1,59 +0,0 @@
1
- import React 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 resizeFlexChild(layoutRoot, { path, size }) {
7
- const target = followPath(layoutRoot, path, true);
8
- const { style } = getProps(target);
9
- const newStyle = {
10
- ...style,
11
- width: size
12
- };
13
- const replacement = React.cloneElement(target, { style: newStyle });
14
- return swapChild(layoutRoot, target, replacement);
15
- }
16
- function resizeFlexChildren(layoutRoot, { path, sizes }) {
17
- const target = followPath(layoutRoot, path, true);
18
- const { children, style } = getProps(target);
19
- const dimension2 = style.flexDirection === "column" ? "height" : "width";
20
- const replacementChildren = applySizesToChildren(children, sizes, dimension2);
21
- const replacement = React.cloneElement(
22
- target,
23
- void 0,
24
- replacementChildren
25
- );
26
- return swapChild(layoutRoot, target, replacement);
27
- }
28
- function applySizesToChildren(children, sizes, dimension2) {
29
- return children.map((child, i) => {
30
- const {
31
- style: { [dimension2]: size, flexBasis: actualFlexBasis }
32
- } = getProps(child);
33
- const meta = sizes[i];
34
- const { currentSize, flexBasis } = meta;
35
- const hasCurrentSize = currentSize !== void 0;
36
- const newSize = hasCurrentSize ? meta.currentSize : flexBasis;
37
- if (newSize === void 0 || size === newSize || actualFlexBasis === newSize) {
38
- return child;
39
- }
40
- return React.cloneElement(child, {
41
- style: applySizeToChild(child.props.style, dimension2, newSize)
42
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
- });
44
- });
45
- }
46
- function applySizeToChild(style, dimension2, newSize) {
47
- const hasSize = typeof style[dimension2] === "number";
48
- const { flexShrink = 1, flexGrow = 1 } = style;
49
- return {
50
- ...style,
51
- [dimension2]: hasSize ? newSize : "auto",
52
- flexBasis: hasSize ? "auto" : newSize,
53
- flexShrink,
54
- flexGrow
55
- };
56
- }
57
-
58
- export { resizeFlexChild, resizeFlexChildren };
59
- //# sourceMappingURL=resize-flex-children.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resize-flex-children.js","sources":["../../src/layout-reducer/resize-flex-children.ts"],"sourcesContent":["import { dimension } from \"@vuu-ui/vuu-utils\";\nimport React, { CSSProperties, ReactElement } from \"react\";\nimport { followPath, getProps } from \"../utils\";\nimport { LayoutResizeAction, SplitterResizeAction } from \"./layoutTypes\";\nimport { swapChild } from \"./replace-layout-element\";\n\nexport function resizeFlexChild(\n layoutRoot: ReactElement,\n { path, size }: LayoutResizeAction,\n) {\n const target = followPath(layoutRoot, path, true);\n\n const { style } = getProps(target);\n\n const newStyle = {\n ...style,\n width: size,\n };\n\n // const dimension = style.flexDirection === \"column\" ? \"height\" : \"width\";\n // const replacementChildren = applySizesToChildren(children, sizes, dimension);\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const replacement = React.cloneElement(target, { style: newStyle } as any);\n\n return swapChild(layoutRoot, target, replacement);\n}\n\nexport function resizeFlexChildren(\n layoutRoot: ReactElement,\n { path, sizes }: SplitterResizeAction,\n) {\n const target = followPath(layoutRoot, path, true);\n const { children, style } = getProps(target);\n\n const dimension = style.flexDirection === \"column\" ? \"height\" : \"width\";\n const replacementChildren = applySizesToChildren(children, sizes, dimension);\n\n const replacement = React.cloneElement(\n target,\n undefined,\n replacementChildren,\n );\n\n return swapChild(layoutRoot, target, replacement);\n}\n\nfunction applySizesToChildren(\n children: ReactElement[],\n sizes: { currentSize: number; flexBasis: number }[],\n dimension: dimension,\n) {\n return children.map((child, i) => {\n const {\n style: { [dimension]: size, flexBasis: actualFlexBasis },\n } = getProps(child);\n const meta = sizes[i];\n const { currentSize, flexBasis } = meta;\n const hasCurrentSize = currentSize !== undefined;\n const newSize = hasCurrentSize ? meta.currentSize : flexBasis;\n\n if (\n newSize === undefined ||\n size === newSize ||\n actualFlexBasis === newSize\n ) {\n return child;\n }\n return React.cloneElement(child, {\n style: applySizeToChild((child.props as any).style, dimension, newSize),\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any);\n });\n}\n\nfunction applySizeToChild(\n style: CSSProperties,\n dimension: dimension,\n newSize: number,\n) {\n const hasSize = typeof style[dimension] === \"number\";\n const { flexShrink = 1, flexGrow = 1 } = style;\n return {\n ...style,\n [dimension]: hasSize ? newSize : \"auto\",\n flexBasis: hasSize ? \"auto\" : newSize,\n flexShrink,\n flexGrow,\n };\n}\n"],"names":["dimension"],"mappings":";;;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AgB;AAAA,KACzD,GAAI,SAAS,KAAK,CAAA;AAClB,IAAM,MAAA,IAAA,GAAO,MAAM,CAAC,CAAA;AACpB,IAAM,MAAA,EAAE,WAAa,EAAA,SAAA,EAAc,GAAA,IAAA;AACnC,IAAA,MAAM,iBAAiB,WAAgB,KAAA,KAAA,CAAA;AACvC,IAAM,MAAA,OAAA,GAAU,cAAiB,GAAA,IAAA,CAAK,WAAc,GAAA,SAAA;AAEpD,IAAA,IACE,OAAY,KAAA,KAAA,CAAA,IACZ,IAAS,KAAA,OAAA,IACT,oBAAoB,OACpB,EAAA;AACA,MAAO,OAAA,KAAA;AAAA;AAET,IAAO,OAAA,KAAA,CAAM,aAAa,KAAO,EAAA;AAAA,MAC/B,OAAO,gBAAkB,CAAA,KAAA,CAAM,KAAc,CAAA,KAAA,EAAOA,YAAW,OAAO;AAAA;AAAA,KAEhE,CAAA;AAAA,GACT,CAAA;AACH;AAEA,SAAS,gBAAA,CACP,KACAA,EAAAA,UAAAA,EACA,OACA,EAAA;AACA,EAAA,MAAM,OAAU,GAAA,OAAO,KAAMA,CAAAA,UAAS,CAAM,KAAA,QAAA;AAC5C,EAAA,MAAM,EAAE,UAAA,GAAa,CAAG,EAAA,QAAA,GAAW,GAAM,GAAA,KAAA;AACzC,EAAO,OAAA;AAAA,IACL,GAAG,KAAA;AAAA,IACH,CAACA,UAAS,GAAG,OAAA,GAAU,OAAU,GAAA,MAAA;AAAA,IACjC,SAAA,EAAW,UAAU,MAAS,GAAA,OAAA;AAAA,IAC9B,UAAA;AAAA,IACA;AAAA,GACF;AACF;;;;"}
@@ -1,209 +0,0 @@
1
- import { uuid, getLayoutComponent } from '@vuu-ui/vuu-utils';
2
- import React from 'react';
3
- import { nextStep, resetPath } from '../utils/pathUtils.js';
4
- import { getProps, getProp } from '../utils/propUtils.js';
5
- import { typeOf } from '../utils/typeOf.js';
6
- import { getIntrinsicSize, createPlaceHolder, wrapIntrinsicSizeComponentWithFlexbox, createFlexbox, getFlexStyle } from './flexUtils.js';
7
- import { applyLayoutProps } from './layoutUtils.js';
8
-
9
- const isHtmlElement = (component) => {
10
- const [firstLetter] = typeOf(component);
11
- return firstLetter === firstLetter.toLowerCase();
12
- };
13
- function wrap(container, existingComponent, newComponent, pos, clientRect, dropRect) {
14
- const { children: containerChildren, path: containerPath } = getProps(container);
15
- const existingComponentPath = getProp(existingComponent, "path");
16
- const { idx, finalStep } = nextStep(containerPath, existingComponentPath);
17
- const children = finalStep ? updateChildren(
18
- container,
19
- containerChildren,
20
- existingComponent,
21
- newComponent,
22
- pos,
23
- clientRect,
24
- dropRect
25
- ) : containerChildren.map(
26
- (child, index) => index === idx ? wrap(
27
- child,
28
- existingComponent,
29
- newComponent,
30
- pos,
31
- clientRect,
32
- dropRect
33
- ) : child
34
- );
35
- return React.cloneElement(container, void 0, children);
36
- }
37
- function updateChildren(container, containerChildren, existingComponent, newComponent, pos, clientRect, dropRect) {
38
- const intrinsicSize = getIntrinsicSize(newComponent);
39
- if (intrinsicSize?.width && intrinsicSize?.height) {
40
- if (clientRect === void 0 || dropRect === void 0) {
41
- throw Error(
42
- "wrap-layout-element, updateChildren clientRect and dropRect must both be available"
43
- );
44
- }
45
- return wrapIntrinsicSizedComponent(
46
- containerChildren,
47
- existingComponent,
48
- newComponent,
49
- pos,
50
- clientRect,
51
- dropRect
52
- );
53
- }
54
- return wrapFlexComponent(
55
- container,
56
- containerChildren,
57
- existingComponent,
58
- newComponent,
59
- pos
60
- );
61
- }
62
- function wrapFlexComponent(container, containerChildren, existingComponent, newComponent, pos) {
63
- const { version = 0 } = getProps(newComponent);
64
- const { path: existingComponentPath, title } = getProps(existingComponent);
65
- const {
66
- type,
67
- flexDirection: flexDirection2,
68
- showTabs: showTabsProp
69
- } = getLayoutSpecForWrapper(pos);
70
- const [style, existingComponentStyle, newComponentStyle] = getWrappedFlexStyles(
71
- type,
72
- existingComponent,
73
- newComponent,
74
- flexDirection2,
75
- pos
76
- );
77
- const targetFirst = isTargetFirst(pos);
78
- const active = targetFirst ? 1 : 0;
79
- const newComponentProps = {
80
- resizeable: true,
81
- style: newComponentStyle,
82
- version: version + 1
83
- };
84
- const resizeProp = isHtmlElement(existingComponent) ? "data-resizeable" : "resizeable";
85
- const existingComponentProps = {
86
- [resizeProp]: true,
87
- style: existingComponentStyle
88
- };
89
- const showTabs = type === "Stack" ? { showTabs: showTabsProp } : void 0;
90
- const splitterSize = type === "Flexbox" ? {
91
- splitterSize: (typeOf(container) === "Flexbox" && container.props.splitterSize) ?? void 0
92
- } : void 0;
93
- const id = uuid();
94
- const wrapper = React.createElement(
95
- getLayoutComponent(type),
96
- {
97
- active,
98
- id,
99
- key: id,
100
- path: getProp(existingComponent, "path"),
101
- flexFill: getProp(existingComponent, "flexFill"),
102
- ...splitterSize,
103
- ...showTabs,
104
- style,
105
- title,
106
- resizeable: getProp(existingComponent, "resizeable")
107
- },
108
- targetFirst ? [
109
- resetPath(
110
- existingComponent,
111
- `${existingComponentPath}.0`,
112
- existingComponentProps
113
- ),
114
- applyLayoutProps(
115
- React.cloneElement(newComponent, newComponentProps),
116
- `${existingComponentPath}.1`
117
- )
118
- ] : [
119
- applyLayoutProps(
120
- React.cloneElement(newComponent, newComponentProps),
121
- `${existingComponentPath}.0`
122
- ),
123
- resetPath(
124
- existingComponent,
125
- `${existingComponentPath}.1`,
126
- existingComponentProps
127
- )
128
- ]
129
- );
130
- return containerChildren.map(
131
- (child) => child === existingComponent ? wrapper : child
132
- );
133
- }
134
- function wrapIntrinsicSizedComponent(containerChildren, existingComponent, newComponent, pos, clientRect, dropRect) {
135
- const { flexDirection: flexDirection2 } = getLayoutSpecForWrapper(pos);
136
- const contraDirection = flexDirection2 === "column" ? "row" : "column";
137
- const targetFirst = isTargetFirst(pos);
138
- const [dropLeft, dropTop, dropRight, dropBottom] = dropRect;
139
- const [startPlaceholder, endPlaceholder] = flexDirection2 === "column" ? [dropTop - clientRect.top, clientRect.bottom - dropBottom] : [dropLeft - clientRect.left, clientRect.right - dropRight];
140
- const pathRoot = getProp(existingComponent, "path");
141
- let pathIndex = 0;
142
- const resizeProp = isHtmlElement(existingComponent) ? "data-resizeable" : "resizeable";
143
- const wrappedChildren = [];
144
- if (startPlaceholder) {
145
- wrappedChildren.push(
146
- targetFirst ? resetPath(existingComponent, `${pathRoot}.${pathIndex++}`, {
147
- [resizeProp]: true,
148
- style: { flexBasis: startPlaceholder, flexGrow: 1, flexShrink: 1 }
149
- }) : createPlaceHolder(`${pathRoot}.${pathIndex++}`, startPlaceholder, {
150
- flexGrow: 0,
151
- flexShrink: 0
152
- })
153
- );
154
- }
155
- wrappedChildren.push(
156
- wrapIntrinsicSizeComponentWithFlexbox(
157
- newComponent,
158
- contraDirection,
159
- `${pathRoot}.${pathIndex++}`,
160
- clientRect,
161
- dropRect
162
- )
163
- );
164
- if (endPlaceholder) {
165
- wrappedChildren.push(
166
- targetFirst ? createPlaceHolder(`${pathRoot}.${pathIndex++}`, 0) : resetPath(existingComponent, `${pathRoot}.${pathIndex++}`, {
167
- [resizeProp]: true,
168
- style: { flexBasis: 0, flexGrow: 1, flexShrink: 1 }
169
- })
170
- );
171
- }
172
- const wrapper = createFlexbox(
173
- flexDirection2,
174
- existingComponent.props,
175
- wrappedChildren,
176
- pathRoot
177
- );
178
- return containerChildren.map(
179
- (child) => child === existingComponent ? wrapper : child
180
- );
181
- }
182
- function getWrappedFlexStyles(type, existingComponent, newComponent, flexDirection2, pos) {
183
- const style = {
184
- ...existingComponent.props.style,
185
- flexDirection: flexDirection2
186
- };
187
- const dimension = type === "Flexbox" && flexDirection2 === "column" ? "height" : "width";
188
- const newComponentStyle = getFlexStyle(newComponent, dimension, pos);
189
- const existingComponentStyle = getFlexStyle(existingComponent, dimension);
190
- return [style, existingComponentStyle, newComponentStyle];
191
- }
192
- const isTargetFirst = (pos) => pos.position.SouthOrEast ? true : pos?.tab?.positionRelativeToTab === "before" ? false : pos.position.Header ? true : false;
193
- function getLayoutSpecForWrapper(pos) {
194
- if (pos.position.Header) {
195
- return {
196
- type: "Stack",
197
- flexDirection: "column",
198
- showTabs: true
199
- };
200
- } else {
201
- return {
202
- type: "Flexbox",
203
- flexDirection: pos.position.EastOrWest ? "row" : "column"
204
- };
205
- }
206
- }
207
-
208
- export { wrap };
209
- //# sourceMappingURL=wrap-layout-element.js.map