@riebeckite/plugin-docs 0.0.34 → 0.0.36

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/README.md CHANGED
@@ -71,11 +71,14 @@ fields you want to override and leave the rest of the vault untouched.
71
71
 
72
72
  The plugin provides React-like JSX components for site integration:
73
73
 
74
- - `<DocsSidebar items={...} currentPermalink? label? />` renders
75
- `details.rb-docs-sidebar-details` with `nav.rb-docs-sidebar`
74
+ - `<DocsSidebar items={...} currentPermalink? label? />` converts the Docs tree
75
+ to `SidebarNavigation` and renders `nav.rb-docs-sidebar`. Outside an article
76
+ context it resolves the current entry from the site path.
76
77
  - `<DocsPrevNext previous? next? />` renders `nav.rb-docs-prev-next`
77
78
 
78
- The `initDocsSidebar` client keeps the sidebar collapsible.
79
+ The `initDocsSidebar` client enables independent group disclosure and sidebar
80
+ filtering. It reuses the navigation plugin renderer; the navigation plugin never
81
+ depends on Docs.
79
82
 
80
83
  ## l10n and publishing
81
84
 
package/README_ja.md CHANGED
@@ -68,10 +68,12 @@ sidebar:
68
68
 
69
69
  プラグインは、サイトへ組み込むための React 風の JSX コンポーネントを提供します。
70
70
 
71
- - `<DocsSidebar items={...} currentPermalink? label? />` は `details.rb-docs-sidebar-details` と `nav.rb-docs-sidebar` を描画
71
+ - `<DocsSidebar items={...} currentPermalink? label? />` は Docs のツリーを
72
+ `SidebarNavigation` に変換し、`nav.rb-docs-sidebar` を描画します。記事コンテキストの外では、サイトのパスから現在のエントリを解決します。
72
73
  - `<DocsPrevNext previous? next? />` は `nav.rb-docs-prev-next` を描画
73
74
 
74
- クライアント側の `initDocsSidebar` を使うと、サイドバーを折りたためます。
75
+ クライアント側の `initDocsSidebar` はグループごとの開閉とサイドバーの絞り込みを有効にします。
76
+ 描画器は Navigation Plugin と共有しますが、Navigation Plugin は Docs に依存しません。
75
77
 
76
78
  ## l10n と公開の境界
77
79
 
package/dist/client.js CHANGED
@@ -1,30 +1,7 @@
1
1
  // src/docs-sidebar.client.ts
2
- var COLLAPSIBLE_PROPERTY = "--rb-docs-sidebar-collapsible";
2
+ import { initSidebarNavigation } from "@riebeckite/plugin-navigation/client";
3
3
  function initDocsSidebar(context = {}) {
4
- const root = context.root ?? document;
5
- const details = Array.from(
6
- root.querySelectorAll("[data-docs-sidebar-details]")
7
- );
8
- const first = details[0];
9
- if (!first) return;
10
- let collapsible = isCollapsible(first);
11
- const apply = (value) => {
12
- for (const element of details) {
13
- element.open = !value;
14
- }
15
- };
16
- apply(collapsible);
17
- const sync = () => {
18
- const next = isCollapsible(first);
19
- if (next === collapsible) return;
20
- collapsible = next;
21
- apply(next);
22
- };
23
- window.addEventListener("resize", sync, { passive: true });
24
- return () => window.removeEventListener("resize", sync);
25
- }
26
- function isCollapsible(element) {
27
- return getComputedStyle(element).getPropertyValue(COLLAPSIBLE_PROPERTY).trim() !== "0";
4
+ return initSidebarNavigation(context);
28
5
  }
29
6
  export {
30
7
  initDocsSidebar
@@ -1,4 +1,7 @@
1
1
  // components/docs-sidebar.tsx
2
+ import {
3
+ SidebarNavigation
4
+ } from "@riebeckite/plugin-navigation";
2
5
  import { useArticleContext, useSiteContext } from "@riebeckite/ui";
3
6
  import { html } from "hono/html";
4
7
 
@@ -160,102 +163,59 @@ var getDocsNavigation = ({ view, entries, entrySlug, options }) => {
160
163
  };
161
164
 
162
165
  // components/docs-sidebar.tsx
163
- import { jsx, jsxs } from "hono/jsx/jsx-runtime";
166
+ import { jsx } from "hono/jsx/jsx-runtime";
164
167
  var DocsSidebar = (async (props) => {
165
168
  const site = useSiteContext();
166
169
  const article = useArticleContext();
167
170
  const options = findDocsOptions(site?.config.plugins);
168
- const items = props.items ?? (site && article?.entry && options ? await getDocsNavigation({
171
+ const requestedPermalink = props.currentPermalink ?? article?.entry?.permalink ?? site?.path;
172
+ const currentEntry = article?.entry ?? findEntryByPermalink(site?.view, requestedPermalink);
173
+ const currentPermalink = currentEntry?.permalink ?? requestedPermalink;
174
+ const items = props.items ?? (site && currentEntry && options ? await getDocsNavigation({
169
175
  view: site.view,
170
176
  entries: site.manifest.discoverableEntries,
171
- entrySlug: article.entry.slug,
177
+ entrySlug: currentEntry.slug,
172
178
  options
173
179
  }) : []);
174
- const currentPermalink = props.currentPermalink ?? article?.entry?.permalink;
175
- const label = props.label ?? options?.sidebar?.label ?? "Docs navigation";
176
180
  if (items.length === 0) return html``;
177
- const permalink = currentPermalink ?? "";
178
- const sidebar = /* @__PURE__ */ jsxs("details", { class: "rb-docs-sidebar-details", "data-docs-sidebar-details": true, open: true, children: [
179
- /* @__PURE__ */ jsx("summary", { class: "rb-docs-sidebar-summary", children: label }),
180
- /* @__PURE__ */ jsx("nav", { class: "rb-docs-sidebar", "aria-label": label, "data-docs-sidebar": true, children: /* @__PURE__ */ jsx(
181
- DocsSidebarItems,
182
- {
183
- items,
184
- currentPermalink: permalink,
185
- level: 1
186
- }
187
- ) })
188
- ] });
189
- return props.placement === "article-rail" ? /* @__PURE__ */ jsx("aside", { class: "rb-docs-sidebar-rail", children: sidebar }) : sidebar;
190
- });
191
- function DocsSidebarItems({
192
- items,
193
- currentPermalink,
194
- level
195
- }) {
196
- return /* @__PURE__ */ jsx(
197
- "ul",
198
- {
199
- class: `rb-docs-sidebar__list rb-docs-sidebar__list--level-${level}`,
200
- "data-docs-level": String(level),
201
- children: items.map((item) => /* @__PURE__ */ jsx(
202
- DocsSidebarItem,
203
- {
204
- item,
205
- currentPermalink,
206
- level
207
- },
208
- item.slug ?? item.title
209
- ))
210
- }
211
- );
212
- }
213
- function DocsSidebarItem({
214
- item,
215
- currentPermalink,
216
- level
217
- }) {
218
- const isCurrent = item.href === currentPermalink;
219
- const isCurrentBranch = item.children.some(
220
- (child) => containsPermalink(child, currentPermalink)
221
- );
222
- const collapsed = item.collapsed === true && !isCurrent && !isCurrentBranch;
223
- return /* @__PURE__ */ jsxs(
224
- "li",
181
+ const label = props.label ?? options?.sidebar?.label ?? "Docs navigation";
182
+ const sidebar = /* @__PURE__ */ jsx(
183
+ SidebarNavigation,
225
184
  {
226
- class: `rb-docs-sidebar__item rb-docs-sidebar__item--level-${level}`,
227
- "data-docs-level": String(level),
228
- "data-docs-collapsed": item.children.length > 0 ? String(collapsed) : void 0,
229
- children: [
230
- item.href ? /* @__PURE__ */ jsx(
231
- "a",
232
- {
233
- class: "rb-docs-sidebar__link",
234
- href: item.href,
235
- "data-docs-link": true,
236
- "aria-current": isCurrent ? "page" : void 0,
237
- children: item.title
238
- }
239
- ) : /* @__PURE__ */ jsx("span", { class: "rb-docs-sidebar__section", "data-docs-section": true, children: item.title }),
240
- item.children.length > 0 ? /* @__PURE__ */ jsx(
241
- DocsSidebarItems,
242
- {
243
- items: item.children,
244
- currentPermalink,
245
- level: level + 1
246
- }
247
- ) : null
248
- ]
185
+ items: toNavigationItems(items),
186
+ path: currentPermalink,
187
+ label,
188
+ searchable: true,
189
+ nativeDetails: true,
190
+ autoExpandActive: false,
191
+ stateKey: options ? `docs:${options.root}:${site?.language ?? ""}` : void 0,
192
+ class: "rb-docs-sidebar"
249
193
  }
250
194
  );
251
- }
252
- function containsPermalink(item, currentPermalink) {
253
- return item.href === currentPermalink || item.children.some((child) => containsPermalink(child, currentPermalink));
195
+ return props.placement === "article-rail" ? /* @__PURE__ */ jsx("aside", { class: "rb-docs-sidebar-rail", children: sidebar }) : sidebar;
196
+ });
197
+ function toNavigationItems(items) {
198
+ return items.map((item) => ({
199
+ label: item.title,
200
+ ...item.href ? { href: item.href } : {},
201
+ collapsed: item.collapsed ?? true,
202
+ children: toNavigationItems(item.children)
203
+ }));
254
204
  }
255
205
  var docs_sidebar_default = DocsSidebar;
256
206
  function findDocsOptions(plugins) {
257
207
  return plugins?.find((plugin) => plugin.name.startsWith("docs:"))?.options;
258
208
  }
209
+ function findEntryByPermalink(view, permalink) {
210
+ if (!permalink) return void 0;
211
+ const path = normalizePermalink(permalink);
212
+ return view?.routableEntries.find(
213
+ (entry) => normalizePermalink(entry.permalink) === path
214
+ );
215
+ }
216
+ function normalizePermalink(permalink) {
217
+ return permalink.replace(/\/+$/, "") || "/";
218
+ }
259
219
  export {
260
220
  docs_sidebar_default as default
261
221
  };
package/dist/index.js CHANGED
@@ -244,135 +244,73 @@ function findDocsOptions(plugins) {
244
244
  }
245
245
 
246
246
  // components/docs-sidebar.tsx
247
+ import {
248
+ SidebarNavigation
249
+ } from "@riebeckite/plugin-navigation";
247
250
  import { useArticleContext as useArticleContext2, useSiteContext as useSiteContext2 } from "@riebeckite/ui";
248
251
  import { html as html2 } from "hono/html";
249
- import { jsx as jsx2, jsxs as jsxs2 } from "hono/jsx/jsx-runtime";
252
+ import { jsx as jsx2 } from "hono/jsx/jsx-runtime";
250
253
  var DocsSidebar = (async (props) => {
251
254
  const site = useSiteContext2();
252
255
  const article = useArticleContext2();
253
256
  const options = findDocsOptions2(site?.config.plugins);
254
- const items = props.items ?? (site && article?.entry && options ? await getDocsNavigation({
257
+ const requestedPermalink = props.currentPermalink ?? article?.entry?.permalink ?? site?.path;
258
+ const currentEntry = article?.entry ?? findEntryByPermalink(site?.view, requestedPermalink);
259
+ const currentPermalink = currentEntry?.permalink ?? requestedPermalink;
260
+ const items = props.items ?? (site && currentEntry && options ? await getDocsNavigation({
255
261
  view: site.view,
256
262
  entries: site.manifest.discoverableEntries,
257
- entrySlug: article.entry.slug,
263
+ entrySlug: currentEntry.slug,
258
264
  options
259
265
  }) : []);
260
- const currentPermalink = props.currentPermalink ?? article?.entry?.permalink;
261
- const label = props.label ?? options?.sidebar?.label ?? "Docs navigation";
262
266
  if (items.length === 0) return html2``;
263
- const permalink = currentPermalink ?? "";
264
- const sidebar = /* @__PURE__ */ jsxs2("details", { class: "rb-docs-sidebar-details", "data-docs-sidebar-details": true, open: true, children: [
265
- /* @__PURE__ */ jsx2("summary", { class: "rb-docs-sidebar-summary", children: label }),
266
- /* @__PURE__ */ jsx2("nav", { class: "rb-docs-sidebar", "aria-label": label, "data-docs-sidebar": true, children: /* @__PURE__ */ jsx2(
267
- DocsSidebarItems,
268
- {
269
- items,
270
- currentPermalink: permalink,
271
- level: 1
272
- }
273
- ) })
274
- ] });
275
- return props.placement === "article-rail" ? /* @__PURE__ */ jsx2("aside", { class: "rb-docs-sidebar-rail", children: sidebar }) : sidebar;
276
- });
277
- function DocsSidebarItems({
278
- items,
279
- currentPermalink,
280
- level
281
- }) {
282
- return /* @__PURE__ */ jsx2(
283
- "ul",
284
- {
285
- class: `rb-docs-sidebar__list rb-docs-sidebar__list--level-${level}`,
286
- "data-docs-level": String(level),
287
- children: items.map((item) => /* @__PURE__ */ jsx2(
288
- DocsSidebarItem,
289
- {
290
- item,
291
- currentPermalink,
292
- level
293
- },
294
- item.slug ?? item.title
295
- ))
296
- }
297
- );
298
- }
299
- function DocsSidebarItem({
300
- item,
301
- currentPermalink,
302
- level
303
- }) {
304
- const isCurrent = item.href === currentPermalink;
305
- const isCurrentBranch = item.children.some(
306
- (child) => containsPermalink(child, currentPermalink)
307
- );
308
- const collapsed = item.collapsed === true && !isCurrent && !isCurrentBranch;
309
- return /* @__PURE__ */ jsxs2(
310
- "li",
267
+ const label = props.label ?? options?.sidebar?.label ?? "Docs navigation";
268
+ const sidebar = /* @__PURE__ */ jsx2(
269
+ SidebarNavigation,
311
270
  {
312
- class: `rb-docs-sidebar__item rb-docs-sidebar__item--level-${level}`,
313
- "data-docs-level": String(level),
314
- "data-docs-collapsed": item.children.length > 0 ? String(collapsed) : void 0,
315
- children: [
316
- item.href ? /* @__PURE__ */ jsx2(
317
- "a",
318
- {
319
- class: "rb-docs-sidebar__link",
320
- href: item.href,
321
- "data-docs-link": true,
322
- "aria-current": isCurrent ? "page" : void 0,
323
- children: item.title
324
- }
325
- ) : /* @__PURE__ */ jsx2("span", { class: "rb-docs-sidebar__section", "data-docs-section": true, children: item.title }),
326
- item.children.length > 0 ? /* @__PURE__ */ jsx2(
327
- DocsSidebarItems,
328
- {
329
- items: item.children,
330
- currentPermalink,
331
- level: level + 1
332
- }
333
- ) : null
334
- ]
271
+ items: toNavigationItems(items),
272
+ path: currentPermalink,
273
+ label,
274
+ searchable: true,
275
+ nativeDetails: true,
276
+ autoExpandActive: false,
277
+ stateKey: options ? `docs:${options.root}:${site?.language ?? ""}` : void 0,
278
+ class: "rb-docs-sidebar"
335
279
  }
336
280
  );
337
- }
338
- function containsPermalink(item, currentPermalink) {
339
- return item.href === currentPermalink || item.children.some((child) => containsPermalink(child, currentPermalink));
281
+ return props.placement === "article-rail" ? /* @__PURE__ */ jsx2("aside", { class: "rb-docs-sidebar-rail", children: sidebar }) : sidebar;
282
+ });
283
+ function toNavigationItems(items) {
284
+ return items.map((item) => ({
285
+ label: item.title,
286
+ ...item.href ? { href: item.href } : {},
287
+ collapsed: item.collapsed ?? true,
288
+ children: toNavigationItems(item.children)
289
+ }));
340
290
  }
341
291
  var docs_sidebar_default = DocsSidebar;
342
292
  function findDocsOptions2(plugins) {
343
293
  return plugins?.find((plugin) => plugin.name.startsWith("docs:"))?.options;
344
294
  }
295
+ function findEntryByPermalink(view, permalink) {
296
+ if (!permalink) return void 0;
297
+ const path = normalizePermalink(permalink);
298
+ return view?.routableEntries.find(
299
+ (entry) => normalizePermalink(entry.permalink) === path
300
+ );
301
+ }
302
+ function normalizePermalink(permalink) {
303
+ return permalink.replace(/\/+$/, "") || "/";
304
+ }
345
305
 
346
306
  // src/docs-sidebar.client.ts
347
- var COLLAPSIBLE_PROPERTY = "--rb-docs-sidebar-collapsible";
307
+ import { initSidebarNavigation } from "@riebeckite/plugin-navigation/client";
348
308
  function initDocsSidebar(context = {}) {
349
- const root = context.root ?? document;
350
- const details = Array.from(
351
- root.querySelectorAll("[data-docs-sidebar-details]")
352
- );
353
- const first = details[0];
354
- if (!first) return;
355
- let collapsible = isCollapsible(first);
356
- const apply = (value) => {
357
- for (const element of details) {
358
- element.open = !value;
359
- }
360
- };
361
- apply(collapsible);
362
- const sync = () => {
363
- const next = isCollapsible(first);
364
- if (next === collapsible) return;
365
- collapsible = next;
366
- apply(next);
367
- };
368
- window.addEventListener("resize", sync, { passive: true });
369
- return () => window.removeEventListener("resize", sync);
370
- }
371
- function isCollapsible(element) {
372
- return getComputedStyle(element).getPropertyValue(COLLAPSIBLE_PROPERTY).trim() !== "0";
309
+ return initSidebarNavigation(context);
373
310
  }
374
311
 
375
312
  // src/render.ts
313
+ import { escapeHtml } from "@riebeckite/core";
376
314
  function renderDocsSidebar(context) {
377
315
  if (context.items.length === 0) return "";
378
316
  const label = escapeAttribute(context.label);
@@ -393,15 +331,15 @@ function renderItems(items, currentPermalink, level) {
393
331
  function renderItem(item, currentPermalink, level) {
394
332
  const isCurrent = item.href === currentPermalink;
395
333
  const isCurrentBranch = item.children.some(
396
- (child) => containsPermalink2(child, currentPermalink)
334
+ (child) => containsPermalink(child, currentPermalink)
397
335
  );
398
336
  const children = item.children.length > 0 ? renderItems(item.children, currentPermalink, level + 1) : "";
399
337
  const collapsed = item.collapsed === true && !isCurrent && !isCurrentBranch;
400
338
  const state = item.children.length > 0 ? ` data-docs-collapsed="${collapsed ? "true" : "false"}"` : "";
401
339
  return `<li class="rb-docs-sidebar__item rb-docs-sidebar__item--level-${level}" data-docs-level="${level}"${state}>${renderItemLabel(item, isCurrent)}${children}</li>`;
402
340
  }
403
- function containsPermalink2(item, currentPermalink) {
404
- return item.href === currentPermalink || item.children.some((child) => containsPermalink2(child, currentPermalink));
341
+ function containsPermalink(item, currentPermalink) {
342
+ return item.href === currentPermalink || item.children.some((child) => containsPermalink(child, currentPermalink));
405
343
  }
406
344
  function renderItemLabel(item, isCurrent) {
407
345
  const current = isCurrent ? ' aria-current="page"' : "";
@@ -432,9 +370,6 @@ function prevNextLabels(language) {
432
370
  if (language === "ja") return PREV_NEXT_LABELS.ja;
433
371
  return PREV_NEXT_LABELS.en;
434
372
  }
435
- function escapeHtml(value) {
436
- return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
437
- }
438
373
  function escapeAttribute(value) {
439
374
  return escapeHtml(value);
440
375
  }
@@ -458,7 +393,7 @@ function docs(options) {
458
393
  "@riebeckite/plugin-docs/client",
459
394
  "initDocsSidebar",
460
395
  void 0,
461
- void 0,
396
+ "app",
462
397
  "context"
463
398
  )
464
399
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-docs",
3
- "version": "0.0.34",
3
+ "version": "0.0.36",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -27,12 +27,13 @@
27
27
  "./style.css": "./style.css"
28
28
  },
29
29
  "dependencies": {
30
- "@riebeckite/core": "0.0.34",
31
- "@riebeckite/ui": "0.0.34",
30
+ "@riebeckite/core": "0.0.36",
31
+ "@riebeckite/plugin-navigation": "0.0.36",
32
+ "@riebeckite/ui": "0.0.36",
32
33
  "hono": "^4.12.25"
33
34
  },
34
35
  "devDependencies": {
35
- "@riebeckite/test": "0.0.34",
36
+ "@riebeckite/test": "0.0.36",
36
37
  "tsx": "^4.22.4"
37
38
  },
38
39
  "publishConfig": {
package/style.css CHANGED
@@ -1,7 +1,3 @@
1
- .rb-docs-sidebar-details {
2
- --rb-docs-sidebar-collapsible: 1;
3
- }
4
-
5
1
  .rb-docs-sidebar-rail {
6
2
  display: none;
7
3
  }
@@ -14,81 +10,6 @@
14
10
  }
15
11
  }
16
12
 
17
- @media (min-width: 88rem) {
18
- :is(:root, .rb-theme-root)[data-rb-layout="article"] .rb-docs-sidebar-rail {
19
- display: block;
20
- grid-column: 1;
21
- grid-row: 1;
22
- position: sticky;
23
- top: var(--rb-docs-rail-top);
24
- align-self: start;
25
- width: var(--rb-layout-sidebar);
26
- max-height: var(--rb-docs-rail-max-block-size);
27
- margin-block: 0;
28
- margin-inline-start: calc(
29
- -1 *
30
- var(--rb-layout-sidebar) -
31
- var(--rb-layout-gap)
32
- );
33
- overflow: auto;
34
- padding-block: 0;
35
- padding-inline-end: 1rem;
36
- border-inline-end: 1px solid
37
- color-mix(in oklab, currentColor 18%, transparent);
38
- }
39
- }
40
-
41
- .rb-docs-sidebar-details > .rb-docs-sidebar-summary {
42
- cursor: pointer;
43
- font-size: 0.95rem;
44
- }
45
-
46
- @media (min-width: 88rem) {
47
- .rb-docs-sidebar-details {
48
- --rb-docs-sidebar-collapsible: 0;
49
- }
50
-
51
- .rb-docs-sidebar-details > .rb-docs-sidebar-summary {
52
- display: none;
53
- }
54
- }
55
-
56
- .rb-docs-sidebar {
57
- font-size: 0.95rem;
58
- }
59
-
60
- .rb-docs-sidebar__list {
61
- list-style: none;
62
- margin: 0;
63
- padding: 0;
64
- }
65
-
66
- .rb-docs-sidebar__list--level-2,
67
- .rb-docs-sidebar__list--level-3,
68
- .rb-docs-sidebar__list--level-4 {
69
- margin-block-start: 0.25rem;
70
- padding-inline-start: 1rem;
71
- }
72
-
73
- .rb-docs-sidebar__item + .rb-docs-sidebar__item {
74
- margin-block-start: 0.25rem;
75
- }
76
-
77
- .rb-docs-sidebar__item[data-docs-collapsed="true"] > .rb-docs-sidebar__list {
78
- display: none;
79
- }
80
-
81
- .rb-docs-sidebar__link,
82
- .rb-docs-sidebar__section {
83
- display: block;
84
- color: inherit;
85
- text-decoration: none;
86
- }
87
-
88
- .rb-docs-sidebar__link[aria-current="page"] {
89
- font-weight: 700;
90
- }
91
-
92
13
  .rb-docs-prev-next {
93
14
  display: flex;
94
15
  flex-wrap: wrap;