mountly-vite-plugin 1.3.0 → 1.6.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 +28 -0
- package/dist/docs.d.ts +31 -0
- package/dist/embed.d.ts +74 -0
- package/dist/externals.d.ts +11 -0
- package/dist/index.d.ts +5 -10
- package/dist/index.js +1064 -39
- package/dist/props.d.ts +61 -0
- package/package.json +11 -1
package/README.md
CHANGED
|
@@ -78,6 +78,34 @@ to compose them into a config you already own:
|
|
|
78
78
|
| `mountlyCssAsText` | import CSS as a string, for adopting into a shadow root |
|
|
79
79
|
| `getFrameworkPeerExternals` | the externals list for a peer build |
|
|
80
80
|
|
|
81
|
+
## Script-tag component libraries
|
|
82
|
+
|
|
83
|
+
`defineElementsConfig({ prefix, elements })` turns typed React/Vue/Svelte
|
|
84
|
+
components into lazily-loaded custom elements, and emits `embed.d.ts` and
|
|
85
|
+
`custom-elements.json` alongside `embed.js`.
|
|
86
|
+
|
|
87
|
+
Elements render in light DOM, so the consuming page's design system reaches in.
|
|
88
|
+
Pass `shadow: true` when the host is not one you trust: every element in the
|
|
89
|
+
distribution then renders into its own shadow root, and the build emits one
|
|
90
|
+
stylesheet that it injects into no document.
|
|
91
|
+
|
|
92
|
+
Pass `peer: true` when one page loads several distributions, such as widgets
|
|
93
|
+
from several teams. The build leaves the framework, its mountly adapter and
|
|
94
|
+
mountly's runtime as bare imports (`react`, `mountly-react`, `mountly/embed`),
|
|
95
|
+
and the page maps them once in an import map, so every distribution shares one
|
|
96
|
+
React. Without it, each `embed.js` works alone on any page.
|
|
97
|
+
|
|
98
|
+
`custom-elements.json` carries each component's JSDoc as its description, and
|
|
99
|
+
each prop's JSDoc, its type as written (`"paid" | "overdue"`) and a JSON Schema
|
|
100
|
+
derived from that type. JSDoc tags add constraints: `@minimum`, `@maximum`,
|
|
101
|
+
`@minLength`, `@maxLength`, `@pattern` and `@format`. `@slot` tags declare the
|
|
102
|
+
slots a component renders, and the element fills them from the page's children.
|
|
103
|
+
Slots need a `shadow: true` distribution, and the build warns without one.
|
|
104
|
+
|
|
105
|
+
See the [complete guide](https://mountly.dev/concepts/script-embeds/) and the
|
|
106
|
+
[React](../../docs/examples/react-embed) and
|
|
107
|
+
[mixed-framework](../../docs/examples/mixed-embed) examples.
|
|
108
|
+
|
|
81
109
|
## TypeScript
|
|
82
110
|
|
|
83
111
|
`mountlyManifestFragmentPlugin` reads exports from the TypeScript checker and
|
package/dist/docs.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type ExtractOptions } from "./props.js";
|
|
2
|
+
/** A JSON Schema, as far as the build can derive one from a TypeScript type. */
|
|
3
|
+
export type PropSchema = Record<string, unknown>;
|
|
4
|
+
export interface ComponentDocs {
|
|
5
|
+
/** The component's JSDoc summary. */
|
|
6
|
+
description?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Per prop: its JSDoc summary, its type as written (`"paid" | "overdue"`), and
|
|
9
|
+
* a JSON Schema derived from that type plus any `@minimum`, `@maximum`,
|
|
10
|
+
* `@minLength`, `@maxLength`, `@pattern` or `@format` tags.
|
|
11
|
+
*/
|
|
12
|
+
props: Record<string, {
|
|
13
|
+
description?: string;
|
|
14
|
+
type?: string;
|
|
15
|
+
schema?: PropSchema;
|
|
16
|
+
}>;
|
|
17
|
+
/** `@slot` tags on the component: `@slot - body` or `@slot actions - the buttons`. */
|
|
18
|
+
slots?: Array<{
|
|
19
|
+
name: string;
|
|
20
|
+
description: string;
|
|
21
|
+
}>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The prose a reader of the component's source would see: the JSDoc on the
|
|
25
|
+
* component and on each prop, and each prop's type as the author wrote it.
|
|
26
|
+
* The prop table says how to wire a prop; this says what it is for, which is
|
|
27
|
+
* what a person browsing a catalog — or a model composing from one — needs.
|
|
28
|
+
*
|
|
29
|
+
* Best effort: anything unreadable is simply absent, never an error.
|
|
30
|
+
*/
|
|
31
|
+
export declare function extractDocs(code: string, options?: ExtractOptions): ComponentDocs;
|
package/dist/embed.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { type UserConfig } from "vite";
|
|
2
|
+
import { type MountlyWidgetFramework } from "./externals.js";
|
|
3
|
+
import { type PropSpec } from "./props.js";
|
|
4
|
+
export interface MountlyElementEntry {
|
|
5
|
+
/** Browser-compatible component source, also importable directly by your app. */
|
|
6
|
+
component: string;
|
|
7
|
+
exportName?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Override the adapter for this element. Inferred from the file extension, so
|
|
10
|
+
* this is only for a component whose extension does not say what it is — a
|
|
11
|
+
* Vue `defineComponent` written in a `.ts` file, say.
|
|
12
|
+
*/
|
|
13
|
+
framework?: MountlyWidgetFramework;
|
|
14
|
+
/** Override the prop table when the component's props type lives elsewhere. */
|
|
15
|
+
props?: PropSpec[];
|
|
16
|
+
/** Core trigger syntax. Defaults to mounting when connected. */
|
|
17
|
+
trigger?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface MountlyElementsConfigOptions {
|
|
20
|
+
/**
|
|
21
|
+
* Namespace for the generated tags. Custom element names need a dash, and
|
|
22
|
+
* the consumer's page is not yours — `acme` gives `<acme-payments-summary>`.
|
|
23
|
+
*/
|
|
24
|
+
prefix: string;
|
|
25
|
+
/** A glob of component files, or an explicit tag → component map. */
|
|
26
|
+
elements: string | string[] | Record<string, string | MountlyElementEntry>;
|
|
27
|
+
/**
|
|
28
|
+
* Project root. Only needed when the config is not loaded from it — a
|
|
29
|
+
* monorepo running the build from elsewhere, say. Defaults to `process.cwd()`.
|
|
30
|
+
*/
|
|
31
|
+
root?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Render every element into a shadow root instead of the host's light DOM.
|
|
34
|
+
*
|
|
35
|
+
* Light DOM is the default because the usual consumer is a page that wants
|
|
36
|
+
* its own design system to reach in — a CMS template, a partner site running
|
|
37
|
+
* your tokens. Turn this on when the host is one you do not trust to leave
|
|
38
|
+
* your component alone, or that you must not affect: the host's CSS cannot
|
|
39
|
+
* reach in, and your CSS stops being emitted into its document.
|
|
40
|
+
*
|
|
41
|
+
* The whole distribution shares the setting, because it describes the kind
|
|
42
|
+
* of host you ship to, not the component.
|
|
43
|
+
*/
|
|
44
|
+
shadow?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Leave the framework (React, Vue or Svelte), its mountly adapter and
|
|
47
|
+
* mountly's runtime as bare imports, for the page's import map to resolve.
|
|
48
|
+
*
|
|
49
|
+
* Off by default, because then one script tag works on any page. Turn it on
|
|
50
|
+
* when one page loads several distributions — widgets from several teams,
|
|
51
|
+
* say — so they share one copy of React instead of each bringing its own.
|
|
52
|
+
* The page must map every bare specifier the build leaves behind (`react`,
|
|
53
|
+
* `react-dom/client`, `mountly-react`, `mountly/embed`, …).
|
|
54
|
+
*/
|
|
55
|
+
peer?: boolean;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Route each `new Worker(…)` that means the platform's Worker through the
|
|
59
|
+
* cross-origin shim. Parsed, not pattern-matched: the same characters in a
|
|
60
|
+
* string, template or comment are content, and an inline worker's source is one
|
|
61
|
+
* of those strings. A call is left alone when any enclosing scope binds
|
|
62
|
+
* `Worker` (a parameter, a catch, a var, a let, a class, an import), since that
|
|
63
|
+
* call constructs the author's Worker.
|
|
64
|
+
*/
|
|
65
|
+
export declare function shimWorkers(code: string): string | null;
|
|
66
|
+
/**
|
|
67
|
+
* Build a script-tag distribution: one file registers every tag, and each
|
|
68
|
+
* component, its framework and its CSS arrive only when an element connects.
|
|
69
|
+
*
|
|
70
|
+
* The author writes an ordinary React/Vue/Svelte component. Its props type is
|
|
71
|
+
* read at build time, so the consumer gets real attributes, real properties and
|
|
72
|
+
* real DOM events with nothing to configure on either side.
|
|
73
|
+
*/
|
|
74
|
+
export declare function defineElementsConfig(options: MountlyElementsConfigOptions): UserConfig;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Which imports a build leaves for the page to provide, per framework. */
|
|
2
|
+
export type MountlyWidgetFramework = "react" | "vue" | "svelte";
|
|
3
|
+
export declare function getFrameworkPeerExternals(framework: MountlyWidgetFramework): Array<string | RegExp>;
|
|
4
|
+
/**
|
|
5
|
+
* The self-contained build's whole promise is "drop this file in a page and it
|
|
6
|
+
* works", so mountly's own runtime helpers are bundled in rather than
|
|
7
|
+
* externalised: the host then needs no import map at all. The peer build still
|
|
8
|
+
* externalises them, because sharing through the host's import map is the point
|
|
9
|
+
* of that build.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getSelfContainedExternals(framework: MountlyWidgetFramework): Array<string | RegExp>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import type { Plugin, UserConfig } from "vite";
|
|
2
2
|
export { mountlyHostPlugin, type MountlyHostPluginOptions } from "./host.js";
|
|
3
3
|
export { mountlyManifestFragmentPlugin, type ManifestFragmentPluginOptions } from "./fragment.js";
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
/**
|
|
7
|
-
* The self-contained build's whole promise is "drop this file in a page and it
|
|
8
|
-
* works", so mountly's own runtime helpers are bundled in rather than
|
|
9
|
-
* externalised: the host then needs no import map at all. The peer build still
|
|
10
|
-
* externalises them, because sharing through the host's import map is the point
|
|
11
|
-
* of that build.
|
|
12
|
-
*/
|
|
13
|
-
export declare function getSelfContainedExternals(framework: MountlyWidgetFramework): Array<string | RegExp>;
|
|
4
|
+
import { getFrameworkPeerExternals, getSelfContainedExternals, type MountlyWidgetFramework } from "./externals.js";
|
|
5
|
+
export { getFrameworkPeerExternals, getSelfContainedExternals, type MountlyWidgetFramework };
|
|
14
6
|
export interface MountlyCssAsTextOptions {
|
|
15
7
|
include?: string | RegExp | (string | RegExp)[];
|
|
16
8
|
}
|
|
@@ -70,3 +62,6 @@ export interface DefineMountlyWidgetConfigOptions {
|
|
|
70
62
|
featureExport?: string;
|
|
71
63
|
}
|
|
72
64
|
export declare function defineMountlyWidgetConfig(options?: DefineMountlyWidgetConfigOptions): UserConfig[];
|
|
65
|
+
export { defineElementsConfig, type MountlyElementsConfigOptions, type MountlyElementEntry, } from "./embed.js";
|
|
66
|
+
export { extractDocs, type ComponentDocs, type PropSchema } from "./docs.js";
|
|
67
|
+
export { extractProps, type PropSpec, type PropKind } from "./props.js";
|