@robthepcguy/rag-vault 1.7.0 → 1.8.0
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/README.md +28 -9
- package/dist/chunker/semantic-chunker.d.ts +0 -1
- package/dist/chunker/semantic-chunker.d.ts.map +1 -1
- package/dist/chunker/semantic-chunker.js +1 -1
- package/dist/chunker/semantic-chunker.js.map +1 -1
- package/dist/embedder/index.d.ts +5 -0
- package/dist/embedder/index.d.ts.map +1 -1
- package/dist/embedder/index.js +40 -5
- package/dist/embedder/index.js.map +1 -1
- package/dist/errors/index.d.ts +1 -1
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/flywheel/feedback.d.ts +1 -1
- package/dist/flywheel/feedback.d.ts.map +1 -1
- package/dist/flywheel/feedback.js +1 -1
- package/dist/flywheel/feedback.js.map +1 -1
- package/dist/parser/pdf-filter.d.ts +3 -5
- package/dist/parser/pdf-filter.d.ts.map +1 -1
- package/dist/parser/pdf-filter.js +1 -1
- package/dist/parser/pdf-filter.js.map +1 -1
- package/dist/query/parser.d.ts +2 -6
- package/dist/query/parser.d.ts.map +1 -1
- package/dist/query/parser.js +14 -22
- package/dist/query/parser.js.map +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +37 -34
- package/dist/server/index.js.map +1 -1
- package/dist/server/raw-data-utils.d.ts +0 -40
- package/dist/server/raw-data-utils.d.ts.map +1 -1
- package/dist/server/raw-data-utils.js +9 -8
- package/dist/server/raw-data-utils.js.map +1 -1
- package/dist/server/remote-transport.d.ts +2 -1
- package/dist/server/remote-transport.d.ts.map +1 -1
- package/dist/server/remote-transport.js +27 -7
- package/dist/server/remote-transport.js.map +1 -1
- package/dist/server/schemas.d.ts +5 -29
- package/dist/server/schemas.d.ts.map +1 -1
- package/dist/server/schemas.js +6 -6
- package/dist/server/schemas.js.map +1 -1
- package/dist/vectordb/index.d.ts +12 -9
- package/dist/vectordb/index.d.ts.map +1 -1
- package/dist/vectordb/index.js +242 -163
- package/dist/vectordb/index.js.map +1 -1
- package/dist/web/api-routes.d.ts.map +1 -1
- package/dist/web/api-routes.js +23 -10
- package/dist/web/api-routes.js.map +1 -1
- package/dist/web/database-manager.d.ts.map +1 -1
- package/dist/web/database-manager.js +32 -25
- package/dist/web/database-manager.js.map +1 -1
- package/dist/web/http-server.d.ts +0 -5
- package/dist/web/http-server.d.ts.map +1 -1
- package/dist/web/http-server.js +4 -8
- package/dist/web/http-server.js.map +1 -1
- package/dist/web/index.js +4 -2
- package/dist/web/index.js.map +1 -1
- package/dist/web/middleware/async-handler.d.ts +2 -1
- package/dist/web/middleware/async-handler.d.ts.map +1 -1
- package/dist/web/middleware/rate-limit.d.ts +2 -1
- package/dist/web/middleware/rate-limit.d.ts.map +1 -1
- package/dist/web/middleware/request-logger.d.ts +1 -1
- package/dist/web/middleware/request-logger.d.ts.map +1 -1
- package/package.json +1 -1
- package/web-ui/dist/assets/{CollectionsPage-BDmEfv3V.js → CollectionsPage-CjLs8_5j.js} +1 -1
- package/web-ui/dist/assets/{FilesPage-pG9HmpgQ.js → FilesPage-Bw9x9aMr.js} +1 -1
- package/web-ui/dist/assets/ReaderPage-JPNiOF-x.js +28 -0
- package/web-ui/dist/assets/{ReaderSettingsContext-CkSjqsRh.js → ReaderSettingsContext-BLFJnEne.js} +1 -1
- package/web-ui/dist/assets/{SearchPage-DAltjnLL.js → SearchPage-D3_Vtbdw.js} +1 -1
- package/web-ui/dist/assets/{SettingsPage-C6J5BITP.js → SettingsPage-BAxB2264.js} +1 -1
- package/web-ui/dist/assets/{StatusPage-powRGmW3.js → StatusPage-CzJZW8Gs.js} +1 -1
- package/web-ui/dist/assets/{UploadPage-eyfSjL4u.js → UploadPage-DW8OujeJ.js} +5 -5
- package/web-ui/dist/assets/index-ANt8Xo4z.js +6 -0
- package/web-ui/dist/assets/index-DovQIIL4.css +1 -0
- package/web-ui/dist/assets/motion-Brxs0UET.js +9 -0
- package/web-ui/dist/assets/vendor-DSXQOR6A.js +10 -0
- package/web-ui/dist/index.html +3 -3
- package/web-ui/dist/assets/ReaderPage-CwMN03NU.js +0 -28
- package/web-ui/dist/assets/index-BpwaiuGL.css +0 -1
- package/web-ui/dist/assets/index-D068MV_o.js +0 -6
- package/web-ui/dist/assets/motion-CKwJwI3J.js +0 -9
- package/web-ui/dist/assets/vendor-C2QPsZ3S.js +0 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-server.js","sourceRoot":"","sources":["../../src/web/http-server.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,WAAW,MAAM,aAAa,CAAA;AACrC,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,OAAyE,MAAM,SAAS,CAAA;AAC/F,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,MAAM,MAAM,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"http-server.js","sourceRoot":"","sources":["../../src/web/http-server.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,WAAW,MAAM,aAAa,CAAA;AACrC,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,OAAyE,MAAM,SAAS,CAAA;AAC/F,OAAO,EAAE,kBAAkB,EAAE,MAAM,W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W,CAAC,CAAA;IACvC,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/web/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Entry point for RAG Web Server
|
|
3
3
|
import { existsSync } from 'node:fs';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
5
6
|
import { buildRAGConfig, validateAllowedScanRoots, validateRAGConfig } from '../utils/config.js';
|
|
6
7
|
import { onShutdown, setupGracefulShutdown, setupProcessHandlers, } from '../utils/process-handlers.js';
|
|
7
8
|
import { stopRateLimiterCleanup } from './middleware/index.js';
|
|
@@ -36,8 +37,9 @@ async function main() {
|
|
|
36
37
|
// Check multiple locations: cwd for dev, package dir for npx/global install
|
|
37
38
|
let staticDir;
|
|
38
39
|
const cwd = process.cwd();
|
|
39
|
-
//
|
|
40
|
-
const
|
|
40
|
+
// import.meta.url points to dist/web/ when compiled, so go up to package root
|
|
41
|
+
const currentDir = path.dirname(fileURLToPath(import.meta.url));
|
|
42
|
+
const packageDir = path.resolve(currentDir, '../..');
|
|
41
43
|
const possiblePaths = [
|
|
42
44
|
path.resolve(cwd, 'web-ui/dist'), // Dev: running from repo root
|
|
43
45
|
path.resolve(packageDir, 'web-ui/dist'), // npx/global: relative to package
|
package/dist/web/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/web/index.ts"],"names":[],"mappings":";AACA,iCAAiC;AAEjC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAChG,OAAO,EACL,UAAU,EACV,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAE9D,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|
|
2
2
|
/**
|
|
3
3
|
* Async request handler type
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
type AsyncHandler = (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
6
6
|
/**
|
|
7
7
|
* Wraps an async route handler to automatically catch errors
|
|
8
8
|
* and pass them to Express error middleware
|
|
@@ -14,4 +14,5 @@ export type AsyncHandler = (req: Request, res: Response, next: NextFunction) =>
|
|
|
14
14
|
* }))
|
|
15
15
|
*/
|
|
16
16
|
export declare function asyncHandler(handler: AsyncHandler): AsyncHandler;
|
|
17
|
+
export {};
|
|
17
18
|
//# sourceMappingURL=async-handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-handler.d.ts","sourceRoot":"","sources":["../../../src/web/middleware/async-handler.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAE9D;;GAEG;AACH,
|
|
1
|
+
{"version":3,"file":"async-handler.d.ts","sourceRoot":"","sources":["../../../src/web/middleware/async-handler.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAE9D;;GAEG;AACH,KAAK,YAAY,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;AAEtF;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,YAAY,CAQhE"}
|
|
@@ -2,7 +2,7 @@ import type { NextFunction, Request, Response } from 'express';
|
|
|
2
2
|
/**
|
|
3
3
|
* Rate limit configuration
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
interface RateLimitConfig {
|
|
6
6
|
/** Time window in milliseconds */
|
|
7
7
|
windowMs: number;
|
|
8
8
|
/** Maximum requests per window */
|
|
@@ -35,4 +35,5 @@ export declare function getRateLimitConfigFromEnv(): RateLimitConfig;
|
|
|
35
35
|
* Safe to call multiple times or when no interval is active.
|
|
36
36
|
*/
|
|
37
37
|
export declare function stopRateLimiterCleanup(): void;
|
|
38
|
+
export {};
|
|
38
39
|
//# sourceMappingURL=rate-limit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rate-limit.d.ts","sourceRoot":"","sources":["../../../src/web/middleware/rate-limit.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAQ9D;;GAEG;AACH,
|
|
1
|
+
{"version":3,"file":"rate-limit.d.ts","sourceRoot":"","sources":["../../../src/web/middleware/rate-limit.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAQ9D;;GAEG;AACH,UAAU,eAAe;IACvB,kCAAkC;IAClC,QAAQ,EAAE,MAAM,CAAA;IAChB,kCAAkC;IAClC,WAAW,EAAE,MAAM,CAAA;IACnB,0CAA0C;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAmBD;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,GAAE,OAAO,CAAC,eAAe,CAAM,IAuC7D,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,KAAG,IAAI,CAkC/D;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,IAAI,eAAe,CAY3D;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,IAAI,IAAI,CAM7C"}
|
|
@@ -19,7 +19,7 @@ type LoggerFn = (entry: RequestLogEntry) => void;
|
|
|
19
19
|
/**
|
|
20
20
|
* Request logging configuration
|
|
21
21
|
*/
|
|
22
|
-
|
|
22
|
+
interface RequestLoggerConfig {
|
|
23
23
|
/** Custom logger function */
|
|
24
24
|
logger?: LoggerFn;
|
|
25
25
|
/** Skip logging for certain paths (e.g., health checks) */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-logger.d.ts","sourceRoot":"","sources":["../../../src/web/middleware/request-logger.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAE9D;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB;AAED;;GAEG;AACH,KAAK,QAAQ,GAAG,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAA;AAkBhD;;GAEG;AACH,
|
|
1
|
+
{"version":3,"file":"request-logger.d.ts","sourceRoot":"","sources":["../../../src/web/middleware/request-logger.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAE9D;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB;AAED;;GAEG;AACH,KAAK,QAAQ,GAAG,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAA;AAkBhD;;GAEG;AACH,UAAU,mBAAmB;IAC3B,6BAA6B;IAC7B,MAAM,CAAC,EAAE,QAAQ,CAAA;IACjB,2DAA2D;IAC3D,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAA;IAChC,iEAAiE;IACjE,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,GAAE,mBAAwB,IAG1D,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,KAAG,IAAI,CAgC/D;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,OAAO,CAGjD"}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,j as e}from"./query-DPt-uCb6.js";import{k as D,C as O,m as w}from"./index-
|
|
1
|
+
import{a,j as e}from"./query-DPt-uCb6.js";import{k as D,C as O,m as w}from"./index-ANt8Xo4z.js";import{A as b,m as N}from"./motion-Brxs0UET.js";import{u as M}from"./vendor-DSXQOR6A.js";function B(){const{collections:s,createCollection:n,updateCollection:o,deleteCollection:h,getCollection:p,getDocumentsInCollection:f}=D();return{collections:s,createCollection:n,updateCollection:o,deleteCollection:h,getCollection:p,getDocumentsInCollection:f}}function R(){const s=M(),{collections:n,createCollection:o,updateCollection:h,deleteCollection:p,getDocumentsInCollection:f}=B(),[l,d]=a.useState(!1),[m,u]=a.useState(null),[r,i]=a.useState(""),[v,c]=a.useState(""),[x,j]=a.useState("blue"),g=()=>{d(!0),u(null),i(""),c(""),j("blue")},L=t=>{d(!1),u(t.id),i(t.name),c(t.description||""),j(t.color)},S=()=>{r.trim()&&(l?o(r.trim(),x,v.trim()||void 0):m&&h(m,{name:r.trim(),color:x,description:v.trim()||void 0}),d(!1),u(null),i(""),c(""))},I=()=>{d(!1),u(null),i(""),c("")},E=t=>{s(`/files?collection=${t}`)};return e.jsxs("div",{className:"ws-page max-w-4xl mx-auto space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"ws-page-title text-2xl font-bold mb-2",children:"Collections"}),e.jsx("p",{style:{color:"var(--ws-text-secondary)"},children:"Organize your documents into collections."})]}),!l&&!m&&e.jsxs("button",{type:"button",onClick:g,className:"ws-button flex items-center gap-2 px-4 py-2 rounded-lg transition-colors","data-variant":"primary",children:[e.jsx(k,{className:"w-4 h-4"}),"New Collection"]})]}),e.jsx(b,{children:(l||m)&&e.jsxs(N.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"ws-surface p-4 space-y-4",children:[e.jsx("h3",{className:"text-lg font-medium",style:{color:"var(--ws-text)"},children:l?"Create Collection":"Edit Collection"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx("div",{children:e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--ws-text-secondary)"},children:["Name",e.jsx("input",{type:"text",value:r,onChange:t=>i(t.target.value),placeholder:"Collection name",className:"ws-input mt-1"})]})}),e.jsxs("div",{children:[e.jsx("span",{className:"block text-sm font-medium mb-1",style:{color:"var(--ws-text-secondary)"},children:"Color"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:O.map(t=>e.jsx("button",{type:"button",onClick:()=>j(t),className:`w-8 h-8 rounded-full ${w[t].bg} ${x===t?"ring-2 ring-offset-2":""}`,style:x===t?{"--tw-ring-color":"var(--ws-accent)","--tw-ring-offset-color":"var(--ws-surface-2)"}:void 0},t))})]})]}),e.jsx("div",{children:e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--ws-text-secondary)"},children:["Description (optional)",e.jsx("input",{type:"text",value:v,onChange:t=>c(t.target.value),placeholder:"What's this collection for?",className:"ws-input mt-1"})]})}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{type:"button",onClick:I,className:"ws-button px-4 py-2 text-sm rounded-lg transition-colors","data-variant":"default",children:"Cancel"}),e.jsx("button",{type:"button",onClick:S,disabled:!r.trim(),className:"ws-button px-4 py-2 text-sm rounded-lg transition-colors","data-variant":"primary",children:l?"Create":"Save"})]})]})}),n.length===0?e.jsxs("div",{className:"ws-surface text-center py-12",children:[e.jsx(W,{className:"w-12 h-12 mx-auto mb-3",style:{color:"var(--ws-text-faint)"}}),e.jsx("h3",{className:"text-lg font-medium mb-1",style:{color:"var(--ws-text)"},children:"No collections yet"}),e.jsx("p",{className:"mb-4",style:{color:"var(--ws-text-muted)"},children:"Create a collection to organize your documents."}),e.jsxs("button",{type:"button",onClick:g,className:"ws-button inline-flex items-center gap-2 px-4 py-2 rounded-lg transition-colors","data-variant":"primary",children:[e.jsx(k,{className:"w-4 h-4"}),"Create your first collection"]})]}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:e.jsx(b,{children:n.map(t=>{const y=f(t.id),C=w[t.color];return e.jsxs(N.div,{layout:!0,initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},className:`rounded-lg p-4 ${C.border}`,style:{background:"var(--ws-surface-2)",border:"1px solid"},children:[e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`w-4 h-4 rounded-full ${C.bg}`}),e.jsx("h3",{className:"text-lg font-medium",style:{color:"var(--ws-text)"},children:t.name})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{type:"button",onClick:()=>L(t),className:"p-1.5 rounded transition-colors",style:{color:"var(--ws-text-faint)"},title:"Edit",children:e.jsx($,{className:"w-4 h-4"})}),e.jsx(H,{onDelete:()=>p(t.id)})]})]}),t.description&&e.jsx("p",{className:"text-sm mb-3",style:{color:"var(--ws-text-muted)"},children:t.description}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm",style:{color:"var(--ws-text-muted)"},children:[y.length," document",y.length!==1?"s":""]}),e.jsx("button",{type:"button",onClick:()=>E(t.id),className:"text-sm hover:underline",style:{color:"var(--ws-accent)"},children:"View documents →"})]})]},t.id)})})})]})}function H({onDelete:s}){const[n,o]=a.useState(!1);return n?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{type:"button",onClick:s,className:"px-2 py-1 text-xs font-medium rounded transition-colors",style:{color:"var(--ws-danger)",background:"var(--ws-danger-muted)"},children:"Delete"}),e.jsx("button",{type:"button",onClick:()=>o(!1),className:"px-2 py-1 text-xs font-medium rounded transition-colors",style:{color:"var(--ws-text-muted)"},children:"Cancel"})]}):e.jsx("button",{type:"button",onClick:()=>o(!0),className:"p-1.5 rounded transition-colors",style:{color:"var(--ws-text-faint)"},title:"Delete",children:e.jsx(z,{className:"w-4 h-4"})})}function k({className:s}){return e.jsx("svg",{className:s,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})}function W({className:s,style:n}){return e.jsx("svg",{className:s,style:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"})})}function $({className:s}){return e.jsx("svg",{className:s,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}function z({className:s}){return e.jsx("svg",{className:s,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})}export{R as CollectionsPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as k,j as e}from"./query-DPt-uCb6.js";import{u as P,c as L}from"./vendor-
|
|
1
|
+
import{a as k,j as e}from"./query-DPt-uCb6.js";import{u as P,c as L}from"./vendor-DSXQOR6A.js";import{j as F,k as S,l as T,S as R,T as M}from"./index-ANt8Xo4z.js";function I({file:s,onDelete:l,isDeleting:n}){const[o,r]=k.useState(!1),p=P(),j=s.source||s.filePath.split(/[/\\]/).pop()||s.filePath,i=s.filePath.includes("raw-data"),d=()=>{s.source?l({source:s.source}):l({filePath:s.filePath}),r(!1)},m=()=>{const c=new URLSearchParams({path:s.filePath});p(`/read?${c.toString()}`)};return e.jsxs("div",{className:"rounded-lg p-4 flex items-center justify-between gap-4",style:{background:"var(--ws-surface-raised)",border:"1px solid var(--ws-border)"},children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"font-medium truncate",style:{color:"var(--ws-text)"},title:s.source||s.filePath,children:j}),e.jsxs("div",{className:"flex items-center gap-4 mt-1 text-sm",style:{color:"var(--ws-text-muted)"},children:[e.jsxs("span",{children:[s.chunkCount," chunks"]}),i&&e.jsx("span",{style:{color:"var(--ws-accent)"},children:"Ingested content"})]}),s.source&&e.jsx("p",{className:"text-xs truncate mt-1",style:{color:"var(--ws-text-muted)"},title:s.filePath,children:s.filePath})]}),e.jsx("div",{className:"flex items-center gap-2",children:o?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:d,disabled:n,className:"px-3 py-1.5 text-sm bg-red-600 text-white rounded-lg hover:bg-red-700 disabled:opacity-50 transition-colors",children:"Confirm"}),e.jsx("button",{type:"button",onClick:()=>r(!1),disabled:n,className:"px-3 py-1.5 text-sm rounded-lg transition-colors",style:{color:"var(--ws-text-secondary)",background:"var(--ws-surface-1)"},children:"Cancel"})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:m,className:"px-3 py-1.5 text-sm text-green-600 hover:bg-green-50 rounded-lg transition-colors",children:"Read"}),e.jsx("button",{type:"button",onClick:()=>r(!0),className:"px-3 py-1.5 text-sm text-red-600 hover:bg-red-50 rounded-lg transition-colors",children:"Delete"})]})})]})}function A({files:s,onDelete:l,isDeleting:n}){return s.length===0?e.jsxs("div",{className:"text-center py-12",style:{color:"var(--ws-text-muted)"},children:[e.jsx("p",{children:"No files ingested yet."}),e.jsx("p",{className:"text-sm mt-1",children:"Upload a file or paste content to get started."})]}):e.jsx("div",{className:"space-y-2",children:s.map(o=>e.jsx(I,{file:o,onDelete:l,isDeleting:n},o.filePath))})}function D(){const[s,l]=L(),{files:n,isLoading:o,error:r,deleteFile:p,isDeleting:j}=F(),{collections:i}=S(),{tags:d,getTagsForTarget:m}=T(),c=s.get("collection")||"",x=s.get("tag")||"",h=i.find(t=>t.id===c),f=d.find(t=>t.id===x),u=k.useMemo(()=>{let t=n;if(c&&h){const a=new Set(h.documents);t=t.filter(b=>a.has(b.filePath))}return x&&(t=t.filter(a=>m("document",a.filePath).some(C=>C.id===x))),t},[n,c,h,x,m]),v=t=>{const a=new URLSearchParams(s);t?a.set("collection",t):a.delete("collection"),l(a)},w=t=>{const a=new URLSearchParams(s);t?a.set("tag",t):a.delete("tag"),l(a)},y=()=>{l({})},g=c||x;return e.jsxs("div",{className:"ws-page max-w-4xl mx-auto space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"ws-page-title text-2xl font-bold mb-2",children:"Ingested Files"}),e.jsx("p",{style:{color:"var(--ws-text-secondary)"},children:"Manage your knowledge base content."})]}),n.length>0&&e.jsx("span",{className:"text-sm",style:{color:"var(--ws-text-muted)"},children:u.length===n.length?`${n.length} file${n.length!==1?"s":""}`:`${u.length} of ${n.length} files`})]}),(i.length>0||d.length>0)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-3 p-3 rounded-lg",style:{background:"var(--ws-surface-1)",border:"1px solid var(--ws-border)"},children:[e.jsx("span",{className:"text-sm font-medium",style:{color:"var(--ws-text-secondary)"},children:"Filter by:"}),i.length>0&&e.jsxs("select",{value:c,onChange:t=>v(t.target.value),className:"ws-select text-sm px-3 py-1.5",children:[e.jsx("option",{value:"",children:"All collections"}),i.map(t=>e.jsxs("option",{value:t.id,children:[t.name," (",t.documents.length,")"]},t.id))]}),d.length>0&&e.jsxs("select",{value:x,onChange:t=>w(t.target.value),className:"ws-select text-sm px-3 py-1.5",children:[e.jsx("option",{value:"",children:"All tags"}),d.map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))]}),g&&e.jsx("button",{type:"button",onClick:y,className:"text-sm hover:underline",style:{color:"var(--ws-accent)"},children:"Clear filters"})]}),g&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[h&&e.jsx(N,{label:h.name,type:"collection",onRemove:()=>v("")}),f&&e.jsx(N,{label:f.name,type:"tag",color:f.color,onRemove:()=>w("")})]}),o?e.jsxs("div",{className:"flex items-center justify-center py-12",children:[e.jsx("span",{style:{color:"var(--ws-text-faint)"},children:e.jsx(R,{})}),e.jsx("span",{className:"ml-3",style:{color:"var(--ws-text-muted)"},children:"Loading files..."})]}):r?e.jsxs("div",{className:"ws-error-box rounded-lg",children:[e.jsx("p",{className:"font-medium",children:"Error loading files"}),e.jsx("p",{className:"text-sm",children:r.message})]}):u.length===0?e.jsxs("div",{className:"ws-surface text-center py-12",children:[e.jsx($,{className:"w-10 h-10 mx-auto mb-3",style:{color:"var(--ws-text-faint)"}}),e.jsx("p",{style:{color:"var(--ws-text-secondary)"},children:g?"No files match the selected filters.":"No files ingested yet."}),g&&e.jsx("button",{type:"button",onClick:y,className:"mt-2 text-sm hover:underline",style:{color:"var(--ws-accent)"},children:"Clear filters"})]}):e.jsx(A,{files:u,onDelete:p,isDeleting:j})]})}function N({label:s,type:l,color:n,onRemove:o}){const r=l==="tag"&&n?M[n]?.bg:void 0;return e.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-1 text-sm rounded-full ${r||""}`,style:r?void 0:{background:"var(--ws-surface-2)"},children:[l==="collection"?e.jsx(B,{className:"w-3.5 h-3.5",style:{color:"var(--ws-text-muted)"}}):e.jsx(E,{className:"w-3.5 h-3.5",style:{color:"var(--ws-text-muted)"}}),e.jsx("span",{style:{color:"var(--ws-text-secondary)"},children:s}),e.jsx("button",{type:"button",onClick:o,className:"p-0.5 rounded-full hover:bg-black/10 dark:hover:bg-white/10",children:e.jsx(U,{className:"w-3 h-3",style:{color:"var(--ws-text-muted)"}})})]})}function $({className:s,style:l}){return e.jsx("svg",{className:s,style:l,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"})})}function B({className:s,style:l}){return e.jsx("svg",{className:s,style:l,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"})})}function E({className:s,style:l}){return e.jsx("svg",{className:s,style:l,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z"})})}function U({className:s,style:l}){return e.jsx("svg",{className:s,style:l,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}export{D as FilesPage};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import{a,b as st,j as e}from"./query-DPt-uCb6.js";import{useReaderSettings as je}from"./ReaderSettingsContext-BLFJnEne.js";import{g as nt,u as Ne,a as rt,b as at,s as ot,S as J,c as lt,K as ct,d as Ce,e as it,f as dt}from"./index-ANt8Xo4z.js";import{m as M,A}from"./motion-Brxs0UET.js";import{c as ut,u as xt}from"./vendor-DSXQOR6A.js";function ht(t="100px"){const[s,n]=a.useState(new Set),[r,o]=a.useState(null),c=a.useRef(null),d=a.useRef(new Map),i=a.useRef(new Set);a.useEffect(()=>{c.current=new IntersectionObserver(h=>{n(x=>{const f=new Set(x);for(const p of h){const y=Number(p.target.getAttribute("data-chunk-index"));Number.isNaN(y)||(p.isIntersecting?f.add(y):f.delete(y))}return f})},{rootMargin:t,threshold:[0,.25,.5,.75,1]});const u=c.current;for(const[,h]of d.current)u.observe(h);for(const h of i.current){const x=d.current.get(h);x&&u.observe(x)}return i.current.clear(),()=>{u.disconnect(),c.current=null,d.current.clear()}},[t]),a.useEffect(()=>{if(s.size===0)o(null);else{const u=Array.from(s).sort((h,x)=>h-x);o(u[0]??null)}},[s]);const l=a.useCallback((u,h)=>{const x=c.current,f=d.current.get(u);f&&x&&x.unobserve(f),i.current.delete(u),h?(d.current.set(u,h),h.setAttribute("data-chunk-index",String(u)),x?x.observe(h):i.current.add(u)):d.current.delete(u)},[]);return{visibleChunkIndices:s,registerChunk:l,activeChunkIndex:r}}function mt(t,s,n=300,r=5){const[o,c]=a.useState([]);a.useEffect(()=>{if(!t||s.size===0){c([]);return}const u=Array.from(s).map(x=>({filePath:t,chunkIndex:x})),h=setTimeout(()=>{c(u)},n);return()=>clearTimeout(h)},[t,s,n]);const{data:d={},isLoading:i,error:l}=st({queryKey:["batchRelatedChunks",o,r],queryFn:()=>o.length>0?nt(o,r):{},enabled:o.length>0,staleTime:300*1e3});return{relatedChunks:d,isLoading:i,error:l}}function le(){return crypto.randomUUID()}function ft(t,s){const n=t||"1",r=String.fromCharCode(97+s);return`${n}${r}`}function pt(t){if(t.length===0)return null;const s=t[0];if(!s)return null;const n={id:le(),chunkKey:s.chunkKey,visitedAt:s.visitedAt,connectionReason:s.connectionReason,branchLabel:"1",children:[]};let r=n;for(let o=1;o<t.length;o++){const c=t[o];if(!c)continue;const d={id:le(),chunkKey:c.chunkKey,visitedAt:c.visitedAt,connectionReason:c.connectionReason,branchLabel:String(o+1),children:[]};r.children.push(d),r=d}return n}function Ie(t,s=[]){return t&&(s.push({chunkKey:t.chunkKey,visitedAt:t.visitedAt,connectionReason:t.connectionReason}),t.children.length>0&&Ie(t.children[0]||null,s)),s}function Se(t,s){if(!t)return null;if(t.id===s)return t;for(const n of t.children){const r=Se(n,s);if(r)return r}return null}function bt(){const t=Ne(),[s,n]=a.useState(null),r=a.useCallback((l,u)=>{t.addToTrail(l,u)},[t]),o=a.useCallback(()=>t.currentTrail?t.currentTrail.root?t.currentTrail.root:pt(t.currentTrail.steps):null,[t.currentTrail]),c=a.useCallback(()=>Ie(o()),[o]),d=a.useCallback((l,u)=>{if(!t.currentTrail)return null;const h=o();if(!h)return null;const x=s||h.id,f=Se(h,x);if(!f)return null;const p={id:le(),chunkKey:l,visitedAt:new Date().toISOString(),connectionReason:u,branchLabel:ft(f.branchLabel,f.children.length),children:[]};return f.children.push(p),n(p.id),p.id},[t.currentTrail,s,o]),i=a.useMemo(()=>{if(!t.currentTrail)return 0;const l=o();if(!l)return t.currentTrail.steps.length;let u=0;const h=x=>{u++,x.children.forEach(h)};return h(l),u},[t.currentTrail,o]);return{currentTrail:t.currentTrail,savedTrails:t.trails,isRecording:t.currentTrail!==null,stepCount:i,startNewTrail:t.startNewTrail,addStep:r,saveTrail:t.saveTrail,loadTrail:t.loadTrail,deleteTrail:t.deleteTrail,clearCurrentTrail:t.clearCurrentTrail,currentNodeId:s,setCurrentNodeId:n,addBranch:d,getTrailTree:o,flattenTrail:c}}function gt({totalChunks:t,activeChunkIndex:s,onNavigateToChunk:n,onToggleSplit:r,onPinTopSuggestion:o,onOpenSearch:c,onOpenHelp:d,onCloseOverlay:i,isOverlayOpen:l,enabled:u=!0,isSearchOpen:h=!1,onNextSearchMatch:x,onPreviousSearchMatch:f,onToggleBookmark:p,onOpenTagPicker:y,onToggleAnnotationPanel:m,onToggleReadingMode:g,onOpenComparison:b,onResetGraphLayout:w,onOpenGraphExport:k,onTogglePathfinding:T,onToggleClustering:K,isGraphOpen:D=!1,onToggleInferredLinks:B,onToggleCrossDocPanel:$,onToggleStatsPanel:v,onToggleDiscoveryMode:j,isDiscoveryMode:C=!1,onDiscoverySelectSuggestion:E,onDiscoveryGoBack:V}){const q=a.useRef(null),Z=a.useRef({totalChunks:t,activeChunkIndex:s,isOverlayOpen:l,isSearchOpen:h,isGraphOpen:D,isDiscoveryMode:C}),L=a.useRef({onNavigateToChunk:n,onToggleSplit:r,onPinTopSuggestion:o,onOpenSearch:c,onOpenHelp:d,onCloseOverlay:i,onNextSearchMatch:x,onPreviousSearchMatch:f,onToggleBookmark:p,onOpenTagPicker:y,onToggleAnnotationPanel:m,onToggleReadingMode:g,onOpenComparison:b,onResetGraphLayout:w,onOpenGraphExport:k,onTogglePathfinding:T,onToggleClustering:K,onToggleInferredLinks:B,onToggleCrossDocPanel:$,onToggleStatsPanel:v,onToggleDiscoveryMode:j,onDiscoverySelectSuggestion:E,onDiscoveryGoBack:V});Z.current={totalChunks:t,activeChunkIndex:s,isOverlayOpen:l,isSearchOpen:h,isGraphOpen:D,isDiscoveryMode:C},L.current={onNavigateToChunk:n,onToggleSplit:r,onPinTopSuggestion:o,onOpenSearch:c,onOpenHelp:d,onCloseOverlay:i,onNextSearchMatch:x,onPreviousSearchMatch:f,onToggleBookmark:p,onOpenTagPicker:y,onToggleAnnotationPanel:m,onToggleReadingMode:g,onOpenComparison:b,onResetGraphLayout:w,onOpenGraphExport:k,onTogglePathfinding:T,onToggleClustering:K,onToggleInferredLinks:B,onToggleCrossDocPanel:$,onToggleStatsPanel:v,onToggleDiscoveryMode:j,onDiscoverySelectSuggestion:E,onDiscoveryGoBack:V};const G=a.useCallback(()=>{const I=document.activeElement;if(I){const S=I.tagName.toLowerCase();if(S==="input"||S==="textarea"||I.getAttribute("contenteditable")==="true")return!0}const R=window.getSelection();return!!(R&&R.toString().length>0)},[]),U=a.useCallback(I=>{if(G())return;const R=Z.current,S=L.current;if(I.key==="Escape"){R.isOverlayOpen&&(I.preventDefault(),S.onCloseOverlay());return}if(R.isSearchOpen){switch(I.key){case"n":I.preventDefault(),S.onNextSearchMatch?.();return;case"N":I.preventDefault(),S.onPreviousSearchMatch?.();return}return}if(!R.isOverlayOpen)switch(I.key){case"j":{I.preventDefault();const W=R.activeChunkIndex===null?0:Math.min(R.activeChunkIndex+1,R.totalChunks-1);S.onNavigateToChunk(W);break}case"k":{I.preventDefault();const W=R.activeChunkIndex===null?0:Math.max(R.activeChunkIndex-1,0);S.onNavigateToChunk(W);break}case" ":{I.preventDefault(),S.onToggleSplit();break}case"p":{I.preventDefault(),S.onPinTopSuggestion();break}case"/":{I.preventDefault(),S.onOpenSearch();break}case"?":{I.preventDefault(),S.onOpenHelp();break}case"b":{I.preventDefault(),S.onToggleBookmark?.();break}case"t":{I.preventDefault(),S.onOpenTagPicker?.();break}case"a":{I.preventDefault(),S.onToggleAnnotationPanel?.();break}case"m":{I.preventDefault(),S.onToggleReadingMode?.();break}case"c":{I.preventDefault(),S.onOpenComparison?.();break}case"r":{R.isGraphOpen&&(I.preventDefault(),S.onResetGraphLayout?.());break}case"e":{R.isGraphOpen&&(I.preventDefault(),S.onOpenGraphExport?.());break}case"f":{R.isGraphOpen&&(I.preventDefault(),S.onTogglePathfinding?.());break}case"g":{R.isGraphOpen&&(I.preventDefault(),S.onToggleClustering?.());break}case"i":{I.preventDefault(),S.onToggleInferredLinks?.();break}case"x":{I.preventDefault(),S.onToggleCrossDocPanel?.();break}case"s":{I.preventDefault(),S.onToggleStatsPanel?.();break}case"d":{I.preventDefault(),S.onToggleDiscoveryMode?.();break}case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":{if(R.isDiscoveryMode){I.preventDefault();const W=parseInt(I.key,10)-1;S.onDiscoverySelectSuggestion?.(W)}break}case"Backspace":{R.isDiscoveryMode&&(I.preventDefault(),S.onDiscoveryGoBack?.());break}}},[G]);return a.useEffect(()=>{if(u)return document.addEventListener("keydown",U),()=>{document.removeEventListener("keydown",U)}},[u,U]),{containerRef:q}}async function vt(t){const n=new TextEncoder().encode(t.slice(0,500)),r=await crypto.subtle.digest("SHA-256",n);return Array.from(new Uint8Array(r)).slice(0,8).map(c=>c.toString(16).padStart(2,"0")).join("")}function yt({filePath:t,chunks:s,activeChunkIndex:n,vaultId:r="default",debounceMs:o=1e3}){const c=`rag-vault-reading-progress-${r}`,[d,i]=rt(c,{}),l=a.useRef(null),u=a.useRef(null),h=a.useRef(!1),x=a.useRef({chunkIndex:0,scrollOffset:0});a.useEffect(()=>{if(s.length>0){const w=s[0];w&&vt(w.text).then(k=>{u.current=k})}},[s]);const f=a.useCallback(w=>`${t}:${w}`,[t]),p=Object.entries(d).find(([w])=>w.startsWith(`${t}:`)),y=!!p,m=p?p[1].lastChunkIndex:null,g=a.useCallback((w,k)=>{u.current&&(x.current={chunkIndex:w,scrollOffset:k},l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{const T=u.current;if(!T)return;const{chunkIndex:K,scrollOffset:D}=x.current,B=f(T);i($=>({...$,[B]:{lastChunkIndex:K,scrollOffsetWithinChunk:D,lastVisited:new Date().toISOString(),fileFingerprint:T}}))},o))},[f,i,o]);a.useEffect(()=>{if(n!==null&&h.current){const w=document.getElementById(`chunk-${n}`),k=w?w.getBoundingClientRect().top:0;g(n,k)}},[n,g]);const b=a.useCallback(()=>{if(!u.current||s.length===0)return null;const w=u.current,k=f(w),T=d[k];return T?T.fileFingerprint!==w?(h.current=!0,{chunkIndex:0,scrollOffset:0}):(h.current=!0,{chunkIndex:Math.min(T.lastChunkIndex,s.length-1),scrollOffset:T.scrollOffsetWithinChunk}):Object.entries(d).find(([D])=>D.startsWith(`${t}:`))?(h.current=!0,{chunkIndex:0,scrollOffset:0}):(h.current=!0,null)},[t,s,d,f]);return a.useEffect(()=>()=>{l.current&&clearTimeout(l.current)},[]),{restorePosition:b,savePosition:g,hasSavedPosition:y,savedChunkIndex:m}}function kt(t){const s=at(),n=a.useMemo(()=>t?s.getHighlightsForChunk(t):[],[s,t]),r=a.useMemo(()=>{const h=new Map;for(const x of n){const f=s.getAnnotationForHighlight(x.id);f&&h.set(x.id,f)}return h},[n,s]),o=a.useCallback((h,x,f,p,y)=>{if(!t)throw new Error("No chunk key provided");return s.createHighlight(t,h,x,f,p,y)},[s,t]),c=a.useCallback(h=>{s.deleteHighlight(h)},[s]),d=a.useCallback((h,x)=>{s.updateHighlightColor(h,x)},[s]),i=a.useCallback((h,x)=>s.createAnnotation(h,x),[s]),l=a.useCallback((h,x)=>{s.updateAnnotation(h,x)},[s]),u=a.useCallback(h=>{s.deleteAnnotation(h)},[s]);return{highlights:n,annotations:r,createHighlight:o,deleteHighlight:c,updateHighlightColor:d,addNote:i,updateNote:l,deleteNote:u,hasHighlights:n.length>0}}function wt(t,s,n){const r=t.getRangeAt(0),o=[],c=document.createTreeWalker(s,NodeFilter.SHOW_TEXT);let d=c.nextNode();for(;d!==null;)o.push(d),d=c.nextNode();let i=0,l=!1;for(const x of o){if(x===r.startContainer){i+=r.startOffset,l=!0;break}i+=x.textContent?.length??0}if(!l)return null;let u=0,h=!1;for(const x of o){if(x===r.endContainer){u+=r.endOffset,h=!0;break}u+=x.textContent?.length??0}return!h||i<0||u>n.length||i>=u?null:{startOffset:i,endOffset:u}}function jt({containerRef:t,chunkText:s,enabled:n=!0}){const[r,o]=a.useState(null),c=a.useCallback(()=>{o(null),window.getSelection()?.removeAllRanges()},[]);return a.useEffect(()=>{if(!n)return;const d=()=>{const u=window.getSelection();if(!u||u.isCollapsed||!u.rangeCount){o(null);return}const h=t.current;if(!h){o(null);return}const x=u.getRangeAt(0);if(!h.contains(x.commonAncestorContainer)){o(null);return}const f=u.toString().trim();if(!f){o(null);return}const p=wt(u,h,s);if(!p){o(null);return}const y=x.getBoundingClientRect(),m=s.slice(Math.max(0,p.startOffset-30),p.startOffset),g=s.slice(p.endOffset,p.endOffset+30);o({startOffset:p.startOffset,endOffset:p.endOffset,text:f,contextBefore:m,contextAfter:g,rect:y})};let i;const l=()=>{clearTimeout(i),i=setTimeout(d,100)};return document.addEventListener("selectionchange",l),()=>{document.removeEventListener("selectionchange",l),clearTimeout(i)}},[n,t,s]),{selection:r,clearSelection:c}}function Nt(t){return t.map(s=>({chunkIndex:s.chunkIndex,text:s.text,lowerText:s.text.toLowerCase()}))}function pe(t,s,n){if(!s||s.length===0)return[];const r=[],o=n?s:s.toLowerCase();for(const c of t){const d=n?c.text:c.lowerText;let i=0;for(;i<d.length;){const l=d.indexOf(o,i);if(l===-1)break;const u=Math.max(0,l-25),h=Math.min(c.text.length,l+s.length+25),x=c.text.slice(u,h);r.push({chunkIndex:c.chunkIndex,startOffset:l,endOffset:l+s.length,context:(u>0?"...":"")+x+(h<c.text.length?"...":"")}),i=l+1}}return r}const be={query:"",matches:[],currentIndex:-1,caseSensitive:!1,isOpen:!1};function Ct({chunks:t,onNavigateToChunk:s}){const[n,r]=a.useState(be),o=a.useMemo(()=>Nt(t),[t]),c=a.useCallback(()=>{r(m=>({...m,isOpen:!0}))},[]),d=a.useCallback(()=>{r(m=>({...m,isOpen:!1}))},[]),i=a.useCallback(()=>{r(be)},[]),l=a.useCallback(m=>{const g=pe(o,m,n.caseSensitive);r(b=>({...b,query:m,matches:g,currentIndex:g.length>0?0:-1})),g.length>0&&s&&s(g[0].chunkIndex)},[o,n.caseSensitive,s]),u=a.useCallback(()=>{r(m=>{const g=!m.caseSensitive,b=pe(o,m.query,g);return{...m,caseSensitive:g,matches:b,currentIndex:b.length>0?0:-1}})},[o]),h=a.useCallback(()=>{r(m=>{if(m.matches.length===0)return m;const g=(m.currentIndex+1)%m.matches.length,b=m.matches[g];return b&&s&&s(b.chunkIndex),{...m,currentIndex:g}})},[s]),x=a.useCallback(()=>{r(m=>{if(m.matches.length===0)return m;const g=m.currentIndex<=0?m.matches.length-1:m.currentIndex-1,b=m.matches[g];return b&&s&&s(b.chunkIndex),{...m,currentIndex:g}})},[s]),f=a.useCallback(m=>{r(g=>{if(m<0||m>=g.matches.length)return g;const b=g.matches[m];return b&&s&&s(b.chunkIndex),{...g,currentIndex:m}})},[s]),p=a.useCallback(m=>n.matches.filter(g=>g.chunkIndex===m),[n.matches]),y=a.useMemo(()=>n.currentIndex>=0&&n.currentIndex<n.matches.length?n.matches[n.currentIndex]??null:null,[n.matches,n.currentIndex]);return{searchState:n,isSearchOpen:n.isOpen,openSearch:c,closeSearch:d,setQuery:l,toggleCaseSensitive:u,nextMatch:h,previousMatch:x,goToMatch:f,clearSearch:i,getMatchesForChunk:p,currentMatch:y,totalMatches:n.matches.length}}const It=10,St=400,Lt=5,Tt=300*1e3,z=new Map;function Le(t){return t.trim().toLowerCase().slice(0,100)}function Ot(t){const s=Le(t),n=z.get(s);return n&&Date.now()-n.timestamp<Tt?n.results:(n&&z.delete(s),null)}function Mt(t,s){const n=Le(t);if(z.size>=50){const r=z.keys().next().value;r&&z.delete(r)}z.set(n,{results:s,timestamp:Date.now()})}function Rt({selectionText:t,filePath:s,chunkIndex:n,enabled:r=!0}){const[o,c]=a.useState([]),[d,i]=a.useState(!1),[l,u]=a.useState(null),[h,x]=a.useState(null),f=a.useRef(null),p=a.useRef(null),y=a.useRef(null),m=a.useCallback(()=>{c([]),u(null),x(null),i(!1),y.current=null,p.current&&(clearTimeout(p.current),p.current=null),f.current&&(f.current.abort(),f.current=null)},[]);return a.useEffect(()=>{if(!r){m();return}if(!t){m();return}if(t.length<It){m();return}if(t===y.current)return;p.current&&clearTimeout(p.current),f.current&&f.current.abort();const g=Ot(t);if(g){const b=g.filter(w=>!(w.filePath===s&&w.chunkIndex===n));c(b),u(t),y.current=t;return}return p.current=setTimeout(async()=>{i(!0),f.current=new AbortController;try{x(null);const b=await ot(t,Lt),w=b.filter(k=>!(k.filePath===s&&k.chunkIndex===n));Mt(t,b),c(w),u(t),y.current=t}catch(b){b instanceof Error&&b.name!=="AbortError"&&(console.error("Auto-selection search failed:",b),c([]),x(b.message||"Search failed"))}finally{i(!1)}},St),()=>{p.current&&clearTimeout(p.current)}},[t,s,n,r,m]),a.useEffect(()=>()=>{p.current&&clearTimeout(p.current),f.current&&f.current.abort()},[]),{results:o,isSearching:d,searchedText:l,searchError:h,clearResults:m}}const ge=[{color:"yellow",bg:"bg-yellow-300",ring:"ring-yellow-400",label:"Yellow"},{color:"green",bg:"bg-green-300",ring:"ring-green-400",label:"Green"},{color:"blue",bg:"bg-blue-300",ring:"ring-blue-400",label:"Blue"},{color:"pink",bg:"bg-pink-300",ring:"ring-pink-400",label:"Pink"},{color:"purple",bg:"bg-purple-300",ring:"ring-purple-400",label:"Purple"}];function Et({highlight:t,annotation:s,onUpdateNote:n,onDeleteNote:r,onDeleteHighlight:o,onChangeColor:c}){const[d,i]=a.useState(!1),[l,u]=a.useState(s?.note||""),[h,x]=a.useState(!1),f=a.useCallback(()=>{l.trim()&&n(l.trim()),i(!1)},[l,n]),p=a.useCallback(m=>{m.key==="Enter"&&!m.shiftKey&&(m.preventDefault(),f()),m.key==="Escape"&&(i(!1),u(s?.note||""))},[f,s?.note]),y=ge.find(m=>m.color===t.color);return e.jsxs(M.div,{initial:{opacity:0,x:10},animate:{opacity:1,x:0},exit:{opacity:0,x:-10},className:"rounded-lg border shadow-sm overflow-hidden",style:{background:"var(--ws-surface-raised)",borderColor:"var(--ws-border)"},children:[e.jsx("div",{className:"px-3 py-2 border-b",style:{background:"var(--ws-surface-1)",borderColor:"var(--ws-border)"},children:e.jsxs("p",{className:"text-xs italic line-clamp-2",style:{color:"var(--ws-text-muted)"},children:['"',t.text.length>60?`${t.text.slice(0,60)}...`:t.text,'"']})}),e.jsx("div",{className:"p-3",children:d?e.jsxs("div",{children:[e.jsx("textarea",{value:l,onChange:m=>u(m.target.value),onKeyDown:p,onBlur:f,placeholder:"Add a note...",className:"w-full px-2 py-1.5 text-sm rounded border-0 resize-none focus:ring-2 focus:ring-blue-500",style:{background:"var(--ws-surface-1)",color:"var(--ws-text)"},rows:3}),e.jsxs("div",{className:"flex justify-end gap-2 mt-2",children:[e.jsx("button",{type:"button",onClick:()=>{i(!1),u(s?.note||"")},className:"px-2 py-1 text-xs",style:{color:"var(--ws-text-secondary)"},children:"Cancel"}),e.jsx("button",{type:"button",onClick:f,className:"px-2 py-1 text-xs rounded",style:{background:"var(--ws-accent)",color:"white"},children:"Save"})]})]}):e.jsx("div",{children:s?.note?e.jsx("button",{type:"button",className:"text-left text-sm cursor-pointer",style:{color:"var(--ws-text-secondary)"},onClick:()=>i(!0),children:s.note}):e.jsx("button",{type:"button",onClick:()=>i(!0),className:"text-sm italic",style:{color:"var(--ws-text-muted)"},children:"+ Add note..."})})}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-t",style:{borderColor:"var(--ws-border-subtle)"},children:[e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",onClick:()=>x(!h),className:`w-5 h-5 rounded-full ${y?.bg} ring-1`,style:{"--tw-ring-color":"var(--ws-border)"},title:"Change color"}),h&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>x(!1),onKeyDown:m=>m.key==="Escape"&&x(!1),role:"button",tabIndex:0,"aria-label":"Close color picker"}),e.jsx("div",{className:"absolute bottom-full left-0 mb-2 z-20 flex gap-1 p-1.5 rounded-lg shadow-lg border",style:{background:"var(--ws-surface-raised)",borderColor:"var(--ws-border)"},children:ge.map(({color:m,bg:g,ring:b})=>e.jsx("button",{type:"button",onClick:()=>{c(m),x(!1)},className:`w-5 h-5 rounded-full ${g} hover:ring-2 ${b} transition-all ${m===t.color?"ring-2":""}`,title:m},m))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[s&&e.jsx("button",{type:"button",onClick:r,className:"text-xs",style:{color:"var(--ws-text-muted)"},title:"Delete note",children:"Remove note"}),e.jsx("button",{type:"button",onClick:o,className:"p-1",style:{color:"var(--ws-text-muted)"},title:"Delete highlight",children:e.jsx($t,{className:"w-4 h-4"})})]})]})]})}function $t({className:t}){return e.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})}function Dt({items:t,onNavigate:s,onSaveTrail:n,canSaveTrail:r}){return t.length===0?null:e.jsxs("nav",{className:"flex items-center gap-1 px-4 py-2 border-b overflow-x-auto",style:{background:"var(--ws-surface-1)",borderColor:"var(--ws-border)"},"aria-label":"Breadcrumb",children:[e.jsxs("ol",{className:"flex items-center gap-1",children:[e.jsx("li",{children:e.jsx("button",{type:"button",onClick:()=>s({filePath:"",label:"Search",chunkIndex:void 0}),className:"transition-colors",style:{color:"var(--ws-text-muted)"},children:e.jsx(At,{})})}),t.map((o,c)=>e.jsxs(M.li,{initial:{opacity:0,x:-10},animate:{opacity:1,x:0},className:"flex items-center",children:[e.jsx("span",{className:"mx-1",style:{color:"var(--ws-text-muted)"},children:"/"}),o.connectionReason&&e.jsxs("span",{className:"text-xs italic mr-1",style:{color:"var(--ws-text-muted)"},children:['via "',o.connectionReason,'"']}),e.jsxs("button",{type:"button",onClick:()=>s(o),disabled:c===t.length-1,className:"text-sm truncate max-w-[150px] px-2 py-0.5 rounded transition-colors",style:c===t.length-1?{color:"var(--ws-text)",fontWeight:500,background:"var(--ws-surface-1)"}:{color:"var(--ws-text-secondary)"},title:`${o.label}${o.chunkIndex!==void 0?` #${o.chunkIndex}`:""}`,children:[o.label,o.chunkIndex!==void 0&&e.jsxs("span",{className:"ml-1",style:{color:"var(--ws-text-muted)"},children:["#",o.chunkIndex]})]})]},`${o.filePath}-${o.chunkIndex??"doc"}`))]}),n&&r&&t.length>1&&e.jsx(M.button,{initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1},type:"button",onClick:n,className:"ml-auto px-2 py-1 text-xs font-medium rounded transition-colors whitespace-nowrap",style:{color:"var(--ws-accent)"},children:"Save Trail"})]})}function At(){return e.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"})})}const Kt=[{color:"yellow",bg:"bg-yellow-300",ring:"ring-yellow-400"},{color:"green",bg:"bg-green-300",ring:"ring-green-400"},{color:"blue",bg:"bg-blue-300",ring:"ring-blue-400"},{color:"pink",bg:"bg-pink-300",ring:"ring-pink-400"},{color:"purple",bg:"bg-purple-300",ring:"ring-purple-400"}],Bt=[{action:"related",icon:"🔍",label:"Related",title:"Find related content in vault"},{action:"support",icon:"✓",label:"Support",title:"Find supporting evidence"},{action:"contradict",icon:"✗",label:"Contradict",title:"Find contradicting content"},{action:"compare",icon:"⚖️",label:"Compare",title:"Compare with other chunks"},{action:"pin",icon:"📌",label:"Pin",title:"Pin selection as note"}];function Ht({rect:t,onSelectColor:s,onClose:n,onSelectionAction:r,isActionLoading:o=!1,showMarginIndicator:c=!0}){const d=!!r,i=c&&!d,l=d?220:160,u=d?80:i?70:44,h=8,x=t.left+t.width/2-l/2,f=t.top-u-h+window.scrollY,p=Math.max(8,Math.min(x,window.innerWidth-l-8)),y=f<8?t.bottom+h+window.scrollY:f;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-50",onClick:n,onKeyDown:m=>m.key==="Escape"&&n(),role:"button",tabIndex:0,"aria-label":"Close popover"}),e.jsxs(M.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},exit:{opacity:0,y:4},transition:{duration:.1},className:"fixed z-50 rounded-lg shadow-xl border p-2",style:{background:"var(--ws-surface-raised)",borderColor:"var(--ws-border)",left:p,top:y,minWidth:l},children:[e.jsx("div",{className:"flex items-center justify-center gap-1 mb-1.5",children:Kt.map(({color:m,bg:g,ring:b})=>e.jsx("button",{type:"button",onClick:()=>s(m),className:`w-7 h-7 rounded-full ${g} hover:ring-2 ${b} transition-all`,title:`Highlight ${m}`},m))}),i&&e.jsx("div",{className:"flex items-center justify-center gap-1.5 pt-1.5 border-t",style:{borderColor:"var(--ws-border)"},children:e.jsxs("span",{className:"text-xs text-violet-600 dark:text-violet-400 flex items-center gap-1",children:[e.jsx(Pt,{className:"w-3 h-3"}),"See margin",e.jsx(Ft,{className:"w-3 h-3"})]})}),d&&e.jsx("div",{className:"flex items-center justify-center gap-1 pt-1.5 border-t",style:{borderColor:"var(--ws-border)"},children:Bt.map(({action:m,icon:g,title:b})=>e.jsx("button",{type:"button",onClick:()=>r(m),disabled:o,className:`
|
|
2
|
+
flex items-center justify-center w-8 h-8 rounded-md text-sm
|
|
3
|
+
transition-all
|
|
4
|
+
${o?"opacity-50 cursor-not-allowed":""}
|
|
5
|
+
`,title:b,children:g},m))})]})]})}function Pt({className:t}){return e.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"})})}function Ft({className:t}){return e.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})}const Wt={yellow:"bg-yellow-200 dark:bg-yellow-800/60",green:"bg-green-200 dark:bg-green-800/60",blue:"bg-blue-200 dark:bg-blue-800/60",pink:"bg-pink-200 dark:bg-pink-800/60",purple:"bg-purple-200 dark:bg-purple-800/60"},zt={yellow:"hover:bg-yellow-300 dark:hover:bg-yellow-700/60",green:"hover:bg-green-300 dark:hover:bg-green-700/60",blue:"hover:bg-blue-300 dark:hover:bg-blue-700/60",pink:"hover:bg-pink-300 dark:hover:bg-pink-700/60",purple:"hover:bg-purple-300 dark:hover:bg-purple-700/60"};function Vt(t,s,n){const r=new Set;r.add(0),r.add(t.length);const o=[...s,...n];for(const i of o)i.startOffset>=0&&i.startOffset<=t.length&&r.add(i.startOffset),i.endOffset>=0&&i.endOffset<=t.length&&r.add(i.endOffset);const c=Array.from(r).sort((i,l)=>i-l),d=[];for(let i=0;i<c.length-1;i++){const l=c[i],u=c[i+1];if(l>=u)continue;const h=o.filter(x=>x.startOffset<=l&&x.endOffset>=u);d.push({text:t.slice(l,u),types:h})}return d}function Gt(t){return t.map(s=>({startOffset:s.range.startOffset,endOffset:s.range.endOffset,type:"annotation",highlightId:s.id,color:s.color}))}function Ut(t,s,n){let r=0;const o=[];let c=0;for(const d of t)d.chunkIndex<s&&c++;for(const d of t){if(d.chunkIndex!==s)continue;const i=c+r;o.push({startOffset:d.startOffset,endOffset:d.endOffset,type:i===n?"search-current":"search-match"}),r++}return o}function _t({text:t,highlights:s,searchMatches:n=[],currentSearchIndex:r=-1,chunkIndex:o,onHighlightClick:c}){const d=a.useMemo(()=>Gt(s),[s]),i=a.useMemo(()=>Ut(n,o,r),[n,o,r]),l=a.useMemo(()=>Vt(t,d,i),[t,d,i]),u=a.useMemo(()=>{const h=new Map;for(const x of s)h.set(x.id,x);return h},[s]);return e.jsx("span",{className:"whitespace-pre-wrap",children:l.map((h,x)=>{const f=h.types.find(g=>g.type==="annotation"),p=h.types.find(g=>g.type==="search-current"),y=h.types.find(g=>g.type==="search-match"),m=["rounded","transition-colors"];if(f?.color&&(m.push(Wt[f.color]),m.push(zt[f.color]),m.push("cursor-pointer","px-0.5")),p&&(m.push("ring-2","ring-orange-500","dark:ring-orange-400","ring-offset-1","ring-offset-white"),f||m.push("bg-orange-100","dark:bg-orange-900/30")),y&&!p&&m.push("underline","decoration-dotted","decoration-orange-500","dark:decoration-orange-400","underline-offset-2"),f?.highlightId){const g=u.get(f.highlightId);return e.jsx("span",{className:m.join(" "),onClick:b=>{b.stopPropagation(),g&&c&&c(g)},onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),g&&c&&c(g))},role:"button",tabIndex:0,"data-highlight-id":f.highlightId,children:h.text},`highlight-${f.highlightId}-${x}`)}return p||y?e.jsx("span",{className:m.join(" "),"data-search-match":"true",children:h.text},`search-${x}-${h.text.length}`):e.jsx("span",{children:h.text},`text-${x}-${h.text.length}`)})})}function Qt({chunk:t,isActive:s,onRegister:n,onClick:r,showChunkNumbers:o=!0,highlights:c=[],onCreateHighlight:d,onHighlightClick:i,searchMatches:l=[],currentSearchIndex:u=-1,isBookmarked:h=!1,onSelectionAction:x,isSelectionActionLoading:f=!1}){const p=a.useRef(null),y=a.useRef(null),m=a.useRef(null),g=r?y:p,{selection:b,clearSelection:w}=jt({containerRef:m,chunkText:t.text,enabled:!!d}),k=a.useCallback($=>{b&&d&&(d({startOffset:b.startOffset,endOffset:b.endOffset},b.text,b.contextBefore,b.contextAfter,$),w())},[b,d,w]),T=a.useCallback($=>{b&&x&&(x($,{text:b.text,startOffset:b.startOffset,endOffset:b.endOffset,contextBefore:b.contextBefore,contextAfter:b.contextAfter}),$==="pin"&&w())},[b,x,w]);a.useEffect(()=>(n(t.chunkIndex,g.current),()=>{n(t.chunkIndex,null)}),[t.chunkIndex,n,g]);const K=e.jsx("div",{ref:m,children:c.length>0||l.length>0?e.jsx(_t,{text:t.text,highlights:c,searchMatches:l,currentSearchIndex:u,chunkIndex:t.chunkIndex,onHighlightClick:i}):e.jsx("span",{className:"whitespace-pre-wrap",children:t.text})}),D=e.jsxs(e.Fragment,{children:[o&&e.jsxs("div",{className:"absolute -left-1 top-5 flex items-center gap-1.5",children:[e.jsxs("span",{className:"book-chunk-badge",children:["§",t.chunkIndex]}),h&&e.jsx(Zt,{className:"w-3.5 h-3.5 text-amber-600 dark:text-amber-500"})]}),e.jsx("div",{className:"pl-8 pr-4 max-w-none book-text",style:{fontSize:"var(--reader-font-size, 1.05rem)",lineHeight:"var(--reader-line-height, 1.85)",fontFamily:"var(--reader-font-family, 'Georgia', 'Palatino Linotype', serif)"},children:K}),s&&e.jsx("div",{className:"absolute left-0 top-0 bottom-0 w-0.5 bg-amber-500/60 dark:bg-amber-600/50"}),e.jsx(A,{children:b&&d&&e.jsx(Ht,{rect:b.rect,onSelectColor:k,onClose:w,onSelectionAction:x?T:void 0,isActionLoading:f})})]}),B=`
|
|
6
|
+
book-page group relative py-6 px-8 mb-4 transition-all duration-200 text-left w-full
|
|
7
|
+
${s?"book-chunk-active":""}
|
|
8
|
+
`;return r?e.jsx("button",{ref:y,id:`chunk-${t.chunkIndex}`,type:"button",className:B,onClick:r,children:D}):e.jsx("div",{ref:p,id:`chunk-${t.chunkIndex}`,className:B,children:D})}function Zt({className:t}){return e.jsx("svg",{className:t,fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{d:"M5 4a2 2 0 012-2h6a2 2 0 012 2v14l-5-2.5L5 18V4z"})})}function Te({chunks:t,activeChunkIndex:s,onRegisterChunk:n,scrollToChunk:r,showChunkNumbers:o=!0,getHighlightsForChunk:c,onCreateHighlight:d,onHighlightClick:i,getSearchMatchesForChunk:l,currentSearchIndex:u=-1,isChunkBookmarked:h}){return a.useEffect(()=>{if(r!=null){const x=document.getElementById(`chunk-${r}`);x&&requestAnimationFrame(()=>{x.scrollIntoView({behavior:"smooth",block:"center"})})}},[r]),t.length===0?e.jsx("div",{className:"flex items-center justify-center h-64",style:{color:"var(--ws-text-muted)"},children:e.jsx("p",{children:"No content to display"})}):e.jsx("div",{className:"max-w-3xl mx-auto space-y-2",children:t.map(x=>{const f=c?.(x.chunkIndex)??[],p=l?.(x.chunkIndex)??[],y=h?.(x.chunkIndex)??!1;return e.jsx(Qt,{chunk:x,isActive:s===x.chunkIndex,onRegister:n,showChunkNumbers:o,highlights:f,onCreateHighlight:d?(m,g,b,w,k)=>d(x.chunkIndex,m,g,b,w,k):void 0,onHighlightClick:i,searchMatches:p,currentSearchIndex:u,isBookmarked:y},`${x.filePath}-${x.chunkIndex}`)})})}const Xt={hidden:{opacity:0,y:-15,rotate:-3,scale:.95},visible:t=>({opacity:1,y:0,rotate:-.3,scale:1,transition:{delay:t*.06,duration:.3,ease:"easeOut"}}),exit:{opacity:0,x:-20,transition:{duration:.15}}};function Yt(t){switch(t){case"backlink":return"zettel-backlink";case"forward":return"zettel-forward";case"semantic":return"zettel-semantic"}}function Jt(t){switch(t){case"backlink":return"Links here";case"forward":return"Links to";case"semantic":return"Related"}}function qt(t){const s=t.split(/[/\\]/);return s[s.length-1]||t}function ve(t){return`${Math.round((1-t)*100)}%`}function Y({filePath:t,chunkIndex:s,previewText:n,type:r,score:o,sharedKeywords:c=[],onNavigate:d,onPin:i,isPinned:l=!1,animationIndex:u=0}){const h=qt(t),x=Jt(r),f=Yt(r);return e.jsxs(M.button,{type:"button",onClick:d,custom:u,variants:Xt,initial:"hidden",animate:"visible",exit:"exit",className:`
|
|
9
|
+
zettel-slip ${f}
|
|
10
|
+
w-full text-left cursor-pointer
|
|
11
|
+
focus:outline-none focus:ring-2 focus:ring-amber-400 dark:focus:ring-amber-600
|
|
12
|
+
${l?"ring-2 ring-amber-500 dark:ring-amber-400":""}
|
|
13
|
+
`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0 flex-1",children:[e.jsx(es,{type:r}),e.jsx("span",{className:"text-xs font-medium text-stone-600 dark:text-stone-400 truncate font-serif",title:t,children:h}),e.jsxs("span",{className:"text-xs text-stone-400 dark:text-stone-500 font-mono",children:["#",s]})]}),o!==void 0&&e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-stone-200/50 dark:bg-stone-700/50 text-stone-600 dark:text-stone-400",title:`Similarity: ${ve(o)}`,children:ve(o)})]}),e.jsxs("p",{className:"text-sm text-stone-700 dark:text-stone-300 line-clamp-3 font-serif leading-relaxed",children:[n.slice(0,180),n.length>180&&"..."]}),c.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-2",children:c.slice(0,3).map(p=>e.jsx("span",{className:"px-1.5 py-0.5 text-xs bg-amber-100/60 dark:bg-amber-900/30 text-amber-700 dark:text-amber-400 rounded font-sans",children:p},p))}),e.jsxs("div",{className:"flex items-center justify-between mt-2 pt-1.5 border-t border-stone-200/50 dark:border-stone-700/50",children:[e.jsx("span",{className:"text-xs text-stone-500 dark:text-stone-400 italic",children:x}),e.jsx("div",{className:"flex items-center gap-1",children:i&&e.jsx("span",{role:"button",tabIndex:0,onClick:p=>{p.stopPropagation(),i()},onKeyDown:p=>{(p.key==="Enter"||p.key===" ")&&(p.stopPropagation(),p.preventDefault(),i())},className:`
|
|
14
|
+
p-1 rounded transition-colors
|
|
15
|
+
${l?"text-amber-600 dark:text-amber-400":"text-stone-400 hover:text-amber-500 dark:text-stone-500 dark:hover:text-amber-400"}
|
|
16
|
+
`,title:l?"Unpin":"Pin",children:e.jsx(ts,{className:"w-3.5 h-3.5"})})})]})]})}function es({type:t}){const s={backlink:"bg-blue-500",forward:"bg-emerald-500",semantic:"bg-violet-500"}[t];return e.jsx("span",{className:`w-2 h-2 rounded-full ${s} flex-shrink-0`,"aria-hidden":"true"})}function ts({className:t}){return e.jsx("svg",{className:t,fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{d:"M5 5a2 2 0 012-2h6a2 2 0 012 2v14l-5-2.5L5 19V5z"})})}function ss({message:t}){return e.jsxs(M.div,{initial:{opacity:0},animate:{opacity:1},className:"text-center py-6 text-stone-500 dark:text-stone-400",children:[e.jsx(ns,{}),e.jsx("p",{className:"mt-2 text-sm font-serif italic",children:t})]})}function ns(){return e.jsx("svg",{className:"mx-auto h-10 w-10 text-stone-300 dark:text-stone-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}function Q({title:t,count:s,icon:n}){return e.jsxs("div",{className:"flex items-center gap-2 px-1 py-2",children:[n&&e.jsx("span",{className:"text-stone-400 dark:text-stone-500",children:n}),e.jsx("h4",{className:"text-xs font-semibold text-stone-600 dark:text-stone-400 uppercase tracking-wide font-sans",children:t}),s!==void 0&&s>0&&e.jsxs("span",{className:"text-xs text-stone-400 dark:text-stone-500",children:["(",s,")"]})]})}function ye(){return e.jsxs("div",{className:"zettel-slip zettel-semantic animate-pulse",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-stone-300 dark:bg-stone-600"}),e.jsx("div",{className:"h-3 w-24 bg-stone-300 dark:bg-stone-600 rounded"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-3 w-full bg-stone-200 dark:bg-stone-700 rounded"}),e.jsx("div",{className:"h-3 w-4/5 bg-stone-200 dark:bg-stone-700 rounded"}),e.jsx("div",{className:"h-3 w-2/3 bg-stone-200 dark:bg-stone-700 rounded"})]})]})}function ke(t,s,n){return[...t].sort((r,o)=>{const c=s(r)===n,d=s(o)===n;if(c!==d)return c?-1:1;const i=!!r.label,l=!!o.label;return i!==l?i?-1:1:new Date(o.createdAt).getTime()-new Date(r.createdAt).getTime()})}function rs({relatedChunks:t,isLoading:s,activeChunkIndex:n,currentFilePath:r,onNavigateToChunk:o,pinnedChunkKeys:c,onTogglePin:d,highlights:i=[],annotations:l=new Map,onUpdateNote:u,onDeleteNote:h,onDeleteHighlight:x,onChangeHighlightColor:f,backlinks:p=[],outgoingLinks:y=[],autoSelectionResults:m=[],isAutoSearching:g=!1,selectionText:b=null}){const w=t.filter(v=>v.score<.7),k=i.length>0,T=p.length>0,K=y.length>0,D=m.length>0||g,B=a.useMemo(()=>ke(p,v=>v.sourceKey.filePath,r),[p,r]),$=a.useMemo(()=>ke(y,v=>v.targetKey.filePath,r),[y,r]);return e.jsxs("div",{className:"h-full flex flex-col zettel-margin",children:[e.jsxs("div",{className:"zettel-header flex items-center justify-between",children:[e.jsxs("h3",{className:"text-sm font-semibold text-stone-700 dark:text-stone-300 font-serif",children:["Connections",n!==null&&e.jsxs("span",{className:"ml-2 text-stone-400 dark:text-stone-500 font-mono text-xs",children:["#",n]})]}),s&&e.jsx(J,{className:"w-4 h-4 text-stone-400"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-3 space-y-4",children:[k&&e.jsxs("div",{className:"border-b border-stone-200/50 dark:border-stone-700/50 pb-4",children:[e.jsx(Q,{title:"Notes",count:i.length,icon:e.jsx(as,{className:"w-3.5 h-3.5"})}),e.jsx("div",{className:"space-y-3 mt-2",children:e.jsx(A,{mode:"popLayout",children:i.map(v=>e.jsx(Et,{highlight:v,annotation:l.get(v.id),onUpdateNote:j=>u?.(v.id,j),onDeleteNote:()=>{const j=l.get(v.id);j&&h?.(j.id)},onDeleteHighlight:()=>x?.(v.id),onChangeColor:j=>f?.(v.id,j)},v.id))})})]}),D&&e.jsxs("div",{className:"border-b border-stone-200/50 dark:border-stone-700/50 pb-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx(Q,{title:"From Selection",count:m.length,icon:e.jsx(is,{className:"w-3.5 h-3.5"})}),b&&e.jsxs("span",{className:"zettel-selection-pill truncate max-w-[150px]",title:b,children:['"',b.slice(0,30),b.length>30?"...":"",'"']})]}),e.jsx("div",{className:"space-y-2 mt-2",children:g?e.jsxs("div",{className:"zettel-searching",children:[e.jsx(J,{className:"w-4 h-4 text-violet-500"}),e.jsx("span",{className:"text-xs text-violet-600 dark:text-violet-400 font-serif italic",children:"Finding connections..."})]}):m.length===0?e.jsx("p",{className:"text-xs text-stone-500 dark:text-stone-400 italic font-serif py-2",children:"No related content found"}):e.jsx(A,{mode:"popLayout",children:m.map((v,j)=>e.jsx(Y,{filePath:v.filePath,chunkIndex:v.chunkIndex,previewText:v.text,type:"semantic",score:v.score,onNavigate:()=>o(v.filePath,v.chunkIndex),onPin:d?()=>d(v.filePath,v.chunkIndex):void 0,isPinned:c?.has(`${v.filePath}:${v.chunkIndex}`)??!1,animationIndex:j},`${v.filePath}:${v.chunkIndex}`))})})]}),T&&e.jsxs("div",{className:"border-b border-stone-200/50 dark:border-stone-700/50 pb-4",children:[e.jsx(Q,{title:"Links Here",count:B.length,icon:e.jsx(ls,{className:"w-3.5 h-3.5"})}),e.jsx("div",{className:"space-y-2 mt-2",children:e.jsx(A,{mode:"popLayout",children:B.map((v,j)=>e.jsx(Y,{filePath:v.sourceKey.filePath,chunkIndex:v.sourceKey.chunkIndex,previewText:v.sourceText||"No preview available",type:"backlink",sharedKeywords:v.label?[v.label]:void 0,onNavigate:()=>o(v.sourceKey.filePath,v.sourceKey.chunkIndex),animationIndex:j},v.id))})})]}),K&&e.jsxs("div",{className:"border-b border-stone-200/50 dark:border-stone-700/50 pb-4",children:[e.jsx(Q,{title:"Links From",count:$.length,icon:e.jsx(cs,{className:"w-3.5 h-3.5"})}),e.jsx("div",{className:"space-y-2 mt-2",children:e.jsx(A,{mode:"popLayout",children:$.map((v,j)=>e.jsx(Y,{filePath:v.targetKey.filePath,chunkIndex:v.targetKey.chunkIndex,previewText:v.targetText||"No preview available",type:"forward",sharedKeywords:v.label?[v.label]:void 0,onNavigate:()=>o(v.targetKey.filePath,v.targetKey.chunkIndex),animationIndex:j},v.id))})})]}),e.jsxs("div",{children:[e.jsx(Q,{title:"Suggested",count:w.length,icon:e.jsx(os,{className:"w-3.5 h-3.5"})}),e.jsx("div",{className:"space-y-2 mt-2",children:e.jsx(A,{mode:"popLayout",children:w.length===0&&!s?e.jsx(ss,{message:n!==null?"No related content found":"Scroll to see related content"}):s&&w.length===0?e.jsxs(e.Fragment,{children:[e.jsx(ye,{}),e.jsx(ye,{})]}):w.map((v,j)=>{const C=`${v.filePath}:${v.chunkIndex}`,E=c?.has(C)??!1;return e.jsx(Y,{filePath:v.filePath,chunkIndex:v.chunkIndex,previewText:v.text,type:"semantic",score:v.score,sharedKeywords:v.explanation?.sharedKeywords,onNavigate:()=>o(v.filePath,v.chunkIndex),onPin:d?()=>d(v.filePath,v.chunkIndex):void 0,isPinned:E,animationIndex:j},C)})})})]})]})]})}function as({className:t}){return e.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})})}function os({className:t}){return e.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"})})}function ls({className:t}){return e.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 19l-7-7 7-7m8 14l-7-7 7-7"})})}function cs({className:t}){return e.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 5l7 7-7 7M5 5l7 7-7 7"})})}function is({className:t}){return e.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 9l4-4 4 4m0 6l-4 4-4-4"})})}function ds({isOpen:t,onToggle:s,filePath:n,activeChunkIndex:r,relatedChunks:o,pins:c,onNavigateToChunk:d}){const{graphData:i,currentNodeId:l}=lt({filePath:n,activeChunkIndex:r,relatedChunks:o,pins:c}),u=a.useMemo(()=>{const x=new Set;for(const f of c)x.add(`${f.sourceKey.filePath}:${f.sourceKey.chunkIndex}`),x.add(`${f.targetKey.filePath}:${f.targetKey.chunkIndex}`);return x},[c]),h=x=>{d(x.filePath,x.chunkIndex)};return e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:s,className:"flex items-center gap-2 px-3 py-1.5 text-sm font-medium rounded-lg transition-colors",style:{color:"var(--ws-text-secondary)"},title:t?"Hide knowledge graph":"Show knowledge graph",children:[e.jsx(we,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Graph"}),i.nodes.length>0&&e.jsxs("span",{className:"text-xs",style:{color:"var(--ws-text-muted)"},children:["(",i.nodes.length,")"]})]}),e.jsx(A,{children:t&&e.jsx(M.div,{initial:{height:0,opacity:0},animate:{height:300,opacity:1},exit:{height:0,opacity:0},transition:{duration:.2},className:"absolute bottom-0 left-0 right-0 z-30 border-t overflow-hidden",style:{borderColor:"var(--ws-border)",background:"var(--ws-surface-raised)"},children:e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b",style:{borderColor:"var(--ws-border)",background:"var(--ws-surface-1)"},children:[e.jsxs("h3",{className:"text-sm font-medium",style:{color:"var(--ws-text-secondary)"},children:["Knowledge Graph",r!==null&&e.jsxs("span",{className:"ml-2",style:{color:"var(--ws-text-muted)"},children:["(centered on #",r,")"]})]}),e.jsx("button",{type:"button",onClick:s,className:"p-1 rounded",style:{color:"var(--ws-text-muted)"},children:e.jsx(us,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"flex-1 p-2",children:i.nodes.length===0?e.jsx("div",{className:"h-full flex items-center justify-center",style:{color:"var(--ws-text-muted)"},children:e.jsxs("div",{className:"text-center",children:[e.jsx(we,{className:"w-10 h-10 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No graph data available"}),e.jsx("p",{className:"text-xs mt-1",children:"Scroll through the document to load related content"})]})}):e.jsx(ct,{graphData:i,currentNodeId:l,pinnedNodeIds:u,onNodeClick:h})})]})})})]})}function we({className:t}){return e.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})})}function us({className:t}){return e.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}const xs=[{key:"j",description:"Navigate to next chunk"},{key:"k",description:"Navigate to previous chunk"},{key:"Space",description:"Toggle split view"},{key:"p",description:"Pin top margin suggestion"},{key:"/",description:"Open search"},{key:"?",description:"Show keyboard shortcuts"},{key:"Esc",description:"Close overlays"}];function hs({isOpen:t,onClose:s}){return e.jsx(A,{children:t&&e.jsxs(e.Fragment,{children:[e.jsx(M.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm",onClick:s}),e.jsx(M.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},transition:{duration:.15},className:"fixed inset-0 z-50 flex items-center justify-center p-4",onClick:n=>n.target===n.currentTarget&&s(),children:e.jsxs("div",{className:"w-full max-w-md rounded-xl shadow-2xl overflow-hidden",style:{background:"var(--ws-surface-raised)"},children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b",style:{borderColor:"var(--ws-border)"},children:[e.jsx("h2",{className:"text-lg font-semibold",style:{color:"var(--ws-text)"},children:"Keyboard Shortcuts"}),e.jsx("button",{type:"button",onClick:s,className:"p-1 rounded-lg transition-colors",style:{color:"var(--ws-text-muted)"},children:e.jsx(ms,{className:"w-5 h-5"})})]}),e.jsx("div",{className:"p-4",children:e.jsx("table",{className:"w-full",children:e.jsx("tbody",{className:"divide-y",style:{borderColor:"var(--ws-border-subtle)"},children:xs.map(n=>e.jsxs("tr",{className:"group",children:[e.jsx("td",{className:"py-2.5 pr-4",children:e.jsx("kbd",{className:"inline-flex items-center justify-center min-w-[2rem] px-2 py-1 text-sm font-mono font-semibold border rounded shadow-sm",style:{color:"var(--ws-text-secondary)",background:"var(--ws-surface-1)",borderColor:"var(--ws-border)"},children:n.key})}),e.jsx("td",{className:"py-2.5 text-sm",style:{color:"var(--ws-text-secondary)"},children:n.description})]},n.key))})})}),e.jsx("div",{className:"px-6 py-3 border-t",style:{background:"var(--ws-surface-1)",borderColor:"var(--ws-border)"},children:e.jsx("p",{className:"text-xs text-center",style:{color:"var(--ws-text-muted)"},children:"Shortcuts are disabled when typing in inputs or selecting text"})})]})})]})})}function ms({className:t}){return e.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}function fs({isOpen:t,onClose:s}){const{settings:n,setFontSize:r,setLineHeight:o,setFontFamily:c,setShowChunkNumbers:d,setShowHeatmap:i,resetSettings:l}=je();return e.jsx(A,{children:t&&e.jsxs(e.Fragment,{children:[e.jsx(M.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-40",onClick:s}),e.jsx(M.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},transition:{duration:.15},className:"absolute right-0 top-full mt-2 z-50 w-72 rounded-lg shadow-xl border p-4",style:{background:"var(--ws-surface-raised)",borderColor:"var(--ws-border)"},children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("span",{className:"block text-xs font-medium mb-2",style:{color:"var(--ws-text-secondary)"},children:"Font Size"}),e.jsx("div",{className:"flex gap-1",role:"group","aria-label":"Font size",children:["sm","base","lg","xl"].map(u=>e.jsxs("button",{type:"button",onClick:()=>r(u),className:"flex-1 px-2 py-1.5 text-sm rounded-md transition-colors",style:n.fontSize===u?{background:"var(--ws-accent-subtle)",color:"var(--ws-accent)",fontWeight:500}:{background:"var(--ws-surface-1)",color:"var(--ws-text-secondary)"},children:[u==="sm"&&"S",u==="base"&&"M",u==="lg"&&"L",u==="xl"&&"XL"]},u))})]}),e.jsxs("div",{children:[e.jsx("span",{className:"block text-xs font-medium mb-2",style:{color:"var(--ws-text-secondary)"},children:"Line Spacing"}),e.jsx("div",{className:"flex gap-1",role:"group","aria-label":"Line spacing",children:["tight","normal","relaxed"].map(u=>e.jsx("button",{type:"button",onClick:()=>o(u),className:"flex-1 px-2 py-1.5 text-sm rounded-md transition-colors capitalize",style:n.lineHeight===u?{background:"var(--ws-accent-subtle)",color:"var(--ws-accent)",fontWeight:500}:{background:"var(--ws-surface-1)",color:"var(--ws-text-secondary)"},children:u},u))})]}),e.jsx("div",{children:e.jsxs("label",{className:"block text-xs font-medium mb-2",style:{color:"var(--ws-text-secondary)"},children:["Font",e.jsxs("select",{value:n.fontFamily,onChange:u=>c(u.target.value),className:"mt-1 w-full px-3 py-2 text-sm border-0 rounded-md focus:ring-2 focus:ring-blue-500",style:{background:"var(--ws-surface-1)",color:"var(--ws-text-secondary)"},children:[e.jsx("option",{value:"sans",children:"Sans-serif"}),e.jsx("option",{value:"serif",children:"Serif"}),e.jsx("option",{value:"mono",children:"Monospace"})]})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm",style:{color:"var(--ws-text-secondary)"},children:"Show chunk numbers"}),e.jsx("button",{type:"button",onClick:()=>d(!n.showChunkNumbers),className:"relative inline-flex h-6 w-11 items-center rounded-full transition-colors",style:{background:n.showChunkNumbers?"var(--ws-accent)":"var(--ws-surface-2)"},children:e.jsx("span",{className:`
|
|
17
|
+
inline-block h-4 w-4 transform rounded-full bg-white transition-transform
|
|
18
|
+
${n.showChunkNumbers?"translate-x-6":"translate-x-1"}
|
|
19
|
+
`})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("span",{className:"text-sm",style:{color:"var(--ws-text-secondary)"},children:"Semantic heatmap"}),e.jsx("p",{className:"text-xs",style:{color:"var(--ws-text-muted)"},children:"Highlight connected terms"})]}),e.jsx("button",{type:"button",onClick:()=>i(!n.showHeatmap),className:"relative inline-flex h-6 w-11 items-center rounded-full transition-colors",style:{background:n.showHeatmap?"var(--ws-accent)":"var(--ws-surface-2)"},children:e.jsx("span",{className:`
|
|
20
|
+
inline-block h-4 w-4 transform rounded-full bg-white transition-transform
|
|
21
|
+
${n.showHeatmap?"translate-x-6":"translate-x-1"}
|
|
22
|
+
`})})]}),e.jsx("div",{className:"pt-2 border-t",style:{borderColor:"var(--ws-border)"},children:e.jsx("button",{type:"button",onClick:l,className:"w-full px-3 py-1.5 text-sm rounded-md transition-colors",style:{color:"var(--ws-text-secondary)"},children:"Reset to defaults"})})]})})]})})}function ps({onClick:t}){return e.jsxs("button",{type:"button",onClick:t,className:"flex items-center gap-2 px-3 py-1.5 text-sm font-medium rounded-lg transition-colors",style:{color:"var(--ws-text-secondary)"},title:"Reader settings",children:[e.jsx(bs,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Display"})]})}function bs({className:t}){return e.jsxs("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})}function gs({isOpen:t,query:s,matches:n,currentIndex:r,caseSensitive:o,onQueryChange:c,onToggleCaseSensitive:d,onNextMatch:i,onPreviousMatch:l,onGoToMatch:u,onClose:h}){const x=a.useRef(null),f=a.useRef(null);a.useEffect(()=>{t&&requestAnimationFrame(()=>{x.current?.focus(),x.current?.select()})},[t]),a.useEffect(()=>{r>=0&&f.current&&f.current.querySelector(`[data-result-index="${r}"]`)?.scrollIntoView({block:"nearest",behavior:"smooth"})},[r]);const p=a.useCallback(y=>{switch(y.key){case"Escape":y.preventDefault(),h();break;case"Enter":y.preventDefault(),y.shiftKey?l():i();break;case"n":y.target!==x.current&&(y.preventDefault(),y.shiftKey?l():i());break;case"N":y.target!==x.current&&(y.preventDefault(),l());break}},[h,i,l]);return e.jsx(A,{children:t&&e.jsx(M.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},transition:{duration:.15},className:"fixed top-16 left-1/2 -translate-x-1/2 z-50 w-full max-w-lg px-4",onKeyDown:p,children:e.jsxs("div",{className:"rounded-xl shadow-2xl border overflow-hidden",style:{background:"var(--ws-surface-raised)",borderColor:"var(--ws-border)"},children:[e.jsxs("div",{className:"flex items-center gap-2 p-3 border-b",style:{borderColor:"var(--ws-border)"},children:[e.jsx("span",{style:{color:"var(--ws-text-muted)"},children:e.jsx(ys,{className:"w-5 h-5 flex-shrink-0"})}),e.jsx("input",{ref:x,type:"text",value:s,onChange:y=>c(y.target.value),placeholder:"Search in document...",className:"flex-1 bg-transparent placeholder-gray-400 focus:outline-none text-base",style:{color:"var(--ws-text)"}}),n.length>0&&e.jsxs("span",{className:"text-sm whitespace-nowrap px-2",style:{color:"var(--ws-text-muted)"},children:[r+1,"/",n.length]}),e.jsx("button",{type:"button",onClick:d,className:"p-1.5 rounded text-sm font-medium transition-colors",style:o?{background:"var(--ws-accent-subtle)",color:"var(--ws-accent)"}:{color:"var(--ws-text-muted)"},title:"Case sensitive (Aa)",children:"Aa"}),e.jsxs("div",{className:"flex items-center gap-1 border-l pl-2",style:{borderColor:"var(--ws-border)"},children:[e.jsx("button",{type:"button",onClick:l,disabled:n.length===0,className:"p-1 disabled:opacity-30 disabled:cursor-not-allowed rounded transition-colors",style:{color:"var(--ws-text-muted)"},title:"Previous match (N)",children:e.jsx(ks,{className:"w-4 h-4"})}),e.jsx("button",{type:"button",onClick:i,disabled:n.length===0,className:"p-1 disabled:opacity-30 disabled:cursor-not-allowed rounded transition-colors",style:{color:"var(--ws-text-muted)"},title:"Next match (n)",children:e.jsx(ws,{className:"w-4 h-4"})})]}),e.jsx("button",{type:"button",onClick:h,className:"p-1 rounded transition-colors",style:{color:"var(--ws-text-muted)"},title:"Close (Esc)",children:e.jsx(js,{className:"w-4 h-4"})})]}),s.length>0&&e.jsx("div",{ref:f,className:"max-h-64 overflow-y-auto",children:n.length===0?e.jsx("div",{className:"px-4 py-6 text-center",style:{color:"var(--ws-text-muted)"},children:e.jsx("p",{className:"text-sm",children:"No matches found"})}):e.jsxs("div",{className:"py-1",children:[n.slice(0,50).map((y,m)=>e.jsxs("button",{"data-result-index":m,type:"button",onClick:()=>u(m),className:`w-full text-left px-4 py-2 transition-colors ${m===r?"border-l-2":""}`,style:m===r?{background:"var(--ws-accent-subtle)",borderColor:"var(--ws-accent)"}:{},children:[e.jsx("div",{className:"flex items-center gap-2 mb-0.5",children:e.jsxs("span",{className:"text-xs font-medium",style:{color:"var(--ws-text-muted)"},children:["Chunk #",y.chunkIndex]})}),e.jsx("p",{className:"text-sm line-clamp-2",style:{color:"var(--ws-text-secondary)"},children:vs(y.context,s,o)})]},`${y.chunkIndex}-${y.startOffset}`)),n.length>50&&e.jsxs("div",{className:"px-4 py-2 text-xs text-center border-t",style:{color:"var(--ws-text-muted)",borderColor:"var(--ws-border)"},children:["Showing first 50 of ",n.length," matches"]})]})}),s.length===0&&e.jsxs("div",{className:"px-4 py-3 text-xs",style:{color:"var(--ws-text-muted)",background:"var(--ws-surface-1)"},children:[e.jsxs("span",{className:"mr-4",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 rounded",style:{background:"var(--ws-surface-2)",color:"var(--ws-text-secondary)"},children:"Enter"})," ","next"]}),e.jsxs("span",{className:"mr-4",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 rounded",style:{background:"var(--ws-surface-2)",color:"var(--ws-text-secondary)"},children:"Shift+Enter"})," ","previous"]}),e.jsxs("span",{children:[e.jsx("kbd",{className:"px-1.5 py-0.5 rounded",style:{background:"var(--ws-surface-2)",color:"var(--ws-text-secondary)"},children:"Esc"})," ","close"]})]})]})})})}function vs(t,s,n){if(!s)return t;const r=n?s:s.toLowerCase(),c=(n?t:t.toLowerCase()).indexOf(r);if(c===-1)return t;const d=t.slice(0,c),i=t.slice(c,c+s.length),l=t.slice(c+s.length);return e.jsxs(e.Fragment,{children:[d,e.jsx("mark",{className:"bg-orange-200 dark:bg-orange-800/60 rounded px-0.5",children:i}),l]})}function ys({className:t}){return e.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})}function ks({className:t}){return e.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}function ws({className:t}){return e.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}function js({className:t}){return e.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}function Ns({filePath:t,chunkIndex:s,onClose:n,onNavigate:r}){const{chunks:o,isLoading:c,error:d}=Ce(t),i=Cs(t);return e.jsxs(M.div,{initial:{opacity:0,x:50},animate:{opacity:1,x:0},exit:{opacity:0,x:50},className:"h-full flex flex-col border-l",style:{background:"var(--ws-surface-raised)",borderColor:"var(--ws-border)"},children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b",style:{borderColor:"var(--ws-border)",background:"var(--ws-surface-1)"},children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-sm font-medium truncate",style:{color:"var(--ws-text)"},title:t,children:i}),e.jsxs("p",{className:"text-xs",style:{color:"var(--ws-text-muted)"},children:[o.length," chunks · Viewing #",s]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[e.jsx("button",{type:"button",onClick:()=>r(t,s),className:"px-3 py-1.5 text-sm font-medium rounded-lg transition-colors",style:{color:"var(--ws-accent)"},children:"Open Full"}),e.jsx("button",{type:"button",onClick:n,className:"p-1.5 rounded-lg transition-colors",style:{color:"var(--ws-text-muted)"},"aria-label":"Close split view",children:e.jsx(Is,{})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:c?e.jsxs("div",{className:"flex items-center justify-center h-32",children:[e.jsx(J,{className:"w-6 h-6",style:{color:"var(--ws-text-muted)"}}),e.jsx("span",{className:"ml-2",style:{color:"var(--ws-text-muted)"},children:"Loading document..."})]}):d?e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 text-red-700 dark:text-red-400",children:[e.jsx("p",{className:"font-medium",children:"Error loading document"}),e.jsx("p",{className:"text-sm mt-1",children:d.message})]}):e.jsx(Te,{chunks:o,activeChunkIndex:s,onRegisterChunk:()=>{},scrollToChunk:s})})]})}function Cs(t){const s=t.split(/[/\\]/);return s[s.length-1]||t}function Is(){return e.jsx("svg",{className:"h-5 w-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}function Ss({entries:t,activeChunkIndex:s,onNavigateToChunk:n,isOpen:r,onToggle:o,isFallback:c=!1}){const d=t.findIndex((l,u)=>{const h=t[u+1];return h?l.chunkIndex<=(s??0)&&h.chunkIndex>(s??0):l.chunkIndex<=(s??0)}),i=a.useCallback(l=>{n(l.chunkIndex)},[n]);return e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:o,className:"flex items-center gap-2 px-3 py-1.5 text-sm font-medium rounded-lg transition-colors",style:{color:"var(--ws-text-secondary)"},title:r?"Hide table of contents":"Show table of contents",children:[e.jsx(Ts,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Contents"}),e.jsx(M.span,{animate:{rotate:r?180:0},transition:{duration:.2},children:e.jsx(Os,{className:"w-3 h-3"})})]}),e.jsx(A,{children:r&&e.jsx(M.div,{initial:{width:0,opacity:0},animate:{width:240,opacity:1},exit:{width:0,opacity:0},transition:{duration:.2},className:"fixed left-0 top-16 bottom-0 z-40 border-r shadow-lg overflow-hidden",style:{background:"var(--ws-surface-raised)",borderColor:"var(--ws-border)"},children:e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b",style:{borderColor:"var(--ws-border)"},children:[e.jsx("h3",{className:"text-sm font-semibold",style:{color:"var(--ws-text)"},children:"Table of Contents"}),c&&e.jsx("span",{className:"text-xs",style:{color:"var(--ws-text-muted)"},children:"(auto)"})]}),e.jsx("div",{className:"flex-1 overflow-y-auto py-2",children:t.length===0?e.jsx("div",{className:"px-4 py-8 text-center",style:{color:"var(--ws-text-muted)"},children:e.jsx("p",{className:"text-sm",children:"No headings detected"})}):e.jsx("nav",{className:"space-y-0.5",children:t.map((l,u)=>e.jsx(Ls,{entry:l,isCurrent:u===d,onClick:()=>i(l)},l.id))})})]})})})]})}function Ls({entry:t,isCurrent:s,onClick:n}){const r=16+(t.level-1)*12;return e.jsxs("button",{type:"button",onClick:n,className:`
|
|
23
|
+
w-full text-left px-4 py-1.5 text-sm transition-colors border-l-2
|
|
24
|
+
${s?"font-medium":"border-transparent"}
|
|
25
|
+
`,style:s?{background:"var(--ws-accent-subtle)",color:"var(--ws-accent)",borderColor:"var(--ws-accent)",paddingLeft:r}:{color:"var(--ws-text-secondary)",paddingLeft:r},children:[e.jsx("span",{className:"line-clamp-2",children:t.text}),t.type==="allcaps"&&e.jsx("span",{className:"ml-1 text-xs",style:{color:"var(--ws-text-muted)"},children:t.chunkIndex})]})}function Ts({className:t}){return e.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 10h16M4 14h16M4 18h16"})})}function Os({className:t}){return e.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}function Ms({filePath:t,initialChunkIndex:s,onNavigate:n,onGoHome:r,pinnedChunkKeys:o,onTogglePin:c,onSaveTrail:d}){const[i,l]=a.useState(null),[u,h]=a.useState(()=>{const N=oe(t);return[{filePath:t,chunkIndex:s,label:N}]}),[x,f]=a.useState(!1),[p,y]=a.useState(!1),[m,g]=a.useState(!1),[b,w]=a.useState(!1),[k,T]=a.useState(null),K=a.useRef(null),{settings:D,cssVariables:B}=je(),{pins:$,getBacklinks:v,getPinsFromChunk:j}=Ne(),{chunks:C,isLoading:E,error:V}=Ce(t),{visibleChunkIndices:q,registerChunk:Z,activeChunkIndex:L}=ht("100px"),{relatedChunks:G,isLoading:U}=mt(t,q,300,5),{results:I,isSearching:R,searchedText:S}=Rt({selectionText:k,filePath:t,chunkIndex:L??0,enabled:!i});a.useEffect(()=>{const N=()=>{const P=window.getSelection();if(!P||P.isCollapsed||!P.rangeCount){T(null);return}const X=P.toString().trim();X.length>=10?T(X):T(null)};let O;const H=()=>{clearTimeout(O),O=setTimeout(N,150)};return document.addEventListener("selectionchange",H),()=>{document.removeEventListener("selectionchange",H),clearTimeout(O)}},[]);const{entries:W,isFallback:Re}=it({chunks:C}),ee=a.useCallback(N=>{const O=document.getElementById(`chunk-${N}`);O&&O.scrollIntoView({behavior:"smooth",block:"center"})},[]),{searchState:_,isSearchOpen:te,openSearch:Ee,closeSearch:se,setQuery:$e,toggleCaseSensitive:De,nextMatch:ce,previousMatch:ie,goToMatch:Ae,getMatchesForChunk:Ke}=Ct({chunks:C,onNavigateToChunk:ee}),{restorePosition:de,hasSavedPosition:Be}=yt({filePath:t,chunks:C,activeChunkIndex:L}),He=a.useMemo(()=>L!==null?{filePath:t,chunkIndex:L}:null,[t,L]),{highlights:ne,annotations:re,createHighlight:ue,deleteHighlight:Pe,updateHighlightColor:Fe,addNote:xe,updateNote:he,deleteNote:We}=kt(He),ze=a.useCallback(N=>N===L?ne:[],[L,ne]),Ve=a.useCallback((N,O,H,P,X,tt)=>{N===L&&ue(O,H,P,X,tt)},[L,ue]),Ge=a.useCallback(N=>{},[]),Ue=a.useCallback((N,O)=>{const H=re.get(N);H?he(H.id,O):xe(N,O)},[re,he,xe]),me=a.useRef(!1);a.useEffect(()=>{if(C.length>0&&!me.current&&!s){me.current=!0;const N=de();N&&requestAnimationFrame(()=>{const O=document.getElementById(`chunk-${N.chunkIndex}`);O&&O.scrollIntoView({behavior:"auto",block:"start"})})}},[C,de,s]);const F=a.useMemo(()=>{if(L===null)return[];const N=`${t}:${L}`;return G[N]||[]},[t,L,G]),ae=a.useCallback((N,O)=>{const H=F.find(P=>P.filePath===N&&P.chunkIndex===O);h(P=>[...P,{filePath:N,chunkIndex:O,label:oe(N),connectionReason:H?.connectionReason}]),n(N,O)},[F,n]),fe=a.useCallback((N,O)=>{l({filePath:N,chunkIndex:O})},[]),_e=a.useCallback(N=>{if(!N.filePath){r();return}const O=u.findIndex(H=>H.filePath===N.filePath&&H.chunkIndex===N.chunkIndex);O!==-1&&h(H=>H.slice(0,O+1)),n(N.filePath,N.chunkIndex)},[u,n,r]),Qe=m||te||p,Ze=a.useMemo(()=>L===null?[]:v({filePath:t,chunkIndex:L}),[t,L,v]),Xe=a.useMemo(()=>L===null?[]:j({filePath:t,chunkIndex:L}),[t,L,j]),Ye=a.useCallback(()=>{if(F.length>0&&c){const N=F[0];N&&c(N.filePath,N.chunkIndex)}},[F,c]),Je=a.useCallback(()=>{if(i)l(null);else if(F.length>0){const N=F[0];N&&fe(N.filePath,N.chunkIndex)}},[i,F,fe]),qe=a.useCallback(()=>{g(!1),se(),y(!1)},[se]);gt({totalChunks:C.length,activeChunkIndex:L,onNavigateToChunk:ee,onToggleSplit:Je,onPinTopSuggestion:Ye,onOpenSearch:Ee,onOpenHelp:()=>g(!0),onCloseOverlay:qe,isOverlayOpen:Qe,enabled:!0,isSearchOpen:te,onNextSearchMatch:ce,onPreviousSearchMatch:ie});const et=oe(t);return e.jsxs("div",{className:"h-full flex flex-col",style:B,children:[e.jsx(Dt,{items:u,onNavigate:_e,onSaveTrail:d,canSaveTrail:u.length>1}),e.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[x&&e.jsx("div",{className:"w-60 flex-shrink-0"}),e.jsxs("div",{className:`
|
|
26
|
+
flex flex-col overflow-hidden transition-all duration-300
|
|
27
|
+
${i?"w-[40%]":"w-[60%]"}
|
|
28
|
+
`,children:[e.jsxs("div",{className:"book-header flex items-center justify-between px-6 py-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(Ss,{entries:W,activeChunkIndex:L,onNavigateToChunk:ee,isOpen:x,onToggle:()=>f(!x),isFallback:Re}),e.jsxs("div",{children:[e.jsx("h2",{className:"book-title text-xl truncate",title:t,children:et}),e.jsxs("p",{className:"text-sm text-stone-500 dark:text-stone-400 font-serif",children:[C.length," passages",L!==null&&` · §${L}`,Be&&!s&&e.jsx("span",{className:"ml-2 text-amber-600 dark:text-amber-500",children:"· Restored"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 relative",children:[e.jsx(ds,{isOpen:b,onToggle:()=>w(!b),filePath:t,activeChunkIndex:L,relatedChunks:F,pins:$,onNavigateToChunk:ae}),e.jsx("button",{type:"button",onClick:()=>g(!0),className:"p-2 rounded-lg transition-colors",style:{color:"var(--ws-text-muted)"},title:"Keyboard shortcuts (?)",children:e.jsx(Rs,{className:"w-4 h-4"})}),e.jsx(ps,{onClick:()=>y(!p)}),e.jsx(fs,{isOpen:p,onClose:()=>y(!1)})]})]}),e.jsx("div",{ref:K,className:"flex-1 overflow-y-auto px-8 py-6 book-reader",children:E?e.jsxs("div",{className:"flex items-center justify-center h-32",children:[e.jsx(J,{className:"w-6 h-6",style:{color:"var(--ws-text-muted)"}}),e.jsx("span",{className:"ml-2",style:{color:"var(--ws-text-muted)"},children:"Loading document..."})]}):V?e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 text-red-700 dark:text-red-400",children:[e.jsx("p",{className:"font-medium",children:"Error loading document"}),e.jsx("p",{className:"text-sm mt-1",children:V.message})]}):e.jsx(Te,{chunks:C,activeChunkIndex:L,onRegisterChunk:Z,scrollToChunk:s,showChunkNumbers:D.showChunkNumbers,getHighlightsForChunk:ze,onCreateHighlight:Ve,onHighlightClick:Ge,getSearchMatchesForChunk:Ke,currentSearchIndex:_.currentIndex})})]}),e.jsx(A,{mode:"wait",children:i?e.jsx("div",{className:"w-[60%] border-l",style:{borderColor:"var(--ws-border)"},children:e.jsx(Ns,{filePath:i.filePath,chunkIndex:i.chunkIndex,onClose:()=>l(null),onNavigate:(N,O)=>{l(null),ae(N,O)}})},"split"):e.jsx("div",{className:"w-[40%] border-l",style:{borderColor:"var(--ws-border)",background:"var(--ws-surface-1)"},children:e.jsx(rs,{relatedChunks:F,isLoading:U,activeChunkIndex:L,currentFilePath:t,onNavigateToChunk:ae,pinnedChunkKeys:o,onTogglePin:c,highlights:ne,annotations:re,onUpdateNote:Ue,onDeleteNote:We,onDeleteHighlight:Pe,onChangeHighlightColor:Fe,backlinks:Ze,outgoingLinks:Xe,autoSelectionResults:I,isAutoSearching:R,selectionText:S})},"margin")})]}),e.jsx(hs,{isOpen:m,onClose:()=>g(!1)}),e.jsx(gs,{isOpen:te,query:_.query,matches:_.matches,currentIndex:_.currentIndex,caseSensitive:_.caseSensitive,onQueryChange:$e,onToggleCaseSensitive:De,onNextMatch:ce,onPreviousMatch:ie,onGoToMatch:Ae,onClose:se})]})}function oe(t){const s=t.split(/[/\\]/);return s[s.length-1]||t}function Rs({className:t}){return e.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 3v2m6-2v2M9 19v2m6-2v2M5 9H3m2 6H3m18-6h-2m2 6h-2M7 19h10a2 2 0 002-2V7a2 2 0 00-2-2H7a2 2 0 00-2 2v10a2 2 0 002 2zM9 9h6m-6 4h6"})})}function Es({currentTrail:t,savedTrails:s,onSaveTrail:n,onLoadTrail:r,onDeleteTrail:o,onClearCurrentTrail:c,onNavigateToStep:d,isOpen:i,onClose:l,trailTree:u,currentNodeId:h,onSetCurrentNode:x}){const[f,p]=a.useState(!1),[y,m]=a.useState(""),[g,b]=a.useState("current"),w=()=>{y.trim()&&(n(y.trim()),m(""),p(!1))};return i?e.jsx(M.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:l,children:e.jsxs(M.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},className:"rounded-xl shadow-xl max-w-lg w-full mx-4 max-h-[80vh] flex flex-col",style:{background:"var(--ws-surface-raised)"},onClick:k=>k.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b",style:{borderColor:"var(--ws-border)"},children:[e.jsx("h2",{className:"text-lg font-semibold",style:{color:"var(--ws-text)"},children:"Trail Manager"}),e.jsx("button",{type:"button",onClick:l,className:"p-1 rounded transition-colors",style:{color:"var(--ws-text-muted)"},children:e.jsx(As,{})})]}),e.jsxs("div",{className:"flex border-b",style:{borderColor:"var(--ws-border)"},children:[e.jsxs("button",{type:"button",onClick:()=>b("current"),className:`flex-1 px-4 py-2 text-sm font-medium transition-colors ${g==="current"?"border-b-2":""}`,style:g==="current"?{color:"var(--ws-accent)",borderColor:"var(--ws-accent)"}:{color:"var(--ws-text-muted)"},children:["Current Trail",t&&e.jsx("span",{className:"ml-2 text-xs px-1.5 py-0.5 rounded",style:{background:"var(--ws-accent-subtle)",color:"var(--ws-accent)"},children:t.steps.length})]}),e.jsxs("button",{type:"button",onClick:()=>b("saved"),className:`flex-1 px-4 py-2 text-sm font-medium transition-colors ${g==="saved"?"border-b-2":""}`,style:g==="saved"?{color:"var(--ws-accent)",borderColor:"var(--ws-accent)"}:{color:"var(--ws-text-muted)"},children:["Saved Trails",s.length>0&&e.jsx("span",{className:"ml-2 text-xs px-1.5 py-0.5 rounded",style:{background:"var(--ws-surface-1)",color:"var(--ws-text-secondary)"},children:s.length})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:e.jsx(A,{mode:"wait",children:g==="current"?e.jsx(M.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},exit:{opacity:0,x:20},children:t?e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"space-y-2",children:u?e.jsx(Me,{node:u,depth:0,currentNodeId:h,onNavigate:k=>d(k.chunkKey.filePath,k.chunkKey.chunkIndex),onSetCurrent:k=>x?.(k)}):t.steps.map((k,T)=>e.jsx($s,{step:k,index:T,isLast:T===t.steps.length-1,onNavigate:()=>d(k.chunkKey.filePath,k.chunkKey.chunkIndex)},`${k.chunkKey.filePath}-${k.chunkKey.chunkIndex}-${T}`))}),e.jsxs("div",{className:"flex gap-2 pt-2 border-t",style:{borderColor:"var(--ws-border)"},children:[e.jsx("button",{type:"button",onClick:()=>p(!0),disabled:t.steps.length<2,className:"flex-1 px-3 py-2 text-sm font-medium rounded-lg disabled:opacity-50 disabled:cursor-not-allowed transition-colors",style:{background:"var(--ws-accent)",color:"white"},children:"Save Trail"}),e.jsx("button",{type:"button",onClick:c,className:"px-3 py-2 text-sm font-medium rounded-lg transition-colors",style:{color:"var(--ws-text-secondary)",background:"var(--ws-surface-1)"},children:"Clear"})]})]}):e.jsxs("div",{className:"text-center py-8",style:{color:"var(--ws-text-muted)"},children:[e.jsx(Ks,{}),e.jsx("p",{className:"mt-2",children:"No active trail"}),e.jsx("p",{className:"text-sm mt-1",children:"Navigate between documents to start recording"})]})},"current"):e.jsx(M.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},exit:{opacity:0,x:-20},children:s.length>0?e.jsx("div",{className:"space-y-2",children:s.map(k=>e.jsx(Ds,{trail:k,onLoad:()=>{r(k.id),l()},onDelete:()=>o(k.id)},k.id))}):e.jsxs("div",{className:"text-center py-8",style:{color:"var(--ws-text-muted)"},children:[e.jsx(Bs,{}),e.jsx("p",{className:"mt-2",children:"No saved trails"}),e.jsx("p",{className:"text-sm mt-1",children:"Save your explorations to revisit later"})]})},"saved")})}),e.jsx(A,{children:f&&e.jsx(M.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"absolute inset-0 bg-black/30 flex items-center justify-center rounded-xl",children:e.jsxs(M.div,{initial:{scale:.9},animate:{scale:1},exit:{scale:.9},className:"rounded-lg p-4 m-4 shadow-lg",style:{background:"var(--ws-surface-raised)"},children:[e.jsx("h3",{className:"text-sm font-medium mb-3",style:{color:"var(--ws-text)"},children:"Save Trail"}),e.jsx("input",{type:"text",value:y,onChange:k=>m(k.target.value),placeholder:"Enter trail name...",className:"w-full px-3 py-2 border rounded-lg placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-500",style:{borderColor:"var(--ws-border)",background:"var(--ws-surface-raised)",color:"var(--ws-text)"},onKeyDown:k=>{k.key==="Enter"&&w(),k.key==="Escape"&&p(!1)}}),e.jsxs("div",{className:"flex gap-2 mt-3",children:[e.jsx("button",{type:"button",onClick:w,disabled:!y.trim(),className:"flex-1 px-3 py-1.5 text-sm font-medium rounded-lg disabled:opacity-50 transition-colors",style:{background:"var(--ws-accent)",color:"white"},children:"Save"}),e.jsx("button",{type:"button",onClick:()=>p(!1),className:"px-3 py-1.5 text-sm font-medium rounded-lg transition-colors",style:{color:"var(--ws-text-secondary)",background:"var(--ws-surface-1)"},children:"Cancel"})]})]})})})]})}):null}function $s({step:t,index:s,isLast:n,onNavigate:r}){const o=Oe(t.chunkKey.filePath);return e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:"w-6 h-6 rounded-full flex items-center justify-center text-xs font-medium",style:n?{background:"var(--ws-accent)",color:"white"}:{background:"var(--ws-surface-2)",color:"var(--ws-text-secondary)"},children:s+1}),!n&&e.jsx("div",{className:"w-0.5 h-4",style:{background:"var(--ws-surface-2)"}})]}),e.jsxs("button",{type:"button",onClick:r,className:"flex-1 text-left p-2 rounded-lg transition-colors",children:[e.jsx("div",{className:"text-sm font-medium truncate",style:{color:"var(--ws-text)"},children:o}),e.jsxs("div",{className:"text-xs",style:{color:"var(--ws-text-muted)"},children:["Chunk #",t.chunkKey.chunkIndex,t.connectionReason&&e.jsxs("span",{className:"ml-2 italic",children:['via "',t.connectionReason,'"']})]})]})]})}function Ds({trail:t,onLoad:s,onDelete:n}){const[r,o]=a.useState(!1);return e.jsx("div",{className:"border rounded-lg p-3",style:{borderColor:"var(--ws-border)"},children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h4",{className:"text-sm font-medium truncate",style:{color:"var(--ws-text)"},children:t.name}),e.jsxs("p",{className:"text-xs mt-0.5",style:{color:"var(--ws-text-muted)"},children:[t.steps.length," steps · ",new Date(t.updatedAt).toLocaleDateString()]})]}),e.jsx("div",{className:"flex items-center gap-1",children:r?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:n,className:"px-2 py-1 text-xs font-medium text-red-600 dark:text-red-400 bg-red-50 dark:bg-red-900/30 rounded hover:bg-red-100 dark:hover:bg-red-900/50 transition-colors",children:"Delete"}),e.jsx("button",{type:"button",onClick:()=>o(!1),className:"px-2 py-1 text-xs font-medium rounded transition-colors",style:{color:"var(--ws-text-secondary)",background:"var(--ws-surface-1)"},children:"Cancel"})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:s,className:"px-2 py-1 text-xs font-medium rounded transition-colors",style:{color:"var(--ws-accent)"},children:"Load"}),e.jsx("button",{type:"button",onClick:()=>o(!0),className:"px-2 py-1 text-xs font-medium rounded transition-colors",style:{color:"var(--ws-text-muted)"},children:"Delete"})]})})]})})}function Oe(t){const s=t.split(/[/\\]/);return s[s.length-1]||t}function As(){return e.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}function Ks(){return e.jsx("svg",{className:"mx-auto h-10 w-10",style:{color:"var(--ws-text-muted)"},fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 20l-5.447-2.724A1 1 0 013 16.382V5.618a1 1 0 011.447-.894L9 7m0 13l6-3m-6 3V7m6 10l4.553 2.276A1 1 0 0021 18.382V7.618a1 1 0 00-.553-.894L15 4m0 13V4m0 0L9 7"})})}function Bs(){return e.jsx("svg",{className:"mx-auto h-10 w-10",style:{color:"var(--ws-text-muted)"},fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 5a2 2 0 012-2h10a2 2 0 012 2v16l-7-3.5L5 21V5z"})})}function Me({node:t,depth:s,currentNodeId:n,onNavigate:r,onSetCurrent:o}){const[c,d]=a.useState(!0),i=Oe(t.chunkKey.filePath),l=t.id===n,u=t.children.length>1;return e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[u?e.jsx("button",{type:"button",onClick:()=>d(!c),className:"mt-1 w-5 h-5 flex items-center justify-center",style:{color:"var(--ws-text-muted)"},children:c?e.jsx(Hs,{className:"w-4 h-4"}):e.jsx(Ps,{className:"w-4 h-4"})}):e.jsx("div",{className:"w-5"}),e.jsx("div",{className:"flex items-center justify-center min-w-[2rem] h-6 px-1.5 rounded text-xs font-medium",style:l?{background:"var(--ws-accent)",color:"white"}:{background:"var(--ws-surface-2)",color:"var(--ws-text-secondary)"},children:t.branchLabel||s+1}),e.jsxs("button",{type:"button",onClick:()=>{r(t),o(t.id)},className:"flex-1 text-left p-2 rounded-lg transition-colors",style:l?{background:"var(--ws-accent-subtle)",borderWidth:"1px",borderStyle:"solid",borderColor:"var(--ws-accent)"}:{},children:[e.jsx("div",{className:"text-sm font-medium truncate",style:{color:"var(--ws-text)"},children:i}),e.jsxs("div",{className:"text-xs",style:{color:"var(--ws-text-muted)"},children:["Chunk #",t.chunkKey.chunkIndex,t.connectionReason&&e.jsxs("span",{className:"ml-2 italic",children:['via "',t.connectionReason,'"']})]})]})]}),c&&t.children.length>0&&e.jsx("div",{className:"ml-6 mt-1 space-y-1 border-l-2 pl-2",style:{borderColor:"var(--ws-border)"},children:t.children.map(h=>e.jsx(Me,{node:h,depth:s+1,currentNodeId:n,onNavigate:r,onSetCurrent:o},h.id))})]})}function Hs({className:t}){return e.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}function Ps({className:t}){return e.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})}function Fs(t){try{let s=t.replace(/-/g,"+").replace(/_/g,"/");const n=s.length%4;n>0&&(s+="=".repeat(4-n));const r=atob(s),o=JSON.parse(r);if(o.v!==1)return console.error("Unsupported trail version:",o.v),null;if(!o.vault||!Array.isArray(o.steps))return console.error("Invalid trail structure"),null;for(const c of o.steps)if(typeof c.p!="string"||typeof c.c!="number")return console.error("Invalid step structure: each step must have p (string) and c (number)"),null;return o}catch(s){return console.error("Failed to decode trail:",s),null}}function Ws(){const t=window.location.hash;return t.startsWith("#trail=")?t.slice(7):null}function zs(t,s){const n=[],r=[];if(t.vault!==s.currentVaultId&&n.push(`This trail was created in a different vault (${t.vault}). Some steps may not be available.`),t.steps.length===0)return r.push("Trail has no steps"),{success:!1,warnings:n,errors:r};const c=[],d=[];for(const l of t.steps)if(!(!l.p||typeof l.c!="number")){if(s.checkFileExists&&!s.checkFileExists(l.p)){d.push(l.p);continue}c.push({chunkKey:{filePath:l.p,chunkIndex:l.c},visitedAt:new Date().toISOString()})}if(d.length>0){const l=[...new Set(d)];n.push(`${l.length} file(s) not found and will be skipped: ${l.slice(0,3).join(", ")}${l.length>3?"...":""}`)}return c.length===0?(r.push("No valid steps found in trail"),{success:!1,warnings:n,errors:r}):{success:!0,trail:{id:crypto.randomUUID(),name:"Imported Trail",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),steps:c},warnings:n,errors:r}}function Xs(){const[t]=ut(),s=xt(),[n,r]=a.useState(!1),[o,c]=a.useState(!1),[d,i]=a.useState(null),l=t.get("path"),u=t.get("chunk"),h=u?Number.parseInt(u,10):void 0,{pinnedChunkKeys:x,togglePin:f}=dt(),{currentTrail:p,savedTrails:y,addStep:m,saveTrail:g,loadTrail:b,deleteTrail:w,clearCurrentTrail:k}=bt();a.useEffect(()=>{const j=Ws();if(!j)return;const C=Fs(j);if(!C)return;const E=zs(C,{currentVaultId:"default"});i({decoded:C,validation:E}),c(!0),window.history.replaceState(null,"",window.location.pathname+window.location.search)},[]);const T=a.useCallback((j,C)=>{const E=new URLSearchParams({path:j});C!==void 0&&E.set("chunk",String(C)),s(`/read?${E.toString()}`),m({filePath:j,chunkIndex:C??0})},[s,m]),K=a.useCallback(()=>{s("/")},[s]),D=a.useCallback((j,C)=>{!l||h===void 0||f({filePath:l,chunkIndex:h},{filePath:j,chunkIndex:C},"","",void 0)},[l,h,f]),B=a.useCallback(()=>{r(!0)},[]),$=a.useCallback(()=>{if(!d?.validation.trail)return;const j=d.validation.trail;if(j.steps.length>0){const C=j.steps[0];if(C){for(const E of j.steps)m(E.chunkKey);s(`/read?path=${encodeURIComponent(C.chunkKey.filePath)}&chunk=${C.chunkKey.chunkIndex}`)}}c(!1),i(null)},[d,m,s]),v=a.useCallback(()=>{c(!1),i(null)},[]);return l?e.jsxs("div",{className:"h-[calc(100vh-4rem)]",children:[e.jsx(Ms,{filePath:l,initialChunkIndex:h,onNavigate:T,onGoHome:K,pinnedChunkKeys:x,onTogglePin:D,onSaveTrail:B}),e.jsx(Es,{currentTrail:p,savedTrails:y,onSaveTrail:g,onLoadTrail:j=>{const C=b(j);if(C&&C.steps.length>0){const E=C.steps[0];E&&T(E.chunkKey.filePath,E.chunkKey.chunkIndex)}},onDeleteTrail:w,onClearCurrentTrail:k,onNavigateToStep:T,isOpen:n,onClose:()=>r(!1)}),e.jsx(A,{children:o&&d&&e.jsx(M.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:v,children:e.jsxs(M.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},className:"rounded-xl shadow-xl max-w-md w-full mx-4 p-6",style:{background:"var(--ws-surface-raised)"},onClick:j=>j.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"p-2 rounded-lg",style:{background:"var(--ws-accent-subtle)"},children:e.jsx("span",{style:{color:"var(--ws-accent)"},children:e.jsx(Vs,{className:"w-5 h-5"})})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",style:{color:"var(--ws-text)"},children:"Import Shared Trail"}),e.jsxs("p",{className:"text-sm",style:{color:"var(--ws-text-muted)"},children:[d.decoded.steps.length," steps"]})]})]}),d.validation.warnings.length>0&&e.jsx("div",{className:"mb-4 p-3 bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-700 rounded-lg",children:e.jsx("p",{className:"text-sm text-yellow-700 dark:text-yellow-300",children:d.validation.warnings[0]})}),d.validation.errors.length>0&&e.jsx("div",{className:"mb-4 p-3 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-700 rounded-lg",children:e.jsx("p",{className:"text-sm text-red-700 dark:text-red-300",children:d.validation.errors[0]})}),d.validation.success&&d.validation.trail&&e.jsxs("div",{className:"mb-4 max-h-48 overflow-y-auto",children:[e.jsx("p",{className:"text-xs font-medium mb-2",style:{color:"var(--ws-text-muted)"},children:"Trail steps:"}),e.jsxs("div",{className:"space-y-1",children:[d.validation.trail.steps.slice(0,5).map((j,C)=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsxs("span",{className:"w-4",style:{color:"var(--ws-text-muted)"},children:[C+1,"."]}),e.jsx("span",{className:"truncate",style:{color:"var(--ws-text-secondary)"},children:j.chunkKey.filePath.split("/").pop()}),e.jsxs("span",{className:"text-xs",style:{color:"var(--ws-text-muted)"},children:["#",j.chunkKey.chunkIndex]})]},`${j.chunkKey.filePath}::${j.chunkKey.chunkIndex}`)),d.validation.trail.steps.length>5&&e.jsxs("p",{className:"text-xs pl-6",style:{color:"var(--ws-text-muted)"},children:["+",d.validation.trail.steps.length-5," more steps"]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:v,className:"px-4 py-2 text-sm rounded-lg transition-colors",style:{color:"var(--ws-text-secondary)",background:"var(--ws-surface-1)"},children:"Cancel"}),d.validation.success&&e.jsx("button",{type:"button",onClick:$,className:"px-4 py-2 text-sm rounded-lg transition-colors",style:{background:"var(--ws-accent)",color:"white"},children:"Import & Navigate"})]})]})})})]}):e.jsx("div",{className:"max-w-4xl mx-auto py-12",children:e.jsxs("div",{className:"bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-700 rounded-lg p-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-yellow-800 dark:text-yellow-200 mb-2",children:"No document selected"}),e.jsx("p",{className:"text-yellow-700 dark:text-yellow-300 mb-4",children:"Please select a document from the search results or files page to read."}),e.jsx("button",{type:"button",onClick:K,className:"px-4 py-2 bg-yellow-600 text-white rounded-lg hover:bg-yellow-700 transition-colors",children:"Go to Search"})]})})}function Vs({className:t}){return e.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 7h8m0 0v8m0-8l-8 8-4-4-6 6"})})}export{Xs as ReaderPage};
|
package/web-ui/dist/assets/{ReaderSettingsContext-CkSjqsRh.js → ReaderSettingsContext-BLFJnEne.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as t,j as C}from"./query-DPt-uCb6.js";import{a as p}from"./index-
|
|
1
|
+
import{a as t,j as C}from"./query-DPt-uCb6.js";import{a as p}from"./index-ANt8Xo4z.js";import"./vendor-DSXQOR6A.js";const f={fontSize:"base",lineHeight:"normal",fontFamily:"sans",showChunkNumbers:!0,showHeatmap:!1},F={sm:"0.875rem",base:"1rem",lg:"1.125rem",xl:"1.25rem"},x={tight:"1.4",normal:"1.6",relaxed:"1.8"},M={sans:'ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',serif:'ui-serif, Georgia, Cambria, "Times New Roman", Times, serif',mono:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace'},S=t.createContext(null);function w({children:a,vaultId:b="default"}){const d=`rag-vault-reader-settings-${b}`,[n,e]=p(d,f),r=t.useCallback(s=>{e(o=>({...o,fontSize:s}))},[e]),i=t.useCallback(s=>{e(o=>({...o,lineHeight:s}))},[e]),l=t.useCallback(s=>{e(o=>({...o,fontFamily:s}))},[e]),m=t.useCallback(s=>{e(o=>({...o,showChunkNumbers:s}))},[e]),c=t.useCallback(s=>{e(o=>({...o,showHeatmap:s}))},[e]),u=t.useCallback(()=>{e(f)},[e]),g=t.useMemo(()=>({"--reader-font-size":F[n.fontSize],"--reader-line-height":x[n.lineHeight],"--reader-font-family":M[n.fontFamily]}),[n.fontSize,n.lineHeight,n.fontFamily]),h=t.useMemo(()=>({settings:n,setFontSize:r,setLineHeight:i,setFontFamily:l,setShowChunkNumbers:m,setShowHeatmap:c,resetSettings:u,cssVariables:g}),[n,r,i,l,m,c,u,g]);return C.jsx(S.Provider,{value:h,children:a})}function E(){const a=t.useContext(S);if(!a)throw new Error("useReaderSettings must be used within a ReaderSettingsProvider");return a}export{w as ReaderSettingsProvider,E as useReaderSettings};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,a as i,c as u}from"./query-DPt-uCb6.js";import{u as x}from"./vendor-C2QPsZ3S.js";import{s as m}from"./index-D068MV_o.js";function h({icon:t,title:s,description:r,action:n}){return e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[t&&e.jsx("div",{className:"mb-4",style:{color:"var(--ws-text-muted)"},children:t}),e.jsx("h3",{className:"text-lg font-medium",style:{color:"var(--ws-text)"},children:s}),r&&e.jsx("p",{className:"mt-1 text-sm max-w-sm",style:{color:"var(--ws-text-muted)"},children:r}),n&&e.jsx("button",{type:"button",onClick:n.onClick,className:"mt-4 px-4 py-2 text-sm font-medium rounded-lg transition-colors",style:{color:"var(--ws-accent)",background:"var(--ws-accent-subtle)"},children:n.label})]})}function f({isOpen:t,onClose:s,title:r,children:n}){const a=i.useRef(null),o=i.useRef(null);return i.useEffect(()=>{if(t){o.current=document.activeElement,a.current?.focus();const l=c=>{c.key==="Escape"&&s()};return document.addEventListener("keydown",l),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",l),document.body.style.overflow="",o.current instanceof HTMLElement&&o.current.focus()}}},[t,s]),t?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",role:"dialog","aria-modal":"true","aria-labelledby":"modal-title",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 transition-opacity",onClick:s,"aria-hidden":"true"}),e.jsxs("div",{ref:a,tabIndex:-1,className:"relative rounded-lg shadow-xl max-w-2xl w-full mx-4 max-h-[85vh] flex flex-col",style:{background:"var(--ws-surface-raised)"},children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b",style:{borderColor:"var(--ws-border)"},children:[e.jsx("h2",{id:"modal-title",className:"text-lg font-semibold",style:{color:"var(--ws-text)"},children:r}),e.jsx("button",{type:"button",onClick:s,className:"transition-colors",style:{color:"var(--ws-text-muted)"},"aria-label":"Close modal",children:e.jsx("svg",{className:"h-6 w-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-4",children:n})]})]}):null}function p(){const[t,s]=i.useState([]),[r,n]=i.useState(!1),a=u({mutationFn:({query:c,limit:d})=>m(c,d),onSuccess:c=>{s(c),n(!0)}});return{results:t,search:(c,d)=>{a.mutate({query:c,limit:d})},clear:()=>{s([]),n(!1)},isLoading:a.isPending,error:a.error,hasSearched:r}}function y({result:t,isOpen:s,onClose:r}){const[n,a]=i.useState(!1),o=t.source||t.filePath,l=i.useRef(null);i.useEffect(()=>()=>{l.current&&clearTimeout(l.current)},[]);const c=async()=>{try{await navigator.clipboard.writeText(t.text),a(!0),l.current&&clearTimeout(l.current),l.current=setTimeout(()=>a(!1),2e3)}catch{}};return e.jsx(f,{isOpen:s,onClose:r,title:"Document Preview",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4 p-4 rounded-lg text-sm",style:{background:"var(--ws-surface-1)"},children:[e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--ws-text-muted)"},children:"Source:"}),e.jsx("p",{className:"font-medium break-all",style:{color:"var(--ws-text)"},children:o})]}),e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--ws-text-muted)"},children:"Chunk:"}),e.jsxs("p",{className:"font-medium",style:{color:"var(--ws-text)"},children:["#",t.chunkIndex]})]}),e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--ws-text-muted)"},children:"Score:"}),e.jsx("p",{className:"font-medium",style:{color:"var(--ws-text)"},children:t.score.toFixed(4)})]}),e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--ws-text-muted)"},children:"File Path:"}),e.jsx("p",{className:"font-medium break-all truncate",style:{color:"var(--ws-text)"},title:t.filePath,children:t.filePath})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-sm font-medium",style:{color:"var(--ws-text-secondary)"},children:"Content"}),e.jsx("button",{type:"button",onClick:c,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded transition-colors",style:{color:"var(--ws-text-secondary)",background:"var(--ws-surface-1)"},children:n?e.jsxs(e.Fragment,{children:[e.jsx(j,{}),"Copied"]}):e.jsxs(e.Fragment,{children:[e.jsx(v,{}),"Copy"]})})]}),e.jsx("div",{className:"p-4 rounded-lg",style:{background:"var(--ws-surface-raised)",border:"1px solid var(--ws-border)"},children:e.jsx("p",{className:"text-sm whitespace-pre-wrap",style:{color:"var(--ws-text-secondary)"},children:t.text})})]})]})})}function v(){return e.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}function j(){return e.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}function w({onSearch:t,isLoading:s}){const[r,n]=i.useState(""),[a,o]=i.useState(10),l=c=>{c.preventDefault(),r.trim()&&t(r.trim(),a)};return e.jsxs("form",{onSubmit:l,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"query",className:"block text-sm font-medium mb-1",style:{color:"var(--ws-text-secondary)"},children:"Search Query"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",id:"query",value:r,onChange:c=>n(c.target.value),placeholder:"Enter your search query...",className:"ws-input flex-1 px-4 py-2",disabled:s}),e.jsx("button",{type:"submit",disabled:s||!r.trim(),className:"ws-button px-6 py-2 font-medium rounded-lg transition-colors","data-variant":"primary",children:s?"Searching...":"Search"})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("label",{htmlFor:"limit",className:"text-sm",style:{color:"var(--ws-text-secondary)"},children:"Results limit:"}),e.jsxs("select",{id:"limit",value:a,onChange:c=>o(Number(c.target.value)),className:"ws-select px-3 py-1.5 text-sm",children:[e.jsx("option",{value:5,children:"5"}),e.jsx("option",{value:10,children:"10"}),e.jsx("option",{value:20,children:"20"}),e.jsx("option",{value:50,children:"50"})]})]})]})}function b({results:t,hasSearched:s}){const[r,n]=i.useState(null),a=x(),o=l=>{const c=new URLSearchParams({path:l.filePath});c.set("chunk",String(l.chunkIndex)),a(`/read?${c.toString()}`)};return s?t.length===0?e.jsx(h,{icon:e.jsx(N,{}),title:"No results found",description:"Try different keywords or a broader query."}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h2",{className:"text-lg font-medium",style:{color:"var(--ws-text)"},children:["Results (",t.length,")"]}),e.jsx("div",{className:"space-y-3",children:t.map((l,c)=>e.jsx(g,{result:l,rank:c+1,onView:()=>n(l),onRead:()=>o(l)},`${l.filePath}-${l.chunkIndex}`))}),r&&e.jsx(y,{result:r,isOpen:!0,onClose:()=>n(null)})]}):null}function g({result:t,rank:s,onView:r,onRead:n}){const a=t.source||t.filePath,o=C(t.score);return e.jsxs("div",{className:"ws-surface p-4 hover:shadow-md transition-shadow",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-sm font-medium",style:{color:"var(--ws-text-faint)"},children:["#",s]}),e.jsx("h3",{className:"font-medium truncate",style:{color:"var(--ws-text)"},title:a,children:k(a)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`px-2 py-0.5 text-xs font-medium rounded-full ${o}`,title:`Distance score: ${t.score.toFixed(4)}`,children:S(t.score)}),e.jsx("button",{type:"button",onClick:n,className:"px-2 py-1 text-xs font-medium rounded transition-colors",style:{color:"var(--ws-success)"},children:"Read"}),e.jsx("button",{type:"button",onClick:r,className:"px-2 py-1 text-xs font-medium rounded transition-colors",style:{color:"var(--ws-accent)"},children:"View"})]})]}),e.jsx("p",{className:"text-sm whitespace-pre-wrap line-clamp-4",style:{color:"var(--ws-text-secondary)"},children:t.text}),e.jsxs("div",{className:"mt-2 flex items-center gap-3 text-xs",style:{color:"var(--ws-text-faint)"},children:[e.jsxs("span",{children:["Chunk #",t.chunkIndex]}),t.source&&e.jsx("span",{className:"truncate",title:t.filePath,children:t.filePath.split("/").pop()})]})]})}function N(){return e.jsx("svg",{className:"h-12 w-12",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})}function k(t){if(t.startsWith("/")||t.includes("\\"))return t.split(/[/\\]/).pop()||t;if(t.startsWith("http"))try{const s=new URL(t);return s.hostname+s.pathname.slice(0,30)+(s.pathname.length>30?"...":"")}catch{return`${t.slice(0,40)}...`}return t}function S(t){return t<.3?"Excellent":t<.5?"Good":t<.7?"Fair":"Low"}function C(t){return t<.3?"bg-green-100 text-green-800":t<.5?"bg-blue-100 text-blue-800":t<.7?"bg-yellow-100 text-yellow-800":"bg-gray-100 text-gray-800"}function P(){const{results:t,search:s,isLoading:r,error:n,hasSearched:a}=p();return e.jsxs("div",{className:"ws-page max-w-4xl mx-auto space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"ws-page-title text-2xl font-bold mb-2",children:"Search Documents"}),e.jsx("p",{style:{color:"var(--ws-text-secondary)"},children:"Search through your ingested documents using semantic and keyword matching."})]}),e.jsx("div",{className:"ws-surface p-6",children:e.jsx(w,{onSearch:s,isLoading:r})}),n&&e.jsxs("div",{className:"ws-error-box rounded-lg",children:[e.jsx("p",{className:"font-medium",children:"Search Error"}),e.jsx("p",{className:"text-sm",children:n.message})]}),!r&&!a&&!n&&e.jsx("div",{className:"text-center py-12",style:{color:"var(--ws-text-muted)"},children:e.jsx("p",{children:"Enter a search query to find relevant documents."})}),e.jsx(b,{results:t,hasSearched:a&&!r})]})}export{P as SearchPage};
|
|
1
|
+
import{j as e,a as i,c as u}from"./query-DPt-uCb6.js";import{u as x}from"./vendor-DSXQOR6A.js";import{s as m}from"./index-ANt8Xo4z.js";function h({icon:t,title:s,description:r,action:n}){return e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[t&&e.jsx("div",{className:"mb-4",style:{color:"var(--ws-text-muted)"},children:t}),e.jsx("h3",{className:"text-lg font-medium",style:{color:"var(--ws-text)"},children:s}),r&&e.jsx("p",{className:"mt-1 text-sm max-w-sm",style:{color:"var(--ws-text-muted)"},children:r}),n&&e.jsx("button",{type:"button",onClick:n.onClick,className:"mt-4 px-4 py-2 text-sm font-medium rounded-lg transition-colors",style:{color:"var(--ws-accent)",background:"var(--ws-accent-subtle)"},children:n.label})]})}function f({isOpen:t,onClose:s,title:r,children:n}){const a=i.useRef(null),o=i.useRef(null);return i.useEffect(()=>{if(t){o.current=document.activeElement,a.current?.focus();const l=c=>{c.key==="Escape"&&s()};return document.addEventListener("keydown",l),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",l),document.body.style.overflow="",o.current instanceof HTMLElement&&o.current.focus()}}},[t,s]),t?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",role:"dialog","aria-modal":"true","aria-labelledby":"modal-title",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 transition-opacity",onClick:s,"aria-hidden":"true"}),e.jsxs("div",{ref:a,tabIndex:-1,className:"relative rounded-lg shadow-xl max-w-2xl w-full mx-4 max-h-[85vh] flex flex-col",style:{background:"var(--ws-surface-raised)"},children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b",style:{borderColor:"var(--ws-border)"},children:[e.jsx("h2",{id:"modal-title",className:"text-lg font-semibold",style:{color:"var(--ws-text)"},children:r}),e.jsx("button",{type:"button",onClick:s,className:"transition-colors",style:{color:"var(--ws-text-muted)"},"aria-label":"Close modal",children:e.jsx("svg",{className:"h-6 w-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-4",children:n})]})]}):null}function p(){const[t,s]=i.useState([]),[r,n]=i.useState(!1),a=u({mutationFn:({query:c,limit:d})=>m(c,d),onSuccess:c=>{s(c),n(!0)}});return{results:t,search:(c,d)=>{a.mutate({query:c,limit:d})},clear:()=>{s([]),n(!1)},isLoading:a.isPending,error:a.error,hasSearched:r}}function y({result:t,isOpen:s,onClose:r}){const[n,a]=i.useState(!1),o=t.source||t.filePath,l=i.useRef(null);i.useEffect(()=>()=>{l.current&&clearTimeout(l.current)},[]);const c=async()=>{try{await navigator.clipboard.writeText(t.text),a(!0),l.current&&clearTimeout(l.current),l.current=setTimeout(()=>a(!1),2e3)}catch{}};return e.jsx(f,{isOpen:s,onClose:r,title:"Document Preview",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4 p-4 rounded-lg text-sm",style:{background:"var(--ws-surface-1)"},children:[e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--ws-text-muted)"},children:"Source:"}),e.jsx("p",{className:"font-medium break-all",style:{color:"var(--ws-text)"},children:o})]}),e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--ws-text-muted)"},children:"Chunk:"}),e.jsxs("p",{className:"font-medium",style:{color:"var(--ws-text)"},children:["#",t.chunkIndex]})]}),e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--ws-text-muted)"},children:"Score:"}),e.jsx("p",{className:"font-medium",style:{color:"var(--ws-text)"},children:t.score.toFixed(4)})]}),e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--ws-text-muted)"},children:"File Path:"}),e.jsx("p",{className:"font-medium break-all truncate",style:{color:"var(--ws-text)"},title:t.filePath,children:t.filePath})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-sm font-medium",style:{color:"var(--ws-text-secondary)"},children:"Content"}),e.jsx("button",{type:"button",onClick:c,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded transition-colors",style:{color:"var(--ws-text-secondary)",background:"var(--ws-surface-1)"},children:n?e.jsxs(e.Fragment,{children:[e.jsx(j,{}),"Copied"]}):e.jsxs(e.Fragment,{children:[e.jsx(v,{}),"Copy"]})})]}),e.jsx("div",{className:"p-4 rounded-lg",style:{background:"var(--ws-surface-raised)",border:"1px solid var(--ws-border)"},children:e.jsx("p",{className:"text-sm whitespace-pre-wrap",style:{color:"var(--ws-text-secondary)"},children:t.text})})]})]})})}function v(){return e.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}function j(){return e.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}function w({onSearch:t,isLoading:s}){const[r,n]=i.useState(""),[a,o]=i.useState(10),l=c=>{c.preventDefault(),r.trim()&&t(r.trim(),a)};return e.jsxs("form",{onSubmit:l,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"query",className:"block text-sm font-medium mb-1",style:{color:"var(--ws-text-secondary)"},children:"Search Query"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",id:"query",value:r,onChange:c=>n(c.target.value),placeholder:"Enter your search query...",className:"ws-input flex-1 px-4 py-2",disabled:s}),e.jsx("button",{type:"submit",disabled:s||!r.trim(),className:"ws-button px-6 py-2 font-medium rounded-lg transition-colors","data-variant":"primary",children:s?"Searching...":"Search"})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("label",{htmlFor:"limit",className:"text-sm",style:{color:"var(--ws-text-secondary)"},children:"Results limit:"}),e.jsxs("select",{id:"limit",value:a,onChange:c=>o(Number(c.target.value)),className:"ws-select px-3 py-1.5 text-sm",children:[e.jsx("option",{value:5,children:"5"}),e.jsx("option",{value:10,children:"10"}),e.jsx("option",{value:20,children:"20"}),e.jsx("option",{value:50,children:"50"})]})]})]})}function b({results:t,hasSearched:s}){const[r,n]=i.useState(null),a=x(),o=l=>{const c=new URLSearchParams({path:l.filePath});c.set("chunk",String(l.chunkIndex)),a(`/read?${c.toString()}`)};return s?t.length===0?e.jsx(h,{icon:e.jsx(N,{}),title:"No results found",description:"Try different keywords or a broader query."}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h2",{className:"text-lg font-medium",style:{color:"var(--ws-text)"},children:["Results (",t.length,")"]}),e.jsx("div",{className:"space-y-3",children:t.map((l,c)=>e.jsx(g,{result:l,rank:c+1,onView:()=>n(l),onRead:()=>o(l)},`${l.filePath}-${l.chunkIndex}`))}),r&&e.jsx(y,{result:r,isOpen:!0,onClose:()=>n(null)})]}):null}function g({result:t,rank:s,onView:r,onRead:n}){const a=t.source||t.filePath,o=C(t.score);return e.jsxs("div",{className:"ws-surface p-4 hover:shadow-md transition-shadow",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-sm font-medium",style:{color:"var(--ws-text-faint)"},children:["#",s]}),e.jsx("h3",{className:"font-medium truncate",style:{color:"var(--ws-text)"},title:a,children:k(a)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`px-2 py-0.5 text-xs font-medium rounded-full ${o}`,title:`Distance score: ${t.score.toFixed(4)}`,children:S(t.score)}),e.jsx("button",{type:"button",onClick:n,className:"px-2 py-1 text-xs font-medium rounded transition-colors",style:{color:"var(--ws-success)"},children:"Read"}),e.jsx("button",{type:"button",onClick:r,className:"px-2 py-1 text-xs font-medium rounded transition-colors",style:{color:"var(--ws-accent)"},children:"View"})]})]}),e.jsx("p",{className:"text-sm whitespace-pre-wrap line-clamp-4",style:{color:"var(--ws-text-secondary)"},children:t.text}),e.jsxs("div",{className:"mt-2 flex items-center gap-3 text-xs",style:{color:"var(--ws-text-faint)"},children:[e.jsxs("span",{children:["Chunk #",t.chunkIndex]}),t.source&&e.jsx("span",{className:"truncate",title:t.filePath,children:t.filePath.split("/").pop()})]})]})}function N(){return e.jsx("svg",{className:"h-12 w-12",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})}function k(t){if(t.startsWith("/")||t.includes("\\"))return t.split(/[/\\]/).pop()||t;if(t.startsWith("http"))try{const s=new URL(t);return s.hostname+s.pathname.slice(0,30)+(s.pathname.length>30?"...":"")}catch{return`${t.slice(0,40)}...`}return t}function S(t){return t<.3?"Excellent":t<.5?"Good":t<.7?"Fair":"Low"}function C(t){return t<.3?"bg-green-100 text-green-800":t<.5?"bg-blue-100 text-blue-800":t<.7?"bg-yellow-100 text-yellow-800":"bg-gray-100 text-gray-800"}function P(){const{results:t,search:s,isLoading:r,error:n,hasSearched:a}=p();return e.jsxs("div",{className:"ws-page max-w-4xl mx-auto space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"ws-page-title text-2xl font-bold mb-2",children:"Search Documents"}),e.jsx("p",{style:{color:"var(--ws-text-secondary)"},children:"Search through your ingested documents using semantic and keyword matching."})]}),e.jsx("div",{className:"ws-surface p-6",children:e.jsx(w,{onSearch:s,isLoading:r})}),n&&e.jsxs("div",{className:"ws-error-box rounded-lg",children:[e.jsx("p",{className:"font-medium",children:"Search Error"}),e.jsx("p",{className:"text-sm",children:n.message})]}),!r&&!a&&!n&&e.jsx("div",{className:"text-center py-12",style:{color:"var(--ws-text-muted)"},children:e.jsx("p",{children:"Enter a search query to find relevant documents."})}),e.jsx(b,{results:t,hasSearched:a&&!r})]})}export{P as SearchPage};
|