@situaction/traquiste-docs-kit 0.0.0-stage → 1.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.
Files changed (68) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +356 -2
  3. package/client.d.ts +7 -0
  4. package/dist/app/ColorModeContext.d.ts +15 -0
  5. package/dist/app/ColorModeContext.d.ts.map +1 -0
  6. package/dist/app/ColorModeContext.js +58 -0
  7. package/dist/app/config.d.ts +69 -0
  8. package/dist/app/config.d.ts.map +1 -0
  9. package/dist/app/config.js +35 -0
  10. package/dist/app/createDocsApp.d.ts +9 -0
  11. package/dist/app/createDocsApp.d.ts.map +1 -0
  12. package/dist/app/createDocsApp.js +53 -0
  13. package/dist/components/Callout.d.ts +11 -0
  14. package/dist/components/Callout.d.ts.map +1 -0
  15. package/dist/components/Callout.js +28 -0
  16. package/dist/components/CodeBlock.d.ts +12 -0
  17. package/dist/components/CodeBlock.d.ts.map +1 -0
  18. package/dist/components/CodeBlock.js +60 -0
  19. package/dist/components/DeviceFrame.d.ts +17 -0
  20. package/dist/components/DeviceFrame.d.ts.map +1 -0
  21. package/dist/components/DeviceFrame.js +74 -0
  22. package/dist/components/LiveEditor.d.ts +10 -0
  23. package/dist/components/LiveEditor.d.ts.map +1 -0
  24. package/dist/components/LiveEditor.js +231 -0
  25. package/dist/components/PropsTable.d.ts +16 -0
  26. package/dist/components/PropsTable.d.ts.map +1 -0
  27. package/dist/components/PropsTable.js +60 -0
  28. package/dist/components/layout/ComponentSearch.d.ts +2 -0
  29. package/dist/components/layout/ComponentSearch.d.ts.map +1 -0
  30. package/dist/components/layout/ComponentSearch.js +156 -0
  31. package/dist/components/layout/Layout.d.ts +8 -0
  32. package/dist/components/layout/Layout.d.ts.map +1 -0
  33. package/dist/components/layout/Layout.js +109 -0
  34. package/dist/components/layout/NotFound.d.ts +2 -0
  35. package/dist/components/layout/NotFound.d.ts.map +1 -0
  36. package/dist/components/layout/NotFound.js +36 -0
  37. package/dist/components/layout/Sidebar.d.ts +2 -0
  38. package/dist/components/layout/Sidebar.d.ts.map +1 -0
  39. package/dist/components/layout/Sidebar.js +88 -0
  40. package/dist/components/layout/TableOfContents.d.ts +10 -0
  41. package/dist/components/layout/TableOfContents.d.ts.map +1 -0
  42. package/dist/components/layout/TableOfContents.js +48 -0
  43. package/dist/hooks/useCopy.d.ts +5 -0
  44. package/dist/hooks/useCopy.d.ts.map +1 -0
  45. package/dist/hooks/useCopy.js +19 -0
  46. package/dist/index.d.ts +21 -0
  47. package/dist/index.d.ts.map +1 -0
  48. package/dist/index.js +13 -0
  49. package/dist/pages/DocPage.d.ts +26 -0
  50. package/dist/pages/DocPage.d.ts.map +1 -0
  51. package/dist/pages/DocPage.js +23 -0
  52. package/dist/pages/createComponentPage.d.ts +33 -0
  53. package/dist/pages/createComponentPage.d.ts.map +1 -0
  54. package/dist/pages/createComponentPage.js +150 -0
  55. package/dist/pages/createScreenPage.d.ts +33 -0
  56. package/dist/pages/createScreenPage.d.ts.map +1 -0
  57. package/dist/pages/createScreenPage.js +124 -0
  58. package/dist/styles/docs.css +177 -0
  59. package/dist/styles/pageStyles.d.ts +45 -0
  60. package/dist/styles/pageStyles.d.ts.map +1 -0
  61. package/dist/styles/pageStyles.js +46 -0
  62. package/dist/vite/extractProps.d.ts +8 -0
  63. package/dist/vite/extractProps.d.ts.map +1 -0
  64. package/dist/vite/extractProps.js +79 -0
  65. package/dist/vite/index.d.ts +18 -0
  66. package/dist/vite/index.d.ts.map +1 -0
  67. package/dist/vite/index.js +73 -0
  68. package/package.json +111 -4
@@ -0,0 +1,79 @@
1
+ /** Reads component props from TypeScript sources (interfaces, JSDoc, defaults) — Node only */
2
+ import ts from 'typescript';
3
+ import { withCompilerOptions, withCustomConfig } from 'react-docgen-typescript';
4
+ const PARSER_OPTIONS = {
5
+ // Unions of literals are expanded to their values instead of a type alias name
6
+ shouldExtractLiteralValuesFromEnum: true,
7
+ shouldRemoveUndefinedFromOptional: true,
8
+ savePropValueAsString: true,
9
+ // Inherited DOM / React props (ButtonHTMLAttributes, ViewProps…) would bury the component's own API
10
+ propFilter: (prop) => !prop.parent?.fileName.includes('node_modules'),
11
+ };
12
+ // Single quotes, as in the libraries' code style: "primary" → 'primary'
13
+ const singleQuote = (literal) => literal.replace(/^"(.*)"$/, "'$1'");
14
+ /** Removes outer parentheses added around optional function types: `(() => void)` → `() => void` */
15
+ function unwrapParens(type) {
16
+ if (!type.startsWith('(') || !type.endsWith(')'))
17
+ return type;
18
+ let depth = 0;
19
+ for (let i = 0; i < type.length; i++) {
20
+ if (type[i] === '(')
21
+ depth++;
22
+ else if (type[i] === ')')
23
+ depth--;
24
+ // The first parenthesis closes before the end: they do not wrap the whole type
25
+ if (depth === 0 && i < type.length - 1)
26
+ return type;
27
+ }
28
+ return type.slice(1, -1);
29
+ }
30
+ function formatType(prop) {
31
+ const { type } = prop;
32
+ if (type.name === 'enum') {
33
+ const values = (type.value ?? []);
34
+ if (values.length)
35
+ return values.map((v) => singleQuote(v.value)).join(' | ');
36
+ return type.raw ?? type.name;
37
+ }
38
+ return unwrapParens(type.name)
39
+ // ReactElement<unknown, string | JSXElementConstructor<any>> → ReactElement
40
+ .replace(/ReactElement<[^<>]*(<[^<>]*>[^<>]*)*>/g, 'ReactElement');
41
+ }
42
+ function formatDefault(value, type) {
43
+ if (value === undefined || value === null || value === '')
44
+ return undefined;
45
+ const text = String(value);
46
+ // String defaults come without quotes: put them back when the prop holds strings
47
+ const isStringProp = type === 'string' || type.includes("'");
48
+ const isLiteral = /^(true|false|null|undefined|-?\d+(\.\d+)?|['"`].*)$/.test(text);
49
+ return isStringProp && !isLiteral ? `'${text}'` : text;
50
+ }
51
+ // JSDoc written as `/** text **/` leaves a trailing asterisk
52
+ const cleanDescription = (text) => text.replace(/\s*\*+\s*$/, '').trim();
53
+ function toPropDef(prop) {
54
+ const type = formatType(prop);
55
+ const def = formatDefault(prop.defaultValue?.value, type);
56
+ return {
57
+ name: prop.name,
58
+ type,
59
+ required: prop.required,
60
+ ...(def !== undefined ? { default: def } : {}),
61
+ description: cleanDescription(prop.description),
62
+ };
63
+ }
64
+ // docgen also reports exported helpers and constants (getBearingSector, MARKER_HEIGHT): keep PascalCase only
65
+ const isComponentName = (name) => /^[A-Z]/.test(name) && !/^[A-Z0-9_]+$/.test(name);
66
+ function toComponentProps(docs) {
67
+ const result = {};
68
+ for (const doc of docs) {
69
+ if (isComponentName(doc.displayName))
70
+ result[doc.displayName] = Object.values(doc.props).map(toPropDef);
71
+ }
72
+ return result;
73
+ }
74
+ export function createPropsExtractor({ tsconfig } = {}) {
75
+ const parser = tsconfig
76
+ ? withCustomConfig(tsconfig, PARSER_OPTIONS)
77
+ : withCompilerOptions({ jsx: ts.JsxEmit.ReactJSX, esModuleInterop: true, skipLibCheck: true }, PARSER_OPTIONS);
78
+ return (files) => (files.length ? toComponentProps(parser.parse(files)) : {});
79
+ }
@@ -0,0 +1,18 @@
1
+ import type { Plugin } from 'vite';
2
+ export type { ComponentProps } from './extractProps.js';
3
+ export interface DocgenOptions {
4
+ /** Component source files, relative to the Vite root — e.g. ['../src/components/**\/*.tsx'] */
5
+ include: string[];
6
+ /** Files to skip — stories and tests are always skipped */
7
+ exclude?: string[];
8
+ /** tsconfig used to read the components, relative to the Vite root */
9
+ tsconfig?: string;
10
+ }
11
+ /** Absolute paths of the files matching `include` minus `exclude` */
12
+ export declare function findComponentFiles(root: string, include: string[], exclude?: string[]): Promise<string[]>;
13
+ /**
14
+ * Exposes `virtual:traquiste-docs/props`, a `{ [componentName]: PropDef[] }` map to pass to
15
+ * `defineDocsConfig({ componentProps })`. Pages then use `props: 'auto'`.
16
+ */
17
+ export declare function docgen(options: DocgenOptions): Plugin;
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vite/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,MAAM,CAAA;AAIlD,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAEvD,MAAM,WAAW,aAAa;IAC5B,+FAA+F;IAC/F,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,2DAA2D;IAC3D,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,sEAAsE;IACtE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAQD,qEAAqE;AACrE,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,MAAM,EAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAOnH;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAqDrD"}
@@ -0,0 +1,73 @@
1
+ /** Vite plugin: generates component props tables from TypeScript sources — import from '@situaction/traquiste-docs-kit/vite' */
2
+ import path from 'node:path';
3
+ import { glob } from 'tinyglobby';
4
+ import { createPropsExtractor } from './extractProps.js';
5
+ const VIRTUAL_ID = 'virtual:traquiste-docs/props';
6
+ const RESOLVED_ID = '\0' + VIRTUAL_ID;
7
+ // Matched on absolute paths: glob `ignore` patterns are relative to the cwd, and components live
8
+ // outside it (`../src/…`), so they would never apply
9
+ const ALWAYS_EXCLUDED = /(\.(stories|test|spec)\.[^/\\]+$)|([/\\]node_modules[/\\])/;
10
+ /** Absolute paths of the files matching `include` minus `exclude` */
11
+ export async function findComponentFiles(root, include, exclude = []) {
12
+ const [matched, excluded] = await Promise.all([
13
+ glob(include, { cwd: root, absolute: true }),
14
+ exclude.length ? glob(exclude, { cwd: root, absolute: true }) : Promise.resolve([]),
15
+ ]);
16
+ const skip = new Set(excluded);
17
+ return matched.filter((file) => !skip.has(file) && !ALWAYS_EXCLUDED.test(file)).sort();
18
+ }
19
+ /**
20
+ * Exposes `virtual:traquiste-docs/props`, a `{ [componentName]: PropDef[] }` map to pass to
21
+ * `defineDocsConfig({ componentProps })`. Pages then use `props: 'auto'`.
22
+ */
23
+ export function docgen(options) {
24
+ let root = process.cwd();
25
+ let files = [];
26
+ let props = {};
27
+ let extract;
28
+ let ready = null;
29
+ async function scan() {
30
+ files = await findComponentFiles(root, options.include, options.exclude);
31
+ props = extract(files);
32
+ }
33
+ const isIncluded = (file) => files.includes(path.resolve(file));
34
+ return {
35
+ name: 'traquiste-docs:docgen',
36
+ configResolved(config) {
37
+ root = config.root;
38
+ extract = createPropsExtractor({
39
+ tsconfig: options.tsconfig ? path.resolve(root, options.tsconfig) : undefined,
40
+ });
41
+ },
42
+ resolveId(id) {
43
+ return id === VIRTUAL_ID ? RESOLVED_ID : null;
44
+ },
45
+ async load(id) {
46
+ if (id !== RESOLVED_ID)
47
+ return null;
48
+ // Parsed once, on first import: a TypeScript program over all components takes a few seconds
49
+ ready ??= scan();
50
+ await ready;
51
+ return `export default ${JSON.stringify(props)}`;
52
+ },
53
+ configureServer(server) {
54
+ // Edit a component → re-read it alone; add or remove one → rescan everything
55
+ const refresh = async (file, rescan) => {
56
+ if (rescan)
57
+ await scan();
58
+ else if (isIncluded(file))
59
+ Object.assign(props, extract([path.resolve(file)]));
60
+ else
61
+ return;
62
+ const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
63
+ if (mod) {
64
+ server.moduleGraph.invalidateModule(mod);
65
+ server.ws.send({ type: 'full-reload' });
66
+ }
67
+ };
68
+ server.watcher.on('change', (file) => void refresh(file, false));
69
+ server.watcher.on('add', (file) => void refresh(file, true));
70
+ server.watcher.on('unlink', (file) => void refresh(file, true));
71
+ },
72
+ };
73
+ }
package/package.json CHANGED
@@ -1,6 +1,113 @@
1
1
  {
2
2
  "name": "@situaction/traquiste-docs-kit",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.1.0",
4
+ "description": "Documentation site engine shared by the Traquiste UI libraries (web and mobile)",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./vite": {
14
+ "types": "./dist/vite/index.d.ts",
15
+ "import": "./dist/vite/index.js"
16
+ },
17
+ "./client": {
18
+ "types": "./client.d.ts"
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "client.d.ts",
24
+ "CHANGELOG.md"
25
+ ],
26
+ "sideEffects": [
27
+ "**/*.css"
28
+ ],
29
+ "scripts": {
30
+ "dev": "vite",
31
+ "build": "rm -rf dist && tsc -p tsconfig.build.json && mkdir -p dist/styles && cp src/styles/*.css dist/styles/",
32
+ "build:playground": "vite build",
33
+ "preview": "vite preview",
34
+ "typecheck": "tsc -p tsconfig.json",
35
+ "lint": "eslint .",
36
+ "test": "vitest run",
37
+ "prepublishOnly": "npm run build"
38
+ },
39
+ "keywords": [
40
+ "documentation",
41
+ "react",
42
+ "live-editor",
43
+ "traquiste"
44
+ ],
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "https://bitbucket.org/winoc/traq-ui-ste-docs-kit"
48
+ },
49
+ "bugs": {
50
+ "url": "https://bitbucket.org/winoc/traq-ui-ste-docs-kit/issues"
51
+ },
52
+ "author": "Situaction <dev@situaction.fr>",
53
+ "license": "MIT",
54
+ "homepage": "https://bitbucket.org/winoc/traq-ui-ste-docs-kit#readme",
55
+ "dependencies": {
56
+ "@babel/standalone": "^7.29.4",
57
+ "@monaco-editor/react": "^4.7.0",
58
+ "@phosphor-icons/react": "^2.1.10",
59
+ "react-docgen-typescript": "^2.4.0",
60
+ "react-router-dom": "^7.15.1",
61
+ "tinyglobby": "^0.2.17"
62
+ },
63
+ "peerDependencies": {
64
+ "react": "^18.0.0 || ^19.0.0",
65
+ "react-dom": "^18.0.0 || ^19.0.0",
66
+ "typescript": ">=5.0.0",
67
+ "vite": "^6.0.0 || ^7.0.0 || ^8.0.0"
68
+ },
69
+ "devDependencies": {
70
+ "@eslint/js": "^10.0.1",
71
+ "@semantic-release/changelog": "^7.0.0",
72
+ "@semantic-release/commit-analyzer": "^13.0.1",
73
+ "@semantic-release/git": "^10.0.1",
74
+ "@semantic-release/npm": "^13.1.5",
75
+ "@semantic-release/release-notes-generator": "^14.1.1",
76
+ "@testing-library/jest-dom": "^7.0.1",
77
+ "@testing-library/react": "^16.3.3",
78
+ "@testing-library/user-event": "^14.6.8",
79
+ "@types/babel__standalone": "^7.1.9",
80
+ "@types/node": "^24.12.3",
81
+ "@types/react": "^18.3.12",
82
+ "@types/react-dom": "^18.3.1",
83
+ "@vitejs/plugin-react": "^6.0.1",
84
+ "eslint": "^10.3.0",
85
+ "eslint-plugin-react-hooks": "^7.1.1",
86
+ "eslint-plugin-react-refresh": "^0.5.2",
87
+ "globals": "^17.6.0",
88
+ "jsdom": "^29.1.1",
89
+ "react": "^19.3.1",
90
+ "react-dom": "^19.3.1",
91
+ "react-native": "^0.83.6",
92
+ "react-native-web": "^0.21.4",
93
+ "semantic-release": "^25.0.3",
94
+ "typescript": "~6.0.2",
95
+ "typescript-eslint": "^8.59.2",
96
+ "vite": "^8.0.12",
97
+ "vitest": "^5.0.5"
98
+ },
99
+ "publishConfig": {
100
+ "access": "public"
101
+ },
102
+ "peerDependenciesMeta": {
103
+ "typescript": {
104
+ "optional": true
105
+ },
106
+ "vite": {
107
+ "optional": true
108
+ }
109
+ },
110
+ "overrides": {
111
+ "@types/react": "$@types/react"
112
+ }
113
+ }