kritzel-vue 0.0.5

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 ADDED
@@ -0,0 +1,11 @@
1
+ # `vue`
2
+
3
+ > TODO: description
4
+
5
+ ## Usage
6
+
7
+ ```
8
+ const vue = require('vue');
9
+
10
+ // TODO: DEMONSTRATE API
11
+ ```
@@ -0,0 +1,5 @@
1
+ import type { JSX } from '@kritzel/stencil';
2
+ export declare const MyButton: import("vue").DefineSetupFnComponent<JSX.MyButton & import("./vue-component-lib/utils").InputProps<string | number | boolean>, {}, {}, JSX.MyButton & import("./vue-component-lib/utils").InputProps<string | number | boolean> & {}, import("vue").PublicProps>;
3
+ export declare const MyComponent: import("vue").DefineSetupFnComponent<JSX.MyComponent & import("./vue-component-lib/utils").InputProps<string | number | boolean>, {}, {}, JSX.MyComponent & import("./vue-component-lib/utils").InputProps<string | number | boolean> & {}, import("vue").PublicProps>;
4
+ export declare const MyList: import("vue").DefineSetupFnComponent<JSX.MyList & import("./vue-component-lib/utils").InputProps<string | number | boolean>, {}, {}, JSX.MyList & import("./vue-component-lib/utils").InputProps<string | number | boolean> & {}, import("vue").PublicProps>;
5
+ export declare const MyTitle: import("vue").DefineSetupFnComponent<JSX.MyTitle & import("./vue-component-lib/utils").InputProps<string | number | boolean>, {}, {}, JSX.MyTitle & import("./vue-component-lib/utils").InputProps<string | number | boolean> & {}, import("vue").PublicProps>;
@@ -0,0 +1,14 @@
1
+ /* eslint-disable */
2
+ /* tslint:disable */
3
+ /* auto-generated vue proxies */
4
+ import { defineContainer } from './vue-component-lib/utils';
5
+ export const MyButton = /*@__PURE__*/ defineContainer('my-button', undefined);
6
+ export const MyComponent = /*@__PURE__*/ defineContainer('my-component', undefined, [
7
+ 'first',
8
+ 'last',
9
+ 'age'
10
+ ]);
11
+ export const MyList = /*@__PURE__*/ defineContainer('my-list', undefined, [
12
+ 'items'
13
+ ]);
14
+ export const MyTitle = /*@__PURE__*/ defineContainer('my-title', undefined);
@@ -0,0 +1,2 @@
1
+ export * from './components';
2
+ export * from './plugin';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './components';
2
+ export * from './plugin';
@@ -0,0 +1 @@
1
+ export declare const ComponentLibrary: any;
package/dist/plugin.js ADDED
@@ -0,0 +1,6 @@
1
+ import { defineCustomElements } from '@kritzel/stencil/loader';
2
+ export const ComponentLibrary = {
3
+ async install() {
4
+ defineCustomElements();
5
+ },
6
+ };
@@ -0,0 +1,16 @@
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
+ */
16
+ export declare const defineContainer: <Props, VModelType = string | number | boolean>(name: string, defineCustomElement: any, componentProps?: string[], modelProp?: string, modelUpdateEvent?: string) => import("vue").DefineSetupFnComponent<Props & InputProps<VModelType>, {}, {}, Props & InputProps<VModelType> & {}, import("vue").PublicProps>;
@@ -0,0 +1,188 @@
1
+ // @ts-nocheck
2
+ // It's easier and safer for Volar to disable typechecking and let the return type inference do its job.
3
+ import { defineComponent, getCurrentInstance, h, inject, ref, withDirectives } from 'vue';
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
+ /**
11
+ * Starting in Vue 3.1.0, all properties are
12
+ * added as keys to the props object, even if
13
+ * they are not being used. In order to correctly
14
+ * account for both value props and v-model props,
15
+ * we need to check if the key exists for Vue <3.1.0
16
+ * and then check if it is not undefined for Vue >= 3.1.0.
17
+ * See https://github.com/vuejs/vue-next/issues/3889
18
+ */
19
+ const EMPTY_PROP = Symbol();
20
+ const DEFAULT_EMPTY_PROP = { default: EMPTY_PROP };
21
+ const getComponentClasses = (classes) => {
22
+ return (classes === null || classes === void 0 ? void 0 : classes.split(' ')) || [];
23
+ };
24
+ const getElementClasses = (ref, componentClasses, defaultClasses = []) => {
25
+ var _a;
26
+ return [...Array.from(((_a = ref.value) === null || _a === void 0 ? void 0 : _a.classList) || []), ...defaultClasses].filter((c, i, self) => !componentClasses.has(c) && self.indexOf(c) === i);
27
+ };
28
+ /**
29
+ * Create a callback to define a Vue component wrapper around a Web Component.
30
+ *
31
+ * @prop name - The component tag name (i.e. `ion-button`)
32
+ * @prop componentProps - An array of properties on the
33
+ * component. These usually match up with the @Prop definitions
34
+ * in each component's TSX file.
35
+ * @prop customElement - An option custom element instance to pass
36
+ * to customElements.define. Only set if `includeImportCustomElements: true` in your config.
37
+ * @prop modelProp - The prop that v-model binds to (i.e. value)
38
+ * @prop modelUpdateEvent - The event that is fired from your Web Component when the value changes (i.e. ionChange)
39
+ */
40
+ export const defineContainer = (name, defineCustomElement, componentProps = [], modelProp, modelUpdateEvent) => {
41
+ /**
42
+ * Create a Vue component wrapper around a Web Component.
43
+ * Note: The `props` here are not all properties on a component.
44
+ * They refer to whatever properties are set on an instance of a component.
45
+ */
46
+ if (defineCustomElement !== undefined) {
47
+ defineCustomElement();
48
+ }
49
+ const Container = defineComponent((props, { attrs, slots, emit }) => {
50
+ var _a;
51
+ let modelPropValue = props[modelProp];
52
+ const containerRef = ref();
53
+ const classes = new Set(getComponentClasses(attrs.class));
54
+ /**
55
+ * This directive is responsible for updating any reactive
56
+ * reference associated with v-model on the component.
57
+ * This code must be run inside of the "created" callback.
58
+ * Since the following listener callbacks as well as any potential
59
+ * event callback defined in the developer's app are set on
60
+ * the same element, we need to make sure the following callbacks
61
+ * are set first so they fire first. If the developer's callback fires first
62
+ * then the reactive reference will not have been updated yet.
63
+ */
64
+ const vModelDirective = {
65
+ created: (el) => {
66
+ const eventsNames = Array.isArray(modelUpdateEvent) ? modelUpdateEvent : [modelUpdateEvent];
67
+ eventsNames.forEach((eventName) => {
68
+ el.addEventListener(eventName.toLowerCase(), (e) => {
69
+ /**
70
+ * Only update the v-model binding if the event's target is the element we are
71
+ * listening on. For example, Component A could emit ionChange, but it could also
72
+ * have a descendant Component B that also emits ionChange. We only want to update
73
+ * the v-model for Component A when ionChange originates from that element and not
74
+ * when ionChange bubbles up from Component B.
75
+ */
76
+ if (e.target.tagName === el.tagName) {
77
+ modelPropValue = (e === null || e === void 0 ? void 0 : e.target)[modelProp];
78
+ emit(UPDATE_VALUE_EVENT, modelPropValue);
79
+ }
80
+ });
81
+ });
82
+ },
83
+ };
84
+ const currentInstance = getCurrentInstance();
85
+ const hasRouter = (_a = currentInstance === null || currentInstance === void 0 ? void 0 : currentInstance.appContext) === null || _a === void 0 ? void 0 : _a.provides[NAV_MANAGER];
86
+ const navManager = hasRouter ? inject(NAV_MANAGER) : undefined;
87
+ const handleRouterLink = (ev) => {
88
+ const { routerLink } = props;
89
+ if (routerLink === EMPTY_PROP)
90
+ return;
91
+ if (navManager !== undefined) {
92
+ /**
93
+ * This prevents the browser from
94
+ * performing a page reload when pressing
95
+ * an Ionic component with routerLink.
96
+ * The page reload interferes with routing
97
+ * and causes ion-back-button to disappear
98
+ * since the local history is wiped on reload.
99
+ */
100
+ ev.preventDefault();
101
+ let navigationPayload = { event: ev };
102
+ for (const key in props) {
103
+ const value = props[key];
104
+ if (props.hasOwnProperty(key) && key.startsWith(ROUTER_PROP_PREFIX) && value !== EMPTY_PROP) {
105
+ navigationPayload[key] = value;
106
+ }
107
+ }
108
+ navManager.navigate(navigationPayload);
109
+ }
110
+ else {
111
+ console.warn('Tried to navigate, but no router was found. Make sure you have mounted Vue Router.');
112
+ }
113
+ };
114
+ return () => {
115
+ modelPropValue = props[modelProp];
116
+ getComponentClasses(attrs.class).forEach((value) => {
117
+ classes.add(value);
118
+ });
119
+ const oldClick = props.onClick;
120
+ const handleClick = (ev) => {
121
+ if (oldClick !== undefined) {
122
+ oldClick(ev);
123
+ }
124
+ if (!ev.defaultPrevented) {
125
+ handleRouterLink(ev);
126
+ }
127
+ };
128
+ let propsToAdd = {
129
+ ref: containerRef,
130
+ class: getElementClasses(containerRef, classes),
131
+ onClick: handleClick,
132
+ };
133
+ /**
134
+ * We can use Object.entries here
135
+ * to avoid the hasOwnProperty check,
136
+ * but that would require 2 iterations
137
+ * where as this only requires 1.
138
+ */
139
+ for (const key in props) {
140
+ const value = props[key];
141
+ if ((props.hasOwnProperty(key) && value !== EMPTY_PROP) || key.startsWith(ARIA_PROP_PREFIX)) {
142
+ propsToAdd[key] = value;
143
+ }
144
+ }
145
+ if (modelProp) {
146
+ /**
147
+ * If form value property was set using v-model
148
+ * then we should use that value.
149
+ * Otherwise, check to see if form value property
150
+ * was set as a static value (i.e. no v-model).
151
+ */
152
+ if (props[MODEL_VALUE] !== EMPTY_PROP) {
153
+ propsToAdd = Object.assign(Object.assign({}, propsToAdd), { [modelProp]: props[MODEL_VALUE] });
154
+ }
155
+ else if (modelPropValue !== EMPTY_PROP) {
156
+ propsToAdd = Object.assign(Object.assign({}, propsToAdd), { [modelProp]: modelPropValue });
157
+ }
158
+ }
159
+ // If router link is defined, add href to props
160
+ // in order to properly render an anchor tag inside
161
+ // of components that should become activatable and
162
+ // focusable with router link.
163
+ if (props[ROUTER_LINK_VALUE] !== EMPTY_PROP) {
164
+ propsToAdd = Object.assign(Object.assign({}, propsToAdd), { href: props[ROUTER_LINK_VALUE] });
165
+ }
166
+ /**
167
+ * vModelDirective is only needed on components that support v-model.
168
+ * As a result, we conditionally call withDirectives with v-model components.
169
+ */
170
+ const node = h(name, propsToAdd, slots.default && slots.default());
171
+ return modelProp === undefined ? node : withDirectives(node, [[vModelDirective]]);
172
+ };
173
+ });
174
+ if (typeof Container !== 'function') {
175
+ Container.name = name;
176
+ Container.props = {
177
+ [ROUTER_LINK_VALUE]: DEFAULT_EMPTY_PROP,
178
+ };
179
+ componentProps.forEach((componentProp) => {
180
+ Container.props[componentProp] = DEFAULT_EMPTY_PROP;
181
+ });
182
+ if (modelProp) {
183
+ Container.props[MODEL_VALUE] = DEFAULT_EMPTY_PROP;
184
+ Container.emits = [UPDATE_VALUE_EVENT];
185
+ }
186
+ }
187
+ return Container;
188
+ };
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "kritzel-vue",
3
+ "version": "0.0.5",
4
+ "description": "> TODO: description",
5
+ "author": "kasual1 <seifertluk11@gmail.com>",
6
+ "homepage": "https://gitlab.com/kasual1/kritzel#readme",
7
+ "license": "ISC",
8
+ "main": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "directories": {
11
+ "lib": "lib",
12
+ "test": "__tests__"
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+ssh://git@gitlab.com/kasual1/kritzel.git"
20
+ },
21
+ "scripts": {
22
+ "test": "echo \"Error: run tests from root\" && exit 1",
23
+ "build": "npm run tsc",
24
+ "tsc": "tsc -p . --outDir ./dist",
25
+ "clean": "rimraf dist node_modules",
26
+ "bump": "npm version patch",
27
+ "publish": "cd dist && npm publish"
28
+ },
29
+ "bugs": {
30
+ "url": "https://gitlab.com/kasual1/kritzel/issues"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "dependencies": {
36
+ "@stencil/vue-output-target": "0.8.9",
37
+ "@kritzel/stencil": "file:../stencil"
38
+ }
39
+ }