@atlaskit/editor-plugin-breakout 2.6.0 → 2.6.1

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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # @atlaskit/editor-plugin-breakout
2
2
 
3
+ ## 2.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#166490](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/166490)
8
+ [`9f140155c14be`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/9f140155c14be) -
9
+ [ux] Shows tooltip on the resize handle when it is hovered.
10
+ - Updated dependencies
11
+
3
12
  ## 2.6.0
4
13
 
5
14
  ### Minor Changes
@@ -209,8 +209,10 @@ var breakoutPlugin = exports.breakoutPlugin = function breakoutPlugin(_ref4) {
209
209
  if ((0, _experiments.editorExperiment)('platform_editor_breakout_resizing', true)) {
210
210
  return [{
211
211
  name: 'breakout-resizing',
212
- plugin: function plugin() {
213
- return (0, _resizingPlugin.createResizingPlugin)(api, options);
212
+ plugin: function plugin(_ref5) {
213
+ var getIntl = _ref5.getIntl,
214
+ nodeViewPortalProviderAPI = _ref5.nodeViewPortalProviderAPI;
215
+ return (0, _resizingPlugin.createResizingPlugin)(api, getIntl, nodeViewPortalProviderAPI, options);
214
216
  }
215
217
  }];
216
218
  }
@@ -241,11 +243,11 @@ var breakoutPlugin = exports.breakoutPlugin = function breakoutPlugin(_ref4) {
241
243
  }
242
244
  return pluginState;
243
245
  },
244
- contentComponent: function contentComponent(_ref5) {
245
- var editorView = _ref5.editorView,
246
- popupsMountPoint = _ref5.popupsMountPoint,
247
- popupsBoundariesElement = _ref5.popupsBoundariesElement,
248
- popupsScrollableElement = _ref5.popupsScrollableElement;
246
+ contentComponent: function contentComponent(_ref6) {
247
+ var editorView = _ref6.editorView,
248
+ popupsMountPoint = _ref6.popupsMountPoint,
249
+ popupsBoundariesElement = _ref6.popupsBoundariesElement,
250
+ popupsScrollableElement = _ref6.popupsScrollableElement;
249
251
  // This is a bit crappy, but should be resolved once we move to a static schema.
250
252
  if (options && !options.allowBreakoutButton) {
251
253
  return null;
@@ -1,20 +1,71 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
- exports.createPragmaticResizer = void 0;
8
+ exports.resizeHandleMessage = exports.createPragmaticResizer = void 0;
8
9
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
+ var _react = _interopRequireWildcard(require("react"));
9
12
  var _bindEventListener = require("bind-event-listener");
13
+ var _v = _interopRequireDefault(require("uuid/v4"));
14
+ var _messages = require("@atlaskit/editor-common/messages");
15
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
10
16
  var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
11
17
  var _disableNativeDragPreview = require("@atlaskit/pragmatic-drag-and-drop/element/disable-native-drag-preview");
12
18
  var _preventUnhandled = require("@atlaskit/pragmatic-drag-and-drop/prevent-unhandled");
13
- var createPragmaticResizer = exports.createPragmaticResizer = function createPragmaticResizer(_ref) {
14
- var target = _ref.target,
15
- _onDragStart = _ref.onDragStart,
16
- onDrag = _ref.onDrag,
17
- _onDrop = _ref.onDrop;
19
+ var _tooltip = _interopRequireDefault(require("@atlaskit/tooltip"));
20
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
21
+ var getNodeName = function getNodeName(nodeName) {
22
+ if (nodeName === 'layoutSection') {
23
+ return 'layout';
24
+ } else if (nodeName === 'codeBlock' || nodeName === 'expand') {
25
+ return nodeName;
26
+ } else {
27
+ return 'node';
28
+ }
29
+ };
30
+ var resizeHandleMessage = exports.resizeHandleMessage = {
31
+ expand: _messages.breakoutMessages.resizeExpand,
32
+ codeBlock: _messages.breakoutMessages.resizeCodeBlock,
33
+ layout: _messages.breakoutMessages.resizeLayout,
34
+ node: _messages.breakoutMessages.resizeElement
35
+ };
36
+ var RailWithTooltip = function RailWithTooltip(_ref) {
37
+ var rail = _ref.rail,
38
+ target = _ref.target,
39
+ intl = _ref.intl;
40
+ var _useState = (0, _react.useState)('node'),
41
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
42
+ nodeName = _useState2[0],
43
+ setNodeName = _useState2[1];
44
+ (0, _react.useLayoutEffect)(function () {
45
+ var node = target.querySelector('[data-prosemirror-node-name]');
46
+ var name = getNodeName(node === null || node === void 0 ? void 0 : node.dataset.prosemirrorNodeName);
47
+ setNodeName(name);
48
+ }, [target]);
49
+ return /*#__PURE__*/_react.default.createElement(_tooltip.default, {
50
+ content: intl.formatMessage(resizeHandleMessage[nodeName]),
51
+ position: "mouse"
52
+ }, /*#__PURE__*/_react.default.createElement("div", {
53
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
54
+ className: "pm-breakout-resize-handle-rail-inside-tooltip",
55
+ ref: function ref(el) {
56
+ if (el && rail.parentNode !== el) {
57
+ el.appendChild(rail);
58
+ }
59
+ }
60
+ }));
61
+ };
62
+ var createPragmaticResizer = exports.createPragmaticResizer = function createPragmaticResizer(_ref2) {
63
+ var target = _ref2.target,
64
+ _onDragStart = _ref2.onDragStart,
65
+ onDrag = _ref2.onDrag,
66
+ _onDrop = _ref2.onDrop,
67
+ intl = _ref2.intl,
68
+ nodeViewPortalProviderAPI = _ref2.nodeViewPortalProviderAPI;
18
69
  var state = 'default';
19
70
  var createHandle = function createHandle(side) {
20
71
  var handle = document.createElement('div');
@@ -34,21 +85,45 @@ var createPragmaticResizer = exports.createPragmaticResizer = function createPra
34
85
  var thumb = document.createElement('div');
35
86
  thumb.classList.add('pm-breakout-resize-handle-thumb');
36
87
  rail.appendChild(thumb);
37
- handle.appendChild(rail);
38
- handle.appendChild(handleHitBox);
39
- return {
40
- handle: handle,
41
- rail: rail,
42
- handleHitBox: handleHitBox
43
- };
88
+ if ((0, _platformFeatureFlags.fg)('platform_editor_breakout_resizing_hello_release')) {
89
+ var tooltipContainer = document.createElement('div');
90
+ tooltipContainer.classList.add('pm-breakout-resize-handle-rail-wrapper');
91
+ handle.appendChild(tooltipContainer);
92
+ handle.appendChild(handleHitBox);
93
+ var key = (0, _v.default)();
94
+ nodeViewPortalProviderAPI.render(function () {
95
+ return /*#__PURE__*/_react.default.createElement(RailWithTooltip, {
96
+ rail: rail,
97
+ target: target,
98
+ intl: intl
99
+ });
100
+ }, tooltipContainer, key);
101
+ return {
102
+ handle: handle,
103
+ rail: rail,
104
+ handleHitBox: handleHitBox,
105
+ destroyTooltip: function destroyTooltip() {
106
+ return nodeViewPortalProviderAPI.remove(key);
107
+ }
108
+ };
109
+ } else {
110
+ handle.appendChild(rail);
111
+ handle.appendChild(handleHitBox);
112
+ return {
113
+ handle: handle,
114
+ rail: rail,
115
+ handleHitBox: handleHitBox,
116
+ destroyTooltip: function destroyTooltip() {}
117
+ };
118
+ }
44
119
  };
45
120
  var rightHandle = createHandle('right');
46
121
  var leftHandle = createHandle('left');
47
122
  var registerHandle = function registerHandle(handleElement, handleSide) {
48
123
  return (0, _adapter.draggable)({
49
124
  element: handleElement,
50
- onGenerateDragPreview: function onGenerateDragPreview(_ref2) {
51
- var nativeSetDragImage = _ref2.nativeSetDragImage;
125
+ onGenerateDragPreview: function onGenerateDragPreview(_ref3) {
126
+ var nativeSetDragImage = _ref3.nativeSetDragImage;
52
127
  (0, _disableNativeDragPreview.disableNativeDragPreview)({
53
128
  nativeSetDragImage: nativeSetDragImage
54
129
  });
@@ -92,7 +167,7 @@ var createPragmaticResizer = exports.createPragmaticResizer = function createPra
92
167
  })];
93
168
  };
94
169
  var unbindFns = [].concat((0, _toConsumableArray2.default)(registerEvents(target)), (0, _toConsumableArray2.default)(registerEvents(rightHandle.handleHitBox)), (0, _toConsumableArray2.default)(registerEvents(leftHandle.handleHitBox)), (0, _toConsumableArray2.default)(registerEvents(rightHandle.rail)), (0, _toConsumableArray2.default)(registerEvents(leftHandle.rail)));
95
- var destroyFns = [registerHandle(rightHandle.handle, 'right'), registerHandle(leftHandle.handle, 'left')];
170
+ var destroyFns = [registerHandle(rightHandle.handle, 'right'), registerHandle(leftHandle.handle, 'left')].concat((0, _toConsumableArray2.default)((0, _platformFeatureFlags.fg)('platform_editor_breakout_resizing_hello_release') ? [rightHandle.destroyTooltip, leftHandle.destroyTooltip] : []));
96
171
  return {
97
172
  rightHandle: rightHandle.handle,
98
173
  leftHandle: leftHandle.handle,
@@ -19,12 +19,14 @@ var ResizingMarkView = exports.ResizingMarkView = /*#__PURE__*/function () {
19
19
  * Wrap node view in a resizing mark view
20
20
  * @param {Mark} mark - The breakout mark to resize
21
21
  * @param {EditorView} view - The editor view
22
- * @param {ExtractInjectionAPI<BreakoutPlugin> | undefined} api - the pluginInjectionAPI
22
+ * @param {ExtractInjectionAPI<BreakoutPlugin> | undefined} api - The pluginInjectionAPI
23
+ * @param {Function} getIntl - () => IntlShape
24
+ * @param {PortalProviderAPI} - The nodeViewPortalProviderAPI
23
25
  * @example
24
26
  * ```ts
25
27
  * ```
26
28
  */
27
- function ResizingMarkView(mark, view, api) {
29
+ function ResizingMarkView(mark, view, api, getIntl, nodeViewPortalProviderAPI) {
28
30
  (0, _classCallCheck2.default)(this, ResizingMarkView);
29
31
  var dom = document.createElement('div');
30
32
  var contentDOM = document.createElement('div');
@@ -60,9 +62,14 @@ var ResizingMarkView = exports.ResizingMarkView = /*#__PURE__*/function () {
60
62
  mark: mark,
61
63
  api: api
62
64
  });
63
- var _createPragmaticResiz = (0, _pragmaticResizer.createPragmaticResizer)(_objectSpread({
65
+ this.intl = getIntl();
66
+ this.nodeViewPortalProviderAPI = nodeViewPortalProviderAPI;
67
+ var _createPragmaticResiz = (0, _pragmaticResizer.createPragmaticResizer)(_objectSpread(_objectSpread({
64
68
  target: contentDOM
65
- }, callbacks)),
69
+ }, callbacks), {}, {
70
+ intl: this.intl,
71
+ nodeViewPortalProviderAPI: this.nodeViewPortalProviderAPI
72
+ })),
66
73
  leftHandle = _createPragmaticResiz.leftHandle,
67
74
  rightHandle = _createPragmaticResiz.rightHandle,
68
75
  destroy = _createPragmaticResiz.destroy;
@@ -49,13 +49,13 @@ var addBreakoutToResizableNode = function addBreakoutToResizableNode(_ref) {
49
49
  };
50
50
  };
51
51
  var resizingPluginKey = exports.resizingPluginKey = new _state.PluginKey('breakout-resizing');
52
- var createResizingPlugin = exports.createResizingPlugin = function createResizingPlugin(api, options) {
52
+ var createResizingPlugin = exports.createResizingPlugin = function createResizingPlugin(api, getIntl, nodeViewPortalProviderAPI, options) {
53
53
  return new _safePlugin.SafePlugin({
54
54
  key: resizingPluginKey,
55
55
  props: {
56
56
  markViews: {
57
57
  breakout: function breakout(mark, view) {
58
- return new _resizingMarkView.ResizingMarkView(mark, view, api);
58
+ return new _resizingMarkView.ResizingMarkView(mark, view, api, getIntl, nodeViewPortalProviderAPI);
59
59
  }
60
60
  },
61
61
  handleKeyDown: _handleKeyDown.handleKeyDown
@@ -195,7 +195,10 @@ export const breakoutPlugin = ({
195
195
  if (editorExperiment('platform_editor_breakout_resizing', true)) {
196
196
  return [{
197
197
  name: 'breakout-resizing',
198
- plugin: () => createResizingPlugin(api, options)
198
+ plugin: ({
199
+ getIntl,
200
+ nodeViewPortalProviderAPI
201
+ }) => createResizingPlugin(api, getIntl, nodeViewPortalProviderAPI, options)
199
202
  }];
200
203
  }
201
204
  return [{
@@ -1,12 +1,58 @@
1
+ import React, { useLayoutEffect, useState } from 'react';
1
2
  import { bind } from 'bind-event-listener';
3
+ import uuid from 'uuid/v4';
4
+ import { breakoutMessages as messages } from '@atlaskit/editor-common/messages';
5
+ import { fg } from '@atlaskit/platform-feature-flags';
2
6
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
3
7
  import { disableNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/element/disable-native-drag-preview';
4
8
  import { preventUnhandled } from '@atlaskit/pragmatic-drag-and-drop/prevent-unhandled';
9
+ import Tooltip from '@atlaskit/tooltip';
10
+ const getNodeName = nodeName => {
11
+ if (nodeName === 'layoutSection') {
12
+ return 'layout';
13
+ } else if (nodeName === 'codeBlock' || nodeName === 'expand') {
14
+ return nodeName;
15
+ } else {
16
+ return 'node';
17
+ }
18
+ };
19
+ export const resizeHandleMessage = {
20
+ expand: messages.resizeExpand,
21
+ codeBlock: messages.resizeCodeBlock,
22
+ layout: messages.resizeLayout,
23
+ node: messages.resizeElement
24
+ };
25
+ const RailWithTooltip = ({
26
+ rail,
27
+ target,
28
+ intl
29
+ }) => {
30
+ const [nodeName, setNodeName] = useState('node');
31
+ useLayoutEffect(() => {
32
+ const node = target.querySelector('[data-prosemirror-node-name]');
33
+ const name = getNodeName(node === null || node === void 0 ? void 0 : node.dataset.prosemirrorNodeName);
34
+ setNodeName(name);
35
+ }, [target]);
36
+ return /*#__PURE__*/React.createElement(Tooltip, {
37
+ content: intl.formatMessage(resizeHandleMessage[nodeName]),
38
+ position: "mouse"
39
+ }, /*#__PURE__*/React.createElement("div", {
40
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
41
+ className: "pm-breakout-resize-handle-rail-inside-tooltip",
42
+ ref: el => {
43
+ if (el && rail.parentNode !== el) {
44
+ el.appendChild(rail);
45
+ }
46
+ }
47
+ }));
48
+ };
5
49
  export const createPragmaticResizer = ({
6
50
  target,
7
51
  onDragStart,
8
52
  onDrag,
9
- onDrop
53
+ onDrop,
54
+ intl,
55
+ nodeViewPortalProviderAPI
10
56
  }) => {
11
57
  let state = 'default';
12
58
  const createHandle = side => {
@@ -27,13 +73,33 @@ export const createPragmaticResizer = ({
27
73
  const thumb = document.createElement('div');
28
74
  thumb.classList.add('pm-breakout-resize-handle-thumb');
29
75
  rail.appendChild(thumb);
30
- handle.appendChild(rail);
31
- handle.appendChild(handleHitBox);
32
- return {
33
- handle,
34
- rail,
35
- handleHitBox
36
- };
76
+ if (fg('platform_editor_breakout_resizing_hello_release')) {
77
+ const tooltipContainer = document.createElement('div');
78
+ tooltipContainer.classList.add('pm-breakout-resize-handle-rail-wrapper');
79
+ handle.appendChild(tooltipContainer);
80
+ handle.appendChild(handleHitBox);
81
+ const key = uuid();
82
+ nodeViewPortalProviderAPI.render(() => /*#__PURE__*/React.createElement(RailWithTooltip, {
83
+ rail: rail,
84
+ target: target,
85
+ intl: intl
86
+ }), tooltipContainer, key);
87
+ return {
88
+ handle,
89
+ rail,
90
+ handleHitBox,
91
+ destroyTooltip: () => nodeViewPortalProviderAPI.remove(key)
92
+ };
93
+ } else {
94
+ handle.appendChild(rail);
95
+ handle.appendChild(handleHitBox);
96
+ return {
97
+ handle,
98
+ rail,
99
+ handleHitBox,
100
+ destroyTooltip: () => {}
101
+ };
102
+ }
37
103
  };
38
104
  const rightHandle = createHandle('right');
39
105
  const leftHandle = createHandle('left');
@@ -84,7 +150,7 @@ export const createPragmaticResizer = ({
84
150
  })];
85
151
  };
86
152
  const unbindFns = [...registerEvents(target), ...registerEvents(rightHandle.handleHitBox), ...registerEvents(leftHandle.handleHitBox), ...registerEvents(rightHandle.rail), ...registerEvents(leftHandle.rail)];
87
- const destroyFns = [registerHandle(rightHandle.handle, 'right'), registerHandle(leftHandle.handle, 'left')];
153
+ const destroyFns = [registerHandle(rightHandle.handle, 'right'), registerHandle(leftHandle.handle, 'left'), ...(fg('platform_editor_breakout_resizing_hello_release') ? [rightHandle.destroyTooltip, leftHandle.destroyTooltip] : [])];
88
154
  return {
89
155
  rightHandle: rightHandle.handle,
90
156
  leftHandle: leftHandle.handle,
@@ -7,12 +7,14 @@ export class ResizingMarkView {
7
7
  * Wrap node view in a resizing mark view
8
8
  * @param {Mark} mark - The breakout mark to resize
9
9
  * @param {EditorView} view - The editor view
10
- * @param {ExtractInjectionAPI<BreakoutPlugin> | undefined} api - the pluginInjectionAPI
10
+ * @param {ExtractInjectionAPI<BreakoutPlugin> | undefined} api - The pluginInjectionAPI
11
+ * @param {Function} getIntl - () => IntlShape
12
+ * @param {PortalProviderAPI} - The nodeViewPortalProviderAPI
11
13
  * @example
12
14
  * ```ts
13
15
  * ```
14
16
  */
15
- constructor(mark, view, api) {
17
+ constructor(mark, view, api, getIntl, nodeViewPortalProviderAPI) {
16
18
  const dom = document.createElement('div');
17
19
  const contentDOM = document.createElement('div');
18
20
  contentDOM.className = BreakoutCssClassName.BREAKOUT_MARK_DOM;
@@ -47,13 +49,17 @@ export class ResizingMarkView {
47
49
  mark,
48
50
  api
49
51
  });
52
+ this.intl = getIntl();
53
+ this.nodeViewPortalProviderAPI = nodeViewPortalProviderAPI;
50
54
  const {
51
55
  leftHandle,
52
56
  rightHandle,
53
57
  destroy
54
58
  } = createPragmaticResizer({
55
59
  target: contentDOM,
56
- ...callbacks
60
+ ...callbacks,
61
+ intl: this.intl,
62
+ nodeViewPortalProviderAPI: this.nodeViewPortalProviderAPI
57
63
  });
58
64
  dom.prepend(leftHandle);
59
65
  dom.appendChild(rightHandle);
@@ -44,13 +44,13 @@ const addBreakoutToResizableNode = ({
44
44
  };
45
45
  };
46
46
  export const resizingPluginKey = new PluginKey('breakout-resizing');
47
- export const createResizingPlugin = (api, options) => {
47
+ export const createResizingPlugin = (api, getIntl, nodeViewPortalProviderAPI, options) => {
48
48
  return new SafePlugin({
49
49
  key: resizingPluginKey,
50
50
  props: {
51
51
  markViews: {
52
52
  breakout: (mark, view) => {
53
- return new ResizingMarkView(mark, view, api);
53
+ return new ResizingMarkView(mark, view, api, getIntl, nodeViewPortalProviderAPI);
54
54
  }
55
55
  },
56
56
  handleKeyDown
@@ -200,8 +200,10 @@ export var breakoutPlugin = function breakoutPlugin(_ref4) {
200
200
  if (editorExperiment('platform_editor_breakout_resizing', true)) {
201
201
  return [{
202
202
  name: 'breakout-resizing',
203
- plugin: function plugin() {
204
- return createResizingPlugin(api, options);
203
+ plugin: function plugin(_ref5) {
204
+ var getIntl = _ref5.getIntl,
205
+ nodeViewPortalProviderAPI = _ref5.nodeViewPortalProviderAPI;
206
+ return createResizingPlugin(api, getIntl, nodeViewPortalProviderAPI, options);
205
207
  }
206
208
  }];
207
209
  }
@@ -232,11 +234,11 @@ export var breakoutPlugin = function breakoutPlugin(_ref4) {
232
234
  }
233
235
  return pluginState;
234
236
  },
235
- contentComponent: function contentComponent(_ref5) {
236
- var editorView = _ref5.editorView,
237
- popupsMountPoint = _ref5.popupsMountPoint,
238
- popupsBoundariesElement = _ref5.popupsBoundariesElement,
239
- popupsScrollableElement = _ref5.popupsScrollableElement;
237
+ contentComponent: function contentComponent(_ref6) {
238
+ var editorView = _ref6.editorView,
239
+ popupsMountPoint = _ref6.popupsMountPoint,
240
+ popupsBoundariesElement = _ref6.popupsBoundariesElement,
241
+ popupsScrollableElement = _ref6.popupsScrollableElement;
240
242
  // This is a bit crappy, but should be resolved once we move to a static schema.
241
243
  if (options && !options.allowBreakoutButton) {
242
244
  return null;
@@ -1,13 +1,62 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ import React, { useLayoutEffect, useState } from 'react';
2
4
  import { bind } from 'bind-event-listener';
5
+ import uuid from 'uuid/v4';
6
+ import { breakoutMessages as messages } from '@atlaskit/editor-common/messages';
7
+ import { fg } from '@atlaskit/platform-feature-flags';
3
8
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
4
9
  import { disableNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/element/disable-native-drag-preview';
5
10
  import { preventUnhandled } from '@atlaskit/pragmatic-drag-and-drop/prevent-unhandled';
6
- export var createPragmaticResizer = function createPragmaticResizer(_ref) {
7
- var target = _ref.target,
8
- _onDragStart = _ref.onDragStart,
9
- onDrag = _ref.onDrag,
10
- _onDrop = _ref.onDrop;
11
+ import Tooltip from '@atlaskit/tooltip';
12
+ var getNodeName = function getNodeName(nodeName) {
13
+ if (nodeName === 'layoutSection') {
14
+ return 'layout';
15
+ } else if (nodeName === 'codeBlock' || nodeName === 'expand') {
16
+ return nodeName;
17
+ } else {
18
+ return 'node';
19
+ }
20
+ };
21
+ export var resizeHandleMessage = {
22
+ expand: messages.resizeExpand,
23
+ codeBlock: messages.resizeCodeBlock,
24
+ layout: messages.resizeLayout,
25
+ node: messages.resizeElement
26
+ };
27
+ var RailWithTooltip = function RailWithTooltip(_ref) {
28
+ var rail = _ref.rail,
29
+ target = _ref.target,
30
+ intl = _ref.intl;
31
+ var _useState = useState('node'),
32
+ _useState2 = _slicedToArray(_useState, 2),
33
+ nodeName = _useState2[0],
34
+ setNodeName = _useState2[1];
35
+ useLayoutEffect(function () {
36
+ var node = target.querySelector('[data-prosemirror-node-name]');
37
+ var name = getNodeName(node === null || node === void 0 ? void 0 : node.dataset.prosemirrorNodeName);
38
+ setNodeName(name);
39
+ }, [target]);
40
+ return /*#__PURE__*/React.createElement(Tooltip, {
41
+ content: intl.formatMessage(resizeHandleMessage[nodeName]),
42
+ position: "mouse"
43
+ }, /*#__PURE__*/React.createElement("div", {
44
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
45
+ className: "pm-breakout-resize-handle-rail-inside-tooltip",
46
+ ref: function ref(el) {
47
+ if (el && rail.parentNode !== el) {
48
+ el.appendChild(rail);
49
+ }
50
+ }
51
+ }));
52
+ };
53
+ export var createPragmaticResizer = function createPragmaticResizer(_ref2) {
54
+ var target = _ref2.target,
55
+ _onDragStart = _ref2.onDragStart,
56
+ onDrag = _ref2.onDrag,
57
+ _onDrop = _ref2.onDrop,
58
+ intl = _ref2.intl,
59
+ nodeViewPortalProviderAPI = _ref2.nodeViewPortalProviderAPI;
11
60
  var state = 'default';
12
61
  var createHandle = function createHandle(side) {
13
62
  var handle = document.createElement('div');
@@ -27,21 +76,45 @@ export var createPragmaticResizer = function createPragmaticResizer(_ref) {
27
76
  var thumb = document.createElement('div');
28
77
  thumb.classList.add('pm-breakout-resize-handle-thumb');
29
78
  rail.appendChild(thumb);
30
- handle.appendChild(rail);
31
- handle.appendChild(handleHitBox);
32
- return {
33
- handle: handle,
34
- rail: rail,
35
- handleHitBox: handleHitBox
36
- };
79
+ if (fg('platform_editor_breakout_resizing_hello_release')) {
80
+ var tooltipContainer = document.createElement('div');
81
+ tooltipContainer.classList.add('pm-breakout-resize-handle-rail-wrapper');
82
+ handle.appendChild(tooltipContainer);
83
+ handle.appendChild(handleHitBox);
84
+ var key = uuid();
85
+ nodeViewPortalProviderAPI.render(function () {
86
+ return /*#__PURE__*/React.createElement(RailWithTooltip, {
87
+ rail: rail,
88
+ target: target,
89
+ intl: intl
90
+ });
91
+ }, tooltipContainer, key);
92
+ return {
93
+ handle: handle,
94
+ rail: rail,
95
+ handleHitBox: handleHitBox,
96
+ destroyTooltip: function destroyTooltip() {
97
+ return nodeViewPortalProviderAPI.remove(key);
98
+ }
99
+ };
100
+ } else {
101
+ handle.appendChild(rail);
102
+ handle.appendChild(handleHitBox);
103
+ return {
104
+ handle: handle,
105
+ rail: rail,
106
+ handleHitBox: handleHitBox,
107
+ destroyTooltip: function destroyTooltip() {}
108
+ };
109
+ }
37
110
  };
38
111
  var rightHandle = createHandle('right');
39
112
  var leftHandle = createHandle('left');
40
113
  var registerHandle = function registerHandle(handleElement, handleSide) {
41
114
  return draggable({
42
115
  element: handleElement,
43
- onGenerateDragPreview: function onGenerateDragPreview(_ref2) {
44
- var nativeSetDragImage = _ref2.nativeSetDragImage;
116
+ onGenerateDragPreview: function onGenerateDragPreview(_ref3) {
117
+ var nativeSetDragImage = _ref3.nativeSetDragImage;
45
118
  disableNativeDragPreview({
46
119
  nativeSetDragImage: nativeSetDragImage
47
120
  });
@@ -85,7 +158,7 @@ export var createPragmaticResizer = function createPragmaticResizer(_ref) {
85
158
  })];
86
159
  };
87
160
  var unbindFns = [].concat(_toConsumableArray(registerEvents(target)), _toConsumableArray(registerEvents(rightHandle.handleHitBox)), _toConsumableArray(registerEvents(leftHandle.handleHitBox)), _toConsumableArray(registerEvents(rightHandle.rail)), _toConsumableArray(registerEvents(leftHandle.rail)));
88
- var destroyFns = [registerHandle(rightHandle.handle, 'right'), registerHandle(leftHandle.handle, 'left')];
161
+ var destroyFns = [registerHandle(rightHandle.handle, 'right'), registerHandle(leftHandle.handle, 'left')].concat(_toConsumableArray(fg('platform_editor_breakout_resizing_hello_release') ? [rightHandle.destroyTooltip, leftHandle.destroyTooltip] : []));
89
162
  return {
90
163
  rightHandle: rightHandle.handle,
91
164
  leftHandle: leftHandle.handle,
@@ -12,12 +12,14 @@ export var ResizingMarkView = /*#__PURE__*/function () {
12
12
  * Wrap node view in a resizing mark view
13
13
  * @param {Mark} mark - The breakout mark to resize
14
14
  * @param {EditorView} view - The editor view
15
- * @param {ExtractInjectionAPI<BreakoutPlugin> | undefined} api - the pluginInjectionAPI
15
+ * @param {ExtractInjectionAPI<BreakoutPlugin> | undefined} api - The pluginInjectionAPI
16
+ * @param {Function} getIntl - () => IntlShape
17
+ * @param {PortalProviderAPI} - The nodeViewPortalProviderAPI
16
18
  * @example
17
19
  * ```ts
18
20
  * ```
19
21
  */
20
- function ResizingMarkView(mark, view, api) {
22
+ function ResizingMarkView(mark, view, api, getIntl, nodeViewPortalProviderAPI) {
21
23
  _classCallCheck(this, ResizingMarkView);
22
24
  var dom = document.createElement('div');
23
25
  var contentDOM = document.createElement('div');
@@ -53,9 +55,14 @@ export var ResizingMarkView = /*#__PURE__*/function () {
53
55
  mark: mark,
54
56
  api: api
55
57
  });
56
- var _createPragmaticResiz = createPragmaticResizer(_objectSpread({
58
+ this.intl = getIntl();
59
+ this.nodeViewPortalProviderAPI = nodeViewPortalProviderAPI;
60
+ var _createPragmaticResiz = createPragmaticResizer(_objectSpread(_objectSpread({
57
61
  target: contentDOM
58
- }, callbacks)),
62
+ }, callbacks), {}, {
63
+ intl: this.intl,
64
+ nodeViewPortalProviderAPI: this.nodeViewPortalProviderAPI
65
+ })),
59
66
  leftHandle = _createPragmaticResiz.leftHandle,
60
67
  rightHandle = _createPragmaticResiz.rightHandle,
61
68
  destroy = _createPragmaticResiz.destroy;
@@ -43,13 +43,13 @@ var addBreakoutToResizableNode = function addBreakoutToResizableNode(_ref) {
43
43
  };
44
44
  };
45
45
  export var resizingPluginKey = new PluginKey('breakout-resizing');
46
- export var createResizingPlugin = function createResizingPlugin(api, options) {
46
+ export var createResizingPlugin = function createResizingPlugin(api, getIntl, nodeViewPortalProviderAPI, options) {
47
47
  return new SafePlugin({
48
48
  key: resizingPluginKey,
49
49
  props: {
50
50
  markViews: {
51
51
  breakout: function breakout(mark, view) {
52
- return new ResizingMarkView(mark, view, api);
52
+ return new ResizingMarkView(mark, view, api, getIntl, nodeViewPortalProviderAPI);
53
53
  }
54
54
  },
55
55
  handleKeyDown: handleKeyDown
@@ -1,9 +1,14 @@
1
+ import type { IntlShape, MessageDescriptor } from 'react-intl-next';
2
+ import { type PortalProviderAPI } from '@atlaskit/editor-common/portal';
1
3
  import type { BaseEventPayload, ElementDragType } from '@atlaskit/pragmatic-drag-and-drop/types';
2
- export declare const createPragmaticResizer: ({ target, onDragStart, onDrag, onDrop, }: {
4
+ export declare const resizeHandleMessage: Record<string, MessageDescriptor>;
5
+ export declare const createPragmaticResizer: ({ target, onDragStart, onDrag, onDrop, intl, nodeViewPortalProviderAPI, }: {
3
6
  target: HTMLElement;
4
7
  onDragStart: (args: BaseEventPayload<ElementDragType>) => void;
5
8
  onDrag: (args: BaseEventPayload<ElementDragType>) => void;
6
9
  onDrop: (args: BaseEventPayload<ElementDragType>) => void;
10
+ intl: IntlShape;
11
+ nodeViewPortalProviderAPI: PortalProviderAPI;
7
12
  }) => {
8
13
  rightHandle: HTMLDivElement;
9
14
  leftHandle: HTMLDivElement;
@@ -1,3 +1,5 @@
1
+ import type { IntlShape } from 'react-intl-next';
2
+ import { type PortalProviderAPI } from '@atlaskit/editor-common/portal';
1
3
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
4
  import type { Mark } from '@atlaskit/editor-prosemirror/model';
3
5
  import type { EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
@@ -9,16 +11,20 @@ export declare class ResizingMarkView implements NodeView {
9
11
  view: EditorView;
10
12
  mark: Mark;
11
13
  destroyFn: () => void;
14
+ intl: IntlShape;
15
+ nodeViewPortalProviderAPI: PortalProviderAPI;
12
16
  /**
13
17
  * Wrap node view in a resizing mark view
14
18
  * @param {Mark} mark - The breakout mark to resize
15
19
  * @param {EditorView} view - The editor view
16
- * @param {ExtractInjectionAPI<BreakoutPlugin> | undefined} api - the pluginInjectionAPI
20
+ * @param {ExtractInjectionAPI<BreakoutPlugin> | undefined} api - The pluginInjectionAPI
21
+ * @param {Function} getIntl - () => IntlShape
22
+ * @param {PortalProviderAPI} - The nodeViewPortalProviderAPI
17
23
  * @example
18
24
  * ```ts
19
25
  * ```
20
26
  */
21
- constructor(mark: Mark, view: EditorView, api: ExtractInjectionAPI<BreakoutPlugin> | undefined);
27
+ constructor(mark: Mark, view: EditorView, api: ExtractInjectionAPI<BreakoutPlugin> | undefined, getIntl: () => IntlShape, nodeViewPortalProviderAPI: PortalProviderAPI);
22
28
  ignoreMutation(): boolean;
23
29
  destroy(): void;
24
30
  }
@@ -1,7 +1,9 @@
1
+ import type { IntlShape } from 'react-intl-next';
2
+ import { type PortalProviderAPI } from '@atlaskit/editor-common/portal';
1
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
4
  import { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
5
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
6
  import { BreakoutPlugin } from '../breakoutPluginType';
5
7
  import type { BreakoutPluginOptions } from '../breakoutPluginType';
6
8
  export declare const resizingPluginKey: PluginKey<any>;
7
- export declare const createResizingPlugin: (api: ExtractInjectionAPI<BreakoutPlugin> | undefined, options?: BreakoutPluginOptions) => SafePlugin<any>;
9
+ export declare const createResizingPlugin: (api: ExtractInjectionAPI<BreakoutPlugin> | undefined, getIntl: () => IntlShape, nodeViewPortalProviderAPI: PortalProviderAPI, options?: BreakoutPluginOptions) => SafePlugin<any>;
@@ -1,9 +1,14 @@
1
+ import type { IntlShape, MessageDescriptor } from 'react-intl-next';
2
+ import { type PortalProviderAPI } from '@atlaskit/editor-common/portal';
1
3
  import type { BaseEventPayload, ElementDragType } from '@atlaskit/pragmatic-drag-and-drop/types';
2
- export declare const createPragmaticResizer: ({ target, onDragStart, onDrag, onDrop, }: {
4
+ export declare const resizeHandleMessage: Record<string, MessageDescriptor>;
5
+ export declare const createPragmaticResizer: ({ target, onDragStart, onDrag, onDrop, intl, nodeViewPortalProviderAPI, }: {
3
6
  target: HTMLElement;
4
7
  onDragStart: (args: BaseEventPayload<ElementDragType>) => void;
5
8
  onDrag: (args: BaseEventPayload<ElementDragType>) => void;
6
9
  onDrop: (args: BaseEventPayload<ElementDragType>) => void;
10
+ intl: IntlShape;
11
+ nodeViewPortalProviderAPI: PortalProviderAPI;
7
12
  }) => {
8
13
  rightHandle: HTMLDivElement;
9
14
  leftHandle: HTMLDivElement;
@@ -1,3 +1,5 @@
1
+ import type { IntlShape } from 'react-intl-next';
2
+ import { type PortalProviderAPI } from '@atlaskit/editor-common/portal';
1
3
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
4
  import type { Mark } from '@atlaskit/editor-prosemirror/model';
3
5
  import type { EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
@@ -9,16 +11,20 @@ export declare class ResizingMarkView implements NodeView {
9
11
  view: EditorView;
10
12
  mark: Mark;
11
13
  destroyFn: () => void;
14
+ intl: IntlShape;
15
+ nodeViewPortalProviderAPI: PortalProviderAPI;
12
16
  /**
13
17
  * Wrap node view in a resizing mark view
14
18
  * @param {Mark} mark - The breakout mark to resize
15
19
  * @param {EditorView} view - The editor view
16
- * @param {ExtractInjectionAPI<BreakoutPlugin> | undefined} api - the pluginInjectionAPI
20
+ * @param {ExtractInjectionAPI<BreakoutPlugin> | undefined} api - The pluginInjectionAPI
21
+ * @param {Function} getIntl - () => IntlShape
22
+ * @param {PortalProviderAPI} - The nodeViewPortalProviderAPI
17
23
  * @example
18
24
  * ```ts
19
25
  * ```
20
26
  */
21
- constructor(mark: Mark, view: EditorView, api: ExtractInjectionAPI<BreakoutPlugin> | undefined);
27
+ constructor(mark: Mark, view: EditorView, api: ExtractInjectionAPI<BreakoutPlugin> | undefined, getIntl: () => IntlShape, nodeViewPortalProviderAPI: PortalProviderAPI);
22
28
  ignoreMutation(): boolean;
23
29
  destroy(): void;
24
30
  }
@@ -1,7 +1,9 @@
1
+ import type { IntlShape } from 'react-intl-next';
2
+ import { type PortalProviderAPI } from '@atlaskit/editor-common/portal';
1
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
4
  import { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
5
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
6
  import { BreakoutPlugin } from '../breakoutPluginType';
5
7
  import type { BreakoutPluginOptions } from '../breakoutPluginType';
6
8
  export declare const resizingPluginKey: PluginKey<any>;
7
- export declare const createResizingPlugin: (api: ExtractInjectionAPI<BreakoutPlugin> | undefined, options?: BreakoutPluginOptions) => SafePlugin<any>;
9
+ export declare const createResizingPlugin: (api: ExtractInjectionAPI<BreakoutPlugin> | undefined, getIntl: () => IntlShape, nodeViewPortalProviderAPI: PortalProviderAPI, options?: BreakoutPluginOptions) => SafePlugin<any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-breakout",
3
- "version": "2.6.0",
3
+ "version": "2.6.1",
4
4
  "description": "Breakout plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -34,8 +34,8 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@atlaskit/adf-schema": "^47.6.0",
37
- "@atlaskit/editor-common": "^106.3.0",
38
- "@atlaskit/editor-plugin-block-controls": "^3.15.0",
37
+ "@atlaskit/editor-common": "^106.4.0",
38
+ "@atlaskit/editor-plugin-block-controls": "^3.16.0",
39
39
  "@atlaskit/editor-plugin-editor-disabled": "^2.0.0",
40
40
  "@atlaskit/editor-plugin-editor-viewmode": "^4.0.0",
41
41
  "@atlaskit/editor-plugin-guideline": "^2.0.0",
@@ -50,10 +50,12 @@
50
50
  "@atlaskit/theme": "^18.0.0",
51
51
  "@atlaskit/tmp-editor-statsig": "^5.14.0",
52
52
  "@atlaskit/tokens": "^5.1.0",
53
+ "@atlaskit/tooltip": "^20.3.0",
53
54
  "@babel/runtime": "^7.0.0",
54
55
  "@emotion/react": "^11.7.1",
55
56
  "bind-event-listener": "^3.0.0",
56
- "memoize-one": "^6.0.0"
57
+ "memoize-one": "^6.0.0",
58
+ "uuid": "^3.1.0"
57
59
  },
58
60
  "peerDependencies": {
59
61
  "react": "^18.2.0",