@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.
@@ -1,13 +1,20 @@
1
- import { jsxs as r, jsx as t } from "react/jsx-runtime";
2
- import { useSettings as s } from "../../providers/settings-provider.js";
3
- import { cn as d } from "../../lib/utils.js";
4
- const n = [
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 g() {
9
- const { settings: o, storeOption: l } = s();
10
- return /* @__PURE__ */ r("div", { className: "theme-toggle px-5 pb-4 pt-3 border-t border-border", children: [
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: "grid grid-cols-2 gap-1 p-1 bg-muted rounded-md",
24
- children: n.map((e) => {
25
- const a = o.theme === e.value;
26
- return /* @__PURE__ */ r(
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: () => l("theme", e.value),
40
+ onClick: () => s("theme", e.value),
31
41
  title: e.label,
32
- className: d(
42
+ className: l(
33
43
  "flex items-center justify-center gap-1.5 h-8 rounded text-xs font-medium transition-colors",
34
- a ? "bg-card text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"
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
- g as ThemeToggle
65
+ u as ThemeToggle
56
66
  };
@@ -1,12 +1,12 @@
1
- import { useOptionalSettings as s } from "../../providers/settings-provider.js";
2
- const t = {
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 a() {
7
- const e = s()?.settings.theme ?? "glass";
8
- return t[e] ?? t.glass;
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
- a as useChartPalette
11
+ i as useChartPalette
12
12
  };
@@ -1,4 +1,7 @@
1
1
  import { ReactNode } from 'react';
2
- export declare function DemoKitProvider({ children }: {
2
+ import { SettingsProviderInitialSettings } from './settings-provider';
3
+ export interface DemoKitProviderProps {
3
4
  children: ReactNode;
4
- }): import("react/jsx-runtime").JSX.Element;
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 i } from "./settings-provider.js";
3
- import { TooltipsProvider as t } from "./tooltips-provider.js";
4
- function p({ children: o }) {
5
- return /* @__PURE__ */ r(i, { children: /* @__PURE__ */ r(t, { children: o }) });
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
- p as DemoKitProvider
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 declare const SettingsProvider: React.FC<{
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 O } from "react/jsx-runtime";
2
- import { useState as v, useEffect as f, useCallback as g, useMemo as E, useContext as y, createContext as w } from "react";
3
- import { APP_SETTINGS as p } from "../config/settings.config.js";
4
- const h = w(
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 P(e, t) {
8
- return t.split(".").reduce((n, s) => n?.[s], e);
8
+ function L(t, e) {
9
+ return e.split(".").reduce((o, a) => o?.[a], t);
9
10
  }
10
- function S(e, t, n) {
11
- const s = t.split("."), i = s.pop(), u = s.reduce((m, r) => m[r] ??= {}, e);
12
- return u[i] = n, { ...e };
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 x(e, t) {
15
+ function A(t, e) {
15
16
  if (c())
16
17
  try {
17
18
  localStorage.setItem(
18
- `${l}${e}`,
19
- JSON.stringify(t)
19
+ `${l}${t}`,
20
+ JSON.stringify(e)
20
21
  );
21
- } catch (n) {
22
- console.error("LocalStorage write error:", n);
22
+ } catch (o) {
23
+ console.error("LocalStorage write error:", o);
23
24
  }
24
25
  }
25
- function C(e) {
26
+ function I(t) {
26
27
  if (c())
27
28
  try {
28
- const t = localStorage.getItem(`${l}${e}`);
29
- return t ? JSON.parse(t) : void 0;
30
- } catch (t) {
31
- console.error("LocalStorage read error:", t);
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
- const T = ({
36
- children: e
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 [t, n] = v(
39
- structuredClone(p)
75
+ const [o, a] = w(
76
+ () => E(e)
40
77
  );
41
- f(() => {
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 = structuredClone(p);
44
- Object.keys(localStorage).filter((o) => o.startsWith(l)).forEach((o) => {
45
- const a = o.replace(l, ""), d = C(a);
46
- d !== void 0 && S(r, a, d);
47
- }), n(r);
48
- }, []), f(() => {
49
- c() && (document.documentElement.dataset.theme = t.theme);
50
- }, [t.theme]), f(() => {
51
- c() && (document.documentElement.dataset.density = t.appearance?.density ?? p.appearance.density, document.documentElement.dataset.radius = t.appearance?.radius ?? p.appearance.radius);
52
- }, [t.appearance?.density, t.appearance?.radius]);
53
- const s = g(
54
- (r) => P(t, r),
55
- [t]
56
- ), i = g((r, o) => {
57
- n((a) => S({ ...a }, r, o));
58
- }, []), u = g((r, o) => {
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
- }, []), m = E(
64
- () => ({ getOption: s, setOption: i, storeOption: u, settings: t }),
65
- [s, i, u, t]
106
+ }, []), f = P(
107
+ () => ({ getOption: u, setOption: d, storeOption: m, settings: o }),
108
+ [u, d, m, o]
66
109
  );
67
- return /* @__PURE__ */ O(h.Provider, { value: m, children: e });
68
- }, $ = () => {
69
- const e = y(h);
70
- if (!e)
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 e;
73
- }, b = () => y(h);
115
+ return t;
116
+ }, j = () => O(g);
74
117
  export {
75
- T as SettingsProvider,
76
- b as useOptionalSettings,
77
- $ as useSettings
118
+ F as SettingsProvider,
119
+ j as useOptionalSettings,
120
+ N as useSettings
78
121
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@demokit-ui/demokit",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Open-source React component library with provider, styles, and composable UI primitives",
5
5
  "license": "MIT",
6
6
  "repository": {