Add interface languages and improve themes and workspace controls for 0.1.36
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { t } from "$lib/i18n";
|
||||
import { untrack } from "svelte";
|
||||
import type { Chrome, OpenBuffer } from "$lib/workspace/types";
|
||||
import { isMarkdownPath, imageFiles, hasFileDrag, imageInsertion, workspaceImageLink } from "$lib/workspace/media";
|
||||
@@ -275,7 +276,7 @@
|
||||
<div
|
||||
class="monaco-host"
|
||||
role="application"
|
||||
aria-label="Editor"
|
||||
aria-label={$t("Editor")}
|
||||
bind:this={host}
|
||||
ondragover={(event) => {
|
||||
if (isMarkdownPath(buffer.relPath) && onInsertImage && hasFileDrag(event.dataTransfer)) {
|
||||
@@ -290,7 +291,7 @@
|
||||
void takeImages(event, event.clipboardData);
|
||||
}}
|
||||
></div>
|
||||
{#if loadError}<p class="editor-notice" role="alert">{loadError}<button onclick={() => { loadError = null; }}>Dismiss</button></p>{/if}
|
||||
{#if loadError}<p class="editor-notice" role="alert">{loadError}<button onclick={() => { loadError = null; }}>{$t("Dismiss")}</button></p>{/if}
|
||||
|
||||
<style>
|
||||
.monaco-host {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { t } from "$lib/i18n";
|
||||
import { untrack } from "svelte";
|
||||
import { runScopeHandlers, type EditorView } from "@codemirror/view";
|
||||
import { SearchQuery, closeSearchPanel, findNext, findPrevious, getSearchQuery, replaceAll, replaceNext, selectMatches, setSearchQuery } from "@codemirror/search";
|
||||
@@ -44,34 +45,34 @@
|
||||
</script>
|
||||
|
||||
<!-- svelte-ignore a11y_no_noninteractive_element_interactions (Handle shortcuts from the search controls.) -->
|
||||
<section class="rs-find-bar" aria-label="Find and replace" onkeydown={keydown}>
|
||||
<section class="rs-find-bar" aria-label={$t("Find and replace")} onkeydown={keydown}>
|
||||
<div class="rs-find-row">
|
||||
<div class="rs-find-field">
|
||||
<Icon icon="search" />
|
||||
<input type="text" name="search" {...{ "main-field": "true" }} aria-label="Find in document" placeholder="Find in document"
|
||||
<input type="text" name="search" {...{ "main-field": "true" }} aria-label={$t("Find in document")} placeholder={$t("Find in document")}
|
||||
aria-invalid={searchText !== "" && !query.valid} bind:value={() => searchText, value => { searchText = value; commit(); }} />
|
||||
</div>
|
||||
<div class="rs-find-actions">
|
||||
<IconButton icon="up" label="Previous match (Shift+Enter)" onclick={() => findPrevious(view)} disabled={!query.valid} />
|
||||
<IconButton icon="down" label="Next match (Enter)" onclick={() => findNext(view)} disabled={!query.valid} />
|
||||
<button class="rs-find-button" type="button" onclick={() => selectMatches(view)} disabled={!query.valid}>Select all</button>
|
||||
<IconButton icon="close" label="Close find (Escape)" onclick={() => closeSearchPanel(view)} />
|
||||
<IconButton icon="up" label={$t("Previous match (Shift+Enter)")} onclick={() => findPrevious(view)} disabled={!query.valid} />
|
||||
<IconButton icon="down" label={$t("Next match (Enter)")} onclick={() => findNext(view)} disabled={!query.valid} />
|
||||
<button class="rs-find-button" type="button" onclick={() => selectMatches(view)} disabled={!query.valid}>{$t("Select all")}</button>
|
||||
<IconButton icon="close" label={$t("Close find (Escape)")} onclick={() => closeSearchPanel(view)} />
|
||||
</div>
|
||||
</div>
|
||||
<div class="rs-find-options">
|
||||
<label><input type="checkbox" bind:checked={() => caseSensitive, value => { caseSensitive = value; commit(); }} />Match case</label>
|
||||
<label><input type="checkbox" bind:checked={() => wholeWord, value => { wholeWord = value; commit(); }} />Whole word</label>
|
||||
<label><input type="checkbox" bind:checked={() => regexp, value => { regexp = value; commit(); }} />Regex</label>
|
||||
{#if searchText && !query.valid}<span class="rs-find-error" role="status">Invalid expression</span>{/if}
|
||||
<label><input type="checkbox" bind:checked={() => caseSensitive, value => { caseSensitive = value; commit(); }} />{$t("Match case")}</label>
|
||||
<label><input type="checkbox" bind:checked={() => wholeWord, value => { wholeWord = value; commit(); }} />{$t("Whole word")}</label>
|
||||
<label><input type="checkbox" bind:checked={() => regexp, value => { regexp = value; commit(); }} />{$t("Regex")}</label>
|
||||
{#if searchText && !query.valid}<span class="rs-find-error" role="status">{$t("Invalid expression")}</span>{/if}
|
||||
</div>
|
||||
{#if !view.state.readOnly}
|
||||
<div class="rs-find-row">
|
||||
<div class="rs-find-field">
|
||||
<input type="text" name="replace" aria-label="Replace with" placeholder="Replace with" bind:value={() => replacement, value => { replacement = value; commit(); }} />
|
||||
<input type="text" name="replace" aria-label={$t("Replace with")} placeholder={$t("Replace with")} bind:value={() => replacement, value => { replacement = value; commit(); }} />
|
||||
</div>
|
||||
<div class="rs-find-actions">
|
||||
<button class="rs-find-button" type="button" onclick={() => replaceNext(view)} disabled={!query.valid}>Replace</button>
|
||||
<button class="rs-find-button" type="button" onclick={() => replaceAll(view)} disabled={!query.valid}>Replace all</button>
|
||||
<button class="rs-find-button" type="button" onclick={() => replaceNext(view)} disabled={!query.valid}>{$t("Replace")}</button>
|
||||
<button class="rs-find-button" type="button" onclick={() => replaceAll(view)} disabled={!query.valid}>{$t("Replace all")}</button>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { t } from "$lib/i18n";
|
||||
import { pluginHost } from "$lib/plugins/registry";
|
||||
import { isSpellingTarget } from "./spellingMenu";
|
||||
import { untrack } from "svelte";
|
||||
@@ -216,7 +217,7 @@
|
||||
}),
|
||||
imageDrops,
|
||||
title.of(noteTitle(markdownTitle(current.relPath), onRenameTitle ? renameTitle : undefined)),
|
||||
EditorView.contentAttributes.of({ role: "textbox", "aria-label": "Writing editor", "aria-multiline": "true", spellcheck: "true" }),
|
||||
EditorView.contentAttributes.of({ role: "textbox", "aria-label": $t("Writing editor"), "aria-multiline": "true", spellcheck: "true" }),
|
||||
EditorView.updateListener.of(update => {
|
||||
if (update.docChanged || update.selectionSet) {
|
||||
menu?.close(false);
|
||||
@@ -395,7 +396,7 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="live-writer" bind:this={host} role="application" aria-label="Markdown writing editor"
|
||||
<div class="live-writer" bind:this={host} role="application" aria-label={$t("Markdown writing editor")}
|
||||
ondragovercapture={(event) => {
|
||||
if (!onInsertImage || !hasFileDrag(event.dataTransfer)) return;
|
||||
event.preventDefault();
|
||||
@@ -403,7 +404,7 @@
|
||||
}}
|
||||
ondropcapture={(event) => { if (editor) void insertImages(event, editor); }}
|
||||
></div>
|
||||
{#if error}<p class="editor-notice" role="alert">{error}<button onclick={() => { error = ""; }}>Dismiss</button></p>{/if}
|
||||
{#if error}<p class="editor-notice" role="alert">{error}<button onclick={() => { error = ""; }}>{$t("Dismiss")}</button></p>{/if}
|
||||
|
||||
<style>
|
||||
.live-writer { position: absolute; inset: 0; }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { t } from "$lib/i18n";
|
||||
import { untrack } from "svelte";
|
||||
import type { OpenBuffer } from "$lib/workspace/types";
|
||||
import { workspaceReadDataUrl } from "$lib/workspace/api";
|
||||
@@ -228,7 +229,7 @@
|
||||
<div
|
||||
class="writer-host"
|
||||
role="application"
|
||||
aria-label="Writer"
|
||||
aria-label={$t("Writer")}
|
||||
bind:this={host}
|
||||
ondragover={(event) => {
|
||||
if (imageFiles(event.dataTransfer).length > 0) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { tr } from '../i18n/index.ts';
|
||||
import type { editor } from "monaco-editor";
|
||||
import { actionMenu, type ActionMenuItem } from "../ui/actionMenu";
|
||||
|
||||
@@ -36,19 +37,19 @@ export function codeMenu(view: editor.IStandaloneCodeEditor, report: (message: s
|
||||
};
|
||||
const run = (id: string) => { close(); void view.getAction(id)?.run(); };
|
||||
const items: ActionMenuItem[] = [
|
||||
{ label: "Undo", icon: "undo", shortcut: "Ctrl+Z", disabled: !model.canUndo(), run: () => { close(); view.trigger("code-menu", "undo", null); } },
|
||||
{ label: "Redo", icon: "redo", shortcut: "Ctrl+Shift+Z", disabled: !model.canRedo(), run: () => { close(); view.trigger("code-menu", "redo", null); } },
|
||||
{ label: tr("Undo"), icon: "undo", shortcut: "Ctrl+Z", disabled: !model.canUndo(), run: () => { close(); view.trigger("code-menu", "undo", null); } },
|
||||
{ label: tr("Redo"), icon: "redo", shortcut: "Ctrl+Shift+Z", disabled: !model.canRedo(), run: () => { close(); view.trigger("code-menu", "redo", null); } },
|
||||
{ separator: true },
|
||||
{ label: "Change all occurrences", icon: "select", shortcut: "Ctrl+F2", disabled: !view.getAction("editor.action.changeAll")?.isSupported(), run: () => run("editor.action.changeAll") },
|
||||
{ label: tr("Change all occurrences"), icon: "select", shortcut: "Ctrl+F2", disabled: !view.getAction("editor.action.changeAll")?.isSupported(), run: () => run("editor.action.changeAll") },
|
||||
{ separator: true },
|
||||
{ label: "Cut", icon: "cut", shortcut: "Ctrl+X", disabled: !selected, run: () => void clipboard("cut") },
|
||||
{ label: "Copy", icon: "copy", shortcut: "Ctrl+C", disabled: !selected, run: () => void clipboard("copy") },
|
||||
{ label: "Paste", icon: "paste", shortcut: "Ctrl+V", run: () => void clipboard("paste") },
|
||||
{ label: "Select all", icon: "select", shortcut: "Ctrl+A", run: () => { close(); view.setSelection(model.getFullModelRange()); } },
|
||||
{ label: tr("Cut"), icon: "cut", shortcut: "Ctrl+X", disabled: !selected, run: () => void clipboard("cut") },
|
||||
{ label: tr("Copy"), icon: "copy", shortcut: "Ctrl+C", disabled: !selected, run: () => void clipboard("copy") },
|
||||
{ label: tr("Paste"), icon: "paste", shortcut: "Ctrl+V", run: () => void clipboard("paste") },
|
||||
{ label: tr("Select all"), icon: "select", shortcut: "Ctrl+A", run: () => { close(); view.setSelection(model.getFullModelRange()); } },
|
||||
{ separator: true },
|
||||
{ label: "Command palette", icon: "terminal", shortcut: "F1", run: () => run("editor.action.quickCommand") },
|
||||
{ label: tr("Command palette"), icon: "terminal", shortcut: "F1", run: () => run("editor.action.quickCommand") },
|
||||
];
|
||||
root = actionMenu(x, y, items, close, "Code text actions");
|
||||
root = actionMenu(x, y, items, close, tr("Code text actions"));
|
||||
}
|
||||
return { open, close, destroy() {
|
||||
close(false);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { tr } from '../i18n/index.ts';
|
||||
import type MarkdownIt from "markdown-it";
|
||||
import type { Token } from "markdown-it";
|
||||
type MarkdownParser = InstanceType<typeof MarkdownIt>;
|
||||
@@ -60,15 +61,15 @@ export function footnotes(markdown: MarkdownParser) {
|
||||
markdown.renderer.rules.note_footnote_definition = () => "";
|
||||
markdown.renderer.rules.note_footnote_reference = (tokens, index) => {
|
||||
const { number, reference } = tokens[index].meta as { number: number; reference: number };
|
||||
return `<sup class="md-footnote-ref"><a href="#rs-fn-${number}" id="rs-fnref-${number}-${reference}" data-footnote-link aria-label="Footnote ${number}">${number}</a></sup>`;
|
||||
return `<sup class="md-footnote-ref"><a href="#rs-fn-${number}" id="rs-fnref-${number}-${reference}" data-footnote-link aria-label="${markdown.utils.escapeHtml(tr('Footnote {number}', { number }))}">${number}</a></sup>`;
|
||||
};
|
||||
}
|
||||
|
||||
export function renderFootnotes(markdown: MarkdownParser, env: FootnoteEnvironment): string {
|
||||
const notes = [...env.noteFootnotes?.values() ?? []].filter(note => note.number).sort((a, b) => a.number - b.number);
|
||||
if (!notes.length) return "";
|
||||
return '<section class="md-footnotes" aria-label="Footnotes"><ol>' + notes.map(note => {
|
||||
const backlinks = Array.from({ length: note.references }, (_, index) => `<a href="#rs-fnref-${note.number}-${index + 1}" class="md-footnote-back" data-footnote-link aria-label="Back to reference ${note.number}${index ? `, occurrence ${index + 1}` : ""}" title="Back to reference">↩</a>`).join(" ");
|
||||
return `<section class="md-footnotes" aria-label="${markdown.utils.escapeHtml(tr('Footnotes'))}"><ol>` + notes.map(note => {
|
||||
const backlinks = Array.from({ length: note.references }, (_, index) => `<a href="#rs-fnref-${note.number}-${index + 1}" class="md-footnote-back" data-footnote-link aria-label="${markdown.utils.escapeHtml(index ? tr('Back to reference {number}, occurrence {occurrence}', { number: note.number, occurrence: index + 1 }) : tr('Back to reference {number}', { number: note.number }))}" title="${markdown.utils.escapeHtml(tr('Back to reference'))}">↩</a>`).join(" ");
|
||||
return `<li id="rs-fn-${note.number}" tabindex="-1">${markdown.renderer.render(note.tokens, markdown.options, env)} ${backlinks}</li>`;
|
||||
}).join("") + "</ol></section>";
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { tr } from '../i18n/index.ts';
|
||||
import { StateField, type EditorState, type Range } from "@codemirror/state";
|
||||
import { Decoration, EditorView, WidgetType, keymap } from "@codemirror/view";
|
||||
import { codeFolding, foldEffect, foldKeymap, foldedRanges, foldService, syntaxTree, unfoldEffect } from "@codemirror/language";
|
||||
@@ -29,7 +30,7 @@ export function headingButton(label: string, collapsed: boolean): HTMLButtonElem
|
||||
button.type = "button";
|
||||
button.className = "rs-heading-toggle";
|
||||
button.setAttribute("aria-expanded", String(!collapsed));
|
||||
const title = `${collapsed ? "Expand" : "Collapse"} ${label || "heading"}`;
|
||||
const title = tr(collapsed ? "Expand {name}" : "Collapse {name}", { name: label || tr("heading") });
|
||||
button.setAttribute("aria-label", title);
|
||||
tooltipCleanups.set(button, attachTooltip(button, () => button.getAttribute("aria-label") || ""));
|
||||
const icon = actionIcon("chevron");
|
||||
@@ -100,7 +101,7 @@ export function readerHeadingFolding(root: HTMLElement, collapsed: Set<string>)
|
||||
headings.forEach(item => {
|
||||
const button = item.heading.querySelector<HTMLButtonElement>(".rs-heading-toggle");
|
||||
if (button) {
|
||||
const label = `${collapsed.has(item.key) ? "Expand" : "Collapse"} ${item.label}`;
|
||||
const label = tr(collapsed.has(item.key) ? "Expand {name}" : "Collapse {name}", { name: item.label });
|
||||
button.setAttribute("aria-expanded", String(!collapsed.has(item.key)));
|
||||
button.setAttribute("aria-label", label);
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { tr } from '../i18n/index.ts';
|
||||
import { actionIcon, type ActionIcon } from "../ui/actionIcons";
|
||||
import { attachTooltip } from "../ui/tooltip";
|
||||
const tooltipCleanups = new WeakMap<HTMLElement, () => void>();
|
||||
@@ -43,12 +44,12 @@ function button(label: string, icon: ActionIcon, action: () => void) {
|
||||
function zoomImage(original: HTMLImageElement, trigger: HTMLButtonElement) {
|
||||
const dialog = document.createElement("dialog");
|
||||
dialog.className = "image-lightbox";
|
||||
dialog.setAttribute("aria-label", "Image zoom");
|
||||
dialog.setAttribute("aria-label", tr("Image zoom"));
|
||||
const header = document.createElement("div");
|
||||
header.className = "image-lightbox-toolbar";
|
||||
const name = document.createElement("span");
|
||||
name.className = "image-lightbox-name";
|
||||
name.textContent = original.dataset.mdSrc || original.alt || "Image";
|
||||
name.textContent = original.dataset.mdSrc || original.alt || tr("Image");
|
||||
const viewport = document.createElement("div");
|
||||
viewport.className = "image-lightbox-viewport";
|
||||
const image = original.cloneNode() as HTMLImageElement;
|
||||
@@ -62,14 +63,14 @@ function zoomImage(original: HTMLImageElement, trigger: HTMLButtonElement) {
|
||||
scale = next;
|
||||
image.style.width = scale ? `${image.naturalWidth * scale}px` : "";
|
||||
viewport.classList.toggle("is-zoomed", scale > 0);
|
||||
status.textContent = scale ? `${Math.round(scale * 100)}%` : "Fit";
|
||||
status.textContent = scale ? `${Math.round(scale * 100)}%` : tr("Fit");
|
||||
zoomOut.disabled = scale === 0;
|
||||
zoomIn.disabled = scale >= 4;
|
||||
}
|
||||
const zoomOut = button("Zoom out", "zoom-out", () => resize(scale <= .5 ? 0 : scale / 2));
|
||||
const zoomIn = button("Zoom in", "zoom-in", () => resize(scale ? Math.min(4, scale * 2) : 1));
|
||||
const fit = button("Fit image", "select", () => resize(0));
|
||||
const close = button("Close image", "close", () => dialog.close());
|
||||
const zoomOut = button(tr("Zoom out"), "zoom-out", () => resize(scale <= .5 ? 0 : scale / 2));
|
||||
const zoomIn = button(tr("Zoom in"), "zoom-in", () => resize(scale ? Math.min(4, scale * 2) : 1));
|
||||
const fit = button(tr("Fit image"), "select", () => resize(0));
|
||||
const close = button(tr("Close image"), "close", () => dialog.close());
|
||||
header.append(name, zoomOut, status, zoomIn, fit, close);
|
||||
viewport.append(image);
|
||||
dialog.append(header, viewport);
|
||||
@@ -93,17 +94,17 @@ export function imageControls(root: HTMLElement, actions: ImageActions = {}, mea
|
||||
frame.contentEditable = "false";
|
||||
frame.tabIndex = 0;
|
||||
frame.setAttribute("role", "group");
|
||||
frame.setAttribute("aria-label", `Image: ${image.alt || image.dataset.mdSrc || "image"}`);
|
||||
frame.setAttribute("aria-label", tr("Image: {name}", { name: image.alt || image.dataset.mdSrc || tr("Image") }));
|
||||
image.replaceWith(frame);
|
||||
frame.append(image);
|
||||
image.draggable = false;
|
||||
const toolbar = document.createElement("span");
|
||||
toolbar.className = "md-image-actions";
|
||||
let closeZoom: (() => void) | undefined;
|
||||
const zoom = button("Zoom in", "zoom-in", () => { closeZoom = zoomImage(image, zoom); });
|
||||
const zoom = button(tr("Zoom in"), "zoom-in", () => { closeZoom = zoomImage(image, zoom); });
|
||||
cleanup.push(() => closeZoom?.());
|
||||
toolbar.append(zoom);
|
||||
if (actions.edit) toolbar.append(button(actions.editing ? "Hide image source" : "Edit image source", "code", actions.editing && actions.done ? actions.done : actions.edit));
|
||||
if (actions.edit) toolbar.append(button(actions.editing ? tr("Hide image source") : tr("Edit image source"), "code", actions.editing && actions.done ? actions.done : actions.edit));
|
||||
frame.append(toolbar);
|
||||
cleanup.push(() => toolbar.querySelectorAll<HTMLButtonElement>("button").forEach(button => tooltipCleanups.get(button)?.()));
|
||||
let menu: HTMLElement | undefined;
|
||||
@@ -125,19 +126,19 @@ export function imageControls(root: HTMLElement, actions: ImageActions = {}, mea
|
||||
function openMenu(x: number, y: number) {
|
||||
closeMenu(false); select();
|
||||
const items: ActionMenuItem[] = [
|
||||
{ label: "Copy image", icon: "copy", run: () => void run(() => copyImage(image)) },
|
||||
...(actions.markdown ? [{ label: "Copy Markdown", icon: "code" as const, run: () => void run(() => navigator.clipboard.writeText(actions.markdown!())) }] : []),
|
||||
...(actions.swap ? [{ label: "Swap image…", icon: "swap" as const, run: () => void run(() => actions.swap!(image)) }] : []),
|
||||
...(actions.remove ? [{ label: "Remove image", icon: "trash" as const, run: () => void run(actions.remove!) }] : []),
|
||||
{ label: tr("Copy image"), icon: "copy", run: () => void run(() => copyImage(image)) },
|
||||
...(actions.markdown ? [{ label: tr("Copy Markdown"), icon: "code" as const, run: () => void run(() => navigator.clipboard.writeText(actions.markdown!())) }] : []),
|
||||
...(actions.swap ? [{ label: tr("Swap image…"), icon: "swap" as const, run: () => void run(() => actions.swap!(image)) }] : []),
|
||||
...(actions.remove ? [{ label: tr("Remove image"), icon: "trash" as const, run: () => void run(actions.remove!) }] : []),
|
||||
{ separator: true },
|
||||
{ label: "Zoom in", icon: "zoom-in", run: () => { closeMenu(false); closeZoom = zoomImage(image, zoom); } },
|
||||
...(actions.edit ? [{ label: "Edit image source", icon: "code" as const, run: () => void run(actions.edit!) }] : []),
|
||||
...(actions.open ? [{ label: "Open in new tab", icon: "external" as const, run: () => void run(() => actions.open!(image)) }] : []),
|
||||
{ label: "Copy path", icon: "link", run: () => void run(() => navigator.clipboard.writeText(image.dataset.mdSrc || "")) },
|
||||
...(actions.reveal && !/^https?:/i.test(image.dataset.mdSrc || "") ? [{ label: "Show in Explorer", icon: "external" as const, run: () => void run(() => actions.reveal!(image)) }] : []),
|
||||
{ label: tr("Zoom in"), icon: "zoom-in", run: () => { closeMenu(false); closeZoom = zoomImage(image, zoom); } },
|
||||
...(actions.edit ? [{ label: tr("Edit image source"), icon: "code" as const, run: () => void run(actions.edit!) }] : []),
|
||||
...(actions.open ? [{ label: tr("Open in new tab"), icon: "external" as const, run: () => void run(() => actions.open!(image)) }] : []),
|
||||
{ label: tr("Copy path"), icon: "link", run: () => void run(() => navigator.clipboard.writeText(image.dataset.mdSrc || "")) },
|
||||
...(actions.reveal && !/^https?:/i.test(image.dataset.mdSrc || "") ? [{ label: tr("Show in Explorer"), icon: "external" as const, run: () => void run(() => actions.reveal!(image)) }] : []),
|
||||
];
|
||||
openingMenu = true;
|
||||
try { menu = actionMenu(x, y, items, closeMenu, "Image actions"); }
|
||||
try { menu = actionMenu(x, y, items, closeMenu, tr("Image actions")); }
|
||||
finally { openingMenu = false; }
|
||||
}
|
||||
frame.addEventListener("mousedown", event => { if (!(event.target as Element).closest("button")) { event.preventDefault(); event.stopPropagation(); select(); } });
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { tr } from '../i18n/index.ts';
|
||||
import { EditorView, WidgetType } from "@codemirror/view";
|
||||
import { isolateHistory } from "@codemirror/commands";
|
||||
import { imageControls, type ImageActions } from "./imageControls";
|
||||
@@ -48,9 +49,9 @@ export class ImagePreview extends WidgetType {
|
||||
report: this.context.report,
|
||||
swap: async image => {
|
||||
const before = view.state.doc;
|
||||
const path = (await requestText("Image path relative to this note, or https URL", image.dataset.mdSrc || ""))?.trim();
|
||||
const path = (await requestText(tr("Image path relative to this note, or https URL"), image.dataset.mdSrc || ""))?.trim();
|
||||
if (!path || !dom.isConnected || view.state.doc !== before) return;
|
||||
if (!isRemoteImage(path) && /^[a-z][a-z\d+.-]*:/i.test(path)) throw new Error("Choose a workspace image path or an http/https URL.");
|
||||
if (!isRemoteImage(path) && /^[a-z][a-z\d+.-]*:/i.test(path)) throw new Error(tr("Choose a workspace image path or an http/https URL."));
|
||||
await this.context.validate?.(path);
|
||||
if (!dom.isConnected || view.state.doc !== before) return;
|
||||
const target = path.replace(/[<>\s]/g, char => encodeURIComponent(char));
|
||||
@@ -63,7 +64,7 @@ export class ImagePreview extends WidgetType {
|
||||
if (!dom.querySelector("img")) {
|
||||
const edit = document.createElement("button");
|
||||
edit.type = "button"; edit.className = "image-action";
|
||||
const label = this.editing ? "Hide image source" : "Edit image source";
|
||||
const label = this.editing ? tr("Hide image source") : tr("Edit image source");
|
||||
edit.setAttribute("aria-label", label); edit.dataset.editorTooltip = label;
|
||||
edit.append(actionIcon("code"));
|
||||
edit.addEventListener("click", event => { event.preventDefault(); event.stopPropagation(); (this.editing ? actions.done : actions.edit)?.(); });
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { tr } from '../i18n/index.ts';
|
||||
import type { ActionMenuItem } from "../ui/actionMenu";
|
||||
|
||||
export type MenuLink = { kind: "md" | "wiki"; target: string };
|
||||
@@ -15,16 +16,16 @@ export function linkMenuItems(link: MenuLink, actions: DocumentLinkActions, clos
|
||||
};
|
||||
const external = /^(https?:\/\/|mailto:)/i.test(link.target);
|
||||
const items: ActionMenuItem[] = external ? [
|
||||
...(actions.browser && /^https?:\/\//i.test(link.target) ? [{ label: "Open link in app browser", icon: "globe" as const, run: run(() => actions.browser!(link.target)) }] : []),
|
||||
...(actions.defaultBrowser ? [{ label: "Open link in default browser", icon: "external" as const, run: run(() => actions.defaultBrowser!(link.target)) }] : []),
|
||||
...(actions.browser && /^https?:\/\//i.test(link.target) ? [{ label: tr("Open link in app browser"), icon: "globe" as const, run: run(() => actions.browser!(link.target)) }] : []),
|
||||
...(actions.defaultBrowser ? [{ label: tr("Open link in default browser"), icon: "external" as const, run: run(() => actions.defaultBrowser!(link.target)) }] : []),
|
||||
] : [];
|
||||
if (!items.length && actions.open) items.push({ label: external ? "Open link" : "Open in new tab", icon: external ? "external" : "file-plus", run: run(() => actions.open!(link)) });
|
||||
if (!items.length && actions.open) items.push({ label: external ? tr("Open link") : tr("Open in new tab"), icon: external ? "external" : "file-plus", run: run(() => actions.open!(link)) });
|
||||
if (!external && actions.workspaceItems) {
|
||||
const wrap = (item: ActionMenuItem): ActionMenuItem => "separator" in item ? item : { ...item, run: item.run ? run(item.run) : undefined, children: item.children?.map(wrap) };
|
||||
const workspaceItems = actions.workspaceItems(link).filter(item => !edit || "separator" in item || !["Rename…", "Move file to…", "Open in default app"].includes(item.label));
|
||||
const workspaceItems = actions.workspaceItems(link).filter(item => !edit || "separator" in item || ![tr("Rename…"), tr("Move file to…"), tr("Open in default app")].includes(item.label));
|
||||
items.push(...workspaceItems.map(wrap));
|
||||
}
|
||||
items.push({ label: external ? "Copy URL" : "Copy link target", icon: "link", run: run(() => navigator.clipboard.writeText(link.target)) });
|
||||
if (edit) items.push({ label: "Edit link", icon: "rename", run: () => { close(); edit(); } });
|
||||
items.push({ label: external ? tr("Copy URL") : tr("Copy link target"), icon: "link", run: run(() => navigator.clipboard.writeText(link.target)) });
|
||||
if (edit) items.push({ label: tr("Edit link"), icon: "rename", run: () => { close(); edit(); } });
|
||||
return items;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { tr } from '../i18n/index.ts';
|
||||
import { StateEffect, StateField, type EditorState, type Range } from "@codemirror/state";
|
||||
import { Decoration, EditorView, ViewPlugin, WidgetType, type DecorationSet } from "@codemirror/view";
|
||||
import { syntaxTree, foldedRanges, foldEffect, unfoldEffect } from "@codemirror/language";
|
||||
@@ -40,8 +41,8 @@ class CodeCopy extends WidgetType {
|
||||
const button = document.createElement("button");
|
||||
button.type = "button";
|
||||
button.className = "rs-fence-copy writer-code-copy";
|
||||
button.setAttribute("aria-label", "Copy code");
|
||||
button.dataset.editorTooltip = "Copy code";
|
||||
button.setAttribute("aria-label", tr("Copy code"));
|
||||
button.dataset.editorTooltip = tr("Copy code");
|
||||
button.append(actionIcon("copy"));
|
||||
button.onmousedown = event => event.preventDefault();
|
||||
button.onclick = async event => {
|
||||
@@ -49,11 +50,11 @@ class CodeCopy extends WidgetType {
|
||||
try {
|
||||
await navigator.clipboard.writeText(this.code);
|
||||
button.dataset.copied = "true";
|
||||
button.dataset.editorTooltip = "Copied";
|
||||
button.setAttribute("aria-label", "Code copied");
|
||||
button.dataset.editorTooltip = tr("Copied");
|
||||
button.setAttribute("aria-label", tr("Code copied"));
|
||||
} catch {
|
||||
button.dataset.editorTooltip = "Could not copy code";
|
||||
button.setAttribute("aria-label", "Could not copy code");
|
||||
button.dataset.editorTooltip = tr("Could not copy code");
|
||||
button.setAttribute("aria-label", tr("Could not copy code"));
|
||||
}
|
||||
};
|
||||
return button;
|
||||
@@ -86,7 +87,7 @@ class Checkbox extends WidgetType {
|
||||
box.type = "checkbox";
|
||||
box.checked = this.checked;
|
||||
box.className = "writer-checkbox";
|
||||
box.setAttribute("aria-label", this.checked ? "Mark task incomplete" : "Mark task complete");
|
||||
box.setAttribute("aria-label", this.checked ? tr("Mark task incomplete") : tr("Mark task complete"));
|
||||
box.addEventListener("mousedown", event => event.preventDefault());
|
||||
box.addEventListener("click", event => {
|
||||
event.stopPropagation();
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { tr } from "../i18n/index.ts";
|
||||
import { actionMenu, type ActionMenuItem } from "../ui/actionMenu";
|
||||
import { invoke, isTauri } from "@tauri-apps/api/core";
|
||||
import { wordAt } from "./spellingWord";
|
||||
@@ -89,40 +90,40 @@ export function markdownMenu(editor: MarkdownMenuEditor, actions: TableContextAc
|
||||
editor.select(selectedLink.targetFrom, selectedLink.targetTo); editor.focus();
|
||||
}), { separator: true as const }] : []),
|
||||
...(editor.undo ? [
|
||||
{ label: "Undo", icon: "undo" as const, shortcut: "Ctrl+Z", disabled: !editor.canUndo?.(), run: () => { close(); editor.undo?.(); } },
|
||||
{ label: "Redo", icon: "redo" as const, shortcut: "Ctrl+Shift+Z", disabled: !editor.canRedo?.(), run: () => { close(); editor.redo?.(); } },
|
||||
{ label: tr("Undo"), icon: "undo" as const, shortcut: "Ctrl+Z", disabled: !editor.canUndo?.(), run: () => { close(); editor.undo?.(); } },
|
||||
{ label: tr("Redo"), icon: "redo" as const, shortcut: "Ctrl+Shift+Z", disabled: !editor.canRedo?.(), run: () => { close(); editor.redo?.(); } },
|
||||
{ separator: true as const },
|
||||
] : []),
|
||||
{ label: "Add link", icon: "link", run: () => link(false) },
|
||||
{ label: "Add external link", icon: "external", run: () => link(true) },
|
||||
{ label: tr("Add link"), icon: "link", run: () => link(false) },
|
||||
{ label: tr("Add external link"), icon: "external", run: () => link(true) },
|
||||
{ separator: true },
|
||||
{ label: text ? `Search for “${text.length > 32 ? text.slice(0, 32) + "…" : text}”` : "Search selection", icon: "search", disabled: !text || !actions.onSearch, run: () => { close(); actions.onSearch?.(text); } },
|
||||
{ label: "Extract current selection…", icon: "extract", disabled: !text || !actions.onExtract, run: () => void request(async () => {
|
||||
{ label: text ? tr("Search for “{text}”", { text: text.length > 32 ? text.slice(0, 32) + "…" : text }) : tr("Search selection"), icon: "search", disabled: !text || !actions.onSearch, run: () => { close(); actions.onSearch?.(text); } },
|
||||
{ label: tr("Extract current selection…"), icon: "extract", disabled: !text || !actions.onExtract, run: () => void request(async () => {
|
||||
const target = await actions.onExtract?.(text, text, valid);
|
||||
if (target) apply(replacement(selection, `[[${target}|${text.replace(/[\[\]|]/g, "").replace(/\s+/g, " ").trim()}]]`));
|
||||
}) },
|
||||
{ label: "Format", icon: "format", children: cellFormats.flatMap(([label, kind]) => [
|
||||
{ label: tr("Format"), icon: "format", children: cellFormats.flatMap(([label, kind]) => [
|
||||
...(kind === "code" || kind === "clear" ? [{ separator: true } as const] : []),
|
||||
{ label, icon: kind, disabled: kind === "clear" && !text, run: () => apply(formatText(source, selection, kind)) },
|
||||
{ label: tr(label), icon: kind, disabled: kind === "clear" && !text, run: () => apply(formatText(source, selection, kind)) },
|
||||
]) },
|
||||
{ label: "Paragraph", icon: "paragraph", children: [
|
||||
paragraph("Bullet list", "bullet", "bullet"), paragraph("Numbered list", "number", "number"), paragraph("Task list", "task", "task"),
|
||||
{ label: tr("Paragraph"), icon: "paragraph", children: [
|
||||
paragraph(tr("Bullet list"), "bullet", "bullet"), paragraph(tr("Numbered list"), "number", "number"), paragraph(tr("Task list"), "task", "task"),
|
||||
{ separator: true },
|
||||
...([1, 2, 3, 4, 5, 6] as const).map(level => paragraph(`Heading ${level}`, level, "heading")),
|
||||
paragraph("Body", "body", "paragraph"), { separator: true }, paragraph("Quote", "quote", "quote"),
|
||||
...([1, 2, 3, 4, 5, 6] as const).map(level => paragraph(tr("Heading {level}", { level }), level, "heading")),
|
||||
paragraph(tr("Body"), "body", "paragraph"), { separator: true }, paragraph(tr("Quote"), "quote", "quote"),
|
||||
] },
|
||||
{ label: "Insert", icon: "insert", children: [
|
||||
insert("Footnote", "footnote", "footnote"), insert("Table", "table", "table"), insert("Callout", "callout", "quote"), insert("Horizontal rule", "rule", "rule"),
|
||||
{ separator: true }, insert("Code block", "code", "code"), insert("Math block", "math", "math"),
|
||||
{ label: tr("Insert"), icon: "insert", children: [
|
||||
insert(tr("Footnote"), "footnote", "footnote"), insert(tr("Table"), "table", "table"), insert(tr("Callout"), "callout", "quote"), insert(tr("Horizontal rule"), "rule", "rule"),
|
||||
{ separator: true }, insert(tr("Code block"), "code", "code"), insert(tr("Math block"), "math", "math"),
|
||||
] },
|
||||
{ separator: true },
|
||||
{ label: "Cut", icon: "cut", disabled: !text, run: () => clipboard("cut") },
|
||||
{ label: "Copy", icon: "copy", disabled: !text, run: () => clipboard("copy") },
|
||||
{ label: "Paste", icon: "paste", run: () => clipboard("paste") },
|
||||
{ label: "Paste as plain text", icon: "paste-text", run: () => clipboard("plain") },
|
||||
{ label: "Select all", icon: "select", run: () => { close(); editor.selectAll(); } },
|
||||
{ label: tr("Cut"), icon: "cut", disabled: !text, run: () => clipboard("cut") },
|
||||
{ label: tr("Copy"), icon: "copy", disabled: !text, run: () => clipboard("copy") },
|
||||
{ label: tr("Paste"), icon: "paste", run: () => clipboard("paste") },
|
||||
{ label: tr("Paste as plain text"), icon: "paste-text", run: () => clipboard("plain") },
|
||||
{ label: tr("Select all"), icon: "select", run: () => { close(); editor.selectAll(); } },
|
||||
];
|
||||
root = actionMenu(x, y, items, close, "Markdown text actions");
|
||||
root = actionMenu(x, y, items, close, tr("Markdown text actions"));
|
||||
const opened = root;
|
||||
const word = spellingOffset === undefined ? null : wordAt(source, spellingOffset);
|
||||
if (word && isTauri()) {
|
||||
@@ -130,14 +131,14 @@ export function markdownMenu(editor: MarkdownMenuEditor, actions: TableContextAc
|
||||
void invoke<{ language: string; words: string[]; misspelled: boolean }>("spelling_suggestions", { word: word.word, languages }).then(result => {
|
||||
if (!result.misspelled || root !== opened || !valid()) return;
|
||||
const suggestions: ActionMenuItem[] = result.words.map(value => ({ label: value, run: () => apply(replacement(word, value)) }));
|
||||
if (!suggestions.length) suggestions.push({ label: "No spelling suggestions", disabled: true });
|
||||
suggestions.push({ label: "Add to dictionary", icon: "book", run: () => {
|
||||
if (!suggestions.length) suggestions.push({ label: tr("No spelling suggestions"), disabled: true });
|
||||
suggestions.push({ label: tr("Add to dictionary"), icon: "book", run: () => {
|
||||
close();
|
||||
void invoke("spelling_suggestions", { word: word.word, languages: [result.language], add: true }).catch(() => report("Could not add the word to the dictionary."));
|
||||
} });
|
||||
const focusedLabel = opened.contains(document.activeElement) ? document.activeElement?.querySelector(".action-label")?.textContent : undefined;
|
||||
opened.remove();
|
||||
root = actionMenu(x, y, [...suggestions, { separator: true }, ...items], close, "Markdown text actions");
|
||||
root = actionMenu(x, y, [...suggestions, { separator: true }, ...items], close, tr("Markdown text actions"));
|
||||
if (focusedLabel) [...root.querySelectorAll<HTMLButtonElement>(":scope > button")].find(button => button.querySelector(".action-label")?.textContent === focusedLabel)?.focus();
|
||||
}).catch(() => { /* Editing actions remain available without spelling suggestions. */ });
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { tr } from '../i18n/index.ts';
|
||||
import { Decoration, EditorView, WidgetType } from "@codemirror/view";
|
||||
import { actionIcon } from "../ui/actionIcons";
|
||||
|
||||
@@ -19,14 +20,14 @@ class NoteTitle extends WidgetType {
|
||||
const button = document.createElement("button");
|
||||
button.type = "button";
|
||||
button.className = "note-title-button";
|
||||
button.setAttribute("aria-label", "Rename note");
|
||||
button.setAttribute("aria-label", tr("Rename note"));
|
||||
button.append(document.createTextNode(this.title), actionIcon("rename"));
|
||||
button.dataset.editorTooltip = "Rename note";
|
||||
button.dataset.editorTooltip = tr("Rename note");
|
||||
heading.replaceChildren(button);
|
||||
|
||||
const input = document.createElement("input");
|
||||
input.className = "note-title-input";
|
||||
input.setAttribute("aria-label", "Note filename");
|
||||
input.setAttribute("aria-label", tr("Note filename"));
|
||||
input.autocomplete = "off";
|
||||
input.spellcheck = false;
|
||||
input.hidden = true;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { tr } from '../i18n/index.ts';
|
||||
import { actionMenu, type ActionMenuItem } from "../ui/actionMenu";
|
||||
import { linkMenuItems, type DocumentLinkActions } from "./linkMenu";
|
||||
|
||||
@@ -31,16 +32,16 @@ export function readingMenu(host: HTMLElement, actions: DocumentLinkActions, sea
|
||||
previousFocus = document.activeElement instanceof HTMLElement && host.contains(document.activeElement) ? document.activeElement : host;
|
||||
const items: ActionMenuItem[] = [];
|
||||
if (text) items.push(
|
||||
{ label: "Copy", icon: "copy", shortcut: "Ctrl+C", run: () => { close(); void navigator.clipboard.writeText(text).catch(() => report("Clipboard unavailable. Use Ctrl+C to copy.")); } },
|
||||
{ label: `Search for “${text.length > 32 ? text.slice(0, 32) + "…" : text}”`, icon: "search", disabled: !search, run: () => { close(false); search?.(text); } },
|
||||
{ label: tr("Copy"), icon: "copy", shortcut: "Ctrl+C", run: () => { close(); void navigator.clipboard.writeText(text).catch(() => report(tr("Clipboard unavailable. Use Ctrl+C to copy."))); } },
|
||||
{ label: tr("Search for “{text}”", { text: text.length > 32 ? text.slice(0, 32) + "…" : text }), icon: "search", disabled: !search, run: () => { close(false); search?.(text); } },
|
||||
);
|
||||
if (anchor) {
|
||||
if (items.length) items.push({ separator: true });
|
||||
if (anchor.hasAttribute("data-footnote-link")) items.push({ label: "Open link", icon: "link", run: () => { close(false); (anchor as HTMLElement).click(); } });
|
||||
if (anchor.hasAttribute("data-footnote-link")) items.push({ label: tr("Open link"), icon: "link", run: () => { close(false); (anchor as HTMLElement).click(); } });
|
||||
else items.push(...linkMenuItems({ kind: anchor.getAttribute("data-kind") === "wiki" ? "wiki" : "md", target: anchor.getAttribute("href") ?? "" }, actions, () => close(false), report));
|
||||
}
|
||||
const rect = keyboard ? (range?.getBoundingClientRect() ?? anchor?.getBoundingClientRect() ?? host.getBoundingClientRect()) : null;
|
||||
root = actionMenu(rect?.left ?? (event as MouseEvent).clientX, rect?.bottom ?? (event as MouseEvent).clientY, items, close, "Reading actions");
|
||||
root = actionMenu(rect?.left ?? (event as MouseEvent).clientX, rect?.bottom ?? (event as MouseEvent).clientY, items, close, tr("Reading actions"));
|
||||
}
|
||||
const outside = (event: Event) => { if (root && event.target instanceof Node && !root.contains(event.target)) close(false); };
|
||||
const resize = () => close(false);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { tr } from "../i18n/index.ts";
|
||||
import { invoke, isTauri } from "@tauri-apps/api/core";
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
import { actionMenu, type ActionMenuItem } from "../ui/actionMenu";
|
||||
@@ -87,32 +88,40 @@ export function mountSpellingMenu(): () => void {
|
||||
const { target, x, y, word } = context;
|
||||
const requestRevision = ++revision;
|
||||
let items = spellingItems(payload.items, id => finish(id, true));
|
||||
const parent = target.closest<HTMLDialogElement>("dialog[open]") ?? document.body;
|
||||
const show = () => {
|
||||
const previous = active?.request === payload.request ? active.root : undefined;
|
||||
const focusedLabel = previous?.contains(document.activeElement) ? document.activeElement?.querySelector(".action-label")?.textContent : undefined;
|
||||
previous?.remove();
|
||||
const root = actionMenu(x, y, items, () => finish(null, true), tr("Spelling actions"), parent);
|
||||
active = { request: payload.request, root, target };
|
||||
if (focusedLabel) [...root.querySelectorAll<HTMLButtonElement>(":scope > button")].find(button => button.querySelector(".action-label")?.textContent === focusedLabel)?.focus();
|
||||
};
|
||||
if (payload.fallback_spelling) {
|
||||
const readable = (entries: NativeSpellingItem[]): NativeSpellingItem[] => entries.filter(item => item.kind === 3 || item.label.trim()).map(item => ({ ...item, children: readable(item.children) }));
|
||||
items = spellingItems(readable(payload.items), id => finish(id, true));
|
||||
show();
|
||||
if (word) {
|
||||
const languages = [...new Set([target.lang, document.documentElement.lang, ...navigator.languages].filter(Boolean))];
|
||||
try {
|
||||
const result = await invoke<{ language: string; words: string[]; misspelled: boolean }>("spelling_suggestions", { word: word.word, languages });
|
||||
const suggestions: ActionMenuItem[] = result.words.map(value => ({ label: value, run: () => { finish(); word.replace(value); } }));
|
||||
if (result.misspelled && !suggestions.length) suggestions.push({ label: "No spelling suggestions", disabled: true });
|
||||
if (result.misspelled) suggestions.push({ label: "Add to dictionary", icon: "book", run: () => {
|
||||
if (result.misspelled && !suggestions.length) suggestions.push({ label: tr("No spelling suggestions"), disabled: true });
|
||||
if (result.misspelled) suggestions.push({ label: tr("Add to dictionary"), icon: "book", run: () => {
|
||||
finish(null, true);
|
||||
void invoke("spelling_suggestions", { word: word.word, languages: [result.language], add: true }).catch(error => console.error("Could not add the word", error));
|
||||
} }, { separator: true });
|
||||
items = [...suggestions, ...items];
|
||||
} catch {
|
||||
items = [{ label: "Spelling suggestions unavailable", disabled: true }, { separator: true }, ...items];
|
||||
items = [{ label: tr("Spelling suggestions unavailable"), disabled: true }, { separator: true }, ...items];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (disposed || requestRevision !== revision || !target.isConnected || (payload.fallback_spelling && word && !word.valid())) {
|
||||
if (disposed || requestRevision !== revision || (payload.fallback_spelling && active?.request !== payload.request) || !target.isConnected || (payload.fallback_spelling && word && !word.valid())) {
|
||||
void invoke("spelling_menu_select", { request: payload.request, command: null });
|
||||
return;
|
||||
}
|
||||
const parent = target.closest<HTMLDialogElement>("dialog[open]") ?? document.body;
|
||||
const root = actionMenu(x, y, items, () => finish(null, true), "Spelling actions", parent);
|
||||
active = { request: payload.request, root, target };
|
||||
show();
|
||||
}).then(async stop => {
|
||||
if (disposed) { stop(); return; }
|
||||
unlisten = stop;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { tr } from '../i18n/index.ts';
|
||||
import { getMarkRange, type Editor, type JSONContent } from "@tiptap/core";
|
||||
import { requestText } from "../workspace/dialogs.svelte";
|
||||
import { extractedCellMarkdown } from "./tableCellMarkdown";
|
||||
@@ -29,15 +30,15 @@ export function tableTextItems(editor: Editor, actions: TableContextActions, clo
|
||||
}
|
||||
function link(external: boolean) {
|
||||
void request(async () => {
|
||||
const target = await requestText(external ? "External link URL" : "Link to note (name or workspace path)", external ? "https://" : text);
|
||||
const target = await requestText(external ? tr("External link URL") : tr("Link to note (name or workspace path)"), external ? "https://" : text);
|
||||
if (!target || !valid()) return;
|
||||
if (external) {
|
||||
try {
|
||||
const url = new URL(target);
|
||||
if (!(["http:", "https:"].includes(url.protocol) && url.hostname || url.protocol === "mailto:" && url.pathname.includes("@")) || /\s/.test(target)) throw new Error("Invalid URL");
|
||||
} catch { report("Enter a valid http, https, or mailto link."); return; }
|
||||
} catch { report(tr("Enter a valid http, https, or mailto link.")); return; }
|
||||
}
|
||||
if (!external && /[\[\]|\r\n]|^[a-z][a-z\d+.-]*:/i.test(target)) { report("Enter a note name or path without brackets or pipes."); return; }
|
||||
if (!external && /[\[\]|\r\n]|^[a-z][a-z\d+.-]*:/i.test(target)) { report(tr("Enter a note name or path without brackets or pipes.")); return; }
|
||||
run(() => {
|
||||
const attrs = { href: target, "data-kind": external ? "md" : "wiki" };
|
||||
if (selection.empty) editor.commands.insertContent({ type: "text", text: target, marks: [{ type: "link", attrs }] });
|
||||
@@ -88,35 +89,35 @@ export function tableTextItems(editor: Editor, actions: TableContextActions, clo
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch { report("Clipboard unavailable. Use the keyboard shortcut to copy, cut, or paste."); }
|
||||
} catch { report(tr("Clipboard unavailable. Use the keyboard shortcut to copy, cut, or paste.")); }
|
||||
});
|
||||
}
|
||||
const items: ActionMenuItem[] = [
|
||||
...(selectedLink ? [...linkMenuItems(selectedLink, actions.linkActions?.() || {}, close, report, editLink), { separator: true as const }] : []),
|
||||
{ label: "Add link", icon: "link", run: () => link(false) },
|
||||
{ label: "Add external link", icon: "external", run: () => link(true) },
|
||||
{ label: tr("Add link"), icon: "link", run: () => link(false) },
|
||||
{ label: tr("Add external link"), icon: "external", run: () => link(true) },
|
||||
{ separator: true },
|
||||
{ label: text ? `Search for “${text.length > 32 ? text.slice(0, 32) + "…" : text}”` : "Search selection", icon: "search", disabled: !text || !actions.onSearch, run: () => { close(); actions.onSearch?.(text); } },
|
||||
{ label: "Extract current selection…", icon: "extract", disabled: !text || !actions.onExtract, run: () => void request(async () => {
|
||||
{ label: text ? tr("Search for “{text}”", { text: text.length > 32 ? text.slice(0, 32) + "…" : text }) : tr("Search selection"), icon: "search", disabled: !text || !actions.onSearch, run: () => { close(); actions.onSearch?.(text); } },
|
||||
{ label: tr("Extract current selection…"), icon: "extract", disabled: !text || !actions.onExtract, run: () => void request(async () => {
|
||||
const selected = doc.slice(selection.from, selection.to).content.toJSON() as JSONContent[] | null;
|
||||
const markdown = extractedCellMarkdown(selected || []);
|
||||
const target = await actions.onExtract?.(markdown, text, valid);
|
||||
if (target) run(() => { editor.commands.insertContent({ type: "text", text: text.replace(/\s+/g, " ").trim(), marks: [{ type: "link", attrs: { href: target, "data-kind": "wiki" } }] }); });
|
||||
}) },
|
||||
{ label: "Format", icon: "format", children: cellFormats.map(([label, kind]) => ({ label, icon: kind, disabled: selection.empty, run: () => run(() => {
|
||||
{ label: tr("Format"), icon: "format", children: cellFormats.map(([label, kind]) => ({ label: tr(label), icon: kind, disabled: selection.empty, run: () => run(() => {
|
||||
if (kind === "clear") editor.commands.unsetAllMarks(); else editor.commands.toggleMark(kind);
|
||||
}) })) },
|
||||
{ label: "Paragraph", icon: "paragraph", disabled: true, title: "Markdown table cells contain inline text" },
|
||||
{ label: "Insert", icon: "insert", disabled: true, title: "Use the Row and Column menus to change the table" },
|
||||
{ label: tr("Paragraph"), icon: "paragraph", disabled: true, title: tr("Markdown table cells contain inline text") },
|
||||
{ label: tr("Insert"), icon: "insert", disabled: true, title: tr("Use the Row and Column menus to change the table") },
|
||||
{ separator: true },
|
||||
{ label: "Cut", icon: "cut", disabled: selection.empty, run: () => void clipboard("cut") },
|
||||
{ label: "Copy", icon: "copy", disabled: selection.empty, run: () => void clipboard("copy") },
|
||||
{ label: "Paste", icon: "paste", run: () => void clipboard("paste") },
|
||||
{ label: "Paste as plain text", icon: "paste-text", run: () => void clipboard("plain") },
|
||||
{ label: "Select all", icon: "select", run: () => { close(); editor.commands.selectAll(); editor.view.focus(); } },
|
||||
{ label: tr("Cut"), icon: "cut", disabled: selection.empty, run: () => void clipboard("cut") },
|
||||
{ label: tr("Copy"), icon: "copy", disabled: selection.empty, run: () => void clipboard("copy") },
|
||||
{ label: tr("Paste"), icon: "paste", run: () => void clipboard("paste") },
|
||||
{ label: tr("Paste as plain text"), icon: "paste-text", run: () => void clipboard("plain") },
|
||||
{ label: tr("Select all"), icon: "select", run: () => { close(); editor.commands.selectAll(); editor.view.focus(); } },
|
||||
];
|
||||
return sourceEditing ? [
|
||||
...(selectedLink ? [...linkMenuItems(selectedLink, actions.linkActions?.() || {}, close, report, editLink), { separator: true as const }] : []),
|
||||
...items.slice(items.findIndex(item => "label" in item && item.label === "Cut")),
|
||||
...items.slice(items.findIndex(item => "label" in item && item.label === tr("Cut"))),
|
||||
] : items;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { tr } from '../i18n/index.ts';
|
||||
import { Editor, Extension, Mark, getMarkRange } from "@tiptap/core";
|
||||
import { Plugin } from "@tiptap/pm/state";
|
||||
import { Decoration, DecorationSet } from "@tiptap/pm/view";
|
||||
@@ -96,7 +97,7 @@ export function tableControls(root: HTMLElement, view: EditorView, initialSource
|
||||
cell.removeAttribute("title");
|
||||
if (result && cell !== active) cell.innerHTML = formulas.tableFormulaHtml(result);
|
||||
if (cell === active) {
|
||||
formulaStatus.textContent = `${address}${result ? ` = ${result.text}` : " · Type = to calculate"}`;
|
||||
formulaStatus.textContent = `${address}${result ? ` = ${result.text}` : tr(" · Type = to calculate")}`;
|
||||
formulaHint.textContent = result?.error ? formulas.formulaErrors[result.error] : "";
|
||||
formulaHint.hidden = !formulaHint.textContent;
|
||||
}
|
||||
@@ -136,7 +137,7 @@ export function tableControls(root: HTMLElement, view: EditorView, initialSource
|
||||
cell.innerHTML = html;
|
||||
cell.classList.remove("is-editing", "is-source-editing");
|
||||
refreshFormulas();
|
||||
formulaStatus.textContent = "Type = in a cell to calculate";
|
||||
formulaStatus.textContent = tr("Type = in a cell to calculate");
|
||||
formulaHint.hidden = true;
|
||||
view.requestMeasure();
|
||||
if (!firstEdit) view.dispatch({ annotations: isolateHistory.of("after") });
|
||||
@@ -390,7 +391,7 @@ export function tableControls(root: HTMLElement, view: EditorView, initialSource
|
||||
wrapper.after(footer);
|
||||
for (const kind of ["column", "row"] as const) {
|
||||
const button = document.createElement("button");
|
||||
const label = kind === "column" ? "Add column to the right" : "Add row below";
|
||||
const label = kind === "column" ? tr("Add column to the right") : tr("Add row below");
|
||||
button.type = "button";
|
||||
button.className = `table-add table-add-${kind}`;
|
||||
tooltipCleanup.push(attachTooltip(button, () => label));
|
||||
@@ -409,7 +410,7 @@ export function tableControls(root: HTMLElement, view: EditorView, initialSource
|
||||
}
|
||||
for (const row of table.rows) for (const cell of row.cells) {
|
||||
cell.tabIndex = 0;
|
||||
cell.setAttribute("aria-label", `${formulas ? formulas.cellAddress(row.rowIndex, cell.cellIndex) + " · " : ""}Row ${row.rowIndex + 1}, column ${cell.cellIndex + 1}`);
|
||||
cell.setAttribute("aria-label", (formulas ? formulas.cellAddress(row.rowIndex, cell.cellIndex) + " · " : "") + tr("Row {row}, column {column}", { row: row.rowIndex + 1, column: cell.cellIndex + 1 }));
|
||||
cell.addEventListener("focus", () => activate(cell));
|
||||
}
|
||||
selectionControls = tableSelectionControls(root, wrapper, table, view, () => controller.source, finish, change, { get: () => editor, activate, editSource }, actions);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { tr } from '../i18n/index.ts';
|
||||
import type { EditorView } from "@codemirror/view";
|
||||
import { actionIcon } from "../ui/actionIcons";
|
||||
import { moveTableAxis, type TableAxis } from "./tableStructure";
|
||||
@@ -102,7 +103,7 @@ export function tableDragControls(root: HTMLElement, wrapper: HTMLElement, table
|
||||
if (!preview || !previewLabel || !drag) return;
|
||||
const valid = drag.to !== undefined;
|
||||
preview.classList.toggle("is-invalid-drop", !valid);
|
||||
previewLabel.textContent = `${drag.axis === "row" ? "Row" : "Column"} ${drag.index + 1}${valid ? ` → ${drag.to! + 1}` : " · Release to cancel"}`;
|
||||
previewLabel.textContent = `${drag.axis === "row" ? tr("Row") : tr("Column")} ${drag.index + 1}${valid ? ` → ${drag.to! + 1}` : tr(" · Release to cancel")}`;
|
||||
const rect = preview.getBoundingClientRect();
|
||||
const x = Math.max(8, Math.min(drag.x + 16, window.innerWidth - rect.width - 8));
|
||||
const y = Math.max(8, Math.min(drag.y + 16, window.innerHeight - rect.height - 8));
|
||||
@@ -171,8 +172,8 @@ export function tableDragControls(root: HTMLElement, wrapper: HTMLElement, table
|
||||
button.type = "button";
|
||||
button.className = `table-drag-handle table-drag-${axis}`;
|
||||
button.dataset.index = String(index);
|
||||
const label = `Move ${axis} ${index + 1}`;
|
||||
const tooltip = `${label} · Drag to reorder · ${axis === "row" ? "↑/↓" : "←/→"} to move`;
|
||||
const label = tr(axis === "row" ? "Move row {number}" : "Move column {number}", { number: index + 1 });
|
||||
const tooltip = tr("{label} · Drag to reorder · {keys} to move", { label, keys: axis === "row" ? "↑/↓" : "←/→" });
|
||||
button.setAttribute("aria-label", label);
|
||||
tooltipCleanup.push(attachTooltip(button, () => drag ? "" : tooltip));
|
||||
button.append(actionIcon("grip"));
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { tr } from '../i18n/index.ts';
|
||||
import type { EditorView } from "@codemirror/view";
|
||||
import { isolateHistory } from "@codemirror/commands";
|
||||
import { undo, redo } from "./writerHistory";
|
||||
@@ -103,9 +104,9 @@ export function tableSelectionControls(root: HTMLElement, wrapper: HTMLElement,
|
||||
apply((text, selected) => alignTableCells(text, selected, alignment));
|
||||
};
|
||||
const alignmentItems: ActionMenuItem[] = [
|
||||
{ label: "Align left", icon: "left", run: () => align("left") },
|
||||
{ label: "Align centre", icon: "center", run: () => align("center") },
|
||||
{ label: "Align right", icon: "right", run: () => align("right") },
|
||||
{ label: tr("Align left"), icon: "left", run: () => align("left") },
|
||||
{ label: tr("Align centre"), icon: "center", run: () => align("center") },
|
||||
{ label: tr("Align right"), icon: "right", run: () => align("right") },
|
||||
].map(item => ({ ...item, title: "Alignment applies to the selected Markdown columns" } as ActionMenuItem));
|
||||
const report = (message: string) => {
|
||||
const status = root.querySelector<HTMLElement>(".table-edit-help");
|
||||
@@ -114,34 +115,34 @@ export function tableSelectionControls(root: HTMLElement, wrapper: HTMLElement,
|
||||
const items: ActionMenuItem[] = textEditor ? tableTextItems(textEditor, actions, closeMenu, run => {
|
||||
view.dispatch({ annotations: isolateHistory.of("before") }); run(); view.dispatch({ annotations: isolateHistory.of("after") });
|
||||
}, value => { pending = value; }, report, rich.editSource) : [
|
||||
...(["cut", "copy", "paste"] as const).map(action => ({ label: action[0].toUpperCase() + action.slice(1), icon: action, run: () => void clipboard(action) })),
|
||||
...(["cut", "copy", "paste"] as const).map(action => ({ label: tr(action[0].toUpperCase() + action.slice(1)), icon: action, run: () => void clipboard(action) })),
|
||||
sep,
|
||||
{ label: "Format", icon: "format", children: cellFormats.map(([label, kind]) => ({ label, icon: kind, run: () => format(kind) })) },
|
||||
{ label: tr("Format"), icon: "format", children: cellFormats.map(([label, kind]) => ({ label: tr(label), icon: kind, run: () => format(kind) })) },
|
||||
...alignmentItems,
|
||||
sep, { label: "Clear cells", icon: "clear", run: clearCells, title: "Clear selected values and keep the cells." },
|
||||
{ label: "Delete cells", icon: "trash", run: deleteCells, title: "Delete or Backspace removes full rows or columns. Other selections shift cells left." },
|
||||
sep, { label: tr("Clear cells"), icon: "clear", run: clearCells, title: tr("Clear selected values and keep the cells.") },
|
||||
{ label: tr("Delete cells"), icon: "trash", run: deleteCells, title: tr("Delete or Backspace removes full rows or columns. Other selections shift cells left.") },
|
||||
];
|
||||
if (textEditor) items.push(sep, { label: "Select cell", icon: "select", title: "Select this cell, then use Shift+arrow keys to extend the selection", run: () => { closeMenu(); select(cellRange); } });
|
||||
if (textEditor) items.push(sep, { label: tr("Select cell"), icon: "select", title: tr("Select this cell, then use Shift+arrow keys to extend the selection"), run: () => { closeMenu(); select(cellRange); } });
|
||||
items.push(sep,
|
||||
{ label: "Row", icon: "row", children: [
|
||||
{ label: "Add row above", icon: "row-before", disabled: row === 0, title: row === 0 ? "The first row is the Markdown header" : undefined, run: () => structural("row", "before") },
|
||||
{ label: "Add row below", icon: "row-after", run: () => structural("row", "after") }, sep,
|
||||
{ label: "Move row up", icon: "up", disabled: row <= 1, run: () => structural("row", "previous") },
|
||||
{ label: "Move row down", icon: "down", disabled: row === 0 || row === lastRow, run: () => structural("row", "next") }, sep,
|
||||
{ label: "Duplicate row", icon: "copy", run: () => structural("row", "duplicate") },
|
||||
{ label: "Delete row", icon: "trash", run: () => structural("row", "delete") },
|
||||
{ label: tr("Row"), icon: "row", children: [
|
||||
{ label: tr("Add row above"), icon: "row-before", disabled: row === 0, title: row === 0 ? tr("The first row is the Markdown header") : undefined, run: () => structural("row", "before") },
|
||||
{ label: tr("Add row below"), icon: "row-after", run: () => structural("row", "after") }, sep,
|
||||
{ label: tr("Move row up"), icon: "up", disabled: row <= 1, run: () => structural("row", "previous") },
|
||||
{ label: tr("Move row down"), icon: "down", disabled: row === 0 || row === lastRow, run: () => structural("row", "next") }, sep,
|
||||
{ label: tr("Duplicate row"), icon: "copy", run: () => structural("row", "duplicate") },
|
||||
{ label: tr("Delete row"), icon: "trash", run: () => structural("row", "delete") },
|
||||
] },
|
||||
{ label: "Column", icon: "column", children: [
|
||||
{ label: "Add column to the left", icon: "column-before", run: () => structural("column", "before") },
|
||||
{ label: "Add column to the right", icon: "column-after", run: () => structural("column", "after") }, sep,
|
||||
{ label: "Move column left", icon: "move-left", disabled: column === 0, run: () => structural("column", "previous") },
|
||||
{ label: "Move column right", icon: "move-right", disabled: column === lastColumn, run: () => structural("column", "next") }, sep,
|
||||
{ label: tr("Column"), icon: "column", children: [
|
||||
{ label: tr("Add column to the left"), icon: "column-before", run: () => structural("column", "before") },
|
||||
{ label: tr("Add column to the right"), icon: "column-after", run: () => structural("column", "after") }, sep,
|
||||
{ label: tr("Move column left"), icon: "move-left", disabled: column === 0, run: () => structural("column", "previous") },
|
||||
{ label: tr("Move column right"), icon: "move-right", disabled: column === lastColumn, run: () => structural("column", "next") }, sep,
|
||||
...alignmentItems, sep,
|
||||
{ label: "Duplicate column", icon: "copy", run: () => structural("column", "duplicate") },
|
||||
{ label: "Delete column", icon: "trash", run: () => structural("column", "delete") },
|
||||
{ label: tr("Duplicate column"), icon: "copy", run: () => structural("column", "duplicate") },
|
||||
{ label: tr("Delete column"), icon: "trash", run: () => structural("column", "delete") },
|
||||
] }, sep,
|
||||
{ label: "Sort by column (A to Z)", icon: "sort-asc", disabled: lastRow < 2, run: () => { range ??= cellRange; apply(text => sortTableColumn(text, column)); } },
|
||||
{ label: "Sort by column (Z to A)", icon: "sort-desc", disabled: lastRow < 2, run: () => { range ??= cellRange; apply(text => sortTableColumn(text, column, true)); } },
|
||||
{ label: tr("Sort by column (A to Z)"), icon: "sort-asc", disabled: lastRow < 2, run: () => { range ??= cellRange; apply(text => sortTableColumn(text, column)); } },
|
||||
{ label: tr("Sort by column (Z to A)"), icon: "sort-desc", disabled: lastRow < 2, run: () => { range ??= cellRange; apply(text => sortTableColumn(text, column, true)); } },
|
||||
);
|
||||
menu = actionMenu(x, y, items, returnFocus);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { tr } from '../i18n/index.ts';
|
||||
import type { Editor } from "@tiptap/core";
|
||||
import type { MenuItem } from "../layout/menuTypes";
|
||||
|
||||
@@ -47,93 +48,93 @@ export async function pasteClipboard(editor: Editor): Promise<void> {
|
||||
export function writerContextItems(editor: Editor): MenuItem[] {
|
||||
const inTable = editor.isActive("table");
|
||||
return [
|
||||
{ kind: "action", label: "Cut", run: () => void cutSelection(editor) },
|
||||
{ kind: "action", label: "Copy", run: () => void copySelection(editor) },
|
||||
{ kind: "action", label: "Paste", run: () => void pasteClipboard(editor) },
|
||||
{ kind: "action", label: tr("Cut"), run: () => void cutSelection(editor) },
|
||||
{ kind: "action", label: tr("Copy"), run: () => void copySelection(editor) },
|
||||
{ kind: "action", label: tr("Paste"), run: () => void pasteClipboard(editor) },
|
||||
{ kind: "sep" },
|
||||
{
|
||||
kind: "group",
|
||||
label: "Style",
|
||||
label: tr("Style"),
|
||||
items: [
|
||||
{ kind: "action", label: "Heading 1", run: () => editor.chain().focus().toggleHeading({ level: 1 }).run() },
|
||||
{ kind: "action", label: "Heading 2", run: () => editor.chain().focus().toggleHeading({ level: 2 }).run() },
|
||||
{ kind: "action", label: "Heading 3", run: () => editor.chain().focus().toggleHeading({ level: 3 }).run() },
|
||||
{ kind: "action", label: "Heading 4", run: () => editor.chain().focus().toggleHeading({ level: 4 }).run() },
|
||||
{ kind: "action", label: "Heading 5", run: () => editor.chain().focus().toggleHeading({ level: 5 }).run() },
|
||||
{ kind: "action", label: "Heading 6", run: () => editor.chain().focus().toggleHeading({ level: 6 }).run() },
|
||||
{ kind: "action", label: "Body", run: () => editor.chain().focus().setParagraph().run() },
|
||||
{ kind: "action", label: "Quote", run: () => editor.chain().focus().toggleBlockquote().run() },
|
||||
{ kind: "action", label: tr("Heading {level}", { level: 1 }), run: () => editor.chain().focus().toggleHeading({ level: 1 }).run() },
|
||||
{ kind: "action", label: tr("Heading {level}", { level: 2 }), run: () => editor.chain().focus().toggleHeading({ level: 2 }).run() },
|
||||
{ kind: "action", label: tr("Heading {level}", { level: 3 }), run: () => editor.chain().focus().toggleHeading({ level: 3 }).run() },
|
||||
{ kind: "action", label: tr("Heading {level}", { level: 4 }), run: () => editor.chain().focus().toggleHeading({ level: 4 }).run() },
|
||||
{ kind: "action", label: tr("Heading {level}", { level: 5 }), run: () => editor.chain().focus().toggleHeading({ level: 5 }).run() },
|
||||
{ kind: "action", label: tr("Heading {level}", { level: 6 }), run: () => editor.chain().focus().toggleHeading({ level: 6 }).run() },
|
||||
{ kind: "action", label: tr("Body"), run: () => editor.chain().focus().setParagraph().run() },
|
||||
{ kind: "action", label: tr("Quote"), run: () => editor.chain().focus().toggleBlockquote().run() },
|
||||
{ kind: "sep" },
|
||||
{ kind: "action", label: "Bullet list", run: () => editor.chain().focus().toggleBulletList().run() },
|
||||
{ kind: "action", label: "Numbered list", run: () => editor.chain().focus().toggleOrderedList().run() },
|
||||
{ kind: "action", label: "Task list", run: () => editor.chain().focus().toggleTaskList().run() },
|
||||
{ kind: "action", label: tr("Bullet list"), run: () => editor.chain().focus().toggleBulletList().run() },
|
||||
{ kind: "action", label: tr("Numbered list"), run: () => editor.chain().focus().toggleOrderedList().run() },
|
||||
{ kind: "action", label: tr("Task list"), run: () => editor.chain().focus().toggleTaskList().run() },
|
||||
],
|
||||
},
|
||||
{
|
||||
kind: "group",
|
||||
label: "Format",
|
||||
label: tr("Format"),
|
||||
items: [
|
||||
{ kind: "action", label: "Bold", run: () => editor.chain().focus().toggleBold().run() },
|
||||
{ kind: "action", label: "Italic", run: () => editor.chain().focus().toggleItalic().run() },
|
||||
{ kind: "action", label: "Strikethrough", run: () => editor.chain().focus().toggleStrike().run() },
|
||||
{ kind: "action", label: "Highlight", run: () => editor.chain().focus().toggleHighlight().run() },
|
||||
{ kind: "action", label: "Code", run: () => editor.chain().focus().toggleCode().run() },
|
||||
{ kind: "action", label: "Math", run: () => editor.chain().focus().toggleMark("math").run() },
|
||||
{ kind: "action", label: "Comment", run: () => editor.chain().focus().toggleMark("comment").run() },
|
||||
{ kind: "action", label: tr("Bold"), run: () => editor.chain().focus().toggleBold().run() },
|
||||
{ kind: "action", label: tr("Italic"), run: () => editor.chain().focus().toggleItalic().run() },
|
||||
{ kind: "action", label: tr("Strikethrough"), run: () => editor.chain().focus().toggleStrike().run() },
|
||||
{ kind: "action", label: tr("Highlight"), run: () => editor.chain().focus().toggleHighlight().run() },
|
||||
{ kind: "action", label: tr("Code"), run: () => editor.chain().focus().toggleCode().run() },
|
||||
{ kind: "action", label: tr("Math"), run: () => editor.chain().focus().toggleMark("math").run() },
|
||||
{ kind: "action", label: tr("Comment"), run: () => editor.chain().focus().toggleMark("comment").run() },
|
||||
{ kind: "sep" },
|
||||
{ kind: "action", label: "Clear formatting", run: () => editor.chain().focus().unsetAllMarks().run() },
|
||||
{ kind: "action", label: tr("Clear formatting"), run: () => editor.chain().focus().unsetAllMarks().run() },
|
||||
],
|
||||
},
|
||||
{
|
||||
kind: "group",
|
||||
label: "Table",
|
||||
label: tr("Table"),
|
||||
items: [
|
||||
{
|
||||
kind: "action",
|
||||
label: "Insert table",
|
||||
label: tr("Insert table"),
|
||||
run: () => editor.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run(),
|
||||
},
|
||||
{ kind: "sep" },
|
||||
{
|
||||
kind: "action",
|
||||
label: "Add row above",
|
||||
label: tr("Add row above"),
|
||||
disabled: !inTable,
|
||||
run: () => editor.chain().focus().addRowBefore().run(),
|
||||
},
|
||||
{
|
||||
kind: "action",
|
||||
label: "Add row below",
|
||||
label: tr("Add row below"),
|
||||
disabled: !inTable,
|
||||
run: () => editor.chain().focus().addRowAfter().run(),
|
||||
},
|
||||
{
|
||||
kind: "action",
|
||||
label: "Delete row",
|
||||
label: tr("Delete row"),
|
||||
disabled: !inTable,
|
||||
run: () => editor.chain().focus().deleteRow().run(),
|
||||
},
|
||||
{ kind: "sep" },
|
||||
{
|
||||
kind: "action",
|
||||
label: "Add column left",
|
||||
label: tr("Add column left"),
|
||||
disabled: !inTable,
|
||||
run: () => editor.chain().focus().addColumnBefore().run(),
|
||||
},
|
||||
{
|
||||
kind: "action",
|
||||
label: "Add column right",
|
||||
label: tr("Add column right"),
|
||||
disabled: !inTable,
|
||||
run: () => editor.chain().focus().addColumnAfter().run(),
|
||||
},
|
||||
{
|
||||
kind: "action",
|
||||
label: "Delete column",
|
||||
label: tr("Delete column"),
|
||||
disabled: !inTable,
|
||||
run: () => editor.chain().focus().deleteColumn().run(),
|
||||
},
|
||||
{
|
||||
kind: "action",
|
||||
label: "Delete table",
|
||||
label: tr("Delete table"),
|
||||
disabled: !inTable,
|
||||
run: () => editor.chain().focus().deleteTable().run(),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user