dtable-ui-component 5.0.21-alpha.3 → 5.0.21-alpha.4

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.
@@ -6,7 +6,7 @@
6
6
  padding: 0.75rem;
7
7
  line-height: normal;
8
8
  position: absolute;
9
- box-shadow: rgba(0, 0, 0, 0.3) 0px 0px 2px, rgba(0, 0, 0, 0.3) 0px 4px 8px
9
+ box-shadow: rgba(0, 0, 0, 0.3) 0px 0px 2px, rgba(0, 0, 0, 0.3) 0px 4px 8px;
10
10
  }
11
11
 
12
12
  .dtable-color-picker .chrome-picker {
@@ -11,16 +11,25 @@ var _reactstrap = require("reactstrap");
11
11
  var _reactColor = require("react-color");
12
12
  var _lang = require("../lang");
13
13
  var _ClickOutside = _interopRequireDefault(require("../ClickOutside"));
14
- var _constants = require("./constants");
15
14
  var _utils = require("./utils");
16
15
  require("./index.css");
16
+ const DEFAULT_COLORS = ['#ffffff', '#f5f5f5', '#eef6f9', '#deffe6', '#def7c4', '#fefdb5', '#feebb6', '#ffdde5'];
17
+ const COLOR_PICKER_MODE = {
18
+ HEX: 'hex',
19
+ RGBA: 'rgba'
20
+ };
21
+ const RGB_COLORS_MAP = {
22
+ RED: 'r',
23
+ GREEN: 'g',
24
+ BLUE: 'b'
25
+ };
26
+ const LOCAL_STORAGE_KEY = 'dtable-color-picker';
17
27
  const DTableColorPicker = props => {
18
28
  const {
19
29
  onToggle,
20
30
  popoverStyle,
21
31
  color,
22
- defaultColors,
23
- storageKey
32
+ defaultColors
24
33
  } = props;
25
34
  const initialRgbaColor = (0, _utils.hexToRgba)(color);
26
35
  const [value, setValue] = (0, _react.useState)(initialRgbaColor);
@@ -29,11 +38,19 @@ const DTableColorPicker = props => {
29
38
  const [redVal, setRedVal] = (0, _react.useState)(initialRgbaColor.r);
30
39
  const [greenVal, setGreenVal] = (0, _react.useState)(initialRgbaColor.g);
31
40
  const [blueVal, setBlueVal] = (0, _react.useState)(initialRgbaColor.b);
32
- const [colorMode, setColorMode] = (0, _react.useState)(_constants.COLOR_PICKER_MODE.HEX); // hex or rgb
33
- const currentUsedColorsStr = window.localStorage.getItem(storageKey);
34
- let currentUsedColors = currentUsedColorsStr ? JSON.parse(currentUsedColorsStr) : [];
41
+ const [colorMode, setColorMode] = (0, _react.useState)(COLOR_PICKER_MODE.HEX); // hex or rgb
42
+ let currentUsedColors = [];
43
+ const currentUsedColorsStr = window.localStorage.getItem(LOCAL_STORAGE_KEY);
44
+ try {
45
+ currentUsedColors = currentUsedColorsStr ? JSON.parse(currentUsedColorsStr) : [];
46
+ } catch (error) {
47
+ console.error("Error parsing current used colors from localStorage:", error);
48
+ }
35
49
  (0, _react.useEffect)(() => {
36
- document.querySelector('.chrome-picker > div:last-of-type > .flexbox-fix:first-of-type').classList.add('color-bar');
50
+ const colorBarElement = document.querySelector('.chrome-picker > div:last-of-type > .flexbox-fix:first-of-type');
51
+ if (colorBarElement) {
52
+ colorBarElement.classList.add('color-bar');
53
+ }
37
54
  }, []);
38
55
  const onChangeChromePicker = newColor => {
39
56
  const rgba = newColor.rgb;
@@ -48,7 +65,7 @@ const DTableColorPicker = props => {
48
65
  } = rgba;
49
66
  setAlphaVal((0, _utils.toPercentage)(a));
50
67
  updateValue(rgba);
51
- if (colorMode === _constants.COLOR_PICKER_MODE.HEX) {
68
+ if (colorMode === COLOR_PICKER_MODE.HEX) {
52
69
  setHexVal(hexVal);
53
70
  } else {
54
71
  setRedVal(r);
@@ -58,8 +75,8 @@ const DTableColorPicker = props => {
58
75
  };
59
76
  const onChangeMode = () => {
60
77
  let newMode;
61
- if (colorMode === _constants.COLOR_PICKER_MODE.HEX) {
62
- newMode = _constants.COLOR_PICKER_MODE.RGBA;
78
+ if (colorMode === COLOR_PICKER_MODE.HEX) {
79
+ newMode = COLOR_PICKER_MODE.RGBA;
63
80
  const rgba = (0, _utils.hexToRgba)(color);
64
81
  const {
65
82
  r,
@@ -70,7 +87,7 @@ const DTableColorPicker = props => {
70
87
  setGreenVal(g);
71
88
  setBlueVal(b);
72
89
  } else {
73
- newMode = _constants.COLOR_PICKER_MODE.HEX;
90
+ newMode = COLOR_PICKER_MODE.HEX;
74
91
  const hexVal = (0, _utils.rgbaToHex)(value, false, false);
75
92
  setHexVal(hexVal);
76
93
  }
@@ -117,17 +134,17 @@ const DTableColorPicker = props => {
117
134
  if (!regex.test(newVal)) return;
118
135
  if (newVal) newVal = parseInt(newVal);
119
136
  switch (specColor) {
120
- case _constants.RGB_COLORS_MAP.RED:
137
+ case RGB_COLORS_MAP.RED:
121
138
  {
122
139
  setRedVal(newVal);
123
140
  break;
124
141
  }
125
- case _constants.RGB_COLORS_MAP.GREEN:
142
+ case RGB_COLORS_MAP.GREEN:
126
143
  {
127
144
  setGreenVal(newVal);
128
145
  break;
129
146
  }
130
- case _constants.RGB_COLORS_MAP.BLUT:
147
+ case RGB_COLORS_MAP.BLUE:
131
148
  {
132
149
  setBlueVal(newVal);
133
150
  break;
@@ -139,10 +156,10 @@ const DTableColorPicker = props => {
139
156
  const onRgbInputBlur = specColor => {
140
157
  let val = redVal;
141
158
  let setSpecColor = setRedVal;
142
- if (specColor === _constants.RGB_COLORS_MAP.GREEN) {
159
+ if (specColor === RGB_COLORS_MAP.GREEN) {
143
160
  val = greenVal;
144
161
  setSpecColor = setGreenVal;
145
- } else if (specColor === _constants.RGB_COLORS_MAP.BLUT) {
162
+ } else if (specColor === RGB_COLORS_MAP.BLUE) {
146
163
  val = blueVal;
147
164
  setSpecColor = setBlueVal;
148
165
  }
@@ -189,35 +206,34 @@ const DTableColorPicker = props => {
189
206
  a
190
207
  } = rgba;
191
208
  const alphaVal = (0, _utils.toPercentage)(a);
192
- if (colorMode === _constants.COLOR_PICKER_MODE.HEX) {
193
- setHexVal(hexVal);
194
- } else {
209
+ if (colorMode === COLOR_PICKER_MODE.RGBA) {
195
210
  setRedVal(r);
196
211
  setGreenVal(g);
197
212
  setBlueVal(b);
198
213
  }
214
+ setHexVal(hexVal);
199
215
  setAlphaVal(alphaVal);
200
216
  updateValue(rgba);
201
217
  };
202
218
  const onClosePopover = () => {
203
- if (storageKey) {
204
- if (currentUsedColors.length >= 8) currentUsedColors.pop();
205
- const hex = (0, _utils.rgbaToHex)(value);
206
- if (!currentUsedColors.includes(hex)) {
207
- currentUsedColors.unshift(hex);
208
- window.localStorage.setItem(storageKey, JSON.stringify(currentUsedColors));
209
- }
219
+ if (currentUsedColors.length >= 8) currentUsedColors.pop();
220
+ const hex = (0, _utils.rgbaToHex)(value);
221
+ if (!currentUsedColors.includes(hex)) {
222
+ currentUsedColors.unshift(hex);
223
+ window.localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(currentUsedColors));
210
224
  }
211
225
  onToggle();
212
226
  };
213
227
  const renderDefaultContainer = () => {
228
+ const colors = defaultColors ? defaultColors.slice(0, 8) : DEFAULT_COLORS;
214
229
  return /*#__PURE__*/_react.default.createElement("div", {
215
230
  className: "default-color-setting"
216
231
  }, /*#__PURE__*/_react.default.createElement("span", null, (0, _lang.getLocale)('Default')), /*#__PURE__*/_react.default.createElement("div", {
217
232
  className: "default-colors-container d-flex mt-2 mb-2"
218
- }, (defaultColors || _constants.DEFAULT_COLORS).map((color, index) => {
233
+ }, colors.map((color, index) => {
234
+ const isLight = (0, _utils.isLightColor)(color);
219
235
  return /*#__PURE__*/_react.default.createElement("div", {
220
- className: "color-item mr-2",
236
+ className: "color-item mr-2 ".concat(isLight ? '' : 'dark'),
221
237
  onClick: () => onSelectDefaultColor(color),
222
238
  key: "default-color-".concat(index)
223
239
  }, /*#__PURE__*/_react.default.createElement("span", {
@@ -225,7 +241,7 @@ const DTableColorPicker = props => {
225
241
  style: {
226
242
  backgroundColor: color
227
243
  }
228
- }, color === "#".concat(hexVal) && !currentUsedColors.includes(color) && alphaVal === 100 && /*#__PURE__*/_react.default.createElement("i", {
244
+ }, color === "#".concat(hexVal) && alphaVal === 100 && /*#__PURE__*/_react.default.createElement("i", {
229
245
  className: "dtable-icon-color-check dtable-font dtable-icon-check-mark"
230
246
  })));
231
247
  })));
@@ -239,10 +255,10 @@ const DTableColorPicker = props => {
239
255
  className: "color-setting d-flex align-items-center ".concat(colorMode)
240
256
  }, /*#__PURE__*/_react.default.createElement("span", {
241
257
  className: "mode-btn d-flex"
242
- }, colorMode === _constants.COLOR_PICKER_MODE.HEX ? 'HEX' : 'RGB', /*#__PURE__*/_react.default.createElement("i", {
258
+ }, colorMode === COLOR_PICKER_MODE.HEX ? 'HEX' : 'RGB', /*#__PURE__*/_react.default.createElement("i", {
243
259
  onClick: onChangeMode,
244
260
  className: "dtable-font dtable-icon-right"
245
- })), colorMode === _constants.COLOR_PICKER_MODE.HEX ? renderHexContainer() : renderRgbContainer(), /*#__PURE__*/_react.default.createElement(_reactstrap.Input, {
261
+ })), colorMode === COLOR_PICKER_MODE.HEX ? renderHexContainer() : renderRgbContainer(), /*#__PURE__*/_react.default.createElement(_reactstrap.Input, {
246
262
  className: "alpha-input",
247
263
  type: "text",
248
264
  value: alphaVal + '%',
@@ -270,26 +286,26 @@ const DTableColorPicker = props => {
270
286
  className: "rgb-input",
271
287
  type: "text",
272
288
  value: redVal,
273
- onBlur: () => onRgbInputBlur(_constants.RGB_COLORS_MAP.RED),
274
- onChange: e => onChangeRgb(e, _constants.RGB_COLORS_MAP.RED)
289
+ onBlur: () => onRgbInputBlur(RGB_COLORS_MAP.RED),
290
+ onChange: e => onChangeRgb(e, RGB_COLORS_MAP.RED)
275
291
  }), /*#__PURE__*/_react.default.createElement("span", null, "G"), /*#__PURE__*/_react.default.createElement(_reactstrap.Input, {
276
292
  className: "rgb-input",
277
293
  type: "text",
278
294
  value: greenVal,
279
- onBlur: () => onRgbInputBlur(_constants.RGB_COLORS_MAP.GREEN),
280
- onChange: e => onChangeRgb(e, _constants.RGB_COLORS_MAP.GREEN)
295
+ onBlur: () => onRgbInputBlur(RGB_COLORS_MAP.GREEN),
296
+ onChange: e => onChangeRgb(e, RGB_COLORS_MAP.GREEN)
281
297
  }), /*#__PURE__*/_react.default.createElement("span", null, "B"), /*#__PURE__*/_react.default.createElement(_reactstrap.Input, {
282
298
  className: "rgb-input",
283
299
  type: "text",
284
300
  value: blueVal,
285
- onBlur: () => onRgbInputBlur(_constants.RGB_COLORS_MAP.BLUT),
286
- onChange: e => onChangeRgb(e, _constants.RGB_COLORS_MAP.BLUT)
301
+ onBlur: () => onRgbInputBlur(RGB_COLORS_MAP.BLUE),
302
+ onChange: e => onChangeRgb(e, RGB_COLORS_MAP.BLUE)
287
303
  }));
288
304
  };
289
305
  const renderUsedContainer = () => {
290
306
  return /*#__PURE__*/_react.default.createElement("div", {
291
307
  className: "current-used-container mt-2"
292
- }, /*#__PURE__*/_react.default.createElement("span", null, (0, _lang.getLocale)('Used')), /*#__PURE__*/_react.default.createElement("div", {
308
+ }, /*#__PURE__*/_react.default.createElement("span", null, (0, _lang.getLocale)('Recently_used')), /*#__PURE__*/_react.default.createElement("div", {
293
309
  className: "current-used-colors d-flex mt-2"
294
310
  }, currentUsedColors.length > 0 ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, currentUsedColors.map((color, index) => {
295
311
  const isLight = (0, _utils.isLightColor)(color);
@@ -12,8 +12,7 @@ const hexToRgba = color => {
12
12
  let g;
13
13
  let b;
14
14
  let a = 1;
15
- let hex = color;
16
- hex = hex.replace(/^#/, '');
15
+ const hex = color.replace(/^#/, '');
17
16
  if (hex.length === 6 || hex.length === 8) {
18
17
  r = parseInt(hex.slice(0, 2), 16);
19
18
  g = parseInt(hex.slice(2, 4), 16);
package/lib/locals/de.js CHANGED
@@ -98,6 +98,6 @@ const de = {
98
98
  "Select_department": "Bereich auswählen",
99
99
  "Default": "Standard",
100
100
  "Custom": "Benutzerdefiniert",
101
- "Used": "Verwendet"
101
+ "Recently_used": "Kürzlich benutzt"
102
102
  };
103
103
  var _default = exports.default = de;
package/lib/locals/en.js CHANGED
@@ -98,6 +98,6 @@ const en = {
98
98
  "Select_department": "Select department",
99
99
  "Default": "Default",
100
100
  "Custom": "Custom",
101
- "Used": "Used"
101
+ "Recently_used": "Recently used"
102
102
  };
103
103
  var _default = exports.default = en;
package/lib/locals/es.js CHANGED
@@ -98,6 +98,6 @@ const es = {
98
98
  "Select_department": "Select department",
99
99
  "Default": "Incumplimiento de contrato",
100
100
  "Custom": "Costumbres",
101
- "Used": "Acostumbrado a"
101
+ "Recently_used": "Recientemente usado"
102
102
  };
103
103
  var _default = exports.default = es;
package/lib/locals/fr.js CHANGED
@@ -98,6 +98,6 @@ const fr = {
98
98
  "Select_department": "Sélectionner un département",
99
99
  "Default": "Violation",
100
100
  "Custom": "Les coutumes",
101
- "Used": "Habitué à"
101
+ "Recently_used": "Utilisé récemment"
102
102
  };
103
103
  var _default = exports.default = fr;
package/lib/locals/pt.js CHANGED
@@ -98,6 +98,6 @@ const pt = {
98
98
  "Select_department": "Select department",
99
99
  "Default": "por omissão",
100
100
  "Custom": "personalizado",
101
- "Used": "usado"
101
+ "Recently_used": "usado recentemente"
102
102
  };
103
103
  var _default = exports.default = pt;
package/lib/locals/ru.js CHANGED
@@ -98,6 +98,6 @@ const ru = {
98
98
  "Select_department": "Select department",
99
99
  "Default": "Нарушение обязательств",
100
100
  "Custom": "Обычаи",
101
- "Used": "Привыкнуть"
101
+ "Recently_used": "Недавно использованный"
102
102
  };
103
103
  var _default = exports.default = ru;
@@ -98,6 +98,6 @@ const zh_CN = {
98
98
  "Select_department": "选择部门",
99
99
  "Default": "默认",
100
100
  "Custom": "自定义",
101
- "Used": "使用过"
101
+ "Recently_used": "最近使用"
102
102
  };
103
103
  var _default = exports.default = zh_CN;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dtable-ui-component",
3
- "version": "5.0.21-alpha.3",
3
+ "version": "5.0.21-alpha.4",
4
4
  "main": "./lib/index.js",
5
5
  "dependencies": {
6
6
  "@seafile/react-image-lightbox": "2.0.5",
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.RGB_COLORS_MAP = exports.DEFAULT_COLORS = exports.COLOR_PICKER_MODE = void 0;
7
- const DEFAULT_COLORS = exports.DEFAULT_COLORS = ['#ffffff', '#f5f5f5', '#eef6f9', '#deffe6', '#def7c4', '#fefdb5', '#feebb6', '#ffdde5'];
8
- const COLOR_PICKER_MODE = exports.COLOR_PICKER_MODE = {
9
- HEX: 'hex',
10
- RGBA: 'rgba'
11
- };
12
- const RGB_COLORS_MAP = exports.RGB_COLORS_MAP = {
13
- RED: 'r',
14
- GREEN: 'g',
15
- BLUT: 'b'
16
- };