@vuu-ui/vuu-layout 2.1.19-beta.1 → 2.1.19-beta.3
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/cjs/Component.js +14 -0
- package/cjs/Component.js.map +1 -0
- package/cjs/LayoutContainer.css.js +6 -0
- package/cjs/LayoutContainer.css.js.map +1 -0
- package/cjs/LayoutContainer.js +33 -0
- package/cjs/LayoutContainer.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 +41 -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 +95 -0
- package/cjs/dock-layout/Drawer.js.map +1 -0
- package/cjs/drag-drop/BoxModel.js +416 -0
- package/cjs/drag-drop/BoxModel.js.map +1 -0
- package/cjs/drag-drop/DragState.js +161 -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/DropTarget.js +257 -0
- package/cjs/drag-drop/DropTarget.js.map +1 -0
- package/cjs/drag-drop/DropTargetRenderer.js +218 -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 +69 -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/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 +95 -0
- package/cjs/flexbox/flexbox-utils.js.map +1 -0
- package/cjs/flexbox/useSplitterResizing.js +197 -0
- package/cjs/flexbox/useSplitterResizing.js.map +1 -0
- package/cjs/index.js +122 -0
- package/cjs/index.js.map +1 -0
- package/cjs/layout-action.js +24 -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 +152 -0
- package/cjs/layout-header/Header.js.map +1 -0
- package/cjs/layout-header/useHeader.js +85 -0
- package/cjs/layout-header/useHeader.js.map +1 -0
- package/cjs/layout-provider/LayoutProvider.js +304 -0
- package/cjs/layout-provider/LayoutProvider.js.map +1 -0
- package/cjs/layout-provider/LayoutProviderContext.js +23 -0
- package/cjs/layout-provider/LayoutProviderContext.js.map +1 -0
- package/cjs/layout-provider/useLayoutDragDrop.js +177 -0
- package/cjs/layout-provider/useLayoutDragDrop.js.map +1 -0
- package/cjs/layout-reducer/flexUtils.js +227 -0
- package/cjs/layout-reducer/flexUtils.js.map +1 -0
- package/cjs/layout-reducer/insert-layout-element.js +286 -0
- package/cjs/layout-reducer/insert-layout-element.js.map +1 -0
- package/cjs/layout-reducer/layout-reducer.js +202 -0
- package/cjs/layout-reducer/layout-reducer.js.map +1 -0
- package/cjs/layout-reducer/layoutTypes.js +40 -0
- package/cjs/layout-reducer/layoutTypes.js.map +1 -0
- package/cjs/layout-reducer/layoutUtils.js +237 -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 +237 -0
- package/cjs/layout-reducer/remove-layout-element.js.map +1 -0
- package/cjs/layout-reducer/replace-layout-element.js +96 -0
- package/cjs/layout-reducer/replace-layout-element.js.map +1 -0
- package/cjs/layout-reducer/resize-flex-children.js +62 -0
- package/cjs/layout-reducer/resize-flex-children.js.map +1 -0
- package/cjs/layout-reducer/wrap-layout-element.js +211 -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 +160 -0
- package/cjs/layout-view/View.js.map +1 -0
- package/cjs/layout-view/useView.js +75 -0
- package/cjs/layout-view/useView.js.map +1 -0
- package/cjs/layout-view/useViewBroadcastChannel.js +35 -0
- package/cjs/layout-view/useViewBroadcastChannel.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 +112 -0
- package/cjs/layout-view-actions/useViewActionDispatcher.js.map +1 -0
- package/cjs/layout-view-actions/useViewContributions.js +33 -0
- package/cjs/layout-view-actions/useViewContributions.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 +115 -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 +56 -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/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 +150 -0
- package/cjs/stack/Stack.js.map +1 -0
- package/cjs/stack/StackLayout.js +116 -0
- package/cjs/stack/StackLayout.js.map +1 -0
- package/cjs/use-persistent-state.js +63 -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/LayoutContainer.css.js +4 -0
- package/esm/LayoutContainer.css.js.map +1 -0
- package/esm/LayoutContainer.js +31 -0
- package/esm/LayoutContainer.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 +39 -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 +93 -0
- package/esm/dock-layout/Drawer.js.map +1 -0
- package/esm/drag-drop/BoxModel.js +409 -0
- package/esm/drag-drop/BoxModel.js.map +1 -0
- package/esm/drag-drop/DragState.js +159 -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/DropTarget.js +253 -0
- package/esm/drag-drop/DropTarget.js.map +1 -0
- package/esm/drag-drop/DropTargetRenderer.js +216 -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 +67 -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/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 +89 -0
- package/esm/flexbox/flexbox-utils.js.map +1 -0
- package/esm/flexbox/useSplitterResizing.js +195 -0
- package/esm/flexbox/useSplitterResizing.js.map +1 -0
- package/esm/index.js +33 -0
- package/esm/index.js.map +1 -0
- package/esm/layout-action.js +22 -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 +150 -0
- package/esm/layout-header/Header.js.map +1 -0
- package/esm/layout-header/useHeader.js +83 -0
- package/esm/layout-header/useHeader.js.map +1 -0
- package/esm/layout-provider/LayoutProvider.js +297 -0
- package/esm/layout-provider/LayoutProvider.js.map +1 -0
- package/esm/layout-provider/LayoutProviderContext.js +20 -0
- package/esm/layout-provider/LayoutProviderContext.js.map +1 -0
- package/esm/layout-provider/useLayoutDragDrop.js +175 -0
- package/esm/layout-provider/useLayoutDragDrop.js.map +1 -0
- package/esm/layout-reducer/flexUtils.js +218 -0
- package/esm/layout-reducer/flexUtils.js.map +1 -0
- package/esm/layout-reducer/insert-layout-element.js +282 -0
- package/esm/layout-reducer/insert-layout-element.js.map +1 -0
- package/esm/layout-reducer/layout-reducer.js +200 -0
- package/esm/layout-reducer/layout-reducer.js.map +1 -0
- package/esm/layout-reducer/layoutTypes.js +36 -0
- package/esm/layout-reducer/layoutTypes.js.map +1 -0
- package/esm/layout-reducer/layoutUtils.js +226 -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 +235 -0
- package/esm/layout-reducer/remove-layout-element.js.map +1 -0
- package/esm/layout-reducer/replace-layout-element.js +92 -0
- package/esm/layout-reducer/replace-layout-element.js.map +1 -0
- package/esm/layout-reducer/resize-flex-children.js +59 -0
- package/esm/layout-reducer/resize-flex-children.js.map +1 -0
- package/esm/layout-reducer/wrap-layout-element.js +209 -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 +158 -0
- package/esm/layout-view/View.js.map +1 -0
- package/esm/layout-view/useView.js +73 -0
- package/esm/layout-view/useView.js.map +1 -0
- package/esm/layout-view/useViewBroadcastChannel.js +33 -0
- package/esm/layout-view/useViewBroadcastChannel.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 +110 -0
- package/esm/layout-view-actions/useViewActionDispatcher.js.map +1 -0
- package/esm/layout-view-actions/useViewContributions.js +31 -0
- package/esm/layout-view-actions/useViewContributions.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 +112 -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 +54 -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/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 +148 -0
- package/esm/stack/Stack.js.map +1 -0
- package/esm/stack/StackLayout.js +114 -0
- package/esm/stack/StackLayout.js.map +1 -0
- package/esm/use-persistent-state.js +58 -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 +16 -14
- package/types/dock-layout/DockLayout.d.ts +4 -4
- package/types/dock-layout/Drawer.d.ts +4 -4
- package/types/drag-drop/BoxModel.d.ts +7 -7
- package/types/flexbox/FlexboxLayout.d.ts +4 -4
- package/types/flexbox/Splitter.d.ts +1 -1
- package/types/layout-reducer/layoutUtils.d.ts +1 -1
- package/types/layout-reducer/remove-layout-element.d.ts +1 -1
- package/types/layout-reducer/replace-layout-element.d.ts +2 -2
- package/types/layout-reducer/resize-flex-children.d.ts +2 -2
- package/types/layout-view/useView.d.ts +1 -1
- package/types/placeholder/Placeholder.d.ts +4 -4
- package/types/responsive/overflowUtils.d.ts +2 -2
- package/types/stack/StackLayout.d.ts +4 -4
- package/types/tools/devtools-box/layout-configurator.d.ts +26 -26
- package/types/tools/devtools-tree/layout-tree-viewer.d.ts +2 -2
- package/types/utils/pathUtils.d.ts +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replace-layout-element.js","sources":["../../../../packages/vuu-layout/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,EACc,EAAA;AACd,EAAA,IAAI,UAAU,KAAO,EAAA;AACnB,IAAO,OAAA,WAAA;AAAA;AAGT,EAAM,MAAA,EAAE,GAAK,EAAA,SAAA,EAAc,GAAA,QAAA;AAAA,IACzB,OAAA,CAAQ,OAAO,MAAM,CAAA;AAAA,IACrB,OAAA,CAAQ,OA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AA,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;;;;"}
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resize-flex-children.js","sources":["../../../../packages/vuu-layout/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":";;;;;AAMO,SAAS,eACd,CAAA,UAAA,EACA,EAAE,IAAA,EAAM,MACR,EAAA;AACA,EAAA,MAAM,MAAS,GAAA,UAAA,CAAW,UAAY,EAAA,IAAA,EAAM,IAAI,CAAA;AAEhD,EAAA,MAAM,EAAE,KAAA,EAAU,GAAA,QAAA,CAAS,MAAM,CAAA;AAEjC,EAAA,MAAM,QAAW,GAAA;AAAA,IACf,GAAG,KAAA;AAAA,IACH,KAAO,EAAA;AAAA,GACT;AAMA,EAAA,MAAM,cAAc,KAAM,CAAA,YAAA,CAAa,QAAQ,EAAE,KAAA,EAAO,UAAiB,CAAA;AAEzE,EAAO,OAAA,SAAA,CAAU,UAAY,EAAA,MAAA,EAAQ,WAAW,CAAA;AAClD;AAEO,SAAS,kBACd,CAAA,UAAA,EACA,EAAE,IAAA,EAAM,OACR,EAAA;AACA,EAAA,MAAM,MAAS,GAAA,UAAA,CAAW,UAAY,EAAA,IAAA,EAAM,IAAI,CAAA;AAChD,EAAA,MAAM,EAAE,QAAA,EAAU,KAAM,EAAA,GAAI,SAAS,MAAM,CAAA;AAE3C,EAAA,MAAMA,UAAY,GAAA,KAAA,CAAM,aAAkB,KAAA,QAAA,GAAW,QAAW,GAAA,OAAA;AAChE,EAAA,MAAM,mBAAsB,GAAA,oBAAA,CAAqB,QAAU,EAAA,KAAA,EAAOA,UAAS,CAAA;AAE3E,EAAA,MAAM,cAAc,KAAM,CAAA,YAAA;AAAA,IACxB,MAAA;AAAA,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AU,MAAS,GAAA,OAAA;AAAA,IAC9B,UAAA;AAAA,IACA;AAAA,GACF;AACF;;;;"}
|
|
@@ -0,0 +1,209 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrap-layout-element.js","sources":["../../../../packages/vuu-layout/src/layout-reducer/wrap-layout-element.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n getLayoutComponent,\n LayoutModel,\n rectTuple,\n uuid,\n} from \"@vuu-ui/vuu-utils\";\nimport React, { ReactElement } from \"react\";\nimport { DropPos } from \"../drag-drop/dragDropTypes\";\nimport { DropTarget } from \"../drag-drop/DropTarget\";\nimport { getProp, getProps, nextStep, resetPath, typeOf } from \"../utils\";\nimport {\n createFlexbox,\n createPlaceHolder,\n flexDirection,\n getFlexStyle,\n getIntrinsicSize,\n wrapIntrinsicSizeComponentWithFlexbox,\n} from \"./flexUtils\";\nimport { applyLayoutProps, LayoutProps } from \"./layoutUtils\";\n\nexport interface LayoutSpec {\n type: \"Stack\" | \"Flexbox\";\n flexDirection: \"column\" | \"row\";\n showTabs?: boolean;\n}\n\nconst isHtmlElement = (component: LayoutModel) => {\n const [firstLetter] = typeOf(component) as string;\n return firstLetter === firstLetter.toLowerCase();\n};\n\nexport function wrap(\n container: ReactElement,\n existingComponent: ReactElement,\n newComponent: any,\n pos: DropPos,\n clientRect?: DropTarget[\"clientRect\"],\n dropRect?: DropTarget[\"dropRect\"],\n): ReactElement {\n const { children: containerChildren, path: containerPath } =\n getProps(container);\n\n const existingComponentPath = getProp(existingComponent, \"path\");\n const { idx, finalStep } = nextStep(containerPath, existingComponentPath);\n const children = finalStep\n ? updateChildren(\n container,\n containerChildren,\n existingComponent,\n newComponent,\n pos,\n clientRect,\n dropRect,\n )\n : containerChildren.map((child: ReactElement, index: number) =>\n index === idx\n ? wrap(\n child,\n existingComponent,\n newComponent,\n pos,\n clientRect,\n dropRect,\n )\n : child,\n );\n\n return React.cloneElement(container, undefined, children);\n}\n\nfunction updateChildren(\n container: LayoutModel,\n containerChildren: ReactElement[],\n existingComponent: ReactElement,\n newComponent: ReactElement,\n pos: DropPos,\n clientRect?: DropTarget[\"clientRect\"],\n dropRect?: rectTuple,\n) {\n const intrinsicSize = getIntrinsicSize(newComponent);\n\n if (intrinsicSize?.width && intrinsicSize?.height) {\n if (clientRect === undefined || dropRect === undefined) {\n throw Error(\n \"wrap-layout-element, updateChildren clientRect and dropRect must both be available\",\n );\n }\n return wrapIntrinsicSizedComponent(\n containerChildren,\n existingComponent,\n newComponent,\n pos,\n clientRect,\n dropRect,\n );\n }\n return wrapFlexComponent(\n container,\n containerChildren,\n existingComponent,\n newComponent,\n pos,\n );\n}\n\nfunction wrapFlexComponent(\n container: LayoutModel,\n containerChildren: ReactElement[],\n existingComponent: ReactElement,\n newComponent: ReactElement,\n pos: DropPos,\n) {\n const { version = 0 } = getProps(newComponent);\n const { path: existingComponentPath, title } = getProps(existingComponent);\n const {\n type,\n flexDirection,\n showTabs: showTabsProp,\n } = getLayoutSpecForWrapper(pos);\n const [style, existingComponentStyle, newComponentStyle] =\n getWrappedFlexStyles(\n type,\n existingComponent,\n newComponent,\n flexDirection,\n pos,\n );\n const targetFirst = isTargetFirst(pos);\n const active = targetFirst ? 1 : 0;\n\n const newComponentProps = {\n resizeable: true,\n style: newComponentStyle,\n version: version + 1,\n };\n const resizeProp = isHtmlElement(existingComponent)\n ? \"data-resizeable\"\n : \"resizeable\";\n\n const existingComponentProps = {\n [resizeProp]: true,\n style: existingComponentStyle,\n };\n\n const showTabs = type === \"Stack\" ? { showTabs: showTabsProp } : undefined;\n const splitterSize =\n type === \"Flexbox\"\n ? {\n splitterSize:\n (typeOf(container) === \"Flexbox\" &&\n (container.props as any).splitterSize) ??\n undefined,\n }\n : undefined;\n\n const id = uuid();\n const wrapper = React.createElement(\n getLayoutComponent(type),\n {\n active,\n id,\n key: id,\n path: getProp(existingComponent, \"path\"),\n flexFill: getProp(existingComponent, \"flexFill\"),\n ...splitterSize,\n ...showTabs,\n style,\n title,\n resizeable: getProp(existingComponent, \"resizeable\"),\n } as LayoutProps,\n targetFirst\n ? [\n resetPath(\n existingComponent,\n `${existingComponentPath}.0`,\n existingComponentProps,\n ),\n applyLayoutProps(\n React.cloneElement(newComponent, newComponentProps),\n `${existingComponentPath}.1`,\n ),\n ]\n : [\n applyLayoutProps(\n React.cloneElement(newComponent, newComponentProps),\n `${existingComponentPath}.0`,\n ),\n resetPath(\n existingComponent,\n `${existingComponentPath}.1`,\n existingComponentProps,\n ),\n ],\n );\n return containerChildren.map((child: ReactElement) =>\n child === existingComponent ? wrapper : child,\n );\n}\n\nfunction wrapIntrinsicSizedComponent(\n containerChildren: ReactElement[],\n existingComponent: ReactElement,\n newComponent: ReactElement,\n pos: DropPos,\n clientRect: DropTarget[\"clientRect\"],\n dropRect: rectTuple,\n) {\n const { flexDirection } = getLayoutSpecForWrapper(pos);\n const contraDirection = flexDirection === \"column\" ? \"row\" : \"column\";\n const targetFirst = isTargetFirst(pos);\n\n const [dropLeft, dropTop, dropRight, dropBottom] = dropRect;\n const [startPlaceholder, endPlaceholder] =\n flexDirection === \"column\"\n ? [dropTop - clientRect.top, clientRect.bottom - dropBottom]\n : [dropLeft - clientRect.left, clientRect.right - dropRight];\n const pathRoot = getProp(existingComponent, \"path\");\n let pathIndex = 0;\n\n const resizeProp = isHtmlElement(existingComponent)\n ? \"data-resizeable\"\n : \"resizeable\";\n\n const wrappedChildren = [];\n if (startPlaceholder) {\n wrappedChildren.push(\n targetFirst\n ? resetPath(existingComponent, `${pathRoot}.${pathIndex++}`, {\n [resizeProp]: true,\n style: { flexBasis: startPlaceholder, flexGrow: 1, flexShrink: 1 },\n })\n : createPlaceHolder(`${pathRoot}.${pathIndex++}`, startPlaceholder, {\n flexGrow: 0,\n flexShrink: 0,\n }),\n );\n }\n wrappedChildren.push(\n wrapIntrinsicSizeComponentWithFlexbox(\n newComponent,\n contraDirection,\n `${pathRoot}.${pathIndex++}`,\n clientRect,\n dropRect,\n ),\n );\n if (endPlaceholder) {\n wrappedChildren.push(\n targetFirst\n ? createPlaceHolder(`${pathRoot}.${pathIndex++}`, 0)\n : resetPath(existingComponent, `${pathRoot}.${pathIndex++}`, {\n [resizeProp]: true,\n style: { flexBasis: 0, flexGrow: 1, flexShrink: 1 },\n }),\n );\n }\n\n const wrapper = createFlexbox(\n flexDirection,\n existingComponent.props,\n wrappedChildren,\n pathRoot,\n );\n return containerChildren.map((child) =>\n child === existingComponent ? wrapper : child,\n );\n}\n\nfunction getWrappedFlexStyles(\n type: string,\n existingComponent: ReactElement,\n newComponent: ReactElement,\n flexDirection: flexDirection,\n pos: DropPos,\n) {\n const style = {\n ...(existingComponent.props as any).style,\n flexDirection,\n };\n\n const dimension =\n type === \"Flexbox\" && flexDirection === \"column\" ? \"height\" : \"width\";\n const newComponentStyle = getFlexStyle(newComponent, dimension, pos);\n const existingComponentStyle = getFlexStyle(existingComponent, dimension);\n\n return [style, existingComponentStyle, newComponentStyle];\n}\n\nconst isTargetFirst = (pos: DropPos) =>\n pos.position.SouthOrEast\n ? true\n : pos?.tab?.positionRelativeToTab === \"before\"\n ? false\n : pos.position.Header\n ? true\n : false;\n\nfunction getLayoutSpecForWrapper(pos: DropPos): LayoutSpec {\n if (pos.position.Header) {\n return {\n type: \"Stack\",\n flexDirection: \"column\",\n showTabs: true,\n };\n } else {\n return {\n type: \"Flexbox\",\n flexDirection: pos.position.EastOrWest ? \"row\" : \"column\",\n };\n }\n}\n"],"names":["flexDirection"],"mappings":";;;;;;;;AA2BA,MAAM,aAAA,GAAgB,CAAC,SAA2B,KAAA;AAChD,EAAA,MAAM,CAAC,WAAW,CAAI,GAAA,MAAA,CAAO,SAAS,CAAA;AACtC,EAAO,OAAA,WAAA,KAAgB,YAAY,WAAY,EAAA;AACjD,CAAA;AAEO,SAAS,KACd,SACA,EAAA,iBAAA,EACA,YACA,EAAA,GAAA,EACA,YACA,QACc,EAAA;AACd,EAAA,MAAM,EAAE,QAAU,EAAA,iBAAA,EAAmB,MAAM,aAAc,EAAA,GACvD,SAAS,SAAS,CAAA;AAEpB,EAAM,MAAA,qBAAA,GAAwB,OAAQ,CAAA,iBAAA,EAAmB,MAAM,CAAA;AAC/D,EAAA,MAAM,EAAE,GAAK,EAAA,SAAA,EAAc,GAAA,QAAA,CAAS,eAAe,qBAAqB,CAAA;AACxE,EAAA,MAAM,WAAW,SACb,GAAA,cAAA;AAAA,IACE,SAAA;AAAA,IACA,iBA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A,CAAI,SAAS,MAAQ,EAAA;AACvB,IAAO,OAAA;AAAA,MACL,IAAM,EAAA,OAAA;AAAA,MACN,aAAe,EAAA,QAAA;AAAA,MACf,QAAU,EAAA;AAAA,KACZ;AAAA,GACK,MAAA;AACL,IAAO,OAAA;AAAA,MACL,IAAM,EAAA,SAAA;AAAA,MACN,aAAe,EAAA,GAAA,CAAI,QAAS,CAAA,UAAA,GAAa,KAAQ,GAAA;AAAA,KACnD;AAAA;AAEJ;;;;"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var viewCss = ".vuuView {\n --vuuToolbarProxy-height: var(--salt-size-base);\n border-color: var(--vuuView-borderColor, transparent);\n border-width: var(--vuuView-borderWidth, 1px);\n border-style: var(--vuuView-borderStyle, solid);\n\n display: flex;\n flex-direction: column;\n margin: var(--vuuView-margin, 0px);\n min-height: 50px;\n min-width: 50px;\n outline: none;\n overflow: hidden;\n position: relative;\n transition: flex-basis .3s ease-in-out;\n\n &.vuuHighlighted {\n --vuuView-borderStyle: dashed;\n --vuuView-borderColor: var(--salt-container-primary-borderColor);\n }\n}\n\n.vuuSplitterResizing .vuuView {\n transition: none;\n\n}\n\n.vuuView:has(> .vuuHeader){\n min-height: var(--vuuToolbarProxy-height);\n}\n\n.vuuView.focus-visible:after {\n content: \"\";\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n border: dotted cornflowerblue 2px;\n}\n\n.vuuView.dragging {\n box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);\n}\n\n.vuuView-main {\n /* height: var(--view-content-height);\n width: var(--view-content-width); */\n display: flex;\n flex-direction: var(--vuuView-flexDirection, column);\n flex-wrap: var(--vuuView-flex-wrap, nowrap);\n flex: 1;\n justify-content: var(--vuuView-justify, flex-start);\n overflow: hidden;\n position: relative;\n}\n\n.vuuView-main > * {\n flex-basis: auto;\n flex-grow: var(--vuuView-flex-grow, 1);\n flex-shrink: var(--vuuView-flex-shrink, 1);\n}\n\n/* .vuuView-collapsed .vuuView-main {\n display: none;\n} */\n\n.vuuView-collapsed {\n flex: 0 0 0 !important;\n}\n\n\n.vuuView-collapsed + .Splitter {\n display: none;\n}\n\n.vuuView-collapsed .Toolbar-vertical {\n border-right: solid 1px var(--grey40);\n}\n\n.vuuView-collapsed .Toolbar-vertical .toolbar-title {\n display: none;\n}\n";
|
|
2
|
+
|
|
3
|
+
export { viewCss as default };
|
|
4
|
+
//# sourceMappingURL=View.css.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"View.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import { useId, registerComponent } from '@vuu-ui/vuu-utils';
|
|
3
|
+
import { useForkRef } from '@salt-ds/core';
|
|
4
|
+
import { useComponentCssInjection } from '@salt-ds/styles';
|
|
5
|
+
import { useWindow } from '@salt-ds/window';
|
|
6
|
+
import cx from 'clsx';
|
|
7
|
+
import React, { forwardRef, useRef, useState, useCallback, useMemo } from 'react';
|
|
8
|
+
import { Header } from '../layout-header/Header.js';
|
|
9
|
+
import { useView } from './useView.js';
|
|
10
|
+
import { useViewResize } from './useViewResize.js';
|
|
11
|
+
import { ViewContext } from '../layout-view-actions/ViewContext.js';
|
|
12
|
+
import viewCss from './View.css.js';
|
|
13
|
+
|
|
14
|
+
const classBase = "vuuView";
|
|
15
|
+
const getProps = (state, props) => {
|
|
16
|
+
if (state && props) {
|
|
17
|
+
return {
|
|
18
|
+
...state,
|
|
19
|
+
...props
|
|
20
|
+
};
|
|
21
|
+
} else return state || props;
|
|
22
|
+
};
|
|
23
|
+
const View = forwardRef(function View2(props, forwardedRef) {
|
|
24
|
+
const {
|
|
25
|
+
Header: Header$1 = Header,
|
|
26
|
+
allowRename,
|
|
27
|
+
children,
|
|
28
|
+
className,
|
|
29
|
+
collapsed,
|
|
30
|
+
closeable,
|
|
31
|
+
"data-path": dataPath,
|
|
32
|
+
"data-resizeable": dataResizeable,
|
|
33
|
+
dropTargets,
|
|
34
|
+
expanded,
|
|
35
|
+
flexFill,
|
|
36
|
+
id: idProp,
|
|
37
|
+
header,
|
|
38
|
+
onCollapse,
|
|
39
|
+
onExpand,
|
|
40
|
+
orientation = "horizontal",
|
|
41
|
+
path = dataPath,
|
|
42
|
+
resize = "responsive",
|
|
43
|
+
resizeable = dataResizeable,
|
|
44
|
+
restoreStyle,
|
|
45
|
+
tearOut,
|
|
46
|
+
style = {},
|
|
47
|
+
title: titleProp,
|
|
48
|
+
...restProps
|
|
49
|
+
} = props;
|
|
50
|
+
const targetWindow = useWindow();
|
|
51
|
+
useComponentCssInjection({
|
|
52
|
+
testId: "vuu-view",
|
|
53
|
+
css: viewCss,
|
|
54
|
+
window: targetWindow
|
|
55
|
+
});
|
|
56
|
+
const id = useId(idProp);
|
|
57
|
+
const rootRef = useRef(null);
|
|
58
|
+
const mainRef = useRef(null);
|
|
59
|
+
const [componentProps, _setComponentProps] = useState();
|
|
60
|
+
const {
|
|
61
|
+
contributions,
|
|
62
|
+
dispatchViewAction,
|
|
63
|
+
load,
|
|
64
|
+
onConfigChange,
|
|
65
|
+
onEditTitle,
|
|
66
|
+
purge,
|
|
67
|
+
restoredState,
|
|
68
|
+
save,
|
|
69
|
+
title
|
|
70
|
+
} = useView({
|
|
71
|
+
id,
|
|
72
|
+
rootRef,
|
|
73
|
+
path,
|
|
74
|
+
dropTargets,
|
|
75
|
+
title: titleProp
|
|
76
|
+
});
|
|
77
|
+
useViewResize({ mainRef, resize, rootRef });
|
|
78
|
+
const setComponentProps = useCallback((props2) => {
|
|
79
|
+
_setComponentProps(props2);
|
|
80
|
+
}, []);
|
|
81
|
+
const getContent = () => {
|
|
82
|
+
if (React.isValidElement(children) && (restoredState || componentProps)) {
|
|
83
|
+
return React.cloneElement(
|
|
84
|
+
children,
|
|
85
|
+
getProps(restoredState, componentProps)
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
return children;
|
|
89
|
+
};
|
|
90
|
+
const viewContextValue = useMemo(
|
|
91
|
+
() => ({
|
|
92
|
+
dispatch: dispatchViewAction,
|
|
93
|
+
id,
|
|
94
|
+
path,
|
|
95
|
+
title,
|
|
96
|
+
load,
|
|
97
|
+
onConfigChange,
|
|
98
|
+
purge,
|
|
99
|
+
save,
|
|
100
|
+
setComponentProps
|
|
101
|
+
}),
|
|
102
|
+
[
|
|
103
|
+
dispatchViewAction,
|
|
104
|
+
id,
|
|
105
|
+
load,
|
|
106
|
+
onConfigChange,
|
|
107
|
+
path,
|
|
108
|
+
purge,
|
|
109
|
+
save,
|
|
110
|
+
setComponentProps,
|
|
111
|
+
title
|
|
112
|
+
]
|
|
113
|
+
);
|
|
114
|
+
const headerProps = typeof header === "object" ? header : {};
|
|
115
|
+
return /* @__PURE__ */ jsx(
|
|
116
|
+
"div",
|
|
117
|
+
{
|
|
118
|
+
...restProps,
|
|
119
|
+
className: cx(classBase, className, {
|
|
120
|
+
[`${classBase}-collapsed`]: collapsed,
|
|
121
|
+
[`${classBase}-expanded`]: expanded,
|
|
122
|
+
[`${classBase}-resize-defer`]: resize === "defer"
|
|
123
|
+
}),
|
|
124
|
+
"data-resizeable": resizeable,
|
|
125
|
+
id,
|
|
126
|
+
ref: useForkRef(forwardedRef, rootRef),
|
|
127
|
+
style,
|
|
128
|
+
tabIndex: -1,
|
|
129
|
+
children: /* @__PURE__ */ jsxs(ViewContext.Provider, { value: viewContextValue, children: [
|
|
130
|
+
header ? /* @__PURE__ */ jsx(
|
|
131
|
+
Header$1,
|
|
132
|
+
{
|
|
133
|
+
...headerProps,
|
|
134
|
+
allowRename,
|
|
135
|
+
collapsed,
|
|
136
|
+
contributions,
|
|
137
|
+
expanded,
|
|
138
|
+
closeable,
|
|
139
|
+
onCollapse,
|
|
140
|
+
onEditTitle,
|
|
141
|
+
onExpand,
|
|
142
|
+
orientation,
|
|
143
|
+
tearOut,
|
|
144
|
+
title
|
|
145
|
+
}
|
|
146
|
+
) : null,
|
|
147
|
+
/* @__PURE__ */ jsx("div", { className: `${classBase}-main`, ref: mainRef, children: getContent() })
|
|
148
|
+
] })
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
View.displayName = "View";
|
|
153
|
+
const MemoView = React.memo(View);
|
|
154
|
+
MemoView.displayName = "View";
|
|
155
|
+
registerComponent("View", MemoView, "view");
|
|
156
|
+
|
|
157
|
+
export { MemoView as View };
|
|
158
|
+
//# sourceMappingURL=View.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"View.js","sources":["../../../../packages/vuu-layout/src/layout-view/View.tsx"],"sourcesContent":["import { registerComponent, useId } from \"@vuu-ui/vuu-utils\";\nimport { useForkRef } from \"@salt-ds/core\";\nimport { useComponentCssInjection } from \"@salt-ds/styles\";\nimport { useWindow } from \"@salt-ds/window\";\nimport cx from \"clsx\";\nimport React, {\n ForwardedRef,\n forwardRef,\n ReactElement,\n useCallback,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { Header as VuuHeader } from \"../layout-header/Header\";\nimport { useView } from \"./useView\";\nimport { useViewResize } from \"./useViewResize\";\nimport {\n ViewContext,\n ViewContextAPI,\n} from \"../layout-view-actions/ViewContext\";\nimport { ViewProps } from \"./viewTypes\";\n\nimport viewCss from \"./View.css\";\n\nconst classBase = \"vuuView\";\n\ntype Props = { [key: string]: unknown };\n\nconst getProps = (state?: Props, props?: Props) => {\n if (state && props) {\n return {\n ...state,\n ...props,\n };\n } else return state || props;\n};\n\n/**\n * View is the leaf-level entity managed by the Vuu layout system. It may represent a component\n * or a group of components. It also offers an API (via useViewContext) for persistence.\n */\nconst View = forwardRef(function View(\n props: ViewProps,\n forwardedRef: ForwardedRef<HTMLDivElement>,\n) {\n const {\n Header = VuuHeader,\n allowRename,\n children,\n className,\n collapsed,\n closeable,\n \"data-path\": dataPath,\n \"data-resizeable\": dataResizeable,\n dropTargets,\n expanded,\n flexFill,\n id: idProp,\n header,\n onCollapse,\n onExpand,\n orientation = \"horizontal\",\n path = dataPath,\n resize = \"responsive\",\n resizeable = dataResizeable,\n restoreStyle,\n tearOut,\n style = {},\n title: titleProp,\n ...restProps\n } = props;\n\n const targetWindow = useWindow();\n useComponentCssInjection({\n testId: \"vuu-view\",\n css: viewCss,\n window: targetWindow,\n });\n\n const id = useId(idProp);\n\n const rootRef = useRef<HTMLDivElement>(null);\n const mainRef = useRef<HTMLDivElement>(null);\n const [componentProps, _setComponentProps] = useState<Props>();\n const {\n contributions,\n dispatchViewAction,\n load,\n onConfigChange,\n onEditTitle,\n purge,\n restoredState,\n save,\n title,\n } = useView({\n id,\n rootRef,\n path,\n dropTargets,\n title: titleProp,\n });\n\n useViewResize({ mainRef, resize, rootRef });\n\n const setComponentProps = useCallback((props?: Props) => {\n _setComponentProps(props);\n }, []);\n\n const getContent = () => {\n if (React.isValidElement(children) && (restoredState || componentProps)) {\n return React.cloneElement(\n children,\n getProps(restoredState, componentProps),\n );\n }\n return children;\n };\n\n const viewContextValue: ViewContextAPI = useMemo(\n () => ({\n dispatch: dispatchViewAction,\n id,\n path,\n title,\n load,\n onConfigChange,\n purge,\n save,\n setComponentProps,\n }),\n [\n dispatchViewAction,\n id,\n load,\n onConfigChange,\n path,\n purge,\n save,\n setComponentProps,\n title,\n ],\n );\n\n const headerProps = typeof header === \"object\" ? header : {};\n\n return (\n <div\n {...restProps}\n className={cx(classBase, className, {\n [`${classBase}-collapsed`]: collapsed,\n [`${classBase}-expanded`]: expanded,\n [`${classBase}-resize-defer`]: resize === \"defer\",\n })}\n data-resizeable={resizeable}\n id={id}\n ref={useForkRef(forwardedRef, rootRef)}\n style={style}\n tabIndex={-1}\n >\n <ViewContext.Provider value={viewContextValue}>\n {header ? (\n <Header\n {...headerProps}\n allowRename={allowRename}\n collapsed={collapsed}\n contributions={contributions}\n expanded={expanded}\n closeable={closeable}\n onCollapse={onCollapse}\n onEditTitle={onEditTitle}\n onExpand={onExpand}\n orientation={orientation}\n tearOut={tearOut}\n title={title}\n />\n ) : null}\n <div className={`${classBase}-main`} ref={mainRef}>\n {getContent()}\n </div>\n </ViewContext.Provider>\n </div>\n );\n});\nView.displayName = \"View\";\n\ninterface ViewComponentType {\n (\n props: ViewProps & {\n ref?: ForwardedRef<HTMLDivElement>;\n },\n ): ReactElement<ViewProps>;\n displayName?: string;\n}\n\nconst MemoView = React.memo(View) as ViewComponentType;\n\nMemoView.displayName = \"View\";\n\nregisterComponent(\"View\", MemoView, \"view\");\n\nexport { MemoView as View };\n"],"names":["View","Header","VuuHeader","props"],"mappings":";;;;;;;;;;;;;AAyBA,MAAM,SAAY,GAAA,SAAA;AAIlB,MAAM,QAAA,GAAW,CAAC,KAAA,EAAe,KAAkB,KAAA;AACjD,EAAA,IAAI,SAAS,KAAO,EAAA;AAClB,IAAO,OAAA;AAAA,MACL,GAAG,KAAA;AAAA,MACH,GAAG;AAAA,KACL;AAAA,GACF,aAAc,KAAS,IAAA,KAAA;AACzB,CAAA;AAMA,MAAM,IAAO,GAAA,UAAA,CAAW,SAASA,KAAAA,CAC/B,OACA,YACA,EAAA;AACA,EAAM,MAAA;AAAA,YACJC,QAAS,GAAAC,MAAA;AAAA,IACT,WAAA;AAAA,IACA,QAAA;AAAA,IACA,SAAA;AAAA,IACA,SAAA;AAAA,IACA,SAAA;AAAA,IACA,WAAa,EAAA,QAAA;AAAA,IACb,iBAAmB,EAAA,cAAA;AAAA,IACnB,WAAA;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA,IACA,EAAI,EAAA,MAAA;AAAA,IACJ,MAAA;AAAA,IACA,UAAA;AAAA,IACA,QAAA;AAAA,IACA,WAAc,GAAA,YAAA;AAAA,IACd,IAAO,GAAA,QAAA;AAAA,IACP,MAAS,GAAA,YAAA;AAAA,IACT,UAAa,GAAA,cAAA;AAAA,IACb,YAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAQ,EAAC;AAAA,IACT,KAAO,EAAA,SAAA;AAAA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AAA,YACA,UAAA;AAAA,YACA,WAAA;AAAA,YACA,QAAA;AAAA,YACA,WAAA;AAAA,YACA,OAAA;AAAA,YACA;AAAA;AAAA,SAEA,GAAA,IAAA;AAAA,wBACJ,GAAA,CAAC,SAAI,SAAW,EAAA,CAAA,EAAG,SAAS,CAAS,KAAA,CAAA,EAAA,GAAA,EAAK,OACvC,EAAA,QAAA,EAAA,UAAA,EACH,EAAA;AAAA,OACF,EAAA;AAAA;AAAA,GACF;AAEJ,CAAC,CAAA;AACD,IAAA,CAAK,WAAc,GAAA,MAAA;AAWb,MAAA,QAAA,GAAW,KAAM,CAAA,IAAA,CAAK,IAAI;AAEhC,QAAA,CAAS,WAAc,GAAA,MAAA;AAEvB,iBAAkB,CAAA,MAAA,EAAQ,UAAU,MAAM,CAAA;;;;"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { useMemo, useCallback } from 'react';
|
|
2
|
+
import { useLayoutProviderDispatch } from '../layout-provider/LayoutProvider.js';
|
|
3
|
+
import { usePersistentState } from '../use-persistent-state.js';
|
|
4
|
+
import { useViewActionDispatcher } from '../layout-view-actions/useViewActionDispatcher.js';
|
|
5
|
+
|
|
6
|
+
const useView = ({
|
|
7
|
+
id,
|
|
8
|
+
rootRef,
|
|
9
|
+
path,
|
|
10
|
+
dropTargets,
|
|
11
|
+
title: titleProp
|
|
12
|
+
}) => {
|
|
13
|
+
const layoutDispatch = useLayoutProviderDispatch();
|
|
14
|
+
const { loadState, purgeState, saveState } = usePersistentState();
|
|
15
|
+
const [dispatchViewAction, contributions] = useViewActionDispatcher(
|
|
16
|
+
id,
|
|
17
|
+
rootRef,
|
|
18
|
+
path,
|
|
19
|
+
dropTargets
|
|
20
|
+
);
|
|
21
|
+
const title = useMemo(
|
|
22
|
+
() => loadState("view-title") ?? titleProp,
|
|
23
|
+
[loadState, titleProp]
|
|
24
|
+
);
|
|
25
|
+
const onEditTitle = useCallback(
|
|
26
|
+
(title2) => {
|
|
27
|
+
if (path) {
|
|
28
|
+
layoutDispatch({ type: "set-title", path, title: title2 });
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
[layoutDispatch, path]
|
|
32
|
+
);
|
|
33
|
+
const restoredState = useMemo(() => loadState(id), [id, loadState]);
|
|
34
|
+
const load = useCallback(
|
|
35
|
+
(key) => loadState(id, key),
|
|
36
|
+
[id, loadState]
|
|
37
|
+
);
|
|
38
|
+
const purge = useCallback(
|
|
39
|
+
(key) => {
|
|
40
|
+
purgeState(id, key);
|
|
41
|
+
layoutDispatch({ type: "save" });
|
|
42
|
+
},
|
|
43
|
+
[id, layoutDispatch, purgeState]
|
|
44
|
+
);
|
|
45
|
+
const save = useCallback(
|
|
46
|
+
(state, key) => {
|
|
47
|
+
saveState(id, key, state);
|
|
48
|
+
layoutDispatch({ type: "save" });
|
|
49
|
+
},
|
|
50
|
+
[id, layoutDispatch, saveState]
|
|
51
|
+
);
|
|
52
|
+
const onConfigChange = useCallback(
|
|
53
|
+
({ type: key, ...config }) => {
|
|
54
|
+
const { [key]: data } = config;
|
|
55
|
+
save(data, key);
|
|
56
|
+
},
|
|
57
|
+
[save]
|
|
58
|
+
);
|
|
59
|
+
return {
|
|
60
|
+
contributions,
|
|
61
|
+
dispatchViewAction,
|
|
62
|
+
load,
|
|
63
|
+
onConfigChange,
|
|
64
|
+
onEditTitle,
|
|
65
|
+
purge,
|
|
66
|
+
restoredState,
|
|
67
|
+
save,
|
|
68
|
+
title
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export { useView };
|
|
73
|
+
//# sourceMappingURL=useView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useView.js","sources":["../../../../packages/vuu-layout/src/layout-view/useView.tsx"],"sourcesContent":["import { RefObject, useCallback, useMemo } from \"react\";\nimport { useLayoutProviderDispatch } from \"../layout-provider/LayoutProvider\";\nimport { usePersistentState } from \"../use-persistent-state\";\nimport { useViewActionDispatcher } from \"../layout-view-actions/useViewActionDispatcher\";\nimport { ConfigChangeHandler } from \"../layout-view-actions/ViewContext\";\n\nexport interface ViewHookProps {\n id: string;\n rootRef: RefObject<HTMLDivElement | null>;\n path?: string;\n dropTargets?: string[];\n title?: string;\n}\n\nexport const useView = ({\n id,\n rootRef,\n path,\n dropTargets,\n title: titleProp,\n}: ViewHookProps) => {\n const layoutDispatch = useLayoutProviderDispatch();\n\n const { loadState, purgeState, saveState } = usePersistentState();\n\n const [dispatchViewAction, contributions] = useViewActionDispatcher(\n id,\n rootRef,\n path,\n dropTargets,\n );\n\n const title = useMemo(\n () => loadState(\"view-title\") ?? titleProp,\n [loadState, titleProp],\n );\n\n const onEditTitle = useCallback(\n (title: string) => {\n if (path) {\n layoutDispatch({ type: \"set-title\", path, title });\n }\n },\n [layoutDispatch, path],\n );\n\n const restoredState = useMemo(() => loadState(id), [id, loadState]);\n\n const load = useCallback(\n (key?: string) => loadState(id, key),\n [id, loadState],\n );\n\n const purge = useCallback(\n (key: string) => {\n purgeState(id, key);\n layoutDispatch({ type: \"save\" });\n },\n [id, layoutDispatch, purgeState],\n );\n\n const save = useCallback(\n (state: unknown, key: string) => {\n saveState(id, key, state);\n layoutDispatch({ type: \"save\" });\n },\n [id, layoutDispatch, saveState],\n );\n\n const onConfigChange = useCallback<ConfigChangeHandler>(\n ({ type: key, ...config }) => {\n const { [key]: data } = config;\n save(data, key);\n },\n [save],\n );\n\n return {\n contributions,\n dispatchViewAction,\n load,\n onConfigChange,\n onEditTitle,\n purge,\n restoredState,\n save,\n title,\n };\n};\n"],"names":["title"],"mappings":";;;;;AAcO,MAAM,UAAU,CAAC;AAAA,EACtB,EAAA;AAAA,EACA,OAAA;AAAA,EACA,IAAA;AAAA,EACA,WAAA;AAAA,EACA,KAAO,EAAA;AACT,CAAqB,KAAA;AACnB,EAAA,MAAM,iBAAiB,yBAA0B,EAAA;AAEjD,EAAA,MAAM,EAAE,SAAA,EAAW,UAAY,EAAA,SAAA,KAAc,kBAAmB,EAAA;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CAAC,EAAI,EAAA,cAAA,EAAgB,SAAS;AAAA,GAChC;AAEA,EAAA,MAAM,cAAiB,GAAA,WAAA;AAAA,IACrB,CAAC,EAAE,IAAA,EAAM,GAAK,EAAA,GAAG,QAAa,KAAA;AAC5B,MAAA,MAAM,EAAE,CAAC,GAAG,GAAG,MAAS,GAAA,MAAA;AACxB,MAAA,IAAA,CAAK,MAAM,GAAG,CAAA;AAAA,KAChB;AAAA,IACA,CAAC,IAAI;AAAA,GACP;AAEA,EAAO,OAAA;AAAA,IACL,aAAA;AAAA,IACA,kBAAA;AAAA,IACA,IAAA;AAAA,IACA,cAAA;AAAA,IACA,WAAA;AAAA,IACA,KAAA;AAAA,IACA,aAAA;AAAA,IACA,IAAA;AAAA,IACA;AAAA,GACF;AACF;;;;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useRef, useEffect, useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
const isMessageForSelf = (message, id, path) => {
|
|
4
|
+
if (id && message.targetId === id) {
|
|
5
|
+
return true;
|
|
6
|
+
} else if (message.path && path?.startsWith(message.path)) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
return false;
|
|
10
|
+
};
|
|
11
|
+
const useViewBroadcastChannel = (id, path, onMessageReceived) => {
|
|
12
|
+
const broadcastChannelRef = useRef(void 0);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const broadcastChannel = new BroadcastChannel("vuu");
|
|
15
|
+
broadcastChannel.onmessage = (evt) => {
|
|
16
|
+
if (isMessageForSelf(evt.data, id, path)) {
|
|
17
|
+
onMessageReceived?.(evt.data);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
broadcastChannelRef.current = broadcastChannel;
|
|
21
|
+
return () => {
|
|
22
|
+
broadcastChannel.close();
|
|
23
|
+
broadcastChannelRef.current = void 0;
|
|
24
|
+
};
|
|
25
|
+
}, [id, onMessageReceived, path]);
|
|
26
|
+
const sendMessage = useCallback((message) => {
|
|
27
|
+
broadcastChannelRef.current?.postMessage(message);
|
|
28
|
+
}, []);
|
|
29
|
+
return sendMessage;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { useViewBroadcastChannel };
|
|
33
|
+
//# sourceMappingURL=useViewBroadcastChannel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useViewBroadcastChannel.js","sources":["../../../../packages/vuu-layout/src/layout-view/useViewBroadcastChannel.ts"],"sourcesContent":["import { VuuBroadcastChannel } from \"@vuu-ui/vuu-utils\";\nimport { useCallback, useEffect, useRef } from \"react\";\n\nexport interface ViewBroadcastMessage {\n path?: string;\n targetId?: string;\n type: \"highlight-on\" | \"highlight-off\" | \"layout-closed\";\n}\n\nexport type BroadcastMessageHandler = (message: ViewBroadcastMessage) => void;\n\nconst isMessageForSelf = (\n message: ViewBroadcastMessage,\n id?: string,\n path?: string,\n) => {\n if (id && message.targetId === id) {\n return true;\n } else if (message.path && path?.startsWith(message.path)) {\n return true;\n }\n return false;\n};\n\nexport const useViewBroadcastChannel = (\n id?: string,\n path?: string,\n onMessageReceived?: BroadcastMessageHandler,\n) => {\n const broadcastChannelRef =\n useRef<VuuBroadcastChannel<ViewBroadcastMessage>>(undefined);\n\n useEffect(() => {\n const broadcastChannel: VuuBroadcastChannel<ViewBroadcastMessage> =\n new BroadcastChannel(\"vuu\");\n broadcastChannel.onmessage = (evt) => {\n if (isMessageForSelf(evt.data, id, path)) {\n onMessageReceived?.(evt.data);\n }\n };\n broadcastChannelRef.current = broadcastChannel;\n return () => {\n broadcastChannel.close();\n broadcastChannelRef.current = undefined;\n };\n }, [id, onMessageReceived, path]);\n\n const sendMessage = useCallback((message: ViewBroadcastMessage) => {\n broadcastChannelRef.current?.postMessage(message);\n }, []);\n\n return sendMessage;\n};\n"],"names":[],"mappings":";;AAWA,MAAM,gBAAmB,GAAA,CACvB,OACA,EAAA,EAAA,EACA,IACG,KAAA;AACH,EAAI,IAAA,EAAA,IAAM,OAAQ,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