@but212/atom-effect-jquery 0.32.0 → 0.32.1

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.
@@ -10,7 +10,11 @@ import { FormOptions } from '../types';
10
10
  * browser-native APIs.
11
11
  *
12
12
  * @param form - The target form element to bind.
13
- * @param atom - A writable atom containing the state model.
13
+ * @param atom - A writable atom or an array of atoms.
14
+ * Logic: Polymorphic Input
15
+ * If an array is provided, it is merged via `mergeLenses`.
16
+ * Note: When merging, later atoms in the array override
17
+ * properties with the same path from earlier atoms.
14
18
  * @param options - Configuration for transformations and reactive validation.
15
19
  *
16
20
  * @example
@@ -25,5 +29,5 @@ import { FormOptions } from '../types';
25
29
  * });
26
30
  * ```
27
31
  */
28
- export declare function bindForm<T extends object>(form: HTMLFormElement, atom: WritableAtom<T>, options?: FormOptions<unknown>): void;
32
+ export declare function bindForm<T extends object>(form: HTMLFormElement, atom: WritableAtom<T> | WritableAtom<unknown>[], options?: FormOptions<unknown>): void;
29
33
  //# sourceMappingURL=form.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../src/bindings/form.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,YAAY,EAClB,MAAM,qBAAqB,CAAC;AAI7B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AA0S3C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,EACvC,IAAI,EAAE,eAAe,EACrB,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,EACrB,OAAO,GAAE,WAAW,CAAC,OAAO,CAAM,GACjC,IAAI,CAGN"}
1
+ {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../src/bindings/form.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,YAAY,EAClB,MAAM,qBAAqB,CAAC;AAI7B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAmZ3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,EACvC,IAAI,EAAE,eAAe,EACrB,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,EAAE,EAC/C,OAAO,GAAE,WAAW,CAAC,OAAO,CAAM,GACjC,IAAI,CAIN"}
@@ -1,61 +1,82 @@
1
1
  import { EffectObject, ListKey } from '../../types';
2
2
  /**
3
- * Manages the reconciliation state and lifecycle for the `$.fn.atomList` binding.
3
+ * Represents the state of a single list item at a point in time.
4
+ * Used by the reconciler to calculate moves, updates, and removals.
5
+ */
6
+ export interface ListSnapshot<T> {
7
+ key: ListKey;
8
+ item: T;
9
+ /** The actual DOM element or JQuery wrapper currently representing this item. */
10
+ node?: Element | JQuery | undefined;
11
+ }
12
+ /**
13
+ * Persistent state for the `$.fn.atomList` binding.
4
14
  *
5
- * This context tracks historical DOM nodes and keys to enable efficient diffing.
6
- * Its primary responsibility is coordinating asynchronous item removals (e.g., animations)
7
- * while ensuring that elements reused in the same cycle are not accidentally destroyed.
15
+ * WHY:
16
+ * Reactive lists require a stable reference to track historical DOM nodes across
17
+ * multiple rendering cycles. Using a POJO (Plain Old JavaScript Object) ensures
18
+ * state is decoupled from logic, following a functional "Relation Function" pattern.
8
19
  *
9
20
  * @internal
10
21
  */
11
- export declare class ListContext<T> {
22
+ export interface ListContext<T> {
23
+ /** Sequential snapshot of the previous render state. */
24
+ snapshots: ListSnapshot<T>[];
25
+ /** Keys currently undergoing asynchronous exit animations. */
26
+ readonly removingKeys: Set<ListKey>;
27
+ /** Cached reference to the placeholder element shown when the list is empty. */
28
+ $emptyEl: JQuery | null;
29
+ /** Inverse lookup for O(1) index retrieval from a key. */
30
+ keyToIndex: Map<ListKey, number>;
31
+ /** The reactive effect controlling this list. Needed to check disposal state during async tasks. */
32
+ fx?: EffectObject;
33
+ /** Target container element. */
12
34
  readonly $container: JQuery;
35
+ /** Selector for the container. */
13
36
  readonly containerSelector: string;
37
+ /** Optional removal lifecycle hook. */
14
38
  readonly onRemove: (($el: JQuery) => Promise<void> | void) | undefined;
15
- private _oldKeys;
16
- private _oldItems;
17
- private _oldNodes;
18
- private readonly _removingKeys;
19
- private _emptyEl;
20
- private readonly _keyToIndex;
21
- fx?: EffectObject;
22
- constructor($container: JQuery, containerSelector: string, onRemove: (($el: JQuery) => Promise<void> | void) | undefined);
23
- get oldKeys(): ListKey[];
24
- set oldKeys(v: ListKey[]);
25
- get oldItems(): T[];
26
- set oldItems(v: T[]);
27
- get oldNodes(): (Element | JQuery<HTMLElement> | undefined)[];
28
- set oldNodes(v: (Element | JQuery<HTMLElement> | undefined)[]);
29
- get removingKeys(): Set<ListKey>;
30
- get keyToIndex(): Map<ListKey, number>;
31
- get $emptyEl(): JQuery<HTMLElement> | null;
32
- set $emptyEl(v: JQuery<HTMLElement> | null);
33
- /**
34
- * Retrieves the index of a key, supporting string-to-number normalization.
35
- *
36
- * Reason: DOM attributes (like `data-atom-key`) are always returned as strings,
37
- * but the internal `_keyToIndex` map might use numbers.
38
- */
39
- getIndex(key: ListKey | string): number | undefined;
40
- /**
41
- * Orchestrates the physical removal of an element from the DOM.
42
- *
43
- * Logic:
44
- * 1. If `onRemove` returns a Promise, it waits for completion (e.g., a fade-out animation).
45
- * 2. Constraint: Before calling `.remove()`, it checks if the element has been "resurrected"
46
- * (assigned a new `data-atom-key`) by a subsequent render cycle.
47
- */
48
- scheduleRemoval(k: ListKey, $el: JQuery): void;
49
- /**
50
- * Marks a key as "removing" and initiates the removal sequence.
51
- *
52
- * Note: The `data-atom-key` attribute is cleared immediately to prevent the reconciler
53
- * from finding this "ghost" element via DOM lookups while animations are still running.
54
- */
55
- removeItem(k: ListKey, $el: JQuery): void;
56
- /**
57
- * Performs full cleanup of the list state and event listeners.
58
- */
59
- dispose(): void;
60
39
  }
40
+ /**
41
+ * Factory to initialize a new ListContext.
42
+ */
43
+ export declare function createListContext<T>($container: JQuery, containerSelector: string, onRemove: (($el: JQuery) => Promise<void> | void) | undefined): ListContext<T>;
44
+ /**
45
+ * Retrieves the index of a key, handling string-to-number normalization.
46
+ *
47
+ * WHY: DOM `data-atom-key` attributes are always strings. If the original
48
+ * atom keys were numbers, a direct Map lookup will fail.
49
+ *
50
+ * @internal
51
+ */
52
+ export declare function getListIndex<T>(ctx: ListContext<T>, key: ListKey | string): number | undefined;
53
+ /**
54
+ * Marks a key as "in transit" and starts the removal lifecycle.
55
+ * @internal
56
+ */
57
+ export declare function removeListItem<T>(ctx: ListContext<T>, k: ListKey, $el: JQuery): void;
58
+ /**
59
+ * Initiates the physical removal of an element.
60
+ *
61
+ * PERFORMANCE: Allocation-free path for synchronous removals.
62
+ * Closures are only created if `onRemove` returns a Promise.
63
+ * @internal
64
+ */
65
+ export declare function scheduleListItemRemoval<T>(ctx: ListContext<T>, k: ListKey, $el: JQuery): void;
66
+ /**
67
+ * Finalizes DOM removal and state cleanup.
68
+ *
69
+ * GUARD: If an element is "resurrected" (reused for a new key) during the
70
+ * asynchronous removal delay, this method aborts to prevent accidental destruction.
71
+ * @internal
72
+ */
73
+ export declare function commitListItemRemoval<T>(ctx: ListContext<T>, k: ListKey, $el: JQuery): void;
74
+ /**
75
+ * Full cleanup of state and DOM references.
76
+ *
77
+ * GC: Reuses the `snapshots` array instance (length = 0) to reduce
78
+ * memory fragmentation on high-frequency list swaps.
79
+ * @internal
80
+ */
81
+ export declare function disposeListContext<T>(ctx: ListContext<T>): void;
61
82
  //# sourceMappingURL=context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/bindings/list/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGrD;;;;;;;;GAQG;AACH,qBAAa,WAAW,CAAC,CAAC;aAWN,UAAU,EAAE,MAAM;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C,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAW9F;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAIpF;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAS7F;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAY3F;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI,CAM/D"}
@@ -2,29 +2,21 @@ import { ListKeyFn, ListOptions } from '../../types';
2
2
  import { ListContext } from './context';
3
3
  import { PreparedDiff } from './types';
4
4
  /**
5
- * Generates a reconciliation plan by calculating the difference between the
6
- * current list state and the new item set.
7
- *
8
- * Logic: This function implements a double-ended diffing algorithm to identify
9
- * reusable DOM nodes, new entries, and required replacements. It optimizes
10
- * performance by isolating the "dirty" range — skipping unchanged items at
11
- * both the head and tail of the list.
5
+ * Generates a reconciliation plan between the previous and next state of a list.
12
6
  *
13
7
  * When to use:
14
8
  * - Internal orchestration of DOM mutations for the `atomList` binding.
15
9
  *
16
- * @param ctx - The current list context containing historical DOM state.
17
- * @param items - The new set of items to render.
18
- * @param itemCount - The total number of new items.
19
- * @param getKey - A function to derive a unique key for each item.
20
- * @param update - An optional callback used to patch existing DOM nodes.
21
- * @param isEqual - An optional equality comparator for items.
22
- * @returns A detailed diff plan used to execute DOM updates.
10
+ * Performance:
11
+ * - O(N) time complexity.
12
+ * - Best case: O(1) for pure appends/prepends via head/tail fast-forwarding.
13
+ *
14
+ * @param ctx - Persistent state containing historical DOM and keys.
15
+ * @param items - The new data array from the source atom.
23
16
  *
24
17
  * @example
25
- * ```typescript
26
- * const diff = buildIndices(context, nextItems, nextItems.length, getKey, onUpdate, onEqual);
27
- * ```
18
+ * const diff = buildIndices(ctx, nextItems, nextItems.length, getKey, update, isEqual);
19
+ * // diff.slots now contains the mapping instructions for each index.
28
20
  *
29
21
  * @internal
30
22
  */
@@ -1 +1 @@
1
- {"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../../src/bindings/list/diff.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAW,SAAS,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAa,KAAK,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC5B,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,EACnB,KAAK,EAAE,CAAC,EAAE,EACV,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,EACpB,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAChC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GACjC,YAAY,CAAC,CAAC,CAAC,CA6HjB"}
1
+ {"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../../src/bindings/list/diff.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAW,SAAS,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAA4B,KAAK,YAAY,EAAE,MAAM,SAAS,CAAC;AAEtE;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC5B,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,EACnB,KAAK,EAAE,CAAC,EAAE,EACV,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,EACpB,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAChC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GACjC,YAAY,CAAC,CAAC,CAAC,CAyHjB"}
@@ -2,62 +2,49 @@ import { ListOptions } from '../../types';
2
2
  import { ListContext } from './context';
3
3
  import { PlaceCallbacks, PreparedDiff } from './types';
4
4
  /**
5
- * A low-level DOM utility for inserting elements before a specific reference node.
5
+ * Inserts elements before a reference node with zero-allocation for jQuery collections.
6
6
  *
7
- * This helper supports both raw `Element` instances and jQuery collections,
8
- * ensuring consistent insertion behavior regardless of the input type.
9
- *
10
- * @param elOrJq - The element or jQuery collection to insert.
11
- * @param nextNode - The reference node to insert before. If null, appends to the container.
12
- * @param container - The parent container element.
13
- * @internal
7
+ * Why:
8
+ * - Directly iterates over JQuery objects to avoid `.get()` or `Array.from()` array allocations.
9
+ * - Handles polymorphic inputs (Element | JQuery) to keep the caller's logic simple.
14
10
  */
15
11
  export declare function insertOrAppend(elOrJq: Element | JQuery | undefined, nextNode: Node | null, container: Element): void;
16
12
  /**
17
- * Orchestrates the cleanup of a list container and the rendering of empty placeholders.
18
- *
19
- * Logic: If an `onRemove` callback is provided, the function performs asynchronous
20
- * removals for each item to allow for exit animations. Otherwise, it executes a
21
- * destructive `empty()` on the container for efficiency.
13
+ * Resets the container or renders an empty placeholder.
22
14
  *
23
- * When to use:
24
- * - To reset a list container during reconciliation or when the data source becomes empty.
25
- *
26
- * @param ctx - The list context containing historical state.
27
- * @param itemCount - The number of items in the new data set.
28
- * @param $container - The jQuery-wrapped container.
29
- * @param empty - The template or element to display when the list is empty.
30
- * @internal
15
+ * Why:
16
+ * - Decouples destructive cleanup (`.empty()`) from animated cleanup (`removeItem`).
17
+ * - Ensures the historical context is cleared only after the DOM reflects the empty state.
31
18
  */
32
19
  export declare function handleEmpty<T>(ctx: ListContext<T>, itemCount: number, $container: JQuery, empty: ListOptions<T>['empty']): void;
33
20
  /**
34
- * Transforms items into DOM handles based on the reconciliation plan.
35
- *
36
- * Optimization: If all items utilize string templates and the list is undergoing
37
- * an initial render (cold start), the function returns sanitized HTML fragments
38
- * for direct `innerHTML` injection, bypassing the overhead of individual jQuery
39
- * object construction.
21
+ * Transforms items into DOM nodes or sanitized HTML strings.
40
22
  *
41
- * When to use:
42
- * - Internal processing of new items within the `atomList` lifecycle.
23
+ * Performance:
24
+ * - Provides a "Cold Start" optimization: returns raw HTML strings for initial render
25
+ * to allow direct `innerHTML` injection, bypassing jQuery construction overhead.
43
26
  *
44
- * @param diff - The prepared diff plan.
45
- * @param options - Configuration options for the list.
46
- * @param isInitial - Indicates whether this is the first render of the list.
47
- * @returns An array of sanitized HTML strings if the fast-path is applicable; otherwise null.
48
- * @internal
27
+ * Why:
28
+ * - String parsing is batched (`batchSanitize`) to reduce sanitization engine overhead.
49
29
  */
50
30
  export declare function renderItems<T>(diff: PreparedDiff<T>, options: ListOptions<T>, isInitial: boolean): string[] | null;
51
31
  /**
52
- * Identifies and removes items that are no longer present in the reactive data set.
32
+ * Triggers removal lifecycle for items missing in the new data set.
33
+ *
34
+ * When to use:
35
+ * - Called during the diffing phase before new items are placed.
36
+ */
37
+ export declare function cleanupRemoved<T>(ctx: ListContext<T>): void;
38
+ /**
39
+ * Positions items in the DOM and executes lifecycle callbacks.
53
40
  *
54
- * Logic: Iterates through the historical key set and triggers the removal
55
- * lifecycle for any key that is not found in the new state.
41
+ * Logic:
42
+ * 1. Initial Render: Replaces entire innerHTML or appends via DocumentFragment.
43
+ * 2. Reconciliation: Moves existing nodes or inserts new ones based on the diff plan.
56
44
  *
57
- * @param ctx - The list context containing historical state.
58
- * @param diff - The prepared diff plan.
59
- * @internal
45
+ * Performance:
46
+ * - Uses a reverse loop for reconciliation to maintain DOM order with minimal moves.
47
+ * - Uses `switch` instead of a handler Map to avoid object allocation in the hot loop.
60
48
  */
61
- export declare function cleanupRemoved<T>(ctx: ListContext<T>, diff: PreparedDiff<T>): void;
62
49
  export declare function placeItems<T>(ctx: ListContext<T>, diff: PreparedDiff<T>, container: Element, callbacks: PlaceCallbacks<T>, htmlFragments: string[] | null): void;
63
50
  //# sourceMappingURL=dom.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dom.d.ts","sourceRoot":"","sources":["../../../src/bindings/list/dom.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAa,KAAK,cAAc,EAAE,KAAK,YAAY,EAAE,MAAM,SAAS,CAAC;AAG5E;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,EACpC,QAAQ,EAAE,IAAI,GAAG,IAAI,EACrB,SAAS,EAAE,OAAO,GACjB,IAAI,CAUN;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,EACnB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAC7B,IAAI,CA8BN;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,EACrB,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,EACvB,SAAS,EAA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AAC,EACvB,SAAS,EAAE,OAAO,GACjB,MAAM,EAAE,GAAG,IAAI,CAuEjB;AAcD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI,CAQ3D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAC1B,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,EACnB,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,EACrB,SAAS,EAAE,OAAO,EAClB,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC,EAC5B,aAAa,EAAE,MAAM,EAAE,GAAG,IAAI,GAC7B,IAAI,CA0GN"}
@@ -1,2 +1,19 @@
1
- export {};
1
+ import { EffectObject, ListOptions, ReadonlyAtom } from '../../types';
2
+ import { ListContext } from './context';
3
+ /**
4
+ * Internal engine for list reconciliation.
5
+ *
6
+ * When to use:
7
+ * - Coordinates the full lifecycle: Empty state -> Diffing -> Rendering -> DOM placement.
8
+ *
9
+ * Boundary:
10
+ * - Uses `untracked` to ensure DOM mutations don't accidentally trigger parent effects.
11
+ * - Relies on `ListContext` for state persistence across render cycles.
12
+ *
13
+ * @internal
14
+ */
15
+ export declare function applyListBinding<T>(element: HTMLElement, source: ReadonlyAtom<T[]>, options: ListOptions<T>): {
16
+ fx: EffectObject;
17
+ ctx: ListContext<T>;
18
+ };
2
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/bindings/list/index.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/bindings/list/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAsB,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE3F,OAAO,EAAuD,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAalG;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,EACzB,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,GACtB;IAAE,EAAE,EAAE,YAAY,CAAC;IAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,CAAA;CAAE,CAiD3C"}
@@ -36,42 +36,40 @@ export declare const ItemState: {
36
36
  readonly ForceReplace: number;
37
37
  };
38
38
  export type ItemState = (typeof ItemState)[keyof typeof ItemState];
39
+ /**
40
+ * Represents a single item's reconciliation state and metadata.
41
+ *
42
+ * @internal
43
+ */
44
+ export interface DiffSlot<T> {
45
+ /** The unique key for the item. */
46
+ key: ListKey;
47
+ /** The current data item. */
48
+ item: T;
49
+ /** The assigned reconciliation state. */
50
+ state: ItemState;
51
+ /** The index in the previous state, or -1 if new. */
52
+ oldIndex: number;
53
+ /** The index in the new state. */
54
+ targetIndex: number;
55
+ /** The current DOM handle. */
56
+ node: Element | JQuery | undefined;
57
+ }
39
58
  /**
40
59
  * A reconciliation plan generated by the diffing algorithm.
41
60
  *
42
- * Logic: This interface provides index-based buffers and metadata required by
43
- * the DOM synchronizer to perform atomic mutations with minimal overhead.
61
+ * Logic: This interface provides a unified table of item slots and metadata
62
+ * required by the DOM synchronizer to perform atomic mutations.
44
63
  *
45
64
  * @internal
46
65
  */
47
66
  export interface PreparedDiff<T> {
48
- /** The collection of unique keys for the new item set. */
49
- newKeys: ListKey[];
50
- /** The collection of data items for the new state. */
51
- newItems: T[];
52
- /** A set containing all unique keys used for duplicate detection. */
53
- newKeySet: Set<ListKey>;
54
- /** A map of new indices to their corresponding indices in the previous state. */
55
- newIndices: number[];
56
- /** The reconciliation state assigned to each item. */
57
- newStates: ItemState[];
58
- /** The current DOM handles (Element or jQuery) for each item. */
59
- newNodes: (Element | JQuery | undefined)[];
67
+ /** The unified collection of item slots. */
68
+ slots: DiffSlot<T>[];
60
69
  /**
61
- * A collection of items that require new DOM construction or HTML parsing
62
- * during this rendering cycle.
70
+ * A collection of slots that require new DOM construction or HTML parsing.
63
71
  */
64
- toRender: {
65
- key: ListKey;
66
- item: T;
67
- index: number;
68
- }[];
69
- /** The starting index of the "dirty" middle section after prefix optimization. */
70
- startIndex: number;
71
- /** The ending index of the "dirty" section relative to the old list state. */
72
- oldEndIndex: number;
73
- /** The ending index of the "dirty" section relative to the new list state. */
74
- newEndIndex: number;
72
+ toRender: DiffSlot<T>[];
75
73
  }
76
74
  /**
77
75
  * A collection of user-provided lifecycle hooks and event configurations.
@@ -90,4 +88,13 @@ export interface PlaceCallbacks<T> {
90
88
  /** Delegated event listeners for the list container. */
91
89
  events?: ListOptions<T>['events'] | undefined;
92
90
  }
91
+ /**
92
+ * Normalization table for delegated event listeners.
93
+ * @internal
94
+ */
95
+ export interface EventBinding {
96
+ type: string;
97
+ selector: string;
98
+ callback: Function;
99
+ }
93
100
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/bindings/list/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE/D,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AAEnC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS;IACpB;;;OAGG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;;CAEK,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,OAAO,SAAS,CAAC,CAAC;AAEnE;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,0DAA0D;IAC1D,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB,sDAAsD;IACtD,QAAQ,EAAE,CAAC,EAAE,CAAC;IACd,qEAAqE;IACrE,SAAS,EA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AAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IACrE,8DAA8D;IAC9D,KAAK,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAC5C,qFAAqF;IACrF,QAAQ,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,SAAS,CAAC;IAClD,wDAAwD;IACxD,MAAM,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC;CAC/C;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC;CACpB"}
@@ -1,32 +1,32 @@
1
1
  /**
2
2
  * Normalizes a raw DOM element or a jQuery collection into a standard jQuery object.
3
3
  *
4
- * @param $el - The element or collection to normalize.
5
- * @returns A standard jQuery object.
4
+ * Logic: Polymorphic Input
5
+ * Supports both raw Element for single operations and JQuery collections for bulk
6
+ * processing, ensuring consistent API behavior.
7
+ *
6
8
  * @internal
7
9
  */
8
10
  export declare function wrap($el: Element | JQuery<Element>): JQuery;
9
11
  /**
10
12
  * Assigns or removes a stable reactive identifier on a DOM node or collection.
11
13
  *
12
- * Logic: The `data-atom-key` attribute serves as the primary stable identifier
13
- * for DOM nodes within the list reconciliation engine. This allows the diffing
14
- * algorithm to perform O(N) re-ordering and node reuse, avoiding the overhead
15
- * of positional comparisons.
16
- *
17
- * @param node - The DOM element, Node, or jQuery collection.
18
- * @param key - The unique string key to assign, or null to remove the identifier.
14
+ * @param node - The target DOM element or collection.
15
+ * @param key - Unique string key for identification, or null to remove.
19
16
  * @internal
20
17
  */
21
18
  export declare function setAtomKey(node: Element | Node | JQuery, key: string | null): void;
22
19
  /**
23
20
  * Performs a deep recursive cleanup of reactive resources associated with a DOM tree.
24
21
  *
25
- * Caution: This method must be executed before an element is permanently detached
26
- * from the DOM or replaced. Failure to do so may result in "zombie" reactive
27
- * effects remaining in the registry, leading to significant memory leaks.
22
+ * Constraint: Teardown Order
23
+ * Must be executed before an element is permanently detached or replaced.
24
+ *
25
+ * Caution: Memory Leak
26
+ * Failure to call this results in "zombie" reactive effects remaining in the
27
+ * global registry, leading to significant memory growth over time.
28
28
  *
29
- * @param node - The root element or jQuery collection to clean up.
29
+ * @param node - The root element or collection to purge from the registry.
30
30
  * @internal
31
31
  */
32
32
  export declare function cleanupNodes(node: Element | JQuery): void;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/bindings/list/utils.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,CAE3D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,GAAG,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAoBlF;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAYzD"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/bindings/list/utils.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,CAG3D;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,GAAG,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAgClF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAczD"}