mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
Fix ButtonDropdown disappearing when mouseupping on HandleBackground
This commit is contained in:
parent
add6d86ae6
commit
bbf03a6b93
4 changed files with 19 additions and 20 deletions
|
@ -11,7 +11,11 @@ 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 bind:this={background} on:mousedown|preventDefault on:click on:dblclick />
|
<div
|
||||||
|
bind:this={background}
|
||||||
|
on:mousedown|preventDefault
|
||||||
|
on:dblclick
|
||||||
|
/>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
div {
|
div {
|
||||||
|
|
|
@ -32,9 +32,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
class:active
|
class:active
|
||||||
class="control nw"
|
class="control nw"
|
||||||
on:mousedown|preventDefault
|
on:mousedown|preventDefault
|
||||||
on:click
|
|
||||||
on:pointerdown={onPointerdown(true, true)}
|
on:pointerdown={onPointerdown(true, true)}
|
||||||
on:pointerup
|
|
||||||
on:pointermove
|
on:pointermove
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
|
@ -42,9 +40,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
class:active
|
class:active
|
||||||
class="control ne"
|
class="control ne"
|
||||||
on:mousedown|preventDefault
|
on:mousedown|preventDefault
|
||||||
on:click
|
|
||||||
on:pointerdown={onPointerdown(true, false)}
|
on:pointerdown={onPointerdown(true, false)}
|
||||||
on:pointerup
|
|
||||||
on:pointermove
|
on:pointermove
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
|
@ -52,9 +48,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
class:active
|
class:active
|
||||||
class="control sw"
|
class="control sw"
|
||||||
on:mousedown|preventDefault
|
on:mousedown|preventDefault
|
||||||
on:click
|
|
||||||
on:pointerdown={onPointerdown(false, true)}
|
on:pointerdown={onPointerdown(false, true)}
|
||||||
on:pointerup
|
|
||||||
on:pointermove
|
on:pointermove
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
|
@ -62,9 +56,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
class:active
|
class:active
|
||||||
class="control se"
|
class="control se"
|
||||||
on:mousedown|preventDefault
|
on:mousedown|preventDefault
|
||||||
on:click
|
|
||||||
on:pointerdown={onPointerdown(false, false)}
|
on:pointerdown={onPointerdown(false, false)}
|
||||||
on:pointerup
|
|
||||||
on:pointermove
|
on:pointermove
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -37,6 +37,7 @@ 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()}
|
||||||
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 />
|
||||||
|
|
|
@ -62,20 +62,25 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
/* window resizing */
|
/* window resizing */
|
||||||
const resizeObserver = new ResizeObserver(async () => {
|
const resizeObserver = new ResizeObserver(async () => {
|
||||||
if (activeImage) {
|
await updateSizesWithDimensions();
|
||||||
await updateSizesWithDimensions();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function startObserving() {
|
function startObserving() {
|
||||||
|
console.log('start observe');
|
||||||
resizeObserver.observe(container);
|
resizeObserver.observe(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopObserving() {
|
function stopObserving() {
|
||||||
|
console.log('stop observe');
|
||||||
resizeObserver.unobserve(container);
|
resizeObserver.unobserve(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
startObserving();
|
$: observes = Boolean(activeImage);
|
||||||
|
$: if (observes) {
|
||||||
|
startObserving();
|
||||||
|
} else {
|
||||||
|
stopObserving();
|
||||||
|
}
|
||||||
|
|
||||||
/* memoized position of image on resize start
|
/* memoized position of image on resize start
|
||||||
* prevents frantic behavior when image shift into the next/previous line */
|
* prevents frantic behavior when image shift into the next/previous line */
|
||||||
|
@ -83,7 +88,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
let getDragHeight: (event: PointerEvent) => number;
|
let getDragHeight: (event: PointerEvent) => number;
|
||||||
|
|
||||||
function setPointerCapture({ detail }: CustomEvent): void {
|
function setPointerCapture({ detail }: CustomEvent): void {
|
||||||
if (detail.originalEvent.pointerId !== 1) {
|
const pointerId = detail.originalEvent.pointerId;
|
||||||
|
|
||||||
|
if (pointerId !== 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,10 +108,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
getDragHeight = ({ clientY }) => multY * clientY + imageY;
|
getDragHeight = ({ clientY }) => multY * clientY + imageY;
|
||||||
|
|
||||||
stopObserving();
|
|
||||||
|
|
||||||
const target = detail.originalEvent.target as Element;
|
const target = detail.originalEvent.target as Element;
|
||||||
target.setPointerCapture(detail.originalEvent.pointerId);
|
target.setPointerCapture(pointerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
$: [minResizeWidth, minResizeHeight] =
|
$: [minResizeWidth, minResizeHeight] =
|
||||||
|
@ -165,7 +170,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
on:mount={(event) => createDropdown(event.detail.selection)}
|
on:mount={(event) => createDropdown(event.detail.selection)}
|
||||||
>
|
>
|
||||||
<HandleBackground
|
<HandleBackground
|
||||||
on:click={(event) => event.stopPropagation()}
|
|
||||||
on:dblclick={toggleActualSize}
|
on:dblclick={toggleActualSize}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
@ -182,13 +186,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
activeSize={8}
|
activeSize={8}
|
||||||
offsetX={5}
|
offsetX={5}
|
||||||
offsetY={5}
|
offsetY={5}
|
||||||
on:click={(event) => event.stopPropagation()}
|
|
||||||
on:pointerclick={(event) => {
|
on:pointerclick={(event) => {
|
||||||
if (active) {
|
if (active) {
|
||||||
setPointerCapture(event);
|
setPointerCapture(event);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
on:pointerup={startObserving}
|
|
||||||
on:pointermove={(event) => {
|
on:pointermove={(event) => {
|
||||||
resize(event);
|
resize(event);
|
||||||
updateSizesWithDimensions();
|
updateSizesWithDimensions();
|
||||||
|
|
Loading…
Reference in a new issue