@demokit-ui/demokit 0.1.2 → 0.2.0
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/README.md +44 -0
- package/dist/app/tweak-panel.d.ts +2 -1
- package/dist/app/tweak-panel.js +165 -93
- package/dist/config/settings.config.js +1 -0
- package/dist/config/types.d.ts +58 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +826 -812
- package/dist/kit/themes/adaptive-theme-panel.d.ts +14 -0
- package/dist/kit/themes/adaptive-theme-panel.js +196 -0
- package/dist/kit/themes/adaptive-theme.d.ts +54 -0
- package/dist/kit/themes/adaptive-theme.js +377 -0
- package/dist/kit/themes/theme-toggle.js +25 -15
- package/dist/kit/tokens/chart-palette.js +6 -6
- package/dist/providers/demokit-provider.d.ts +5 -2
- package/dist/providers/demokit-provider.js +8 -5
- package/dist/providers/settings-provider.d.ts +10 -2
- package/dist/providers/settings-provider.js +98 -55
- package/package.json +1 -1
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useSettings as
|
|
3
|
-
import { cn as
|
|
4
|
-
const
|
|
1
|
+
import { jsxs as a, jsx as t } from "react/jsx-runtime";
|
|
2
|
+
import { useSettings as i } from "../../providers/settings-provider.js";
|
|
3
|
+
import { cn as l } from "../../lib/utils.js";
|
|
4
|
+
const d = [
|
|
5
5
|
{ value: "glass", label: "活力", dot: "#009ef7" },
|
|
6
6
|
{ value: "navy", label: "沉稳", dot: "#2563eb" }
|
|
7
7
|
];
|
|
8
|
-
function
|
|
9
|
-
const { settings: o, storeOption:
|
|
10
|
-
|
|
8
|
+
function u() {
|
|
9
|
+
const { settings: o, storeOption: s } = i(), r = o.adaptiveTheme ? [
|
|
10
|
+
...d,
|
|
11
|
+
{
|
|
12
|
+
value: "adaptive",
|
|
13
|
+
label: "自适配",
|
|
14
|
+
dot: o.adaptiveTheme.tokens.primary
|
|
15
|
+
}
|
|
16
|
+
] : d;
|
|
17
|
+
return /* @__PURE__ */ a("div", { className: "theme-toggle px-5 pb-4 pt-3 border-t border-border", children: [
|
|
11
18
|
/* @__PURE__ */ t(
|
|
12
19
|
"div",
|
|
13
20
|
{
|
|
@@ -20,18 +27,21 @@ function g() {
|
|
|
20
27
|
"div",
|
|
21
28
|
{
|
|
22
29
|
"data-slot": "theme-toggle-grid",
|
|
23
|
-
className:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
className: l(
|
|
31
|
+
"grid gap-1 rounded-md bg-muted p-1",
|
|
32
|
+
r.length === 3 ? "grid-cols-3" : "grid-cols-2"
|
|
33
|
+
),
|
|
34
|
+
children: r.map((e) => {
|
|
35
|
+
const n = o.theme === e.value;
|
|
36
|
+
return /* @__PURE__ */ a(
|
|
27
37
|
"button",
|
|
28
38
|
{
|
|
29
39
|
type: "button",
|
|
30
|
-
onClick: () =>
|
|
40
|
+
onClick: () => s("theme", e.value),
|
|
31
41
|
title: e.label,
|
|
32
|
-
className:
|
|
42
|
+
className: l(
|
|
33
43
|
"flex items-center justify-center gap-1.5 h-8 rounded text-xs font-medium transition-colors",
|
|
34
|
-
|
|
44
|
+
n ? "bg-card text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"
|
|
35
45
|
),
|
|
36
46
|
children: [
|
|
37
47
|
/* @__PURE__ */ t(
|
|
@@ -52,5 +62,5 @@ function g() {
|
|
|
52
62
|
] });
|
|
53
63
|
}
|
|
54
64
|
export {
|
|
55
|
-
|
|
65
|
+
u as ThemeToggle
|
|
56
66
|
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { useOptionalSettings as
|
|
2
|
-
const
|
|
1
|
+
import { useOptionalSettings as a } from "../../providers/settings-provider.js";
|
|
2
|
+
const s = {
|
|
3
3
|
glass: ["#009EF7", "#1BC5BD", "#FFA800", "#8950FC", "#F64E60", "#50CD89"],
|
|
4
4
|
navy: ["#2563eb", "#7c3aed", "#0d9488", "#f97316", "#e11d48", "#0891b2"]
|
|
5
5
|
};
|
|
6
|
-
function
|
|
7
|
-
const
|
|
8
|
-
return t[e] ??
|
|
6
|
+
function i() {
|
|
7
|
+
const t = a(), e = t?.settings.theme ?? "glass";
|
|
8
|
+
return e === "adaptive" && t?.settings.adaptiveTheme ? t.settings.adaptiveTheme.tokens.chart : s[e] ?? s.glass;
|
|
9
9
|
}
|
|
10
10
|
export {
|
|
11
|
-
|
|
11
|
+
i as useChartPalette
|
|
12
12
|
};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
|
|
2
|
+
import { SettingsProviderInitialSettings } from './settings-provider';
|
|
3
|
+
export interface DemoKitProviderProps {
|
|
3
4
|
children: ReactNode;
|
|
4
|
-
|
|
5
|
+
initialSettings?: SettingsProviderInitialSettings;
|
|
6
|
+
}
|
|
7
|
+
export declare function DemoKitProvider({ children, initialSettings, }: DemoKitProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { jsx as r } from "react/jsx-runtime";
|
|
2
|
-
import { SettingsProvider as
|
|
3
|
-
import { TooltipsProvider as
|
|
4
|
-
function
|
|
5
|
-
|
|
2
|
+
import { SettingsProvider as t } from "./settings-provider.js";
|
|
3
|
+
import { TooltipsProvider as e } from "./tooltips-provider.js";
|
|
4
|
+
function d({
|
|
5
|
+
children: o,
|
|
6
|
+
initialSettings: i
|
|
7
|
+
}) {
|
|
8
|
+
return /* @__PURE__ */ r(t, { initialSettings: i, children: /* @__PURE__ */ r(e, { children: o }) });
|
|
6
9
|
}
|
|
7
10
|
export {
|
|
8
|
-
|
|
11
|
+
d as DemoKitProvider
|
|
9
12
|
};
|
|
@@ -7,9 +7,17 @@ type SettingsContextType = {
|
|
|
7
7
|
storeOption: <T = any>(path: Path, value: T) => void;
|
|
8
8
|
settings: Settings;
|
|
9
9
|
};
|
|
10
|
-
export
|
|
10
|
+
export type SettingsProviderInitialSettings = Partial<Omit<Settings, 'appearance' | 'layouts'>> & {
|
|
11
|
+
appearance?: Partial<Settings['appearance']>;
|
|
12
|
+
layouts?: {
|
|
13
|
+
[K in keyof Settings['layouts']]?: Partial<Settings['layouts'][K]>;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export interface SettingsProviderProps {
|
|
11
17
|
children: React.ReactNode;
|
|
12
|
-
|
|
18
|
+
initialSettings?: SettingsProviderInitialSettings;
|
|
19
|
+
}
|
|
20
|
+
export declare const SettingsProvider: React.FC<SettingsProviderProps>;
|
|
13
21
|
export declare const useSettings: () => SettingsContextType;
|
|
14
22
|
export declare const useOptionalSettings: () => SettingsContextType | undefined;
|
|
15
23
|
export {};
|
|
@@ -1,78 +1,121 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { jsx as T } from "react/jsx-runtime";
|
|
2
|
+
import { useState as w, useEffect as i, useCallback as y, useMemo as P, useContext as O, createContext as x } from "react";
|
|
3
|
+
import { applyAdaptiveTheme as C, clearAdaptiveTheme as S } from "../kit/themes/adaptive-theme.js";
|
|
4
|
+
import { APP_SETTINGS as v } from "../config/settings.config.js";
|
|
5
|
+
const g = x(
|
|
5
6
|
void 0
|
|
6
7
|
), l = "app_settings_", c = () => typeof window < "u";
|
|
7
|
-
function
|
|
8
|
-
return
|
|
8
|
+
function L(t, e) {
|
|
9
|
+
return e.split(".").reduce((o, a) => o?.[a], t);
|
|
9
10
|
}
|
|
10
|
-
function
|
|
11
|
-
const
|
|
12
|
-
return u
|
|
11
|
+
function h(t, e, o) {
|
|
12
|
+
const a = e.split("."), u = a.pop(), d = a.reduce((m, f) => m[f] ??= {}, t);
|
|
13
|
+
return d[u] = o, { ...t };
|
|
13
14
|
}
|
|
14
|
-
function
|
|
15
|
+
function A(t, e) {
|
|
15
16
|
if (c())
|
|
16
17
|
try {
|
|
17
18
|
localStorage.setItem(
|
|
18
|
-
`${l}${
|
|
19
|
-
JSON.stringify(
|
|
19
|
+
`${l}${t}`,
|
|
20
|
+
JSON.stringify(e)
|
|
20
21
|
);
|
|
21
|
-
} catch (
|
|
22
|
-
console.error("LocalStorage write error:",
|
|
22
|
+
} catch (o) {
|
|
23
|
+
console.error("LocalStorage write error:", o);
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
|
-
function
|
|
26
|
+
function I(t) {
|
|
26
27
|
if (c())
|
|
27
28
|
try {
|
|
28
|
-
const
|
|
29
|
-
return
|
|
30
|
-
} catch (
|
|
31
|
-
console.error("LocalStorage read error:",
|
|
29
|
+
const e = localStorage.getItem(`${l}${t}`);
|
|
30
|
+
return e ? JSON.parse(e) : void 0;
|
|
31
|
+
} catch (e) {
|
|
32
|
+
console.error("LocalStorage read error:", e);
|
|
32
33
|
return;
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
function E(t) {
|
|
37
|
+
const e = structuredClone(v);
|
|
38
|
+
return t ? {
|
|
39
|
+
...e,
|
|
40
|
+
...t,
|
|
41
|
+
appearance: {
|
|
42
|
+
...e.appearance,
|
|
43
|
+
...t.appearance
|
|
44
|
+
},
|
|
45
|
+
layouts: {
|
|
46
|
+
...e.layouts,
|
|
47
|
+
...t.layouts,
|
|
48
|
+
demo1: {
|
|
49
|
+
...e.layouts.demo1,
|
|
50
|
+
...t.layouts?.demo1
|
|
51
|
+
},
|
|
52
|
+
demo2: {
|
|
53
|
+
...e.layouts.demo2,
|
|
54
|
+
...t.layouts?.demo2
|
|
55
|
+
},
|
|
56
|
+
demo5: {
|
|
57
|
+
...e.layouts.demo5,
|
|
58
|
+
...t.layouts?.demo5
|
|
59
|
+
},
|
|
60
|
+
demo7: {
|
|
61
|
+
...e.layouts.demo7,
|
|
62
|
+
...t.layouts?.demo7
|
|
63
|
+
},
|
|
64
|
+
demo9: {
|
|
65
|
+
...e.layouts.demo9,
|
|
66
|
+
...t.layouts?.demo9
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
} : e;
|
|
70
|
+
}
|
|
71
|
+
const F = ({
|
|
72
|
+
children: t,
|
|
73
|
+
initialSettings: e
|
|
37
74
|
}) => {
|
|
38
|
-
const [
|
|
39
|
-
|
|
75
|
+
const [o, a] = w(
|
|
76
|
+
() => E(e)
|
|
40
77
|
);
|
|
41
|
-
|
|
78
|
+
i(() => {
|
|
79
|
+
if (!c()) return;
|
|
80
|
+
const r = E(e);
|
|
81
|
+
Object.keys(localStorage).filter((n) => n.startsWith(l)).forEach((n) => {
|
|
82
|
+
const s = n.replace(l, ""), p = I(s);
|
|
83
|
+
p !== void 0 && h(r, s, p);
|
|
84
|
+
}), a(r);
|
|
85
|
+
}, [e]), i(() => {
|
|
86
|
+
c() && (document.documentElement.dataset.theme = o.theme);
|
|
87
|
+
}, [o.theme]), i(() => {
|
|
42
88
|
if (!c()) return;
|
|
43
|
-
const r =
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
n((a) => {
|
|
60
|
-
const d = S({ ...a }, r, o);
|
|
61
|
-
return x(r, o), d;
|
|
89
|
+
const r = document.documentElement;
|
|
90
|
+
if (o.theme === "adaptive" && o.adaptiveTheme)
|
|
91
|
+
return C(r, o.adaptiveTheme), () => S(r);
|
|
92
|
+
S(r);
|
|
93
|
+
}, [o.theme, o.adaptiveTheme]), i(() => {
|
|
94
|
+
c() && (document.documentElement.dataset.density = o.appearance?.density ?? v.appearance.density, document.documentElement.dataset.radius = o.appearance?.radius ?? v.appearance.radius);
|
|
95
|
+
}, [o.appearance?.density, o.appearance?.radius]);
|
|
96
|
+
const u = y(
|
|
97
|
+
(r) => L(o, r),
|
|
98
|
+
[o]
|
|
99
|
+
), d = y((r, n) => {
|
|
100
|
+
a((s) => h({ ...s }, r, n));
|
|
101
|
+
}, []), m = y((r, n) => {
|
|
102
|
+
a((s) => {
|
|
103
|
+
const p = h({ ...s }, r, n);
|
|
104
|
+
return A(r, n), p;
|
|
62
105
|
});
|
|
63
|
-
}, []),
|
|
64
|
-
() => ({ getOption:
|
|
65
|
-
[
|
|
106
|
+
}, []), f = P(
|
|
107
|
+
() => ({ getOption: u, setOption: d, storeOption: m, settings: o }),
|
|
108
|
+
[u, d, m, o]
|
|
66
109
|
);
|
|
67
|
-
return /* @__PURE__ */
|
|
68
|
-
},
|
|
69
|
-
const
|
|
70
|
-
if (!
|
|
110
|
+
return /* @__PURE__ */ T(g.Provider, { value: f, children: t });
|
|
111
|
+
}, N = () => {
|
|
112
|
+
const t = O(g);
|
|
113
|
+
if (!t)
|
|
71
114
|
throw new Error("useSettings must be used within a SettingsProvider");
|
|
72
|
-
return
|
|
73
|
-
},
|
|
115
|
+
return t;
|
|
116
|
+
}, j = () => O(g);
|
|
74
117
|
export {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
118
|
+
F as SettingsProvider,
|
|
119
|
+
j as useOptionalSettings,
|
|
120
|
+
N as useSettings
|
|
78
121
|
};
|