goblin-gadgets 3.2.2 → 3.2.3

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.
Files changed (361) hide show
  1. package/.editorconfig +9 -9
  2. package/.eslintrc.js +28 -28
  3. package/.zou-flow +2 -2
  4. package/builders/builders.js +5 -5
  5. package/builders/gadget.js +85 -85
  6. package/calendar-boards-gadget.js +64 -64
  7. package/demo-gadget.js +17 -17
  8. package/glyphs-dialog.js +13 -13
  9. package/login-dialog.js +13 -13
  10. package/package.json +46 -46
  11. package/pivot-gadget.js +18 -18
  12. package/stack-navigation.js +13 -13
  13. package/table-gadget.js +102 -102
  14. package/test/code-parser.spec.js +61 -61
  15. package/tree-gadget.js +70 -70
  16. package/types/types.js +455 -455
  17. package/widgets/accordion/styles.js +16 -16
  18. package/widgets/accordion/widget.js +90 -90
  19. package/widgets/analog-clock/props.js +102 -102
  20. package/widgets/analog-clock/scenarios.js +43 -43
  21. package/widgets/analog-clock/styles.js +754 -754
  22. package/widgets/analog-clock/widget.js +404 -404
  23. package/widgets/animated-container/animations.js +566 -566
  24. package/widgets/animated-container/styles.js +36 -36
  25. package/widgets/animated-container/widget.js +24 -24
  26. package/widgets/badge/styles.js +107 -107
  27. package/widgets/badge/widget.js +33 -33
  28. package/widgets/button/props.js +377 -377
  29. package/widgets/button/scenarios.js +54 -54
  30. package/widgets/button/styles.js +1082 -1082
  31. package/widgets/button/widget.js +426 -426
  32. package/widgets/button-combo/styles.js +73 -73
  33. package/widgets/button-combo/widget.js +297 -297
  34. package/widgets/calendar/props.js +207 -207
  35. package/widgets/calendar/scenarios.js +50 -50
  36. package/widgets/calendar/styles.js +198 -198
  37. package/widgets/calendar/widget.js +895 -895
  38. package/widgets/calendar-boards/styles.js +29 -29
  39. package/widgets/calendar-boards/widget.js +215 -215
  40. package/widgets/calendar-button/styles.js +273 -273
  41. package/widgets/calendar-button/widget.js +94 -94
  42. package/widgets/calendar-list/styles.js +35 -35
  43. package/widgets/calendar-list/widget.js +223 -223
  44. package/widgets/calendar-recurrence/widget.js +183 -183
  45. package/widgets/carousel/props.js +104 -104
  46. package/widgets/carousel/scenarios.js +163 -163
  47. package/widgets/carousel/styles.js +133 -133
  48. package/widgets/carousel/widget.js +491 -491
  49. package/widgets/carousel-bullet/styles.js +29 -29
  50. package/widgets/carousel-bullet/widget.js +25 -25
  51. package/widgets/carousel-button/styles.js +71 -71
  52. package/widgets/carousel-button/widget.js +33 -33
  53. package/widgets/carousel-item/styles.js +21 -21
  54. package/widgets/carousel-item/widget.js +24 -24
  55. package/widgets/chat-balloon/props.js +65 -65
  56. package/widgets/chat-balloon/scenarios.js +47 -47
  57. package/widgets/chat-balloon/styles.js +193 -193
  58. package/widgets/chat-balloon/widget.js +62 -62
  59. package/widgets/chat-dialog/styles.js +15 -15
  60. package/widgets/chat-dialog/widget.js +62 -62
  61. package/widgets/check-list/styles.js +66 -66
  62. package/widgets/check-list/widget.js +168 -168
  63. package/widgets/checkbox/widget.js +15 -15
  64. package/widgets/checkbox-nc/props.js +191 -191
  65. package/widgets/checkbox-nc/scenarios.js +41 -41
  66. package/widgets/checkbox-nc/styles.js +122 -122
  67. package/widgets/checkbox-nc/widget.js +116 -116
  68. package/widgets/clock-combo/styles.js +174 -174
  69. package/widgets/clock-combo/widget.js +390 -390
  70. package/widgets/color-picker/props.js +145 -145
  71. package/widgets/color-picker/scenarios.js +34 -34
  72. package/widgets/color-picker/styles.js +209 -209
  73. package/widgets/color-picker/widget.js +735 -735
  74. package/widgets/colored-container/props.js +34 -34
  75. package/widgets/colored-container/scenarios.js +54 -54
  76. package/widgets/colored-container/styles.js +100 -100
  77. package/widgets/colored-container/widget.js +27 -27
  78. package/widgets/combo/styles.js +69 -69
  79. package/widgets/combo/widget.js +224 -224
  80. package/widgets/combo-container/styles.js +66 -66
  81. package/widgets/combo-container/widget.js +188 -188
  82. package/widgets/command-button/widget.js +39 -39
  83. package/widgets/container/props.js +295 -295
  84. package/widgets/container/scenarios.js +47 -47
  85. package/widgets/container/styles.js +1439 -1439
  86. package/widgets/container/widget.js +279 -279
  87. package/widgets/demo/widget.js +24 -24
  88. package/widgets/dialog/styles.js +29 -29
  89. package/widgets/dialog/widget.js +26 -26
  90. package/widgets/dialog-modal/props.js +126 -126
  91. package/widgets/dialog-modal/styles.js +234 -234
  92. package/widgets/dialog-modal/widget.js +273 -273
  93. package/widgets/dialog-resizable/props.js +1 -1
  94. package/widgets/dialog-resizable/scenarios.js +18 -18
  95. package/widgets/dialog-resizable/widget.js +367 -367
  96. package/widgets/dialog-resizable-nc/props.js +150 -150
  97. package/widgets/dialog-resizable-nc/scenarios.js +18 -18
  98. package/widgets/dialog-resizable-nc/styles.js +259 -259
  99. package/widgets/dialog-resizable-nc/widget.js +197 -197
  100. package/widgets/directory-input/widget.js +18 -18
  101. package/widgets/directory-input-nc/widget.js +20 -20
  102. package/widgets/document-container/getPath.js +43 -43
  103. package/widgets/document-container/props.js +79 -79
  104. package/widgets/document-container/scenarios.js +39 -39
  105. package/widgets/document-container/styles.js +69 -69
  106. package/widgets/document-container/widget.js +53 -53
  107. package/widgets/drag-cab/styles.js +56 -56
  108. package/widgets/drag-cab/widget.js +285 -285
  109. package/widgets/drag-carrier/styles.js +21 -21
  110. package/widgets/drag-carrier/widget.js +780 -780
  111. package/widgets/dynamic-toolbar/styles.js +110 -110
  112. package/widgets/dynamic-toolbar/widget.js +128 -128
  113. package/widgets/field/readonly/label.js +39 -39
  114. package/widgets/field/widget.js +1743 -1743
  115. package/widgets/file-input/widget.js +18 -18
  116. package/widgets/file-input-nc/styles.js +38 -38
  117. package/widgets/file-input-nc/widget.js +88 -88
  118. package/widgets/flat-combo/styles.js +21 -21
  119. package/widgets/flat-combo/widget.js +61 -61
  120. package/widgets/flat-list/styles.js +30 -30
  121. package/widgets/flat-list/widget.js +219 -219
  122. package/widgets/flying-balloon/styles.js +52 -52
  123. package/widgets/flying-balloon/widget.js +43 -43
  124. package/widgets/fragment/widget.js +26 -26
  125. package/widgets/full-screen/props.js +27 -27
  126. package/widgets/full-screen/styles.js +32 -32
  127. package/widgets/full-screen/widget.js +40 -40
  128. package/widgets/gauge/props.js +71 -71
  129. package/widgets/gauge/scenarios.js +83 -83
  130. package/widgets/gauge/styles.js +183 -183
  131. package/widgets/gauge/widget.js +36 -36
  132. package/widgets/glyph-detail/service.js +9 -9
  133. package/widgets/glyph-detail/widget.js +109 -109
  134. package/widgets/glyphs-dialog/service.js +94 -94
  135. package/widgets/glyphs-dialog/styles.js +37 -37
  136. package/widgets/glyphs-dialog/widget.js +236 -236
  137. package/widgets/goblin-editor/widget.js +146 -146
  138. package/widgets/guild-entry/props.js +53 -53
  139. package/widgets/guild-entry/scenarios.js +26 -26
  140. package/widgets/guild-entry/styles.js +98 -98
  141. package/widgets/guild-entry/widget.js +126 -126
  142. package/widgets/guild-user-logo/guild-helpers.js +77 -77
  143. package/widgets/guild-user-logo/props.js +48 -48
  144. package/widgets/guild-user-logo/scenarios.js +64 -64
  145. package/widgets/guild-user-logo/styles.js +114 -114
  146. package/widgets/guild-user-logo/widget.js +81 -81
  147. package/widgets/guild-user-profile/props.js +73 -73
  148. package/widgets/guild-user-profile/scenarios.js +54 -54
  149. package/widgets/guild-user-profile/styles.js +162 -162
  150. package/widgets/guild-user-profile/widget.js +202 -202
  151. package/widgets/helpers/combo-helpers.js +218 -218
  152. package/widgets/helpers/geom-helpers.js +80 -80
  153. package/widgets/helpers/rect-helpers.js +10 -10
  154. package/widgets/helpers/shortcut-helpers.js +56 -56
  155. package/widgets/helpers/spacing-helpers.js +26 -26
  156. package/widgets/helpers/svg-helpers.js +151 -151
  157. package/widgets/helpers/table-helpers.js +68 -68
  158. package/widgets/hinter/styles.js +79 -79
  159. package/widgets/hinter/widget.js +205 -205
  160. package/widgets/hinter-column/widget.js +49 -49
  161. package/widgets/hinter-field/reducer.js +18 -18
  162. package/widgets/hinter-field/widget.js +176 -176
  163. package/widgets/hinter-field-nc/props.js +114 -114
  164. package/widgets/hinter-field-nc/scenarios.js +47 -47
  165. package/widgets/hinter-field-nc/widget.js +191 -191
  166. package/widgets/input-wrapper/widget.js +157 -157
  167. package/widgets/key-trap.js +96 -96
  168. package/widgets/label/props.js +1 -1
  169. package/widgets/label/scenarios.js +1 -1
  170. package/widgets/label/widget.js +7 -7
  171. package/widgets/label-nc/props.js +308 -308
  172. package/widgets/label-nc/scenarios.js +29 -29
  173. package/widgets/label-nc/styles.js +1218 -1218
  174. package/widgets/label-nc/widget.js +314 -314
  175. package/widgets/label-row/props.js +1 -1
  176. package/widgets/label-row/scenarios.js +1 -1
  177. package/widgets/label-row/widget.js +7 -7
  178. package/widgets/label-row-nc/props.js +94 -94
  179. package/widgets/label-row-nc/scenarios.js +46 -46
  180. package/widgets/label-row-nc/widget.js +81 -81
  181. package/widgets/label-text-field/styles.js +55 -55
  182. package/widgets/label-text-field/widget.js +178 -178
  183. package/widgets/launcher/props.js +177 -177
  184. package/widgets/launcher/scenarios.js +55 -55
  185. package/widgets/launcher/styles.js +46 -46
  186. package/widgets/launcher/widget.js +79 -79
  187. package/widgets/launcher-blob/props.js +25 -25
  188. package/widgets/launcher-blob/scenarios.js +24 -24
  189. package/widgets/launcher-blob/styles.js +62 -62
  190. package/widgets/launcher-blob/widget.js +50 -50
  191. package/widgets/list/widget.js +211 -211
  192. package/widgets/login-dialog/service.js +117 -117
  193. package/widgets/login-dialog/widget.js +117 -117
  194. package/widgets/map/reaflet.js +208 -208
  195. package/widgets/map/widget.js +67 -67
  196. package/widgets/markdown/styles.js +85 -85
  197. package/widgets/markdown/widget.js +31 -31
  198. package/widgets/notification/styles.js +97 -97
  199. package/widgets/notification/widget.js +207 -207
  200. package/widgets/pivot/custom.css +320 -320
  201. package/widgets/pivot/widget.js +42 -42
  202. package/widgets/radio-list/styles.js +48 -48
  203. package/widgets/radio-list/widget.js +111 -111
  204. package/widgets/resizable-container/styles.js +108 -108
  205. package/widgets/resizable-container/widget.js +225 -225
  206. package/widgets/retro-action-button/helpers.js +106 -106
  207. package/widgets/retro-action-button/styles.js +285 -285
  208. package/widgets/retro-action-button/widget.js +364 -364
  209. package/widgets/retro-badge-button/styles.js +87 -87
  210. package/widgets/retro-badge-button/widget.js +251 -251
  211. package/widgets/retro-gear/helpers.js +156 -156
  212. package/widgets/retro-gear/styles.js +130 -130
  213. package/widgets/retro-gear/widget.js +51 -51
  214. package/widgets/retro-illuminated-button/styles.js +274 -274
  215. package/widgets/retro-illuminated-button/widget.js +147 -147
  216. package/widgets/retro-panel/helpers.js +57 -57
  217. package/widgets/retro-panel/styles.js +293 -293
  218. package/widgets/retro-panel/widget.js +239 -239
  219. package/widgets/retro-screw/styles.js +80 -80
  220. package/widgets/retro-screw/widget.js +25 -25
  221. package/widgets/rocket/props.js +124 -124
  222. package/widgets/rocket/scenarios.js +71 -71
  223. package/widgets/rocket/styles.js +306 -306
  224. package/widgets/rocket/widget.js +225 -225
  225. package/widgets/samples-monitor/helpers.js +147 -147
  226. package/widgets/samples-monitor/styles.js +529 -529
  227. package/widgets/samples-monitor/widget.js +516 -516
  228. package/widgets/scrollable-container/styles.js +58 -58
  229. package/widgets/scrollable-container/widget.js +132 -132
  230. package/widgets/scrollable-linkable-container/reducer.js +18 -18
  231. package/widgets/scrollable-linkable-container/styles.js +42 -42
  232. package/widgets/scrollable-linkable-container/widget.js +78 -78
  233. package/widgets/select/styles.js +68 -68
  234. package/widgets/select/widget.js +119 -119
  235. package/widgets/separator/props.js +46 -46
  236. package/widgets/separator/styles.js +116 -116
  237. package/widgets/separator/widget.js +27 -27
  238. package/widgets/slider/props.js +136 -136
  239. package/widgets/slider/scenarios.js +74 -74
  240. package/widgets/slider/styles.js +246 -246
  241. package/widgets/slider/widget.js +404 -404
  242. package/widgets/slider-circle/props.js +72 -72
  243. package/widgets/slider-circle/scenarios.js +16 -16
  244. package/widgets/slider-circle/styles.js +78 -78
  245. package/widgets/slider-circle/widget.js +154 -154
  246. package/widgets/slider-xy/props.js +87 -87
  247. package/widgets/slider-xy/scenarios.js +19 -19
  248. package/widgets/slider-xy/styles.js +102 -102
  249. package/widgets/slider-xy/widget.js +234 -234
  250. package/widgets/smiley/props.js +51 -51
  251. package/widgets/smiley/scenarios.js +58 -58
  252. package/widgets/smiley/styles.js +489 -489
  253. package/widgets/smiley/widget.js +72 -72
  254. package/widgets/spinner/props.js +31 -31
  255. package/widgets/spinner/scenarios.js +31 -31
  256. package/widgets/spinner/styles.js +49 -49
  257. package/widgets/spinner/widget.js +23 -23
  258. package/widgets/splitter/props.js +71 -71
  259. package/widgets/splitter/scenarios.js +182 -182
  260. package/widgets/splitter/styles.js +41 -41
  261. package/widgets/splitter/widget.js +455 -455
  262. package/widgets/stack-navigation/service.js +324 -324
  263. package/widgets/stack-navigation/widget.js +296 -296
  264. package/widgets/state-browser/styles.js +19 -19
  265. package/widgets/state-browser/widget.js +135 -135
  266. package/widgets/state-browser-dialog/styles.js +100 -100
  267. package/widgets/state-browser-dialog/widget.js +253 -253
  268. package/widgets/state-monitor/styles.js +50 -50
  269. package/widgets/state-monitor/widget.js +324 -324
  270. package/widgets/switch-on-off/props.js +30 -30
  271. package/widgets/switch-on-off/scenarios.js +34 -34
  272. package/widgets/switch-on-off/styles.js +63 -63
  273. package/widgets/switch-on-off/widget.js +41 -41
  274. package/widgets/table/helpers.js +160 -160
  275. package/widgets/table/props.js +658 -658
  276. package/widgets/table/reducer.js +196 -196
  277. package/widgets/table/scenarios.js +54 -54
  278. package/widgets/table/widget.js +253 -253
  279. package/widgets/table-cell/props.js +145 -145
  280. package/widgets/table-cell/styles.js +160 -160
  281. package/widgets/table-cell/widget.js +139 -139
  282. package/widgets/table-header-drag-manager/styles.js +184 -184
  283. package/widgets/table-header-drag-manager/widget.js +392 -392
  284. package/widgets/table-nc/styles.js +100 -100
  285. package/widgets/table-nc/widget.js +409 -409
  286. package/widgets/table-row/props.js +73 -73
  287. package/widgets/table-row/styles.js +82 -82
  288. package/widgets/table-row/widget.js +207 -207
  289. package/widgets/text-field/widget.js +18 -18
  290. package/widgets/text-field-combo/widget.js +21 -21
  291. package/widgets/text-field-combo-nc/props.js +300 -300
  292. package/widgets/text-field-combo-nc/scenarios.js +72 -72
  293. package/widgets/text-field-combo-nc/widget.js +339 -339
  294. package/widgets/text-field-date-interval/styles.js +37 -37
  295. package/widgets/text-field-date-interval/widget.js +162 -162
  296. package/widgets/text-field-nc/props.js +40 -40
  297. package/widgets/text-field-nc/scenarios.js +67 -67
  298. package/widgets/text-field-nc/widget.js +14 -14
  299. package/widgets/text-field-time-interval/styles.js +37 -37
  300. package/widgets/text-field-time-interval/widget.js +160 -160
  301. package/widgets/text-field-typed/widget.js +51 -51
  302. package/widgets/text-field-typed-nc/props.js +81 -81
  303. package/widgets/text-field-typed-nc/scenarios.js +105 -105
  304. package/widgets/text-field-typed-nc/styles.js +20 -20
  305. package/widgets/text-field-typed-nc/widget.js +749 -750
  306. package/widgets/text-input-info-nc/props.js +62 -62
  307. package/widgets/text-input-info-nc/widget.js +55 -55
  308. package/widgets/text-input-nc/props.js +143 -143
  309. package/widgets/text-input-nc/scenarios.js +44 -44
  310. package/widgets/text-input-nc/styles.js +242 -242
  311. package/widgets/text-input-nc/widget.js +234 -234
  312. package/widgets/ticket/getPath.js +128 -128
  313. package/widgets/ticket/props.js +181 -181
  314. package/widgets/ticket/scenarios.js +39 -39
  315. package/widgets/ticket/styles.js +332 -332
  316. package/widgets/ticket/ticket-helpers.js +33 -33
  317. package/widgets/ticket/widget.js +348 -348
  318. package/widgets/ticket-hover/styles.js +207 -207
  319. package/widgets/ticket-hover/widget.js +53 -53
  320. package/widgets/time-gauge/widget.js +64 -64
  321. package/widgets/tips/styles.js +48 -48
  322. package/widgets/tips/widget.js +171 -171
  323. package/widgets/translatable-text-field/styles.js +202 -202
  324. package/widgets/translatable-text-field/text-field.js +132 -132
  325. package/widgets/translatable-text-field/widget.js +660 -660
  326. package/widgets/tree/props.js +246 -246
  327. package/widgets/tree/scenarios.js +14 -14
  328. package/widgets/tree/styles.js +142 -142
  329. package/widgets/tree/widget.js +383 -383
  330. package/widgets/tree-cell/styles.js +140 -140
  331. package/widgets/tree-cell/widget.js +100 -100
  332. package/widgets/tree-row/styles.js +77 -77
  333. package/widgets/tree-row/widget.js +135 -135
  334. package/widgets/triangle/props.js +48 -48
  335. package/widgets/triangle/scenarios.js +33 -33
  336. package/widgets/triangle/styles.js +92 -92
  337. package/widgets/triangle/widget.js +36 -36
  338. package/widgets/well-done/widget.js +170 -170
  339. package/widgets/widget-doc/reducer.js +68 -68
  340. package/widgets/widget-doc/styles.js +15 -15
  341. package/widgets/widget-doc/widget-list.js +25 -25
  342. package/widgets/widget-doc/widget.js +89 -89
  343. package/widgets/widget-doc-menu/styles.js +12 -12
  344. package/widgets/widget-doc-menu/widget.js +79 -79
  345. package/widgets/widget-doc-preview/parse-code.js +20 -20
  346. package/widgets/widget-doc-preview/styles.js +77 -77
  347. package/widgets/widget-doc-preview/widget.js +481 -481
  348. package/widgets/widget-doc-preview-container/styles.js +60 -60
  349. package/widgets/widget-doc-preview-container/widget.js +129 -129
  350. package/widgets/widget-doc-properties/styles.js +41 -41
  351. package/widgets/widget-doc-properties/widget.js +307 -307
  352. package/widgets/widget-doc-property/styles.js +75 -75
  353. package/widgets/widget-doc-property/widget.js +108 -108
  354. package/widgets/widget-doc-property-control/styles.js +14 -14
  355. package/widgets/widget-doc-property-control/widget.js +343 -343
  356. package/widgets/wizard/service.js +2132 -2132
  357. package/widgets/wizard/styles.js +21 -21
  358. package/widgets/wizard/widget.js +927 -927
  359. package/widgets/work-dialog/styles.js +31 -31
  360. package/widgets/work-dialog/widget.js +162 -162
  361. package/wizard.js +13 -13
@@ -1,735 +1,735 @@
1
- import React from 'react';
2
- import props from './props';
3
- import scenarios from './scenarios';
4
- import {registerWidget} from 'goblin-gadgets/widgets/widget-doc/widget-list';
5
- import Widget from 'goblin-laboratory/widgets/widget';
6
- import * as styles from './styles';
7
- import throttle from 'lodash/throttle';
8
- import TextFieldTypedNC from 'goblin-gadgets/widgets/text-field-typed-nc/widget';
9
- import TextInputInfoNC from 'goblin-gadgets/widgets/text-input-info-nc/widget';
10
- import Slider from 'goblin-gadgets/widgets/slider/widget';
11
- import SliderXY from 'goblin-gadgets/widgets/slider-xy/widget';
12
- import SliderCircle from 'goblin-gadgets/widgets/slider-circle/widget';
13
- import Label from 'goblin-gadgets/widgets/label/widget';
14
- import Button from 'goblin-gadgets/widgets/button/widget';
15
- import Separator from 'goblin-gadgets/widgets/separator/widget';
16
- import {color as ColorConverters} from 'xcraft-core-converters';
17
- import T from 't';
18
- import {TranslatableDiv} from 'goblin-nabu/widgets/helpers/element-helpers';
19
- import MouseTrap from 'mousetrap';
20
-
21
- /******************************************************************************/
22
-
23
- class ColorPicker extends Widget {
24
- constructor() {
25
- super(...arguments);
26
- this.styles = styles;
27
-
28
- // Warning: initialColor and lastColorsDisplayed are never changed for
29
- // this instance of ColorPicker.
30
- this.initialColor = this.props.color;
31
- this.lastColorsDisplayed = this.props.lastColors
32
- ? [...this.props.lastColors]
33
- : [];
34
- this.alreadyPushed = false;
35
-
36
- this.state = {
37
- analysis: {},
38
- editedColor: null,
39
- info: null,
40
- warning: null,
41
- lastColors: this.props.lastColors ? this.props.lastColors : [],
42
- showPallet: false,
43
- };
44
-
45
- this.onColorChanged = throttle(this.onColorChanged, 50).bind(this);
46
- this.onTextEdited = this.onTextEdited.bind(this);
47
- this.onTextChanged = this.onTextChanged.bind(this);
48
- this.onTextValidate = this.onTextValidate.bind(this);
49
- this.onPaste = this.onPaste.bind(this);
50
- }
51
-
52
- //#region get/set
53
- get analysis() {
54
- return this.state.analysis;
55
- }
56
- set analysis(value) {
57
- this.setState({
58
- analysis: value,
59
- });
60
- }
61
-
62
- get editedColor() {
63
- return this.state.editedColor;
64
- }
65
- set editedColor(value) {
66
- this.setState({
67
- editedColor: value,
68
- });
69
- }
70
-
71
- get info() {
72
- return this.state.info;
73
- }
74
- set info(value) {
75
- this.setState({
76
- info: value,
77
- });
78
- }
79
-
80
- get warning() {
81
- return this.state.warning;
82
- }
83
- set warning(value) {
84
- this.setState({
85
- warning: value,
86
- });
87
- }
88
-
89
- get lastColors() {
90
- return this.state.lastColors;
91
- }
92
- set lastColors(value) {
93
- this.setState({
94
- lastColors: value,
95
- });
96
- }
97
-
98
- get showPallet() {
99
- return this.state.showPallet;
100
- }
101
- set showPallet(value) {
102
- this.setState({
103
- showPallet: value,
104
- });
105
- }
106
- //#endregion
107
-
108
- updateColor(color) {
109
- this.analysis = ColorConverters.analysisFromCanonical(color);
110
- this.editedColor = color;
111
- }
112
-
113
- UNSAFE_componentWillMount() {
114
- this.updateColor(this.props.color);
115
- if (this.props.pallet) {
116
- this.showPallet = true;
117
- }
118
- MouseTrap.bind('return', this.onTextValidate);
119
- }
120
-
121
- componentWillUnmount() {
122
- super.componentWillUnmount();
123
- MouseTrap.unbind('return', this.onTextValidate);
124
- }
125
-
126
- componentDidUpdate(prevProps) {
127
- if (prevProps.color !== this.props.color) {
128
- this.updateColor(this.props.color);
129
- }
130
- if (!prevProps.pallet && this.props.pallet) {
131
- this.showPallet = true;
132
- }
133
- }
134
-
135
- pushColor(color) {
136
- const lastColors = [...this.lastColors];
137
- if (this.alreadyPushed) {
138
- // A color has already been pushed. Update it.
139
- lastColors[lastColors.length - 1] = color;
140
- } else {
141
- // Add color at the end.
142
- lastColors.push(color);
143
- // Remove excess colors if there are any.
144
- // Keeps much more than 8 colors, because of the duplicates
145
- // that are ignored when displayed.
146
- if (lastColors.length > 100) {
147
- lastColors.splice(0, 1);
148
- }
149
- this.alreadyPushed = true;
150
- }
151
- this.lastColors = lastColors;
152
-
153
- if (this.props.clientSessionId) {
154
- this.doFor(this.props.clientSessionId, 'set-last-colors-picker', {
155
- splitterId: this.props.id,
156
- state: lastColors,
157
- });
158
- }
159
- }
160
-
161
- changeColor(canonical) {
162
- this.updateColor(canonical);
163
-
164
- if (this.props.onChange) {
165
- this.props.onChange(canonical);
166
- }
167
-
168
- this.pushColor(canonical);
169
-
170
- this.info = null;
171
- this.warning = null;
172
- }
173
-
174
- onColorChanged(key, value) {
175
- if (key === 'mode') {
176
- this.showPallet = value === 'PALLET';
177
- if (value === 'PALLET') {
178
- return;
179
- }
180
- }
181
-
182
- const analysis = {...this.analysis};
183
- analysis[key] = value;
184
- this.analysis = analysis;
185
-
186
- const canonical = ColorConverters.analysisToCanonical(analysis);
187
- this.changeColor(canonical);
188
- }
189
-
190
- parseEditedValue(value) {
191
- const {value: parsedValue, error} = ColorConverters.parseEdited(value);
192
- const finalValue = ColorConverters.getDisplayed(parsedValue);
193
- let info = null;
194
- if (finalValue !== value) {
195
- info = finalValue;
196
- }
197
- return {
198
- info,
199
- warning: error,
200
- canonical: parsedValue,
201
- };
202
- }
203
-
204
- onTextEdited(value) {
205
- const p = this.parseEditedValue(value);
206
- this.info = p.info;
207
- this.warning = p.warning;
208
- this.editedColor = value;
209
- }
210
-
211
- onTextChanged(value) {
212
- const p = this.parseEditedValue(value);
213
- this.info = p.info;
214
- this.warning = p.warning;
215
-
216
- if (p.warning === null) {
217
- this.changeColor(p.canonical, true);
218
- }
219
- }
220
-
221
- onTextValidate() {
222
- this.changeColor(this.editedColor, true);
223
- }
224
-
225
- onPaste() {
226
- navigator.clipboard
227
- .readText()
228
- .then((text) => {
229
- if (text && !text.startsWith('#')) {
230
- text = '#' + text;
231
- }
232
- const result = ColorConverters.parseEdited(text);
233
- if (result.error === null) {
234
- this.changeColor(result.value, true);
235
- }
236
- })
237
- .catch((err) => {
238
- console.error('Failed to read clipboard contents: ', err);
239
- });
240
- }
241
-
242
- get mode() {
243
- return this.showPallet && this.props.pallet
244
- ? 'PALLET'
245
- : this.analysis
246
- ? this.analysis.mode
247
- : null;
248
- }
249
-
250
- /******************************************************************************/
251
-
252
- renderMode(glyph, tooltip, mode) {
253
- if (this.props[`show${mode}`] === 'no') {
254
- return null;
255
- }
256
-
257
- return (
258
- <Button
259
- border="none"
260
- horizontalSpacing="overlap"
261
- glyph={glyph}
262
- tooltip={tooltip}
263
- active={this.mode === mode}
264
- onClick={() => this.onColorChanged('mode', mode)}
265
- />
266
- );
267
- }
268
-
269
- renderModes() {
270
- return (
271
- <div className={this.styles.classNames.modes}>
272
- {this.props.pallet
273
- ? this.renderMode('solid/th', T('Palette'), 'PALLET')
274
- : null}
275
- {this.renderMode(
276
- 'solid/palette',
277
- T('Teinte Saturation Luminosité'),
278
- 'HSL'
279
- )}
280
- {this.renderMode('solid/sliders-h', T('Rouge Vert Bleu'), 'RGB')}
281
- {this.renderMode('solid/print', T('Cyan Magenta Jaune Noir'), 'CMYK')}
282
- {this.renderMode('solid/sun', T('Niveau de gris'), 'G')}
283
- <Label width="20px" />
284
- <TextInputInfoNC
285
- value={this.editedColor}
286
- info={this.info}
287
- warning={this.warning}
288
- wrong={!!this.warning}
289
- grow="1"
290
- horizontalSpacing="overlap"
291
- onChange={this.onTextEdited}
292
- onBlur={this.onTextChanged}
293
- />
294
- {this.props.showPaste === 'no' ? null : (
295
- <Button
296
- kind="combo"
297
- glyph="solid/eye-dropper"
298
- tooltip={T('Colle la couleur contenue dans le bloc-notes')}
299
- onClick={this.onPaste}
300
- />
301
- )}
302
- </div>
303
- );
304
- }
305
-
306
- renderComposantSlider(
307
- value,
308
- sliderColor1,
309
- sliderColor2,
310
- key,
311
- range,
312
- isVertical
313
- ) {
314
- const hasSlider = sliderColor1 && sliderColor2;
315
- if (!hasSlider) {
316
- return null;
317
- }
318
-
319
- let gliderSize = 'default';
320
- let cabSize = 'default';
321
- let cabType = 'round';
322
- let gradient = '1to2';
323
- if (key === 'h') {
324
- gliderSize = 'large';
325
- cabSize = 'large';
326
- cabType = 'thin';
327
- gradient = 'rainbow';
328
- } else if (key === 's' || key === 'l') {
329
- gliderSize = 'large';
330
- cabSize = 'large';
331
- } else if (key === 'n') {
332
- gliderSize = 'large';
333
- }
334
-
335
- return (
336
- <Slider
337
- direction="horizontal"
338
- grow={isVertical ? null : '1'}
339
- width={isVertical ? '105px' : null}
340
- min={0}
341
- max={range}
342
- step={1}
343
- value={value}
344
- gliderSize={gliderSize}
345
- cabSize={cabSize}
346
- cabType={cabType}
347
- gradient={gradient}
348
- gradientColor1={sliderColor1}
349
- gradientColor2={sliderColor2}
350
- changeMode="immediate"
351
- onChange={(value) => this.onColorChanged(key, value)}
352
- />
353
- );
354
- }
355
-
356
- renderComposant(
357
- label,
358
- tooltip,
359
- sliderColor1,
360
- sliderColor2,
361
- key,
362
- range,
363
- isVertical
364
- ) {
365
- const analysis = this.analysis;
366
- const value = analysis ? analysis[key] : null;
367
-
368
- if (isVertical) {
369
- return (
370
- <div className={this.styles.classNames.composantVertical}>
371
- <TextFieldTypedNC
372
- width="50px"
373
- tooltip={tooltip}
374
- type="integer"
375
- min={0}
376
- max={range}
377
- value={value}
378
- onChange={(value) => this.onColorChanged(key, value)}
379
- />
380
- <Separator kind="exact" height="5px" />
381
- {this.renderComposantSlider(
382
- value,
383
- sliderColor1,
384
- sliderColor2,
385
- key,
386
- range,
387
- isVertical
388
- )}
389
- </div>
390
- );
391
- } else {
392
- return (
393
- <div className={this.styles.classNames.composantHorizontal}>
394
- <TextFieldTypedNC
395
- width="50px"
396
- tooltip={tooltip}
397
- type="integer"
398
- min={0}
399
- max={range}
400
- value={value}
401
- onChange={(value) => this.onColorChanged(key, value)}
402
- />
403
- <Label width="10px" />
404
- {this.renderComposantSlider(
405
- value,
406
- sliderColor1,
407
- sliderColor2,
408
- key,
409
- range,
410
- isVertical
411
- )}
412
- </div>
413
- );
414
- }
415
- }
416
-
417
- renderComposantsPalletOne(color, index) {
418
- const bc = ColorConverters.toRGB(color);
419
- const style = {
420
- backgroundColor: bc,
421
- };
422
-
423
- return (
424
- <div
425
- key={index}
426
- className={this.styles.classNames.pallet}
427
- style={style}
428
- onClick={() => this.changeColor(color, true)}
429
- ></div>
430
- );
431
- }
432
-
433
- renderComposantsPallet() {
434
- return (
435
- <div className={this.styles.classNames.pallets}>
436
- {this.props.pallet.map((color, index) =>
437
- this.renderComposantsPalletOne(color, index)
438
- )}
439
- </div>
440
- );
441
- }
442
-
443
- renderComposantsRGB() {
444
- return (
445
- <div className={this.styles.classNames.composants}>
446
- {this.renderComposant(
447
- T('R'),
448
- T('Rouge (de 0 à 255)'),
449
- '#f00',
450
- '#f00',
451
- 'r',
452
- 255
453
- )}
454
- {this.renderComposant(
455
- T('V'),
456
- T('Vert (de 0 à 255)'),
457
- '#0f0',
458
- '#0f0',
459
- 'g',
460
- 255
461
- )}
462
- {this.renderComposant(
463
- T('B'),
464
- T('Bleu (de 0 à 255)'),
465
- '#00f',
466
- '#00f',
467
- 'b',
468
- 255
469
- )}
470
- </div>
471
- );
472
- }
473
-
474
- renderComposantsCMYK() {
475
- return (
476
- <div className={this.styles.classNames.composants}>
477
- {this.renderComposant(
478
- T('C'),
479
- T('Cyan (de 0 à 100)'),
480
- '#0ff',
481
- '#0ff',
482
- 'c',
483
- 100
484
- )}
485
- {this.renderComposant(
486
- T('M'),
487
- T('Magenta (de 0 à 100)'),
488
- '#f0f',
489
- '#f0f',
490
- 'm',
491
- 100
492
- )}
493
- {this.renderComposant(
494
- T('J'),
495
- T('Jaune (de 0 à 100)'),
496
- '#ff0',
497
- '#ff0',
498
- 'y',
499
- 100
500
- )}
501
- {this.renderComposant(
502
- T('N'),
503
- T('Noir (de 0 à 100)'),
504
- '#000',
505
- '#000',
506
- 'k',
507
- 100,
508
- false
509
- )}
510
- </div>
511
- );
512
- }
513
-
514
- renderComposantsHSL() {
515
- const analysis = this.analysis;
516
- const t = ColorConverters.toRGB(`HSL(${analysis.h},100,100)`);
517
-
518
- return (
519
- <div className={this.styles.classNames.composantHsl}>
520
- <div className={this.styles.classNames.composantHslFields}>
521
- {this.renderComposant(
522
- T('T'),
523
- T('Teinte (de 0 à 360)'),
524
- t,
525
- t,
526
- 'h',
527
- 360,
528
- true
529
- )}
530
- {this.renderComposant(
531
- T('S'),
532
- T('Saturation (de 0 à 100)'),
533
- '#fff',
534
- t,
535
- 's',
536
- 100,
537
- true
538
- )}
539
- {this.renderComposant(
540
- T('L'),
541
- T('Luminosité (de 0 à 100)'),
542
- '#000',
543
- t,
544
- 'l',
545
- 100,
546
- true
547
- )}
548
- </div>
549
- <div className={this.styles.classNames.composantHslSliders}>
550
- <div className={this.styles.classNames.composantHslCircle}>
551
- <SliderCircle
552
- width="214px"
553
- height="214px"
554
- gliderSize="default"
555
- cabSize="default"
556
- value={analysis.h}
557
- changeMode="immediate"
558
- onChange={(a) => this.onColorChanged('h', Math.round(a))}
559
- />
560
- </div>
561
- <div className={this.styles.classNames.composantHslSquare}>
562
- <SliderXY
563
- width="126px"
564
- height="126px"
565
- cabSize="default"
566
- marginSize="small"
567
- marginStyle="none"
568
- draggingScale={2}
569
- hue={analysis.h}
570
- value={`${analysis.s};${analysis.l}`}
571
- changeMode="immediate"
572
- onChange={(xy) => {
573
- const p = xy.split(';');
574
- this.onColorChanged('s', Math.round(p[0]));
575
- this.onColorChanged('l', Math.round(p[1]));
576
- }}
577
- />
578
- </div>
579
- </div>
580
- </div>
581
- );
582
- }
583
-
584
- renderComposantsGrey() {
585
- return (
586
- <div className={this.styles.classNames.composants}>
587
- {this.renderComposant(
588
- T('N'),
589
- T('Niveau de gris (de 0 à 100)'),
590
- '#fff',
591
- '#000',
592
- 'n',
593
- 100
594
- )}
595
- </div>
596
- );
597
- }
598
-
599
- renderComposants() {
600
- switch (this.mode) {
601
- case 'PALLET':
602
- return this.renderComposantsPallet();
603
- case 'RGB':
604
- return this.renderComposantsRGB();
605
- case 'CMYK':
606
- return this.renderComposantsCMYK();
607
- case 'HSL':
608
- return this.renderComposantsHSL();
609
- case 'G':
610
- return this.renderComposantsGrey();
611
- default:
612
- return null;
613
- }
614
- }
615
-
616
- renderSamples() {
617
- if (!this.analysis) {
618
- return null;
619
- }
620
-
621
- const colorUp = ColorConverters.toRGB(this.initialColor);
622
-
623
- const canonical = ColorConverters.analysisToCanonical(this.analysis);
624
- const colorDown = ColorConverters.toRGB(canonical);
625
-
626
- const fc = (color) =>
627
- ColorConverters.getLuminance(color) < 0.5 ? 'white' : 'black';
628
-
629
- const styleUp = {
630
- backgroundColor: colorUp,
631
- color: fc(this.initialColor),
632
- };
633
-
634
- const styleDown = {
635
- backgroundColor: colorDown,
636
- color: fc(canonical),
637
- };
638
-
639
- return (
640
- <div className={this.styles.classNames.samples}>
641
- <TranslatableDiv
642
- className={this.styles.classNames.sampleUp}
643
- style={styleUp}
644
- workitemId={this.context.desktopId || this.getNearestId()}
645
- title={T('Remet la couleur initiale')}
646
- onClick={() => this.changeColor(this.initialColor, true)}
647
- >
648
- {this.initialColor === canonical ? null : this.initialColor}
649
- </TranslatableDiv>
650
- <TranslatableDiv
651
- className={this.styles.classNames.sampleDown}
652
- style={styleDown}
653
- workitemId={this.context.desktopId || this.getNearestId()}
654
- title={T('Couleur choisie')}
655
- >
656
- {this.initialColor === canonical ? null : canonical}
657
- </TranslatableDiv>
658
- </div>
659
- );
660
- }
661
-
662
- renderLastColor(color, index) {
663
- const style = {
664
- backgroundColor: ColorConverters.toRGB(color),
665
- };
666
-
667
- return (
668
- <div
669
- key={index}
670
- className={this.styles.classNames.lastColor}
671
- style={style}
672
- title={color}
673
- onClick={() => this.changeColor(color, true)}
674
- />
675
- );
676
- }
677
-
678
- renderColorsSet(colorsSet) {
679
- const result = [];
680
- let index = 0;
681
- colorsSet.forEach((color) =>
682
- result.push(this.renderLastColor(color, index++))
683
- );
684
- return result;
685
- }
686
-
687
- renderLastColors() {
688
- if (!this.analysis) {
689
- return null;
690
- }
691
-
692
- // Build the table set of the 8 most recent colors, removing duplicates.
693
- const colorsSet = new Set();
694
- for (let i = this.lastColorsDisplayed.length - 1; i >= 0; i--) {
695
- const color = this.lastColorsDisplayed[i];
696
- colorsSet.add(color);
697
- if (colorsSet.size >= 8) {
698
- break;
699
- }
700
- }
701
-
702
- return (
703
- <div className={this.styles.classNames.lastColors}>
704
- {this.renderColorsSet(colorsSet)}
705
- </div>
706
- );
707
- }
708
-
709
- render() {
710
- return (
711
- <div className={this.styles.classNames.colorPicker}>
712
- {this.renderModes()}
713
- <div className={this.styles.classNames.content}>
714
- {this.renderComposants()}
715
- {this.renderSamples()}
716
- {this.renderLastColors()}
717
- </div>
718
- </div>
719
- );
720
- }
721
- }
722
-
723
- /******************************************************************************/
724
-
725
- registerWidget(ColorPicker, props, scenarios);
726
-
727
- /******************************************************************************/
728
-
729
- export default Widget.connect((state) => {
730
- const userSession = Widget.getUserSession(state);
731
- const clientSessionId = userSession.get('id');
732
- const lastColors = userSession.get('lastColorsPicker') || [];
733
-
734
- return {clientSessionId, lastColors};
735
- })(ColorPicker);
1
+ import React from 'react';
2
+ import props from './props';
3
+ import scenarios from './scenarios';
4
+ import {registerWidget} from 'goblin-gadgets/widgets/widget-doc/widget-list';
5
+ import Widget from 'goblin-laboratory/widgets/widget';
6
+ import * as styles from './styles';
7
+ import throttle from 'lodash/throttle';
8
+ import TextFieldTypedNC from 'goblin-gadgets/widgets/text-field-typed-nc/widget';
9
+ import TextInputInfoNC from 'goblin-gadgets/widgets/text-input-info-nc/widget';
10
+ import Slider from 'goblin-gadgets/widgets/slider/widget';
11
+ import SliderXY from 'goblin-gadgets/widgets/slider-xy/widget';
12
+ import SliderCircle from 'goblin-gadgets/widgets/slider-circle/widget';
13
+ import Label from 'goblin-gadgets/widgets/label/widget';
14
+ import Button from 'goblin-gadgets/widgets/button/widget';
15
+ import Separator from 'goblin-gadgets/widgets/separator/widget';
16
+ import {color as ColorConverters} from 'xcraft-core-converters';
17
+ import T from 't';
18
+ import {TranslatableDiv} from 'goblin-nabu/widgets/helpers/element-helpers';
19
+ import MouseTrap from 'mousetrap';
20
+
21
+ /******************************************************************************/
22
+
23
+ class ColorPicker extends Widget {
24
+ constructor() {
25
+ super(...arguments);
26
+ this.styles = styles;
27
+
28
+ // Warning: initialColor and lastColorsDisplayed are never changed for
29
+ // this instance of ColorPicker.
30
+ this.initialColor = this.props.color;
31
+ this.lastColorsDisplayed = this.props.lastColors
32
+ ? [...this.props.lastColors]
33
+ : [];
34
+ this.alreadyPushed = false;
35
+
36
+ this.state = {
37
+ analysis: {},
38
+ editedColor: null,
39
+ info: null,
40
+ warning: null,
41
+ lastColors: this.props.lastColors ? this.props.lastColors : [],
42
+ showPallet: false,
43
+ };
44
+
45
+ this.onColorChanged = throttle(this.onColorChanged, 50).bind(this);
46
+ this.onTextEdited = this.onTextEdited.bind(this);
47
+ this.onTextChanged = this.onTextChanged.bind(this);
48
+ this.onTextValidate = this.onTextValidate.bind(this);
49
+ this.onPaste = this.onPaste.bind(this);
50
+ }
51
+
52
+ //#region get/set
53
+ get analysis() {
54
+ return this.state.analysis;
55
+ }
56
+ set analysis(value) {
57
+ this.setState({
58
+ analysis: value,
59
+ });
60
+ }
61
+
62
+ get editedColor() {
63
+ return this.state.editedColor;
64
+ }
65
+ set editedColor(value) {
66
+ this.setState({
67
+ editedColor: value,
68
+ });
69
+ }
70
+
71
+ get info() {
72
+ return this.state.info;
73
+ }
74
+ set info(value) {
75
+ this.setState({
76
+ info: value,
77
+ });
78
+ }
79
+
80
+ get warning() {
81
+ return this.state.warning;
82
+ }
83
+ set warning(value) {
84
+ this.setState({
85
+ warning: value,
86
+ });
87
+ }
88
+
89
+ get lastColors() {
90
+ return this.state.lastColors;
91
+ }
92
+ set lastColors(value) {
93
+ this.setState({
94
+ lastColors: value,
95
+ });
96
+ }
97
+
98
+ get showPallet() {
99
+ return this.state.showPallet;
100
+ }
101
+ set showPallet(value) {
102
+ this.setState({
103
+ showPallet: value,
104
+ });
105
+ }
106
+ //#endregion
107
+
108
+ updateColor(color) {
109
+ this.analysis = ColorConverters.analysisFromCanonical(color);
110
+ this.editedColor = color;
111
+ }
112
+
113
+ UNSAFE_componentWillMount() {
114
+ this.updateColor(this.props.color);
115
+ if (this.props.pallet) {
116
+ this.showPallet = true;
117
+ }
118
+ MouseTrap.bind('return', this.onTextValidate);
119
+ }
120
+
121
+ componentWillUnmount() {
122
+ super.componentWillUnmount();
123
+ MouseTrap.unbind('return', this.onTextValidate);
124
+ }
125
+
126
+ componentDidUpdate(prevProps) {
127
+ if (prevProps.color !== this.props.color) {
128
+ this.updateColor(this.props.color);
129
+ }
130
+ if (!prevProps.pallet && this.props.pallet) {
131
+ this.showPallet = true;
132
+ }
133
+ }
134
+
135
+ pushColor(color) {
136
+ const lastColors = [...this.lastColors];
137
+ if (this.alreadyPushed) {
138
+ // A color has already been pushed. Update it.
139
+ lastColors[lastColors.length - 1] = color;
140
+ } else {
141
+ // Add color at the end.
142
+ lastColors.push(color);
143
+ // Remove excess colors if there are any.
144
+ // Keeps much more than 8 colors, because of the duplicates
145
+ // that are ignored when displayed.
146
+ if (lastColors.length > 100) {
147
+ lastColors.splice(0, 1);
148
+ }
149
+ this.alreadyPushed = true;
150
+ }
151
+ this.lastColors = lastColors;
152
+
153
+ if (this.props.clientSessionId) {
154
+ this.doFor(this.props.clientSessionId, 'set-last-colors-picker', {
155
+ splitterId: this.props.id,
156
+ state: lastColors,
157
+ });
158
+ }
159
+ }
160
+
161
+ changeColor(canonical) {
162
+ this.updateColor(canonical);
163
+
164
+ if (this.props.onChange) {
165
+ this.props.onChange(canonical);
166
+ }
167
+
168
+ this.pushColor(canonical);
169
+
170
+ this.info = null;
171
+ this.warning = null;
172
+ }
173
+
174
+ onColorChanged(key, value) {
175
+ if (key === 'mode') {
176
+ this.showPallet = value === 'PALLET';
177
+ if (value === 'PALLET') {
178
+ return;
179
+ }
180
+ }
181
+
182
+ const analysis = {...this.analysis};
183
+ analysis[key] = value;
184
+ this.analysis = analysis;
185
+
186
+ const canonical = ColorConverters.analysisToCanonical(analysis);
187
+ this.changeColor(canonical);
188
+ }
189
+
190
+ parseEditedValue(value) {
191
+ const {value: parsedValue, error} = ColorConverters.parseEdited(value);
192
+ const finalValue = ColorConverters.getDisplayed(parsedValue);
193
+ let info = null;
194
+ if (finalValue !== value) {
195
+ info = finalValue;
196
+ }
197
+ return {
198
+ info,
199
+ warning: error,
200
+ canonical: parsedValue,
201
+ };
202
+ }
203
+
204
+ onTextEdited(value) {
205
+ const p = this.parseEditedValue(value);
206
+ this.info = p.info;
207
+ this.warning = p.warning;
208
+ this.editedColor = value;
209
+ }
210
+
211
+ onTextChanged(value) {
212
+ const p = this.parseEditedValue(value);
213
+ this.info = p.info;
214
+ this.warning = p.warning;
215
+
216
+ if (p.warning === null) {
217
+ this.changeColor(p.canonical, true);
218
+ }
219
+ }
220
+
221
+ onTextValidate() {
222
+ this.changeColor(this.editedColor, true);
223
+ }
224
+
225
+ onPaste() {
226
+ navigator.clipboard
227
+ .readText()
228
+ .then((text) => {
229
+ if (text && !text.startsWith('#')) {
230
+ text = '#' + text;
231
+ }
232
+ const result = ColorConverters.parseEdited(text);
233
+ if (result.error === null) {
234
+ this.changeColor(result.value, true);
235
+ }
236
+ })
237
+ .catch((err) => {
238
+ console.error('Failed to read clipboard contents: ', err);
239
+ });
240
+ }
241
+
242
+ get mode() {
243
+ return this.showPallet && this.props.pallet
244
+ ? 'PALLET'
245
+ : this.analysis
246
+ ? this.analysis.mode
247
+ : null;
248
+ }
249
+
250
+ /******************************************************************************/
251
+
252
+ renderMode(glyph, tooltip, mode) {
253
+ if (this.props[`show${mode}`] === 'no') {
254
+ return null;
255
+ }
256
+
257
+ return (
258
+ <Button
259
+ border="none"
260
+ horizontalSpacing="overlap"
261
+ glyph={glyph}
262
+ tooltip={tooltip}
263
+ active={this.mode === mode}
264
+ onClick={() => this.onColorChanged('mode', mode)}
265
+ />
266
+ );
267
+ }
268
+
269
+ renderModes() {
270
+ return (
271
+ <div className={this.styles.classNames.modes}>
272
+ {this.props.pallet
273
+ ? this.renderMode('solid/th', T('Palette'), 'PALLET')
274
+ : null}
275
+ {this.renderMode(
276
+ 'solid/palette',
277
+ T('Teinte Saturation Luminosité'),
278
+ 'HSL'
279
+ )}
280
+ {this.renderMode('solid/sliders-h', T('Rouge Vert Bleu'), 'RGB')}
281
+ {this.renderMode('solid/print', T('Cyan Magenta Jaune Noir'), 'CMYK')}
282
+ {this.renderMode('solid/sun', T('Niveau de gris'), 'G')}
283
+ <Label width="20px" />
284
+ <TextInputInfoNC
285
+ value={this.editedColor}
286
+ info={this.info}
287
+ warning={this.warning}
288
+ wrong={!!this.warning}
289
+ grow="1"
290
+ horizontalSpacing="overlap"
291
+ onChange={this.onTextEdited}
292
+ onBlur={this.onTextChanged}
293
+ />
294
+ {this.props.showPaste === 'no' ? null : (
295
+ <Button
296
+ kind="combo"
297
+ glyph="solid/eye-dropper"
298
+ tooltip={T('Colle la couleur contenue dans le bloc-notes')}
299
+ onClick={this.onPaste}
300
+ />
301
+ )}
302
+ </div>
303
+ );
304
+ }
305
+
306
+ renderComposantSlider(
307
+ value,
308
+ sliderColor1,
309
+ sliderColor2,
310
+ key,
311
+ range,
312
+ isVertical
313
+ ) {
314
+ const hasSlider = sliderColor1 && sliderColor2;
315
+ if (!hasSlider) {
316
+ return null;
317
+ }
318
+
319
+ let gliderSize = 'default';
320
+ let cabSize = 'default';
321
+ let cabType = 'round';
322
+ let gradient = '1to2';
323
+ if (key === 'h') {
324
+ gliderSize = 'large';
325
+ cabSize = 'large';
326
+ cabType = 'thin';
327
+ gradient = 'rainbow';
328
+ } else if (key === 's' || key === 'l') {
329
+ gliderSize = 'large';
330
+ cabSize = 'large';
331
+ } else if (key === 'n') {
332
+ gliderSize = 'large';
333
+ }
334
+
335
+ return (
336
+ <Slider
337
+ direction="horizontal"
338
+ grow={isVertical ? null : '1'}
339
+ width={isVertical ? '105px' : null}
340
+ min={0}
341
+ max={range}
342
+ step={1}
343
+ value={value}
344
+ gliderSize={gliderSize}
345
+ cabSize={cabSize}
346
+ cabType={cabType}
347
+ gradient={gradient}
348
+ gradientColor1={sliderColor1}
349
+ gradientColor2={sliderColor2}
350
+ changeMode="immediate"
351
+ onChange={(value) => this.onColorChanged(key, value)}
352
+ />
353
+ );
354
+ }
355
+
356
+ renderComposant(
357
+ label,
358
+ tooltip,
359
+ sliderColor1,
360
+ sliderColor2,
361
+ key,
362
+ range,
363
+ isVertical
364
+ ) {
365
+ const analysis = this.analysis;
366
+ const value = analysis ? analysis[key] : null;
367
+
368
+ if (isVertical) {
369
+ return (
370
+ <div className={this.styles.classNames.composantVertical}>
371
+ <TextFieldTypedNC
372
+ width="50px"
373
+ tooltip={tooltip}
374
+ type="integer"
375
+ min={0}
376
+ max={range}
377
+ value={value}
378
+ onChange={(value) => this.onColorChanged(key, value)}
379
+ />
380
+ <Separator kind="exact" height="5px" />
381
+ {this.renderComposantSlider(
382
+ value,
383
+ sliderColor1,
384
+ sliderColor2,
385
+ key,
386
+ range,
387
+ isVertical
388
+ )}
389
+ </div>
390
+ );
391
+ } else {
392
+ return (
393
+ <div className={this.styles.classNames.composantHorizontal}>
394
+ <TextFieldTypedNC
395
+ width="50px"
396
+ tooltip={tooltip}
397
+ type="integer"
398
+ min={0}
399
+ max={range}
400
+ value={value}
401
+ onChange={(value) => this.onColorChanged(key, value)}
402
+ />
403
+ <Label width="10px" />
404
+ {this.renderComposantSlider(
405
+ value,
406
+ sliderColor1,
407
+ sliderColor2,
408
+ key,
409
+ range,
410
+ isVertical
411
+ )}
412
+ </div>
413
+ );
414
+ }
415
+ }
416
+
417
+ renderComposantsPalletOne(color, index) {
418
+ const bc = ColorConverters.toRGB(color);
419
+ const style = {
420
+ backgroundColor: bc,
421
+ };
422
+
423
+ return (
424
+ <div
425
+ key={index}
426
+ className={this.styles.classNames.pallet}
427
+ style={style}
428
+ onClick={() => this.changeColor(color, true)}
429
+ ></div>
430
+ );
431
+ }
432
+
433
+ renderComposantsPallet() {
434
+ return (
435
+ <div className={this.styles.classNames.pallets}>
436
+ {this.props.pallet.map((color, index) =>
437
+ this.renderComposantsPalletOne(color, index)
438
+ )}
439
+ </div>
440
+ );
441
+ }
442
+
443
+ renderComposantsRGB() {
444
+ return (
445
+ <div className={this.styles.classNames.composants}>
446
+ {this.renderComposant(
447
+ T('R'),
448
+ T('Rouge (de 0 à 255)'),
449
+ '#f00',
450
+ '#f00',
451
+ 'r',
452
+ 255
453
+ )}
454
+ {this.renderComposant(
455
+ T('V'),
456
+ T('Vert (de 0 à 255)'),
457
+ '#0f0',
458
+ '#0f0',
459
+ 'g',
460
+ 255
461
+ )}
462
+ {this.renderComposant(
463
+ T('B'),
464
+ T('Bleu (de 0 à 255)'),
465
+ '#00f',
466
+ '#00f',
467
+ 'b',
468
+ 255
469
+ )}
470
+ </div>
471
+ );
472
+ }
473
+
474
+ renderComposantsCMYK() {
475
+ return (
476
+ <div className={this.styles.classNames.composants}>
477
+ {this.renderComposant(
478
+ T('C'),
479
+ T('Cyan (de 0 à 100)'),
480
+ '#0ff',
481
+ '#0ff',
482
+ 'c',
483
+ 100
484
+ )}
485
+ {this.renderComposant(
486
+ T('M'),
487
+ T('Magenta (de 0 à 100)'),
488
+ '#f0f',
489
+ '#f0f',
490
+ 'm',
491
+ 100
492
+ )}
493
+ {this.renderComposant(
494
+ T('J'),
495
+ T('Jaune (de 0 à 100)'),
496
+ '#ff0',
497
+ '#ff0',
498
+ 'y',
499
+ 100
500
+ )}
501
+ {this.renderComposant(
502
+ T('N'),
503
+ T('Noir (de 0 à 100)'),
504
+ '#000',
505
+ '#000',
506
+ 'k',
507
+ 100,
508
+ false
509
+ )}
510
+ </div>
511
+ );
512
+ }
513
+
514
+ renderComposantsHSL() {
515
+ const analysis = this.analysis;
516
+ const t = ColorConverters.toRGB(`HSL(${analysis.h},100,100)`);
517
+
518
+ return (
519
+ <div className={this.styles.classNames.composantHsl}>
520
+ <div className={this.styles.classNames.composantHslFields}>
521
+ {this.renderComposant(
522
+ T('T'),
523
+ T('Teinte (de 0 à 360)'),
524
+ t,
525
+ t,
526
+ 'h',
527
+ 360,
528
+ true
529
+ )}
530
+ {this.renderComposant(
531
+ T('S'),
532
+ T('Saturation (de 0 à 100)'),
533
+ '#fff',
534
+ t,
535
+ 's',
536
+ 100,
537
+ true
538
+ )}
539
+ {this.renderComposant(
540
+ T('L'),
541
+ T('Luminosité (de 0 à 100)'),
542
+ '#000',
543
+ t,
544
+ 'l',
545
+ 100,
546
+ true
547
+ )}
548
+ </div>
549
+ <div className={this.styles.classNames.composantHslSliders}>
550
+ <div className={this.styles.classNames.composantHslCircle}>
551
+ <SliderCircle
552
+ width="214px"
553
+ height="214px"
554
+ gliderSize="default"
555
+ cabSize="default"
556
+ value={analysis.h}
557
+ changeMode="immediate"
558
+ onChange={(a) => this.onColorChanged('h', Math.round(a))}
559
+ />
560
+ </div>
561
+ <div className={this.styles.classNames.composantHslSquare}>
562
+ <SliderXY
563
+ width="126px"
564
+ height="126px"
565
+ cabSize="default"
566
+ marginSize="small"
567
+ marginStyle="none"
568
+ draggingScale={2}
569
+ hue={analysis.h}
570
+ value={`${analysis.s};${analysis.l}`}
571
+ changeMode="immediate"
572
+ onChange={(xy) => {
573
+ const p = xy.split(';');
574
+ this.onColorChanged('s', Math.round(p[0]));
575
+ this.onColorChanged('l', Math.round(p[1]));
576
+ }}
577
+ />
578
+ </div>
579
+ </div>
580
+ </div>
581
+ );
582
+ }
583
+
584
+ renderComposantsGrey() {
585
+ return (
586
+ <div className={this.styles.classNames.composants}>
587
+ {this.renderComposant(
588
+ T('N'),
589
+ T('Niveau de gris (de 0 à 100)'),
590
+ '#fff',
591
+ '#000',
592
+ 'n',
593
+ 100
594
+ )}
595
+ </div>
596
+ );
597
+ }
598
+
599
+ renderComposants() {
600
+ switch (this.mode) {
601
+ case 'PALLET':
602
+ return this.renderComposantsPallet();
603
+ case 'RGB':
604
+ return this.renderComposantsRGB();
605
+ case 'CMYK':
606
+ return this.renderComposantsCMYK();
607
+ case 'HSL':
608
+ return this.renderComposantsHSL();
609
+ case 'G':
610
+ return this.renderComposantsGrey();
611
+ default:
612
+ return null;
613
+ }
614
+ }
615
+
616
+ renderSamples() {
617
+ if (!this.analysis) {
618
+ return null;
619
+ }
620
+
621
+ const colorUp = ColorConverters.toRGB(this.initialColor);
622
+
623
+ const canonical = ColorConverters.analysisToCanonical(this.analysis);
624
+ const colorDown = ColorConverters.toRGB(canonical);
625
+
626
+ const fc = (color) =>
627
+ ColorConverters.getLuminance(color) < 0.5 ? 'white' : 'black';
628
+
629
+ const styleUp = {
630
+ backgroundColor: colorUp,
631
+ color: fc(this.initialColor),
632
+ };
633
+
634
+ const styleDown = {
635
+ backgroundColor: colorDown,
636
+ color: fc(canonical),
637
+ };
638
+
639
+ return (
640
+ <div className={this.styles.classNames.samples}>
641
+ <TranslatableDiv
642
+ className={this.styles.classNames.sampleUp}
643
+ style={styleUp}
644
+ workitemId={this.context.desktopId || this.getNearestId()}
645
+ title={T('Remet la couleur initiale')}
646
+ onClick={() => this.changeColor(this.initialColor, true)}
647
+ >
648
+ {this.initialColor === canonical ? null : this.initialColor}
649
+ </TranslatableDiv>
650
+ <TranslatableDiv
651
+ className={this.styles.classNames.sampleDown}
652
+ style={styleDown}
653
+ workitemId={this.context.desktopId || this.getNearestId()}
654
+ title={T('Couleur choisie')}
655
+ >
656
+ {this.initialColor === canonical ? null : canonical}
657
+ </TranslatableDiv>
658
+ </div>
659
+ );
660
+ }
661
+
662
+ renderLastColor(color, index) {
663
+ const style = {
664
+ backgroundColor: ColorConverters.toRGB(color),
665
+ };
666
+
667
+ return (
668
+ <div
669
+ key={index}
670
+ className={this.styles.classNames.lastColor}
671
+ style={style}
672
+ title={color}
673
+ onClick={() => this.changeColor(color, true)}
674
+ />
675
+ );
676
+ }
677
+
678
+ renderColorsSet(colorsSet) {
679
+ const result = [];
680
+ let index = 0;
681
+ colorsSet.forEach((color) =>
682
+ result.push(this.renderLastColor(color, index++))
683
+ );
684
+ return result;
685
+ }
686
+
687
+ renderLastColors() {
688
+ if (!this.analysis) {
689
+ return null;
690
+ }
691
+
692
+ // Build the table set of the 8 most recent colors, removing duplicates.
693
+ const colorsSet = new Set();
694
+ for (let i = this.lastColorsDisplayed.length - 1; i >= 0; i--) {
695
+ const color = this.lastColorsDisplayed[i];
696
+ colorsSet.add(color);
697
+ if (colorsSet.size >= 8) {
698
+ break;
699
+ }
700
+ }
701
+
702
+ return (
703
+ <div className={this.styles.classNames.lastColors}>
704
+ {this.renderColorsSet(colorsSet)}
705
+ </div>
706
+ );
707
+ }
708
+
709
+ render() {
710
+ return (
711
+ <div className={this.styles.classNames.colorPicker}>
712
+ {this.renderModes()}
713
+ <div className={this.styles.classNames.content}>
714
+ {this.renderComposants()}
715
+ {this.renderSamples()}
716
+ {this.renderLastColors()}
717
+ </div>
718
+ </div>
719
+ );
720
+ }
721
+ }
722
+
723
+ /******************************************************************************/
724
+
725
+ registerWidget(ColorPicker, props, scenarios);
726
+
727
+ /******************************************************************************/
728
+
729
+ export default Widget.connect((state) => {
730
+ const userSession = Widget.getUserSession(state);
731
+ const clientSessionId = userSession.get('id');
732
+ const lastColors = userSession.get('lastColorsPicker') || [];
733
+
734
+ return {clientSessionId, lastColors};
735
+ })(ColorPicker);