@vuu-ui/grid-layout 4.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +141 -0
- package/package.json +40 -0
- package/src/GridCommand.js +395 -0
- package/src/GridComponentSettings.js +163 -0
- package/src/GridController.js +359 -0
- package/src/GridDragCoordinator.js +293 -0
- package/src/GridGeometry.js +1298 -0
- package/src/GridLayout.css.js +119 -0
- package/src/GridLayout.js +120 -0
- package/src/GridLayoutContext.js +58 -0
- package/src/GridLayoutDocument.js +307 -0
- package/src/GridLayoutDocumentIds.js +110 -0
- package/src/GridLayoutItem.css.js +46 -0
- package/src/GridLayoutItem.js +147 -0
- package/src/GridLayoutLegacyCompatibility.js +66 -0
- package/src/GridLayoutModel.js +138 -0
- package/src/GridLayoutProvider.js +263 -0
- package/src/GridLayoutStackedItem.css.js +26 -0
- package/src/GridLayoutStackedtem.js +140 -0
- package/src/GridModel.js +1289 -0
- package/src/GridPlaceholder.css.js +9 -0
- package/src/GridPlaceholder.js +24 -0
- package/src/GridSnapshot.js +11 -0
- package/src/GridSplitter.css.js +62 -0
- package/src/GridSplitter.js +26 -0
- package/src/GridStack.js +277 -0
- package/src/Icon.css.js +8 -0
- package/src/Icon.js +26 -0
- package/src/IconButton.css.js +9 -0
- package/src/IconButton.js +28 -0
- package/src/TabDialog.css.js +10 -0
- package/src/TabDialog.js +77 -0
- package/src/TabMenu.css.js +8 -0
- package/src/TabMenu.js +78 -0
- package/src/componentToJson.js +41 -0
- package/src/drag-drop-next/DragContextNext.js +173 -0
- package/src/drag-drop-next/DragDropProviderNext.css.js +72 -0
- package/src/drag-drop-next/DragDropProviderNext.js +91 -0
- package/src/drag-drop-next/SpaceMan.js +256 -0
- package/src/drag-drop-next/TemplateDragSession.js +36 -0
- package/src/drag-drop-next/tabstrip-drag-drop.js +251 -0
- package/src/grid-dom-utils.js +57 -0
- package/src/grid-layout-utils.js +39 -0
- package/src/grid-snapshot-adapters.js +435 -0
- package/src/index.js +24 -0
- package/src/json-value.js +56 -0
- package/src/layoutFromJson.js +15 -0
- package/src/layoutToJson.js +5 -0
- package/src/propUtils.js +15 -0
- package/src/react-element-utils.js +15 -0
- package/src/typeOf.js +15 -0
- package/src/useAsDropTarget.js +229 -0
- package/src/useDraggable.js +46 -0
- package/src/useEditTabName.js +70 -0
- package/src/useGridChildProps.js +47 -0
- package/src/useGridControllerSnapshot.js +21 -0
- package/src/useGridLayout.js +727 -0
- package/src/useGridSplitterResizing.js +262 -0
- package/src/useNotDropTarget.js +2 -0
- package/types/AddTabDialog.d.ts +5 -0
- package/types/GridCommand.d.ts +146 -0
- package/types/GridComponentSettings.d.ts +71 -0
- package/types/GridController.d.ts +50 -0
- package/types/GridDragCoordinator.d.ts +80 -0
- package/types/GridGeometry.d.ts +331 -0
- package/types/GridLayout.d.ts +20 -0
- package/types/GridLayoutContext.d.ts +141 -0
- package/types/GridLayoutDocument.d.ts +61 -0
- package/types/GridLayoutDocumentIds.d.ts +15 -0
- package/types/GridLayoutItem.d.ts +28 -0
- package/types/GridLayoutLegacyCompatibility.d.ts +57 -0
- package/types/GridLayoutModel.d.ts +72 -0
- package/types/GridLayoutProvider.d.ts +59 -0
- package/types/GridLayoutStackedtem.d.ts +10 -0
- package/types/GridModel.d.ts +504 -0
- package/types/GridPlaceholder.d.ts +5 -0
- package/types/GridSnapshot.d.ts +49 -0
- package/types/GridSplitter.d.ts +10 -0
- package/types/GridStack.d.ts +160 -0
- package/types/Icon.d.ts +6 -0
- package/types/IconButton.d.ts +6 -0
- package/types/TabDialog.d.ts +9 -0
- package/types/TabMenu.d.ts +7 -0
- package/types/componentToJson.d.ts +38 -0
- package/types/drag-drop-next/DragContextNext.d.ts +92 -0
- package/types/drag-drop-next/DragDropProviderNext.d.ts +23 -0
- package/types/drag-drop-next/SpaceMan.d.ts +35 -0
- package/types/drag-drop-next/TemplateDragSession.d.ts +21 -0
- package/types/drag-drop-next/tabstrip-drag-drop.d.ts +3 -0
- package/types/grid-dom-utils.d.ts +17 -0
- package/types/grid-layout-utils.d.ts +18 -0
- package/types/grid-matrix.d.ts +5 -0
- package/types/grid-snapshot-adapters.d.ts +22 -0
- package/types/index.d.ts +24 -0
- package/types/json-value.d.ts +23 -0
- package/types/layoutFromJson.d.ts +4 -0
- package/types/layoutToJson.d.ts +3 -0
- package/types/propUtils.d.ts +5 -0
- package/types/react-element-utils.d.ts +3 -0
- package/types/src/AddTabDialog.d.ts +5 -0
- package/types/src/GridLayout.d.ts +14 -0
- package/types/src/GridLayoutContext.d.ts +88 -0
- package/types/src/GridLayoutItem.d.ts +28 -0
- package/types/src/GridLayoutModel.d.ts +59 -0
- package/types/src/GridLayoutProvider.d.ts +37 -0
- package/types/src/GridLayoutStackedtem.d.ts +10 -0
- package/types/src/GridModel.d.ts +350 -0
- package/types/src/GridPlaceholder.d.ts +5 -0
- package/types/src/GridSplitter.d.ts +9 -0
- package/types/src/Icon.d.ts +6 -0
- package/types/src/IconButton.d.ts +6 -0
- package/types/src/TabMenu.d.ts +6 -0
- package/types/src/componentToJson.d.ts +32 -0
- package/types/src/drag-drop-next/DragContextNext.d.ts +73 -0
- package/types/src/drag-drop-next/DragDropProviderNext.d.ts +20 -0
- package/types/src/drag-drop-next/SpaceMan.d.ts +35 -0
- package/types/src/drag-drop-next/tabstrip-drag-drop.d.ts +3 -0
- package/types/src/grid-dom-utils.d.ts +17 -0
- package/types/src/grid-layout-utils.d.ts +80 -0
- package/types/src/grid-matrix.d.ts +5 -0
- package/types/src/index.d.ts +10 -0
- package/types/src/layoutFromJson.d.ts +3 -0
- package/types/src/layoutToJson.d.ts +2 -0
- package/types/src/propUtils.d.ts +5 -0
- package/types/src/react-element-utils.d.ts +3 -0
- package/types/src/typeOf.d.ts +6 -0
- package/types/src/useAsDropTarget.d.ts +7 -0
- package/types/src/useDraggable.d.ts +23 -0
- package/types/src/useGridChildProps.d.ts +13 -0
- package/types/src/useGridLayout.d.ts +43 -0
- package/types/src/useGridSplitterResizing.d.ts +12 -0
- package/types/src/useNotDropTarget.d.ts +1 -0
- package/types/typeOf.d.ts +6 -0
- package/types/useAsDropTarget.d.ts +7 -0
- package/types/useDraggable.d.ts +24 -0
- package/types/useEditTabName.d.ts +11 -0
- package/types/useGridChildProps.d.ts +13 -0
- package/types/useGridControllerSnapshot.d.ts +7 -0
- package/types/useGridLayout.d.ts +53 -0
- package/types/useGridSplitterResizing.d.ts +14 -0
- package/types/useNotDropTarget.d.ts +1 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, createElement, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { GridLayoutDocumentCodecError, decodeGridLayoutDocument, encodeGridLayoutDocument, immutableGridLayoutDocument } from "./GridLayoutDocument.js";
|
|
4
|
+
import { createLegacyGridLayoutReader } from "./GridLayoutLegacyCompatibility.js";
|
|
5
|
+
import { gridSnapshotToGridLayoutDescriptor } from "./grid-snapshot-adapters.js";
|
|
6
|
+
import { GridLayoutItem } from "./GridLayoutItem.js";
|
|
7
|
+
import { TemplateDragSession, TemplateDragSessionContext, useTemplateDragSession } from "./drag-drop-next/TemplateDragSession.js";
|
|
8
|
+
import { isTypedComponentTemplate } from "./GridLayoutContext.js";
|
|
9
|
+
const GridLayoutProviderContext = /*#__PURE__*/ createContext({});
|
|
10
|
+
class GridLayoutDocumentController {
|
|
11
|
+
#change;
|
|
12
|
+
#document;
|
|
13
|
+
#listeners = new Set();
|
|
14
|
+
constructor(document){
|
|
15
|
+
this.#document = document ? immutableGridLayoutDocument(document) : void 0;
|
|
16
|
+
}
|
|
17
|
+
getSnapshot = ()=>this.#document;
|
|
18
|
+
getChange = ()=>this.#change;
|
|
19
|
+
subscribe = (listener)=>{
|
|
20
|
+
this.#listeners.add(listener);
|
|
21
|
+
return ()=>this.#listeners.delete(listener);
|
|
22
|
+
};
|
|
23
|
+
replace(document) {
|
|
24
|
+
const immutableDocument = document ? immutableGridLayoutDocument(document) : void 0;
|
|
25
|
+
if (this.#document === document) return;
|
|
26
|
+
this.#document = immutableDocument;
|
|
27
|
+
this.#change = void 0;
|
|
28
|
+
this.#notify();
|
|
29
|
+
}
|
|
30
|
+
publish(change) {
|
|
31
|
+
this.#document = change.document;
|
|
32
|
+
this.#change = change;
|
|
33
|
+
this.#notify();
|
|
34
|
+
}
|
|
35
|
+
#notify() {
|
|
36
|
+
for (const listener of [
|
|
37
|
+
...this.#listeners
|
|
38
|
+
])if (this.#listeners.has(listener)) listener();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const resolveDocument = (document, settingsCodecs, componentRenderers)=>{
|
|
42
|
+
if (void 0 === document) return {
|
|
43
|
+
ok: true,
|
|
44
|
+
value: void 0
|
|
45
|
+
};
|
|
46
|
+
if (!settingsCodecs || !componentRenderers) return {
|
|
47
|
+
error: {
|
|
48
|
+
code: "INVALID_DOCUMENT",
|
|
49
|
+
message: "GridLayoutProvider document requires settingsCodecs and componentRenderers",
|
|
50
|
+
path: "$"
|
|
51
|
+
},
|
|
52
|
+
ok: false
|
|
53
|
+
};
|
|
54
|
+
const decoded = decodeGridLayoutDocument(document, settingsCodecs);
|
|
55
|
+
if (!decoded.ok) return decoded;
|
|
56
|
+
const componentById = new Map();
|
|
57
|
+
for(let index = 0; index < decoded.value.components.length; index += 1){
|
|
58
|
+
const component = decoded.value.components[index];
|
|
59
|
+
try {
|
|
60
|
+
componentById.set(component.id, componentRenderers.render(component));
|
|
61
|
+
} catch (cause) {
|
|
62
|
+
return {
|
|
63
|
+
error: {
|
|
64
|
+
code: "COMPONENT_RENDERER_ERROR",
|
|
65
|
+
message: cause instanceof Error ? cause.message : `Unable to render component "${component.id}"`,
|
|
66
|
+
path: `$.components[${index}]`
|
|
67
|
+
},
|
|
68
|
+
ok: false
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
ok: true,
|
|
74
|
+
value: {
|
|
75
|
+
componentById,
|
|
76
|
+
decodedSettings: decoded.value.components.map(({ id, settings, type })=>({
|
|
77
|
+
id,
|
|
78
|
+
settings,
|
|
79
|
+
type
|
|
80
|
+
})),
|
|
81
|
+
layout: gridSnapshotToGridLayoutDescriptor(decoded.value.snapshot),
|
|
82
|
+
document: decoded.value.document,
|
|
83
|
+
placeholderIds: [
|
|
84
|
+
...decoded.value.document.layout.placeholderIds
|
|
85
|
+
],
|
|
86
|
+
snapshot: decoded.value.snapshot
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
const GridLayoutProvider = (props)=>{
|
|
91
|
+
const { children, componentRenderers, componentSettings, document, documentController, onDocumentChange, onDocumentError, serializedLayout, settingsCodecs, options } = props;
|
|
92
|
+
const inheritedTemplateDragSession = useTemplateDragSession();
|
|
93
|
+
const localTemplateDragSession = useMemo(()=>new TemplateDragSession(), []);
|
|
94
|
+
const templateDragSession = inheritedTemplateDragSession ?? localTemplateDragSession;
|
|
95
|
+
const runtimeComponentSettings = useRef(new Map());
|
|
96
|
+
const templateComponentIds = useRef(new Set());
|
|
97
|
+
const documentResolution = useMemo(()=>resolveDocument(document, settingsCodecs, componentRenderers), [
|
|
98
|
+
componentRenderers,
|
|
99
|
+
document,
|
|
100
|
+
settingsCodecs
|
|
101
|
+
]);
|
|
102
|
+
const [decodedDocument, setDecodedDocument] = useState(()=>documentResolution.ok ? documentResolution.value : void 0);
|
|
103
|
+
const reportedError = useRef(void 0);
|
|
104
|
+
useEffect(()=>{
|
|
105
|
+
if (documentResolution.ok) {
|
|
106
|
+
reportedError.current = void 0;
|
|
107
|
+
setDecodedDocument(documentResolution.value);
|
|
108
|
+
const nextSettings = new Map((componentSettings ?? documentResolution.value?.decodedSettings ?? []).map((component)=>[
|
|
109
|
+
component.id,
|
|
110
|
+
component
|
|
111
|
+
]));
|
|
112
|
+
for (const componentId of templateComponentIds.current){
|
|
113
|
+
const runtimeSettings = runtimeComponentSettings.current.get(componentId);
|
|
114
|
+
if (runtimeSettings) nextSettings.set(componentId, runtimeSettings);
|
|
115
|
+
}
|
|
116
|
+
runtimeComponentSettings.current = nextSettings;
|
|
117
|
+
if (documentController && documentResolution.value && void 0 === documentController.getSnapshot()) documentController.replace(documentResolution.value.document);
|
|
118
|
+
} else if (reportedError.current !== documentResolution && onDocumentError) {
|
|
119
|
+
reportedError.current = documentResolution;
|
|
120
|
+
onDocumentError(documentResolution.error);
|
|
121
|
+
} else if (!onDocumentError) throw new GridLayoutDocumentCodecError(documentResolution.error);
|
|
122
|
+
}, [
|
|
123
|
+
componentSettings,
|
|
124
|
+
documentController,
|
|
125
|
+
documentResolution,
|
|
126
|
+
onDocumentError
|
|
127
|
+
]);
|
|
128
|
+
const legacyReader = useMemo(()=>serializedLayout ? createLegacyGridLayoutReader(serializedLayout) : void 0, [
|
|
129
|
+
serializedLayout
|
|
130
|
+
]);
|
|
131
|
+
const getSavedGrid = useCallback((id)=>{
|
|
132
|
+
if (decodedDocument?.snapshot.gridId === id) return {
|
|
133
|
+
components: Object.fromEntries(decodedDocument.snapshot.items.flatMap((item)=>{
|
|
134
|
+
const { column, componentInstanceId, dropTarget, id: itemId, row, ...metadata } = item;
|
|
135
|
+
const component = decodedDocument.componentById.get(componentInstanceId ?? itemId);
|
|
136
|
+
return component ? [
|
|
137
|
+
[
|
|
138
|
+
itemId,
|
|
139
|
+
/*#__PURE__*/ createElement(GridLayoutItem, {
|
|
140
|
+
...metadata,
|
|
141
|
+
"data-drop-target": dropTarget,
|
|
142
|
+
id: itemId,
|
|
143
|
+
key: itemId,
|
|
144
|
+
style: {
|
|
145
|
+
gridArea: `${row.start}/${column.start}/${row.start + row.span}/${column.start + column.span}`
|
|
146
|
+
}
|
|
147
|
+
}, component)
|
|
148
|
+
]
|
|
149
|
+
] : [];
|
|
150
|
+
})),
|
|
151
|
+
id,
|
|
152
|
+
layout: decodedDocument.layout,
|
|
153
|
+
placeholderIds: decodedDocument.placeholderIds
|
|
154
|
+
};
|
|
155
|
+
return legacyReader?.getSavedGrid(id);
|
|
156
|
+
}, [
|
|
157
|
+
decodedDocument,
|
|
158
|
+
legacyReader
|
|
159
|
+
]);
|
|
160
|
+
const renderTemplateComponent = useCallback((template, id)=>{
|
|
161
|
+
if (!isTypedComponentTemplate(template)) return;
|
|
162
|
+
if (!settingsCodecs || !componentRenderers) throw new Error("Typed component templates require settingsCodecs and componentRenderers");
|
|
163
|
+
const decoded = settingsCodecs.decode({
|
|
164
|
+
id,
|
|
165
|
+
...template.component
|
|
166
|
+
});
|
|
167
|
+
if (!decoded.ok) throw new GridLayoutDocumentCodecError({
|
|
168
|
+
code: "COMPONENT_SETTINGS_ERROR",
|
|
169
|
+
componentError: decoded.error,
|
|
170
|
+
message: decoded.error.message,
|
|
171
|
+
path: "$.component",
|
|
172
|
+
version: decoded.error.version
|
|
173
|
+
});
|
|
174
|
+
runtimeComponentSettings.current.set(id, {
|
|
175
|
+
id,
|
|
176
|
+
settings: decoded.value.settings,
|
|
177
|
+
type: decoded.value.type
|
|
178
|
+
});
|
|
179
|
+
templateComponentIds.current.add(id);
|
|
180
|
+
return componentRenderers.render(decoded.value);
|
|
181
|
+
}, [
|
|
182
|
+
componentRenderers,
|
|
183
|
+
settingsCodecs
|
|
184
|
+
]);
|
|
185
|
+
const releaseTemplateComponent = useCallback((id)=>{
|
|
186
|
+
runtimeComponentSettings.current.delete(id);
|
|
187
|
+
templateComponentIds.current.delete(id);
|
|
188
|
+
}, []);
|
|
189
|
+
const onCommittedSnapshot = useCallback((transition, placeholderIds)=>{
|
|
190
|
+
if (!onDocumentChange && !documentController) return;
|
|
191
|
+
if (!settingsCodecs) {
|
|
192
|
+
const error = {
|
|
193
|
+
code: "INVALID_DOCUMENT",
|
|
194
|
+
message: "onDocumentChange requires a GridComponentSettingsRegistry",
|
|
195
|
+
path: "$.components"
|
|
196
|
+
};
|
|
197
|
+
if (onDocumentError) return void onDocumentError(error);
|
|
198
|
+
throw new GridLayoutDocumentCodecError(error);
|
|
199
|
+
}
|
|
200
|
+
const { previous, snapshot } = transition;
|
|
201
|
+
const availableSettings = [
|
|
202
|
+
...runtimeComponentSettings.current.values()
|
|
203
|
+
];
|
|
204
|
+
const referencedComponentIds = new Set(snapshot.items.map(({ componentInstanceId, id })=>componentInstanceId ?? id));
|
|
205
|
+
const settings = availableSettings.filter(({ id })=>referencedComponentIds.has(id));
|
|
206
|
+
const encoded = encodeGridLayoutDocument(snapshot, settingsCodecs, {
|
|
207
|
+
componentSettings: settings,
|
|
208
|
+
placeholderIds
|
|
209
|
+
});
|
|
210
|
+
if (encoded.ok) {
|
|
211
|
+
const currentComponentIds = new Set(snapshot.items.map(({ componentInstanceId, id })=>componentInstanceId ?? id));
|
|
212
|
+
const removedComponentInstanceIds = previous.items.map(({ componentInstanceId, id })=>componentInstanceId ?? id).filter((componentId)=>!currentComponentIds.has(componentId) && runtimeComponentSettings.current.has(componentId));
|
|
213
|
+
const change = {
|
|
214
|
+
document: encoded.value,
|
|
215
|
+
kind: transition.kind,
|
|
216
|
+
removedComponentInstanceIds,
|
|
217
|
+
revision: snapshot.revision
|
|
218
|
+
};
|
|
219
|
+
documentController?.publish(change);
|
|
220
|
+
onDocumentChange?.(encoded.value, change);
|
|
221
|
+
for (const componentId of removedComponentInstanceIds){
|
|
222
|
+
runtimeComponentSettings.current.delete(componentId);
|
|
223
|
+
templateComponentIds.current.delete(componentId);
|
|
224
|
+
}
|
|
225
|
+
} else if (onDocumentError) onDocumentError(encoded.error);
|
|
226
|
+
else throw new GridLayoutDocumentCodecError(encoded.error);
|
|
227
|
+
}, [
|
|
228
|
+
documentController,
|
|
229
|
+
onDocumentChange,
|
|
230
|
+
onDocumentError,
|
|
231
|
+
settingsCodecs
|
|
232
|
+
]);
|
|
233
|
+
return /*#__PURE__*/ jsx(TemplateDragSessionContext.Provider, {
|
|
234
|
+
value: templateDragSession,
|
|
235
|
+
children: /*#__PURE__*/ jsx(GridLayoutProviderContext.Provider, {
|
|
236
|
+
value: {
|
|
237
|
+
getSavedGrid,
|
|
238
|
+
onCommittedSnapshot,
|
|
239
|
+
options,
|
|
240
|
+
releaseTemplateComponent,
|
|
241
|
+
renderTemplateComponent
|
|
242
|
+
},
|
|
243
|
+
children: void 0 !== document && void 0 === decodedDocument ? null : children
|
|
244
|
+
})
|
|
245
|
+
});
|
|
246
|
+
};
|
|
247
|
+
const useGridChangeHandler = ()=>{
|
|
248
|
+
const { onCommittedSnapshot, releaseTemplateComponent, renderTemplateComponent } = useContext(GridLayoutProviderContext);
|
|
249
|
+
return {
|
|
250
|
+
onCommittedSnapshot,
|
|
251
|
+
releaseTemplateComponent,
|
|
252
|
+
renderTemplateComponent
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
const useSavedGrid = ()=>{
|
|
256
|
+
const { getSavedGrid } = useContext(GridLayoutProviderContext);
|
|
257
|
+
return getSavedGrid;
|
|
258
|
+
};
|
|
259
|
+
const useGridLayoutOptions = ()=>{
|
|
260
|
+
const { options } = useContext(GridLayoutProviderContext);
|
|
261
|
+
return options;
|
|
262
|
+
};
|
|
263
|
+
export { GridLayoutDocumentController, GridLayoutProvider, useGridChangeHandler, useGridLayoutOptions, useSavedGrid };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const css = `
|
|
2
|
+
.vuuGridLayoutStackedItem {
|
|
3
|
+
& .saltTabsNext {
|
|
4
|
+
& .saltTabBar {
|
|
5
|
+
justify-content: flex-start;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
& .saltTabListNext {
|
|
9
|
+
width: auto;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
margin-top: 3px;
|
|
13
|
+
|
|
14
|
+
& .saltTabNext {
|
|
15
|
+
margin-left: 2px;
|
|
16
|
+
|
|
17
|
+
&:first-child {
|
|
18
|
+
margin-left: 0;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
`;
|
|
26
|
+
export default css;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createElement, useCallback, useEffect } from "react";
|
|
3
|
+
import { Tab, TabBar, TabList, TabTrigger, Tabs } from "@salt-ds/core";
|
|
4
|
+
import { IconButton } from "@vuu-ui/vuu-ui-controls";
|
|
5
|
+
import { useComponentCssInjection } from "@salt-ds/styles";
|
|
6
|
+
import { useWindow } from "@salt-ds/window";
|
|
7
|
+
import clsx from "clsx";
|
|
8
|
+
import { useDragContext } from "./drag-drop-next/DragDropProviderNext.js";
|
|
9
|
+
import { useGridLayoutDispatch, useGridSnapshot } from "./GridLayoutContext.js";
|
|
10
|
+
import { resolveMinimumGridItemSize } from "./GridModel.js";
|
|
11
|
+
import { TabMenu } from "./TabMenu.js";
|
|
12
|
+
import { useEditTabName } from "./useEditTabName.js";
|
|
13
|
+
import { useGridChildProps } from "./useGridChildProps.js";
|
|
14
|
+
import GridLayoutStackedItem from "./GridLayoutStackedItem.css";
|
|
15
|
+
const classBaseItem = "vuuGridLayoutStackedItem";
|
|
16
|
+
const GridLayoutStackedtem_GridLayoutStackedItem = ({ allowAddTab, children, className: classNameProp, header, id, getNewComponent, minHeight, minWidth, resizeable, showMenu, style: styleProp, title, ...htmlAttributes })=>{
|
|
17
|
+
const targetWindow = useWindow();
|
|
18
|
+
useComponentCssInjection({
|
|
19
|
+
testId: "vuu-grid-layout-stacked-item",
|
|
20
|
+
css: GridLayoutStackedItem,
|
|
21
|
+
window: targetWindow
|
|
22
|
+
});
|
|
23
|
+
const { dialog, showTabEditDialog } = useEditTabName({
|
|
24
|
+
getNewComponent,
|
|
25
|
+
id
|
|
26
|
+
});
|
|
27
|
+
const { registerTabsForDragDrop } = useDragContext();
|
|
28
|
+
const modelMinHeight = resolveMinimumGridItemSize(minHeight, styleProp?.minHeight);
|
|
29
|
+
const modelMinWidth = resolveMinimumGridItemSize(minWidth, styleProp?.minWidth);
|
|
30
|
+
const { gridArea, horizontalSplitter, verticalSplitter } = useGridChildProps({
|
|
31
|
+
id,
|
|
32
|
+
minHeight: modelMinHeight,
|
|
33
|
+
minWidth: modelMinWidth,
|
|
34
|
+
resizeable,
|
|
35
|
+
style: styleProp,
|
|
36
|
+
type: "stacked-content"
|
|
37
|
+
});
|
|
38
|
+
const dispatch = useGridLayoutDispatch();
|
|
39
|
+
const snapshot = useGridSnapshot();
|
|
40
|
+
const stack = snapshot.stacks.find((candidate)=>candidate.id === id);
|
|
41
|
+
if (!stack) throw Error(`[GridLayoutStackedItem] canonical stack #${id} not found`);
|
|
42
|
+
const itemById = new Map(snapshot.items.map((item)=>[
|
|
43
|
+
item.id,
|
|
44
|
+
item
|
|
45
|
+
]));
|
|
46
|
+
const tabOrderKey = stack.itemIds.join("\u0000");
|
|
47
|
+
useEffect(()=>tabOrderKey ? registerTabsForDragDrop(id) : void 0, [
|
|
48
|
+
id,
|
|
49
|
+
registerTabsForDragDrop,
|
|
50
|
+
tabOrderKey
|
|
51
|
+
]);
|
|
52
|
+
const handleTabSelectionChange = useCallback((_, value)=>{
|
|
53
|
+
dispatch({
|
|
54
|
+
type: "select-tab",
|
|
55
|
+
itemId: value,
|
|
56
|
+
stackId: id
|
|
57
|
+
});
|
|
58
|
+
}, [
|
|
59
|
+
dispatch,
|
|
60
|
+
id
|
|
61
|
+
]);
|
|
62
|
+
const className = clsx(classBaseItem, "vuuGridLayoutItem", {
|
|
63
|
+
"has-h-splitter": horizontalSplitter,
|
|
64
|
+
"has-v-splitter": verticalSplitter
|
|
65
|
+
});
|
|
66
|
+
const style = {
|
|
67
|
+
...styleProp,
|
|
68
|
+
gridArea,
|
|
69
|
+
...void 0 === minHeight ? {} : {
|
|
70
|
+
minHeight
|
|
71
|
+
},
|
|
72
|
+
...void 0 === minWidth ? {} : {
|
|
73
|
+
minWidth
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const tabsId = `tabs-${id}`;
|
|
77
|
+
const handleClickAddTab = useCallback(()=>{
|
|
78
|
+
showTabEditDialog();
|
|
79
|
+
}, [
|
|
80
|
+
showTabEditDialog
|
|
81
|
+
]);
|
|
82
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
83
|
+
children: [
|
|
84
|
+
/*#__PURE__*/ createElement("div", {
|
|
85
|
+
...htmlAttributes,
|
|
86
|
+
className: clsx(className),
|
|
87
|
+
id: id,
|
|
88
|
+
key: id,
|
|
89
|
+
style: style
|
|
90
|
+
}, /*#__PURE__*/ jsx(Tabs, {
|
|
91
|
+
onChange: handleTabSelectionChange,
|
|
92
|
+
value: stack.selectedItemId,
|
|
93
|
+
children: /*#__PURE__*/ jsxs(TabBar, {
|
|
94
|
+
divider: true,
|
|
95
|
+
children: [
|
|
96
|
+
/*#__PURE__*/ jsx(TabList, {
|
|
97
|
+
appearance: "transparent",
|
|
98
|
+
className: "vuuDragContainer",
|
|
99
|
+
id: tabsId,
|
|
100
|
+
children: stack.itemIds.map((gridLayoutItemId, index)=>{
|
|
101
|
+
const label = itemById.get(gridLayoutItemId)?.title ?? gridLayoutItemId;
|
|
102
|
+
return /*#__PURE__*/ jsxs(Tab, {
|
|
103
|
+
className: "vuuDraggableItem",
|
|
104
|
+
"data-index": index,
|
|
105
|
+
"data-grid-layout-item-id": gridLayoutItemId,
|
|
106
|
+
"data-label": label,
|
|
107
|
+
draggable: true,
|
|
108
|
+
value: gridLayoutItemId,
|
|
109
|
+
children: [
|
|
110
|
+
/*#__PURE__*/ jsx(TabTrigger, {
|
|
111
|
+
children: label
|
|
112
|
+
}),
|
|
113
|
+
showMenu ? /*#__PURE__*/ jsx(TabMenu, {
|
|
114
|
+
layoutItemId: gridLayoutItemId,
|
|
115
|
+
tabLabel: label
|
|
116
|
+
}) : null
|
|
117
|
+
]
|
|
118
|
+
}, gridLayoutItemId);
|
|
119
|
+
})
|
|
120
|
+
}, tabOrderKey),
|
|
121
|
+
allowAddTab ? /*#__PURE__*/ jsx(IconButton, {
|
|
122
|
+
"aria-label": "Create Tab",
|
|
123
|
+
className: `${classBaseItem}-addTabButton`,
|
|
124
|
+
"data-embedded": true,
|
|
125
|
+
icon: "add",
|
|
126
|
+
"data-overflow-priority": "1",
|
|
127
|
+
onClick: handleClickAddTab,
|
|
128
|
+
variant: "secondary",
|
|
129
|
+
tabIndex: -1
|
|
130
|
+
}, "addButton") : null
|
|
131
|
+
]
|
|
132
|
+
})
|
|
133
|
+
})),
|
|
134
|
+
dialog
|
|
135
|
+
]
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
const GridLayoutStackedItemType = (/*#__PURE__*/ createElement(GridLayoutStackedtem_GridLayoutStackedItem)).type;
|
|
139
|
+
const isGridLayoutStackedItem = (element)=>element.type === GridLayoutStackedItemType;
|
|
140
|
+
export { GridLayoutStackedtem_GridLayoutStackedItem as GridLayoutStackedItem, isGridLayoutStackedItem };
|