dinocollab-core 2.1.39 → 2.1.40
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.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{inherits as e,createClass as t,superPropGet as r,typeof as i,objectWithoutProperties as n,objectSpread2 as o,classCallCheck as a,callSuper as s,defineProperty as u}from"../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as l,Fragment as c}from"react/jsx-runtime";import f from"events";import{forwardRef as v,useEffect as p}from"react";var g=["onClick","routeKey"],h=function(){function i(){var e;return a(this,i),e=s(this,i),u(e,"_createWrapListener",function(e){return function(){try{e.apply(void 0,arguments)}catch(e){console.error("Error in MfeBridge listener:",e)}}}),e}return e(i,f),t(i,[{key:"subscribe",value:function(e,t){var n=this,o=!(arguments.length>2&&void 0!==arguments[2])||arguments[2]?this._createWrapListener(t):t;return r(i,"addListener",this)([e,o]),function(){r(i,"removeListener",n)([e,o])}}}])}();function d(){if(void 0===("undefined"==typeof globalThis?"undefined":i(globalThis)))return null;void 0===globalThis.MfeNavigationEventStore&&(globalThis.MfeNavigationEventStore=new h);var e=globalThis.MfeNavigationEventStore;return e.setMaxListeners(50),e}var m=function(e){return p(function(){var t=d();if(t){var r=t.subscribe("navigation",function(t){e.navigation&&e.navigation(t.routeKey,t.options)});return function(){r()}}},[]),l(c,{})},b=v(function(e,t){var r=e.onClick,i=e.routeKey,a=n(e,g);return l("a",o(o({},
|
|
1
|
+
import{inherits as e,createClass as t,superPropGet as r,typeof as i,objectWithoutProperties as n,objectSpread2 as o,classCallCheck as a,callSuper as s,defineProperty as u}from"../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as l,Fragment as c}from"react/jsx-runtime";import f from"events";import{forwardRef as v,useEffect as p}from"react";var g=["onClick","routeKey","site"],h=function(){function i(){var e;return a(this,i),e=s(this,i),u(e,"_createWrapListener",function(e){return function(){try{e.apply(void 0,arguments)}catch(e){console.error("Error in MfeBridge listener:",e)}}}),e}return e(i,f),t(i,[{key:"subscribe",value:function(e,t){var n=this,o=!(arguments.length>2&&void 0!==arguments[2])||arguments[2]?this._createWrapListener(t):t;return r(i,"addListener",this)([e,o]),function(){r(i,"removeListener",n)([e,o])}}}])}();function d(){if(void 0===("undefined"==typeof globalThis?"undefined":i(globalThis)))return null;void 0===globalThis.MfeNavigationEventStore&&(globalThis.MfeNavigationEventStore=new h);var e=globalThis.MfeNavigationEventStore;return e.setMaxListeners(50),e}var m=function(e){return p(function(){var t=d();if(t){var r=t.subscribe("navigation",function(t){e.navigation&&e.navigation(t.routeKey,t.options)});return function(){r()}}},[]),l(c,{})},b=v(function(e,t){var r=e.onClick,i=e.routeKey,a=e.site,s=n(e,g);return l("a",o(o({},s),{},{ref:t,onClick:function(e){if(r&&r(e),!e.defaultPrevented){var t=d();if(t&&i){e.preventDefault(),e.stopPropagation();var n=s.target,o=s.rel,u=s.href,l={message:"Link clicked"};n&&(l.target=n),o&&(l.rel=o),u&&(l.href=u),a&&(l.site=a),t.emit("navigation",{routeKey:i,options:l})}}}}))}),y=function(e,t){var r=d();r&&r.emit("navigation",{routeKey:e,options:o({message:"Navigating to ".concat(e)},t)})};export{b as MfeLink,h as MfeNavigationEventStore,m as MfeNavigationProvider,d as getMfeNavigationEventStore,y as mfeNavigation};
|
|
2
2
|
//# sourceMappingURL=navigation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation.js","sources":["../../../src/mfe-shared/navigation.tsx"],"sourcesContent":["import EventEmitter from 'events'\r\nimport { FC, forwardRef, useEffect } from 'react'\r\n\r\ninterface IEventOptions {\r\n message?: string\r\n href?: string\r\n target?: string\r\n rel?: string\r\n}\r\n\r\nexport interface IMfeNavigationEventConfigs {\r\n navigation: [{ routeKey?: string; options?: IEventOptions }]\r\n}\r\n\r\nexport class MfeNavigationEventStore extends EventEmitter<IMfeNavigationEventConfigs> {\r\n constructor() {\r\n super()\r\n }\r\n /**\r\n * Subscribe to a specific channel\r\n * @param channel The channel to subscribe to\r\n * @param callback Function to call when an event occurs on this channel\r\n * @returns Unsubscribe function to remove the event listener\r\n */\r\n _createWrapListener = (callback: (...payload: any[]) => void) => {\r\n return (...payload: any[]) => {\r\n try {\r\n callback(...payload)\r\n } catch (error) {\r\n console.error('Error in MfeBridge listener:', error)\r\n }\r\n }\r\n }\r\n subscribe<K extends keyof IMfeNavigationEventConfigs>(\r\n eventName: K,\r\n listener: K extends keyof IMfeNavigationEventConfigs\r\n ? IMfeNavigationEventConfigs[K] extends unknown[]\r\n ? (...args: IMfeNavigationEventConfigs[K]) => void\r\n : never\r\n : never,\r\n isTry: boolean = true\r\n ) {\r\n const action = isTry ? this._createWrapListener(listener) : listener\r\n super.addListener(eventName, action as any)\r\n return () => {\r\n super.removeListener(eventName, action as any)\r\n }\r\n }\r\n}\r\n\r\nexport function getMfeNavigationEventStore() {\r\n if (typeof globalThis === undefined) return null\r\n\r\n if (typeof (globalThis as any).MfeNavigationEventStore === 'undefined') {\r\n // If MfeNavigationEventStore is not defined globally, define it\r\n // This allows it to be used in other parts of the application\r\n // without needing to import it explicitly\r\n ;(globalThis as any).MfeNavigationEventStore = new MfeNavigationEventStore()\r\n }\r\n const eventEmitter = (globalThis as any).MfeNavigationEventStore as MfeNavigationEventStore\r\n eventEmitter.setMaxListeners(50)\r\n return eventEmitter\r\n}\r\n\r\ntype INavigationFunction = (routeKey?: string, options?: IEventOptions) => void\r\n\r\nexport interface IMfeNavigationProviderProps {\r\n navigation?: INavigationFunction\r\n}\r\n\r\nexport const MfeNavigationProvider: FC<IMfeNavigationProviderProps> = (props) => {\r\n useEffect(() => {\r\n const eventStore = getMfeNavigationEventStore()\r\n if (!eventStore) return\r\n\r\n const unsubscribe = eventStore.subscribe('navigation', (payload) => {\r\n if (props.navigation) {\r\n props.navigation(payload.routeKey, payload.options)\r\n }\r\n })\r\n\r\n return () => {\r\n unsubscribe()\r\n }\r\n }, [])\r\n\r\n return <></>\r\n}\r\n\r\nexport interface IMfeLinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {\r\n routeKey?: string\r\n}\r\n\r\nexport const MfeLink = forwardRef<HTMLAnchorElement, IMfeLinkProps>(({ onClick, routeKey, ...props }, ref) => {\r\n const handleClick = (event: React.MouseEvent<HTMLAnchorElement>) => {\r\n if (onClick) {\r\n onClick(event)\r\n }\r\n if (event.defaultPrevented) {\r\n return // nothing to do if event already handled\r\n }\r\n const eventStore = getMfeNavigationEventStore()\r\n if (eventStore && !!routeKey) {\r\n event.preventDefault() // Prevent default link behavior\r\n event.stopPropagation() // Stop the event from bubbling up\r\n const { target, rel, href } = props\r\n const options: IEventOptions = { message: 'Link clicked' }\r\n if (target) options.target = target\r\n if (rel) options.rel = rel\r\n if (href) options.href = href\r\n eventStore.emit('navigation', { routeKey: routeKey, options })\r\n }\r\n }\r\n return <a {...props} ref={ref} onClick={handleClick} />\r\n})\r\n\r\nexport const mfeNavigation = (routeKey: string, options?: IEventOptions) => {\r\n const eventStore = getMfeNavigationEventStore()\r\n if (eventStore) {\r\n eventStore.emit('navigation', { routeKey: routeKey, options: { message: `Navigating to ${routeKey}`, ...options } })\r\n }\r\n}\r\n"],"names":["MfeNavigationEventStore","_this","_classCallCheck","_callSuper","this","_defineProperty","callback","apply","arguments","error","console","_inherits","EventEmitter","_createClass","key","value","eventName","listener","_this2","action","_createWrapListener","_superPropGet","getMfeNavigationEventStore","undefined","globalThis","_typeof","eventEmitter","setMaxListeners","MfeNavigationProvider","props","useEffect","eventStore","unsubscribe","subscribe","payload","navigation","routeKey","options","_jsx","MfeLink","forwardRef","_ref","ref","onClick","_objectWithoutProperties","_excluded","_objectSpread","event","defaultPrevented","preventDefault","stopPropagation","target","rel","href","message","emit","mfeNavigation","concat"],"mappings":"
|
|
1
|
+
{"version":3,"file":"navigation.js","sources":["../../../src/mfe-shared/navigation.tsx"],"sourcesContent":["import EventEmitter from 'events'\r\nimport { FC, forwardRef, useEffect } from 'react'\r\n\r\nexport type TSite = 'admin' | 'client' | 'music' | 'home' | (string & {})\r\n\r\ninterface IEventOptions {\r\n message?: string\r\n href?: string\r\n target?: string\r\n rel?: string\r\n site?: TSite\r\n}\r\n\r\nexport interface IMfeNavigationEventConfigs {\r\n navigation: [{ routeKey?: string; options?: IEventOptions }]\r\n}\r\n\r\nexport class MfeNavigationEventStore extends EventEmitter<IMfeNavigationEventConfigs> {\r\n constructor() {\r\n super()\r\n }\r\n /**\r\n * Subscribe to a specific channel\r\n * @param channel The channel to subscribe to\r\n * @param callback Function to call when an event occurs on this channel\r\n * @returns Unsubscribe function to remove the event listener\r\n */\r\n _createWrapListener = (callback: (...payload: any[]) => void) => {\r\n return (...payload: any[]) => {\r\n try {\r\n callback(...payload)\r\n } catch (error) {\r\n console.error('Error in MfeBridge listener:', error)\r\n }\r\n }\r\n }\r\n subscribe<K extends keyof IMfeNavigationEventConfigs>(\r\n eventName: K,\r\n listener: K extends keyof IMfeNavigationEventConfigs\r\n ? IMfeNavigationEventConfigs[K] extends unknown[]\r\n ? (...args: IMfeNavigationEventConfigs[K]) => void\r\n : never\r\n : never,\r\n isTry: boolean = true\r\n ) {\r\n const action = isTry ? this._createWrapListener(listener) : listener\r\n super.addListener(eventName, action as any)\r\n return () => {\r\n super.removeListener(eventName, action as any)\r\n }\r\n }\r\n}\r\n\r\nexport function getMfeNavigationEventStore() {\r\n if (typeof globalThis === undefined) return null\r\n\r\n if (typeof (globalThis as any).MfeNavigationEventStore === 'undefined') {\r\n // If MfeNavigationEventStore is not defined globally, define it\r\n // This allows it to be used in other parts of the application\r\n // without needing to import it explicitly\r\n ;(globalThis as any).MfeNavigationEventStore = new MfeNavigationEventStore()\r\n }\r\n const eventEmitter = (globalThis as any).MfeNavigationEventStore as MfeNavigationEventStore\r\n eventEmitter.setMaxListeners(50)\r\n return eventEmitter\r\n}\r\n\r\ntype INavigationFunction = (routeKey?: string, options?: IEventOptions) => void\r\n\r\nexport interface IMfeNavigationProviderProps {\r\n navigation?: INavigationFunction\r\n}\r\n\r\nexport const MfeNavigationProvider: FC<IMfeNavigationProviderProps> = (props) => {\r\n useEffect(() => {\r\n const eventStore = getMfeNavigationEventStore()\r\n if (!eventStore) return\r\n\r\n const unsubscribe = eventStore.subscribe('navigation', (payload) => {\r\n if (props.navigation) {\r\n props.navigation(payload.routeKey, payload.options)\r\n }\r\n })\r\n\r\n return () => {\r\n unsubscribe()\r\n }\r\n }, [])\r\n\r\n return <></>\r\n}\r\n\r\nexport interface IMfeLinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {\r\n routeKey?: string\r\n site?: TSite\r\n}\r\n\r\nexport const MfeLink = forwardRef<HTMLAnchorElement, IMfeLinkProps>(({ onClick, routeKey, site, ...props }, ref) => {\r\n const handleClick = (event: React.MouseEvent<HTMLAnchorElement>) => {\r\n if (onClick) {\r\n onClick(event)\r\n }\r\n if (event.defaultPrevented) {\r\n return // nothing to do if event already handled\r\n }\r\n const eventStore = getMfeNavigationEventStore()\r\n if (eventStore && !!routeKey) {\r\n event.preventDefault() // Prevent default link behavior\r\n event.stopPropagation() // Stop the event from bubbling up\r\n const { target, rel, href } = props\r\n const options: IEventOptions = { message: 'Link clicked' }\r\n if (target) options.target = target\r\n if (rel) options.rel = rel\r\n if (href) options.href = href\r\n if (site) options.site = site\r\n eventStore.emit('navigation', { routeKey: routeKey, options })\r\n }\r\n }\r\n return <a {...props} ref={ref} onClick={handleClick} />\r\n})\r\n\r\nexport const mfeNavigation = (routeKey: string, options?: IEventOptions) => {\r\n const eventStore = getMfeNavigationEventStore()\r\n if (eventStore) {\r\n eventStore.emit('navigation', { routeKey: routeKey, options: { message: `Navigating to ${routeKey}`, ...options } })\r\n }\r\n}\r\n"],"names":["MfeNavigationEventStore","_this","_classCallCheck","_callSuper","this","_defineProperty","callback","apply","arguments","error","console","_inherits","EventEmitter","_createClass","key","value","eventName","listener","_this2","action","_createWrapListener","_superPropGet","getMfeNavigationEventStore","undefined","globalThis","_typeof","eventEmitter","setMaxListeners","MfeNavigationProvider","props","useEffect","eventStore","unsubscribe","subscribe","payload","navigation","routeKey","options","_jsx","MfeLink","forwardRef","_ref","ref","onClick","site","_objectWithoutProperties","_excluded","_objectSpread","event","defaultPrevented","preventDefault","stopPropagation","target","rel","href","message","emit","mfeNavigation","concat"],"mappings":"+XAiBaA,aACX,SAAAA,IAAA,IAAAC,EAiBC,OAjBDC,OAAAF,GACEC,EAAAE,EAAAC,KAAAJ,GAEFK,EAAAJ,EAMsB,sBAAA,SAACK,GACrB,OAAO,WACL,IACEA,EAAQC,WAAAC,EAAAA,UACT,CAAC,MAAOC,GACPC,QAAQD,MAAM,+BAAgCA,EAC/C,CACF,IACFR,CAfD,CAAC,OAAAU,EAAAX,EAH0CY,GAG1CC,EAAAb,EAAA,CAAA,CAAAc,IAAA,YAAAC,MAgBD,SACEC,EACAC,GAKqB,IAAAC,EAAAd,KAEfe,6DAAiBf,KAAKgB,oBAAoBH,GAAYA,EAE5D,OADAI,EAAArB,EAAkBgB,cAAAA,KAAlBK,CAAkBL,CAAAA,EAAWG,IACtB,WACLE,EAAArB,EAAA,iBAAAkB,EAAAG,CAAqBL,CAAAA,EAAWG,GACjC,CACH,IAAC,aAGaG,IACd,QAA0BC,KAAL,oBAAVC,WAAU,YAAAC,EAAVD,aAA0B,OAAO,UAEe,IAA/CA,WAAmBxB,0BAI3BwB,WAAmBxB,wBAA0B,IAAIA,GAErD,IAAM0B,EAAgBF,WAAmBxB,wBAEzC,OADA0B,EAAaC,gBAAgB,IACtBD,CACT,KAQaE,EAAyD,SAACC,GAgBrE,OAfAC,EAAU,WACR,IAAMC,EAAaT,IACnB,GAAKS,EAAL,CAEA,IAAMC,EAAcD,EAAWE,UAAU,aAAc,SAACC,GAClDL,EAAMM,YACRN,EAAMM,WAAWD,EAAQE,SAAUF,EAAQG,QAE/C,GAEA,OAAO,WACLL,GACD,CAVgB,CAWlB,EAAE,IAEIM,OACT,EAOaC,EAAUC,EAA6C,SAAAC,EAAwCC,GAAO,IAA5CC,EAAOF,EAAPE,QAASP,EAAQK,EAARL,SAAUQ,EAAIH,EAAJG,KAASf,EAAKgB,EAAAJ,EAAAK,GAqBtG,OAAOR,EAAA,IAAAS,EAAAA,KAAOlB,GAAK,GAAA,CAAEa,IAAKA,EAAKC,QApBX,SAACK,GAInB,GAHIL,GACFA,EAAQK,IAENA,EAAMC,iBAAV,CAGA,IAAMlB,EAAaT,IACnB,GAAIS,GAAgBK,EAAU,CAC5BY,EAAME,iBACNF,EAAMG,kBACN,IAAQC,EAAsBvB,EAAtBuB,OAAQC,EAAcxB,EAAdwB,IAAKC,EAASzB,EAATyB,KACfjB,EAAyB,CAAEkB,QAAS,gBACtCH,IAAQf,EAAQe,OAASA,GACzBC,IAAKhB,EAAQgB,IAAMA,GACnBC,IAAMjB,EAAQiB,KAAOA,GACrBV,IAAMP,EAAQO,KAAOA,GACzBb,EAAWyB,KAAK,aAAc,CAAEpB,SAAUA,EAAUC,QAAAA,GACrD,CAZA,CAaF,IAEH,GAEaoB,EAAgB,SAACrB,EAAkBC,GAC9C,IAAMN,EAAaT,IACfS,GACFA,EAAWyB,KAAK,aAAc,CAAEpB,SAAUA,EAAUC,QAAOU,EAAA,CAAIQ,QAAO,iBAAAG,OAAmBtB,IAAeC,IAE5G"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import EventEmitter from 'events';
|
|
3
3
|
import { FC } from 'react';
|
|
4
|
+
export type TSite = 'admin' | 'client' | 'music' | 'home' | (string & {});
|
|
4
5
|
interface IEventOptions {
|
|
5
6
|
message?: string;
|
|
6
7
|
href?: string;
|
|
7
8
|
target?: string;
|
|
8
9
|
rel?: string;
|
|
10
|
+
site?: TSite;
|
|
9
11
|
}
|
|
10
12
|
export interface IMfeNavigationEventConfigs {
|
|
11
13
|
navigation: [{
|
|
@@ -32,6 +34,7 @@ export interface IMfeNavigationProviderProps {
|
|
|
32
34
|
export declare const MfeNavigationProvider: FC<IMfeNavigationProviderProps>;
|
|
33
35
|
export interface IMfeLinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
34
36
|
routeKey?: string;
|
|
37
|
+
site?: TSite;
|
|
35
38
|
}
|
|
36
39
|
export declare const MfeLink: import("react").ForwardRefExoticComponent<IMfeLinkProps & import("react").RefAttributes<HTMLAnchorElement>>;
|
|
37
40
|
export declare const mfeNavigation: (routeKey: string, options?: IEventOptions) => void;
|