@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
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @atlaskit/editor-plugin-text-color
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2023 Atlassian Pty Ltd
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Editor plugin text color
|
|
2
|
+
|
|
3
|
+
Text color plugin for @atlaskit/editor-core
|
|
4
|
+
|
|
5
|
+
**Note:** This component is designed for internal Atlassian development.
|
|
6
|
+
External contributors will be able to use this component but will not be able to submit issues.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
---
|
|
10
|
+
- **Install** - *yarn add @atlaskit/editor-plugin-text-color*
|
|
11
|
+
- **npm** - [@atlaskit/editor-plugin-text-color](https://www.npmjs.com/package/@atlaskit/editor-plugin-text-color)
|
|
12
|
+
- **Source** - [Bitbucket](https://bitbucket.org/atlassian/atlassian-frontend/src/master/packages/editor/editor-plugin-text-color)
|
|
13
|
+
- **Bundle** - [unpkg.com](https://unpkg.com/@atlaskit/editor-plugin-text-color/dist/)
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
---
|
|
17
|
+
**Internal use only**
|
|
18
|
+
|
|
19
|
+
@atlaskit/editor-plugin-text-color is intended for internal use by the @atlaskit/editor-core and as a plugin dependency of the Editor within your product.
|
|
20
|
+
|
|
21
|
+
Direct use of this component is not supported.
|
|
22
|
+
|
|
23
|
+
Please see [Atlaskit - Editor plugin text color](https://atlaskit.atlassian.com/packages/editor/editor-plugin-text-color) for documentation and examples for this package.
|
|
24
|
+
|
|
25
|
+
## Support
|
|
26
|
+
---
|
|
27
|
+
For internal Atlassian, visit the slack channel [#help-editor](https://atlassian.slack.com/archives/CFG3PSQ9E) for support or visit [go/editor-help](https://go/editor-help) to submit a bug.
|
|
28
|
+
## License
|
|
29
|
+
---
|
|
30
|
+
Please see [Atlassian Frontend - License](https://hello.atlassian.net/wiki/spaces/AF/pages/2589099144/Documentation#License) for more licensing information.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.changeColor = void 0;
|
|
7
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
8
|
+
var _editorAnalytics = require("@atlaskit/editor-common/editor-analytics");
|
|
9
|
+
var _main = require("../pm-plugins/main");
|
|
10
|
+
var _color = require("../utils/color");
|
|
11
|
+
var _removeColor = require("./remove-color");
|
|
12
|
+
var _toggleColor = require("./toggle-color");
|
|
13
|
+
/**
|
|
14
|
+
* Helper to create a higher order analytics command
|
|
15
|
+
* @param newColor - Color to be change in hex code
|
|
16
|
+
* @param previousColor - Active color in hex code
|
|
17
|
+
* @param palette - Current palette of colors
|
|
18
|
+
* @return Higher order command with analytics logic inside.
|
|
19
|
+
*/
|
|
20
|
+
function createWithColorAnalytics(newColor, previousColor, palette, editorAnalyticsApi) {
|
|
21
|
+
var newColorFromPalette = palette.find(function (_ref) {
|
|
22
|
+
var value = _ref.value;
|
|
23
|
+
return value === newColor;
|
|
24
|
+
});
|
|
25
|
+
var previousColorFromPalette = palette.find(function (_ref2) {
|
|
26
|
+
var value = _ref2.value;
|
|
27
|
+
return value === previousColor;
|
|
28
|
+
});
|
|
29
|
+
var newColorLabel = newColorFromPalette ? newColorFromPalette.label : newColor;
|
|
30
|
+
var previousColorLabel = previousColorFromPalette ? previousColorFromPalette.label : previousColor || '';
|
|
31
|
+
return (0, _editorAnalytics.withAnalytics)(editorAnalyticsApi, {
|
|
32
|
+
action: _analytics.ACTION.FORMATTED,
|
|
33
|
+
actionSubject: _analytics.ACTION_SUBJECT.TEXT,
|
|
34
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.FORMAT_COLOR,
|
|
35
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
36
|
+
attributes: {
|
|
37
|
+
newColor: newColorLabel.toLowerCase(),
|
|
38
|
+
previousColor: previousColorLabel.toLowerCase()
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
var changeColor = exports.changeColor = function changeColor(color, editorAnalyticsApi) {
|
|
43
|
+
return function (state, dispatch) {
|
|
44
|
+
var textColor = state.schema.marks.textColor;
|
|
45
|
+
if (textColor) {
|
|
46
|
+
var pluginState = _main.pluginKey.getState(state);
|
|
47
|
+
var activeColor = (0, _color.getActiveColor)(state);
|
|
48
|
+
var withColorAnalytics = createWithColorAnalytics(color, activeColor, (pluginState === null || pluginState === void 0 ? void 0 : pluginState.palette) || [], editorAnalyticsApi);
|
|
49
|
+
if (pluginState !== null && pluginState !== void 0 && pluginState.disabled) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if (color === (pluginState === null || pluginState === void 0 ? void 0 : pluginState.defaultColor)) {
|
|
53
|
+
withColorAnalytics((0, _removeColor.removeColor)())(state, dispatch);
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
withColorAnalytics((0, _toggleColor.toggleColor)(color))(state, dispatch);
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.removeColor = void 0;
|
|
7
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
8
|
+
var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
|
|
9
|
+
var _main = require("../pm-plugins/main");
|
|
10
|
+
var removeColor = exports.removeColor = function removeColor() {
|
|
11
|
+
return function (state, dispatch) {
|
|
12
|
+
var schema = state.schema,
|
|
13
|
+
selection = state.selection;
|
|
14
|
+
var textColor = schema.marks.textColor;
|
|
15
|
+
var tr = state.tr;
|
|
16
|
+
if (selection instanceof _state.TextSelection) {
|
|
17
|
+
var from = selection.from,
|
|
18
|
+
to = selection.to,
|
|
19
|
+
$cursor = selection.$cursor;
|
|
20
|
+
if ($cursor) {
|
|
21
|
+
tr = state.tr.removeStoredMark(textColor);
|
|
22
|
+
} else {
|
|
23
|
+
tr = state.tr.removeMark(from, to, textColor);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (selection instanceof _cellSelection.CellSelection) {
|
|
27
|
+
/**
|
|
28
|
+
* This is a slight abstraction from `src/utils/commands.ts`
|
|
29
|
+
* The main difference is we can't toggle the default from another (since they are different marks),
|
|
30
|
+
* we want to remove all text color marks on the selection, so we slightly modify the cell selection
|
|
31
|
+
* part here.
|
|
32
|
+
*/
|
|
33
|
+
selection.forEachCell(function (cell, cellPos) {
|
|
34
|
+
var from = cellPos;
|
|
35
|
+
var to = cellPos + cell.nodeSize;
|
|
36
|
+
tr.doc.nodesBetween(tr.mapping.map(from), tr.mapping.map(to), function (node, pos) {
|
|
37
|
+
if (!node.isText) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// This is an issue when the user selects some text.
|
|
42
|
+
// We need to check if the current node position is less than the range selection from.
|
|
43
|
+
// If it’s true, that means we should apply the mark using the range selection,
|
|
44
|
+
// not the current node position.
|
|
45
|
+
var nodeBetweenFrom = Math.max(pos, tr.mapping.map(from));
|
|
46
|
+
var nodeBetweenTo = Math.min(pos + node.nodeSize, tr.mapping.map(to));
|
|
47
|
+
tr.removeMark(nodeBetweenFrom, nodeBetweenTo, textColor);
|
|
48
|
+
return true;
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (dispatch) {
|
|
53
|
+
dispatch(tr.setMeta(_main.pluginKey, {
|
|
54
|
+
action: _main.ACTIONS.RESET_COLOR
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.toggleColor = void 0;
|
|
7
|
+
var _mark = require("@atlaskit/editor-common/mark");
|
|
8
|
+
var _preset = require("@atlaskit/editor-common/preset");
|
|
9
|
+
var _main = require("../pm-plugins/main");
|
|
10
|
+
var _disabled = require("../utils/disabled");
|
|
11
|
+
var toggleColor = exports.toggleColor = function toggleColor(color) {
|
|
12
|
+
return function (state, dispatch) {
|
|
13
|
+
var textColor = state.schema.marks.textColor;
|
|
14
|
+
var tr = state.tr;
|
|
15
|
+
var disabledState = (0, _disabled.getDisabledState)(state);
|
|
16
|
+
if (disabledState) {
|
|
17
|
+
if (dispatch) {
|
|
18
|
+
dispatch(tr.setMeta(_main.pluginKey, {
|
|
19
|
+
action: _main.ACTIONS.DISABLE
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
if (dispatch) {
|
|
25
|
+
state.tr.setMeta(_main.pluginKey, {
|
|
26
|
+
action: _main.ACTIONS.SET_COLOR,
|
|
27
|
+
color: color
|
|
28
|
+
});
|
|
29
|
+
state.tr.scrollIntoView();
|
|
30
|
+
(0, _preset.editorCommandToPMCommand)((0, _mark.toggleMark)(textColor, {
|
|
31
|
+
color: color
|
|
32
|
+
}))(state, dispatch);
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "textColorPlugin", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _plugin.textColorPlugin;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _plugin = require("./plugin");
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.textColorPlugin = void 0;
|
|
8
|
+
Object.defineProperty(exports, "textColorPluginKey", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function get() {
|
|
11
|
+
return _main.pluginKey;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
var _react = _interopRequireDefault(require("react"));
|
|
15
|
+
var _adfSchema = require("@atlaskit/adf-schema");
|
|
16
|
+
var _withPluginState = require("@atlaskit/editor-common/with-plugin-state");
|
|
17
|
+
var _changeColor2 = require("./commands/change-color");
|
|
18
|
+
var _main = require("./pm-plugins/main");
|
|
19
|
+
var _ToolbarTextColor = _interopRequireDefault(require("./ui/ToolbarTextColor"));
|
|
20
|
+
var pluginConfig = function pluginConfig(textColorConfig) {
|
|
21
|
+
if (!textColorConfig || typeof textColorConfig === 'boolean') {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
return textColorConfig;
|
|
25
|
+
};
|
|
26
|
+
var textColorPlugin = exports.textColorPlugin = function textColorPlugin(_ref) {
|
|
27
|
+
var textColorConfig = _ref.config,
|
|
28
|
+
api = _ref.api;
|
|
29
|
+
return {
|
|
30
|
+
name: 'textColor',
|
|
31
|
+
marks: function marks() {
|
|
32
|
+
return [{
|
|
33
|
+
name: 'textColor',
|
|
34
|
+
mark: _adfSchema.textColor
|
|
35
|
+
}];
|
|
36
|
+
},
|
|
37
|
+
pmPlugins: function pmPlugins() {
|
|
38
|
+
return [{
|
|
39
|
+
name: 'textColor',
|
|
40
|
+
plugin: function plugin(_ref2) {
|
|
41
|
+
var dispatch = _ref2.dispatch;
|
|
42
|
+
return (0, _main.createPlugin)(dispatch, pluginConfig(textColorConfig));
|
|
43
|
+
}
|
|
44
|
+
}];
|
|
45
|
+
},
|
|
46
|
+
getSharedState: function getSharedState(editorState) {
|
|
47
|
+
if (!editorState) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
return _main.pluginKey.getState(editorState);
|
|
51
|
+
},
|
|
52
|
+
actions: {
|
|
53
|
+
changeColor: function changeColor(color) {
|
|
54
|
+
var _api$analytics;
|
|
55
|
+
return (0, _changeColor2.changeColor)(color, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
primaryToolbarComponent: function primaryToolbarComponent(_ref3) {
|
|
59
|
+
var editorView = _ref3.editorView,
|
|
60
|
+
popupsMountPoint = _ref3.popupsMountPoint,
|
|
61
|
+
popupsBoundariesElement = _ref3.popupsBoundariesElement,
|
|
62
|
+
popupsScrollableElement = _ref3.popupsScrollableElement,
|
|
63
|
+
isToolbarReducedSpacing = _ref3.isToolbarReducedSpacing,
|
|
64
|
+
dispatchAnalyticsEvent = _ref3.dispatchAnalyticsEvent,
|
|
65
|
+
disabled = _ref3.disabled;
|
|
66
|
+
return /*#__PURE__*/_react.default.createElement(_withPluginState.WithPluginState, {
|
|
67
|
+
plugins: {
|
|
68
|
+
textColor: _main.pluginKey
|
|
69
|
+
},
|
|
70
|
+
render: function render(_ref4) {
|
|
71
|
+
var textColor = _ref4.textColor;
|
|
72
|
+
return /*#__PURE__*/_react.default.createElement(_ToolbarTextColor.default, {
|
|
73
|
+
pluginState: textColor,
|
|
74
|
+
isReducedSpacing: isToolbarReducedSpacing,
|
|
75
|
+
editorView: editorView,
|
|
76
|
+
popupsMountPoint: popupsMountPoint,
|
|
77
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
78
|
+
popupsScrollableElement: popupsScrollableElement,
|
|
79
|
+
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
80
|
+
disabled: disabled,
|
|
81
|
+
pluginInjectionApi: api
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.ACTIONS = void 0;
|
|
8
|
+
Object.defineProperty(exports, "DEFAULT_COLOR", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function get() {
|
|
11
|
+
return _color.DEFAULT_COLOR;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
exports.createPlugin = createPlugin;
|
|
15
|
+
exports.pluginKey = void 0;
|
|
16
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
17
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
18
|
+
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
19
|
+
var _uiColor = require("@atlaskit/editor-common/ui-color");
|
|
20
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
21
|
+
var _color = require("../utils/color");
|
|
22
|
+
var _disabled = require("../utils/disabled");
|
|
23
|
+
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
|
+
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
|
+
function createInitialPluginState(editorState, pluginConfig) {
|
|
26
|
+
var defaultColor = (pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.defaultColor) || _color.DEFAULT_COLOR;
|
|
27
|
+
var palette = [{
|
|
28
|
+
value: defaultColor.color,
|
|
29
|
+
label: defaultColor.label,
|
|
30
|
+
border: _uiColor.DEFAULT_BORDER_COLOR
|
|
31
|
+
}].concat((0, _toConsumableArray2.default)(_uiColor.textColorPalette));
|
|
32
|
+
var state = {
|
|
33
|
+
color: (0, _color.getActiveColor)(editorState),
|
|
34
|
+
disabled: (0, _disabled.getDisabledState)(editorState),
|
|
35
|
+
palette: palette,
|
|
36
|
+
defaultColor: defaultColor.color
|
|
37
|
+
};
|
|
38
|
+
return state;
|
|
39
|
+
}
|
|
40
|
+
var ACTIONS = exports.ACTIONS = /*#__PURE__*/function (ACTIONS) {
|
|
41
|
+
ACTIONS[ACTIONS["RESET_COLOR"] = 0] = "RESET_COLOR";
|
|
42
|
+
ACTIONS[ACTIONS["SET_COLOR"] = 1] = "SET_COLOR";
|
|
43
|
+
ACTIONS[ACTIONS["DISABLE"] = 2] = "DISABLE";
|
|
44
|
+
return ACTIONS;
|
|
45
|
+
}({});
|
|
46
|
+
var pluginKey = exports.pluginKey = new _state.PluginKey('textColorPlugin');
|
|
47
|
+
function createPlugin(dispatch, pluginConfig) {
|
|
48
|
+
return new _safePlugin.SafePlugin({
|
|
49
|
+
key: pluginKey,
|
|
50
|
+
state: {
|
|
51
|
+
init: function init(_config, editorState) {
|
|
52
|
+
return createInitialPluginState(editorState, pluginConfig);
|
|
53
|
+
},
|
|
54
|
+
apply: function apply(tr, pluginState, _, newState) {
|
|
55
|
+
var meta = tr.getMeta(pluginKey) || {};
|
|
56
|
+
var nextState;
|
|
57
|
+
switch (meta.action) {
|
|
58
|
+
case ACTIONS.RESET_COLOR:
|
|
59
|
+
nextState = _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
60
|
+
color: pluginState.defaultColor
|
|
61
|
+
});
|
|
62
|
+
break;
|
|
63
|
+
case ACTIONS.SET_COLOR:
|
|
64
|
+
nextState = _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
65
|
+
color: meta.color,
|
|
66
|
+
disabled: false
|
|
67
|
+
});
|
|
68
|
+
break;
|
|
69
|
+
case ACTIONS.DISABLE:
|
|
70
|
+
nextState = _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
71
|
+
disabled: true
|
|
72
|
+
});
|
|
73
|
+
break;
|
|
74
|
+
default:
|
|
75
|
+
nextState = _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
76
|
+
color: (0, _color.getActiveColor)(newState),
|
|
77
|
+
disabled: (0, _disabled.getDisabledState)(newState)
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (pluginState && pluginState.color !== nextState.color || pluginState && pluginState.disabled !== nextState.disabled) {
|
|
81
|
+
dispatch(pluginKey, nextState);
|
|
82
|
+
return nextState;
|
|
83
|
+
}
|
|
84
|
+
return pluginState;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.EditorTextColorIcon = void 0;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _base = _interopRequireDefault(require("@atlaskit/icon/base"));
|
|
11
|
+
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
12
|
+
|
|
13
|
+
var textColorGlyph = function textColorGlyph(props) {
|
|
14
|
+
return /*#__PURE__*/_react.default.createElement("svg", (0, _extends2.default)({}, props, {
|
|
15
|
+
width: "24",
|
|
16
|
+
height: "24",
|
|
17
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
18
|
+
}), /*#__PURE__*/_react.default.createElement("path", {
|
|
19
|
+
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",
|
|
20
|
+
fill: "currentColor",
|
|
21
|
+
fillRule: "evenodd"
|
|
22
|
+
}));
|
|
23
|
+
};
|
|
24
|
+
var EditorTextColorIcon = exports.EditorTextColorIcon = function EditorTextColorIcon() {
|
|
25
|
+
return /*#__PURE__*/_react.default.createElement(_base.default, {
|
|
26
|
+
glyph: textColorGlyph,
|
|
27
|
+
label: ""
|
|
28
|
+
});
|
|
29
|
+
};
|