sdocs 0.0.31 → 0.0.33

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 (33) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +3 -3
  3. package/dist/commands/dev.js +1 -1
  4. package/dist/{client/App.svelte → explorer/Explorer.svelte} +13 -2
  5. package/dist/explorer/Explorer.svelte.d.ts +15 -0
  6. package/dist/{client → explorer}/views/PreviewFrame.svelte +7 -2
  7. package/dist/server/app-gen.js +16 -16
  8. package/dist/server/cli.js +2 -2
  9. package/dist/vite.js +11 -3
  10. package/package.json +3 -3
  11. package/dist/client/App.svelte.d.ts +0 -15
  12. /package/dist/{client → explorer}/favicon.png +0 -0
  13. /package/dist/{client → explorer}/router.svelte.d.ts +0 -0
  14. /package/dist/{client → explorer}/router.svelte.js +0 -0
  15. /package/dist/{client → explorer}/tree-builder.d.ts +0 -0
  16. /package/dist/{client → explorer}/tree-builder.js +0 -0
  17. /package/dist/{client → explorer}/views/CollapsiblePanel.svelte +0 -0
  18. /package/dist/{client → explorer}/views/CollapsiblePanel.svelte.d.ts +0 -0
  19. /package/dist/{client → explorer}/views/ComponentView.svelte +0 -0
  20. /package/dist/{client → explorer}/views/ComponentView.svelte.d.ts +0 -0
  21. /package/dist/{client → explorer}/views/ControlsPanel.svelte +0 -0
  22. /package/dist/{client → explorer}/views/ControlsPanel.svelte.d.ts +0 -0
  23. /package/dist/{client → explorer}/views/DataTable.svelte +0 -0
  24. /package/dist/{client → explorer}/views/DataTable.svelte.d.ts +0 -0
  25. /package/dist/{client → explorer}/views/HomePage.svelte +0 -0
  26. /package/dist/{client → explorer}/views/HomePage.svelte.d.ts +0 -0
  27. /package/dist/{client → explorer}/views/LayoutView.svelte +0 -0
  28. /package/dist/{client → explorer}/views/LayoutView.svelte.d.ts +0 -0
  29. /package/dist/{client → explorer}/views/PageView.svelte +0 -0
  30. /package/dist/{client → explorer}/views/PageView.svelte.d.ts +0 -0
  31. /package/dist/{client → explorer}/views/PreviewFrame.svelte.d.ts +0 -0
  32. /package/dist/{client → explorer}/views/Sidebar.svelte +0 -0
  33. /package/dist/{client → explorer}/views/Sidebar.svelte.d.ts +0 -0
package/CHANGELOG.md CHANGED
@@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.0.33] - 2026-07-03
11
+
12
+ ### Added
13
+
14
+ - **Embedded apps can deploy under a sub-path.** Preview URLs pick up the
15
+ host Vite `base` automatically; SvelteKit apps (whose base Vite doesn't
16
+ see) pass it explicitly via the new `previewBase` prop on `Explorer` —
17
+ e.g. `previewBase={base}` with `base` from `$app/paths`.
18
+
19
+ ## [0.0.32] - 2026-07-03
20
+
21
+ ### Changed
22
+
23
+ - **Breaking: the embedded component is the Explorer now.** Import
24
+ `Explorer` from `sdocs/explorer` instead of `App` from `sdocs/client` —
25
+ same component and props, named for what it is. The CLI help and
26
+ generated app use the same naming.
27
+
10
28
  ## [0.0.31] - 2026-07-03
11
29
 
12
30
  ### Added
package/README.md CHANGED
@@ -65,11 +65,11 @@ The plugin discovers `.sdoc` files and exposes them via a `virtual:sdocs` module
65
65
  ```svelte
66
66
  <!-- src/routes/docs/+page.svelte -->
67
67
  <script>
68
- import App from 'sdocs/client';
68
+ import Explorer from 'sdocs/explorer';
69
69
  import { docs, cssNames } from 'virtual:sdocs';
70
70
  </script>
71
71
 
72
- <App
72
+ <Explorer
73
73
  {docs}
74
74
  {cssNames}
75
75
  logo="My Design System"
@@ -273,7 +273,7 @@ sidebar: {
273
273
  |--------|-------------|
274
274
  | `sdocs` | Main entry — `sdocsPlugin` + types |
275
275
  | `sdocs/vite` | Vite plugin function |
276
- | `sdocs/client` | App.svelte UI component |
276
+ | `sdocs/explorer` | Explorer.svelte UI component |
277
277
  | `sdocs/ui` | Reusable UI components (Button, Frame, Icon, Control, NavTree, Stack) |
278
278
 
279
279
  ## License
@@ -44,7 +44,7 @@ export async function devCommand() {
44
44
  // Rolldown-based Vite (8+) can't scan .svelte entry graphs and floods
45
45
  // the console with unresolved-import errors. Skip the initial scan —
46
46
  // runtime discovery still optimizes dependencies on demand — and
47
- // pre-bundle the one dependency the client app always needs.
47
+ // pre-bundle the one dependency the Explorer app always needs.
48
48
  entries: [],
49
49
  include: ['svelte'],
50
50
  },
@@ -7,7 +7,7 @@
7
7
  import PageView from './views/PageView.svelte';
8
8
  import LayoutView from './views/LayoutView.svelte';
9
9
  import HomePage from './views/HomePage.svelte';
10
- import { onMount } from 'svelte';
10
+ import { onMount, setContext } from 'svelte';
11
11
  import '../ui/styles/sdocs.css';
12
12
 
13
13
  type ThemeMode = 'light' | 'dark';
@@ -17,13 +17,24 @@
17
17
  logo?: string;
18
18
  icon?: string | false;
19
19
  cssNames?: string[];
20
+ /** URL prefix for preview pages when the host app is served under a sub-path (e.g. SvelteKit's base). */
21
+ previewBase?: string;
20
22
  sidebarConfig?: {
21
23
  order?: Record<string, string[]>;
22
24
  open?: string[];
23
25
  };
24
26
  }
25
27
 
26
- let { docs, logo = 'sdocs', icon = 'sdocs', cssNames = [], sidebarConfig }: Props = $props();
28
+ let {
29
+ docs,
30
+ logo = 'sdocs',
31
+ icon = 'sdocs',
32
+ cssNames = [],
33
+ previewBase = '',
34
+ sidebarConfig
35
+ }: Props = $props();
36
+
37
+ setContext('sdocs-preview-base', previewBase);
27
38
 
28
39
  let sidebarHidden = $state(false);
29
40
  let activeStylesheet = $state<string | undefined>(undefined);
@@ -0,0 +1,15 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import '../ui/styles/sdocs.css';
3
+ declare const __propDef: {
4
+ props: Record<string, never>;
5
+ events: {
6
+ [evt: string]: CustomEvent<any>;
7
+ };
8
+ slots: {};
9
+ };
10
+ export type ExplorerProps = typeof __propDef.props;
11
+ export type ExplorerEvents = typeof __propDef.events;
12
+ export type ExplorerSlots = typeof __propDef.slots;
13
+ export default class Explorer extends SvelteComponentTyped<ExplorerProps, ExplorerEvents, ExplorerSlots> {
14
+ }
15
+ export {};
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import { onMount, untrack } from 'svelte';
2
+ import { getContext, onMount, untrack } from 'svelte';
3
3
 
4
4
  interface Props {
5
5
  src: string;
@@ -10,6 +10,11 @@
10
10
  }
11
11
 
12
12
  let { src, props = {}, cssVars = {}, activeStylesheet, fullHeight = false }: Props = $props();
13
+
14
+ // Preview URLs are root-absolute; hosts serving under a sub-path pass the
15
+ // prefix via the Explorer's previewBase prop (see Explorer.svelte).
16
+ const previewBase = (getContext('sdocs-preview-base') as string | undefined) ?? '';
17
+ const resolvedSrc = $derived(previewBase.replace(/\/$/, '') + src);
13
18
  let iframe: HTMLIFrameElement;
14
19
  let ready = $state(false);
15
20
  let contentHeight = $state(0);
@@ -73,7 +78,7 @@
73
78
  <div class="sdocs-preview-frame" class:full-height={fullHeight}>
74
79
  <iframe
75
80
  bind:this={iframe}
76
- {src}
81
+ src={resolvedSrc}
77
82
  title="Component preview"
78
83
  class="sdocs-iframe"
79
84
  scrolling="no"
@@ -7,13 +7,13 @@ import { discoverDocFiles, getSdocKind } from './discovery.js';
7
7
  import { extractSnippets, hasDefaultSnippet } from './snippet-extractor.js';
8
8
  import { base64urlEncode } from './snippet-compiler.js';
9
9
  const __dirname = dirname(fileURLToPath(import.meta.url));
10
- /** Source client directory in the installed package (dist/client, next to dist/server) */
11
- function getClientSourceDir() {
12
- return resolve(__dirname, '../client');
10
+ /** Source Explorer directory in the installed package (dist/explorer, next to dist/server) */
11
+ function getExplorerSourceDir() {
12
+ return resolve(__dirname, '../explorer');
13
13
  }
14
- /** Copy the client app plus the ui/ tree it imports (styles, fonts, components) */
15
- async function copyClientApp(sdocsDir) {
16
- await copyDir(getClientSourceDir(), resolve(sdocsDir, 'client'));
14
+ /** Copy the Explorer app plus the ui/ tree it imports (styles, fonts, components) */
15
+ async function copyExplorerApp(sdocsDir) {
16
+ await copyDir(getExplorerSourceDir(), resolve(sdocsDir, 'explorer'));
17
17
  await copyDir(resolve(__dirname, '../ui'), resolve(sdocsDir, 'ui'));
18
18
  }
19
19
  /** Nearest node_modules walking up from dir (mirrors Node's resolution) */
@@ -68,7 +68,7 @@ function generateIndexHtml(title) {
68
68
  <head>
69
69
  <meta charset="UTF-8">
70
70
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
71
- <link rel="icon" type="image/png" href="./client/favicon.png">
71
+ <link rel="icon" type="image/png" href="./explorer/favicon.png">
72
72
  <title>${title}</title>
73
73
  <style>body { margin: 0; }</style>
74
74
  </head>
@@ -78,13 +78,13 @@ function generateIndexHtml(title) {
78
78
  </body>
79
79
  </html>`;
80
80
  }
81
- /** Generate the entry.js that mounts the App */
81
+ /** Generate the entry.js that mounts the Explorer */
82
82
  function generateEntryJs(config) {
83
83
  return `import { mount } from 'svelte';
84
84
  import { docs, cssNames } from 'virtual:sdocs';
85
- import App from './client/App.svelte';
85
+ import Explorer from './explorer/Explorer.svelte';
86
86
 
87
- mount(App, {
87
+ mount(Explorer, {
88
88
  target: document.getElementById('app'),
89
89
  props: {
90
90
  docs,
@@ -122,8 +122,8 @@ function generatePreviewHtml(iframeVirtualId, css) {
122
122
  <div id="app"></div>
123
123
  <script type="module">
124
124
  import { mount } from 'svelte';
125
- import App from '${iframeVirtualId}';
126
- mount(App, { target: document.getElementById('app') });
125
+ import Preview from '${iframeVirtualId}';
126
+ mount(Preview, { target: document.getElementById('app') });
127
127
 
128
128
  window.addEventListener('message', (e) => {
129
129
  if (e.data?.type === 'sdocs:update-stylesheet') {
@@ -165,8 +165,8 @@ async function discoverSnippets(config, cwd) {
165
165
  /** Generate the staging directory with entry files for dev mode */
166
166
  export async function generateDevFiles(config, cwd) {
167
167
  const sdocsDir = await createStagingDir(cwd);
168
- // Copy client components into the staging dir so they're compiled outside node_modules
169
- await copyClientApp(sdocsDir);
168
+ // Copy Explorer components into the staging dir so they're compiled outside node_modules
169
+ await copyExplorerApp(sdocsDir);
170
170
  await writeFile(resolve(sdocsDir, 'index.html'), generateIndexHtml(config.logo));
171
171
  await writeFile(resolve(sdocsDir, 'entry.js'), generateEntryJs(config));
172
172
  return sdocsDir;
@@ -174,8 +174,8 @@ export async function generateDevFiles(config, cwd) {
174
174
  /** Generate the staging directory with entry + preview HTML files for build mode */
175
175
  export async function generateBuildFiles(config, cwd) {
176
176
  const sdocsDir = await createStagingDir(cwd);
177
- // Copy client components into the staging dir
178
- await copyClientApp(sdocsDir);
177
+ // Copy Explorer components into the staging dir
178
+ await copyExplorerApp(sdocsDir);
179
179
  await writeFile(resolve(sdocsDir, 'index.html'), generateIndexHtml(config.logo));
180
180
  await writeFile(resolve(sdocsDir, 'entry.js'), generateEntryJs(config));
181
181
  const inputs = {
@@ -18,9 +18,9 @@ Usage:
18
18
  sdocs <command>
19
19
 
20
20
  Commands:
21
- dev Start development server with live reload
21
+ dev Start the Explorer dev server with live reload
22
22
  run Same as dev — works with npx and no local install
23
- build Build static documentation site
23
+ build Build the Explorer as a static site
24
24
  preview Serve built site locally
25
25
  init Scaffold sdocs.config.js
26
26
 
package/dist/vite.js CHANGED
@@ -21,6 +21,9 @@ export function sdocsPlugin(userConfig) {
21
21
  const buildMode = userConfig?._buildMode ?? false;
22
22
  let isBuild = false;
23
23
  let isSsrBuild = false;
24
+ // Host app's base path ('/' when served at the domain root); preview URLs
25
+ // are root-absolute and must carry it so embedding works under a sub-path.
26
+ let base = '/';
24
27
  // Previews planned for emission into a host app's build (embedded mode)
25
28
  let plannedPreviews = [];
26
29
  let emittedCssLinks = [];
@@ -30,6 +33,7 @@ export function sdocsPlugin(userConfig) {
30
33
  root = resolvedConfig.root;
31
34
  isBuild = resolvedConfig.command === 'build';
32
35
  isSsrBuild = !!resolvedConfig.build?.ssr;
36
+ base = resolvedConfig.base || '/';
33
37
  const fileConfig = await loadRawConfig(root);
34
38
  const merged = { ...fileConfig, ...userConfig };
35
39
  config = resolveAndFinalize(merged, root);
@@ -320,9 +324,13 @@ export function sdocsPlugin(userConfig) {
320
324
  name: s.name,
321
325
  body: s.body,
322
326
  highlightedHtml: s.highlightedHtml,
323
- previewUrl: buildMode || isBuild
324
- ? buildPreviewUrl(e.filePath, s.name)
325
- : previewUrl(e.filePath, s.name),
327
+ previewUrl:
328
+ // Only absolute bases prefix here; SvelteKit builds with a relative
329
+ // base ('./') and passes its real path via the Explorer's previewBase.
330
+ (base.startsWith('/') && base !== '/' ? base.replace(/\/$/, '') : '') +
331
+ (buildMode || isBuild
332
+ ? buildPreviewUrl(e.filePath, s.name)
333
+ : previewUrl(e.filePath, s.name)),
326
334
  })),
327
335
  highlightedSource: e.highlightedSource,
328
336
  toc: e.toc,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdocs",
3
- "version": "0.0.31",
3
+ "version": "0.0.33",
4
4
  "description": "A lightweight documentation tool for Svelte 5 components",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -21,8 +21,8 @@
21
21
  "types": "./dist/vite.d.ts",
22
22
  "default": "./dist/vite.js"
23
23
  },
24
- "./client": {
25
- "svelte": "./dist/client/App.svelte"
24
+ "./explorer": {
25
+ "svelte": "./dist/explorer/Explorer.svelte"
26
26
  },
27
27
  "./ui": {
28
28
  "types": "./dist/ui/index.d.ts",
@@ -1,15 +0,0 @@
1
- import { SvelteComponentTyped } from "svelte";
2
- import '../ui/styles/sdocs.css';
3
- declare const __propDef: {
4
- props: Record<string, never>;
5
- events: {
6
- [evt: string]: CustomEvent<any>;
7
- };
8
- slots: {};
9
- };
10
- export type AppProps = typeof __propDef.props;
11
- export type AppEvents = typeof __propDef.events;
12
- export type AppSlots = typeof __propDef.slots;
13
- export default class App extends SvelteComponentTyped<AppProps, AppEvents, AppSlots> {
14
- }
15
- export {};
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes