@cyguin/docs 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +27 -0
- package/LICENSE +7 -0
- package/README.md +152 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +438 -0
- package/dist/index.mjs +438 -0
- package/dist/next.d.mts +10 -0
- package/dist/next.d.ts +10 -0
- package/dist/next.js +53 -0
- package/dist/next.mjs +53 -0
- package/dist/styles.css +11 -0
- package/dist/types-0oOQLVHA.d.mts +52 -0
- package/dist/types-0oOQLVHA.d.ts +52 -0
- package/package.json +46 -0
- package/src/adapters/index.ts +1 -0
- package/src/adapters/sqlite.ts +95 -0
- package/src/app/admin/docs/[...route]/route.ts +31 -0
- package/src/app/api/docs/[...cyguin]/route.ts +10 -0
- package/src/components/DocsWidget.tsx +521 -0
- package/src/components/index.ts +2 -0
- package/src/handlers/admin.ts +89 -0
- package/src/handlers/route.ts +70 -0
- package/src/index.ts +5 -0
- package/src/next.ts +3 -0
- package/src/styles.css +11 -0
- package/src/types.ts +62 -0
- package/tsconfig.json +18 -0
- package/tsup.config.ts +12 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
name: Publish to npm
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- 'v*'
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
permissions:
|
|
12
|
+
contents: read
|
|
13
|
+
id-token: write
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- uses: actions/setup-node@v4
|
|
17
|
+
with:
|
|
18
|
+
node-version: '20'
|
|
19
|
+
registry-url: 'https://registry.npmjs.org'
|
|
20
|
+
- name: Install dependencies
|
|
21
|
+
run: npm install --legacy-peer-deps
|
|
22
|
+
- name: Build
|
|
23
|
+
run: npm run build
|
|
24
|
+
- name: Publish
|
|
25
|
+
env:
|
|
26
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
27
|
+
run: npm publish --provenance --access public
|
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2026 cyguin.com
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# @cyguin/docs
|
|
2
|
+
|
|
3
|
+
Embeddable help and documentation widget for Next.js — renders searchable, markdown-backed docs as a modal or sidebar overlay.
|
|
4
|
+
|
|
5
|
+
## Quickstart
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @cyguin/docs
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### 1. Add the widget to your app
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
// app/layout.tsx (or any page)
|
|
15
|
+
import { DocsWidget } from '@cyguin/docs';
|
|
16
|
+
import '@cyguin/docs/styles.css';
|
|
17
|
+
|
|
18
|
+
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
19
|
+
return (
|
|
20
|
+
<html>
|
|
21
|
+
<body>
|
|
22
|
+
{children}
|
|
23
|
+
<DocsWidget apiUrl="/api/docs" mode="modal" triggerLabel="Help" />
|
|
24
|
+
</body>
|
|
25
|
+
</html>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### 2. Wire up the API route
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
// app/api/docs/[...cyguin]/route.ts
|
|
34
|
+
import { createDocsHandler } from '@cyguin/docs/next';
|
|
35
|
+
import { createSQLiteAdapter } from '@cyguin/docs/adapters/sqlite';
|
|
36
|
+
|
|
37
|
+
const adapter = createSQLiteAdapter({ path: './docs.db' });
|
|
38
|
+
export const GET = createDocsHandler({ adapter });
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### 3. Seed some articles
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { createDocsHandler } from '@cyguin/docs/next';
|
|
45
|
+
import { createSQLiteAdapter } from '@cyguin/docs/adapters/sqlite';
|
|
46
|
+
|
|
47
|
+
const adapter = createSQLiteAdapter({ path: './docs.db' });
|
|
48
|
+
const handler = createDocsHandler({ adapter });
|
|
49
|
+
|
|
50
|
+
// POST /admin/docs — create article
|
|
51
|
+
await handler.request(new Request('http://localhost/admin/docs', {
|
|
52
|
+
method: 'POST',
|
|
53
|
+
headers: { 'x-secret': 'your-secret', 'Content-Type': 'application/json' },
|
|
54
|
+
body: JSON.stringify({
|
|
55
|
+
title: 'Getting Started',
|
|
56
|
+
body_md: '# Getting Started\n\nWelcome to **My App**!',
|
|
57
|
+
section: 'Introduction',
|
|
58
|
+
article_order: 1,
|
|
59
|
+
}),
|
|
60
|
+
}));
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Modes
|
|
64
|
+
|
|
65
|
+
### Modal (default)
|
|
66
|
+
Floating corner button opens a centered overlay with backdrop. Click backdrop or press `Esc` to close.
|
|
67
|
+
|
|
68
|
+
```tsx
|
|
69
|
+
<DocsWidget mode="modal" triggerLabel="Help" />
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Sidebar
|
|
73
|
+
Panel slides in from the right edge. Good for persistent help panels.
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
<DocsWidget mode="sidebar" triggerLabel="Docs" />
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Props
|
|
80
|
+
|
|
81
|
+
| Prop | Type | Default | Description |
|
|
82
|
+
|------|------|---------|-------------|
|
|
83
|
+
| `apiUrl` | `string` | `"/api/docs"` | Endpoint that returns article list |
|
|
84
|
+
| `mode` | `"modal" \| "sidebar"` | `"modal"` | Widget display mode |
|
|
85
|
+
| `triggerLabel` | `string` | `"Help"` | Label shown on the floating trigger button |
|
|
86
|
+
| `defaultOpen` | `boolean` | `false` | Open on mount |
|
|
87
|
+
| `className` | `string` | `""` | CSS class on root element |
|
|
88
|
+
|
|
89
|
+
## API Contract
|
|
90
|
+
|
|
91
|
+
The `apiUrl` must return a JSON array of articles:
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
[
|
|
95
|
+
{
|
|
96
|
+
"id": "1",
|
|
97
|
+
"title": "Getting Started",
|
|
98
|
+
"body_md": "# Getting Started\n\nWelcome...",
|
|
99
|
+
"section": "Introduction",
|
|
100
|
+
"article_order": 1,
|
|
101
|
+
"published_at": 1710000000
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
`GET /api/docs` from `@cyguin/docs/next` returns this shape automatically.
|
|
107
|
+
|
|
108
|
+
## Theming
|
|
109
|
+
|
|
110
|
+
All colors use `--cyguin-*` CSS custom properties. Override on your root element or `:root`:
|
|
111
|
+
|
|
112
|
+
```css
|
|
113
|
+
:root {
|
|
114
|
+
--cyguin-bg: #ffffff;
|
|
115
|
+
--cyguin-bg-subtle: #f5f5f5;
|
|
116
|
+
--cyguin-border: #e5e5e5;
|
|
117
|
+
--cyguin-border-focus: #f5a800;
|
|
118
|
+
--cyguin-fg: #0a0a0a;
|
|
119
|
+
--cyguin-fg-muted: #888888;
|
|
120
|
+
--cyguin-accent: #f5a800;
|
|
121
|
+
--cyguin-accent-dark: #c47f00;
|
|
122
|
+
--cyguin-accent-fg: #0a0a0a;
|
|
123
|
+
--cyguin-radius: 6px;
|
|
124
|
+
--cyguin-shadow: 0 1px 4px rgba(0,0,0,0.08);
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Keyboard Navigation
|
|
129
|
+
|
|
130
|
+
| Key | Action |
|
|
131
|
+
|-----|--------|
|
|
132
|
+
| `/` | Focus search input |
|
|
133
|
+
| `Esc` | Close widget |
|
|
134
|
+
| `↑` / `↓` | Navigate article list |
|
|
135
|
+
| `Enter` | Open selected article |
|
|
136
|
+
|
|
137
|
+
## Exports
|
|
138
|
+
|
|
139
|
+
### `@cyguin/docs`
|
|
140
|
+
| Export | Type | Description |
|
|
141
|
+
|--------|------|-------------|
|
|
142
|
+
| `DocsWidget` | Component | Searchable docs widget (modal/sidebar) |
|
|
143
|
+
| `DocsWidgetProps` | Interface | Component props |
|
|
144
|
+
| `DocArticle` | Interface | Article shape |
|
|
145
|
+
| `defaultCssVars` | Object | Default CSS variable values |
|
|
146
|
+
|
|
147
|
+
### `@cyguin/docs/next`
|
|
148
|
+
| Export | Type | Description |
|
|
149
|
+
|--------|------|-------------|
|
|
150
|
+
| `createDocsHandler` | Function | Factory for Next.js API route handler |
|
|
151
|
+
| `DocsAdapter` | Interface | Storage adapter contract |
|
|
152
|
+
| `DocArticle` | Interface | Article shape |
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { D as DocsWidgetProps } from './types-0oOQLVHA.mjs';
|
|
2
|
+
export { a as DocArticle, d as defaultCssVars } from './types-0oOQLVHA.mjs';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
declare function DocsWidget({ apiUrl, mode, triggerLabel, defaultOpen, className, }: DocsWidgetProps): react_jsx_runtime.JSX.Element;
|
|
6
|
+
|
|
7
|
+
export { DocsWidget, DocsWidgetProps };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { D as DocsWidgetProps } from './types-0oOQLVHA.js';
|
|
2
|
+
export { a as DocArticle, d as defaultCssVars } from './types-0oOQLVHA.js';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
declare function DocsWidget({ apiUrl, mode, triggerLabel, defaultOpen, className, }: DocsWidgetProps): react_jsx_runtime.JSX.Element;
|
|
6
|
+
|
|
7
|
+
export { DocsWidget, DocsWidgetProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/components/DocsWidget.tsx
|
|
2
|
+
var _react = require('react');
|
|
3
|
+
var _marked = require('marked');
|
|
4
|
+
var _jsxruntime = require('react/jsx-runtime');
|
|
5
|
+
_marked.marked.setOptions({ breaks: true, gfm: true });
|
|
6
|
+
function HelpIcon() {
|
|
7
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
8
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "circle", { cx: "12", cy: "12", r: "10" }),
|
|
9
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3" }),
|
|
10
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M12 17h.01" })
|
|
11
|
+
] });
|
|
12
|
+
}
|
|
13
|
+
function SearchIcon() {
|
|
14
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
15
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "circle", { cx: "11", cy: "11", r: "8" }),
|
|
16
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "m21 21-4.35-4.35" })
|
|
17
|
+
] });
|
|
18
|
+
}
|
|
19
|
+
function CloseIcon() {
|
|
20
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
21
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M18 6 6 18" }),
|
|
22
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "m6 6 12 12" })
|
|
23
|
+
] });
|
|
24
|
+
}
|
|
25
|
+
function ChevronRightIcon({ expanded }) {
|
|
26
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
27
|
+
"svg",
|
|
28
|
+
{
|
|
29
|
+
width: "14",
|
|
30
|
+
height: "14",
|
|
31
|
+
viewBox: "0 0 24 24",
|
|
32
|
+
fill: "none",
|
|
33
|
+
stroke: "currentColor",
|
|
34
|
+
strokeWidth: "2",
|
|
35
|
+
strokeLinecap: "round",
|
|
36
|
+
strokeLinejoin: "round",
|
|
37
|
+
style: { transform: expanded ? "rotate(90deg)" : "rotate(0deg)", transition: "transform 0.15s" },
|
|
38
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "m9 18 6-6-6-6" })
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
function BackIcon() {
|
|
43
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "m15 18-6-6 6-6" }) });
|
|
44
|
+
}
|
|
45
|
+
function renderMarkdown(md) {
|
|
46
|
+
return _marked.marked.parse(md);
|
|
47
|
+
}
|
|
48
|
+
function groupBySection(articles) {
|
|
49
|
+
const map = /* @__PURE__ */ new Map();
|
|
50
|
+
for (const article of articles) {
|
|
51
|
+
const list = _nullishCoalesce(map.get(article.section), () => ( []));
|
|
52
|
+
list.push(article);
|
|
53
|
+
map.set(article.section, list);
|
|
54
|
+
}
|
|
55
|
+
return Array.from(map.entries()).map(([section, arts]) => ({ section, articles: arts.sort((a, b) => a.article_order - b.article_order) })).sort((a, b) => a.section.localeCompare(b.section));
|
|
56
|
+
}
|
|
57
|
+
function DocsTrigger({ label, onClick }) {
|
|
58
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
59
|
+
"button",
|
|
60
|
+
{
|
|
61
|
+
onClick,
|
|
62
|
+
"aria-label": label,
|
|
63
|
+
style: {
|
|
64
|
+
position: "fixed",
|
|
65
|
+
bottom: "24px",
|
|
66
|
+
right: "24px",
|
|
67
|
+
zIndex: 9998,
|
|
68
|
+
width: "48px",
|
|
69
|
+
height: "48px",
|
|
70
|
+
borderRadius: "var(--cyguin-docs-radius)",
|
|
71
|
+
background: "var(--cyguin-docs-accent)",
|
|
72
|
+
color: "var(--cyguin-accent-fg, #0a0a0a)",
|
|
73
|
+
border: "none",
|
|
74
|
+
cursor: "pointer",
|
|
75
|
+
display: "flex",
|
|
76
|
+
alignItems: "center",
|
|
77
|
+
justifyContent: "center",
|
|
78
|
+
boxShadow: "var(--cyguin-docs-shadow)",
|
|
79
|
+
fontWeight: 600,
|
|
80
|
+
fontSize: "14px",
|
|
81
|
+
fontFamily: "var(--cyguin-docs-font)",
|
|
82
|
+
transition: "opacity 0.15s"
|
|
83
|
+
},
|
|
84
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, HelpIcon, {})
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
function DocsSearch({ value, onChange }) {
|
|
89
|
+
const ref = _react.useRef.call(void 0, null);
|
|
90
|
+
_react.useEffect.call(void 0, () => {
|
|
91
|
+
const handler = (e) => {
|
|
92
|
+
if (e.key === "/" && !e.ctrlKey && !e.metaKey) {
|
|
93
|
+
const active = document.activeElement;
|
|
94
|
+
const widget = document.getElementById("cyguin-docs-widget");
|
|
95
|
+
if (active && _optionalChain([widget, 'optionalAccess', _ => _.contains, 'call', _2 => _2(active)])) return;
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
_optionalChain([ref, 'access', _3 => _3.current, 'optionalAccess', _4 => _4.focus, 'call', _5 => _5()]);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
document.addEventListener("keydown", handler);
|
|
101
|
+
return () => document.removeEventListener("keydown", handler);
|
|
102
|
+
}, []);
|
|
103
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { style: { position: "relative", padding: "12px 12px 8px" }, children: [
|
|
104
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, SearchIcon, {}),
|
|
105
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
106
|
+
"input",
|
|
107
|
+
{
|
|
108
|
+
ref,
|
|
109
|
+
type: "text",
|
|
110
|
+
value,
|
|
111
|
+
onChange: (e) => onChange(e.target.value),
|
|
112
|
+
placeholder: "Search docs... (press / to focus)",
|
|
113
|
+
"aria-label": "Search documentation",
|
|
114
|
+
style: {
|
|
115
|
+
width: "100%",
|
|
116
|
+
padding: "8px 8px 8px 32px",
|
|
117
|
+
borderRadius: "var(--cyguin-docs-radius)",
|
|
118
|
+
border: "1px solid var(--cyguin-docs-border)",
|
|
119
|
+
background: "var(--cyguin-bg-subtle, #f5f5f5)",
|
|
120
|
+
color: "var(--cyguin-docs-text)",
|
|
121
|
+
fontSize: "14px",
|
|
122
|
+
fontFamily: "var(--cyguin-docs-font)",
|
|
123
|
+
boxSizing: "border-box",
|
|
124
|
+
outline: "none"
|
|
125
|
+
},
|
|
126
|
+
onFocus: (e) => {
|
|
127
|
+
e.currentTarget.style.borderColor = "var(--cyguin-border-focus, #f5a800)";
|
|
128
|
+
},
|
|
129
|
+
onBlur: (e) => {
|
|
130
|
+
e.currentTarget.style.borderColor = "var(--cyguin-docs-border)";
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
)
|
|
134
|
+
] });
|
|
135
|
+
}
|
|
136
|
+
function DocsNav({ groups, selectedId, selectedIndex, onSelectArticle, searchQuery }) {
|
|
137
|
+
const [expandedSections, setExpandedSections] = _react.useState.call(void 0, new Set(groups.map((g) => g.section)));
|
|
138
|
+
const navRef = _react.useRef.call(void 0, null);
|
|
139
|
+
const flatArticles = groups.flatMap((g) => g.articles);
|
|
140
|
+
const activeIndexRef = _react.useRef.call(void 0, -1);
|
|
141
|
+
_react.useEffect.call(void 0, () => {
|
|
142
|
+
activeIndexRef.current = selectedIndex;
|
|
143
|
+
}, [selectedIndex]);
|
|
144
|
+
_react.useEffect.call(void 0, () => {
|
|
145
|
+
const handler = (e) => {
|
|
146
|
+
if (e.key === "ArrowDown") {
|
|
147
|
+
e.preventDefault();
|
|
148
|
+
const next = Math.min(activeIndexRef.current + 1, flatArticles.length - 1);
|
|
149
|
+
onSelectArticle(flatArticles[next].id, next);
|
|
150
|
+
scrollToSelected(next);
|
|
151
|
+
} else if (e.key === "ArrowUp") {
|
|
152
|
+
e.preventDefault();
|
|
153
|
+
const prev = Math.max(activeIndexRef.current - 1, 0);
|
|
154
|
+
onSelectArticle(flatArticles[prev].id, prev);
|
|
155
|
+
scrollToSelected(prev);
|
|
156
|
+
} else if (e.key === "Enter" && selectedId) {
|
|
157
|
+
e.preventDefault();
|
|
158
|
+
const idx = flatArticles.findIndex((a) => a.id === selectedId);
|
|
159
|
+
if (idx !== -1) onSelectArticle(selectedId, idx);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
const widget = document.getElementById("cyguin-docs-widget");
|
|
163
|
+
_optionalChain([widget, 'optionalAccess', _6 => _6.addEventListener, 'call', _7 => _7("keydown", handler)]);
|
|
164
|
+
return () => _optionalChain([widget, 'optionalAccess', _8 => _8.removeEventListener, 'call', _9 => _9("keydown", handler)]);
|
|
165
|
+
}, [flatArticles, selectedId, onSelectArticle]);
|
|
166
|
+
function scrollToSelected(index) {
|
|
167
|
+
const buttons = _optionalChain([navRef, 'access', _10 => _10.current, 'optionalAccess', _11 => _11.querySelectorAll, 'call', _12 => _12("[data-article-btn]")]);
|
|
168
|
+
_optionalChain([buttons, 'optionalAccess', _13 => _13[index], 'optionalAccess', _14 => _14.scrollIntoView, 'call', _15 => _15({ block: "nearest" })]);
|
|
169
|
+
}
|
|
170
|
+
function toggleSection(section) {
|
|
171
|
+
setExpandedSections((prev) => {
|
|
172
|
+
const next = new Set(prev);
|
|
173
|
+
if (next.has(section)) next.delete(section);
|
|
174
|
+
else next.add(section);
|
|
175
|
+
return next;
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
let articleIdx = 0;
|
|
179
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { ref: navRef, style: { overflowY: "auto", flex: 1, borderRight: "1px solid var(--cyguin-docs-border)" }, children: [
|
|
180
|
+
groups.length === 0 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { style: { padding: "16px", color: "var(--cyguin-docs-muted)", fontSize: "13px", textAlign: "center", fontFamily: "var(--cyguin-docs-font)" }, children: searchQuery ? "No results found" : "No articles yet" }),
|
|
181
|
+
groups.map((group) => {
|
|
182
|
+
const isExpanded = expandedSections.has(group.section);
|
|
183
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { children: [
|
|
184
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
185
|
+
"button",
|
|
186
|
+
{
|
|
187
|
+
onClick: () => toggleSection(group.section),
|
|
188
|
+
style: {
|
|
189
|
+
width: "100%",
|
|
190
|
+
padding: "8px 12px",
|
|
191
|
+
background: "none",
|
|
192
|
+
border: "none",
|
|
193
|
+
cursor: "pointer",
|
|
194
|
+
display: "flex",
|
|
195
|
+
alignItems: "center",
|
|
196
|
+
gap: "6px",
|
|
197
|
+
color: "var(--cyguin-docs-text)",
|
|
198
|
+
fontSize: "12px",
|
|
199
|
+
fontWeight: 700,
|
|
200
|
+
fontFamily: "var(--cyguin-docs-font)",
|
|
201
|
+
textTransform: "uppercase",
|
|
202
|
+
letterSpacing: "0.05em"
|
|
203
|
+
},
|
|
204
|
+
children: [
|
|
205
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, ChevronRightIcon, { expanded: isExpanded }),
|
|
206
|
+
group.section
|
|
207
|
+
]
|
|
208
|
+
}
|
|
209
|
+
),
|
|
210
|
+
isExpanded && group.articles.map((article) => {
|
|
211
|
+
const idx = articleIdx++;
|
|
212
|
+
const isSelected = article.id === selectedId;
|
|
213
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
214
|
+
"button",
|
|
215
|
+
{
|
|
216
|
+
"data-article-btn": true,
|
|
217
|
+
onClick: () => onSelectArticle(article.id, idx),
|
|
218
|
+
style: {
|
|
219
|
+
width: "100%",
|
|
220
|
+
padding: "6px 12px 6px 28px",
|
|
221
|
+
background: isSelected ? "var(--cyguin-docs-accent)" : "none",
|
|
222
|
+
color: isSelected ? "var(--cyguin-accent-fg, #0a0a0a)" : "var(--cyguin-docs-text)",
|
|
223
|
+
border: "none",
|
|
224
|
+
cursor: "pointer",
|
|
225
|
+
textAlign: "left",
|
|
226
|
+
fontSize: "13px",
|
|
227
|
+
fontFamily: "var(--cyguin-docs-font)",
|
|
228
|
+
borderRadius: "var(--cyguin-docs-radius)",
|
|
229
|
+
margin: "1px 6px",
|
|
230
|
+
whiteSpace: "nowrap",
|
|
231
|
+
overflow: "hidden",
|
|
232
|
+
textOverflow: "ellipsis"
|
|
233
|
+
},
|
|
234
|
+
children: article.title
|
|
235
|
+
},
|
|
236
|
+
article.id
|
|
237
|
+
);
|
|
238
|
+
})
|
|
239
|
+
] }, group.section);
|
|
240
|
+
})
|
|
241
|
+
] });
|
|
242
|
+
}
|
|
243
|
+
function DocsArticleView({ article, onBack }) {
|
|
244
|
+
const contentRef = _react.useRef.call(void 0, null);
|
|
245
|
+
_react.useEffect.call(void 0, () => {
|
|
246
|
+
if (contentRef.current) {
|
|
247
|
+
contentRef.current.scrollTop = 0;
|
|
248
|
+
}
|
|
249
|
+
}, [_optionalChain([article, 'optionalAccess', _16 => _16.id])]);
|
|
250
|
+
if (!article) {
|
|
251
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { style: { flex: 2, display: "flex", alignItems: "center", justifyContent: "center", color: "var(--cyguin-docs-muted)", fontSize: "14px", fontFamily: "var(--cyguin-docs-font)" }, children: "Select an article to read" });
|
|
252
|
+
}
|
|
253
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { style: { flex: 2, display: "flex", flexDirection: "column", overflow: "hidden" }, children: [
|
|
254
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { style: { padding: "12px 16px", borderBottom: "1px solid var(--cyguin-docs-border)", display: "flex", alignItems: "center", gap: "8px" }, children: [
|
|
255
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
256
|
+
"button",
|
|
257
|
+
{
|
|
258
|
+
onClick: onBack,
|
|
259
|
+
"aria-label": "Back to list",
|
|
260
|
+
style: { background: "none", border: "none", cursor: "pointer", color: "var(--cyguin-docs-muted)", display: "flex", alignItems: "center", padding: "4px", borderRadius: "var(--cyguin-docs-radius)" },
|
|
261
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, BackIcon, {})
|
|
262
|
+
}
|
|
263
|
+
),
|
|
264
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { style: { fontSize: "15px", fontWeight: 700, color: "var(--cyguin-docs-text)", fontFamily: "var(--cyguin-docs-font)", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: article.title })
|
|
265
|
+
] }),
|
|
266
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
267
|
+
"div",
|
|
268
|
+
{
|
|
269
|
+
ref: contentRef,
|
|
270
|
+
style: { flex: 1, overflowY: "auto", padding: "20px 24px", fontSize: "14px", lineHeight: 1.7, color: "var(--cyguin-docs-text)", fontFamily: "var(--cyguin-docs-font)" },
|
|
271
|
+
dangerouslySetInnerHTML: { __html: renderMarkdown(article.body_md) }
|
|
272
|
+
}
|
|
273
|
+
)
|
|
274
|
+
] });
|
|
275
|
+
}
|
|
276
|
+
function DocsPanel({ mode, open, onClose, groups, selectedId, selectedIndex, searchQuery, onSearchChange, onSelectArticle, onBack, article }) {
|
|
277
|
+
const isMobile = typeof window !== "undefined" && window.innerWidth < 640;
|
|
278
|
+
const panelStyle = {
|
|
279
|
+
position: "fixed",
|
|
280
|
+
top: 0,
|
|
281
|
+
right: 0,
|
|
282
|
+
bottom: 0,
|
|
283
|
+
width: isMobile ? "100vw" : mode === "sidebar" ? "420px" : "680px",
|
|
284
|
+
maxWidth: "100vw",
|
|
285
|
+
background: "var(--cyguin-docs-bg)",
|
|
286
|
+
borderRadius: mode === "sidebar" || isMobile ? 0 : "var(--cyguin-docs-radius)",
|
|
287
|
+
boxShadow: mode === "modal" ? "var(--cyguin-docs-shadow)" : "none",
|
|
288
|
+
border: mode === "modal" && !isMobile ? "1px solid var(--cyguin-docs-border)" : "none",
|
|
289
|
+
display: "flex",
|
|
290
|
+
flexDirection: "column",
|
|
291
|
+
zIndex: 9999,
|
|
292
|
+
transform: open ? "translateX(0)" : "translateX(100%)",
|
|
293
|
+
transition: "transform 0.25s cubic-bezier(0.4, 0, 0.2, 1)",
|
|
294
|
+
fontFamily: "var(--cyguin-docs-font)"
|
|
295
|
+
};
|
|
296
|
+
if (!open) return null;
|
|
297
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
298
|
+
mode === "modal" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
299
|
+
"div",
|
|
300
|
+
{
|
|
301
|
+
onClick: onClose,
|
|
302
|
+
style: {
|
|
303
|
+
position: "fixed",
|
|
304
|
+
inset: 0,
|
|
305
|
+
background: `rgba(0, 0, 0, ${parseFloat(String(0.5))})`,
|
|
306
|
+
zIndex: 9998
|
|
307
|
+
},
|
|
308
|
+
"aria-hidden": "true"
|
|
309
|
+
}
|
|
310
|
+
),
|
|
311
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { id: "cyguin-docs-widget", role: "dialog", "aria-modal": mode === "modal", "aria-label": "Documentation", style: panelStyle, children: [
|
|
312
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { style: { display: "flex", alignItems: "center", padding: "12px 12px 8px", borderBottom: "1px solid var(--cyguin-docs-border)" }, children: [
|
|
313
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { style: { flex: 1, fontWeight: 700, fontSize: "15px", color: "var(--cyguin-docs-text)", fontFamily: "var(--cyguin-docs-font)" }, children: "Help Center" }),
|
|
314
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
315
|
+
"button",
|
|
316
|
+
{
|
|
317
|
+
onClick: onClose,
|
|
318
|
+
"aria-label": "Close",
|
|
319
|
+
style: { background: "none", border: "none", cursor: "pointer", color: "var(--cyguin-docs-muted)", display: "flex", alignItems: "center", padding: "4px", borderRadius: "var(--cyguin-docs-radius)" },
|
|
320
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, CloseIcon, {})
|
|
321
|
+
}
|
|
322
|
+
)
|
|
323
|
+
] }),
|
|
324
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, DocsSearch, { value: searchQuery, onChange: onSearchChange }),
|
|
325
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { style: { display: "flex", flex: 1, overflow: "hidden" }, children: [
|
|
326
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { style: { width: isMobile ? "100%" : "180px", display: "flex", flexDirection: "column" }, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
327
|
+
DocsNav,
|
|
328
|
+
{
|
|
329
|
+
groups,
|
|
330
|
+
selectedId,
|
|
331
|
+
selectedIndex,
|
|
332
|
+
onSelectArticle,
|
|
333
|
+
searchQuery
|
|
334
|
+
}
|
|
335
|
+
) }),
|
|
336
|
+
!isMobile && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, DocsArticleView, { article, onBack }),
|
|
337
|
+
isMobile && article && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, DocsArticleView, { article, onBack })
|
|
338
|
+
] })
|
|
339
|
+
] })
|
|
340
|
+
] });
|
|
341
|
+
}
|
|
342
|
+
function DocsWidget({
|
|
343
|
+
apiUrl = "/api/docs",
|
|
344
|
+
mode = "modal",
|
|
345
|
+
triggerLabel = "Help",
|
|
346
|
+
defaultOpen = false,
|
|
347
|
+
className = ""
|
|
348
|
+
}) {
|
|
349
|
+
const [open, setOpen] = _react.useState.call(void 0, defaultOpen);
|
|
350
|
+
const [articles, setArticles] = _react.useState.call(void 0, []);
|
|
351
|
+
const [loading, setLoading] = _react.useState.call(void 0, false);
|
|
352
|
+
const [searchQuery, setSearchQuery] = _react.useState.call(void 0, "");
|
|
353
|
+
const [selectedId, setSelectedId] = _react.useState.call(void 0, null);
|
|
354
|
+
const [selectedIndex, setSelectedIndex] = _react.useState.call(void 0, 0);
|
|
355
|
+
const [selectedArticle, setSelectedArticle] = _react.useState.call(void 0, null);
|
|
356
|
+
_react.useEffect.call(void 0, () => {
|
|
357
|
+
if (open && articles.length === 0) {
|
|
358
|
+
setLoading(true);
|
|
359
|
+
fetch(apiUrl).then((r) => r.json()).then((data) => {
|
|
360
|
+
const arts = Array.isArray(data) ? data : _nullishCoalesce(_nullishCoalesce(data.articles, () => ( data.data)), () => ( []));
|
|
361
|
+
setArticles(arts);
|
|
362
|
+
}).catch(() => setArticles([])).finally(() => setLoading(false));
|
|
363
|
+
}
|
|
364
|
+
}, [open, apiUrl, articles.length]);
|
|
365
|
+
_react.useEffect.call(void 0, () => {
|
|
366
|
+
if (selectedId) {
|
|
367
|
+
const art = articles.find((a) => a.id === selectedId);
|
|
368
|
+
setSelectedArticle(_nullishCoalesce(art, () => ( null)));
|
|
369
|
+
} else {
|
|
370
|
+
setSelectedArticle(null);
|
|
371
|
+
}
|
|
372
|
+
}, [selectedId, articles]);
|
|
373
|
+
_react.useEffect.call(void 0, () => {
|
|
374
|
+
if (!open) return;
|
|
375
|
+
const handler = (e) => {
|
|
376
|
+
if (e.key === "Escape") setOpen(false);
|
|
377
|
+
};
|
|
378
|
+
document.addEventListener("keydown", handler);
|
|
379
|
+
return () => document.removeEventListener("keydown", handler);
|
|
380
|
+
}, [open]);
|
|
381
|
+
const handleSearchChange = _react.useCallback.call(void 0, (q) => {
|
|
382
|
+
setSearchQuery(q);
|
|
383
|
+
setSelectedId(null);
|
|
384
|
+
setSelectedIndex(0);
|
|
385
|
+
setSelectedArticle(null);
|
|
386
|
+
}, []);
|
|
387
|
+
const handleSelectArticle = _react.useCallback.call(void 0, (id, index) => {
|
|
388
|
+
setSelectedId(id);
|
|
389
|
+
setSelectedIndex(index);
|
|
390
|
+
const art = articles.find((a) => a.id === id);
|
|
391
|
+
setSelectedArticle(_nullishCoalesce(art, () => ( null)));
|
|
392
|
+
}, [articles]);
|
|
393
|
+
const handleBack = _react.useCallback.call(void 0, () => {
|
|
394
|
+
setSelectedId(null);
|
|
395
|
+
setSelectedArticle(null);
|
|
396
|
+
}, []);
|
|
397
|
+
const filteredArticles = searchQuery.trim() ? articles.filter(
|
|
398
|
+
(a) => a.title.toLowerCase().includes(searchQuery.toLowerCase()) || a.body_md.toLowerCase().includes(searchQuery.toLowerCase())
|
|
399
|
+
) : articles;
|
|
400
|
+
const groups = groupBySection(filteredArticles);
|
|
401
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment, { children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className, style: { fontFamily: "var(--cyguin-docs-font)" }, children: [
|
|
402
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, DocsTrigger, { label: triggerLabel, onClick: () => setOpen(true) }),
|
|
403
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
404
|
+
DocsPanel,
|
|
405
|
+
{
|
|
406
|
+
mode,
|
|
407
|
+
open,
|
|
408
|
+
onClose: () => setOpen(false),
|
|
409
|
+
groups,
|
|
410
|
+
selectedId,
|
|
411
|
+
selectedIndex,
|
|
412
|
+
searchQuery,
|
|
413
|
+
onSearchChange: handleSearchChange,
|
|
414
|
+
onSelectArticle: handleSelectArticle,
|
|
415
|
+
onBack: handleBack,
|
|
416
|
+
article: selectedArticle
|
|
417
|
+
}
|
|
418
|
+
)
|
|
419
|
+
] }) });
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// src/types.ts
|
|
423
|
+
var defaultCssVars = {
|
|
424
|
+
"--cyguin-docs-bg": "var(--cyguin-surface, #ffffff)",
|
|
425
|
+
"--cyguin-docs-text": "var(--cyguin-text, #1a1a1a)",
|
|
426
|
+
"--cyguin-docs-border": "var(--cyguin-border, #e5e5e5)",
|
|
427
|
+
"--cyguin-docs-accent": "var(--cyguin-primary, #6366f1)",
|
|
428
|
+
"--cyguin-docs-muted": "var(--cyguin-muted, #737373)",
|
|
429
|
+
"--cyguin-docs-backdrop-opacity": "0.5",
|
|
430
|
+
"--cyguin-docs-radius": "var(--cyguin-radius, 8px)",
|
|
431
|
+
"--cyguin-docs-shadow": "var(--cyguin-shadow, 0 4px 24px rgba(0,0,0,0.12))",
|
|
432
|
+
"--cyguin-docs-trigger-size": "48px",
|
|
433
|
+
"--cyguin-docs-font": "var(--cyguin-font, system-ui, sans-serif)"
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
exports.DocsWidget = DocsWidget; exports.defaultCssVars = defaultCssVars;
|