@zccz14/ux 0.1.3 → 0.1.5

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/index.js CHANGED
@@ -1,23 +1,23 @@
1
- import { jsxs as s, jsx as e, Fragment as _ } from "react/jsx-runtime";
2
- import { useState as f, useCallback as g, useEffect as y, useSyncExternalStore as w } from "react";
3
- import { Dialog as h } from "@base-ui/react/dialog";
4
- import { Tooltip as p } from "@base-ui/react/tooltip";
5
- import { useLinkit as v, LinkitMyInfo as M } from "linkit-react-components";
6
- import { useLocation as L, NavLink as S } from "react-router-dom";
7
- const C = {
1
+ import { jsxs as l, jsx as e, Fragment as w } from "react/jsx-runtime";
2
+ import { useState as g, useCallback as x, useEffect as M, useSyncExternalStore as L } from "react";
3
+ import { Dialog as m } from "@base-ui/react/dialog";
4
+ import { Tooltip as h } from "@base-ui/react/tooltip";
5
+ import { useLinkit as N, LinkitMyInfo as S } from "linkit-react-components";
6
+ import { useLocation as k, NavLink as C } from "react-router-dom";
7
+ const O = {
8
8
  closeNavigation: "Close navigation",
9
9
  navigation: "Navigation",
10
10
  toggleSidebar: "Toggle sidebar"
11
- }, O = {
11
+ }, P = {
12
12
  closeNavigation: "关闭导航",
13
13
  navigation: "导航",
14
14
  toggleSidebar: "切换侧边栏"
15
15
  };
16
- function P(n) {
17
- return n.toLowerCase().startsWith("zh") ? O : C;
16
+ function I(a) {
17
+ return a.toLowerCase().startsWith("zh") ? P : O;
18
18
  }
19
19
  function T() {
20
- return /* @__PURE__ */ s(
20
+ return /* @__PURE__ */ l(
21
21
  "svg",
22
22
  {
23
23
  "aria-hidden": "true",
@@ -35,7 +35,7 @@ function T() {
35
35
  );
36
36
  }
37
37
  function E() {
38
- return /* @__PURE__ */ s(
38
+ return /* @__PURE__ */ l(
39
39
  "svg",
40
40
  {
41
41
  "aria-hidden": "true",
@@ -52,164 +52,171 @@ function E() {
52
52
  }
53
53
  );
54
54
  }
55
- const m = "sidebar_state", I = 3600 * 24 * 7, N = "(max-width: 767px)";
56
- function W() {
57
- const n = document.cookie.split("; ").find((a) => a.startsWith(`${m}=`));
58
- return n ? n.slice(m.length + 1) !== "false" : !0;
55
+ const b = "sidebar_state", W = 3600 * 24 * 7, _ = "(max-width: 767px)";
56
+ function $() {
57
+ const a = document.cookie.split("; ").find((n) => n.startsWith(`${b}=`));
58
+ return a ? a.slice(b.length + 1) !== "false" : !0;
59
59
  }
60
- function $(n) {
61
- document.cookie = `${m}=${n}; path=/; max-age=${I}`;
60
+ function j(a) {
61
+ document.cookie = `${b}=${a}; path=/; max-age=${W}`;
62
62
  }
63
- function j(n) {
64
- const a = window.matchMedia(N);
65
- return a.addEventListener("change", n), () => a.removeEventListener("change", n);
63
+ function B(a) {
64
+ const n = window.matchMedia(_);
65
+ return n.addEventListener("change", a), () => n.removeEventListener("change", a);
66
66
  }
67
- function B() {
68
- return w(
69
- j,
70
- () => window.matchMedia(N).matches,
67
+ function A() {
68
+ return L(
69
+ B,
70
+ () => window.matchMedia(_).matches,
71
71
  () => !1
72
72
  );
73
73
  }
74
- function A() {
75
- const n = B(), [a, t] = f(W), [c, r] = f(!1), d = g((i) => {
76
- t(i), $(i);
77
- }, []), u = g(() => {
78
- if (n) {
79
- r((i) => !i);
74
+ function D() {
75
+ const a = A(), [n, t] = g($), [c, i] = g(!1), d = x((r) => {
76
+ t(r), j(r);
77
+ }, []), u = x(() => {
78
+ if (a) {
79
+ i((r) => !r);
80
80
  return;
81
81
  }
82
- d(!a);
83
- }, [n, a, d]);
84
- return y(() => {
85
- function i(o) {
86
- (o.metaKey || o.ctrlKey) && o.key === "b" && (o.preventDefault(), u());
82
+ d(!n);
83
+ }, [a, n, d]);
84
+ return M(() => {
85
+ function r(s) {
86
+ (s.metaKey || s.ctrlKey) && s.key === "b" && (s.preventDefault(), u());
87
87
  }
88
- return window.addEventListener("keydown", i), () => window.removeEventListener("keydown", i);
89
- }, [u]), { isMobile: n, open: a, openMobile: c, setOpenMobile: r, toggleSidebar: u };
88
+ return window.addEventListener("keydown", r), () => window.removeEventListener("keydown", r);
89
+ }, [u]), { isMobile: a, open: n, openMobile: c, setOpenMobile: i, toggleSidebar: u };
90
90
  }
91
- function D(n, a) {
91
+ function y(a, n) {
92
92
  let t;
93
- for (const c of n)
94
- for (const r of c.items)
95
- (r.to === "/" ? a === "/" : a === r.to || a.startsWith(`${r.to}/`)) && (!t || r.to.length > t.to.length) && (t = r);
93
+ for (const c of a)
94
+ for (const i of c.items)
95
+ (i.to === "/" ? n === "/" : n === i.to || n.startsWith(`${i.to}/`)) && (!t || i.to.length > t.to.length) && (t = i);
96
96
  return t;
97
97
  }
98
98
  function K({
99
- collapsed: n,
100
- item: a,
101
- onNavigate: t
99
+ collapsed: a,
100
+ end: n,
101
+ item: t,
102
+ onNavigate: c
102
103
  }) {
103
- return /* @__PURE__ */ s(p.Root, { children: [
104
- /* @__PURE__ */ s(
105
- p.Trigger,
104
+ return /* @__PURE__ */ l(h.Root, { children: [
105
+ /* @__PURE__ */ l(
106
+ h.Trigger,
106
107
  {
107
108
  render: /* @__PURE__ */ e(
108
- S,
109
+ C,
109
110
  {
110
111
  className: "ux-nav-item",
111
- end: a.to === "/",
112
- onClick: t,
113
- to: a.to
112
+ end: n,
113
+ onClick: c,
114
+ to: t.to
114
115
  }
115
116
  ),
116
117
  children: [
117
- /* @__PURE__ */ e("span", { className: "ux-nav-item__icon", children: a.icon }),
118
- /* @__PURE__ */ e("span", { className: "ux-nav-item__text", children: a.label })
118
+ /* @__PURE__ */ e("span", { className: "ux-nav-item__icon", children: t.icon }),
119
+ /* @__PURE__ */ e("span", { className: "ux-nav-item__text", children: t.label })
119
120
  ]
120
121
  }
121
122
  ),
122
- /* @__PURE__ */ e(p.Portal, { children: /* @__PURE__ */ e(
123
- p.Positioner,
123
+ /* @__PURE__ */ e(h.Portal, { children: /* @__PURE__ */ e(
124
+ h.Positioner,
124
125
  {
125
126
  className: "ux-tooltip-positioner",
126
127
  side: "right",
127
128
  sideOffset: 6,
128
- children: /* @__PURE__ */ e(p.Popup, { className: "ux-tooltip", hidden: !n, children: a.label })
129
+ children: /* @__PURE__ */ e(h.Popup, { className: "ux-tooltip", hidden: !a, children: t.label })
129
130
  }
130
131
  ) })
131
132
  ] });
132
133
  }
133
- function x({
134
- copy: n,
135
- logo: a,
134
+ function v({
135
+ copy: a,
136
+ logo: n,
136
137
  nav: t,
137
138
  onNavigate: c,
138
- state: r,
139
+ state: i,
139
140
  title: d
140
141
  }) {
141
- const { resolvedTheme: u } = v();
142
- return /* @__PURE__ */ s(_, { children: [
143
- /* @__PURE__ */ s("div", { className: "ux-sidebar__header", children: [
144
- /* @__PURE__ */ e("span", { className: "ux-sidebar__logo", children: u === "dark" ? a.dark : a.light }),
142
+ const { resolvedTheme: u } = N(), { pathname: r } = k(), s = y(t, r);
143
+ return /* @__PURE__ */ l(w, { children: [
144
+ /* @__PURE__ */ l("div", { className: "ux-sidebar__header", children: [
145
+ /* @__PURE__ */ e("span", { className: "ux-sidebar__logo", children: u === "dark" ? n.dark : n.light }),
145
146
  /* @__PURE__ */ e("span", { className: "ux-sidebar__title", children: d })
146
147
  ] }),
147
- /* @__PURE__ */ e("nav", { "aria-label": n.navigation, className: "ux-sidebar__nav", children: t.map((i) => /* @__PURE__ */ s("div", { className: "ux-nav-group", children: [
148
- /* @__PURE__ */ e("div", { className: "ux-nav-group__label", children: i.label }),
149
- i.items.map((o) => /* @__PURE__ */ e(
150
- K,
151
- {
152
- collapsed: r === "collapsed",
153
- item: o,
154
- onNavigate: c
155
- },
156
- o.to
148
+ /* @__PURE__ */ e("nav", { "aria-label": a.navigation, className: "ux-sidebar__nav", children: t.map((o) => /* @__PURE__ */ l("div", { className: "ux-nav-group", children: [
149
+ /* @__PURE__ */ e("div", { className: "ux-nav-group__label", children: o.label }),
150
+ o.items.map((p) => (
151
+ // NavLink would mark a parent section current on its children's
152
+ // routes; follow matchActiveItem instead so only the deepest
153
+ // match (or the exact path) stays marked.
154
+ /* @__PURE__ */ e(
155
+ K,
156
+ {
157
+ collapsed: i === "collapsed",
158
+ end: p !== s || p.to === r,
159
+ item: p,
160
+ onNavigate: c
161
+ },
162
+ p.to
163
+ )
157
164
  ))
158
- ] }, i.label)) })
165
+ ] }, o.label)) })
159
166
  ] });
160
167
  }
161
168
  function H({
162
- children: n,
163
- headerSlot: a,
169
+ children: a,
170
+ headerSlot: n,
164
171
  logo: t,
165
172
  nav: c,
166
- pageTitle: r,
173
+ pageTitle: i,
167
174
  title: d
168
175
  }) {
169
- var b;
170
- const { pathname: u } = L(), { lang: i } = v(), o = P(i), l = A(), k = r ?? ((b = D(c, u)) == null ? void 0 : b.label);
171
- return /* @__PURE__ */ e(p.Provider, { delay: 0, children: /* @__PURE__ */ s(
176
+ var f;
177
+ const { pathname: u } = k(), { lang: r } = N(), s = I(r), o = D(), p = i ?? ((f = y(c, u)) == null ? void 0 : f.label);
178
+ return /* @__PURE__ */ e(h.Provider, { delay: 0, children: /* @__PURE__ */ l(
172
179
  "div",
173
180
  {
174
181
  className: "ux-app-layout",
175
- "data-state": l.open ? "expanded" : "collapsed",
182
+ "data-state": o.open ? "expanded" : "collapsed",
176
183
  children: [
177
184
  /* @__PURE__ */ e("aside", { className: "ux-sidebar", children: /* @__PURE__ */ e(
178
- x,
185
+ v,
179
186
  {
180
- copy: o,
187
+ copy: s,
181
188
  logo: t,
182
189
  nav: c,
183
- state: l.open ? "expanded" : "collapsed",
190
+ state: o.open ? "expanded" : "collapsed",
184
191
  title: d
185
192
  }
186
193
  ) }),
187
- l.isMobile ? /* @__PURE__ */ e(
188
- h.Root,
194
+ o.isMobile ? /* @__PURE__ */ e(
195
+ m.Root,
189
196
  {
190
- open: l.openMobile,
191
- onOpenChange: l.setOpenMobile,
192
- children: /* @__PURE__ */ s(h.Portal, { children: [
193
- /* @__PURE__ */ e(h.Backdrop, { className: "ux-drawer-backdrop" }),
194
- /* @__PURE__ */ s(h.Popup, { className: "ux-drawer", children: [
195
- /* @__PURE__ */ e(h.Title, { className: "ux-visually-hidden", children: o.navigation }),
197
+ open: o.openMobile,
198
+ onOpenChange: o.setOpenMobile,
199
+ children: /* @__PURE__ */ l(m.Portal, { children: [
200
+ /* @__PURE__ */ e(m.Backdrop, { className: "ux-drawer-backdrop" }),
201
+ /* @__PURE__ */ l(m.Popup, { className: "ux-drawer", children: [
202
+ /* @__PURE__ */ e(m.Title, { className: "ux-visually-hidden", children: s.navigation }),
196
203
  /* @__PURE__ */ e(
197
204
  "button",
198
205
  {
199
- "aria-label": o.closeNavigation,
206
+ "aria-label": s.closeNavigation,
200
207
  className: "ux-drawer__close",
201
208
  type: "button",
202
- onClick: () => l.setOpenMobile(!1),
209
+ onClick: () => o.setOpenMobile(!1),
203
210
  children: /* @__PURE__ */ e(T, {})
204
211
  }
205
212
  ),
206
213
  /* @__PURE__ */ e(
207
- x,
214
+ v,
208
215
  {
209
- copy: o,
216
+ copy: s,
210
217
  logo: t,
211
218
  nav: c,
212
- onNavigate: () => l.setOpenMobile(!1),
219
+ onNavigate: () => o.setOpenMobile(!1),
213
220
  state: "expanded",
214
221
  title: d
215
222
  }
@@ -218,25 +225,25 @@ function H({
218
225
  ] })
219
226
  }
220
227
  ) : null,
221
- /* @__PURE__ */ s("div", { className: "ux-shell", children: [
222
- /* @__PURE__ */ s("header", { className: "ux-app-header", children: [
228
+ /* @__PURE__ */ l("div", { className: "ux-shell", children: [
229
+ /* @__PURE__ */ l("header", { className: "ux-app-header", children: [
223
230
  /* @__PURE__ */ e(
224
231
  "button",
225
232
  {
226
- "aria-expanded": l.isMobile ? l.openMobile : l.open,
227
- "aria-label": o.toggleSidebar,
233
+ "aria-expanded": o.isMobile ? o.openMobile : o.open,
234
+ "aria-label": s.toggleSidebar,
228
235
  className: "ux-app-header__trigger",
229
236
  type: "button",
230
- onClick: l.toggleSidebar,
237
+ onClick: o.toggleSidebar,
231
238
  children: /* @__PURE__ */ e(E, {})
232
239
  }
233
240
  ),
234
241
  /* @__PURE__ */ e("span", { "aria-hidden": "true", className: "ux-app-header__separator" }),
235
- /* @__PURE__ */ e("p", { className: "ux-app-header__title", children: k }),
236
- /* @__PURE__ */ e("div", { className: "ux-app-header__slot", children: a }),
237
- /* @__PURE__ */ e(M, {})
242
+ /* @__PURE__ */ e("p", { className: "ux-app-header__title", children: p }),
243
+ /* @__PURE__ */ e("div", { className: "ux-app-header__slot", children: n }),
244
+ /* @__PURE__ */ e(S, {})
238
245
  ] }),
239
- /* @__PURE__ */ e("main", { className: "ux-main", children: n })
246
+ /* @__PURE__ */ e("main", { className: "ux-main", children: a })
240
247
  ] })
241
248
  ]
242
249
  }
package/dist/styles.css CHANGED
@@ -178,6 +178,7 @@
178
178
  }
179
179
 
180
180
  .ux-app-layout[data-state="collapsed"] .ux-nav-item__text {
181
+ width: 0;
181
182
  opacity: 0;
182
183
  }
183
184
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zccz14/ux",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Unified AppLayout shell for the NTNL app family: one animated icon sidebar, a fixed-size dark/light logo, and the Linkit-integrated AppHeader.",
5
5
  "license": "MIT",
6
6
  "repository": {