@dxtmisha/functional 1.15.1 → 1.15.2
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/ai-doc.md +60 -174
- package/package.json +1 -1
package/ai-doc.md
CHANGED
|
@@ -1,226 +1,112 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
1. When developing in Vue, always use this library for functionality, logic, and composables instead of `@dxtmisha/functional-basic` whenever possible.
|
|
5
|
-
2. It wraps basic non-reactive logic into Vue's reactivity system. If the required function or composable exists here, it has absolute priority.
|
|
6
|
-
3. Import utilities from `@dxtmisha/functional` for reactive UI behavior, composables, and state management.
|
|
7
|
-
|
|
8
|
-
WORKING WITH API AND STATE (useApi / executeUse):
|
|
9
|
-
A set of composables is provided for network requests: `useApiGet`, `useApiPost`, `useApiPut`, `useApiDelete`, `useApiRequest`, `useApiRef`, `useApiAsyncRef`, `useApiManagementRef`, `useApiManagementAsyncRef`.
|
|
10
|
-
Strictly follow these rules for their application:
|
|
11
|
-
|
|
12
|
-
1. DO NOT call these composables directly in the Vue components (SFC).
|
|
13
|
-
2. Move all API configurations and `useApi*` calls into SEPARATE FILES (services/stores).
|
|
14
|
-
3. Wrap the API configurations inside the `executeUse` factory (specifically: `executeUseGlobal`, `executeUseProvide`, or `executeUseLocal` from `src/functions/executeUse.ts`). This guarantees the creation of managed singletons (single access point) and prevents duplicated requests and reactive states.
|
|
15
|
-
4. Perform any additional request processing (e.g., data mapping, preparing structures for skeletons before loading a form) in the same file, inside the `executeUse` callback, and return a fully prepared set of data and methods.
|
|
16
|
-
*Example of correct usage:*
|
|
17
|
-
```ts
|
|
18
|
-
import { executeUseGlobal } from '@dxtmisha/functional';
|
|
19
|
-
import { useApiManagementRef } from '@dxtmisha/functional';
|
|
20
|
-
|
|
21
|
-
export const useUserManagement = executeUseGlobal(() => {
|
|
22
|
-
return useApiManagementRef(
|
|
23
|
-
{ path: '/api/users' }, // GET setup
|
|
24
|
-
{ date: (v) => new Date(v).toLocaleString() }, // Formatters
|
|
25
|
-
{ columns: ['name', 'email'] }, // Search
|
|
26
|
-
{ path: '/api/users' }, // POST
|
|
27
|
-
{ path: (o) => `/api/users/${o.id}` }, // PUT
|
|
28
|
-
{ path: (o) => `/api/users/${o.id}` } // DELETE
|
|
29
|
-
);
|
|
30
|
-
// Logic for skeletons, additional formatting, etc., should be added here,
|
|
31
|
-
// and then return the extended object.
|
|
32
|
-
});
|
|
33
|
-
```
|
|
34
|
-
5. Within the Vue component itself, simply import and call your custom singleton composable: `const { list, loading, sendPost } = useUserManagement();`
|
|
35
|
-
|
|
36
|
-
CHOOSING THE executeUse STRATEGY:
|
|
37
|
-
1. `executeUseLocal` (PREFERRED):
|
|
38
|
-
- When to use: For most API requests and services.
|
|
39
|
-
- Key Features: Works "lazily" (lazy initialization) — initializes only when first called. The instance persists until the end of the session. This prevents overloading the application start with unnecessary requests.
|
|
40
|
-
2. `executeUseGlobal`:
|
|
41
|
-
- When to use: When data or a service must be loaded/initialized IMMEDIATELY at application start (e.g., critical settings, SDKs).
|
|
42
|
-
- Key Features: Creates a single instance for the entire application. All global singletons are forcibly initialized via `executeUseGlobalInit()`.
|
|
43
|
-
3. `executeUseProvide`:
|
|
44
|
-
- When to use: For state shared between a parent and a group of child components (e.g., tabs, complex forms with sub-components).
|
|
45
|
-
- Key Features: Uses provide/inject. The first component in the tree that calls the hook becomes the "provider", others become consumers.
|
|
46
|
-
|
|
47
|
-
=============================================================================
|
|
48
|
-
DEVELOPER GUIDE: USING `@dxtmisha/functional` AS A LIBRARY
|
|
49
|
-
=============================================================================
|
|
50
|
-
|
|
51
|
-
This section contains instructions and code guidelines for AI models on how to import and use the Vue-specific reactive classes, composables, and utility functions provided by this library in Vue 3 / Nuxt applications.
|
|
1
|
+
# @dxtmisha/functional Reference
|
|
2
|
+
|
|
3
|
+
Vue 3 reactive utilities, composables, and classes built on `@dxtmisha/functional-basic`. Refer to [ai-types.md](file:///Volumes/T7/Code/dxt-ui/packages/functional/ai-types.md) for full signatures, types, and exported methods.
|
|
52
4
|
|
|
53
5
|
---
|
|
54
6
|
|
|
55
|
-
|
|
7
|
+
## Usage Rules & Strategies
|
|
56
8
|
|
|
57
|
-
|
|
9
|
+
1. **Priority**: Always prioritize `@dxtmisha/functional` over `@dxtmisha/functional-basic` in Vue environments.
|
|
10
|
+
2. **API & State (`useApi*` / `executeUse*`)**:
|
|
11
|
+
- **Never** call `useApiGet`, `useApiPost`, `useApiPut`, `useApiDelete`, `useApiRequest`, `useApiRef`, `useApiAsyncRef`, `useApiManagementRef`, `useApiManagementAsyncRef` directly inside components (SFC).
|
|
12
|
+
- Move all API configurations into separate files (services/stores).
|
|
13
|
+
- Wrap setups in `executeUse` factories (`executeUseLocal`, `executeUseGlobal`, `executeUseProvide`) to ensure singletons, prevent duplicate requests, and process data (mappings, skeletons) in the callback.
|
|
14
|
+
- Components only import/call the singleton hook.
|
|
58
15
|
|
|
59
|
-
#### `useStorageRef` (localStorage)
|
|
60
|
-
Reactively binds a key from `localStorage`.
|
|
61
16
|
```typescript
|
|
62
|
-
import {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
17
|
+
import { executeUseGlobal, useApiManagementRef } from '@dxtmisha/functional';
|
|
18
|
+
|
|
19
|
+
export const useUserManagement = executeUseGlobal(() => {
|
|
20
|
+
return useApiManagementRef(
|
|
21
|
+
{ path: '/api/users' }, // GET
|
|
22
|
+
{ date: (v) => new Date(v).toLocaleString() }, // Formatters
|
|
23
|
+
{ columns: ['name', 'email'] }, // Search
|
|
24
|
+
{ path: '/api/users' }, // POST
|
|
25
|
+
{ path: (o) => `/api/users/${o.id}` }, // PUT
|
|
26
|
+
{ path: (o) => `/api/users/${o.id}` } // DELETE
|
|
27
|
+
);
|
|
28
|
+
});
|
|
69
29
|
```
|
|
70
30
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
31
|
+
### `executeUse` Strategies:
|
|
32
|
+
- `executeUseLocal` (Preferred): Lazy-loaded when first called. Persists until session end.
|
|
33
|
+
- `executeUseGlobal`: Eagerly loaded at application startup (useful for critical configs, SDKs). Must be initialized via `executeUseGlobalInit()`.
|
|
34
|
+
- `executeUseProvide`: Scoped via `provide/inject` to a component tree branch (useful for form/tab hierarchies).
|
|
74
35
|
|
|
75
|
-
|
|
76
|
-
const step = useSessionRef<number>('form_step', 1);
|
|
36
|
+
---
|
|
77
37
|
|
|
78
|
-
|
|
79
|
-
const token = useCookieRef<string>('auth_token', '', { secure: true });
|
|
80
|
-
```
|
|
38
|
+
## Key API Examples
|
|
81
39
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
```typescript
|
|
85
|
-
import { useBroadcastValueRef } from '@dxtmisha/functional';
|
|
40
|
+
### 1. Storage & State (Reactive)
|
|
41
|
+
Reactively syncs Vue refs with browser storages or cross-tab broadcast channels.
|
|
86
42
|
|
|
87
|
-
// Synchronizes the value of the ref across tabs using BroadcastChannel
|
|
88
|
-
const syncState = useBroadcastValueRef<string>('active_channel', 'idle');
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
#### `useHashRef` (URL Hash)
|
|
92
|
-
Reactively binds Vue state to the URL hash parameters.
|
|
93
43
|
```typescript
|
|
94
|
-
import { useHashRef } from '@dxtmisha/functional';
|
|
44
|
+
import { useStorageRef, useSessionRef, useCookieRef, useBroadcastValueRef, useHashRef } from '@dxtmisha/functional';
|
|
95
45
|
|
|
46
|
+
const theme = useStorageRef<'light' | 'dark'>('theme_key', 'light');
|
|
47
|
+
const step = useSessionRef<number>('form_step', 1);
|
|
48
|
+
const token = useCookieRef<string>('auth_token', '', { secure: true });
|
|
49
|
+
const syncState = useBroadcastValueRef<string>('active_channel', 'idle');
|
|
96
50
|
const hashPage = useHashRef<string>('page', 'home');
|
|
97
51
|
```
|
|
98
52
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
### 2. Reactive Geolocation & Internationalization (`GeoRef`, `GeoIntlRef`, `GeoFlagRef`, `useTranslateRef`)
|
|
102
|
-
|
|
103
|
-
Provides reactive integrations for internationalization APIs.
|
|
53
|
+
### 2. Geolocation & Internationalization
|
|
54
|
+
Static helpers and reactive wrappers for localization and translation.
|
|
104
55
|
|
|
105
|
-
#### `GeoRef` & `GeoIntlRef`
|
|
106
56
|
```typescript
|
|
107
|
-
import { GeoRef, useGeoIntlRef } from '@dxtmisha/functional';
|
|
108
|
-
|
|
109
|
-
// Reactive tracking of user location details
|
|
110
|
-
const currentCountry = GeoRef.getCountry(); // ComputedRef<string>
|
|
57
|
+
import { GeoRef, useGeoIntlRef, useTranslateRef } from '@dxtmisha/functional';
|
|
111
58
|
|
|
112
|
-
|
|
59
|
+
const currentCountry = GeoRef.getCountry();
|
|
113
60
|
const intl = useGeoIntlRef();
|
|
114
|
-
const formattedPrice = intl.currency(150, 'EUR');
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
#### `useTranslateRef`
|
|
118
|
-
Reactively loads and gets translation tokens.
|
|
119
|
-
```typescript
|
|
120
|
-
import { useTranslateRef } from '@dxtmisha/functional';
|
|
121
|
-
|
|
122
|
-
const translations = useTranslateRef(['global.save', 'global.cancel']);
|
|
123
|
-
// returns: ShallowRef<Record<string, string>> containing loaded translations
|
|
61
|
+
const formattedPrice = intl.currency(150, 'EUR');
|
|
62
|
+
const translations = useTranslateRef(['global.save', 'global.cancel']); // Or alias `t(...)`
|
|
124
63
|
```
|
|
125
64
|
|
|
126
|
-
---
|
|
127
|
-
|
|
128
65
|
### 3. SEO & Layout Utilities
|
|
66
|
+
Metadata manager and reactive scrollbar tracker to solve layout shifts.
|
|
129
67
|
|
|
130
|
-
#### `useMeta`
|
|
131
|
-
Manages page metadata reactively. Calling setters will update document headers and tags reactively.
|
|
132
68
|
```typescript
|
|
133
|
-
import { useMeta } from '@dxtmisha/functional';
|
|
69
|
+
import { useMeta, ScrollbarWidthRef } from '@dxtmisha/functional';
|
|
134
70
|
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
metaManager.setDescription('Product details and configurations.');
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
#### `ScrollbarWidthRef`
|
|
141
|
-
Tracks the scrollbar width reactively to solve layout shift issues.
|
|
142
|
-
```typescript
|
|
143
|
-
import { ScrollbarWidthRef } from '@dxtmisha/functional';
|
|
71
|
+
const meta = useMeta();
|
|
72
|
+
meta.setTitle('Product Page');
|
|
144
73
|
|
|
145
74
|
const scrollbar = new ScrollbarWidthRef();
|
|
146
|
-
const
|
|
147
|
-
const hasScroll = scrollbar.is;
|
|
75
|
+
const w = scrollbar.width;
|
|
76
|
+
const hasScroll = scrollbar.is;
|
|
148
77
|
```
|
|
149
78
|
|
|
150
|
-
---
|
|
151
|
-
|
|
152
79
|
### 4. Advanced Reactivity Helpers
|
|
80
|
+
Helpers for resolving async data reactively or caching computations.
|
|
153
81
|
|
|
154
|
-
#### `computedAsync`
|
|
155
|
-
Creates a computed property that resolves its value asynchronously. Useful for async tasks inside computed getters.
|
|
156
|
-
```typescript
|
|
157
|
-
import { computedAsync } from '@dxtmisha/functional';
|
|
158
|
-
|
|
159
|
-
// Performs asynchronous data lookup and reactively returns the result
|
|
160
|
-
const asyncData = computedAsync(async () => {
|
|
161
|
-
return await fetchSomeData(activeId.value);
|
|
162
|
-
}, 'initial_loading_value');
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
#### `computedEternity`
|
|
166
|
-
Computes an asynchronous value once and caches it indefinitely unless manually refreshed.
|
|
167
82
|
```typescript
|
|
168
|
-
import { computedEternity } from '@dxtmisha/functional';
|
|
83
|
+
import { computedAsync, computedEternity } from '@dxtmisha/functional';
|
|
169
84
|
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
}, 'loading_state');
|
|
85
|
+
const asyncData = computedAsync(async () => await fetchSomeData(activeId.value), 'loading...');
|
|
86
|
+
const cachedData = computedEternity(async () => await fetchStaticData(), 'loading...');
|
|
173
87
|
```
|
|
174
88
|
|
|
175
|
-
---
|
|
176
|
-
|
|
177
89
|
### 5. List & Search Orchestration
|
|
90
|
+
Orchestrates list state (selection, pagination, highlights) and performs debounced list searches.
|
|
178
91
|
|
|
179
|
-
#### `ListDataRef`
|
|
180
|
-
A powerful reactive state orchestrator for managing lists, groups, items, pagination, highlight paths, and selections.
|
|
181
92
|
```typescript
|
|
182
|
-
import { ListDataRef } from '@dxtmisha/functional';
|
|
183
|
-
|
|
184
|
-
const items = ref([
|
|
185
|
-
{ value: 'id1', label: 'First Option' },
|
|
186
|
-
{ value: 'id2', label: 'Second Option' },
|
|
187
|
-
]);
|
|
188
|
-
const selectedId = ref('id1');
|
|
93
|
+
import { ListDataRef, useSearchRef } from '@dxtmisha/functional';
|
|
189
94
|
|
|
190
95
|
const listData = new ListDataRef(items, selectedId);
|
|
191
|
-
const isSelected = listData.isSelected;
|
|
192
|
-
const nextItem = listData.getSelectedNext();
|
|
193
|
-
```
|
|
96
|
+
const isSelected = listData.isSelected;
|
|
97
|
+
const nextItem = listData.getSelectedNext();
|
|
194
98
|
|
|
195
|
-
|
|
196
|
-
Combines a source list, target fields, search query, and options to reactively search a list with built-in delay and highlight support.
|
|
197
|
-
```typescript
|
|
198
|
-
import { useSearchRef } from '@dxtmisha/functional';
|
|
199
|
-
|
|
200
|
-
const query = ref('second');
|
|
99
|
+
const query = ref('search_term');
|
|
201
100
|
const { listSearch, loading, length } = useSearchRef(items, ['label'], query);
|
|
202
101
|
```
|
|
203
102
|
|
|
204
|
-
---
|
|
205
|
-
|
|
206
103
|
### 6. DOM & Lazy Rendering
|
|
104
|
+
Lifecycle-aware event listeners and IntersectionObserver wrappers.
|
|
207
105
|
|
|
208
|
-
#### `EventRef`
|
|
209
|
-
Reactive wrapper for DOM events. Starts and stops event binding cleanly inside Vue component lifecycles (runs setup and teardown hooks automatically).
|
|
210
|
-
```typescript
|
|
211
|
-
import { EventRef } from '@dxtmisha/functional';
|
|
212
|
-
|
|
213
|
-
// Listens reactively; auto-starts on setup and auto-stops on unmounted
|
|
214
|
-
const keyListener = new EventRef(window, window, 'keydown', (event) => {
|
|
215
|
-
console.log('Key pressed', event.key);
|
|
216
|
-
});
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
#### `useLazyRef`
|
|
220
|
-
Reactive manager utilizing `IntersectionObserver` to defer rendering of off-screen components.
|
|
221
106
|
```typescript
|
|
222
|
-
import { useLazyRef } from '@dxtmisha/functional';
|
|
107
|
+
import { EventRef, useLazyRef } from '@dxtmisha/functional';
|
|
223
108
|
|
|
109
|
+
const keyListener = new EventRef(window, window, 'keydown', (e) => console.log(e.key));
|
|
224
110
|
const lazyManager = useLazyRef();
|
|
225
|
-
const isVisible = lazyManager.addLazyItem(elementRef);
|
|
111
|
+
const isVisible = lazyManager.addLazyItem(elementRef);
|
|
226
112
|
```
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxtmisha/functional",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.15.
|
|
4
|
+
"version": "1.15.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "A comprehensive library of utilities, base classes, and Vue 3 composables for reactive web development. Extends @dxtmisha/functional-basic with Composition API.",
|
|
7
7
|
"keywords": [
|