@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,296 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.messages = exports.default = exports.ToolbarTextColor = void 0;
|
|
8
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
11
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
12
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
13
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
+
var _react = _interopRequireDefault(require("react"));
|
|
16
|
+
var _react2 = require("@emotion/react");
|
|
17
|
+
var _reactIntlNext = require("react-intl-next");
|
|
18
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
19
|
+
var _styles = require("@atlaskit/editor-common/styles");
|
|
20
|
+
var _uiColor = require("@atlaskit/editor-common/ui-color");
|
|
21
|
+
var _uiMenu = require("@atlaskit/editor-common/ui-menu");
|
|
22
|
+
var _editorPalette = require("@atlaskit/editor-palette");
|
|
23
|
+
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
24
|
+
var _chevronDown = _interopRequireDefault(require("@atlaskit/icon/glyph/chevron-down"));
|
|
25
|
+
var _changeColor = require("../../commands/change-color");
|
|
26
|
+
var _icon = require("./icon");
|
|
27
|
+
var _styles2 = require("./styles");
|
|
28
|
+
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; }
|
|
29
|
+
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; }
|
|
30
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
31
|
+
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; } } /** @jsx jsx */
|
|
32
|
+
var EXPERIMENT_NAME = 'editor.toolbarTextColor.moreColors';
|
|
33
|
+
var EXPERIMENT_GROUP_CONTROL = 'control';
|
|
34
|
+
var messages = exports.messages = (0, _reactIntlNext.defineMessages)({
|
|
35
|
+
textColor: {
|
|
36
|
+
id: 'fabric.editor.textColor',
|
|
37
|
+
defaultMessage: 'Text color',
|
|
38
|
+
description: ''
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
42
|
+
var ToolbarTextColor = exports.ToolbarTextColor = /*#__PURE__*/function (_React$Component) {
|
|
43
|
+
(0, _inherits2.default)(ToolbarTextColor, _React$Component);
|
|
44
|
+
var _super = _createSuper(ToolbarTextColor);
|
|
45
|
+
function ToolbarTextColor() {
|
|
46
|
+
var _this;
|
|
47
|
+
(0, _classCallCheck2.default)(this, ToolbarTextColor);
|
|
48
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
49
|
+
args[_key] = arguments[_key];
|
|
50
|
+
}
|
|
51
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
52
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "state", {
|
|
53
|
+
isOpen: false,
|
|
54
|
+
isOpenedByKeyboard: false
|
|
55
|
+
});
|
|
56
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "toolbarItemRef", /*#__PURE__*/_react.default.createRef());
|
|
57
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "changeColor", function (color, editorAnalyticsApi) {
|
|
58
|
+
return (0, _changeColor.changeColor)(color, editorAnalyticsApi)(_this.props.editorView.state, _this.props.editorView.dispatch);
|
|
59
|
+
});
|
|
60
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onOpenChange", function (attrs) {
|
|
61
|
+
_this.handleOpenChange({
|
|
62
|
+
isOpen: attrs.isOpen,
|
|
63
|
+
logCloseEvent: true,
|
|
64
|
+
event: attrs.event
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "changeTextColor", function (color, editorAnalyticsApi, disabled) {
|
|
68
|
+
if (!disabled) {
|
|
69
|
+
var _this$props$editorVie;
|
|
70
|
+
var palette = _this.props.pluginState.palette;
|
|
71
|
+
|
|
72
|
+
// we store color names in analytics
|
|
73
|
+
var swatch = palette.find(function (sw) {
|
|
74
|
+
return sw.value === color;
|
|
75
|
+
});
|
|
76
|
+
_this.dispatchAnalyticsEvent(_this.buildAnalyticsSelectColor({
|
|
77
|
+
color: (swatch ? swatch.label : color).toLowerCase()
|
|
78
|
+
}));
|
|
79
|
+
_this.handleOpenChange({
|
|
80
|
+
isOpen: false,
|
|
81
|
+
logCloseEvent: false
|
|
82
|
+
});
|
|
83
|
+
_this.changeColor(color, editorAnalyticsApi);
|
|
84
|
+
//To set the focus on the textcolor button when the menu is closed by 'Esc' only to meet aria guidelines
|
|
85
|
+
(_this$props$editorVie = _this.props.editorView) === null || _this$props$editorVie === void 0 || _this$props$editorVie.focus();
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
});
|
|
89
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "toggleOpen", function () {
|
|
90
|
+
_this.handleOpenChange({
|
|
91
|
+
isOpen: !_this.state.isOpen,
|
|
92
|
+
logCloseEvent: true
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onKeyDown", function (event) {
|
|
96
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
_this.setState({
|
|
99
|
+
isOpenedByKeyboard: true
|
|
100
|
+
});
|
|
101
|
+
_this.toggleOpen();
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleOpenChange", function (_ref) {
|
|
105
|
+
var isOpen = _ref.isOpen,
|
|
106
|
+
logCloseEvent = _ref.logCloseEvent,
|
|
107
|
+
event = _ref.event;
|
|
108
|
+
_this.setState({
|
|
109
|
+
isOpen: isOpen
|
|
110
|
+
});
|
|
111
|
+
if (!isOpen) {
|
|
112
|
+
_this.setState({
|
|
113
|
+
isOpenedByKeyboard: false
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
if (logCloseEvent) {
|
|
117
|
+
_this.dispatchAnalyticsEvent(_this.buildAnalyticsPalette(isOpen ? _analytics.ACTION.OPENED : _analytics.ACTION.CLOSED, {
|
|
118
|
+
noSelect: isOpen === false
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
if (!isOpen && event instanceof KeyboardEvent && (event === null || event === void 0 ? void 0 : event.key) === 'Escape') {
|
|
122
|
+
var _this$toolbarItemRef;
|
|
123
|
+
(_this$toolbarItemRef = _this.toolbarItemRef) === null || _this$toolbarItemRef === void 0 || (_this$toolbarItemRef = _this$toolbarItemRef.current) === null || _this$toolbarItemRef === void 0 || _this$toolbarItemRef.focus();
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "hide", function (e) {
|
|
127
|
+
var isOpen = _this.state.isOpen;
|
|
128
|
+
if (isOpen === true) {
|
|
129
|
+
_this.dispatchAnalyticsEvent(_this.buildAnalyticsPalette(_analytics.ACTION.CLOSED, {
|
|
130
|
+
noSelect: true
|
|
131
|
+
}));
|
|
132
|
+
_this.setState({
|
|
133
|
+
isOpen: false
|
|
134
|
+
});
|
|
135
|
+
if (e instanceof KeyboardEvent && e.key === 'Escape') {
|
|
136
|
+
var _this$toolbarItemRef2;
|
|
137
|
+
(_this$toolbarItemRef2 = _this.toolbarItemRef) === null || _this$toolbarItemRef2 === void 0 || (_this$toolbarItemRef2 = _this$toolbarItemRef2.current) === null || _this$toolbarItemRef2 === void 0 || _this$toolbarItemRef2.focus();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "hideonEsc", function (e) {
|
|
142
|
+
var _this$toolbarItemRef3;
|
|
143
|
+
_this.hide(e);
|
|
144
|
+
(_this$toolbarItemRef3 = _this.toolbarItemRef) === null || _this$toolbarItemRef3 === void 0 || (_this$toolbarItemRef3 = _this$toolbarItemRef3.current) === null || _this$toolbarItemRef3 === void 0 || _this$toolbarItemRef3.focus();
|
|
145
|
+
});
|
|
146
|
+
return _this;
|
|
147
|
+
}
|
|
148
|
+
(0, _createClass2.default)(ToolbarTextColor, [{
|
|
149
|
+
key: "render",
|
|
150
|
+
value: function render() {
|
|
151
|
+
var _this2 = this;
|
|
152
|
+
var _this$state = this.state,
|
|
153
|
+
isOpen = _this$state.isOpen,
|
|
154
|
+
isOpenedByKeyboard = _this$state.isOpenedByKeyboard;
|
|
155
|
+
var _this$props = this.props,
|
|
156
|
+
popupsMountPoint = _this$props.popupsMountPoint,
|
|
157
|
+
popupsBoundariesElement = _this$props.popupsBoundariesElement,
|
|
158
|
+
popupsScrollableElement = _this$props.popupsScrollableElement,
|
|
159
|
+
isReducedSpacing = _this$props.isReducedSpacing,
|
|
160
|
+
pluginState = _this$props.pluginState,
|
|
161
|
+
formatMessage = _this$props.intl.formatMessage,
|
|
162
|
+
disabled = _this$props.disabled,
|
|
163
|
+
pluginInjectionApi = _this$props.pluginInjectionApi;
|
|
164
|
+
var labelTextColor = formatMessage(messages.textColor);
|
|
165
|
+
var palette = pluginState.palette;
|
|
166
|
+
var fitWidth;
|
|
167
|
+
if (document.body.clientWidth <= 740) {
|
|
168
|
+
// This was originally hard-coded, but moved here to a const
|
|
169
|
+
// My guess is it's based off (width of button * columns) + left/right padding
|
|
170
|
+
// 240 = (32 * 7) + (8 + 8)
|
|
171
|
+
// Not sure where the extra 2px comes from
|
|
172
|
+
fitWidth = 242;
|
|
173
|
+
}
|
|
174
|
+
var selectedColor = this.getSelectedColor(pluginState);
|
|
175
|
+
var _getSelectedRowAndCol = (0, _uiColor.getSelectedRowAndColumnFromPalette)(palette, pluginState.color),
|
|
176
|
+
selectedRowIndex = _getSelectedRowAndCol.selectedRowIndex,
|
|
177
|
+
selectedColumnIndex = _getSelectedRowAndCol.selectedColumnIndex;
|
|
178
|
+
return (
|
|
179
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
180
|
+
(0, _react2.jsx)("span", {
|
|
181
|
+
css: _styles.wrapperStyle
|
|
182
|
+
}, (0, _react2.jsx)(_uiMenu.DropdownContainer, {
|
|
183
|
+
mountTo: popupsMountPoint,
|
|
184
|
+
boundariesElement: popupsBoundariesElement,
|
|
185
|
+
scrollableElement: popupsScrollableElement,
|
|
186
|
+
isOpen: isOpen && !pluginState.disabled,
|
|
187
|
+
handleClickOutside: this.hide,
|
|
188
|
+
handleEscapeKeydown: this.hideonEsc,
|
|
189
|
+
zIndex: _editorSharedStyles.akEditorMenuZIndex,
|
|
190
|
+
fitWidth: fitWidth,
|
|
191
|
+
onOpenChange: this.onOpenChange,
|
|
192
|
+
closeOnTab: true,
|
|
193
|
+
arrowKeyNavigationProviderOptions: {
|
|
194
|
+
type: _uiMenu.ArrowKeyNavigationType.COLOR,
|
|
195
|
+
selectedRowIndex: selectedRowIndex,
|
|
196
|
+
selectedColumnIndex: selectedColumnIndex,
|
|
197
|
+
isOpenedByKeyboard: isOpenedByKeyboard,
|
|
198
|
+
isPopupPositioned: true
|
|
199
|
+
},
|
|
200
|
+
trigger: (0, _react2.jsx)(_uiMenu.ToolbarButton, {
|
|
201
|
+
buttonId: _uiMenu.TOOLBAR_BUTTON.TEXT_COLOR,
|
|
202
|
+
spacing: isReducedSpacing ? 'none' : 'default',
|
|
203
|
+
disabled: disabled || pluginState.disabled,
|
|
204
|
+
selected: isOpen,
|
|
205
|
+
"aria-label": labelTextColor,
|
|
206
|
+
"aria-expanded": isOpen,
|
|
207
|
+
"aria-haspopup": true,
|
|
208
|
+
title: labelTextColor,
|
|
209
|
+
onClick: this.toggleOpen,
|
|
210
|
+
onKeyDown: this.onKeyDown,
|
|
211
|
+
ref: this.toolbarItemRef,
|
|
212
|
+
iconBefore:
|
|
213
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
214
|
+
(0, _react2.jsx)("div", {
|
|
215
|
+
css: _styles.triggerWrapperStyles
|
|
216
|
+
}, (0, _react2.jsx)("div", {
|
|
217
|
+
css: _styles2.textColorIconWrapper
|
|
218
|
+
}, (0, _react2.jsx)(_icon.EditorTextColorIcon, null), (0, _react2.jsx)("div", {
|
|
219
|
+
css: [
|
|
220
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
221
|
+
_styles2.textColorIconBar, selectedColor ? // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
222
|
+
"background: ".concat(selectedColor, ";") :
|
|
223
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
224
|
+
pluginState.disabled && _styles2.backgroundDisabled]
|
|
225
|
+
})), (0, _react2.jsx)("span", {
|
|
226
|
+
css: _styles.expandIconWrapperStyle
|
|
227
|
+
}, (0, _react2.jsx)(_chevronDown.default, {
|
|
228
|
+
label: ""
|
|
229
|
+
})))
|
|
230
|
+
})
|
|
231
|
+
}, (0, _react2.jsx)("div", {
|
|
232
|
+
"data-testid": "text-color-palette"
|
|
233
|
+
}, (0, _react2.jsx)(_uiColor.ColorPalette, {
|
|
234
|
+
onClick: function onClick(color) {
|
|
235
|
+
var _pluginInjectionApi$a;
|
|
236
|
+
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);
|
|
237
|
+
},
|
|
238
|
+
selectedColor: pluginState.color,
|
|
239
|
+
paletteOptions: {
|
|
240
|
+
palette: palette,
|
|
241
|
+
hexToPaletteColor: _editorPalette.hexToEditorTextPaletteColor,
|
|
242
|
+
paletteColorTooltipMessages: _uiColor.textPaletteTooltipMessages
|
|
243
|
+
}
|
|
244
|
+
}))), (0, _react2.jsx)("span", {
|
|
245
|
+
css: _styles.separatorStyles
|
|
246
|
+
}))
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
}, {
|
|
250
|
+
key: "getSelectedColor",
|
|
251
|
+
value: function getSelectedColor(pluginState) {
|
|
252
|
+
var selectedColor = pluginState.color !== pluginState.defaultColor && (pluginState.color ? (0, _editorPalette.hexToEditorTextPaletteColor)(pluginState.color) : pluginState.color);
|
|
253
|
+
return selectedColor;
|
|
254
|
+
}
|
|
255
|
+
}, {
|
|
256
|
+
key: "getCommonAnalyticsAttributes",
|
|
257
|
+
value: function getCommonAnalyticsAttributes() {
|
|
258
|
+
return {
|
|
259
|
+
experiment: EXPERIMENT_NAME,
|
|
260
|
+
experimentGroup: EXPERIMENT_GROUP_CONTROL
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
}, {
|
|
264
|
+
key: "buildAnalyticsPalette",
|
|
265
|
+
value: function buildAnalyticsPalette(action, data) {
|
|
266
|
+
return {
|
|
267
|
+
action: action,
|
|
268
|
+
actionSubject: _analytics.ACTION_SUBJECT.TOOLBAR,
|
|
269
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.FORMAT_COLOR,
|
|
270
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
271
|
+
attributes: _objectSpread(_objectSpread({}, this.getCommonAnalyticsAttributes()), data)
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
}, {
|
|
275
|
+
key: "buildAnalyticsSelectColor",
|
|
276
|
+
value: function buildAnalyticsSelectColor(data) {
|
|
277
|
+
return {
|
|
278
|
+
action: _analytics.ACTION.FORMATTED,
|
|
279
|
+
actionSubject: _analytics.ACTION_SUBJECT.TEXT,
|
|
280
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.FORMAT_COLOR,
|
|
281
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
282
|
+
attributes: _objectSpread(_objectSpread({}, this.getCommonAnalyticsAttributes()), data)
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
}, {
|
|
286
|
+
key: "dispatchAnalyticsEvent",
|
|
287
|
+
value: function dispatchAnalyticsEvent(payload) {
|
|
288
|
+
var dispatchAnalyticsEvent = this.props.dispatchAnalyticsEvent;
|
|
289
|
+
if (dispatchAnalyticsEvent) {
|
|
290
|
+
dispatchAnalyticsEvent(payload);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}]);
|
|
294
|
+
return ToolbarTextColor;
|
|
295
|
+
}(_react.default.Component);
|
|
296
|
+
var _default = exports.default = (0, _reactIntlNext.injectIntl)(ToolbarTextColor);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.textColorIconWrapper = exports.textColorIconBar = exports.backgroundDisabled = void 0;
|
|
8
|
+
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
9
|
+
var _react = require("@emotion/react");
|
|
10
|
+
var _colors = require("@atlaskit/theme/colors");
|
|
11
|
+
var _constants = require("@atlaskit/theme/constants");
|
|
12
|
+
var _templateObject, _templateObject2, _templateObject3;
|
|
13
|
+
var createSteppedRainbow = function createSteppedRainbow(colors) {
|
|
14
|
+
return "\n linear-gradient(\n to right,\n ".concat(colors.map(function (color, i) {
|
|
15
|
+
var inc = 100 / colors.length;
|
|
16
|
+
var pos = i + 1;
|
|
17
|
+
if (i === 0) {
|
|
18
|
+
return "".concat(color, " ").concat(pos * inc, "%,");
|
|
19
|
+
}
|
|
20
|
+
if (i === colors.length - 1) {
|
|
21
|
+
return "".concat(color, " ").concat((pos - 1) * inc, "%");
|
|
22
|
+
}
|
|
23
|
+
return "\n ".concat(color, " ").concat((pos - 1) * inc, "%,\n ").concat(color, " ").concat(pos * inc, "%,\n ");
|
|
24
|
+
}).join('\n'), "\n );\n ");
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// TODO: https://product-fabric.atlassian.net/browse/DSP-4137
|
|
28
|
+
/* eslint-disable @atlaskit/design-system/ensure-design-token-usage */
|
|
29
|
+
var rainbow = createSteppedRainbow([_colors.P300, _colors.T300, _colors.Y400, _colors.R400]);
|
|
30
|
+
var disabledRainbow = createSteppedRainbow([_colors.N80, _colors.N60, _colors.N40, _colors.N60]);
|
|
31
|
+
/* eslint-enable @atlaskit/design-system/ensure-design-token-usage */
|
|
32
|
+
|
|
33
|
+
var textColorIconWrapper = exports.textColorIconWrapper = (0, _react.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n position: relative;\n"])));
|
|
34
|
+
var textColorIconBar = exports.textColorIconBar = (0, _react.css)(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2.default)(["\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)", (0, _constants.borderRadius)() + 'px', rainbow);
|
|
35
|
+
var backgroundDisabled = exports.backgroundDisabled = (0, _react.css)(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2.default)(["\n background: ", ";\n"])), disabledRainbow);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
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
|
+
};
|
|
14
|
+
var getActiveColor = exports.getActiveColor = function getActiveColor(state) {
|
|
15
|
+
var _ref = state.selection,
|
|
16
|
+
$from = _ref.$from,
|
|
17
|
+
$to = _ref.$to,
|
|
18
|
+
$cursor = _ref.$cursor;
|
|
19
|
+
var _ref2 = state.schema.marks,
|
|
20
|
+
textColor = _ref2.textColor;
|
|
21
|
+
|
|
22
|
+
// Filter out other marks
|
|
23
|
+
var marks = [];
|
|
24
|
+
if ($cursor) {
|
|
25
|
+
marks.push(textColor.isInSet(state.storedMarks || $cursor.marks()) || undefined);
|
|
26
|
+
} else {
|
|
27
|
+
state.doc.nodesBetween($from.pos, $to.pos, function (currentNode) {
|
|
28
|
+
if (currentNode.isLeaf) {
|
|
29
|
+
var mark = textColor.isInSet(currentNode.marks) || undefined;
|
|
30
|
+
marks.push(mark);
|
|
31
|
+
return !mark;
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Merge consecutive same color marks
|
|
38
|
+
var prevMark;
|
|
39
|
+
marks = marks.filter(function (mark) {
|
|
40
|
+
if (mark && prevMark && mark.attrs.color === prevMark.attrs.color) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
prevMark = mark;
|
|
44
|
+
return true;
|
|
45
|
+
});
|
|
46
|
+
var marksWithColor = marks.filter(function (mark) {
|
|
47
|
+
return !!mark;
|
|
48
|
+
});
|
|
49
|
+
// When multiple colors are selected revert back to default color
|
|
50
|
+
if (marksWithColor.length > 1 || marksWithColor.length === 1 && marks.length > 1) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
return marksWithColor.length ? marksWithColor[0].attrs.color : DEFAULT_COLOR.color;
|
|
54
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
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 hasLinkMark = function hasLinkMark($pos) {
|
|
9
|
+
var linkMarkType = $pos.doc.type.schema.marks.link,
|
|
10
|
+
pos = $pos.pos;
|
|
11
|
+
if (!linkMarkType) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
return $pos.doc.rangeHasMark(pos, Math.min(pos + 1, $pos.doc.content.size), linkMarkType);
|
|
15
|
+
};
|
|
16
|
+
var getDisabledState = exports.getDisabledState = function getDisabledState(state) {
|
|
17
|
+
var textColor = state.schema.marks.textColor;
|
|
18
|
+
if (textColor) {
|
|
19
|
+
var _ref = state.selection,
|
|
20
|
+
empty = _ref.empty,
|
|
21
|
+
ranges = _ref.ranges,
|
|
22
|
+
$cursor = _ref.$cursor;
|
|
23
|
+
if (empty && !$cursor || $cursor && hasLinkMark($cursor) || (0, _mark.isMarkAllowedInRange)(state.doc, ranges, textColor) === false) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
if ((0, _mark.isMarkExcluded)(textColor, state.storedMarks || $cursor && $cursor.marks())) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
|
|
3
|
+
import { pluginKey } from '../pm-plugins/main';
|
|
4
|
+
import { getActiveColor } from '../utils/color';
|
|
5
|
+
import { removeColor } from './remove-color';
|
|
6
|
+
import { toggleColor } from './toggle-color';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Helper to create a higher order analytics command
|
|
10
|
+
* @param newColor - Color to be change in hex code
|
|
11
|
+
* @param previousColor - Active color in hex code
|
|
12
|
+
* @param palette - Current palette of colors
|
|
13
|
+
* @return Higher order command with analytics logic inside.
|
|
14
|
+
*/
|
|
15
|
+
function createWithColorAnalytics(newColor, previousColor, palette, editorAnalyticsApi) {
|
|
16
|
+
const newColorFromPalette = palette.find(({
|
|
17
|
+
value
|
|
18
|
+
}) => value === newColor);
|
|
19
|
+
const previousColorFromPalette = palette.find(({
|
|
20
|
+
value
|
|
21
|
+
}) => value === previousColor);
|
|
22
|
+
const newColorLabel = newColorFromPalette ? newColorFromPalette.label : newColor;
|
|
23
|
+
const previousColorLabel = previousColorFromPalette ? previousColorFromPalette.label : previousColor || '';
|
|
24
|
+
return withAnalytics(editorAnalyticsApi, {
|
|
25
|
+
action: ACTION.FORMATTED,
|
|
26
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
27
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_COLOR,
|
|
28
|
+
eventType: EVENT_TYPE.TRACK,
|
|
29
|
+
attributes: {
|
|
30
|
+
newColor: newColorLabel.toLowerCase(),
|
|
31
|
+
previousColor: previousColorLabel.toLowerCase()
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
export const changeColor = (color, editorAnalyticsApi) => (state, dispatch) => {
|
|
36
|
+
const {
|
|
37
|
+
textColor
|
|
38
|
+
} = state.schema.marks;
|
|
39
|
+
if (textColor) {
|
|
40
|
+
const pluginState = pluginKey.getState(state);
|
|
41
|
+
const activeColor = getActiveColor(state);
|
|
42
|
+
const withColorAnalytics = createWithColorAnalytics(color, activeColor, (pluginState === null || pluginState === void 0 ? void 0 : pluginState.palette) || [], editorAnalyticsApi);
|
|
43
|
+
if (pluginState !== null && pluginState !== void 0 && pluginState.disabled) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
if (color === (pluginState === null || pluginState === void 0 ? void 0 : pluginState.defaultColor)) {
|
|
47
|
+
withColorAnalytics(removeColor())(state, dispatch);
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
withColorAnalytics(toggleColor(color))(state, dispatch);
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
3
|
+
import { ACTIONS, pluginKey } from '../pm-plugins/main';
|
|
4
|
+
export const removeColor = () => (state, dispatch) => {
|
|
5
|
+
const {
|
|
6
|
+
schema,
|
|
7
|
+
selection
|
|
8
|
+
} = state;
|
|
9
|
+
const {
|
|
10
|
+
textColor
|
|
11
|
+
} = schema.marks;
|
|
12
|
+
let tr = state.tr;
|
|
13
|
+
if (selection instanceof TextSelection) {
|
|
14
|
+
const {
|
|
15
|
+
from,
|
|
16
|
+
to,
|
|
17
|
+
$cursor
|
|
18
|
+
} = selection;
|
|
19
|
+
if ($cursor) {
|
|
20
|
+
tr = state.tr.removeStoredMark(textColor);
|
|
21
|
+
} else {
|
|
22
|
+
tr = state.tr.removeMark(from, to, textColor);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (selection instanceof CellSelection) {
|
|
26
|
+
/**
|
|
27
|
+
* This is a slight abstraction from `src/utils/commands.ts`
|
|
28
|
+
* The main difference is we can't toggle the default from another (since they are different marks),
|
|
29
|
+
* we want to remove all text color marks on the selection, so we slightly modify the cell selection
|
|
30
|
+
* part here.
|
|
31
|
+
*/
|
|
32
|
+
selection.forEachCell((cell, cellPos) => {
|
|
33
|
+
const from = cellPos;
|
|
34
|
+
const to = cellPos + cell.nodeSize;
|
|
35
|
+
tr.doc.nodesBetween(tr.mapping.map(from), tr.mapping.map(to), (node, pos) => {
|
|
36
|
+
if (!node.isText) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// This is an issue when the user selects some text.
|
|
41
|
+
// We need to check if the current node position is less than the range selection from.
|
|
42
|
+
// If it’s true, that means we should apply the mark using the range selection,
|
|
43
|
+
// not the current node position.
|
|
44
|
+
const nodeBetweenFrom = Math.max(pos, tr.mapping.map(from));
|
|
45
|
+
const nodeBetweenTo = Math.min(pos + node.nodeSize, tr.mapping.map(to));
|
|
46
|
+
tr.removeMark(nodeBetweenFrom, nodeBetweenTo, textColor);
|
|
47
|
+
return true;
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (dispatch) {
|
|
52
|
+
dispatch(tr.setMeta(pluginKey, {
|
|
53
|
+
action: ACTIONS.RESET_COLOR
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
57
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { toggleMark } from '@atlaskit/editor-common/mark';
|
|
2
|
+
import { editorCommandToPMCommand } from '@atlaskit/editor-common/preset';
|
|
3
|
+
import { ACTIONS, pluginKey } from '../pm-plugins/main';
|
|
4
|
+
import { getDisabledState } from '../utils/disabled';
|
|
5
|
+
export const toggleColor = color => (state, dispatch) => {
|
|
6
|
+
const {
|
|
7
|
+
textColor
|
|
8
|
+
} = state.schema.marks;
|
|
9
|
+
let tr = state.tr;
|
|
10
|
+
const disabledState = getDisabledState(state);
|
|
11
|
+
if (disabledState) {
|
|
12
|
+
if (dispatch) {
|
|
13
|
+
dispatch(tr.setMeta(pluginKey, {
|
|
14
|
+
action: ACTIONS.DISABLE
|
|
15
|
+
}));
|
|
16
|
+
}
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
if (dispatch) {
|
|
20
|
+
state.tr.setMeta(pluginKey, {
|
|
21
|
+
action: ACTIONS.SET_COLOR,
|
|
22
|
+
color
|
|
23
|
+
});
|
|
24
|
+
state.tr.scrollIntoView();
|
|
25
|
+
editorCommandToPMCommand(toggleMark(textColor, {
|
|
26
|
+
color
|
|
27
|
+
}))(state, dispatch);
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
30
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { textColorPlugin } from './plugin';
|
|
@@ -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 } from './commands/change-color';
|
|
5
|
+
import { createPlugin, pluginKey as textColorPluginKey } from './pm-plugins/main';
|
|
6
|
+
import ToolbarTextColor from './ui/ToolbarTextColor';
|
|
7
|
+
const pluginConfig = textColorConfig => {
|
|
8
|
+
if (!textColorConfig || typeof textColorConfig === 'boolean') {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
return textColorConfig;
|
|
12
|
+
};
|
|
13
|
+
export const textColorPlugin = ({
|
|
14
|
+
config: textColorConfig,
|
|
15
|
+
api
|
|
16
|
+
}) => {
|
|
17
|
+
return {
|
|
18
|
+
name: 'textColor',
|
|
19
|
+
marks() {
|
|
20
|
+
return [{
|
|
21
|
+
name: 'textColor',
|
|
22
|
+
mark: textColor
|
|
23
|
+
}];
|
|
24
|
+
},
|
|
25
|
+
pmPlugins() {
|
|
26
|
+
return [{
|
|
27
|
+
name: 'textColor',
|
|
28
|
+
plugin: ({
|
|
29
|
+
dispatch
|
|
30
|
+
}) => createPlugin(dispatch, pluginConfig(textColorConfig))
|
|
31
|
+
}];
|
|
32
|
+
},
|
|
33
|
+
getSharedState(editorState) {
|
|
34
|
+
if (!editorState) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
return textColorPluginKey.getState(editorState);
|
|
38
|
+
},
|
|
39
|
+
actions: {
|
|
40
|
+
changeColor: color => {
|
|
41
|
+
var _api$analytics;
|
|
42
|
+
return changeColor(color, api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
primaryToolbarComponent({
|
|
46
|
+
editorView,
|
|
47
|
+
popupsMountPoint,
|
|
48
|
+
popupsBoundariesElement,
|
|
49
|
+
popupsScrollableElement,
|
|
50
|
+
isToolbarReducedSpacing,
|
|
51
|
+
dispatchAnalyticsEvent,
|
|
52
|
+
disabled
|
|
53
|
+
}) {
|
|
54
|
+
return /*#__PURE__*/React.createElement(WithPluginState, {
|
|
55
|
+
plugins: {
|
|
56
|
+
textColor: textColorPluginKey
|
|
57
|
+
},
|
|
58
|
+
render: ({
|
|
59
|
+
textColor
|
|
60
|
+
}) => /*#__PURE__*/React.createElement(ToolbarTextColor, {
|
|
61
|
+
pluginState: textColor,
|
|
62
|
+
isReducedSpacing: isToolbarReducedSpacing,
|
|
63
|
+
editorView: editorView,
|
|
64
|
+
popupsMountPoint: popupsMountPoint,
|
|
65
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
66
|
+
popupsScrollableElement: popupsScrollableElement,
|
|
67
|
+
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
68
|
+
disabled: disabled,
|
|
69
|
+
pluginInjectionApi: api
|
|
70
|
+
})
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
export { textColorPluginKey };
|