@xyd-js/framework 0.1.0-xyd.7 → 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.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/dist/Sidebar-CdavG0uc.d.ts +23 -0
  3. package/dist/hydration.d.ts +9 -3
  4. package/dist/hydration.js +189 -191
  5. package/dist/hydration.js.map +1 -1
  6. package/dist/index.d.ts +22 -4
  7. package/dist/index.js +34 -15
  8. package/dist/index.js.map +1 -1
  9. package/dist/react.d.ts +49 -9
  10. package/dist/react.js +446 -528
  11. package/dist/react.js.map +1 -1
  12. package/package.json +19 -16
  13. package/dist/hydration.d.mts +0 -11
  14. package/dist/hydration.mjs +0 -245
  15. package/dist/hydration.mjs.map +0 -1
  16. package/dist/index.d.mts +0 -6
  17. package/dist/index.mjs +0 -1
  18. package/dist/index.mjs.map +0 -1
  19. package/dist/react.d.mts +0 -32
  20. package/dist/react.mjs +0 -651
  21. package/dist/react.mjs.map +0 -1
  22. package/dist/sidebar-Dwf54qYp.d.mts +0 -15
  23. package/dist/sidebar-Dwf54qYp.d.ts +0 -15
  24. package/packages/hydration/README.md +0 -3
  25. package/packages/hydration/index.ts +0 -3
  26. package/packages/hydration/settings-to-props.ts +0 -325
  27. package/packages/react/README.md +0 -3
  28. package/packages/react/components/index.tsx +0 -337
  29. package/packages/react/components/sidebar/index.ts +0 -3
  30. package/packages/react/components/sidebar/sidebar-group.tsx +0 -240
  31. package/packages/react/components/sidebar/sidebar.tsx +0 -127
  32. package/packages/react/contexts/framework.tsx +0 -78
  33. package/packages/react/contexts/index.ts +0 -2
  34. package/packages/react/contexts/ui.tsx +0 -6
  35. package/packages/react/hooks/index.ts +0 -3
  36. package/packages/react/hooks/useMatchedNav.tsx +0 -29
  37. package/packages/react/index.ts +0 -12
  38. package/packages/react/utils/manualHydration.ts +0 -25
  39. package/packages/theme/context.tsx +0 -19
  40. package/packages/theme/index.ts +0 -0
  41. package/postcss.config.cjs +0 -5
  42. package/src/index.ts +0 -1
  43. package/src/types.ts +0 -5
  44. package/tsconfig.json +0 -45
  45. package/tsup.config.ts +0 -28
package/dist/react.js CHANGED
@@ -1,694 +1,612 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
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/index.ts
30
- var react_exports = {};
31
- __export(react_exports, {
32
- Framework: () => Framework,
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
- module.exports = __toCommonJS(react_exports);
42
-
43
- // packages/react/components/index.tsx
44
- var import_react6 = __toESM(require("react"));
45
- var import_react_router3 = require("react-router");
46
- var import_ui3 = require("@xyd-js/ui");
47
- var import_writer2 = require("@xyd-js/components/writer");
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
- var import_react = __toESM(require("react"));
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
- sidebarGroups: []
48
+ metadata: {
49
+ title: ""
50
+ },
51
+ sidebarGroups: [],
52
+ setMetadata: () => {
53
+ },
54
+ components: {}
54
55
  };
55
- var FrameworkContext = (0, import_react.createContext)(framework);
56
+ var FrameworkContext = createContext2(framework);
56
57
  function Framework(props) {
57
- return /* @__PURE__ */ import_react.default.createElement(FrameworkContext.Provider, { value: {
58
- settings: props.settings,
59
- sidebarGroups: props.sidebarGroups,
60
- toc: props.toc,
61
- breadcrumbs: props.breadcrumbs,
62
- navlinks: props.navlinks
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 = (0, import_react.useContext)(FrameworkContext);
101
+ const ctx = useContext2(FrameworkContext);
67
102
  return ctx.sidebarGroups;
68
103
  }
69
104
  function useSettings() {
70
- const ctx = (0, import_react.useContext)(FrameworkContext);
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 = (0, import_react.useContext)(FrameworkContext);
75
- return ctx.toc;
117
+ const ctx = useContext2(FrameworkPageContext);
118
+ const toc = ctx.toc || [];
119
+ return toc;
76
120
  }
77
121
  function useBreadcrumbs() {
78
- const ctx = (0, import_react.useContext)(FrameworkContext);
122
+ const ctx = useContext2(FrameworkPageContext);
79
123
  return ctx.breadcrumbs;
80
124
  }
81
125
  function useNavLinks() {
82
- const ctx = (0, import_react.useContext)(FrameworkContext);
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/sidebar/sidebar-group.tsx
87
- var import_react3 = __toESM(require("react"));
88
- var import_react_router = require("react-router");
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/sidebar/sidebar-group.tsx
99
- var groupContext = (0, import_react3.createContext)({
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
- onePathBehaviour,
108
- clientSideRouting,
109
- initialActiveItems
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 (0, import_react3.useContext)(groupContext);
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 groups = useSidebarGroups();
180
- const [weakSet] = (0, import_react3.useState)(() => new Set(initialActiveItems.map((item) => stringify(item))));
181
- const [, setForceUpdate] = (0, import_react3.useState)(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
- const addItem = (item) => {
198
- weakSet.add(stringify(item));
199
- forceUpdate();
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
- function useOnePathBehaviour(initialActiveItems) {
220
- const [weakSet] = (0, import_react3.useState)(() => new Set(initialActiveItems.map((item) => stringify(item))));
221
- const [lastLevel, setLastLevel] = (0, import_react3.useState)(false);
222
- const [, setForceUpdate] = (0, import_react3.useState)(0);
223
- const forceUpdate = () => setForceUpdate((prev) => prev + 1);
224
- const addItem = (item) => {
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
- const hasItem = (item) => {
233
- return weakSet.has(stringify(item));
234
- };
235
- const clear = () => {
236
- weakSet.clear();
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
- return (item) => [
240
- hasItem(item),
241
- () => {
242
- setLastLevel(item.level);
243
- if (hasItem(item) && item.level == 0) {
244
- setLastLevel(false);
245
- clear();
246
- return;
247
- }
248
- if (hasItem(item)) {
249
- setLastLevel(false);
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 scrollToDataSlug(event, item) {
264
- event.preventDefault();
265
- const dataSlug = document.querySelector(`[data-slug="${item.href}"]`);
266
- if (dataSlug) {
267
- dataSlug.scrollIntoView({ block: "start", inline: "nearest" });
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/sidebar/sidebar.tsx
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
- return /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null, /* @__PURE__ */ import_react4.default.createElement(import_ui2.UISidebar.ItemHeader, null, props.group), props.items.map((item, index) => /* @__PURE__ */ import_react4.default.createElement(
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
- level: 0
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, onClick } = useGroup();
241
+ var _a, _b, _c, _d;
242
+ const { active } = useGroup();
317
243
  const [isActive, setActive] = active(props);
318
- let Title;
319
- if (typeof props.title === "object" && "code" in props.title) {
320
- const code = props.title.code;
321
- Title = () => mdxExport(
322
- // TODO: in the future better mechanism + support props + better components (provider?) - similar to codehik
323
- code.replace("() => ", ""),
324
- components
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
- return /* @__PURE__ */ import_react4.default.createElement(
330
- import_ui2.UISidebar.Item,
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: !!((_a = props.items) == null ? void 0 : _a.length),
266
+ button: nested,
333
267
  href: props.href,
334
- active: isActive,
335
- onClick: () => {
336
- setActive();
337
- }
268
+ active: isActiveItem,
269
+ isParentActive,
270
+ onClick: handleClick,
271
+ icon
338
272
  },
339
- /* @__PURE__ */ import_react4.default.createElement(Title, null),
340
- ((_b = props.items) == null ? void 0 : _b.length) && /* @__PURE__ */ import_react4.default.createElement(import_ui2.UISidebar.SubTree, { isOpen: isActive }, /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null, (_c = props.items) == null ? void 0 : _c.map((item, index) => /* @__PURE__ */ import_react4.default.createElement(
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
- level: (props.level || 0) + 1
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
- var import_react_router2 = require("react-router");
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 location = (0, import_react_router2.useLocation)();
391
- 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) => {
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 normalizeHref(location.pathname).startsWith(normalizeHref(((_a2 = item.sub) == null ? void 0 : _a2.match) || ""));
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.sub || null;
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, _b, _c;
338
+ var _a;
404
339
  const settings = useSettings();
405
- const logo = (0, import_react6.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);
406
- return /* @__PURE__ */ import_react6.default.createElement("a", { href: "/" }, logo);
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, _c;
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 headers = matchedSubnav ? matchedSubnav == null ? void 0 : matchedSubnav.items : (_a = settings == null ? void 0 : settings.structure) == null ? void 0 : _a.header;
414
- const active = headers == null ? void 0 : headers.find((item) => location.pathname.startsWith(item.url || ""));
415
- return /* @__PURE__ */ import_react6.default.createElement(
416
- import_ui4.Nav,
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.url) || "",
382
+ value: (active == null ? void 0 : active.page) || "",
419
383
  kind,
420
- logo: /* @__PURE__ */ import_react6.default.createElement(FwNavLogo, null),
421
- onChange: () => {
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
- key: index + (item.url || "") + item.name,
429
- href: (item == null ? void 0 : item.url) || "",
430
- value: item.url
388
+ value: (active == null ? void 0 : active.page) || ""
431
389
  },
432
- item.name
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 = (0, import_react_router3.useLocation)();
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.items.findLast((item) => location.pathname.startsWith(item.url || ""));
444
- return /* @__PURE__ */ import_react6.default.createElement(
445
- import_ui3.SubNav,
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.name) || "",
448
- value: (active == null ? void 0 : active.url) || "",
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.items.map((item, index) => {
453
- return /* @__PURE__ */ import_react6.default.createElement(import_ui3.SubNav.Item, { value: item.url || "", href: item.url }, item.name);
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.structure) == null ? void 0 : _a.anchors) == null ? void 0 : _b.bottom) == null ? void 0 : _c.map((anchor) => {
477
- let icon;
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 = recursiveSearch2(group.items, location.pathname) || [];
509
- activeLevels.reduce((acc, index) => {
510
- initialActiveItems.push(acc[index]);
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__ */ import_react6.default.createElement(
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__ */ import_react6.default.createElement(import_ui3.UISidebar, { footerItems: footerItems && footerItems }, groups == null ? void 0 : groups.map((group, index) => /* @__PURE__ */ import_react6.default.createElement(
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 flatToc = [];
539
- const flatten = (toc2) => {
540
- if (!toc2) {
541
- return;
542
- }
543
- toc2.forEach((item) => {
544
- flatToc.push({
545
- depth: item.depth,
546
- value: item.value
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
- flatten(toc);
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 breadcrumbs = useBreadcrumbs();
566
- return /* @__PURE__ */ import_react6.default.createElement(
567
- import_writer2.Breadcrumbs,
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__ */ import_react6.default.createElement(
581
- import_writer2.NavLinks,
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 IconCookbook() {
591
- return /* @__PURE__ */ import_react6.default.createElement(
592
- "svg",
593
- {
594
- xmlns: "http://www.w3.org/2000/svg",
595
- viewBox: "0 0 24 24",
596
- width: "1em",
597
- height: "1em"
598
- },
599
- /* @__PURE__ */ import_react6.default.createElement(
600
- "path",
601
- {
602
- fillRule: "evenodd",
603
- 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",
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 IconCommunity() {
610
- return /* @__PURE__ */ import_react6.default.createElement(
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 IconMarketplace() {
630
- return /* @__PURE__ */ import_react6.default.createElement(
631
- "svg",
632
- {
633
- xmlns: "http://www.w3.org/2000/svg",
634
- viewBox: "0 0 24 24",
635
- fill: "none",
636
- width: "1em",
637
- height: "1em"
638
- },
639
- /* @__PURE__ */ import_react6.default.createElement(
640
- "path",
641
- {
642
- "fill-rule": "evenodd",
643
- "clip-rule": "evenodd",
644
- 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"
645
- }
646
- ),
647
- /* @__PURE__ */ import_react6.default.createElement(
648
- "path",
649
- {
650
- "fill-rule": "evenodd",
651
- "clip-rule": "evenodd",
652
- 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"
653
- }
654
- ),
655
- /* @__PURE__ */ import_react6.default.createElement(
656
- "path",
657
- {
658
- 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"
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 IconSDK() {
664
- return /* @__PURE__ */ import_react6.default.createElement(
665
- "svg",
666
- {
667
- viewBox: "0 0 15 15",
668
- xmlns: "http://www.w3.org/2000/svg",
669
- width: "1em",
670
- height: "1em"
671
- },
672
- /* @__PURE__ */ import_react6.default.createElement(
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
- // Annotate the CommonJS export names for ESM import in node:
684
- 0 && (module.exports = {
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
- useMatchedSubNav
693
- });
604
+ Surface,
605
+ SurfaceContext,
606
+ useComponents,
607
+ useContentComponent,
608
+ useMatchedSubNav,
609
+ useMetadata,
610
+ useSettings
611
+ };
694
612
  //# sourceMappingURL=react.js.map