@kopexa/sidebar 17.2.1 → 17.3.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/dist/{chunk-YW3JMPRU.mjs → chunk-5VE25P3M.mjs} +61 -21
- package/dist/{chunk-LCCZNS2E.mjs → chunk-6H2EH7LL.mjs} +3 -3
- package/dist/chunk-BFZFZSUC.mjs +27 -0
- package/dist/{chunk-KLYPP6QE.mjs → chunk-G2J7EJQ6.mjs} +24 -15
- package/dist/{chunk-YVQVW5EP.mjs → chunk-WIP5GNGJ.mjs} +1 -1
- package/dist/{chunk-AIRHHM7Z.mjs → chunk-XBTONQ3L.mjs} +5 -1
- package/dist/index.js +88 -35
- package/dist/index.mjs +6 -6
- package/dist/v2/app-shell.mjs +3 -2
- package/dist/v2/components.d.mts +7 -1
- package/dist/v2/components.d.ts +7 -1
- package/dist/v2/components.js +69 -21
- package/dist/v2/components.mjs +3 -3
- package/dist/v2/context.js +16 -1
- package/dist/v2/context.mjs +2 -1
- package/dist/v2/from-config.js +85 -30
- package/dist/v2/from-config.mjs +4 -4
- package/dist/v2/index.js +88 -35
- package/dist/v2/index.mjs +6 -6
- package/dist/v2/types.d.mts +20 -1
- package/dist/v2/types.d.ts +20 -1
- package/dist/v2/types.js +17 -2
- package/dist/v2/types.mjs +7 -3
- package/package.json +11 -11
- package/dist/chunk-SDMGFB6V.mjs +0 -14
package/dist/v2/components.js
CHANGED
|
@@ -49,14 +49,19 @@ var import_theme = require("@kopexa/theme");
|
|
|
49
49
|
var import_tooltip = require("@kopexa/tooltip");
|
|
50
50
|
var import_use_is_mobile = require("@kopexa/use-is-mobile");
|
|
51
51
|
var import_react = require("react");
|
|
52
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
53
|
-
var PIN_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
|
|
54
|
-
var [Provider, useSidebarV2] = (0, import_react_utils.createContext)({
|
|
55
|
-
name: "SidebarV2Context",
|
|
56
|
-
errorMessage: "useSidebarV2 must be used within <SidebarV2> (the provider component)."
|
|
57
|
-
});
|
|
58
52
|
|
|
59
53
|
// src/v2/types.ts
|
|
54
|
+
function normalizePath(href) {
|
|
55
|
+
const path = href.split("#")[0].split("?")[0].replace(/\/+$/, "");
|
|
56
|
+
return path === "" ? "/" : path;
|
|
57
|
+
}
|
|
58
|
+
function pathMatchLength(currentPath, href) {
|
|
59
|
+
const target = normalizePath(href);
|
|
60
|
+
if (currentPath === target) return target.length;
|
|
61
|
+
if (target !== "/" && currentPath.startsWith(`${target}/`))
|
|
62
|
+
return target.length;
|
|
63
|
+
return -1;
|
|
64
|
+
}
|
|
60
65
|
function panelItemHasChildren(item) {
|
|
61
66
|
return "children" in item && Array.isArray(item.children);
|
|
62
67
|
}
|
|
@@ -64,6 +69,14 @@ function panelItemIsSection(item) {
|
|
|
64
69
|
return "section" in item;
|
|
65
70
|
}
|
|
66
71
|
|
|
72
|
+
// src/v2/context.tsx
|
|
73
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
74
|
+
var PIN_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
|
|
75
|
+
var [Provider, useSidebarV2] = (0, import_react_utils.createContext)({
|
|
76
|
+
name: "SidebarV2Context",
|
|
77
|
+
errorMessage: "useSidebarV2 must be used within <SidebarV2> (the provider component)."
|
|
78
|
+
});
|
|
79
|
+
|
|
67
80
|
// src/v2/components.tsx
|
|
68
81
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
69
82
|
function SidebarV2Inset({
|
|
@@ -269,31 +282,34 @@ function SidebarV2PanelLeaf({
|
|
|
269
282
|
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
270
283
|
Icon && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { className: styles.panelLeafIcon() }),
|
|
271
284
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: styles.panelLeafLabel(), children: item.label }),
|
|
285
|
+
item.tag && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: styles.panelLeafTag(), children: item.tag }),
|
|
272
286
|
item.badge != null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: styles.panelLeafBadge(), children: item.badge })
|
|
273
287
|
] })
|
|
274
288
|
}) });
|
|
275
289
|
}
|
|
276
290
|
function SidebarV2PanelGroup({
|
|
277
|
-
item
|
|
291
|
+
item,
|
|
292
|
+
winningHref
|
|
278
293
|
}) {
|
|
279
294
|
var _a;
|
|
280
295
|
const { openGroup, toggleGroup, activeHref, renderLink, tone, styles } = useSidebarV2();
|
|
281
296
|
const light = tone === "light";
|
|
282
297
|
const Icon = item.icon;
|
|
283
298
|
const key = (_a = item.value) != null ? _a : item.label;
|
|
284
|
-
let
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
299
|
+
let winner = winningHref;
|
|
300
|
+
if (winner === void 0) {
|
|
301
|
+
const current = normalizePath(activeHref);
|
|
302
|
+
let len = -1;
|
|
303
|
+
winner = null;
|
|
304
|
+
for (const c of item.children) {
|
|
305
|
+
const l = pathMatchLength(current, c.href);
|
|
306
|
+
if (l > len) {
|
|
307
|
+
len = l;
|
|
308
|
+
winner = normalizePath(c.href);
|
|
309
|
+
}
|
|
294
310
|
}
|
|
295
311
|
}
|
|
296
|
-
const containsActive =
|
|
312
|
+
const containsActive = winner != null && item.children.some((c) => normalizePath(c.href) === winner);
|
|
297
313
|
const open = openGroup === key || openGroup === null && containsActive;
|
|
298
314
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
|
|
299
315
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
@@ -316,7 +332,7 @@ function SidebarV2PanelGroup({
|
|
|
316
332
|
}
|
|
317
333
|
),
|
|
318
334
|
open && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: styles.panelTree(), children: item.children.map((child) => {
|
|
319
|
-
const active = child.href ===
|
|
335
|
+
const active = normalizePath(child.href) === winner;
|
|
320
336
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: renderLink({
|
|
321
337
|
href: child.href,
|
|
322
338
|
"data-active": active,
|
|
@@ -330,15 +346,47 @@ function SidebarV2PanelGroup({
|
|
|
330
346
|
function SidebarV2PanelItems({
|
|
331
347
|
items
|
|
332
348
|
}) {
|
|
349
|
+
const { activeHref } = useSidebarV2();
|
|
350
|
+
const winningHref = (0, import_react2.useMemo)(() => {
|
|
351
|
+
const current = normalizePath(activeHref);
|
|
352
|
+
let href = null;
|
|
353
|
+
let len = -1;
|
|
354
|
+
for (const item of items) {
|
|
355
|
+
if (panelItemIsSection(item)) continue;
|
|
356
|
+
const hrefs = panelItemHasChildren(item) ? item.children.map((c) => c.href) : [item.href];
|
|
357
|
+
for (const h of hrefs) {
|
|
358
|
+
const l = pathMatchLength(current, h);
|
|
359
|
+
if (l > len) {
|
|
360
|
+
len = l;
|
|
361
|
+
href = normalizePath(h);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return href;
|
|
366
|
+
}, [items, activeHref]);
|
|
333
367
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: items.map((item, idx) => {
|
|
334
368
|
var _a;
|
|
335
369
|
if (panelItemIsSection(item)) {
|
|
336
370
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SidebarV2PanelLabel, { children: item.section }, `section-${item.section}-${idx}`);
|
|
337
371
|
}
|
|
338
372
|
if (panelItemHasChildren(item)) {
|
|
339
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
373
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
374
|
+
SidebarV2PanelGroup,
|
|
375
|
+
{
|
|
376
|
+
item,
|
|
377
|
+
winningHref
|
|
378
|
+
},
|
|
379
|
+
(_a = item.value) != null ? _a : item.label
|
|
380
|
+
);
|
|
340
381
|
}
|
|
341
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
382
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
383
|
+
SidebarV2PanelLeaf,
|
|
384
|
+
{
|
|
385
|
+
item,
|
|
386
|
+
active: winningHref != null && normalizePath(item.href) === winningHref
|
|
387
|
+
},
|
|
388
|
+
item.href
|
|
389
|
+
);
|
|
342
390
|
}) });
|
|
343
391
|
}
|
|
344
392
|
function SidebarV2Trigger({
|
package/dist/v2/components.mjs
CHANGED
|
@@ -13,9 +13,9 @@ import {
|
|
|
13
13
|
SidebarV2RailSpacer,
|
|
14
14
|
SidebarV2Trigger,
|
|
15
15
|
SidebarV2Workspace
|
|
16
|
-
} from "../chunk-
|
|
17
|
-
import "../chunk-
|
|
18
|
-
import "../chunk-
|
|
16
|
+
} from "../chunk-5VE25P3M.mjs";
|
|
17
|
+
import "../chunk-XBTONQ3L.mjs";
|
|
18
|
+
import "../chunk-BFZFZSUC.mjs";
|
|
19
19
|
export {
|
|
20
20
|
SidebarV2Inset,
|
|
21
21
|
SidebarV2Panel,
|
package/dist/v2/context.js
CHANGED
|
@@ -31,6 +31,21 @@ var import_theme = require("@kopexa/theme");
|
|
|
31
31
|
var import_tooltip = require("@kopexa/tooltip");
|
|
32
32
|
var import_use_is_mobile = require("@kopexa/use-is-mobile");
|
|
33
33
|
var import_react = require("react");
|
|
34
|
+
|
|
35
|
+
// src/v2/types.ts
|
|
36
|
+
function normalizePath(href) {
|
|
37
|
+
const path = href.split("#")[0].split("?")[0].replace(/\/+$/, "");
|
|
38
|
+
return path === "" ? "/" : path;
|
|
39
|
+
}
|
|
40
|
+
function pathMatchLength(currentPath, href) {
|
|
41
|
+
const target = normalizePath(href);
|
|
42
|
+
if (currentPath === target) return target.length;
|
|
43
|
+
if (target !== "/" && currentPath.startsWith(`${target}/`))
|
|
44
|
+
return target.length;
|
|
45
|
+
return -1;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/v2/context.tsx
|
|
34
49
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
50
|
var PIN_COOKIE = "kpx_sidebar_v2_pinned";
|
|
36
51
|
var PIN_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
|
|
@@ -97,7 +112,7 @@ function SidebarV2Provider({
|
|
|
97
112
|
setOpenGroup((curr) => curr === key ? null : key);
|
|
98
113
|
}, []);
|
|
99
114
|
const isActive = (0, import_react.useCallback)(
|
|
100
|
-
(href) => activeHref
|
|
115
|
+
(href) => pathMatchLength(normalizePath(activeHref), href) >= 0,
|
|
101
116
|
[activeHref]
|
|
102
117
|
);
|
|
103
118
|
const value = (0, import_react.useMemo)(
|
package/dist/v2/context.mjs
CHANGED
package/dist/v2/from-config.js
CHANGED
|
@@ -44,14 +44,19 @@ var import_theme = require("@kopexa/theme");
|
|
|
44
44
|
var import_tooltip = require("@kopexa/tooltip");
|
|
45
45
|
var import_use_is_mobile = require("@kopexa/use-is-mobile");
|
|
46
46
|
var import_react = require("react");
|
|
47
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
48
|
-
var PIN_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
|
|
49
|
-
var [Provider, useSidebarV2] = (0, import_react_utils.createContext)({
|
|
50
|
-
name: "SidebarV2Context",
|
|
51
|
-
errorMessage: "useSidebarV2 must be used within <SidebarV2> (the provider component)."
|
|
52
|
-
});
|
|
53
47
|
|
|
54
48
|
// src/v2/types.ts
|
|
49
|
+
function normalizePath(href) {
|
|
50
|
+
const path = href.split("#")[0].split("?")[0].replace(/\/+$/, "");
|
|
51
|
+
return path === "" ? "/" : path;
|
|
52
|
+
}
|
|
53
|
+
function pathMatchLength(currentPath, href) {
|
|
54
|
+
const target = normalizePath(href);
|
|
55
|
+
if (currentPath === target) return target.length;
|
|
56
|
+
if (target !== "/" && currentPath.startsWith(`${target}/`))
|
|
57
|
+
return target.length;
|
|
58
|
+
return -1;
|
|
59
|
+
}
|
|
55
60
|
function panelItemHasChildren(item) {
|
|
56
61
|
return "children" in item && Array.isArray(item.children);
|
|
57
62
|
}
|
|
@@ -59,6 +64,14 @@ function panelItemIsSection(item) {
|
|
|
59
64
|
return "section" in item;
|
|
60
65
|
}
|
|
61
66
|
|
|
67
|
+
// src/v2/context.tsx
|
|
68
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
69
|
+
var PIN_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
|
|
70
|
+
var [Provider, useSidebarV2] = (0, import_react_utils.createContext)({
|
|
71
|
+
name: "SidebarV2Context",
|
|
72
|
+
errorMessage: "useSidebarV2 must be used within <SidebarV2> (the provider component)."
|
|
73
|
+
});
|
|
74
|
+
|
|
62
75
|
// src/v2/components.tsx
|
|
63
76
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
64
77
|
function SidebarV2Rail({ className, ...props }) {
|
|
@@ -247,31 +260,34 @@ function SidebarV2PanelLeaf({
|
|
|
247
260
|
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
248
261
|
Icon && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { className: styles.panelLeafIcon() }),
|
|
249
262
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: styles.panelLeafLabel(), children: item.label }),
|
|
263
|
+
item.tag && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: styles.panelLeafTag(), children: item.tag }),
|
|
250
264
|
item.badge != null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: styles.panelLeafBadge(), children: item.badge })
|
|
251
265
|
] })
|
|
252
266
|
}) });
|
|
253
267
|
}
|
|
254
268
|
function SidebarV2PanelGroup({
|
|
255
|
-
item
|
|
269
|
+
item,
|
|
270
|
+
winningHref
|
|
256
271
|
}) {
|
|
257
272
|
var _a;
|
|
258
273
|
const { openGroup, toggleGroup, activeHref, renderLink, tone, styles } = useSidebarV2();
|
|
259
274
|
const light = tone === "light";
|
|
260
275
|
const Icon = item.icon;
|
|
261
276
|
const key = (_a = item.value) != null ? _a : item.label;
|
|
262
|
-
let
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
277
|
+
let winner = winningHref;
|
|
278
|
+
if (winner === void 0) {
|
|
279
|
+
const current = normalizePath(activeHref);
|
|
280
|
+
let len = -1;
|
|
281
|
+
winner = null;
|
|
282
|
+
for (const c of item.children) {
|
|
283
|
+
const l = pathMatchLength(current, c.href);
|
|
284
|
+
if (l > len) {
|
|
285
|
+
len = l;
|
|
286
|
+
winner = normalizePath(c.href);
|
|
287
|
+
}
|
|
272
288
|
}
|
|
273
289
|
}
|
|
274
|
-
const containsActive =
|
|
290
|
+
const containsActive = winner != null && item.children.some((c) => normalizePath(c.href) === winner);
|
|
275
291
|
const open = openGroup === key || openGroup === null && containsActive;
|
|
276
292
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
|
|
277
293
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
@@ -294,7 +310,7 @@ function SidebarV2PanelGroup({
|
|
|
294
310
|
}
|
|
295
311
|
),
|
|
296
312
|
open && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: styles.panelTree(), children: item.children.map((child) => {
|
|
297
|
-
const active = child.href ===
|
|
313
|
+
const active = normalizePath(child.href) === winner;
|
|
298
314
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: renderLink({
|
|
299
315
|
href: child.href,
|
|
300
316
|
"data-active": active,
|
|
@@ -308,15 +324,47 @@ function SidebarV2PanelGroup({
|
|
|
308
324
|
function SidebarV2PanelItems({
|
|
309
325
|
items
|
|
310
326
|
}) {
|
|
327
|
+
const { activeHref } = useSidebarV2();
|
|
328
|
+
const winningHref = (0, import_react2.useMemo)(() => {
|
|
329
|
+
const current = normalizePath(activeHref);
|
|
330
|
+
let href = null;
|
|
331
|
+
let len = -1;
|
|
332
|
+
for (const item of items) {
|
|
333
|
+
if (panelItemIsSection(item)) continue;
|
|
334
|
+
const hrefs = panelItemHasChildren(item) ? item.children.map((c) => c.href) : [item.href];
|
|
335
|
+
for (const h of hrefs) {
|
|
336
|
+
const l = pathMatchLength(current, h);
|
|
337
|
+
if (l > len) {
|
|
338
|
+
len = l;
|
|
339
|
+
href = normalizePath(h);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return href;
|
|
344
|
+
}, [items, activeHref]);
|
|
311
345
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: items.map((item, idx) => {
|
|
312
346
|
var _a;
|
|
313
347
|
if (panelItemIsSection(item)) {
|
|
314
348
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SidebarV2PanelLabel, { children: item.section }, `section-${item.section}-${idx}`);
|
|
315
349
|
}
|
|
316
350
|
if (panelItemHasChildren(item)) {
|
|
317
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
351
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
352
|
+
SidebarV2PanelGroup,
|
|
353
|
+
{
|
|
354
|
+
item,
|
|
355
|
+
winningHref
|
|
356
|
+
},
|
|
357
|
+
(_a = item.value) != null ? _a : item.label
|
|
358
|
+
);
|
|
318
359
|
}
|
|
319
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
360
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
361
|
+
SidebarV2PanelLeaf,
|
|
362
|
+
{
|
|
363
|
+
item,
|
|
364
|
+
active: winningHref != null && normalizePath(item.href) === winningHref
|
|
365
|
+
},
|
|
366
|
+
item.href
|
|
367
|
+
);
|
|
320
368
|
}) });
|
|
321
369
|
}
|
|
322
370
|
|
|
@@ -347,7 +395,7 @@ function SidebarV2FromConfig({
|
|
|
347
395
|
closeFlyout,
|
|
348
396
|
selectedRail,
|
|
349
397
|
setSelectedRail,
|
|
350
|
-
|
|
398
|
+
activeHref,
|
|
351
399
|
isMobile,
|
|
352
400
|
drawerOpen,
|
|
353
401
|
setDrawerOpen,
|
|
@@ -393,14 +441,21 @@ function SidebarV2FromConfig({
|
|
|
393
441
|
[items]
|
|
394
442
|
);
|
|
395
443
|
const activeRailValue = (0, import_react4.useMemo)(() => {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
444
|
+
var _a2, _b2;
|
|
445
|
+
const current = normalizePath(activeHref);
|
|
446
|
+
let best = null;
|
|
447
|
+
for (const p of panels) {
|
|
448
|
+
for (const item of p.items) {
|
|
449
|
+
if (panelItemIsSection(item)) continue;
|
|
450
|
+
const hrefs = panelItemHasChildren(item) ? item.children.map((c) => c.href) : [item.href];
|
|
451
|
+
for (const href of hrefs) {
|
|
452
|
+
const len = pathMatchLength(current, href);
|
|
453
|
+
if (len > ((_a2 = best == null ? void 0 : best.len) != null ? _a2 : -1)) best = { value: entryValue(p), len };
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return (_b2 = best == null ? void 0 : best.value) != null ? _b2 : null;
|
|
458
|
+
}, [panels, activeHref]);
|
|
404
459
|
const shownValue = pinned ? selectedRail != null ? selectedRail : activeRailValue : flyoutValue;
|
|
405
460
|
const shownPanel = (_a = panels.find((p) => entryValue(p) === shownValue)) != null ? _a : null;
|
|
406
461
|
const topEntries = items.filter((e) => e.slot !== "bottom");
|
package/dist/v2/from-config.mjs
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"use client";
|
|
3
3
|
import {
|
|
4
4
|
SidebarV2FromConfig
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
5
|
+
} from "../chunk-G2J7EJQ6.mjs";
|
|
6
|
+
import "../chunk-5VE25P3M.mjs";
|
|
7
|
+
import "../chunk-XBTONQ3L.mjs";
|
|
8
|
+
import "../chunk-BFZFZSUC.mjs";
|
|
9
9
|
export {
|
|
10
10
|
SidebarV2FromConfig
|
|
11
11
|
};
|
package/dist/v2/index.js
CHANGED
|
@@ -57,6 +57,27 @@ var import_theme = require("@kopexa/theme");
|
|
|
57
57
|
var import_tooltip = require("@kopexa/tooltip");
|
|
58
58
|
var import_use_is_mobile = require("@kopexa/use-is-mobile");
|
|
59
59
|
var import_react = require("react");
|
|
60
|
+
|
|
61
|
+
// src/v2/types.ts
|
|
62
|
+
function normalizePath(href) {
|
|
63
|
+
const path = href.split("#")[0].split("?")[0].replace(/\/+$/, "");
|
|
64
|
+
return path === "" ? "/" : path;
|
|
65
|
+
}
|
|
66
|
+
function pathMatchLength(currentPath, href) {
|
|
67
|
+
const target = normalizePath(href);
|
|
68
|
+
if (currentPath === target) return target.length;
|
|
69
|
+
if (target !== "/" && currentPath.startsWith(`${target}/`))
|
|
70
|
+
return target.length;
|
|
71
|
+
return -1;
|
|
72
|
+
}
|
|
73
|
+
function panelItemHasChildren(item) {
|
|
74
|
+
return "children" in item && Array.isArray(item.children);
|
|
75
|
+
}
|
|
76
|
+
function panelItemIsSection(item) {
|
|
77
|
+
return "section" in item;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/v2/context.tsx
|
|
60
81
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
61
82
|
var PIN_COOKIE = "kpx_sidebar_v2_pinned";
|
|
62
83
|
var PIN_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
|
|
@@ -123,7 +144,7 @@ function SidebarV2Provider({
|
|
|
123
144
|
setOpenGroup((curr) => curr === key ? null : key);
|
|
124
145
|
}, []);
|
|
125
146
|
const isActive = (0, import_react.useCallback)(
|
|
126
|
-
(href) => activeHref
|
|
147
|
+
(href) => pathMatchLength(normalizePath(activeHref), href) >= 0,
|
|
127
148
|
[activeHref]
|
|
128
149
|
);
|
|
129
150
|
const value = (0, import_react.useMemo)(
|
|
@@ -284,16 +305,6 @@ var import_shared_utils = require("@kopexa/shared-utils");
|
|
|
284
305
|
var import_theme2 = require("@kopexa/theme");
|
|
285
306
|
var import_tooltip2 = require("@kopexa/tooltip");
|
|
286
307
|
var import_react3 = require("react");
|
|
287
|
-
|
|
288
|
-
// src/v2/types.ts
|
|
289
|
-
function panelItemHasChildren(item) {
|
|
290
|
-
return "children" in item && Array.isArray(item.children);
|
|
291
|
-
}
|
|
292
|
-
function panelItemIsSection(item) {
|
|
293
|
-
return "section" in item;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// src/v2/components.tsx
|
|
297
308
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
298
309
|
function SidebarV2Inset({
|
|
299
310
|
className,
|
|
@@ -498,31 +509,34 @@ function SidebarV2PanelLeaf({
|
|
|
498
509
|
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
499
510
|
Icon && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon, { className: styles.panelLeafIcon() }),
|
|
500
511
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: styles.panelLeafLabel(), children: item.label }),
|
|
512
|
+
item.tag && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: styles.panelLeafTag(), children: item.tag }),
|
|
501
513
|
item.badge != null && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: styles.panelLeafBadge(), children: item.badge })
|
|
502
514
|
] })
|
|
503
515
|
}) });
|
|
504
516
|
}
|
|
505
517
|
function SidebarV2PanelGroup({
|
|
506
|
-
item
|
|
518
|
+
item,
|
|
519
|
+
winningHref
|
|
507
520
|
}) {
|
|
508
521
|
var _a;
|
|
509
522
|
const { openGroup, toggleGroup, activeHref, renderLink, tone, styles } = useSidebarV2();
|
|
510
523
|
const light = tone === "light";
|
|
511
524
|
const Icon = item.icon;
|
|
512
525
|
const key = (_a = item.value) != null ? _a : item.label;
|
|
513
|
-
let
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
526
|
+
let winner = winningHref;
|
|
527
|
+
if (winner === void 0) {
|
|
528
|
+
const current = normalizePath(activeHref);
|
|
529
|
+
let len = -1;
|
|
530
|
+
winner = null;
|
|
531
|
+
for (const c of item.children) {
|
|
532
|
+
const l = pathMatchLength(current, c.href);
|
|
533
|
+
if (l > len) {
|
|
534
|
+
len = l;
|
|
535
|
+
winner = normalizePath(c.href);
|
|
536
|
+
}
|
|
523
537
|
}
|
|
524
538
|
}
|
|
525
|
-
const containsActive =
|
|
539
|
+
const containsActive = winner != null && item.children.some((c) => normalizePath(c.href) === winner);
|
|
526
540
|
const open = openGroup === key || openGroup === null && containsActive;
|
|
527
541
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { children: [
|
|
528
542
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
@@ -545,7 +559,7 @@ function SidebarV2PanelGroup({
|
|
|
545
559
|
}
|
|
546
560
|
),
|
|
547
561
|
open && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: styles.panelTree(), children: item.children.map((child) => {
|
|
548
|
-
const active = child.href ===
|
|
562
|
+
const active = normalizePath(child.href) === winner;
|
|
549
563
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: renderLink({
|
|
550
564
|
href: child.href,
|
|
551
565
|
"data-active": active,
|
|
@@ -559,15 +573,47 @@ function SidebarV2PanelGroup({
|
|
|
559
573
|
function SidebarV2PanelItems({
|
|
560
574
|
items
|
|
561
575
|
}) {
|
|
576
|
+
const { activeHref } = useSidebarV2();
|
|
577
|
+
const winningHref = (0, import_react3.useMemo)(() => {
|
|
578
|
+
const current = normalizePath(activeHref);
|
|
579
|
+
let href = null;
|
|
580
|
+
let len = -1;
|
|
581
|
+
for (const item of items) {
|
|
582
|
+
if (panelItemIsSection(item)) continue;
|
|
583
|
+
const hrefs = panelItemHasChildren(item) ? item.children.map((c) => c.href) : [item.href];
|
|
584
|
+
for (const h of hrefs) {
|
|
585
|
+
const l = pathMatchLength(current, h);
|
|
586
|
+
if (l > len) {
|
|
587
|
+
len = l;
|
|
588
|
+
href = normalizePath(h);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
return href;
|
|
593
|
+
}, [items, activeHref]);
|
|
562
594
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children: items.map((item, idx) => {
|
|
563
595
|
var _a;
|
|
564
596
|
if (panelItemIsSection(item)) {
|
|
565
597
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SidebarV2PanelLabel, { children: item.section }, `section-${item.section}-${idx}`);
|
|
566
598
|
}
|
|
567
599
|
if (panelItemHasChildren(item)) {
|
|
568
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
600
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
601
|
+
SidebarV2PanelGroup,
|
|
602
|
+
{
|
|
603
|
+
item,
|
|
604
|
+
winningHref
|
|
605
|
+
},
|
|
606
|
+
(_a = item.value) != null ? _a : item.label
|
|
607
|
+
);
|
|
569
608
|
}
|
|
570
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
609
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
610
|
+
SidebarV2PanelLeaf,
|
|
611
|
+
{
|
|
612
|
+
item,
|
|
613
|
+
active: winningHref != null && normalizePath(item.href) === winningHref
|
|
614
|
+
},
|
|
615
|
+
item.href
|
|
616
|
+
);
|
|
571
617
|
}) });
|
|
572
618
|
}
|
|
573
619
|
function SidebarV2Trigger({
|
|
@@ -620,7 +666,7 @@ function SidebarV2FromConfig({
|
|
|
620
666
|
closeFlyout,
|
|
621
667
|
selectedRail,
|
|
622
668
|
setSelectedRail,
|
|
623
|
-
|
|
669
|
+
activeHref,
|
|
624
670
|
isMobile,
|
|
625
671
|
drawerOpen,
|
|
626
672
|
setDrawerOpen,
|
|
@@ -666,14 +712,21 @@ function SidebarV2FromConfig({
|
|
|
666
712
|
[items]
|
|
667
713
|
);
|
|
668
714
|
const activeRailValue = (0, import_react5.useMemo)(() => {
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
715
|
+
var _a2, _b2;
|
|
716
|
+
const current = normalizePath(activeHref);
|
|
717
|
+
let best = null;
|
|
718
|
+
for (const p of panels) {
|
|
719
|
+
for (const item of p.items) {
|
|
720
|
+
if (panelItemIsSection(item)) continue;
|
|
721
|
+
const hrefs = panelItemHasChildren(item) ? item.children.map((c) => c.href) : [item.href];
|
|
722
|
+
for (const href of hrefs) {
|
|
723
|
+
const len = pathMatchLength(current, href);
|
|
724
|
+
if (len > ((_a2 = best == null ? void 0 : best.len) != null ? _a2 : -1)) best = { value: entryValue(p), len };
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
return (_b2 = best == null ? void 0 : best.value) != null ? _b2 : null;
|
|
729
|
+
}, [panels, activeHref]);
|
|
677
730
|
const shownValue = pinned ? selectedRail != null ? selectedRail : activeRailValue : flyoutValue;
|
|
678
731
|
const shownPanel = (_a = panels.find((p) => entryValue(p) === shownValue)) != null ? _a : null;
|
|
679
732
|
const topEntries = items.filter((e) => e.slot !== "bottom");
|
package/dist/v2/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"use client";
|
|
3
3
|
import {
|
|
4
4
|
SidebarV2
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-6H2EH7LL.mjs";
|
|
6
6
|
import {
|
|
7
7
|
AppShell,
|
|
8
8
|
AppShellAside,
|
|
@@ -10,10 +10,10 @@ import {
|
|
|
10
10
|
AppShellMain,
|
|
11
11
|
AppShellPanelContent,
|
|
12
12
|
AppShellRoot
|
|
13
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-WIP5GNGJ.mjs";
|
|
14
14
|
import {
|
|
15
15
|
SidebarV2FromConfig
|
|
16
|
-
} from "../chunk-
|
|
16
|
+
} from "../chunk-G2J7EJQ6.mjs";
|
|
17
17
|
import {
|
|
18
18
|
SidebarV2Inset,
|
|
19
19
|
SidebarV2Panel,
|
|
@@ -27,12 +27,12 @@ import {
|
|
|
27
27
|
SidebarV2RailSpacer,
|
|
28
28
|
SidebarV2Trigger,
|
|
29
29
|
SidebarV2Workspace
|
|
30
|
-
} from "../chunk-
|
|
31
|
-
import "../chunk-SDMGFB6V.mjs";
|
|
30
|
+
} from "../chunk-5VE25P3M.mjs";
|
|
32
31
|
import {
|
|
33
32
|
SidebarV2Provider,
|
|
34
33
|
useSidebarV2
|
|
35
|
-
} from "../chunk-
|
|
34
|
+
} from "../chunk-XBTONQ3L.mjs";
|
|
35
|
+
import "../chunk-BFZFZSUC.mjs";
|
|
36
36
|
export {
|
|
37
37
|
AppShell,
|
|
38
38
|
AppShellAside,
|