@atlaskit/editor-plugin-text-color 0.1.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 +1 -0
- package/LICENSE.md +13 -0
- package/README.md +30 -0
- package/dist/cjs/commands/change-color.js +61 -0
- package/dist/cjs/commands/remove-color.js +59 -0
- package/dist/cjs/commands/toggle-color.js +36 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/plugin.js +87 -0
- package/dist/cjs/pm-plugins/main.js +88 -0
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/ui/ToolbarTextColor/icon.js +29 -0
- package/dist/cjs/ui/ToolbarTextColor/index.js +296 -0
- package/dist/cjs/ui/ToolbarTextColor/styles.js +35 -0
- package/dist/cjs/utils/color.js +54 -0
- package/dist/cjs/utils/disabled.js +32 -0
- package/dist/es2019/commands/change-color.js +54 -0
- package/dist/es2019/commands/remove-color.js +57 -0
- package/dist/es2019/commands/toggle-color.js +30 -0
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/plugin.js +75 -0
- package/dist/es2019/pm-plugins/main.js +74 -0
- package/dist/es2019/types.js +1 -0
- package/dist/es2019/ui/ToolbarTextColor/icon.js +20 -0
- package/dist/es2019/ui/ToolbarTextColor/index.js +274 -0
- package/dist/es2019/ui/ToolbarTextColor/styles.js +48 -0
- package/dist/es2019/utils/color.js +48 -0
- package/dist/es2019/utils/disabled.js +39 -0
- package/dist/esm/commands/change-color.js +56 -0
- package/dist/esm/commands/remove-color.js +53 -0
- package/dist/esm/commands/toggle-color.js +30 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/plugin.js +75 -0
- package/dist/esm/pm-plugins/main.js +74 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/ui/ToolbarTextColor/icon.js +22 -0
- package/dist/esm/ui/ToolbarTextColor/index.js +290 -0
- package/dist/esm/ui/ToolbarTextColor/styles.js +28 -0
- package/dist/esm/utils/color.js +48 -0
- package/dist/esm/utils/disabled.js +26 -0
- package/dist/types/commands/change-color.d.ts +3 -0
- package/dist/types/commands/remove-color.d.ts +2 -0
- package/dist/types/commands/toggle-color.d.ts +2 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/plugin.d.ts +6 -0
- package/dist/types/pm-plugins/main.d.ts +25 -0
- package/dist/types/types.d.ts +14 -0
- package/dist/types/ui/ToolbarTextColor/icon.d.ts +2 -0
- package/dist/types/ui/ToolbarTextColor/index.d.ts +53 -0
- package/dist/types/ui/ToolbarTextColor/styles.d.ts +3 -0
- package/dist/types/utils/color.d.ts +6 -0
- package/dist/types/utils/disabled.d.ts +2 -0
- package/dist/types-ts4.5/commands/change-color.d.ts +3 -0
- package/dist/types-ts4.5/commands/remove-color.d.ts +2 -0
- package/dist/types-ts4.5/commands/toggle-color.d.ts +2 -0
- package/dist/types-ts4.5/index.d.ts +3 -0
- package/dist/types-ts4.5/plugin.d.ts +6 -0
- package/dist/types-ts4.5/pm-plugins/main.d.ts +25 -0
- package/dist/types-ts4.5/types.d.ts +16 -0
- package/dist/types-ts4.5/ui/ToolbarTextColor/icon.d.ts +2 -0
- package/dist/types-ts4.5/ui/ToolbarTextColor/index.d.ts +53 -0
- package/dist/types-ts4.5/ui/ToolbarTextColor/styles.d.ts +3 -0
- package/dist/types-ts4.5/utils/color.d.ts +6 -0
- package/dist/types-ts4.5/utils/disabled.d.ts +2 -0
- package/package.json +98 -0
- package/report.api.md +82 -0
- package/tmp/api-report-tmp.d.ts +54 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { textColor } from '@atlaskit/adf-schema';
|
|
3
|
+
import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
|
|
4
|
+
import { changeColor as _changeColor } from './commands/change-color';
|
|
5
|
+
import { createPlugin, pluginKey as textColorPluginKey } from './pm-plugins/main';
|
|
6
|
+
import ToolbarTextColor from './ui/ToolbarTextColor';
|
|
7
|
+
var pluginConfig = function pluginConfig(textColorConfig) {
|
|
8
|
+
if (!textColorConfig || typeof textColorConfig === 'boolean') {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
return textColorConfig;
|
|
12
|
+
};
|
|
13
|
+
export var textColorPlugin = function textColorPlugin(_ref) {
|
|
14
|
+
var textColorConfig = _ref.config,
|
|
15
|
+
api = _ref.api;
|
|
16
|
+
return {
|
|
17
|
+
name: 'textColor',
|
|
18
|
+
marks: function marks() {
|
|
19
|
+
return [{
|
|
20
|
+
name: 'textColor',
|
|
21
|
+
mark: textColor
|
|
22
|
+
}];
|
|
23
|
+
},
|
|
24
|
+
pmPlugins: function pmPlugins() {
|
|
25
|
+
return [{
|
|
26
|
+
name: 'textColor',
|
|
27
|
+
plugin: function plugin(_ref2) {
|
|
28
|
+
var dispatch = _ref2.dispatch;
|
|
29
|
+
return createPlugin(dispatch, pluginConfig(textColorConfig));
|
|
30
|
+
}
|
|
31
|
+
}];
|
|
32
|
+
},
|
|
33
|
+
getSharedState: function getSharedState(editorState) {
|
|
34
|
+
if (!editorState) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
return textColorPluginKey.getState(editorState);
|
|
38
|
+
},
|
|
39
|
+
actions: {
|
|
40
|
+
changeColor: function changeColor(color) {
|
|
41
|
+
var _api$analytics;
|
|
42
|
+
return _changeColor(color, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
primaryToolbarComponent: function primaryToolbarComponent(_ref3) {
|
|
46
|
+
var editorView = _ref3.editorView,
|
|
47
|
+
popupsMountPoint = _ref3.popupsMountPoint,
|
|
48
|
+
popupsBoundariesElement = _ref3.popupsBoundariesElement,
|
|
49
|
+
popupsScrollableElement = _ref3.popupsScrollableElement,
|
|
50
|
+
isToolbarReducedSpacing = _ref3.isToolbarReducedSpacing,
|
|
51
|
+
dispatchAnalyticsEvent = _ref3.dispatchAnalyticsEvent,
|
|
52
|
+
disabled = _ref3.disabled;
|
|
53
|
+
return /*#__PURE__*/React.createElement(WithPluginState, {
|
|
54
|
+
plugins: {
|
|
55
|
+
textColor: textColorPluginKey
|
|
56
|
+
},
|
|
57
|
+
render: function render(_ref4) {
|
|
58
|
+
var textColor = _ref4.textColor;
|
|
59
|
+
return /*#__PURE__*/React.createElement(ToolbarTextColor, {
|
|
60
|
+
pluginState: textColor,
|
|
61
|
+
isReducedSpacing: isToolbarReducedSpacing,
|
|
62
|
+
editorView: editorView,
|
|
63
|
+
popupsMountPoint: popupsMountPoint,
|
|
64
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
65
|
+
popupsScrollableElement: popupsScrollableElement,
|
|
66
|
+
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
67
|
+
disabled: disabled,
|
|
68
|
+
pluginInjectionApi: api
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
export { textColorPluginKey };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
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
|
+
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
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
6
|
+
import { DEFAULT_BORDER_COLOR, textColorPalette } from '@atlaskit/editor-common/ui-color';
|
|
7
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
8
|
+
import { DEFAULT_COLOR, getActiveColor } from '../utils/color';
|
|
9
|
+
import { getDisabledState } from '../utils/disabled';
|
|
10
|
+
export { DEFAULT_COLOR } from '../utils/color';
|
|
11
|
+
function createInitialPluginState(editorState, pluginConfig) {
|
|
12
|
+
var defaultColor = (pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.defaultColor) || DEFAULT_COLOR;
|
|
13
|
+
var palette = [{
|
|
14
|
+
value: defaultColor.color,
|
|
15
|
+
label: defaultColor.label,
|
|
16
|
+
border: DEFAULT_BORDER_COLOR
|
|
17
|
+
}].concat(_toConsumableArray(textColorPalette));
|
|
18
|
+
var state = {
|
|
19
|
+
color: getActiveColor(editorState),
|
|
20
|
+
disabled: getDisabledState(editorState),
|
|
21
|
+
palette: palette,
|
|
22
|
+
defaultColor: defaultColor.color
|
|
23
|
+
};
|
|
24
|
+
return state;
|
|
25
|
+
}
|
|
26
|
+
export var ACTIONS = /*#__PURE__*/function (ACTIONS) {
|
|
27
|
+
ACTIONS[ACTIONS["RESET_COLOR"] = 0] = "RESET_COLOR";
|
|
28
|
+
ACTIONS[ACTIONS["SET_COLOR"] = 1] = "SET_COLOR";
|
|
29
|
+
ACTIONS[ACTIONS["DISABLE"] = 2] = "DISABLE";
|
|
30
|
+
return ACTIONS;
|
|
31
|
+
}({});
|
|
32
|
+
export var pluginKey = new PluginKey('textColorPlugin');
|
|
33
|
+
export function createPlugin(dispatch, pluginConfig) {
|
|
34
|
+
return new SafePlugin({
|
|
35
|
+
key: pluginKey,
|
|
36
|
+
state: {
|
|
37
|
+
init: function init(_config, editorState) {
|
|
38
|
+
return createInitialPluginState(editorState, pluginConfig);
|
|
39
|
+
},
|
|
40
|
+
apply: function apply(tr, pluginState, _, newState) {
|
|
41
|
+
var meta = tr.getMeta(pluginKey) || {};
|
|
42
|
+
var nextState;
|
|
43
|
+
switch (meta.action) {
|
|
44
|
+
case ACTIONS.RESET_COLOR:
|
|
45
|
+
nextState = _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
46
|
+
color: pluginState.defaultColor
|
|
47
|
+
});
|
|
48
|
+
break;
|
|
49
|
+
case ACTIONS.SET_COLOR:
|
|
50
|
+
nextState = _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
51
|
+
color: meta.color,
|
|
52
|
+
disabled: false
|
|
53
|
+
});
|
|
54
|
+
break;
|
|
55
|
+
case ACTIONS.DISABLE:
|
|
56
|
+
nextState = _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
57
|
+
disabled: true
|
|
58
|
+
});
|
|
59
|
+
break;
|
|
60
|
+
default:
|
|
61
|
+
nextState = _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
62
|
+
color: getActiveColor(newState),
|
|
63
|
+
disabled: getDisabledState(newState)
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (pluginState && pluginState.color !== nextState.color || pluginState && pluginState.disabled !== nextState.disabled) {
|
|
67
|
+
dispatch(pluginKey, nextState);
|
|
68
|
+
return nextState;
|
|
69
|
+
}
|
|
70
|
+
return pluginState;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
5
|
+
import Icon from '@atlaskit/icon/base';
|
|
6
|
+
var textColorGlyph = function textColorGlyph(props) {
|
|
7
|
+
return /*#__PURE__*/React.createElement("svg", _extends({}, props, {
|
|
8
|
+
width: "24",
|
|
9
|
+
height: "24",
|
|
10
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
11
|
+
}), /*#__PURE__*/React.createElement("path", {
|
|
12
|
+
d: "M14 12.5h-4l-.874 2.186A.5.5 0 0 1 8.66 15H7.273a.5.5 0 0 1-.456-.705l4.05-9A.5.5 0 0 1 11.323 5h1.354a.5.5 0 0 1 .456.295l4.05 9a.5.5 0 0 1-.456.705h-1.388a.5.5 0 0 1-.465-.314L14 12.5zm-.6-1.5L12 7.5 10.6 11h2.8z",
|
|
13
|
+
fill: "currentColor",
|
|
14
|
+
fillRule: "evenodd"
|
|
15
|
+
}));
|
|
16
|
+
};
|
|
17
|
+
export var EditorTextColorIcon = function EditorTextColorIcon() {
|
|
18
|
+
return /*#__PURE__*/React.createElement(Icon, {
|
|
19
|
+
glyph: textColorGlyph,
|
|
20
|
+
label: ""
|
|
21
|
+
});
|
|
22
|
+
};
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
4
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
5
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
6
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
7
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
8
|
+
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; }
|
|
9
|
+
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; }
|
|
10
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
11
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
12
|
+
/** @jsx jsx */
|
|
13
|
+
import React from 'react';
|
|
14
|
+
import { jsx } from '@emotion/react';
|
|
15
|
+
import { defineMessages, injectIntl } from 'react-intl-next';
|
|
16
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
17
|
+
import { expandIconWrapperStyle, separatorStyles, triggerWrapperStyles, wrapperStyle } from '@atlaskit/editor-common/styles';
|
|
18
|
+
import { ColorPalette, getSelectedRowAndColumnFromPalette, textPaletteTooltipMessages } from '@atlaskit/editor-common/ui-color';
|
|
19
|
+
import { ArrowKeyNavigationType, DropdownContainer as Dropdown, TOOLBAR_BUTTON, ToolbarButton } from '@atlaskit/editor-common/ui-menu';
|
|
20
|
+
import { hexToEditorTextPaletteColor } from '@atlaskit/editor-palette';
|
|
21
|
+
import { akEditorMenuZIndex } from '@atlaskit/editor-shared-styles';
|
|
22
|
+
import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
|
|
23
|
+
import { changeColor as changeColorWithAnalytics } from '../../commands/change-color';
|
|
24
|
+
import { EditorTextColorIcon } from './icon';
|
|
25
|
+
import { backgroundDisabled, textColorIconBar, textColorIconWrapper } from './styles';
|
|
26
|
+
var EXPERIMENT_NAME = 'editor.toolbarTextColor.moreColors';
|
|
27
|
+
var EXPERIMENT_GROUP_CONTROL = 'control';
|
|
28
|
+
export var messages = defineMessages({
|
|
29
|
+
textColor: {
|
|
30
|
+
id: 'fabric.editor.textColor',
|
|
31
|
+
defaultMessage: 'Text color',
|
|
32
|
+
description: ''
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
36
|
+
export var ToolbarTextColor = /*#__PURE__*/function (_React$Component) {
|
|
37
|
+
_inherits(ToolbarTextColor, _React$Component);
|
|
38
|
+
var _super = _createSuper(ToolbarTextColor);
|
|
39
|
+
function ToolbarTextColor() {
|
|
40
|
+
var _this;
|
|
41
|
+
_classCallCheck(this, ToolbarTextColor);
|
|
42
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
43
|
+
args[_key] = arguments[_key];
|
|
44
|
+
}
|
|
45
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
46
|
+
_defineProperty(_assertThisInitialized(_this), "state", {
|
|
47
|
+
isOpen: false,
|
|
48
|
+
isOpenedByKeyboard: false
|
|
49
|
+
});
|
|
50
|
+
_defineProperty(_assertThisInitialized(_this), "toolbarItemRef", /*#__PURE__*/React.createRef());
|
|
51
|
+
_defineProperty(_assertThisInitialized(_this), "changeColor", function (color, editorAnalyticsApi) {
|
|
52
|
+
return changeColorWithAnalytics(color, editorAnalyticsApi)(_this.props.editorView.state, _this.props.editorView.dispatch);
|
|
53
|
+
});
|
|
54
|
+
_defineProperty(_assertThisInitialized(_this), "onOpenChange", function (attrs) {
|
|
55
|
+
_this.handleOpenChange({
|
|
56
|
+
isOpen: attrs.isOpen,
|
|
57
|
+
logCloseEvent: true,
|
|
58
|
+
event: attrs.event
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
_defineProperty(_assertThisInitialized(_this), "changeTextColor", function (color, editorAnalyticsApi, disabled) {
|
|
62
|
+
if (!disabled) {
|
|
63
|
+
var _this$props$editorVie;
|
|
64
|
+
var palette = _this.props.pluginState.palette;
|
|
65
|
+
|
|
66
|
+
// we store color names in analytics
|
|
67
|
+
var swatch = palette.find(function (sw) {
|
|
68
|
+
return sw.value === color;
|
|
69
|
+
});
|
|
70
|
+
_this.dispatchAnalyticsEvent(_this.buildAnalyticsSelectColor({
|
|
71
|
+
color: (swatch ? swatch.label : color).toLowerCase()
|
|
72
|
+
}));
|
|
73
|
+
_this.handleOpenChange({
|
|
74
|
+
isOpen: false,
|
|
75
|
+
logCloseEvent: false
|
|
76
|
+
});
|
|
77
|
+
_this.changeColor(color, editorAnalyticsApi);
|
|
78
|
+
//To set the focus on the textcolor button when the menu is closed by 'Esc' only to meet aria guidelines
|
|
79
|
+
(_this$props$editorVie = _this.props.editorView) === null || _this$props$editorVie === void 0 || _this$props$editorVie.focus();
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
});
|
|
83
|
+
_defineProperty(_assertThisInitialized(_this), "toggleOpen", function () {
|
|
84
|
+
_this.handleOpenChange({
|
|
85
|
+
isOpen: !_this.state.isOpen,
|
|
86
|
+
logCloseEvent: true
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
_defineProperty(_assertThisInitialized(_this), "onKeyDown", function (event) {
|
|
90
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
91
|
+
event.preventDefault();
|
|
92
|
+
_this.setState({
|
|
93
|
+
isOpenedByKeyboard: true
|
|
94
|
+
});
|
|
95
|
+
_this.toggleOpen();
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
_defineProperty(_assertThisInitialized(_this), "handleOpenChange", function (_ref) {
|
|
99
|
+
var isOpen = _ref.isOpen,
|
|
100
|
+
logCloseEvent = _ref.logCloseEvent,
|
|
101
|
+
event = _ref.event;
|
|
102
|
+
_this.setState({
|
|
103
|
+
isOpen: isOpen
|
|
104
|
+
});
|
|
105
|
+
if (!isOpen) {
|
|
106
|
+
_this.setState({
|
|
107
|
+
isOpenedByKeyboard: false
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
if (logCloseEvent) {
|
|
111
|
+
_this.dispatchAnalyticsEvent(_this.buildAnalyticsPalette(isOpen ? ACTION.OPENED : ACTION.CLOSED, {
|
|
112
|
+
noSelect: isOpen === false
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
if (!isOpen && event instanceof KeyboardEvent && (event === null || event === void 0 ? void 0 : event.key) === 'Escape') {
|
|
116
|
+
var _this$toolbarItemRef;
|
|
117
|
+
(_this$toolbarItemRef = _this.toolbarItemRef) === null || _this$toolbarItemRef === void 0 || (_this$toolbarItemRef = _this$toolbarItemRef.current) === null || _this$toolbarItemRef === void 0 || _this$toolbarItemRef.focus();
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
_defineProperty(_assertThisInitialized(_this), "hide", function (e) {
|
|
121
|
+
var isOpen = _this.state.isOpen;
|
|
122
|
+
if (isOpen === true) {
|
|
123
|
+
_this.dispatchAnalyticsEvent(_this.buildAnalyticsPalette(ACTION.CLOSED, {
|
|
124
|
+
noSelect: true
|
|
125
|
+
}));
|
|
126
|
+
_this.setState({
|
|
127
|
+
isOpen: false
|
|
128
|
+
});
|
|
129
|
+
if (e instanceof KeyboardEvent && e.key === 'Escape') {
|
|
130
|
+
var _this$toolbarItemRef2;
|
|
131
|
+
(_this$toolbarItemRef2 = _this.toolbarItemRef) === null || _this$toolbarItemRef2 === void 0 || (_this$toolbarItemRef2 = _this$toolbarItemRef2.current) === null || _this$toolbarItemRef2 === void 0 || _this$toolbarItemRef2.focus();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
_defineProperty(_assertThisInitialized(_this), "hideonEsc", function (e) {
|
|
136
|
+
var _this$toolbarItemRef3;
|
|
137
|
+
_this.hide(e);
|
|
138
|
+
(_this$toolbarItemRef3 = _this.toolbarItemRef) === null || _this$toolbarItemRef3 === void 0 || (_this$toolbarItemRef3 = _this$toolbarItemRef3.current) === null || _this$toolbarItemRef3 === void 0 || _this$toolbarItemRef3.focus();
|
|
139
|
+
});
|
|
140
|
+
return _this;
|
|
141
|
+
}
|
|
142
|
+
_createClass(ToolbarTextColor, [{
|
|
143
|
+
key: "render",
|
|
144
|
+
value: function render() {
|
|
145
|
+
var _this2 = this;
|
|
146
|
+
var _this$state = this.state,
|
|
147
|
+
isOpen = _this$state.isOpen,
|
|
148
|
+
isOpenedByKeyboard = _this$state.isOpenedByKeyboard;
|
|
149
|
+
var _this$props = this.props,
|
|
150
|
+
popupsMountPoint = _this$props.popupsMountPoint,
|
|
151
|
+
popupsBoundariesElement = _this$props.popupsBoundariesElement,
|
|
152
|
+
popupsScrollableElement = _this$props.popupsScrollableElement,
|
|
153
|
+
isReducedSpacing = _this$props.isReducedSpacing,
|
|
154
|
+
pluginState = _this$props.pluginState,
|
|
155
|
+
formatMessage = _this$props.intl.formatMessage,
|
|
156
|
+
disabled = _this$props.disabled,
|
|
157
|
+
pluginInjectionApi = _this$props.pluginInjectionApi;
|
|
158
|
+
var labelTextColor = formatMessage(messages.textColor);
|
|
159
|
+
var palette = pluginState.palette;
|
|
160
|
+
var fitWidth;
|
|
161
|
+
if (document.body.clientWidth <= 740) {
|
|
162
|
+
// This was originally hard-coded, but moved here to a const
|
|
163
|
+
// My guess is it's based off (width of button * columns) + left/right padding
|
|
164
|
+
// 240 = (32 * 7) + (8 + 8)
|
|
165
|
+
// Not sure where the extra 2px comes from
|
|
166
|
+
fitWidth = 242;
|
|
167
|
+
}
|
|
168
|
+
var selectedColor = this.getSelectedColor(pluginState);
|
|
169
|
+
var _getSelectedRowAndCol = getSelectedRowAndColumnFromPalette(palette, pluginState.color),
|
|
170
|
+
selectedRowIndex = _getSelectedRowAndCol.selectedRowIndex,
|
|
171
|
+
selectedColumnIndex = _getSelectedRowAndCol.selectedColumnIndex;
|
|
172
|
+
return (
|
|
173
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
174
|
+
jsx("span", {
|
|
175
|
+
css: wrapperStyle
|
|
176
|
+
}, jsx(Dropdown, {
|
|
177
|
+
mountTo: popupsMountPoint,
|
|
178
|
+
boundariesElement: popupsBoundariesElement,
|
|
179
|
+
scrollableElement: popupsScrollableElement,
|
|
180
|
+
isOpen: isOpen && !pluginState.disabled,
|
|
181
|
+
handleClickOutside: this.hide,
|
|
182
|
+
handleEscapeKeydown: this.hideonEsc,
|
|
183
|
+
zIndex: akEditorMenuZIndex,
|
|
184
|
+
fitWidth: fitWidth,
|
|
185
|
+
onOpenChange: this.onOpenChange,
|
|
186
|
+
closeOnTab: true,
|
|
187
|
+
arrowKeyNavigationProviderOptions: {
|
|
188
|
+
type: ArrowKeyNavigationType.COLOR,
|
|
189
|
+
selectedRowIndex: selectedRowIndex,
|
|
190
|
+
selectedColumnIndex: selectedColumnIndex,
|
|
191
|
+
isOpenedByKeyboard: isOpenedByKeyboard,
|
|
192
|
+
isPopupPositioned: true
|
|
193
|
+
},
|
|
194
|
+
trigger: jsx(ToolbarButton, {
|
|
195
|
+
buttonId: TOOLBAR_BUTTON.TEXT_COLOR,
|
|
196
|
+
spacing: isReducedSpacing ? 'none' : 'default',
|
|
197
|
+
disabled: disabled || pluginState.disabled,
|
|
198
|
+
selected: isOpen,
|
|
199
|
+
"aria-label": labelTextColor,
|
|
200
|
+
"aria-expanded": isOpen,
|
|
201
|
+
"aria-haspopup": true,
|
|
202
|
+
title: labelTextColor,
|
|
203
|
+
onClick: this.toggleOpen,
|
|
204
|
+
onKeyDown: this.onKeyDown,
|
|
205
|
+
ref: this.toolbarItemRef,
|
|
206
|
+
iconBefore:
|
|
207
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
208
|
+
jsx("div", {
|
|
209
|
+
css: triggerWrapperStyles
|
|
210
|
+
}, jsx("div", {
|
|
211
|
+
css: textColorIconWrapper
|
|
212
|
+
}, jsx(EditorTextColorIcon, null), jsx("div", {
|
|
213
|
+
css: [
|
|
214
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
215
|
+
textColorIconBar, selectedColor ? // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
216
|
+
"background: ".concat(selectedColor, ";") :
|
|
217
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
218
|
+
pluginState.disabled && backgroundDisabled]
|
|
219
|
+
})), jsx("span", {
|
|
220
|
+
css: expandIconWrapperStyle
|
|
221
|
+
}, jsx(ExpandIcon, {
|
|
222
|
+
label: ""
|
|
223
|
+
})))
|
|
224
|
+
})
|
|
225
|
+
}, jsx("div", {
|
|
226
|
+
"data-testid": "text-color-palette"
|
|
227
|
+
}, jsx(ColorPalette, {
|
|
228
|
+
onClick: function onClick(color) {
|
|
229
|
+
var _pluginInjectionApi$a;
|
|
230
|
+
return _this2.changeTextColor(color, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions, pluginState.disabled);
|
|
231
|
+
},
|
|
232
|
+
selectedColor: pluginState.color,
|
|
233
|
+
paletteOptions: {
|
|
234
|
+
palette: palette,
|
|
235
|
+
hexToPaletteColor: hexToEditorTextPaletteColor,
|
|
236
|
+
paletteColorTooltipMessages: textPaletteTooltipMessages
|
|
237
|
+
}
|
|
238
|
+
}))), jsx("span", {
|
|
239
|
+
css: separatorStyles
|
|
240
|
+
}))
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
}, {
|
|
244
|
+
key: "getSelectedColor",
|
|
245
|
+
value: function getSelectedColor(pluginState) {
|
|
246
|
+
var selectedColor = pluginState.color !== pluginState.defaultColor && (pluginState.color ? hexToEditorTextPaletteColor(pluginState.color) : pluginState.color);
|
|
247
|
+
return selectedColor;
|
|
248
|
+
}
|
|
249
|
+
}, {
|
|
250
|
+
key: "getCommonAnalyticsAttributes",
|
|
251
|
+
value: function getCommonAnalyticsAttributes() {
|
|
252
|
+
return {
|
|
253
|
+
experiment: EXPERIMENT_NAME,
|
|
254
|
+
experimentGroup: EXPERIMENT_GROUP_CONTROL
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
}, {
|
|
258
|
+
key: "buildAnalyticsPalette",
|
|
259
|
+
value: function buildAnalyticsPalette(action, data) {
|
|
260
|
+
return {
|
|
261
|
+
action: action,
|
|
262
|
+
actionSubject: ACTION_SUBJECT.TOOLBAR,
|
|
263
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_COLOR,
|
|
264
|
+
eventType: EVENT_TYPE.TRACK,
|
|
265
|
+
attributes: _objectSpread(_objectSpread({}, this.getCommonAnalyticsAttributes()), data)
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
}, {
|
|
269
|
+
key: "buildAnalyticsSelectColor",
|
|
270
|
+
value: function buildAnalyticsSelectColor(data) {
|
|
271
|
+
return {
|
|
272
|
+
action: ACTION.FORMATTED,
|
|
273
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
274
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_COLOR,
|
|
275
|
+
eventType: EVENT_TYPE.TRACK,
|
|
276
|
+
attributes: _objectSpread(_objectSpread({}, this.getCommonAnalyticsAttributes()), data)
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
}, {
|
|
280
|
+
key: "dispatchAnalyticsEvent",
|
|
281
|
+
value: function dispatchAnalyticsEvent(payload) {
|
|
282
|
+
var dispatchAnalyticsEvent = this.props.dispatchAnalyticsEvent;
|
|
283
|
+
if (dispatchAnalyticsEvent) {
|
|
284
|
+
dispatchAnalyticsEvent(payload);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}]);
|
|
288
|
+
return ToolbarTextColor;
|
|
289
|
+
}(React.Component);
|
|
290
|
+
export default injectIntl(ToolbarTextColor);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
|
|
2
|
+
var _templateObject, _templateObject2, _templateObject3;
|
|
3
|
+
import { css } from '@emotion/react';
|
|
4
|
+
import { N40, N60, N80, P300, R400, T300, Y400 } from '@atlaskit/theme/colors';
|
|
5
|
+
import { borderRadius } from '@atlaskit/theme/constants';
|
|
6
|
+
var createSteppedRainbow = function createSteppedRainbow(colors) {
|
|
7
|
+
return "\n linear-gradient(\n to right,\n ".concat(colors.map(function (color, i) {
|
|
8
|
+
var inc = 100 / colors.length;
|
|
9
|
+
var pos = i + 1;
|
|
10
|
+
if (i === 0) {
|
|
11
|
+
return "".concat(color, " ").concat(pos * inc, "%,");
|
|
12
|
+
}
|
|
13
|
+
if (i === colors.length - 1) {
|
|
14
|
+
return "".concat(color, " ").concat((pos - 1) * inc, "%");
|
|
15
|
+
}
|
|
16
|
+
return "\n ".concat(color, " ").concat((pos - 1) * inc, "%,\n ").concat(color, " ").concat(pos * inc, "%,\n ");
|
|
17
|
+
}).join('\n'), "\n );\n ");
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// TODO: https://product-fabric.atlassian.net/browse/DSP-4137
|
|
21
|
+
/* eslint-disable @atlaskit/design-system/ensure-design-token-usage */
|
|
22
|
+
var rainbow = createSteppedRainbow([P300, T300, Y400, R400]);
|
|
23
|
+
var disabledRainbow = createSteppedRainbow([N80, N60, N40, N60]);
|
|
24
|
+
/* eslint-enable @atlaskit/design-system/ensure-design-token-usage */
|
|
25
|
+
|
|
26
|
+
export var textColorIconWrapper = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: relative;\n"])));
|
|
27
|
+
export var textColorIconBar = css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n position: absolute;\n left: 0;\n right: 0;\n top: ", ";\n margin: auto;\n width: 12px;\n height: 3px;\n border-radius: ", ";\n background: ", ";\n"])), "var(--ds-space-200, 16px)", borderRadius() + 'px', rainbow);
|
|
28
|
+
export var backgroundDisabled = css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n background: ", ";\n"])), disabledRainbow);
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
};
|
|
8
|
+
export var getActiveColor = function getActiveColor(state) {
|
|
9
|
+
var _ref = state.selection,
|
|
10
|
+
$from = _ref.$from,
|
|
11
|
+
$to = _ref.$to,
|
|
12
|
+
$cursor = _ref.$cursor;
|
|
13
|
+
var _ref2 = state.schema.marks,
|
|
14
|
+
textColor = _ref2.textColor;
|
|
15
|
+
|
|
16
|
+
// Filter out other marks
|
|
17
|
+
var marks = [];
|
|
18
|
+
if ($cursor) {
|
|
19
|
+
marks.push(textColor.isInSet(state.storedMarks || $cursor.marks()) || undefined);
|
|
20
|
+
} else {
|
|
21
|
+
state.doc.nodesBetween($from.pos, $to.pos, function (currentNode) {
|
|
22
|
+
if (currentNode.isLeaf) {
|
|
23
|
+
var mark = textColor.isInSet(currentNode.marks) || undefined;
|
|
24
|
+
marks.push(mark);
|
|
25
|
+
return !mark;
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Merge consecutive same color marks
|
|
32
|
+
var prevMark;
|
|
33
|
+
marks = marks.filter(function (mark) {
|
|
34
|
+
if (mark && prevMark && mark.attrs.color === prevMark.attrs.color) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
prevMark = mark;
|
|
38
|
+
return true;
|
|
39
|
+
});
|
|
40
|
+
var marksWithColor = marks.filter(function (mark) {
|
|
41
|
+
return !!mark;
|
|
42
|
+
});
|
|
43
|
+
// When multiple colors are selected revert back to default color
|
|
44
|
+
if (marksWithColor.length > 1 || marksWithColor.length === 1 && marks.length > 1) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return marksWithColor.length ? marksWithColor[0].attrs.color : DEFAULT_COLOR.color;
|
|
48
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { isMarkAllowedInRange, isMarkExcluded } from '@atlaskit/editor-common/mark';
|
|
2
|
+
var hasLinkMark = function hasLinkMark($pos) {
|
|
3
|
+
var linkMarkType = $pos.doc.type.schema.marks.link,
|
|
4
|
+
pos = $pos.pos;
|
|
5
|
+
if (!linkMarkType) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
return $pos.doc.rangeHasMark(pos, Math.min(pos + 1, $pos.doc.content.size), linkMarkType);
|
|
9
|
+
};
|
|
10
|
+
export var getDisabledState = function getDisabledState(state) {
|
|
11
|
+
var textColor = state.schema.marks.textColor;
|
|
12
|
+
if (textColor) {
|
|
13
|
+
var _ref = state.selection,
|
|
14
|
+
empty = _ref.empty,
|
|
15
|
+
ranges = _ref.ranges,
|
|
16
|
+
$cursor = _ref.$cursor;
|
|
17
|
+
if (empty && !$cursor || $cursor && hasLinkMark($cursor) || isMarkAllowedInRange(state.doc, ranges, textColor) === false) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
if (isMarkExcluded(textColor, state.storedMarks || $cursor && $cursor.marks())) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TextColorPluginState } from './pm-plugins/main';
|
|
2
|
+
import { pluginKey as textColorPluginKey } from './pm-plugins/main';
|
|
3
|
+
import type { TextColorPlugin } from './types';
|
|
4
|
+
export declare const textColorPlugin: TextColorPlugin;
|
|
5
|
+
export { textColorPluginKey };
|
|
6
|
+
export type { TextColorPluginState };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
|
|
2
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
|
+
import type { PaletteColor } from '@atlaskit/editor-common/ui-color';
|
|
4
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
export { DEFAULT_COLOR } from '../utils/color';
|
|
6
|
+
export type TextColorPluginState = {
|
|
7
|
+
palette: Array<PaletteColor>;
|
|
8
|
+
defaultColor: string;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
color: string | null;
|
|
11
|
+
};
|
|
12
|
+
type TextColorDefaultColor = {
|
|
13
|
+
color: string;
|
|
14
|
+
label: string;
|
|
15
|
+
};
|
|
16
|
+
export interface TextColorPluginConfig {
|
|
17
|
+
defaultColor?: TextColorDefaultColor;
|
|
18
|
+
}
|
|
19
|
+
export declare enum ACTIONS {
|
|
20
|
+
RESET_COLOR = 0,
|
|
21
|
+
SET_COLOR = 1,
|
|
22
|
+
DISABLE = 2
|
|
23
|
+
}
|
|
24
|
+
export declare const pluginKey: PluginKey<TextColorPluginState>;
|
|
25
|
+
export declare function createPlugin(dispatch: Dispatch, pluginConfig?: TextColorPluginConfig): SafePlugin;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Command, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
3
|
+
import type { TextColorPluginConfig, TextColorPluginState } from './pm-plugins/main';
|
|
4
|
+
type Config = TextColorPluginConfig | boolean;
|
|
5
|
+
export type TextColorPluginDependencies = [OptionalPlugin<AnalyticsPlugin>];
|
|
6
|
+
export type TextColorPlugin = NextEditorPlugin<'textColor', {
|
|
7
|
+
pluginConfiguration: Config | undefined;
|
|
8
|
+
dependencies: TextColorPluginDependencies;
|
|
9
|
+
actions: {
|
|
10
|
+
changeColor: (color: string) => Command;
|
|
11
|
+
};
|
|
12
|
+
sharedState: TextColorPluginState | undefined;
|
|
13
|
+
}>;
|
|
14
|
+
export {};
|