aloha-vue 2.86.0 → 2.87.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 +7 -0
- package/dist/aloha-vue.css +21 -0
- package/dist/aloha-vue.css.map +1 -1
- package/dist/aloha-vue.es.js +2428 -2361
- package/dist/aloha-vue.umd.js +102 -102
- package/package.json +1 -1
- package/scss/components/ui/AColorPicker.scss +20 -0
- package/src/ui/AColorPicker/AColorPicker.js +70 -24
- package/src/ui/AColorPicker/__tests__/AColorPicker.test.js +66 -1
- package/src/ui/AColorPicker/__tests__/colorUtils.test.js +12 -0
- package/src/ui/AColorPicker/compositionAPI/ColorStateAPI.js +28 -3
- package/src/ui/AColorPicker/compositionAPI/FormatAPI.js +59 -0
- package/src/ui/AColorPicker/compositionAPI/PopoverAPI.js +20 -3
- package/src/ui/AColorPicker/i18n/ar.json +2 -1
- package/src/ui/AColorPicker/i18n/de.json +2 -1
- package/src/ui/AColorPicker/i18n/en.json +2 -1
- package/src/ui/AColorPicker/i18n/es.json +2 -1
- package/src/ui/AColorPicker/i18n/fr.json +2 -1
- package/src/ui/AColorPicker/i18n/hr.json +2 -1
- package/src/ui/AColorPicker/i18n/it.json +2 -1
- package/src/ui/AColorPicker/i18n/nl.json +2 -1
- package/src/ui/AColorPicker/i18n/pl.json +2 -1
- package/src/ui/AColorPicker/i18n/ru.json +2 -1
- package/src/ui/AColorPicker/i18n/uk.json +2 -1
- package/src/ui/AColorPicker/utils/colorUtils.js +15 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aloha-vue",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.87.0",
|
|
4
4
|
"description": "Aloha-vue is a JavaScript library that provides a wide range of accessible components and directives for Vue.js. Accessibility is of paramount importance to us, and we have designed all our components to meet accessibility compliance criteria. This library is a valuable tool for frontend developers and has already been used in three projects, including two large-scale ones",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"accessibility compliance criteria",
|
|
@@ -103,6 +103,10 @@
|
|
|
103
103
|
box-shadow: var(--a_color_picker_popup_shadow, 0 0.5rem 1rem rgba(0, 0, 0, 0.15));
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
.a_color_picker__popup_positioning {
|
|
107
|
+
visibility: hidden;
|
|
108
|
+
}
|
|
109
|
+
|
|
106
110
|
// Thumbs of the saturation area and the sliders
|
|
107
111
|
.a_color_picker_saturation__thumb,
|
|
108
112
|
.a_color_picker_slider__thumb {
|
|
@@ -185,6 +189,22 @@
|
|
|
185
189
|
border-radius: var(--a_border_radius, 0.375rem);
|
|
186
190
|
}
|
|
187
191
|
|
|
192
|
+
.a_color_picker__value {
|
|
193
|
+
display: flex;
|
|
194
|
+
align-items: flex-start;
|
|
195
|
+
gap: 0.5rem;
|
|
196
|
+
> .a_color_picker__input {
|
|
197
|
+
flex: 1;
|
|
198
|
+
min-width: 0;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
.a_color_picker__format {
|
|
202
|
+
flex-shrink: 0;
|
|
203
|
+
min-width: 3.5rem;
|
|
204
|
+
min-height: calc(1.5em + 0.75rem + 2px);
|
|
205
|
+
font-variant-numeric: tabular-nums;
|
|
206
|
+
}
|
|
207
|
+
|
|
188
208
|
.a_color_picker__predefine {
|
|
189
209
|
display: flex;
|
|
190
210
|
flex-wrap: wrap;
|
|
@@ -26,6 +26,7 @@ import AColorPickerSlider from "./AColorPickerSlider/AColorPickerSlider";
|
|
|
26
26
|
|
|
27
27
|
import ColorStateAPI from "./compositionAPI/ColorStateAPI";
|
|
28
28
|
import ConfirmAPI from "./compositionAPI/ConfirmAPI";
|
|
29
|
+
import FormatAPI from "./compositionAPI/FormatAPI";
|
|
29
30
|
import InputAPI from "./compositionAPI/InputAPI";
|
|
30
31
|
import PopoverAPI from "./compositionAPI/PopoverAPI";
|
|
31
32
|
import PredefineAPI from "./compositionAPI/PredefineAPI";
|
|
@@ -36,6 +37,7 @@ import {
|
|
|
36
37
|
COLOR_FORMATS,
|
|
37
38
|
} from "./utils/colorUtils";
|
|
38
39
|
import {
|
|
40
|
+
isArray,
|
|
39
41
|
uniqueId,
|
|
40
42
|
} from "lodash-es";
|
|
41
43
|
|
|
@@ -59,11 +61,11 @@ export default {
|
|
|
59
61
|
required: false,
|
|
60
62
|
default: undefined,
|
|
61
63
|
},
|
|
62
|
-
|
|
63
|
-
type: String,
|
|
64
|
+
colorFormats: {
|
|
65
|
+
type: [String, Array],
|
|
64
66
|
required: false,
|
|
65
67
|
default: "hex",
|
|
66
|
-
validator: value => COLOR_FORMATS.indexOf(
|
|
68
|
+
validator: value => (isArray(value) ? value : [value]).every(format => COLOR_FORMATS.indexOf(format) !== -1),
|
|
67
69
|
},
|
|
68
70
|
dependencies: {
|
|
69
71
|
type: [Array, Object],
|
|
@@ -238,6 +240,14 @@ export default {
|
|
|
238
240
|
componentStyleHide,
|
|
239
241
|
} = UiStyleHideAPI(props);
|
|
240
242
|
|
|
243
|
+
const {
|
|
244
|
+
currentFormat,
|
|
245
|
+
isFormatSwitch,
|
|
246
|
+
nextFormat,
|
|
247
|
+
setFormatFromModel,
|
|
248
|
+
switchFormat,
|
|
249
|
+
} = FormatAPI(props);
|
|
250
|
+
|
|
241
251
|
const {
|
|
242
252
|
alphaBackground,
|
|
243
253
|
alphaPercent,
|
|
@@ -254,7 +264,9 @@ export default {
|
|
|
254
264
|
setHue,
|
|
255
265
|
setSaturationBrightness,
|
|
256
266
|
valueLocal,
|
|
257
|
-
} = ColorStateAPI(props
|
|
267
|
+
} = ColorStateAPI(props, {
|
|
268
|
+
currentFormat,
|
|
269
|
+
});
|
|
258
270
|
|
|
259
271
|
const {
|
|
260
272
|
ariaDescribedbyLocal,
|
|
@@ -272,6 +284,7 @@ export default {
|
|
|
272
284
|
const {
|
|
273
285
|
closePopover,
|
|
274
286
|
isOpen,
|
|
287
|
+
isPositioned,
|
|
275
288
|
onPopupKeydown,
|
|
276
289
|
onToggleKeydown,
|
|
277
290
|
popupId,
|
|
@@ -280,7 +293,10 @@ export default {
|
|
|
280
293
|
togglePopover,
|
|
281
294
|
} = PopoverAPI(props, context, {
|
|
282
295
|
htmlIdLocal,
|
|
283
|
-
setColorFromModel
|
|
296
|
+
setColorFromModel: () => {
|
|
297
|
+
setFormatFromModel();
|
|
298
|
+
setColorFromModel();
|
|
299
|
+
},
|
|
284
300
|
});
|
|
285
301
|
|
|
286
302
|
const {
|
|
@@ -349,6 +365,7 @@ export default {
|
|
|
349
365
|
confirmColor,
|
|
350
366
|
cssColorLocal,
|
|
351
367
|
cssColorOpaqueLocal,
|
|
368
|
+
currentFormat,
|
|
352
369
|
disabledAttribut,
|
|
353
370
|
errorsId,
|
|
354
371
|
hasErrorIcon,
|
|
@@ -360,12 +377,15 @@ export default {
|
|
|
360
377
|
inputText,
|
|
361
378
|
isClearButtonLocal,
|
|
362
379
|
isErrors,
|
|
380
|
+
isFormatSwitch,
|
|
363
381
|
isModel,
|
|
364
382
|
isOpen,
|
|
383
|
+
isPositioned,
|
|
365
384
|
labelDescriptionId,
|
|
366
385
|
labelId,
|
|
367
386
|
modelCssColor,
|
|
368
387
|
modelTextColor,
|
|
388
|
+
nextFormat,
|
|
369
389
|
onBlur,
|
|
370
390
|
onFocus,
|
|
371
391
|
onInputChange,
|
|
@@ -379,6 +399,7 @@ export default {
|
|
|
379
399
|
setAlphaPercent,
|
|
380
400
|
setHue,
|
|
381
401
|
setSaturationBrightness,
|
|
402
|
+
switchFormat,
|
|
382
403
|
toggleClassBtns,
|
|
383
404
|
togglePopover,
|
|
384
405
|
toggleRef,
|
|
@@ -553,7 +574,12 @@ export default {
|
|
|
553
574
|
h("div", {
|
|
554
575
|
ref: "popupRef",
|
|
555
576
|
id: this.popupId,
|
|
556
|
-
class:
|
|
577
|
+
class: [
|
|
578
|
+
"a_color_picker__popup",
|
|
579
|
+
{
|
|
580
|
+
a_color_picker__popup_positioning: !this.isPositioned,
|
|
581
|
+
},
|
|
582
|
+
],
|
|
557
583
|
role: "dialog",
|
|
558
584
|
"aria-modal": "true",
|
|
559
585
|
"aria-labelledby": hasLabel ? this.labelId : undefined,
|
|
@@ -618,24 +644,44 @@ export default {
|
|
|
618
644
|
ariaHidden: true,
|
|
619
645
|
}),
|
|
620
646
|
]),
|
|
621
|
-
h(
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
647
|
+
h("div", {
|
|
648
|
+
class: "a_color_picker__value",
|
|
649
|
+
}, [
|
|
650
|
+
h(AInput, {
|
|
651
|
+
id: `${ this.htmlIdLocal }_input`,
|
|
652
|
+
alwaysTranslate: this.alwaysTranslate,
|
|
653
|
+
class: "a_color_picker__input",
|
|
654
|
+
errors: this.inputErrors,
|
|
655
|
+
inputAttributes: {
|
|
656
|
+
autocomplete: "off",
|
|
657
|
+
spellcheck: "false",
|
|
658
|
+
onKeydown: this.onInputKeydown,
|
|
659
|
+
},
|
|
660
|
+
extra: {
|
|
661
|
+
format: this.currentFormat.toUpperCase(),
|
|
662
|
+
},
|
|
663
|
+
isClearButton: false,
|
|
664
|
+
label: "_A_COLOR_PICKER_INPUT_{{format}}_",
|
|
665
|
+
modelValue: this.inputText,
|
|
666
|
+
change: this.onInputChange,
|
|
667
|
+
onBlur: this.applyInput,
|
|
668
|
+
}),
|
|
669
|
+
this.isFormatSwitch ?
|
|
670
|
+
h(AButton, {
|
|
671
|
+
alwaysTranslate: this.alwaysTranslate,
|
|
672
|
+
ariaLabel: "_A_COLOR_PICKER_FORMAT_SWITCH_{{format}}_{{next}}_",
|
|
673
|
+
extra: {
|
|
674
|
+
format: this.currentFormat.toUpperCase(),
|
|
675
|
+
next: this.nextFormat.toUpperCase(),
|
|
676
|
+
},
|
|
677
|
+
class: "a_btn a_btn_outline_secondary a_btn_small a_color_picker__format",
|
|
678
|
+
text: this.currentFormat.toUpperCase(),
|
|
679
|
+
title: "_A_COLOR_PICKER_FORMAT_SWITCH_{{format}}_{{next}}_",
|
|
680
|
+
type: "button",
|
|
681
|
+
onClick: this.switchFormat,
|
|
682
|
+
}) :
|
|
683
|
+
"",
|
|
684
|
+
]),
|
|
639
685
|
this.predefineLocal.length ?
|
|
640
686
|
h("div", {
|
|
641
687
|
class: "a_color_picker__predefine",
|
|
@@ -77,6 +77,21 @@ describe("AColorPicker", () => {
|
|
|
77
77
|
wrapper.unmount();
|
|
78
78
|
});
|
|
79
79
|
|
|
80
|
+
it("focuses the dialog only after it is positioned", async() => {
|
|
81
|
+
const wrapper = mountPicker({ modelValue: "#ff0000" });
|
|
82
|
+
await wrapper.get("button.a_color_picker__toggle").trigger("click");
|
|
83
|
+
await nextTick();
|
|
84
|
+
|
|
85
|
+
expect(getPopup().classList.contains("a_color_picker__popup_positioning")).toBe(true);
|
|
86
|
+
|
|
87
|
+
await new Promise(resolve => setTimeout(resolve, 20));
|
|
88
|
+
await flush();
|
|
89
|
+
|
|
90
|
+
expect(getPopup().classList.contains("a_color_picker__popup_positioning")).toBe(false);
|
|
91
|
+
expect(document.activeElement.classList.contains("a_color_picker_saturation__thumb")).toBe(true);
|
|
92
|
+
wrapper.unmount();
|
|
93
|
+
});
|
|
94
|
+
|
|
80
95
|
it("closes with Escape without changing the model and returns the focus", async() => {
|
|
81
96
|
const wrapper = mountPicker({ modelValue: "#ff0000" });
|
|
82
97
|
const toggle = wrapper.get("button.a_color_picker__toggle");
|
|
@@ -96,7 +111,7 @@ describe("AColorPicker", () => {
|
|
|
96
111
|
});
|
|
97
112
|
|
|
98
113
|
it("applies a typed value and shows an error for an invalid one", async() => {
|
|
99
|
-
const wrapper = mountPicker({ modelValue: "#ff0000",
|
|
114
|
+
const wrapper = mountPicker({ modelValue: "#ff0000", colorFormats: "rgb", showAlpha: true });
|
|
100
115
|
await wrapper.get("button.a_color_picker__toggle").trigger("click");
|
|
101
116
|
await flush();
|
|
102
117
|
|
|
@@ -116,6 +131,56 @@ describe("AColorPicker", () => {
|
|
|
116
131
|
wrapper.unmount();
|
|
117
132
|
});
|
|
118
133
|
|
|
134
|
+
it("opens with the format of the model and switches formats in the given order", async() => {
|
|
135
|
+
const wrapper = mountPicker({ modelValue: "hsl(0, 100%, 50%)", colorFormats: ["hex", "hsl", "rgb"] });
|
|
136
|
+
await wrapper.get("button.a_color_picker__toggle").trigger("click");
|
|
137
|
+
await flush();
|
|
138
|
+
|
|
139
|
+
const input = () => getPopup().querySelector(".a_color_picker__input input");
|
|
140
|
+
const switchButton = () => getPopup().querySelector(".a_color_picker__format");
|
|
141
|
+
expect(input().value).toBe("hsl(0, 100%, 50%)");
|
|
142
|
+
expect(switchButton().textContent).toBe("HSL");
|
|
143
|
+
expect(switchButton().getAttribute("aria-label")).toBe("_A_COLOR_PICKER_FORMAT_SWITCH_{{format}}_{{next}}_");
|
|
144
|
+
|
|
145
|
+
switchButton().click();
|
|
146
|
+
await flush();
|
|
147
|
+
expect(input().value).toBe("rgb(255, 0, 0)");
|
|
148
|
+
switchButton().click();
|
|
149
|
+
await flush();
|
|
150
|
+
expect(input().value).toBe("#ff0000");
|
|
151
|
+
|
|
152
|
+
[...getPopup().querySelectorAll("button")].find(button => button.textContent.includes("_A_COLOR_PICKER_CONFIRM_")).click();
|
|
153
|
+
await flush();
|
|
154
|
+
expect(wrapper.emitted("update:modelValue").at(-1)).toEqual(["#ff0000"]);
|
|
155
|
+
wrapper.unmount();
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("keeps the model text when nothing is changed", async() => {
|
|
159
|
+
const wrapper = mountPicker({ modelValue: "hsl(145, 63%, 29%)", colorFormats: ["hex", "hsl"] });
|
|
160
|
+
await wrapper.get("button.a_color_picker__toggle").trigger("click");
|
|
161
|
+
await flush();
|
|
162
|
+
|
|
163
|
+
expect(getPopup().querySelector(".a_color_picker__input input").value).toBe("hsl(145, 63%, 29%)");
|
|
164
|
+
[...getPopup().querySelectorAll("button")].find(button => button.textContent.includes("_A_COLOR_PICKER_CONFIRM_")).click();
|
|
165
|
+
await flush();
|
|
166
|
+
expect(wrapper.emitted("update:modelValue").at(-1)).toEqual(["hsl(145, 63%, 29%)"]);
|
|
167
|
+
wrapper.unmount();
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("uses the first format if the model format is not allowed and hides the switch for one format", async() => {
|
|
171
|
+
const wrapper = mountPicker({ modelValue: "#ff0000", colorFormats: ["rgb", "hsv"] });
|
|
172
|
+
await wrapper.get("button.a_color_picker__toggle").trigger("click");
|
|
173
|
+
await flush();
|
|
174
|
+
expect(getPopup().querySelector(".a_color_picker__input input").value).toBe("rgb(255, 0, 0)");
|
|
175
|
+
wrapper.unmount();
|
|
176
|
+
|
|
177
|
+
const single = mountPicker({ modelValue: "#ff0000", colorFormats: "hex" });
|
|
178
|
+
await single.get("button.a_color_picker__toggle").trigger("click");
|
|
179
|
+
await flush();
|
|
180
|
+
expect(getPopup().querySelector(".a_color_picker__format")).toBeNull();
|
|
181
|
+
single.unmount();
|
|
182
|
+
});
|
|
183
|
+
|
|
119
184
|
it("marks the selected predefined color", async() => {
|
|
120
185
|
const wrapper = mountPicker({ modelValue: "#ff0000", predefine: ["#ff0000", "#00ff00", "invalid"] });
|
|
121
186
|
await wrapper.get("button.a_color_picker__toggle").trigger("click");
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
contrastRatio,
|
|
9
|
+
detectColorFormat,
|
|
9
10
|
formatColor,
|
|
10
11
|
getContrastTextColor,
|
|
11
12
|
hslToHsv,
|
|
@@ -42,6 +43,17 @@ describe("colorUtils parseColor", () => {
|
|
|
42
43
|
});
|
|
43
44
|
});
|
|
44
45
|
|
|
46
|
+
describe("colorUtils detectColorFormat", () => {
|
|
47
|
+
it("detects the format of a value", () => {
|
|
48
|
+
expect(detectColorFormat("#0775b0")).toBe("hex");
|
|
49
|
+
expect(detectColorFormat("RGBA(7, 117, 176, .5)")).toBe("rgb");
|
|
50
|
+
expect(detectColorFormat("hsl(0, 100%, 50%)")).toBe("hsl");
|
|
51
|
+
expect(detectColorFormat("hsva(0, 100%, 100%, 1)")).toBe("hsv");
|
|
52
|
+
expect(detectColorFormat("red")).toBeUndefined();
|
|
53
|
+
expect(detectColorFormat(undefined)).toBeUndefined();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
45
57
|
describe("colorUtils formatColor", () => {
|
|
46
58
|
const COLOR = { r: 7, g: 117, b: 176, a: 0.5 };
|
|
47
59
|
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
} from "vue";
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
|
+
detectColorFormat,
|
|
8
9
|
formatColor,
|
|
9
10
|
getContrastTextColor,
|
|
10
11
|
hsvToRgb,
|
|
@@ -12,20 +13,31 @@ import {
|
|
|
12
13
|
rgbToHsv,
|
|
13
14
|
toCssColor,
|
|
14
15
|
} from "../utils/colorUtils";
|
|
16
|
+
import {
|
|
17
|
+
isEqual,
|
|
18
|
+
} from "lodash-es";
|
|
15
19
|
|
|
16
20
|
const COLOR_FALLBACK = { r: 255, g: 0, b: 0, a: 1 };
|
|
17
21
|
|
|
18
22
|
/**
|
|
19
23
|
* State of the panel (hsva) and the colors derived from it and from the model.
|
|
20
24
|
*/
|
|
21
|
-
export default function ColorStateAPI(props
|
|
22
|
-
|
|
25
|
+
export default function ColorStateAPI(props, {
|
|
26
|
+
currentFormat = ref("hex"),
|
|
27
|
+
} = {}) {
|
|
23
28
|
const modelValue = toRef(props, "modelValue");
|
|
24
29
|
const panelDefaultColor = toRef(props, "panelDefaultColor");
|
|
25
30
|
const showAlpha = toRef(props, "showAlpha");
|
|
26
31
|
|
|
27
32
|
const hsva = ref({ h: 0, s: 100, v: 100, a: 1 });
|
|
28
33
|
|
|
34
|
+
/*
|
|
35
|
+
* The model value as it was when the dialog was opened. As long as the color
|
|
36
|
+
* and the format are not changed, this text is shown and written back,
|
|
37
|
+
* so e.g. "hsl(145, 63%, 29%)" does not become "hsl(145, 64%, 29%)" by rounding.
|
|
38
|
+
*/
|
|
39
|
+
const modelSnapshot = ref(undefined);
|
|
40
|
+
|
|
29
41
|
const modelColor = computed(() => parseColor(modelValue.value));
|
|
30
42
|
|
|
31
43
|
const modelCssColor = computed(() => {
|
|
@@ -44,7 +56,12 @@ export default function ColorStateAPI(props) {
|
|
|
44
56
|
});
|
|
45
57
|
|
|
46
58
|
const valueLocal = computed(() => {
|
|
47
|
-
|
|
59
|
+
if (modelSnapshot.value &&
|
|
60
|
+
modelSnapshot.value.format === currentFormat.value &&
|
|
61
|
+
isEqual(modelSnapshot.value.hsva, hsva.value)) {
|
|
62
|
+
return modelSnapshot.value.text;
|
|
63
|
+
}
|
|
64
|
+
return formatColor(rgbaLocal.value, currentFormat.value, showAlpha.value);
|
|
48
65
|
});
|
|
49
66
|
|
|
50
67
|
const cssColorLocal = computed(() => toCssColor(rgbaLocal.value));
|
|
@@ -73,6 +90,14 @@ export default function ColorStateAPI(props) {
|
|
|
73
90
|
|
|
74
91
|
const setColorFromModel = () => {
|
|
75
92
|
setColor(modelColor.value || parseColor(panelDefaultColor.value) || COLOR_FALLBACK);
|
|
93
|
+
const IS_SNAPSHOT = !!modelColor.value && (showAlpha.value || modelColor.value.a === 1);
|
|
94
|
+
modelSnapshot.value = IS_SNAPSHOT ?
|
|
95
|
+
{
|
|
96
|
+
format: detectColorFormat(modelValue.value),
|
|
97
|
+
hsva: { ...hsva.value },
|
|
98
|
+
text: modelValue.value.trim(),
|
|
99
|
+
} :
|
|
100
|
+
undefined;
|
|
76
101
|
};
|
|
77
102
|
|
|
78
103
|
const setHue = h => {
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
ref,
|
|
4
|
+
toRef,
|
|
5
|
+
} from "vue";
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
COLOR_FORMATS,
|
|
9
|
+
detectColorFormat,
|
|
10
|
+
} from "../utils/colorUtils";
|
|
11
|
+
import {
|
|
12
|
+
isArray,
|
|
13
|
+
uniq,
|
|
14
|
+
} from "lodash-es";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Formats from the prop colorFormats (string or array, in the given order)
|
|
18
|
+
* and the format that is currently used in the dialog.
|
|
19
|
+
*/
|
|
20
|
+
export default function FormatAPI(props) {
|
|
21
|
+
const colorFormats = toRef(props, "colorFormats");
|
|
22
|
+
const modelValue = toRef(props, "modelValue");
|
|
23
|
+
|
|
24
|
+
const colorFormatsLocal = computed(() => {
|
|
25
|
+
const FORMATS = isArray(colorFormats.value) ? colorFormats.value : [colorFormats.value];
|
|
26
|
+
const VALID = uniq(FORMATS).filter(format => COLOR_FORMATS.indexOf(format) !== -1);
|
|
27
|
+
return VALID.length ? VALID : ["hex"];
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const currentFormat = ref(colorFormatsLocal.value[0]);
|
|
31
|
+
|
|
32
|
+
const isFormatSwitch = computed(() => colorFormatsLocal.value.length > 1);
|
|
33
|
+
|
|
34
|
+
const nextFormat = computed(() => {
|
|
35
|
+
const INDEX = colorFormatsLocal.value.indexOf(currentFormat.value);
|
|
36
|
+
return colorFormatsLocal.value[(INDEX + 1) % colorFormatsLocal.value.length];
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// The format of the model wins, if it is allowed. Otherwise the first format.
|
|
40
|
+
const setFormatFromModel = () => {
|
|
41
|
+
const FORMAT = detectColorFormat(modelValue.value);
|
|
42
|
+
currentFormat.value = colorFormatsLocal.value.indexOf(FORMAT) !== -1 ?
|
|
43
|
+
FORMAT :
|
|
44
|
+
colorFormatsLocal.value[0];
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const switchFormat = () => {
|
|
48
|
+
currentFormat.value = nextFormat.value;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
colorFormatsLocal,
|
|
53
|
+
currentFormat,
|
|
54
|
+
isFormatSwitch,
|
|
55
|
+
nextFormat,
|
|
56
|
+
setFormatFromModel,
|
|
57
|
+
switchFormat,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -32,6 +32,12 @@ export default function PopoverAPI(props, { emit }, {
|
|
|
32
32
|
|
|
33
33
|
const cleanupPopper = ref(undefined);
|
|
34
34
|
const isOpen = ref(false);
|
|
35
|
+
|
|
36
|
+
/*
|
|
37
|
+
* The popup is hidden until floating-ui has positioned it. Otherwise it stays
|
|
38
|
+
* at the top of the page for a moment and focusing it scrolls the page up.
|
|
39
|
+
*/
|
|
40
|
+
const isPositioned = ref(false);
|
|
35
41
|
const popupRef = ref(undefined);
|
|
36
42
|
const toggleRef = ref(undefined);
|
|
37
43
|
|
|
@@ -39,7 +45,7 @@ export default function PopoverAPI(props, { emit }, {
|
|
|
39
45
|
|
|
40
46
|
const elementsForClickOutside = computed(() => [toggleRef.value, popupRef.value]);
|
|
41
47
|
|
|
42
|
-
const startPosition = () => {
|
|
48
|
+
const startPosition = ({ onPositioned = () => {} } = {}) => {
|
|
43
49
|
if (cleanupPopper.value || !toggleRef.value || !popupRef.value) {
|
|
44
50
|
return;
|
|
45
51
|
}
|
|
@@ -62,6 +68,10 @@ export default function PopoverAPI(props, { emit }, {
|
|
|
62
68
|
left: `${ x }px`,
|
|
63
69
|
top: `${ y }px`,
|
|
64
70
|
});
|
|
71
|
+
if (!isPositioned.value) {
|
|
72
|
+
isPositioned.value = true;
|
|
73
|
+
nextTick(onPositioned);
|
|
74
|
+
}
|
|
65
75
|
});
|
|
66
76
|
});
|
|
67
77
|
};
|
|
@@ -94,6 +104,7 @@ export default function PopoverAPI(props, { emit }, {
|
|
|
94
104
|
return;
|
|
95
105
|
}
|
|
96
106
|
isOpen.value = false;
|
|
107
|
+
isPositioned.value = false;
|
|
97
108
|
stopPosition();
|
|
98
109
|
destroyEventClickOutside();
|
|
99
110
|
closePopup({ id: popupId.value });
|
|
@@ -112,8 +123,13 @@ export default function PopoverAPI(props, { emit }, {
|
|
|
112
123
|
openPopup({ id: popupId.value });
|
|
113
124
|
emit("open");
|
|
114
125
|
nextTick(() => {
|
|
115
|
-
startPosition(
|
|
116
|
-
|
|
126
|
+
startPosition({
|
|
127
|
+
onPositioned: () => {
|
|
128
|
+
// only as much scrolling as needed to show the whole popup
|
|
129
|
+
popupRef.value?.scrollIntoView?.({ block: "nearest" });
|
|
130
|
+
getFocusableElements()[0]?.focus({ preventScroll: true });
|
|
131
|
+
},
|
|
132
|
+
});
|
|
117
133
|
setTimeout(setEventClickOutside, 100);
|
|
118
134
|
});
|
|
119
135
|
};
|
|
@@ -169,6 +185,7 @@ export default function PopoverAPI(props, { emit }, {
|
|
|
169
185
|
return {
|
|
170
186
|
closePopover,
|
|
171
187
|
isOpen,
|
|
188
|
+
isPositioned,
|
|
172
189
|
onPopupKeydown,
|
|
173
190
|
onToggleKeydown,
|
|
174
191
|
popupId,
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
"_A_COLOR_PICKER_CONFIRM_": "موافق",
|
|
5
5
|
"_A_COLOR_PICKER_DIALOG_": "اختيار اللون",
|
|
6
6
|
"_A_COLOR_PICKER_EMPTY_": "لم يتم اختيار لون",
|
|
7
|
+
"_A_COLOR_PICKER_FORMAT_SWITCH_{{format}}_{{next}}_": "تنسيق اللون {{format}}، التبديل إلى {{next}}",
|
|
7
8
|
"_A_COLOR_PICKER_HUE_": "درجة اللون",
|
|
8
|
-
"_A_COLOR_PICKER_INPUT_": "قيمة اللون",
|
|
9
|
+
"_A_COLOR_PICKER_INPUT_{{format}}_": "قيمة اللون ({{format}})",
|
|
9
10
|
"_A_COLOR_PICKER_INVALID_": "قيمة لون غير صالحة. المسموح: #rrggbb و rgb() و hsl() و hsv().",
|
|
10
11
|
"_A_COLOR_PICKER_PREDEFINE_": "ألوان محددة مسبقًا",
|
|
11
12
|
"_A_COLOR_PICKER_SATURATION_": "التشبع والسطوع",
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
"_A_COLOR_PICKER_CONFIRM_": "OK",
|
|
5
5
|
"_A_COLOR_PICKER_DIALOG_": "Farbe wählen",
|
|
6
6
|
"_A_COLOR_PICKER_EMPTY_": "Keine Farbe ausgewählt",
|
|
7
|
+
"_A_COLOR_PICKER_FORMAT_SWITCH_{{format}}_{{next}}_": "Farbformat {{format}}, wechseln zu {{next}}",
|
|
7
8
|
"_A_COLOR_PICKER_HUE_": "Farbton",
|
|
8
|
-
"_A_COLOR_PICKER_INPUT_": "Farbwert",
|
|
9
|
+
"_A_COLOR_PICKER_INPUT_{{format}}_": "Farbwert ({{format}})",
|
|
9
10
|
"_A_COLOR_PICKER_INVALID_": "Ungültiger Farbwert. Erlaubt: #rrggbb, rgb(), hsl(), hsv().",
|
|
10
11
|
"_A_COLOR_PICKER_PREDEFINE_": "Vordefinierte Farben",
|
|
11
12
|
"_A_COLOR_PICKER_SATURATION_": "Sättigung und Helligkeit",
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
"_A_COLOR_PICKER_CONFIRM_": "OK",
|
|
5
5
|
"_A_COLOR_PICKER_DIALOG_": "Choose color",
|
|
6
6
|
"_A_COLOR_PICKER_EMPTY_": "No color selected",
|
|
7
|
+
"_A_COLOR_PICKER_FORMAT_SWITCH_{{format}}_{{next}}_": "Color format {{format}}, switch to {{next}}",
|
|
7
8
|
"_A_COLOR_PICKER_HUE_": "Hue",
|
|
8
|
-
"_A_COLOR_PICKER_INPUT_": "Color value",
|
|
9
|
+
"_A_COLOR_PICKER_INPUT_{{format}}_": "Color value ({{format}})",
|
|
9
10
|
"_A_COLOR_PICKER_INVALID_": "Invalid color value. Allowed: #rrggbb, rgb(), hsl(), hsv().",
|
|
10
11
|
"_A_COLOR_PICKER_PREDEFINE_": "Predefined colors",
|
|
11
12
|
"_A_COLOR_PICKER_SATURATION_": "Saturation and brightness",
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
"_A_COLOR_PICKER_CONFIRM_": "Aceptar",
|
|
5
5
|
"_A_COLOR_PICKER_DIALOG_": "Elegir color",
|
|
6
6
|
"_A_COLOR_PICKER_EMPTY_": "Ningún color seleccionado",
|
|
7
|
+
"_A_COLOR_PICKER_FORMAT_SWITCH_{{format}}_{{next}}_": "Formato de color {{format}}, cambiar a {{next}}",
|
|
7
8
|
"_A_COLOR_PICKER_HUE_": "Tono",
|
|
8
|
-
"_A_COLOR_PICKER_INPUT_": "Valor del color",
|
|
9
|
+
"_A_COLOR_PICKER_INPUT_{{format}}_": "Valor del color ({{format}})",
|
|
9
10
|
"_A_COLOR_PICKER_INVALID_": "Valor de color no válido. Permitido: #rrggbb, rgb(), hsl(), hsv().",
|
|
10
11
|
"_A_COLOR_PICKER_PREDEFINE_": "Colores predefinidos",
|
|
11
12
|
"_A_COLOR_PICKER_SATURATION_": "Saturación y brillo",
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
"_A_COLOR_PICKER_CONFIRM_": "OK",
|
|
5
5
|
"_A_COLOR_PICKER_DIALOG_": "Choisir une couleur",
|
|
6
6
|
"_A_COLOR_PICKER_EMPTY_": "Aucune couleur sélectionnée",
|
|
7
|
+
"_A_COLOR_PICKER_FORMAT_SWITCH_{{format}}_{{next}}_": "Format de couleur {{format}}, passer à {{next}}",
|
|
7
8
|
"_A_COLOR_PICKER_HUE_": "Teinte",
|
|
8
|
-
"_A_COLOR_PICKER_INPUT_": "Valeur de couleur",
|
|
9
|
+
"_A_COLOR_PICKER_INPUT_{{format}}_": "Valeur de couleur ({{format}})",
|
|
9
10
|
"_A_COLOR_PICKER_INVALID_": "Valeur de couleur invalide. Autorisé : #rrggbb, rgb(), hsl(), hsv().",
|
|
10
11
|
"_A_COLOR_PICKER_PREDEFINE_": "Couleurs prédéfinies",
|
|
11
12
|
"_A_COLOR_PICKER_SATURATION_": "Saturation et luminosité",
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
"_A_COLOR_PICKER_CONFIRM_": "U redu",
|
|
5
5
|
"_A_COLOR_PICKER_DIALOG_": "Odaberi boju",
|
|
6
6
|
"_A_COLOR_PICKER_EMPTY_": "Nije odabrana boja",
|
|
7
|
+
"_A_COLOR_PICKER_FORMAT_SWITCH_{{format}}_{{next}}_": "Format boje {{format}}, prebaci na {{next}}",
|
|
7
8
|
"_A_COLOR_PICKER_HUE_": "Nijansa",
|
|
8
|
-
"_A_COLOR_PICKER_INPUT_": "Vrijednost boje",
|
|
9
|
+
"_A_COLOR_PICKER_INPUT_{{format}}_": "Vrijednost boje ({{format}})",
|
|
9
10
|
"_A_COLOR_PICKER_INVALID_": "Nevaljana vrijednost boje. Dopušteno: #rrggbb, rgb(), hsl(), hsv().",
|
|
10
11
|
"_A_COLOR_PICKER_PREDEFINE_": "Unaprijed definirane boje",
|
|
11
12
|
"_A_COLOR_PICKER_SATURATION_": "Zasićenost i svjetlina",
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
"_A_COLOR_PICKER_CONFIRM_": "OK",
|
|
5
5
|
"_A_COLOR_PICKER_DIALOG_": "Scegli colore",
|
|
6
6
|
"_A_COLOR_PICKER_EMPTY_": "Nessun colore selezionato",
|
|
7
|
+
"_A_COLOR_PICKER_FORMAT_SWITCH_{{format}}_{{next}}_": "Formato colore {{format}}, passa a {{next}}",
|
|
7
8
|
"_A_COLOR_PICKER_HUE_": "Tonalità",
|
|
8
|
-
"_A_COLOR_PICKER_INPUT_": "Valore del colore",
|
|
9
|
+
"_A_COLOR_PICKER_INPUT_{{format}}_": "Valore del colore ({{format}})",
|
|
9
10
|
"_A_COLOR_PICKER_INVALID_": "Valore del colore non valido. Consentito: #rrggbb, rgb(), hsl(), hsv().",
|
|
10
11
|
"_A_COLOR_PICKER_PREDEFINE_": "Colori predefiniti",
|
|
11
12
|
"_A_COLOR_PICKER_SATURATION_": "Saturazione e luminosità",
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
"_A_COLOR_PICKER_CONFIRM_": "OK",
|
|
5
5
|
"_A_COLOR_PICKER_DIALOG_": "Kleur kiezen",
|
|
6
6
|
"_A_COLOR_PICKER_EMPTY_": "Geen kleur geselecteerd",
|
|
7
|
+
"_A_COLOR_PICKER_FORMAT_SWITCH_{{format}}_{{next}}_": "Kleurformaat {{format}}, wisselen naar {{next}}",
|
|
7
8
|
"_A_COLOR_PICKER_HUE_": "Tint",
|
|
8
|
-
"_A_COLOR_PICKER_INPUT_": "Kleurwaarde",
|
|
9
|
+
"_A_COLOR_PICKER_INPUT_{{format}}_": "Kleurwaarde ({{format}})",
|
|
9
10
|
"_A_COLOR_PICKER_INVALID_": "Ongeldige kleurwaarde. Toegestaan: #rrggbb, rgb(), hsl(), hsv().",
|
|
10
11
|
"_A_COLOR_PICKER_PREDEFINE_": "Vooraf gedefinieerde kleuren",
|
|
11
12
|
"_A_COLOR_PICKER_SATURATION_": "Verzadiging en helderheid",
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
"_A_COLOR_PICKER_CONFIRM_": "OK",
|
|
5
5
|
"_A_COLOR_PICKER_DIALOG_": "Wybierz kolor",
|
|
6
6
|
"_A_COLOR_PICKER_EMPTY_": "Nie wybrano koloru",
|
|
7
|
+
"_A_COLOR_PICKER_FORMAT_SWITCH_{{format}}_{{next}}_": "Format koloru {{format}}, przełącz na {{next}}",
|
|
7
8
|
"_A_COLOR_PICKER_HUE_": "Odcień",
|
|
8
|
-
"_A_COLOR_PICKER_INPUT_": "Wartość koloru",
|
|
9
|
+
"_A_COLOR_PICKER_INPUT_{{format}}_": "Wartość koloru ({{format}})",
|
|
9
10
|
"_A_COLOR_PICKER_INVALID_": "Nieprawidłowa wartość koloru. Dozwolone: #rrggbb, rgb(), hsl(), hsv().",
|
|
10
11
|
"_A_COLOR_PICKER_PREDEFINE_": "Kolory predefiniowane",
|
|
11
12
|
"_A_COLOR_PICKER_SATURATION_": "Nasycenie i jasność",
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
"_A_COLOR_PICKER_CONFIRM_": "OK",
|
|
5
5
|
"_A_COLOR_PICKER_DIALOG_": "Выбор цвета",
|
|
6
6
|
"_A_COLOR_PICKER_EMPTY_": "Цвет не выбран",
|
|
7
|
+
"_A_COLOR_PICKER_FORMAT_SWITCH_{{format}}_{{next}}_": "Формат цвета {{format}}, переключить на {{next}}",
|
|
7
8
|
"_A_COLOR_PICKER_HUE_": "Оттенок",
|
|
8
|
-
"_A_COLOR_PICKER_INPUT_": "Значение цвета",
|
|
9
|
+
"_A_COLOR_PICKER_INPUT_{{format}}_": "Значение цвета ({{format}})",
|
|
9
10
|
"_A_COLOR_PICKER_INVALID_": "Недопустимое значение цвета. Допустимо: #rrggbb, rgb(), hsl(), hsv().",
|
|
10
11
|
"_A_COLOR_PICKER_PREDEFINE_": "Предустановленные цвета",
|
|
11
12
|
"_A_COLOR_PICKER_SATURATION_": "Насыщенность и яркость",
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
"_A_COLOR_PICKER_CONFIRM_": "OK",
|
|
5
5
|
"_A_COLOR_PICKER_DIALOG_": "Вибір кольору",
|
|
6
6
|
"_A_COLOR_PICKER_EMPTY_": "Колір не вибрано",
|
|
7
|
+
"_A_COLOR_PICKER_FORMAT_SWITCH_{{format}}_{{next}}_": "Формат кольору {{format}}, перемкнути на {{next}}",
|
|
7
8
|
"_A_COLOR_PICKER_HUE_": "Відтінок",
|
|
8
|
-
"_A_COLOR_PICKER_INPUT_": "Значення кольору",
|
|
9
|
+
"_A_COLOR_PICKER_INPUT_{{format}}_": "Значення кольору ({{format}})",
|
|
9
10
|
"_A_COLOR_PICKER_INVALID_": "Неприпустиме значення кольору. Дозволено: #rrggbb, rgb(), hsl(), hsv().",
|
|
10
11
|
"_A_COLOR_PICKER_PREDEFINE_": "Попередньо визначені кольори",
|
|
11
12
|
"_A_COLOR_PICKER_SATURATION_": "Насиченість і яскравість",
|