@source-crafter/xzor-runtime 0.1.8 → 0.1.10

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.
@@ -0,0 +1,35 @@
1
+ import { Model } from "./model";
2
+ export declare class EntitySet<T extends Model> extends Array<T> {
3
+ #private;
4
+ static get [Symbol.species](): ArrayConstructor;
5
+ /** Builds a set from server data: `Array.of` and `Array.from` keep their own meaning. */
6
+ static track<T extends Model>(type: new (data?: object) => T, items?: Iterable<object>): EntitySet<T>;
7
+ /** @internal The model this set belongs to, and the index of the field holding it. */
8
+ $own(owner: Model, index: number): void;
9
+ /** @internal */
10
+ $watch(dep: object): void;
11
+ /** @internal */
12
+ $unwatch(dep: object): void;
13
+ [Symbol.iterator](): ArrayIterator<T>;
14
+ /** The items to show: everything but the deleted ones. */
15
+ get view(): T[];
16
+ get hasChanges(): boolean;
17
+ get hasErrors(): boolean;
18
+ /** What to send to the server: only the items that changed, each as its own `changes`. */
19
+ get changes(): Record<string, unknown>[];
20
+ /** Added items leave the set, the others are marked Deleted; a Detached one is left alone. */
21
+ delete(...items: T[]): this;
22
+ revertChanges(): this;
23
+ /**
24
+ * Takes the list the server confirmed: a `null` at an index drops that item, as do the deleted ones.
25
+ * Items past the end of a shorter server list are left exactly as they are.
26
+ */
27
+ confirmChanges(items?: readonly (object | null)[]): this;
28
+ push(...items: T[]): number;
29
+ unshift(...items: T[]): number;
30
+ pop(): T | undefined;
31
+ shift(): T | undefined;
32
+ splice(start: number, deleteCount?: number, ...items: T[]): T[];
33
+ sort(compare?: (a: T, b: T) => number): this;
34
+ reverse(): T[];
35
+ }
package/fine.d.ts ADDED
@@ -0,0 +1,62 @@
1
+ import { ComponentBase, type RenderTreeBuilder } from "./index";
2
+ type Build = (parent: Node) => void;
3
+ /** The element type of tag `K`. */
4
+ export type El<K extends string> = K extends keyof HTMLElementTagNameMap ? HTMLElementTagNameMap[K] : HTMLElement;
5
+ /**
6
+ * What generated `@fine` code calls. A run of nodes is a `template` clone; the `...At` calls bind the nodes it
7
+ * has in place, and the `...Item` ones bind a row's nodes to a read its list shares (`reads[i]`, given the item).
8
+ * The others append the node they bind to `parent`.
9
+ */
10
+ export declare const fine: {
11
+ /**
12
+ * Builds the nodes of `specs` (a fragment unless they are one element). The first call builds them directly:
13
+ * a component used once keeps no copy. From the second on, calls clone a copy built then.
14
+ */
15
+ template(specs: readonly unknown[]): () => Node;
16
+ el<K extends string>(parent: Node, tag: K): El<K>;
17
+ /** A handler; afterwards the component re-runs its bindings that read nothing tracked. */
18
+ on(el: Element, event: string, handler: (e: any) => unknown): void;
19
+ /** A row's handler: `reads[i](item)` gives it. */
20
+ onItem(el: Element, event: string, i: number): void;
21
+ /** Static text. */
22
+ t(parent: Node, text: string): void;
23
+ /** Text that follows `read()`; markup (a `RenderFragment`) renders as markup. */
24
+ text(parent: Node, read: () => unknown): void;
25
+ textAt(node: Text, read: () => unknown): void;
26
+ textItem(node: Text, i: number): void;
27
+ /** Attribute `name` of `el` that follows `read()`; `false`/`null`/`undefined` remove it. */
28
+ attr(el: Element, name: string, read: () => unknown): void;
29
+ attrItem(el: Element, name: string, i: number): void;
30
+ /** `@if`, `@switch`, a `@for` that is not a plain list, `@{ }`: rebuilt whenever what `build` read changes. */
31
+ region(parent: Node, build: Build): void;
32
+ /** A region between `end` and the comment before it. */
33
+ regionAt(end: Comment, build: Build): void;
34
+ /** A row's region: `reads[i](item, parent)` builds it. */
35
+ regionItem(end: Comment, i: number): void;
36
+ /** `@for (const item of items)`: one row per item, matched by identity; a row is built once. */
37
+ list<T>(parent: Node, items: () => Iterable<T>, build: (parent: Node, item: T) => void): void;
38
+ /** A list before `end`; its rows' bindings use `reads`, shared by the rows. */
39
+ listAt<T>(end: Comment, items: () => Iterable<T>, reads: readonly ((item: T, x?: any) => any)[], build: (parent: Node, item: T) => void): void;
40
+ /** Child components, slots, `@cascade`, routes: virtual-DOM builder calls, patched when what they read changes. */
41
+ island(parent: Node, build: (b: RenderTreeBuilder) => void): void;
42
+ islandAt(end: Comment, build: (b: RenderTreeBuilder) => void): void;
43
+ };
44
+ /**
45
+ * Base of `@fine` components. The bundle turns their fields into tracked ones, as it does a model's, so a
46
+ * handler that writes a field updates what reads it. `stateHasChanged()` re-runs every binding.
47
+ */
48
+ export declare abstract class FineComponent extends ComponentBase {
49
+ #private;
50
+ /** @internal What tracked getters report to; the bundle emits `FineComponent.$reader?.(this, i)`. */
51
+ static get $reader(): ((source: object, index: number) => void) | undefined;
52
+ static same(a: unknown, b: unknown): boolean;
53
+ /** @internal Records a class's tracked fields after its base's; returns where they start. */
54
+ static $define(cls: Function, names: string[]): number;
55
+ /** @internal */
56
+ $watch(dep: object): void;
57
+ /** @internal */
58
+ $unwatch(dep: object): void;
59
+ /** @internal What a tracked setter reports once it stored a different value. */
60
+ protected $changed(index: number, _previous: unknown): void;
61
+ }
62
+ export {};