mirror of
https://github.com/directus/directus.git
synced 2026-02-11 07:55:00 -05:00
Prevent nested ternary expressions (#18376)
Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
This commit is contained in:
@@ -228,8 +228,13 @@ function parseHTML(innerText?: string, isDirectInput = false) {
|
||||
}
|
||||
|
||||
let newHTML = input.value.innerText;
|
||||
let caretPos = 0;
|
||||
|
||||
const caretPos = isDirectInput ? previousCaretPos : window.getSelection()?.rangeCount ? position(input.value).pos : 0;
|
||||
if (isDirectInput) {
|
||||
caretPos = previousCaretPos;
|
||||
} else if (window.getSelection()?.rangeCount) {
|
||||
caretPos = position(input.value).pos;
|
||||
}
|
||||
|
||||
let lastMatchIndex = 0;
|
||||
const matches = newHTML.match(new RegExp(`${props.captureGroup}(?!</mark>)`, 'gi'));
|
||||
|
||||
@@ -124,7 +124,7 @@ export default function useMedia(editor: Ref<any>, imageToken: Ref<string | unde
|
||||
if (newEmbed === '') {
|
||||
mediaSelection.value = null;
|
||||
} else {
|
||||
const tag = /<(video|audio|iframe)/g.exec(newEmbed)?.[1];
|
||||
const tag = /<(video|audio|iframe)/g.exec(newEmbed)?.[1] as 'video' | 'audio' | 'iframe' | undefined;
|
||||
const sourceUrl = /src="(.*?)"/g.exec(newEmbed)?.[1] || undefined;
|
||||
const width = Number(/width="(.*?)"/g.exec(newEmbed)?.[1]) || undefined;
|
||||
const height = Number(/height="(.*?)"/g.exec(newEmbed)?.[1]) || undefined;
|
||||
@@ -136,7 +136,7 @@ export default function useMedia(editor: Ref<any>, imageToken: Ref<string | unde
|
||||
const previewUrl = replaceUrlAccessToken(sourceUrl, imageToken.value || getToken());
|
||||
|
||||
mediaSelection.value = {
|
||||
tag: tag === 'audio' ? 'audio' : tag === 'iframe' ? 'iframe' : 'video',
|
||||
tag,
|
||||
sourceUrl,
|
||||
width,
|
||||
height,
|
||||
|
||||
@@ -304,8 +304,11 @@ function useColor() {
|
||||
|
||||
const rgb = computed<number[]>({
|
||||
get() {
|
||||
const arr = color.value !== null ? color.value.rgb().array() : props.opacity ? [0, 0, 0, 1] : [0, 0, 0];
|
||||
return arr.length === 4 ? [...arr.slice(0, -1).map(Math.round), arr[3]] : arr.map(Math.round);
|
||||
if (color.value !== null) {
|
||||
return roundColorValues(color.value.rgb().array());
|
||||
}
|
||||
|
||||
return roundColorValues(props.opacity ? [0, 0, 0, 1] : [0, 0, 0]);
|
||||
},
|
||||
set(newRGB) {
|
||||
setColor(Color.rgb(newRGB).alpha(newRGB.length === 4 ? newRGB[3] : 1));
|
||||
@@ -314,8 +317,11 @@ function useColor() {
|
||||
|
||||
const hsl = computed<number[]>({
|
||||
get() {
|
||||
const arr = color.value !== null ? color.value.hsl().array() : props.opacity ? [0, 0, 0, 1] : [0, 0, 0];
|
||||
return arr.length === 4 ? [...arr.slice(0, -1).map(Math.round), arr[3]] : arr.map(Math.round);
|
||||
if (color.value !== null) {
|
||||
return roundColorValues(color.value.hsl().array());
|
||||
}
|
||||
|
||||
return roundColorValues(props.opacity ? [0, 0, 0, 1] : [0, 0, 0]);
|
||||
},
|
||||
set(newHSL) {
|
||||
setColor(Color.hsl(newHSL).alpha(newHSL.length === 4 ? newHSL[3] : 1));
|
||||
@@ -361,6 +367,15 @@ function useColor() {
|
||||
emit('input', getHexa());
|
||||
}
|
||||
}
|
||||
|
||||
function roundColorValues(arr: number[]): number[] {
|
||||
if (arr.length === 4) {
|
||||
// Do not round the opacity
|
||||
return [...arr.slice(0, -1).map((x) => Math.round(x)), arr[3]];
|
||||
}
|
||||
|
||||
return arr.map((x) => Math.round(x));
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user