@myop/cli 0.1.42 → 0.1.46

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.
@@ -0,0 +1,263 @@
1
+ ---
2
+ name: myop-vue-host
3
+ description: "Integrate Myop components into Vue 3 applications using @myop/vue. This skill covers MyopComponent props, events, slots, data binding, preloading, auto-generated packages, and local dev setup. Activate when the user is building a Vue app that hosts Myop components, or when you see @myop/vue in package.json."
4
+ ---
5
+
6
+ # Myop Vue Host Integration
7
+
8
+ Embed Myop components in Vue 3 applications using `@myop/vue`.
9
+
10
+ ## When This Skill Activates
11
+
12
+ - `@myop/vue` is in `package.json` dependencies
13
+ - User asks to "add a Myop component to Vue", "integrate Myop in Vue"
14
+ - Files import from `@myop/vue`
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install @myop/vue @myop/sdk
20
+ ```
21
+
22
+ Requires **Vue 3.5+**.
23
+
24
+ ## Quick Start
25
+
26
+ ### Option 1: Auto-Generated Package (Recommended)
27
+
28
+ ```bash
29
+ npm install https://cloud.myop.dev/npm/{componentId}/vue
30
+ ```
31
+
32
+ ```vue
33
+ <script setup lang="ts">
34
+ import { MyComponent } from "@myop/my-component";
35
+ </script>
36
+
37
+ <template>
38
+ <MyComponent
39
+ :data="{ title: 'Hello', items: ['a', 'b'] }"
40
+ @cta="(action, payload) => console.log(action, payload)"
41
+ />
42
+ </template>
43
+ ```
44
+
45
+ The auto-generated package bakes in the `componentId` and exports typed props and events.
46
+
47
+ ### Option 2: MyopComponent Directly
48
+
49
+ ```vue
50
+ <script setup lang="ts">
51
+ import { MyopComponent } from "@myop/vue";
52
+ </script>
53
+
54
+ <template>
55
+ <MyopComponent
56
+ component-id="your-component-id"
57
+ :data="{ title: 'Hello' }"
58
+ @cta="(action, payload) => console.log(action, payload)"
59
+ />
60
+ </template>
61
+ ```
62
+
63
+ ## MyopComponent Props
64
+
65
+ | Prop | Type | Default | Description |
66
+ |------|------|---------|-------------|
67
+ | `componentId` | `string` | — | Myop component ID (UUID) |
68
+ | `data` | `TData` | — | Data passed to `myop_init_interface`. Reactive — deep-watched |
69
+ | `on` | `(action, payload) => void` | — | Generic CTA callback (alternative to `@cta` event) |
70
+ | `fadeDuration` | `number` | `200` | Loader fade-out duration in ms |
71
+ | `autoSize` | `boolean` | `false` | Auto-size container to match iframe content |
72
+ | `environment` | `string` | — | Load from specific environment |
73
+ | `preview` | `boolean` | `false` | Load unpublished preview version |
74
+ | `componentConfig` | `IComponentInstanceConfig` | — | Direct config object (advanced) |
75
+
76
+ ## Events
77
+
78
+ | Event | Payload | Description |
79
+ |-------|---------|-------------|
80
+ | `@load` | `ITypedMyopComponent` | Component finished loading |
81
+ | `@error` | `string` | Load failure message |
82
+ | `@sizeChange` | `SizeInfo` | Auto-sized component changed dimensions |
83
+ | `@cta` | `action: string, payload: any` | CTA event from component |
84
+
85
+ ```vue
86
+ <MyopComponent
87
+ component-id="..."
88
+ :data="data"
89
+ @load="onComponentLoaded"
90
+ @error="onError"
91
+ @cta="handleCta"
92
+ />
93
+ ```
94
+
95
+ ```ts
96
+ function handleCta(action: string, payload: any) {
97
+ switch (action) {
98
+ case 'item-selected':
99
+ console.log(payload.itemId);
100
+ break;
101
+ case 'form-submitted':
102
+ console.log(payload);
103
+ break;
104
+ }
105
+ }
106
+ ```
107
+
108
+ ## Slots
109
+
110
+ | Slot | Purpose |
111
+ |------|---------|
112
+ | `loader` | Custom loading indicator |
113
+ | `fallback` | Custom error fallback UI |
114
+
115
+ ```vue
116
+ <MyopComponent component-id="...">
117
+ <template #loader>
118
+ <div class="spinner">Loading...</div>
119
+ </template>
120
+ <template #fallback>
121
+ <div class="error">Failed to load component</div>
122
+ </template>
123
+ </MyopComponent>
124
+ ```
125
+
126
+ ## Data Binding
127
+
128
+ The `data` prop is **deep-watched**. Vue reactivity changes automatically call `myop_init_interface`:
129
+
130
+ ```vue
131
+ <script setup>
132
+ import { ref } from 'vue';
133
+
134
+ const count = ref(0);
135
+ </script>
136
+
137
+ <template>
138
+ <button @click="count++">+1</button>
139
+ <MyopComponent
140
+ component-id="counter-display"
141
+ :data="{ count }"
142
+ />
143
+ </template>
144
+ ```
145
+
146
+ **Important:** Vue reactive proxies are automatically stripped (via `JSON.parse(JSON.stringify())`) before passing data to the SDK, so no Vue internals leak into the iframe.
147
+
148
+ ## Preloading
149
+
150
+ ```ts
151
+ import { preloadComponents, isPreloaded } from "@myop/vue";
152
+
153
+ await preloadComponents(["component-id-1", "component-id-2"]);
154
+ await preloadComponents(["component-id-1"], "staging");
155
+
156
+ if (isPreloaded("component-id-1")) {
157
+ console.log("Will render instantly");
158
+ }
159
+ ```
160
+
161
+ ## Configuration Functions
162
+
163
+ ```ts
164
+ import { enableLocalDev, setCloudRepositoryUrl, setEnvironment } from "@myop/vue";
165
+
166
+ enableLocalDev(); // localhost:9292
167
+ setCloudRepositoryUrl("https://custom"); // Custom URL
168
+ setEnvironment("staging"); // Default environment
169
+ ```
170
+
171
+ ## Accessing Component Instance
172
+
173
+ Via template ref:
174
+
175
+ ```vue
176
+ <script setup>
177
+ import { ref } from 'vue';
178
+
179
+ const myopRef = ref(null);
180
+
181
+ function updateManually() {
182
+ myopRef.value?.myopComponent?.props?.myop_init_interface({ title: 'Updated' });
183
+ }
184
+ </script>
185
+
186
+ <template>
187
+ <MyopComponent ref="myopRef" component-id="..." />
188
+ </template>
189
+ ```
190
+
191
+ Exposed properties: `myopComponent` (SDK component instance), `isLoaded` (boolean ref).
192
+
193
+ ## Generics (TypeScript)
194
+
195
+ The component supports Vue 3 generics for typed `data` and events:
196
+
197
+ ```vue
198
+ <script setup lang="ts" generic="TData, TCtaPayloads extends Record<string, any>">
199
+ // TypeScript generics flow through to props and events
200
+ </script>
201
+ ```
202
+
203
+ ## Complete Example
204
+
205
+ ```vue
206
+ <script setup lang="ts">
207
+ import { ref } from 'vue';
208
+ import { MyopComponent, preloadComponents } from '@myop/vue';
209
+
210
+ preloadComponents(['sidebar-abc123']);
211
+
212
+ const tasks = ref([
213
+ { id: '1', title: 'Review PR', completed: false },
214
+ { id: '2', title: 'Deploy', completed: true },
215
+ ]);
216
+
217
+ function handleCta(action: string, payload: any) {
218
+ if (action === 'task-toggled') {
219
+ const task = tasks.value.find(t => t.id === payload.taskId);
220
+ if (task) task.completed = payload.completed;
221
+ }
222
+ if (action === 'task-deleted') {
223
+ tasks.value = tasks.value.filter(t => t.id !== payload.taskId);
224
+ }
225
+ }
226
+ </script>
227
+
228
+ <template>
229
+ <div style="display: flex; height: 100vh">
230
+ <MyopComponent
231
+ component-id="sidebar-abc123"
232
+ :data="{ tasks }"
233
+ @cta="handleCta"
234
+ style="width: 300px"
235
+ >
236
+ <template #loader>
237
+ <div>Loading...</div>
238
+ </template>
239
+ </MyopComponent>
240
+ </div>
241
+ </template>
242
+ ```
243
+
244
+ ## Auto-Generated Vue Package
245
+
246
+ ```bash
247
+ npm install https://cloud.myop.dev/npm/{componentId}/vue
248
+ ```
249
+
250
+ The generated package uses `defineComponent` with the `componentId` baked in. It emits `load`, `error`, `sizeChange`, and `cta` events — same API as `MyopComponent` but without needing a `componentId` prop.
251
+
252
+ ## TypeScript Types
253
+
254
+ ```ts
255
+ import type {
256
+ IPropTypes, // Full props type
257
+ ITypedMyopComponent, // Component instance with typed props
258
+ IMyopComponentProps, // myop_init_interface + myop_cta_handler
259
+ SizeInfo, // { width, height, autoSizingWidth, autoSizingHeight }
260
+ EventHandlerProps, // Generated event handler types
261
+ KebabToPascal, // Utility type
262
+ } from "@myop/vue";
263
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myop/cli",
3
- "version": "0.1.42",
3
+ "version": "0.1.46",
4
4
  "description": "Myop cli",
5
5
  "type": "module",
6
6
  "repository": {
@@ -21,7 +21,7 @@
21
21
  "README.md"
22
22
  ],
23
23
  "bin": {
24
- "myop": "./dist/myop-cli.js"
24
+ "myop": "dist/myop-cli.js"
25
25
  },
26
26
  "scripts": {
27
27
  "try": "myop",