@atlaskit/editor-plugin-loom 0.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/.eslintrc.js +6 -0
- package/CHANGELOG.md +1 -0
- package/LICENSE.md +13 -0
- package/README.md +9 -0
- package/dist/cjs/commands.js +86 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/plugin.js +104 -0
- package/dist/cjs/pm-plugin.js +200 -0
- package/dist/cjs/ui/ToolbarButton.js +44 -0
- package/dist/es2019/commands.js +80 -0
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/plugin.js +95 -0
- package/dist/es2019/pm-plugin.js +160 -0
- package/dist/es2019/ui/ToolbarButton.js +41 -0
- package/dist/esm/commands.js +80 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/plugin.js +94 -0
- package/dist/esm/pm-plugin.js +188 -0
- package/dist/esm/ui/ToolbarButton.js +37 -0
- package/dist/types/commands.d.ts +22 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/plugin.d.ts +12 -0
- package/dist/types/pm-plugin.d.ts +22 -0
- package/dist/types/ui/ToolbarButton.d.ts +178 -0
- package/dist/types-ts4.5/commands.d.ts +22 -0
- package/dist/types-ts4.5/index.d.ts +2 -0
- package/dist/types-ts4.5/plugin.d.ts +12 -0
- package/dist/types-ts4.5/pm-plugin.d.ts +22 -0
- package/dist/types-ts4.5/ui/ToolbarButton.d.ts +220 -0
- package/package.json +104 -0
package/.eslintrc.js
ADDED
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @atlaskit/editor-plugin-loom
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2023 Atlassian Pty Ltd
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# EditorPluginLoom
|
|
2
|
+
|
|
3
|
+
Loom plugin for @atlaskit/editor-core
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
`import EditorPluginLoom from '@atlaskit/editor-plugin-loom';`
|
|
8
|
+
|
|
9
|
+
Detailed docs and example usage can be found [here](https://atlaskit.atlassian.com/packages/editor/editor-plugin-loom).
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.recordVideoFailed = exports.recordVideo = exports.insertVideo = exports.enableLoom = exports.disableLoom = void 0;
|
|
7
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
8
|
+
var _pmPlugin = require("./pm-plugin");
|
|
9
|
+
var enableLoom = exports.enableLoom = function enableLoom(_ref) {
|
|
10
|
+
var loomButton = _ref.loomButton;
|
|
11
|
+
return function (_ref2) {
|
|
12
|
+
var tr = _ref2.tr;
|
|
13
|
+
tr.setMeta(_pmPlugin.loomPluginKey, {
|
|
14
|
+
type: _pmPlugin.LoomPluginAction.ENABLE,
|
|
15
|
+
loomButton: loomButton
|
|
16
|
+
});
|
|
17
|
+
return tr;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
var disableLoom = exports.disableLoom = function disableLoom(_ref3) {
|
|
21
|
+
var error = _ref3.error;
|
|
22
|
+
return function (_ref4) {
|
|
23
|
+
var tr = _ref4.tr;
|
|
24
|
+
tr.setMeta(_pmPlugin.loomPluginKey, {
|
|
25
|
+
type: _pmPlugin.LoomPluginAction.DISABLE,
|
|
26
|
+
error: error
|
|
27
|
+
});
|
|
28
|
+
return tr;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
var recordVideo = exports.recordVideo = function recordVideo(_ref5) {
|
|
32
|
+
var inputMethod = _ref5.inputMethod,
|
|
33
|
+
editorAnalyticsAPI = _ref5.editorAnalyticsAPI;
|
|
34
|
+
return function (_ref6) {
|
|
35
|
+
var tr = _ref6.tr;
|
|
36
|
+
tr.setMeta(_pmPlugin.loomPluginKey, {
|
|
37
|
+
type: _pmPlugin.LoomPluginAction.RECORD_VIDEO
|
|
38
|
+
});
|
|
39
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
40
|
+
action: _analytics.ACTION.RECORD_VIDEO,
|
|
41
|
+
actionSubject: _analytics.ACTION_SUBJECT.LOOM,
|
|
42
|
+
attributes: {
|
|
43
|
+
inputMethod: inputMethod
|
|
44
|
+
},
|
|
45
|
+
eventType: _analytics.EVENT_TYPE.TRACK
|
|
46
|
+
})(tr);
|
|
47
|
+
return tr;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
var recordVideoFailed = exports.recordVideoFailed = function recordVideoFailed(_ref7) {
|
|
51
|
+
var inputMethod = _ref7.inputMethod,
|
|
52
|
+
error = _ref7.error,
|
|
53
|
+
editorAnalyticsAPI = _ref7.editorAnalyticsAPI;
|
|
54
|
+
return function (_ref8) {
|
|
55
|
+
var tr = _ref8.tr;
|
|
56
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
57
|
+
action: _analytics.ACTION.RECORD_VIDEO_FAILED,
|
|
58
|
+
actionSubject: _analytics.ACTION_SUBJECT.LOOM,
|
|
59
|
+
attributes: {
|
|
60
|
+
inputMethod: inputMethod,
|
|
61
|
+
error: error
|
|
62
|
+
},
|
|
63
|
+
eventType: _analytics.EVENT_TYPE.TRACK
|
|
64
|
+
})(tr);
|
|
65
|
+
return tr;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
var insertVideo = exports.insertVideo = function insertVideo(_ref9) {
|
|
69
|
+
var editorAnalyticsAPI = _ref9.editorAnalyticsAPI,
|
|
70
|
+
video = _ref9.video;
|
|
71
|
+
return function (_ref10) {
|
|
72
|
+
var tr = _ref10.tr;
|
|
73
|
+
tr.setMeta(_pmPlugin.loomPluginKey, {
|
|
74
|
+
type: _pmPlugin.LoomPluginAction.INSERT_VIDEO
|
|
75
|
+
});
|
|
76
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
77
|
+
action: _analytics.ACTION.INSERT_VIDEO,
|
|
78
|
+
actionSubject: _analytics.ACTION_SUBJECT.LOOM,
|
|
79
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
80
|
+
attributes: {
|
|
81
|
+
duration: video.duration
|
|
82
|
+
}
|
|
83
|
+
})(tr);
|
|
84
|
+
return tr;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.loomPlugin = void 0;
|
|
9
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _analyticsNext = require("@atlaskit/analytics-next");
|
|
11
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
12
|
+
var _messages = require("@atlaskit/editor-common/messages");
|
|
13
|
+
var _monitoring = require("@atlaskit/editor-common/monitoring");
|
|
14
|
+
var _quickInsert = require("@atlaskit/editor-common/quick-insert");
|
|
15
|
+
var _commands = require("./commands");
|
|
16
|
+
var _pmPlugin = require("./pm-plugin");
|
|
17
|
+
var _ToolbarButton = _interopRequireDefault(require("./ui/ToolbarButton"));
|
|
18
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
+
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; }
|
|
20
|
+
var loomPlugin = exports.loomPlugin = function loomPlugin(_ref) {
|
|
21
|
+
var _api$analytics;
|
|
22
|
+
var api = _ref.api;
|
|
23
|
+
var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
|
|
24
|
+
return {
|
|
25
|
+
name: 'loom',
|
|
26
|
+
usePluginHook: function usePluginHook(_ref2) {
|
|
27
|
+
var editorView = _ref2.editorView;
|
|
28
|
+
var _useAnalyticsEvents = (0, _analyticsNext.useAnalyticsEvents)(),
|
|
29
|
+
createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
|
|
30
|
+
(0, _react.useLayoutEffect)(function () {
|
|
31
|
+
var dispatch = editorView.dispatch,
|
|
32
|
+
tr = editorView.state.tr;
|
|
33
|
+
tr.setMeta(_pmPlugin.loomPluginKey, {
|
|
34
|
+
type: _pmPlugin.LoomPluginAction.SET_ANALYTICS_FUNCTION,
|
|
35
|
+
createAnalyticsEvent: createAnalyticsEvent
|
|
36
|
+
});
|
|
37
|
+
dispatch(tr);
|
|
38
|
+
}, [createAnalyticsEvent, editorView]);
|
|
39
|
+
},
|
|
40
|
+
pmPlugins: function pmPlugins() {
|
|
41
|
+
return [{
|
|
42
|
+
name: 'loom',
|
|
43
|
+
plugin: function plugin() {
|
|
44
|
+
return (0, _pmPlugin.createPlugin)(api);
|
|
45
|
+
}
|
|
46
|
+
}];
|
|
47
|
+
},
|
|
48
|
+
getSharedState: function getSharedState(editorState) {
|
|
49
|
+
if (!editorState) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
return _pmPlugin.loomPluginKey.getState(editorState);
|
|
53
|
+
},
|
|
54
|
+
pluginsOptions: {
|
|
55
|
+
// Enable inserting Loom recordings through the slash command
|
|
56
|
+
quickInsert: function quickInsert(_ref3) {
|
|
57
|
+
var formatMessage = _ref3.formatMessage;
|
|
58
|
+
return [{
|
|
59
|
+
id: 'loom',
|
|
60
|
+
title: formatMessage(_messages.toolbarInsertBlockMessages.recordVideo),
|
|
61
|
+
description: formatMessage(_messages.toolbarInsertBlockMessages.recordVideoDescription),
|
|
62
|
+
keywords: ['loom', 'record', 'video'],
|
|
63
|
+
priority: 800,
|
|
64
|
+
icon: function icon() {
|
|
65
|
+
return /*#__PURE__*/_react.default.createElement(_quickInsert.IconLoom, null);
|
|
66
|
+
},
|
|
67
|
+
action: function action(insert, editorState) {
|
|
68
|
+
var _recordVideo;
|
|
69
|
+
var tr = insert(undefined);
|
|
70
|
+
var loomState = _pmPlugin.loomPluginKey.getState(editorState);
|
|
71
|
+
if (!(loomState !== null && loomState !== void 0 && loomState.isEnabled)) {
|
|
72
|
+
var _recordVideoFailed;
|
|
73
|
+
var errorMessage = loomState === null || loomState === void 0 ? void 0 : loomState.error;
|
|
74
|
+
(0, _monitoring.logException)(new Error(errorMessage), {
|
|
75
|
+
location: 'editor-plugin-loom/quick-insert-record-video'
|
|
76
|
+
});
|
|
77
|
+
return (_recordVideoFailed = (0, _commands.recordVideoFailed)({
|
|
78
|
+
inputMethod: _analytics.INPUT_METHOD.QUICK_INSERT,
|
|
79
|
+
error: errorMessage,
|
|
80
|
+
editorAnalyticsAPI: editorAnalyticsAPI
|
|
81
|
+
})({
|
|
82
|
+
tr: tr
|
|
83
|
+
})) !== null && _recordVideoFailed !== void 0 ? _recordVideoFailed : false;
|
|
84
|
+
}
|
|
85
|
+
return (_recordVideo = (0, _commands.recordVideo)({
|
|
86
|
+
inputMethod: _analytics.INPUT_METHOD.QUICK_INSERT,
|
|
87
|
+
editorAnalyticsAPI: editorAnalyticsAPI
|
|
88
|
+
})({
|
|
89
|
+
tr: tr
|
|
90
|
+
})) !== null && _recordVideo !== void 0 ? _recordVideo : false;
|
|
91
|
+
}
|
|
92
|
+
}];
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
// Enable inserting Loom recordings through main toolbar
|
|
96
|
+
primaryToolbarComponent: function primaryToolbarComponent(_ref4) {
|
|
97
|
+
var disabled = _ref4.disabled;
|
|
98
|
+
return /*#__PURE__*/_react.default.createElement(_ToolbarButton.default, {
|
|
99
|
+
disabled: disabled,
|
|
100
|
+
api: api
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
};
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.loomPluginKey = exports.createPlugin = exports.LoomPluginAction = void 0;
|
|
9
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
10
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
13
|
+
var _monitoring = require("@atlaskit/editor-common/monitoring");
|
|
14
|
+
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
15
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
16
|
+
var _commands = require("./commands");
|
|
17
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
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; }
|
|
19
|
+
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; }
|
|
20
|
+
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; }
|
|
21
|
+
var LoomPluginAction = exports.LoomPluginAction = /*#__PURE__*/function (LoomPluginAction) {
|
|
22
|
+
LoomPluginAction[LoomPluginAction["ENABLE"] = 0] = "ENABLE";
|
|
23
|
+
LoomPluginAction[LoomPluginAction["DISABLE"] = 1] = "DISABLE";
|
|
24
|
+
LoomPluginAction[LoomPluginAction["RECORD_VIDEO"] = 2] = "RECORD_VIDEO";
|
|
25
|
+
LoomPluginAction[LoomPluginAction["INSERT_VIDEO"] = 3] = "INSERT_VIDEO";
|
|
26
|
+
LoomPluginAction[LoomPluginAction["SET_ANALYTICS_FUNCTION"] = 4] = "SET_ANALYTICS_FUNCTION";
|
|
27
|
+
return LoomPluginAction;
|
|
28
|
+
}({});
|
|
29
|
+
var loomPluginKey = exports.loomPluginKey = new _state.PluginKey('loom');
|
|
30
|
+
var LOOM_SDK_PUBLIC_APP_ID = 'e1cff63a-8ca2-4c2c-ad41-d61c54beb16a';
|
|
31
|
+
var createPlugin = exports.createPlugin = function createPlugin(api) {
|
|
32
|
+
var _api$analytics;
|
|
33
|
+
var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
|
|
34
|
+
return new _safePlugin.SafePlugin({
|
|
35
|
+
key: loomPluginKey,
|
|
36
|
+
state: {
|
|
37
|
+
init: function init() {
|
|
38
|
+
return {
|
|
39
|
+
isEnabled: false,
|
|
40
|
+
loomButton: null,
|
|
41
|
+
isRecordingVideo: false,
|
|
42
|
+
error: undefined,
|
|
43
|
+
createAnalyticsEvent: undefined
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
apply: function apply(tr, pluginState) {
|
|
47
|
+
var _tr$getMeta, _pluginState$loomButt;
|
|
48
|
+
var action = (_tr$getMeta = tr.getMeta(loomPluginKey)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.type;
|
|
49
|
+
switch (action) {
|
|
50
|
+
case LoomPluginAction.SET_ANALYTICS_FUNCTION:
|
|
51
|
+
var _tr$getMeta2 = tr.getMeta(loomPluginKey),
|
|
52
|
+
createAnalyticsEvent = _tr$getMeta2.createAnalyticsEvent;
|
|
53
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
54
|
+
createAnalyticsEvent: createAnalyticsEvent
|
|
55
|
+
});
|
|
56
|
+
case LoomPluginAction.ENABLE:
|
|
57
|
+
var _tr$getMeta3 = tr.getMeta(loomPluginKey),
|
|
58
|
+
loomButton = _tr$getMeta3.loomButton;
|
|
59
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
60
|
+
isEnabled: true,
|
|
61
|
+
loomButton: loomButton
|
|
62
|
+
});
|
|
63
|
+
case LoomPluginAction.DISABLE:
|
|
64
|
+
var _tr$getMeta4 = tr.getMeta(loomPluginKey),
|
|
65
|
+
error = _tr$getMeta4.error;
|
|
66
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
67
|
+
isEnabled: false,
|
|
68
|
+
loomButton: null,
|
|
69
|
+
error: error
|
|
70
|
+
});
|
|
71
|
+
case LoomPluginAction.RECORD_VIDEO:
|
|
72
|
+
// Click the unmounted button in state that has the Loom SDK attached
|
|
73
|
+
pluginState === null || pluginState === void 0 || (_pluginState$loomButt = pluginState.loomButton) === null || _pluginState$loomButt === void 0 || _pluginState$loomButt.click();
|
|
74
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
75
|
+
isRecordingVideo: true
|
|
76
|
+
});
|
|
77
|
+
case LoomPluginAction.INSERT_VIDEO:
|
|
78
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
79
|
+
isRecordingVideo: false
|
|
80
|
+
});
|
|
81
|
+
default:
|
|
82
|
+
return pluginState;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
view: function view(editorView) {
|
|
87
|
+
var setupLoom = /*#__PURE__*/function () {
|
|
88
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
|
|
89
|
+
var _yield$import, isSupported, setup, _yield$isSupported, supported, error, _pluginState, _yield$setup, configureButton, loomButton, sdkButton, pluginState;
|
|
90
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
91
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
92
|
+
case 0:
|
|
93
|
+
_context2.next = 2;
|
|
94
|
+
return Promise.resolve().then(function () {
|
|
95
|
+
return _interopRequireWildcard(require( /* webpackChunkName: "@atlaskit-internal_editor-loom-sdk" */'@loomhq/record-sdk'));
|
|
96
|
+
});
|
|
97
|
+
case 2:
|
|
98
|
+
_yield$import = _context2.sent;
|
|
99
|
+
isSupported = _yield$import.isSupported;
|
|
100
|
+
setup = _yield$import.setup;
|
|
101
|
+
_context2.next = 7;
|
|
102
|
+
return isSupported();
|
|
103
|
+
case 7:
|
|
104
|
+
_yield$isSupported = _context2.sent;
|
|
105
|
+
supported = _yield$isSupported.supported;
|
|
106
|
+
error = _yield$isSupported.error;
|
|
107
|
+
if (supported) {
|
|
108
|
+
_context2.next = 16;
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
// Keep plugin state update and analytics separate to avoid accidentally not updating
|
|
112
|
+
// plugin state due to collab-edit filtering out transactions with steps
|
|
113
|
+
api === null || api === void 0 || api.core.actions.execute((0, _commands.disableLoom)({
|
|
114
|
+
error: error
|
|
115
|
+
}));
|
|
116
|
+
(0, _monitoring.logException)(new Error(error), {
|
|
117
|
+
location: 'editor-plugin-loom/sdk-initialisation'
|
|
118
|
+
});
|
|
119
|
+
// We're not combining the analytics steps into the enable / disable commands because the collab-edit plugin
|
|
120
|
+
// filters out any transactions with steps (even analytics) when it's initialising
|
|
121
|
+
_pluginState = loomPluginKey.getState(editorView.state);
|
|
122
|
+
(0, _analytics.fireAnalyticsEvent)(_pluginState === null || _pluginState === void 0 ? void 0 : _pluginState.createAnalyticsEvent)({
|
|
123
|
+
payload: {
|
|
124
|
+
action: _analytics.ACTION.ERRORED,
|
|
125
|
+
actionSubject: _analytics.ACTION_SUBJECT.LOOM,
|
|
126
|
+
eventType: _analytics.EVENT_TYPE.OPERATIONAL,
|
|
127
|
+
attributes: {
|
|
128
|
+
error: error
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
return _context2.abrupt("return");
|
|
133
|
+
case 16:
|
|
134
|
+
_context2.next = 18;
|
|
135
|
+
return setup({
|
|
136
|
+
publicAppId: LOOM_SDK_PUBLIC_APP_ID
|
|
137
|
+
});
|
|
138
|
+
case 18:
|
|
139
|
+
_yield$setup = _context2.sent;
|
|
140
|
+
configureButton = _yield$setup.configureButton;
|
|
141
|
+
// Hidden element to work around the SDK API
|
|
142
|
+
loomButton = document.createElement('button');
|
|
143
|
+
sdkButton = configureButton({
|
|
144
|
+
element: loomButton
|
|
145
|
+
}); // Attach insertion logic to the event handlers on the SDK
|
|
146
|
+
sdkButton.on('insert-click', /*#__PURE__*/function () {
|
|
147
|
+
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(video) {
|
|
148
|
+
var _api$hyperlink;
|
|
149
|
+
var state, dispatch, pos;
|
|
150
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
151
|
+
while (1) switch (_context.prev = _context.next) {
|
|
152
|
+
case 0:
|
|
153
|
+
state = editorView.state, dispatch = editorView.dispatch;
|
|
154
|
+
pos = editorView.state.selection.from;
|
|
155
|
+
api === null || api === void 0 || (_api$hyperlink = api.hyperlink) === null || _api$hyperlink === void 0 || _api$hyperlink.actions.insertLink(_analytics.INPUT_METHOD.TYPEAHEAD, pos,
|
|
156
|
+
// from === to, don't replace text to avoid accidental content loss
|
|
157
|
+
pos, video.sharedUrl, video.title, undefined, undefined, undefined, 'embed' // Convert to embed card instead of inline
|
|
158
|
+
)(state, dispatch);
|
|
159
|
+
api === null || api === void 0 || api.core.actions.execute((0, _commands.insertVideo)({
|
|
160
|
+
editorAnalyticsAPI: editorAnalyticsAPI,
|
|
161
|
+
video: video
|
|
162
|
+
}));
|
|
163
|
+
case 4:
|
|
164
|
+
case "end":
|
|
165
|
+
return _context.stop();
|
|
166
|
+
}
|
|
167
|
+
}, _callee);
|
|
168
|
+
}));
|
|
169
|
+
return function (_x) {
|
|
170
|
+
return _ref2.apply(this, arguments);
|
|
171
|
+
};
|
|
172
|
+
}());
|
|
173
|
+
api === null || api === void 0 || api.core.actions.execute((0, _commands.enableLoom)({
|
|
174
|
+
loomButton: loomButton
|
|
175
|
+
}));
|
|
176
|
+
// We're not combining the analytics steps into the enable / disable commands because the collab-edit plugin
|
|
177
|
+
// filters out any transactions with steps (even analytics) when it's initialising
|
|
178
|
+
pluginState = loomPluginKey.getState(editorView.state);
|
|
179
|
+
(0, _analytics.fireAnalyticsEvent)(pluginState === null || pluginState === void 0 ? void 0 : pluginState.createAnalyticsEvent)({
|
|
180
|
+
payload: {
|
|
181
|
+
action: _analytics.ACTION.INITIALISED,
|
|
182
|
+
actionSubject: _analytics.ACTION_SUBJECT.LOOM,
|
|
183
|
+
eventType: _analytics.EVENT_TYPE.OPERATIONAL
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
case 26:
|
|
187
|
+
case "end":
|
|
188
|
+
return _context2.stop();
|
|
189
|
+
}
|
|
190
|
+
}, _callee2);
|
|
191
|
+
}));
|
|
192
|
+
return function setupLoom() {
|
|
193
|
+
return _ref.apply(this, arguments);
|
|
194
|
+
};
|
|
195
|
+
}();
|
|
196
|
+
setupLoom();
|
|
197
|
+
return {};
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _reactIntlNext = require("react-intl-next");
|
|
10
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
11
|
+
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
12
|
+
var _messages = require("@atlaskit/editor-common/messages");
|
|
13
|
+
var _uiMenu = require("@atlaskit/editor-common/ui-menu");
|
|
14
|
+
var _videoCircle = _interopRequireDefault(require("@atlaskit/icon/glyph/video-circle"));
|
|
15
|
+
var _commands = require("../commands");
|
|
16
|
+
var LoomToolbarButton = function LoomToolbarButton(_ref) {
|
|
17
|
+
var disabled = _ref.disabled,
|
|
18
|
+
api = _ref.api,
|
|
19
|
+
formatMessage = _ref.intl.formatMessage;
|
|
20
|
+
var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['loom']),
|
|
21
|
+
loomState = _useSharedPluginState.loomState;
|
|
22
|
+
if (!loomState) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
var label = formatMessage(_messages.toolbarInsertBlockMessages.recordVideo);
|
|
26
|
+
return /*#__PURE__*/_react.default.createElement(_uiMenu.ToolbarButton, {
|
|
27
|
+
buttonId: _uiMenu.TOOLBAR_BUTTON.RECORD_VIDEO,
|
|
28
|
+
onClick: function onClick() {
|
|
29
|
+
var _api$analytics;
|
|
30
|
+
return api === null || api === void 0 ? void 0 : api.core.actions.execute((0, _commands.recordVideo)({
|
|
31
|
+
inputMethod: _analytics.INPUT_METHOD.TOOLBAR,
|
|
32
|
+
editorAnalyticsAPI: api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
// Disable the icon while the SDK isn't initialised
|
|
36
|
+
,
|
|
37
|
+
disabled: disabled || !(loomState !== null && loomState !== void 0 && loomState.isEnabled),
|
|
38
|
+
title: label,
|
|
39
|
+
iconBefore: /*#__PURE__*/_react.default.createElement(_videoCircle.default, {
|
|
40
|
+
label: label
|
|
41
|
+
})
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var _default = exports.default = (0, _reactIntlNext.injectIntl)(LoomToolbarButton);
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import { LoomPluginAction, loomPluginKey } from './pm-plugin';
|
|
3
|
+
export const enableLoom = ({
|
|
4
|
+
loomButton
|
|
5
|
+
}) => ({
|
|
6
|
+
tr
|
|
7
|
+
}) => {
|
|
8
|
+
tr.setMeta(loomPluginKey, {
|
|
9
|
+
type: LoomPluginAction.ENABLE,
|
|
10
|
+
loomButton
|
|
11
|
+
});
|
|
12
|
+
return tr;
|
|
13
|
+
};
|
|
14
|
+
export const disableLoom = ({
|
|
15
|
+
error
|
|
16
|
+
}) => ({
|
|
17
|
+
tr
|
|
18
|
+
}) => {
|
|
19
|
+
tr.setMeta(loomPluginKey, {
|
|
20
|
+
type: LoomPluginAction.DISABLE,
|
|
21
|
+
error
|
|
22
|
+
});
|
|
23
|
+
return tr;
|
|
24
|
+
};
|
|
25
|
+
export const recordVideo = ({
|
|
26
|
+
inputMethod,
|
|
27
|
+
editorAnalyticsAPI
|
|
28
|
+
}) => ({
|
|
29
|
+
tr
|
|
30
|
+
}) => {
|
|
31
|
+
tr.setMeta(loomPluginKey, {
|
|
32
|
+
type: LoomPluginAction.RECORD_VIDEO
|
|
33
|
+
});
|
|
34
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
35
|
+
action: ACTION.RECORD_VIDEO,
|
|
36
|
+
actionSubject: ACTION_SUBJECT.LOOM,
|
|
37
|
+
attributes: {
|
|
38
|
+
inputMethod
|
|
39
|
+
},
|
|
40
|
+
eventType: EVENT_TYPE.TRACK
|
|
41
|
+
})(tr);
|
|
42
|
+
return tr;
|
|
43
|
+
};
|
|
44
|
+
export const recordVideoFailed = ({
|
|
45
|
+
inputMethod,
|
|
46
|
+
error,
|
|
47
|
+
editorAnalyticsAPI
|
|
48
|
+
}) => ({
|
|
49
|
+
tr
|
|
50
|
+
}) => {
|
|
51
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
52
|
+
action: ACTION.RECORD_VIDEO_FAILED,
|
|
53
|
+
actionSubject: ACTION_SUBJECT.LOOM,
|
|
54
|
+
attributes: {
|
|
55
|
+
inputMethod,
|
|
56
|
+
error
|
|
57
|
+
},
|
|
58
|
+
eventType: EVENT_TYPE.TRACK
|
|
59
|
+
})(tr);
|
|
60
|
+
return tr;
|
|
61
|
+
};
|
|
62
|
+
export const insertVideo = ({
|
|
63
|
+
editorAnalyticsAPI,
|
|
64
|
+
video
|
|
65
|
+
}) => ({
|
|
66
|
+
tr
|
|
67
|
+
}) => {
|
|
68
|
+
tr.setMeta(loomPluginKey, {
|
|
69
|
+
type: LoomPluginAction.INSERT_VIDEO
|
|
70
|
+
});
|
|
71
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
72
|
+
action: ACTION.INSERT_VIDEO,
|
|
73
|
+
actionSubject: ACTION_SUBJECT.LOOM,
|
|
74
|
+
eventType: EVENT_TYPE.TRACK,
|
|
75
|
+
attributes: {
|
|
76
|
+
duration: video.duration
|
|
77
|
+
}
|
|
78
|
+
})(tr);
|
|
79
|
+
return tr;
|
|
80
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { loomPlugin } from './plugin';
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import React, { useLayoutEffect } from 'react';
|
|
2
|
+
import { useAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
3
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
4
|
+
import { toolbarInsertBlockMessages } from '@atlaskit/editor-common/messages';
|
|
5
|
+
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
6
|
+
import { IconLoom } from '@atlaskit/editor-common/quick-insert';
|
|
7
|
+
import { recordVideo, recordVideoFailed } from './commands';
|
|
8
|
+
import { createPlugin, LoomPluginAction, loomPluginKey } from './pm-plugin';
|
|
9
|
+
import LoomToolbarButton from './ui/ToolbarButton';
|
|
10
|
+
export const loomPlugin = ({
|
|
11
|
+
api
|
|
12
|
+
}) => {
|
|
13
|
+
var _api$analytics;
|
|
14
|
+
const editorAnalyticsAPI = api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
|
|
15
|
+
return {
|
|
16
|
+
name: 'loom',
|
|
17
|
+
usePluginHook({
|
|
18
|
+
editorView
|
|
19
|
+
}) {
|
|
20
|
+
const {
|
|
21
|
+
createAnalyticsEvent
|
|
22
|
+
} = useAnalyticsEvents();
|
|
23
|
+
useLayoutEffect(() => {
|
|
24
|
+
const {
|
|
25
|
+
dispatch,
|
|
26
|
+
state: {
|
|
27
|
+
tr
|
|
28
|
+
}
|
|
29
|
+
} = editorView;
|
|
30
|
+
tr.setMeta(loomPluginKey, {
|
|
31
|
+
type: LoomPluginAction.SET_ANALYTICS_FUNCTION,
|
|
32
|
+
createAnalyticsEvent
|
|
33
|
+
});
|
|
34
|
+
dispatch(tr);
|
|
35
|
+
}, [createAnalyticsEvent, editorView]);
|
|
36
|
+
},
|
|
37
|
+
pmPlugins: () => [{
|
|
38
|
+
name: 'loom',
|
|
39
|
+
plugin: () => createPlugin(api)
|
|
40
|
+
}],
|
|
41
|
+
getSharedState(editorState) {
|
|
42
|
+
if (!editorState) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
return loomPluginKey.getState(editorState);
|
|
46
|
+
},
|
|
47
|
+
pluginsOptions: {
|
|
48
|
+
// Enable inserting Loom recordings through the slash command
|
|
49
|
+
quickInsert: ({
|
|
50
|
+
formatMessage
|
|
51
|
+
}) => [{
|
|
52
|
+
id: 'loom',
|
|
53
|
+
title: formatMessage(toolbarInsertBlockMessages.recordVideo),
|
|
54
|
+
description: formatMessage(toolbarInsertBlockMessages.recordVideoDescription),
|
|
55
|
+
keywords: ['loom', 'record', 'video'],
|
|
56
|
+
priority: 800,
|
|
57
|
+
icon: () => /*#__PURE__*/React.createElement(IconLoom, null),
|
|
58
|
+
action(insert, editorState) {
|
|
59
|
+
var _recordVideo;
|
|
60
|
+
const tr = insert(undefined);
|
|
61
|
+
const loomState = loomPluginKey.getState(editorState);
|
|
62
|
+
if (!(loomState !== null && loomState !== void 0 && loomState.isEnabled)) {
|
|
63
|
+
var _recordVideoFailed;
|
|
64
|
+
const errorMessage = loomState === null || loomState === void 0 ? void 0 : loomState.error;
|
|
65
|
+
logException(new Error(errorMessage), {
|
|
66
|
+
location: 'editor-plugin-loom/quick-insert-record-video'
|
|
67
|
+
});
|
|
68
|
+
return (_recordVideoFailed = recordVideoFailed({
|
|
69
|
+
inputMethod: INPUT_METHOD.QUICK_INSERT,
|
|
70
|
+
error: errorMessage,
|
|
71
|
+
editorAnalyticsAPI
|
|
72
|
+
})({
|
|
73
|
+
tr
|
|
74
|
+
})) !== null && _recordVideoFailed !== void 0 ? _recordVideoFailed : false;
|
|
75
|
+
}
|
|
76
|
+
return (_recordVideo = recordVideo({
|
|
77
|
+
inputMethod: INPUT_METHOD.QUICK_INSERT,
|
|
78
|
+
editorAnalyticsAPI
|
|
79
|
+
})({
|
|
80
|
+
tr
|
|
81
|
+
})) !== null && _recordVideo !== void 0 ? _recordVideo : false;
|
|
82
|
+
}
|
|
83
|
+
}]
|
|
84
|
+
},
|
|
85
|
+
// Enable inserting Loom recordings through main toolbar
|
|
86
|
+
primaryToolbarComponent({
|
|
87
|
+
disabled
|
|
88
|
+
}) {
|
|
89
|
+
return /*#__PURE__*/React.createElement(LoomToolbarButton, {
|
|
90
|
+
disabled: disabled,
|
|
91
|
+
api: api
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
};
|