@warp-drive-mirror/react 5.8.0-alpha.3 → 5.8.0-alpha.32

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 (50) hide show
  1. package/README.md +36 -15
  2. package/dist/unpkg/dev/declarations/-private/reactive-context.d.ts +18 -0
  3. package/dist/unpkg/dev/declarations/-private/request.d.ts +141 -0
  4. package/dist/unpkg/dev/declarations/-private/store-provider.d.ts +19 -0
  5. package/dist/unpkg/dev/declarations/index.d.ts +7 -0
  6. package/dist/unpkg/dev/declarations/install.d.ts +3 -0
  7. package/dist/unpkg/dev/index.js +274 -0
  8. package/dist/unpkg/dev/install.js +104 -0
  9. package/dist/unpkg/dev/reactive-context-ClTRYXie.js +154 -0
  10. package/dist/unpkg/dev-deprecated/declarations/-private/reactive-context.d.ts +18 -0
  11. package/dist/unpkg/dev-deprecated/declarations/-private/request.d.ts +141 -0
  12. package/dist/unpkg/dev-deprecated/declarations/-private/store-provider.d.ts +19 -0
  13. package/dist/unpkg/dev-deprecated/declarations/index.d.ts +7 -0
  14. package/dist/unpkg/dev-deprecated/declarations/install.d.ts +3 -0
  15. package/dist/unpkg/dev-deprecated/index.js +274 -0
  16. package/dist/unpkg/dev-deprecated/install.js +104 -0
  17. package/dist/unpkg/dev-deprecated/reactive-context-ClTRYXie.js +154 -0
  18. package/dist/unpkg/prod/declarations/-private/reactive-context.d.ts +18 -0
  19. package/dist/unpkg/prod/declarations/-private/request.d.ts +141 -0
  20. package/dist/unpkg/prod/declarations/-private/store-provider.d.ts +19 -0
  21. package/dist/unpkg/prod/declarations/index.d.ts +7 -0
  22. package/dist/unpkg/prod/declarations/install.d.ts +3 -0
  23. package/dist/unpkg/prod/index.js +274 -0
  24. package/dist/unpkg/prod/install.js +104 -0
  25. package/dist/unpkg/prod/reactive-context-ClTRYXie.js +154 -0
  26. package/dist/unpkg/prod-deprecated/declarations/-private/reactive-context.d.ts +18 -0
  27. package/dist/unpkg/prod-deprecated/declarations/-private/request.d.ts +141 -0
  28. package/dist/unpkg/prod-deprecated/declarations/-private/store-provider.d.ts +19 -0
  29. package/dist/unpkg/prod-deprecated/declarations/index.d.ts +7 -0
  30. package/dist/unpkg/prod-deprecated/declarations/install.d.ts +3 -0
  31. package/dist/unpkg/prod-deprecated/index.js +274 -0
  32. package/dist/unpkg/prod-deprecated/install.js +104 -0
  33. package/dist/unpkg/prod-deprecated/reactive-context-ClTRYXie.js +154 -0
  34. package/logos/README.md +2 -2
  35. package/logos/logo-yellow-slab.svg +1 -0
  36. package/logos/word-mark-black.svg +1 -0
  37. package/logos/word-mark-white.svg +1 -0
  38. package/package.json +5 -5
  39. package/logos/NCC-1701-a-blue.svg +0 -4
  40. package/logos/NCC-1701-a-gold.svg +0 -4
  41. package/logos/NCC-1701-a-gold_100.svg +0 -1
  42. package/logos/NCC-1701-a-gold_base-64.txt +0 -1
  43. package/logos/NCC-1701-a.svg +0 -4
  44. package/logos/docs-badge.svg +0 -2
  45. package/logos/ember-data-logo-dark.svg +0 -12
  46. package/logos/ember-data-logo-light.svg +0 -12
  47. package/logos/social1.png +0 -0
  48. package/logos/social2.png +0 -0
  49. package/logos/warp-drive-logo-dark.svg +0 -4
  50. package/logos/warp-drive-logo-gold.svg +0 -4
package/README.md CHANGED
@@ -1,25 +1,46 @@
1
1
  <p align="center">
2
2
  <img
3
3
  class="project-logo"
4
- src="./logos/NCC-1701-a-blue.svg#gh-light-mode-only"
4
+ src="./logos/logo-yellow-slab.svg"
5
5
  alt="WarpDrive"
6
- width="120px"
7
- title="WarpDrive" />
8
- <img
9
- class="project-logo"
10
- src="./logos/NCC-1701-a.svg#gh-dark-mode-only"
11
- alt="WarpDrive"
12
- width="120px"
13
- title="WarpDrive" />
6
+ width="180px"
7
+ title="WarpDrive"
8
+ />
14
9
  </p>
15
10
 
16
- <h3 align="center">:electron: Components, Hooks and Utilities for using <em style="color: lightgreen">Warp</em><strong style="color: magenta">Drive</strong> with <strong style="color: lightblue">React</strong></h3>
11
+ ![NPM Stable Version](https://img.shields.io/npm/v/ember-data/latest?label=version&style=flat&color=fdb155)
12
+ ![NPM Downloads](https://img.shields.io/npm/dm/ember-data.svg?style=flat&color=fdb155)
13
+ ![License](https://img.shields.io/github/license/warp-drive-data/warp-drive.svg?style=flat&color=fdb155)
14
+ [![EmberJS Discord Community Server](https://img.shields.io/badge/EmberJS-grey?logo=discord&logoColor=fdb155)](https://discord.gg/zT3asNS
15
+ )
16
+ [![WarpDrive Discord Server](https://img.shields.io/badge/WarpDrive-grey?logo=discord&logoColor=fdb155)](https://discord.gg/PHBbnWJx5S
17
+ )
18
+
19
+ <h3 align="center">Signals Integration and Component API for using <em>Warp</em><strong>Drive</strong> with <strong style="color: lightblue">React</strong></h3>
20
+
21
+ ***Warp*Drive** makes it easy to build scalable, fast, feature
22
+ rich applications &mdash; letting you ship better experiences more quickly without re-architecting your app or API. ***Warp*Drive** is:
23
+
24
+ - 🌌 Seamless Reactivity in any Framework
25
+ - ⚡️ Committed to Best-In-Class Performance
26
+ - 💚 Typed
27
+ - ⚛️ Works with any API
28
+ - 🌲 Focused on being as tiny as possible
29
+ - 🚀 SSR Ready
30
+ - 🐹 Built with ♥️ by [Ember](https://emberjs.com)
31
+
32
+ <br>
33
+ <br>
34
+
35
+ *Get Started* → [Guides](https://warp-drive.io/guides/)
36
+
37
+ <br>
17
38
 
18
39
  ---
19
40
 
20
- ```sh
21
- pnpm install @warp-drive-mirror/react
22
- ```
41
+ <br>
42
+
43
+ # @warp-drive-mirror/react
23
44
 
24
45
  **Tagged Releases**
25
46
 
@@ -44,7 +65,7 @@ This library provides reactive utilities for working with promises and requests,
44
65
  img.project-logo {
45
66
  padding: 0 5em 1em 5em;
46
67
  width: 100px;
47
- border-bottom: 2px solid #0969da;
68
+ border-bottom: 2px solid #bbb;
48
69
  margin: 0 auto;
49
70
  display: block;
50
71
  }
@@ -60,7 +81,7 @@ This library provides reactive utilities for working with promises and requests,
60
81
  display: inline-block;
61
82
  padding: .2rem 0;
62
83
  color: #000;
63
- border-bottom: 3px solid #0969da;
84
+ border-bottom: 3px solid #bbb;
64
85
  }
65
86
 
66
87
  details > details {
@@ -0,0 +1,18 @@
1
+ import { Signal } from "signal-polyfill";
2
+ import { type JSX, type ReactNode, type Context } from "react";
3
+ export declare function useWatcher(): {
4
+ watcher: Signal.subtle.Watcher;
5
+ } | null;
6
+ /**
7
+ * @category Contexts
8
+ */
9
+ export declare const WatcherContext: Context<{
10
+ watcher: Signal.subtle.Watcher;
11
+ } | null>;
12
+ /**
13
+ *
14
+ * @category Components
15
+ */
16
+ export declare function ReactiveContext({ children }: {
17
+ children: ReactNode;
18
+ }): JSX.Element;
@@ -0,0 +1,141 @@
1
+ import { RequestArgs, type ContentFeatures, type RecoveryFeatures, type RequestLoadingState, type RequestState } from "@warp-drive-mirror/core/store/-private";
2
+ import type { StructuredErrorDocument } from "@warp-drive-mirror/core/types/request";
3
+ import { JSX, ReactNode } from "react";
4
+ interface ChromeComponentProps<RT> {
5
+ children: ReactNode;
6
+ state: RequestState | null;
7
+ features: ContentFeatures<RT>;
8
+ }
9
+ export interface RequestProps<
10
+ RT,
11
+ E
12
+ > extends RequestArgs<RT, E> {
13
+ chrome?: React.FC<ChromeComponentProps<RT>>;
14
+ states: RequestStates<RT, E>;
15
+ }
16
+ interface RequestStates<
17
+ RT,
18
+ E
19
+ > {
20
+ /**
21
+ * The block to render when the component is idle and waiting to be given a request.
22
+ *
23
+ */
24
+ idle?: React.FC<{}>;
25
+ /**
26
+ * The block to render when the request is loading.
27
+ *
28
+ */
29
+ loading?: React.FC<{
30
+ state: RequestLoadingState;
31
+ }>;
32
+ /**
33
+ * The block to render when the request was cancelled.
34
+ *
35
+ */
36
+ cancelled?: React.FC<{
37
+ /**
38
+ * The Error the request rejected with.
39
+ */
40
+ error: StructuredErrorDocument<E>;
41
+ /**
42
+ * Utilities to assist in recovering from the error.
43
+ */
44
+ features: RecoveryFeatures;
45
+ }>;
46
+ /**
47
+ * The block to render when the request failed. If this block is not provided,
48
+ * the error will be rethrown.
49
+ *
50
+ * Thus it is required to provide an error block and proper error handling if
51
+ * you do not want the error to crash the application.
52
+ */
53
+ error: React.FC<{
54
+ /**
55
+ * The Error the request rejected with.
56
+ */
57
+ error: StructuredErrorDocument<E>;
58
+ /**
59
+ * Utilities to assist in recovering from the error.
60
+ */
61
+ features: RecoveryFeatures;
62
+ }>;
63
+ /**
64
+ * The block to render when the request succeeded.
65
+ *
66
+ */
67
+ content: React.FC<{
68
+ result: RT;
69
+ features: ContentFeatures<RT>;
70
+ }>;
71
+ }
72
+ export declare function Throw({ error }: {
73
+ error: Error;
74
+ }): never;
75
+ /**
76
+ * The `<Request />` component is a powerful tool for managing data fetching and
77
+ * state in your React application. It provides a declarative approach to reactive
78
+ * control-flow for managing requests and state in your application.
79
+ *
80
+ * The `<Request />` component is ideal for handling "boundaries", outside which some
81
+ * state is still allowed to be unresolved and within which it MUST be resolved.
82
+ *
83
+ * ## Request States
84
+ *
85
+ * `<Request />` has five states, only one of which will be active and rendered at a time.
86
+ *
87
+ * - `idle`: The component is waiting to be given a request to monitor
88
+ * - `loading`: The request is in progress
89
+ * - `error`: The request failed
90
+ * - `content`: The request succeeded
91
+ * - `cancelled`: The request was cancelled
92
+ *
93
+ * Additionally, the `content` state has a `refresh` method that can be used to
94
+ * refresh the request in the background, which is available as a sub-state of
95
+ * the `content` state.
96
+ *
97
+ * ### Example Usage
98
+ *
99
+ * ```tsx
100
+ * import { Request } from "@warp-drive-mirror/react";
101
+ *
102
+ * export function UserPreview($props: { id: string | null }) {
103
+ * return (
104
+ * <Request
105
+ * query={findRecord('user', $props.id)}
106
+ * states={{
107
+ * idle: () => <div>Waiting for User Selection</div>,
108
+ * loading: ({ state }) => <div>Loading user data...</div>,
109
+ * cancelled: ({ error, features }) => (
110
+ * <div>
111
+ * <p>Request Cancelled</p>
112
+ * <p><button onClick={features.retry}>Start Again?</button></p>
113
+ * </div>
114
+ * ),
115
+ * error: ({ error, features }) => (
116
+ * <div>
117
+ * <p>Error: {error.message}</p>
118
+ * <p><button onClick={features.retry}>Try Again?</button></p>
119
+ * </div>
120
+ * ),
121
+ * content: ({ result, features }) => (
122
+ * <div>
123
+ * <h2>User Details</h2>
124
+ * <p>ID: {result.id}</p>
125
+ * <p>Name: {result.name}</p>
126
+ * </div>
127
+ * ),
128
+ * }}
129
+ * />
130
+ * );
131
+ * }
132
+ *
133
+ * ```
134
+ *
135
+ * @category Components
136
+ */
137
+ export declare function Request<
138
+ RT,
139
+ E
140
+ >($props: RequestProps<RT, E>): JSX.Element;
141
+ export {};
@@ -0,0 +1,19 @@
1
+ import { Store } from "@warp-drive-mirror/core";
2
+ import { JSX, ReactNode } from "react";
3
+ /**
4
+ * @category Hooks
5
+ */
6
+ export declare function useStore(): Store;
7
+ type WithExistingStore = {
8
+ store: Store;
9
+ children: ReactNode;
10
+ };
11
+ type WithNewStore = {
12
+ Store: typeof Store;
13
+ children: ReactNode;
14
+ };
15
+ /**
16
+ * @category Components
17
+ */
18
+ export declare function StoreProvider($props: WithExistingStore | WithNewStore): JSX.Element;
19
+ export {};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @module
3
+ * @mergeModuleWith <project>
4
+ */
5
+ export { ReactiveContext, WatcherContext } from "./-private/reactive-context.js";
6
+ export { StoreProvider, useStore } from "./-private/store-provider.js";
7
+ export { Request, Throw } from "./-private/request.js";
@@ -0,0 +1,3 @@
1
+ import { type HooksOptions, type SignalHooks } from "@warp-drive-mirror/core/configure";
2
+ export declare function settled(): Promise<void>;
3
+ export declare function buildSignalConfig(options: HooksOptions): SignalHooks;
@@ -0,0 +1,274 @@
1
+ import { R as ReactiveContext } from "./reactive-context-ClTRYXie.js";
2
+ export { W as WatcherContext } from "./reactive-context-ClTRYXie.js";
3
+ import '@warp-drive-mirror/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 { DISPOSE, createRequestSubscription, signal } from '@warp-drive-mirror/core/store/-private';
8
+ import '@warp-drive-mirror/core/request';
9
+ const StoreContext = /*#__PURE__*/createContext(null);
10
+
11
+ /**
12
+ * @category Hooks
13
+ */
14
+ function useStore() {
15
+ const store = use(StoreContext);
16
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
17
+ if (!test) {
18
+ throw new Error("No Store provided via context. Please ensure you are using <StoreProvider> to provide a Store instance.");
19
+ }
20
+ })(store) : {};
21
+ return store;
22
+ }
23
+ /**
24
+ * @category Components
25
+ */
26
+ function StoreProvider($props) {
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
+ });
32
+ }
33
+ const deferred = /* @__PURE__ */new WeakMap();
34
+ function deferDecorator(proto, prop, desc) {
35
+ let map = deferred.get(proto);
36
+ if (!map) {
37
+ map = /* @__PURE__ */new Map();
38
+ deferred.set(proto, map);
39
+ }
40
+ map.set(prop, desc);
41
+ }
42
+ function findDeferredDecorator(target, prop) {
43
+ var _a;
44
+ let cursor = target.prototype;
45
+ while (cursor) {
46
+ let desc = (_a = deferred.get(cursor)) == null ? void 0 : _a.get(prop);
47
+ if (desc) {
48
+ return desc;
49
+ }
50
+ cursor = cursor.prototype;
51
+ }
52
+ }
53
+ function decorateFieldV2(prototype, prop, decorators, initializer) {
54
+ let desc = {
55
+ configurable: true,
56
+ enumerable: true,
57
+ writable: true,
58
+ initializer: null
59
+ };
60
+ if (initializer) {
61
+ desc.initializer = initializer;
62
+ }
63
+ for (let decorator of decorators) {
64
+ desc = decorator(prototype, prop, desc) || desc;
65
+ }
66
+ if (desc.initializer === void 0) {
67
+ Object.defineProperty(prototype, prop, desc);
68
+ } else {
69
+ deferDecorator(prototype, prop, desc);
70
+ }
71
+ }
72
+ function initializeDeferredDecorator(target, prop) {
73
+ let desc = findDeferredDecorator(target.constructor, prop);
74
+ if (desc) {
75
+ Object.defineProperty(target, prop, {
76
+ enumerable: desc.enumerable,
77
+ configurable: desc.configurable,
78
+ writable: desc.writable,
79
+ value: desc.initializer ? desc.initializer.call(target) : void 0
80
+ });
81
+ }
82
+ }
83
+ const IdleBlockMissingError = new Error("No idle block provided for <Request> component, and no query or request was provided.");
84
+ class ReactiveArgs {
85
+ static {
86
+ decorateFieldV2(this.prototype, "request", [signal]);
87
+ }
88
+ #request = (initializeDeferredDecorator(this, "request"), void 0);
89
+ static {
90
+ decorateFieldV2(this.prototype, "query", [signal]);
91
+ }
92
+ #query = (initializeDeferredDecorator(this, "query"), void 0);
93
+ static {
94
+ decorateFieldV2(this.prototype, "autorefresh", [signal]);
95
+ }
96
+ #autorefresh = (initializeDeferredDecorator(this, "autorefresh"), void 0);
97
+ static {
98
+ decorateFieldV2(this.prototype, "autorefreshThreshold", [signal]);
99
+ }
100
+ #autorefreshThreshold = (initializeDeferredDecorator(this, "autorefreshThreshold"), void 0);
101
+ static {
102
+ decorateFieldV2(this.prototype, "autorefreshBehavior", [signal]);
103
+ }
104
+ #autorefreshBehavior = (initializeDeferredDecorator(this, "autorefreshBehavior"), void 0);
105
+ }
106
+ const DefaultChrome = ({
107
+ children
108
+ }) => {
109
+ return /*#__PURE__*/jsx(Fragment, {
110
+ children: children
111
+ });
112
+ };
113
+ function Throw({
114
+ error
115
+ }) {
116
+ throw error;
117
+ }
118
+
119
+ /**
120
+ * The `<Request />` component is a powerful tool for managing data fetching and
121
+ * state in your React application. It provides a declarative approach to reactive
122
+ * control-flow for managing requests and state in your application.
123
+ *
124
+ * The `<Request />` component is ideal for handling "boundaries", outside which some
125
+ * state is still allowed to be unresolved and within which it MUST be resolved.
126
+ *
127
+ * ## Request States
128
+ *
129
+ * `<Request />` has five states, only one of which will be active and rendered at a time.
130
+ *
131
+ * - `idle`: The component is waiting to be given a request to monitor
132
+ * - `loading`: The request is in progress
133
+ * - `error`: The request failed
134
+ * - `content`: The request succeeded
135
+ * - `cancelled`: The request was cancelled
136
+ *
137
+ * Additionally, the `content` state has a `refresh` method that can be used to
138
+ * refresh the request in the background, which is available as a sub-state of
139
+ * the `content` state.
140
+ *
141
+ * ### Example Usage
142
+ *
143
+ * ```tsx
144
+ * import { Request } from "@warp-drive-mirror/react";
145
+ *
146
+ * export function UserPreview($props: { id: string | null }) {
147
+ * return (
148
+ * <Request
149
+ * query={findRecord('user', $props.id)}
150
+ * states={{
151
+ * idle: () => <div>Waiting for User Selection</div>,
152
+ * loading: ({ state }) => <div>Loading user data...</div>,
153
+ * cancelled: ({ error, features }) => (
154
+ * <div>
155
+ * <p>Request Cancelled</p>
156
+ * <p><button onClick={features.retry}>Start Again?</button></p>
157
+ * </div>
158
+ * ),
159
+ * error: ({ error, features }) => (
160
+ * <div>
161
+ * <p>Error: {error.message}</p>
162
+ * <p><button onClick={features.retry}>Try Again?</button></p>
163
+ * </div>
164
+ * ),
165
+ * content: ({ result, features }) => (
166
+ * <div>
167
+ * <h2>User Details</h2>
168
+ * <p>ID: {result.id}</p>
169
+ * <p>Name: {result.name}</p>
170
+ * </div>
171
+ * ),
172
+ * }}
173
+ * />
174
+ * );
175
+ * }
176
+ *
177
+ * ```
178
+ *
179
+ * @category Components
180
+ */
181
+ function Request($props) {
182
+ return /*#__PURE__*/jsx(ReactiveContext, {
183
+ children: /*#__PURE__*/jsx(InternalRequest, {
184
+ ...$props
185
+ })
186
+ });
187
+ }
188
+ function isStrictModeRender() {
189
+ const count = useRef(0);
190
+
191
+ // in debug we need to skip every second invocation
192
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
193
+ if (count.current++ % 2 === 1) {
194
+ return true;
195
+ }
196
+ }
197
+ return false;
198
+ }
199
+ function InternalRequest($props) {
200
+ const isStrict = isStrictModeRender();
201
+ const store = $props.store ?? useStore();
202
+ const Chrome = $props.chrome ?? DefaultChrome;
203
+ const sink = useRef(null);
204
+ const args = useRef(null);
205
+ if (!args.current) {
206
+ args.current = new ReactiveArgs();
207
+ }
208
+ Object.assign(args.current, $props);
209
+ if (sink.current && (sink.current.store !== store || $props.subscription)) {
210
+ sink.current[DISPOSE]();
211
+ sink.current = null;
212
+ }
213
+ if (!sink.current && !$props.subscription) {
214
+ sink.current = createRequestSubscription(store, args.current);
215
+ }
216
+ const initialized = useRef(null);
217
+ const effect = () => {
218
+ if (sink.current && (!initialized.current || initialized.current.disposable !== sink.current)) {
219
+ initialized.current = {
220
+ disposable: sink.current,
221
+ dispose: () => {
222
+ sink.current?.[DISPOSE]();
223
+ initialized.current = null;
224
+ sink.current = null;
225
+ }
226
+ };
227
+ }
228
+ return sink.current ? initialized.current.dispose : undefined;
229
+ };
230
+ let maybeEffect = effect;
231
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
232
+ if (isStrict) {
233
+ maybeEffect = () => {
234
+ if (initialized.current) {
235
+ return effect();
236
+ }
237
+ return () => {
238
+ // initialize our actual effect
239
+ effect();
240
+ // in strict mode we don't want to run the teardown
241
+ // for the second invocation
242
+ };
243
+ };
244
+ }
245
+ }
246
+ useEffect(maybeEffect, [sink.current]);
247
+ const state = $props.subscription ?? sink.current;
248
+ const slots = $props.states;
249
+ return /*#__PURE__*/jsx(Chrome, {
250
+ state: state.isIdle ? null : state.reqState,
251
+ features: state.contentFeatures,
252
+ children:
253
+ // prettier-ignore
254
+ state.isIdle && slots.idle ? /*#__PURE__*/jsx(slots.idle, {}) : state.isIdle ? /*#__PURE__*/jsx(Throw, {
255
+ error: IdleBlockMissingError
256
+ }) : state.reqState.isLoading ? slots.loading ? /*#__PURE__*/jsx(slots.loading, {
257
+ state: state.reqState.loadingState
258
+ }) : '' : state.reqState.isCancelled && slots.cancelled ? /*#__PURE__*/jsx(slots.cancelled, {
259
+ error: state.reqState.reason,
260
+ features: state.errorFeatures
261
+ }) : state.reqState.isError && slots.error ? /*#__PURE__*/jsx(slots.error, {
262
+ error: state.reqState.reason,
263
+ features: state.errorFeatures
264
+ }) : state.reqState.isSuccess ? slots.content ? /*#__PURE__*/jsx(slots.content, {
265
+ result: state.reqState.value,
266
+ features: state.contentFeatures
267
+ }) : /*#__PURE__*/jsx(Throw, {
268
+ error: new Error('No content block provided for <Request> component.')
269
+ }) : !state.reqState.isCancelled ? /*#__PURE__*/jsx(Throw, {
270
+ error: state.reqState.reason
271
+ }) : '' // never
272
+ });
273
+ }
274
+ export { ReactiveContext, Request, StoreProvider, Throw, useStore };
@@ -0,0 +1,104 @@
1
+ import { use } from 'react';
2
+ import { Signal } from 'signal-polyfill';
3
+ import { setupSignals } from '@warp-drive-mirror/core/configure';
4
+ import { W as WatcherContext } from "./reactive-context-ClTRYXie.js";
5
+ import { macroCondition, getGlobalConfig } from '@embroider/macros';
6
+
7
+ /**
8
+ * {@include ./install.md}
9
+ * @module
10
+ */
11
+
12
+ function tryConsumeContext(signal) {
13
+ // eslint-disable-next-line no-console
14
+ const logError = console.error;
15
+ try {
16
+ // eslint-disable-next-line no-console
17
+ console.error = () => {};
18
+ // ensure signals are watched by our closest watcher
19
+ const watcher = use(WatcherContext);
20
+ // eslint-disable-next-line no-console
21
+ console.error = logError;
22
+ watcher?.watcher.watch(signal);
23
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
24
+ if (getGlobalConfig().WarpDriveMirror.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) {
25
+ // eslint-disable-next-line no-console
26
+ console.log(`[WarpDrive] Consumed Context Signal`, signal, watcher);
27
+ }
28
+ }
29
+ } catch {
30
+ // eslint-disable-next-line no-console
31
+ console.error = logError;
32
+ // if we are not in a React context, we will Error
33
+ // so we just ignore it.
34
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
35
+ if (getGlobalConfig().WarpDriveMirror.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) {
36
+ // eslint-disable-next-line no-console
37
+ console.log(`[WarpDrive] No Context Available To Consume Signal`, signal);
38
+ }
39
+ }
40
+ }
41
+ }
42
+ let pending;
43
+ async function settled() {
44
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.TESTING)) {
45
+ // in testing mode we provide a test waiter integration
46
+ if (!pending || !pending.length) return;
47
+ const current = pending ?? [];
48
+ pending = [];
49
+ await Promise.allSettled(current);
50
+ await Promise.resolve();
51
+ await Promise.resolve();
52
+ await Promise.resolve();
53
+ return settled();
54
+ }
55
+ }
56
+ function buildSignalConfig(options) {
57
+ return {
58
+ createSignal: (obj, key) => new Signal.State(macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? {
59
+ obj,
60
+ key
61
+ } : null, {
62
+ equals: () => false
63
+ }),
64
+ notifySignal: signal => {
65
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
66
+ if (getGlobalConfig().WarpDriveMirror.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) {
67
+ if (Signal.subtle.hasSinks(signal)) {
68
+ // eslint-disable-next-line no-console
69
+ console.log(`[WarpDrive] Notifying Signal`, signal);
70
+ } else {
71
+ // eslint-disable-next-line no-console
72
+ console.log(`[WarpDrive] Notified Signal That Has No Watcher`, signal);
73
+ }
74
+ }
75
+ }
76
+ signal.set(signal.get());
77
+ },
78
+ consumeSignal: signal => {
79
+ tryConsumeContext(signal);
80
+ void signal.get();
81
+ },
82
+ createMemo: (object, key, fn) => {
83
+ const memo = new Signal.Computed(fn);
84
+ return () => {
85
+ tryConsumeContext(memo);
86
+ return memo.get();
87
+ };
88
+ },
89
+ waitFor: promise => {
90
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.TESTING)) {
91
+ pending = pending || [];
92
+ const newPromise = promise.finally(() => {
93
+ pending = pending.filter(p => p !== newPromise);
94
+ });
95
+ pending.push(newPromise);
96
+ return newPromise;
97
+ }
98
+ return promise;
99
+ },
100
+ willSyncFlushWatchers: () => false
101
+ };
102
+ }
103
+ setupSignals(buildSignalConfig);
104
+ export { buildSignalConfig, settled };