@atlaskit/editor-plugin-engagement-platform 2.0.0 → 2.1.0
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/CHANGELOG.md +21 -0
- package/README.md +65 -14
- package/dist/cjs/actions/startMessage.js +66 -0
- package/dist/cjs/actions/stopMessage.js +66 -0
- package/dist/cjs/actions/types.js +5 -0
- package/dist/cjs/engagementPlatformPlugin.js +14 -6
- package/dist/cjs/pmPlugins/engagementPlatformPmPlugin/commands/setMessageState.js +22 -0
- package/dist/cjs/pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPlugin.js +48 -0
- package/dist/cjs/pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPluginKey.js +8 -0
- package/dist/cjs/pmPlugins/engagementPlatformPmPlugin/types.js +5 -0
- package/dist/es2019/actions/startMessage.js +34 -0
- package/dist/es2019/actions/stopMessage.js +34 -0
- package/dist/es2019/actions/types.js +1 -0
- package/dist/es2019/engagementPlatformPlugin.js +14 -6
- package/dist/es2019/pmPlugins/engagementPlatformPmPlugin/commands/setMessageState.js +14 -0
- package/dist/es2019/pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPlugin.js +38 -0
- package/dist/es2019/pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPluginKey.js +2 -0
- package/dist/es2019/pmPlugins/engagementPlatformPmPlugin/types.js +1 -0
- package/dist/esm/actions/startMessage.js +59 -0
- package/dist/esm/actions/stopMessage.js +59 -0
- package/dist/esm/actions/types.js +1 -0
- package/dist/esm/engagementPlatformPlugin.js +14 -6
- package/dist/esm/pmPlugins/engagementPlatformPmPlugin/commands/setMessageState.js +15 -0
- package/dist/esm/pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPlugin.js +41 -0
- package/dist/esm/pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPluginKey.js +2 -0
- package/dist/esm/pmPlugins/engagementPlatformPmPlugin/types.js +1 -0
- package/dist/types/actions/startMessage.d.ts +3 -0
- package/dist/types/actions/stopMessage.d.ts +3 -0
- package/dist/types/actions/types.d.ts +2 -0
- package/dist/types/engagementPlatformPluginType.d.ts +58 -15
- package/dist/types/index.d.ts +1 -1
- package/dist/types/pmPlugins/engagementPlatformPmPlugin/commands/setMessageState.d.ts +3 -0
- package/dist/types/pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPlugin.d.ts +4 -0
- package/dist/types/pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPluginKey.d.ts +3 -0
- package/dist/types/pmPlugins/engagementPlatformPmPlugin/types.d.ts +25 -0
- package/dist/types-ts4.5/actions/startMessage.d.ts +3 -0
- package/dist/types-ts4.5/actions/stopMessage.d.ts +3 -0
- package/dist/types-ts4.5/actions/types.d.ts +2 -0
- package/dist/types-ts4.5/engagementPlatformPluginType.d.ts +58 -14
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/pmPlugins/engagementPlatformPmPlugin/commands/setMessageState.d.ts +3 -0
- package/dist/types-ts4.5/pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPlugin.d.ts +4 -0
- package/dist/types-ts4.5/pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPluginKey.d.ts +3 -0
- package/dist/types-ts4.5/pmPlugins/engagementPlatformPmPlugin/types.d.ts +25 -0
- package/package.json +3 -2
- package/dist/cjs/pm-plugins/main.js +0 -29
- package/dist/es2019/pm-plugins/main.js +0 -23
- package/dist/esm/pm-plugins/main.js +0 -23
- package/dist/types/pm-plugins/main.d.ts +0 -9
- package/dist/types-ts4.5/pm-plugins/main.d.ts +0 -9
package/CHANGELOG.md
CHANGED
|
@@ -1 +1,22 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-engagement-platform
|
|
2
|
+
|
|
3
|
+
## 2.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#151455](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/151455)
|
|
8
|
+
[`1c6e93e3f7c13`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/1c6e93e3f7c13) -
|
|
9
|
+
ED-25240 minor type adjustment, make it non-breaking change due to no consumer affected
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
15
|
+
## 2.0.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [#150384](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/150384)
|
|
20
|
+
[`704af5d7d4a1a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/704af5d7d4a1a) -
|
|
21
|
+
[EDF-1668](https://product-fabric.atlassian.net/browse/EDF-1668) - add external message API
|
|
22
|
+
support into editor-plugin-engagement-platform
|
package/README.md
CHANGED
|
@@ -1,32 +1,83 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Editor Engagement Platform Plugin
|
|
2
2
|
|
|
3
|
-
Engagement
|
|
3
|
+
This plugin allows interaction with the Atlassian Engagement Platform within the editor. It provides
|
|
4
|
+
functionalities to start and stop engagement messages, as well as to check the state of these
|
|
5
|
+
messages.
|
|
4
6
|
|
|
5
7
|
**Note:** This component is designed for internal Atlassian development.
|
|
6
8
|
External contributors will be able to use this component but will not be able to submit issues.
|
|
7
9
|
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- **Start Message**: Start an engagement message with a given ID and optional variation ID.
|
|
13
|
+
- **Stop Message**: Stop an engagement message with a given ID.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
**Internal use only**
|
|
18
|
+
|
|
19
|
+
To install the plugin, use yarn:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
yarn add @atlassian/editor-plugin-engagement-platform
|
|
23
|
+
```
|
|
8
24
|
|
|
9
25
|
## Usage
|
|
10
|
-
|
|
26
|
+
|
|
11
27
|
**Internal use only**
|
|
12
28
|
|
|
13
|
-
|
|
29
|
+
To use the plugin, import it and include it in your editor setup:
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { engagementPlatformPlugin } from '@atlassian/editor-plugin-engagement-platform';
|
|
33
|
+
|
|
34
|
+
const coordinationClient = useCoordinationClient()
|
|
35
|
+
|
|
36
|
+
const { preset, editorApi } = usePreset(() => {
|
|
37
|
+
return universalPreset.add([
|
|
38
|
+
engagementPlatformPlugin,
|
|
39
|
+
{ coordinationClient },
|
|
40
|
+
]);
|
|
41
|
+
}, [universalPreset, coordinationClient]);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
To get the current state of an engagement message, you can use the following code:
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
function isMessageActive(messageId: string): boolean {
|
|
48
|
+
const messageStates = api.engagementPlatform.sharedState.currentState()?.messageStates ?? {};
|
|
49
|
+
return !!messageStates[messageId];
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Detailed docs and example usage can be found [here](https://atlaskit.atlassian.com/packages/editor/editor-plugin-engagement-platform).
|
|
14
54
|
|
|
15
|
-
|
|
55
|
+
## API
|
|
56
|
+
|
|
57
|
+
### `api.engagementPlatform.actions.startMessage(messageId: string, variationId?: string): Promise<boolean>`
|
|
58
|
+
|
|
59
|
+
Starts an engagement message with the given ID and optional variation ID.
|
|
60
|
+
|
|
61
|
+
### `api.engagementPlatform.actions.stopMessage(messageId: string): Promise<boolean>`
|
|
62
|
+
|
|
63
|
+
Stops an engagement message with the given ID.
|
|
16
64
|
|
|
17
65
|
Please see [Atlaskit - Editor Engagement Platform Plugin](https://atlaskit.atlassian.com/packages/editor/editor-plugin-engagement-platform) for documentation and examples for this package.
|
|
18
66
|
|
|
19
|
-
##
|
|
20
|
-
---
|
|
21
|
-
For internal Atlassian, visit the slack channel [#help-editor](https://atlassian.slack.com/archives/CFG3PSQ9E) for support or visit [go/editor-help](https://go/editor-help) to submit a bug.
|
|
22
|
-
## License
|
|
23
|
-
---
|
|
24
|
-
Please see [Atlassian Frontend - License](https://hello.atlassian.net/wiki/spaces/AF/pages/2589099144/Documentation#Platform-License) for more licensing information.
|
|
67
|
+
## Configuration
|
|
25
68
|
|
|
69
|
+
The plugin requires a configuration object with the following structure:
|
|
26
70
|
|
|
27
|
-
|
|
71
|
+
```typescript
|
|
72
|
+
interface EngagementPlatformPluginConfig {
|
|
73
|
+
coordinationClient: CoordinationClientType;
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Support
|
|
28
78
|
|
|
29
|
-
|
|
79
|
+
For internal Atlassian, visit the slack channel [#help-editor](https://atlassian.slack.com/archives/CFG3PSQ9E) for support or visit [go/editor-help](https://go/editor-help) to submit a bug.
|
|
30
80
|
|
|
81
|
+
## License
|
|
31
82
|
|
|
32
|
-
|
|
83
|
+
Please see [Atlassian Frontend - License](https://hello.atlassian.net/wiki/spaces/AF/pages/2589099144/Documentation#Platform-License) for more licensing information.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.startMessage = startMessage;
|
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
11
|
+
var _setMessageState = require("../pmPlugins/engagementPlatformPmPlugin/commands/setMessageState");
|
|
12
|
+
function startMessage(api, coordinationClient) {
|
|
13
|
+
return /*#__PURE__*/function () {
|
|
14
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(messageId, variationId) {
|
|
15
|
+
var _api$engagementPlatfo, _api$engagementPlatfo2;
|
|
16
|
+
var messageStates, isActive, isStarted, _api$analytics;
|
|
17
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
18
|
+
while (1) switch (_context.prev = _context.next) {
|
|
19
|
+
case 0:
|
|
20
|
+
if (api) {
|
|
21
|
+
_context.next = 2;
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
return _context.abrupt("return", false);
|
|
25
|
+
case 2:
|
|
26
|
+
messageStates = (_api$engagementPlatfo = (_api$engagementPlatfo2 = api.engagementPlatform.sharedState.currentState()) === null || _api$engagementPlatfo2 === void 0 ? void 0 : _api$engagementPlatfo2.messageStates) !== null && _api$engagementPlatfo !== void 0 ? _api$engagementPlatfo : {};
|
|
27
|
+
isActive = messageStates[messageId];
|
|
28
|
+
if (!isActive) {
|
|
29
|
+
_context.next = 6;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
return _context.abrupt("return", true);
|
|
33
|
+
case 6:
|
|
34
|
+
_context.prev = 6;
|
|
35
|
+
_context.next = 9;
|
|
36
|
+
return coordinationClient.start(messageId, variationId);
|
|
37
|
+
case 9:
|
|
38
|
+
isStarted = _context.sent;
|
|
39
|
+
if (isStarted) {
|
|
40
|
+
api.core.actions.execute((0, _setMessageState.setMessageState)(messageId, true));
|
|
41
|
+
}
|
|
42
|
+
return _context.abrupt("return", isStarted);
|
|
43
|
+
case 14:
|
|
44
|
+
_context.prev = 14;
|
|
45
|
+
_context.t0 = _context["catch"](6);
|
|
46
|
+
(_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.fireAnalyticsEvent({
|
|
47
|
+
action: _analytics.ACTION.ERRORED,
|
|
48
|
+
actionSubject: _analytics.ACTION_SUBJECT.ENGAGEMENT_PLATFORM,
|
|
49
|
+
eventType: _analytics.EVENT_TYPE.OPERATIONAL,
|
|
50
|
+
attributes: {
|
|
51
|
+
error: _context.t0 instanceof Error ? _context.t0.message : "".concat(_context.t0),
|
|
52
|
+
errorStack: _context.t0 instanceof Error ? _context.t0.stack : undefined
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return _context.abrupt("return", false);
|
|
56
|
+
case 18:
|
|
57
|
+
case "end":
|
|
58
|
+
return _context.stop();
|
|
59
|
+
}
|
|
60
|
+
}, _callee, null, [[6, 14]]);
|
|
61
|
+
}));
|
|
62
|
+
return function (_x, _x2) {
|
|
63
|
+
return _ref.apply(this, arguments);
|
|
64
|
+
};
|
|
65
|
+
}();
|
|
66
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.stopMessage = stopMessage;
|
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
11
|
+
var _setMessageState = require("../pmPlugins/engagementPlatformPmPlugin/commands/setMessageState");
|
|
12
|
+
function stopMessage(api, coordinationClient) {
|
|
13
|
+
return /*#__PURE__*/function () {
|
|
14
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(messageId) {
|
|
15
|
+
var _api$engagementPlatfo, _api$engagementPlatfo2;
|
|
16
|
+
var messageStates, isActive, isStopped, _api$analytics;
|
|
17
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
18
|
+
while (1) switch (_context.prev = _context.next) {
|
|
19
|
+
case 0:
|
|
20
|
+
if (api) {
|
|
21
|
+
_context.next = 2;
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
return _context.abrupt("return", false);
|
|
25
|
+
case 2:
|
|
26
|
+
messageStates = (_api$engagementPlatfo = (_api$engagementPlatfo2 = api.engagementPlatform.sharedState.currentState()) === null || _api$engagementPlatfo2 === void 0 ? void 0 : _api$engagementPlatfo2.messageStates) !== null && _api$engagementPlatfo !== void 0 ? _api$engagementPlatfo : {};
|
|
27
|
+
isActive = messageStates[messageId];
|
|
28
|
+
if (isActive) {
|
|
29
|
+
_context.next = 6;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
return _context.abrupt("return", true);
|
|
33
|
+
case 6:
|
|
34
|
+
_context.prev = 6;
|
|
35
|
+
_context.next = 9;
|
|
36
|
+
return coordinationClient.stop(messageId);
|
|
37
|
+
case 9:
|
|
38
|
+
isStopped = _context.sent;
|
|
39
|
+
if (isStopped) {
|
|
40
|
+
api.core.actions.execute((0, _setMessageState.setMessageState)(messageId, false));
|
|
41
|
+
}
|
|
42
|
+
return _context.abrupt("return", isStopped);
|
|
43
|
+
case 14:
|
|
44
|
+
_context.prev = 14;
|
|
45
|
+
_context.t0 = _context["catch"](6);
|
|
46
|
+
(_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.fireAnalyticsEvent({
|
|
47
|
+
action: _analytics.ACTION.ERRORED,
|
|
48
|
+
actionSubject: _analytics.ACTION_SUBJECT.ENGAGEMENT_PLATFORM,
|
|
49
|
+
eventType: _analytics.EVENT_TYPE.OPERATIONAL,
|
|
50
|
+
attributes: {
|
|
51
|
+
error: _context.t0 instanceof Error ? _context.t0.message : "".concat(_context.t0),
|
|
52
|
+
errorStack: _context.t0 instanceof Error ? _context.t0.stack : undefined
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return _context.abrupt("return", false);
|
|
56
|
+
case 18:
|
|
57
|
+
case "end":
|
|
58
|
+
return _context.stop();
|
|
59
|
+
}
|
|
60
|
+
}, _callee, null, [[6, 14]]);
|
|
61
|
+
}));
|
|
62
|
+
return function (_x) {
|
|
63
|
+
return _ref.apply(this, arguments);
|
|
64
|
+
};
|
|
65
|
+
}();
|
|
66
|
+
}
|
|
@@ -4,24 +4,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.engagementPlatformPlugin = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _startMessage = require("./actions/startMessage");
|
|
8
|
+
var _stopMessage = require("./actions/stopMessage");
|
|
9
|
+
var _engagementPlatformPmPlugin = require("./pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPlugin");
|
|
10
|
+
var _engagementPlatformPmPluginKey = require("./pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPluginKey");
|
|
8
11
|
var engagementPlatformPlugin = exports.engagementPlatformPlugin = function engagementPlatformPlugin(_ref) {
|
|
9
|
-
var config = _ref.config
|
|
12
|
+
var config = _ref.config,
|
|
13
|
+
api = _ref.api;
|
|
10
14
|
return {
|
|
11
15
|
name: 'engagementPlatform',
|
|
16
|
+
actions: {
|
|
17
|
+
startMessage: (0, _startMessage.startMessage)(api, config.coordinationClient),
|
|
18
|
+
stopMessage: (0, _stopMessage.stopMessage)(api, config.coordinationClient)
|
|
19
|
+
},
|
|
12
20
|
pmPlugins: function pmPlugins() {
|
|
13
21
|
return [{
|
|
14
|
-
name: '
|
|
22
|
+
name: 'engagementPlatformPmPlugin',
|
|
15
23
|
plugin: function plugin() {
|
|
16
|
-
return (0,
|
|
24
|
+
return (0, _engagementPlatformPmPlugin.engagementPlatformPmPlugin)(config);
|
|
17
25
|
}
|
|
18
26
|
}];
|
|
19
27
|
},
|
|
20
28
|
getSharedState: function getSharedState(editorState) {
|
|
21
|
-
if (!
|
|
29
|
+
if (!editorState) {
|
|
22
30
|
return undefined;
|
|
23
31
|
}
|
|
24
|
-
return
|
|
32
|
+
return _engagementPlatformPmPluginKey.engagementPlatformPmPluginKey.getState(editorState);
|
|
25
33
|
}
|
|
26
34
|
};
|
|
27
35
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.setMessageState = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _engagementPlatformPmPluginKey = require("../engagementPlatformPmPluginKey");
|
|
10
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
|
+
/** Set the state of a message in the Engagement Platform plugin */
|
|
13
|
+
var setMessageState = exports.setMessageState = function setMessageState(messageIs, state) {
|
|
14
|
+
return function (_ref) {
|
|
15
|
+
var _tr$getMeta;
|
|
16
|
+
var tr = _ref.tr;
|
|
17
|
+
var meta = {
|
|
18
|
+
newMessageStates: _objectSpread(_objectSpread({}, (_tr$getMeta = tr.getMeta(_engagementPlatformPmPluginKey.engagementPlatformPmPluginKey)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.messageStates), {}, (0, _defineProperty2.default)({}, messageIs, state))
|
|
19
|
+
};
|
|
20
|
+
return tr.setMeta(_engagementPlatformPmPluginKey.engagementPlatformPmPluginKey, meta);
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.engagementPlatformPmPlugin = void 0;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
11
|
+
var _engagementPlatformPmPluginKey = require("./engagementPlatformPmPluginKey");
|
|
12
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
13
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
14
|
+
var engagementPlatformPmPlugin = exports.engagementPlatformPmPlugin = function engagementPlatformPmPlugin(pluginConfig) {
|
|
15
|
+
return new _safePlugin.SafePlugin({
|
|
16
|
+
key: _engagementPlatformPmPluginKey.engagementPlatformPmPluginKey,
|
|
17
|
+
state: {
|
|
18
|
+
init: function init() {
|
|
19
|
+
return {
|
|
20
|
+
messageStates: {},
|
|
21
|
+
epComponents: pluginConfig.epComponents,
|
|
22
|
+
epHooks: pluginConfig.epHooks,
|
|
23
|
+
coordinationClient: pluginConfig.coordinationClient
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
apply: function apply(tr, pluginState) {
|
|
27
|
+
var meta = tr.getMeta(_engagementPlatformPmPluginKey.engagementPlatformPmPluginKey);
|
|
28
|
+
if (!meta) {
|
|
29
|
+
return pluginState;
|
|
30
|
+
}
|
|
31
|
+
var newState = _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
32
|
+
messageStates: _objectSpread(_objectSpread({}, pluginState.messageStates), meta.newMessageStates)
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Remove false message states to save memory
|
|
36
|
+
Object.entries(newState.messageStates).forEach(function (_ref) {
|
|
37
|
+
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
|
38
|
+
key = _ref2[0],
|
|
39
|
+
value = _ref2[1];
|
|
40
|
+
if (!value) {
|
|
41
|
+
delete newState.messageStates[key];
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return newState;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.engagementPlatformPmPluginKey = void 0;
|
|
7
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
8
|
+
var engagementPlatformPmPluginKey = exports.engagementPlatformPmPluginKey = new _state.PluginKey('engagementPlatformPmPlugin');
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import { setMessageState } from '../pmPlugins/engagementPlatformPmPlugin/commands/setMessageState';
|
|
3
|
+
export function startMessage(api, coordinationClient) {
|
|
4
|
+
return async (messageId, variationId) => {
|
|
5
|
+
var _api$engagementPlatfo, _api$engagementPlatfo2;
|
|
6
|
+
if (!api) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
const messageStates = (_api$engagementPlatfo = (_api$engagementPlatfo2 = api.engagementPlatform.sharedState.currentState()) === null || _api$engagementPlatfo2 === void 0 ? void 0 : _api$engagementPlatfo2.messageStates) !== null && _api$engagementPlatfo !== void 0 ? _api$engagementPlatfo : {};
|
|
10
|
+
const isActive = messageStates[messageId];
|
|
11
|
+
if (isActive) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const isStarted = await coordinationClient.start(messageId, variationId);
|
|
16
|
+
if (isStarted) {
|
|
17
|
+
api.core.actions.execute(setMessageState(messageId, true));
|
|
18
|
+
}
|
|
19
|
+
return isStarted;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
var _api$analytics;
|
|
22
|
+
(_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.fireAnalyticsEvent({
|
|
23
|
+
action: ACTION.ERRORED,
|
|
24
|
+
actionSubject: ACTION_SUBJECT.ENGAGEMENT_PLATFORM,
|
|
25
|
+
eventType: EVENT_TYPE.OPERATIONAL,
|
|
26
|
+
attributes: {
|
|
27
|
+
error: error instanceof Error ? error.message : `${error}`,
|
|
28
|
+
errorStack: error instanceof Error ? error.stack : undefined
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import { setMessageState } from '../pmPlugins/engagementPlatformPmPlugin/commands/setMessageState';
|
|
3
|
+
export function stopMessage(api, coordinationClient) {
|
|
4
|
+
return async messageId => {
|
|
5
|
+
var _api$engagementPlatfo, _api$engagementPlatfo2;
|
|
6
|
+
if (!api) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
const messageStates = (_api$engagementPlatfo = (_api$engagementPlatfo2 = api.engagementPlatform.sharedState.currentState()) === null || _api$engagementPlatfo2 === void 0 ? void 0 : _api$engagementPlatfo2.messageStates) !== null && _api$engagementPlatfo !== void 0 ? _api$engagementPlatfo : {};
|
|
10
|
+
const isActive = messageStates[messageId];
|
|
11
|
+
if (!isActive) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const isStopped = await coordinationClient.stop(messageId);
|
|
16
|
+
if (isStopped) {
|
|
17
|
+
api.core.actions.execute(setMessageState(messageId, false));
|
|
18
|
+
}
|
|
19
|
+
return isStopped;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
var _api$analytics;
|
|
22
|
+
(_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.fireAnalyticsEvent({
|
|
23
|
+
action: ACTION.ERRORED,
|
|
24
|
+
actionSubject: ACTION_SUBJECT.ENGAGEMENT_PLATFORM,
|
|
25
|
+
eventType: EVENT_TYPE.OPERATIONAL,
|
|
26
|
+
attributes: {
|
|
27
|
+
error: error instanceof Error ? error.message : `${error}`,
|
|
28
|
+
errorStack: error instanceof Error ? error.stack : undefined
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,20 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { startMessage } from './actions/startMessage';
|
|
2
|
+
import { stopMessage } from './actions/stopMessage';
|
|
3
|
+
import { engagementPlatformPmPlugin } from './pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPlugin';
|
|
4
|
+
import { engagementPlatformPmPluginKey } from './pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPluginKey';
|
|
2
5
|
export const engagementPlatformPlugin = ({
|
|
3
|
-
config
|
|
6
|
+
config,
|
|
7
|
+
api
|
|
4
8
|
}) => {
|
|
5
9
|
return {
|
|
6
10
|
name: 'engagementPlatform',
|
|
11
|
+
actions: {
|
|
12
|
+
startMessage: startMessage(api, config.coordinationClient),
|
|
13
|
+
stopMessage: stopMessage(api, config.coordinationClient)
|
|
14
|
+
},
|
|
7
15
|
pmPlugins() {
|
|
8
16
|
return [{
|
|
9
|
-
name: '
|
|
10
|
-
plugin: () =>
|
|
17
|
+
name: 'engagementPlatformPmPlugin',
|
|
18
|
+
plugin: () => engagementPlatformPmPlugin(config)
|
|
11
19
|
}];
|
|
12
20
|
},
|
|
13
21
|
getSharedState(editorState) {
|
|
14
|
-
if (!
|
|
22
|
+
if (!editorState) {
|
|
15
23
|
return undefined;
|
|
16
24
|
}
|
|
17
|
-
return
|
|
25
|
+
return engagementPlatformPmPluginKey.getState(editorState);
|
|
18
26
|
}
|
|
19
27
|
};
|
|
20
28
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { engagementPlatformPmPluginKey } from '../engagementPlatformPmPluginKey';
|
|
2
|
+
/** Set the state of a message in the Engagement Platform plugin */
|
|
3
|
+
export const setMessageState = (messageIs, state) => ({
|
|
4
|
+
tr
|
|
5
|
+
}) => {
|
|
6
|
+
var _tr$getMeta;
|
|
7
|
+
const meta = {
|
|
8
|
+
newMessageStates: {
|
|
9
|
+
...((_tr$getMeta = tr.getMeta(engagementPlatformPmPluginKey)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.messageStates),
|
|
10
|
+
[messageIs]: state
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
return tr.setMeta(engagementPlatformPmPluginKey, meta);
|
|
14
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import { engagementPlatformPmPluginKey } from './engagementPlatformPmPluginKey';
|
|
3
|
+
export const engagementPlatformPmPlugin = pluginConfig => {
|
|
4
|
+
return new SafePlugin({
|
|
5
|
+
key: engagementPlatformPmPluginKey,
|
|
6
|
+
state: {
|
|
7
|
+
init: () => {
|
|
8
|
+
return {
|
|
9
|
+
messageStates: {},
|
|
10
|
+
epComponents: pluginConfig.epComponents,
|
|
11
|
+
epHooks: pluginConfig.epHooks,
|
|
12
|
+
coordinationClient: pluginConfig.coordinationClient
|
|
13
|
+
};
|
|
14
|
+
},
|
|
15
|
+
apply: (tr, pluginState) => {
|
|
16
|
+
const meta = tr.getMeta(engagementPlatformPmPluginKey);
|
|
17
|
+
if (!meta) {
|
|
18
|
+
return pluginState;
|
|
19
|
+
}
|
|
20
|
+
const newState = {
|
|
21
|
+
...pluginState,
|
|
22
|
+
messageStates: {
|
|
23
|
+
...pluginState.messageStates,
|
|
24
|
+
...meta.newMessageStates
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// Remove false message states to save memory
|
|
29
|
+
Object.entries(newState.messageStates).forEach(([key, value]) => {
|
|
30
|
+
if (!value) {
|
|
31
|
+
delete newState.messageStates[key];
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return newState;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
4
|
+
import { setMessageState } from '../pmPlugins/engagementPlatformPmPlugin/commands/setMessageState';
|
|
5
|
+
export function startMessage(api, coordinationClient) {
|
|
6
|
+
return /*#__PURE__*/function () {
|
|
7
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(messageId, variationId) {
|
|
8
|
+
var _api$engagementPlatfo, _api$engagementPlatfo2;
|
|
9
|
+
var messageStates, isActive, isStarted, _api$analytics;
|
|
10
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
11
|
+
while (1) switch (_context.prev = _context.next) {
|
|
12
|
+
case 0:
|
|
13
|
+
if (api) {
|
|
14
|
+
_context.next = 2;
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
return _context.abrupt("return", false);
|
|
18
|
+
case 2:
|
|
19
|
+
messageStates = (_api$engagementPlatfo = (_api$engagementPlatfo2 = api.engagementPlatform.sharedState.currentState()) === null || _api$engagementPlatfo2 === void 0 ? void 0 : _api$engagementPlatfo2.messageStates) !== null && _api$engagementPlatfo !== void 0 ? _api$engagementPlatfo : {};
|
|
20
|
+
isActive = messageStates[messageId];
|
|
21
|
+
if (!isActive) {
|
|
22
|
+
_context.next = 6;
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
return _context.abrupt("return", true);
|
|
26
|
+
case 6:
|
|
27
|
+
_context.prev = 6;
|
|
28
|
+
_context.next = 9;
|
|
29
|
+
return coordinationClient.start(messageId, variationId);
|
|
30
|
+
case 9:
|
|
31
|
+
isStarted = _context.sent;
|
|
32
|
+
if (isStarted) {
|
|
33
|
+
api.core.actions.execute(setMessageState(messageId, true));
|
|
34
|
+
}
|
|
35
|
+
return _context.abrupt("return", isStarted);
|
|
36
|
+
case 14:
|
|
37
|
+
_context.prev = 14;
|
|
38
|
+
_context.t0 = _context["catch"](6);
|
|
39
|
+
(_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.fireAnalyticsEvent({
|
|
40
|
+
action: ACTION.ERRORED,
|
|
41
|
+
actionSubject: ACTION_SUBJECT.ENGAGEMENT_PLATFORM,
|
|
42
|
+
eventType: EVENT_TYPE.OPERATIONAL,
|
|
43
|
+
attributes: {
|
|
44
|
+
error: _context.t0 instanceof Error ? _context.t0.message : "".concat(_context.t0),
|
|
45
|
+
errorStack: _context.t0 instanceof Error ? _context.t0.stack : undefined
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return _context.abrupt("return", false);
|
|
49
|
+
case 18:
|
|
50
|
+
case "end":
|
|
51
|
+
return _context.stop();
|
|
52
|
+
}
|
|
53
|
+
}, _callee, null, [[6, 14]]);
|
|
54
|
+
}));
|
|
55
|
+
return function (_x, _x2) {
|
|
56
|
+
return _ref.apply(this, arguments);
|
|
57
|
+
};
|
|
58
|
+
}();
|
|
59
|
+
}
|