@20baht/angular 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +158 -2
- package/dist/cell.d.ts +44 -0
- package/dist/cell.js +101 -0
- package/dist/elements.d.ts +2323 -0
- package/dist/elements.js +5082 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/runtime.d.ts +21 -0
- package/dist/runtime.js +49 -0
- package/dist/stickers.d.ts +77 -0
- package/dist/stickers.js +146 -0
- package/dist/store.d.ts +12 -0
- package/dist/store.js +37 -0
- package/package.json +81 -4
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type OutputEmitterRef } from '@angular/core';
|
|
2
|
+
/** The element the directive sits on, typed as its @20baht/ui class. */
|
|
3
|
+
export declare function hostElement<T extends HTMLElement>(): T;
|
|
4
|
+
/**
|
|
5
|
+
* Set one property on the element. Optional properties (`debounce?: number`) take `undefined`
|
|
6
|
+
* too, which an input can pass when the binding is cleared.
|
|
7
|
+
*/
|
|
8
|
+
export declare function assign<T extends HTMLElement, K extends keyof T>(el: T, key: K, v: T[K] | undefined): void;
|
|
9
|
+
/** Number inputs accept a static attribute string (`debounce="300"`); unset stays unset. */
|
|
10
|
+
export declare function num(v: unknown): number | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Emit the element's own `name` events on `out`, as their `detail` (or `pick(detail)`). Events
|
|
13
|
+
* bubbling up from another element inside it are not its own, so they are left alone: an
|
|
14
|
+
* accordion inside a popover does not fire the popover's `bahtToggle`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function relay<D, T = D>(el: HTMLElement, name: string, out: OutputEmitterRef<T>, pick?: (detail: D) => T): void;
|
|
17
|
+
/**
|
|
18
|
+
* Emit the element's own `name` events on `out` as the events themselves, for a cancelable one:
|
|
19
|
+
* the output fires inside the dispatch, so a handler's `preventDefault()` reaches the element.
|
|
20
|
+
*/
|
|
21
|
+
export declare function relayEvent<D>(el: HTMLElement, name: string, out: OutputEmitterRef<CustomEvent<D>>): void;
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// What every generated directive shares: the host element, the input transforms, and relaying
|
|
2
|
+
// an element event to an output as its detail (or, for a cancelable one, as the event too).
|
|
3
|
+
import { DestroyRef, ElementRef, inject, numberAttribute, } from '@angular/core';
|
|
4
|
+
/** The element the directive sits on, typed as its @20baht/ui class. */
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters -- each directive names its element class here; the element is that class
|
|
6
|
+
export function hostElement() {
|
|
7
|
+
return inject(ElementRef).nativeElement;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Set one property on the element. Optional properties (`debounce?: number`) take `undefined`
|
|
11
|
+
* too, which an input can pass when the binding is cleared.
|
|
12
|
+
*/
|
|
13
|
+
export function assign(el, key, v) {
|
|
14
|
+
el[key] = v;
|
|
15
|
+
}
|
|
16
|
+
/** Number inputs accept a static attribute string (`debounce="300"`); unset stays unset. */
|
|
17
|
+
export function num(v) {
|
|
18
|
+
return v === undefined || v === null || v === '' ? undefined : numberAttribute(v);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Emit the element's own `name` events on `out`, as their `detail` (or `pick(detail)`). Events
|
|
22
|
+
* bubbling up from another element inside it are not its own, so they are left alone: an
|
|
23
|
+
* accordion inside a popover does not fire the popover's `bahtToggle`.
|
|
24
|
+
*/
|
|
25
|
+
export function relay(el, name, out, pick) {
|
|
26
|
+
own(el, name, (e) => {
|
|
27
|
+
out.emit(pick ? pick(e.detail) : e.detail);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Emit the element's own `name` events on `out` as the events themselves, for a cancelable one:
|
|
32
|
+
* the output fires inside the dispatch, so a handler's `preventDefault()` reaches the element.
|
|
33
|
+
*/
|
|
34
|
+
export function relayEvent(el, name, out) {
|
|
35
|
+
own(el, name, (e) => {
|
|
36
|
+
out.emit(e);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/** Listen to the element's own `name` events (not ones bubbling from inside) until destroy. */
|
|
40
|
+
function own(el, name, fn) {
|
|
41
|
+
const listener = (e) => {
|
|
42
|
+
if (e.target === el)
|
|
43
|
+
fn(e);
|
|
44
|
+
};
|
|
45
|
+
el.addEventListener(name, listener);
|
|
46
|
+
inject(DestroyRef).onDestroy(() => {
|
|
47
|
+
el.removeEventListener(name, listener);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Icon, Palette } from '@20baht/stickers';
|
|
2
|
+
import type { BahtSticker } from '@20baht/stickers/element';
|
|
3
|
+
import type { BahtStickerGraph, GraphNode, GraphStep } from '@20baht/stickers/graph';
|
|
4
|
+
import type { StickerName } from '@20baht/stickers/load';
|
|
5
|
+
import * as i0 from "@angular/core";
|
|
6
|
+
/**
|
|
7
|
+
* `<baht-sticker>`: an animated slab sticker. Register the element (and the stickers you name) first:
|
|
8
|
+
* `import '@20baht/stickers/all'`, or `/element` with `registerSticker(icon)`.
|
|
9
|
+
*
|
|
10
|
+
* `once` has no input: Angular reads any name starting with "on" as an event handler, so bind
|
|
11
|
+
* `[playOnce]` (the element's other name for it). A static `once` attribute still reaches the element.
|
|
12
|
+
*/
|
|
13
|
+
export declare class BahtStickerDirective {
|
|
14
|
+
/** The element itself, for its methods (`replay()`). */
|
|
15
|
+
readonly element: BahtSticker;
|
|
16
|
+
/** Name of a sticker in the collection; ignored while `icon` is set. A sticker of your own goes in `[icon]`. */
|
|
17
|
+
set name(v: StickerName | undefined);
|
|
18
|
+
/** The icon to play, as an object (`import { piggyBank } from '@20baht/stickers/icons/piggy-bank'`). Wins over `name`. */
|
|
19
|
+
set icon(v: Icon | undefined);
|
|
20
|
+
/** Slots to swap; unset follows the --baht-* tokens. */
|
|
21
|
+
set palette(v: Partial<Palette> | undefined);
|
|
22
|
+
/** Play once when first shown (or on replay), then rest on the icon's still frame. The element's `once`. */
|
|
23
|
+
set playOnce(v: BahtSticker['playOnce']);
|
|
24
|
+
/** Frames ahead of the page clock, to put neighbours out of phase. */
|
|
25
|
+
set offset(v: BahtSticker['offset']);
|
|
26
|
+
/** Seconds after first shown to pop in on the bounce entrance; unset skips the entrance. */
|
|
27
|
+
set enter(v: BahtSticker['enter']);
|
|
28
|
+
/** Replay from frame 0 when the pointer enters. */
|
|
29
|
+
set replayOnHover(v: BahtSticker['replayOnHover']);
|
|
30
|
+
/** Accessible name; the sticker's name by default. */
|
|
31
|
+
set label(v: BahtSticker['label']);
|
|
32
|
+
/** Outline weight as a multiple of the sticker's own: `0.6` thinner, `1.5` bolder; unset is 1. */
|
|
33
|
+
set line(v: BahtSticker['line']);
|
|
34
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<BahtStickerDirective, never>;
|
|
35
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<BahtStickerDirective, "baht-sticker", ["bahtSticker"], { "name": { "alias": "name"; "required": false; }; "icon": { "alias": "icon"; "required": false; }; "palette": { "alias": "palette"; "required": false; }; "playOnce": { "alias": "playOnce"; "required": false; }; "offset": { "alias": "offset"; "required": false; }; "enter": { "alias": "enter"; "required": false; }; "replayOnHover": { "alias": "replayOnHover"; "required": false; }; "label": { "alias": "label"; "required": false; }; "line": { "alias": "line"; "required": false; }; }, {}, never, never, true, never>;
|
|
36
|
+
static ngAcceptInputType_playOnce: unknown;
|
|
37
|
+
static ngAcceptInputType_offset: unknown;
|
|
38
|
+
static ngAcceptInputType_enter: unknown;
|
|
39
|
+
static ngAcceptInputType_replayOnHover: unknown;
|
|
40
|
+
static ngAcceptInputType_line: unknown;
|
|
41
|
+
}
|
|
42
|
+
/** `<baht-sticker-graph>`: a network-style diagram drawn with stickers. Register it with `import '@20baht/stickers/graph'` (or `/all`). */
|
|
43
|
+
export declare class BahtStickerGraphDirective {
|
|
44
|
+
/** The element itself, for its methods. */
|
|
45
|
+
readonly element: BahtStickerGraph;
|
|
46
|
+
/** The diagram to draw: `{ nodes, links, flow }`. */
|
|
47
|
+
set graph(v: BahtStickerGraph['graph']);
|
|
48
|
+
/** Milliseconds a packet takes along one step (default 900). */
|
|
49
|
+
set stepMs(v: BahtStickerGraph['stepMs'] | undefined);
|
|
50
|
+
/** Holds the packets where they are. */
|
|
51
|
+
set paused(v: BahtStickerGraph['paused']);
|
|
52
|
+
/** Leaves out the floor grid. */
|
|
53
|
+
set hideGrid(v: BahtStickerGraph['hideGrid']);
|
|
54
|
+
/** Accessible name of the diagram. */
|
|
55
|
+
set label(v: BahtStickerGraph['label']);
|
|
56
|
+
/** Nodes are focusable buttons (click, Enter, Space) that emit `bahtNode`. */
|
|
57
|
+
set interactive(v: BahtStickerGraph['interactive']);
|
|
58
|
+
/** A packet set off on step `index` of `flow`. */
|
|
59
|
+
readonly bahtStep: import("@angular/core").OutputEmitterRef<{
|
|
60
|
+
index: number;
|
|
61
|
+
step: GraphStep;
|
|
62
|
+
}>;
|
|
63
|
+
/** A node was clicked or pressed; only with `interactive`. */
|
|
64
|
+
readonly bahtNode: import("@angular/core").OutputEmitterRef<{
|
|
65
|
+
id: string;
|
|
66
|
+
node: GraphNode;
|
|
67
|
+
}>;
|
|
68
|
+
constructor();
|
|
69
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<BahtStickerGraphDirective, never>;
|
|
70
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<BahtStickerGraphDirective, "baht-sticker-graph", ["bahtStickerGraph"], { "graph": { "alias": "graph"; "required": false; }; "stepMs": { "alias": "stepMs"; "required": false; }; "paused": { "alias": "paused"; "required": false; }; "hideGrid": { "alias": "hideGrid"; "required": false; }; "label": { "alias": "label"; "required": false; }; "interactive": { "alias": "interactive"; "required": false; }; }, { "bahtStep": "bahtStep"; "bahtNode": "bahtNode"; }, never, never, true, never>;
|
|
71
|
+
static ngAcceptInputType_stepMs: unknown;
|
|
72
|
+
static ngAcceptInputType_paused: unknown;
|
|
73
|
+
static ngAcceptInputType_hideGrid: unknown;
|
|
74
|
+
static ngAcceptInputType_interactive: unknown;
|
|
75
|
+
}
|
|
76
|
+
/** Both sticker directives: `imports: [BAHT_STICKERS]` in a standalone component. */
|
|
77
|
+
export declare const BAHT_STICKERS: readonly [typeof BahtStickerDirective, typeof BahtStickerGraphDirective];
|
package/dist/stickers.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// @20baht/stickers as Angular directives: `<baht-sticker>` and `<baht-sticker-graph>`, in the same
|
|
2
|
+
// shape as the generated ones in elements.ts. Hand-written: the stickers package ships no
|
|
3
|
+
// custom-elements.json to generate from (tests/stickers.spec.ts fails when an element property has
|
|
4
|
+
// no input). An entry point of its own, so @20baht/stickers stays an optional peer.
|
|
5
|
+
import { booleanAttribute, Directive, Input, output } from '@angular/core';
|
|
6
|
+
import { assign, hostElement, num, relay } from './runtime.js';
|
|
7
|
+
import * as i0 from "@angular/core";
|
|
8
|
+
/**
|
|
9
|
+
* `<baht-sticker>`: an animated slab sticker. Register the element (and the stickers you name) first:
|
|
10
|
+
* `import '@20baht/stickers/all'`, or `/element` with `registerSticker(icon)`.
|
|
11
|
+
*
|
|
12
|
+
* `once` has no input: Angular reads any name starting with "on" as an event handler, so bind
|
|
13
|
+
* `[playOnce]` (the element's other name for it). A static `once` attribute still reaches the element.
|
|
14
|
+
*/
|
|
15
|
+
export class BahtStickerDirective {
|
|
16
|
+
constructor() {
|
|
17
|
+
/** The element itself, for its methods (`replay()`). */
|
|
18
|
+
this.element = hostElement();
|
|
19
|
+
}
|
|
20
|
+
/** Name of a sticker in the collection; ignored while `icon` is set. A sticker of your own goes in `[icon]`. */
|
|
21
|
+
set name(v) {
|
|
22
|
+
assign(this.element, 'name', v);
|
|
23
|
+
}
|
|
24
|
+
/** The icon to play, as an object (`import { piggyBank } from '@20baht/stickers/icons/piggy-bank'`). Wins over `name`. */
|
|
25
|
+
set icon(v) {
|
|
26
|
+
assign(this.element, 'icon', v);
|
|
27
|
+
}
|
|
28
|
+
/** Slots to swap; unset follows the --baht-* tokens. */
|
|
29
|
+
set palette(v) {
|
|
30
|
+
assign(this.element, 'palette', v);
|
|
31
|
+
}
|
|
32
|
+
/** Play once when first shown (or on replay), then rest on the icon's still frame. The element's `once`. */
|
|
33
|
+
set playOnce(v) {
|
|
34
|
+
assign(this.element, 'playOnce', v);
|
|
35
|
+
}
|
|
36
|
+
/** Frames ahead of the page clock, to put neighbours out of phase. */
|
|
37
|
+
set offset(v) {
|
|
38
|
+
assign(this.element, 'offset', v);
|
|
39
|
+
}
|
|
40
|
+
/** Seconds after first shown to pop in on the bounce entrance; unset skips the entrance. */
|
|
41
|
+
set enter(v) {
|
|
42
|
+
assign(this.element, 'enter', v);
|
|
43
|
+
}
|
|
44
|
+
/** Replay from frame 0 when the pointer enters. */
|
|
45
|
+
set replayOnHover(v) {
|
|
46
|
+
assign(this.element, 'replayOnHover', v);
|
|
47
|
+
}
|
|
48
|
+
/** Accessible name; the sticker's name by default. */
|
|
49
|
+
set label(v) {
|
|
50
|
+
assign(this.element, 'label', v);
|
|
51
|
+
}
|
|
52
|
+
/** Outline weight as a multiple of the sticker's own: `0.6` thinner, `1.5` bolder; unset is 1. */
|
|
53
|
+
set line(v) {
|
|
54
|
+
assign(this.element, 'line', v);
|
|
55
|
+
}
|
|
56
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.5", ngImport: i0, type: BahtStickerDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
57
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "22.2.5", type: BahtStickerDirective, isStandalone: true, selector: "baht-sticker", inputs: { name: "name", icon: "icon", palette: "palette", playOnce: ["playOnce", "playOnce", booleanAttribute], offset: ["offset", "offset", num], enter: ["enter", "enter", num], replayOnHover: ["replayOnHover", "replayOnHover", booleanAttribute], label: "label", line: ["line", "line", num] }, exportAs: ["bahtSticker"], ngImport: i0 }); }
|
|
58
|
+
}
|
|
59
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.5", ngImport: i0, type: BahtStickerDirective, decorators: [{
|
|
60
|
+
type: Directive,
|
|
61
|
+
args: [{ selector: 'baht-sticker', exportAs: 'bahtSticker' }]
|
|
62
|
+
}], propDecorators: { name: [{
|
|
63
|
+
type: Input
|
|
64
|
+
}], icon: [{
|
|
65
|
+
type: Input
|
|
66
|
+
}], palette: [{
|
|
67
|
+
type: Input
|
|
68
|
+
}], playOnce: [{
|
|
69
|
+
type: Input,
|
|
70
|
+
args: [{ transform: booleanAttribute }]
|
|
71
|
+
}], offset: [{
|
|
72
|
+
type: Input,
|
|
73
|
+
args: [{ transform: num }]
|
|
74
|
+
}], enter: [{
|
|
75
|
+
type: Input,
|
|
76
|
+
args: [{ transform: num }]
|
|
77
|
+
}], replayOnHover: [{
|
|
78
|
+
type: Input,
|
|
79
|
+
args: [{ transform: booleanAttribute }]
|
|
80
|
+
}], label: [{
|
|
81
|
+
type: Input
|
|
82
|
+
}], line: [{
|
|
83
|
+
type: Input,
|
|
84
|
+
args: [{ transform: num }]
|
|
85
|
+
}] } });
|
|
86
|
+
/** `<baht-sticker-graph>`: a network-style diagram drawn with stickers. Register it with `import '@20baht/stickers/graph'` (or `/all`). */
|
|
87
|
+
export class BahtStickerGraphDirective {
|
|
88
|
+
/** The diagram to draw: `{ nodes, links, flow }`. */
|
|
89
|
+
set graph(v) {
|
|
90
|
+
assign(this.element, 'graph', v);
|
|
91
|
+
}
|
|
92
|
+
/** Milliseconds a packet takes along one step (default 900). */
|
|
93
|
+
set stepMs(v) {
|
|
94
|
+
assign(this.element, 'stepMs', v);
|
|
95
|
+
}
|
|
96
|
+
/** Holds the packets where they are. */
|
|
97
|
+
set paused(v) {
|
|
98
|
+
assign(this.element, 'paused', v);
|
|
99
|
+
}
|
|
100
|
+
/** Leaves out the floor grid. */
|
|
101
|
+
set hideGrid(v) {
|
|
102
|
+
assign(this.element, 'hideGrid', v);
|
|
103
|
+
}
|
|
104
|
+
/** Accessible name of the diagram. */
|
|
105
|
+
set label(v) {
|
|
106
|
+
assign(this.element, 'label', v);
|
|
107
|
+
}
|
|
108
|
+
/** Nodes are focusable buttons (click, Enter, Space) that emit `bahtNode`. */
|
|
109
|
+
set interactive(v) {
|
|
110
|
+
assign(this.element, 'interactive', v);
|
|
111
|
+
}
|
|
112
|
+
constructor() {
|
|
113
|
+
/** The element itself, for its methods. */
|
|
114
|
+
this.element = hostElement();
|
|
115
|
+
/** A packet set off on step `index` of `flow`. */
|
|
116
|
+
this.bahtStep = output();
|
|
117
|
+
/** A node was clicked or pressed; only with `interactive`. */
|
|
118
|
+
this.bahtNode = output();
|
|
119
|
+
relay(this.element, 'baht-step', this.bahtStep);
|
|
120
|
+
relay(this.element, 'baht-node', this.bahtNode);
|
|
121
|
+
}
|
|
122
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.5", ngImport: i0, type: BahtStickerGraphDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
123
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "22.2.5", type: BahtStickerGraphDirective, isStandalone: true, selector: "baht-sticker-graph", inputs: { graph: "graph", stepMs: ["stepMs", "stepMs", num], paused: ["paused", "paused", booleanAttribute], hideGrid: ["hideGrid", "hideGrid", booleanAttribute], label: "label", interactive: ["interactive", "interactive", booleanAttribute] }, outputs: { bahtStep: "bahtStep", bahtNode: "bahtNode" }, exportAs: ["bahtStickerGraph"], ngImport: i0 }); }
|
|
124
|
+
}
|
|
125
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.5", ngImport: i0, type: BahtStickerGraphDirective, decorators: [{
|
|
126
|
+
type: Directive,
|
|
127
|
+
args: [{ selector: 'baht-sticker-graph', exportAs: 'bahtStickerGraph' }]
|
|
128
|
+
}], ctorParameters: () => [], propDecorators: { graph: [{
|
|
129
|
+
type: Input
|
|
130
|
+
}], stepMs: [{
|
|
131
|
+
type: Input,
|
|
132
|
+
args: [{ transform: num }]
|
|
133
|
+
}], paused: [{
|
|
134
|
+
type: Input,
|
|
135
|
+
args: [{ transform: booleanAttribute }]
|
|
136
|
+
}], hideGrid: [{
|
|
137
|
+
type: Input,
|
|
138
|
+
args: [{ transform: booleanAttribute }]
|
|
139
|
+
}], label: [{
|
|
140
|
+
type: Input
|
|
141
|
+
}], interactive: [{
|
|
142
|
+
type: Input,
|
|
143
|
+
args: [{ transform: booleanAttribute }]
|
|
144
|
+
}], bahtStep: [{ type: i0.Output, args: ["bahtStep"] }], bahtNode: [{ type: i0.Output, args: ["bahtNode"] }] } });
|
|
145
|
+
/** Both sticker directives: `imports: [BAHT_STICKERS]` in a standalone component. */
|
|
146
|
+
export const BAHT_STICKERS = [BahtStickerDirective, BahtStickerGraphDirective];
|
package/dist/store.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Signal, type WritableSignal } from '@angular/core';
|
|
2
|
+
import type { BahtStore } from '@20baht/store';
|
|
3
|
+
/**
|
|
4
|
+
* One ref of a store as a `WritableSignal`: reading follows the store (a bound form's edits
|
|
5
|
+
* included), `set()` writes through `store.set`, so a bound element updates in place. Call it in
|
|
6
|
+
* an injection context (a field initializer or constructor); it unsubscribes on destroy.
|
|
7
|
+
*
|
|
8
|
+
* readonly days = bahtSignal<number>(this.store, 'Request.days');
|
|
9
|
+
*/
|
|
10
|
+
export declare function bahtSignal<T = unknown>(store: BahtStore, ref: string): WritableSignal<T>;
|
|
11
|
+
/** The whole store as a read-only signal (stable identity between changes). */
|
|
12
|
+
export declare function bahtStore(store: BahtStore): Signal<Record<string, unknown>>;
|
package/dist/store.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// @20baht/store as Angular signals: the counterpart of @20baht/store/react's hooks.
|
|
2
|
+
import { DestroyRef, inject, signal } from '@angular/core';
|
|
3
|
+
/**
|
|
4
|
+
* One ref of a store as a `WritableSignal`: reading follows the store (a bound form's edits
|
|
5
|
+
* included), `set()` writes through `store.set`, so a bound element updates in place. Call it in
|
|
6
|
+
* an injection context (a field initializer or constructor); it unsubscribes on destroy.
|
|
7
|
+
*
|
|
8
|
+
* readonly days = bahtSignal<number>(this.store, 'Request.days');
|
|
9
|
+
*/
|
|
10
|
+
export function bahtSignal(store, ref) {
|
|
11
|
+
const value = signal(store.get(ref), /* @ts-ignore */
|
|
12
|
+
...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
|
|
13
|
+
const off = store.subscribe(() => {
|
|
14
|
+
value.set(store.get(ref));
|
|
15
|
+
});
|
|
16
|
+
inject(DestroyRef).onDestroy(off);
|
|
17
|
+
const write = (next) => {
|
|
18
|
+
store.set(ref, next);
|
|
19
|
+
};
|
|
20
|
+
return Object.assign(value.asReadonly(), {
|
|
21
|
+
set: write,
|
|
22
|
+
update: (fn) => {
|
|
23
|
+
write(fn(value()));
|
|
24
|
+
},
|
|
25
|
+
asReadonly: () => value.asReadonly(),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/** The whole store as a read-only signal (stable identity between changes). */
|
|
29
|
+
export function bahtStore(store) {
|
|
30
|
+
const value = signal(store.get(), /* @ts-ignore */
|
|
31
|
+
...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
|
|
32
|
+
const off = store.subscribe((data) => {
|
|
33
|
+
value.set(data);
|
|
34
|
+
});
|
|
35
|
+
inject(DestroyRef).onDestroy(off);
|
|
36
|
+
return value.asReadonly();
|
|
37
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,83 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@20baht/angular",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Angular adapter for @20baht/ui: typed directives on the real <baht-*> elements, with typed outputs, [(value)] two-way binding and the Angular binding gotchas handled. Generated from the elements' manifest.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Nattapong Promthong",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/bank20baht/20baht.git",
|
|
11
|
+
"directory": "packages/angular/ui"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/bank20baht/20baht/tree/main/packages/angular/ui#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/bank20baht/20baht/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"angular",
|
|
19
|
+
"web-components",
|
|
20
|
+
"lit",
|
|
21
|
+
"forms",
|
|
22
|
+
"bahtui"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"LICENSE"
|
|
30
|
+
],
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./store": {
|
|
37
|
+
"types": "./dist/store.d.ts",
|
|
38
|
+
"default": "./dist/store.js"
|
|
39
|
+
},
|
|
40
|
+
"./stickers": {
|
|
41
|
+
"types": "./dist/stickers.d.ts",
|
|
42
|
+
"default": "./dist/stickers.js"
|
|
43
|
+
},
|
|
44
|
+
"./package.json": "./package.json"
|
|
45
|
+
},
|
|
46
|
+
"main": "./dist/index.js",
|
|
47
|
+
"types": "./dist/index.d.ts",
|
|
48
|
+
"sideEffects": false,
|
|
49
|
+
"scripts": {
|
|
50
|
+
"generate": "bun scripts/generate.ts",
|
|
51
|
+
"build": "bun scripts/generate.ts && rm -rf dist && ngc -p tsconfig.json",
|
|
52
|
+
"test": "ngc -p tsconfig.json && vitest run",
|
|
53
|
+
"test:coverage": "ngc -p tsconfig.json && vitest run"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@angular/core": ">=20.0.0",
|
|
57
|
+
"@20baht/stickers": ">=0.1.0 <0.2.0",
|
|
58
|
+
"@20baht/store": ">=0.1.0 <0.2.0",
|
|
59
|
+
"@20baht/ui": ">=0.1.0 <0.2.0"
|
|
60
|
+
},
|
|
61
|
+
"peerDependenciesMeta": {
|
|
62
|
+
"@20baht/store": {
|
|
63
|
+
"optional": true
|
|
64
|
+
},
|
|
65
|
+
"@20baht/stickers": {
|
|
66
|
+
"optional": true
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"devDependencies": {
|
|
70
|
+
"@angular/common": "^22.2.0",
|
|
71
|
+
"@angular/compiler": "^22.2.0",
|
|
72
|
+
"@angular/compiler-cli": "^22.2.0",
|
|
73
|
+
"@angular/core": "^22.2.0",
|
|
74
|
+
"@angular/platform-browser": "^22.2.0",
|
|
75
|
+
"@20baht/stickers": "workspace:*",
|
|
76
|
+
"@20baht/store": "workspace:*",
|
|
77
|
+
"@20baht/ui": "workspace:*",
|
|
78
|
+
"happy-dom": "^20.0.0",
|
|
79
|
+
"rxjs": "^7.8.0",
|
|
80
|
+
"typescript": "~6.0.2",
|
|
81
|
+
"vitest": "^3.2.4"
|
|
82
|
+
}
|
|
83
|
+
}
|