@manyducks.co/dolla 2.0.0-alpha.21 → 2.0.0-alpha.23

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 (43) hide show
  1. package/dist/{modules/render.d.ts → core/batch.d.ts} +4 -1
  2. package/dist/{modules → core}/dolla.d.ts +25 -9
  3. package/dist/{markup.d.ts → core/markup.d.ts} +6 -6
  4. package/dist/{nodes → core/nodes}/cond.d.ts +4 -2
  5. package/dist/{nodes → core/nodes}/html.d.ts +2 -0
  6. package/dist/{nodes → core/nodes}/observer.d.ts +4 -1
  7. package/dist/core/nodes/outlet.d.ts +18 -0
  8. package/dist/{nodes → core/nodes}/portal.d.ts +4 -2
  9. package/dist/{nodes → core/nodes}/repeat.d.ts +5 -3
  10. package/dist/{nodes → core/nodes}/text.d.ts +2 -0
  11. package/dist/{view.d.ts → core/nodes/view.d.ts} +8 -6
  12. package/dist/{state.d.ts → core/state.d.ts} +3 -4
  13. package/dist/core/symbols.d.ts +5 -0
  14. package/dist/index.d.ts +9 -8
  15. package/dist/index.js +670 -1038
  16. package/dist/index.js.map +1 -1
  17. package/dist/jsx-dev-runtime.d.ts +2 -2
  18. package/dist/jsx-dev-runtime.js +2 -2
  19. package/dist/jsx-dev-runtime.js.map +1 -1
  20. package/dist/jsx-runtime.d.ts +3 -3
  21. package/dist/jsx-runtime.js +2 -2
  22. package/dist/jsx-runtime.js.map +1 -1
  23. package/dist/modules/http.d.ts +2 -0
  24. package/dist/modules/i18n.d.ts +2 -2
  25. package/dist/modules/router.d.ts +27 -48
  26. package/dist/{passthrough-6Lrg96Id.js → passthrough-C9975ULD.js} +636 -576
  27. package/dist/passthrough-C9975ULD.js.map +1 -0
  28. package/dist/typeChecking.d.ts +2 -2
  29. package/dist/types.d.ts +2 -2
  30. package/dist/utils.d.ts +14 -1
  31. package/dist/views/default-crash-view.d.ts +1 -1
  32. package/dist/views/passthrough.d.ts +2 -2
  33. package/docs/http.md +16 -0
  34. package/docs/router.md +19 -0
  35. package/index.d.ts +2 -2
  36. package/notes/TODO.md +6 -0
  37. package/notes/scratch.md +2 -2
  38. package/package.json +3 -6
  39. package/vite.config.js +0 -10
  40. package/dist/nodes/outlet.d.ts +0 -22
  41. package/dist/passthrough-6Lrg96Id.js.map +0 -1
  42. /package/dist/{routing.d.ts → modules/router.utils.d.ts} +0 -0
  43. /package/dist/{routing.test.d.ts → modules/router.utils.test.d.ts} +0 -0
@@ -1,5 +1,8 @@
1
1
  import type { Dolla } from "./dolla.js";
2
- export declare class Render {
2
+ /**
3
+ * Batches DOM updates; reads before writes.
4
+ */
5
+ export declare class Batch {
3
6
  #private;
4
7
  constructor(dolla: Dolla);
5
8
  /**
@@ -1,11 +1,11 @@
1
- import { type Markup, type MarkupElement } from "../markup.js";
2
- import { createRef, createSettableState, createState, createWatcher, derive, isRef, toSettableState, toState, valueOf } from "../state.js";
3
- import { type ViewElement, type ViewFunction } from "../view.js";
4
1
  import { type CrashViewProps } from "../views/default-crash-view.js";
5
- import { HTTP } from "./http.js";
6
- import { I18n } from "./i18n.js";
7
- import { Render } from "./render.js";
8
- import { Router } from "./router.js";
2
+ import { Batch } from "./batch.js";
3
+ import { type Markup, type MarkupElement } from "./markup.js";
4
+ import { type ViewElement, type ViewFunction } from "./nodes/view.js";
5
+ import { createRef, createSettableState, createState, createWatcher, derive, isRef, toSettableState, toState, valueOf } from "./state.js";
6
+ import { HTTP } from "../modules/http.js";
7
+ import { I18n } from "../modules/i18n.js";
8
+ import { Router } from "../modules/router.js";
9
9
  export type Environment = "development" | "production";
10
10
  /**
11
11
  * Log type toggles. Each message category can be turned on or off or enabled only in a specific environment.
@@ -39,14 +39,18 @@ export type LoggerOptions = {
39
39
  */
40
40
  uid?: string;
41
41
  };
42
+ export interface DollaModuleConfig<Options = never> {
43
+ root: Dolla;
44
+ options: Options;
45
+ }
42
46
  export declare class Dolla {
43
47
  #private;
48
+ readonly batch: Batch;
44
49
  readonly http: HTTP;
45
50
  readonly i18n: I18n;
46
- readonly render: Render;
47
51
  readonly router: Router;
48
52
  constructor();
49
- watch: <I extends import("../state.js").MaybeState<any>[]>(states: [...I], fn: (...currentValues: import("../state.js").StateValues<I>) => void) => import("../state.js").StopFunction;
53
+ watch: <I extends import("./state.js").MaybeState<any>[]>(states: [...I], fn: (...currentValues: import("./state.js").StateValues<I>) => void) => import("./state.js").StopFunction;
50
54
  createState: typeof createState;
51
55
  createSettableState: typeof createSettableState;
52
56
  toSettableState: typeof toSettableState;
@@ -75,6 +79,17 @@ export declare class Dolla {
75
79
  * When a crash is reported the app will be unmounted and replaced with this crash page.
76
80
  */
77
81
  setCrashView(view: ViewFunction<CrashViewProps>): void;
82
+ /**
83
+ * Returns the HTMLElement Dolla is mounted to. This will return undefined until Dolla.mount() is called.
84
+ */
85
+ getRootElement(): HTMLElement | undefined;
86
+ /**
87
+ * Returns the top level view Dolla is rendering inside the root element. This will return undefined until Dolla.mount() is called.
88
+ */
89
+ getRootView(): ViewElement | undefined;
90
+ /**
91
+ * Registers a Dolla module.
92
+ */
78
93
  /**
79
94
  * Sets a context variable and returns its value. Context variables are accessible on the app and in child views.
80
95
  */
@@ -123,3 +138,4 @@ export declare class Dolla {
123
138
  */
124
139
  constructMarkup(markup: Markup | Markup[]): MarkupElement;
125
140
  }
141
+ export declare function getDefaultConsole(): any;
@@ -1,7 +1,7 @@
1
- import type { Dolla } from "./modules/dolla.js";
1
+ import type { Renderable, Stringable } from "../types.js";
2
+ import type { Dolla } from "./dolla.js";
3
+ import { type ViewContext, type ViewFunction, type ViewResult } from "./nodes/view.js";
2
4
  import { MaybeState, type State } from "./state.js";
3
- import type { Renderable, Stringable } from "./types.js";
4
- import { type ViewContext, type ViewFunction, type ViewResult } from "./view.js";
5
5
  export interface ElementContext {
6
6
  /**
7
7
  * The root Dolla instance this element belongs to.
@@ -50,8 +50,8 @@ export interface MarkupElement {
50
50
  */
51
51
  unmount(parentIsUnmounting?: boolean): void;
52
52
  }
53
- export declare function isMarkup(value: unknown): value is Markup;
54
- export declare function isMarkupElement(value: unknown): value is MarkupElement;
53
+ export declare function isMarkup(value: any): value is Markup;
54
+ export declare function isMarkupElement(value: any): value is MarkupElement;
55
55
  export declare function toMarkup(renderables: Renderable | Renderable[]): Markup[];
56
56
  export interface MarkupAttributes {
57
57
  $text: {
@@ -109,5 +109,5 @@ export declare function constructMarkup(elementContext: ElementContext, markup:
109
109
  /**
110
110
  * Combines one or more MarkupElements into a single MarkupElement.
111
111
  */
112
- export declare function groupElements(nodes: MarkupElement[]): MarkupElement;
112
+ export declare function groupElements(elements: MarkupElement[]): MarkupElement;
113
113
  export declare function isRenderable(value: unknown): value is Renderable;
@@ -1,6 +1,7 @@
1
- import { type MarkupElement, type ElementContext, type Markup } from "../markup.js";
1
+ import { type Renderable } from "../../types.js";
2
+ import { type ElementContext, type Markup, type MarkupElement } from "../markup.js";
2
3
  import { type State, type StopFunction } from "../state.js";
3
- import { type Renderable } from "../types.js";
4
+ import { TYPE_MARKUP_ELEMENT } from "../symbols.js";
4
5
  export interface ConditionalConfig {
5
6
  $predicate: State<any>;
6
7
  thenContent?: Renderable;
@@ -8,6 +9,7 @@ export interface ConditionalConfig {
8
9
  elementContext: ElementContext;
9
10
  }
10
11
  export declare class Conditional implements MarkupElement {
12
+ [TYPE_MARKUP_ELEMENT]: boolean;
11
13
  node: Node;
12
14
  endNode: Node;
13
15
  $predicate: State<any>;
@@ -1,5 +1,6 @@
1
1
  import { type ElementContext, type Markup, type MarkupElement } from "../markup.js";
2
2
  import { type Ref, type State, type StopFunction } from "../state.js";
3
+ import { TYPE_MARKUP_ELEMENT } from "../symbols.js";
3
4
  type HTMLOptions = {
4
5
  elementContext: ElementContext;
5
6
  tag: string;
@@ -7,6 +8,7 @@ type HTMLOptions = {
7
8
  children?: Markup[];
8
9
  };
9
10
  export declare class HTML implements MarkupElement {
11
+ [TYPE_MARKUP_ELEMENT]: boolean;
10
12
  node: HTMLElement | SVGElement;
11
13
  props: Record<string, any>;
12
14
  children: MarkupElement[];
@@ -1,6 +1,7 @@
1
+ import type { Renderable } from "../../types.js";
1
2
  import { type ElementContext, type MarkupElement } from "../markup.js";
2
3
  import { type State } from "../state.js";
3
- import type { Renderable } from "../types.js";
4
+ import { TYPE_MARKUP_ELEMENT } from "../symbols.js";
4
5
  interface ObserverOptions {
5
6
  elementContext: ElementContext;
6
7
  states: State<any>[];
@@ -8,8 +9,10 @@ interface ObserverOptions {
8
9
  }
9
10
  /**
10
11
  * Displays dynamic children without a parent element.
12
+ * Used when a State is passed as a child in a view template.
11
13
  */
12
14
  export declare class Observer implements MarkupElement {
15
+ [TYPE_MARKUP_ELEMENT]: boolean;
13
16
  node: Node;
14
17
  endNode: Node;
15
18
  connectedViews: MarkupElement[];
@@ -0,0 +1,18 @@
1
+ import { type MarkupElement } from "../markup.js";
2
+ import { MaybeState, type StopFunction } from "../state.js";
3
+ import { TYPE_MARKUP_ELEMENT } from "../symbols.js";
4
+ /**
5
+ * Manages several MarkupElements as one.
6
+ */
7
+ export declare class Outlet implements MarkupElement {
8
+ [TYPE_MARKUP_ELEMENT]: boolean;
9
+ node: Text;
10
+ isMounted: boolean;
11
+ elements: MaybeState<MarkupElement[]>;
12
+ children: MarkupElement[];
13
+ stopCallback?: StopFunction;
14
+ constructor(elements: MaybeState<MarkupElement[]>);
15
+ mount(parent: Node, after?: Node | undefined): void;
16
+ unmount(parentIsUnmounting?: boolean): void;
17
+ update(newChildren: MarkupElement[]): void;
18
+ }
@@ -1,5 +1,6 @@
1
- import { type MarkupElement, type ElementContext } from "../markup.js";
2
- import { type Renderable } from "../types.js";
1
+ import { type Renderable } from "../../types.js";
2
+ import { type ElementContext, type MarkupElement } from "../markup.js";
3
+ import { TYPE_MARKUP_ELEMENT } from "../symbols.js";
3
4
  interface PortalConfig {
4
5
  content: Renderable;
5
6
  parent: Node;
@@ -9,6 +10,7 @@ interface PortalConfig {
9
10
  * Renders content into a specified parent node.
10
11
  */
11
12
  export declare class Portal implements MarkupElement {
13
+ [TYPE_MARKUP_ELEMENT]: boolean;
12
14
  config: PortalConfig;
13
15
  element?: MarkupElement;
14
16
  get isMounted(): boolean;
@@ -1,6 +1,7 @@
1
- import { type MarkupElement, type ElementContext } from "../markup.js";
2
- import { type State, type Setter, type StopFunction } from "../state.js";
3
- import { type ViewContext, type ViewResult } from "../view.js";
1
+ import { type ElementContext, type MarkupElement } from "../markup.js";
2
+ import { type Setter, type State, type StopFunction } from "../state.js";
3
+ import { TYPE_MARKUP_ELEMENT } from "../symbols.js";
4
+ import { type ViewContext, type ViewResult } from "./view.js";
4
5
  interface RepeatOptions<T> {
5
6
  elementContext: ElementContext;
6
7
  $items: State<T[]>;
@@ -16,6 +17,7 @@ type ConnectedItem<T> = {
16
17
  element: MarkupElement;
17
18
  };
18
19
  export declare class Repeat<T> implements MarkupElement {
20
+ [TYPE_MARKUP_ELEMENT]: boolean;
19
21
  node: Node;
20
22
  endNode: Node;
21
23
  $items: State<T[]>;
@@ -1,5 +1,6 @@
1
1
  import { type MarkupElement } from "../markup.js";
2
2
  import { type MaybeState, type StopFunction } from "../state.js";
3
+ import { TYPE_MARKUP_ELEMENT } from "../symbols.js";
3
4
  interface Stringable {
4
5
  toString(): string;
5
6
  }
@@ -7,6 +8,7 @@ interface TextOptions {
7
8
  value: MaybeState<Stringable>;
8
9
  }
9
10
  export declare class Text implements MarkupElement {
11
+ [TYPE_MARKUP_ELEMENT]: boolean;
10
12
  node: globalThis.Text;
11
13
  value: MaybeState<Stringable>;
12
14
  stopCallback?: StopFunction;
@@ -1,6 +1,7 @@
1
- import { type MarkupElement, type ElementContext, type Markup } from "./markup.js";
2
- import type { Logger } from "./modules/dolla.js";
3
- import { type MaybeState, Setter, State, type StateValues, type StopFunction } from "./state.js";
1
+ import type { Logger } from "../dolla.js";
2
+ import { type ElementContext, type Markup, type MarkupElement } from "../markup.js";
3
+ import { type MaybeState, type State, type StateValues, type StopFunction } from "../state.js";
4
+ import { TYPE_MARKUP_ELEMENT } from "../symbols.js";
4
5
  /**
5
6
  * Any valid value that a View can return.
6
7
  */
@@ -17,7 +18,7 @@ export interface ViewElement extends MarkupElement {
17
18
  }
18
19
  export interface ViewContext extends Logger {
19
20
  /**
20
- * A string ID unique to this view.
21
+ * An ID unique to this view.
21
22
  */
22
23
  readonly uid: string;
23
24
  /**
@@ -63,6 +64,7 @@ export interface ViewContext extends Logger {
63
64
  outlet(): Markup;
64
65
  }
65
66
  export declare class View<P> implements ViewElement {
67
+ [TYPE_MARKUP_ELEMENT]: boolean;
66
68
  uniqueId: string;
67
69
  _elementContext: ElementContext;
68
70
  _logger: Logger;
@@ -70,8 +72,8 @@ export declare class View<P> implements ViewElement {
70
72
  _props: P;
71
73
  _element?: MarkupElement;
72
74
  _$children: State<MarkupElement[]>;
73
- _setChildren: Setter<MarkupElement[], MarkupElement[]>;
74
- _watcher: import("./state.js").StateWatcher;
75
+ _setChildren: import("../state.js").Setter<MarkupElement[], MarkupElement[]>;
76
+ _watcher: import("../state.js").StateWatcher;
75
77
  _beforeMountCallbacks: (() => any)[];
76
78
  _onMountCallbacks: (() => any)[];
77
79
  _beforeUnmountCallbacks: (() => any)[];
@@ -1,3 +1,5 @@
1
+ import { strictEqual } from "../utils";
2
+ import { TYPE_SETTABLE_STATE, TYPE_STATE } from "./symbols";
1
3
  /**
2
4
  * Stops the observer that created it when called.
3
5
  */
@@ -63,8 +65,6 @@ export interface SettableState<I, O = I> extends State<I> {
63
65
  export interface Ref<T extends Node> extends State<T | undefined> {
64
66
  node: T | undefined;
65
67
  }
66
- declare const TYPE_STATE: unique symbol;
67
- declare const TYPE_SETTABLE_STATE: unique symbol;
68
68
  export declare function isState<T>(value: any): value is State<T>;
69
69
  export declare function isSettableState<T>(value: any): value is SettableState<T>;
70
70
  export declare function isRef<T extends Node>(value: any): value is Ref<T>;
@@ -77,10 +77,9 @@ export declare function valueOf<T>(value: MaybeState<T>): T;
77
77
  */
78
78
  export declare function toState<T>(value: MaybeState<T>): State<T>;
79
79
  export declare class ValueHolder<T> implements State<T> {
80
- static defaultEquals(next: any, current: any): boolean;
81
80
  value: T;
82
81
  watchers: ((value: T) => void)[];
83
- equals: typeof ValueHolder.defaultEquals;
82
+ equals: typeof strictEqual;
84
83
  constructor(value: T, options?: CreateStateOptions<T>);
85
84
  get(): T;
86
85
  set(action: T | SetFunction<T>): void;
@@ -0,0 +1,5 @@
1
+ export declare const TYPE_STATE: unique symbol;
2
+ export declare const TYPE_SETTABLE_STATE: unique symbol;
3
+ export declare const TYPE_REF: unique symbol;
4
+ export declare const TYPE_MARKUP: unique symbol;
5
+ export declare const TYPE_MARKUP_ELEMENT: unique symbol;
package/dist/index.d.ts CHANGED
@@ -1,17 +1,18 @@
1
- export { createRef, createSettableState, createSetter, createState, derive, isRef, toSettableState, toState, valueOf, } from "./state.js";
2
- export type { MaybeState, Ref, SettableState, State, StopFunction } from "./state.js";
3
- export { cond, createMarkup, html, portal, repeat } from "./markup.js";
4
- export type { Markup, MarkupElement } from "./markup.js";
5
- import { Dolla } from "./modules/dolla.js";
1
+ export { createRef, createSettableState, createSetter, createState, derive, isRef, toSettableState, toState, valueOf, } from "./core/state.js";
2
+ export type { MaybeState, Ref, SettableState, State, StopFunction } from "./core/state.js";
3
+ export { strictEqual, shallowEqual, deepEqual } from "./utils.js";
4
+ export { cond, createMarkup, html, portal, repeat } from "./core/markup.js";
5
+ export type { Markup, MarkupElement } from "./core/markup.js";
6
+ import { Dolla } from "./core/dolla.js";
6
7
  declare const dolla: Dolla;
7
8
  export default dolla;
8
- export declare const t: (selector: string, options?: import("./modules/i18n.js").TOptions) => import("./state.js").State<string>;
9
+ export declare const t: (selector: string, options?: import("./modules/i18n.js").TOptions) => import("./core/state.js").State<string>;
9
10
  export declare function setDevDebug(value: boolean): void;
10
11
  export declare function getDevDebug(): boolean;
11
- export type { Dolla, Environment, Logger, LoggerErrorContext, LoggerOptions, Loggles } from "./modules/dolla.js";
12
+ export type { Dolla, Environment, Logger, LoggerErrorContext, LoggerOptions, Loggles } from "./core/dolla.js";
12
13
  export type { HTTPRequest, HTTPResponse } from "./modules/http.js";
13
14
  export type { InputType, Renderable } from "./types.js";
14
- export type { ViewContext, ViewFunction, ViewElement as ViewNode } from "./view.js";
15
+ export type { ViewContext, ViewFunction, ViewElement as ViewNode } from "./core/nodes/view.js";
15
16
  export type { CrashViewProps } from "./views/default-crash-view.js";
16
17
  import type { IntrinsicElements as Elements } from "./types";
17
18
  declare global {