@atlaskit/editor-plugin-media 0.12.0 → 0.12.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,12 @@
1
1
  # @atlaskit/editor-plugin-media
2
2
 
3
+ ## 0.12.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#66027](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/66027) [`9e0417874343`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/9e0417874343) - [CXP-2867] Fix superfluous newline in inline-to-card conversion
8
+ - Updated dependencies
9
+
3
10
  ## 0.12.0
4
11
 
5
12
  ### Minor Changes
@@ -28,10 +28,13 @@ var getNodeType = exports.getNodeType = function getNodeType(state) {
28
28
  };
29
29
  var changeInlineToMediaCard = exports.changeInlineToMediaCard = function changeInlineToMediaCard(editorAnalyticsAPI, forceFocusSelector) {
30
30
  return function (state, dispatch) {
31
+ var _findParentNodeCloses, _parent$content$first, _parent$content$lastC, _parent$content$lastC2;
31
32
  var _state$schema$nodes2 = state.schema.nodes,
32
33
  media = _state$schema$nodes2.media,
33
34
  mediaInline = _state$schema$nodes2.mediaInline,
34
- mediaGroup = _state$schema$nodes2.mediaGroup;
35
+ mediaGroup = _state$schema$nodes2.mediaGroup,
36
+ paragraph = _state$schema$nodes2.paragraph,
37
+ heading = _state$schema$nodes2.heading;
35
38
  var selectedNode = state.selection instanceof _state.NodeSelection && state.selection.node.type === mediaInline && state.selection.node;
36
39
  if (!selectedNode) {
37
40
  return false;
@@ -46,10 +49,26 @@ var changeInlineToMediaCard = exports.changeInlineToMediaCard = function changeI
46
49
  collection: collection
47
50
  });
48
51
  var group = mediaGroup.createChecked({}, mediaNode);
49
- var nodePos = state.tr.doc.resolve(state.selection.from).end();
52
+ var parent = (_findParentNodeCloses = (0, _utils.findParentNodeClosestToPos)(state.selection.$from, function (node) {
53
+ return node.type === paragraph || node.type === heading;
54
+ })) === null || _findParentNodeCloses === void 0 ? void 0 : _findParentNodeCloses.node;
50
55
  var tr = state.tr;
51
- tr = (0, _utils.removeSelectedNode)(tr);
52
- tr = (0, _utils.safeInsert)(group, nodePos, true)(tr);
56
+ if (!!parent && parent.content.size === 2 && ((_parent$content$first = parent.content.firstChild) === null || _parent$content$first === void 0 ? void 0 : _parent$content$first.type.name) === 'mediaInline' && ((_parent$content$lastC = parent.content.lastChild) === null || _parent$content$lastC === void 0 ? void 0 : _parent$content$lastC.type.name) === 'text' && ((_parent$content$lastC2 = parent.content.lastChild) === null || _parent$content$lastC2 === void 0 || (_parent$content$lastC2 = _parent$content$lastC2.text) === null || _parent$content$lastC2 === void 0 ? void 0 : _parent$content$lastC2.trim()) === '') {
57
+ /// Empty paragraph or empty heading
58
+ /// Drop the corresponding card on the current line
59
+ var insertPos = state.tr.doc.resolve(state.selection.from).start() - 1;
60
+ if (insertPos < 0) {
61
+ return false;
62
+ }
63
+ tr = tr.delete(insertPos, insertPos + parent.nodeSize);
64
+ tr = (0, _utils.safeInsert)(group, insertPos, false)(tr);
65
+ } else {
66
+ /// Non-empty paragraph, non-empty heading, or other nodes (e.g., action, list)
67
+ /// Drop the corresponding card underneath the current line
68
+ var _insertPos = state.tr.doc.resolve(state.selection.from).end();
69
+ tr = (0, _utils.removeSelectedNode)(tr);
70
+ tr = (0, _utils.safeInsert)(group, _insertPos, false)(tr);
71
+ }
53
72
  if (dispatch) {
54
73
  editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
55
74
  action: _analytics.ACTION.CHANGED_TYPE,
@@ -60,6 +79,7 @@ var changeInlineToMediaCard = exports.changeInlineToMediaCard = function changeI
60
79
  previousType: _analytics.ACTION_SUBJECT_ID.MEDIA_INLINE
61
80
  }
62
81
  })(tr);
82
+ var nodePos = state.tr.doc.resolve(state.selection.from).end();
63
83
  if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.ally-media-file-dropdown_1kxo8')) {
64
84
  var $endOfNode = tr.doc.resolve(nodePos + 1);
65
85
  var newSelection = new _state.NodeSelection($endOfNode);
@@ -1,7 +1,7 @@
1
1
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
2
2
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
3
3
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
4
- import { isNodeSelection, removeSelectedNode, safeInsert } from '@atlaskit/editor-prosemirror/utils';
4
+ import { findParentNodeClosestToPos, isNodeSelection, removeSelectedNode, safeInsert } from '@atlaskit/editor-prosemirror/utils';
5
5
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
6
6
  import { findChangeFromLocation, getChangeMediaAnalytics, getMediaInputResizeAnalyticsEvent } from '../utils/analytics';
7
7
  import { currentMediaInlineNodeWithPos, currentMediaNodeWithPos } from '../utils/current-media-node';
@@ -18,10 +18,13 @@ export const getNodeType = state => {
18
18
  return isSelectionMediaSingleNode(state) ? mediaSingle.name : mediaInline.name;
19
19
  };
20
20
  export const changeInlineToMediaCard = (editorAnalyticsAPI, forceFocusSelector) => (state, dispatch) => {
21
+ var _findParentNodeCloses, _parent$content$first, _parent$content$lastC, _parent$content$lastC2, _parent$content$lastC3;
21
22
  const {
22
23
  media,
23
24
  mediaInline,
24
- mediaGroup
25
+ mediaGroup,
26
+ paragraph,
27
+ heading
25
28
  } = state.schema.nodes;
26
29
  const selectedNode = state.selection instanceof NodeSelection && state.selection.node.type === mediaInline && state.selection.node;
27
30
  if (!selectedNode) {
@@ -38,10 +41,26 @@ export const changeInlineToMediaCard = (editorAnalyticsAPI, forceFocusSelector)
38
41
  collection
39
42
  });
40
43
  const group = mediaGroup.createChecked({}, mediaNode);
41
- const nodePos = state.tr.doc.resolve(state.selection.from).end();
44
+ const parent = (_findParentNodeCloses = findParentNodeClosestToPos(state.selection.$from, node => {
45
+ return node.type === paragraph || node.type === heading;
46
+ })) === null || _findParentNodeCloses === void 0 ? void 0 : _findParentNodeCloses.node;
42
47
  let tr = state.tr;
43
- tr = removeSelectedNode(tr);
44
- tr = safeInsert(group, nodePos, true)(tr);
48
+ if (!!parent && parent.content.size === 2 && ((_parent$content$first = parent.content.firstChild) === null || _parent$content$first === void 0 ? void 0 : _parent$content$first.type.name) === 'mediaInline' && ((_parent$content$lastC = parent.content.lastChild) === null || _parent$content$lastC === void 0 ? void 0 : _parent$content$lastC.type.name) === 'text' && ((_parent$content$lastC2 = parent.content.lastChild) === null || _parent$content$lastC2 === void 0 ? void 0 : (_parent$content$lastC3 = _parent$content$lastC2.text) === null || _parent$content$lastC3 === void 0 ? void 0 : _parent$content$lastC3.trim()) === '') {
49
+ /// Empty paragraph or empty heading
50
+ /// Drop the corresponding card on the current line
51
+ const insertPos = state.tr.doc.resolve(state.selection.from).start() - 1;
52
+ if (insertPos < 0) {
53
+ return false;
54
+ }
55
+ tr = tr.delete(insertPos, insertPos + parent.nodeSize);
56
+ tr = safeInsert(group, insertPos, false)(tr);
57
+ } else {
58
+ /// Non-empty paragraph, non-empty heading, or other nodes (e.g., action, list)
59
+ /// Drop the corresponding card underneath the current line
60
+ const insertPos = state.tr.doc.resolve(state.selection.from).end();
61
+ tr = removeSelectedNode(tr);
62
+ tr = safeInsert(group, insertPos, false)(tr);
63
+ }
45
64
  if (dispatch) {
46
65
  editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
47
66
  action: ACTION.CHANGED_TYPE,
@@ -52,6 +71,7 @@ export const changeInlineToMediaCard = (editorAnalyticsAPI, forceFocusSelector)
52
71
  previousType: ACTION_SUBJECT_ID.MEDIA_INLINE
53
72
  }
54
73
  })(tr);
74
+ const nodePos = state.tr.doc.resolve(state.selection.from).end();
55
75
  if (getBooleanFF('platform.editor.ally-media-file-dropdown_1kxo8')) {
56
76
  const $endOfNode = tr.doc.resolve(nodePos + 1);
57
77
  const newSelection = new NodeSelection($endOfNode);
@@ -4,7 +4,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
4
4
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
5
5
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
6
6
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
7
- import { isNodeSelection, removeSelectedNode, safeInsert } from '@atlaskit/editor-prosemirror/utils';
7
+ import { findParentNodeClosestToPos, isNodeSelection, removeSelectedNode, safeInsert } from '@atlaskit/editor-prosemirror/utils';
8
8
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
9
9
  import { findChangeFromLocation, getChangeMediaAnalytics, getMediaInputResizeAnalyticsEvent } from '../utils/analytics';
10
10
  import { currentMediaInlineNodeWithPos, currentMediaNodeWithPos } from '../utils/current-media-node';
@@ -21,10 +21,13 @@ export var getNodeType = function getNodeType(state) {
21
21
  };
22
22
  export var changeInlineToMediaCard = function changeInlineToMediaCard(editorAnalyticsAPI, forceFocusSelector) {
23
23
  return function (state, dispatch) {
24
+ var _findParentNodeCloses, _parent$content$first, _parent$content$lastC, _parent$content$lastC2;
24
25
  var _state$schema$nodes2 = state.schema.nodes,
25
26
  media = _state$schema$nodes2.media,
26
27
  mediaInline = _state$schema$nodes2.mediaInline,
27
- mediaGroup = _state$schema$nodes2.mediaGroup;
28
+ mediaGroup = _state$schema$nodes2.mediaGroup,
29
+ paragraph = _state$schema$nodes2.paragraph,
30
+ heading = _state$schema$nodes2.heading;
28
31
  var selectedNode = state.selection instanceof NodeSelection && state.selection.node.type === mediaInline && state.selection.node;
29
32
  if (!selectedNode) {
30
33
  return false;
@@ -39,10 +42,26 @@ export var changeInlineToMediaCard = function changeInlineToMediaCard(editorAnal
39
42
  collection: collection
40
43
  });
41
44
  var group = mediaGroup.createChecked({}, mediaNode);
42
- var nodePos = state.tr.doc.resolve(state.selection.from).end();
45
+ var parent = (_findParentNodeCloses = findParentNodeClosestToPos(state.selection.$from, function (node) {
46
+ return node.type === paragraph || node.type === heading;
47
+ })) === null || _findParentNodeCloses === void 0 ? void 0 : _findParentNodeCloses.node;
43
48
  var tr = state.tr;
44
- tr = removeSelectedNode(tr);
45
- tr = safeInsert(group, nodePos, true)(tr);
49
+ if (!!parent && parent.content.size === 2 && ((_parent$content$first = parent.content.firstChild) === null || _parent$content$first === void 0 ? void 0 : _parent$content$first.type.name) === 'mediaInline' && ((_parent$content$lastC = parent.content.lastChild) === null || _parent$content$lastC === void 0 ? void 0 : _parent$content$lastC.type.name) === 'text' && ((_parent$content$lastC2 = parent.content.lastChild) === null || _parent$content$lastC2 === void 0 || (_parent$content$lastC2 = _parent$content$lastC2.text) === null || _parent$content$lastC2 === void 0 ? void 0 : _parent$content$lastC2.trim()) === '') {
50
+ /// Empty paragraph or empty heading
51
+ /// Drop the corresponding card on the current line
52
+ var insertPos = state.tr.doc.resolve(state.selection.from).start() - 1;
53
+ if (insertPos < 0) {
54
+ return false;
55
+ }
56
+ tr = tr.delete(insertPos, insertPos + parent.nodeSize);
57
+ tr = safeInsert(group, insertPos, false)(tr);
58
+ } else {
59
+ /// Non-empty paragraph, non-empty heading, or other nodes (e.g., action, list)
60
+ /// Drop the corresponding card underneath the current line
61
+ var _insertPos = state.tr.doc.resolve(state.selection.from).end();
62
+ tr = removeSelectedNode(tr);
63
+ tr = safeInsert(group, _insertPos, false)(tr);
64
+ }
46
65
  if (dispatch) {
47
66
  editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
48
67
  action: ACTION.CHANGED_TYPE,
@@ -53,6 +72,7 @@ export var changeInlineToMediaCard = function changeInlineToMediaCard(editorAnal
53
72
  previousType: ACTION_SUBJECT_ID.MEDIA_INLINE
54
73
  }
55
74
  })(tr);
75
+ var nodePos = state.tr.doc.resolve(state.selection.from).end();
56
76
  if (getBooleanFF('platform.editor.ally-media-file-dropdown_1kxo8')) {
57
77
  var $endOfNode = tr.doc.resolve(nodePos + 1);
58
78
  var newSelection = new NodeSelection($endOfNode);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-media",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "description": "Media plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -37,13 +37,13 @@
37
37
  "@atlaskit/analytics-namespaced-context": "^6.9.0",
38
38
  "@atlaskit/analytics-next": "^9.1.0",
39
39
  "@atlaskit/button": "^17.2.0",
40
- "@atlaskit/editor-common": "^77.0.0",
40
+ "@atlaskit/editor-common": "^77.1.0",
41
41
  "@atlaskit/editor-palette": "1.5.2",
42
42
  "@atlaskit/editor-plugin-analytics": "^0.4.0",
43
43
  "@atlaskit/editor-plugin-decorations": "^0.2.0",
44
44
  "@atlaskit/editor-plugin-editor-disabled": "^0.2.0",
45
45
  "@atlaskit/editor-plugin-feature-flags": "^1.0.0",
46
- "@atlaskit/editor-plugin-floating-toolbar": "^0.8.0",
46
+ "@atlaskit/editor-plugin-floating-toolbar": "^0.9.0",
47
47
  "@atlaskit/editor-plugin-focus": "^0.2.0",
48
48
  "@atlaskit/editor-plugin-grid": "^0.3.0",
49
49
  "@atlaskit/editor-plugin-guideline": "^0.5.0",
@@ -51,7 +51,7 @@
51
51
  "@atlaskit/editor-plugin-width": "^0.2.0",
52
52
  "@atlaskit/editor-prosemirror": "1.1.0",
53
53
  "@atlaskit/editor-shared-styles": "^2.9.0",
54
- "@atlaskit/editor-tables": "^2.4.0",
54
+ "@atlaskit/editor-tables": "^2.5.0",
55
55
  "@atlaskit/form": "^9.0.3",
56
56
  "@atlaskit/icon": "^22.0.0",
57
57
  "@atlaskit/media-card": "^77.7.0",
@@ -65,7 +65,7 @@
65
65
  "@atlaskit/platform-feature-flags": "^0.2.0",
66
66
  "@atlaskit/textfield": "^6.0.0",
67
67
  "@atlaskit/theme": "^12.6.0",
68
- "@atlaskit/tokens": "^1.34.0",
68
+ "@atlaskit/tokens": "^1.35.0",
69
69
  "@atlaskit/tooltip": "^18.1.0",
70
70
  "@babel/runtime": "^7.0.0",
71
71
  "@emotion/react": "^11.7.1",
@@ -75,17 +75,9 @@
75
75
  "uuid": "^3.1.0"
76
76
  },
77
77
  "devDependencies": {
78
- "@af/visual-regression": "*",
79
- "@atlaskit/media-test-helpers": "^33.0.0",
80
- "@atlaskit/util-data-test": "^17.8.0",
81
78
  "@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
82
- "@atlassian/feature-flags-test-utils": "^0.1.1",
83
- "@testing-library/react": "^12.1.5",
84
- "@testing-library/user-event": "^14.4.3",
85
- "enzyme": "^3.10.0",
86
79
  "react-dom": "^16.8.0",
87
- "typescript": "~4.9.5",
88
- "wait-for-expect": "^1.2.0"
80
+ "typescript": "~4.9.5"
89
81
  },
90
82
  "peerDependencies": {
91
83
  "@atlaskit/media-core": "^34.1.2",
@@ -152,5 +144,10 @@
152
144
  "type": "boolean"
153
145
  }
154
146
  },
155
- "prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.0"
147
+ "prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.0",
148
+ "stricter": {
149
+ "no-unused-dependencies": {
150
+ "checkDevDependencies": true
151
+ }
152
+ }
156
153
  }