Merge branch 'qt-widget-gallery' of https://github.com/kleinerpirat/anki into qt-widget-gallery

This commit is contained in:
Matthias Metelka 2023-01-14 03:46:44 +01:00
commit 5aa7b240a5
5 changed files with 32 additions and 51 deletions

View file

@ -1,19 +0,0 @@
<!--
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<style lang="scss">
:global(img:not(.mathjax)) {
max-width: var(--editor-default-max-width, inherit);
max-height: var(--editor-default-max-height, inherit);
&:is([data-editor-shrink="true"]) {
max-width: var(--editor-shrink-max-width);
max-height: var(--editor-shrink-max-height);
}
&:is([data-editor-shrink="false"]) {
max-width: initial;
max-height: initial;
}
}
</style>

View file

@ -26,3 +26,18 @@ p {
pre {
white-space: pre-wrap;
}
// image size constraints
img:not(.mathjax) {
&:not([data-editor-shrink="false"]) {
:host-context(.shrink-image) & {
max-width: var(--editor-default-max-width);
max-height: var(--editor-default-max-height);
}
}
&[data-editor-shrink="true"] {
max-width: var(--editor-shrink-max-width);
max-height: var(--editor-shrink-max-height);
}
}

View file

@ -5,4 +5,3 @@ import "./editable-base.scss";
/* only imported for the CSS */
import "./ContentEditable.svelte";
import "./Mathjax.svelte";
import "./ResizableImage.svelte";

View file

@ -162,7 +162,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
let fieldDescriptions: string[] = [];
export function setDescriptions(descriptions: string[]): void {
fieldDescriptions = descriptions;
fieldDescriptions = descriptions.map((d) =>
d.replace(/\\/g, "").replace(/"/g, '\\"'),
);
}
let fonts: [string, number, boolean][] = [];

View file

@ -24,25 +24,26 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import HandleControl from "../HandleControl.svelte";
import HandleLabel from "../HandleLabel.svelte";
import { context } from "../NoteEditor.svelte";
import type { RichTextInputAPI } from "../rich-text-input";
import {
editingInputIsRichText,
lifecycle as richTextLifecycle,
} from "../rich-text-input";
import { editingInputIsRichText } from "../rich-text-input";
import FloatButtons from "./FloatButtons.svelte";
import SizeSelect from "./SizeSelect.svelte";
export let maxWidth: number;
export let maxHeight: number;
richTextLifecycle.onMount(({ element }: RichTextInputAPI): void => {
(async () => {
const container = await element;
(<[string, number][]>[
["--editor-shrink-max-width", maxWidth],
["--editor-shrink-max-height", maxHeight],
["--editor-default-max-width", maxWidth],
["--editor-default-max-height", maxHeight],
]).forEach(([prop, value]) =>
document.documentElement.style.setProperty(prop, `${value}px`),
);
container.style.setProperty("--editor-shrink-max-width", `${maxWidth}px`);
container.style.setProperty("--editor-shrink-max-height", `${maxHeight}px`);
})();
});
$: document.documentElement.classList.toggle(
"shrink-image",
$shrinkImagesByDefault,
);
const { focusedInput } = context.get();
@ -83,24 +84,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
}
}
$: {
if ($shrinkImagesByDefault) {
document.documentElement.style.setProperty(
"--editor-default-max-width",
`${maxWidth}px`,
);
document.documentElement.style.setProperty(
"--editor-default-max-height",
`${maxHeight}px`,
);
} else {
document.documentElement.style.removeProperty("--editor-default-max-width");
document.documentElement.style.removeProperty(
"--editor-default-max-height",
);
}
}
async function resetHandle(): Promise<void> {
activeImage = null;
await tick();
@ -265,6 +248,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
offset={20}
inline
hideIfReferenceHidden
portalTarget={document.body}
let:position={positionFloating}
on:close={async ({ detail }) => {
const { reason, originalEvent } = detail;