Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types for viewer modifications #454

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/common/dialog/DocumentPickerDialog.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { modification } from "@/viewer/modification/modification.js";
import { modification } from "@/viewer/modification/modification";
import Documents from "@/pages/app/Documents.svelte";
import emitter from "@/emit.js";

Expand Down
18 changes: 9 additions & 9 deletions src/pages/viewer/ModifyImage.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script>
import Image from "@/common/Image.svelte";
import { viewer } from "@/viewer/viewer.js";
import { pageImageUrl } from "@/api/viewer.js";
import { modification } from "@/viewer/modification/modification.js";
import { getDocument } from "@/api/document.js";
<script lang="ts">
import Image from "../../common/Image.svelte";
import { viewer } from "../../viewer/viewer.js";
import { getDocument } from "../../api/document.js";
import { pageImageUrl } from "../../api/viewer.js";
import { modification } from "../../viewer/modification/modification";

export let id;
export let page;
Expand Down Expand Up @@ -34,11 +34,11 @@
$: {
if ($viewer.document != null && id != $viewer.document.id) {
if ($modification.documentCache[id] == null) {
modification.documentCache[id] = {};
$modification.documentCache[id] = {};
// Update the document cache
getDocument(id, null).then((doc) => {
modification.documentCache[doc.id] = doc;
modification.documentCache = modification.documentCache;
$modification.documentCache[doc.id] = doc;
$modification.documentCache = $modification.documentCache;
});
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/pages/viewer/ThumbnailBody.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<script>
<script lang="ts">
import { _ } from "svelte-i18n";

import ActionPane from "./pane/ActionPane.svelte";
import ModifyImage from "./ModifyImage.svelte";
import Modification from "@/viewer/modification/Modification.svelte";
import { viewer } from "@/viewer/viewer.js";
import { layout } from "@/viewer/layout.js";
import { restorePosition, changeMode } from "@/viewer/document.js";
import { ModificationSpec } from "@/viewer/modification/modifySpec.js";
import { modification } from "@/viewer/modification/modification.js";
import Modification from "../../viewer/modification/Modification.svelte";
import { viewer } from "../../viewer/viewer.js";
import { layout } from "../../viewer/layout.js";
import { restorePosition, changeMode } from "../../viewer/document.js";
import { ModificationSpec } from "../../viewer/modification/modifySpec";
import { modification } from "../../viewer/modification/modification";

$: modify = $layout.modifying;

Expand Down Expand Up @@ -43,7 +43,7 @@
$viewer.document.pageCount != null
) {
// Init page spec
modification.initSpec(
$modification.initSpec(
ModificationSpec.getDocument($viewer.document.pageCount),
);
}
Expand Down Expand Up @@ -169,14 +169,14 @@
{/if}
{#if showInserts}
<div
on:click={() => modification.selectInsert(page.index)}
on:click={() => $modification.selectInsert(page.index)}
class="insert before"
class:emphasized={(insertOnly && !$modification.hasInsert) ||
$modification.insert == page.index}
/>
{#if page.index == $modification.pageCount - 1}
<div
on:click={() => modification.selectInsert(page.index + 1)}
on:click={() => $modification.selectInsert(page.index + 1)}
class="insert after"
class:emphasized={(insertOnly && !$modification.hasInsert) ||
$modification.insert == page.index + 1}
Expand Down
45 changes: 24 additions & 21 deletions src/pages/viewer/pane/ModifyPane.svelte
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
<script>
<script lang="ts">
import { _ } from "svelte-i18n";

import Button from "@/common/Button.svelte";
import Modification from "@/viewer/modification/Modification.svelte";
import Button from "../../../common/Button.svelte";
import Modification from "../../../viewer/modification/Modification.svelte";
import ModifyImage from "../ModifyImage.svelte";

import { modification } from "@/viewer/modification/modification.js";
import { viewer } from "@/viewer/viewer.js";
import { cancelActions } from "@/viewer/document.js";
import { showInsertDialog, modify } from "@/viewer/layout.js";
import { modification } from "../../../viewer/modification/modification";
import { viewer } from "../../../viewer/viewer.js";
import { cancelActions } from "../../../viewer/document.js";
import { showInsertDialog, modify } from "../../../viewer/layout.js";

const MAX_BUFFER_SIZE = 5;

const MAX_THUMB_WIDTH = 30;
const MAX_THUMB_HEIGHT = 39;

$: {
console.log($modification);
}
</script>

{#if $modification.modifyHasSelection}
Expand All @@ -27,28 +30,28 @@
<Button
tertiary={true}
on:click={() => {
modify(modification, cancelActions);
modify($modification, cancelActions);
}}
>
{$_("modifyPane.applyModifications")}
</Button>
{/if}
<Button on:click={() => modification.copy()}
<Button on:click={() => $modification.copy()}
>{$_("modifyPane.duplicate")}</Button
>
{#if $modification.modifyNumSelected < $modification.pageCount}
<Button on:click={() => modification.cut()}
<Button on:click={() => $modification.cut()}
>{$_("modifyPane.move")}</Button
>
{/if}
<Button on:click={() => modification.rotateClockwise()}
<Button on:click={() => $modification.rotateClockwise()}
>{$_("modifyPane.rotate")}</Button
>
<Button secondary={true} on:click={() => modification.modifyUnselect()}>
<Button secondary={true} on:click={() => $modification.modifyUnselect()}>
{$_("modifyPane.unselect")}
</Button>
{#if $modification.modifyNumSelected < $modification.pageCount}
<Button danger={true} on:click={() => modification.remove()}>
<Button danger={true} on:click={() => $modification.remove()}>
{$_("modifyPane.remove")}
</Button>
{/if}
Expand Down Expand Up @@ -116,15 +119,15 @@
</p>
<div class="buttonpadded">
{#if $modification.hasInsert}
<Button on:click={() => modification.pasteAtInsert()}
<Button on:click={() => $modification.pasteAtInsert()}
>{$_("modifyPane.insert")}</Button
>
{:else}
<Button on:click={() => modification.pasteAtEnd()}
<Button on:click={() => $modification.pasteAtEnd()}
>{$_("modifyPane.insertAtEnd")}</Button
>
{/if}
<Button secondary={true} on:click={() => modification.clearCopyBuffer()}>
<Button secondary={true} on:click={() => $modification.clearCopyBuffer()}>
{$_("dialog.cancel")}
</Button>
</div>
Expand All @@ -134,7 +137,7 @@
<Button on:click={showInsertDialog}
>{$_("modifyPane.insertOtherDoc")}</Button
>
<Button secondary={true} on:click={() => modification.clearInsertion()}>
<Button secondary={true} on:click={() => $modification.clearInsertion()}>
{$_("dialog.cancel")}
</Button>
</div>
Expand All @@ -151,7 +154,7 @@
<Button
tertiary={true}
on:click={() => {
modify(modification, cancelActions);
modify($modification, cancelActions);
}}
>
{$_("modifyPane.applyModifications")}
Expand All @@ -160,12 +163,12 @@
<Button
disabled={!$modification.canUndo}
secondary={true}
on:click={() => modification.undo()}>{$_("modifyPane.undo")}</Button
on:click={() => $modification.undo()}>{$_("modifyPane.undo")}</Button
>
<Button
disabled={!$modification.canRedo}
secondary={true}
on:click={() => modification.redo()}>{$_("modifyPane.redo")}</Button
on:click={() => $modification.redo()}>{$_("modifyPane.redo")}</Button
>
</div>
{/if}
Expand Down
2 changes: 1 addition & 1 deletion src/viewer/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
import { Note } from "@/structure/note.js";
import { DEFAULT_EXPAND } from "../api/common.js";
import { inIframe } from "@/util/iframe.js";
import { modification } from "./modification/modification.js";
import { modification } from "./modification/modification.ts";

import {
MOBILE_BREAKPOINT,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { modification } from "./modification.js";
import { ModificationSpec } from "./modifySpec.js";
import { Modification } from "./modification";
import { ModificationSpec } from "./modifySpec";

let modification;

beforeEach(() => {
modification = new Modification();
modification.clear();
modification.initSpec(ModificationSpec.getDocument(3));
});
Expand Down
Loading
Loading