@kayr/umbika-web-renderer 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +46 -2
- package/THIRD_PARTY_LICENSES.txt +20 -0
- package/dist/browser/umbika.min.css +23 -0
- package/dist/browser/umbika.min.d.mts +437 -0
- package/dist/browser/umbika.min.d.ts +437 -0
- package/dist/browser/umbika.min.js +60 -0
- package/dist/browser/umbika.min.mjs +60 -0
- package/dist/casconda.d.ts +2 -0
- package/dist/casconda.d.ts.map +1 -0
- package/dist/contracts.d.ts +165 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/dom-identity.d.ts +17 -0
- package/dist/dom-identity.d.ts.map +1 -0
- package/dist/field-presentation.d.ts +26 -0
- package/dist/field-presentation.d.ts.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/layout.d.ts +25 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/mount.d.ts +14 -0
- package/dist/mount.d.ts.map +1 -0
- package/dist/render-nodes.d.ts +18 -0
- package/dist/render-nodes.d.ts.map +1 -0
- package/dist/renderers/multi-select.d.ts +18 -0
- package/dist/renderers/multi-select.d.ts.map +1 -0
- package/dist/renderers/object.d.ts +6 -0
- package/dist/renderers/object.d.ts.map +1 -0
- package/dist/renderers/output.d.ts +6 -0
- package/dist/renderers/output.d.ts.map +1 -0
- package/dist/renderers/select.d.ts +6 -0
- package/dist/renderers/select.d.ts.map +1 -0
- package/dist/renderers/table.d.ts +6 -0
- package/dist/renderers/table.d.ts.map +1 -0
- package/dist/renderers/text.d.ts +8 -0
- package/dist/renderers/text.d.ts.map +1 -0
- package/dist/row-details.d.ts +89 -0
- package/dist/row-details.d.ts.map +1 -0
- package/dist/standalone/contracts.d.ts +77 -0
- package/dist/standalone/contracts.d.ts.map +1 -0
- package/dist/standalone/index.d.ts +7 -0
- package/dist/standalone/index.d.ts.map +1 -0
- package/dist/standalone/mount.d.ts +9 -0
- package/dist/standalone/mount.d.ts.map +1 -0
- package/dist/summary.d.ts +29 -0
- package/dist/summary.d.ts.map +1 -0
- package/dist/tags.d.ts +32 -0
- package/dist/tags.d.ts.map +1 -0
- package/package.json +78 -4
- package/src/casconda.js +10 -0
- package/src/contracts.js +79 -0
- package/src/dom-identity.js +31 -0
- package/src/field-presentation.js +71 -0
- package/src/index.js +9 -0
- package/src/layout.js +176 -0
- package/src/mount.js +569 -0
- package/src/render-nodes.js +77 -0
- package/src/renderers/multi-select.js +211 -0
- package/src/renderers/object.js +43 -0
- package/src/renderers/output.js +87 -0
- package/src/renderers/select.js +104 -0
- package/src/renderers/table.js +344 -0
- package/src/renderers/text.js +82 -0
- package/src/row-details.js +305 -0
- package/src/standalone/contracts.js +22 -0
- package/src/standalone/index.js +5 -0
- package/src/standalone/mount.js +128 -0
- package/src/summary.js +135 -0
- package/src/tags.js +69 -0
- package/styles/base.css +432 -0
- package/styles/standalone.css +2 -0
- package/styles/themes/default.css +99 -0
- package/vendor/LICENSE +21 -0
- package/vendor/README.md +33 -0
- package/vendor/casconda.min.d.mts +340 -0
- package/vendor/casconda.min.d.ts +340 -0
- package/vendor/casconda.min.mjs +1 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
export namespace d {
|
|
4
|
+
export function arr(): (val: any) => val is any[];
|
|
5
|
+
export function map(): (val: any) => val is Map<any, any>;
|
|
6
|
+
export function any(): () => boolean;
|
|
7
|
+
export function func(): (val: any) => boolean;
|
|
8
|
+
export function num(): (val: any) => boolean;
|
|
9
|
+
export function str(): (val: any) => boolean;
|
|
10
|
+
export function bool(): (val: any) => boolean;
|
|
11
|
+
export function bigint(): (val: any) => boolean;
|
|
12
|
+
export function sym(): (val: any) => boolean;
|
|
13
|
+
export function undef(): (val: any) => boolean;
|
|
14
|
+
export function obj(): (val: any) => boolean;
|
|
15
|
+
export function nil(matcher: any): (val: any) => boolean;
|
|
16
|
+
export function notNil(matcher: any): (val: any) => boolean;
|
|
17
|
+
export { dispatch as dispatch };
|
|
18
|
+
export { varg as varg };
|
|
19
|
+
export function eq(val: any): (v: any) => boolean;
|
|
20
|
+
export { or };
|
|
21
|
+
export { and };
|
|
22
|
+
export { not };
|
|
23
|
+
export { instOf };
|
|
24
|
+
}
|
|
25
|
+
declare function dispatch(...fns: any[]): (...args: any[]) => any;
|
|
26
|
+
declare function varg(pred: any): ((argList: any) => any) & {
|
|
27
|
+
__isVarg: boolean;
|
|
28
|
+
};
|
|
29
|
+
declare function or(...fns: any[]): (val: any) => boolean;
|
|
30
|
+
declare function and(...fns: any[]): (val: any) => boolean;
|
|
31
|
+
declare function not(fn: any): (val: any) => boolean;
|
|
32
|
+
declare function instOf(type: any): (val: any) => boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Creates an independently configured Casconda renderer.
|
|
35
|
+
*
|
|
36
|
+
* Binding defaults are scoped to the returned instance. Explicit binding
|
|
37
|
+
* options such as `{ ref, event }` override the matching instance default.
|
|
38
|
+
*
|
|
39
|
+
* @param {{bindings?: {text?: {event?: string}, checkbox?: {event?: string}, radio?: {event?: string}}}} [options]
|
|
40
|
+
* @returns {{render: (...args: any[]) => any}}
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* const form = createCasconda({
|
|
44
|
+
* bindings: { text: { event: "blur" } },
|
|
45
|
+
* });
|
|
46
|
+
* form.render(["input", { bind: myRef }]);
|
|
47
|
+
*/
|
|
48
|
+
export function createCasconda(options?: {
|
|
49
|
+
bindings?: {
|
|
50
|
+
text?: {
|
|
51
|
+
event?: string;
|
|
52
|
+
};
|
|
53
|
+
checkbox?: {
|
|
54
|
+
event?: string;
|
|
55
|
+
};
|
|
56
|
+
radio?: {
|
|
57
|
+
event?: string;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
}): {
|
|
61
|
+
render: (...args: any[]) => any;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Wraps an array of elements so that `render()` can unambiguously treat it as
|
|
65
|
+
* a children list rather than an attribute object.
|
|
66
|
+
*
|
|
67
|
+
* Useful when you have a dynamically-built array of children to pass to a tag
|
|
68
|
+
* factory that would otherwise interpret a plain array as attributes.
|
|
69
|
+
*
|
|
70
|
+
* @param {Array} elems - Array of child nodes or tagged arrays.
|
|
71
|
+
* @returns {_lst}
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* const items = ["a", "b", "c"];
|
|
75
|
+
* render(["ul", lst(items.map(i => ["li", i]))])
|
|
76
|
+
*/
|
|
77
|
+
export function lst(elems: any[]): _lst;
|
|
78
|
+
export const render: (...args: any[]) => any;
|
|
79
|
+
/**
|
|
80
|
+
* Proxy that generates tagged arrays via property access.
|
|
81
|
+
*
|
|
82
|
+
* Any property accessed on `tags` returns a factory function that prepends the
|
|
83
|
+
* tag name to its arguments, producing an array suitable for {@link render}.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* const { div, span } = tags;
|
|
87
|
+
* render(div({ class: "box" }, span("Hello")))
|
|
88
|
+
* // equivalent to: render(["div", { class: "box" }, ["span", "Hello"]])
|
|
89
|
+
*/
|
|
90
|
+
export const tags: {};
|
|
91
|
+
declare function _lst(elems: any): void;
|
|
92
|
+
declare class _lst {
|
|
93
|
+
constructor(elems: any);
|
|
94
|
+
_elems: any;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Creates a reactive reference (`DataRef`).
|
|
98
|
+
*
|
|
99
|
+
* - **Single argument** — wraps a plain value in a new reactive cell.
|
|
100
|
+
* - **Two arguments** — creates a reactive view over `obj[property]`.
|
|
101
|
+
* Reads and writes go directly to the object property.
|
|
102
|
+
*
|
|
103
|
+
* @param {*|object} obj - A plain value, or an object to bind to.
|
|
104
|
+
* @param {string} [property] - Property name on `obj` to bind to.
|
|
105
|
+
* @returns {DataRef}
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* const count = ref(0);
|
|
109
|
+
* count.set(1);
|
|
110
|
+
* count.get(); // 1
|
|
111
|
+
*
|
|
112
|
+
* const user = { name: "Alice" };
|
|
113
|
+
* const nameRef = ref(user, "name");
|
|
114
|
+
* nameRef.set("Bob"); // user.name === "Bob"
|
|
115
|
+
*/
|
|
116
|
+
export function ref(obj: any | object, property?: string): DataRef;
|
|
117
|
+
/**
|
|
118
|
+
* Creates a watcher that fires whenever any of the given reactive refs change.
|
|
119
|
+
*
|
|
120
|
+
* The returned `RefWatcher` tears down its source subscriptions automatically
|
|
121
|
+
* when its last subscriber unsubscribes, avoiding memory leaks.
|
|
122
|
+
*
|
|
123
|
+
* Pass the result as the `watch` attribute inside a tagged array to make an
|
|
124
|
+
* element re-render reactively when the watched refs change.
|
|
125
|
+
*
|
|
126
|
+
* @param {...Watchable} refs - One or more `DataRef` or `Computed` instances.
|
|
127
|
+
* @returns {RefWatcher}
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* const a = ref(1);
|
|
131
|
+
* const b = ref(2);
|
|
132
|
+
* render(["span", { watch: [a, b] }, () => `${a.get()} + ${b.get()}`])
|
|
133
|
+
*/
|
|
134
|
+
export function watch(...refs: Watchable[]): RefWatcher;
|
|
135
|
+
/**
|
|
136
|
+
* Creates a computed reactive value derived from one or more source refs.
|
|
137
|
+
*
|
|
138
|
+
* `fn` is evaluated lazily — only when `.get()` is called or when a subscriber
|
|
139
|
+
* is attached. Source subscriptions are wired up on first subscriber and torn
|
|
140
|
+
* down automatically when the last subscriber unsubscribes.
|
|
141
|
+
*
|
|
142
|
+
* @param {() => *} fn - Pure function that computes the derived value.
|
|
143
|
+
* @param {...Watchable} sources - Reactive sources that `fn` depends on.
|
|
144
|
+
* @returns {Computed}
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* const a = ref(2);
|
|
148
|
+
* const b = ref(3);
|
|
149
|
+
* const sum = computed(() => a.get() + b.get(), a, b);
|
|
150
|
+
* sum.get(); // 5
|
|
151
|
+
* a.set(10);
|
|
152
|
+
* sum.get(); // 13
|
|
153
|
+
*/
|
|
154
|
+
export function computed(fn: () => any, ...sources: Watchable[]): Computed;
|
|
155
|
+
declare class Watchable {
|
|
156
|
+
_listeners: any[];
|
|
157
|
+
/**
|
|
158
|
+
* Get the current value.
|
|
159
|
+
*
|
|
160
|
+
* Subclasses are expected to override this.
|
|
161
|
+
*
|
|
162
|
+
* @returns {*}
|
|
163
|
+
*/
|
|
164
|
+
get(): any;
|
|
165
|
+
_notify(v: any): void;
|
|
166
|
+
notify(): void;
|
|
167
|
+
subscribe(f: any): () => void;
|
|
168
|
+
}
|
|
169
|
+
declare class DataRef extends Watchable {
|
|
170
|
+
constructor({ r, w }: {
|
|
171
|
+
r: any;
|
|
172
|
+
w: any;
|
|
173
|
+
});
|
|
174
|
+
_reader: any;
|
|
175
|
+
_writer: any;
|
|
176
|
+
set(v: any): void;
|
|
177
|
+
orElse(v: any): any;
|
|
178
|
+
orElseGet(f: any): any;
|
|
179
|
+
toString(): any;
|
|
180
|
+
}
|
|
181
|
+
declare class RefWatcher extends Watchable {
|
|
182
|
+
constructor(refs: any);
|
|
183
|
+
_unsubs: any;
|
|
184
|
+
}
|
|
185
|
+
declare class Computed extends Watchable {
|
|
186
|
+
constructor(fn: any, sources: any);
|
|
187
|
+
_fn: any;
|
|
188
|
+
_sources: any;
|
|
189
|
+
_unsubs: any[];
|
|
190
|
+
orElse(v: any): any;
|
|
191
|
+
orElseGet(f: any): any;
|
|
192
|
+
toString(): any;
|
|
193
|
+
}
|
|
194
|
+
export function text(source: Watchable): {
|
|
195
|
+
__condaReactiveText: Watchable;
|
|
196
|
+
};
|
|
197
|
+
export function property(source: Watchable): {
|
|
198
|
+
__condaReactiveProperty: Watchable;
|
|
199
|
+
};
|
|
200
|
+
export function attribute(source: Watchable): {
|
|
201
|
+
__condaReactiveAttribute: Watchable;
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Short reactive DOM-binding API.
|
|
205
|
+
*
|
|
206
|
+
* Each method accepts either a ready Watchable or a Watchable plus a selector.
|
|
207
|
+
* The selector form derives the target value from the source without requiring
|
|
208
|
+
* callers to construct an intermediate `computed` value.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* rx.text(todo, (item) => item.label)
|
|
212
|
+
* rx.prop(todo, (item) => item.done)
|
|
213
|
+
* rx.attr(todo, (item) => item.invalid ? "true" : "false")
|
|
214
|
+
*/
|
|
215
|
+
export const rx: Readonly<{
|
|
216
|
+
/**
|
|
217
|
+
* @param {import('./conda-watchable.js').Watchable} source
|
|
218
|
+
* @param {(value: any) => any} [selector]
|
|
219
|
+
*/
|
|
220
|
+
text: (source: Watchable, selector?: (value: any) => any) => {
|
|
221
|
+
__condaReactiveText: Watchable;
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* @param {import('./conda-watchable.js').Watchable} source
|
|
225
|
+
* @param {(value: any) => any} [selector]
|
|
226
|
+
*/
|
|
227
|
+
prop: (source: Watchable, selector?: (value: any) => any) => {
|
|
228
|
+
__condaReactiveProperty: Watchable;
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* @param {import('./conda-watchable.js').Watchable} source
|
|
232
|
+
* @param {(value: any) => any} [selector]
|
|
233
|
+
*/
|
|
234
|
+
attr: (source: Watchable, selector?: (value: any) => any) => {
|
|
235
|
+
__condaReactiveAttribute: Watchable;
|
|
236
|
+
};
|
|
237
|
+
}>;
|
|
238
|
+
/**
|
|
239
|
+
* Creates a self-contained lazy page loader for a route.
|
|
240
|
+
*
|
|
241
|
+
* Returns a SYNC function. When called it immediately returns a container
|
|
242
|
+
* element (so the Router and the DOM get something to display right away),
|
|
243
|
+
* then fills it in once the dynamic import settles.
|
|
244
|
+
*
|
|
245
|
+
* Stale-navigation safety comes for free: if the user navigates away before
|
|
246
|
+
* the import finishes, the Router replaces the container in the DOM. When the
|
|
247
|
+
* import eventually resolves it updates the now-detached container — a silent
|
|
248
|
+
* no-op that never touches the live page.
|
|
249
|
+
*
|
|
250
|
+
* @param {() => Promise} importFn - e.g. () => import('./pages/one.js')
|
|
251
|
+
* @param {object} [options]
|
|
252
|
+
* @param {() => Element} [options.loading] - shown immediately while the import is in flight
|
|
253
|
+
* @param {(err: Error) => Element} [options.error] - shown if the import or page factory fails
|
|
254
|
+
* @param {(mod) => Element} [options.getPage] - pull the page out of the module
|
|
255
|
+
* (default: calls mod.default())
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* // default export: export default function() { return render(...) }
|
|
259
|
+
* { path: "/one", page: lazy(() => import('./pages/one.js')) }
|
|
260
|
+
*
|
|
261
|
+
* // with loading + error states:
|
|
262
|
+
* { path: "/two", page: lazy(() => import('./pages/two.js'), {
|
|
263
|
+
* loading: () => render(['div', 'Loading…']),
|
|
264
|
+
* error: (err) => render(['div', `Failed: ${err.message}`]),
|
|
265
|
+
* }) }
|
|
266
|
+
*
|
|
267
|
+
* // named export:
|
|
268
|
+
* { path: "/three", page: lazy(() => import('./pages/three.js'), {
|
|
269
|
+
* getPage: (mod) => mod.ThreePage(),
|
|
270
|
+
* }) }
|
|
271
|
+
*/
|
|
272
|
+
export function lazy(importFn: () => Promise<any>, { loading, error, getPage }?: {
|
|
273
|
+
loading?: () => Element;
|
|
274
|
+
error?: (err: Error) => Element;
|
|
275
|
+
getPage?: (mod: any) => Element;
|
|
276
|
+
}): () => HTMLDivElement;
|
|
277
|
+
export type RouterOptions = {
|
|
278
|
+
/**
|
|
279
|
+
* Called when an async `page()` rejects. Return an Element to display as the
|
|
280
|
+
* error state. If omitted, errors are logged to `console.error`.
|
|
281
|
+
*/
|
|
282
|
+
onError?: (err: Error, path: string) => Element;
|
|
283
|
+
/**
|
|
284
|
+
* Called when no route matches the current path. Return an Element to display
|
|
285
|
+
* as the 404 state. If omitted, a default fallback message is shown.
|
|
286
|
+
*/
|
|
287
|
+
notFound?: (path: string) => Element;
|
|
288
|
+
};
|
|
289
|
+
/**
|
|
290
|
+
* @typedef {object} RouterOptions
|
|
291
|
+
* @property {(err: Error, path: string) => Element} [onError]
|
|
292
|
+
* Called when an async `page()` rejects. Return an Element to display as the
|
|
293
|
+
* error state. If omitted, errors are logged to `console.error`.
|
|
294
|
+
* @property {(path: string) => Element} [notFound]
|
|
295
|
+
* Called when no route matches the current path. Return an Element to display
|
|
296
|
+
* as the 404 state. If omitted, a default fallback message is shown.
|
|
297
|
+
*/
|
|
298
|
+
/**
|
|
299
|
+
* Hash-based SPA router.
|
|
300
|
+
*
|
|
301
|
+
* Reads `window.location.hash` on construction and on every `hashchange` event.
|
|
302
|
+
* Converts the hash to a path by replacing `"#"` with `"/"`, so `href="#about"`
|
|
303
|
+
* maps to route path `"/about"`, and an empty hash maps to `"/"`.
|
|
304
|
+
*
|
|
305
|
+
* Each navigation is assigned an incrementing ID. If an async `page()` resolves
|
|
306
|
+
* after the user has already navigated away, its result is silently discarded
|
|
307
|
+
* (stale-navigation safety).
|
|
308
|
+
*
|
|
309
|
+
* @param {Element} targetEl
|
|
310
|
+
* DOM element where matched pages are rendered.
|
|
311
|
+
* @param {Array<{path: string, page: () => Element | Promise<Element>}>} routes
|
|
312
|
+
* Array of route definitions. Each `page` function may be sync or async.
|
|
313
|
+
* Use {@link lazy} for dynamic-import routes with built-in loading/error states.
|
|
314
|
+
* @param {RouterOptions} [options]
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* new Router(document.getElementById("app"), [
|
|
318
|
+
* { path: "/", page: () => render(HomePage()) },
|
|
319
|
+
* { path: "/about", page: lazy(() => import("./pages/about.js")) },
|
|
320
|
+
* ], {
|
|
321
|
+
* onError: (err, path) => render(["div", `Error on ${path}: ${err.message}`]),
|
|
322
|
+
* notFound: (path) => render(["div", `404: ${path} was not found`]),
|
|
323
|
+
* });
|
|
324
|
+
*/
|
|
325
|
+
export function Router(targetEl: Element, routes: Array<{
|
|
326
|
+
path: string;
|
|
327
|
+
page: () => Element | Promise<Element>;
|
|
328
|
+
}>, options?: RouterOptions): void;
|
|
329
|
+
/**
|
|
330
|
+
* Recursively release Casconda-managed resources and detach a rendered node.
|
|
331
|
+
* Safe to call more than once, including after the node is already detached.
|
|
332
|
+
*
|
|
333
|
+
* @param {Node} node
|
|
334
|
+
* @returns {void}
|
|
335
|
+
*/
|
|
336
|
+
export function destroy(node: Node): void;
|
|
337
|
+
|
|
338
|
+
export as namespace casconda;
|
|
339
|
+
|
|
340
|
+
export {};
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
export namespace d {
|
|
4
|
+
export function arr(): (val: any) => val is any[];
|
|
5
|
+
export function map(): (val: any) => val is Map<any, any>;
|
|
6
|
+
export function any(): () => boolean;
|
|
7
|
+
export function func(): (val: any) => boolean;
|
|
8
|
+
export function num(): (val: any) => boolean;
|
|
9
|
+
export function str(): (val: any) => boolean;
|
|
10
|
+
export function bool(): (val: any) => boolean;
|
|
11
|
+
export function bigint(): (val: any) => boolean;
|
|
12
|
+
export function sym(): (val: any) => boolean;
|
|
13
|
+
export function undef(): (val: any) => boolean;
|
|
14
|
+
export function obj(): (val: any) => boolean;
|
|
15
|
+
export function nil(matcher: any): (val: any) => boolean;
|
|
16
|
+
export function notNil(matcher: any): (val: any) => boolean;
|
|
17
|
+
export { dispatch as dispatch };
|
|
18
|
+
export { varg as varg };
|
|
19
|
+
export function eq(val: any): (v: any) => boolean;
|
|
20
|
+
export { or };
|
|
21
|
+
export { and };
|
|
22
|
+
export { not };
|
|
23
|
+
export { instOf };
|
|
24
|
+
}
|
|
25
|
+
declare function dispatch(...fns: any[]): (...args: any[]) => any;
|
|
26
|
+
declare function varg(pred: any): ((argList: any) => any) & {
|
|
27
|
+
__isVarg: boolean;
|
|
28
|
+
};
|
|
29
|
+
declare function or(...fns: any[]): (val: any) => boolean;
|
|
30
|
+
declare function and(...fns: any[]): (val: any) => boolean;
|
|
31
|
+
declare function not(fn: any): (val: any) => boolean;
|
|
32
|
+
declare function instOf(type: any): (val: any) => boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Creates an independently configured Casconda renderer.
|
|
35
|
+
*
|
|
36
|
+
* Binding defaults are scoped to the returned instance. Explicit binding
|
|
37
|
+
* options such as `{ ref, event }` override the matching instance default.
|
|
38
|
+
*
|
|
39
|
+
* @param {{bindings?: {text?: {event?: string}, checkbox?: {event?: string}, radio?: {event?: string}}}} [options]
|
|
40
|
+
* @returns {{render: (...args: any[]) => any}}
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* const form = createCasconda({
|
|
44
|
+
* bindings: { text: { event: "blur" } },
|
|
45
|
+
* });
|
|
46
|
+
* form.render(["input", { bind: myRef }]);
|
|
47
|
+
*/
|
|
48
|
+
export function createCasconda(options?: {
|
|
49
|
+
bindings?: {
|
|
50
|
+
text?: {
|
|
51
|
+
event?: string;
|
|
52
|
+
};
|
|
53
|
+
checkbox?: {
|
|
54
|
+
event?: string;
|
|
55
|
+
};
|
|
56
|
+
radio?: {
|
|
57
|
+
event?: string;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
}): {
|
|
61
|
+
render: (...args: any[]) => any;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Wraps an array of elements so that `render()` can unambiguously treat it as
|
|
65
|
+
* a children list rather than an attribute object.
|
|
66
|
+
*
|
|
67
|
+
* Useful when you have a dynamically-built array of children to pass to a tag
|
|
68
|
+
* factory that would otherwise interpret a plain array as attributes.
|
|
69
|
+
*
|
|
70
|
+
* @param {Array} elems - Array of child nodes or tagged arrays.
|
|
71
|
+
* @returns {_lst}
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* const items = ["a", "b", "c"];
|
|
75
|
+
* render(["ul", lst(items.map(i => ["li", i]))])
|
|
76
|
+
*/
|
|
77
|
+
export function lst(elems: any[]): _lst;
|
|
78
|
+
export const render: (...args: any[]) => any;
|
|
79
|
+
/**
|
|
80
|
+
* Proxy that generates tagged arrays via property access.
|
|
81
|
+
*
|
|
82
|
+
* Any property accessed on `tags` returns a factory function that prepends the
|
|
83
|
+
* tag name to its arguments, producing an array suitable for {@link render}.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* const { div, span } = tags;
|
|
87
|
+
* render(div({ class: "box" }, span("Hello")))
|
|
88
|
+
* // equivalent to: render(["div", { class: "box" }, ["span", "Hello"]])
|
|
89
|
+
*/
|
|
90
|
+
export const tags: {};
|
|
91
|
+
declare function _lst(elems: any): void;
|
|
92
|
+
declare class _lst {
|
|
93
|
+
constructor(elems: any);
|
|
94
|
+
_elems: any;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Creates a reactive reference (`DataRef`).
|
|
98
|
+
*
|
|
99
|
+
* - **Single argument** — wraps a plain value in a new reactive cell.
|
|
100
|
+
* - **Two arguments** — creates a reactive view over `obj[property]`.
|
|
101
|
+
* Reads and writes go directly to the object property.
|
|
102
|
+
*
|
|
103
|
+
* @param {*|object} obj - A plain value, or an object to bind to.
|
|
104
|
+
* @param {string} [property] - Property name on `obj` to bind to.
|
|
105
|
+
* @returns {DataRef}
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* const count = ref(0);
|
|
109
|
+
* count.set(1);
|
|
110
|
+
* count.get(); // 1
|
|
111
|
+
*
|
|
112
|
+
* const user = { name: "Alice" };
|
|
113
|
+
* const nameRef = ref(user, "name");
|
|
114
|
+
* nameRef.set("Bob"); // user.name === "Bob"
|
|
115
|
+
*/
|
|
116
|
+
export function ref(obj: any | object, property?: string): DataRef;
|
|
117
|
+
/**
|
|
118
|
+
* Creates a watcher that fires whenever any of the given reactive refs change.
|
|
119
|
+
*
|
|
120
|
+
* The returned `RefWatcher` tears down its source subscriptions automatically
|
|
121
|
+
* when its last subscriber unsubscribes, avoiding memory leaks.
|
|
122
|
+
*
|
|
123
|
+
* Pass the result as the `watch` attribute inside a tagged array to make an
|
|
124
|
+
* element re-render reactively when the watched refs change.
|
|
125
|
+
*
|
|
126
|
+
* @param {...Watchable} refs - One or more `DataRef` or `Computed` instances.
|
|
127
|
+
* @returns {RefWatcher}
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* const a = ref(1);
|
|
131
|
+
* const b = ref(2);
|
|
132
|
+
* render(["span", { watch: [a, b] }, () => `${a.get()} + ${b.get()}`])
|
|
133
|
+
*/
|
|
134
|
+
export function watch(...refs: Watchable[]): RefWatcher;
|
|
135
|
+
/**
|
|
136
|
+
* Creates a computed reactive value derived from one or more source refs.
|
|
137
|
+
*
|
|
138
|
+
* `fn` is evaluated lazily — only when `.get()` is called or when a subscriber
|
|
139
|
+
* is attached. Source subscriptions are wired up on first subscriber and torn
|
|
140
|
+
* down automatically when the last subscriber unsubscribes.
|
|
141
|
+
*
|
|
142
|
+
* @param {() => *} fn - Pure function that computes the derived value.
|
|
143
|
+
* @param {...Watchable} sources - Reactive sources that `fn` depends on.
|
|
144
|
+
* @returns {Computed}
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* const a = ref(2);
|
|
148
|
+
* const b = ref(3);
|
|
149
|
+
* const sum = computed(() => a.get() + b.get(), a, b);
|
|
150
|
+
* sum.get(); // 5
|
|
151
|
+
* a.set(10);
|
|
152
|
+
* sum.get(); // 13
|
|
153
|
+
*/
|
|
154
|
+
export function computed(fn: () => any, ...sources: Watchable[]): Computed;
|
|
155
|
+
declare class Watchable {
|
|
156
|
+
_listeners: any[];
|
|
157
|
+
/**
|
|
158
|
+
* Get the current value.
|
|
159
|
+
*
|
|
160
|
+
* Subclasses are expected to override this.
|
|
161
|
+
*
|
|
162
|
+
* @returns {*}
|
|
163
|
+
*/
|
|
164
|
+
get(): any;
|
|
165
|
+
_notify(v: any): void;
|
|
166
|
+
notify(): void;
|
|
167
|
+
subscribe(f: any): () => void;
|
|
168
|
+
}
|
|
169
|
+
declare class DataRef extends Watchable {
|
|
170
|
+
constructor({ r, w }: {
|
|
171
|
+
r: any;
|
|
172
|
+
w: any;
|
|
173
|
+
});
|
|
174
|
+
_reader: any;
|
|
175
|
+
_writer: any;
|
|
176
|
+
set(v: any): void;
|
|
177
|
+
orElse(v: any): any;
|
|
178
|
+
orElseGet(f: any): any;
|
|
179
|
+
toString(): any;
|
|
180
|
+
}
|
|
181
|
+
declare class RefWatcher extends Watchable {
|
|
182
|
+
constructor(refs: any);
|
|
183
|
+
_unsubs: any;
|
|
184
|
+
}
|
|
185
|
+
declare class Computed extends Watchable {
|
|
186
|
+
constructor(fn: any, sources: any);
|
|
187
|
+
_fn: any;
|
|
188
|
+
_sources: any;
|
|
189
|
+
_unsubs: any[];
|
|
190
|
+
orElse(v: any): any;
|
|
191
|
+
orElseGet(f: any): any;
|
|
192
|
+
toString(): any;
|
|
193
|
+
}
|
|
194
|
+
export function text(source: Watchable): {
|
|
195
|
+
__condaReactiveText: Watchable;
|
|
196
|
+
};
|
|
197
|
+
export function property(source: Watchable): {
|
|
198
|
+
__condaReactiveProperty: Watchable;
|
|
199
|
+
};
|
|
200
|
+
export function attribute(source: Watchable): {
|
|
201
|
+
__condaReactiveAttribute: Watchable;
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Short reactive DOM-binding API.
|
|
205
|
+
*
|
|
206
|
+
* Each method accepts either a ready Watchable or a Watchable plus a selector.
|
|
207
|
+
* The selector form derives the target value from the source without requiring
|
|
208
|
+
* callers to construct an intermediate `computed` value.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* rx.text(todo, (item) => item.label)
|
|
212
|
+
* rx.prop(todo, (item) => item.done)
|
|
213
|
+
* rx.attr(todo, (item) => item.invalid ? "true" : "false")
|
|
214
|
+
*/
|
|
215
|
+
export const rx: Readonly<{
|
|
216
|
+
/**
|
|
217
|
+
* @param {import('./conda-watchable.js').Watchable} source
|
|
218
|
+
* @param {(value: any) => any} [selector]
|
|
219
|
+
*/
|
|
220
|
+
text: (source: Watchable, selector?: (value: any) => any) => {
|
|
221
|
+
__condaReactiveText: Watchable;
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* @param {import('./conda-watchable.js').Watchable} source
|
|
225
|
+
* @param {(value: any) => any} [selector]
|
|
226
|
+
*/
|
|
227
|
+
prop: (source: Watchable, selector?: (value: any) => any) => {
|
|
228
|
+
__condaReactiveProperty: Watchable;
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* @param {import('./conda-watchable.js').Watchable} source
|
|
232
|
+
* @param {(value: any) => any} [selector]
|
|
233
|
+
*/
|
|
234
|
+
attr: (source: Watchable, selector?: (value: any) => any) => {
|
|
235
|
+
__condaReactiveAttribute: Watchable;
|
|
236
|
+
};
|
|
237
|
+
}>;
|
|
238
|
+
/**
|
|
239
|
+
* Creates a self-contained lazy page loader for a route.
|
|
240
|
+
*
|
|
241
|
+
* Returns a SYNC function. When called it immediately returns a container
|
|
242
|
+
* element (so the Router and the DOM get something to display right away),
|
|
243
|
+
* then fills it in once the dynamic import settles.
|
|
244
|
+
*
|
|
245
|
+
* Stale-navigation safety comes for free: if the user navigates away before
|
|
246
|
+
* the import finishes, the Router replaces the container in the DOM. When the
|
|
247
|
+
* import eventually resolves it updates the now-detached container — a silent
|
|
248
|
+
* no-op that never touches the live page.
|
|
249
|
+
*
|
|
250
|
+
* @param {() => Promise} importFn - e.g. () => import('./pages/one.js')
|
|
251
|
+
* @param {object} [options]
|
|
252
|
+
* @param {() => Element} [options.loading] - shown immediately while the import is in flight
|
|
253
|
+
* @param {(err: Error) => Element} [options.error] - shown if the import or page factory fails
|
|
254
|
+
* @param {(mod) => Element} [options.getPage] - pull the page out of the module
|
|
255
|
+
* (default: calls mod.default())
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* // default export: export default function() { return render(...) }
|
|
259
|
+
* { path: "/one", page: lazy(() => import('./pages/one.js')) }
|
|
260
|
+
*
|
|
261
|
+
* // with loading + error states:
|
|
262
|
+
* { path: "/two", page: lazy(() => import('./pages/two.js'), {
|
|
263
|
+
* loading: () => render(['div', 'Loading…']),
|
|
264
|
+
* error: (err) => render(['div', `Failed: ${err.message}`]),
|
|
265
|
+
* }) }
|
|
266
|
+
*
|
|
267
|
+
* // named export:
|
|
268
|
+
* { path: "/three", page: lazy(() => import('./pages/three.js'), {
|
|
269
|
+
* getPage: (mod) => mod.ThreePage(),
|
|
270
|
+
* }) }
|
|
271
|
+
*/
|
|
272
|
+
export function lazy(importFn: () => Promise<any>, { loading, error, getPage }?: {
|
|
273
|
+
loading?: () => Element;
|
|
274
|
+
error?: (err: Error) => Element;
|
|
275
|
+
getPage?: (mod: any) => Element;
|
|
276
|
+
}): () => HTMLDivElement;
|
|
277
|
+
export type RouterOptions = {
|
|
278
|
+
/**
|
|
279
|
+
* Called when an async `page()` rejects. Return an Element to display as the
|
|
280
|
+
* error state. If omitted, errors are logged to `console.error`.
|
|
281
|
+
*/
|
|
282
|
+
onError?: (err: Error, path: string) => Element;
|
|
283
|
+
/**
|
|
284
|
+
* Called when no route matches the current path. Return an Element to display
|
|
285
|
+
* as the 404 state. If omitted, a default fallback message is shown.
|
|
286
|
+
*/
|
|
287
|
+
notFound?: (path: string) => Element;
|
|
288
|
+
};
|
|
289
|
+
/**
|
|
290
|
+
* @typedef {object} RouterOptions
|
|
291
|
+
* @property {(err: Error, path: string) => Element} [onError]
|
|
292
|
+
* Called when an async `page()` rejects. Return an Element to display as the
|
|
293
|
+
* error state. If omitted, errors are logged to `console.error`.
|
|
294
|
+
* @property {(path: string) => Element} [notFound]
|
|
295
|
+
* Called when no route matches the current path. Return an Element to display
|
|
296
|
+
* as the 404 state. If omitted, a default fallback message is shown.
|
|
297
|
+
*/
|
|
298
|
+
/**
|
|
299
|
+
* Hash-based SPA router.
|
|
300
|
+
*
|
|
301
|
+
* Reads `window.location.hash` on construction and on every `hashchange` event.
|
|
302
|
+
* Converts the hash to a path by replacing `"#"` with `"/"`, so `href="#about"`
|
|
303
|
+
* maps to route path `"/about"`, and an empty hash maps to `"/"`.
|
|
304
|
+
*
|
|
305
|
+
* Each navigation is assigned an incrementing ID. If an async `page()` resolves
|
|
306
|
+
* after the user has already navigated away, its result is silently discarded
|
|
307
|
+
* (stale-navigation safety).
|
|
308
|
+
*
|
|
309
|
+
* @param {Element} targetEl
|
|
310
|
+
* DOM element where matched pages are rendered.
|
|
311
|
+
* @param {Array<{path: string, page: () => Element | Promise<Element>}>} routes
|
|
312
|
+
* Array of route definitions. Each `page` function may be sync or async.
|
|
313
|
+
* Use {@link lazy} for dynamic-import routes with built-in loading/error states.
|
|
314
|
+
* @param {RouterOptions} [options]
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* new Router(document.getElementById("app"), [
|
|
318
|
+
* { path: "/", page: () => render(HomePage()) },
|
|
319
|
+
* { path: "/about", page: lazy(() => import("./pages/about.js")) },
|
|
320
|
+
* ], {
|
|
321
|
+
* onError: (err, path) => render(["div", `Error on ${path}: ${err.message}`]),
|
|
322
|
+
* notFound: (path) => render(["div", `404: ${path} was not found`]),
|
|
323
|
+
* });
|
|
324
|
+
*/
|
|
325
|
+
export function Router(targetEl: Element, routes: Array<{
|
|
326
|
+
path: string;
|
|
327
|
+
page: () => Element | Promise<Element>;
|
|
328
|
+
}>, options?: RouterOptions): void;
|
|
329
|
+
/**
|
|
330
|
+
* Recursively release Casconda-managed resources and detach a rendered node.
|
|
331
|
+
* Safe to call more than once, including after the node is already detached.
|
|
332
|
+
*
|
|
333
|
+
* @param {Node} node
|
|
334
|
+
* @returns {void}
|
|
335
|
+
*/
|
|
336
|
+
export function destroy(node: Node): void;
|
|
337
|
+
|
|
338
|
+
export as namespace casconda;
|
|
339
|
+
|
|
340
|
+
export {};
|