@xyd-js/framework 0.1.0-xyd.6 → 0.1.0-xyd.73
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/LICENSE +21 -0
- package/dist/Sidebar-CdavG0uc.d.ts +23 -0
- package/dist/hydration.d.ts +9 -3
- package/dist/hydration.js +189 -191
- package/dist/hydration.js.map +1 -1
- package/dist/index.d.ts +22 -4
- package/dist/index.js +34 -15
- package/dist/index.js.map +1 -1
- package/dist/react.d.ts +49 -9
- package/dist/react.js +446 -528
- package/dist/react.js.map +1 -1
- package/package.json +19 -16
- package/dist/hydration.d.mts +0 -11
- package/dist/hydration.mjs +0 -245
- package/dist/hydration.mjs.map +0 -1
- package/dist/index.d.mts +0 -6
- package/dist/index.mjs +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/react.d.mts +0 -32
- package/dist/react.mjs +0 -651
- package/dist/react.mjs.map +0 -1
- package/dist/sidebar-Dwf54qYp.d.mts +0 -15
- package/dist/sidebar-Dwf54qYp.d.ts +0 -15
- 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 -5
- package/tsconfig.json +0 -45
- package/tsup.config.ts +0 -28
package/dist/react.js
CHANGED
|
@@ -1,694 +1,612 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
// packages/react/components/index.tsx
|
|
2
|
+
import React5, { isValidElement, useState as useState3 } from "react";
|
|
3
|
+
import { Link, useLocation as useLocation2, useMatches as useMatches2 } from "react-router";
|
|
4
|
+
import { Nav, SubNav, Toc, UISidebar as UISidebar2 } from "@xyd-js/ui";
|
|
5
|
+
import { Anchor, Breadcrumbs, Button as Button2, ColorSchemeButton, Icon as Icon2, NavLinks, useColorScheme } from "@xyd-js/components/writer";
|
|
28
6
|
|
|
29
|
-
// packages/react/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
FwBreadcrumbs: () => FwBreadcrumbs,
|
|
34
|
-
FwNav: () => FwNav,
|
|
35
|
-
FwNavLinks: () => FwNavLinks,
|
|
36
|
-
FwSidebarGroups: () => FwSidebarGroups,
|
|
37
|
-
FwSubNav: () => FwSubNav,
|
|
38
|
-
FwToc: () => FwToc,
|
|
39
|
-
useMatchedSubNav: () => useMatchedSubNav
|
|
7
|
+
// packages/react/components/Surfaces.tsx
|
|
8
|
+
import React, { createContext, useContext } from "react";
|
|
9
|
+
var SurfaceContext = createContext({
|
|
10
|
+
surfaces: void 0
|
|
40
11
|
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
12
|
+
function Surface(props) {
|
|
13
|
+
const { target } = props;
|
|
14
|
+
const registry = useContext(SurfaceContext);
|
|
15
|
+
if (!registry.surfaces) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const components = registry.surfaces.get(target);
|
|
19
|
+
if (!components) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
if (!Array.isArray(components)) {
|
|
23
|
+
if (typeof components === "function") {
|
|
24
|
+
const Component = components;
|
|
25
|
+
return /* @__PURE__ */ React.createElement(Component, { ...props.props });
|
|
26
|
+
}
|
|
27
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, components);
|
|
28
|
+
}
|
|
29
|
+
if (!components.length) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, components.map((Component, index) => {
|
|
33
|
+
if (typeof Component === "function") {
|
|
34
|
+
const Comp = Component;
|
|
35
|
+
return /* @__PURE__ */ React.createElement(Comp, { key: index, ...props.props });
|
|
36
|
+
}
|
|
37
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, { key: index }, Component);
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
48
40
|
|
|
49
41
|
// packages/react/contexts/framework.tsx
|
|
50
|
-
|
|
42
|
+
import React2, { createContext as createContext2, useContext as useContext2, useEffect, useState } from "react";
|
|
43
|
+
import { useNavigation } from "react-router";
|
|
44
|
+
import { ProgressBar } from "@xyd-js/ui";
|
|
45
|
+
import { Banner } from "@xyd-js/components/writer";
|
|
51
46
|
var framework = {
|
|
52
47
|
settings: {},
|
|
53
|
-
|
|
48
|
+
metadata: {
|
|
49
|
+
title: ""
|
|
50
|
+
},
|
|
51
|
+
sidebarGroups: [],
|
|
52
|
+
setMetadata: () => {
|
|
53
|
+
},
|
|
54
|
+
components: {}
|
|
54
55
|
};
|
|
55
|
-
var FrameworkContext = (
|
|
56
|
+
var FrameworkContext = createContext2(framework);
|
|
56
57
|
function Framework(props) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
59
|
+
const navigation = useNavigation();
|
|
60
|
+
const [metadata, setMetadata] = useState(props.metadata);
|
|
61
|
+
const BannerContent = props.BannerContent || null;
|
|
62
|
+
const BannerComponent = ((_c = (_b = (_a = props == null ? void 0 : props.settings) == null ? void 0 : _a.theme) == null ? void 0 : _b.banner) == null ? void 0 : _c.kind) === "secondary" ? Banner.Secondary : Banner;
|
|
63
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(FrameworkContext, { value: {
|
|
64
|
+
settings: Object.freeze({ ...props.settings }),
|
|
65
|
+
sidebarGroups: Object.freeze([...props.sidebarGroups]),
|
|
66
|
+
metadata: Object.freeze({ ...metadata, title: (metadata == null ? void 0 : metadata.title) || "" }),
|
|
67
|
+
setMetadata,
|
|
68
|
+
components: Object.freeze(props.components || {})
|
|
69
|
+
} }, /* @__PURE__ */ React2.createElement(SurfaceContext, { value: {
|
|
70
|
+
surfaces: props.surfaces
|
|
71
|
+
} }, /* @__PURE__ */ React2.createElement(ProgressBar, { isActive: navigation.state === "loading" }), BannerContent ? /* @__PURE__ */ React2.createElement(
|
|
72
|
+
BannerComponent,
|
|
73
|
+
{
|
|
74
|
+
label: (_f = (_e = (_d = props.settings) == null ? void 0 : _d.theme) == null ? void 0 : _e.banner) == null ? void 0 : _f.label,
|
|
75
|
+
icon: (_i = (_h = (_g = props.settings) == null ? void 0 : _g.theme) == null ? void 0 : _h.banner) == null ? void 0 : _i.icon
|
|
76
|
+
},
|
|
77
|
+
/* @__PURE__ */ React2.createElement(BannerContent, null)
|
|
78
|
+
) : null, props.children)));
|
|
79
|
+
}
|
|
80
|
+
var FrameworkPageContext = createContext2({
|
|
81
|
+
ContentComponent: () => /* @__PURE__ */ React2.createElement(React2.Fragment, null),
|
|
82
|
+
metadata: {
|
|
83
|
+
title: ""
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
function FrameworkPage(props) {
|
|
87
|
+
const { setMetadata } = useContext2(FrameworkContext);
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
setMetadata(props.metadata);
|
|
90
|
+
}, []);
|
|
91
|
+
return /* @__PURE__ */ React2.createElement(FrameworkPageContext, { value: {
|
|
92
|
+
ContentComponent: props.ContentComponent || (() => /* @__PURE__ */ React2.createElement(React2.Fragment, null)),
|
|
93
|
+
metadata: Object.freeze(props.metadata),
|
|
94
|
+
breadcrumbs: Object.freeze(props.breadcrumbs),
|
|
95
|
+
rawPage: Object.freeze(props.rawPage),
|
|
96
|
+
toc: Object.freeze(props.toc || []),
|
|
97
|
+
navlinks: Object.freeze(props.navlinks)
|
|
63
98
|
} }, props.children);
|
|
64
99
|
}
|
|
65
100
|
function useSidebarGroups() {
|
|
66
|
-
const ctx = (
|
|
101
|
+
const ctx = useContext2(FrameworkContext);
|
|
67
102
|
return ctx.sidebarGroups;
|
|
68
103
|
}
|
|
69
104
|
function useSettings() {
|
|
70
|
-
const ctx = (
|
|
105
|
+
const ctx = useContext2(FrameworkContext);
|
|
71
106
|
return ctx.settings;
|
|
72
107
|
}
|
|
108
|
+
function useMetadata() {
|
|
109
|
+
const ctx = useContext2(FrameworkContext);
|
|
110
|
+
return ctx.metadata;
|
|
111
|
+
}
|
|
112
|
+
function useComponents() {
|
|
113
|
+
const ctx = useContext2(FrameworkContext);
|
|
114
|
+
return ctx.components;
|
|
115
|
+
}
|
|
73
116
|
function useToC() {
|
|
74
|
-
const ctx = (
|
|
75
|
-
|
|
117
|
+
const ctx = useContext2(FrameworkPageContext);
|
|
118
|
+
const toc = ctx.toc || [];
|
|
119
|
+
return toc;
|
|
76
120
|
}
|
|
77
121
|
function useBreadcrumbs() {
|
|
78
|
-
const ctx = (
|
|
122
|
+
const ctx = useContext2(FrameworkPageContext);
|
|
79
123
|
return ctx.breadcrumbs;
|
|
80
124
|
}
|
|
81
125
|
function useNavLinks() {
|
|
82
|
-
const ctx = (
|
|
126
|
+
const ctx = useContext2(FrameworkPageContext);
|
|
83
127
|
return ctx.navlinks;
|
|
84
128
|
}
|
|
129
|
+
function useRawPage() {
|
|
130
|
+
const ctx = useContext2(FrameworkPageContext);
|
|
131
|
+
return ctx.rawPage;
|
|
132
|
+
}
|
|
133
|
+
function useContentComponent() {
|
|
134
|
+
const ctx = useContext2(FrameworkPageContext);
|
|
135
|
+
return ctx.ContentComponent;
|
|
136
|
+
}
|
|
85
137
|
|
|
86
|
-
// packages/react/components/
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
// packages/react/contexts/ui.tsx
|
|
91
|
-
var import_react2 = require("react");
|
|
92
|
-
var UIContext = (0, import_react2.createContext)({
|
|
93
|
-
href: "",
|
|
94
|
-
setHref: (v) => {
|
|
95
|
-
}
|
|
96
|
-
});
|
|
138
|
+
// packages/react/components/Sidebar/Sidebar.tsx
|
|
139
|
+
import React4 from "react";
|
|
140
|
+
import { UISidebar } from "@xyd-js/ui";
|
|
141
|
+
import { Icon } from "@xyd-js/components/writer";
|
|
97
142
|
|
|
98
|
-
// packages/react/components/
|
|
99
|
-
|
|
143
|
+
// packages/react/components/Sidebar/SidebarGroup.tsx
|
|
144
|
+
import React3, { createContext as createContext3, useContext as useContext3, useState as useState2, useEffect as useEffect2 } from "react";
|
|
145
|
+
import { useNavigation as useNavigation2 } from "react-router";
|
|
146
|
+
var GroupContext = createContext3({
|
|
100
147
|
active: () => [false, () => {
|
|
101
|
-
}]
|
|
102
|
-
onClick: () => null
|
|
103
|
-
// TODO: should be deprecated?
|
|
148
|
+
}]
|
|
104
149
|
});
|
|
105
|
-
function FwSidebarGroupContext({
|
|
106
|
-
children,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
})
|
|
111
|
-
let groupBehaviour;
|
|
112
|
-
if (onePathBehaviour) {
|
|
113
|
-
groupBehaviour = useOnePathBehaviour(initialActiveItems);
|
|
114
|
-
} else {
|
|
115
|
-
groupBehaviour = useDefaultBehaviour(initialActiveItems);
|
|
116
|
-
}
|
|
117
|
-
const location = (0, import_react_router.useLocation)();
|
|
118
|
-
const [href, setHref] = (0, import_react3.useState)(location.pathname);
|
|
119
|
-
return /* @__PURE__ */ import_react3.default.createElement(UIContext.Provider, { value: {
|
|
120
|
-
href,
|
|
121
|
-
setHref: (value) => {
|
|
122
|
-
setHref(value);
|
|
123
|
-
}
|
|
124
|
-
} }, /* @__PURE__ */ import_react3.default.createElement(groupContext.Provider, { value: {
|
|
125
|
-
active: groupBehaviour,
|
|
126
|
-
onClick: clientSideRouting ? (event, item) => {
|
|
127
|
-
setHref(item.href);
|
|
128
|
-
scrollToDataSlug(event, item);
|
|
129
|
-
} : void 0
|
|
130
|
-
} }, children));
|
|
150
|
+
function FwSidebarGroupContext(props) {
|
|
151
|
+
const { children, initialActiveItems } = props;
|
|
152
|
+
const groupBehaviour = useDefaultBehaviour(initialActiveItems);
|
|
153
|
+
return /* @__PURE__ */ React3.createElement(GroupContext, { value: {
|
|
154
|
+
active: groupBehaviour
|
|
155
|
+
} }, children);
|
|
131
156
|
}
|
|
132
157
|
function useGroup() {
|
|
133
|
-
return (
|
|
134
|
-
}
|
|
135
|
-
function getLastValue(set) {
|
|
136
|
-
let value;
|
|
137
|
-
for (value of set) ;
|
|
138
|
-
return value;
|
|
139
|
-
}
|
|
140
|
-
function stringify(item) {
|
|
141
|
-
var _a;
|
|
142
|
-
return JSON.stringify({
|
|
143
|
-
title: item.title,
|
|
144
|
-
href: item.href,
|
|
145
|
-
items: (_a = item.items) == null ? void 0 : _a.map((item2) => stringify(item2))
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
function recursiveSearch(items, href, levels = []) {
|
|
149
|
-
for (let i = 0; i < items.length; i++) {
|
|
150
|
-
const item = items[i];
|
|
151
|
-
if (item.href === href) {
|
|
152
|
-
return [...levels, i];
|
|
153
|
-
}
|
|
154
|
-
if (item.items) {
|
|
155
|
-
const result = recursiveSearch(item.items, href, [...levels, i]);
|
|
156
|
-
if (result) {
|
|
157
|
-
return result;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return null;
|
|
162
|
-
}
|
|
163
|
-
function calcActive(groups, url) {
|
|
164
|
-
const initialActiveItems = [];
|
|
165
|
-
groups.forEach((group) => {
|
|
166
|
-
const activeLevels = recursiveSearch(group.items, url) || [];
|
|
167
|
-
activeLevels.reduce((acc, index) => {
|
|
168
|
-
initialActiveItems.push({
|
|
169
|
-
...acc[index],
|
|
170
|
-
active: true
|
|
171
|
-
});
|
|
172
|
-
return acc[index].items;
|
|
173
|
-
}, group.items);
|
|
174
|
-
return group;
|
|
175
|
-
});
|
|
176
|
-
return initialActiveItems;
|
|
158
|
+
return useContext3(GroupContext);
|
|
177
159
|
}
|
|
178
160
|
function useDefaultBehaviour(initialActiveItems) {
|
|
179
|
-
const
|
|
180
|
-
const [
|
|
181
|
-
const [, setForceUpdate] = (0
|
|
182
|
-
(0, import_react3.useEffect)(() => {
|
|
183
|
-
window.addEventListener("xyd.history.pushState", (event) => {
|
|
184
|
-
var _a;
|
|
185
|
-
const url = (_a = event.detail) == null ? void 0 : _a.url;
|
|
186
|
-
if (!url) {
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
const active = calcActive(groups, url);
|
|
190
|
-
weakSet.clear();
|
|
191
|
-
active.forEach((item) => {
|
|
192
|
-
addItem(item);
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
}, []);
|
|
161
|
+
const navigation = useNavigation2();
|
|
162
|
+
const [activeItems, setActiveItems] = useState2(() => createItemsMap(initialActiveItems));
|
|
163
|
+
const [, setForceUpdate] = useState2(0);
|
|
196
164
|
const forceUpdate = () => setForceUpdate((prev) => prev + 1);
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
const deleteItem = (item) => {
|
|
202
|
-
weakSet.delete(stringify(item));
|
|
203
|
-
forceUpdate();
|
|
204
|
-
};
|
|
205
|
-
const hasItem = (item) => {
|
|
206
|
-
return weakSet.has(stringify(item));
|
|
207
|
-
};
|
|
208
|
-
return (item) => [
|
|
209
|
-
hasItem(item) || false,
|
|
210
|
-
() => {
|
|
211
|
-
if (hasItem(item)) {
|
|
212
|
-
deleteItem(item);
|
|
213
|
-
} else {
|
|
214
|
-
addItem(item);
|
|
215
|
-
}
|
|
165
|
+
useEffect2(() => {
|
|
166
|
+
if (navigation.state !== "loading") {
|
|
167
|
+
setActiveItems(createItemsMap(initialActiveItems));
|
|
168
|
+
forceUpdate();
|
|
216
169
|
}
|
|
217
|
-
];
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
weakSet.add(stringify(item));
|
|
226
|
-
forceUpdate();
|
|
227
|
-
};
|
|
228
|
-
const deleteItem = (item) => {
|
|
229
|
-
weakSet.delete(stringify(item));
|
|
170
|
+
}, [initialActiveItems, navigation.state]);
|
|
171
|
+
function addItem(item) {
|
|
172
|
+
const key = itemId(item);
|
|
173
|
+
setActiveItems((prev) => {
|
|
174
|
+
const newMap = new Map(prev);
|
|
175
|
+
newMap.set(key, true);
|
|
176
|
+
return newMap;
|
|
177
|
+
});
|
|
230
178
|
forceUpdate();
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
179
|
+
}
|
|
180
|
+
function deleteItem(item) {
|
|
181
|
+
const key = itemId(item);
|
|
182
|
+
setActiveItems((prev) => {
|
|
183
|
+
const newMap = new Map(prev);
|
|
184
|
+
newMap.delete(key);
|
|
185
|
+
return newMap;
|
|
186
|
+
});
|
|
237
187
|
forceUpdate();
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
()
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
188
|
+
}
|
|
189
|
+
function hasItem(item) {
|
|
190
|
+
const key = itemId(item);
|
|
191
|
+
return activeItems.get(key) || false;
|
|
192
|
+
}
|
|
193
|
+
return (item) => {
|
|
194
|
+
return [
|
|
195
|
+
hasItem(item) || false,
|
|
196
|
+
() => {
|
|
197
|
+
if (!hasItem(item)) {
|
|
198
|
+
addItem(item);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
250
201
|
deleteItem(item);
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
if ((item.level || 0) > (lastLevel || 0) || lastLevel == false) {
|
|
254
|
-
addItem(item);
|
|
255
|
-
} else {
|
|
256
|
-
const v = getLastValue(weakSet);
|
|
257
|
-
deleteItem(JSON.parse(v));
|
|
258
|
-
addItem(item);
|
|
259
202
|
}
|
|
260
|
-
|
|
261
|
-
|
|
203
|
+
];
|
|
204
|
+
};
|
|
262
205
|
}
|
|
263
|
-
function
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
206
|
+
function itemId(item) {
|
|
207
|
+
const id = `${item.uniqIndex}:${item.groupIndex}-${item.level}-${item.itemIndex}`;
|
|
208
|
+
return id;
|
|
209
|
+
}
|
|
210
|
+
function createItemsMap(items) {
|
|
211
|
+
const map = /* @__PURE__ */ new Map();
|
|
212
|
+
items.forEach((item) => {
|
|
213
|
+
const key = itemId(item);
|
|
214
|
+
map.set(key, true);
|
|
215
|
+
});
|
|
216
|
+
return map;
|
|
269
217
|
}
|
|
270
218
|
|
|
271
|
-
// packages/react/components/
|
|
272
|
-
var import_react4 = __toESM(require("react"));
|
|
273
|
-
var import_writer = require("@xyd-js/components/writer");
|
|
274
|
-
var import_ui2 = require("@xyd-js/ui");
|
|
219
|
+
// packages/react/components/Sidebar/Sidebar.tsx
|
|
275
220
|
function FwSidebarItemGroup(props) {
|
|
276
|
-
|
|
221
|
+
const icon = props.icon ? /* @__PURE__ */ React4.createElement(Icon, { name: props.icon || "", size: 16 }) : null;
|
|
222
|
+
return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(UISidebar.ItemHeader, { icon }, props.group), props.items.map((item, index) => /* @__PURE__ */ React4.createElement(
|
|
277
223
|
FwSidebarItem,
|
|
278
224
|
{
|
|
225
|
+
uniqIndex: item.uniqIndex,
|
|
226
|
+
groupIndex: props.groupIndex,
|
|
227
|
+
level: 0,
|
|
228
|
+
itemIndex: index,
|
|
279
229
|
key: index + item.href,
|
|
280
230
|
title: item.title,
|
|
231
|
+
sidebarTitle: item.sidebarTitle,
|
|
232
|
+
pageMeta: item.pageMeta,
|
|
281
233
|
href: item.href,
|
|
282
234
|
items: item.items,
|
|
283
235
|
active: item.active,
|
|
284
|
-
|
|
236
|
+
icon: item.icon
|
|
285
237
|
}
|
|
286
238
|
)));
|
|
287
239
|
}
|
|
288
|
-
var components = {
|
|
289
|
-
Frontmatter: {
|
|
290
|
-
// TODO: css
|
|
291
|
-
Title: ({ children }) => /* @__PURE__ */ import_react4.default.createElement("div", { style: {
|
|
292
|
-
display: "flex",
|
|
293
|
-
alignItems: "center",
|
|
294
|
-
justifyContent: "space-between",
|
|
295
|
-
width: "100%",
|
|
296
|
-
gap: "10px"
|
|
297
|
-
} }, children)
|
|
298
|
-
},
|
|
299
|
-
Badge: ({ children }) => /* @__PURE__ */ import_react4.default.createElement(import_writer.Badge, null, children)
|
|
300
|
-
};
|
|
301
|
-
function mdxExport(code, components2) {
|
|
302
|
-
const scope = {
|
|
303
|
-
Fragment: import_react4.default.Fragment,
|
|
304
|
-
jsxs: import_react4.default.createElement,
|
|
305
|
-
jsx: import_react4.default.createElement,
|
|
306
|
-
jsxDEV: import_react4.default.createElement,
|
|
307
|
-
_jsxs: import_react4.default.createElement,
|
|
308
|
-
_jsx: import_react4.default.createElement,
|
|
309
|
-
...components2
|
|
310
|
-
};
|
|
311
|
-
const fn = new Function(...Object.keys(scope), `return ${code}`);
|
|
312
|
-
return fn(...Object.values(scope));
|
|
313
|
-
}
|
|
314
240
|
function FwSidebarItem(props) {
|
|
315
|
-
var _a, _b, _c;
|
|
316
|
-
const { active
|
|
241
|
+
var _a, _b, _c, _d;
|
|
242
|
+
const { active } = useGroup();
|
|
317
243
|
const [isActive, setActive] = active(props);
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
);
|
|
326
|
-
} else {
|
|
327
|
-
Title = () => props.title;
|
|
244
|
+
const title = props.sidebarTitle || props.title || "";
|
|
245
|
+
const nested = !!((_a = props.items) == null ? void 0 : _a.length);
|
|
246
|
+
function handleClick() {
|
|
247
|
+
if (!nested) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
setActive();
|
|
328
251
|
}
|
|
329
|
-
|
|
330
|
-
|
|
252
|
+
const hasActiveChild = (_b = props.items) == null ? void 0 : _b.some((item) => {
|
|
253
|
+
var _a2;
|
|
254
|
+
const [itemActive] = active(item);
|
|
255
|
+
return itemActive && item.href || ((_a2 = item.items) == null ? void 0 : _a2.some((subItem) => {
|
|
256
|
+
const [subItemActive] = active(subItem);
|
|
257
|
+
return subItemActive && subItem.href;
|
|
258
|
+
}));
|
|
259
|
+
});
|
|
260
|
+
const isActiveItem = !!(isActive && props.href);
|
|
261
|
+
const isParentActive = hasActiveChild;
|
|
262
|
+
const icon = /* @__PURE__ */ React4.createElement(Icon, { name: props.icon || "", size: 16 });
|
|
263
|
+
return /* @__PURE__ */ React4.createElement(
|
|
264
|
+
UISidebar.Item,
|
|
331
265
|
{
|
|
332
|
-
button:
|
|
266
|
+
button: nested,
|
|
333
267
|
href: props.href,
|
|
334
|
-
active:
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
268
|
+
active: isActiveItem,
|
|
269
|
+
isParentActive,
|
|
270
|
+
onClick: handleClick,
|
|
271
|
+
icon
|
|
338
272
|
},
|
|
339
|
-
/* @__PURE__ */
|
|
340
|
-
|
|
273
|
+
/* @__PURE__ */ React4.createElement("div", { part: "item-title-container" }, /* @__PURE__ */ React4.createElement(
|
|
274
|
+
Surface,
|
|
275
|
+
{
|
|
276
|
+
target: "sidebar.item.left",
|
|
277
|
+
props: {
|
|
278
|
+
active: isActiveItem,
|
|
279
|
+
pageMeta: props.pageMeta
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
), /* @__PURE__ */ React4.createElement("div", { part: "item-title" }, title), /* @__PURE__ */ React4.createElement(
|
|
283
|
+
Surface,
|
|
284
|
+
{
|
|
285
|
+
target: "sidebar.item.right",
|
|
286
|
+
props: {
|
|
287
|
+
active: isActiveItem,
|
|
288
|
+
pageMeta: props.pageMeta
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
)),
|
|
292
|
+
((_c = props.items) == null ? void 0 : _c.length) && /* @__PURE__ */ React4.createElement(UISidebar.SubTree, { isOpen: isActive }, /* @__PURE__ */ React4.createElement(React4.Fragment, null, (_d = props.items) == null ? void 0 : _d.map((item, index) => /* @__PURE__ */ React4.createElement(
|
|
341
293
|
FwSidebarItem,
|
|
342
294
|
{
|
|
295
|
+
uniqIndex: item.uniqIndex,
|
|
296
|
+
groupIndex: props.groupIndex,
|
|
297
|
+
level: (props.level || 0) + 1,
|
|
298
|
+
itemIndex: index,
|
|
343
299
|
key: index + item.href,
|
|
344
300
|
title: item.title,
|
|
345
301
|
href: item.href,
|
|
346
302
|
items: item.items,
|
|
347
303
|
active: active(item)[0],
|
|
348
|
-
|
|
304
|
+
icon: item.icon,
|
|
305
|
+
pageMeta: item.pageMeta
|
|
349
306
|
}
|
|
350
307
|
))))
|
|
351
308
|
);
|
|
352
309
|
}
|
|
353
310
|
|
|
354
|
-
// packages/react/components/index.tsx
|
|
355
|
-
var import_ui4 = require("@xyd-js/ui");
|
|
356
|
-
|
|
357
|
-
// packages/react/utils/manualHydration.ts
|
|
358
|
-
var import_react5 = __toESM(require("react"));
|
|
359
|
-
function manualHydration(obj, key = 0) {
|
|
360
|
-
if (typeof obj !== "object" || obj === null) {
|
|
361
|
-
return import_react5.default.createElement(import_react5.default.Fragment, { key });
|
|
362
|
-
}
|
|
363
|
-
const { type, props } = obj || {};
|
|
364
|
-
if (typeof type !== "string" && typeof type !== "function") {
|
|
365
|
-
return import_react5.default.createElement(import_react5.default.Fragment, { key });
|
|
366
|
-
}
|
|
367
|
-
let children = [];
|
|
368
|
-
if (props == null ? void 0 : props.children) {
|
|
369
|
-
if (Array.isArray(props.children)) {
|
|
370
|
-
children = props.children.map((child, i) => manualHydration(child, key + i)) || [];
|
|
371
|
-
} else {
|
|
372
|
-
children = [manualHydration(props.children, key)];
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
const elementProps = { ...props, children, key };
|
|
376
|
-
return import_react5.default.createElement(type, elementProps);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
311
|
// packages/react/hooks/useMatchedNav.tsx
|
|
380
|
-
|
|
381
|
-
function normalizeHref(href) {
|
|
382
|
-
if (href.startsWith("/")) {
|
|
383
|
-
return href;
|
|
384
|
-
}
|
|
385
|
-
return `/${href}`;
|
|
386
|
-
}
|
|
312
|
+
import { useMatches } from "react-router";
|
|
387
313
|
function useMatchedSubNav() {
|
|
388
314
|
var _a, _b, _c;
|
|
389
315
|
const settings = useSettings();
|
|
390
|
-
const
|
|
391
|
-
const
|
|
316
|
+
const matches = useMatches();
|
|
317
|
+
const lastMatchId = (_a = matches[matches.length - 1]) == null ? void 0 : _a.id;
|
|
318
|
+
let matchedSubnav = (_c = (_b = settings.navigation) == null ? void 0 : _b.segments) == null ? void 0 : _c.find((item) => {
|
|
392
319
|
var _a2;
|
|
393
|
-
return
|
|
320
|
+
return (_a2 = item.pages) == null ? void 0 : _a2.find((page) => {
|
|
321
|
+
return sanitizeUrl(page.page || "") === sanitizeUrl(lastMatchId);
|
|
322
|
+
});
|
|
394
323
|
});
|
|
395
324
|
if (!matchedSubnav) {
|
|
396
325
|
return null;
|
|
397
326
|
}
|
|
398
|
-
return matchedSubnav
|
|
327
|
+
return matchedSubnav || null;
|
|
328
|
+
}
|
|
329
|
+
function sanitizeUrl(url) {
|
|
330
|
+
if (url.startsWith("/")) {
|
|
331
|
+
return url;
|
|
332
|
+
}
|
|
333
|
+
return `/${url}`;
|
|
399
334
|
}
|
|
400
335
|
|
|
401
336
|
// packages/react/components/index.tsx
|
|
402
337
|
function FwNavLogo() {
|
|
403
|
-
var _a
|
|
338
|
+
var _a;
|
|
404
339
|
const settings = useSettings();
|
|
405
|
-
const logo =
|
|
406
|
-
|
|
340
|
+
const logo = typeof ((_a = settings == null ? void 0 : settings.theme) == null ? void 0 : _a.logo);
|
|
341
|
+
if (!logo) {
|
|
342
|
+
return null;
|
|
343
|
+
}
|
|
344
|
+
return /* @__PURE__ */ React5.createElement("a", { href: "/" }, /* @__PURE__ */ React5.createElement(FwLogo, null));
|
|
407
345
|
}
|
|
408
346
|
function FwNav({ kind }) {
|
|
409
|
-
var _a, _b
|
|
347
|
+
var _a, _b;
|
|
348
|
+
const matches = useMatches2();
|
|
410
349
|
const matchedSubnav = useMatchedSubNav();
|
|
411
|
-
const location = (0, import_react_router3.useLocation)();
|
|
412
350
|
const settings = useSettings();
|
|
413
|
-
const
|
|
414
|
-
const
|
|
415
|
-
|
|
416
|
-
|
|
351
|
+
const lastMatch = matches[matches.length - 1];
|
|
352
|
+
const header = ((_a = settings == null ? void 0 : settings.navigation) == null ? void 0 : _a.header) || [];
|
|
353
|
+
const active = header.find((item) => {
|
|
354
|
+
if (matchedSubnav) {
|
|
355
|
+
return pageLink(item.page || "") === pageLink(matchedSubnav == null ? void 0 : matchedSubnav.route);
|
|
356
|
+
}
|
|
357
|
+
return pageLink(item.page || "") === (lastMatch == null ? void 0 : lastMatch.id);
|
|
358
|
+
});
|
|
359
|
+
function createHeader(item) {
|
|
360
|
+
return /* @__PURE__ */ React5.createElement(
|
|
361
|
+
Nav.Item,
|
|
362
|
+
{
|
|
363
|
+
key: (item.page || "") + item.page,
|
|
364
|
+
href: pageLink((item == null ? void 0 : item.page) || ""),
|
|
365
|
+
value: item.page || "",
|
|
366
|
+
as: $Link
|
|
367
|
+
},
|
|
368
|
+
item.title
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
const headerMap = header.reduce((acc, item) => {
|
|
372
|
+
const float = item.float || "default";
|
|
373
|
+
return {
|
|
374
|
+
...acc,
|
|
375
|
+
[float]: [...acc[float] || [], createHeader(item)]
|
|
376
|
+
};
|
|
377
|
+
}, {});
|
|
378
|
+
const rightHeaderExists = ((_b = headerMap["right"]) == null ? void 0 : _b.length) > 0;
|
|
379
|
+
return /* @__PURE__ */ React5.createElement(
|
|
380
|
+
Nav,
|
|
417
381
|
{
|
|
418
|
-
value: (active == null ? void 0 : active.
|
|
382
|
+
value: (active == null ? void 0 : active.page) || "",
|
|
419
383
|
kind,
|
|
420
|
-
logo: /* @__PURE__ */
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
},
|
|
424
|
-
(_c = (_b = settings == null ? void 0 : settings.structure) == null ? void 0 : _b.header) == null ? void 0 : _c.map((item, index) => {
|
|
425
|
-
return /* @__PURE__ */ import_react6.default.createElement(
|
|
426
|
-
import_ui4.Nav.Item,
|
|
384
|
+
logo: /* @__PURE__ */ React5.createElement(FwNavLogo, null),
|
|
385
|
+
rightSurface: /* @__PURE__ */ React5.createElement(React5.Fragment, null, rightHeaderExists ? /* @__PURE__ */ React5.createElement(
|
|
386
|
+
Nav.Tab,
|
|
427
387
|
{
|
|
428
|
-
|
|
429
|
-
href: (item == null ? void 0 : item.url) || "",
|
|
430
|
-
value: item.url
|
|
388
|
+
value: (active == null ? void 0 : active.page) || ""
|
|
431
389
|
},
|
|
432
|
-
|
|
433
|
-
)
|
|
434
|
-
}
|
|
390
|
+
headerMap["right"]
|
|
391
|
+
) : null, /* @__PURE__ */ React5.createElement(Surface, { target: "nav.right" /* NavRight */ }), /* @__PURE__ */ React5.createElement(ColorSchemeButton, null))
|
|
392
|
+
},
|
|
393
|
+
headerMap["default"]
|
|
435
394
|
);
|
|
436
395
|
}
|
|
437
396
|
function FwSubNav() {
|
|
438
397
|
const matchedSubnav = useMatchedSubNav();
|
|
439
|
-
const location = (
|
|
398
|
+
const location = useLocation2();
|
|
399
|
+
const pathname = trailingSlash(location.pathname);
|
|
440
400
|
if (!matchedSubnav) {
|
|
441
401
|
return null;
|
|
442
402
|
}
|
|
443
|
-
const active = matchedSubnav == null ? void 0 : matchedSubnav.
|
|
444
|
-
|
|
445
|
-
|
|
403
|
+
const active = matchedSubnav == null ? void 0 : matchedSubnav.pages.findLast((item) => {
|
|
404
|
+
return pathname.startsWith(pageLink(item.page || ""));
|
|
405
|
+
});
|
|
406
|
+
return /* @__PURE__ */ React5.createElement(
|
|
407
|
+
SubNav,
|
|
446
408
|
{
|
|
447
|
-
title: (matchedSubnav == null ? void 0 : matchedSubnav.
|
|
448
|
-
value: (active == null ? void 0 : active.
|
|
409
|
+
title: (matchedSubnav == null ? void 0 : matchedSubnav.title) || "",
|
|
410
|
+
value: (active == null ? void 0 : active.page) || "",
|
|
449
411
|
onChange: () => {
|
|
450
412
|
}
|
|
451
413
|
},
|
|
452
|
-
matchedSubnav == null ? void 0 : matchedSubnav.
|
|
453
|
-
return /* @__PURE__ */
|
|
414
|
+
matchedSubnav == null ? void 0 : matchedSubnav.pages.map((item, index) => {
|
|
415
|
+
return /* @__PURE__ */ React5.createElement(
|
|
416
|
+
SubNav.Item,
|
|
417
|
+
{
|
|
418
|
+
value: item.page || "",
|
|
419
|
+
href: pageLink(item.page || ""),
|
|
420
|
+
as: $Link
|
|
421
|
+
},
|
|
422
|
+
item.title
|
|
423
|
+
);
|
|
454
424
|
})
|
|
455
425
|
);
|
|
456
426
|
}
|
|
457
|
-
function recursiveSearch2(items, href, levels = []) {
|
|
458
|
-
for (let i = 0; i < items.length; i++) {
|
|
459
|
-
const item = items[i];
|
|
460
|
-
if (item.href === href) {
|
|
461
|
-
return [...levels, i];
|
|
462
|
-
}
|
|
463
|
-
if (item.items) {
|
|
464
|
-
const result = recursiveSearch2(item.items, href, [...levels, i]);
|
|
465
|
-
if (result) {
|
|
466
|
-
return result;
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
return null;
|
|
471
|
-
}
|
|
472
427
|
function FwSidebarGroups(props) {
|
|
473
428
|
var _a, _b, _c;
|
|
429
|
+
const location = useLocation2();
|
|
430
|
+
const pathname = trailingSlash(location.pathname);
|
|
474
431
|
const groups = useSidebarGroups();
|
|
475
432
|
const settings = useSettings();
|
|
476
|
-
const footerItems = (_c = (_b = (_a = settings.
|
|
477
|
-
|
|
478
|
-
if (typeof anchor.icon === "string") {
|
|
479
|
-
switch (anchor.icon) {
|
|
480
|
-
case "icon-cookbook": {
|
|
481
|
-
icon = /* @__PURE__ */ import_react6.default.createElement(IconCookbook, null);
|
|
482
|
-
break;
|
|
483
|
-
}
|
|
484
|
-
case "icon-community": {
|
|
485
|
-
icon = /* @__PURE__ */ import_react6.default.createElement(IconCommunity, null);
|
|
486
|
-
break;
|
|
487
|
-
}
|
|
488
|
-
case "icon-marketplace": {
|
|
489
|
-
icon = /* @__PURE__ */ import_react6.default.createElement(IconMarketplace, null);
|
|
490
|
-
break;
|
|
491
|
-
}
|
|
492
|
-
case "icon-sdk": {
|
|
493
|
-
icon = /* @__PURE__ */ import_react6.default.createElement(IconSDK, null);
|
|
494
|
-
break;
|
|
495
|
-
}
|
|
496
|
-
default: {
|
|
497
|
-
icon = null;
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
} else {
|
|
501
|
-
icon = (0, import_react6.isValidElement)(anchor.icon) ? anchor.icon : manualHydration(anchor.icon);
|
|
502
|
-
}
|
|
503
|
-
return /* @__PURE__ */ import_react6.default.createElement(import_ui3.UISidebar.FooterItem, { href: anchor.url, icon }, anchor.name);
|
|
433
|
+
const footerItems = (_c = (_b = (_a = settings.navigation) == null ? void 0 : _a.anchors) == null ? void 0 : _b.bottom) == null ? void 0 : _c.map((anchor) => {
|
|
434
|
+
return /* @__PURE__ */ React5.createElement(UISidebar2.FooterItem, { href: anchor.url, icon: /* @__PURE__ */ React5.createElement(Icon2, { name: anchor.icon || "" }) }, anchor.name);
|
|
504
435
|
});
|
|
505
|
-
const location = (0, import_react_router3.useLocation)();
|
|
506
436
|
const initialActiveItems = [];
|
|
507
|
-
groups.forEach((group) => {
|
|
508
|
-
const activeLevels =
|
|
509
|
-
activeLevels.reduce((acc, index) => {
|
|
510
|
-
initialActiveItems.push(
|
|
437
|
+
groups.forEach((group, groupIndex) => {
|
|
438
|
+
const activeLevels = recursiveSearch(group.items, pathname) || [];
|
|
439
|
+
activeLevels.reduce((acc, index, level) => {
|
|
440
|
+
initialActiveItems.push({
|
|
441
|
+
...acc[index],
|
|
442
|
+
groupIndex,
|
|
443
|
+
level,
|
|
444
|
+
itemIndex: index
|
|
445
|
+
});
|
|
511
446
|
acc[index].active = true;
|
|
512
447
|
return acc[index].items;
|
|
513
448
|
}, group.items);
|
|
514
449
|
return group;
|
|
515
450
|
});
|
|
516
|
-
return /* @__PURE__ */
|
|
451
|
+
return /* @__PURE__ */ React5.createElement(
|
|
517
452
|
FwSidebarGroupContext,
|
|
518
453
|
{
|
|
519
|
-
onePathBehaviour: props.onePathBehaviour,
|
|
520
|
-
clientSideRouting: props.clientSideRouting,
|
|
521
454
|
initialActiveItems
|
|
522
455
|
},
|
|
523
|
-
/* @__PURE__ */
|
|
456
|
+
/* @__PURE__ */ React5.createElement(UISidebar2, { footerItems: footerItems && footerItems }, /* @__PURE__ */ React5.createElement(Surface, { target: "sidebar.top" /* SidebarTop */ }), groups == null ? void 0 : groups.map((group, index) => /* @__PURE__ */ React5.createElement(
|
|
524
457
|
FwSidebarItemGroup,
|
|
525
458
|
{
|
|
526
459
|
key: index + group.group,
|
|
527
|
-
...group
|
|
460
|
+
...group,
|
|
461
|
+
groupIndex: index
|
|
528
462
|
}
|
|
529
463
|
)))
|
|
530
464
|
);
|
|
531
465
|
}
|
|
532
466
|
function FwToc() {
|
|
533
467
|
var _a;
|
|
468
|
+
const metadata = useMetadata();
|
|
469
|
+
const settings = useSettings();
|
|
534
470
|
const toc = useToC();
|
|
535
471
|
if (!toc) {
|
|
536
472
|
return null;
|
|
537
473
|
}
|
|
538
|
-
const
|
|
539
|
-
const
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
flatten(item.children);
|
|
549
|
-
});
|
|
474
|
+
const maxDepth = (metadata == null ? void 0 : metadata.maxTocDepth) || ((_a = settings == null ? void 0 : settings.theme) == null ? void 0 : _a.maxTocDepth) || 2;
|
|
475
|
+
const renderTocItems = (items, uiDepth = 0) => {
|
|
476
|
+
return items.map((item) => /* @__PURE__ */ React5.createElement(React5.Fragment, { key: item.id }, /* @__PURE__ */ React5.createElement(
|
|
477
|
+
Toc.Item,
|
|
478
|
+
{
|
|
479
|
+
id: item.id,
|
|
480
|
+
depth: uiDepth
|
|
481
|
+
},
|
|
482
|
+
item.value
|
|
483
|
+
), item.children && item.children.length > 0 && renderTocItems(item.children, uiDepth + 1)));
|
|
550
484
|
};
|
|
551
|
-
|
|
552
|
-
const tocFinal = flatToc.filter((item) => item.depth === 2);
|
|
553
|
-
const location = (0, import_react_router3.useLocation)();
|
|
554
|
-
const defaultValue = location.hash ? location.hash.replace("#", "") : (_a = tocFinal[0]) == null ? void 0 : _a.value;
|
|
555
|
-
return /* @__PURE__ */ import_react6.default.createElement(import_ui3.Toc, { defaultValue }, tocFinal.map((item, index) => /* @__PURE__ */ import_react6.default.createElement(
|
|
556
|
-
import_ui3.Toc.Item,
|
|
557
|
-
{
|
|
558
|
-
key: index + item.value + item.depth,
|
|
559
|
-
value: item.value
|
|
560
|
-
},
|
|
561
|
-
item.value
|
|
562
|
-
)));
|
|
485
|
+
return /* @__PURE__ */ React5.createElement(Toc, { maxDepth }, renderTocItems(toc));
|
|
563
486
|
}
|
|
564
487
|
function FwBreadcrumbs() {
|
|
565
|
-
const
|
|
566
|
-
|
|
567
|
-
|
|
488
|
+
const fwBreadcrumbs = useBreadcrumbs();
|
|
489
|
+
const breadcrumbs = fwBreadcrumbs == null ? void 0 : fwBreadcrumbs.map((item) => ({
|
|
490
|
+
title: item.title,
|
|
491
|
+
href: item.href
|
|
492
|
+
}));
|
|
493
|
+
return /* @__PURE__ */ React5.createElement(
|
|
494
|
+
Breadcrumbs,
|
|
568
495
|
{
|
|
569
496
|
items: breadcrumbs || []
|
|
570
497
|
}
|
|
571
498
|
);
|
|
572
499
|
}
|
|
573
500
|
function FwNavLinks() {
|
|
574
|
-
var _a, _b;
|
|
575
501
|
const navlinks = useNavLinks();
|
|
576
|
-
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") {
|
|
577
|
-
return null;
|
|
578
|
-
}
|
|
579
502
|
if ((navlinks == null ? void 0 : navlinks.prev) || (navlinks == null ? void 0 : navlinks.next)) {
|
|
580
|
-
return /* @__PURE__ */
|
|
581
|
-
|
|
503
|
+
return /* @__PURE__ */ React5.createElement(
|
|
504
|
+
NavLinks,
|
|
582
505
|
{
|
|
583
506
|
prev: navlinks.prev,
|
|
584
|
-
next: navlinks.next
|
|
507
|
+
next: navlinks.next,
|
|
508
|
+
as: $Link
|
|
585
509
|
}
|
|
586
510
|
);
|
|
587
511
|
}
|
|
588
512
|
return null;
|
|
589
513
|
}
|
|
590
|
-
function
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
},
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
clipRule: "evenodd"
|
|
605
|
-
}
|
|
606
|
-
)
|
|
607
|
-
);
|
|
514
|
+
function FwLogo() {
|
|
515
|
+
var _a, _b, _c, _d, _e, _f;
|
|
516
|
+
const settings = useSettings();
|
|
517
|
+
const [colorScheme] = useColorScheme();
|
|
518
|
+
if (typeof ((_a = settings == null ? void 0 : settings.theme) == null ? void 0 : _a.logo) === "string") {
|
|
519
|
+
return /* @__PURE__ */ React5.createElement("img", { src: (_b = settings == null ? void 0 : settings.theme) == null ? void 0 : _b.logo });
|
|
520
|
+
}
|
|
521
|
+
if (isValidElement((_c = settings == null ? void 0 : settings.theme) == null ? void 0 : _c.logo)) {
|
|
522
|
+
return /* @__PURE__ */ React5.createElement("a", { href: "/" }, (_d = settings == null ? void 0 : settings.theme) == null ? void 0 : _d.logo);
|
|
523
|
+
}
|
|
524
|
+
if (typeof ((_e = settings == null ? void 0 : settings.theme) == null ? void 0 : _e.logo) === "object" && colorScheme) {
|
|
525
|
+
return /* @__PURE__ */ React5.createElement("img", { src: (_f = settings == null ? void 0 : settings.theme) == null ? void 0 : _f.logo[colorScheme] });
|
|
526
|
+
}
|
|
527
|
+
return null;
|
|
608
528
|
}
|
|
609
|
-
function
|
|
610
|
-
return /* @__PURE__ */
|
|
611
|
-
"svg",
|
|
612
|
-
{
|
|
613
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
614
|
-
fill: "currentColor",
|
|
615
|
-
viewBox: "0 0 24 24",
|
|
616
|
-
width: "1em",
|
|
617
|
-
height: "1em"
|
|
618
|
-
},
|
|
619
|
-
/* @__PURE__ */ import_react6.default.createElement(
|
|
620
|
-
"path",
|
|
621
|
-
{
|
|
622
|
-
fillRule: "evenodd",
|
|
623
|
-
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",
|
|
624
|
-
clipRule: "evenodd"
|
|
625
|
-
}
|
|
626
|
-
)
|
|
627
|
-
);
|
|
529
|
+
function FwLink({ children, ...rest }) {
|
|
530
|
+
return /* @__PURE__ */ React5.createElement(Anchor, { ...rest, as: $Link }, children);
|
|
628
531
|
}
|
|
629
|
-
function
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
532
|
+
function FwCopyPage() {
|
|
533
|
+
const [isCopied, setIsCopied] = useState3(false);
|
|
534
|
+
const rawPage = useRawPage();
|
|
535
|
+
const handleCopy = () => {
|
|
536
|
+
navigator.clipboard.writeText(rawPage || "");
|
|
537
|
+
setIsCopied(true);
|
|
538
|
+
setTimeout(() => setIsCopied(false), 2e3);
|
|
539
|
+
};
|
|
540
|
+
return /* @__PURE__ */ React5.createElement(Button2, { icon: isCopied ? /* @__PURE__ */ React5.createElement(Icon2, { name: "check", size: 12 }) : /* @__PURE__ */ React5.createElement(Icon2, { name: "copy", size: 12 }), onClick: handleCopy }, "Copy page");
|
|
541
|
+
}
|
|
542
|
+
function $Link({ children, ...rest }) {
|
|
543
|
+
let to = "";
|
|
544
|
+
if (rest.href) {
|
|
545
|
+
try {
|
|
546
|
+
new URL(rest.href);
|
|
547
|
+
to = rest.href;
|
|
548
|
+
} catch (error) {
|
|
549
|
+
if (rest.href.startsWith("/")) {
|
|
550
|
+
const url = new URL(`https://example.com${rest.href}`);
|
|
551
|
+
to = {
|
|
552
|
+
pathname: url.pathname,
|
|
553
|
+
search: url.search,
|
|
554
|
+
hash: url.hash
|
|
555
|
+
};
|
|
556
|
+
} else {
|
|
557
|
+
return /* @__PURE__ */ React5.createElement(Anchor, { as: "button", onClick: () => {
|
|
558
|
+
const url = new URL(window.location.href);
|
|
559
|
+
const currentParams = url.searchParams;
|
|
560
|
+
new URLSearchParams(rest.href).forEach((value, key) => {
|
|
561
|
+
currentParams.set(key, value);
|
|
562
|
+
});
|
|
563
|
+
url.search = currentParams.toString();
|
|
564
|
+
history.replaceState(null, "", url);
|
|
565
|
+
} }, children);
|
|
659
566
|
}
|
|
660
|
-
|
|
661
|
-
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
return /* @__PURE__ */ React5.createElement(Link, { ...rest, to }, children);
|
|
662
570
|
}
|
|
663
|
-
function
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
{
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
"path",
|
|
674
|
-
{
|
|
675
|
-
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",
|
|
676
|
-
fill: "currentColor",
|
|
677
|
-
fillRule: "evenodd",
|
|
678
|
-
clipRule: "evenodd"
|
|
571
|
+
function recursiveSearch(items, href, levels = []) {
|
|
572
|
+
for (let i = 0; i < items.length; i++) {
|
|
573
|
+
const item = items[i];
|
|
574
|
+
if (item.href === href) {
|
|
575
|
+
return [...levels, i];
|
|
576
|
+
}
|
|
577
|
+
if (item.items) {
|
|
578
|
+
const result = recursiveSearch(item.items, href, [...levels, i]);
|
|
579
|
+
if (result) {
|
|
580
|
+
return result;
|
|
679
581
|
}
|
|
680
|
-
|
|
681
|
-
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
return null;
|
|
585
|
+
}
|
|
586
|
+
function trailingSlash(path) {
|
|
587
|
+
return path.endsWith("/") ? path.slice(0, -1) : path;
|
|
682
588
|
}
|
|
683
|
-
|
|
684
|
-
|
|
589
|
+
function pageLink(page) {
|
|
590
|
+
return page.startsWith("/") ? page : `/${page}`;
|
|
591
|
+
}
|
|
592
|
+
export {
|
|
685
593
|
Framework,
|
|
594
|
+
FrameworkPage,
|
|
686
595
|
FwBreadcrumbs,
|
|
596
|
+
FwCopyPage,
|
|
597
|
+
FwLink,
|
|
598
|
+
FwLogo,
|
|
687
599
|
FwNav,
|
|
688
600
|
FwNavLinks,
|
|
689
601
|
FwSidebarGroups,
|
|
690
602
|
FwSubNav,
|
|
691
603
|
FwToc,
|
|
692
|
-
|
|
693
|
-
|
|
604
|
+
Surface,
|
|
605
|
+
SurfaceContext,
|
|
606
|
+
useComponents,
|
|
607
|
+
useContentComponent,
|
|
608
|
+
useMatchedSubNav,
|
|
609
|
+
useMetadata,
|
|
610
|
+
useSettings
|
|
611
|
+
};
|
|
694
612
|
//# sourceMappingURL=react.js.map
|