@qilin-agent/client-ui-sidebar-documentpreview 3.1.5 → 3.1.6

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/lib/client.js CHANGED
@@ -2098,6 +2098,23 @@ window.__ModuleLoader__.load({
2098
2098
  }, VideoBody)));
2099
2099
  }
2100
2100
  //#endregion
2101
+ //#region lib/types/client/markdown/frontmatter.js
2102
+ /** Leading YAML frontmatter split from a Markdown document before Markdown parsing. */
2103
+ const FRONTMATTER = /^\uFEFF?---[ \t]*\r?\n(?:([\s\S]*?)\r?\n)??(?:---|\.\.\.)[ \t]*(?:\r?\n|$)/u;
2104
+ /**
2105
+ * Split a leading YAML frontmatter block from Markdown text without parsing its YAML.
2106
+ * @param text - Markdown source; an unterminated block is not frontmatter.
2107
+ * @returns frontmatter source and the remaining body, or `undefined` when the text has none.
2108
+ */
2109
+ function splitFrontmatter(text) {
2110
+ const match = FRONTMATTER.exec(text);
2111
+ if (match === null) return void 0;
2112
+ return {
2113
+ source: match[1] ?? "",
2114
+ body: text.slice(match[0].length)
2115
+ };
2116
+ }
2117
+ //#endregion
2101
2118
  //#region lib/types/client/markdown/path-images.js
2102
2119
  /** Local Markdown image destinations served by the authenticated file route. */
2103
2120
  /**
@@ -4381,7 +4398,7 @@ window.__ModuleLoader__.load({
4381
4398
  }
4382
4399
  //#endregion
4383
4400
  //#region \0qilin-css:/home/runner/work/QiLin/QiLin/packages/client/ui-sidebar-documentpreview/src/client/markdown/MarkdownBody.module.css.mjs
4384
- const css$7 = ".zbylqG_document{min-width:0;font-family:var(--qilin-font,inherit);white-space:normal;padding:10px 12px}.zbylqG_htmlBlock{min-width:0;font-family:inherit;overflow-x:auto}";
4401
+ const css$7 = ".zbylqG_document{min-width:0;font-family:var(--qilin-font,inherit);white-space:normal;padding:10px 12px}.zbylqG_htmlBlock{min-width:0;font-family:inherit;overflow-x:auto}.zbylqG_frontmatter{border:.5px solid var(--qilin-alias-border-l2);border-radius:var(--qilin-radius-md);background:var(--qilin-alias-bg-layer-1);font:var(--qilin-font-markdown-small);color:var(--qilin-alias-label-primary);white-space:pre-wrap;overflow-wrap:anywhere;margin:0 0 16px;padding:10px 12px}.zbylqG_frontmatter:empty{display:none}.zbylqG_frontmatterSource{font-family:var(--ds-font-family-code);white-space:inherit;margin:0}";
4385
4402
  const tagId$7 = "@qilin-agent/client-ui-sidebar-documentpreview/MarkdownBody.module.css";
4386
4403
  if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$7) + "]") === null) {
4387
4404
  const tag = document.createElement("style");
@@ -4392,13 +4409,22 @@ window.__ModuleLoader__.load({
4392
4409
  }
4393
4410
  var MarkdownBody_module_css_default = {
4394
4411
  "document": "zbylqG_document",
4412
+ "frontmatter": "zbylqG_frontmatter",
4413
+ "frontmatterSource": "zbylqG_frontmatterSource",
4395
4414
  "htmlBlock": "zbylqG_htmlBlock"
4396
4415
  };
4397
4416
  //#endregion
4398
4417
  //#region lib/types/client/markdown/MarkdownBody.js
4399
4418
  /** One retained Markdown renderer over the document owner's accumulated text. */
4419
+ /** Show the verbatim frontmatter when the field-list chunk cannot load. */
4420
+ function FrontmatterFallback({ fallback }) {
4421
+ return fallback;
4422
+ }
4423
+ const FrontmatterFields = (0, react.lazy)(() => require.async("./client.frontmatter-fields.js").then((module) => ({ default: module.FrontmatterFields }), () => ({ default: FrontmatterFallback })));
4400
4424
  /**
4401
4425
  * Render one accumulated document; EOF completes the primitive's full parse.
4426
+ * A leading YAML frontmatter block renders as a field list instead of Markdown; its
4427
+ * verbatim source stands in while the field-list chunk loads or when it fails.
4402
4428
  * @param props - owner-loaded contents and localized primitive labels.
4403
4429
  * @returns Markdown content, or nothing for a non-text delivery.
4404
4430
  */
@@ -4436,16 +4462,40 @@ window.__ModuleLoader__.load({
4436
4462
  dangerouslySetInnerHTML: { __html: markup }
4437
4463
  });
4438
4464
  }, [absolutePath]);
4465
+ const text = content.kind === "text" ? content.text : "";
4466
+ const split = (0, react.useMemo)(() => splitFrontmatter(text), [text]);
4439
4467
  if (content.kind !== "text") return null;
4440
- return (0, react_jsx_runtime.jsx)("div", {
4468
+ return (0, react_jsx_runtime.jsxs)("div", {
4441
4469
  className: MarkdownBody_module_css_default.document,
4442
4470
  "data-document-markdown": true,
4443
- children: (0, react_jsx_runtime.jsx)(_qilin_agent_client_ui_primitives.MarkdownText, {
4444
- text: content.text,
4471
+ children: [split === void 0 ? null : (0, react_jsx_runtime.jsx)(FrontmatterBox, { source: split.source }), (0, react_jsx_runtime.jsx)(_qilin_agent_client_ui_primitives.MarkdownText, {
4472
+ text: split?.body ?? text,
4445
4473
  streaming: !content.eof,
4446
4474
  labels,
4447
4475
  pathImages,
4448
4476
  html
4477
+ })]
4478
+ });
4479
+ }
4480
+ /**
4481
+ * Frame one frontmatter block and choose its field list or verbatim source.
4482
+ * @param props - YAML between the frontmatter delimiters.
4483
+ * @returns the metadata box; it collapses when the document has no content.
4484
+ */
4485
+ function FrontmatterBox({ source }) {
4486
+ const verbatim = (0, react_jsx_runtime.jsx)("pre", {
4487
+ className: MarkdownBody_module_css_default.frontmatterSource,
4488
+ children: source
4489
+ });
4490
+ return (0, react_jsx_runtime.jsx)("div", {
4491
+ className: MarkdownBody_module_css_default.frontmatter,
4492
+ "data-document-frontmatter": true,
4493
+ children: (0, react_jsx_runtime.jsx)(react.Suspense, {
4494
+ fallback: verbatim,
4495
+ children: (0, react_jsx_runtime.jsx)(FrontmatterFields, {
4496
+ source,
4497
+ fallback: verbatim
4498
+ })
4449
4499
  })
4450
4500
  });
4451
4501
  }
@@ -5,6 +5,8 @@ import type { DocumentPreviewProps } from '../document/contract.ts';
5
5
  export type MarkdownBodyProps = DocumentPreviewProps & PropsLocale<'documentMarkdown'>;
6
6
  /**
7
7
  * Render one accumulated document; EOF completes the primitive's full parse.
8
+ * A leading YAML frontmatter block renders as a field list instead of Markdown; its
9
+ * verbatim source stands in while the field-list chunk loads or when it fails.
8
10
  * @param props - owner-loaded contents and localized primitive labels.
9
11
  * @returns Markdown content, or nothing for a non-text delivery.
10
12
  */
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Field list for a Markdown document's leading YAML frontmatter. The Markdown
3
+ * body loads this module lazily so the YAML parser stays out of the startup
4
+ * chunk.
5
+ */
6
+ import { type ReactNode } from 'react';
7
+ /** Owner inputs for the lazily loaded field list. */
8
+ export interface FrontmatterFieldsProps {
9
+ /** YAML between the frontmatter delimiters. */
10
+ source: string;
11
+ /** Verbatim block shown for invalid YAML and non-mapping documents. */
12
+ fallback: ReactNode;
13
+ }
14
+ /**
15
+ * Render frontmatter fields, or the owner's verbatim block when the YAML is not a mapping.
16
+ * @param props - frontmatter source and its verbatim fallback.
17
+ * @returns the field list, the fallback, or nothing for a document without content.
18
+ */
19
+ export declare function FrontmatterFields({ source, fallback }: FrontmatterFieldsProps): ReactNode;
20
+ //# sourceMappingURL=frontmatter-fields.d.ts.map
@@ -0,0 +1,13 @@
1
+ /** Leading YAML frontmatter split from a Markdown document before Markdown parsing. */
2
+ /** Frontmatter source between its delimiters and the Markdown body after the closing delimiter. */
3
+ export interface FrontmatterSplit {
4
+ source: string;
5
+ body: string;
6
+ }
7
+ /**
8
+ * Split a leading YAML frontmatter block from Markdown text without parsing its YAML.
9
+ * @param text - Markdown source; an unterminated block is not frontmatter.
10
+ * @returns frontmatter source and the remaining body, or `undefined` when the text has none.
11
+ */
12
+ export declare function splitFrontmatter(text: string): FrontmatterSplit | undefined;
13
+ //# sourceMappingURL=frontmatter.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@qilin-agent/client-ui-sidebar-documentpreview",
3
3
  "description": "Extensible document previews for Sidebar files: Office, Markdown, highlighted code, images, PDF, HTML, and plain text",
4
- "version": "3.1.5",
4
+ "version": "3.1.6",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -46,7 +46,7 @@
46
46
  },
47
47
  "license": "MIT",
48
48
  "peerDependencies": {
49
- "@qilin-agent/kylin": "~4.0.3"
49
+ "@qilin-agent/kylin": "~4.0.5"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@fortune-sheet/core": "1.0.4",
@@ -65,27 +65,28 @@
65
65
  "react": "^18.2.0",
66
66
  "react-dom": "^18.2.0",
67
67
  "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz",
68
- "@qilin-agent/api-gateway": "3.1.5",
69
- "@qilin-agent/kylin": "~4.0.3",
70
- "@qilin-agent/api-remotes": "3.1.5",
71
- "@qilin-agent/client-connection": "3.1.5",
72
- "@qilin-agent/api-workspace-files": "3.1.5",
73
- "@qilin-agent/client-locale": "3.1.5",
74
- "@qilin-agent/client-resources": "3.1.5",
75
- "@qilin-agent/client-store": "3.1.5",
76
- "@qilin-agent/client-ui-conversation": "3.1.5",
77
- "@qilin-agent/client-ui-primitives": "3.1.5",
78
- "@qilin-agent/client-ui-dockkit": "3.1.5",
79
- "@qilin-agent/client-test-runtime": "3.1.5",
80
- "@qilin-agent/client-ui-renderer": "3.1.5",
81
- "@qilin-agent/client-ui-session": "3.1.5",
82
- "@qilin-agent/client-ui-settings": "3.1.5",
83
- "@qilin-agent/client-ui-sidebar-right": "3.1.5",
84
- "@qilin-agent/client-ui-slots": "3.1.5",
85
- "@qilin-agent/host-webserver": "3.1.5",
86
- "@qilin-agent/session": "3.1.5",
87
- "@qilin-agent/util-workspace-path": "3.1.5",
88
- "@qilin-agent/office-to-pdf": "3.1.5"
68
+ "yaml": "^2.9.0",
69
+ "@qilin-agent/api-gateway": "3.1.6",
70
+ "@qilin-agent/kylin": "~4.0.5",
71
+ "@qilin-agent/api-workspace-files": "3.1.6",
72
+ "@qilin-agent/client-connection": "3.1.6",
73
+ "@qilin-agent/api-remotes": "3.1.6",
74
+ "@qilin-agent/client-locale": "3.1.6",
75
+ "@qilin-agent/client-store": "3.1.6",
76
+ "@qilin-agent/client-resources": "3.1.6",
77
+ "@qilin-agent/client-test-runtime": "3.1.6",
78
+ "@qilin-agent/client-ui-dockkit": "3.1.6",
79
+ "@qilin-agent/client-ui-conversation": "3.1.6",
80
+ "@qilin-agent/client-ui-primitives": "3.1.6",
81
+ "@qilin-agent/client-ui-renderer": "3.1.6",
82
+ "@qilin-agent/client-ui-settings": "3.1.6",
83
+ "@qilin-agent/client-ui-sidebar-right": "3.1.6",
84
+ "@qilin-agent/session": "3.1.6",
85
+ "@qilin-agent/host-webserver": "3.1.6",
86
+ "@qilin-agent/util-workspace-path": "3.1.6",
87
+ "@qilin-agent/client-ui-session": "3.1.6",
88
+ "@qilin-agent/office-to-pdf": "3.1.6",
89
+ "@qilin-agent/client-ui-slots": "3.1.6"
89
90
  },
90
91
  "files": [
91
92
  "lib/index.js",
@@ -94,7 +95,7 @@
94
95
  "lib/types/**/*.d.ts"
95
96
  ],
96
97
  "dependencies": {
97
- "@qilin-agent/schemastery": "~3.18.3"
98
+ "@qilin-agent/schemastery": "~3.18.5"
98
99
  },
99
100
  "scripts": {
100
101
  "bundle": "tsdown",