import { ChangeSpec, Decoration, DecorationSet, EditorState, EditorView, foldedRanges, NodeType, SyntaxNodeRef, syntaxTree, ViewPlugin, ViewUpdate, WidgetType, } from "./deps.ts"; function getLinkAnchor(view: EditorView) { const widgets: any[] = []; for (const { from, to } of view.visibleRanges) { syntaxTree(view.state).iterate({ from, to, enter: ({ type, from, to, node }) => { if (type.name !== "URL") return; const parent = node.parent; const blackListedParents = ["Image"]; if (parent && !blackListedParents.includes(parent.name)) { const marks = parent.getChildren("LinkMark"); const ranges = view.state.selection.ranges; const cursorOverlaps = ranges.some(({ from, to }) => checkRangeOverlap([from, to], [parent.from, parent.to]) ); if (!cursorOverlaps) { widgets.push( ...marks.map(({ from, to }) => invisibleDecoration.range(from, to) ), invisibleDecoration.range(from, to), ); } } }, }); } return Decoration.set(widgets, true); } export const goToLinkPlugin = ViewPlugin.fromClass( class { decorations: DecorationSet = Decoration.none; constructor(view: EditorView) { this.decorations = getLinkAnchor(view); } update(update: ViewUpdate) { if ( update.docChanged || update.viewportChanged || update.selectionSet ) { this.decorations = getLinkAnchor(update.view); } } }, { decorations: (v) => v.decorations }, ); class StartDirectiveWidget extends WidgetType { constructor() { super(); } toDOM(): HTMLElement { const queryEl = document.createElement("div"); queryEl.textContent = "start"; queryEl.className = "sb-directive-start"; console.log("Got dom", queryEl); return queryEl; } } function getDirectives(view: EditorView) { const widgets: any[] = []; for (const { from, to } of view.visibleRanges) { syntaxTree(view.state).iterate({ from, to, enter: ({ type, from, to }) => { if (type.name !== "CommentBlock") { return; } const text = view.state.sliceDoc(from, to); if (/