@dxtmisha/functional 1.15.3 → 1.15.6
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/CHANGELOG.md +17 -0
- package/README.md +42 -21
- package/ai-description.md +7 -25
- package/ai-doc.md +5 -109
- package/ai-mcp.json +26 -0
- package/ai-prompts/api-reference.md +25 -0
- package/ai-prompts/localization-seo.md +29 -0
- package/ai-prompts/reactivity-lists.md +34 -0
- package/ai-prompts/storage-state.md +27 -0
- package/ai-types.md +669 -540
- package/dist/classes/ref/GeoIntlRef.d.ts +7 -0
- package/dist/composables/ref/useGeoIntlRef.d.ts +7 -0
- package/dist/composables/ref/useLazyItemByMarginRef.d.ts +6 -4
- package/dist/composables/ref/useLazyRef.d.ts +1 -1
- package/dist/composables/ref/useSearchRef.d.ts +2 -2
- package/dist/library.js +16 -15
- package/dist/types/searchTypes.d.ts +5 -1
- package/package.json +38 -11
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [1.15.5] - 2026-07-25
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- **useSearchRef**: Supported reactive `Ref` and getter callbacks for the `columns` parameter via `SearchColumnsInput` (`SearchColumnsRef<T, K>`), dynamically updating search results when target columns change.
|
|
9
|
+
- **searchTypes**: Introduced `SearchColumnsRef` and `SearchColumnsInput` type definitions to support reactive column definitions.
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
- **GeoIntlRef & useGeoIntlRef**: Added JSDoc `@remarks` guidelines recommending the use of standard non-reactive `GeoIntl` from `@dxtmisha/functional-basic` when reactivity is not required.
|
|
13
|
+
- **package.json**: Updated package `description` and expanded `keywords` list to comprehensively cover composables, `executeUse` singletons, and reactive utilities. Fixed `homepage` and `repository.directory` paths.
|
|
14
|
+
- **README.md**: Updated documentation and Quick Start code examples to showcase `executeUseGlobal` state singletons and reactive composables while preserving original document layout and style.
|
|
15
|
+
|
|
16
|
+
## [1.15.4] - 2026-07-24
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
- **useLazyItemByMarginRef**: Added explicit return type annotations (`ReturnType<typeof useLazyRef>`) for `getItemByMargin` and `LazyItemByMargin[]` for `getItems`.
|
|
20
|
+
- **useLazyRef**: Updated `getItem(element?: HTMLElement)` method signature to accept optional element references.
|
|
21
|
+
|
|
5
22
|
## [1.15.3] - 2026-07-14
|
|
6
23
|
|
|
7
24
|
### Changed
|
package/README.md
CHANGED
|
@@ -4,25 +4,27 @@
|
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
[](https://nodejs.org/)
|
|
6
6
|
|
|
7
|
-
`@dxtmisha/functional` is a library of utilities, base classes, and composables for complex web development in Vue 3. The package operates on the foundation of `@dxtmisha/functional-basic`, providing reactive wrappers and architectural solutions designed specifically for the Vue ecosystem (Composition API).
|
|
7
|
+
`@dxtmisha/functional` is a library of utilities, base classes, and composables for complex web development in Vue 3. The package operates on the foundation of `@dxtmisha/functional-basic`, providing reactive wrappers, state singletons, and architectural solutions designed specifically for the Vue ecosystem (Composition API).
|
|
8
8
|
|
|
9
9
|
## Why this library?
|
|
10
10
|
|
|
11
|
-
Every modern frontend application inevitably faces the same set of challenges: managing HTTP requests, localization, dates, cookies, caching, loading states, and side effects.
|
|
11
|
+
Every modern frontend application inevitably faces the same set of challenges: managing HTTP requests, state synchronization, localization, dates, cookies, caching, loading states, and side effects.
|
|
12
12
|
|
|
13
|
-
When developers solve these tasks locally within components, it often leads to code duplication, bloated `.vue` files,
|
|
13
|
+
When developers solve these tasks locally within components, it often leads to code duplication, bloated `.vue` files, memory leaks from forgotten subscriptions, and difficult-to-maintain state. `functional` solves this by moving business logic into ready-made reactive abstractions and state singletons (`executeUse`). You simply call the necessary composable or class, and under the hood, the library manages `ref` dependencies, monitors the Vue lifecycle, handles SSR hydration, and maintains strict TypeScript typing.
|
|
14
14
|
|
|
15
15
|
## What does it do?
|
|
16
16
|
|
|
17
|
-
For **network requests (API)** — a set of composables (`useApiGet`, `useApiPost`, `
|
|
17
|
+
For **network requests (API)** — a set of reactive composables (`useApiRef`, `useApiManagementRef`, `useApiGet`, `useApiPost`, `useApiPut`, `useApiDelete`) that encapsulate server interactions. They return a fully reactive object with loading states, errors, client-side search, schema validation, and fetched data. They intelligently handle response caching, SSR hydration, headers, and automatic cancellation of outdated requests.
|
|
18
18
|
|
|
19
|
-
For **
|
|
19
|
+
For **state management & singletons (`executeUse`)** — `executeUseLocal`, `executeUseGlobal`, and `executeUseProvide` factories that allow creating managed singleton state hooks. This decouples complex API and business logic completely from `.vue` components, ensuring unified state across component trees and preventing duplicate requests.
|
|
20
20
|
|
|
21
|
-
For **
|
|
21
|
+
For **browser state management** — convenient reactive hooks (`useStorageRef`, `useSessionRef`, `useCookieRef`, `useHashRef`, `useQueryRef`, `useBroadcastValueRef`) that seamlessly bind Vue variables to LocalStorage, SessionStorage, cookies, URL hash/query parameters, or BroadcastChannels with automatic cross-tab synchronization.
|
|
22
22
|
|
|
23
|
-
For **
|
|
23
|
+
For **geolocation and internationalization** — utilities like `useTranslateRef` (`t`), `useGeoIntlRef`, `useGeoUnitRef`, `GeoFlagRef`, and `DatetimeRef` that automatically respond to changes in global environment settings (language, currency, region) and dynamically rebuild dates, numbers, units, and translations without manual event listeners.
|
|
24
24
|
|
|
25
|
-
For **
|
|
25
|
+
For **UI component architecture** — a powerful system of base classes (`DesignConstructorAbstract`, `DesignComponents`, `DesignComp`, `DesignAbstract`, `DesignAsyncAbstract`) that provides a structured class-based inheritance model for building complex UI component constructors with automatic lifecycle, slot rendering, and BEM styling.
|
|
26
|
+
|
|
27
|
+
For **auxiliary utilities** — specialized reactive modules for SEO meta tags (`useMeta`), reactive scrollbar tracking (`ScrollbarWidthRef`), IntersectionObserver lazy loading (`useLazyRef`), list selection management (`ListDataRef`), debounced list search (`useSearchRef`), and asynchronous computation primitives (`computedAsync`, `computedEternity`).
|
|
26
28
|
|
|
27
29
|
## Installation
|
|
28
30
|
|
|
@@ -33,22 +35,41 @@ npm install @dxtmisha/functional
|
|
|
33
35
|
## Quick Start
|
|
34
36
|
|
|
35
37
|
```typescript
|
|
36
|
-
import {
|
|
37
|
-
|
|
38
|
+
import { ref } from 'vue'
|
|
39
|
+
import {
|
|
40
|
+
executeUseGlobal,
|
|
41
|
+
useApiManagementRef,
|
|
42
|
+
useStorageRef,
|
|
43
|
+
useGeoIntlRef,
|
|
44
|
+
t
|
|
45
|
+
} from '@dxtmisha/functional'
|
|
46
|
+
|
|
47
|
+
// 1. Decoupled API & state singleton service
|
|
48
|
+
export const useUserManagement = executeUseGlobal(() => {
|
|
49
|
+
return useApiManagementRef(
|
|
50
|
+
{ path: '/api/users' }, // GET list endpoint
|
|
51
|
+
{ date: (v) => new Date(v).toLocaleString() }, // Formatters
|
|
52
|
+
{ columns: ['name', 'email'] } // Search columns
|
|
53
|
+
)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
// 2. Component usage (Composition API)
|
|
38
57
|
export default {
|
|
39
58
|
setup() {
|
|
40
|
-
// Reactive
|
|
41
|
-
const
|
|
59
|
+
// Reactive storage with cross-tab auto-sync
|
|
60
|
+
const theme = useStorageRef<'light' | 'dark'>('theme', 'dark')
|
|
61
|
+
|
|
62
|
+
// Reactive locale-aware formatting
|
|
63
|
+
const intl = useGeoIntlRef()
|
|
64
|
+
const formattedPrice = intl.currency(150, 'EUR')
|
|
42
65
|
|
|
43
|
-
// Reactive
|
|
44
|
-
const
|
|
45
|
-
theme: 'dark'
|
|
46
|
-
})
|
|
66
|
+
// Reactive translations
|
|
67
|
+
const labels = t(['global.save', 'global.cancel'])
|
|
47
68
|
|
|
48
|
-
//
|
|
49
|
-
const
|
|
69
|
+
// Shared state singleton hook
|
|
70
|
+
const users = useUserManagement()
|
|
50
71
|
|
|
51
|
-
return {
|
|
72
|
+
return { theme, intl, formattedPrice, labels, users }
|
|
52
73
|
}
|
|
53
74
|
}
|
|
54
75
|
```
|
|
@@ -56,7 +77,7 @@ export default {
|
|
|
56
77
|
## Principles
|
|
57
78
|
|
|
58
79
|
- **Full Composition API integration** — every utility is designed with Vue 3's reactivity system in mind, heavily utilizing `ref`, `computed`, and lifecycle hooks.
|
|
59
|
-
- **Separation of concerns** — ideologically encourages extracting validation, state management, and side-effects into specialized classes, maintaining "thin" components.
|
|
80
|
+
- **Separation of concerns** — ideologically encourages extracting validation, state management, and side-effects into specialized classes and `executeUse` singletons, maintaining "thin" components.
|
|
60
81
|
- **Type safety** — provides 100% TypeScript type coverage between APIs, storages, and the UI, protecting codebase scaling with smart type inference.
|
|
61
82
|
- **Predictable resource management** — safely manages subscriptions and frees memory. When a component is unmounted, associated tasks and watchers are cleanly terminated.
|
|
62
83
|
|
|
@@ -69,7 +90,7 @@ Full API reference, examples, and guides:
|
|
|
69
90
|
## Difference from @dxtmisha/functional-basic
|
|
70
91
|
|
|
71
92
|
- **`@dxtmisha/functional-basic`** — core utilities, no framework dependencies. Use this with vanilla JS, React, or any non-Vue stack, or when building a library.
|
|
72
|
-
- **`@dxtmisha/functional`** — extends `functional-basic` with Vue 3 composables and
|
|
93
|
+
- **`@dxtmisha/functional`** — extends `functional-basic` with Vue 3 composables, reactive wrappers, state singletons, and component design constructors. Use this when building complex Vue / Nuxt applications.
|
|
73
94
|
|
|
74
95
|
## License
|
|
75
96
|
|
package/ai-description.md
CHANGED
|
@@ -1,25 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* `useApiManagementRef` / `useApiManagementAsyncRef`: High-level orchestration for CRUD operations (GET/POST/PUT/DELETE) with client-side searching, list formatting, and atomic mutation state management.
|
|
9
|
-
* Standard wrappers: `useApiGet`, `useApiPost`, `useApiPut`, `useApiDelete` for cleaner endpoint interaction.
|
|
10
|
-
* **Reactive Utilities:**
|
|
11
|
-
* `executeUse`: A factory for creating managed singletons (`global`, `provide`, `local`) to ensure unified state across component trees.
|
|
12
|
-
* `useTranslateRef`, `useStorageRef`, `useCookieRef`, `useSessionRef`: Reactive bridges to local persistence and internationalization.
|
|
13
|
-
* `computedAsync`, `computedEternity`: Advanced reactive primitives for asynchronous data flow and on-demand caching.
|
|
14
|
-
* **Data Formatting:** `GeoIntlRef`, `GeoUnitRef`, and `useFormattersRef` provide reactive, localized formatting for numbers, currencies, units (metric/imperial conversion), and dates.
|
|
15
|
-
* **List & Search Logic:** `ListDataRef` and `useSearchRef` manage complex hierarchical or flat data structures with optimized search and filtering capabilities.
|
|
16
|
-
|
|
17
|
-
### Triggers for Studying ai-types.md
|
|
18
|
-
Mandatory to review `ai-types.md` when:
|
|
19
|
-
1. **System Integration:** You are implementing new API endpoints, configuring `dxtFunctionalPlugin`, or setting up global state providers (`executeUseProvide`).
|
|
20
|
-
2. **Schema Validation:** You are utilizing `validateResponseContract` or `validateRequestContract` and require the expected structure for `ApiDataValidation` or error storage interfaces.
|
|
21
|
-
3. **Component Construction:** You are extending `DesignConstructorAbstract` or implementing custom component modifications.
|
|
22
|
-
4. **Type Mapping:** You encounter complex generic constraints in the `useApiManagementRef` signature or `Constr` prefixed utility types (e.g., `ConstrBind`, `ConstrOptions`, `ConstrEmit`).
|
|
23
|
-
|
|
24
|
-
### Integration Context
|
|
25
|
-
The library acts as a foundational service layer in the system stack. It integrates directly with Vue 3's composition API, Vue Router for navigation, and `@dxtmisha/functional-basic` for core network and utility logic. It is intended to be used as a singleton-pattern service provider within an application's plugin system via `dxtFunctionalPlugin` to facilitate consistent SSR state hydration and global dependency injection.
|
|
1
|
+
This library provides a reactive utility and component abstraction framework for Vue 3 built on top of functional basic utilities, standardizing UI design system architecture, reactive API request orchestration, localized data formatting, and state management. Its core capabilities span five main modules: the API & Network Module (`useApiRef`, `useApiAsyncRef`, `useApiManagementRef`, `useApiRequest`, and HTTP method composables) manages reactive request lifecycle, SSR prefetching, error contracts, response validation, and list mutations; the Design & Component Architecture Module (`DesignConstructorAbstract`, `DesignComponents`, `DesignAbstract`, `DesignChanged`) provides abstract base classes for component setup, dynamic rendering, class and style calculation, slot management, and prop change tracking; the Localization & Geo Module (`GeoRef`, `GeoIntlRef`, `GeoUnitRef`, `GeoFlagRef`, `DatetimeRef`, `useTranslateRef`) handles reactive internationalization, language/country metadata, locale-sensitive number and date formatting, unit conversions, and translation keys; the Storage & State Module (`useStorageRef`, `useCookieRef`, `useSessionRef`, `useBroadcastValueRef`, `useQueryRef`, `useHashRef`, `executeUse`) binds local/session storage, cookies, cross-tab communication, URL state, and singletons to Vue reactive references; and the DOM, Search & Navigation Module (`useLazyRef`, `RouterItemRef`, `useRouterList`, `useSearchRef`, `useMeta`, `EventRef`) provides lazy visibility tracking, router integration, search indexing, DOM event listeners, and reactive meta tag management. AI assistant study of ai-types.md is mandatory when extending design component abstractions like `DesignConstructorAbstract` or `DesignComponents`, typing component properties, modifications, or emits via `ConstrComponentMod`, `ConstrClasses`, `ConstrEmit`, or `ConstrBind`, configuring API management types including `ApiManagementGet`, `ApiManagementRequest`, or `ApiManagementSearch`, handling reactive input wrappers typed with `RefOrNormal` or `RefOrNormalOrFunction`, or structuring dataset records using `ListListInput`, `ListDataItem`, and `ListSelectedList`. The library seamlessly integrates with Vue 3, vue-router, and @dxtmisha/functional-basic to form a cohesive reactive application infrastructure.
|
|
2
|
+
## Mandatory Rules
|
|
3
|
+
Read the corresponding file if your task relates to:
|
|
4
|
+
- 'node_modules/@dxtmisha/functional/ai-prompts/api-reference.md': Scope-isolated singleton factories and reactive REST API management
|
|
5
|
+
- 'node_modules/@dxtmisha/functional/ai-prompts/localization-seo.md': Geographic context, i18n formatting, translation primitives, document metadata, and scrollbar utilities
|
|
6
|
+
- 'node_modules/@dxtmisha/functional/ai-prompts/reactivity-lists.md': Async reactivity composables, list data models, search filters, and DOM observers
|
|
7
|
+
- 'node_modules/@dxtmisha/functional/ai-prompts/storage-state.md': Composables for reactive browser storage, session, cookies, cross-tab broadcasting, and URL hash state
|
package/ai-doc.md
CHANGED
|
@@ -1,112 +1,8 @@
|
|
|
1
1
|
# @dxtmisha/functional Reference
|
|
2
2
|
|
|
3
|
-
Vue 3 reactive utilities
|
|
3
|
+
Vue 3 reactive utilities built on `@dxtmisha/functional-basic`. See `ai-types.md` for full signatures.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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.
|
|
15
|
-
|
|
16
|
-
```typescript
|
|
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
|
-
});
|
|
29
|
-
```
|
|
30
|
-
|
|
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).
|
|
35
|
-
|
|
36
|
-
---
|
|
37
|
-
|
|
38
|
-
## Key API Examples
|
|
39
|
-
|
|
40
|
-
### 1. Storage & State (Reactive)
|
|
41
|
-
Reactively syncs Vue refs with browser storages or cross-tab broadcast channels.
|
|
42
|
-
|
|
43
|
-
```typescript
|
|
44
|
-
import { useStorageRef, useSessionRef, useCookieRef, useBroadcastValueRef, useHashRef } from '@dxtmisha/functional';
|
|
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');
|
|
50
|
-
const hashPage = useHashRef<string>('page', 'home');
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
### 2. Geolocation & Internationalization
|
|
54
|
-
Static helpers and reactive wrappers for localization and translation.
|
|
55
|
-
|
|
56
|
-
```typescript
|
|
57
|
-
import { GeoRef, useGeoIntlRef, useTranslateRef } from '@dxtmisha/functional';
|
|
58
|
-
|
|
59
|
-
const currentCountry = GeoRef.getCountry();
|
|
60
|
-
const intl = useGeoIntlRef();
|
|
61
|
-
const formattedPrice = intl.currency(150, 'EUR');
|
|
62
|
-
const translations = useTranslateRef(['global.save', 'global.cancel']); // Or alias `t(...)`
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### 3. SEO & Layout Utilities
|
|
66
|
-
Metadata manager and reactive scrollbar tracker to solve layout shifts.
|
|
67
|
-
|
|
68
|
-
```typescript
|
|
69
|
-
import { useMeta, ScrollbarWidthRef } from '@dxtmisha/functional';
|
|
70
|
-
|
|
71
|
-
const meta = useMeta();
|
|
72
|
-
meta.setTitle('Product Page');
|
|
73
|
-
|
|
74
|
-
const scrollbar = new ScrollbarWidthRef();
|
|
75
|
-
const w = scrollbar.width;
|
|
76
|
-
const hasScroll = scrollbar.is;
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### 4. Advanced Reactivity Helpers
|
|
80
|
-
Helpers for resolving async data reactively or caching computations.
|
|
81
|
-
|
|
82
|
-
```typescript
|
|
83
|
-
import { computedAsync, computedEternity } from '@dxtmisha/functional';
|
|
84
|
-
|
|
85
|
-
const asyncData = computedAsync(async () => await fetchSomeData(activeId.value), 'loading...');
|
|
86
|
-
const cachedData = computedEternity(async () => await fetchStaticData(), 'loading...');
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### 5. List & Search Orchestration
|
|
90
|
-
Orchestrates list state (selection, pagination, highlights) and performs debounced list searches.
|
|
91
|
-
|
|
92
|
-
```typescript
|
|
93
|
-
import { ListDataRef, useSearchRef } from '@dxtmisha/functional';
|
|
94
|
-
|
|
95
|
-
const listData = new ListDataRef(items, selectedId);
|
|
96
|
-
const isSelected = listData.isSelected;
|
|
97
|
-
const nextItem = listData.getSelectedNext();
|
|
98
|
-
|
|
99
|
-
const query = ref('search_term');
|
|
100
|
-
const { listSearch, loading, length } = useSearchRef(items, ['label'], query);
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
### 6. DOM & Lazy Rendering
|
|
104
|
-
Lifecycle-aware event listeners and IntersectionObserver wrappers.
|
|
105
|
-
|
|
106
|
-
```typescript
|
|
107
|
-
import { EventRef, useLazyRef } from '@dxtmisha/functional';
|
|
108
|
-
|
|
109
|
-
const keyListener = new EventRef(window, window, 'keydown', (e) => console.log(e.key));
|
|
110
|
-
const lazyManager = useLazyRef();
|
|
111
|
-
const isVisible = lazyManager.addLazyItem(elementRef);
|
|
112
|
-
```
|
|
5
|
+
## Core Architectural Rules & Strategies
|
|
6
|
+
- **Priority**: Always use `@dxtmisha/functional` reactive composables instead of low-level `@dxtmisha/functional-basic` primitives in Vue 3 applications.
|
|
7
|
+
- **API & State Singletons**: **NEVER** call `useApi*` / `executeUse*` hooks directly in Vue components (`<script setup>`). Wrap them in `executeUseGlobal` (startup), `executeUseLocal` (lazy, session scope), or `executeUseProvide` (scoped tree) inside external service files. Components only import and call the resulting hook.
|
|
8
|
+
- **Purity & Atomicity**: Keep Vue components minimal. Extract all reactive state management, network orchestration, and side effects into external composables.
|
package/ai-mcp.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"uri": "@dxtmisha/functional/ai-prompts/api-reference.md",
|
|
4
|
+
"name": "API Management Reference",
|
|
5
|
+
"mimeType": "text/markdown",
|
|
6
|
+
"description": "Guidance and architectural patterns for REST API management and scope-isolated reactive singleton factories using the @dxtmisha/functional library."
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"uri": "@dxtmisha/functional/ai-prompts/localization-seo.md",
|
|
10
|
+
"name": "Localization SEO Utilities",
|
|
11
|
+
"mimeType": "text/markdown",
|
|
12
|
+
"description": "Guidelines and reactive utilities for locale-aware formatting, multi-key translations, geographic context, and dynamic HTML document metadata management."
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"uri": "@dxtmisha/functional/ai-prompts/reactivity-lists.md",
|
|
16
|
+
"name": "Reactivity and Lists",
|
|
17
|
+
"mimeType": "text/markdown",
|
|
18
|
+
"description": "Provides specifications and usage patterns for advanced async reactivity helpers, list selection models, debounced search filters, and DOM observer utilities."
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"uri": "@dxtmisha/functional/ai-prompts/storage-state.md",
|
|
22
|
+
"name": "Browser State Composables",
|
|
23
|
+
"mimeType": "text/markdown",
|
|
24
|
+
"description": "Provides reactive composable wrappers for persistent and synchronized browser state management, including localStorage, sessionStorage, cookies, broadcast channels, and URL hash fragments."
|
|
25
|
+
}
|
|
26
|
+
]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# API Management & Reactive Singletons
|
|
2
|
+
|
|
3
|
+
Guidance and usage patterns for REST API management and scope-isolated singleton factories in `@dxtmisha/functional`.
|
|
4
|
+
|
|
5
|
+
## 1. Scope Factory Initialization (`executeUse*`)
|
|
6
|
+
- **`executeUseGlobal`**: Initializes a global singleton instance at application startup (shared across the entire application).
|
|
7
|
+
- **`executeUseLocal`**: Lazily creates a session-scoped or closure-local instance upon first invocation.
|
|
8
|
+
- **`executeUseProvide`**: Scope-bound singleton bound to a specific component subtree via Vue `provide` / `inject`.
|
|
9
|
+
|
|
10
|
+
## 2. API Management (`useApiManagementRef`)
|
|
11
|
+
Handles REST CRUD operations with built-in reactivity, client-side caching, filtering, and contract validation.
|
|
12
|
+
|
|
13
|
+
### Example
|
|
14
|
+
```typescript
|
|
15
|
+
import { executeUseLocal, useApiManagementRef } from '@dxtmisha/functional';
|
|
16
|
+
|
|
17
|
+
export const useUsers = executeUseLocal(() => useApiManagementRef(
|
|
18
|
+
{ path: '/api/users' },
|
|
19
|
+
{ date: (v: string) => new Date(v).toLocaleString() },
|
|
20
|
+
{ columns: ['name', 'email'] },
|
|
21
|
+
{ path: '/api/users' },
|
|
22
|
+
{ path: (o) => `/api/users/${o.id}` },
|
|
23
|
+
{ path: (o) => `/api/users/${o.id}` }
|
|
24
|
+
));
|
|
25
|
+
```
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Localization, Geo & SEO Management
|
|
2
|
+
|
|
3
|
+
Locale-aware formatting, translation primitives, and reactive HTML document metadata handling.
|
|
4
|
+
|
|
5
|
+
## Available Utilities
|
|
6
|
+
- **`GeoRef`**: Access country information and geographic context (`GeoRef.getCountry()`).
|
|
7
|
+
- **`useGeoIntlRef()`**: Reactive internationalization helper for currency, numbers, and dates.
|
|
8
|
+
- **`useTranslateRef(keys)`**: Multi-key reactive translation resolver.
|
|
9
|
+
- **`useMeta()`**: Reactive manager for HTML document title, meta tags, and open graph social tags.
|
|
10
|
+
- **`ScrollbarWidthRef`**: Helper to measure dynamic scrollbar width for fixed overlay calculations.
|
|
11
|
+
|
|
12
|
+
### Example
|
|
13
|
+
```typescript
|
|
14
|
+
import {
|
|
15
|
+
GeoRef,
|
|
16
|
+
useGeoIntlRef,
|
|
17
|
+
useTranslateRef,
|
|
18
|
+
useMeta,
|
|
19
|
+
ScrollbarWidthRef
|
|
20
|
+
} from '@dxtmisha/functional';
|
|
21
|
+
|
|
22
|
+
const country = GeoRef.getCountry();
|
|
23
|
+
const intl = useGeoIntlRef();
|
|
24
|
+
intl.currency(150, 'EUR');
|
|
25
|
+
|
|
26
|
+
const t = useTranslateRef(['global.save']);
|
|
27
|
+
useMeta().setTitle('User Dashboard');
|
|
28
|
+
const scrollW = new ScrollbarWidthRef().width;
|
|
29
|
+
```
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Reactivity Helpers, Lists & DOM Utilities
|
|
2
|
+
|
|
3
|
+
Advanced async reactivity, list data models, search filters, and DOM observers.
|
|
4
|
+
|
|
5
|
+
## Available Composables & Classes
|
|
6
|
+
- **`computedAsync(evaluator, defaultVal)`**: Asynchronous computed reference for promise resolution.
|
|
7
|
+
- **`computedEternity(evaluator, defaultVal)`**: Cached asynchronous computed ref that preserves state across re-evaluations.
|
|
8
|
+
- **`ListDataRef(items, selectedId)`**: Reactive list structure supporting selection state management.
|
|
9
|
+
- **`useSearchRef(items, fields, queryRef)`**: Debounced multi-field search and highlighting composable.
|
|
10
|
+
- **`EventRef(target, element, event, callback)`**: Managed DOM event listener with automatic lifecycle cleanup.
|
|
11
|
+
- **`useLazyRef()`**: IntersectionObserver helper for lazy rendering and dynamic element loading.
|
|
12
|
+
|
|
13
|
+
### Example
|
|
14
|
+
```typescript
|
|
15
|
+
import { ref } from 'vue';
|
|
16
|
+
import {
|
|
17
|
+
computedAsync,
|
|
18
|
+
computedEternity,
|
|
19
|
+
ListDataRef,
|
|
20
|
+
useSearchRef,
|
|
21
|
+
EventRef,
|
|
22
|
+
useLazyRef
|
|
23
|
+
} from '@dxtmisha/functional';
|
|
24
|
+
|
|
25
|
+
const asyncData = computedAsync(async () => fetch('/api/data').then(r => r.json()), 'loading...');
|
|
26
|
+
const cachedData = computedEternity(async () => fetch('/api/cached').then(r => r.json()), 'loading...');
|
|
27
|
+
|
|
28
|
+
const list = new ListDataRef(items, selectedId);
|
|
29
|
+
const query = ref('');
|
|
30
|
+
const { listSearch } = useSearchRef(items, ['name', 'description'], query);
|
|
31
|
+
|
|
32
|
+
const listener = new EventRef(window, window, 'keydown', (e) => console.log(e.key));
|
|
33
|
+
const lazy = useLazyRef();
|
|
34
|
+
```
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Reactive Storage & Browser State
|
|
2
|
+
|
|
3
|
+
Composable wrappers for persistent and synchronized browser state management.
|
|
4
|
+
|
|
5
|
+
## Available Composables
|
|
6
|
+
- **`useStorageRef<T>(key, defaultVal)`**: Reactive `localStorage` wrapper with cross-tab synchronization.
|
|
7
|
+
- **`useSessionRef<T>(key, defaultVal)`**: Reactive `sessionStorage` wrapper for session-scoped data.
|
|
8
|
+
- **`useCookieRef<T>(key, defaultVal, options)`**: SSR-safe reactive cookie state wrapper.
|
|
9
|
+
- **`useBroadcastValueRef<T>(channel, defaultVal)`**: Reactive cross-tab broadcast messaging using `BroadcastChannel`.
|
|
10
|
+
- **`useHashRef<T>(key, defaultVal)`**: Reactive synchronization with URL hash fragments.
|
|
11
|
+
|
|
12
|
+
### Example
|
|
13
|
+
```typescript
|
|
14
|
+
import {
|
|
15
|
+
useStorageRef,
|
|
16
|
+
useSessionRef,
|
|
17
|
+
useCookieRef,
|
|
18
|
+
useBroadcastValueRef,
|
|
19
|
+
useHashRef
|
|
20
|
+
} from '@dxtmisha/functional';
|
|
21
|
+
|
|
22
|
+
const theme = useStorageRef<'light' | 'dark'>('theme', 'light');
|
|
23
|
+
const step = useSessionRef<number>('step', 1);
|
|
24
|
+
const token = useCookieRef<string>('auth', '', { secure: true });
|
|
25
|
+
const sync = useBroadcastValueRef<string>('ch', 'idle');
|
|
26
|
+
const page = useHashRef<string>('page', 'home');
|
|
27
|
+
```
|