@limetech/kompendium 1.1.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/LICENSE +21 -0
- package/README.md +313 -0
- package/dist/cjs/_commonjsHelpers-BJu3ubxk.js +13 -0
- package/dist/cjs/_commonjsHelpers-BJu3ubxk.js.map +1 -0
- package/dist/cjs/anchor-scroll-BmplAyR0.js +69 -0
- package/dist/cjs/anchor-scroll-BmplAyR0.js.map +1 -0
- package/dist/cjs/index-DYiJ6dQL.js +1866 -0
- package/dist/cjs/index-DYiJ6dQL.js.map +1 -0
- package/dist/cjs/index.cjs.js +3 -0
- package/dist/cjs/index.cjs.js.map +1 -0
- package/dist/cjs/kompendium-app.kompendium-darkmode-switch.kompendium-navigation.kompendium-search.stencil-route.stencil-route-switch.stencil-router.entry.cjs.js.map +1 -0
- package/dist/cjs/kompendium-app_7.cjs.entry.js +2924 -0
- package/dist/cjs/kompendium-code.cjs.entry.js +2724 -0
- package/dist/cjs/kompendium-code.entry.cjs.js.map +1 -0
- package/dist/cjs/kompendium-component.cjs.entry.js +207 -0
- package/dist/cjs/kompendium-component.entry.cjs.js.map +1 -0
- package/dist/cjs/kompendium-debug.cjs.entry.js +47 -0
- package/dist/cjs/kompendium-debug.entry.cjs.js.map +1 -0
- package/dist/cjs/kompendium-example-code.cjs.entry.js +20 -0
- package/dist/cjs/kompendium-example-code.entry.cjs.js.map +1 -0
- package/dist/cjs/kompendium-example-markdown.cjs.entry.js +165 -0
- package/dist/cjs/kompendium-example-markdown.entry.cjs.js.map +1 -0
- package/dist/cjs/kompendium-guide.cjs.entry.js +33 -0
- package/dist/cjs/kompendium-guide.entry.cjs.js.map +1 -0
- package/dist/cjs/kompendium-markdown.cjs.entry.js +48923 -0
- package/dist/cjs/kompendium-markdown.entry.cjs.js.map +1 -0
- package/dist/cjs/kompendium-playground.cjs.entry.js +89 -0
- package/dist/cjs/kompendium-playground.entry.cjs.js.map +1 -0
- package/dist/cjs/kompendium-proplist.kompendium-taglist.entry.cjs.js.map +1 -0
- package/dist/cjs/kompendium-proplist_2.cjs.entry.js +49 -0
- package/dist/cjs/kompendium-type.cjs.entry.js +83 -0
- package/dist/cjs/kompendium-type.entry.cjs.js.map +1 -0
- package/dist/cjs/kompendium.cjs.js +25 -0
- package/dist/cjs/kompendium.cjs.js.map +1 -0
- package/dist/cjs/loader.cjs.js +13 -0
- package/dist/cjs/loader.cjs.js.map +1 -0
- package/dist/cjs/markdown-types-B884tLd-.js +15 -0
- package/dist/cjs/markdown-types-B884tLd-.js.map +1 -0
- package/dist/cjs/methods-DoA78dOH.js +97 -0
- package/dist/cjs/methods-DoA78dOH.js.map +1 -0
- package/dist/cjs/types-SjA7Kcy_.js +8 -0
- package/dist/cjs/types-SjA7Kcy_.js.map +1 -0
- package/dist/collection/assets/favicon.svg +65 -0
- package/dist/collection/assets/icons/bookmark-fill.svg +1 -0
- package/dist/collection/assets/icons/danger.svg +1 -0
- package/dist/collection/assets/icons/debug.svg +1 -0
- package/dist/collection/assets/icons/important.svg +1 -0
- package/dist/collection/assets/icons/info.svg +1 -0
- package/dist/collection/assets/icons/logo.svg +1 -0
- package/dist/collection/assets/icons/note.svg +1 -0
- package/dist/collection/assets/icons/search.svg +1 -0
- package/dist/collection/assets/icons/tip.svg +1 -0
- package/dist/collection/assets/icons/warning.svg +1 -0
- package/dist/collection/assets/logotype.svg +64 -0
- package/dist/collection/collection-manifest.json +35 -0
- package/dist/collection/components/anchor-scroll.js +61 -0
- package/dist/collection/components/anchor-scroll.js.map +1 -0
- package/dist/collection/components/app/app.css +125 -0
- package/dist/collection/components/app/app.js +149 -0
- package/dist/collection/components/app/app.js.map +1 -0
- package/dist/collection/components/code/code.css +250 -0
- package/dist/collection/components/code/code.js +82 -0
- package/dist/collection/components/code/code.js.map +1 -0
- package/dist/collection/components/code/examples/code.js +14 -0
- package/dist/collection/components/code/examples/code.js.map +1 -0
- package/dist/collection/components/component/component.css +383 -0
- package/dist/collection/components/component/component.js +191 -0
- package/dist/collection/components/component/component.js.map +1 -0
- package/dist/collection/components/component/templates/events.js +32 -0
- package/dist/collection/components/component/templates/events.js.map +1 -0
- package/dist/collection/components/component/templates/examples.js +17 -0
- package/dist/collection/components/component/templates/examples.js.map +1 -0
- package/dist/collection/components/component/templates/methods.js +54 -0
- package/dist/collection/components/component/templates/methods.js.map +1 -0
- package/dist/collection/components/component/templates/props.js +36 -0
- package/dist/collection/components/component/templates/props.js.map +1 -0
- package/dist/collection/components/component/templates/slots.js +14 -0
- package/dist/collection/components/component/templates/slots.js.map +1 -0
- package/dist/collection/components/component/templates/style.js +14 -0
- package/dist/collection/components/component/templates/style.js.map +1 -0
- package/dist/collection/components/darkmode-switch/darkmode-switch.css +141 -0
- package/dist/collection/components/darkmode-switch/darkmode-switch.js +90 -0
- package/dist/collection/components/darkmode-switch/darkmode-switch.js.map +1 -0
- package/dist/collection/components/darkmode-switch/types.js +2 -0
- package/dist/collection/components/darkmode-switch/types.js.map +1 -0
- package/dist/collection/components/debug/debug.js +146 -0
- package/dist/collection/components/debug/debug.js.map +1 -0
- package/dist/collection/components/guide/guide.js +61 -0
- package/dist/collection/components/guide/guide.js.map +1 -0
- package/dist/collection/components/markdown/examples/markdown-example.js +150 -0
- package/dist/collection/components/markdown/examples/markdown-example.js.map +1 -0
- package/dist/collection/components/markdown/examples/markdown.js +14 -0
- package/dist/collection/components/markdown/examples/markdown.js.map +1 -0
- package/dist/collection/components/markdown/markdown-types.js +8 -0
- package/dist/collection/components/markdown/markdown-types.js.map +1 -0
- package/dist/collection/components/markdown/markdown.css +660 -0
- package/dist/collection/components/markdown/markdown.js +83 -0
- package/dist/collection/components/markdown/markdown.js.map +1 -0
- package/dist/collection/components/navigation/navigation.css +403 -0
- package/dist/collection/components/navigation/navigation.js +184 -0
- package/dist/collection/components/navigation/navigation.js.map +1 -0
- package/dist/collection/components/playground/playground.css +198 -0
- package/dist/collection/components/playground/playground.js +174 -0
- package/dist/collection/components/playground/playground.js.map +1 -0
- package/dist/collection/components/playground/playground.types.js +2 -0
- package/dist/collection/components/playground/playground.types.js.map +1 -0
- package/dist/collection/components/proplist/proplist.css +334 -0
- package/dist/collection/components/proplist/proplist.js +53 -0
- package/dist/collection/components/proplist/proplist.js.map +1 -0
- package/dist/collection/components/search/search.css +183 -0
- package/dist/collection/components/search/search.js +76 -0
- package/dist/collection/components/search/search.js.map +1 -0
- package/dist/collection/components/taglist/taglist.css +58 -0
- package/dist/collection/components/taglist/taglist.js +82 -0
- package/dist/collection/components/taglist/taglist.js.map +1 -0
- package/dist/collection/components/type/templates/alias.js +11 -0
- package/dist/collection/components/type/templates/alias.js.map +1 -0
- package/dist/collection/components/type/templates/enum.js +25 -0
- package/dist/collection/components/type/templates/enum.js.map +1 -0
- package/dist/collection/components/type/templates/interface.js +13 -0
- package/dist/collection/components/type/templates/interface.js.map +1 -0
- package/dist/collection/components/type/type.js +97 -0
- package/dist/collection/components/type/type.js.map +1 -0
- package/dist/collection/index.js +4 -0
- package/dist/collection/index.js.map +1 -0
- package/dist/collection/kompendium/config.js +7 -0
- package/dist/collection/kompendium/config.js.map +1 -0
- package/dist/collection/kompendium/filesystem.js +9 -0
- package/dist/collection/kompendium/filesystem.js.map +1 -0
- package/dist/collection/kompendium/generator.js +217 -0
- package/dist/collection/kompendium/generator.js.map +1 -0
- package/dist/collection/kompendium/guides.js +30 -0
- package/dist/collection/kompendium/guides.js.map +1 -0
- package/dist/collection/kompendium/index.js +2 -0
- package/dist/collection/kompendium/index.js.map +1 -0
- package/dist/collection/kompendium/markdown-admonitions.js +82 -0
- package/dist/collection/kompendium/markdown-admonitions.js.map +1 -0
- package/dist/collection/kompendium/markdown-code.js +40 -0
- package/dist/collection/kompendium/markdown-code.js.map +1 -0
- package/dist/collection/kompendium/markdown-frontmatter.js +12 -0
- package/dist/collection/kompendium/markdown-frontmatter.js.map +1 -0
- package/dist/collection/kompendium/markdown-nodes.js +10 -0
- package/dist/collection/kompendium/markdown-nodes.js.map +1 -0
- package/dist/collection/kompendium/markdown-typelinks.js +115 -0
- package/dist/collection/kompendium/markdown-typelinks.js.map +1 -0
- package/dist/collection/kompendium/markdown.js +35 -0
- package/dist/collection/kompendium/markdown.js.map +1 -0
- package/dist/collection/kompendium/menu.js +149 -0
- package/dist/collection/kompendium/menu.js.map +1 -0
- package/dist/collection/kompendium/schema.js +167 -0
- package/dist/collection/kompendium/schema.js.map +1 -0
- package/dist/collection/kompendium/search.js +144 -0
- package/dist/collection/kompendium/search.js.map +1 -0
- package/dist/collection/kompendium/source.js +81 -0
- package/dist/collection/kompendium/source.js.map +1 -0
- package/dist/collection/kompendium/test/fixtures/basic.js +48 -0
- package/dist/collection/kompendium/test/fixtures/basic.js.map +1 -0
- package/dist/collection/kompendium/test/fixtures/filtering/example-type.js +2 -0
- package/dist/collection/kompendium/test/fixtures/filtering/example-type.js.map +1 -0
- package/dist/collection/kompendium/test/fixtures/filtering/node-modules-type.js +2 -0
- package/dist/collection/kompendium/test/fixtures/filtering/node-modules-type.js.map +1 -0
- package/dist/collection/kompendium/test/fixtures/filtering/private-types.js +2 -0
- package/dist/collection/kompendium/test/fixtures/filtering/private-types.js.map +1 -0
- package/dist/collection/kompendium/test/fixtures/filtering/stencil-component-types.js +2 -0
- package/dist/collection/kompendium/test/fixtures/filtering/stencil-component-types.js.map +1 -0
- package/dist/collection/kompendium/test/fixtures/filtering/test-helper-type.js +2 -0
- package/dist/collection/kompendium/test/fixtures/filtering/test-helper-type.js.map +1 -0
- package/dist/collection/kompendium/test/fixtures/filtering/valid-types.js +29 -0
- package/dist/collection/kompendium/test/fixtures/filtering/valid-types.js.map +1 -0
- package/dist/collection/kompendium/typedoc.js +481 -0
- package/dist/collection/kompendium/typedoc.js.map +1 -0
- package/dist/collection/kompendium/watch.js +9 -0
- package/dist/collection/kompendium/watch.js.map +1 -0
- package/dist/collection/types.js +2 -0
- package/dist/collection/types.js.map +1 -0
- package/dist/config.ts +8 -0
- package/dist/esm/_commonjsHelpers-BFTU3MAI.js +10 -0
- package/dist/esm/_commonjsHelpers-BFTU3MAI.js.map +1 -0
- package/dist/esm/anchor-scroll-BAGXN2n6.js +65 -0
- package/dist/esm/anchor-scroll-BAGXN2n6.js.map +1 -0
- package/dist/esm/index-9UrzenzW.js +1857 -0
- package/dist/esm/index-9UrzenzW.js.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/kompendium-app.kompendium-darkmode-switch.kompendium-navigation.kompendium-search.stencil-route.stencil-route-switch.stencil-router.entry.js.map +1 -0
- package/dist/esm/kompendium-app_7.entry.js +2916 -0
- package/dist/esm/kompendium-code.entry.js +2722 -0
- package/dist/esm/kompendium-code.entry.js.map +1 -0
- package/dist/esm/kompendium-component.entry.js +205 -0
- package/dist/esm/kompendium-component.entry.js.map +1 -0
- package/dist/esm/kompendium-debug.entry.js +45 -0
- package/dist/esm/kompendium-debug.entry.js.map +1 -0
- package/dist/esm/kompendium-example-code.entry.js +18 -0
- package/dist/esm/kompendium-example-code.entry.js.map +1 -0
- package/dist/esm/kompendium-example-markdown.entry.js +163 -0
- package/dist/esm/kompendium-example-markdown.entry.js.map +1 -0
- package/dist/esm/kompendium-guide.entry.js +31 -0
- package/dist/esm/kompendium-guide.entry.js.map +1 -0
- package/dist/esm/kompendium-markdown.entry.js +48921 -0
- package/dist/esm/kompendium-markdown.entry.js.map +1 -0
- package/dist/esm/kompendium-playground.entry.js +87 -0
- package/dist/esm/kompendium-playground.entry.js.map +1 -0
- package/dist/esm/kompendium-proplist.kompendium-taglist.entry.js.map +1 -0
- package/dist/esm/kompendium-proplist_2.entry.js +46 -0
- package/dist/esm/kompendium-type.entry.js +81 -0
- package/dist/esm/kompendium-type.entry.js.map +1 -0
- package/dist/esm/kompendium.js +21 -0
- package/dist/esm/kompendium.js.map +1 -0
- package/dist/esm/loader.js +11 -0
- package/dist/esm/loader.js.map +1 -0
- package/dist/esm/markdown-types-Ajsawr_9.js +12 -0
- package/dist/esm/markdown-types-Ajsawr_9.js.map +1 -0
- package/dist/esm/methods-BAjd6f7g.js +94 -0
- package/dist/esm/methods-BAjd6f7g.js.map +1 -0
- package/dist/esm/types-BIPLEi1G.js +6 -0
- package/dist/esm/types-BIPLEi1G.js.map +1 -0
- package/dist/filesystem.ts +9 -0
- package/dist/generator.ts +302 -0
- package/dist/guides.ts +49 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.js +1 -0
- package/dist/index.ts +1 -0
- package/dist/kompendium/index.esm.js +2 -0
- package/dist/kompendium/index.esm.js.map +1 -0
- package/dist/kompendium/kompendium-app.kompendium-darkmode-switch.kompendium-navigation.kompendium-search.stencil-route.stencil-route-switch.stencil-router.entry.esm.js.map +1 -0
- package/dist/kompendium/kompendium-code.entry.esm.js.map +1 -0
- package/dist/kompendium/kompendium-component.entry.esm.js.map +1 -0
- package/dist/kompendium/kompendium-debug.entry.esm.js.map +1 -0
- package/dist/kompendium/kompendium-example-code.entry.esm.js.map +1 -0
- package/dist/kompendium/kompendium-example-markdown.entry.esm.js.map +1 -0
- package/dist/kompendium/kompendium-guide.entry.esm.js.map +1 -0
- package/dist/kompendium/kompendium-markdown.entry.esm.js.map +1 -0
- package/dist/kompendium/kompendium-playground.entry.esm.js.map +1 -0
- package/dist/kompendium/kompendium-proplist.kompendium-taglist.entry.esm.js.map +1 -0
- package/dist/kompendium/kompendium-type.entry.esm.js.map +1 -0
- package/dist/kompendium/kompendium.css +47 -0
- package/dist/kompendium/kompendium.esm.js +2 -0
- package/dist/kompendium/kompendium.esm.js.map +1 -0
- package/dist/kompendium/loader.esm.js.map +1 -0
- package/dist/kompendium/p-15e4b2c0.entry.js +2 -0
- package/dist/kompendium/p-15e4b2c0.entry.js.map +1 -0
- package/dist/kompendium/p-1cf0168f.entry.js +2 -0
- package/dist/kompendium/p-1cf0168f.entry.js.map +1 -0
- package/dist/kompendium/p-29c23c89.entry.js +2 -0
- package/dist/kompendium/p-29c23c89.entry.js.map +1 -0
- package/dist/kompendium/p-3981d11f.entry.js +2 -0
- package/dist/kompendium/p-3981d11f.entry.js.map +1 -0
- package/dist/kompendium/p-93f0548d.entry.js +2 -0
- package/dist/kompendium/p-93f0548d.entry.js.map +1 -0
- package/dist/kompendium/p-97b02575.entry.js +2 -0
- package/dist/kompendium/p-97b02575.entry.js.map +1 -0
- package/dist/kompendium/p-9UrzenzW.js +3 -0
- package/dist/kompendium/p-9UrzenzW.js.map +1 -0
- package/dist/kompendium/p-Ajsawr_9.js +2 -0
- package/dist/kompendium/p-Ajsawr_9.js.map +1 -0
- package/dist/kompendium/p-BAGXN2n6.js +2 -0
- package/dist/kompendium/p-BAGXN2n6.js.map +1 -0
- package/dist/kompendium/p-BFTU3MAI.js +2 -0
- package/dist/kompendium/p-BFTU3MAI.js.map +1 -0
- package/dist/kompendium/p-BIPLEi1G.js +2 -0
- package/dist/kompendium/p-BIPLEi1G.js.map +1 -0
- package/dist/kompendium/p-CnQEA7KO.js +2 -0
- package/dist/kompendium/p-CnQEA7KO.js.map +1 -0
- package/dist/kompendium/p-b0f95bd6.entry.js +2 -0
- package/dist/kompendium/p-b0f95bd6.entry.js.map +1 -0
- package/dist/kompendium/p-d9bcc473.entry.js +10 -0
- package/dist/kompendium/p-d9bcc473.entry.js.map +1 -0
- package/dist/kompendium/p-e36f3f1e.entry.js +2 -0
- package/dist/kompendium/p-e36f3f1e.entry.js.map +1 -0
- package/dist/kompendium/p-e52a2f57.entry.js +2 -0
- package/dist/kompendium/p-e52a2f57.entry.js.map +1 -0
- package/dist/kompendium/p-ec5861de.entry.js +2 -0
- package/dist/kompendium/p-ec5861de.entry.js.map +1 -0
- package/dist/markdown-admonitions.ts +112 -0
- package/dist/markdown-code.ts +51 -0
- package/dist/markdown-frontmatter.ts +19 -0
- package/dist/markdown-nodes.ts +23 -0
- package/dist/markdown-typelinks.ts +166 -0
- package/dist/markdown.ts +49 -0
- package/dist/menu.ts +189 -0
- package/dist/schema.ts +233 -0
- package/dist/search.ts +197 -0
- package/dist/source.ts +129 -0
- package/dist/typedoc.ts +665 -0
- package/dist/types/components/anchor-scroll.d.ts +36 -0
- package/dist/types/components/app/app.d.ts +22 -0
- package/dist/types/components/code/code.d.ts +26 -0
- package/dist/types/components/code/examples/code.d.ts +3 -0
- package/dist/types/components/component/component.d.ts +32 -0
- package/dist/types/components/component/templates/events.d.ts +5 -0
- package/dist/types/components/component/templates/examples.d.ts +9 -0
- package/dist/types/components/component/templates/methods.d.ts +5 -0
- package/dist/types/components/component/templates/props.d.ts +5 -0
- package/dist/types/components/component/templates/slots.d.ts +5 -0
- package/dist/types/components/component/templates/style.d.ts +5 -0
- package/dist/types/components/darkmode-switch/darkmode-switch.d.ts +18 -0
- package/dist/types/components/darkmode-switch/types.d.ts +2 -0
- package/dist/types/components/debug/debug.d.ts +24 -0
- package/dist/types/components/guide/guide.d.ts +14 -0
- package/dist/types/components/markdown/examples/markdown-example.d.ts +1 -0
- package/dist/types/components/markdown/examples/markdown.d.ts +7 -0
- package/dist/types/components/markdown/markdown-types.d.ts +2 -0
- package/dist/types/components/markdown/markdown.d.ts +20 -0
- package/dist/types/components/navigation/navigation.d.ts +35 -0
- package/dist/types/components/playground/playground.d.ts +32 -0
- package/dist/types/components/playground/playground.types.d.ts +1 -0
- package/dist/types/components/proplist/proplist.d.ts +12 -0
- package/dist/types/components/search/search.d.ts +15 -0
- package/dist/types/components/taglist/taglist.d.ts +16 -0
- package/dist/types/components/type/templates/alias.d.ts +4 -0
- package/dist/types/components/type/templates/enum.d.ts +4 -0
- package/dist/types/components/type/templates/interface.d.ts +4 -0
- package/dist/types/components/type/type.d.ts +15 -0
- package/dist/types/components.d.ts +517 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/kompendium/config.d.ts +2 -0
- package/dist/types/kompendium/filesystem.d.ts +1 -0
- package/dist/types/kompendium/generator.d.ts +4 -0
- package/dist/types/kompendium/guides.d.ts +9 -0
- package/dist/types/kompendium/index.d.ts +1 -0
- package/dist/types/kompendium/markdown-admonitions.d.ts +3 -0
- package/dist/types/kompendium/markdown-code.d.ts +2 -0
- package/dist/types/kompendium/markdown-frontmatter.d.ts +6 -0
- package/dist/types/kompendium/markdown-nodes.d.ts +12 -0
- package/dist/types/kompendium/markdown-typelinks.d.ts +21 -0
- package/dist/types/kompendium/markdown.d.ts +8 -0
- package/dist/types/kompendium/menu.d.ts +12 -0
- package/dist/types/kompendium/schema.d.ts +9 -0
- package/dist/types/kompendium/search.d.ts +3 -0
- package/dist/types/kompendium/source.d.ts +10 -0
- package/dist/types/kompendium/test/fixtures/basic.d.ts +65 -0
- package/dist/types/kompendium/test/fixtures/filtering/example-type.d.ts +8 -0
- package/dist/types/kompendium/test/fixtures/filtering/node-modules-type.d.ts +8 -0
- package/dist/types/kompendium/test/fixtures/filtering/private-types.d.ts +23 -0
- package/dist/types/kompendium/test/fixtures/filtering/stencil-component-types.d.ts +19 -0
- package/dist/types/kompendium/test/fixtures/filtering/test-helper-type.d.ts +8 -0
- package/dist/types/kompendium/test/fixtures/filtering/valid-types.d.ts +42 -0
- package/dist/types/kompendium/typedoc.d.ts +2 -0
- package/dist/types/kompendium/watch.d.ts +1 -0
- package/dist/types/stencil-public-runtime.d.ts +1746 -0
- package/dist/types/types.d.ts +119 -0
- package/dist/watch.ts +14 -0
- package/loader/cdn.js +1 -0
- package/loader/index.cjs.js +1 -0
- package/loader/index.d.ts +24 -0
- package/loader/index.es2017.js +1 -0
- package/loader/index.js +2 -0
- package/package.json +116 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import type { Node } from 'unist';
|
|
2
|
+
import { isElement, isParent, isTextNode } from './markdown-nodes';
|
|
3
|
+
|
|
4
|
+
type MapFn = (node: Node, index: number, parent: Node | null) => Node[];
|
|
5
|
+
|
|
6
|
+
export function typeLinks(
|
|
7
|
+
options: { types?: string[] } = {},
|
|
8
|
+
): (tree: Node) => Node {
|
|
9
|
+
return transformer(options.types);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const transformer =
|
|
13
|
+
(types: string[] = []) =>
|
|
14
|
+
(tree: Node): Node => {
|
|
15
|
+
if (types.length === 0) {
|
|
16
|
+
return tree;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const preCodeElements = collectPreCodeElements(tree);
|
|
20
|
+
|
|
21
|
+
return flatMap(tree, mapCodeNode(types, preCodeElements));
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function collectPreCodeElements(node: Node): Set<Node> {
|
|
25
|
+
const set = new Set<Node>();
|
|
26
|
+
collectPreCode(node, set);
|
|
27
|
+
|
|
28
|
+
return set;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function collectPreCode(node: Node, set: Set<Node>) {
|
|
32
|
+
if (!isParent(node)) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (isElement(node) && node.tagName === 'pre') {
|
|
37
|
+
for (const child of node.children) {
|
|
38
|
+
if (isElement(child) && child.tagName === 'code') {
|
|
39
|
+
set.add(child);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
for (const child of node.children) {
|
|
45
|
+
collectPreCode(child, set);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const mapCodeNode =
|
|
50
|
+
(types: string[] = [], preCodeElements: Set<Node>) =>
|
|
51
|
+
(node: Node, _: number, parent: Node | null) => {
|
|
52
|
+
if (!isTextNode(node)) {
|
|
53
|
+
return [node];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!parent || !isElement(parent)) {
|
|
57
|
+
return [node];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (parent.tagName !== 'code') {
|
|
61
|
+
return [node];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (preCodeElements.has(parent)) {
|
|
65
|
+
return [node];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return wrapText(node, types);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export function wrapText(node: { value: string }, types: string[] = []) {
|
|
72
|
+
return splitTypeString(node.value).map(createNode(types));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const createNode =
|
|
76
|
+
(types: string[] = []) =>
|
|
77
|
+
(type: string) => {
|
|
78
|
+
if (!types.includes(type)) {
|
|
79
|
+
return createTextNode(type);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return createLinkNode(type);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
function createTextNode(text: string) {
|
|
86
|
+
return {
|
|
87
|
+
type: 'text',
|
|
88
|
+
value: text,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function createLinkNode(type: string) {
|
|
93
|
+
return {
|
|
94
|
+
type: 'element',
|
|
95
|
+
tagName: 'a',
|
|
96
|
+
properties: {
|
|
97
|
+
href: `#/type/${type}`,
|
|
98
|
+
},
|
|
99
|
+
children: [
|
|
100
|
+
{
|
|
101
|
+
type: 'text',
|
|
102
|
+
value: type,
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function splitTypeString(typeString: string): string[] {
|
|
109
|
+
const pattern = /(\b\w+\b)+/g;
|
|
110
|
+
const types = typeString.match(pattern);
|
|
111
|
+
const result: string[] = [];
|
|
112
|
+
|
|
113
|
+
if (!types) {
|
|
114
|
+
return [typeString];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
let currentString = typeString;
|
|
118
|
+
types.forEach((type: string) => {
|
|
119
|
+
const index = currentString.indexOf(type);
|
|
120
|
+
if (index > 0) {
|
|
121
|
+
result.push(currentString.substring(0, index));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
result.push(type);
|
|
125
|
+
currentString = currentString.substring(index + type.length);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
if (currentString.length > 0) {
|
|
129
|
+
result.push(currentString);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return result;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function transformChildren(node: Node, fn: MapFn) {
|
|
136
|
+
if (!isParent(node)) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
node.children = node.children.flatMap((child, i) =>
|
|
141
|
+
transform(child, i, node, fn),
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function transform(
|
|
146
|
+
node: Node,
|
|
147
|
+
index: number,
|
|
148
|
+
parent: Node | null,
|
|
149
|
+
fn: MapFn,
|
|
150
|
+
): Node[] {
|
|
151
|
+
transformChildren(node, fn);
|
|
152
|
+
|
|
153
|
+
return fn(node, index, parent);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function flatMap(ast: Node, fn: MapFn): Node {
|
|
157
|
+
const result = transform(ast, 0, null, fn);
|
|
158
|
+
|
|
159
|
+
if (result.length !== 1) {
|
|
160
|
+
throw new Error(
|
|
161
|
+
`flatMap: root must map to exactly one node, got ${result.length}`,
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return result[0];
|
|
166
|
+
}
|
package/dist/markdown.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { unified } from 'unified';
|
|
2
|
+
import remarkParse from 'remark-parse';
|
|
3
|
+
import remarkFrontmatter from 'remark-frontmatter';
|
|
4
|
+
import remarkDirective from 'remark-directive';
|
|
5
|
+
import remarkGfm from 'remark-gfm';
|
|
6
|
+
import remarkRehype from 'remark-rehype';
|
|
7
|
+
import rehypeRaw from 'rehype-raw';
|
|
8
|
+
import rehypeSlug from 'rehype-slug';
|
|
9
|
+
import rehypeStringify from 'rehype-stringify';
|
|
10
|
+
import { saveFrontmatter } from './markdown-frontmatter';
|
|
11
|
+
import {
|
|
12
|
+
admonitions,
|
|
13
|
+
normalizeLegacyAdmonitions,
|
|
14
|
+
} from './markdown-admonitions';
|
|
15
|
+
import { kompendiumCode } from './markdown-code';
|
|
16
|
+
import { typeLinks } from './markdown-typelinks';
|
|
17
|
+
|
|
18
|
+
export interface File {
|
|
19
|
+
data: {
|
|
20
|
+
frontmatter?: Record<string, any>;
|
|
21
|
+
path?: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
toString(): string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function markdownToHtml(text: string, types = []): Promise<File> {
|
|
28
|
+
const normalized = normalizeLegacyAdmonitions(text);
|
|
29
|
+
|
|
30
|
+
const file = await unified()
|
|
31
|
+
.use(remarkParse)
|
|
32
|
+
.use(remarkGfm)
|
|
33
|
+
.use(remarkFrontmatter)
|
|
34
|
+
.use(saveFrontmatter)
|
|
35
|
+
.use(remarkDirective)
|
|
36
|
+
.use(admonitions)
|
|
37
|
+
.use(remarkRehype, { allowDangerousHtml: true })
|
|
38
|
+
.use(rehypeRaw)
|
|
39
|
+
.use(rehypeSlug)
|
|
40
|
+
.use(typeLinks, { types: types })
|
|
41
|
+
.use(kompendiumCode)
|
|
42
|
+
.use(rehypeStringify)
|
|
43
|
+
.process(normalized);
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
data: file.data as File['data'],
|
|
47
|
+
toString: () => file.toString(),
|
|
48
|
+
};
|
|
49
|
+
}
|
package/dist/menu.ts
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { JsonDocsComponent, JsonDocs } from '@stencil/core/internal';
|
|
2
|
+
import startCase from 'lodash/startCase';
|
|
3
|
+
import { MenuItem, KompendiumGuide, TypeDescription } from '../types';
|
|
4
|
+
|
|
5
|
+
export function createMenu(
|
|
6
|
+
docs: JsonDocs,
|
|
7
|
+
guides: KompendiumGuide[],
|
|
8
|
+
types: TypeDescription[],
|
|
9
|
+
): MenuItem[] {
|
|
10
|
+
let menu = [];
|
|
11
|
+
|
|
12
|
+
guides.forEach(addGuide(menu, ''));
|
|
13
|
+
menu = [...menu, createComponentMenu(docs), createTypeMenu(types)];
|
|
14
|
+
|
|
15
|
+
return menu;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const addGuide =
|
|
19
|
+
(menu: MenuItem[], path: string) => (guide: KompendiumGuide) => {
|
|
20
|
+
const subPath: string = guide.data.path.replace(path, '');
|
|
21
|
+
const parts = subPath.split('/');
|
|
22
|
+
const parentPath = `${path}/${parts[1]}`;
|
|
23
|
+
let submenu = menu.find((item) => item.path === parentPath + '/');
|
|
24
|
+
|
|
25
|
+
if (!submenu && parts.length === 2) {
|
|
26
|
+
const title = getGuideTitle(guide);
|
|
27
|
+
menu.push({
|
|
28
|
+
path: guide.data.path + '/',
|
|
29
|
+
title: title,
|
|
30
|
+
children: [],
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!submenu) {
|
|
37
|
+
submenu = {
|
|
38
|
+
path: parentPath + '/',
|
|
39
|
+
title: startCase(parts[1]),
|
|
40
|
+
children: [],
|
|
41
|
+
};
|
|
42
|
+
menu.push(submenu);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
addGuide(submenu.children, parentPath)(guide);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
function getGuideTitle(guide: KompendiumGuide): string {
|
|
49
|
+
const regex = /^#\s?(.+?)$/m;
|
|
50
|
+
const match = guide.content.match(regex);
|
|
51
|
+
|
|
52
|
+
return match?.[1];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function createComponentMenu(docs: JsonDocs): MenuItem {
|
|
56
|
+
const components = docs.components || [];
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
path: '/component/',
|
|
60
|
+
title: 'Components',
|
|
61
|
+
children: components
|
|
62
|
+
.filter(isNotExample)
|
|
63
|
+
.filter(isPublic)
|
|
64
|
+
.map(getComponentMenu),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function isExample(component: JsonDocsComponent): boolean {
|
|
69
|
+
return !!component.dirPath.match(/\/examples?$/);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function isNotExample(component: JsonDocsComponent) {
|
|
73
|
+
return !isExample(component);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function isPublic(component: JsonDocsComponent): boolean {
|
|
77
|
+
return !component.docsTags.find((tag) =>
|
|
78
|
+
['internal', 'private', 'ignore'].includes(tag.name),
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function getComponentMenu(component: JsonDocsComponent): MenuItem {
|
|
83
|
+
return {
|
|
84
|
+
path: `/component/${component.tag}/`,
|
|
85
|
+
title: getComponentTitle(component.tag),
|
|
86
|
+
children: [
|
|
87
|
+
getComponentPropertyMenu(component),
|
|
88
|
+
getComponentEventMenu(component),
|
|
89
|
+
getComponentMethodMenu(component),
|
|
90
|
+
getComponentSlotMenu(component),
|
|
91
|
+
getComponentStyleMenu(component),
|
|
92
|
+
].filter((item) => !!item),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function getComponentPropertyMenu(component: JsonDocsComponent): MenuItem {
|
|
97
|
+
if (!component.props.length) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
title: 'Properties',
|
|
103
|
+
path: `/component/${component.tag}/properties/`,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function getComponentEventMenu(component: JsonDocsComponent): MenuItem {
|
|
108
|
+
if (!component.events.length) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
title: 'Events',
|
|
114
|
+
path: `/component/${component.tag}/events/`,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function getComponentMethodMenu(component: JsonDocsComponent): MenuItem {
|
|
119
|
+
if (!component.methods.length) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
title: 'Methods',
|
|
125
|
+
path: `/component/${component.tag}/methods/`,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function getComponentSlotMenu(component: JsonDocsComponent): MenuItem {
|
|
130
|
+
if (!component.slots.length) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
title: 'Slots',
|
|
136
|
+
path: `/component/${component.tag}/slots/`,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function getComponentStyleMenu(component: JsonDocsComponent): MenuItem {
|
|
141
|
+
if (!component.styles.length) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
title: 'Styles',
|
|
147
|
+
path: `/component/${component.tag}/styles/`,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function getComponentTitle(tag: string): string {
|
|
152
|
+
const title = tag.split('-').slice(1).join(' ');
|
|
153
|
+
|
|
154
|
+
return title[0].toLocaleUpperCase() + title.slice(1);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function createApiMenu(): MenuItem {
|
|
158
|
+
return {
|
|
159
|
+
path: '/api/',
|
|
160
|
+
title: 'API',
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function createVersionMenu(): MenuItem {
|
|
165
|
+
return {
|
|
166
|
+
path: '/version/',
|
|
167
|
+
title: 'Versions',
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function createTypeMenu(types: TypeDescription[]): MenuItem {
|
|
172
|
+
return {
|
|
173
|
+
path: '/type/',
|
|
174
|
+
title: 'Types',
|
|
175
|
+
// Sort types alphabetically by name
|
|
176
|
+
children: types
|
|
177
|
+
.slice()
|
|
178
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
179
|
+
.map(getTypeMenu),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function getTypeMenu(type: TypeDescription): MenuItem {
|
|
184
|
+
return {
|
|
185
|
+
path: `/type/${type.name}/`,
|
|
186
|
+
title: type.name,
|
|
187
|
+
children: [],
|
|
188
|
+
};
|
|
189
|
+
}
|
package/dist/schema.ts
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { JsonDocsComponent, JsonDocsProp } from '@stencil/core/internal';
|
|
2
|
+
import {
|
|
3
|
+
ClassDescription,
|
|
4
|
+
InterfaceDescription,
|
|
5
|
+
TypeDescription,
|
|
6
|
+
} from '../types';
|
|
7
|
+
import { isExample } from './menu';
|
|
8
|
+
import negate from 'lodash/negate';
|
|
9
|
+
import startCase from 'lodash/startCase';
|
|
10
|
+
import zipObject from 'lodash/zipObject';
|
|
11
|
+
import pick from 'lodash/pick';
|
|
12
|
+
|
|
13
|
+
const ARRAY_PATTERN = /^(\w+)(<\w+>)?\[\]$|^Array<(.+)>$/;
|
|
14
|
+
const ENUM_PATTERN = /["'](\w+)["']\s?\|?/g;
|
|
15
|
+
const ID_PATTERN = /^number \| string$|string \| number$/g;
|
|
16
|
+
const TS_UTILITY_PATTERN = /(Partial|Required|Readonly|Array)<(.+?)>/g;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create schemas for the components that describe their interface
|
|
20
|
+
* @param {JsonDocsComponent[]} components the components
|
|
21
|
+
* @param {TypeDescription[]} types type definitions
|
|
22
|
+
* @returns {*} list of schemas for the components
|
|
23
|
+
*/
|
|
24
|
+
export function createSchemas(
|
|
25
|
+
components: JsonDocsComponent[],
|
|
26
|
+
types: TypeDescription[],
|
|
27
|
+
): Array<Record<string, any>> {
|
|
28
|
+
const componentSchemas =
|
|
29
|
+
components?.filter(negate(isExample)).map(createSchema(types)) || [];
|
|
30
|
+
const classSchemas = types?.filter(isClass)?.map(createSchema(types)) || [];
|
|
31
|
+
|
|
32
|
+
return [...componentSchemas, ...classSchemas];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const createSchema =
|
|
36
|
+
(types: TypeDescription[]) =>
|
|
37
|
+
(object: JsonDocsComponent | ClassDescription) => {
|
|
38
|
+
const definitions = createDefinitions(types);
|
|
39
|
+
const properties = createProps(object.props, definitions);
|
|
40
|
+
|
|
41
|
+
const schema: any = {
|
|
42
|
+
type: 'object',
|
|
43
|
+
$id: getSchemaId(object),
|
|
44
|
+
properties: properties,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const data = JSON.stringify(properties);
|
|
48
|
+
const definitionKeys = Object.keys(definitions).filter(
|
|
49
|
+
isReferenceUsed(data),
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
if (definitionKeys.length > 0) {
|
|
53
|
+
schema.definitions = pick(definitions, definitionKeys);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return schema;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
function getSchemaId(object: JsonDocsComponent | ClassDescription): string {
|
|
60
|
+
if (isClass(object)) {
|
|
61
|
+
return object.name;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return object.tag;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function createDefinitions(types: TypeDescription[]): Record<string, any> {
|
|
68
|
+
const interfaces: InterfaceDescription[] = types.filter(
|
|
69
|
+
(type) => type.type === 'interface',
|
|
70
|
+
) as any;
|
|
71
|
+
const keys = interfaces.map((i) => i.name);
|
|
72
|
+
const schemas = interfaces.map((i) => {
|
|
73
|
+
return {
|
|
74
|
+
type: 'object',
|
|
75
|
+
properties: createProps(i.props as JsonDocsProp[], {}),
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
return zipObject(keys, schemas);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function createProps(
|
|
83
|
+
props: Array<Partial<JsonDocsProp>>,
|
|
84
|
+
definitions: Record<string, any>,
|
|
85
|
+
) {
|
|
86
|
+
const keys = props?.map((prop) => prop.name) || [];
|
|
87
|
+
const schemas = props?.map(createPropSchema(definitions)) || [];
|
|
88
|
+
|
|
89
|
+
return zipObject(keys, schemas);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const createPropSchema =
|
|
93
|
+
(definitions: Record<string, any>) => (prop: JsonDocsProp) => {
|
|
94
|
+
const schema: any = {
|
|
95
|
+
type: getSchemaType(prop.type),
|
|
96
|
+
title: startCase(prop.name),
|
|
97
|
+
description: prop.docs,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
if (prop.default) {
|
|
101
|
+
schema.default = getDefaultValue(prop.default, schema.type);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (schema.type === 'array') {
|
|
105
|
+
schema.items = getSchemaItems(prop.type, definitions);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (schema.type === 'object') {
|
|
109
|
+
const ref = getSchemaPropertiesRef(prop.type, definitions);
|
|
110
|
+
|
|
111
|
+
if (ref) {
|
|
112
|
+
schema.$ref = ref;
|
|
113
|
+
} else {
|
|
114
|
+
schema.additionalProperties = true;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (schema.type === 'string') {
|
|
119
|
+
const oneOf = getOneOf(prop.type);
|
|
120
|
+
|
|
121
|
+
if (oneOf) {
|
|
122
|
+
schema.oneOf = oneOf;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return schema;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
function getDefaultValue(value: any, type: string) {
|
|
130
|
+
if (type === 'boolean') {
|
|
131
|
+
return value === 'true';
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (type === 'number') {
|
|
135
|
+
return Number(value);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (type !== 'string') {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (value === 'null') {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return value;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function getSchemaType(propType: string) {
|
|
150
|
+
if (['string', 'number', 'boolean'].includes(propType)) {
|
|
151
|
+
return propType;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (propType.match(ARRAY_PATTERN)) {
|
|
155
|
+
return 'array';
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (propType.match(ENUM_PATTERN) || propType.match(ID_PATTERN)) {
|
|
159
|
+
return 'string';
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return 'object';
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function getSchemaItems(propType: string, definitions: Record<string, any>) {
|
|
166
|
+
const result = propType.match(ARRAY_PATTERN);
|
|
167
|
+
const type = getSchemaType(result[1] || result[3]);
|
|
168
|
+
|
|
169
|
+
const items: any = {
|
|
170
|
+
type: type,
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
if (type === 'object') {
|
|
174
|
+
const ref = getSchemaPropertiesRef(result[1] || result[3], definitions);
|
|
175
|
+
|
|
176
|
+
if (ref) {
|
|
177
|
+
items.$ref = ref;
|
|
178
|
+
} else {
|
|
179
|
+
items.additionalProperties = true;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return items;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function getSchemaPropertiesRef(
|
|
187
|
+
propType: string,
|
|
188
|
+
definitions: Record<string, any>,
|
|
189
|
+
): string {
|
|
190
|
+
const definition = Object.keys(definitions).find((key) => key === propType);
|
|
191
|
+
if (definition) {
|
|
192
|
+
return '#/definitions/' + definition;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const type = propType.replace(TS_UTILITY_PATTERN, '$2');
|
|
196
|
+
if (type === propType) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return getSchemaPropertiesRef(type, definitions);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function getOneOf(propType: string) {
|
|
204
|
+
if (!ENUM_PATTERN.test(propType)) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const oneOf = propType.split('|').map((token) => {
|
|
209
|
+
const value = token.trim().replace(/["']/g, '');
|
|
210
|
+
|
|
211
|
+
return {
|
|
212
|
+
type: 'string',
|
|
213
|
+
const: value,
|
|
214
|
+
title: value,
|
|
215
|
+
};
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
if (!oneOf.length) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return oneOf;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const isReferenceUsed = (data: string) => (name: string) => {
|
|
226
|
+
const ref = '#/definitions/' + name;
|
|
227
|
+
|
|
228
|
+
return data.includes(ref);
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
function isClass(type: any): type is ClassDescription {
|
|
232
|
+
return type.type === 'class';
|
|
233
|
+
}
|