@manyducks.co/dolla 2.0.0-alpha.53 → 2.0.0-alpha.55

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 (52) hide show
  1. package/README.md +1 -12
  2. package/dist/core/context.d.ts +80 -54
  3. package/dist/core/index.d.ts +8 -7
  4. package/dist/core/logger.d.ts +9 -4
  5. package/dist/core/markup.d.ts +10 -10
  6. package/dist/core/mount.d.ts +11 -6
  7. package/dist/core/nodes/dynamic.d.ts +3 -3
  8. package/dist/core/nodes/html.d.ts +6 -5
  9. package/dist/core/nodes/outlet.d.ts +3 -4
  10. package/dist/core/nodes/portal.d.ts +2 -2
  11. package/dist/core/nodes/repeat.d.ts +6 -6
  12. package/dist/core/nodes/view.d.ts +13 -81
  13. package/dist/core/symbols.d.ts +0 -2
  14. package/dist/core/views/default-crash-view.d.ts +5 -1
  15. package/dist/core/views/fragment.d.ts +2 -2
  16. package/dist/fragment-VXM-P2tT.js +7 -0
  17. package/dist/fragment-VXM-P2tT.js.map +1 -0
  18. package/dist/http.js +1 -1
  19. package/dist/i18n.js +14 -14
  20. package/dist/i18n.js.map +1 -1
  21. package/dist/index.js +54 -61
  22. package/dist/index.js.map +1 -1
  23. package/dist/jsx-dev-runtime.js +8 -8
  24. package/dist/jsx-dev-runtime.js.map +1 -1
  25. package/dist/jsx-runtime.js +9 -9
  26. package/dist/jsx-runtime.js.map +1 -1
  27. package/dist/{logger-CByUPmlz.js → logger-CXdzxt1e.js} +178 -176
  28. package/dist/{logger-CByUPmlz.js.map → logger-CXdzxt1e.js.map} +1 -1
  29. package/dist/markup-yTuFdC0t.js +923 -0
  30. package/dist/markup-yTuFdC0t.js.map +1 -0
  31. package/dist/router/router.d.ts +9 -6
  32. package/dist/router-B-rtBG7i.js +488 -0
  33. package/dist/router-B-rtBG7i.js.map +1 -0
  34. package/dist/router.js +1 -1
  35. package/dist/router.js.map +1 -1
  36. package/dist/{typeChecking-EAVNeFyB.js → typeChecking-lgllKIVq.js} +5 -5
  37. package/dist/{typeChecking-EAVNeFyB.js.map → typeChecking-lgllKIVq.js.map} +1 -1
  38. package/dist/types.d.ts +21 -0
  39. package/docs/mixins.md +32 -0
  40. package/docs/ref.md +93 -0
  41. package/index.d.ts +1 -1
  42. package/notes/mixins.md +22 -0
  43. package/notes/scratch.md +24 -0
  44. package/package.json +2 -2
  45. package/dist/core/store.d.ts +0 -57
  46. package/dist/core/views/passthrough.d.ts +0 -5
  47. package/dist/fragment-DFnx8z2z.js +0 -8
  48. package/dist/fragment-DFnx8z2z.js.map +0 -1
  49. package/dist/router-W2HPWbeI.js +0 -482
  50. package/dist/router-W2HPWbeI.js.map +0 -1
  51. package/dist/view-CAEIbcZt.js +0 -932
  52. package/dist/view-CAEIbcZt.js.map +0 -1
package/README.md CHANGED
@@ -73,22 +73,11 @@ function Counter(props, ctx) {
73
73
  $(() => $count() > 10),
74
74
  <span>That's a lot of clicks!</span>,
75
75
  )}
76
-
77
- {/* ALT: Or slot a getter function into the DOM and have it conditionally render an element */}
78
- {() => {
79
- // DEV NOTE
80
- // If we get Dynamic to track its rendered elements and diff them by keys
81
- // then we may be able to do away with repeat and when and just do things like:
82
- // <ul>{() => items().map(item => <li>{item}</li>)}</ul>
83
- if ($count() > 10) {
84
- return <span>That's a lot of clicks!</span>;
85
- }
86
- }}
87
76
  </div>
88
77
  );
89
78
  }
90
79
 
91
- mount(document.body, Counter);
80
+ mount(Counter, document.body);
92
81
  ```
93
82
 
94
83
  > TODO: Show small examples for routing and stores.
@@ -1,69 +1,95 @@
1
- import type { View } from "./nodes/view";
2
- import type { Source } from "./signals";
3
- import type { Store, StoreFunction } from "./store";
4
- export interface ElementContext {
5
- /**
6
- * The root Dolla instance this element belongs to.
7
- */
8
- /**
9
- * Stores attached to this context.
10
- */
11
- stores: Map<StoreFunction<any, any>, Store<any, any>>;
12
- /**
13
- * The nearest view.
14
- */
15
- view?: View<any>;
16
- /**
17
- * A reference to the parent context.
18
- */
19
- parent?: ElementContext;
20
- /**
21
- * Whether to create DOM nodes in the SVG namespace. An `<svg>` element will set this to true and pass it down to children.
22
- */
23
- isSVG?: boolean;
24
- /**
25
- * The name of the nearest parent view.
26
- */
1
+ import { Logger, LoggerOptions } from "./logger";
2
+ import { type EffectFn, type MaybeSignal, type UnsubscribeFn } from "./signals";
3
+ /**
4
+ *
5
+ */
6
+ export type Store<Options, Value> = (this: Context, options: Options, context: Context) => Value;
7
+ type StoreMap = Map<Store<any, any>, any>;
8
+ export declare const globalStores: StoreMap;
9
+ type LifecycleListener = () => void;
10
+ type ContextLifecycleListeners = {
11
+ willMount?: LifecycleListener[];
12
+ didMount?: LifecycleListener[];
13
+ willUnmount?: LifecycleListener[];
14
+ didUnmount?: LifecycleListener[];
15
+ };
16
+ declare enum LifecycleState {
17
+ Unmounted = 0,
18
+ WillMount = 1,
19
+ WillMountByDependent = 2,
20
+ DidMount = 3,
21
+ DidMountByDependent = 4,
22
+ WillUnmount = 5,
23
+ WillUnmountByDependent = 6,
24
+ DidUnmount = 7
25
+ }
26
+ /**
27
+ * Manages lifecycle events for a Context.
28
+ */
29
+ declare class ContextLifecycle {
30
+ #private;
31
+ state: LifecycleState;
32
+ dependents: number;
33
+ on<E extends keyof ContextLifecycleListeners>(event: E, listener: LifecycleListener): void;
34
+ off<E extends keyof ContextLifecycleListeners>(event: E, listener: LifecycleListener): void;
35
+ willMount(dependent?: boolean): void;
36
+ didMount(dependent?: boolean): void;
37
+ willUnmount(dependent?: boolean): void;
38
+ didUnmount(dependent?: boolean): void;
39
+ dispose(): void;
40
+ }
41
+ export interface ContextOptions {
42
+ logger?: LoggerOptions;
43
+ }
44
+ export interface InheritedContextOptions extends ContextOptions {
45
+ bindLifecycleToParent?: boolean;
46
+ }
47
+ export interface Context extends Logger {
48
+ }
49
+ export declare class Context implements Logger {
50
+ #private;
51
+ _name: string;
52
+ _parent?: Context;
53
+ _lifecycle: ContextLifecycle;
54
+ _stores: StoreMap;
55
+ _state: Map<any, any>;
56
+ get isMounted(): boolean;
27
57
  /**
28
- * The context of the nearest parent view.
58
+ * Returns a new Context with this one as its parent.
29
59
  */
60
+ static inherit(parent: Context, name: MaybeSignal<string>, options?: InheritedContextOptions): Context;
61
+ constructor(name: MaybeSignal<string>, options?: ContextOptions);
30
62
  /**
31
- * Current route layer of the nearest view.
63
+ * Returns the current name of this context.
32
64
  */
33
- route?: Source<View<{}> | undefined>;
34
- }
35
- export interface ComponentContext {
65
+ getName(): string;
36
66
  /**
37
- * A name for debugging purposes. Prepended to log messages.
67
+ * Sets a new name for this context.
38
68
  */
39
- name: string;
40
- }
41
- /**
42
- * A context capable of providing stores.
43
- */
44
- export interface StoreProviderContext {
69
+ setName(name: MaybeSignal<string>): void;
70
+ addStore<T>(store: Store<any, T>, options?: any): this;
71
+ getStore<T>(store: Store<any, T>): T;
72
+ beforeMount(listener: LifecycleListener): () => void;
73
+ onMount(listener: LifecycleListener): () => void;
74
+ beforeUnmount(listener: LifecycleListener): () => void;
75
+ onUnmount(listener: LifecycleListener): () => void;
76
+ effect(callback: EffectFn): UnsubscribeFn;
45
77
  /**
46
- * Attaches a new store to this context and returns it.
78
+ * Gets the value stored at `key`, or returns the `defaultValue` if none is set.
47
79
  */
48
- provide<Value>(store: StoreFunction<{}, Value>): Value;
80
+ getState<T>(key: any, defaultValue: T): T;
49
81
  /**
50
- * Attaches a new store to this context and returns it.
82
+ * Gets the value stored at `key`, or throws an error if none is set.
51
83
  */
52
- provide<Value>(store: StoreFunction<undefined, Value>): Value;
84
+ getState<T>(key: any): T;
53
85
  /**
54
- * Attaches a new store to this context and returns it.
86
+ * Gets all values available to this context.
55
87
  */
56
- provide<Options, Value>(store: StoreFunction<Options, Value>, options: Options): Value;
88
+ getState(): Map<any, any>;
89
+ setState<T>(key: any, value: T): void;
90
+ setState(entries: [any, any][]): void;
57
91
  }
58
- export interface StoreConsumerContext {
59
- /**
60
- * Gets the closest instance of a store. Throws an error if the store isn't provided higher in the tree.
61
- */
62
- get<Value>(store: StoreFunction<any, Value>): Value;
92
+ export declare function createContext(name: MaybeSignal<string>, options?: ContextOptions): Context;
93
+ export declare class StoreError extends Error {
63
94
  }
64
- type StoreMap = Map<any, any>;
65
- export declare const globalStores: StoreMap;
66
- export declare const rootElementContext: {
67
- stores: StoreMap;
68
- };
69
95
  export {};
@@ -1,19 +1,20 @@
1
1
  export { $, effect, get, peek } from "./signals.js";
2
2
  export type { MaybeSignal, Signal, Source } from "./signals.js";
3
+ export { createContext } from "./context.js";
4
+ export type { Context, Store } from "./context.js";
5
+ export { m, portal, render, repeat, unless, when } from "./markup.js";
6
+ export type { Markup, MarkupElement } from "./markup.js";
7
+ export { type Mixin } from "./nodes/html.js";
3
8
  export { ref, type Ref } from "./ref.js";
4
- export { constructView } from "./nodes/view.js";
9
+ export { mount, type UnmountFn } from "./mount.js";
5
10
  export { deepEqual, shallowEqual, strictEqual } from "../utils.js";
6
- export { Stores, type StoreContext, type StoreFunction } from "./store.js";
7
- export { markup, portal, repeat, unless, when, constructMarkup } from "./markup.js";
8
- export type { Markup, MarkupElement } from "./markup.js";
9
11
  export { getEnv, setEnv } from "./env.js";
10
12
  export type { Env } from "./env.js";
11
13
  export { createLogger, setLogFilter, setLogLevels } from "./logger.js";
12
14
  export type { Logger, LoggerErrorContext, LoggerOptions, LogLevels } from "./logger.js";
13
- export { mount, type UnmountFn } from "./mount.js";
14
- export type { ViewContext, ViewElement, ViewFunction } from "./nodes/view.js";
15
- export type { CrashViewProps } from "./views/default-crash-view.js";
16
15
  export type { InputType, Renderable } from "../types.js";
16
+ export type { View } from "./nodes/view.js";
17
+ export type { CrashViewProps } from "./views/default-crash-view.js";
17
18
  import type { IntrinsicElements as Elements } from "../types.js";
18
19
  declare global {
19
20
  namespace JSX {
@@ -11,13 +11,17 @@ export interface Logger {
11
11
  log(...args: any[]): void;
12
12
  warn(...args: any[]): void;
13
13
  error(...args: any[]): void;
14
- crash(error: Error): void;
14
+ crash(error: Error): Error;
15
15
  }
16
16
  export interface LoggerOptions {
17
17
  /**
18
- * Unique ID to print with logs. Makes it easier to track down messages from specific view instances.
18
+ * Tag value to print with logs.
19
19
  */
20
- uid?: string;
20
+ tag?: string;
21
+ /**
22
+ * Label for tag value. Will be printed without a label if not specified.
23
+ */
24
+ tagName?: string;
21
25
  /**
22
26
  * Console object to use for logging (mostly for testing). Uses window.console by default.
23
27
  */
@@ -26,7 +30,8 @@ export interface LoggerOptions {
26
30
  export interface LoggerErrorContext {
27
31
  error: Error;
28
32
  loggerName: string;
29
- uid?: string;
33
+ tag?: string;
34
+ tagName?: string;
30
35
  }
31
36
  export declare function onLoggerCrash(listener: (context: LoggerErrorContext) => void): () => void;
32
37
  export declare function createLogger(name: MaybeSignal<string>, options?: LoggerOptions): Logger;
@@ -1,6 +1,6 @@
1
1
  import type { Mountable, Renderable } from "../types.js";
2
- import { type ElementContext } from "./context.js";
3
- import { View, type ViewContext, type ViewFunction, type ViewResult } from "./nodes/view.js";
2
+ import { Context } from "./context.js";
3
+ import { ViewInstance, type View, type ViewResult } from "./nodes/view.js";
4
4
  import { type MaybeSignal, type Signal } from "./signals.js";
5
5
  /**
6
6
  * Markup is a set of element metadata that hasn't been constructed into a MarkupElement yet.
@@ -10,7 +10,7 @@ export interface Markup {
10
10
  * In the case of a view, type will be the View function itself. It can also hold an identifier for special nodes like "$cond", "$repeat", etc.
11
11
  * DOM nodes can be created by name, such as HTML elements like "div", "ul" or "span", SVG elements like ""
12
12
  */
13
- type: string | ViewFunction<any>;
13
+ type: string | View<any>;
14
14
  /**
15
15
  * Data that will be passed to a new MarkupElement instance when it is constructed.
16
16
  */
@@ -30,7 +30,6 @@ export interface MarkupElement extends Mountable {
30
30
  export declare function isMarkup(value: any): value is Markup;
31
31
  export declare function isMarkupElement(value: any): value is MarkupElement;
32
32
  export declare function toMarkup(renderables: Renderable | Renderable[]): Markup[];
33
- export declare function constructMarkup(markup: Markup | Markup[]): MarkupElement;
34
33
  export declare enum MarkupType {
35
34
  Text = "$text",
36
35
  Repeat = "$repeat",
@@ -47,13 +46,13 @@ export interface MarkupAttributes {
47
46
  [MarkupType.Repeat]: {
48
47
  items: Signal<any[]>;
49
48
  keyFn: (value: any, index: number) => string | number | symbol;
50
- renderFn: (item: Signal<any>, index: Signal<number>, ctx: ViewContext) => ViewResult;
49
+ renderFn: (item: Signal<any>, index: Signal<number>, ctx: Context) => ViewResult;
51
50
  };
52
51
  [MarkupType.Dynamic]: {
53
52
  source: Signal<Renderable>;
54
53
  };
55
54
  [MarkupType.Outlet]: {
56
- view: Signal<View<{}> | undefined>;
55
+ view: Signal<ViewInstance<{}> | undefined>;
57
56
  };
58
57
  [MarkupType.Fragment]: {
59
58
  children: MaybeSignal<MarkupElement[]>;
@@ -67,8 +66,8 @@ export interface MarkupAttributes {
67
66
  };
68
67
  [tag: string]: Record<string, any>;
69
68
  }
70
- export declare function markup<T extends keyof MarkupAttributes>(type: T, attributes: MarkupAttributes[T], ...children: Renderable[]): Markup;
71
- export declare function markup<I>(type: ViewFunction<I>, attributes?: I, ...children: any[]): Markup;
69
+ export declare function m<T extends keyof MarkupAttributes>(type: T, attributes: MarkupAttributes[T], ...children: Renderable[]): Markup;
70
+ export declare function m<I>(type: View<I>, attributes?: I, ...children: any[]): Markup;
72
71
  /**
73
72
  * Displays `thenContent` when `condition` is truthy and `elseContent` when falsy.
74
73
  */
@@ -81,15 +80,16 @@ export declare function unless(condition: MaybeSignal<any>, thenContent?: Render
81
80
  * Calls `renderFn` for each item in `items`. Dynamically adds and removes views as items change.
82
81
  * The result of `keyFn` is used to compare items and decide if item was added, removed or updated.
83
82
  */
84
- export declare function repeat<T>(items: MaybeSignal<T[]>, keyFn: (value: T, index: number) => string | number | symbol, renderFn: (item: Signal<T>, index: Signal<number>, ctx: ViewContext) => ViewResult): Markup;
83
+ export declare function repeat<T>(items: MaybeSignal<T[]>, keyFn: (value: T, index: number) => string | number | symbol, renderFn: (item: Signal<T>, index: Signal<number>, ctx: Context) => ViewResult): Markup;
85
84
  /**
86
85
  * Renders `content` into a `parent` node anywhere in the page, rather than its usual position in the view.
87
86
  */
88
87
  export declare function portal(parent: Node, content: Renderable): Markup;
88
+ export declare function render(content: Renderable, context?: Context): MarkupElement;
89
89
  /**
90
90
  * Construct Markup metadata into a set of MarkupElements.
91
91
  */
92
- export declare function toMarkupElements(elementContext: ElementContext, markup: Markup | Markup[]): MarkupElement[];
92
+ export declare function toMarkupElements(context: Context, markup: Markup | Markup[]): MarkupElement[];
93
93
  /**
94
94
  * Combines one or more MarkupElements into a single MarkupElement.
95
95
  */
@@ -1,10 +1,15 @@
1
+ import { Router } from "../router/router";
2
+ import { Context } from "./context";
1
3
  import { type LoggerErrorContext } from "./logger";
2
- import { type ViewFunction } from "./nodes/view";
4
+ import { type View } from "./nodes/view";
3
5
  export type UnmountFn = () => Promise<void>;
4
6
  export interface MountOptions {
5
- crashView?: ViewFunction<LoggerErrorContext>;
7
+ crashView?: View<LoggerErrorContext>;
8
+ /**
9
+ * An existing Context to use as the root, otherwise a new one will be created.
10
+ * Use this to provide top-level stores and state to the whole app.
11
+ */
12
+ context?: Context;
6
13
  }
7
- export declare function mount(parent: Element, view: any, options?: MountOptions): Promise<UnmountFn>;
8
- export declare function mount(parent: Element, router: any, options?: MountOptions): Promise<UnmountFn>;
9
- export declare function mount(parent: string, view: any, options?: MountOptions): Promise<UnmountFn>;
10
- export declare function mount(parent: string, router: any, options?: MountOptions): Promise<UnmountFn>;
14
+ export declare function mount(view: View<{}>, domNode: Element, options?: MountOptions): Promise<UnmountFn>;
15
+ export declare function mount(router: Router, domNode: Element, options?: MountOptions): Promise<UnmountFn>;
@@ -1,11 +1,11 @@
1
1
  import type { Renderable } from "../../types.js";
2
- import type { ElementContext } from "../context.js";
2
+ import type { Context } from "../context.js";
3
3
  import { type MarkupElement } from "../markup.js";
4
4
  import { Signal } from "../signals.js";
5
5
  import { IS_MARKUP_ELEMENT } from "../symbols.js";
6
6
  interface DynamicOptions {
7
7
  source: Signal<Renderable>;
8
- elementContext: ElementContext;
8
+ context: Context;
9
9
  }
10
10
  /**
11
11
  * Displays dynamic children without a parent element.
@@ -17,7 +17,7 @@ export declare class Dynamic implements MarkupElement {
17
17
  [IS_MARKUP_ELEMENT]: boolean;
18
18
  domNode: Text;
19
19
  private children;
20
- private elementContext;
20
+ private context;
21
21
  private source;
22
22
  private unsubscribe?;
23
23
  get isMounted(): boolean;
@@ -1,25 +1,26 @@
1
- import { type ElementContext } from "../context.js";
1
+ import { Context } from "../context.js";
2
2
  import { type MarkupElement } from "../markup.js";
3
3
  import { IS_MARKUP_ELEMENT } from "../symbols.js";
4
+ export type Mixin<E extends Element = Element> = (element: E, context: Context) => void;
4
5
  type HTMLOptions = {
5
- elementContext: ElementContext;
6
+ context: Context;
6
7
  tag: string;
7
8
  props: Record<string, any>;
8
9
  children?: any[];
9
10
  };
10
11
  export declare class HTML implements MarkupElement {
11
12
  [IS_MARKUP_ELEMENT]: boolean;
12
- domNode: HTMLElement | SVGElement;
13
+ domNode: SVGElement | HTMLElement;
14
+ context: Context;
13
15
  private props;
14
16
  private childMarkup;
15
17
  private children;
16
18
  private unsubscribers;
17
- private elementContext;
18
19
  private logger;
19
20
  private ref?;
20
21
  private canClickAway;
21
22
  get isMounted(): boolean;
22
- constructor({ tag, props, children, elementContext }: HTMLOptions);
23
+ constructor({ tag, props, children, context }: HTMLOptions);
23
24
  mount(parent: Node, after?: Node): void;
24
25
  unmount(parentIsUnmounting?: boolean): void;
25
26
  private attachProp;
@@ -1,7 +1,6 @@
1
1
  import { type MarkupElement } from "../markup.js";
2
2
  import { type Signal } from "../signals.js";
3
3
  import { IS_MARKUP_ELEMENT } from "../symbols.js";
4
- import { View } from "./view.js";
5
4
  /**
6
5
  * Renders the subroute of the nearest view.
7
6
  */
@@ -9,10 +8,10 @@ export declare class Outlet implements MarkupElement {
9
8
  [IS_MARKUP_ELEMENT]: boolean;
10
9
  domNode: Text;
11
10
  isMounted: boolean;
12
- private view;
13
- private mountedView?;
11
+ private $slot;
12
+ private mounted?;
14
13
  private unsubscribe?;
15
- constructor(view: Signal<View<{}> | undefined>);
14
+ constructor($slot: Signal<MarkupElement | undefined>);
16
15
  mount(parent: Node, after?: Node | undefined): void;
17
16
  unmount(parentIsUnmounting?: boolean): void;
18
17
  private cleanup;
@@ -1,11 +1,11 @@
1
1
  import type { Renderable } from "../../types.js";
2
- import type { ElementContext } from "../context.js";
2
+ import { Context } from "../context.js";
3
3
  import { type MarkupElement } from "../markup.js";
4
4
  import { IS_MARKUP_ELEMENT } from "../symbols.js";
5
5
  interface PortalConfig {
6
6
  content: Renderable;
7
7
  parent: Node;
8
- elementContext: ElementContext;
8
+ context: Context;
9
9
  }
10
10
  /**
11
11
  * Renders content into a specified parent node.
@@ -1,13 +1,13 @@
1
- import { type ElementContext } from "../context.js";
1
+ import { type Context } from "../context.js";
2
2
  import { type MarkupElement } from "../markup.js";
3
3
  import { type Signal } from "../signals.js";
4
4
  import { IS_MARKUP_ELEMENT } from "../symbols.js";
5
- import { type ViewContext, type ViewResult } from "./view.js";
5
+ import { type ViewResult } from "./view.js";
6
6
  interface RepeatOptions<T> {
7
- elementContext: ElementContext;
7
+ context: Context;
8
8
  items: Signal<T[]>;
9
9
  keyFn: (item: T, index: number) => string | number | symbol;
10
- renderFn: (item: Signal<T>, index: Signal<number>, ctx: ViewContext) => ViewResult;
10
+ renderFn: (item: Signal<T>, index: Signal<number>, ctx: Context) => ViewResult;
11
11
  }
12
12
  export declare class Repeat<T> implements MarkupElement {
13
13
  [IS_MARKUP_ELEMENT]: boolean;
@@ -15,11 +15,11 @@ export declare class Repeat<T> implements MarkupElement {
15
15
  private items;
16
16
  private unsubscribe;
17
17
  private connectedItems;
18
- private elementContext;
18
+ private context;
19
19
  private renderFn;
20
20
  private keyFn;
21
21
  get isMounted(): boolean;
22
- constructor({ elementContext, items, renderFn, keyFn }: RepeatOptions<T>);
22
+ constructor({ context, items, renderFn, keyFn }: RepeatOptions<T>);
23
23
  mount(parent: Node, after?: Node): void;
24
24
  unmount(parentIsUnmounting?: boolean): void;
25
25
  private _cleanup;
@@ -1,102 +1,34 @@
1
- import { Renderable } from "../../types.js";
2
- import { type ComponentContext, type ElementContext, type StoreConsumerContext, type StoreProviderContext } from "../context.js";
3
- import { type Logger } from "../logger.js";
1
+ import { Context } from "../context.js";
4
2
  import { type Markup, type MarkupElement } from "../markup.js";
5
- import { type EffectFn, type Signal, type UnsubscribeFn } from "../signals.js";
6
- import { StoreFunction } from "../store.js";
3
+ import { type Signal } from "../signals.js";
7
4
  import { IS_MARKUP_ELEMENT } from "../symbols.js";
5
+ export declare const ROUTE: unique symbol;
6
+ export declare const VIEW: unique symbol;
8
7
  /**
9
8
  * Any valid value that a View can return.
10
9
  */
11
10
  export type ViewResult = Node | Signal<any> | Markup | Markup[] | null;
12
- export type ViewFunction<P> = (this: ViewContext, props: P, context: ViewContext) => ViewResult;
11
+ /**
12
+ *
13
+ */
14
+ export type View<P> = (this: Context, props: P, context: Context) => ViewResult;
13
15
  /**
14
16
  * A view that has been constructed into DOM nodes.
15
17
  */
16
- export interface ViewElement extends MarkupElement {
17
- setRouteView(view: ViewFunction<{}>): ViewElement;
18
- }
19
- export interface ViewContext extends Omit<Logger, "setName">, ComponentContext, StoreProviderContext, StoreConsumerContext {
20
- /**
21
- * An ID unique to this view.
22
- */
23
- readonly uid: string;
24
- /**
25
- * True while this view is connected to the DOM.
26
- */
27
- readonly isMounted: boolean;
28
- /**
29
- * Registers a callback to run just before this view is mounted. DOM nodes are not yet attached to the page.
30
- */
31
- beforeMount(callback: () => void): void;
32
- /**
33
- * Registers a callback to run just after this view is mounted.
34
- */
35
- onMount(callback: () => void): void;
36
- /**
37
- * Registers a callback to run just before this view is unmounted. DOM nodes are still attached to the page.
38
- */
39
- beforeUnmount(callback: () => void): void;
40
- /**
41
- * Registers a callback to run just after this view is unmounted.
42
- */
43
- onUnmount(callback: () => void): void;
44
- /**
45
- * Passes a getter function to `callback` that will track reactive states and return their current values.
46
- * Callback will be run each time a tracked state gets a new value.
47
- */
48
- effect(callback: EffectFn): UnsubscribeFn;
49
- /**
50
- * Displays this view's subroutes if mounted as a router view.
51
- */
52
- outlet(): Markup;
53
- }
54
- interface Context extends Omit<Logger, "setName"> {
55
- }
56
- declare class Context implements ViewContext {
57
- private view;
58
- constructor(view: View<any>);
59
- get uid(): string;
60
- get isMounted(): boolean;
61
- get name(): string;
62
- set name(value: string);
63
- provide<Value>(store: StoreFunction<any, Value>, options?: any): Value;
64
- get<Value>(store: StoreFunction<any, Value>): Value;
65
- beforeMount(callback: () => void): void;
66
- onMount(callback: () => void): void;
67
- beforeUnmount(callback: () => void): void;
68
- onUnmount(callback: () => void): void;
69
- effect(callback: EffectFn): UnsubscribeFn;
70
- outlet(): Markup;
71
- }
72
- export declare class View<P> implements ViewElement {
18
+ export declare class ViewInstance<P> implements MarkupElement {
73
19
  [IS_MARKUP_ELEMENT]: boolean;
74
20
  uniqueId: string;
75
- elementContext: ElementContext;
76
- logger: Logger;
21
+ context: Context;
77
22
  props: P & {
78
23
  children: Markup[] | undefined;
79
24
  };
80
- fn: ViewFunction<P>;
25
+ fn: View<P>;
81
26
  element?: MarkupElement;
82
- name: import("../signals.js").Source<string>;
83
- context: Context;
84
- lifecycleListeners: {
85
- beforeMount: (() => any)[];
86
- mount: (() => any)[];
87
- beforeUnmount: (() => any)[];
88
- unmount: (() => any)[];
89
- };
90
- constructor(elementContext: ElementContext, fn: ViewFunction<P>, props: P, children?: Markup[]);
27
+ $name: import("../signals.js").Source<string>;
28
+ constructor(context: Context, fn: View<P>, props: P, children?: Markup[]);
91
29
  get domNode(): Node;
92
30
  isMounted: boolean;
93
31
  mount(parent: Node, after?: Node): void;
94
32
  unmount(parentIsUnmounting?: boolean): void;
95
- setRouteView(fn: ViewFunction<{}>): View<{}>;
96
33
  private _initialize;
97
34
  }
98
- export declare function constructView<P>(view: ViewFunction<P>, props: P, children?: Renderable[]): ViewElement;
99
- export declare function constructView(view: ViewFunction<{}>, children?: Renderable[]): ViewElement;
100
- export declare function constructView<P>(context: ElementContext, view: ViewFunction<P>, props: P, children?: Renderable[]): ViewElement;
101
- export declare function constructView(context: ElementContext, view: ViewFunction<{}>, children?: Renderable[]): ViewElement;
102
- export {};
@@ -1,4 +1,2 @@
1
1
  export declare const IS_MARKUP: unique symbol;
2
2
  export declare const IS_MARKUP_ELEMENT: unique symbol;
3
- export declare const IS_STORE: unique symbol;
4
- export declare const IS_ROUTER: unique symbol;
@@ -13,6 +13,10 @@ export type CrashViewProps = {
13
13
  /**
14
14
  * Unique identifier to pinpoint the specific view that reported the crash.
15
15
  */
16
- uid?: string;
16
+ tag?: string;
17
+ /**
18
+ * Label for the tag.
19
+ */
20
+ tagName?: string;
17
21
  };
18
22
  export declare function DefaultCrashView(props: CrashViewProps): import("../markup.js").Markup;
@@ -1,8 +1,8 @@
1
1
  import type { Renderable } from "../../types.js";
2
- import { type ViewContext } from "../nodes/view.js";
2
+ import { Context } from "../context.js";
3
3
  /**
4
4
  * A utility view that displays its children.
5
5
  */
6
6
  export declare function Fragment(props: {
7
7
  children?: Renderable;
8
- }, ctx: ViewContext): import("../markup.js").Markup;
8
+ }, ctx: Context): string | number | false | import("../signals.js").Signal<any> | import("../markup.js").Markup | (string | number | false | import("../signals.js").Signal<any> | import("../markup.js").Markup | null | undefined)[] | null;
@@ -0,0 +1,7 @@
1
+ function t(n, r) {
2
+ return n.children ?? null;
3
+ }
4
+ export {
5
+ t as F
6
+ };
7
+ //# sourceMappingURL=fragment-VXM-P2tT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fragment-VXM-P2tT.js","sources":["../src/core/views/fragment.ts"],"sourcesContent":["import type { Renderable } from \"../../types.js\";\nimport { Context } from \"../context.js\";\nimport { m } from \"../markup.js\";\n\n/**\n * A utility view that displays its children.\n */\nexport function Fragment(props: { children?: Renderable }, ctx: Context) {\n return props.children ?? null;\n // return m(\"$dynamic\", { source: () => props.children });\n}\n"],"names":["Fragment","props","ctx"],"mappings":"AAOgB,SAAAA,EAASC,GAAkCC,GAAc;AACvE,SAAOD,EAAM,YAAY;AAE3B;"}
package/dist/http.js CHANGED
@@ -6,7 +6,7 @@ var g = (r, e, t) => e in r ? b(r, e, { enumerable: !0, configurable: !0, writab
6
6
  var a = (r, e, t) => g(r, typeof e != "symbol" ? e + "" : e, t), m = (r, e, t) => e.has(r) || f("Cannot " + t);
7
7
  var d = (r, e, t) => (m(r, e, "read from private field"), t ? t.call(r) : e.get(r)), c = (r, e, t) => e.has(r) ? f("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(r) : e.set(r, t);
8
8
  var o = (r, e, t) => (m(r, e, "access private method"), t);
9
- import { b as w } from "./typeChecking-EAVNeFyB.js";
9
+ import { i as w } from "./typeChecking-lgllKIVq.js";
10
10
  var l, p, i, h;
11
11
  class O {
12
12
  constructor() {