@hienlh/ppm 0.9.83 → 0.9.85
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/260413-1354-new-file-editor-tab/reports/code-reviewer-260413-1420-new-file-tab-review.md +210 -0
- package/CHANGELOG.md +20 -0
- package/bun.lock +259 -9
- package/dist/web/assets/{_basePickBy-5PGDJbfF.js → _basePickBy-D-bUmjma.js} +1 -1
- package/dist/web/assets/{_baseUniq-BT4Ow4Kk.js → _baseUniq-BnXXIfRB.js} +1 -1
- package/dist/web/assets/ai-settings-section-D6d-RmR6.js +1 -0
- package/dist/web/assets/{api-settings-Bn-bIxD1.js → api-settings-Qi2xRiHa.js} +1 -1
- package/dist/web/assets/{arc-BAOivWpI.js → arc-DB9vXGzd.js} +1 -1
- package/dist/web/assets/architecture-PBZL5I3N-DpVzOETR.js +1 -0
- package/dist/web/assets/{architectureDiagram-2XIMDMQ5-Z-4eN4za.js → architectureDiagram-2XIMDMQ5-BBV25747.js} +1 -1
- package/dist/web/assets/{blockDiagram-WCTKOSBZ-BCLqzhuZ.js → blockDiagram-WCTKOSBZ-BOTnY2Lq.js} +1 -1
- package/dist/web/assets/{c4Diagram-IC4MRINW-0Vp0Jeas.js → c4Diagram-IC4MRINW-D7QAUdHD.js} +1 -1
- package/dist/web/assets/channel-Cgy1thYT.js +1 -0
- package/dist/web/assets/chat-tab-DXBb9Y3U.js +10 -0
- package/dist/web/assets/check-ePA3ZvK4.js +1 -0
- package/dist/web/assets/chevron-down-EQA06nR-.js +1 -0
- package/dist/web/assets/{chunk-4BX2VUAB-D4tOov49.js → chunk-4BX2VUAB-BnOVw77D.js} +1 -1
- package/dist/web/assets/{chunk-55IACEB6-DJ6BynZ4.js → chunk-55IACEB6-BftA8DxR.js} +1 -1
- package/dist/web/assets/{chunk-7E7YKBS2-CiyUJxNI.js → chunk-7E7YKBS2-B0vnP8v3.js} +1 -1
- package/dist/web/assets/{chunk-7R4GIKGN-Dv-4cAYn.js → chunk-7R4GIKGN-Czlaj26D.js} +2 -2
- package/dist/web/assets/{chunk-C72U2L5F-D21mS_6G.js → chunk-C72U2L5F-DpEbDtMo.js} +1 -1
- package/dist/web/assets/{chunk-EGIJ26TM-DzqmU2Z7.js → chunk-EGIJ26TM-BWXe6lkx.js} +1 -1
- package/dist/web/assets/{chunk-FMBD7UC4-DXncblvW.js → chunk-FMBD7UC4-DspqhPfk.js} +1 -1
- package/dist/web/assets/{chunk-GEFDOKGD-D-pKjlVd.js → chunk-GEFDOKGD-D6HHRbYk.js} +1 -1
- package/dist/web/assets/chunk-GLR3WWYH-CxUl1sdz.js +2 -0
- package/dist/web/assets/chunk-HHEYEP7N-DN7ebS2Y.js +1 -0
- package/dist/web/assets/{chunk-JSJVCQXG-99JzIdPr.js → chunk-JSJVCQXG-BC8wnMwf.js} +1 -1
- package/dist/web/assets/{chunk-KX2RTZJC-CRq1OBZv.js → chunk-KX2RTZJC-D3VDtyvX.js} +1 -1
- package/dist/web/assets/{chunk-KYZI473N-Bb0MCaIO.js → chunk-KYZI473N-Z-NBw_HS.js} +1 -1
- package/dist/web/assets/{chunk-L3YUKLVL-C7qGJrfV.js → chunk-L3YUKLVL--RGkEh__.js} +1 -1
- package/dist/web/assets/{chunk-MX3YWQON-BpS_PtKp.js → chunk-MX3YWQON-2B76t_Kx.js} +1 -1
- package/dist/web/assets/{chunk-NQ4KR5QH-z_blpjxi.js → chunk-NQ4KR5QH-BekY3tEi.js} +1 -1
- package/dist/web/assets/{chunk-O4XLMI2P-nDhi_cVu.js → chunk-O4XLMI2P-2CJLfx_1.js} +1 -1
- package/dist/web/assets/{chunk-OZEHJAEY-BXhYx3nO.js → chunk-OZEHJAEY-sug_L09P.js} +1 -1
- package/dist/web/assets/{chunk-PQ6SQG4A-TF58UVMU.js → chunk-PQ6SQG4A-_fwPRLQy.js} +1 -1
- package/dist/web/assets/{chunk-PU5JKC2W-ek7k4QVB.js → chunk-PU5JKC2W-BUaTFJVQ.js} +1 -1
- package/dist/web/assets/chunk-QZHKN3VN-C4La7oLj.js +1 -0
- package/dist/web/assets/{chunk-R5LLSJPH-CFwSJijQ.js → chunk-R5LLSJPH-C37xW0vj.js} +1 -1
- package/dist/web/assets/{chunk-WL4C6EOR-ByUrSRin.js → chunk-WL4C6EOR-CCkt_MT6.js} +1 -1
- package/dist/web/assets/{chunk-XIRO2GV7-Djlmrely.js → chunk-XIRO2GV7-Dz2LBq7Y.js} +1 -1
- package/dist/web/assets/{chunk-XPW4576I-BPQQBakK.js → chunk-XPW4576I-DenTbBuj.js} +1 -1
- package/dist/web/assets/{chunk-XZSTWKYB-DxAOx4hG.js → chunk-XZSTWKYB-Dbp1nUSQ.js} +1 -1
- package/dist/web/assets/{chunk-YBOYWFTD-rQG3QH5s.js → chunk-YBOYWFTD-3OTKowjE.js} +1 -1
- package/dist/web/assets/classDiagram-VBA2DB6C-C3IyfqG-.js +1 -0
- package/dist/web/assets/classDiagram-v2-RAHNMMFH-Dcvhz2pb.js +1 -0
- package/dist/web/assets/clone--C7Tby8z.js +1 -0
- package/dist/web/assets/code-editor-Cr7JrBKC.js +8 -0
- package/dist/web/assets/{cose-bilkent-S5V4N54A-B_AWZsOP.js → cose-bilkent-S5V4N54A-MbmGZnt0.js} +1 -1
- package/dist/web/assets/{csv-preview-D2pJJj3K.js → csv-preview-uZ_7b8I7.js} +1 -1
- package/dist/web/assets/{dagre-DHq9bhnd.js → dagre-CPhI6v-K.js} +1 -1
- package/dist/web/assets/{dagre-KLK3FWXG-BdJr7Byp.js → dagre-KLK3FWXG-CmSE-oNj.js} +1 -1
- package/dist/web/assets/database-D1ToEV9d.js +1 -0
- package/dist/web/assets/{database-viewer-0P_zRC9w.js → database-viewer-5xljX0JI.js} +2 -2
- package/dist/web/assets/{diagram-E7M64L7V-_db4pBVA.js → diagram-E7M64L7V-B5XG3ZT7.js} +1 -1
- package/dist/web/assets/{diagram-IFDJBPK2-xKoeuiJx.js → diagram-IFDJBPK2-BsP248aX.js} +1 -1
- package/dist/web/assets/{diagram-P4PSJMXO-C8tjJsev.js → diagram-P4PSJMXO-Cna3408N.js} +1 -1
- package/dist/web/assets/diff-viewer-BBr6e_gb.js +4 -0
- package/dist/web/assets/dist-KUoHa6tg.js +1 -0
- package/dist/web/assets/{erDiagram-INFDFZHY-BSh2z9Df.js → erDiagram-INFDFZHY-B7SgktiR.js} +1 -1
- package/dist/web/assets/{extension-webview-Cx0GpRyC.js → extension-webview-B0klBip8.js} +1 -1
- package/dist/web/assets/eye-CNcBU6Tx.js +1 -0
- package/dist/web/assets/{flowDiagram-PKNHOUZH-oYaovqyp.js → flowDiagram-PKNHOUZH-FOYZZ1OB.js} +1 -1
- package/dist/web/assets/{ganttDiagram-A5KZAMGK-DmL26q2P.js → ganttDiagram-A5KZAMGK-CnHVYh9v.js} +1 -1
- package/dist/web/assets/git-graph-CDiwGa0g.js +1 -0
- package/dist/web/assets/gitGraph-HDMCJU4V-DcPyMEIJ.js +1 -0
- package/dist/web/assets/{gitGraphDiagram-K3NZZRJ6-CMoukSrY.js → gitGraphDiagram-K3NZZRJ6-0G9XxZay.js} +1 -1
- package/dist/web/assets/{graphlib-BcsNnGcW.js → graphlib-CNiBwlg_.js} +1 -1
- package/dist/web/assets/index-CkaCzNgO.css +2 -0
- package/dist/web/assets/index-Ic5uTu20.js +26 -0
- package/dist/web/assets/info-3K5VOQVL-Dw4O15cw.js +1 -0
- package/dist/web/assets/infoDiagram-LFFYTUFH-DFhmsucr.js +2 -0
- package/dist/web/assets/input-CcbTF6ih.js +45 -0
- package/dist/web/assets/{isEmpty-bnrF3Qbc.js → isEmpty-CcCb5n2-.js} +1 -1
- package/dist/web/assets/{ishikawaDiagram-PHBUUO56-D05_LyL7.js → ishikawaDiagram-PHBUUO56-D4QCzh5J.js} +1 -1
- package/dist/web/assets/{journeyDiagram-4ABVD52K-B_L20qMe.js → journeyDiagram-4ABVD52K-CnHYNfKW.js} +1 -1
- package/dist/web/assets/{kanban-definition-K7BYSVSG-CZ535BbZ.js → kanban-definition-K7BYSVSG-Bh_g3EVu.js} +1 -1
- package/dist/web/assets/keybindings-store-CxE6BlG2.js +1 -0
- package/dist/web/assets/{line-CVvo3dRu.js → line-6d3eBADm.js} +1 -1
- package/dist/web/assets/{linear-DP4mkX3m.js → linear-cA_2lQy7.js} +1 -1
- package/dist/web/assets/markdown-renderer-CZ07F7T6.js +306 -0
- package/dist/web/assets/{mermaid-parser.core-C7UwoIh6.js → mermaid-parser.core-C3kd7JXM.js} +2 -2
- package/dist/web/assets/{mindmap-definition-YRQLILUH-x0MTutJp.js → mindmap-definition-YRQLILUH-CYiUwhr_.js} +1 -1
- package/dist/web/assets/{ordinal-_K3x1fkz.js → ordinal-XHK5vIzZ.js} +1 -1
- package/dist/web/assets/packet-RMMSAZCW-o3LmdL8H.js +1 -0
- package/dist/web/assets/pie-UPGHQEXC-BjNP0M3B.js +1 -0
- package/dist/web/assets/{pieDiagram-SKSYHLDU-C1Gjrtzy.js → pieDiagram-SKSYHLDU-D0S7jeZA.js} +1 -1
- package/dist/web/assets/plus-Iso5r9vD.js +1 -0
- package/dist/web/assets/port-forwarding-tab-BPuSc6pI.js +1 -0
- package/dist/web/assets/{postgres-viewer-DlCLiEGU.js → postgres-viewer-RldlAO_m.js} +3 -3
- package/dist/web/assets/{quadrantDiagram-337W2JSQ-C8bzJCjQ.js → quadrantDiagram-337W2JSQ-0hNP63hW.js} +1 -1
- package/dist/web/assets/radar-KQ55EAFF-gDgOiaME.js +1 -0
- package/dist/web/assets/refresh-cw-BgQzFNaG.js +1 -0
- package/dist/web/assets/{requirementDiagram-Z7DCOOCP-pQyah6WB.js → requirementDiagram-Z7DCOOCP-BVnmqFbL.js} +1 -1
- package/dist/web/assets/{sankeyDiagram-WA2Y5GQK-T6RgG-N8.js → sankeyDiagram-WA2Y5GQK-DVkYdCJb.js} +1 -1
- package/dist/web/assets/scroll-area-i4EZlOl_.js +1 -0
- package/dist/web/assets/{sequenceDiagram-2WXFIKYE-BQDJ4CVs.js → sequenceDiagram-2WXFIKYE-B80s7sOg.js} +1 -1
- package/dist/web/assets/settings-tab-BzSSN2BQ.js +1 -0
- package/dist/web/assets/{sql-query-editor-Dxx-QZaI.js → sql-query-editor-CjZ7Z6XL.js} +1 -1
- package/dist/web/assets/sqlite-viewer-CoyZOM_Y.js +1 -0
- package/dist/web/assets/{stateDiagram-RAJIS63D-66vhiIuk.js → stateDiagram-RAJIS63D-BPLXgXRR.js} +1 -1
- package/dist/web/assets/stateDiagram-v2-FVOUBMTO-DksQJ7es.js +1 -0
- package/dist/web/assets/{terminal-tab-yfmxGQ5e.js → terminal-tab-DjzD8GLn.js} +2 -2
- package/dist/web/assets/{timeline-definition-YZTLITO2-DwZqB3nn.js → timeline-definition-YZTLITO2-fa_51u1X.js} +1 -1
- package/dist/web/assets/trash-2-DYCa06CV.js +1 -0
- package/dist/web/assets/treemap-KZPCXAKY-DwFqAvnj.js +1 -0
- package/dist/web/assets/{use-monaco-theme-7qyyJae5.js → use-monaco-theme-D9XFxQuU.js} +1 -1
- package/dist/web/assets/{vennDiagram-LZ73GAT5-s9Z71fz-.js → vennDiagram-LZ73GAT5-kX4jJn6W.js} +1 -1
- package/dist/web/assets/x-BXecj-16.js +1 -0
- package/dist/web/assets/{xychartDiagram-JWTSCODW-DRa_TH4B.js → xychartDiagram-JWTSCODW-Bzm5lZBs.js} +1 -1
- package/dist/web/index.html +22 -12
- package/dist/web/sw.js +1 -1
- package/package.json +9 -3
- package/src/server/index.ts +1 -1
- package/src/server/routes/settings.ts +6 -3
- package/src/services/cloud.service.ts +35 -4
- package/src/web/components/editor/code-editor.tsx +67 -4
- package/src/web/components/editor/save-as-dialog.tsx +75 -0
- package/src/web/components/git/git-status-panel.tsx +7 -1
- package/src/web/components/layout/command-palette.tsx +2 -0
- package/src/web/components/layout/draggable-tab.tsx +120 -67
- package/src/web/components/layout/mobile-nav.tsx +69 -2
- package/src/web/components/layout/sidebar.tsx +11 -1
- package/src/web/components/layout/tab-bar.tsx +74 -1
- package/src/web/components/layout/upgrade-banner.tsx +3 -0
- package/src/web/components/shared/markdown-code-block.tsx +142 -0
- package/src/web/components/shared/markdown-context.ts +20 -0
- package/src/web/components/shared/markdown-renderer.tsx +113 -288
- package/src/web/hooks/use-global-keybindings.ts +7 -0
- package/src/web/main.tsx +1 -0
- package/src/web/stores/git-status-store.ts +55 -0
- package/src/web/stores/keybindings-store.ts +1 -0
- package/src/web/stores/panel-utils.ts +13 -0
- package/src/web/stores/tab-store.ts +16 -0
- package/src/web/styles/globals.css +6 -0
- package/dist/web/assets/architecture-PBZL5I3N-DEO2f3VD.js +0 -1
- package/dist/web/assets/channel-By7bn0Yq.js +0 -1
- package/dist/web/assets/chat-tab-DBJJz0Dm.js +0 -10
- package/dist/web/assets/chunk-GLR3WWYH-DKikpoJM.js +0 -2
- package/dist/web/assets/chunk-HHEYEP7N-C7vxA5i9.js +0 -1
- package/dist/web/assets/chunk-QZHKN3VN-CYaTbeZf.js +0 -1
- package/dist/web/assets/classDiagram-VBA2DB6C-BA8Nj-_C.js +0 -1
- package/dist/web/assets/classDiagram-v2-RAHNMMFH-DjYu-6mn.js +0 -1
- package/dist/web/assets/clone-LRxlvnMj.js +0 -1
- package/dist/web/assets/code-editor-BvSFsrGo.js +0 -8
- package/dist/web/assets/diff-viewer-BmBJq4gO.js +0 -4
- package/dist/web/assets/dist-DIV6WgAG.js +0 -41
- package/dist/web/assets/git-graph-BAlhf058.js +0 -1
- package/dist/web/assets/gitGraph-HDMCJU4V-Bwna3and.js +0 -1
- package/dist/web/assets/index-BDAqXmpQ.js +0 -30
- package/dist/web/assets/index-BYXjCNlK.css +0 -2
- package/dist/web/assets/info-3K5VOQVL-_vRxVNUm.js +0 -1
- package/dist/web/assets/infoDiagram-LFFYTUFH-DWwumDkq.js +0 -2
- package/dist/web/assets/keybindings-store-L7UlPjK0.js +0 -1
- package/dist/web/assets/markdown-renderer-CYs_lrjt.js +0 -326
- package/dist/web/assets/packet-RMMSAZCW-DY5PNnZU.js +0 -1
- package/dist/web/assets/pie-UPGHQEXC-BHncZutv.js +0 -1
- package/dist/web/assets/port-forwarding-tab-CSHJ7gxM.js +0 -1
- package/dist/web/assets/radar-KQ55EAFF-DH0AOkUy.js +0 -1
- package/dist/web/assets/settings-tab-Dcr7lDcJ.js +0 -1
- package/dist/web/assets/sqlite-viewer-B0052fC-.js +0 -1
- package/dist/web/assets/stateDiagram-v2-FVOUBMTO-BGVqj_g9.js +0 -1
- package/dist/web/assets/treemap-KZPCXAKY-B2Xkyv-K.js +0 -1
- package/dist/web/assets/x-D2_KzIET.js +0 -1
- /package/dist/web/assets/{api-client-BfBM3I7n.js → api-client-wQbeUyeh.js} +0 -0
- /package/dist/web/assets/{array-B9UHiPd-.js → array-X0JlPOfd.js} +0 -0
- /package/dist/web/assets/{arrow-up-BYhx9ckd.js → arrow-up-BigIMx-e.js} +0 -0
- /package/dist/web/assets/{chevron-right-4zq1jPv6.js → chevron-right-CXzzT44u.js} +0 -0
- /package/dist/web/assets/{columns-2-BoZAN-iw.js → columns-2-BZ9uqssV.js} +0 -0
- /package/dist/web/assets/{csv-parser-CNNw2RVA.js → csv-parser-CElqio6o.js} +0 -0
- /package/dist/web/assets/{cytoscape.esm-BW-DbntU.js → cytoscape.esm-BfIOPvwt.js} +0 -0
- /package/dist/web/assets/{defaultLocale-5eAKkKJC.js → defaultLocale-B6RGN4id.js} +0 -0
- /package/dist/web/assets/{dist-CSJdAyA9.js → dist-CK1enexV.js} +0 -0
- /package/dist/web/assets/{init-DlZdxViB.js → init-BmUWJJHz.js} +0 -0
- /package/dist/web/assets/{isArrayLikeObject-B_v2FtYn.js → isArrayLikeObject-BrCM-iA1.js} +0 -0
- /package/dist/web/assets/{jsx-runtime-kMwlnEGE.js → jsx-runtime-R_NjdZtX.js} +0 -0
- /package/dist/web/assets/{katex-Bqvo_ZG0.js → katex-xQS_6bNb.js} +0 -0
- /package/dist/web/assets/{lib-DurwGtQO.js → lib-CfWBrYll.js} +0 -0
- /package/dist/web/assets/{math-069Z4SuC.js → math-CpLFzrfV.js} +0 -0
- /package/dist/web/assets/{path-6uRLdFF7.js → path-CoPyR7c2.js} +0 -0
- /package/dist/web/assets/{preload-helper-Bf_JiD2A.js → preload-helper-CH6UZRzu.js} +0 -0
- /package/dist/web/assets/{react-SKk5z-bm.js → react-j5zqhEum.js} +0 -0
- /package/dist/web/assets/{rough.esm-JX0wREDd.js → rough.esm-D5NinLFK.js} +0 -0
- /package/dist/web/assets/{sql-completion-provider-DM9Qov6L.js → sql-completion-provider-D0xutVaK.js} +0 -0
- /package/dist/web/assets/{square-oPKIkJiw.js → square-pfn_LYYy.js} +0 -0
- /package/dist/web/assets/{src-BqX54PbV.js → src-j04igtQ5.js} +0 -0
- /package/dist/web/assets/{table-DFevCOMd.js → table-CHv2x_qg.js} +0 -0
- /package/dist/web/assets/{tag-CXMT0QB6.js → tag-Bb_UFXt0.js} +0 -0
- /package/dist/web/assets/{text-wrap-BWNOVswA.js → text-wrap-D8BbQYTx.js} +0 -0
- /package/dist/web/assets/{utils-BNytJOb1.js → utils-CSCvNZxE.js} +0 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { useState, useEffect, useRef, type ReactNode } from "react";
|
|
2
|
+
import mermaid from "mermaid";
|
|
3
|
+
import { useMdContext, FILE_EXT_RE, GLOB_CHARS_RE } from "./markdown-context";
|
|
4
|
+
import { useTabStore } from "@/stores/tab-store";
|
|
5
|
+
|
|
6
|
+
const MERMAID_KEYWORDS = /^(sequenceDiagram|flowchart|graph\s|classDiagram|stateDiagram|erDiagram|journey|gantt|pie|quadrantChart|requirementDiagram|gitGraph|mindmap|timeline|sankey|xychart|block-beta|packet-beta|architecture-beta|kanban)\b/;
|
|
7
|
+
|
|
8
|
+
let mermaidInitialized = false;
|
|
9
|
+
function ensureMermaidInit() {
|
|
10
|
+
if (mermaidInitialized) return;
|
|
11
|
+
mermaid.initialize({ startOnLoad: false, theme: "default", securityLevel: "loose", fontFamily: "ui-sans-serif, system-ui, sans-serif" });
|
|
12
|
+
mermaidInitialized = true;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Extract plain text from a hast node tree */
|
|
16
|
+
function hastToText(node: any): string {
|
|
17
|
+
if (!node) return "";
|
|
18
|
+
if (node.type === "text") return node.value ?? "";
|
|
19
|
+
if (node.children) return node.children.map(hastToText).join("");
|
|
20
|
+
return "";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Pre — code block wrapper with mermaid detection and action buttons */
|
|
24
|
+
export function MdPre({ children, node, ...rest }: any) {
|
|
25
|
+
const { codeActions, projectName, openDiagramOverlay } = useMdContext();
|
|
26
|
+
const openTab = useTabStore((s) => s.openTab);
|
|
27
|
+
|
|
28
|
+
const codeNode = node?.children?.[0];
|
|
29
|
+
const langClass = (codeNode?.properties?.className ?? []).find((c: string) => c.startsWith("language-"));
|
|
30
|
+
const lang = langClass?.replace("language-", "");
|
|
31
|
+
const text = hastToText(codeNode);
|
|
32
|
+
|
|
33
|
+
// Mermaid detection
|
|
34
|
+
if (lang === "mermaid" || (!lang && MERMAID_KEYWORDS.test(text.trim()))) {
|
|
35
|
+
return <MermaidDiagram source={text.trim()} />;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const isBash = /^(bash|sh|shell|zsh)$/.test(lang || "") || (!lang && text.startsWith("$"));
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<pre {...rest} className={`relative group ${rest.className || ""}`}>
|
|
42
|
+
{children}
|
|
43
|
+
{codeActions && (
|
|
44
|
+
<div className="code-actions absolute top-1 right-1 flex gap-1">
|
|
45
|
+
<ActionBtn title="Copy" icon={<CopyIcon />} activeIcon={<CheckIcon />} onClick={() => navigator.clipboard.writeText(text)} />
|
|
46
|
+
{isBash && projectName && (
|
|
47
|
+
<ActionBtn
|
|
48
|
+
title="Run in terminal"
|
|
49
|
+
icon={<PlayIcon />}
|
|
50
|
+
onClick={() => {
|
|
51
|
+
navigator.clipboard.writeText(text.replace(/^\$\s*/gm, ""));
|
|
52
|
+
openTab({ type: "terminal", title: "Terminal", metadata: { projectName }, projectId: projectName, closable: true });
|
|
53
|
+
}}
|
|
54
|
+
/>
|
|
55
|
+
)}
|
|
56
|
+
</div>
|
|
57
|
+
)}
|
|
58
|
+
</pre>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Code — inline code with file clicking; block code passes through */
|
|
63
|
+
export function MdCode({ className, children, node, ...rest }: any) {
|
|
64
|
+
const { openFileOrSearch } = useMdContext();
|
|
65
|
+
|
|
66
|
+
// Block code (has language/hljs class from rehype-highlight) — render as-is
|
|
67
|
+
if (className) return <code className={className} {...rest}>{children}</code>;
|
|
68
|
+
|
|
69
|
+
// Inline code — check for clickable file paths
|
|
70
|
+
const text = String(children ?? "").trim();
|
|
71
|
+
if (text && !text.includes(" ") && !GLOB_CHARS_RE.test(text) && FILE_EXT_RE.test(text)) {
|
|
72
|
+
return (
|
|
73
|
+
<code
|
|
74
|
+
onClick={() => openFileOrSearch(text)}
|
|
75
|
+
style={{ cursor: "pointer", textDecoration: "underline", textDecorationStyle: "dotted" as const }}
|
|
76
|
+
{...rest}
|
|
77
|
+
>
|
|
78
|
+
{children}
|
|
79
|
+
</code>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return <code {...rest}>{children}</code>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Mermaid diagram renderer with click-to-expand */
|
|
87
|
+
function MermaidDiagram({ source }: { source: string }) {
|
|
88
|
+
const { openDiagramOverlay } = useMdContext();
|
|
89
|
+
const [svg, setSvg] = useState<string | null>(null);
|
|
90
|
+
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
ensureMermaidInit();
|
|
93
|
+
const id = `mermaid-${Math.random().toString(36).slice(2, 9)}`;
|
|
94
|
+
mermaid.render(id, source).then(({ svg }) => setSvg(svg)).catch(() => {});
|
|
95
|
+
}, [source]);
|
|
96
|
+
|
|
97
|
+
if (!svg) return <pre><code>{source}</code></pre>;
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<div
|
|
101
|
+
className="mermaid-diagram group relative cursor-pointer rounded-lg border border-border bg-white dark:bg-zinc-50 p-3 overflow-x-auto my-2"
|
|
102
|
+
onClick={() => openDiagramOverlay(svg)}
|
|
103
|
+
>
|
|
104
|
+
<div dangerouslySetInnerHTML={{ __html: svg }} />
|
|
105
|
+
<div className="absolute top-2 right-2 flex items-center gap-1 px-2 py-1 rounded bg-black/60 text-white text-xs can-hover:opacity-0 can-hover:group-hover:opacity-100 transition-opacity pointer-events-none">
|
|
106
|
+
Click to expand
|
|
107
|
+
</div>
|
|
108
|
+
</div>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Reusable code-block action button with optional active state */
|
|
113
|
+
function ActionBtn({ title, icon, activeIcon, onClick }: { title: string; icon: ReactNode; activeIcon?: ReactNode; onClick: () => void }) {
|
|
114
|
+
const [active, setActive] = useState(false);
|
|
115
|
+
return (
|
|
116
|
+
<button
|
|
117
|
+
className="flex items-center justify-center size-6 rounded bg-surface-elevated/80 hover:bg-surface-elevated text-text-secondary hover:text-text-primary transition-colors border border-border/50"
|
|
118
|
+
title={title}
|
|
119
|
+
onClick={() => { onClick(); if (activeIcon) { setActive(true); setTimeout(() => setActive(false), 2000); } }}
|
|
120
|
+
>
|
|
121
|
+
{active && activeIcon ? activeIcon : icon}
|
|
122
|
+
</button>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const CopyIcon = () => (
|
|
127
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
128
|
+
<rect width="14" height="14" x="8" y="8" rx="2" ry="2" /><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" />
|
|
129
|
+
</svg>
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
const CheckIcon = () => (
|
|
133
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
134
|
+
<polyline points="20 6 9 17 4 12" />
|
|
135
|
+
</svg>
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
const PlayIcon = () => (
|
|
139
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
140
|
+
<polyline points="4 17 10 11 4 5" /><line x1="12" y1="19" x2="20" y2="19" />
|
|
141
|
+
</svg>
|
|
142
|
+
);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
|
|
3
|
+
/** Common text file extensions that PPM can open as editor tabs */
|
|
4
|
+
const FILE_EXTS = "ts|tsx|js|jsx|mjs|cjs|py|json|md|mdx|yaml|yml|toml|css|scss|less|html|htm|sh|bash|zsh|go|rs|sql|rb|java|kt|swift|c|cpp|h|hpp|cs|vue|svelte|txt|env|cfg|conf|ini|xml|csv|log|dockerfile|makefile|gradle";
|
|
5
|
+
export const FILE_EXT_RE = new RegExp(`\\.(${FILE_EXTS})$`, "i");
|
|
6
|
+
/** Glob/regex chars that indicate a pattern, not a real file */
|
|
7
|
+
export const GLOB_CHARS_RE = /[*?{}\[\]]/;
|
|
8
|
+
/** Detect local absolute file paths (Unix or Windows) */
|
|
9
|
+
export const LOCAL_PATH_RE = /^(\/|[A-Za-z]:[/\\])/;
|
|
10
|
+
|
|
11
|
+
export interface MdContextValue {
|
|
12
|
+
projectName?: string;
|
|
13
|
+
codeActions: boolean;
|
|
14
|
+
openFileOrSearch: (path: string) => void;
|
|
15
|
+
openImageOverlay: (url: string, alt: string) => void;
|
|
16
|
+
openDiagramOverlay: (svg: string) => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const MdContext = createContext<MdContextValue>(null!);
|
|
20
|
+
export const useMdContext = () => useContext(MdContext);
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import { useMemo,
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { useMemo, useCallback, useState, useEffect } from "react";
|
|
2
|
+
import ReactMarkdown from "react-markdown";
|
|
3
|
+
import remarkGfm from "remark-gfm";
|
|
4
|
+
import remarkMath from "remark-math";
|
|
5
|
+
import remarkBreaks from "remark-breaks";
|
|
6
|
+
import rehypeRaw from "rehype-raw";
|
|
7
|
+
import rehypeKatex from "rehype-katex";
|
|
8
|
+
import rehypeHighlight from "rehype-highlight";
|
|
4
9
|
import { useTabStore } from "@/stores/tab-store";
|
|
5
10
|
import { useFileStore, type FileNode } from "@/stores/file-store";
|
|
6
11
|
import { useImageOverlay } from "@/stores/image-overlay-store";
|
|
@@ -8,35 +13,8 @@ import { useDiagramOverlay } from "@/stores/diagram-overlay-store";
|
|
|
8
13
|
import { openCommandPalette } from "@/hooks/use-global-keybindings";
|
|
9
14
|
import { api, projectUrl, getAuthToken } from "@/lib/api-client";
|
|
10
15
|
import { basename } from "@/lib/utils";
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
/** Mermaid keywords that start a diagram definition */
|
|
14
|
-
const MERMAID_KEYWORDS = /^(sequenceDiagram|flowchart|graph\s|classDiagram|stateDiagram|erDiagram|journey|gantt|pie|quadrantChart|requirementDiagram|gitGraph|mindmap|timeline|sankey|xychart|block-beta|packet-beta|architecture-beta|kanban)\b/;
|
|
15
|
-
|
|
16
|
-
let mermaidInitialized = false;
|
|
17
|
-
function ensureMermaidInit() {
|
|
18
|
-
if (mermaidInitialized) return;
|
|
19
|
-
mermaid.initialize({
|
|
20
|
-
startOnLoad: false,
|
|
21
|
-
theme: "default",
|
|
22
|
-
securityLevel: "loose",
|
|
23
|
-
fontFamily: "ui-sans-serif, system-ui, sans-serif",
|
|
24
|
-
});
|
|
25
|
-
mermaidInitialized = true;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** Detect local absolute file paths (Unix or Windows) */
|
|
29
|
-
const LOCAL_PATH_RE = /^(\/|[A-Za-z]:[/\\])/;
|
|
30
|
-
|
|
31
|
-
// Configure marked globally
|
|
32
|
-
marked.use({ gfm: true, breaks: true });
|
|
33
|
-
marked.use(markedKatex({ throwOnError: false }));
|
|
34
|
-
|
|
35
|
-
/** Common text file extensions that PPM can open as editor tabs */
|
|
36
|
-
const FILE_EXTS = "ts|tsx|js|jsx|mjs|cjs|py|json|md|mdx|yaml|yml|toml|css|scss|less|html|htm|sh|bash|zsh|go|rs|sql|rb|java|kt|swift|c|cpp|h|hpp|cs|vue|svelte|txt|env|cfg|conf|ini|xml|csv|log|dockerfile|makefile|gradle";
|
|
37
|
-
const FILE_EXT_RE = new RegExp(`\\.(${FILE_EXTS})$`, "i");
|
|
38
|
-
/** Glob/regex chars that indicate a pattern, not a real file */
|
|
39
|
-
const GLOB_CHARS_RE = /[*?{}\[\]]/;
|
|
16
|
+
import { MdContext, useMdContext, FILE_EXT_RE, GLOB_CHARS_RE, LOCAL_PATH_RE } from "./markdown-context";
|
|
17
|
+
import { MdPre, MdCode } from "./markdown-code-block";
|
|
40
18
|
|
|
41
19
|
interface MarkdownRendererProps {
|
|
42
20
|
content: string;
|
|
@@ -46,286 +24,133 @@ interface MarkdownRendererProps {
|
|
|
46
24
|
isStreaming?: boolean;
|
|
47
25
|
}
|
|
48
26
|
|
|
49
|
-
/**
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
* - Add target=_blank to external links
|
|
53
|
-
* - Mark <a> file paths with data-file-path
|
|
54
|
-
* - Make inline <code> with file names clickable (via HTML transform, not DOM)
|
|
55
|
-
*/
|
|
56
|
-
function transformHtml(raw: string): string {
|
|
57
|
-
let html = raw;
|
|
27
|
+
/** Plugin arrays — stable references to avoid re-creating on each render */
|
|
28
|
+
const remarkPlugins = [remarkGfm, remarkMath, remarkBreaks] as any;
|
|
29
|
+
const rehypePlugins = [rehypeRaw, rehypeKatex, rehypeHighlight] as any;
|
|
58
30
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
html = html.replace(/<\/table>/g, "</table></div>");
|
|
31
|
+
/** Component map — stable references; dynamic state flows through MdContext */
|
|
32
|
+
const mdComponents = { a: MdLink, img: MdImage, pre: MdPre, code: MdCode, table: MdTable };
|
|
62
33
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
html = html.replace(/<a\s+href="([^"]+)"/g, (match, href: string) => {
|
|
71
|
-
if (/^https?:\/\//.test(href)) return match; // already handled
|
|
72
|
-
if (GLOB_CHARS_RE.test(href)) return match; // skip glob/regex patterns
|
|
73
|
-
if (!FILE_EXT_RE.test(href)) return match; // must have a file extension
|
|
74
|
-
return `<a href="${href}" data-file-path="${href}"`;
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
// Inline <code> with file-like names → make clickable
|
|
78
|
-
// Split by <pre>...</pre> blocks to avoid transforming code inside them
|
|
79
|
-
const parts = html.split(/(<pre[\s\S]*?<\/pre>)/g);
|
|
80
|
-
html = parts.map((part) => {
|
|
81
|
-
// Skip <pre> blocks
|
|
82
|
-
if (part.startsWith("<pre")) return part;
|
|
83
|
-
// Transform inline <code> in non-pre content
|
|
84
|
-
return part.replace(
|
|
85
|
-
/<code>([^<]+)<\/code>/g,
|
|
86
|
-
(match, text: string) => {
|
|
87
|
-
const trimmed = text.trim();
|
|
88
|
-
if (!trimmed || trimmed.includes(" ")) return match;
|
|
89
|
-
if (GLOB_CHARS_RE.test(trimmed)) return match; // skip glob/regex patterns
|
|
90
|
-
if (!FILE_EXT_RE.test(trimmed)) return match; // must have a file extension
|
|
91
|
-
return `<code data-file-clickable="${trimmed}" style="cursor:pointer;text-decoration:underline;text-decoration-style:dotted">${text}</code>`;
|
|
92
|
-
},
|
|
93
|
-
);
|
|
94
|
-
}).join("");
|
|
95
|
-
|
|
96
|
-
return html;
|
|
34
|
+
function findInTree(nodes: FileNode[], name: string): string[] {
|
|
35
|
+
const results: string[] = [];
|
|
36
|
+
for (const n of nodes) {
|
|
37
|
+
if (n.type === "file" && n.name === name) results.push(n.path);
|
|
38
|
+
if (n.children) results.push(...findInTree(n.children, name));
|
|
39
|
+
}
|
|
40
|
+
return results;
|
|
97
41
|
}
|
|
98
42
|
|
|
99
43
|
export function MarkdownRenderer({ content, projectName, className = "", codeActions = false, isStreaming = false }: MarkdownRendererProps) {
|
|
100
|
-
const html = useMemo(() => {
|
|
101
|
-
try {
|
|
102
|
-
const raw = marked.parse(content) as string;
|
|
103
|
-
return transformHtml(raw);
|
|
104
|
-
} catch {
|
|
105
|
-
return content;
|
|
106
|
-
}
|
|
107
|
-
}, [content]);
|
|
108
|
-
|
|
109
|
-
const containerRef = useRef<HTMLDivElement>(null);
|
|
110
44
|
const openTab = useTabStore((s) => s.openTab);
|
|
111
45
|
const fileTree = useFileStore((s) => s.tree);
|
|
112
|
-
const
|
|
113
|
-
const
|
|
46
|
+
const openImageOverlayFn = useImageOverlay((s) => s.open);
|
|
47
|
+
const openDiagramOverlayFn = useDiagramOverlay((s) => s.open);
|
|
114
48
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const renderMermaid = async () => {
|
|
121
|
-
ensureMermaidInit();
|
|
122
|
-
const pres = container.querySelectorAll("pre");
|
|
123
|
-
for (const pre of pres) {
|
|
124
|
-
const code = pre.querySelector("code");
|
|
125
|
-
if (!code) continue;
|
|
126
|
-
const langClass = code.className ?? "";
|
|
127
|
-
const text = (code.textContent ?? "").trim();
|
|
128
|
-
const isMermaid = langClass.includes("language-mermaid") || MERMAID_KEYWORDS.test(text);
|
|
129
|
-
if (!isMermaid) continue;
|
|
130
|
-
|
|
131
|
-
try {
|
|
132
|
-
const id = `mermaid-${Math.random().toString(36).slice(2, 9)}`;
|
|
133
|
-
const { svg } = await mermaid.render(id, text);
|
|
134
|
-
const wrapper = document.createElement("div");
|
|
135
|
-
wrapper.className = "mermaid-diagram group relative cursor-pointer rounded-lg border border-border bg-white dark:bg-zinc-50 p-3 overflow-x-auto my-2";
|
|
136
|
-
wrapper.innerHTML = svg;
|
|
137
|
-
// Expand icon hint
|
|
138
|
-
const hint = document.createElement("div");
|
|
139
|
-
hint.className = "absolute top-2 right-2 flex items-center gap-1 px-2 py-1 rounded bg-black/60 text-white text-xs can-hover:opacity-0 can-hover:group-hover:opacity-100 transition-opacity pointer-events-none";
|
|
140
|
-
hint.textContent = "Click to expand";
|
|
141
|
-
wrapper.appendChild(hint);
|
|
142
|
-
// Click to open overlay
|
|
143
|
-
wrapper.addEventListener("click", () => openDiagramOverlay(svg));
|
|
144
|
-
pre.replaceWith(wrapper);
|
|
145
|
-
} catch {
|
|
146
|
-
// Render failed — leave as code block
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
renderMermaid();
|
|
151
|
-
|
|
152
|
-
// --- Click handler for file links and clickable code ---
|
|
153
|
-
const handleClick = (e: MouseEvent) => {
|
|
154
|
-
const target = e.target as HTMLElement;
|
|
49
|
+
const openFileOrSearch = useCallback((filePath: string) => {
|
|
50
|
+
if (!filePath) return;
|
|
51
|
+
const isAbsolute = /^(\/|[A-Za-z]:[/\\])/.test(filePath);
|
|
52
|
+
const isRelative = /^(\.\/|\.\.\/)/.test(filePath);
|
|
53
|
+
const fileName = basename(filePath);
|
|
155
54
|
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
if (
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// Check clickable <code>
|
|
165
|
-
const code = target.closest("code[data-file-clickable]") as HTMLElement | null;
|
|
166
|
-
if (code && container.contains(code)) {
|
|
167
|
-
openFileOrSearch(code.getAttribute("data-file-clickable") ?? "");
|
|
168
|
-
return;
|
|
55
|
+
const searchAndOpen = (fp: string) => {
|
|
56
|
+
const matches = findInTree(fileTree, basename(fp));
|
|
57
|
+
if (matches.length === 1) {
|
|
58
|
+
openTab({ type: "editor", title: basename(fp), metadata: { filePath: matches[0], projectName }, projectId: projectName ?? null, closable: true });
|
|
59
|
+
} else {
|
|
60
|
+
openCommandPalette(fp);
|
|
169
61
|
}
|
|
170
62
|
};
|
|
171
63
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
return results;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function openFileOrSearch(filePath: string) {
|
|
183
|
-
if (!filePath) return;
|
|
184
|
-
const isAbsolute = /^(\/|[A-Za-z]:[/\\])/.test(filePath);
|
|
185
|
-
const isRelative = /^(\.\/|\.\.\/)/.test(filePath);
|
|
186
|
-
const fileName = basename(filePath);
|
|
187
|
-
|
|
188
|
-
// Absolute path → verify then open
|
|
189
|
-
if (isAbsolute) {
|
|
190
|
-
const meta: Record<string, unknown> = { filePath };
|
|
191
|
-
if (projectName) meta.projectName = projectName;
|
|
192
|
-
api.get(`/api/fs/read?path=${encodeURIComponent(filePath)}`).then(() => {
|
|
193
|
-
openTab({ type: "editor", title: fileName, metadata: meta, projectId: null, closable: true });
|
|
194
|
-
}).catch(() => openCommandPalette(filePath));
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// Relative path with ./ or ../ → try exact path in project
|
|
199
|
-
if (isRelative && projectName) {
|
|
200
|
-
const meta: Record<string, unknown> = { filePath, projectName };
|
|
201
|
-
api.get(`${projectUrl(projectName)}/files/read?path=${encodeURIComponent(filePath)}`)
|
|
202
|
-
.then(() => {
|
|
203
|
-
openTab({ type: "editor", title: fileName, metadata: meta, projectId: projectName, closable: true });
|
|
204
|
-
})
|
|
205
|
-
.catch(() => searchAndOpen(filePath));
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// Just a filename → search in project tree
|
|
210
|
-
searchAndOpen(filePath);
|
|
64
|
+
if (isAbsolute) {
|
|
65
|
+
const meta: Record<string, unknown> = { filePath };
|
|
66
|
+
if (projectName) meta.projectName = projectName;
|
|
67
|
+
api.get(`/api/fs/read?path=${encodeURIComponent(filePath)}`).then(() => {
|
|
68
|
+
openTab({ type: "editor", title: fileName, metadata: meta, projectId: null, closable: true });
|
|
69
|
+
}).catch(() => openCommandPalette(filePath));
|
|
70
|
+
return;
|
|
211
71
|
}
|
|
212
72
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const match = matches[0]!;
|
|
219
|
-
openTab({
|
|
220
|
-
type: "editor",
|
|
221
|
-
title: fileName,
|
|
222
|
-
metadata: { filePath: match, projectName },
|
|
223
|
-
projectId: projectName ?? null,
|
|
224
|
-
closable: true,
|
|
225
|
-
});
|
|
226
|
-
} else {
|
|
227
|
-
openCommandPalette(filePath);
|
|
228
|
-
}
|
|
73
|
+
if (isRelative && projectName) {
|
|
74
|
+
api.get(`${projectUrl(projectName)}/files/read?path=${encodeURIComponent(filePath)}`)
|
|
75
|
+
.then(() => openTab({ type: "editor", title: fileName, metadata: { filePath, projectName }, projectId: projectName, closable: true }))
|
|
76
|
+
.catch(() => searchAndOpen(filePath));
|
|
77
|
+
return;
|
|
229
78
|
}
|
|
230
79
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
// --- Auth-load images with local file paths ---
|
|
234
|
-
const blobUrls: string[] = [];
|
|
235
|
-
container.querySelectorAll("img").forEach((img) => {
|
|
236
|
-
const src = img.getAttribute("src") ?? "";
|
|
237
|
-
// Only intercept local file paths, not http/data/blob URLs
|
|
238
|
-
if (!LOCAL_PATH_RE.test(src)) return;
|
|
239
|
-
// Mark as loading
|
|
240
|
-
img.style.opacity = "0.3";
|
|
241
|
-
img.style.minHeight = "48px";
|
|
242
|
-
img.style.minWidth = "48px";
|
|
243
|
-
const token = getAuthToken();
|
|
244
|
-
fetch(`/api/fs/raw?path=${encodeURIComponent(src)}`, {
|
|
245
|
-
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
|
246
|
-
})
|
|
247
|
-
.then((r) => {
|
|
248
|
-
if (!r.ok) throw new Error("Failed to load");
|
|
249
|
-
return r.blob();
|
|
250
|
-
})
|
|
251
|
-
.then((blob) => {
|
|
252
|
-
const url = URL.createObjectURL(blob);
|
|
253
|
-
blobUrls.push(url);
|
|
254
|
-
img.src = url;
|
|
255
|
-
img.style.opacity = "";
|
|
256
|
-
img.style.minHeight = "";
|
|
257
|
-
img.style.minWidth = "";
|
|
258
|
-
// Style: constrain size, add border like AuthImage
|
|
259
|
-
img.style.maxHeight = "400px";
|
|
260
|
-
img.style.maxWidth = "100%";
|
|
261
|
-
img.style.objectFit = "contain";
|
|
262
|
-
img.style.borderRadius = "0.375rem";
|
|
263
|
-
img.style.border = "1px solid var(--color-border)";
|
|
264
|
-
img.style.cursor = "pointer";
|
|
265
|
-
img.onclick = () => openImageOverlay(url, img.alt || basename(src));
|
|
266
|
-
})
|
|
267
|
-
.catch(() => {
|
|
268
|
-
img.style.opacity = "0.5";
|
|
269
|
-
img.alt = `[Image not found: ${basename(src)}]`;
|
|
270
|
-
});
|
|
271
|
-
});
|
|
80
|
+
searchAndOpen(filePath);
|
|
81
|
+
}, [openTab, fileTree, projectName]);
|
|
272
82
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
const text = code?.textContent ?? pre.textContent ?? "";
|
|
279
|
-
const langClass = code?.className ?? "";
|
|
280
|
-
const isBash = /language-(bash|sh|shell|zsh)/.test(langClass)
|
|
281
|
-
|| (!langClass.includes("language-") && text.startsWith("$"));
|
|
83
|
+
const ctx = useMemo(() => ({
|
|
84
|
+
projectName, codeActions, openFileOrSearch,
|
|
85
|
+
openImageOverlay: openImageOverlayFn,
|
|
86
|
+
openDiagramOverlay: openDiagramOverlayFn,
|
|
87
|
+
}), [projectName, codeActions, openFileOrSearch, openImageOverlayFn, openDiagramOverlayFn]);
|
|
282
88
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
89
|
+
return (
|
|
90
|
+
<MdContext.Provider value={ctx}>
|
|
91
|
+
<div className={`markdown-content prose-sm ${isStreaming ? "is-streaming" : ""} ${className}`}>
|
|
92
|
+
<ReactMarkdown remarkPlugins={remarkPlugins} rehypePlugins={rehypePlugins} components={mdComponents}>
|
|
93
|
+
{content}
|
|
94
|
+
</ReactMarkdown>
|
|
95
|
+
</div>
|
|
96
|
+
</MdContext.Provider>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
288
99
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
actions.appendChild(copyBtn);
|
|
100
|
+
/** Link — external links open in new tab; file paths open in editor */
|
|
101
|
+
function MdLink({ href, children, node, ...props }: any) {
|
|
102
|
+
const { openFileOrSearch } = useMdContext();
|
|
103
|
+
if (href?.match(/^https?:\/\//)) {
|
|
104
|
+
return <a href={href} target="_blank" rel="noopener noreferrer" {...props}>{children}</a>;
|
|
105
|
+
}
|
|
106
|
+
if (href && !GLOB_CHARS_RE.test(href) && FILE_EXT_RE.test(href)) {
|
|
107
|
+
return <a href={href} onClick={(e: React.MouseEvent) => { e.preventDefault(); openFileOrSearch(href); }} {...props}>{children}</a>;
|
|
108
|
+
}
|
|
109
|
+
return <a href={href} {...props}>{children}</a>;
|
|
110
|
+
}
|
|
301
111
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
runBtn.addEventListener("click", () => {
|
|
308
|
-
navigator.clipboard.writeText(text.replace(/^\$\s*/gm, ""));
|
|
309
|
-
openTab({ type: "terminal", title: "Terminal", metadata: { projectName }, projectId: projectName, closable: true });
|
|
310
|
-
});
|
|
311
|
-
actions.appendChild(runBtn);
|
|
312
|
-
}
|
|
112
|
+
/** Image — auth-loads local file paths via API, click to open overlay */
|
|
113
|
+
function MdImage({ src, alt, node, ...props }: any) {
|
|
114
|
+
const { openImageOverlay } = useMdContext();
|
|
115
|
+
const [blobUrl, setBlobUrl] = useState<string | null>(null);
|
|
116
|
+
const [loading, setLoading] = useState(false);
|
|
313
117
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (!src || !LOCAL_PATH_RE.test(src)) return;
|
|
120
|
+
setLoading(true);
|
|
121
|
+
let cancelled = false;
|
|
122
|
+
let url: string | null = null;
|
|
123
|
+
const token = getAuthToken();
|
|
124
|
+
fetch(`/api/fs/raw?path=${encodeURIComponent(src)}`, {
|
|
125
|
+
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
|
126
|
+
})
|
|
127
|
+
.then((r) => { if (!r.ok) throw new Error(); return r.blob(); })
|
|
128
|
+
.then((blob) => {
|
|
129
|
+
if (cancelled) return;
|
|
130
|
+
url = URL.createObjectURL(blob);
|
|
131
|
+
setBlobUrl(url);
|
|
132
|
+
setLoading(false);
|
|
133
|
+
})
|
|
134
|
+
.catch(() => { if (!cancelled) setLoading(false); });
|
|
135
|
+
return () => { cancelled = true; if (url) URL.revokeObjectURL(url); };
|
|
136
|
+
}, [src]);
|
|
317
137
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
blobUrls.forEach((u) => URL.revokeObjectURL(u));
|
|
321
|
-
};
|
|
322
|
-
}, [html, projectName, openTab, codeActions, openImageOverlay, openDiagramOverlay]);
|
|
138
|
+
const displaySrc = blobUrl || src || "";
|
|
139
|
+
const name = alt || (src ? basename(src) : "");
|
|
323
140
|
|
|
324
141
|
return (
|
|
325
|
-
<
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
142
|
+
<img
|
|
143
|
+
src={displaySrc}
|
|
144
|
+
alt={name}
|
|
145
|
+
onClick={() => displaySrc && openImageOverlay(displaySrc, name)}
|
|
146
|
+
className="max-h-[400px] max-w-full object-contain rounded-md border border-border cursor-pointer"
|
|
147
|
+
style={{ opacity: loading ? 0.3 : 1, minHeight: loading ? 48 : undefined, minWidth: loading ? 48 : undefined }}
|
|
148
|
+
{...props}
|
|
329
149
|
/>
|
|
330
150
|
);
|
|
331
151
|
}
|
|
152
|
+
|
|
153
|
+
/** Table — wrap in scrollable container */
|
|
154
|
+
function MdTable({ children, node, ...props }: any) {
|
|
155
|
+
return <div className="table-scroll-wrapper overflow-x-auto"><table {...props}>{children}</table></div>;
|
|
156
|
+
}
|
|
@@ -101,6 +101,13 @@ export function useGlobalKeybindings() {
|
|
|
101
101
|
return;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
// New file
|
|
105
|
+
if (match(e, "new-file")) {
|
|
106
|
+
e.preventDefault();
|
|
107
|
+
useTabStore.getState().openNewFile();
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
104
111
|
// Open tab shortcuts
|
|
105
112
|
const tabShortcuts: { action: string; type: string; title: string }[] = [
|
|
106
113
|
{ action: "open-chat", type: "chat", title: "AI Chat" },
|
package/src/web/main.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import { createRoot } from "react-dom/client";
|
|
|
3
3
|
import { App } from "./app.tsx";
|
|
4
4
|
import "./styles/globals.css";
|
|
5
5
|
import "katex/dist/katex.min.css";
|
|
6
|
+
import "highlight.js/styles/github-dark-dimmed.min.css";
|
|
6
7
|
|
|
7
8
|
createRoot(document.getElementById("root")!).render(
|
|
8
9
|
<StrictMode>
|