@atlaskit/editor-plugin-highlight 1.4.0 → 1.4.2

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,23 @@
1
1
  # @atlaskit/editor-plugin-highlight
2
2
 
3
+ ## 1.4.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#101513](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/101513)
8
+ [`98b5dfc33bed`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/98b5dfc33bed) -
9
+ [ux] [ED-23156] The highlight primary toolbar button is disabled when trying to apply it on
10
+ nodes that don't enable the mark and when in a gap cursor. The text color primary toolbar button
11
+ is disabled when selecting text with a highlight.
12
+
13
+ ## 1.4.1
14
+
15
+ ### Patch Changes
16
+
17
+ - [#101524](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/101524)
18
+ [`4821570088e6`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/4821570088e6) -
19
+ ED-23362 Bump ADF schema to version 36.8.1 and add support for adf validation and transformation
20
+
3
21
  ## 1.4.0
4
22
 
5
23
  ### Minor Changes
@@ -9,13 +9,10 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
9
9
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
10
10
  var _uiColor = require("@atlaskit/editor-common/ui-color");
11
11
  var _state = require("@atlaskit/editor-prosemirror/state");
12
+ var _disabled = require("./utils/disabled");
12
13
  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; }
13
14
  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; }
14
15
  var highlightPluginKey = exports.highlightPluginKey = new _state.PluginKey('highlight');
15
- var initialState = {
16
- activeColor: _uiColor.REMOVE_HIGHLIGHT_COLOR,
17
- disabled: false // TODO: Should probably be true, but we can tackle it once we tackle disabled state
18
- };
19
16
  var HighlightPluginAction = exports.HighlightPluginAction = /*#__PURE__*/function (HighlightPluginAction) {
20
17
  HighlightPluginAction[HighlightPluginAction["CHANGE_COLOR"] = 0] = "CHANGE_COLOR";
21
18
  return HighlightPluginAction;
@@ -26,11 +23,15 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
26
23
  key: highlightPluginKey,
27
24
  state: {
28
25
  init: function init() {
29
- return initialState;
26
+ return {
27
+ activeColor: _uiColor.REMOVE_HIGHLIGHT_COLOR,
28
+ disabled: true
29
+ };
30
30
  },
31
- apply: function apply(tr, pluginState) {
31
+ apply: function apply(tr, pluginState, _oldState, newState) {
32
32
  var _tr$getMeta;
33
33
  var action = (_tr$getMeta = tr.getMeta(highlightPluginKey)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.type;
34
+ var nextState;
34
35
  switch (action) {
35
36
  case HighlightPluginAction.CHANGE_COLOR:
36
37
  var _tr$getMeta2 = tr.getMeta(highlightPluginKey),
@@ -39,6 +40,12 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
39
40
  activeColor: color
40
41
  });
41
42
  default:
43
+ nextState = _objectSpread(_objectSpread({}, pluginState), {}, {
44
+ disabled: (0, _disabled.getDisabledState)(newState)
45
+ });
46
+ if (pluginState && pluginState.disabled !== nextState.disabled) {
47
+ return nextState;
48
+ }
42
49
  return pluginState;
43
50
  }
44
51
  }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getDisabledState = void 0;
7
+ var _mark = require("@atlaskit/editor-common/mark");
8
+ var _selection = require("@atlaskit/editor-common/selection");
9
+ var _state = require("@atlaskit/editor-prosemirror/state");
10
+ var getDisabledState = exports.getDisabledState = function getDisabledState(state) {
11
+ var backgroundColor = state.schema.marks.backgroundColor;
12
+ var _ref = state.selection,
13
+ empty = _ref.empty,
14
+ ranges = _ref.ranges,
15
+ $cursor = _ref.$cursor;
16
+ if (!backgroundColor) {
17
+ return true;
18
+ }
19
+ if (state.selection instanceof _state.NodeSelection || state.selection instanceof _selection.GapCursorSelection) {
20
+ return true;
21
+ }
22
+ if (empty && !$cursor || (0, _mark.isMarkAllowedInRange)(state.doc, ranges, backgroundColor) === false) {
23
+ return true;
24
+ }
25
+ if ((0, _mark.isMarkExcluded)(backgroundColor, state.storedMarks || $cursor && $cursor.marks())) {
26
+ return true;
27
+ }
28
+ return false;
29
+ };
@@ -1,11 +1,8 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { REMOVE_HIGHLIGHT_COLOR } from '@atlaskit/editor-common/ui-color';
3
3
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
+ import { getDisabledState } from './utils/disabled';
4
5
  export const highlightPluginKey = new PluginKey('highlight');
5
- const initialState = {
6
- activeColor: REMOVE_HIGHLIGHT_COLOR,
7
- disabled: false // TODO: Should probably be true, but we can tackle it once we tackle disabled state
8
- };
9
6
  export let HighlightPluginAction = /*#__PURE__*/function (HighlightPluginAction) {
10
7
  HighlightPluginAction[HighlightPluginAction["CHANGE_COLOR"] = 0] = "CHANGE_COLOR";
11
8
  return HighlightPluginAction;
@@ -16,10 +13,14 @@ export const createPlugin = ({
16
13
  return new SafePlugin({
17
14
  key: highlightPluginKey,
18
15
  state: {
19
- init: () => initialState,
20
- apply: (tr, pluginState) => {
16
+ init: () => ({
17
+ activeColor: REMOVE_HIGHLIGHT_COLOR,
18
+ disabled: true
19
+ }),
20
+ apply: (tr, pluginState, _oldState, newState) => {
21
21
  var _tr$getMeta;
22
22
  const action = (_tr$getMeta = tr.getMeta(highlightPluginKey)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.type;
23
+ let nextState;
23
24
  switch (action) {
24
25
  case HighlightPluginAction.CHANGE_COLOR:
25
26
  const {
@@ -30,6 +31,13 @@ export const createPlugin = ({
30
31
  activeColor: color
31
32
  };
32
33
  default:
34
+ nextState = {
35
+ ...pluginState,
36
+ disabled: getDisabledState(newState)
37
+ };
38
+ if (pluginState && pluginState.disabled !== nextState.disabled) {
39
+ return nextState;
40
+ }
33
41
  return pluginState;
34
42
  }
35
43
  }
@@ -0,0 +1,26 @@
1
+ import { isMarkAllowedInRange, isMarkExcluded } from '@atlaskit/editor-common/mark';
2
+ import { GapCursorSelection } from '@atlaskit/editor-common/selection';
3
+ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
4
+ export const getDisabledState = state => {
5
+ const {
6
+ backgroundColor
7
+ } = state.schema.marks;
8
+ const {
9
+ empty,
10
+ ranges,
11
+ $cursor
12
+ } = state.selection;
13
+ if (!backgroundColor) {
14
+ return true;
15
+ }
16
+ if (state.selection instanceof NodeSelection || state.selection instanceof GapCursorSelection) {
17
+ return true;
18
+ }
19
+ if (empty && !$cursor || isMarkAllowedInRange(state.doc, ranges, backgroundColor) === false) {
20
+ return true;
21
+ }
22
+ if (isMarkExcluded(backgroundColor, state.storedMarks || $cursor && $cursor.marks())) {
23
+ return true;
24
+ }
25
+ return false;
26
+ };
@@ -4,11 +4,8 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
4
4
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
5
  import { REMOVE_HIGHLIGHT_COLOR } from '@atlaskit/editor-common/ui-color';
6
6
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
7
+ import { getDisabledState } from './utils/disabled';
7
8
  export var highlightPluginKey = new PluginKey('highlight');
8
- var initialState = {
9
- activeColor: REMOVE_HIGHLIGHT_COLOR,
10
- disabled: false // TODO: Should probably be true, but we can tackle it once we tackle disabled state
11
- };
12
9
  export var HighlightPluginAction = /*#__PURE__*/function (HighlightPluginAction) {
13
10
  HighlightPluginAction[HighlightPluginAction["CHANGE_COLOR"] = 0] = "CHANGE_COLOR";
14
11
  return HighlightPluginAction;
@@ -19,11 +16,15 @@ export var createPlugin = function createPlugin(_ref) {
19
16
  key: highlightPluginKey,
20
17
  state: {
21
18
  init: function init() {
22
- return initialState;
19
+ return {
20
+ activeColor: REMOVE_HIGHLIGHT_COLOR,
21
+ disabled: true
22
+ };
23
23
  },
24
- apply: function apply(tr, pluginState) {
24
+ apply: function apply(tr, pluginState, _oldState, newState) {
25
25
  var _tr$getMeta;
26
26
  var action = (_tr$getMeta = tr.getMeta(highlightPluginKey)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.type;
27
+ var nextState;
27
28
  switch (action) {
28
29
  case HighlightPluginAction.CHANGE_COLOR:
29
30
  var _tr$getMeta2 = tr.getMeta(highlightPluginKey),
@@ -32,6 +33,12 @@ export var createPlugin = function createPlugin(_ref) {
32
33
  activeColor: color
33
34
  });
34
35
  default:
36
+ nextState = _objectSpread(_objectSpread({}, pluginState), {}, {
37
+ disabled: getDisabledState(newState)
38
+ });
39
+ if (pluginState && pluginState.disabled !== nextState.disabled) {
40
+ return nextState;
41
+ }
35
42
  return pluginState;
36
43
  }
37
44
  }
@@ -0,0 +1,23 @@
1
+ import { isMarkAllowedInRange, isMarkExcluded } from '@atlaskit/editor-common/mark';
2
+ import { GapCursorSelection } from '@atlaskit/editor-common/selection';
3
+ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
4
+ export var getDisabledState = function getDisabledState(state) {
5
+ var backgroundColor = state.schema.marks.backgroundColor;
6
+ var _ref = state.selection,
7
+ empty = _ref.empty,
8
+ ranges = _ref.ranges,
9
+ $cursor = _ref.$cursor;
10
+ if (!backgroundColor) {
11
+ return true;
12
+ }
13
+ if (state.selection instanceof NodeSelection || state.selection instanceof GapCursorSelection) {
14
+ return true;
15
+ }
16
+ if (empty && !$cursor || isMarkAllowedInRange(state.doc, ranges, backgroundColor) === false) {
17
+ return true;
18
+ }
19
+ if (isMarkExcluded(backgroundColor, state.storedMarks || $cursor && $cursor.marks())) {
20
+ return true;
21
+ }
22
+ return false;
23
+ };
@@ -0,0 +1,2 @@
1
+ import { type EditorState } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const getDisabledState: (state: EditorState) => boolean;
@@ -0,0 +1,2 @@
1
+ import { type EditorState } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const getDisabledState: (state: EditorState) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-highlight",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Highlight plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -38,15 +38,15 @@
38
38
  ".": "./src/index.ts"
39
39
  },
40
40
  "dependencies": {
41
- "@atlaskit/adf-schema": "^36.3.0",
42
- "@atlaskit/editor-common": "^80.4.0",
41
+ "@atlaskit/adf-schema": "^36.8.0",
42
+ "@atlaskit/editor-common": "^80.5.0",
43
43
  "@atlaskit/editor-palette": "1.6.0",
44
44
  "@atlaskit/editor-plugin-analytics": "^1.2.0",
45
45
  "@atlaskit/editor-plugin-text-formatting": "^1.6.0",
46
46
  "@atlaskit/editor-prosemirror": "4.0.1",
47
47
  "@atlaskit/editor-shared-styles": "^2.11.0",
48
- "@atlaskit/icon": "^22.2.0",
49
- "@atlaskit/primitives": "^6.2.0",
48
+ "@atlaskit/icon": "^22.3.0",
49
+ "@atlaskit/primitives": "^6.3.0",
50
50
  "@babel/runtime": "^7.0.0",
51
51
  "@emotion/react": "^11.7.1"
52
52
  },
@@ -55,7 +55,7 @@
55
55
  "react-intl-next": "npm:react-intl@^5.18.1"
56
56
  },
57
57
  "devDependencies": {
58
- "@atlaskit/tokens": "^1.48.0",
58
+ "@atlaskit/tokens": "^1.49.0",
59
59
  "@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
60
60
  "typescript": "~5.4.2"
61
61
  },