@tempots/dom 8.0.1 → 9.0.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.
@@ -1,14 +1,14 @@
1
- import { type JSX } from '../jsx';
1
+ import { type JSX } from '../jsx-runtime';
2
2
  import { type Signal } from '../prop';
3
3
  export interface IfProps {
4
4
  is: Signal<boolean>;
5
- then?: JSX.DOMNode;
6
- otherwise?: JSX.DOMNode;
5
+ then?: () => JSX.DOMNode;
6
+ otherwise?: () => JSX.DOMNode;
7
7
  }
8
8
  export declare function If({ is, then, otherwise }: IfProps): JSX.DOMNode;
9
9
  export interface WhenProps {
10
10
  is: Signal<boolean>;
11
- children?: JSX.DOMNode;
11
+ children?: () => JSX.DOMNode;
12
12
  }
13
13
  export declare function When({ is, children }: WhenProps): JSX.DOMNode;
14
14
  export declare function Unless({ is, children }: WhenProps): JSX.DOMNode;
package/components/If.js CHANGED
@@ -1,19 +1,19 @@
1
1
  import { OneOfImpl } from './OneOf';
2
2
  export function If({ is, then, otherwise }) {
3
- return new OneOfImpl(is.map(v => v ? { 1: true } : { 2: false }), {
4
- 1: () => then,
5
- 2: () => otherwise
3
+ return new OneOfImpl(is.map(v => v ? { then: true } : { otherwise: false }), {
4
+ then: then || (() => null),
5
+ otherwise: otherwise || (() => null)
6
6
  });
7
7
  }
8
8
  export function When({ is, children }) {
9
- return new OneOfImpl(is.map(v => v ? { 1: true } : { 2: false }), {
10
- 1: () => children,
11
- 2: () => null
9
+ return new OneOfImpl(is.map(v => v ? { then: true } : { otherwise: false }), {
10
+ then: children,
11
+ otherwise: (() => null)
12
12
  });
13
13
  }
14
14
  export function Unless({ is, children }) {
15
- return new OneOfImpl(is.map(v => v ? { 1: true } : { 2: false }), {
16
- 1: () => null,
17
- 2: () => children
15
+ return new OneOfImpl(is.map(v => v ? { then: true } : { otherwise: false }), {
16
+ then: (() => null),
17
+ otherwise: children
18
18
  });
19
19
  }
@@ -3,7 +3,7 @@ import { type Signal } from '../prop';
3
3
  import { type JSX } from '../jsx-runtime';
4
4
  export interface NotEmptyProps<T> {
5
5
  on: Signal<T>;
6
- whenEmpty?: JSX.DOMNode;
7
- display: JSX.DOMNode;
6
+ whenEmpty?: () => JSX.DOMNode;
7
+ display: () => JSX.DOMNode;
8
8
  }
9
9
  export declare function NotEmpty<T extends unknown[] | Record<any, unknown>>({ on, display, whenEmpty }: NotEmptyProps<T>): JSX.DOMNode;
@@ -87,6 +87,8 @@ export class RepeatImpl {
87
87
  if (separatorClears.length > 0) {
88
88
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
89
89
  separatorClears.pop()(true);
90
+ }
91
+ if (separatorProps.length > 0) {
90
92
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
91
93
  separatorProps.pop().clean();
92
94
  }
@@ -5,11 +5,11 @@ import { OneOfImpl } from './OneOf';
5
5
  export type Condition<T> = Signal<T | null | undefined> | Signal<T | undefined> | Signal<T | null> | Signal<T>;
6
6
  export interface ShowProps<T> {
7
7
  when: Condition<T>;
8
- otherwise?: JSX.DOMNode;
8
+ otherwise?: () => JSX.DOMNode;
9
9
  children?: (value: Signal<NonNullable<T>>) => JSX.DOMNode;
10
10
  }
11
11
  export declare function Show<T>({ when, children, otherwise }: ShowProps<T>): OneOfImpl<{
12
- T: NonNullable<T>;
12
+ then: NonNullable<T>;
13
13
  } | {
14
- F: false;
14
+ otherwise: false;
15
15
  }>;
@@ -1,8 +1,8 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx } from "../jsx-runtime";
2
2
  import { OneOfImpl } from './OneOf';
3
3
  export function Show({ when, children, otherwise }) {
4
- return new OneOfImpl(when.map(v => (v != null ? { T: v } : { F: false })), {
5
- T: (v) => ((children && children(v)) || _jsx(_Fragment, {})),
6
- F: (_) => (otherwise || _jsx(_Fragment, {}))
4
+ return new OneOfImpl(when.map(v => (v != null ? { then: v } : { otherwise: false })), {
5
+ then: (v) => ((children && children(v)) || _jsx(_Fragment, {})),
6
+ otherwise: otherwise || (() => _jsx(_Fragment, {}))
7
7
  });
8
8
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tempots/dom",
3
3
  "main": "index.js",
4
4
  "types": "index.d.ts",
5
- "version": "8.0.1",
5
+ "version": "9.0.1",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/fponticelli/tempots-dom.git"
package/prop.d.ts CHANGED
@@ -33,6 +33,11 @@ export declare class Signal<T> {
33
33
  readonly clean: () => void;
34
34
  readonly count: () => Signal<number>;
35
35
  readonly animate: (duration: number, interpolate: (start: T, end: T, delta: number) => T, initialValue?: T | null, easing?: (t: number) => number) => Signal<T>;
36
+ readonly equals: (other: Signal<T>, equality?: ((a: T, b: T) => boolean) | undefined) => Signal<boolean>;
37
+ readonly isNull: () => Signal<boolean>;
38
+ readonly isNotNull: () => Signal<boolean>;
39
+ readonly isEmpty: () => Signal<boolean>;
40
+ readonly isNotEmpty: () => Signal<boolean>;
36
41
  }
37
42
  export declare class Prop<T> extends Signal<T> {
38
43
  static isProp<T = unknown>(x: unknown): x is Prop<T>;
package/prop.js CHANGED
@@ -194,6 +194,17 @@ export class Signal {
194
194
  });
195
195
  return prop;
196
196
  };
197
+ equals = (other, equality) => {
198
+ return this.combine(other, (a, b) => {
199
+ if (equality != null)
200
+ return equality(a, b);
201
+ return a === b;
202
+ });
203
+ };
204
+ isNull = () => this.map(value => value == null);
205
+ isNotNull = () => this.map(value => value != null);
206
+ isEmpty = () => this.map(value => value == null || (Reflect.has(value, 'length') && Reflect.get(value, 'length') === 0));
207
+ isNotEmpty = () => this.map(value => value != null && (!Reflect.has(value, 'length') || Reflect.get(value, 'length') !== 0));
197
208
  }
198
209
  export class Prop extends Signal {
199
210
  static isProp(x) {