@katlux/toolkit 0.1.1-alpha.128 → 0.1.1-alpha.130
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/bin/add-ai-reference.mjs +85 -46
- package/dist/module.json +1 -1
- package/dist/runtime/components/KButton/KButton.global.d.vue.ts +1 -1
- package/dist/runtime/components/KButton/KButton.global.vue.d.ts +1 -1
- package/dist/runtime/components/KButton/KButton.logic.d.ts +1 -1
- package/dist/runtime/components/KCombobox/KCombobox.global.d.vue.ts +3 -3
- package/dist/runtime/components/KCombobox/KCombobox.global.vue.d.ts +3 -3
- package/dist/runtime/components/KCompositeInput/KCompositeInput.global.d.vue.ts +6 -6
- package/dist/runtime/components/KCompositeInput/KCompositeInput.global.vue.d.ts +6 -6
- package/dist/runtime/components/KDatePicker/KDatePicker.global.d.vue.ts +1 -1
- package/dist/runtime/components/KDatePicker/KDatePicker.global.vue.d.ts +1 -1
- package/dist/runtime/components/KDateTimePicker/KDateTimePicker.global.d.vue.ts +1 -1
- package/dist/runtime/components/KDateTimePicker/KDateTimePicker.global.vue.d.ts +1 -1
- package/dist/runtime/components/KDropdown/KDropdown.global.d.vue.ts +1 -1
- package/dist/runtime/components/KDropdown/KDropdown.global.vue.d.ts +1 -1
- package/dist/runtime/components/KPagination/KPagination.global.d.vue.ts +1 -1
- package/dist/runtime/components/KPagination/KPagination.global.vue.d.ts +1 -1
- package/dist/runtime/components/KTree/KTree.global.d.vue.ts +1 -1
- package/dist/runtime/components/KTree/KTree.global.vue.d.ts +1 -1
- package/dist/runtime/components/KTreePicker/KTreePicker.global.d.vue.ts +2 -2
- package/dist/runtime/components/KTreePicker/KTreePicker.global.vue.d.ts +2 -2
- package/dist/runtime/presets/default/components/KTree/KTree.d.vue.ts +1 -1
- package/dist/runtime/presets/default/components/KTree/KTree.vue.d.ts +1 -1
- package/dist/skills/KATLUX_INDEX.md +40 -0
- package/dist/skills/katlux-components/SKILL.md +106 -0
- package/dist/skills/katlux-components/components/KAccordion.md +27 -0
- package/dist/skills/katlux-components/components/KAlert.md +22 -0
- package/dist/skills/katlux-components/components/KAreaChart.md +19 -0
- package/dist/skills/katlux-components/components/KBarChart.md +20 -0
- package/dist/skills/katlux-components/components/KBulkActions.md +19 -0
- package/dist/skills/katlux-components/components/KButton.md +12 -0
- package/dist/skills/katlux-components/components/KCalendar.md +17 -0
- package/dist/skills/katlux-components/components/KCheckbox.md +15 -0
- package/dist/skills/katlux-components/components/KCombobox.md +41 -0
- package/dist/skills/katlux-components/components/KCompositeInput.md +67 -0
- package/dist/skills/katlux-components/components/KContextMenu.md +20 -0
- package/dist/skills/katlux-components/components/KDataIterator.md +35 -0
- package/dist/skills/katlux-components/components/KDatatable.md +55 -0
- package/dist/skills/katlux-components/components/KDatePicker.md +26 -0
- package/dist/skills/katlux-components/components/KDropdown.md +18 -0
- package/dist/skills/katlux-components/components/KGantt.md +28 -0
- package/dist/skills/katlux-components/components/KGrid.md +17 -0
- package/dist/skills/katlux-components/components/KHeatMap.md +32 -0
- package/dist/skills/katlux-components/components/KHourSelect.md +11 -0
- package/dist/skills/katlux-components/components/KIcon.md +5 -0
- package/dist/skills/katlux-components/components/KLayout.md +34 -0
- package/dist/skills/katlux-components/components/KLineChart.md +18 -0
- package/dist/skills/katlux-components/components/KLoader.md +7 -0
- package/dist/skills/katlux-components/components/KMaskTextbox.md +12 -0
- package/dist/skills/katlux-components/components/KModal.md +22 -0
- package/dist/skills/katlux-components/components/KPagination.md +22 -0
- package/dist/skills/katlux-components/components/KPanel.md +18 -0
- package/dist/skills/katlux-components/components/KPieChart.md +14 -0
- package/dist/skills/katlux-components/components/KProductList.md +42 -0
- package/dist/skills/katlux-components/components/KScatterChart.md +20 -0
- package/dist/skills/katlux-components/components/KSlider.md +28 -0
- package/dist/skills/katlux-components/components/KTabs.md +31 -0
- package/dist/skills/katlux-components/components/KTextbox.md +15 -0
- package/dist/skills/katlux-components/components/KToast.md +14 -0
- package/dist/skills/katlux-components/components/KTooltip.md +13 -0
- package/dist/skills/katlux-components/components/KTree.md +45 -0
- package/dist/skills/katlux-components/components/KTreePicker.md +35 -0
- package/dist/skills/katlux-components/components/KTreeView.md +30 -0
- package/dist/skills/katlux-components/components/MultiTabs.md +20 -0
- package/dist/skills/katlux-components/components/calendar-customization.md +6 -0
- package/dist/skills/katlux-components/components/datatable-customization.md +14 -0
- package/dist/skills/katlux-components/components/directives.md +11 -0
- package/dist/skills/katlux-components/components/form-validation.md +125 -0
- package/dist/skills/katlux-components/components/tree-customization.md +9 -0
- package/dist/skills/katlux-components/components/useToast.md +27 -0
- package/dist/skills/katlux-components/components/validation-directives.md +6 -0
- package/dist/skills/katlux-config/SKILL.md +156 -0
- package/dist/skills/katlux-presets/SKILL.md +356 -0
- package/dist/skills/katlux-providers/SKILL.md +64 -0
- package/dist/skills/katlux-providers/providers/ADataProvider.md +59 -0
- package/dist/skills/katlux-providers/providers/CAPIFlatClientDataProvider.md +28 -0
- package/dist/skills/katlux-providers/providers/CAPIFlatServerDataProvider.md +20 -0
- package/dist/skills/katlux-providers/providers/CFlatClientDataProvider.md +11 -0
- package/dist/skills/katlux-providers/providers/CFlatServerDataProvider.md +58 -0
- package/dist/skills/katlux-providers/providers/CTreeClientDataProvider.md +14 -0
- package/dist/skills/katlux-providers/providers/CTreeServerDataProvider.md +5 -0
- package/dist/skills/katlux-providers/providers/KatluxIndexedDB.md +10 -0
- package/dist/skills/katlux-providers/providers/RequestProvider.md +49 -0
- package/dist/skills/katlux-providers/providers/RequestQueue.md +52 -0
- package/dist/skills/katlux-providers/providers/api-protocol.md +40 -0
- package/dist/skills/katlux-providers/providers/caching.md +170 -0
- package/dist/skills/katlux-providers/providers/composables.md +107 -0
- package/dist/skills/katlux-providers/providers/encryption.md +151 -0
- package/dist/skills/katlux-providers/providers/react-integration.md +45 -0
- package/dist/skills/katlux-providers/providers/testing-isolation.md +6 -0
- package/dist/skills/katlux-providers/providers/types.md +27 -0
- package/dist/skills/katlux-providers/providers/useDataProvider.md +51 -0
- package/dist/skills/katlux-tokens/SKILL.md +133 -0
- package/package.json +3 -3
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: katlux-presets
|
|
3
|
+
description: Complete reference for the Katlux preset and theming system. Covers creating custom presets via the CLI, the fallback/cascade resolution stack, folder structure, CSS variable override patterns, runtime switching, programmatic preset registration, custom SVG icons, and advanced KLayout slot forwarding. Use this skill for any task involving visual theming, design customization, or layout architecture.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Katlux Toolkit: Preset System
|
|
7
|
+
|
|
8
|
+
Katlux uses a unified **preset** system to allow full visual customization without forking components. Each component has a `*.global.vue` wrapper that delegates rendering to a preset-specific implementation via `usePresetComponent()`.
|
|
9
|
+
|
|
10
|
+
## Unified Preset Architecture
|
|
11
|
+
|
|
12
|
+
> [!IMPORTANT]
|
|
13
|
+
> **Any Preset Can Be Token-Only**:
|
|
14
|
+
> Katlux does **not** differentiate between "token presets" and "structural template presets".
|
|
15
|
+
> - **Any preset can be token-only**: If a preset only defines CSS variables/SCSS in `assets/css-variables.scss` and contains no `components/` directory, it is a token-only preset (e.g., the official `@katlux/preset-dark` package is purely token-based).
|
|
16
|
+
> - **Any preset can optionally override components**: Simply add `components/<ComponentName>/<ComponentName>.vue`.
|
|
17
|
+
> - All presets share the exact same architecture, directory conventions, and automatic cascading resolution.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Scaffolding a Custom Preset (CLI & MCP Tool)
|
|
22
|
+
|
|
23
|
+
Katlux preset scaffolding uses a single source of truth (`createPreset` engine). Custom presets can be generated via CLI command or programmatically via Katlux MCP server tool:
|
|
24
|
+
|
|
25
|
+
### Option A: CLI Tool (`create-preset`)
|
|
26
|
+
```bash
|
|
27
|
+
# Scaffolding based on another preset (e.g., 'modern'):
|
|
28
|
+
npx @katlux/toolkit create-preset cyber-brand --base=modern
|
|
29
|
+
|
|
30
|
+
# Scaffolding without a base preset (falls back directly to 'default'):
|
|
31
|
+
npx @katlux/toolkit create-preset cyber-brand
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Option B: Model Context Protocol (MCP) Tool (`katlux_create_preset`)
|
|
35
|
+
```json
|
|
36
|
+
// Call katlux_create_preset tool on @katlux/mcp server:
|
|
37
|
+
{
|
|
38
|
+
"name": "cyber-brand",
|
|
39
|
+
"base": "modern"
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
*The MCP tool calls the core `createPreset` engine directly, returning created file paths, starter CSS tokens, and ready-to-copy `app.config.ts` configuration.*
|
|
43
|
+
|
|
44
|
+
> [!WARNING]
|
|
45
|
+
> **Zero-Copy Fallback Architecture**:
|
|
46
|
+
> When a preset is based on another preset via `--base=<base-preset>`, **do NOT copy any files, tokens, or components from the base preset**.
|
|
47
|
+
> Katlux resolves presets via a cascading priority stack. Copying base files creates technical debt and prevents upstream improvements. Inheritance is handled exclusively via `activePreset` configuration in `app.config.ts`.
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## How Presets Are Activated & Fallback Mechanics
|
|
52
|
+
|
|
53
|
+
### 1. When Based on Another Preset (`--base=<base-preset>`)
|
|
54
|
+
|
|
55
|
+
Configure `app.config.ts` with a **multiple preset configuration** (array where child preset precedes the base):
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
// app.config.ts
|
|
59
|
+
export default defineAppConfig({
|
|
60
|
+
katluxToolkit: {
|
|
61
|
+
presetList: [
|
|
62
|
+
{ name: 'Default', value: 'default' },
|
|
63
|
+
{ name: 'Modern', value: 'modern' },
|
|
64
|
+
{ name: 'Cyber Brand', value: ['cyber-brand', 'modern'] },
|
|
65
|
+
],
|
|
66
|
+
// Priority cascade: cyber-brand -> modern -> default
|
|
67
|
+
activePreset: ['cyber-brand', 'modern'],
|
|
68
|
+
},
|
|
69
|
+
})
|
|
70
|
+
```
|
|
71
|
+
- **Fallback behavior**:
|
|
72
|
+
1. If `cyber-brand` defines a component or token, it is used.
|
|
73
|
+
2. If `cyber-brand` does not define it, it automatically falls back to `modern`.
|
|
74
|
+
3. If `modern` does not define it, it automatically falls back to `default`.
|
|
75
|
+
|
|
76
|
+
### 2. When No Base Preset is Provided
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
// app.config.ts
|
|
80
|
+
export default defineAppConfig({
|
|
81
|
+
katluxToolkit: {
|
|
82
|
+
presetList: [
|
|
83
|
+
{ name: 'Default', value: 'default' },
|
|
84
|
+
{ name: 'Cyber Brand', value: 'cyber-brand' },
|
|
85
|
+
],
|
|
86
|
+
activePreset: 'cyber-brand',
|
|
87
|
+
},
|
|
88
|
+
})
|
|
89
|
+
```
|
|
90
|
+
- Any unspecified token or component automatically falls back directly to the built-in `default` preset.
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Override Priority Stack
|
|
95
|
+
|
|
96
|
+
When `activePreset` is an **array**, presets are applied as a **priority stack** — the **leftmost entry has the highest priority**.
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
activePreset: ['dark', 'modern']
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Resolution order for each component:
|
|
103
|
+
1. **`dark`** preset — if it defines the component, use it. Done.
|
|
104
|
+
2. **`modern`** preset — if `dark` did not define the component, check here.
|
|
105
|
+
3. **`default`** preset — built-in fallback, always available.
|
|
106
|
+
|
|
107
|
+
**Visual representation**:
|
|
108
|
+
```
|
|
109
|
+
┌────────────────────────────────────────────────────────┐
|
|
110
|
+
│ activePreset: ['cyber-brand', 'modern'] │
|
|
111
|
+
├──────────────┬──────────────────────────┬──────────────┤
|
|
112
|
+
│ cyber-brand │ modern │ default │
|
|
113
|
+
│ (highest) │ (base fallback) │ (lowest) │
|
|
114
|
+
├──────────────┴──────────────────────────┴──────────────┤
|
|
115
|
+
│ KButton resolved from: │
|
|
116
|
+
│ cyber-brand has it? → YES → use cyber-brand's KButton│
|
|
117
|
+
│ │
|
|
118
|
+
│ KCombobox resolved from: │
|
|
119
|
+
│ cyber-brand has it? → NO │
|
|
120
|
+
│ modern has it? → YES → use modern's KCombobox │
|
|
121
|
+
│ │
|
|
122
|
+
│ KCalendar resolved from: │
|
|
123
|
+
│ cyber-brand → NO, modern → NO │
|
|
124
|
+
│ → use default's KCalendar │
|
|
125
|
+
└────────────────────────────────────────────────────────┘
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Custom Preset Folder Structure
|
|
131
|
+
|
|
132
|
+
When scaffolded via `create-preset`, the preset is created in `presets/<preset-name>`:
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
presets/
|
|
136
|
+
└── cyber-brand/
|
|
137
|
+
├── assets/
|
|
138
|
+
│ └── css-variables.scss ← All 22 Katlux design token categories commented out for instant customization
|
|
139
|
+
└── components/ ← Empty scaffold folder ready for optional custom component overrides
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
> [!NOTE]
|
|
143
|
+
> **Static CSS Variables File (`assets/css-variables.scss` or `.css`)**:
|
|
144
|
+
> Place custom CSS variables in `presets/<preset-name>/assets/css-variables.scss`.
|
|
145
|
+
> Scaffolding populates this file with **all Katlux design tokens in commented-out format** across 22 categories.
|
|
146
|
+
> `@katlux/toolkit` **automatically discovers and injects** this stylesheet — no manual `nuxt.config.ts` setup required!
|
|
147
|
+
> Always scope rules under the space-separated attribute selector `[data-preset~="<preset-name>"]`. Avoid `!important`.
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## Custom Preset Component File Format
|
|
152
|
+
|
|
153
|
+
Each component override is a standard Vue 3 SFC located at `presets/<preset-name>/components/<ComponentName>/<ComponentName>.vue`:
|
|
154
|
+
|
|
155
|
+
```vue
|
|
156
|
+
<!-- presets/my-brand/components/KButton/KButton.vue -->
|
|
157
|
+
<template lang="pug">
|
|
158
|
+
button.KButton.my-brand(:class="buttonClasses" @click="onClick")
|
|
159
|
+
slot
|
|
160
|
+
</template>
|
|
161
|
+
|
|
162
|
+
<script lang="ts" setup>
|
|
163
|
+
defineProps<{
|
|
164
|
+
buttonClasses: any
|
|
165
|
+
onClick: (e: MouseEvent) => void
|
|
166
|
+
// ... same props as the default KButton template
|
|
167
|
+
}>()
|
|
168
|
+
</script>
|
|
169
|
+
|
|
170
|
+
<style lang="scss" scoped>
|
|
171
|
+
.KButton.my-brand {
|
|
172
|
+
background: var(--button-bg-primary);
|
|
173
|
+
border-radius: var(--border-radius-md);
|
|
174
|
+
padding: var(--gap-sm) var(--gap-md);
|
|
175
|
+
}
|
|
176
|
+
</style>
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
> [!NOTE]
|
|
180
|
+
> Custom preset component files are **case-sensitive**. The folder name and file name must exactly match the component name (e.g., `KButton/KButton.vue`). Component-level props come from the internal logic layer — inspect the built-in default preset for the canonical prop list.
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Switching Presets at Runtime
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
const appConfig = useAppConfig()
|
|
188
|
+
|
|
189
|
+
// Switch to a single preset
|
|
190
|
+
appConfig.katluxToolkit.activePreset = 'modern'
|
|
191
|
+
|
|
192
|
+
// Switch to a preset stack
|
|
193
|
+
appConfig.katluxToolkit.activePreset = ['dark', 'modern']
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
> [!WARNING]
|
|
197
|
+
> **Container Swapping and Subtree Unmounting in Vue 3**:
|
|
198
|
+
> In Vue 3's virtual DOM reconciliation, when a parent component's root template is swapped via `:is="presetComponent"` (which occurs whenever switching to a preset that overrides a structural container component like `KLayout`, `KPanel`, or `KGrid`), Vue treats the template as a completely new component type.
|
|
199
|
+
>
|
|
200
|
+
> As a consequence:
|
|
201
|
+
> 1. **Component Lifecycle**: The previous container instance and its entire slotted VNode subtree are completely **unmounted** (`onUnmounted` fires for all slotted children) and new instances are mounted.
|
|
202
|
+
> 2. **Ephemeral State Loss**: Any reactive state held strictly in local component `ref()` or `reactive()` variables inside slotted components (such as an open accordion index, selected tab index in `KTabs`, or selected row IDs in a `KDatatable`) will reset to their default initial state.
|
|
203
|
+
> 3. **Design Contract**: This is an accepted and intended architectural behavior of dynamic preset template swapping in Katlux. Presets favor CSS token customizations for 99% of visual theming (which cause zero DOM unmounting). When a structural Vue template override is applied, template remounting occurs.
|
|
204
|
+
> 4. **State Persistence Best Practice**: If an application requires UI state (e.g., active tabs, table selections, filters) to survive dynamic preset switching, that state **must be held in an external state store** (such as **Pinia** or Nuxt's `useState()`), or synchronized to URL query parameters, rather than kept solely in ephemeral local component refs.
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## Programmatic Preset Registration (`registerPresetComponents`)
|
|
209
|
+
|
|
210
|
+
For multi-tenant SaaS whitelabeling or runtime-loaded micro-frontends:
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
import { registerPresetComponents } from '@katlux/toolkit'
|
|
214
|
+
import AcmeButton from './AcmeButton.vue'
|
|
215
|
+
|
|
216
|
+
// 1. Synchronous components (pre-bundled tenant themes):
|
|
217
|
+
registerPresetComponents('tenantAcme', {
|
|
218
|
+
'./components/KButton/KButton.vue': AcmeButton
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
// 2. Dynamic asynchronous loaders (code-split on demand):
|
|
222
|
+
registerPresetComponents('tenantBeta', {
|
|
223
|
+
'./components/KButton/KButton.vue': () => import('./BetaButton.vue')
|
|
224
|
+
})
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## Custom and On-Demand SVG Iconography (`registerSvgIcon`)
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
import { registerSvgIcon } from '@katlux/toolkit'
|
|
233
|
+
|
|
234
|
+
// Synchronous custom SVG:
|
|
235
|
+
registerSvgIcon('custom-badge', '<svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/></svg>')
|
|
236
|
+
|
|
237
|
+
// Dynamic asynchronous loader (fetches on-demand when rendered):
|
|
238
|
+
registerSvgIcon('heavy-logo', () => fetch('/icons/logo.svg').then(r => r.text()))
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## Built-in Preset Packages
|
|
244
|
+
|
|
245
|
+
| Preset Value | Package | Description |
|
|
246
|
+
| --- | --- | --- |
|
|
247
|
+
| `'default'` | _(built into `@katlux/toolkit`)_ | The baseline preset; always available as a final fallback |
|
|
248
|
+
| `'modern'` | `@katlux/preset-modern` | Clean modern design with gradients and smooth animations |
|
|
249
|
+
| `'dark'` | `@katlux/preset-dark` | Sleek dark mode styling |
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
npm install @katlux/preset-modern@alpha
|
|
253
|
+
npm install @katlux/preset-dark@alpha
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## Custom Layout Presets & Dynamic Slot Forwarding (`KLayout`)
|
|
259
|
+
|
|
260
|
+
`KLayout.global.vue` dynamically iterates over all slots provided by the consumer:
|
|
261
|
+
```pug
|
|
262
|
+
component(:is="presetComponent" v-bind="$attrs")
|
|
263
|
+
template(v-for="(_, slot) in $slots" #[slot]="scope")
|
|
264
|
+
slot(:name="slot" v-bind="scope")
|
|
265
|
+
```
|
|
266
|
+
This means custom presets can introduce any custom slots (e.g., `#toolbar`, `#statusbar`, `#banner`, `#right-drawer`) without modifying `@katlux/toolkit`.
|
|
267
|
+
|
|
268
|
+
### Example Custom KLayout Preset
|
|
269
|
+
```vue
|
|
270
|
+
<!-- presets/my-brand/components/KLayout/KLayout.vue -->
|
|
271
|
+
<template lang="pug">
|
|
272
|
+
.my-brand-layout
|
|
273
|
+
.banner(v-if="$slots.banner")
|
|
274
|
+
slot(name="banner")
|
|
275
|
+
header.header(v-if="$slots.header")
|
|
276
|
+
slot(name="header")
|
|
277
|
+
nav.toolbar(v-if="$slots.toolbar")
|
|
278
|
+
slot(name="toolbar")
|
|
279
|
+
.body
|
|
280
|
+
aside(v-if="$slots.aside")
|
|
281
|
+
slot(name="aside")
|
|
282
|
+
main
|
|
283
|
+
slot(name="main")
|
|
284
|
+
aside.drawer(v-if="$slots['right-drawer']")
|
|
285
|
+
slot(name="right-drawer")
|
|
286
|
+
footer(v-if="$slots.footer")
|
|
287
|
+
slot(name="footer")
|
|
288
|
+
.statusbar(v-if="$slots.statusbar")
|
|
289
|
+
slot(name="statusbar")
|
|
290
|
+
</template>
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### Modular Structure & Subcomponent Switching in `KLayout`
|
|
294
|
+
|
|
295
|
+
For significantly different layout structures, create modular subcomponents:
|
|
296
|
+
|
|
297
|
+
```
|
|
298
|
+
presets/my-brand/components/KLayout/
|
|
299
|
+
├── KLayout.vue <-- Main preset switcher
|
|
300
|
+
└── structures/
|
|
301
|
+
├── LayoutStandard.vue <-- Header + Sidebar + Main + Footer
|
|
302
|
+
├── LayoutDashboard.vue <-- Grid + Toolbar + Right drawer
|
|
303
|
+
└── LayoutCanvas.vue <-- Fullscreen clean canvas
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
```vue
|
|
307
|
+
<!-- presets/my-brand/components/KLayout/KLayout.vue -->
|
|
308
|
+
<script setup lang="ts">
|
|
309
|
+
import { computed } from 'vue'
|
|
310
|
+
import { useRoute } from '#app'
|
|
311
|
+
import LayoutStandard from './structures/LayoutStandard.vue'
|
|
312
|
+
import LayoutDashboard from './structures/LayoutDashboard.vue'
|
|
313
|
+
import LayoutCanvas from './structures/LayoutCanvas.vue'
|
|
314
|
+
|
|
315
|
+
const props = defineProps<{
|
|
316
|
+
structure?: 'standard' | 'dashboard' | 'canvas'
|
|
317
|
+
}>()
|
|
318
|
+
|
|
319
|
+
const route = useRoute()
|
|
320
|
+
|
|
321
|
+
const activeStructure = computed(() => {
|
|
322
|
+
const mode = props.structure || route.meta.layoutStructure
|
|
323
|
+
if (mode === 'dashboard') return LayoutDashboard
|
|
324
|
+
if (mode === 'canvas') return LayoutCanvas
|
|
325
|
+
return LayoutStandard
|
|
326
|
+
})
|
|
327
|
+
</script>
|
|
328
|
+
|
|
329
|
+
<template>
|
|
330
|
+
<component :is="activeStructure">
|
|
331
|
+
<template v-for="(_, slot) in $slots" #[slot]="scope">
|
|
332
|
+
<slot :name="slot" v-bind="scope" />
|
|
333
|
+
</template>
|
|
334
|
+
</component>
|
|
335
|
+
</template>
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
---
|
|
339
|
+
|
|
340
|
+
## Presetting Composables
|
|
341
|
+
|
|
342
|
+
### `usePresetComponent(name, defaultComponent)`
|
|
343
|
+
Resolves which preset component implementation to render for a given component name across the active preset cascade. Used internally by all global components.
|
|
344
|
+
- **Fast-path**: Evaluates `'default'` preset synchronously with zero glob scanning or iterations.
|
|
345
|
+
- **Instance Caching**: Caches `defineAsyncComponent` instances in a module-level `Map` to preserve component identity and avoid re-wrapping across re-renders.
|
|
346
|
+
- **Synchronous & Asynchronous Support**: Accepts both pre-bundled Vue component objects (zero async suspense boundary overhead) and dynamic loader functions registered via `registerPresetComponents`.
|
|
347
|
+
|
|
348
|
+
### `useTemplate(options)`
|
|
349
|
+
Reactive template resolution for components.
|
|
350
|
+
```typescript
|
|
351
|
+
const { metadata, isCustomTemplate, templateName, refreshTemplate } = useTemplate({
|
|
352
|
+
componentName: 'KButton',
|
|
353
|
+
fallbackToDefault: true
|
|
354
|
+
})
|
|
355
|
+
```
|
|
356
|
+
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: katlux-providers
|
|
3
|
+
description: Complete reference and atomic index for Katlux data management architecture (@katlux/providers). Links to dedicated specifications for ADataProvider, client/server providers, caching tiers, encryption, and auto-imported composables.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Katlux Data Management Architecture (`@katlux/providers`) Master Index
|
|
7
|
+
|
|
8
|
+
> **Atomic Architecture**: Data providers and architectural subsystems are divided into atomic, focused specification files under [`providers/`](providers/). To minimize token consumption and avoid context bloat, read **only** the atomic provider file needed for your task.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 1. Core Architecture & Base Engine
|
|
13
|
+
|
|
14
|
+
| Specification | Description | Primary Use Case | Spec Link |
|
|
15
|
+
| :--- | :--- | :--- | :--- |
|
|
16
|
+
| `ADataProvider` | Core abstract base class | Foundation for all providers. Constructor options, native state properties, observer events, URL serialization | [ADataProvider.md](providers/ADataProvider.md) |
|
|
17
|
+
| Core Types & Interfaces | Standard interfaces and enums | `IDataResult`, `IDataFilter`, `IDataSort`, `ECacheStrategy`, filter operators | [types.md](providers/types.md) |
|
|
18
|
+
| `useDataProvider` | Vue 3 reactivity bridge composable | Binds native `ADataProvider` to Vue refs (`pageData`, `loading`, `rowCount`), Pinia store sync, SSR cleanup | [useDataProvider.md](providers/useDataProvider.md) |
|
|
19
|
+
| React 18+ Integration | React integration guide | `useSyncExternalStore` binding for zero-overhead React 18+ concurrent rendering | [react-integration.md](providers/react-integration.md) |
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 2. Client-Side Data Providers
|
|
24
|
+
|
|
25
|
+
| Class | Description | Caching / Performance | Spec Link |
|
|
26
|
+
| :--- | :--- | :--- | :--- |
|
|
27
|
+
| `CFlatClientDataProvider` | In-memory client data engine | Instant sorting, complex AST filtering, local pagination for preloaded arrays | [CFlatClientDataProvider.md](providers/CFlatClientDataProvider.md) |
|
|
28
|
+
| `CTreeClientDataProvider` | Hierarchical client tree engine | Parent-child relationship management, recursive expansion, tree filtering | [CTreeClientDataProvider.md](providers/CTreeClientDataProvider.md) |
|
|
29
|
+
| `CAPIFlatClientDataProvider` | Remote fetch with client-side ops | Fetches dataset from API once, then performs all filtering/sorting locally | [CAPIFlatClientDataProvider.md](providers/CAPIFlatClientDataProvider.md) |
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## 3. Server-Side Data Providers
|
|
34
|
+
|
|
35
|
+
| Class | Description | Protocol / Backend | Spec Link |
|
|
36
|
+
| :--- | :--- | :--- | :--- |
|
|
37
|
+
| `CAPIFlatServerDataProvider` | Remote HTTP REST flat server provider | Offloads pagination, sorting, and filter AST to backend endpoints via HTTP GET/POST | [CAPIFlatServerDataProvider.md](providers/CAPIFlatServerDataProvider.md) |
|
|
38
|
+
| `CFlatServerDataProvider` | Base remote server data provider | Generic server provider extensible for custom network layers (GraphQL, gRPC, RPC) | [CFlatServerDataProvider.md](providers/CFlatServerDataProvider.md) |
|
|
39
|
+
| `CTreeServerDataProvider` | Remote hierarchical tree server provider | Server-side lazy loading of child tree nodes and sub-branches | [CTreeServerDataProvider.md](providers/CTreeServerDataProvider.md) |
|
|
40
|
+
| API Communication Protocol | Standard query params & filter JSON AST | Specification for backend developers to implement Katlux-compatible endpoints | [api-protocol.md](providers/api-protocol.md) |
|
|
41
|
+
| Provider Testing Isolation | Test patterns & `nuxtAppCompat` | Safe unit testing of server providers without full Nuxt runtime overhead | [testing-isolation.md](providers/testing-isolation.md) |
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## 4. Infrastructure & Security Services
|
|
46
|
+
|
|
47
|
+
| Service | Description | Security / Features | Spec Link |
|
|
48
|
+
| :--- | :--- | :--- | :--- |
|
|
49
|
+
| `RequestProvider` | Resilient HTTP networking client | Request deduplication, automatic retries, exponential backoff, circuit breaking | [RequestProvider.md](providers/RequestProvider.md) |
|
|
50
|
+
| `RequestQueue` | Offline PWA operation queue | Queues mutations offline in IndexedDB, auto-flushes on reconnect | [RequestQueue.md](providers/RequestQueue.md) |
|
|
51
|
+
| `KatluxIndexedDB` | High-performance IndexedDB wrapper | Client-side persistent storage for offline data and large cache entries | [KatluxIndexedDB.md](providers/KatluxIndexedDB.md) |
|
|
52
|
+
| `CacheProvider` | Tiered multi-layer caching engine | Memory, BrowserSession, LocalStorage, IndexedDB, Cookie tiers | [caching.md](providers/caching.md) |
|
|
53
|
+
| `EncryptionProvider` | WebCrypto & NodeCrypto encryption | AES-GCM 256-bit payload encryption, SSR zero-knowledge transit, AAD validation | [encryption.md](providers/encryption.md) |
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## 5. Auto-Imported Composables
|
|
58
|
+
|
|
59
|
+
| Composable | Description | Link |
|
|
60
|
+
| :--- | :--- | :--- |
|
|
61
|
+
| `useFilterLogic()`, `useSortLogic()` | Headless composables for input search & sort state | [composables.md](providers/composables.md) |
|
|
62
|
+
| `useDebounce()`, `useRemainingTime()` | Timing utilities for input throttling and session expiry | [composables.md](providers/composables.md) |
|
|
63
|
+
| `useKatluxContext()`, `useKatluxI18n()` | Global context, active preset, and locale formatting | [composables.md](providers/composables.md) |
|
|
64
|
+
| `useRequestProvider()`, `useRequestQueue()` | Global request client registry and offline sync queue access | [composables.md](providers/composables.md) |
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
## 3.2. Base Class: `ADataProvider`
|
|
2
|
+
|
|
3
|
+
`ADataProvider` is the core foundation for all data providers.
|
|
4
|
+
|
|
5
|
+
> [!IMPORTANT]
|
|
6
|
+
> **Framework-Agnostic Core**: `@katlux/providers` is a **100% standalone TypeScript library** with zero runtime dependencies on Vue or any framework. It can run in Node.js, CLI utilities, Vanilla JS, React, Svelte, or Vue 3 / Nuxt 3.
|
|
7
|
+
>
|
|
8
|
+
> - **Observer Pattern**: Use `provider.subscribe((state) => { ... })` to listen to updates.
|
|
9
|
+
> - **Auto-Bound Methods**: All provider methods (`setFilter`, `setCurrentPage`, `refresh`, etc.) are auto-bound in the constructor, making them safe to destructure directly.
|
|
10
|
+
> - **Pure Native State**: Provider properties are pure native TypeScript values (`pageData: T[]`, `rowCount: number`, `loading: boolean`, `currentPage: number`, etc.) with zero runtime overhead or call stack bottlenecks. Ingestion of 1,000,000 items is sub-50ms.
|
|
11
|
+
> - **Vue 3 Reactivity**: In Vue 3 and Nuxt 3, use the `useDataProvider` composable from `@katlux/toolkit` for idiomatic Vue reactivity, computed filtering/sorting, and automatic SSR lifecycle cleanup without memory leaks.
|
|
12
|
+
|
|
13
|
+
### Constructor Options (`IDataProviderOptions`)
|
|
14
|
+
| Option | Type | Default | Description |
|
|
15
|
+
| --- | --- | --- | --- |
|
|
16
|
+
| `filter` | `IDataFilter` | `null` | Initial filter configuration |
|
|
17
|
+
| `sortList` | `IDataSort[]` | `[]` | Initial sort configuration |
|
|
18
|
+
| `pageSize` | `number` | `10` | Items per page |
|
|
19
|
+
| `currentPage` | `number` | `1` | Starting page |
|
|
20
|
+
| `SSR` | `boolean` | `false` | Server-side rendering flag |
|
|
21
|
+
| `urlPageParam` | `string` | `undefined` | URL query key for page sync (e.g. `'p'`) |
|
|
22
|
+
| `cacheStrategy` | `ECacheStrategy` | `undefined` | Persistence engine |
|
|
23
|
+
| `cacheLifetime` | `number` | `undefined` | Cache expiration in milliseconds |
|
|
24
|
+
| `filterDebounce` | `number` | `300` | Debounce time in ms for `setFilter` |
|
|
25
|
+
| `sortDebounce` | `number` | `200` | Debounce time in ms for `setSortList` |
|
|
26
|
+
| `context` | `any` | `undefined` | Framework-agnostic SSR context (React SSR state, Next.js context, or Nuxt app instance) |
|
|
27
|
+
| `nuxtApp` | `any` | `undefined` | *(Deprecated, use `context`)* Nuxt app instance for backward compatibility |
|
|
28
|
+
| `refreshOnMutation` | `boolean` | `true` | Reload data after `create`/`update`/`delete` |
|
|
29
|
+
|
|
30
|
+
### State Properties (Pure native TypeScript properties)
|
|
31
|
+
- **`pageData`**: `T[]` - Current visible slice of data.
|
|
32
|
+
- **`rowCount`**: `number` - Total results (filtered count or server total).
|
|
33
|
+
- **`loading`**: `boolean` - Active data operation status.
|
|
34
|
+
- **`error`**: `any` - Last error encountered during fetch.
|
|
35
|
+
- **`currentPage`**: `number` - Active page index (1-based).
|
|
36
|
+
- **`pageSize`**: `number` - Items per page.
|
|
37
|
+
- **`filter`**: `IDataFilter | null` - Active filter configuration.
|
|
38
|
+
- **`sortList`**: `IDataSort[]` - Active multi-column sort array.
|
|
39
|
+
- **`urlPageParam`**: `string` - URL query key for pagination (e.g., `'p'`).
|
|
40
|
+
- **`SSR`**: `boolean` - Server-side rendering flag.
|
|
41
|
+
|
|
42
|
+
> **Architecture Note (Headless Data Layer)**: Selection state (`selectedRows`, `selectAll`, `selectAllScope`, `unselectedRows`) is transient UI state owned exclusively by presentation components like `KDatatable`. DataProviders remain pure headless data engines (fetching, caching, sorting, filtering, pagination) with zero selection state, ensuring multiple components (e.g. Datatable + Combobox) can safely share the same provider without cross-component selection collisions.
|
|
43
|
+
|
|
44
|
+
### Methods
|
|
45
|
+
- **`setFilter(filter: IDataFilter | null, immediate: boolean = false)`**: Updates filter and resets to page 1. Set `immediate: true` to bypass the 300ms debounce.
|
|
46
|
+
- **`setSortList(sort: IDataSort[], immediate: boolean = false)`**: Updates sorting and resets to page 1.
|
|
47
|
+
- **`setCurrentPage(page: number)`**: Direct page navigation.
|
|
48
|
+
- **`setPageSize(size: number)`**: Updates items per page; resets to page 1.
|
|
49
|
+
- **`loadPageData(options?)`**: (Abstract) Core logic for data retrieval. Supports `{ disableCache: true }` to force a fresh fetch.
|
|
50
|
+
- **`refresh(hardRefresh?: boolean)`**: Re-runs the last request and reloads data. Cache will only be overridden if `hardRefresh` is true.
|
|
51
|
+
- **`subscribe(listener: (state) => void): () => void`**: Subscribes a listener to provider state updates. Returns an unsubscribe function.
|
|
52
|
+
- **`notify()`**: Dispatches current state to all active subscribers.
|
|
53
|
+
- **`getState(): IDataProviderState<T>`**: Returns an immutable snapshot object of current state (`currentPage`, `pageSize`, `filter`, `sortList`).
|
|
54
|
+
- **`setState(partial: Partial<IDataProviderState<T>>, options?: IDataProviderSetStateOptions): void`**: Atomically updates provider state. Supports `{ silent: true }` to avoid auto-triggering data loads.
|
|
55
|
+
- **`onStateChange(listener: TDataProviderStateChangeListener<T>): () => void`**: Subscribes specifically to state change events, providing an array of changed keys. Returns unsubscribe function.
|
|
56
|
+
- **`serializeState(): string`**: Serializes active pagination, filters, and sorts to a URL query string (e.g. `page=2&pageSize=25`).
|
|
57
|
+
- **`deserializeState(serialized: string, options?: IDataProviderSetStateOptions): void`**: Restores provider state from a URL query string.
|
|
58
|
+
|
|
59
|
+
---
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
### `CAPIFlatClientDataProvider` / `CAPITreeClientDataProvider`
|
|
2
|
+
Specialized versions that fetch a dataset **once** from an API and then manage it locally as flat or tree data.
|
|
3
|
+
- **Purpose**: Ideal for small-to-medium datasets that need local filtering/sorting after an initial fetch.
|
|
4
|
+
- **Methods**:
|
|
5
|
+
| Method | Params | Description |
|
|
6
|
+
| --- | --- | --- |
|
|
7
|
+
| `setAPIUrl(url)` | `string` | Sets endpoint and triggers initial fetch |
|
|
8
|
+
| `refresh(hardRefresh?)`| `boolean` | Manually refetch the entire dataset. Cache will only be overridden if `hardRefresh` parameter is true. |
|
|
9
|
+
| `setFilter(filter)` | `IDataFilter \| null` | Applies a structured filter to the locally cached dataset. Filtering runs client-side via `useFilterLogic()`. Resets to page 1. |
|
|
10
|
+
| `create(item)` | `any` | POST to API and update local state |
|
|
11
|
+
| `update(item)` | `any` | PUT to API and update local item |
|
|
12
|
+
| `delete(items)` | `any[]` | DELETE from API and remove locally |
|
|
13
|
+
- **`filter`**: `Ref<IDataFilter | null>` - The currently active filter configuration.
|
|
14
|
+
|
|
15
|
+
### Tree-Specific methods (Client Providers)
|
|
16
|
+
Available on `CTreeClientDataProvider` and `CAPITreeClientDataProvider`:
|
|
17
|
+
| Method | Params | Description |
|
|
18
|
+
| --- | --- | --- |
|
|
19
|
+
| `toggleNode(id)` | `string\|number` | Toggles node expansion |
|
|
20
|
+
| `expandAll()` | None | Expands all branch nodes |
|
|
21
|
+
| `collapseAll()` | None | Collapses the entire tree |
|
|
22
|
+
| `getNode(id)` | `string\|number` | Returns `ITreeNode` wrapper |
|
|
23
|
+
| `getChildren(id)`| `string\|number` | Returns child `ITreeNode` array |
|
|
24
|
+
| `isExpanded(id)` | `string\|number` | Returns current expansion state |
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 3.4. Server-Side Data Providers (API)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
### `CAPIFlatServerDataProvider` / `CAPITreeServerDataProvider`
|
|
2
|
+
Handle full API integration with automatic query generation. Pagination, filtering, and sorting are executed on the server via query parameters.
|
|
3
|
+
|
|
4
|
+
- **`setAPIUrl(url: string)`**: Sets the endpoint and triggers initial load.
|
|
5
|
+
- **`apiUrl`**: `Ref<string>` - The active API endpoint.
|
|
6
|
+
|
|
7
|
+
| Provider Option | Type | Description |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `cacheStrategy` | `ECacheStrategy`| Persistence engine for this provider |
|
|
10
|
+
| `cacheLifetime` | `number` | Expiration in milliseconds |
|
|
11
|
+
| `refreshOnMutation`| `boolean` | Reload data after `delete`/`update` (Default: true) |
|
|
12
|
+
|
|
13
|
+
- **Methods**:
|
|
14
|
+
| Method | Params | Description |
|
|
15
|
+
| --- | --- | --- |
|
|
16
|
+
| `refresh(hardRefresh?)`| `boolean` | Manual trigger for reload. Cache will only be overridden if `hardRefresh` parameter is true. |
|
|
17
|
+
| `loadPageData(opts)` | `{ disableCache?: boolean }` | Core logic for data retrieval |
|
|
18
|
+
| `create(item)` | `any` | Async POST request to creation endpoint |
|
|
19
|
+
| `update(item)` | `any` | Async PUT request to update endpoint |
|
|
20
|
+
| `delete(items)` | `any[]` | Async batch deletion via endpoint |
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
### `CFlatClientDataProvider`
|
|
2
|
+
Manages local arrays with client-side logic, extending `AEncryptedClientProvider`.
|
|
3
|
+
- **`setData(data: any[]): Promise<void> | void`**: Ingests dataset into provider. When encryption is enabled, eagerly encrypts designated `fields` before storing in `allData`. Plaintext never persists in `allData`. Pre-encrypted envelopes (`__encrypted: true`) pass through unchanged (idempotent). Zero overhead synchronous fast-path when encryption is disabled.
|
|
4
|
+
- **`setDataChunked(data: any[], options?: ISetDataChunkedOptions): Promise<void>`**: Ingests massive datasets in batches, yielding to the event loop between chunks to keep the browser UI responsive (`chunkSize`, `onProgress`, `yieldStrategy`).
|
|
5
|
+
- **`setEncryption(options)` / `clearEncryption()`**: Dynamically updates, rotates, or wipes cryptographic keys and cached ciphers at runtime.
|
|
6
|
+
- **`allData`**: `Ref<any[]>` - The complete source dataset (holds ciphertext for encrypted fields in JS memory).
|
|
7
|
+
- **`pageData`**: `Ref<any[]>` - Active visible page slice (lazily decrypted into plaintext on active page render). Only `pageSize` rows are plaintext in JS memory.
|
|
8
|
+
- **`rowMap`**: `readonly TRow[]` - Reference map array maintaining the active filtered & sorted row references. When a page is requested, a portion of this array is served directly in $O(1)$ without re-evaluating filters or sorts.
|
|
9
|
+
- **`updateMap()`**: Explicitly forces recalculation of the `rowMap` if items inside `allData` were modified in-place.
|
|
10
|
+
- **`setFilter(filter: IDataFilter | null, immediate: boolean = false)`**: Applies a structured filter. When `encryption.searchIndex: true`, performs exact match (`==`, `!=`) and substring search (`in`) on encrypted fields using HMAC-SHA256 blind index tokens and trigram sets via `CSearchIndex`. Resets to page 1.
|
|
11
|
+
- **`filter`**: `Ref<IDataFilter | null>` - The currently active filter configuration.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
### `CFlatServerDataProvider`
|
|
2
|
+
Handler-based server-side flat data provider that delegates pagination, filtering, and sorting to a custom async handler function.
|
|
3
|
+
- **Purpose**: Use when API requests require custom logic, GraphQL queries, non-standard endpoints, or multi-source data aggregation where standard REST URL conventions don't apply.
|
|
4
|
+
- **Constructor Options (`IDataProviderOptions`)**:
|
|
5
|
+
| Option | Type | Default | Description |
|
|
6
|
+
| --- | --- | --- | --- |
|
|
7
|
+
| `pageSize` | `number` | `10` | Default items per page |
|
|
8
|
+
| `currentPage` | `number` | `1` | Initial page number (1-based) |
|
|
9
|
+
| `filter` | `IDataFilter \| null` | `null` | Initial filter structure |
|
|
10
|
+
| `sortList` | `IDataSort[]` | `[]` | Initial sorting rules |
|
|
11
|
+
| `SSR` | `boolean` | `false` | Enable Nuxt SSR hydration via `getAsyncData` |
|
|
12
|
+
| `urlPageParam` | `string` | `''` | Optional URL query parameter for page syncing |
|
|
13
|
+
| `deduplicate` | `boolean` | `true` | Prevent duplicate concurrent fetches |
|
|
14
|
+
|
|
15
|
+
- **Reactive Properties**:
|
|
16
|
+
| Property | Type | Description |
|
|
17
|
+
| --- | --- | --- |
|
|
18
|
+
| `pageData` | `Ref<any[]>` | Current page slice of records |
|
|
19
|
+
| `rowCount` | `Ref<number>` | Total matching record count returned by the handler |
|
|
20
|
+
| `loading` | `Ref<boolean>` | Reactive fetching indicator |
|
|
21
|
+
| `currentPage` | `Ref<number>` | Current page index (triggers reload when modified) |
|
|
22
|
+
| `pageSize` | `Ref<number>` | Page size (triggers reload when modified) |
|
|
23
|
+
| `contextKey` | `Ref<string>` | Stable key used for Nuxt SSR hydration caching |
|
|
24
|
+
|
|
25
|
+
- **Methods**:
|
|
26
|
+
| Method | Parameters | Description |
|
|
27
|
+
| --- | --- | --- |
|
|
28
|
+
| `setContextKey(key)` | `string` | Sets a stable unique key for Nuxt SSR hydration |
|
|
29
|
+
| `setPageDataHandler(handler)` | `TPageDataHandler` | Sets the async fetching function and triggers initial load |
|
|
30
|
+
| `loadPageData(opts?)` | `{ disableCache?: boolean }` | Triggers the registered handler |
|
|
31
|
+
| `refresh(hardRefresh?)` | `boolean` | Re-runs the handler; overrides cache if `hardRefresh = true` |
|
|
32
|
+
| `setFilter(filter)` | `IDataFilter \| null` | Updates active filter criteria and resets to page 1 |
|
|
33
|
+
| `setSortList(sorts)` | `IDataSort[]` | Updates sort order and resets to page 1 |
|
|
34
|
+
|
|
35
|
+
- **Example Usage**:
|
|
36
|
+
```ts
|
|
37
|
+
import { CFlatServerDataProvider } from '@katlux/providers'
|
|
38
|
+
|
|
39
|
+
const userProvider = new CFlatServerDataProvider({
|
|
40
|
+
pageSize: 15,
|
|
41
|
+
currentPage: 1,
|
|
42
|
+
SSR: true
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
// Set unique context key for SSR hydration
|
|
46
|
+
userProvider.setContextKey('admin-user-list')
|
|
47
|
+
|
|
48
|
+
// Register custom async fetcher
|
|
49
|
+
await userProvider.setPageDataHandler(async (currentPage, pageSize, filter, sortList) => {
|
|
50
|
+
const data = await $fetch('/api/users', {
|
|
51
|
+
params: { page: currentPage, limit: pageSize, filter, sort: sortList }
|
|
52
|
+
})
|
|
53
|
+
return {
|
|
54
|
+
rows: data.items,
|
|
55
|
+
rowCount: data.total
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
### `CTreeClientDataProvider`
|
|
2
|
+
Builds and manages reactive trees from flat arrays, extending `CFlatClientDataProvider`.
|
|
3
|
+
- **`setData(data: any[]): Promise<void> | void`**: Ingests hierarchical items. Encrypts sensitive fields eagerly while preserving structural keys (`idKey`, `parentKey`) in plaintext.
|
|
4
|
+
- **`setDataChunked(data: any[], options?)`**: Non-blocking chunked ingestion for large trees.
|
|
5
|
+
- **Constructor Options (`ITreeDataProviderOptions`)**:
|
|
6
|
+
| Option | Type | Default | Description |
|
|
7
|
+
| --- | --- | --- | --- |
|
|
8
|
+
| `idKey` | `string` | `'id'` | Unique identifier field |
|
|
9
|
+
| `parentKey` | `string` | `'parentId'`| Parent reference field |
|
|
10
|
+
| `expandedByDefault`| `boolean` | `false` | Initial node state |
|
|
11
|
+
| `paginateBy` | `string` | `'all'` | `'all'` (flat) or `'root'` (hierarchical) |
|
|
12
|
+
| `encryption` | `IProviderEncryptionOptions` | `undefined` | AES-GCM or custom cipher encryption configuration |
|
|
13
|
+
- **`setFilter(filter: IDataFilter | null)`**: Applies a structured filter across tree nodes client-side. When `searchIndex: true`, matches on encrypted fields using blind index search and automatically expands parent ancestors of matching child nodes. Resets to page 1.
|
|
14
|
+
- **`filter`**: `Ref<IDataFilter | null>` - The currently active filter configuration.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
### `CTreeServerDataProvider`
|
|
2
|
+
Hierarchical equivalent of `CFlatServerDataProvider`.
|
|
3
|
+
- **Purpose**: Tree-based server-side data provider delegating hierarchical data retrieval to a custom async handler function.
|
|
4
|
+
- **Tree Persistence**: Automatically syncs `expandedNodes` with the server via the handler.
|
|
5
|
+
- **Handler Signature**: `(page, size, filter, sort, treeParams) => Promise<IDataResult>`
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
### `KatluxIndexedDB`
|
|
2
|
+
Centralized IndexedDB singleton (`DB_NAME = 'KatluxDB'`, `DB_VERSION = 3`) that manages shared object stores (`cache`, `queue`, `dead_letter`). Prevents IndexedDB database versioning conflicts across Katlux modules.
|
|
3
|
+
|
|
4
|
+
- **Static Methods**:
|
|
5
|
+
| Method | Params | Description |
|
|
6
|
+
| --- | --- | --- |
|
|
7
|
+
| `open()` | None | Opens or retrieves the shared IDBDatabase connection |
|
|
8
|
+
| `getStore(name, mode)`| `'cache'\|'queue'\|'dead_letter', 'readonly'\|'readwrite'` | Returns an IDBObjectStore for reading or writing |
|
|
9
|
+
| `clearStore(name)` | `'cache'\|'queue'\|'dead_letter'` | Clears all records in the specified object store |
|
|
10
|
+
| `close()` | None | Closes the open database connection |
|