mvc-kit 2.12.4 → 2.13.0
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/agent-config/bin/postinstall.mjs +4 -3
- package/agent-config/bin/setup.mjs +5 -1
- package/agent-config/claude-code/agents/mvc-kit-architect.md +11 -8
- package/agent-config/claude-code/skills/guide/SKILL.md +20 -7
- package/agent-config/claude-code/skills/guide/patterns.md +12 -0
- package/agent-config/claude-code/skills/guide/recipes.md +510 -0
- package/agent-config/claude-code/skills/guide/testing.md +297 -0
- package/agent-config/claude-code/skills/review/SKILL.md +3 -13
- package/agent-config/claude-code/skills/review/checklist.md +30 -5
- package/agent-config/claude-code/skills/scaffold/SKILL.md +4 -13
- package/agent-config/lib/install-claude.mjs +84 -25
- package/dist/Channel.cjs +276 -300
- package/dist/Channel.cjs.map +1 -1
- package/dist/Channel.js +275 -299
- package/dist/Channel.js.map +1 -1
- package/dist/Collection.cjs +424 -504
- package/dist/Collection.cjs.map +1 -1
- package/dist/Collection.js +423 -503
- package/dist/Collection.js.map +1 -1
- package/dist/Controller.cjs +70 -67
- package/dist/Controller.cjs.map +1 -1
- package/dist/Controller.js +69 -66
- package/dist/Controller.js.map +1 -1
- package/dist/EventBus.cjs +77 -88
- package/dist/EventBus.cjs.map +1 -1
- package/dist/EventBus.js +76 -87
- package/dist/EventBus.js.map +1 -1
- package/dist/Feed.cjs +81 -77
- package/dist/Feed.cjs.map +1 -1
- package/dist/Feed.js +80 -76
- package/dist/Feed.js.map +1 -1
- package/dist/Model.cjs +181 -207
- package/dist/Model.cjs.map +1 -1
- package/dist/Model.js +179 -205
- package/dist/Model.js.map +1 -1
- package/dist/Pagination.cjs +75 -73
- package/dist/Pagination.cjs.map +1 -1
- package/dist/Pagination.js +74 -72
- package/dist/Pagination.js.map +1 -1
- package/dist/Pending.cjs +255 -287
- package/dist/Pending.cjs.map +1 -1
- package/dist/Pending.js +253 -285
- package/dist/Pending.js.map +1 -1
- package/dist/PersistentCollection.cjs +242 -285
- package/dist/PersistentCollection.cjs.map +1 -1
- package/dist/PersistentCollection.js +241 -284
- package/dist/PersistentCollection.js.map +1 -1
- package/dist/Resource.cjs +166 -174
- package/dist/Resource.cjs.map +1 -1
- package/dist/Resource.js +164 -172
- package/dist/Resource.js.map +1 -1
- package/dist/Selection.cjs +84 -94
- package/dist/Selection.cjs.map +1 -1
- package/dist/Selection.js +83 -93
- package/dist/Selection.js.map +1 -1
- package/dist/Service.cjs +54 -55
- package/dist/Service.cjs.map +1 -1
- package/dist/Service.js +53 -54
- package/dist/Service.js.map +1 -1
- package/dist/Sorting.cjs +102 -101
- package/dist/Sorting.cjs.map +1 -1
- package/dist/Sorting.js +102 -101
- package/dist/Sorting.js.map +1 -1
- package/dist/Trackable.cjs +112 -80
- package/dist/Trackable.cjs.map +1 -1
- package/dist/Trackable.js +111 -79
- package/dist/Trackable.js.map +1 -1
- package/dist/ViewModel.cjs +528 -576
- package/dist/ViewModel.cjs.map +1 -1
- package/dist/ViewModel.js +525 -573
- package/dist/ViewModel.js.map +1 -1
- package/dist/bindPublicMethods.cjs +43 -24
- package/dist/bindPublicMethods.cjs.map +1 -1
- package/dist/bindPublicMethods.js +43 -24
- package/dist/bindPublicMethods.js.map +1 -1
- package/dist/errors.cjs +67 -68
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.js +68 -71
- package/dist/errors.js.map +1 -1
- package/dist/mvc-kit.cjs +44 -46
- package/dist/mvc-kit.js +5 -32
- package/dist/produceDraft.cjs +105 -95
- package/dist/produceDraft.cjs.map +1 -1
- package/dist/produceDraft.js +106 -97
- package/dist/produceDraft.js.map +1 -1
- package/dist/react/components/CardList.cjs +30 -40
- package/dist/react/components/CardList.cjs.map +1 -1
- package/dist/react/components/CardList.js +31 -41
- package/dist/react/components/CardList.js.map +1 -1
- package/dist/react/components/DataTable.cjs +146 -169
- package/dist/react/components/DataTable.cjs.map +1 -1
- package/dist/react/components/DataTable.js +147 -170
- package/dist/react/components/DataTable.js.map +1 -1
- package/dist/react/components/InfiniteScroll.cjs +51 -42
- package/dist/react/components/InfiniteScroll.cjs.map +1 -1
- package/dist/react/components/InfiniteScroll.js +52 -43
- package/dist/react/components/InfiniteScroll.js.map +1 -1
- package/dist/react/components/types.cjs +10 -6
- package/dist/react/components/types.cjs.map +1 -1
- package/dist/react/components/types.js +11 -9
- package/dist/react/components/types.js.map +1 -1
- package/dist/react/guards.cjs +10 -6
- package/dist/react/guards.cjs.map +1 -1
- package/dist/react/guards.js +11 -9
- package/dist/react/guards.js.map +1 -1
- package/dist/react/provider.cjs +23 -20
- package/dist/react/provider.cjs.map +1 -1
- package/dist/react/provider.js +23 -21
- package/dist/react/provider.js.map +1 -1
- package/dist/react/use-event-bus.cjs +24 -20
- package/dist/react/use-event-bus.cjs.map +1 -1
- package/dist/react/use-event-bus.js +24 -21
- package/dist/react/use-event-bus.js.map +1 -1
- package/dist/react/use-instance.cjs +43 -36
- package/dist/react/use-instance.cjs.map +1 -1
- package/dist/react/use-instance.js +43 -36
- package/dist/react/use-instance.js.map +1 -1
- package/dist/react/use-local.cjs +48 -64
- package/dist/react/use-local.cjs.map +1 -1
- package/dist/react/use-local.js +47 -63
- package/dist/react/use-local.js.map +1 -1
- package/dist/react/use-model.cjs +84 -98
- package/dist/react/use-model.cjs.map +1 -1
- package/dist/react/use-model.js +84 -100
- package/dist/react/use-model.js.map +1 -1
- package/dist/react/use-singleton.cjs +19 -23
- package/dist/react/use-singleton.cjs.map +1 -1
- package/dist/react/use-singleton.js +16 -20
- package/dist/react/use-singleton.js.map +1 -1
- package/dist/react/use-subscribe-only.cjs +28 -22
- package/dist/react/use-subscribe-only.cjs.map +1 -1
- package/dist/react/use-subscribe-only.js +28 -22
- package/dist/react/use-subscribe-only.js.map +1 -1
- package/dist/react/use-teardown.cjs +20 -19
- package/dist/react/use-teardown.cjs.map +1 -1
- package/dist/react/use-teardown.js +20 -19
- package/dist/react/use-teardown.js.map +1 -1
- package/dist/react-native/NativeCollection.cjs +98 -78
- package/dist/react-native/NativeCollection.cjs.map +1 -1
- package/dist/react-native/NativeCollection.js +97 -77
- package/dist/react-native/NativeCollection.js.map +1 -1
- package/dist/react-native.cjs +2 -4
- package/dist/react-native.js +1 -4
- package/dist/react.cjs +24 -26
- package/dist/react.js +1 -17
- package/dist/singleton.cjs +28 -22
- package/dist/singleton.cjs.map +1 -1
- package/dist/singleton.js +29 -26
- package/dist/singleton.js.map +1 -1
- package/dist/walkPrototypeChain.cjs +20 -12
- package/dist/walkPrototypeChain.cjs.map +1 -1
- package/dist/walkPrototypeChain.js +21 -13
- package/dist/walkPrototypeChain.js.map +1 -1
- package/dist/web/IndexedDBCollection.cjs +53 -36
- package/dist/web/IndexedDBCollection.cjs.map +1 -1
- package/dist/web/IndexedDBCollection.js +52 -35
- package/dist/web/IndexedDBCollection.js.map +1 -1
- package/dist/web/WebStorageCollection.cjs +82 -84
- package/dist/web/WebStorageCollection.cjs.map +1 -1
- package/dist/web/WebStorageCollection.js +81 -83
- package/dist/web/WebStorageCollection.js.map +1 -1
- package/dist/web/idb.cjs +107 -99
- package/dist/web/idb.cjs.map +1 -1
- package/dist/web/idb.js +108 -105
- package/dist/web/idb.js.map +1 -1
- package/dist/web.cjs +4 -6
- package/dist/web.js +1 -5
- package/dist/wrapAsyncMethods.cjs +141 -168
- package/dist/wrapAsyncMethods.cjs.map +1 -1
- package/dist/wrapAsyncMethods.js +141 -168
- package/dist/wrapAsyncMethods.js.map +1 -1
- package/package.json +8 -8
- package/src/Pending.test.ts +1 -2
- package/src/Sorting.test.ts +1 -1
- package/src/produceDraft.test.ts +3 -3
- package/src/react/components/CardList.test.tsx +1 -1
- package/src/react/components/DataTable.test.tsx +1 -1
- package/src/react/components/InfiniteScroll.test.tsx +5 -5
- package/dist/mvc-kit.cjs.map +0 -1
- package/dist/mvc-kit.js.map +0 -1
- package/dist/react-native.cjs.map +0 -1
- package/dist/react-native.js.map +0 -1
- package/dist/react.cjs.map +0 -1
- package/dist/react.js.map +0 -1
- package/dist/web.cjs.map +0 -1
- package/dist/web.js.map +0 -1
package/dist/Resource.js
CHANGED
|
@@ -1,175 +1,167 @@
|
|
|
1
|
-
import { Collection } from "./Collection.js";
|
|
2
1
|
import { walkPrototypeChain } from "./walkPrototypeChain.js";
|
|
3
2
|
import { wrapAsyncMethods } from "./wrapAsyncMethods.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
if (RESERVED_ASYNC_KEYS.includes(key)) {
|
|
165
|
-
throw new Error(
|
|
166
|
-
`[mvc-kit] "${key}" is a reserved property on Resource and cannot be overridden.`
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
export {
|
|
173
|
-
Resource
|
|
3
|
+
import { Collection } from "./Collection.js";
|
|
4
|
+
//#region src/Resource.ts
|
|
5
|
+
var __DEV__ = typeof __MVC_KIT_DEV__ !== "undefined" && __MVC_KIT_DEV__;
|
|
6
|
+
var DEFAULT_TASK_STATE = Object.freeze({
|
|
7
|
+
loading: false,
|
|
8
|
+
error: null,
|
|
9
|
+
errorCode: null
|
|
10
|
+
});
|
|
11
|
+
var RESERVED_ASYNC_KEYS = ["async", "subscribeAsync"];
|
|
12
|
+
var LIFECYCLE_HOOKS = new Set(["onInit", "onDispose"]);
|
|
13
|
+
/**
|
|
14
|
+
* Collection + async tracking toolkit. Extends Collection with lifecycle
|
|
15
|
+
* (init/dispose) and automatic async method tracking. Optionally delegates
|
|
16
|
+
* to an external Collection for shared data scenarios.
|
|
17
|
+
*/
|
|
18
|
+
var Resource = class Resource extends Collection {
|
|
19
|
+
_external = null;
|
|
20
|
+
_initialized = false;
|
|
21
|
+
_asyncStates = /* @__PURE__ */ new Map();
|
|
22
|
+
_asyncSnapshots = /* @__PURE__ */ new Map();
|
|
23
|
+
_asyncListeners = /* @__PURE__ */ new Set();
|
|
24
|
+
_asyncProxy = null;
|
|
25
|
+
_activeOps = null;
|
|
26
|
+
/** DEV-only timeout (ms) for detecting ghost async operations after dispose. */
|
|
27
|
+
static GHOST_TIMEOUT = 3e3;
|
|
28
|
+
constructor(collectionOrItems) {
|
|
29
|
+
const isExternal = collectionOrItems != null && !Array.isArray(collectionOrItems);
|
|
30
|
+
super(isExternal ? [] : collectionOrItems ?? []);
|
|
31
|
+
if (isExternal) {
|
|
32
|
+
this._external = collectionOrItems;
|
|
33
|
+
if (__DEV__) {
|
|
34
|
+
const Ctor = this.constructor;
|
|
35
|
+
if (Ctor.MAX_SIZE > 0 || Ctor.TTL > 0) console.warn(`[mvc-kit] Resource "${Ctor.name}" has MAX_SIZE or TTL set but uses an injected Collection. Configure these on the Collection instead.`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
this._guardReservedKeys();
|
|
39
|
+
}
|
|
40
|
+
/** Whether init() has been called. */
|
|
41
|
+
get initialized() {
|
|
42
|
+
return this._initialized;
|
|
43
|
+
}
|
|
44
|
+
/** Initializes the instance. Called automatically by React hooks after mount. */
|
|
45
|
+
init() {
|
|
46
|
+
if (this._initialized || this.disposed) return;
|
|
47
|
+
this._initialized = true;
|
|
48
|
+
if (__DEV__) this._activeOps = /* @__PURE__ */ new Map();
|
|
49
|
+
wrapAsyncMethods({
|
|
50
|
+
instance: this,
|
|
51
|
+
stopPrototype: Resource.prototype,
|
|
52
|
+
reservedKeys: RESERVED_ASYNC_KEYS,
|
|
53
|
+
lifecycleHooks: LIFECYCLE_HOOKS,
|
|
54
|
+
isDisposed: () => this.disposed,
|
|
55
|
+
isInitialized: () => this._initialized,
|
|
56
|
+
asyncStates: this._asyncStates,
|
|
57
|
+
asyncSnapshots: this._asyncSnapshots,
|
|
58
|
+
asyncListeners: this._asyncListeners,
|
|
59
|
+
notifyAsync: () => this._notifyAsync(),
|
|
60
|
+
addCleanup: (fn) => this.addCleanup(fn),
|
|
61
|
+
ghostTimeout: this.constructor.GHOST_TIMEOUT,
|
|
62
|
+
className: "Resource",
|
|
63
|
+
activeOps: this._activeOps
|
|
64
|
+
});
|
|
65
|
+
return this.onInit?.();
|
|
66
|
+
}
|
|
67
|
+
/** Current items array. Delegates to external Collection when injected. */
|
|
68
|
+
get state() {
|
|
69
|
+
return this._external ? this._external.state : super.state;
|
|
70
|
+
}
|
|
71
|
+
/** The raw array of items. Delegates to external Collection when injected. */
|
|
72
|
+
get items() {
|
|
73
|
+
return this._external ? this._external.items : super.items;
|
|
74
|
+
}
|
|
75
|
+
/** Number of items. Delegates to external Collection when injected. */
|
|
76
|
+
get length() {
|
|
77
|
+
return this._external ? this._external.length : super.length;
|
|
78
|
+
}
|
|
79
|
+
add(...items) {
|
|
80
|
+
this._external ? this._external.add(...items) : super.add(...items);
|
|
81
|
+
}
|
|
82
|
+
upsert(...items) {
|
|
83
|
+
this._external ? this._external.upsert(...items) : super.upsert(...items);
|
|
84
|
+
}
|
|
85
|
+
update(id, changes) {
|
|
86
|
+
this._external ? this._external.update(id, changes) : super.update(id, changes);
|
|
87
|
+
}
|
|
88
|
+
remove(...ids) {
|
|
89
|
+
this._external ? this._external.remove(...ids) : super.remove(...ids);
|
|
90
|
+
}
|
|
91
|
+
reset(items) {
|
|
92
|
+
this._external ? this._external.reset(items) : super.reset(items);
|
|
93
|
+
}
|
|
94
|
+
clear() {
|
|
95
|
+
this._external ? this._external.clear() : super.clear();
|
|
96
|
+
}
|
|
97
|
+
optimistic(callback) {
|
|
98
|
+
return this._external ? this._external.optimistic(callback) : super.optimistic(callback);
|
|
99
|
+
}
|
|
100
|
+
get(id) {
|
|
101
|
+
return this._external ? this._external.get(id) : super.get(id);
|
|
102
|
+
}
|
|
103
|
+
has(id) {
|
|
104
|
+
return this._external ? this._external.has(id) : super.has(id);
|
|
105
|
+
}
|
|
106
|
+
find(predicate) {
|
|
107
|
+
return this._external ? this._external.find(predicate) : super.find(predicate);
|
|
108
|
+
}
|
|
109
|
+
filter(predicate) {
|
|
110
|
+
return this._external ? this._external.filter(predicate) : super.filter(predicate);
|
|
111
|
+
}
|
|
112
|
+
sorted(compareFn) {
|
|
113
|
+
return this._external ? this._external.sorted(compareFn) : super.sorted(compareFn);
|
|
114
|
+
}
|
|
115
|
+
map(fn) {
|
|
116
|
+
return this._external ? this._external.map(fn) : super.map(fn);
|
|
117
|
+
}
|
|
118
|
+
subscribe(listener) {
|
|
119
|
+
if (this.disposed) return () => {};
|
|
120
|
+
return this._external ? this._external.subscribe(listener) : super.subscribe(listener);
|
|
121
|
+
}
|
|
122
|
+
/** Proxy providing `TaskState` (loading, error, errorCode) per async method. */
|
|
123
|
+
get async() {
|
|
124
|
+
if (!this._asyncProxy) {
|
|
125
|
+
const self = this;
|
|
126
|
+
this._asyncProxy = new Proxy({}, {
|
|
127
|
+
get(_, prop) {
|
|
128
|
+
return self._asyncSnapshots.get(prop) ?? DEFAULT_TASK_STATE;
|
|
129
|
+
},
|
|
130
|
+
has(_, prop) {
|
|
131
|
+
return self._asyncSnapshots.has(prop);
|
|
132
|
+
},
|
|
133
|
+
ownKeys() {
|
|
134
|
+
return Array.from(self._asyncSnapshots.keys());
|
|
135
|
+
},
|
|
136
|
+
getOwnPropertyDescriptor(_, prop) {
|
|
137
|
+
if (self._asyncSnapshots.has(prop)) return {
|
|
138
|
+
configurable: true,
|
|
139
|
+
enumerable: true,
|
|
140
|
+
value: self._asyncSnapshots.get(prop)
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return this._asyncProxy;
|
|
146
|
+
}
|
|
147
|
+
/** Subscribes to async state changes. Used by `useInstance` for React integration. */
|
|
148
|
+
subscribeAsync(listener) {
|
|
149
|
+
if (this.disposed) return () => {};
|
|
150
|
+
this._asyncListeners.add(listener);
|
|
151
|
+
return () => {
|
|
152
|
+
this._asyncListeners.delete(listener);
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
_notifyAsync() {
|
|
156
|
+
for (const listener of this._asyncListeners) listener();
|
|
157
|
+
}
|
|
158
|
+
_guardReservedKeys() {
|
|
159
|
+
walkPrototypeChain(this, Resource.prototype, (key) => {
|
|
160
|
+
if (RESERVED_ASYNC_KEYS.includes(key)) throw new Error(`[mvc-kit] "${key}" is a reserved property on Resource and cannot be overridden.`);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
174
163
|
};
|
|
175
|
-
//#
|
|
164
|
+
//#endregion
|
|
165
|
+
export { Resource };
|
|
166
|
+
|
|
167
|
+
//# sourceMappingURL=Resource.js.map
|
package/dist/Resource.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Resource.js","sources":["../src/Resource.ts"],"sourcesContent":["import { Collection } from './Collection';\nimport { walkPrototypeChain } from './walkPrototypeChain';\nimport { wrapAsyncMethods } from './wrapAsyncMethods';\nimport type { InternalTaskState } from './wrapAsyncMethods';\nimport type { Listener, TaskState } from './types';\n\nconst __DEV__ = typeof __MVC_KIT_DEV__ !== 'undefined' && __MVC_KIT_DEV__;\n\n// ── Async tracking types ────────────────────────────────────────\n\nconst DEFAULT_TASK_STATE: TaskState = Object.freeze({ loading: false, error: null, errorCode: null });\n\nexport type ResourceAsyncMethodKeys<T> = {\n [K in Exclude<keyof T, keyof Resource<any>>]: T[K] extends (...args: any[]) => Promise<any> ? K : never;\n}[Exclude<keyof T, keyof Resource<any>>];\n\ntype ResourceAsyncMap<T> = {\n readonly [K in ResourceAsyncMethodKeys<T>]: TaskState;\n};\n\nconst RESERVED_ASYNC_KEYS = ['async', 'subscribeAsync'] as const;\nconst LIFECYCLE_HOOKS = new Set(['onInit', 'onDispose']);\n\n// ── Resource ────────────────────────────────────────────────────\n\n/**\n * Collection + async tracking toolkit. Extends Collection with lifecycle\n * (init/dispose) and automatic async method tracking. Optionally delegates\n * to an external Collection for shared data scenarios.\n */\nexport class Resource<T extends { id: string | number }> extends Collection<T> {\n private _external: Collection<T> | null = null;\n private _initialized = false;\n\n // ── Async tracking fields ──\n private _asyncStates = new Map<string, InternalTaskState>();\n private _asyncSnapshots = new Map<string, TaskState>();\n private _asyncListeners = new Set<() => void>();\n private _asyncProxy: ResourceAsyncMap<this> | null = null;\n private _activeOps: Map<string, number> | null = null;\n\n /** DEV-only timeout (ms) for detecting ghost async operations after dispose. */\n static GHOST_TIMEOUT = 3000;\n\n constructor(collectionOrItems?: Collection<T> | T[]) {\n const isExternal = collectionOrItems != null && !Array.isArray(collectionOrItems);\n super(isExternal ? [] : (collectionOrItems as T[]) ?? []);\n\n if (isExternal) {\n this._external = collectionOrItems as Collection<T>;\n\n if (__DEV__) {\n const Ctor = this.constructor as typeof Resource;\n if (Ctor.MAX_SIZE > 0 || Ctor.TTL > 0) {\n console.warn(\n `[mvc-kit] Resource \"${Ctor.name}\" has MAX_SIZE or TTL set but uses an ` +\n `injected Collection. Configure these on the Collection instead.`\n );\n }\n }\n }\n\n this._guardReservedKeys();\n }\n\n // ── Lifecycle ─────────────────────────────────────────────────\n\n /** Whether init() has been called. */\n get initialized(): boolean {\n return this._initialized;\n }\n\n /** Initializes the instance. Called automatically by React hooks after mount. */\n init(): void | Promise<void> {\n if (this._initialized || this.disposed) return;\n this._initialized = true;\n\n if (__DEV__) {\n this._activeOps = new Map();\n }\n\n wrapAsyncMethods({\n instance: this,\n stopPrototype: Resource.prototype,\n reservedKeys: RESERVED_ASYNC_KEYS,\n lifecycleHooks: LIFECYCLE_HOOKS,\n isDisposed: () => this.disposed,\n isInitialized: () => this._initialized,\n asyncStates: this._asyncStates,\n asyncSnapshots: this._asyncSnapshots,\n asyncListeners: this._asyncListeners,\n notifyAsync: () => this._notifyAsync(),\n addCleanup: (fn) => this.addCleanup(fn),\n ghostTimeout: (this.constructor as typeof Resource).GHOST_TIMEOUT,\n className: 'Resource',\n activeOps: this._activeOps,\n });\n\n return this.onInit?.();\n }\n\n /** Lifecycle hook called at the end of init(). Override to load initial data. @protected */\n protected onInit?(): void | Promise<void>;\n\n // ── Collection delegation ─────────────────────────────────────\n\n /** Current items array. Delegates to external Collection when injected. */\n get state(): T[] {\n return this._external ? this._external.state : super.state;\n }\n\n /** The raw array of items. Delegates to external Collection when injected. */\n get items(): T[] {\n return this._external ? this._external.items : super.items;\n }\n\n /** Number of items. Delegates to external Collection when injected. */\n get length(): number {\n return this._external ? this._external.length : super.length;\n }\n\n add(...items: T[]): void {\n this._external ? this._external.add(...items) : super.add(...items);\n }\n\n upsert(...items: T[]): void {\n this._external ? this._external.upsert(...items) : super.upsert(...items);\n }\n\n update(id: T['id'], changes: Partial<T>): void {\n this._external ? this._external.update(id, changes) : super.update(id, changes);\n }\n\n remove(...ids: T['id'][]): void {\n this._external ? this._external.remove(...ids) : super.remove(...ids);\n }\n\n reset(items: T[]): void {\n this._external ? this._external.reset(items) : super.reset(items);\n }\n\n clear(): void {\n this._external ? this._external.clear() : super.clear();\n }\n\n optimistic(callback: () => void): () => void {\n return this._external ? this._external.optimistic(callback) : super.optimistic(callback);\n }\n\n get(id: T['id']): T | undefined {\n return this._external ? this._external.get(id) : super.get(id);\n }\n\n has(id: T['id']): boolean {\n return this._external ? this._external.has(id) : super.has(id);\n }\n\n find(predicate: (item: T) => boolean): T | undefined {\n return this._external ? this._external.find(predicate) : super.find(predicate);\n }\n\n filter(predicate: (item: T) => boolean): T[] {\n return this._external ? this._external.filter(predicate) : super.filter(predicate);\n }\n\n sorted(compareFn: (a: T, b: T) => number): T[] {\n return this._external ? this._external.sorted(compareFn) : super.sorted(compareFn);\n }\n\n map<U>(fn: (item: T) => U): U[] {\n return this._external ? this._external.map(fn) : super.map(fn);\n }\n\n subscribe(listener: Listener<T[]>): () => void {\n if (this.disposed) return () => {};\n return this._external ? this._external.subscribe(listener) : super.subscribe(listener);\n }\n\n // ── Async tracking API ────────────────────────────────────────\n\n /** Proxy providing `TaskState` (loading, error, errorCode) per async method. */\n get async(): ResourceAsyncMap<this> {\n if (!this._asyncProxy) {\n const self = this;\n this._asyncProxy = new Proxy({} as ResourceAsyncMap<this>, {\n get(_, prop: string) {\n return self._asyncSnapshots.get(prop) ?? DEFAULT_TASK_STATE;\n },\n has(_, prop: string) {\n return self._asyncSnapshots.has(prop);\n },\n ownKeys() {\n return Array.from(self._asyncSnapshots.keys());\n },\n getOwnPropertyDescriptor(_, prop: string) {\n if (self._asyncSnapshots.has(prop)) {\n return { configurable: true, enumerable: true, value: self._asyncSnapshots.get(prop) };\n }\n return undefined;\n },\n });\n }\n return this._asyncProxy;\n }\n\n /** Subscribes to async state changes. Used by `useInstance` for React integration. */\n subscribeAsync(listener: () => void): () => void {\n if (this.disposed) return () => {};\n this._asyncListeners.add(listener);\n return () => { this._asyncListeners.delete(listener); };\n }\n\n // ── Private: async tracking internals ─────────────────────────\n\n private _notifyAsync(): void {\n for (const listener of this._asyncListeners) {\n listener();\n }\n }\n\n private _guardReservedKeys(): void {\n walkPrototypeChain(this, Resource.prototype, (key) => {\n if (RESERVED_ASYNC_KEYS.includes(key as any)) {\n throw new Error(\n `[mvc-kit] \"${key}\" is a reserved property on Resource and cannot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;AACR,iBAAO,MAAM,KAAK,KAAK,gBAAgB,MAAM;AAAA,QAC/C;AAAA,QACA,yBAAyB,GAAG,MAAc;AACxC,cAAI,KAAK,gBAAgB,IAAI,IAAI,GAAG;AAClC,mBAAO,EAAE,cAAc,MAAM,YAAY,MAAM,OAAO,KAAK,gBAAgB,IAAI,IAAI,EAAA;AAAA,UACrF;AACA,iBAAO;AAAA,QACT;AAAA,MAAA,CACD;AAAA,IACH;AACA,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,eAAe,UAAkC;AAC/C,QAAI,KAAK,SAAU,QAAO,MAAM;AAAA,IAAC;AACjC,SAAK,gBAAgB,IAAI,QAAQ;AACjC,WAAO,MAAM;AAAE,WAAK,gBAAgB,OAAO,QAAQ;AAAA,IAAG;AAAA,EACxD;AAAA;AAAA,EAIQ,eAAqB;AAC3B,eAAW,YAAY,KAAK,iBAAiB;AAC3C,eAAA;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,qBAA2B;AACjC,uBAAmB,MAAM,SAAS,WAAW,CAAC,QAAQ;AACpD,UAAI,oBAAoB,SAAS,GAAU,GAAG;AAC5C,cAAM,IAAI;AAAA,UACR,cAAc,GAAG;AAAA,QAAA;AAAA,MAErB;AAAA,IACF,CAAC;AAAA,EACH;AAEF;"}
|
|
1
|
+
{"version":3,"file":"Resource.js","names":[],"sources":["../src/Resource.ts"],"sourcesContent":["import { Collection } from './Collection';\nimport { walkPrototypeChain } from './walkPrototypeChain';\nimport { wrapAsyncMethods } from './wrapAsyncMethods';\nimport type { InternalTaskState } from './wrapAsyncMethods';\nimport type { Listener, TaskState } from './types';\n\nconst __DEV__ = typeof __MVC_KIT_DEV__ !== 'undefined' && __MVC_KIT_DEV__;\n\n// ── Async tracking types ────────────────────────────────────────\n\nconst DEFAULT_TASK_STATE: TaskState = Object.freeze({ loading: false, error: null, errorCode: null });\n\nexport type ResourceAsyncMethodKeys<T> = {\n [K in Exclude<keyof T, keyof Resource<any>>]: T[K] extends (...args: any[]) => Promise<any> ? K : never;\n}[Exclude<keyof T, keyof Resource<any>>];\n\ntype ResourceAsyncMap<T> = {\n readonly [K in ResourceAsyncMethodKeys<T>]: TaskState;\n};\n\nconst RESERVED_ASYNC_KEYS = ['async', 'subscribeAsync'] as const;\nconst LIFECYCLE_HOOKS = new Set(['onInit', 'onDispose']);\n\n// ── Resource ────────────────────────────────────────────────────\n\n/**\n * Collection + async tracking toolkit. Extends Collection with lifecycle\n * (init/dispose) and automatic async method tracking. Optionally delegates\n * to an external Collection for shared data scenarios.\n */\nexport class Resource<T extends { id: string | number }> extends Collection<T> {\n private _external: Collection<T> | null = null;\n private _initialized = false;\n\n // ── Async tracking fields ──\n private _asyncStates = new Map<string, InternalTaskState>();\n private _asyncSnapshots = new Map<string, TaskState>();\n private _asyncListeners = new Set<() => void>();\n private _asyncProxy: ResourceAsyncMap<this> | null = null;\n private _activeOps: Map<string, number> | null = null;\n\n /** DEV-only timeout (ms) for detecting ghost async operations after dispose. */\n static GHOST_TIMEOUT = 3000;\n\n constructor(collectionOrItems?: Collection<T> | T[]) {\n const isExternal = collectionOrItems != null && !Array.isArray(collectionOrItems);\n super(isExternal ? [] : (collectionOrItems as T[]) ?? []);\n\n if (isExternal) {\n this._external = collectionOrItems as Collection<T>;\n\n if (__DEV__) {\n const Ctor = this.constructor as typeof Resource;\n if (Ctor.MAX_SIZE > 0 || Ctor.TTL > 0) {\n console.warn(\n `[mvc-kit] Resource \"${Ctor.name}\" has MAX_SIZE or TTL set but uses an ` +\n `injected Collection. Configure these on the Collection instead.`\n );\n }\n }\n }\n\n this._guardReservedKeys();\n }\n\n // ── Lifecycle ─────────────────────────────────────────────────\n\n /** Whether init() has been called. */\n get initialized(): boolean {\n return this._initialized;\n }\n\n /** Initializes the instance. Called automatically by React hooks after mount. */\n init(): void | Promise<void> {\n if (this._initialized || this.disposed) return;\n this._initialized = true;\n\n if (__DEV__) {\n this._activeOps = new Map();\n }\n\n wrapAsyncMethods({\n instance: this,\n stopPrototype: Resource.prototype,\n reservedKeys: RESERVED_ASYNC_KEYS,\n lifecycleHooks: LIFECYCLE_HOOKS,\n isDisposed: () => this.disposed,\n isInitialized: () => this._initialized,\n asyncStates: this._asyncStates,\n asyncSnapshots: this._asyncSnapshots,\n asyncListeners: this._asyncListeners,\n notifyAsync: () => this._notifyAsync(),\n addCleanup: (fn) => this.addCleanup(fn),\n ghostTimeout: (this.constructor as typeof Resource).GHOST_TIMEOUT,\n className: 'Resource',\n activeOps: this._activeOps,\n });\n\n return this.onInit?.();\n }\n\n /** Lifecycle hook called at the end of init(). Override to load initial data. @protected */\n protected onInit?(): void | Promise<void>;\n\n // ── Collection delegation ─────────────────────────────────────\n\n /** Current items array. Delegates to external Collection when injected. */\n get state(): T[] {\n return this._external ? this._external.state : super.state;\n }\n\n /** The raw array of items. Delegates to external Collection when injected. */\n get items(): T[] {\n return this._external ? this._external.items : super.items;\n }\n\n /** Number of items. Delegates to external Collection when injected. */\n get length(): number {\n return this._external ? this._external.length : super.length;\n }\n\n add(...items: T[]): void {\n this._external ? this._external.add(...items) : super.add(...items);\n }\n\n upsert(...items: T[]): void {\n this._external ? this._external.upsert(...items) : super.upsert(...items);\n }\n\n update(id: T['id'], changes: Partial<T>): void {\n this._external ? this._external.update(id, changes) : super.update(id, changes);\n }\n\n remove(...ids: T['id'][]): void {\n this._external ? this._external.remove(...ids) : super.remove(...ids);\n }\n\n reset(items: T[]): void {\n this._external ? this._external.reset(items) : super.reset(items);\n }\n\n clear(): void {\n this._external ? this._external.clear() : super.clear();\n }\n\n optimistic(callback: () => void): () => void {\n return this._external ? this._external.optimistic(callback) : super.optimistic(callback);\n }\n\n get(id: T['id']): T | undefined {\n return this._external ? this._external.get(id) : super.get(id);\n }\n\n has(id: T['id']): boolean {\n return this._external ? this._external.has(id) : super.has(id);\n }\n\n find(predicate: (item: T) => boolean): T | undefined {\n return this._external ? this._external.find(predicate) : super.find(predicate);\n }\n\n filter(predicate: (item: T) => boolean): T[] {\n return this._external ? this._external.filter(predicate) : super.filter(predicate);\n }\n\n sorted(compareFn: (a: T, b: T) => number): T[] {\n return this._external ? this._external.sorted(compareFn) : super.sorted(compareFn);\n }\n\n map<U>(fn: (item: T) => U): U[] {\n return this._external ? this._external.map(fn) : super.map(fn);\n }\n\n subscribe(listener: Listener<T[]>): () => void {\n if (this.disposed) return () => {};\n return this._external ? this._external.subscribe(listener) : super.subscribe(listener);\n }\n\n // ── Async tracking API ────────────────────────────────────────\n\n /** Proxy providing `TaskState` (loading, error, errorCode) per async method. */\n get async(): ResourceAsyncMap<this> {\n if (!this._asyncProxy) {\n const self = this;\n this._asyncProxy = new Proxy({} as ResourceAsyncMap<this>, {\n get(_, prop: string) {\n return self._asyncSnapshots.get(prop) ?? DEFAULT_TASK_STATE;\n },\n has(_, prop: string) {\n return self._asyncSnapshots.has(prop);\n },\n ownKeys() {\n return Array.from(self._asyncSnapshots.keys());\n },\n getOwnPropertyDescriptor(_, prop: string) {\n if (self._asyncSnapshots.has(prop)) {\n return { configurable: true, enumerable: true, value: self._asyncSnapshots.get(prop) };\n }\n return undefined;\n },\n });\n }\n return this._asyncProxy;\n }\n\n /** Subscribes to async state changes. Used by `useInstance` for React integration. */\n subscribeAsync(listener: () => void): () => void {\n if (this.disposed) return () => {};\n this._asyncListeners.add(listener);\n return () => { this._asyncListeners.delete(listener); };\n }\n\n // ── Private: async tracking internals ─────────────────────────\n\n private _notifyAsync(): void {\n for (const listener of this._asyncListeners) {\n listener();\n }\n }\n\n private _guardReservedKeys(): void {\n walkPrototypeChain(this, Resource.prototype, (key) => {\n if (RESERVED_ASYNC_KEYS.includes(key as any)) {\n throw new Error(\n `[mvc-kit] \"${key}\" is a reserved property on Resource and cannot be overridden.`\n );\n }\n });\n }\n\n}\n"],"mappings":";;;;AAMA,IAAM,UAAU,OAAO,oBAAoB,eAAe;AAI1D,IAAM,qBAAgC,OAAO,OAAO;CAAE,SAAS;CAAO,OAAO;CAAM,WAAW;CAAM,CAAC;AAUrG,IAA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-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
// ── Utility ──
|
|
84
|
-
/** Filter an array to only items whose key is in the selection. */
|
|
85
|
-
selectedFrom(items, keyOf) {
|
|
86
|
-
return items.filter((item) => this._selected.has(keyOf(item)));
|
|
87
|
-
}
|
|
88
|
-
// ── Internal ──
|
|
89
|
-
_publish() {
|
|
90
|
-
this._readonlyView = new Set(this._selected);
|
|
91
|
-
this.notify();
|
|
92
|
-
}
|
|
93
|
-
}
|
|
1
|
+
const require_Trackable = require("./Trackable.cjs");
|
|
2
|
+
//#region src/Selection.ts
|
|
3
|
+
/**
|
|
4
|
+
* Key-based selection set with toggle and select-all support.
|
|
5
|
+
* Tracks which items are selected by their key (id).
|
|
6
|
+
* Subscribable — auto-tracked when used as a ViewModel property.
|
|
7
|
+
*/
|
|
8
|
+
var Selection = class extends require_Trackable.Trackable {
|
|
9
|
+
_selected = /* @__PURE__ */ new Set();
|
|
10
|
+
_readonlyView = this._selected;
|
|
11
|
+
constructor() {
|
|
12
|
+
super();
|
|
13
|
+
}
|
|
14
|
+
/** Read-only view of currently selected keys. */
|
|
15
|
+
get selected() {
|
|
16
|
+
return this._readonlyView;
|
|
17
|
+
}
|
|
18
|
+
/** Number of currently selected items. */
|
|
19
|
+
get count() {
|
|
20
|
+
return this._selected.size;
|
|
21
|
+
}
|
|
22
|
+
/** Whether any items are currently selected. */
|
|
23
|
+
get hasSelection() {
|
|
24
|
+
return this._selected.size > 0;
|
|
25
|
+
}
|
|
26
|
+
/** Check whether a specific key is selected. */
|
|
27
|
+
isSelected(key) {
|
|
28
|
+
return this._selected.has(key);
|
|
29
|
+
}
|
|
30
|
+
/** Toggle a key's selection state (select if unselected, deselect if selected). */
|
|
31
|
+
toggle(key) {
|
|
32
|
+
if (this._selected.has(key)) this._selected.delete(key);
|
|
33
|
+
else this._selected.add(key);
|
|
34
|
+
this._publish();
|
|
35
|
+
}
|
|
36
|
+
/** Add one or more keys to the selection. */
|
|
37
|
+
select(...keys) {
|
|
38
|
+
let changed = false;
|
|
39
|
+
for (const key of keys) if (!this._selected.has(key)) {
|
|
40
|
+
this._selected.add(key);
|
|
41
|
+
changed = true;
|
|
42
|
+
}
|
|
43
|
+
if (changed) this._publish();
|
|
44
|
+
}
|
|
45
|
+
/** Remove one or more keys from the selection. */
|
|
46
|
+
deselect(...keys) {
|
|
47
|
+
let changed = false;
|
|
48
|
+
for (const key of keys) if (this._selected.has(key)) {
|
|
49
|
+
this._selected.delete(key);
|
|
50
|
+
changed = true;
|
|
51
|
+
}
|
|
52
|
+
if (changed) this._publish();
|
|
53
|
+
}
|
|
54
|
+
/** If all selected → deselect all, else select all. */
|
|
55
|
+
toggleAll(allKeys) {
|
|
56
|
+
if (allKeys.length > 0 && allKeys.every((k) => this._selected.has(k))) this._selected.clear();
|
|
57
|
+
else for (const key of allKeys) this._selected.add(key);
|
|
58
|
+
this._publish();
|
|
59
|
+
}
|
|
60
|
+
/** Replace the entire selection atomically. Single notification. */
|
|
61
|
+
set(...keys) {
|
|
62
|
+
if (keys.length === this._selected.size && keys.every((k) => this._selected.has(k))) return;
|
|
63
|
+
this._selected.clear();
|
|
64
|
+
for (const key of keys) this._selected.add(key);
|
|
65
|
+
this._publish();
|
|
66
|
+
}
|
|
67
|
+
/** Remove all items from the selection. */
|
|
68
|
+
clear() {
|
|
69
|
+
if (this._selected.size === 0) return;
|
|
70
|
+
this._selected.clear();
|
|
71
|
+
this._publish();
|
|
72
|
+
}
|
|
73
|
+
/** Filter an array to only items whose key is in the selection. */
|
|
74
|
+
selectedFrom(items, keyOf) {
|
|
75
|
+
return items.filter((item) => this._selected.has(keyOf(item)));
|
|
76
|
+
}
|
|
77
|
+
_publish() {
|
|
78
|
+
this._readonlyView = new Set(this._selected);
|
|
79
|
+
this.notify();
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
//#endregion
|
|
94
83
|
exports.Selection = Selection;
|
|
95
|
-
|
|
84
|
+
|
|
85
|
+
//# sourceMappingURL=Selection.cjs.map
|
package/dist/Selection.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Selection.cjs","sources":["../src/Selection.ts"],"sourcesContent":["import { Trackable } from './Trackable';\n\n/**\n * Key-based selection set with toggle and select-all support.\n * Tracks which items are selected by their key (id).\n * Subscribable — auto-tracked when used as a ViewModel property.\n */\nexport class Selection<K extends string | number = string | number> extends Trackable {\n private _selected: Set<K> = new Set();\n private _readonlyView: ReadonlySet<K> = this._selected;\n\n constructor() {\n super();\n }\n\n // ── Readable state ──\n\n /** Read-only view of currently selected keys. */\n get selected(): ReadonlySet<K> {\n return this._readonlyView;\n }\n\n /** Number of currently selected items. */\n get count(): number {\n return this._selected.size;\n }\n\n /** Whether any items are currently selected. */\n get hasSelection(): boolean {\n return this._selected.size > 0;\n }\n\n // ── Query ──\n\n /** Check whether a specific key is selected. */\n isSelected(key: K): boolean {\n return this._selected.has(key);\n }\n\n // ── Actions ──\n\n /** Toggle a key's selection state (select if unselected, deselect if selected). */\n toggle(key: K): void {\n if (this._selected.has(key)) {\n this._selected.delete(key);\n } else {\n this._selected.add(key);\n }\n this._publish();\n }\n\n /** Add one or more keys to the selection. */\n select(...keys: K[]): void {\n let changed = false;\n for (const key of keys) {\n if (!this._selected.has(key)) {\n this._selected.add(key);\n changed = true;\n }\n }\n if (changed) this._publish();\n }\n\n /** Remove one or more keys from the selection. */\n deselect(...keys: K[]): void {\n let changed = false;\n for (const key of keys) {\n if (this._selected.has(key)) {\n this._selected.delete(key);\n changed = true;\n }\n }\n if (changed) this._publish();\n }\n\n /** If all selected → deselect all, else select all. */\n toggleAll(allKeys: K[]): void {\n const allSelected = allKeys.length > 0 && allKeys.every(k => this._selected.has(k));\n if (allSelected) {\n this._selected.clear();\n } else {\n for (const key of allKeys) this._selected.add(key);\n }\n this._publish();\n }\n\n /** Replace the entire selection atomically. Single notification. */\n set(...keys: K[]): void {\n // Check if anything actually changed\n if (keys.length === this._selected.size && keys.every(k => this._selected.has(k))) return;\n this._selected.clear();\n for (const key of keys) this._selected.add(key);\n this._publish();\n }\n\n /** Remove all items from the selection. */\n clear(): void {\n if (this._selected.size === 0) return;\n this._selected.clear();\n this._publish();\n }\n\n // ── Utility ──\n\n /** Filter an array to only items whose key is in the selection. */\n selectedFrom<T>(items: T[], keyOf: (item: T) => K): T[] {\n return items.filter(item => this._selected.has(keyOf(item)));\n }\n\n // ── Internal ──\n\n private _publish(): void {\n // Replace readonlyView so reference equality changes (needed for React)\n this._readonlyView = new Set(this._selected);\n this.notify();\n }\n}\n"],"
|
|
1
|
+
{"version":3,"file":"Selection.cjs","names":[],"sources":["../src/Selection.ts"],"sourcesContent":["import { Trackable } from './Trackable';\n\n/**\n * Key-based selection set with toggle and select-all support.\n * Tracks which items are selected by their key (id).\n * Subscribable — auto-tracked when used as a ViewModel property.\n */\nexport class Selection<K extends string | number = string | number> extends Trackable {\n private _selected: Set<K> = new Set();\n private _readonlyView: ReadonlySet<K> = this._selected;\n\n constructor() {\n super();\n }\n\n // ── Readable state ──\n\n /** Read-only view of currently selected keys. */\n get selected(): ReadonlySet<K> {\n return this._readonlyView;\n }\n\n /** Number of currently selected items. */\n get count(): number {\n return this._selected.size;\n }\n\n /** Whether any items are currently selected. */\n get hasSelection(): boolean {\n return this._selected.size > 0;\n }\n\n // ── Query ──\n\n /** Check whether a specific key is selected. */\n isSelected(key: K): boolean {\n return this._selected.has(key);\n }\n\n // ── Actions ──\n\n /** Toggle a key's selection state (select if unselected, deselect if selected). */\n toggle(key: K): void {\n if (this._selected.has(key)) {\n this._selected.delete(key);\n } else {\n this._selected.add(key);\n }\n this._publish();\n }\n\n /** Add one or more keys to the selection. */\n select(...keys: K[]): void {\n let changed = false;\n for (const key of keys) {\n if (!this._selected.has(key)) {\n this._selected.add(key);\n changed = true;\n }\n }\n if (changed) this._publish();\n }\n\n /** Remove one or more keys from the selection. */\n deselect(...keys: K[]): void {\n let changed = false;\n for (const key of keys) {\n if (this._selected.has(key)) {\n this._selected.delete(key);\n changed = true;\n }\n }\n if (changed) this._publish();\n }\n\n /** If all selected → deselect all, else select all. */\n toggleAll(allKeys: K[]): void {\n const allSelected = allKeys.length > 0 && allKeys.every(k => this._selected.has(k));\n if (allSelected) {\n this._selected.clear();\n } else {\n for (const key of allKeys) this._selected.add(key);\n }\n this._publish();\n }\n\n /** Replace the entire selection atomically. Single notification. */\n set(...keys: K[]): void {\n // Check if anything actually changed\n if (keys.length === this._selected.size && keys.every(k => this._selected.has(k))) return;\n this._selected.clear();\n for (const key of keys) this._selected.add(key);\n this._publish();\n }\n\n /** Remove all items from the selection. */\n clear(): void {\n if (this._selected.size === 0) return;\n this._selected.clear();\n this._publish();\n }\n\n // ── Utility ──\n\n /** Filter an array to only items whose key is in the selection. */\n selectedFrom<T>(items: T[], keyOf: (item: T) => K): T[] {\n return items.filter(item => this._selected.has(keyOf(item)));\n }\n\n // ── Internal ──\n\n private _publish(): void {\n // Replace readonlyView so reference equality changes (needed for React)\n this._readonlyView = new Set(this._selected);\n this.notify();\n }\n}\n"],"mappings":";;;;;;;AAOA,IAAa,YAAb,cAA4E,kBAAA,UAAU;CACpF,4BAA4B,IAAI,KAAK;CACrC,gBAAwC,KAAK;CAE7C,cAAc;AACZ,SAAO;;;CAMT,IAAI,WAA2B;AAC7B,SAAO,KAAK;;;CAId,IAAI,QAAgB;AAClB,SAAO,KAAK,UAAU;;;CAIxB,IAAI,eAAwB;AAC1B,SAAO,KAAK,UAAU,OAAO;;;CAM/B,WAAW,KAAiB;AAC1B,SAAO,KAAK,UAAU,IAAI,IAAI;;;CAMhC,OAAO,KAAc;AACnB,MAAI,KAAK,UAAU,IAAI,IAAI,CACzB,MAAK,UAAU,OAAO,IAAI;MAE1B,MAAK,UAAU,IAAI,IAAI;AAEzB,OAAK,UAAU;;;CAIjB,OAAO,GAAG,MAAiB;EACzB,IAAI,UAAU;AACd,OAAK,MAAM,OAAO,KAChB,KAAI,CAAC,KAAK,UAAU,IAAI,IAAI,EAAE;AAC5B,QAAK,UAAU,IAAI,IAAI;AACvB,aAAU;;AAGd,MAAI,QAAS,MAAK,UAAU;;;CAI9B,SAAS,GAAG,MAAiB;EAC3B,IAAI,UAAU;AACd,OAAK,MAAM,OAAO,KAChB,KAAI,KAAK,UAAU,IAAI,IAAI,EAAE;AAC3B,QAAK,UAAU,OAAO,IAAI;AAC1B,aAAU;;AAGd,MAAI,QAAS,MAAK,UAAU;;;CAI9B,UAAU,SAAoB;AAE5B,MADoB,QAAQ,SAAS,KAAK,QAAQ,OAAM,MAAK,KAAK,UAAU,IAAI,EAAE,CAAC,CAEjF,MAAK,UAAU,OAAO;MAEtB,MAAK,MAAM,OAAO,QA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