Editor refactor: fix plug namespace
This commit is contained in:
parent
e92ed2c5be
commit
f3936f9b2f
@ -9,28 +9,28 @@ export type NamespaceOperation =
|
|||||||
| "getFileMeta"
|
| "getFileMeta"
|
||||||
| "deleteFile";
|
| "deleteFile";
|
||||||
|
|
||||||
export type PageNamespaceDef = {
|
export type PlugNamespaceDef = {
|
||||||
pattern: string;
|
pattern: string;
|
||||||
operation: NamespaceOperation;
|
operation: NamespaceOperation;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PageNamespaceHookT = {
|
export type PlugNamespaceHookT = {
|
||||||
pageNamespace?: PageNamespaceDef;
|
pageNamespace?: PlugNamespaceDef;
|
||||||
};
|
};
|
||||||
|
|
||||||
type SpaceFunction = {
|
type SpaceFunction = {
|
||||||
operation: NamespaceOperation;
|
operation: NamespaceOperation;
|
||||||
pattern: RegExp;
|
pattern: RegExp;
|
||||||
plug: Plug<PageNamespaceHookT>;
|
plug: Plug<PlugNamespaceHookT>;
|
||||||
name: string;
|
name: string;
|
||||||
env?: string;
|
env?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class PageNamespaceHook implements Hook<PageNamespaceHookT> {
|
export class PlugNamespaceHook implements Hook<PlugNamespaceHookT> {
|
||||||
spaceFunctions: SpaceFunction[] = [];
|
spaceFunctions: SpaceFunction[] = [];
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
apply(system: System<PageNamespaceHookT>): void {
|
apply(system: System<PlugNamespaceHookT>): void {
|
||||||
system.on({
|
system.on({
|
||||||
plugLoaded: () => {
|
plugLoaded: () => {
|
||||||
this.updateCache(system);
|
this.updateCache(system);
|
||||||
@ -41,7 +41,7 @@ export class PageNamespaceHook implements Hook<PageNamespaceHookT> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCache(system: System<PageNamespaceHookT>) {
|
updateCache(system: System<PlugNamespaceHookT>) {
|
||||||
this.spaceFunctions = [];
|
this.spaceFunctions = [];
|
||||||
for (const plug of system.loadedPlugs.values()) {
|
for (const plug of system.loadedPlugs.values()) {
|
||||||
if (plug.manifest?.functions) {
|
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[] = [];
|
const errors: string[] = [];
|
||||||
if (!manifest.functions) {
|
if (!manifest.functions) {
|
||||||
return [];
|
return [];
|
@ -3,7 +3,7 @@ import { CronHookT } from "../plugos/hooks/cron.ts";
|
|||||||
import { EventHookT } from "../plugos/hooks/event.ts";
|
import { EventHookT } from "../plugos/hooks/event.ts";
|
||||||
import { CommandHookT } from "../web/hooks/command.ts";
|
import { CommandHookT } from "../web/hooks/command.ts";
|
||||||
import { SlashCommandHookT } from "../web/hooks/slash_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";
|
import { CodeWidgetT } from "../web/hooks/code_widget.ts";
|
||||||
|
|
||||||
export type SilverBulletHooks =
|
export type SilverBulletHooks =
|
||||||
@ -12,7 +12,7 @@ export type SilverBulletHooks =
|
|||||||
& CronHookT
|
& CronHookT
|
||||||
& EventHookT
|
& EventHookT
|
||||||
& CodeWidgetT
|
& CodeWidgetT
|
||||||
& PageNamespaceHookT;
|
& PlugNamespaceHookT;
|
||||||
|
|
||||||
export type SyntaxExtensions = {
|
export type SyntaxExtensions = {
|
||||||
syntax?: { [key: string]: NodeDef };
|
syntax?: { [key: string]: NodeDef };
|
||||||
|
@ -2,13 +2,13 @@ import { SpacePrimitives } from "../../common/spaces/space_primitives.ts";
|
|||||||
import { FileMeta } from "../../common/types.ts";
|
import { FileMeta } from "../../common/types.ts";
|
||||||
import {
|
import {
|
||||||
NamespaceOperation,
|
NamespaceOperation,
|
||||||
PageNamespaceHook,
|
PlugNamespaceHook,
|
||||||
} from "../hooks/page_namespace.ts";
|
} from "../hooks/plug_namespace.ts";
|
||||||
|
|
||||||
export class PlugSpacePrimitives implements SpacePrimitives {
|
export class PlugSpacePrimitives implements SpacePrimitives {
|
||||||
constructor(
|
constructor(
|
||||||
private wrapped: SpacePrimitives,
|
private wrapped: SpacePrimitives,
|
||||||
private hook: PageNamespaceHook,
|
private hook: PlugNamespaceHook,
|
||||||
private env?: string,
|
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 { Manifest, SilverBulletHooks } from "../common/manifest.ts";
|
||||||
import buildMarkdown from "../common/markdown_parser/parser.ts";
|
import buildMarkdown from "../common/markdown_parser/parser.ts";
|
||||||
import { CronHook } from "../plugos/hooks/cron.ts";
|
import { CronHook } from "../plugos/hooks/cron.ts";
|
||||||
@ -35,7 +35,7 @@ export class ClientSystem {
|
|||||||
system: System<SilverBulletHooks> = new System("client");
|
system: System<SilverBulletHooks> = new System("client");
|
||||||
commandHook: CommandHook;
|
commandHook: CommandHook;
|
||||||
slashCommandHook: SlashCommandHook;
|
slashCommandHook: SlashCommandHook;
|
||||||
namespaceHook: PageNamespaceHook;
|
namespaceHook: PlugNamespaceHook;
|
||||||
indexSyscalls: SysCallMapping;
|
indexSyscalls: SysCallMapping;
|
||||||
codeWidgetHook: CodeWidgetHook;
|
codeWidgetHook: CodeWidgetHook;
|
||||||
plugsUpdated = false;
|
plugsUpdated = false;
|
||||||
@ -47,15 +47,11 @@ export class ClientSystem {
|
|||||||
private dbPrefix: string,
|
private dbPrefix: string,
|
||||||
private eventHook: EventHook,
|
private eventHook: EventHook,
|
||||||
) {
|
) {
|
||||||
// Attach the page namespace hook
|
|
||||||
const namespaceHook = new PageNamespaceHook();
|
|
||||||
this.system.addHook(namespaceHook);
|
|
||||||
|
|
||||||
this.system.addHook(this.eventHook);
|
this.system.addHook(this.eventHook);
|
||||||
|
|
||||||
// Attach the page namespace hook
|
// Plug page namespace hook
|
||||||
this.namespaceHook = new PageNamespaceHook();
|
this.namespaceHook = new PlugNamespaceHook();
|
||||||
this.system.addHook(namespaceHook);
|
this.system.addHook(this.namespaceHook);
|
||||||
|
|
||||||
// Cron hook
|
// Cron hook
|
||||||
const cronHook = new CronHook(this.system);
|
const cronHook = new CronHook(this.system);
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
import {
|
import {
|
||||||
CompletionContext,
|
CompletionContext,
|
||||||
CompletionResult,
|
CompletionResult,
|
||||||
EditorSelection,
|
|
||||||
EditorView,
|
EditorView,
|
||||||
gitIgnoreCompiler,
|
gitIgnoreCompiler,
|
||||||
runScopeHandlers,
|
runScopeHandlers,
|
||||||
@ -10,32 +9,12 @@ import {
|
|||||||
} from "../common/deps.ts";
|
} from "../common/deps.ts";
|
||||||
import { Space } from "./space.ts";
|
import { Space } from "./space.ts";
|
||||||
import { FilterOption, PageMeta } from "./types.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 { 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 { AppCommand } from "./hooks/command.ts";
|
||||||
import { PathPageNavigator } from "./navigator.ts";
|
import { PathPageNavigator } from "./navigator.ts";
|
||||||
import reducer from "./reducer.ts";
|
|
||||||
|
|
||||||
import {
|
import { AppViewState, BuiltinSettings } from "./types.ts";
|
||||||
Action,
|
|
||||||
AppViewState,
|
|
||||||
BuiltinSettings,
|
|
||||||
initialViewState,
|
|
||||||
} from "./types.ts";
|
|
||||||
|
|
||||||
import type { AppEvent, CompleteEvent } from "../plug-api/app_event.ts";
|
import type { AppEvent, CompleteEvent } from "../plug-api/app_event.ts";
|
||||||
import { throttle } from "../common/async_util.ts";
|
import { throttle } from "../common/async_util.ts";
|
||||||
@ -194,37 +173,6 @@ export class Editor {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.openPages = new OpenPages(this.editorView);
|
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 {
|
get currentPage(): string | undefined {
|
||||||
|
@ -10,6 +10,7 @@ import {
|
|||||||
BookIcon,
|
BookIcon,
|
||||||
HomeIcon,
|
HomeIcon,
|
||||||
preactRender,
|
preactRender,
|
||||||
|
runScopeHandlers,
|
||||||
TerminalIcon,
|
TerminalIcon,
|
||||||
useEffect,
|
useEffect,
|
||||||
useReducer,
|
useReducer,
|
||||||
@ -23,6 +24,36 @@ export class MainUI {
|
|||||||
viewDispatch: (action: Action) => void = () => {};
|
viewDispatch: (action: Action) => void = () => {};
|
||||||
|
|
||||||
constructor(private editor: Editor) {
|
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() {
|
ViewComponent() {
|
||||||
|
Loading…
Reference in New Issue
Block a user