sdocs 0.0.37 → 0.0.39

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/CHANGELOG.md CHANGED
@@ -7,6 +7,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.0.39] - 2026-07-04
11
+
12
+ ### Changed
13
+
14
+ - **Methods and States join the unified section layout.** Methods render a
15
+ single signature chip (`(params) => returns`, colored like events) with
16
+ the Run button in the control rail; States show their live value in a
17
+ "Current value" rail. The value rail widens to align section right edges
18
+ when it's the last column. All six sections now share one table
19
+ implementation.
20
+ - **JSDoc types display like TypeScript types.** `import('module').`
21
+ qualifiers are stripped for display and classification, so
22
+ `import('svelte').Snippet<[…]>` renders as the same pink `Snippet<[…]>`
23
+ chip as in TS components.
24
+
25
+ ## [0.0.38] - 2026-07-04
26
+
27
+ ### Changed
28
+
29
+ - Names in the API tables are slightly larger (14px), giving each row a
30
+ clearer anchor.
31
+
10
32
  ## [0.0.37] - 2026-07-03
11
33
 
12
34
  ### Changed
@@ -16,12 +16,16 @@
16
16
  control?: Snippet<[Row]>;
17
17
  /** Show the Default column (rows without defaults, e.g. events, turn it off) */
18
18
  showDefault?: boolean;
19
+ /** Header label of the Default column (e.g. "Current value" for states) */
20
+ defaultLabel?: string;
19
21
  }
20
22
 
21
- let { rows, control, showDefault = true }: Props = $props();
23
+ let { rows, control, showDefault = true, defaultLabel = 'Default' }: Props = $props();
22
24
 
25
+ // The default/value column widens to the control-rail width when it is the
26
+ // last column, so section right edges align.
23
27
  const gridColumns = $derived(
24
- ['200px', 'minmax(0, 1fr)', ...(showDefault ? ['120px'] : []), ...(control ? ['200px'] : [])].join(' '),
28
+ ['200px', 'minmax(0, 1fr)', ...(showDefault ? [control ? '120px' : '200px'] : []), ...(control ? ['200px'] : [])].join(' '),
25
29
  );
26
30
  </script>
27
31
 
@@ -30,7 +34,7 @@
30
34
  <div class="sdocs-api-header" style:grid-template-columns={gridColumns}>
31
35
  <div>Name</div>
32
36
  <div>Details</div>
33
- {#if showDefault}<div>Default</div>{/if}
37
+ {#if showDefault}<div>{defaultLabel}</div>{/if}
34
38
  {#if control}<div>Control</div>{/if}
35
39
  </div>
36
40
  {#each rows as row (row.name)}
@@ -97,6 +101,7 @@
97
101
  font-size: 13px;
98
102
  }
99
103
  .sdocs-api-name {
104
+ font-size: 14px;
100
105
  font-weight: 600;
101
106
  color: var(--color-base-900);
102
107
  overflow-wrap: break-word;
@@ -4,7 +4,6 @@
4
4
  import { highlightSvelte } from '../highlighter.js';
5
5
  import CollapsiblePanel from './CollapsiblePanel.svelte';
6
6
  import PreviewFrame from './PreviewFrame.svelte';
7
- import DataTable from './DataTable.svelte';
8
7
  import ApiTable from './ApiTable.svelte';
9
8
  import PropControl from './PropControl.svelte';
10
9
  import CssPropControl from './CssPropControl.svelte';
@@ -249,15 +248,15 @@
249
248
  const methodsRows = $derived(
250
249
  (cd?.methods ?? []).map((m) => ({
251
250
  name: m.name,
251
+ type: `(${m.params ?? ''}) => ${m.returnType || 'void'}`,
252
252
  params: m.params,
253
- returns: m.returnType,
254
253
  description: m.description,
255
254
  })),
256
255
  );
257
256
 
258
257
  const stateRows = $derived(
259
258
  (cd?.state ?? []).map((s) => ({
260
- value: s.name in liveStateValues ? JSON.stringify(liveStateValues[s.name]) : undefined,
259
+ default: s.name in liveStateValues ? JSON.stringify(liveStateValues[s.name]) : undefined,
261
260
  name: s.name,
262
261
  type: s.type,
263
262
  description: s.description,
@@ -380,16 +379,7 @@
380
379
  <Icon name="square-function" --w="15px" --h="15px" --fill="var(--color-base-500)" />
381
380
  Methods
382
381
  </h2>
383
- <DataTable
384
- columns={[
385
- { key: 'name', label: 'Name', kind: 'name' },
386
- { key: 'params', label: 'Parameters' },
387
- { key: 'returns', label: 'Returns', kind: 'type' },
388
- { key: 'description', label: 'Description', kind: 'text' },
389
- ]}
390
- rows={methodsRows}
391
- control={methodsRows.length > 0 ? methodControl : undefined}
392
- />
382
+ <ApiTable rows={methodsRows} showDefault={false} control={methodControl} />
393
383
  </section>
394
384
 
395
385
  <section class="sdocs-doc-section">
@@ -397,15 +387,7 @@
397
387
  <Icon name="database" --w="15px" --h="15px" --fill="var(--color-base-500)" />
398
388
  States
399
389
  </h2>
400
- <DataTable
401
- columns={[
402
- { key: 'name', label: 'Name', kind: 'name' },
403
- { key: 'type', label: 'Type', kind: 'type' },
404
- { key: 'value', label: 'Current value', kind: 'value' },
405
- { key: 'description', label: 'Description', kind: 'text' },
406
- ]}
407
- rows={stateRows}
408
- />
390
+ <ApiTable rows={stateRows} defaultLabel="Current value" />
409
391
  </section>
410
392
 
411
393
  {#if exampleSnippets.length > 0}
@@ -1,6 +1,12 @@
1
+ /** Drop `import('module').` qualifiers — JSDoc types carry them, TS ones don't */
2
+ function normalizeType(value) {
3
+ return String(value)
4
+ .trim()
5
+ .replace(/import\((['"])[^'"]*\1\)\./g, '');
6
+ }
1
7
  /** Classify a type string for color coding (conventions, not a formal standard) */
2
8
  export function typeClass(value) {
3
- const v = String(value).trim();
9
+ const v = normalizeType(value);
4
10
  if (v === 'string' || /^'[^']*'(\s*\|\s*'[^']*')*$/.test(v))
5
11
  return 'string';
6
12
  if (v === 'number' || /^\d+(\.\d+)?(\s*\|\s*\d+(\.\d+)?)*$/.test(v))
@@ -36,7 +42,7 @@ export function valueClass(value) {
36
42
  }
37
43
  /** Split a clean union type into its members; everything else stays whole */
38
44
  export function typeParts(value) {
39
- const v = String(value).trim();
45
+ const v = normalizeType(value);
40
46
  if (/^'[^']*'(\s*\|\s*'[^']*')+$/.test(v) || /^\d+(\.\d+)?(\s*\|\s*\d+(\.\d+)?)+$/.test(v)) {
41
47
  return v.split('|').map((part) => part.trim());
42
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdocs",
3
- "version": "0.0.37",
3
+ "version": "0.0.39",
4
4
  "description": "A lightweight documentation tool for Svelte 5 components",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,121 +0,0 @@
1
- <script lang="ts">
2
- import type { Snippet } from 'svelte';
3
- import { typeClass, typeParts, valueClass } from './format.js';
4
-
5
- interface Column {
6
- key: string;
7
- label: string;
8
- /** 'name' renders as bold plain text, 'text' as plain text,
9
- * 'type' as a code chip color-coded by the type,
10
- * 'value' as mono text color-coded by the literal; default is a code chip */
11
- kind?: 'name' | 'text' | 'type' | 'value';
12
- }
13
-
14
- interface Props {
15
- columns: Column[];
16
- rows: Record<string, unknown>[];
17
- /** When set, adds a Control column rendering this snippet per row */
18
- control?: Snippet<[Record<string, unknown>]>;
19
- }
20
-
21
- let { columns, rows, control }: Props = $props();
22
-
23
-
24
- </script>
25
-
26
- {#if rows.length > 0}
27
- <table class="sdocs-table">
28
- <thead>
29
- <tr>
30
- {#each columns as col (col.key)}
31
- <th>{col.label}</th>
32
- {/each}
33
- {#if control}
34
- <th class="sdocs-table-control-col">Control</th>
35
- {/if}
36
- </tr>
37
- </thead>
38
- <tbody>
39
- {#each rows as row, i (i)}
40
- <tr>
41
- {#each columns as col (col.key)}
42
- <td>
43
- {#if row[col.key] == null}
44
- <span class="sdocs-table-empty">—</span>
45
- {:else if col.kind === 'name'}
46
- <span class="sdocs-table-name">
47
- {row[col.key]}{#if row.required === true}<span class="sdocs-table-required" title="Required">*</span>{/if}
48
- </span>
49
- {:else if col.kind === 'text'}
50
- {row[col.key]}
51
- {:else if col.kind === 'type'}
52
- {#each typeParts(row[col.key]) as part, i (i)}
53
- {#if i > 0}<span class="sdocs-typesep">|</span>{/if}
54
- <code class="sdocs-type-{typeClass(row[col.key])}">{part}</code>
55
- {/each}
56
- {:else if col.kind === 'value'}
57
- <span class="sdocs-value sdocs-value-{valueClass(row[col.key])}">{row[col.key]}</span>
58
- {:else}
59
- <code>{row[col.key]}</code>
60
- {/if}
61
- </td>
62
- {/each}
63
- {#if control}
64
- <td class="sdocs-table-control-col">
65
- {@render control(row)}
66
- </td>
67
- {/if}
68
- </tr>
69
- {/each}
70
- </tbody>
71
- </table>
72
- {:else}
73
- <p class="sdocs-table-none">None</p>
74
- {/if}
75
-
76
- <style>
77
- .sdocs-table {
78
- width: 100%;
79
- border-collapse: collapse;
80
- font-size: 13px;
81
- }
82
- .sdocs-table th {
83
- text-align: left;
84
- padding: 6px 12px;
85
- border-bottom: 2px solid var(--color-base-200);
86
- font-weight: 600;
87
- color: var(--color-base-600);
88
- font-size: 12px;
89
- }
90
- .sdocs-table td {
91
- padding: 6px 12px;
92
- border-bottom: 1px solid var(--color-base-100);
93
- color: var(--color-base-800);
94
- }
95
- .sdocs-table code {
96
- font-family: var(--mono);
97
- font-size: 12px;
98
- background: var(--color-base-100);
99
- padding: 1px 4px;
100
- border-radius: 3px;
101
- }
102
- .sdocs-table-name {
103
- font-weight: 600;
104
- }
105
- .sdocs-table-required {
106
- color: var(--color-red-500);
107
- }
108
- .sdocs-table-control-col {
109
- width: 220px;
110
- min-width: 180px;
111
- }
112
- .sdocs-table-empty {
113
- color: var(--color-base-300);
114
- }
115
- .sdocs-table-none {
116
- color: var(--color-base-400);
117
- font-size: 13px;
118
- font-style: italic;
119
- margin: 0;
120
- }
121
- </style>
@@ -1,14 +0,0 @@
1
- import { SvelteComponentTyped } from "svelte";
2
- declare const __propDef: {
3
- props: Record<string, never>;
4
- events: {
5
- [evt: string]: CustomEvent<any>;
6
- };
7
- slots: {};
8
- };
9
- export type DataTableProps = typeof __propDef.props;
10
- export type DataTableEvents = typeof __propDef.events;
11
- export type DataTableSlots = typeof __propDef.slots;
12
- export default class DataTable extends SvelteComponentTyped<DataTableProps, DataTableEvents, DataTableSlots> {
13
- }
14
- export {};