@manyducks.co/dolla 2.0.0 → 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 (112) hide show
  1. package/README.md +133 -284
  2. package/dist/core/context.d.ts +22 -146
  3. package/dist/core/debug.d.ts +19 -0
  4. package/dist/core/index.d.ts +15 -16
  5. package/dist/core/markup/helpers.d.ts +34 -0
  6. package/dist/core/markup/html.d.ts +3 -0
  7. package/dist/core/{nodes → markup/nodes}/dom.d.ts +5 -4
  8. package/dist/core/markup/nodes/dynamic.d.ts +16 -0
  9. package/dist/core/markup/nodes/element.d.ts +14 -0
  10. package/dist/core/markup/nodes/portal.d.ts +15 -0
  11. package/dist/core/markup/nodes/repeat.d.ts +21 -0
  12. package/dist/core/markup/nodes/view.d.ts +17 -0
  13. package/dist/core/markup/scheduler.d.ts +1 -0
  14. package/dist/core/markup/types.d.ts +62 -0
  15. package/dist/core/markup/utils.d.ts +22 -0
  16. package/dist/core/ref.d.ts +6 -12
  17. package/dist/core/root.d.ts +36 -0
  18. package/dist/core/signals.d.ts +46 -76
  19. package/dist/core/symbols.d.ts +2 -0
  20. package/dist/core-BLkJ-xuh.js +242 -0
  21. package/dist/core-BLkJ-xuh.js.map +1 -0
  22. package/dist/http/index.d.ts +21 -33
  23. package/dist/http.js +89 -149
  24. package/dist/http.js.map +1 -1
  25. package/dist/index.js +4 -174
  26. package/dist/jsx-dev-runtime.d.ts +4 -3
  27. package/dist/jsx-dev-runtime.js +12 -9
  28. package/dist/jsx-dev-runtime.js.map +1 -1
  29. package/dist/jsx-runtime.d.ts +5 -4
  30. package/dist/jsx-runtime.js +17 -12
  31. package/dist/jsx-runtime.js.map +1 -1
  32. package/dist/router/index.d.ts +4 -3
  33. package/dist/router/router.d.ts +19 -162
  34. package/dist/router/store.d.ts +12 -0
  35. package/dist/router/types.d.ts +152 -0
  36. package/dist/router/utils.d.ts +99 -0
  37. package/dist/router/utils.test.d.ts +1 -0
  38. package/dist/router.js +428 -5
  39. package/dist/router.js.map +1 -1
  40. package/dist/signals-CMJPGr_M.js +354 -0
  41. package/dist/signals-CMJPGr_M.js.map +1 -0
  42. package/dist/translate/index.d.ts +82 -0
  43. package/dist/translate.js +125 -0
  44. package/dist/translate.js.map +1 -0
  45. package/dist/types.d.ts +21 -39
  46. package/dist/utils.d.ts +41 -29
  47. package/dist/utils.test.d.ts +1 -0
  48. package/dist/view-cBN-hn_T.js +360 -0
  49. package/dist/view-cBN-hn_T.js.map +1 -0
  50. package/dist/virtual/index.d.ts +1 -0
  51. package/dist/virtual/list.d.ts +53 -0
  52. package/package.json +19 -16
  53. package/dist/core/app.d.ts +0 -24
  54. package/dist/core/env.d.ts +0 -3
  55. package/dist/core/hooks.d.ts +0 -70
  56. package/dist/core/logger.d.ts +0 -42
  57. package/dist/core/logger.test.d.ts +0 -0
  58. package/dist/core/markup.d.ts +0 -82
  59. package/dist/core/markup.test.d.ts +0 -0
  60. package/dist/core/nodes/_markup.d.ts +0 -36
  61. package/dist/core/nodes/dynamic.d.ts +0 -22
  62. package/dist/core/nodes/element.d.ts +0 -27
  63. package/dist/core/nodes/portal.d.ts +0 -18
  64. package/dist/core/nodes/repeat.d.ts +0 -27
  65. package/dist/core/nodes/view.d.ts +0 -25
  66. package/dist/core/views/default-crash-view.d.ts +0 -25
  67. package/dist/core/views/for.d.ts +0 -21
  68. package/dist/core/views/fragment.d.ts +0 -7
  69. package/dist/core/views/portal.d.ts +0 -16
  70. package/dist/core/views/show.d.ts +0 -25
  71. package/dist/fragment-BahD_BJA.js +0 -7
  72. package/dist/fragment-BahD_BJA.js.map +0 -1
  73. package/dist/i18n/index.d.ts +0 -134
  74. package/dist/i18n.js +0 -309
  75. package/dist/i18n.js.map +0 -1
  76. package/dist/index-DRJlxs-Q.js +0 -535
  77. package/dist/index-DRJlxs-Q.js.map +0 -1
  78. package/dist/index.js.map +0 -1
  79. package/dist/logger-Aqi9m1CF.js +0 -565
  80. package/dist/logger-Aqi9m1CF.js.map +0 -1
  81. package/dist/markup-8jNhoqDe.js +0 -1089
  82. package/dist/markup-8jNhoqDe.js.map +0 -1
  83. package/dist/router/hooks.d.ts +0 -2
  84. package/dist/router/router.utils.d.ts +0 -93
  85. package/dist/typeChecking-5kmX0ulW.js +0 -65
  86. package/dist/typeChecking-5kmX0ulW.js.map +0 -1
  87. package/dist/typeChecking.d.ts +0 -95
  88. package/docs/buildless.md +0 -132
  89. package/docs/components.md +0 -238
  90. package/docs/hooks.md +0 -356
  91. package/docs/http.md +0 -178
  92. package/docs/i18n.md +0 -220
  93. package/docs/index.md +0 -10
  94. package/docs/markup.md +0 -136
  95. package/docs/mixins.md +0 -176
  96. package/docs/ref.md +0 -77
  97. package/docs/router.md +0 -281
  98. package/docs/setup.md +0 -137
  99. package/docs/signals.md +0 -262
  100. package/docs/stores.md +0 -113
  101. package/docs/views.md +0 -356
  102. package/notes/atomic.md +0 -452
  103. package/notes/elimination.md +0 -33
  104. package/notes/observable.md +0 -180
  105. package/notes/scratch.md +0 -565
  106. package/notes/splitting.md +0 -5
  107. package/notes/views.md +0 -195
  108. package/vite.config.js +0 -22
  109. /package/dist/core/{hooks.test.d.ts → markup/html.test.d.ts} +0 -0
  110. /package/dist/core/{ref.test.d.ts → markup/utils.test.d.ts} +0 -0
  111. /package/dist/router/{router.utils.test.d.ts → matcher.test.d.ts} +0 -0
  112. /package/dist/{typeChecking.test.d.ts → router/router.test.d.ts} +0 -0
@@ -1,166 +1,23 @@
1
1
  import { Context } from "../core/context.js";
2
- import { type MarkupNode } from "../core/markup.js";
3
- import { type Signal } from "../core/signals.js";
4
- import type { View } from "../types.js";
5
- export type Stringable = {
6
- toString(): string;
7
- };
8
- export interface Match {
9
- /**
10
- * The path as it appears in the URL bar.
11
- */
12
- path: string;
13
- /**
14
- * The pattern that this path was matched with.
15
- */
16
- pattern: string;
17
- /**
18
- * Named route params parsed from `path`.
19
- */
20
- params: Record<string, string>;
21
- /**
22
- * Query params parsed from `path`.
23
- */
24
- query: Record<string, string>;
25
- /**
26
- * Freeform data you wish to store with this route.
27
- * Merged `data` from all matched layers are available from `router.$match()`.
28
- */
29
- data: Record<string, any>;
30
- }
31
- export interface RouteMatchContext extends Match {
32
- /**
33
- * Stores `value` at `key` in this context's state.
34
- */
35
- setState<T>(key: any, value: T): void;
36
- /**
37
- * For each tuple in `entries`, stores `value` at `key` in this context's state.
38
- */
39
- setState(entries: [key: any, value: any][]): void;
40
- /**
41
- * Redirects the user to a different route instead of matching the current one.
42
- */
43
- redirect(path: string): void;
44
- }
45
- export interface Route {
46
- /**
47
- * The path or path fragment to match.
48
- */
49
- path: string;
50
- /**
51
- * Path to redirect to when this route is matched, or a callback function that returns such path.
52
- */
53
- redirect?: string | ((ctx: RouteRedirectContext) => string) | ((ctx: RouteRedirectContext) => Promise<string>);
54
- /**
55
- * View to display when this route is matched.
56
- */
57
- view?: View<any>;
58
- /**
59
- * Subroutes.
60
- */
61
- routes?: Route[];
62
- /**
63
- * Called after the match is identified but before it is acted on. Use this to set state, load data, etc.
64
- */
65
- beforeMatch?: (ctx: RouteMatchContext) => void | Promise<void>;
66
- /**
67
- * Arbitrary data you'd like to store on this route.
68
- * This object will be available at `router.$match` while the route is active.
69
- *
70
- * In the case of nested routes, data from all layers will be merged into a single data object.
71
- */
72
- data?: Record<string, any>;
73
- }
74
- export interface RouteMeta {
75
- redirect?: string | ((ctx: RouteRedirectContext) => string) | ((ctx: RouteRedirectContext) => Promise<string>);
76
- pattern?: string;
77
- layers?: RouteLayer[];
78
- beforeMatch?: {
79
- fn: (ctx: RouteMatchContext) => void | Promise<void>;
80
- layerId: number;
81
- }[];
82
- data?: Record<string, any>;
83
- }
84
- export interface RouteConfig {
85
- pattern: string;
86
- meta: RouteMeta;
87
- }
88
- export interface RouteLayer {
89
- id: number;
90
- view: View<{}>;
91
- }
2
+ import { DollaPlugin } from "../core/index.js";
3
+ import { DynamicNode } from "../core/markup/nodes/dynamic.js";
4
+ import type { LazyLoader, LazyView, RouterOptions } from "./types.js";
92
5
  /**
93
- * Object passed to redirect callbacks. Contains information useful for determining how to redirect.
6
+ * Lazy loads a view when its route is first matched.
7
+ *
8
+ * @example
9
+ * {
10
+ * path: "/users",
11
+ * view: lazy(() => import("./views/users.js"))
12
+ * }
94
13
  */
95
- export interface RouteRedirectContext extends Match {
96
- }
97
- export interface NavigateOptions {
98
- /**
99
- * Replace the current item in the history stack instead of adding a new one.
100
- * The back button will send the user to the page they visited before this. Defaults to false.
101
- */
102
- replace?: boolean;
103
- /**
104
- * Preserve existing query params (if any) when navigating. Defaults to false.
105
- * If true, all existing query params are preserved and merged with new ones.
106
- * If an array of strings is passed only those keys will be preserved, then merged with any new ones.
107
- */
108
- preserveQuery?: boolean | string[];
109
- }
110
- export interface RouterOptions {
111
- routes: Route[];
112
- /**
113
- * When true, the router will construct routes like "https://www.example.com/#/sub/route" which work without any backend intervention.
114
- */
115
- hash?: boolean;
116
- }
117
- export declare const ROUTER: unique symbol;
118
- export declare const MOUNT: unique symbol;
119
- export declare const UNMOUNT: unique symbol;
120
- export declare const ROOT_VIEW: unique symbol;
121
- export declare class Router {
122
- #private;
123
- /**
124
- * The current match object.
125
- */
126
- readonly $match: Signal<Match | undefined>;
127
- /**
128
- * The currently matched route pattern, if any.
129
- */
130
- readonly $pattern: Signal<string | undefined>;
131
- /**
132
- * The current URL path.
133
- */
134
- readonly $path: Signal<string>;
135
- /**
136
- * The current named path params.
137
- */
138
- readonly $params: Signal<Record<string, string>>;
139
- /**
140
- * The current query params.
141
- */
142
- readonly $query: Signal<Record<string, string>>;
143
- constructor(options: RouterOptions);
144
- [MOUNT](parent: Element, context: Context): Promise<MarkupNode>;
145
- [UNMOUNT](): Promise<void>;
146
- /**
147
- * Navigate backward. Pass a number of steps to hit the back button that many times.
148
- */
149
- back(steps?: number): void;
150
- /**
151
- * Navigate forward. Pass a number of steps to hit the forward button that many times.
152
- */
153
- forward(steps?: number): void;
154
- /**
155
- * Navigates to another route.
156
- *
157
- * @example
158
- * router.go("/login"); // navigate to `/login`
159
- * router.go["/users", 215], { replace: true }); // replace current history entry with `/users/215`
160
- */
161
- go(path: Stringable | Stringable[], options?: NavigateOptions): void;
162
- /**
163
- * Updates query params, keeping existing ones and applying new ones. Removes the query param if value is set to `null`.
164
- */
165
- updateQuery(values: Record<string, Stringable | null>): void;
14
+ export declare function lazy(load: LazyLoader): LazyView;
15
+ export declare function createRouterPlugin(options: RouterOptions): DollaPlugin;
16
+ /**
17
+ * Displays the router's content.
18
+ */
19
+ export declare function Outlet(this: Context): DynamicNode;
20
+ export declare class RedirectError extends Error {
21
+ redirectPath: string;
22
+ constructor(redirectPath: string);
166
23
  }
@@ -0,0 +1,12 @@
1
+ import { type Context, type Getter, type Setter } from "../core";
2
+ import type { Router } from "./types";
3
+ import { type HistoryAdapter, type Match } from "./utils";
4
+ export interface RouterStoreProps {
5
+ currentMatch: Getter<Match>;
6
+ setCurrentMatch: Setter<Match>;
7
+ progress: Getter<number>;
8
+ history: HistoryAdapter;
9
+ updateRoute: () => void;
10
+ guards: Set<() => boolean | Promise<boolean>>;
11
+ }
12
+ export declare function RouterStore(this: Context, { currentMatch, setCurrentMatch, progress, history, updateRoute, guards }: RouterStoreProps): Router;
@@ -0,0 +1,152 @@
1
+ import type { Setter, Getter, MarkupNode, Renderable, View } from "../core";
2
+ import type { Context } from "../core/context";
3
+ import type { Match } from "./utils";
4
+ export type Stringable = {
5
+ toString(): string;
6
+ };
7
+ export type LazyLoader<Props = any> = () => Promise<{
8
+ default: View<Props>;
9
+ } | View<Props>>;
10
+ export interface LazyView<Props = any> {
11
+ _lazy: true;
12
+ load: LazyLoader<Props>;
13
+ }
14
+ export interface Route<Data = any> {
15
+ /**
16
+ * The path or path fragment to match.
17
+ */
18
+ path: string;
19
+ /**
20
+ * Path to redirect to when this route is matched, or a callback function that returns such path.
21
+ */
22
+ redirect?: string | ((match: Match) => string) | ((match: Match) => Promise<string>);
23
+ preload?: (match: Match) => Data | Promise<Data>;
24
+ /**
25
+ * View to display when this route is matched.
26
+ */
27
+ view?: View<{
28
+ data?: Data;
29
+ children: Renderable;
30
+ }> | LazyView<{
31
+ data?: Data;
32
+ children: Renderable;
33
+ }>;
34
+ errorView?: View<{
35
+ error: Error;
36
+ }>;
37
+ /**
38
+ * Subroutes.
39
+ */
40
+ routes?: Route[];
41
+ /**
42
+ * Arbitrary data you'd like to store on this route.
43
+ * This object is accessible via `match.meta` on the `$router` API while the route is active.
44
+ *
45
+ * In the case of nested routes, data from all layers will be merged into a single data object.
46
+ */
47
+ meta?: Record<string | symbol, any>;
48
+ }
49
+ export interface RouteLayer {
50
+ id: string;
51
+ pattern: string;
52
+ view: View<any> | LazyView<any>;
53
+ errorView?: View<{
54
+ error: Error;
55
+ }>;
56
+ preload?: (match: Match) => any | Promise<any>;
57
+ }
58
+ /**
59
+ * An active route layer whose markup has been initialized into a view.
60
+ */
61
+ export interface ActiveLayer {
62
+ id: string;
63
+ key: string;
64
+ node: MarkupNode;
65
+ context: Context;
66
+ slot: Getter<MarkupNode | undefined>;
67
+ setSlot: Setter<MarkupNode | undefined>;
68
+ }
69
+ /**
70
+ * A log for a single step in the route resolution process.
71
+ */
72
+ export interface JourneyStep {
73
+ kind: "match" | "redirect" | "miss";
74
+ message: string;
75
+ }
76
+ export interface NavigateOptions {
77
+ /**
78
+ * Preserve existing query params (if any) when navigating. Defaults to false.
79
+ * If true, all existing query params are preserved and merged with new ones.
80
+ * If an array of strings is passed only those keys will be preserved, then merged with any new ones.
81
+ */
82
+ preserveQuery?: boolean | string[];
83
+ }
84
+ export interface RouterOptions {
85
+ routes: Route[];
86
+ /**
87
+ * When true, the router will construct routes like "https://www.example.com/#/sub/route" which work without any backend intervention.
88
+ */
89
+ hash?: boolean;
90
+ /**
91
+ * Persist query params between pages when navigating. Pass an array to specify a list of params that will be preserved.
92
+ * By default all query params are cleared when navigating to a new URL (equivalent to `false`).
93
+ */
94
+ preserveQuery?: boolean | string[];
95
+ }
96
+ export interface Router {
97
+ /**
98
+ * The current path as it is displayed in the URL bar (e.g. `/users/123/edit`).
99
+ */
100
+ path: Getter<string>;
101
+ /**
102
+ * The route pattern that was matched (e.g. `/users/{#id}/edit`), or undefined if no route is currently matched.
103
+ */
104
+ pattern: Getter<string | undefined>;
105
+ /**
106
+ * The extracted route parameters from the path. (e.g. `{ id: "123" }`)
107
+ */
108
+ params: Getter<Record<string, string>>;
109
+ /**
110
+ * The current query params.
111
+ */
112
+ query: Getter<Record<string, string>>;
113
+ /**
114
+ * The contents of the `meta` fields of all matched route layers.
115
+ */
116
+ meta: Getter<Record<string, string>>;
117
+ /**
118
+ * Represents the loading progress of the current navigation from 0 to 1.
119
+ * Returns 0 when no navigation is pending.
120
+ */
121
+ progress: Getter<number>;
122
+ /**
123
+ * Update query params without changing the route.
124
+ */
125
+ setQuery(params: Record<string, Stringable>): Record<string, string>;
126
+ /**
127
+ * Go back in the page history. Equivalent to hitting the back button.
128
+ * Steps is the number of times to hit the back button. The default is 1.
129
+ */
130
+ back(steps?: number): void;
131
+ /**
132
+ * Go forward in the page history. Equivalent to hitting the forward button.
133
+ * Steps is the number of times to hit the forward button. The default is 1.
134
+ */
135
+ forward(steps?: number): void;
136
+ /**
137
+ * Push a new route into the page history and navigate to it.
138
+ */
139
+ push(path: string): void;
140
+ /**
141
+ * Replace the current route in the page history and navigate to it.
142
+ */
143
+ replace(path: string): void;
144
+ /**
145
+ * Prevents attempted navigations if the condition returns true.
146
+ */
147
+ block(guard: () => boolean | Promise<boolean>): () => void;
148
+ /**
149
+ * Contains `true` when the current route matches `path`.
150
+ */
151
+ isActive(path: string, exact?: boolean): Getter<boolean>;
152
+ }
@@ -0,0 +1,99 @@
1
+ import type { JourneyStep, Route, RouteLayer, Stringable } from "./types.js";
2
+ export interface Match {
3
+ /**
4
+ * The path string that triggered this match.
5
+ */
6
+ path: string;
7
+ /**
8
+ * The pattern satisfied by `path`.
9
+ */
10
+ pattern: string;
11
+ /**
12
+ * Named params as parsed from `path`.
13
+ */
14
+ params: Record<string, string>;
15
+ /**
16
+ * Query params as parsed from `path`.
17
+ */
18
+ query: Record<string, string>;
19
+ /**
20
+ * Freeform data you wish to store with this route.
21
+ * Merged `data` from all matched layers are available on the router's `match.meta`.
22
+ */
23
+ meta: Record<any, any>;
24
+ }
25
+ export interface RouteMatch extends Match {
26
+ layers: RouteLayer[];
27
+ redirect?: string | ((match: Match) => string) | ((match: Match) => Promise<string>);
28
+ }
29
+ export type RoutePayload = {
30
+ pattern: string;
31
+ meta: Record<any, any>;
32
+ layers?: RouteLayer[];
33
+ redirect?: string | ((match: Match) => string) | ((match: Match) => Promise<string>);
34
+ };
35
+ export type RouteMatchOptions = {
36
+ willMatch?: (route: RoutePayload) => boolean;
37
+ };
38
+ /**
39
+ * Separates a URL path into multiple fragments.
40
+ *
41
+ * @param path - A path string (e.g. `"/api/users/5"`)
42
+ * @returns an array of fragments (e.g. `["api", "users", "5"]`)
43
+ */
44
+ export declare function splitPath(path: string): string[];
45
+ /**
46
+ * Joins multiple URL path fragments into a single string.
47
+ *
48
+ * @param parts - One or more URL fragments (e.g. `["api", "users", 5]`)
49
+ * @returns a joined path (e.g. `"api/users/5"`)
50
+ */
51
+ export declare function joinPath(parts: {
52
+ toString(): string;
53
+ }[]): string;
54
+ export declare function resolvePath(base: string, part?: string | null): string;
55
+ export declare function parseQueryParams(query: string): Record<string, string>;
56
+ export declare function mergeQueryParams(previous: Record<string, string>, current: Record<string, Stringable>, preserve?: boolean | string[]): URLSearchParams;
57
+ export declare class RouteNode {
58
+ staticChildren: Map<string, RouteNode>;
59
+ numericChild: RouteNode | null;
60
+ paramChild: RouteNode | null;
61
+ wildcardChild: RouteNode | null;
62
+ route?: RoutePayload;
63
+ paramName?: string;
64
+ numericName?: string;
65
+ }
66
+ export declare function buildRouteTree(routes: Route[]): RouteNode;
67
+ export declare function matchRoute(rootNode: RouteNode, url: string, options?: RouteMatchOptions): RouteMatch | undefined;
68
+ export interface ResolvedRoute {
69
+ match?: RouteMatch;
70
+ journey: JourneyStep[];
71
+ }
72
+ /**
73
+ * Takes a URL and finds a match, following redirects.
74
+ */
75
+ export declare function resolveRoute(rootNode: RouteNode, path: string, journey?: JourneyStep[]): Promise<ResolvedRoute>;
76
+ /**
77
+ * Intercepts links within the root node.
78
+ *
79
+ * This is adapted from https://github.com/choojs/nanohref/blob/master/index.js
80
+ *
81
+ * @param root - Element under which to intercept link clicks
82
+ * @param callback - Function to call when a click event is intercepted
83
+ * @param _window - (optional) Override for global window object
84
+ */
85
+ export declare function catchLinks(root: Element, callback: (href: string, anchor: HTMLAnchorElement) => void, _window?: Window & typeof globalThis): () => void;
86
+ export declare function expandOptionalPaths(path: string): string[];
87
+ /**
88
+ * Replace route pattern param placeholders with real matched values.
89
+ */
90
+ export declare function replaceParams(path: string, params: Record<string, string | number>): string;
91
+ export interface HistoryAdapter {
92
+ getPath(): string;
93
+ getSearch(): string;
94
+ getKey(): string;
95
+ getIndex(): number;
96
+ push(url: string): void;
97
+ replace(url: string): void;
98
+ }
99
+ export declare function createHistoryAdapter(useHash: boolean): HistoryAdapter;
@@ -0,0 +1 @@
1
+ export {};