esp-js-react 9.0.0-beta.3 → 9.0.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.
- package/.dist/esp-react.esm.mjs +15 -326
- package/.dist/esp-react.esm.mjs.map +1 -1
- package/.dist/esp-react.js +34 -345
- package/.dist/esp-react.js.map +1 -1
- package/.dist/esp-react.min.js +1 -1
- package/.dist/esp-react.min.js.map +1 -1
- package/.dist/typings/connectableComponent.d.ts +1 -1
- package/.dist/typings/espApp.d.ts +1 -1
- package/.dist/typings/espEventBusContextProvider.d.ts +4 -3
- package/.dist/typings/espStoreContextProvider.d.ts +6 -5
- package/.dist/typings/regionView.d.ts +2 -1
- package/package.json +4 -6
package/.dist/esp-react.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("esp-js")):"function"==typeof define&&define.amd?define(["exports","react","esp-js"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).espReact={},e.React,e.espJs)}(this,(function(e,t,n){"use strict";function r(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const n in e)if("default"!==n){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}return t.default=e,Object.freeze(t)}const o=r(t)
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("esp-js")):"function"==typeof define&&define.amd?define(["exports","react","esp-js"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).espReact={},e.React,e.espJs)}(this,(function(e,t,n){"use strict";function r(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const n in e)if("default"!==n){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}return t.default=e,Object.freeze(t)}const o=r(t),u=t.createContext(null),l=()=>t.useContext(u),s=t.createContext(null),i=({children:e,bus:n})=>{let r=l();n=n||r;const i=t.useCallback((e=>function(...t){1===t.length?e.publishEvent(t[0].address,t[0].eventType,t[0].event):e.publishEvent(t[0],t[1],t[2])})(n),[n]);return o.createElement(u.Provider,{value:n},o.createElement(s.Provider,{value:i},e))},c=t.createContext(null),a=()=>t.useContext(c),d=t.createContext(null),v=t.createContext(null),f=t.createContext(null),p=({storeId:e,children:r,model:u})=>{const s=l();let i=a();e=e||i;const p=t.useCallback(((e,t)=>function(...n){1===n.length?e.publishEvent(t,n[0].eventType,n[0].event):e.publishEvent(t,n[0],n[1])})(s,e),[s,e]),S=t.useCallback(((e,t)=>function(...r){1===r.length?e.publishEvent(new n.DefaultStoreAddress(t,r[0].entityKey),r[0].eventType,r[0].event):e.publishEvent(new n.DefaultStoreAddress(t,r[0]),r[1],r[2])})(s,e),[s,e]);return o.createElement(c.Provider,{value:e},o.createElement(v.Provider,{value:p},o.createElement(f.Provider,{value:S},o.createElement(d.Provider,{value:u},r))))};var S,b={exports:{}},h={};b.exports=function(){if(S)return h;S=1;var e=t,n="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},r=e.useSyncExternalStore,o=e.useRef,u=e.useEffect,l=e.useMemo,s=e.useDebugValue;return h.useSyncExternalStoreWithSelector=function(e,t,i,c,a){var d=o(null);if(null===d.current){var v={hasValue:!1,value:null};d.current=v}else v=d.current;d=l((function(){function e(e){if(!u){if(u=!0,r=e,e=c(e),void 0!==a&&v.hasValue){var t=v.value;if(a(t,e))return o=t}return o=e}if(t=o,n(r,e))return t;var l=c(e);return void 0!==a&&a(t,l)?(r=e,t):(r=e,o=l)}var r,o,u=!1,l=void 0===i?null:i;return[function(){return e(t())},null===l?void 0:function(){return e(l())}]}),[t,i,c,a]);var f=r(e,d[0],d[1]);return u((function(){v.hasValue=!0,v.value=f}),[f]),s(f),f},h}();var E=b.exports;n.Logger.create("useSyncStoreModelWithSelector");const m=()=>{let e,t=(e,t)=>e===t;return{get storeId(){return e},setStoreId(t){return e=t,this},get equalityFn(){return t},setEqualityFn(e){return t=e,this}}},y=(e,r=m())=>{((e,t)=>{if(!n.utils.isFunction(e))throw new Error("You must pass a selector function to useSyncStoreModelWithSelector");if(!n.utils.isObject(t))throw new Error("You must provide options when using useSyncStoreModelWithSelector");if(!n.utils.isFunction(t.equalityFn))throw new Error("You must provide an equalityFn when using useSyncStoreModelWithSelector")})(e,r);const o=l(),u=a(),s=(null==r?void 0:r.storeId)||u,i=null==r?void 0:r.equalityFn,c=t.useMemo((()=>o&&n.utils.isString(s)?x(o,s):g()),[o,s]);return E.useSyncExternalStoreWithSelector(c.subscribe,c.getSnapshot,void 0,(t=>t?e(t):null),i)},x=(e,t)=>{let n;return{subscribe:r=>{const o=e.getStoreModelObservable(t).subscribe((e=>{e!==n&&(n=e,r())}));return()=>{n=null,o.dispose()}},getSnapshot:()=>(null==n&&e.isStoreRegistered(t)&&(n=e.getStoreModel(t)),n)}},g=()=>({subscribe:()=>()=>{},getSnapshot:()=>null}),C=({storeId:e,mapStoreModelToProps:n,createPublishEventProps:r,view:u,...s})=>{const i=l();let c=a();e=e||c;const d=t.useMemo((()=>{if(r){return r(((t,n)=>{i.publishEvent(e,t,n)}))}return{}}),[i,e]),v=y((e=>e),m().setStoreId(e));if(null==v)return null;let f=((e,t,n,r,o,u)=>{let l={storeId:t,bus:e,...n,...u,model:r};return o&&(l={...l,...o(r,u)}),l})(i,e,s,v,n,d),S=u?o.createElement(u,f):null;return o.createElement(p,{storeId:e,model:v,bus:i,...f},S)},P=o.createContext([]);e.ConnectableComponent=C,e.EspApp=({app:e,children:t})=>o.createElement(i,{bus:e.eventBus},o.createElement(P.Provider,{value:e.modules},t)),e.EspEventBusContextProvider=i,e.EspModulesContext=P,e.EspStoreContextProvider=p,e.EventBusContext=u,e.GetStoreIdContext=c,e.GetStoreModelContext=d,e.PublishEventContext=s,e.PublishStoreEventContext=v,e.PublishStoreEventWithEntityKeyContext=f,e.RegionView=({regionName:e})=>{const n=t.useContext(P),r=t.useMemo((()=>n.flatMap((e=>e.viewBindings)).filter((t=>t.region===e))),[n,e]);return o.createElement(o.Fragment,null,r.map(((e,t)=>o.createElement(C,{key:`${e.storeId}:${t}`,storeId:e.storeId,view:e.viewComponent}))))},e.syncStoreModelWithSelectorOptions=m,e.useEventBus=l,e.useGetStoreId=a,e.useGetStoreModel=()=>t.useContext(d),e.usePublishEvent=()=>t.useContext(s),e.usePublishStoreEvent=()=>t.useContext(v),e.usePublishStoreEventWithEntityKey=()=>t.useContext(f),e.useSyncStoreModelWithSelector=y,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
|
|
2
2
|
//# sourceMappingURL=esp-react.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"esp-react.min.js","sources":["../../../node_modules/react/jsx-runtime.js","../../../node_modules/react/cjs/react-jsx-runtime.production.js","../src/espEventBusContextProvider.tsx","../src/espStoreContextProvider.tsx","../../../node_modules/use-sync-external-store/with-selector.js","../../../node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.production.js","../src/useSyncStoreModelWithSelector.ts","../src/connectableComponent.tsx","../src/espModulesContext.ts","../src/espApp.tsx","../src/regionView.tsx"],"sourcesContent":["'use strict';\n\nif (process.env.NODE_ENV === 'production') {\n module.exports = require('./cjs/react-jsx-runtime.production.js');\n} else {\n module.exports = require('./cjs/react-jsx-runtime.development.js');\n}\n","/**\n * @license React\n * react-jsx-runtime.production.js\n *\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n\"use strict\";\nvar REACT_ELEMENT_TYPE = Symbol.for(\"react.transitional.element\"),\n REACT_FRAGMENT_TYPE = Symbol.for(\"react.fragment\");\nfunction jsxProd(type, config, maybeKey) {\n var key = null;\n void 0 !== maybeKey && (key = \"\" + maybeKey);\n void 0 !== config.key && (key = \"\" + config.key);\n if (\"key\" in config) {\n maybeKey = {};\n for (var propName in config)\n \"key\" !== propName && (maybeKey[propName] = config[propName]);\n } else maybeKey = config;\n config = maybeKey.ref;\n return {\n $$typeof: REACT_ELEMENT_TYPE,\n type: type,\n key: key,\n ref: void 0 !== config ? config : null,\n props: maybeKey\n };\n}\nexports.Fragment = REACT_FRAGMENT_TYPE;\nexports.jsx = jsxProd;\nexports.jsxs = jsxProd;\n","// notice_start\n/*\n * Copyright 2015 Dev Shop Limited\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n// notice_end\n\nimport {StoreAddress, EventBus} from 'esp-js';\nimport {PropsWithChildren, createContext, useContext, useCallback} from 'react';\n\nexport const EventBusContext = createContext<EventBus>(null);\n\n/**\n * Get the esp EventBus from context.\n *\n * To use this, please ensure your V-DOM has the EspEventBusContextProvider at a higher node:\n *\n * <EspEventBusContextProvider bus={bus}>\n * <YourComponents />\n * </EspEventBusContextProvider>\n */\nexport const useEventBus = () => {\n return useContext(EventBusContext);\n};\n\nexport type PublishEventDelegate = {(storeIdOrStoreAddress: string | StoreAddress, eventType: string, event: any): void; (eventData: { address: string | StoreAddress, eventType: string, event: any }): void; };\nconst createPublishEvent = (bus: EventBus) => {\n function publishEvent(storeIdOrStoreAddress: string | StoreAddress, eventType: string, event: any): void;\n function publishEvent(eventData: { address: string | StoreAddress, eventType: string, event: any }): void;\n function publishEvent(...args: any[]): void {\n if (args.length === 1) {\n bus.publishEvent(args[0].address, args[0].eventType, args[0].event);\n } else {\n bus.publishEvent(args[0], args[1], args[2]);\n }\n }\n return publishEvent;\n};\nexport const PublishEventContext = createContext<PublishEventDelegate>(null);\n\n/**\n * Returns a function which can be used to publish an event.\n *\n * To use this, please ensure your V-DOM has the EspEventBusContextProvider at a higher node:\n *\n * <EspEventBusContextProvider bus={bus}>\n * <YourComponents />\n * </EspEventBusContextProvider>\n */\nexport const usePublishEvent = () => useContext(PublishEventContext);\n\nexport type EspEventBusContextProviderProps = PropsWithChildren<{ bus: EventBus; }>;\n\n/**\n * Used to set the bus on the EventBusContext making it available to components down the tree via the useEventBus() hook.\n *\n * Also sets up the usePublishEvent() hook so nested components can publish to the bus.\n */\nexport const EspEventBusContextProvider = ({children, bus}: EspEventBusContextProviderProps) => {\n // EventBus may have been set by a higher level version of this component, so we try and get it from context if it's not set by props.\n let busFromContext = useEventBus();\n bus = bus || busFromContext;\n const publishEvent: PublishEventDelegate = useCallback(createPublishEvent(bus), [bus]);\n return (\n <EventBusContext.Provider value={bus}>\n <PublishEventContext.Provider value={publishEvent}>\n {children}\n </PublishEventContext.Provider>\n </EventBusContext.Provider>\n );\n};","import {DefaultStoreAddress, EventBus} from 'esp-js';\nimport {useContext, useCallback, createContext, PropsWithChildren} from 'react';\nimport {useEventBus} from './espEventBusContextProvider';\n\nexport const GetStoreIdContext = createContext<string>(null);\n/**\n * Returns a function to get the ID of the store connected at a higher point in the V-DOM.\n *\n * To use this, please ensure your V-DOM has the EspStoreContextProvider at a higher node.\n */\nexport const useGetStoreId = () => useContext(GetStoreIdContext);\n\nexport const GetStoreModelContext = createContext<object>(null);\n/**\n * Returns the current model (frozen snapshot) of the store connected at a higher point in the V-DOM.\n *\n * To use this, please ensure your V-DOM has the EspStoreContextProvider at a higher node.\n */\nexport const useGetStoreModel = <TModel,>() => useContext(GetStoreModelContext) as TModel;\n\nexport type PublishStoreEventDelegate = { (eventType: string, event: any): void; (eventData: {eventType: string, event: any}): void; };\nconst createPublishStoreEvent = (bus: EventBus, storeId: string) => {\n function publishStoreEvent(eventType: string, event: any): void;\n function publishStoreEvent(eventData: {eventType: string, event: any}): void;\n function publishStoreEvent(...args: any[]) {\n if (args.length === 1) {\n bus.publishEvent(storeId, args[0].eventType, args[0].event);\n } else {\n bus.publishEvent(storeId, args[0], args[1]);\n }\n }\n return publishStoreEvent;\n};\nexport const PublishStoreEventContext = createContext<PublishStoreEventDelegate>(null);\n\n/**\n * Returns a function which can be used to publish an event to the store connected at a higher point in the V-DOM.\n *\n * Effectively, this is a version of usePublishEvent() which closes over the relevant storeId.\n *\n * To use this, please ensure your V-DOM has the EspStoreContextProvider at a higher node.\n */\nexport const usePublishStoreEvent = () => useContext(PublishStoreEventContext);\n\nexport type PublishStoreEventWithEntityKeyDelegate = {(entityKey: string, eventType: string, event: any): void; (eventData: {entityKey: string, eventType: string, event: any}): void; };\nconst createPublishStoreEventWithEntityKey = (bus: EventBus, storeId: string) => {\n function publishStoreEventWithEntityKey(entityKey: string, eventType: string, event: any): void;\n function publishStoreEventWithEntityKey(eventData: {entityKey: string, eventType: string, event: any}): void;\n function publishStoreEventWithEntityKey(...args: any[]) {\n if (args.length === 1) {\n bus.publishEvent(new DefaultStoreAddress(storeId, args[0].entityKey), args[0].eventType, args[0].event);\n } else {\n bus.publishEvent(new DefaultStoreAddress(storeId, args[0]), args[1], args[2]);\n }\n }\n return publishStoreEventWithEntityKey;\n};\nexport const PublishStoreEventWithEntityKeyContext = createContext<PublishStoreEventWithEntityKeyDelegate>(null);\n/**\n * Returns a function which can be used to publish an event to the store connected at a higher point in the V-DOM, allows an entityKey to be specified.\n *\n * Effectively, this is a version of usePublishEvent() which closes over the storeId.\n *\n * To use this, please ensure your V-DOM has the EspStoreContextProvider at a higher node.\n */\nexport const usePublishStoreEventWithEntityKey = () => useContext(PublishStoreEventWithEntityKeyContext);\n\nexport interface EspStoreContextProviderProps {\n storeId: string;\n model?: any;\n}\n\n/**\n * Sets up various ESP context so ESP hooks are available below this point in the V-DOM\n *\n * To use this, please ensure your V-DOM has the EspEventBusContextProvider at a higher node.\n * @param storeId\n * @param children\n * @param model\n * @constructor\n */\nexport const EspStoreContextProvider = ({storeId, children, model}: PropsWithChildren<EspStoreContextProviderProps>) => {\n const bus = useEventBus();\n // storeId may have been set by a higher level version of this component, so we try and get it from context if it's not set by props.\n let storeIdFromContext = useGetStoreId();\n storeId = storeId || storeIdFromContext;\n const publishStoreEvent: PublishStoreEventDelegate = useCallback(createPublishStoreEvent(bus, storeId), [bus, storeId]);\n const publishStoreEventWithEntityKey: PublishStoreEventWithEntityKeyDelegate = useCallback(createPublishStoreEventWithEntityKey(bus, storeId), [bus, storeId]);\n return (\n <GetStoreIdContext.Provider value={storeId}>\n <PublishStoreEventContext.Provider value={publishStoreEvent}>\n <PublishStoreEventWithEntityKeyContext.Provider value={publishStoreEventWithEntityKey}>\n <GetStoreModelContext.Provider value={model}>\n {children}\n </GetStoreModelContext.Provider>\n </PublishStoreEventWithEntityKeyContext.Provider>\n </PublishStoreEventContext.Provider>\n </GetStoreIdContext.Provider>\n );\n};\n","'use strict';\n\nif (process.env.NODE_ENV === 'production') {\n module.exports = require('./cjs/use-sync-external-store-with-selector.production.js');\n} else {\n module.exports = require('./cjs/use-sync-external-store-with-selector.development.js');\n}\n","/**\n * @license React\n * use-sync-external-store-with-selector.production.js\n *\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n\"use strict\";\nvar React = require(\"react\");\nfunction is(x, y) {\n return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y);\n}\nvar objectIs = \"function\" === typeof Object.is ? Object.is : is,\n useSyncExternalStore = React.useSyncExternalStore,\n useRef = React.useRef,\n useEffect = React.useEffect,\n useMemo = React.useMemo,\n useDebugValue = React.useDebugValue;\nexports.useSyncExternalStoreWithSelector = function (\n subscribe,\n getSnapshot,\n getServerSnapshot,\n selector,\n isEqual\n) {\n var instRef = useRef(null);\n if (null === instRef.current) {\n var inst = { hasValue: !1, value: null };\n instRef.current = inst;\n } else inst = instRef.current;\n instRef = useMemo(\n function () {\n function memoizedSelector(nextSnapshot) {\n if (!hasMemo) {\n hasMemo = !0;\n memoizedSnapshot = nextSnapshot;\n nextSnapshot = selector(nextSnapshot);\n if (void 0 !== isEqual && inst.hasValue) {\n var currentSelection = inst.value;\n if (isEqual(currentSelection, nextSnapshot))\n return (memoizedSelection = currentSelection);\n }\n return (memoizedSelection = nextSnapshot);\n }\n currentSelection = memoizedSelection;\n if (objectIs(memoizedSnapshot, nextSnapshot)) return currentSelection;\n var nextSelection = selector(nextSnapshot);\n if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))\n return (memoizedSnapshot = nextSnapshot), currentSelection;\n memoizedSnapshot = nextSnapshot;\n return (memoizedSelection = nextSelection);\n }\n var hasMemo = !1,\n memoizedSnapshot,\n memoizedSelection,\n maybeGetServerSnapshot =\n void 0 === getServerSnapshot ? null : getServerSnapshot;\n return [\n function () {\n return memoizedSelector(getSnapshot());\n },\n null === maybeGetServerSnapshot\n ? void 0\n : function () {\n return memoizedSelector(maybeGetServerSnapshot());\n }\n ];\n },\n [getSnapshot, getServerSnapshot, selector, isEqual]\n );\n var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);\n useEffect(\n function () {\n inst.hasValue = !0;\n inst.value = value;\n },\n [value]\n );\n useDebugValue(value);\n return value;\n};\n","import {useMemo} from 'react';\nimport {useSyncExternalStoreWithSelector} from 'use-sync-external-store/with-selector';\nimport {Logger, EventBus, utils} from 'esp-js';\nimport {useEventBus} from './espEventBusContextProvider';\nimport {useGetStoreId} from './espStoreContextProvider';\n\nexport type SyncStoreModelWithSelectorEqualityFn<T> = (last: T, next: T) => boolean;\n\nexport const logger = Logger.create('useSyncStoreModelWithSelector');\n\n/**\n * Options affecting the subscription of the model to the EventBus.\n *\n * Use syncStoreModelWithSelectorOptions() to create an instance of this type with sensible defaults.\n *\n * @param storeId - the storeId of the store to be observed via the esp EventBus.\n * @param equalityFn - Equality function which will be applied against TSelected, defaults to instance equality (a === b).\n */\nexport type SyncStoreModelWithSelectorOptions<TSelected> = {\n storeId?: string,\n equalityFn: SyncStoreModelWithSelectorEqualityFn<TSelected>\n};\n\n/**\n * Convenience API to build SyncStoreModelWithSelectorOptions<TSelected>, has sensible defaulting.\n */\nexport interface SyncStoreModelWithSelectorOptionsBuilder<TSelected> extends SyncStoreModelWithSelectorOptions<TSelected> {\n /**\n * Sets the store ID\n * @param storeId - default if unset: undefined\n */\n setStoreId(storeId: string): this;\n\n /**\n * Equality function used when comparing the last TSelected with the next.\n * @param fn - default if unset: obj instance equality (e.g. a===b)\n */\n setEqualityFn(fn: (a: TSelected, b: TSelected) => boolean): this;\n}\n\n/**\n * Convenience API to create SyncStoreModelWithSelectorOptions\n */\nexport const syncStoreModelWithSelectorOptions = <TSelected>() => {\n let storeId = undefined;\n let equalityFn: SyncStoreModelWithSelectorEqualityFn<TSelected> = (a: TSelected, b: TSelected) => a === b;\n return {\n get storeId() {\n return storeId;\n },\n setStoreId(value: string) {\n storeId = value;\n return this;\n },\n get equalityFn() {\n return equalityFn;\n },\n setEqualityFn(value: SyncStoreModelWithSelectorEqualityFn<TSelected>) {\n equalityFn = value;\n return this;\n }\n } as SyncStoreModelWithSelectorOptionsBuilder<TSelected>;\n};\n\nconst checkArguments = (selector: (model: any) => any, options: SyncStoreModelWithSelectorOptions<any> ) => {\n if (!utils.isFunction(selector)) {\n throw new Error('You must pass a selector function to useSyncStoreModelWithSelector');\n }\n if (!utils.isObject(options)) {\n throw new Error('You must provide options when using useSyncStoreModelWithSelector');\n }\n if (!utils.isFunction(options.equalityFn)) {\n throw new Error('You must provide an equalityFn when using useSyncStoreModelWithSelector');\n }\n};\n\n/**\n * A hook which returns model state from the esp EventBus.\n *\n * This hooks wih observe updates and re-render the component if the model changes.\n *\n * To use this, please ensure your V-DOM has the EspEventBusContextProvider at a higher node, and optionally EspStoreContextProvider.\n *\n * If the store isn't registered yet, the hook returns null and picks up the model once the store is registered.\n *\n * @param selector - a function to select a selection of the model. It does not need to be memoized: the latest selector is used on each render, and the equalityFn (if any) decides whether a new selection re-renders.\n * @param options\n */\nexport const useSyncStoreModelWithSelector = <TModel, TSelected>(\n selector: (model: TModel) => TSelected,\n options: SyncStoreModelWithSelectorOptions<TSelected> = syncStoreModelWithSelectorOptions<TSelected>()\n): TSelected => {\n checkArguments(selector, options);\n const bus = useEventBus();\n const storeIdFromContext = useGetStoreId();\n const storeId = options?.storeId || storeIdFromContext;\n const equalityFn = options?.equalityFn;\n const dependencies = useMemo(\n () => {\n // Subscribe even if the store isn't registered yet: getStoreModelObservable() supports stores registered later,\n // and emits the model when the store is added.\n const canSubscribe = bus && utils.isString(storeId);\n if (canSubscribe) {\n return createSubscriptionState(bus, storeId);\n }\n return createNoopSubscriptionState();\n },\n [bus, storeId]\n );\n // Wrap the caller's selector on every render so a selector that closes over props/state is never stale.\n // useSyncExternalStoreWithSelector re-runs it when it changes and applies the equalityFn to the result.\n const wrappedSelector = (snapshot: TModel) => snapshot ? selector(snapshot) : null;\n\n // Docs on useSyncExternalStore https://github.com/reactwg/react-18/discussions/86\n // Redux's usage of this: https://github.com/reduxjs/react-redux/blob/master/src/hooks/useSelector.ts\n // Code: https://github.com/facebook/react/blob/main/packages/use-sync-external-store/src/useSyncExternalStoreWithSelector.js\n return useSyncExternalStoreWithSelector(\n dependencies.subscribe,\n dependencies.getSnapshot,\n undefined,\n wrappedSelector,\n equalityFn,\n );\n};\n\nconst createSubscriptionState = <TModel>(\n bus: EventBus,\n storeId: string,\n) => {\n // Because of how useSyncExternalStore works, there is an implicit dependency between the subscribe and getSnapshot functions.\n // When the subscription receives the new state from the EventBus, it can't pass this directly onto getSnapshot,\n // React calls that when it deems it needs to.\n // Given that, we need to cache the state which getSnapshot will return.\n //\n // Note: the bus subscription is created inside the `subscribe` callback (not here at factory time).\n // This is important for correctness with React StrictMode: StrictMode intentionally unmounts and remounts\n // components to surface side-effect bugs. When the cleanup returned by `subscribe` is called, it disposes\n // the bus subscription and clears `currentModel`. Because the `dependencies` object created by useMemo is\n // reused across the remount (deps haven't changed), any bus subscription created eagerly at useMemo time\n // would already be disposed on remount, leaving `currentModel` permanently null.\n //\n // useSyncExternalStore guarantees that `getSnapshot` is called before `subscribe`, so we initialise\n // `currentModel` lazily from `bus.getStoreModel()` inside `getSnapshot` when it is still null.\n let currentModel: TModel;\n return {\n subscribe: (stateChanged: () => void) => {\n // Subscribe to future model updates from the EventBus.\n // This is called by React when the component mounts (and remounts after StrictMode teardown).\n const modelSubscriptionDisposable = bus\n .getStoreModelObservable<TModel>(storeId)\n .subscribe(\n (m: TModel) => {\n // The model is a frozen immutable snapshot produced by immer after each dispatch cycle.\n // immer only creates a new reference when something changed, so the same reference means no change.\n // This also covers the replay of the current model when we subscribe, which getSnapshot() already returned.\n if (m === currentModel) {\n return;\n }\n currentModel = m;\n stateChanged();\n }\n );\n return () => {\n currentModel = null;\n modelSubscriptionDisposable.dispose();\n };\n },\n // React expects getSnapshot to be pure and stable between renders unless the store has changed.\n // We seed currentModel from bus.getStoreModel() on first call (before subscribe has been called),\n // then keep it up-to-date via the subscription callback above.\n // getStoreModel() throws for a store that's been observed but not registered yet, so check first; until then the snapshot is null.\n getSnapshot: () => {\n if (currentModel == null && bus.isStoreRegistered(storeId)) {\n currentModel = bus.getStoreModel<TModel>(storeId);\n }\n return currentModel;\n },\n };\n};\n\nconst createNoopSubscriptionState = () => ({\n subscribe: () => {\n return () => {};\n },\n getSnapshot: (): null => null,\n});\n","import * as React from 'react';\nimport {useEventBus} from './espEventBusContextProvider';\nimport {useMemo} from 'react';\nimport {EventBus} from 'esp-js';\nimport {EspStoreContextProvider, useGetStoreId} from './espStoreContextProvider';\nimport {syncStoreModelWithSelectorOptions, useSyncStoreModelWithSelector} from './useSyncStoreModelWithSelector';\n\nexport type CreatePublishEventProps<TPublishEventProps> = (publishModelEvent: (eventType: string, event: any) => void) => TPublishEventProps;\n\nexport type MapStoreModelToProps<TModel, TModelMappedToProps, TPublishEventProps = {}> = (model: TModel, publishEventProps: TPublishEventProps) => TModelMappedToProps;\n\nexport interface ConnectableComponentProps<TModel = {}, TPublishEventProps = {}, TModelMappedToProps = {}> {\n storeId?: string;\n view?: React.ComponentType<any>;\n createPublishEventProps?: CreatePublishEventProps<TPublishEventProps>;\n mapStoreModelToProps?: MapStoreModelToProps<TModel, TModelMappedToProps, TPublishEventProps>;\n [key: string]: any; // ...rest props, including the result of mapPublish and mapPublish if 'connect' was used\n}\n\nexport interface ConnectableComponentChildProps<TModel = object> {\n storeId: string;\n model: TModel;\n bus: EventBus;\n [key: string]: any; // ...rest props\n}\n\nconst getChildProps = <TModel, TModelMappedToProps, TPublishEventProps>(\n bus: EventBus,\n storeId: string,\n restProps: object,\n model: TModel,\n mapStoreModelToProps: MapStoreModelToProps<TModel, TModelMappedToProps, TPublishEventProps>,\n publishEventProps: TPublishEventProps\n): ConnectableComponentChildProps<TModel> => {\n let childProps = {\n storeId,\n bus: bus,\n ...restProps,\n ...publishEventProps,\n model\n };\n if (mapStoreModelToProps) {\n childProps = {\n ...childProps,\n ...(mapStoreModelToProps(model, publishEventProps) as TModelMappedToProps)\n };\n }\n return childProps;\n};\n\nexport const ConnectableComponent = <TModel = {}, TPublishEventProps = {}, TModelMappedToProps = {}>(\n {\n storeId,\n mapStoreModelToProps,\n createPublishEventProps,\n view,\n ...rest\n }: ConnectableComponentProps<TModel, TPublishEventProps, TModelMappedToProps>\n) => {\n const bus = useEventBus();\n // Note: we always need to render the hooks else react will complain about a different count.\n let storeIdFromContext = useGetStoreId();\n storeId = storeId || storeIdFromContext;\n // createPublishEventProps is captured once per bus/storeId (not re-run when the prop changes),\n // so callers can pass an inline function and still get stable publish props.\n const publishEventProps: TPublishEventProps = useMemo(\n () => {\n if (createPublishEventProps) {\n const publishModelEvent = (eventType: string, event: any) => {\n bus.publishEvent(storeId, eventType, event);\n };\n return createPublishEventProps(publishModelEvent);\n }\n return {} as TPublishEventProps;\n },\n [bus, storeId]\n );\n const model = useSyncStoreModelWithSelector<TModel, TModel>(\n m => m,\n syncStoreModelWithSelectorOptions()\n .setStoreId(storeId)\n );\n if (model == null) {\n return null;\n }\n let childProps = getChildProps(bus, storeId, rest, model, mapStoreModelToProps, publishEventProps);\n let viewElement = view ? React.createElement(view, childProps) : null;\n return (\n <EspStoreContextProvider storeId={storeId} model={model} bus={bus} {...childProps}>\n {viewElement}\n </EspStoreContextProvider>\n );\n};\n","import * as React from 'react';\nimport type { Module } from 'esp-js-ui';\n\nexport const EspModulesContext = React.createContext<ReadonlyArray<Module>>([]);\n","import * as React from 'react';\nimport type { App } from 'esp-js-ui';\nimport { EspEventBusContextProvider } from './espEventBusContextProvider';\nimport { EspModulesContext } from './espModulesContext';\n\nexport interface EspAppProps {\n app: App;\n children: React.ReactNode;\n}\n\n/**\n * Wraps an application root with the ESP context providers.\n *\n * Provides the EventBus (via EspEventBusContextProvider) and the loaded\n * modules list (via EspModulesContext) so that RegionView and any\n * esp-js-react hooks work without additional setup in the root component.\n *\n * Multiple EspApp instances can be mounted independently in the same DOM\n * for multi-app scenarios.\n *\n * Example:\n * await app.start();\n * ReactDOM.createRoot(document.getElementById('root')).render(\n * <EspApp app={app}>\n * <AppShell />\n * </EspApp>\n * );\n */\nexport const EspApp = ({ app, children }: EspAppProps) => (\n <EspEventBusContextProvider bus={app.eventBus}>\n <EspModulesContext.Provider value={app.modules}>\n {children}\n </EspModulesContext.Provider>\n </EspEventBusContextProvider>\n);\n","import * as React from 'react';\nimport {useContext, useMemo} from 'react';\nimport { ConnectableComponent } from './connectableComponent';\nimport { EspModulesContext } from './espModulesContext';\n\nexport interface RegionViewProps {\n regionName: string;\n}\n\n/**\n * Renders all view bindings registered for a given region across all loaded modules.\n *\n * Each module declares views with a region token (ModuleBuilder.withView in esp-js-ui).\n * RegionView reads EspModulesContext (populated by EspApp), finds all bindings\n * matching regionName, and mounts a ConnectableComponent for each.\n *\n * Example:\n * const AppRoot = () => (\n * <div>\n * <RegionView regionName='main' />\n * <RegionView regionName='sidebar' />\n * </div>\n * );\n */\nexport const RegionView = ({ regionName }: RegionViewProps) => {\n const modules = useContext(EspModulesContext);\n const bindings = useMemo(\n () => modules\n .flatMap(m => m.viewBindings)\n .filter(b => b.region === regionName),\n [modules, regionName]\n );\n return (\n <>\n {bindings.map((binding, index) => (\n <ConnectableComponent\n // storeId alone isn't unique: a region can hold several views over the same store.\n // Bindings are fixed once the modules are built, so the index is a stable key.\n key={`${binding.storeId}:${index}`}\n storeId={binding.storeId}\n view={binding.viewComponent}\n />\n ))}\n </>\n );\n};\n"],"names":["jsxRuntimeModule","exports","REACT_ELEMENT_TYPE","Symbol","for","REACT_FRAGMENT_TYPE","jsxProd","type","config","maybeKey","key","propName","ref","$$typeof","props","reactJsxRuntime_production","Fragment","jsx","jsxs","require$$0","EventBusContext","createContext","useEventBus","useContext","PublishEventContext","EspEventBusContextProvider","children","bus","busFromContext","publishEvent","useCallback","args","length","address","eventType","event","createPublishEvent","Provider","value","GetStoreIdContext","useGetStoreId","GetStoreModelContext","PublishStoreEventContext","PublishStoreEventWithEntityKeyContext","EspStoreContextProvider","storeId","model","storeIdFromContext","publishStoreEvent","createPublishStoreEvent","publishStoreEventWithEntityKey","DefaultStoreAddress","entityKey","createPublishStoreEventWithEntityKey","withSelectorModule","React","objectIs","Object","is","x","y","useSyncExternalStore","useRef","useEffect","useMemo","useDebugValue","useSyncExternalStoreWithSelector_production","useSyncExternalStoreWithSelector","subscribe","getSnapshot","getServerSnapshot","selector","isEqual","instRef","current","inst","hasValue","memoizedSelector","nextSnapshot","hasMemo","memoizedSnapshot","currentSelection","memoizedSelection","nextSelection","maybeGetServerSnapshot","Logger","create","syncStoreModelWithSelectorOptions","equalityFn","a","b","setStoreId","this","setEqualityFn","useSyncStoreModelWithSelector","options","utils","isFunction","Error","isObject","checkArguments","dependencies","isString","createSubscriptionState","createNoopSubscriptionState","snapshot","currentModel","stateChanged","modelSubscriptionDisposable","getStoreModelObservable","m","dispose","isStoreRegistered","getStoreModel","ConnectableComponent","mapStoreModelToProps","createPublishEventProps","view","rest","publishEventProps","childProps","restProps","getChildProps","viewElement","createElement","EspModulesContext","app","eventBus","modules","regionName","bindings","flatMap","viewBindings","filter","region","map","binding","index","viewComponent"],"mappings":"0mBAGEA,EAAAC,qCCQF,IAAIC,EAAqBC,OAAOC,IAAI,8BAClCC,EAAsBF,OAAOC,IAAI,kBACnC,SAASE,EAAQC,EAAMC,EAAQC,GAC7B,IAAIC,EAAM,KAGV,QAFA,IAAWD,IAAaC,EAAM,GAAKD,QACnC,IAAWD,EAAOE,MAAQA,EAAM,GAAKF,EAAOE,KACxC,QAASF,EAEX,IAAA,IAASG,KADTF,EAAW,CAAA,EACUD,EACnB,QAAUG,IAAaF,EAASE,GAAYH,EAAOG,SAChDF,EAAWD,EAElB,OADAA,EAASC,EAASG,IACX,CACLC,SAAUX,EACVK,OACAG,MACAE,SAAK,IAAWJ,EAASA,EAAS,KAClCM,MAAOL,EAEX,QACAM,EAAAC,SAAmBX,EACnBU,EAAAE,IAAcX,EACdS,EAAAG,KAAeZ,ID9BIa,mBEkBZ,MAAMC,EAAkBC,EAAAA,cAAwB,MAW1CC,EAAc,IAChBC,EAAAA,WAAWH,GAgBTI,EAAsBH,EAAAA,cAAoC,MAoB1DI,EAA6B,EAAEC,WAAUC,UAElD,IAAIC,EAAiBN,IACrBK,EAAMA,GAAOC,EACb,MAAMC,EAAqCC,EAAAA,YApCpB,CAACH,GAGxB,YAAyBI,GACD,IAAhBA,EAAKC,OACLL,EAAIE,aAAaE,EAAK,GAAGE,QAASF,EAAK,GAAGG,UAAWH,EAAK,GAAGI,OAE7DR,EAAIE,aAAaE,EAAK,GAAIA,EAAK,GAAIA,EAAK,GAEhD,EA2BuDK,CAAmBT,GAAM,CAACA,IACjF,SACIV,IAACG,EAAgBiB,SAAhB,CAAyBC,MAAOX,EAC7BD,SAAAT,EAAAA,IAACO,EAAoBa,SAApB,CAA6BC,MAAOT,EAChCH,cAET,EC3EKa,EAAoBlB,EAAAA,cAAsB,MAM1CmB,EAAgB,IAAMjB,EAAAA,WAAWgB,G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AAA,IAACiG,EAAA,CAIGrE,QAAS2F,EAAQ3F,QACjBwE,KAAMmB,EAAQE,eAFT,GAAGF,EAAQ3F,WAAW4F,QAKvC,6FPzBwB,IAAelH,EAAAA,WAAWkB,qBD0C3B,IAAMlB,EAAAA,WAAWC,0BClBZ,IAAMD,EAAAA,WAAWmB,uCAuBJ,IAAMnB,EAAAA,WAAWoB","x_google_ignoreList":[0,1,4,5]}
|
|
1
|
+
{"version":3,"file":"esp-react.min.js","sources":["../src/espEventBusContextProvider.tsx","../src/espStoreContextProvider.tsx","../../../node_modules/use-sync-external-store/with-selector.js","../../../node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.production.js","../src/useSyncStoreModelWithSelector.ts","../src/connectableComponent.tsx","../src/espModulesContext.ts","../src/espApp.tsx","../src/regionView.tsx"],"sourcesContent":["// notice_start\n/*\n * Copyright 2015 Dev Shop Limited\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n// notice_end\n\nimport {StoreAddress, EventBus} from 'esp-js';\nimport * as React from 'react';\nimport {PropsWithChildren, createContext, useContext, useCallback} from 'react';\n\nexport const EventBusContext = createContext<EventBus>(null);\n\n/**\n * Get the esp EventBus from context.\n *\n * To use this, please ensure your V-DOM has the EspEventBusContextProvider at a higher node:\n *\n * <EspEventBusContextProvider bus={bus}>\n * <YourComponents />\n * </EspEventBusContextProvider>\n */\nexport const useEventBus = () => {\n return useContext(EventBusContext);\n};\n\nexport type PublishEventDelegate = {(storeIdOrStoreAddress: string | StoreAddress, eventType: string, event: any): void; (eventData: { address: string | StoreAddress, eventType: string, event: any }): void; };\nconst createPublishEvent = (bus: EventBus) => {\n function publishEvent(storeIdOrStoreAddress: string | StoreAddress, eventType: string, event: any): void;\n function publishEvent(eventData: { address: string | StoreAddress, eventType: string, event: any }): void;\n function publishEvent(...args: any[]): void {\n if (args.length === 1) {\n bus.publishEvent(args[0].address, args[0].eventType, args[0].event);\n } else {\n bus.publishEvent(args[0], args[1], args[2]);\n }\n }\n return publishEvent;\n};\nexport const PublishEventContext = createContext<PublishEventDelegate>(null);\n\n/**\n * Returns a function which can be used to publish an event.\n *\n * To use this, please ensure your V-DOM has the EspEventBusContextProvider at a higher node:\n *\n * <EspEventBusContextProvider bus={bus}>\n * <YourComponents />\n * </EspEventBusContextProvider>\n */\nexport const usePublishEvent = () => useContext(PublishEventContext);\n\nexport type EspEventBusContextProviderProps = PropsWithChildren<{ bus: EventBus; }>;\n\n/**\n * Used to set the bus on the EventBusContext making it available to components down the tree via the useEventBus() hook.\n *\n * Also sets up the usePublishEvent() hook so nested components can publish to the bus.\n */\nexport const EspEventBusContextProvider = ({children, bus}: EspEventBusContextProviderProps) => {\n // EventBus may have been set by a higher level version of this component, so we try and get it from context if it's not set by props.\n let busFromContext = useEventBus();\n bus = bus || busFromContext;\n const publishEvent: PublishEventDelegate = useCallback(createPublishEvent(bus), [bus]);\n return (\n <EventBusContext.Provider value={bus}>\n <PublishEventContext.Provider value={publishEvent}>\n {children}\n </PublishEventContext.Provider>\n </EventBusContext.Provider>\n );\n};","import {DefaultStoreAddress, EventBus} from 'esp-js';\nimport * as React from 'react';\nimport {useContext, useCallback, createContext, PropsWithChildren} from 'react';\nimport {useEventBus} from './espEventBusContextProvider';\n\nexport const GetStoreIdContext = createContext<string>(null);\n/**\n * Returns a function to get the ID of the store connected at a higher point in the V-DOM.\n *\n * To use this, please ensure your V-DOM has the EspStoreContextProvider at a higher node.\n */\nexport const useGetStoreId = () => useContext(GetStoreIdContext);\n\nexport const GetStoreModelContext = createContext<object>(null);\n/**\n * Returns the current model (frozen snapshot) of the store connected at a higher point in the V-DOM.\n *\n * To use this, please ensure your V-DOM has the EspStoreContextProvider at a higher node.\n */\nexport const useGetStoreModel = <TModel,>() => useContext(GetStoreModelContext) as TModel;\n\nexport type PublishStoreEventDelegate = { (eventType: string, event: any): void; (eventData: {eventType: string, event: any}): void; };\nconst createPublishStoreEvent = (bus: EventBus, storeId: string) => {\n function publishStoreEvent(eventType: string, event: any): void;\n function publishStoreEvent(eventData: {eventType: string, event: any}): void;\n function publishStoreEvent(...args: any[]) {\n if (args.length === 1) {\n bus.publishEvent(storeId, args[0].eventType, args[0].event);\n } else {\n bus.publishEvent(storeId, args[0], args[1]);\n }\n }\n return publishStoreEvent;\n};\nexport const PublishStoreEventContext = createContext<PublishStoreEventDelegate>(null);\n\n/**\n * Returns a function which can be used to publish an event to the store connected at a higher point in the V-DOM.\n *\n * Effectively, this is a version of usePublishEvent() which closes over the relevant storeId.\n *\n * To use this, please ensure your V-DOM has the EspStoreContextProvider at a higher node.\n */\nexport const usePublishStoreEvent = () => useContext(PublishStoreEventContext);\n\nexport type PublishStoreEventWithEntityKeyDelegate = {(entityKey: string, eventType: string, event: any): void; (eventData: {entityKey: string, eventType: string, event: any}): void; };\nconst createPublishStoreEventWithEntityKey = (bus: EventBus, storeId: string) => {\n function publishStoreEventWithEntityKey(entityKey: string, eventType: string, event: any): void;\n function publishStoreEventWithEntityKey(eventData: {entityKey: string, eventType: string, event: any}): void;\n function publishStoreEventWithEntityKey(...args: any[]) {\n if (args.length === 1) {\n bus.publishEvent(new DefaultStoreAddress(storeId, args[0].entityKey), args[0].eventType, args[0].event);\n } else {\n bus.publishEvent(new DefaultStoreAddress(storeId, args[0]), args[1], args[2]);\n }\n }\n return publishStoreEventWithEntityKey;\n};\nexport const PublishStoreEventWithEntityKeyContext = createContext<PublishStoreEventWithEntityKeyDelegate>(null);\n/**\n * Returns a function which can be used to publish an event to the store connected at a higher point in the V-DOM, allows an entityKey to be specified.\n *\n * Effectively, this is a version of usePublishEvent() which closes over the storeId.\n *\n * To use this, please ensure your V-DOM has the EspStoreContextProvider at a higher node.\n */\nexport const usePublishStoreEventWithEntityKey = () => useContext(PublishStoreEventWithEntityKeyContext);\n\nexport interface EspStoreContextProviderProps {\n storeId: string;\n model?: any;\n}\n\n/**\n * Sets up various ESP context so ESP hooks are available below this point in the V-DOM\n *\n * To use this, please ensure your V-DOM has the EspEventBusContextProvider at a higher node.\n * @param storeId\n * @param children\n * @param model\n * @constructor\n */\nexport const EspStoreContextProvider = ({storeId, children, model}: PropsWithChildren<EspStoreContextProviderProps>) => {\n const bus = useEventBus();\n // storeId may have been set by a higher level version of this component, so we try and get it from context if it's not set by props.\n let storeIdFromContext = useGetStoreId();\n storeId = storeId || storeIdFromContext;\n const publishStoreEvent: PublishStoreEventDelegate = useCallback(createPublishStoreEvent(bus, storeId), [bus, storeId]);\n const publishStoreEventWithEntityKey: PublishStoreEventWithEntityKeyDelegate = useCallback(createPublishStoreEventWithEntityKey(bus, storeId), [bus, storeId]);\n return (\n <GetStoreIdContext.Provider value={storeId}>\n <PublishStoreEventContext.Provider value={publishStoreEvent}>\n <PublishStoreEventWithEntityKeyContext.Provider value={publishStoreEventWithEntityKey}>\n <GetStoreModelContext.Provider value={model}>\n {children}\n </GetStoreModelContext.Provider>\n </PublishStoreEventWithEntityKeyContext.Provider>\n </PublishStoreEventContext.Provider>\n </GetStoreIdContext.Provider>\n );\n};\n","'use strict';\n\nif (process.env.NODE_ENV === 'production') {\n module.exports = require('./cjs/use-sync-external-store-with-selector.production.js');\n} else {\n module.exports = require('./cjs/use-sync-external-store-with-selector.development.js');\n}\n","/**\n * @license React\n * use-sync-external-store-with-selector.production.js\n *\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n\"use strict\";\nvar React = require(\"react\");\nfunction is(x, y) {\n return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y);\n}\nvar objectIs = \"function\" === typeof Object.is ? Object.is : is,\n useSyncExternalStore = React.useSyncExternalStore,\n useRef = React.useRef,\n useEffect = React.useEffect,\n useMemo = React.useMemo,\n useDebugValue = React.useDebugValue;\nexports.useSyncExternalStoreWithSelector = function (\n subscribe,\n getSnapshot,\n getServerSnapshot,\n selector,\n isEqual\n) {\n var instRef = useRef(null);\n if (null === instRef.current) {\n var inst = { hasValue: !1, value: null };\n instRef.current = inst;\n } else inst = instRef.current;\n instRef = useMemo(\n function () {\n function memoizedSelector(nextSnapshot) {\n if (!hasMemo) {\n hasMemo = !0;\n memoizedSnapshot = nextSnapshot;\n nextSnapshot = selector(nextSnapshot);\n if (void 0 !== isEqual && inst.hasValue) {\n var currentSelection = inst.value;\n if (isEqual(currentSelection, nextSnapshot))\n return (memoizedSelection = currentSelection);\n }\n return (memoizedSelection = nextSnapshot);\n }\n currentSelection = memoizedSelection;\n if (objectIs(memoizedSnapshot, nextSnapshot)) return currentSelection;\n var nextSelection = selector(nextSnapshot);\n if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))\n return (memoizedSnapshot = nextSnapshot), currentSelection;\n memoizedSnapshot = nextSnapshot;\n return (memoizedSelection = nextSelection);\n }\n var hasMemo = !1,\n memoizedSnapshot,\n memoizedSelection,\n maybeGetServerSnapshot =\n void 0 === getServerSnapshot ? null : getServerSnapshot;\n return [\n function () {\n return memoizedSelector(getSnapshot());\n },\n null === maybeGetServerSnapshot\n ? void 0\n : function () {\n return memoizedSelector(maybeGetServerSnapshot());\n }\n ];\n },\n [getSnapshot, getServerSnapshot, selector, isEqual]\n );\n var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);\n useEffect(\n function () {\n inst.hasValue = !0;\n inst.value = value;\n },\n [value]\n );\n useDebugValue(value);\n return value;\n};\n","import {useMemo} from 'react';\nimport {useSyncExternalStoreWithSelector} from 'use-sync-external-store/with-selector';\nimport {Logger, EventBus, utils} from 'esp-js';\nimport {useEventBus} from './espEventBusContextProvider';\nimport {useGetStoreId} from './espStoreContextProvider';\n\nexport type SyncStoreModelWithSelectorEqualityFn<T> = (last: T, next: T) => boolean;\n\nexport const logger = Logger.create('useSyncStoreModelWithSelector');\n\n/**\n * Options affecting the subscription of the model to the EventBus.\n *\n * Use syncStoreModelWithSelectorOptions() to create an instance of this type with sensible defaults.\n *\n * @param storeId - the storeId of the store to be observed via the esp EventBus.\n * @param equalityFn - Equality function which will be applied against TSelected, defaults to instance equality (a === b).\n */\nexport type SyncStoreModelWithSelectorOptions<TSelected> = {\n storeId?: string,\n equalityFn: SyncStoreModelWithSelectorEqualityFn<TSelected>\n};\n\n/**\n * Convenience API to build SyncStoreModelWithSelectorOptions<TSelected>, has sensible defaulting.\n */\nexport interface SyncStoreModelWithSelectorOptionsBuilder<TSelected> extends SyncStoreModelWithSelectorOptions<TSelected> {\n /**\n * Sets the store ID\n * @param storeId - default if unset: undefined\n */\n setStoreId(storeId: string): this;\n\n /**\n * Equality function used when comparing the last TSelected with the next.\n * @param fn - default if unset: obj instance equality (e.g. a===b)\n */\n setEqualityFn(fn: (a: TSelected, b: TSelected) => boolean): this;\n}\n\n/**\n * Convenience API to create SyncStoreModelWithSelectorOptions\n */\nexport const syncStoreModelWithSelectorOptions = <TSelected>() => {\n let storeId = undefined;\n let equalityFn: SyncStoreModelWithSelectorEqualityFn<TSelected> = (a: TSelected, b: TSelected) => a === b;\n return {\n get storeId() {\n return storeId;\n },\n setStoreId(value: string) {\n storeId = value;\n return this;\n },\n get equalityFn() {\n return equalityFn;\n },\n setEqualityFn(value: SyncStoreModelWithSelectorEqualityFn<TSelected>) {\n equalityFn = value;\n return this;\n }\n } as SyncStoreModelWithSelectorOptionsBuilder<TSelected>;\n};\n\nconst checkArguments = (selector: (model: any) => any, options: SyncStoreModelWithSelectorOptions<any> ) => {\n if (!utils.isFunction(selector)) {\n throw new Error('You must pass a selector function to useSyncStoreModelWithSelector');\n }\n if (!utils.isObject(options)) {\n throw new Error('You must provide options when using useSyncStoreModelWithSelector');\n }\n if (!utils.isFunction(options.equalityFn)) {\n throw new Error('You must provide an equalityFn when using useSyncStoreModelWithSelector');\n }\n};\n\n/**\n * A hook which returns model state from the esp EventBus.\n *\n * This hooks wih observe updates and re-render the component if the model changes.\n *\n * To use this, please ensure your V-DOM has the EspEventBusContextProvider at a higher node, and optionally EspStoreContextProvider.\n *\n * If the store isn't registered yet, the hook returns null and picks up the model once the store is registered.\n *\n * @param selector - a function to select a selection of the model. It does not need to be memoized: the latest selector is used on each render, and the equalityFn (if any) decides whether a new selection re-renders.\n * @param options\n */\nexport const useSyncStoreModelWithSelector = <TModel, TSelected>(\n selector: (model: TModel) => TSelected,\n options: SyncStoreModelWithSelectorOptions<TSelected> = syncStoreModelWithSelectorOptions<TSelected>()\n): TSelected => {\n checkArguments(selector, options);\n const bus = useEventBus();\n const storeIdFromContext = useGetStoreId();\n const storeId = options?.storeId || storeIdFromContext;\n const equalityFn = options?.equalityFn;\n const dependencies = useMemo(\n () => {\n // Subscribe even if the store isn't registered yet: getStoreModelObservable() supports stores registered later,\n // and emits the model when the store is added.\n const canSubscribe = bus && utils.isString(storeId);\n if (canSubscribe) {\n return createSubscriptionState(bus, storeId);\n }\n return createNoopSubscriptionState();\n },\n [bus, storeId]\n );\n // Wrap the caller's selector on every render so a selector that closes over props/state is never stale.\n // useSyncExternalStoreWithSelector re-runs it when it changes and applies the equalityFn to the result.\n const wrappedSelector = (snapshot: TModel) => snapshot ? selector(snapshot) : null;\n\n // Docs on useSyncExternalStore https://github.com/reactwg/react-18/discussions/86\n // Redux's usage of this: https://github.com/reduxjs/react-redux/blob/master/src/hooks/useSelector.ts\n // Code: https://github.com/facebook/react/blob/main/packages/use-sync-external-store/src/useSyncExternalStoreWithSelector.js\n return useSyncExternalStoreWithSelector(\n dependencies.subscribe,\n dependencies.getSnapshot,\n undefined,\n wrappedSelector,\n equalityFn,\n );\n};\n\nconst createSubscriptionState = <TModel>(\n bus: EventBus,\n storeId: string,\n) => {\n // Because of how useSyncExternalStore works, there is an implicit dependency between the subscribe and getSnapshot functions.\n // When the subscription receives the new state from the EventBus, it can't pass this directly onto getSnapshot,\n // React calls that when it deems it needs to.\n // Given that, we need to cache the state which getSnapshot will return.\n //\n // Note: the bus subscription is created inside the `subscribe` callback (not here at factory time).\n // This is important for correctness with React StrictMode: StrictMode intentionally unmounts and remounts\n // components to surface side-effect bugs. When the cleanup returned by `subscribe` is called, it disposes\n // the bus subscription and clears `currentModel`. Because the `dependencies` object created by useMemo is\n // reused across the remount (deps haven't changed), any bus subscription created eagerly at useMemo time\n // would already be disposed on remount, leaving `currentModel` permanently null.\n //\n // useSyncExternalStore guarantees that `getSnapshot` is called before `subscribe`, so we initialise\n // `currentModel` lazily from `bus.getStoreModel()` inside `getSnapshot` when it is still null.\n let currentModel: TModel;\n return {\n subscribe: (stateChanged: () => void) => {\n // Subscribe to future model updates from the EventBus.\n // This is called by React when the component mounts (and remounts after StrictMode teardown).\n const modelSubscriptionDisposable = bus\n .getStoreModelObservable<TModel>(storeId)\n .subscribe(\n (m: TModel) => {\n // The model is a frozen immutable snapshot produced by immer after each dispatch cycle.\n // immer only creates a new reference when something changed, so the same reference means no change.\n // This also covers the replay of the current model when we subscribe, which getSnapshot() already returned.\n if (m === currentModel) {\n return;\n }\n currentModel = m;\n stateChanged();\n }\n );\n return () => {\n currentModel = null;\n modelSubscriptionDisposable.dispose();\n };\n },\n // React expects getSnapshot to be pure and stable between renders unless the store has changed.\n // We seed currentModel from bus.getStoreModel() on first call (before subscribe has been called),\n // then keep it up-to-date via the subscription callback above.\n // getStoreModel() throws for a store that's been observed but not registered yet, so check first; until then the snapshot is null.\n getSnapshot: () => {\n if (currentModel == null && bus.isStoreRegistered(storeId)) {\n currentModel = bus.getStoreModel<TModel>(storeId);\n }\n return currentModel;\n },\n };\n};\n\nconst createNoopSubscriptionState = () => ({\n subscribe: () => {\n return () => {};\n },\n getSnapshot: (): null => null,\n});\n","import * as React from 'react';\nimport {useEventBus} from './espEventBusContextProvider';\nimport {useMemo} from 'react';\nimport {EventBus} from 'esp-js';\nimport {EspStoreContextProvider, useGetStoreId} from './espStoreContextProvider';\nimport {syncStoreModelWithSelectorOptions, useSyncStoreModelWithSelector} from './useSyncStoreModelWithSelector';\n\nexport type CreatePublishEventProps<TPublishEventProps> = (publishModelEvent: (eventType: string, event: any) => void) => TPublishEventProps;\n\nexport type MapStoreModelToProps<TModel, TModelMappedToProps, TPublishEventProps = {}> = (model: TModel, publishEventProps: TPublishEventProps) => TModelMappedToProps;\n\nexport interface ConnectableComponentProps<TModel = {}, TPublishEventProps = {}, TModelMappedToProps = {}> {\n storeId?: string;\n view?: React.ComponentType<any>;\n createPublishEventProps?: CreatePublishEventProps<TPublishEventProps>;\n mapStoreModelToProps?: MapStoreModelToProps<TModel, TModelMappedToProps, TPublishEventProps>;\n [key: string]: any; // ...rest props, including the result of mapPublish and mapPublish if 'connect' was used\n}\n\nexport interface ConnectableComponentChildProps<TModel = object> {\n storeId: string;\n model: TModel;\n bus: EventBus;\n [key: string]: any; // ...rest props\n}\n\nconst getChildProps = <TModel, TModelMappedToProps, TPublishEventProps>(\n bus: EventBus,\n storeId: string,\n restProps: object,\n model: TModel,\n mapStoreModelToProps: MapStoreModelToProps<TModel, TModelMappedToProps, TPublishEventProps>,\n publishEventProps: TPublishEventProps\n): ConnectableComponentChildProps<TModel> => {\n let childProps = {\n storeId,\n bus: bus,\n ...restProps,\n ...publishEventProps,\n model\n };\n if (mapStoreModelToProps) {\n childProps = {\n ...childProps,\n ...(mapStoreModelToProps(model, publishEventProps) as TModelMappedToProps)\n };\n }\n return childProps;\n};\n\nexport const ConnectableComponent = <TModel = {}, TPublishEventProps = {}, TModelMappedToProps = {}>(\n {\n storeId,\n mapStoreModelToProps,\n createPublishEventProps,\n view,\n ...rest\n }: ConnectableComponentProps<TModel, TPublishEventProps, TModelMappedToProps>\n) => {\n const bus = useEventBus();\n // Note: we always need to render the hooks else react will complain about a different count.\n let storeIdFromContext = useGetStoreId();\n storeId = storeId || storeIdFromContext;\n // createPublishEventProps is captured once per bus/storeId (not re-run when the prop changes),\n // so callers can pass an inline function and still get stable publish props.\n const publishEventProps: TPublishEventProps = useMemo(\n () => {\n if (createPublishEventProps) {\n const publishModelEvent = (eventType: string, event: any) => {\n bus.publishEvent(storeId, eventType, event);\n };\n return createPublishEventProps(publishModelEvent);\n }\n return {} as TPublishEventProps;\n },\n [bus, storeId]\n );\n const model = useSyncStoreModelWithSelector<TModel, TModel>(\n m => m,\n syncStoreModelWithSelectorOptions()\n .setStoreId(storeId)\n );\n if (model == null) {\n return null;\n }\n let childProps = getChildProps(bus, storeId, rest, model, mapStoreModelToProps, publishEventProps);\n let viewElement = view ? React.createElement(view, childProps) : null;\n return (\n <EspStoreContextProvider storeId={storeId} model={model} bus={bus} {...childProps}>\n {viewElement}\n </EspStoreContextProvider>\n );\n};\n","import * as React from 'react';\nimport type { Module } from 'esp-js-ui';\n\nexport const EspModulesContext = React.createContext<ReadonlyArray<Module>>([]);\n","import * as React from 'react';\nimport type { App } from 'esp-js-ui';\nimport { EspEventBusContextProvider } from './espEventBusContextProvider';\nimport { EspModulesContext } from './espModulesContext';\n\nexport interface EspAppProps {\n app: App;\n children: React.ReactNode;\n}\n\n/**\n * Wraps an application root with the ESP context providers.\n *\n * Provides the EventBus (via EspEventBusContextProvider) and the loaded\n * modules list (via EspModulesContext) so that RegionView and any\n * esp-js-react hooks work without additional setup in the root component.\n *\n * Multiple EspApp instances can be mounted independently in the same DOM\n * for multi-app scenarios.\n *\n * Example:\n * await app.start();\n * ReactDOM.createRoot(document.getElementById('root')).render(\n * <EspApp app={app}>\n * <AppShell />\n * </EspApp>\n * );\n */\nexport const EspApp = ({ app, children }: EspAppProps) => (\n <EspEventBusContextProvider bus={app.eventBus}>\n <EspModulesContext.Provider value={app.modules}>\n {children}\n </EspModulesContext.Provider>\n </EspEventBusContextProvider>\n);\n","import * as React from 'react';\nimport {useContext, useMemo} from 'react';\nimport { ConnectableComponent } from './connectableComponent';\nimport { EspModulesContext } from './espModulesContext';\n\nexport interface RegionViewProps {\n regionName: string;\n}\n\n/**\n * Renders all view bindings registered for a given region across all loaded modules.\n *\n * Each module declares views with a region token (ModuleBuilder.withView in esp-js-ui).\n * RegionView reads EspModulesContext (populated by EspApp), finds all bindings\n * matching regionName, and mounts a ConnectableComponent for each.\n *\n * Example:\n * const AppRoot = () => (\n * <div>\n * <RegionView regionName='main' />\n * <RegionView regionName='sidebar' />\n * </div>\n * );\n */\nexport const RegionView = ({ regionName }: RegionViewProps) => {\n const modules = useContext(EspModulesContext);\n const bindings = useMemo(\n () => modules\n .flatMap(m => m.viewBindings)\n .filter(b => b.region === regionName),\n [modules, regionName]\n );\n return (\n <>\n {bindings.map((binding, index) => (\n <ConnectableComponent\n // storeId alone isn't unique: a region can hold several views over the same store.\n // Bindings are fixed once the modules are built, so the index is a stable key.\n key={`${binding.storeId}:${index}`}\n storeId={binding.storeId}\n view={binding.viewComponent}\n />\n ))}\n </>\n );\n};\n"],"names":["EventBusContext","createContext","useEventBus","useContext","PublishEventContext","EspEventBusContextProvider","children","bus","busFromContext","publishEvent","useCallback","args","length","address","eventType","event","createPublishEvent","createElement","Provider","value","React","GetStoreIdContext","useGetStoreId","GetStoreModelContext","PublishStoreEventContext","PublishStoreEventWithEntityKeyContext","EspStoreContextProvider","storeId","model","storeIdFromContext","publishStoreEvent","createPublishStoreEvent","publishStoreEventWithEntityKey","DefaultStoreAddress","entityKey","createPublishStoreEventWithEntityKey","withSelectorModule","exports","require$$0","objectIs","Object","is","x","y","useSyncExternalStore","useRef","useEffect","useMemo","useDebugValue","useSyncExternalStoreWithSelector_production","useSyncExternalStoreWithSelector","subscribe","getSnapshot","getServerSnapshot","selector","isEqual","instRef","current","inst","hasValue","memoizedSelector","nextSnapshot","hasMemo","memoizedSnapshot","currentSelection","memoizedSelection","nextSelection","maybeGetServerSnapshot","Logger","create","syncStoreModelWithSelectorOptions","equalityFn","a","b","setStoreId","this","setEqualityFn","useSyncStoreModelWithSelector","options","utils","isFunction","Error","isObject","checkArguments","dependencies","isString","createSubscriptionState","createNoopSubscriptionState","snapshot","currentModel","stateChanged","modelSubscriptionDisposable","getStoreModelObservable","m","dispose","isStoreRegistered","getStoreModel","ConnectableComponent","mapStoreModelToProps","createPublishEventProps","view","rest","publishEventProps","childProps","restProps","getChildProps","viewElement","EspModulesContext","app","eventBus","modules","regionName","bindings","flatMap","viewBindings","filter","region","Fragment","map","binding","index","key","viewComponent"],"mappings":"glBAsBaA,EAAkBC,EAAAA,cAAwB,MAW1CC,EAAc,IAChBC,EAAAA,WAAWH,GAgBTI,EAAsBH,EAAAA,cAAoC,MAoB1DI,EAA6B,EAAEC,WAAUC,UAElD,IAAIC,EAAiBN,IACrBK,EAAMA,GAAOC,EACb,MAAMC,EAAqCC,EAAAA,YApCpB,CAACH,GAGxB,YAAyBI,GACD,IAAhBA,EAAKC,OACLL,EAAIE,aAAaE,EAAK,GAAGE,QAASF,EAAK,GAAGG,UAAWH,EAAK,GAAGI,OAE7DR,EAAIE,aAAaE,EAAK,GAAIA,EAAK,GAAIA,EAAK,GAEhD,EA2BuDK,CAAmBT,GAAM,CAACA,IACjF,SACIU,cAACjB,EAAgBkB,SAAhB,CAAyBC,MAAOZ,GAC7Ba,EAAAH,cAACb,EAAoBc,SAApB,CAA6BC,MAAOV,GAChCH,GAET,EC3EKe,EAAoBpB,EAAAA,cAAsB,MAM1CqB,EAAgB,IAAMnB,EAAAA,WAAWkB,GAEjCE,EAAuBtB,EAAAA,cAAsB,MAqB7CuB,EAA2BvB,EAAAA,cAAyC,MAwBpEwB,EAAwCxB,EAAAA,cAAsD,MAwB9FyB,EAA0B,EAAEC,UAASrB,WAAUsB,YACxD,MAAMrB,EAAML,IAEZ,IAAI2B,EAAqBP,IACzBK,EAAUA,GAAWE,EACrB,MAAMC,EAA+CpB,EAAAA,YAjEzB,EAACH,EAAeoB,IAG5C,YAA8BhB,GACN,IAAhBA,EAAKC,OACLL,EAAIE,aAAakB,EAAShB,EAAK,GAAGG,UAAWH,EAAK,GAAGI,OAErDR,EA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,IAEpB,GAAa,MAATC,EACA,OAAO,KAEX,IAAI2E,EA3Dc,EAClBhG,EACAoB,EACA6E,EACA5E,EACAsE,EACAI,KAEA,IAAIC,EAAa,CACb5E,UACApB,SACGiG,KACAF,EACH1E,SAQJ,OANIsE,IACAK,EAAa,IACNA,KACCL,EAAqBtE,EAAO0E,KAGjCC,CAAA,EAsCUE,CAAclG,EAAKoB,EAAS0E,EAAMzE,EAAOsE,EAAsBI,GAC5EI,EAAcN,EAAOhF,EAAMH,cAAcmF,EAAMG,GAAc,KACjE,uBACK7E,EAAA,CAAwBC,UAAkBC,QAAcrB,SAAcgG,GAClEG,EACL,ECvFKC,EAAoBvF,EAAMnB,cAAqC,sCCyBtD,EAAG2G,MAAKtG,8BACzBD,EAAA,CAA2BE,IAAKqG,EAAIC,UACjCzF,EAAAH,cAAC0F,EAAkBzF,SAAlB,CAA2BC,MAAOyF,EAAIE,SAClCxG,oQCPa,EAAGyG,iBACzB,MAAMD,EAAU3G,EAAAA,WAAWwG,GACrBK,EAAWjE,EAAAA,SACb,IAAM+D,EACDG,SAAQpB,GAAKA,EAAEqB,eACfC,QAAO1C,GAAKA,EAAE2C,SAAWL,KAC9B,CAACD,EAASC,IAEd,OACI3F,EAAAH,cAAAG,EAAAiG,SAAA,KACKL,EAASM,KAAI,CAACC,EAASC,IACpBpG,EAAAH,cAACgF,EAAA,CAGGwB,IAAK,GAAGF,EAAQ5F,WAAW6F,IAC3B7F,QAAS4F,EAAQ5F,QACjByE,KAAMmB,EAAQG,kBAG1B,6FPxBwB,IAAevH,EAAAA,WAAWoB,qBD0C3B,IAAMpB,EAAAA,WAAWC,0BClBZ,IAAMD,EAAAA,WAAWqB,uCAuBJ,IAAMrB,EAAAA,WAAWsB","x_google_ignoreList":[2,3]}
|
|
@@ -15,4 +15,4 @@ export interface ConnectableComponentChildProps<TModel = object> {
|
|
|
15
15
|
bus: EventBus;
|
|
16
16
|
[key: string]: any;
|
|
17
17
|
}
|
|
18
|
-
export declare const ConnectableComponent: <TModel = {}, TPublishEventProps = {}, TModelMappedToProps = {}>({ storeId, mapStoreModelToProps, createPublishEventProps, view, ...rest }: ConnectableComponentProps<TModel, TPublishEventProps, TModelMappedToProps>) =>
|
|
18
|
+
export declare const ConnectableComponent: <TModel = {}, TPublishEventProps = {}, TModelMappedToProps = {}>({ storeId, mapStoreModelToProps, createPublishEventProps, view, ...rest }: ConnectableComponentProps<TModel, TPublishEventProps, TModelMappedToProps>) => React.JSX.Element;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { StoreAddress, EventBus } from 'esp-js';
|
|
2
2
|
import { PropsWithChildren } from 'react';
|
|
3
|
-
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
export declare const EventBusContext: React.Context<EventBus>;
|
|
4
5
|
/**
|
|
5
6
|
* Get the esp EventBus from context.
|
|
6
7
|
*
|
|
@@ -19,7 +20,7 @@ export type PublishEventDelegate = {
|
|
|
19
20
|
event: any;
|
|
20
21
|
}): void;
|
|
21
22
|
};
|
|
22
|
-
export declare const PublishEventContext:
|
|
23
|
+
export declare const PublishEventContext: React.Context<PublishEventDelegate>;
|
|
23
24
|
/**
|
|
24
25
|
* Returns a function which can be used to publish an event.
|
|
25
26
|
*
|
|
@@ -38,4 +39,4 @@ export type EspEventBusContextProviderProps = PropsWithChildren<{
|
|
|
38
39
|
*
|
|
39
40
|
* Also sets up the usePublishEvent() hook so nested components can publish to the bus.
|
|
40
41
|
*/
|
|
41
|
-
export declare const EspEventBusContextProvider: ({ children, bus }: EspEventBusContextProviderProps) =>
|
|
42
|
+
export declare const EspEventBusContextProvider: ({ children, bus }: EspEventBusContextProviderProps) => React.JSX.Element;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
|
-
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
export declare const GetStoreIdContext: React.Context<string>;
|
|
3
4
|
/**
|
|
4
5
|
* Returns a function to get the ID of the store connected at a higher point in the V-DOM.
|
|
5
6
|
*
|
|
6
7
|
* To use this, please ensure your V-DOM has the EspStoreContextProvider at a higher node.
|
|
7
8
|
*/
|
|
8
9
|
export declare const useGetStoreId: () => string;
|
|
9
|
-
export declare const GetStoreModelContext:
|
|
10
|
+
export declare const GetStoreModelContext: React.Context<object>;
|
|
10
11
|
/**
|
|
11
12
|
* Returns the current model (frozen snapshot) of the store connected at a higher point in the V-DOM.
|
|
12
13
|
*
|
|
@@ -20,7 +21,7 @@ export type PublishStoreEventDelegate = {
|
|
|
20
21
|
event: any;
|
|
21
22
|
}): void;
|
|
22
23
|
};
|
|
23
|
-
export declare const PublishStoreEventContext:
|
|
24
|
+
export declare const PublishStoreEventContext: React.Context<PublishStoreEventDelegate>;
|
|
24
25
|
/**
|
|
25
26
|
* Returns a function which can be used to publish an event to the store connected at a higher point in the V-DOM.
|
|
26
27
|
*
|
|
@@ -37,7 +38,7 @@ export type PublishStoreEventWithEntityKeyDelegate = {
|
|
|
37
38
|
event: any;
|
|
38
39
|
}): void;
|
|
39
40
|
};
|
|
40
|
-
export declare const PublishStoreEventWithEntityKeyContext:
|
|
41
|
+
export declare const PublishStoreEventWithEntityKeyContext: React.Context<PublishStoreEventWithEntityKeyDelegate>;
|
|
41
42
|
/**
|
|
42
43
|
* Returns a function which can be used to publish an event to the store connected at a higher point in the V-DOM, allows an entityKey to be specified.
|
|
43
44
|
*
|
|
@@ -59,4 +60,4 @@ export interface EspStoreContextProviderProps {
|
|
|
59
60
|
* @param model
|
|
60
61
|
* @constructor
|
|
61
62
|
*/
|
|
62
|
-
export declare const EspStoreContextProvider: ({ storeId, children, model }: PropsWithChildren<EspStoreContextProviderProps>) =>
|
|
63
|
+
export declare const EspStoreContextProvider: ({ storeId, children, model }: PropsWithChildren<EspStoreContextProviderProps>) => React.JSX.Element;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
1
2
|
export interface RegionViewProps {
|
|
2
3
|
regionName: string;
|
|
3
4
|
}
|
|
@@ -16,4 +17,4 @@ export interface RegionViewProps {
|
|
|
16
17
|
* </div>
|
|
17
18
|
* );
|
|
18
19
|
*/
|
|
19
|
-
export declare const RegionView: ({ regionName }: RegionViewProps) =>
|
|
20
|
+
export declare const RegionView: ({ regionName }: RegionViewProps) => React.JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "esp-js-react",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.1",
|
|
4
4
|
"description": "Evented State Processor (ESP) React Components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"esp",
|
|
@@ -42,9 +42,6 @@
|
|
|
42
42
|
"test-ci": "nps test-ci",
|
|
43
43
|
"dev": "nps dev"
|
|
44
44
|
},
|
|
45
|
-
"dependencies": {
|
|
46
|
-
"use-sync-external-store": "^1.6.0"
|
|
47
|
-
},
|
|
48
45
|
"devDependencies": {
|
|
49
46
|
"@rollup/plugin-terser": "^0.4.4",
|
|
50
47
|
"@vitejs/plugin-react": "^4.3.1",
|
|
@@ -52,13 +49,14 @@
|
|
|
52
49
|
"esp-js-ui": "*",
|
|
53
50
|
"react": "^19.0.0",
|
|
54
51
|
"typescript": "^5.8.0",
|
|
52
|
+
"use-sync-external-store": "^1.6.0",
|
|
55
53
|
"vite": "^5.4.6",
|
|
56
54
|
"vite-plugin-dts": "^4.2.1",
|
|
57
55
|
"vitest": "^2.1.1"
|
|
58
56
|
},
|
|
59
57
|
"peerDependencies": {
|
|
60
|
-
"esp-js": "^9.0.
|
|
61
|
-
"esp-js-ui": "^9.0.
|
|
58
|
+
"esp-js": "^9.0.1",
|
|
59
|
+
"esp-js-ui": "^9.0.1",
|
|
62
60
|
"react": "^19.0.0"
|
|
63
61
|
},
|
|
64
62
|
"gitHead": "f6791a488f3fc5f59f20e19445b848d5e2f415c4"
|