@but212/atom-effect-jquery 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +198 -0
- package/dist/atom-effect-jquery.min.js +2 -0
- package/dist/atom-effect-jquery.min.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +159 -0
- package/dist/index.mjs +1799 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +66 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,1799 @@
|
|
|
1
|
+
import u from "jquery";
|
|
2
|
+
import { default as Nt } from "jquery";
|
|
3
|
+
const Be = {
|
|
4
|
+
/** One second in milliseconds */
|
|
5
|
+
ONE_SECOND_MS: 1e3
|
|
6
|
+
}, oe = {
|
|
7
|
+
IDLE: "idle",
|
|
8
|
+
PENDING: "pending",
|
|
9
|
+
RESOLVED: "resolved",
|
|
10
|
+
REJECTED: "rejected"
|
|
11
|
+
}, Z = {
|
|
12
|
+
DISPOSED: 1,
|
|
13
|
+
// 0001 - Effect has been disposed
|
|
14
|
+
EXECUTING: 2
|
|
15
|
+
// 0010 - Effect is currently executing
|
|
16
|
+
}, d = {
|
|
17
|
+
DIRTY: 1,
|
|
18
|
+
// 0001 - Needs recomputation
|
|
19
|
+
IDLE: 2,
|
|
20
|
+
// 0010 - Initial state, not computed yet
|
|
21
|
+
PENDING: 4,
|
|
22
|
+
// 0100 - Async computation in progress
|
|
23
|
+
RESOLVED: 8,
|
|
24
|
+
// 1000 - Successfully computed
|
|
25
|
+
REJECTED: 16,
|
|
26
|
+
// 10000 - Computation failed
|
|
27
|
+
RECOMPUTING: 32,
|
|
28
|
+
// 100000 - Currently recomputing
|
|
29
|
+
HAS_ERROR: 64
|
|
30
|
+
// 1000000 - Has error state
|
|
31
|
+
}, V = {
|
|
32
|
+
/** Maximum effect executions per second to detect infinite loops (Legacy/Fallback) */
|
|
33
|
+
MAX_EXECUTIONS_PER_SECOND: 1e3,
|
|
34
|
+
/**
|
|
35
|
+
* Maximum executions per effect within a single flush cycle
|
|
36
|
+
* Increased from 50 to 100
|
|
37
|
+
*/
|
|
38
|
+
MAX_EXECUTIONS_PER_EFFECT: 100,
|
|
39
|
+
/**
|
|
40
|
+
* Maximum total executions across all effects in a single flush cycle
|
|
41
|
+
* Increased from 5000 to 10000
|
|
42
|
+
*/
|
|
43
|
+
MAX_EXECUTIONS_PER_FLUSH: 1e4,
|
|
44
|
+
/** Maximum iterations for synchronous flush loop to prevent infinite loops */
|
|
45
|
+
MAX_FLUSH_ITERATIONS: 1e3,
|
|
46
|
+
/** Minimum allowed value for max flush iterations */
|
|
47
|
+
MIN_FLUSH_ITERATIONS: 10
|
|
48
|
+
}, Ee = {
|
|
49
|
+
/** Maximum dependencies before warning about large dependency graphs */
|
|
50
|
+
MAX_DEPENDENCIES: 1e3,
|
|
51
|
+
/** Enable infinite loop detection warnings */
|
|
52
|
+
WARN_INFINITE_LOOP: !0
|
|
53
|
+
}, B = 1073741823, R = typeof process < "u" && process.env && process.env.NODE_ENV !== "production", qe = Object.freeze([]);
|
|
54
|
+
class k extends Error {
|
|
55
|
+
/**
|
|
56
|
+
* Creates a new AtomError
|
|
57
|
+
* @param message - Error message describing what went wrong
|
|
58
|
+
* @param cause - Original error that caused this error
|
|
59
|
+
* @param recoverable - Whether the operation can be retried
|
|
60
|
+
*/
|
|
61
|
+
constructor(e, s = null, n = !0) {
|
|
62
|
+
super(e), this.name = "AtomError", this.cause = s, this.recoverable = n, this.timestamp = /* @__PURE__ */ new Date();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
class X extends k {
|
|
66
|
+
/**
|
|
67
|
+
* Creates a new ComputedError
|
|
68
|
+
* @param message - Error message
|
|
69
|
+
* @param cause - Original error
|
|
70
|
+
*/
|
|
71
|
+
constructor(e, s = null) {
|
|
72
|
+
super(e, s, !0), this.name = "ComputedError";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
class M extends k {
|
|
76
|
+
/**
|
|
77
|
+
* Creates a new EffectError
|
|
78
|
+
* @param message - Error message
|
|
79
|
+
* @param cause - Original error
|
|
80
|
+
*/
|
|
81
|
+
constructor(e, s = null) {
|
|
82
|
+
super(e, s, !1), this.name = "EffectError";
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
class ee extends k {
|
|
86
|
+
/**
|
|
87
|
+
* Creates a new SchedulerError
|
|
88
|
+
* @param message - Error message
|
|
89
|
+
* @param cause - Original error
|
|
90
|
+
*/
|
|
91
|
+
constructor(e, s = null) {
|
|
92
|
+
super(e, s, !1), this.name = "SchedulerError";
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const m = {
|
|
96
|
+
// ─────────────────────────────────────────────────────────────────
|
|
97
|
+
// Computed errors
|
|
98
|
+
// ─────────────────────────────────────────────────────────────────
|
|
99
|
+
/**
|
|
100
|
+
* Error thrown when computed() receives a non-function argument.
|
|
101
|
+
*/
|
|
102
|
+
COMPUTED_MUST_BE_FUNCTION: "Computed function must be a function",
|
|
103
|
+
/**
|
|
104
|
+
* Error thrown when subscribe() receives an invalid listener.
|
|
105
|
+
*/
|
|
106
|
+
COMPUTED_SUBSCRIBER_MUST_BE_FUNCTION: "Subscriber listener must be a function or Subscriber object",
|
|
107
|
+
/**
|
|
108
|
+
* Error thrown when accessing a pending async computed without a default value.
|
|
109
|
+
*/
|
|
110
|
+
COMPUTED_ASYNC_PENDING_NO_DEFAULT: "Async computation is pending. No default value provided",
|
|
111
|
+
/**
|
|
112
|
+
* Error thrown when a synchronous computed computation fails.
|
|
113
|
+
*/
|
|
114
|
+
COMPUTED_COMPUTATION_FAILED: "Computed computation failed",
|
|
115
|
+
/**
|
|
116
|
+
* Error thrown when an asynchronous computed computation fails.
|
|
117
|
+
*/
|
|
118
|
+
COMPUTED_ASYNC_COMPUTATION_FAILED: "Async computed computation failed",
|
|
119
|
+
/**
|
|
120
|
+
* Error thrown when subscribing to a dependency fails.
|
|
121
|
+
*/
|
|
122
|
+
COMPUTED_DEPENDENCY_SUBSCRIPTION_FAILED: "Failed to subscribe to dependency",
|
|
123
|
+
// ─────────────────────────────────────────────────────────────────
|
|
124
|
+
// Atom errors
|
|
125
|
+
// ─────────────────────────────────────────────────────────────────
|
|
126
|
+
/**
|
|
127
|
+
* Error thrown when atom.subscribe() receives an invalid listener.
|
|
128
|
+
*/
|
|
129
|
+
ATOM_SUBSCRIBER_MUST_BE_FUNCTION: "Subscription listener must be a function or Subscriber object",
|
|
130
|
+
/**
|
|
131
|
+
* Error thrown when the atom subscriber notification process fails.
|
|
132
|
+
*/
|
|
133
|
+
ATOM_SUBSCRIBER_EXECUTION_FAILED: "Error occurred while executing atom subscribers",
|
|
134
|
+
/**
|
|
135
|
+
* Error logged when an individual subscriber throws during notification.
|
|
136
|
+
* @remarks This error is caught and logged to prevent cascading failures.
|
|
137
|
+
*/
|
|
138
|
+
ATOM_INDIVIDUAL_SUBSCRIBER_FAILED: "Error during individual atom subscriber execution",
|
|
139
|
+
// ─────────────────────────────────────────────────────────────────
|
|
140
|
+
// Effect errors
|
|
141
|
+
// ─────────────────────────────────────────────────────────────────
|
|
142
|
+
/**
|
|
143
|
+
* Error thrown when effect() receives a non-function argument.
|
|
144
|
+
*/
|
|
145
|
+
EFFECT_MUST_BE_FUNCTION: "Effect function must be a function",
|
|
146
|
+
/**
|
|
147
|
+
* Error thrown when an effect's execution fails.
|
|
148
|
+
*/
|
|
149
|
+
EFFECT_EXECUTION_FAILED: "Effect execution failed",
|
|
150
|
+
/**
|
|
151
|
+
* Error thrown when an effect's cleanup function fails.
|
|
152
|
+
*/
|
|
153
|
+
EFFECT_CLEANUP_FAILED: "Effect cleanup function execution failed",
|
|
154
|
+
// ─────────────────────────────────────────────────────────────────
|
|
155
|
+
// Debug warnings
|
|
156
|
+
// ─────────────────────────────────────────────────────────────────
|
|
157
|
+
/**
|
|
158
|
+
* Warning message for large dependency graphs.
|
|
159
|
+
*
|
|
160
|
+
* @param count - The number of dependencies detected
|
|
161
|
+
* @returns Formatted warning message with dependency count
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* console.warn(ERROR_MESSAGES.LARGE_DEPENDENCY_GRAPH(150));
|
|
166
|
+
* // Output: "Large dependency graph detected: 150 dependencies"
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
LARGE_DEPENDENCY_GRAPH: (t) => `Large dependency graph detected: ${t} dependencies`,
|
|
170
|
+
/**
|
|
171
|
+
* Warning logged when attempting to unsubscribe a non-existent listener.
|
|
172
|
+
*/
|
|
173
|
+
UNSUBSCRIBE_NON_EXISTENT: "Attempted to unsubscribe a non-existent listener",
|
|
174
|
+
/**
|
|
175
|
+
* Error logged when the onError callback itself throws an error.
|
|
176
|
+
* @remarks This prevents cascading failures from masking the original error.
|
|
177
|
+
*/
|
|
178
|
+
CALLBACK_ERROR_IN_ERROR_HANDLER: "Error occurred during onError callback execution"
|
|
179
|
+
}, he = /* @__PURE__ */ Symbol("debugName"), ze = /* @__PURE__ */ Symbol("id"), ae = /* @__PURE__ */ Symbol("type"), ge = /* @__PURE__ */ Symbol("noDefaultValue");
|
|
180
|
+
function Xe(t) {
|
|
181
|
+
return "dependencies" in t && Array.isArray(t.dependencies);
|
|
182
|
+
}
|
|
183
|
+
let me = 0;
|
|
184
|
+
function Ce(t, e, s) {
|
|
185
|
+
if (t._visitedEpoch !== s) {
|
|
186
|
+
if (t._visitedEpoch = s, t === e)
|
|
187
|
+
throw new X("Indirect circular dependency detected");
|
|
188
|
+
if (Xe(t)) {
|
|
189
|
+
const n = t.dependencies;
|
|
190
|
+
for (let i = 0; i < n.length; i++) {
|
|
191
|
+
const r = n[i];
|
|
192
|
+
r && Ce(r, e, s);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const w = {
|
|
198
|
+
enabled: typeof process < "u" && process.env?.NODE_ENV === "development",
|
|
199
|
+
maxDependencies: Ee.MAX_DEPENDENCIES,
|
|
200
|
+
warnInfiniteLoop: Ee.WARN_INFINITE_LOOP,
|
|
201
|
+
warn(t, e) {
|
|
202
|
+
this.enabled && t && console.warn(`[Atom Effect] ${e}`);
|
|
203
|
+
},
|
|
204
|
+
/**
|
|
205
|
+
* Checks for circular dependencies.
|
|
206
|
+
* Direct check runs always; indirect check only in dev mode.
|
|
207
|
+
* @throws {ComputedError} When circular dependency detected
|
|
208
|
+
*/
|
|
209
|
+
checkCircular(t, e) {
|
|
210
|
+
if (t === e)
|
|
211
|
+
throw new X("Direct circular dependency detected");
|
|
212
|
+
this.enabled && (me++, Ce(t, e, me));
|
|
213
|
+
},
|
|
214
|
+
attachDebugInfo(t, e, s) {
|
|
215
|
+
if (!this.enabled)
|
|
216
|
+
return;
|
|
217
|
+
const n = t;
|
|
218
|
+
n[he] = `${e}_${s}`, n[ze] = s, n[ae] = e;
|
|
219
|
+
},
|
|
220
|
+
getDebugName(t) {
|
|
221
|
+
if (t != null && he in t)
|
|
222
|
+
return t[he];
|
|
223
|
+
},
|
|
224
|
+
getDebugType(t) {
|
|
225
|
+
if (t != null && ae in t)
|
|
226
|
+
return t[ae];
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
let Ge = 1;
|
|
230
|
+
const Qe = () => Ge++;
|
|
231
|
+
class ve {
|
|
232
|
+
constructor() {
|
|
233
|
+
this.id = Qe() & B, this.flags = 0;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
class Ne extends ve {
|
|
237
|
+
constructor() {
|
|
238
|
+
super(), this.version = 0, this._lastSeenEpoch = -1;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Subscribes a listener function or Subscriber object to value changes.
|
|
242
|
+
*
|
|
243
|
+
* @param listener - Function or Subscriber object to call when the value changes
|
|
244
|
+
* @returns An unsubscribe function
|
|
245
|
+
* @throws {AtomError} If listener is not a function or Subscriber
|
|
246
|
+
*/
|
|
247
|
+
subscribe(e) {
|
|
248
|
+
if (typeof e == "object" && e !== null && "execute" in e)
|
|
249
|
+
return this._objectSubscribers.add(e);
|
|
250
|
+
if (typeof e != "function")
|
|
251
|
+
throw new k(m.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);
|
|
252
|
+
return this._functionSubscribers.add(e);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Gets the total number of active subscribers.
|
|
256
|
+
*/
|
|
257
|
+
subscriberCount() {
|
|
258
|
+
return this._functionSubscribers.size + this._objectSubscribers.size;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Notifies all subscribers of a change.
|
|
262
|
+
*
|
|
263
|
+
* @param newValue - The new value
|
|
264
|
+
* @param oldValue - The old value
|
|
265
|
+
*/
|
|
266
|
+
_notifySubscribers(e, s) {
|
|
267
|
+
this._functionSubscribers.forEachSafe(
|
|
268
|
+
(n) => n(e, s),
|
|
269
|
+
(n) => console.error(new k(m.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED, n))
|
|
270
|
+
), this._objectSubscribers.forEachSafe(
|
|
271
|
+
(n) => n.execute(),
|
|
272
|
+
(n) => console.error(new k(m.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED, n))
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
let te = 0;
|
|
277
|
+
function Te() {
|
|
278
|
+
return te = (te + 1 | 0) & B, te;
|
|
279
|
+
}
|
|
280
|
+
function He() {
|
|
281
|
+
return te;
|
|
282
|
+
}
|
|
283
|
+
let ne = 0, fe = 0, ie = !1;
|
|
284
|
+
function Se() {
|
|
285
|
+
return ie ? (R && console.warn(
|
|
286
|
+
"Warning: startFlush() called during flush - ignored to prevent infinite loop detection bypass"
|
|
287
|
+
), !1) : (ie = !0, ne = ne + 1 & B, fe = 0, !0);
|
|
288
|
+
}
|
|
289
|
+
function ye() {
|
|
290
|
+
ie = !1;
|
|
291
|
+
}
|
|
292
|
+
function Je() {
|
|
293
|
+
return ie ? ++fe : 0;
|
|
294
|
+
}
|
|
295
|
+
class Ye {
|
|
296
|
+
constructor() {
|
|
297
|
+
this.queueA = [], this.queueB = [], this.queue = this.queueA, this.queueSize = 0, this._epoch = 0, this.isProcessing = !1, this.isBatching = !1, this.batchDepth = 0, this.batchQueue = [], this.batchQueueSize = 0, this.isFlushingSync = !1, this.maxFlushIterations = V.MAX_FLUSH_ITERATIONS;
|
|
298
|
+
}
|
|
299
|
+
get phase() {
|
|
300
|
+
return this.isProcessing || this.isFlushingSync ? 2 : this.isBatching ? 1 : 0;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Schedules a task for execution.
|
|
304
|
+
* Tasks are deduplicated within the same flush cycle using epoch tracking.
|
|
305
|
+
* @param callback - The function to execute.
|
|
306
|
+
* @throws {SchedulerError} If the callback is not a function.
|
|
307
|
+
*/
|
|
308
|
+
schedule(e) {
|
|
309
|
+
if (typeof e != "function")
|
|
310
|
+
throw new ee("Scheduler callback must be a function");
|
|
311
|
+
e._nextEpoch !== this._epoch && (e._nextEpoch = this._epoch, this.isBatching || this.isFlushingSync ? this.batchQueue[this.batchQueueSize++] = e : (this.queue[this.queueSize++] = e, this.isProcessing || this.flush()));
|
|
312
|
+
}
|
|
313
|
+
flush() {
|
|
314
|
+
if (this.isProcessing || this.queueSize === 0) return;
|
|
315
|
+
this.isProcessing = !0;
|
|
316
|
+
const e = this.queue, s = this.queueSize;
|
|
317
|
+
this.queue = this.queue === this.queueA ? this.queueB : this.queueA, this.queueSize = 0, this._epoch++, queueMicrotask(() => {
|
|
318
|
+
const n = Se();
|
|
319
|
+
this._processJobs(e, s), this.isProcessing = !1, n && ye(), this.queueSize > 0 && !this.isBatching && this.flush();
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
flushSync() {
|
|
323
|
+
this.isFlushingSync = !0;
|
|
324
|
+
const e = Se();
|
|
325
|
+
try {
|
|
326
|
+
this._mergeBatchQueue(), this._drainQueue();
|
|
327
|
+
} finally {
|
|
328
|
+
this.isFlushingSync = !1, e && ye();
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
_mergeBatchQueue() {
|
|
332
|
+
if (this._epoch++, this.batchQueueSize > 0) {
|
|
333
|
+
for (let e = 0; e < this.batchQueueSize; e++) {
|
|
334
|
+
const s = this.batchQueue[e];
|
|
335
|
+
s && s._nextEpoch !== this._epoch && (s._nextEpoch = this._epoch, this.queue[this.queueSize++] = s);
|
|
336
|
+
}
|
|
337
|
+
this.batchQueueSize = 0;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
_drainQueue() {
|
|
341
|
+
let e = 0;
|
|
342
|
+
for (; this.queueSize > 0; ) {
|
|
343
|
+
if (++e > this.maxFlushIterations) {
|
|
344
|
+
this._handleFlushOverflow();
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
this._processCurrentQueue(), this._mergeBatchQueue();
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
_processCurrentQueue() {
|
|
351
|
+
const e = this.queue, s = this.queueSize;
|
|
352
|
+
this.queue = this.queue === this.queueA ? this.queueB : this.queueA, this.queueSize = 0, this._epoch++, this._processJobs(e, s);
|
|
353
|
+
}
|
|
354
|
+
_handleFlushOverflow() {
|
|
355
|
+
console.error(
|
|
356
|
+
new ee(
|
|
357
|
+
`Maximum flush iterations (${this.maxFlushIterations}) exceeded. Possible infinite loop.`
|
|
358
|
+
)
|
|
359
|
+
), this.queueSize = 0, this.queue.length = 0, this.batchQueueSize = 0;
|
|
360
|
+
}
|
|
361
|
+
_processJobs(e, s) {
|
|
362
|
+
for (let n = 0; n < s; n++)
|
|
363
|
+
try {
|
|
364
|
+
e[n]?.();
|
|
365
|
+
} catch (i) {
|
|
366
|
+
console.error(
|
|
367
|
+
new ee("Error occurred during scheduler execution", i)
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
e.length = 0;
|
|
371
|
+
}
|
|
372
|
+
/** Starts a new batch of updates. Updates will be deferred until endBatch is called. */
|
|
373
|
+
startBatch() {
|
|
374
|
+
this.batchDepth++, this.isBatching = !0;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Ends the current batch. If the batch depth reaches zero, all pending updates are flushed synchronously.
|
|
378
|
+
*/
|
|
379
|
+
endBatch() {
|
|
380
|
+
this.batchDepth = Math.max(0, this.batchDepth - 1), this.batchDepth === 0 && (this.flushSync(), this.isBatching = !1);
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Configures the maximum number of iterations allowed during a synchronous flush.
|
|
384
|
+
* Used to prevent infinite loops.
|
|
385
|
+
* @param max - Maximum iterations count.
|
|
386
|
+
*/
|
|
387
|
+
setMaxFlushIterations(e) {
|
|
388
|
+
if (e < V.MIN_FLUSH_ITERATIONS)
|
|
389
|
+
throw new ee(
|
|
390
|
+
`Max flush iterations must be at least ${V.MIN_FLUSH_ITERATIONS}`
|
|
391
|
+
);
|
|
392
|
+
this.maxFlushIterations = e;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
const Y = new Ye();
|
|
396
|
+
function z(t) {
|
|
397
|
+
if (typeof t != "function")
|
|
398
|
+
throw new k("Batch callback must be a function");
|
|
399
|
+
Y.startBatch();
|
|
400
|
+
try {
|
|
401
|
+
return t();
|
|
402
|
+
} finally {
|
|
403
|
+
Y.endBatch();
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
const q = {
|
|
407
|
+
current: null,
|
|
408
|
+
run(t, e) {
|
|
409
|
+
const s = this.current;
|
|
410
|
+
this.current = t;
|
|
411
|
+
try {
|
|
412
|
+
return e();
|
|
413
|
+
} finally {
|
|
414
|
+
this.current = s;
|
|
415
|
+
}
|
|
416
|
+
},
|
|
417
|
+
getCurrent() {
|
|
418
|
+
return this.current;
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
function Re(t) {
|
|
422
|
+
if (typeof t != "function")
|
|
423
|
+
throw new k("Untracked callback must be a function");
|
|
424
|
+
const e = q.current;
|
|
425
|
+
q.current = null;
|
|
426
|
+
try {
|
|
427
|
+
return t();
|
|
428
|
+
} finally {
|
|
429
|
+
q.current = e;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
class re {
|
|
433
|
+
constructor() {
|
|
434
|
+
this.subscribers = null;
|
|
435
|
+
}
|
|
436
|
+
/** Adds subscriber and returns unsubscribe function (idempotent) */
|
|
437
|
+
add(e) {
|
|
438
|
+
if (this.subscribers || (this.subscribers = []), this.subscribers.indexOf(e) !== -1)
|
|
439
|
+
return () => {
|
|
440
|
+
};
|
|
441
|
+
this.subscribers.push(e);
|
|
442
|
+
let s = !1;
|
|
443
|
+
return () => {
|
|
444
|
+
s || (s = !0, this.remove(e));
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
/** Removes subscriber using swap-and-pop */
|
|
448
|
+
remove(e) {
|
|
449
|
+
if (!this.subscribers)
|
|
450
|
+
return !1;
|
|
451
|
+
const s = this.subscribers.indexOf(e);
|
|
452
|
+
if (s === -1)
|
|
453
|
+
return !1;
|
|
454
|
+
const n = this.subscribers.length - 1;
|
|
455
|
+
return s !== n && (this.subscribers[s] = this.subscribers[n]), this.subscribers.pop(), !0;
|
|
456
|
+
}
|
|
457
|
+
has(e) {
|
|
458
|
+
return this.subscribers ? this.subscribers.indexOf(e) !== -1 : !1;
|
|
459
|
+
}
|
|
460
|
+
forEach(e) {
|
|
461
|
+
if (this.subscribers)
|
|
462
|
+
for (let s = 0; s < this.subscribers.length; s++)
|
|
463
|
+
e(this.subscribers[s], s);
|
|
464
|
+
}
|
|
465
|
+
/** Iterates with error handling to prevent one failure from breaking the chain */
|
|
466
|
+
forEachSafe(e, s) {
|
|
467
|
+
if (this.subscribers)
|
|
468
|
+
for (let n = 0; n < this.subscribers.length; n++)
|
|
469
|
+
try {
|
|
470
|
+
e(this.subscribers[n], n);
|
|
471
|
+
} catch (i) {
|
|
472
|
+
s ? s(i) : console.error("[SubscriberManager] Error in subscriber callback:", i);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
get size() {
|
|
476
|
+
return this.subscribers?.length ?? 0;
|
|
477
|
+
}
|
|
478
|
+
get hasSubscribers() {
|
|
479
|
+
return this.subscribers !== null && this.subscribers.length > 0;
|
|
480
|
+
}
|
|
481
|
+
clear() {
|
|
482
|
+
this.subscribers = null;
|
|
483
|
+
}
|
|
484
|
+
toArray() {
|
|
485
|
+
return this.subscribers ? [...this.subscribers] : [];
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
function le(t) {
|
|
489
|
+
return t !== null && typeof t == "object" && "value" in t && "subscribe" in t && typeof t.subscribe == "function";
|
|
490
|
+
}
|
|
491
|
+
function De(t) {
|
|
492
|
+
if (w.enabled && (t == null || typeof t == "object")) {
|
|
493
|
+
const e = w.getDebugType(t);
|
|
494
|
+
if (e)
|
|
495
|
+
return e === "computed";
|
|
496
|
+
}
|
|
497
|
+
return le(t) && "invalidate" in t && typeof t.invalidate == "function";
|
|
498
|
+
}
|
|
499
|
+
function Ue(t) {
|
|
500
|
+
return t != null && typeof t.then == "function";
|
|
501
|
+
}
|
|
502
|
+
function Ke(t) {
|
|
503
|
+
return typeof t == "object" && t !== null;
|
|
504
|
+
}
|
|
505
|
+
function xe(t) {
|
|
506
|
+
return (typeof t == "object" || typeof t == "function") && t !== null && typeof t.addDependency == "function";
|
|
507
|
+
}
|
|
508
|
+
function Oe(t) {
|
|
509
|
+
return typeof t == "function" && typeof t.addDependency != "function";
|
|
510
|
+
}
|
|
511
|
+
function Ae(t) {
|
|
512
|
+
return Ke(t) && typeof t.execute == "function";
|
|
513
|
+
}
|
|
514
|
+
class We extends Ne {
|
|
515
|
+
constructor(e, s) {
|
|
516
|
+
super(), this._isNotificationScheduled = !1, this._value = e, this._functionSubscribersStore = new re(), this._objectSubscribersStore = new re(), this._sync = s, this._notifyTask = this._flushNotifications.bind(this), w.attachDebugInfo(this, "atom", this.id);
|
|
517
|
+
}
|
|
518
|
+
/** Gets the manager for function-based subscribers. */
|
|
519
|
+
get _functionSubscribers() {
|
|
520
|
+
return this._functionSubscribersStore;
|
|
521
|
+
}
|
|
522
|
+
/** Gets the manager for object-based subscribers. */
|
|
523
|
+
get _objectSubscribers() {
|
|
524
|
+
return this._objectSubscribersStore;
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Returns the current value and registers the atom as a dependency in the current tracking context.
|
|
528
|
+
*/
|
|
529
|
+
get value() {
|
|
530
|
+
const e = q.getCurrent();
|
|
531
|
+
return e && this._track(e), this._value;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Sets a new value and schedules notifications if the value has changed.
|
|
535
|
+
* Uses `Object.is` for comparison.
|
|
536
|
+
*/
|
|
537
|
+
set value(e) {
|
|
538
|
+
if (Object.is(this._value, e)) return;
|
|
539
|
+
const s = this._value;
|
|
540
|
+
this.version = this.version + 1 & B, this._value = e, !(!this._functionSubscribersStore.hasSubscribers && !this._objectSubscribersStore.hasSubscribers) && this._scheduleNotification(s);
|
|
541
|
+
}
|
|
542
|
+
_track(e) {
|
|
543
|
+
if (xe(e)) {
|
|
544
|
+
e.addDependency(this);
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
if (Oe(e)) {
|
|
548
|
+
this._functionSubscribersStore.add(e);
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
Ae(e) && this._objectSubscribersStore.add(e);
|
|
552
|
+
}
|
|
553
|
+
_scheduleNotification(e) {
|
|
554
|
+
this._isNotificationScheduled || (this._pendingOldValue = e, this._isNotificationScheduled = !0), this._sync && !Y.isBatching ? this._flushNotifications() : Y.schedule(this._notifyTask);
|
|
555
|
+
}
|
|
556
|
+
_flushNotifications() {
|
|
557
|
+
if (!this._isNotificationScheduled) return;
|
|
558
|
+
const e = this._pendingOldValue, s = this._value;
|
|
559
|
+
this._pendingOldValue = void 0, this._isNotificationScheduled = !1, this._notifySubscribers(s, e);
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Returns the current value without registering as a dependency in the tracking context.
|
|
563
|
+
*/
|
|
564
|
+
peek() {
|
|
565
|
+
return this._value;
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Disposes of the atom, clearing all subscribers and resetting the value.
|
|
569
|
+
*/
|
|
570
|
+
dispose() {
|
|
571
|
+
this._functionSubscribersStore.clear(), this._objectSubscribersStore.clear(), this._value = void 0;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
function Ze(t, e = {}) {
|
|
575
|
+
return new We(t, e.sync ?? !1);
|
|
576
|
+
}
|
|
577
|
+
class de {
|
|
578
|
+
constructor() {
|
|
579
|
+
this.pool = [], this.maxPoolSize = 50, this.maxReusableCapacity = 256, this.stats = R ? {
|
|
580
|
+
acquired: 0,
|
|
581
|
+
released: 0,
|
|
582
|
+
rejected: { frozen: 0, tooLarge: 0, poolFull: 0 }
|
|
583
|
+
} : null;
|
|
584
|
+
}
|
|
585
|
+
/** Acquires an array from the pool or creates a new one if the pool is empty. */
|
|
586
|
+
acquire() {
|
|
587
|
+
return R && this.stats && this.stats.acquired++, this.pool.pop() ?? [];
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Releases an array back to the pool.
|
|
591
|
+
* Clears the array before storing it.
|
|
592
|
+
* @param arr - The array to release.
|
|
593
|
+
* @param emptyConst - Optional reference to a constant empty array to skip.
|
|
594
|
+
*/
|
|
595
|
+
release(e, s) {
|
|
596
|
+
if (!(s && e === s)) {
|
|
597
|
+
if (Object.isFrozen(e)) {
|
|
598
|
+
R && this.stats && this.stats.rejected.frozen++;
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
if (e.length > this.maxReusableCapacity) {
|
|
602
|
+
R && this.stats && this.stats.rejected.tooLarge++;
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
if (this.pool.length >= this.maxPoolSize) {
|
|
606
|
+
R && this.stats && this.stats.rejected.poolFull++;
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
e.length = 0, this.pool.push(e), R && this.stats && this.stats.released++;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
/** Returns current stats for the pool (dev mode only). */
|
|
613
|
+
getStats() {
|
|
614
|
+
if (!R || !this.stats) return null;
|
|
615
|
+
const { acquired: e, released: s, rejected: n } = this.stats, i = n.frozen + n.tooLarge + n.poolFull;
|
|
616
|
+
return {
|
|
617
|
+
acquired: e,
|
|
618
|
+
released: s,
|
|
619
|
+
rejected: n,
|
|
620
|
+
leaked: e - s - i,
|
|
621
|
+
poolSize: this.pool.length
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
/** Resets the pool and its stats. */
|
|
625
|
+
reset() {
|
|
626
|
+
this.pool.length = 0, R && this.stats && (this.stats.acquired = 0, this.stats.released = 0, this.stats.rejected = { frozen: 0, tooLarge: 0, poolFull: 0 });
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
const y = Object.freeze([]), O = Object.freeze([]), D = Object.freeze([]), $ = new de(), j = new de(), A = new de();
|
|
630
|
+
function et(t, e, s, n) {
|
|
631
|
+
if (e !== y && s !== O)
|
|
632
|
+
for (let r = 0; r < e.length; r++) {
|
|
633
|
+
const o = e[r];
|
|
634
|
+
o && (o._tempUnsub = s[r]);
|
|
635
|
+
}
|
|
636
|
+
const i = j.acquire();
|
|
637
|
+
i.length = t.length;
|
|
638
|
+
for (let r = 0; r < t.length; r++) {
|
|
639
|
+
const o = t[r];
|
|
640
|
+
o && (o._tempUnsub ? (i[r] = o._tempUnsub, o._tempUnsub = void 0) : (w.checkCircular(o, n), i[r] = o.subscribe(n)));
|
|
641
|
+
}
|
|
642
|
+
if (e !== y)
|
|
643
|
+
for (let r = 0; r < e.length; r++) {
|
|
644
|
+
const o = e[r];
|
|
645
|
+
o?._tempUnsub && (o._tempUnsub(), o._tempUnsub = void 0);
|
|
646
|
+
}
|
|
647
|
+
return s !== O && j.release(s), i;
|
|
648
|
+
}
|
|
649
|
+
function G(t, e, s) {
|
|
650
|
+
if (t instanceof TypeError)
|
|
651
|
+
return new e(`Type error (${s}): ${t.message}`, t);
|
|
652
|
+
if (t instanceof ReferenceError)
|
|
653
|
+
return new e(`Reference error (${s}): ${t.message}`, t);
|
|
654
|
+
if (t instanceof k)
|
|
655
|
+
return t;
|
|
656
|
+
const n = t instanceof Error ? t.message : String(t), i = t instanceof Error ? t : null;
|
|
657
|
+
return new e(`Unexpected error (${s}): ${n}`, i);
|
|
658
|
+
}
|
|
659
|
+
const we = d.RESOLVED | d.PENDING | d.REJECTED, ce = Array(we + 1).fill(oe.IDLE);
|
|
660
|
+
ce[d.RESOLVED] = oe.RESOLVED;
|
|
661
|
+
ce[d.PENDING] = oe.PENDING;
|
|
662
|
+
ce[d.REJECTED] = oe.REJECTED;
|
|
663
|
+
class ke extends Ne {
|
|
664
|
+
constructor(e, s = {}) {
|
|
665
|
+
if (typeof e != "function")
|
|
666
|
+
throw new X(m.COMPUTED_MUST_BE_FUNCTION);
|
|
667
|
+
if (super(), this._cachedErrors = null, this._errorCacheEpoch = -1, this._value = void 0, this.flags = d.DIRTY | d.IDLE, this._error = null, this._promiseId = 0, this._equal = s.equal ?? Object.is, this._fn = e, this._defaultValue = "defaultValue" in s ? s.defaultValue : ge, this._hasDefaultValue = this._defaultValue !== ge, this._onError = s.onError ?? null, this.MAX_PROMISE_ID = Number.MAX_SAFE_INTEGER - 1, this._functionSubscribersStore = new re(), this._objectSubscribersStore = new re(), this._dependencies = y, this._dependencyVersions = D, this._unsubscribes = O, this._notifyJob = () => {
|
|
668
|
+
this._functionSubscribersStore.forEachSafe(
|
|
669
|
+
(n) => n(),
|
|
670
|
+
(n) => console.error(n)
|
|
671
|
+
), this._objectSubscribersStore.forEachSafe(
|
|
672
|
+
(n) => n.execute(),
|
|
673
|
+
(n) => console.error(n)
|
|
674
|
+
);
|
|
675
|
+
}, this._trackable = Object.assign(() => this._markDirty(), {
|
|
676
|
+
addDependency: (n) => {
|
|
677
|
+
}
|
|
678
|
+
}), w.attachDebugInfo(this, "computed", this.id), w.enabled) {
|
|
679
|
+
const n = this;
|
|
680
|
+
n.subscriberCount = () => this._functionSubscribersStore.size + this._objectSubscribersStore.size, n.isDirty = () => this._isDirty(), n.dependencies = this._dependencies, n.stateFlags = this._getFlagsAsString();
|
|
681
|
+
}
|
|
682
|
+
if (s.lazy === !1)
|
|
683
|
+
try {
|
|
684
|
+
this._recompute();
|
|
685
|
+
} catch {
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
get _functionSubscribers() {
|
|
689
|
+
return this._functionSubscribersStore;
|
|
690
|
+
}
|
|
691
|
+
get _objectSubscribers() {
|
|
692
|
+
return this._objectSubscribersStore;
|
|
693
|
+
}
|
|
694
|
+
get value() {
|
|
695
|
+
return this._registerTracking(), this._computeValue();
|
|
696
|
+
}
|
|
697
|
+
peek() {
|
|
698
|
+
return this._value;
|
|
699
|
+
}
|
|
700
|
+
get state() {
|
|
701
|
+
return this._registerTracking(), this._getAsyncState();
|
|
702
|
+
}
|
|
703
|
+
get hasError() {
|
|
704
|
+
if (this._registerTracking(), this._isRejected())
|
|
705
|
+
return !0;
|
|
706
|
+
for (let e = 0; e < this._dependencies.length; e++) {
|
|
707
|
+
const s = this._dependencies[e];
|
|
708
|
+
if (s && "hasError" in s && s.hasError)
|
|
709
|
+
return !0;
|
|
710
|
+
}
|
|
711
|
+
return !1;
|
|
712
|
+
}
|
|
713
|
+
get isValid() {
|
|
714
|
+
return !this.hasError;
|
|
715
|
+
}
|
|
716
|
+
get errors() {
|
|
717
|
+
if (this._registerTracking(), !this.hasError)
|
|
718
|
+
return qe;
|
|
719
|
+
const e = He();
|
|
720
|
+
if (this._errorCacheEpoch === e && this._cachedErrors !== null)
|
|
721
|
+
return this._cachedErrors;
|
|
722
|
+
const s = /* @__PURE__ */ new Set();
|
|
723
|
+
this._error && s.add(this._error);
|
|
724
|
+
for (let n = 0; n < this._dependencies.length; n++) {
|
|
725
|
+
const i = this._dependencies[n];
|
|
726
|
+
if (i && "errors" in i) {
|
|
727
|
+
const r = i.errors;
|
|
728
|
+
for (let o = 0; o < r.length; o++) {
|
|
729
|
+
const c = r[o];
|
|
730
|
+
c && s.add(c);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
return this._cachedErrors = Object.freeze([...s]), this._errorCacheEpoch = e, this._cachedErrors;
|
|
735
|
+
}
|
|
736
|
+
get lastError() {
|
|
737
|
+
return this._registerTracking(), this._error;
|
|
738
|
+
}
|
|
739
|
+
get isPending() {
|
|
740
|
+
return this._registerTracking(), this._isPending();
|
|
741
|
+
}
|
|
742
|
+
get isResolved() {
|
|
743
|
+
return this._registerTracking(), this._isResolved();
|
|
744
|
+
}
|
|
745
|
+
invalidate() {
|
|
746
|
+
this._markDirty(), this._dependencyVersions !== D && (A.release(this._dependencyVersions), this._dependencyVersions = D), this._errorCacheEpoch = -1, this._cachedErrors = null;
|
|
747
|
+
}
|
|
748
|
+
dispose() {
|
|
749
|
+
if (this._unsubscribes !== O) {
|
|
750
|
+
for (let e = 0; e < this._unsubscribes.length; e++) {
|
|
751
|
+
const s = this._unsubscribes[e];
|
|
752
|
+
s && s();
|
|
753
|
+
}
|
|
754
|
+
j.release(this._unsubscribes), this._unsubscribes = O;
|
|
755
|
+
}
|
|
756
|
+
this._dependencies !== y && ($.release(this._dependencies), this._dependencies = y), this._dependencyVersions !== D && (A.release(this._dependencyVersions), this._dependencyVersions = D), this._functionSubscribersStore.clear(), this._objectSubscribersStore.clear(), this.flags = d.DIRTY | d.IDLE, this._error = null, this._value = void 0, this._promiseId = (this._promiseId + 1) % this.MAX_PROMISE_ID, this._cachedErrors = null, this._errorCacheEpoch = -1;
|
|
757
|
+
}
|
|
758
|
+
// State flag operations
|
|
759
|
+
_isDirty() {
|
|
760
|
+
return (this.flags & d.DIRTY) !== 0;
|
|
761
|
+
}
|
|
762
|
+
_setDirty() {
|
|
763
|
+
this.flags |= d.DIRTY;
|
|
764
|
+
}
|
|
765
|
+
_clearDirty() {
|
|
766
|
+
this.flags &= -2;
|
|
767
|
+
}
|
|
768
|
+
_isIdle() {
|
|
769
|
+
return (this.flags & d.IDLE) !== 0;
|
|
770
|
+
}
|
|
771
|
+
_setIdle() {
|
|
772
|
+
this.flags |= d.IDLE, this.flags &= -29;
|
|
773
|
+
}
|
|
774
|
+
_isPending() {
|
|
775
|
+
return (this.flags & d.PENDING) !== 0;
|
|
776
|
+
}
|
|
777
|
+
_setPending() {
|
|
778
|
+
this.flags |= d.PENDING, this.flags &= -27;
|
|
779
|
+
}
|
|
780
|
+
_isResolved() {
|
|
781
|
+
return (this.flags & d.RESOLVED) !== 0;
|
|
782
|
+
}
|
|
783
|
+
_setResolved() {
|
|
784
|
+
this.flags |= d.RESOLVED, this.flags &= -87;
|
|
785
|
+
}
|
|
786
|
+
_isRejected() {
|
|
787
|
+
return (this.flags & d.REJECTED) !== 0;
|
|
788
|
+
}
|
|
789
|
+
_setRejected() {
|
|
790
|
+
this.flags |= d.REJECTED | d.HAS_ERROR, this.flags &= -15;
|
|
791
|
+
}
|
|
792
|
+
_isRecomputing() {
|
|
793
|
+
return (this.flags & d.RECOMPUTING) !== 0;
|
|
794
|
+
}
|
|
795
|
+
_setRecomputing(e) {
|
|
796
|
+
const s = d.RECOMPUTING;
|
|
797
|
+
this.flags = this.flags & ~s | -Number(e) & s;
|
|
798
|
+
}
|
|
799
|
+
_getAsyncState() {
|
|
800
|
+
return ce[this.flags & we];
|
|
801
|
+
}
|
|
802
|
+
_getFlagsAsString() {
|
|
803
|
+
const e = [];
|
|
804
|
+
return this._isDirty() && e.push("DIRTY"), this._isIdle() && e.push("IDLE"), this._isPending() && e.push("PENDING"), this._isResolved() && e.push("RESOLVED"), this._isRejected() && e.push("REJECTED"), this._isRecomputing() && e.push("RECOMPUTING"), e.join(" | ");
|
|
805
|
+
}
|
|
806
|
+
_computeValue() {
|
|
807
|
+
return this._isRecomputing() ? this._value : ((this._isDirty() || this._isIdle()) && this._recompute(), this._isPending() ? this._handlePending() : this._isRejected() ? this._handleRejected() : this._value);
|
|
808
|
+
}
|
|
809
|
+
_recompute() {
|
|
810
|
+
if (this._isRecomputing()) return;
|
|
811
|
+
this._setRecomputing(!0);
|
|
812
|
+
const e = this._prepareComputationContext();
|
|
813
|
+
let s = !1;
|
|
814
|
+
try {
|
|
815
|
+
const n = q.run(this._trackable, this._fn);
|
|
816
|
+
this._commitDependencies(e), s = !0, Ue(n) ? this._handleAsyncComputation(n) : this._handleSyncResult(n);
|
|
817
|
+
} catch (n) {
|
|
818
|
+
if (!s)
|
|
819
|
+
try {
|
|
820
|
+
this._commitDependencies(e), s = !0;
|
|
821
|
+
} catch (i) {
|
|
822
|
+
this._handleComputationError(i);
|
|
823
|
+
}
|
|
824
|
+
this._handleComputationError(n);
|
|
825
|
+
} finally {
|
|
826
|
+
this._cleanupContext(e, s), this._setRecomputing(!1);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
_prepareComputationContext() {
|
|
830
|
+
const e = this._dependencies, s = this._dependencyVersions, n = $.acquire(), i = A.acquire(), r = Te(), o = { depCount: 0 }, c = (_) => {
|
|
831
|
+
_._lastSeenEpoch !== r && (_._lastSeenEpoch = r, o.depCount < n.length ? (n[o.depCount] = _, i[o.depCount] = _.version) : (n.push(_), i.push(_.version)), o.depCount++);
|
|
832
|
+
}, f = this._trackable.addDependency;
|
|
833
|
+
return this._trackable.addDependency = c, { prevDeps: e, prevVersions: s, nextDeps: n, nextVersions: i, originalAdd: f, state: o };
|
|
834
|
+
}
|
|
835
|
+
_commitDependencies(e) {
|
|
836
|
+
const { nextDeps: s, nextVersions: n, state: i, prevDeps: r } = e;
|
|
837
|
+
s.length = i.depCount, n.length = i.depCount, this._unsubscribes = et(s, r, this._unsubscribes, this), this._dependencies = s, this._dependencyVersions = n;
|
|
838
|
+
}
|
|
839
|
+
_cleanupContext(e, s) {
|
|
840
|
+
this._trackable.addDependency = e.originalAdd, s ? (e.prevDeps !== y && $.release(e.prevDeps), e.prevVersions !== D && A.release(e.prevVersions)) : ($.release(e.nextDeps), A.release(e.nextVersions));
|
|
841
|
+
}
|
|
842
|
+
_handleSyncResult(e) {
|
|
843
|
+
const s = !this._isResolved() || !this._equal(this._value, e);
|
|
844
|
+
this.version = this.version + Number(s) & B, this._value = e, this._clearDirty(), this._setResolved(), this._error = null, this._setRecomputing(!1), this._cachedErrors = null, this._errorCacheEpoch = -1;
|
|
845
|
+
}
|
|
846
|
+
_handleAsyncComputation(e) {
|
|
847
|
+
this._setPending(), this._clearDirty(), this._notifyJob(), this._promiseId = this._promiseId >= this.MAX_PROMISE_ID ? 1 : this._promiseId + 1;
|
|
848
|
+
const s = this._promiseId;
|
|
849
|
+
e.then((n) => {
|
|
850
|
+
s === this._promiseId && this._handleAsyncResolution(n);
|
|
851
|
+
}).catch((n) => {
|
|
852
|
+
s === this._promiseId && this._handleAsyncRejection(n);
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
_handleAsyncResolution(e) {
|
|
856
|
+
const s = !this._isResolved() || !this._equal(this._value, e);
|
|
857
|
+
this.version = this.version + Number(s) & B, this._value = e, this._clearDirty(), this._setResolved(), this._error = null, this._setRecomputing(!1), this._cachedErrors = null, this._errorCacheEpoch = -1, this._notifyJob();
|
|
858
|
+
}
|
|
859
|
+
_handleAsyncRejection(e) {
|
|
860
|
+
const s = G(e, X, m.COMPUTED_ASYNC_COMPUTATION_FAILED), n = !this._isRejected();
|
|
861
|
+
if (this.version = this.version + Number(n) & B, this._error = s, this._setRejected(), this._clearDirty(), this._setRecomputing(!1), this._onError)
|
|
862
|
+
try {
|
|
863
|
+
this._onError(s);
|
|
864
|
+
} catch (i) {
|
|
865
|
+
console.error(m.CALLBACK_ERROR_IN_ERROR_HANDLER, i);
|
|
866
|
+
}
|
|
867
|
+
this._notifyJob();
|
|
868
|
+
}
|
|
869
|
+
_handleComputationError(e) {
|
|
870
|
+
const s = G(e, X, m.COMPUTED_COMPUTATION_FAILED);
|
|
871
|
+
if (this._error = s, this._setRejected(), this._clearDirty(), this._setRecomputing(!1), this._onError)
|
|
872
|
+
try {
|
|
873
|
+
this._onError(s);
|
|
874
|
+
} catch (n) {
|
|
875
|
+
console.error(m.CALLBACK_ERROR_IN_ERROR_HANDLER, n);
|
|
876
|
+
}
|
|
877
|
+
throw s;
|
|
878
|
+
}
|
|
879
|
+
_handlePending() {
|
|
880
|
+
if (this._hasDefaultValue)
|
|
881
|
+
return this._defaultValue;
|
|
882
|
+
throw new X(m.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
|
|
883
|
+
}
|
|
884
|
+
_handleRejected() {
|
|
885
|
+
if (this._error?.recoverable && this._hasDefaultValue)
|
|
886
|
+
return this._defaultValue;
|
|
887
|
+
throw this._error;
|
|
888
|
+
}
|
|
889
|
+
/** Subscriber interface - marks dirty on dependency change */
|
|
890
|
+
execute() {
|
|
891
|
+
this._markDirty();
|
|
892
|
+
}
|
|
893
|
+
_markDirty() {
|
|
894
|
+
this._isRecomputing() || this._isDirty() || (this._setDirty(), this._notifyJob());
|
|
895
|
+
}
|
|
896
|
+
_registerTracking() {
|
|
897
|
+
const e = q.getCurrent();
|
|
898
|
+
if (e) {
|
|
899
|
+
if (xe(e)) {
|
|
900
|
+
e.addDependency(this);
|
|
901
|
+
return;
|
|
902
|
+
}
|
|
903
|
+
if (Oe(e)) {
|
|
904
|
+
this._functionSubscribersStore.add(e);
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
Ae(e) && this._objectSubscribersStore.add(e);
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
Object.freeze(ke.prototype);
|
|
912
|
+
function tt(t, e = {}) {
|
|
913
|
+
return new ke(t, e);
|
|
914
|
+
}
|
|
915
|
+
class st extends ve {
|
|
916
|
+
/**
|
|
917
|
+
* Creates a new EffectImpl instance.
|
|
918
|
+
* @param fn - The effect function to run.
|
|
919
|
+
* @param options - Configuration options for the effect.
|
|
920
|
+
*/
|
|
921
|
+
constructor(e, s = {}) {
|
|
922
|
+
super(), this.run = () => {
|
|
923
|
+
if (this.isDisposed)
|
|
924
|
+
throw new M(m.EFFECT_MUST_BE_FUNCTION);
|
|
925
|
+
this._dependencyVersions !== D && (A.release(this._dependencyVersions), this._dependencyVersions = D), this.execute();
|
|
926
|
+
}, this.dispose = () => {
|
|
927
|
+
if (!this.isDisposed) {
|
|
928
|
+
if (this._setDisposed(), this._safeCleanup(), this._unsubscribes !== O) {
|
|
929
|
+
for (let n = 0; n < this._unsubscribes.length; n++) {
|
|
930
|
+
const i = this._unsubscribes[n];
|
|
931
|
+
i && i();
|
|
932
|
+
}
|
|
933
|
+
j.release(this._unsubscribes), this._unsubscribes = O;
|
|
934
|
+
}
|
|
935
|
+
this._dependencies !== y && ($.release(this._dependencies), this._dependencies = y), this._dependencyVersions !== D && (A.release(this._dependencyVersions), this._dependencyVersions = D);
|
|
936
|
+
}
|
|
937
|
+
}, this.addDependency = (n) => {
|
|
938
|
+
if (this.isExecuting && this._nextDeps && this._nextUnsubs && this._nextVersions) {
|
|
939
|
+
const i = this._currentEpoch;
|
|
940
|
+
if (n._lastSeenEpoch === i) return;
|
|
941
|
+
n._lastSeenEpoch = i, this._nextDeps.push(n), this._nextVersions.push(n.version), n._tempUnsub ? (this._nextUnsubs.push(n._tempUnsub), n._tempUnsub = void 0) : this._subscribeTo(n);
|
|
942
|
+
}
|
|
943
|
+
}, this.execute = () => {
|
|
944
|
+
if (this.isDisposed || this.isExecuting || !this._shouldExecute()) return;
|
|
945
|
+
this._checkInfiniteLoop(), this._setExecuting(!0), this._safeCleanup();
|
|
946
|
+
const n = this._prepareEffectContext();
|
|
947
|
+
let i = !1;
|
|
948
|
+
try {
|
|
949
|
+
const r = q.run(this, this._fn);
|
|
950
|
+
this._commitEffect(n), i = !0, this._checkLoopWarnings(), Ue(r) ? r.then((o) => {
|
|
951
|
+
!this.isDisposed && typeof o == "function" && (this._cleanup = o);
|
|
952
|
+
}).catch((o) => {
|
|
953
|
+
console.error(G(o, M, m.EFFECT_EXECUTION_FAILED));
|
|
954
|
+
}) : this._cleanup = typeof r == "function" ? r : null;
|
|
955
|
+
} catch (r) {
|
|
956
|
+
i = !0, console.error(G(r, M, m.EFFECT_EXECUTION_FAILED)), this._cleanup = null;
|
|
957
|
+
} finally {
|
|
958
|
+
this._cleanupEffect(n, i), this._setExecuting(!1);
|
|
959
|
+
}
|
|
960
|
+
}, this._currentEpoch = -1, this._lastFlushEpoch = -1, this._executionsInEpoch = 0, this._fn = e, this._sync = s.sync ?? !1, this._maxExecutions = s.maxExecutionsPerSecond ?? V.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = s.maxExecutionsPerFlush ?? V.MAX_EXECUTIONS_PER_EFFECT, this._trackModifications = s.trackModifications ?? !1, this._cleanup = null, this._dependencies = y, this._dependencyVersions = D, this._unsubscribes = O, this._nextDeps = null, this._nextVersions = null, this._nextUnsubs = null, this._history = R ? [] : null, this._executionCount = 0, w.attachDebugInfo(this, "effect", this.id);
|
|
961
|
+
}
|
|
962
|
+
/**
|
|
963
|
+
* Prepares the execution context by acquiring pools and setting up epoch.
|
|
964
|
+
* @returns The prepared EffectContext.
|
|
965
|
+
*/
|
|
966
|
+
_prepareEffectContext() {
|
|
967
|
+
const e = this._dependencies, s = this._dependencyVersions, n = this._unsubscribes, i = $.acquire(), r = A.acquire(), o = j.acquire(), c = Te();
|
|
968
|
+
if (e !== y && n !== O)
|
|
969
|
+
for (let f = 0; f < e.length; f++) {
|
|
970
|
+
const _ = e[f];
|
|
971
|
+
_ && (_._tempUnsub = n[f]);
|
|
972
|
+
}
|
|
973
|
+
return this._nextDeps = i, this._nextVersions = r, this._nextUnsubs = o, this._currentEpoch = c, { prevDeps: e, prevVersions: s, prevUnsubs: n, nextDeps: i, nextVersions: r, nextUnsubs: o };
|
|
974
|
+
}
|
|
975
|
+
/**
|
|
976
|
+
* Commits the tracked dependencies as the current active dependencies.
|
|
977
|
+
* @param ctx - The current effect context.
|
|
978
|
+
*/
|
|
979
|
+
_commitEffect(e) {
|
|
980
|
+
const s = e.nextDeps.length;
|
|
981
|
+
e.nextDeps.length = s, e.nextVersions.length = s, this._dependencies = e.nextDeps, this._dependencyVersions = e.nextVersions, this._unsubscribes = e.nextUnsubs;
|
|
982
|
+
}
|
|
983
|
+
/**
|
|
984
|
+
* Cleans up the effect execution context, releasing resources back to pools.
|
|
985
|
+
* @param ctx - The effect context to clean up.
|
|
986
|
+
* @param committed - Whether the changes were committed to the effect.
|
|
987
|
+
*/
|
|
988
|
+
_cleanupEffect(e, s) {
|
|
989
|
+
if (this._nextDeps = null, this._nextVersions = null, this._nextUnsubs = null, s) {
|
|
990
|
+
if (e.prevDeps !== y) {
|
|
991
|
+
for (let n = 0; n < e.prevDeps.length; n++) {
|
|
992
|
+
const i = e.prevDeps[n];
|
|
993
|
+
i?._tempUnsub && (i._tempUnsub(), i._tempUnsub = void 0);
|
|
994
|
+
}
|
|
995
|
+
$.release(e.prevDeps);
|
|
996
|
+
}
|
|
997
|
+
e.prevUnsubs !== O && j.release(e.prevUnsubs), e.prevVersions !== D && A.release(e.prevVersions);
|
|
998
|
+
} else {
|
|
999
|
+
$.release(e.nextDeps), A.release(e.nextVersions);
|
|
1000
|
+
for (let n = 0; n < e.nextUnsubs.length; n++)
|
|
1001
|
+
e.nextUnsubs[n]?.();
|
|
1002
|
+
if (j.release(e.nextUnsubs), e.prevDeps !== y)
|
|
1003
|
+
for (let n = 0; n < e.prevDeps.length; n++) {
|
|
1004
|
+
const i = e.prevDeps[n];
|
|
1005
|
+
i && (i._tempUnsub = void 0);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* Subscribes to a dependency's changes.
|
|
1011
|
+
* @param dep - The dependency to subscribe to.
|
|
1012
|
+
*/
|
|
1013
|
+
_subscribeTo(e) {
|
|
1014
|
+
try {
|
|
1015
|
+
const s = e.subscribe(() => {
|
|
1016
|
+
this._trackModifications && this.isExecuting && (e._modifiedAtEpoch = this._currentEpoch), this._sync ? this.execute() : Y.schedule(this.execute);
|
|
1017
|
+
});
|
|
1018
|
+
this._nextUnsubs && this._nextUnsubs.push(s);
|
|
1019
|
+
} catch (s) {
|
|
1020
|
+
console.error(G(s, M, m.EFFECT_EXECUTION_FAILED)), this._nextUnsubs && this._nextUnsubs.push(() => {
|
|
1021
|
+
});
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* Whether the effect has been disposed.
|
|
1026
|
+
*/
|
|
1027
|
+
get isDisposed() {
|
|
1028
|
+
return (this.flags & Z.DISPOSED) !== 0;
|
|
1029
|
+
}
|
|
1030
|
+
/**
|
|
1031
|
+
* Total number of times this effect has executed.
|
|
1032
|
+
*/
|
|
1033
|
+
get executionCount() {
|
|
1034
|
+
return this._executionCount;
|
|
1035
|
+
}
|
|
1036
|
+
/**
|
|
1037
|
+
* Whether the effect is currently executing.
|
|
1038
|
+
*/
|
|
1039
|
+
get isExecuting() {
|
|
1040
|
+
return (this.flags & Z.EXECUTING) !== 0;
|
|
1041
|
+
}
|
|
1042
|
+
_setDisposed() {
|
|
1043
|
+
this.flags |= Z.DISPOSED;
|
|
1044
|
+
}
|
|
1045
|
+
_setExecuting(e) {
|
|
1046
|
+
const s = Z.EXECUTING;
|
|
1047
|
+
this.flags = this.flags & ~s | -Number(e) & s;
|
|
1048
|
+
}
|
|
1049
|
+
/**
|
|
1050
|
+
* Executes the cleanup function if it exists.
|
|
1051
|
+
*/
|
|
1052
|
+
_safeCleanup() {
|
|
1053
|
+
if (this._cleanup) {
|
|
1054
|
+
try {
|
|
1055
|
+
this._cleanup();
|
|
1056
|
+
} catch (e) {
|
|
1057
|
+
console.error(G(e, M, m.EFFECT_CLEANUP_FAILED));
|
|
1058
|
+
}
|
|
1059
|
+
this._cleanup = null;
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
/**
|
|
1063
|
+
* Checks for infinite loops by tracking execution counts within a flush and time period.
|
|
1064
|
+
* @throws {EffectError} If an infinite loop is detected.
|
|
1065
|
+
*/
|
|
1066
|
+
_checkInfiniteLoop() {
|
|
1067
|
+
if (this._lastFlushEpoch !== ne && (this._lastFlushEpoch = ne, this._executionsInEpoch = 0), this._executionsInEpoch++, this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), Je() > V.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++, this._history) {
|
|
1068
|
+
const e = Date.now();
|
|
1069
|
+
this._history.push(e), this._history.length > V.MAX_EXECUTIONS_PER_SECOND + 10 && this._history.shift(), this._checkTimestampLoop(e);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
_checkTimestampLoop(e) {
|
|
1073
|
+
const s = this._history;
|
|
1074
|
+
if (!s || this._maxExecutions <= 0) return;
|
|
1075
|
+
const n = e - Be.ONE_SECOND_MS;
|
|
1076
|
+
let i = 0;
|
|
1077
|
+
for (let r = s.length - 1; r >= 0 && !(s[r] < n); r--)
|
|
1078
|
+
i++;
|
|
1079
|
+
if (i > this._maxExecutions) {
|
|
1080
|
+
const r = new M(
|
|
1081
|
+
`Effect executed ${i} times within 1 second. Infinite loop suspected`
|
|
1082
|
+
);
|
|
1083
|
+
if (this.dispose(), console.error(r), R)
|
|
1084
|
+
throw r;
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
_throwInfiniteLoopError(e) {
|
|
1088
|
+
const s = new M(
|
|
1089
|
+
`Infinite loop detected (${e}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${fe}`
|
|
1090
|
+
);
|
|
1091
|
+
throw this.dispose(), console.error(s), s;
|
|
1092
|
+
}
|
|
1093
|
+
/**
|
|
1094
|
+
* Determines if the effect should execute based on dependency versions.
|
|
1095
|
+
* @returns true if any dependency has changed or if it's the first run.
|
|
1096
|
+
*/
|
|
1097
|
+
_shouldExecute() {
|
|
1098
|
+
if (this._dependencies === y || this._dependencyVersions === D)
|
|
1099
|
+
return !0;
|
|
1100
|
+
for (let e = 0; e < this._dependencies.length; e++) {
|
|
1101
|
+
const s = this._dependencies[e];
|
|
1102
|
+
if (s) {
|
|
1103
|
+
if ("value" in s)
|
|
1104
|
+
try {
|
|
1105
|
+
Re(() => s.value);
|
|
1106
|
+
} catch {
|
|
1107
|
+
return !0;
|
|
1108
|
+
}
|
|
1109
|
+
if (s.version !== this._dependencyVersions[e])
|
|
1110
|
+
return !0;
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
return !1;
|
|
1114
|
+
}
|
|
1115
|
+
/**
|
|
1116
|
+
* Checks for potential infinite loops where an effect modifies its own dependencies.
|
|
1117
|
+
* Only active if trackModifications is enabled and debug is on.
|
|
1118
|
+
*/
|
|
1119
|
+
_checkLoopWarnings() {
|
|
1120
|
+
if (this._trackModifications && w.enabled) {
|
|
1121
|
+
const e = this._dependencies;
|
|
1122
|
+
for (let s = 0; s < e.length; s++) {
|
|
1123
|
+
const n = e[s];
|
|
1124
|
+
n && n._modifiedAtEpoch === this._currentEpoch && w.warn(
|
|
1125
|
+
!0,
|
|
1126
|
+
`Effect is reading a dependency (${w.getDebugName(n) || "unknown"}) that it just modified. Infinite loop may occur`
|
|
1127
|
+
);
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
function I(t, e = {}) {
|
|
1133
|
+
if (typeof t != "function")
|
|
1134
|
+
throw new M(m.EFFECT_MUST_BE_FUNCTION);
|
|
1135
|
+
const s = new st(t, e);
|
|
1136
|
+
return s.execute(), s;
|
|
1137
|
+
}
|
|
1138
|
+
function b(t) {
|
|
1139
|
+
return t !== null && typeof t == "object" && "value" in t && "subscribe" in t;
|
|
1140
|
+
}
|
|
1141
|
+
function E(t) {
|
|
1142
|
+
return b(t) ? t.value : t;
|
|
1143
|
+
}
|
|
1144
|
+
function ue(t) {
|
|
1145
|
+
const e = t.jquery ? t[0] : t;
|
|
1146
|
+
if (!e) return "unknown";
|
|
1147
|
+
if (e.id) return `#${e.id}`;
|
|
1148
|
+
if (e.className) {
|
|
1149
|
+
const s = String(e.className).split(/\s+/).filter(Boolean).join(".");
|
|
1150
|
+
return s ? `${e.tagName.toLowerCase()}.${s}` : e.tagName.toLowerCase();
|
|
1151
|
+
}
|
|
1152
|
+
return e.tagName.toLowerCase();
|
|
1153
|
+
}
|
|
1154
|
+
function nt() {
|
|
1155
|
+
if (typeof window < "u") {
|
|
1156
|
+
const t = window.__ATOM_DEBUG__;
|
|
1157
|
+
if (typeof t == "boolean")
|
|
1158
|
+
return t;
|
|
1159
|
+
}
|
|
1160
|
+
try {
|
|
1161
|
+
if (typeof process < "u" && process.env && process.env.NODE_ENV === "development")
|
|
1162
|
+
return !0;
|
|
1163
|
+
} catch {
|
|
1164
|
+
}
|
|
1165
|
+
return !1;
|
|
1166
|
+
}
|
|
1167
|
+
let P = nt();
|
|
1168
|
+
const h = {
|
|
1169
|
+
get enabled() {
|
|
1170
|
+
return P;
|
|
1171
|
+
},
|
|
1172
|
+
set enabled(t) {
|
|
1173
|
+
P = t;
|
|
1174
|
+
},
|
|
1175
|
+
log(t, ...e) {
|
|
1176
|
+
P && console.log(`[atom-effect-jquery] ${t}:`, ...e);
|
|
1177
|
+
},
|
|
1178
|
+
atomChanged(t, e, s) {
|
|
1179
|
+
P && console.log(`[atom-effect-jquery] Atom "${t || "anonymous"}" changed:`, e, "→", s);
|
|
1180
|
+
},
|
|
1181
|
+
/**
|
|
1182
|
+
* Logs DOM updates and triggers visual highlight.
|
|
1183
|
+
*/
|
|
1184
|
+
domUpdated(t, e, s) {
|
|
1185
|
+
if (!P) return;
|
|
1186
|
+
const n = ue(t);
|
|
1187
|
+
console.log(`[atom-effect-jquery] DOM updated: ${n}.${e} =`, s), it(t);
|
|
1188
|
+
},
|
|
1189
|
+
cleanup(t) {
|
|
1190
|
+
P && console.log(`[atom-effect-jquery] Cleanup: ${t}`);
|
|
1191
|
+
},
|
|
1192
|
+
warn(...t) {
|
|
1193
|
+
P && console.warn("[atom-effect-jquery]", ...t);
|
|
1194
|
+
}
|
|
1195
|
+
};
|
|
1196
|
+
function it(t) {
|
|
1197
|
+
const e = t[0];
|
|
1198
|
+
if (!e || !document.contains(e)) return;
|
|
1199
|
+
const s = "atom_debug_timer", n = "atom_debug_cleanup_timer", i = "atom_debug_org_style";
|
|
1200
|
+
clearTimeout(t.data(s)), clearTimeout(t.data(n)), t.data(i) || t.data(i, {
|
|
1201
|
+
outline: t.css("outline"),
|
|
1202
|
+
outlineOffset: t.css("outline-offset"),
|
|
1203
|
+
transition: t.css("transition")
|
|
1204
|
+
}), t.css({
|
|
1205
|
+
outline: "2px solid rgba(255, 68, 68, 0.8)",
|
|
1206
|
+
"outline-offset": "1px",
|
|
1207
|
+
transition: "none"
|
|
1208
|
+
// Remove transition for instant feedback on update
|
|
1209
|
+
});
|
|
1210
|
+
const r = setTimeout(() => {
|
|
1211
|
+
const o = t.data(i);
|
|
1212
|
+
t.css("transition", "outline 0.5s ease-out"), requestAnimationFrame(() => {
|
|
1213
|
+
t.css({
|
|
1214
|
+
outline: o?.outline || "",
|
|
1215
|
+
"outline-offset": o?.outlineOffset || ""
|
|
1216
|
+
});
|
|
1217
|
+
const c = setTimeout(() => {
|
|
1218
|
+
t.css("transition", o?.transition || ""), t.removeData(s), t.removeData(n), t.removeData(i);
|
|
1219
|
+
}, 500);
|
|
1220
|
+
t.data(n, c);
|
|
1221
|
+
});
|
|
1222
|
+
}, 100);
|
|
1223
|
+
t.data(s, r);
|
|
1224
|
+
}
|
|
1225
|
+
const rt = /* @__PURE__ */ new WeakMap();
|
|
1226
|
+
function Fe(t, e = {}) {
|
|
1227
|
+
const s = Ze(t, e);
|
|
1228
|
+
return e.name && rt.set(s, { name: e.name }), s;
|
|
1229
|
+
}
|
|
1230
|
+
Object.defineProperty(Fe, "debug", {
|
|
1231
|
+
get() {
|
|
1232
|
+
return h.enabled;
|
|
1233
|
+
},
|
|
1234
|
+
set(t) {
|
|
1235
|
+
h.enabled = t;
|
|
1236
|
+
}
|
|
1237
|
+
});
|
|
1238
|
+
function ot() {
|
|
1239
|
+
return new Promise((t) => setTimeout(t, 0));
|
|
1240
|
+
}
|
|
1241
|
+
u.extend({
|
|
1242
|
+
atom: Fe,
|
|
1243
|
+
computed: tt,
|
|
1244
|
+
effect: I,
|
|
1245
|
+
batch: z,
|
|
1246
|
+
untracked: Re,
|
|
1247
|
+
isAtom: le,
|
|
1248
|
+
isComputed: De,
|
|
1249
|
+
isReactive: (t) => le(t) || De(t),
|
|
1250
|
+
nextTick: ot
|
|
1251
|
+
});
|
|
1252
|
+
function Me() {
|
|
1253
|
+
return { timeoutId: null, phase: "idle", hasFocus: !1 };
|
|
1254
|
+
}
|
|
1255
|
+
function $e(t, e, s = {}) {
|
|
1256
|
+
const {
|
|
1257
|
+
debounce: n,
|
|
1258
|
+
event: i = "input",
|
|
1259
|
+
parse: r = (p) => p,
|
|
1260
|
+
format: o = (p) => String(p ?? "")
|
|
1261
|
+
} = s, c = Me(), f = () => {
|
|
1262
|
+
c.phase = "composing";
|
|
1263
|
+
}, _ = () => {
|
|
1264
|
+
c.phase = "idle", F();
|
|
1265
|
+
};
|
|
1266
|
+
t.on("compositionstart", f), t.on("compositionend", _);
|
|
1267
|
+
const C = () => {
|
|
1268
|
+
c.hasFocus = !0;
|
|
1269
|
+
}, S = () => {
|
|
1270
|
+
c.hasFocus = !1;
|
|
1271
|
+
const p = o(e.value);
|
|
1272
|
+
t.val() !== p && t.val(p);
|
|
1273
|
+
};
|
|
1274
|
+
t.on("focus", C), t.on("blur", S);
|
|
1275
|
+
const F = () => {
|
|
1276
|
+
c.phase === "idle" && (c.phase = "syncing-to-atom", z(() => {
|
|
1277
|
+
e.value = r(t.val());
|
|
1278
|
+
}), c.phase = "idle");
|
|
1279
|
+
}, v = () => {
|
|
1280
|
+
c.phase === "idle" && (n ? (c.timeoutId && clearTimeout(c.timeoutId), c.timeoutId = window.setTimeout(F, n)) : F());
|
|
1281
|
+
};
|
|
1282
|
+
return t.on(i, v), t.on("change", v), { effect: () => {
|
|
1283
|
+
const p = o(e.value), L = t.val();
|
|
1284
|
+
if (L !== p) {
|
|
1285
|
+
if (c.hasFocus && r(L) === e.value)
|
|
1286
|
+
return;
|
|
1287
|
+
c.phase = "syncing-to-dom", t.val(p), h.domUpdated(t, "val", p), c.phase = "idle";
|
|
1288
|
+
}
|
|
1289
|
+
}, cleanup: () => {
|
|
1290
|
+
t.off(i, v), t.off("change", v), t.off("compositionstart", f), t.off("compositionend", _), t.off("focus", C), t.off("blur", S), c.timeoutId && clearTimeout(c.timeoutId);
|
|
1291
|
+
} };
|
|
1292
|
+
}
|
|
1293
|
+
class ct {
|
|
1294
|
+
// DOM Element -> Effect Array (for disposal)
|
|
1295
|
+
effects = /* @__PURE__ */ new WeakMap();
|
|
1296
|
+
// DOM Element -> Custom Cleanup Function Array
|
|
1297
|
+
cleanups = /* @__PURE__ */ new WeakMap();
|
|
1298
|
+
// Track bound elements (Performance optimization)
|
|
1299
|
+
boundElements = /* @__PURE__ */ new WeakSet();
|
|
1300
|
+
/**
|
|
1301
|
+
* Tracks elements that are temporarily detached (e.g. via .detach())
|
|
1302
|
+
* so they are NOT cleaned up by the MutationObserver.
|
|
1303
|
+
*/
|
|
1304
|
+
preservedNodes = /* @__PURE__ */ new WeakSet();
|
|
1305
|
+
keep(e) {
|
|
1306
|
+
this.preservedNodes.add(e);
|
|
1307
|
+
}
|
|
1308
|
+
isKept(e) {
|
|
1309
|
+
return this.preservedNodes.has(e);
|
|
1310
|
+
}
|
|
1311
|
+
/**
|
|
1312
|
+
* Registers an Effect to be disposed later.
|
|
1313
|
+
*/
|
|
1314
|
+
trackEffect(e, s) {
|
|
1315
|
+
const n = this.effects.get(e) || [];
|
|
1316
|
+
n.push(s), this.effects.set(e, n), this.boundElements.add(e);
|
|
1317
|
+
}
|
|
1318
|
+
/**
|
|
1319
|
+
* Registers a custom cleanup function (e.g., event listener removal).
|
|
1320
|
+
*/
|
|
1321
|
+
trackCleanup(e, s) {
|
|
1322
|
+
const n = this.cleanups.get(e) || [];
|
|
1323
|
+
n.push(s), this.cleanups.set(e, n), this.boundElements.add(e);
|
|
1324
|
+
}
|
|
1325
|
+
/**
|
|
1326
|
+
* Checks if an element has bindings (Fast check).
|
|
1327
|
+
*/
|
|
1328
|
+
hasBind(e) {
|
|
1329
|
+
return this.boundElements.has(e);
|
|
1330
|
+
}
|
|
1331
|
+
/**
|
|
1332
|
+
* Cleans up a single element.
|
|
1333
|
+
* - Disposes all Effects (severs connection with Atom).
|
|
1334
|
+
* - Executes all custom cleanups.
|
|
1335
|
+
*/
|
|
1336
|
+
cleanup(e) {
|
|
1337
|
+
if (!this.boundElements.has(e)) return;
|
|
1338
|
+
h.cleanup(ue(e));
|
|
1339
|
+
const s = this.effects.get(e);
|
|
1340
|
+
s && (this.effects.delete(e), s.forEach((i) => {
|
|
1341
|
+
try {
|
|
1342
|
+
i.dispose();
|
|
1343
|
+
} catch (r) {
|
|
1344
|
+
h.warn("Effect dispose error:", r);
|
|
1345
|
+
}
|
|
1346
|
+
}));
|
|
1347
|
+
const n = this.cleanups.get(e);
|
|
1348
|
+
n && (this.cleanups.delete(e), n.forEach((i) => {
|
|
1349
|
+
try {
|
|
1350
|
+
i();
|
|
1351
|
+
} catch (r) {
|
|
1352
|
+
h.warn("Cleanup error:", r);
|
|
1353
|
+
}
|
|
1354
|
+
})), this.boundElements.delete(e);
|
|
1355
|
+
}
|
|
1356
|
+
/**
|
|
1357
|
+
* Cleans up the element and all its descendants (Recursive).
|
|
1358
|
+
* - Essential for deep removal (empty(), remove(), etc.).
|
|
1359
|
+
*/
|
|
1360
|
+
cleanupTree(e) {
|
|
1361
|
+
e.querySelectorAll("*").forEach((n) => {
|
|
1362
|
+
this.boundElements.has(n) && this.cleanup(n);
|
|
1363
|
+
}), this.cleanup(e);
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
const l = new ct();
|
|
1367
|
+
let J = null;
|
|
1368
|
+
function ut(t = document.body) {
|
|
1369
|
+
J || (J = new MutationObserver((e) => {
|
|
1370
|
+
for (const s of e)
|
|
1371
|
+
s.removedNodes.forEach((n) => {
|
|
1372
|
+
l.isKept(n) || n.isConnected || n.nodeType === 1 && l.cleanupTree(n);
|
|
1373
|
+
});
|
|
1374
|
+
}), J.observe(t, { childList: !0, subtree: !0 }));
|
|
1375
|
+
}
|
|
1376
|
+
function Dt() {
|
|
1377
|
+
J?.disconnect(), J = null;
|
|
1378
|
+
}
|
|
1379
|
+
u.fn.atomText = function(t, e) {
|
|
1380
|
+
return this.each(function() {
|
|
1381
|
+
const s = u(this);
|
|
1382
|
+
if (b(t)) {
|
|
1383
|
+
const n = I(() => {
|
|
1384
|
+
const i = E(t), r = e ? e(i) : String(i ?? "");
|
|
1385
|
+
s.text(r), h.domUpdated(s, "text", r);
|
|
1386
|
+
});
|
|
1387
|
+
l.trackEffect(this, n);
|
|
1388
|
+
} else {
|
|
1389
|
+
const n = e ? e(t) : String(t ?? "");
|
|
1390
|
+
s.text(n);
|
|
1391
|
+
}
|
|
1392
|
+
});
|
|
1393
|
+
};
|
|
1394
|
+
u.fn.atomHtml = function(t) {
|
|
1395
|
+
return this.each(function() {
|
|
1396
|
+
const e = u(this);
|
|
1397
|
+
if (b(t)) {
|
|
1398
|
+
const s = I(() => {
|
|
1399
|
+
const n = String(E(t) ?? "");
|
|
1400
|
+
e.html(n), h.domUpdated(e, "html", n);
|
|
1401
|
+
});
|
|
1402
|
+
l.trackEffect(this, s);
|
|
1403
|
+
} else
|
|
1404
|
+
e.html(String(t ?? ""));
|
|
1405
|
+
});
|
|
1406
|
+
};
|
|
1407
|
+
u.fn.atomClass = function(t, e) {
|
|
1408
|
+
return this.each(function() {
|
|
1409
|
+
const s = u(this);
|
|
1410
|
+
if (b(e)) {
|
|
1411
|
+
const n = I(() => {
|
|
1412
|
+
const i = !!E(e);
|
|
1413
|
+
s.toggleClass(t, i), h.domUpdated(s, `class.${t}`, i);
|
|
1414
|
+
});
|
|
1415
|
+
l.trackEffect(this, n);
|
|
1416
|
+
} else
|
|
1417
|
+
s.toggleClass(t, !!e);
|
|
1418
|
+
});
|
|
1419
|
+
};
|
|
1420
|
+
u.fn.atomCss = function(t, e, s) {
|
|
1421
|
+
return this.each(function() {
|
|
1422
|
+
const n = u(this);
|
|
1423
|
+
if (b(e)) {
|
|
1424
|
+
const i = I(() => {
|
|
1425
|
+
const r = E(e), o = s ? `${r}${s}` : r;
|
|
1426
|
+
n.css(t, o), h.domUpdated(n, `css.${t}`, o);
|
|
1427
|
+
});
|
|
1428
|
+
l.trackEffect(this, i);
|
|
1429
|
+
} else
|
|
1430
|
+
n.css(t, s ? `${e}${s}` : e);
|
|
1431
|
+
});
|
|
1432
|
+
};
|
|
1433
|
+
u.fn.atomAttr = function(t, e) {
|
|
1434
|
+
return this.each(function() {
|
|
1435
|
+
const s = u(this), n = (i) => {
|
|
1436
|
+
i == null || i === !1 ? s.removeAttr(t) : i === !0 ? s.attr(t, t) : s.attr(t, String(i)), h.domUpdated(s, `attr.${t}`, i);
|
|
1437
|
+
};
|
|
1438
|
+
if (b(e)) {
|
|
1439
|
+
const i = I(() => n(E(e)));
|
|
1440
|
+
l.trackEffect(this, i);
|
|
1441
|
+
} else
|
|
1442
|
+
n(e);
|
|
1443
|
+
});
|
|
1444
|
+
};
|
|
1445
|
+
u.fn.atomProp = function(t, e) {
|
|
1446
|
+
return this.each(function() {
|
|
1447
|
+
const s = u(this);
|
|
1448
|
+
if (b(e)) {
|
|
1449
|
+
const n = I(() => {
|
|
1450
|
+
const i = E(e);
|
|
1451
|
+
s.prop(t, i), h.domUpdated(s, `prop.${t}`, i);
|
|
1452
|
+
});
|
|
1453
|
+
l.trackEffect(this, n);
|
|
1454
|
+
} else
|
|
1455
|
+
s.prop(t, e);
|
|
1456
|
+
});
|
|
1457
|
+
};
|
|
1458
|
+
u.fn.atomShow = function(t) {
|
|
1459
|
+
return this.each(function() {
|
|
1460
|
+
const e = u(this);
|
|
1461
|
+
if (b(t)) {
|
|
1462
|
+
const s = I(() => {
|
|
1463
|
+
const n = !!E(t);
|
|
1464
|
+
e.toggle(n), h.domUpdated(e, "show", n);
|
|
1465
|
+
});
|
|
1466
|
+
l.trackEffect(this, s);
|
|
1467
|
+
} else
|
|
1468
|
+
e.toggle(!!t);
|
|
1469
|
+
});
|
|
1470
|
+
};
|
|
1471
|
+
u.fn.atomHide = function(t) {
|
|
1472
|
+
return this.each(function() {
|
|
1473
|
+
const e = u(this);
|
|
1474
|
+
if (b(t)) {
|
|
1475
|
+
const s = I(() => {
|
|
1476
|
+
const n = !E(t);
|
|
1477
|
+
e.toggle(n), h.domUpdated(e, "hide", !n);
|
|
1478
|
+
});
|
|
1479
|
+
l.trackEffect(this, s);
|
|
1480
|
+
} else
|
|
1481
|
+
e.toggle(!t);
|
|
1482
|
+
});
|
|
1483
|
+
};
|
|
1484
|
+
u.fn.atomVal = function(t, e = {}) {
|
|
1485
|
+
return this.each(function() {
|
|
1486
|
+
const { effect: s, cleanup: n } = $e(u(this), t, e), i = I(s);
|
|
1487
|
+
l.trackEffect(this, i), l.trackCleanup(this, n);
|
|
1488
|
+
});
|
|
1489
|
+
};
|
|
1490
|
+
u.fn.atomChecked = function(t) {
|
|
1491
|
+
return this.each(function() {
|
|
1492
|
+
const e = u(this);
|
|
1493
|
+
let s = !1;
|
|
1494
|
+
const n = () => {
|
|
1495
|
+
s || z(() => {
|
|
1496
|
+
t.value = e.prop("checked");
|
|
1497
|
+
});
|
|
1498
|
+
};
|
|
1499
|
+
e.on("change", n), l.trackCleanup(this, () => e.off("change", n));
|
|
1500
|
+
const i = I(() => {
|
|
1501
|
+
s = !0, e.prop("checked", t.value), h.domUpdated(e, "checked", t.value), s = !1;
|
|
1502
|
+
});
|
|
1503
|
+
l.trackEffect(this, i);
|
|
1504
|
+
});
|
|
1505
|
+
};
|
|
1506
|
+
u.fn.atomOn = function(t, e) {
|
|
1507
|
+
return this.each(function() {
|
|
1508
|
+
const s = u(this), n = function(i) {
|
|
1509
|
+
z(() => e.call(this, i));
|
|
1510
|
+
};
|
|
1511
|
+
s.on(t, n), l.trackCleanup(this, () => s.off(t, n));
|
|
1512
|
+
});
|
|
1513
|
+
};
|
|
1514
|
+
u.fn.atomUnbind = function() {
|
|
1515
|
+
return this.each(function() {
|
|
1516
|
+
l.cleanupTree(this);
|
|
1517
|
+
});
|
|
1518
|
+
};
|
|
1519
|
+
function ht(t, e) {
|
|
1520
|
+
b(e) ? t.effects.push(() => {
|
|
1521
|
+
const s = String(E(e) ?? "");
|
|
1522
|
+
t.$el.text(s), h.domUpdated(t.$el, "text", s);
|
|
1523
|
+
}) : t.$el.text(String(e ?? ""));
|
|
1524
|
+
}
|
|
1525
|
+
function at(t, e) {
|
|
1526
|
+
b(e) ? t.effects.push(() => {
|
|
1527
|
+
const s = String(E(e) ?? "");
|
|
1528
|
+
t.$el.html(s), h.domUpdated(t.$el, "html", s);
|
|
1529
|
+
}) : t.$el.html(String(e ?? ""));
|
|
1530
|
+
}
|
|
1531
|
+
function lt(t, e) {
|
|
1532
|
+
for (const [s, n] of Object.entries(e))
|
|
1533
|
+
b(n) ? t.effects.push(() => {
|
|
1534
|
+
const i = !!E(n);
|
|
1535
|
+
t.$el.toggleClass(s, i), h.domUpdated(t.$el, `class.${s}`, i);
|
|
1536
|
+
}) : t.$el.toggleClass(s, !!n);
|
|
1537
|
+
}
|
|
1538
|
+
function ft(t, e) {
|
|
1539
|
+
for (const [s, n] of Object.entries(e))
|
|
1540
|
+
if (Array.isArray(n)) {
|
|
1541
|
+
const [i, r] = n;
|
|
1542
|
+
b(i) ? t.effects.push(() => {
|
|
1543
|
+
const o = `${E(i)}${r}`;
|
|
1544
|
+
t.$el.css(s, o), h.domUpdated(t.$el, `css.${s}`, o);
|
|
1545
|
+
}) : t.$el.css(s, `${i}${r}`);
|
|
1546
|
+
} else b(n) ? t.effects.push(() => {
|
|
1547
|
+
const i = E(n);
|
|
1548
|
+
t.$el.css(s, i), h.domUpdated(t.$el, `css.${s}`, i);
|
|
1549
|
+
}) : t.$el.css(s, n);
|
|
1550
|
+
}
|
|
1551
|
+
function dt(t, e) {
|
|
1552
|
+
for (const [s, n] of Object.entries(e)) {
|
|
1553
|
+
const i = (r) => {
|
|
1554
|
+
r == null || r === !1 ? t.$el.removeAttr(s) : r === !0 ? t.$el.attr(s, s) : t.$el.attr(s, String(r)), h.domUpdated(t.$el, `attr.${s}`, r);
|
|
1555
|
+
};
|
|
1556
|
+
b(n) ? t.effects.push(() => i(E(n))) : i(n);
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
function _t(t, e) {
|
|
1560
|
+
for (const [s, n] of Object.entries(e))
|
|
1561
|
+
b(n) ? t.effects.push(() => {
|
|
1562
|
+
const i = E(n);
|
|
1563
|
+
t.$el.prop(s, i), h.domUpdated(t.$el, `prop.${s}`, i);
|
|
1564
|
+
}) : t.$el.prop(s, n);
|
|
1565
|
+
}
|
|
1566
|
+
function pt(t, e) {
|
|
1567
|
+
b(e) ? t.effects.push(() => {
|
|
1568
|
+
const s = !!E(e);
|
|
1569
|
+
t.$el.toggle(s), h.domUpdated(t.$el, "show", s);
|
|
1570
|
+
}) : t.$el.toggle(!!e);
|
|
1571
|
+
}
|
|
1572
|
+
function bt(t, e) {
|
|
1573
|
+
b(e) ? t.effects.push(() => {
|
|
1574
|
+
const s = !E(e);
|
|
1575
|
+
t.$el.toggle(s), h.domUpdated(t.$el, "hide", !s);
|
|
1576
|
+
}) : t.$el.toggle(!e);
|
|
1577
|
+
}
|
|
1578
|
+
function Et(t, e) {
|
|
1579
|
+
const s = Array.isArray(e) ? e[0] : e, n = Array.isArray(e) ? e[1] : {}, { effect: i, cleanup: r } = $e(t.$el, s, n);
|
|
1580
|
+
t.effects.push(i), t.trackCleanup(r);
|
|
1581
|
+
}
|
|
1582
|
+
function gt(t, e) {
|
|
1583
|
+
const s = Me(), n = () => {
|
|
1584
|
+
s.phase === "idle" && z(() => {
|
|
1585
|
+
e.value = t.$el.prop("checked");
|
|
1586
|
+
});
|
|
1587
|
+
};
|
|
1588
|
+
t.$el.on("change", n), t.trackCleanup(() => t.$el.off("change", n)), t.effects.push(() => {
|
|
1589
|
+
s.phase = "syncing-to-dom", t.$el.prop("checked", e.value), h.domUpdated(t.$el, "checked", e.value), s.phase = "idle";
|
|
1590
|
+
});
|
|
1591
|
+
}
|
|
1592
|
+
function mt(t, e) {
|
|
1593
|
+
for (const [s, n] of Object.entries(e)) {
|
|
1594
|
+
const i = function(r) {
|
|
1595
|
+
z(() => n.call(this, r));
|
|
1596
|
+
};
|
|
1597
|
+
t.$el.on(s, i), t.trackCleanup(() => t.$el.off(s, i));
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
u.fn.atomBind = function(t) {
|
|
1601
|
+
return this.each(function() {
|
|
1602
|
+
const e = u(this), s = [], n = {
|
|
1603
|
+
$el: e,
|
|
1604
|
+
el: this,
|
|
1605
|
+
effects: s,
|
|
1606
|
+
trackCleanup: (i) => l.trackCleanup(this, i)
|
|
1607
|
+
};
|
|
1608
|
+
t.text !== void 0 && ht(n, t.text), t.html !== void 0 && at(n, t.html), t.class && lt(n, t.class), t.css && ft(n, t.css), t.attr && dt(n, t.attr), t.prop && _t(n, t.prop), t.show !== void 0 && pt(n, t.show), t.hide !== void 0 && bt(n, t.hide), t.val !== void 0 && Et(n, t.val), t.checked !== void 0 && gt(n, t.checked), t.on && mt(n, t.on), s.forEach((i) => {
|
|
1609
|
+
const r = I(i);
|
|
1610
|
+
l.trackEffect(this, r);
|
|
1611
|
+
});
|
|
1612
|
+
});
|
|
1613
|
+
};
|
|
1614
|
+
function St(t) {
|
|
1615
|
+
if (t.length === 0) return [];
|
|
1616
|
+
const e = t.slice(), s = [0];
|
|
1617
|
+
let n, i, r, o;
|
|
1618
|
+
const c = t.length;
|
|
1619
|
+
for (n = 0; n < c; n++) {
|
|
1620
|
+
const C = t[n];
|
|
1621
|
+
if (C !== -1) {
|
|
1622
|
+
const S = s[s.length - 1];
|
|
1623
|
+
if (t[S] < C) {
|
|
1624
|
+
e[n] = S, s.push(n);
|
|
1625
|
+
continue;
|
|
1626
|
+
}
|
|
1627
|
+
for (i = 0, r = s.length - 1; i < r; )
|
|
1628
|
+
o = (i + r) / 2 | 0, t[s[o]] < C ? i = o + 1 : r = o;
|
|
1629
|
+
C < t[s[i]] && (i > 0 && (e[n] = s[i - 1]), s[i] = n);
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
let f = s.length, _ = s[f - 1];
|
|
1633
|
+
for (; f-- > 0; )
|
|
1634
|
+
s[f] = _, _ = e[_];
|
|
1635
|
+
return s;
|
|
1636
|
+
}
|
|
1637
|
+
u.fn.atomList = function(t, e) {
|
|
1638
|
+
return this.each(function() {
|
|
1639
|
+
const s = u(this), n = ue(this), { key: i, render: r, bind: o, onAdd: c, onRemove: f, empty: _ } = e, C = typeof i == "function" ? i : (p) => p[i], S = /* @__PURE__ */ new Map();
|
|
1640
|
+
let F = [], v = null;
|
|
1641
|
+
const K = /* @__PURE__ */ new Set(), _e = I(() => {
|
|
1642
|
+
const p = t.value, L = [], pe = /* @__PURE__ */ new Set();
|
|
1643
|
+
for (let a = 0; a < p.length; a++) {
|
|
1644
|
+
const g = p[a], T = C(g, a);
|
|
1645
|
+
L.push(T), pe.add(T);
|
|
1646
|
+
}
|
|
1647
|
+
if (h.log("list", `${n} updating with ${p.length} items`), p.length === 0 && _) {
|
|
1648
|
+
v || (v = u(_), s.append(v));
|
|
1649
|
+
for (const [, a] of S) {
|
|
1650
|
+
a.$el.remove();
|
|
1651
|
+
const g = a.$el[0];
|
|
1652
|
+
g && l.cleanup(g);
|
|
1653
|
+
}
|
|
1654
|
+
S.clear(), F = [];
|
|
1655
|
+
return;
|
|
1656
|
+
} else v && (v.remove(), v = null);
|
|
1657
|
+
for (const [a, g] of S)
|
|
1658
|
+
if (!pe.has(a)) {
|
|
1659
|
+
if (K.has(a)) continue;
|
|
1660
|
+
const T = () => {
|
|
1661
|
+
g.$el.remove();
|
|
1662
|
+
const W = g.$el[0];
|
|
1663
|
+
W && l.cleanup(W), K.delete(a), h.log("list", `${n} removed item:`, a);
|
|
1664
|
+
};
|
|
1665
|
+
S.delete(a), K.add(a), f ? Promise.resolve(f(g.$el)).then(T) : T();
|
|
1666
|
+
}
|
|
1667
|
+
const be = /* @__PURE__ */ new Map();
|
|
1668
|
+
F.forEach((a, g) => be.set(a, g));
|
|
1669
|
+
const Pe = L.map((a) => be.get(a) ?? -1), Ve = St(Pe), je = new Set(Ve);
|
|
1670
|
+
let U = null;
|
|
1671
|
+
for (let a = p.length - 1; a >= 0; a--) {
|
|
1672
|
+
const g = L[a], T = p[a], W = je.has(a);
|
|
1673
|
+
if (S.has(g)) {
|
|
1674
|
+
const N = S.get(g);
|
|
1675
|
+
if (!N) continue;
|
|
1676
|
+
N.item = T;
|
|
1677
|
+
const x = N.$el[0];
|
|
1678
|
+
if (!x) continue;
|
|
1679
|
+
if (e.update && e.update(N.$el, T, a), !W)
|
|
1680
|
+
U ? N.$el.insertBefore(U) : N.$el.appendTo(s);
|
|
1681
|
+
else {
|
|
1682
|
+
const Q = x.nextSibling;
|
|
1683
|
+
U && Q !== U ? N.$el.insertBefore(U) : !U && Q && N.$el.appendTo(s);
|
|
1684
|
+
}
|
|
1685
|
+
U = x;
|
|
1686
|
+
} else {
|
|
1687
|
+
const N = r(T, a), x = N instanceof Element ? u(N) : u(N);
|
|
1688
|
+
S.set(g, { $el: x, item: T }), U ? x.insertBefore(U) : x.appendTo(s), o && o(x, T, a), c && c(x), h.log("list", `${n} added item:`, g);
|
|
1689
|
+
const Q = x[0];
|
|
1690
|
+
Q && (U = Q);
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
F = L;
|
|
1694
|
+
});
|
|
1695
|
+
l.trackEffect(this, _e), l.trackCleanup(this, () => {
|
|
1696
|
+
S.clear(), F = [], v?.remove();
|
|
1697
|
+
});
|
|
1698
|
+
});
|
|
1699
|
+
};
|
|
1700
|
+
const se = /* @__PURE__ */ new WeakMap();
|
|
1701
|
+
u.fn.atomMount = function(t, e = {}) {
|
|
1702
|
+
return this.each(function() {
|
|
1703
|
+
const s = u(this), n = ue(this), i = se.get(this);
|
|
1704
|
+
i && (h.log("mount", `${n} unmounting existing component`), i()), h.log("mount", `${n} mounting component`);
|
|
1705
|
+
let r;
|
|
1706
|
+
try {
|
|
1707
|
+
r = t(s, e);
|
|
1708
|
+
} catch (f) {
|
|
1709
|
+
console.error("[atom-effect-jquery] Mount error:", f);
|
|
1710
|
+
return;
|
|
1711
|
+
}
|
|
1712
|
+
let o = !1;
|
|
1713
|
+
const c = () => {
|
|
1714
|
+
if (!o) {
|
|
1715
|
+
if (o = !0, h.log("mount", `${n} full cleanup`), typeof r == "function")
|
|
1716
|
+
try {
|
|
1717
|
+
r();
|
|
1718
|
+
} catch {
|
|
1719
|
+
}
|
|
1720
|
+
l.cleanupTree(this), se.delete(this);
|
|
1721
|
+
}
|
|
1722
|
+
};
|
|
1723
|
+
se.set(this, c), l.trackCleanup(this, c);
|
|
1724
|
+
});
|
|
1725
|
+
};
|
|
1726
|
+
u.fn.atomUnmount = function() {
|
|
1727
|
+
return this.each(function() {
|
|
1728
|
+
se.get(this)?.();
|
|
1729
|
+
});
|
|
1730
|
+
};
|
|
1731
|
+
const H = /* @__PURE__ */ new WeakMap();
|
|
1732
|
+
let Ie = !1;
|
|
1733
|
+
function Le() {
|
|
1734
|
+
if (Ie) return;
|
|
1735
|
+
Ie = !0;
|
|
1736
|
+
const t = u.fn.on, e = u.fn.off, s = u.fn.remove, n = u.fn.empty, i = u.fn.detach;
|
|
1737
|
+
u.fn.remove = function(r) {
|
|
1738
|
+
return (r ? this.filter(r) : this).each(function() {
|
|
1739
|
+
l.cleanupTree(this);
|
|
1740
|
+
}), s.call(this, r);
|
|
1741
|
+
}, u.fn.empty = function() {
|
|
1742
|
+
return this.each(function() {
|
|
1743
|
+
this.querySelectorAll("*").forEach((o) => l.cleanup(o));
|
|
1744
|
+
}), n.call(this);
|
|
1745
|
+
}, u.fn.detach = function(r) {
|
|
1746
|
+
return (r ? this.filter(r) : this).each(function() {
|
|
1747
|
+
l.keep(this);
|
|
1748
|
+
}), i.call(this, r);
|
|
1749
|
+
}, u.fn.on = function(...r) {
|
|
1750
|
+
let o = -1;
|
|
1751
|
+
for (let c = r.length - 1; c >= 0; c--)
|
|
1752
|
+
if (typeof r[c] == "function") {
|
|
1753
|
+
o = c;
|
|
1754
|
+
break;
|
|
1755
|
+
}
|
|
1756
|
+
if (o !== -1) {
|
|
1757
|
+
const c = r[o];
|
|
1758
|
+
let f;
|
|
1759
|
+
H.has(c) ? f = H.get(c) : (f = function(..._) {
|
|
1760
|
+
let C;
|
|
1761
|
+
return z(() => {
|
|
1762
|
+
C = c.apply(this, _);
|
|
1763
|
+
}), C;
|
|
1764
|
+
}, H.set(c, f)), r[o] = f;
|
|
1765
|
+
}
|
|
1766
|
+
return t.apply(this, r);
|
|
1767
|
+
}, u.fn.off = function(...r) {
|
|
1768
|
+
let o = -1;
|
|
1769
|
+
for (let c = r.length - 1; c >= 0; c--)
|
|
1770
|
+
if (typeof r[c] == "function") {
|
|
1771
|
+
o = c;
|
|
1772
|
+
break;
|
|
1773
|
+
}
|
|
1774
|
+
if (o !== -1) {
|
|
1775
|
+
const c = r[o];
|
|
1776
|
+
H.has(c) && (r[o] = H.get(c));
|
|
1777
|
+
}
|
|
1778
|
+
return e.apply(this, r);
|
|
1779
|
+
};
|
|
1780
|
+
}
|
|
1781
|
+
const It = Le;
|
|
1782
|
+
Le();
|
|
1783
|
+
u(() => {
|
|
1784
|
+
ut(document.body);
|
|
1785
|
+
});
|
|
1786
|
+
export {
|
|
1787
|
+
Ze as atom,
|
|
1788
|
+
z as batch,
|
|
1789
|
+
tt as computed,
|
|
1790
|
+
Nt as default,
|
|
1791
|
+
Dt as disableAutoCleanup,
|
|
1792
|
+
I as effect,
|
|
1793
|
+
ut as enableAutoCleanup,
|
|
1794
|
+
It as enablejQueryBatching,
|
|
1795
|
+
Le as enablejQueryOverrides,
|
|
1796
|
+
l as registry,
|
|
1797
|
+
Re as untracked
|
|
1798
|
+
};
|
|
1799
|
+
//# sourceMappingURL=index.mjs.map
|