do11y 0.4.3 → 0.5.1

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
@@ -9,19 +9,19 @@ A bare-bones tool to document Vue components.
9
9
 
10
10
  ### Markdown components with [@mdit-vue](https://github.com/mdit-vue/mdit-vue).
11
11
 
12
- Markdown files are treated as single file Vue components with the help of [@mdit-vue](https://github.com/mdit-vue/mdit-vue).
12
+ > Customizable through the options `markdownSetup` and `markdownCodeBlock`.
13
13
 
14
- You can customize the markdown-it instance through the `markdownSetup` option.
14
+ Markdown files are treated as single file Vue components with the help of [@mdit-vue](https://github.com/mdit-vue/mdit-vue).
15
15
 
16
- ### Import markdown route files and pages as routes through `do11y:routes`
16
+ ### Markdown routes available through `do11y:routes`
17
17
 
18
- To include a markdown file as a route it needs to have a `title` and a `slug` (e.g. `/button`) in it's frontmatter. Or add it inside the `docs/do11y/pages` folder.
18
+ To include a markdown file as a route it needs to have a `title` and a `slug` (e.g. `/button`) in it's frontmatter, or it needs to be placed inside `docs/do11y/pages`.
19
19
 
20
20
  ### [Shiki](https://shiki.style) code highlighting
21
21
 
22
- Code blocks are automatically highlighted with [Shiki](https://shiki.style).
22
+ > Customizable through the `highlighter` option.
23
23
 
24
- You can customize the Shiki instance through the `highlighter` options.
24
+ Code blocks are automatically highlighted with [Shiki](https://shiki.style).
25
25
 
26
26
  ### Highlight imports
27
27
 
@@ -30,28 +30,50 @@ You can import Vue files as highlighted code blocks through `.vue?highlight`, or
30
30
  These imports return HTML strings meaning you have to render the code block using `v-html`.
31
31
 
32
32
  > [!WARNING]
33
- > Imports of type `.vue?highlight&lang=css` only work on built sites. During development it will return the same result as `.vue?highlight`.
33
+ > Imports of type `.vue?highlight&lang=css` only work on _built_ sites. During development it will return the same result as `.vue?highlight`.
34
34
 
35
35
  ### Sandboxes
36
36
 
37
- Create sandbox components - e.g. `Button.sandbox.vue` will be available under the url `/sandbox?id=button`, and if importing the component it will be wrapped inside an iframe component that has access to the components `?highlight` imports.
37
+ > To customize the Sandbox app add a custom `docs/do11y/pages/Sandbox.vue` wrapper component and/or use the `setupSandbox` option.
38
38
 
39
- To customize the sandbox app, use the `Sandbox` option - and to cutomize the iframe component used for import, use the `SandboxIframe` option.
39
+ Turn a component into a sandbox by adding a `.sandbox` prefix to the component name, e.g. `Button.sandbox.vue` will be available under the url `/sandbox?id=button`, and when importing the component it will be wrapped inside an iframe.
40
40
 
41
41
  > [!NOTE]
42
- > The id is based on the filename - not the path to the file - this means if you have two sandbox files of the same name in different locations - they won't both work.
42
+ > The id of a sandbox component is based on the filename - not the path - this means every sandbox component must have a unique name.
43
+
44
+ #### Sandbox Iframe
45
+
46
+ > To customize the Sandbox app add a custom `docs/do11y/layout/SandboxIframe.vue` wrapper component.
47
+
48
+ The sandbox iframe component has some props automatically passed to it - you can use the `SandboxIframeProps` type to declare these.
49
+
50
+ ```vue
51
+ <template>
52
+ <iframe ref="iframe" :title="`Sandbox for ${title || id}`" :src="url" />
53
+ </template>
54
+
55
+ <script lang="ts" setup>
56
+ import type { SandboxIframeProps } from "do11y";
57
+
58
+ defineProps<SandboxIframeProps & { title?: string }>();
59
+ </script>
60
+ ```
43
61
 
44
62
  ### Document components with [vue-component-meta](https://www.npmjs.com/package/vue-component-meta)
45
63
 
46
- Document components through meta imports (`Button.vue?meta`) which give a simplified version of a result from [vue-component-meta](https://www.npmjs.com/package/vue-component-meta).
64
+ Document components through meta imports (`Button.vue?meta`) which give a simplified version of the result from [vue-component-meta](https://www.npmjs.com/package/vue-component-meta).
47
65
 
48
66
  ## Options
49
67
 
50
- Expected as the default export in `docs/do11y/do11y.ts`.
68
+ > Options should be the default export of `docs/do11y/do11y.ts`.
51
69
 
52
- You can specify a layout for each page by adding a `docs/do11y/layout/Page.vue` file with a `<RouterView />` in it.
70
+ You can set the home page by adding a `docs/do11y/pages/Home.vue` file, and you can add a layout for each page in `docs/do11y/layout/Page.vue` using `<RouterView />`.
53
71
 
54
- And you can set the home page by adding `docs/do11y/pages/Home.vue`.
72
+ ```ts
73
+ import type { Options } from "do11y";
74
+
75
+ export default {} satisfies Options;
76
+ ```
55
77
 
56
78
  ```ts
57
79
  interface Options {
@@ -60,21 +82,11 @@ interface Options {
60
82
  */
61
83
  setup?(app: App, router: Router): void | Promise<void>;
62
84
 
63
- /**
64
- * The wrapper component for sandboxes.
65
- */
66
- Sandbox?: () => Promise<Component>;
67
-
68
85
  /**
69
86
  * Additional setup for the sandbox app.
70
87
  */
71
88
  setupSandbox?(app: App): void | Promise<void>;
72
89
 
73
- /**
74
- * Custom wrapper component for `.vue.sandbox` imports.
75
- */
76
- SandboxIframe?: () => Promise<Component>;
77
-
78
90
  /**
79
91
  * The code highlighter.
80
92
  * - Markdown code blocks
@@ -1,5 +1,5 @@
1
1
  import type { Plugin } from "vite";
2
- import type { App, Component } from "vue";
2
+ import type { App } from "vue";
3
3
  import type { Router } from "vue-router";
4
4
  import type { BundledTheme, ShikiTransformer, StringLiteralUnion, ThemeInput } from "shiki";
5
5
  import type { MarkdownPluginOptions } from "./markdown.js";
@@ -8,18 +8,10 @@ export interface Options extends MarkdownPluginOptions {
8
8
  * Additional setup for the app.
9
9
  */
10
10
  setup?(app: App, router: Router): void | Promise<void>;
11
- /**
12
- * The wrapper component for sandboxes.
13
- */
14
- Sandbox?: () => Promise<Component>;
15
11
  /**
16
12
  * Additional setup for the sandbox app.
17
13
  */
18
14
  setupSandbox?(app: App): void | Promise<void>;
19
- /**
20
- * Custom wrapper component for `.vue.sandbox` imports.
21
- */
22
- SandboxIframe?: () => Promise<Component>;
23
15
  /**
24
16
  * The code highlighter.
25
17
  * - Markdown code blocks
@@ -76,9 +68,15 @@ export interface ResolvedOptions extends Omit<Options, "highlighter"> {
76
68
  };
77
69
  }
78
70
  /**
79
- * Add ability to access options (`docs/do11y/do11y.ts`)
80
- * through `do11y:options`, the home component through `do11y:home`,
81
- * and the layout component through `do11y:page-layout`.
71
+ * Adds the ability to import options and setup files.
72
+ *
73
+ * `do11y:options` `docs/do11y/do11y.ts`
74
+ *
75
+ * `do11y:home` → `docs/do11y/pages/Home.vue`
76
+ * `do11y:page-layout` → `docs/do11y/layout/Page.vue`
77
+ *
78
+ * `do11y:sandbox` → `docs/do11y/pages/Sandbox.vue`
79
+ * `do11y:sandbox-iframe` → `docs/do11y/layout/SandboxIframe.vue`
82
80
  */
83
81
  declare const _default: () => Plugin;
84
82
  export default _default;
@@ -2,37 +2,41 @@ import { existsSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { do11y } from "../files.js";
4
4
  /**
5
- * Add ability to access options (`docs/do11y/do11y.ts`)
6
- * through `do11y:options`, the home component through `do11y:home`,
7
- * and the layout component through `do11y:page-layout`.
5
+ * Adds the ability to import options and setup files.
6
+ *
7
+ * `do11y:options` `docs/do11y/do11y.ts`
8
+ *
9
+ * `do11y:home` → `docs/do11y/pages/Home.vue`
10
+ * `do11y:page-layout` → `docs/do11y/layout/Page.vue`
11
+ *
12
+ * `do11y:sandbox` → `docs/do11y/pages/Sandbox.vue`
13
+ * `do11y:sandbox-iframe` → `docs/do11y/layout/SandboxIframe.vue`
8
14
  */
9
- export default () => ({
10
- name: "do11y:options",
11
- async resolveId(id, importer) {
12
- if (id === "do11y:options") {
13
- return this.resolve(join(do11y, "do11y.js"), importer);
14
- }
15
- if (id === "do11y:home") {
16
- const homeFile = join(do11y, "pages", "Home.vue");
17
- /* prettier-ignore */
18
- return existsSync(homeFile)
19
- ? this.resolve(homeFile, importer)
20
- : `\0do11y:home`;
21
- }
22
- if (id === "do11y:page-layout") {
23
- const pageLayoutFile = join(do11y, "layout", "Page.vue");
24
- /* prettier-ignore */
25
- return existsSync(pageLayoutFile)
26
- ? this.resolve(pageLayoutFile, importer)
27
- : `\0do11y:page-layout`;
28
- }
29
- },
30
- async load(id) {
31
- if (id === `\0do11y:home` || id === `\0do11y:page-layout`) {
32
- return {
33
- code: "export default undefined",
34
- moduleType: "js",
35
- };
36
- }
37
- },
38
- });
15
+ export default () => {
16
+ const setupFiles = {
17
+ "do11y:options": join(do11y, "do11y.js"),
18
+ "do11y:home": join(do11y, "pages", "Home.vue"),
19
+ "do11y:page-layout": join(do11y, "layout", "Page.vue"),
20
+ "do11y:sandbox": join(do11y, "pages", "Sandbox.vue"),
21
+ "do11y:sandbox-iframe": join(do11y, "layout", "SandboxIframe.vue"),
22
+ };
23
+ return {
24
+ name: "do11y:options",
25
+ async resolveId(id, importer) {
26
+ if (Object.keys(setupFiles).includes(id)) {
27
+ /* prettier-ignore */
28
+ return existsSync(setupFiles[id])
29
+ ? this.resolve(setupFiles[id], importer)
30
+ : `\0${id}`;
31
+ }
32
+ },
33
+ async load(id) {
34
+ if (id.startsWith("\0") && Object.keys(setupFiles).includes(id.replace("\0", ""))) {
35
+ return {
36
+ code: "export default undefined",
37
+ moduleType: "js",
38
+ };
39
+ }
40
+ },
41
+ };
42
+ };
@@ -2,8 +2,8 @@ import { join, parse } from "node:path";
2
2
  import { existsSync, readdirSync, readFileSync } from "node:fs";
3
3
  import { globSync } from "tinyglobby";
4
4
  import { root, do11y } from "../files.js";
5
- import fm from "front-matter";
6
5
  import { toParamId } from "./sandbox.js";
6
+ import fm from "front-matter";
7
7
  /**
8
8
  * Adds the ability to import routes through `do11y:routes`.
9
9
  *
@@ -24,9 +24,10 @@ export default () => {
24
24
  .map((path) => ({ path, frontmatter: fm(readFileSync(path, "utf-8")).attributes }))
25
25
  .filter((file) => typeof file.frontmatter.title === "string" && typeof file.frontmatter.slug === "string");
26
26
  /* prettier-ignore */
27
- const pages = existsSync(join(do11y, "pages"))
27
+ let pages = existsSync(join(do11y, "pages"))
28
28
  ? readdirSync(join(do11y, "pages")).filter((page) => page !== "Home.vue" && (page.endsWith(".md") || page.endsWith(".vue")))
29
29
  : [];
30
+ pages = pages.filter((page) => page !== "Sandbox.vue");
30
31
  return {
31
32
  name: "do11y:routes",
32
33
  resolveId(id) {
@@ -60,8 +61,6 @@ export default () => {
60
61
  import Home from 'do11y:home';
61
62
  import options from 'do11y:options';
62
63
 
63
- import { RouterView } from 'vue-router';
64
-
65
64
  const homeRoute = {
66
65
  path: "/",
67
66
  component: Home,
@@ -72,7 +71,7 @@ export default () => {
72
71
  }
73
72
  };
74
73
 
75
- const customRoutes = (options.routes ?? []).map(page => ({
74
+ const customRoutes = (options?.routes ?? []).map(page => ({
76
75
  ...page,
77
76
 
78
77
  meta: {
@@ -2,7 +2,7 @@ import type { Plugin } from "vite";
2
2
  export declare const toParamId: (path: string) => string;
3
3
  /**
4
4
  * Creates a seprate sandbox app, and
5
- * adds access to sandbox components through `do11y:sandbox`.
5
+ * adds access to sandbox components through `do11y:sandboxes`.
6
6
  */
7
7
  declare const _default: () => Plugin;
8
8
  export default _default;
@@ -5,10 +5,10 @@ import { indexHtml } from "../html/plugin.js";
5
5
  export const toParamId = (path) => parse(path).name.toLowerCase().replace(".sandbox", "").replace(".vue", "");
6
6
  /**
7
7
  * Creates a seprate sandbox app, and
8
- * adds access to sandbox components through `do11y:sandbox`.
8
+ * adds access to sandbox components through `do11y:sandboxes`.
9
9
  */
10
10
  export default () => {
11
- const moduleId = "do11y:sandbox";
11
+ const moduleId = "do11y:sandboxes";
12
12
  const resolvedModuleId = "\0" + moduleId;
13
13
  const sandboxFiles = globSync(["(docs|src|packages)/**/*.sandbox.vue"], {
14
14
  ignore: ["**/node_modules/**", "**/dist/**"],
@@ -17,7 +17,7 @@ export default () => {
17
17
  cwd: root,
18
18
  });
19
19
  return {
20
- name: "do11y:sandbox",
20
+ name: "do11y:sandboxes",
21
21
  ...indexHtml(ui, "sandbox"),
22
22
  resolveId(id) {
23
23
  if (id === moduleId) {
package/dist/ui/index.js CHANGED
@@ -1 +1 @@
1
- import{createApp as e,createBlock as t,defineComponent as n,onBeforeMount as r,openBlock as i,resolveComponent as a,unref as o}from"vue";import s from"do11y:options";import{createRouter as c,createWebHistory as l}from"vue-router";import u from"do11y:routes";import d from"do11y:page-layout";import f from"do11y:css";var p=n({__name:`Page`,setup(e){return r(async()=>{let e=document.createElement(`style`);e.innerHTML=f,document.head.appendChild(e)}),(e,n)=>{let r=a(`RouterView`);return o(d)?(i(),t(o(d),{key:0})):(i(),t(r,{key:1}))}}});(async()=>{let t=c({history:l(`/`),routes:u,scrollBehavior(e,t,n){if(!e.hash)return;let r=document.querySelector(e.hash);if(!r)return;let i=parseFloat(getComputedStyle(r).scrollMarginTop);return{el:e.hash,top:isNaN(i)?n?.top??0:i}}}),n=e(p);await s.setup?.(n,t),n.use(t),n.mount(`#app`)})();
1
+ import{createApp as e,createBlock as t,defineComponent as n,onBeforeMount as r,openBlock as i,resolveComponent as a,unref as o}from"vue";import{createRouter as s,createWebHistory as c}from"vue-router";import l from"do11y:routes";import u from"do11y:options";import d from"do11y:page-layout";import f from"do11y:css";var p=n({__name:`Page`,setup(e){return r(async()=>{let e=document.createElement(`style`);e.innerHTML=f,document.head.appendChild(e)}),(e,n)=>{let r=a(`RouterView`);return o(d)?(i(),t(o(d),{key:0})):(i(),t(r,{key:1}))}}});(async()=>{let t=s({history:c(`/`),routes:l,scrollBehavior(e,t,n){if(!e.hash)return;let r=document.querySelector(e.hash);if(!r)return;let i=parseFloat(getComputedStyle(r).scrollMarginTop);return{el:e.hash,top:isNaN(i)?n?.top??0:i}}}),n=e(p);await u?.setup?.(n,t),n.use(t),n.mount(`#app`)})();
@@ -1 +1 @@
1
- import{computed as e,createBlock as t,createElementBlock as n,defineComponent as r,mergeProps as i,onBeforeMount as a,openBlock as o,shallowRef as s,unref as c}from"vue";import l from"do11y:options";var u=[`title`,`src`],d=r({__name:`SandboxIframe`,props:{title:{},id:{},url:{},highlightedSource:{},highlightedStylelessSource:{},highlightedCssSource:{},passedProps:{}},setup(r){let d=r,f=e(()=>`/sandbox?id=${d.id}`),p=s();return a(async()=>{p.value=(await l.SandboxIframe?.())?.default}),(e,a)=>p.value?(o(),t(c(p),i({key:0,title:r.title,id:r.id,url:f.value,"highlighted-source":r.highlightedSource,"highlighted-css-source":r.highlightedCssSource,"highlighted-styleless-source":r.highlightedStylelessSource},r.passedProps),null,16,[`title`,`id`,`url`,`highlighted-source`,`highlighted-css-source`,`highlighted-styleless-source`])):(o(),n(`iframe`,{key:1,title:r.title,src:f.value},null,8,u))}});export{d as default};
1
+ import{computed as e,createBlock as t,createElementBlock as n,defineComponent as r,mergeProps as i,openBlock as a,unref as o}from"vue";import s from"do11y:sandbox-iframe";var c=[`title`,`src`],l=r({__name:`SandboxIframe`,props:{title:{},id:{},url:{},highlightedSource:{},highlightedStylelessSource:{},highlightedCssSource:{},passedProps:{}},setup(r){let l=r,u=e(()=>`/sandbox?id=${l.id}`);return(e,l)=>o(s)?(a(),t(o(s),i({key:0,title:r.title,id:r.id,url:u.value,"highlighted-source":r.highlightedSource,"highlighted-css-source":r.highlightedCssSource,"highlighted-styleless-source":r.highlightedStylelessSource},r.passedProps),null,16,[`title`,`id`,`url`,`highlighted-source`,`highlighted-css-source`,`highlighted-styleless-source`])):(a(),n(`iframe`,{key:1,title:r.title,src:u.value},null,8,c))}});export{l as default};
@@ -1 +1 @@
1
- import{createApp as e,createBlock as t,createCommentVNode as n,defineComponent as r,onBeforeMount as i,openBlock as a,shallowRef as o,unref as s,withCtx as c}from"vue";import l from"do11y:options";import{parseQuery as u}from"vue-router";import d from"do11y:sandbox";e(r({__name:`Sandbox`,setup(e){let r=u(window.location.search),f=o(),p=o();return i(async()=>{let{component:e}=d.find(({url:e})=>e===r.id)??{};f.value=(await l.Sandbox?.())?.default,p.value=await e?.()}),(e,r)=>f.value?(a(),t(s(f),{key:0},{default:c(()=>[p.value?(a(),t(s(p),{key:0})):n(``,!0)]),_:1})):n(``,!0)}})).mount(`#app`);
1
+ import{createApp as e,createBlock as t,createCommentVNode as n,defineComponent as r,onBeforeMount as i,openBlock as a,shallowRef as o,unref as s,withCtx as c}from"vue";import{parseQuery as l}from"vue-router";import u from"do11y:sandboxes";import d from"do11y:sandbox";e(r({__name:`Sandbox`,setup(e){let r=l(window.location.search),f=o();return i(async()=>{let{component:e}=u.find(({url:e})=>e===r.id)??{};f.value=await e?.()}),(e,r)=>s(d)?(a(),t(s(d),{key:0},{default:c(()=>[f.value?(a(),t(s(f),{key:0})):n(``,!0)]),_:1})):n(``,!0)}})).mount(`#app`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "do11y",
3
- "version": "0.4.3",
3
+ "version": "0.5.1",
4
4
  "description": "A bare-bones tool to document Vue components.",
5
5
  "keywords": [
6
6
  "docs-generator",
package/src/types.d.ts CHANGED
@@ -16,11 +16,13 @@ declare module "do11y:routes" {
16
16
  declare module "do11y:options" {
17
17
  import type { Options } from "do11y";
18
18
 
19
- const options: Omit<Options, "Layout" | "Sandbox" | "SandboxIframe"> & {
20
- Layout: () => Promise<{ default: Component }>;
21
- Sandbox?: () => Promise<{ default: Component }>;
22
- SandboxIframe?: () => Promise<{ default: Component }>;
23
- };
19
+ const options:
20
+ | (Omit<Options, "Layout" | "Sandbox" | "SandboxIframe"> & {
21
+ Layout: () => Promise<{ default: Component }>;
22
+ Sandbox?: () => Promise<{ default: Component }>;
23
+ SandboxIframe?: () => Promise<{ default: Component }>;
24
+ })
25
+ | undefined;
24
26
 
25
27
  export default options;
26
28
  }
@@ -37,12 +39,24 @@ declare module "do11y:page-layout" {
37
39
  export default layout;
38
40
  }
39
41
 
42
+ declare module "do11y:sandbox" {
43
+ import type { Component } from "vue";
44
+ const sandbox: Component | undefined;
45
+ export default sandbox;
46
+ }
47
+
48
+ declare module "do11y:sandbox-iframe" {
49
+ import type { Component } from "vue";
50
+ const iframe: Component | undefined;
51
+ export default iframe;
52
+ }
53
+
40
54
  declare module "do11y:css" {
41
55
  const css: string;
42
56
  export default string;
43
57
  }
44
58
 
45
- declare module "do11y:sandbox" {
59
+ declare module "do11y:sandboxes" {
46
60
  import type { Component } from "vue";
47
61
 
48
62
  const sandboxes: {