@xyd-js/framework 0.1.0-xyd.11 → 0.1.0-xyd.12
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/hydration.d.mts +11 -0
- package/dist/hydration.d.ts +11 -0
- package/dist/hydration.js +271 -0
- package/dist/hydration.js.map +1 -0
- package/dist/hydration.mjs +245 -0
- package/dist/hydration.mjs.map +1 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -0
- package/dist/react.d.mts +32 -0
- package/dist/react.d.ts +32 -0
- package/dist/react.js +694 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +651 -0
- package/dist/react.mjs.map +1 -0
- package/dist/sidebar-Dwf54qYp.d.mts +15 -0
- package/dist/sidebar-Dwf54qYp.d.ts +15 -0
- package/package.json +6 -2
- package/packages/hydration/README.md +0 -3
- package/packages/hydration/index.ts +0 -3
- package/packages/hydration/settings-to-props.ts +0 -325
- package/packages/react/README.md +0 -3
- package/packages/react/components/index.tsx +0 -337
- package/packages/react/components/sidebar/index.ts +0 -3
- package/packages/react/components/sidebar/sidebar-group.tsx +0 -240
- package/packages/react/components/sidebar/sidebar.tsx +0 -127
- package/packages/react/contexts/framework.tsx +0 -78
- package/packages/react/contexts/index.ts +0 -2
- package/packages/react/contexts/ui.tsx +0 -6
- package/packages/react/hooks/index.ts +0 -3
- package/packages/react/hooks/useMatchedNav.tsx +0 -29
- package/packages/react/index.ts +0 -12
- package/packages/react/utils/manualHydration.ts +0 -25
- package/packages/theme/context.tsx +0 -19
- package/packages/theme/index.ts +0 -0
- package/postcss.config.cjs +0 -5
- package/src/index.ts +0 -1
- package/src/types.ts +0 -7
- package/tsconfig.json +0 -45
- package/tsup.config.ts +0 -28
package/dist/react.mjs
ADDED
|
@@ -0,0 +1,651 @@
|
|
|
1
|
+
// packages/react/components/index.tsx
|
|
2
|
+
import React5, { isValidElement } from "react";
|
|
3
|
+
import { useLocation as useLocation3 } from "react-router";
|
|
4
|
+
import { Toc, SubNav, UISidebar as UISidebar2 } from "@xyd-js/ui";
|
|
5
|
+
import { Breadcrumbs, NavLinks } from "@xyd-js/components/writer";
|
|
6
|
+
|
|
7
|
+
// packages/react/contexts/framework.tsx
|
|
8
|
+
import React, { createContext, useContext } from "react";
|
|
9
|
+
var framework = {
|
|
10
|
+
settings: {},
|
|
11
|
+
sidebarGroups: []
|
|
12
|
+
};
|
|
13
|
+
var FrameworkContext = createContext(framework);
|
|
14
|
+
function Framework(props) {
|
|
15
|
+
return /* @__PURE__ */ React.createElement(FrameworkContext.Provider, { value: {
|
|
16
|
+
settings: props.settings,
|
|
17
|
+
sidebarGroups: props.sidebarGroups,
|
|
18
|
+
toc: props.toc,
|
|
19
|
+
breadcrumbs: props.breadcrumbs,
|
|
20
|
+
navlinks: props.navlinks
|
|
21
|
+
} }, props.children);
|
|
22
|
+
}
|
|
23
|
+
function useSidebarGroups() {
|
|
24
|
+
const ctx = useContext(FrameworkContext);
|
|
25
|
+
return ctx.sidebarGroups;
|
|
26
|
+
}
|
|
27
|
+
function useSettings() {
|
|
28
|
+
const ctx = useContext(FrameworkContext);
|
|
29
|
+
return ctx.settings;
|
|
30
|
+
}
|
|
31
|
+
function useToC() {
|
|
32
|
+
const ctx = useContext(FrameworkContext);
|
|
33
|
+
return ctx.toc;
|
|
34
|
+
}
|
|
35
|
+
function useBreadcrumbs() {
|
|
36
|
+
const ctx = useContext(FrameworkContext);
|
|
37
|
+
return ctx.breadcrumbs;
|
|
38
|
+
}
|
|
39
|
+
function useNavLinks() {
|
|
40
|
+
const ctx = useContext(FrameworkContext);
|
|
41
|
+
return ctx.navlinks;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// packages/react/components/sidebar/sidebar-group.tsx
|
|
45
|
+
import React2, { createContext as createContext3, useContext as useContext2, useEffect, useState } from "react";
|
|
46
|
+
import { useLocation } from "react-router";
|
|
47
|
+
|
|
48
|
+
// packages/react/contexts/ui.tsx
|
|
49
|
+
import { createContext as createContext2 } from "react";
|
|
50
|
+
var UIContext = createContext2({
|
|
51
|
+
href: "",
|
|
52
|
+
setHref: (v) => {
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// packages/react/components/sidebar/sidebar-group.tsx
|
|
57
|
+
var groupContext = createContext3({
|
|
58
|
+
active: () => [false, () => {
|
|
59
|
+
}],
|
|
60
|
+
onClick: () => null
|
|
61
|
+
// TODO: should be deprecated?
|
|
62
|
+
});
|
|
63
|
+
function FwSidebarGroupContext({
|
|
64
|
+
children,
|
|
65
|
+
onePathBehaviour,
|
|
66
|
+
clientSideRouting,
|
|
67
|
+
initialActiveItems
|
|
68
|
+
}) {
|
|
69
|
+
let groupBehaviour;
|
|
70
|
+
if (onePathBehaviour) {
|
|
71
|
+
groupBehaviour = useOnePathBehaviour(initialActiveItems);
|
|
72
|
+
} else {
|
|
73
|
+
groupBehaviour = useDefaultBehaviour(initialActiveItems);
|
|
74
|
+
}
|
|
75
|
+
const location = useLocation();
|
|
76
|
+
const [href, setHref] = useState(location.pathname);
|
|
77
|
+
return /* @__PURE__ */ React2.createElement(UIContext.Provider, { value: {
|
|
78
|
+
href,
|
|
79
|
+
setHref: (value) => {
|
|
80
|
+
setHref(value);
|
|
81
|
+
}
|
|
82
|
+
} }, /* @__PURE__ */ React2.createElement(groupContext.Provider, { value: {
|
|
83
|
+
active: groupBehaviour,
|
|
84
|
+
onClick: clientSideRouting ? (event, item) => {
|
|
85
|
+
setHref(item.href);
|
|
86
|
+
scrollToDataSlug(event, item);
|
|
87
|
+
} : void 0
|
|
88
|
+
} }, children));
|
|
89
|
+
}
|
|
90
|
+
function useGroup() {
|
|
91
|
+
return useContext2(groupContext);
|
|
92
|
+
}
|
|
93
|
+
function getLastValue(set) {
|
|
94
|
+
let value;
|
|
95
|
+
for (value of set) ;
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
function stringify(item) {
|
|
99
|
+
var _a;
|
|
100
|
+
return JSON.stringify({
|
|
101
|
+
title: item.title,
|
|
102
|
+
href: item.href,
|
|
103
|
+
items: (_a = item.items) == null ? void 0 : _a.map((item2) => stringify(item2))
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function recursiveSearch(items, href, levels = []) {
|
|
107
|
+
for (let i = 0; i < items.length; i++) {
|
|
108
|
+
const item = items[i];
|
|
109
|
+
if (item.href === href) {
|
|
110
|
+
return [...levels, i];
|
|
111
|
+
}
|
|
112
|
+
if (item.items) {
|
|
113
|
+
const result = recursiveSearch(item.items, href, [...levels, i]);
|
|
114
|
+
if (result) {
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
function calcActive(groups, url) {
|
|
122
|
+
const initialActiveItems = [];
|
|
123
|
+
groups.forEach((group) => {
|
|
124
|
+
const activeLevels = recursiveSearch(group.items, url) || [];
|
|
125
|
+
activeLevels.reduce((acc, index) => {
|
|
126
|
+
initialActiveItems.push({
|
|
127
|
+
...acc[index],
|
|
128
|
+
active: true
|
|
129
|
+
});
|
|
130
|
+
return acc[index].items;
|
|
131
|
+
}, group.items);
|
|
132
|
+
return group;
|
|
133
|
+
});
|
|
134
|
+
return initialActiveItems;
|
|
135
|
+
}
|
|
136
|
+
function useDefaultBehaviour(initialActiveItems) {
|
|
137
|
+
const groups = useSidebarGroups();
|
|
138
|
+
const [weakSet] = useState(() => new Set(initialActiveItems.map((item) => stringify(item))));
|
|
139
|
+
const [, setForceUpdate] = useState(0);
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
window.addEventListener("xyd.history.pushState", (event) => {
|
|
142
|
+
var _a;
|
|
143
|
+
const url = (_a = event.detail) == null ? void 0 : _a.url;
|
|
144
|
+
if (!url) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const active = calcActive(groups, url);
|
|
148
|
+
weakSet.clear();
|
|
149
|
+
active.forEach((item) => {
|
|
150
|
+
addItem(item);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
}, []);
|
|
154
|
+
const forceUpdate = () => setForceUpdate((prev) => prev + 1);
|
|
155
|
+
const addItem = (item) => {
|
|
156
|
+
weakSet.add(stringify(item));
|
|
157
|
+
forceUpdate();
|
|
158
|
+
};
|
|
159
|
+
const deleteItem = (item) => {
|
|
160
|
+
weakSet.delete(stringify(item));
|
|
161
|
+
forceUpdate();
|
|
162
|
+
};
|
|
163
|
+
const hasItem = (item) => {
|
|
164
|
+
return weakSet.has(stringify(item));
|
|
165
|
+
};
|
|
166
|
+
return (item) => [
|
|
167
|
+
hasItem(item) || false,
|
|
168
|
+
() => {
|
|
169
|
+
if (hasItem(item)) {
|
|
170
|
+
deleteItem(item);
|
|
171
|
+
} else {
|
|
172
|
+
addItem(item);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
];
|
|
176
|
+
}
|
|
177
|
+
function useOnePathBehaviour(initialActiveItems) {
|
|
178
|
+
const [weakSet] = useState(() => new Set(initialActiveItems.map((item) => stringify(item))));
|
|
179
|
+
const [lastLevel, setLastLevel] = useState(false);
|
|
180
|
+
const [, setForceUpdate] = useState(0);
|
|
181
|
+
const forceUpdate = () => setForceUpdate((prev) => prev + 1);
|
|
182
|
+
const addItem = (item) => {
|
|
183
|
+
weakSet.add(stringify(item));
|
|
184
|
+
forceUpdate();
|
|
185
|
+
};
|
|
186
|
+
const deleteItem = (item) => {
|
|
187
|
+
weakSet.delete(stringify(item));
|
|
188
|
+
forceUpdate();
|
|
189
|
+
};
|
|
190
|
+
const hasItem = (item) => {
|
|
191
|
+
return weakSet.has(stringify(item));
|
|
192
|
+
};
|
|
193
|
+
const clear = () => {
|
|
194
|
+
weakSet.clear();
|
|
195
|
+
forceUpdate();
|
|
196
|
+
};
|
|
197
|
+
return (item) => [
|
|
198
|
+
hasItem(item),
|
|
199
|
+
() => {
|
|
200
|
+
setLastLevel(item.level);
|
|
201
|
+
if (hasItem(item) && item.level == 0) {
|
|
202
|
+
setLastLevel(false);
|
|
203
|
+
clear();
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (hasItem(item)) {
|
|
207
|
+
setLastLevel(false);
|
|
208
|
+
deleteItem(item);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if ((item.level || 0) > (lastLevel || 0) || lastLevel == false) {
|
|
212
|
+
addItem(item);
|
|
213
|
+
} else {
|
|
214
|
+
const v = getLastValue(weakSet);
|
|
215
|
+
deleteItem(JSON.parse(v));
|
|
216
|
+
addItem(item);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
];
|
|
220
|
+
}
|
|
221
|
+
function scrollToDataSlug(event, item) {
|
|
222
|
+
event.preventDefault();
|
|
223
|
+
const dataSlug = document.querySelector(`[data-slug="${item.href}"]`);
|
|
224
|
+
if (dataSlug) {
|
|
225
|
+
dataSlug.scrollIntoView({ block: "start", inline: "nearest" });
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// packages/react/components/sidebar/sidebar.tsx
|
|
230
|
+
import React3 from "react";
|
|
231
|
+
import { Badge } from "@xyd-js/components/writer";
|
|
232
|
+
import { UISidebar } from "@xyd-js/ui";
|
|
233
|
+
function FwSidebarItemGroup(props) {
|
|
234
|
+
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(UISidebar.ItemHeader, null, props.group), props.items.map((item, index) => /* @__PURE__ */ React3.createElement(
|
|
235
|
+
FwSidebarItem,
|
|
236
|
+
{
|
|
237
|
+
key: index + item.href,
|
|
238
|
+
title: item.title,
|
|
239
|
+
href: item.href,
|
|
240
|
+
items: item.items,
|
|
241
|
+
active: item.active,
|
|
242
|
+
level: 0
|
|
243
|
+
}
|
|
244
|
+
)));
|
|
245
|
+
}
|
|
246
|
+
var components = {
|
|
247
|
+
Frontmatter: {
|
|
248
|
+
// TODO: css
|
|
249
|
+
Title: ({ children }) => /* @__PURE__ */ React3.createElement("div", { style: {
|
|
250
|
+
display: "flex",
|
|
251
|
+
alignItems: "center",
|
|
252
|
+
justifyContent: "space-between",
|
|
253
|
+
width: "100%",
|
|
254
|
+
gap: "10px"
|
|
255
|
+
} }, children)
|
|
256
|
+
},
|
|
257
|
+
Badge: ({ children }) => /* @__PURE__ */ React3.createElement(Badge, null, children)
|
|
258
|
+
};
|
|
259
|
+
function mdxExport(code, components2) {
|
|
260
|
+
const scope = {
|
|
261
|
+
Fragment: React3.Fragment,
|
|
262
|
+
jsxs: React3.createElement,
|
|
263
|
+
jsx: React3.createElement,
|
|
264
|
+
jsxDEV: React3.createElement,
|
|
265
|
+
_jsxs: React3.createElement,
|
|
266
|
+
_jsx: React3.createElement,
|
|
267
|
+
...components2
|
|
268
|
+
};
|
|
269
|
+
const fn = new Function(...Object.keys(scope), `return ${code}`);
|
|
270
|
+
return fn(...Object.values(scope));
|
|
271
|
+
}
|
|
272
|
+
function FwSidebarItem(props) {
|
|
273
|
+
var _a, _b, _c;
|
|
274
|
+
const { active, onClick } = useGroup();
|
|
275
|
+
const [isActive, setActive] = active(props);
|
|
276
|
+
let Title;
|
|
277
|
+
if (typeof props.title === "object" && "code" in props.title) {
|
|
278
|
+
const code = props.title.code;
|
|
279
|
+
Title = () => mdxExport(
|
|
280
|
+
// TODO: in the future better mechanism + support props + better components (provider?) - similar to codehik
|
|
281
|
+
code.replace("() => ", ""),
|
|
282
|
+
components
|
|
283
|
+
);
|
|
284
|
+
} else {
|
|
285
|
+
Title = () => props.title;
|
|
286
|
+
}
|
|
287
|
+
return /* @__PURE__ */ React3.createElement(
|
|
288
|
+
UISidebar.Item,
|
|
289
|
+
{
|
|
290
|
+
button: !!((_a = props.items) == null ? void 0 : _a.length),
|
|
291
|
+
href: props.href,
|
|
292
|
+
active: isActive,
|
|
293
|
+
onClick: () => {
|
|
294
|
+
setActive();
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
/* @__PURE__ */ React3.createElement(Title, null),
|
|
298
|
+
((_b = props.items) == null ? void 0 : _b.length) && /* @__PURE__ */ React3.createElement(UISidebar.SubTree, { isOpen: isActive }, /* @__PURE__ */ React3.createElement(React3.Fragment, null, (_c = props.items) == null ? void 0 : _c.map((item, index) => /* @__PURE__ */ React3.createElement(
|
|
299
|
+
FwSidebarItem,
|
|
300
|
+
{
|
|
301
|
+
key: index + item.href,
|
|
302
|
+
title: item.title,
|
|
303
|
+
href: item.href,
|
|
304
|
+
items: item.items,
|
|
305
|
+
active: active(item)[0],
|
|
306
|
+
level: (props.level || 0) + 1
|
|
307
|
+
}
|
|
308
|
+
))))
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// packages/react/components/index.tsx
|
|
313
|
+
import { Nav } from "@xyd-js/ui";
|
|
314
|
+
|
|
315
|
+
// packages/react/utils/manualHydration.ts
|
|
316
|
+
import React4 from "react";
|
|
317
|
+
function manualHydration(obj, key = 0) {
|
|
318
|
+
if (typeof obj !== "object" || obj === null) {
|
|
319
|
+
return React4.createElement(React4.Fragment, { key });
|
|
320
|
+
}
|
|
321
|
+
const { type, props } = obj || {};
|
|
322
|
+
if (typeof type !== "string" && typeof type !== "function") {
|
|
323
|
+
return React4.createElement(React4.Fragment, { key });
|
|
324
|
+
}
|
|
325
|
+
let children = [];
|
|
326
|
+
if (props == null ? void 0 : props.children) {
|
|
327
|
+
if (Array.isArray(props.children)) {
|
|
328
|
+
children = props.children.map((child, i) => manualHydration(child, key + i)) || [];
|
|
329
|
+
} else {
|
|
330
|
+
children = [manualHydration(props.children, key)];
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
const elementProps = { ...props, children, key };
|
|
334
|
+
return React4.createElement(type, elementProps);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// packages/react/hooks/useMatchedNav.tsx
|
|
338
|
+
import { useLocation as useLocation2 } from "react-router";
|
|
339
|
+
function normalizeHref(href) {
|
|
340
|
+
if (href.startsWith("/")) {
|
|
341
|
+
return href;
|
|
342
|
+
}
|
|
343
|
+
return `/${href}`;
|
|
344
|
+
}
|
|
345
|
+
function useMatchedSubNav() {
|
|
346
|
+
var _a, _b, _c;
|
|
347
|
+
const settings = useSettings();
|
|
348
|
+
const location = useLocation2();
|
|
349
|
+
const matchedSubnav = (_c = (_b = (_a = settings.structure) == null ? void 0 : _a.header) == null ? void 0 : _b.filter((item) => item.sub)) == null ? void 0 : _c.find((item) => {
|
|
350
|
+
var _a2;
|
|
351
|
+
return normalizeHref(location.pathname).startsWith(normalizeHref(((_a2 = item.sub) == null ? void 0 : _a2.match) || ""));
|
|
352
|
+
});
|
|
353
|
+
if (!matchedSubnav) {
|
|
354
|
+
return null;
|
|
355
|
+
}
|
|
356
|
+
return matchedSubnav.sub || null;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// packages/react/components/index.tsx
|
|
360
|
+
function FwNavLogo() {
|
|
361
|
+
var _a, _b, _c;
|
|
362
|
+
const settings = useSettings();
|
|
363
|
+
const logo = isValidElement((_a = settings == null ? void 0 : settings.styling) == null ? void 0 : _a.logo) ? (_b = settings == null ? void 0 : settings.styling) == null ? void 0 : _b.logo : manualHydration((_c = settings == null ? void 0 : settings.styling) == null ? void 0 : _c.logo);
|
|
364
|
+
return /* @__PURE__ */ React5.createElement("a", { href: "/" }, logo);
|
|
365
|
+
}
|
|
366
|
+
function FwNav({ kind }) {
|
|
367
|
+
var _a, _b, _c;
|
|
368
|
+
const matchedSubnav = useMatchedSubNav();
|
|
369
|
+
const location = useLocation3();
|
|
370
|
+
const settings = useSettings();
|
|
371
|
+
const headers = matchedSubnav ? matchedSubnav == null ? void 0 : matchedSubnav.items : (_a = settings == null ? void 0 : settings.structure) == null ? void 0 : _a.header;
|
|
372
|
+
const active = headers == null ? void 0 : headers.find((item) => location.pathname.startsWith(item.url || ""));
|
|
373
|
+
return /* @__PURE__ */ React5.createElement(
|
|
374
|
+
Nav,
|
|
375
|
+
{
|
|
376
|
+
value: (active == null ? void 0 : active.url) || "",
|
|
377
|
+
kind,
|
|
378
|
+
logo: /* @__PURE__ */ React5.createElement(FwNavLogo, null),
|
|
379
|
+
onChange: () => {
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
(_c = (_b = settings == null ? void 0 : settings.structure) == null ? void 0 : _b.header) == null ? void 0 : _c.map((item, index) => {
|
|
383
|
+
return /* @__PURE__ */ React5.createElement(
|
|
384
|
+
Nav.Item,
|
|
385
|
+
{
|
|
386
|
+
key: index + (item.url || "") + item.name,
|
|
387
|
+
href: (item == null ? void 0 : item.url) || "",
|
|
388
|
+
value: item.url
|
|
389
|
+
},
|
|
390
|
+
item.name
|
|
391
|
+
);
|
|
392
|
+
})
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
function FwSubNav() {
|
|
396
|
+
const matchedSubnav = useMatchedSubNav();
|
|
397
|
+
const location = useLocation3();
|
|
398
|
+
if (!matchedSubnav) {
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
const active = matchedSubnav == null ? void 0 : matchedSubnav.items.findLast((item) => location.pathname.startsWith(item.url || ""));
|
|
402
|
+
return /* @__PURE__ */ React5.createElement(
|
|
403
|
+
SubNav,
|
|
404
|
+
{
|
|
405
|
+
title: (matchedSubnav == null ? void 0 : matchedSubnav.name) || "",
|
|
406
|
+
value: (active == null ? void 0 : active.url) || "",
|
|
407
|
+
onChange: () => {
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
matchedSubnav == null ? void 0 : matchedSubnav.items.map((item, index) => {
|
|
411
|
+
return /* @__PURE__ */ React5.createElement(SubNav.Item, { value: item.url || "", href: item.url }, item.name);
|
|
412
|
+
})
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
function recursiveSearch2(items, href, levels = []) {
|
|
416
|
+
for (let i = 0; i < items.length; i++) {
|
|
417
|
+
const item = items[i];
|
|
418
|
+
if (item.href === href) {
|
|
419
|
+
return [...levels, i];
|
|
420
|
+
}
|
|
421
|
+
if (item.items) {
|
|
422
|
+
const result = recursiveSearch2(item.items, href, [...levels, i]);
|
|
423
|
+
if (result) {
|
|
424
|
+
return result;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return null;
|
|
429
|
+
}
|
|
430
|
+
function FwSidebarGroups(props) {
|
|
431
|
+
var _a, _b, _c;
|
|
432
|
+
const groups = useSidebarGroups();
|
|
433
|
+
const settings = useSettings();
|
|
434
|
+
const footerItems = (_c = (_b = (_a = settings.structure) == null ? void 0 : _a.anchors) == null ? void 0 : _b.bottom) == null ? void 0 : _c.map((anchor) => {
|
|
435
|
+
let icon;
|
|
436
|
+
if (typeof anchor.icon === "string") {
|
|
437
|
+
switch (anchor.icon) {
|
|
438
|
+
case "icon-cookbook": {
|
|
439
|
+
icon = /* @__PURE__ */ React5.createElement(IconCookbook, null);
|
|
440
|
+
break;
|
|
441
|
+
}
|
|
442
|
+
case "icon-community": {
|
|
443
|
+
icon = /* @__PURE__ */ React5.createElement(IconCommunity, null);
|
|
444
|
+
break;
|
|
445
|
+
}
|
|
446
|
+
case "icon-marketplace": {
|
|
447
|
+
icon = /* @__PURE__ */ React5.createElement(IconMarketplace, null);
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
450
|
+
case "icon-sdk": {
|
|
451
|
+
icon = /* @__PURE__ */ React5.createElement(IconSDK, null);
|
|
452
|
+
break;
|
|
453
|
+
}
|
|
454
|
+
default: {
|
|
455
|
+
icon = null;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
} else {
|
|
459
|
+
icon = isValidElement(anchor.icon) ? anchor.icon : manualHydration(anchor.icon);
|
|
460
|
+
}
|
|
461
|
+
return /* @__PURE__ */ React5.createElement(UISidebar2.FooterItem, { href: anchor.url, icon }, anchor.name);
|
|
462
|
+
});
|
|
463
|
+
const location = useLocation3();
|
|
464
|
+
const initialActiveItems = [];
|
|
465
|
+
groups.forEach((group) => {
|
|
466
|
+
const activeLevels = recursiveSearch2(group.items, location.pathname) || [];
|
|
467
|
+
activeLevels.reduce((acc, index) => {
|
|
468
|
+
initialActiveItems.push(acc[index]);
|
|
469
|
+
acc[index].active = true;
|
|
470
|
+
return acc[index].items;
|
|
471
|
+
}, group.items);
|
|
472
|
+
return group;
|
|
473
|
+
});
|
|
474
|
+
return /* @__PURE__ */ React5.createElement(
|
|
475
|
+
FwSidebarGroupContext,
|
|
476
|
+
{
|
|
477
|
+
onePathBehaviour: props.onePathBehaviour,
|
|
478
|
+
clientSideRouting: props.clientSideRouting,
|
|
479
|
+
initialActiveItems
|
|
480
|
+
},
|
|
481
|
+
/* @__PURE__ */ React5.createElement(UISidebar2, { footerItems: footerItems && footerItems }, groups == null ? void 0 : groups.map((group, index) => /* @__PURE__ */ React5.createElement(
|
|
482
|
+
FwSidebarItemGroup,
|
|
483
|
+
{
|
|
484
|
+
key: index + group.group,
|
|
485
|
+
...group
|
|
486
|
+
}
|
|
487
|
+
)))
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
function FwToc() {
|
|
491
|
+
var _a;
|
|
492
|
+
const toc = useToC();
|
|
493
|
+
if (!toc) {
|
|
494
|
+
return null;
|
|
495
|
+
}
|
|
496
|
+
const flatToc = [];
|
|
497
|
+
const flatten = (toc2) => {
|
|
498
|
+
if (!toc2) {
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
toc2.forEach((item) => {
|
|
502
|
+
flatToc.push({
|
|
503
|
+
depth: item.depth,
|
|
504
|
+
value: item.value
|
|
505
|
+
});
|
|
506
|
+
flatten(item.children);
|
|
507
|
+
});
|
|
508
|
+
};
|
|
509
|
+
flatten(toc);
|
|
510
|
+
const tocFinal = flatToc.filter((item) => item.depth === 2);
|
|
511
|
+
const location = useLocation3();
|
|
512
|
+
const defaultValue = location.hash ? location.hash.replace("#", "") : (_a = tocFinal[0]) == null ? void 0 : _a.value;
|
|
513
|
+
return /* @__PURE__ */ React5.createElement(Toc, { defaultValue }, tocFinal.map((item, index) => /* @__PURE__ */ React5.createElement(
|
|
514
|
+
Toc.Item,
|
|
515
|
+
{
|
|
516
|
+
key: index + item.value + item.depth,
|
|
517
|
+
value: item.value
|
|
518
|
+
},
|
|
519
|
+
item.value
|
|
520
|
+
)));
|
|
521
|
+
}
|
|
522
|
+
function FwBreadcrumbs() {
|
|
523
|
+
const breadcrumbs = useBreadcrumbs();
|
|
524
|
+
return /* @__PURE__ */ React5.createElement(
|
|
525
|
+
Breadcrumbs,
|
|
526
|
+
{
|
|
527
|
+
items: breadcrumbs || []
|
|
528
|
+
}
|
|
529
|
+
);
|
|
530
|
+
}
|
|
531
|
+
function FwNavLinks() {
|
|
532
|
+
var _a, _b;
|
|
533
|
+
const navlinks = useNavLinks();
|
|
534
|
+
if (typeof ((_a = navlinks == null ? void 0 : navlinks.prev) == null ? void 0 : _a.title) !== "string" || typeof ((_b = navlinks == null ? void 0 : navlinks.next) == null ? void 0 : _b.title) !== "string") {
|
|
535
|
+
return null;
|
|
536
|
+
}
|
|
537
|
+
if ((navlinks == null ? void 0 : navlinks.prev) || (navlinks == null ? void 0 : navlinks.next)) {
|
|
538
|
+
return /* @__PURE__ */ React5.createElement(
|
|
539
|
+
NavLinks,
|
|
540
|
+
{
|
|
541
|
+
prev: navlinks.prev,
|
|
542
|
+
next: navlinks.next
|
|
543
|
+
}
|
|
544
|
+
);
|
|
545
|
+
}
|
|
546
|
+
return null;
|
|
547
|
+
}
|
|
548
|
+
function IconCookbook() {
|
|
549
|
+
return /* @__PURE__ */ React5.createElement(
|
|
550
|
+
"svg",
|
|
551
|
+
{
|
|
552
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
553
|
+
viewBox: "0 0 24 24",
|
|
554
|
+
width: "1em",
|
|
555
|
+
height: "1em"
|
|
556
|
+
},
|
|
557
|
+
/* @__PURE__ */ React5.createElement(
|
|
558
|
+
"path",
|
|
559
|
+
{
|
|
560
|
+
fillRule: "evenodd",
|
|
561
|
+
d: "M14.447 7.106a1 1 0 0 1 .447 1.341l-4 8a1 1 0 1 1-1.788-.894l4-8a1 1 0 0 1 1.341-.447ZM6.6 7.2a1 1 0 0 1 .2 1.4L4.25 12l2.55 3.4a1 1 0 0 1-1.6 1.2l-3-4a1 1 0 0 1 0-1.2l3-4a1 1 0 0 1 1.4-.2Zm10.8 0a1 1 0 0 1 1.4.2l3 4a1 1 0 0 1 0 1.2l-3 4a1 1 0 0 1-1.6-1.2l2.55-3.4-2.55-3.4a1 1 0 0 1 .2-1.4Z",
|
|
562
|
+
clipRule: "evenodd"
|
|
563
|
+
}
|
|
564
|
+
)
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
function IconCommunity() {
|
|
568
|
+
return /* @__PURE__ */ React5.createElement(
|
|
569
|
+
"svg",
|
|
570
|
+
{
|
|
571
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
572
|
+
fill: "currentColor",
|
|
573
|
+
viewBox: "0 0 24 24",
|
|
574
|
+
width: "1em",
|
|
575
|
+
height: "1em"
|
|
576
|
+
},
|
|
577
|
+
/* @__PURE__ */ React5.createElement(
|
|
578
|
+
"path",
|
|
579
|
+
{
|
|
580
|
+
fillRule: "evenodd",
|
|
581
|
+
d: "M10.5 8.5a1.5 1.5 0 1 1 3 0 1.5 1.5 0 0 1-3 0ZM12 5a3.5 3.5 0 1 0 0 7 3.5 3.5 0 0 0 0-7ZM3 9.5a1 1 0 1 1 2 0 1 1 0 0 1-2 0Zm1-3a3 3 0 1 0 0 6 3 3 0 0 0 0-6Zm16 2a1 1 0 1 0 0 2 1 1 0 0 0 0-2Zm-3 1a3 3 0 1 1 6 0 3 3 0 0 1-6 0ZM8 18c0-.974.438-1.684 1.142-2.185C9.876 15.293 10.911 15 12 15c1.09 0 2.124.293 2.858.815.704.5 1.142 1.21 1.142 2.185a1 1 0 1 0 2 0c0-1.692-.812-2.982-1.983-3.815C14.876 13.373 13.411 13 12 13c-1.41 0-2.876.373-4.017 1.185C6.812 15.018 6 16.308 6 18a1 1 0 1 0 2 0Zm-3.016-3.675a1 1 0 0 1-.809 1.16C2.79 15.732 2 16.486 2 17.5a1 1 0 1 1-2 0c0-2.41 1.978-3.655 3.825-3.985a1 1 0 0 1 1.16.81Zm14.84 1.16a1 1 0 1 1 .351-1.97C22.022 13.845 24 15.09 24 17.5a1 1 0 1 1-2 0c0-1.014-.79-1.768-2.175-2.015Z",
|
|
582
|
+
clipRule: "evenodd"
|
|
583
|
+
}
|
|
584
|
+
)
|
|
585
|
+
);
|
|
586
|
+
}
|
|
587
|
+
function IconMarketplace() {
|
|
588
|
+
return /* @__PURE__ */ React5.createElement(
|
|
589
|
+
"svg",
|
|
590
|
+
{
|
|
591
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
592
|
+
viewBox: "0 0 24 24",
|
|
593
|
+
fill: "none",
|
|
594
|
+
width: "1em",
|
|
595
|
+
height: "1em"
|
|
596
|
+
},
|
|
597
|
+
/* @__PURE__ */ React5.createElement(
|
|
598
|
+
"path",
|
|
599
|
+
{
|
|
600
|
+
"fill-rule": "evenodd",
|
|
601
|
+
"clip-rule": "evenodd",
|
|
602
|
+
d: "M3.78163 3.28449C3.8768 2.96725 4.16879 2.75 4.5 2.75H19.5C19.8312 2.75 20.1232 2.96725 20.2184 3.28449L21.7184 8.28449C21.7393 8.3544 21.75 8.42701 21.75 8.5C21.75 10.5711 20.0711 12.25 18 12.25C16.7733 12.25 15.6842 11.661 15 10.7504C14.3158 11.661 13.2267 12.25 12 12.25C10.7733 12.25 9.68417 11.661 9 10.7504C8.31583 11.661 7.2267 12.25 6 12.25C3.92893 12.25 2.25 10.5711 2.25 8.5C2.25 8.42701 2.26066 8.3544 2.28163 8.28449L3.78163 3.28449ZM9.75 8.5C9.75 9.74264 10.7574 10.75 12 10.75C13.2426 10.75 14.25 9.74264 14.25 8.5C14.25 8.08579 14.5858 7.75 15 7.75C15.4142 7.75 15.75 8.08579 15.75 8.5C15.75 9.74264 16.7574 10.75 18 10.75C19.2083 10.75 20.1942 9.79754 20.2477 8.60244L18.942 4.25H5.05802L3.75229 8.60244C3.80584 9.79753 4.79169 10.75 6 10.75C7.24264 10.75 8.25 9.74264 8.25 8.5C8.25 8.08579 8.58579 7.75 9 7.75C9.41421 7.75 9.75 8.08579 9.75 8.5Z"
|
|
603
|
+
}
|
|
604
|
+
),
|
|
605
|
+
/* @__PURE__ */ React5.createElement(
|
|
606
|
+
"path",
|
|
607
|
+
{
|
|
608
|
+
"fill-rule": "evenodd",
|
|
609
|
+
"clip-rule": "evenodd",
|
|
610
|
+
d: "M4 10.25C4.41421 10.25 4.75 10.5858 4.75 11V19.75H6.5C6.91421 19.75 7.25 20.0858 7.25 20.5C7.25 20.9142 6.91421 21.25 6.5 21.25H4C3.58579 21.25 3.25 20.9142 3.25 20.5V11C3.25 10.5858 3.58579 10.25 4 10.25ZM20 10.25C20.4142 10.25 20.75 10.5858 20.75 11V20.5C20.75 20.9142 20.4142 21.25 20 21.25H10.5C10.0858 21.25 9.75 20.9142 9.75 20.5C9.75 20.0858 10.0858 19.75 10.5 19.75H19.25V11C19.25 10.5858 19.5858 10.25 20 10.25Z"
|
|
611
|
+
}
|
|
612
|
+
),
|
|
613
|
+
/* @__PURE__ */ React5.createElement(
|
|
614
|
+
"path",
|
|
615
|
+
{
|
|
616
|
+
d: "M12.003 19C11.31 18.9996 10.6384 18.7598 10.102 18.3213C9.56564 17.8829 9.19745 17.2726 9.05983 16.594C8.92222 15.9154 9.02364 15.2101 9.34693 14.5976C9.67022 13.9852 10.1955 13.5032 10.8337 13.2333C11.5673 12.9262 12.393 12.9221 13.1296 13.2222C13.8661 13.5222 14.4536 14.1018 14.7631 14.8338C15.0727 15.5659 15.0791 16.3907 14.7808 17.1274C14.4827 17.8642 13.9042 18.4527 13.1724 18.7641C12.8025 18.9205 12.4047 19.0007 12.003 19ZM11.1458 14.7215C11.1124 14.7215 11.0803 14.7348 11.0567 14.7584C11.0331 14.782 11.0198 14.8141 11.0198 14.8475V17.1923C11.0198 17.2258 11.0331 17.2578 11.0567 17.2814C11.0803 17.305 11.1124 17.3183 11.1458 17.3183C11.1671 17.3183 11.188 17.3128 11.2065 17.3024L13.3399 16.13C13.3597 16.1192 13.3761 16.1032 13.3876 16.0838C13.3991 16.0644 13.4052 16.0423 13.4052 16.0197C13.4052 15.9972 13.3991 15.9751 13.3876 15.9557C13.3761 15.9362 13.3597 15.9203 13.3399 15.9094L11.2063 14.7373C11.1879 14.727 11.1671 14.7215 11.1458 14.7215Z"
|
|
617
|
+
}
|
|
618
|
+
)
|
|
619
|
+
);
|
|
620
|
+
}
|
|
621
|
+
function IconSDK() {
|
|
622
|
+
return /* @__PURE__ */ React5.createElement(
|
|
623
|
+
"svg",
|
|
624
|
+
{
|
|
625
|
+
viewBox: "0 0 15 15",
|
|
626
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
627
|
+
width: "1em",
|
|
628
|
+
height: "1em"
|
|
629
|
+
},
|
|
630
|
+
/* @__PURE__ */ React5.createElement(
|
|
631
|
+
"path",
|
|
632
|
+
{
|
|
633
|
+
d: "M7.28856 0.796908C7.42258 0.734364 7.57742 0.734364 7.71144 0.796908L13.7114 3.59691C13.8875 3.67906 14 3.85574 14 4.05V10.95C14 11.1443 13.8875 11.3209 13.7114 11.4031L7.71144 14.2031C7.57742 14.2656 7.42258 14.2656 7.28856 14.2031L1.28856 11.4031C1.11252 11.3209 1 11.1443 1 10.95V4.05C1 3.85574 1.11252 3.67906 1.28856 3.59691L7.28856 0.796908ZM2 4.80578L7 6.93078V12.9649L2 10.6316V4.80578ZM8 12.9649L13 10.6316V4.80578L8 6.93078V12.9649ZM7.5 6.05672L12.2719 4.02866L7.5 1.80176L2.72809 4.02866L7.5 6.05672Z",
|
|
634
|
+
fill: "currentColor",
|
|
635
|
+
fillRule: "evenodd",
|
|
636
|
+
clipRule: "evenodd"
|
|
637
|
+
}
|
|
638
|
+
)
|
|
639
|
+
);
|
|
640
|
+
}
|
|
641
|
+
export {
|
|
642
|
+
Framework,
|
|
643
|
+
FwBreadcrumbs,
|
|
644
|
+
FwNav,
|
|
645
|
+
FwNavLinks,
|
|
646
|
+
FwSidebarGroups,
|
|
647
|
+
FwSubNav,
|
|
648
|
+
FwToc,
|
|
649
|
+
useMatchedSubNav
|
|
650
|
+
};
|
|
651
|
+
//# sourceMappingURL=react.mjs.map
|