polaris-vue-elements 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/LICENSE +21 -0
- package/README.md +108 -0
- package/dist/generated/components.d.ts +62 -0
- package/dist/generated/components.d.ts.map +1 -0
- package/dist/generated/metadata.d.ts +64 -0
- package/dist/generated/metadata.d.ts.map +1 -0
- package/dist/generated/types.d.ts +980 -0
- package/dist/generated/types.d.ts.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3446 -0
- package/dist/index.js.map +1 -0
- package/dist/overrides.d.ts +18 -0
- package/dist/overrides.d.ts.map +1 -0
- package/dist/runtime/createWrapper.d.ts +68 -0
- package/dist/runtime/createWrapper.d.ts.map +1 -0
- package/package.json +85 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hand-written v-model mappings for Polaris web components.
|
|
3
|
+
*
|
|
4
|
+
* The Custom Elements Manifest has no concept of v-model, so this small map tells
|
|
5
|
+
* `createWrapper` which prop/event pair to bind `modelValue` / `update:modelValue` to,
|
|
6
|
+
* keyed by tag name. Every entry is verified against the manifest by
|
|
7
|
+
* `src/lib/__tests__/overrides.spec.ts` (the tag must exist and the event must be real),
|
|
8
|
+
* and that spec also fails if a new form-like component appears in the manifest without
|
|
9
|
+
* a matching entry here.
|
|
10
|
+
*/
|
|
11
|
+
export interface VModelOverride {
|
|
12
|
+
/** camelCase property name to bind `modelValue` to. */
|
|
13
|
+
prop: string;
|
|
14
|
+
/** DOM event name to listen for and re-emit as `update:modelValue`. */
|
|
15
|
+
event: string;
|
|
16
|
+
}
|
|
17
|
+
export declare const vModelOverrides: Record<string, VModelOverride>;
|
|
18
|
+
//# sourceMappingURL=overrides.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overrides.d.ts","sourceRoot":"","sources":["../src/lib/overrides.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,WAAW,cAAc;IAC7B,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAA;IACZ,uEAAuE;IACvE,KAAK,EAAE,MAAM,CAAA;CACd;AAED,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAsB1D,CAAA"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Describes a single prop derived from the Custom Elements Manifest.
|
|
3
|
+
*/
|
|
4
|
+
export interface ComponentPropMeta {
|
|
5
|
+
/** camelCase JS property name (e.g. `accessibilityLabel`). */
|
|
6
|
+
name: string;
|
|
7
|
+
/** Lowercase HTML attribute name, or `null` when the prop is property-only. */
|
|
8
|
+
attribute: string | null;
|
|
9
|
+
/** The manifest type text, verbatim (e.g. `"auto" | "primary" | "secondary"`). */
|
|
10
|
+
type: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Describes a single Polaris web component, as derived from the manifest.
|
|
14
|
+
*/
|
|
15
|
+
export interface ComponentMeta {
|
|
16
|
+
/** The custom element tag name (e.g. `s-button`). */
|
|
17
|
+
tagName: string;
|
|
18
|
+
props: ComponentPropMeta[];
|
|
19
|
+
events: string[];
|
|
20
|
+
slots: string[];
|
|
21
|
+
}
|
|
22
|
+
type UnknownRecord = Record<string, unknown>;
|
|
23
|
+
/**
|
|
24
|
+
* Derives `onX` event-listener props from an events shape `E` (e.g.
|
|
25
|
+
* `{ click: CustomEvent }` -> `{ onClick?: (event: CustomEvent) => void }`), the way Vue's
|
|
26
|
+
* template compiler maps `@click` to an `onClick` prop.
|
|
27
|
+
*/
|
|
28
|
+
export type EventListenerProps<E> = {
|
|
29
|
+
[K in keyof E as `on${Capitalize<string & K>}`]?: (event: E[K]) => void;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* A lightweight constructor-shaped type for the props of a generated wrapper component,
|
|
33
|
+
* used purely so callers (and template type-checking) see the manifest-derived prop
|
|
34
|
+
* and event-listener types. Deliberately not `DefineComponent<...>` — casting to that
|
|
35
|
+
* type here trips a TS "two different types with this name" recursion error, since the
|
|
36
|
+
* concrete component defined below is itself a `DefineComponent` instantiated with
|
|
37
|
+
* different type args.
|
|
38
|
+
*/
|
|
39
|
+
export type WrapperComponent<P, E = UnknownRecord, El extends HTMLElement = HTMLElement> = {
|
|
40
|
+
new (): {
|
|
41
|
+
$props: Partial<P> & EventListenerProps<E> & {
|
|
42
|
+
modelValue?: unknown;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* The wrapped custom element's root DOM node, typed to include any imperative
|
|
46
|
+
* methods declared on it (e.g. `ModalElement#showOverlay`). Vue single-root
|
|
47
|
+
* components' `$el` IS the root element at runtime, so this is truthful typing —
|
|
48
|
+
* no runtime shim is involved.
|
|
49
|
+
*/
|
|
50
|
+
$el: El;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Creates a Vue component that wraps a single Polaris custom element.
|
|
55
|
+
*
|
|
56
|
+
* - All manifest-derived props are declared so they don't leak into `$attrs`.
|
|
57
|
+
* - Props that map to an HTML attribute are serialized onto the element as attributes
|
|
58
|
+
* (booleans render as an empty-string attribute when `true`, and are omitted otherwise).
|
|
59
|
+
* - Props that are property-only (no matching attribute) are assigned directly as DOM
|
|
60
|
+
* properties on the element once it is mounted/updated.
|
|
61
|
+
* - Any remaining `$attrs` (class, style, aria-*, native event listeners, arbitrary
|
|
62
|
+
* attributes) are passed straight through to the underlying element.
|
|
63
|
+
* - When the tag has a v-model mapping in `overrides.ts`, a `modelValue` prop is
|
|
64
|
+
* accepted and an `update:modelValue` event is emitted from the mapped DOM event.
|
|
65
|
+
*/
|
|
66
|
+
export declare function createWrapper<P extends object = UnknownRecord, E extends object = UnknownRecord, El extends HTMLElement = HTMLElement>(meta: ComponentMeta): WrapperComponent<P, E, El>;
|
|
67
|
+
export {};
|
|
68
|
+
//# sourceMappingURL=createWrapper.d.ts.map
|
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AG,aAAa,EAChC,EAAE,SAAS,WAAW,GAAG,WAAW,EACpC,IAAI,EAAE,aAAa,GAAG,gBAAgB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CA8FjD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "polaris-vue-elements",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Typed Vue 3 wrapper components for Shopify Polaris web components.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://polaris-vue.vict0r.net",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/HQCuong/polaris-vue.git"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"shopify",
|
|
13
|
+
"polaris",
|
|
14
|
+
"web-components",
|
|
15
|
+
"vue",
|
|
16
|
+
"wrapper"
|
|
17
|
+
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"main": "./dist/index.js",
|
|
20
|
+
"module": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"sideEffects": false,
|
|
32
|
+
"scripts": {
|
|
33
|
+
"prepublishOnly": "npm run type-check && vitest run && npm run build:lib",
|
|
34
|
+
"dev": "vite",
|
|
35
|
+
"build": "run-p type-check \"build-only {@}\" --",
|
|
36
|
+
"preview": "vite preview",
|
|
37
|
+
"test:unit": "vitest",
|
|
38
|
+
"build-only": "vite build",
|
|
39
|
+
"build:lib": "vite build --config vite.lib.config.ts && vue-tsc -p tsconfig.lib.json",
|
|
40
|
+
"type-check": "vue-tsc --build",
|
|
41
|
+
"lint": "run-s \"lint:*\"",
|
|
42
|
+
"lint:oxlint": "oxlint . --fix",
|
|
43
|
+
"lint:eslint": "eslint . --fix --cache",
|
|
44
|
+
"format": "oxfmt src/",
|
|
45
|
+
"generate": "node scripts/generate.mjs",
|
|
46
|
+
"docs:dev": "vitepress dev docs",
|
|
47
|
+
"docs:build": "vitepress build docs",
|
|
48
|
+
"docs:preview": "vitepress preview docs",
|
|
49
|
+
"docs:generate": "node scripts/generate-docs.mjs"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"vue": "^3.5.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@shopify/polaris-types": "^1.0.7",
|
|
56
|
+
"@tsconfig/node24": "^24.0.4",
|
|
57
|
+
"@types/jsdom": "^28.0.3",
|
|
58
|
+
"@types/node": "^24.13.3",
|
|
59
|
+
"@vitejs/plugin-vue": "^6.0.8",
|
|
60
|
+
"@vitest/eslint-plugin": "^1.6.23",
|
|
61
|
+
"@vue/eslint-config-typescript": "^14.9.0",
|
|
62
|
+
"@vue/test-utils": "^2.4.11",
|
|
63
|
+
"@vue/tsconfig": "^0.9.1",
|
|
64
|
+
"eslint": "^10.7.0",
|
|
65
|
+
"eslint-config-prettier": "^10.1.8",
|
|
66
|
+
"eslint-plugin-oxlint": "~1.79.0",
|
|
67
|
+
"eslint-plugin-vue": "~10.9.2",
|
|
68
|
+
"jiti": "^2.7.0",
|
|
69
|
+
"jsdom": "^29.1.1",
|
|
70
|
+
"npm-run-all2": "^9.0.2",
|
|
71
|
+
"oxfmt": "^0.59.0",
|
|
72
|
+
"oxlint": "~1.79.0",
|
|
73
|
+
"typescript": "~6.0.0",
|
|
74
|
+
"vite": "^8.1.5",
|
|
75
|
+
"vite-plugin-vue-devtools": "^8.1.5",
|
|
76
|
+
"vitepress": "^1.6.4",
|
|
77
|
+
"vitest": "^4.1.10",
|
|
78
|
+
"vue": "^3.5.40",
|
|
79
|
+
"vue-eslint-parser": "^10.4.1",
|
|
80
|
+
"vue-tsc": "^3.3.7"
|
|
81
|
+
},
|
|
82
|
+
"engines": {
|
|
83
|
+
"node": "^22.18.0 || >=24.12.0"
|
|
84
|
+
}
|
|
85
|
+
}
|