@manyducks.co/dolla 2.0.0-alpha.61 → 2.0.0-alpha.62

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.
@@ -52,6 +52,22 @@ declare class ContextLifecycle {
52
52
  */
53
53
  private notify;
54
54
  }
55
+ export interface ContextGetStateOptions<T> {
56
+ fallback?: T;
57
+ /**
58
+ * Only check this context; skip parent contexts.
59
+ */
60
+ immediate?: boolean;
61
+ }
62
+ export interface ContextGetStateOptionsWithFallbackValue<T> extends ContextGetStateOptions<T> {
63
+ fallback: T;
64
+ }
65
+ export interface ContextGetStateMapOptions {
66
+ /**
67
+ * Only include state from this context; skip parent contexts.
68
+ */
69
+ immediate?: boolean;
70
+ }
55
71
  export interface ContextOptions {
56
72
  logger?: LoggerOptions;
57
73
  }
@@ -118,17 +134,20 @@ export declare class Context implements Logger {
118
134
  onUnmount(listener: LifecycleListener): () => void;
119
135
  effect(callback: EffectFn): UnsubscribeFn;
120
136
  /**
121
- * Gets the value stored at `key`, or returns the `defaultValue` if none is set.
137
+ * Gets the value stored at `key`, or returns `options.fallback` if none is set.
122
138
  */
123
- getState<T>(key: any, defaultValue: T): T;
139
+ getState<T>(key: any, options: ContextGetStateOptionsWithFallbackValue<T>): T;
124
140
  /**
125
141
  * Gets the value stored at `key`, or throws an error if none is set.
126
142
  */
127
- getState<T>(key: any): T;
143
+ getState<T>(key: any, options?: ContextGetStateOptions<T>): T;
128
144
  /**
129
145
  * Returns a Map containing all state values available to this context.
146
+ *
147
+ * Pass `options.immediate` to only include state stored on this context.
148
+ * By default all state stored on parent contexts is also included.
130
149
  */
131
- getState(): Map<any, any>;
150
+ getStateMap(options?: ContextGetStateMapOptions): Map<any, any>;
132
151
  /**
133
152
  * Stores `value` at `key` in this context's state.
134
153
  */
@@ -4,6 +4,8 @@ export { createContext } from "./context.js";
4
4
  export type { Context } from "./context.js";
5
5
  export { m, MarkupNode, portal, render, repeat, unless, when } from "./markup.js";
6
6
  export { ref, type Ref } from "./ref.js";
7
+ export { For, type ForProps } from "./views/for.js";
8
+ export { Show, type ShowProps } from "./views/show.js";
7
9
  export { mount, type UnmountFn } from "./mount.js";
8
10
  export { deepEqual, shallowEqual, strictEqual } from "../utils.js";
9
11
  export { getEnv, setEnv } from "./env.js";
@@ -20,12 +20,6 @@ export declare class Markup<P = any> {
20
20
  props: P | undefined;
21
21
  constructor(type: string | View<P>, props?: P);
22
22
  }
23
- /**
24
- * A node that can be mounted by the Markup layout engine.
25
- * Implemented by the built in nodes, but can of course also be implemented to create your own custom nodes.
26
- *
27
- * A `MarkupNode` instance can be passed anywhere a `Renderable` is required.
28
- */
29
23
  export declare enum MarkupType {
30
24
  DOM = "$dom",
31
25
  Dynamic = "$dynamic",
@@ -2,7 +2,7 @@ import type { Renderable } from "../../types.js";
2
2
  import type { Context } from "../context.js";
3
3
  import { type Signal } from "../signals.js";
4
4
  import { MarkupNode } from "./_markup.js";
5
- export type Key = string | number | symbol;
5
+ export type Key = any;
6
6
  export type KeyFn<T> = (item: T, index: number) => Key;
7
7
  export type RenderFn<T> = (item: Signal<T>, index: Signal<number>, ctx: Context) => Renderable;
8
8
  /**
@@ -0,0 +1,23 @@
1
+ import type { Renderable } from "../../types";
2
+ import type { Context } from "../context";
3
+ import { type Key, RepeatNode } from "../nodes/repeat";
4
+ import { type Signal } from "../signals";
5
+ export interface ForProps<T> {
6
+ /**
7
+ * An array of items to render.
8
+ */
9
+ each: Signal<T[]>;
10
+ /**
11
+ * A function to extract a unique key that identifies each item.
12
+ * If no `key` function is passed, object identity (===) will be used.
13
+ */
14
+ key?: (item: T, index: number) => Key;
15
+ /**
16
+ * A render function. Takes the item and its index in signal form and returns something to display for each item.
17
+ */
18
+ children: ($item: Signal<T>, $index: Signal<number>, ctx: Context) => Renderable;
19
+ }
20
+ /**
21
+ *
22
+ */
23
+ export declare function For<T>(props: ForProps<T>, context: Context): RepeatNode<T>;
@@ -0,0 +1,26 @@
1
+ import type { Renderable } from "../../types";
2
+ import type { Context } from "../context";
3
+ import { DynamicNode } from "../nodes/dynamic";
4
+ import { type Signal } from "../signals";
5
+ export interface ShowProps {
6
+ /**
7
+ * If present, children will be rendered only when this signal holds a truthy value.
8
+ */
9
+ when?: Signal<any>;
10
+ /**
11
+ * If present, children will be rendered only when this signal holds a falsy value.
12
+ */
13
+ unless?: Signal<any>;
14
+ /**
15
+ * Content to render if conditions permit.
16
+ */
17
+ children: Renderable;
18
+ /**
19
+ * Content to render when conditions don't permit `children` to render.
20
+ */
21
+ fallback?: Renderable;
22
+ }
23
+ /**
24
+ * Conditionally display children.
25
+ */
26
+ export declare function Show(props: ShowProps, context: Context): DynamicNode;
@@ -24,7 +24,7 @@ export declare function useState<T>(value: T): [Signal<T>, Setter<T>];
24
24
  * Creates a new read-only Signal and a bound Setter function.
25
25
  */
26
26
  export declare function useState<T>(): [Signal<T | undefined>, Setter<T | undefined>];
27
- export declare function useMemo<T>(compute: (current?: T) => T, deps?: Signal<any>[]): Signal<T>;
27
+ export declare function useMemo<T>(compute: (current?: T) => MaybeSignal<T>, deps?: Signal<any>[]): Signal<T>;
28
28
  export declare function useEffect(fn: EffectFn, deps?: Signal<any>[]): void;
29
29
  /**
30
30
  * Takes the current state and a dispatched action. Returns a new state based on the action.
package/dist/hooks.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.js","sources":["../src/hooks/index.ts"],"sourcesContent":["import { Context, Logger, ref, type Ref, type Store } from \"../core\";\nimport { $, type EffectFn, get, getCurrentContext, MaybeSignal, type Signal, untracked } from \"../core/signals\";\n\n/**\n * Returns the Context object of the View, Store or Mixin this hook is called in.\n */\nexport function useContext(): Context {\n const context = getCurrentContext();\n if (!context) {\n throw new Error(`No context found; hooks can only be called in the body of a View, Store or Mixin.`);\n }\n return context;\n}\n\n/**\n * Returns a logger. If a name is passed it will be used as a prefix for all console messages.\n * Otherwise the default name of the context will be used.\n */\nexport function useLogger(name?: MaybeSignal<string>): Logger {\n const context = useContext();\n if (name) context.setName(name);\n return context;\n}\n\n/**\n * Sets the value of the Signal it is bound to.\n */\nexport interface Setter<T> {\n (value: T): void;\n (fn: (current: T) => T): void;\n}\n\n/**\n * Creates a new read-only Signal and a bound Setter function.\n */\nexport function useState<T>(value: T): [Signal<T>, Setter<T>];\n\n/**\n * Creates a new read-only Signal and a bound Setter function.\n */\nexport function useState<T>(): [Signal<T | undefined>, Setter<T | undefined>];\n\nexport function useState<T>(value?: T): [Signal<T>, Setter<T>] {\n useContext(); // assert that we're in a valid context\n const $value = $(value);\n return [() => $value() as T, $value];\n}\n\nexport function useMemo<T>(compute: (current?: T) => T, deps?: Signal<any>[]): Signal<T> {\n useContext(); // assert that we're in a valid context\n if (deps) {\n return $(function () {\n // Track deps and run `compute` untracked.\n for (const dep of deps) get(dep);\n return untracked(() => compute(this.value));\n });\n } else {\n return $(function () {\n return compute(this.value);\n });\n }\n}\n\nexport function useEffect(fn: EffectFn, deps?: Signal<any>[]): void {\n const context = useContext();\n if (deps) {\n context.effect(() => {\n // Track deps and run `fn` untracked.\n for (const dep of deps) get(dep);\n untracked(fn);\n });\n } else {\n context.effect(fn);\n }\n}\n\n// TODO: What would layout effect even mean in dolla?\n// export function useLayoutEffect() {}\n\n/**\n * Takes the current state and a dispatched action. Returns a new state based on the action.\n * Typically the body of this function will be a large switch statement.\n */\nexport type ReducerFn<State, Action> = (state: State, action: Action) => State;\n\n/**\n * Dispatches an action to this reducer, causing the state to update.\n */\nexport type DispatchFn<Action> = (action: Action) => void;\n\n/**\n *\n */\nexport function useReducer<State, Action>(\n reducer: ReducerFn<State, Action>,\n initialState: State,\n): [Signal<State>, DispatchFn<Action>] {\n const [state, setState] = useState(initialState);\n const dispatch = (action: Action) => {\n setState((current) => reducer(current, action));\n };\n return [state, dispatch];\n}\n\n/**\n * Uses a previously added Store. Takes the Store function itself and returns the nearest instance.\n */\nexport function useStore<T>(store: Store<any, T>): T {\n const context = useContext();\n return context.getStore(store);\n}\n\n/**\n * A hybrid Ref which is both a function ref and a React-style object ref with a `current` property.\n * Both the `current` property and the function syntax access the same value.\n */\nexport interface HybridRef<T> extends Ref<T> {\n current: T;\n}\n\n/**\n * Creates a Ref. Useful for getting references to DOM nodes.\n */\nexport function useRef<T>(initialValue?: T): HybridRef<T>;\n\nexport function useRef<T>(...value: [T]): HybridRef<T> {\n useContext(); // assert that we're in a valid context\n const valueRef = ref(...value);\n Object.defineProperty(valueRef, \"current\", { get: valueRef, set: valueRef });\n return valueRef as HybridRef<T>;\n}\n\n/**\n * Calls `callback` when the context is mounted. If `callback` returns a function, that function is called when the context is unmounted.\n */\nexport function useMount(callback: () => void | (() => void)): void {\n const context = useContext();\n context.onMount(() => {\n const result = callback();\n if (result) context.onUnmount(result);\n });\n}\n\n/**\n * Calls `callback` when the context is unmounted.\n */\nexport function useUnmount(callback: () => void): void {\n const context = useContext();\n context.onUnmount(callback);\n}\n"],"names":["useContext","context","getCurrentContext","useLogger","name","useState","value","$value","$","useMemo","compute","deps","dep","get","untracked","useEffect","fn","useReducer","reducer","initialState","state","setState","action","current","useStore","store","useRef","valueRef","ref","useMount","callback","result","useUnmount"],"mappings":";;AAMO,SAASA,IAAsB;AACpC,QAAMC,IAAUC,EAAkB;AAClC,MAAI,CAACD;AACG,UAAA,IAAI,MAAM,mFAAmF;AAE9F,SAAAA;AACT;AAMO,SAASE,EAAUC,GAAoC;AAC5D,QAAMH,IAAUD,EAAW;AACvB,SAAAI,KAAcH,EAAA,QAAQG,CAAI,GACvBH;AACT;AAoBO,SAASI,EAAYC,GAAmC;AAClD,EAAAN,EAAA;AACL,QAAAO,IAASC,EAAEF,CAAK;AACtB,SAAO,CAAC,MAAMC,EAAO,GAAQA,CAAM;AACrC;AAEgB,SAAAE,EAAWC,GAA6BC,GAAiC;AAEvF,SADWX,EAAA,GACPW,IACKH,EAAE,WAAY;AAER,eAAAI,KAAOD,EAAM,CAAAE,EAAID,CAAG;AAC/B,WAAOE,EAAU,MAAMJ,EAAQ,KAAK,KAAK,CAAC;AAAA,EAAA,CAC3C,IAEMF,EAAE,WAAY;AACZ,WAAAE,EAAQ,KAAK,KAAK;AAAA,EAAA,CAC1B;AAEL;AAEgB,SAAAK,EAAUC,GAAcL,GAA4B;AAClE,QAAMV,IAAUD,EAAW;AAC3B,EAAIW,IACFV,EAAQ,OAAO,MAAM;AAER,eAAAW,KAAOD,EAAM,CAAAE,EAAID,CAAG;AAC/B,IAAAE,EAAUE,CAAE;AAAA,EAAA,CACb,IAEDf,EAAQ,OAAOe,CAAE;AAErB;AAmBgB,SAAAC,EACdC,GACAC,GACqC;AACrC,QAAM,CAACC,GAAOC,CAAQ,IAAIhB,EAASc,CAAY;AAIxC,SAAA,CAACC,GAHS,CAACE,MAAmB;AACnC,IAAAD,EAAS,CAACE,MAAYL,EAAQK,GAASD,CAAM,CAAC;AAAA,EAChD,CACuB;AACzB;AAKO,SAASE,EAAYC,GAAyB;AAE5C,SADSzB,EAAW,EACZ,SAASyB,CAAK;AAC/B;AAeO,SAASC,KAAapB,GAA0B;AAC1C,EAAAN,EAAA;AACL,QAAA2B,IAAWC,EAAI,GAAGtB,CAAK;AACtB,gBAAA,eAAeqB,GAAU,WAAW,EAAE,KAAKA,GAAU,KAAKA,GAAU,GACpEA;AACT;AAKO,SAASE,EAASC,GAA2C;AAClE,QAAM7B,IAAUD,EAAW;AAC3B,EAAAC,EAAQ,QAAQ,MAAM;AACpB,UAAM8B,IAASD,EAAS;AACpB,IAAAC,KAAgB9B,EAAA,UAAU8B,CAAM;AAAA,EAAA,CACrC;AACH;AAKO,SAASC,EAAWF,GAA4B;AAErD,EADgB9B,EAAW,EACnB,UAAU8B,CAAQ;AAC5B;"}
1
+ {"version":3,"file":"hooks.js","sources":["../src/hooks/index.ts"],"sourcesContent":["import { Context, Logger, ref, type Ref, type Store } from \"../core\";\nimport { $, type EffectFn, get, getCurrentContext, MaybeSignal, type Signal, untracked } from \"../core/signals\";\n\n/**\n * Returns the Context object of the View, Store or Mixin this hook is called in.\n */\nexport function useContext(): Context {\n const context = getCurrentContext();\n if (!context) {\n throw new Error(`No context found; hooks can only be called in the body of a View, Store or Mixin.`);\n }\n return context;\n}\n\n/**\n * Returns a logger. If a name is passed it will be used as a prefix for all console messages.\n * Otherwise the default name of the context will be used.\n */\nexport function useLogger(name?: MaybeSignal<string>): Logger {\n const context = useContext();\n if (name) context.setName(name);\n return context;\n}\n\n/**\n * Sets the value of the Signal it is bound to.\n */\nexport interface Setter<T> {\n (value: T): void;\n (fn: (current: T) => T): void;\n}\n\n/**\n * Creates a new read-only Signal and a bound Setter function.\n */\nexport function useState<T>(value: T): [Signal<T>, Setter<T>];\n\n/**\n * Creates a new read-only Signal and a bound Setter function.\n */\nexport function useState<T>(): [Signal<T | undefined>, Setter<T | undefined>];\n\nexport function useState<T>(value?: T): [Signal<T>, Setter<T>] {\n useContext(); // assert that we're in a valid context\n const $value = $(value);\n return [() => $value() as T, $value];\n}\n\nexport function useMemo<T>(compute: (current?: T) => MaybeSignal<T>, deps?: Signal<any>[]): Signal<T> {\n useContext(); // assert that we're in a valid context\n if (deps) {\n return $(function () {\n // Track deps and run `compute` untracked.\n for (const dep of deps) get(dep);\n return untracked(() => compute(this.value));\n });\n } else {\n return $(function () {\n return compute(this.value);\n });\n }\n}\n\nexport function useEffect(fn: EffectFn, deps?: Signal<any>[]): void {\n const context = useContext();\n if (deps) {\n context.effect(() => {\n // Track deps and run `fn` untracked.\n for (const dep of deps) get(dep);\n untracked(fn);\n });\n } else {\n context.effect(fn);\n }\n}\n\n// TODO: What would layout effect even mean in dolla?\n// export function useLayoutEffect() {}\n\n/**\n * Takes the current state and a dispatched action. Returns a new state based on the action.\n * Typically the body of this function will be a large switch statement.\n */\nexport type ReducerFn<State, Action> = (state: State, action: Action) => State;\n\n/**\n * Dispatches an action to this reducer, causing the state to update.\n */\nexport type DispatchFn<Action> = (action: Action) => void;\n\n/**\n *\n */\nexport function useReducer<State, Action>(\n reducer: ReducerFn<State, Action>,\n initialState: State,\n): [Signal<State>, DispatchFn<Action>] {\n const [state, setState] = useState(initialState);\n const dispatch = (action: Action) => {\n setState((current) => reducer(current, action));\n };\n return [state, dispatch];\n}\n\n/**\n * Uses a previously added Store. Takes the Store function itself and returns the nearest instance.\n */\nexport function useStore<T>(store: Store<any, T>): T {\n const context = useContext();\n return context.getStore(store);\n}\n\n/**\n * A hybrid Ref which is both a function ref and a React-style object ref with a `current` property.\n * Both the `current` property and the function syntax access the same value.\n */\nexport interface HybridRef<T> extends Ref<T> {\n current: T;\n}\n\n/**\n * Creates a Ref. Useful for getting references to DOM nodes.\n */\nexport function useRef<T>(initialValue?: T): HybridRef<T>;\n\nexport function useRef<T>(...value: [T]): HybridRef<T> {\n useContext(); // assert that we're in a valid context\n const valueRef = ref(...value);\n Object.defineProperty(valueRef, \"current\", { get: valueRef, set: valueRef });\n return valueRef as HybridRef<T>;\n}\n\n/**\n * Calls `callback` when the context is mounted. If `callback` returns a function, that function is called when the context is unmounted.\n */\nexport function useMount(callback: () => void | (() => void)): void {\n const context = useContext();\n context.onMount(() => {\n const result = callback();\n if (result) context.onUnmount(result);\n });\n}\n\n/**\n * Calls `callback` when the context is unmounted.\n */\nexport function useUnmount(callback: () => void): void {\n const context = useContext();\n context.onUnmount(callback);\n}\n"],"names":["useContext","context","getCurrentContext","useLogger","name","useState","value","$value","$","useMemo","compute","deps","dep","get","untracked","useEffect","fn","useReducer","reducer","initialState","state","setState","action","current","useStore","store","useRef","valueRef","ref","useMount","callback","result","useUnmount"],"mappings":";;AAMO,SAASA,IAAsB;AACpC,QAAMC,IAAUC,EAAkB;AAClC,MAAI,CAACD;AACG,UAAA,IAAI,MAAM,mFAAmF;AAE9F,SAAAA;AACT;AAMO,SAASE,EAAUC,GAAoC;AAC5D,QAAMH,IAAUD,EAAW;AACvB,SAAAI,KAAcH,EAAA,QAAQG,CAAI,GACvBH;AACT;AAoBO,SAASI,EAAYC,GAAmC;AAClD,EAAAN,EAAA;AACL,QAAAO,IAASC,EAAEF,CAAK;AACt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8B,CAAQ;AAC5B;"}
package/dist/index.js CHANGED
@@ -1,13 +1,24 @@
1
- import { $ as T, b as D, d as E, e as V, g as v, s as I, a as R, u as q } from "./signals-gCwiIe5X.js";
2
- import { m as a, w as g, C as s, L as m, V as d } from "./markup-CX27GJ1M.js";
3
- import { M as _, c as $, p as B, r as W, a as z, u as A } from "./markup-CX27GJ1M.js";
4
- import { r as G } from "./ref-BD79iqlg.js";
5
- import { R as h, M as p, U as y } from "./router-CjCkk4dA.js";
6
- import { a as w } from "./typeChecking-CbltMOUt.js";
7
- import { o as x } from "./logger-Bl496yfY.js";
8
- import { c as j, g as H, s as J, a as K, b as Q } from "./logger-Bl496yfY.js";
9
- function N(e) {
10
- return a("div", {
1
+ import { g as m } from "./signals-gCwiIe5X.js";
2
+ import { $ as q, b as S, d as _, e as $, s as B, a as W, u as z } from "./signals-gCwiIe5X.js";
3
+ import { R as g, D as w, m as n, w as y, C as l, L as c, V as f } from "./markup-UzKSsawX.js";
4
+ import { M as G, c as K, p as P, r as j, a as H, u as J } from "./markup-UzKSsawX.js";
5
+ import { r as X } from "./ref-BD79iqlg.js";
6
+ import { R as N, M as x, U as b } from "./router-BXBX8lnO.js";
7
+ import { a as L } from "./typeChecking-CbltMOUt.js";
8
+ import { o as M } from "./logger-Bl496yfY.js";
9
+ import { c as Z, g as p, s as ee, a as ae, b as te } from "./logger-Bl496yfY.js";
10
+ const U = (e) => e;
11
+ function E(e, t) {
12
+ return new g(t, e.each, e.key ?? U, e.children);
13
+ }
14
+ function F(e, t) {
15
+ return new w(t, () => {
16
+ let a = !0;
17
+ return e.when != null && e.unless != null ? a = m(e.when) && !m(e.unless) : e.when != null ? a = m(e.when) : e.unless != null && (a = !m(e.unless)), a ? e.children : e.fallback;
18
+ });
19
+ }
20
+ function k(e) {
21
+ return n("div", {
11
22
  style: {
12
23
  backgroundColor: "#880000",
13
24
  color: "#fff",
@@ -17,17 +28,17 @@ function N(e) {
17
28
  fontSize: "20px"
18
29
  },
19
30
  children: [
20
- a("h1", { style: { marginBottom: "0.5rem" }, children: "The app has crashed" }),
21
- a("p", {
31
+ n("h1", { style: { marginBottom: "0.5rem" }, children: "The app has crashed" }),
32
+ n("p", {
22
33
  style: { marginBottom: "0.25rem" },
23
34
  children: [
24
- a("span", {
35
+ n("span", {
25
36
  style: { fontFamily: "monospace" },
26
37
  children: e.loggerName
27
38
  }),
28
- g(
39
+ y(
29
40
  e.tag,
30
- a("span", {
41
+ n("span", {
31
42
  style: { fontFamily: "monospace", opacity: 0.5 },
32
43
  children: ` [${e.tagName ? `${e.tagName}: ` : ""}${e.tag}]`
33
44
  })
@@ -35,7 +46,7 @@ function N(e) {
35
46
  " says:"
36
47
  ]
37
48
  }),
38
- a("blockquote", {
49
+ n("blockquote", {
39
50
  style: {
40
51
  backgroundColor: "#991111",
41
52
  padding: "0.25em",
@@ -44,7 +55,7 @@ function N(e) {
44
55
  marginBottom: "1rem"
45
56
  },
46
57
  children: [
47
- a("span", {
58
+ n("span", {
48
59
  style: {
49
60
  display: "inline-block",
50
61
  backgroundColor: "red",
@@ -59,48 +70,50 @@ function N(e) {
59
70
  e.error.message
60
71
  ]
61
72
  }),
62
- a("p", { children: "Please see the browser console for details." })
73
+ n("p", { children: "Please see the browser console for details." })
63
74
  ]
64
75
  });
65
76
  }
66
- let o = !1;
67
- async function C(e, n, r) {
68
- if (w(Element, n, "Expected an element or a selector string. Got type: %t, value: %v"), o)
77
+ let s = !1;
78
+ async function V(e, t, a) {
79
+ if (L(Element, t, "Expected an element or a selector string. Got type: %t, value: %v"), s)
69
80
  throw new Error("A Dolla app is already mounted.");
70
- let l, i, f = (r == null ? void 0 : r.crashView) ?? N;
71
- const t = (r == null ? void 0 : r.context) ?? new s("App");
72
- x((u) => {
73
- o && c(), new d(t, f, u).mount(n);
74
- }), s.emit(t, m.WILL_MOUNT), e instanceof h ? (i = e, l = await i[p](n, t)) : l = new d(t, e, {}), l.mount(n), o = !0, s.emit(t, m.DID_MOUNT);
75
- async function c() {
76
- o && (s.emit(t, m.WILL_UNMOUNT), l.unmount(!1), i && await i[y](), o = !1, s.emit(t, m.DID_UNMOUNT));
81
+ let o, i, d = (a == null ? void 0 : a.crashView) ?? k;
82
+ const r = (a == null ? void 0 : a.context) ?? new l("App");
83
+ M((h) => {
84
+ s && u(), new f(r, d, h).mount(t);
85
+ }), l.emit(r, c.WILL_MOUNT), e instanceof N ? (i = e, o = await i[x](t, r)) : o = new f(r, e, {}), o.mount(t), s = !0, l.emit(r, c.DID_MOUNT);
86
+ async function u() {
87
+ s && (l.emit(r, c.WILL_UNMOUNT), o.unmount(!1), i && await i[b](), s = !1, l.emit(r, c.DID_UNMOUNT));
77
88
  }
78
- return c;
89
+ return u;
79
90
  }
80
91
  export {
81
- T as $,
82
- _ as MarkupNode,
83
- D as batch,
84
- $ as createContext,
85
- j as createLogger,
86
- E as deepEqual,
87
- V as effect,
88
- v as get,
89
- H as getEnv,
90
- a as m,
91
- C as mount,
92
- x as onLoggerCrash,
93
- B as portal,
94
- G as ref,
95
- W as render,
96
- z as repeat,
97
- J as setEnv,
98
- K as setLogFilter,
99
- Q as setLogLevels,
100
- I as shallowEqual,
101
- R as strictEqual,
102
- A as unless,
103
- q as untracked,
104
- g as when
92
+ q as $,
93
+ E as For,
94
+ G as MarkupNode,
95
+ F as Show,
96
+ S as batch,
97
+ K as createContext,
98
+ Z as createLogger,
99
+ _ as deepEqual,
100
+ $ as effect,
101
+ m as get,
102
+ p as getEnv,
103
+ n as m,
104
+ V as mount,
105
+ M as onLoggerCrash,
106
+ P as portal,
107
+ X as ref,
108
+ j as render,
109
+ H as repeat,
110
+ ee as setEnv,
111
+ ae as setLogFilter,
112
+ te as setLogLevels,
113
+ B as shallowEqual,
114
+ W as strictEqual,
115
+ J as unless,
116
+ z as untracked,
117
+ y as when
105
118
  };
106
119
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/core/views/default-crash-view.ts","../src/core/mount.ts"],"sourcesContent":["import { when, m } from \"../markup.js\";\n\n/**\n * Props passed to the crash view when a crash occurs.\n */\nexport interface CrashViewProps {\n /**\n * JavaScript Error object.\n */\n error: Error;\n\n /**\n * A string to identify the logger that reported this error.\n */\n loggerName: string;\n\n /**\n * Unique identifier to pinpoint the specific view that reported the crash.\n */\n tag?: string;\n\n /**\n * Label for the tag.\n */\n tagName?: string;\n}\n\n/**\n * The crash view displayed unless you specify your own.\n */\nexport function DefaultCrashView(props: CrashViewProps) {\n return m(\"div\", {\n style: {\n backgroundColor: \"#880000\",\n color: \"#fff\",\n padding: \"2rem\",\n position: \"fixed\",\n inset: 0,\n fontSize: \"20px\",\n },\n children: [\n m(\"h1\", { style: { marginBottom: \"0.5rem\" }, children: \"The app has crashed\" }),\n m(\"p\", {\n style: { marginBottom: \"0.25rem\" },\n children: [\n m(\"span\", {\n style: { fontFamily: \"monospace\" },\n children: props.loggerName,\n }),\n when(\n props.tag,\n m(\"span\", {\n style: { fontFamily: \"monospace\", opacity: 0.5 },\n children: ` [${props.tagName ? `${props.tagName}: ` : \"\"}${props.tag}]`,\n }),\n ),\n \" says:\",\n ],\n }),\n m(\"blockquote\", {\n style: {\n backgroundColor: \"#991111\",\n padding: \"0.25em\",\n borderRadius: \"6px\",\n fontFamily: \"monospace\",\n marginBottom: \"1rem\",\n },\n children: [\n m(\"span\", {\n style: {\n display: \"inline-block\",\n backgroundColor: \"red\",\n padding: \"0.1em 0.4em\",\n marginRight: \"0.5em\",\n borderRadius: \"4px\",\n fontSize: \"0.9em\",\n fontWeight: \"bold\",\n },\n children: props.error.name,\n }),\n props.error.message,\n ],\n }),\n m(\"p\", { children: \"Please see the browser console for details.\" }),\n ],\n });\n}\n","import { MOUNT, Router, UNMOUNT } from \"../router/router\";\nimport { assertInstanceOf } from \"../typeChecking\";\nimport type { View } from \"../types\";\nimport { Context, LifecycleEvent } from \"./context\";\nimport { type LoggerCrashProps, onLoggerCrash } from \"./logger\";\nimport { type MarkupNode } from \"./markup\";\nimport { ViewNode } from \"./nodes/view\";\nimport { DefaultCrashView } from \"./views/default-crash-view\";\n\nlet isMounted = false;\n\nexport type UnmountFn = () => Promise<void>;\nexport interface MountOptions {\n crashView?: View<LoggerCrashProps>;\n\n /**\n * An existing Context to use as the root, otherwise a new one will be created.\n * Use this to provide top-level stores and state to the whole app.\n */\n context?: Context;\n}\n\nexport async function mount(view: View<{}>, domNode: Element, options?: MountOptions): Promise<UnmountFn>;\nexport async function mount(router: Router, domNode: Element, options?: MountOptions): Promise<UnmountFn>;\n\nexport async function mount(view: any, rootElement: Element, options?: MountOptions): Promise<UnmountFn> {\n assertInstanceOf(Element, rootElement, \"Expected an element or a selector string. Got type: %t, value: %v\");\n\n if (isMounted) {\n throw new Error(`A Dolla app is already mounted.`);\n }\n\n let rootView: MarkupNode;\n let router: Router | undefined;\n let crashView = options?.crashView ?? DefaultCrashView;\n\n const rootContext = options?.context ?? new Context(\"App\");\n\n onLoggerCrash((props) => {\n if (isMounted) {\n unmount();\n }\n\n // Mount the crash page\n new ViewNode(rootContext, crashView, props).mount(rootElement);\n });\n\n Context.emit(rootContext, LifecycleEvent.WILL_MOUNT);\n\n if (view instanceof Router) {\n // Store router reference so we can unmount it with the app.\n router = view;\n rootView = await router[MOUNT](rootElement, rootContext);\n } else {\n rootView = new ViewNode(rootContext, view, {});\n }\n rootView.mount(rootElement);\n isMounted = true;\n\n Context.emit(rootContext, LifecycleEvent.DID_MOUNT);\n\n async function unmount() {\n if (!isMounted) return;\n\n Context.emit(rootContext, LifecycleEvent.WILL_UNMOUNT);\n\n rootView.unmount(false);\n if (router) {\n await router[UNMOUNT]();\n }\n isMounted = false;\n\n Context.emit(rootContext, LifecycleEvent.DID_UNMOUNT);\n }\n\n return unmount;\n}\n"],"names":["DefaultCrashView","props","m","when","isMounted","mount","view","rootElement","options","assertInstanceOf","rootView","router","crashView","rootContext","Context","onLoggerCrash","unmount","ViewNode","LifecycleEvent","Router","MOUNT","UNMOUNT"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;AAAA,EACpE,CACD;AACH;AC7EA,IAAIE,IAAY;AAgBM,eAAAC,EAAMC,GAAWC,GAAsBC,GAA4C;AAGvG,MAFiBC,EAAA,SAASF,GAAa,mEAAmE,GAEtGH;AACI,UAAA,IAAI,MAAM,iCAAiC;AAG/C,MAAAM,GACAC,GACAC,KAAYJ,KAAA,gBAAAA,EAAS,cAAaR;AAEtC,QAAMa,KAAcL,KAAA,gBAAAA,EAAS,YAAW,IAAIM,EAAQ,KAAK;AAEzD,EAAAC,EAAc,CAACd,MAAU;AACvB,IAAIG,KACMY,EAAA,GAIV,IAAIC,EAASJ,GAAaD,GAAWX,CAAK,EAAE,MAAMM,CAAW;AAAA,EAAA,CAC9D,GAEOO,EAAA,KAAKD,GAAaK,EAAe,UAAU,GAE/CZ,aAAgBa,KAETR,IAAAL,GACTI,IAAW,MAAMC,EAAOS,CAAK,EAAEb,GAAaM,CAAW,KAEvDH,IAAW,IAAIO,EAASJ,GAAaP,GAAM,CAAA,CAAE,GAE/CI,EAAS,MAAMH,CAAW,GACdH,IAAA,IAEJU,EAAA,KAAKD,GAAaK,EAAe,SAAS;AAElD,iBAAeF,IAAU;AACvB,IAAKZ,MAEGU,EAAA,KAAKD,GAAaK,EAAe,YAAY,GAErDR,EAAS,QAAQ,EAAK,GAClBC,KACI,MAAAA,EAAOU,CAAO,EAAE,GAEZjB,IAAA,IAEJU,EAAA,KAAKD,GAAaK,EAAe,WAAW;AAAA,EAAA;AAG/C,SAAAF;AACT;"}
1
+ {"version":3,"file":"index.js","sources":["../src/core/views/for.ts","../src/core/views/show.ts","../src/core/views/default-crash-view.ts","../src/core/mount.ts"],"sourcesContent":["import type { Renderable } from \"../../types\";\nimport type { Context } from \"../context\";\nimport { type Key, RepeatNode } from \"../nodes/repeat\";\nimport { type Signal } from \"../signals\";\n\nexport interface ForProps<T> {\n /**\n * An array of items to render.\n */\n each: Signal<T[]>;\n /**\n * A function to extract a unique key that identifies each item.\n * If no `key` function is passed, object identity (===) will be used.\n */\n key?: (item: T, index: number) => Key;\n /**\n * A render function. Takes the item and its index in signal form and returns something to display for each item.\n */\n children: ($item: Signal<T>, $index: Signal<number>, ctx: Context) => Renderable;\n}\n\nconst defaultKeyFn = (x: any) => x;\n\n/**\n *\n */\nexport function For<T>(props: ForProps<T>, context: Context) {\n return new RepeatNode(context, props.each, props.key ?? defaultKeyFn, props.children);\n}\n","import type { Renderable } from \"../../types\";\nimport type { Context } from \"../context\";\nimport { DynamicNode } from \"../nodes/dynamic\";\nimport { get, type Signal } from \"../signals\";\n\nexport interface ShowProps {\n /**\n * If present, children will be rendered only when this signal holds a truthy value.\n */\n when?: Signal<any>;\n\n /**\n * If present, children will be rendered only when this signal holds a falsy value.\n */\n unless?: Signal<any>;\n\n /**\n * Content to render if conditions permit.\n */\n children: Renderable;\n\n /**\n * Content to render when conditions don't permit `children` to render.\n */\n fallback?: Renderable;\n}\n\n/**\n * Conditionally display children.\n */\nexport function Show(props: ShowProps, context: Context) {\n return new DynamicNode(context, () => {\n let shouldShow = true;\n\n if (props.when != null && props.unless != null) {\n shouldShow = get(props.when) && !get(props.unless);\n } else if (props.when != null) {\n shouldShow = get(props.when);\n } else if (props.unless != null) {\n shouldShow = !get(props.unless);\n }\n\n if (shouldShow) {\n return props.children;\n } else {\n return props.fallback;\n }\n });\n}\n","import { when, m } from \"../markup.js\";\n\n/**\n * Props passed to the crash view when a crash occurs.\n */\nexport interface CrashViewProps {\n /**\n * JavaScript Error object.\n */\n error: Error;\n\n /**\n * A string to identify the logger that reported this error.\n */\n loggerName: string;\n\n /**\n * Unique identifier to pinpoint the specific view that reported the crash.\n */\n tag?: string;\n\n /**\n * Label for the tag.\n */\n tagName?: string;\n}\n\n/**\n * The crash view displayed unless you specify your own.\n */\nexport function DefaultCrashView(props: CrashViewProps) {\n return m(\"div\", {\n style: {\n backgroundColor: \"#880000\",\n color: \"#fff\",\n padding: \"2rem\",\n position: \"fixed\",\n inset: 0,\n fontSize: \"20px\",\n },\n children: [\n m(\"h1\", { style: { marginBottom: \"0.5rem\" }, children: \"The app has crashed\" }),\n m(\"p\", {\n style: { marginBottom: \"0.25rem\" },\n children: [\n m(\"span\", {\n style: { fontFamily: \"monospace\" },\n children: props.loggerName,\n }),\n when(\n props.tag,\n m(\"span\", {\n style: { fontFamily: \"monospace\", opacity: 0.5 },\n children: ` [${props.tagName ? `${props.tagName}: ` : \"\"}${props.tag}]`,\n }),\n ),\n \" says:\",\n ],\n }),\n m(\"blockquote\", {\n style: {\n backgroundColor: \"#991111\",\n padding: \"0.25em\",\n borderRadius: \"6px\",\n fontFamily: \"monospace\",\n marginBottom: \"1rem\",\n },\n children: [\n m(\"span\", {\n style: {\n display: \"inline-block\",\n backgroundColor: \"red\",\n padding: \"0.1em 0.4em\",\n marginRight: \"0.5em\",\n borderRadius: \"4px\",\n fontSize: \"0.9em\",\n fontWeight: \"bold\",\n },\n children: props.error.name,\n }),\n props.error.message,\n ],\n }),\n m(\"p\", { children: \"Please see the browser console for details.\" }),\n ],\n });\n}\n","import { MOUNT, Router, UNMOUNT } from \"../router/router\";\nimport { assertInstanceOf } from \"../typeChecking\";\nimport type { View } from \"../types\";\nimport { Context, LifecycleEvent } from \"./context\";\nimport { type LoggerCrashProps, onLoggerCrash } from \"./logger\";\nimport { type MarkupNode } from \"./markup\";\nimport { ViewNode } from \"./nodes/view\";\nimport { DefaultCrashView } from \"./views/default-crash-view\";\n\nlet isMounted = false;\n\nexport type UnmountFn = () => Promise<void>;\nexport interface MountOptions {\n crashView?: View<LoggerCrashProps>;\n\n /**\n * An existing Context to use as the root, otherwise a new one will be created.\n * Use this to provide top-level stores and state to the whole app.\n */\n context?: Context;\n}\n\nexport async function mount(view: View<{}>, domNode: Element, options?: MountOptions): Promise<UnmountFn>;\nexport async function mount(router: Router, domNode: Element, options?: MountOptions): Promise<UnmountFn>;\n\nexport async function mount(view: any, rootElement: Element, options?: MountOptions): Promise<UnmountFn> {\n assertInstanceOf(Element, rootElement, \"Expected an element or a selector string. Got type: %t, value: %v\");\n\n if (isMounted) {\n throw new Error(`A Dolla app is already mounted.`);\n }\n\n let rootView: MarkupNode;\n let router: Router | undefined;\n let crashView = options?.crashView ?? DefaultCrashView;\n\n const rootContext = options?.context ?? new Context(\"App\");\n\n onLoggerCrash((props) => {\n if (isMounted) {\n unmount();\n }\n\n // Mount the crash page\n new ViewNode(rootContext, crashView, props).mount(rootElement);\n });\n\n Context.emit(rootContext, LifecycleEvent.WILL_MOUNT);\n\n if (view instanceof Router) {\n // Store router reference so we can unmount it with the app.\n router = view;\n rootView = await router[MOUNT](rootElement, rootContext);\n } else {\n rootView = new ViewNode(rootContext, view, {});\n }\n rootView.mount(rootElement);\n isMounted = true;\n\n Context.emit(rootContext, LifecycleEvent.DID_MOUNT);\n\n async function unmount() {\n if (!isMounted) return;\n\n Context.emit(rootContext, LifecycleEvent.WILL_UNMOUNT);\n\n rootView.unmount(false);\n if (router) {\n await router[UNMOUNT]();\n }\n isMounted = false;\n\n Context.emit(rootContext, LifecycleEvent.DID_UNMOUNT);\n }\n\n return unmount;\n}\n"],"names":["defaultKeyFn","x","For","props","context","RepeatNode","Show","DynamicNode","shouldShow","get","DefaultCrashView","m","when","isMounted","mount","view","rootElement","options","assertInstanceOf","rootView","router","crashView","rootContext","Context","onLoggerCrash","unmount","ViewNode","LifecycleEvent","Router","MOUNT","UNMOUNT"],"mappings":";;;;;;;;;AAqBA,MAAMA,IAAe,CAACC,MAAWA;AAKjB,SAAAC,EAAOC,GAAoBC,GAAkB;AACpD,SAAA,IAAIC,EAAWD,GAASD,EAAM,MAAMA,EAAM,OAAOH,GAAcG,EAAM,QAAQ;AACtF;ACEgB,SAAAG,EAAKH,GAAkBC,GAAkB;AAChD,SAAA,IAAIG,EAAYH,GAAS,MAAM;AACpC,QAAII,IAAa;AAUjB,WARIL,EAAM,QAAQ,QAAQA,EAAM,UAAU,OACxCK,IAAaC,EAAIN,EAAM,IAAI,KAAK,CAACM,EAAIN,EAAM,MAAM,IACxCA,EAAM,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M;AAAA,UAAA,CACvB;AAAA,UACDA,EAAM,MAAM;AAAA,QAAA;AAAA,MACd,CACD;AAAA,MACDQ,EAAE,KAAK,EAAE,UAAU,8CAA+C,CAAA;AAAA,IAAA;AAAA,EACpE,CACD;AACH;AC7EA,IAAIE,IAAY;AAgBM,eAAAC,EAAMC,GAAWC,GAAsBC,GAA4C;AAGvG,MAFiBC,EAAA,SAASF,GAAa,mEAAmE,GAEtGH;AACI,UAAA,IAAI,MAAM,iCAAiC;AAG/C,MAAAM,GACAC,GACAC,KAAYJ,KAAA,gBAAAA,EAAS,cAAaP;AAEtC,QAAMY,KAAcL,KAAA,gBAAAA,EAAS,YAAW,IAAIM,EAAQ,KAAK;AAEzD,EAAAC,EAAc,CAACrB,MAAU;AACvB,IAAIU,KACMY,EAAA,GAIV,IAAIC,EAASJ,GAAaD,GAAWlB,CAAK,EAAE,MAAMa,CAAW;AAAA,EAAA,CAC9D,GAEOO,EAAA,KAAKD,GAAaK,EAAe,UAAU,GAE/CZ,aAAgBa,KAETR,IAAAL,GACTI,IAAW,MAAMC,EAAOS,CAAK,EAAEb,GAAaM,CAAW,KAEvDH,IAAW,IAAIO,EAASJ,GAAaP,GAAM,CAAA,CAAE,GAE/CI,EAAS,MAAMH,CAAW,GACdH,IAAA,IAEJU,EAAA,KAAKD,GAAaK,EAAe,SAAS;AAElD,iBAAeF,IAAU;AACvB,IAAKZ,MAEGU,EAAA,KAAKD,GAAaK,EAAe,YAAY,GAErDR,EAAS,QAAQ,EAAK,GAClBC,KACI,MAAAA,EAAOU,CAAO,EAAE,GAEZjB,IAAA,IAEJU,EAAA,KAAKD,GAAaK,EAAe,WAAW;AAAA,EAAA;AAG/C,SAAAF;AACT;"}
@@ -1,4 +1,4 @@
1
- import { d as n } from "./markup-CX27GJ1M.js";
1
+ import { d as n } from "./markup-UzKSsawX.js";
2
2
  import { F as m } from "./fragment-BahD_BJA.js";
3
3
  function u(e, r, t, o, a, i) {
4
4
  return new n(e, t != null ? { ...r, key: t } : r);
@@ -1,4 +1,4 @@
1
- import { d as u } from "./markup-CX27GJ1M.js";
1
+ import { d as u } from "./markup-UzKSsawX.js";
2
2
  import { F as m } from "./fragment-BahD_BJA.js";
3
3
  function o(t, n, r) {
4
4
  return new u(t, r != null ? { ...n, key: r } : n);
@@ -3,8 +3,8 @@ var B = (i) => {
3
3
  throw TypeError(i);
4
4
  };
5
5
  var nt = (i, o, t) => o in i ? it(i, o, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[o] = t;
6
- var a = (i, o, t) => nt(i, typeof o != "symbol" ? o + "" : o, t), V = (i, o, t) => o.has(i) || B("Cannot " + t);
7
- var O = (i, o, t) => (V(i, o, "read from private field"), t ? t.call(i) : o.get(i)), j = (i, o, t) => o.has(i) ? B("Cannot add the same private member more than once") : o instanceof WeakSet ? o.add(i) : o.set(i, t), T = (i, o, t, e) => (V(i, o, "write to private field"), e ? e.call(i, t) : o.set(i, t), t);
6
+ var a = (i, o, t) => nt(i, typeof o != "symbol" ? o + "" : o, t), j = (i, o, t) => o.has(i) || B("Cannot " + t);
7
+ var O = (i, o, t) => (j(i, o, "read from private field"), t ? t.call(i) : o.get(i)), V = (i, o, t) => o.has(i) ? B("Cannot add the same private member more than once") : o instanceof WeakSet ? o.add(i) : o.set(i, t), T = (i, o, t, e) => (j(i, o, "write to private field"), e ? e.call(i, t) : o.set(i, t), t);
8
8
  import { c as m, t as rt, i as C, b as D } from "./typeChecking-CbltMOUt.js";
9
9
  import { u as I, g as x, f as Y, h as M, e as v, t as J, o as ct, i as at, b as ht, $ as _, d as ut } from "./signals-gCwiIe5X.js";
10
10
  import { c as lt, g as dt } from "./logger-Bl496yfY.js";
@@ -82,7 +82,7 @@ var z, F, H, Z, K, N;
82
82
  K = U, Z = d, H = b, F = y, z = w;
83
83
  const L = class L {
84
84
  constructor(o, t) {
85
- j(this, N);
85
+ V(this, N);
86
86
  a(this, K);
87
87
  a(this, Z, new ft(this));
88
88
  a(this, H);
@@ -215,24 +215,30 @@ const L = class L {
215
215
  }
216
216
  }
217
217
  getState(o, t) {
218
- var e;
219
- if (arguments.length > 0) {
220
- let s = this, n;
221
- for (; n = (e = s[w]) == null ? void 0 : e.get(o), n === void 0 && s[b] != null; )
222
- s = s[b];
223
- if (n === void 0) {
224
- if (arguments.length > 1)
225
- return t;
226
- throw new Error(`Expected a value for '${String(o)}' but got undefined.`);
227
- }
228
- return n;
229
- } else {
230
- let s = this;
231
- const n = [];
232
- for (; s[w] && n.push(...s[w].entries()), s[b] != null; )
233
- s = s[b];
234
- return new Map(n.reverse());
218
+ var c;
219
+ const e = (t == null ? void 0 : t.immediate) ?? !1;
220
+ let s = this, n;
221
+ for (; n = (c = s[w]) == null ? void 0 : c.get(o), n === void 0 && !e && s[b] != null; )
222
+ s = s[b];
223
+ if (n === void 0) {
224
+ if (t != null && Object.hasOwn(t, "fallback"))
225
+ return t.fallback;
226
+ throw new Error(`Expected a value for '${String(o)}' but got undefined.`);
235
227
  }
228
+ return n;
229
+ }
230
+ /**
231
+ * Returns a Map containing all state values available to this context.
232
+ *
233
+ * Pass `options.immediate` to only include state stored on this context.
234
+ * By default all state stored on parent contexts is also included.
235
+ */
236
+ getStateMap(o) {
237
+ let t = this;
238
+ const e = (o == null ? void 0 : o.immediate) ?? !1, s = [];
239
+ for (; t[w] && s.push(...t[w].entries()), !e && t[b] != null; )
240
+ t = t[b];
241
+ return new Map(s.reverse());
236
242
  }
237
243
  setState(...o) {
238
244
  if (this[w] || (this[w] = /* @__PURE__ */ new Map()), o.length === 2)
@@ -448,8 +454,8 @@ class bt extends k {
448
454
  a(this, "ref");
449
455
  // Prevents 'onClickOutside' handlers from firing in the same cycle in which the element is connected.
450
456
  a(this, "canClickAway", !1);
451
- if (this.tag = e, this.props = s, this.context = f.linked(t, q.bind(this)), e.toLowerCase() === "svg" && this.context.setState(P, !0), this.context.getState(P, !1) ? this.root = document.createElementNS("http://www.w3.org/2000/svg", e) : this.root = document.createElement(e), dt() === "development") {
452
- const c = this.context.getState(Q, null);
457
+ if (this.tag = e, this.props = s, this.context = f.linked(t, q.bind(this)), e.toLowerCase() === "svg" && this.context.setState(P, !0), this.context.getState(P, { fallback: !1 }) ? this.root = document.createElementNS("http://www.w3.org/2000/svg", e) : this.root = document.createElement(e), dt() === "development") {
458
+ const c = this.context.getState(Q, { fallback: null });
453
459
  c && (this.root.dataset.view = c.context.getName());
454
460
  }
455
461
  if (s.mixin)
@@ -557,7 +563,7 @@ class bt extends k {
557
563
  this.attachProp(n, (c) => {
558
564
  c == null ? t.removeAttribute(s) : t.setAttribute(s, String(c));
559
565
  });
560
- else if (this.context.getState(P, !1))
566
+ else if (this.context.getState(P, { fallback: !1 }))
561
567
  this.attachProp(n, (c) => {
562
568
  c != null ? t.setAttribute(s, String(e[s])) : t.removeAttribute(s);
563
569
  });
@@ -1016,6 +1022,7 @@ export {
1016
1022
  A as D,
1017
1023
  g as L,
1018
1024
  k as M,
1025
+ vt as R,
1019
1026
  X as V,
1020
1027
  Tt as a,
1021
1028
  Nt as b,
@@ -1027,4 +1034,4 @@ export {
1027
1034
  Ot as u,
1028
1035
  kt as w
1029
1036
  };
1030
- //# sourceMappingURL=markup-CX27GJ1M.js.map
1037
+ //# sourceMappingURL=markup-UzKSsawX.js.map