@vuu-ui/vuu-layout 0.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +1 -0
- package/cjs/Component.js +14 -0
- package/cjs/Component.js.map +1 -0
- package/cjs/DraggableLayout.css.js +6 -0
- package/cjs/DraggableLayout.css.js.map +1 -0
- package/cjs/DraggableLayout.js +33 -0
- package/cjs/DraggableLayout.js.map +1 -0
- package/cjs/dock-layout/DockLayout.css.js +6 -0
- package/cjs/dock-layout/DockLayout.css.js.map +1 -0
- package/cjs/dock-layout/DockLayout.js +36 -0
- package/cjs/dock-layout/DockLayout.js.map +1 -0
- package/cjs/dock-layout/Drawer.css.js +6 -0
- package/cjs/dock-layout/Drawer.css.js.map +1 -0
- package/cjs/dock-layout/Drawer.js +96 -0
- package/cjs/dock-layout/Drawer.js.map +1 -0
- package/cjs/drag-drop/BoxModel.js +422 -0
- package/cjs/drag-drop/BoxModel.js.map +1 -0
- package/cjs/drag-drop/DragState.js +154 -0
- package/cjs/drag-drop/DragState.js.map +1 -0
- package/cjs/drag-drop/Draggable.js +192 -0
- package/cjs/drag-drop/Draggable.js.map +1 -0
- package/cjs/drag-drop/DropMenu.css.js +6 -0
- package/cjs/drag-drop/DropMenu.css.js.map +1 -0
- package/cjs/drag-drop/DropMenu.js +55 -0
- package/cjs/drag-drop/DropMenu.js.map +1 -0
- package/cjs/drag-drop/DropTarget.js +244 -0
- package/cjs/drag-drop/DropTarget.js.map +1 -0
- package/cjs/drag-drop/DropTargetRenderer.js +244 -0
- package/cjs/drag-drop/DropTargetRenderer.js.map +1 -0
- package/cjs/flexbox/Flexbox.css.js +6 -0
- package/cjs/flexbox/Flexbox.css.js.map +1 -0
- package/cjs/flexbox/Flexbox.js +70 -0
- package/cjs/flexbox/Flexbox.js.map +1 -0
- package/cjs/flexbox/FlexboxLayout.js +30 -0
- package/cjs/flexbox/FlexboxLayout.js.map +1 -0
- package/cjs/flexbox/FluidGrid.css.js +6 -0
- package/cjs/flexbox/FluidGrid.css.js.map +1 -0
- package/cjs/flexbox/FluidGrid.js +87 -0
- package/cjs/flexbox/FluidGrid.js.map +1 -0
- package/cjs/flexbox/FluidGridLayout.js +14 -0
- package/cjs/flexbox/FluidGridLayout.js.map +1 -0
- package/cjs/flexbox/Splitter.css.js +6 -0
- package/cjs/flexbox/Splitter.css.js.map +1 -0
- package/cjs/flexbox/Splitter.js +122 -0
- package/cjs/flexbox/Splitter.js.map +1 -0
- package/cjs/flexbox/flexbox-utils.js +109 -0
- package/cjs/flexbox/flexbox-utils.js.map +1 -0
- package/cjs/flexbox/useResponsiveSizing.js +62 -0
- package/cjs/flexbox/useResponsiveSizing.js.map +1 -0
- package/cjs/flexbox/useSplitterResizing.js +209 -0
- package/cjs/flexbox/useSplitterResizing.js.map +1 -0
- package/cjs/index.js +133 -0
- package/cjs/index.js.map +1 -0
- package/cjs/layout-action.js +27 -0
- package/cjs/layout-action.js.map +1 -0
- package/cjs/layout-header/Header.css.js +6 -0
- package/cjs/layout-header/Header.css.js.map +1 -0
- package/cjs/layout-header/Header.js +131 -0
- package/cjs/layout-header/Header.js.map +1 -0
- package/cjs/layout-provider/LayoutProvider.js +178 -0
- package/cjs/layout-provider/LayoutProvider.js.map +1 -0
- package/cjs/layout-provider/LayoutProviderContext.js +14 -0
- package/cjs/layout-provider/LayoutProviderContext.js.map +1 -0
- package/cjs/layout-provider/useLayoutDragDrop.js +172 -0
- package/cjs/layout-provider/useLayoutDragDrop.js.map +1 -0
- package/cjs/layout-reducer/flexUtils.js +219 -0
- package/cjs/layout-reducer/flexUtils.js.map +1 -0
- package/cjs/layout-reducer/insert-layout-element.js +273 -0
- package/cjs/layout-reducer/insert-layout-element.js.map +1 -0
- package/cjs/layout-reducer/layout-reducer.js +198 -0
- package/cjs/layout-reducer/layout-reducer.js.map +1 -0
- package/cjs/layout-reducer/layoutTypes.js +41 -0
- package/cjs/layout-reducer/layoutTypes.js.map +1 -0
- package/cjs/layout-reducer/layoutUtils.js +226 -0
- package/cjs/layout-reducer/layoutUtils.js.map +1 -0
- package/cjs/layout-reducer/move-layout-element.js +31 -0
- package/cjs/layout-reducer/move-layout-element.js.map +1 -0
- package/cjs/layout-reducer/remove-layout-element.js +223 -0
- package/cjs/layout-reducer/remove-layout-element.js.map +1 -0
- package/cjs/layout-reducer/replace-layout-element.js +91 -0
- package/cjs/layout-reducer/replace-layout-element.js.map +1 -0
- package/cjs/layout-reducer/resize-flex-children.js +61 -0
- package/cjs/layout-reducer/resize-flex-children.js.map +1 -0
- package/cjs/layout-reducer/wrap-layout-element.js +212 -0
- package/cjs/layout-reducer/wrap-layout-element.js.map +1 -0
- package/cjs/layout-view/View.css.js +6 -0
- package/cjs/layout-view/View.css.js.map +1 -0
- package/cjs/layout-view/View.js +164 -0
- package/cjs/layout-view/View.js.map +1 -0
- package/cjs/layout-view/useView.js +92 -0
- package/cjs/layout-view/useView.js.map +1 -0
- package/cjs/layout-view/useViewResize.js +42 -0
- package/cjs/layout-view/useViewResize.js.map +1 -0
- package/cjs/layout-view-actions/ViewContext.js +16 -0
- package/cjs/layout-view-actions/ViewContext.js.map +1 -0
- package/cjs/layout-view-actions/useViewActionDispatcher.js +103 -0
- package/cjs/layout-view-actions/useViewActionDispatcher.js.map +1 -0
- package/cjs/palette/Palette.css.js +6 -0
- package/cjs/palette/Palette.css.js.map +1 -0
- package/cjs/palette/Palette.js +127 -0
- package/cjs/palette/Palette.js.map +1 -0
- package/cjs/placeholder/LayoutStartPanel.css.js +6 -0
- package/cjs/placeholder/LayoutStartPanel.css.js.map +1 -0
- package/cjs/placeholder/LayoutStartPanel.js +60 -0
- package/cjs/placeholder/LayoutStartPanel.js.map +1 -0
- package/cjs/placeholder/Placeholder.css.js +6 -0
- package/cjs/placeholder/Placeholder.css.js.map +1 -0
- package/cjs/placeholder/Placeholder.js +34 -0
- package/cjs/placeholder/Placeholder.js.map +1 -0
- package/cjs/registry/ComponentRegistry.js +27 -0
- package/cjs/registry/ComponentRegistry.js.map +1 -0
- package/cjs/responsive/breakpoints.js +36 -0
- package/cjs/responsive/breakpoints.js.map +1 -0
- package/cjs/responsive/use-breakpoints.js +76 -0
- package/cjs/responsive/use-breakpoints.js.map +1 -0
- package/cjs/responsive/useResizeObserver.js +118 -0
- package/cjs/responsive/useResizeObserver.js.map +1 -0
- package/cjs/responsive/utils.js +34 -0
- package/cjs/responsive/utils.js.map +1 -0
- package/cjs/stack/Stack.css.js +6 -0
- package/cjs/stack/Stack.css.js.map +1 -0
- package/cjs/stack/Stack.js +148 -0
- package/cjs/stack/Stack.js.map +1 -0
- package/cjs/stack/StackLayout.js +122 -0
- package/cjs/stack/StackLayout.js.map +1 -0
- package/cjs/use-persistent-state.js +109 -0
- package/cjs/use-persistent-state.js.map +1 -0
- package/cjs/utils/pathUtils.js +293 -0
- package/cjs/utils/pathUtils.js.map +1 -0
- package/cjs/utils/propUtils.js +27 -0
- package/cjs/utils/propUtils.js.map +1 -0
- package/cjs/utils/refUtils.js +12 -0
- package/cjs/utils/refUtils.js.map +1 -0
- package/cjs/utils/styleUtils.js +15 -0
- package/cjs/utils/styleUtils.js.map +1 -0
- package/cjs/utils/typeOf.js +27 -0
- package/cjs/utils/typeOf.js.map +1 -0
- package/esm/Component.js +12 -0
- package/esm/Component.js.map +1 -0
- package/esm/DraggableLayout.css.js +4 -0
- package/esm/DraggableLayout.css.js.map +1 -0
- package/esm/DraggableLayout.js +31 -0
- package/esm/DraggableLayout.js.map +1 -0
- package/esm/dock-layout/DockLayout.css.js +4 -0
- package/esm/dock-layout/DockLayout.css.js.map +1 -0
- package/esm/dock-layout/DockLayout.js +34 -0
- package/esm/dock-layout/DockLayout.js.map +1 -0
- package/esm/dock-layout/Drawer.css.js +4 -0
- package/esm/dock-layout/Drawer.css.js.map +1 -0
- package/esm/dock-layout/Drawer.js +94 -0
- package/esm/dock-layout/Drawer.js.map +1 -0
- package/esm/drag-drop/BoxModel.js +415 -0
- package/esm/drag-drop/BoxModel.js.map +1 -0
- package/esm/drag-drop/DragState.js +152 -0
- package/esm/drag-drop/DragState.js.map +1 -0
- package/esm/drag-drop/Draggable.js +190 -0
- package/esm/drag-drop/Draggable.js.map +1 -0
- package/esm/drag-drop/DropMenu.css.js +4 -0
- package/esm/drag-drop/DropMenu.css.js.map +1 -0
- package/esm/drag-drop/DropMenu.js +52 -0
- package/esm/drag-drop/DropMenu.js.map +1 -0
- package/esm/drag-drop/DropTarget.js +240 -0
- package/esm/drag-drop/DropTarget.js.map +1 -0
- package/esm/drag-drop/DropTargetRenderer.js +242 -0
- package/esm/drag-drop/DropTargetRenderer.js.map +1 -0
- package/esm/flexbox/Flexbox.css.js +4 -0
- package/esm/flexbox/Flexbox.css.js.map +1 -0
- package/esm/flexbox/Flexbox.js +68 -0
- package/esm/flexbox/Flexbox.js.map +1 -0
- package/esm/flexbox/FlexboxLayout.js +28 -0
- package/esm/flexbox/FlexboxLayout.js.map +1 -0
- package/esm/flexbox/FluidGrid.css.js +4 -0
- package/esm/flexbox/FluidGrid.css.js.map +1 -0
- package/esm/flexbox/FluidGrid.js +85 -0
- package/esm/flexbox/FluidGrid.js.map +1 -0
- package/esm/flexbox/FluidGridLayout.js +12 -0
- package/esm/flexbox/FluidGridLayout.js.map +1 -0
- package/esm/flexbox/Splitter.css.js +4 -0
- package/esm/flexbox/Splitter.css.js.map +1 -0
- package/esm/flexbox/Splitter.js +120 -0
- package/esm/flexbox/Splitter.js.map +1 -0
- package/esm/flexbox/flexbox-utils.js +103 -0
- package/esm/flexbox/flexbox-utils.js.map +1 -0
- package/esm/flexbox/useResponsiveSizing.js +60 -0
- package/esm/flexbox/useResponsiveSizing.js.map +1 -0
- package/esm/flexbox/useSplitterResizing.js +207 -0
- package/esm/flexbox/useSplitterResizing.js.map +1 -0
- package/esm/index.js +37 -0
- package/esm/index.js.map +1 -0
- package/esm/layout-action.js +25 -0
- package/esm/layout-action.js.map +1 -0
- package/esm/layout-header/Header.css.js +4 -0
- package/esm/layout-header/Header.css.js.map +1 -0
- package/esm/layout-header/Header.js +129 -0
- package/esm/layout-header/Header.js.map +1 -0
- package/esm/layout-provider/LayoutProvider.js +172 -0
- package/esm/layout-provider/LayoutProvider.js.map +1 -0
- package/esm/layout-provider/LayoutProviderContext.js +12 -0
- package/esm/layout-provider/LayoutProviderContext.js.map +1 -0
- package/esm/layout-provider/useLayoutDragDrop.js +170 -0
- package/esm/layout-provider/useLayoutDragDrop.js.map +1 -0
- package/esm/layout-reducer/flexUtils.js +210 -0
- package/esm/layout-reducer/flexUtils.js.map +1 -0
- package/esm/layout-reducer/insert-layout-element.js +269 -0
- package/esm/layout-reducer/insert-layout-element.js.map +1 -0
- package/esm/layout-reducer/layout-reducer.js +196 -0
- package/esm/layout-reducer/layout-reducer.js.map +1 -0
- package/esm/layout-reducer/layoutTypes.js +37 -0
- package/esm/layout-reducer/layoutTypes.js.map +1 -0
- package/esm/layout-reducer/layoutUtils.js +215 -0
- package/esm/layout-reducer/layoutUtils.js.map +1 -0
- package/esm/layout-reducer/move-layout-element.js +29 -0
- package/esm/layout-reducer/move-layout-element.js.map +1 -0
- package/esm/layout-reducer/remove-layout-element.js +221 -0
- package/esm/layout-reducer/remove-layout-element.js.map +1 -0
- package/esm/layout-reducer/replace-layout-element.js +87 -0
- package/esm/layout-reducer/replace-layout-element.js.map +1 -0
- package/esm/layout-reducer/resize-flex-children.js +58 -0
- package/esm/layout-reducer/resize-flex-children.js.map +1 -0
- package/esm/layout-reducer/wrap-layout-element.js +210 -0
- package/esm/layout-reducer/wrap-layout-element.js.map +1 -0
- package/esm/layout-view/View.css.js +4 -0
- package/esm/layout-view/View.css.js.map +1 -0
- package/esm/layout-view/View.js +162 -0
- package/esm/layout-view/View.js.map +1 -0
- package/esm/layout-view/useView.js +90 -0
- package/esm/layout-view/useView.js.map +1 -0
- package/esm/layout-view/useViewResize.js +40 -0
- package/esm/layout-view/useViewResize.js.map +1 -0
- package/esm/layout-view-actions/ViewContext.js +12 -0
- package/esm/layout-view-actions/ViewContext.js.map +1 -0
- package/esm/layout-view-actions/useViewActionDispatcher.js +101 -0
- package/esm/layout-view-actions/useViewActionDispatcher.js.map +1 -0
- package/esm/palette/Palette.css.js +4 -0
- package/esm/palette/Palette.css.js.map +1 -0
- package/esm/palette/Palette.js +124 -0
- package/esm/palette/Palette.js.map +1 -0
- package/esm/placeholder/LayoutStartPanel.css.js +4 -0
- package/esm/placeholder/LayoutStartPanel.css.js.map +1 -0
- package/esm/placeholder/LayoutStartPanel.js +58 -0
- package/esm/placeholder/LayoutStartPanel.js.map +1 -0
- package/esm/placeholder/Placeholder.css.js +4 -0
- package/esm/placeholder/Placeholder.css.js.map +1 -0
- package/esm/placeholder/Placeholder.js +32 -0
- package/esm/placeholder/Placeholder.js.map +1 -0
- package/esm/registry/ComponentRegistry.js +21 -0
- package/esm/registry/ComponentRegistry.js.map +1 -0
- package/esm/responsive/breakpoints.js +33 -0
- package/esm/responsive/breakpoints.js.map +1 -0
- package/esm/responsive/use-breakpoints.js +74 -0
- package/esm/responsive/use-breakpoints.js.map +1 -0
- package/esm/responsive/useResizeObserver.js +112 -0
- package/esm/responsive/useResizeObserver.js.map +1 -0
- package/esm/responsive/utils.js +31 -0
- package/esm/responsive/utils.js.map +1 -0
- package/esm/stack/Stack.css.js +4 -0
- package/esm/stack/Stack.css.js.map +1 -0
- package/esm/stack/Stack.js +146 -0
- package/esm/stack/Stack.js.map +1 -0
- package/esm/stack/StackLayout.js +120 -0
- package/esm/stack/StackLayout.js.map +1 -0
- package/esm/use-persistent-state.js +104 -0
- package/esm/use-persistent-state.js.map +1 -0
- package/esm/utils/pathUtils.js +280 -0
- package/esm/utils/pathUtils.js.map +1 -0
- package/esm/utils/propUtils.js +23 -0
- package/esm/utils/propUtils.js.map +1 -0
- package/esm/utils/refUtils.js +10 -0
- package/esm/utils/refUtils.js.map +1 -0
- package/esm/utils/styleUtils.js +13 -0
- package/esm/utils/styleUtils.js.map +1 -0
- package/esm/utils/typeOf.js +23 -0
- package/esm/utils/typeOf.js.map +1 -0
- package/package.json +43 -0
- package/types/Component.d.ts +7 -0
- package/types/DraggableLayout.d.ts +6 -0
- package/types/debug.d.ts +2 -0
- package/types/dock-layout/DockLayout.d.ts +9 -0
- package/types/dock-layout/Drawer.d.ts +17 -0
- package/types/dock-layout/index.d.ts +2 -0
- package/types/drag-drop/BoxModel.d.ts +143 -0
- package/types/drag-drop/DragState.d.ts +46 -0
- package/types/drag-drop/Draggable.d.ts +24 -0
- package/types/drag-drop/DropMenu.d.ts +9 -0
- package/types/drag-drop/DropTarget.d.ts +61 -0
- package/types/drag-drop/DropTargetRenderer.d.ts +17 -0
- package/types/drag-drop/dragDropTypes.d.ts +51 -0
- package/types/drag-drop/index.d.ts +4 -0
- package/types/flexbox/Flexbox.d.ts +4 -0
- package/types/flexbox/FlexboxLayout.d.ts +6 -0
- package/types/flexbox/FluidGrid.d.ts +6 -0
- package/types/flexbox/FluidGridLayout.d.ts +6 -0
- package/types/flexbox/Splitter.d.ts +12 -0
- package/types/flexbox/flexbox-utils.d.ts +12 -0
- package/types/flexbox/flexboxTypes.d.ts +51 -0
- package/types/flexbox/index.d.ts +4 -0
- package/types/flexbox/useResponsiveSizing.d.ts +10 -0
- package/types/flexbox/useSplitterResizing.d.ts +2 -0
- package/types/index.d.ts +18 -0
- package/types/layout-action.d.ts +22 -0
- package/types/layout-header/ActionButton.d.ts +8 -0
- package/types/layout-header/Header.d.ts +12 -0
- package/types/layout-header/index.d.ts +1 -0
- package/types/layout-provider/LayoutProvider.d.ts +15 -0
- package/types/layout-provider/LayoutProviderContext.d.ts +9 -0
- package/types/layout-provider/index.d.ts +2 -0
- package/types/layout-provider/useLayoutDragDrop.d.ts +4 -0
- package/types/layout-reducer/flexUtils.d.ts +22 -0
- package/types/layout-reducer/index.d.ts +4 -0
- package/types/layout-reducer/insert-layout-element.d.ts +8 -0
- package/types/layout-reducer/layout-reducer.d.ts +3 -0
- package/types/layout-reducer/layoutTypes.d.ts +193 -0
- package/types/layout-reducer/layoutUtils.d.ts +38 -0
- package/types/layout-reducer/move-layout-element.d.ts +3 -0
- package/types/layout-reducer/remove-layout-element.d.ts +3 -0
- package/types/layout-reducer/replace-layout-element.d.ts +6 -0
- package/types/layout-reducer/resize-flex-children.d.ts +4 -0
- package/types/layout-reducer/wrap-layout-element.d.ts +9 -0
- package/types/layout-view/View.d.ts +10 -0
- package/types/layout-view/index.d.ts +2 -0
- package/types/layout-view/useView.d.ts +21 -0
- package/types/layout-view/useViewResize.d.ts +7 -0
- package/types/layout-view/viewTypes.d.ts +21 -0
- package/types/layout-view-actions/ViewContext.d.ts +33 -0
- package/types/layout-view-actions/index.d.ts +2 -0
- package/types/layout-view-actions/useViewActionDispatcher.d.ts +9 -0
- package/types/palette/Palette.d.ts +21 -0
- package/types/palette/index.d.ts +1 -0
- package/types/placeholder/LayoutStartPanel.d.ts +5 -0
- package/types/placeholder/Placeholder.d.ts +17 -0
- package/types/placeholder/index.d.ts +1 -0
- package/types/registry/ComponentRegistry.d.ts +13 -0
- package/types/registry/index.d.ts +1 -0
- package/types/responsive/breakpoints.d.ts +4 -0
- package/types/responsive/index.d.ts +3 -0
- package/types/responsive/measureMinimumNodeSize.d.ts +1 -0
- package/types/responsive/overflowUtils.d.ts +2 -0
- package/types/responsive/use-breakpoints.d.ts +7 -0
- package/types/responsive/useResizeObserver.d.ts +13 -0
- package/types/responsive/utils.d.ts +6 -0
- package/types/stack/Stack.d.ts +3 -0
- package/types/stack/StackLayout.d.ts +6 -0
- package/types/stack/index.d.ts +3 -0
- package/types/stack/stackTypes.d.ts +22 -0
- package/types/tabs/TabPanel.d.ts +7 -0
- package/types/tabs/index.d.ts +1 -0
- package/types/tools/config-wrapper/ConfigWrapper.d.ts +2 -0
- package/types/tools/config-wrapper/index.d.ts +1 -0
- package/types/tools/devtools-box/layout-configurator.d.ts +31 -0
- package/types/tools/devtools-tree/layout-tree-viewer.d.ts +5 -0
- package/types/tools/index.d.ts +3 -0
- package/types/use-persistent-state.d.ts +11 -0
- package/types/utils/index.d.ts +5 -0
- package/types/utils/pathUtils.d.ts +31 -0
- package/types/utils/propUtils.d.ts +5 -0
- package/types/utils/refUtils.d.ts +2 -0
- package/types/utils/styleUtils.d.ts +3 -0
- package/types/utils/typeOf.d.ts +5 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { uuid } from '@vuu-ui/vuu-utils';
|
|
2
|
+
import React, { cloneElement } from 'react';
|
|
3
|
+
import { isContainer, ComponentRegistry, isLayoutComponent } from '../registry/ComponentRegistry.js';
|
|
4
|
+
import { setPersistentState, hasPersistentState, getPersistentState } from '../use-persistent-state.js';
|
|
5
|
+
import { followPathToParent } from '../utils/pathUtils.js';
|
|
6
|
+
import { getProps } from '../utils/propUtils.js';
|
|
7
|
+
import { expandFlex } from '../utils/styleUtils.js';
|
|
8
|
+
import { typeOf } from '../utils/typeOf.js';
|
|
9
|
+
|
|
10
|
+
const getManagedDimension = (style) => style.flexDirection === "column" ? ["height", "width"] : ["width", "height"];
|
|
11
|
+
const theKidHasNoStyle = {};
|
|
12
|
+
const applyLayoutProps = (component, path = "0") => {
|
|
13
|
+
const [layoutProps, children] = getChildLayoutProps(
|
|
14
|
+
typeOf(component),
|
|
15
|
+
component.props,
|
|
16
|
+
path
|
|
17
|
+
);
|
|
18
|
+
return React.cloneElement(component, layoutProps, children);
|
|
19
|
+
};
|
|
20
|
+
const processLayoutElement = (layoutElement, previousLayout) => {
|
|
21
|
+
const type = typeOf(layoutElement);
|
|
22
|
+
const [layoutProps, children] = getChildLayoutProps(
|
|
23
|
+
type,
|
|
24
|
+
layoutElement.props,
|
|
25
|
+
"0",
|
|
26
|
+
void 0,
|
|
27
|
+
previousLayout
|
|
28
|
+
);
|
|
29
|
+
return cloneElement(layoutElement, layoutProps, children);
|
|
30
|
+
};
|
|
31
|
+
const applyLayout = (type, props, previousLayout) => {
|
|
32
|
+
const [layoutProps, children] = getChildLayoutProps(
|
|
33
|
+
type,
|
|
34
|
+
props,
|
|
35
|
+
"0",
|
|
36
|
+
void 0,
|
|
37
|
+
previousLayout
|
|
38
|
+
);
|
|
39
|
+
return {
|
|
40
|
+
...props,
|
|
41
|
+
...layoutProps,
|
|
42
|
+
type,
|
|
43
|
+
children
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
function getLayoutProps(type, props, path = "0", parentType = null, previousLayout) {
|
|
47
|
+
const {
|
|
48
|
+
active: prevActive = 0,
|
|
49
|
+
"data-path": dataPath,
|
|
50
|
+
path: prevPath = dataPath,
|
|
51
|
+
id: prevId,
|
|
52
|
+
style: prevStyle
|
|
53
|
+
} = getProps(previousLayout);
|
|
54
|
+
const prevMatch = typeOf(previousLayout) === type && path === prevPath;
|
|
55
|
+
const id = prevMatch ? prevId : props.id ?? uuid();
|
|
56
|
+
const active = type === "Stack" ? props.active ?? prevActive : void 0;
|
|
57
|
+
const key = id;
|
|
58
|
+
const style = prevMatch ? prevStyle : getStyle(type, props, parentType);
|
|
59
|
+
return isLayoutComponent(type) ? { id, key, path, style, type, active } : { id, key, style, "data-path": path };
|
|
60
|
+
}
|
|
61
|
+
function getChildLayoutProps(type, props, path, parentType = null, previousLayout) {
|
|
62
|
+
const layoutProps = getLayoutProps(
|
|
63
|
+
type,
|
|
64
|
+
props,
|
|
65
|
+
path,
|
|
66
|
+
parentType,
|
|
67
|
+
previousLayout
|
|
68
|
+
);
|
|
69
|
+
if (props.layout && !previousLayout) {
|
|
70
|
+
return [layoutProps, [layoutFromJson(props.layout, `${path}.0`)]];
|
|
71
|
+
}
|
|
72
|
+
const previousChildren = previousLayout?.children ?? previousLayout?.props?.children;
|
|
73
|
+
const hasDynamicChildren = props.dropTarget && previousChildren;
|
|
74
|
+
const children = hasDynamicChildren ? previousChildren : getLayoutChildren(type, props.children, path, previousChildren);
|
|
75
|
+
return [layoutProps, children];
|
|
76
|
+
}
|
|
77
|
+
function getLayoutChildren(type, children, path = "0", previousChildren) {
|
|
78
|
+
const kids = Array.isArray(children) ? children : React.isValidElement(children) ? [children] : [];
|
|
79
|
+
return isContainer(type) ? kids.map((child, i) => {
|
|
80
|
+
const childType = typeOf(child);
|
|
81
|
+
const previousType = typeOf(previousChildren?.[i]);
|
|
82
|
+
if (!previousType || childType === previousType) {
|
|
83
|
+
const [layoutProps, children2] = getChildLayoutProps(
|
|
84
|
+
childType,
|
|
85
|
+
child.props,
|
|
86
|
+
`${path}.${i}`,
|
|
87
|
+
type,
|
|
88
|
+
previousChildren?.[i]
|
|
89
|
+
);
|
|
90
|
+
return React.cloneElement(child, layoutProps, children2);
|
|
91
|
+
}
|
|
92
|
+
return previousChildren?.[i];
|
|
93
|
+
}) : children;
|
|
94
|
+
}
|
|
95
|
+
const getStyle = (type, props, parentType) => {
|
|
96
|
+
let { style = theKidHasNoStyle } = props;
|
|
97
|
+
if (type === "Flexbox") {
|
|
98
|
+
style = {
|
|
99
|
+
flexDirection: props.column ? "column" : "row",
|
|
100
|
+
...style,
|
|
101
|
+
display: "flex"
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
if (style.flex) {
|
|
105
|
+
const { flex, ...otherStyles } = style;
|
|
106
|
+
style = {
|
|
107
|
+
...otherStyles,
|
|
108
|
+
...expandFlex(typeof flex === "number" ? flex : 0)
|
|
109
|
+
};
|
|
110
|
+
} else if (parentType === "Stack") {
|
|
111
|
+
style = {
|
|
112
|
+
...style,
|
|
113
|
+
...expandFlex(1)
|
|
114
|
+
};
|
|
115
|
+
} else if (parentType === "Flexbox" && (style.width || style.height) && style.flexBasis === void 0) {
|
|
116
|
+
style = {
|
|
117
|
+
...style,
|
|
118
|
+
flexBasis: "auto",
|
|
119
|
+
flexGrow: 0,
|
|
120
|
+
flexShrink: 0
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return style;
|
|
124
|
+
};
|
|
125
|
+
function layoutFromJson({ id = uuid(), type, children, props, state }, path) {
|
|
126
|
+
const componentType = type.match(/^[a-z]/) ? type : ComponentRegistry[type];
|
|
127
|
+
if (componentType === void 0) {
|
|
128
|
+
throw Error(
|
|
129
|
+
`layoutUtils unable to create component from JSON, unknown type ${type}`
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
if (state) {
|
|
133
|
+
setPersistentState(id, state);
|
|
134
|
+
}
|
|
135
|
+
return React.createElement(
|
|
136
|
+
componentType,
|
|
137
|
+
{
|
|
138
|
+
id,
|
|
139
|
+
...props,
|
|
140
|
+
key: id,
|
|
141
|
+
path
|
|
142
|
+
},
|
|
143
|
+
children ? children.map((child, i) => layoutFromJson(child, `${path}.${i}`)) : void 0
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
function layoutToJSON(component) {
|
|
147
|
+
return componentToJson(component);
|
|
148
|
+
}
|
|
149
|
+
function componentToJson(component) {
|
|
150
|
+
const type = typeOf(component);
|
|
151
|
+
const { id, children, type: _omit, ...props } = getProps(component);
|
|
152
|
+
const state = hasPersistentState(id) ? getPersistentState(id) : void 0;
|
|
153
|
+
return {
|
|
154
|
+
id,
|
|
155
|
+
type,
|
|
156
|
+
props: serializeProps(props),
|
|
157
|
+
state,
|
|
158
|
+
children: React.Children.map(children, componentToJson)
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function serializeProps(props) {
|
|
162
|
+
if (props) {
|
|
163
|
+
const { path, ...otherProps } = props;
|
|
164
|
+
const result = {};
|
|
165
|
+
for (const [key, value] of Object.entries(otherProps)) {
|
|
166
|
+
result[key] = serializeValue(value);
|
|
167
|
+
}
|
|
168
|
+
return result;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function serializeValue(value) {
|
|
172
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
173
|
+
return value;
|
|
174
|
+
} else if (Array.isArray(value)) {
|
|
175
|
+
return value.map(serializeValue);
|
|
176
|
+
} else if (typeof value === "object" && value !== null) {
|
|
177
|
+
const result = {};
|
|
178
|
+
for (const [k, v] of Object.entries(value)) {
|
|
179
|
+
result[k] = serializeValue(v);
|
|
180
|
+
}
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const layoutQuery = (query, path, layoutRoot) => {
|
|
185
|
+
if (path && layoutRoot) {
|
|
186
|
+
const parentElement = followPathToParent(layoutRoot, path);
|
|
187
|
+
if (parentElement) {
|
|
188
|
+
const { id: parentContainerId } = getProps(parentElement);
|
|
189
|
+
const parentContainerType = typeOf(parentElement);
|
|
190
|
+
return {
|
|
191
|
+
parentContainerId,
|
|
192
|
+
parentContainerType
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
parentContainerType: "Stack",
|
|
197
|
+
parentContainerId: "blah"
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
const getDefaultTabLabel = (component, tabIndex, existingLabels = []) => {
|
|
202
|
+
let label = component.props?.title ?? component.props?.["data-tab-title"];
|
|
203
|
+
if (label) {
|
|
204
|
+
return label;
|
|
205
|
+
} else {
|
|
206
|
+
let count = tabIndex;
|
|
207
|
+
do {
|
|
208
|
+
label = `Tab ${++count}`;
|
|
209
|
+
} while (existingLabels.includes(label));
|
|
210
|
+
return label;
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
export { applyLayout, applyLayoutProps, componentToJson, getDefaultTabLabel, getManagedDimension, layoutFromJson, layoutQuery, layoutToJSON, processLayoutElement, serializeProps };
|
|
215
|
+
//# sourceMappingURL=layoutUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layoutUtils.js","sources":["../../src/layout-reducer/layoutUtils.ts"],"sourcesContent":["import { dimension, uuid } from \"@vuu-ui/vuu-utils\";\nimport React, { cloneElement, CSSProperties, ReactElement } from \"react\";\nimport {\n ComponentWithId,\n ComponentRegistry,\n isContainer,\n isLayoutComponent,\n} from \"../registry/ComponentRegistry\";\nimport { TabLabelFactory } from \"../stack\";\nimport {\n getPersistentState,\n hasPersistentState,\n setPersistentState,\n} from \"../use-persistent-state\";\nimport { expandFlex, followPathToParent, getProps, typeOf } from \"../utils\";\nimport { LayoutJSON, LayoutModel, layoutType } from \"./layoutTypes\";\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 component.props,\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?: any;\n dropTarget?: any;\n key: string;\n layout?: any;\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 processLayoutElement = (\n layoutElement: ReactElement,\n previousLayout?: ReactElement\n): ReactElement => {\n const type = typeOf(layoutElement) as string;\n const [layoutProps, children] = getChildLayoutProps(\n type,\n layoutElement.props,\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 (previousLayout as any)?.children ?? previousLayout?.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 child.props,\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 { id = uuid(), type, children, props, state }: LayoutJSON,\n path: string\n): ReactElement {\n const componentType = type.match(/^[a-z]/) ? type : ComponentRegistry[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 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 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\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 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 = component.props?.title ?? component.props?.[\"data-tab-title\"];\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":";;;;;;;;;AAiBO,MAAM,mBAAsB,GAAA,CACjC,KAEA,KAAA,KAAA,CAAM,aAAkB,KAAA,QAAA,GAAW,CAAC,QAAA,EAAU,OAAO,CAAA,GAAI,CAAC,OAAA,EAAS,QAAQ,EAAA;AAE7E,MAAM,mBAAkC,EAAC,CAAA;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,IAChB,SAAU,CAAA,KAAA;AAAA,IACV,IAAA;AAAA,GACF,CAAA;AACA,EAAA,OAAO,KAAM,CAAA,YAAA,CAAa,SAAW,EAAA,WAAA,EAAa,QAAQ,CAAA,CAAA;AAC5D,EAAA;AAoBa,MAAA,oBAAA,GAAuB,CAClC,aAAA,EACA,cACiB,KAAA;AACjB,EAAM,MAAA,IAAA,GAAO,OAAO,aAAa,CAAA,CAAA;AACjC,EAAM,MAAA,CAAC,WAAa,EAAA,QAAQ,CAAI,GAAA,mBAAA;AAAA,IAC9B,IAAA;AAAA,IACA,aAAc,CAAA,KAAA;AAAA,IACd,GAAA;AAAA,IACA,KAAA,CAAA;AAAA,IACA,cAAA;AAAA,GACF,CAAA;AACA,EAAO,OAAA,YAAA,CAAa,aAAe,EAAA,WAAA,EAAa,QAAQ,CAAA,CAAA;AAC1D,EAAA;AAEO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D,MAAQ,KAAA,GAAA,CAAA,IAAA,EAAO,EAAE,KAAK,CAAA,CAAA,CAAA;AAAA,KACxB,QAAS,cAAe,CAAA,QAAA,CAAS,KAAK,CAAA,EAAA;AACtC,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AACF;;;;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,CAAA;AAChD,EAAA,MAAM,EAAE,QAAA,EAAa,GAAA,QAAA,CAAS,MAAM,CAAA,CAAA;AACpC,EAAA,MAAM,mBAAsB,GAAA,uBAAA;AAAA,IAC1B,QAAA;AAAA,IACA,SAAA;AAAA,IACA,OAAA;AAAA,GACF,CAAA;AACA,EAAA,MAAM,WAAc,GAAA,YAAA,CAAa,MAAQ,EAAA,KAAA,CAAA,EAAW,mBAAmB,CAAA,CAAA;AACvE,EAAO,OAAA,SAAA,CAAU,UAAY,EAAA,MAAA,EAAQ,WAAW,CAAA,CAAA;AAClD,CAAA;AAEA,SAAS,uBAAA,CACP,QACA,EAAA,SAAA,EACA,OACA,EAAA;AACA,EAAM,MAAA,WAAA,GAAc,SAAS,KAAM,EAAA,CAAA;AACnC,EAAA,MAAM,CAAC,KAAK,CAAA,GAAI,WAAY,CAAA,MAAA,CAAO,WAAW,CAAC,CAAA,CAAA;AAC/C,EAAA,IAAI,YAAY,CAAI,CAAA,EAAA;AAClB,IAAO,OAAA,WAAA,CAAY,OAAO,KAAK,CAAA,CAAA;AAAA,GAC1B,MAAA;AACL,IAAY,WAAA,CAAA,MAAA,CAAO,OAAS,EAAA,CAAA,EAAG,KAAK,CAAA,CAAA;AACpC,IAAO,OAAA,WAAA,CAAA;AAAA,GACT;AACF;;;;"}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { createPlaceHolder } from './flexUtils.js';
|
|
3
|
+
import { layoutFromJson } from './layoutUtils.js';
|
|
4
|
+
import { swapChild } from './replace-layout-element.js';
|
|
5
|
+
import { followPath, followPathToParent, nextStep, resetPath } from '../utils/pathUtils.js';
|
|
6
|
+
import { getProps, getProp } from '../utils/propUtils.js';
|
|
7
|
+
import { typeOf } from '../utils/typeOf.js';
|
|
8
|
+
|
|
9
|
+
function removeChild(layoutRoot, { path }) {
|
|
10
|
+
const target = followPath(layoutRoot, path);
|
|
11
|
+
let targetParent = followPathToParent(layoutRoot, path);
|
|
12
|
+
if (targetParent === null) {
|
|
13
|
+
return layoutRoot;
|
|
14
|
+
}
|
|
15
|
+
const { children } = getProps(targetParent);
|
|
16
|
+
if (
|
|
17
|
+
// this is very specific to explicitly sized components
|
|
18
|
+
children.length > 1 && typeOf(targetParent) !== "Stack" && allOtherChildrenArePlaceholders(children, path)
|
|
19
|
+
) {
|
|
20
|
+
const {
|
|
21
|
+
style: { flexBasis, display, flexDirection, ...style }
|
|
22
|
+
} = getProps(targetParent);
|
|
23
|
+
let containerPath = getProp(targetParent, "path");
|
|
24
|
+
let newLayout = swapChild(
|
|
25
|
+
layoutRoot,
|
|
26
|
+
targetParent,
|
|
27
|
+
createPlaceHolder(containerPath, flexBasis, style)
|
|
28
|
+
);
|
|
29
|
+
while (targetParent = followPathToParent(newLayout, containerPath)) {
|
|
30
|
+
if (getProp(targetParent, "path") === "0") {
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
const { children: children2 } = getProps(targetParent);
|
|
34
|
+
if (allOtherChildrenArePlaceholders(children2)) {
|
|
35
|
+
containerPath = getProp(targetParent, "path");
|
|
36
|
+
const {
|
|
37
|
+
style: { flexBasis: flexBasis2, display: display2, flexDirection: flexDirection2, ...style2 }
|
|
38
|
+
} = getProps(targetParent);
|
|
39
|
+
newLayout = swapChild(
|
|
40
|
+
layoutRoot,
|
|
41
|
+
targetParent,
|
|
42
|
+
createPlaceHolder(containerPath, flexBasis2, style2)
|
|
43
|
+
);
|
|
44
|
+
} else if (hasAdjacentPlaceholders(children2)) {
|
|
45
|
+
newLayout = collapsePlaceholders(
|
|
46
|
+
layoutRoot,
|
|
47
|
+
targetParent
|
|
48
|
+
);
|
|
49
|
+
} else {
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return newLayout;
|
|
54
|
+
}
|
|
55
|
+
return _removeChild(layoutRoot, target);
|
|
56
|
+
}
|
|
57
|
+
function _removeChild(container, child) {
|
|
58
|
+
const props = getProps(container);
|
|
59
|
+
const { children: componentChildren, path, preserve } = props;
|
|
60
|
+
let { active, id: containerId } = props;
|
|
61
|
+
const { idx, finalStep } = nextStep(path, getProp(child, "path"));
|
|
62
|
+
const type = typeOf(container);
|
|
63
|
+
let children = componentChildren.slice();
|
|
64
|
+
if (finalStep) {
|
|
65
|
+
children.splice(idx, 1);
|
|
66
|
+
if (active !== void 0 && active >= idx) {
|
|
67
|
+
active = Math.max(0, active - 1);
|
|
68
|
+
}
|
|
69
|
+
if (children.length === 0 && preserve && type === "Stack") {
|
|
70
|
+
const {
|
|
71
|
+
path: path2,
|
|
72
|
+
style: { flexBasis }
|
|
73
|
+
} = getProps(child);
|
|
74
|
+
const placeHolder = containerId === "main-tabs" ? layoutFromJson(
|
|
75
|
+
{
|
|
76
|
+
props: {
|
|
77
|
+
style: { flexGrow: 1, flexShrink: 1, flexBasis },
|
|
78
|
+
title: "Tab 1"
|
|
79
|
+
},
|
|
80
|
+
type: "Placeholder"
|
|
81
|
+
},
|
|
82
|
+
path2
|
|
83
|
+
) : createPlaceHolder(path2, flexBasis);
|
|
84
|
+
children.push(placeHolder);
|
|
85
|
+
} else if (children.length === 1 && !preserve && path !== "0" && type.match(/Flexbox|Stack/)) {
|
|
86
|
+
return unwrap(container, children[0]);
|
|
87
|
+
}
|
|
88
|
+
if (!children.some(isFlexible) && children.some(canBeMadeFlexible)) {
|
|
89
|
+
children = makeFlexible(children);
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
children[idx] = _removeChild(children[idx], child);
|
|
93
|
+
}
|
|
94
|
+
children = children.map((child2, i) => resetPath(child2, `${path}.${i}`));
|
|
95
|
+
return React.cloneElement(container, { active }, children);
|
|
96
|
+
}
|
|
97
|
+
function unwrap(container, child) {
|
|
98
|
+
const type = typeOf(container);
|
|
99
|
+
const {
|
|
100
|
+
path,
|
|
101
|
+
style: { flexBasis, flexGrow, flexShrink, width, height }
|
|
102
|
+
} = getProps(container);
|
|
103
|
+
let unwrappedChild = resetPath(child, path);
|
|
104
|
+
if (path === "0") {
|
|
105
|
+
unwrappedChild = React.cloneElement(unwrappedChild, {
|
|
106
|
+
style: {
|
|
107
|
+
...child.props.style,
|
|
108
|
+
width,
|
|
109
|
+
height
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
} else if (type === "Flexbox") {
|
|
113
|
+
const dim = container.props.style.flexDirection === "column" ? "height" : "width";
|
|
114
|
+
const {
|
|
115
|
+
style: { [dim]: size, ...style }
|
|
116
|
+
} = unwrappedChild.props;
|
|
117
|
+
unwrappedChild = React.cloneElement(unwrappedChild, {
|
|
118
|
+
flexFill: void 0,
|
|
119
|
+
style: {
|
|
120
|
+
...style,
|
|
121
|
+
flexGrow,
|
|
122
|
+
flexShrink,
|
|
123
|
+
flexBasis,
|
|
124
|
+
width,
|
|
125
|
+
height
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return unwrappedChild;
|
|
130
|
+
}
|
|
131
|
+
const isFlexible = (element) => {
|
|
132
|
+
return element.props.style.flexGrow > 0;
|
|
133
|
+
};
|
|
134
|
+
const canBeMadeFlexible = (element) => {
|
|
135
|
+
const { width, height, flexGrow } = element.props.style;
|
|
136
|
+
return flexGrow === 0 && typeof width !== "number" && typeof height !== "number";
|
|
137
|
+
};
|
|
138
|
+
const makeFlexible = (children) => {
|
|
139
|
+
return children.map(
|
|
140
|
+
(child) => canBeMadeFlexible(child) ? React.cloneElement(child, {
|
|
141
|
+
style: {
|
|
142
|
+
...child.props.style,
|
|
143
|
+
flexGrow: 1
|
|
144
|
+
}
|
|
145
|
+
}) : child
|
|
146
|
+
);
|
|
147
|
+
};
|
|
148
|
+
const hasAdjacentPlaceholders = (children) => {
|
|
149
|
+
if (children && children.length > 0) {
|
|
150
|
+
let wasPlaceholder = getProp(children[0], "placeholder");
|
|
151
|
+
let isPlaceholder = false;
|
|
152
|
+
for (let i = 1; i < children.length; i++) {
|
|
153
|
+
isPlaceholder = getProp(children[i], "placeholder");
|
|
154
|
+
if (wasPlaceholder && isPlaceholder) {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
wasPlaceholder = isPlaceholder;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
const collapsePlaceholders = (container, target) => {
|
|
162
|
+
const { children: componentChildren, path } = getProps(container);
|
|
163
|
+
const { idx, finalStep } = nextStep(path, getProp(target, "path"));
|
|
164
|
+
let children = componentChildren.slice();
|
|
165
|
+
if (finalStep) {
|
|
166
|
+
children[idx] = _collapsePlaceHolders(target);
|
|
167
|
+
} else {
|
|
168
|
+
children[idx] = collapsePlaceholders(children[idx], target);
|
|
169
|
+
}
|
|
170
|
+
children = children.map((child, i) => resetPath(child, `${path}.${i}`));
|
|
171
|
+
return React.cloneElement(container, void 0, children);
|
|
172
|
+
};
|
|
173
|
+
const _collapsePlaceHolders = (container) => {
|
|
174
|
+
const { children } = getProps(container);
|
|
175
|
+
const newChildren = [];
|
|
176
|
+
const placeholders = [];
|
|
177
|
+
for (let i = 0; i < children.length; i++) {
|
|
178
|
+
if (getProp(children[i], "placeholder")) {
|
|
179
|
+
placeholders.push(children[i]);
|
|
180
|
+
} else {
|
|
181
|
+
if (placeholders.length === 1) {
|
|
182
|
+
newChildren.push(placeholders.pop());
|
|
183
|
+
} else if (placeholders.length > 0) {
|
|
184
|
+
newChildren.push(mergePlaceholders(placeholders));
|
|
185
|
+
placeholders.length = 0;
|
|
186
|
+
}
|
|
187
|
+
newChildren.push(children[i]);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (placeholders.length === 1) {
|
|
191
|
+
newChildren.push(placeholders.pop());
|
|
192
|
+
} else if (placeholders.length > 0) {
|
|
193
|
+
newChildren.push(mergePlaceholders(placeholders));
|
|
194
|
+
}
|
|
195
|
+
const containerPath = getProp(container, "path");
|
|
196
|
+
return React.cloneElement(
|
|
197
|
+
container,
|
|
198
|
+
void 0,
|
|
199
|
+
newChildren.map((child, i) => resetPath(child, `${containerPath}.${i}`))
|
|
200
|
+
);
|
|
201
|
+
};
|
|
202
|
+
const mergePlaceholders = ([placeholder, ...placeholders]) => {
|
|
203
|
+
const targetStyle = getProp(placeholder, "style");
|
|
204
|
+
let { flexBasis, flexGrow, flexShrink } = targetStyle;
|
|
205
|
+
for (const {
|
|
206
|
+
props: { style }
|
|
207
|
+
} of placeholders) {
|
|
208
|
+
flexBasis += style.flexBasis;
|
|
209
|
+
flexGrow = Math.max(flexGrow, style.flexGrow);
|
|
210
|
+
flexShrink = Math.max(flexShrink, style.flexShrink);
|
|
211
|
+
}
|
|
212
|
+
return React.cloneElement(placeholder, {
|
|
213
|
+
style: { ...targetStyle, flexBasis, flexGrow, flexShrink }
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
const allOtherChildrenArePlaceholders = (children, path) => children.every(
|
|
217
|
+
(child) => getProp(child, "placeholder") || path && getProp(child, "path") === path
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
export { removeChild };
|
|
221
|
+
//# sourceMappingURL=remove-layout-element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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 React, { ReactElement } from \"react\";\nimport { createPlaceHolder } from \"./flexUtils\";\nimport { layoutFromJson } from \"./layoutUtils\";\nimport { swapChild } from \"./replace-layout-element\";\n\nimport {\n followPath,\n followPathToParent,\n getProp,\n getProps,\n nextStep,\n resetPath,\n typeOf,\n} from \"../utils\";\nimport { RemoveAction } from \"./layoutTypes\";\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 === \"main-tabs\"\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 return React.cloneElement(container, { active }, 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 ...child.props.style,\n width,\n height,\n },\n });\n } else if (type === \"Flexbox\") {\n const dim =\n container.props.style.flexDirection === \"column\" ? \"height\" : \"width\";\n const {\n style: { [dim]: size, ...style },\n } = unwrappedChild.props;\n unwrappedChild = React.cloneElement(unwrappedChild, {\n flexFill: undefined,\n style: {\n ...style,\n flexGrow,\n flexShrink,\n flexBasis,\n width,\n height,\n },\n });\n }\n return unwrappedChild;\n}\n\nconst isFlexible = (element: ReactElement) => {\n return element.props.style.flexGrow > 0;\n};\n\nconst canBeMadeFlexible = (element: ReactElement) => {\n const { width, height, flexGrow } = element.props.style;\n return (\n flexGrow === 0 && typeof width !== \"number\" && typeof height !== \"number\"\n );\n};\n\nconst makeFlexible = (children: ReactElement[]) => {\n return children.map((child) =>\n canBeMadeFlexible(child)\n ? React.cloneElement(child, {\n style: {\n ...child.props.style,\n flexGrow: 1,\n },\n })\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 {\n props: { style },\n } of placeholders) {\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 });\n};\n\nconst allOtherChildrenArePlaceholders = (\n children: ReactElement[],\n path?: string\n) =>\n children.every(\n (child) =>\n getProp(child, \"placeholder\") || (path && getProp(child, \"path\") === path)\n );\n"],"names":["children","flexBasis","display","flexDirection","style","path","child"],"mappings":";;;;;;;;AAiBO,SAAS,WAAY,CAAA,UAAA,EAA0B,EAAE,IAAA,EAAsB,EAAA;AAC5E,EAAM,MAAA,MAAA,GAAS,UAAW,CAAA,UAAA,EAAY,IAAK,CAAA,CAAA;AAC3C,EAAI,IAAA,YAAA,GAAe,kBAAmB,CAAA,UAAA,EAAY,IAAK,CAAA,CAAA;AACvD,EAAA,IAAI,iBAAiB,IAAM,EAAA;AACzB,IAAO,OAAA,UAAA,CAAA;AAAA,GACT;AACA,EAAA,MAAM,EAAE,QAAA,EAAa,GAAA,QAAA,CAAS,YAAY,CAAA,CAAA;AAC1C,EAAA;AAAA;AAAA,IAEE,QAAA,CAAS,SAAS,CAClB,IAAA,MAAA,CAAO,YAAY,CAAM,KAAA,OAAA,IACzB,+BAAgC,CAAA,QAAA,EAAU,IAAI,CAAA;AAAA,IAC9C;AACA,IAAM,MAAA;AAAA,MACJ,OAAO,EAAE,SAAA,EAAW,OAAS,EAAA,aAAA,EAAe,GAAG,KAAM,EAAA;AAAA,KACvD,GAAI,SAAS,YAAY,CAAA,CAAA;AACzB,IAAI,IAAA,aAAA,GAAgB,OAAQ,CAAA,YAAA,EAAc,MAAM,CAAA,CAAA;AAChD,IAAA,IAAI,SAAY,GAAA,SAAA;AAAA,MACd,UAAA;AAAA,MACA,YAAA;AAAA,MACA,iBAAA,CAAkB,aAAe,EAAA,SAA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UAAU,UAAW,EAAA;AAAA,GAC1D,CAAA,CAAA;AACH,CAAA,CAAA;AAEA,MAAM,+BAAkC,GAAA,CACtC,QACA,EAAA,IAAA,KAEA,QAAS,CAAA,KAAA;AAAA,EACP,CAAC,KACC,KAAA,OAAA,CAAQ,KAAO,EAAA,aAAa,KAAM,IAAQ,IAAA,OAAA,CAAQ,KAAO,EAAA,MAAM,CAAM,KAAA,IAAA;AACzE,CAAA;;;;"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Action } from '../layout-action.js';
|
|
3
|
+
import { nextStep } from '../utils/pathUtils.js';
|
|
4
|
+
import { getProp, getProps } from '../utils/propUtils.js';
|
|
5
|
+
import { applyLayoutProps } from './layoutUtils.js';
|
|
6
|
+
|
|
7
|
+
function replaceChild(model, { target, replacement }) {
|
|
8
|
+
return _replaceChild(model, target, replacement);
|
|
9
|
+
}
|
|
10
|
+
function _replaceChild(model, child, replacement) {
|
|
11
|
+
const path = getProp(child, "path");
|
|
12
|
+
const resizeable = getProp(child, "resizeable");
|
|
13
|
+
const { style } = getProps(child);
|
|
14
|
+
const newChild = applyLayoutProps(
|
|
15
|
+
React.cloneElement(replacement, {
|
|
16
|
+
resizeable,
|
|
17
|
+
style: {
|
|
18
|
+
...style,
|
|
19
|
+
...replacement.props.style
|
|
20
|
+
}
|
|
21
|
+
}),
|
|
22
|
+
path
|
|
23
|
+
);
|
|
24
|
+
return swapChild(model, child, newChild);
|
|
25
|
+
}
|
|
26
|
+
function swapChild(model, child, replacement, op) {
|
|
27
|
+
if (model === child) {
|
|
28
|
+
return replacement;
|
|
29
|
+
}
|
|
30
|
+
const { idx, finalStep } = nextStep(getProp(model, "path"), getProp(child, "path"));
|
|
31
|
+
const children = model.props.children.slice();
|
|
32
|
+
if (finalStep) {
|
|
33
|
+
if (!op) {
|
|
34
|
+
children[idx] = replacement;
|
|
35
|
+
} else if (op === Action.MINIMIZE) {
|
|
36
|
+
children[idx] = minimize(model, children[idx]);
|
|
37
|
+
} else if (op === Action.RESTORE) {
|
|
38
|
+
children[idx] = restore(children[idx]);
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
children[idx] = swapChild(children[idx], child, replacement, op);
|
|
42
|
+
}
|
|
43
|
+
return React.cloneElement(model, void 0, children);
|
|
44
|
+
}
|
|
45
|
+
function minimize(parent, child) {
|
|
46
|
+
const { style: parentStyle } = getProps(parent);
|
|
47
|
+
const { style: childStyle } = getProps(child);
|
|
48
|
+
const { width, height, flexBasis, flexShrink, flexGrow, ...rest } = childStyle;
|
|
49
|
+
const restoreStyle = {
|
|
50
|
+
width,
|
|
51
|
+
height,
|
|
52
|
+
flexBasis,
|
|
53
|
+
flexShrink,
|
|
54
|
+
flexGrow
|
|
55
|
+
};
|
|
56
|
+
const style = {
|
|
57
|
+
...rest,
|
|
58
|
+
flexBasis: 0,
|
|
59
|
+
flexGrow: 0,
|
|
60
|
+
flexShrink: 0
|
|
61
|
+
};
|
|
62
|
+
const collapsed = parentStyle.flexDirection === "row" ? "vertical" : parentStyle.flexDirection === "column" ? "horizontal" : false;
|
|
63
|
+
if (collapsed) {
|
|
64
|
+
return React.cloneElement(child, {
|
|
65
|
+
collapsed,
|
|
66
|
+
restoreStyle,
|
|
67
|
+
style
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return child;
|
|
71
|
+
}
|
|
72
|
+
function restore(child) {
|
|
73
|
+
const { style: childStyle, restoreStyle } = getProps(child);
|
|
74
|
+
const { flexBasis, flexShrink, flexGrow, ...rest } = childStyle;
|
|
75
|
+
const style = {
|
|
76
|
+
...rest,
|
|
77
|
+
...restoreStyle
|
|
78
|
+
};
|
|
79
|
+
return React.cloneElement(child, {
|
|
80
|
+
collapsed: false,
|
|
81
|
+
style,
|
|
82
|
+
restoreStyle: void 0
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export { _replaceChild, replaceChild, swapChild };
|
|
87
|
+
//# sourceMappingURL=replace-layout-element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replace-layout-element.js","sources":["../../src/layout-reducer/replace-layout-element.ts"],"sourcesContent":["import React, { ReactElement } from 'react';\nimport { Action } from '../layout-action';\nimport { getProp, getProps, nextStep } from '../utils';\nimport { ReplaceAction } from './layoutTypes';\nimport { applyLayoutProps, LayoutProps } from './layoutUtils';\n\nexport function replaceChild(model: ReactElement, { target, replacement }: ReplaceAction) {\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 =\n 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?: 'maximize' | 'minimize' | 'restore'\n): ReactElement {\n if (model === child) {\n return replacement;\n }\n \n const { idx, finalStep } = nextStep(getProp(model, 'path'), getProp(child, 'path'));\n const children = model.props.children.slice();\n \n if (finalStep) {\n if (!op) {\n children[idx] = replacement;\n } else if (op === Action.MINIMIZE) {\n children[idx] = minimize(model, children[idx]);\n } else if (op === Action.RESTORE) {\n children[idx] = restore(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 minimize(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 } = 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 });\n }\n return child;\n}\n\nfunction restore(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 });\n}\n"],"names":[],"mappings":";;;;;;AAMO,SAAS,YAAa,CAAA,KAAA,EAAqB,EAAE,MAAA,EAAQ,aAA8B,EAAA;AACxF,EAAO,OAAA,aAAA,CAAc,KAAO,EAAA,MAAA,EAAQ,WAAW,CAAA,CAAA;AACjD,CAAA;AAEgB,SAAA,aAAA,CACd,KACA,EAAA,KAAA,EACA,WACA,EAAA;AACA,EAAM,MAAA,IAAA,GAAO,OAAQ,CAAA,KAAA,EAAO,MAAM,CAAA,CAAA;AAClC,EAAM,MAAA,UAAA,GAAa,OAAQ,CAAA,KAAA,EAAO,YAAY,CAAA,CAAA;AAC9C,EAAA,MAAM,EAAE,KAAA,EAAU,GAAA,QAAA,CAAS,KAAK,CAAA,CAAA;AAChC,EAAA,MAAM,QACJ,GAAA,gBAAA;AAAA,IACE,KAAA,CAAM,aAAa,WAAa,EAAA;AAAA,MAC9B,UAAA;AAAA,MACA,KAAO,EAAA;AAAA,QACL,GAAG,KAAA;AAAA,QACH,GAAG,YAAY,KAAM,CAAA,KAAA;AAAA,OACvB;AAAA,KACD,CAAA;AAAA,IACD,IAAA;AAAA,GACF,CAAA;AAEF,EAAO,OAAA,SAAA,CAAU,KAAO,EAAA,KAAA,EAAO,QAAQ,CAAA,CAAA;AACzC,CAAA;AAEO,SAAS,SACd,CAAA,KAAA,EACA,KACA,EAAA,WAAA,EACA,EACc,EAAA;AACd,EAAA,IAAI,UAAU,KAAO,EAAA;AACnB,IAAO,OAAA,WAAA,CAAA;AAAA,GACT;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