@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 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
- - Add sandbox components - e.g. `Button.sandbox.vue` will be available on the url `/sandbox?id=button`.
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 will be used to configure the site.
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 { Site } from '@do11y/docs';
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
- // Additional setup for the app.
79
+ /** Setup app */
76
80
  },
77
81
 
78
82
  async setupSandbox(app) {
79
- // Additional setup for the sandbox app.
83
+ /** Setup sandbox app */
80
84
  },
81
- } satisfies Site;
82
- ```
83
-
84
- ### `site/plugins.ts`
85
85
 
86
- This file will be used to configure the different plugins available.
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
- highlight(md, code, lang, attrs) {
90
+ markdownHighlight(md, code, lang, attrs) {
97
91
  // The highlight option for `markdown-it`.
98
92
  }
99
- } satisfies PluginOptions;
93
+ } satisfies Options;
100
94
  ```
package/dist/files.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export declare const ui: string;
2
2
  export declare const root: string;
3
3
  export declare const docs: string;
4
- export declare const plugins: string;
4
+ export declare const site: string;
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 = join(dirname(require.resolve('@do11y/ui/package.json')));
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 plugins = join(docs, 'site', 'plugins.ts');
9
+ export const site = join(docs, 'site', 'index.ts');
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import type { PluginOptions } from './plugin-options.js';
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 { PluginOptions, Site, Meta };
3
+ export type { Options, Meta };
5
4
  export declare const vueOptions: {
6
5
  include: RegExp[];
7
6
  exclude: RegExp[];
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export const vueOptions = {
2
2
  include: [/\.vue$/, /\.md$/],
3
- exclude: [/\.vue\?meta$/],
3
+ exclude: [/\.vue\?meta$/, /\.vue\?iframe$/],
4
4
  };
@@ -0,0 +1,5 @@
1
+ import type { Options } from './plugins/options/options.js';
2
+ /**
3
+ * Access plugin options (`docs/site/index.ts`).
4
+ */
5
+ export declare const options: Options;
@@ -0,0 +1,5 @@
1
+ import { site } from './files.js';
2
+ /**
3
+ * Access plugin options (`docs/site/index.ts`).
4
+ */
5
+ export const options = (await import(site)).default;
@@ -6,11 +6,11 @@ export interface MarkdownPluginOptions {
6
6
  /**
7
7
  * Additional markdown-it setup.
8
8
  */
9
- setup?: PluginSimple;
9
+ markdownSetup?: PluginSimple;
10
10
  /**
11
11
  * The highlight option for `markdown-it`.
12
12
  */
13
- highlight?: (md: MarkdownIt, code: string, lang: string, attrs: string) => string;
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?.highlight?.(md, code, lang, attrs) ?? '';
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?.setup) {
23
- md.use(options.setup);
22
+ if (options?.markdownSetup) {
23
+ md.use(options.markdownSetup);
24
24
  }
25
25
  return {
26
26
  name: 'do11y:markdown',
@@ -26,7 +26,6 @@ export default () => {
26
26
  const code = `export default ${JSON.stringify(mapMeta(meta, (content) => md.render(content)))}`;
27
27
  return {
28
28
  code,
29
- map: { mappings: '' },
30
29
  moduleType: 'js',
31
30
  };
32
31
  }
@@ -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
- export interface Site {
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 the site options (`docs/site/index.ts`)
24
- * through `do11y:site`.
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 the site options (`docs/site/index.ts`)
5
- * through `do11y:site`.
4
+ * Add ability to access options (`docs/site/index.ts`)
5
+ * through `do11y:options`.
6
6
  */
7
7
  export default () => ({
8
- name: 'do11y:site',
8
+ name: 'do11y:options',
9
9
  async resolveId(id, importer) {
10
- if (id === 'do11y:site') {
10
+ if (id === 'do11y:options') {
11
11
  return this.resolve(join(docs, 'site', 'index.js'), importer);
12
12
  }
13
13
  },
@@ -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 sitePlugin from './site/site.js';
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 { pluginOptions } from '../plugin-options.js';
8
+ import { options } from '../options.js';
9
9
  export const plugins = () => [
10
10
  uiPlugin(),
11
11
  sandboxPlugin(),
12
12
  metaPlugin(),
13
- markdownPlugin(pluginOptions),
13
+ markdownPlugin(options),
14
14
  customBlockPlugin('docs'),
15
- sitePlugin(),
15
+ optionsPlugin(),
16
16
  routesPlugin(),
17
17
  ];
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vue").DefineSetupFnComponent<Record<string, any>, {}, {}, Record<string, any> & {}, import("vue").PublicProps>;
2
+ export default _default;
@@ -0,0 +1,5 @@
1
+ import { defineComponent, h, useAttrs } from 'vue';
2
+ export default defineComponent(() => {
3
+ const attrs = useAttrs();
4
+ return () => h('div', undefined, () => h('div', attrs));
5
+ }, { inheritAttrs: false });
@@ -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: "${kebabCase(parse(path).name.replace('.sandbox', ''))}",
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.16",
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.9"
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 { computed, ref } from 'vue';
10
+ import { ref } from 'vue';
8
11
 
9
- const props = defineProps<{
12
+ defineProps<{
10
13
  /**
11
- * The iframe title.
14
+ * The title of the iframe.
12
15
  */
13
- title: string;
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>
@@ -1,15 +1,14 @@
1
- import type { Site } from '@do11y/docs';
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;
@@ -1,6 +0,0 @@
1
- import type { MarkdownPluginOptions } from './plugins/markdown/markdown.js';
2
- export type PluginOptions = MarkdownPluginOptions;
3
- /**
4
- * Access plugin options (`docs/site/plugins.ts`).
5
- */
6
- export declare const pluginOptions: PluginOptions | undefined;
@@ -1,8 +0,0 @@
1
- import { existsSync } from 'node:fs';
2
- import { plugins } from './files.js';
3
- /**
4
- * Access plugin options (`docs/site/plugins.ts`).
5
- */
6
- export const pluginOptions = existsSync(plugins)
7
- ? (await import(plugins)).default
8
- : undefined;
@@ -1 +0,0 @@
1
- export {};
package/dist/scaffold.js DELETED
@@ -1,4 +0,0 @@
1
- import { cp } from 'node:fs/promises';
2
- import { join } from 'node:path';
3
- import { docs } from './files.js';
4
- await cp(join(import.meta.dirname, '../template'), docs, { recursive: true });