bank20baht-ui-angular 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +78 -2
- package/dist/elements.d.ts +2058 -0
- package/dist/elements.js +4596 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/runtime.d.ts +16 -0
- package/dist/runtime.js +36 -0
- package/dist/store.d.ts +12 -0
- package/dist/store.js +37 -0
- package/package.json +72 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './elements.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './elements.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type OutputEmitterRef } from '@angular/core';
|
|
2
|
+
/** The element the directive sits on, typed as its bank20baht-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;
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// What every generated directive shares: the host element, the input transforms, and relaying
|
|
2
|
+
// an element event to an output as its detail.
|
|
3
|
+
import { DestroyRef, ElementRef, inject, numberAttribute, } from '@angular/core';
|
|
4
|
+
/** The element the directive sits on, typed as its bank20baht-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
|
+
const listener = (e) => {
|
|
27
|
+
if (e.target !== el)
|
|
28
|
+
return;
|
|
29
|
+
const detail = e.detail;
|
|
30
|
+
out.emit(pick ? pick(detail) : detail);
|
|
31
|
+
};
|
|
32
|
+
el.addEventListener(name, listener);
|
|
33
|
+
inject(DestroyRef).onDestroy(() => {
|
|
34
|
+
el.removeEventListener(name, listener);
|
|
35
|
+
});
|
|
36
|
+
}
|
package/dist/store.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Signal, type WritableSignal } from '@angular/core';
|
|
2
|
+
import type { BahtStore } from 'bank20baht-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
|
+
// bank20baht-store as Angular signals: the counterpart of bank20baht-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,74 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bank20baht-ui-angular",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Angular adapter for bank20baht-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/bahtui.git",
|
|
11
|
+
"directory": "packages/angular"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/bank20baht/bahtui#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/bank20baht/bahtui/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
|
+
"./package.json": "./package.json"
|
|
41
|
+
},
|
|
42
|
+
"main": "./dist/index.js",
|
|
43
|
+
"types": "./dist/index.d.ts",
|
|
44
|
+
"sideEffects": false,
|
|
45
|
+
"scripts": {
|
|
46
|
+
"generate": "bun scripts/generate.ts",
|
|
47
|
+
"build": "bun scripts/generate.ts && ngc -p tsconfig.json",
|
|
48
|
+
"test": "ngc -p tsconfig.json && vitest run",
|
|
49
|
+
"test:coverage": "ngc -p tsconfig.json && vitest run"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@angular/core": ">=20.0.0",
|
|
53
|
+
"bank20baht-store": ">=0.2.0 <0.3.0",
|
|
54
|
+
"bank20baht-ui": ">=0.18.0 <0.19.0"
|
|
55
|
+
},
|
|
56
|
+
"peerDependenciesMeta": {
|
|
57
|
+
"bank20baht-store": {
|
|
58
|
+
"optional": true
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@angular/common": "^22.2.0",
|
|
63
|
+
"@angular/compiler": "^22.2.0",
|
|
64
|
+
"@angular/compiler-cli": "^22.2.0",
|
|
65
|
+
"@angular/core": "^22.2.0",
|
|
66
|
+
"@angular/platform-browser": "^22.2.0",
|
|
67
|
+
"bank20baht-store": "workspace:*",
|
|
68
|
+
"bank20baht-ui": "workspace:*",
|
|
69
|
+
"happy-dom": "^20.0.0",
|
|
70
|
+
"rxjs": "^7.8.0",
|
|
71
|
+
"typescript": "~6.0.2",
|
|
72
|
+
"vitest": "^3.2.4"
|
|
73
|
+
}
|
|
74
|
+
}
|