vlite3 1.5.12 → 1.5.13
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 +20 -8
- package/components/Accordion/AccordionContent.vue.js +2 -2
- package/components/CommandPalette/CommandPaletteContent2.vue.js +1 -1
- package/components/CommandPalette/{CommandPaletteItem2.vue.js → CommandPaletteItem.vue.js} +1 -1
- package/components/Dropdown/DropdownMenu.vue.js +1 -1
- package/components/Form/AccordionView2.vue.js +1 -1
- package/components/Form/Form.vue.js +2 -2
- package/components/NavbarCommandPalette.vue.js +1 -1
- package/components/PanZoomViewport/PanZoomViewport.vue.d.ts +7 -7
- package/components/PanZoomViewport/PanZoomViewport.vue.js +1 -1
- package/components/Tabes/Tabes.vue.js +2 -2
- package/docs/README.md +17 -0
- package/docs/all-components.md +89 -0
- package/docs/component-index.md +313 -0
- package/docs/components/accordion.md +52 -0
- package/docs/components/alert.md +34 -0
- package/docs/components/app-shell.md +371 -0
- package/docs/components/async-select.md +264 -0
- package/docs/components/attachments-list.md +231 -0
- package/docs/components/avatar-group.md +74 -0
- package/docs/components/avatar-uploader.md +61 -0
- package/docs/components/avatar.md +28 -0
- package/docs/components/badge.md +81 -0
- package/docs/components/barcode.md +42 -0
- package/docs/components/beacon.md +29 -0
- package/docs/components/breadcrumb.md +317 -0
- package/docs/components/button-group.md +35 -0
- package/docs/components/button.md +86 -0
- package/docs/components/calendar.md +95 -0
- package/docs/components/carousel.md +122 -0
- package/docs/components/cart.md +533 -0
- package/docs/components/category-manager.md +269 -0
- package/docs/components/category-menu.md +251 -0
- package/docs/components/charts.md +1456 -0
- package/docs/components/chat.md +330 -0
- package/docs/components/checkbox.md +31 -0
- package/docs/components/chip.md +137 -0
- package/docs/components/choice-box.md +40 -0
- package/docs/components/clipboard.md +105 -0
- package/docs/components/clock.md +70 -0
- package/docs/components/color-picker.md +82 -0
- package/docs/components/command-palette.md +214 -0
- package/docs/components/comment-thread.md +171 -0
- package/docs/components/confirmation-modal.md +50 -0
- package/docs/components/custom-fields-display.md +94 -0
- package/docs/components/custom-fields.md +97 -0
- package/docs/components/data-list.md +93 -0
- package/docs/components/data-table.md +922 -0
- package/docs/components/date-picker.md +58 -0
- package/docs/components/date-range-picker.md +24 -0
- package/docs/components/date-time.md +104 -0
- package/docs/components/dropdown.md +740 -0
- package/docs/components/empty.md +100 -0
- package/docs/components/export-data.md +320 -0
- package/docs/components/file-picker.md +83 -0
- package/docs/components/file-preview.md +42 -0
- package/docs/components/file-tree.md +144 -0
- package/docs/components/footer.md +251 -0
- package/docs/components/forms.md +776 -0
- package/docs/components/gantt-chart.md +767 -0
- package/docs/components/google-login.md +67 -0
- package/docs/components/google-map.md +128 -0
- package/docs/components/heatmap.md +80 -0
- package/docs/components/icon-picker.md +58 -0
- package/docs/components/icon.md +176 -0
- package/docs/components/image-comparison.md +51 -0
- package/docs/components/image-magnifier.md +26 -0
- package/docs/components/import-data.md +521 -0
- package/docs/components/input.md +58 -0
- package/docs/components/invoice.md +339 -0
- package/docs/components/kanban.md +302 -0
- package/docs/components/label.md +25 -0
- package/docs/components/list.md +419 -0
- package/docs/components/masonry.md +55 -0
- package/docs/components/modal.md +133 -0
- package/docs/components/multi-select.md +54 -0
- package/docs/components/navbar.md +403 -0
- package/docs/components/number-input.md +41 -0
- package/docs/components/otp-input.md +68 -0
- package/docs/components/pagination.md +83 -0
- package/docs/components/pan-zoom-viewport.md +245 -0
- package/docs/components/permission-editor.md +322 -0
- package/docs/components/persona.md +56 -0
- package/docs/components/price.md +106 -0
- package/docs/components/pricing-plan.md +68 -0
- package/docs/components/progress-bar.md +53 -0
- package/docs/components/qr-code.md +59 -0
- package/docs/components/rating.md +59 -0
- package/docs/components/rich-text-editor.md +210 -0
- package/docs/components/scale-generator.md +101 -0
- package/docs/components/screen.md +208 -0
- package/docs/components/seo-provider.md +189 -0
- package/docs/components/side-panel.md +94 -0
- package/docs/components/sidebar-menu.md +422 -0
- package/docs/components/skeleton.md +115 -0
- package/docs/components/slider.md +48 -0
- package/docs/components/spinner.md +27 -0
- package/docs/components/splitter.md +97 -0
- package/docs/components/stats.md +234 -0
- package/docs/components/status-chip.md +232 -0
- package/docs/components/switch.md +23 -0
- package/docs/components/tabs.md +335 -0
- package/docs/components/tag-input.md +55 -0
- package/docs/components/textarea.md +31 -0
- package/docs/components/theme-provider.md +130 -0
- package/docs/components/theme-toggle.md +36 -0
- package/docs/components/thumbnail-selector.md +186 -0
- package/docs/components/timeline.md +225 -0
- package/docs/components/toast-notification.md +89 -0
- package/docs/components/tooltip.md +31 -0
- package/docs/components/workbook.md +102 -0
- package/docs/composables/use-theme.md +59 -0
- package/docs/getting-started/setup.md +176 -0
- package/docs/guides/draggable.md +211 -0
- package/docs/guides/internationalization.md +281 -0
- package/docs/guides/performance.md +118 -0
- package/docs/guides/testing-forms.md +154 -0
- package/docs/guides/testing-overlays.md +131 -0
- package/docs/guides/theming.md +124 -0
- package/docs/utilities/search.md +580 -0
- package/docs/utilities/utilities.md +371 -0
- package/docs-manifest.json +339 -0
- package/package.json +5 -13
- package/scripts/generate-docs-manifest.js +207 -0
- package/scripts/sync-docs.js +754 -0
- package/style.css +1 -1
- /package/components/Dropdown/{DropdownMenu2.vue.js → DropdownMenu3.vue.js} +0 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
# 🌍 Translation (i18n) Support
|
|
2
|
+
|
|
3
|
+
**vlite3** provides a lightweight, library-agnostic translation system. Instead of forcing you to use a specific i18n package (like `vue-i18n`), vlite3 allows you to register a global translation handler. If registered, components will automatically resolve translation keys; if not, they gracefully fall back to the default text properties.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. Setup & Configuration
|
|
8
|
+
|
|
9
|
+
To enable translations, you need to provide a translation handler function `t` to the `createVLite` plugin in your `main.ts` (or `main.js`) file.
|
|
10
|
+
|
|
11
|
+
### Example 1: Using `vue-i18n`
|
|
12
|
+
|
|
13
|
+
If you are using the official `vue-i18n` library, you can pass its global `t` function directly to vlite3.
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
// main.ts
|
|
17
|
+
import { createApp } from 'vue'
|
|
18
|
+
import { createI18n } from 'vue-i18n'
|
|
19
|
+
import { createVLite } from 'vlite3'
|
|
20
|
+
import App from './App.vue'
|
|
21
|
+
|
|
22
|
+
const app = createApp(App)
|
|
23
|
+
|
|
24
|
+
// 1. Setup your i18n instance
|
|
25
|
+
const i18n = createI18n({
|
|
26
|
+
legacy: false,
|
|
27
|
+
locale: 'en',
|
|
28
|
+
messages: {
|
|
29
|
+
en: {
|
|
30
|
+
common: {
|
|
31
|
+
save: 'Save Changes',
|
|
32
|
+
cancel: 'Cancel',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
// 2. Pass the translation function to vLite
|
|
39
|
+
const vlite = createVLite({
|
|
40
|
+
services: {
|
|
41
|
+
t: (key: string, ...args: any[]) => {
|
|
42
|
+
// Use vue-i18n's global translation method
|
|
43
|
+
return i18n.global.t(key, ...args)
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
app.use(i18n)
|
|
49
|
+
app.use(vlite)
|
|
50
|
+
app.mount('#app')
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Example 2: Using a Custom Dictionary
|
|
54
|
+
|
|
55
|
+
If you have a custom translation system or a simple dictionary object, you can wrap it in the handler.
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
// main.ts
|
|
59
|
+
import { createApp } from 'vue'
|
|
60
|
+
import { createVLite } from 'vlite3'
|
|
61
|
+
import App from './App.vue'
|
|
62
|
+
|
|
63
|
+
const myTranslations: Record<string, string> = {
|
|
64
|
+
'auth.login': 'Sign In',
|
|
65
|
+
'auth.password': 'Enter your password',
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const vlite = createVLite({
|
|
69
|
+
services: {
|
|
70
|
+
t: (key: string) => myTranslations[key] || key, // Fallback to key if missing
|
|
71
|
+
},
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
const app = createApp(App)
|
|
75
|
+
app.use(vlite)
|
|
76
|
+
app.mount('#app')
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## 2. Global Internal Component Translations
|
|
82
|
+
|
|
83
|
+
For structural texts hardcoded inside components (like empty states, search placeholders, or pagination labels), vlite3 requests specific keys under the `vlite.` namespace. Add these keys to your dictionary/locale files to automatically translate the internal UI text.
|
|
84
|
+
|
|
85
|
+
| Key | Default Fallback | Component |
|
|
86
|
+
| ------------------------------------- | ----------------------------------------------------- | ------------------- |
|
|
87
|
+
| **Forms & Selectors** | | |
|
|
88
|
+
| `vlite.customFields.emptyTitle` | "No items added" | `CustomFields` |
|
|
89
|
+
| `vlite.customFields.emptyDescription` | "Add a new item to get started" | `CustomFields` |
|
|
90
|
+
| `vlite.dropdown.empty` | "No options found" | `Dropdown` |
|
|
91
|
+
| `vlite.dropdown.search` | "Search..." | `Dropdown` |
|
|
92
|
+
| `vlite.filePicker.clickToUpload` | "Click to upload" | `FilePicker` |
|
|
93
|
+
| `vlite.filePicker.dragAndDrop` | "or drag and drop" | `FilePicker` |
|
|
94
|
+
| `vlite.filePicker.addMore` | "Add more" | `FilePicker` |
|
|
95
|
+
| `vlite.multiSelect.placeholder` | "Select items..." | `MultiSelect` |
|
|
96
|
+
| `vlite.datePicker.placeholder` | "Select date" | `DatePicker` |
|
|
97
|
+
| `vlite.iconPicker.search` | "Search 1000+ icons..." | `IconPicker` |
|
|
98
|
+
| **Data Display & Tables** | | |
|
|
99
|
+
| `vlite.empty.title` | "No data found" | `Empty`, `DataList` |
|
|
100
|
+
| `vlite.empty.description` | "There is nothing to display here right now." | `Empty`, `DataList` |
|
|
101
|
+
| `vlite.dataTable.searchPlaceholder` | "Search..." | `DataTable` |
|
|
102
|
+
| `vlite.dataTable.confirmDeleteTitle` | "Confirm Deletion" | `DataTable` |
|
|
103
|
+
| `vlite.dataTable.confirmDeleteDesc` | "Are you sure you want to delete the selected items?" | `DataTable` |
|
|
104
|
+
| `vlite.dataTable.deleteBtn` | "Delete" | `DataTable` |
|
|
105
|
+
| `vlite.dataTable.cancelBtn` | "Cancel" | `DataTable` |
|
|
106
|
+
| **Screens & Layouts** | | |
|
|
107
|
+
| `vlite.screen.deleteSelected` | "Delete Selected" | `Screen` |
|
|
108
|
+
| `vlite.screen.listView` | "List View" | `Screen` |
|
|
109
|
+
| `vlite.screen.tableView` | "Table View" | `Screen` |
|
|
110
|
+
| `vlite.screen.refresh` | "Refresh" | `Screen` |
|
|
111
|
+
| `vlite.screen.searchPlaceholder` | "Search..." | `Screen` |
|
|
112
|
+
| `vlite.screen.confirmDeleteTitle` | "Confirm Deletion" | `Screen` |
|
|
113
|
+
| `vlite.screen.confirmDeleteDesc` | "Are you sure you want to delete this item?" | `Screen` |
|
|
114
|
+
| `vlite.screen.confirmDeleteBtn` | "Delete" | `Screen` |
|
|
115
|
+
| `vlite.screen.cancelBtn` | "Cancel" | `Screen` |
|
|
116
|
+
| `vlite.screen.missingView` | "Please provide a `:list` or `:table` component." | `Screen` |
|
|
117
|
+
| `vlite.screen.addNew` | "Add New" | `Screen` |
|
|
118
|
+
| `vlite.screen.filters` | "Filters" | `Screen` |
|
|
119
|
+
| `vlite.screen.applyFilters` | "Apply Filters" | `Screen` |
|
|
120
|
+
| `vlite.screen.filter` | "Filter" | `Screen` |
|
|
121
|
+
| **Pagination** | | |
|
|
122
|
+
| `vlite.pagination.show` | "Show" | `Pagination` |
|
|
123
|
+
| `vlite.pagination.perPage` | "per page" | `Pagination` |
|
|
124
|
+
| `vlite.pagination.page` | "Page" | `Pagination` |
|
|
125
|
+
| `vlite.pagination.of` | "of" | `Pagination` |
|
|
126
|
+
| `vlite.pagination.previous` | "Previous" | `Pagination` |
|
|
127
|
+
| `vlite.pagination.next` | "Next" | `Pagination` |
|
|
128
|
+
| **Advanced Components** | | |
|
|
129
|
+
| `vlite.fileTree.emptyText` | "No results found." | `FileTree` |
|
|
130
|
+
| `vlite.pricingPlan.selected` | "Selected" | `PricingPlan` |
|
|
131
|
+
| `vlite.pricingPlan.choosePlan` | "Choose Plan" | `PricingPlan` |
|
|
132
|
+
| `vlite.pricingPlan.recommended` | "Recommended" | `PricingPlan` |
|
|
133
|
+
| `vlite.pricingPlan.mostPopular` | "Most Popular" | `PricingPlan` |
|
|
134
|
+
| `vlite.workbook.rename` | "Rename" | `Workbook` |
|
|
135
|
+
| `vlite.workbook.duplicate` | "Duplicate" | `Workbook` |
|
|
136
|
+
| `vlite.workbook.delete` | "Delete" | `Workbook` |
|
|
137
|
+
| `vlite.workbook.addSheet` | "Add New Sheet" | `Workbook` |
|
|
138
|
+
| **Modals & Utilities** | | |
|
|
139
|
+
| `vlite.confirmation.confirm` | "Confirm" | `ConfirmationModal` |
|
|
140
|
+
| `vlite.confirmation.cancel` | "Cancel" | `ConfirmationModal` |
|
|
141
|
+
| `vlite.googleLogin.buttonText` | "Sign in with Google" | `GoogleLogin` |
|
|
142
|
+
| `vlite.themeToggle.switchToDark` | "Switch to dark mode" | `ThemeToggle` |
|
|
143
|
+
| `vlite.themeToggle.switchToLight` | "Switch to light mode" | `ThemeToggle` |
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## 3. Using Translations in Components
|
|
148
|
+
|
|
149
|
+
Almost every component in vlite3 supports `*I18n` props. If the i18n key is resolved successfully, it will be displayed. If no translation is found or the system is unconfigured, it will fall back to the standard standard props (`text`, `title`, `label`, `description`, etc.).
|
|
150
|
+
|
|
151
|
+
### Common i18n Props
|
|
152
|
+
|
|
153
|
+
- `textI18n` (Button, Chip)
|
|
154
|
+
- `labelI18n` (Input, Checkbox, Switch, Textarea, Slider, etc.)
|
|
155
|
+
- `placeholderI18n` (Input, Textarea, Select, DatePicker, etc.)
|
|
156
|
+
- `titleI18n` & `descriptionI18n` (Modal, SidePanel, Alert, Empty, Screen, Accordion, ChoiceBox, etc.)
|
|
157
|
+
- `contentI18n` (Tooltip)
|
|
158
|
+
- `confirmTextI18n` & `cancelTextI18n` (ConfirmationModal)
|
|
159
|
+
|
|
160
|
+
### Button & Chip Example
|
|
161
|
+
|
|
162
|
+
```vue
|
|
163
|
+
<template>
|
|
164
|
+
<Button textI18n="common.save" text="Save" icon="lucide:check" />
|
|
165
|
+
<Chip textI18n="status.active" text="Active" variant="success" />
|
|
166
|
+
</template>
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Input & Form Controls
|
|
170
|
+
|
|
171
|
+
```vue
|
|
172
|
+
<template>
|
|
173
|
+
<Input
|
|
174
|
+
v-model="email"
|
|
175
|
+
labelI18n="form.email.label"
|
|
176
|
+
label="Email Address"
|
|
177
|
+
placeholderI18n="form.email.placeholder"
|
|
178
|
+
placeholder="Enter your email" />
|
|
179
|
+
</template>
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Schema Arrays (Dropdown, ChoiceBox, Accordion)
|
|
183
|
+
|
|
184
|
+
Options and Schema arrays fully support i18n keys for their respective text fields.
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
const options = [
|
|
188
|
+
{
|
|
189
|
+
label: 'General Settings',
|
|
190
|
+
labelI18n: 'settings.general.title',
|
|
191
|
+
description: 'Manage preferences',
|
|
192
|
+
descriptionI18n: 'settings.general.desc',
|
|
193
|
+
value: 'general',
|
|
194
|
+
},
|
|
195
|
+
]
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Modals & Alerts
|
|
199
|
+
|
|
200
|
+
```vue
|
|
201
|
+
<template>
|
|
202
|
+
<Alert
|
|
203
|
+
titleI18n="alert.success.title"
|
|
204
|
+
title="Operation Successful"
|
|
205
|
+
descriptionI18n="alert.success.desc"
|
|
206
|
+
description="Your changes have been saved."
|
|
207
|
+
variant="success" />
|
|
208
|
+
</template>
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## 4. Using Translations in Form Schemas
|
|
214
|
+
|
|
215
|
+
When using the schema-driven `<Form />` component, you can define translation keys directly inside your field definitions. The `FormFields` component will dynamically resolve these keys using the global `t` handler. Error messages will also automatically use the translated label.
|
|
216
|
+
|
|
217
|
+
```vue
|
|
218
|
+
<script setup lang="ts">
|
|
219
|
+
import { Form, type IForm } from 'vlite3'
|
|
220
|
+
|
|
221
|
+
const branchSchema: IForm[] = [
|
|
222
|
+
{
|
|
223
|
+
name: 'name',
|
|
224
|
+
type: 'text',
|
|
225
|
+
required: true,
|
|
226
|
+
// Fallback standard props
|
|
227
|
+
label: 'Branch Name',
|
|
228
|
+
placeholder: 'Enter branch name',
|
|
229
|
+
// i18n keys
|
|
230
|
+
labelI18n: 'common.words.name',
|
|
231
|
+
placeholderI18n: 'hrm.branch.form.namePlaceholder',
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
name: 'manager',
|
|
235
|
+
type: 'select',
|
|
236
|
+
options: [{ label: 'Option 1', labelI18n: 'options.one', value: '1' }],
|
|
237
|
+
// Fallback standard props
|
|
238
|
+
label: 'Manager',
|
|
239
|
+
placeholder: 'Add Manager',
|
|
240
|
+
// i18n keys
|
|
241
|
+
labelI18n: 'hrm.branch.form.managerLabel',
|
|
242
|
+
placeholderI18n: 'hrm.branch.form.managerPlaceholder',
|
|
243
|
+
},
|
|
244
|
+
]
|
|
245
|
+
</script>
|
|
246
|
+
|
|
247
|
+
<template>
|
|
248
|
+
<Form :schema="branchSchema" @onSubmit="handleSave" />
|
|
249
|
+
</template>
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
**Supported schema properties:**
|
|
253
|
+
|
|
254
|
+
- `labelI18n`: Translates the field label (including CustomFields array headers).
|
|
255
|
+
- `placeholderI18n`: Translates the input placeholder.
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## 5. `$t` Utility Function (Advanced)
|
|
260
|
+
|
|
261
|
+
If you are building your own custom components, static validation schemas, or Pinia/Vuex actions and need access to the translation handler registered in `vlite3`, you can import and use the global `$t` function directly. It works safely inside or outside of a Vue component's setup context.
|
|
262
|
+
|
|
263
|
+
```vue
|
|
264
|
+
<script setup lang="ts">
|
|
265
|
+
import { $t } from 'vlite3'
|
|
266
|
+
|
|
267
|
+
const welcomeMessage = $t('dashboard.welcome', { user: 'John' })
|
|
268
|
+
</script>
|
|
269
|
+
|
|
270
|
+
<template>
|
|
271
|
+
<div>
|
|
272
|
+
<h1>{{ welcomeMessage }}</h1>
|
|
273
|
+
</div>
|
|
274
|
+
</template>
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Note on Performance
|
|
278
|
+
|
|
279
|
+
This setup is entirely optional. If a developer installs `vlite3` but does not register a `t` function via `createVLite()`, the components and the `$t` utility will simply bypass the translation step and render the standard fallback props (`label`, `text`, `placeholder`, `title`, etc.) without any performance penalty.
|
|
280
|
+
|
|
281
|
+
EOF
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Vue 3 Performance Directives
|
|
2
|
+
|
|
3
|
+
When writing, refactoring, or reviewing Vue 3 code in this project, you MUST strictly adhere to the following performance optimization rules. Do not generate code that violates these directives unless explicitly overridden by the user.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🛑 STRICT BANS & FORBIDDEN PATTERNS
|
|
8
|
+
|
|
9
|
+
### 1. The Deep Proxy Trap
|
|
10
|
+
|
|
11
|
+
**NEVER** store Vue component definitions, large static config objects, or 3rd-party class instances (Chart.js, Maps, DOM refs) inside a plain `ref()` or `reactive()`.
|
|
12
|
+
|
|
13
|
+
- **Why:** Vue's deep proxy traversal will recursively walk the entire object tree, spiking CPU and memory on every render cycle.
|
|
14
|
+
- **REQUIRED FIX:** Always wrap them in `markRaw()`.
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
import { markRaw, ref } from 'vue'
|
|
18
|
+
|
|
19
|
+
// FORBIDDEN
|
|
20
|
+
const activeComponent = ref(MyComponent)
|
|
21
|
+
const chart = ref(new Chart(...))
|
|
22
|
+
|
|
23
|
+
// MANDATORY
|
|
24
|
+
const activeComponent = ref(markRaw(MyComponent))
|
|
25
|
+
const chart = ref(markRaw(new Chart(...)))
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## ⚡ MANDATORY OPTIMIZATION PATTERNS
|
|
32
|
+
|
|
33
|
+
### 1. GPU Layer Promotion for Heavy Containers
|
|
34
|
+
|
|
35
|
+
When generating scrollable containers, modal bodies, or side panels, you MUST promote them to their own compositor layer to isolate hover/focus repaints from the rest of the DOM.
|
|
36
|
+
|
|
37
|
+
- **MANDATORY CSS:**
|
|
38
|
+
|
|
39
|
+
```css
|
|
40
|
+
.scrollable-container,
|
|
41
|
+
.modal-body {
|
|
42
|
+
will-change: transform;
|
|
43
|
+
contain: layout style;
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 2. V-DOM Diff Bounding with `v-memo`
|
|
48
|
+
|
|
49
|
+
When generating a `<template v-for>` loop that renders lists of forms, tables, or complex components, you MUST apply `v-memo` to skip diffing unchanged rows.
|
|
50
|
+
|
|
51
|
+
- **Rules:** The memo array must contain the specific item and any external state (e.g., selection state) that affects the row.
|
|
52
|
+
|
|
53
|
+
```vue
|
|
54
|
+
<tr
|
|
55
|
+
v-for="row in rows"
|
|
56
|
+
:key="row.id"
|
|
57
|
+
v-memo="[row, selectedIds.has(row.id), isHovered === row.id]">...</tr>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 3. Shallow Reactivity for Large Datasets
|
|
61
|
+
|
|
62
|
+
If generating code that fetches or stores large arrays of objects (e.g., data tables) where individual properties are not mutated reactively (only the whole array is replaced), you MUST use `shallowRef()`.
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import { shallowRef } from 'vue'
|
|
66
|
+
|
|
67
|
+
// MANDATORY FOR LARGE DATA SETS
|
|
68
|
+
const tableData = shallowRef([])
|
|
69
|
+
tableData.value = await fetchHugeList()
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 4. Static Subtree Hoisting
|
|
73
|
+
|
|
74
|
+
When generating large SVGs, complex static footers, or massive text blocks that do not depend on reactive state, apply `v-once`.
|
|
75
|
+
|
|
76
|
+
```vue
|
|
77
|
+
<div v-once class="heavy-static-wrapper">
|
|
78
|
+
<svg>...</svg>
|
|
79
|
+
</div>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### 5. Memory Leak Prevention
|
|
83
|
+
|
|
84
|
+
If your generated code instantiates an event listener (`window.addEventListener`), an interval (`setInterval`), an observer (`IntersectionObserver`), or a 3rd-party library instance, you MUST generate the corresponding cleanup code in `onUnmounted`.
|
|
85
|
+
|
|
86
|
+
### 7. The `backdrop-filter` Ban
|
|
87
|
+
|
|
88
|
+
**NEVER** generate CSS containing `backdrop-filter: blur()` for Modals, Drawers, Popovers, Dropdowns, or any overlay with nested interactive elements.
|
|
89
|
+
|
|
90
|
+
- **Why:** It forces the browser GPU to re-composite the entire viewport on every frame (including child hover/focus states), causing severe input lag.
|
|
91
|
+
- **REQUIRED FIX:** Always use plain semi-transparent backgrounds.
|
|
92
|
+
|
|
93
|
+
```css
|
|
94
|
+
/* FORBIDDEN */
|
|
95
|
+
.modal-overlay {
|
|
96
|
+
backdrop-filter: blur(4px);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/* MANDATORY REPLACEMENT */
|
|
100
|
+
.modal-overlay {
|
|
101
|
+
background-color: rgba(0, 0, 0, 0.4);
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## 🤖 AGENT COMPLIANCE CHECKLIST
|
|
108
|
+
|
|
109
|
+
Before outputting code, silently run this check:
|
|
110
|
+
|
|
111
|
+
1. Did I accidentally use `backdrop-filter: blur()`? (If yes, rewrite to `rgba()`).
|
|
112
|
+
2. Am I passing a Component instance to a reactive state? (If yes, add `markRaw()`).
|
|
113
|
+
3. Is this a `v-for` loop with complex children? (If yes, add `v-memo`).
|
|
114
|
+
4. Is this a modal/scrollable container? (If yes, add `will-change: transform; contain: layout style;`).
|
|
115
|
+
5. Am I fetching or storing a massive dataset that only gets replaced, not deeply mutated? (If yes, use `shallowRef()` instead of `ref()`).
|
|
116
|
+
6. Am I rendering a heavy, non-reactive block of HTML or a large SVG? (If yes, add `v-once`).
|
|
117
|
+
7. Did I initialize a listener, observer, or 3rd-party instance? (If yes, generate the `onUnmounted` cleanup).
|
|
118
|
+
8. Transition, Teleport, Suspense, KeepAlive, v-memo, custom directives
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# Testing Forms & Components
|
|
2
|
+
|
|
3
|
+
**VLite3** provides a robust, zero-configuration testing ecosystem for form components. Whether you are writing End-to-End (E2E) tests with **Playwright** / **Cypress** or Component tests with **Vitest** / **Vue Test Utils**, our form elements are designed to be immediately queryable.
|
|
4
|
+
|
|
5
|
+
## The `data-testid` System
|
|
6
|
+
|
|
7
|
+
You do **not** need to manually add `data-testid` attributes to your form schemas. The VLite3 library automatically generates and injects these attributes based on your schema's existing `name`, `label`, or `id` properties.
|
|
8
|
+
|
|
9
|
+
This ensures that your components remain completely accessible for testing without polluting your production schemas or requiring any migrations for existing codebases.
|
|
10
|
+
|
|
11
|
+
### Standardized Selectors
|
|
12
|
+
|
|
13
|
+
Here is how the automatic `data-testid` mapping resolves across different component types:
|
|
14
|
+
|
|
15
|
+
| Component | Test ID Format | Fallback Resolution Order | Example Output |
|
|
16
|
+
| :------------------- | :-------------------- | :-------------------------------------- | :-------------------------------------- |
|
|
17
|
+
| **Input** | `input-{name}` | `name` → `label` (kebab-case) → `input` | `[data-testid="input-email"]` |
|
|
18
|
+
| **Textarea** | `textarea-{name}` | `name` → `textarea` | `[data-testid="textarea-description"]` |
|
|
19
|
+
| **Button** | `btn-{text}` | `text` (kebab-case) → `icon` → `button` | `[data-testid="btn-sign-in"]` |
|
|
20
|
+
| **Switch** | `switch-{name}` | `name` → `id` → `label` → `switch` | `[data-testid="switch-rememberMe"]` |
|
|
21
|
+
| **Checkbox** | `checkbox-{name}` | `name` → `id` → `label` → `checkbox` | `[data-testid="checkbox-terms"]` |
|
|
22
|
+
| **NumberInput** | `number-{name}` | `name` → `id` → `number-input` | `[data-testid="number-age"]` |
|
|
23
|
+
| **Number (Inc/Dec)** | `number-{name}-inc` | Appends `-inc` or `-dec` to base ID | `[data-testid="number-age-inc"]` |
|
|
24
|
+
| **DatePicker** | `datepicker-{name}` | `name` → `datepicker` | `[data-testid="datepicker-birthDate"]` |
|
|
25
|
+
| **DateRange** | `daterange-{name}` | `name` → `daterange` | `[data-testid="daterange-period"]` |
|
|
26
|
+
| **MultiSelect** | `multiselect-{name}` | `name` → `multiselect` | `[data-testid="multiselect-roles"]` |
|
|
27
|
+
| **FilePicker** | `filepicker-{name}` | `name` → `filepicker` | `[data-testid="filepicker-resume"]` |
|
|
28
|
+
| **AvatarUploader** | `avatar-{name}` | `name` → `avatar-uploader` | `[data-testid="avatar-profilePicture"]` |
|
|
29
|
+
| **ThumbnailSelector**| `thumbnail-{name}` | `name` → `thumbnail-selector` | `[data-testid="thumbnail-media"]` |
|
|
30
|
+
| **Dropdown Item** | `dropdown-item-{val}` | `value` → `label` (kebab-case) | `[data-testid="dropdown-item-admin"]` |
|
|
31
|
+
|
|
32
|
+
> **Note:** If you explicitly pass a `data-testid` via a component's `props` in the schema, it will immediately override the automatically generated ID.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Playwright Integration (E2E)
|
|
37
|
+
|
|
38
|
+
Playwright has native support for `data-testid` via the `page.getByTestId()` locator. Here is an example of testing a standard authentication form built with VLite3.
|
|
39
|
+
|
|
40
|
+
### Example Form Schema
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
const loginSchema = [
|
|
44
|
+
{ name: 'email', label: 'Email Address', type: 'email' },
|
|
45
|
+
{ name: 'password', label: 'Password', type: 'password' },
|
|
46
|
+
{ name: 'rememberMe', label: 'Remember Me', type: 'switch' },
|
|
47
|
+
]
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Playwright Test (`login.spec.ts`)
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { test, expect } from '@playwright/test'
|
|
54
|
+
|
|
55
|
+
test('User can fill and submit the login form', async ({ page }) => {
|
|
56
|
+
await page.goto('/login')
|
|
57
|
+
|
|
58
|
+
// 1. Target inputs via auto-generated test IDs
|
|
59
|
+
const emailInput = page.getByTestId('input-email')
|
|
60
|
+
const passwordInput = page.getByTestId('input-password')
|
|
61
|
+
|
|
62
|
+
// 2. Fill standard text fields
|
|
63
|
+
await emailInput.fill('john@example.com')
|
|
64
|
+
await passwordInput.fill('123456')
|
|
65
|
+
|
|
66
|
+
// 3. Interact with boolean switches
|
|
67
|
+
const rememberSwitch = page.getByTestId('switch-rememberMe')
|
|
68
|
+
await rememberSwitch.click()
|
|
69
|
+
|
|
70
|
+
// 4. Assert field states before submission
|
|
71
|
+
await expect(emailInput).toHaveValue('john@example.com')
|
|
72
|
+
await expect(rememberSwitch).toHaveAttribute('aria-checked', 'true')
|
|
73
|
+
|
|
74
|
+
// 5. Target auto-generated button IDs and submit
|
|
75
|
+
const submitButton = page.getByTestId('btn-sign-in')
|
|
76
|
+
await submitButton.click()
|
|
77
|
+
|
|
78
|
+
// 6. Assert successful navigation or toast
|
|
79
|
+
await expect(page).toHaveURL('/dashboard')
|
|
80
|
+
})
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Testing Complex Components (Dropdowns & Selects)
|
|
84
|
+
|
|
85
|
+
VLite3 Dropdowns use Portals (`Teleport`), which means their menu items might be appended to the end of the `<body>`. Using `data-testid` bypasses complex DOM traversing.
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
test('User can select a role from a dropdown', async ({ page }) => {
|
|
89
|
+
// Click the multi-select trigger
|
|
90
|
+
await page.getByTestId('multiselect-role').click()
|
|
91
|
+
|
|
92
|
+
// Wait for the dropdown menu to animate in, then click the exact item
|
|
93
|
+
const adminOption = page.getByTestId('dropdown-item-admin')
|
|
94
|
+
await expect(adminOption).toBeVisible()
|
|
95
|
+
await adminOption.click()
|
|
96
|
+
|
|
97
|
+
// Close the dropdown (pressing Escape is usually safest for accessibility-compliant components)
|
|
98
|
+
await page.keyboard.press('Escape')
|
|
99
|
+
})
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Vitest & Vue Test Utils (Component Testing)
|
|
105
|
+
|
|
106
|
+
When writing localized component tests, the consistent `data-testid` attributes make finding and interacting with deeply nested form elements reliable.
|
|
107
|
+
|
|
108
|
+
### Vitest Test (`LoginForm.spec.ts`)
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
import { mount } from '@vue/test-utils'
|
|
112
|
+
import { describe, it, expect } from 'vitest'
|
|
113
|
+
import LoginForm from './LoginForm.vue'
|
|
114
|
+
|
|
115
|
+
describe('LoginForm.vue', () => {
|
|
116
|
+
it('emits the correct payload on form submission', async () => {
|
|
117
|
+
const wrapper = mount(LoginForm)
|
|
118
|
+
|
|
119
|
+
// 1. Find elements cleanly
|
|
120
|
+
const emailInput = wrapper.find('[data-testid="input-email"]')
|
|
121
|
+
const passwordInput = wrapper.find('[data-testid="input-password"]')
|
|
122
|
+
const submitBtn = wrapper.find('[data-testid="btn-sign-in"]')
|
|
123
|
+
|
|
124
|
+
// 2. Set values
|
|
125
|
+
await emailInput.setValue('test@vlite.com')
|
|
126
|
+
await passwordInput.setValue('secure-pass')
|
|
127
|
+
|
|
128
|
+
// 3. Submit
|
|
129
|
+
await submitBtn.trigger('click')
|
|
130
|
+
|
|
131
|
+
// 4. Validate emitted Form component event
|
|
132
|
+
const emitted = wrapper.findComponent({ name: 'Form' }).emitted('onSubmit')
|
|
133
|
+
expect(emitted).toBeTruthy()
|
|
134
|
+
|
|
135
|
+
const payload = emitted[0][0] // Extract first emission's payload
|
|
136
|
+
expect(payload.values).toEqual({
|
|
137
|
+
email: 'test@vlite.com',
|
|
138
|
+
password: 'secure-pass',
|
|
139
|
+
})
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
it('increments number fields correctly', async () => {
|
|
143
|
+
const wrapper = mount(LoginForm)
|
|
144
|
+
|
|
145
|
+
const incButton = wrapper.find('[data-testid="number-age-inc"]')
|
|
146
|
+
const numberInput = wrapper.find('[data-testid="number-age"]')
|
|
147
|
+
|
|
148
|
+
await incButton.trigger('keydown.up') // Or trigger pointerdown
|
|
149
|
+
|
|
150
|
+
// Check internal state / DOM update
|
|
151
|
+
expect((numberInput.element as HTMLInputElement).value).toBe('1')
|
|
152
|
+
})
|
|
153
|
+
})
|
|
154
|
+
```
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Testing Overlays (Modals & SidePanels)
|
|
2
|
+
|
|
3
|
+
Testing components that rely on `<Teleport>` to render outside the standard DOM hierarchy (like `Modal`, `SidePanel`, and `ConfirmationModal`) requires a slight shift in strategy compared to standard inline components.
|
|
4
|
+
|
|
5
|
+
VLite3 simplifies this by automatically generating semantic `data-testid` attributes on both the **Trigger** and the **Teleported Body**.
|
|
6
|
+
|
|
7
|
+
## The `data-testid` System
|
|
8
|
+
|
|
9
|
+
You do not need to manually add test attributes to overlays. They are derived directly from the `title` of the overlay component to ensure immediate predictability.
|
|
10
|
+
|
|
11
|
+
| Component | Teleported Body ID | Trigger ID | Close Button ID |
|
|
12
|
+
| :--- | :--- | :--- | :--- |
|
|
13
|
+
| **Modal** | `modal-{title}` | `modal-trigger-{title}` | `modal-close-btn` |
|
|
14
|
+
| **SidePanel** | `sidepanel-{title}` | `sidepanel-trigger-{title}` | `sidepanel-close-btn` |
|
|
15
|
+
| **ConfirmationModal** | `confirm-modal-{title}`| `modal-trigger-{title}` | `confirm-modal-cancel` / `confirm-modal-confirm` |
|
|
16
|
+
|
|
17
|
+
> **Example:** A `<Modal title="Edit User">` will have its trigger wrapped with `data-testid="modal-trigger-edit-user"` and the teleported dialog body will have `data-testid="modal-edit-user"`.
|
|
18
|
+
|
|
19
|
+
If you explicitly pass `data-testid="my-custom-modal"` to the component, the trigger will receive `my-custom-modal-trigger` and the body will receive `my-custom-modal`.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Playwright Integration (E2E)
|
|
24
|
+
|
|
25
|
+
Playwright searches the real DOM effortlessly, meaning you can locate Teleported elements exactly as you would locate standard inline elements.
|
|
26
|
+
|
|
27
|
+
### Example: Testing a Modal Workflow
|
|
28
|
+
```typescript
|
|
29
|
+
import { test, expect } from '@playwright/test';
|
|
30
|
+
|
|
31
|
+
test('User can open and submit the Edit Profile modal', async ({ page }) => {
|
|
32
|
+
await page.goto('/settings');
|
|
33
|
+
|
|
34
|
+
// 1. Click the trigger using its auto-generated ID
|
|
35
|
+
await page.getByTestId('modal-trigger-edit-profile').click();
|
|
36
|
+
|
|
37
|
+
// 2. Wait for the teleported modal body to animate in and become visible
|
|
38
|
+
const modal = page.getByTestId('modal-edit-profile');
|
|
39
|
+
await expect(modal).toBeVisible();
|
|
40
|
+
|
|
41
|
+
// 3. Interact with the form *inside* the modal
|
|
42
|
+
const usernameInput = modal.getByTestId('input-username');
|
|
43
|
+
await usernameInput.fill('new_username');
|
|
44
|
+
|
|
45
|
+
// 4. Submit and verify closure
|
|
46
|
+
await modal.getByTestId('btn-save').click();
|
|
47
|
+
await expect(modal).toBeHidden();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('User can dismiss a Confirmation Modal', async ({ page }) => {
|
|
51
|
+
await page.getByTestId('modal-trigger-delete-account').click();
|
|
52
|
+
|
|
53
|
+
const confirmModal = page.getByTestId('confirm-modal-delete-account');
|
|
54
|
+
await expect(confirmModal).toBeVisible();
|
|
55
|
+
|
|
56
|
+
// Click the specific cancel button inside the confirmation wrapper
|
|
57
|
+
await confirmModal.getByTestId('confirm-modal-cancel').click();
|
|
58
|
+
await expect(confirmModal).toBeHidden();
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Vitest & Vue Test Utils (Component Testing)
|
|
65
|
+
|
|
66
|
+
When writing localized component tests with `@vue/test-utils`, `<Teleport>` targets like `body` are outside the scope of your `wrapper`. By default, `wrapper.find()` will **not** find teleported content.
|
|
67
|
+
|
|
68
|
+
You have two solutions:
|
|
69
|
+
|
|
70
|
+
### Strategy 1: Global Stubs (Recommended)
|
|
71
|
+
You can configure Vitest to stub the `<Teleport>` component so that it renders its contents **inline** (where the component was declared), rather than moving it to the `<body>`. This makes standard `wrapper.find()` queries work perfectly.
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { mount } from '@vue/test-utils';
|
|
75
|
+
import { describe, it, expect } from 'vitest';
|
|
76
|
+
import UserProfile from './UserProfile.vue';
|
|
77
|
+
|
|
78
|
+
describe('UserProfile.vue', () => {
|
|
79
|
+
it('opens the sidepanel when clicking the edit button', async () => {
|
|
80
|
+
const wrapper = mount(UserProfile, {
|
|
81
|
+
global: {
|
|
82
|
+
stubs: {
|
|
83
|
+
// Renders the sidepanel inline for easy querying
|
|
84
|
+
teleport: true
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// 1. Click the SidePanel Trigger
|
|
90
|
+
await wrapper.find('[data-testid="sidepanel-trigger-user-settings"]').trigger('click');
|
|
91
|
+
|
|
92
|
+
// 2. Because Teleport is stubbed, we can find the panel inside the wrapper
|
|
93
|
+
const panel = wrapper.find('[data-testid="sidepanel-user-settings"]');
|
|
94
|
+
expect(panel.exists()).toBe(true);
|
|
95
|
+
|
|
96
|
+
// 3. Close it via the internal close button
|
|
97
|
+
await panel.find('[data-testid="sidepanel-close-btn"]').trigger('click');
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Strategy 2: Querying `document.body` directly
|
|
103
|
+
If you are testing logic that specifically relies on the element existing at the end of the DOM hierarchy, you can query `document.body` manually. Ensure you clean up your DOM after each test.
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { mount } from '@vue/test-utils';
|
|
107
|
+
import { describe, it, expect, afterEach } from 'vitest';
|
|
108
|
+
import UserProfile from './UserProfile.vue';
|
|
109
|
+
|
|
110
|
+
describe('UserProfile.vue (Real DOM)', () => {
|
|
111
|
+
afterEach(() => {
|
|
112
|
+
// Crucial: Clean up the DOM so teleports don't bleed between tests
|
|
113
|
+
document.body.innerHTML = '';
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('renders teleported modal into the body', async () => {
|
|
117
|
+
const wrapper = mount(UserProfile);
|
|
118
|
+
|
|
119
|
+
await wrapper.find('[data-testid="modal-trigger-edit-profile"]').trigger('click');
|
|
120
|
+
|
|
121
|
+
// Query the actual document body
|
|
122
|
+
const modalInBody = document.body.querySelector('[data-testid="modal-edit-profile"]');
|
|
123
|
+
expect(modalInBody).not.toBeNull();
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Accessibility (A11y) Testing
|
|
129
|
+
VLite3 overlays automatically inject correct ARIA attributes when they mount. If you write accessibility tests (like `axe-core`), you can target standard ARIA selectors.
|
|
130
|
+
* Both `Modal` and `SidePanel` bodies possess `role="dialog"` and `aria-modal="true"`.
|
|
131
|
+
* Focus is trapped inside the component while open, and restored back to the trigger on close.
|