@alwatr/flux 9.17.0 → 9.18.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/README.md +117 -0
- package/dist/lit-html.d.ts +36 -0
- package/dist/lit-html.d.ts.map +1 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +3 -3
- package/dist/main.js.map +5 -4
- package/package.json +6 -5
- package/src/lit-html.ts +41 -0
- package/src/main.ts +1 -0
package/README.md
CHANGED
|
@@ -945,6 +945,123 @@ renderState(currentState, {
|
|
|
945
945
|
|
|
946
946
|
---
|
|
947
947
|
|
|
948
|
+
### Template (lit-html)
|
|
949
|
+
|
|
950
|
+
`@alwatr/flux` re-exports a curated subset of [`lit-html`](https://lit.dev/docs/libraries/standalone-templates/) so you can render efficient DOM templates without adding a separate dependency.
|
|
951
|
+
|
|
952
|
+
#### `html`
|
|
953
|
+
|
|
954
|
+
Tagged template literal that produces a `TemplateResult`. lit-html parses the template once and only updates the dynamic parts on subsequent renders.
|
|
955
|
+
|
|
956
|
+
```typescript
|
|
957
|
+
import {html} from '@alwatr/flux';
|
|
958
|
+
|
|
959
|
+
const greeting = (name: string) => html`
|
|
960
|
+
<p>Hello, ${name}!</p>
|
|
961
|
+
`;
|
|
962
|
+
```
|
|
963
|
+
|
|
964
|
+
#### `render(value, container)`
|
|
965
|
+
|
|
966
|
+
Renders a `TemplateResult` (or any renderable value) into a DOM container. Subsequent calls efficiently patch only the changed parts.
|
|
967
|
+
|
|
968
|
+
```typescript
|
|
969
|
+
import {html, render} from '@alwatr/flux';
|
|
970
|
+
|
|
971
|
+
render(
|
|
972
|
+
html`
|
|
973
|
+
<h1>Hello World</h1>
|
|
974
|
+
`,
|
|
975
|
+
document.getElementById('app')!,
|
|
976
|
+
);
|
|
977
|
+
```
|
|
978
|
+
|
|
979
|
+
#### `noChange` / `nothing`
|
|
980
|
+
|
|
981
|
+
Sentinels for fine-grained control over part updates:
|
|
982
|
+
|
|
983
|
+
- **`noChange`** — leaves the current DOM value untouched (skips the update entirely)
|
|
984
|
+
- **`nothing`** — removes the node or attribute from the DOM
|
|
985
|
+
|
|
986
|
+
```typescript
|
|
987
|
+
import {html, noChange, nothing} from '@alwatr/flux';
|
|
988
|
+
|
|
989
|
+
const badge = (count: number | undefined) => html`
|
|
990
|
+
<span class="badge">
|
|
991
|
+
${count === undefined ? nothing
|
|
992
|
+
: count === 0 ? noChange
|
|
993
|
+
: count}
|
|
994
|
+
</span>
|
|
995
|
+
`;
|
|
996
|
+
```
|
|
997
|
+
|
|
998
|
+
#### `ifDefined(value)`
|
|
999
|
+
|
|
1000
|
+
Renders the attribute only when `value` is not `undefined`; removes the attribute otherwise.
|
|
1001
|
+
|
|
1002
|
+
```typescript
|
|
1003
|
+
import {html, ifDefined} from '@alwatr/flux';
|
|
1004
|
+
|
|
1005
|
+
const link = (href?: string) => html`
|
|
1006
|
+
<a href=${ifDefined(href)}>Click</a>
|
|
1007
|
+
`;
|
|
1008
|
+
```
|
|
1009
|
+
|
|
1010
|
+
#### `cache(value)`
|
|
1011
|
+
|
|
1012
|
+
Caches rendered templates keyed by their `TemplateResult` identity. Avoids re-parsing the template string when switching between a fixed set of templates (e.g. tab panels).
|
|
1013
|
+
|
|
1014
|
+
```typescript
|
|
1015
|
+
import {html, cache} from '@alwatr/flux';
|
|
1016
|
+
|
|
1017
|
+
const panel = (tab: 'home' | 'settings') =>
|
|
1018
|
+
cache(
|
|
1019
|
+
tab === 'home' ?
|
|
1020
|
+
html`
|
|
1021
|
+
<home-panel></home-panel>
|
|
1022
|
+
`
|
|
1023
|
+
: html`
|
|
1024
|
+
<settings-panel></settings-panel>
|
|
1025
|
+
`,
|
|
1026
|
+
);
|
|
1027
|
+
```
|
|
1028
|
+
|
|
1029
|
+
#### `classMap(classInfo)`
|
|
1030
|
+
|
|
1031
|
+
Efficiently toggles CSS classes from a `{[className]: boolean}` object. Only the classes present in the map are touched; others are left unchanged.
|
|
1032
|
+
|
|
1033
|
+
```typescript
|
|
1034
|
+
import {html, classMap} from '@alwatr/flux';
|
|
1035
|
+
|
|
1036
|
+
const button = (isActive: boolean, isDisabled: boolean) => html`
|
|
1037
|
+
<button class=${classMap({active: isActive, disabled: isDisabled})}>Click</button>
|
|
1038
|
+
`;
|
|
1039
|
+
```
|
|
1040
|
+
|
|
1041
|
+
#### `when(condition, trueCase, falseCase?)`
|
|
1042
|
+
|
|
1043
|
+
Conditional rendering helper. Cleaner than ternary expressions for template branches.
|
|
1044
|
+
|
|
1045
|
+
```typescript
|
|
1046
|
+
import {html, when} from '@alwatr/flux';
|
|
1047
|
+
|
|
1048
|
+
const status = (isLoading: boolean) => html`
|
|
1049
|
+
<div>
|
|
1050
|
+
${when(
|
|
1051
|
+
isLoading,
|
|
1052
|
+
() => html`
|
|
1053
|
+
<spinner-element></spinner-element>
|
|
1054
|
+
`,
|
|
1055
|
+
() => html`
|
|
1056
|
+
<content-element></content-element>
|
|
1057
|
+
`,
|
|
1058
|
+
)}
|
|
1059
|
+
</div>
|
|
1060
|
+
`;
|
|
1061
|
+
```
|
|
1062
|
+
|
|
1063
|
+
---
|
|
1064
|
+
|
|
948
1065
|
## 🆚 Why Choose Alwatr Flux?
|
|
949
1066
|
|
|
950
1067
|
| Feature | React + Redux | Solid.js | Svelte | **Alwatr Flux** 🌊 |
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Curated re-exports from `lit-html` for use within `@alwatr/flux`.
|
|
3
|
+
*
|
|
4
|
+
* Only the subset of `lit-html` APIs that are commonly needed in a Flux-based
|
|
5
|
+
* application is exported here. This keeps the public surface minimal and
|
|
6
|
+
* avoids pulling in advanced directive utilities that most consumers never use.
|
|
7
|
+
*
|
|
8
|
+
* **Exported APIs:**
|
|
9
|
+
* - `html` — tagged template literal that produces a `TemplateResult`
|
|
10
|
+
* - `render` — renders a `TemplateResult` into a DOM container
|
|
11
|
+
* - `noChange` — sentinel that tells lit-html to leave the current part value unchanged
|
|
12
|
+
* - `nothing` — sentinel that renders nothing (removes the node/attribute)
|
|
13
|
+
* - `ifDefined` — renders a value only when it is not `undefined`
|
|
14
|
+
* - `cache` — caches rendered templates to avoid re-parsing on state changes
|
|
15
|
+
* - `classMap` — efficiently sets/removes CSS classes from an object map
|
|
16
|
+
* - `when` — conditional rendering helper (`when(condition, trueCase, falseCase)`)
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import {html, render, classMap, when} from '@alwatr/flux';
|
|
21
|
+
*
|
|
22
|
+
* const template = (isActive: boolean) => html`
|
|
23
|
+
* <div class=${classMap({active: isActive, hidden: !isActive})}>
|
|
24
|
+
* ${when(isActive, () => html`<span>Active</span>`, () => html`<span>Inactive</span>`)}
|
|
25
|
+
* </div>
|
|
26
|
+
* `;
|
|
27
|
+
*
|
|
28
|
+
* render(template(true), document.getElementById('app')!);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export { html, render, noChange, nothing } from 'lit-html';
|
|
32
|
+
export { ifDefined } from 'lit-html/directives/if-defined.js';
|
|
33
|
+
export { cache } from 'lit-html/directives/cache.js';
|
|
34
|
+
export { classMap } from 'lit-html/directives/class-map.js';
|
|
35
|
+
export { when } from 'lit-html/directives/when.js';
|
|
36
|
+
//# sourceMappingURL=lit-html.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lit-html.d.ts","sourceRoot":"","sources":["../src/lit-html.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,OAAO,EAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAC,MAAM,UAAU,CAAC;AAIzD,OAAO,EAAC,SAAS,EAAC,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAC,KAAK,EAAC,MAAM,8BAA8B,CAAC;AACnD,OAAO,EAAC,QAAQ,EAAC,MAAM,kCAAkC,CAAC;AAC1D,OAAO,EAAC,IAAI,EAAC,MAAM,6BAA6B,CAAC"}
|
package/dist/main.d.ts
CHANGED
|
@@ -5,5 +5,6 @@ export * from '@alwatr/render-state';
|
|
|
5
5
|
export * from '@alwatr/local-storage';
|
|
6
6
|
export * from '@alwatr/session-storage';
|
|
7
7
|
export * from '@alwatr/page-ready';
|
|
8
|
+
export * from './lit-html.js';
|
|
8
9
|
export type * from '@alwatr/type-helper';
|
|
9
10
|
//# sourceMappingURL=main.d.ts.map
|
package/dist/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAGA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,mBAAmB,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAGA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,mBAAmB,qBAAqB,CAAC"}
|
package/dist/main.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/* 📦 @alwatr/flux v9.
|
|
2
|
-
export*from"@alwatr/signal";export*from"@alwatr/action";export*from"@alwatr/directive";export*from"@alwatr/render-state";export*from"@alwatr/local-storage";export*from"@alwatr/session-storage";export*from"@alwatr/page-ready";
|
|
1
|
+
/* 📦 @alwatr/flux v9.18.0 */
|
|
2
|
+
export*from"@alwatr/signal";export*from"@alwatr/action";export*from"@alwatr/directive";export*from"@alwatr/render-state";export*from"@alwatr/local-storage";export*from"@alwatr/session-storage";export*from"@alwatr/page-ready";import{html as o,render as a,noChange as t,nothing as p}from"lit-html";import{ifDefined as f}from"lit-html/directives/if-defined.js";import{cache as g}from"lit-html/directives/cache.js";import{classMap as i}from"lit-html/directives/class-map.js";import{when as s}from"lit-html/directives/when.js";export{s as when,a as render,p as nothing,t as noChange,f as ifDefined,o as html,i as classMap,g as cache};
|
|
3
3
|
|
|
4
|
-
//# debugId=
|
|
4
|
+
//# debugId=432FAE968752561764756E2164756E21
|
|
5
5
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/main.ts"],
|
|
3
|
+
"sources": ["../src/main.ts", "../src/lit-html.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"// UI and reactive bundle — signals, actions, directives, and client-side storage.\n// This package aggregates all UI-layer nanolibs for convenient single-import usage.\n\nexport * from '@alwatr/signal';\nexport * from '@alwatr/action';\nexport * from '@alwatr/directive';\nexport * from '@alwatr/render-state';\nexport * from '@alwatr/local-storage';\nexport * from '@alwatr/session-storage';\nexport * from '@alwatr/page-ready';\nexport type * from '@alwatr/type-helper';\n"
|
|
5
|
+
"// UI and reactive bundle — signals, actions, directives, and client-side storage.\n// This package aggregates all UI-layer nanolibs for convenient single-import usage.\n\nexport * from '@alwatr/signal';\nexport * from '@alwatr/action';\nexport * from '@alwatr/directive';\nexport * from '@alwatr/render-state';\nexport * from '@alwatr/local-storage';\nexport * from '@alwatr/session-storage';\nexport * from '@alwatr/page-ready';\nexport * from './lit-html.js';\nexport type * from '@alwatr/type-helper';\n",
|
|
6
|
+
"/**\n * Curated re-exports from `lit-html` for use within `@alwatr/flux`.\n *\n * Only the subset of `lit-html` APIs that are commonly needed in a Flux-based\n * application is exported here. This keeps the public surface minimal and\n * avoids pulling in advanced directive utilities that most consumers never use.\n *\n * **Exported APIs:**\n * - `html` — tagged template literal that produces a `TemplateResult`\n * - `render` — renders a `TemplateResult` into a DOM container\n * - `noChange` — sentinel that tells lit-html to leave the current part value unchanged\n * - `nothing` — sentinel that renders nothing (removes the node/attribute)\n * - `ifDefined` — renders a value only when it is not `undefined`\n * - `cache` — caches rendered templates to avoid re-parsing on state changes\n * - `classMap` — efficiently sets/removes CSS classes from an object map\n * - `when` — conditional rendering helper (`when(condition, trueCase, falseCase)`)\n *\n * @example\n * ```typescript\n * import {html, render, classMap, when} from '@alwatr/flux';\n *\n * const template = (isActive: boolean) => html`\n * <div class=${classMap({active: isActive, hidden: !isActive})}>\n * ${when(isActive, () => html`<span>Active</span>`, () => html`<span>Inactive</span>`)}\n * </div>\n * `;\n *\n * render(template(true), document.getElementById('app')!);\n * ```\n */\nexport {html, render, noChange, nothing} from 'lit-html';\n// export {Directive, PartType, directive} from 'lit-html/directive.js';\n// export {AsyncDirective} from 'lit-html/async-directive.js';\n// export {unsafeSVG} from 'lit-html/directives/unsafe-svg.js';\nexport {ifDefined} from 'lit-html/directives/if-defined.js';\nexport {cache} from 'lit-html/directives/cache.js';\nexport {classMap} from 'lit-html/directives/class-map.js';\nexport {when} from 'lit-html/directives/when.js';\n\n// export type {Part, PartInfo} from 'lit-html/directive.js';\n// export type {LitUnstable} from 'lit-html';\n"
|
|
6
7
|
],
|
|
7
|
-
"mappings": ";AAGA,4BACA,4BACA,+BACA,kCACA,mCACA,qCACA",
|
|
8
|
-
"debugId": "
|
|
8
|
+
"mappings": ";AAGA,4BACA,4BACA,+BACA,kCACA,mCACA,qCACA,gCCqBA,eAAQ,YAAM,cAAQ,aAAU,iBAIhC,oBAAQ,0CACR,gBAAQ,qCACR,mBAAQ,yCACR,eAAQ",
|
|
9
|
+
"debugId": "432FAE968752561764756E2164756E21",
|
|
9
10
|
"names": []
|
|
10
11
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwatr/flux",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.18.0",
|
|
4
4
|
"description": "UI and reactive library bundle for ECMAScript (JavaScript/TypeScript) projects — signals, actions, directives, and storage.",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com> (https://ali.mihandoost.com)",
|
|
@@ -22,13 +22,14 @@
|
|
|
22
22
|
"sideEffects": false,
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@alwatr/action": "9.17.0",
|
|
25
|
-
"@alwatr/directive": "9.
|
|
25
|
+
"@alwatr/directive": "9.18.0",
|
|
26
26
|
"@alwatr/local-storage": "9.16.0",
|
|
27
27
|
"@alwatr/page-ready": "9.16.0",
|
|
28
28
|
"@alwatr/render-state": "9.16.0",
|
|
29
29
|
"@alwatr/session-storage": "9.16.0",
|
|
30
30
|
"@alwatr/signal": "9.16.0",
|
|
31
|
-
"@alwatr/type-helper": "9.14.0"
|
|
31
|
+
"@alwatr/type-helper": "9.14.0",
|
|
32
|
+
"lit-html": "^3.3.2"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"@alwatr/nano-build": "9.14.0",
|
|
@@ -38,7 +39,7 @@
|
|
|
38
39
|
"scripts": {
|
|
39
40
|
"b": "bun run build",
|
|
40
41
|
"build": "bun run build:ts && bun run build:es",
|
|
41
|
-
"build:es": "nano-build --preset=module src
|
|
42
|
+
"build:es": "nano-build --preset=module src/main.ts",
|
|
42
43
|
"build:ts": "tsc --build",
|
|
43
44
|
"cl": "bun run clean",
|
|
44
45
|
"clean": "rm -rfv dist *.tsbuildinfo",
|
|
@@ -81,5 +82,5 @@
|
|
|
81
82
|
"ui",
|
|
82
83
|
"unidirectional-data-flow"
|
|
83
84
|
],
|
|
84
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "ae7aed95106fd2e6d3c14f0628fc12ae8a29ea15"
|
|
85
86
|
}
|
package/src/lit-html.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Curated re-exports from `lit-html` for use within `@alwatr/flux`.
|
|
3
|
+
*
|
|
4
|
+
* Only the subset of `lit-html` APIs that are commonly needed in a Flux-based
|
|
5
|
+
* application is exported here. This keeps the public surface minimal and
|
|
6
|
+
* avoids pulling in advanced directive utilities that most consumers never use.
|
|
7
|
+
*
|
|
8
|
+
* **Exported APIs:**
|
|
9
|
+
* - `html` — tagged template literal that produces a `TemplateResult`
|
|
10
|
+
* - `render` — renders a `TemplateResult` into a DOM container
|
|
11
|
+
* - `noChange` — sentinel that tells lit-html to leave the current part value unchanged
|
|
12
|
+
* - `nothing` — sentinel that renders nothing (removes the node/attribute)
|
|
13
|
+
* - `ifDefined` — renders a value only when it is not `undefined`
|
|
14
|
+
* - `cache` — caches rendered templates to avoid re-parsing on state changes
|
|
15
|
+
* - `classMap` — efficiently sets/removes CSS classes from an object map
|
|
16
|
+
* - `when` — conditional rendering helper (`when(condition, trueCase, falseCase)`)
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import {html, render, classMap, when} from '@alwatr/flux';
|
|
21
|
+
*
|
|
22
|
+
* const template = (isActive: boolean) => html`
|
|
23
|
+
* <div class=${classMap({active: isActive, hidden: !isActive})}>
|
|
24
|
+
* ${when(isActive, () => html`<span>Active</span>`, () => html`<span>Inactive</span>`)}
|
|
25
|
+
* </div>
|
|
26
|
+
* `;
|
|
27
|
+
*
|
|
28
|
+
* render(template(true), document.getElementById('app')!);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export {html, render, noChange, nothing} from 'lit-html';
|
|
32
|
+
// export {Directive, PartType, directive} from 'lit-html/directive.js';
|
|
33
|
+
// export {AsyncDirective} from 'lit-html/async-directive.js';
|
|
34
|
+
// export {unsafeSVG} from 'lit-html/directives/unsafe-svg.js';
|
|
35
|
+
export {ifDefined} from 'lit-html/directives/if-defined.js';
|
|
36
|
+
export {cache} from 'lit-html/directives/cache.js';
|
|
37
|
+
export {classMap} from 'lit-html/directives/class-map.js';
|
|
38
|
+
export {when} from 'lit-html/directives/when.js';
|
|
39
|
+
|
|
40
|
+
// export type {Part, PartInfo} from 'lit-html/directive.js';
|
|
41
|
+
// export type {LitUnstable} from 'lit-html';
|