@manyducks.co/dolla 2.0.0-alpha.6 → 2.0.0-alpha.61
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 +86 -591
- package/dist/core/context.d.ts +142 -0
- package/dist/core/env.d.ts +3 -0
- package/dist/core/index.d.ts +21 -0
- package/dist/core/logger.d.ts +42 -0
- package/dist/core/logger.test.d.ts +0 -0
- package/dist/core/markup.d.ts +104 -0
- package/dist/core/markup.test.d.ts +0 -0
- package/dist/core/mount.d.ts +15 -0
- package/dist/core/mount.test.d.ts +0 -0
- package/dist/core/nodes/_markup.d.ts +36 -0
- package/dist/core/nodes/dom.d.ts +13 -0
- package/dist/core/nodes/dynamic.d.ts +22 -0
- package/dist/core/nodes/element.d.ts +25 -0
- package/dist/core/nodes/portal.d.ts +18 -0
- package/dist/core/nodes/repeat.d.ts +27 -0
- package/dist/core/nodes/view.d.ts +25 -0
- package/dist/core/ref.d.ts +18 -0
- package/dist/core/ref.test.d.ts +1 -0
- package/dist/core/signals.d.ts +58 -0
- package/dist/core/signals.test.d.ts +1 -0
- package/dist/{views → core/views}/default-crash-view.d.ts +11 -4
- package/dist/core/views/fragment.d.ts +7 -0
- package/dist/fragment-BahD_BJA.js +7 -0
- package/dist/fragment-BahD_BJA.js.map +1 -0
- package/dist/hooks/index.d.ts +64 -0
- package/dist/hooks/index.test.d.ts +1 -0
- package/dist/hooks.js +69 -0
- package/dist/hooks.js.map +1 -0
- package/dist/{modules/http.d.ts → http/index.d.ts} +3 -5
- package/dist/http.js +163 -0
- package/dist/http.js.map +1 -0
- package/dist/i18n/index.d.ts +134 -0
- package/dist/i18n.js +318 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index.js +98 -1388
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.d.ts +3 -2
- package/dist/jsx-dev-runtime.js +5 -12
- package/dist/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx-runtime.d.ts +4 -3
- package/dist/jsx-runtime.js +9 -15
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/logger-Bl496yfY.js +91 -0
- package/dist/logger-Bl496yfY.js.map +1 -0
- package/dist/markup-CX27GJ1M.js +1030 -0
- package/dist/markup-CX27GJ1M.js.map +1 -0
- package/dist/ref-BD79iqlg.js +15 -0
- package/dist/ref-BD79iqlg.js.map +1 -0
- package/dist/router/index.d.ts +2 -0
- package/dist/router/router.d.ts +160 -0
- package/dist/{routing.d.ts → router/router.utils.d.ts} +17 -3
- package/dist/router/router.utils.test.d.ts +1 -0
- package/dist/router-CjCkk4dA.js +543 -0
- package/dist/router-CjCkk4dA.js.map +1 -0
- package/dist/router.js +8 -0
- package/dist/router.js.map +1 -0
- package/dist/signals-gCwiIe5X.js +450 -0
- package/dist/signals-gCwiIe5X.js.map +1 -0
- package/dist/typeChecking-CbltMOUt.js +71 -0
- package/dist/typeChecking-CbltMOUt.js.map +1 -0
- package/dist/typeChecking.d.ts +2 -98
- package/dist/typeChecking.test.d.ts +1 -0
- package/dist/types.d.ts +98 -25
- package/dist/utils.d.ts +20 -3
- package/docs/hooks.md +211 -0
- package/docs/http.md +29 -0
- package/docs/i18n.md +43 -0
- package/docs/index.md +10 -0
- package/docs/markup.md +16 -0
- package/docs/mixins.md +32 -0
- package/docs/ref.md +93 -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/effection-idea.md +34 -0
- package/notes/elimination.md +33 -0
- package/notes/mixins.md +22 -0
- package/notes/molecule.md +35 -0
- package/notes/observable.md +180 -0
- package/notes/readme-scratch.md +45 -7
- package/notes/route-middleware.md +42 -0
- package/notes/scratch.md +353 -6
- package/notes/splitting.md +5 -0
- package/notes/stores.md +79 -0
- package/package.json +31 -12
- package/vite.config.js +6 -11
- package/build.js +0 -34
- package/dist/index.d.ts +0 -21
- package/dist/markup.d.ts +0 -100
- package/dist/modules/dolla.d.ts +0 -111
- package/dist/modules/language.d.ts +0 -41
- package/dist/modules/render.d.ts +0 -17
- package/dist/modules/router.d.ts +0 -152
- 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-CW8Ezjg-.js +0 -1244
- package/dist/passthrough-CW8Ezjg-.js.map +0 -1
- package/dist/state.d.ts +0 -101
- package/dist/view.d.ts +0 -50
- package/dist/views/passthrough.d.ts +0 -5
- package/tests/state.test.js +0 -135
- /package/dist/{routing.test.d.ts → core/context.test.d.ts} +0 -0
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,17 +1,31 @@
|
|
|
1
1
|
import type * as CSS from "csstype";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import type { Markup, MarkupNode } from "./core/markup.js";
|
|
3
|
+
import type { Signal } from "./core/signals.js";
|
|
4
|
+
import type { Context } from "./core/context.js";
|
|
5
|
+
export type Env = "production" | "development";
|
|
4
6
|
/**
|
|
5
7
|
* Represents everything that can be handled as a DOM node.
|
|
6
8
|
* These are all the items considered valid to pass as children to any element.
|
|
7
9
|
*/
|
|
8
|
-
export type Renderable = string | number | Markup | false | null | undefined |
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
export type Renderable = string | number | Node | Markup | MarkupNode | false | null | undefined | Signal<any> | (string | number | Node | Markup | MarkupNode | false | null | undefined | Signal<any>)[];
|
|
11
|
+
export interface BaseProps {
|
|
12
|
+
children?: Renderable;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
export type View<Props> = (this: Context, props: Props, context: Context) => Renderable;
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
export type Store<Options, Value> = (this: Context, options: Options, context: Context) => Value;
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
export type Mixin<E extends Element = Element> = (element: E, context: Context) => void;
|
|
26
|
+
type MaybeSignal<T> = T | Signal<T> | Signal<T | undefined>;
|
|
27
|
+
type OptionalProperty<T> = MaybeSignal<T>;
|
|
28
|
+
type RequiredProperty<T> = T | Signal<T>;
|
|
15
29
|
type AutocapitalizeValues = "off" | "on" | "none" | "sentences" | "words" | "characters";
|
|
16
30
|
type ContentEditableValues = true | false | "true" | "false" | "plaintext-only" | "inherit";
|
|
17
31
|
type ClassListValues = string | ClassMap | Array<string | ClassMap | (string | ClassMap)[]>;
|
|
@@ -23,21 +37,31 @@ type InputModeValues = "decimal" | "email" | "none" | "numeric" | "search" | "te
|
|
|
23
37
|
* Properties common to all Elements.
|
|
24
38
|
*/
|
|
25
39
|
export interface ElementProps {
|
|
40
|
+
/**
|
|
41
|
+
* Sets the value as an HTML attribute.
|
|
42
|
+
*/
|
|
43
|
+
[key: `attr:${string}`]: OptionalProperty<any>;
|
|
44
|
+
/**
|
|
45
|
+
* Sets the value directly on the HTMLElement as a property.
|
|
46
|
+
*/
|
|
47
|
+
[key: `prop:${string}`]: OptionalProperty<any>;
|
|
48
|
+
/**
|
|
49
|
+
* Attaches an event listener to the element (with `addEventListener`).
|
|
50
|
+
*/
|
|
51
|
+
[key: `on:${string}`]: OptionalProperty<EventHandler<Event>>;
|
|
26
52
|
/**
|
|
27
53
|
* HTML attributes to assign to the element.
|
|
28
54
|
*/
|
|
29
|
-
attributes?: OptionalProperty<Record<string, any>>;
|
|
30
55
|
/**
|
|
31
56
|
* Object of event listeners.
|
|
32
57
|
*/
|
|
33
|
-
eventListeners?: OptionalProperty<Record<string, EventHandler<Event>>>;
|
|
34
58
|
/**
|
|
35
59
|
* CSS classes to be applied to this element. In addition to the standard space-separated list of class names,
|
|
36
60
|
* this property also supports a class map object with class names as keys and booleans as values.
|
|
37
61
|
* Class names in a class map will be applied to the element while their values are true. Also supports an
|
|
38
62
|
* array of strings and class maps.
|
|
39
63
|
*
|
|
40
|
-
*
|
|
64
|
+
* @alias className
|
|
41
65
|
*
|
|
42
66
|
* @example
|
|
43
67
|
* <div class="one-class" />
|
|
@@ -57,6 +81,8 @@ export interface ElementProps {
|
|
|
57
81
|
* Class names in a class map will be applied to the element while their values are true. Also supports an
|
|
58
82
|
* array of strings and class maps.
|
|
59
83
|
*
|
|
84
|
+
* @alias class
|
|
85
|
+
*
|
|
60
86
|
* @example
|
|
61
87
|
* <div className="one-class" />
|
|
62
88
|
*
|
|
@@ -71,22 +97,39 @@ export interface ElementProps {
|
|
|
71
97
|
className?: OptionalProperty<ClassListValues>;
|
|
72
98
|
/**
|
|
73
99
|
* A unique string to identify this element.
|
|
100
|
+
*
|
|
101
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/id
|
|
74
102
|
*/
|
|
75
103
|
id?: OptionalProperty<string>;
|
|
104
|
+
/**
|
|
105
|
+
* Renders a string of HTML as the children of this element.
|
|
106
|
+
* Equivalent to setting `innerHTML` on a DOM element.
|
|
107
|
+
*
|
|
108
|
+
* `NOTE` This property does no sanitization. If it's in the string, it's in the DOM. Be mindful when handling user-generated content.
|
|
109
|
+
*/
|
|
110
|
+
innerHTML?: OptionalProperty<string>;
|
|
111
|
+
/**
|
|
112
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/popover
|
|
113
|
+
*/
|
|
114
|
+
popover?: OptionalProperty<"auto" | "hint" | "manual" | true | false>;
|
|
115
|
+
/**
|
|
116
|
+
* Specifies the element's [WAI-ARIA role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles).
|
|
117
|
+
*
|
|
118
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/role
|
|
119
|
+
*/
|
|
120
|
+
role?: OptionalProperty<string>;
|
|
76
121
|
/**
|
|
77
122
|
* Scroll position from the left (on the X axis), if this element is scrollable.
|
|
123
|
+
*
|
|
124
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollLeft
|
|
78
125
|
*/
|
|
79
126
|
scrollLeft?: OptionalProperty<number>;
|
|
80
127
|
/**
|
|
81
128
|
* Scroll position from the top (on the Y axis) if this element is scrollable.
|
|
82
|
-
*/
|
|
83
|
-
scrollTop?: OptionalProperty<number>;
|
|
84
|
-
/**
|
|
85
|
-
* Enables or disables checking for spelling errors in an element's content.
|
|
86
129
|
*
|
|
87
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/
|
|
130
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollTop
|
|
88
131
|
*/
|
|
89
|
-
|
|
132
|
+
scrollTop?: OptionalProperty<number>;
|
|
90
133
|
/**
|
|
91
134
|
* Specifies whether an element's content should be translated when the page is localized.
|
|
92
135
|
*
|
|
@@ -105,12 +148,18 @@ export interface ElementProps {
|
|
|
105
148
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/slot
|
|
106
149
|
*/
|
|
107
150
|
slot?: OptionalProperty<string>;
|
|
151
|
+
/**
|
|
152
|
+
* Enables or disables checking for spelling errors in an element's content.
|
|
153
|
+
*
|
|
154
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/spellcheck
|
|
155
|
+
*/
|
|
156
|
+
spellCheck?: OptionalProperty<boolean>;
|
|
108
157
|
/**
|
|
109
158
|
* Inline styles applied to the element. Can be passed as a string or as an object.
|
|
110
159
|
*
|
|
111
160
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/style
|
|
112
161
|
*/
|
|
113
|
-
style?: string | CSSProperties |
|
|
162
|
+
style?: string | CSSProperties | Signal<string> | Signal<CSSProperties> | Signal<string | CSSProperties> | Signal<string | undefined> | Signal<CSSProperties | undefined> | Signal<string | CSSProperties | undefined>;
|
|
114
163
|
/**
|
|
115
164
|
* Fired when a CSS animation unexpectedly aborts.
|
|
116
165
|
*
|
|
@@ -178,6 +227,12 @@ export interface ElementProps {
|
|
|
178
227
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/compositionupdate_event
|
|
179
228
|
*/
|
|
180
229
|
onCompositionUpdate?: OptionalProperty<EventHandler<CompositionEvent>>;
|
|
230
|
+
/**
|
|
231
|
+
* Fired when the user attempts to open a context menu. Typically triggered by clicking the right mouse button.
|
|
232
|
+
*
|
|
233
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/contextmenu_event
|
|
234
|
+
*/
|
|
235
|
+
onContextMenu?: OptionalProperty<EventHandler<PointerEvent>>;
|
|
181
236
|
/**
|
|
182
237
|
* Fired when a pointing device button is rapidly clicked twice while the pointer is inside the element.
|
|
183
238
|
*
|
|
@@ -452,6 +507,12 @@ export interface ElementProps {
|
|
|
452
507
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/compositionupdate_event
|
|
453
508
|
*/
|
|
454
509
|
oncompositionupdate?: OptionalProperty<EventHandler<CompositionEvent>>;
|
|
510
|
+
/**
|
|
511
|
+
* Fired when the user attempts to open a context menu. Typically triggered by clicking the right mouse button.
|
|
512
|
+
*
|
|
513
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/contextmenu_event
|
|
514
|
+
*/
|
|
515
|
+
oncontextmenu?: OptionalProperty<EventHandler<PointerEvent>>;
|
|
455
516
|
/**
|
|
456
517
|
* Fired when a pointing device button is rapidly clicked twice while the pointer is inside the element.
|
|
457
518
|
*
|
|
@@ -683,6 +744,12 @@ export interface HTMLElementProps extends ElementProps {
|
|
|
683
744
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/contentEditable
|
|
684
745
|
*/
|
|
685
746
|
contentEditable?: OptionalProperty<ContentEditableValues>;
|
|
747
|
+
/**
|
|
748
|
+
* Stores values on the element as attributes prefixed with `data-`.
|
|
749
|
+
*
|
|
750
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset
|
|
751
|
+
*/
|
|
752
|
+
dataset?: OptionalProperty<Record<string, string>>;
|
|
686
753
|
/**
|
|
687
754
|
* Specifies text directionality of the content of this element. Some languages, such as Arabic, are written from right to left (specified here as "rtl").
|
|
688
755
|
*
|
|
@@ -729,7 +796,6 @@ export interface HTMLElementProps extends ElementProps {
|
|
|
729
796
|
/**
|
|
730
797
|
* TODO: Add support. Currently experimental.
|
|
731
798
|
*/
|
|
732
|
-
role?: OptionalProperty<string>;
|
|
733
799
|
/**
|
|
734
800
|
* This element's position in the tab order, or the order this element will be focused as the user cycles through elements with the tab key.
|
|
735
801
|
*
|
|
@@ -938,6 +1004,10 @@ export interface HTMLElementProps extends ElementProps {
|
|
|
938
1004
|
onpaste?: OptionalProperty<EventHandler<ClipboardEvent>>;
|
|
939
1005
|
}
|
|
940
1006
|
export interface SVGElementProps extends ElementProps {
|
|
1007
|
+
/**
|
|
1008
|
+
* A mixin function or an array of mixin functions to be applied to this element.
|
|
1009
|
+
*/
|
|
1010
|
+
mixin?: Mixin<SVGElement> | Mixin<SVGElement>[];
|
|
941
1011
|
}
|
|
942
1012
|
/**
|
|
943
1013
|
* Mapping of event props to event names.
|
|
@@ -1210,7 +1280,7 @@ export type CSSProperties = {
|
|
|
1210
1280
|
[K in keyof Styles]: OptionalProperty<Styles[K]>;
|
|
1211
1281
|
};
|
|
1212
1282
|
export interface ClassMap {
|
|
1213
|
-
[className: string]:
|
|
1283
|
+
[className: string]: MaybeSignal<any>;
|
|
1214
1284
|
}
|
|
1215
1285
|
export type EventHandler<E> = (event: E) => void;
|
|
1216
1286
|
export interface PropertiesOf<E extends HTMLElement> extends HTMLElementProps {
|
|
@@ -1221,7 +1291,11 @@ export interface PropertiesOf<E extends HTMLElement> extends HTMLElementProps {
|
|
|
1221
1291
|
/**
|
|
1222
1292
|
* Receives a reference to the DOM node when rendered.
|
|
1223
1293
|
*/
|
|
1224
|
-
ref?:
|
|
1294
|
+
ref?: ((value: E | undefined) => void) | ((value: HTMLElement | undefined) => void) | ((value: Element | undefined) => void) | ((value: Node | undefined) => void);
|
|
1295
|
+
/**
|
|
1296
|
+
* A mixin function or an array of mixin functions to be applied to this element.
|
|
1297
|
+
*/
|
|
1298
|
+
mixin?: Mixin<E> | Mixin<E>[];
|
|
1225
1299
|
}
|
|
1226
1300
|
/**
|
|
1227
1301
|
* The following elements are defined based on the WHATWG HTML spec:
|
|
@@ -2098,7 +2172,7 @@ interface HTMLMediaElementProps<T extends HTMLMediaElement> extends HTMLElementP
|
|
|
2098
2172
|
*
|
|
2099
2173
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/srcObject
|
|
2100
2174
|
*/
|
|
2101
|
-
srcObject?: MediaStream | MediaSource | Blob | File |
|
|
2175
|
+
srcObject?: MediaStream | MediaSource | Blob | File | Signal<MediaStream> | Signal<MediaStream | undefined> | Signal<MediaSource> | Signal<MediaSource | undefined> | Signal<Blob> | Signal<Blob | undefined> | Signal<File> | Signal<File | undefined>;
|
|
2102
2176
|
/**
|
|
2103
2177
|
* The current audio volume of the media element. Must be a number between 0 and 1.
|
|
2104
2178
|
*
|
|
@@ -2597,7 +2671,7 @@ interface HTMLImageElementProps extends PropertiesOf<HTMLImageElement> {
|
|
|
2597
2671
|
*
|
|
2598
2672
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/sizes
|
|
2599
2673
|
*/
|
|
2600
|
-
sizes?:
|
|
2674
|
+
sizes?: MaybeSignal<string>;
|
|
2601
2675
|
/**
|
|
2602
2676
|
* The image URL.
|
|
2603
2677
|
*
|
|
@@ -3143,7 +3217,6 @@ interface HTMLInputElementProps extends PropertiesOf<HTMLInputElement> {
|
|
|
3143
3217
|
step?: OptionalProperty<number>;
|
|
3144
3218
|
type?: OptionalProperty<InputType>;
|
|
3145
3219
|
value?: OptionalProperty<string>;
|
|
3146
|
-
$$value?: SettableState<any>;
|
|
3147
3220
|
width?: OptionalProperty<string | number> | OptionalProperty<string> | OptionalProperty<number>;
|
|
3148
3221
|
title?: OptionalProperty<string>;
|
|
3149
3222
|
/**
|
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,12 @@ 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
|
-
export declare function
|
|
17
|
-
export declare function
|
|
29
|
+
export declare function toArray<T>(value: T | T[]): T[];
|
|
30
|
+
export declare function toCamelCase(s: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Takes any string and returns an OKLCH color.
|
|
33
|
+
*/
|
|
34
|
+
export declare function okhash(value: string): string;
|
|
18
35
|
export type MatcherFunction = (value: string) => boolean;
|
|
19
36
|
/**
|
|
20
37
|
* Parses a filter string into a matcher function.
|
package/docs/hooks.md
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# Hooks
|
|
2
|
+
|
|
3
|
+
Dolla implements a React-style hooks API for use in Views, Stores and Mixins. Internally these hooks are still using signals, and view functions still only run once, but this API may be more fun and enjoyable for those familiar with React.
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
import { useState, useEffect, useLogger } from "@manyducks.co/dolla/hooks";
|
|
7
|
+
|
|
8
|
+
export function CounterView() {
|
|
9
|
+
const [count, setCount] = useState(0);
|
|
10
|
+
|
|
11
|
+
const logger = useLogger();
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
// Effect is triggered each time count changes; calling its getter tracks it.
|
|
14
|
+
logger.info(`Count is now ${count()}`);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<div>
|
|
19
|
+
Count: {count}
|
|
20
|
+
<button onClick={() => setCount((n) => n + 1)}>+1</button>
|
|
21
|
+
<button onClick={() => setCount((n) => n - 1)}>-1</button>
|
|
22
|
+
<button onClick={() => setCount(0)}>Reset</button>
|
|
23
|
+
</div>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
import { useReducer } from "@manyducks.co/dolla/hooks";
|
|
30
|
+
|
|
31
|
+
export function CounterView() {
|
|
32
|
+
const countReducer = (state, action) => {
|
|
33
|
+
switch (action) {
|
|
34
|
+
case "increment":
|
|
35
|
+
return state + 1;
|
|
36
|
+
case "decrement":
|
|
37
|
+
return state - 1;
|
|
38
|
+
case "reset":
|
|
39
|
+
return 0;
|
|
40
|
+
default:
|
|
41
|
+
throw new Error("Invalid action");
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const [count, dispatch] = useReducer(countReducer, 0);
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<div>
|
|
48
|
+
Count: {count}
|
|
49
|
+
<button onClick={() => dispatch("increment")}>+1</button>
|
|
50
|
+
<button onClick={() => dispatch("decrement")}>-1</button>
|
|
51
|
+
<button onClick={() => dispatch("reset")}>Reset</button>
|
|
52
|
+
</div>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## All Hooks
|
|
58
|
+
|
|
59
|
+
### `useState`
|
|
60
|
+
|
|
61
|
+
Creates a new state and returns a Signal and a Setter. Signals are functions that return the current value when called. If they are called within a tracking scope (such as a useMemo or useEffect function) they will _signal_ to that scope that they need to re-run when a new value is set.
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
const [message, setMessage] = useState("Hello World");
|
|
65
|
+
message(); // "Hello World"
|
|
66
|
+
setValue("different value");
|
|
67
|
+
setValue((current) => current.toUpperCase());
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### `useMemo`
|
|
71
|
+
|
|
72
|
+
Basic usage.
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
const [count, setCount] = useState(5);
|
|
76
|
+
|
|
77
|
+
// Signals called within the body of the `useMemo` callback will be tracked.
|
|
78
|
+
// This means `doubled` will re-run and update its value when and only when its tracked dependencies do.
|
|
79
|
+
const doubled = useMemo(() => count() * 2);
|
|
80
|
+
|
|
81
|
+
// `useMemo` can also track other memoized values. You can nest derived values as deeply as you want.
|
|
82
|
+
const quadrupled = useMemo(() => doubled() * 2);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
#### Explicit Dependencies
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
const [first, setFirst] = useState(10);
|
|
89
|
+
const [second, setSecond] = useState(20);
|
|
90
|
+
|
|
91
|
+
// You can alternatively pass an array of dependencies. When you do this your callback will be re-run whenever
|
|
92
|
+
// any of the provided dependencies change, regardless of what dependencies you actually call inside the callback;
|
|
93
|
+
const added = useMemo(() => first() + second(), [second]);
|
|
94
|
+
|
|
95
|
+
added(); // 30
|
|
96
|
+
setFirst(11);
|
|
97
|
+
added(); // 30; did not update because only second() is tracked as a dependency.
|
|
98
|
+
setSecond(21);
|
|
99
|
+
added(); // 32; now it updates because second() received a new value.
|
|
100
|
+
|
|
101
|
+
// Note: receives the value it returned last as the first argument.
|
|
102
|
+
// Node: can pass a deps array to re-run when deps change regardless of what's called inside the memo function.
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### `useEffect`
|
|
106
|
+
|
|
107
|
+
> TODO
|
|
108
|
+
>
|
|
109
|
+
> 1. Autotracked deps
|
|
110
|
+
> 2. Explicitly tracked deps
|
|
111
|
+
|
|
112
|
+
### `useRef`
|
|
113
|
+
|
|
114
|
+
Create a new ref. Refs are useful for getting references to DOM nodes rendered by Dolla. View functions are only called once, so refs in Dolla are not as broadly applicable for storing other types of data as they are in React.
|
|
115
|
+
|
|
116
|
+
```js
|
|
117
|
+
function ExampleView() {
|
|
118
|
+
const element = useRef();
|
|
119
|
+
|
|
120
|
+
useMount(() => {
|
|
121
|
+
console.log("The element!", element.current);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
return <div ref={element}>I am a div.</div>;
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### `useContext`
|
|
129
|
+
|
|
130
|
+
Not to be confused with React `useContext`. The context referred to here is the View, Store or Mixin `Context` object.
|
|
131
|
+
|
|
132
|
+
```js
|
|
133
|
+
// `useContext` returns the currently active Context object for the View, Store or Mixin it's called in.
|
|
134
|
+
function ExampleView() {
|
|
135
|
+
const ctx = useContext();
|
|
136
|
+
|
|
137
|
+
ctx.onMount(() => {
|
|
138
|
+
/// ...
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### `useStore`
|
|
144
|
+
|
|
145
|
+
Access an instance of a provided Store. Equivalent to `context.getStore(Store)`.
|
|
146
|
+
|
|
147
|
+
```jsx
|
|
148
|
+
function CounterStore() {
|
|
149
|
+
const [value, setValue] = useState(0);
|
|
150
|
+
|
|
151
|
+
const increment = () => setValue((n) => n + 1);
|
|
152
|
+
const decrement = () => setValue((n) => n - 1);
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
value,
|
|
156
|
+
increment,
|
|
157
|
+
decrement,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Register the store at some point in the view tree.
|
|
162
|
+
function ParentView() {
|
|
163
|
+
const context = useContext();
|
|
164
|
+
context.addStore(CounterStore);
|
|
165
|
+
|
|
166
|
+
return <ChildView />;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Then...
|
|
170
|
+
function ChildView() {
|
|
171
|
+
const counter = useStore(CounterStore);
|
|
172
|
+
|
|
173
|
+
counter.value(); // 0
|
|
174
|
+
counter.increment();
|
|
175
|
+
counter.value(); // 1
|
|
176
|
+
|
|
177
|
+
return <span>{counter.value}</span>;
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### `useMount`
|
|
182
|
+
|
|
183
|
+
Register a callback to run when the context is mounted. If the callback returns a function, that function is called when the context is unmounted.
|
|
184
|
+
|
|
185
|
+
```js
|
|
186
|
+
function ExampleView() {
|
|
187
|
+
useMount(() => {
|
|
188
|
+
console.log("View is now mounted.")
|
|
189
|
+
|
|
190
|
+
return () => {
|
|
191
|
+
console.log("View is now unmounted.);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// ...
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### `useUnmount`
|
|
200
|
+
|
|
201
|
+
Register a callback to run when the context is unmounted.
|
|
202
|
+
|
|
203
|
+
```js
|
|
204
|
+
function ExampleView() {
|
|
205
|
+
useUnmount(() => {
|
|
206
|
+
console.log("View is now unmounted.");
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
// ...
|
|
210
|
+
}
|
|
211
|
+
```
|
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)
|