selective-ui 1.2.3 → 1.2.5
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/selective-ui.css.map +1 -1
- package/dist/selective-ui.esm.js +5462 -1043
- package/dist/selective-ui.esm.js.map +1 -1
- package/dist/selective-ui.esm.min.js +2 -2
- package/dist/selective-ui.esm.min.js.br +0 -0
- package/dist/selective-ui.min.js +2 -2
- package/dist/selective-ui.min.js.br +0 -0
- package/dist/selective-ui.umd.js +5463 -1044
- package/dist/selective-ui.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/ts/adapter/mixed-adapter.ts +312 -65
- package/src/ts/components/accessorybox.ts +248 -28
- package/src/ts/components/directive.ts +91 -11
- package/src/ts/components/option-handle.ts +191 -28
- package/src/ts/components/placeholder.ts +111 -16
- package/src/ts/components/popup/empty-state.ts +162 -0
- package/src/ts/components/popup/loading-state.ts +160 -0
- package/src/ts/components/{popup.ts → popup/popup.ts} +167 -71
- package/src/ts/components/searchbox.ts +225 -20
- package/src/ts/components/selectbox.ts +498 -120
- package/src/ts/core/base/adapter.ts +200 -53
- package/src/ts/core/base/fenwick.ts +147 -0
- package/src/ts/core/base/lifecycle.ts +258 -0
- package/src/ts/core/base/model.ts +120 -31
- package/src/ts/core/base/recyclerview.ts +55 -18
- package/src/ts/core/base/view.ts +87 -19
- package/src/ts/core/base/virtual-recyclerview.ts +475 -202
- package/src/ts/core/model-manager.ts +166 -85
- package/src/ts/core/search-controller.ts +236 -38
- package/src/ts/global.ts +6 -6
- package/src/ts/index.ts +6 -6
- package/src/ts/models/group-model.ts +159 -32
- package/src/ts/models/option-model.ts +213 -54
- package/src/ts/services/dataset-observer.ts +72 -10
- package/src/ts/services/ea-observer.ts +92 -15
- package/src/ts/services/effector.ts +181 -32
- package/src/ts/services/refresher.ts +30 -6
- package/src/ts/services/resize-observer.ts +132 -15
- package/src/ts/services/select-observer.ts +115 -50
- package/src/ts/types/components/searchbox.type.ts +1 -1
- package/src/ts/types/core/base/adapter.type.ts +2 -1
- package/src/ts/types/core/base/lifecycle.type.ts +62 -0
- package/src/ts/types/core/base/model.type.ts +3 -1
- package/src/ts/types/core/base/recyclerview.type.ts +2 -8
- package/src/ts/types/core/base/view.type.ts +36 -24
- package/src/ts/types/utils/ievents.type.ts +6 -1
- package/src/ts/utils/callback-scheduler.ts +112 -34
- package/src/ts/utils/ievents.ts +91 -29
- package/src/ts/utils/istorage.ts +1 -1
- package/src/ts/utils/selective.ts +474 -88
- package/src/ts/views/group-view.ts +170 -21
- package/src/ts/views/option-view.ts +349 -68
- package/src/ts/components/empty-state.ts +0 -68
- package/src/ts/components/loading-state.ts +0 -66
- /package/src/css/components/{empty-state.css → popup/empty-state.css} +0 -0
- /package/src/css/components/{loading-state.css → popup/loading-state.css} +0 -0
- /package/src/css/components/{popup.css → popup/popup.css} +0 -0
- /package/src/css/{components/optgroup.css → views/group-view.css} +0 -0
- /package/src/css/{components/option.css → views/option-view.css} +0 -0
package/src/ts/core/base/view.ts
CHANGED
|
@@ -1,43 +1,111 @@
|
|
|
1
1
|
import { MountViewResult } from "src/ts/types/utils/libs.type";
|
|
2
2
|
import type { ViewContract } from "../../types/core/base/view.type";
|
|
3
|
+
import { Lifecycle } from "./lifecycle";
|
|
4
|
+
import { LifecycleState } from "src/ts/types/core/base/lifecycle.type";
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
|
-
*
|
|
7
|
+
* Base View primitive that anchors a mounted DOM structure into a parent container.
|
|
8
|
+
*
|
|
9
|
+
* This class is the **View** part of the library's Model/View separation:
|
|
10
|
+
* - A View is responsible for owning/manipulating DOM nodes and exposing typed handles (`tags`)
|
|
11
|
+
* for efficient updates.
|
|
12
|
+
* - A View is typically created/managed by an Adapter/RecyclerView layer and assigned back to a Model.
|
|
13
|
+
*
|
|
14
|
+
* ### Responsibility
|
|
15
|
+
* - Hold a reference to the host container (`parent`) where the view's root element is attached.
|
|
16
|
+
* - Store the mounted structure (`view`) produced by a mount utility (root element + typed tag map).
|
|
17
|
+
* - Provide a safe root accessor ({@link getView}) for downstream code (e.g., scrolling, a11y, styling).
|
|
18
|
+
*
|
|
19
|
+
* ### Lifecycle (Strict FSM)
|
|
20
|
+
* - Constructor calls {@link Lifecycle.init} immediately (`NEW → INITIALIZED`).
|
|
21
|
+
* - Mounting is performed by subclasses / infrastructure:
|
|
22
|
+
* - populate {@link view} (usually during a subclass mount hook),
|
|
23
|
+
* - append `view.view` to {@link parent},
|
|
24
|
+
* - then transition to `MOUNTED` via {@link Lifecycle.mount} (typically done by the base/framework).
|
|
25
|
+
* - {@link destroy} transitions to `DESTROYED` and removes the root element from the DOM.
|
|
26
|
+
*
|
|
27
|
+
* ### Idempotency / No-ops
|
|
28
|
+
* - {@link destroy} is idempotent once in {@link LifecycleState.DESTROYED}.
|
|
29
|
+
* - {@link getView} throws if the view is not yet mounted (i.e., {@link view} is unset).
|
|
30
|
+
*
|
|
31
|
+
* ### DOM side effects / Ownership
|
|
32
|
+
* - Owns the root element produced by the mount helper and removes it on {@link destroy}.
|
|
33
|
+
* - Does not automatically append the root node; external orchestrators (Adapter/RecyclerView) control attachment.
|
|
34
|
+
*
|
|
35
|
+
* @template TTags - Map of tag names to their corresponding HTMLElement instances.
|
|
6
36
|
* @implements {ViewContract<TTags>}
|
|
37
|
+
* @extends Lifecycle
|
|
38
|
+
* @see {@link MountViewResult}
|
|
39
|
+
* @see {@link ViewContract}
|
|
40
|
+
* @see {@link LifecycleState}
|
|
7
41
|
*/
|
|
8
|
-
export class View<TTags extends Record<string, HTMLElement>> implements ViewContract<TTags> {
|
|
42
|
+
export class View<TTags extends Record<string, HTMLElement>> extends Lifecycle implements ViewContract<TTags> {
|
|
43
|
+
/**
|
|
44
|
+
* Host container element into which this view's root element is rendered/attached.
|
|
45
|
+
*
|
|
46
|
+
* This reference is captured at construction time and cleared on {@link destroy}.
|
|
47
|
+
*/
|
|
9
48
|
public parent: HTMLElement | null = null;
|
|
10
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Mounted view result containing:
|
|
52
|
+
* - `view`: the root element of this view
|
|
53
|
+
* - `tags`: a strongly-typed map of child elements for fast access
|
|
54
|
+
*
|
|
55
|
+
* This is expected to be assigned by subclasses (or a mount helper) before {@link getView} is called.
|
|
56
|
+
*/
|
|
11
57
|
public view: MountViewResult<TTags> | null = null;
|
|
12
58
|
|
|
13
59
|
/**
|
|
14
|
-
*
|
|
60
|
+
* Creates a View bound to the specified parent container and initializes lifecycle state.
|
|
15
61
|
*
|
|
16
|
-
*
|
|
62
|
+
* Notes:
|
|
63
|
+
* - This base constructor **does not** perform DOM mounting or attachment.
|
|
64
|
+
* - Subclasses typically assign {@link view} during their mount step, then append `view.view` to {@link parent}.
|
|
65
|
+
*
|
|
66
|
+
* @param {HTMLElement} parent - Host element into which this view will render.
|
|
17
67
|
*/
|
|
18
68
|
public constructor(parent: HTMLElement) {
|
|
69
|
+
super();
|
|
19
70
|
this.parent = parent;
|
|
71
|
+
this.init();
|
|
20
72
|
}
|
|
21
73
|
|
|
22
|
-
/**
|
|
23
|
-
* Renders the view into the parent container.
|
|
24
|
-
* Override in subclasses to create DOM structure and mount tags.
|
|
25
|
-
*/
|
|
26
|
-
public render(): void { }
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Updates the view to reflect model or state changes.
|
|
30
|
-
* Override in subclasses to patch DOM nodes without full re-render.
|
|
31
|
-
*/
|
|
32
|
-
public update(): void { }
|
|
33
|
-
|
|
34
74
|
/**
|
|
35
75
|
* Returns the root HTMLElement of the mounted view.
|
|
36
76
|
*
|
|
37
|
-
* @returns {HTMLElement}
|
|
77
|
+
* @returns {HTMLElement} The root element produced by the mounting helper.
|
|
78
|
+
* @throws {Error} If {@link view} is not set or the view has not been mounted yet.
|
|
38
79
|
*/
|
|
39
80
|
public getView(): HTMLElement {
|
|
40
|
-
if (!this.view?.view)
|
|
81
|
+
if (!this.view?.view) {
|
|
82
|
+
throw new Error("View is not mounted. Did you forget to set this.view?");
|
|
83
|
+
}
|
|
41
84
|
return this.view.view;
|
|
42
85
|
}
|
|
43
|
-
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Destroys the view and releases DOM references.
|
|
89
|
+
*
|
|
90
|
+
* Behavior:
|
|
91
|
+
* - Idempotent: returns early if already in {@link LifecycleState.DESTROYED}.
|
|
92
|
+
* - Removes the root element from the DOM (if present).
|
|
93
|
+
* - Clears references to {@link parent} and {@link view}.
|
|
94
|
+
* - Completes teardown by calling {@link Lifecycle.destroy}.
|
|
95
|
+
*
|
|
96
|
+
* @returns {void}
|
|
97
|
+
* @override
|
|
98
|
+
*/
|
|
99
|
+
public override destroy(): void {
|
|
100
|
+
if (this.is(LifecycleState.DESTROYED)) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
this.getView()?.remove?.();
|
|
105
|
+
|
|
106
|
+
this.parent = null;
|
|
107
|
+
this.view = null;
|
|
108
|
+
|
|
109
|
+
super.destroy();
|
|
110
|
+
}
|
|
111
|
+
}
|