@teambit/pubsub 0.0.881 → 0.0.882
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/bit-base-event.js +0 -3
- package/dist/bit-base-event.js.map +1 -1
- package/dist/index.js +0 -9
- package/dist/index.js.map +1 -1
- package/dist/no-parent-error.js +0 -3
- package/dist/no-parent-error.js.map +1 -1
- package/dist/pubsub-context.js +0 -10
- package/dist/pubsub-context.js.map +1 -1
- package/dist/pubsub.aspect.js +0 -5
- package/dist/pubsub.aspect.js.map +1 -1
- package/dist/pubsub.composition.js +0 -6
- package/dist/pubsub.composition.js.map +1 -1
- package/dist/pubsub.main.runtime.js +0 -19
- package/dist/pubsub.main.runtime.js.map +1 -1
- package/dist/pubsub.preview.runtime.js +3 -37
- package/dist/pubsub.preview.runtime.js.map +1 -1
- package/dist/pubsub.ui.runtime.js +3 -33
- package/dist/pubsub.ui.runtime.js.map +1 -1
- package/package-tar/teambit-pubsub-0.0.882.tgz +0 -0
- package/package.json +4 -4
- package/{preview-1666409808293.js → preview-1666496165706.js} +2 -2
- package/package-tar/teambit-pubsub-0.0.881.tgz +0 -0
package/dist/bit-base-event.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.BitBaseEvent = void 0;
|
|
7
|
-
|
|
8
7
|
class BitBaseEvent {
|
|
9
8
|
constructor(type, version, timestamp, data) {
|
|
10
9
|
this.type = type;
|
|
@@ -12,9 +11,7 @@ class BitBaseEvent {
|
|
|
12
11
|
this.timestamp = timestamp;
|
|
13
12
|
this.data = data;
|
|
14
13
|
}
|
|
15
|
-
|
|
16
14
|
}
|
|
17
|
-
|
|
18
15
|
exports.BitBaseEvent = BitBaseEvent;
|
|
19
16
|
|
|
20
17
|
//# sourceMappingURL=bit-base-event.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BitBaseEvent","constructor","type","version","timestamp","data"],"sources":["bit-base-event.ts"],"sourcesContent":["export class BitBaseEvent<T> {\n constructor(readonly type: string, readonly version: string, readonly timestamp: number, readonly data: T) {}\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["BitBaseEvent","constructor","type","version","timestamp","data"],"sources":["bit-base-event.ts"],"sourcesContent":["export class BitBaseEvent<T> {\n constructor(readonly type: string, readonly version: string, readonly timestamp: number, readonly data: T) {}\n}\n"],"mappings":";;;;;;AAAO,MAAMA,YAAY,CAAI;EAC3BC,WAAW,CAAUC,IAAY,EAAWC,OAAe,EAAWC,SAAiB,EAAWC,IAAO,EAAE;IAAA,KAAtFH,IAAY,GAAZA,IAAY;IAAA,KAAWC,OAAe,GAAfA,OAAe;IAAA,KAAWC,SAAiB,GAAjBA,SAAiB;IAAA,KAAWC,IAAO,GAAPA,IAAO;EAAG;AAC9G;AAAC"}
|
package/dist/index.js
CHANGED
|
@@ -39,34 +39,25 @@ Object.defineProperty(exports, "usePubSubIframe", {
|
|
|
39
39
|
return _pubsubContext().usePubSubIframe;
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
|
-
|
|
43
42
|
function _pubsub() {
|
|
44
43
|
const data = require("./pubsub.aspect");
|
|
45
|
-
|
|
46
44
|
_pubsub = function () {
|
|
47
45
|
return data;
|
|
48
46
|
};
|
|
49
|
-
|
|
50
47
|
return data;
|
|
51
48
|
}
|
|
52
|
-
|
|
53
49
|
function _bitBaseEvent() {
|
|
54
50
|
const data = require("./bit-base-event");
|
|
55
|
-
|
|
56
51
|
_bitBaseEvent = function () {
|
|
57
52
|
return data;
|
|
58
53
|
};
|
|
59
|
-
|
|
60
54
|
return data;
|
|
61
55
|
}
|
|
62
|
-
|
|
63
56
|
function _pubsubContext() {
|
|
64
57
|
const data = require("./pubsub-context");
|
|
65
|
-
|
|
66
58
|
_pubsubContext = function () {
|
|
67
59
|
return data;
|
|
68
60
|
};
|
|
69
|
-
|
|
70
61
|
return data;
|
|
71
62
|
}
|
|
72
63
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { PubsubAspect, PubsubAspect as default } from './pubsub.aspect';\n\nexport type { PubsubMain } from './pubsub.main.runtime';\nexport type { PubsubPreview } from './pubsub.preview.runtime';\nexport type { PubsubUI } from './pubsub.ui.runtime';\nexport { BitBaseEvent } from './bit-base-event';\nexport { usePubSub, PubSubRegistry, usePubSubIframe } from './pubsub-context';\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { PubsubAspect, PubsubAspect as default } from './pubsub.aspect';\n\nexport type { PubsubMain } from './pubsub.main.runtime';\nexport type { PubsubPreview } from './pubsub.preview.runtime';\nexport type { PubsubUI } from './pubsub.ui.runtime';\nexport { BitBaseEvent } from './bit-base-event';\nexport { usePubSub, PubSubRegistry, usePubSubIframe } from './pubsub-context';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAKA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA"}
|
package/dist/no-parent-error.js
CHANGED
|
@@ -4,15 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.PubSubNoParentError = void 0;
|
|
7
|
-
|
|
8
7
|
class PubSubNoParentError extends Error {
|
|
9
8
|
constructor() {
|
|
10
9
|
super('could not connect to parent window');
|
|
11
10
|
this.name = 'PubSubNoParentError';
|
|
12
11
|
}
|
|
13
|
-
|
|
14
12
|
}
|
|
15
|
-
|
|
16
13
|
exports.PubSubNoParentError = PubSubNoParentError;
|
|
17
14
|
|
|
18
15
|
//# sourceMappingURL=no-parent-error.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["PubSubNoParentError","Error","constructor","name"],"sources":["no-parent-error.ts"],"sourcesContent":["export class PubSubNoParentError extends Error {\n constructor() {\n super('could not connect to parent window');\n this.name = 'PubSubNoParentError';\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["PubSubNoParentError","Error","constructor","name"],"sources":["no-parent-error.ts"],"sourcesContent":["export class PubSubNoParentError extends Error {\n constructor() {\n super('could not connect to parent window');\n this.name = 'PubSubNoParentError';\n }\n}\n"],"mappings":";;;;;;AAAO,MAAMA,mBAAmB,SAASC,KAAK,CAAC;EAC7CC,WAAW,GAAG;IACZ,KAAK,CAAC,oCAAoC,CAAC;IAC3C,IAAI,CAACC,IAAI,GAAG,qBAAqB;EACnC;AACF;AAAC"}
|
package/dist/pubsub-context.js
CHANGED
|
@@ -7,38 +7,28 @@ exports.createProvider = createProvider;
|
|
|
7
7
|
exports.pubsubRegistry = void 0;
|
|
8
8
|
exports.usePubSub = usePubSub;
|
|
9
9
|
exports.usePubSubIframe = usePubSubIframe;
|
|
10
|
-
|
|
11
10
|
function _react() {
|
|
12
11
|
const data = _interopRequireWildcard(require("react"));
|
|
13
|
-
|
|
14
12
|
_react = function () {
|
|
15
13
|
return data;
|
|
16
14
|
};
|
|
17
|
-
|
|
18
15
|
return data;
|
|
19
16
|
}
|
|
20
|
-
|
|
21
17
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
22
|
-
|
|
23
18
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
24
|
-
|
|
25
19
|
const pubsubRegistry = /*#__PURE__*/(0, _react().createContext)(undefined);
|
|
26
20
|
exports.pubsubRegistry = pubsubRegistry;
|
|
27
|
-
|
|
28
21
|
function createProvider(pubSubContext) {
|
|
29
22
|
const PubSubProvider = ({
|
|
30
23
|
children
|
|
31
24
|
}) => /*#__PURE__*/_react().default.createElement(pubsubRegistry.Provider, {
|
|
32
25
|
value: pubSubContext
|
|
33
26
|
}, children);
|
|
34
|
-
|
|
35
27
|
return PubSubProvider;
|
|
36
28
|
}
|
|
37
|
-
|
|
38
29
|
function usePubSub() {
|
|
39
30
|
return (0, _react().useContext)(pubsubRegistry);
|
|
40
31
|
}
|
|
41
|
-
|
|
42
32
|
function usePubSubIframe(ref) {
|
|
43
33
|
const pubSub = usePubSub();
|
|
44
34
|
(0, _react().useEffect)(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["pubsubRegistry","createContext","undefined","createProvider","pubSubContext","PubSubProvider","children","usePubSub","useContext","usePubSubIframe","ref","pubSub","useEffect","current","destroyConnection","connect"],"sources":["pubsub-context.tsx"],"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"],"mappings":"
|
|
1
|
+
{"version":3,"names":["pubsubRegistry","createContext","undefined","createProvider","pubSubContext","PubSubProvider","children","usePubSub","useContext","usePubSubIframe","ref","pubSub","useEffect","current","destroyConnection","connect"],"sources":["pubsub-context.tsx"],"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"],"mappings":";;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAA0F;AAAA;AAUnF,MAAMA,cAAc,gBAAG,IAAAC,sBAAa,EAA6BC,SAAS,CAAC;AAAC;AAE5E,SAASC,cAAc,CAACC,aAA6B,EAAE;EAC5D,MAAMC,cAAc,GAAG,CAAC;IAAEC;EAAkC,CAAC,kBAC3D,+BAAC,cAAc,CAAC,QAAQ;IAAC,KAAK,EAAEF;EAAc,GAAEE,QAAQ,CACzD;EAED,OAAOD,cAAc;AACvB;AAEO,SAASE,SAAS,GAAG;EAC1B,OAAO,IAAAC,mBAAU,EAACR,cAAc,CAAC;AACnC;AAEO,SAASS,eAAe,CAACC,GAAkC,EAAE;EAClE,MAAMC,MAAM,GAAGJ,SAAS,EAAE;EAE1B,IAAAK,kBAAS,EAAC,MAAM;IACd,IAAI,EAACF,GAAG,aAAHA,GAAG,eAAHA,GAAG,CAAEG,OAAO,KAAI,CAACF,MAAM,EAAE,OAAO,MAAM,CAAC,CAAC;IAE7C,MAAMG,iBAAiB,GAAGH,MAAM,CAACI,OAAO,CAACL,GAAG,CAACG,OAAO,CAAC;IACrD,OAAO,MAAMC,iBAAiB,EAAE;EAClC,CAAC,EAAE,CAACJ,GAAG,aAAHA,GAAG,uBAAHA,GAAG,CAAEG,OAAO,EAAEF,MAAM,CAAC,CAAC;AAC5B"}
|
package/dist/pubsub.aspect.js
CHANGED
|
@@ -4,22 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = exports.PubsubAspect = void 0;
|
|
7
|
-
|
|
8
7
|
function _harmony() {
|
|
9
8
|
const data = require("@teambit/harmony");
|
|
10
|
-
|
|
11
9
|
_harmony = function () {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
const PubsubAspect = _harmony().Aspect.create({
|
|
19
15
|
id: 'teambit.harmony/pubsub',
|
|
20
16
|
dependencies: []
|
|
21
17
|
});
|
|
22
|
-
|
|
23
18
|
exports.PubsubAspect = PubsubAspect;
|
|
24
19
|
var _default = PubsubAspect;
|
|
25
20
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["PubsubAspect","Aspect","create","id","dependencies"],"sources":["pubsub.aspect.ts"],"sourcesContent":["import { Aspect } from '@teambit/harmony';\n\nexport const PubsubAspect = Aspect.create({\n id: 'teambit.harmony/pubsub',\n dependencies: [],\n});\n\nexport default PubsubAspect;\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["PubsubAspect","Aspect","create","id","dependencies"],"sources":["pubsub.aspect.ts"],"sourcesContent":["import { Aspect } from '@teambit/harmony';\n\nexport const PubsubAspect = Aspect.create({\n id: 'teambit.harmony/pubsub',\n dependencies: [],\n});\n\nexport default PubsubAspect;\n"],"mappings":";;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,YAAY,GAAGC,iBAAM,CAACC,MAAM,CAAC;EACxCC,EAAE,EAAE,wBAAwB;EAC5BC,YAAY,EAAE;AAChB,CAAC,CAAC;AAAC;AAAA,eAEYJ,YAAY;AAAA"}
|
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.Logo = void 0;
|
|
9
|
-
|
|
10
8
|
function _react() {
|
|
11
9
|
const data = _interopRequireDefault(require("react"));
|
|
12
|
-
|
|
13
10
|
_react = function () {
|
|
14
11
|
return data;
|
|
15
12
|
};
|
|
16
|
-
|
|
17
13
|
return data;
|
|
18
14
|
}
|
|
19
|
-
|
|
20
15
|
const Logo = () => /*#__PURE__*/_react().default.createElement("div", {
|
|
21
16
|
style: {
|
|
22
17
|
height: '100%',
|
|
@@ -29,7 +24,6 @@ const Logo = () => /*#__PURE__*/_react().default.createElement("div", {
|
|
|
29
24
|
},
|
|
30
25
|
src: "https://static.bit.dev/extensions-icons/pubsub.svg"
|
|
31
26
|
}));
|
|
32
|
-
|
|
33
27
|
exports.Logo = Logo;
|
|
34
28
|
|
|
35
29
|
//# sourceMappingURL=pubsub.composition.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Logo","height","display","justifyContent","width"],"sources":["pubsub.composition.tsx"],"sourcesContent":["import React from 'react';\n\nexport const Logo = () => (\n <div style={{ height: '100%', display: 'flex', justifyContent: 'center' }}>\n <img style={{ width: 70 }} src=\"https://static.bit.dev/extensions-icons/pubsub.svg\" />\n </div>\n);\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["Logo","height","display","justifyContent","width"],"sources":["pubsub.composition.tsx"],"sourcesContent":["import React from 'react';\n\nexport const Logo = () => (\n <div style={{ height: '100%', display: 'flex', justifyContent: 'center' }}>\n <img style={{ width: 70 }} src=\"https://static.bit.dev/extensions-icons/pubsub.svg\" />\n </div>\n);\n"],"mappings":";;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,IAAI,GAAG,mBAClB;EAAK,KAAK,EAAE;IAAEC,MAAM,EAAE,MAAM;IAAEC,OAAO,EAAE,MAAM;IAAEC,cAAc,EAAE;EAAS;AAAE,gBACxE;EAAK,KAAK,EAAE;IAAEC,KAAK,EAAE;EAAG,CAAE;EAAC,GAAG,EAAC;AAAoD,EAAG,CAEzF;AAAC"}
|
|
@@ -1,44 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
require("core-js/modules/es.promise.js");
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.PubsubMain = void 0;
|
|
11
|
-
|
|
12
9
|
function _defineProperty2() {
|
|
13
10
|
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
|
-
|
|
15
11
|
_defineProperty2 = function () {
|
|
16
12
|
return data;
|
|
17
13
|
};
|
|
18
|
-
|
|
19
14
|
return data;
|
|
20
15
|
}
|
|
21
|
-
|
|
22
16
|
function _cli() {
|
|
23
17
|
const data = require("@teambit/cli");
|
|
24
|
-
|
|
25
18
|
_cli = function () {
|
|
26
19
|
return data;
|
|
27
20
|
};
|
|
28
|
-
|
|
29
21
|
return data;
|
|
30
22
|
}
|
|
31
|
-
|
|
32
23
|
function _pubsub() {
|
|
33
24
|
const data = require("./pubsub.aspect");
|
|
34
|
-
|
|
35
25
|
_pubsub = function () {
|
|
36
26
|
return data;
|
|
37
27
|
};
|
|
38
|
-
|
|
39
28
|
return data;
|
|
40
29
|
}
|
|
41
|
-
|
|
42
30
|
class PubsubMain {
|
|
43
31
|
constructor() {
|
|
44
32
|
(0, _defineProperty2().default)(this, "topicMap", {});
|
|
@@ -46,30 +34,23 @@ class PubsubMain {
|
|
|
46
34
|
this.topicMap[topicUUID] = this.topicMap[topicUUID] || [];
|
|
47
35
|
});
|
|
48
36
|
}
|
|
49
|
-
|
|
50
37
|
sub(topicUUID, callback) {
|
|
51
38
|
this.createOrGetTopic(topicUUID);
|
|
52
39
|
this.topicMap[topicUUID].push(callback);
|
|
53
40
|
}
|
|
54
|
-
|
|
55
41
|
pub(topicUUID, event) {
|
|
56
42
|
this.createOrGetTopic(topicUUID);
|
|
57
43
|
this.topicMap[topicUUID].forEach(callback => callback(event));
|
|
58
44
|
}
|
|
59
|
-
|
|
60
45
|
unsubscribeAll(topicId) {
|
|
61
46
|
delete this.topicMap[topicId];
|
|
62
47
|
}
|
|
63
|
-
|
|
64
48
|
static async provider() {
|
|
65
49
|
return new PubsubMain();
|
|
66
50
|
}
|
|
67
|
-
|
|
68
51
|
}
|
|
69
|
-
|
|
70
52
|
exports.PubsubMain = PubsubMain;
|
|
71
53
|
(0, _defineProperty2().default)(PubsubMain, "runtime", _cli().MainRuntime);
|
|
72
|
-
|
|
73
54
|
_pubsub().PubsubAspect.addRuntime(PubsubMain);
|
|
74
55
|
|
|
75
56
|
//# sourceMappingURL=pubsub.main.runtime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["PubsubMain","topicUUID","topicMap","sub","callback","createOrGetTopic","push","pub","event","forEach","unsubscribeAll","topicId","provider","MainRuntime","PubsubAspect","addRuntime"],"sources":["pubsub.main.runtime.ts"],"sourcesContent":["import { MainRuntime } from '@teambit/cli';\n\nimport { BitBaseEvent } from './bit-base-event';\nimport { PubsubAspect } from './pubsub.aspect';\n\nexport class PubsubMain {\n private topicMap = {};\n\n private createOrGetTopic = (topicUUID) => {\n this.topicMap[topicUUID] = this.topicMap[topicUUID] || [];\n };\n\n public sub(topicUUID, callback) {\n this.createOrGetTopic(topicUUID);\n this.topicMap[topicUUID].push(callback);\n }\n\n public pub(topicUUID, event: BitBaseEvent<any>) {\n this.createOrGetTopic(topicUUID);\n this.topicMap[topicUUID].forEach((callback) => callback(event));\n }\n\n unsubscribeAll(topicId: string) {\n delete this.topicMap[topicId];\n }\n\n static runtime = MainRuntime;\n\n static async provider() {\n return new PubsubMain();\n }\n}\n\nPubsubAspect.addRuntime(PubsubMain);\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["PubsubMain","topicUUID","topicMap","sub","callback","createOrGetTopic","push","pub","event","forEach","unsubscribeAll","topicId","provider","MainRuntime","PubsubAspect","addRuntime"],"sources":["pubsub.main.runtime.ts"],"sourcesContent":["import { MainRuntime } from '@teambit/cli';\n\nimport { BitBaseEvent } from './bit-base-event';\nimport { PubsubAspect } from './pubsub.aspect';\n\nexport class PubsubMain {\n private topicMap = {};\n\n private createOrGetTopic = (topicUUID) => {\n this.topicMap[topicUUID] = this.topicMap[topicUUID] || [];\n };\n\n public sub(topicUUID, callback) {\n this.createOrGetTopic(topicUUID);\n this.topicMap[topicUUID].push(callback);\n }\n\n public pub(topicUUID, event: BitBaseEvent<any>) {\n this.createOrGetTopic(topicUUID);\n this.topicMap[topicUUID].forEach((callback) => callback(event));\n }\n\n unsubscribeAll(topicId: string) {\n delete this.topicMap[topicId];\n }\n\n static runtime = MainRuntime;\n\n static async provider() {\n return new PubsubMain();\n }\n}\n\nPubsubAspect.addRuntime(PubsubMain);\n"],"mappings":";;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,UAAU,CAAC;EAAA;IAAA,kDACH,CAAC,CAAC;IAAA,0DAEOC,SAAS,IAAK;MACxC,IAAI,CAACC,QAAQ,CAACD,SAAS,CAAC,GAAG,IAAI,CAACC,QAAQ,CAACD,SAAS,CAAC,IAAI,EAAE;IAC3D,CAAC;EAAA;EAEME,GAAG,CAACF,SAAS,EAAEG,QAAQ,EAAE;IAC9B,IAAI,CAACC,gBAAgB,CAACJ,SAAS,CAAC;IAChC,IAAI,CAACC,QAAQ,CAACD,SAAS,CAAC,CAACK,IAAI,CAACF,QAAQ,CAAC;EACzC;EAEOG,GAAG,CAACN,SAAS,EAAEO,KAAwB,EAAE;IAC9C,IAAI,CAACH,gBAAgB,CAACJ,SAAS,CAAC;IAChC,IAAI,CAACC,QAAQ,CAACD,SAAS,CAAC,CAACQ,OAAO,CAAEL,QAAQ,IAAKA,QAAQ,CAACI,KAAK,CAAC,CAAC;EACjE;EAEAE,cAAc,CAACC,OAAe,EAAE;IAC9B,OAAO,IAAI,CAACT,QAAQ,CAACS,OAAO,CAAC;EAC/B;EAIA,aAAaC,QAAQ,GAAG;IACtB,OAAO,IAAIZ,UAAU,EAAE;EACzB;AACF;AAAC;AAAA,gCA1BYA,UAAU,aAqBJa,kBAAW;AAO9BC,sBAAY,CAACC,UAAU,CAACf,UAAU,CAAC"}
|
|
@@ -1,87 +1,64 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
require("core-js/modules/es.promise.js");
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.PubsubPreview = void 0;
|
|
11
|
-
|
|
12
9
|
function _defineProperty2() {
|
|
13
10
|
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
|
-
|
|
15
11
|
_defineProperty2 = function () {
|
|
16
12
|
return data;
|
|
17
13
|
};
|
|
18
|
-
|
|
19
14
|
return data;
|
|
20
15
|
}
|
|
21
|
-
|
|
22
16
|
function _preview() {
|
|
23
17
|
const data = require("@teambit/preview");
|
|
24
|
-
|
|
25
18
|
_preview = function () {
|
|
26
19
|
return data;
|
|
27
20
|
};
|
|
28
|
-
|
|
29
21
|
return data;
|
|
30
22
|
}
|
|
31
|
-
|
|
32
23
|
function _uiFoundationUi() {
|
|
33
24
|
const data = require("@teambit/ui-foundation.ui.is-browser");
|
|
34
|
-
|
|
35
25
|
_uiFoundationUi = function () {
|
|
36
26
|
return data;
|
|
37
27
|
};
|
|
38
|
-
|
|
39
28
|
return data;
|
|
40
29
|
}
|
|
41
|
-
|
|
42
30
|
function _eventemitter() {
|
|
43
31
|
const data = require("eventemitter2");
|
|
44
|
-
|
|
45
32
|
_eventemitter = function () {
|
|
46
33
|
return data;
|
|
47
34
|
};
|
|
48
|
-
|
|
49
35
|
return data;
|
|
50
36
|
}
|
|
51
|
-
|
|
52
37
|
function _penpal() {
|
|
53
38
|
const data = require("penpal");
|
|
54
|
-
|
|
55
39
|
_penpal = function () {
|
|
56
40
|
return data;
|
|
57
41
|
};
|
|
58
|
-
|
|
59
42
|
return data;
|
|
60
43
|
}
|
|
61
|
-
|
|
62
44
|
function _noParentError() {
|
|
63
45
|
const data = require("./no-parent-error");
|
|
64
|
-
|
|
65
46
|
_noParentError = function () {
|
|
66
47
|
return data;
|
|
67
48
|
};
|
|
68
|
-
|
|
69
49
|
return data;
|
|
70
50
|
}
|
|
71
|
-
|
|
72
51
|
function _pubsub() {
|
|
73
52
|
const data = require("./pubsub.aspect");
|
|
74
|
-
|
|
75
53
|
_pubsub = function () {
|
|
76
54
|
return data;
|
|
77
55
|
};
|
|
78
|
-
|
|
79
56
|
return data;
|
|
80
57
|
}
|
|
81
|
-
|
|
82
58
|
/**
|
|
83
59
|
* Please Notice: This file will run in the preview iframe.
|
|
84
60
|
*/
|
|
61
|
+
|
|
85
62
|
class PubsubPreview {
|
|
86
63
|
constructor() {
|
|
87
64
|
(0, _defineProperty2().default)(this, "_parentPubsub", void 0);
|
|
@@ -102,28 +79,22 @@ class PubsubPreview {
|
|
|
102
79
|
this.events.emit(topic, message);
|
|
103
80
|
});
|
|
104
81
|
}
|
|
105
|
-
|
|
106
82
|
sub(topic, callback) {
|
|
107
83
|
const emitter = this.events;
|
|
108
84
|
emitter.on(topic, callback);
|
|
109
|
-
|
|
110
85
|
const unSub = () => {
|
|
111
86
|
emitter.off(topic, callback);
|
|
112
87
|
};
|
|
113
|
-
|
|
114
88
|
return unSub;
|
|
115
89
|
}
|
|
116
|
-
|
|
117
90
|
pub(topic, event) {
|
|
118
91
|
var _this$_parentPubsub;
|
|
119
|
-
|
|
120
92
|
this.events.emit(topic, event);
|
|
121
93
|
(_this$_parentPubsub = this._parentPubsub) === null || _this$_parentPubsub === void 0 ? void 0 : _this$_parentPubsub.pub(topic, event).catch(err => {
|
|
122
94
|
// eslint-disable-next-line no-console
|
|
123
95
|
console.error('[Pubsub.preview]', err);
|
|
124
96
|
});
|
|
125
97
|
}
|
|
126
|
-
|
|
127
98
|
inIframe() {
|
|
128
99
|
try {
|
|
129
100
|
return _uiFoundationUi().isBrowser && window.self !== window.top;
|
|
@@ -131,27 +102,22 @@ class PubsubPreview {
|
|
|
131
102
|
return false;
|
|
132
103
|
}
|
|
133
104
|
}
|
|
134
|
-
|
|
135
105
|
static async provider() {
|
|
136
106
|
const pubsubPreview = new PubsubPreview();
|
|
137
|
-
|
|
138
107
|
if (pubsubPreview.inIframe()) {
|
|
139
108
|
pubsubPreview.connectToParentPubSub().catch(err => {
|
|
140
109
|
// parent window is not required to accept connections
|
|
141
|
-
if (err instanceof _noParentError().PubSubNoParentError) return;
|
|
110
|
+
if (err instanceof _noParentError().PubSubNoParentError) return;
|
|
142
111
|
|
|
112
|
+
// eslint-disable-next-line no-console
|
|
143
113
|
console.error('[Pubsub.preview]', err);
|
|
144
114
|
});
|
|
145
115
|
}
|
|
146
|
-
|
|
147
116
|
return pubsubPreview;
|
|
148
117
|
}
|
|
149
|
-
|
|
150
118
|
}
|
|
151
|
-
|
|
152
119
|
exports.PubsubPreview = PubsubPreview;
|
|
153
120
|
(0, _defineProperty2().default)(PubsubPreview, "runtime", _preview().PreviewRuntime);
|
|
154
|
-
|
|
155
121
|
_pubsub().PubsubAspect.addRuntime(PubsubPreview);
|
|
156
122
|
|
|
157
123
|
//# sourceMappingURL=pubsub.preview.runtime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["PubsubPreview","EventEmitter2","retries","PubSubNoParentError","connectToParent","timeout","methods","pub","handleMessageFromParent","promise","then","parentPubsub","_parentPubsub","catch","e","code","ErrorCode","ConnectionTimeout","connectToParentPubSub","topic","message","events","emit","sub","callback","emitter","on","unSub","off","event","err","console","error","inIframe","isBrowser","window","self","top","provider","pubsubPreview","PreviewRuntime","PubsubAspect","addRuntime"],"sources":["pubsub.preview.runtime.ts"],"sourcesContent":["/**\n * Please Notice: This file will run in the preview iframe.\n */\n\nimport { PreviewRuntime } from '@teambit/preview';\nimport { isBrowser } from '@teambit/ui-foundation.ui.is-browser';\n\nimport { EventEmitter2 } from 'eventemitter2';\nimport { connectToParent, ErrorCode } from 'penpal';\n\nimport { BitBaseEvent } from './bit-base-event';\nimport { PubSubNoParentError } from './no-parent-error';\nimport { PubsubAspect } from './pubsub.aspect';\nimport { Callback } from './types';\n\ntype ParentMethods = {\n pub: (topic: string, event: BitBaseEvent<any>) => Promise<any>;\n};\n\nexport class PubsubPreview {\n private _parentPubsub?: ParentMethods;\n private events = new EventEmitter2();\n\n public sub(topic: string, callback: Callback) {\n const emitter = this.events;\n emitter.on(topic, callback);\n\n const unSub = () => {\n emitter.off(topic, callback);\n };\n return unSub;\n }\n\n public pub(topic: string, event: BitBaseEvent<any>) {\n this.events.emit(topic, event);\n this._parentPubsub?.pub(topic, event).catch((err) => {\n // eslint-disable-next-line no-console\n console.error('[Pubsub.preview]', err);\n });\n }\n\n private inIframe() {\n try {\n return isBrowser && window.self !== window.top;\n } catch (e: any) {\n return false;\n }\n }\n\n private connectToParentPubSub = (retries = 10): Promise<ParentMethods | undefined> => {\n if (retries <= 0) throw new PubSubNoParentError();\n\n return connectToParent<ParentMethods>({\n timeout: 300,\n methods: {\n pub: this.handleMessageFromParent,\n },\n })\n .promise.then((parentPubsub) => (this._parentPubsub = parentPubsub))\n .catch((e: any) => {\n if (e.code !== ErrorCode.ConnectionTimeout) throw e;\n\n return this.connectToParentPubSub(retries - 1);\n });\n };\n\n private handleMessageFromParent = (topic: string, message: BitBaseEvent<any>) => {\n this.events.emit(topic, message);\n };\n\n static runtime = PreviewRuntime;\n\n static async provider(): Promise<PubsubPreview> {\n const pubsubPreview = new PubsubPreview();\n\n if (pubsubPreview.inIframe()) {\n pubsubPreview.connectToParentPubSub().catch((err) => {\n // parent window is not required to accept connections\n if (err instanceof PubSubNoParentError) return;\n\n // eslint-disable-next-line no-console\n console.error('[Pubsub.preview]', err);\n });\n }\n\n return pubsubPreview;\n }\n}\n\nPubsubAspect.addRuntime(PubsubPreview);\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["PubsubPreview","EventEmitter2","retries","PubSubNoParentError","connectToParent","timeout","methods","pub","handleMessageFromParent","promise","then","parentPubsub","_parentPubsub","catch","e","code","ErrorCode","ConnectionTimeout","connectToParentPubSub","topic","message","events","emit","sub","callback","emitter","on","unSub","off","event","err","console","error","inIframe","isBrowser","window","self","top","provider","pubsubPreview","PreviewRuntime","PubsubAspect","addRuntime"],"sources":["pubsub.preview.runtime.ts"],"sourcesContent":["/**\n * Please Notice: This file will run in the preview iframe.\n */\n\nimport { PreviewRuntime } from '@teambit/preview';\nimport { isBrowser } from '@teambit/ui-foundation.ui.is-browser';\n\nimport { EventEmitter2 } from 'eventemitter2';\nimport { connectToParent, ErrorCode } from 'penpal';\n\nimport { BitBaseEvent } from './bit-base-event';\nimport { PubSubNoParentError } from './no-parent-error';\nimport { PubsubAspect } from './pubsub.aspect';\nimport { Callback } from './types';\n\ntype ParentMethods = {\n pub: (topic: string, event: BitBaseEvent<any>) => Promise<any>;\n};\n\nexport class PubsubPreview {\n private _parentPubsub?: ParentMethods;\n private events = new EventEmitter2();\n\n public sub(topic: string, callback: Callback) {\n const emitter = this.events;\n emitter.on(topic, callback);\n\n const unSub = () => {\n emitter.off(topic, callback);\n };\n return unSub;\n }\n\n public pub(topic: string, event: BitBaseEvent<any>) {\n this.events.emit(topic, event);\n this._parentPubsub?.pub(topic, event).catch((err) => {\n // eslint-disable-next-line no-console\n console.error('[Pubsub.preview]', err);\n });\n }\n\n private inIframe() {\n try {\n return isBrowser && window.self !== window.top;\n } catch (e: any) {\n return false;\n }\n }\n\n private connectToParentPubSub = (retries = 10): Promise<ParentMethods | undefined> => {\n if (retries <= 0) throw new PubSubNoParentError();\n\n return connectToParent<ParentMethods>({\n timeout: 300,\n methods: {\n pub: this.handleMessageFromParent,\n },\n })\n .promise.then((parentPubsub) => (this._parentPubsub = parentPubsub))\n .catch((e: any) => {\n if (e.code !== ErrorCode.ConnectionTimeout) throw e;\n\n return this.connectToParentPubSub(retries - 1);\n });\n };\n\n private handleMessageFromParent = (topic: string, message: BitBaseEvent<any>) => {\n this.events.emit(topic, message);\n };\n\n static runtime = PreviewRuntime;\n\n static async provider(): Promise<PubsubPreview> {\n const pubsubPreview = new PubsubPreview();\n\n if (pubsubPreview.inIframe()) {\n pubsubPreview.connectToParentPubSub().catch((err) => {\n // parent window is not required to accept connections\n if (err instanceof PubSubNoParentError) return;\n\n // eslint-disable-next-line no-console\n console.error('[Pubsub.preview]', err);\n });\n }\n\n return pubsubPreview;\n }\n}\n\nPubsubAspect.addRuntime(PubsubPreview);\n"],"mappings":";;;;;;;;;;;;;;;AAIA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAZA;AACA;AACA;;AAiBO,MAAMA,aAAa,CAAC;EAAA;IAAA;IAAA,gDAER,KAAIC,6BAAa,GAAE;IAAA,+DA4BJ,CAACC,OAAO,GAAG,EAAE,KAAyC;MACpF,IAAIA,OAAO,IAAI,CAAC,EAAE,MAAM,KAAIC,oCAAmB,GAAE;MAEjD,OAAO,IAAAC,yBAAe,EAAgB;QACpCC,OAAO,EAAE,GAAG;QACZC,OAAO,EAAE;UACPC,GAAG,EAAE,IAAI,CAACC;QACZ;MACF,CAAC,CAAC,CACCC,OAAO,CAACC,IAAI,CAAEC,YAAY,IAAM,IAAI,CAACC,aAAa,GAAGD,YAAa,CAAC,CACnEE,KAAK,CAAEC,CAAM,IAAK;QACjB,IAAIA,CAAC,CAACC,IAAI,KAAKC,mBAAS,CAACC,iBAAiB,EAAE,MAAMH,CAAC;QAEnD,OAAO,IAAI,CAACI,qBAAqB,CAAChB,OAAO,GAAG,CAAC,CAAC;MAChD,CAAC,CAAC;IACN,CAAC;IAAA,iEAEiC,CAACiB,KAAa,EAAEC,OAA0B,KAAK;MAC/E,IAAI,CAACC,MAAM,CAACC,IAAI,CAACH,KAAK,EAAEC,OAAO,CAAC;IAClC,CAAC;EAAA;EA7CMG,GAAG,CAACJ,KAAa,EAAEK,QAAkB,EAAE;IAC5C,MAAMC,OAAO,GAAG,IAAI,CAACJ,MAAM;IAC3BI,OAAO,CAACC,EAAE,CAACP,KAAK,EAAEK,QAAQ,CAAC;IAE3B,MAAMG,KAAK,GAAG,MAAM;MAClBF,OAAO,CAACG,GAAG,CAACT,KAAK,EAAEK,QAAQ,CAAC;IAC9B,CAAC;IACD,OAAOG,KAAK;EACd;EAEOpB,GAAG,CAACY,KAAa,EAAEU,KAAwB,EAAE;IAAA;IAClD,IAAI,CAACR,MAAM,CAACC,IAAI,CAACH,KAAK,EAAEU,KAAK,CAAC;IAC9B,2BAAI,CAACjB,aAAa,wDAAlB,oBAAoBL,GAAG,CAACY,KAAK,EAAEU,KAAK,CAAC,CAAChB,KAAK,CAAEiB,GAAG,IAAK;MACnD;MACAC,OAAO,CAACC,KAAK,CAAC,kBAAkB,EAAEF,GAAG,CAAC;IACxC,CAAC,CAAC;EACJ;EAEQG,QAAQ,GAAG;IACjB,IAAI;MACF,OAAOC,2BAAS,IAAIC,MAAM,CAACC,IAAI,KAAKD,MAAM,CAACE,GAAG;IAChD,CAAC,CAAC,OAAOvB,CAAM,EAAE;MACf,OAAO,KAAK;IACd;EACF;EAyBA,aAAawB,QAAQ,GAA2B;IAC9C,MAAMC,aAAa,GAAG,IAAIvC,aAAa,EAAE;IAEzC,IAAIuC,aAAa,CAACN,QAAQ,EAAE,EAAE;MAC5BM,aAAa,CAACrB,qBAAqB,EAAE,CAACL,KAAK,CAAEiB,GAAG,IAAK;QACnD;QACA,IAAIA,GAAG,YAAY3B,oCAAmB,EAAE;;QAExC;QACA4B,OAAO,CAACC,KAAK,CAAC,kBAAkB,EAAEF,GAAG,CAAC;MACxC,CAAC,CAAC;IACJ;IAEA,OAAOS,aAAa;EACtB;AACF;AAAC;AAAA,gCApEYvC,aAAa,aAmDPwC,yBAAc;AAmBjCC,sBAAY,CAACC,UAAU,CAAC1C,aAAa,CAAC"}
|
|
@@ -1,76 +1,54 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
require("core-js/modules/es.array.iterator.js");
|
|
6
|
-
|
|
7
5
|
require("core-js/modules/es.promise.js");
|
|
8
|
-
|
|
9
6
|
Object.defineProperty(exports, "__esModule", {
|
|
10
7
|
value: true
|
|
11
8
|
});
|
|
12
9
|
exports.PubsubUI = void 0;
|
|
13
|
-
|
|
14
10
|
function _defineProperty2() {
|
|
15
11
|
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
16
|
-
|
|
17
12
|
_defineProperty2 = function () {
|
|
18
13
|
return data;
|
|
19
14
|
};
|
|
20
|
-
|
|
21
15
|
return data;
|
|
22
16
|
}
|
|
23
|
-
|
|
24
17
|
function _ui() {
|
|
25
18
|
const data = require("@teambit/ui");
|
|
26
|
-
|
|
27
19
|
_ui = function () {
|
|
28
20
|
return data;
|
|
29
21
|
};
|
|
30
|
-
|
|
31
22
|
return data;
|
|
32
23
|
}
|
|
33
|
-
|
|
34
24
|
function _eventemitter() {
|
|
35
25
|
const data = require("eventemitter2");
|
|
36
|
-
|
|
37
26
|
_eventemitter = function () {
|
|
38
27
|
return data;
|
|
39
28
|
};
|
|
40
|
-
|
|
41
29
|
return data;
|
|
42
30
|
}
|
|
43
|
-
|
|
44
31
|
function _penpal() {
|
|
45
32
|
const data = require("penpal");
|
|
46
|
-
|
|
47
33
|
_penpal = function () {
|
|
48
34
|
return data;
|
|
49
35
|
};
|
|
50
|
-
|
|
51
36
|
return data;
|
|
52
37
|
}
|
|
53
|
-
|
|
54
38
|
function _pubsub() {
|
|
55
39
|
const data = require("./pubsub.aspect");
|
|
56
|
-
|
|
57
40
|
_pubsub = function () {
|
|
58
41
|
return data;
|
|
59
42
|
};
|
|
60
|
-
|
|
61
43
|
return data;
|
|
62
44
|
}
|
|
63
|
-
|
|
64
45
|
function _pubsubContext() {
|
|
65
46
|
const data = require("./pubsub-context");
|
|
66
|
-
|
|
67
47
|
_pubsubContext = function () {
|
|
68
48
|
return data;
|
|
69
49
|
};
|
|
70
|
-
|
|
71
50
|
return data;
|
|
72
51
|
}
|
|
73
|
-
|
|
74
52
|
class PubsubUI {
|
|
75
53
|
constructor() {
|
|
76
54
|
(0, _defineProperty2().default)(this, "childApi", void 0);
|
|
@@ -78,18 +56,17 @@ class PubsubUI {
|
|
|
78
56
|
(0, _defineProperty2().default)(this, "sub", (topic, callback) => {
|
|
79
57
|
const events = this.events;
|
|
80
58
|
events.on(topic, callback);
|
|
81
|
-
|
|
82
59
|
const unSub = () => {
|
|
83
60
|
events.off(topic, callback);
|
|
84
61
|
};
|
|
85
|
-
|
|
86
62
|
return unSub;
|
|
87
63
|
});
|
|
88
64
|
(0, _defineProperty2().default)(this, "pub", (topic, event, {
|
|
89
65
|
propagate
|
|
90
66
|
} = {}) => {
|
|
91
|
-
this.emitEvent(topic, event);
|
|
67
|
+
this.emitEvent(topic, event);
|
|
92
68
|
|
|
69
|
+
// opt-in to forward to iframe, as we would not want 'private' messages automatically passing to iframe
|
|
93
70
|
if (propagate) {
|
|
94
71
|
this.pubToChild(topic, event);
|
|
95
72
|
}
|
|
@@ -105,11 +82,9 @@ class PubsubUI {
|
|
|
105
82
|
// eslint-disable-next-line no-console
|
|
106
83
|
console.error('[Pubsub.ui]', 'failed connecting to child iframe:', err);
|
|
107
84
|
});
|
|
108
|
-
|
|
109
85
|
const destroy = () => {
|
|
110
86
|
connection && connection.destroy();
|
|
111
87
|
};
|
|
112
|
-
|
|
113
88
|
return destroy;
|
|
114
89
|
});
|
|
115
90
|
(0, _defineProperty2().default)(this, "emitEvent", (topic, event) => {
|
|
@@ -117,21 +92,19 @@ class PubsubUI {
|
|
|
117
92
|
});
|
|
118
93
|
(0, _defineProperty2().default)(this, "pubToChild", (topic, event) => {
|
|
119
94
|
var _this$childApi;
|
|
120
|
-
|
|
121
95
|
return (_this$childApi = this.childApi) === null || _this$childApi === void 0 ? void 0 : _this$childApi.pub(topic, event);
|
|
122
96
|
});
|
|
123
97
|
}
|
|
124
|
-
|
|
125
98
|
getPubSubContext() {
|
|
126
99
|
return (0, _pubsubContext().createProvider)({
|
|
127
100
|
connect: this.connectToIframe
|
|
128
101
|
});
|
|
129
102
|
}
|
|
103
|
+
|
|
130
104
|
/**
|
|
131
105
|
* publish event to all subscribers in this window
|
|
132
106
|
*/
|
|
133
107
|
|
|
134
|
-
|
|
135
108
|
static async provider([uiUI]) {
|
|
136
109
|
const pubsubUI = new PubsubUI();
|
|
137
110
|
const reactContext = pubsubUI.getPubSubContext();
|
|
@@ -140,13 +113,10 @@ class PubsubUI {
|
|
|
140
113
|
});
|
|
141
114
|
return pubsubUI;
|
|
142
115
|
}
|
|
143
|
-
|
|
144
116
|
}
|
|
145
|
-
|
|
146
117
|
exports.PubsubUI = PubsubUI;
|
|
147
118
|
(0, _defineProperty2().default)(PubsubUI, "runtime", _ui().UIRuntime);
|
|
148
119
|
(0, _defineProperty2().default)(PubsubUI, "dependencies", [_ui().UIAspect]);
|
|
149
|
-
|
|
150
120
|
_pubsub().PubsubAspect.addRuntime(PubsubUI);
|
|
151
121
|
|
|
152
122
|
//# sourceMappingURL=pubsub.ui.runtime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["PubsubUI","EventEmitter2","topic","callback","events","on","unSub","off","event","propagate","emitEvent","pubToChild","iframe","connection","connectToChild","methods","pub","promise","then","childConnection","childApi","catch","err","console","error","destroy","emit","getPubSubContext","createProvider","connect","connectToIframe","provider","uiUI","pubsubUI","reactContext","registerRenderHooks","UIRuntime","UIAspect","PubsubAspect","addRuntime"],"sources":["pubsub.ui.runtime.ts"],"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 getPubSubContext() {\n return createProvider({\n connect: this.connectToIframe,\n });\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 = pubsubUI.getPubSubContext();\n\n if (uiUI) uiUI.registerRenderHooks({ reactContext });\n\n return pubsubUI;\n }\n}\n\nPubsubAspect.addRuntime(PubsubUI);\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["PubsubUI","EventEmitter2","topic","callback","events","on","unSub","off","event","propagate","emitEvent","pubToChild","iframe","connection","connectToChild","methods","pub","promise","then","childConnection","childApi","catch","err","console","error","destroy","emit","getPubSubContext","createProvider","connect","connectToIframe","provider","uiUI","pubsubUI","reactContext","registerRenderHooks","UIRuntime","UIAspect","PubsubAspect","addRuntime"],"sources":["pubsub.ui.runtime.ts"],"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 getPubSubContext() {\n return createProvider({\n connect: this.connectToIframe,\n });\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 = pubsubUI.getPubSubContext();\n\n if (uiUI) uiUI.registerRenderHooks({ reactContext });\n\n return pubsubUI;\n }\n}\n\nPubsubAspect.addRuntime(PubsubUI);\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAWO,MAAMA,QAAQ,CAAC;EAAA;IAAA;IAAA,gDAEH,KAAIC,6BAAa,GAAE;IAAA,6CAKvB,CAACC,KAAa,EAAEC,QAAkB,KAAK;MAClD,MAAMC,MAAM,GAAG,IAAI,CAACA,MAAM;MAC1BA,MAAM,CAACC,EAAE,CAACH,KAAK,EAAEC,QAAQ,CAAC;MAE1B,MAAMG,KAAK,GAAG,MAAM;QAClBF,MAAM,CAACG,GAAG,CAACL,KAAK,EAAEC,QAAQ,CAAC;MAC7B,CAAC;MAED,OAAOG,KAAK;IACd,CAAC;IAAA,6CAKY,CAACJ,KAAa,EAAEM,KAAwB,EAAE;MAAEC;IAAsB,CAAC,GAAG,CAAC,CAAC,KAAK;MACxF,IAAI,CAACC,SAAS,CAACR,KAAK,EAAEM,KAAK,CAAC;;MAE5B;MACA,IAAIC,SAAS,EAAE;QACb,IAAI,CAACE,UAAU,CAACT,KAAK,EAAEM,KAAK,CAAC;MAC/B;IACF,CAAC;IAAA,yDAE0BI,MAAyB,IAAK;MACvD,MAAMC,UAAU,GAAG,IAAAC,wBAAc,EAAe;QAC9CF,MAAM;QACNG,OAAO,EAAE;UACPC,GAAG,EAAE,IAAI,CAACN;QACZ;MACF,CAAC,CAAC;MAEFG,UAAU,CAACI,OAAO,CACfC,IAAI,CAAEC,eAAe,IAAM,IAAI,CAACC,QAAQ,GAAGD,eAAgB,CAAC,CAC5DE,KAAK,CAAEC,GAAG,IAAK;QACd;QACAC,OAAO,CAACC,KAAK,CAAC,aAAa,EAAE,oCAAoC,EAAEF,GAAG,CAAC;MACzE,CAAC,CAAC;MAEJ,MAAMG,OAAO,GAAG,MAAM;QACpBZ,UAAU,IAAIA,UAAU,CAACY,OAAO,EAAE;MACpC,CAAC;MACD,OAAOA,OAAO;IAChB,CAAC;IAAA,mDAWmB,CAACvB,KAAa,EAAEM,KAAwB,KAAK;MAC/D,IAAI,CAACJ,MAAM,CAACsB,IAAI,CAACxB,KAAK,EAAEM,KAAK,CAAC;IAChC,CAAC;IAAA,oDAKoB,CAACN,KAAa,EAAEM,KAAwB,KAAK;MAAA;MAChE,yBAAO,IAAI,CAACY,QAAQ,mDAAb,eAAeJ,GAAG,CAACd,KAAK,EAAEM,KAAK,CAAC;IACzC,CAAC;EAAA;EAlBDmB,gBAAgB,GAAG;IACjB,OAAO,IAAAC,+BAAc,EAAC;MACpBC,OAAO,EAAE,IAAI,CAACC;IAChB,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;;EAeE,aAAaC,QAAQ,CAAC,CAACC,IAAI,CAAS,EAAE;IACpC,MAAMC,QAAQ,GAAG,IAAIjC,QAAQ,EAAE;IAE/B,MAAMkC,YAAY,GAAGD,QAAQ,CAACN,gBAAgB,EAAE;IAEhD,IAAIK,IAAI,EAAEA,IAAI,CAACG,mBAAmB,CAAC;MAAED;IAAa,CAAC,CAAC;IAEpD,OAAOD,QAAQ;EACjB;AACF;AAAC;AAAA,gCAnFYjC,QAAQ,aAuEFoC,eAAS;AAAA,gCAvEfpC,QAAQ,kBAwEG,CAACqC,cAAQ,CAAC;AAalCC,sBAAY,CAACC,UAAU,CAACvC,QAAQ,CAAC"}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/pubsub",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.882",
|
|
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.
|
|
9
|
+
"version": "0.0.882"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"eventemitter2": "6.4.4",
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"core-js": "^3.0.0",
|
|
16
16
|
"@teambit/harmony": "0.3.3",
|
|
17
17
|
"@teambit/cli": "0.0.591",
|
|
18
|
-
"@teambit/preview": "0.0.
|
|
18
|
+
"@teambit/preview": "0.0.882",
|
|
19
19
|
"@teambit/ui-foundation.ui.is-browser": "0.0.492",
|
|
20
|
-
"@teambit/ui": "0.0.
|
|
20
|
+
"@teambit/ui": "0.0.882"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/react": "^17.0.8",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_pubsub@0.0.
|
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_pubsub@0.0.
|
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_pubsub@0.0.882/dist/pubsub.composition.js';
|
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_pubsub@0.0.882/dist/pubsub.docs.mdx';
|
|
3
3
|
|
|
4
4
|
export const compositions = [compositions_0];
|
|
5
5
|
export const overview = [overview_0];
|
|
Binary file
|