@manyducks.co/dolla 2.0.0-alpha.9 → 3.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.
Files changed (90) hide show
  1. package/README.md +132 -573
  2. package/dist/core/context.d.ts +23 -0
  3. package/dist/core/debug.d.ts +19 -0
  4. package/dist/core/index.d.ts +24 -0
  5. package/dist/core/markup/helpers.d.ts +34 -0
  6. package/dist/core/markup/html.d.ts +3 -0
  7. package/dist/core/markup/html.test.d.ts +1 -0
  8. package/dist/core/markup/nodes/dom.d.ts +14 -0
  9. package/dist/core/markup/nodes/dynamic.d.ts +16 -0
  10. package/dist/core/markup/nodes/element.d.ts +14 -0
  11. package/dist/core/markup/nodes/portal.d.ts +15 -0
  12. package/dist/core/markup/nodes/repeat.d.ts +21 -0
  13. package/dist/core/markup/nodes/view.d.ts +17 -0
  14. package/dist/core/markup/scheduler.d.ts +1 -0
  15. package/dist/core/markup/types.d.ts +62 -0
  16. package/dist/core/markup/utils.d.ts +22 -0
  17. package/dist/core/markup/utils.test.d.ts +1 -0
  18. package/dist/core/ref.d.ts +13 -0
  19. package/dist/core/root.d.ts +36 -0
  20. package/dist/core/signals.d.ts +70 -0
  21. package/dist/core/signals.test.d.ts +1 -0
  22. package/dist/core/symbols.d.ts +2 -0
  23. package/dist/core-BLkJ-xuh.js +242 -0
  24. package/dist/core-BLkJ-xuh.js.map +1 -0
  25. package/dist/http/index.d.ts +43 -0
  26. package/dist/http.js +90 -0
  27. package/dist/http.js.map +1 -0
  28. package/dist/index.js +4 -1428
  29. package/dist/jsx-dev-runtime.d.ts +4 -2
  30. package/dist/jsx-dev-runtime.js +12 -16
  31. package/dist/jsx-dev-runtime.js.map +1 -1
  32. package/dist/jsx-runtime.d.ts +5 -3
  33. package/dist/jsx-runtime.js +17 -18
  34. package/dist/jsx-runtime.js.map +1 -1
  35. package/dist/router/index.d.ts +4 -0
  36. package/dist/router/matcher.test.d.ts +1 -0
  37. package/dist/router/router.d.ts +23 -0
  38. package/dist/router/router.test.d.ts +1 -0
  39. package/dist/router/store.d.ts +12 -0
  40. package/dist/router/types.d.ts +152 -0
  41. package/dist/router/utils.d.ts +99 -0
  42. package/dist/router/utils.test.d.ts +1 -0
  43. package/dist/router.js +429 -0
  44. package/dist/router.js.map +1 -0
  45. package/dist/signals-CMJPGr_M.js +354 -0
  46. package/dist/signals-CMJPGr_M.js.map +1 -0
  47. package/dist/translate/index.d.ts +82 -0
  48. package/dist/translate.js +125 -0
  49. package/dist/translate.js.map +1 -0
  50. package/dist/types.d.ts +83 -29
  51. package/dist/utils.d.ts +46 -12
  52. package/dist/utils.test.d.ts +1 -0
  53. package/dist/view-cBN-hn_T.js +360 -0
  54. package/dist/view-cBN-hn_T.js.map +1 -0
  55. package/dist/virtual/index.d.ts +1 -0
  56. package/dist/virtual/list.d.ts +53 -0
  57. package/index.d.ts +2 -2
  58. package/package.json +34 -17
  59. package/build.js +0 -34
  60. package/dist/index.d.ts +0 -21
  61. package/dist/index.js.map +0 -1
  62. package/dist/markup.d.ts +0 -108
  63. package/dist/modules/dolla.d.ts +0 -111
  64. package/dist/modules/http.d.ts +0 -57
  65. package/dist/modules/i18n.d.ts +0 -59
  66. package/dist/modules/render.d.ts +0 -17
  67. package/dist/modules/router.d.ts +0 -152
  68. package/dist/nodes/cond.d.ts +0 -26
  69. package/dist/nodes/html.d.ts +0 -31
  70. package/dist/nodes/observer.d.ts +0 -29
  71. package/dist/nodes/outlet.d.ts +0 -22
  72. package/dist/nodes/portal.d.ts +0 -19
  73. package/dist/nodes/repeat.d.ts +0 -34
  74. package/dist/nodes/text.d.ts +0 -19
  75. package/dist/passthrough-9kwwjgWk.js +0 -1279
  76. package/dist/passthrough-9kwwjgWk.js.map +0 -1
  77. package/dist/routing.d.ts +0 -79
  78. package/dist/state.d.ts +0 -101
  79. package/dist/typeChecking.d.ts +0 -191
  80. package/dist/view.d.ts +0 -65
  81. package/dist/views/default-crash-view.d.ts +0 -18
  82. package/dist/views/passthrough.d.ts +0 -5
  83. package/notes/context-vars.md +0 -21
  84. package/notes/readme-scratch.md +0 -222
  85. package/notes/route-middleware.md +0 -42
  86. package/notes/scratch.md +0 -233
  87. package/notes/views.md +0 -195
  88. package/tests/state.test.js +0 -135
  89. package/vite.config.js +0 -28
  90. /package/dist/{routing.test.d.ts → core/context.test.d.ts} +0 -0
@@ -1,59 +0,0 @@
1
- import { MaybeState, type State } from "../state.js";
2
- import type { Stringable } from "../types.js";
3
- import type { Dolla } from "./dolla.js";
4
- /**
5
- * An object where values are either a translated string or another nested Translation object.
6
- */
7
- type LocalizedStrings = Record<string, string | Record<string, string | Record<string, string | Record<string, string>>>>;
8
- export interface TranslationConfig {
9
- /**
10
- * Name of the locale this translation is for (BCP 47 locale names recommended).
11
- */
12
- locale: string;
13
- /**
14
- * Path to a JSON file with translated strings for this language.
15
- */
16
- path?: string;
17
- /**
18
- * A callback function that returns a Promise that resolves to the translation object for this language.
19
- */
20
- fetch?: () => Promise<LocalizedStrings>;
21
- }
22
- export type I18nSetupOptions = {
23
- /**
24
- * Default locale to load on startup
25
- */
26
- locale?: string | null;
27
- translations: TranslationConfig[];
28
- };
29
- /**
30
- * Dolla's I(nternationalizatio)n module. Manages language translations and locale-based formatting.
31
- */
32
- export declare class I18n {
33
- #private;
34
- $locale: State<string | undefined>;
35
- constructor(dolla: Dolla);
36
- get locales(): string[];
37
- setup(options: I18nSetupOptions): void;
38
- setLocale(name: string): Promise<void>;
39
- /**
40
- * Returns a State containing the value at `key`.
41
-
42
- * @param key - Key to the translated value.
43
- * @param values - A map of {{placeholder}} names and the values to replace them with.
44
- */
45
- t(key: string, values?: Record<string, Stringable | State<Stringable>>): State<string>;
46
- /**
47
- * Format a number in the current locale.
48
- */
49
- formatNumber(count: number, options?: Intl.NumberFormatOptions): string;
50
- /**
51
- * Format a number in the current locale and get the result as a State that will update if the locale changes.
52
- */
53
- formatNumber$(count: MaybeState<number>, options?: Intl.NumberFormatOptions): State<string>;
54
- formatDate(date: string | Date, options?: Intl.DateTimeFormatOptions): string;
55
- formatDate$(date: MaybeState<string | Date>, options?: Intl.DateTimeFormatOptions): State<string>;
56
- formatList(list: string[], options?: Intl.ListFormatOptions): string;
57
- formatList$(list: MaybeState<string[]>, options?: Intl.ListFormatOptions): State<string>;
58
- }
59
- export {};
@@ -1,17 +0,0 @@
1
- import type { Dolla } from "./dolla.js";
2
- export declare class Render {
3
- #private;
4
- constructor(dolla: Dolla);
5
- /**
6
- * Queues a callback to run in the next render batch.
7
- * Running your DOM mutations in update callbacks reduces layout thrashing.
8
- * Returns a Promise that resolves once the callback has run.
9
- */
10
- update(callback: () => void, key?: string): Promise<void>;
11
- /**
12
- * Queues a callback that reads DOM information to run after the next render batch,
13
- * ensuring all writes have been performed before reading.
14
- * Returns a Promise that resolves once the callback has run.
15
- */
16
- read(callback: () => void): Promise<void>;
17
- }
@@ -1,152 +0,0 @@
1
- import { type Stringable } from "../types.js";
2
- import { ViewNode, type ViewFunction } from "../view.js";
3
- import type { Dolla } from "./dolla.js";
4
- export interface RouteMatchContext {
5
- /**
6
- * Redirects the user to a different route instead of matching the current one.
7
- */
8
- redirect(path: string): void;
9
- }
10
- export interface Route {
11
- /**
12
- * The path or path fragment to match.
13
- */
14
- path: string;
15
- /**
16
- * Path to redirect to when this route is matched, or a callback function that returns such path.
17
- */
18
- redirect?: string | ((ctx: RouteRedirectContext) => string) | ((ctx: RouteRedirectContext) => Promise<string>);
19
- /**
20
- * View to display when this route is matched.
21
- */
22
- view?: ViewFunction<any>;
23
- /**
24
- * Subroutes.
25
- */
26
- routes?: Route[];
27
- /**
28
- * Called after the match is identified but before it is acted on. Use this to set state, load data, etc.
29
- */
30
- beforeMatch?: (ctx: RouteMatchContext) => void | Promise<void>;
31
- }
32
- export interface RouteConfig {
33
- pattern: string;
34
- meta: {
35
- redirect?: string | ((ctx: RouteRedirectContext) => string) | ((ctx: RouteRedirectContext) => Promise<string>);
36
- pattern?: string;
37
- layers?: RouteLayer[];
38
- beforeMatch?: (ctx: RouteMatchContext) => void | Promise<void>;
39
- };
40
- }
41
- export interface RouteLayer {
42
- id: number;
43
- view: ViewFunction<{}>;
44
- }
45
- /**
46
- * Object passed to redirect callbacks. Contains information useful for determining how to redirect.
47
- */
48
- export interface RouteRedirectContext {
49
- /**
50
- * The path as it appears in the URL bar.
51
- */
52
- path: string;
53
- /**
54
- * The pattern that this path was matched with.
55
- */
56
- pattern: string;
57
- /**
58
- * Named route params parsed from `path`.
59
- */
60
- params: Record<string, string | number | undefined>;
61
- /**
62
- * Query params parsed from `path`.
63
- */
64
- query: Record<string, string | number | boolean | undefined>;
65
- }
66
- interface ParsedParams {
67
- [key: string]: string | number | boolean | (string | number | boolean | null)[] | null;
68
- }
69
- interface ParsedQuery extends ParsedParams {
70
- }
71
- export interface NavigateOptions {
72
- /**
73
- * Replace the current item in the history stack instead of adding a new one.
74
- * The back button will send the user to the page they visited before this. Defaults to false.
75
- */
76
- replace?: boolean;
77
- /**
78
- * Preserve existing query params (if any) when navigating. Defaults to false.
79
- */
80
- preserveQuery?: boolean;
81
- }
82
- export declare enum RoutingStyle {
83
- /**
84
- * Constructs routes like "https://www.example.com/#/sub/route" which work without any server-side setup.
85
- * A good choice if your app has no backend.
86
- */
87
- hash = "hash",
88
- /**
89
- * Constructs routes like "https://www.example.com/sub/route" which look nicer (subjective?) than hash routes and are what most users will expect URLs to look like, but require additional backend setup.
90
- * Path routing requires you to configure your backend to redirect to the app's index.html when subpaths are requested.
91
- */
92
- path = "path"
93
- }
94
- export interface RouterSetupOptions {
95
- routes: Route[];
96
- /**
97
- * The routing style to use; "hash" will construct routes like "https://www.example.com/#/sub/route" which work without any server-side setup, while "path" will construct routes that use paths directly.
98
- */
99
- style?: RoutingStyle;
100
- }
101
- export interface RouterElements {
102
- readonly rootElement?: HTMLElement;
103
- readonly rootView?: ViewNode;
104
- }
105
- export declare class Router {
106
- #private;
107
- /**
108
- * The currently matched route pattern, if any.
109
- */
110
- $pattern: import("../state.js").State<string | null>;
111
- /**
112
- * The current URL path.
113
- */
114
- $path: import("../state.js").State<string>;
115
- /**
116
- * The current named path params.
117
- */
118
- $params: import("../state.js").State<ParsedParams>;
119
- /**
120
- * The current query params. Changes to this object will be reflected in the URL.
121
- */
122
- $query: import("../state.js").State<ParsedQuery>;
123
- constructor(dolla: Dolla, elements: RouterElements);
124
- setup(options: RouterSetupOptions): void;
125
- /**
126
- * Navigates to another route.
127
- *
128
- * @example
129
- * navigate("/login"); // navigate to `/login`
130
- * navigate(["/users", 215], { replace: true }); // replace current history entry with `/users/215`
131
- */
132
- go(path: Stringable | Stringable[], options?: NavigateOptions): void;
133
- /**
134
- * Navigate backward. Pass a number of steps to hit the back button that many times.
135
- */
136
- back(steps?: number): void;
137
- /**
138
- * Navigate forward. Pass a number of steps to hit the forward button that many times.
139
- */
140
- forward(steps?: number): void;
141
- }
142
- /**
143
- * Intercepts links within the root node.
144
- *
145
- * This is adapted from https://github.com/choojs/nanohref/blob/master/index.js
146
- *
147
- * @param root - Element under which to intercept link clicks
148
- * @param callback - Function to call when a click event is intercepted
149
- * @param _window - (optional) Override for global window object
150
- */
151
- export declare function catchLinks(root: HTMLElement, callback: (anchor: HTMLAnchorElement) => void, _window?: Window & typeof globalThis): () => void;
152
- export {};
@@ -1,26 +0,0 @@
1
- import { type MarkupNode, type ElementContext, type Markup } from "../markup.js";
2
- import { type State, type StopFunction } from "../state.js";
3
- import { type Renderable } from "../types.js";
4
- export interface ConditionalConfig {
5
- $predicate: State<any>;
6
- thenContent?: Renderable;
7
- elseContent?: Renderable;
8
- elementContext: ElementContext;
9
- }
10
- export declare class Conditional implements MarkupNode {
11
- node: Node;
12
- endNode: Node;
13
- $predicate: State<any>;
14
- stopCallback?: StopFunction;
15
- thenContent?: Markup[];
16
- elseContent?: Markup[];
17
- connectedContent: MarkupNode[];
18
- elementContext: ElementContext;
19
- initialUpdateHappened: boolean;
20
- previousValue?: any;
21
- constructor(config: ConditionalConfig);
22
- get isMounted(): boolean;
23
- mount(parent: Node, after?: Node | undefined): void;
24
- unmount(): void;
25
- update(value: any): void;
26
- }
@@ -1,31 +0,0 @@
1
- import { type ElementContext, type Markup, type MarkupNode, type Ref } from "../markup.js";
2
- import { type StopFunction } from "../state.js";
3
- type HTMLOptions = {
4
- elementContext: ElementContext;
5
- tag: string;
6
- props: Record<string, any>;
7
- children?: Markup[];
8
- };
9
- export declare class HTML implements MarkupNode {
10
- node: HTMLElement | SVGElement;
11
- props: Record<string, any>;
12
- children: MarkupNode[];
13
- stopCallbacks: StopFunction[];
14
- elementContext: ElementContext;
15
- uniqueId: string;
16
- ref?: Ref<any>;
17
- canClickAway: boolean;
18
- get isMounted(): boolean;
19
- constructor({ tag, props, children, elementContext }: HTMLOptions);
20
- mount(parent: Node, after?: Node): void;
21
- unmount(): void;
22
- getUpdateKey(type: string, value: string | number): string;
23
- applyProps(element: HTMLElement | SVGElement, props: Record<string, unknown>): void;
24
- applyStyles(element: HTMLElement | SVGElement, styles: unknown, stopCallbacks: StopFunction[]): () => void;
25
- applyClasses(element: HTMLElement | SVGElement, classes: unknown, stopCallbacks: StopFunction[]): () => void;
26
- }
27
- /**
28
- * Converts a camelCase string to kebab-case.
29
- */
30
- export declare function camelToKebab(value: string): string;
31
- export {};
@@ -1,29 +0,0 @@
1
- import { type ElementContext, type MarkupNode } from "../markup.js";
2
- import { type State } from "../state.js";
3
- import type { Renderable } from "../types.js";
4
- interface ObserverOptions {
5
- elementContext: ElementContext;
6
- states: State<any>[];
7
- renderFn: (...values: any) => Renderable;
8
- }
9
- /**
10
- * Displays dynamic children without a parent element.
11
- */
12
- export declare class Observer implements MarkupNode {
13
- node: Node;
14
- endNode: Node;
15
- connectedViews: MarkupNode[];
16
- renderFn: (...values: any) => Renderable;
17
- elementContext: ElementContext;
18
- observerControls: {
19
- start: () => void;
20
- stop: () => void;
21
- };
22
- get isMounted(): boolean;
23
- constructor({ states, renderFn, elementContext }: ObserverOptions);
24
- mount(parent: Node, after?: Node): void;
25
- unmount(): void;
26
- cleanup(): void;
27
- update(...children: Renderable[]): void;
28
- }
29
- export {};
@@ -1,22 +0,0 @@
1
- import { type MarkupNode, type ElementContext } from "../markup.js";
2
- import { type State, type StopFunction } from "../state.js";
3
- export interface OutletConfig {
4
- $children: State<MarkupNode[]>;
5
- elementContext: ElementContext;
6
- }
7
- /**
8
- * Manages an array of DOMHandles.
9
- */
10
- export declare class Outlet implements MarkupNode {
11
- node: Node;
12
- endNode: Node;
13
- $children: State<MarkupNode[]>;
14
- stopCallback?: StopFunction;
15
- connectedChildren: MarkupNode[];
16
- elementContext: ElementContext;
17
- constructor(config: OutletConfig);
18
- get isMounted(): boolean;
19
- mount(parent: Node, after?: Node | undefined): void;
20
- unmount(): void;
21
- update(newChildren: MarkupNode[]): void;
22
- }
@@ -1,19 +0,0 @@
1
- import { type MarkupNode, type ElementContext } from "../markup.js";
2
- import { type Renderable } from "../types.js";
3
- interface PortalConfig {
4
- content: Renderable;
5
- parent: Node;
6
- elementContext: ElementContext;
7
- }
8
- /**
9
- * Renders content into a specified parent node.
10
- */
11
- export declare class Portal implements MarkupNode {
12
- config: PortalConfig;
13
- handle?: MarkupNode;
14
- get isMounted(): boolean;
15
- constructor(config: PortalConfig);
16
- mount(_parent: Node, _after?: Node): void;
17
- unmount(): void;
18
- }
19
- export {};
@@ -1,34 +0,0 @@
1
- import { type MarkupNode, type ElementContext } from "../markup.js";
2
- import { type State, type Setter, type StopFunction } from "../state.js";
3
- import { type ViewContext, type ViewResult } from "../view.js";
4
- interface RepeatOptions<T> {
5
- elementContext: ElementContext;
6
- $items: State<T[]>;
7
- keyFn: (value: T, index: number) => string | number | symbol;
8
- renderFn: ($value: State<T>, $index: State<number>, ctx: ViewContext) => ViewResult;
9
- }
10
- type ConnectedItem<T> = {
11
- key: any;
12
- $value: State<T>;
13
- setValue: Setter<T>;
14
- $index: State<number>;
15
- setIndex: Setter<number>;
16
- handle: MarkupNode;
17
- };
18
- export declare class Repeat<T> implements MarkupNode {
19
- node: Node;
20
- endNode: Node;
21
- $items: State<T[]>;
22
- stopCallback?: StopFunction;
23
- connectedItems: ConnectedItem<T>[];
24
- elementContext: ElementContext;
25
- renderFn: ($value: State<T>, $index: State<number>, ctx: ViewContext) => ViewResult;
26
- keyFn: (value: T, index: number) => string | number | symbol;
27
- get isMounted(): boolean;
28
- constructor({ elementContext, $items, renderFn, keyFn }: RepeatOptions<T>);
29
- mount(parent: Node, after?: Node): void;
30
- unmount(): void;
31
- _cleanup(): void;
32
- _update(value: T[]): void;
33
- }
34
- export {};
@@ -1,19 +0,0 @@
1
- import { type MarkupNode } from "../markup.js";
2
- import { type MaybeState, type StopFunction } from "../state.js";
3
- interface Stringable {
4
- toString(): string;
5
- }
6
- interface TextOptions {
7
- value: MaybeState<Stringable>;
8
- }
9
- export declare class Text implements MarkupNode {
10
- node: globalThis.Text;
11
- value: MaybeState<Stringable>;
12
- stopCallback?: StopFunction;
13
- get isMounted(): boolean;
14
- constructor({ value }: TextOptions);
15
- mount(parent: Node, after?: Node | null): Promise<void>;
16
- unmount(): Promise<void>;
17
- update(value?: Stringable): void;
18
- }
19
- export {};