2021-04-12 06:18:30 +02:00
|
|
|
<!--
|
|
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
-->
|
|
|
|
<script lang="ts">
|
2021-04-26 15:34:33 +02:00
|
|
|
import * as tr from "lib/i18n";
|
2021-04-12 06:18:30 +02:00
|
|
|
import { revertIcon } from "./icons";
|
|
|
|
import { createEventDispatcher } from "svelte";
|
2021-05-24 10:26:01 +02:00
|
|
|
import { isEqual as isEqualLodash, cloneDeep } from "lodash-es";
|
2021-04-26 15:34:33 +02:00
|
|
|
// import { onMount } from "svelte";
|
|
|
|
// import Tooltip from "bootstrap/js/dist/tooltip";
|
|
|
|
|
|
|
|
let ref: HTMLDivElement;
|
|
|
|
|
|
|
|
// fixme: figure out why this breaks halfway down the page
|
|
|
|
// onMount(() => {
|
|
|
|
// new Tooltip(ref, {
|
|
|
|
// placement: "bottom",
|
|
|
|
// html: true,
|
|
|
|
// offset: [0, 20],
|
|
|
|
// });
|
|
|
|
// });
|
2021-04-12 06:18:30 +02:00
|
|
|
|
|
|
|
export let value: any;
|
|
|
|
export let defaultValue: any;
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
|
2021-05-24 10:26:01 +02:00
|
|
|
function isEqual(a: unknown, b: unknown): boolean {
|
|
|
|
if (typeof a === "number" && typeof b === "number") {
|
|
|
|
// round to .01 precision before comparing,
|
|
|
|
// so the values coming out of the UI match
|
|
|
|
// the originals
|
|
|
|
return isEqualLodash(Math.round(a * 100) / 100, Math.round(b * 100) / 100);
|
|
|
|
} else {
|
|
|
|
return isEqualLodash(a, b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-12 06:18:30 +02:00
|
|
|
let modified: boolean;
|
2021-04-25 11:05:19 +02:00
|
|
|
$: modified = !isEqual(value, defaultValue);
|
2021-04-12 06:18:30 +02:00
|
|
|
|
|
|
|
/// This component can be used either with bind:value, or by listening
|
|
|
|
/// to the revert event.
|
|
|
|
function revert(): void {
|
2021-04-25 11:05:19 +02:00
|
|
|
value = cloneDeep(defaultValue);
|
2021-04-12 06:18:30 +02:00
|
|
|
dispatch("revert", { value });
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2021-05-28 00:52:49 +02:00
|
|
|
<span
|
|
|
|
bind:this={ref}
|
2021-06-05 01:17:10 +02:00
|
|
|
class="badge px-1"
|
2021-05-28 00:52:49 +02:00
|
|
|
class:invisible={!modified}
|
|
|
|
title={tr.deckConfigRevertButtonTooltip()}
|
|
|
|
on:click={revert}
|
|
|
|
>
|
|
|
|
{@html revertIcon}
|
|
|
|
</span>
|
2021-05-26 01:21:33 +02:00
|
|
|
|
2021-04-22 10:11:27 +02:00
|
|
|
<style lang="scss">
|
2021-06-05 00:57:47 +02:00
|
|
|
.badge {
|
|
|
|
color: inherit;
|
|
|
|
}
|
|
|
|
|
2021-05-27 22:01:14 +02:00
|
|
|
span :global(svg) {
|
|
|
|
vertical-align: -0.125rem;
|
|
|
|
opacity: 0.3;
|
2021-04-12 06:18:30 +02:00
|
|
|
}
|
|
|
|
</style>
|