From 988f9b56844b956b2452d3d4b1ab6d944b622eca Mon Sep 17 00:00:00 2001 From: Franck Freiburger Date: Thu, 11 Jan 2024 16:18:12 +0100 Subject: [PATCH] chore(docs): v0.9.0 API docs & examples --- docs/api/README.md | 69 +++++++++++++++++++++-------------------- docs/examples.md | 76 +++++++++++++++++++++++----------------------- 2 files changed, 74 insertions(+), 71 deletions(-) diff --git a/docs/api/README.md b/docs/api/README.md index cbe4faa..a77a10d 100644 --- a/docs/api/README.md +++ b/docs/api/README.md @@ -49,7 +49,7 @@ Ƭ **AbstractPath**: { toString: () => string } -*Defined in [types.ts:32](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/types.ts#L32)* +*Defined in [types.ts:32](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/types.ts#L32)* An abstract way to specify a path. It could be a simple string or a object like an URL. An AbstractPath must always be convertible to a string. @@ -65,7 +65,7 @@ ___ Ƭ **Cache**: { get: (key: string) => Promise ; set: (key: string, value: string) => Promise } -*Defined in [types.ts:20](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/types.ts#L20)* +*Defined in [types.ts:20](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/types.ts#L20)* #### Type declaration: @@ -80,7 +80,7 @@ ___ Ƭ **ContentData**: string \| ArrayBuffer -*Defined in [types.ts:71](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/types.ts#L71)* +*Defined in [types.ts:71](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/types.ts#L71)* ___ @@ -88,7 +88,7 @@ ___ Ƭ **CustomBlock**: { attrs: Record ; content: string ; type: string } -*Defined in [types.ts:109](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/types.ts#L109)* +*Defined in [types.ts:109](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/types.ts#L109)* A custom block @@ -106,7 +106,7 @@ ___ Ƭ **CustomBlockCallback**: (component: [ModuleExport](README.md#moduleexport)) => void -*Defined in [types.ts:103](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/types.ts#L103)* +*Defined in [types.ts:103](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/types.ts#L103)* CustomBlockCallback function type @@ -116,7 +116,7 @@ ___ Ƭ **File**: { getContentData: (asBinary: Boolean) => Promise<[ContentData](README.md#contentdata)\> ; type: string } -*Defined in [types.ts:77](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/types.ts#L77)* +*Defined in [types.ts:77](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/types.ts#L77)* Represents a file content and the extension name. @@ -133,7 +133,7 @@ ___ Ƭ **LangProcessor**: (source: string, preprocessOptions?: any) => Promise \| string -*Defined in [types.ts:399](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/types.ts#L399)* +*Defined in [types.ts:422](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/types.ts#L422)* ___ @@ -141,7 +141,7 @@ ___ Ƭ **Module**: { exports: [ModuleExport](README.md#moduleexport) } -*Defined in [types.ts:129](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/types.ts#L129)* +*Defined in [types.ts:128](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/types.ts#L128)* This just represents a loaded js module @@ -157,15 +157,15 @@ ___ Ƭ **ModuleCacheId**: string -*Defined in [types.ts:26](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/types.ts#L26)* +*Defined in [types.ts:26](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/types.ts#L26)* ___ ### ModuleExport -Ƭ **ModuleExport**: {} +Ƭ **ModuleExport**: {} \| null -*Defined in [types.ts:123](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/types.ts#L123)* +*Defined in [types.ts:123](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/types.ts#L123)* This just represents a loaded js module exports @@ -175,7 +175,7 @@ ___ Ƭ **ModuleHandler**: (type: string, getContentData: File[\"getContentData\"], path: [AbstractPath](README.md#abstractpath), options: [Options](README.md#options)) => Promise<[ModuleExport](README.md#moduleexport) \| null\> -*Defined in [types.ts:68](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/types.ts#L68)* +*Defined in [types.ts:68](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/types.ts#L68)* Used by the library when it needs to handle a does not know how to handle a given file type (eg. `.json` files). @@ -198,9 +198,9 @@ ___ ### Options -Ƭ **Options**: { additionalBabelParserPlugins?: babel\_ParserPlugin[] ; additionalBabelPlugins?: Record ; compiledCache?: [Cache](README.md#cache) ; delimiters?: [string, string] ; handleModule?: [ModuleHandler](README.md#modulehandler) ; moduleCache: Record<[ModuleCacheId](README.md#modulecacheid), LoadingType<[ModuleExport](README.md#moduleexport)\> \| [ModuleExport](README.md#moduleexport)\> ; pathResolve: [PathResolve](README.md#pathresolve) ; addStyle: (style: string, scopeId: string \| undefined) => void ; customBlockHandler?: (block: [CustomBlock](README.md#customblock), filename: [AbstractPath](README.md#abstractpath), options: [Options](README.md#options)) => Promise<[CustomBlockCallback](README.md#customblockcallback) \| undefined\> ; getFile: (path: [AbstractPath](README.md#abstractpath)) => Promise<[File](README.md#file) \| [ContentData](README.md#contentdata)\> ; getResource: (pathCx: [PathContext](README.md#pathcontext), options: [Options](README.md#options)) => [Resource](README.md#resource) ; loadModule?: (path: [AbstractPath](README.md#abstractpath), options: [Options](README.md#options)) => Promise<[ModuleExport](README.md#moduleexport) \| undefined\> ; log?: (type: string, ...data: any[]) => void } +Ƭ **Options**: { additionalBabelParserPlugins?: babel\_ParserPlugin[] ; additionalBabelPlugins?: Record ; compiledCache?: [Cache](README.md#cache) ; delimiters?: [string, string] ; devMode?: boolean ; handleModule?: [ModuleHandler](README.md#modulehandler) ; isCustomElement: (tag: string) => boolean \| undefined ; moduleCache: Record<[ModuleCacheId](README.md#modulecacheid), LoadingType<[ModuleExport](README.md#moduleexport)\> \| [ModuleExport](README.md#moduleexport)\> ; pathResolve: [PathResolve](README.md#pathresolve) ; whitespace?: \"preserve\" \| \"condense\" ; addStyle: (style: string, scopeId: string \| undefined) => void ; customBlockHandler?: (block: [CustomBlock](README.md#customblock), filename: [AbstractPath](README.md#abstractpath), options: [Options](README.md#options)) => Promise<[CustomBlockCallback](README.md#customblockcallback) \| undefined\> ; getFile: (path: [AbstractPath](README.md#abstractpath)) => Promise<[File](README.md#file) \| [ContentData](README.md#contentdata)\> ; getResource: (pathCx: [PathContext](README.md#pathcontext), options: [Options](README.md#options)) => [Resource](README.md#resource) ; loadModule?: (path: [AbstractPath](README.md#abstractpath), options: [Options](README.md#options)) => Promise<[ModuleExport](README.md#moduleexport) \| undefined\> ; log?: (type: string, ...data: any[]) => void } -*Defined in [types.ts:140](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/types.ts#L140)* +*Defined in [types.ts:139](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/types.ts#L139)* #### Type declaration: @@ -210,9 +210,12 @@ Name | Type | Description | `additionalBabelPlugins?` | Record | Additional babel plugins. [TBD] ```javascript ... ... ``` | `compiledCache?` | [Cache](README.md#cache) | [get](README.md#get)() and [set](README.md#set)() functions of this object are called when the lib needs to save or load already compiled code. get and set functions must return a `Promise` (or can be `async`). Since compilation consume a lot of CPU, is is always a good idea to provide this object. **example:** In the following example, we cache the compiled code in the browser's local storage. Note that local storage is a limited place (usually 5MB). Here we handle space limitation in a very basic way. Maybe (not tested), the following libraries may help you to gain more space [pako](https://github.com/nodeca/pako), [lz-string](https://github.com/pieroxy/lz-string/) ```javascript ... compiledCache: { set(key, str) { // naive storage space management for (;;) { try { // doc: https://developer.mozilla.org/en-US/docs/Web/API/Storage window.localStorage.setItem(key, str); break; } catch(ex) { // here we handle DOMException: Failed to execute 'setItem' on 'Storage': Setting the value of 'XXX' exceeded the quota window.localStorage.removeItem(window.localStorage.key(0)); } } }, get(key) { return window.localStorage.getItem(key); }, }, ... ``` | `delimiters?` | [string, string] | Sets the delimiters used for text interpolation within the template. Typically this is used to avoid conflicting with server-side frameworks that also use mustache syntax. ```javascript ... ... ``` | +`devMode?` | boolean | Set development mode prevent minification, allow debugger statement, | `handleModule?` | [ModuleHandler](README.md#modulehandler) | Handle additional module types (eg. '.svg', '.json' ). see [ModuleHandler](README.md#modulehandler) | +`isCustomElement` | (tag: string) => boolean \| undefined | Specifies a check method to recognize native custom elements. see. https://vuejs.org/api/application.html#app-config-compileroptions-iscustomelement note: this option has no effect on vue2 | `moduleCache` | Record<[ModuleCacheId](README.md#modulecacheid), LoadingType<[ModuleExport](README.md#moduleexport)\> \| [ModuleExport](README.md#moduleexport)\> | Initial cache that will contain resolved dependencies. All new modules go here. `vue` must initially be contained in this object. [moduleCache](README.md#modulecache) is mandatory and should be shared between options objects used for you application (note that you can also pass the same options object through multiple loadModule calls) It is recommended to provide a prototype-less object (`Object.create(null)`) to avoid potential conflict with `Object` properties (constructor, __proto__, hasOwnProperty, ...). ​ * See also [[options.loadModule]]. **example:** ```javascript ... moduleCache: Object.assign(Object.create(null), { vue: Vue, }), ... ``` | `pathResolve` | [PathResolve](README.md#pathresolve) | Abstact path handling | +`whitespace?` | \"preserve\" \| \"condense\" | Whitespace handling strategy see https://github.com/vuejs/vue/tree/dev/packages/vue-template-compiler#options | `addStyle` | (style: string, scopeId: string \| undefined) => void | - | `customBlockHandler?` | (block: [CustomBlock](README.md#customblock), filename: [AbstractPath](README.md#abstractpath), options: [Options](README.md#options)) => Promise<[CustomBlockCallback](README.md#customblockcallback) \| undefined\> | - | `getFile` | (path: [AbstractPath](README.md#abstractpath)) => Promise<[File](README.md#file) \| [ContentData](README.md#contentdata)\> | - | @@ -226,10 +229,10 @@ ___ Ƭ **PathContext**: { refPath: [AbstractPath](README.md#abstractpath) ; relPath: [AbstractPath](README.md#abstractpath) } -*Defined in [types.ts:41](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/types.ts#L41)* +*Defined in [types.ts:41](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/types.ts#L41)* A PathContext represents a path (relPath) relative to an abolute path (refPath) -Note that relPath is not necessary relative, but it is, relPath is relative to refPath. +Note that relPath is not necessary relative, but when it is, relPath is relative to refPath. #### Type declaration: @@ -244,7 +247,7 @@ ___ Ƭ **PathResolve**: (pathCx: [PathContext](README.md#pathcontext)) => [AbstractPath](README.md#abstractpath) -*Defined in [types.ts:50](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/types.ts#L50)* +*Defined in [types.ts:50](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/types.ts#L50)* relative to absolute module path resolution @@ -254,7 +257,7 @@ ___ Ƭ **Resource**: { getContent: () => Promise<[File](README.md#file)\> ; id: [ModuleCacheId](README.md#modulecacheid) ; path: [AbstractPath](README.md#abstractpath) } -*Defined in [types.ts:88](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/types.ts#L88)* +*Defined in [types.ts:88](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/types.ts#L88)* Represents a resource. @@ -270,11 +273,11 @@ Name | Type | Description | ### version -• `Const` **version**: string = process.env.VERSION +• `Const` **version**: string = process.env.VERSION as string -*Defined in [tools.ts:47](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/tools.ts#L47)* +*Defined in [tools.ts:49](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/tools.ts#L49)* -*Defined in [index.ts:26](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/index.ts#L26)* +*Defined in [index.ts:26](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/index.ts#L26)* the version of the library (process.env.VERSION is set by webpack, at compile-time) @@ -284,7 +287,7 @@ ___ • `Const` **vueVersion**: string -*Defined in [createSFCModule.ts:4](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/createSFCModule.ts#L4)* +*Defined in [createSFCModule.ts:4](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/createSFCModule.ts#L4)* ## Functions @@ -292,7 +295,7 @@ ___ ▸ **buildTemplateProcessor**(`processor`: [LangProcessor](README.md#langprocessor)): object -*Defined in [index.ts:179](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/index.ts#L179)* +*Defined in [index.ts:184](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/index.ts#L184)* Convert a function to template processor interface (consolidate) @@ -314,7 +317,7 @@ ___ ▸ **createSFCModule**(`source`: string, `filename`: [AbstractPath](README.md#abstractpath), `options`: [Options](README.md#options)): Promise<[ModuleExport](README.md#moduleexport)\> -*Defined in [createSFCModule.ts:3](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/createSFCModule.ts#L3)* +*Defined in [createSFCModule.ts:3](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/createSFCModule.ts#L3)* #### Parameters: @@ -332,7 +335,7 @@ ___ ▸ **defaultGetResource**(`pathCx`: [PathContext](README.md#pathcontext), `options`: [Options](README.md#options)): [Resource](README.md#resource) -*Defined in [index.ts:76](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/index.ts#L76)* +*Defined in [index.ts:76](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/index.ts#L76)* Default getResource implementation by default, getContent() use the file extension as file type. @@ -350,9 +353,9 @@ ___ ### defaultHandleModule -▸ **defaultHandleModule**(`type`: string, `getContentData`: File[\"getContentData\"], `path`: [AbstractPath](README.md#abstractpath), `options`: [Options](README.md#options)): Promise<[ModuleExport](README.md#moduleexport) \| null\> +▸ **defaultHandleModule**(`type`: string, `getContentData`: File[\"getContentData\"], `path`: [AbstractPath](README.md#abstractpath), `options`: [Options](README.md#options)): Promise<[ModuleExport](README.md#moduleexport) \| undefined\> -*Defined in [tools.ts:370](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/tools.ts#L370)* +*Defined in [tools.ts:388](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/tools.ts#L388)* Default implementation of handleModule @@ -365,7 +368,7 @@ Name | Type | `path` | [AbstractPath](README.md#abstractpath) | `options` | [Options](README.md#options) | -**Returns:** Promise<[ModuleExport](README.md#moduleexport) \| null\> +**Returns:** Promise<[ModuleExport](README.md#moduleexport) \| undefined\> ___ @@ -373,7 +376,7 @@ ___ ▸ `Const`**defaultPathResolve**(`__namedParameters`: { refPath: [AbstractPath](README.md#abstractpath) ; relPath: [AbstractPath](README.md#abstractpath) }): string \| [AbstractPath](README.md#abstractpath) -*Defined in [index.ts:53](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/index.ts#L53)* +*Defined in [index.ts:53](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/index.ts#L53)* Default resolve implementation resolve() should handle 3 situations : @@ -395,11 +398,11 @@ ___ ▸ **loadModule**(`path`: [AbstractPath](README.md#abstractpath), `options?`: [Options](README.md#options)): Promise<[ModuleExport](README.md#moduleexport)\> -*Defined in [index.ts:152](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/index.ts#L152)* +*Defined in [index.ts:157](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/index.ts#L157)* This is the main function. This function is intended to be used only to load the entry point of your application. -If for some reason you need to use it in your components, be sure to share at least the options.`compiledCache` object between all calls. +If for some reason you need to use it in your components, be sure to share at least the options.`moduleCache` object between all calls. #### Parameters: @@ -449,7 +452,7 @@ ___ ▸ **loadModuleInternal**(`pathCx`: [PathContext](README.md#pathcontext), `options`: [Options](README.md#options)): Promise<[ModuleExport](README.md#moduleexport)\> -*Defined in [tools.ts:258](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/tools.ts#L258)* +*Defined in [tools.ts:276](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/tools.ts#L276)* #### Parameters: @@ -466,6 +469,6 @@ Name | Type | ▪ `Const` **targetBrowserBabelPlugins**: object -*Defined in [tools.ts:205](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/4211825/src/tools.ts#L205)* +*Defined in [tools.ts:211](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/70777c8/src/tools.ts#L211)* #### Properties: diff --git a/docs/examples.md b/docs/examples.md index 11f456c..219f129 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -25,7 +25,7 @@ find [more examples here](https://github.com/FranckFreiburger/vue3-sfc-loader/di # Examples -:warning: **beware**, the following examples are sticky to version *0.8.4*. For your use, you would prefer the [latest version](../README.md#dist) +:warning: **beware**, the following examples are sticky to version *0.9.0*. For your use, you would prefer the [latest version](../README.md#dist) **Try the examples locally** Since most browsers do not allow you to access local filesystem, you can start a small [express](https://expressjs.com/) server to run these examples. @@ -68,7 +68,7 @@ In the following examples, for convenience, we just returns static content as fi
- + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +