@myop/vue 0.0.24 → 0.0.26

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 CHANGED
@@ -1,5 +1,417 @@
1
- # Vue 3 + TypeScript + Vite
1
+ # @myop/vue
2
2
 
3
- This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
3
+ Official Vue bindings for embedding [Myop](https://myop.dev) components in your Vue applications.
4
4
 
5
- Learn more about the recommended Project Setup and IDE Support in the [Vue Docs TypeScript Guide](https://vuejs.org/guide/typescript/overview.html#project-setup).
5
+ Myop components are framework-agnostic UI components that can be updated in real-time without redeploying your application. Build once, embed anywhere, and iterate instantly. Perfect for teams that need to ship UI changes fast, A/B test components, or empower non-developers to customize the interface. Myop is also the safest way to adopt AI-generated components in your application—whether created by developers or non-developers—with built-in sandboxing and controlled integration.
6
+
7
+ [![npm version](https://img.shields.io/npm/v/@myop/vue.svg)](https://www.npmjs.com/package/@myop/vue)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
9
+ [![Discord](https://img.shields.io/badge/Discord-Join%20us-5865F2?logo=discord&logoColor=white)](https://myop.dev/discord)
10
+
11
+ [Website](https://www.myop.dev/) | [Documentation](https://docs.myop.dev/) | [Dashboard](https://dashboard.myop.dev/) | [Discord](https://myop.dev/discord)
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install @myop/vue
17
+ ```
18
+
19
+ ```bash
20
+ yarn add @myop/vue
21
+ ```
22
+
23
+ ```bash
24
+ pnpm add @myop/vue
25
+ ```
26
+
27
+ ## Auto-Generated Vue Components
28
+
29
+ Myop automatically generates a typed Vue component package for every component you create in the [dashboard](https://dashboard.myop.dev/). Install it directly via npm:
30
+
31
+ ```bash
32
+ npm install https://cloud.myop.dev/npm/{component-id}/vue
33
+ ```
34
+
35
+ Then import and use it like any Vue component. For example, if you created a table component called "users-table" in the dashboard:
36
+
37
+ ```vue
38
+ <script setup lang="ts">
39
+ import { UsersTable } from "@myop/users-table";
40
+
41
+ const users = [
42
+ { id: 1, name: "Alice", email: "alice@example.com", role: "Admin" },
43
+ { id: 2, name: "Bob", email: "bob@example.com", role: "User" },
44
+ { id: 3, name: "Charlie", email: "charlie@example.com", role: "User" },
45
+ ];
46
+
47
+ function handleRowClicked(payload: { rowData: any }) {
48
+ console.log("Selected user:", payload.rowData);
49
+ }
50
+
51
+ function handleDeleteClicked(payload: { userId: number }) {
52
+ deleteUser(payload.userId);
53
+ }
54
+
55
+ function handleExportRequested(payload: { format: "csv" | "xlsx" }) {
56
+ exportToFormat(payload.format);
57
+ }
58
+ </script>
59
+
60
+ <template>
61
+ <UsersTable
62
+ :data="{ rows: users }"
63
+ @row-clicked="handleRowClicked"
64
+ @delete-clicked="handleDeleteClicked"
65
+ @export-requested="handleExportRequested"
66
+ />
67
+ </template>
68
+ ```
69
+
70
+ **Why this is powerful:**
71
+
72
+ - **Fully typed** — The generated package includes complete TypeScript types for your component's data interface and all CTA event payloads
73
+ - **Auto loaded** — Components are fetched and rendered automatically, no manual setup required
74
+ - **Not in your code** — The actual component implementation lives on Myop and is loaded at runtime. Update your component in the dashboard and it's instantly live—no rebuild, no redeploy
75
+ - **Zero bundle impact** — The entire `@myop/vue` package costs only ~6KB gzipped—and that's the total cost whether you use 1, 2, or 1,000 components. Auto-generated component packages are just thin typed wrappers. The actual component implementations are loaded at runtime, meaning your Myop components can be as complex, feature-rich, and heavy as you need without adding a single byte to your application bundle. Consider typical bundle costs: a chart library (~60KB), a map component (~200KB), a data grid (~150KB), a rich text editor (~100KB), or a chat widget with emoji picker (~80KB). With Myop, all of these cost ~0KB to your bundle—they load on-demand when needed
76
+
77
+ **Environment options:**
78
+
79
+ Set the default environment for all components using `setEnvironment`:
80
+
81
+ ```ts
82
+ import { setEnvironment } from "@myop/vue";
83
+
84
+ // Set default environment for all component loads
85
+ setEnvironment("staging");
86
+ ```
87
+
88
+ You can also override the environment directly on a specific component:
89
+
90
+ ```vue
91
+ <template>
92
+ <UsersTable
93
+ :data="{ rows: users }"
94
+ :preview="true"
95
+ environment="staging"
96
+ />
97
+ </template>
98
+ ```
99
+
100
+ Environments are fully configurable in the [dashboard](https://dashboard.myop.dev/), allowing you to test changes in staging before publishing to production.
101
+
102
+ ## Requirements
103
+
104
+ - Vue 3.0+
105
+
106
+ ## Quick Start
107
+
108
+ ```vue
109
+ <script setup lang="ts">
110
+ import { MyopComponent } from "@myop/vue";
111
+
112
+ function handleAction(action: string, payload: any) {
113
+ console.log("Action:", action, "Payload:", payload);
114
+ }
115
+ </script>
116
+
117
+ <template>
118
+ <MyopComponent
119
+ componentId="your-component-id"
120
+ :style="{ width: '600px', height: '400px' }"
121
+ @action="handleAction"
122
+ />
123
+ </template>
124
+ ```
125
+
126
+ ## Components
127
+
128
+ ### `MyopComponent`
129
+
130
+ The main component for embedding Myop components.
131
+
132
+ ```vue
133
+ <script setup lang="ts">
134
+ import { MyopComponent } from "@myop/vue";
135
+
136
+ const items = [{ id: 1, name: "Item 1" }, { id: 2, name: "Item 2" }];
137
+
138
+ function handleRowClicked(payload: any) {
139
+ console.log("Row clicked:", payload);
140
+ }
141
+
142
+ function handleLoad(component: any) {
143
+ console.log("Loaded!", component);
144
+ }
145
+
146
+ function handleError(error: string) {
147
+ console.error("Error:", error);
148
+ }
149
+ </script>
150
+
151
+ <template>
152
+ <MyopComponent
153
+ componentId="abc123"
154
+ :data="{ items }"
155
+ @row-clicked="handleRowClicked"
156
+ @load="handleLoad"
157
+ @error="handleError"
158
+ />
159
+ </template>
160
+ ```
161
+
162
+ #### Props
163
+
164
+ | Prop | Type | Description |
165
+ |------|------|-------------|
166
+ | `componentId` | `string` | The ID of the Myop component to load |
167
+ | `data` | `object` | Data to pass to the component via `myop_init_interface` |
168
+ | `style` | `object` | CSS styles for the container |
169
+ | `#loader` | `slot` | Loading indicator slot (default: no loader). Use `<MyopLoader />` for default Myop loader |
170
+ | `#fallback` | `slot` | Error fallback slot (default: `<MyopFallback />`). Override with custom component |
171
+ | `fadeDuration` | `number` | Loader fade-out duration in ms (default: `200`) |
172
+ | `environment` | `string` | Load from a specific environment (e.g., `"staging"`, `"prod"`) |
173
+ | `preview` | `boolean` | Load the unpublished preview version of the component |
174
+
175
+ #### Events
176
+
177
+ | Event | Payload | Description |
178
+ |-------|---------|-------------|
179
+ | `@action` | `(action, payload)` | Generic handler for all CTA events |
180
+ | `@[action-name]` | `payload` | Handler for specific actions (e.g., `@row-clicked`) |
181
+ | `@load` | `component` | Called when the component finishes loading |
182
+ | `@error` | `error: string` | Called when loading fails |
183
+
184
+ #### Environments & Preview
185
+
186
+ Myop supports multiple environments, allowing you to test changes before going live:
187
+
188
+ ```vue
189
+ <template>
190
+ <!-- Production (default) -->
191
+ <MyopComponent componentId="abc123" />
192
+
193
+ <!-- Load from staging environment -->
194
+ <MyopComponent componentId="abc123" environment="staging" />
195
+
196
+ <!-- Load unpublished preview version (for testing before publishing) -->
197
+ <MyopComponent componentId="abc123" :preview="true" />
198
+
199
+ <!-- Combine both: preview version in staging -->
200
+ <MyopComponent componentId="abc123" environment="staging" :preview="true" />
201
+ </template>
202
+ ```
203
+
204
+ Environments are configured in the [dashboard](https://dashboard.myop.dev/). Use `:preview="true"` to test unpublished changes before making them live.
205
+
206
+ ### `MyopContainer` (Legacy)
207
+
208
+ The legacy container component. Use `MyopComponent` for new projects.
209
+
210
+ ```vue
211
+ <script setup lang="ts">
212
+ import { MyopContainer } from "@myop/vue";
213
+
214
+ function handleReady(component: any) {
215
+ console.log("Ready!", component);
216
+ }
217
+ </script>
218
+
219
+ <template>
220
+ <MyopContainer
221
+ componentId="abc123"
222
+ :onReady="handleReady"
223
+ />
224
+ </template>
225
+ ```
226
+
227
+ ## Type-Safe Event Handlers
228
+
229
+ Define your CTA payloads for fully typed event handlers:
230
+
231
+ ```vue
232
+ <script setup lang="ts">
233
+ import { MyopComponent } from "@myop/vue";
234
+
235
+ // Define your component's data and CTA payload types
236
+ interface MyData {
237
+ items: { id: string; name: string }[];
238
+ }
239
+
240
+ interface RowClickedPayload {
241
+ rowIndex: number;
242
+ rowData: any;
243
+ }
244
+
245
+ interface ItemSelectedPayload {
246
+ itemId: string;
247
+ }
248
+
249
+ interface ExportRequestedPayload {
250
+ format: "csv" | "json";
251
+ }
252
+
253
+ function handleRowClicked(payload: RowClickedPayload) {
254
+ console.log("Row clicked:", payload.rowIndex);
255
+ }
256
+
257
+ function handleItemSelected(payload: ItemSelectedPayload) {
258
+ console.log("Item selected:", payload.itemId);
259
+ }
260
+
261
+ function handleAction(action: string, payload: any) {
262
+ console.log(action, payload);
263
+ }
264
+ </script>
265
+
266
+ <template>
267
+ <MyopComponent
268
+ componentId="dashboard-component"
269
+ :data="{ items: [...] }"
270
+ @row-clicked="handleRowClicked"
271
+ @item-selected="handleItemSelected"
272
+ @action="handleAction"
273
+ />
274
+ </template>
275
+ ```
276
+
277
+ ## Configuration
278
+
279
+ ### Preloading Components
280
+
281
+ Preload components for faster rendering:
282
+
283
+ ```ts
284
+ import { preloadComponents, isPreloaded } from "@myop/vue";
285
+
286
+ // Preload multiple components
287
+ await preloadComponents(["component-1", "component-2"]);
288
+
289
+ // Check if a component is preloaded
290
+ if (isPreloaded("component-1")) {
291
+ console.log("Component is cached and ready");
292
+ }
293
+ ```
294
+
295
+ ### Custom Repository URL
296
+
297
+ ```ts
298
+ import { setCloudRepositoryUrl } from "@myop/vue";
299
+
300
+ // Point to a custom Myop server
301
+ setCloudRepositoryUrl("https://your-custom-server.com");
302
+ ```
303
+
304
+ ### Environment Configuration
305
+
306
+ ```ts
307
+ import { setEnvironment } from "@myop/vue";
308
+
309
+ // Set default environment for all component loads
310
+ setEnvironment("staging");
311
+ ```
312
+
313
+ ### Local Development
314
+
315
+ ```ts
316
+ import { enableLocalDev } from "@myop/vue";
317
+
318
+ // Connect to local Myop development server (localhost:9292)
319
+ enableLocalDev();
320
+ ```
321
+
322
+ ### Advanced: Custom Repository
323
+
324
+ ```ts
325
+ import { setCloudRepository, getCloudRepository } from "@myop/vue";
326
+ import { CloudRepository } from "@myop/sdk/helpers";
327
+
328
+ // Set a custom CloudRepository instance
329
+ const customRepo = new CloudRepository("https://custom-url.com");
330
+ setCloudRepository(customRepo);
331
+
332
+ // Get the current repository
333
+ const repo = getCloudRepository();
334
+ ```
335
+
336
+ ## Loading & Error States
337
+
338
+ By default, no loader is shown while the component loads. The Myop-branded fallback is displayed automatically on error.
339
+
340
+ ### Using the Default Myop Loader
341
+
342
+ ```vue
343
+ <script setup lang="ts">
344
+ import { MyopComponent, MyopLoader } from "@myop/vue";
345
+ </script>
346
+
347
+ <template>
348
+ <MyopComponent componentId="my-component" :fadeDuration="300">
349
+ <template #loader>
350
+ <MyopLoader />
351
+ </template>
352
+ </MyopComponent>
353
+ </template>
354
+ ```
355
+
356
+ ### Custom Loading State
357
+
358
+ ```vue
359
+ <template>
360
+ <MyopComponent componentId="my-component" :fadeDuration="300">
361
+ <template #loader>
362
+ <div class="custom-loader">
363
+ <Spinner />
364
+ <p>Loading component...</p>
365
+ </div>
366
+ </template>
367
+ </MyopComponent>
368
+ </template>
369
+ ```
370
+
371
+ ### Custom Error Fallback
372
+
373
+ ```vue
374
+ <script setup lang="ts">
375
+ import { MyopComponent, MyopFallback } from "@myop/vue";
376
+ </script>
377
+
378
+ <template>
379
+ <MyopComponent componentId="my-component">
380
+ <!-- Custom fallback -->
381
+ <template #fallback>
382
+ <div class="error-state">
383
+ <p>Failed to load component</p>
384
+ <button @click="() => window.location.reload()">Retry</button>
385
+ </div>
386
+ </template>
387
+ </MyopComponent>
388
+
389
+ <!-- Or use default Myop fallback explicitly -->
390
+ <MyopComponent componentId="other-component">
391
+ <template #fallback>
392
+ <MyopFallback />
393
+ </template>
394
+ </MyopComponent>
395
+ </template>
396
+ ```
397
+
398
+ ## API Reference
399
+
400
+ ### Exports
401
+
402
+ | Export | Description |
403
+ |--------|-------------|
404
+ | `MyopComponent` | Main component for embedding Myop components |
405
+ | `MyopLoader` | Default Myop-branded loading indicator (opt-in) |
406
+ | `MyopFallback` | Default Myop-branded error fallback |
407
+ | `preloadComponents` | Preload components for faster rendering |
408
+ | `isPreloaded` | Check if a component is cached |
409
+ | `enableLocalDev` | Enable local development mode |
410
+ | `setCloudRepositoryUrl` | Set custom server URL |
411
+ | `setCloudRepository` | Set custom CloudRepository instance |
412
+ | `getCloudRepository` | Get current CloudRepository instance |
413
+ | `setEnvironment` | Set default environment |
414
+
415
+ ## License
416
+
417
+ MIT
@@ -0,0 +1,27 @@
1
+ import { type IMyopComponent } from "@myop/sdk/host";
2
+ import type { SizeInfo, ITypedMyopComponent, IBaseProps } from "../types";
3
+ declare const _default: <TData = any, TCtaPayloads extends Record<string, any> = Record<string, any>>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
4
+ props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{
5
+ readonly onError?: ((error: string) => any) | undefined;
6
+ readonly onLoad?: ((component: ITypedMyopComponent<TData, TCtaPayloads>) => any) | undefined;
7
+ readonly onSizeChange?: ((size: SizeInfo) => any) | undefined;
8
+ readonly onCta?: ((action: string, payload: any) => any) | undefined;
9
+ } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, "onLoad" | "onError" | "onSizeChange" | "onCta"> & IBaseProps<TData, TCtaPayloads> & Partial<{}>> & import("vue").PublicProps;
10
+ expose(exposed: import("vue").ShallowUnwrapRef<{
11
+ myopComponent: import("vue").ShallowRef<IMyopComponent<any, any> | null, IMyopComponent<any, any> | null>;
12
+ isLoaded: import("vue").Ref<boolean, boolean>;
13
+ }>): void;
14
+ attrs: any;
15
+ slots: {
16
+ loader?: (props: {}) => any;
17
+ } & {
18
+ fallback?: (props: {}) => any;
19
+ };
20
+ emit: ((evt: "error", error: string) => void) & ((evt: "load", component: ITypedMyopComponent<TData, TCtaPayloads>) => void) & ((evt: "sizeChange", size: SizeInfo) => void) & ((evt: "cta", action: string, payload: any) => void);
21
+ }>) => import("vue").VNode & {
22
+ __ctx?: Awaited<typeof __VLS_setup>;
23
+ };
24
+ export default _default;
25
+ type __VLS_PrettifyLocal<T> = {
26
+ [K in keyof T]: T[K];
27
+ } & {};
@@ -0,0 +1,12 @@
1
+ declare var __VLS_1: {};
2
+ type __VLS_Slots = {} & {
3
+ default?: (props: typeof __VLS_1) => any;
4
+ };
5
+ declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
6
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
7
+ export default _default;
8
+ type __VLS_WithSlots<T, S> = T & {
9
+ new (): {
10
+ $slots: S;
11
+ };
12
+ };
@@ -0,0 +1,19 @@
1
+ interface Props {
2
+ opacity?: number;
3
+ fadeDuration?: number;
4
+ }
5
+ declare var __VLS_1: {};
6
+ type __VLS_Slots = {} & {
7
+ default?: (props: typeof __VLS_1) => any;
8
+ };
9
+ declare const __VLS_component: import("vue").DefineComponent<Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{}>, {
10
+ opacity: number;
11
+ fadeDuration: number;
12
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
13
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
14
+ export default _default;
15
+ type __VLS_WithSlots<T, S> = T & {
16
+ new (): {
17
+ $slots: S;
18
+ };
19
+ };
package/dist/index.d.ts CHANGED
@@ -1 +1,44 @@
1
- export { default as MyopContainer } from './components/MyopVueComponent.vue';
1
+ export { default as MyopComponent } from "./components/MyopComponent.vue";
2
+ export { default as MyopLoader } from "./components/MyopLoader.vue";
3
+ export { default as MyopFallback } from "./components/MyopFallback.vue";
4
+ export { default as MyopContainer } from "./components/MyopVueComponent.vue";
5
+ export type { IMyopComponent } from "@myop/sdk/host";
6
+ export type { IComponentInstanceConfig, SizeInfo, IPropTypes, KebabToPascal, EventHandlerProps, IMyopComponentProps, ITypedMyopComponent, } from "./types";
7
+ import { CloudRepository } from "@myop/sdk/helpers";
8
+ /**
9
+ * Get the current CloudRepository instance
10
+ */
11
+ export declare const getCloudRepository: () => CloudRepository;
12
+ /**
13
+ * Check if a component is already preloaded/cached
14
+ * If env/preview not provided, checks if ANY version is preloaded
15
+ */
16
+ export declare const isPreloaded: (componentId: string, env?: string, preview?: boolean) => boolean;
17
+ /**
18
+ * Get the preloaded params for a component
19
+ */
20
+ export declare const getPreloadedParams: (componentId: string) => {
21
+ env: string;
22
+ preview: boolean;
23
+ } | undefined;
24
+ /**
25
+ * Enable local development mode
26
+ */
27
+ export declare const enableLocalDev: () => void;
28
+ /**
29
+ * Set a custom CloudRepository URL
30
+ */
31
+ export declare const setCloudRepositoryUrl: (url: string) => void;
32
+ /**
33
+ * Set a custom CloudRepository instance
34
+ */
35
+ export declare const setCloudRepository: (repository: CloudRepository) => void;
36
+ /**
37
+ * Set the default environment for component loading
38
+ */
39
+ export declare const setEnvironment: (env: string) => void;
40
+ /**
41
+ * Preload components for faster rendering.
42
+ * Continues even if some components fail to load.
43
+ */
44
+ export declare const preloadComponents: (ids: string[], env?: string, preview?: boolean) => Promise<PromiseSettledResult<import("@myop/sdk/common").IComponentConfig>[]>;