esp-js-react 8.1.1-next.0 → 9.0.0-beta.3

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/.dist/esp-react.esm.mjs +710 -0
  2. package/.dist/esp-react.esm.mjs.map +1 -0
  3. package/.dist/esp-react.js +695 -777
  4. package/.dist/esp-react.js.map +1 -1
  5. package/.dist/esp-react.min.js +2 -3
  6. package/.dist/esp-react.min.js.map +1 -1
  7. package/.dist/typings/connectableComponent.d.ts +8 -9
  8. package/.dist/typings/espApp.d.ts +25 -0
  9. package/.dist/typings/espEventBusContextProvider.d.ts +41 -0
  10. package/.dist/typings/espModulesContext.d.ts +3 -0
  11. package/.dist/typings/espStoreContextProvider.d.ts +62 -0
  12. package/.dist/typings/index.d.ts +13 -9
  13. package/.dist/typings/regionView.d.ts +19 -0
  14. package/.dist/typings/useSyncStoreModelWithSelector.d.ts +47 -0
  15. package/README.md +62 -22
  16. package/package.json +63 -45
  17. package/.dist/esp-react.min.js.LICENSE.txt +0 -9
  18. package/.dist/typings/connect.d.ts +0 -8
  19. package/.dist/typings/espModelContextProvider.d.ts +0 -63
  20. package/.dist/typings/espRouterContextProvider.d.ts +0 -54
  21. package/.dist/typings/polimer/polimerModelBuilderExtentsions.d.ts +0 -6
  22. package/.dist/typings/useSyncModelWithSelector.d.ts +0 -52
  23. package/.dist/typings/viewBinder.d.ts +0 -13
  24. package/.dist/typings/viewBindingDecorator.d.ts +0 -34
  25. package/.yarnignore +0 -15
  26. package/docs/images/esp-agile-demo.gif +0 -0
  27. package/jest.config.js +0 -19
  28. package/src/connect.tsx +0 -27
  29. package/src/connectableComponent.tsx +0 -99
  30. package/src/espModelContextProvider.tsx +0 -101
  31. package/src/espRouterContextProvider.tsx +0 -97
  32. package/src/index.ts +0 -68
  33. package/src/polimer/polimerModelBuilderExtentsions.ts +0 -36
  34. package/src/useSyncModelWithSelector.ts +0 -223
  35. package/src/viewBinder.tsx +0 -51
  36. package/src/viewBindingDecorator.ts +0 -113
  37. package/tests/connectableComponentTests.tsx +0 -477
  38. package/tests/espModelContextProviderTests.tsx +0 -150
  39. package/tests/espRouterContextProviderTests.tsx +0 -56
  40. package/tests/indexTests.ts +0 -47
  41. package/tests/testApi/asserts.ts +0 -102
  42. package/tests/testApi/routerSpy.ts +0 -24
  43. package/tests/testApi/testApi.tsx +0 -100
  44. package/tests/testApi/testModel.ts +0 -43
  45. package/tests/testApi/useStoreReceivedProps.ts +0 -14
  46. package/tests/testApi/viewFactory.tsx +0 -31
  47. package/tests/useSyncModelWithSelectorTests.tsx +0 -330
  48. package/tests/viewBinderTests.tsx +0 -61
  49. package/tsconfig.json +0 -14
  50. package/webpack.config.js +0 -27
@@ -0,0 +1,710 @@
1
+ import * as require$$0 from "react";
2
+ import require$$0__default, { createContext, useCallback, useContext, useMemo } from "react";
3
+ import { DefaultStoreAddress, Logger, utils } from "esp-js";
4
+ var jsxRuntime = { exports: {} };
5
+ var reactJsxRuntime_production = {};
6
+ /**
7
+ * @license React
8
+ * react-jsx-runtime.production.js
9
+ *
10
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
11
+ *
12
+ * This source code is licensed under the MIT license found in the
13
+ * LICENSE file in the root directory of this source tree.
14
+ */
15
+ var hasRequiredReactJsxRuntime_production;
16
+ function requireReactJsxRuntime_production() {
17
+ if (hasRequiredReactJsxRuntime_production) return reactJsxRuntime_production;
18
+ hasRequiredReactJsxRuntime_production = 1;
19
+ var REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"), REACT_FRAGMENT_TYPE = Symbol.for("react.fragment");
20
+ function jsxProd(type, config, maybeKey) {
21
+ var key = null;
22
+ void 0 !== maybeKey && (key = "" + maybeKey);
23
+ void 0 !== config.key && (key = "" + config.key);
24
+ if ("key" in config) {
25
+ maybeKey = {};
26
+ for (var propName in config)
27
+ "key" !== propName && (maybeKey[propName] = config[propName]);
28
+ } else maybeKey = config;
29
+ config = maybeKey.ref;
30
+ return {
31
+ $$typeof: REACT_ELEMENT_TYPE,
32
+ type,
33
+ key,
34
+ ref: void 0 !== config ? config : null,
35
+ props: maybeKey
36
+ };
37
+ }
38
+ reactJsxRuntime_production.Fragment = REACT_FRAGMENT_TYPE;
39
+ reactJsxRuntime_production.jsx = jsxProd;
40
+ reactJsxRuntime_production.jsxs = jsxProd;
41
+ return reactJsxRuntime_production;
42
+ }
43
+ var reactJsxRuntime_development = {};
44
+ /**
45
+ * @license React
46
+ * react-jsx-runtime.development.js
47
+ *
48
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
49
+ *
50
+ * This source code is licensed under the MIT license found in the
51
+ * LICENSE file in the root directory of this source tree.
52
+ */
53
+ var hasRequiredReactJsxRuntime_development;
54
+ function requireReactJsxRuntime_development() {
55
+ if (hasRequiredReactJsxRuntime_development) return reactJsxRuntime_development;
56
+ hasRequiredReactJsxRuntime_development = 1;
57
+ "production" !== process.env.NODE_ENV && function() {
58
+ function getComponentNameFromType(type) {
59
+ if (null == type) return null;
60
+ if ("function" === typeof type)
61
+ return type.$$typeof === REACT_CLIENT_REFERENCE ? null : type.displayName || type.name || null;
62
+ if ("string" === typeof type) return type;
63
+ switch (type) {
64
+ case REACT_FRAGMENT_TYPE:
65
+ return "Fragment";
66
+ case REACT_PROFILER_TYPE:
67
+ return "Profiler";
68
+ case REACT_STRICT_MODE_TYPE:
69
+ return "StrictMode";
70
+ case REACT_SUSPENSE_TYPE:
71
+ return "Suspense";
72
+ case REACT_SUSPENSE_LIST_TYPE:
73
+ return "SuspenseList";
74
+ case REACT_ACTIVITY_TYPE:
75
+ return "Activity";
76
+ }
77
+ if ("object" === typeof type)
78
+ switch ("number" === typeof type.tag && console.error(
79
+ "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
80
+ ), type.$$typeof) {
81
+ case REACT_PORTAL_TYPE:
82
+ return "Portal";
83
+ case REACT_CONTEXT_TYPE:
84
+ return type.displayName || "Context";
85
+ case REACT_CONSUMER_TYPE:
86
+ return (type._context.displayName || "Context") + ".Consumer";
87
+ case REACT_FORWARD_REF_TYPE:
88
+ var innerType = type.render;
89
+ type = type.displayName;
90
+ type || (type = innerType.displayName || innerType.name || "", type = "" !== type ? "ForwardRef(" + type + ")" : "ForwardRef");
91
+ return type;
92
+ case REACT_MEMO_TYPE:
93
+ return innerType = type.displayName || null, null !== innerType ? innerType : getComponentNameFromType(type.type) || "Memo";
94
+ case REACT_LAZY_TYPE:
95
+ innerType = type._payload;
96
+ type = type._init;
97
+ try {
98
+ return getComponentNameFromType(type(innerType));
99
+ } catch (x) {
100
+ }
101
+ }
102
+ return null;
103
+ }
104
+ function testStringCoercion(value) {
105
+ return "" + value;
106
+ }
107
+ function checkKeyStringCoercion(value) {
108
+ try {
109
+ testStringCoercion(value);
110
+ var JSCompiler_inline_result = false;
111
+ } catch (e) {
112
+ JSCompiler_inline_result = true;
113
+ }
114
+ if (JSCompiler_inline_result) {
115
+ JSCompiler_inline_result = console;
116
+ var JSCompiler_temp_const = JSCompiler_inline_result.error;
117
+ var JSCompiler_inline_result$jscomp$0 = "function" === typeof Symbol && Symbol.toStringTag && value[Symbol.toStringTag] || value.constructor.name || "Object";
118
+ JSCompiler_temp_const.call(
119
+ JSCompiler_inline_result,
120
+ "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
121
+ JSCompiler_inline_result$jscomp$0
122
+ );
123
+ return testStringCoercion(value);
124
+ }
125
+ }
126
+ function getTaskName(type) {
127
+ if (type === REACT_FRAGMENT_TYPE) return "<>";
128
+ if ("object" === typeof type && null !== type && type.$$typeof === REACT_LAZY_TYPE)
129
+ return "<...>";
130
+ try {
131
+ var name = getComponentNameFromType(type);
132
+ return name ? "<" + name + ">" : "<...>";
133
+ } catch (x) {
134
+ return "<...>";
135
+ }
136
+ }
137
+ function getOwner() {
138
+ var dispatcher = ReactSharedInternals.A;
139
+ return null === dispatcher ? null : dispatcher.getOwner();
140
+ }
141
+ function UnknownOwner() {
142
+ return Error("react-stack-top-frame");
143
+ }
144
+ function hasValidKey(config) {
145
+ if (hasOwnProperty.call(config, "key")) {
146
+ var getter = Object.getOwnPropertyDescriptor(config, "key").get;
147
+ if (getter && getter.isReactWarning) return false;
148
+ }
149
+ return void 0 !== config.key;
150
+ }
151
+ function defineKeyPropWarningGetter(props, displayName) {
152
+ function warnAboutAccessingKey() {
153
+ specialPropKeyWarningShown || (specialPropKeyWarningShown = true, console.error(
154
+ "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
155
+ displayName
156
+ ));
157
+ }
158
+ warnAboutAccessingKey.isReactWarning = true;
159
+ Object.defineProperty(props, "key", {
160
+ get: warnAboutAccessingKey,
161
+ configurable: true
162
+ });
163
+ }
164
+ function elementRefGetterWithDeprecationWarning() {
165
+ var componentName = getComponentNameFromType(this.type);
166
+ didWarnAboutElementRef[componentName] || (didWarnAboutElementRef[componentName] = true, console.error(
167
+ "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
168
+ ));
169
+ componentName = this.props.ref;
170
+ return void 0 !== componentName ? componentName : null;
171
+ }
172
+ function ReactElement(type, key, props, owner, debugStack, debugTask) {
173
+ var refProp = props.ref;
174
+ type = {
175
+ $$typeof: REACT_ELEMENT_TYPE,
176
+ type,
177
+ key,
178
+ props,
179
+ _owner: owner
180
+ };
181
+ null !== (void 0 !== refProp ? refProp : null) ? Object.defineProperty(type, "ref", {
182
+ enumerable: false,
183
+ get: elementRefGetterWithDeprecationWarning
184
+ }) : Object.defineProperty(type, "ref", { enumerable: false, value: null });
185
+ type._store = {};
186
+ Object.defineProperty(type._store, "validated", {
187
+ configurable: false,
188
+ enumerable: false,
189
+ writable: true,
190
+ value: 0
191
+ });
192
+ Object.defineProperty(type, "_debugInfo", {
193
+ configurable: false,
194
+ enumerable: false,
195
+ writable: true,
196
+ value: null
197
+ });
198
+ Object.defineProperty(type, "_debugStack", {
199
+ configurable: false,
200
+ enumerable: false,
201
+ writable: true,
202
+ value: debugStack
203
+ });
204
+ Object.defineProperty(type, "_debugTask", {
205
+ configurable: false,
206
+ enumerable: false,
207
+ writable: true,
208
+ value: debugTask
209
+ });
210
+ Object.freeze && (Object.freeze(type.props), Object.freeze(type));
211
+ return type;
212
+ }
213
+ function jsxDEVImpl(type, config, maybeKey, isStaticChildren, debugStack, debugTask) {
214
+ var children = config.children;
215
+ if (void 0 !== children)
216
+ if (isStaticChildren)
217
+ if (isArrayImpl(children)) {
218
+ for (isStaticChildren = 0; isStaticChildren < children.length; isStaticChildren++)
219
+ validateChildKeys(children[isStaticChildren]);
220
+ Object.freeze && Object.freeze(children);
221
+ } else
222
+ console.error(
223
+ "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
224
+ );
225
+ else validateChildKeys(children);
226
+ if (hasOwnProperty.call(config, "key")) {
227
+ children = getComponentNameFromType(type);
228
+ var keys = Object.keys(config).filter(function(k) {
229
+ return "key" !== k;
230
+ });
231
+ isStaticChildren = 0 < keys.length ? "{key: someKey, " + keys.join(": ..., ") + ": ...}" : "{key: someKey}";
232
+ didWarnAboutKeySpread[children + isStaticChildren] || (keys = 0 < keys.length ? "{" + keys.join(": ..., ") + ": ...}" : "{}", console.error(
233
+ 'A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',
234
+ isStaticChildren,
235
+ children,
236
+ keys,
237
+ children
238
+ ), didWarnAboutKeySpread[children + isStaticChildren] = true);
239
+ }
240
+ children = null;
241
+ void 0 !== maybeKey && (checkKeyStringCoercion(maybeKey), children = "" + maybeKey);
242
+ hasValidKey(config) && (checkKeyStringCoercion(config.key), children = "" + config.key);
243
+ if ("key" in config) {
244
+ maybeKey = {};
245
+ for (var propName in config)
246
+ "key" !== propName && (maybeKey[propName] = config[propName]);
247
+ } else maybeKey = config;
248
+ children && defineKeyPropWarningGetter(
249
+ maybeKey,
250
+ "function" === typeof type ? type.displayName || type.name || "Unknown" : type
251
+ );
252
+ return ReactElement(
253
+ type,
254
+ children,
255
+ maybeKey,
256
+ getOwner(),
257
+ debugStack,
258
+ debugTask
259
+ );
260
+ }
261
+ function validateChildKeys(node) {
262
+ isValidElement(node) ? node._store && (node._store.validated = 1) : "object" === typeof node && null !== node && node.$$typeof === REACT_LAZY_TYPE && ("fulfilled" === node._payload.status ? isValidElement(node._payload.value) && node._payload.value._store && (node._payload.value._store.validated = 1) : node._store && (node._store.validated = 1));
263
+ }
264
+ function isValidElement(object) {
265
+ return "object" === typeof object && null !== object && object.$$typeof === REACT_ELEMENT_TYPE;
266
+ }
267
+ var React = require$$0__default, REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"), REACT_PORTAL_TYPE = Symbol.for("react.portal"), REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"), REACT_STRICT_MODE_TYPE = Symbol.for("react.strict_mode"), REACT_PROFILER_TYPE = Symbol.for("react.profiler"), REACT_CONSUMER_TYPE = Symbol.for("react.consumer"), REACT_CONTEXT_TYPE = Symbol.for("react.context"), REACT_FORWARD_REF_TYPE = Symbol.for("react.forward_ref"), REACT_SUSPENSE_TYPE = Symbol.for("react.suspense"), REACT_SUSPENSE_LIST_TYPE = Symbol.for("react.suspense_list"), REACT_MEMO_TYPE = Symbol.for("react.memo"), REACT_LAZY_TYPE = Symbol.for("react.lazy"), REACT_ACTIVITY_TYPE = Symbol.for("react.activity"), REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference"), ReactSharedInternals = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, hasOwnProperty = Object.prototype.hasOwnProperty, isArrayImpl = Array.isArray, createTask = console.createTask ? console.createTask : function() {
268
+ return null;
269
+ };
270
+ React = {
271
+ react_stack_bottom_frame: function(callStackForError) {
272
+ return callStackForError();
273
+ }
274
+ };
275
+ var specialPropKeyWarningShown;
276
+ var didWarnAboutElementRef = {};
277
+ var unknownOwnerDebugStack = React.react_stack_bottom_frame.bind(
278
+ React,
279
+ UnknownOwner
280
+ )();
281
+ var unknownOwnerDebugTask = createTask(getTaskName(UnknownOwner));
282
+ var didWarnAboutKeySpread = {};
283
+ reactJsxRuntime_development.Fragment = REACT_FRAGMENT_TYPE;
284
+ reactJsxRuntime_development.jsx = function(type, config, maybeKey) {
285
+ var trackActualOwner = 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
286
+ return jsxDEVImpl(
287
+ type,
288
+ config,
289
+ maybeKey,
290
+ false,
291
+ trackActualOwner ? Error("react-stack-top-frame") : unknownOwnerDebugStack,
292
+ trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask
293
+ );
294
+ };
295
+ reactJsxRuntime_development.jsxs = function(type, config, maybeKey) {
296
+ var trackActualOwner = 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
297
+ return jsxDEVImpl(
298
+ type,
299
+ config,
300
+ maybeKey,
301
+ true,
302
+ trackActualOwner ? Error("react-stack-top-frame") : unknownOwnerDebugStack,
303
+ trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask
304
+ );
305
+ };
306
+ }();
307
+ return reactJsxRuntime_development;
308
+ }
309
+ if (process.env.NODE_ENV === "production") {
310
+ jsxRuntime.exports = requireReactJsxRuntime_production();
311
+ } else {
312
+ jsxRuntime.exports = requireReactJsxRuntime_development();
313
+ }
314
+ var jsxRuntimeExports = jsxRuntime.exports;
315
+ const EventBusContext = createContext(null);
316
+ const useEventBus = () => {
317
+ return useContext(EventBusContext);
318
+ };
319
+ const createPublishEvent = (bus) => {
320
+ function publishEvent(...args) {
321
+ if (args.length === 1) {
322
+ bus.publishEvent(args[0].address, args[0].eventType, args[0].event);
323
+ } else {
324
+ bus.publishEvent(args[0], args[1], args[2]);
325
+ }
326
+ }
327
+ return publishEvent;
328
+ };
329
+ const PublishEventContext = createContext(null);
330
+ const usePublishEvent = () => useContext(PublishEventContext);
331
+ const EspEventBusContextProvider = ({ children, bus }) => {
332
+ let busFromContext = useEventBus();
333
+ bus = bus || busFromContext;
334
+ const publishEvent = useCallback(createPublishEvent(bus), [bus]);
335
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(EventBusContext.Provider, { value: bus, children: /* @__PURE__ */ jsxRuntimeExports.jsx(PublishEventContext.Provider, { value: publishEvent, children }) });
336
+ };
337
+ const GetStoreIdContext = createContext(null);
338
+ const useGetStoreId = () => useContext(GetStoreIdContext);
339
+ const GetStoreModelContext = createContext(null);
340
+ const useGetStoreModel = () => useContext(GetStoreModelContext);
341
+ const createPublishStoreEvent = (bus, storeId) => {
342
+ function publishStoreEvent(...args) {
343
+ if (args.length === 1) {
344
+ bus.publishEvent(storeId, args[0].eventType, args[0].event);
345
+ } else {
346
+ bus.publishEvent(storeId, args[0], args[1]);
347
+ }
348
+ }
349
+ return publishStoreEvent;
350
+ };
351
+ const PublishStoreEventContext = createContext(null);
352
+ const usePublishStoreEvent = () => useContext(PublishStoreEventContext);
353
+ const createPublishStoreEventWithEntityKey = (bus, storeId) => {
354
+ function publishStoreEventWithEntityKey(...args) {
355
+ if (args.length === 1) {
356
+ bus.publishEvent(new DefaultStoreAddress(storeId, args[0].entityKey), args[0].eventType, args[0].event);
357
+ } else {
358
+ bus.publishEvent(new DefaultStoreAddress(storeId, args[0]), args[1], args[2]);
359
+ }
360
+ }
361
+ return publishStoreEventWithEntityKey;
362
+ };
363
+ const PublishStoreEventWithEntityKeyContext = createContext(null);
364
+ const usePublishStoreEventWithEntityKey = () => useContext(PublishStoreEventWithEntityKeyContext);
365
+ const EspStoreContextProvider = ({ storeId, children, model }) => {
366
+ const bus = useEventBus();
367
+ let storeIdFromContext = useGetStoreId();
368
+ storeId = storeId || storeIdFromContext;
369
+ const publishStoreEvent = useCallback(createPublishStoreEvent(bus, storeId), [bus, storeId]);
370
+ const publishStoreEventWithEntityKey = useCallback(createPublishStoreEventWithEntityKey(bus, storeId), [bus, storeId]);
371
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(GetStoreIdContext.Provider, { value: storeId, children: /* @__PURE__ */ jsxRuntimeExports.jsx(PublishStoreEventContext.Provider, { value: publishStoreEvent, children: /* @__PURE__ */ jsxRuntimeExports.jsx(PublishStoreEventWithEntityKeyContext.Provider, { value: publishStoreEventWithEntityKey, children: /* @__PURE__ */ jsxRuntimeExports.jsx(GetStoreModelContext.Provider, { value: model, children }) }) }) });
372
+ };
373
+ var withSelector = { exports: {} };
374
+ var useSyncExternalStoreWithSelector_production = {};
375
+ /**
376
+ * @license React
377
+ * use-sync-external-store-with-selector.production.js
378
+ *
379
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
380
+ *
381
+ * This source code is licensed under the MIT license found in the
382
+ * LICENSE file in the root directory of this source tree.
383
+ */
384
+ var hasRequiredUseSyncExternalStoreWithSelector_production;
385
+ function requireUseSyncExternalStoreWithSelector_production() {
386
+ if (hasRequiredUseSyncExternalStoreWithSelector_production) return useSyncExternalStoreWithSelector_production;
387
+ hasRequiredUseSyncExternalStoreWithSelector_production = 1;
388
+ var React = require$$0__default;
389
+ function is(x, y) {
390
+ return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
391
+ }
392
+ var objectIs = "function" === typeof Object.is ? Object.is : is, useSyncExternalStore = React.useSyncExternalStore, useRef = React.useRef, useEffect = React.useEffect, useMemo2 = React.useMemo, useDebugValue = React.useDebugValue;
393
+ useSyncExternalStoreWithSelector_production.useSyncExternalStoreWithSelector = function(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
394
+ var instRef = useRef(null);
395
+ if (null === instRef.current) {
396
+ var inst = { hasValue: false, value: null };
397
+ instRef.current = inst;
398
+ } else inst = instRef.current;
399
+ instRef = useMemo2(
400
+ function() {
401
+ function memoizedSelector(nextSnapshot) {
402
+ if (!hasMemo) {
403
+ hasMemo = true;
404
+ memoizedSnapshot = nextSnapshot;
405
+ nextSnapshot = selector(nextSnapshot);
406
+ if (void 0 !== isEqual && inst.hasValue) {
407
+ var currentSelection = inst.value;
408
+ if (isEqual(currentSelection, nextSnapshot))
409
+ return memoizedSelection = currentSelection;
410
+ }
411
+ return memoizedSelection = nextSnapshot;
412
+ }
413
+ currentSelection = memoizedSelection;
414
+ if (objectIs(memoizedSnapshot, nextSnapshot)) return currentSelection;
415
+ var nextSelection = selector(nextSnapshot);
416
+ if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
417
+ return memoizedSnapshot = nextSnapshot, currentSelection;
418
+ memoizedSnapshot = nextSnapshot;
419
+ return memoizedSelection = nextSelection;
420
+ }
421
+ var hasMemo = false, memoizedSnapshot, memoizedSelection, maybeGetServerSnapshot = void 0 === getServerSnapshot ? null : getServerSnapshot;
422
+ return [
423
+ function() {
424
+ return memoizedSelector(getSnapshot());
425
+ },
426
+ null === maybeGetServerSnapshot ? void 0 : function() {
427
+ return memoizedSelector(maybeGetServerSnapshot());
428
+ }
429
+ ];
430
+ },
431
+ [getSnapshot, getServerSnapshot, selector, isEqual]
432
+ );
433
+ var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);
434
+ useEffect(
435
+ function() {
436
+ inst.hasValue = true;
437
+ inst.value = value;
438
+ },
439
+ [value]
440
+ );
441
+ useDebugValue(value);
442
+ return value;
443
+ };
444
+ return useSyncExternalStoreWithSelector_production;
445
+ }
446
+ var useSyncExternalStoreWithSelector_development = {};
447
+ /**
448
+ * @license React
449
+ * use-sync-external-store-with-selector.development.js
450
+ *
451
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
452
+ *
453
+ * This source code is licensed under the MIT license found in the
454
+ * LICENSE file in the root directory of this source tree.
455
+ */
456
+ var hasRequiredUseSyncExternalStoreWithSelector_development;
457
+ function requireUseSyncExternalStoreWithSelector_development() {
458
+ if (hasRequiredUseSyncExternalStoreWithSelector_development) return useSyncExternalStoreWithSelector_development;
459
+ hasRequiredUseSyncExternalStoreWithSelector_development = 1;
460
+ "production" !== process.env.NODE_ENV && function() {
461
+ function is(x, y) {
462
+ return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
463
+ }
464
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
465
+ var React = require$$0__default, objectIs = "function" === typeof Object.is ? Object.is : is, useSyncExternalStore = React.useSyncExternalStore, useRef = React.useRef, useEffect = React.useEffect, useMemo2 = React.useMemo, useDebugValue = React.useDebugValue;
466
+ useSyncExternalStoreWithSelector_development.useSyncExternalStoreWithSelector = function(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
467
+ var instRef = useRef(null);
468
+ if (null === instRef.current) {
469
+ var inst = { hasValue: false, value: null };
470
+ instRef.current = inst;
471
+ } else inst = instRef.current;
472
+ instRef = useMemo2(
473
+ function() {
474
+ function memoizedSelector(nextSnapshot) {
475
+ if (!hasMemo) {
476
+ hasMemo = true;
477
+ memoizedSnapshot = nextSnapshot;
478
+ nextSnapshot = selector(nextSnapshot);
479
+ if (void 0 !== isEqual && inst.hasValue) {
480
+ var currentSelection = inst.value;
481
+ if (isEqual(currentSelection, nextSnapshot))
482
+ return memoizedSelection = currentSelection;
483
+ }
484
+ return memoizedSelection = nextSnapshot;
485
+ }
486
+ currentSelection = memoizedSelection;
487
+ if (objectIs(memoizedSnapshot, nextSnapshot))
488
+ return currentSelection;
489
+ var nextSelection = selector(nextSnapshot);
490
+ if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
491
+ return memoizedSnapshot = nextSnapshot, currentSelection;
492
+ memoizedSnapshot = nextSnapshot;
493
+ return memoizedSelection = nextSelection;
494
+ }
495
+ var hasMemo = false, memoizedSnapshot, memoizedSelection, maybeGetServerSnapshot = void 0 === getServerSnapshot ? null : getServerSnapshot;
496
+ return [
497
+ function() {
498
+ return memoizedSelector(getSnapshot());
499
+ },
500
+ null === maybeGetServerSnapshot ? void 0 : function() {
501
+ return memoizedSelector(maybeGetServerSnapshot());
502
+ }
503
+ ];
504
+ },
505
+ [getSnapshot, getServerSnapshot, selector, isEqual]
506
+ );
507
+ var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);
508
+ useEffect(
509
+ function() {
510
+ inst.hasValue = true;
511
+ inst.value = value;
512
+ },
513
+ [value]
514
+ );
515
+ useDebugValue(value);
516
+ return value;
517
+ };
518
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
519
+ }();
520
+ return useSyncExternalStoreWithSelector_development;
521
+ }
522
+ if (process.env.NODE_ENV === "production") {
523
+ withSelector.exports = requireUseSyncExternalStoreWithSelector_production();
524
+ } else {
525
+ withSelector.exports = requireUseSyncExternalStoreWithSelector_development();
526
+ }
527
+ var withSelectorExports = withSelector.exports;
528
+ Logger.create("useSyncStoreModelWithSelector");
529
+ const syncStoreModelWithSelectorOptions = () => {
530
+ let storeId = void 0;
531
+ let equalityFn = (a, b) => a === b;
532
+ return {
533
+ get storeId() {
534
+ return storeId;
535
+ },
536
+ setStoreId(value) {
537
+ storeId = value;
538
+ return this;
539
+ },
540
+ get equalityFn() {
541
+ return equalityFn;
542
+ },
543
+ setEqualityFn(value) {
544
+ equalityFn = value;
545
+ return this;
546
+ }
547
+ };
548
+ };
549
+ const checkArguments = (selector, options) => {
550
+ if (!utils.isFunction(selector)) {
551
+ throw new Error("You must pass a selector function to useSyncStoreModelWithSelector");
552
+ }
553
+ if (!utils.isObject(options)) {
554
+ throw new Error("You must provide options when using useSyncStoreModelWithSelector");
555
+ }
556
+ if (!utils.isFunction(options.equalityFn)) {
557
+ throw new Error("You must provide an equalityFn when using useSyncStoreModelWithSelector");
558
+ }
559
+ };
560
+ const useSyncStoreModelWithSelector = (selector, options = syncStoreModelWithSelectorOptions()) => {
561
+ checkArguments(selector, options);
562
+ const bus = useEventBus();
563
+ const storeIdFromContext = useGetStoreId();
564
+ const storeId = (options == null ? void 0 : options.storeId) || storeIdFromContext;
565
+ const equalityFn = options == null ? void 0 : options.equalityFn;
566
+ const dependencies = useMemo(
567
+ () => {
568
+ const canSubscribe = bus && utils.isString(storeId);
569
+ if (canSubscribe) {
570
+ return createSubscriptionState(bus, storeId);
571
+ }
572
+ return createNoopSubscriptionState();
573
+ },
574
+ [bus, storeId]
575
+ );
576
+ const wrappedSelector = (snapshot) => snapshot ? selector(snapshot) : null;
577
+ return withSelectorExports.useSyncExternalStoreWithSelector(
578
+ dependencies.subscribe,
579
+ dependencies.getSnapshot,
580
+ void 0,
581
+ wrappedSelector,
582
+ equalityFn
583
+ );
584
+ };
585
+ const createSubscriptionState = (bus, storeId) => {
586
+ let currentModel;
587
+ return {
588
+ subscribe: (stateChanged) => {
589
+ const modelSubscriptionDisposable = bus.getStoreModelObservable(storeId).subscribe(
590
+ (m) => {
591
+ if (m === currentModel) {
592
+ return;
593
+ }
594
+ currentModel = m;
595
+ stateChanged();
596
+ }
597
+ );
598
+ return () => {
599
+ currentModel = null;
600
+ modelSubscriptionDisposable.dispose();
601
+ };
602
+ },
603
+ // React expects getSnapshot to be pure and stable between renders unless the store has changed.
604
+ // We seed currentModel from bus.getStoreModel() on first call (before subscribe has been called),
605
+ // then keep it up-to-date via the subscription callback above.
606
+ // getStoreModel() throws for a store that's been observed but not registered yet, so check first; until then the snapshot is null.
607
+ getSnapshot: () => {
608
+ if (currentModel == null && bus.isStoreRegistered(storeId)) {
609
+ currentModel = bus.getStoreModel(storeId);
610
+ }
611
+ return currentModel;
612
+ }
613
+ };
614
+ };
615
+ const createNoopSubscriptionState = () => ({
616
+ subscribe: () => {
617
+ return () => {
618
+ };
619
+ },
620
+ getSnapshot: () => null
621
+ });
622
+ const getChildProps = (bus, storeId, restProps, model, mapStoreModelToProps, publishEventProps) => {
623
+ let childProps = {
624
+ storeId,
625
+ bus,
626
+ ...restProps,
627
+ ...publishEventProps,
628
+ model
629
+ };
630
+ if (mapStoreModelToProps) {
631
+ childProps = {
632
+ ...childProps,
633
+ ...mapStoreModelToProps(model, publishEventProps)
634
+ };
635
+ }
636
+ return childProps;
637
+ };
638
+ const ConnectableComponent = ({
639
+ storeId,
640
+ mapStoreModelToProps,
641
+ createPublishEventProps,
642
+ view,
643
+ ...rest
644
+ }) => {
645
+ const bus = useEventBus();
646
+ let storeIdFromContext = useGetStoreId();
647
+ storeId = storeId || storeIdFromContext;
648
+ const publishEventProps = useMemo(
649
+ () => {
650
+ if (createPublishEventProps) {
651
+ const publishModelEvent = (eventType, event) => {
652
+ bus.publishEvent(storeId, eventType, event);
653
+ };
654
+ return createPublishEventProps(publishModelEvent);
655
+ }
656
+ return {};
657
+ },
658
+ [bus, storeId]
659
+ );
660
+ const model = useSyncStoreModelWithSelector(
661
+ (m) => m,
662
+ syncStoreModelWithSelectorOptions().setStoreId(storeId)
663
+ );
664
+ if (model == null) {
665
+ return null;
666
+ }
667
+ let childProps = getChildProps(bus, storeId, rest, model, mapStoreModelToProps, publishEventProps);
668
+ let viewElement = view ? require$$0.createElement(view, childProps) : null;
669
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(EspStoreContextProvider, { storeId, model, bus, ...childProps, children: viewElement });
670
+ };
671
+ const EspModulesContext = require$$0.createContext([]);
672
+ const RegionView = ({ regionName }) => {
673
+ const modules = useContext(EspModulesContext);
674
+ const bindings = useMemo(
675
+ () => modules.flatMap((m) => m.viewBindings).filter((b) => b.region === regionName),
676
+ [modules, regionName]
677
+ );
678
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: bindings.map((binding, index) => /* @__PURE__ */ jsxRuntimeExports.jsx(
679
+ ConnectableComponent,
680
+ {
681
+ storeId: binding.storeId,
682
+ view: binding.viewComponent
683
+ },
684
+ `${binding.storeId}:${index}`
685
+ )) });
686
+ };
687
+ const EspApp = ({ app, children }) => /* @__PURE__ */ jsxRuntimeExports.jsx(EspEventBusContextProvider, { bus: app.eventBus, children: /* @__PURE__ */ jsxRuntimeExports.jsx(EspModulesContext.Provider, { value: app.modules, children }) });
688
+ export {
689
+ ConnectableComponent,
690
+ EspApp,
691
+ EspEventBusContextProvider,
692
+ EspModulesContext,
693
+ EspStoreContextProvider,
694
+ EventBusContext,
695
+ GetStoreIdContext,
696
+ GetStoreModelContext,
697
+ PublishEventContext,
698
+ PublishStoreEventContext,
699
+ PublishStoreEventWithEntityKeyContext,
700
+ RegionView,
701
+ syncStoreModelWithSelectorOptions,
702
+ useEventBus,
703
+ useGetStoreId,
704
+ useGetStoreModel,
705
+ usePublishEvent,
706
+ usePublishStoreEvent,
707
+ usePublishStoreEventWithEntityKey,
708
+ useSyncStoreModelWithSelector
709
+ };
710
+ //# sourceMappingURL=esp-react.esm.mjs.map