Release RuneStone 0.1.3 and expand plugin plans

This commit is contained in:
Knotty Wyvern
2026-10-03 04:23:45 -07:00
parent 43106ed9c7
commit 0268c5c9f0
44 changed files with 247 additions and 53 deletions
+20 -5
View File
@@ -54,9 +54,17 @@ class Checkbox extends WidgetType {
}
class Preview extends WidgetType {
constructor(readonly html: string, readonly source: string, readonly actions: TableContextActions, readonly sourceVisible = false) { super(); }
constructor(readonly html: string, readonly source: string, readonly actions: TableContextActions, readonly sourceVisible = false, readonly height = { value: -1 }) { super(); }
get estimatedHeight() { return this.height.value; }
eq(other: Preview) { return other.html === this.html && other.source === this.source && other.sourceVisible === this.sourceVisible; }
updateDOM(dom: HTMLElement) { return tableEditors.get(dom)?.source === this.source; }
measure(dom: HTMLElement, view: EditorView) {
view.requestMeasure({ key: this.height, read: () => dom.offsetHeight, write: height => { this.height.value = height; } });
}
updateDOM(dom: HTMLElement, view: EditorView) {
if (tableEditors.get(dom)?.source !== this.source) return false;
this.measure(dom, view);
return true;
}
destroy(dom: HTMLElement) { tableEditors.get(dom)?.destroy(); imageCleanups.get(dom)?.(); }
toDOM(view: EditorView) {
const dom = document.createElement("div");
@@ -64,6 +72,7 @@ class Preview extends WidgetType {
dom.innerHTML = this.html;
tableControls(dom, view, this.source, this.actions);
imageCleanups.set(dom, imageControls(dom, {}, () => { if (dom.isConnected) view.requestMeasure(); }));
this.measure(dom, view);
dom.querySelectorAll("button.rs-fence-copy").forEach(button => button.remove());
dom.addEventListener("mousedown", event => {
if (event.target instanceof Element && event.target.closest(".writer-table, .table-footer")) return;
@@ -85,7 +94,7 @@ class Preview extends WidgetType {
}
export function liveMarkdown(urls: Map<string, string>, actions: TableContextActions = {}, images: ImageContext = {}) {
function build(state: EditorState): DecorationSet {
function build(state: EditorState, previous?: DecorationSet): DecorationSet {
const ranges: Range<Decoration>[] = [];
const active = state.selection.ranges.map(range => ({ from: state.doc.lineAt(range.from).from, to: state.doc.lineAt(range.to).to }));
const selected = (from: number, to: number) => active.some(range => range.from <= to && range.to >= from);
@@ -123,7 +132,13 @@ export function liveMarkdown(urls: Map<string, string>, actions: TableContextAct
continue;
}
hiddenBlocks.push({ from: section.start, to: end });
ranges.push(Decoration.replace({ widget: new Preview(section.html, source.slice(section.start, end), actions), block: true, atomic: true }).range(section.start, end));
// Keep the table height between edits and the next layout pass. A one-line
// estimate can move the scroll anchor below a tall table on a second update.
let height: { value: number } | undefined;
if (isTable) previous?.between(section.start, end, (from, to, decoration) => {
if (from === section.start && to === end && decoration.spec.widget instanceof Preview) height = decoration.spec.widget.height;
});
ranges.push(Decoration.replace({ widget: new Preview(section.html, source.slice(section.start, end), actions, false, height), block: true, atomic: true }).range(section.start, end));
}
const hidden = (from: number, to: number) => hiddenBlocks.some(block => block.from <= from && block.to >= to);
const replace = (from: number, to: number) => { if (to > from) ranges.push(Decoration.replace({ atomic: true }).range(from, to)); };
@@ -188,7 +203,7 @@ export function liveMarkdown(urls: Map<string, string>, actions: TableContextAct
return [imageSource, StateField.define<DecorationSet>({
create: build,
update(value, transaction) {
return transaction.docChanged || transaction.selection || transaction.effects.some(effect => effect.is(refreshImages) || effect.is(editImageSource)) ? build(transaction.state) : value;
return transaction.docChanged || transaction.selection || transaction.effects.some(effect => effect.is(refreshImages) || effect.is(editImageSource)) ? build(transaction.state, value.map(transaction.changes)) : value;
},
provide: field => [EditorView.decorations.from(field), EditorView.atomicRanges.of(view => view.state.field(field).update({
filter: (_from, _to, decoration) => decoration.spec.atomic === true,