@manyducks.co/dolla 2.0.0-alpha.6 → 2.0.0-alpha.60
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 +144 -0
- package/dist/core/env.d.ts +3 -0
- package/dist/core/index.d.ts +22 -0
- package/dist/core/logger.d.ts +42 -0
- package/dist/core/markup.d.ts +125 -0
- package/dist/core/mount.d.ts +15 -0
- package/dist/core/nodes/dom.d.ts +14 -0
- package/dist/core/nodes/dynamic.d.ts +29 -0
- package/dist/core/nodes/html.d.ts +24 -0
- package/dist/core/nodes/portal.d.ts +19 -0
- package/dist/core/nodes/repeat.d.ts +25 -0
- package/dist/core/nodes/view.d.ts +24 -0
- package/dist/core/ref.d.ts +18 -0
- package/dist/core/signals.d.ts +43 -0
- package/dist/core/symbols.d.ts +2 -0
- package/dist/{views → core/views}/default-crash-view.d.ts +6 -2
- 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/{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 +105 -1385
- 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-MPwl-Xqu.js +524 -0
- package/dist/logger-MPwl-Xqu.js.map +1 -0
- package/dist/markup-BGlfQYQk.js +996 -0
- package/dist/markup-BGlfQYQk.js.map +1 -0
- package/dist/router/index.d.ts +2 -0
- package/dist/router/router.d.ts +149 -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-BpuJQ6OA.js +516 -0
- package/dist/router-BpuJQ6OA.js.map +1 -0
- package/dist/router.js +8 -0
- package/dist/router.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/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 +27 -12
- package/vite.config.js +5 -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/signals.test.d.ts} +0 -0
package/notes/stores.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Stores
|
|
2
|
+
|
|
3
|
+
Ideas for updating the API.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
What about a global stores registry? Basically just a global object you can import and register stores on, then get them later. Global (not scoped to views). You can still use `provide` and `get` on view contexts in the same exact way if you want scoped stores.
|
|
8
|
+
|
|
9
|
+
This is a replacement for the current way of providing global stores on the Dolla object. The Dolla object is going away in future API versions.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { Stores, Views } from "@manyducks.co/dolla";
|
|
13
|
+
|
|
14
|
+
Stores.provide(SomeStore, {
|
|
15
|
+
/* options */
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const some = Stores.get(SomeStore);
|
|
19
|
+
|
|
20
|
+
const SomeStore = Stores.define(() => {});
|
|
21
|
+
|
|
22
|
+
// Could also have views be defined this way.
|
|
23
|
+
const SomeView = Views.define<SomeProps>((props, ctx) => {});
|
|
24
|
+
|
|
25
|
+
// Register as a custom element.
|
|
26
|
+
Views.register("some-view", SomeView);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
function CounterStore(initialCount = 0, ctx) {
|
|
33
|
+
const [$value, setValue] = createState(initialCount);
|
|
34
|
+
|
|
35
|
+
ctx.on("counter:increment", (e) => {
|
|
36
|
+
e.stop(); // Stop this event from bubbling up to counters at higher levels (if any).
|
|
37
|
+
setValue((current) => current + 1);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
ctx.on("counter:decrement", (e) => {
|
|
41
|
+
e.stop();
|
|
42
|
+
setValue((current) => current - 1);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Events can be emitted from this context in a store.
|
|
46
|
+
ctx.emit("otherEvent");
|
|
47
|
+
|
|
48
|
+
ctx.onMount(() => {
|
|
49
|
+
// Setup
|
|
50
|
+
// This is called based on the context the store is attached to.
|
|
51
|
+
// If Dolla, it's called when the app is mounted. If ViewContext, it's called when the view is mounted.
|
|
52
|
+
});
|
|
53
|
+
ctx.onUnmount(() => {
|
|
54
|
+
// Cleanup
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Context variables will be accessible on the same context (e.g. the view this is attached to and below)
|
|
58
|
+
ctx.get("context variable");
|
|
59
|
+
ctx.set("context variable", "context variable value");
|
|
60
|
+
|
|
61
|
+
// Stores don't have to return anything, but if they do it becomes accessible with `ctx.use(Store)`.
|
|
62
|
+
return $value;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Attach it to the app.
|
|
66
|
+
Dolla.provide(CounterStore, 0);
|
|
67
|
+
|
|
68
|
+
function ExampleView(props, ctx) {
|
|
69
|
+
// ctx.use lets you access the return value
|
|
70
|
+
// but the events will still be received and handled regardless
|
|
71
|
+
const $count = ctx.use(Counter);
|
|
72
|
+
|
|
73
|
+
return html`
|
|
74
|
+
<button onclick=${() => this.emit("counter:decrement")}>-1</button>
|
|
75
|
+
<span>${$count}</span>
|
|
76
|
+
<button onclick=${() => this.emit("counter:increment")}>+1</button>
|
|
77
|
+
`;
|
|
78
|
+
}
|
|
79
|
+
```
|
package/package.json
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manyducks.co/dolla",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.60",
|
|
4
4
|
"description": "Front-end components, routing and state management.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
6
|
+
"types": "dist/core/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"sideEffects": false,
|
|
9
|
-
"repository":
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/manyducksco/dolla.git"
|
|
12
|
+
},
|
|
10
13
|
"scripts": {
|
|
11
|
-
"test": "
|
|
14
|
+
"test": "vitest",
|
|
12
15
|
"build:esbuild": "tsc && node build.js",
|
|
13
16
|
"build": "vite build && tsc",
|
|
14
17
|
"start": "tsc --watch",
|
|
@@ -25,7 +28,19 @@
|
|
|
25
28
|
"exports": {
|
|
26
29
|
".": {
|
|
27
30
|
"import": "./dist/index.js",
|
|
28
|
-
"types": "./index.d.ts"
|
|
31
|
+
"types": "./dist/core/index.d.ts"
|
|
32
|
+
},
|
|
33
|
+
"./router": {
|
|
34
|
+
"import": "./dist/router.js",
|
|
35
|
+
"types": "./dist/router/index.d.ts"
|
|
36
|
+
},
|
|
37
|
+
"./http": {
|
|
38
|
+
"import": "./dist/http.js",
|
|
39
|
+
"types": "./dist/http/index.d.ts"
|
|
40
|
+
},
|
|
41
|
+
"./i18n": {
|
|
42
|
+
"import": "./dist/i18n.js",
|
|
43
|
+
"types": "./dist/i18n/index.d.ts"
|
|
29
44
|
},
|
|
30
45
|
"./jsx-runtime": {
|
|
31
46
|
"import": "./dist/jsx-runtime.js",
|
|
@@ -36,16 +51,16 @@
|
|
|
36
51
|
"types": "./jsx-dev-runtime.d.ts"
|
|
37
52
|
}
|
|
38
53
|
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"alien-signals": "^2.0.5"
|
|
56
|
+
},
|
|
39
57
|
"devDependencies": {
|
|
40
|
-
"@types/node": "^22.
|
|
58
|
+
"@types/node": "^22.12.0",
|
|
41
59
|
"csstype": "^3.1.3",
|
|
42
|
-
"esbuild": "^0.24.2",
|
|
43
|
-
"history": "^5.3.0",
|
|
44
|
-
"htm": "^3.1.1",
|
|
45
|
-
"nanoid": "^5.0.9",
|
|
46
60
|
"prettier": "^3.4.2",
|
|
47
|
-
"simple-color-hash": "^1.0.2",
|
|
48
61
|
"typescript": "^5.7.3",
|
|
49
|
-
"vite": "^6.0.
|
|
62
|
+
"vite": "^6.0.11",
|
|
63
|
+
"vite-plugin-externalize-deps": "^0.9.0",
|
|
64
|
+
"vitest": "^3.0.5"
|
|
50
65
|
}
|
|
51
66
|
}
|
package/vite.config.js
CHANGED
|
@@ -3,26 +3,20 @@ import { defineConfig } from "vite";
|
|
|
3
3
|
|
|
4
4
|
export default defineConfig({
|
|
5
5
|
build: {
|
|
6
|
-
// minify: "terser",
|
|
7
|
-
// minify: false,
|
|
8
6
|
sourcemap: true,
|
|
7
|
+
minify: true,
|
|
9
8
|
|
|
10
9
|
lib: {
|
|
11
10
|
entry: {
|
|
12
|
-
index: resolve(__dirname, "src/index.ts"),
|
|
11
|
+
index: resolve(__dirname, "src/core/index.ts"),
|
|
12
|
+
http: resolve(__dirname, "src/http/index.ts"),
|
|
13
|
+
i18n: resolve(__dirname, "src/i18n/index.ts"),
|
|
14
|
+
router: resolve(__dirname, "src/router/index.ts"),
|
|
13
15
|
"jsx-runtime": resolve(__dirname, "src/jsx-runtime.js"),
|
|
14
16
|
"jsx-dev-runtime": resolve(__dirname, "src/jsx-dev-runtime.js"),
|
|
15
17
|
},
|
|
16
18
|
name: "Dolla",
|
|
17
19
|
formats: ["es"],
|
|
18
20
|
},
|
|
19
|
-
// rollupOptions: {
|
|
20
|
-
// external: ["vue"],
|
|
21
|
-
// output: {
|
|
22
|
-
// globals: {
|
|
23
|
-
// vue: "Vue",
|
|
24
|
-
// },
|
|
25
|
-
// },
|
|
26
|
-
// },
|
|
27
21
|
},
|
|
28
22
|
});
|
package/build.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import esbuild from "esbuild";
|
|
3
|
-
|
|
4
|
-
esbuild
|
|
5
|
-
.build({
|
|
6
|
-
entryPoints: ["src/index.ts"],
|
|
7
|
-
bundle: true,
|
|
8
|
-
metafile: true,
|
|
9
|
-
sourcemap: true,
|
|
10
|
-
// minify: process.env.NODE_ENV === "production",
|
|
11
|
-
outdir: "dist",
|
|
12
|
-
format: "esm",
|
|
13
|
-
})
|
|
14
|
-
.then((result) => {
|
|
15
|
-
fs.writeFileSync("esbuild-meta.json", JSON.stringify(result.metafile));
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
esbuild.build({
|
|
19
|
-
entryPoints: ["src/jsx-runtime.js"],
|
|
20
|
-
bundle: false,
|
|
21
|
-
minify: false,
|
|
22
|
-
sourcemap: true,
|
|
23
|
-
outdir: "dist",
|
|
24
|
-
format: "esm",
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
esbuild.build({
|
|
28
|
-
entryPoints: ["src/jsx-dev-runtime.js"],
|
|
29
|
-
bundle: false,
|
|
30
|
-
minify: false,
|
|
31
|
-
sourcemap: true,
|
|
32
|
-
outdir: "dist",
|
|
33
|
-
format: "esm",
|
|
34
|
-
});
|
package/dist/index.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export { createSettableState, createSetter, createState, derive, toSettableState, toState, valueOf } from "./state.js";
|
|
2
|
-
export type { MaybeState, SettableState, State, StopFunction } from "./state.js";
|
|
3
|
-
export { cond, createMarkup, createRef, html, isRef, portal, repeat } from "./markup.js";
|
|
4
|
-
export type { Markup, MarkupNode, Ref } from "./markup.js";
|
|
5
|
-
import { Dolla } from "./modules/dolla.js";
|
|
6
|
-
declare const dolla: Dolla;
|
|
7
|
-
export default dolla;
|
|
8
|
-
export declare const t: (key: string, values?: Record<string, import("./types.js").Stringable | import("./state.js").State<import("./types.js").Stringable>>) => import("./state.js").State<string>;
|
|
9
|
-
export type { Dolla, Environment, Logger, LoggerErrorContext, LoggerOptions, Loggles } from "./modules/dolla.js";
|
|
10
|
-
export type { HTTPRequest, HTTPResponse } from "./modules/http.js";
|
|
11
|
-
export type { InputType, Renderable } from "./types.js";
|
|
12
|
-
export type { ViewContext, ViewFunction, ViewNode } from "./view.js";
|
|
13
|
-
export type { CrashViewProps } from "./views/default-crash-view.js";
|
|
14
|
-
import type { IntrinsicElements as Elements } from "./types";
|
|
15
|
-
declare global {
|
|
16
|
-
namespace JSX {
|
|
17
|
-
interface IntrinsicElements extends Elements {
|
|
18
|
-
[tag: string]: any;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
package/dist/markup.d.ts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import type { Dolla } from "./modules/dolla.js";
|
|
2
|
-
import { MaybeState, type State } from "./state.js";
|
|
3
|
-
import type { Renderable, Stringable } from "./types.js";
|
|
4
|
-
import { type ViewFunction, type ViewContext, type ViewResult } from "./view.js";
|
|
5
|
-
export interface ElementContext {
|
|
6
|
-
/**
|
|
7
|
-
* The root Dolla instance this element belongs to.
|
|
8
|
-
*/
|
|
9
|
-
root: Dolla;
|
|
10
|
-
/**
|
|
11
|
-
* Whether to create DOM nodes in the SVG namespace. An `<svg>` element will set this to true and pass it down to children.
|
|
12
|
-
*/
|
|
13
|
-
isSVG?: boolean;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Markup is a set of element metadata that hasn't been constructed into a MarkupNode yet.
|
|
17
|
-
*/
|
|
18
|
-
export interface Markup {
|
|
19
|
-
type: string | ViewFunction<any>;
|
|
20
|
-
props?: Record<string, any>;
|
|
21
|
-
children?: Markup[];
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* A DOM node that has been constructed from a Markup object.
|
|
25
|
-
*/
|
|
26
|
-
export interface MarkupNode {
|
|
27
|
-
readonly node?: Node;
|
|
28
|
-
readonly isMounted: boolean;
|
|
29
|
-
mount(parent: Node, after?: Node): void;
|
|
30
|
-
unmount(): void;
|
|
31
|
-
}
|
|
32
|
-
export declare function isMarkup(value: unknown): value is Markup;
|
|
33
|
-
export declare function isNode(value: unknown): value is MarkupNode;
|
|
34
|
-
export declare function toMarkup(renderables: Renderable | Renderable[]): Markup[];
|
|
35
|
-
export interface MarkupAttributes {
|
|
36
|
-
$text: {
|
|
37
|
-
value: MaybeState<Stringable>;
|
|
38
|
-
};
|
|
39
|
-
$cond: {
|
|
40
|
-
$predicate: State<any>;
|
|
41
|
-
thenContent?: Renderable;
|
|
42
|
-
elseContent?: Renderable;
|
|
43
|
-
};
|
|
44
|
-
$repeat: {
|
|
45
|
-
$items: State<any[]>;
|
|
46
|
-
keyFn: (value: any, index: number) => string | number | symbol;
|
|
47
|
-
renderFn: ($item: State<any>, $index: State<number>, c: ViewContext) => ViewResult;
|
|
48
|
-
};
|
|
49
|
-
$observer: {
|
|
50
|
-
states: State<any>[];
|
|
51
|
-
renderFn: (...items: any) => Renderable;
|
|
52
|
-
};
|
|
53
|
-
$outlet: {
|
|
54
|
-
$children: State<MarkupNode[]>;
|
|
55
|
-
};
|
|
56
|
-
$node: {
|
|
57
|
-
value: Node;
|
|
58
|
-
};
|
|
59
|
-
$portal: {
|
|
60
|
-
content: Renderable;
|
|
61
|
-
parent: Node;
|
|
62
|
-
};
|
|
63
|
-
[tag: string]: Record<string, any>;
|
|
64
|
-
}
|
|
65
|
-
export declare function createMarkup<T extends keyof MarkupAttributes>(type: T, attributes: MarkupAttributes[T], ...children: Renderable[]): Markup;
|
|
66
|
-
export declare function createMarkup<I>(type: ViewFunction<I>, attributes?: I, ...children: Renderable[]): Markup;
|
|
67
|
-
/**
|
|
68
|
-
* Generate markup with HTML in a tagged template literal.
|
|
69
|
-
*/
|
|
70
|
-
export declare const html: (strings: TemplateStringsArray, ...values: any[]) => Markup | Markup[];
|
|
71
|
-
/**
|
|
72
|
-
* Displays content conditionally. When `predicate` holds a truthy value, `thenContent` is displayed; when `predicate` holds a falsy value, `elseContent` is displayed.
|
|
73
|
-
*/
|
|
74
|
-
export declare function cond(predicate: MaybeState<any>, thenContent?: Renderable, elseContent?: Renderable): Markup;
|
|
75
|
-
/**
|
|
76
|
-
* Calls `renderFn` for each item in `items`. Dynamically adds and removes views as items change.
|
|
77
|
-
* The result of `keyFn` is used to compare items and decide if item was added, removed or updated.
|
|
78
|
-
*/
|
|
79
|
-
export declare function repeat<T>(items: MaybeState<T[]>, keyFn: (value: T, index: number) => string | number | symbol, renderFn: ($value: State<T>, $index: State<number>, ctx: ViewContext) => ViewResult): Markup;
|
|
80
|
-
/**
|
|
81
|
-
* Render `content` into a `parent` node anywhere in the page, rather than at its position in the view.
|
|
82
|
-
*/
|
|
83
|
-
export declare function portal(parent: Node, content: Renderable): Markup;
|
|
84
|
-
/**
|
|
85
|
-
* A special kind of State exclusively for storing references to DOM nodes.
|
|
86
|
-
*/
|
|
87
|
-
export declare function createRef<T extends Node>(): Ref<T>;
|
|
88
|
-
export declare function isRef<T extends Node>(value: any): value is Ref<T>;
|
|
89
|
-
export interface Ref<T extends Node> extends State<T | undefined> {
|
|
90
|
-
node: T | undefined;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Construct Markup metadata into a set of MarkupNodes.
|
|
94
|
-
*/
|
|
95
|
-
export declare function constructMarkup(elementContext: ElementContext, markup: Markup | Markup[]): MarkupNode[];
|
|
96
|
-
/**
|
|
97
|
-
* Combines one or more MarkupNodes into a single MarkupNode.
|
|
98
|
-
*/
|
|
99
|
-
export declare function mergeNodes(nodes: MarkupNode[]): MarkupNode;
|
|
100
|
-
export declare function isRenderable(value: unknown): value is Renderable;
|
package/dist/modules/dolla.d.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { createRef, isRef, MarkupNode, type Markup } from "../markup.js";
|
|
2
|
-
import { createSettableState, createState, derive, toSettableState, toState, valueOf, watch, type State } from "../state.js";
|
|
3
|
-
import { type ViewFunction, type ViewNode } from "../view.js";
|
|
4
|
-
import { type CrashViewProps } from "../views/default-crash-view.js";
|
|
5
|
-
import { HTTP } from "./http.js";
|
|
6
|
-
import { Language } from "./language.js";
|
|
7
|
-
import { Render } from "./render.js";
|
|
8
|
-
import { Router } from "./router.js";
|
|
9
|
-
export type Environment = "development" | "production";
|
|
10
|
-
/**
|
|
11
|
-
* Log type toggles. Each message category can be turned on or off or enabled only in a specific environment.
|
|
12
|
-
*/
|
|
13
|
-
export type Loggles = {
|
|
14
|
-
info: boolean | Environment;
|
|
15
|
-
log: boolean | Environment;
|
|
16
|
-
warn: boolean | Environment;
|
|
17
|
-
error: boolean | Environment;
|
|
18
|
-
};
|
|
19
|
-
export interface Logger {
|
|
20
|
-
info(...args: any[]): void;
|
|
21
|
-
log(...args: any[]): void;
|
|
22
|
-
warn(...args: any[]): void;
|
|
23
|
-
error(...args: any[]): void;
|
|
24
|
-
crash(error: Error): void;
|
|
25
|
-
}
|
|
26
|
-
export interface LoggerErrorContext {
|
|
27
|
-
error: Error;
|
|
28
|
-
loggerName: string;
|
|
29
|
-
uid?: string;
|
|
30
|
-
}
|
|
31
|
-
export type LoggerOptions = {
|
|
32
|
-
/**
|
|
33
|
-
* Console object to use for logging (mostly for testing). Uses window.console by default.
|
|
34
|
-
*/
|
|
35
|
-
console?: any;
|
|
36
|
-
/**
|
|
37
|
-
* Unique ID to print with logs. Makes it easier to track down messages from specific view instances.
|
|
38
|
-
*/
|
|
39
|
-
uid?: string;
|
|
40
|
-
};
|
|
41
|
-
export declare class Dolla {
|
|
42
|
-
#private;
|
|
43
|
-
readonly http: HTTP;
|
|
44
|
-
readonly language: Language;
|
|
45
|
-
readonly render: Render;
|
|
46
|
-
readonly router: Router;
|
|
47
|
-
constructor();
|
|
48
|
-
createState: typeof createState;
|
|
49
|
-
createSettableState: typeof createSettableState;
|
|
50
|
-
toSettableState: typeof toSettableState;
|
|
51
|
-
toState: typeof toState;
|
|
52
|
-
valueOf: typeof valueOf;
|
|
53
|
-
derive: typeof derive;
|
|
54
|
-
watch: typeof watch;
|
|
55
|
-
createRef: typeof createRef;
|
|
56
|
-
isRef: typeof isRef;
|
|
57
|
-
/**
|
|
58
|
-
* True when the app is connected to a DOM node and displayed to the user.
|
|
59
|
-
*/
|
|
60
|
-
get isMounted(): boolean;
|
|
61
|
-
/**
|
|
62
|
-
* Get the current environment that this app is running in.
|
|
63
|
-
* Environment affects which log messages will print and how much debugging info is included in the DOM.
|
|
64
|
-
*/
|
|
65
|
-
getEnv(): Environment;
|
|
66
|
-
/**
|
|
67
|
-
* Sets the environment that this app is running in.
|
|
68
|
-
* Environment affects which log messages will print and how much debugging info is included in the DOM.
|
|
69
|
-
*/
|
|
70
|
-
setEnv(value: Environment): void;
|
|
71
|
-
/**
|
|
72
|
-
* Sets the view that will be shown when the `crash` method is called on any logger.
|
|
73
|
-
* When a crash is reported the app will be unmounted and replaced with this crash page.
|
|
74
|
-
*/
|
|
75
|
-
setCrashView(view: ViewFunction<CrashViewProps>): void;
|
|
76
|
-
mount(selector: string, view?: ViewFunction<any>): Promise<void>;
|
|
77
|
-
mount(element: HTMLElement, view?: ViewFunction<any>): Promise<void>;
|
|
78
|
-
unmount(): Promise<void>;
|
|
79
|
-
/**
|
|
80
|
-
* Registers a `callback` to run after `Dolla.mount` is called, before the app is mounted. If `callback` returns a Promise,
|
|
81
|
-
* it will be awaited before mounting finishes. Use this to perform initial setup before the app is displayed to the user.
|
|
82
|
-
*/
|
|
83
|
-
beforeMount(callback: () => void | Promise<void>): void;
|
|
84
|
-
/**
|
|
85
|
-
* Registers a `callback` to run after the app is mounted.
|
|
86
|
-
*/
|
|
87
|
-
onMount(callback: () => void): void;
|
|
88
|
-
/**
|
|
89
|
-
* Registers a `callback` to run after `Dolla.unmount` is called, before the app is unmounted. If `callback` returns a Promise,
|
|
90
|
-
* it will be awaited before unmounting finishes. Use this to perform cleanup.
|
|
91
|
-
*/
|
|
92
|
-
beforeUnmount(callback: () => void | Promise<void>): void;
|
|
93
|
-
/**
|
|
94
|
-
* Registers a `callback` to run after the app is unmounted.
|
|
95
|
-
*/
|
|
96
|
-
onUnmount(callback: () => void): void;
|
|
97
|
-
/**
|
|
98
|
-
* Update log type toggles. Values that are not passed will remain unchanged.
|
|
99
|
-
*/
|
|
100
|
-
setLoggles(options: Partial<Loggles>): void;
|
|
101
|
-
setLogFilter(filter: string | RegExp): void;
|
|
102
|
-
createLogger(name: string | State<string>, options?: LoggerOptions): Logger;
|
|
103
|
-
/**
|
|
104
|
-
*
|
|
105
|
-
*/
|
|
106
|
-
constructView<P>(view: ViewFunction<P>, props: P, children?: Markup[]): ViewNode;
|
|
107
|
-
/**
|
|
108
|
-
*
|
|
109
|
-
*/
|
|
110
|
-
constructMarkup(markup: Markup | Markup[]): MarkupNode;
|
|
111
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { 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 LanguageConfig {
|
|
9
|
-
name: string;
|
|
10
|
-
/**
|
|
11
|
-
* Path to a JSON file with translated strings for this language.
|
|
12
|
-
*/
|
|
13
|
-
path?: string;
|
|
14
|
-
/**
|
|
15
|
-
* A callback function that returns a Promise that resolves to the translation object for this language.
|
|
16
|
-
*/
|
|
17
|
-
fetch?: () => Promise<LocalizedStrings>;
|
|
18
|
-
}
|
|
19
|
-
export type LanguageSetupOptions = {
|
|
20
|
-
/**
|
|
21
|
-
* Default language to load on startup
|
|
22
|
-
*/
|
|
23
|
-
initialLanguage?: string | null;
|
|
24
|
-
languages: LanguageConfig[];
|
|
25
|
-
};
|
|
26
|
-
export declare class Language {
|
|
27
|
-
#private;
|
|
28
|
-
$current: State<string | undefined>;
|
|
29
|
-
constructor(dolla: Dolla);
|
|
30
|
-
get supportedLanguages(): string[];
|
|
31
|
-
setup(options: LanguageSetupOptions): void;
|
|
32
|
-
setLanguage(name: string): Promise<void>;
|
|
33
|
-
/**
|
|
34
|
-
* Returns a State containing the value at `key`.
|
|
35
|
-
|
|
36
|
-
* @param key - Key to the translated value.
|
|
37
|
-
* @param values - A map of {{placeholder}} names and the values to replace them with.
|
|
38
|
-
*/
|
|
39
|
-
t(key: string, values?: Record<string, Stringable | State<Stringable>>): State<string>;
|
|
40
|
-
}
|
|
41
|
-
export {};
|
package/dist/modules/render.d.ts
DELETED
|
@@ -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
|
-
}
|
package/dist/modules/router.d.ts
DELETED
|
@@ -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 {};
|
package/dist/nodes/cond.d.ts
DELETED
|
@@ -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
|
-
}
|