Editor refactor: fix plug namespace
This commit is contained in:
parent
e92ed2c5be
commit
f3936f9b2f
@ -9,28 +9,28 @@ export type NamespaceOperation =
|
||||
| "getFileMeta"
|
||||
| "deleteFile";
|
||||
|
||||
export type PageNamespaceDef = {
|
||||
export type PlugNamespaceDef = {
|
||||
pattern: string;
|
||||
operation: NamespaceOperation;
|
||||
};
|
||||
|
||||
export type PageNamespaceHookT = {
|
||||
pageNamespace?: PageNamespaceDef;
|
||||
export type PlugNamespaceHookT = {
|
||||
pageNamespace?: PlugNamespaceDef;
|
||||
};
|
||||
|
||||
type SpaceFunction = {
|
||||
operation: NamespaceOperation;
|
||||
pattern: RegExp;
|
||||
plug: Plug<PageNamespaceHookT>;
|
||||
plug: Plug<PlugNamespaceHookT>;
|
||||
name: string;
|
||||
env?: string;
|
||||
};
|
||||
|
||||
export class PageNamespaceHook implements Hook<PageNamespaceHookT> {
|
||||
export class PlugNamespaceHook implements Hook<PlugNamespaceHookT> {
|
||||
spaceFunctions: SpaceFunction[] = [];
|
||||
constructor() {}
|
||||
|
||||
apply(system: System<PageNamespaceHookT>): void {
|
||||
apply(system: System<PlugNamespaceHookT>): void {
|
||||
system.on({
|
||||
plugLoaded: () => {
|
||||
this.updateCache(system);
|
||||
@ -41,7 +41,7 @@ export class PageNamespaceHook implements Hook<PageNamespaceHookT> {
|
||||
});
|
||||
}
|
||||
|
||||
updateCache(system: System<PageNamespaceHookT>) {
|
||||
updateCache(system: System<PlugNamespaceHookT>) {
|
||||
this.spaceFunctions = [];
|
||||
for (const plug of system.loadedPlugs.values()) {
|
||||
if (plug.manifest?.functions) {
|
||||
@ -64,7 +64,7 @@ export class PageNamespaceHook implements Hook<PageNamespaceHookT> {
|
||||
}
|
||||
}
|
||||
|
||||
validateManifest(manifest: Manifest<PageNamespaceHookT>): string[] {
|
||||
validateManifest(manifest: Manifest<PlugNamespaceHookT>): string[] {
|
||||
const errors: string[] = [];
|
||||
if (!manifest.functions) {
|
||||
return [];
|
@ -3,7 +3,7 @@ import { CronHookT } from "../plugos/hooks/cron.ts";
|
||||
import { EventHookT } from "../plugos/hooks/event.ts";
|
||||
import { CommandHookT } from "../web/hooks/command.ts";
|
||||
import { SlashCommandHookT } from "../web/hooks/slash_command.ts";
|
||||
import { PageNamespaceHookT } from "./hooks/page_namespace.ts";
|
||||
import { PlugNamespaceHookT } from "./hooks/plug_namespace.ts";
|
||||
import { CodeWidgetT } from "../web/hooks/code_widget.ts";
|
||||
|
||||
export type SilverBulletHooks =
|
||||
@ -12,7 +12,7 @@ export type SilverBulletHooks =
|
||||
& CronHookT
|
||||
& EventHookT
|
||||
& CodeWidgetT
|
||||
& PageNamespaceHookT;
|
||||
& PlugNamespaceHookT;
|
||||
|
||||
export type SyntaxExtensions = {
|
||||
syntax?: { [key: string]: NodeDef };
|
||||
|
@ -2,13 +2,13 @@ import { SpacePrimitives } from "../../common/spaces/space_primitives.ts";
|
||||
import { FileMeta } from "../../common/types.ts";
|
||||
import {
|
||||
NamespaceOperation,
|
||||
PageNamespaceHook,
|
||||
} from "../hooks/page_namespace.ts";
|
||||
PlugNamespaceHook,
|
||||
} from "../hooks/plug_namespace.ts";
|
||||
|
||||
export class PlugSpacePrimitives implements SpacePrimitives {
|
||||
constructor(
|
||||
private wrapped: SpacePrimitives,
|
||||
private hook: PageNamespaceHook,
|
||||
private hook: PlugNamespaceHook,
|
||||
private env?: string,
|
||||
) {}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { PageNamespaceHook } from "../common/hooks/page_namespace.ts";
|
||||
import { PlugNamespaceHook } from "../common/hooks/plug_namespace.ts";
|
||||
import { Manifest, SilverBulletHooks } from "../common/manifest.ts";
|
||||
import buildMarkdown from "../common/markdown_parser/parser.ts";
|
||||
import { CronHook } from "../plugos/hooks/cron.ts";
|
||||
@ -35,7 +35,7 @@ export class ClientSystem {
|
||||
system: System<SilverBulletHooks> = new System("client");
|
||||
commandHook: CommandHook;
|
||||
slashCommandHook: SlashCommandHook;
|
||||
namespaceHook: PageNamespaceHook;
|
||||
namespaceHook: PlugNamespaceHook;
|
||||
indexSyscalls: SysCallMapping;
|
||||
codeWidgetHook: CodeWidgetHook;
|
||||
plugsUpdated = false;
|
||||
@ -47,15 +47,11 @@ export class ClientSystem {
|
||||
private dbPrefix: string,
|
||||
private eventHook: EventHook,
|
||||
) {
|
||||
// Attach the page namespace hook
|
||||
const namespaceHook = new PageNamespaceHook();
|
||||
this.system.addHook(namespaceHook);
|
||||
|
||||
this.system.addHook(this.eventHook);
|
||||
|
||||
// Attach the page namespace hook
|
||||
this.namespaceHook = new PageNamespaceHook();
|
||||
this.system.addHook(namespaceHook);
|
||||
// Plug page namespace hook
|
||||
this.namespaceHook = new PlugNamespaceHook();
|
||||
this.system.addHook(this.namespaceHook);
|
||||
|
||||
// Cron hook
|
||||
const cronHook = new CronHook(this.system);
|
||||
|
@ -2,7 +2,6 @@
|
||||
import {
|
||||
CompletionContext,
|
||||
CompletionResult,
|
||||
EditorSelection,
|
||||
EditorView,
|
||||
gitIgnoreCompiler,
|
||||
runScopeHandlers,
|
||||
@ -10,32 +9,12 @@ import {
|
||||
} from "../common/deps.ts";
|
||||
import { Space } from "./space.ts";
|
||||
import { FilterOption, PageMeta } from "./types.ts";
|
||||
import { isMacLike, parseYamlSettings, safeRun } from "../common/util.ts";
|
||||
import { parseYamlSettings } from "../common/util.ts";
|
||||
import { EventHook } from "../plugos/hooks/event.ts";
|
||||
import { Confirm, Prompt } from "./components/basic_modals.tsx";
|
||||
import { CommandPalette } from "./components/command_palette.tsx";
|
||||
import { FilterList } from "./components/filter.tsx";
|
||||
import { PageNavigator } from "./components/page_navigator.tsx";
|
||||
import { Panel } from "./components/panel.tsx";
|
||||
import { TopBar } from "./components/top_bar.tsx";
|
||||
import {
|
||||
BookIcon,
|
||||
HomeIcon,
|
||||
preactRender,
|
||||
TerminalIcon,
|
||||
useEffect,
|
||||
useReducer,
|
||||
} from "./deps.ts";
|
||||
import { AppCommand } from "./hooks/command.ts";
|
||||
import { PathPageNavigator } from "./navigator.ts";
|
||||
import reducer from "./reducer.ts";
|
||||
|
||||
import {
|
||||
Action,
|
||||
AppViewState,
|
||||
BuiltinSettings,
|
||||
initialViewState,
|
||||
} from "./types.ts";
|
||||
import { AppViewState, BuiltinSettings } from "./types.ts";
|
||||
|
||||
import type { AppEvent, CompleteEvent } from "../plug-api/app_event.ts";
|
||||
import { throttle } from "../common/async_util.ts";
|
||||
@ -194,37 +173,6 @@ export class Editor {
|
||||
});
|
||||
|
||||
this.openPages = new OpenPages(this.editorView);
|
||||
|
||||
// Make keyboard shortcuts work even when the editor is in read only mode or not focused
|
||||
globalThis.addEventListener("keydown", (ev) => {
|
||||
if (!this.editorView?.hasFocus) {
|
||||
if ((ev.target as any).closest(".cm-editor")) {
|
||||
// In some cm element, let's back out
|
||||
return;
|
||||
}
|
||||
if (runScopeHandlers(this.editorView!, ev, "editor")) {
|
||||
ev.preventDefault();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
globalThis.addEventListener("touchstart", (ev) => {
|
||||
// Launch the page picker on a two-finger tap
|
||||
if (ev.touches.length === 2) {
|
||||
ev.stopPropagation();
|
||||
ev.preventDefault();
|
||||
this.ui.viewDispatch({ type: "start-navigate" });
|
||||
}
|
||||
// Launch the command palette using a three-finger tap
|
||||
if (ev.touches.length === 3) {
|
||||
ev.stopPropagation();
|
||||
ev.preventDefault();
|
||||
this.ui.viewDispatch({
|
||||
type: "show-palette",
|
||||
context: this.getContext(),
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get currentPage(): string | undefined {
|
||||
|
@ -10,6 +10,7 @@ import {
|
||||
BookIcon,
|
||||
HomeIcon,
|
||||
preactRender,
|
||||
runScopeHandlers,
|
||||
TerminalIcon,
|
||||
useEffect,
|
||||
useReducer,
|
||||
@ -23,6 +24,36 @@ export class MainUI {
|
||||
viewDispatch: (action: Action) => void = () => {};
|
||||
|
||||
constructor(private editor: Editor) {
|
||||
// Make keyboard shortcuts work even when the editor is in read only mode or not focused
|
||||
globalThis.addEventListener("keydown", (ev) => {
|
||||
if (!editor.editorView?.hasFocus) {
|
||||
if ((ev.target as any).closest(".cm-editor")) {
|
||||
// In some cm element, let's back out
|
||||
return;
|
||||
}
|
||||
if (runScopeHandlers(editor.editorView!, ev, "editor")) {
|
||||
ev.preventDefault();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
globalThis.addEventListener("touchstart", (ev) => {
|
||||
// Launch the page picker on a two-finger tap
|
||||
if (ev.touches.length === 2) {
|
||||
ev.stopPropagation();
|
||||
ev.preventDefault();
|
||||
this.viewDispatch({ type: "start-navigate" });
|
||||
}
|
||||
// Launch the command palette using a three-finger tap
|
||||
if (ev.touches.length === 3) {
|
||||
ev.stopPropagation();
|
||||
ev.preventDefault();
|
||||
this.viewDispatch({
|
||||
type: "show-palette",
|
||||
context: editor.getContext(),
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ViewComponent() {
|
||||
|
Loading…
Reference in New Issue
Block a user