@warp-drive/react 5.9.0-beta.0 → 5.9.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/declarations/index.d.ts +179 -6
  2. package/declarations/index.d.ts.map +1 -0
  3. package/declarations/install.d.ts +21 -3
  4. package/declarations/install.d.ts.map +1 -0
  5. package/dist/index.js +216 -251
  6. package/dist/index.js.map +1 -0
  7. package/dist/install.js +90 -94
  8. package/dist/install.js.map +1 -0
  9. package/dist/reactive-context-DNq02nr1.js +122 -0
  10. package/dist/reactive-context-DNq02nr1.js.map +1 -0
  11. package/dist/unpkg/dev/index.js +260 -299
  12. package/dist/unpkg/dev/index.js.map +1 -0
  13. package/dist/unpkg/dev/install.js +82 -92
  14. package/dist/unpkg/dev/install.js.map +1 -0
  15. package/dist/unpkg/dev/reactive-context-C9-Fc8qx.js +218 -0
  16. package/dist/unpkg/dev/reactive-context-C9-Fc8qx.js.map +1 -0
  17. package/dist/unpkg/dev-deprecated/index.js +260 -299
  18. package/dist/unpkg/dev-deprecated/index.js.map +1 -0
  19. package/dist/unpkg/dev-deprecated/install.js +82 -92
  20. package/dist/unpkg/dev-deprecated/install.js.map +1 -0
  21. package/dist/unpkg/dev-deprecated/reactive-context-DhpCE2Tv.js +218 -0
  22. package/dist/unpkg/dev-deprecated/reactive-context-DhpCE2Tv.js.map +1 -0
  23. package/dist/unpkg/prod/index.js +199 -226
  24. package/dist/unpkg/prod/index.js.map +1 -0
  25. package/dist/unpkg/prod/install.js +56 -48
  26. package/dist/unpkg/prod/install.js.map +1 -0
  27. package/dist/unpkg/prod/reactive-context-CvfXAZqb.js +92 -0
  28. package/dist/unpkg/prod/reactive-context-CvfXAZqb.js.map +1 -0
  29. package/dist/unpkg/prod-deprecated/index.js +199 -226
  30. package/dist/unpkg/prod-deprecated/index.js.map +1 -0
  31. package/dist/unpkg/prod-deprecated/install.js +56 -48
  32. package/dist/unpkg/prod-deprecated/install.js.map +1 -0
  33. package/dist/unpkg/prod-deprecated/reactive-context-CvfXAZqb.js +92 -0
  34. package/dist/unpkg/prod-deprecated/reactive-context-CvfXAZqb.js.map +1 -0
  35. package/package.json +14 -15
  36. package/declarations/-private/reactive-context.d.ts +0 -18
  37. package/declarations/-private/request.d.ts +0 -142
  38. package/declarations/-private/store-provider.d.ts +0 -19
  39. package/dist/reactive-context-ClTRYXie.js +0 -154
  40. package/dist/unpkg/dev/reactive-context-B815u0_c.js +0 -290
  41. package/dist/unpkg/dev-deprecated/reactive-context-DMgQ7YV_.js +0 -290
  42. package/dist/unpkg/prod/reactive-context-DKimDkR3.js +0 -110
  43. package/dist/unpkg/prod-deprecated/reactive-context-DKimDkR3.js +0 -110
package/dist/index.js CHANGED
@@ -1,275 +1,240 @@
1
- import { R as ReactiveContext } from "./reactive-context-ClTRYXie.js";
2
- export { W as WatcherContext } from "./reactive-context-ClTRYXie.js";
3
- import '@warp-drive/core';
4
- import { useMemo, createContext, use, useRef, useEffect } from 'react';
5
- import { macroCondition, getGlobalConfig } from '@embroider/macros';
6
- import { jsx, Fragment } from 'react/jsx-runtime';
7
- import { createRequestSubscription } from '@warp-drive/core/reactive';
8
- import { DISPOSE, signal } from '@warp-drive/core/signals/-leaked';
9
- import '@warp-drive/core/request';
10
- const StoreContext = /*#__PURE__*/createContext(null);
1
+ import { n as WatcherContext, t as ReactiveContext } from "./reactive-context-DNq02nr1.js";
2
+ import { createContext, use, useEffect, useMemo, useRef } from "react";
3
+ import { getGlobalConfig, macroCondition } from "@embroider/macros";
4
+ import { Fragment, jsx } from "react/jsx-runtime";
5
+ import { createRequestSubscription } from "@warp-drive/core/reactive";
6
+ import { DISPOSE, signal } from "@warp-drive/core/signals/-leaked";
11
7
 
8
+ //#region src/-private/store-provider.tsx
12
9
  /**
13
- * @category Hooks
14
- */
10
+ * @category Contexts
11
+ */
12
+ const StoreContext = /*#__PURE__*/ createContext(null);
13
+ /**
14
+ * @category Hooks
15
+ */
15
16
  function useStore() {
16
- const store = use(StoreContext);
17
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
18
- if (!test) {
19
- throw new Error("No Store provided via context. Please ensure you are using <StoreProvider> to provide a Store instance.");
20
- }
21
- })(store) : {};
22
- return store;
17
+ const store = use(StoreContext);
18
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
19
+ if (!test) throw new Error("No Store provided via context. Please ensure you are using <StoreProvider> to provide a Store instance.");
20
+ })(store);
21
+ return store;
23
22
  }
24
23
  /**
25
- * @category Components
26
- */
24
+ * @category Components
25
+ */
27
26
  function StoreProvider($props) {
28
- const store = useMemo(() => "store" in $props ? $props.store : new $props.Store(), ["store" in $props ? $props.store : $props.Store]);
29
- return /*#__PURE__*/jsx(StoreContext, {
30
- value: store,
31
- children: $props.children
32
- });
27
+ const store = useMemo(() => "store" in $props ? $props.store : new $props.Store(), ["store" in $props ? $props.store : $props.Store]);
28
+ return /*#__PURE__*/ jsx(StoreContext, {
29
+ value: store,
30
+ children: $props.children
31
+ });
33
32
  }
34
- const deferred = /* @__PURE__ */new WeakMap();
33
+
34
+ //#endregion
35
+ //#region ../../node_modules/.pnpm/decorat_5005bbc272376d25df08203abab44e2f/node_modules/decorator-transforms/dist/runtime-BPCpkOf1.js
36
+ const deferred = /* @__PURE__ */ new WeakMap();
35
37
  function deferDecorator(proto, prop, desc) {
36
- let map = deferred.get(proto);
37
- if (!map) {
38
- map = /* @__PURE__ */new Map();
39
- deferred.set(proto, map);
40
- }
41
- map.set(prop, desc);
38
+ let map = deferred.get(proto);
39
+ if (!map) {
40
+ map = /* @__PURE__ */ new Map();
41
+ deferred.set(proto, map);
42
+ }
43
+ map.set(prop, desc);
42
44
  }
43
45
  function findDeferredDecorator(target, prop) {
44
- var _a;
45
- let cursor = target.prototype;
46
- while (cursor) {
47
- let desc = (_a = deferred.get(cursor)) == null ? void 0 : _a.get(prop);
48
- if (desc) {
49
- return desc;
50
- }
51
- cursor = cursor.prototype;
52
- }
46
+ var _a;
47
+ let cursor = target.prototype;
48
+ while (cursor) {
49
+ let desc = (_a = deferred.get(cursor)) == null ? void 0 : _a.get(prop);
50
+ if (desc) return desc;
51
+ cursor = cursor.prototype;
52
+ }
53
53
  }
54
54
  function decorateFieldV2(prototype, prop, decorators, initializer) {
55
- let desc = {
56
- configurable: true,
57
- enumerable: true,
58
- writable: true,
59
- initializer: null
60
- };
61
- if (initializer) {
62
- desc.initializer = initializer;
63
- }
64
- for (let decorator of decorators) {
65
- desc = decorator(prototype, prop, desc) || desc;
66
- }
67
- if (desc.initializer === void 0) {
68
- Object.defineProperty(prototype, prop, desc);
69
- } else {
70
- deferDecorator(prototype, prop, desc);
71
- }
55
+ let desc = {
56
+ configurable: true,
57
+ enumerable: true,
58
+ writable: true,
59
+ initializer: null
60
+ };
61
+ if (initializer) desc.initializer = initializer;
62
+ for (let decorator of decorators) desc = decorator(prototype, prop, desc) || desc;
63
+ if (desc.initializer === void 0) Object.defineProperty(prototype, prop, desc);
64
+ else deferDecorator(prototype, prop, desc);
72
65
  }
73
66
  function initializeDeferredDecorator(target, prop) {
74
- let desc = findDeferredDecorator(target.constructor, prop);
75
- if (desc) {
76
- Object.defineProperty(target, prop, {
77
- enumerable: desc.enumerable,
78
- configurable: desc.configurable,
79
- writable: desc.writable,
80
- value: desc.initializer ? desc.initializer.call(target) : void 0
81
- });
82
- }
83
- }
84
- const IdleBlockMissingError = new Error("No idle block provided for <Request> component, and no query or request was provided.");
85
- class ReactiveArgs {
86
- static {
87
- decorateFieldV2(this.prototype, "request", [signal]);
88
- }
89
- #request = (initializeDeferredDecorator(this, "request"), void 0);
90
- static {
91
- decorateFieldV2(this.prototype, "query", [signal]);
92
- }
93
- #query = (initializeDeferredDecorator(this, "query"), void 0);
94
- static {
95
- decorateFieldV2(this.prototype, "autorefresh", [signal]);
96
- }
97
- #autorefresh = (initializeDeferredDecorator(this, "autorefresh"), void 0);
98
- static {
99
- decorateFieldV2(this.prototype, "autorefreshThreshold", [signal]);
100
- }
101
- #autorefreshThreshold = (initializeDeferredDecorator(this, "autorefreshThreshold"), void 0);
102
- static {
103
- decorateFieldV2(this.prototype, "autorefreshBehavior", [signal]);
104
- }
105
- #autorefreshBehavior = (initializeDeferredDecorator(this, "autorefreshBehavior"), void 0);
67
+ let desc = findDeferredDecorator(target.constructor, prop);
68
+ if (desc) Object.defineProperty(target, prop, {
69
+ enumerable: desc.enumerable,
70
+ configurable: desc.configurable,
71
+ writable: desc.writable,
72
+ value: desc.initializer ? desc.initializer.call(target) : void 0
73
+ });
106
74
  }
107
- const DefaultChrome = ({
108
- children
109
- }) => {
110
- return /*#__PURE__*/jsx(Fragment, {
111
- children: children
112
- });
75
+
76
+ //#endregion
77
+ //#region src/-private/request.tsx
78
+ const IdleBlockMissingError = /* @__PURE__ */ new Error("No idle block provided for <Request> component, and no query or request was provided.");
79
+ var ReactiveArgs = class {
80
+ static {
81
+ decorateFieldV2(this.prototype, "request", [signal]);
82
+ }
83
+ #request = (initializeDeferredDecorator(this, "request"), void 0);
84
+ static {
85
+ decorateFieldV2(this.prototype, "query", [signal]);
86
+ }
87
+ #query = (initializeDeferredDecorator(this, "query"), void 0);
88
+ static {
89
+ decorateFieldV2(this.prototype, "autorefresh", [signal]);
90
+ }
91
+ #autorefresh = (initializeDeferredDecorator(this, "autorefresh"), void 0);
92
+ static {
93
+ decorateFieldV2(this.prototype, "autorefreshThreshold", [signal]);
94
+ }
95
+ #autorefreshThreshold = (initializeDeferredDecorator(this, "autorefreshThreshold"), void 0);
96
+ static {
97
+ decorateFieldV2(this.prototype, "autorefreshBehavior", [signal]);
98
+ }
99
+ #autorefreshBehavior = (initializeDeferredDecorator(this, "autorefreshBehavior"), void 0);
100
+ };
101
+ const DefaultChrome = ({ children }) => {
102
+ return /*#__PURE__*/ jsx(Fragment, { children });
113
103
  };
114
- function Throw({
115
- error
116
- }) {
117
- throw error;
104
+ /**
105
+ * Throws the given error. Used internally to rethrow request errors that
106
+ * are not otherwise handled by a provided error/cancelled block.
107
+ *
108
+ * @private
109
+ */
110
+ function Throw({ error }) {
111
+ throw error;
118
112
  }
119
-
120
113
  /**
121
- * The `<Request />` component is a powerful tool for managing data fetching and
122
- * state in your React application. It provides a declarative approach to reactive
123
- * control-flow for managing requests and state in your application.
124
- *
125
- * The `<Request />` component is ideal for handling "boundaries", outside which some
126
- * state is still allowed to be unresolved and within which it MUST be resolved.
127
- *
128
- * ## Request States
129
- *
130
- * `<Request />` has five states, only one of which will be active and rendered at a time.
131
- *
132
- * - `idle`: The component is waiting to be given a request to monitor
133
- * - `loading`: The request is in progress
134
- * - `error`: The request failed
135
- * - `content`: The request succeeded
136
- * - `cancelled`: The request was cancelled
137
- *
138
- * Additionally, the `content` state has a `refresh` method that can be used to
139
- * refresh the request in the background, which is available as a sub-state of
140
- * the `content` state.
141
- *
142
- * ### Example Usage
143
- *
144
- * ```tsx
145
- * import { Request } from "@warp-drive/react";
146
- *
147
- * export function UserPreview($props: { id: string | null }) {
148
- * return (
149
- * <Request
150
- * query={findRecord('user', $props.id)}
151
- * states={{
152
- * idle: () => <div>Waiting for User Selection</div>,
153
- * loading: ({ state }) => <div>Loading user data...</div>,
154
- * cancelled: ({ error, features }) => (
155
- * <div>
156
- * <p>Request Cancelled</p>
157
- * <p><button onClick={features.retry}>Start Again?</button></p>
158
- * </div>
159
- * ),
160
- * error: ({ error, features }) => (
161
- * <div>
162
- * <p>Error: {error.message}</p>
163
- * <p><button onClick={features.retry}>Try Again?</button></p>
164
- * </div>
165
- * ),
166
- * content: ({ result, features }) => (
167
- * <div>
168
- * <h2>User Details</h2>
169
- * <p>ID: {result.id}</p>
170
- * <p>Name: {result.name}</p>
171
- * </div>
172
- * ),
173
- * }}
174
- * />
175
- * );
176
- * }
177
- *
178
- * ```
179
- *
180
- * @category Components
181
- */
114
+ * The `<Request />` component is a powerful tool for managing data fetching and
115
+ * state in your React application. It provides a declarative approach to reactive
116
+ * control-flow for managing requests and state in your application.
117
+ *
118
+ * The `<Request />` component is ideal for handling "boundaries", outside which some
119
+ * state is still allowed to be unresolved and within which it MUST be resolved.
120
+ *
121
+ * ## Request States
122
+ *
123
+ * `<Request />` has five states, only one of which will be active and rendered at a time.
124
+ *
125
+ * - `idle`: The component is waiting to be given a request to monitor
126
+ * - `loading`: The request is in progress
127
+ * - `error`: The request failed
128
+ * - `content`: The request succeeded
129
+ * - `cancelled`: The request was cancelled
130
+ *
131
+ * Additionally, the `content` state has a `refresh` method that can be used to
132
+ * refresh the request in the background, which is available as a sub-state of
133
+ * the `content` state.
134
+ *
135
+ * ### Example Usage
136
+ *
137
+ * ```tsx
138
+ * import { Request } from "@warp-drive/react";
139
+ *
140
+ * export function UserPreview($props: { id: string | null }) {
141
+ * return (
142
+ * <Request
143
+ * query={findRecord('user', $props.id)}
144
+ * states={{
145
+ * idle: () => <div>Waiting for User Selection</div>,
146
+ * loading: ({ state }) => <div>Loading user data...</div>,
147
+ * cancelled: ({ error, features }) => (
148
+ * <div>
149
+ * <p>Request Cancelled</p>
150
+ * <p><button onClick={features.retry}>Start Again?</button></p>
151
+ * </div>
152
+ * ),
153
+ * error: ({ error, features }) => (
154
+ * <div>
155
+ * <p>Error: {error.message}</p>
156
+ * <p><button onClick={features.retry}>Try Again?</button></p>
157
+ * </div>
158
+ * ),
159
+ * content: ({ result, features }) => (
160
+ * <div>
161
+ * <h2>User Details</h2>
162
+ * <p>ID: {result.id}</p>
163
+ * <p>Name: {result.name}</p>
164
+ * </div>
165
+ * ),
166
+ * }}
167
+ * />
168
+ * );
169
+ * }
170
+ *
171
+ * ```
172
+ *
173
+ * @category Components
174
+ */
182
175
  function Request($props) {
183
- return /*#__PURE__*/jsx(ReactiveContext, {
184
- children: /*#__PURE__*/jsx(InternalRequest, {
185
- ...$props
186
- })
187
- });
176
+ return /*#__PURE__*/ jsx(ReactiveContext, { children: /*#__PURE__*/ jsx(InternalRequest, { ...$props }) });
188
177
  }
189
178
  function isStrictModeRender() {
190
- const count = useRef(0);
191
-
192
- // in debug we need to skip every second invocation
193
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
194
- if (count.current++ % 2 === 1) {
195
- return true;
196
- }
197
- }
198
- return false;
179
+ const count = useRef(0);
180
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
181
+ if (count.current++ % 2 === 1) return true;
182
+ }
183
+ return false;
199
184
  }
200
185
  function InternalRequest($props) {
201
- const isStrict = isStrictModeRender();
202
- const store = $props.store ?? useStore();
203
- const Chrome = $props.chrome ?? DefaultChrome;
204
- const sink = useRef(null);
205
- const args = useRef(null);
206
- if (!args.current) {
207
- args.current = new ReactiveArgs();
208
- }
209
- Object.assign(args.current, $props);
210
- if (sink.current && (sink.current.store !== store || $props.subscription)) {
211
- sink.current[DISPOSE]();
212
- sink.current = null;
213
- }
214
- if (!sink.current && !$props.subscription) {
215
- sink.current = createRequestSubscription(store, args.current);
216
- }
217
- const initialized = useRef(null);
218
- const effect = () => {
219
- if (sink.current && (!initialized.current || initialized.current.disposable !== sink.current)) {
220
- initialized.current = {
221
- disposable: sink.current,
222
- dispose: () => {
223
- sink.current?.[DISPOSE]();
224
- initialized.current = null;
225
- sink.current = null;
226
- }
227
- };
228
- }
229
- return sink.current ? initialized.current.dispose : undefined;
230
- };
231
- let maybeEffect = effect;
232
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
233
- if (isStrict) {
234
- maybeEffect = () => {
235
- if (initialized.current) {
236
- return effect();
237
- }
238
- return () => {
239
- // initialize our actual effect
240
- effect();
241
- // in strict mode we don't want to run the teardown
242
- // for the second invocation
243
- };
244
- };
245
- }
246
- }
247
- useEffect(maybeEffect, [sink.current]);
248
- const state = $props.subscription ?? sink.current;
249
- const slots = $props.states;
250
- return /*#__PURE__*/jsx(Chrome, {
251
- state: state.isIdle ? null : state.reqState,
252
- features: state.contentFeatures,
253
- children:
254
- // prettier-ignore
255
- state.isIdle && slots.idle ? /*#__PURE__*/jsx(slots.idle, {}) : state.isIdle ? /*#__PURE__*/jsx(Throw, {
256
- error: IdleBlockMissingError
257
- }) : state.reqState.isLoading ? slots.loading ? /*#__PURE__*/jsx(slots.loading, {
258
- state: state.reqState.loadingState
259
- }) : '' : state.reqState.isCancelled && slots.cancelled ? /*#__PURE__*/jsx(slots.cancelled, {
260
- error: state.reqState.reason,
261
- features: state.errorFeatures
262
- }) : state.reqState.isError && slots.error ? /*#__PURE__*/jsx(slots.error, {
263
- error: state.reqState.reason,
264
- features: state.errorFeatures
265
- }) : state.reqState.isSuccess ? slots.content ? /*#__PURE__*/jsx(slots.content, {
266
- result: state.reqState.value,
267
- features: state.contentFeatures
268
- }) : /*#__PURE__*/jsx(Throw, {
269
- error: new Error('No content block provided for <Request> component.')
270
- }) : !state.reqState.isCancelled ? /*#__PURE__*/jsx(Throw, {
271
- error: state.reqState.reason
272
- }) : '' // never
273
- });
186
+ const isStrict = isStrictModeRender();
187
+ const store = $props.store ?? useStore();
188
+ const Chrome = $props.chrome ?? DefaultChrome;
189
+ const sink = useRef(null);
190
+ const args = useRef(null);
191
+ if (!args.current) args.current = new ReactiveArgs();
192
+ Object.assign(args.current, $props);
193
+ if (sink.current && (sink.current.store !== store || $props.subscription)) {
194
+ sink.current[DISPOSE]();
195
+ sink.current = null;
196
+ }
197
+ if (!sink.current && !$props.subscription) sink.current = createRequestSubscription(store, args.current);
198
+ const initialized = useRef(null);
199
+ const effect = () => {
200
+ if (sink.current && (!initialized.current || initialized.current.disposable !== sink.current)) initialized.current = {
201
+ disposable: sink.current,
202
+ dispose: () => {
203
+ sink.current?.[DISPOSE]();
204
+ initialized.current = null;
205
+ sink.current = null;
206
+ }
207
+ };
208
+ return sink.current ? initialized.current.dispose : void 0;
209
+ };
210
+ let maybeEffect = effect;
211
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
212
+ if (isStrict) maybeEffect = () => {
213
+ if (initialized.current) return effect();
214
+ return () => {
215
+ effect();
216
+ };
217
+ };
218
+ }
219
+ useEffect(maybeEffect, [sink.current]);
220
+ const state = $props.subscription ?? sink.current;
221
+ const slots = $props.states;
222
+ return /*#__PURE__*/ jsx(Chrome, {
223
+ state: state.isIdle ? null : state.reqState,
224
+ features: state.contentFeatures,
225
+ children: state.isIdle && slots.idle ? /*#__PURE__*/ jsx(slots.idle, {}) : state.isIdle ? /*#__PURE__*/ jsx(Throw, { error: IdleBlockMissingError }) : state.reqState.isLoading ? slots.loading ? /*#__PURE__*/ jsx(slots.loading, { state: state.reqState.loadingState }) : "" : state.reqState.isCancelled && slots.cancelled ? /*#__PURE__*/ jsx(slots.cancelled, {
226
+ error: state.reqState.reason,
227
+ features: state.errorFeatures
228
+ }) : state.reqState.isError && slots.error ? /*#__PURE__*/ jsx(slots.error, {
229
+ error: state.reqState.reason,
230
+ features: state.errorFeatures
231
+ }) : state.reqState.isSuccess ? slots.content ? /*#__PURE__*/ jsx(slots.content, {
232
+ result: state.reqState.value,
233
+ features: state.contentFeatures
234
+ }) : /*#__PURE__*/ jsx(Throw, { error: /* @__PURE__ */ new Error("No content block provided for <Request> component.") }) : !state.reqState.isCancelled ? /*#__PURE__*/ jsx(Throw, { error: state.reqState.reason }) : ""
235
+ });
274
236
  }
275
- export { ReactiveContext, Request, StoreProvider, Throw, useStore };
237
+
238
+ //#endregion
239
+ export { ReactiveContext, Request, StoreProvider, Throw, WatcherContext, useStore };
240
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["Store","createContext","JSX","ReactNode","use","useMemo","macroCondition","getGlobalConfig","jsx","_jsx","StoreContext","useStore","store","WarpDrive","env","DEBUG","test","Error","StoreProvider","$props","value","children","createRequestSubscription","AutorefreshBehaviorCombos","DISPOSE","RequestArgs","signal","JSX","ReactNode","useEffect","useMemo","useRef","useStore","ReactiveContext","Future","StoreRequestInput","getGlobalConfig","macroCondition","g","i","Fragment","_Fragment","jsx","_jsx","IdleBlockMissingError","Error","ReactiveArgs","prototype","request","void 0","query","autorefresh","autorefreshThreshold","autorefreshBehavior","DefaultChrome","children","Throw","error","Request","$props","InternalRequest","isStrictModeRender","count","WarpDrive","env","DEBUG","current","isStrict","store","Chrome","chrome","sink","args","Object","assign","subscription","initialized","effect","disposable","dispose","undefined","maybeEffect","state","slots","states","isIdle","reqState","features","contentFeatures","idle","isLoading","loading","loadingState","isCancelled","cancelled","reason","errorFeatures","isError","isSuccess","content","result","value"],"sources":["../src/-private/store-provider.tsx","../../../node_modules/.pnpm/decorat_5005bbc272376d25df08203abab44e2f/node_modules/decorator-transforms/dist/runtime-BPCpkOf1.js","../src/-private/request.tsx"],"sourcesContent":["import { Store } from \"@warp-drive/core\";\nimport { assert } from \"@warp-drive/core/build-config/macros\";\nimport { createContext, JSX, ReactNode, use, useMemo } from \"react\";\n\n/**\n * @category Contexts\n */\nconst StoreContext = createContext<Store | null>(null);\n\n/**\n * @category Hooks\n */\nexport function useStore(): Store {\n const store = use(StoreContext);\n assert(\n \"No Store provided via context. Please ensure you are using <StoreProvider> to provide a Store instance.\",\n store\n );\n return store;\n}\n\ntype WithExistingStore = { store: Store; children: ReactNode };\ntype WithNewStore = { Store: typeof Store; children: ReactNode };\n\n/**\n * @category Components\n */\nexport function StoreProvider($props: WithExistingStore | WithNewStore): JSX.Element {\n const store = useMemo(\n () => (\"store\" in $props ? $props.store : new $props.Store()),\n [\"store\" in $props ? $props.store : $props.Store]\n );\n\n return <StoreContext value={store}>{$props.children}</StoreContext>;\n}\n","const deferred = /* @__PURE__ */ new WeakMap();\nfunction deferDecorator(proto, prop, desc) {\n let map = deferred.get(proto);\n if (!map) {\n map = /* @__PURE__ */ new Map();\n deferred.set(proto, map);\n }\n map.set(prop, desc);\n}\nfunction findDeferredDecorator(target, prop) {\n var _a;\n let cursor = target.prototype;\n while (cursor) {\n let desc = (_a = deferred.get(cursor)) == null ? void 0 : _a.get(prop);\n if (desc) {\n return desc;\n }\n cursor = cursor.prototype;\n }\n}\nfunction decorateFieldV1(target, prop, decorators, initializer) {\n return decorateFieldV2(target.prototype, prop, decorators, initializer);\n}\nfunction decorateFieldV2(prototype, prop, decorators, initializer) {\n let desc = {\n configurable: true,\n enumerable: true,\n writable: true,\n initializer: null\n };\n if (initializer) {\n desc.initializer = initializer;\n }\n for (let decorator of decorators) {\n desc = decorator(prototype, prop, desc) || desc;\n }\n if (desc.initializer === void 0) {\n Object.defineProperty(prototype, prop, desc);\n } else {\n deferDecorator(prototype, prop, desc);\n }\n}\nfunction decorateMethodV1({ prototype }, prop, decorators) {\n return decorateMethodV2(prototype, prop, decorators);\n}\nfunction decorateMethodV2(prototype, prop, decorators) {\n const origDesc = Object.getOwnPropertyDescriptor(prototype, prop);\n let desc = { ...origDesc };\n for (let decorator of decorators) {\n desc = decorator(prototype, prop, desc) || desc;\n }\n if (desc.initializer !== void 0) {\n desc.value = desc.initializer ? desc.initializer.call(prototype) : void 0;\n desc.initializer = void 0;\n }\n Object.defineProperty(prototype, prop, desc);\n}\nfunction initializeDeferredDecorator(target, prop) {\n let desc = findDeferredDecorator(target.constructor, prop);\n if (desc) {\n Object.defineProperty(target, prop, {\n enumerable: desc.enumerable,\n configurable: desc.configurable,\n writable: desc.writable,\n value: desc.initializer ? desc.initializer.call(target) : void 0\n });\n }\n}\nfunction decorateClass(target, decorators) {\n return decorators.reduce(\n (accum, decorator) => decorator(accum) || accum,\n target\n );\n}\nfunction decoratePOJO(pojo, decorated) {\n for (let [type, prop, decorators] of decorated) {\n if (type === \"field\") {\n decoratePojoField(pojo, prop, decorators);\n } else {\n decorateMethodV2(pojo, prop, decorators);\n }\n }\n return pojo;\n}\nfunction decoratePojoField(pojo, prop, decorators) {\n let desc = {\n configurable: true,\n enumerable: true,\n writable: true,\n initializer: () => {\n var _a;\n return (_a = Object.getOwnPropertyDescriptor(pojo, prop)) == null ? void 0 : _a.value;\n }\n };\n for (let decorator of decorators) {\n desc = decorator(pojo, prop, desc) || desc;\n }\n if (desc.initializer) {\n desc.value = desc.initializer.call(pojo);\n delete desc.initializer;\n }\n Object.defineProperty(pojo, prop, desc);\n}\nconst runtime = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({\n __proto__: null,\n c: decorateClass,\n f: decorateFieldV1,\n g: decorateFieldV2,\n i: initializeDeferredDecorator,\n m: decorateMethodV1,\n n: decorateMethodV2,\n p: decoratePOJO\n}, Symbol.toStringTag, { value: \"Module\" }));\nexport {\n decorateFieldV2 as a,\n decorateMethodV1 as b,\n decorateMethodV2 as c,\n decorateFieldV1 as d,\n decorateClass as e,\n decoratePOJO as f,\n initializeDeferredDecorator as i,\n runtime as r\n};\n//# sourceMappingURL=runtime-BPCpkOf1.js.map\n","import {\n createRequestSubscription,\n type RequestLoadingState,\n type RequestState,\n type RequestSubscription,\n} from \"@warp-drive/core/reactive\";\nimport {\n AutorefreshBehaviorCombos,\n DISPOSE,\n RequestArgs,\n signal,\n type ContentFeatures,\n type RecoveryFeatures,\n type SubscriptionArgs,\n} from \"@warp-drive/core/signals/-leaked\";\nimport type { StructuredErrorDocument } from \"@warp-drive/core/types/request\";\nimport { JSX, ReactNode, useEffect, useMemo, useRef } from \"react\";\nimport { useStore } from \"./store-provider\";\nimport { ReactiveContext } from \"./reactive-context\";\nimport { Future } from \"@warp-drive/core/request\";\nimport { StoreRequestInput } from \"@warp-drive/core\";\nimport { DEBUG } from \"@warp-drive/core/build-config/env\";\n\nconst IdleBlockMissingError = new Error(\n \"No idle block provided for <Request> component, and no query or request was provided.\"\n);\n\nclass ReactiveArgs<RT, E> implements SubscriptionArgs<RT, E> {\n @signal request?: Future<RT> | undefined | null;\n @signal query?: StoreRequestInput<RT> | undefined | null;\n @signal autorefresh?: AutorefreshBehaviorCombos | undefined;\n @signal autorefreshThreshold?: number | undefined;\n @signal autorefreshBehavior?: \"refresh\" | \"reload\" | \"policy\";\n}\n\ninterface ChromeComponentProps<RT> {\n children: ReactNode;\n state: RequestState | null;\n features: ContentFeatures<RT>;\n}\n\nconst DefaultChrome = <RT,>({ children }: ChromeComponentProps<RT>) => {\n return <>{children}</>;\n};\n\nexport interface RequestProps<RT, E> extends RequestArgs<RT, E> {\n chrome?: React.FC<ChromeComponentProps<RT>>;\n\n states: RequestStates<RT, E>;\n}\n\ninterface RequestStates<RT, E> {\n /**\n * The block to render when the component is idle and waiting to be given a request.\n *\n */\n idle?: React.FC<{}>;\n\n /**\n * The block to render when the request is loading.\n *\n */\n loading?: React.FC<{ state: RequestLoadingState }>;\n\n /**\n * The block to render when the request was cancelled.\n *\n */\n cancelled?: React.FC<{\n /**\n * The Error the request rejected with.\n */\n error: StructuredErrorDocument<E>;\n /**\n * Utilities to assist in recovering from the error.\n */\n features: RecoveryFeatures;\n }>;\n\n /**\n * The block to render when the request failed. If this block is not provided,\n * the error will be rethrown.\n *\n * Thus it is required to provide an error block and proper error handling if\n * you do not want the error to crash the application.\n */\n error: React.FC<{\n /**\n * The Error the request rejected with.\n */\n error: StructuredErrorDocument<E>;\n /**\n * Utilities to assist in recovering from the error.\n */\n features: RecoveryFeatures;\n }>;\n\n /**\n * The block to render when the request succeeded.\n *\n */\n content: React.FC<{ result: RT; features: ContentFeatures<RT> }>;\n}\n\n/**\n * Throws the given error. Used internally to rethrow request errors that\n * are not otherwise handled by a provided error/cancelled block.\n *\n * @private\n */\nexport function Throw({ error }: { error: Error }): never {\n throw error;\n}\n\n/**\n * The `<Request />` component is a powerful tool for managing data fetching and\n * state in your React application. It provides a declarative approach to reactive\n * control-flow for managing requests and state in your application.\n *\n * The `<Request />` component is ideal for handling \"boundaries\", outside which some\n * state is still allowed to be unresolved and within which it MUST be resolved.\n *\n * ## Request States\n *\n * `<Request />` has five states, only one of which will be active and rendered at a time.\n *\n * - `idle`: The component is waiting to be given a request to monitor\n * - `loading`: The request is in progress\n * - `error`: The request failed\n * - `content`: The request succeeded\n * - `cancelled`: The request was cancelled\n *\n * Additionally, the `content` state has a `refresh` method that can be used to\n * refresh the request in the background, which is available as a sub-state of\n * the `content` state.\n *\n * ### Example Usage\n *\n * ```tsx\n * import { Request } from \"@warp-drive/react\";\n *\n * export function UserPreview($props: { id: string | null }) {\n * return (\n * <Request\n * query={findRecord('user', $props.id)}\n * states={{\n * idle: () => <div>Waiting for User Selection</div>,\n * loading: ({ state }) => <div>Loading user data...</div>,\n * cancelled: ({ error, features }) => (\n * <div>\n * <p>Request Cancelled</p>\n * <p><button onClick={features.retry}>Start Again?</button></p>\n * </div>\n * ),\n * error: ({ error, features }) => (\n * <div>\n * <p>Error: {error.message}</p>\n * <p><button onClick={features.retry}>Try Again?</button></p>\n * </div>\n * ),\n * content: ({ result, features }) => (\n * <div>\n * <h2>User Details</h2>\n * <p>ID: {result.id}</p>\n * <p>Name: {result.name}</p>\n * </div>\n * ),\n * }}\n * />\n * );\n * }\n *\n * ```\n *\n * @category Components\n */\nexport function Request<RT, E>($props: RequestProps<RT, E>): JSX.Element {\n return (\n <ReactiveContext>\n <InternalRequest {...$props} />\n </ReactiveContext>\n );\n}\n\nfunction isStrictModeRender(): boolean {\n const count = useRef<number>(0);\n\n // in debug we need to skip every second invocation\n if (DEBUG) {\n if (count.current++ % 2 === 1) {\n return true;\n }\n }\n\n return false;\n}\n\nfunction InternalRequest<RT, E>($props: RequestProps<RT, E>): JSX.Element {\n const isStrict = isStrictModeRender();\n const store = $props.store ?? useStore();\n const Chrome = $props.chrome ?? DefaultChrome;\n const sink = useRef<RequestSubscription<RT, E> | null>(null);\n const args = useRef<SubscriptionArgs<RT, E> | null>(null);\n\n if (!args.current) {\n args.current = new ReactiveArgs<RT, E>();\n }\n Object.assign(args.current, $props);\n\n if (sink.current && (sink.current.store !== store || $props.subscription)) {\n sink.current[DISPOSE]();\n sink.current = null;\n }\n\n if (!sink.current && !$props.subscription) {\n sink.current = createRequestSubscription(store, args.current!);\n }\n\n const initialized = useRef<null | {\n disposable: { [DISPOSE]: () => void } | null;\n dispose: () => void;\n }>(null);\n const effect = () => {\n if (sink.current && (!initialized.current || initialized.current.disposable !== sink.current)) {\n initialized.current = {\n disposable: sink.current,\n dispose: () => {\n sink.current?.[DISPOSE]();\n initialized.current = null;\n sink.current = null;\n },\n };\n }\n\n return sink.current ? initialized.current!.dispose : undefined;\n };\n let maybeEffect = effect;\n\n if (DEBUG) {\n if (isStrict) {\n maybeEffect = () => {\n if (initialized.current) {\n return effect();\n }\n return () => {\n // initialize our actual effect\n effect();\n // in strict mode we don't want to run the teardown\n // for the second invocation\n };\n };\n }\n }\n\n useEffect(maybeEffect, [sink.current]);\n\n const state = $props.subscription ?? sink.current!;\n const slots = $props.states;\n\n return (\n <Chrome state={state.isIdle ? null : state.reqState} features={state.contentFeatures}>\n {\n // prettier-ignore\n state.isIdle && slots.idle ? <slots.idle />\n : state.isIdle ? <Throw error={IdleBlockMissingError} />\n : state.reqState.isLoading ? slots.loading ? <slots.loading state={state.reqState.loadingState} /> : ''\n : state.reqState.isCancelled && slots.cancelled ? <slots.cancelled error={state.reqState.reason} features={state.errorFeatures} />\n : state.reqState.isError && slots.error ? <slots.error error={state.reqState.reason} features={state.errorFeatures} />\n : state.reqState.isSuccess ? slots.content ? <slots.content result={state.reqState.value} features={state.contentFeatures} /> : <Throw error={new Error('No content block provided for <Request> component.')} />\n : !state.reqState.isCancelled ? <Throw error={state.reqState.reason} />\n : '' // never\n }\n </Chrome>\n );\n}\n"],"x_google_ignoreList":[1],"mappings":";;;;;;;;;;;AAOA,MAAMU,eAAeT,4BAA4B,IAAI;;;;AAKrD,SAAgBU,WAAkB;CAChC,MAAMC,QAAQR,IAAIM,YAAY;CAC9BJ,eAAAC,gBAAA,CAAA,CAAAM,UAAAC,IAAAC,KAAA,OAAAC,SAAA;EAAA,IAAA,CAAAA,MAAA,MAAA,IAAAC,MACE,yGAAyG;CAAA,EAAA,CACzGL,KAAK;CAEP,OAAOA;AACT;;;;AAQA,SAAgBM,cAAcC,QAAuD;CACnF,MAAMP,QAAQP,cACL,WAAWc,SAASA,OAAOP,QAAQ,IAAIO,OAAOnB,MAAM,GAC3D,CAAC,WAAWmB,SAASA,OAAOP,QAAQO,OAAO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