@dxtmisha/wiki 0.39.7 → 0.39.8
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/dist/{defineProperty-DblGXmzD.js → defineProperty-Bjg6wMoX.js} +4 -4
- package/dist/library.js +1 -1
- package/dist/media.js +12 -0
- package/dist/storybook.js +1 -1
- package/package.json +1 -1
- package/src/media/functional/functional-basic/api/api.en.mdx +45 -0
- package/src/media/functional/functional-basic/api/api.ru.mdx +45 -0
- package/src/media/functional/functional-basic/api/api.vi.mdx +45 -0
- package/src/media/functional/functional-basic/classes/Api/Api.en.mdx +54 -54
- package/src/media/functional/functional-basic/classes/Api/Api.ru.mdx +54 -54
- package/src/media/functional/functional-basic/classes/Api/Api.vi.mdx +54 -54
- package/src/media/functional/functional-basic/classes/ApiCache/ApiCache.en.mdx +111 -0
- package/src/media/functional/functional-basic/classes/ApiCache/ApiCache.ru.mdx +111 -0
- package/src/media/functional/functional-basic/classes/ApiCache/ApiCache.vi.mdx +111 -0
- package/src/media/functional/functional-basic/classes/ApiDataReturn/ApiDataReturn.en.mdx +32 -0
- package/src/media/functional/functional-basic/classes/ApiDataReturn/ApiDataReturn.ru.mdx +32 -0
- package/src/media/functional/functional-basic/classes/ApiDataReturn/ApiDataReturn.vi.mdx +32 -0
- package/src/media/functional/functional-basic/classes/ApiDefault/ApiDefault.en.mdx +24 -28
- package/src/media/functional/functional-basic/classes/ApiDefault/ApiDefault.ru.mdx +24 -28
- package/src/media/functional/functional-basic/classes/ApiDefault/ApiDefault.vi.mdx +24 -28
- package/src/media/functional/functional-basic/classes/ApiHeaders/ApiHeaders.en.mdx +28 -14
- package/src/media/functional/functional-basic/classes/ApiHeaders/ApiHeaders.ru.mdx +33 -19
- package/src/media/functional/functional-basic/classes/ApiHeaders/ApiHeaders.vi.mdx +33 -19
- package/src/media/functional/functional-basic/classes/ApiHydration/ApiHydration.en.mdx +56 -0
- package/src/media/functional/functional-basic/classes/ApiHydration/ApiHydration.ru.mdx +56 -0
- package/src/media/functional/functional-basic/classes/ApiHydration/ApiHydration.vi.mdx +55 -0
- package/src/media/functional/functional-basic/classes/ApiInstance/ApiInstance.en.mdx +101 -49
- package/src/media/functional/functional-basic/classes/ApiInstance/ApiInstance.ru.mdx +101 -49
- package/src/media/functional/functional-basic/classes/ApiInstance/ApiInstance.vi.mdx +98 -47
- package/src/media/functional/functional-basic/classes/ApiPreparation/ApiPreparation.en.mdx +44 -26
- package/src/media/functional/functional-basic/classes/ApiPreparation/ApiPreparation.ru.mdx +45 -27
- package/src/media/functional/functional-basic/classes/ApiPreparation/ApiPreparation.vi.mdx +44 -26
- package/src/media/functional/functional-basic/classes/ApiResponse/ApiResponse.en.mdx +50 -21
- package/src/media/functional/functional-basic/classes/ApiResponse/ApiResponse.ru.mdx +54 -25
- package/src/media/functional/functional-basic/classes/ApiResponse/ApiResponse.vi.mdx +55 -26
- package/src/media/functional/functional-basic/classes/ApiStatus/ApiStatus.en.mdx +29 -32
- package/src/media/functional/functional-basic/classes/ApiStatus/ApiStatus.ru.mdx +33 -36
- package/src/media/functional/functional-basic/classes/ApiStatus/ApiStatus.vi.mdx +33 -36
- package/src/media/functional/functional-basic/classes/BroadcastMessage/BroadcastMessage.en.mdx +34 -53
- package/src/media/functional/functional-basic/classes/BroadcastMessage/BroadcastMessage.ru.mdx +33 -52
- package/src/media/functional/functional-basic/classes/BroadcastMessage/BroadcastMessage.vi.mdx +39 -58
- package/src/media/functional/functional-basic/classes/Cache/Cache.en.mdx +7 -4
- package/src/media/functional/functional-basic/classes/Cache/Cache.ru.mdx +7 -4
- package/src/media/functional/functional-basic/classes/Cache/Cache.vi.mdx +28 -25
- package/src/media/functional/functional-basic/classes/CacheItem/CacheItem.en.mdx +45 -53
- package/src/media/functional/functional-basic/classes/CacheItem/CacheItem.ru.mdx +46 -54
- package/src/media/functional/functional-basic/classes/CacheItem/CacheItem.vi.mdx +47 -55
- package/src/media/functional/functional-basic/classes/CacheStatic/CacheStatic.en.mdx +13 -1
- package/src/media/functional/functional-basic/classes/CacheStatic/CacheStatic.ru.mdx +13 -1
- package/src/media/functional/functional-basic/classes/CacheStatic/CacheStatic.vi.mdx +13 -0
- package/src/media/functional/functional-basic/classes/Cookie/Cookie.en.mdx +88 -44
- package/src/media/functional/functional-basic/classes/Cookie/Cookie.ru.mdx +88 -44
- package/src/media/functional/functional-basic/classes/Cookie/Cookie.vi.mdx +85 -41
- package/src/media/functional/functional-basic/classes/CookieBlock/CookieBlock.en.mdx +43 -22
- package/src/media/functional/functional-basic/classes/CookieBlock/CookieBlock.ru.mdx +46 -25
- package/src/media/functional/functional-basic/classes/CookieBlock/CookieBlock.vi.mdx +43 -22
- package/src/media/functional/functional-basic/classes/CookieBlockInstance/CookieBlockInstance.en.mdx +84 -0
- package/src/media/functional/functional-basic/classes/CookieBlockInstance/CookieBlockInstance.ru.mdx +84 -0
- package/src/media/functional/functional-basic/classes/CookieBlockInstance/CookieBlockInstance.vi.mdx +100 -0
- package/src/media/functional/functional-basic/classes/CookieStorage/CookieStorage.en.mdx +153 -0
- package/src/media/functional/functional-basic/classes/CookieStorage/CookieStorage.ru.mdx +153 -0
- package/src/media/functional/functional-basic/classes/CookieStorage/CookieStorage.vi.mdx +153 -0
- package/src/media/functional/functional-basic/classes/DataStorage/DataStorage.en.mdx +32 -25
- package/src/media/functional/functional-basic/classes/DataStorage/DataStorage.ru.mdx +32 -25
- package/src/media/functional/functional-basic/classes/DataStorage/DataStorage.vi.mdx +32 -27
- package/src/media/functional/functional-basic/classes/Datetime/Datetime.en.mdx +36 -4
- package/src/media/functional/functional-basic/classes/Datetime/Datetime.ru.mdx +36 -4
- package/src/media/functional/functional-basic/classes/Datetime/Datetime.vi.mdx +36 -4
- package/src/media/functional/functional-basic/classes/ErrorCenter/ErrorCenter.en.mdx +101 -70
- package/src/media/functional/functional-basic/classes/ErrorCenter/ErrorCenter.ru.mdx +100 -69
- package/src/media/functional/functional-basic/classes/ErrorCenter/ErrorCenter.vi.mdx +101 -70
- package/src/media/functional/functional-basic/classes/ErrorCenterHandler/ErrorCenterHandler.en.mdx +46 -42
- package/src/media/functional/functional-basic/classes/ErrorCenterHandler/ErrorCenterHandler.ru.mdx +46 -42
- package/src/media/functional/functional-basic/classes/ErrorCenterHandler/ErrorCenterHandler.vi.mdx +46 -42
- package/src/media/functional/functional-basic/classes/ErrorCenterInstance/ErrorCenterInstance.en.mdx +44 -96
- package/src/media/functional/functional-basic/classes/ErrorCenterInstance/ErrorCenterInstance.ru.mdx +44 -96
- package/src/media/functional/functional-basic/classes/ErrorCenterInstance/ErrorCenterInstance.vi.mdx +44 -96
- package/src/media/functional/functional-basic/classes/EventItem/EventItem.en.mdx +49 -28
- package/src/media/functional/functional-basic/classes/EventItem/EventItem.ru.mdx +21 -0
- package/src/media/functional/functional-basic/classes/EventItem/EventItem.vi.mdx +63 -42
- package/src/media/functional/functional-basic/classes/Formatters/Formatters.en.mdx +97 -109
- package/src/media/functional/functional-basic/classes/Formatters/Formatters.ru.mdx +86 -98
- package/src/media/functional/functional-basic/classes/Formatters/Formatters.vi.mdx +99 -111
- package/src/media/functional/functional-basic/classes/Geo/Geo.en.mdx +3 -3
- package/src/media/functional/functional-basic/classes/Geo/Geo.ru.mdx +5 -5
- package/src/media/functional/functional-basic/classes/Geo/Geo.vi.mdx +5 -5
- package/src/media/functional/functional-basic/classes/GeoFlag/GeoFlag.en.mdx +83 -40
- package/src/media/functional/functional-basic/classes/GeoFlag/GeoFlag.ru.mdx +83 -40
- package/src/media/functional/functional-basic/classes/GeoFlag/GeoFlag.vi.mdx +87 -44
- package/src/media/functional/functional-basic/classes/GeoInstance/GeoInstance.en.mdx +81 -0
- package/src/media/functional/functional-basic/classes/GeoInstance/GeoInstance.ru.mdx +81 -0
- package/src/media/functional/functional-basic/classes/GeoInstance/GeoInstance.vi.mdx +81 -0
- package/src/media/functional/functional-basic/classes/GeoPhone/GeoPhone.en.mdx +56 -105
- package/src/media/functional/functional-basic/classes/GeoPhone/GeoPhone.ru.mdx +53 -102
- package/src/media/functional/functional-basic/classes/GeoPhone/GeoPhone.vi.mdx +55 -105
- package/src/media/functional/functional-basic/classes/Hash/Hash.en.mdx +18 -7
- package/src/media/functional/functional-basic/classes/Hash/Hash.ru.mdx +18 -7
- package/src/media/functional/functional-basic/classes/Hash/Hash.vi.mdx +18 -7
- package/src/media/functional/functional-basic/classes/HashInstance/HashInstance.en.mdx +54 -0
- package/src/media/functional/functional-basic/classes/HashInstance/HashInstance.ru.mdx +54 -0
- package/src/media/functional/functional-basic/classes/HashInstance/HashInstance.vi.mdx +54 -0
- package/src/media/functional/functional-basic/classes/MetaStatic/MetaStatic.en.mdx +78 -0
- package/src/media/functional/functional-basic/classes/MetaStatic/MetaStatic.ru.mdx +78 -0
- package/src/media/functional/functional-basic/classes/MetaStatic/MetaStatic.vi.mdx +78 -0
- package/src/media/functional/functional-basic/classes/ResumableTimer/ResumableTimer.en.mdx +50 -0
- package/src/media/functional/functional-basic/classes/ResumableTimer/ResumableTimer.ru.mdx +50 -0
- package/src/media/functional/functional-basic/classes/ResumableTimer/ResumableTimer.vi.mdx +50 -0
- package/src/media/functional/functional-basic/classes/ServerStorage/ServerStorage.en.mdx +131 -0
- package/src/media/functional/functional-basic/classes/ServerStorage/ServerStorage.ru.mdx +131 -0
- package/src/media/functional/functional-basic/classes/ServerStorage/ServerStorage.vi.mdx +131 -0
- package/src/media/functional/functional-basic/classes/StorageCallback/StorageCallback.en.mdx +97 -0
- package/src/media/functional/functional-basic/classes/StorageCallback/StorageCallback.ru.mdx +97 -0
- package/src/media/functional/functional-basic/classes/StorageCallback/StorageCallback.vi.mdx +97 -0
- package/src/media/functional/functional-basic/functions/addTagHighlightMatch/addTagHighlightMatch.en.mdx +13 -5
- package/src/media/functional/functional-basic/functions/addTagHighlightMatch/addTagHighlightMatch.ru.mdx +13 -5
- package/src/media/functional/functional-basic/functions/addTagHighlightMatch/addTagHighlightMatch.vi.mdx +13 -5
- package/src/media/functional/functional-basic/functions/anyToString/anyToString.en.mdx +37 -19
- package/src/media/functional/functional-basic/functions/anyToString/anyToString.ru.mdx +37 -19
- package/src/media/functional/functional-basic/functions/anyToString/anyToString.vi.mdx +35 -17
- package/src/media/functional/functional-basic/functions/applyTemplate/applyTemplate.en.mdx +31 -19
- package/src/media/functional/functional-basic/functions/applyTemplate/applyTemplate.ru.mdx +31 -19
- package/src/media/functional/functional-basic/functions/applyTemplate/applyTemplate.vi.mdx +32 -20
- package/src/media/functional/functional-basic/functions/blobToBase64/blobToBase64.en.mdx +29 -15
- package/src/media/functional/functional-basic/functions/blobToBase64/blobToBase64.ru.mdx +28 -14
- package/src/media/functional/functional-basic/functions/blobToBase64/blobToBase64.vi.mdx +28 -14
- package/src/media/functional/functional-basic/functions/capitalize/capitalize.en.mdx +7 -3
- package/src/media/functional/functional-basic/functions/capitalize/capitalize.ru.mdx +7 -3
- package/src/media/functional/functional-basic/functions/capitalize/capitalize.vi.mdx +7 -3
- package/src/media/functional/functional-basic/functions/copyObject/copyObject.en.mdx +17 -13
- package/src/media/functional/functional-basic/functions/copyObject/copyObject.ru.mdx +17 -13
- package/src/media/functional/functional-basic/functions/copyObject/copyObject.vi.mdx +17 -13
- package/src/media/functional/functional-basic/functions/createElement/createElement.en.mdx +2 -0
- package/src/media/functional/functional-basic/functions/createElement/createElement.ru.mdx +2 -0
- package/src/media/functional/functional-basic/functions/createElement/createElement.vi.mdx +2 -0
- package/src/media/functional/functional-basic/functions/encodeAttribute/encodeAttribute.en.mdx +1 -3
- package/src/media/functional/functional-basic/functions/encodeAttribute/encodeAttribute.ru.mdx +1 -3
- package/src/media/functional/functional-basic/functions/encodeAttribute/encodeAttribute.vi.mdx +1 -3
- package/src/media/functional/functional-basic/functions/executeFunction/executeFunction.en.mdx +13 -10
- package/src/media/functional/functional-basic/functions/executeFunction/executeFunction.ru.mdx +14 -11
- package/src/media/functional/functional-basic/functions/executeFunction/executeFunction.vi.mdx +12 -9
- package/src/media/functional/functional-basic/functions/executePromise/executePromise.en.mdx +14 -13
- package/src/media/functional/functional-basic/functions/executePromise/executePromise.ru.mdx +15 -14
- package/src/media/functional/functional-basic/functions/executePromise/executePromise.vi.mdx +14 -13
- package/src/media/functional/functional-basic/functions/forEach/forEach.en.mdx +1 -1
- package/src/media/functional/functional-basic/functions/forEach/forEach.ru.mdx +1 -1
- package/src/media/functional/functional-basic/functions/forEach/forEach.vi.mdx +1 -1
- package/src/media/functional/functional-basic/functions/frame/frame.en.mdx +7 -4
- package/src/media/functional/functional-basic/functions/frame/frame.ru.mdx +6 -3
- package/src/media/functional/functional-basic/functions/frame/frame.vi.mdx +7 -4
- package/src/media/functional/functional-basic/functions/getArrayHighlightMatch/getArrayHighlightMatch.en.mdx +34 -0
- package/src/media/functional/functional-basic/functions/getArrayHighlightMatch/getArrayHighlightMatch.ru.mdx +34 -0
- package/src/media/functional/functional-basic/functions/getArrayHighlightMatch/getArrayHighlightMatch.vi.mdx +35 -0
- package/src/media/functional/functional-basic/functions/getCurrentDate/getCurrentDate.en.mdx +2 -0
- package/src/media/functional/functional-basic/functions/getCurrentDate/getCurrentDate.ru.mdx +2 -0
- package/src/media/functional/functional-basic/functions/getCurrentDate/getCurrentDate.vi.mdx +2 -0
- package/src/media/functional/functional-basic/functions/getCurrentTime/getCurrentTime.en.mdx +21 -0
- package/src/media/functional/functional-basic/functions/getCurrentTime/getCurrentTime.ru.mdx +21 -0
- package/src/media/functional/functional-basic/functions/getCurrentTime/getCurrentTime.vi.mdx +21 -0
- package/src/media/functional/functional-basic/functions/getElementId/getElementId.en.mdx +17 -3
- package/src/media/functional/functional-basic/functions/getElementId/getElementId.ru.mdx +17 -3
- package/src/media/functional/functional-basic/functions/getElementId/getElementId.vi.mdx +18 -4
- package/src/media/functional/functional-basic/functions/getElementSafeScript/getElementSafeScript.en.mdx +31 -0
- package/src/media/functional/functional-basic/functions/getElementSafeScript/getElementSafeScript.ru.mdx +31 -0
- package/src/media/functional/functional-basic/functions/getElementSafeScript/getElementSafeScript.vi.mdx +31 -0
- package/src/media/functional/functional-basic/functions/getOnlyText/getOnlyText.en.mdx +25 -0
- package/src/media/functional/functional-basic/functions/getOnlyText/getOnlyText.ru.mdx +25 -0
- package/src/media/functional/functional-basic/functions/getOnlyText/getOnlyText.vi.mdx +25 -0
- package/src/media/functional/functional-basic/functions/getSearchExp/getSearchExp.en.mdx +11 -4
- package/src/media/functional/functional-basic/functions/getSearchExp/getSearchExp.ru.mdx +14 -7
- package/src/media/functional/functional-basic/functions/getSearchExp/getSearchExp.vi.mdx +13 -6
- package/src/media/functional/functional-basic/functions/getSeparatingSearchExp/getSeparatingSearchExp.en.mdx +3 -2
- package/src/media/functional/functional-basic/functions/getSeparatingSearchExp/getSeparatingSearchExp.ru.mdx +3 -2
- package/src/media/functional/functional-basic/functions/getSeparatingSearchExp/getSeparatingSearchExp.vi.mdx +3 -2
- package/src/media/functional/functional-basic/functions/toNumber/toNumber.en.mdx +25 -9
- package/src/media/functional/functional-basic/functions/toNumber/toNumber.ru.mdx +25 -9
- package/src/media/functional/functional-basic/functions/toNumber/toNumber.vi.mdx +25 -9
- package/src/media/functional/functional-basic/functions/toString/toString.en.mdx +28 -0
- package/src/media/functional/functional-basic/functions/toString/toString.ru.mdx +28 -0
- package/src/media/functional/functional-basic/functions/toString/toString.vi.mdx +28 -0
- package/src/media/functional/ui/about/about.en.mdx +45 -0
- package/src/media/functional/ui/about/about.ru.mdx +45 -0
- package/src/media/functional/ui/about/about.vi.mdx +45 -0
- package/src/media/functional/ui/component/component.en.mdx +104 -0
- package/src/media/functional/ui/component/component.ru.mdx +106 -0
- package/src/media/functional/ui/component/component.vi.mdx +104 -0
- package/src/media/functional/ui/setup/setup.en.mdx +72 -0
- package/src/media/functional/ui/setup/setup.ru.mdx +72 -0
- package/src/media/functional/ui/setup/setup.vi.mdx +72 -0
- package/src/media/functional/ui/wiki-data.en.mdx +114 -0
- package/src/media/functional/ui/wiki-data.ru.mdx +114 -0
- package/src/media/functional/ui/wiki-data.vi.mdx +114 -0
|
@@ -4,31 +4,31 @@ import {Meta} from '@storybook/addon-docs/blocks'
|
|
|
4
4
|
|
|
5
5
|
# EventItem Class
|
|
6
6
|
|
|
7
|
-
A powerful wrapper for managing event listeners on DOM elements or the `window` object.
|
|
7
|
+
A powerful wrapper for managing event listeners on DOM elements or the `window` object. The class simplifies working with the event lifecycle (add, remove, toggle), supports automatic checking of the element's presence in the DOM, and provides built-in optimization for heavy events such as `resize` and `scroll`.
|
|
8
8
|
|
|
9
9
|
## Key Features
|
|
10
10
|
|
|
11
|
-
- **Lifecycle Management** — convenient `start`, `stop`, `toggle`, and `reset` methods
|
|
12
|
-
- **DOM Safety** — automatic `isInDom` check before executing the
|
|
13
|
-
- **ResizeObserver Support** — built-in handling of the `resize` event for any HTML
|
|
14
|
-
- **Scroll Optimization** — special `scroll-sync` event type using `requestAnimationFrame` for high performance.
|
|
15
|
-
- **Chaining and Flexibility** — support for
|
|
16
|
-
- **Custom Data** — ability to pass and dispatch custom data via `CustomEvent`.
|
|
11
|
+
- **Lifecycle Management** — convenient `start`, `stop`, `toggle`, and `reset` methods to control event listening.
|
|
12
|
+
- **DOM Safety** — automatic `isInDom` check before executing the handler (a control element can be configured).
|
|
13
|
+
- **ResizeObserver Support** — built-in handling of the `resize` event for any HTML elements via a modern API.
|
|
14
|
+
- **Scroll Optimization** — a special `scroll-sync` event type using `requestAnimationFrame` for high performance.
|
|
15
|
+
- **Chaining and Flexibility** — support for call chaining and dynamic changing of the target, type, or event handler.
|
|
16
|
+
- **Custom Data** — the ability to pass and dispatch custom data via `CustomEvent`.
|
|
17
17
|
|
|
18
18
|
## Initialization
|
|
19
19
|
|
|
20
|
-
To initialize the object, call the `EventItem(elementSelector, type, listener, options, detail)
|
|
20
|
+
To initialize the object, call the constructor `EventItem(elementSelector, type, listener, options, detail)`.
|
|
21
21
|
|
|
22
22
|
### Generic Constraints
|
|
23
23
|
|
|
24
24
|
To ensure strict typing, the class supports the following generics:
|
|
25
|
-
- `E extends ElementOrWindow` — The type of
|
|
26
|
-
- `O extends Event` — The event object
|
|
27
|
-
- `D extends Record<string, any>` — The structure
|
|
25
|
+
- `E extends ElementOrWindow` — The type of element on which events are listened.
|
|
26
|
+
- `O extends Event` — The type of the event object.
|
|
27
|
+
- `D extends Record<string, any>` — The structure of additional data.
|
|
28
28
|
|
|
29
29
|
**Parameters:**
|
|
30
|
-
- `elementSelector?: ElementOrString<E>` — the target element
|
|
31
|
-
- `type: string | string[] = 'click'` —
|
|
30
|
+
- `elementSelector?: ElementOrString<E>` — the target element on which the listener is attached.
|
|
31
|
+
- `type: string | string[] = 'click'` — event type, array of types, or special types (`'resize'`, `'scroll-sync'`).
|
|
32
32
|
- `listener?: EventListenerDetail<O, D>` — the event handler function.
|
|
33
33
|
- `options?: EventOptions` — standard `addEventListener` options.
|
|
34
34
|
- `detail?: D` — custom data that will be available in the handler.
|
|
@@ -36,7 +36,7 @@ To ensure strict typing, the class supports the following generics:
|
|
|
36
36
|
```typescript
|
|
37
37
|
import { EventItem } from '@dxtmisha/functional-basic'
|
|
38
38
|
|
|
39
|
-
// 1.
|
|
39
|
+
// 1. Basic initialization
|
|
40
40
|
const myEvent = new EventItem(
|
|
41
41
|
'.my-button',
|
|
42
42
|
'click',
|
|
@@ -49,13 +49,13 @@ const customEvent = new EventItem<Window, MouseEvent, MyData>(
|
|
|
49
49
|
window,
|
|
50
50
|
'mousedown',
|
|
51
51
|
(event, detail) => {
|
|
52
|
-
console.log('Window
|
|
52
|
+
console.log('Window click, data ID:', detail?.id)
|
|
53
53
|
},
|
|
54
54
|
{ passive: true },
|
|
55
55
|
{ id: 42 }
|
|
56
56
|
)
|
|
57
57
|
|
|
58
|
-
// 3. Activating
|
|
58
|
+
// 3. Activating listening
|
|
59
59
|
myEvent.start()
|
|
60
60
|
customEvent.start()
|
|
61
61
|
```
|
|
@@ -72,27 +72,48 @@ customEvent.start()
|
|
|
72
72
|
All methods in this group support chaining and automatically call `reset()` if the event is active.
|
|
73
73
|
|
|
74
74
|
- `setElement(elementSelector?: ElementOrString): this` — Changes the target element.
|
|
75
|
-
- `setElementControl(elementSelector?: ElementOrString): this` — Sets
|
|
75
|
+
- `setElementControl(elementSelector?: ElementOrString): this` — Sets the control element (if it is not in the DOM, the event will not fire).
|
|
76
76
|
- `setType(type: string | string[]): this` — Changes the event type.
|
|
77
|
-
- `setListener(listener: Function): this` — Changes the
|
|
78
|
-
- `setOptions(options?: EventOptions): this` — Changes the listener
|
|
79
|
-
- `setDetail(detail?: D): this` — Changes the custom
|
|
77
|
+
- `setListener(listener: Function): this` — Changes the handler function.
|
|
78
|
+
- `setOptions(options?: EventOptions): this` — Changes the listener parameters.
|
|
79
|
+
- `setDetail(detail?: D): this` — Changes the custom event data.
|
|
80
80
|
|
|
81
|
-
###
|
|
81
|
+
### Management
|
|
82
82
|
|
|
83
|
-
- `start(): this` — Starts listening
|
|
84
|
-
- `stop(): this` — Stops listening
|
|
85
|
-
- `toggle(activity: boolean): this` — Enables or disables listening
|
|
83
|
+
- `start(): this` — Starts event listening.
|
|
84
|
+
- `stop(): this` — Stops event listening.
|
|
85
|
+
- `toggle(activity: boolean): this` — Enables or disables listening depending on the flag.
|
|
86
86
|
- `reset(): this` — Restarts the event (useful after changing settings).
|
|
87
|
-
- `dispatch(detail?: D): this` — Triggers the event on the target element with data
|
|
87
|
+
- `dispatch(detail?: D): this` — Triggers the event on the target element with data transfer.
|
|
88
|
+
|
|
89
|
+
## Types
|
|
90
|
+
|
|
91
|
+
#### `ElementOrWindow`
|
|
92
|
+
Element on which an event can be attached: `HTMLElement | Window`.
|
|
93
|
+
|
|
94
|
+
#### `ElementOrString<E>`
|
|
95
|
+
Type for passing an element or its selector: `E | string`.
|
|
96
|
+
|
|
97
|
+
#### `EventListenerDetail<O, D>`
|
|
98
|
+
Event listener function: `(event: O, detail?: D) => void`.
|
|
99
|
+
|
|
100
|
+
#### `EventOptions`
|
|
101
|
+
Listening options: `AddEventListenerOptions | boolean | undefined`.
|
|
102
|
+
|
|
103
|
+
#### `EventActivityItem<E>`
|
|
104
|
+
Internal interface for tracking active listeners.
|
|
105
|
+
- `element: E | undefined` — Target element.
|
|
106
|
+
- `type: string` — Event type.
|
|
107
|
+
- `listener?: (event: any) => void` — Active function.
|
|
108
|
+
- `observer?: ResizeObserver` — Observer instance (for `resize`).
|
|
88
109
|
|
|
89
110
|
## Special Events
|
|
90
111
|
|
|
91
112
|
### `resize`
|
|
92
|
-
If the event type is set to `resize`, the class automatically uses `ResizeObserver` to track
|
|
113
|
+
If the event type is set to `resize`, the class automatically uses `ResizeObserver` to track changes in the size of the element (even if it is not `window`).
|
|
93
114
|
|
|
94
115
|
### `scroll-sync`
|
|
95
|
-
A special type for optimized scrolling.
|
|
116
|
+
A special type for optimized scrolling. Internally uses `requestAnimationFrame`, preventing unnecessary handler calls and increasing performance.
|
|
96
117
|
|
|
97
118
|
## Examples
|
|
98
119
|
|
|
@@ -104,7 +125,7 @@ const tracker = new EventItem('.item-1', 'mousemove', (e) => {
|
|
|
104
125
|
|
|
105
126
|
tracker.start()
|
|
106
127
|
|
|
107
|
-
// ...
|
|
128
|
+
// ... switch to another element later
|
|
108
129
|
tracker.setElement('.item-2')
|
|
109
130
|
```
|
|
110
131
|
|
|
@@ -86,6 +86,27 @@ customEvent.start()
|
|
|
86
86
|
- `reset(): this` — Перезапускает событие (полезно после смены настроек).
|
|
87
87
|
- `dispatch(detail?: D): this` — Вызывает событие на целевом элементе с передачей данных.
|
|
88
88
|
|
|
89
|
+
## Типы
|
|
90
|
+
|
|
91
|
+
#### `ElementOrWindow`
|
|
92
|
+
Элемент, на котором может висеть событие: `HTMLElement | Window`.
|
|
93
|
+
|
|
94
|
+
#### `ElementOrString<E>`
|
|
95
|
+
Тип для передачи элемента или его селектора: `E | string`.
|
|
96
|
+
|
|
97
|
+
#### `EventListenerDetail<O, D>`
|
|
98
|
+
Функция-обработчик события: `(event: O, detail?: D) => void`.
|
|
99
|
+
|
|
100
|
+
#### `EventOptions`
|
|
101
|
+
Опции прослушивания: `AddEventListenerOptions | boolean | undefined`.
|
|
102
|
+
|
|
103
|
+
#### `EventActivityItem<E>`
|
|
104
|
+
Внутренний интерфейс для отслеживания активных слушателей.
|
|
105
|
+
- `element: E | undefined` — Целевой элемент.
|
|
106
|
+
- `type: string` — Тип события.
|
|
107
|
+
- `listener?: (event: any) => void` — Активная функция.
|
|
108
|
+
- `observer?: ResizeObserver` — Инстанс наблюдателя (для `resize`).
|
|
109
|
+
|
|
89
110
|
## Специальные события
|
|
90
111
|
|
|
91
112
|
### `resize`
|
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
import {Meta} from '@storybook/addon-docs/blocks'
|
|
2
2
|
|
|
3
|
-
<Meta title='@dxtmisha/vi/functional-basic/Classes/EventItem - Quản lý
|
|
3
|
+
<Meta title='@dxtmisha/vi/functional-basic/Classes/EventItem - Quản lý sự kiện nâng cao'/>
|
|
4
4
|
|
|
5
5
|
# Lớp EventItem
|
|
6
6
|
|
|
7
|
-
Một
|
|
7
|
+
Một vỏ bọc mạnh mẽ để quản lý các trình lắng nghe sự kiện trên các phần tử DOM hoặc đối tượng `window`. Lớp này đơn giản hóa việc làm việc với vòng đời sự kiện (thêm, xóa, chuyển đổi), hỗ trợ tự động kiểm tra sự hiện diện của phần tử trong DOM và cung cấp tối ưu hóa tích hợp cho các sự kiện nặng như `resize` và `scroll`.
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Các tính năng chính
|
|
10
10
|
|
|
11
|
-
- **Quản lý vòng đời** — các phương thức `start`, `stop`, `toggle` và `reset` tiện
|
|
12
|
-
- **An toàn DOM** — tự động kiểm tra `isInDom` trước khi thực
|
|
13
|
-
- **Hỗ trợ ResizeObserver** — xử lý tích hợp sự kiện `resize` cho bất kỳ phần tử HTML nào
|
|
14
|
-
- **Tối ưu hóa cuộn** —
|
|
15
|
-
- **
|
|
16
|
-
- **Dữ liệu tùy chỉnh** — khả năng truyền và
|
|
11
|
+
- **Quản lý vòng đời** — các phương thức `start`, `stop`, `toggle` và `reset` thuận tiện để kiểm soát việc lắng nghe sự kiện.
|
|
12
|
+
- **An toàn DOM** — tự động kiểm tra `isInDom` trước khi thực thi trình xử lý (có thể cấu hình phần tử điều khiển).
|
|
13
|
+
- **Hỗ trợ ResizeObserver** — xử lý tích hợp sự kiện `resize` cho bất kỳ phần tử HTML nào thông qua API hiện đại.
|
|
14
|
+
- **Tối ưu hóa cuộn** — kiểu sự kiện `scroll-sync` đặc biệt sử dụng `requestAnimationFrame` cho hiệu suất cao.
|
|
15
|
+
- **Chaining và linh hoạt** — hỗ trợ nối chuỗi cuộc gọi và thay đổi động đích, kiểu hoặc trình xử lý sự kiện.
|
|
16
|
+
- **Dữ liệu tùy chỉnh** — khả năng truyền và điều phối dữ liệu tùy chỉnh thông qua `CustomEvent`.
|
|
17
17
|
|
|
18
18
|
## Khởi tạo
|
|
19
19
|
|
|
20
|
-
Để khởi tạo đối tượng, hãy gọi
|
|
20
|
+
Để khởi tạo đối tượng, hãy gọi constructor `EventItem(elementSelector, type, listener, options, detail)`.
|
|
21
21
|
|
|
22
|
-
###
|
|
22
|
+
### Các ràng buộc Generic (Generic Constraints)
|
|
23
23
|
|
|
24
|
-
Để đảm bảo
|
|
25
|
-
- `E extends ElementOrWindow` — Kiểu
|
|
26
|
-
- `O extends Event` — Kiểu đối tượng sự kiện.
|
|
27
|
-
- `D extends Record<string, any>` — Cấu trúc dữ liệu bổ sung.
|
|
24
|
+
Để đảm bảo kiểu nghiêm ngặt, lớp hỗ trợ các generic sau:
|
|
25
|
+
- `E extends ElementOrWindow` — Kiểu phần tử mà các sự kiện được lắng nghe.
|
|
26
|
+
- `O extends Event` — Kiểu của đối tượng sự kiện.
|
|
27
|
+
- `D extends Record<string, any>` — Cấu trúc của dữ liệu bổ sung.
|
|
28
28
|
|
|
29
29
|
**Tham số:**
|
|
30
|
-
- `elementSelector?: ElementOrString<E>` — phần tử đích
|
|
31
|
-
- `type: string | string[] = 'click'` —
|
|
30
|
+
- `elementSelector?: ElementOrString<E>` — phần tử đích mà trình lắng nghe được đính kèm.
|
|
31
|
+
- `type: string | string[] = 'click'` — kiểu sự kiện, mảng các kiểu hoặc các kiểu đặc biệt (`'resize'`, `'scroll-sync'`).
|
|
32
32
|
- `listener?: EventListenerDetail<O, D>` — hàm xử lý sự kiện.
|
|
33
33
|
- `options?: EventOptions` — các tùy chọn `addEventListener` tiêu chuẩn.
|
|
34
34
|
- `detail?: D` — dữ liệu tùy chỉnh sẽ có sẵn trong trình xử lý.
|
|
@@ -36,63 +36,84 @@ Một bộ khung (wrapper) mạnh mẽ để quản lý các trình lắng nghe
|
|
|
36
36
|
```typescript
|
|
37
37
|
import { EventItem } from '@dxtmisha/functional-basic'
|
|
38
38
|
|
|
39
|
-
// 1. Khởi tạo
|
|
39
|
+
// 1. Khởi tạo cơ bản
|
|
40
40
|
const myEvent = new EventItem(
|
|
41
41
|
'.my-button',
|
|
42
42
|
'click',
|
|
43
|
-
(event) => console.log('Sự kiện
|
|
43
|
+
(event) => console.log('Sự kiện đã kích hoạt:', event.type)
|
|
44
44
|
)
|
|
45
45
|
|
|
46
|
-
// 2. Sử dụng generic
|
|
46
|
+
// 2. Sử dụng generic cho kiểu nghiêm ngặt
|
|
47
47
|
interface MyData { id: number }
|
|
48
48
|
const customEvent = new EventItem<Window, MouseEvent, MyData>(
|
|
49
49
|
window,
|
|
50
50
|
'mousedown',
|
|
51
51
|
(event, detail) => {
|
|
52
|
-
console.log('
|
|
52
|
+
console.log('Nhấp vào cửa sổ, ID dữ liệu:', detail?.id)
|
|
53
53
|
},
|
|
54
54
|
{ passive: true },
|
|
55
55
|
{ id: 42 }
|
|
56
56
|
)
|
|
57
57
|
|
|
58
|
-
// 3. Kích hoạt
|
|
58
|
+
// 3. Kích hoạt lắng nghe
|
|
59
59
|
myEvent.start()
|
|
60
60
|
customEvent.start()
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
-
##
|
|
63
|
+
## Các phương thức
|
|
64
64
|
|
|
65
65
|
### Thông tin
|
|
66
66
|
|
|
67
|
-
- `isActive(): boolean` — Kiểm tra xem việc lắng nghe sự kiện có đang hoạt động hay không.
|
|
68
|
-
- `getElement(): E | undefined` — Trả về phần tử
|
|
67
|
+
- `isActive(): boolean` — Kiểm tra xem việc lắng nghe sự kiện hiện có đang hoạt động hay không.
|
|
68
|
+
- `getElement(): E | undefined` — Trả về phần tử đích hiện tại.
|
|
69
69
|
|
|
70
70
|
### Cấu hình (Setters)
|
|
71
71
|
|
|
72
|
-
Tất cả các phương thức trong nhóm này đều hỗ trợ chuỗi
|
|
72
|
+
Tất cả các phương thức trong nhóm này đều hỗ trợ nối chuỗi và tự động gọi `reset()` nếu sự kiện đang hoạt động.
|
|
73
73
|
|
|
74
|
-
- `setElement(elementSelector?: ElementOrString): this` — Thay đổi phần tử
|
|
75
|
-
- `setElementControl(elementSelector?: ElementOrString): this` — Thiết lập phần tử
|
|
76
|
-
- `setType(type: string | string[]): this` — Thay đổi
|
|
74
|
+
- `setElement(elementSelector?: ElementOrString): this` — Thay đổi phần tử đích.
|
|
75
|
+
- `setElementControl(elementSelector?: ElementOrString): this` — Thiết lập phần tử điều khiển (nếu nó không có trong DOM, sự kiện sẽ không kích hoạt).
|
|
76
|
+
- `setType(type: string | string[]): this` — Thay đổi kiểu sự kiện.
|
|
77
77
|
- `setListener(listener: Function): this` — Thay đổi hàm xử lý.
|
|
78
|
-
- `setOptions(options?: EventOptions): this` — Thay đổi các
|
|
79
|
-
- `setDetail(detail?: D): this` — Thay đổi dữ liệu tùy chỉnh
|
|
78
|
+
- `setOptions(options?: EventOptions): this` — Thay đổi các tham số trình lắng nghe.
|
|
79
|
+
- `setDetail(detail?: D): this` — Thay đổi dữ liệu sự kiện tùy chỉnh.
|
|
80
80
|
|
|
81
|
-
###
|
|
81
|
+
### Quản lý
|
|
82
82
|
|
|
83
|
-
- `start(): this` — Bắt đầu lắng nghe
|
|
84
|
-
- `stop(): this` — Dừng lắng nghe
|
|
85
|
-
- `toggle(activity: boolean): this` — Bật hoặc tắt
|
|
83
|
+
- `start(): this` — Bắt đầu lắng nghe sự kiện.
|
|
84
|
+
- `stop(): this` — Dừng lắng nghe sự kiện.
|
|
85
|
+
- `toggle(activity: boolean): this` — Bật hoặc tắt lắng nghe tùy thuộc vào cờ.
|
|
86
86
|
- `reset(): this` — Khởi động lại sự kiện (hữu ích sau khi thay đổi cài đặt).
|
|
87
|
-
- `dispatch(detail?: D): this` — Kích hoạt sự kiện trên phần tử
|
|
87
|
+
- `dispatch(detail?: D): this` — Kích hoạt sự kiện trên phần tử đích với việc truyền dữ liệu.
|
|
88
|
+
|
|
89
|
+
## Các kiểu dữ liệu
|
|
90
|
+
|
|
91
|
+
#### `ElementOrWindow`
|
|
92
|
+
Phần tử mà sự kiện có thể được đính kèm: `HTMLElement | Window`.
|
|
93
|
+
|
|
94
|
+
#### `ElementOrString<E>`
|
|
95
|
+
Kiểu để truyền một phần tử hoặc bộ chọn của nó: `E | string`.
|
|
96
|
+
|
|
97
|
+
#### `EventListenerDetail<O, D>`
|
|
98
|
+
Hàm lắng nghe sự kiện: `(event: O, detail?: D) => void`.
|
|
99
|
+
|
|
100
|
+
#### `EventOptions`
|
|
101
|
+
Các tùy chọn lắng nghe: `AddEventListenerOptions | boolean | undefined`.
|
|
102
|
+
|
|
103
|
+
#### `EventActivityItem<E>`
|
|
104
|
+
Giao diện nội bộ để theo dõi các trình lắng nghe đang hoạt động.
|
|
105
|
+
- `element: E | undefined` — Phần tử đích.
|
|
106
|
+
- `type: string` — Kiểu sự kiện.
|
|
107
|
+
- `listener?: (event: any) => void` — Hàm đang hoạt động.
|
|
108
|
+
- `observer?: ResizeObserver` — Thực thể observer (cho `resize`).
|
|
88
109
|
|
|
89
110
|
## Các sự kiện đặc biệt
|
|
90
111
|
|
|
91
112
|
### `resize`
|
|
92
|
-
Nếu
|
|
113
|
+
Nếu kiểu sự kiện được đặt thành `resize`, lớp sẽ tự động sử dụng `ResizeObserver` để theo dõi những thay đổi về kích thước của phần tử (ngay cả khi đó không phải là `window`).
|
|
93
114
|
|
|
94
115
|
### `scroll-sync`
|
|
95
|
-
Một
|
|
116
|
+
Một kiểu đặc biệt cho việc cuộn tối ưu hóa. Bên trong sử dụng `requestAnimationFrame`, ngăn chặn các cuộc gọi trình xử lý không cần thiết và tăng hiệu suất.
|
|
96
117
|
|
|
97
118
|
## Ví dụ
|
|
98
119
|
|
|
@@ -104,20 +125,20 @@ const tracker = new EventItem('.item-1', 'mousemove', (e) => {
|
|
|
104
125
|
|
|
105
126
|
tracker.start()
|
|
106
127
|
|
|
107
|
-
// ...
|
|
128
|
+
// ... chuyển sang phần tử khác sau đó
|
|
108
129
|
tracker.setElement('.item-2')
|
|
109
130
|
```
|
|
110
131
|
|
|
111
|
-
### Sử dụng CustomEvent với
|
|
132
|
+
### Sử dụng CustomEvent với dữ liệu
|
|
112
133
|
```javascript
|
|
113
134
|
const emitter = new EventItem(window, 'my-custom-event')
|
|
114
135
|
|
|
115
136
|
emitter.setListener((e, detail) => {
|
|
116
|
-
console.log('Dữ liệu nhận
|
|
137
|
+
console.log('Dữ liệu đã nhận:', e.detail) // dữ liệu từ CustomEvent
|
|
117
138
|
})
|
|
118
139
|
|
|
119
140
|
emitter.start()
|
|
120
141
|
|
|
121
|
-
//
|
|
142
|
+
// Điều phối sự kiện
|
|
122
143
|
emitter.dispatch({ userId: 123, action: 'refresh' })
|
|
123
144
|
```
|
|
@@ -4,34 +4,34 @@ import {Meta} from '@storybook/addon-docs/blocks'
|
|
|
4
4
|
|
|
5
5
|
# Formatters Class
|
|
6
6
|
|
|
7
|
-
A specialized class for formatting lists
|
|
7
|
+
A specialized class for formatting data lists based on a provided configuration. It serves as a bridge between raw data and localized, human-readable strings, utilizing the `GeoIntl` singleton for consistent formatting across different locales.
|
|
8
8
|
|
|
9
9
|
## Key Features
|
|
10
10
|
|
|
11
|
-
- **Declarative Configuration** — Define formatting rules once and apply them to
|
|
12
|
-
- **Support for Multiple Types** — Built-in support for
|
|
13
|
-
- **Custom Transformations** —
|
|
14
|
-
- **
|
|
15
|
-
- **Automatic Key Generation** — Automatically adds formatted values to items with
|
|
11
|
+
- **Declarative Configuration** — Define formatting rules once and apply them to the entire dataset.
|
|
12
|
+
- **Support for Multiple Types** — Built-in support for currencies, dates, names, numbers, plurals, and units.
|
|
13
|
+
- **Custom Transformations** — The ability to provide your own functions for unique formatting needs.
|
|
14
|
+
- **Typing** — Full TypeScript support for items, parameters, and resulting formatted lists.
|
|
15
|
+
- **Automatic Key Generation** — Automatically adds formatted values to items with the `Format` suffix (e.g., `price` becomes `priceFormat`).
|
|
16
16
|
|
|
17
17
|
## Initialization
|
|
18
18
|
|
|
19
|
-
To initialize the object, call the `Formatters(options, list)
|
|
19
|
+
To initialize the object, call the constructor `Formatters(options, list)`.
|
|
20
20
|
|
|
21
21
|
### Generic Constraints
|
|
22
22
|
|
|
23
|
-
- `Options extends FormattersOptionsList` — type of formatting
|
|
24
|
-
- `List extends
|
|
25
|
-
- `Item extends
|
|
23
|
+
- `Options extends FormattersOptionsList` — type of formatting parameters.
|
|
24
|
+
- `List extends FormattersListProp` — type of input data (array or single item).
|
|
25
|
+
- `Item extends FormattersItemProp<List>` — type of a single item in the list.
|
|
26
26
|
|
|
27
27
|
**Parameters:**
|
|
28
|
-
- `options: Options` — formatting
|
|
29
|
-
- `list?: List` — initial list
|
|
28
|
+
- `options: Options` — formatting parameters for each column/property.
|
|
29
|
+
- `list?: List` — initial data list for formatting.
|
|
30
30
|
|
|
31
31
|
```typescript
|
|
32
32
|
import { Formatters } from '@dxtmisha/functional-basic'
|
|
33
33
|
|
|
34
|
-
// 1.
|
|
34
|
+
// 1. Defining formatting parameters
|
|
35
35
|
const options = {
|
|
36
36
|
price: {
|
|
37
37
|
type: 'currency',
|
|
@@ -44,31 +44,17 @@ const options = {
|
|
|
44
44
|
user: {
|
|
45
45
|
type: 'name',
|
|
46
46
|
options: { lastPropName: 'surname', firstPropName: 'name' }
|
|
47
|
-
},
|
|
48
|
-
weight: {
|
|
49
|
-
type: 'unit',
|
|
50
|
-
options: { unit: 'kilogram' }
|
|
51
|
-
},
|
|
52
|
-
count: {
|
|
53
|
-
type: 'plural',
|
|
54
|
-
options: { words: 'apple|apples' }
|
|
55
|
-
},
|
|
56
|
-
status: {
|
|
57
|
-
transformation: (value: number) => value === 1 ? 'Active' : 'Inactive'
|
|
58
47
|
}
|
|
59
48
|
}
|
|
60
49
|
|
|
61
|
-
// 2.
|
|
50
|
+
// 2. Raw data
|
|
62
51
|
const data = [
|
|
63
52
|
{
|
|
64
53
|
price: 100,
|
|
65
54
|
currency: 'USD',
|
|
66
55
|
created: '2024-03-07T12:00:00',
|
|
67
56
|
name: 'John',
|
|
68
|
-
surname: 'Doe'
|
|
69
|
-
weight: 75,
|
|
70
|
-
count: 5,
|
|
71
|
-
status: 1
|
|
57
|
+
surname: 'Doe'
|
|
72
58
|
}
|
|
73
59
|
]
|
|
74
60
|
|
|
@@ -76,93 +62,95 @@ const data = [
|
|
|
76
62
|
const formatter = new Formatters(options, data)
|
|
77
63
|
```
|
|
78
64
|
|
|
79
|
-
##
|
|
65
|
+
## Methods
|
|
80
66
|
|
|
81
|
-
###
|
|
67
|
+
### Processing
|
|
68
|
+
- `to(): FormattersReturn<List, Options>` — Processes the data and returns the result. If the input was an array, returns a new array of enriched items. If it was a single item — a single object. Adds properties with the `Format` suffix.
|
|
82
69
|
|
|
83
|
-
|
|
70
|
+
### Configuration
|
|
71
|
+
- `setList(list?: List): this` — Updates the data for formatting. Supports chaining.
|
|
84
72
|
|
|
85
|
-
|
|
73
|
+
### Information
|
|
74
|
+
- `is(): boolean` — Checks if data is set for processing.
|
|
75
|
+
- `isArray(): boolean` — Whether the current data is an array.
|
|
76
|
+
- `length(): number` — Returns the count of records in the list.
|
|
77
|
+
- `getList(): FormattersList<Item>` — Returns the current list as an array.
|
|
78
|
+
- `getOptions(): Options` — Returns the current formatting configuration.
|
|
79
|
+
|
|
80
|
+
## Formatting Types and Parameters
|
|
81
|
+
|
|
82
|
+
The `FormattersOptionsList` configuration is a dictionary where keys correspond to property names in the data (dot notation `path.to.prop` is supported), and values are `FormattersOptionsItem` objects.
|
|
83
|
+
|
|
84
|
+
### General Structure of `FormattersOptionsItem`
|
|
85
|
+
- `type?: FormattersType` — Formatter type.
|
|
86
|
+
- `transformation?: (value, item, options) => string` — Custom transformation function.
|
|
87
|
+
- `options?: Options` — Parameter object, the structure of which depends on the selected `type`.
|
|
88
|
+
|
|
89
|
+
### Detailed Type Description
|
|
90
|
+
|
|
91
|
+
#### 1. Currency (`currency`)
|
|
92
|
+
Used for localized display of monetary values.
|
|
93
|
+
- `currencyPropName?: string` — Property name in the item from which the currency code is taken (default is `currency`).
|
|
94
|
+
- `options?: string | Intl.NumberFormatOptions` — You can pass a fixed code (e.g., `'USD'`) or an `Intl.NumberFormat` settings object.
|
|
95
|
+
- `numberOnly?: boolean` — If `true`, returns only the formatted number without the currency symbol.
|
|
96
|
+
|
|
97
|
+
#### 2. Date (`date`)
|
|
98
|
+
Formatting dates and times via `GeoIntl`.
|
|
99
|
+
- `type?: GeoDate` — Preset format:
|
|
100
|
+
- `full` — Full date and time.
|
|
101
|
+
- `datetime` — Date and time (without seconds).
|
|
102
|
+
- `date` — Date only.
|
|
103
|
+
- `time` — Time only.
|
|
104
|
+
- `year-month`, `year`, `month`, `day`, `day-month`, `hour-minute`.
|
|
105
|
+
- `options?: Intl.DateTimeFormatOptions` — Standard `Intl` parameters (e.g., `month: 'long'`).
|
|
106
|
+
- `hour24?: boolean` — If `true`, forces 24-hour mode.
|
|
107
|
+
|
|
108
|
+
#### 3. Name (`name`)
|
|
109
|
+
Combines full name parts in the correct order.
|
|
110
|
+
- `lastPropName?: string` — Field for the last name (default is `lastName`).
|
|
111
|
+
- `firstPropName?: string` — Field for the first name (default is `firstName`).
|
|
112
|
+
- `surname?: string` — Field for the middle name/surname (default is `surname`).
|
|
113
|
+
- `short?: boolean` — If `true`, outputs the last name and initials (e.g., "Doe J.").
|
|
114
|
+
|
|
115
|
+
#### 4. Number (`number`)
|
|
116
|
+
Standard number formatting with digit separation.
|
|
117
|
+
- `options?: Intl.NumberFormatOptions` — `Intl` parameters (number of decimal places, style, etc.).
|
|
118
|
+
|
|
119
|
+
#### 5. Plural (`plural`)
|
|
120
|
+
Choosing the correct word form depending on the number.
|
|
121
|
+
- `words: string` — Word forms via the `|` separator.
|
|
122
|
+
- For English: `"apple|apples"`.
|
|
123
|
+
- For Russian: `"яблоко|яблока|яблок"`.
|
|
124
|
+
- `options?: Intl.PluralRulesOptions` — Pluralization rule settings.
|
|
125
|
+
- `optionsNumber?: Intl.NumberFormatOptions` — Settings for formatting the number itself that is output before the word.
|
|
126
|
+
|
|
127
|
+
#### 6. Unit (`unit`)
|
|
128
|
+
Adding units of measurement (km, kg, l).
|
|
129
|
+
- `unit: string` — Unit of measurement code (e.g., `'kilometer'`, `'kilogram'`, `'liter'`).
|
|
130
|
+
- `options?: Intl.NumberFormatOptions` — Formatting parameters for the numeric part.
|
|
131
|
+
|
|
132
|
+
## Examples
|
|
133
|
+
|
|
134
|
+
### Using Dot Notation
|
|
135
|
+
```typescript
|
|
136
|
+
const options = {
|
|
137
|
+
'user.profile.age': { type: 'number' }
|
|
138
|
+
}
|
|
139
|
+
const data = { user: { profile: { age: 25 } } }
|
|
140
|
+
const formatter = new Formatters(options, data)
|
|
86
141
|
|
|
87
|
-
```javascript
|
|
88
142
|
const result = formatter.to()
|
|
89
|
-
|
|
90
|
-
Result (if array): [
|
|
91
|
-
{
|
|
92
|
-
id: 101,
|
|
93
|
-
price: 100,
|
|
94
|
-
currency: 'USD',
|
|
95
|
-
priceFormat: '$100.00',
|
|
96
|
-
status: 1,
|
|
97
|
-
statusFormat: 'Active',
|
|
98
|
-
...
|
|
99
|
-
}
|
|
100
|
-
]
|
|
101
|
-
|
|
102
|
-
Result (if single item): {
|
|
103
|
-
price: 100,
|
|
104
|
-
priceFormat: '$100.00',
|
|
105
|
-
...
|
|
106
|
-
}
|
|
107
|
-
*/
|
|
143
|
+
// result.userProfileAgeFormat === "25"
|
|
108
144
|
```
|
|
109
145
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
- `is(): boolean` — Checks if the list/item is set.
|
|
113
|
-
- `isArray(): boolean` — Checks if the current data is an array.
|
|
114
|
-
- `length(): number` — Returns the count of records in the list.
|
|
115
|
-
- `getList(): Item[]` — Returns the current list of data as an array.
|
|
116
|
-
- `getOptions(): Options` — Returns the current formatting configuration mapping.
|
|
117
|
-
- `setList(list?: List): this` — Updates the data and returns the instance for chaining.
|
|
118
|
-
|
|
119
|
-
## Configuration Structure
|
|
120
|
-
|
|
121
|
-
The configuration object passed to the constructor is a map where each key corresponds to a property name in your data. Each value must follow the `FormattersOptionsItem` structure.
|
|
122
|
-
|
|
123
|
-
### Main Item Structure
|
|
124
|
-
|
|
146
|
+
### Custom Transformation
|
|
125
147
|
```typescript
|
|
126
|
-
{
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
// 3. Or use a custom function (overrides type-specific logic)
|
|
134
|
-
transformation: (value, item, options) => string
|
|
148
|
+
const options = {
|
|
149
|
+
status: {
|
|
150
|
+
// Custom function takes precedence over type
|
|
151
|
+
transformation: (value, item) => {
|
|
152
|
+
return value === 'active' ? `✅ ${item.name} is online` : '❌ Offline'
|
|
153
|
+
}
|
|
154
|
+
}
|
|
135
155
|
}
|
|
136
156
|
```
|
|
137
|
-
|
|
138
|
-
## Specific Parameters
|
|
139
|
-
|
|
140
|
-
Below are the parameters available within the **`options`** property for each type.
|
|
141
|
-
|
|
142
|
-
### Currency (`currency`)
|
|
143
|
-
- `currencyPropName?: string` — Property in the item containing the currency code (defaults to `item.currency`).
|
|
144
|
-
- `options?: string | Intl.NumberFormatOptions` — Fixed currency code or full `Intl` options.
|
|
145
|
-
- `numberOnly?: boolean` — If `true`, returns only the formatted number without the symbol.
|
|
146
|
-
|
|
147
|
-
### Date (`date`)
|
|
148
|
-
- `type?: GeoDate` — Preset type: `full`, `datetime`, `date`, `year-month`, `year`, `month`, `day`, `day-month`, `time`, `hour-minute`, `hour`, `minute`, `second`.
|
|
149
|
-
- `options?: Intl.DateTimeFormatOptions['month'] | Intl.DateTimeFormatOptions` — Additional `Intl` date options or month style.
|
|
150
|
-
- `hour24?: boolean` — Forces 24-hour format if `true`.
|
|
151
|
-
|
|
152
|
-
### Name (`name`)
|
|
153
|
-
- `lastPropName?: string` — Field for last name (default: `lastName`).
|
|
154
|
-
- `firstPropName?: string` — Field for first name (default: `firstName`).
|
|
155
|
-
- `surname?: string` — Field for surname (default: `surname`).
|
|
156
|
-
- `short?: boolean` — Whether to use short format (initials).
|
|
157
|
-
|
|
158
|
-
### Number (`number`)
|
|
159
|
-
- `options?: Intl.NumberFormatOptions` — Standard `Intl` number options.
|
|
160
|
-
|
|
161
|
-
### Plural (`plural`)
|
|
162
|
-
- `words: string` — Word forms separated by `|` (e.g., `"apple|apples"`).
|
|
163
|
-
- `options?: Intl.PluralRulesOptions` — Plural rule settings.
|
|
164
|
-
- `optionsNumber?: Intl.NumberFormatOptions` — Formatting for the number itself.
|
|
165
|
-
|
|
166
|
-
### Unit (`unit`)
|
|
167
|
-
- `unit: string | Intl.NumberFormatOptions` — The unit to display (e.g., `'kilometer'`, `'kilogram'`).
|
|
168
|
-
|