CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 7s
CI & Build / integration (push) Successful in 17s
CI & Build / TypeScript typecheck (push) Successful in 34s
CI & Build / Python tests (push) Successful in 48s
CI & Build / Build & push image (push) Successful in 37s
#2533. theme.css claimed "removing this block is a rename sweep across the
components, tracked separately" — written in 67a529a, never filed, which made
the comment itself an instance of the survey's presence-without-reference
pattern. This is that sweep.
73 alias declarations deleted; 69 files rewritten; every --color-*-style name
now references its --fs-* token directly. Mechanical by construction: the map
IS the alias block, applied longest-name-first with a boundary guard so
--color-text never matched inside --color-text-muted. Zero survivors outside
theme.css, verified by grep rather than assumed.
One deliberate survivor: --color-shadow stays DECLARED, because it was never
an alias — it is a literal value the design system has no token for. Marked
in place as a recorded gap: promote it to an --fs-* token when a second app
needs it, don't copy the line.
Nothing is lost mode-wise: the aliases' resolve-at-use-time trick (which
absorbed 48 dark-mode overrides) lives one layer down in the --fs-* tokens'
own derivations, which is why the sweep is a pure rename. Both CSS checkers
green.
Why now rather than never: check_snippets_against_design_system reports every
--color-* reference as "unknown — renders as NOTHING", and nine recipe
snippets recorded from components.css carried the deprecated names, making
them prior art pointing the wrong way. With the sweep in, the checker's
report over re-recorded snippets should be EMPTY — the acceptance test that
proves the checker was right all along (#2517's correction).
Refs #2533
163 lines
4.7 KiB
Vue
163 lines
4.7 KiB
Vue
<script setup lang="ts">
|
|
import { watch, onBeforeUnmount } from "vue";
|
|
import { Editor, EditorContent } from "@tiptap/vue-3";
|
|
import StarterKit from "@tiptap/starter-kit";
|
|
import Link from "@tiptap/extension-link";
|
|
import { Placeholder } from "@tiptap/extensions";
|
|
import { marked } from "marked";
|
|
import DOMPurify from "dompurify";
|
|
import { serializeToMarkdown } from "@/utils/markdownSerializer";
|
|
import { TaskList, TaskItem } from "@tiptap/extension-list";
|
|
import { TagDecoration } from "@/extensions/TagDecoration";
|
|
import { WikilinkDecoration } from "@/extensions/WikilinkDecoration";
|
|
import { WikilinkSuggestion } from "@/extensions/WikilinkSuggestion";
|
|
import { SlashCommands } from "@/extensions/SlashCommands";
|
|
|
|
const props = withDefaults(
|
|
defineProps<{
|
|
modelValue: string;
|
|
placeholder?: string;
|
|
}>(),
|
|
{
|
|
placeholder: "",
|
|
}
|
|
);
|
|
|
|
const emit = defineEmits<{
|
|
"update:modelValue": [value: string];
|
|
selectionChange: [payload: { text: string; start: number; end: number }];
|
|
escape: [];
|
|
}>();
|
|
|
|
let updatingFromProp = false;
|
|
let lastEmittedMarkdown = props.modelValue;
|
|
|
|
function markdownToHtml(md: string): string {
|
|
const html = marked(md) as string;
|
|
return DOMPurify.sanitize(html);
|
|
}
|
|
|
|
let editor: Editor | null = null;
|
|
|
|
try {
|
|
editor = new Editor({
|
|
content: markdownToHtml(props.modelValue),
|
|
editable: true,
|
|
editorProps: {
|
|
handleKeyDown: (_view, event) => {
|
|
if (event.key === "Escape") {
|
|
editor?.commands.blur();
|
|
emit("escape");
|
|
return true;
|
|
}
|
|
return false;
|
|
},
|
|
handlePaste: (_view, event) => {
|
|
const text = event.clipboardData?.getData("text/plain");
|
|
if (!text || !editor) return false;
|
|
// If clipboard already has HTML (e.g. copying from a webpage), let Tiptap handle it
|
|
const html = event.clipboardData?.getData("text/html");
|
|
if (html) return false;
|
|
// Check if the pasted text looks like it contains markdown formatting
|
|
const hasMd = /(?:^#{1,6}\s|^\s*[-*+]\s|^\s*\d+\.\s|^\s*>|```|\*\*|__|~~|\[.+\]\(.+\))/m.test(text);
|
|
if (!hasMd) return false;
|
|
// Convert markdown to HTML and insert as formatted content
|
|
const converted = markdownToHtml(text);
|
|
editor.chain().focus().deleteSelection().insertContent(converted).run();
|
|
return true;
|
|
},
|
|
},
|
|
extensions: [
|
|
StarterKit.configure({
|
|
heading: { levels: [1, 2, 3, 4, 5, 6] },
|
|
link: false,
|
|
}),
|
|
Link.configure({
|
|
openOnClick: false,
|
|
autolink: true,
|
|
}),
|
|
Placeholder.configure({
|
|
placeholder: props.placeholder,
|
|
}),
|
|
TaskList,
|
|
TaskItem.configure({ nested: true }),
|
|
TagDecoration,
|
|
WikilinkDecoration,
|
|
WikilinkSuggestion,
|
|
SlashCommands,
|
|
],
|
|
onUpdate({ editor: ed }) {
|
|
if (updatingFromProp) return;
|
|
const md = serializeToMarkdown(ed.getJSON());
|
|
lastEmittedMarkdown = md;
|
|
emit("update:modelValue", md);
|
|
},
|
|
onSelectionUpdate({ editor: ed }) {
|
|
const { from, to } = ed.state.selection;
|
|
if (from === to) return;
|
|
const selectedText = ed.state.doc.textBetween(from, to, "\n");
|
|
if (!selectedText) return;
|
|
|
|
const md = lastEmittedMarkdown;
|
|
const fraction = from / (ed.state.doc.content.size || 1);
|
|
const estIdx = Math.floor(fraction * md.length);
|
|
|
|
let bestIdx = -1;
|
|
let bestDist = Infinity;
|
|
let searchFrom = 0;
|
|
while (true) {
|
|
const idx = md.indexOf(selectedText, searchFrom);
|
|
if (idx === -1) break;
|
|
const dist = Math.abs(idx - estIdx);
|
|
if (dist < bestDist) { bestDist = dist; bestIdx = idx; }
|
|
searchFrom = idx + 1;
|
|
}
|
|
if (bestIdx !== -1) {
|
|
emit("selectionChange", {
|
|
text: selectedText,
|
|
start: bestIdx,
|
|
end: bestIdx + selectedText.length,
|
|
});
|
|
}
|
|
},
|
|
});
|
|
} catch (e) {
|
|
console.error("Tiptap editor creation failed:", e);
|
|
}
|
|
|
|
onBeforeUnmount(() => {
|
|
editor?.destroy();
|
|
});
|
|
|
|
// Watch for external modelValue changes (e.g. AI assist accept)
|
|
watch(
|
|
() => props.modelValue,
|
|
(newVal) => {
|
|
if (!editor) return;
|
|
if (newVal === lastEmittedMarkdown) return;
|
|
|
|
updatingFromProp = true;
|
|
editor.commands.setContent(markdownToHtml(newVal));
|
|
lastEmittedMarkdown = newVal;
|
|
updatingFromProp = false;
|
|
}
|
|
);
|
|
|
|
defineExpose({ editor });
|
|
</script>
|
|
|
|
<template>
|
|
<div class="tiptap-wrapper tiptap-editor">
|
|
<EditorContent v-if="editor" :editor="editor" class="prose" />
|
|
<div v-else class="editor-error">Editor failed to load. Check console.</div>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.editor-error {
|
|
padding: 1rem;
|
|
color: var(--fs-error);
|
|
font-size: 0.9rem;
|
|
}
|
|
</style>
|