@atlaskit/editor-plugin-media 2.3.8 → 2.3.9

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 (68) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/mediaPlugin.js +7 -0
  3. package/dist/cjs/pm-plugins/pixel-resizing/commands.js +22 -0
  4. package/dist/cjs/pm-plugins/pixel-resizing/index.js +31 -0
  5. package/dist/cjs/pm-plugins/pixel-resizing/reducer.js +28 -0
  6. package/dist/cjs/pm-plugins/pixel-resizing/ui/constants.js +11 -0
  7. package/dist/cjs/pm-plugins/pixel-resizing/ui/index.js +124 -0
  8. package/dist/cjs/{ui/PixelEntry/index.js → pm-plugins/pixel-resizing/ui/pixel-entry.js} +168 -13
  9. package/dist/cjs/ui/toolbar/commands.js +29 -22
  10. package/dist/cjs/ui/toolbar/index.js +55 -94
  11. package/dist/cjs/ui/toolbar/linking.js +1 -1
  12. package/dist/cjs/ui/toolbar/pixel-resizing.js +47 -0
  13. package/dist/es2019/mediaPlugin.js +7 -0
  14. package/dist/es2019/pm-plugins/pixel-resizing/commands.js +16 -0
  15. package/dist/es2019/pm-plugins/pixel-resizing/index.js +27 -0
  16. package/dist/es2019/pm-plugins/pixel-resizing/reducer.js +20 -0
  17. package/dist/es2019/pm-plugins/pixel-resizing/ui/constants.js +5 -0
  18. package/dist/es2019/pm-plugins/pixel-resizing/ui/index.js +126 -0
  19. package/dist/es2019/{ui/PixelEntry/index.js → pm-plugins/pixel-resizing/ui/pixel-entry.js} +170 -19
  20. package/dist/es2019/ui/toolbar/commands.js +9 -2
  21. package/dist/es2019/ui/toolbar/index.js +47 -88
  22. package/dist/es2019/ui/toolbar/linking.js +1 -1
  23. package/dist/es2019/ui/toolbar/pixel-resizing.js +37 -0
  24. package/dist/esm/mediaPlugin.js +7 -0
  25. package/dist/esm/pm-plugins/pixel-resizing/commands.js +16 -0
  26. package/dist/esm/pm-plugins/pixel-resizing/index.js +25 -0
  27. package/dist/esm/pm-plugins/pixel-resizing/reducer.js +21 -0
  28. package/dist/esm/pm-plugins/pixel-resizing/ui/constants.js +5 -0
  29. package/dist/esm/pm-plugins/pixel-resizing/ui/index.js +120 -0
  30. package/dist/esm/{ui/PixelEntry/index.js → pm-plugins/pixel-resizing/ui/pixel-entry.js} +172 -17
  31. package/dist/esm/ui/toolbar/commands.js +28 -21
  32. package/dist/esm/ui/toolbar/index.js +47 -86
  33. package/dist/esm/ui/toolbar/linking.js +1 -1
  34. package/dist/esm/ui/toolbar/pixel-resizing.js +40 -0
  35. package/dist/types/pm-plugins/pixel-resizing/commands.d.ts +4 -0
  36. package/dist/types/pm-plugins/pixel-resizing/index.d.ts +13 -0
  37. package/dist/types/pm-plugins/pixel-resizing/reducer.d.ts +12 -0
  38. package/dist/types/pm-plugins/pixel-resizing/ui/constants.d.ts +3 -0
  39. package/dist/types/pm-plugins/pixel-resizing/ui/index.d.ts +21 -0
  40. package/dist/types/pm-plugins/pixel-resizing/ui/pixel-entry.d.ts +4 -0
  41. package/dist/types/{ui/PixelEntry → pm-plugins/pixel-resizing/ui}/types.d.ts +18 -0
  42. package/dist/types/ui/toolbar/commands.d.ts +2 -1
  43. package/dist/types/ui/toolbar/pixel-resizing.d.ts +4 -0
  44. package/dist/types-ts4.5/pm-plugins/pixel-resizing/commands.d.ts +4 -0
  45. package/dist/types-ts4.5/pm-plugins/pixel-resizing/index.d.ts +13 -0
  46. package/dist/types-ts4.5/pm-plugins/pixel-resizing/reducer.d.ts +12 -0
  47. package/dist/types-ts4.5/pm-plugins/pixel-resizing/ui/constants.d.ts +3 -0
  48. package/dist/types-ts4.5/pm-plugins/pixel-resizing/ui/index.d.ts +21 -0
  49. package/dist/types-ts4.5/pm-plugins/pixel-resizing/ui/pixel-entry.d.ts +4 -0
  50. package/dist/types-ts4.5/{ui/PixelEntry → pm-plugins/pixel-resizing/ui}/types.d.ts +18 -0
  51. package/dist/types-ts4.5/ui/toolbar/commands.d.ts +2 -1
  52. package/dist/types-ts4.5/ui/toolbar/pixel-resizing.d.ts +4 -0
  53. package/package.json +5 -5
  54. package/dist/cjs/ui/PixelEntry/constants.js +0 -7
  55. package/dist/es2019/ui/PixelEntry/constants.js +0 -1
  56. package/dist/esm/ui/PixelEntry/constants.js +0 -1
  57. package/dist/types/ui/PixelEntry/constants.d.ts +0 -1
  58. package/dist/types/ui/PixelEntry/index.d.ts +0 -7
  59. package/dist/types-ts4.5/ui/PixelEntry/constants.d.ts +0 -1
  60. package/dist/types-ts4.5/ui/PixelEntry/index.d.ts +0 -7
  61. /package/dist/cjs/{ui/PixelEntry → pm-plugins/pixel-resizing/ui}/styles.js +0 -0
  62. /package/dist/cjs/{ui/PixelEntry → pm-plugins/pixel-resizing/ui}/types.js +0 -0
  63. /package/dist/es2019/{ui/PixelEntry → pm-plugins/pixel-resizing/ui}/styles.js +0 -0
  64. /package/dist/es2019/{ui/PixelEntry → pm-plugins/pixel-resizing/ui}/types.js +0 -0
  65. /package/dist/esm/{ui/PixelEntry → pm-plugins/pixel-resizing/ui}/styles.js +0 -0
  66. /package/dist/esm/{ui/PixelEntry → pm-plugins/pixel-resizing/ui}/types.js +0 -0
  67. /package/dist/types/{ui/PixelEntry → pm-plugins/pixel-resizing/ui}/styles.d.ts +0 -0
  68. /package/dist/types-ts4.5/{ui/PixelEntry → pm-plugins/pixel-resizing/ui}/styles.d.ts +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @atlaskit/editor-plugin-media
2
2
 
3
+ ## 2.3.9
4
+
5
+ ### Patch Changes
6
+
7
+ - [#128123](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/128123)
8
+ [`ab71af4c9be90`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ab71af4c9be90) -
9
+ [ux] [ED-26947] Implement media pixel resizing editor
10
+ - Updated dependencies
11
+
3
12
  ## 2.3.8
4
13
 
5
14
  ### Patch Changes
@@ -32,6 +32,7 @@ var _keymapMedia = _interopRequireDefault(require("./pm-plugins/keymap-media"));
32
32
  var _linking = _interopRequireDefault(require("./pm-plugins/linking"));
33
33
  var _keymap3 = _interopRequireDefault(require("./pm-plugins/linking/keymap"));
34
34
  var _main = require("./pm-plugins/main");
35
+ var _pixelResizing = require("./pm-plugins/pixel-resizing");
35
36
  var _pluginKey = require("./pm-plugins/plugin-key");
36
37
  var _mediaCommon2 = require("./pm-plugins/utils/media-common");
37
38
  var _mediaSingle2 = require("./pm-plugins/utils/media-single");
@@ -244,6 +245,12 @@ var mediaPlugin = exports.mediaPlugin = function mediaPlugin(_ref3) {
244
245
  }
245
246
  });
246
247
  }
248
+ if (options && options.allowAdvancedToolBarOptions && options.allowResizing && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_media_extended_resize_experience')) {
249
+ pmPlugins.push({
250
+ name: 'mediaPixelResizing',
251
+ plugin: _pixelResizing.createPlugin
252
+ });
253
+ }
247
254
  pmPlugins.push({
248
255
  name: 'mediaSelectionHandler',
249
256
  plugin: function plugin() {
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.openPixelEditor = exports.closePixelEditorAndSave = exports.closePixelEditor = void 0;
7
+ var _index = require("./index");
8
+ var openPixelEditor = exports.openPixelEditor = function openPixelEditor() {
9
+ return (0, _index.createCommand)({
10
+ type: 'openPixelEditor'
11
+ });
12
+ };
13
+ var closePixelEditor = exports.closePixelEditor = function closePixelEditor() {
14
+ return (0, _index.createCommand)({
15
+ type: 'closePixelEditor'
16
+ });
17
+ };
18
+ var closePixelEditorAndSave = exports.closePixelEditorAndSave = function closePixelEditorAndSave(saveTransform) {
19
+ return (0, _index.createCommand)({
20
+ type: 'closePixelEditor'
21
+ }, saveTransform);
22
+ };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getPluginState = exports.createPlugin = exports.createCommand = void 0;
8
+ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
9
+ var _utils = require("@atlaskit/editor-common/utils");
10
+ var _state = require("@atlaskit/editor-prosemirror/state");
11
+ var _reducer = _interopRequireDefault(require("./reducer"));
12
+ var pluginKey = new _state.PluginKey('mediaPixelResizingPlugin');
13
+ var _pluginFactory = (0, _utils.pluginFactory)(pluginKey, _reducer.default, {
14
+ onSelectionChanged: function onSelectionChanged() {
15
+ return {
16
+ isPixelEditorOpen: false
17
+ };
18
+ }
19
+ }),
20
+ createPluginState = _pluginFactory.createPluginState,
21
+ createCommand = exports.createCommand = _pluginFactory.createCommand,
22
+ getPluginState = exports.getPluginState = _pluginFactory.getPluginState;
23
+ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
24
+ var dispatch = _ref.dispatch;
25
+ return new _safePlugin.SafePlugin({
26
+ state: createPluginState(dispatch, {
27
+ isPixelEditorOpen: false
28
+ }),
29
+ key: pluginKey
30
+ });
31
+ };
@@ -0,0 +1,28 @@
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 _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ 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; }
10
+ 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; }
11
+ var _default = exports.default = function _default(state, action) {
12
+ switch (action.type) {
13
+ case 'openPixelEditor':
14
+ {
15
+ return _objectSpread(_objectSpread({}, state), {}, {
16
+ isPixelEditorOpen: true
17
+ });
18
+ }
19
+ case 'closePixelEditor':
20
+ {
21
+ return _objectSpread(_objectSpread({}, state), {}, {
22
+ isPixelEditorOpen: false
23
+ });
24
+ }
25
+ default:
26
+ return state;
27
+ }
28
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.PIXEL_VIEW_MODE_TOOLBAR_WIDTH = exports.PIXEL_RESIZING_TOOLBAR_WIDTH = exports.PIXELENTRY_MIGRATION_BUTTON_TESTID = void 0;
7
+ var PIXELENTRY_MIGRATION_BUTTON_TESTID = exports.PIXELENTRY_MIGRATION_BUTTON_TESTID = 'pixel-entry-convert-pixels-btn';
8
+
9
+ // pixel resizing toolbar width (with `platform_editor_controls` enabled)
10
+ var PIXEL_RESIZING_TOOLBAR_WIDTH = exports.PIXEL_RESIZING_TOOLBAR_WIDTH = 240;
11
+ var PIXEL_VIEW_MODE_TOOLBAR_WIDTH = exports.PIXEL_VIEW_MODE_TOOLBAR_WIDTH = 204;
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.PixelEntry = exports.FullWidthDisplay = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _react = require("react");
10
+ var _react2 = require("@emotion/react");
11
+ var _media = require("@atlaskit/editor-common/media");
12
+ var _mediaSingle = require("@atlaskit/editor-common/media-single");
13
+ var _state = require("@atlaskit/editor-prosemirror/state");
14
+ var _utils = require("@atlaskit/editor-prosemirror/utils");
15
+ var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
16
+ var _primitives = require("@atlaskit/primitives");
17
+ var _commands = require("../../../ui/toolbar/commands");
18
+ var _utils2 = require("../../../ui/toolbar/utils");
19
+ var _mediaSingle2 = require("../../utils/media-single");
20
+ var _commands2 = require("../commands");
21
+ var _pixelEntry = require("./pixel-entry");
22
+ var _styles = require("./styles");
23
+ 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; }
24
+ 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; } /**
25
+ * @jsxRuntime classic
26
+ * @jsx jsx
27
+ */ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
28
+ var PixelEntry = exports.PixelEntry = function PixelEntry(_ref) {
29
+ var _pluginInjectionApi$w, _pluginInjectionApi$m;
30
+ var editorView = _ref.editorView,
31
+ selectedMediaSingleNode = _ref.selectedMediaSingleNode,
32
+ pluginInjectionApi = _ref.pluginInjectionApi,
33
+ intl = _ref.intl,
34
+ pluginState = _ref.pluginState,
35
+ hoverDecoration = _ref.hoverDecoration,
36
+ isEditorFullWidthEnabled = _ref.isEditorFullWidthEnabled;
37
+ var state = editorView.state,
38
+ dispatch = editorView.dispatch;
39
+ var mediaSingle = state.schema.nodes.mediaSingle;
40
+ var contentWidth = (pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$w = pluginInjectionApi.width.sharedState.currentState()) === null || _pluginInjectionApi$w === void 0 ? void 0 : _pluginInjectionApi$w.lineLength) || _editorSharedStyles.akEditorDefaultLayoutWidth;
41
+ var _selectedMediaSingleN = selectedMediaSingleNode.node.attrs,
42
+ mediaSingleWidth = _selectedMediaSingleN.width,
43
+ widthType = _selectedMediaSingleN.widthType,
44
+ layout = _selectedMediaSingleN.layout;
45
+
46
+ // hasParentNode will return falsey value if selection depth === 0
47
+ var isNested = (0, _utils.hasParentNode)(function (n) {
48
+ return n.type !== state.schema.nodes.doc;
49
+ })(state.selection);
50
+ var updateNodeWithTr = (0, _react.useCallback)(function (width, validation) {
51
+ var _pluginInjectionApi$a;
52
+ var newLayout = (0, _utils2.calcNewLayout)(width, layout, contentWidth, isEditorFullWidthEnabled, isNested);
53
+ return (0, _commands.updateMediaSingleWidthTr)(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions, state, width, validation, 'floatingToolBar', newLayout);
54
+ }, [layout, contentWidth, isEditorFullWidthEnabled, isNested, state, pluginInjectionApi]);
55
+ var selectedMediaNode = selectedMediaSingleNode.node.content.firstChild;
56
+ if (!selectedMediaNode) {
57
+ return null;
58
+ }
59
+ var _selectedMediaNode$at = selectedMediaNode.attrs,
60
+ mediaWidth = _selectedMediaNode$at.width,
61
+ mediaHeight = _selectedMediaNode$at.height;
62
+ var maxWidthForNestedNode = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$m = pluginInjectionApi.media) === null || _pluginInjectionApi$m === void 0 || (_pluginInjectionApi$m = _pluginInjectionApi$m.sharedState.currentState()) === null || _pluginInjectionApi$m === void 0 ? void 0 : _pluginInjectionApi$m.currentMaxWidth;
63
+ var maxWidth = maxWidthForNestedNode || _editorSharedStyles.akEditorFullWidthLayoutWidth;
64
+ var isVideoFile = (0, _mediaSingle2.isVideo)(selectedMediaNode.attrs.__fileMimeType);
65
+ var minWidth = (0, _mediaSingle.calcMinWidth)(isVideoFile, maxWidthForNestedNode || contentWidth);
66
+ var hasPixelType = widthType === 'pixel';
67
+ var pixelWidthFromElement = (0, _utils2.getPixelWidthOfElement)(editorView, selectedMediaSingleNode.pos + 1,
68
+ // get pos of media node
69
+ mediaWidth || _mediaSingle.DEFAULT_IMAGE_WIDTH);
70
+ var pixelWidth = hasPixelType ? mediaSingleWidth : pixelWidthFromElement;
71
+ return (0, _react2.jsx)(_pixelEntry.PixelEntryComponent, {
72
+ intl: intl,
73
+ width: pluginState.isResizing ? pluginState.resizingWidth : pixelWidth,
74
+ showMigration: !pluginState.isResizing && !hasPixelType,
75
+ mediaWidth: mediaWidth || _mediaSingle.DEFAULT_IMAGE_WIDTH,
76
+ mediaHeight: mediaHeight || _mediaSingle.DEFAULT_IMAGE_HEIGHT,
77
+ minWidth: minWidth,
78
+ maxWidth: maxWidth,
79
+ onChange: function onChange(valid) {
80
+ if (valid) {
81
+ hoverDecoration === null || hoverDecoration === void 0 || hoverDecoration(mediaSingle, true, 'warning')(editorView.state, dispatch, editorView);
82
+ } else {
83
+ hoverDecoration === null || hoverDecoration === void 0 || hoverDecoration(mediaSingle, false)(editorView.state, dispatch, editorView);
84
+ }
85
+ },
86
+ onSubmit: function onSubmit(_ref2) {
87
+ var width = _ref2.width,
88
+ validation = _ref2.validation;
89
+ var tr = updateNodeWithTr(width, validation);
90
+ if (tr) {
91
+ dispatch(tr);
92
+ }
93
+ },
94
+ onMigrate: function onMigrate() {
95
+ var tr = state.tr.setNodeMarkup(selectedMediaSingleNode.pos, undefined, _objectSpread(_objectSpread({}, selectedMediaSingleNode.node.attrs), {}, {
96
+ width: pixelWidthFromElement,
97
+ widthType: 'pixel'
98
+ }));
99
+ tr.setMeta('scrollIntoView', false);
100
+ tr.setSelection(_state.NodeSelection.create(tr.doc, selectedMediaSingleNode.pos));
101
+ dispatch(tr);
102
+ },
103
+ onCloseAndSave: function onCloseAndSave(_ref3) {
104
+ var width = _ref3.width,
105
+ validation = _ref3.validation;
106
+ var tr = updateNodeWithTr(width, validation);
107
+ if (tr) {
108
+ return (0, _commands2.closePixelEditorAndSave)(function () {
109
+ return tr;
110
+ })(state, dispatch);
111
+ }
112
+ },
113
+ isViewMode: pluginState.isResizing
114
+ });
115
+ };
116
+ var FullWidthDisplay = exports.FullWidthDisplay = function FullWidthDisplay(_ref4) {
117
+ var formatMessage = _ref4.intl.formatMessage;
118
+ return (
119
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
120
+ (0, _react2.jsx)("div", {
121
+ css: _styles.pixelSizingFullWidthLabelStyles
122
+ }, (0, _react2.jsx)(_primitives.Text, null, formatMessage(_media.pixelEntryMessages.fullWidthLabel)))
123
+ );
124
+ };
@@ -5,16 +5,19 @@ var _typeof = require("@babel/runtime/helpers/typeof");
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.PixelEntry = exports.FullWidthDisplay = void 0;
8
+ exports.PixelEntryComponentNext = exports.PixelEntryComponent = void 0;
9
9
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
10
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
11
  var _react = require("react");
12
12
  var _react2 = require("@emotion/react");
13
13
  var _button = _interopRequireDefault(require("@atlaskit/button"));
14
+ var _new = require("@atlaskit/button/new");
14
15
  var _media = require("@atlaskit/editor-common/media");
15
16
  var _form = _interopRequireWildcard(require("@atlaskit/form"));
17
+ var _close = _interopRequireDefault(require("@atlaskit/icon/core/close"));
16
18
  var _primitives = require("@atlaskit/primitives");
17
19
  var _textfield = _interopRequireDefault(require("@atlaskit/textfield"));
20
+ var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
18
21
  var _tooltip = _interopRequireDefault(require("@atlaskit/tooltip"));
19
22
  var _constants = require("./constants");
20
23
  var _styles = require("./styles");
@@ -31,7 +34,7 @@ var pixelSizingLabel = (0, _primitives.xcss)({
31
34
  gridArea: 'label',
32
35
  lineHeight: "var(--ds-space-300, 24px)"
33
36
  });
34
- var PixelEntry = exports.PixelEntry = function PixelEntry(_ref) {
37
+ var PixelEntryComponent = exports.PixelEntryComponent = function PixelEntryComponent(_ref) {
35
38
  var width = _ref.width,
36
39
  mediaWidth = _ref.mediaWidth,
37
40
  mediaHeight = _ref.mediaHeight,
@@ -41,7 +44,9 @@ var PixelEntry = exports.PixelEntry = function PixelEntry(_ref) {
41
44
  onChange = _ref.onChange,
42
45
  formatMessage = _ref.intl.formatMessage,
43
46
  showMigration = _ref.showMigration,
44
- onMigrate = _ref.onMigrate;
47
+ onMigrate = _ref.onMigrate,
48
+ onCloseAndSave = _ref.onCloseAndSave,
49
+ isViewMode = _ref.isViewMode;
45
50
  var ratioWidth = (0, _react.useMemo)(function () {
46
51
  return mediaHeight / mediaWidth;
47
52
  }, [mediaHeight, mediaWidth]);
@@ -94,6 +99,37 @@ var PixelEntry = exports.PixelEntry = function PixelEntry(_ref) {
94
99
  }
95
100
  };
96
101
 
102
+ // Handle submit when user presses enter or click close button in PixelEntryComponentNext
103
+ var handleCloseAndSave = (0, _react.useCallback)(function (data) {
104
+ if (data.inputWidth === '' || data.inputHeight === '') {
105
+ return;
106
+ }
107
+ if (onCloseAndSave) {
108
+ var widthToBeSubmitted = data.inputWidth;
109
+ var validation = 'valid';
110
+ if (data.inputWidth < minWidth) {
111
+ widthToBeSubmitted = minWidth;
112
+ validation = 'less-than-min';
113
+ }
114
+ if (data.inputWidth > maxWidth) {
115
+ widthToBeSubmitted = maxWidth;
116
+ validation = 'greater-than-max';
117
+ }
118
+
119
+ // If user keeps submitting an invalid input, node width attribute will be updated with the same value
120
+ // and won't upadte the state in useEffect (since width is the same)
121
+ // Thus, we set the state here to always display the correct dimension
122
+ if (validation !== 'valid') {
123
+ setComputedWidth(widthToBeSubmitted);
124
+ setComputedHeight(Math.round(ratioWidth * widthToBeSubmitted));
125
+ }
126
+ onCloseAndSave({
127
+ width: widthToBeSubmitted,
128
+ validation: validation
129
+ });
130
+ }
131
+ }, [maxWidth, minWidth, onCloseAndSave, ratioWidth]);
132
+
97
133
  // Handle updating computed fields based on
98
134
  var handleOnChange = (0, _react.useCallback)(function (type) {
99
135
  return function (event) {
@@ -131,6 +167,17 @@ var PixelEntry = exports.PixelEntry = function PixelEntry(_ref) {
131
167
  testId: _constants.PIXELENTRY_MIGRATION_BUTTON_TESTID
132
168
  }, formatMessage(_media.pixelEntryMessages.migrationButtonText)));
133
169
  }
170
+ if ((0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
171
+ return (0, _react2.jsx)(PixelEntryComponentNext, {
172
+ maxWidth: maxWidth,
173
+ formatMessage: formatMessage,
174
+ handleFieldChange: handleOnChange,
175
+ computedWidth: computedWidth,
176
+ computedHeight: computedHeight,
177
+ handleCloseAndSave: handleCloseAndSave,
178
+ isViewMode: isViewMode
179
+ });
180
+ }
134
181
  return (
135
182
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
136
183
  (0, _react2.jsx)("div", {
@@ -160,7 +207,7 @@ var PixelEntry = exports.PixelEntry = function PixelEntry(_ref) {
160
207
  // Ignored via go/ees005
161
208
  // eslint-disable-next-line react/jsx-props-no-spreading
162
209
  , (0, _extends2.default)({}, fieldProps, {
163
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
210
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/no-unsafe-style-overrides -- Ignored via go/DSP-18766
164
211
  css: [_styles.pixelSizingWidthInput, _styles.pixelSizingInput],
165
212
  appearance: "none",
166
213
  isCompact: true,
@@ -187,7 +234,7 @@ var PixelEntry = exports.PixelEntry = function PixelEntry(_ref) {
187
234
  // Ignored via go/ees005
188
235
  // eslint-disable-next-line react/jsx-props-no-spreading
189
236
  , (0, _extends2.default)({}, fieldProps, {
190
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
237
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/no-unsafe-style-overrides -- Ignored via go/DSP-18766
191
238
  css: [_styles.pixelSizingHeightInput, _styles.pixelSizingInput],
192
239
  appearance: "none",
193
240
  isCompact: true,
@@ -203,12 +250,120 @@ var PixelEntry = exports.PixelEntry = function PixelEntry(_ref) {
203
250
  }))
204
251
  );
205
252
  };
206
- var FullWidthDisplay = exports.FullWidthDisplay = function FullWidthDisplay(_ref5) {
207
- var formatMessage = _ref5.intl.formatMessage;
208
- return (
209
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
210
- (0, _react2.jsx)("div", {
211
- css: _styles.pixelSizingFullWidthLabelStyles
212
- }, (0, _react2.jsx)(_primitives.Text, null, formatMessage(_media.pixelEntryMessages.fullWidthLabel)))
213
- );
253
+ var pixelEntryWrapperStyles = (0, _primitives.xcss)({
254
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values
255
+ width: "".concat(_constants.PIXEL_RESIZING_TOOLBAR_WIDTH, "px")
256
+ });
257
+ var pixelEntryWrapperViewModeStyles = (0, _primitives.xcss)({
258
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values
259
+ width: "".concat(_constants.PIXEL_VIEW_MODE_TOOLBAR_WIDTH, "px")
260
+ });
261
+ var fieldStyles = (0, _react2.css)({
262
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors
263
+ '[data-ds--text-field--input]': {
264
+ paddingBlock: "var(--ds-space-0, 0px)",
265
+ paddingInline: "var(--ds-space-100, 8px)"
266
+ },
267
+ flex: '1'
268
+ });
269
+ var dividerStyles = (0, _primitives.xcss)({
270
+ width: '1px',
271
+ height: "var(--ds-space-500, 40px)",
272
+ background: "var(--ds-border, #091E4224)",
273
+ marginInlineEnd: 'space.050'
274
+ });
275
+ var PixelEntryComponentNext = exports.PixelEntryComponentNext = function PixelEntryComponentNext(_ref5) {
276
+ var maxWidth = _ref5.maxWidth,
277
+ formatMessage = _ref5.formatMessage,
278
+ handleFieldChange = _ref5.handleFieldChange,
279
+ computedWidth = _ref5.computedWidth,
280
+ computedHeight = _ref5.computedHeight,
281
+ handleCloseAndSave = _ref5.handleCloseAndSave,
282
+ isViewMode = _ref5.isViewMode;
283
+ var widthInputRef = (0, _react.useRef)(null);
284
+ (0, _react.useEffect)(function () {
285
+ if (widthInputRef.current) {
286
+ if (isViewMode) {
287
+ widthInputRef.current.blur();
288
+ } else {
289
+ widthInputRef.current.focus();
290
+ }
291
+ }
292
+ }, [isViewMode, widthInputRef]);
293
+ var handleKeyDown = (0, _react.useCallback)(function (event) {
294
+ if (event.key === 'Enter') {
295
+ handleCloseAndSave({
296
+ inputWidth: computedWidth,
297
+ inputHeight: computedHeight
298
+ });
299
+ }
300
+ }, [computedWidth, computedHeight, handleCloseAndSave]);
301
+ return (0, _react2.jsx)(_primitives.Box, {
302
+ xcss: [pixelEntryWrapperStyles, isViewMode && pixelEntryWrapperViewModeStyles]
303
+ }, (0, _react2.jsx)(_primitives.Inline, {
304
+ alignBlock: "center",
305
+ spread: "space-between"
306
+ }, (0, _react2.jsx)(_primitives.Box, {
307
+ paddingInlineStart: "space.100"
308
+ }, (0, _react2.jsx)(_primitives.Text, {
309
+ color: "color.text.subtlest"
310
+ }, formatMessage(_media.pixelEntryMessages.inputWidthLabel))), (0, _react2.jsx)("div", {
311
+ css: fieldStyles
312
+ }, (0, _react2.jsx)(_tooltip.default, {
313
+ hideTooltipOnMouseDown: true,
314
+ hideTooltipOnClick: true,
315
+ position: "top",
316
+ content: formatMessage(_media.pixelEntryMessages.inputWidthTooltip, {
317
+ maxWidth: maxWidth
318
+ })
319
+ }, (0, _react2.jsx)(_textfield.default, {
320
+ name: "inputWidth",
321
+ value: computedWidth,
322
+ ref: widthInputRef,
323
+ height: "var(--ds-space-250, 20px)",
324
+ appearance: "none",
325
+ pattern: "\\d*",
326
+ "aria-label": formatMessage(_media.pixelEntryMessages.inputWidthAriaLabel, {
327
+ maxWidth: maxWidth
328
+ }),
329
+ onChange: handleFieldChange('inputWidth'),
330
+ onKeyDown: handleKeyDown
331
+ }))), (0, _react2.jsx)(_primitives.Box, {
332
+ paddingInlineStart: "space.100"
333
+ }, (0, _react2.jsx)(_primitives.Text, {
334
+ color: "color.text.subtlest"
335
+ }, formatMessage(_media.pixelEntryMessages.inputHeightTooltip))), (0, _react2.jsx)("div", {
336
+ css: fieldStyles
337
+ }, (0, _react2.jsx)(_tooltip.default, {
338
+ hideTooltipOnMouseDown: true,
339
+ hideTooltipOnClick: true,
340
+ content: formatMessage(_media.pixelEntryMessages.inputHeightTooltip),
341
+ position: "top"
342
+ }, (0, _react2.jsx)(_textfield.default, {
343
+ name: "inputHeight",
344
+ value: computedHeight,
345
+ height: "var(--ds-space-250, 20px)",
346
+ appearance: "none",
347
+ pattern: "\\d*",
348
+ "aria-label": formatMessage(_media.pixelEntryMessages.inputHeightAriaLabel),
349
+ onChange: handleFieldChange('inputHeight'),
350
+ onKeyDown: handleKeyDown
351
+ }))), !isViewMode && (0, _react2.jsx)(_react.Fragment, null, (0, _react2.jsx)(_primitives.Box, {
352
+ xcss: dividerStyles
353
+ }), (0, _react2.jsx)(_new.IconButton, {
354
+ icon: function icon() {
355
+ return (0, _react2.jsx)(_close.default, {
356
+ label: "",
357
+ color: "var(--ds-icon-subtlest, #626F86)"
358
+ });
359
+ },
360
+ label: formatMessage(_media.pixelEntryMessages.closePixelEntry),
361
+ appearance: "subtle",
362
+ onClick: function onClick() {
363
+ handleCloseAndSave({
364
+ inputWidth: computedWidth,
365
+ inputHeight: computedHeight
366
+ });
367
+ }
368
+ }))));
214
369
  };
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.updateMediaSingleWidth = exports.toggleBorderMark = exports.setBorderMark = exports.removeInlineCard = exports.getNodeType = exports.changeMediaSingleToMediaInline = exports.changeMediaInlineToMediaSingle = exports.changeMediaCardToInline = exports.changeInlineToMediaCard = exports.DEFAULT_BORDER_SIZE = exports.DEFAULT_BORDER_COLOR = void 0;
7
+ exports.updateMediaSingleWidthTr = exports.updateMediaSingleWidth = exports.toggleBorderMark = exports.setBorderMark = exports.removeInlineCard = exports.getNodeType = exports.changeMediaSingleToMediaInline = exports.changeMediaInlineToMediaSingle = exports.changeMediaCardToInline = exports.changeInlineToMediaCard = exports.DEFAULT_BORDER_SIZE = exports.DEFAULT_BORDER_COLOR = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _analytics = require("@atlaskit/editor-common/analytics");
10
10
  var _mediaSingle = require("@atlaskit/editor-common/media-single");
@@ -259,32 +259,39 @@ var setBorderMark = exports.setBorderMark = function setBorderMark(editorAnalyti
259
259
  };
260
260
  };
261
261
  };
262
+ var updateMediaSingleWidthTr = exports.updateMediaSingleWidthTr = function updateMediaSingleWidthTr(editorAnalyticsAPI, state, width, validation, inputMethod, layout) {
263
+ var selectedMediaSingleNode = (0, _utils2.getSelectedMediaSingle)(state);
264
+ if (!selectedMediaSingleNode) {
265
+ return null;
266
+ }
267
+ var tr = state.tr.setNodeMarkup(selectedMediaSingleNode.pos, undefined, _objectSpread(_objectSpread({}, selectedMediaSingleNode.node.attrs), {}, {
268
+ width: width,
269
+ widthType: 'pixel',
270
+ layout: layout
271
+ }));
272
+ tr.setMeta('scrollIntoView', false);
273
+ tr.setSelection(_state.NodeSelection.create(tr.doc, selectedMediaSingleNode.pos));
274
+ var $pos = state.doc.resolve(selectedMediaSingleNode.pos);
275
+ var parentNodeType = $pos ? $pos.parent.type.name : undefined;
276
+ var payload = (0, _analytics2.getMediaInputResizeAnalyticsEvent)('mediaSingle', {
277
+ width: width,
278
+ layout: layout,
279
+ validation: validation,
280
+ inputMethod: inputMethod,
281
+ parentNode: parentNodeType
282
+ });
283
+ if (payload) {
284
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(payload)(tr);
285
+ }
286
+ return tr;
287
+ };
262
288
  var updateMediaSingleWidth = exports.updateMediaSingleWidth = function updateMediaSingleWidth(editorAnalyticsAPI) {
263
289
  return function (width, validation, inputMethod, layout) {
264
290
  return function (state, dispatch) {
265
- var selectedMediaSingleNode = (0, _utils2.getSelectedMediaSingle)(state);
266
- if (!selectedMediaSingleNode) {
291
+ var tr = updateMediaSingleWidthTr(editorAnalyticsAPI, state, width, validation, inputMethod, layout);
292
+ if (!tr) {
267
293
  return false;
268
294
  }
269
- var tr = state.tr.setNodeMarkup(selectedMediaSingleNode.pos, undefined, _objectSpread(_objectSpread({}, selectedMediaSingleNode.node.attrs), {}, {
270
- width: width,
271
- widthType: 'pixel',
272
- layout: layout
273
- }));
274
- tr.setMeta('scrollIntoView', false);
275
- tr.setSelection(_state.NodeSelection.create(tr.doc, selectedMediaSingleNode.pos));
276
- var $pos = state.doc.resolve(selectedMediaSingleNode.pos);
277
- var parentNodeType = $pos ? $pos.parent.type.name : undefined;
278
- var payload = (0, _analytics2.getMediaInputResizeAnalyticsEvent)('mediaSingle', {
279
- width: width,
280
- layout: layout,
281
- validation: validation,
282
- inputMethod: inputMethod,
283
- parentNode: parentNodeType
284
- });
285
- if (payload) {
286
- editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(payload)(tr);
287
- }
288
295
  if (dispatch) {
289
296
  dispatch(tr);
290
297
  }