@atlaskit/editor-plugin-text-formatting 1.2.3 → 1.2.4

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,11 @@
1
1
  # @atlaskit/editor-plugin-text-formatting
2
2
 
3
+ ## 1.2.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#78492](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/78492) [`3b0b93acfd19`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/3b0b93acfd19) - [ux] [CAMPTASKS-123] faulty formatting state for inline nodes
8
+
3
9
  ## 1.2.3
4
10
 
5
11
  ### Patch Changes
@@ -16,6 +16,7 @@ var _mark = require("@atlaskit/editor-common/mark");
16
16
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
17
17
  var _utils = require("@atlaskit/editor-common/utils");
18
18
  var _commands = require("@atlaskit/editor-prosemirror/commands");
19
+ var _state = require("@atlaskit/editor-prosemirror/state");
19
20
  var _textFormatting = _interopRequireWildcard(require("../commands/text-formatting"));
20
21
  var commands = _textFormatting;
21
22
  var _pluginKey = require("./plugin-key");
@@ -24,6 +25,24 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
24
25
  // TODO: Ideally this should use the custom toggleMark function from @atlaskit/editor-common so we also disable the options when selecting inline nodes but it disables the marks when the selection is empty at this point in time which is undesirable
25
26
  // import { toggleMark } from '@atlaskit/editor-common/mark';
26
27
 
28
+ var isSelectionInlineCursor = function isSelectionInlineCursor(selection) {
29
+ if (selection instanceof _state.NodeSelection) {
30
+ return true;
31
+ }
32
+ return false;
33
+ };
34
+ var checkNodeSelection = function checkNodeSelection(mark, editorState, type) {
35
+ var selection = editorState.selection;
36
+ if (isSelectionInlineCursor(selection)) {
37
+ return false;
38
+ }
39
+ if (type !== null || type !== undefined) {
40
+ return (0, _commands.toggleMark)(mark, {
41
+ type: type
42
+ })(editorState);
43
+ }
44
+ return (0, _commands.toggleMark)(mark)(editorState);
45
+ };
27
46
  var getTextFormattingState = function getTextFormattingState(editorState, editorAnalyticsAPI) {
28
47
  var _editorState$schema$m = editorState.schema.marks,
29
48
  em = _editorState$schema$m.em,
@@ -35,19 +54,19 @@ var getTextFormattingState = function getTextFormattingState(editorState, editor
35
54
  var state = {};
36
55
  if (code) {
37
56
  state.codeActive = (0, _mark.anyMarkActive)(editorState, code.create());
38
- state.codeDisabled = !(0, _commands.toggleMark)(code)(editorState);
57
+ state.codeDisabled = !checkNodeSelection(code, editorState);
39
58
  }
40
59
  if (em) {
41
60
  state.emActive = (0, _mark.anyMarkActive)(editorState, em);
42
- state.emDisabled = state.codeActive ? true : !(0, _commands.toggleMark)(em)(editorState);
61
+ state.emDisabled = state.codeActive ? true : !checkNodeSelection(em, editorState);
43
62
  }
44
63
  if (strike) {
45
64
  state.strikeActive = (0, _mark.anyMarkActive)(editorState, strike);
46
- state.strikeDisabled = state.codeActive ? true : !(0, _commands.toggleMark)(strike)(editorState);
65
+ state.strikeDisabled = state.codeActive ? true : !checkNodeSelection(strike, editorState);
47
66
  }
48
67
  if (strong) {
49
68
  state.strongActive = (0, _mark.anyMarkActive)(editorState, strong);
50
- state.strongDisabled = state.codeActive ? true : !(0, _commands.toggleMark)(strong)(editorState);
69
+ state.strongDisabled = state.codeActive ? true : !checkNodeSelection(strong, editorState);
51
70
  }
52
71
  if (subsup) {
53
72
  var subMark = subsup.create({
@@ -57,17 +76,13 @@ var getTextFormattingState = function getTextFormattingState(editorState, editor
57
76
  type: 'sup'
58
77
  });
59
78
  state.subscriptActive = (0, _mark.anyMarkActive)(editorState, subMark);
60
- state.subscriptDisabled = state.codeActive ? true : !(0, _commands.toggleMark)(subsup, {
61
- type: 'sub'
62
- })(editorState);
79
+ state.subscriptDisabled = state.codeActive ? true : !checkNodeSelection(subsup, editorState, 'sub');
63
80
  state.superscriptActive = (0, _mark.anyMarkActive)(editorState, supMark);
64
- state.superscriptDisabled = state.codeActive ? true : !(0, _commands.toggleMark)(subsup, {
65
- type: 'sup'
66
- })(editorState);
81
+ state.superscriptDisabled = state.codeActive ? true : !checkNodeSelection(subsup, editorState, 'sup');
67
82
  }
68
83
  if (underline) {
69
84
  state.underlineActive = (0, _mark.anyMarkActive)(editorState, underline);
70
- state.underlineDisabled = state.codeActive ? true : !(0, _commands.toggleMark)(underline)(editorState);
85
+ state.underlineDisabled = state.codeActive ? true : !checkNodeSelection(underline, editorState);
71
86
  }
72
87
  return state;
73
88
  };
@@ -6,10 +6,29 @@ import { anyMarkActive } from '@atlaskit/editor-common/mark';
6
6
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
7
7
  import { shallowEqual } from '@atlaskit/editor-common/utils';
8
8
  import { toggleMark } from '@atlaskit/editor-prosemirror/commands';
9
+ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
9
10
  import { createInlineCodeFromTextInputWithAnalytics } from '../commands/text-formatting';
10
11
  import * as commands from '../commands/text-formatting';
11
12
  import { pluginKey } from './plugin-key';
12
13
  export { pluginKey };
14
+ const isSelectionInlineCursor = selection => {
15
+ if (selection instanceof NodeSelection) {
16
+ return true;
17
+ }
18
+ return false;
19
+ };
20
+ const checkNodeSelection = (mark, editorState, type) => {
21
+ const selection = editorState.selection;
22
+ if (isSelectionInlineCursor(selection)) {
23
+ return false;
24
+ }
25
+ if (type !== null || type !== undefined) {
26
+ return toggleMark(mark, {
27
+ type: type
28
+ })(editorState);
29
+ }
30
+ return toggleMark(mark)(editorState);
31
+ };
13
32
  const getTextFormattingState = (editorState, editorAnalyticsAPI) => {
14
33
  const {
15
34
  em,
@@ -22,19 +41,19 @@ const getTextFormattingState = (editorState, editorAnalyticsAPI) => {
22
41
  const state = {};
23
42
  if (code) {
24
43
  state.codeActive = anyMarkActive(editorState, code.create());
25
- state.codeDisabled = !toggleMark(code)(editorState);
44
+ state.codeDisabled = !checkNodeSelection(code, editorState);
26
45
  }
27
46
  if (em) {
28
47
  state.emActive = anyMarkActive(editorState, em);
29
- state.emDisabled = state.codeActive ? true : !toggleMark(em)(editorState);
48
+ state.emDisabled = state.codeActive ? true : !checkNodeSelection(em, editorState);
30
49
  }
31
50
  if (strike) {
32
51
  state.strikeActive = anyMarkActive(editorState, strike);
33
- state.strikeDisabled = state.codeActive ? true : !toggleMark(strike)(editorState);
52
+ state.strikeDisabled = state.codeActive ? true : !checkNodeSelection(strike, editorState);
34
53
  }
35
54
  if (strong) {
36
55
  state.strongActive = anyMarkActive(editorState, strong);
37
- state.strongDisabled = state.codeActive ? true : !toggleMark(strong)(editorState);
56
+ state.strongDisabled = state.codeActive ? true : !checkNodeSelection(strong, editorState);
38
57
  }
39
58
  if (subsup) {
40
59
  const subMark = subsup.create({
@@ -44,17 +63,13 @@ const getTextFormattingState = (editorState, editorAnalyticsAPI) => {
44
63
  type: 'sup'
45
64
  });
46
65
  state.subscriptActive = anyMarkActive(editorState, subMark);
47
- state.subscriptDisabled = state.codeActive ? true : !toggleMark(subsup, {
48
- type: 'sub'
49
- })(editorState);
66
+ state.subscriptDisabled = state.codeActive ? true : !checkNodeSelection(subsup, editorState, 'sub');
50
67
  state.superscriptActive = anyMarkActive(editorState, supMark);
51
- state.superscriptDisabled = state.codeActive ? true : !toggleMark(subsup, {
52
- type: 'sup'
53
- })(editorState);
68
+ state.superscriptDisabled = state.codeActive ? true : !checkNodeSelection(subsup, editorState, 'sup');
54
69
  }
55
70
  if (underline) {
56
71
  state.underlineActive = anyMarkActive(editorState, underline);
57
- state.underlineDisabled = state.codeActive ? true : !toggleMark(underline)(editorState);
72
+ state.underlineDisabled = state.codeActive ? true : !checkNodeSelection(underline, editorState);
58
73
  }
59
74
  return state;
60
75
  };
@@ -6,10 +6,29 @@ import { anyMarkActive } from '@atlaskit/editor-common/mark';
6
6
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
7
7
  import { shallowEqual } from '@atlaskit/editor-common/utils';
8
8
  import { toggleMark } from '@atlaskit/editor-prosemirror/commands';
9
+ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
9
10
  import { createInlineCodeFromTextInputWithAnalytics } from '../commands/text-formatting';
10
11
  import * as commands from '../commands/text-formatting';
11
12
  import { pluginKey } from './plugin-key';
12
13
  export { pluginKey };
14
+ var isSelectionInlineCursor = function isSelectionInlineCursor(selection) {
15
+ if (selection instanceof NodeSelection) {
16
+ return true;
17
+ }
18
+ return false;
19
+ };
20
+ var checkNodeSelection = function checkNodeSelection(mark, editorState, type) {
21
+ var selection = editorState.selection;
22
+ if (isSelectionInlineCursor(selection)) {
23
+ return false;
24
+ }
25
+ if (type !== null || type !== undefined) {
26
+ return toggleMark(mark, {
27
+ type: type
28
+ })(editorState);
29
+ }
30
+ return toggleMark(mark)(editorState);
31
+ };
13
32
  var getTextFormattingState = function getTextFormattingState(editorState, editorAnalyticsAPI) {
14
33
  var _editorState$schema$m = editorState.schema.marks,
15
34
  em = _editorState$schema$m.em,
@@ -21,19 +40,19 @@ var getTextFormattingState = function getTextFormattingState(editorState, editor
21
40
  var state = {};
22
41
  if (code) {
23
42
  state.codeActive = anyMarkActive(editorState, code.create());
24
- state.codeDisabled = !toggleMark(code)(editorState);
43
+ state.codeDisabled = !checkNodeSelection(code, editorState);
25
44
  }
26
45
  if (em) {
27
46
  state.emActive = anyMarkActive(editorState, em);
28
- state.emDisabled = state.codeActive ? true : !toggleMark(em)(editorState);
47
+ state.emDisabled = state.codeActive ? true : !checkNodeSelection(em, editorState);
29
48
  }
30
49
  if (strike) {
31
50
  state.strikeActive = anyMarkActive(editorState, strike);
32
- state.strikeDisabled = state.codeActive ? true : !toggleMark(strike)(editorState);
51
+ state.strikeDisabled = state.codeActive ? true : !checkNodeSelection(strike, editorState);
33
52
  }
34
53
  if (strong) {
35
54
  state.strongActive = anyMarkActive(editorState, strong);
36
- state.strongDisabled = state.codeActive ? true : !toggleMark(strong)(editorState);
55
+ state.strongDisabled = state.codeActive ? true : !checkNodeSelection(strong, editorState);
37
56
  }
38
57
  if (subsup) {
39
58
  var subMark = subsup.create({
@@ -43,17 +62,13 @@ var getTextFormattingState = function getTextFormattingState(editorState, editor
43
62
  type: 'sup'
44
63
  });
45
64
  state.subscriptActive = anyMarkActive(editorState, subMark);
46
- state.subscriptDisabled = state.codeActive ? true : !toggleMark(subsup, {
47
- type: 'sub'
48
- })(editorState);
65
+ state.subscriptDisabled = state.codeActive ? true : !checkNodeSelection(subsup, editorState, 'sub');
49
66
  state.superscriptActive = anyMarkActive(editorState, supMark);
50
- state.superscriptDisabled = state.codeActive ? true : !toggleMark(subsup, {
51
- type: 'sup'
52
- })(editorState);
67
+ state.superscriptDisabled = state.codeActive ? true : !checkNodeSelection(subsup, editorState, 'sup');
53
68
  }
54
69
  if (underline) {
55
70
  state.underlineActive = anyMarkActive(editorState, underline);
56
- state.underlineDisabled = state.codeActive ? true : !toggleMark(underline)(editorState);
71
+ state.underlineDisabled = state.codeActive ? true : !checkNodeSelection(underline, editorState);
57
72
  }
58
73
  return state;
59
74
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-text-formatting",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "description": "Text-formatting plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@atlaskit/adf-schema": "^35.6.0",
36
- "@atlaskit/editor-common": "^78.12.0",
36
+ "@atlaskit/editor-common": "^78.14.0",
37
37
  "@atlaskit/editor-plugin-analytics": "^1.0.0",
38
38
  "@atlaskit/editor-prosemirror": "3.0.0",
39
39
  "@atlaskit/editor-shared-styles": "^2.9.0",
@@ -78,11 +78,9 @@
78
78
  "ui-components": [
79
79
  "lite-mode"
80
80
  ],
81
- "deprecation": [
82
- "no-deprecated-imports"
83
- ],
81
+ "deprecation": "no-deprecated-imports",
84
82
  "styling": [
85
- "static",
83
+ "emotion",
86
84
  "emotion"
87
85
  ],
88
86
  "imports": [
@@ -91,4 +89,4 @@
91
89
  }
92
90
  },
93
91
  "prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.0"
94
- }
92
+ }