@atlaskit/editor-plugin-loom 2.8.3 → 3.0.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/cjs/commands.js +109 -2
  3. package/dist/cjs/plugin.js +12 -58
  4. package/dist/cjs/pm-plugin.js +2 -78
  5. package/dist/cjs/types.js +5 -1
  6. package/dist/cjs/ui/PrimaryToolbarButton.js +99 -0
  7. package/dist/cjs/ui/{ToolbarButton.js → ToolbarButtonComponent.js} +43 -24
  8. package/dist/cjs/ui/quickInsert.js +56 -0
  9. package/dist/es2019/commands.js +93 -0
  10. package/dist/es2019/plugin.js +15 -57
  11. package/dist/es2019/pm-plugin.js +3 -64
  12. package/dist/es2019/types.js +1 -0
  13. package/dist/es2019/ui/PrimaryToolbarButton.js +84 -0
  14. package/dist/es2019/ui/{ToolbarButton.js → ToolbarButtonComponent.js} +40 -22
  15. package/dist/es2019/ui/quickInsert.js +44 -0
  16. package/dist/esm/commands.js +107 -1
  17. package/dist/esm/plugin.js +13 -58
  18. package/dist/esm/pm-plugin.js +3 -79
  19. package/dist/esm/types.js +1 -0
  20. package/dist/esm/ui/PrimaryToolbarButton.js +90 -0
  21. package/dist/esm/ui/{ToolbarButton.js → ToolbarButtonComponent.js} +39 -21
  22. package/dist/esm/ui/quickInsert.js +49 -0
  23. package/dist/types/commands.d.ts +5 -1
  24. package/dist/types/index.d.ts +1 -1
  25. package/dist/types/plugin.d.ts +14 -3
  26. package/dist/types/types.d.ts +32 -1
  27. package/dist/types/ui/PrimaryToolbarButton.d.ts +4 -0
  28. package/dist/types/ui/ToolbarButtonComponent.d.ts +20 -0
  29. package/dist/types/ui/quickInsert.d.ts +3 -0
  30. package/dist/types-ts4.5/commands.d.ts +5 -1
  31. package/dist/types-ts4.5/index.d.ts +1 -1
  32. package/dist/types-ts4.5/plugin.d.ts +14 -3
  33. package/dist/types-ts4.5/types.d.ts +32 -1
  34. package/dist/types-ts4.5/ui/PrimaryToolbarButton.d.ts +4 -0
  35. package/dist/types-ts4.5/ui/ToolbarButtonComponent.d.ts +20 -0
  36. package/dist/types-ts4.5/ui/quickInsert.d.ts +3 -0
  37. package/package.json +5 -3
  38. package/.eslintrc.js +0 -6
  39. package/dist/types/ui/ToolbarButton.d.ts +0 -798
  40. package/dist/types-ts4.5/ui/ToolbarButton.d.ts +0 -956
@@ -1,5 +1,7 @@
1
1
  import { ACTION, ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
+ import { logException } from '@atlaskit/editor-common/monitoring';
2
3
  import { LoomPluginAction, loomPluginKey } from './pm-plugin';
4
+ import { getQuickInsertItem } from './ui/quickInsert';
3
5
  export const enableLoom = ({
4
6
  loomButton
5
7
  }) => ({
@@ -113,4 +115,95 @@ export const insertLoom = (editorView, api, video, positionType) => {
113
115
  } = getPositions(state.tr, positionType);
114
116
  return (_api$hyperlink$action = api === null || api === void 0 ? void 0 : (_api$hyperlink = api.hyperlink) === null || _api$hyperlink === void 0 ? void 0 : _api$hyperlink.actions.insertLink(INPUT_METHOD.TYPEAHEAD, from, to, video.sharedUrl, video.title, undefined, undefined, undefined, 'embed' // Convert to embed card instead of inline
115
117
  )(state, dispatch)) !== null && _api$hyperlink$action !== void 0 ? _api$hyperlink$action : false;
118
+ };
119
+ export const executeRecordVideo = api => {
120
+ var _api$core, _api$analytics;
121
+ api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(recordVideo({
122
+ inputMethod: INPUT_METHOD.TOOLBAR,
123
+ editorAnalyticsAPI: api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions
124
+ }));
125
+ };
126
+ export const setupLoom = async (loomProvider, api, editorView, isAfterEditorLoaded) => {
127
+ var _api$core4;
128
+ const clientResult = await loomProvider.getClient();
129
+ if (clientResult.status === 'error') {
130
+ var _api$core2, _api$analytics2;
131
+ api === null || api === void 0 ? void 0 : (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions.execute(disableLoom({
132
+ error: clientResult.message
133
+ }));
134
+ logException(new Error(clientResult.message), {
135
+ location: 'editor-plugin-loom/sdk-initialisation'
136
+ });
137
+ api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions.fireAnalyticsEvent({
138
+ action: ACTION.ERRORED,
139
+ actionSubject: ACTION_SUBJECT.LOOM,
140
+ eventType: EVENT_TYPE.OPERATIONAL,
141
+ attributes: {
142
+ error: clientResult.message
143
+ }
144
+ });
145
+ return {
146
+ error: clientResult.message
147
+ };
148
+ }
149
+ const {
150
+ attachToButton
151
+ } = clientResult.client;
152
+
153
+ // Hidden element to work around the SDK API
154
+ const loomButton = document.createElement('button');
155
+ attachToButton({
156
+ button: loomButton,
157
+ onInsert: video => {
158
+ var _api$hyperlink2, _api$core3, _api$analytics3;
159
+ if (!editorView) {
160
+ return;
161
+ }
162
+ const {
163
+ state,
164
+ dispatch
165
+ } = editorView;
166
+ const pos = state.selection.from;
167
+ api === null || api === void 0 ? void 0 : (_api$hyperlink2 = api.hyperlink) === null || _api$hyperlink2 === void 0 ? void 0 : _api$hyperlink2.actions.insertLink(INPUT_METHOD.TYPEAHEAD, pos,
168
+ // from === to, don't replace text to avoid accidental content loss
169
+ pos, video.sharedUrl, video.title, undefined, undefined, undefined, 'embed' // Convert to embed card instead of inline
170
+ )(state, dispatch);
171
+ api === null || api === void 0 ? void 0 : (_api$core3 = api.core) === null || _api$core3 === void 0 ? void 0 : _api$core3.actions.execute(insertVideo({
172
+ editorAnalyticsAPI: api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions,
173
+ video
174
+ }));
175
+ }
176
+ });
177
+ api === null || api === void 0 ? void 0 : (_api$core4 = api.core) === null || _api$core4 === void 0 ? void 0 : _api$core4.actions.execute(({
178
+ tr
179
+ }) => {
180
+ enableLoom({
181
+ loomButton
182
+ })({
183
+ tr
184
+ });
185
+ if (isAfterEditorLoaded) {
186
+ var _api$quickInsert, _api$analytics4, _api$analytics5;
187
+ api === null || api === void 0 ? void 0 : (_api$quickInsert = api.quickInsert) === null || _api$quickInsert === void 0 ? void 0 : _api$quickInsert.commands.addQuickInsertItem(getQuickInsertItem(api === null || api === void 0 ? void 0 : (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions))({
188
+ tr
189
+ });
190
+ api === null || api === void 0 ? void 0 : (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions.attachAnalyticsEvent({
191
+ action: ACTION.INITIALISED,
192
+ actionSubject: ACTION_SUBJECT.LOOM,
193
+ eventType: EVENT_TYPE.OPERATIONAL
194
+ })(tr);
195
+ }
196
+ return tr;
197
+ });
198
+ if (!isAfterEditorLoaded) {
199
+ var _api$analytics6;
200
+ // We're not combining the analytics steps into the enable / disable commands because the collab-edit plugin
201
+ // filters out any transactions with steps (even analytics) when it's initialising
202
+ api === null || api === void 0 ? void 0 : (_api$analytics6 = api.analytics) === null || _api$analytics6 === void 0 ? void 0 : _api$analytics6.actions.fireAnalyticsEvent({
203
+ action: ACTION.INITIALISED,
204
+ actionSubject: ACTION_SUBJECT.LOOM,
205
+ eventType: EVENT_TYPE.OPERATIONAL
206
+ });
207
+ }
208
+ return {};
116
209
  };
@@ -1,12 +1,8 @@
1
- import React from 'react';
2
- import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
- import { toolbarInsertBlockMessages } from '@atlaskit/editor-common/messages';
4
- import { logException } from '@atlaskit/editor-common/monitoring';
5
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
- import { LoomIcon } from '@atlaskit/logo';
7
- import { insertLoom, recordVideo, recordVideoFailed } from './commands';
2
+ import { insertLoom, recordVideo, setupLoom } from './commands';
8
3
  import { createPlugin, loomPluginKey } from './pm-plugin';
9
- import LoomToolbarButton from './ui/ToolbarButton';
4
+ import { loomPrimaryToolbarComponent } from './ui/PrimaryToolbarButton';
5
+ import { getQuickInsertItem } from './ui/quickInsert';
10
6
  export const loomPlugin = ({
11
7
  config,
12
8
  api
@@ -20,19 +16,7 @@ export const loomPlugin = ({
20
16
  const editorViewRef = {
21
17
  current: null
22
18
  };
23
- const primaryToolbarComponent = ({
24
- disabled,
25
- appearance
26
- }) => {
27
- if (!config.shouldShowToolbarButton) {
28
- return null;
29
- }
30
- return /*#__PURE__*/React.createElement(LoomToolbarButton, {
31
- disabled: disabled,
32
- api: api,
33
- appearance: appearance
34
- });
35
- };
19
+ const primaryToolbarComponent = loomPrimaryToolbarComponent(config, api);
36
20
  api === null || api === void 0 ? void 0 : (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 ? void 0 : _api$primaryToolbar.actions.registerComponent({
37
21
  name: 'loom',
38
22
  component: primaryToolbarComponent
@@ -41,7 +25,12 @@ export const loomPlugin = ({
41
25
  name: 'loom',
42
26
  actions: {
43
27
  recordVideo,
44
- insertLoom: (video, positionType) => insertLoom(editorViewRef.current, api, video, positionType)
28
+ insertLoom: (video, positionType) => insertLoom(editorViewRef.current, api, video, positionType),
29
+ initLoom: ({
30
+ loomProvider
31
+ }) => {
32
+ return setupLoom(loomProvider, api, editorViewRef.current, true);
33
+ }
45
34
  },
46
35
  pmPlugins: () => [{
47
36
  name: 'loom',
@@ -74,43 +63,12 @@ export const loomPlugin = ({
74
63
  },
75
64
  pluginsOptions: {
76
65
  // Enable inserting Loom recordings through the slash command
77
- quickInsert: ({
78
- formatMessage
79
- }) => [{
80
- id: 'loom',
81
- title: formatMessage(toolbarInsertBlockMessages.recordVideo),
82
- description: formatMessage(toolbarInsertBlockMessages.recordVideoDescription),
83
- keywords: ['loom', 'record', 'video'],
84
- priority: 800,
85
- icon: () => /*#__PURE__*/React.createElement(LoomIcon, {
86
- appearance: "brand"
87
- }),
88
- action(insert, editorState) {
89
- var _recordVideo;
90
- const tr = insert(undefined);
91
- const loomState = loomPluginKey.getState(editorState);
92
- if (!(loomState !== null && loomState !== void 0 && loomState.isEnabled)) {
93
- var _recordVideoFailed;
94
- const errorMessage = loomState === null || loomState === void 0 ? void 0 : loomState.error;
95
- logException(new Error(errorMessage), {
96
- location: 'editor-plugin-loom/quick-insert-record-video'
97
- });
98
- return (_recordVideoFailed = recordVideoFailed({
99
- inputMethod: INPUT_METHOD.QUICK_INSERT,
100
- error: errorMessage,
101
- editorAnalyticsAPI
102
- })({
103
- tr
104
- })) !== null && _recordVideoFailed !== void 0 ? _recordVideoFailed : false;
105
- }
106
- return (_recordVideo = recordVideo({
107
- inputMethod: INPUT_METHOD.QUICK_INSERT,
108
- editorAnalyticsAPI
109
- })({
110
- tr
111
- })) !== null && _recordVideo !== void 0 ? _recordVideo : false;
66
+ quickInsert: intl => {
67
+ if (config.loomProvider) {
68
+ return getQuickInsertItem(editorAnalyticsAPI)(intl);
112
69
  }
113
- }]
70
+ return [];
71
+ }
114
72
  },
115
73
  // Enable inserting Loom recordings through main toolbar
116
74
  primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) ? primaryToolbarComponent : undefined
@@ -1,8 +1,6 @@
1
- import { ACTION, ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
- import { logException } from '@atlaskit/editor-common/monitoring';
3
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
5
- import { disableLoom, enableLoom, insertVideo } from './commands';
3
+ import { setupLoom } from './commands';
6
4
  export let LoomPluginAction = /*#__PURE__*/function (LoomPluginAction) {
7
5
  LoomPluginAction[LoomPluginAction["ENABLE"] = 0] = "ENABLE";
8
6
  LoomPluginAction[LoomPluginAction["DISABLE"] = 1] = "DISABLE";
@@ -15,8 +13,6 @@ export const createPlugin = ({
15
13
  config,
16
14
  api
17
15
  }) => {
18
- var _api$analytics;
19
- const editorAnalyticsAPI = api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
20
16
  return new SafePlugin({
21
17
  key: loomPluginKey,
22
18
  state: {
@@ -67,65 +63,8 @@ export const createPlugin = ({
67
63
  }
68
64
  },
69
65
  view(editorView) {
70
- const setupLoom = async () => {
71
- var _api$core3, _api$analytics3;
72
- const clientResult = await config.loomProvider.getClient();
73
- if (clientResult.status === 'error') {
74
- var _api$core, _api$analytics2;
75
- api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(disableLoom({
76
- error: clientResult.message
77
- }));
78
- logException(new Error(clientResult.message), {
79
- location: 'editor-plugin-loom/sdk-initialisation'
80
- });
81
- api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions.fireAnalyticsEvent({
82
- action: ACTION.ERRORED,
83
- actionSubject: ACTION_SUBJECT.LOOM,
84
- eventType: EVENT_TYPE.OPERATIONAL,
85
- attributes: {
86
- error: clientResult.message
87
- }
88
- });
89
- return;
90
- }
91
- const {
92
- attachToButton
93
- } = clientResult.client;
94
-
95
- // Hidden element to work around the SDK API
96
- const loomButton = document.createElement('button');
97
- attachToButton({
98
- button: loomButton,
99
- onInsert: video => {
100
- var _api$hyperlink, _api$core2;
101
- const {
102
- state,
103
- dispatch
104
- } = editorView;
105
- const pos = editorView.state.selection.from;
106
- api === null || api === void 0 ? void 0 : (_api$hyperlink = api.hyperlink) === null || _api$hyperlink === void 0 ? void 0 : _api$hyperlink.actions.insertLink(INPUT_METHOD.TYPEAHEAD, pos,
107
- // from === to, don't replace text to avoid accidental content loss
108
- pos, video.sharedUrl, video.title, undefined, undefined, undefined, 'embed' // Convert to embed card instead of inline
109
- )(state, dispatch);
110
- api === null || api === void 0 ? void 0 : (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions.execute(insertVideo({
111
- editorAnalyticsAPI,
112
- video
113
- }));
114
- }
115
- });
116
- api === null || api === void 0 ? void 0 : (_api$core3 = api.core) === null || _api$core3 === void 0 ? void 0 : _api$core3.actions.execute(enableLoom({
117
- loomButton
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
- api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions.fireAnalyticsEvent({
122
- action: ACTION.INITIALISED,
123
- actionSubject: ACTION_SUBJECT.LOOM,
124
- eventType: EVENT_TYPE.OPERATIONAL
125
- });
126
- };
127
- if (config) {
128
- setupLoom();
66
+ if (config.loomProvider) {
67
+ setupLoom(config.loomProvider, api, editorView);
129
68
  }
130
69
  return {};
131
70
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,84 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ /**
3
+ * @jsxRuntime classic
4
+ * @jsx jsx
5
+ */
6
+ import React, { useCallback } from 'react';
7
+
8
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
9
+ import { jsx } from '@emotion/react';
10
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
11
+ import { executeRecordVideo } from '../commands';
12
+ import { loomPluginKey } from '../pm-plugin';
13
+ import ToolbarButtonComponent from './ToolbarButtonComponent';
14
+ const CustomisableLoomToolbarButton = (editorView, disabled, appearance, api) => /*#__PURE__*/React.forwardRef((props, ref) => {
15
+ var _loomPluginKey$getSta;
16
+ const {
17
+ onClickBeforeInit,
18
+ isDisabled = false,
19
+ href,
20
+ ...restProps
21
+ } = props;
22
+ const isLoomEnabled = (_loomPluginKey$getSta = loomPluginKey.getState(editorView.state)) === null || _loomPluginKey$getSta === void 0 ? void 0 : _loomPluginKey$getSta.isEnabled;
23
+ const handleOnClick = useCallback(e => {
24
+ if (isLoomEnabled) {
25
+ executeRecordVideo(api);
26
+ } else {
27
+ onClickBeforeInit && onClickBeforeInit(e);
28
+ }
29
+ }, [isLoomEnabled, onClickBeforeInit]);
30
+ return jsx(ToolbarButtonComponent, _extends({
31
+ ref: ref,
32
+ hideTooltip: !!(restProps.onMouseEnter || restProps.onMouseLeave)
33
+ // Ignore href if Loom is enabled so that it doesn't interfere with recording
34
+ ,
35
+ href: isLoomEnabled ? undefined : href,
36
+ disabled: disabled || isDisabled,
37
+ api: api,
38
+ appearance: appearance,
39
+ onClick: e => handleOnClick(e)
40
+ }, restProps));
41
+ });
42
+ const LoomToolbarButtonWrapper = ({
43
+ disabled,
44
+ api,
45
+ appearance
46
+ }) => {
47
+ const handleOnClick = useCallback(() => executeRecordVideo(api), [api]);
48
+ const {
49
+ loomState
50
+ } = useSharedPluginState(api, ['loom']);
51
+ if (!loomState) {
52
+ return null;
53
+ }
54
+ return jsx(ToolbarButtonComponent
55
+ // Disable the icon while the SDK isn't initialised
56
+ , {
57
+ disabled: disabled || !(loomState !== null && loomState !== void 0 && loomState.isEnabled),
58
+ api: api,
59
+ appearance: appearance,
60
+ onClick: handleOnClick
61
+ });
62
+ };
63
+ export const loomPrimaryToolbarComponent = (config, api) => ({
64
+ disabled,
65
+ appearance,
66
+ editorView
67
+ }) => {
68
+ if (config.shouldShowToolbarButton === false) {
69
+ return null;
70
+ }
71
+ if (config.renderButton) {
72
+ return config.renderButton(CustomisableLoomToolbarButton(editorView, disabled, appearance, api));
73
+ }
74
+ if (config.shouldShowToolbarButton) {
75
+ return jsx(LoomToolbarButtonWrapper
76
+ // Disable the icon while the SDK isn't initialised
77
+ , {
78
+ disabled: disabled,
79
+ api: api,
80
+ appearance: appearance
81
+ });
82
+ }
83
+ return null;
84
+ };
@@ -2,53 +2,71 @@
2
2
  * @jsxRuntime classic
3
3
  * @jsx jsx
4
4
  */
5
+ import React from 'react';
6
+
5
7
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
6
8
  import { jsx } from '@emotion/react';
7
9
  import { injectIntl } from 'react-intl-next';
8
- import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
9
10
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
10
11
  import { toolbarInsertBlockMessages } from '@atlaskit/editor-common/messages';
11
12
  import { TOOLBAR_BUTTON, ToolbarButton } from '@atlaskit/editor-common/ui-menu';
12
13
  import { LoomIcon } from '@atlaskit/logo';
13
14
  import { fg } from '@atlaskit/platform-feature-flags';
14
- import { recordVideo } from '../commands';
15
15
  // This const is derived from the breakpoint where the toolbar hides its icons. It is used to hide the text in the AI button.
16
16
  // Derived from values from platform/packages/editor/editor-core/src/ui/Appearance/FullPage/MainToolbar.tsx
17
17
  const LOOM_BUTTON_WIDTH_BREAKPOINT = 1076;
18
- const LoomToolbarButton = ({
18
+ const LoomToolbarButtonInternal = /*#__PURE__*/React.forwardRef(({
19
19
  disabled,
20
20
  api,
21
21
  appearance,
22
22
  intl: {
23
23
  formatMessage
24
- }
25
- }) => {
24
+ },
25
+ selected,
26
+ onBlur,
27
+ onFocus,
28
+ onKeyDown,
29
+ onMouseEnter,
30
+ onMouseLeave,
31
+ 'aria-controls': ariaControls,
32
+ 'aria-expanded': ariaExpanded,
33
+ 'aria-haspopup': ariaHasPopup,
34
+ 'data-ds--level': dataDsLevel,
35
+ onClick,
36
+ href,
37
+ target,
38
+ hideTooltip
39
+ }, ref) => {
26
40
  const {
27
- loomState,
28
41
  widthState
29
42
  } = useSharedPluginState(api, ['loom', 'width']);
30
- if (!loomState) {
31
- return null;
32
- }
33
43
  const label = formatMessage(appearance === 'comment' ? toolbarInsertBlockMessages.addLoomVideoComment : toolbarInsertBlockMessages.addLoomVideo);
34
44
  const shouldShowRecordText = fg('platform.editor.plugin.loom.responsive-menu_4at4a') && ((widthState === null || widthState === void 0 ? void 0 : widthState.width) || 0) > LOOM_BUTTON_WIDTH_BREAKPOINT;
35
45
  return jsx(ToolbarButton, {
46
+ hideTooltip: hideTooltip,
47
+ ref: ref,
48
+ href: href,
36
49
  buttonId: TOOLBAR_BUTTON.RECORD_VIDEO,
37
- onClick: () => {
38
- var _api$core, _api$analytics;
39
- return api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(recordVideo({
40
- inputMethod: INPUT_METHOD.TOOLBAR,
41
- editorAnalyticsAPI: api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions
42
- }));
43
- }
44
- // Disable the icon while the SDK isn't initialised
45
- ,
46
- disabled: disabled || !(loomState !== null && loomState !== void 0 && loomState.isEnabled),
50
+ disabled: disabled,
47
51
  title: label,
48
52
  iconBefore: jsx(LoomIcon, {
49
53
  label: label,
50
54
  size: "small"
51
- })
55
+ }),
56
+ selected: selected,
57
+ onBlur: onBlur,
58
+ onFocus: onFocus,
59
+ onKeyDown: onKeyDown,
60
+ onMouseEnter: onMouseEnter,
61
+ onMouseLeave: onMouseLeave,
62
+ "aria-controls": ariaControls,
63
+ "aria-expanded": ariaExpanded,
64
+ "aria-haspopup": ariaHasPopup,
65
+ "data-ds--level": dataDsLevel,
66
+ onClick: onClick,
67
+ target: target
52
68
  }, shouldShowRecordText && formatMessage(toolbarInsertBlockMessages.recordLoomShortTitle));
53
- };
54
- export default injectIntl(LoomToolbarButton);
69
+ });
70
+ export default injectIntl(LoomToolbarButtonInternal, {
71
+ forwardRef: true
72
+ });
@@ -0,0 +1,44 @@
1
+ import React from 'react';
2
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
+ import { toolbarInsertBlockMessages } from '@atlaskit/editor-common/messages';
4
+ import { logException } from '@atlaskit/editor-common/monitoring';
5
+ import { LoomIcon } from '@atlaskit/logo';
6
+ import { recordVideo, recordVideoFailed } from '../commands';
7
+ import { loomPluginKey } from '../pm-plugin';
8
+ export const getQuickInsertItem = editorAnalyticsAPI => ({
9
+ formatMessage
10
+ }) => [{
11
+ id: 'loom',
12
+ title: formatMessage(toolbarInsertBlockMessages.recordVideo),
13
+ description: formatMessage(toolbarInsertBlockMessages.recordVideoDescription),
14
+ keywords: ['loom', 'record', 'video'],
15
+ priority: 800,
16
+ icon: () => /*#__PURE__*/React.createElement(LoomIcon, {
17
+ appearance: "brand"
18
+ }),
19
+ action(insert, editorState) {
20
+ var _recordVideo;
21
+ const tr = insert(undefined);
22
+ const loomState = loomPluginKey.getState(editorState);
23
+ if (!(loomState !== null && loomState !== void 0 && loomState.isEnabled)) {
24
+ var _recordVideoFailed;
25
+ const errorMessage = loomState === null || loomState === void 0 ? void 0 : loomState.error;
26
+ logException(new Error(errorMessage), {
27
+ location: 'editor-plugin-loom/quick-insert-record-video'
28
+ });
29
+ return (_recordVideoFailed = recordVideoFailed({
30
+ inputMethod: INPUT_METHOD.QUICK_INSERT,
31
+ error: errorMessage,
32
+ editorAnalyticsAPI
33
+ })({
34
+ tr
35
+ })) !== null && _recordVideoFailed !== void 0 ? _recordVideoFailed : false;
36
+ }
37
+ return (_recordVideo = recordVideo({
38
+ inputMethod: INPUT_METHOD.QUICK_INSERT,
39
+ editorAnalyticsAPI
40
+ })({
41
+ tr
42
+ })) !== null && _recordVideo !== void 0 ? _recordVideo : false;
43
+ }
44
+ }];
@@ -1,5 +1,9 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
1
3
  import { ACTION, ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
+ import { logException } from '@atlaskit/editor-common/monitoring';
2
5
  import { LoomPluginAction, loomPluginKey } from './pm-plugin';
6
+ import { getQuickInsertItem } from './ui/quickInsert';
3
7
  export var enableLoom = function enableLoom(_ref) {
4
8
  var loomButton = _ref.loomButton;
5
9
  return function (_ref2) {
@@ -110,4 +114,106 @@ export var insertLoom = function insertLoom(editorView, api, video, positionType
110
114
  to = _getPositions.to;
111
115
  return (_api$hyperlink$action = api === null || api === void 0 || (_api$hyperlink = api.hyperlink) === null || _api$hyperlink === void 0 ? void 0 : _api$hyperlink.actions.insertLink(INPUT_METHOD.TYPEAHEAD, from, to, video.sharedUrl, video.title, undefined, undefined, undefined, 'embed' // Convert to embed card instead of inline
112
116
  )(state, dispatch)) !== null && _api$hyperlink$action !== void 0 ? _api$hyperlink$action : false;
113
- };
117
+ };
118
+ export var executeRecordVideo = function executeRecordVideo(api) {
119
+ var _api$core, _api$analytics;
120
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(recordVideo({
121
+ inputMethod: INPUT_METHOD.TOOLBAR,
122
+ editorAnalyticsAPI: api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions
123
+ }));
124
+ };
125
+ export var setupLoom = /*#__PURE__*/function () {
126
+ var _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(loomProvider, api, editorView, isAfterEditorLoaded) {
127
+ var _api$core4;
128
+ var clientResult, _api$core2, _api$analytics2, attachToButton, loomButton, _api$analytics6;
129
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
130
+ while (1) switch (_context.prev = _context.next) {
131
+ case 0:
132
+ _context.next = 2;
133
+ return loomProvider.getClient();
134
+ case 2:
135
+ clientResult = _context.sent;
136
+ if (!(clientResult.status === 'error')) {
137
+ _context.next = 8;
138
+ break;
139
+ }
140
+ api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(disableLoom({
141
+ error: clientResult.message
142
+ }));
143
+ logException(new Error(clientResult.message), {
144
+ location: 'editor-plugin-loom/sdk-initialisation'
145
+ });
146
+ api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 || _api$analytics2.actions.fireAnalyticsEvent({
147
+ action: ACTION.ERRORED,
148
+ actionSubject: ACTION_SUBJECT.LOOM,
149
+ eventType: EVENT_TYPE.OPERATIONAL,
150
+ attributes: {
151
+ error: clientResult.message
152
+ }
153
+ });
154
+ return _context.abrupt("return", {
155
+ error: clientResult.message
156
+ });
157
+ case 8:
158
+ attachToButton = clientResult.client.attachToButton; // Hidden element to work around the SDK API
159
+ loomButton = document.createElement('button');
160
+ attachToButton({
161
+ button: loomButton,
162
+ onInsert: function onInsert(video) {
163
+ var _api$hyperlink2, _api$core3, _api$analytics3;
164
+ if (!editorView) {
165
+ return;
166
+ }
167
+ var state = editorView.state,
168
+ dispatch = editorView.dispatch;
169
+ var pos = state.selection.from;
170
+ api === null || api === void 0 || (_api$hyperlink2 = api.hyperlink) === null || _api$hyperlink2 === void 0 || _api$hyperlink2.actions.insertLink(INPUT_METHOD.TYPEAHEAD, pos,
171
+ // from === to, don't replace text to avoid accidental content loss
172
+ pos, video.sharedUrl, video.title, undefined, undefined, undefined, 'embed' // Convert to embed card instead of inline
173
+ )(state, dispatch);
174
+ api === null || api === void 0 || (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.actions.execute(insertVideo({
175
+ editorAnalyticsAPI: api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions,
176
+ video: video
177
+ }));
178
+ }
179
+ });
180
+ api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 || _api$core4.actions.execute(function (_ref12) {
181
+ var tr = _ref12.tr;
182
+ enableLoom({
183
+ loomButton: loomButton
184
+ })({
185
+ tr: tr
186
+ });
187
+ if (isAfterEditorLoaded) {
188
+ var _api$quickInsert, _api$analytics4, _api$analytics5;
189
+ api === null || api === void 0 || (_api$quickInsert = api.quickInsert) === null || _api$quickInsert === void 0 || _api$quickInsert.commands.addQuickInsertItem(getQuickInsertItem(api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions))({
190
+ tr: tr
191
+ });
192
+ api === null || api === void 0 || (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 || _api$analytics5.actions.attachAnalyticsEvent({
193
+ action: ACTION.INITIALISED,
194
+ actionSubject: ACTION_SUBJECT.LOOM,
195
+ eventType: EVENT_TYPE.OPERATIONAL
196
+ })(tr);
197
+ }
198
+ return tr;
199
+ });
200
+ if (!isAfterEditorLoaded) {
201
+ // We're not combining the analytics steps into the enable / disable commands because the collab-edit plugin
202
+ // filters out any transactions with steps (even analytics) when it's initialising
203
+ api === null || api === void 0 || (_api$analytics6 = api.analytics) === null || _api$analytics6 === void 0 || _api$analytics6.actions.fireAnalyticsEvent({
204
+ action: ACTION.INITIALISED,
205
+ actionSubject: ACTION_SUBJECT.LOOM,
206
+ eventType: EVENT_TYPE.OPERATIONAL
207
+ });
208
+ }
209
+ return _context.abrupt("return", {});
210
+ case 14:
211
+ case "end":
212
+ return _context.stop();
213
+ }
214
+ }, _callee);
215
+ }));
216
+ return function setupLoom(_x, _x2, _x3, _x4) {
217
+ return _ref11.apply(this, arguments);
218
+ };
219
+ }();