pne-ui 3.0.27 → 3.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/component/widget-board/index.d.ts +0 -1
- package/cjs/component/widget-board/index.js +0 -1
- package/cjs/component/widget-board/index.js.map +1 -1
- package/cjs/component/widget-board/layoutPersistence.d.ts +1 -37
- package/cjs/component/widget-board/layoutPersistence.js +1 -126
- package/cjs/component/widget-board/layoutPersistence.js.map +1 -1
- package/esm/component/widget-board/index.d.ts +0 -1
- package/esm/component/widget-board/index.js +0 -1
- package/esm/component/widget-board/index.js.map +1 -1
- package/esm/component/widget-board/layoutPersistence.d.ts +1 -37
- package/esm/component/widget-board/layoutPersistence.js +0 -122
- package/esm/component/widget-board/layoutPersistence.js.map +1 -1
- package/package.json +1 -1
|
@@ -5,6 +5,5 @@ tslib_1.__exportStar(require("./WidgetBoard"), exports);
|
|
|
5
5
|
tslib_1.__exportStar(require("./types"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./WidgetLayoutsPanel"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./layoutPersistence"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./useWidgetLayoutsManager"), exports);
|
|
9
8
|
tslib_1.__exportStar(require("./widgetLayoutsPanelStore"), exports);
|
|
10
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/component/widget-board/index.ts"],"names":[],"mappings":";;;AAAA,wDAA6B;AAC7B,kDAAuB;AACvB,+DAAoC;AACpC,8DAAmC;AACnC,oEAAyC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/component/widget-board/index.ts"],"names":[],"mappings":";;;AAAA,wDAA6B;AAC7B,kDAAuB;AACvB,+DAAoC;AACpC,8DAAmC;AACnC,oEAAyC"}
|
|
@@ -1,38 +1,2 @@
|
|
|
1
|
-
import type { BreakpointLayoutConfig,
|
|
2
|
-
export type WidgetLayoutPlacement = {
|
|
3
|
-
columnSpan?: number;
|
|
4
|
-
rowSpan?: number;
|
|
5
|
-
columnOffset?: WidgetLayoutConfig['defaultSize']['columnOffset'];
|
|
6
|
-
isHidden?: boolean;
|
|
7
|
-
isCollapsed?: boolean;
|
|
8
|
-
};
|
|
9
|
-
export type WidgetLayoutSettingsBreakpoint = {
|
|
10
|
-
columns?: number;
|
|
11
|
-
widgets?: Record<string, WidgetLayoutPlacement>;
|
|
12
|
-
};
|
|
13
|
-
export type WidgetLayoutSettingsLayout = {
|
|
14
|
-
id: string;
|
|
15
|
-
name?: string;
|
|
16
|
-
layoutByBreakpoint?: Record<number | string, WidgetLayoutSettingsBreakpoint>;
|
|
17
|
-
version?: string;
|
|
18
|
-
updatedAt?: string;
|
|
19
|
-
};
|
|
20
|
-
export type WidgetLayoutSettings = {
|
|
21
|
-
layouts?: WidgetLayoutSettingsLayout[];
|
|
22
|
-
selectedLayoutId?: string;
|
|
23
|
-
};
|
|
24
|
-
export declare const normalizeWidgetLayoutSettings: (settings: WidgetLayoutSettings | null | undefined, defaultOption: WidgetBoardLayoutOption, breakpoints?: readonly number[]) => WidgetBoardLoadLayoutsResult;
|
|
25
|
-
export declare const buildLayoutSettingsPayload: (options: WidgetBoardLayoutOption[], selectedId?: string) => WidgetLayoutSettings;
|
|
1
|
+
import type { BreakpointLayoutConfig, WidgetBoardState } from './types';
|
|
26
2
|
export declare const buildPresetFromState: (state: WidgetBoardState | null, baseLayoutByBreakpoint: Record<number | string, BreakpointLayoutConfig>, breakpoints?: readonly number[]) => Record<number | string, BreakpointLayoutConfig>;
|
|
27
|
-
type RemoteHandlersParams = {
|
|
28
|
-
defaultOption: WidgetBoardLayoutOption;
|
|
29
|
-
breakpoints?: readonly number[];
|
|
30
|
-
loadSettings?: () => Promise<WidgetLayoutSettings | null | undefined>;
|
|
31
|
-
saveSettings?: (settings: WidgetLayoutSettings) => Promise<void>;
|
|
32
|
-
skipWhenStorybook?: boolean;
|
|
33
|
-
};
|
|
34
|
-
export declare const createWidgetLayoutsRemoteHandlers: ({ defaultOption, breakpoints, loadSettings, saveSettings, skipWhenStorybook, }: RemoteHandlersParams) => {
|
|
35
|
-
loadLayouts: () => Promise<WidgetBoardLoadLayoutsResult>;
|
|
36
|
-
saveLayouts: (options: WidgetBoardLayoutOption[], selectedId?: string) => Promise<void>;
|
|
37
|
-
};
|
|
38
|
-
export {};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.buildPresetFromState = void 0;
|
|
4
4
|
const breakpoints_1 = require("../../common/responsive/breakpoints");
|
|
5
|
-
const isStorybookRuntime = () => typeof window !== 'undefined' &&
|
|
6
|
-
(Boolean(window.__STORYBOOK_CLIENT_API__) || Boolean(window.__STORYBOOK_ADDONS_CHANNEL__));
|
|
7
5
|
const cloneLayoutConfig = (config) => ({
|
|
8
6
|
columns: config.columns,
|
|
9
7
|
widgets: Object.fromEntries(Object.entries(config.widgets).map(([id, widget]) => [
|
|
@@ -15,97 +13,6 @@ const cloneLayoutConfig = (config) => ({
|
|
|
15
13
|
},
|
|
16
14
|
])),
|
|
17
15
|
});
|
|
18
|
-
const mergeWidgetPlacement = (base, remote) => {
|
|
19
|
-
if (!remote)
|
|
20
|
-
return base;
|
|
21
|
-
return {
|
|
22
|
-
defaultSize: {
|
|
23
|
-
...base.defaultSize,
|
|
24
|
-
columnSpan: remote.columnSpan ?? base.defaultSize.columnSpan,
|
|
25
|
-
rowSpan: remote.rowSpan ?? base.defaultSize.rowSpan,
|
|
26
|
-
columnOffset: remote.columnOffset ?? base.defaultSize.columnOffset,
|
|
27
|
-
},
|
|
28
|
-
limits: base.limits,
|
|
29
|
-
initialState: {
|
|
30
|
-
...base.initialState,
|
|
31
|
-
isHidden: remote.isHidden ?? base.initialState?.isHidden,
|
|
32
|
-
isCollapsed: remote.isCollapsed ?? base.initialState?.isCollapsed,
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
const normalizeLayoutMap = (layoutByBreakpoint, baseLayoutByBreakpoint, breakpoints) => {
|
|
37
|
-
if (!layoutByBreakpoint)
|
|
38
|
-
return null;
|
|
39
|
-
const normalized = {};
|
|
40
|
-
breakpoints.forEach(breakpoint => {
|
|
41
|
-
const base = baseLayoutByBreakpoint[breakpoint] ?? baseLayoutByBreakpoint[String(breakpoint)];
|
|
42
|
-
if (!base)
|
|
43
|
-
return;
|
|
44
|
-
const candidate = layoutByBreakpoint[breakpoint] ?? layoutByBreakpoint[String(breakpoint)];
|
|
45
|
-
if (!candidate)
|
|
46
|
-
return;
|
|
47
|
-
const widgets = {};
|
|
48
|
-
Object.keys(base.widgets).forEach(id => {
|
|
49
|
-
widgets[id] = mergeWidgetPlacement(base.widgets[id], candidate.widgets?.[id]);
|
|
50
|
-
});
|
|
51
|
-
normalized[breakpoint] = {
|
|
52
|
-
columns: candidate.columns ?? base.columns,
|
|
53
|
-
widgets,
|
|
54
|
-
};
|
|
55
|
-
});
|
|
56
|
-
if (Object.keys(normalized).length === 0) {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
return normalized;
|
|
60
|
-
};
|
|
61
|
-
const normalizeLayoutOption = (layout, baseLayoutByBreakpoint, breakpoints) => {
|
|
62
|
-
const layoutByBreakpoint = normalizeLayoutMap(layout.layoutByBreakpoint, baseLayoutByBreakpoint, breakpoints);
|
|
63
|
-
if (!layoutByBreakpoint)
|
|
64
|
-
return null;
|
|
65
|
-
return {
|
|
66
|
-
id: layout.id,
|
|
67
|
-
name: layout.name || 'Layout',
|
|
68
|
-
layoutByBreakpoint,
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
const normalizeWidgetLayoutSettings = (settings, defaultOption, breakpoints = breakpoints_1.DEFAULT_BREAKPOINTS) => {
|
|
72
|
-
const baseLayout = defaultOption.layoutByBreakpoint;
|
|
73
|
-
const layouts = settings?.layouts ?? [];
|
|
74
|
-
const options = layouts
|
|
75
|
-
.map(layout => normalizeLayoutOption(layout, baseLayout, breakpoints))
|
|
76
|
-
.filter((option) => Boolean(option));
|
|
77
|
-
const optionsWithDefault = options.some(option => option.id === defaultOption.id) ? options : [...options, defaultOption];
|
|
78
|
-
const selectedFromServer = settings?.selectedLayoutId && optionsWithDefault.some(option => option.id === settings.selectedLayoutId)
|
|
79
|
-
? settings.selectedLayoutId
|
|
80
|
-
: optionsWithDefault[0]?.id ?? defaultOption.id;
|
|
81
|
-
return { options: optionsWithDefault, selectedId: selectedFromServer };
|
|
82
|
-
};
|
|
83
|
-
exports.normalizeWidgetLayoutSettings = normalizeWidgetLayoutSettings;
|
|
84
|
-
const mapOptionToSettingsLayout = (option) => ({
|
|
85
|
-
id: option.id,
|
|
86
|
-
name: option.name,
|
|
87
|
-
layoutByBreakpoint: Object.fromEntries(Object.entries(option.layoutByBreakpoint).map(([breakpoint, config]) => [
|
|
88
|
-
breakpoint,
|
|
89
|
-
{
|
|
90
|
-
columns: config.columns,
|
|
91
|
-
widgets: Object.fromEntries(Object.entries(config.widgets).map(([id, widget]) => [
|
|
92
|
-
id,
|
|
93
|
-
{
|
|
94
|
-
columnSpan: widget.defaultSize.columnSpan,
|
|
95
|
-
rowSpan: widget.defaultSize.rowSpan,
|
|
96
|
-
columnOffset: widget.defaultSize.columnOffset,
|
|
97
|
-
isHidden: widget.initialState?.isHidden,
|
|
98
|
-
isCollapsed: widget.initialState?.isCollapsed,
|
|
99
|
-
},
|
|
100
|
-
])),
|
|
101
|
-
},
|
|
102
|
-
])),
|
|
103
|
-
});
|
|
104
|
-
const buildLayoutSettingsPayload = (options, selectedId) => ({
|
|
105
|
-
layouts: options.map(mapOptionToSettingsLayout),
|
|
106
|
-
selectedLayoutId: selectedId && options.some(option => option.id === selectedId) ? selectedId : options[0]?.id,
|
|
107
|
-
});
|
|
108
|
-
exports.buildLayoutSettingsPayload = buildLayoutSettingsPayload;
|
|
109
16
|
const buildPresetFromState = (state, baseLayoutByBreakpoint, breakpoints = breakpoints_1.DEFAULT_BREAKPOINTS) => {
|
|
110
17
|
if (!state) {
|
|
111
18
|
return Object.fromEntries(Object.entries(baseLayoutByBreakpoint).map(([breakpoint, config]) => [breakpoint, cloneLayoutConfig(config)]));
|
|
@@ -153,36 +60,4 @@ const buildPresetFromState = (state, baseLayoutByBreakpoint, breakpoints = break
|
|
|
153
60
|
return layoutByBreakpoint;
|
|
154
61
|
};
|
|
155
62
|
exports.buildPresetFromState = buildPresetFromState;
|
|
156
|
-
const createWidgetLayoutsRemoteHandlers = ({ defaultOption, breakpoints = breakpoints_1.DEFAULT_BREAKPOINTS, loadSettings, saveSettings, skipWhenStorybook = true, }) => {
|
|
157
|
-
const shouldSkipRemote = skipWhenStorybook && isStorybookRuntime();
|
|
158
|
-
const loadLayouts = async () => {
|
|
159
|
-
if (!loadSettings || shouldSkipRemote) {
|
|
160
|
-
return { options: [defaultOption], selectedId: defaultOption.id };
|
|
161
|
-
}
|
|
162
|
-
try {
|
|
163
|
-
const response = await loadSettings();
|
|
164
|
-
const normalized = (0, exports.normalizeWidgetLayoutSettings)(response, defaultOption, breakpoints);
|
|
165
|
-
return normalized ?? { options: [defaultOption], selectedId: defaultOption.id };
|
|
166
|
-
}
|
|
167
|
-
catch (error) {
|
|
168
|
-
console.warn('Failed to load widget layouts', error);
|
|
169
|
-
return { options: [defaultOption], selectedId: defaultOption.id };
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
const saveLayouts = async (options, selectedId) => {
|
|
173
|
-
if (!saveSettings || shouldSkipRemote)
|
|
174
|
-
return;
|
|
175
|
-
const safeOptions = options.length ? options : [defaultOption];
|
|
176
|
-
const resolvedSelected = selectedId && safeOptions.some(option => option.id === selectedId) ? selectedId : safeOptions[0]?.id ?? defaultOption.id;
|
|
177
|
-
const payload = (0, exports.buildLayoutSettingsPayload)(safeOptions, resolvedSelected);
|
|
178
|
-
try {
|
|
179
|
-
await saveSettings(payload);
|
|
180
|
-
}
|
|
181
|
-
catch (error) {
|
|
182
|
-
console.warn('Failed to save widget layouts', error);
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
return { loadLayouts, saveLayouts };
|
|
186
|
-
};
|
|
187
|
-
exports.createWidgetLayoutsRemoteHandlers = createWidgetLayoutsRemoteHandlers;
|
|
188
63
|
//# sourceMappingURL=layoutPersistence.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layoutPersistence.js","sourceRoot":"","sources":["../../../src/component/widget-board/layoutPersistence.ts"],"names":[],"mappings":";;;AAAA,qEAAyE;
|
|
1
|
+
{"version":3,"file":"layoutPersistence.js","sourceRoot":"","sources":["../../../src/component/widget-board/layoutPersistence.ts"],"names":[],"mappings":";;;AAAA,qEAAyE;AAGzE,MAAM,iBAAiB,GAAG,CAAC,MAA8B,EAA0B,EAAE,CAAC,CAAC;IACnF,OAAO,EAAE,MAAM,CAAC,OAAO;IACvB,OAAO,EAAE,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC;QACjD,EAAE;QACF;YACI,WAAW,EAAE,EAAE,GAAG,MAAM,CAAC,WAAW,EAAE;YACtC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS;YACxD,YAAY,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,SAAS;SAC7E;KACJ,CAAC,CACiC;CAC1C,CAAC,CAAA;AAEK,MAAM,oBAAoB,GAAG,CAChC,KAA8B,EAC9B,sBAAuE,EACvE,cAAiC,iCAAmB,EACL,EAAE;IACjD,IAAI,CAAC,KA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A;AACvB,cAAc,sBAAsB,CAAA;AACpC,cAAc,qBAAqB,CAAA;AACnC,cAAc,2BAA2B,CAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/component/widget-board/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,SAAS,CAAA;AACvB,cAAc,sBAAsB,CAAA;AACpC,cAAc,qBAAqB,CAAA;AACnC,cAAc,2BAA2B,CAAA"}
|
|
@@ -1,38 +1,2 @@
|
|
|
1
|
-
import type { BreakpointLayoutConfig,
|
|
2
|
-
export type WidgetLayoutPlacement = {
|
|
3
|
-
columnSpan?: number;
|
|
4
|
-
rowSpan?: number;
|
|
5
|
-
columnOffset?: WidgetLayoutConfig['defaultSize']['columnOffset'];
|
|
6
|
-
isHidden?: boolean;
|
|
7
|
-
isCollapsed?: boolean;
|
|
8
|
-
};
|
|
9
|
-
export type WidgetLayoutSettingsBreakpoint = {
|
|
10
|
-
columns?: number;
|
|
11
|
-
widgets?: Record<string, WidgetLayoutPlacement>;
|
|
12
|
-
};
|
|
13
|
-
export type WidgetLayoutSettingsLayout = {
|
|
14
|
-
id: string;
|
|
15
|
-
name?: string;
|
|
16
|
-
layoutByBreakpoint?: Record<number | string, WidgetLayoutSettingsBreakpoint>;
|
|
17
|
-
version?: string;
|
|
18
|
-
updatedAt?: string;
|
|
19
|
-
};
|
|
20
|
-
export type WidgetLayoutSettings = {
|
|
21
|
-
layouts?: WidgetLayoutSettingsLayout[];
|
|
22
|
-
selectedLayoutId?: string;
|
|
23
|
-
};
|
|
24
|
-
export declare const normalizeWidgetLayoutSettings: (settings: WidgetLayoutSettings | null | undefined, defaultOption: WidgetBoardLayoutOption, breakpoints?: readonly number[]) => WidgetBoardLoadLayoutsResult;
|
|
25
|
-
export declare const buildLayoutSettingsPayload: (options: WidgetBoardLayoutOption[], selectedId?: string) => WidgetLayoutSettings;
|
|
1
|
+
import type { BreakpointLayoutConfig, WidgetBoardState } from './types';
|
|
26
2
|
export declare const buildPresetFromState: (state: WidgetBoardState | null, baseLayoutByBreakpoint: Record<number | string, BreakpointLayoutConfig>, breakpoints?: readonly number[]) => Record<number | string, BreakpointLayoutConfig>;
|
|
27
|
-
type RemoteHandlersParams = {
|
|
28
|
-
defaultOption: WidgetBoardLayoutOption;
|
|
29
|
-
breakpoints?: readonly number[];
|
|
30
|
-
loadSettings?: () => Promise<WidgetLayoutSettings | null | undefined>;
|
|
31
|
-
saveSettings?: (settings: WidgetLayoutSettings) => Promise<void>;
|
|
32
|
-
skipWhenStorybook?: boolean;
|
|
33
|
-
};
|
|
34
|
-
export declare const createWidgetLayoutsRemoteHandlers: ({ defaultOption, breakpoints, loadSettings, saveSettings, skipWhenStorybook, }: RemoteHandlersParams) => {
|
|
35
|
-
loadLayouts: () => Promise<WidgetBoardLoadLayoutsResult>;
|
|
36
|
-
saveLayouts: (options: WidgetBoardLayoutOption[], selectedId?: string) => Promise<void>;
|
|
37
|
-
};
|
|
38
|
-
export {};
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { DEFAULT_BREAKPOINTS } from '../../common/responsive/breakpoints';
|
|
2
|
-
const isStorybookRuntime = () => typeof window !== 'undefined' &&
|
|
3
|
-
(Boolean(window.__STORYBOOK_CLIENT_API__) || Boolean(window.__STORYBOOK_ADDONS_CHANNEL__));
|
|
4
2
|
const cloneLayoutConfig = (config) => ({
|
|
5
3
|
columns: config.columns,
|
|
6
4
|
widgets: Object.fromEntries(Object.entries(config.widgets).map(([id, widget]) => [
|
|
@@ -12,95 +10,6 @@ const cloneLayoutConfig = (config) => ({
|
|
|
12
10
|
},
|
|
13
11
|
])),
|
|
14
12
|
});
|
|
15
|
-
const mergeWidgetPlacement = (base, remote) => {
|
|
16
|
-
if (!remote)
|
|
17
|
-
return base;
|
|
18
|
-
return {
|
|
19
|
-
defaultSize: {
|
|
20
|
-
...base.defaultSize,
|
|
21
|
-
columnSpan: remote.columnSpan ?? base.defaultSize.columnSpan,
|
|
22
|
-
rowSpan: remote.rowSpan ?? base.defaultSize.rowSpan,
|
|
23
|
-
columnOffset: remote.columnOffset ?? base.defaultSize.columnOffset,
|
|
24
|
-
},
|
|
25
|
-
limits: base.limits,
|
|
26
|
-
initialState: {
|
|
27
|
-
...base.initialState,
|
|
28
|
-
isHidden: remote.isHidden ?? base.initialState?.isHidden,
|
|
29
|
-
isCollapsed: remote.isCollapsed ?? base.initialState?.isCollapsed,
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
const normalizeLayoutMap = (layoutByBreakpoint, baseLayoutByBreakpoint, breakpoints) => {
|
|
34
|
-
if (!layoutByBreakpoint)
|
|
35
|
-
return null;
|
|
36
|
-
const normalized = {};
|
|
37
|
-
breakpoints.forEach(breakpoint => {
|
|
38
|
-
const base = baseLayoutByBreakpoint[breakpoint] ?? baseLayoutByBreakpoint[String(breakpoint)];
|
|
39
|
-
if (!base)
|
|
40
|
-
return;
|
|
41
|
-
const candidate = layoutByBreakpoint[breakpoint] ?? layoutByBreakpoint[String(breakpoint)];
|
|
42
|
-
if (!candidate)
|
|
43
|
-
return;
|
|
44
|
-
const widgets = {};
|
|
45
|
-
Object.keys(base.widgets).forEach(id => {
|
|
46
|
-
widgets[id] = mergeWidgetPlacement(base.widgets[id], candidate.widgets?.[id]);
|
|
47
|
-
});
|
|
48
|
-
normalized[breakpoint] = {
|
|
49
|
-
columns: candidate.columns ?? base.columns,
|
|
50
|
-
widgets,
|
|
51
|
-
};
|
|
52
|
-
});
|
|
53
|
-
if (Object.keys(normalized).length === 0) {
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
return normalized;
|
|
57
|
-
};
|
|
58
|
-
const normalizeLayoutOption = (layout, baseLayoutByBreakpoint, breakpoints) => {
|
|
59
|
-
const layoutByBreakpoint = normalizeLayoutMap(layout.layoutByBreakpoint, baseLayoutByBreakpoint, breakpoints);
|
|
60
|
-
if (!layoutByBreakpoint)
|
|
61
|
-
return null;
|
|
62
|
-
return {
|
|
63
|
-
id: layout.id,
|
|
64
|
-
name: layout.name || 'Layout',
|
|
65
|
-
layoutByBreakpoint,
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
export const normalizeWidgetLayoutSettings = (settings, defaultOption, breakpoints = DEFAULT_BREAKPOINTS) => {
|
|
69
|
-
const baseLayout = defaultOption.layoutByBreakpoint;
|
|
70
|
-
const layouts = settings?.layouts ?? [];
|
|
71
|
-
const options = layouts
|
|
72
|
-
.map(layout => normalizeLayoutOption(layout, baseLayout, breakpoints))
|
|
73
|
-
.filter((option) => Boolean(option));
|
|
74
|
-
const optionsWithDefault = options.some(option => option.id === defaultOption.id) ? options : [...options, defaultOption];
|
|
75
|
-
const selectedFromServer = settings?.selectedLayoutId && optionsWithDefault.some(option => option.id === settings.selectedLayoutId)
|
|
76
|
-
? settings.selectedLayoutId
|
|
77
|
-
: optionsWithDefault[0]?.id ?? defaultOption.id;
|
|
78
|
-
return { options: optionsWithDefault, selectedId: selectedFromServer };
|
|
79
|
-
};
|
|
80
|
-
const mapOptionToSettingsLayout = (option) => ({
|
|
81
|
-
id: option.id,
|
|
82
|
-
name: option.name,
|
|
83
|
-
layoutByBreakpoint: Object.fromEntries(Object.entries(option.layoutByBreakpoint).map(([breakpoint, config]) => [
|
|
84
|
-
breakpoint,
|
|
85
|
-
{
|
|
86
|
-
columns: config.columns,
|
|
87
|
-
widgets: Object.fromEntries(Object.entries(config.widgets).map(([id, widget]) => [
|
|
88
|
-
id,
|
|
89
|
-
{
|
|
90
|
-
columnSpan: widget.defaultSize.columnSpan,
|
|
91
|
-
rowSpan: widget.defaultSize.rowSpan,
|
|
92
|
-
columnOffset: widget.defaultSize.columnOffset,
|
|
93
|
-
isHidden: widget.initialState?.isHidden,
|
|
94
|
-
isCollapsed: widget.initialState?.isCollapsed,
|
|
95
|
-
},
|
|
96
|
-
])),
|
|
97
|
-
},
|
|
98
|
-
])),
|
|
99
|
-
});
|
|
100
|
-
export const buildLayoutSettingsPayload = (options, selectedId) => ({
|
|
101
|
-
layouts: options.map(mapOptionToSettingsLayout),
|
|
102
|
-
selectedLayoutId: selectedId && options.some(option => option.id === selectedId) ? selectedId : options[0]?.id,
|
|
103
|
-
});
|
|
104
13
|
export const buildPresetFromState = (state, baseLayoutByBreakpoint, breakpoints = DEFAULT_BREAKPOINTS) => {
|
|
105
14
|
if (!state) {
|
|
106
15
|
return Object.fromEntries(Object.entries(baseLayoutByBreakpoint).map(([breakpoint, config]) => [breakpoint, cloneLayoutConfig(config)]));
|
|
@@ -147,35 +56,4 @@ export const buildPresetFromState = (state, baseLayoutByBreakpoint, breakpoints
|
|
|
147
56
|
});
|
|
148
57
|
return layoutByBreakpoint;
|
|
149
58
|
};
|
|
150
|
-
export const createWidgetLayoutsRemoteHandlers = ({ defaultOption, breakpoints = DEFAULT_BREAKPOINTS, loadSettings, saveSettings, skipWhenStorybook = true, }) => {
|
|
151
|
-
const shouldSkipRemote = skipWhenStorybook && isStorybookRuntime();
|
|
152
|
-
const loadLayouts = async () => {
|
|
153
|
-
if (!loadSettings || shouldSkipRemote) {
|
|
154
|
-
return { options: [defaultOption], selectedId: defaultOption.id };
|
|
155
|
-
}
|
|
156
|
-
try {
|
|
157
|
-
const response = await loadSettings();
|
|
158
|
-
const normalized = normalizeWidgetLayoutSettings(response, defaultOption, breakpoints);
|
|
159
|
-
return normalized ?? { options: [defaultOption], selectedId: defaultOption.id };
|
|
160
|
-
}
|
|
161
|
-
catch (error) {
|
|
162
|
-
console.warn('Failed to load widget layouts', error);
|
|
163
|
-
return { options: [defaultOption], selectedId: defaultOption.id };
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
const saveLayouts = async (options, selectedId) => {
|
|
167
|
-
if (!saveSettings || shouldSkipRemote)
|
|
168
|
-
return;
|
|
169
|
-
const safeOptions = options.length ? options : [defaultOption];
|
|
170
|
-
const resolvedSelected = selectedId && safeOptions.some(option => option.id === selectedId) ? selectedId : safeOptions[0]?.id ?? defaultOption.id;
|
|
171
|
-
const payload = buildLayoutSettingsPayload(safeOptions, resolvedSelected);
|
|
172
|
-
try {
|
|
173
|
-
await saveSettings(payload);
|
|
174
|
-
}
|
|
175
|
-
catch (error) {
|
|
176
|
-
console.warn('Failed to save widget layouts', error);
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
return { loadLayouts, saveLayouts };
|
|
180
|
-
};
|
|
181
59
|
//# sourceMappingURL=layoutPersistence.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layoutPersistence.js","sourceRoot":"","sources":["../../../src/component/widget-board/layoutPersistence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAA;
|
|
1
|
+
{"version":3,"file":"layoutPersistence.js","sourceRoot":"","sources":["../../../src/component/widget-board/layoutPersistence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAA;AAGzE,MAAM,iBAAiB,GAAG,CAAC,MAA8B,EAA0B,EAAE,CAAC,CAAC;IACnF,OAAO,EAAE,MAAM,CAAC,OAAO;IACvB,OAAO,EAAE,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC;QACjD,EAAE;QACF;YACI,WAAW,EAAE,EAAE,GAAG,MAAM,CAAC,WAAW,EAAE;YACtC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS;YACxD,YAAY,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,SAAS;SAC7E;KACJ,CAAC,CACiC;CAC1C,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,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