@tianditu/vue 0.0.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 ADDED
@@ -0,0 +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.
package/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # @tianditu/vue
2
+
3
+ ![npm version](https://img.shields.io/npm/v/@tianditu/vue)
4
+ ![npm downloads](https://img.shields.io/npm/dw/@tianditu/vue)
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
+
8
+ > Vue components for tianditu, powered by Demo Macro.
9
+
10
+ ## Getting started
11
+
12
+ ```bash
13
+ # npm
14
+ $ npm install -D @tianditu/web-components @tianditu/vue
15
+
16
+ # yarn
17
+ $ yarn add -D @tianditu/web-components @tianditu/vue
18
+
19
+ # pnpm
20
+ $ pnpm add -D @tianditu/web-components @tianditu/vue
21
+ ```
22
+
23
+ ## License
24
+
25
+ - [MIT](LICENSE) © [Demo Macro](https://imst.xyz/)
@@ -0,0 +1,9 @@
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
+ }>;
@@ -0,0 +1,10 @@
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
+ );
@@ -0,0 +1,2 @@
1
+ export * from "./components";
2
+ export * from "./plugin";
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./components.mjs";
2
+ export * from "./plugin.mjs";
@@ -0,0 +1,2 @@
1
+ import { Plugin } from "vue";
2
+ export declare const ComponentLibrary: Plugin;
@@ -0,0 +1,11 @@
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
+ };
@@ -0,0 +1,20 @@
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>>>;
@@ -0,0 +1,124 @@
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
+ };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@tianditu/vue",
3
+ "version": "0.0.0",
4
+ "description": "Vue components for tianditu, powered by Demo Macro.",
5
+ "main": "dist/index.mjs",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/DemoMacro/tianditu.git"
13
+ },
14
+ "keywords": [
15
+ "utility",
16
+ "libraries",
17
+ "tianditu",
18
+ "map",
19
+ "vue"
20
+ ],
21
+ "author": {
22
+ "name": "Demo Macro",
23
+ "email": "abc@imst.xyz",
24
+ "url": "https://imst.xyz/"
25
+ },
26
+ "license": "MIT",
27
+ "bugs": {
28
+ "url": "https://github.com/DemoMacro/tianditu/issues"
29
+ },
30
+ "homepage": "https://github.com/DemoMacro/tianditu#readme",
31
+ "devDependencies": {
32
+ "vue": "3.2.47",
33
+ "@tianditu/web-components": "0.0.0"
34
+ },
35
+ "scripts": {}
36
+ }