@atlaskit/editor-common 116.23.0 → 116.23.1
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 +8 -0
- package/dist/cjs/ui-color/ColorPalette/utils.js +60 -2
- package/dist/cjs/ui-color/index.js +6 -0
- package/dist/es2019/ui-color/ColorPalette/utils.js +44 -1
- package/dist/es2019/ui-color/index.js +1 -1
- package/dist/esm/ui-color/ColorPalette/utils.js +58 -1
- package/dist/esm/ui-color/index.js +1 -1
- package/dist/types/ui-color/ColorPalette/utils.d.ts +1 -0
- package/dist/types/ui-color/index.d.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/editor-common
|
|
2
2
|
|
|
3
|
+
## 116.23.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`74b3e15fed77e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/74b3e15fed77e) -
|
|
8
|
+
Check editor text and highlight color accessibility against both light and dark theme variants.
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
3
11
|
## 116.23.0
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
@@ -12,13 +13,57 @@ Object.defineProperty(exports, "getSelectedRowAndColumn", {
|
|
|
12
13
|
}
|
|
13
14
|
});
|
|
14
15
|
exports.getSelectedRowAndColumnFromPalette = getSelectedRowAndColumnFromPalette;
|
|
15
|
-
exports.getTokenCSSVariableValue = void 0;
|
|
16
|
+
exports.getTokenCSSVariableValueForNonActiveTheme = exports.getTokenCSSVariableValue = void 0;
|
|
17
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
18
|
+
var _palettesRaw = _interopRequireDefault(require("@atlaskit/tokens/palettes-raw"));
|
|
19
|
+
var _tokenNames = _interopRequireDefault(require("@atlaskit/tokens/token-names"));
|
|
20
|
+
var _tokensRaw = require("@atlaskit/tokens/tokens-raw");
|
|
16
21
|
var _getSelectedRowAndColumn = require("./getSelectedRowAndColumn");
|
|
17
22
|
var DEFAULT_COLOR_PICKER_COLUMNS = exports.DEFAULT_COLOR_PICKER_COLUMNS = 7;
|
|
18
|
-
|
|
19
23
|
// Ignored via go/ees005
|
|
20
24
|
// eslint-disable-next-line require-unicode-regexp
|
|
21
25
|
var CSS_VAR_EXPRESSION_REGEX = /var\(([^,\)]+)(,.*)?\)/;
|
|
26
|
+
var getCSSVariableParts = function getCSSVariableParts(variableExpression) {
|
|
27
|
+
var matcher = variableExpression.match(CSS_VAR_EXPRESSION_REGEX);
|
|
28
|
+
if (!matcher) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
fallback: matcher[2] ? matcher[2].replace(',', '').trim() : '',
|
|
33
|
+
variable: matcher[1].trim()
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// Build the reverse lookup (CSS variable -> token name) once at module load so that
|
|
38
|
+
// each lookup is O(1) instead of O(n) with an extra array allocation per call.
|
|
39
|
+
var cssVariableToTokenName = new Map(Object.entries(_tokenNames.default).map(function (_ref) {
|
|
40
|
+
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
|
41
|
+
tokenName = _ref2[0],
|
|
42
|
+
cssVariable = _ref2[1];
|
|
43
|
+
return [cssVariable, tokenName];
|
|
44
|
+
}));
|
|
45
|
+
var getTokenName = function getTokenName(cssVariable) {
|
|
46
|
+
return cssVariableToTokenName.get(cssVariable);
|
|
47
|
+
};
|
|
48
|
+
var resolveRawTokenValue = function resolveRawTokenValue(value) {
|
|
49
|
+
var _paletteRaw$find;
|
|
50
|
+
if (typeof value !== 'string') {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
var paletteValue = (_paletteRaw$find = _palettesRaw.default.find(function (paletteToken) {
|
|
54
|
+
return paletteToken.path[paletteToken.path.length - 1] === value;
|
|
55
|
+
})) === null || _paletteRaw$find === void 0 ? void 0 : _paletteRaw$find.value;
|
|
56
|
+
return typeof paletteValue === 'string' ? paletteValue : value;
|
|
57
|
+
};
|
|
58
|
+
var getCurrentThemeMode = function getCurrentThemeMode() {
|
|
59
|
+
if (typeof document === 'undefined') {
|
|
60
|
+
return 'light';
|
|
61
|
+
}
|
|
62
|
+
return document.documentElement.getAttribute('data-color-mode') === 'dark' ? 'dark' : 'light';
|
|
63
|
+
};
|
|
64
|
+
var getNonActiveThemeMode = function getNonActiveThemeMode() {
|
|
65
|
+
return getCurrentThemeMode() === 'dark' ? 'light' : 'dark';
|
|
66
|
+
};
|
|
22
67
|
|
|
23
68
|
// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
|
|
24
69
|
function getColorsPerRowFromPalette(palette) {
|
|
@@ -52,4 +97,17 @@ var getTokenCSSVariableValue = exports.getTokenCSSVariableValue = function getTo
|
|
|
52
97
|
}
|
|
53
98
|
return '';
|
|
54
99
|
};
|
|
100
|
+
|
|
101
|
+
// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
|
|
102
|
+
var getTokenCSSVariableValueForNonActiveTheme = exports.getTokenCSSVariableValueForNonActiveTheme = function getTokenCSSVariableValueForNonActiveTheme(variableExpression, fallback) {
|
|
103
|
+
var cssVariableParts = getCSSVariableParts(variableExpression);
|
|
104
|
+
var tokenName = cssVariableParts ? getTokenName(cssVariableParts.variable) : undefined;
|
|
105
|
+
var rawToken = (getNonActiveThemeMode() === 'light' ? _tokensRaw.light : _tokensRaw.dark).find(function (token) {
|
|
106
|
+
return token.cleanName === tokenName;
|
|
107
|
+
});
|
|
108
|
+
if (rawToken) {
|
|
109
|
+
return resolveRawTokenValue(rawToken.value) || fallback;
|
|
110
|
+
}
|
|
111
|
+
return (cssVariableParts === null || cssVariableParts === void 0 ? void 0 : cssVariableParts.fallback) || fallback;
|
|
112
|
+
};
|
|
55
113
|
// eslint-disable-next-line @atlaskit/editor/no-re-export
|
|
@@ -100,6 +100,12 @@ Object.defineProperty(exports, "getTokenCSSVariableValue", {
|
|
|
100
100
|
return _utils.getTokenCSSVariableValue;
|
|
101
101
|
}
|
|
102
102
|
});
|
|
103
|
+
Object.defineProperty(exports, "getTokenCSSVariableValueForNonActiveTheme", {
|
|
104
|
+
enumerable: true,
|
|
105
|
+
get: function get() {
|
|
106
|
+
return _utils.getTokenCSSVariableValueForNonActiveTheme;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
103
109
|
Object.defineProperty(exports, "highlightColorPalette", {
|
|
104
110
|
enumerable: true,
|
|
105
111
|
get: function get() {
|
|
@@ -1,9 +1,41 @@
|
|
|
1
|
+
import paletteRaw from '@atlaskit/tokens/palettes-raw';
|
|
2
|
+
import tokenNames from '@atlaskit/tokens/token-names';
|
|
3
|
+
import { dark as darkTokensRaw, light as lightTokensRaw } from '@atlaskit/tokens/tokens-raw';
|
|
1
4
|
import { getSelectedRowAndColumn } from './getSelectedRowAndColumn';
|
|
2
5
|
export const DEFAULT_COLOR_PICKER_COLUMNS = 7;
|
|
3
|
-
|
|
4
6
|
// Ignored via go/ees005
|
|
5
7
|
// eslint-disable-next-line require-unicode-regexp
|
|
6
8
|
const CSS_VAR_EXPRESSION_REGEX = /var\(([^,\)]+)(,.*)?\)/;
|
|
9
|
+
const getCSSVariableParts = variableExpression => {
|
|
10
|
+
const matcher = variableExpression.match(CSS_VAR_EXPRESSION_REGEX);
|
|
11
|
+
if (!matcher) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
fallback: matcher[2] ? matcher[2].replace(',', '').trim() : '',
|
|
16
|
+
variable: matcher[1].trim()
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Build the reverse lookup (CSS variable -> token name) once at module load so that
|
|
21
|
+
// each lookup is O(1) instead of O(n) with an extra array allocation per call.
|
|
22
|
+
const cssVariableToTokenName = new Map(Object.entries(tokenNames).map(([tokenName, cssVariable]) => [cssVariable, tokenName]));
|
|
23
|
+
const getTokenName = cssVariable => cssVariableToTokenName.get(cssVariable);
|
|
24
|
+
const resolveRawTokenValue = value => {
|
|
25
|
+
var _paletteRaw$find;
|
|
26
|
+
if (typeof value !== 'string') {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
const paletteValue = (_paletteRaw$find = paletteRaw.find(paletteToken => paletteToken.path[paletteToken.path.length - 1] === value)) === null || _paletteRaw$find === void 0 ? void 0 : _paletteRaw$find.value;
|
|
30
|
+
return typeof paletteValue === 'string' ? paletteValue : value;
|
|
31
|
+
};
|
|
32
|
+
const getCurrentThemeMode = () => {
|
|
33
|
+
if (typeof document === 'undefined') {
|
|
34
|
+
return 'light';
|
|
35
|
+
}
|
|
36
|
+
return document.documentElement.getAttribute('data-color-mode') === 'dark' ? 'dark' : 'light';
|
|
37
|
+
};
|
|
38
|
+
const getNonActiveThemeMode = () => getCurrentThemeMode() === 'dark' ? 'light' : 'dark';
|
|
7
39
|
|
|
8
40
|
// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
|
|
9
41
|
export function getColorsPerRowFromPalette(palette, cols = DEFAULT_COLOR_PICKER_COLUMNS) {
|
|
@@ -35,5 +67,16 @@ export const getTokenCSSVariableValue = variableExpression => {
|
|
|
35
67
|
}
|
|
36
68
|
return '';
|
|
37
69
|
};
|
|
70
|
+
|
|
71
|
+
// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
|
|
72
|
+
export const getTokenCSSVariableValueForNonActiveTheme = (variableExpression, fallback) => {
|
|
73
|
+
const cssVariableParts = getCSSVariableParts(variableExpression);
|
|
74
|
+
const tokenName = cssVariableParts ? getTokenName(cssVariableParts.variable) : undefined;
|
|
75
|
+
const rawToken = (getNonActiveThemeMode() === 'light' ? lightTokensRaw : darkTokensRaw).find(token => token.cleanName === tokenName);
|
|
76
|
+
if (rawToken) {
|
|
77
|
+
return resolveRawTokenValue(rawToken.value) || fallback;
|
|
78
|
+
}
|
|
79
|
+
return (cssVariableParts === null || cssVariableParts === void 0 ? void 0 : cssVariableParts.fallback) || fallback;
|
|
80
|
+
};
|
|
38
81
|
// eslint-disable-next-line @atlaskit/editor/no-re-export
|
|
39
82
|
export { getSelectedRowAndColumn } from './getSelectedRowAndColumn';
|
|
@@ -6,7 +6,7 @@ export { default as Color } from './ColorPalette/Color';
|
|
|
6
6
|
export { SelectedTextColorProvider } from './ColorPalette/SelectedTextColorProvider';
|
|
7
7
|
export { useSelectedTextColor } from './ColorPalette/useSelectedTextColor';
|
|
8
8
|
export { getSelectedRowAndColumn } from './ColorPalette/getSelectedRowAndColumn';
|
|
9
|
-
export { DEFAULT_COLOR_PICKER_COLUMNS, getColorsPerRowFromPalette, getSelectedRowAndColumnFromPalette, getTokenCSSVariableValue } from './ColorPalette/utils';
|
|
9
|
+
export { DEFAULT_COLOR_PICKER_COLUMNS, getColorsPerRowFromPalette, getSelectedRowAndColumnFromPalette, getTokenCSSVariableValue, getTokenCSSVariableValueForNonActiveTheme } from './ColorPalette/utils';
|
|
10
10
|
export { default as cellBackgroundColorPalette } from './ColorPalette/Palettes/cellBackgroundColorPalette';
|
|
11
11
|
export { default as colorPaletteMessages } from './ColorPalette/Palettes/paletteMessages';
|
|
12
12
|
export { panelBackgroundPalette } from './ColorPalette/Palettes/panelBackgroundPalette';
|
|
@@ -1,9 +1,53 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import paletteRaw from '@atlaskit/tokens/palettes-raw';
|
|
3
|
+
import tokenNames from '@atlaskit/tokens/token-names';
|
|
4
|
+
import { dark as darkTokensRaw, light as lightTokensRaw } from '@atlaskit/tokens/tokens-raw';
|
|
1
5
|
import { getSelectedRowAndColumn } from './getSelectedRowAndColumn';
|
|
2
6
|
export var DEFAULT_COLOR_PICKER_COLUMNS = 7;
|
|
3
|
-
|
|
4
7
|
// Ignored via go/ees005
|
|
5
8
|
// eslint-disable-next-line require-unicode-regexp
|
|
6
9
|
var CSS_VAR_EXPRESSION_REGEX = /var\(([^,\)]+)(,.*)?\)/;
|
|
10
|
+
var getCSSVariableParts = function getCSSVariableParts(variableExpression) {
|
|
11
|
+
var matcher = variableExpression.match(CSS_VAR_EXPRESSION_REGEX);
|
|
12
|
+
if (!matcher) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
fallback: matcher[2] ? matcher[2].replace(',', '').trim() : '',
|
|
17
|
+
variable: matcher[1].trim()
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// Build the reverse lookup (CSS variable -> token name) once at module load so that
|
|
22
|
+
// each lookup is O(1) instead of O(n) with an extra array allocation per call.
|
|
23
|
+
var cssVariableToTokenName = new Map(Object.entries(tokenNames).map(function (_ref) {
|
|
24
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
25
|
+
tokenName = _ref2[0],
|
|
26
|
+
cssVariable = _ref2[1];
|
|
27
|
+
return [cssVariable, tokenName];
|
|
28
|
+
}));
|
|
29
|
+
var getTokenName = function getTokenName(cssVariable) {
|
|
30
|
+
return cssVariableToTokenName.get(cssVariable);
|
|
31
|
+
};
|
|
32
|
+
var resolveRawTokenValue = function resolveRawTokenValue(value) {
|
|
33
|
+
var _paletteRaw$find;
|
|
34
|
+
if (typeof value !== 'string') {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
var paletteValue = (_paletteRaw$find = paletteRaw.find(function (paletteToken) {
|
|
38
|
+
return paletteToken.path[paletteToken.path.length - 1] === value;
|
|
39
|
+
})) === null || _paletteRaw$find === void 0 ? void 0 : _paletteRaw$find.value;
|
|
40
|
+
return typeof paletteValue === 'string' ? paletteValue : value;
|
|
41
|
+
};
|
|
42
|
+
var getCurrentThemeMode = function getCurrentThemeMode() {
|
|
43
|
+
if (typeof document === 'undefined') {
|
|
44
|
+
return 'light';
|
|
45
|
+
}
|
|
46
|
+
return document.documentElement.getAttribute('data-color-mode') === 'dark' ? 'dark' : 'light';
|
|
47
|
+
};
|
|
48
|
+
var getNonActiveThemeMode = function getNonActiveThemeMode() {
|
|
49
|
+
return getCurrentThemeMode() === 'dark' ? 'light' : 'dark';
|
|
50
|
+
};
|
|
7
51
|
|
|
8
52
|
// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
|
|
9
53
|
export function getColorsPerRowFromPalette(palette) {
|
|
@@ -37,5 +81,18 @@ export var getTokenCSSVariableValue = function getTokenCSSVariableValue(variable
|
|
|
37
81
|
}
|
|
38
82
|
return '';
|
|
39
83
|
};
|
|
84
|
+
|
|
85
|
+
// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
|
|
86
|
+
export var getTokenCSSVariableValueForNonActiveTheme = function getTokenCSSVariableValueForNonActiveTheme(variableExpression, fallback) {
|
|
87
|
+
var cssVariableParts = getCSSVariableParts(variableExpression);
|
|
88
|
+
var tokenName = cssVariableParts ? getTokenName(cssVariableParts.variable) : undefined;
|
|
89
|
+
var rawToken = (getNonActiveThemeMode() === 'light' ? lightTokensRaw : darkTokensRaw).find(function (token) {
|
|
90
|
+
return token.cleanName === tokenName;
|
|
91
|
+
});
|
|
92
|
+
if (rawToken) {
|
|
93
|
+
return resolveRawTokenValue(rawToken.value) || fallback;
|
|
94
|
+
}
|
|
95
|
+
return (cssVariableParts === null || cssVariableParts === void 0 ? void 0 : cssVariableParts.fallback) || fallback;
|
|
96
|
+
};
|
|
40
97
|
// eslint-disable-next-line @atlaskit/editor/no-re-export
|
|
41
98
|
export { getSelectedRowAndColumn } from './getSelectedRowAndColumn';
|
|
@@ -6,7 +6,7 @@ export { default as Color } from './ColorPalette/Color';
|
|
|
6
6
|
export { SelectedTextColorProvider } from './ColorPalette/SelectedTextColorProvider';
|
|
7
7
|
export { useSelectedTextColor } from './ColorPalette/useSelectedTextColor';
|
|
8
8
|
export { getSelectedRowAndColumn } from './ColorPalette/getSelectedRowAndColumn';
|
|
9
|
-
export { DEFAULT_COLOR_PICKER_COLUMNS, getColorsPerRowFromPalette, getSelectedRowAndColumnFromPalette, getTokenCSSVariableValue } from './ColorPalette/utils';
|
|
9
|
+
export { DEFAULT_COLOR_PICKER_COLUMNS, getColorsPerRowFromPalette, getSelectedRowAndColumnFromPalette, getTokenCSSVariableValue, getTokenCSSVariableValueForNonActiveTheme } from './ColorPalette/utils';
|
|
10
10
|
export { default as cellBackgroundColorPalette } from './ColorPalette/Palettes/cellBackgroundColorPalette';
|
|
11
11
|
export { default as colorPaletteMessages } from './ColorPalette/Palettes/paletteMessages';
|
|
12
12
|
export { panelBackgroundPalette } from './ColorPalette/Palettes/panelBackgroundPalette';
|
|
@@ -6,4 +6,5 @@ export declare function getSelectedRowAndColumnFromPalette(palette: PaletteColor
|
|
|
6
6
|
selectedRowIndex: number;
|
|
7
7
|
};
|
|
8
8
|
export declare const getTokenCSSVariableValue: (variableExpression: string) => string;
|
|
9
|
+
export declare const getTokenCSSVariableValueForNonActiveTheme: (variableExpression: string, fallback: string) => string;
|
|
9
10
|
export { getSelectedRowAndColumn } from './getSelectedRowAndColumn';
|
|
@@ -3,7 +3,7 @@ export { default as Color } from './ColorPalette/Color';
|
|
|
3
3
|
export { SelectedTextColorProvider } from './ColorPalette/SelectedTextColorProvider';
|
|
4
4
|
export { useSelectedTextColor } from './ColorPalette/useSelectedTextColor';
|
|
5
5
|
export { getSelectedRowAndColumn } from './ColorPalette/getSelectedRowAndColumn';
|
|
6
|
-
export { DEFAULT_COLOR_PICKER_COLUMNS, getColorsPerRowFromPalette, getSelectedRowAndColumnFromPalette, getTokenCSSVariableValue, } from './ColorPalette/utils';
|
|
6
|
+
export { DEFAULT_COLOR_PICKER_COLUMNS, getColorsPerRowFromPalette, getSelectedRowAndColumnFromPalette, getTokenCSSVariableValue, getTokenCSSVariableValueForNonActiveTheme, } from './ColorPalette/utils';
|
|
7
7
|
export { default as cellBackgroundColorPalette } from './ColorPalette/Palettes/cellBackgroundColorPalette';
|
|
8
8
|
export { default as colorPaletteMessages } from './ColorPalette/Palettes/paletteMessages';
|
|
9
9
|
export { panelBackgroundPalette } from './ColorPalette/Palettes/panelBackgroundPalette';
|
package/package.json
CHANGED