@tianditu/vue 0.0.0 → 0.0.1-edge.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 CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 Demo Macro
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Demo Macro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -3,7 +3,6 @@
3
3
  ![npm version](https://img.shields.io/npm/v/@tianditu/vue)
4
4
  ![npm downloads](https://img.shields.io/npm/dw/@tianditu/vue)
5
5
  ![npm license](https://img.shields.io/npm/l/@tianditu/vue)
6
- [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](https://www.contributor-covenant.org/version/2/1/code_of_conduct/)
7
6
 
8
7
  > Vue components for tianditu, powered by Demo Macro.
9
8
 
@@ -11,13 +10,13 @@
11
10
 
12
11
  ```bash
13
12
  # npm
14
- $ npm install -D @tianditu/web-components @tianditu/vue
13
+ $ npm install -D @tianditu/wc @tianditu/vue
15
14
 
16
15
  # yarn
17
- $ yarn add -D @tianditu/web-components @tianditu/vue
16
+ $ yarn add -D @tianditu/wc @tianditu/vue
18
17
 
19
18
  # pnpm
20
- $ pnpm add -D @tianditu/web-components @tianditu/vue
19
+ $ pnpm add -D @tianditu/wc @tianditu/vue
21
20
  ```
22
21
 
23
22
  ## License
@@ -0,0 +1,15 @@
1
+ import { JSX } from '@tianditu/wc';
2
+ import { Plugin } from 'vue';
3
+
4
+ interface InputProps<T> {
5
+ modelValue?: T;
6
+ }
7
+
8
+ declare const TdtControl: (props: JSX.TdtControl & InputProps<string | number | boolean> & {}) => any;
9
+ declare const TdtControlScale: (props: JSX.TdtControlScale & InputProps<string | number | boolean> & {}) => any;
10
+ declare const TdtControlZoom: (props: JSX.TdtControlZoom & InputProps<string | number | boolean> & {}) => any;
11
+ declare const TdtMap: (props: JSX.TdtMap & InputProps<string | number | boolean> & {}) => any;
12
+
13
+ declare const ComponentLibrary: Plugin;
14
+
15
+ export { ComponentLibrary, TdtControl, TdtControlScale, TdtControlZoom, TdtMap };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,15 @@
1
- export * from "./components";
2
- export * from "./plugin";
1
+ import { JSX } from '@tianditu/wc';
2
+ import { Plugin } from 'vue';
3
+
4
+ interface InputProps<T> {
5
+ modelValue?: T;
6
+ }
7
+
8
+ declare const TdtControl: (props: JSX.TdtControl & InputProps<string | number | boolean> & {}) => any;
9
+ declare const TdtControlScale: (props: JSX.TdtControlScale & InputProps<string | number | boolean> & {}) => any;
10
+ declare const TdtControlZoom: (props: JSX.TdtControlZoom & InputProps<string | number | boolean> & {}) => any;
11
+ declare const TdtMap: (props: JSX.TdtMap & InputProps<string | number | boolean> & {}) => any;
12
+
13
+ declare const ComponentLibrary: Plugin;
14
+
15
+ export { ComponentLibrary, TdtControl, TdtControlScale, TdtControlZoom, TdtMap };
package/dist/index.mjs CHANGED
@@ -1,2 +1,153 @@
1
- export * from "./components.mjs";
2
- export * from "./plugin.mjs";
1
+ import { defineComponent, ref, getCurrentInstance, inject, h } from 'vue';
2
+ import { applyPolyfills, defineCustomElements } from '@tianditu/wc/dist/loader';
3
+
4
+ const UPDATE_VALUE_EVENT = "update:modelValue";
5
+ const MODEL_VALUE = "modelValue";
6
+ const ROUTER_LINK_VALUE = "routerLink";
7
+ const NAV_MANAGER = "navManager";
8
+ const ROUTER_PROP_PREFIX = "router";
9
+ const ARIA_PROP_PREFIX = "aria";
10
+ const EMPTY_PROP = Symbol();
11
+ const DEFAULT_EMPTY_PROP = { default: EMPTY_PROP };
12
+ const getComponentClasses = (classes) => {
13
+ return classes?.split(" ") || [];
14
+ };
15
+ const getElementClasses = (ref2, componentClasses, defaultClasses = []) => {
16
+ return [...Array.from(ref2.value?.classList || []), ...defaultClasses].filter(
17
+ (c, i, self) => !componentClasses.has(c) && self.indexOf(c) === i
18
+ );
19
+ };
20
+ const defineContainer = (name, defineCustomElement, componentProps = [], modelProp, modelUpdateEvent, externalModelUpdateEvent) => {
21
+ if (defineCustomElement !== void 0) {
22
+ defineCustomElement();
23
+ }
24
+ const Container = defineComponent(
25
+ (props, { attrs, slots, emit }) => {
26
+ let modelPropValue = props[modelProp];
27
+ const containerRef = ref();
28
+ const classes = new Set(getComponentClasses(attrs.class));
29
+ const onVnodeBeforeMount = (vnode) => {
30
+ if (vnode.el) {
31
+ const eventsNames = Array.isArray(modelUpdateEvent) ? modelUpdateEvent : [modelUpdateEvent];
32
+ eventsNames.forEach((eventName) => {
33
+ vnode.el.addEventListener(eventName.toLowerCase(), (e) => {
34
+ modelPropValue = (e?.target)[modelProp];
35
+ emit(UPDATE_VALUE_EVENT, modelPropValue);
36
+ if (externalModelUpdateEvent) {
37
+ emit(externalModelUpdateEvent, e);
38
+ }
39
+ });
40
+ });
41
+ }
42
+ };
43
+ const currentInstance = getCurrentInstance();
44
+ const hasRouter = currentInstance?.appContext?.provides[NAV_MANAGER];
45
+ const navManager = hasRouter ? inject(NAV_MANAGER) : void 0;
46
+ const handleRouterLink = (ev) => {
47
+ const { routerLink } = props;
48
+ if (routerLink === EMPTY_PROP)
49
+ return;
50
+ if (navManager !== void 0) {
51
+ let navigationPayload = { event: ev };
52
+ for (const key in props) {
53
+ const value = props[key];
54
+ if (props.hasOwnProperty(key) && key.startsWith(ROUTER_PROP_PREFIX) && value !== EMPTY_PROP) {
55
+ navigationPayload[key] = value;
56
+ }
57
+ }
58
+ navManager.navigate(navigationPayload);
59
+ } else {
60
+ console.warn(
61
+ "Tried to navigate, but no router was found. Make sure you have mounted Vue Router."
62
+ );
63
+ }
64
+ };
65
+ return () => {
66
+ modelPropValue = props[modelProp];
67
+ getComponentClasses(attrs.class).forEach((value) => {
68
+ classes.add(value);
69
+ });
70
+ const oldClick = props.onClick;
71
+ const handleClick = (ev) => {
72
+ if (oldClick !== void 0) {
73
+ oldClick(ev);
74
+ }
75
+ if (!ev.defaultPrevented) {
76
+ handleRouterLink(ev);
77
+ }
78
+ };
79
+ let propsToAdd = {
80
+ ref: containerRef,
81
+ class: getElementClasses(containerRef, classes),
82
+ onClick: handleClick,
83
+ onVnodeBeforeMount: modelUpdateEvent ? onVnodeBeforeMount : void 0
84
+ };
85
+ for (const key in props) {
86
+ const value = props[key];
87
+ if (props.hasOwnProperty(key) && value !== EMPTY_PROP || key.startsWith(ARIA_PROP_PREFIX)) {
88
+ propsToAdd[key] = value;
89
+ }
90
+ }
91
+ if (modelProp) {
92
+ if (props[MODEL_VALUE] !== EMPTY_PROP) {
93
+ propsToAdd = {
94
+ ...propsToAdd,
95
+ [modelProp]: props[MODEL_VALUE]
96
+ };
97
+ } else if (modelPropValue !== EMPTY_PROP) {
98
+ propsToAdd = {
99
+ ...propsToAdd,
100
+ [modelProp]: modelPropValue
101
+ };
102
+ }
103
+ }
104
+ return h(name, propsToAdd, slots.default && slots.default());
105
+ };
106
+ }
107
+ );
108
+ if (typeof Container !== "function") {
109
+ Container.name = name;
110
+ Container.props = {
111
+ [ROUTER_LINK_VALUE]: DEFAULT_EMPTY_PROP
112
+ };
113
+ componentProps.forEach((componentProp) => {
114
+ Container.props[componentProp] = DEFAULT_EMPTY_PROP;
115
+ });
116
+ if (modelProp) {
117
+ Container.props[MODEL_VALUE] = DEFAULT_EMPTY_PROP;
118
+ Container.emits = [UPDATE_VALUE_EVENT, externalModelUpdateEvent];
119
+ }
120
+ }
121
+ return Container;
122
+ };
123
+
124
+ const TdtControl = /* @__PURE__ */ defineContainer(
125
+ "tdt-control",
126
+ void 0,
127
+ ["control", "position", "offset", "options"]
128
+ );
129
+ const TdtControlScale = /* @__PURE__ */ defineContainer(
130
+ "tdt-control-scale",
131
+ void 0,
132
+ ["position", "color"]
133
+ );
134
+ const TdtControlZoom = /* @__PURE__ */ defineContainer(
135
+ "tdt-control-zoom",
136
+ void 0,
137
+ ["position", "zoomInText", "zoomInTitle", "zoomOutText", "zoomOutTitle"]
138
+ );
139
+ const TdtMap = /* @__PURE__ */ defineContainer(
140
+ "tdt-map",
141
+ void 0,
142
+ ["tk", "projection", "minZoom", "maxZoom", "maxBounds", "center", "zoom"]
143
+ );
144
+
145
+ const ComponentLibrary = {
146
+ async install() {
147
+ applyPolyfills().then(() => {
148
+ defineCustomElements();
149
+ });
150
+ }
151
+ };
152
+
153
+ export { ComponentLibrary, TdtControl, TdtControlScale, TdtControlZoom, TdtMap };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tianditu/vue",
3
- "version": "0.0.0",
3
+ "version": "0.0.1-edge.0",
4
4
  "description": "Vue components for tianditu, powered by Demo Macro.",
5
5
  "main": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -29,8 +29,11 @@
29
29
  },
30
30
  "homepage": "https://github.com/DemoMacro/tianditu#readme",
31
31
  "devDependencies": {
32
- "vue": "3.2.47",
33
- "@tianditu/web-components": "0.0.0"
32
+ "vue": "3.3.4",
33
+ "@tianditu/wc": "0.0.1-edge.0"
34
34
  },
35
- "scripts": {}
35
+ "scripts": {
36
+ "dev": "unbuild --stub",
37
+ "postinstall": "pnpm prepack"
38
+ }
36
39
  }
@@ -1,9 +0,0 @@
1
- import type { JSX } from "@tianditu/web-components";
2
- export declare const TControl: import("vue").DefineComponent<JSX.TControl & import("./vue-component-lib/utils").InputProps<string | number | boolean>, object, {}, import("vue").ComputedOptions, import("vue").MethodOptions, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<JSX.TControl & import("./vue-component-lib/utils").InputProps<string | number | boolean>>, {}>;
3
- export declare const TMap: import("vue").DefineComponent<JSX.TMap & import("./vue-component-lib/utils").InputProps<string | number | boolean>, object, {}, import("vue").ComputedOptions, import("vue").MethodOptions, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<JSX.TMap & import("./vue-component-lib/utils").InputProps<string | number | boolean>>, {
4
- projection: any;
5
- minZoom: any;
6
- maxZoom: any;
7
- maxBounds: any;
8
- zoom: any;
9
- }>;
@@ -1,10 +0,0 @@
1
- import { defineContainer } from "./vue-component-lib/utils.mjs";
2
- export const TControl = /* @__PURE__ */ defineContainer(
3
- "t-control",
4
- void 0
5
- );
6
- export const TMap = /* @__PURE__ */ defineContainer(
7
- "t-map",
8
- void 0,
9
- ["tk", "projection", "minZoom", "maxZoom", "maxBounds", "center", "zoom"]
10
- );
package/dist/plugin.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { Plugin } from "vue";
2
- export declare const ComponentLibrary: Plugin;
package/dist/plugin.mjs DELETED
@@ -1,11 +0,0 @@
1
- import {
2
- applyPolyfills,
3
- defineCustomElements
4
- } from "@tianditu/web-components/dist/loader";
5
- export const ComponentLibrary = {
6
- async install() {
7
- applyPolyfills().then(() => {
8
- defineCustomElements();
9
- });
10
- }
11
- };
@@ -1,20 +0,0 @@
1
- export interface InputProps<T> {
2
- modelValue?: T;
3
- }
4
- /**
5
- * Create a callback to define a Vue component wrapper around a Web Component.
6
- *
7
- * @prop name - The component tag name (i.e. `ion-button`)
8
- * @prop componentProps - An array of properties on the
9
- * component. These usually match up with the @Prop definitions
10
- * in each component's TSX file.
11
- * @prop customElement - An option custom element instance to pass
12
- * to customElements.define. Only set if `includeImportCustomElements: true` in your config.
13
- * @prop modelProp - The prop that v-model binds to (i.e. value)
14
- * @prop modelUpdateEvent - The event that is fired from your Web Component when the value changes (i.e. ionChange)
15
- * @prop externalModelUpdateEvent - The external event to fire from your Vue component when modelUpdateEvent fires. This is used for ensuring that v-model references have been
16
- * correctly updated when a user's event callback fires.
17
- */
18
- export declare const defineContainer: <Props, VModelType = string | number | boolean>(name: string, defineCustomElement: any, componentProps?: string[], modelProp?: string, modelUpdateEvent?: string, externalModelUpdateEvent?: string) => import("vue").DefineComponent<Props & InputProps<VModelType>, object, {}, import("vue").ComputedOptions, import("vue").MethodOptions, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<Props & InputProps<VModelType> extends infer T ? T extends Props & InputProps<VModelType> ? T extends import("vue").ComponentPropsOptions<{
19
- [x: string]: unknown;
20
- }> ? import("vue").ExtractPropTypes<T> : T : never : never>, import("vue").ExtractDefaultPropTypes<Props & InputProps<VModelType>>>;
@@ -1,124 +0,0 @@
1
- import {
2
- defineComponent,
3
- getCurrentInstance,
4
- h,
5
- inject,
6
- ref
7
- } from "vue";
8
- const UPDATE_VALUE_EVENT = "update:modelValue";
9
- const MODEL_VALUE = "modelValue";
10
- const ROUTER_LINK_VALUE = "routerLink";
11
- const NAV_MANAGER = "navManager";
12
- const ROUTER_PROP_PREFIX = "router";
13
- const ARIA_PROP_PREFIX = "aria";
14
- const EMPTY_PROP = Symbol();
15
- const DEFAULT_EMPTY_PROP = { default: EMPTY_PROP };
16
- const getComponentClasses = (classes) => {
17
- return classes?.split(" ") || [];
18
- };
19
- const getElementClasses = (ref2, componentClasses, defaultClasses = []) => {
20
- return [...Array.from(ref2.value?.classList || []), ...defaultClasses].filter(
21
- (c, i, self) => !componentClasses.has(c) && self.indexOf(c) === i
22
- );
23
- };
24
- export const defineContainer = (name, defineCustomElement, componentProps = [], modelProp, modelUpdateEvent, externalModelUpdateEvent) => {
25
- if (defineCustomElement !== void 0) {
26
- defineCustomElement();
27
- }
28
- const Container = defineComponent(
29
- (props, { attrs, slots, emit }) => {
30
- let modelPropValue = props[modelProp];
31
- const containerRef = ref();
32
- const classes = new Set(getComponentClasses(attrs.class));
33
- const onVnodeBeforeMount = (vnode) => {
34
- if (vnode.el) {
35
- const eventsNames = Array.isArray(modelUpdateEvent) ? modelUpdateEvent : [modelUpdateEvent];
36
- eventsNames.forEach((eventName) => {
37
- vnode.el.addEventListener(eventName.toLowerCase(), (e) => {
38
- modelPropValue = (e?.target)[modelProp];
39
- emit(UPDATE_VALUE_EVENT, modelPropValue);
40
- if (externalModelUpdateEvent) {
41
- emit(externalModelUpdateEvent, e);
42
- }
43
- });
44
- });
45
- }
46
- };
47
- const currentInstance = getCurrentInstance();
48
- const hasRouter = currentInstance?.appContext?.provides[NAV_MANAGER];
49
- const navManager = hasRouter ? inject(NAV_MANAGER) : void 0;
50
- const handleRouterLink = (ev) => {
51
- const { routerLink } = props;
52
- if (routerLink === EMPTY_PROP)
53
- return;
54
- if (navManager !== void 0) {
55
- let navigationPayload = { event: ev };
56
- for (const key in props) {
57
- const value = props[key];
58
- if (props.hasOwnProperty(key) && key.startsWith(ROUTER_PROP_PREFIX) && value !== EMPTY_PROP) {
59
- navigationPayload[key] = value;
60
- }
61
- }
62
- navManager.navigate(navigationPayload);
63
- } else {
64
- console.warn(
65
- "Tried to navigate, but no router was found. Make sure you have mounted Vue Router."
66
- );
67
- }
68
- };
69
- return () => {
70
- modelPropValue = props[modelProp];
71
- getComponentClasses(attrs.class).forEach((value) => {
72
- classes.add(value);
73
- });
74
- const oldClick = props.onClick;
75
- const handleClick = (ev) => {
76
- if (oldClick !== void 0) {
77
- oldClick(ev);
78
- }
79
- if (!ev.defaultPrevented) {
80
- handleRouterLink(ev);
81
- }
82
- };
83
- let propsToAdd = {
84
- ref: containerRef,
85
- class: getElementClasses(containerRef, classes),
86
- onClick: handleClick,
87
- onVnodeBeforeMount: modelUpdateEvent ? onVnodeBeforeMount : void 0
88
- };
89
- for (const key in props) {
90
- const value = props[key];
91
- if (props.hasOwnProperty(key) && value !== EMPTY_PROP || key.startsWith(ARIA_PROP_PREFIX)) {
92
- propsToAdd[key] = value;
93
- }
94
- }
95
- if (modelProp) {
96
- if (props[MODEL_VALUE] !== EMPTY_PROP) {
97
- propsToAdd = {
98
- ...propsToAdd,
99
- [modelProp]: props[MODEL_VALUE]
100
- };
101
- } else if (modelPropValue !== EMPTY_PROP) {
102
- propsToAdd = {
103
- ...propsToAdd,
104
- [modelProp]: modelPropValue
105
- };
106
- }
107
- }
108
- return h(name, propsToAdd, slots.default && slots.default());
109
- };
110
- }
111
- );
112
- Container.name = name;
113
- Container.props = {
114
- [ROUTER_LINK_VALUE]: DEFAULT_EMPTY_PROP
115
- };
116
- componentProps.forEach((componentProp) => {
117
- Container.props[componentProp] = DEFAULT_EMPTY_PROP;
118
- });
119
- if (modelProp) {
120
- Container.props[MODEL_VALUE] = DEFAULT_EMPTY_PROP;
121
- Container.emits = [UPDATE_VALUE_EVENT, externalModelUpdateEvent];
122
- }
123
- return Container;
124
- };