@expressive/react 0.74.1 → 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-DEag_HVs.js +0 -62
- package/dist/context-DEag_HVs.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/state.d.ts
CHANGED
|
@@ -1,122 +1,75 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ReactNode } from "react";
|
|
1
|
+
import { State } from "@expressive/state";
|
|
3
2
|
|
|
4
3
|
//#region src/state.d.ts
|
|
5
4
|
declare const Pragma: {
|
|
6
|
-
useState<S>(initial: () => S): [S, (next: (previous: S) => S) => void];
|
|
7
|
-
useEffect(effect: () => () => void, deps?: any[]): void;
|
|
8
5
|
createElement(type: any, props?: any, ...children: any[]): any;
|
|
6
|
+
useState<S>(initial: S | (() => S)): [S, (next: (previous: S) => S) => void];
|
|
7
|
+
useEffect(effect: () => (() => void) | void, deps?: any[]): void;
|
|
8
|
+
useRef<T>(initial: T): {
|
|
9
|
+
current: T;
|
|
10
|
+
};
|
|
9
11
|
};
|
|
10
12
|
/** Type may not be undefined - instead will be null. */
|
|
11
13
|
type NoVoid<T> = T extends undefined | void ? null : T;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
/** @deprecated Only for React JSX compatibility in typescript and nonfunctional. */
|
|
67
|
-
forceUpdate: (callback?: () => void) => void;
|
|
68
|
-
}
|
|
69
|
-
type ComponentType<T, P = {}> = State.Type<T & Component<P>>;
|
|
70
|
-
declare namespace ReactState {
|
|
71
|
-
export import Extends = State.Extends;
|
|
72
|
-
export import Type = State.Type;
|
|
73
|
-
export import Args = State.Args;
|
|
74
|
-
export import Init = State.Init;
|
|
75
|
-
export import Assign = State.Assign;
|
|
76
|
-
export import Field = State.Field;
|
|
77
|
-
export import Event = State.Event;
|
|
78
|
-
export import Export = State.Export;
|
|
79
|
-
export import Value = State.Value;
|
|
80
|
-
export import Setter = State.Setter;
|
|
81
|
-
export import OnEvent = State.OnEvent;
|
|
82
|
-
export import OnUpdate = State.OnUpdate;
|
|
83
|
-
export import Values = State.Values;
|
|
84
|
-
export import Partial = State.Partial;
|
|
85
|
-
export import Ref = State.Ref;
|
|
86
|
-
export import Effect = State.Effect;
|
|
87
|
-
export import EffectCallback = State.EffectCallback;
|
|
88
|
-
export { GetFactory, GetEffect, UseArgs, Props, Component };
|
|
89
|
-
}
|
|
90
|
-
declare abstract class ReactState extends State {
|
|
91
|
-
/**
|
|
92
|
-
* Optional hook is called when State.use() is invoked within a React component.
|
|
93
|
-
*
|
|
94
|
-
* This is called *every render* of the component, and will intercept
|
|
95
|
-
* arguments which would otherwise be merged into the State.
|
|
96
|
-
*
|
|
97
|
-
* @param props Arguments passed to State.use().
|
|
98
|
-
*/
|
|
99
|
-
protected use?(...props: any[]): Promise<void> | void;
|
|
100
|
-
/**
|
|
101
|
-
* Create and manage instance of this State within React component.
|
|
102
|
-
*
|
|
103
|
-
* @param args Arguments to pass to constructor or `use` method (if defined).
|
|
104
|
-
* @returns Managed instance of this State.
|
|
105
|
-
*/
|
|
106
|
-
static use<T extends ReactState>(this: State.Type<T>, ...args: UseArgs<T>): T;
|
|
107
|
-
/** Fetch instance of this class from context. */
|
|
108
|
-
static get<T extends State>(this: State.Extends<T>): T;
|
|
109
|
-
/** Fetch instance of this class optionally. */
|
|
110
|
-
static get<T extends State>(this: State.Extends<T>, required: false): T | undefined;
|
|
111
|
-
/** Fetch instance of this class from context. */
|
|
112
|
-
static get<T extends State>(this: State.Extends<T>, requireValues: true): Required<T>;
|
|
113
|
-
static get<T extends State, R>(this: State.Extends<T>, factory: GetFactory<T, Promise<R> | R>): NoVoid<R>;
|
|
114
|
-
static get<T extends State>(this: State.Extends<T>, factory: GetEffect<T>): null;
|
|
115
|
-
static as<T extends State, P extends object = {}>(this: State.Type<T>, render: Render<T, P>): ComponentType<T, P>;
|
|
116
|
-
static as<T extends State, P extends object = {}>(this: ComponentType<T, P>, withProps: Props<T>): ComponentType<T, P>;
|
|
117
|
-
static as<T extends State>(this: State.Type<T>, withProps: Props<T>): ComponentType<T, {}>;
|
|
14
|
+
declare module '@expressive/state' {
|
|
15
|
+
interface UseState extends State {
|
|
16
|
+
/**
|
|
17
|
+
* Optional hook called when State.use() is invoked within a React component.
|
|
18
|
+
*
|
|
19
|
+
* This is called *every render* of the component, and will intercept
|
|
20
|
+
* arguments which would otherwise be passed into the State constructor.
|
|
21
|
+
*
|
|
22
|
+
* @param props Arguments passed to State.use().
|
|
23
|
+
*/
|
|
24
|
+
use?(...props: any[]): Promise<void> | void;
|
|
25
|
+
}
|
|
26
|
+
namespace State {
|
|
27
|
+
type ForceRefresh = {
|
|
28
|
+
/** Request a refresh for current component. */(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Request a refresh and again after promise either resolves or rejects.
|
|
31
|
+
*
|
|
32
|
+
* @param waitFor Promise to wait for.
|
|
33
|
+
* @returns Promise which resolves, after refresh, to same value as `waitFor`.
|
|
34
|
+
*/
|
|
35
|
+
<T = void>(waitFor: Promise<T>): Promise<T>;
|
|
36
|
+
/**
|
|
37
|
+
* Request refresh before and after async function.
|
|
38
|
+
* A refresh will occur both before and after the given function.
|
|
39
|
+
*
|
|
40
|
+
* **Note:** Any actions performed before first `await` will occur prior to refresh.
|
|
41
|
+
*
|
|
42
|
+
* @param invoke Async function to invoke.
|
|
43
|
+
* @returns Promise which resolves returned value after refresh.
|
|
44
|
+
*/
|
|
45
|
+
<T = void>(invoke: () => Promise<T>): Promise<T>;
|
|
46
|
+
};
|
|
47
|
+
type GetFactory<T extends State, R> = (this: T, current: T, refresh: ForceRefresh) => R;
|
|
48
|
+
type GetEffect<T extends State> = (this: T, current: T, refresh: ForceRefresh) => null;
|
|
49
|
+
type UseArgs<T extends State> = T extends {
|
|
50
|
+
use(...props: infer P): any;
|
|
51
|
+
} ? P : State.Args<T>;
|
|
52
|
+
/**
|
|
53
|
+
* Create and manage instance of this State within React component.
|
|
54
|
+
*
|
|
55
|
+
* @param args Arguments to pass to constructor or `use` method (if defined).
|
|
56
|
+
* @returns Managed instance of this State.
|
|
57
|
+
*/
|
|
58
|
+
function use<T extends UseState>(this: State.Type<T>, ...args: UseArgs<T>): T;
|
|
59
|
+
/** Fetch instance of this class from context. */
|
|
60
|
+
function get<T extends State>(this: State.Extends<T>): T;
|
|
61
|
+
/** Fetch instance of this class optionally. */
|
|
62
|
+
function get<T extends State>(this: State.Extends<T>, required: false): T | undefined;
|
|
63
|
+
/** Fetch instance of this class from context. */
|
|
64
|
+
function get<T extends State>(this: State.Extends<T>, requireValues: true): Required<T>;
|
|
65
|
+
function get<T extends State, R>(this: State.Extends<T>, factory: GetFactory<T, Promise<R> | R>): NoVoid<R>;
|
|
66
|
+
function get<T extends State>(this: State.Extends<T>, factory: GetEffect<T>): null;
|
|
67
|
+
}
|
|
118
68
|
}
|
|
119
|
-
|
|
69
|
+
/**
|
|
70
|
+
* useEffect which tolerates react StrictMode double-invoking effects on mount.
|
|
71
|
+
*/
|
|
72
|
+
declare function useMount(callback: (refresh: () => void) => (() => void) | void): void;
|
|
120
73
|
//#endregion
|
|
121
|
-
export { Pragma,
|
|
74
|
+
export { Pragma, State, useMount };
|
|
122
75
|
//# sourceMappingURL=state.d.ts.map
|
package/dist/state.js
CHANGED
|
@@ -1,176 +1,142 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const
|
|
3
|
-
const require_context = require('./context-DEag_HVs.js');
|
|
2
|
+
const require_index = require('./index.js');
|
|
4
3
|
let _expressive_state = require("@expressive/state");
|
|
5
4
|
|
|
6
5
|
//#region src/state.ts
|
|
7
6
|
const Pragma = {};
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (x instanceof ReactState && x.use) {
|
|
25
|
-
use = x.use?.bind(x);
|
|
26
|
-
use(...args);
|
|
27
|
-
} else return args;
|
|
28
|
-
});
|
|
29
|
-
const context = ambient.push(instance);
|
|
30
|
-
(0, _expressive_state.watch)(instance, (current) => {
|
|
31
|
-
active = current;
|
|
32
|
-
if (ready) state[1]((x) => x.bind(null));
|
|
33
|
-
});
|
|
34
|
-
function didMount() {
|
|
7
|
+
_expressive_state.State.use = function(...args) {
|
|
8
|
+
const outer = _expressive_state.Context.get();
|
|
9
|
+
const ref = Pragma.useRef(null);
|
|
10
|
+
return (ref.current || (ref.current = init(this)))(args);
|
|
11
|
+
function init(Type) {
|
|
12
|
+
const add = (arg) => typeof arg == "object" && instance.set(arg);
|
|
13
|
+
let use = (...args) => Promise.all(args.flat().map(add));
|
|
14
|
+
const instance = new Type((x) => {
|
|
15
|
+
if ("use" in x && typeof x.use == "function") (use = x.use.bind(x))(...args);
|
|
16
|
+
else return args;
|
|
17
|
+
});
|
|
18
|
+
const context = outer.push(instance);
|
|
19
|
+
let ready = false;
|
|
20
|
+
let active;
|
|
21
|
+
return (args) => {
|
|
22
|
+
Pragma.useEffect(() => {
|
|
35
23
|
ready = true;
|
|
24
|
+
}, []);
|
|
25
|
+
useMount((refresh) => {
|
|
26
|
+
(0, _expressive_state.watch)(instance, (current) => {
|
|
27
|
+
active = current;
|
|
28
|
+
if (ready) refresh();
|
|
29
|
+
});
|
|
36
30
|
return () => {
|
|
37
31
|
context.pop();
|
|
38
32
|
instance.set(null);
|
|
39
33
|
};
|
|
34
|
+
});
|
|
35
|
+
if (ready) {
|
|
36
|
+
ready = false;
|
|
37
|
+
Promise.resolve(use(...args)).finally(() => {
|
|
38
|
+
ready = true;
|
|
39
|
+
});
|
|
40
40
|
}
|
|
41
|
-
return
|
|
42
|
-
|
|
43
|
-
if (ready) {
|
|
44
|
-
ready = false;
|
|
45
|
-
Promise.resolve(use(...args)).finally(() => ready = true);
|
|
46
|
-
}
|
|
47
|
-
return active;
|
|
48
|
-
};
|
|
49
|
-
});
|
|
50
|
-
return state[0](...args);
|
|
41
|
+
return active;
|
|
42
|
+
};
|
|
51
43
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
44
|
+
};
|
|
45
|
+
_expressive_state.State.get = function(argument) {
|
|
46
|
+
const ref = Pragma.useRef(null);
|
|
47
|
+
const next = Pragma.useState(0)[1];
|
|
48
|
+
const context = _expressive_state.Context.get();
|
|
49
|
+
return (ref.current || (ref.current = init(this)))();
|
|
50
|
+
function init(Type) {
|
|
51
|
+
let instance;
|
|
52
|
+
let unwatch;
|
|
53
|
+
let mounted = false;
|
|
54
|
+
let pending = false;
|
|
55
|
+
let value;
|
|
56
|
+
function update() {
|
|
57
|
+
pending = false;
|
|
58
|
+
next((x) => x + 1);
|
|
59
|
+
}
|
|
60
|
+
function refresh(action) {
|
|
61
|
+
if (typeof action == "function") action = action();
|
|
62
|
+
update();
|
|
63
|
+
if (action instanceof Promise) return action.finally(update);
|
|
64
|
+
}
|
|
65
|
+
function release() {
|
|
66
|
+
unwatch?.();
|
|
67
|
+
unsubscribe();
|
|
68
|
+
unwatch = void 0;
|
|
69
|
+
instance = void 0;
|
|
70
|
+
}
|
|
71
|
+
const unsubscribe = context.get(Type, (next) => {
|
|
72
|
+
unwatch?.();
|
|
73
|
+
unwatch = (0, _expressive_state.watch)(instance = next, (current, changed) => {
|
|
69
74
|
if (typeof argument === "function") {
|
|
70
75
|
const next = argument.call(current, current, refresh);
|
|
71
76
|
if (next === value) return;
|
|
72
77
|
value = next;
|
|
73
78
|
} else value = current;
|
|
74
|
-
if (
|
|
79
|
+
if (changed.length) update();
|
|
75
80
|
}, argument === true);
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
value.then((x) => value = x, (e) => error = e).finally(render);
|
|
80
|
-
value = null;
|
|
81
|
-
return () => {
|
|
82
|
-
if (error) throw error;
|
|
83
|
-
return value === void 0 ? null : value;
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
if (value === null) {
|
|
87
|
-
unwatch();
|
|
88
|
-
return () => null;
|
|
89
|
-
}
|
|
90
|
-
function onMount() {
|
|
91
|
-
ready = true;
|
|
92
|
-
return unwatch;
|
|
81
|
+
if (mounted) {
|
|
82
|
+
pending = true;
|
|
83
|
+
queueMicrotask(() => pending && update());
|
|
93
84
|
}
|
|
85
|
+
return release;
|
|
86
|
+
});
|
|
87
|
+
if (!instance) {
|
|
88
|
+
release();
|
|
89
|
+
if (argument === false) return () => void 0;
|
|
90
|
+
throw new Error(`Could not find ${Type} in context.`);
|
|
91
|
+
}
|
|
92
|
+
if (value instanceof Promise) {
|
|
93
|
+
let error;
|
|
94
|
+
release();
|
|
95
|
+
value.then((x) => value = x, (e) => error = e).finally(update);
|
|
96
|
+
value = null;
|
|
94
97
|
return () => {
|
|
95
|
-
|
|
98
|
+
if (error) throw error;
|
|
96
99
|
return value === void 0 ? null : value;
|
|
97
100
|
};
|
|
98
|
-
});
|
|
99
|
-
return state[0]();
|
|
100
|
-
}
|
|
101
|
-
static as(argument) {
|
|
102
|
-
const Type = this;
|
|
103
|
-
const render = typeof argument === "function" ? argument : void 0;
|
|
104
|
-
class ReactType extends Type {
|
|
105
|
-
static {
|
|
106
|
-
this.contextType = require_context.Layers;
|
|
107
|
-
}
|
|
108
|
-
get props() {
|
|
109
|
-
return PROPS.get(this);
|
|
110
|
-
}
|
|
111
|
-
set props(props) {
|
|
112
|
-
PROPS.set(this, props);
|
|
113
|
-
this.set(props);
|
|
114
|
-
}
|
|
115
|
-
get context() {
|
|
116
|
-
return _expressive_state.Context.get(this);
|
|
117
|
-
}
|
|
118
|
-
set context(context) {
|
|
119
|
-
if (OUTER.get(this) === context) return;
|
|
120
|
-
OUTER.set(this, context);
|
|
121
|
-
context.push(this);
|
|
122
|
-
}
|
|
123
|
-
get state() {
|
|
124
|
-
return this.get();
|
|
125
|
-
}
|
|
126
|
-
set state(_state) {}
|
|
127
|
-
constructor(nextProps, ...rest) {
|
|
128
|
-
const { is } = nextProps;
|
|
129
|
-
const defaults = typeof argument === "object" ? argument : {};
|
|
130
|
-
if (rest[0] instanceof _expressive_state.Context) rest.shift();
|
|
131
|
-
super(nextProps, defaults, is, rest);
|
|
132
|
-
this.fallback = void 0;
|
|
133
|
-
PROPS.set(this, nextProps);
|
|
134
|
-
if (render) {
|
|
135
|
-
const Self = Render.bind(this, render);
|
|
136
|
-
this.render = () => Pragma.createElement(Self);
|
|
137
|
-
} else if (!this.render) this.render = () => require_context.provide(this.context, this.props.children || null, this.props.fallback, String(this));
|
|
138
|
-
}
|
|
139
101
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
102
|
+
if (value === null) {
|
|
103
|
+
release();
|
|
104
|
+
return () => null;
|
|
105
|
+
}
|
|
106
|
+
return () => {
|
|
107
|
+
pending = false;
|
|
108
|
+
Pragma.useEffect(() => {
|
|
109
|
+
mounted = true;
|
|
110
|
+
}, []);
|
|
111
|
+
useMount(() => release);
|
|
112
|
+
return value === void 0 ? null : value;
|
|
113
|
+
};
|
|
143
114
|
}
|
|
144
115
|
};
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
};
|
|
162
|
-
const View = () => render.call(active, this.props, active);
|
|
116
|
+
/**
|
|
117
|
+
* useEffect which tolerates react StrictMode double-invoking effects on mount.
|
|
118
|
+
*/
|
|
119
|
+
function useMount(callback) {
|
|
120
|
+
const { current } = Pragma.useRef({});
|
|
121
|
+
current.update = Pragma.useState(() => {
|
|
122
|
+
if (!current.mounts) {
|
|
123
|
+
current.mounts = 0;
|
|
124
|
+
current.unmount = callback(() => {
|
|
125
|
+
if (current.ready) current.update((x) => x + 1);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return current.mounts++;
|
|
129
|
+
})[1];
|
|
130
|
+
Pragma.useEffect(() => {
|
|
131
|
+
current.ready = true;
|
|
163
132
|
return () => {
|
|
164
|
-
|
|
165
|
-
Pragma.useEffect(didMount, []);
|
|
166
|
-
setTimeout(() => ready = true, 0);
|
|
167
|
-
return require_context.provide(context, Pragma.createElement(View), this.props.fallback, String(this));
|
|
133
|
+
if (!--current.mounts) current.unmount?.();
|
|
168
134
|
};
|
|
169
|
-
});
|
|
170
|
-
return state[0]();
|
|
135
|
+
}, []);
|
|
171
136
|
}
|
|
172
137
|
|
|
173
138
|
//#endregion
|
|
174
139
|
exports.Pragma = Pragma;
|
|
175
|
-
exports.
|
|
140
|
+
exports.State = _expressive_state.State;
|
|
141
|
+
exports.useMount = useMount;
|
|
176
142
|
//# sourceMappingURL=state.js.map
|
package/dist/state.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","names":["State","Context","Layers","provide"],"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,mBAAmBA,wBAAM;;;;;;;CAiBtC,OAAO,IAEL,GAAG,MACA;EACH,MAAM,UAAUC,0BAAQ,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,gCAAM,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;AAE9B,QAAI,OAAO;AACT,aAAQ;AAER,aAAQ,QAAQ,IAAI,GAA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AEF,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,UAAOA,wBACL,SACA,OAAO,cAAc,KAAK,EAC1B,KAAK,MAAM,UACX,OAAO,KAAK,CACb;;GAEH;AAEF,QAAO,MAAM,IAAI"}
|
|
1
|
+
{"version":3,"file":"state.js","names":["Context"],"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,wBAAM,MAAM,SAEV,GAAG,MACH;CACA,MAAM,QAAQA,0BAAQ,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,iCAAM,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,wBAAM,MAAM,SAEV,UACA;CACA,MAAM,MAAM,OAAO,OAA2B,KAAK;CACnD,MAAM,OAAO,OA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AAU;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/package.json
CHANGED
|
@@ -32,16 +32,6 @@
|
|
|
32
32
|
"types": "./dist/state.d.ts",
|
|
33
33
|
"require": "./dist/state.js",
|
|
34
34
|
"import": "./dist/esm/state.js"
|
|
35
|
-
},
|
|
36
|
-
"./jsx-runtime": {
|
|
37
|
-
"types": "./dist/jsx-runtime.d.ts",
|
|
38
|
-
"require": "./dist/jsx-runtime.js",
|
|
39
|
-
"import": "./dist/esm/jsx-runtime.js"
|
|
40
|
-
},
|
|
41
|
-
"./jsx-dev-runtime": {
|
|
42
|
-
"types": "./dist/jsx-dev-runtime.d.ts",
|
|
43
|
-
"require": "./dist/jsx-dev-runtime.js",
|
|
44
|
-
"import": "./dist/esm/jsx-dev-runtime.js"
|
|
45
35
|
}
|
|
46
36
|
},
|
|
47
37
|
"files": [
|
|
@@ -53,7 +43,7 @@
|
|
|
53
43
|
"preversion": "npm run test && npm run build"
|
|
54
44
|
},
|
|
55
45
|
"dependencies": {
|
|
56
|
-
"@expressive/state": "^0.
|
|
46
|
+
"@expressive/state": "^0.75.0"
|
|
57
47
|
},
|
|
58
48
|
"peerDependencies": {
|
|
59
49
|
"react": ">=16.8.0 <20.0.0"
|
|
@@ -74,6 +64,6 @@
|
|
|
74
64
|
"tsup": "^8.0.2",
|
|
75
65
|
"vitest": "^4.0.18"
|
|
76
66
|
},
|
|
77
|
-
"version": "0.
|
|
78
|
-
"gitHead": "
|
|
67
|
+
"version": "0.75.0",
|
|
68
|
+
"gitHead": "8545753fc1f8da654b3e4d70b2f3905d168bd982"
|
|
79
69
|
}
|
package/dist/chunk-BE-pF4vm.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
-
key = keys[i];
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
-
__defProp(to, key, {
|
|
14
|
-
get: ((k) => from[k]).bind(null, key),
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
-
value: mod,
|
|
24
|
-
enumerable: true
|
|
25
|
-
}) : target, mod));
|
|
26
|
-
|
|
27
|
-
//#endregion
|
|
28
|
-
|
|
29
|
-
Object.defineProperty(exports, '__toESM', {
|
|
30
|
-
enumerable: true,
|
|
31
|
-
get: function () {
|
|
32
|
-
return __toESM;
|
|
33
|
-
}
|
|
34
|
-
});
|