@do11y/docs 0.0.16 → 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/README.md +13 -19
- package/dist/files.d.ts +1 -1
- package/dist/files.js +2 -2
- package/dist/index.d.ts +2 -3
- package/dist/index.js +1 -1
- package/dist/options.d.ts +5 -0
- package/dist/options.js +5 -0
- package/dist/plugins/markdown/markdown.d.ts +2 -2
- package/dist/plugins/markdown/markdown.js +3 -3
- package/dist/plugins/meta/meta.js +0 -1
- package/dist/plugins/{site/site.d.ts → options/options.d.ts} +8 -3
- package/dist/plugins/{site/site.js → options/options.js} +4 -4
- package/dist/plugins/plugins.js +4 -4
- package/dist/plugins/sandbox/ok.d.ts +2 -0
- package/dist/plugins/sandbox/ok.js +5 -0
- package/dist/plugins/sandbox/sandbox.js +54 -2
- package/package.json +2 -2
- package/template/site/SandboxIframe.vue +25 -7
- package/template/site/index.ts +5 -6
- package/dist/plugin-options.d.ts +0 -6
- package/dist/plugin-options.js +0 -8
- package/dist/scaffold.d.ts +0 -1
- package/dist/scaffold.js +0 -4
package/README.md
CHANGED
|
@@ -4,7 +4,8 @@ A very bare-bones tool to help document Vue components.
|
|
|
4
4
|
|
|
5
5
|
- Write documentation in Markdown files that get treated as Vue components.
|
|
6
6
|
- Import markdown files as routes.
|
|
7
|
-
-
|
|
7
|
+
- Sandbox components - e.g. `Button.sandbox.vue` will be available on the url `/sandbox?id=button`.
|
|
8
|
+
- Import components isolated inside an iframe - e.g. `import 'Button.sandbox.vue?iframe'` or `import 'Button.vue?iframe'`.
|
|
8
9
|
- Easily document components with [vue-component-meta](https://www.npmjs.com/package/vue-component-meta) using meta imports - e.g. `Button.vue?meta`.
|
|
9
10
|
|
|
10
11
|
## Setup
|
|
@@ -59,42 +60,35 @@ npm docs:dev
|
|
|
59
60
|
|
|
60
61
|
### `site/index.ts`
|
|
61
62
|
|
|
62
|
-
This file
|
|
63
|
+
This file is used for configuration.
|
|
63
64
|
|
|
64
65
|
> [!WARNING]
|
|
65
66
|
> Both the documentation site and the sandbox import this file - this is why it is recommended to import necessary files/components _inside_ the functions.
|
|
66
67
|
|
|
67
68
|
```ts
|
|
68
|
-
import type {
|
|
69
|
+
import type { Options } from '@do11y/docs';
|
|
69
70
|
|
|
70
71
|
export default {
|
|
71
|
-
// The main component for the site.
|
|
72
72
|
Site: () => import('./Site.vue'),
|
|
73
73
|
|
|
74
|
+
Sandbox: () => import('./Sandbox.vue'),
|
|
75
|
+
|
|
76
|
+
SandboxIframe: () => import('./SandboxIframe.vue'),
|
|
77
|
+
|
|
74
78
|
async setup(app, router) {
|
|
75
|
-
|
|
79
|
+
/** Setup app */
|
|
76
80
|
},
|
|
77
81
|
|
|
78
82
|
async setupSandbox(app) {
|
|
79
|
-
|
|
83
|
+
/** Setup sandbox app */
|
|
80
84
|
},
|
|
81
|
-
} satisfies Site;
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
### `site/plugins.ts`
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
```ts
|
|
89
|
-
import type { PluginOptions } from '@do11y/docs';
|
|
90
|
-
|
|
91
|
-
export default {
|
|
92
|
-
setup(md) {
|
|
86
|
+
markdownSetup(md) {
|
|
93
87
|
// Additional markdown-it setup.
|
|
94
88
|
}
|
|
95
89
|
|
|
96
|
-
|
|
90
|
+
markdownHighlight(md, code, lang, attrs) {
|
|
97
91
|
// The highlight option for `markdown-it`.
|
|
98
92
|
}
|
|
99
|
-
} satisfies
|
|
93
|
+
} satisfies Options;
|
|
100
94
|
```
|
package/dist/files.d.ts
CHANGED
package/dist/files.js
CHANGED
|
@@ -2,8 +2,8 @@ import { join, dirname } from 'node:path';
|
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
3
|
import { searchForWorkspaceRoot } from 'vite';
|
|
4
4
|
const require = createRequire(import.meta.url);
|
|
5
|
-
export const ui =
|
|
5
|
+
export const ui = dirname(require.resolve('@do11y/ui/package.json'));
|
|
6
6
|
export const root = searchForWorkspaceRoot(process.cwd());
|
|
7
7
|
// export const root = join(searchForWorkspaceRoot(process.cwd()), 'example');
|
|
8
8
|
export const docs = join(root, 'docs');
|
|
9
|
-
export const
|
|
9
|
+
export const site = join(docs, 'site', 'index.ts');
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Site } from './plugins/site/site.js';
|
|
1
|
+
import type { Options } from './plugins/options/options.js';
|
|
3
2
|
import type { Meta } from './plugins/meta/meta-types.js';
|
|
4
|
-
export type {
|
|
3
|
+
export type { Options, Meta };
|
|
5
4
|
export declare const vueOptions: {
|
|
6
5
|
include: RegExp[];
|
|
7
6
|
exclude: RegExp[];
|
package/dist/index.js
CHANGED
package/dist/options.js
ADDED
|
@@ -6,11 +6,11 @@ export interface MarkdownPluginOptions {
|
|
|
6
6
|
/**
|
|
7
7
|
* Additional markdown-it setup.
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
markdownSetup?: PluginSimple;
|
|
10
10
|
/**
|
|
11
11
|
* The highlight option for `markdown-it`.
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
markdownHighlight?: (md: MarkdownIt, code: string, lang: string, attrs: string) => string;
|
|
14
14
|
}
|
|
15
15
|
export interface MarkdownItEnv {
|
|
16
16
|
/**
|
|
@@ -12,15 +12,15 @@ export default (options) => {
|
|
|
12
12
|
const md = markdown({
|
|
13
13
|
html: true,
|
|
14
14
|
highlight(code, lang, attrs) {
|
|
15
|
-
return options?.
|
|
15
|
+
return options?.markdownHighlight?.(md, code, lang, attrs) ?? '';
|
|
16
16
|
},
|
|
17
17
|
});
|
|
18
18
|
md.use(frontmatterPlugin);
|
|
19
19
|
md.use(sfcPlugin);
|
|
20
20
|
md.use(componentPlugin);
|
|
21
21
|
md.use(attrsPlugin);
|
|
22
|
-
if (options?.
|
|
23
|
-
md.use(options.
|
|
22
|
+
if (options?.markdownSetup) {
|
|
23
|
+
md.use(options.markdownSetup);
|
|
24
24
|
}
|
|
25
25
|
return {
|
|
26
26
|
name: 'do11y:markdown',
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
2
|
import type { App, Component } from 'vue';
|
|
3
3
|
import type { Router } from 'vue-router';
|
|
4
|
-
|
|
4
|
+
import type { MarkdownPluginOptions } from '../markdown/markdown.js';
|
|
5
|
+
export interface Options extends MarkdownPluginOptions {
|
|
5
6
|
/**
|
|
6
7
|
* The wrapper component for the site.
|
|
7
8
|
*/
|
|
@@ -18,10 +19,14 @@ export interface Site {
|
|
|
18
19
|
* Additional setup for the sandbox app.
|
|
19
20
|
*/
|
|
20
21
|
setupSandbox?(app: App): void | Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Custom wrapper component for `?iframe` imports.
|
|
24
|
+
*/
|
|
25
|
+
SandboxIframe?: () => Promise<Component>;
|
|
21
26
|
}
|
|
22
27
|
/**
|
|
23
|
-
* Add ability to access
|
|
24
|
-
* through `do11y:
|
|
28
|
+
* Add ability to access options (`docs/site/index.ts`)
|
|
29
|
+
* through `do11y:options`.
|
|
25
30
|
*/
|
|
26
31
|
declare const _default: () => Plugin;
|
|
27
32
|
export default _default;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
2
|
import { docs } from '../../files.js';
|
|
3
3
|
/**
|
|
4
|
-
* Add ability to access
|
|
5
|
-
* through `do11y:
|
|
4
|
+
* Add ability to access options (`docs/site/index.ts`)
|
|
5
|
+
* through `do11y:options`.
|
|
6
6
|
*/
|
|
7
7
|
export default () => ({
|
|
8
|
-
name: 'do11y:
|
|
8
|
+
name: 'do11y:options',
|
|
9
9
|
async resolveId(id, importer) {
|
|
10
|
-
if (id === 'do11y:
|
|
10
|
+
if (id === 'do11y:options') {
|
|
11
11
|
return this.resolve(join(docs, 'site', 'index.js'), importer);
|
|
12
12
|
}
|
|
13
13
|
},
|
package/dist/plugins/plugins.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import markdownPlugin from './markdown/markdown.js';
|
|
2
2
|
import metaPlugin from './meta/meta.js';
|
|
3
3
|
import customBlockPlugin from 'v-custom-block';
|
|
4
|
-
import
|
|
4
|
+
import optionsPlugin from './options/options.js';
|
|
5
5
|
import routesPlugin from './routes/routes.js';
|
|
6
6
|
import uiPlugin from './ui/ui.js';
|
|
7
7
|
import sandboxPlugin from './sandbox/sandbox.js';
|
|
8
|
-
import {
|
|
8
|
+
import { options } from '../options.js';
|
|
9
9
|
export const plugins = () => [
|
|
10
10
|
uiPlugin(),
|
|
11
11
|
sandboxPlugin(),
|
|
12
12
|
metaPlugin(),
|
|
13
|
-
markdownPlugin(
|
|
13
|
+
markdownPlugin(options),
|
|
14
14
|
customBlockPlugin('docs'),
|
|
15
|
-
|
|
15
|
+
optionsPlugin(),
|
|
16
16
|
routesPlugin(),
|
|
17
17
|
];
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { kebabCase } from 'change-case';
|
|
2
|
-
import { parse } from 'node:path';
|
|
2
|
+
import { join, parse } from 'node:path';
|
|
3
3
|
import fg from 'fast-glob';
|
|
4
4
|
import { root, ui } from '../../files.js';
|
|
5
5
|
import { html } from '../../html/html.js';
|
|
6
|
+
const toParamId = (path) => kebabCase(parse(path).name.replace('.sandbox', ''));
|
|
6
7
|
/**
|
|
7
8
|
* Creates a seprate sandbox app, and
|
|
8
9
|
* adds the ability to declare sandbox components
|
|
@@ -27,12 +28,63 @@ export default () => {
|
|
|
27
28
|
if (id === resolvedModuleId) {
|
|
28
29
|
const stringifiedStories = sandboxFiles.map((path) => {
|
|
29
30
|
return `{
|
|
30
|
-
url: "${
|
|
31
|
+
url: "${toParamId(path)}",
|
|
31
32
|
component: async () => (await import("${path}")).default
|
|
32
33
|
}`;
|
|
33
34
|
});
|
|
34
35
|
return `export default [${stringifiedStories.map((sandbox) => sandbox.trim()).join(',\n')}]`;
|
|
35
36
|
}
|
|
36
37
|
},
|
|
38
|
+
transform: {
|
|
39
|
+
handler(source, id) {
|
|
40
|
+
if (!id.endsWith('.vue?iframe')) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const file = id.replace('?iframe', '');
|
|
44
|
+
const components = join(ui, 'dist', 'bundled', 'components.js');
|
|
45
|
+
const sandboxId = toParamId(file);
|
|
46
|
+
if (id.endsWith('.sandbox.vue?iframe')) {
|
|
47
|
+
const customCode = `
|
|
48
|
+
import { defineComponent, h } from 'vue';
|
|
49
|
+
|
|
50
|
+
import { Do11ySandboxIframe } from '${components}';
|
|
51
|
+
|
|
52
|
+
import options from 'do11y:options';
|
|
53
|
+
|
|
54
|
+
const customIframe = options.SandboxIframe ? (await options.SandboxIframe()).default : undefined;
|
|
55
|
+
|
|
56
|
+
export default defineComponent((props) => {
|
|
57
|
+
return () => h(Do11ySandboxIframe, {
|
|
58
|
+
id: '${sandboxId}',
|
|
59
|
+
source: ${JSON.stringify(source)},
|
|
60
|
+
customIframe,
|
|
61
|
+
customIframeProps: props,
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
`;
|
|
65
|
+
return {
|
|
66
|
+
code: customCode,
|
|
67
|
+
moduleType: 'js',
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const customCode = `
|
|
71
|
+
import { defineComponent, h, useAttrs } from 'vue';
|
|
72
|
+
|
|
73
|
+
import Component from '${file}';
|
|
74
|
+
|
|
75
|
+
import { Do11yIframe } from '${components}';
|
|
76
|
+
|
|
77
|
+
export default defineComponent(() => {
|
|
78
|
+
const attrs = useAttrs();
|
|
79
|
+
|
|
80
|
+
return () => h(Do11yIframe, undefined, () => h(Component, attrs));
|
|
81
|
+
});
|
|
82
|
+
`;
|
|
83
|
+
return {
|
|
84
|
+
code: customCode,
|
|
85
|
+
moduleType: 'js',
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
},
|
|
37
89
|
};
|
|
38
90
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@do11y/docs",
|
|
3
3
|
"description": "A very bare-bones tool to help document Vue components.",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.1.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"markdown-it-attrs": "^4.3.1",
|
|
40
40
|
"v-custom-block": "^1.0.67",
|
|
41
41
|
"vue-component-meta": "^3.1.8",
|
|
42
|
-
"@do11y/ui": "0.0
|
|
42
|
+
"@do11y/ui": "0.1.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@tsconfig/node24": "^24.0.3",
|
|
@@ -1,27 +1,44 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<iframe ref="iframe" :title="`Sandbox for ${title}`" :src="url" />
|
|
2
|
+
<iframe ref="iframe" :title="`Sandbox for ${title || id}`" :src="url" />
|
|
3
|
+
|
|
3
4
|
<a :href="url" target="_blank" rel="noopener noreferrer">Open in a new tab</a>
|
|
5
|
+
|
|
6
|
+
<pre><code>{{ source }}</code></pre>
|
|
4
7
|
</template>
|
|
5
8
|
|
|
6
9
|
<script lang="ts" setup>
|
|
7
|
-
import {
|
|
10
|
+
import { ref } from 'vue';
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
defineProps<{
|
|
10
13
|
/**
|
|
11
|
-
* The iframe
|
|
14
|
+
* The title of the iframe.
|
|
12
15
|
*/
|
|
13
|
-
title
|
|
16
|
+
title?: string;
|
|
14
17
|
|
|
15
18
|
/**
|
|
16
19
|
* The `id` of the sandbox - which is the filename
|
|
17
20
|
* without the extension `.sandbox.vue`.
|
|
21
|
+
*
|
|
22
|
+
* @do11y Automatically passed.
|
|
18
23
|
*/
|
|
19
24
|
id: string;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The sandbox url.
|
|
28
|
+
*
|
|
29
|
+
* @do11y Automatically passed.
|
|
30
|
+
*/
|
|
31
|
+
url: string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The source code.
|
|
35
|
+
*
|
|
36
|
+
* @do11y Automatically passed.
|
|
37
|
+
*/
|
|
38
|
+
source?: string;
|
|
20
39
|
}>();
|
|
21
40
|
|
|
22
41
|
const iframe = ref<HTMLIFrameElement>();
|
|
23
|
-
|
|
24
|
-
const url = computed(() => `${window.location.origin}/sandbox?id=${props.id}`);
|
|
25
42
|
</script>
|
|
26
43
|
|
|
27
44
|
<style scoped>
|
|
@@ -32,5 +49,6 @@
|
|
|
32
49
|
|
|
33
50
|
a {
|
|
34
51
|
float: right;
|
|
52
|
+
clear: both;
|
|
35
53
|
}
|
|
36
54
|
</style>
|
package/template/site/index.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Options } from '@do11y/docs';
|
|
2
2
|
|
|
3
3
|
export default {
|
|
4
4
|
Site: () => import('./Site.vue'),
|
|
5
|
+
|
|
5
6
|
Sandbox: () => import('./Sandbox.vue'),
|
|
6
7
|
|
|
8
|
+
SandboxIframe: () => import('./SandboxIframe.vue'),
|
|
9
|
+
|
|
7
10
|
async setup(app, router) {
|
|
8
11
|
const SandboxIframe = (await import('./SandboxIframe.vue')).default;
|
|
9
12
|
app.component('SandboxIframe', SandboxIframe);
|
|
10
13
|
},
|
|
11
|
-
|
|
12
|
-
async setupSandbox(app) {
|
|
13
|
-
/** Setup sandbox app */
|
|
14
|
-
},
|
|
15
|
-
} satisfies Site;
|
|
14
|
+
} satisfies Options;
|
package/dist/plugin-options.d.ts
DELETED
package/dist/plugin-options.js
DELETED
package/dist/scaffold.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/scaffold.js
DELETED