From 3e14bff1e96128e9f862899e0768d46bca904246 Mon Sep 17 00:00:00 2001 From: hypercross Date: Sun, 1 Mar 2026 11:52:09 +0800 Subject: [PATCH] feat: command template csv --- src/components/md-commander/index.tsx | 14 ++++++++++---- src/components/utils/path.ts | 11 +++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/components/md-commander/index.tsx b/src/components/md-commander/index.tsx index b2f7855..41285ba 100644 --- a/src/components/md-commander/index.tsx +++ b/src/components/md-commander/index.tsx @@ -1,19 +1,25 @@ import { customElement, noShadowDOM } from "solid-element"; -import { onMount, onCleanup, Show } from "solid-js"; +import { onMount, onCleanup, Show, createEffect } from "solid-js"; import { useCommander } from "./hooks"; import { CommanderInput } from "./CommanderInput"; import { CommanderEntries } from "./CommanderEntries"; import { TrackerView } from "./TrackerView"; import { TabBar } from "./TabBar"; -import type { MdCommanderProps, TrackerAttribute } from "./types"; +import type { MdCommanderProps } from "./types"; +import {loadElementSrc, resolvePath} from "../utils/path"; +import {loadCommandTemplates} from "./utils/commandTemplates"; customElement( "md-commander", - { placeholder: "", class: "", height: "" }, + { placeholder: "", class: "", height: "", commandTemplates: "" }, (props, { element }) => { noShadowDOM(); - + const {articlePath, rawSrc} = loadElementSrc(element as any); const commander = useCommander(props.commands); + createEffect(async () => { + if(!rawSrc) return; + await loadCommandTemplates(commander.commands, resolvePath(articlePath, rawSrc)); + }); const handleKeyDown = (e: KeyboardEvent) => { if (commander.showCompletions() && commander.completions().length > 0) { diff --git a/src/components/utils/path.ts b/src/components/utils/path.ts index e1c78d9..1a887a7 100644 --- a/src/components/utils/path.ts +++ b/src/components/utils/path.ts @@ -37,3 +37,14 @@ export function resolvePath(base: string, relative: string): string { return '/' + baseParts.join('/'); } + + +export function loadElementSrc(element?: { textContent: string, closest: (arg0: string) => HTMLElement }){ + const rawSrc = element?.textContent; + if(element) element.textContent = ""; + + const articleEl = element?.closest('article[data-src]'); + const articlePath = articleEl?.getAttribute('data-src') || ''; + + return { articlePath, rawSrc }; +} \ No newline at end of file