@manyducks.co/dolla 2.0.0-alpha.5 → 2.0.0-alpha.51

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 (83) hide show
  1. package/README.md +81 -933
  2. package/dist/core/context.d.ts +65 -0
  3. package/dist/{modules → core}/dolla.d.ts +43 -26
  4. package/dist/core/markup.d.ts +102 -0
  5. package/dist/core/nodes/dom.d.ts +13 -0
  6. package/dist/core/nodes/dynamic.d.ts +30 -0
  7. package/dist/core/nodes/fragment.d.ts +19 -0
  8. package/dist/core/nodes/html.d.ts +34 -0
  9. package/dist/core/nodes/outlet.d.ts +20 -0
  10. package/dist/core/nodes/portal.d.ts +22 -0
  11. package/dist/core/nodes/repeat.d.ts +28 -0
  12. package/dist/core/nodes/view.d.ts +97 -0
  13. package/dist/core/signals-api.d.ts +42 -0
  14. package/dist/core/signals.d.ts +22 -0
  15. package/dist/core/store.d.ts +52 -0
  16. package/dist/core/symbols.d.ts +4 -0
  17. package/dist/{views → core/views}/default-crash-view.d.ts +1 -1
  18. package/dist/core/views/fragment.d.ts +8 -0
  19. package/dist/{views → core/views}/passthrough.d.ts +2 -2
  20. package/dist/fragment-Bvuvw3ue.js +8 -0
  21. package/dist/fragment-Bvuvw3ue.js.map +1 -0
  22. package/dist/{modules/http.d.ts → http/index.d.ts} +3 -5
  23. package/dist/index.d.ts +15 -10
  24. package/dist/index.js +1056 -1216
  25. package/dist/index.js.map +1 -1
  26. package/dist/jsx-dev-runtime.d.ts +2 -2
  27. package/dist/jsx-dev-runtime.js +8 -8
  28. package/dist/jsx-dev-runtime.js.map +1 -1
  29. package/dist/jsx-runtime.d.ts +3 -3
  30. package/dist/jsx-runtime.js +10 -10
  31. package/dist/jsx-runtime.js.map +1 -1
  32. package/dist/markup-QqAGIoYP.js +1501 -0
  33. package/dist/markup-QqAGIoYP.js.map +1 -0
  34. package/dist/{modules/router.d.ts → router/index.d.ts} +53 -60
  35. package/dist/{routing.d.ts → router/router.utils.d.ts} +17 -3
  36. package/dist/router/router.utils.test.d.ts +1 -0
  37. package/dist/translate/index.d.ts +133 -0
  38. package/dist/typeChecking.d.ts +2 -98
  39. package/dist/typeChecking.test.d.ts +1 -0
  40. package/dist/types.d.ts +17 -7
  41. package/dist/utils.d.ts +18 -3
  42. package/docs/http.md +29 -0
  43. package/docs/i18n.md +38 -0
  44. package/docs/index.md +10 -0
  45. package/docs/router.md +80 -0
  46. package/docs/setup.md +31 -0
  47. package/docs/signals.md +166 -0
  48. package/docs/state.md +141 -0
  49. package/docs/stores.md +62 -0
  50. package/docs/views.md +208 -0
  51. package/examples/webcomponent/index.html +14 -0
  52. package/examples/webcomponent/main.js +165 -0
  53. package/index.d.ts +2 -2
  54. package/notes/TODO.md +6 -0
  55. package/notes/atomic.md +452 -0
  56. package/notes/context-routes.md +61 -0
  57. package/notes/custom-nodes.md +17 -0
  58. package/notes/elimination.md +33 -0
  59. package/notes/molecule.md +35 -0
  60. package/notes/readme-scratch.md +260 -0
  61. package/notes/route-middleware.md +42 -0
  62. package/notes/scratch.md +330 -7
  63. package/notes/splitting.md +5 -0
  64. package/notes/stores.md +53 -0
  65. package/package.json +13 -10
  66. package/vite.config.js +5 -10
  67. package/build.js +0 -34
  68. package/dist/markup.d.ts +0 -100
  69. package/dist/modules/language.d.ts +0 -41
  70. package/dist/modules/render.d.ts +0 -17
  71. package/dist/nodes/cond.d.ts +0 -26
  72. package/dist/nodes/html.d.ts +0 -31
  73. package/dist/nodes/observer.d.ts +0 -29
  74. package/dist/nodes/outlet.d.ts +0 -22
  75. package/dist/nodes/portal.d.ts +0 -19
  76. package/dist/nodes/repeat.d.ts +0 -34
  77. package/dist/nodes/text.d.ts +0 -19
  78. package/dist/passthrough-CtoBcpag.js +0 -1245
  79. package/dist/passthrough-CtoBcpag.js.map +0 -1
  80. package/dist/signals.d.ts +0 -101
  81. package/dist/view.d.ts +0 -50
  82. package/tests/signals.test.js +0 -135
  83. /package/dist/{routing.test.d.ts → core/signals-api.test.d.ts} +0 -0
package/notes/scratch.md CHANGED
@@ -1,5 +1,328 @@
1
1
  # Scratch Note
2
2
 
3
+ Idea: Monomorphic app context. Replaces StoreContext, ViewContext, etc.
4
+
5
+ Routes are baked into the app once again, but
6
+
7
+ ```jsx
8
+ import { createRoot } from "@manyducks.co/dolla";
9
+ import { example } from "./stores/example.js";
10
+
11
+ const root = createRoot();
12
+
13
+ root.use(example());
14
+
15
+ async function auth(_, state, redirect) {
16
+ // route context
17
+ // Routes run through each callback until one resolves to a renderable value.
18
+ // If redirect is called, the route is re-matched and no further callbacks are run for this route.
19
+
20
+ if (state.auth == null) {
21
+ redirect("/login");
22
+ }
23
+ }
24
+
25
+ root.route("/users/*", auth, (C) => {
26
+ C.route("/{#id}/*", (C) => {
27
+ C.route("/", (C) => <UserDetailRoute userId={C.params.id} />);
28
+ C.route("*", "./");
29
+ });
30
+ });
31
+
32
+ root.route("/users/*", auth, (route) => {
33
+ route("/{#id}/*", (route) => {
34
+ // TODO: It's possible to reference the wrong 'route'
35
+ // Track active context and throw error if the one you call belongs to the wrong context?
36
+ route("/", (_, state) => <UserDetailView userId={state.params.id} />);
37
+ route("*", "./");
38
+ });
39
+ });
40
+
41
+ function ExampleView(props, ctx) {
42
+ // ctx.routes returns a special type of outlet that renders children based on
43
+ // the route segments that come after the ones at this ctx.
44
+
45
+ // The weakness of this idea is that routes can't be validated without initializing views.
46
+ return (
47
+ <div>
48
+ <Suspense fallback={<span>Loading...</span>}>
49
+ {ctx.routes((route) => {
50
+ route("/subroute", () => <OtherView />);
51
+
52
+ // Routes can be async.
53
+ route("/other", () => import("some-module"));
54
+ })}
55
+ </Suspense>
56
+ </div>
57
+ );
58
+
59
+ // Also Suspense. This can be simply implemented with events.
60
+ ctx.emit("suspense:begin", uniqueId);
61
+ // Then when done:
62
+ ctx.emit("suspense:end", uniqueId);
63
+
64
+ // The nearest Suspense view will track ids which are in suspense and show fallback content in the meantime.
65
+ }
66
+
67
+ function Suspense(props, ctx) {
68
+ const [$tracked, setTracked] = createState({});
69
+
70
+ ctx.on("suspense:begin", (e) => {
71
+ setTracked((tracked) => {
72
+ return {
73
+ ...tracked,
74
+ [e.detail]: new Date(),
75
+ };
76
+ });
77
+ });
78
+
79
+ ctx.on("suspense:end", (e) => {
80
+ setTracked((tracked) => {
81
+ const updated = Object.assign({}, tracked);
82
+ delete updated[e.detail];
83
+ return updated;
84
+ });
85
+ });
86
+
87
+ // TODO: Hide suspended view without unmounting it. This might take special logic.
88
+ }
89
+
90
+ // Can also pass markup directly if you don't need the context.
91
+ root.route("/", auth, <HomeRoute />);
92
+
93
+ // Static redirect.
94
+ root.route("*", "/");
95
+
96
+ // Programmatic redirect.
97
+ root.route("*", (C) => {
98
+ C.log("hit wildcard");
99
+ C.redirect("/");
100
+ });
101
+
102
+ root.mount(document.body);
103
+
104
+ // generate an HTML string for server side rendering.
105
+ root.toString("/some/path");
106
+ ```
107
+
108
+ ---
109
+
110
+ ```js
111
+ class ClockStore extends Store {
112
+
113
+
114
+ constructor() {
115
+
116
+ }
117
+ }
118
+
119
+ class CounterStore extends Store {
120
+ // Could have better name. This will catch any
121
+ // this.emit('counter:increment') or this.emit('counter:decrement') calls
122
+ // and update the state according to these functions.
123
+ value = new Emittable('counter', 0, {
124
+ increment: state => state + 1,
125
+ decrement: state => state - 1
126
+ });
127
+ }
128
+
129
+ type CounterEvents = {
130
+ increment: [amount: number];
131
+ decrement: [amount: number];
132
+ }
133
+
134
+
135
+
136
+ ```
137
+
138
+ ---
139
+
140
+ Bring the $ back and the name full circle.
141
+
142
+ ```js
143
+ import { $, $$ } from "@manyducks.co/dolla";
144
+
145
+ // Shorthand dolla sign
146
+
147
+ // An initial value (with optional options object) creates a state.
148
+ const [$count, setCount] = $(0);
149
+ // = createState(0)
150
+
151
+ // An array and a function derives a state.
152
+ const $doubled = $.map([$count], (count) => count * 2);
153
+ // = derive([$count], (count) => count * 2);
154
+
155
+ // A state returns the same state.
156
+ const $sameCount = $.from($count);
157
+ const $wrapped = $.from({ message: "This is a state with no setter." });
158
+ // = toState($count)
159
+
160
+ // Get value from a state. Values that are not states are returned directly.
161
+ const count = $.get($count);
162
+ ```
163
+
164
+ What about other operators like RxJS?
165
+
166
+ ```js
167
+ // These would be functionally equivalent.
168
+ const $doubled = $count.pipe($.map((count) => count * 2));
169
+ const $doubled = $.map([$count], (count) => count * 2);
170
+
171
+ // Chainable. Get doubled value, but only update if it's between 10 and 100.
172
+ const $boundedDouble = $count.pipe(
173
+ // Transforms the value
174
+ $.map((count) => count * 2),
175
+
176
+ // Receives the value when it changes without affecting the output.
177
+ // Only receives values while this state is actively being watched.
178
+ $.tap((count) => console.log(`doubled value is ${count}`))
179
+
180
+ // Value only changes if it's within the range.
181
+ $.filter((count) => count >= 10 && count <= 100),
182
+ );
183
+
184
+ // Could have a top level pipe operator
185
+ const $boundedDouble = $.pipe(
186
+ [$count],
187
+ $.map((count) => count * 2),
188
+ $.tap((count) => console.log(`doubled value is ${count}`))
189
+ $.filter((count) => count >= 10 && count <= 100),
190
+ );
191
+
192
+ // Could also be chainable
193
+ const $boundedDouble = $count
194
+ .map((count) => count * 2)
195
+ .tap((count) => console.log(`doubled value is ${count}`))
196
+ .filter((count) => count >= 10 && count <= 100);
197
+
198
+ // I kind of like this more than the current derive. It's cleaner.
199
+ $count.map(c => c * 2);
200
+ $count.merge([$other], (c, o) => c * o);
201
+
202
+ // Another way to merge multiple.
203
+ $.merge([$count, $other], (c, o) => c * o);
204
+
205
+ // What if you want to add something in the middle?
206
+
207
+ const $example = $count
208
+ .map((count) => count * 2)
209
+ .tap((count) => console.log(`doubled value is ${count}`))
210
+ .merge([$other1, $other2], (count, other1, other2) => /* ... */)
211
+ .filter((value) => value >= 10 && value <= 100);
212
+
213
+ // Is this a good pattern?
214
+ $count
215
+ .merge([$other], (count, other) => count * other)
216
+ .merge([$another], (merged, another) => merged * another);
217
+ // I think it gets a little weird to follow.
218
+
219
+ // equivalent to
220
+ derive(
221
+ [
222
+ derive([$count, $other], (count, other) => count * other),
223
+ $another
224
+ ],
225
+ (merged, another) => merged * another)
226
+ // Is this a pattern? Yeah, I guess I do that. Just never in line like that.
227
+
228
+ // Do we want to handle errors?
229
+ // I feel like errors usually happen in watchers though.
230
+ $boundedDouble.watch((value) => {
231
+ // Received a value.
232
+ }, (error) => {
233
+ // Something threw an error.
234
+ });
235
+ // Or like this.
236
+ $boundedDouble.watch({
237
+ change: (value) => {
238
+ // Received a value.
239
+ // This code is most likely to throw an error.
240
+ // Should errors here be passed to the error callback?
241
+ // What is the point if you can just try/catch?
242
+
243
+ // Although if you don't then Dolla could use this to catch
244
+ // and trace errors better than it does now.
245
+ },
246
+ error: (error) => {
247
+ // Something threw an error.
248
+ }
249
+ });
250
+
251
+ // Filter derives a new state where the value only updates if the function returns truthy.
252
+ const $evens = $count.pipe($.filter((count) => count % 1 === 0));
253
+ // This is equivalent to
254
+ const $events = $.map([$count], (count) => count, { equals: (a, b) => a % 1 === 0 });
255
+
256
+ function filter(...args) {
257
+ if (isArray(args[0]) && isFunction(args[1])) {
258
+ // Standalone signature. Returns a new derived state.
259
+ } else if (args.length === 1 && isFunction(args[1])) {
260
+ // Curried signature. Returns a function that takes an array of states
261
+ // and returns one with args[1] as the equality check.
262
+ }
263
+ }
264
+ ```
265
+
266
+ And you can write your own operators that implement these two signatures.
267
+
268
+ ```js
269
+ // Here's one I might want to include.
270
+ // Use this to prevent ever getting a null value.
271
+ compare((next, previous) => next ?? previous ?? "default");
272
+
273
+ function compare(...args) {}
274
+ ```
275
+
276
+ ---
277
+
278
+ I've been looking into other libraries that don't make you track your dependencies specifically. I think this is weird and unhinged to be honest. Calling functions with side effects that magically re-run things when the value changes is a truly weird and unexpected lifecycle. At least if you're explicitly tracking dependencies you know exactly what depends on what at a glance. Getting the computer to figure it out for you doesn't seem smart.
279
+
280
+ ```js
281
+ import { $ } from "@manyducks.co/dolla";
282
+
283
+ const [count, setCount] = $(0);
284
+
285
+ const doubled = $.computed(() => count() * 2);
286
+
287
+ $.effect(() => {
288
+ console.log(doubled());
289
+ });
290
+
291
+ $.batch(() => {
292
+ // Set multiple things but defer updates to after this function returns.
293
+ });
294
+
295
+ // Helpers on $; can plug into template as is.
296
+ $.if(
297
+ $.computed(() => count() > 5),
298
+ <span>Greater than 5!</span>,
299
+ <span>Not greater than 5...</span>,
300
+ );
301
+
302
+ const switched = $.switch(count, [[1, "one"], [2, "two"], [3, "three"]], "more...");
303
+
304
+ $.repeat()
305
+
306
+ // TODO: How feasible is this?
307
+ <Repeat each={}>
308
+ {(item, index) => {
309
+
310
+ }}
311
+ </Repeat>
312
+
313
+ <Show when={condition}>
314
+ Condition is true.
315
+ </Show>
316
+
317
+ // Get
318
+ count();
319
+
320
+ // Set
321
+ count(52);
322
+ ```
323
+
324
+ ---
325
+
3
326
  What if Dolla was just a global object that you don't instantiate. I have never personally run into a use case for having more than one app on a page at once. In all my projects, the page and the app are synonymous.
4
327
 
5
328
  Doing this would make it possible to access things inside the Dolla app from _outside_ code such as Quill blots. Effectively all code that has access to your Dolla import is _inside_ the app.
@@ -11,8 +334,8 @@ Doing this would make it possible to access things inside the Dolla app from _ou
11
334
  import Dolla from "@manyducks.co/dolla";
12
335
 
13
336
  // Languages: add translation, set language and get localized string as a signal
14
- Dolla.language.setup({
15
- initialLanguage: Dolla.language.detect({ fallback: "ja" }), // Detect user's language and fall back to passed value
337
+ Dolla.i18n.setup({
338
+ initialLanguage: Dolla.i18n.detect({ fallback: "ja" }), // Detect user's language and fall back to passed value
16
339
  languages: [
17
340
  { name: "ja", path: "/static/locales/ja.json" },
18
341
  {
@@ -26,8 +349,8 @@ Dolla.language.setup({
26
349
  ]
27
350
  });
28
351
 
29
- Dolla.language.$current
30
- Dolla.language.t$()
352
+ Dolla.i18n.$locale
353
+ Dolla.i18n.t$()
31
354
 
32
355
  // A single setup call to keep things contained (must happen before mount)
33
356
  Dolla.router.setup({
@@ -75,10 +398,10 @@ debug.log("HELLO");
75
398
  debug.warn("THIS IS A SCOPED LOGGER");
76
399
 
77
400
  // Efficiently and safely read and mutate the DOM using Dolla's render batching
78
- Dolla.render.read(() => {
401
+ Dolla.batch.read(() => {
79
402
  // Reference DOM nodes
80
403
  });
81
- Dolla.render.update(() => {
404
+ Dolla.batch.write(() => {
82
405
  // Mutate the DOM as part of Dolla's next batch
83
406
  }, "some-key");
84
407
 
@@ -93,7 +416,7 @@ function SomeView (props: SomeViewProps, ctx: Dolla.ViewContext) {
93
416
  const debug = Dolla.createLogger("SomeView");
94
417
 
95
418
  // returns a signal and a setter function
96
- const [$someValue, setSomeValue] = Dolla.createSignal(4);
419
+ const [$someValue, setSomeValue] = Dolla.createState(4);
97
420
 
98
421
  // Router is now a part of the Dolla object
99
422
  Dolla.router.$path;
@@ -0,0 +1,5 @@
1
+ # Splitting
2
+
3
+ Thinking again of splitting this out into multiple libraries. Or at least having the base signals+markup be its own standalone thing that the rest of the framework is built on.
4
+
5
+ This implementation of signals + templates would be useful for web components.
@@ -0,0 +1,53 @@
1
+ # Stores
2
+
3
+ Ideas for updating the API.
4
+
5
+ ```js
6
+ function CounterStore(initialCount = 0, ctx) {
7
+ const [$value, setValue] = createState(initialCount);
8
+
9
+ ctx.on("counter:increment", (e) => {
10
+ e.stop(); // Stop this event from bubbling up to counters at higher levels (if any).
11
+ setValue((current) => current + 1);
12
+ });
13
+
14
+ ctx.on("counter:decrement", (e) => {
15
+ e.stop();
16
+ setValue((current) => current - 1);
17
+ });
18
+
19
+ // Events can be emitted from this context in a store.
20
+ ctx.emit("otherEvent");
21
+
22
+ ctx.onMount(() => {
23
+ // Setup
24
+ // This is called based on the context the store is attached to.
25
+ // If Dolla, it's called when the app is mounted. If ViewContext, it's called when the view is mounted.
26
+ });
27
+ ctx.onUnmount(() => {
28
+ // Cleanup
29
+ });
30
+
31
+ // Context variables will be accessible on the same context (e.g. the view this is attached to and below)
32
+ ctx.get("context variable");
33
+ ctx.set("context variable", "context variable value");
34
+
35
+ // Stores don't have to return anything, but if they do it becomes accessible with `ctx.use(Store)`.
36
+ return $value;
37
+ }
38
+
39
+ // Attach it to the app.
40
+ Dolla.provide(CounterStore, 0);
41
+
42
+ function ExampleView(props, ctx) {
43
+ // ctx.use lets you access the return value
44
+ // but the events will still be received and handled regardless
45
+ const $count = ctx.use(Counter);
46
+
47
+ return html`
48
+ <button onclick=${() => this.emit("counter:decrement")}>-1</button>
49
+ <span>${$count}</span>
50
+ <button onclick=${() => this.emit("counter:increment")}>+1</button>
51
+ `;
52
+ }
53
+ ```
package/package.json CHANGED
@@ -1,14 +1,17 @@
1
1
  {
2
2
  "name": "@manyducks.co/dolla",
3
- "version": "2.0.0-alpha.5",
3
+ "version": "2.0.0-alpha.51",
4
4
  "description": "Front-end components, routing and state management.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "type": "module",
8
8
  "sideEffects": false,
9
- "repository": "https://github.com/manyducksco/dolla",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/manyducksco/dolla.git"
12
+ },
10
13
  "scripts": {
11
- "test": "npm run build && node --test",
14
+ "test": "vitest",
12
15
  "build:esbuild": "tsc && node build.js",
13
16
  "build": "vite build && tsc",
14
17
  "start": "tsc --watch",
@@ -36,16 +39,16 @@
36
39
  "types": "./jsx-dev-runtime.d.ts"
37
40
  }
38
41
  },
42
+ "dependencies": {
43
+ "alien-signals": "^1.0.3"
44
+ },
39
45
  "devDependencies": {
40
- "@types/node": "^22.10.6",
46
+ "@types/node": "^22.12.0",
41
47
  "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
48
  "prettier": "^3.4.2",
47
- "simple-color-hash": "^1.0.2",
48
49
  "typescript": "^5.7.3",
49
- "vite": "^6.0.7"
50
+ "vite": "^6.0.11",
51
+ "vite-plugin-externalize-deps": "^0.9.0",
52
+ "vitest": "^3.0.5"
50
53
  }
51
54
  }
package/vite.config.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import { resolve } from "node:path";
2
2
  import { defineConfig } from "vite";
3
+ // import { externalizeDeps } from "vite-plugin-externalize-deps";
3
4
 
4
5
  export default defineConfig({
5
6
  build: {
6
- // minify: "terser",
7
- // minify: false,
8
7
  sourcemap: true,
8
+ minify: true,
9
+ // target: "esnext",
9
10
 
10
11
  lib: {
11
12
  entry: {
@@ -16,13 +17,7 @@ export default defineConfig({
16
17
  name: "Dolla",
17
18
  formats: ["es"],
18
19
  },
19
- // rollupOptions: {
20
- // external: ["vue"],
21
- // output: {
22
- // globals: {
23
- // vue: "Vue",
24
- // },
25
- // },
26
- // },
27
20
  },
21
+
22
+ // plugins: [externalizeDeps()],
28
23
  });
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/markup.d.ts DELETED
@@ -1,100 +0,0 @@
1
- import type { Dolla } from "./modules/dolla.js";
2
- import { MaybeSignal, type Signal } from "./signals.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: MaybeSignal<Stringable>;
38
- };
39
- $cond: {
40
- $predicate: Signal<any>;
41
- thenContent?: Renderable;
42
- elseContent?: Renderable;
43
- };
44
- $repeat: {
45
- $items: Signal<any[]>;
46
- keyFn: (value: any, index: number) => string | number | symbol;
47
- renderFn: ($item: Signal<any>, $index: Signal<number>, c: ViewContext) => ViewResult;
48
- };
49
- $observer: {
50
- signals: Signal<any>[];
51
- renderFn: (...items: any) => Renderable;
52
- };
53
- $outlet: {
54
- $children: Signal<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: MaybeSignal<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: MaybeSignal<T[]>, keyFn: (value: T, index: number) => string | number | symbol, renderFn: ($value: Signal<T>, $index: Signal<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 signal 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 Signal<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;
@@ -1,41 +0,0 @@
1
- import { type Signal } from "../signals.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: Signal<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 Signal 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 | Signal<Stringable>>): Signal<string>;
40
- }
41
- export {};