@teambit/pubsub 1.0.108 → 1.0.109

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.
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["teambit.harmony/pubsub-preview"]=t():e["teambit.harmony/pubsub-preview"]=t()}(self,(()=>(()=>{"use strict";var e={98622:(e,t,o)=>{var r={id:"teambit.harmony/pubsub@1.0.109",homepage:"https://bit.cloud/teambit/harmony/pubsub",exported:!0};function n(){const e=i(o(87363));return n=function(){return e},e}function i(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.Logo=void 0,n.__bit_component=r,i.__bit_component=r;const p=()=>n().default.createElement("div",{style:{height:"100%",display:"flex",justifyContent:"center"}},n().default.createElement("img",{style:{width:70},src:"https://static.bit.dev/extensions-icons/pubsub.svg"}));p.__bit_component=r,t.Logo=p},87363:e=>{e.exports=React}},t={};function o(r){var n=t[r];if(void 0!==n)return n.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,o),i.exports}o.d=(e,t)=>{for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{o.r(r),o.d(r,{compositions:()=>d,compositions_metadata:()=>f,overview:()=>b});var e={};o.r(e),o.d(e,{default:()=>u});var t=o(98622);o(87363);const n=MdxJsReact,i=TeambitMdxUiMdxScopeContext;var p=["components"];function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(e[r]=o[r])}return e},a.apply(this,arguments)}var s={},c="wrapper";function u(e){var t=e.components,o=function(e,t){if(null==e)return{};var o,r,n=function(e,t){if(null==e)return{};var o,r,n={},i=Object.keys(e);for(r=0;r<i.length;r++)o=i[r],t.indexOf(o)>=0||(n[o]=e[o]);return n}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)o=i[r],t.indexOf(o)>=0||Object.prototype.propertyIsEnumerable.call(e,o)&&(n[o]=e[o])}return n}(e,p);return(0,n.mdx)(c,a({},s,o,{components:t,mdxType:"MDXLayout"}),(0,n.mdx)(i.MDXScopeProvider,{components:{},mdxType:"MDXScopeProvider"}))}u.isMDXComponent=!0;const d=[t],b=[e],f={compositions:[{displayName:"Logo",identifier:"Logo"}]}})(),r})()));
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_pubsub@1.0.108/dist/pubsub.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_pubsub@1.0.108/dist/pubsub.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_pubsub@1.0.109/dist/pubsub.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_pubsub@1.0.109/dist/pubsub.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
package/package.json CHANGED
@@ -1,27 +1,27 @@
1
1
  {
2
2
  "name": "@teambit/pubsub",
3
- "version": "1.0.108",
3
+ "version": "1.0.109",
4
4
  "homepage": "https://bit.cloud/teambit/harmony/pubsub",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.harmony",
8
8
  "name": "pubsub",
9
- "version": "1.0.108"
9
+ "version": "1.0.109"
10
10
  },
11
11
  "dependencies": {
12
12
  "eventemitter2": "6.4.4",
13
13
  "penpal": "6.2.2",
14
14
  "@teambit/harmony": "0.4.6",
15
- "@teambit/cli": "0.0.840",
16
- "@teambit/ui": "1.0.108"
15
+ "@teambit/cli": "0.0.841",
16
+ "@teambit/ui": "1.0.109"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@types/mocha": "9.1.0",
20
20
  "@types/jest": "^29.2.2",
21
21
  "@types/testing-library__jest-dom": "^5.9.5",
22
22
  "@teambit/ui-foundation.ui.is-browser": "0.0.500",
23
- "@teambit/harmony.envs.core-aspect-env": "0.0.13",
24
- "@teambit/preview": "1.0.108"
23
+ "@teambit/harmony.envs.core-aspect-env": "0.0.14",
24
+ "@teambit/preview": "1.0.109"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "react": "^17.0.0 || ^18.0.0",
package/bit-base-event.ts DELETED
@@ -1,3 +0,0 @@
1
- export class BitBaseEvent<T> {
2
- constructor(readonly type: string, readonly version: string, readonly timestamp: number, readonly data: T) {}
3
- }
package/index.ts DELETED
@@ -1,8 +0,0 @@
1
- export { PubsubAspect, PubsubAspect as default } from './pubsub.aspect';
2
-
3
- export type { PubsubMain } from './pubsub.main.runtime';
4
- export type { PubsubPreview } from './pubsub.preview.runtime';
5
- export type { PubsubUI } from './pubsub.ui.runtime';
6
- export { BitBaseEvent } from './bit-base-event';
7
- export type { PubSubRegistry } from './pubsub-context';
8
- export { usePubSub, usePubSubIframe } from './pubsub-context';
@@ -1,6 +0,0 @@
1
- export class PubSubNoParentError extends Error {
2
- constructor() {
3
- super('could not connect to parent window');
4
- this.name = 'PubSubNoParentError';
5
- }
6
- }
package/pubsub.aspect.ts DELETED
@@ -1,8 +0,0 @@
1
- import { Aspect } from '@teambit/harmony';
2
-
3
- export const PubsubAspect = Aspect.create({
4
- id: 'teambit.harmony/pubsub',
5
- dependencies: [],
6
- });
7
-
8
- export default PubsubAspect;
@@ -1,34 +0,0 @@
1
- import { MainRuntime } from '@teambit/cli';
2
-
3
- import { BitBaseEvent } from './bit-base-event';
4
- import { PubsubAspect } from './pubsub.aspect';
5
-
6
- export class PubsubMain {
7
- private topicMap = {};
8
-
9
- private createOrGetTopic = (topicUUID) => {
10
- this.topicMap[topicUUID] = this.topicMap[topicUUID] || [];
11
- };
12
-
13
- public sub(topicUUID, callback) {
14
- this.createOrGetTopic(topicUUID);
15
- this.topicMap[topicUUID].push(callback);
16
- }
17
-
18
- public pub(topicUUID, event: BitBaseEvent<any>) {
19
- this.createOrGetTopic(topicUUID);
20
- this.topicMap[topicUUID].forEach((callback) => callback(event));
21
- }
22
-
23
- unsubscribeAll(topicId: string) {
24
- delete this.topicMap[topicId];
25
- }
26
-
27
- static runtime = MainRuntime;
28
-
29
- static async provider() {
30
- return new PubsubMain();
31
- }
32
- }
33
-
34
- PubsubAspect.addRuntime(PubsubMain);
@@ -1,90 +0,0 @@
1
- /**
2
- * Please Notice: This file will run in the preview iframe.
3
- */
4
-
5
- import { PreviewRuntime } from '@teambit/preview';
6
- import { isBrowser } from '@teambit/ui-foundation.ui.is-browser';
7
-
8
- import { EventEmitter2 } from 'eventemitter2';
9
- import { connectToParent, ErrorCode } from 'penpal';
10
-
11
- import { BitBaseEvent } from './bit-base-event';
12
- import { PubSubNoParentError } from './no-parent-error';
13
- import { PubsubAspect } from './pubsub.aspect';
14
- import { Callback } from './types';
15
-
16
- type ParentMethods = {
17
- pub: (topic: string, event: BitBaseEvent<any>) => Promise<any>;
18
- };
19
-
20
- export class PubsubPreview {
21
- private _parentPubsub?: ParentMethods;
22
- private events = new EventEmitter2();
23
-
24
- public sub(topic: string, callback: Callback) {
25
- const emitter = this.events;
26
- emitter.on(topic, callback);
27
-
28
- const unSub = () => {
29
- emitter.off(topic, callback);
30
- };
31
- return unSub;
32
- }
33
-
34
- public pub(topic: string, event: BitBaseEvent<any>) {
35
- this.events.emit(topic, event);
36
- this._parentPubsub?.pub(topic, event).catch((err) => {
37
- // eslint-disable-next-line no-console
38
- console.error('[Pubsub.preview]', err);
39
- });
40
- }
41
-
42
- private inIframe() {
43
- try {
44
- return isBrowser && window.self !== window.top;
45
- } catch (e: any) {
46
- return false;
47
- }
48
- }
49
-
50
- private connectToParentPubSub = (retries = 10): Promise<ParentMethods | undefined> => {
51
- if (retries <= 0) throw new PubSubNoParentError();
52
-
53
- return connectToParent<ParentMethods>({
54
- timeout: 300,
55
- methods: {
56
- pub: this.handleMessageFromParent,
57
- },
58
- })
59
- .promise.then((parentPubsub) => (this._parentPubsub = parentPubsub))
60
- .catch((e: any) => {
61
- if (e.code !== ErrorCode.ConnectionTimeout) throw e;
62
-
63
- return this.connectToParentPubSub(retries - 1);
64
- });
65
- };
66
-
67
- private handleMessageFromParent = (topic: string, message: BitBaseEvent<any>) => {
68
- this.events.emit(topic, message);
69
- };
70
-
71
- static runtime = PreviewRuntime;
72
-
73
- static async provider(): Promise<PubsubPreview> {
74
- const pubsubPreview = new PubsubPreview();
75
-
76
- if (pubsubPreview.inIframe()) {
77
- pubsubPreview.connectToParentPubSub().catch((err) => {
78
- // parent window is not required to accept connections
79
- if (err instanceof PubSubNoParentError) return;
80
-
81
- // eslint-disable-next-line no-console
82
- console.error('[Pubsub.preview]', err);
83
- });
84
- }
85
-
86
- return pubsubPreview;
87
- }
88
- }
89
-
90
- PubsubAspect.addRuntime(PubsubPreview);
@@ -1,103 +0,0 @@
1
- import { UIRuntime, UIAspect, UiUI } from '@teambit/ui';
2
- import { EventEmitter2 } from 'eventemitter2';
3
- import { connectToChild } from 'penpal';
4
- import type { AsyncMethodReturns } from 'penpal/lib/types';
5
- import { BitBaseEvent } from './bit-base-event';
6
- import { PubsubAspect } from './pubsub.aspect';
7
- import { createProvider } from './pubsub-context';
8
- import { Callback } from './types';
9
-
10
- type PubOptions = {
11
- /** forward the event to adjacent windows (including the preview iframe) */
12
- propagate?: boolean;
13
- };
14
-
15
- type ChildMethods = {
16
- pub: (topic: string, event: BitBaseEvent<any>) => any;
17
- };
18
- export class PubsubUI {
19
- private childApi?: AsyncMethodReturns<ChildMethods>;
20
- private events = new EventEmitter2();
21
-
22
- /**
23
- * subscribe to events
24
- */
25
- public sub = (topic: string, callback: Callback) => {
26
- const events = this.events;
27
- events.on(topic, callback);
28
-
29
- const unSub = () => {
30
- events.off(topic, callback);
31
- };
32
-
33
- return unSub;
34
- };
35
-
36
- /**
37
- * publish event to all subscribers, including nested iframes.
38
- */
39
- public pub = (topic: string, event: BitBaseEvent<any>, { propagate }: PubOptions = {}) => {
40
- this.emitEvent(topic, event);
41
-
42
- // opt-in to forward to iframe, as we would not want 'private' messages automatically passing to iframe
43
- if (propagate) {
44
- this.pubToChild(topic, event);
45
- }
46
- };
47
-
48
- private connectToIframe = (iframe: HTMLIFrameElement) => {
49
- const connection = connectToChild<ChildMethods>({
50
- iframe,
51
- methods: {
52
- pub: this.emitEvent,
53
- },
54
- });
55
-
56
- connection.promise
57
- .then((childConnection) => (this.childApi = childConnection))
58
- .catch((err) => {
59
- // eslint-disable-next-line no-console
60
- console.error('[Pubsub.ui]', 'failed connecting to child iframe:', err);
61
- });
62
-
63
- const destroy = () => {
64
- connection && connection.destroy();
65
- };
66
- return destroy;
67
- };
68
-
69
- getPubSubContext() {
70
- return createProvider({
71
- connect: this.connectToIframe,
72
- });
73
- }
74
-
75
- /**
76
- * publish event to all subscribers in this window
77
- */
78
- private emitEvent = (topic: string, event: BitBaseEvent<any>) => {
79
- this.events.emit(topic, event);
80
- };
81
-
82
- /**
83
- * publish event to nested iframes
84
- */
85
- private pubToChild = (topic: string, event: BitBaseEvent<any>) => {
86
- return this.childApi?.pub(topic, event);
87
- };
88
-
89
- static runtime = UIRuntime;
90
- static dependencies = [UIAspect];
91
-
92
- static async provider([uiUI]: [UiUI]) {
93
- const pubsubUI = new PubsubUI();
94
-
95
- const reactContext = pubsubUI.getPubSubContext();
96
-
97
- if (uiUI) uiUI.registerRenderHooks({ reactContext });
98
-
99
- return pubsubUI;
100
- }
101
- }
102
-
103
- PubsubAspect.addRuntime(PubsubUI);
package/types.ts DELETED
@@ -1,3 +0,0 @@
1
- import { BitBaseEvent } from './bit-base-event';
2
-
3
- export type Callback = (event: BitBaseEvent<any>) => void;