* Don't require auth for .ping * Finally introducing loggers * Remove file list caching from disk_space_primitives I don't think this is required anymore with the sync model * Simplification of space primitives and more tests * More reliable online status * Add .zed settings * Remove selfUpdate argument from `writeFile` no longer used - Add `sync` config schema and document sync options - Move sync config handling to client boot logic - Move BootConfig type to ui_types.ts - Remove sync env vars from server - Update documentation for sync and architecture * Improve sync logic and proxy routing for full sync state * Add BoxProxy for late-bound client and improve Lua boot - Add isMobile syscall for editor * Add concurrency to sync process and log indexing duration * Better service worker lifecycle management
79 lines
2.3 KiB
TypeScript
79 lines
2.3 KiB
TypeScript
import type { EditorState, Range } from "@codemirror/state";
|
|
import { syntaxTree } from "@codemirror/language";
|
|
import { Decoration } from "@codemirror/view";
|
|
import {
|
|
decoratorStateField,
|
|
invisibleDecoration,
|
|
isCursorInRange,
|
|
shouldRenderWidgets,
|
|
} from "./util.ts";
|
|
import type { Client } from "../client.ts";
|
|
import { LuaWidget } from "./lua_widget.ts";
|
|
import { inlineContentFromURL, parseTransclusion } from "../markdown/inline.ts";
|
|
|
|
export function inlineContentPlugin(client: Client) {
|
|
return decoratorStateField((state: EditorState) => {
|
|
const widgets: Range<Decoration>[] = [];
|
|
if (!shouldRenderWidgets(client)) {
|
|
// console.info("Not rendering widgets");
|
|
return Decoration.set([]);
|
|
}
|
|
|
|
syntaxTree(state).iterate({
|
|
enter: ({ type, from, to }) => {
|
|
if (type.name !== "Image") {
|
|
return;
|
|
}
|
|
|
|
const text = state.sliceDoc(from, to);
|
|
|
|
const transclusion = parseTransclusion(text);
|
|
if (!transclusion) {
|
|
return;
|
|
}
|
|
|
|
const renderingSyntax = client.ui.viewState.uiOptions
|
|
.markdownSyntaxRendering;
|
|
const cursorIsInRange = isCursorInRange(state, [from, to]);
|
|
if (!renderingSyntax && !cursorIsInRange) {
|
|
widgets.push(invisibleDecoration.range(from, to));
|
|
}
|
|
|
|
widgets.push(
|
|
Decoration.widget({
|
|
widget: new LuaWidget(
|
|
client,
|
|
`widget:${client.currentPath()}:${text}`,
|
|
text,
|
|
async () => {
|
|
const result = await inlineContentFromURL(
|
|
client,
|
|
transclusion.url,
|
|
transclusion.alias,
|
|
transclusion.dimension,
|
|
transclusion.linktype !== "wikilink",
|
|
);
|
|
const content = typeof result === "string"
|
|
? { markdown: result }
|
|
: { html: result };
|
|
|
|
return {
|
|
_isWidget: true,
|
|
display: "block",
|
|
cssClasses: ["sb-inline-content"],
|
|
...content,
|
|
};
|
|
},
|
|
true,
|
|
true,
|
|
),
|
|
block: true,
|
|
}).range(to + 1),
|
|
);
|
|
},
|
|
});
|
|
|
|
return Decoration.set(widgets, true);
|
|
});
|
|
}
|