@atlaskit/editor-plugin-text-color 1.4.1 → 1.6.0

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,26 @@
1
1
  # @atlaskit/editor-plugin-text-color
2
2
 
3
+ ## 1.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#110884](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/110884)
8
+ [`674f78166705c`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/674f78166705c) -
9
+ [ux] [ED-23516] Change border color for highlight and text-color palettes to use tokens.
10
+ Changedefault palette color when undefined
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies
15
+
16
+ ## 1.5.0
17
+
18
+ ### Minor Changes
19
+
20
+ - [#108745](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/108745)
21
+ [`ef4a6d8a3ef73`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/ef4a6d8a3ef73) -
22
+ [ux] [ED-23513] Allow text color mark to replace backgroundColor
23
+
3
24
  ## 1.4.1
4
25
 
5
26
  ### Patch Changes
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.toggleColor = void 0;
7
7
  var _mark = require("@atlaskit/editor-common/mark");
8
- var _preset = require("@atlaskit/editor-common/preset");
9
8
  var _main = require("../pm-plugins/main");
9
+ var _constants = require("../utils/constants");
10
10
  var _disabled = require("../utils/disabled");
11
11
  var toggleColor = exports.toggleColor = function toggleColor(color) {
12
12
  return function (state, dispatch) {
@@ -22,14 +22,20 @@ var toggleColor = exports.toggleColor = function toggleColor(color) {
22
22
  return false;
23
23
  }
24
24
  if (dispatch) {
25
- state.tr.setMeta(_main.pluginKey, {
26
- action: _main.ACTIONS.SET_COLOR,
27
- color: color
25
+ _constants.overrideMarks.forEach(function (mark) {
26
+ var marks = tr.doc.type.schema.marks;
27
+ if (marks[mark]) {
28
+ (0, _mark.removeMark)(marks[mark])({
29
+ tr: tr
30
+ });
31
+ }
28
32
  });
29
- state.tr.scrollIntoView();
30
- (0, _preset.editorCommandToPMCommand)((0, _mark.toggleMark)(textColor, {
33
+ (0, _mark.toggleMark)(textColor, {
31
34
  color: color
32
- }))(state, dispatch);
35
+ })({
36
+ tr: tr
37
+ });
38
+ dispatch(tr);
33
39
  }
34
40
  return true;
35
41
  };
@@ -8,7 +8,7 @@ exports.ACTIONS = void 0;
8
8
  Object.defineProperty(exports, "DEFAULT_COLOR", {
9
9
  enumerable: true,
10
10
  get: function get() {
11
- return _color.DEFAULT_COLOR;
11
+ return _constants.DEFAULT_COLOR;
12
12
  }
13
13
  });
14
14
  exports.createPlugin = createPlugin;
@@ -18,17 +18,19 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
18
18
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
19
19
  var _uiColor = require("@atlaskit/editor-common/ui-color");
20
20
  var _state = require("@atlaskit/editor-prosemirror/state");
21
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
21
22
  var _color = require("../utils/color");
23
+ var _constants = require("../utils/constants");
22
24
  var _disabled = require("../utils/disabled");
23
25
  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
26
  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
27
  function createInitialPluginState(editorState, pluginConfig) {
26
- var defaultColor = (pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.defaultColor) || _color.DEFAULT_COLOR;
28
+ var defaultColor = (pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.defaultColor) || _constants.DEFAULT_COLOR;
27
29
  var palette = [{
28
30
  value: defaultColor.color,
29
31
  label: defaultColor.label,
30
- border: _uiColor.DEFAULT_BORDER_COLOR
31
- }].concat((0, _toConsumableArray2.default)(_uiColor.textColorPalette));
32
+ border: (0, _platformFeatureFlags.getBooleanFF)('platform.editor.dynamic-palette-borders') ? "var(--ds-border, #091E4224)" : _uiColor.DEFAULT_BORDER_COLOR
33
+ }].concat((0, _toConsumableArray2.default)((0, _platformFeatureFlags.getBooleanFF)('platform.editor.dynamic-palette-borders') ? _uiColor.textColorPaletteWithTokenBorders : _uiColor.textColorPalette));
32
34
  var state = {
33
35
  color: (0, _color.getActiveColor)(editorState),
34
36
  disabled: (0, _disabled.getDisabledState)(editorState),
@@ -167,7 +167,7 @@ var ToolbarTextColor = exports.ToolbarTextColor = /*#__PURE__*/function (_React$
167
167
  selectedRowIndex = _getSelectedRowAndCol.selectedRowIndex,
168
168
  selectedColumnIndex = _getSelectedRowAndCol.selectedColumnIndex;
169
169
  return (
170
- // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
170
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
171
171
  (0, _react2.jsx)("span", {
172
172
  css: _styles.wrapperStyle
173
173
  }, (0, _react2.jsx)(_uiMenu.DropdownContainer, {
@@ -200,7 +200,7 @@ var ToolbarTextColor = exports.ToolbarTextColor = /*#__PURE__*/function (_React$
200
200
  onKeyDown: this.onKeyDown,
201
201
  ref: this.toolbarItemRef,
202
202
  iconBefore:
203
- // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
203
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
204
204
  (0, _react2.jsx)("div", {
205
205
  css: _styles.triggerWrapperStyles
206
206
  }, (0, _react2.jsx)(_icons.SteppedRainbowIconDecoration, {
@@ -227,6 +227,7 @@ var ToolbarTextColor = exports.ToolbarTextColor = /*#__PURE__*/function (_React$
227
227
  paletteColorTooltipMessages: _uiColor.textPaletteTooltipMessages
228
228
  }
229
229
  }))), !(pluginInjectionApi !== null && pluginInjectionApi !== void 0 && pluginInjectionApi.primaryToolbar) && /* eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage */
230
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
230
231
  (0, _react2.jsx)("span", {
231
232
  css: _styles.separatorStyles
232
233
  }))
@@ -3,14 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getActiveColor = exports.DEFAULT_COLOR = void 0;
7
- var _colors = require("@atlaskit/theme/colors");
8
- var DEFAULT_COLOR = exports.DEFAULT_COLOR = {
9
- // TODO: https://product-fabric.atlassian.net/browse/DSP-4137
10
- /* eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage */
11
- color: _colors.N800.toLowerCase(),
12
- label: 'Dark gray'
13
- };
6
+ exports.getActiveColor = void 0;
7
+ var _constants = require("./constants");
14
8
  var getActiveColor = exports.getActiveColor = function getActiveColor(state) {
15
9
  var _ref = state.selection,
16
10
  $from = _ref.$from,
@@ -50,5 +44,5 @@ var getActiveColor = exports.getActiveColor = function getActiveColor(state) {
50
44
  if (marksWithColor.length > 1 || marksWithColor.length === 1 && marks.length > 1) {
51
45
  return null;
52
46
  }
53
- return marksWithColor.length ? marksWithColor[0].attrs.color : DEFAULT_COLOR.color;
47
+ return marksWithColor.length ? marksWithColor[0].attrs.color : _constants.DEFAULT_COLOR.color;
54
48
  };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.overrideMarks = exports.DEFAULT_COLOR = void 0;
7
+ var _colors = require("@atlaskit/theme/colors");
8
+ var overrideMarks = exports.overrideMarks = ['backgroundColor'];
9
+ var DEFAULT_COLOR = exports.DEFAULT_COLOR = {
10
+ // TODO: https://product-fabric.atlassian.net/browse/DSP-4137
11
+ /* eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage */
12
+ color: _colors.N800.toLowerCase(),
13
+ label: 'Dark gray'
14
+ };
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getDisabledState = void 0;
7
7
  var _mark = require("@atlaskit/editor-common/mark");
8
+ var _constants = require("./constants");
8
9
  var hasLinkMark = function hasLinkMark($pos) {
9
10
  var linkMarkType = $pos.doc.type.schema.marks.link,
10
11
  pos = $pos.pos;
@@ -13,39 +14,24 @@ var hasLinkMark = function hasLinkMark($pos) {
13
14
  }
14
15
  return $pos.doc.rangeHasMark(pos, Math.min(pos + 1, $pos.doc.content.size), linkMarkType);
15
16
  };
16
- var hasHighlightMark = function hasHighlightMark($pos) {
17
- var highlightMarkType = $pos.doc.type.schema.marks.backgroundColor;
18
- if (!highlightMarkType) {
19
- return false;
20
- }
21
- var node = $pos.nodeBefore;
22
- if (!node) {
23
- return false;
24
- }
25
- return !!highlightMarkType.isInSet(node.marks);
26
- };
27
- var hasHighlightMarkInRange = function hasHighlightMarkInRange($from, $to) {
28
- var highlightMarkType = $from.doc.type.schema.marks.backgroundColor,
29
- pos = $from.pos,
30
- doc = $from.doc;
31
- if (!highlightMarkType) {
32
- return false;
33
- }
34
- return (0, _mark.entireSelectionContainsMark)(highlightMarkType, doc, pos, $to.pos);
35
- };
36
17
  var getDisabledState = exports.getDisabledState = function getDisabledState(state) {
37
18
  var textColor = state.schema.marks.textColor;
38
19
  if (textColor) {
20
+ var _state$storedMarks;
39
21
  var _ref = state.selection,
40
22
  empty = _ref.empty,
41
23
  ranges = _ref.ranges,
42
- $cursor = _ref.$cursor,
43
- $from = _ref.$from,
44
- $to = _ref.$to;
45
- if (empty && !$cursor || $cursor && hasLinkMark($cursor) || $cursor && hasHighlightMark($cursor) || !$cursor && $from && $to && hasHighlightMarkInRange($from, $to) || (0, _mark.isMarkAllowedInRange)(state.doc, ranges, textColor) === false) {
24
+ $cursor = _ref.$cursor;
25
+ if (empty && !$cursor || $cursor && hasLinkMark($cursor) || (0, _mark.isMarkAllowedInRange)(state.doc, ranges, textColor) === false) {
46
26
  return true;
47
27
  }
48
- if ((0, _mark.isMarkExcluded)(textColor, state.storedMarks || $cursor && $cursor.marks())) {
28
+
29
+ // Allow "excluded" marks that can be overridden
30
+ // These marks are explicitly removed before applying the new mark (see toggleColor command)
31
+ var omitOverrides = function omitOverrides(mark) {
32
+ return !_constants.overrideMarks.includes(mark.type.name);
33
+ };
34
+ if ((0, _mark.isMarkExcluded)(textColor, ((_state$storedMarks = state.storedMarks) === null || _state$storedMarks === void 0 ? void 0 : _state$storedMarks.filter(omitOverrides)) || $cursor && $cursor.marks().filter(omitOverrides))) {
49
35
  return true;
50
36
  }
51
37
  return false;
@@ -1,6 +1,6 @@
1
- import { toggleMark } from '@atlaskit/editor-common/mark';
2
- import { editorCommandToPMCommand } from '@atlaskit/editor-common/preset';
1
+ import { removeMark, toggleMark } from '@atlaskit/editor-common/mark';
3
2
  import { ACTIONS, pluginKey } from '../pm-plugins/main';
3
+ import { overrideMarks } from '../utils/constants';
4
4
  import { getDisabledState } from '../utils/disabled';
5
5
  export const toggleColor = color => (state, dispatch) => {
6
6
  const {
@@ -17,14 +17,22 @@ export const toggleColor = color => (state, dispatch) => {
17
17
  return false;
18
18
  }
19
19
  if (dispatch) {
20
- state.tr.setMeta(pluginKey, {
21
- action: ACTIONS.SET_COLOR,
22
- color
20
+ overrideMarks.forEach(mark => {
21
+ const {
22
+ marks
23
+ } = tr.doc.type.schema;
24
+ if (marks[mark]) {
25
+ removeMark(marks[mark])({
26
+ tr
27
+ });
28
+ }
23
29
  });
24
- state.tr.scrollIntoView();
25
- editorCommandToPMCommand(toggleMark(textColor, {
30
+ toggleMark(textColor, {
26
31
  color
27
- }))(state, dispatch);
32
+ })({
33
+ tr
34
+ });
35
+ dispatch(tr);
28
36
  }
29
37
  return true;
30
38
  };
@@ -1,16 +1,18 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { DEFAULT_BORDER_COLOR, textColorPalette } from '@atlaskit/editor-common/ui-color';
2
+ import { DEFAULT_BORDER_COLOR, textColorPalette, textColorPaletteWithTokenBorders } from '@atlaskit/editor-common/ui-color';
3
3
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
- import { DEFAULT_COLOR, getActiveColor } from '../utils/color';
4
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
5
+ import { getActiveColor } from '../utils/color';
6
+ import { DEFAULT_COLOR } from '../utils/constants';
5
7
  import { getDisabledState } from '../utils/disabled';
6
- export { DEFAULT_COLOR } from '../utils/color';
8
+ export { DEFAULT_COLOR } from '../utils/constants';
7
9
  function createInitialPluginState(editorState, pluginConfig) {
8
10
  const defaultColor = (pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.defaultColor) || DEFAULT_COLOR;
9
11
  const palette = [{
10
12
  value: defaultColor.color,
11
13
  label: defaultColor.label,
12
- border: DEFAULT_BORDER_COLOR
13
- }, ...textColorPalette];
14
+ border: getBooleanFF('platform.editor.dynamic-palette-borders') ? "var(--ds-border, #091E4224)" : DEFAULT_BORDER_COLOR
15
+ }, ...(getBooleanFF('platform.editor.dynamic-palette-borders') ? textColorPaletteWithTokenBorders : textColorPalette)];
14
16
  const state = {
15
17
  color: getActiveColor(editorState),
16
18
  disabled: getDisabledState(editorState),
@@ -146,7 +146,7 @@ export class ToolbarTextColor extends React.Component {
146
146
  selectedColumnIndex
147
147
  } = getSelectedRowAndColumnFromPalette(palette, pluginState.color);
148
148
  return (
149
- // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
149
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
150
150
  jsx("span", {
151
151
  css: wrapperStyle
152
152
  }, jsx(Dropdown, {
@@ -179,7 +179,7 @@ export class ToolbarTextColor extends React.Component {
179
179
  onKeyDown: this.onKeyDown,
180
180
  ref: this.toolbarItemRef,
181
181
  iconBefore:
182
- // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
182
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
183
183
  jsx("div", {
184
184
  css: triggerWrapperStyles
185
185
  }, jsx(SteppedRainbowIconDecoration, {
@@ -206,6 +206,7 @@ export class ToolbarTextColor extends React.Component {
206
206
  paletteColorTooltipMessages: textPaletteTooltipMessages
207
207
  }
208
208
  }))), !(pluginInjectionApi !== null && pluginInjectionApi !== void 0 && pluginInjectionApi.primaryToolbar) && /* eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage */
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
209
210
  jsx("span", {
210
211
  css: separatorStyles
211
212
  }))
@@ -1,10 +1,4 @@
1
- import { N800 } from '@atlaskit/theme/colors';
2
- export const DEFAULT_COLOR = {
3
- // TODO: https://product-fabric.atlassian.net/browse/DSP-4137
4
- /* eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage */
5
- color: N800.toLowerCase(),
6
- label: 'Dark gray'
7
- };
1
+ import { DEFAULT_COLOR } from './constants';
8
2
  export const getActiveColor = state => {
9
3
  const {
10
4
  $from,
@@ -0,0 +1,8 @@
1
+ import { N800 } from '@atlaskit/theme/colors';
2
+ export const overrideMarks = ['backgroundColor'];
3
+ export const DEFAULT_COLOR = {
4
+ // TODO: https://product-fabric.atlassian.net/browse/DSP-4137
5
+ /* eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage */
6
+ color: N800.toLowerCase(),
7
+ label: 'Dark gray'
8
+ };
@@ -1,4 +1,5 @@
1
- import { entireSelectionContainsMark, isMarkAllowedInRange, isMarkExcluded } from '@atlaskit/editor-common/mark';
1
+ import { isMarkAllowedInRange, isMarkExcluded } from '@atlaskit/editor-common/mark';
2
+ import { overrideMarks } from './constants';
2
3
  const hasLinkMark = $pos => {
3
4
  const {
4
5
  doc: {
@@ -17,62 +18,27 @@ const hasLinkMark = $pos => {
17
18
  }
18
19
  return $pos.doc.rangeHasMark(pos, Math.min(pos + 1, $pos.doc.content.size), linkMarkType);
19
20
  };
20
- const hasHighlightMark = $pos => {
21
- const {
22
- doc: {
23
- type: {
24
- schema: {
25
- marks: {
26
- backgroundColor: highlightMarkType
27
- }
28
- }
29
- }
30
- }
31
- } = $pos;
32
- if (!highlightMarkType) {
33
- return false;
34
- }
35
- const node = $pos.nodeBefore;
36
- if (!node) {
37
- return false;
38
- }
39
- return !!highlightMarkType.isInSet(node.marks);
40
- };
41
- const hasHighlightMarkInRange = ($from, $to) => {
42
- const {
43
- doc: {
44
- type: {
45
- schema: {
46
- marks: {
47
- backgroundColor: highlightMarkType
48
- }
49
- }
50
- }
51
- },
52
- pos,
53
- doc
54
- } = $from;
55
- if (!highlightMarkType) {
56
- return false;
57
- }
58
- return entireSelectionContainsMark(highlightMarkType, doc, pos, $to.pos);
59
- };
60
21
  export const getDisabledState = state => {
61
22
  const {
62
23
  textColor
63
24
  } = state.schema.marks;
64
25
  if (textColor) {
26
+ var _state$storedMarks;
65
27
  const {
66
28
  empty,
67
29
  ranges,
68
- $cursor,
69
- $from,
70
- $to
30
+ $cursor
71
31
  } = state.selection;
72
- if (empty && !$cursor || $cursor && hasLinkMark($cursor) || $cursor && hasHighlightMark($cursor) || !$cursor && $from && $to && hasHighlightMarkInRange($from, $to) || isMarkAllowedInRange(state.doc, ranges, textColor) === false) {
32
+ if (empty && !$cursor || $cursor && hasLinkMark($cursor) || isMarkAllowedInRange(state.doc, ranges, textColor) === false) {
73
33
  return true;
74
34
  }
75
- if (isMarkExcluded(textColor, state.storedMarks || $cursor && $cursor.marks())) {
35
+
36
+ // Allow "excluded" marks that can be overridden
37
+ // These marks are explicitly removed before applying the new mark (see toggleColor command)
38
+ const omitOverrides = mark => {
39
+ return !overrideMarks.includes(mark.type.name);
40
+ };
41
+ if (isMarkExcluded(textColor, ((_state$storedMarks = state.storedMarks) === null || _state$storedMarks === void 0 ? void 0 : _state$storedMarks.filter(omitOverrides)) || $cursor && $cursor.marks().filter(omitOverrides))) {
76
42
  return true;
77
43
  }
78
44
  return false;
@@ -1,6 +1,6 @@
1
- import { toggleMark } from '@atlaskit/editor-common/mark';
2
- import { editorCommandToPMCommand } from '@atlaskit/editor-common/preset';
1
+ import { removeMark, toggleMark } from '@atlaskit/editor-common/mark';
3
2
  import { ACTIONS, pluginKey } from '../pm-plugins/main';
3
+ import { overrideMarks } from '../utils/constants';
4
4
  import { getDisabledState } from '../utils/disabled';
5
5
  export var toggleColor = function toggleColor(color) {
6
6
  return function (state, dispatch) {
@@ -16,14 +16,20 @@ export var toggleColor = function toggleColor(color) {
16
16
  return false;
17
17
  }
18
18
  if (dispatch) {
19
- state.tr.setMeta(pluginKey, {
20
- action: ACTIONS.SET_COLOR,
21
- color: color
19
+ overrideMarks.forEach(function (mark) {
20
+ var marks = tr.doc.type.schema.marks;
21
+ if (marks[mark]) {
22
+ removeMark(marks[mark])({
23
+ tr: tr
24
+ });
25
+ }
22
26
  });
23
- state.tr.scrollIntoView();
24
- editorCommandToPMCommand(toggleMark(textColor, {
27
+ toggleMark(textColor, {
25
28
  color: color
26
- }))(state, dispatch);
29
+ })({
30
+ tr: tr
31
+ });
32
+ dispatch(tr);
27
33
  }
28
34
  return true;
29
35
  };
@@ -3,18 +3,20 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
3
  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; }
4
4
  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) { _defineProperty(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; }
5
5
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
- import { DEFAULT_BORDER_COLOR, textColorPalette } from '@atlaskit/editor-common/ui-color';
6
+ import { DEFAULT_BORDER_COLOR, textColorPalette, textColorPaletteWithTokenBorders } from '@atlaskit/editor-common/ui-color';
7
7
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
8
- import { DEFAULT_COLOR, getActiveColor } from '../utils/color';
8
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
9
+ import { getActiveColor } from '../utils/color';
10
+ import { DEFAULT_COLOR } from '../utils/constants';
9
11
  import { getDisabledState } from '../utils/disabled';
10
- export { DEFAULT_COLOR } from '../utils/color';
12
+ export { DEFAULT_COLOR } from '../utils/constants';
11
13
  function createInitialPluginState(editorState, pluginConfig) {
12
14
  var defaultColor = (pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.defaultColor) || DEFAULT_COLOR;
13
15
  var palette = [{
14
16
  value: defaultColor.color,
15
17
  label: defaultColor.label,
16
- border: DEFAULT_BORDER_COLOR
17
- }].concat(_toConsumableArray(textColorPalette));
18
+ border: getBooleanFF('platform.editor.dynamic-palette-borders') ? "var(--ds-border, #091E4224)" : DEFAULT_BORDER_COLOR
19
+ }].concat(_toConsumableArray(getBooleanFF('platform.editor.dynamic-palette-borders') ? textColorPaletteWithTokenBorders : textColorPalette));
18
20
  var state = {
19
21
  color: getActiveColor(editorState),
20
22
  disabled: getDisabledState(editorState),
@@ -161,7 +161,7 @@ export var ToolbarTextColor = /*#__PURE__*/function (_React$Component) {
161
161
  selectedRowIndex = _getSelectedRowAndCol.selectedRowIndex,
162
162
  selectedColumnIndex = _getSelectedRowAndCol.selectedColumnIndex;
163
163
  return (
164
- // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
164
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
165
165
  jsx("span", {
166
166
  css: wrapperStyle
167
167
  }, jsx(Dropdown, {
@@ -194,7 +194,7 @@ export var ToolbarTextColor = /*#__PURE__*/function (_React$Component) {
194
194
  onKeyDown: this.onKeyDown,
195
195
  ref: this.toolbarItemRef,
196
196
  iconBefore:
197
- // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
197
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
198
198
  jsx("div", {
199
199
  css: triggerWrapperStyles
200
200
  }, jsx(SteppedRainbowIconDecoration, {
@@ -221,6 +221,7 @@ export var ToolbarTextColor = /*#__PURE__*/function (_React$Component) {
221
221
  paletteColorTooltipMessages: textPaletteTooltipMessages
222
222
  }
223
223
  }))), !(pluginInjectionApi !== null && pluginInjectionApi !== void 0 && pluginInjectionApi.primaryToolbar) && /* eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage */
224
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
224
225
  jsx("span", {
225
226
  css: separatorStyles
226
227
  }))
@@ -1,10 +1,4 @@
1
- import { N800 } from '@atlaskit/theme/colors';
2
- export var DEFAULT_COLOR = {
3
- // TODO: https://product-fabric.atlassian.net/browse/DSP-4137
4
- /* eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage */
5
- color: N800.toLowerCase(),
6
- label: 'Dark gray'
7
- };
1
+ import { DEFAULT_COLOR } from './constants';
8
2
  export var getActiveColor = function getActiveColor(state) {
9
3
  var _ref = state.selection,
10
4
  $from = _ref.$from,
@@ -0,0 +1,8 @@
1
+ import { N800 } from '@atlaskit/theme/colors';
2
+ export var overrideMarks = ['backgroundColor'];
3
+ export var DEFAULT_COLOR = {
4
+ // TODO: https://product-fabric.atlassian.net/browse/DSP-4137
5
+ /* eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage */
6
+ color: N800.toLowerCase(),
7
+ label: 'Dark gray'
8
+ };
@@ -1,4 +1,5 @@
1
- import { entireSelectionContainsMark, isMarkAllowedInRange, isMarkExcluded } from '@atlaskit/editor-common/mark';
1
+ import { isMarkAllowedInRange, isMarkExcluded } from '@atlaskit/editor-common/mark';
2
+ import { overrideMarks } from './constants';
2
3
  var hasLinkMark = function hasLinkMark($pos) {
3
4
  var linkMarkType = $pos.doc.type.schema.marks.link,
4
5
  pos = $pos.pos;
@@ -7,39 +8,24 @@ var hasLinkMark = function hasLinkMark($pos) {
7
8
  }
8
9
  return $pos.doc.rangeHasMark(pos, Math.min(pos + 1, $pos.doc.content.size), linkMarkType);
9
10
  };
10
- var hasHighlightMark = function hasHighlightMark($pos) {
11
- var highlightMarkType = $pos.doc.type.schema.marks.backgroundColor;
12
- if (!highlightMarkType) {
13
- return false;
14
- }
15
- var node = $pos.nodeBefore;
16
- if (!node) {
17
- return false;
18
- }
19
- return !!highlightMarkType.isInSet(node.marks);
20
- };
21
- var hasHighlightMarkInRange = function hasHighlightMarkInRange($from, $to) {
22
- var highlightMarkType = $from.doc.type.schema.marks.backgroundColor,
23
- pos = $from.pos,
24
- doc = $from.doc;
25
- if (!highlightMarkType) {
26
- return false;
27
- }
28
- return entireSelectionContainsMark(highlightMarkType, doc, pos, $to.pos);
29
- };
30
11
  export var getDisabledState = function getDisabledState(state) {
31
12
  var textColor = state.schema.marks.textColor;
32
13
  if (textColor) {
14
+ var _state$storedMarks;
33
15
  var _ref = state.selection,
34
16
  empty = _ref.empty,
35
17
  ranges = _ref.ranges,
36
- $cursor = _ref.$cursor,
37
- $from = _ref.$from,
38
- $to = _ref.$to;
39
- if (empty && !$cursor || $cursor && hasLinkMark($cursor) || $cursor && hasHighlightMark($cursor) || !$cursor && $from && $to && hasHighlightMarkInRange($from, $to) || isMarkAllowedInRange(state.doc, ranges, textColor) === false) {
18
+ $cursor = _ref.$cursor;
19
+ if (empty && !$cursor || $cursor && hasLinkMark($cursor) || isMarkAllowedInRange(state.doc, ranges, textColor) === false) {
40
20
  return true;
41
21
  }
42
- if (isMarkExcluded(textColor, state.storedMarks || $cursor && $cursor.marks())) {
22
+
23
+ // Allow "excluded" marks that can be overridden
24
+ // These marks are explicitly removed before applying the new mark (see toggleColor command)
25
+ var omitOverrides = function omitOverrides(mark) {
26
+ return !overrideMarks.includes(mark.type.name);
27
+ };
28
+ if (isMarkExcluded(textColor, ((_state$storedMarks = state.storedMarks) === null || _state$storedMarks === void 0 ? void 0 : _state$storedMarks.filter(omitOverrides)) || $cursor && $cursor.marks().filter(omitOverrides))) {
43
29
  return true;
44
30
  }
45
31
  return false;
@@ -2,7 +2,7 @@ import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
3
  import type { PaletteColor } from '@atlaskit/editor-common/ui-color';
4
4
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
5
- export { DEFAULT_COLOR } from '../utils/color';
5
+ export { DEFAULT_COLOR } from '../utils/constants';
6
6
  export type TextColorPluginState = {
7
7
  palette: Array<PaletteColor>;
8
8
  defaultColor: string;
@@ -1,6 +1,2 @@
1
1
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
2
- export declare const DEFAULT_COLOR: {
3
- color: string;
4
- label: string;
5
- };
6
2
  export declare const getActiveColor: (state: EditorState) => string | null;
@@ -0,0 +1,5 @@
1
+ export declare const overrideMarks: string[];
2
+ export declare const DEFAULT_COLOR: {
3
+ color: string;
4
+ label: string;
5
+ };
@@ -2,7 +2,7 @@ import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
3
  import type { PaletteColor } from '@atlaskit/editor-common/ui-color';
4
4
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
5
- export { DEFAULT_COLOR } from '../utils/color';
5
+ export { DEFAULT_COLOR } from '../utils/constants';
6
6
  export type TextColorPluginState = {
7
7
  palette: Array<PaletteColor>;
8
8
  defaultColor: string;
@@ -1,6 +1,2 @@
1
1
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
2
- export declare const DEFAULT_COLOR: {
3
- color: string;
4
- label: string;
5
- };
6
2
  export declare const getActiveColor: (state: EditorState) => string | null;
@@ -0,0 +1,5 @@
1
+ export declare const overrideMarks: string[];
2
+ export declare const DEFAULT_COLOR: {
3
+ color: string;
4
+ label: string;
5
+ };
package/package.json CHANGED
@@ -1,95 +1,82 @@
1
1
  {
2
- "name": "@atlaskit/editor-plugin-text-color",
3
- "version": "1.4.1",
4
- "description": "Text color plugin for @atlaskit/editor-core",
5
- "author": "Atlassian Pty Ltd",
6
- "license": "Apache-2.0",
7
- "publishConfig": {
8
- "registry": "https://registry.npmjs.org/"
9
- },
10
- "atlassian": {
11
- "team": "Editor: Lego",
12
- "singleton": true,
13
- "inPublicMirror": false,
14
- "releaseModel": "continuous",
15
- "runReact18": false
16
- },
17
- "repository": "https://bitbucket.org/atlassian/atlassian-frontend-mirror",
18
- "main": "dist/cjs/index.js",
19
- "module": "dist/esm/index.js",
20
- "module:es2019": "dist/es2019/index.js",
21
- "types": "dist/types/index.d.ts",
22
- "typesVersions": {
23
- ">=4.5 <4.9": {
24
- "*": [
25
- "dist/types-ts4.5/*",
26
- "dist/types-ts4.5/index.d.ts"
27
- ]
28
- }
29
- },
30
- "sideEffects": false,
31
- "atlaskit:src": "src/index.ts",
32
- "af:exports": {
33
- ".": "./src/index.ts"
34
- },
35
- "dependencies": {
36
- "@atlaskit/adf-schema": "^36.10.7",
37
- "@atlaskit/editor-common": "^82.0.0",
38
- "@atlaskit/editor-palette": "1.6.0",
39
- "@atlaskit/editor-plugin-analytics": "^1.2.0",
40
- "@atlaskit/editor-plugin-primary-toolbar": "^1.1.0",
41
- "@atlaskit/editor-prosemirror": "4.0.1",
42
- "@atlaskit/editor-shared-styles": "^2.12.0",
43
- "@atlaskit/editor-tables": "^2.7.0",
44
- "@atlaskit/icon": "^22.3.0",
45
- "@atlaskit/theme": "^12.8.0",
46
- "@babel/runtime": "^7.0.0",
47
- "@emotion/react": "^11.7.1"
48
- },
49
- "peerDependencies": {
50
- "react": "^16.8.0",
51
- "react-intl-next": "npm:react-intl@^5.18.1"
52
- },
53
- "devDependencies": {
54
- "@af/visual-regression": "*",
55
- "@atlaskit/ssr": "*",
56
- "@atlaskit/visual-regression": "*",
57
- "@testing-library/react": "^12.1.5",
58
- "react-dom": "^16.8.0",
59
- "typescript": "~5.4.2",
60
- "wait-for-expect": "^1.2.0"
61
- },
62
- "techstack": {
63
- "@atlassian/frontend": {
64
- "import-structure": [
65
- "atlassian-conventions"
66
- ],
67
- "circular-dependencies": [
68
- "file-and-folder-level"
69
- ]
70
- },
71
- "@repo/internal": {
72
- "dom-events": "use-bind-event-listener",
73
- "analytics": [
74
- "analytics-next"
75
- ],
76
- "design-tokens": [
77
- "color"
78
- ],
79
- "theming": [
80
- "react-context"
81
- ],
82
- "ui-components": [
83
- "lite-mode"
84
- ],
85
- "deprecation": "no-deprecated-imports",
86
- "styling": [
87
- "emotion",
88
- "emotion"
89
- ],
90
- "imports": [
91
- "import-no-extraneous-disable-for-examples-and-docs"
92
- ]
93
- }
94
- }
95
- }
2
+ "name": "@atlaskit/editor-plugin-text-color",
3
+ "version": "1.6.0",
4
+ "description": "Text color plugin for @atlaskit/editor-core",
5
+ "author": "Atlassian Pty Ltd",
6
+ "license": "Apache-2.0",
7
+ "publishConfig": {
8
+ "registry": "https://registry.npmjs.org/"
9
+ },
10
+ "atlassian": {
11
+ "team": "Editor: Lego",
12
+ "singleton": true,
13
+ "inPublicMirror": false,
14
+ "releaseModel": "continuous",
15
+ "runReact18": false
16
+ },
17
+ "repository": "https://bitbucket.org/atlassian/atlassian-frontend-mirror",
18
+ "main": "dist/cjs/index.js",
19
+ "module": "dist/esm/index.js",
20
+ "module:es2019": "dist/es2019/index.js",
21
+ "types": "dist/types/index.d.ts",
22
+ "typesVersions": {
23
+ ">=4.5 <4.9": {
24
+ "*": ["dist/types-ts4.5/*", "dist/types-ts4.5/index.d.ts"]
25
+ }
26
+ },
27
+ "sideEffects": false,
28
+ "atlaskit:src": "src/index.ts",
29
+ "af:exports": {
30
+ ".": "./src/index.ts"
31
+ },
32
+ "dependencies": {
33
+ "@atlaskit/adf-schema": "^36.10.7",
34
+ "@atlaskit/editor-common": "^82.6.0",
35
+ "@atlaskit/editor-palette": "1.6.0",
36
+ "@atlaskit/editor-plugin-analytics": "^1.2.0",
37
+ "@atlaskit/editor-plugin-primary-toolbar": "^1.1.0",
38
+ "@atlaskit/editor-prosemirror": "4.0.1",
39
+ "@atlaskit/editor-shared-styles": "^2.12.0",
40
+ "@atlaskit/editor-tables": "^2.7.0",
41
+ "@atlaskit/icon": "^22.3.0",
42
+ "@atlaskit/platform-feature-flags": "^0.2.0",
43
+ "@atlaskit/theme": "^12.9.0",
44
+ "@atlaskit/tokens": "^1.50.0",
45
+ "@babel/runtime": "^7.0.0",
46
+ "@emotion/react": "^11.7.1"
47
+ },
48
+ "peerDependencies": {
49
+ "react": "^16.8.0",
50
+ "react-intl-next": "npm:react-intl@^5.18.1"
51
+ },
52
+ "devDependencies": {
53
+ "@af/visual-regression": "*",
54
+ "@atlaskit/ssr": "*",
55
+ "@atlaskit/visual-regression": "*",
56
+ "@testing-library/react": "^12.1.5",
57
+ "react-dom": "^16.8.0",
58
+ "typescript": "~5.4.2",
59
+ "wait-for-expect": "^1.2.0"
60
+ },
61
+ "techstack": {
62
+ "@atlassian/frontend": {
63
+ "import-structure": ["atlassian-conventions"],
64
+ "circular-dependencies": ["file-and-folder-level"]
65
+ },
66
+ "@repo/internal": {
67
+ "dom-events": "use-bind-event-listener",
68
+ "analytics": ["analytics-next"],
69
+ "design-tokens": ["color"],
70
+ "theming": ["react-context"],
71
+ "ui-components": ["lite-mode"],
72
+ "deprecation": "no-deprecated-imports",
73
+ "styling": ["emotion", "emotion"],
74
+ "imports": ["import-no-extraneous-disable-for-examples-and-docs"]
75
+ }
76
+ },
77
+ "platform-feature-flags": {
78
+ "platform.editor.dynamic-palette-borders": {
79
+ "type": "boolean"
80
+ }
81
+ }
82
+ }