mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Fix Float buttons in rtl
This commit is contained in:
parent
bbf03a6b93
commit
f5ab78825a
7 changed files with 40 additions and 68 deletions
|
@ -19,9 +19,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
export { className as class };
|
export { className as class };
|
||||||
|
|
||||||
export let size: number | undefined = undefined;
|
export let size: number | undefined = undefined;
|
||||||
export let wrap: boolean | undefined = undefined;
|
|
||||||
|
|
||||||
export let reverse = false;
|
export let wrap: boolean | undefined = undefined;
|
||||||
|
|
||||||
$: buttonSize = size ? `--buttons-size: ${size}rem; ` : "";
|
$: buttonSize = size ? `--buttons-size: ${size}rem; ` : "";
|
||||||
let buttonWrap: string;
|
let buttonWrap: string;
|
||||||
|
@ -47,9 +46,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
if ($items.length === 1) {
|
if ($items.length === 1) {
|
||||||
return ButtonPosition.Standalone;
|
return ButtonPosition.Standalone;
|
||||||
} else if (index === 0) {
|
} else if (index === 0) {
|
||||||
return ButtonPosition.Leftmost;
|
return ButtonPosition.InlineStart;
|
||||||
} else if (index === $items.length - 1) {
|
} else if (index === $items.length - 1) {
|
||||||
return ButtonPosition.Rightmost;
|
return ButtonPosition.InlineEnd;
|
||||||
} else {
|
} else {
|
||||||
return ButtonPosition.Center;
|
return ButtonPosition.Center;
|
||||||
}
|
}
|
||||||
|
@ -98,7 +97,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
bind:this={buttonGroupRef}
|
bind:this={buttonGroupRef}
|
||||||
{id}
|
{id}
|
||||||
class="btn-group {className}"
|
class="btn-group {className}"
|
||||||
class:reverse
|
|
||||||
{style}
|
{style}
|
||||||
dir="ltr"
|
dir="ltr"
|
||||||
role="group"
|
role="group"
|
||||||
|
@ -118,8 +116,4 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
padding: calc(var(--buttons-size) / 10);
|
padding: calc(var(--buttons-size) / 10);
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.reverse {
|
|
||||||
flex-direction: row-reverse;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -22,19 +22,22 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
const radius = "5px";
|
const radius = "5px";
|
||||||
|
|
||||||
|
const leftStyle = `--border-left-radius: ${radius}; --border-right-radius: 0; `;
|
||||||
|
const rightStyle = `--border-left-radius: 0; --border-right-radius: ${radius}; `;
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
switch (position_) {
|
switch (position_) {
|
||||||
case ButtonPosition.Standalone:
|
case ButtonPosition.Standalone:
|
||||||
style = `--border-left-radius: ${radius}; --border-right-radius: ${radius}; `;
|
style = `--border-left-radius: ${radius}; --border-right-radius: ${radius}; `;
|
||||||
break;
|
break;
|
||||||
case ButtonPosition.Leftmost:
|
case ButtonPosition.InlineStart:
|
||||||
style = `--border-left-radius: ${radius}; --border-right-radius: 0; `;
|
style = leftStyle;
|
||||||
break;
|
break;
|
||||||
case ButtonPosition.Center:
|
case ButtonPosition.Center:
|
||||||
style = "--border-left-radius: 0; --border-right-radius: 0; ";
|
style = "--border-left-radius: 0; --border-right-radius: 0; ";
|
||||||
break;
|
break;
|
||||||
case ButtonPosition.Rightmost:
|
case ButtonPosition.InlineEnd:
|
||||||
style = `--border-left-radius: 0; --border-right-radius: ${radius}; `;
|
style = rightStyle;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,9 @@ import type { Registration } from "./registration";
|
||||||
|
|
||||||
export enum ButtonPosition {
|
export enum ButtonPosition {
|
||||||
Standalone,
|
Standalone,
|
||||||
Leftmost,
|
InlineStart,
|
||||||
Center,
|
Center,
|
||||||
Rightmost,
|
InlineEnd,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ButtonRegistration extends Registration {
|
export interface ButtonRegistration extends Registration {
|
||||||
|
|
|
@ -11,11 +11,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
onMount(() => dispatch("mount", { background }));
|
onMount(() => dispatch("mount", { background }));
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div bind:this={background} on:mousedown|preventDefault on:dblclick />
|
||||||
bind:this={background}
|
|
||||||
on:mousedown|preventDefault
|
|
||||||
on:dblclick
|
|
||||||
/>
|
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
div {
|
div {
|
||||||
|
|
|
@ -37,7 +37,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
<div
|
<div
|
||||||
bind:this={selection}
|
bind:this={selection}
|
||||||
use:updateSelection
|
use:updateSelection
|
||||||
on:click={(event) => /* prevent triggering Bootstrap dropdown */ event.stopImmediatePropagation()}
|
on:click={(event) =>
|
||||||
|
/* prevent triggering Bootstrap dropdown */ event.stopImmediatePropagation()}
|
||||||
style="--left: {left}px; --top: {top}px; --width: {width}px; --height: {height}px; --offsetX: {offsetX}px; --offsetY: {offsetY}px;"
|
style="--left: {left}px; --top: {top}px; --width: {width}px; --height: {height}px; --offsetX: {offsetX}px; --offsetY: {offsetY}px;"
|
||||||
>
|
>
|
||||||
<slot />
|
<slot />
|
||||||
|
|
|
@ -12,7 +12,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
import HandleSelection from "./HandleSelection.svelte";
|
import HandleSelection from "./HandleSelection.svelte";
|
||||||
import HandleControl from "./HandleControl.svelte";
|
import HandleControl from "./HandleControl.svelte";
|
||||||
import HandleLabel from "./HandleLabel.svelte";
|
import HandleLabel from "./HandleLabel.svelte";
|
||||||
import ImageHandleFloat from "./ImageHandleFloat.svelte";
|
import ImageHandleFloatButtons from "./ImageHandleFloatButtons.svelte";
|
||||||
import ImageHandleSizeSelect from "./ImageHandleSizeSelect.svelte";
|
import ImageHandleSizeSelect from "./ImageHandleSizeSelect.svelte";
|
||||||
|
|
||||||
import { onDestroy } from "svelte";
|
import { onDestroy } from "svelte";
|
||||||
|
@ -65,21 +65,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
await updateSizesWithDimensions();
|
await updateSizesWithDimensions();
|
||||||
});
|
});
|
||||||
|
|
||||||
function startObserving() {
|
|
||||||
console.log('start observe');
|
|
||||||
resizeObserver.observe(container);
|
|
||||||
}
|
|
||||||
|
|
||||||
function stopObserving() {
|
|
||||||
console.log('stop observe');
|
|
||||||
resizeObserver.unobserve(container);
|
|
||||||
}
|
|
||||||
|
|
||||||
$: observes = Boolean(activeImage);
|
$: observes = Boolean(activeImage);
|
||||||
$: if (observes) {
|
$: if (observes) {
|
||||||
startObserving();
|
resizeObserver.observe(container);
|
||||||
} else {
|
} else {
|
||||||
stopObserving();
|
resizeObserver.unobserve(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* memoized position of image on resize start
|
/* memoized position of image on resize start
|
||||||
|
@ -169,9 +159,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
image={activeImage}
|
image={activeImage}
|
||||||
on:mount={(event) => createDropdown(event.detail.selection)}
|
on:mount={(event) => createDropdown(event.detail.selection)}
|
||||||
>
|
>
|
||||||
<HandleBackground
|
<HandleBackground on:dblclick={toggleActualSize} />
|
||||||
on:dblclick={toggleActualSize}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<HandleLabel {isRtl} on:mount={updateDimensions}>
|
<HandleLabel {isRtl} on:mount={updateDimensions}>
|
||||||
<span>{actualWidth}×{actualHeight}</span>
|
<span>{actualWidth}×{actualHeight}</span>
|
||||||
|
@ -201,7 +189,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
<ButtonDropdown>
|
<ButtonDropdown>
|
||||||
<div on:click={updateSizesWithDimensions}>
|
<div on:click={updateSizesWithDimensions}>
|
||||||
<Item>
|
<Item>
|
||||||
<ImageHandleFloat
|
<ImageHandleFloatButtons
|
||||||
image={activeImage}
|
image={activeImage}
|
||||||
{isRtl}
|
{isRtl}
|
||||||
on:update={dropdownObject.update}
|
on:update={dropdownObject.update}
|
||||||
|
|
|
@ -15,24 +15,26 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
export let image: HTMLImageElement;
|
export let image: HTMLImageElement;
|
||||||
export let isRtl: boolean;
|
export let isRtl: boolean;
|
||||||
|
|
||||||
const leftValues = {
|
const [inlineStartIcon, inlineEndIcon] = isRtl
|
||||||
position: "left",
|
? [floatRightIcon, floatLeftIcon]
|
||||||
label: tr.editingFloatLeft(),
|
: [floatLeftIcon, floatRightIcon];
|
||||||
icon: floatLeftIcon,
|
|
||||||
};
|
|
||||||
|
|
||||||
const rightValues = {
|
|
||||||
position: "right",
|
|
||||||
label: tr.editingFloatRight(),
|
|
||||||
};
|
|
||||||
|
|
||||||
$: inlineStart = isRtl ? rightValues : leftValues;
|
|
||||||
$: inlineEnd = isRtl ? leftValues : rightValues;
|
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ButtonGroup size={1.6} wrap={false} reverse={isRtl}>
|
<ButtonGroup size={1.6} wrap={false}>
|
||||||
|
<ButtonGroupItem>
|
||||||
|
<IconButton
|
||||||
|
tooltip={tr.editingFloatLeft()}
|
||||||
|
active={image.style.float === "left"}
|
||||||
|
flipX={isRtl}
|
||||||
|
on:click={() => {
|
||||||
|
image.style.float = "left";
|
||||||
|
setTimeout(() => dispatch("update"));
|
||||||
|
}}>{@html inlineStartIcon}</IconButton
|
||||||
|
>
|
||||||
|
</ButtonGroupItem>
|
||||||
|
|
||||||
<ButtonGroupItem>
|
<ButtonGroupItem>
|
||||||
<IconButton
|
<IconButton
|
||||||
tooltip={tr.editingFloatNone()}
|
tooltip={tr.editingFloatNone()}
|
||||||
|
@ -47,25 +49,13 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
<ButtonGroupItem>
|
<ButtonGroupItem>
|
||||||
<IconButton
|
<IconButton
|
||||||
tooltip={inlineStart.label}
|
tooltip={tr.editingFloatRight()}
|
||||||
active={image.style.float === inlineStart.position}
|
active={image.style.float === "right"}
|
||||||
flipX={isRtl}
|
flipX={isRtl}
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
image.style.float = inlineStart.position;
|
image.style.float = "right";
|
||||||
setTimeout(() => dispatch("update"));
|
setTimeout(() => dispatch("update"));
|
||||||
}}>{@html floatLeftIcon}</IconButton
|
}}>{@html inlineEndIcon}</IconButton
|
||||||
>
|
|
||||||
</ButtonGroupItem>
|
|
||||||
|
|
||||||
<ButtonGroupItem>
|
|
||||||
<IconButton
|
|
||||||
tooltip={inlineEnd.label}
|
|
||||||
active={image.style.float === inlineEnd.position}
|
|
||||||
flipX={isRtl}
|
|
||||||
on:click={() => {
|
|
||||||
image.style.float = inlineEnd.position;
|
|
||||||
setTimeout(() => dispatch("update"));
|
|
||||||
}}>{@html floatRightIcon}</IconButton
|
|
||||||
>
|
>
|
||||||
</ButtonGroupItem>
|
</ButtonGroupItem>
|
||||||
</ButtonGroup>
|
</ButtonGroup>
|
Loading…
Reference in a new issue