@feedlog-ai/vue 0.0.3 → 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,330 @@
1
+ # @feedlog-ai/vue
2
+
3
+ Vue bindings for Feedlog Toolkit web components. Auto-generated from Stencil components with full TypeScript support.
4
+
5
+ ## Features
6
+
7
+ - **Vue Components**: Native Vue components with template syntax support
8
+ - **TypeScript Support**: Full type safety with TypeScript definitions
9
+ - **Auto-generated**: Generated from Stencil web components for consistency
10
+ - **Vue 2 & 3 Support**: Compatible with Vue >=2.6.0 and >=3.0.0
11
+ - **Event Handling**: Vue-friendly event handling with proper typing
12
+ - **Tree Shakeable**: Only import the components you need
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @feedlog-ai/vue
18
+ ```
19
+
20
+ ## Components
21
+
22
+ ### FeedlogGithubIssuesClient
23
+
24
+ The main component for displaying GitHub issues with built-in SDK integration.
25
+
26
+ **Props:**
27
+
28
+ - `apiKey`: API key for Feedlog authentication (required)
29
+ - `type?`: Filter by issue type - `'bug'` or `'enhancement'`
30
+ - `limit?`: Maximum issues to fetch (1-100, default: 10)
31
+ - `endpoint?`: Custom API endpoint
32
+ - `maxWidth?`: Container max width (default: `'42rem'`)
33
+ - `theme?`: Theme variant - `'light'` or `'dark'` (default: `'light'`)
34
+ - `showThemeToggle?`: Show theme toggle button (default: `true`)
35
+
36
+ **Events:**
37
+
38
+ - `@feedlog-upvote`: Emitted when an issue is upvoted
39
+ - `@feedlog-theme-change`: Emitted when theme changes
40
+ - `@feedlog-error`: Emitted on errors
41
+
42
+ ## Usage
43
+
44
+ ### Vue 3 (Composition API)
45
+
46
+ ```vue
47
+ <template>
48
+ <div>
49
+ <FeedlogGithubIssuesClient
50
+ api-key="your-api-key"
51
+ type="bug"
52
+ :limit="10"
53
+ theme="light"
54
+ max-width="42rem"
55
+ @feedlog-upvote="handleUpvote"
56
+ @feedlog-theme-change="handleThemeChange"
57
+ @feedlog-error="handleError"
58
+ />
59
+ </div>
60
+ </template>
61
+
62
+ <script setup lang="ts">
63
+ import { FeedlogGithubIssuesClient } from '@feedlog-ai/vue';
64
+
65
+ const handleUpvote = (event: CustomEvent) => {
66
+ console.log('Issue upvoted:', event.detail);
67
+ // event.detail: { issueId, upvoted, upvoteCount }
68
+ };
69
+
70
+ const handleThemeChange = (event: CustomEvent<'light' | 'dark'>) => {
71
+ console.log('Theme changed to:', event.detail);
72
+ };
73
+
74
+ const handleError = (event: CustomEvent) => {
75
+ console.error('Error:', event.detail);
76
+ // event.detail: { error, code? }
77
+ };
78
+ </script>
79
+ ```
80
+
81
+ ### Vue 3 (Options API)
82
+
83
+ ```vue
84
+ <template>
85
+ <FeedlogGithubIssuesClient
86
+ api-key="your-api-key"
87
+ @feedlog-upvote="onUpvote"
88
+ @feedlog-error="onError"
89
+ />
90
+ </template>
91
+
92
+ <script lang="ts">
93
+ import { FeedlogGithubIssuesClient } from '@feedlog-ai/vue';
94
+
95
+ export default {
96
+ components: {
97
+ FeedlogGithubIssuesClient,
98
+ },
99
+ methods: {
100
+ onUpvote(event: CustomEvent) {
101
+ console.log('Issue upvoted:', event.detail);
102
+ },
103
+ onError(event: CustomEvent) {
104
+ console.error('Error:', event.detail);
105
+ },
106
+ },
107
+ };
108
+ </script>
109
+ ```
110
+
111
+ ### Vue 2
112
+
113
+ ```vue
114
+ <template>
115
+ <feedlog-github-issues-client api-key="your-api-key" @feedlog-upvote="handleUpvote" />
116
+ </template>
117
+
118
+ <script>
119
+ import { FeedlogGithubIssuesClient } from '@feedlog-ai/vue';
120
+
121
+ export default {
122
+ components: {
123
+ FeedlogGithubIssuesClient,
124
+ },
125
+ methods: {
126
+ handleUpvote(event) {
127
+ console.log('Issue upvoted:', event.detail);
128
+ },
129
+ },
130
+ };
131
+ </script>
132
+ ```
133
+
134
+ ### With Reactive Data
135
+
136
+ ```vue
137
+ <template>
138
+ <div>
139
+ <div class="controls">
140
+ <select v-model="issueType">
141
+ <option value="bug">Bugs</option>
142
+ <option value="enhancement">Enhancements</option>
143
+ </select>
144
+
145
+ <button @click="toggleTheme">
146
+ Switch to {{ theme === 'light' ? 'dark' : 'light' }} theme
147
+ </button>
148
+ </div>
149
+
150
+ <FeedlogGithubIssuesClient
151
+ api-key="your-api-key"
152
+ :type="issueType"
153
+ :theme="theme"
154
+ @feedlog-theme-change="updateTheme"
155
+ />
156
+ </div>
157
+ </template>
158
+
159
+ <script setup lang="ts">
160
+ import { ref } from 'vue';
161
+ import { FeedlogGithubIssuesClient } from '@feedlog-ai/vue';
162
+
163
+ const issueType = ref<'bug' | 'enhancement'>('bug');
164
+ const theme = ref<'light' | 'dark'>('light');
165
+
166
+ const toggleTheme = () => {
167
+ theme.value = theme.value === 'light' ? 'dark' : 'light';
168
+ };
169
+
170
+ const updateTheme = (event: CustomEvent<'light' | 'dark'>) => {
171
+ theme.value = event.detail;
172
+ };
173
+ </script>
174
+ ```
175
+
176
+ ### Event Handling
177
+
178
+ ```vue
179
+ <template>
180
+ <FeedlogGithubIssuesClient
181
+ api-key="your-api-key"
182
+ @feedlog-upvote="onUpvote"
183
+ @feedlog-error="onError"
184
+ />
185
+ </template>
186
+
187
+ <script setup lang="ts">
188
+ const onUpvote = (
189
+ event: CustomEvent<{
190
+ issueId: string;
191
+ upvoted: boolean;
192
+ upvoteCount: number;
193
+ }>
194
+ ) => {
195
+ // Fully typed event detail
196
+ const { issueId, upvoted, upvoteCount } = event.detail;
197
+
198
+ if (upvoted) {
199
+ console.log(`User upvoted issue ${issueId}`);
200
+ } else {
201
+ console.log(`User removed upvote from issue ${issueId}`);
202
+ }
203
+
204
+ console.log(`Issue now has ${upvoteCount} upvotes`);
205
+ };
206
+
207
+ const onError = (
208
+ event: CustomEvent<{
209
+ error: string;
210
+ code?: number;
211
+ }>
212
+ ) => {
213
+ const { error, code } = event.detail;
214
+ console.error(`Feedlog error (${code || 'unknown'}):`, error);
215
+
216
+ // Handle error in your UI (show toast, etc.)
217
+ };
218
+ </script>
219
+ ```
220
+
221
+ ### Other Components
222
+
223
+ The package also includes Vue bindings for additional UI components:
224
+
225
+ ```vue
226
+ <template>
227
+ <div>
228
+ <!-- Badge component -->
229
+ <FeedlogBadge variant="primary">New</FeedlogBadge>
230
+
231
+ <!-- Button component -->
232
+ <FeedlogButton variant="primary" size="lg" @feedlog-click="handleClick">
233
+ Click me
234
+ </FeedlogButton>
235
+
236
+ <!-- Card component -->
237
+ <FeedlogCard>
238
+ <h3>Card Title</h3>
239
+ <p>Card content</p>
240
+ </FeedlogCard>
241
+ </div>
242
+ </template>
243
+
244
+ <script setup lang="ts">
245
+ import { FeedlogBadge, FeedlogButton, FeedlogCard } from '@feedlog-ai/vue';
246
+
247
+ const handleClick = (event: CustomEvent<MouseEvent>) => {
248
+ console.log('Button clicked:', event.detail);
249
+ };
250
+ </script>
251
+ ```
252
+
253
+ ## Global Registration
254
+
255
+ You can register components globally in your Vue app:
256
+
257
+ ```ts
258
+ // main.ts
259
+ import { createApp } from 'vue';
260
+ import { FeedlogGithubIssuesClient, FeedlogBadge } from '@feedlog-ai/vue';
261
+
262
+ const app = createApp(App);
263
+
264
+ // Register specific components
265
+ app.component('FeedlogGithubIssuesClient', FeedlogGithubIssuesClient);
266
+ app.component('FeedlogBadge', FeedlogBadge);
267
+
268
+ // Or use the install function (currently minimal but extensible)
269
+ import { install } from '@feedlog-ai/vue';
270
+ app.use(install);
271
+ ```
272
+
273
+ ## TypeScript Support
274
+
275
+ All components are fully typed. Import types from the core package if needed:
276
+
277
+ ```vue
278
+ <script setup lang="ts">
279
+ import type { FeedlogIssue } from '@feedlog-ai/core';
280
+
281
+ const handleUpvote = (
282
+ event: CustomEvent<{
283
+ issueId: string;
284
+ upvoted: boolean;
285
+ upvoteCount: number;
286
+ }>
287
+ ) => {
288
+ // Fully typed event detail
289
+ console.log(event.detail.issueId);
290
+ console.log(event.detail.upvoted);
291
+ console.log(event.detail.upvoteCount);
292
+ };
293
+ </script>
294
+ ```
295
+
296
+ ## Requirements
297
+
298
+ - Vue >= 2.6.0 or >= 3.0.0
299
+ - Modern browsers with Web Components support
300
+
301
+ ## Browser Support
302
+
303
+ Same as the underlying web components:
304
+
305
+ - Chrome 61+
306
+ - Firefox 63+
307
+ - Safari 11+
308
+ - Edge 79+
309
+
310
+ ## Migration from Direct Web Components
311
+
312
+ If you're migrating from using web components directly:
313
+
314
+ ```vue
315
+ <!-- Before (direct web component) -->
316
+ <feedlog-github-issues-client api-key="key" @feedlog-upvote="handleUpvote" />
317
+
318
+ <!-- After (Vue component) -->
319
+ <FeedlogGithubIssuesClient api-key="key" @feedlog-upvote="handleUpvote" />
320
+ ```
321
+
322
+ **Key differences:**
323
+
324
+ - Use PascalCase component names in templates
325
+ - Event names remain the same (kebab-case)
326
+ - All props and events are properly typed
327
+
328
+ ## License
329
+
330
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feedlog-ai/vue",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Vue bindings for Feedlog Toolkit Web Components",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -27,7 +27,7 @@
27
27
  "vue": ">=3.0.0 || >=2.6.0"
28
28
  },
29
29
  "dependencies": {
30
- "@feedlog-ai/webcomponents": "*"
30
+ "@feedlog-ai/webcomponents": "workspace:*"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@jest/test-sequencer": "^29.7.0",
@@ -47,5 +47,8 @@
47
47
  "components",
48
48
  "data-visualization"
49
49
  ],
50
- "license": "MIT"
50
+ "license": "MIT",
51
+ "publishConfig": {
52
+ "access": "public"
53
+ }
51
54
  }
@@ -1,8 +0,0 @@
1
- import type { JSX } from '@feedlog-ai/webcomponents';
2
- export declare const FeedlogBadge: import("vue").DefineSetupFnComponent<JSX.FeedlogBadge & import("./vue-component-lib/utils").InputProps<string | number | boolean>, {}, {}, JSX.FeedlogBadge & import("./vue-component-lib/utils").InputProps<string | number | boolean> & {}, import("vue").PublicProps>;
3
- export declare const FeedlogButton: import("vue").DefineSetupFnComponent<JSX.FeedlogButton & import("./vue-component-lib/utils").InputProps<string | number | boolean>, {}, {}, JSX.FeedlogButton & import("./vue-component-lib/utils").InputProps<string | number | boolean> & {}, import("vue").PublicProps>;
4
- export declare const FeedlogCard: import("vue").DefineSetupFnComponent<JSX.FeedlogCard & import("./vue-component-lib/utils").InputProps<string | number | boolean>, {}, {}, JSX.FeedlogCard & import("./vue-component-lib/utils").InputProps<string | number | boolean> & {}, import("vue").PublicProps>;
5
- export declare const FeedlogGithubIssues: import("vue").DefineSetupFnComponent<JSX.FeedlogGithubIssues & import("./vue-component-lib/utils").InputProps<string | number | boolean>, {}, {}, JSX.FeedlogGithubIssues & import("./vue-component-lib/utils").InputProps<string | number | boolean> & {}, import("vue").PublicProps>;
6
- export declare const FeedlogGithubIssuesClient: import("vue").DefineSetupFnComponent<JSX.FeedlogGithubIssuesClient & import("./vue-component-lib/utils").InputProps<string | number | boolean>, {}, {}, JSX.FeedlogGithubIssuesClient & import("./vue-component-lib/utils").InputProps<string | number | boolean> & {}, import("vue").PublicProps>;
7
- export declare const FeedlogIssuesList: import("vue").DefineSetupFnComponent<JSX.FeedlogIssuesList & import("./vue-component-lib/utils").InputProps<string | number | boolean>, {}, {}, JSX.FeedlogIssuesList & import("./vue-component-lib/utils").InputProps<string | number | boolean> & {}, import("vue").PublicProps>;
8
- //# sourceMappingURL=components.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../src/components.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAMrD,eAAO,MAAM,YAAY,0QAEvB,CAAC;AAGH,eAAO,MAAM,aAAa,4QAMxB,CAAC;AAGH,eAAO,MAAM,WAAW,wQAA4E,CAAC;AAGrG,eAAO,MAAM,mBAAmB,wRAY9B,CAAC;AAGH,eAAO,MAAM,yBAAyB,oSAWpC,CAAC;AAGH,eAAO,MAAM,iBAAiB,oRAI5B,CAAC"}
@@ -1,48 +0,0 @@
1
- /* eslint-disable */
2
- /* tslint:disable */
3
- /* auto-generated vue proxies */
4
- import { defineContainer } from './vue-component-lib/utils';
5
- import { defineCustomElements } from '@feedlog-ai/webcomponents/loader';
6
- defineCustomElements();
7
- export const FeedlogBadge = /*@__PURE__*/ defineContainer('feedlog-badge', undefined, [
8
- 'variant'
9
- ]);
10
- export const FeedlogButton = /*@__PURE__*/ defineContainer('feedlog-button', undefined, [
11
- 'variant',
12
- 'size',
13
- 'disabled',
14
- 'type',
15
- 'feedlogClick'
16
- ]);
17
- export const FeedlogCard = /*@__PURE__*/ defineContainer('feedlog-card', undefined);
18
- export const FeedlogGithubIssues = /*@__PURE__*/ defineContainer('feedlog-github-issues', undefined, [
19
- 'issues',
20
- 'maxWidth',
21
- 'theme',
22
- 'loading',
23
- 'error',
24
- 'showThemeToggle',
25
- 'hasMore',
26
- 'isLoadingMore',
27
- 'feedlogUpvote',
28
- 'feedlogThemeChange',
29
- 'feedlogLoadMore'
30
- ]);
31
- export const FeedlogGithubIssuesClient = /*@__PURE__*/ defineContainer('feedlog-github-issues-client', undefined, [
32
- 'repos',
33
- 'type',
34
- 'limit',
35
- 'endpoint',
36
- 'maxWidth',
37
- 'theme',
38
- 'showThemeToggle',
39
- 'feedlogUpvote',
40
- 'feedlogThemeChange',
41
- 'feedlogError'
42
- ]);
43
- export const FeedlogIssuesList = /*@__PURE__*/ defineContainer('feedlog-issues-list', undefined, [
44
- 'issues',
45
- 'theme',
46
- 'feedlogUpvote'
47
- ]);
48
- //# sourceMappingURL=components.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"components.js","sourceRoot":"","sources":["../src/components.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,oBAAoB;AACpB,gCAAgC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAI5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAExE,oBAAoB,EAAE,CAAC;AAEvB,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAC,eAAe,CAAmB,eAAe,EAAE,SAAS,EAAE;IACtG,SAAS;CACV,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAC,eAAe,CAAoB,gBAAgB,EAAE,SAAS,EAAE;IACzG,SAAS;IACT,MAAM;IACN,UAAU;IACV,MAAM;IACN,cAAc;CACf,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAC,eAAe,CAAkB,cAAc,EAAE,SAAS,CAAC,CAAC;AAGrG,MAAM,CAAC,MAAM,mBAAmB,GAAG,aAAa,CAAC,eAAe,CAA0B,uBAAuB,EAAE,SAAS,EAAE;IAC5H,QAAQ;IACR,UAAU;IACV,OAAO;IACP,SAAS;IACT,OAAO;IACP,iBAAiB;IACjB,SAAS;IACT,eAAe;IACf,eAAe;IACf,oBAAoB;IACpB,iBAAiB;CAClB,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,yBAAyB,GAAG,aAAa,CAAC,eAAe,CAAgC,8BAA8B,EAAE,SAAS,EAAE;IAC/I,OAAO;IACP,MAAM;IACN,OAAO;IACP,UAAU;IACV,UAAU;IACV,OAAO;IACP,iBAAiB;IACjB,eAAe;IACf,oBAAoB;IACpB,cAAc;CACf,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAAC,eAAe,CAAwB,qBAAqB,EAAE,SAAS,EAAE;IACtH,QAAQ;IACR,OAAO;IACP,eAAe;CAChB,CAAC,CAAC"}
package/dist/index.d.ts DELETED
@@ -1,10 +0,0 @@
1
- /**
2
- * Vue bindings for Feedlog Toolkit Web Components
3
- *
4
- * This package provides Vue components that wrap the Stencil web components.
5
- * Components are auto-generated from the Stencil build process.
6
- */
7
- export * from './components';
8
- import type { App } from 'vue';
9
- export declare function install(_app: App): void;
10
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,cAAc,CAAC;AAW7B,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAG/B,wBAAgB,OAAO,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,CAGvC"}
package/dist/index.js DELETED
@@ -1,20 +0,0 @@
1
- /**
2
- * Vue bindings for Feedlog Toolkit Web Components
3
- *
4
- * This package provides Vue components that wrap the Stencil web components.
5
- * Components are auto-generated from the Stencil build process.
6
- */
7
- // Re-export all Vue components generated by Stencil
8
- export * from './components';
9
- // Define custom elements (required for web components to work)
10
- import { defineCustomElements } from '@feedlog-ai/webcomponents/loader';
11
- // Auto-define custom elements when this module is imported
12
- if (typeof window !== 'undefined') {
13
- defineCustomElements();
14
- }
15
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
16
- export function install(_app) {
17
- // Custom elements are automatically registered via defineCustomElements
18
- // Additional Vue-specific setup can be added here if needed
19
- }
20
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,oDAAoD;AACpD,cAAc,cAAc,CAAC;AAE7B,+DAA+D;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAExE,2DAA2D;AAC3D,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IAClC,oBAAoB,EAAE,CAAC;AACzB,CAAC;AAKD,6DAA6D;AAC7D,MAAM,UAAU,OAAO,CAAC,IAAS;IAC/B,wEAAwE;IACxE,4DAA4D;AAC9D,CAAC"}
@@ -1,17 +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
- */
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>;
17
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/vue-component-lib/utils.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,UAAU,CAAC,EAAE,CAAC,CAAC;CAChB;AAsCD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,GAAI,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,EAC3E,MAAM,MAAM,EACZ,qBAAqB,GAAG,EACxB,iBAAgB,MAAM,EAAO,EAC7B,YAAY,MAAM,EAClB,mBAAmB,MAAM,iJA8K1B,CAAC"}
@@ -1,196 +0,0 @@
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?.split(' ') || [];
23
- };
24
- const getElementClasses = (ref, componentClasses, defaultClasses = []) => {
25
- return [...Array.from(ref.value?.classList || []), ...defaultClasses].filter((c, i, self) => !componentClasses.has(c) && self.indexOf(c) === i);
26
- };
27
- /**
28
- * Create a callback to define a Vue component wrapper around a Web Component.
29
- *
30
- * @prop name - The component tag name (i.e. `ion-button`)
31
- * @prop componentProps - An array of properties on the
32
- * component. These usually match up with the @Prop definitions
33
- * in each component's TSX file.
34
- * @prop customElement - An option custom element instance to pass
35
- * to customElements.define. Only set if `includeImportCustomElements: true` in your config.
36
- * @prop modelProp - The prop that v-model binds to (i.e. value)
37
- * @prop modelUpdateEvent - The event that is fired from your Web Component when the value changes (i.e. ionChange)
38
- */
39
- export const defineContainer = (name, defineCustomElement, componentProps = [], modelProp, modelUpdateEvent) => {
40
- /**
41
- * Create a Vue component wrapper around a Web Component.
42
- * Note: The `props` here are not all properties on a component.
43
- * They refer to whatever properties are set on an instance of a component.
44
- */
45
- if (defineCustomElement !== undefined) {
46
- defineCustomElement();
47
- }
48
- const Container = defineComponent((props, { attrs, slots, emit }) => {
49
- let modelPropValue = props[modelProp];
50
- const containerRef = ref();
51
- const classes = new Set(getComponentClasses(attrs.class));
52
- /**
53
- * This directive is responsible for updating any reactive
54
- * reference associated with v-model on the component.
55
- * This code must be run inside of the "created" callback.
56
- * Since the following listener callbacks as well as any potential
57
- * event callback defined in the developer's app are set on
58
- * the same element, we need to make sure the following callbacks
59
- * are set first so they fire first. If the developer's callback fires first
60
- * then the reactive reference will not have been updated yet.
61
- */
62
- const vModelDirective = {
63
- created: (el) => {
64
- const eventsNames = Array.isArray(modelUpdateEvent) ? modelUpdateEvent : [modelUpdateEvent];
65
- eventsNames.forEach((eventName) => {
66
- el.addEventListener(eventName.toLowerCase(), (e) => {
67
- /**
68
- * Only update the v-model binding if the event's target is the element we are
69
- * listening on. For example, Component A could emit ionChange, but it could also
70
- * have a descendant Component B that also emits ionChange. We only want to update
71
- * the v-model for Component A when ionChange originates from that element and not
72
- * when ionChange bubbles up from Component B.
73
- */
74
- if (e.target.tagName === el.tagName) {
75
- modelPropValue = (e?.target)[modelProp];
76
- emit(UPDATE_VALUE_EVENT, modelPropValue);
77
- }
78
- });
79
- });
80
- },
81
- };
82
- const currentInstance = getCurrentInstance();
83
- const hasRouter = currentInstance?.appContext?.provides[NAV_MANAGER];
84
- const navManager = hasRouter ? inject(NAV_MANAGER) : undefined;
85
- const handleRouterLink = (ev) => {
86
- const { routerLink } = props;
87
- if (routerLink === EMPTY_PROP)
88
- return;
89
- if (navManager !== undefined) {
90
- /**
91
- * This prevents the browser from
92
- * performing a page reload when pressing
93
- * an Ionic component with routerLink.
94
- * The page reload interferes with routing
95
- * and causes ion-back-button to disappear
96
- * since the local history is wiped on reload.
97
- */
98
- ev.preventDefault();
99
- let navigationPayload = { event: ev };
100
- for (const key in props) {
101
- const value = props[key];
102
- if (props.hasOwnProperty(key) && key.startsWith(ROUTER_PROP_PREFIX) && value !== EMPTY_PROP) {
103
- navigationPayload[key] = value;
104
- }
105
- }
106
- navManager.navigate(navigationPayload);
107
- }
108
- else {
109
- console.warn('Tried to navigate, but no router was found. Make sure you have mounted Vue Router.');
110
- }
111
- };
112
- return () => {
113
- modelPropValue = props[modelProp];
114
- getComponentClasses(attrs.class).forEach((value) => {
115
- classes.add(value);
116
- });
117
- const oldClick = props.onClick;
118
- const handleClick = (ev) => {
119
- if (oldClick !== undefined) {
120
- oldClick(ev);
121
- }
122
- if (!ev.defaultPrevented) {
123
- handleRouterLink(ev);
124
- }
125
- };
126
- let propsToAdd = {
127
- ref: containerRef,
128
- class: getElementClasses(containerRef, classes),
129
- onClick: handleClick,
130
- };
131
- /**
132
- * We can use Object.entries here
133
- * to avoid the hasOwnProperty check,
134
- * but that would require 2 iterations
135
- * where as this only requires 1.
136
- */
137
- for (const key in props) {
138
- const value = props[key];
139
- if ((props.hasOwnProperty(key) && value !== EMPTY_PROP) || key.startsWith(ARIA_PROP_PREFIX)) {
140
- propsToAdd[key] = value;
141
- }
142
- }
143
- if (modelProp) {
144
- /**
145
- * If form value property was set using v-model
146
- * then we should use that value.
147
- * Otherwise, check to see if form value property
148
- * was set as a static value (i.e. no v-model).
149
- */
150
- if (props[MODEL_VALUE] !== EMPTY_PROP) {
151
- propsToAdd = {
152
- ...propsToAdd,
153
- [modelProp]: props[MODEL_VALUE],
154
- };
155
- }
156
- else if (modelPropValue !== EMPTY_PROP) {
157
- propsToAdd = {
158
- ...propsToAdd,
159
- [modelProp]: modelPropValue,
160
- };
161
- }
162
- }
163
- // If router link is defined, add href to props
164
- // in order to properly render an anchor tag inside
165
- // of components that should become activatable and
166
- // focusable with router link.
167
- if (props[ROUTER_LINK_VALUE] !== EMPTY_PROP) {
168
- propsToAdd = {
169
- ...propsToAdd,
170
- href: props[ROUTER_LINK_VALUE],
171
- };
172
- }
173
- /**
174
- * vModelDirective is only needed on components that support v-model.
175
- * As a result, we conditionally call withDirectives with v-model components.
176
- */
177
- const node = h(name, propsToAdd, slots.default && slots.default());
178
- return modelProp === undefined ? node : withDirectives(node, [[vModelDirective]]);
179
- };
180
- });
181
- if (typeof Container !== 'function') {
182
- Container.name = name;
183
- Container.props = {
184
- [ROUTER_LINK_VALUE]: DEFAULT_EMPTY_PROP,
185
- };
186
- componentProps.forEach((componentProp) => {
187
- Container.props[componentProp] = DEFAULT_EMPTY_PROP;
188
- });
189
- if (modelProp) {
190
- Container.props[MODEL_VALUE] = DEFAULT_EMPTY_PROP;
191
- Container.emits = [UPDATE_VALUE_EVENT];
192
- }
193
- }
194
- return Container;
195
- };
196
- //#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