@katlux/toolkit 0.1.1-alpha.129 → 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 +2 -2
- package/dist/runtime/components/KButton/KButton.global.vue.d.ts +2 -2
- package/dist/runtime/components/KButton/KButton.logic.d.ts +1 -1
- package/dist/runtime/components/KCheckbox/KCheckbox.global.d.vue.ts +1 -1
- package/dist/runtime/components/KCheckbox/KCheckbox.global.vue.d.ts +1 -1
- package/dist/runtime/components/KCombobox/KCombobox.global.d.vue.ts +1 -1
- package/dist/runtime/components/KCombobox/KCombobox.global.vue.d.ts +1 -1
- package/dist/runtime/components/KDatatable/KDataIterator.global.d.vue.ts +1 -1
- package/dist/runtime/components/KDatatable/KDataIterator.global.vue.d.ts +1 -1
- package/dist/runtime/components/KHourPicker/KHourPicker.global.d.vue.ts +1 -1
- package/dist/runtime/components/KHourPicker/KHourPicker.global.vue.d.ts +1 -1
- package/dist/runtime/components/KRangeSlider/KRangeSlider.global.d.vue.ts +1 -1
- package/dist/runtime/components/KRangeSlider/KRangeSlider.global.vue.d.ts +1 -1
- package/dist/runtime/components/KSlider/KSlider.global.d.vue.ts +1 -1
- package/dist/runtime/components/KSlider/KSlider.global.vue.d.ts +1 -1
- package/dist/runtime/components/KTreePicker/KTreePicker.global.d.vue.ts +1 -1
- package/dist/runtime/components/KTreePicker/KTreePicker.global.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 +2 -2
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: katlux-config
|
|
3
|
+
description: Katlux Toolkit project configuration, development standards, and installable packages reference. Use this skill when setting up nuxt.config.ts, app.config.ts, or when you need to know which packages to install.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Katlux Toolkit: Project Configuration & Development Standards
|
|
7
|
+
|
|
8
|
+
## Development Standards (Toolkit, Presets, Blocks)
|
|
9
|
+
|
|
10
|
+
1. **Mandatory Testing**: Every component (whether in `@katlux/toolkit`, presets, or blocks) requires unit and edge-case test coverage to guarantee full functionality and prevent regressions.
|
|
11
|
+
2. **Accessibility & WAI-ARIA**: All components implement appropriate WAI-ARIA roles (`role="dialog"`, `role="tablist"`, `role="grid"`, etc.), focus traps, keyboard navigation (`Enter`, `Space`, `Escape`), and accessible input clips (never `display: none` on interactive inputs).
|
|
12
|
+
3. **Translation-First Labels & Clean Props**: User-facing UI text, `aria-label`s, placeholders, empty state messages, button labels, and JS/TS strings use internationalization translation functions (`t('...')` / `:aria-label="t('...')"`). Avoid hardcoded English strings, static fallbacks (`|| ''`), or bloating props with extra label fields.
|
|
13
|
+
4. **CSS Variables Usage & Preset Selectors**: Styling properties (colors, fonts, sizes, borders, border-radii, shadows, gaps, margins, paddings, transitions) use CSS variables (e.g. `var(--primary-500)`, `var(--border-radius-md)`, `var(--component-gap)`). Preset root selectors use space-separated attribute selectors (`[data-preset~="preset-name"]`) rather than substring matching (`*=`). Avoid `!important` on preset theme rules to enable dynamic preset switching.
|
|
14
|
+
5. **No Deep Relative Imports**: Avoid deep relative imports (e.g. `../../../../composables/...`). Always use workspace or framework module aliases (such as `#toolkit/composables/...`, `#toolkit/components/...`, etc.) for clean, maintainable import paths.
|
|
15
|
+
|
|
16
|
+
## Template & Indentation Standards
|
|
17
|
+
|
|
18
|
+
1. **Template**: Always use **Pug** (`lang="pug"`).
|
|
19
|
+
2. **Indentation**: Use **Tabs**.
|
|
20
|
+
3. **Pug Tip**: Use `v-pre` on code blocks: `pre(v-pre) code {{ content }}`.
|
|
21
|
+
4. **Binding**: Bind DataProviders: `KDatatable(:dataProvider="myProvider")`.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## `nuxt.config.ts`
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
export default defineNuxtConfig({
|
|
29
|
+
modules: ['@katlux/toolkit'],
|
|
30
|
+
runtimeConfig: {
|
|
31
|
+
public: {
|
|
32
|
+
katluxToolkit: {
|
|
33
|
+
template: 'default', // Active template name
|
|
34
|
+
templatesDir: '~/templates', // Path to custom template overrides
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
> [!NOTE]
|
|
42
|
+
> `@katlux/toolkit` automatically installs `@nuxtjs/i18n` with a minimal English default if it is not already present in the consumer's `modules` array. Katlux components rely on `nuxtApp.$t` for all user-facing labels and ARIA strings. If you need custom locales or translation files, add `'@nuxtjs/i18n'` with your own configuration to `modules` **before** `'@katlux/toolkit'` and the toolkit will skip its default installation.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## `app.config.ts`
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
export default defineAppConfig({
|
|
50
|
+
katluxToolkit: {
|
|
51
|
+
presetList: [
|
|
52
|
+
{ name: 'Default', value: 'default' },
|
|
53
|
+
{ name: 'Modern', value: 'modern' },
|
|
54
|
+
{ name: 'Dark Mode', value: 'dark' },
|
|
55
|
+
{ name: 'Dark over Modern', value: ['dark', 'modern'] } // Multi-preset inheritance stack
|
|
56
|
+
],
|
|
57
|
+
// Accepts a single preset string (e.g., 'modern') or a priority array (e.g., ['dark', 'modern'])
|
|
58
|
+
// Priority order: Dark overrides Modern, which overrides Default fallback
|
|
59
|
+
activePreset: ['dark', 'modern'],
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Security & Content Security Policy (CSP) Standards
|
|
67
|
+
|
|
68
|
+
1. **Cookie Security & CSRF**:
|
|
69
|
+
- Keep authentication credentials in a **server-set `HttpOnly` cookie**, never in `localStorage`/`sessionStorage`/client-written cookies (readable by any XSS).
|
|
70
|
+
- For cookies written through `CCookieCache`, flags are constructor options: `sameSite` (default `'lax'`), `secure` (auto-detected from the request protocol), `httpOnly` (default `true`, server writes only), `path`. See the `katlux-providers` skill.
|
|
71
|
+
- `SameSite=Lax`/`Strict` is the baseline CSRF defense. For stricter needs (token-based CSRF), use a Nuxt-level module such as `nuxt-security` rather than rolling your own in the app.
|
|
72
|
+
|
|
73
|
+
2. **Content Security Policy (CSP)**:
|
|
74
|
+
- Configure CSP headers in `nuxt.config.ts` (via `routeRules` or server middleware) to prevent XSS and malicious inline scripts:
|
|
75
|
+
```typescript
|
|
76
|
+
export default defineNuxtConfig({
|
|
77
|
+
routeRules: {
|
|
78
|
+
'/**': {
|
|
79
|
+
headers: {
|
|
80
|
+
'Content-Security-Policy': [
|
|
81
|
+
"default-src 'self'",
|
|
82
|
+
"script-src 'self'",
|
|
83
|
+
"style-src 'self' 'unsafe-inline'",
|
|
84
|
+
"img-src 'self' data: https:",
|
|
85
|
+
"font-src 'self' https: data:",
|
|
86
|
+
"connect-src 'self'",
|
|
87
|
+
"frame-ancestors 'none'",
|
|
88
|
+
"base-uri 'self'",
|
|
89
|
+
"form-action 'self'"
|
|
90
|
+
].join('; ')
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
3. **SVG & Rich Text Sanitization**:
|
|
98
|
+
- Treat any `v-html` with unverified input as unsafe. `KIcon` passes its SVG string through `sanitizeHtml()` (`@katlux/toolkit`, `runtime/utils/sanitize.ts`), a best-effort **regex** filter that strips `<script>`/`<iframe>`-style tags, `on*=` handlers and plain `javascript:` URIs.
|
|
99
|
+
- **Limitation:** it is not a full HTML sanitizer — it does not catch every vector (e.g. `<svg/onload=…>` or entity-encoded `javascript:` URIs). Only feed it developer-controlled icon markup; use a real allowlist sanitizer such as DOMPurify for user-generated HTML.
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Installable Katlux Packages
|
|
104
|
+
|
|
105
|
+
| Package Name | Current Version | Description | Installation Command |
|
|
106
|
+
| --- | --- | --- | --- |
|
|
107
|
+
| `@katlux/toolkit` | `0.1.1-alpha.129` | Core Nuxt module, UI toolkit, presets, and components | `npm install @katlux/toolkit@alpha` |
|
|
108
|
+
| `@katlux/providers` | `0.1.1-alpha.117` | Core data providers, client caching, and state structures | `npm install @katlux/providers@alpha` |
|
|
109
|
+
| `@katlux/preset-modern` | `0.1.1-alpha.105` | Modern design preset and styling variables | `npm install @katlux/preset-modern@alpha` |
|
|
110
|
+
| `@katlux/preset-dark` | `0.1.1-alpha.36` | Sleek Dark Mode design preset | `npm install @katlux/preset-dark@alpha` |
|
|
111
|
+
| `@katlux/block-charts` | `0.1.1-alpha.105` | Pre-built charting block components | `npm install @katlux/block-charts@alpha` |
|
|
112
|
+
| `@katlux/block-ecommerce` | `0.1.1-alpha.105` | Pre-built eCommerce block components | `npm install @katlux/block-ecommerce@alpha` |
|
|
113
|
+
| `@katlux/mcp` | `0.1.0-alpha.9` | Model Context Protocol server for AI assistant integration | `npm install @katlux/mcp@alpha` |
|
|
114
|
+
|
|
115
|
+
> [!NOTE]
|
|
116
|
+
> Katlux packages are currently published under the `@alpha` tag on NPM. Always append `@alpha` or the specific version tag when adding dependencies.
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Monorepo Development Workflow
|
|
121
|
+
|
|
122
|
+
The project is a monorepo with apps under `apps/` and packages under `packages/`.
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
# Start the showcase dev server
|
|
126
|
+
cd apps/showcase && npm run dev
|
|
127
|
+
# OR from root (if workspace script is configured)
|
|
128
|
+
npm run dev
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
In dev mode, the showcase's `nuxt.config.ts` aliases `@katlux/*` package imports directly to their source `src/` directories (bypassing `dist/`). These aliases are **only active in development** (`process.env.NODE_ENV !== 'production'`) and should never appear in a consuming app's config.
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
# Build an individual package before publishing
|
|
135
|
+
cd packages/katlux-toolkit && npm run build
|
|
136
|
+
cd packages/katlux-providers && npm run build
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
# Publish packages to the beta npm tag
|
|
141
|
+
node publish-beta.mjs
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Typecheck Scopes & Verification Commands
|
|
147
|
+
|
|
148
|
+
The repository enforces three distinct typecheck scopes to guarantee type safety across packages, tests, and the consuming showcase Nuxt application:
|
|
149
|
+
|
|
150
|
+
| Scope | Script | Command | Purpose |
|
|
151
|
+
| :--- | :--- | :--- | :--- |
|
|
152
|
+
| **Root (Packages & Tests)** | `npm run typecheck` | `vue-tsc --noEmit` | Validates all packages (`packages/**`) and integration tests (`tests/**`), excluding `apps/**`. |
|
|
153
|
+
| **Strict Providers Package** | `npm run typecheck:providers` | `tsc -p packages/katlux-providers/tsconfig.json --noEmit` | Strict mode check on `@katlux/providers` source and unit specs. |
|
|
154
|
+
| **Showcase Application** | `npm run typecheck:showcase` | `npx nuxi prepare apps/showcase && vue-tsc --noEmit -p apps/showcase/tsconfig.json` | Validates the showcase Nuxt app including layouts, pages, and components using generated `.nuxt` types. |
|
|
155
|
+
| **Complete Monorepo Suite** | `npm run typecheck:all` | Runs all three scopes sequentially | Enforced in GitHub Actions CI (`.github/workflows/ci.yml`) on every push and PR. |
|
|
156
|
+
|
|
@@ -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)
|