@teambit/pubsub 0.0.657 → 0.0.660

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.
@@ -11,4 +11,4 @@ export declare function createProvider(pubSubContext: PubSubRegistry): ({ childr
11
11
  children: ReactNode;
12
12
  }) => JSX.Element;
13
13
  export declare function usePubSub(): PubSubRegistry | undefined;
14
- export declare function usePubSubIframe(ref: RefObject<HTMLIFrameElement>): void;
14
+ export declare function usePubSubIframe(ref?: RefObject<HTMLIFrameElement>): void;
@@ -42,10 +42,10 @@ function usePubSub() {
42
42
  function usePubSubIframe(ref) {
43
43
  const pubSub = usePubSub();
44
44
  (0, _react().useEffect)(() => {
45
- if (!ref.current || !pubSub) return () => {};
45
+ if (!(ref !== null && ref !== void 0 && ref.current) || !pubSub) return () => {};
46
46
  const destroyConnection = pubSub.connect(ref.current);
47
47
  return () => destroyConnection();
48
- }, [ref.current, pubSub]);
48
+ }, [ref === null || ref === void 0 ? void 0 : ref.current, pubSub]);
49
49
  }
50
50
 
51
51
  //# sourceMappingURL=pubsub-context.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["pubsub-context.tsx"],"names":["pubsubRegistry","undefined","createProvider","pubSubContext","PubSubProvider","children","usePubSub","usePubSubIframe","ref","pubSub","current","destroyConnection","connect"],"mappings":";;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;AAUO,MAAMA,cAAc,gBAAG,4BAA0CC,SAA1C,CAAvB;;;AAEA,SAASC,cAAT,CAAwBC,aAAxB,EAAuD;AAC5D,QAAMC,cAAc,GAAG,CAAC;AAAEC,IAAAA;AAAF,GAAD,kBACrB,+BAAC,cAAD,CAAgB,QAAhB;AAAyB,IAAA,KAAK,EAAEF;AAAhC,KAAgDE,QAAhD,CADF;;AAIA,SAAOD,cAAP;AACD;;AAEM,SAASE,SAAT,GAAqB;AAC1B,SAAO,yBAAWN,cAAX,CAAP;AACD;;AAEM,SAASO,eAAT,CAAyBC,GAAzB,EAA4D;AACjE,QAAMC,MAAM,GAAGH,SAAS,EAAxB;AAEA,0BAAU,MAAM;AACd,QAAI,CAACE,GAAG,CAACE,OAAL,IAAgB,CAACD,MAArB,EAA6B,OAAO,MAAM,CAAE,CAAf;AAE7B,UAAME,iBAAiB,GAAGF,MAAM,CAACG,OAAP,CAAeJ,GAAG,CAACE,OAAnB,CAA1B;AACA,WAAO,MAAMC,iBAAiB,EAA9B;AACD,GALD,EAKG,CAACH,GAAG,CAACE,OAAL,EAAcD,MAAd,CALH;AAMD","sourcesContent":["import React, { createContext, useContext, useEffect, RefObject, ReactNode } from 'react';\n\nexport interface PubSubRegistry {\n /**\n * starts a connection to an iframe child.\n * Returns a destroy() function that will break the connection.\n */\n connect(ref: HTMLIFrameElement): () => void;\n}\n\nexport const pubsubRegistry = createContext<PubSubRegistry | undefined>(undefined);\n\nexport function createProvider(pubSubContext: PubSubRegistry) {\n const PubSubProvider = ({ children }: { children: ReactNode }) => (\n <pubsubRegistry.Provider value={pubSubContext}>{children}</pubsubRegistry.Provider>\n );\n\n return PubSubProvider;\n}\n\nexport function usePubSub() {\n return useContext(pubsubRegistry);\n}\n\nexport function usePubSubIframe(ref: RefObject<HTMLIFrameElement>) {\n const pubSub = usePubSub();\n\n useEffect(() => {\n if (!ref.current || !pubSub) return () => {};\n\n const destroyConnection = pubSub.connect(ref.current);\n return () => destroyConnection();\n }, [ref.current, pubSub]);\n}\n"]}
1
+ {"version":3,"sources":["pubsub-context.tsx"],"names":["pubsubRegistry","undefined","createProvider","pubSubContext","PubSubProvider","children","usePubSub","usePubSubIframe","ref","pubSub","current","destroyConnection","connect"],"mappings":";;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;AAUO,MAAMA,cAAc,gBAAG,4BAA0CC,SAA1C,CAAvB;;;AAEA,SAASC,cAAT,CAAwBC,aAAxB,EAAuD;AAC5D,QAAMC,cAAc,GAAG,CAAC;AAAEC,IAAAA;AAAF,GAAD,kBACrB,+BAAC,cAAD,CAAgB,QAAhB;AAAyB,IAAA,KAAK,EAAEF;AAAhC,KAAgDE,QAAhD,CADF;;AAIA,SAAOD,cAAP;AACD;;AAEM,SAASE,SAAT,GAAqB;AAC1B,SAAO,yBAAWN,cAAX,CAAP;AACD;;AAEM,SAASO,eAAT,CAAyBC,GAAzB,EAA6D;AAClE,QAAMC,MAAM,GAAGH,SAAS,EAAxB;AAEA,0BAAU,MAAM;AACd,QAAI,EAACE,GAAD,aAACA,GAAD,eAACA,GAAG,CAAEE,OAAN,KAAiB,CAACD,MAAtB,EAA8B,OAAO,MAAM,CAAE,CAAf;AAE9B,UAAME,iBAAiB,GAAGF,MAAM,CAACG,OAAP,CAAeJ,GAAG,CAACE,OAAnB,CAA1B;AACA,WAAO,MAAMC,iBAAiB,EAA9B;AACD,GALD,EAKG,CAACH,GAAD,aAACA,GAAD,uBAACA,GAAG,CAAEE,OAAN,EAAeD,MAAf,CALH;AAMD","sourcesContent":["import React, { createContext, useContext, useEffect, RefObject, ReactNode } from 'react';\n\nexport interface PubSubRegistry {\n /**\n * starts a connection to an iframe child.\n * Returns a destroy() function that will break the connection.\n */\n connect(ref: HTMLIFrameElement): () => void;\n}\n\nexport const pubsubRegistry = createContext<PubSubRegistry | undefined>(undefined);\n\nexport function createProvider(pubSubContext: PubSubRegistry) {\n const PubSubProvider = ({ children }: { children: ReactNode }) => (\n <pubsubRegistry.Provider value={pubSubContext}>{children}</pubsubRegistry.Provider>\n );\n\n return PubSubProvider;\n}\n\nexport function usePubSub() {\n return useContext(pubsubRegistry);\n}\n\nexport function usePubSubIframe(ref?: RefObject<HTMLIFrameElement>) {\n const pubSub = usePubSub();\n\n useEffect(() => {\n if (!ref?.current || !pubSub) return () => {};\n\n const destroyConnection = pubSub.connect(ref.current);\n return () => destroyConnection();\n }, [ref?.current, pubSub]);\n}\n"]}
@@ -100,11 +100,10 @@ class PubsubUI {
100
100
  methods: {
101
101
  pub: this.emitEvent
102
102
  }
103
- }); // absorb valid errors like 'connection destroyed'
104
-
105
- connection.promise.then(childConnection => this.childApi = childConnection).catch(() => {
103
+ });
104
+ connection.promise.then(childConnection => this.childApi = childConnection).catch(err => {
106
105
  // eslint-disable-next-line no-console
107
- console.error('[Pubsub.ui]', 'failed connecting to child iframe');
106
+ console.error('[Pubsub.ui]', 'failed connecting to child iframe:', err);
108
107
  });
109
108
 
110
109
  const destroy = () => {
@@ -1 +1 @@
1
- {"version":3,"sources":["pubsub.ui.runtime.ts"],"names":["PubsubUI","EventEmitter2","topic","callback","events","on","unSub","off","event","propagate","emitEvent","pubToChild","iframe","connection","methods","pub","promise","then","childConnection","childApi","catch","console","error","destroy","emit","provider","uiUI","pubsubUI","reactContext","connect","connectToIframe","registerRenderHooks","UIRuntime","UIAspect","PubsubAspect","addRuntime"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAWO,MAAMA,QAAN,CAAe;AAAA;AAAA;AAAA,oDAEH,KAAIC,6BAAJ,GAFG;AAAA,iDAOP,CAACC,KAAD,EAAgBC,QAAhB,KAAuC;AAClD,YAAMC,MAAM,GAAG,KAAKA,MAApB;AACAA,MAAAA,MAAM,CAACC,EAAP,CAAUH,KAAV,EAAiBC,QAAjB;;AAEA,YAAMG,KAAK,GAAG,MAAM;AAClBF,QAAAA,MAAM,CAACG,GAAP,CAAWL,KAAX,EAAkBC,QAAlB;AACD,OAFD;;AAIA,aAAOG,KAAP;AACD,KAhBmB;AAAA,iDAqBP,CAACJ,KAAD,EAAgBM,KAAhB,EAA0C;AAAEC,MAAAA;AAAF,QAA4B,EAAtE,KAA6E;AACx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AP;AACD;;AA/EmB;;;gCAAT3B,Q,aAkEMgC,e;gCAlENhC,Q,kBAmEW,CAACiC,cAAD,C;;AAexBC,uBAAaC,UAAb,CAAwBnC,QAAxB","sourcesContent":["import { UIRuntime, UIAspect, UiUI } from '@teambit/ui';\nimport { EventEmitter2 } from 'eventemitter2';\nimport { connectToChild } from 'penpal';\nimport type { AsyncMethodReturns } from 'penpal/lib/types';\nimport { BitBaseEvent } from './bit-base-event';\nimport { PubsubAspect } from './pubsub.aspect';\nimport { createProvider } from './pubsub-context';\nimport { Callback } from './types';\n\ntype PubOptions = {\n /** forward the event to adjacent windows (including the preview iframe) */\n propagate?: boolean;\n};\n\ntype ChildMethods = {\n pub: (topic: string, event: BitBaseEvent<any>) => any;\n};\nexport class PubsubUI {\n private childApi?: AsyncMethodReturns<ChildMethods>;\n private events = new EventEmitter2();\n\n /**\n * subscribe to events\n */\n public sub = (topic: string, callback: Callback) => {\n const events = this.events;\n events.on(topic, callback);\n\n const unSub = () => {\n events.off(topic, callback);\n };\n\n return unSub;\n };\n\n /**\n * publish event to all subscribers, including nested iframes.\n */\n public pub = (topic: string, event: BitBaseEvent<any>, { propagate }: PubOptions = {}) => {\n this.emitEvent(topic, event);\n\n // opt-in to forward to iframe, as we would not want 'private' messages automatically passing to iframe\n if (propagate) {\n this.pubToChild(topic, event);\n }\n };\n\n private connectToIframe = (iframe: HTMLIFrameElement) => {\n const connection = connectToChild<ChildMethods>({\n iframe,\n methods: {\n pub: this.emitEvent,\n },\n });\n\n // absorb valid errors like 'connection destroyed'\n connection.promise\n .then((childConnection) => (this.childApi = childConnection))\n .catch(() => {\n // eslint-disable-next-line no-console\n console.error('[Pubsub.ui]', 'failed connecting to child iframe');\n });\n\n const destroy = () => {\n connection && connection.destroy();\n };\n return destroy;\n };\n\n /**\n * publish event to all subscribers in this window\n */\n private emitEvent = (topic: string, event: BitBaseEvent<any>) => {\n this.events.emit(topic, event);\n };\n\n /**\n * publish event to nested iframes\n */\n private pubToChild = (topic: string, event: BitBaseEvent<any>) => {\n return this.childApi?.pub(topic, event);\n };\n\n static runtime = UIRuntime;\n static dependencies = [UIAspect];\n\n static async provider([uiUI]: [UiUI]) {\n const pubsubUI = new PubsubUI();\n\n const reactContext = createProvider({\n connect: pubsubUI.connectToIframe,\n });\n\n uiUI.registerRenderHooks({ reactContext });\n\n return pubsubUI;\n }\n}\n\nPubsubAspect.addRuntime(PubsubUI);\n"]}
1
+ {"version":3,"sources":["pubsub.ui.runtime.ts"],"names":["PubsubUI","EventEmitter2","topic","callback","events","on","unSub","off","event","propagate","emitEvent","pubToChild","iframe","connection","methods","pub","promise","then","childConnection","childApi","catch","err","console","error","destroy","emit","provider","uiUI","pubsubUI","reactContext","connect","connectToIframe","registerRenderHooks","UIRuntime","UIAspect","PubsubAspect","addRuntime"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAWO,MAAMA,QAAN,CAAe;AAAA;AAAA;AAAA,oDAEH,KAAIC,6BAAJ,GAFG;AAAA,iDAOP,CAACC,KAAD,EAAgBC,QAAhB,KAAuC;AAClD,YAAMC,MAAM,GAAG,KAAKA,MAApB;AACAA,MAAAA,MAAM,CAACC,EAAP,CAAUH,KAAV,EAAiBC,QAAjB;;AAEA,YAAMG,KAAK,GAAG,MAAM;AAClBF,QAAAA,MAAM,CAACG,GAAP,CAAWL,KAAX,EAAkBC,QAAlB;AACD,OAFD;;AAIA,aAAOG,KAAP;AACD,KAhBmB;AAAA,iDAqBP,CAACJ,KAAD,EAAgBM,KAAhB,EAA0C;AAAEC,MAAAA;AAAF,QAA4B,EAAtE,KAA6E;AACxF,WAAKC,SAAL,C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D;;AA9EmB;;;gCAAT5B,Q,aAiEMiC,e;gCAjENjC,Q,kBAkEW,CAACkC,cAAD,C;;AAexBC,uBAAaC,UAAb,CAAwBpC,QAAxB","sourcesContent":["import { UIRuntime, UIAspect, UiUI } from '@teambit/ui';\nimport { EventEmitter2 } from 'eventemitter2';\nimport { connectToChild } from 'penpal';\nimport type { AsyncMethodReturns } from 'penpal/lib/types';\nimport { BitBaseEvent } from './bit-base-event';\nimport { PubsubAspect } from './pubsub.aspect';\nimport { createProvider } from './pubsub-context';\nimport { Callback } from './types';\n\ntype PubOptions = {\n /** forward the event to adjacent windows (including the preview iframe) */\n propagate?: boolean;\n};\n\ntype ChildMethods = {\n pub: (topic: string, event: BitBaseEvent<any>) => any;\n};\nexport class PubsubUI {\n private childApi?: AsyncMethodReturns<ChildMethods>;\n private events = new EventEmitter2();\n\n /**\n * subscribe to events\n */\n public sub = (topic: string, callback: Callback) => {\n const events = this.events;\n events.on(topic, callback);\n\n const unSub = () => {\n events.off(topic, callback);\n };\n\n return unSub;\n };\n\n /**\n * publish event to all subscribers, including nested iframes.\n */\n public pub = (topic: string, event: BitBaseEvent<any>, { propagate }: PubOptions = {}) => {\n this.emitEvent(topic, event);\n\n // opt-in to forward to iframe, as we would not want 'private' messages automatically passing to iframe\n if (propagate) {\n this.pubToChild(topic, event);\n }\n };\n\n private connectToIframe = (iframe: HTMLIFrameElement) => {\n const connection = connectToChild<ChildMethods>({\n iframe,\n methods: {\n pub: this.emitEvent,\n },\n });\n\n connection.promise\n .then((childConnection) => (this.childApi = childConnection))\n .catch((err) => {\n // eslint-disable-next-line no-console\n console.error('[Pubsub.ui]', 'failed connecting to child iframe:', err);\n });\n\n const destroy = () => {\n connection && connection.destroy();\n };\n return destroy;\n };\n\n /**\n * publish event to all subscribers in this window\n */\n private emitEvent = (topic: string, event: BitBaseEvent<any>) => {\n this.events.emit(topic, event);\n };\n\n /**\n * publish event to nested iframes\n */\n private pubToChild = (topic: string, event: BitBaseEvent<any>) => {\n return this.childApi?.pub(topic, event);\n };\n\n static runtime = UIRuntime;\n static dependencies = [UIAspect];\n\n static async provider([uiUI]: [UiUI]) {\n const pubsubUI = new PubsubUI();\n\n const reactContext = createProvider({\n connect: pubsubUI.connectToIframe,\n });\n\n uiUI.registerRenderHooks({ reactContext });\n\n return pubsubUI;\n }\n}\n\nPubsubAspect.addRuntime(PubsubUI);\n"]}
package/package.json CHANGED
@@ -1,23 +1,23 @@
1
1
  {
2
2
  "name": "@teambit/pubsub",
3
- "version": "0.0.657",
3
+ "version": "0.0.660",
4
4
  "homepage": "https://bit.dev/teambit/harmony/pubsub",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.harmony",
8
8
  "name": "pubsub",
9
- "version": "0.0.657"
9
+ "version": "0.0.660"
10
10
  },
11
11
  "dependencies": {
12
12
  "@teambit/harmony": "0.2.11",
13
13
  "eventemitter2": "6.4.4",
14
- "penpal": "5.3.0",
14
+ "penpal": "6.2.1",
15
15
  "@babel/runtime": "7.12.18",
16
16
  "core-js": "^3.0.0",
17
- "@teambit/cli": "0.0.448",
18
- "@teambit/preview": "0.0.657",
17
+ "@teambit/cli": "0.0.449",
18
+ "@teambit/preview": "0.0.660",
19
19
  "@teambit/ui-foundation.ui.is-browser": "0.0.486",
20
- "@teambit/ui": "0.0.657"
20
+ "@teambit/ui": "0.0.660"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/react": "^17.0.8",
@@ -28,7 +28,7 @@
28
28
  "@types/node": "12.20.4"
29
29
  },
30
30
  "peerDependencies": {
31
- "@teambit/legacy": "1.0.227",
31
+ "@teambit/legacy": "1.0.228",
32
32
  "react-dom": "^16.8.0 || ^17.0.0",
33
33
  "react": "^16.8.0 || ^17.0.0"
34
34
  },
@@ -56,7 +56,7 @@
56
56
  "react": "-"
57
57
  },
58
58
  "peerDependencies": {
59
- "@teambit/legacy": "1.0.227",
59
+ "@teambit/legacy": "1.0.228",
60
60
  "react-dom": "^16.8.0 || ^17.0.0",
61
61
  "react": "^16.8.0 || ^17.0.0"
62
62
  }
@@ -22,13 +22,13 @@ export function usePubSub() {
22
22
  return useContext(pubsubRegistry);
23
23
  }
24
24
 
25
- export function usePubSubIframe(ref: RefObject<HTMLIFrameElement>) {
25
+ export function usePubSubIframe(ref?: RefObject<HTMLIFrameElement>) {
26
26
  const pubSub = usePubSub();
27
27
 
28
28
  useEffect(() => {
29
- if (!ref.current || !pubSub) return () => {};
29
+ if (!ref?.current || !pubSub) return () => {};
30
30
 
31
31
  const destroyConnection = pubSub.connect(ref.current);
32
32
  return () => destroyConnection();
33
- }, [ref.current, pubSub]);
33
+ }, [ref?.current, pubSub]);
34
34
  }