@manyducks.co/dolla 2.0.0-alpha.5 → 2.0.0-alpha.50
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 +81 -933
- package/dist/core/context.d.ts +65 -0
- package/dist/{modules → core}/dolla.d.ts +43 -26
- package/dist/core/markup.d.ts +102 -0
- package/dist/core/nodes/dom.d.ts +13 -0
- package/dist/core/nodes/dynamic.d.ts +30 -0
- package/dist/core/nodes/fragment.d.ts +19 -0
- package/dist/core/nodes/html.d.ts +34 -0
- package/dist/core/nodes/outlet.d.ts +20 -0
- package/dist/core/nodes/portal.d.ts +22 -0
- package/dist/core/nodes/repeat.d.ts +28 -0
- package/dist/core/nodes/view.d.ts +97 -0
- package/dist/core/signals-api.d.ts +42 -0
- package/dist/core/signals.d.ts +22 -0
- package/dist/core/store.d.ts +52 -0
- package/dist/core/symbols.d.ts +4 -0
- package/dist/{views → core/views}/default-crash-view.d.ts +1 -1
- package/dist/core/views/fragment.d.ts +8 -0
- package/dist/{views → core/views}/passthrough.d.ts +2 -2
- package/dist/fragment-DjTOSAcw.js +8 -0
- package/dist/fragment-DjTOSAcw.js.map +1 -0
- package/dist/{modules/http.d.ts → http/index.d.ts} +3 -5
- package/dist/index.d.ts +15 -10
- package/dist/index.js +1056 -1216
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.d.ts +2 -2
- package/dist/jsx-dev-runtime.js +8 -8
- package/dist/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx-runtime.d.ts +3 -3
- package/dist/jsx-runtime.js +10 -10
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/markup-DZdmoqTk.js +1501 -0
- package/dist/markup-DZdmoqTk.js.map +1 -0
- package/dist/{modules/router.d.ts → router/index.d.ts} +53 -60
- package/dist/{routing.d.ts → router/router.utils.d.ts} +17 -3
- package/dist/router/router.utils.test.d.ts +1 -0
- package/dist/translate/index.d.ts +133 -0
- package/dist/typeChecking.d.ts +2 -98
- package/dist/typeChecking.test.d.ts +1 -0
- package/dist/types.d.ts +17 -7
- package/dist/utils.d.ts +18 -3
- package/docs/http.md +29 -0
- package/docs/i18n.md +38 -0
- package/docs/index.md +10 -0
- package/docs/router.md +80 -0
- package/docs/setup.md +31 -0
- package/docs/signals.md +166 -0
- package/docs/state.md +141 -0
- package/docs/stores.md +62 -0
- package/docs/views.md +208 -0
- package/examples/webcomponent/index.html +14 -0
- package/examples/webcomponent/main.js +165 -0
- package/index.d.ts +2 -2
- package/notes/TODO.md +6 -0
- package/notes/atomic.md +452 -0
- package/notes/context-routes.md +61 -0
- package/notes/custom-nodes.md +17 -0
- package/notes/elimination.md +33 -0
- package/notes/molecule.md +35 -0
- package/notes/readme-scratch.md +260 -0
- package/notes/route-middleware.md +42 -0
- package/notes/scratch.md +330 -7
- package/notes/splitting.md +5 -0
- package/notes/stores.md +53 -0
- package/package.json +13 -10
- package/vite.config.js +5 -10
- package/build.js +0 -34
- package/dist/markup.d.ts +0 -100
- package/dist/modules/language.d.ts +0 -41
- package/dist/modules/render.d.ts +0 -17
- package/dist/nodes/cond.d.ts +0 -26
- package/dist/nodes/html.d.ts +0 -31
- package/dist/nodes/observer.d.ts +0 -29
- package/dist/nodes/outlet.d.ts +0 -22
- package/dist/nodes/portal.d.ts +0 -19
- package/dist/nodes/repeat.d.ts +0 -34
- package/dist/nodes/text.d.ts +0 -19
- package/dist/passthrough-CtoBcpag.js +0 -1245
- package/dist/passthrough-CtoBcpag.js.map +0 -1
- package/dist/signals.d.ts +0 -101
- package/dist/view.d.ts +0 -50
- package/tests/signals.test.js +0 -135
- /package/dist/{routing.test.d.ts → core/signals-api.test.d.ts} +0 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { Dolla } from "../core/dolla.js";
|
|
2
|
+
import { type MaybeSignal, type Signal } from "../core/signals-api.js";
|
|
3
|
+
/**
|
|
4
|
+
* A JSON object of translated strings. Values can be string templates or nested objects.
|
|
5
|
+
*/
|
|
6
|
+
interface LocalizedStrings extends Record<string, string | LocalizedStrings> {
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A formatter to be applied to a variable.
|
|
10
|
+
*/
|
|
11
|
+
type Format = {
|
|
12
|
+
name: string;
|
|
13
|
+
options: Record<string, any>;
|
|
14
|
+
};
|
|
15
|
+
export interface TranslationConfig {
|
|
16
|
+
/**
|
|
17
|
+
* Name of the locale this translation is for (BCP 47 locale names recommended).
|
|
18
|
+
*/
|
|
19
|
+
locale: string;
|
|
20
|
+
/**
|
|
21
|
+
* An object with translated strings for this language.
|
|
22
|
+
*/
|
|
23
|
+
strings?: LocalizedStrings;
|
|
24
|
+
/**
|
|
25
|
+
* A callback function that returns a Promise that resolves to the translation object for this language.
|
|
26
|
+
*/
|
|
27
|
+
fetch?: () => Promise<LocalizedStrings>;
|
|
28
|
+
/**
|
|
29
|
+
* Path to a JSON file with translated strings for this language.
|
|
30
|
+
*/
|
|
31
|
+
path?: string;
|
|
32
|
+
}
|
|
33
|
+
export type I18nSetupOptions = {
|
|
34
|
+
/**
|
|
35
|
+
* Default locale to load on startup
|
|
36
|
+
*/
|
|
37
|
+
locale?: string | null;
|
|
38
|
+
translations: TranslationConfig[];
|
|
39
|
+
};
|
|
40
|
+
export type TOptions = {
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
count?: MaybeSignal<number>;
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
*/
|
|
48
|
+
context?: MaybeSignal<string>;
|
|
49
|
+
/**
|
|
50
|
+
* Override formats specified in the template with the ones in the array for each named variable.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* t("example_key", {
|
|
54
|
+
* count: 5,
|
|
55
|
+
* formatOverrides: {
|
|
56
|
+
* count: [ { name: "datetime", options: { style: "currency", currency: "JPY" } } ]
|
|
57
|
+
* }
|
|
58
|
+
* });
|
|
59
|
+
*/
|
|
60
|
+
formatOverrides?: MaybeSignal<Record<string, Record<string, Format[]>>>;
|
|
61
|
+
[value: string]: MaybeSignal<any>;
|
|
62
|
+
};
|
|
63
|
+
export type Formatter = (locale: string, value: unknown, options: Record<string, any>) => string;
|
|
64
|
+
/**
|
|
65
|
+
* Dolla's I(nternationalizatio)n module. Manages language translations and locale-based formatting.
|
|
66
|
+
*/
|
|
67
|
+
export declare class I18n {
|
|
68
|
+
#private;
|
|
69
|
+
readonly locale: Signal<string>;
|
|
70
|
+
constructor(dolla: Dolla);
|
|
71
|
+
get locales(): string[];
|
|
72
|
+
setup(options: I18nSetupOptions): void;
|
|
73
|
+
setLocale(name: string): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Returns a State containing the value at `key`.
|
|
76
|
+
|
|
77
|
+
* @param selector - Key to the translated value.
|
|
78
|
+
* @param options - A map of `{{placeholder}}` names and the values to replace them with.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* const $value = t("your.key.here", { count: 5 });
|
|
82
|
+
*/
|
|
83
|
+
t(selector: string, options?: TOptions): Signal<string>;
|
|
84
|
+
/**
|
|
85
|
+
* Add a custom format callback.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* Dolla.i18n.addFormat("uppercase", (locale, value, options) => {
|
|
89
|
+
* return value.toUpperCase();
|
|
90
|
+
* });
|
|
91
|
+
*
|
|
92
|
+
* {
|
|
93
|
+
* "greeting": "Hello, {{name|uppercase}}!"
|
|
94
|
+
* }
|
|
95
|
+
*
|
|
96
|
+
* t("greeting", {name: "world"}); // State<"Hello, WORLD!">
|
|
97
|
+
*/
|
|
98
|
+
addFormat(name: string, callback: (locale: string, value: unknown, options: Record<string, any>) => string): void;
|
|
99
|
+
/**
|
|
100
|
+
* Creates an `Intl.Collator` configured for the current locale.
|
|
101
|
+
* NOTE: The locale is tracked if called within a signal tracking context.
|
|
102
|
+
*
|
|
103
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options
|
|
104
|
+
*/
|
|
105
|
+
collator(options?: Intl.CollatorOptions): Intl.Collator;
|
|
106
|
+
/**
|
|
107
|
+
* Formats a number for the current locale. Uses `Intl.NumberFormat` under the hood.
|
|
108
|
+
*
|
|
109
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options
|
|
110
|
+
*/
|
|
111
|
+
number(count: MaybeSignal<number | bigint>, options?: Intl.NumberFormatOptions): Signal<string>;
|
|
112
|
+
/**
|
|
113
|
+
* Formats a date for the current locale. Uses `Intl.DateTimeFormat` under the hood.
|
|
114
|
+
*
|
|
115
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* const date = new Date();
|
|
119
|
+
* const $formatted = Dolla.i18n.dateTime(date, { dateFormat: "short" });
|
|
120
|
+
*/
|
|
121
|
+
dateTime(date?: MaybeSignal<string | number | Date | undefined>, options?: Intl.DateTimeFormatOptions): Signal<string>;
|
|
122
|
+
/**
|
|
123
|
+
* Formats a list for the current locale. Uses `Intl.ListFormat` under the hood.
|
|
124
|
+
*
|
|
125
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* const list = new Date();
|
|
129
|
+
* const $formatted = Dolla.i18n.list(list, { });
|
|
130
|
+
*/
|
|
131
|
+
list(list: MaybeSignal<Iterable<string>>, options?: Intl.ListFormatOptions): Signal<string>;
|
|
132
|
+
}
|
|
133
|
+
export {};
|
package/dist/typeChecking.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
type TypeNames = "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "null" | "array" | "class" | "promise" | "NaN";
|
|
1
|
+
type TypeNames = "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "null" | "array" | "class" | "promise" | "map" | "set" | "NaN";
|
|
2
2
|
/**
|
|
3
3
|
* Extends `typeof` operator with more specific and useful type distinctions.
|
|
4
4
|
*/
|
|
5
|
-
export declare function typeOf(value:
|
|
5
|
+
export declare function typeOf(value: any): TypeNames;
|
|
6
6
|
/**
|
|
7
7
|
* Throws a TypeError unless `condition` is truthy.
|
|
8
8
|
*
|
|
@@ -18,12 +18,6 @@ export declare function isArray(value: unknown): value is Array<unknown>;
|
|
|
18
18
|
* Throws an error if `value` is not an array.
|
|
19
19
|
*/
|
|
20
20
|
export declare function assertArray(value: unknown, errorMessage?: string): value is Array<unknown>;
|
|
21
|
-
/**
|
|
22
|
-
* Returns a function that takes a `value` and ensures that it is an array for which `check` returns true for every item.
|
|
23
|
-
*
|
|
24
|
-
* @param check - Function to check items against.
|
|
25
|
-
*/
|
|
26
|
-
export declare function isArrayOf<T>(check: (item: unknown) => boolean): (value: unknown) => value is T[];
|
|
27
21
|
/**
|
|
28
22
|
* Returns true when `value` is an array and `check` returns true for every item.
|
|
29
23
|
*
|
|
@@ -31,12 +25,6 @@ export declare function isArrayOf<T>(check: (item: unknown) => boolean): (value:
|
|
|
31
25
|
* @param value - A possible array.
|
|
32
26
|
*/
|
|
33
27
|
export declare function isArrayOf<T>(check: (item: unknown) => boolean, value: unknown): value is T[];
|
|
34
|
-
/**
|
|
35
|
-
* Returns a function that takes a `value` and throws a TypeError unless it is an array for which `check` returns true for every item.
|
|
36
|
-
*
|
|
37
|
-
* @param check - Function to check items against.
|
|
38
|
-
*/
|
|
39
|
-
export declare function assertArrayOf<T>(check: (item: unknown) => boolean): (value: unknown) => value is T[];
|
|
40
28
|
/**
|
|
41
29
|
* Throws a TypeError unless `value` is an array and `check` returns true for every item.
|
|
42
30
|
*
|
|
@@ -45,14 +33,6 @@ export declare function assertArrayOf<T>(check: (item: unknown) => boolean): (va
|
|
|
45
33
|
* @param errorMessage - A custom error message.
|
|
46
34
|
*/
|
|
47
35
|
export declare function assertArrayOf<T>(check: (item: unknown) => boolean, value: unknown, errorMessage?: string): value is T[];
|
|
48
|
-
/**
|
|
49
|
-
* Returns true if `value` is equal to `true` or `false`.
|
|
50
|
-
*/
|
|
51
|
-
export declare function isBoolean(value: unknown): value is boolean;
|
|
52
|
-
/**
|
|
53
|
-
* Throws a TypeError unless `value` is equal to `true` or `false`.
|
|
54
|
-
*/
|
|
55
|
-
export declare function assertBoolean(value: unknown, errorMessage?: string): value is boolean;
|
|
56
36
|
/**
|
|
57
37
|
* Returns true if `value` is a string.
|
|
58
38
|
*/
|
|
@@ -77,34 +57,6 @@ export declare function isNumber(value: unknown): value is number;
|
|
|
77
57
|
* Throws a TypeError unless `value` is a number.
|
|
78
58
|
*/
|
|
79
59
|
export declare function assertNumber(value: unknown, errorMessage?: string): value is number;
|
|
80
|
-
/**
|
|
81
|
-
* Returns true if `value` implements the Promise protocol.
|
|
82
|
-
* This matches true instances of Promise as well as any object that
|
|
83
|
-
* implements `next`, `catch` and `finally` methods.
|
|
84
|
-
*
|
|
85
|
-
* To strictly match instances of Promise, use `isInstanceOf(Promise)`.
|
|
86
|
-
*/
|
|
87
|
-
export declare function isPromise<T = unknown>(value: unknown): value is Promise<T>;
|
|
88
|
-
/**
|
|
89
|
-
* Throws a TypeError unless `value` implements the Promise protocol.
|
|
90
|
-
* This matches true instances of Promise as well as any object that
|
|
91
|
-
* implements `next`, `catch` and `finally` methods.
|
|
92
|
-
*
|
|
93
|
-
* To strictly allow only instances of Promise, use `Type.assertInstanceOf(Promise)`.
|
|
94
|
-
*/
|
|
95
|
-
export declare function assertPromise<T = unknown>(value: unknown, errorMessage?: string): value is Promise<T>;
|
|
96
|
-
/**
|
|
97
|
-
* Returns true if `value` is a class.
|
|
98
|
-
*/
|
|
99
|
-
export declare function isClass(value: unknown): value is {
|
|
100
|
-
new (): unknown;
|
|
101
|
-
};
|
|
102
|
-
/**
|
|
103
|
-
* Throws a TypeError unless `value` is a class.
|
|
104
|
-
*/
|
|
105
|
-
export declare function assertClass(value: unknown, errorMessage?: string): value is {
|
|
106
|
-
new (): unknown;
|
|
107
|
-
};
|
|
108
60
|
/**
|
|
109
61
|
* Returns a function that takes a `value` and returns true if `value` is an instance of `constructor`.
|
|
110
62
|
*
|
|
@@ -132,30 +84,6 @@ export declare function assertInstanceOf<T extends Function>(constructor: T): (v
|
|
|
132
84
|
* @param errorMessage - A custom error message for when the assertion fails.
|
|
133
85
|
*/
|
|
134
86
|
export declare function assertInstanceOf<T extends Function>(constructor: T, value: unknown, errorMessage?: string): value is T;
|
|
135
|
-
/**
|
|
136
|
-
* Returns true if `value` is a Map.
|
|
137
|
-
*/
|
|
138
|
-
export declare function isMap<K = unknown, V = unknown>(value: any): value is Map<K, V>;
|
|
139
|
-
/**
|
|
140
|
-
* Throws a TypeError unless `value` is a Map.
|
|
141
|
-
*/
|
|
142
|
-
export declare function assertMap<K = unknown, V = unknown>(value: any, errorMessage?: string): value is Map<K, V>;
|
|
143
|
-
/**
|
|
144
|
-
* Returns true if `value` is a Set.
|
|
145
|
-
*/
|
|
146
|
-
export declare function isSet<T = unknown>(value: any): value is Set<T>;
|
|
147
|
-
/**
|
|
148
|
-
* Throws a TypeError if `value` is not a Set.
|
|
149
|
-
*/
|
|
150
|
-
export declare function assertSet<T = unknown>(value: any, errorMessage?: string): value is Set<T>;
|
|
151
|
-
/**
|
|
152
|
-
* Returns true if `value` implements the Iterable protocol.
|
|
153
|
-
*/
|
|
154
|
-
export declare function isIterable<T>(value: any): value is Iterable<T>;
|
|
155
|
-
/**
|
|
156
|
-
* Throws a TypeError unless `value` implements the Iterable protocol.
|
|
157
|
-
*/
|
|
158
|
-
export declare function assertIterable<T>(value: any, errorMessage?: string): value is Iterable<T>;
|
|
159
87
|
/**
|
|
160
88
|
* Returns true if `value` is a plain JavaScript object.
|
|
161
89
|
*/
|
|
@@ -164,28 +92,4 @@ export declare function isObject(value: unknown): value is Record<string | numbe
|
|
|
164
92
|
* Throws a TypeError unless `value` is a plain JavaScript object.
|
|
165
93
|
*/
|
|
166
94
|
export declare function assertObject(value: unknown, errorMessage?: string): value is object;
|
|
167
|
-
/**
|
|
168
|
-
* Returns true if `value` is equal to `null`.
|
|
169
|
-
*/
|
|
170
|
-
export declare function isNull(value: unknown): value is null;
|
|
171
|
-
/**
|
|
172
|
-
* Throws a TypeError unless `value` is equal to `null`.
|
|
173
|
-
*/
|
|
174
|
-
export declare function assertNull(value: unknown, errorMessage?: string): value is null;
|
|
175
|
-
/**
|
|
176
|
-
* Returns true if `value` is equal to `undefined`.
|
|
177
|
-
*/
|
|
178
|
-
export declare function isUndefined(value: unknown): value is undefined;
|
|
179
|
-
/**
|
|
180
|
-
* Throws a TypeError unless `value` is equal to `undefined`.
|
|
181
|
-
*/
|
|
182
|
-
export declare function assertUndefined(value: unknown, errorMessage?: string): value is undefined;
|
|
183
|
-
/**
|
|
184
|
-
* Returns true if `value` is equal to `null` or `undefined`.
|
|
185
|
-
*/
|
|
186
|
-
export declare function isEmpty(value: unknown): value is void;
|
|
187
|
-
/**
|
|
188
|
-
* Throws a TypeError unless `value` is equal to `null` or `undefined`.
|
|
189
|
-
*/
|
|
190
|
-
export declare function assertEmpty(value: unknown, errorMessage?: string): value is void;
|
|
191
95
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as CSS from "csstype";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import type { Markup } from "./core/markup.js";
|
|
3
|
+
import { Signal } from "./core/signals-api.js";
|
|
4
4
|
/**
|
|
5
5
|
* Represents everything that can be handled as a DOM node.
|
|
6
6
|
* These are all the items considered valid to pass as children to any element.
|
|
@@ -10,7 +10,7 @@ export type Stringable = {
|
|
|
10
10
|
toString(): string;
|
|
11
11
|
};
|
|
12
12
|
type MaybeSignal<T> = T | Signal<T> | Signal<T | undefined>;
|
|
13
|
-
type OptionalProperty<T> =
|
|
13
|
+
type OptionalProperty<T> = MaybeSignal<T>;
|
|
14
14
|
type RequiredProperty<T> = T | Signal<T>;
|
|
15
15
|
type AutocapitalizeValues = "off" | "on" | "none" | "sentences" | "words" | "characters";
|
|
16
16
|
type ContentEditableValues = true | false | "true" | "false" | "plaintext-only" | "inherit";
|
|
@@ -23,6 +23,18 @@ type InputModeValues = "decimal" | "email" | "none" | "numeric" | "search" | "te
|
|
|
23
23
|
* Properties common to all Elements.
|
|
24
24
|
*/
|
|
25
25
|
export interface ElementProps {
|
|
26
|
+
/**
|
|
27
|
+
* Sets the value as an HTML attribute.
|
|
28
|
+
*/
|
|
29
|
+
[key: `attr:${string}`]: OptionalProperty<any>;
|
|
30
|
+
/**
|
|
31
|
+
* Sets the value directly on the HTMLElement as a property.
|
|
32
|
+
*/
|
|
33
|
+
[key: `prop:${string}`]: OptionalProperty<any>;
|
|
34
|
+
/**
|
|
35
|
+
* Attaches an event listener to the element (with `addEventListener`).
|
|
36
|
+
*/
|
|
37
|
+
[key: `on:${string}`]: OptionalProperty<EventHandler<Event>>;
|
|
26
38
|
/**
|
|
27
39
|
* HTML attributes to assign to the element.
|
|
28
40
|
*/
|
|
@@ -30,7 +42,6 @@ export interface ElementProps {
|
|
|
30
42
|
/**
|
|
31
43
|
* Object of event listeners.
|
|
32
44
|
*/
|
|
33
|
-
eventListeners?: OptionalProperty<Record<string, EventHandler<Event>>>;
|
|
34
45
|
/**
|
|
35
46
|
* CSS classes to be applied to this element. In addition to the standard space-separated list of class names,
|
|
36
47
|
* this property also supports a class map object with class names as keys and booleans as values.
|
|
@@ -1219,9 +1230,9 @@ export interface PropertiesOf<E extends HTMLElement> extends HTMLElementProps {
|
|
|
1219
1230
|
*/
|
|
1220
1231
|
children?: any;
|
|
1221
1232
|
/**
|
|
1222
|
-
*
|
|
1233
|
+
* Receives a reference to the DOM node when rendered.
|
|
1223
1234
|
*/
|
|
1224
|
-
ref?:
|
|
1235
|
+
ref?: ((value: E | undefined) => void) | ((value: HTMLElement | undefined) => void) | ((value: Element | undefined) => void) | ((value: Node | undefined) => void);
|
|
1225
1236
|
}
|
|
1226
1237
|
/**
|
|
1227
1238
|
* The following elements are defined based on the WHATWG HTML spec:
|
|
@@ -3143,7 +3154,6 @@ interface HTMLInputElementProps extends PropertiesOf<HTMLInputElement> {
|
|
|
3143
3154
|
step?: OptionalProperty<number>;
|
|
3144
3155
|
type?: OptionalProperty<InputType>;
|
|
3145
3156
|
value?: OptionalProperty<string>;
|
|
3146
|
-
$$value?: SettableSignal<any>;
|
|
3147
3157
|
width?: OptionalProperty<string | number> | OptionalProperty<string> | OptionalProperty<number>;
|
|
3148
3158
|
title?: OptionalProperty<string>;
|
|
3149
3159
|
/**
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
export declare const noOp: () => void;
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function getUniqueId(): string;
|
|
3
|
+
/**
|
|
4
|
+
* Equality check that passes if both values are the same object.
|
|
5
|
+
* This is the default equality check for states.
|
|
6
|
+
*/
|
|
7
|
+
export declare function strictEqual(a: any, b: any): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Equality check that passes if both values are the same object, or if both are objects or arrays with equal keys and values.
|
|
10
|
+
*/
|
|
11
|
+
export declare function shallowEqual(a: any, b: any): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Equality check that passes if two objects have equal values, even if they are not the same object.
|
|
14
|
+
*/
|
|
15
|
+
export declare function deepEqual(a: any, b: any): boolean;
|
|
3
16
|
/**
|
|
4
17
|
* Takes an old value and a new value. Returns a merged copy if both are objects, otherwise returns the new value.
|
|
5
18
|
*/
|
|
@@ -13,8 +26,10 @@ export declare function merge(one: unknown, two: unknown): any;
|
|
|
13
26
|
* @param object - An object to clone without the omitted keys.
|
|
14
27
|
*/
|
|
15
28
|
export declare function omit<O extends Record<any, any>>(keys: (keyof O)[], object: O): Record<any, any>;
|
|
16
|
-
|
|
17
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Takes any string and returns an OKLCH color.
|
|
31
|
+
*/
|
|
32
|
+
export declare function okhash(value: string): string;
|
|
18
33
|
export type MatcherFunction = (value: string) => boolean;
|
|
19
34
|
/**
|
|
20
35
|
* Parses a filter string into a matcher function.
|
package/docs/http.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# HTTP Client
|
|
2
|
+
|
|
3
|
+
> TODO: Write me.
|
|
4
|
+
|
|
5
|
+
This page goes into detail on how to use the built in HTTP client.
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import { http } from "@manyducks.co/dolla";
|
|
9
|
+
|
|
10
|
+
http.use(async (req, next) => {
|
|
11
|
+
// Apply auth header to all API routes.
|
|
12
|
+
if (req.url.pathname.startsWith("/api/")) {
|
|
13
|
+
req.headers.set("authorization", `Bearer ${localStorage.getItem("api-key")}`);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
await next();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const res = await http.get("/api/some-api-route");
|
|
20
|
+
res.body; // body is already parsed as JSON if server responded with JSON
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
End.
|
|
26
|
+
|
|
27
|
+
- [🗂️ Docs](./index.md)
|
|
28
|
+
- [🏠 README](../README.md)
|
|
29
|
+
- [🦆 That's a lot of ducks.](https://www.manyducks.co)
|
package/docs/i18n.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Internationalization (i18n) Support
|
|
2
|
+
|
|
3
|
+
```jsx
|
|
4
|
+
import Dolla, { createState, t } from "@manyducks.co/dolla";
|
|
5
|
+
|
|
6
|
+
function CounterView(props) {
|
|
7
|
+
const [$count, setCount] = createState(0);
|
|
8
|
+
|
|
9
|
+
const increment = () => {
|
|
10
|
+
setCount((count) => count + 1);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<div>
|
|
15
|
+
<p>Clicks: {$count}</p>
|
|
16
|
+
<button onClick={increment}>{t("buttonLabel")}</button>
|
|
17
|
+
</div>
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
Dolla.i18n.setup({
|
|
22
|
+
locale: "en",
|
|
23
|
+
translations: [
|
|
24
|
+
{ locale: "en", strings: { buttonLabel: "Click here to increment" } },
|
|
25
|
+
{ locale: "ja", strings: { buttonLabel: "ここに押して増加する" } },
|
|
26
|
+
],
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
Dolla.mount(document.body, CounterView);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
End.
|
|
35
|
+
|
|
36
|
+
- [🗂️ Docs](./index.md)
|
|
37
|
+
- [🏠 README](../README.md)
|
|
38
|
+
- [🦆 That's a lot of ducks.](https://www.manyducks.co)
|
package/docs/index.md
ADDED
package/docs/router.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Router
|
|
2
|
+
|
|
3
|
+
Dolla makes heavy use of client-side routing. You can define as many routes as you have views, and the URL
|
|
4
|
+
will determine which one the app shows at any given time. By building an app around routes, lots of things one expects
|
|
5
|
+
from a web app will just work; back and forward buttons, sharable URLs, bookmarks, etc.
|
|
6
|
+
|
|
7
|
+
Routes are matched by highest specificity regardless of the order they were registered.
|
|
8
|
+
This avoids some confusing situations that come up with order-based routers like that of `express`.
|
|
9
|
+
On the other hand, order-based routers can support regular expressions as patterns which Dolla's router cannot.
|
|
10
|
+
|
|
11
|
+
## Route Patterns
|
|
12
|
+
|
|
13
|
+
Routes are defined with strings called patterns. A pattern defines the shape the URL path must match, with special
|
|
14
|
+
placeholders for variables that appear within the route. Values matched by those placeholders are parsed out and exposed
|
|
15
|
+
to your code (`router` store, `$params` readable). Below are some examples of patterns and how they work.
|
|
16
|
+
|
|
17
|
+
- Static: `/this/is/static` has no params and will match only when the route is exactly `/this/is/static`.
|
|
18
|
+
- Numeric params: `/users/{#id}/edit` has the named param `{#id}` which matches numbers only, such as `123` or `52`. The
|
|
19
|
+
resulting value will be parsed as a number.
|
|
20
|
+
- Generic params: `/users/{name}` has the named param `{name}` which matches anything in that position in the path. The
|
|
21
|
+
resulting value will be a string.
|
|
22
|
+
- Wildcard: `/users/*` will match anything beginning with `/users` and store everything after that in params
|
|
23
|
+
as `wildcard`. `*` is valid only at the end of a route.
|
|
24
|
+
|
|
25
|
+
Now, here are some route examples in the context of an app:
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
import Dolla, { createRouter } from "@manyducks.co/dolla";
|
|
29
|
+
import { ThingIndex, ThingDetails, ThingEdit, ThingDelete } from "./views.js";
|
|
30
|
+
|
|
31
|
+
const router = createRouter({
|
|
32
|
+
routes: [
|
|
33
|
+
{
|
|
34
|
+
// A `null` component with subroutes acts as a namespace for those subroutes.
|
|
35
|
+
// Passing a view instead of `null` results in subroutes being rendered inside that view wherever `ctx.outlet()` is called.
|
|
36
|
+
path: "/things",
|
|
37
|
+
view: null,
|
|
38
|
+
routes: [
|
|
39
|
+
{ path: "/", view: ThingIndex }, // matches `/things`
|
|
40
|
+
{ path: "/{#id}", view: ThingDetails }, // matches `/things/{#id}`
|
|
41
|
+
{ path: "/{#id}/edit", view: ThingEdit }, // matches `/things/{#id}/edit`
|
|
42
|
+
{ path: "/{#id}/delete", view: ThingDelete }, // matches `/things/{#id}/delete`
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
// All routes that don't match anything else will redirect to `/things`
|
|
46
|
+
{ path: "*", redirect: "/things" },
|
|
47
|
+
],
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// Mount the router in place of a view.
|
|
51
|
+
Dolla.mount(document.body, router);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
When the URL matches a pattern the corresponding view is displayed. If we visit `/people/john`,
|
|
55
|
+
we will see the `PersonDetails` view and the params will be `{ name: "john" }`. Params can be
|
|
56
|
+
accessed from anywhere in the app through `Dolla.router`.
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
import Dolla from "@manyducks.co/dolla";
|
|
60
|
+
|
|
61
|
+
// Info about the current route is exported as a set of Readables. Query params are also Writable through $$query:
|
|
62
|
+
const { $path, $pattern, $params, $query } = router;
|
|
63
|
+
|
|
64
|
+
router.back(); // Step back in the history to the previous route, if any.
|
|
65
|
+
router.back(2); // Hit the back button twice.
|
|
66
|
+
|
|
67
|
+
router.forward(); // Step forward in the history to the next route, if any.
|
|
68
|
+
router.forward(4); // Hit the forward button 4 times.
|
|
69
|
+
|
|
70
|
+
router.go("/things/152"); // Navigate to another path within the same app.
|
|
71
|
+
router.go("https://www.example.com/another/site"); // Navigate to another domain entirely.
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
End.
|
|
77
|
+
|
|
78
|
+
- [🗂️ Docs](./index.md)
|
|
79
|
+
- [🏠 README](../README.md)
|
|
80
|
+
- [🦆 That's a lot of ducks.](https://www.manyducks.co)
|
package/docs/setup.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Setting up Dolla
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
Dolla is published on npm as `@manyducks.co/dolla`. You can install it in your project with the following command:
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
npm i @manyducks.co/dolla
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## JSX
|
|
12
|
+
|
|
13
|
+
If you want to use JSX in your app you can add the following options to your `tsconfig.json` or `jsconfig.json`. Modern build systems like [Vite](https://vite.dev) will pick these up automatically.
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"compilerOptions": {
|
|
18
|
+
// ... other options ...
|
|
19
|
+
"jsx": "react-jsx",
|
|
20
|
+
"jsxImportSource": "@manyducks.co/dolla"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
End.
|
|
28
|
+
|
|
29
|
+
- [🗂️ Docs](./index.md)
|
|
30
|
+
- [🏠 README](../README.md)
|
|
31
|
+
- [🦆 That's a lot of ducks.](https://www.manyducks.co)
|