@tempots/ui 1.2.1 → 2.0.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/browser-location-Td-R3jYM.cjs +1 -0
- package/browser-location-Wn6jT0ta.js +39 -0
- package/headless-location-24MkNdBT.cjs +1 -0
- package/{headless-location-Ba_ht5ZQ.js → headless-location-CR5zPUNK.js} +5 -5
- package/index.cjs +1 -1
- package/index.js +411 -421
- package/package.json +2 -2
- package/renderables/appearance.d.ts +1 -1
- package/renderables/resource.d.ts +13 -19
- package/renderables/router/browser-location.d.ts +1 -15
- package/renderables/router/headless-location.d.ts +2 -1
- package/renderables/router/location.d.ts +1 -1
- package/utils/make-relative-time.d.ts +5 -5
- package/utils/resource.d.ts +5 -19
- package/utils/ticker.d.ts +1 -1
- package/browser-location-12vUH3Kv.js +0 -41
- package/browser-location-D36kVbd7.cjs +0 -1
- package/headless-location-8Va85S-Q.cjs +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tempots/ui",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.cjs",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -40,6 +40,6 @@
|
|
|
40
40
|
"@floating-ui/dom": "^1.6.7"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@tempots/std": "0.
|
|
43
|
+
"@tempots/std": "0.18.0"
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -22,7 +22,7 @@ export declare const appearanceMarker: import('@tempots/dom').ProviderMark<Signa
|
|
|
22
22
|
* @returns The child component with the appearance context.
|
|
23
23
|
* @public
|
|
24
24
|
*/
|
|
25
|
-
export declare const ProvideAppearance: (child: TNode) => Renderable;
|
|
25
|
+
export declare const ProvideAppearance: (child: (appearance: Signal<AppearanceType>) => TNode) => Renderable;
|
|
26
26
|
/**
|
|
27
27
|
* Makes the AppearanceType available to the child component by consuming the signal provided by the parent.
|
|
28
28
|
* The result of the function is returned as the final output.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Signal, TNode } from '@tempots/dom';
|
|
2
|
-
import {
|
|
1
|
+
import { Renderable, Signal, TNode } from '@tempots/dom';
|
|
2
|
+
import { AsyncResource, ResourceLoadOptions } from '../utils/resource';
|
|
3
3
|
/**
|
|
4
4
|
* Options for displaying the different states of an asynchronous resource.
|
|
5
5
|
*
|
|
@@ -8,25 +8,13 @@ import { MakeResourceOptions, AsyncResource } from '../utils/resource';
|
|
|
8
8
|
* @public
|
|
9
9
|
*/
|
|
10
10
|
export interface ResourceDisplayOptions<V, E> {
|
|
11
|
-
/** Function to render when the resource has not been requested yet. */
|
|
12
|
-
notAsked?: (reload: () => void) => TNode;
|
|
13
11
|
/** Function to render when the resource is loading. */
|
|
14
12
|
loading?: (previous: Signal<V | undefined>, reload: () => void) => TNode;
|
|
15
13
|
/** Function to render when the resource has failed to load. */
|
|
16
|
-
|
|
14
|
+
failure?: (error: Signal<E>, reload: () => void) => TNode;
|
|
17
15
|
/** Function to render when the resource has successfully loaded. */
|
|
18
16
|
success: (value: Signal<V>, reload: () => void) => TNode;
|
|
19
17
|
}
|
|
20
|
-
/**
|
|
21
|
-
* Options for creating and displaying an asynchronous resource.
|
|
22
|
-
*
|
|
23
|
-
* @template R - The type of the request.
|
|
24
|
-
* @template V - The type of the value when the resource is successfully loaded.
|
|
25
|
-
* @template E - The type of the error when the resource fails to load.
|
|
26
|
-
* @public
|
|
27
|
-
*/
|
|
28
|
-
export interface ResourceOptions<R, V, E> extends MakeResourceOptions<R, V, E>, ResourceDisplayOptions<V, E> {
|
|
29
|
-
}
|
|
30
18
|
/**
|
|
31
19
|
* Component to display an asynchronous resource based on its current status.
|
|
32
20
|
*
|
|
@@ -38,7 +26,7 @@ export interface ResourceOptions<R, V, E> extends MakeResourceOptions<R, V, E>,
|
|
|
38
26
|
* @returns {TNode} A node representing the current state of the resource.
|
|
39
27
|
* @public
|
|
40
28
|
*/
|
|
41
|
-
export declare const ResourceDisplay: <V, E>(resource: AsyncResource<V, E>, options: ResourceDisplayOptions<V, E>) =>
|
|
29
|
+
export declare const ResourceDisplay: <V, E>(resource: AsyncResource<V, E>, options: ResourceDisplayOptions<V, E>) => Renderable;
|
|
42
30
|
/**
|
|
43
31
|
* Creates and displays an asynchronous resource.
|
|
44
32
|
*
|
|
@@ -46,8 +34,14 @@ export declare const ResourceDisplay: <V, E>(resource: AsyncResource<V, E>, opti
|
|
|
46
34
|
* @template V - The type of the value when the resource is successfully loaded.
|
|
47
35
|
* @template E - The type of the error when the resource fails to load.
|
|
48
36
|
*
|
|
49
|
-
* @param
|
|
50
|
-
* @
|
|
37
|
+
* @param request - The request to load the resource.
|
|
38
|
+
* @param load - The function to load the resource.
|
|
39
|
+
* @param convertError - The function to convert an unknown error into a specific error type.
|
|
40
|
+
* @returns A function that takes display options and returns a node representing the current state of the resource.
|
|
51
41
|
* @public
|
|
52
42
|
*/
|
|
53
|
-
export declare const Resource: <R, V, E>(
|
|
43
|
+
export declare const Resource: <R, V, E = unknown>({ request, load, mapError, }: {
|
|
44
|
+
request: Signal<R>;
|
|
45
|
+
load: (options: ResourceLoadOptions<R, V, E>) => Promise<V>;
|
|
46
|
+
mapError?: (error: unknown) => E;
|
|
47
|
+
}) => ((displayOptions: ResourceDisplayOptions<V, E>) => Renderable);
|
|
@@ -1,23 +1,9 @@
|
|
|
1
1
|
import { TNode, Prop } from '@tempots/dom';
|
|
2
2
|
import { LocationData } from './location-data';
|
|
3
|
-
/**
|
|
4
|
-
* Creates a location object based on the current browser location.
|
|
5
|
-
* @returns The location object representing the current browser location.
|
|
6
|
-
* @internal
|
|
7
|
-
*/
|
|
8
|
-
export declare const _makeLocation: () => LocationData;
|
|
9
|
-
/**
|
|
10
|
-
* Creates a location prop that represents the current browser location.
|
|
11
|
-
* The location prop is updated whenever the browser location changes.
|
|
12
|
-
*
|
|
13
|
-
* @returns The location prop.
|
|
14
|
-
* @internal
|
|
15
|
-
*/
|
|
16
|
-
export declare const _makeLocationProp: () => Prop<LocationData>;
|
|
17
3
|
/**
|
|
18
4
|
* Provides the location context to the child component.
|
|
19
5
|
* @param child - The child component to be wrapped with the location context.
|
|
20
6
|
* @returns The wrapped component with the location context.
|
|
21
7
|
* @public
|
|
22
8
|
*/
|
|
23
|
-
export declare const ProvideBrowserLocation: (child: TNode) => import('@tempots/dom').Renderable;
|
|
9
|
+
export declare const ProvideBrowserLocation: (child: (location: Prop<LocationData>) => TNode) => import('@tempots/dom').Renderable;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TNode, Prop } from '@tempots/dom';
|
|
2
|
+
import { LocationData } from './location-data';
|
|
2
3
|
export declare const isAbsoluteURL: (url: string) => boolean;
|
|
3
4
|
/**
|
|
4
5
|
* Provides the location context to the child component.
|
|
@@ -6,4 +7,4 @@ export declare const isAbsoluteURL: (url: string) => boolean;
|
|
|
6
7
|
* @returns The wrapped component with the location context.
|
|
7
8
|
* @public
|
|
8
9
|
*/
|
|
9
|
-
export declare const ProvideHeadlessLocation: (url: Prop<string>, child: TNode) => import('@tempots/dom').Renderable;
|
|
10
|
+
export declare const ProvideHeadlessLocation: (url: Prop<string>, child: (location: Prop<LocationData>) => TNode) => import('@tempots/dom').Renderable;
|
|
@@ -12,7 +12,7 @@ export declare const LocationProviderMarker: import('@tempots/dom').ProviderMark
|
|
|
12
12
|
* @returns The wrapped component with the location context.
|
|
13
13
|
* @public
|
|
14
14
|
*/
|
|
15
|
-
export declare const
|
|
15
|
+
export declare const SetLocation: (child: (location: Prop<LocationData>) => TNode) => import('@tempots/dom').Renderable;
|
|
16
16
|
/**
|
|
17
17
|
* A hook that provides the current location data to the given function.
|
|
18
18
|
* @param fn - The function that receives the location data.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Value } from '@tempots/dom';
|
|
1
|
+
import { Value, Signal } from '@tempots/dom';
|
|
2
2
|
/**
|
|
3
3
|
* Creates a signal that automatically updates with the current time at a specified frequency.
|
|
4
4
|
* The signal will clean up its interval when disposed.
|
|
@@ -7,7 +7,7 @@ import { Value } from '@tempots/dom';
|
|
|
7
7
|
* @returns A Value<Date> that updates with the current time at the specified frequency
|
|
8
8
|
* @public
|
|
9
9
|
*/
|
|
10
|
-
export declare const
|
|
10
|
+
export declare const nowSignal: (frequency?: number) => Signal<Date>;
|
|
11
11
|
/**
|
|
12
12
|
* Converts a time difference in milliseconds to a human-readable relative time string.
|
|
13
13
|
*
|
|
@@ -31,7 +31,7 @@ export declare const timeDiffToString: (diffInMillis: number) => string;
|
|
|
31
31
|
* positive values indicate future times. The signal will clean up its resources when disposed.
|
|
32
32
|
* @public
|
|
33
33
|
*/
|
|
34
|
-
export declare const
|
|
34
|
+
export declare const relativeTimeMillisSignal: (date: Value<Date>, { now, frequency }?: {
|
|
35
35
|
now?: Value<Date>;
|
|
36
36
|
frequency?: number;
|
|
37
37
|
}) => import('@tempots/dom').Computed<number>;
|
|
@@ -46,7 +46,7 @@ export declare const makeRelativeTimeMillisSignal: (date: Value<Date>, { now, fr
|
|
|
46
46
|
* The signal will clean up its resources when disposed.
|
|
47
47
|
* @public
|
|
48
48
|
*/
|
|
49
|
-
export declare const
|
|
49
|
+
export declare const relativeTimeSignal: (date: Value<Date>, options?: {
|
|
50
50
|
now?: Value<Date>;
|
|
51
51
|
frequency?: number;
|
|
52
52
|
}) => import('@tempots/dom').Computed<string>;
|
|
@@ -62,7 +62,7 @@ export declare const makeRelativeTimeSignal: (date: Value<Date>, options?: {
|
|
|
62
62
|
* @deprecated Use makeRelativeTimeSignal instead
|
|
63
63
|
* @public
|
|
64
64
|
*/
|
|
65
|
-
export declare const
|
|
65
|
+
export declare const relativeTime: (date: Value<Date>, options?: {
|
|
66
66
|
now?: Value<Date>;
|
|
67
67
|
frequency?: number;
|
|
68
68
|
}) => import('@tempots/dom').Computed<string>;
|
package/utils/resource.d.ts
CHANGED
|
@@ -38,22 +38,6 @@ export interface ResourceLoadOptions<R, V, E> {
|
|
|
38
38
|
/** The previous result of the resource loading, if any. */
|
|
39
39
|
readonly previous: AsyncResult<V, E>;
|
|
40
40
|
}
|
|
41
|
-
/**
|
|
42
|
-
* Options for creating a resource, including the request signal, load function, and error converter.
|
|
43
|
-
*
|
|
44
|
-
* @template R - The type of the request.
|
|
45
|
-
* @template V - The type of the value when the resource is successfully loaded.
|
|
46
|
-
* @template E - The type of the error when the resource fails to load.
|
|
47
|
-
* @public
|
|
48
|
-
*/
|
|
49
|
-
export interface MakeResourceOptions<R, V, E> {
|
|
50
|
-
/** A signal representing the request to load the resource. */
|
|
51
|
-
readonly request: Signal<R>;
|
|
52
|
-
/** A function to load the resource, returning a promise of the value. */
|
|
53
|
-
readonly load: (options: ResourceLoadOptions<R, V, E>) => Promise<V>;
|
|
54
|
-
/** A function to convert an unknown error into a specific error type. */
|
|
55
|
-
readonly convertError: (error: unknown) => E;
|
|
56
|
-
}
|
|
57
41
|
/**
|
|
58
42
|
* Creates an asynchronous resource that can be loaded, reloaded, and disposed of.
|
|
59
43
|
*
|
|
@@ -61,8 +45,10 @@ export interface MakeResourceOptions<R, V, E> {
|
|
|
61
45
|
* @template V - The type of the value when the resource is successfully loaded.
|
|
62
46
|
* @template E - The type of the error when the resource fails to load.
|
|
63
47
|
*
|
|
64
|
-
* @param
|
|
65
|
-
* @
|
|
48
|
+
* @param request - The request to load the resource.
|
|
49
|
+
* @param load - The function to load the resource.
|
|
50
|
+
* @param convertError - The function to convert an unknown error into a specific error type.
|
|
51
|
+
* @returns The created asynchronous resource.
|
|
66
52
|
* @public
|
|
67
53
|
*/
|
|
68
|
-
export declare const makeResource: <R, V, E>(
|
|
54
|
+
export declare const makeResource: <R, V, E>(request: Signal<R>, load: (options: ResourceLoadOptions<R, V, E>) => Promise<V>, convertError: (error: unknown) => E) => AsyncResource<V, E>;
|
package/utils/ticker.d.ts
CHANGED
|
@@ -19,4 +19,4 @@ export declare class Ticker extends Prop<number> {
|
|
|
19
19
|
* @returns A new Ticker instance that only updates when the value changes
|
|
20
20
|
* @public
|
|
21
21
|
*/
|
|
22
|
-
export declare const
|
|
22
|
+
export declare const ticker: (initial?: number) => Ticker;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { getWindow as r, makeProp as c, Fragment as n, OnDispose as h, WithProvider as i } from "@tempots/dom";
|
|
2
|
-
import { areLocationsEqual as m, urlFromLocation as p, LocationProviderMarker as l } from "./index.js";
|
|
3
|
-
const d = () => {
|
|
4
|
-
const t = r(), o = (t == null ? void 0 : t.location.hash) === "" ? void 0 : (t == null ? void 0 : t.location.hash.substring(1)) ?? void 0;
|
|
5
|
-
return {
|
|
6
|
-
pathname: (t == null ? void 0 : t.location.pathname) ?? "",
|
|
7
|
-
search: Object.fromEntries(
|
|
8
|
-
new URLSearchParams((t == null ? void 0 : t.location.search) ?? "").entries()
|
|
9
|
-
),
|
|
10
|
-
hash: o
|
|
11
|
-
};
|
|
12
|
-
}, L = () => {
|
|
13
|
-
const t = c(d(), m), o = r(), e = () => {
|
|
14
|
-
let a = (o == null ? void 0 : o.location.hash) ?? "";
|
|
15
|
-
a.startsWith("#") && (a = a.substring(1));
|
|
16
|
-
const s = {
|
|
17
|
-
pathname: (o == null ? void 0 : o.location.pathname) ?? "",
|
|
18
|
-
search: Object.fromEntries(
|
|
19
|
-
new URLSearchParams((o == null ? void 0 : o.location.search) ?? "").entries()
|
|
20
|
-
),
|
|
21
|
-
hash: a === "" ? void 0 : a
|
|
22
|
-
};
|
|
23
|
-
t.set(s);
|
|
24
|
-
};
|
|
25
|
-
return o == null || o.addEventListener("popstate", e), t.onDispose(() => {
|
|
26
|
-
o == null || o.removeEventListener("popstate", e);
|
|
27
|
-
}), t.on((a) => {
|
|
28
|
-
o == null || o.history.pushState({}, "", p(a));
|
|
29
|
-
}), t;
|
|
30
|
-
}, P = (t) => {
|
|
31
|
-
const o = L();
|
|
32
|
-
return n(
|
|
33
|
-
h(o.dispose),
|
|
34
|
-
i(l, o, t)
|
|
35
|
-
);
|
|
36
|
-
};
|
|
37
|
-
export {
|
|
38
|
-
P as ProvideBrowserLocation,
|
|
39
|
-
d as _makeLocation,
|
|
40
|
-
L as _makeLocationProp
|
|
41
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@tempots/dom"),r=require("./index.cjs"),n=()=>{const t=a.getWindow(),o=(t==null?void 0:t.location.hash)===""?void 0:(t==null?void 0:t.location.hash.substring(1))??void 0;return{pathname:(t==null?void 0:t.location.pathname)??"",search:Object.fromEntries(new URLSearchParams((t==null?void 0:t.location.search)??"").entries()),hash:o}},c=()=>{const t=a.makeProp(n(),r.areLocationsEqual),o=a.getWindow(),s=()=>{let e=(o==null?void 0:o.location.hash)??"";e.startsWith("#")&&(e=e.substring(1));const i={pathname:(o==null?void 0:o.location.pathname)??"",search:Object.fromEntries(new URLSearchParams((o==null?void 0:o.location.search)??"").entries()),hash:e===""?void 0:e};t.set(i)};return o==null||o.addEventListener("popstate",s),t.onDispose(()=>{o==null||o.removeEventListener("popstate",s)}),t.on(e=>{o==null||o.history.pushState({},"",r.urlFromLocation(e))}),t},h=t=>{const o=c();return a.Fragment(a.OnDispose(o.dispose),a.WithProvider(r.LocationProviderMarker,o,t))};exports.ProvideBrowserLocation=h;exports._makeLocation=n;exports._makeLocationProp=c;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@tempots/dom"),e=require("./index.cjs"),s=t=>t.startsWith("http://")||t.startsWith("https://")||t.startsWith("//"),u=(t,a)=>{const n=t.iso(o=>e.locationFromURL(o),o=>{if(s(o.pathname))return e.urlFromLocation(o);const i=new URL(o.pathname,t.value),c=i.origin+i.pathname;return e.urlFromLocation({...o,pathname:c})});return r.Fragment(r.OnDispose(n.dispose),r.WithProvider(e.LocationProviderMarker,n,a))};exports.ProvideHeadlessLocation=u;exports.isAbsoluteURL=s;
|