@vuu-ui/vuu-layout 0.5.9 → 0.5.10
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/package.json +10 -13
- package/src/Component.css +0 -0
- package/src/Component.tsx +20 -0
- package/src/DraggableLayout.css +18 -0
- package/src/DraggableLayout.tsx +26 -0
- package/src/__tests__/flexbox-utils.spec.js +90 -0
- package/src/chest-of-drawers/Chest.css +36 -0
- package/src/chest-of-drawers/Chest.tsx +42 -0
- package/src/chest-of-drawers/Drawer.css +159 -0
- package/src/chest-of-drawers/Drawer.tsx +118 -0
- package/src/chest-of-drawers/index.ts +2 -0
- package/src/common-types.ts +9 -0
- package/src/debug.ts +16 -0
- package/src/drag-drop/BoxModel.ts +551 -0
- package/src/drag-drop/DragState.ts +219 -0
- package/src/drag-drop/Draggable.ts +282 -0
- package/src/drag-drop/DropMenu.css +71 -0
- package/src/drag-drop/DropMenu.tsx +61 -0
- package/src/drag-drop/DropTarget.ts +393 -0
- package/src/drag-drop/DropTargetRenderer.css +40 -0
- package/src/drag-drop/DropTargetRenderer.tsx +277 -0
- package/src/drag-drop/dragDropTypes.ts +47 -0
- package/src/drag-drop/index.ts +5 -0
- package/src/editable-label/EditableLabel.css +28 -0
- package/src/editable-label/EditableLabel.tsx +99 -0
- package/src/editable-label/index.ts +1 -0
- package/src/flexbox/Flexbox.css +45 -0
- package/src/flexbox/Flexbox.tsx +70 -0
- package/src/flexbox/FlexboxLayout.tsx +28 -0
- package/src/flexbox/FluidGrid.css +134 -0
- package/src/flexbox/FluidGrid.tsx +82 -0
- package/src/flexbox/FluidGridLayout.tsx +9 -0
- package/src/flexbox/Splitter.css +140 -0
- package/src/flexbox/Splitter.tsx +127 -0
- package/src/flexbox/flexbox-utils.ts +128 -0
- package/src/flexbox/flexboxTypes.ts +68 -0
- package/src/flexbox/index.ts +5 -0
- package/src/flexbox/useResponsiveSizing.ts +82 -0
- package/src/flexbox/useSplitterResizing.ts +270 -0
- package/src/index.ts +19 -0
- package/src/layout-action.ts +21 -0
- package/src/layout-header/ActionButton.tsx +23 -0
- package/src/layout-header/Header.css +8 -0
- package/src/layout-header/Header.tsx +216 -0
- package/src/layout-header/index.ts +1 -0
- package/src/layout-provider/LayoutProvider.tsx +161 -0
- package/src/layout-provider/LayoutProviderContext.ts +17 -0
- package/src/layout-provider/index.ts +3 -0
- package/src/layout-provider/useLayoutDragDrop.ts +210 -0
- package/src/layout-reducer/flexUtils.ts +276 -0
- package/src/layout-reducer/index.ts +5 -0
- package/src/layout-reducer/insert-layout-element.ts +365 -0
- package/src/layout-reducer/layout-reducer.ts +237 -0
- package/src/layout-reducer/layoutTypes.ts +159 -0
- package/src/layout-reducer/layoutUtils.ts +288 -0
- package/src/layout-reducer/remove-layout-element.ts +226 -0
- package/src/layout-reducer/replace-layout-element.ts +113 -0
- package/src/layout-reducer/resize-flex-children.ts +55 -0
- package/src/layout-reducer/wrap-layout-element.ts +307 -0
- package/src/layout-view/View.css +61 -0
- package/src/layout-view/View.tsx +143 -0
- package/src/layout-view/ViewContext.ts +30 -0
- package/src/layout-view/index.ts +5 -0
- package/src/layout-view/useView.tsx +104 -0
- package/src/layout-view/useViewActionDispatcher.ts +123 -0
- package/src/layout-view/useViewResize.ts +53 -0
- package/src/layout-view/viewTypes.ts +35 -0
- package/src/palette/Palette.css +33 -0
- package/src/palette/Palette.tsx +140 -0
- package/src/palette/PaletteSalt.css +9 -0
- package/src/palette/PaletteSalt.tsx +79 -0
- package/src/palette/index.ts +3 -0
- package/src/placeholder/Placeholder.css +10 -0
- package/src/placeholder/Placeholder.tsx +38 -0
- package/src/placeholder/index.ts +1 -0
- package/src/registry/ComponentRegistry.ts +44 -0
- package/src/registry/index.ts +1 -0
- package/src/responsive/breakpoints.ts +62 -0
- package/src/responsive/index.ts +3 -0
- package/src/responsive/measureMinimumNodeSize.ts +23 -0
- package/src/responsive/overflowUtils.js +14 -0
- package/src/responsive/use-breakpoints.ts +101 -0
- package/src/responsive/useResizeObserver.ts +154 -0
- package/src/responsive/utils.ts +37 -0
- package/src/stack/Stack.css +39 -0
- package/src/stack/Stack.tsx +173 -0
- package/src/stack/StackLayout.tsx +119 -0
- package/src/stack/index.ts +4 -0
- package/src/stack/stackTypes.ts +22 -0
- package/src/tabs/TabPanel.css +12 -0
- package/src/tabs/TabPanel.tsx +17 -0
- package/src/tabs/index.ts +1 -0
- package/src/tools/config-wrapper/ConfigWrapper.tsx +55 -0
- package/src/tools/config-wrapper/index.ts +1 -0
- package/src/tools/devtools-box/layout-configurator.css +112 -0
- package/src/tools/devtools-box/layout-configurator.jsx +369 -0
- package/src/tools/devtools-tree/layout-tree-viewer.css +15 -0
- package/src/tools/devtools-tree/layout-tree-viewer.jsx +36 -0
- package/src/tools/index.ts +4 -0
- package/src/use-persistent-state.ts +112 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/pathUtils.ts +283 -0
- package/src/utils/propUtils.ts +26 -0
- package/src/utils/refUtils.ts +16 -0
- package/src/utils/styleUtils.ts +13 -0
- package/src/utils/typeOf.ts +25 -0
- package/tsconfig-emit-types.json +11 -0
- package/LICENSE +0 -201
- package/cjs/index.js +0 -20
- package/cjs/index.js.map +0 -7
- package/esm/index.js +0 -20
- package/esm/index.js.map +0 -7
- package/index.css +0 -2
- package/index.css.map +0 -7
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
.vuuView {
|
|
2
|
+
border-color: var(--vuuView-borderColor, var(--salt-container-primary-borderColor));
|
|
3
|
+
border-width: var(--vuuView-borderWidth, 1px);
|
|
4
|
+
border-style: var(--vuuView-borderStyle, none);
|
|
5
|
+
|
|
6
|
+
display: flex;
|
|
7
|
+
flex-direction: column;
|
|
8
|
+
margin: var(--vuuView-margin, 0px);
|
|
9
|
+
min-height: 50px;
|
|
10
|
+
min-width: 50px;
|
|
11
|
+
outline: none;
|
|
12
|
+
overflow: hidden;
|
|
13
|
+
position: relative;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.vuuView.focus-visible:after {
|
|
17
|
+
content: '';
|
|
18
|
+
position: absolute;
|
|
19
|
+
top: 0;
|
|
20
|
+
left: 0;
|
|
21
|
+
right: 0;
|
|
22
|
+
bottom: 0;
|
|
23
|
+
border: dotted cornflowerblue 2px;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.vuuView.dragging {
|
|
27
|
+
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.vuuView-main {
|
|
31
|
+
/* height: var(--view-content-height);
|
|
32
|
+
width: var(--view-content-width); */
|
|
33
|
+
display: flex;
|
|
34
|
+
flex-direction: var(--vuuView-flexDirection, column);
|
|
35
|
+
flex-wrap: var(--vuuView-flex-wrap, nowrap);
|
|
36
|
+
flex: 1;
|
|
37
|
+
overflow: hidden;
|
|
38
|
+
position: relative;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.vuuView-main > * {
|
|
42
|
+
flex-basis: auto;
|
|
43
|
+
flex-grow: var(--vuuView-flex-grow, 1);
|
|
44
|
+
flex-shrink: var(--vuuView-flex-shrink, 1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.vuuView-collapsed .vuuView-main {
|
|
48
|
+
display: none;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.vuuView-collapsed + .Splitter {
|
|
52
|
+
display: none;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.vuuView-collapsed .Toolbar-vertical {
|
|
56
|
+
border-right: solid 1px var(--grey40);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.vuuView-collapsed .Toolbar-vertical .toolbar-title {
|
|
60
|
+
display: none;
|
|
61
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { useForkRef, useIdMemo as useId } from "@salt-ds/core";
|
|
2
|
+
import cx from "classnames";
|
|
3
|
+
import React, { ForwardedRef, forwardRef, useMemo, useRef } from "react";
|
|
4
|
+
import { Header } from "../layout-header/Header";
|
|
5
|
+
import { registerComponent } from "../registry/ComponentRegistry";
|
|
6
|
+
import { useView } from "./useView";
|
|
7
|
+
import { useViewResize } from "./useViewResize";
|
|
8
|
+
import { ViewContext } from "./ViewContext";
|
|
9
|
+
import { ViewProps } from "./viewTypes";
|
|
10
|
+
|
|
11
|
+
import "./View.css";
|
|
12
|
+
|
|
13
|
+
const View = forwardRef(function View(
|
|
14
|
+
props: ViewProps,
|
|
15
|
+
forwardedRef: ForwardedRef<HTMLDivElement>
|
|
16
|
+
) {
|
|
17
|
+
const {
|
|
18
|
+
children,
|
|
19
|
+
className,
|
|
20
|
+
collapsed,
|
|
21
|
+
closeable,
|
|
22
|
+
"data-resizeable": dataResizeable,
|
|
23
|
+
dropTargets,
|
|
24
|
+
expanded,
|
|
25
|
+
flexFill,
|
|
26
|
+
id: idProp,
|
|
27
|
+
header,
|
|
28
|
+
orientation = "horizontal",
|
|
29
|
+
path,
|
|
30
|
+
resize = "responsive",
|
|
31
|
+
resizeable = dataResizeable,
|
|
32
|
+
tearOut,
|
|
33
|
+
style = {},
|
|
34
|
+
title: titleProp,
|
|
35
|
+
...restProps
|
|
36
|
+
} = props;
|
|
37
|
+
|
|
38
|
+
const id = useId(idProp);
|
|
39
|
+
const rootRef = useRef<HTMLDivElement>(null);
|
|
40
|
+
const mainRef = useRef<HTMLDivElement>(null);
|
|
41
|
+
|
|
42
|
+
const {
|
|
43
|
+
contributions,
|
|
44
|
+
dispatchViewAction,
|
|
45
|
+
load,
|
|
46
|
+
loadSession,
|
|
47
|
+
onConfigChange,
|
|
48
|
+
onEditTitle,
|
|
49
|
+
purge,
|
|
50
|
+
restoredState,
|
|
51
|
+
save,
|
|
52
|
+
saveSession,
|
|
53
|
+
title,
|
|
54
|
+
} = useView({
|
|
55
|
+
id,
|
|
56
|
+
rootRef,
|
|
57
|
+
path,
|
|
58
|
+
dropTargets,
|
|
59
|
+
title: titleProp,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
useViewResize({ mainRef, resize, rootRef });
|
|
63
|
+
|
|
64
|
+
const classBase = "vuuView";
|
|
65
|
+
|
|
66
|
+
const getContent = () => {
|
|
67
|
+
if (React.isValidElement(children) && restoredState) {
|
|
68
|
+
return React.cloneElement(children, restoredState);
|
|
69
|
+
}
|
|
70
|
+
return children;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const viewContextValue = useMemo(
|
|
74
|
+
() => ({
|
|
75
|
+
dispatch: dispatchViewAction,
|
|
76
|
+
id,
|
|
77
|
+
path,
|
|
78
|
+
title,
|
|
79
|
+
load,
|
|
80
|
+
loadSession,
|
|
81
|
+
onConfigChange,
|
|
82
|
+
purge,
|
|
83
|
+
save,
|
|
84
|
+
saveSession,
|
|
85
|
+
}),
|
|
86
|
+
[
|
|
87
|
+
dispatchViewAction,
|
|
88
|
+
id,
|
|
89
|
+
load,
|
|
90
|
+
loadSession,
|
|
91
|
+
onConfigChange,
|
|
92
|
+
path,
|
|
93
|
+
purge,
|
|
94
|
+
save,
|
|
95
|
+
saveSession,
|
|
96
|
+
title,
|
|
97
|
+
]
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const headerProps = typeof header === "object" ? header : {};
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<div
|
|
104
|
+
{...restProps}
|
|
105
|
+
className={cx(classBase, className, {
|
|
106
|
+
[`${classBase}-collapsed`]: collapsed,
|
|
107
|
+
[`${classBase}-expanded`]: expanded,
|
|
108
|
+
[`${classBase}-resize-defer`]: resize === "defer",
|
|
109
|
+
})}
|
|
110
|
+
data-resizeable={resizeable}
|
|
111
|
+
id={id}
|
|
112
|
+
ref={useForkRef(forwardedRef, rootRef)}
|
|
113
|
+
style={style}
|
|
114
|
+
tabIndex={-1}
|
|
115
|
+
>
|
|
116
|
+
<ViewContext.Provider value={viewContextValue}>
|
|
117
|
+
{header ? (
|
|
118
|
+
<Header
|
|
119
|
+
{...headerProps}
|
|
120
|
+
collapsed={collapsed}
|
|
121
|
+
contributions={contributions}
|
|
122
|
+
expanded={expanded}
|
|
123
|
+
closeable={closeable}
|
|
124
|
+
onEditTitle={onEditTitle}
|
|
125
|
+
orientation={orientation}
|
|
126
|
+
tearOut={tearOut}
|
|
127
|
+
title={title}
|
|
128
|
+
/>
|
|
129
|
+
) : null}
|
|
130
|
+
<div className={`${classBase}-main`} ref={mainRef}>
|
|
131
|
+
{getContent()}
|
|
132
|
+
</div>
|
|
133
|
+
</ViewContext.Provider>
|
|
134
|
+
</div>
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
View.displayName = "View";
|
|
138
|
+
|
|
139
|
+
const MemoView = React.memo(View) as React.FunctionComponent<ViewProps>;
|
|
140
|
+
MemoView.displayName = "View";
|
|
141
|
+
registerComponent("View", MemoView, "view");
|
|
142
|
+
|
|
143
|
+
export { MemoView as View };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React, { SyntheticEvent, useContext } from "react";
|
|
2
|
+
import { ViewAction } from "./viewTypes";
|
|
3
|
+
|
|
4
|
+
export type ViewDispatch = <Action extends ViewAction = ViewAction>(
|
|
5
|
+
action: Action,
|
|
6
|
+
evt?: SyntheticEvent
|
|
7
|
+
) => Promise<boolean | void>;
|
|
8
|
+
|
|
9
|
+
export interface ViewContextProps {
|
|
10
|
+
dispatch?: ViewDispatch | null;
|
|
11
|
+
id?: string;
|
|
12
|
+
load?: (key?: string) => unknown;
|
|
13
|
+
loadSession?: (key?: string) => unknown;
|
|
14
|
+
onConfigChange?: (config: unknown) => void;
|
|
15
|
+
path?: string;
|
|
16
|
+
purge?: (key: string) => void;
|
|
17
|
+
save?: (state: unknown, key: string) => void;
|
|
18
|
+
saveSession?: (state: unknown, key: string) => void;
|
|
19
|
+
title?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const NO_CONTEXT = { dispatch: null } as ViewContextProps;
|
|
23
|
+
export const ViewContext = React.createContext<ViewContextProps>(NO_CONTEXT);
|
|
24
|
+
|
|
25
|
+
export const useViewDispatch = () => {
|
|
26
|
+
const context = useContext(ViewContext);
|
|
27
|
+
return context?.dispatch ?? null;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const useViewContext = () => useContext(ViewContext);
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { RefObject, useCallback, useMemo } from "react";
|
|
2
|
+
import { useLayoutProviderDispatch } from "../layout-provider";
|
|
3
|
+
import { usePersistentState } from "../use-persistent-state";
|
|
4
|
+
import { useViewActionDispatcher } from "./useViewActionDispatcher";
|
|
5
|
+
|
|
6
|
+
export interface ViewHookProps {
|
|
7
|
+
id: string;
|
|
8
|
+
rootRef: RefObject<HTMLDivElement>;
|
|
9
|
+
path?: string;
|
|
10
|
+
dropTargets?: string[];
|
|
11
|
+
title?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const useView = ({
|
|
15
|
+
id,
|
|
16
|
+
rootRef,
|
|
17
|
+
path,
|
|
18
|
+
dropTargets,
|
|
19
|
+
title: titleProp,
|
|
20
|
+
}: ViewHookProps) => {
|
|
21
|
+
const layoutDispatch = useLayoutProviderDispatch();
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
loadState,
|
|
25
|
+
loadSessionState,
|
|
26
|
+
purgeState,
|
|
27
|
+
saveState,
|
|
28
|
+
saveSessionState,
|
|
29
|
+
} = usePersistentState();
|
|
30
|
+
|
|
31
|
+
const [dispatchViewAction, contributions] = useViewActionDispatcher(
|
|
32
|
+
id,
|
|
33
|
+
rootRef,
|
|
34
|
+
path,
|
|
35
|
+
dropTargets
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const title = useMemo(
|
|
39
|
+
() => loadState("view-title") ?? titleProp,
|
|
40
|
+
[loadState, titleProp]
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const onEditTitle = useCallback(
|
|
44
|
+
(title: string) => {
|
|
45
|
+
if (path) {
|
|
46
|
+
layoutDispatch({ type: "set-title", path, title });
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
[layoutDispatch, path]
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const restoredState = useMemo(() => loadState(id), [id, loadState]);
|
|
53
|
+
|
|
54
|
+
const load = useCallback(
|
|
55
|
+
(key?: string) => loadState(id, key),
|
|
56
|
+
[id, loadState]
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const purge = useCallback(
|
|
60
|
+
(key) => {
|
|
61
|
+
purgeState(id, key);
|
|
62
|
+
layoutDispatch({ type: "save" });
|
|
63
|
+
},
|
|
64
|
+
[id, layoutDispatch, purgeState]
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const save = useCallback(
|
|
68
|
+
(state, key) => {
|
|
69
|
+
saveState(id, key, state);
|
|
70
|
+
layoutDispatch({ type: "save" });
|
|
71
|
+
},
|
|
72
|
+
[id, layoutDispatch, saveState]
|
|
73
|
+
);
|
|
74
|
+
const loadSession = useCallback(
|
|
75
|
+
(key?: string) => loadSessionState(id, key),
|
|
76
|
+
[id, loadSessionState]
|
|
77
|
+
);
|
|
78
|
+
const saveSession = useCallback(
|
|
79
|
+
(state, key) => saveSessionState(id, key, state),
|
|
80
|
+
[id, saveSessionState]
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const onConfigChange = useCallback(
|
|
84
|
+
({ type: key, ...config }) => {
|
|
85
|
+
const { [key]: data } = config;
|
|
86
|
+
save(data, key);
|
|
87
|
+
},
|
|
88
|
+
[save]
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
contributions,
|
|
93
|
+
dispatchViewAction,
|
|
94
|
+
load,
|
|
95
|
+
loadSession,
|
|
96
|
+
onConfigChange,
|
|
97
|
+
onEditTitle,
|
|
98
|
+
purge,
|
|
99
|
+
restoredState,
|
|
100
|
+
save,
|
|
101
|
+
saveSession,
|
|
102
|
+
title,
|
|
103
|
+
};
|
|
104
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { DataSource } from "@vuu-ui/vuu-data";
|
|
2
|
+
import {
|
|
3
|
+
ReactElement,
|
|
4
|
+
RefObject,
|
|
5
|
+
SyntheticEvent,
|
|
6
|
+
useCallback,
|
|
7
|
+
useState,
|
|
8
|
+
} from "react";
|
|
9
|
+
import { useLayoutProviderDispatch } from "../layout-provider";
|
|
10
|
+
import { DragStartAction } from "../layout-reducer";
|
|
11
|
+
import { usePersistentState } from "../use-persistent-state";
|
|
12
|
+
import { ViewDispatch } from "./ViewContext";
|
|
13
|
+
import { ViewAction } from "./viewTypes";
|
|
14
|
+
|
|
15
|
+
export type Contribution = {
|
|
16
|
+
index?: number;
|
|
17
|
+
location?: string;
|
|
18
|
+
content: ReactElement;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const useViewActionDispatcher = (
|
|
22
|
+
id: string,
|
|
23
|
+
root: RefObject<HTMLDivElement>,
|
|
24
|
+
viewPath?: string,
|
|
25
|
+
dropTargets?: string[]
|
|
26
|
+
): [ViewDispatch, Contribution[] | undefined] => {
|
|
27
|
+
const { loadSessionState, purgeSessionState, purgeState, saveSessionState } =
|
|
28
|
+
usePersistentState();
|
|
29
|
+
|
|
30
|
+
const [contributions, setContributions] = useState<Contribution[]>(
|
|
31
|
+
loadSessionState(id, "contributions") ?? []
|
|
32
|
+
);
|
|
33
|
+
const dispatchLayoutAction = useLayoutProviderDispatch();
|
|
34
|
+
const updateContributions = useCallback(
|
|
35
|
+
(location: string, content: ReactElement) => {
|
|
36
|
+
const updatedContributions = contributions.concat([
|
|
37
|
+
{ location, content },
|
|
38
|
+
]);
|
|
39
|
+
saveSessionState(id, "contributions", updatedContributions);
|
|
40
|
+
setContributions(updatedContributions);
|
|
41
|
+
},
|
|
42
|
+
[contributions, id, saveSessionState]
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const clearContributions = useCallback(() => {
|
|
46
|
+
purgeSessionState(id, "contributions");
|
|
47
|
+
setContributions([]);
|
|
48
|
+
}, [id, purgeSessionState]);
|
|
49
|
+
|
|
50
|
+
const handleRemove = useCallback(() => {
|
|
51
|
+
const ds = loadSessionState(id, "data-source") as DataSource;
|
|
52
|
+
if (ds) {
|
|
53
|
+
ds.unsubscribe();
|
|
54
|
+
}
|
|
55
|
+
purgeSessionState(id);
|
|
56
|
+
purgeState(id);
|
|
57
|
+
dispatchLayoutAction({ type: "remove", path: viewPath });
|
|
58
|
+
}, [
|
|
59
|
+
dispatchLayoutAction,
|
|
60
|
+
id,
|
|
61
|
+
loadSessionState,
|
|
62
|
+
purgeSessionState,
|
|
63
|
+
purgeState,
|
|
64
|
+
viewPath,
|
|
65
|
+
]);
|
|
66
|
+
|
|
67
|
+
const handleMouseDown = useCallback(
|
|
68
|
+
async (evt, index, preDragActivity): Promise<boolean> => {
|
|
69
|
+
evt.stopPropagation();
|
|
70
|
+
const dragRect = root.current?.getBoundingClientRect();
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
dispatchLayoutAction({
|
|
73
|
+
type: "drag-start",
|
|
74
|
+
evt,
|
|
75
|
+
path: index === undefined ? viewPath : `${viewPath}.${index}`,
|
|
76
|
+
dragRect,
|
|
77
|
+
preDragActivity,
|
|
78
|
+
dropTargets,
|
|
79
|
+
resolveDragStart: resolve,
|
|
80
|
+
rejectDragStart: reject,
|
|
81
|
+
} as DragStartAction);
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
[root, dispatchLayoutAction, viewPath, dropTargets]
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const dispatchAction = useCallback(
|
|
88
|
+
async <A extends ViewAction = ViewAction>(
|
|
89
|
+
action: A,
|
|
90
|
+
evt?: SyntheticEvent
|
|
91
|
+
): Promise<boolean | void> => {
|
|
92
|
+
const { type } = action;
|
|
93
|
+
switch (type) {
|
|
94
|
+
case "maximize":
|
|
95
|
+
case "minimize":
|
|
96
|
+
case "restore":
|
|
97
|
+
return dispatchLayoutAction({ type, path: action.path ?? viewPath });
|
|
98
|
+
case "remove":
|
|
99
|
+
return handleRemove();
|
|
100
|
+
case "mousedown":
|
|
101
|
+
console.log("2) ViewActionDispatch Hook dispatch Action mousedown");
|
|
102
|
+
return handleMouseDown(evt, action.index, action.preDragActivity);
|
|
103
|
+
case "add-toolbar-contribution":
|
|
104
|
+
return updateContributions(action.location, action.content);
|
|
105
|
+
case "remove-toolbar-contribution":
|
|
106
|
+
return clearContributions();
|
|
107
|
+
default: {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
[
|
|
113
|
+
dispatchLayoutAction,
|
|
114
|
+
viewPath,
|
|
115
|
+
handleRemove,
|
|
116
|
+
handleMouseDown,
|
|
117
|
+
updateContributions,
|
|
118
|
+
clearContributions,
|
|
119
|
+
]
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
return [dispatchAction, contributions];
|
|
123
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useResizeObserver, WidthHeight } from "@heswell/salt-lab";
|
|
2
|
+
import { RefObject, useCallback, useRef } from "react";
|
|
3
|
+
|
|
4
|
+
const NO_MEASUREMENT: string[] = [];
|
|
5
|
+
|
|
6
|
+
type size = {
|
|
7
|
+
height?: number;
|
|
8
|
+
width?: number;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export interface ViewResizeHookProps {
|
|
12
|
+
mainRef: RefObject<HTMLDivElement>;
|
|
13
|
+
resize?: "defer" | "responsive";
|
|
14
|
+
rootRef: RefObject<HTMLDivElement>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const useViewResize = ({
|
|
18
|
+
mainRef,
|
|
19
|
+
resize = "responsive",
|
|
20
|
+
rootRef,
|
|
21
|
+
}: ViewResizeHookProps) => {
|
|
22
|
+
const deferResize = resize === "defer";
|
|
23
|
+
|
|
24
|
+
const mainSize = useRef<size>({});
|
|
25
|
+
const resizeHandle = useRef<number>();
|
|
26
|
+
|
|
27
|
+
const setMainSize = useCallback(() => {
|
|
28
|
+
if (mainRef.current) {
|
|
29
|
+
mainRef.current.style.height = mainSize.current.height + "px";
|
|
30
|
+
mainRef.current.style.width = mainSize.current.width + "px";
|
|
31
|
+
}
|
|
32
|
+
resizeHandle.current = undefined;
|
|
33
|
+
}, [mainRef]);
|
|
34
|
+
|
|
35
|
+
const onResize = useCallback(
|
|
36
|
+
({ height, width }) => {
|
|
37
|
+
mainSize.current.height = height;
|
|
38
|
+
mainSize.current.width = width;
|
|
39
|
+
if (resizeHandle.current !== null) {
|
|
40
|
+
clearTimeout(resizeHandle.current);
|
|
41
|
+
}
|
|
42
|
+
resizeHandle.current = window.setTimeout(setMainSize, 40);
|
|
43
|
+
},
|
|
44
|
+
[setMainSize]
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
useResizeObserver(
|
|
48
|
+
rootRef,
|
|
49
|
+
deferResize ? WidthHeight : NO_MEASUREMENT,
|
|
50
|
+
onResize,
|
|
51
|
+
deferResize
|
|
52
|
+
);
|
|
53
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { HTMLAttributes } from "react";
|
|
2
|
+
import { HeaderProps } from "../layout-header";
|
|
3
|
+
import {
|
|
4
|
+
AddToolbarContributionViewAction, MaximizeAction,
|
|
5
|
+
MinimizeAction,
|
|
6
|
+
MousedownViewAction,
|
|
7
|
+
RemoveAction, RemoveToolbarContributionViewAction, RestoreAction,
|
|
8
|
+
TearoutAction
|
|
9
|
+
} from "../layout-reducer";
|
|
10
|
+
|
|
11
|
+
export type ViewAction =
|
|
12
|
+
| MaximizeAction
|
|
13
|
+
| MinimizeAction
|
|
14
|
+
| MousedownViewAction
|
|
15
|
+
| RemoveAction
|
|
16
|
+
| RestoreAction
|
|
17
|
+
| TearoutAction
|
|
18
|
+
| AddToolbarContributionViewAction
|
|
19
|
+
| RemoveToolbarContributionViewAction;
|
|
20
|
+
|
|
21
|
+
export interface ViewProps extends HTMLAttributes<HTMLDivElement> {
|
|
22
|
+
closeable?: boolean;
|
|
23
|
+
collapsed?: boolean;
|
|
24
|
+
"data-resizeable"?: boolean;
|
|
25
|
+
dropTargets?: string[];
|
|
26
|
+
expanded?: boolean;
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
flexFill?: any;
|
|
29
|
+
header?: boolean | Partial<HeaderProps>;
|
|
30
|
+
orientation?: "vertical" | "horizontal";
|
|
31
|
+
path?: string;
|
|
32
|
+
resize?: "defer" | "responsive";
|
|
33
|
+
resizeable?: boolean;
|
|
34
|
+
tearOut?: boolean;
|
|
35
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
.vuuPalette-horizontal {
|
|
2
|
+
align-items: center;
|
|
3
|
+
display: flex;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.vuuPaletteItem {
|
|
7
|
+
--vuu-icon-color: var(--salt-separable-primary-borderColor);
|
|
8
|
+
--vuu-icon-inset: calc(50% - 12px) auto auto -3px;
|
|
9
|
+
--vuu-icon-height: 24px;
|
|
10
|
+
--vuu-icon-width: 24px;
|
|
11
|
+
--list-item-text-padding: 0 0 0 calc(var(--salt-size-unit) * 3);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.vuuPaletteItem[data-draggable]:after {
|
|
15
|
+
height: 22px;
|
|
16
|
+
width: 6px;
|
|
17
|
+
content: "";
|
|
18
|
+
position: absolute;
|
|
19
|
+
|
|
20
|
+
background-image:
|
|
21
|
+
linear-gradient(45deg, rgb(180, 183, 190) 25%, transparent 25%),
|
|
22
|
+
linear-gradient(-45deg, rgb(180, 183, 190) 25%, transparent 25%),
|
|
23
|
+
linear-gradient(45deg, transparent 75%, rgb(180, 183, 190) 25%),
|
|
24
|
+
linear-gradient(-45deg, transparent 75%, rgb(180, 183, 190) 25%);
|
|
25
|
+
background-size: 4px 4px;
|
|
26
|
+
background-position: 0 0, 2px 0, 2px -2px, 0 2px;
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.vuuSimpleDraggableWrapper > .vuuPaletteItem {
|
|
31
|
+
--vuu-icon-color: var(--salt-selectable-foreground);
|
|
32
|
+
|
|
33
|
+
}
|