@expressive/react 0.74.2-canary.0 → 0.75.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/dist/esm/component.js +185 -0
- package/dist/esm/component.js.map +1 -0
- package/dist/esm/context.js +23 -19
- package/dist/esm/context.js.map +1 -1
- package/dist/esm/index.js +7 -8
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/state.js +109 -144
- package/dist/esm/state.js.map +1 -1
- package/dist/index.d.ts +100 -31
- package/dist/index.js +252 -25
- package/dist/index.js.map +1 -1
- package/dist/state.d.ts +65 -112
- package/dist/state.js +110 -144
- package/dist/state.js.map +1 -1
- package/package.json +3 -13
- package/dist/chunk-BE-pF4vm.js +0 -34
- package/dist/context-DT3kwoQN.js +0 -62
- package/dist/context-DT3kwoQN.js.map +0 -1
- package/dist/esm/jsx-dev-runtime.js +0 -10
- package/dist/esm/jsx-dev-runtime.js.map +0 -1
- package/dist/esm/jsx-runtime.js +0 -56
- package/dist/esm/jsx-runtime.js.map +0 -1
- package/dist/jsx-dev-runtime.d.ts +0 -10
- package/dist/jsx-dev-runtime.js +0 -19
- package/dist/jsx-dev-runtime.js.map +0 -1
- package/dist/jsx-runtime.d.ts +0 -43
- package/dist/jsx-runtime.js +0 -67
- package/dist/jsx-runtime.js.map +0 -1
package/dist/esm/state.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","names":[],"sources":["../../src/state.ts"],"sourcesContent":["import { State, Context, watch, event } from '@expressive/state';\nimport { ReactNode } from 'react';\nimport { provide, Layers } from './context';\n\nexport const Pragma = {} as {\n useState<S>(initial: () => S): [S, (next: (previous: S) => S) => void];\n useEffect(effect: () => () => void, deps?: any[]): void;\n createElement(type: any, props?: any, ...children: any[]): any;\n};\n\n/** Type may not be undefined - instead will be null. */\ntype NoVoid<T> = T extends undefined | void ? null : T;\n\nconst OUTER = new WeakMap<object, Context>();\nconst PROPS = new WeakMap<object, ComponentProps<any>>();\n\ntype ForceRefresh = {\n /** Request a refresh for current component. */\n (): void;\n\n /**\n * Request a refresh and again after promise either resolves or rejects.\n *\n * @param waitFor Promise to wait for.\n * @returns Promise which resolves, after refresh, to same value as `waitFor`.\n */\n <T = void>(waitFor: Promise<T>): Promise<T>;\n\n /**\n * Request refresh before and after async function.\n * A refresh will occur both before and after the given function.\n *\n * **Note:** Any actions performed before first `await` will occur prior to refresh.\n *\n * @param invoke Async function to invoke.\n * @returns Promise which resolves returned value after refresh.\n */\n <T = void>(invoke: () => Promise<T>): Promise<T>;\n};\n\ntype GetFactory<T extends State, R> = (\n this: T,\n current: T,\n refresh: ForceRefresh\n) => R;\n\ntype GetEffect<T extends State> = (\n this: T,\n current: T,\n refresh: ForceRefresh\n) => null;\n\ntype UseArgs<T extends State> = T extends {\n use(...props: infer P): any;\n}\n ? P\n : State.Args<T>;\n\ntype Props<T extends State> = {\n [K in Exclude<keyof T, keyof Component>]?: T[K];\n};\n\ntype Render<T extends State, P extends object> = ((\n props: P & Props<T>,\n self: T\n) => ReactNode) &\n PropsValid<P, T>;\n\ntype Overlap<P extends object, V extends object> = Extract<keyof P, keyof V>;\n\ntype PropsConflicting<P extends object, V extends object> = {\n [K in Overlap<P, V>]: [P[K]] extends [V[K]] ? never : K;\n}[Overlap<P, V>];\n\ntype PropsValid<P extends object, T extends State> = [\n PropsConflicting<P, Props<T>>\n] extends [never]\n ? unknown\n : never;\n\ntype ComponentProps<T extends State> = Readonly<\n Props<T> & {\n /**\n * Callback for newly created instance. Only called once.\n * @returns Callback to run when instance is destroyed.\n */\n is?: (instance: T) => void;\n\n /**\n * A fallback react tree to show when suspended.\n * If not provided, `fallback` property of the State will be used.\n */\n fallback?: React.ReactNode;\n\n /**\n * Children to render within component. Will be passed as `children` prop.\n */\n children?: React.ReactNode;\n }\n>;\n\ninterface Component<P = {}> extends ReactState {\n readonly props: ComponentProps<this> & P;\n context: Context;\n state: State.Values<this>;\n fallback?: ReactNode;\n\n render(): ReactNode;\n\n /** @deprecated Only for React JSX compatibility in typescript and nonfunctional. */\n setState: (state: any, callback?: () => void) => void;\n\n /** @deprecated Only for React JSX compatibility in typescript and nonfunctional. */\n forceUpdate: (callback?: () => void) => void;\n}\n\ntype ComponentType<T, P = {}> = State.Type<T & Component<P>>;\n\ndeclare namespace ReactState {\n export import Extends = State.Extends;\n export import Type = State.Type;\n export import Args = State.Args;\n export import Init = State.Init;\n export import Assign = State.Assign;\n export import Field = State.Field;\n export import Event = State.Event;\n export import Export = State.Export;\n export import Value = State.Value;\n export import Setter = State.Setter;\n export import OnEvent = State.OnEvent;\n export import OnUpdate = State.OnUpdate;\n export import Values = State.Values;\n export import Partial = State.Partial;\n export import Ref = State.Ref;\n export import Effect = State.Effect;\n export import EffectCallback = State.EffectCallback;\n\n export { GetFactory, GetEffect, UseArgs, Props, Component };\n}\n\nabstract class ReactState extends State {\n /**\n * Optional hook is called when State.use() is invoked within a React component.\n *\n * This is called *every render* of the component, and will intercept\n * arguments which would otherwise be merged into the State.\n *\n * @param props Arguments passed to State.use().\n */\n protected use?(...props: any[]): Promise<void> | void;\n\n /**\n * Create and manage instance of this State within React component.\n *\n * @param args Arguments to pass to constructor or `use` method (if defined).\n * @returns Managed instance of this State.\n */\n static use<T extends ReactState>(\n this: State.Type<T>,\n ...args: UseArgs<T>\n ): T {\n const ambient = Context.use();\n const state = Pragma.useState(() => {\n let ready: boolean | undefined;\n let active: T;\n\n let use = (...args: State.Args<T>): Promise<unknown> | void =>\n Promise.all(\n args\n .flat()\n .map(\n (arg) =>\n typeof arg == 'object' && instance.set(arg as State.Assign<T>)\n )\n );\n\n // Create instance - pass args to constructor if no use method\n const instance = new this((x) => {\n if (x instanceof ReactState && x.use) {\n use = x.use?.bind(x);\n use(...args);\n } else return args;\n });\n\n const context = ambient.push(instance);\n\n watch(instance, (current) => {\n active = current;\n\n if (ready) state[1]((x) => x.bind(null));\n });\n\n function didMount() {\n ready = true;\n return () => {\n context.pop();\n instance.set(null);\n };\n }\n\n return (...args: State.Args<T>) => {\n Pragma.useEffect(didMount, []);\n\n if (ready) {\n ready = false;\n\n Promise.resolve(use(...args)).finally(() => (ready = true));\n }\n\n return active;\n };\n });\n\n return state[0](...args);\n }\n\n /** Fetch instance of this class from context. */\n static get<T extends State>(this: State.Extends<T>): T;\n\n /** Fetch instance of this class optionally. */\n static get<T extends State>(\n this: State.Extends<T>,\n required: false\n ): T | undefined;\n\n /** Fetch instance of this class from context. */\n static get<T extends State>(\n this: State.Extends<T>,\n requireValues: true\n ): Required<T>;\n\n static get<T extends State, R>(\n this: State.Extends<T>,\n factory: GetFactory<T, Promise<R> | R>\n ): NoVoid<R>;\n\n // TODO: eagerly match this so any nulls are caught - would prevent updates.\n static get<T extends State>(\n this: State.Extends<T>,\n factory: GetEffect<T>\n ): null;\n\n static get<T extends State, R>(\n this: State.Extends<T>,\n argument?: boolean | GetFactory<T, unknown>\n ) {\n const context = Context.use();\n const state = Pragma.useState(() => {\n const instance = context.get(this);\n\n if (!instance)\n if (argument === false) return () => undefined;\n else throw new Error(`Could not find ${this} in context.`);\n\n let ready: boolean | undefined;\n let value: any;\n\n function render() {\n state[1]((x) => x.bind(null));\n }\n\n function refresh<T>(action?: Promise<T> | (() => Promise<T>)): any {\n if (typeof action == 'function') action = action();\n\n render();\n\n if (action) return action.finally(render);\n }\n\n const unwatch = watch(\n instance,\n (current) => {\n if (typeof argument === 'function') {\n const next = argument.call(current, current, refresh);\n\n if (next === value) return;\n\n value = next;\n } else value = current;\n\n if (ready) render();\n },\n argument === true\n );\n\n if (value instanceof Promise) {\n let error: Error | undefined;\n\n unwatch();\n\n value\n .then(\n (x) => (value = x),\n (e) => (error = e)\n )\n .finally(render);\n\n value = null;\n\n return () => {\n if (error) throw error;\n\n return value === undefined ? null : value;\n };\n }\n\n if (value === null) {\n unwatch();\n return () => null;\n }\n\n function onMount() {\n ready = true;\n return unwatch;\n }\n\n return () => {\n Pragma.useEffect(onMount, []);\n return value === undefined ? null : value;\n };\n });\n\n return state[0]() as R;\n }\n\n static as<T extends State, P extends object = {}>(\n this: State.Type<T>,\n render: Render<T, P>\n ): ComponentType<T, P>;\n\n static as<T extends State, P extends object = {}>(\n this: ComponentType<T, P>,\n withProps: Props<T>\n ): ComponentType<T, P>;\n\n static as<T extends State>(\n this: State.Type<T>,\n withProps: Props<T>\n ): ComponentType<T, {}>;\n\n static as<T extends State, P>(\n this: State.Type<T>,\n argument: ((props: P, self: T) => ReactNode) | Props<T>\n ) {\n const Type = this as unknown as State.Type<State>;\n const render = typeof argument === 'function' ? argument : undefined;\n\n class ReactType extends Type {\n static contextType = Layers;\n\n get props(): ComponentProps<this> {\n return PROPS.get(this)!;\n }\n\n private set props(props: ComponentProps<this>) {\n PROPS.set(this, props);\n this.set(props as {});\n }\n\n get context() {\n return Context.get(this)!;\n }\n\n private set context(context: Context) {\n if (OUTER.get(this) === context) return;\n\n OUTER.set(this, context);\n context.push(this);\n }\n\n get state() {\n return this.get();\n }\n\n private set state(_state: State.Values<this>) {}\n\n render!: () => ReactNode;\n fallback?: ReactNode = undefined;\n\n constructor(nextProps: any, ...rest: any[]) {\n const { is } = nextProps;\n const defaults = typeof argument === 'object' ? argument : {};\n\n if (rest[0] instanceof Context) rest.shift();\n\n super(nextProps, defaults, is, rest);\n PROPS.set(this, nextProps);\n\n if (render) {\n const Self = Render.bind(this, render as any);\n this.render = () => Pragma.createElement(Self);\n } else if (!this.render) {\n this.render = () =>\n provide(\n this.context,\n this.props.children || null,\n this.props.fallback,\n String(this)\n );\n }\n }\n\n /** @deprecated Only for React JSX compatibility in typescript and nonfunctional. */\n setState!: (state: any, callback?: () => void) => void;\n\n /** @deprecated Only for React JSX compatibility in typescript and nonfunctional. */\n forceUpdate!: (callback?: () => void) => void;\n }\n\n Object.defineProperty(ReactType, 'name', { value: 'React' + this.name });\n Object.defineProperty(ReactType.prototype, 'isReactComponent', {\n get: () => true\n });\n\n return ReactType;\n }\n}\n\nfunction Render<T extends Component, P extends State.Assign<T>>(\n this: T,\n render: (props: P, self: T) => ReactNode\n) {\n const state = Pragma.useState(() => {\n event(this);\n\n const { context } = this;\n\n let ready: boolean | undefined;\n let active: T;\n\n watch(this, (current) => {\n active = current as T;\n\n if (ready) state[1]((x) => x.bind(null));\n });\n\n const didMount = () => {\n ready = true;\n return () => {\n context.pop();\n this.set(null);\n };\n };\n\n const View = () => render.call(active, this.props as any, active);\n\n return () => {\n ready = false;\n\n Pragma.useEffect(didMount, []);\n setTimeout(() => (ready = true), 0);\n\n return provide(\n context,\n Pragma.createElement(View),\n this.props.fallback,\n String(this)\n );\n };\n });\n\n return state[0]();\n}\n\nexport { ReactState };\n"],"mappings":";;;;AAIA,MAAa,SAAS,EAAE;AASxB,MAAM,wBAAQ,IAAI,SAA0B;AAC5C,MAAM,wBAAQ,IAAI,SAAsC;AA8HxD,IAAe,aAAf,MAAe,mBAAmB,MAAM;;;;;;;CAiBtC,OAAO,IAEL,GAAG,MACA;EACH,MAAM,UAAU,QAAQ,KAAK;EAC7B,MAAM,QAAQ,OAAO,eAAe;GAClC,IAAI;GACJ,IAAI;GAEJ,IAAI,OAAO,GAAG,SACZ,QAAQ,IACN,KACG,MAAM,CACN,KACE,QACC,OAAO,OAAO,YAAY,SAAS,IAAI,IAAuB,CACjE,CACJ;GAGH,MAAM,WAAW,IAAI,MAAM,MAAM;AAC/B,QAAI,aAAa,cAAc,EAAE,KAAK;AACpC,WAAM,EAAE,KAAK,KAAK,EAAE;AACpB,SAAI,GAAG,KAAK;UACP,QAAO;KACd;GAEF,MAAM,UAAU,QAAQ,KAAK,SAAS;AAEtC,SAAM,WAAW,YAAY;AAC3B,aAAS;AAET,QAAI,MAAO,OAAM,IAAI,MAAM,EAAE,KAAK,KAAK,CAAC;KACxC;GAEF,SAAS,WAAW;AAClB,YAAQ;AACR,iBAAa;AACX,aAAQ,KAAK;AACb,cAAS,IAAI,KAAK;;;AAItB,WAAQ,GAAG,SAAwB;AACjC,WAAO,UAAU,UAAU,EAAE,CAAC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O,OAAM,IAAI,MAAM,EAAE,KAAK,KAAK,CAAC;IACxC;EAEF,MAAM,iBAAiB;AACrB,WAAQ;AACR,gBAAa;AACX,YAAQ,KAAK;AACb,SAAK,IAAI,KAAK;;;EAIlB,MAAM,aAAa,OAAO,KAAK,QAAQ,KAAK,OAAc,OAAO;AAEjE,eAAa;AACX,WAAQ;AAER,UAAO,UAAU,UAAU,EAAE,CAAC;AAC9B,oBAAkB,QAAQ,MAAO,EAAE;AAEnC,UAAO,QACL,SACA,OAAO,cAAc,KAAK,EAC1B,KAAK,MAAM,UACX,OAAO,KAAK,CACb;;GAEH;AAEF,QAAO,MAAM,IAAI"}
|
|
1
|
+
{"version":3,"file":"state.js","names":[],"sources":["../../src/state.ts"],"sourcesContent":["import { State, Context, watch } from '@expressive/state';\n\nexport const Pragma = {} as {\n createElement(type: any, props?: any, ...children: any[]): any;\n useState<S>(initial: S | (() => S)): [S, (next: (previous: S) => S) => void];\n useEffect(effect: () => (() => void) | void, deps?: any[]): void;\n useRef<T>(initial: T): { current: T };\n};\n\n/** Type may not be undefined - instead will be null. */\ntype NoVoid<T> = T extends undefined | void ? null : T;\n\ndeclare module '@expressive/state' {\n interface UseState extends State {\n /**\n * Optional hook called when State.use() is invoked within a React component.\n *\n * This is called *every render* of the component, and will intercept\n * arguments which would otherwise be passed into the State constructor.\n *\n * @param props Arguments passed to State.use().\n */\n use?(...props: any[]): Promise<void> | void;\n }\n\n namespace State {\n type ForceRefresh = {\n /** Request a refresh for current component. */\n (): void;\n\n /**\n * Request a refresh and again after promise either resolves or rejects.\n *\n * @param waitFor Promise to wait for.\n * @returns Promise which resolves, after refresh, to same value as `waitFor`.\n */\n <T = void>(waitFor: Promise<T>): Promise<T>;\n\n /**\n * Request refresh before and after async function.\n * A refresh will occur both before and after the given function.\n *\n * **Note:** Any actions performed before first `await` will occur prior to refresh.\n *\n * @param invoke Async function to invoke.\n * @returns Promise which resolves returned value after refresh.\n */\n <T = void>(invoke: () => Promise<T>): Promise<T>;\n };\n\n type GetFactory<T extends State, R> = (\n this: T,\n current: T,\n refresh: ForceRefresh\n ) => R;\n\n type GetEffect<T extends State> = (\n this: T,\n current: T,\n refresh: ForceRefresh\n ) => null;\n\n type UseArgs<T extends State> = T extends {\n use(...props: infer P): any;\n }\n ? P\n : State.Args<T>;\n\n /**\n * Create and manage instance of this State within React component.\n *\n * @param args Arguments to pass to constructor or `use` method (if defined).\n * @returns Managed instance of this State.\n */\n function use<T extends UseState>(\n this: State.Type<T>,\n ...args: UseArgs<T>\n ): T;\n\n /** Fetch instance of this class from context. */\n function get<T extends State>(this: State.Extends<T>): T;\n\n /** Fetch instance of this class optionally. */\n function get<T extends State>(\n this: State.Extends<T>,\n required: false\n ): T | undefined;\n\n /** Fetch instance of this class from context. */\n function get<T extends State>(\n this: State.Extends<T>,\n requireValues: true\n ): Required<T>;\n\n function get<T extends State, R>(\n this: State.Extends<T>,\n factory: GetFactory<T, Promise<R> | R>\n ): NoVoid<R>;\n\n function get<T extends State>(\n this: State.Extends<T>,\n factory: GetEffect<T>\n ): null;\n }\n}\n\nState.use = function <T extends State>(\n this: State.Type<T>,\n ...args: State.UseArgs<T>\n) {\n const outer = Context.get();\n const ref = Pragma.useRef<((args: State.Args<T>) => T) | null>(null);\n const render = ref.current || (ref.current = init(this));\n\n return render(args);\n\n function init(Type: State.Type<T>) {\n const add = (arg: unknown) =>\n typeof arg == 'object' && instance.set(arg as State.Assign<T>);\n\n let use = (...args: State.Args<T>) => Promise.all(args.flat().map(add));\n\n const instance = new Type((x) => {\n if ('use' in x && typeof x.use == 'function') {\n (use = x.use.bind(x))(...args);\n } else {\n return args;\n }\n });\n\n const context = outer.push(instance);\n\n let ready = false;\n let active: T;\n\n return (args: State.Args<T>) => {\n Pragma.useEffect(() => {\n ready = true;\n }, []);\n\n useMount((refresh) => {\n watch(instance, (current) => {\n active = current;\n\n if (ready) refresh();\n });\n\n return () => {\n context.pop();\n instance.set(null);\n };\n });\n\n if (ready) {\n ready = false;\n Promise.resolve(use(...args)).finally(() => {\n ready = true;\n });\n }\n\n return active;\n };\n }\n};\n\nState.get = function <T extends State>(\n this: State.Extends<T>,\n argument?: boolean | State.GetFactory<T, unknown>\n) {\n const ref = Pragma.useRef<(() => any) | null>(null);\n const next = Pragma.useState(0)[1];\n const context = Context.get();\n const render = ref.current || (ref.current = init(this));\n\n return render();\n\n function init(Type: State.Extends<T>) {\n let instance: T | undefined;\n let unwatch: (() => void) | undefined;\n let mounted = false;\n let pending = false;\n let value: any;\n\n function update() {\n pending = false;\n next((x) => x + 1);\n }\n\n function refresh<T>(action?: Promise<T> | (() => Promise<T>)): any {\n if (typeof action == 'function') action = action();\n update();\n if (action instanceof Promise) return action.finally(update);\n }\n\n function release() {\n unwatch?.();\n unsubscribe();\n unwatch = undefined;\n instance = undefined;\n }\n\n const unsubscribe = context.get(Type, (next) => {\n unwatch?.();\n unwatch = watch(\n (instance = next),\n (current, changed) => {\n if (typeof argument === 'function') {\n const next = argument.call(current, current, refresh);\n if (next === value) return;\n value = next;\n } else {\n value = current;\n }\n\n if (changed.length) update();\n },\n argument === true\n );\n\n if (mounted) {\n pending = true;\n queueMicrotask(() => pending && update());\n }\n\n return release;\n });\n\n if (!instance) {\n release();\n if (argument === false) return () => undefined;\n throw new Error(`Could not find ${Type} in context.`);\n }\n\n if (value instanceof Promise) {\n let error: Error | undefined;\n\n release();\n\n value\n .then(\n (x) => (value = x),\n (e) => (error = e)\n )\n .finally(update);\n\n value = null;\n\n return () => {\n if (error) throw error;\n return value === undefined ? null : value;\n };\n }\n\n if (value === null) {\n release();\n return () => null;\n }\n\n return () => {\n pending = false;\n Pragma.useEffect(() => {\n mounted = true;\n }, []);\n useMount(() => release);\n return value === undefined ? null : value;\n };\n }\n};\n\n/**\n * useEffect which tolerates react StrictMode double-invoking effects on mount.\n */\nexport function useMount(\n callback: (refresh: () => void) => (() => void) | void\n) {\n const { current } = Pragma.useRef(\n {} as {\n ready?: boolean;\n mounts: number;\n unmount: (() => void) | void;\n update: (next: (previous: number) => number) => void;\n }\n );\n\n current.update = Pragma.useState(() => {\n if (!current.mounts) {\n current.mounts = 0;\n current.unmount = callback(() => {\n if (current.ready) current.update((x) => x + 1);\n });\n }\n return current.mounts++;\n })[1];\n\n Pragma.useEffect(() => {\n current.ready = true;\n return () => {\n if (!--current.mounts) current.unmount?.();\n };\n }, []);\n}\n\nexport { State };\n"],"mappings":";;;AAEA,MAAa,SAAS,EAAE;AAwGxB,MAAM,MAAM,SAEV,GAAG,MACH;CACA,MAAM,QAAQ,QAAQ,KAAK;CAC3B,MAAM,MAAM,OAAO,OAA4C,KAAK;AAGpE,SAFe,IAAI,YAAY,IAAI,UAAU,KAAK,KAAK,GAEzC,KAAK;CAEnB,SAAS,KAAK,MAAqB;EACjC,MAAM,OAAO,QACX,OAAO,OAAO,YAAY,SAAS,IAAI,IAAuB;EAEhE,IAAI,OAAO,GAAG,SAAwB,QAAQ,IAAI,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC;EAEvE,MAAM,WAAW,IAAI,MAAM,MAAM;AAC/B,OAAI,SAAS,KAAK,OAAO,EAAE,OAAO,WAChC,EAAC,MAAM,EAAE,IAAI,KAAK,EAAE,EAAE,GAAG,KAAK;OAE9B,QAAO;IAET;EAEF,MAAM,UAAU,MAAM,KAAK,SAAS;EAEpC,IAAI,QAAQ;EACZ,IAAI;AAEJ,UAAQ,SAAwB;AAC9B,UAAO,gBAAgB;AACrB,YAAQ;MACP,EAAE,CAAC;AAEN,aAAU,YAAY;AACpB,UAAM,WAAW,YAAY;AAC3B,cAAS;AAET,SAAI,MAAO,UAAS;MACpB;AAEF,iBAAa;AACX,aAAQ,KAAK;AACb,cAAS,IAAI,KAAK;;KAEpB;AAEF,OAAI,OAAO;AACT,YAAQ;AACR,YAAQ,QAAQ,IAAI,GAAG,KAAK,CAAC,CAAC,cAAc;AAC1C,aAAQ;MACR;;AAGJ,UAAO;;;;AAKb,MAAM,MAAM,SAEV,UACA;CACA,MAAM,MAAM,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AAa;AACX,aAAU;AACV,UAAO,gBAAgB;AACrB,cAAU;MACT,EAAE,CAAC;AACN,kBAAe,QAAQ;AACvB,UAAO,UAAU,SAAY,OAAO;;;;;;;AAQ1C,SAAgB,SACd,UACA;CACA,MAAM,EAAE,YAAY,OAAO,OACzB,EAAE,CAMH;AAED,SAAQ,SAAS,OAAO,eAAe;AACrC,MAAI,CAAC,QAAQ,QAAQ;AACnB,WAAQ,SAAS;AACjB,WAAQ,UAAU,eAAe;AAC/B,QAAI,QAAQ,MAAO,SAAQ,QAAQ,MAAM,IAAI,EAAE;KAC/C;;AAEJ,SAAO,QAAQ;GACf,CAAC;AAEH,QAAO,gBAAgB;AACrB,UAAQ,QAAQ;AAChB,eAAa;AACX,OAAI,CAAC,EAAE,QAAQ,OAAQ,SAAQ,WAAW;;IAE3C,EAAE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Context, Context as Context$1, Observable, State, get, ref, set, use } from "@expressive/state";
|
|
1
|
+
import { State, State as State$1 } from "./state";
|
|
3
2
|
import * as react from "react";
|
|
4
|
-
import {
|
|
3
|
+
import React, { ReactNode } from "react";
|
|
4
|
+
import { Context, Context as Context$1, Observable, State as State$2, def, get, ref, set } from "@expressive/state";
|
|
5
5
|
|
|
6
6
|
//#region src/context.d.ts
|
|
7
|
-
declare module '@expressive/state' {
|
|
8
|
-
namespace Context {
|
|
9
|
-
function use(create?: true): Context$1;
|
|
10
|
-
function use(create: boolean): Context$1 | null | undefined;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
7
|
declare namespace Consumer {
|
|
14
|
-
type Props<T extends State> = {
|
|
15
|
-
/** Type of controller to fetch from context. */for: State.Extends<T>;
|
|
8
|
+
type Props<T extends State$2> = {
|
|
9
|
+
/** Type of controller to fetch from context. */for: State$2.Extends<T>;
|
|
16
10
|
/**
|
|
17
11
|
* Render function, will receive instance of desired controller.
|
|
18
12
|
*
|
|
@@ -23,15 +17,10 @@ declare namespace Consumer {
|
|
|
23
17
|
children: (value: T) => ReactNode | void;
|
|
24
18
|
};
|
|
25
19
|
}
|
|
26
|
-
declare function Consumer<T extends State>(props: Consumer.Props<T>): string | number | bigint | boolean | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<ReactNode> | react.ReactPortal | null;
|
|
20
|
+
declare function Consumer<T extends State$2>(props: Consumer.Props<T>): string | number | bigint | boolean | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<ReactNode> | react.ReactPortal | null;
|
|
27
21
|
declare namespace Provider {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
for: Context$1.Accept<T>;
|
|
31
|
-
/**
|
|
32
|
-
* Callback to run for each provided State.
|
|
33
|
-
*/
|
|
34
|
-
forEach?: Context$1.Expect<T>;
|
|
22
|
+
type ForEach<T> = (state: T) => void | (() => void);
|
|
23
|
+
interface SharedProps {
|
|
35
24
|
/**
|
|
36
25
|
* Children to render within this Provider.
|
|
37
26
|
*/
|
|
@@ -44,23 +33,103 @@ declare namespace Provider {
|
|
|
44
33
|
*/
|
|
45
34
|
name?: string | undefined;
|
|
46
35
|
}
|
|
36
|
+
type ForSingleProps<T extends State$2> = SharedProps & {
|
|
37
|
+
for: T | State$2.Type<T>;
|
|
38
|
+
is: (instance: T) => void;
|
|
39
|
+
} & { [K in State$2.Field<T>]?: T[K] };
|
|
40
|
+
type ForMultipleProps<T extends State$2> = SharedProps & {
|
|
41
|
+
for: Context$1.Accept<T>;
|
|
42
|
+
is?: ForEach<T>;
|
|
43
|
+
};
|
|
44
|
+
type Props<T extends State$2 = State$2> = ForSingleProps<T> | ForMultipleProps<T>;
|
|
47
45
|
}
|
|
48
|
-
declare function Provider<T extends State>(props: Provider.Props<T>):
|
|
46
|
+
declare function Provider<T extends State$2>(props: Provider.Props<T>): react.FunctionComponentElement<react.ProviderProps<Context$1>>;
|
|
49
47
|
//#endregion
|
|
50
|
-
//#region src/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
48
|
+
//#region src/component.d.ts
|
|
49
|
+
type StateProps<T extends State$1> = { [K in Exclude<keyof T, keyof Component>]?: T[K] };
|
|
50
|
+
type RenderProps<T> = T extends {
|
|
51
|
+
render(props: infer P): any;
|
|
52
|
+
} ? {} extends P ? {
|
|
53
|
+
children?: ReactNode;
|
|
54
|
+
} : P : {
|
|
55
|
+
children?: ReactNode;
|
|
56
|
+
};
|
|
57
|
+
interface ComponentProps<T extends Component> {
|
|
58
|
+
/** Callback for newly created instance. Only called once. */
|
|
59
|
+
is?: (instance: T) => void;
|
|
60
|
+
/** Fallback to show when suspended or in error recovery. */
|
|
61
|
+
fallback?: ReactNode;
|
|
62
|
+
}
|
|
63
|
+
type Props<T extends Component> = StateProps<T> & ComponentProps<T> & RenderProps<T>;
|
|
57
64
|
declare module '@expressive/state' {
|
|
58
65
|
namespace State {
|
|
59
|
-
export
|
|
60
|
-
export import get = ReactState.get;
|
|
61
|
-
export import use = ReactState.use;
|
|
66
|
+
export type { Component, Props };
|
|
62
67
|
}
|
|
63
68
|
}
|
|
69
|
+
declare class Component extends State$1 {
|
|
70
|
+
static contextType: React.Context<Context$1>;
|
|
71
|
+
/**
|
|
72
|
+
* All JSX attributes passed to this component.
|
|
73
|
+
* Includes state-derived props, render props, and built-in props like `is` and `fallback`.
|
|
74
|
+
*
|
|
75
|
+
* Will incorperate extra props you declare as props parameter in `render` method.
|
|
76
|
+
*/
|
|
77
|
+
readonly props: Props<this>;
|
|
78
|
+
/** @deprecated Only to satisfy React JSX. Use `this.get(State)` instead. */
|
|
79
|
+
readonly context: Context$1;
|
|
80
|
+
/** @deprecated Only to satisfy React JSX. Use `this.get()` instead. */
|
|
81
|
+
readonly state: State$1.Values<this>;
|
|
82
|
+
/** @deprecated Only to satisfy React JSX. Not implemented. */
|
|
83
|
+
setState: (state: any, callback?: () => void) => void;
|
|
84
|
+
/** @deprecated Only to satisfy React JSX. Not implemented. */
|
|
85
|
+
forceUpdate: (callback?: () => void) => void;
|
|
86
|
+
/**
|
|
87
|
+
* Content to display while this component or its children are suspended.
|
|
88
|
+
* Will cover suspense by pending properties in `this.render` as well.
|
|
89
|
+
* Can be set as a class property or overridden via the `fallback` JSX prop.
|
|
90
|
+
*
|
|
91
|
+
* Defaults to null - nothing will be rendered.
|
|
92
|
+
*/
|
|
93
|
+
fallback: ReactNode;
|
|
94
|
+
constructor(nextProps: any, ...rest: any[]);
|
|
95
|
+
/**
|
|
96
|
+
* Output for this component. Override to define custom JSX.
|
|
97
|
+
*
|
|
98
|
+
* Properties accessed via `this` are reactive and will trigger a render when , in addition to props.
|
|
99
|
+
*
|
|
100
|
+
* Accepts optional parameter to receive extra props
|
|
101
|
+
* from JSX, beyond those merged to state properties.
|
|
102
|
+
*
|
|
103
|
+
* To declare extra props use `props = {} as { ... }` with expected shape.
|
|
104
|
+
* A default is required to satisfy TypeScript but safely ignored.
|
|
105
|
+
*
|
|
106
|
+
* ```ts
|
|
107
|
+
* render(props = {} as { label: string }) {
|
|
108
|
+
* return <span>{props.label}</span>;
|
|
109
|
+
* }
|
|
110
|
+
* ```
|
|
111
|
+
* Usable as:
|
|
112
|
+
* ```tsx
|
|
113
|
+
* <MyComponent label="Hello" />
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* These must be compatible with State-derived properties, or be unused.
|
|
117
|
+
* Props you declare as not-optional will be required by the JSX element.
|
|
118
|
+
*
|
|
119
|
+
* Without a parameter, children are accepted by default and passed through provider.
|
|
120
|
+
*/
|
|
121
|
+
render(props?: {}): ReactNode;
|
|
122
|
+
/**
|
|
123
|
+
* Called when a child component throws during render.
|
|
124
|
+
* While this is pending, `fallback` is displayed.
|
|
125
|
+
* When resolved, the error boundary resets and `render` is called again.
|
|
126
|
+
*
|
|
127
|
+
* Override to handle errors - set `this.fallback` for error-specific UI,
|
|
128
|
+
* await async recovery, or await user interaction before retrying. If you
|
|
129
|
+
* assign a fallback within catch, it will be reverted after resolved.
|
|
130
|
+
*/
|
|
131
|
+
catch?(error: Error): Promise<void> | void;
|
|
132
|
+
}
|
|
64
133
|
//#endregion
|
|
65
|
-
export { Consumer, Context,
|
|
134
|
+
export { Component, Consumer, Context, Observable, Provider, State, State as default, def, get, ref, set };
|
|
66
135
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,46 +1,279 @@
|
|
|
1
1
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: ((k) => from[k]).bind(null, key),
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
5
29
|
let react = require("react");
|
|
30
|
+
react = __toESM(react);
|
|
6
31
|
let src_state = require("./state");
|
|
32
|
+
let _expressive_state = require("@expressive/state");
|
|
33
|
+
|
|
34
|
+
//#region src/context.ts
|
|
35
|
+
const Layers = (0, react.createContext)(new _expressive_state.Context());
|
|
36
|
+
const _get = _expressive_state.Context.get;
|
|
37
|
+
_expressive_state.Context.get = (state) => {
|
|
38
|
+
if (state) return _get(state);
|
|
39
|
+
try {
|
|
40
|
+
return (0, react.useContext)(Layers);
|
|
41
|
+
} catch {
|
|
42
|
+
return _expressive_state.Context.root;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
function Consumer(props) {
|
|
46
|
+
return props.for.get((i) => props.children(i));
|
|
47
|
+
}
|
|
48
|
+
function Provider(props) {
|
|
49
|
+
const ambient = (0, react.useContext)(Layers);
|
|
50
|
+
const ref = (0, react.useRef)(null);
|
|
51
|
+
const context = ref.current || (ref.current = new _expressive_state.Context(ambient));
|
|
52
|
+
let { for: input, children, fallback, name, ...rest } = props;
|
|
53
|
+
context.set(input, (added) => rest.is?.(added));
|
|
54
|
+
if (Object.keys(rest).length) {
|
|
55
|
+
if (_expressive_state.State.is(input)) input = context.get(input);
|
|
56
|
+
if (input instanceof _expressive_state.State) input.set(rest);
|
|
57
|
+
}
|
|
58
|
+
(0, src_state.useMount)(() => () => context.pop());
|
|
59
|
+
if (fallback !== void 0) children = (0, react.createElement)(react.Suspense, {
|
|
60
|
+
fallback,
|
|
61
|
+
name
|
|
62
|
+
}, children);
|
|
63
|
+
return (0, react.createElement)(Layers.Provider, {
|
|
64
|
+
value: context,
|
|
65
|
+
children
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/component.ts
|
|
71
|
+
const PENDING = /* @__PURE__ */ new WeakMap();
|
|
72
|
+
var Component = class extends src_state.State {
|
|
73
|
+
static {
|
|
74
|
+
this.contextType = Layers;
|
|
75
|
+
}
|
|
76
|
+
constructor(nextProps, ...rest) {
|
|
77
|
+
const { is, ...props } = nextProps;
|
|
78
|
+
rest = rest.filter((x) => !(x instanceof _expressive_state.Context));
|
|
79
|
+
super(props, rest, is && ((x) => void is(x)));
|
|
80
|
+
this.fallback = null;
|
|
81
|
+
const existing = PENDING.get(nextProps);
|
|
82
|
+
if (existing) return existing;
|
|
83
|
+
PENDING.set(nextProps, this);
|
|
84
|
+
this.props = nextProps;
|
|
85
|
+
this.set("props", () => {
|
|
86
|
+
this.set(this.props);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Output for this component. Override to define custom JSX.
|
|
91
|
+
*
|
|
92
|
+
* Properties accessed via `this` are reactive and will trigger a render when , in addition to props.
|
|
93
|
+
*
|
|
94
|
+
* Accepts optional parameter to receive extra props
|
|
95
|
+
* from JSX, beyond those merged to state properties.
|
|
96
|
+
*
|
|
97
|
+
* To declare extra props use `props = {} as { ... }` with expected shape.
|
|
98
|
+
* A default is required to satisfy TypeScript but safely ignored.
|
|
99
|
+
*
|
|
100
|
+
* ```ts
|
|
101
|
+
* render(props = {} as { label: string }) {
|
|
102
|
+
* return <span>{props.label}</span>;
|
|
103
|
+
* }
|
|
104
|
+
* ```
|
|
105
|
+
* Usable as:
|
|
106
|
+
* ```tsx
|
|
107
|
+
* <MyComponent label="Hello" />
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* These must be compatible with State-derived properties, or be unused.
|
|
111
|
+
* Props you declare as not-optional will be required by the JSX element.
|
|
112
|
+
*
|
|
113
|
+
* Without a parameter, children are accepted by default and passed through provider.
|
|
114
|
+
*/
|
|
115
|
+
render(props) {
|
|
116
|
+
return this.props.children || null;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
Object.defineProperties(Component.prototype, {
|
|
120
|
+
isReactComponent: { get: () => true },
|
|
121
|
+
state: {
|
|
122
|
+
get() {
|
|
123
|
+
return this.get();
|
|
124
|
+
},
|
|
125
|
+
set() {}
|
|
126
|
+
},
|
|
127
|
+
context: {
|
|
128
|
+
configurable: true,
|
|
129
|
+
set: bootstrap
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
function bootstrap(context) {
|
|
133
|
+
const self = this.is;
|
|
134
|
+
const render = (0, _expressive_state.unbind)(this.render);
|
|
135
|
+
context = context.push(self);
|
|
136
|
+
let ready = false;
|
|
137
|
+
let active;
|
|
138
|
+
function Render() {
|
|
139
|
+
return render.call(active, self.props);
|
|
140
|
+
}
|
|
141
|
+
function AsComponent() {
|
|
142
|
+
(0, src_state.useMount)((refresh) => {
|
|
143
|
+
(0, _expressive_state.watch)(self, (current) => {
|
|
144
|
+
active = current;
|
|
145
|
+
if (ready) refresh();
|
|
146
|
+
});
|
|
147
|
+
return () => {
|
|
148
|
+
self.set(null);
|
|
149
|
+
context.pop();
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
(0, react.useEffect)(() => {
|
|
153
|
+
ready = true;
|
|
154
|
+
}, []);
|
|
155
|
+
const children = (0, react.createElement)(Layers.Provider, {
|
|
156
|
+
value: context,
|
|
157
|
+
children: (0, react.createElement)(react.Suspense, {
|
|
158
|
+
fallback: active.fallback,
|
|
159
|
+
name: String(self)
|
|
160
|
+
}, (0, react.createElement)(Render))
|
|
161
|
+
});
|
|
162
|
+
if (active.catch) return (0, react.createElement)(ErrorBoundary, {
|
|
163
|
+
fallback: () => self.fallback,
|
|
164
|
+
onError(error, reset) {
|
|
165
|
+
const { fallback } = self;
|
|
166
|
+
Promise.resolve(self.catch(error)).then(() => ready && reset(), reset).finally(() => self.set({ fallback }, true));
|
|
167
|
+
},
|
|
168
|
+
children
|
|
169
|
+
});
|
|
170
|
+
return children;
|
|
171
|
+
}
|
|
172
|
+
Object.defineProperties(self, {
|
|
173
|
+
context: {
|
|
174
|
+
get: () => context,
|
|
175
|
+
set() {}
|
|
176
|
+
},
|
|
177
|
+
render: { value: () => (0, react.createElement)(AsComponent) }
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
var ErrorBoundary = class extends react.default.Component {
|
|
181
|
+
constructor(..._args) {
|
|
182
|
+
super(..._args);
|
|
183
|
+
this.state = {};
|
|
184
|
+
this.recovering = false;
|
|
185
|
+
}
|
|
186
|
+
static getDerivedStateFromError(error) {
|
|
187
|
+
return { error };
|
|
188
|
+
}
|
|
189
|
+
componentDidCatch(error) {
|
|
190
|
+
this.props.onError(error, (error) => {
|
|
191
|
+
this.recovering = true;
|
|
192
|
+
this.setState({ error });
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
componentDidUpdate() {
|
|
196
|
+
this.recovering = false;
|
|
197
|
+
}
|
|
198
|
+
render() {
|
|
199
|
+
if (!this.state.error) return this.props.children;
|
|
200
|
+
if (this.recovering) throw this.state.error;
|
|
201
|
+
return this.props.fallback();
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
const SEEN = /* @__PURE__ */ new WeakSet();
|
|
205
|
+
function subcomponents(proto) {
|
|
206
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
207
|
+
if (!/^[A-Z]/.test(key)) continue;
|
|
208
|
+
const { get, value } = Object.getOwnPropertyDescriptor(proto, key);
|
|
209
|
+
if (!get && typeof value !== "function") continue;
|
|
210
|
+
Object.defineProperty(proto, key, {
|
|
211
|
+
configurable: true,
|
|
212
|
+
get() {
|
|
213
|
+
const self = this.is;
|
|
214
|
+
let render = (0, _expressive_state.unbind)(get ? get.call(this) : value);
|
|
215
|
+
function Sub(props) {
|
|
216
|
+
const ref = (0, react.useRef)(null);
|
|
217
|
+
(0, src_state.useMount)((refresh) => (0, _expressive_state.watch)(self, (current) => {
|
|
218
|
+
ref.current = current;
|
|
219
|
+
refresh();
|
|
220
|
+
}));
|
|
221
|
+
return render.call(ref.current, props);
|
|
222
|
+
}
|
|
223
|
+
Object.defineProperty(self, key, {
|
|
224
|
+
configurable: true,
|
|
225
|
+
get: () => Sub,
|
|
226
|
+
set(fn) {
|
|
227
|
+
render = fn;
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
return Sub;
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
Component.on((self) => {
|
|
236
|
+
let Type = self.constructor;
|
|
237
|
+
while (Type !== Component) {
|
|
238
|
+
const proto = Type.prototype;
|
|
239
|
+
if (SEEN.has(Type)) break;
|
|
240
|
+
SEEN.add(Type);
|
|
241
|
+
subcomponents(proto);
|
|
242
|
+
Type = Object.getPrototypeOf(Type);
|
|
243
|
+
}
|
|
244
|
+
subcomponents(self);
|
|
245
|
+
});
|
|
7
246
|
|
|
247
|
+
//#endregion
|
|
8
248
|
//#region src/index.ts
|
|
9
249
|
src_state.Pragma.useEffect = react.useEffect;
|
|
10
250
|
src_state.Pragma.useState = react.useState;
|
|
11
251
|
src_state.Pragma.createElement = react.createElement;
|
|
12
|
-
|
|
13
|
-
_expressive_state.State.use = src_state.ReactState.use;
|
|
14
|
-
_expressive_state.State.as = src_state.ReactState.as;
|
|
252
|
+
src_state.Pragma.useRef = react.useRef;
|
|
15
253
|
|
|
16
254
|
//#endregion
|
|
17
|
-
exports.
|
|
255
|
+
exports.Component = Component;
|
|
256
|
+
exports.Consumer = Consumer;
|
|
18
257
|
Object.defineProperty(exports, 'Context', {
|
|
19
258
|
enumerable: true,
|
|
20
259
|
get: function () {
|
|
21
260
|
return _expressive_state.Context;
|
|
22
261
|
}
|
|
23
262
|
});
|
|
24
|
-
Object.defineProperty(exports, 'Fragment', {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function () {
|
|
27
|
-
return react.Fragment;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
263
|
Object.defineProperty(exports, 'Observable', {
|
|
31
264
|
enumerable: true,
|
|
32
265
|
get: function () {
|
|
33
266
|
return _expressive_state.Observable;
|
|
34
267
|
}
|
|
35
268
|
});
|
|
36
|
-
exports.
|
|
37
|
-
exports.
|
|
38
|
-
exports.
|
|
39
|
-
exports.
|
|
40
|
-
Object.defineProperty(exports, '
|
|
269
|
+
exports.Provider = Provider;
|
|
270
|
+
exports.State = src_state.State;
|
|
271
|
+
exports.default = src_state.State;
|
|
272
|
+
exports.__toESM = __toESM;
|
|
273
|
+
Object.defineProperty(exports, 'def', {
|
|
41
274
|
enumerable: true,
|
|
42
275
|
get: function () {
|
|
43
|
-
return
|
|
276
|
+
return _expressive_state.def;
|
|
44
277
|
}
|
|
45
278
|
});
|
|
46
279
|
Object.defineProperty(exports, 'get', {
|
|
@@ -61,10 +294,4 @@ Object.defineProperty(exports, 'set', {
|
|
|
61
294
|
return _expressive_state.set;
|
|
62
295
|
}
|
|
63
296
|
});
|
|
64
|
-
Object.defineProperty(exports, 'use', {
|
|
65
|
-
enumerable: true,
|
|
66
|
-
get: function () {
|
|
67
|
-
return _expressive_state.use;
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
297
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["useEffect","useState","createElement","ReactState"],"sources":["../src/index.ts"],"sourcesContent":["import { State } from '@expressive/state';\n\nimport { createElement, useEffect, useState } from 'react';\n\nimport { ReactState, Pragma } from './state';\n\nPragma.useEffect = useEffect;\nPragma.useState = useState;\nPragma.createElement = createElement;\n\n/**\n * Augmented State namespace to include ReactState hooks as static methods.\n *\n * This retroactively adds React support to agnostic State defined\n * by component libraries which import `@expressive/state` directly.\n */\ndeclare module '@expressive/state' {\n namespace State {\n export import as = ReactState.as;\n export import get = ReactState.get;\n export import use = ReactState.use;\n }\n}\n\nState.get = ReactState.get;\nState.use = ReactState.use;\nState.as = ReactState.as;\n\nexport { ReactState as State, ReactState as default };\nexport { Context, Observable, get, use, ref, set } from '@expressive/state';\nexport { Consumer, Provider } from './context';\nexport { Fragment, createElement } from 'react';\nexport { Pragma };\n"],"mappings":";;;;;;;;AAMA,iBAAO,YAAYA;AACnB,iBAAO,WAAWC;AAClB,iBAAO,gBAAgBC;AAgBvB,wBAAM,MAAMC,qBAAW;AACvB,wBAAM,MAAMA,qBAAW;AACvB,wBAAM,KAAKA,qBAAW"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["Context","State","Suspense","State","Context","Suspense","React","useEffect","useState","createElement","useRef"],"sources":["../src/context.ts","../src/component.ts","../src/index.ts"],"sourcesContent":["import { State, Context } from '@expressive/state';\nimport {\n createContext,\n createElement,\n ReactNode,\n Suspense,\n useContext,\n useRef\n} from 'react';\nimport { useMount } from './state';\n\nconst Layers = createContext(new Context());\n\nconst _get = Context.get;\n\nContext.get = (state?: State) => {\n if (state) return _get(state);\n try {\n return useContext(Layers);\n } catch {\n return Context.root;\n }\n};\n\ndeclare namespace Consumer {\n type Props<T extends State> = {\n /** Type of controller to fetch from context. */\n for: State.Extends<T>;\n\n /**\n * Render function, will receive instance of desired controller.\n *\n * Called every render of parent component.\n * Similar to `State.get()`, updates to properties accessed in\n * this function will cause a refresh when they change.\n */\n children: (value: T) => ReactNode | void;\n };\n}\n\nfunction Consumer<T extends State>(props: Consumer.Props<T>) {\n return props.for.get((i) => props.children(i));\n}\n\ndeclare namespace Provider {\n type ForEach<T> = (state: T) => void | (() => void);\n\n interface SharedProps {\n /**\n * Children to render within this Provider.\n */\n children?: ReactNode;\n\n /** A fallback tree to show when suspended. */\n fallback?: ReactNode;\n\n /**\n * A name for this Suspense boundary for instrumentation purposes.\n * The name will help identify this boundary in React DevTools.\n */\n name?: string | undefined;\n }\n\n type ForSingleProps<T extends State> = SharedProps & {\n for: T | State.Type<T>;\n is: (instance: T) => void;\n } & { [K in State.Field<T>]?: T[K] };\n\n type ForMultipleProps<T extends State> = SharedProps & {\n for: Context.Accept<T>;\n is?: ForEach<T>;\n };\n\n type Props<T extends State = State> = ForSingleProps<T> | ForMultipleProps<T>;\n}\n\nfunction Provider<T extends State>(props: Provider.Props<T>) {\n const ambient = useContext(Layers);\n const ref = useRef<Context | null>(null);\n const context = ref.current || (ref.current = new Context(ambient));\n\n let {\n for: input,\n children,\n fallback,\n name,\n ...rest\n } = props as Provider.ForSingleProps<T> & Provider.ForMultipleProps<T>;\n\n context.set(input, (added) => rest.is?.(added));\n\n if (Object.keys(rest).length) {\n if (State.is(input)) input = context.get(input) as T;\n if (input instanceof State) input.set(rest as State.Assign<T>);\n }\n\n useMount(() => () => context.pop());\n\n if (fallback !== undefined)\n children = createElement(Suspense, { fallback, name }, children);\n\n return createElement(Layers.Provider, { value: context, children });\n}\n\nexport { Consumer, Provider, Context, Layers };\n","import { watch, unbind } from '@expressive/state';\nimport React, {\n createElement,\n Suspense,\n useEffect,\n useRef,\n type ReactNode\n} from 'react';\nimport { Context, Layers } from './context';\nimport { State, useMount } from './state';\n\nconst PENDING = new WeakMap<object, Component>();\n\nexport type StateProps<T extends State> = {\n [K in Exclude<keyof T, keyof Component>]?: T[K];\n};\n\ntype RenderProps<T> = T extends { render(props: infer P): any }\n ? {} extends P\n ? { children?: ReactNode }\n : P\n : { children?: ReactNode };\n\ninterface ComponentProps<T extends Component> {\n /** Callback for newly created instance. Only called once. */\n is?: (instance: T) => void;\n\n /** Fallback to show when suspended or in error recovery. */\n fallback?: ReactNode;\n}\n\nexport type Props<T extends Component> = StateProps<T> &\n ComponentProps<T> &\n RenderProps<T>;\n\ndeclare module '@expressive/state' {\n namespace State {\n export type { Component, Props };\n }\n}\n\nclass Component extends State {\n static contextType = Layers;\n\n /**\n * All JSX attributes passed to this component.\n * Includes state-derived props, render props, and built-in props like `is` and `fallback`.\n *\n * Will incorperate extra props you declare as props parameter in `render` method.\n */\n readonly props!: Props<this>;\n\n /** @deprecated Only to satisfy React JSX. Use `this.get(State)` instead. */\n declare readonly context: Context;\n /** @deprecated Only to satisfy React JSX. Use `this.get()` instead. */\n declare readonly state: State.Values<this>;\n /** @deprecated Only to satisfy React JSX. Not implemented. */\n declare setState: (state: any, callback?: () => void) => void;\n /** @deprecated Only to satisfy React JSX. Not implemented. */\n declare forceUpdate: (callback?: () => void) => void;\n\n /**\n * Content to display while this component or its children are suspended.\n * Will cover suspense by pending properties in `this.render` as well.\n * Can be set as a class property or overridden via the `fallback` JSX prop.\n *\n * Defaults to null - nothing will be rendered.\n */\n fallback: ReactNode = null;\n\n constructor(nextProps: any, ...rest: any[]) {\n const { is, ...props } = nextProps;\n rest = rest.filter((x) => !(x instanceof Context));\n super(props, rest, is && ((x: any) => void is(x)));\n\n const existing = PENDING.get(nextProps);\n if (existing) return existing;\n PENDING.set(nextProps, this);\n\n this.props = nextProps;\n this.set('props', () => {\n this.set(this.props as {});\n });\n }\n\n /**\n * Output for this component. Override to define custom JSX.\n *\n * Properties accessed via `this` are reactive and will trigger a render when , in addition to props.\n *\n * Accepts optional parameter to receive extra props\n * from JSX, beyond those merged to state properties.\n *\n * To declare extra props use `props = {} as { ... }` with expected shape.\n * A default is required to satisfy TypeScript but safely ignored.\n *\n * ```ts\n * render(props = {} as { label: string }) {\n * return <span>{props.label}</span>;\n * }\n * ```\n * Usable as:\n * ```tsx\n * <MyComponent label=\"Hello\" />\n * ```\n *\n * These must be compatible with State-derived properties, or be unused.\n * Props you declare as not-optional will be required by the JSX element.\n *\n * Without a parameter, children are accepted by default and passed through provider.\n */\n render(props?: {}): ReactNode {\n return this.props.children || null;\n }\n\n /**\n * Called when a child component throws during render.\n * While this is pending, `fallback` is displayed.\n * When resolved, the error boundary resets and `render` is called again.\n *\n * Override to handle errors - set `this.fallback` for error-specific UI,\n * await async recovery, or await user interaction before retrying. If you\n * assign a fallback within catch, it will be reverted after resolved.\n */\n catch?(error: Error): Promise<void> | void;\n}\n\nObject.defineProperties(Component.prototype, {\n isReactComponent: {\n get: () => true\n },\n state: {\n get(this: Component) {\n return this.get();\n },\n set() {}\n },\n context: {\n configurable: true,\n set: bootstrap\n }\n});\n\nfunction bootstrap(this: Component, context: Context) {\n const self = this.is;\n const render = unbind(this.render);\n\n context = context.push(self);\n\n let ready = false;\n let active: Component;\n\n function Render() {\n return render.call(active, self.props);\n }\n\n function AsComponent() {\n useMount((refresh) => {\n watch(self, (current) => {\n active = current;\n if (ready) refresh();\n });\n\n return () => {\n self.set(null);\n context.pop();\n };\n });\n\n useEffect(() => {\n ready = true;\n }, []);\n\n const children = createElement(Layers.Provider, {\n value: context,\n children: createElement(\n Suspense,\n { fallback: active.fallback, name: String(self) },\n createElement(Render)\n )\n });\n\n if (active.catch)\n return createElement(ErrorBoundary, {\n fallback: () => self.fallback,\n onError(error: Error, reset: (failed?: Error) => void) {\n const { fallback } = self;\n Promise.resolve(self.catch!(error))\n .then(() => ready && reset(), reset)\n .finally(() => self.set({ fallback }, true));\n },\n children\n });\n\n return children;\n }\n\n Object.defineProperties(self, {\n context: {\n get: () => context,\n set() {}\n },\n render: {\n value: () => createElement(AsComponent)\n }\n });\n}\n\ninterface BoundaryProps {\n children: ReactNode;\n fallback: () => ReactNode;\n onError: (error: Error, reset: (failed?: Error) => void) => void;\n}\n\nclass ErrorBoundary extends React.Component<BoundaryProps> {\n state = {} as { error?: Error };\n recovering = false;\n\n static getDerivedStateFromError(error: Error) {\n return { error };\n }\n\n componentDidCatch(error: Error) {\n this.props.onError(error, (error) => {\n this.recovering = true;\n this.setState({ error });\n });\n }\n\n componentDidUpdate() {\n this.recovering = false;\n }\n\n render() {\n if (!this.state.error) return this.props.children;\n if (this.recovering) throw this.state.error;\n return this.props.fallback();\n }\n}\n\nconst SEEN = new WeakSet<Function>();\n\nfunction subcomponents(proto: State) {\n for (const key of Object.getOwnPropertyNames(proto)) {\n if (!/^[A-Z]/.test(key)) continue;\n\n const { get, value } = Object.getOwnPropertyDescriptor(proto, key)!;\n\n if (!get && typeof value !== 'function') continue;\n\n Object.defineProperty(proto, key, {\n configurable: true,\n get(this: Component) {\n const self = this.is;\n\n let render = unbind(get ? get.call(this) : value);\n\n function Sub(props: any) {\n const ref = useRef<State>(null);\n\n useMount((refresh) =>\n watch(self, (current) => {\n ref.current = current;\n refresh();\n })\n );\n\n return render.call(ref.current, props);\n }\n\n Object.defineProperty(self, key, {\n configurable: true,\n get: () => Sub,\n set(fn: Function) {\n render = fn;\n }\n });\n\n return Sub;\n }\n });\n }\n}\n\nComponent.on((self) => {\n let Type = self.constructor as State.Extends;\n\n while (Type !== Component) {\n const proto = Type.prototype as any;\n\n if (SEEN.has(Type)) break;\n SEEN.add(Type);\n subcomponents(proto);\n Type = Object.getPrototypeOf(Type);\n }\n\n subcomponents(self);\n});\n\nexport { Component };\n","import { createElement, useEffect, useRef, useState } from 'react';\n\nimport { Pragma, State } from './state';\nimport { Consumer, Provider } from './context';\n\nPragma.useEffect = useEffect;\nPragma.useState = useState;\nPragma.createElement = createElement;\nPragma.useRef = useRef;\n\nexport { State, State as default };\nexport { Context, Observable, def, get, ref, set } from '@expressive/state';\nexport { Component } from './component';\nexport { Consumer, Provider };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,MAAM,kCAAuB,IAAIA,2BAAS,CAAC;AAE3C,MAAM,OAAOA,0BAAQ;AAErB,0BAAQ,OAAO,UAAkB;AAC/B,KAAI,MAAO,QAAO,KAAK,MAAM;AAC7B,KAAI;AACF,+BAAkB,OAAO;SACnB;AACN,SAAOA,0BAAQ;;;AAoBnB,SAAS,SAA0B,OAA0B;AAC3D,QAAO,MAAM,IAAI,KAAK,MAAM,MAAM,SAAS,EAAE,CAAC;;AAmChD,SAAS,SAA0B,OAA0B;CAC3D,MAAM,gCAAqB,OAAO;CAClC,MAAM,wBAA6B,KAAK;CACxC,MAAM,UAAU,IAAI,YAAY,IAAI,UAAU,IAAIA,0BAAQ,QAAQ;CAElE,IAAI,EACF,KAAK,OACL,UACA,UACA,MACA,GAAG,SACD;AAEJ,SAAQ,IAAI,QAAQ,UAAU,KAAK,KAAK,MAAM,CAAC;AAE/C,KAAI,OAAO,KAAK,KAAK,CAAC,QAAQ;AAC5B,MAAIC,wBAAM,GAAG,MAAM,CAAE,SAAQ,QAAQ,IAAI,M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