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