diff --git a/Packages/editor/src/DocwellEditor.vue b/Packages/editor/src/DocwellEditor.vue index 45614fa..a19806a 100644 --- a/Packages/editor/src/DocwellEditor.vue +++ b/Packages/editor/src/DocwellEditor.vue @@ -8,6 +8,7 @@ import { DwButton, DwIcon, type IconName } from "@docwell/ui"; import { computed, nextTick, onBeforeUnmount, ref, watch } from "vue"; import { aiActions, type AiAction, type AiHost } from "./ai"; import { copyBlockLink } from "./blocklinks"; +import { currentConversion, turnIntoActions, turnIntoTarget, type BlockAction } from "./blockmenu"; import { palette, type PaletteColor } from "./colors"; import { docwellExtensions, type CollabUser } from "./extensions"; import { findKey } from "./find"; @@ -174,8 +175,23 @@ onBeforeUnmount(() => editor.value?.destroy()); // The selection toolbar: formatting for editors, Comment for anyone allowed. type Tool = { id: string; icon: IconName; label: string; active: () => boolean; run: () => void }; /** The colour or alignment choices open under the toolbar, if any. */ -const panel = ref<"color" | "align" | "ai" | null>(null); -const togglePanel = (p: "color" | "align" | "ai") => (panel.value = panel.value === p ? null : p); +const panel = ref<"turn" | "color" | "align" | "ai" | null>(null); +const togglePanel = (p: "turn" | "color" | "align" | "ai") => (panel.value = panel.value === p ? null : p); + +/** "Turn into" for the block the selection is in: what it is now and what it can become. Null where it has no say. */ +function turnInto(e: Editor): { current: string | null; label: string; actions: BlockAction[] } | null { + const pos = turnIntoTarget(e); + if (pos < 0) return null; + const actions = turnIntoActions(e, pos, labels.value); + if (!actions.length) return null; + const current = currentConversion(e, pos); + const label = (current && labels.value.slash[current]?.label) || labels.value.blockMenu.turnInto; + return { current, label, actions }; +} +function turn(a: BlockAction) { + a.run?.(); + panel.value = null; +} const alignment = (e: Editor) => String(e.getAttributes("paragraph").textAlign ?? e.getAttributes("heading").textAlign ?? "left"); @@ -648,6 +664,22 @@ defineExpose({ editor, openFind }); >
+