@fluid-app/rep-core 0.1.14 → 0.1.15
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/dist/chunk-CKQMccvm.cjs +28 -0
- package/dist/data-sources/DataAwareWidget.cjs +47 -56
- package/dist/data-sources/DataAwareWidget.cjs.map +1 -1
- package/dist/data-sources/DataAwareWidget.d.cts +27 -19
- package/dist/data-sources/DataAwareWidget.d.cts.map +1 -0
- package/dist/data-sources/DataAwareWidget.d.mts +38 -0
- package/dist/data-sources/DataAwareWidget.d.mts.map +1 -0
- package/dist/data-sources/DataAwareWidget.mjs +48 -0
- package/dist/data-sources/DataAwareWidget.mjs.map +1 -0
- package/dist/data-sources/ErrorState.cjs +18 -10
- package/dist/data-sources/ErrorState.cjs.map +1 -1
- package/dist/data-sources/ErrorState.d.cts +5 -3
- package/dist/data-sources/ErrorState.d.cts.map +1 -0
- package/dist/data-sources/ErrorState.d.mts +7 -0
- package/dist/data-sources/ErrorState.d.mts.map +1 -0
- package/dist/data-sources/ErrorState.mjs +18 -0
- package/dist/data-sources/ErrorState.mjs.map +1 -0
- package/dist/data-sources/context.cjs +22 -14
- package/dist/data-sources/context.cjs.map +1 -1
- package/dist/data-sources/context.d.cts +16 -10
- package/dist/data-sources/context.d.cts.map +1 -0
- package/dist/data-sources/context.d.mts +22 -0
- package/dist/data-sources/context.d.mts.map +1 -0
- package/dist/data-sources/context.mjs +21 -0
- package/dist/data-sources/context.mjs.map +1 -0
- package/dist/data-sources/fetchers/api.cjs +63 -10
- package/dist/data-sources/fetchers/api.cjs.map +1 -1
- package/dist/data-sources/fetchers/api.d.cts +4 -2
- package/dist/data-sources/fetchers/api.d.cts.map +1 -0
- package/dist/data-sources/fetchers/api.d.mts +10 -0
- package/dist/data-sources/fetchers/api.d.mts.map +1 -0
- package/dist/data-sources/fetchers/api.mjs +64 -0
- package/dist/data-sources/fetchers/api.mjs.map +1 -0
- package/dist/data-sources/fetchers/custom.cjs +106 -10
- package/dist/data-sources/fetchers/custom.cjs.map +1 -1
- package/dist/data-sources/fetchers/custom.d.cts +4 -2
- package/dist/data-sources/fetchers/custom.d.cts.map +1 -0
- package/dist/data-sources/fetchers/{custom.d.ts → custom.d.mts} +4 -2
- package/dist/data-sources/fetchers/custom.d.mts.map +1 -0
- package/dist/data-sources/fetchers/custom.mjs +107 -0
- package/dist/data-sources/fetchers/custom.mjs.map +1 -0
- package/dist/data-sources/fetchers/static.cjs +159 -14
- package/dist/data-sources/fetchers/static.cjs.map +1 -1
- package/dist/data-sources/fetchers/static.d.cts +12 -10
- package/dist/data-sources/fetchers/static.d.cts.map +1 -0
- package/dist/data-sources/fetchers/{static.d.ts → static.d.mts} +12 -10
- package/dist/data-sources/fetchers/static.d.mts.map +1 -0
- package/dist/data-sources/fetchers/static.mjs +158 -0
- package/dist/data-sources/fetchers/static.mjs.map +1 -0
- package/dist/data-sources/preview-context.cjs +15 -15
- package/dist/data-sources/preview-context.cjs.map +1 -1
- package/dist/data-sources/preview-context.d.cts +10 -6
- package/dist/data-sources/preview-context.d.cts.map +1 -0
- package/dist/data-sources/preview-context.d.mts +15 -0
- package/dist/data-sources/preview-context.d.mts.map +1 -0
- package/dist/data-sources/preview-context.mjs +18 -0
- package/dist/data-sources/preview-context.mjs.map +1 -0
- package/dist/data-sources/registry-context.cjs +51 -24
- package/dist/data-sources/registry-context.cjs.map +1 -1
- package/dist/data-sources/registry-context.d.cts +30 -22
- package/dist/data-sources/registry-context.d.cts.map +1 -0
- package/dist/data-sources/registry-context.d.mts +49 -0
- package/dist/data-sources/registry-context.d.mts.map +1 -0
- package/dist/data-sources/registry-context.mjs +49 -0
- package/dist/data-sources/registry-context.mjs.map +1 -0
- package/dist/data-sources/registry.cjs +29 -18
- package/dist/data-sources/registry.cjs.map +1 -1
- package/dist/data-sources/registry.d.cts +9 -7
- package/dist/data-sources/registry.d.cts.map +1 -0
- package/dist/data-sources/registry.d.mts +19 -0
- package/dist/data-sources/registry.d.mts.map +1 -0
- package/dist/data-sources/registry.mjs +29 -0
- package/dist/data-sources/registry.mjs.map +1 -0
- package/dist/data-sources/transformers.cjs +152 -10
- package/dist/data-sources/transformers.cjs.map +1 -1
- package/dist/data-sources/transformers.d.cts +4 -17
- package/dist/data-sources/transformers.d.cts.map +1 -0
- package/dist/data-sources/transformers.d.mts +10 -0
- package/dist/data-sources/transformers.d.mts.map +1 -0
- package/dist/data-sources/transformers.mjs +153 -0
- package/dist/data-sources/transformers.mjs.map +1 -0
- package/dist/data-sources/types.cjs +0 -4
- package/dist/data-sources/types.d.cts +2 -157
- package/dist/data-sources/types.d.mts +2 -0
- package/dist/data-sources/types.mjs +1 -0
- package/dist/data-sources/use-widget-data.cjs +109 -17
- package/dist/data-sources/use-widget-data.cjs.map +1 -1
- package/dist/data-sources/use-widget-data.d.cts +9 -8
- package/dist/data-sources/use-widget-data.d.cts.map +1 -0
- package/dist/data-sources/use-widget-data.d.mts +17 -0
- package/dist/data-sources/use-widget-data.d.mts.map +1 -0
- package/dist/data-sources/use-widget-data.mjs +109 -0
- package/dist/data-sources/use-widget-data.mjs.map +1 -0
- package/dist/index-Bxe_LIi8.d.cts +287 -0
- package/dist/index-Bxe_LIi8.d.cts.map +1 -0
- package/dist/index-CCAu2n19.d.mts +287 -0
- package/dist/index-CCAu2n19.d.mts.map +1 -0
- package/dist/registries/index.cjs +212 -127
- package/dist/registries/index.cjs.map +1 -1
- package/dist/registries/index.d.cts +146 -149
- package/dist/registries/index.d.cts.map +1 -0
- package/dist/registries/{index.d.ts → index.d.mts} +146 -149
- package/dist/registries/index.d.mts.map +1 -0
- package/dist/registries/index.mjs +229 -0
- package/dist/registries/index.mjs.map +1 -0
- package/dist/shell/AppShellLayout.cjs +47 -12
- package/dist/shell/AppShellLayout.cjs.map +1 -1
- package/dist/shell/AppShellLayout.d.cts +29 -19
- package/dist/shell/AppShellLayout.d.cts.map +1 -0
- package/dist/shell/AppShellLayout.d.mts +40 -0
- package/dist/shell/AppShellLayout.d.mts.map +1 -0
- package/dist/shell/AppShellLayout.mjs +46 -0
- package/dist/{chunk-45BCVWQK.cjs.map → shell/AppShellLayout.mjs.map} +1 -1
- package/dist/shell/ScreenHeader.cjs +44 -0
- package/dist/shell/ScreenHeader.cjs.map +1 -0
- package/dist/shell/ScreenHeader.d.cts +12 -0
- package/dist/shell/ScreenHeader.d.cts.map +1 -0
- package/dist/shell/ScreenHeader.d.mts +12 -0
- package/dist/shell/ScreenHeader.d.mts.map +1 -0
- package/dist/shell/ScreenHeader.mjs +42 -0
- package/dist/shell/ScreenHeader.mjs.map +1 -0
- package/dist/shell/ScreenHeaderContext.cjs +91 -0
- package/dist/shell/ScreenHeaderContext.cjs.map +1 -0
- package/dist/shell/ScreenHeaderContext.d.cts +36 -0
- package/dist/shell/ScreenHeaderContext.d.cts.map +1 -0
- package/dist/shell/ScreenHeaderContext.d.mts +36 -0
- package/dist/shell/ScreenHeaderContext.d.mts.map +1 -0
- package/dist/shell/ScreenHeaderContext.mjs +86 -0
- package/dist/shell/ScreenHeaderContext.mjs.map +1 -0
- package/dist/shell/ThemeModeContext.cjs +68 -18
- package/dist/shell/ThemeModeContext.cjs.map +1 -1
- package/dist/shell/ThemeModeContext.d.cts +23 -16
- package/dist/shell/ThemeModeContext.d.cts.map +1 -0
- package/dist/shell/ThemeModeContext.d.mts +34 -0
- package/dist/shell/ThemeModeContext.d.mts.map +1 -0
- package/dist/shell/ThemeModeContext.mjs +66 -0
- package/dist/shell/ThemeModeContext.mjs.map +1 -0
- package/dist/shell/index.cjs +43 -205
- package/dist/shell/index.d.cts +7 -43
- package/dist/shell/index.d.mts +7 -0
- package/dist/shell/index.mjs +7 -0
- package/dist/shell/sidebar.cjs +372 -87
- package/dist/shell/sidebar.cjs.map +1 -1
- package/dist/shell/sidebar.d.cts +38 -36
- package/dist/shell/sidebar.d.cts.map +1 -0
- package/dist/shell/{sidebar.d.ts → sidebar.d.mts} +38 -36
- package/dist/shell/sidebar.d.mts.map +1 -0
- package/dist/shell/sidebar.mjs +364 -0
- package/dist/{chunk-PFDBULOI.cjs.map → shell/sidebar.mjs.map} +1 -1
- package/dist/shell/use-mobile.cjs +49 -18
- package/dist/shell/use-mobile.cjs.map +1 -1
- package/dist/shell/use-mobile.d.cts +3 -1
- package/dist/shell/use-mobile.d.cts.map +1 -0
- package/dist/shell/{use-mobile.d.ts → use-mobile.d.mts} +3 -1
- package/dist/shell/use-mobile.d.mts.map +1 -0
- package/dist/shell/use-mobile.mjs +47 -0
- package/dist/shell/use-mobile.mjs.map +1 -0
- package/dist/theme/index.cjs +662 -549
- package/dist/theme/index.cjs.map +1 -1
- package/dist/theme/index.d.cts +32 -32
- package/dist/theme/index.d.cts.map +1 -0
- package/dist/theme/{index.d.ts → index.d.mts} +32 -32
- package/dist/theme/index.d.mts.map +1 -0
- package/dist/theme/index.mjs +727 -0
- package/dist/theme/index.mjs.map +1 -0
- package/dist/types/index.cjs +18 -72
- package/dist/types/index.d.cts +4 -268
- package/dist/types/index.d.mts +4 -0
- package/dist/types/index.mjs +2 -0
- package/dist/types-BIXtQlHB.d.cts +155 -0
- package/dist/types-BIXtQlHB.d.cts.map +1 -0
- package/dist/types-BXFX9bXp.cjs +303 -0
- package/dist/types-BXFX9bXp.cjs.map +1 -0
- package/dist/types-Bjmd7Fdx.mjs +208 -0
- package/dist/types-Bjmd7Fdx.mjs.map +1 -0
- package/dist/types-ByG6Xy3C.d.mts +85 -0
- package/dist/types-ByG6Xy3C.d.mts.map +1 -0
- package/dist/types-C5OFJy-O.d.mts +155 -0
- package/dist/types-C5OFJy-O.d.mts.map +1 -0
- package/dist/types-Ctu-Zio6.d.cts +85 -0
- package/dist/types-Ctu-Zio6.d.cts.map +1 -0
- package/dist/{widget-schema-D-ca3--K.d.ts → widget-schema--PY1uMWx.d.cts} +38 -41
- package/dist/widget-schema--PY1uMWx.d.cts.map +1 -0
- package/dist/{widget-schema-DvJdg1-B.d.cts → widget-schema-YkD5p3v4.d.mts} +38 -41
- package/dist/widget-schema-YkD5p3v4.d.mts.map +1 -0
- package/dist/widget-utils/index.cjs +96 -89
- package/dist/widget-utils/index.cjs.map +1 -1
- package/dist/widget-utils/index.d.cts +8 -6
- package/dist/widget-utils/index.d.cts.map +1 -0
- package/dist/widget-utils/{index.d.ts → index.d.mts} +8 -6
- package/dist/widget-utils/index.d.mts.map +1 -0
- package/dist/widget-utils/index.mjs +119 -0
- package/dist/widget-utils/index.mjs.map +1 -0
- package/package.json +4 -4
- package/dist/chunk-2SPTFZRC.js +0 -72
- package/dist/chunk-2SPTFZRC.js.map +0 -1
- package/dist/chunk-3I5Y3PEO.js +0 -23
- package/dist/chunk-3I5Y3PEO.js.map +0 -1
- package/dist/chunk-3ZRE7GX6.js +0 -620
- package/dist/chunk-3ZRE7GX6.js.map +0 -1
- package/dist/chunk-45BCVWQK.cjs +0 -38
- package/dist/chunk-46PUWB7C.cjs +0 -69
- package/dist/chunk-46PUWB7C.cjs.map +0 -1
- package/dist/chunk-5NYM4UTW.cjs +0 -58
- package/dist/chunk-5NYM4UTW.cjs.map +0 -1
- package/dist/chunk-B2NTWEDF.cjs +0 -130
- package/dist/chunk-B2NTWEDF.cjs.map +0 -1
- package/dist/chunk-GDY76JA6.cjs +0 -153
- package/dist/chunk-GDY76JA6.cjs.map +0 -1
- package/dist/chunk-HGVSPZEL.cjs +0 -119
- package/dist/chunk-HGVSPZEL.cjs.map +0 -1
- package/dist/chunk-HIDJYVKJ.js +0 -54
- package/dist/chunk-HIDJYVKJ.js.map +0 -1
- package/dist/chunk-KTXGU7OP.cjs +0 -136
- package/dist/chunk-KTXGU7OP.cjs.map +0 -1
- package/dist/chunk-KW5E2H5T.js +0 -128
- package/dist/chunk-KW5E2H5T.js.map +0 -1
- package/dist/chunk-LBLHDGMT.js +0 -25
- package/dist/chunk-LBLHDGMT.js.map +0 -1
- package/dist/chunk-MNVDL4FX.js +0 -134
- package/dist/chunk-MNVDL4FX.js.map +0 -1
- package/dist/chunk-MOTOSPAO.cjs +0 -15
- package/dist/chunk-MOTOSPAO.cjs.map +0 -1
- package/dist/chunk-N2K6W7FX.cjs +0 -169
- package/dist/chunk-N2K6W7FX.cjs.map +0 -1
- package/dist/chunk-PFDBULOI.cjs +0 -665
- package/dist/chunk-PVTQWD4I.js +0 -166
- package/dist/chunk-PVTQWD4I.js.map +0 -1
- package/dist/chunk-SJQPHJL4.cjs +0 -26
- package/dist/chunk-SJQPHJL4.cjs.map +0 -1
- package/dist/chunk-TML66UEU.js +0 -13
- package/dist/chunk-TML66UEU.js.map +0 -1
- package/dist/chunk-U3CQLX2Z.cjs +0 -28
- package/dist/chunk-U3CQLX2Z.cjs.map +0 -1
- package/dist/chunk-UUNEVOA5.js +0 -36
- package/dist/chunk-UUNEVOA5.js.map +0 -1
- package/dist/chunk-VRF7QEID.js +0 -67
- package/dist/chunk-VRF7QEID.js.map +0 -1
- package/dist/chunk-VSZWXSQA.js +0 -38
- package/dist/chunk-VSZWXSQA.js.map +0 -1
- package/dist/chunk-WYOHFNNW.js +0 -117
- package/dist/chunk-WYOHFNNW.js.map +0 -1
- package/dist/chunk-YKF5ZFF5.js +0 -136
- package/dist/chunk-YKF5ZFF5.js.map +0 -1
- package/dist/chunk-YXJMBVXO.cjs +0 -76
- package/dist/chunk-YXJMBVXO.cjs.map +0 -1
- package/dist/chunk-ZA4AE7KF.cjs +0 -42
- package/dist/chunk-ZA4AE7KF.cjs.map +0 -1
- package/dist/data-sources/DataAwareWidget.d.ts +0 -30
- package/dist/data-sources/DataAwareWidget.js +0 -57
- package/dist/data-sources/DataAwareWidget.js.map +0 -1
- package/dist/data-sources/ErrorState.d.ts +0 -5
- package/dist/data-sources/ErrorState.js +0 -3
- package/dist/data-sources/ErrorState.js.map +0 -1
- package/dist/data-sources/context.d.ts +0 -16
- package/dist/data-sources/context.js +0 -3
- package/dist/data-sources/context.js.map +0 -1
- package/dist/data-sources/fetchers/api.d.ts +0 -8
- package/dist/data-sources/fetchers/api.js +0 -3
- package/dist/data-sources/fetchers/api.js.map +0 -1
- package/dist/data-sources/fetchers/custom.js +0 -3
- package/dist/data-sources/fetchers/custom.js.map +0 -1
- package/dist/data-sources/fetchers/static.js +0 -3
- package/dist/data-sources/fetchers/static.js.map +0 -1
- package/dist/data-sources/preview-context.d.ts +0 -11
- package/dist/data-sources/preview-context.js +0 -18
- package/dist/data-sources/preview-context.js.map +0 -1
- package/dist/data-sources/registry-context.d.ts +0 -41
- package/dist/data-sources/registry-context.js +0 -9
- package/dist/data-sources/registry-context.js.map +0 -1
- package/dist/data-sources/registry.d.ts +0 -17
- package/dist/data-sources/registry.js +0 -7
- package/dist/data-sources/registry.js.map +0 -1
- package/dist/data-sources/transformers.d.ts +0 -23
- package/dist/data-sources/transformers.js +0 -3
- package/dist/data-sources/transformers.js.map +0 -1
- package/dist/data-sources/types.cjs.map +0 -1
- package/dist/data-sources/types.d.ts +0 -157
- package/dist/data-sources/types.js +0 -3
- package/dist/data-sources/types.js.map +0 -1
- package/dist/data-sources/use-widget-data.d.ts +0 -16
- package/dist/data-sources/use-widget-data.js +0 -10
- package/dist/data-sources/use-widget-data.js.map +0 -1
- package/dist/registries/index.js +0 -144
- package/dist/registries/index.js.map +0 -1
- package/dist/shareable-item-DkgWpwoU.d.cts +0 -21
- package/dist/shareable-item-DkgWpwoU.d.ts +0 -21
- package/dist/shell/AppShellLayout.d.ts +0 -30
- package/dist/shell/AppShellLayout.js +0 -5
- package/dist/shell/AppShellLayout.js.map +0 -1
- package/dist/shell/ThemeModeContext.d.ts +0 -27
- package/dist/shell/ThemeModeContext.js +0 -3
- package/dist/shell/ThemeModeContext.js.map +0 -1
- package/dist/shell/index.cjs.map +0 -1
- package/dist/shell/index.d.ts +0 -43
- package/dist/shell/index.js +0 -76
- package/dist/shell/index.js.map +0 -1
- package/dist/shell/sidebar.js +0 -4
- package/dist/shell/sidebar.js.map +0 -1
- package/dist/shell/use-mobile.js +0 -3
- package/dist/shell/use-mobile.js.map +0 -1
- package/dist/theme/index.js +0 -611
- package/dist/theme/index.js.map +0 -1
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.d.ts +0 -268
- package/dist/types/index.js +0 -3
- package/dist/types/index.js.map +0 -1
- package/dist/types-CNIhy4JD.d.cts +0 -83
- package/dist/types-CNIhy4JD.d.ts +0 -83
- package/dist/widget-utils/index.js +0 -111
- package/dist/widget-utils/index.js.map +0 -1
|
@@ -1,113 +1,120 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_types = require("../types-BXFX9bXp.cjs");
|
|
3
|
+
//#region src/widget-utils/widget-utils.ts
|
|
4
|
+
/**
|
|
5
|
+
* Generates a unique ID for a widget
|
|
6
|
+
*/
|
|
6
7
|
function generateWidgetId(type) {
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
const uuid = crypto.randomUUID();
|
|
9
|
+
return type ? `${type}-${uuid}` : uuid;
|
|
9
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Converts a widget path to a unique string identifier
|
|
13
|
+
*/
|
|
10
14
|
function pathToId(path) {
|
|
11
|
-
|
|
15
|
+
return path.join("-");
|
|
12
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Converts a path string back to a WidgetPath array
|
|
19
|
+
*/
|
|
13
20
|
function idToPath(id) {
|
|
14
|
-
|
|
21
|
+
return id.split("-").map((segment) => parseInt(segment, 10));
|
|
15
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Ensures all widgets in an array have valid IDs
|
|
25
|
+
* Note: Handles null values for sparse arrays (e.g., grid layouts with empty cells)
|
|
26
|
+
*/
|
|
16
27
|
function ensureWidgetIds(widgets) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
return widgets?.map((widget, index) => {
|
|
29
|
+
if (!widget) return null;
|
|
30
|
+
return {
|
|
31
|
+
...widget,
|
|
32
|
+
id: widget.id || `widget-${index}-${crypto.randomUUID()}`
|
|
33
|
+
};
|
|
34
|
+
});
|
|
24
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Deep clones a widget and regenerates all IDs (including nested children)
|
|
38
|
+
*/
|
|
25
39
|
function deepCloneWidget(widget) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
id: generateWidgetId(widget.type)
|
|
40
|
-
};
|
|
40
|
+
if (require_types.isWidgetType(widget, require_types.WIDGET_TYPE_NAMES.Layout) && Array.isArray(widget.props.children)) return {
|
|
41
|
+
type: widget.type,
|
|
42
|
+
props: {
|
|
43
|
+
...widget.props,
|
|
44
|
+
children: widget.props.children.map((child) => child ? deepCloneWidget(child) : null)
|
|
45
|
+
},
|
|
46
|
+
id: generateWidgetId(widget.type)
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
type: widget.type,
|
|
50
|
+
props: { ...widget.props },
|
|
51
|
+
id: generateWidgetId(widget.type)
|
|
52
|
+
};
|
|
41
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Deep clones an array of widgets and regenerates all IDs
|
|
56
|
+
*/
|
|
42
57
|
function deepCloneWidgets(widgets) {
|
|
43
|
-
|
|
58
|
+
return widgets.map((widget) => deepCloneWidget(widget));
|
|
44
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Gets a widget at a specific path in the widget tree
|
|
62
|
+
*/
|
|
45
63
|
function getWidgetByPath(screen, path) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
64
|
+
if (path.length === 0 || path[0] === void 0) return null;
|
|
65
|
+
let current = screen[path[0]] ?? null;
|
|
66
|
+
for (let i = 1; i < path.length; i++) {
|
|
67
|
+
if (!require_types.isWidgetType(current, require_types.WIDGET_TYPE_NAMES.Layout)) return null;
|
|
68
|
+
const children = current.props.children ?? [];
|
|
69
|
+
const index = path[i];
|
|
70
|
+
if (index === void 0) return null;
|
|
71
|
+
current = children[index] ?? null;
|
|
72
|
+
}
|
|
73
|
+
return current;
|
|
56
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Groups children by column index.
|
|
77
|
+
* Accepts nullable children (sparse arrays from grid layouts) and filters them out.
|
|
78
|
+
*/
|
|
57
79
|
function groupChildrenByColumn(children, columnCount) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
for (const child of nonNullChildren) {
|
|
66
|
-
const colIndex = Math.min(child.columnIndex ?? 0, columnCount - 1);
|
|
67
|
-
const column = columns[colIndex];
|
|
68
|
-
if (column) {
|
|
69
|
-
column.push(child);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return columns;
|
|
80
|
+
const columns = Array.from({ length: columnCount }, () => []);
|
|
81
|
+
const nonNullChildren = children.filter((child) => child !== null);
|
|
82
|
+
for (const child of nonNullChildren) {
|
|
83
|
+
const column = columns[Math.min(child.columnIndex ?? 0, columnCount - 1)];
|
|
84
|
+
if (column) column.push(child);
|
|
85
|
+
}
|
|
86
|
+
return columns;
|
|
73
87
|
}
|
|
74
|
-
|
|
75
|
-
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/widget-utils/utils.ts
|
|
76
90
|
function createWidgetRegistry(registry) {
|
|
77
|
-
|
|
91
|
+
return registry;
|
|
78
92
|
}
|
|
79
93
|
function createScreen(registry, widgets) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
return widgets;
|
|
94
|
+
widgets.forEach((widget) => {
|
|
95
|
+
if (!(widget.type in registry)) throw new Error(`Widget type "${String(widget.type)}" not found in registry`);
|
|
96
|
+
});
|
|
97
|
+
return widgets;
|
|
88
98
|
}
|
|
89
99
|
function createWidgetFromShareable(item) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
objectFit: "cover"
|
|
107
|
-
}
|
|
108
|
-
};
|
|
100
|
+
if ((item.kind === "video" || !!item.videoUrl) && item.videoUrl) return {
|
|
101
|
+
type: "VideoWidget",
|
|
102
|
+
props: {
|
|
103
|
+
src: item.videoUrl,
|
|
104
|
+
poster: item.imageUrl,
|
|
105
|
+
caption: item.title
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
return {
|
|
109
|
+
type: "ImageWidget",
|
|
110
|
+
props: {
|
|
111
|
+
src: item.imageUrl,
|
|
112
|
+
alt: item.title || "Image",
|
|
113
|
+
objectFit: "cover"
|
|
114
|
+
}
|
|
115
|
+
};
|
|
109
116
|
}
|
|
110
|
-
|
|
117
|
+
//#endregion
|
|
111
118
|
exports.createScreen = createScreen;
|
|
112
119
|
exports.createWidgetFromShareable = createWidgetFromShareable;
|
|
113
120
|
exports.createWidgetRegistry = createWidgetRegistry;
|
|
@@ -119,5 +126,5 @@ exports.getWidgetByPath = getWidgetByPath;
|
|
|
119
126
|
exports.groupChildrenByColumn = groupChildrenByColumn;
|
|
120
127
|
exports.idToPath = idToPath;
|
|
121
128
|
exports.pathToId = pathToId;
|
|
122
|
-
|
|
129
|
+
|
|
123
130
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/widget-utils/widget-utils.ts","../../src/widget-utils/utils.ts"],"
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["isWidgetType","WIDGET_TYPE_NAMES"],"sources":["../../src/widget-utils/widget-utils.ts","../../src/widget-utils/utils.ts"],"sourcesContent":["import type { WidgetSchema, WidgetPath } from \"../types\";\nimport { WIDGET_TYPE_NAMES, isWidgetType } from \"../types\";\n\n/**\n * Generates a unique ID for a widget\n */\nexport function generateWidgetId(type?: string): string {\n const uuid = crypto.randomUUID();\n return type ? `${type}-${uuid}` : uuid;\n}\n\n/**\n * Converts a widget path to a unique string identifier\n */\nexport function pathToId(path: WidgetPath): string {\n return path.join(\"-\");\n}\n\n/**\n * Converts a path string back to a WidgetPath array\n */\nexport function idToPath(id: string): WidgetPath {\n return id.split(\"-\").map((segment) => parseInt(segment, 10));\n}\n\n/**\n * Ensures all widgets in an array have valid IDs\n * Note: Handles null values for sparse arrays (e.g., grid layouts with empty cells)\n */\nexport function ensureWidgetIds(\n widgets: readonly (WidgetSchema | null)[],\n): (WidgetSchema | null)[] {\n return widgets?.map((widget, index) => {\n if (!widget) return null;\n return {\n ...widget,\n id: widget.id || `widget-${index}-${crypto.randomUUID()}`,\n };\n });\n}\n\n/**\n * Deep clones a widget and regenerates all IDs (including nested children)\n */\nexport function deepCloneWidget(widget: WidgetSchema): WidgetSchema {\n // Handle LayoutWidget children recursively\n // Use type guard for discriminated union narrowing (narrowing-discriminated-unions rule)\n if (\n isWidgetType(widget, WIDGET_TYPE_NAMES.Layout) &&\n Array.isArray(widget.props.children)\n ) {\n // Build cloned widget with recursively cloned children\n return {\n type: widget.type,\n props: {\n ...widget.props,\n children: (\n widget.props.children as readonly (WidgetSchema | null)[]\n ).map((child) => (child ? deepCloneWidget(child) : null)),\n },\n id: generateWidgetId(widget.type),\n };\n }\n\n // Clone non-container widget\n return {\n type: widget.type,\n props: { ...widget.props },\n id: generateWidgetId(widget.type),\n };\n}\n\n/**\n * Deep clones an array of widgets and regenerates all IDs\n */\nexport function deepCloneWidgets(\n widgets: readonly WidgetSchema[],\n): WidgetSchema[] {\n return widgets.map((widget) => deepCloneWidget(widget));\n}\n\n/**\n * Gets a widget at a specific path in the widget tree\n */\nexport function getWidgetByPath(\n screen: readonly (WidgetSchema | null)[],\n path: WidgetPath,\n): WidgetSchema | null {\n if (path.length === 0 || path[0] === undefined) return null;\n\n let current: WidgetSchema | null = screen[path[0]] ?? null;\n\n for (let i = 1; i < path.length; i++) {\n // Use type guard for discriminated union narrowing (narrowing-discriminated-unions rule)\n if (!isWidgetType(current, WIDGET_TYPE_NAMES.Layout)) return null;\n\n const children = (current.props.children ??\n []) as readonly (WidgetSchema | null)[];\n const index = path[i];\n if (index === undefined) return null;\n current = children[index] ?? null;\n }\n\n return current;\n}\n\n/**\n * Groups children by column index.\n * Accepts nullable children (sparse arrays from grid layouts) and filters them out.\n */\nexport function groupChildrenByColumn(\n children: readonly (WidgetSchema | null)[],\n columnCount: number,\n): WidgetSchema[][] {\n // Use explicit type annotation to avoid never[] inference (narrowing-empty-array-type rule)\n const columns: WidgetSchema[][] = Array.from(\n { length: columnCount },\n (): WidgetSchema[] => [],\n );\n\n // Filter out nulls first, then process (truthiness narrowing rule)\n // This avoids the narrowing-callback-scope issue since we work with non-null array\n const nonNullChildren = children.filter(\n (child): child is WidgetSchema => child !== null,\n );\n\n for (const child of nonNullChildren) {\n // Default to column 0 if no columnIndex specified\n const colIndex = Math.min(child.columnIndex ?? 0, columnCount - 1);\n const column = columns[colIndex];\n if (column) {\n column.push(child);\n }\n }\n\n return columns;\n}\n","import type { ComponentType } from \"react\";\nimport type { WidgetSchema, TypedWidgetSchema } from \"../types\";\nimport type { ShareableItem } from \"../types/shareable-item\";\n\nexport function createWidgetRegistry<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, ComponentType<any>>,\n>(registry: T): T {\n // Return the registry with its original type intact for type inference\n return registry;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function createScreen<T extends Record<string, ComponentType<any>>>(\n registry: T,\n widgets: TypedWidgetSchema<T>[],\n): TypedWidgetSchema<T>[] {\n // Validate that all widget types exist in the registry at runtime\n widgets.forEach((widget) => {\n if (!(widget.type in registry)) {\n throw new Error(\n `Widget type \"${String(widget.type)}\" not found in registry`,\n );\n }\n });\n return widgets;\n}\n\n// Helper to create WidgetSchema from shareable item\nexport function createWidgetFromShareable(item: ShareableItem): WidgetSchema {\n const isVideo = item.kind === \"video\" || !!item.videoUrl;\n\n if (isVideo && item.videoUrl) {\n return {\n type: \"VideoWidget\",\n props: {\n src: item.videoUrl,\n poster: item.imageUrl,\n caption: item.title,\n },\n };\n }\n\n return {\n type: \"ImageWidget\",\n props: {\n src: item.imageUrl,\n alt: item.title || \"Image\",\n objectFit: \"cover\",\n },\n };\n}\n"],"mappings":";;;;;;AAMA,SAAgB,iBAAiB,MAAuB;CACtD,MAAM,OAAO,OAAO,YAAY;AAChC,QAAO,OAAO,GAAG,KAAK,GAAG,SAAS;;;;;AAMpC,SAAgB,SAAS,MAA0B;AACjD,QAAO,KAAK,KAAK,IAAI;;;;;AAMvB,SAAgB,SAAS,IAAwB;AAC/C,QAAO,GAAG,MAAM,IAAI,CAAC,KAAK,YAAY,SAAS,SAAS,GAAG,CAAC;;;;;;AAO9D,SAAgB,gBACd,SACyB;AACzB,QAAO,SAAS,KAAK,QAAQ,UAAU;AACrC,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO;GACL,GAAG;GACH,IAAI,OAAO,MAAM,UAAU,MAAM,GAAG,OAAO,YAAY;GACxD;GACD;;;;;AAMJ,SAAgB,gBAAgB,QAAoC;AAGlE,KACEA,cAAAA,aAAa,QAAQC,cAAAA,kBAAkB,OAAO,IAC9C,MAAM,QAAQ,OAAO,MAAM,SAAS,CAGpC,QAAO;EACL,MAAM,OAAO;EACb,OAAO;GACL,GAAG,OAAO;GACV,UACE,OAAO,MAAM,SACb,KAAK,UAAW,QAAQ,gBAAgB,MAAM,GAAG,KAAM;GAC1D;EACD,IAAI,iBAAiB,OAAO,KAAK;EAClC;AAIH,QAAO;EACL,MAAM,OAAO;EACb,OAAO,EAAE,GAAG,OAAO,OAAO;EAC1B,IAAI,iBAAiB,OAAO,KAAK;EAClC;;;;;AAMH,SAAgB,iBACd,SACgB;AAChB,QAAO,QAAQ,KAAK,WAAW,gBAAgB,OAAO,CAAC;;;;;AAMzD,SAAgB,gBACd,QACA,MACqB;AACrB,KAAI,KAAK,WAAW,KAAK,KAAK,OAAO,KAAA,EAAW,QAAO;CAEvD,IAAI,UAA+B,OAAO,KAAK,OAAO;AAEtD,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AAEpC,MAAI,CAACD,cAAAA,aAAa,SAASC,cAAAA,kBAAkB,OAAO,CAAE,QAAO;EAE7D,MAAM,WAAY,QAAQ,MAAM,YAC9B,EAAE;EACJ,MAAM,QAAQ,KAAK;AACnB,MAAI,UAAU,KAAA,EAAW,QAAO;AAChC,YAAU,SAAS,UAAU;;AAG/B,QAAO;;;;;;AAOT,SAAgB,sBACd,UACA,aACkB;CAElB,MAAM,UAA4B,MAAM,KACtC,EAAE,QAAQ,aAAa,QACD,EAAE,CACzB;CAID,MAAM,kBAAkB,SAAS,QAC9B,UAAiC,UAAU,KAC7C;AAED,MAAK,MAAM,SAAS,iBAAiB;EAGnC,MAAM,SAAS,QADE,KAAK,IAAI,MAAM,eAAe,GAAG,cAAc,EAAE;AAElE,MAAI,OACF,QAAO,KAAK,MAAM;;AAItB,QAAO;;;;ACnIT,SAAgB,qBAGd,UAAgB;AAEhB,QAAO;;AAIT,SAAgB,aACd,UACA,SACwB;AAExB,SAAQ,SAAS,WAAW;AAC1B,MAAI,EAAE,OAAO,QAAQ,UACnB,OAAM,IAAI,MACR,gBAAgB,OAAO,OAAO,KAAK,CAAC,yBACrC;GAEH;AACF,QAAO;;AAIT,SAAgB,0BAA0B,MAAmC;AAG3E,MAFgB,KAAK,SAAS,WAAW,CAAC,CAAC,KAAK,aAEjC,KAAK,SAClB,QAAO;EACL,MAAM;EACN,OAAO;GACL,KAAK,KAAK;GACV,QAAQ,KAAK;GACb,SAAS,KAAK;GACf;EACF;AAGH,QAAO;EACL,MAAM;EACN,OAAO;GACL,KAAK,KAAK;GACV,KAAK,KAAK,SAAS;GACnB,WAAW;GACZ;EACF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import '../data-sources/types.cjs';
|
|
1
|
+
import { a as WidgetSchema, r as WidgetPath, t as TypedWidgetSchema } from "../widget-schema--PY1uMWx.cjs";
|
|
2
|
+
import { T as ShareableItem } from "../index-Bxe_LIi8.cjs";
|
|
3
|
+
import { ComponentType } from "react";
|
|
5
4
|
|
|
5
|
+
//#region src/widget-utils/widget-utils.d.ts
|
|
6
6
|
/**
|
|
7
7
|
* Generates a unique ID for a widget
|
|
8
8
|
*/
|
|
@@ -37,9 +37,11 @@ declare function getWidgetByPath(screen: readonly (WidgetSchema | null)[], path:
|
|
|
37
37
|
* Accepts nullable children (sparse arrays from grid layouts) and filters them out.
|
|
38
38
|
*/
|
|
39
39
|
declare function groupChildrenByColumn(children: readonly (WidgetSchema | null)[], columnCount: number): WidgetSchema[][];
|
|
40
|
-
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/widget-utils/utils.d.ts
|
|
41
42
|
declare function createWidgetRegistry<T extends Record<string, ComponentType<any>>>(registry: T): T;
|
|
42
43
|
declare function createScreen<T extends Record<string, ComponentType<any>>>(registry: T, widgets: TypedWidgetSchema<T>[]): TypedWidgetSchema<T>[];
|
|
43
44
|
declare function createWidgetFromShareable(item: ShareableItem): WidgetSchema;
|
|
44
|
-
|
|
45
|
+
//#endregion
|
|
45
46
|
export { createScreen, createWidgetFromShareable, createWidgetRegistry, deepCloneWidget, deepCloneWidgets, ensureWidgetIds, generateWidgetId, getWidgetByPath, groupChildrenByColumn, idToPath, pathToId };
|
|
47
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/widget-utils/widget-utils.ts","../../src/widget-utils/utils.ts"],"mappings":";;;;;;;;iBAMgB,gBAAA,CAAiB,IAAA;AAAjC;;;AAAA,iBAQgB,QAAA,CAAS,IAAA,EAAM,UAAA;;AAA/B;;iBAOgB,QAAA,CAAS,EAAA,WAAa,UAAA;;;AAAtC;;iBAQgB,eAAA,CACd,OAAA,YAAmB,YAAA,cACjB,YAAA;;;AAFJ;iBAegB,eAAA,CAAgB,MAAA,EAAQ,YAAA,GAAe,YAAA;;;;iBA+BvC,gBAAA,CACd,OAAA,WAAkB,YAAA,KACjB,YAAA;;;;iBAOa,eAAA,CACd,MAAA,YAAkB,YAAA,YAClB,IAAA,EAAM,UAAA,GACL,YAAA;;;;;iBAuBa,qBAAA,CACd,QAAA,YAAoB,YAAA,YACpB,WAAA,WACC,YAAA;;;iBC7Ga,oBAAA,WAEJ,MAAA,SAAe,aAAA,OAAA,CACzB,QAAA,EAAU,CAAA,GAAI,CAAA;AAAA,iBAMA,YAAA,WAAuB,MAAA,SAAe,aAAA,OAAA,CACpD,QAAA,EAAU,CAAA,EACV,OAAA,EAAS,iBAAA,CAAkB,CAAA,MAC1B,iBAAA,CAAkB,CAAA;AAAA,iBAaL,yBAAA,CAA0B,IAAA,EAAM,aAAA,GAAgB,YAAA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import '../data-sources/types.js';
|
|
1
|
+
import { a as WidgetSchema, r as WidgetPath, t as TypedWidgetSchema } from "../widget-schema-YkD5p3v4.mjs";
|
|
2
|
+
import { T as ShareableItem } from "../index-CCAu2n19.mjs";
|
|
3
|
+
import { ComponentType } from "react";
|
|
5
4
|
|
|
5
|
+
//#region src/widget-utils/widget-utils.d.ts
|
|
6
6
|
/**
|
|
7
7
|
* Generates a unique ID for a widget
|
|
8
8
|
*/
|
|
@@ -37,9 +37,11 @@ declare function getWidgetByPath(screen: readonly (WidgetSchema | null)[], path:
|
|
|
37
37
|
* Accepts nullable children (sparse arrays from grid layouts) and filters them out.
|
|
38
38
|
*/
|
|
39
39
|
declare function groupChildrenByColumn(children: readonly (WidgetSchema | null)[], columnCount: number): WidgetSchema[][];
|
|
40
|
-
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/widget-utils/utils.d.ts
|
|
41
42
|
declare function createWidgetRegistry<T extends Record<string, ComponentType<any>>>(registry: T): T;
|
|
42
43
|
declare function createScreen<T extends Record<string, ComponentType<any>>>(registry: T, widgets: TypedWidgetSchema<T>[]): TypedWidgetSchema<T>[];
|
|
43
44
|
declare function createWidgetFromShareable(item: ShareableItem): WidgetSchema;
|
|
44
|
-
|
|
45
|
+
//#endregion
|
|
45
46
|
export { createScreen, createWidgetFromShareable, createWidgetRegistry, deepCloneWidget, deepCloneWidgets, ensureWidgetIds, generateWidgetId, getWidgetByPath, groupChildrenByColumn, idToPath, pathToId };
|
|
47
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/widget-utils/widget-utils.ts","../../src/widget-utils/utils.ts"],"mappings":";;;;;;;;iBAMgB,gBAAA,CAAiB,IAAA;;AAAjC;;iBAQgB,QAAA,CAAS,IAAA,EAAM,UAAA;;;AAA/B;iBAOgB,QAAA,CAAS,EAAA,WAAa,UAAA;;;;AAAtC;iBAQgB,eAAA,CACd,OAAA,YAAmB,YAAA,cACjB,YAAA;;;;iBAaY,eAAA,CAAgB,MAAA,EAAQ,YAAA,GAAe,YAAA;;;;iBA+BvC,gBAAA,CACd,OAAA,WAAkB,YAAA,KACjB,YAAA;;;;iBAOa,eAAA,CACd,MAAA,YAAkB,YAAA,YAClB,IAAA,EAAM,UAAA,GACL,YAAA;AA3CH;;;;AAAA,iBAkEgB,qBAAA,CACd,QAAA,YAAoB,YAAA,YACpB,WAAA,WACC,YAAA;;;iBC7Ga,oBAAA,WAEJ,MAAA,SAAe,aAAA,OAAA,CACzB,QAAA,EAAU,CAAA,GAAI,CAAA;AAAA,iBAMA,YAAA,WAAuB,MAAA,SAAe,aAAA,OAAA,CACpD,QAAA,EAAU,CAAA,EACV,OAAA,EAAS,iBAAA,CAAkB,CAAA,MAC1B,iBAAA,CAAkB,CAAA;AAAA,iBAaL,yBAAA,CAA0B,IAAA,EAAM,aAAA,GAAgB,YAAA"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { f as WIDGET_TYPE_NAMES, h as isWidgetType } from "../types-Bjmd7Fdx.mjs";
|
|
2
|
+
//#region src/widget-utils/widget-utils.ts
|
|
3
|
+
/**
|
|
4
|
+
* Generates a unique ID for a widget
|
|
5
|
+
*/
|
|
6
|
+
function generateWidgetId(type) {
|
|
7
|
+
const uuid = crypto.randomUUID();
|
|
8
|
+
return type ? `${type}-${uuid}` : uuid;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Converts a widget path to a unique string identifier
|
|
12
|
+
*/
|
|
13
|
+
function pathToId(path) {
|
|
14
|
+
return path.join("-");
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Converts a path string back to a WidgetPath array
|
|
18
|
+
*/
|
|
19
|
+
function idToPath(id) {
|
|
20
|
+
return id.split("-").map((segment) => parseInt(segment, 10));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Ensures all widgets in an array have valid IDs
|
|
24
|
+
* Note: Handles null values for sparse arrays (e.g., grid layouts with empty cells)
|
|
25
|
+
*/
|
|
26
|
+
function ensureWidgetIds(widgets) {
|
|
27
|
+
return widgets?.map((widget, index) => {
|
|
28
|
+
if (!widget) return null;
|
|
29
|
+
return {
|
|
30
|
+
...widget,
|
|
31
|
+
id: widget.id || `widget-${index}-${crypto.randomUUID()}`
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Deep clones a widget and regenerates all IDs (including nested children)
|
|
37
|
+
*/
|
|
38
|
+
function deepCloneWidget(widget) {
|
|
39
|
+
if (isWidgetType(widget, WIDGET_TYPE_NAMES.Layout) && Array.isArray(widget.props.children)) return {
|
|
40
|
+
type: widget.type,
|
|
41
|
+
props: {
|
|
42
|
+
...widget.props,
|
|
43
|
+
children: widget.props.children.map((child) => child ? deepCloneWidget(child) : null)
|
|
44
|
+
},
|
|
45
|
+
id: generateWidgetId(widget.type)
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
type: widget.type,
|
|
49
|
+
props: { ...widget.props },
|
|
50
|
+
id: generateWidgetId(widget.type)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Deep clones an array of widgets and regenerates all IDs
|
|
55
|
+
*/
|
|
56
|
+
function deepCloneWidgets(widgets) {
|
|
57
|
+
return widgets.map((widget) => deepCloneWidget(widget));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Gets a widget at a specific path in the widget tree
|
|
61
|
+
*/
|
|
62
|
+
function getWidgetByPath(screen, path) {
|
|
63
|
+
if (path.length === 0 || path[0] === void 0) return null;
|
|
64
|
+
let current = screen[path[0]] ?? null;
|
|
65
|
+
for (let i = 1; i < path.length; i++) {
|
|
66
|
+
if (!isWidgetType(current, WIDGET_TYPE_NAMES.Layout)) return null;
|
|
67
|
+
const children = current.props.children ?? [];
|
|
68
|
+
const index = path[i];
|
|
69
|
+
if (index === void 0) return null;
|
|
70
|
+
current = children[index] ?? null;
|
|
71
|
+
}
|
|
72
|
+
return current;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Groups children by column index.
|
|
76
|
+
* Accepts nullable children (sparse arrays from grid layouts) and filters them out.
|
|
77
|
+
*/
|
|
78
|
+
function groupChildrenByColumn(children, columnCount) {
|
|
79
|
+
const columns = Array.from({ length: columnCount }, () => []);
|
|
80
|
+
const nonNullChildren = children.filter((child) => child !== null);
|
|
81
|
+
for (const child of nonNullChildren) {
|
|
82
|
+
const column = columns[Math.min(child.columnIndex ?? 0, columnCount - 1)];
|
|
83
|
+
if (column) column.push(child);
|
|
84
|
+
}
|
|
85
|
+
return columns;
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/widget-utils/utils.ts
|
|
89
|
+
function createWidgetRegistry(registry) {
|
|
90
|
+
return registry;
|
|
91
|
+
}
|
|
92
|
+
function createScreen(registry, widgets) {
|
|
93
|
+
widgets.forEach((widget) => {
|
|
94
|
+
if (!(widget.type in registry)) throw new Error(`Widget type "${String(widget.type)}" not found in registry`);
|
|
95
|
+
});
|
|
96
|
+
return widgets;
|
|
97
|
+
}
|
|
98
|
+
function createWidgetFromShareable(item) {
|
|
99
|
+
if ((item.kind === "video" || !!item.videoUrl) && item.videoUrl) return {
|
|
100
|
+
type: "VideoWidget",
|
|
101
|
+
props: {
|
|
102
|
+
src: item.videoUrl,
|
|
103
|
+
poster: item.imageUrl,
|
|
104
|
+
caption: item.title
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
type: "ImageWidget",
|
|
109
|
+
props: {
|
|
110
|
+
src: item.imageUrl,
|
|
111
|
+
alt: item.title || "Image",
|
|
112
|
+
objectFit: "cover"
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
export { createScreen, createWidgetFromShareable, createWidgetRegistry, deepCloneWidget, deepCloneWidgets, ensureWidgetIds, generateWidgetId, getWidgetByPath, groupChildrenByColumn, idToPath, pathToId };
|
|
118
|
+
|
|
119
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/widget-utils/widget-utils.ts","../../src/widget-utils/utils.ts"],"sourcesContent":["import type { WidgetSchema, WidgetPath } from \"../types\";\nimport { WIDGET_TYPE_NAMES, isWidgetType } from \"../types\";\n\n/**\n * Generates a unique ID for a widget\n */\nexport function generateWidgetId(type?: string): string {\n const uuid = crypto.randomUUID();\n return type ? `${type}-${uuid}` : uuid;\n}\n\n/**\n * Converts a widget path to a unique string identifier\n */\nexport function pathToId(path: WidgetPath): string {\n return path.join(\"-\");\n}\n\n/**\n * Converts a path string back to a WidgetPath array\n */\nexport function idToPath(id: string): WidgetPath {\n return id.split(\"-\").map((segment) => parseInt(segment, 10));\n}\n\n/**\n * Ensures all widgets in an array have valid IDs\n * Note: Handles null values for sparse arrays (e.g., grid layouts with empty cells)\n */\nexport function ensureWidgetIds(\n widgets: readonly (WidgetSchema | null)[],\n): (WidgetSchema | null)[] {\n return widgets?.map((widget, index) => {\n if (!widget) return null;\n return {\n ...widget,\n id: widget.id || `widget-${index}-${crypto.randomUUID()}`,\n };\n });\n}\n\n/**\n * Deep clones a widget and regenerates all IDs (including nested children)\n */\nexport function deepCloneWidget(widget: WidgetSchema): WidgetSchema {\n // Handle LayoutWidget children recursively\n // Use type guard for discriminated union narrowing (narrowing-discriminated-unions rule)\n if (\n isWidgetType(widget, WIDGET_TYPE_NAMES.Layout) &&\n Array.isArray(widget.props.children)\n ) {\n // Build cloned widget with recursively cloned children\n return {\n type: widget.type,\n props: {\n ...widget.props,\n children: (\n widget.props.children as readonly (WidgetSchema | null)[]\n ).map((child) => (child ? deepCloneWidget(child) : null)),\n },\n id: generateWidgetId(widget.type),\n };\n }\n\n // Clone non-container widget\n return {\n type: widget.type,\n props: { ...widget.props },\n id: generateWidgetId(widget.type),\n };\n}\n\n/**\n * Deep clones an array of widgets and regenerates all IDs\n */\nexport function deepCloneWidgets(\n widgets: readonly WidgetSchema[],\n): WidgetSchema[] {\n return widgets.map((widget) => deepCloneWidget(widget));\n}\n\n/**\n * Gets a widget at a specific path in the widget tree\n */\nexport function getWidgetByPath(\n screen: readonly (WidgetSchema | null)[],\n path: WidgetPath,\n): WidgetSchema | null {\n if (path.length === 0 || path[0] === undefined) return null;\n\n let current: WidgetSchema | null = screen[path[0]] ?? null;\n\n for (let i = 1; i < path.length; i++) {\n // Use type guard for discriminated union narrowing (narrowing-discriminated-unions rule)\n if (!isWidgetType(current, WIDGET_TYPE_NAMES.Layout)) return null;\n\n const children = (current.props.children ??\n []) as readonly (WidgetSchema | null)[];\n const index = path[i];\n if (index === undefined) return null;\n current = children[index] ?? null;\n }\n\n return current;\n}\n\n/**\n * Groups children by column index.\n * Accepts nullable children (sparse arrays from grid layouts) and filters them out.\n */\nexport function groupChildrenByColumn(\n children: readonly (WidgetSchema | null)[],\n columnCount: number,\n): WidgetSchema[][] {\n // Use explicit type annotation to avoid never[] inference (narrowing-empty-array-type rule)\n const columns: WidgetSchema[][] = Array.from(\n { length: columnCount },\n (): WidgetSchema[] => [],\n );\n\n // Filter out nulls first, then process (truthiness narrowing rule)\n // This avoids the narrowing-callback-scope issue since we work with non-null array\n const nonNullChildren = children.filter(\n (child): child is WidgetSchema => child !== null,\n );\n\n for (const child of nonNullChildren) {\n // Default to column 0 if no columnIndex specified\n const colIndex = Math.min(child.columnIndex ?? 0, columnCount - 1);\n const column = columns[colIndex];\n if (column) {\n column.push(child);\n }\n }\n\n return columns;\n}\n","import type { ComponentType } from \"react\";\nimport type { WidgetSchema, TypedWidgetSchema } from \"../types\";\nimport type { ShareableItem } from \"../types/shareable-item\";\n\nexport function createWidgetRegistry<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, ComponentType<any>>,\n>(registry: T): T {\n // Return the registry with its original type intact for type inference\n return registry;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function createScreen<T extends Record<string, ComponentType<any>>>(\n registry: T,\n widgets: TypedWidgetSchema<T>[],\n): TypedWidgetSchema<T>[] {\n // Validate that all widget types exist in the registry at runtime\n widgets.forEach((widget) => {\n if (!(widget.type in registry)) {\n throw new Error(\n `Widget type \"${String(widget.type)}\" not found in registry`,\n );\n }\n });\n return widgets;\n}\n\n// Helper to create WidgetSchema from shareable item\nexport function createWidgetFromShareable(item: ShareableItem): WidgetSchema {\n const isVideo = item.kind === \"video\" || !!item.videoUrl;\n\n if (isVideo && item.videoUrl) {\n return {\n type: \"VideoWidget\",\n props: {\n src: item.videoUrl,\n poster: item.imageUrl,\n caption: item.title,\n },\n };\n }\n\n return {\n type: \"ImageWidget\",\n props: {\n src: item.imageUrl,\n alt: item.title || \"Image\",\n objectFit: \"cover\",\n },\n };\n}\n"],"mappings":";;;;;AAMA,SAAgB,iBAAiB,MAAuB;CACtD,MAAM,OAAO,OAAO,YAAY;AAChC,QAAO,OAAO,GAAG,KAAK,GAAG,SAAS;;;;;AAMpC,SAAgB,SAAS,MAA0B;AACjD,QAAO,KAAK,KAAK,IAAI;;;;;AAMvB,SAAgB,SAAS,IAAwB;AAC/C,QAAO,GAAG,MAAM,IAAI,CAAC,KAAK,YAAY,SAAS,SAAS,GAAG,CAAC;;;;;;AAO9D,SAAgB,gBACd,SACyB;AACzB,QAAO,SAAS,KAAK,QAAQ,UAAU;AACrC,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO;GACL,GAAG;GACH,IAAI,OAAO,MAAM,UAAU,MAAM,GAAG,OAAO,YAAY;GACxD;GACD;;;;;AAMJ,SAAgB,gBAAgB,QAAoC;AAGlE,KACE,aAAa,QAAQ,kBAAkB,OAAO,IAC9C,MAAM,QAAQ,OAAO,MAAM,SAAS,CAGpC,QAAO;EACL,MAAM,OAAO;EACb,OAAO;GACL,GAAG,OAAO;GACV,UACE,OAAO,MAAM,SACb,KAAK,UAAW,QAAQ,gBAAgB,MAAM,GAAG,KAAM;GAC1D;EACD,IAAI,iBAAiB,OAAO,KAAK;EAClC;AAIH,QAAO;EACL,MAAM,OAAO;EACb,OAAO,EAAE,GAAG,OAAO,OAAO;EAC1B,IAAI,iBAAiB,OAAO,KAAK;EAClC;;;;;AAMH,SAAgB,iBACd,SACgB;AAChB,QAAO,QAAQ,KAAK,WAAW,gBAAgB,OAAO,CAAC;;;;;AAMzD,SAAgB,gBACd,QACA,MACqB;AACrB,KAAI,KAAK,WAAW,KAAK,KAAK,OAAO,KAAA,EAAW,QAAO;CAEvD,IAAI,UAA+B,OAAO,KAAK,OAAO;AAEtD,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AAEpC,MAAI,CAAC,aAAa,SAAS,kBAAkB,OAAO,CAAE,QAAO;EAE7D,MAAM,WAAY,QAAQ,MAAM,YAC9B,EAAE;EACJ,MAAM,QAAQ,KAAK;AACnB,MAAI,UAAU,KAAA,EAAW,QAAO;AAChC,YAAU,SAAS,UAAU;;AAG/B,QAAO;;;;;;AAOT,SAAgB,sBACd,UACA,aACkB;CAElB,MAAM,UAA4B,MAAM,KACtC,EAAE,QAAQ,aAAa,QACD,EAAE,CACzB;CAID,MAAM,kBAAkB,SAAS,QAC9B,UAAiC,UAAU,KAC7C;AAED,MAAK,MAAM,SAAS,iBAAiB;EAGnC,MAAM,SAAS,QADE,KAAK,IAAI,MAAM,eAAe,GAAG,cAAc,EAAE;AAElE,MAAI,OACF,QAAO,KAAK,MAAM;;AAItB,QAAO;;;;ACnIT,SAAgB,qBAGd,UAAgB;AAEhB,QAAO;;AAIT,SAAgB,aACd,UACA,SACwB;AAExB,SAAQ,SAAS,WAAW;AAC1B,MAAI,EAAE,OAAO,QAAQ,UACnB,OAAM,IAAI,MACR,gBAAgB,OAAO,OAAO,KAAK,CAAC,yBACrC;GAEH;AACF,QAAO;;AAIT,SAAgB,0BAA0B,MAAmC;AAG3E,MAFgB,KAAK,SAAS,WAAW,CAAC,CAAC,KAAK,aAEjC,KAAK,SAClB,QAAO;EACL,MAAM;EACN,OAAO;GACL,KAAK,KAAK;GACV,QAAQ,KAAK;GACb,SAAS,KAAK;GACf;EACF;AAGH,QAAO;EACL,MAAM;EACN,OAAO;GACL,KAAK,KAAK;GACV,KAAK,KAAK,SAAS;GACnB,WAAW;GACZ;EACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluid-app/rep-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"description": "Core types, theme engine, and widget utilities for the Fluid rep platform",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -168,7 +168,7 @@
|
|
|
168
168
|
"@tanstack/react-query": "^5.90.11",
|
|
169
169
|
"@types/react": "^19.2.13",
|
|
170
170
|
"react": "^19.2.4",
|
|
171
|
-
"
|
|
171
|
+
"tsdown": "^0.21.0",
|
|
172
172
|
"typescript": "^5",
|
|
173
173
|
"@fluid-app/typescript-config": "0.0.0"
|
|
174
174
|
},
|
|
@@ -188,8 +188,8 @@
|
|
|
188
188
|
}
|
|
189
189
|
},
|
|
190
190
|
"scripts": {
|
|
191
|
-
"build": "
|
|
192
|
-
"dev": "
|
|
191
|
+
"build": "tsdown",
|
|
192
|
+
"dev": "tsdown --watch",
|
|
193
193
|
"lint": "oxlint",
|
|
194
194
|
"lint:fix": "oxlint --fix",
|
|
195
195
|
"typecheck": "tsc --noEmit"
|
package/dist/chunk-2SPTFZRC.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { createContext, useSyncExternalStore, useCallback, useMemo, useContext } from 'react';
|
|
2
|
-
import { jsx } from 'react/jsx-runtime';
|
|
3
|
-
|
|
4
|
-
// src/shell/ThemeModeContext.tsx
|
|
5
|
-
var ThemeModeContext = createContext(null);
|
|
6
|
-
var darkMediaQuery = typeof window !== "undefined" ? window.matchMedia("(prefers-color-scheme: dark)") : null;
|
|
7
|
-
function subscribeToPrefersColorScheme(callback) {
|
|
8
|
-
darkMediaQuery?.addEventListener("change", callback);
|
|
9
|
-
return () => darkMediaQuery?.removeEventListener("change", callback);
|
|
10
|
-
}
|
|
11
|
-
function getSystemPrefersDark() {
|
|
12
|
-
return darkMediaQuery?.matches ?? false;
|
|
13
|
-
}
|
|
14
|
-
function getServerSnapshot() {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
function ThemeModeProvider({
|
|
18
|
-
children,
|
|
19
|
-
mode,
|
|
20
|
-
onModeChange,
|
|
21
|
-
autoModeEnabled = true
|
|
22
|
-
}) {
|
|
23
|
-
const systemPrefersDark = useSyncExternalStore(
|
|
24
|
-
subscribeToPrefersColorScheme,
|
|
25
|
-
getSystemPrefersDark,
|
|
26
|
-
getServerSnapshot
|
|
27
|
-
);
|
|
28
|
-
const systemMode = systemPrefersDark ? "dark" : "light";
|
|
29
|
-
const displayMode = mode === "auto" ? systemMode : mode;
|
|
30
|
-
const cycleMode = useCallback(() => {
|
|
31
|
-
if (autoModeEnabled) {
|
|
32
|
-
const target = displayMode === "light" ? "dark" : "light";
|
|
33
|
-
onModeChange(target === systemMode ? "auto" : target);
|
|
34
|
-
} else {
|
|
35
|
-
onModeChange(mode === "light" ? "dark" : "light");
|
|
36
|
-
}
|
|
37
|
-
}, [mode, displayMode, systemMode, onModeChange, autoModeEnabled]);
|
|
38
|
-
const dataAttribute = getThemeModeAttribute(mode);
|
|
39
|
-
const value = useMemo(
|
|
40
|
-
() => ({
|
|
41
|
-
mode,
|
|
42
|
-
displayMode,
|
|
43
|
-
setMode: onModeChange,
|
|
44
|
-
autoModeEnabled,
|
|
45
|
-
cycleMode,
|
|
46
|
-
dataAttribute
|
|
47
|
-
}),
|
|
48
|
-
[
|
|
49
|
-
mode,
|
|
50
|
-
displayMode,
|
|
51
|
-
onModeChange,
|
|
52
|
-
autoModeEnabled,
|
|
53
|
-
cycleMode,
|
|
54
|
-
dataAttribute
|
|
55
|
-
]
|
|
56
|
-
);
|
|
57
|
-
return /* @__PURE__ */ jsx(ThemeModeContext.Provider, { value, children });
|
|
58
|
-
}
|
|
59
|
-
function useThemeMode() {
|
|
60
|
-
const ctx = useContext(ThemeModeContext);
|
|
61
|
-
if (!ctx) {
|
|
62
|
-
throw new Error("useThemeMode must be used within a ThemeModeProvider");
|
|
63
|
-
}
|
|
64
|
-
return ctx;
|
|
65
|
-
}
|
|
66
|
-
function getThemeModeAttribute(mode) {
|
|
67
|
-
return mode === "auto" ? void 0 : mode;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export { ThemeModeProvider, getThemeModeAttribute, useThemeMode };
|
|
71
|
-
//# sourceMappingURL=chunk-2SPTFZRC.js.map
|
|
72
|
-
//# sourceMappingURL=chunk-2SPTFZRC.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/shell/ThemeModeContext.tsx"],"names":[],"mappings":";;;;AAwBA,IAAM,gBAAA,GAAmB,cAA4C,IAAI,CAAA;AAEzE,IAAM,iBACJ,OAAO,MAAA,KAAW,cACd,MAAA,CAAO,UAAA,CAAW,8BAA8B,CAAA,GAChD,IAAA;AAEN,SAAS,8BAA8B,QAAA,EAAsB;AAC3D,EAAA,cAAA,EAAgB,gBAAA,CAAiB,UAAU,QAAQ,CAAA;AACnD,EAAA,OAAO,MAAM,cAAA,EAAgB,mBAAA,CAAoB,QAAA,EAAU,QAAQ,CAAA;AACrE;AAEA,SAAS,oBAAA,GAAgC;AACvC,EAAA,OAAO,gBAAgB,OAAA,IAAW,KAAA;AACpC;AAEA,SAAS,iBAAA,GAA6B;AACpC,EAAA,OAAO,KAAA;AACT;AAUO,SAAS,iBAAA,CAAkB;AAAA,EAChC,QAAA;AAAA,EACA,IAAA;AAAA,EACA,YAAA;AAAA,EACA,eAAA,GAAkB;AACpB,CAAA,EAA2B;AACzB,EAAA,MAAM,iBAAA,GAAoB,oBAAA;AAAA,IACxB,6BAAA;AAAA,IACA,oBAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,MAAM,UAAA,GAA0B,oBAAoB,MAAA,GAAS,OAAA;AAE7D,EAAA,MAAM,WAAA,GAA2B,IAAA,KAAS,MAAA,GAAS,UAAA,GAAa,IAAA;AAEhE,EAAA,MAAM,SAAA,GAAY,YAAY,MAAM;AAClC,IAAA,IAAI,eAAA,EAAiB;AAEnB,MAAA,MAAM,MAAA,GAAsB,WAAA,KAAgB,OAAA,GAAU,MAAA,GAAS,OAAA;AAC/D,MAAA,YAAA,CAAa,MAAA,KAAW,UAAA,GAAa,MAAA,GAAS,MAAM,CAAA;AAAA,IACtD,CAAA,MAAO;AAEL,MAAA,YAAA,CAAa,IAAA,KAAS,OAAA,GAAU,MAAA,GAAS,OAAO,CAAA;AAAA,IAClD;AAAA,EACF,GAAG,CAAC,IAAA,EAAM,aAAa,UAAA,EAAY,YAAA,EAAc,eAAe,CAAC,CAAA;AAEjE,EAAA,MAAM,aAAA,GAAgB,sBAAsB,IAAI,CAAA;AAEhD,EAAA,MAAM,KAAA,GAAQ,OAAA;AAAA,IACZ,OAAO;AAAA,MACL,IAAA;AAAA,MACA,WAAA;AAAA,MACA,OAAA,EAAS,YAAA;AAAA,MACT,eAAA;AAAA,MACA,SAAA;AAAA,MACA;AAAA,KACF,CAAA;AAAA,IACA;AAAA,MACE,IAAA;AAAA,MACA,WAAA;AAAA,MACA,YAAA;AAAA,MACA,eAAA;AAAA,MACA,SAAA;AAAA,MACA;AAAA;AACF,GACF;AAEA,EAAA,uBACE,GAAA,CAAC,gBAAA,CAAiB,QAAA,EAAjB,EAA0B,OACxB,QAAA,EACH,CAAA;AAEJ;AAGO,SAAS,YAAA,GAAsC;AACpD,EAAA,MAAM,GAAA,GAAM,WAAW,gBAAgB,CAAA;AACvC,EAAA,IAAI,CAAC,GAAA,EAAK;AACR,IAAA,MAAM,IAAI,MAAM,sDAAsD,CAAA;AAAA,EACxE;AACA,EAAA,OAAO,GAAA;AACT;AAGO,SAAS,sBAAsB,IAAA,EAAqC;AACzE,EAAA,OAAO,IAAA,KAAS,SAAS,MAAA,GAAY,IAAA;AACvC","file":"chunk-2SPTFZRC.js","sourcesContent":["\"use client\";\n\nimport {\n createContext,\n useContext,\n useCallback,\n useMemo,\n useSyncExternalStore,\n type ReactNode,\n} from \"react\";\n\nexport type ThemeMode = \"auto\" | \"light\" | \"dark\";\n\nexport type DisplayMode = \"light\" | \"dark\";\n\nexport interface ThemeModeContextValue {\n mode: ThemeMode;\n displayMode: DisplayMode;\n setMode: (mode: ThemeMode) => void;\n autoModeEnabled: boolean;\n cycleMode: () => void;\n dataAttribute: string | undefined;\n}\n\nconst ThemeModeContext = createContext<ThemeModeContextValue | null>(null);\n\nconst darkMediaQuery =\n typeof window !== \"undefined\"\n ? window.matchMedia(\"(prefers-color-scheme: dark)\")\n : null;\n\nfunction subscribeToPrefersColorScheme(callback: () => void) {\n darkMediaQuery?.addEventListener(\"change\", callback);\n return () => darkMediaQuery?.removeEventListener(\"change\", callback);\n}\n\nfunction getSystemPrefersDark(): boolean {\n return darkMediaQuery?.matches ?? false;\n}\n\nfunction getServerSnapshot(): boolean {\n return false;\n}\n\ninterface ThemeModeProviderProps {\n children: ReactNode;\n mode: ThemeMode;\n onModeChange: (mode: ThemeMode) => void;\n /** When false, auto mode is skipped in the cycle (light↔dark only). Default true. */\n autoModeEnabled?: boolean;\n}\n\nexport function ThemeModeProvider({\n children,\n mode,\n onModeChange,\n autoModeEnabled = true,\n}: ThemeModeProviderProps) {\n const systemPrefersDark = useSyncExternalStore(\n subscribeToPrefersColorScheme,\n getSystemPrefersDark,\n getServerSnapshot,\n );\n\n const systemMode: DisplayMode = systemPrefersDark ? \"dark\" : \"light\";\n\n const displayMode: DisplayMode = mode === \"auto\" ? systemMode : mode;\n\n const cycleMode = useCallback(() => {\n if (autoModeEnabled) {\n // Toggle displayed mode. If target matches system preference, use \"auto\".\n const target: DisplayMode = displayMode === \"light\" ? \"dark\" : \"light\";\n onModeChange(target === systemMode ? \"auto\" : target);\n } else {\n // light ↔ dark\n onModeChange(mode === \"light\" ? \"dark\" : \"light\");\n }\n }, [mode, displayMode, systemMode, onModeChange, autoModeEnabled]);\n\n const dataAttribute = getThemeModeAttribute(mode);\n\n const value = useMemo(\n () => ({\n mode,\n displayMode,\n setMode: onModeChange,\n autoModeEnabled,\n cycleMode,\n dataAttribute,\n }),\n [\n mode,\n displayMode,\n onModeChange,\n autoModeEnabled,\n cycleMode,\n dataAttribute,\n ],\n );\n\n return (\n <ThemeModeContext.Provider value={value}>\n {children}\n </ThemeModeContext.Provider>\n );\n}\n\n/** Access the current theme mode, setter, and cycle helper. Must be used within a `ThemeModeProvider`. */\nexport function useThemeMode(): ThemeModeContextValue {\n const ctx = useContext(ThemeModeContext);\n if (!ctx) {\n throw new Error(\"useThemeMode must be used within a ThemeModeProvider\");\n }\n return ctx;\n}\n\n/** Maps a ThemeMode to the value for `data-theme-mode`. Returns undefined for \"auto\". */\nexport function getThemeModeAttribute(mode: ThemeMode): string | undefined {\n return mode === \"auto\" ? undefined : mode;\n}\n"]}
|
package/dist/chunk-3I5Y3PEO.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { createContext, useMemo, useContext } from 'react';
|
|
2
|
-
import { jsx } from 'react/jsx-runtime';
|
|
3
|
-
|
|
4
|
-
// src/data-sources/context.tsx
|
|
5
|
-
var DataSourceContext = createContext({});
|
|
6
|
-
function DataSourceProvider({
|
|
7
|
-
baseUrl,
|
|
8
|
-
getApiHeaders,
|
|
9
|
-
children
|
|
10
|
-
}) {
|
|
11
|
-
const value = useMemo(
|
|
12
|
-
() => ({ baseUrl, getApiHeaders }),
|
|
13
|
-
[baseUrl, getApiHeaders]
|
|
14
|
-
);
|
|
15
|
-
return /* @__PURE__ */ jsx(DataSourceContext.Provider, { value, children });
|
|
16
|
-
}
|
|
17
|
-
function useDataSourceConfig() {
|
|
18
|
-
return useContext(DataSourceContext);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { DataSourceProvider, useDataSourceConfig };
|
|
22
|
-
//# sourceMappingURL=chunk-3I5Y3PEO.js.map
|
|
23
|
-
//# sourceMappingURL=chunk-3I5Y3PEO.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/data-sources/context.tsx"],"names":[],"mappings":";;;;AAOA,IAAM,iBAAA,GAAoB,aAAA,CAAsC,EAAE,CAAA;AAQ3D,SAAS,kBAAA,CAAmB;AAAA,EACjC,OAAA;AAAA,EACA,aAAA;AAAA,EACA;AACF,CAAA,EAA4B;AAC1B,EAAA,MAAM,KAAA,GAAQ,OAAA;AAAA,IACZ,OAAO,EAAE,OAAA,EAAS,aAAA,EAAc,CAAA;AAAA,IAChC,CAAC,SAAS,aAAa;AAAA,GACzB;AAEA,EAAA,uBACE,GAAA,CAAC,iBAAA,CAAkB,QAAA,EAAlB,EAA2B,OACzB,QAAA,EACH,CAAA;AAEJ;AAEO,SAAS,mBAAA,GAA8C;AAC5D,EAAA,OAAO,WAAW,iBAAiB,CAAA;AACrC","file":"chunk-3I5Y3PEO.js","sourcesContent":["import { createContext, useContext, useMemo, type ReactNode } from \"react\";\n\nexport interface DataSourceContextValue {\n baseUrl?: string | undefined;\n getApiHeaders?: (() => Record<string, string>) | undefined;\n}\n\nconst DataSourceContext = createContext<DataSourceContextValue>({});\n\nexport interface DataSourceProviderProps {\n baseUrl?: string | undefined;\n getApiHeaders?: (() => Record<string, string>) | undefined;\n children: ReactNode;\n}\n\nexport function DataSourceProvider({\n baseUrl,\n getApiHeaders,\n children,\n}: DataSourceProviderProps) {\n const value = useMemo(\n () => ({ baseUrl, getApiHeaders }),\n [baseUrl, getApiHeaders],\n );\n\n return (\n <DataSourceContext.Provider value={value}>\n {children}\n </DataSourceContext.Provider>\n );\n}\n\nexport function useDataSourceConfig(): DataSourceContextValue {\n return useContext(DataSourceContext);\n}\n"]}
|