@live-change/frontend-template 0.9.198 → 0.9.199
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/.claude/rules/live-change-backend-actions-views-triggers.md +184 -0
- package/.claude/rules/live-change-backend-architecture.md +126 -0
- package/.claude/rules/live-change-backend-models-and-relations.md +188 -0
- package/.claude/rules/live-change-frontend-vue-primevue.md +291 -0
- package/.claude/rules/live-change-service-structure.md +89 -0
- package/.claude/skills/create-skills-and-rules.md +196 -0
- package/.claude/skills/live-change-design-actions-views-triggers.md +190 -0
- package/.claude/skills/live-change-design-models-relations.md +173 -0
- package/.claude/skills/live-change-design-service.md +132 -0
- package/.claude/skills/live-change-frontend-action-buttons.md +128 -0
- package/.claude/skills/live-change-frontend-action-form.md +143 -0
- package/.claude/skills/live-change-frontend-analytics.md +146 -0
- package/.claude/skills/live-change-frontend-command-forms.md +215 -0
- package/.claude/skills/live-change-frontend-data-views.md +182 -0
- package/.claude/skills/live-change-frontend-editor-form.md +177 -0
- package/.claude/skills/live-change-frontend-locale-time.md +171 -0
- package/.claude/skills/live-change-frontend-page-list-detail.md +200 -0
- package/.claude/skills/live-change-frontend-range-list.md +128 -0
- package/.claude/skills/live-change-frontend-ssr-setup.md +118 -0
- package/.cursor/rules/live-change-backend-actions-views-triggers.mdc +202 -0
- package/.cursor/rules/live-change-backend-architecture.mdc +131 -0
- package/.cursor/rules/live-change-backend-models-and-relations.mdc +194 -0
- package/.cursor/rules/live-change-frontend-vue-primevue.mdc +290 -0
- package/.cursor/rules/live-change-service-structure.mdc +107 -0
- package/.cursor/skills/live-change-design-actions-views-triggers.md +197 -0
- package/.cursor/skills/live-change-design-models-relations.md +168 -0
- package/.cursor/skills/live-change-design-service.md +75 -0
- package/.cursor/skills/live-change-frontend-action-buttons.md +128 -0
- package/.cursor/skills/live-change-frontend-action-form.md +143 -0
- package/.cursor/skills/live-change-frontend-analytics.md +146 -0
- package/.cursor/skills/live-change-frontend-command-forms.md +215 -0
- package/.cursor/skills/live-change-frontend-data-views.md +182 -0
- package/.cursor/skills/live-change-frontend-editor-form.md +177 -0
- package/.cursor/skills/live-change-frontend-locale-time.md +171 -0
- package/.cursor/skills/live-change-frontend-page-list-detail.md +200 -0
- package/.cursor/skills/live-change-frontend-range-list.md +128 -0
- package/.cursor/skills/live-change-frontend-ssr-setup.md +119 -0
- package/README.md +71 -0
- package/package.json +50 -50
- package/server/app.config.js +35 -0
- package/server/services.list.js +2 -0
- package/.nx/workspace-data/file-map.json +0 -195
- package/.nx/workspace-data/nx_files.nxt +0 -0
- package/.nx/workspace-data/project-graph.json +0 -8
- package/.nx/workspace-data/project-graph.lock +0 -0
- package/.nx/workspace-data/source-maps.json +0 -1
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Build one-shot action forms with actionData, AutoField and ActionButtons
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Skill: live-change-frontend-action-form (Claude Code)
|
|
6
|
+
|
|
7
|
+
Use this skill when you build **one-shot action forms** with `actionData` and `AutoField` in a LiveChange frontend.
|
|
8
|
+
|
|
9
|
+
## When to use
|
|
10
|
+
|
|
11
|
+
- You need a form for a command/action (not CRUD model editing).
|
|
12
|
+
- The form submits once, then shows a "done" state.
|
|
13
|
+
- You want draft auto-save while the user fills in the form.
|
|
14
|
+
|
|
15
|
+
**Editing a model record instead?** Use `editorData` (see `live-change-frontend-editor-form` skill).
|
|
16
|
+
**No form fields, just a button?** Use `api.command` (see `live-change-frontend-command-forms` skill).
|
|
17
|
+
|
|
18
|
+
## Step 1 – Set up actionData
|
|
19
|
+
|
|
20
|
+
```javascript
|
|
21
|
+
import { AutoField, actionData, ActionButtons } from '@live-change/frontend-auto-form'
|
|
22
|
+
|
|
23
|
+
const formData = await actionData({
|
|
24
|
+
service: 'blog',
|
|
25
|
+
action: 'publishArticle',
|
|
26
|
+
parameters: { article: props.articleId }, // fixed params (not shown as fields)
|
|
27
|
+
initialValue: { scheduleTime: null }, // initial values for editable fields
|
|
28
|
+
draft: true,
|
|
29
|
+
doneToast: 'Article published!',
|
|
30
|
+
onDone: (result) => {
|
|
31
|
+
router.push({ name: 'articles' })
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
For reactive parameters, use `computedAsync`:
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
import { computedAsync } from '@vueuse/core'
|
|
40
|
+
|
|
41
|
+
const formData = computedAsync(() =>
|
|
42
|
+
actionData({
|
|
43
|
+
service: 'blog',
|
|
44
|
+
action: 'publishArticle',
|
|
45
|
+
parameters: { article: props.articleId },
|
|
46
|
+
})
|
|
47
|
+
)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Step 2 – Build the template with AutoField
|
|
51
|
+
|
|
52
|
+
Use `formData.action.properties.*` as definitions and `formData.value.*` as v-model:
|
|
53
|
+
|
|
54
|
+
```vue
|
|
55
|
+
<template>
|
|
56
|
+
<form @submit.prevent="formData.submit()" @reset.prevent="formData.reset()">
|
|
57
|
+
<AutoField
|
|
58
|
+
:definition="formData.action.properties.scheduleTime"
|
|
59
|
+
v-model="formData.value.scheduleTime"
|
|
60
|
+
:error="formData.propertiesErrors?.scheduleTime"
|
|
61
|
+
label="Schedule time"
|
|
62
|
+
/>
|
|
63
|
+
<AutoField
|
|
64
|
+
:definition="formData.action.properties.message"
|
|
65
|
+
v-model="formData.value.message"
|
|
66
|
+
:error="formData.propertiesErrors?.message"
|
|
67
|
+
label="Message"
|
|
68
|
+
/>
|
|
69
|
+
|
|
70
|
+
<ActionButtons :actionFormData="formData" :resetButton="true" />
|
|
71
|
+
</form>
|
|
72
|
+
</template>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Step 3 – Handle done state
|
|
76
|
+
|
|
77
|
+
After successful submission, `formData.done` becomes `true`:
|
|
78
|
+
|
|
79
|
+
```vue
|
|
80
|
+
<template>
|
|
81
|
+
<div v-if="formData.done" class="text-center">
|
|
82
|
+
<i class="pi pi-check-circle text-4xl text-green-500 mb-2"></i>
|
|
83
|
+
<p>Article published successfully!</p>
|
|
84
|
+
</div>
|
|
85
|
+
<form v-else @submit.prevent="formData.submit()" @reset.prevent="formData.reset()">
|
|
86
|
+
<!-- fields + ActionButtons -->
|
|
87
|
+
</form>
|
|
88
|
+
</template>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Step 4 – Manual buttons (alternative to ActionButtons)
|
|
92
|
+
|
|
93
|
+
```vue
|
|
94
|
+
<div class="flex gap-2 justify-end">
|
|
95
|
+
<Button
|
|
96
|
+
type="submit"
|
|
97
|
+
:label="formData.submitting ? 'Executing...' : 'Execute'"
|
|
98
|
+
:icon="formData.submitting ? 'pi pi-spin pi-spinner' : 'pi pi-play'"
|
|
99
|
+
:disabled="formData.submitting"
|
|
100
|
+
/>
|
|
101
|
+
<Button type="reset" label="Reset" :disabled="!formData.changed" icon="pi pi-eraser" />
|
|
102
|
+
</div>
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## editorData vs actionData
|
|
106
|
+
|
|
107
|
+
| Aspect | `editorData` | `actionData` |
|
|
108
|
+
|---|---|---|
|
|
109
|
+
| Purpose | CRUD model editing | One-shot command form |
|
|
110
|
+
| Identifier | `model` + `identifiers` | `action` + `parameters` |
|
|
111
|
+
| Create/update | Detects automatically | Always "execute" |
|
|
112
|
+
| After submit | Record is saved | `done` becomes `true` |
|
|
113
|
+
| Definition source | `editor.model` | `formData.action` |
|
|
114
|
+
| `parameters` | Extra params on save | Fixed fields excluded from form |
|
|
115
|
+
|
|
116
|
+
## Key options
|
|
117
|
+
|
|
118
|
+
| Option | Default | Description |
|
|
119
|
+
|---|---|---|
|
|
120
|
+
| `service` | required | Service name |
|
|
121
|
+
| `action` | required | Action name |
|
|
122
|
+
| `parameters` | `{}` | Fixed identifier fields (not editable) |
|
|
123
|
+
| `initialValue` | `{}` | Initial values for editable fields |
|
|
124
|
+
| `draft` | `true` | Auto-save draft while filling |
|
|
125
|
+
| `debounce` | `600` | Debounce delay in ms |
|
|
126
|
+
| `doneToast` | `"Action done"` | Toast after success |
|
|
127
|
+
| `onDone` | – | Callback after success |
|
|
128
|
+
|
|
129
|
+
## Key returned properties
|
|
130
|
+
|
|
131
|
+
| Property | Description |
|
|
132
|
+
|---|---|
|
|
133
|
+
| `value` | Editable form data |
|
|
134
|
+
| `action` | Action definition (`.properties.*` for `AutoField`) |
|
|
135
|
+
| `editableProperties` | Properties not fixed by `parameters` |
|
|
136
|
+
| `changed` | Form differs from initial value |
|
|
137
|
+
| `submit()` | Execute the action |
|
|
138
|
+
| `submitting` | Action call in progress |
|
|
139
|
+
| `done` | `true` after success |
|
|
140
|
+
| `reset()` | Discard draft, restore initial value |
|
|
141
|
+
| `propertiesErrors` | Server validation errors per property |
|
|
142
|
+
| `draftChanged` | Draft auto-saved but not submitted |
|
|
143
|
+
| `savingDraft` | Draft auto-save in progress |
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Integrate analytics tracking with analytics.emit and provider wiring
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Skill: live-change-frontend-analytics (Claude Code)
|
|
6
|
+
|
|
7
|
+
Use this skill when you add **analytics tracking** to a LiveChange frontend.
|
|
8
|
+
|
|
9
|
+
## When to use
|
|
10
|
+
|
|
11
|
+
- You need to track user actions, page views, or custom events.
|
|
12
|
+
- You are integrating PostHog, GA4, or another analytics provider.
|
|
13
|
+
- You need consent-aware analytics.
|
|
14
|
+
|
|
15
|
+
## Step 1 – Emit events with `analytics`
|
|
16
|
+
|
|
17
|
+
Import `analytics` from `@live-change/vue3-components` and emit events:
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
import { analytics } from '@live-change/vue3-components'
|
|
21
|
+
|
|
22
|
+
// In a component or handler:
|
|
23
|
+
analytics.emit('article:published', { articleId: article.id })
|
|
24
|
+
analytics.emit('button:clicked', { action: 'delete', target: 'article' })
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Standard built-in events:
|
|
28
|
+
|
|
29
|
+
| Event | Payload | When emitted |
|
|
30
|
+
|---|---|---|
|
|
31
|
+
| `pageView` | route `to` object | On route change (automatic in App.vue) |
|
|
32
|
+
| `user:identification` | `{ user, session, identification, contacts }` | When user identity is known |
|
|
33
|
+
| `consent` | `{ analytics: boolean }` | When user grants/denies tracking consent |
|
|
34
|
+
| `locale:change` | locale settings object | When language/locale changes |
|
|
35
|
+
|
|
36
|
+
## Step 2 – Wire user identification in App.vue
|
|
37
|
+
|
|
38
|
+
Emit `user:identification` when the user profile is loaded:
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
import { analytics } from '@live-change/vue3-components'
|
|
42
|
+
import { usePath, live, useClient } from '@live-change/vue3-ssr'
|
|
43
|
+
import { computed, watch } from 'vue'
|
|
44
|
+
|
|
45
|
+
const client = useClient()
|
|
46
|
+
const path = usePath()
|
|
47
|
+
|
|
48
|
+
if(typeof window !== 'undefined') {
|
|
49
|
+
Promise.all([
|
|
50
|
+
live(path.userIdentification.myIdentification()),
|
|
51
|
+
]).then(([identification]) => {
|
|
52
|
+
const fullIdentification = computed(() => ({
|
|
53
|
+
user: client.value.user,
|
|
54
|
+
session: client.value.session,
|
|
55
|
+
identification: identification.value,
|
|
56
|
+
}))
|
|
57
|
+
watch(fullIdentification, (newId) => {
|
|
58
|
+
analytics.emit('user:identification', newId)
|
|
59
|
+
}, { immediate: true })
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Step 3 – Create a provider file (e.g. PostHog)
|
|
65
|
+
|
|
66
|
+
Create a file like `src/analytics/posthog.js`:
|
|
67
|
+
|
|
68
|
+
```javascript
|
|
69
|
+
import { analytics } from '@live-change/vue3-components'
|
|
70
|
+
import posthog from 'posthog-js'
|
|
71
|
+
|
|
72
|
+
posthog.init('phc_YOUR_KEY', {
|
|
73
|
+
api_host: 'https://eu.i.posthog.com',
|
|
74
|
+
person_profiles: 'always'
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
// Page views
|
|
78
|
+
analytics.on('pageView', (to) => {
|
|
79
|
+
posthog.register({
|
|
80
|
+
route: { name: to.name, params: to.params }
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
// User identification
|
|
85
|
+
analytics.on('user:identification', (identification) => {
|
|
86
|
+
if (!identification.user) {
|
|
87
|
+
posthog.reset()
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
posthog.identify(identification.user, {
|
|
91
|
+
firstName: identification.identification?.firstName,
|
|
92
|
+
lastName: identification.identification?.lastName,
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
// Consent
|
|
97
|
+
analytics.on('consent', (payload) => {
|
|
98
|
+
if (payload?.analytics === true) {
|
|
99
|
+
posthog.opt_in_capturing()
|
|
100
|
+
} else {
|
|
101
|
+
posthog.opt_out_capturing()
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
// Catch-all for custom events
|
|
106
|
+
const ignored = ['user:identification', 'pageView', 'consent']
|
|
107
|
+
analytics.on('*', (type, event) => {
|
|
108
|
+
if (ignored.includes(type)) return
|
|
109
|
+
posthog.capture(type, event)
|
|
110
|
+
})
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Import it in `App.vue`:
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
import './analytics/posthog'
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Step 4 – Emit custom events in components
|
|
120
|
+
|
|
121
|
+
```javascript
|
|
122
|
+
// Track a form submission
|
|
123
|
+
analytics.emit('form:submitted', { formName: 'contactForm' })
|
|
124
|
+
|
|
125
|
+
// Track a feature usage
|
|
126
|
+
analytics.emit('feature:used', { feature: 'darkMode', enabled: true })
|
|
127
|
+
|
|
128
|
+
// Track navigation
|
|
129
|
+
analytics.emit('navigation:click', { target: 'pricing', source: 'navbar' })
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Step 5 – Consent handling
|
|
133
|
+
|
|
134
|
+
Emit consent events from your consent banner:
|
|
135
|
+
|
|
136
|
+
```javascript
|
|
137
|
+
function acceptAnalytics() {
|
|
138
|
+
analytics.emit('consent', { analytics: true })
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function rejectAnalytics() {
|
|
142
|
+
analytics.emit('consent', { analytics: false })
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Provider files listen for `consent` and enable/disable tracking accordingly.
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Build forms with api.command, command-form, workingZone, confirm and toast
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Skill: live-change-frontend-command-forms (Claude Code)
|
|
6
|
+
|
|
7
|
+
Use this skill when you build **forms and actions** for a LiveChange frontend:
|
|
8
|
+
|
|
9
|
+
- calling `api.command`,
|
|
10
|
+
- using `<command-form>`,
|
|
11
|
+
- handling destructive actions with confirm + toast.
|
|
12
|
+
|
|
13
|
+
## Choosing the right pattern
|
|
14
|
+
|
|
15
|
+
Before using this skill, pick the right approach:
|
|
16
|
+
|
|
17
|
+
| Pattern | When to use |
|
|
18
|
+
|---|---|
|
|
19
|
+
| `editorData` | **Editing model records** (create/update). Drafts, validation, `AutoField`. See `live-change-frontend-editor-form` skill. |
|
|
20
|
+
| `actionData` | **One-shot action forms** (not CRUD). Submit once → done. See `live-change-frontend-action-form` skill. |
|
|
21
|
+
| `api.command` | **Single button or programmatic calls** (no form fields). This skill, Step 1. |
|
|
22
|
+
| `<command-form>` | **Avoid.** Legacy. Only for trivial prototypes without drafts or `AutoField`. This skill, Step 2. |
|
|
23
|
+
|
|
24
|
+
**Decision flow:**
|
|
25
|
+
|
|
26
|
+
1. Does the user fill in form fields? → **No**: use `api.command` (this skill).
|
|
27
|
+
2. Is it editing a model record? → **Yes**: use `editorData`.
|
|
28
|
+
3. Is it a one-shot action? → **Yes**: use `actionData`.
|
|
29
|
+
4. Only use `<command-form>` for the simplest throwaway cases.
|
|
30
|
+
|
|
31
|
+
## Step 1 – Use `api.command` directly
|
|
32
|
+
|
|
33
|
+
1. Import and create `api`:
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
import { api as useApi } from '@live-change/vue3-ssr'
|
|
37
|
+
|
|
38
|
+
const api = useApi()
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
2. Call commands as:
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
await api.command(['deviceManager', 'createMyUserDevice'], {
|
|
45
|
+
name: 'My device'
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
await api.command(['deviceManager', 'deleteMyUserDevice'], {
|
|
49
|
+
device: id
|
|
50
|
+
})
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
3. Wrap in `try/catch` if you need custom error handling.
|
|
54
|
+
|
|
55
|
+
## Step 2 – `<command-form>` (legacy – prefer editorData/actionData)
|
|
56
|
+
|
|
57
|
+
> **Note:** `<command-form>` is the oldest pattern. For new code, prefer `editorData` (model editing) or `actionData` (one-shot actions) – they support drafts, `AutoField`, and richer state management.
|
|
58
|
+
|
|
59
|
+
1. Use `<command-form>` only for trivial forms without drafts or `AutoField`.
|
|
60
|
+
2. Provide:
|
|
61
|
+
- `service` – service name,
|
|
62
|
+
- `action` – action name,
|
|
63
|
+
- `fields` – constant/hidden fields (e.g. ids).
|
|
64
|
+
|
|
65
|
+
Example:
|
|
66
|
+
|
|
67
|
+
```vue
|
|
68
|
+
<command-form
|
|
69
|
+
service="deviceManager"
|
|
70
|
+
action="updateMyUserDevice"
|
|
71
|
+
:fields="{ device: deviceId }"
|
|
72
|
+
>
|
|
73
|
+
<template #default="{ fieldProps, submit, busy }">
|
|
74
|
+
<div class="space-y-4">
|
|
75
|
+
<div>
|
|
76
|
+
<label class="block text-sm font-medium mb-1">
|
|
77
|
+
Name
|
|
78
|
+
</label>
|
|
79
|
+
<InputText v-bind="fieldProps('name')" class="w-full" />
|
|
80
|
+
</div>
|
|
81
|
+
<div class="flex justify-end gap-2">
|
|
82
|
+
<Button
|
|
83
|
+
label="Save"
|
|
84
|
+
icon="pi pi-check"
|
|
85
|
+
:loading="busy"
|
|
86
|
+
@click="submit"
|
|
87
|
+
/>
|
|
88
|
+
</div>
|
|
89
|
+
</div>
|
|
90
|
+
</template>
|
|
91
|
+
</command-form>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Step 3 – Confirm + Toast for destructive actions
|
|
95
|
+
|
|
96
|
+
1. Use PrimeVue `useConfirm` and `useToast`.
|
|
97
|
+
2. Put the `api.command` call in `accept`.
|
|
98
|
+
|
|
99
|
+
Example:
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
import { useConfirm } from 'primevue/useconfirm'
|
|
103
|
+
import { useToast } from 'primevue/usetoast'
|
|
104
|
+
import { api as useApi } from '@live-change/vue3-ssr'
|
|
105
|
+
|
|
106
|
+
const api = useApi()
|
|
107
|
+
const confirm = useConfirm()
|
|
108
|
+
const toast = useToast()
|
|
109
|
+
|
|
110
|
+
function deleteDevice(id) {
|
|
111
|
+
confirm.require({
|
|
112
|
+
message: 'Are you sure you want to delete this device?',
|
|
113
|
+
header: 'Confirmation',
|
|
114
|
+
icon: 'pi pi-exclamation-triangle',
|
|
115
|
+
accept: async () => {
|
|
116
|
+
await api.command(['deviceManager', 'deleteMyUserDevice'], { device: id })
|
|
117
|
+
toast.add({
|
|
118
|
+
severity: 'success',
|
|
119
|
+
summary: 'Deleted',
|
|
120
|
+
life: 2000
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Step 3b – WorkingZone for button actions (outside forms)
|
|
128
|
+
|
|
129
|
+
When a button triggers an async action outside a form, wrap it with `workingZone.addPromise()` so the global loading spinner activates:
|
|
130
|
+
|
|
131
|
+
```js
|
|
132
|
+
import { inject } from 'vue'
|
|
133
|
+
import { useToast } from 'primevue/usetoast'
|
|
134
|
+
import { useActions } from '@live-change/vue3-ssr'
|
|
135
|
+
|
|
136
|
+
const workingZone = inject('workingZone')
|
|
137
|
+
const toast = useToast()
|
|
138
|
+
const actions = useActions()
|
|
139
|
+
|
|
140
|
+
function createDevice() {
|
|
141
|
+
workingZone.addPromise('createDevice', (async () => {
|
|
142
|
+
const result = await actions.deviceManager.createMyUserDevice({ name: 'New device' })
|
|
143
|
+
toast.add({ severity: 'success', summary: 'Created', life: 2000 })
|
|
144
|
+
router.push({ name: 'device', params: { device: result } })
|
|
145
|
+
})())
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Combine with `confirm.require()` for destructive actions:
|
|
150
|
+
|
|
151
|
+
```js
|
|
152
|
+
function deleteDevice(id) {
|
|
153
|
+
confirm.require({
|
|
154
|
+
message: 'Are you sure?',
|
|
155
|
+
header: 'Confirmation',
|
|
156
|
+
icon: 'pi pi-trash',
|
|
157
|
+
acceptClass: 'p-button-danger',
|
|
158
|
+
accept: async () => {
|
|
159
|
+
workingZone.addPromise('deleteDevice', (async () => {
|
|
160
|
+
await actions.deviceManager.deleteMyUserDevice({ device: id })
|
|
161
|
+
toast.add({ severity: 'success', summary: 'Deleted', life: 2000 })
|
|
162
|
+
})())
|
|
163
|
+
}
|
|
164
|
+
})
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
For a detailed guide, see the `live-change-frontend-action-buttons` skill.
|
|
169
|
+
|
|
170
|
+
## Step 4 – Pattern for sensitive values (toggle + copy)
|
|
171
|
+
|
|
172
|
+
1. By default, hide sensitive values (keys, tokens, etc.).
|
|
173
|
+
2. Add:
|
|
174
|
+
- a toggle button (eye / eye-slash),
|
|
175
|
+
- a copy button with a toast.
|
|
176
|
+
|
|
177
|
+
Example:
|
|
178
|
+
|
|
179
|
+
```vue
|
|
180
|
+
<template>
|
|
181
|
+
<div class="flex items-center gap-2">
|
|
182
|
+
<code>
|
|
183
|
+
{{ revealed ? item.pairingKey : '••••••••••••' }}
|
|
184
|
+
</code>
|
|
185
|
+
<Button
|
|
186
|
+
:icon="revealed ? 'pi pi-eye-slash' : 'pi pi-eye'"
|
|
187
|
+
text
|
|
188
|
+
@click="revealed = !revealed"
|
|
189
|
+
/>
|
|
190
|
+
<Button
|
|
191
|
+
icon="pi pi-copy"
|
|
192
|
+
text
|
|
193
|
+
@click="copyToClipboard(item.pairingKey)"
|
|
194
|
+
/>
|
|
195
|
+
</div>
|
|
196
|
+
</template>
|
|
197
|
+
|
|
198
|
+
<script setup>
|
|
199
|
+
import { ref } from 'vue'
|
|
200
|
+
import { useToast } from 'primevue/usetoast'
|
|
201
|
+
|
|
202
|
+
const toast = useToast()
|
|
203
|
+
const revealed = ref(false)
|
|
204
|
+
|
|
205
|
+
async function copyToClipboard(text) {
|
|
206
|
+
await navigator.clipboard.writeText(text)
|
|
207
|
+
toast.add({
|
|
208
|
+
severity: 'info',
|
|
209
|
+
summary: 'Copied',
|
|
210
|
+
life: 1500
|
|
211
|
+
})
|
|
212
|
+
}
|
|
213
|
+
</script>
|
|
214
|
+
```
|
|
215
|
+
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Build reactive data views with usePath, live, .with() and useClient auth guards
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Skill: live-change-frontend-data-views (Claude Code)
|
|
6
|
+
|
|
7
|
+
Use this skill when you build **reactive data views** using `usePath`, `live`, `.with()`, and `useClient` in a LiveChange frontend.
|
|
8
|
+
|
|
9
|
+
## When to use
|
|
10
|
+
|
|
11
|
+
- You are loading data from backend views.
|
|
12
|
+
- Paths depend on reactive values (route params, props, client state).
|
|
13
|
+
- You need to load related objects alongside the main data.
|
|
14
|
+
- You need to restrict data loading for unauthenticated users.
|
|
15
|
+
|
|
16
|
+
## Step 1 – Basic data loading with computed paths
|
|
17
|
+
|
|
18
|
+
When paths depend on reactive values (route params, props), wrap them in `computed()`:
|
|
19
|
+
|
|
20
|
+
```javascript
|
|
21
|
+
import { computed, unref } from 'vue'
|
|
22
|
+
import { usePath, live } from '@live-change/vue3-ssr'
|
|
23
|
+
import { useRoute } from 'vue-router'
|
|
24
|
+
|
|
25
|
+
const path = usePath()
|
|
26
|
+
const route = useRoute()
|
|
27
|
+
const articleId = route.params.article
|
|
28
|
+
|
|
29
|
+
const articlePath = computed(() => path.blog.article({ article: unref(articleId) }))
|
|
30
|
+
const commentsPath = computed(() => path.blog.articleComments({ article: unref(articleId) }))
|
|
31
|
+
|
|
32
|
+
const [article, comments] = await Promise.all([
|
|
33
|
+
live(articlePath),
|
|
34
|
+
live(commentsPath),
|
|
35
|
+
])
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
In templates access `.value`:
|
|
39
|
+
|
|
40
|
+
```vue
|
|
41
|
+
<h1>{{ article.value?.title }}</h1>
|
|
42
|
+
<div v-for="comment in comments.value" :key="comment.id">
|
|
43
|
+
{{ comment.text }}
|
|
44
|
+
</div>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Step 2 – Load related objects with `.with()`
|
|
48
|
+
|
|
49
|
+
Chain `.with()` to attach related data to each item:
|
|
50
|
+
|
|
51
|
+
```javascript
|
|
52
|
+
const articlesPath = computed(() =>
|
|
53
|
+
path.blog.articlesByCreatedAt({ limit: 20 })
|
|
54
|
+
.with(article => path.userIdentification.identification({
|
|
55
|
+
sessionOrUserType: article.authorType,
|
|
56
|
+
sessionOrUser: article.author
|
|
57
|
+
}).bind('authorProfile'))
|
|
58
|
+
.with(article => path.blog.articleCategory({ category: article.category }).bind('categoryData'))
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
const [articles] = await Promise.all([live(articlesPath)])
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Access in template:
|
|
65
|
+
|
|
66
|
+
```vue
|
|
67
|
+
<div v-for="article in articles.value" :key="article.id">
|
|
68
|
+
<h3>{{ article.title }}</h3>
|
|
69
|
+
<span>by {{ article.authorProfile?.firstName }}</span>
|
|
70
|
+
<Tag :value="article.categoryData?.name" />
|
|
71
|
+
</div>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Nested `.with()` (with inside with)
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
const eventPath = computed(() =>
|
|
78
|
+
path.myService.event({ event: eventId })
|
|
79
|
+
.with(event => path.myService.eventState({ event: event.id }).bind('state')
|
|
80
|
+
.with(state => path.myService.roundPairs({
|
|
81
|
+
event: event.id,
|
|
82
|
+
round: state.round
|
|
83
|
+
}).bind('roundPairs'))
|
|
84
|
+
)
|
|
85
|
+
)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Step 3 – Conditional loading with `useClient`
|
|
89
|
+
|
|
90
|
+
Use `useClient()` to check authentication state and conditionally build paths:
|
|
91
|
+
|
|
92
|
+
```javascript
|
|
93
|
+
import { useClient } from '@live-change/vue3-ssr'
|
|
94
|
+
|
|
95
|
+
const client = useClient()
|
|
96
|
+
|
|
97
|
+
// Path that only loads for logged-in users (null path = no fetch)
|
|
98
|
+
const myDataPath = computed(() =>
|
|
99
|
+
client.value.user && path.blog.myArticles({})
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
// Path that only loads for admins
|
|
103
|
+
const adminPath = computed(() =>
|
|
104
|
+
client.value.roles.includes('admin') && path.blog.allArticles({})
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
const [myData, adminData] = await Promise.all([
|
|
108
|
+
live(myDataPath),
|
|
109
|
+
live(adminPath),
|
|
110
|
+
])
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
When the path is `null` / `false` / `undefined`, `live()` returns a ref with `null` value and does not subscribe.
|
|
114
|
+
|
|
115
|
+
### Conditional rendering in templates
|
|
116
|
+
|
|
117
|
+
```vue
|
|
118
|
+
<template>
|
|
119
|
+
<!-- Admin-only button -->
|
|
120
|
+
<Button v-if="client.roles.includes('admin')"
|
|
121
|
+
label="Create" icon="pi pi-plus" @click="create" />
|
|
122
|
+
|
|
123
|
+
<!-- Show different content based on auth -->
|
|
124
|
+
<div v-if="client.user">
|
|
125
|
+
<!-- Authenticated content -->
|
|
126
|
+
</div>
|
|
127
|
+
<div v-else>
|
|
128
|
+
<p>Please sign in to see your articles.</p>
|
|
129
|
+
<router-link :to="{ name: 'user:signIn' }">Sign in</router-link>
|
|
130
|
+
</div>
|
|
131
|
+
</template>
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Step 4 – Dependent paths
|
|
135
|
+
|
|
136
|
+
When one path depends on data from another, load them sequentially:
|
|
137
|
+
|
|
138
|
+
```javascript
|
|
139
|
+
// First load
|
|
140
|
+
const [article] = await Promise.all([live(articlePath)])
|
|
141
|
+
|
|
142
|
+
// Dependent path using data from first load
|
|
143
|
+
const authorPath = computed(() =>
|
|
144
|
+
article.value && path.userIdentification.identification({
|
|
145
|
+
sessionOrUserType: article.value.authorType,
|
|
146
|
+
sessionOrUser: article.value.author
|
|
147
|
+
})
|
|
148
|
+
)
|
|
149
|
+
const [author] = await Promise.all([live(authorPath)])
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Or use `.with()` to combine them in a single query (preferred when possible).
|
|
153
|
+
|
|
154
|
+
## Step 5 – Props-based paths in components
|
|
155
|
+
|
|
156
|
+
When building reusable components that receive IDs as props:
|
|
157
|
+
|
|
158
|
+
```vue
|
|
159
|
+
<script setup>
|
|
160
|
+
import { computed } from 'vue'
|
|
161
|
+
import { usePath, live } from '@live-change/vue3-ssr'
|
|
162
|
+
|
|
163
|
+
const props = defineProps({
|
|
164
|
+
articleId: { type: String, required: true }
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
const path = usePath()
|
|
168
|
+
|
|
169
|
+
const articlePath = computed(() => path.blog.article({ article: props.articleId }))
|
|
170
|
+
const [article] = await Promise.all([live(articlePath)])
|
|
171
|
+
</script>
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Summary
|
|
175
|
+
|
|
176
|
+
| Pattern | When to use |
|
|
177
|
+
|---|---|
|
|
178
|
+
| `computed(() => path.xxx(...))` | Path depends on reactive values |
|
|
179
|
+
| `.with(item => path.yyy(...).bind('field'))` | Attach related objects |
|
|
180
|
+
| `client.value.user && path.xxx(...)` | Load only when authenticated |
|
|
181
|
+
| `client.value.roles.includes('admin')` | Load/show only for specific roles |
|
|
182
|
+
| Sequential `live()` calls | Path depends on data from previous load |
|