@robthepcguy/rag-vault 1.5.3 → 1.6.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 +86 -14
- package/dist/bin/install-skills.d.ts.map +1 -0
- package/dist/bin/install-skills.js +16 -17
- package/dist/bin/install-skills.js.map +1 -0
- package/dist/chunker/index.d.ts.map +1 -0
- package/dist/chunker/index.js +1 -5
- package/dist/chunker/index.js.map +1 -0
- package/dist/chunker/semantic-chunker.d.ts.map +1 -0
- package/dist/chunker/semantic-chunker.js +9 -13
- package/dist/chunker/semantic-chunker.js.map +1 -0
- package/dist/chunker/sentence-splitter.d.ts.map +1 -0
- package/dist/chunker/sentence-splitter.js +1 -4
- package/dist/chunker/sentence-splitter.js.map +1 -0
- package/dist/embedder/index.d.ts +10 -0
- package/dist/embedder/index.d.ts.map +1 -0
- package/dist/embedder/index.js +58 -32
- package/dist/embedder/index.js.map +1 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +10 -17
- package/dist/errors/index.js.map +1 -0
- package/dist/explainability/index.d.ts.map +1 -0
- package/dist/explainability/index.js +1 -5
- package/dist/explainability/index.js.map +1 -0
- package/dist/explainability/keywords.d.ts.map +1 -0
- package/dist/explainability/keywords.js +1 -4
- package/dist/explainability/keywords.js.map +1 -0
- package/dist/flywheel/feedback.d.ts.map +1 -0
- package/dist/flywheel/feedback.js +15 -19
- package/dist/flywheel/feedback.js.map +1 -0
- package/dist/flywheel/index.d.ts.map +1 -0
- package/dist/flywheel/index.js +1 -5
- package/dist/flywheel/index.js.map +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +86 -64
- package/dist/index.js.map +1 -0
- package/dist/parser/html-parser.d.ts.map +1 -0
- package/dist/parser/html-parser.js +7 -13
- package/dist/parser/html-parser.js.map +1 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +44 -52
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/pdf-filter.d.ts.map +1 -0
- package/dist/parser/pdf-filter.js +10 -16
- package/dist/parser/pdf-filter.js.map +1 -0
- package/dist/query/index.d.ts.map +1 -0
- package/dist/query/index.js +1 -8
- package/dist/query/index.js.map +1 -0
- package/dist/query/parser.d.ts.map +1 -0
- package/dist/query/parser.js +5 -12
- package/dist/query/parser.js.map +1 -0
- package/dist/server/index.d.ts +6 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +106 -95
- package/dist/server/index.js.map +1 -0
- package/dist/server/raw-data-utils.d.ts.map +1 -0
- package/dist/server/raw-data-utils.js +21 -33
- package/dist/server/raw-data-utils.js.map +1 -0
- package/dist/server/remote-transport.d.ts +31 -0
- package/dist/server/remote-transport.d.ts.map +1 -0
- package/dist/server/remote-transport.js +177 -0
- package/dist/server/remote-transport.js.map +1 -0
- package/dist/server/schemas.d.ts.map +1 -0
- package/dist/server/schemas.js +35 -38
- package/dist/server/schemas.js.map +1 -0
- package/dist/utils/config-parsers.d.ts.map +1 -0
- package/dist/utils/config-parsers.js +3 -8
- package/dist/utils/config-parsers.js.map +1 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +12 -19
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/embedding-device-cli.d.ts +12 -0
- package/dist/utils/embedding-device-cli.d.ts.map +1 -0
- package/dist/utils/embedding-device-cli.js +61 -0
- package/dist/utils/embedding-device-cli.js.map +1 -0
- package/dist/utils/file-utils.d.ts.map +1 -0
- package/dist/utils/file-utils.js +12 -18
- package/dist/utils/file-utils.js.map +1 -0
- package/dist/utils/math.d.ts.map +1 -0
- package/dist/utils/math.js +2 -6
- package/dist/utils/math.js.map +1 -0
- package/dist/utils/process-handlers.d.ts.map +1 -0
- package/dist/utils/process-handlers.js +5 -10
- package/dist/utils/process-handlers.js.map +1 -0
- package/dist/vectordb/index.d.ts.map +1 -0
- package/dist/vectordb/index.js +39 -45
- package/dist/vectordb/index.js.map +1 -0
- package/dist/web/api-routes.d.ts.map +1 -0
- package/dist/web/api-routes.js +41 -47
- package/dist/web/api-routes.js.map +1 -0
- package/dist/web/config-routes.d.ts.map +1 -0
- package/dist/web/config-routes.js +30 -33
- package/dist/web/config-routes.js.map +1 -0
- package/dist/web/database-manager.d.ts.map +1 -0
- package/dist/web/database-manager.js +67 -72
- package/dist/web/database-manager.js.map +1 -0
- package/dist/web/http-server.d.ts.map +1 -0
- package/dist/web/http-server.js +45 -86
- package/dist/web/http-server.js.map +1 -0
- package/dist/web/index.d.ts.map +1 -0
- package/dist/web/index.js +20 -58
- package/dist/web/index.js.map +1 -0
- package/dist/web/middleware/async-handler.d.ts.map +1 -0
- package/dist/web/middleware/async-handler.js +1 -4
- package/dist/web/middleware/async-handler.js.map +1 -0
- package/dist/web/middleware/auth.d.ts.map +1 -0
- package/dist/web/middleware/auth.js +3 -6
- package/dist/web/middleware/auth.js.map +1 -0
- package/dist/web/middleware/error-handler.d.ts.map +1 -0
- package/dist/web/middleware/error-handler.js +4 -8
- package/dist/web/middleware/error-handler.js.map +1 -0
- package/dist/web/middleware/index.d.ts.map +1 -0
- package/dist/web/middleware/index.js +5 -17
- package/dist/web/middleware/index.js.map +1 -0
- package/dist/web/middleware/rate-limit.d.ts.map +1 -0
- package/dist/web/middleware/rate-limit.js +3 -8
- package/dist/web/middleware/rate-limit.js.map +1 -0
- package/dist/web/middleware/request-logger.d.ts.map +1 -0
- package/dist/web/middleware/request-logger.js +2 -6
- package/dist/web/middleware/request-logger.js.map +1 -0
- package/dist/web/types.d.ts.map +1 -0
- package/dist/web/types.js +1 -2
- package/dist/web/types.js.map +1 -0
- package/package.json +31 -35
- package/web-ui/dist/assets/CollectionsPage-BDmEfv3V.js +1 -0
- package/web-ui/dist/assets/FilesPage-pG9HmpgQ.js +1 -0
- package/web-ui/dist/assets/ReaderPage-CwMN03NU.js +28 -0
- package/web-ui/dist/assets/ReaderSettingsContext-CkSjqsRh.js +1 -0
- package/web-ui/dist/assets/SearchPage-DAltjnLL.js +1 -0
- package/web-ui/dist/assets/SettingsPage-C6J5BITP.js +1 -0
- package/web-ui/dist/assets/StatusPage-powRGmW3.js +1 -0
- package/web-ui/dist/assets/UploadPage-eyfSjL4u.js +8 -0
- package/web-ui/dist/assets/format-DOJ3IkRX.js +1 -0
- package/web-ui/dist/assets/index-BpwaiuGL.css +1 -0
- package/web-ui/dist/assets/index-D068MV_o.js +6 -0
- package/web-ui/dist/assets/link-indexer.worker-DGXNsXmZ.js +1 -0
- package/web-ui/dist/assets/motion-CKwJwI3J.js +9 -0
- package/web-ui/dist/assets/query-DPt-uCb6.js +1 -0
- package/web-ui/dist/assets/vendor-C2QPsZ3S.js +10 -0
- package/web-ui/dist/index.html +7 -2
- package/web-ui/dist/assets/index-SBHxoAwi.js +0 -120
- package/web-ui/dist/assets/index-ej8i4PGl.css +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-logger.js","sourceRoot":"","sources":["../../../src/web/middleware/request-logger.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAuB7C;;GAEG;AACH,MAAM,aAAa,GAAa,CAAC,KAAK,EAAE,EAAE;IACxC,MAAM,OAAO,GAAG;QACd,IAAI,KAAK,CAAC,SAAS,GAAG;QACtB,KAAK,CAAC,MAAM;QACZ,KAAK,CAAC,IAAI;QACV,KAAK,CAAC,UAAU;QAChB,GAAG,KAAK,CAAC,YAAY,IAAI;QACzB,KAAK,CAAC,QAAQ;KACf,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAEX,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;AACxB,CAAC,CAAA;AAcD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,mBAAmB,CAAC,SAA8B,EAAE;IAClE,MAAM,EAAE,MAAM,GAAG,aAAa,EAAE,IAAI,EAAE,GAAG,MAAM,CAAA;IAE/C,OAAO,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAQ,EAAE;QAC/D,6BAA6B;QAC7B,IAAI,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC;YAChB,IAAI,EAAE,CAAA;YACN,OAAM;QACR,CAAC;QAED,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAE5B,0BAA0B;QAC1B,GAAG,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;YACpB,MAAM,KAAK,GAAoB;gBAC7B,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;gBACnC,MAAM,EAAE,GAAG,CAAC,MAAM;gBAClB,IAAI,EAAE,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,GAAG;gBAChC,UAAU,EAAE,GAAG,CAAC,UAAU;gBAC1B,YAAY,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;gBACpC,QAAQ,EAAE,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,aAAa,IAAI,SAAS;gBACzD,SAAS,EAAE,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,SAAS;aAC9C,CAAA;YAED,kCAAkC;YAClC,MAAM,aAAa,GAAG,GAAG,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;YAC/C,IAAI,aAAa,EAAE,CAAC;gBAClB,KAAK,CAAC,aAAa,GAAG,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC,CAAA;YAC1D,CAAC;YAED,MAAM,CAAC,KAAK,CAAC,CAAA;QACf,CAAC,CAAC,CAAA;QAEF,IAAI,EAAE,CAAA;IACR,CAAC,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB;IACrC,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;IAC/C,OAAO,QAAQ,KAAK,MAAM,IAAI,QAAQ,KAAK,GAAG,CAAA;AAChD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/web/types.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAEnD;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,SAAS,CAAA"}
|
package/dist/web/types.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/web/types.ts"],"names":[],"mappings":"AAAA,8BAA8B"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@robthepcguy/rag-vault",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"description": "Local RAG MCP Server - Easy-to-setup document search with minimal configuration",
|
|
5
6
|
"main": "dist/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./dist/index.js"
|
|
9
|
+
},
|
|
6
10
|
"bin": {
|
|
7
11
|
"rag-vault": "dist/index.js"
|
|
8
12
|
},
|
|
9
13
|
"files": [
|
|
10
|
-
"dist
|
|
11
|
-
"dist/**/*.d.ts",
|
|
14
|
+
"dist",
|
|
12
15
|
"skills",
|
|
13
16
|
"web-ui/dist"
|
|
14
17
|
],
|
|
@@ -42,19 +45,19 @@
|
|
|
42
45
|
"url": "git+https://github.com/RobThePCGuy/rag-vault.git"
|
|
43
46
|
},
|
|
44
47
|
"dependencies": {
|
|
45
|
-
"@huggingface/transformers": "^3.
|
|
46
|
-
"@lancedb/lancedb": "^0.
|
|
48
|
+
"@huggingface/transformers": "^3.8.1",
|
|
49
|
+
"@lancedb/lancedb": "^0.26.0",
|
|
47
50
|
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
48
51
|
"@mozilla/readability": "^0.6.0",
|
|
49
52
|
"compression": "^1.8.1",
|
|
50
53
|
"cors": "^2.8.5",
|
|
51
|
-
"express": "^
|
|
54
|
+
"express": "^5.2.1",
|
|
52
55
|
"file-type": "^21.3.0",
|
|
53
56
|
"helmet": "^8.1.0",
|
|
54
57
|
"jsdom": "^27.4.0",
|
|
55
58
|
"mammoth": "^1.11.0",
|
|
56
59
|
"multer": "^2.0.2",
|
|
57
|
-
"pdfjs-dist": "^5.4.
|
|
60
|
+
"pdfjs-dist": "^5.4.624",
|
|
58
61
|
"turndown": "^7.2.2",
|
|
59
62
|
"zod": "^3.25.76"
|
|
60
63
|
},
|
|
@@ -65,17 +68,16 @@
|
|
|
65
68
|
"@types/express": "^5.0.0",
|
|
66
69
|
"@types/jsdom": "^27.0.0",
|
|
67
70
|
"@types/multer": "^2.0.0",
|
|
68
|
-
"@types/node": "^
|
|
71
|
+
"@types/node": "^22.0.0",
|
|
69
72
|
"@types/turndown": "5.0.6",
|
|
70
73
|
"@vitejs/plugin-react": "^5.1.2",
|
|
71
74
|
"@vitest/coverage-v8": "^4.0.18",
|
|
72
75
|
"concurrently": "^9.2.1",
|
|
73
76
|
"knip": "^5.61.0",
|
|
74
77
|
"madge": "^8.0.0",
|
|
75
|
-
"ts-node": "^10.9.1",
|
|
76
78
|
"tsc-alias": "^1.8.7",
|
|
77
79
|
"tsx": "^4.19.4",
|
|
78
|
-
"typescript": "^5.
|
|
80
|
+
"typescript": "^5.7.0",
|
|
79
81
|
"vitest": "^4.0.18"
|
|
80
82
|
},
|
|
81
83
|
"engines": {
|
|
@@ -84,43 +86,37 @@
|
|
|
84
86
|
"mcpName": "io.github.RobThePCGuy/rag-vault",
|
|
85
87
|
"scripts": {
|
|
86
88
|
"build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
|
|
89
|
+
"start": "node dist/index.js",
|
|
90
|
+
"dev": "tsx src/index.ts",
|
|
91
|
+
"dev:remote": "tsx src/index.ts --remote",
|
|
87
92
|
"check": "pnpm type-check && pnpm lint && pnpm format:check",
|
|
88
|
-
"check:all": "pnpm check && pnpm
|
|
93
|
+
"check:all": "pnpm check && pnpm --prefix web-ui check && pnpm check:unused && pnpm check:deps && pnpm build && pnpm test:unit",
|
|
89
94
|
"check:deps": "madge --circular --extensions ts src",
|
|
90
95
|
"check:deps:graph": "madge --extensions ts --image graph.svg src",
|
|
91
|
-
"check:
|
|
92
|
-
"check:unused": "node scripts/check-unused-exports.js",
|
|
96
|
+
"check:unused": "node scripts/check-unused-exports.cjs",
|
|
93
97
|
"check:unused:all": "knip",
|
|
94
|
-
"cleanup:processes": "bash ./scripts/cleanup-test-processes.sh",
|
|
95
|
-
"clean:dev": "rm -rf ./node_modules ./tmp ./uploads ./models ./lancedb ./dist ./package-lock.json && cd web-ui && rm -rf ./dist ./node_modules ./package-lock.json",
|
|
96
|
-
"dev": "tsx src/index.ts",
|
|
97
|
-
"format": "biome format --write src",
|
|
98
|
-
"format:check": "biome format src",
|
|
99
|
-
"lint": "biome lint src",
|
|
100
|
-
"lint:fix": "biome lint --write src",
|
|
101
|
-
"start": "node dist/index.js",
|
|
102
98
|
"test": "vitest run",
|
|
99
|
+
"test:unit": "vitest run --project backend-unit --project web-ui",
|
|
100
|
+
"test:integration": "RUN_EMBEDDING_INTEGRATION=1 vitest run --project backend-integration",
|
|
103
101
|
"test:coverage": "vitest run --coverage",
|
|
104
|
-
"test:safe": "pnpm test && pnpm cleanup:processes",
|
|
105
102
|
"test:watch": "vitest",
|
|
106
103
|
"type-check": "tsc --noEmit",
|
|
107
|
-
"
|
|
108
|
-
"
|
|
109
|
-
"
|
|
110
|
-
"
|
|
111
|
-
"
|
|
112
|
-
"web:build": "pnpm build",
|
|
113
|
-
"web:dev": "concurrently -n api,ui -c blue,magenta \"pnpm web:watch\" \"pnpm --prefix web-ui dev\"",
|
|
104
|
+
"lint": "biome lint src",
|
|
105
|
+
"lint:fix": "biome lint --write src",
|
|
106
|
+
"format": "biome format --write src",
|
|
107
|
+
"format:check": "biome format src",
|
|
108
|
+
"web": "tsx src/web/index.ts",
|
|
114
109
|
"web:start": "node dist/web/index.js",
|
|
110
|
+
"web:dev": "concurrently -n api,ui -c blue,magenta \"pnpm web:watch\" \"pnpm --prefix web-ui dev\"",
|
|
115
111
|
"web:watch": "tsx watch src/web/index.ts",
|
|
116
|
-
"
|
|
117
|
-
"
|
|
118
|
-
"
|
|
112
|
+
"ui:build": "pnpm --prefix web-ui build",
|
|
113
|
+
"ui:dev": "pnpm --prefix web-ui dev",
|
|
114
|
+
"clean": "rm -rf .test-tmp .narrative-project .mcpregistry* node_modules tmp uploads models lancedb dist && pnpm --prefix web-ui exec rm -rf dist node_modules",
|
|
115
|
+
"cleanup:processes": "bash ./scripts/cleanup-test-processes.sh",
|
|
119
116
|
"hooks:install": "git config core.hooksPath .githooks",
|
|
120
|
-
"release
|
|
117
|
+
"release": "bash ./scripts/release-npm.sh --bump patch",
|
|
121
118
|
"release:minor": "bash ./scripts/release-npm.sh --bump minor",
|
|
122
119
|
"release:major": "bash ./scripts/release-npm.sh --bump major",
|
|
123
|
-
"release:dry": "bash ./scripts/release-npm.sh --bump patch --dry-run"
|
|
124
|
-
"release:publish": "bash ./scripts/release-npm.sh --bump patch"
|
|
120
|
+
"release:dry": "bash ./scripts/release-npm.sh --bump patch --dry-run"
|
|
125
121
|
}
|
|
126
122
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,j as e}from"./query-DPt-uCb6.js";import{k as D,C as O,m as w}from"./index-D068MV_o.js";import{A as b,m as N}from"./motion-CKwJwI3J.js";import{u as M}from"./vendor-C2QPsZ3S.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as k,j as e}from"./query-DPt-uCb6.js";import{u as P,c as L}from"./vendor-C2QPsZ3S.js";import{j as F,k as S,l as T,S as R,T as M}from"./index-D068MV_o.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 as o,b as st,j as e}from"./query-DPt-uCb6.js";import{useReaderSettings as we}from"./ReaderSettingsContext-CkSjqsRh.js";import{g as nt,u as Ne,a as rt,b as at,s as ot,S as q,c as lt,K as ct,d as Ce,e as it,f as dt}from"./index-D068MV_o.js";import{m as R,A}from"./motion-CKwJwI3J.js";import{c as ut,u as xt}from"./vendor-C2QPsZ3S.js";function ht(t="100px"){const[s,n]=o.useState(new Set),[r,a]=o.useState(null),i=o.useRef(null),u=o.useRef(new Map),d=o.useRef(new Set);o.useEffect(()=>{i.current=new IntersectionObserver(c=>{n(f=>{const m=new Set(f);for(const g of c){const y=Number(g.target.getAttribute("data-chunk-index"));Number.isNaN(y)||(g.isIntersecting?m.add(y):m.delete(y))}return m})},{rootMargin:t,threshold:[0,.25,.5,.75,1]});const x=i.current;for(const[,c]of u.current)x.observe(c);for(const c of d.current){const f=u.current.get(c);f&&x.observe(f)}return d.current.clear(),()=>{x.disconnect(),i.current=null}},[t]),o.useEffect(()=>{if(s.size===0)a(null);else{const x=Array.from(s).sort((c,f)=>c-f);a(x[0]??null)}},[s]);const l=o.useCallback((x,c)=>{const f=i.current,m=u.current.get(x);m&&f&&f.unobserve(m),d.current.delete(x),c?(u.current.set(x,c),c.setAttribute("data-chunk-index",String(x)),f?f.observe(c):d.current.add(x)):u.current.delete(x)},[]);return{visibleChunkIndices:s,registerChunk:l,activeChunkIndex:r}}function ft(t,s,n=300,r=5){const[a,i]=o.useState([]);o.useEffect(()=>{if(!t||s.size===0){i([]);return}const x=Array.from(s).map(f=>({filePath:t,chunkIndex:f})),c=setTimeout(()=>{i(x)},n);return()=>clearTimeout(c)},[t,s,n]);const{data:u={},isLoading:d,error:l}=st({queryKey:["batchRelatedChunks",a,r],queryFn:()=>a.length>0?nt(a,r):{},enabled:a.length>0,staleTime:300*1e3});return{relatedChunks:u,isLoading:d,error:l}}function ie(){return crypto.randomUUID()}function mt(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:ie(),chunkKey:s.chunkKey,visitedAt:s.visitedAt,connectionReason:s.connectionReason,branchLabel:"1",children:[]};let r=n;for(let a=1;a<t.length;a++){const i=t[a];if(!i)continue;const u={id:ie(),chunkKey:i.chunkKey,visitedAt:i.visitedAt,connectionReason:i.connectionReason,branchLabel:String(a+1),children:[]};r.children.push(u),r=u}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]=o.useState(null),r=o.useCallback((l,x)=>{t.addToTrail(l,x)},[t]),a=o.useCallback(()=>t.currentTrail?t.currentTrail.root?t.currentTrail.root:pt(t.currentTrail.steps):null,[t.currentTrail]),i=o.useCallback(()=>Ie(a()),[a]),u=o.useCallback((l,x)=>{if(!t.currentTrail)return null;const c=a();if(!c)return null;const f=s||c.id,m=Se(c,f);if(!m)return null;const g={id:ie(),chunkKey:l,visitedAt:new Date().toISOString(),connectionReason:x,branchLabel:mt(m.branchLabel,m.children.length),children:[]};return m.children.push(g),n(g.id),g.id},[t.currentTrail,s,a]),d=o.useMemo(()=>{if(!t.currentTrail)return 0;const l=a();if(!l)return t.currentTrail.steps.length;let x=0;const c=f=>{x++,f.children.forEach(c)};return c(l),x},[t.currentTrail,a]);return{currentTrail:t.currentTrail,savedTrails:t.trails,isRecording:t.currentTrail!==null,stepCount:d,startNewTrail:t.startNewTrail,addStep:r,saveTrail:t.saveTrail,loadTrail:t.loadTrail,deleteTrail:t.deleteTrail,clearCurrentTrail:t.clearCurrentTrail,currentNodeId:s,setCurrentNodeId:n,addBranch:u,getTrailTree:a,flattenTrail:i}}function gt({totalChunks:t,activeChunkIndex:s,onNavigateToChunk:n,onToggleSplit:r,onPinTopSuggestion:a,onOpenSearch:i,onOpenHelp:u,onCloseOverlay:d,isOverlayOpen:l,enabled:x=!0,isSearchOpen:c=!1,onNextSearchMatch:f,onPreviousSearchMatch:m,onToggleBookmark:g,onOpenTagPicker:y,onToggleAnnotationPanel:h,onToggleReadingMode:b,onOpenComparison:v,onResetGraphLayout:w,onOpenGraphExport:k,onTogglePathfinding:S,onToggleClustering:E,isGraphOpen:K=!1,onToggleInferredLinks:H,onToggleCrossDocPanel:B,onToggleStatsPanel:W,onToggleDiscoveryMode:T,isDiscoveryMode:N=!1,onDiscoverySelectSuggestion:D,onDiscoveryGoBack:p}){const O=o.useRef(null),F=o.useRef({totalChunks:t,activeChunkIndex:s,isOverlayOpen:l,isSearchOpen:c,isGraphOpen:K,isDiscoveryMode:N}),C=o.useRef({onNavigateToChunk:n,onToggleSplit:r,onPinTopSuggestion:a,onOpenSearch:i,onOpenHelp:u,onCloseOverlay:d,onNextSearchMatch:f,onPreviousSearchMatch:m,onToggleBookmark:g,onOpenTagPicker:y,onToggleAnnotationPanel:h,onToggleReadingMode:b,onOpenComparison:v,onResetGraphLayout:w,onOpenGraphExport:k,onTogglePathfinding:S,onToggleClustering:E,onToggleInferredLinks:H,onToggleCrossDocPanel:B,onToggleStatsPanel:W,onToggleDiscoveryMode:T,onDiscoverySelectSuggestion:D,onDiscoveryGoBack:p});F.current={totalChunks:t,activeChunkIndex:s,isOverlayOpen:l,isSearchOpen:c,isGraphOpen:K,isDiscoveryMode:N},C.current={onNavigateToChunk:n,onToggleSplit:r,onPinTopSuggestion:a,onOpenSearch:i,onOpenHelp:u,onCloseOverlay:d,onNextSearchMatch:f,onPreviousSearchMatch:m,onToggleBookmark:g,onOpenTagPicker:y,onToggleAnnotationPanel:h,onToggleReadingMode:b,onOpenComparison:v,onResetGraphLayout:w,onOpenGraphExport:k,onTogglePathfinding:S,onToggleClustering:E,onToggleInferredLinks:H,onToggleCrossDocPanel:B,onToggleStatsPanel:W,onToggleDiscoveryMode:T,onDiscoverySelectSuggestion:D,onDiscoveryGoBack:p};const z=o.useCallback(()=>{const I=document.activeElement;if(I){const L=I.tagName.toLowerCase();if(L==="input"||L==="textarea"||I.getAttribute("contenteditable")==="true")return!0}const $=window.getSelection();return!!($&&$.toString().length>0)},[]),U=o.useCallback(I=>{if(z())return;const $=F.current,L=C.current;if(I.key==="Escape"){$.isOverlayOpen&&(I.preventDefault(),L.onCloseOverlay());return}if($.isSearchOpen){switch(I.key){case"n":I.preventDefault(),L.onNextSearchMatch?.();return;case"N":I.preventDefault(),L.onPreviousSearchMatch?.();return}return}if(!$.isOverlayOpen)switch(I.key){case"j":{I.preventDefault();const _=$.activeChunkIndex===null?0:Math.min($.activeChunkIndex+1,$.totalChunks-1);L.onNavigateToChunk(_);break}case"k":{I.preventDefault();const _=$.activeChunkIndex===null?0:Math.max($.activeChunkIndex-1,0);L.onNavigateToChunk(_);break}case" ":{I.preventDefault(),L.onToggleSplit();break}case"p":{I.preventDefault(),L.onPinTopSuggestion();break}case"/":{I.preventDefault(),L.onOpenSearch();break}case"?":{I.preventDefault(),L.onOpenHelp();break}case"b":{I.preventDefault(),L.onToggleBookmark?.();break}case"t":{I.preventDefault(),L.onOpenTagPicker?.();break}case"a":{I.preventDefault(),L.onToggleAnnotationPanel?.();break}case"m":{I.preventDefault(),L.onToggleReadingMode?.();break}case"c":{I.preventDefault(),L.onOpenComparison?.();break}case"r":{$.isGraphOpen&&(I.preventDefault(),L.onResetGraphLayout?.());break}case"e":{$.isGraphOpen&&(I.preventDefault(),L.onOpenGraphExport?.());break}case"f":{$.isGraphOpen&&(I.preventDefault(),L.onTogglePathfinding?.());break}case"g":{$.isGraphOpen&&(I.preventDefault(),L.onToggleClustering?.());break}case"i":{I.preventDefault(),L.onToggleInferredLinks?.();break}case"x":{I.preventDefault(),L.onToggleCrossDocPanel?.();break}case"s":{I.preventDefault(),L.onToggleStatsPanel?.();break}case"d":{I.preventDefault(),L.onToggleDiscoveryMode?.();break}case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":{if($.isDiscoveryMode){I.preventDefault();const _=parseInt(I.key,10)-1;L.onDiscoverySelectSuggestion?.(_)}break}case"Backspace":{$.isDiscoveryMode&&(I.preventDefault(),L.onDiscoveryGoBack?.());break}}},[z]);return o.useEffect(()=>{if(x)return document.addEventListener("keydown",U),()=>{document.removeEventListener("keydown",U)}},[x,U]),{containerRef:O}}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(i=>i.toString(16).padStart(2,"0")).join("")}function yt({filePath:t,chunks:s,activeChunkIndex:n,vaultId:r="default",debounceMs:a=1e3}){const i=`rag-vault-reading-progress-${r}`,[u,d]=rt(i,{}),l=o.useRef(null),x=o.useRef(null),c=o.useRef(!1),f=o.useRef({chunkIndex:0,scrollOffset:0});o.useEffect(()=>{if(s.length>0){const w=s[0];w&&vt(w.text).then(k=>{x.current=k})}},[s]);const m=o.useCallback(w=>`${t}:${w}`,[t]),g=Object.entries(u).find(([w])=>w.startsWith(`${t}:`)),y=!!g,h=g?g[1].lastChunkIndex:null,b=o.useCallback((w,k)=>{x.current&&(f.current={chunkIndex:w,scrollOffset:k},l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{const S=x.current;if(!S)return;const{chunkIndex:E,scrollOffset:K}=f.current,H=m(S);d(B=>({...B,[H]:{lastChunkIndex:E,scrollOffsetWithinChunk:K,lastVisited:new Date().toISOString(),fileFingerprint:S}}))},a))},[m,d,a]);o.useEffect(()=>{if(n!==null&&c.current){const w=document.getElementById(`chunk-${n}`),k=w?w.getBoundingClientRect().top:0;b(n,k)}},[n,b]);const v=o.useCallback(()=>{if(!x.current||s.length===0)return null;const w=x.current,k=m(w),S=u[k];return S?S.fileFingerprint!==w?(c.current=!0,{chunkIndex:0,scrollOffset:0}):(c.current=!0,{chunkIndex:Math.min(S.lastChunkIndex,s.length-1),scrollOffset:S.scrollOffsetWithinChunk}):Object.entries(u).find(([K])=>K.startsWith(`${t}:`))?(c.current=!0,{chunkIndex:0,scrollOffset:0}):(c.current=!0,null)},[t,s,u,m]);return o.useEffect(()=>()=>{l.current&&clearTimeout(l.current)},[]),{restorePosition:v,savePosition:b,hasSavedPosition:y,savedChunkIndex:h}}function kt(t){const s=at(),n=o.useMemo(()=>t?s.getHighlightsForChunk(t):[],[s,t]),r=o.useMemo(()=>{const c=new Map;for(const f of n){const m=s.getAnnotationForHighlight(f.id);m&&c.set(f.id,m)}return c},[n,s]),a=o.useCallback((c,f,m,g,y)=>{if(!t)throw new Error("No chunk key provided");return s.createHighlight(t,c,f,m,g,y)},[s,t]),i=o.useCallback(c=>{s.deleteHighlight(c)},[s]),u=o.useCallback((c,f)=>{s.updateHighlightColor(c,f)},[s]),d=o.useCallback((c,f)=>s.createAnnotation(c,f),[s]),l=o.useCallback((c,f)=>{s.updateAnnotation(c,f)},[s]),x=o.useCallback(c=>{s.deleteAnnotation(c)},[s]);return{highlights:n,annotations:r,createHighlight:a,deleteHighlight:i,updateHighlightColor:u,addNote:d,updateNote:l,deleteNote:x,hasHighlights:n.length>0}}function jt(t,s,n){const r=t.getRangeAt(0),a=[],i=document.createTreeWalker(s,NodeFilter.SHOW_TEXT);let u=i.nextNode();for(;u!==null;)a.push(u),u=i.nextNode();let d=0,l=!1;for(const f of a){if(f===r.startContainer){d+=r.startOffset,l=!0;break}d+=f.textContent?.length??0}if(!l)return null;let x=0,c=!1;for(const f of a){if(f===r.endContainer){x+=r.endOffset,c=!0;break}x+=f.textContent?.length??0}return!c||d<0||x>n.length||d>=x?null:{startOffset:d,endOffset:x}}function wt({containerRef:t,chunkText:s,enabled:n=!0}){const[r,a]=o.useState(null),i=o.useCallback(()=>{a(null),window.getSelection()?.removeAllRanges()},[]);return o.useEffect(()=>{if(!n)return;const u=()=>{const x=window.getSelection();if(!x||x.isCollapsed||!x.rangeCount){a(null);return}const c=t.current;if(!c){a(null);return}const f=x.getRangeAt(0);if(!c.contains(f.commonAncestorContainer)){a(null);return}const m=x.toString().trim();if(!m){a(null);return}const g=jt(x,c,s);if(!g){a(null);return}const y=f.getBoundingClientRect(),h=s.slice(Math.max(0,g.startOffset-30),g.startOffset),b=s.slice(g.endOffset,g.endOffset+30);a({startOffset:g.startOffset,endOffset:g.endOffset,text:m,contextBefore:h,contextAfter:b,rect:y})};let d;const l=()=>{clearTimeout(d),d=setTimeout(u,100)};return document.addEventListener("selectionchange",l),()=>{document.removeEventListener("selectionchange",l),clearTimeout(d)}},[n,t,s]),{selection:r,clearSelection:i}}function Nt(t){return t.map(s=>({chunkIndex:s.chunkIndex,text:s.text,lowerText:s.text.toLowerCase()}))}function be(t,s,n){if(!s||s.length===0)return[];const r=[],a=n?s:s.toLowerCase();for(const i of t){const u=n?i.text:i.lowerText;let d=0;for(;d<u.length;){const l=u.indexOf(a,d);if(l===-1)break;const x=Math.max(0,l-25),c=Math.min(i.text.length,l+s.length+25),f=i.text.slice(x,c);r.push({chunkIndex:i.chunkIndex,startOffset:l,endOffset:l+s.length,context:(x>0?"...":"")+f+(c<i.text.length?"...":"")}),d=l+1}}return r}const ge={query:"",matches:[],currentIndex:-1,caseSensitive:!1,isOpen:!1};function Ct({chunks:t,onNavigateToChunk:s}){const[n,r]=o.useState(ge),a=o.useMemo(()=>Nt(t),[t]),i=o.useCallback(()=>{r(h=>({...h,isOpen:!0}))},[]),u=o.useCallback(()=>{r(h=>({...h,isOpen:!1}))},[]),d=o.useCallback(()=>{r(ge)},[]),l=o.useCallback(h=>{const b=be(a,h,n.caseSensitive);r(v=>({...v,query:h,matches:b,currentIndex:b.length>0?0:-1})),b.length>0&&s&&s(b[0].chunkIndex)},[a,n.caseSensitive,s]),x=o.useCallback(()=>{r(h=>{const b=!h.caseSensitive,v=be(a,h.query,b);return{...h,caseSensitive:b,matches:v,currentIndex:v.length>0?0:-1}})},[a]),c=o.useCallback(()=>{r(h=>{if(h.matches.length===0)return h;const b=(h.currentIndex+1)%h.matches.length,v=h.matches[b];return v&&s&&s(v.chunkIndex),{...h,currentIndex:b}})},[s]),f=o.useCallback(()=>{r(h=>{if(h.matches.length===0)return h;const b=h.currentIndex<=0?h.matches.length-1:h.currentIndex-1,v=h.matches[b];return v&&s&&s(v.chunkIndex),{...h,currentIndex:b}})},[s]),m=o.useCallback(h=>{r(b=>{if(h<0||h>=b.matches.length)return b;const v=b.matches[h];return v&&s&&s(v.chunkIndex),{...b,currentIndex:h}})},[s]),g=o.useCallback(h=>n.matches.filter(b=>b.chunkIndex===h),[n.matches]),y=o.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:i,closeSearch:u,setQuery:l,toggleCaseSensitive:x,nextMatch:c,previousMatch:f,goToMatch:m,clearSearch:d,getMatchesForChunk:g,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[a,i]=o.useState([]),[u,d]=o.useState(!1),[l,x]=o.useState(null),c=o.useRef(null),f=o.useRef(null),m=o.useRef(null),g=o.useCallback(()=>{i([]),x(null),d(!1),m.current=null,f.current&&(clearTimeout(f.current),f.current=null),c.current&&(c.current.abort(),c.current=null)},[]);return o.useEffect(()=>{if(!r){g();return}if(!t){g();return}if(t.length<It){g();return}if(t===m.current)return;f.current&&clearTimeout(f.current),c.current&&c.current.abort();const y=Ot(t);if(y){const h=y.filter(b=>!(b.filePath===s&&b.chunkIndex===n));i(h),x(t),m.current=t;return}return f.current=setTimeout(async()=>{d(!0),c.current=new AbortController;try{const h=await ot(t,Lt),b=h.filter(v=>!(v.filePath===s&&v.chunkIndex===n));Mt(t,h),i(b),x(t),m.current=t}catch(h){h instanceof Error&&h.name!=="AbortError"&&console.error("Auto-selection search failed:",h)}finally{d(!1)}},St),()=>{f.current&&clearTimeout(f.current)}},[t,s,n,r,g]),o.useEffect(()=>()=>{f.current&&clearTimeout(f.current),c.current&&c.current.abort()},[]),{results:a,isSearching:u,searchedText:l,clearResults:g}}const ve=[{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 $t({highlight:t,annotation:s,onUpdateNote:n,onDeleteNote:r,onDeleteHighlight:a,onChangeColor:i}){const[u,d]=o.useState(!1),[l,x]=o.useState(s?.note||""),[c,f]=o.useState(!1),m=o.useCallback(()=>{l.trim()&&n(l.trim()),d(!1)},[l,n]),g=o.useCallback(h=>{h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),m()),h.key==="Escape"&&(d(!1),x(s?.note||""))},[m,s?.note]),y=ve.find(h=>h.color===t.color);return e.jsxs(R.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:u?e.jsxs("div",{children:[e.jsx("textarea",{value:l,onChange:h=>x(h.target.value),onKeyDown:g,onBlur:m,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:()=>{d(!1),x(s?.note||"")},className:"px-2 py-1 text-xs",style:{color:"var(--ws-text-secondary)"},children:"Cancel"}),e.jsx("button",{type:"button",onClick:m,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:()=>d(!0),children:s.note}):e.jsx("button",{type:"button",onClick:()=>d(!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:()=>f(!c),className:`w-5 h-5 rounded-full ${y?.bg} ring-1`,style:{"--tw-ring-color":"var(--ws-border)"},title:"Change color"}),c&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>f(!1),onKeyDown:h=>h.key==="Escape"&&f(!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:ve.map(({color:h,bg:b,ring:v})=>e.jsx("button",{type:"button",onClick:()=>{i(h),f(!1)},className:`w-5 h-5 rounded-full ${b} hover:ring-2 ${v} transition-all ${h===t.color?"ring-2":""}`,title:h},h))})]})]}),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:a,className:"p-1",style:{color:"var(--ws-text-muted)"},title:"Delete highlight",children:e.jsx(Dt,{className:"w-4 h-4"})})]})]})]})}function Dt({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 Et({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((a,i)=>e.jsxs(R.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:"/"}),a.connectionReason&&e.jsxs("span",{className:"text-xs italic mr-1",style:{color:"var(--ws-text-muted)"},children:['via "',a.connectionReason,'"']}),e.jsxs("button",{type:"button",onClick:()=>s(a),disabled:i===t.length-1,className:"text-sm truncate max-w-[150px] px-2 py-0.5 rounded transition-colors",style:i===t.length-1?{color:"var(--ws-text)",fontWeight:500,background:"var(--ws-surface-1)"}:{color:"var(--ws-text-secondary)"},title:`${a.label}${a.chunkIndex!==void 0?` #${a.chunkIndex}`:""}`,children:[a.label,a.chunkIndex!==void 0&&e.jsxs("span",{className:"ml-1",style:{color:"var(--ws-text-muted)"},children:["#",a.chunkIndex]})]})]},`${a.filePath}-${a.chunkIndex??"doc"}`))]}),n&&r&&t.length>1&&e.jsx(R.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 Pt({rect:t,onSelectColor:s,onClose:n,onSelectionAction:r,isActionLoading:a=!1,showMarginIndicator:i=!0}){const u=!!r,d=i&&!u,l=u?220:160,x=u?80:d?70:44,c=8,f=t.left+t.width/2-l/2,m=t.top-x-c+window.scrollY,g=Math.max(8,Math.min(f,window.innerWidth-l-8)),y=m<8?t.bottom+c+window.scrollY:m;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-50",onClick:n,onKeyDown:h=>h.key==="Escape"&&n(),role:"button",tabIndex:0,"aria-label":"Close popover"}),e.jsxs(R.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:g,top:y,minWidth:l},children:[e.jsx("div",{className:"flex items-center justify-center gap-1 mb-1.5",children:Kt.map(({color:h,bg:b,ring:v})=>e.jsx("button",{type:"button",onClick:()=>s(h),className:`w-7 h-7 rounded-full ${b} hover:ring-2 ${v} transition-all`,title:`Highlight ${h}`},h))}),d&&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(Ht,{className:"w-3 h-3"}),"See margin",e.jsx(Ft,{className:"w-3 h-3"})]})}),u&&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:h,icon:b,title:v})=>e.jsx("button",{type:"button",onClick:()=>r(h),disabled:a,className:`
|
|
2
|
+
flex items-center justify-center w-8 h-8 rounded-md text-sm
|
|
3
|
+
transition-all
|
|
4
|
+
${a?"opacity-50 cursor-not-allowed":""}
|
|
5
|
+
`,title:v,children:b},h))})]})]})}function Ht({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 a=[...s,...n];for(const d of a)d.startOffset>=0&&d.startOffset<=t.length&&r.add(d.startOffset),d.endOffset>=0&&d.endOffset<=t.length&&r.add(d.endOffset);const i=Array.from(r).sort((d,l)=>d-l),u=[];for(let d=0;d<i.length-1;d++){const l=i[d],x=i[d+1];if(l>=x)continue;const c=a.filter(f=>f.startOffset<=l&&f.endOffset>=x);u.push({text:t.slice(l,x),types:c})}return u}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 a=[];let i=0;for(const u of t)u.chunkIndex<s&&i++;for(const u of t){if(u.chunkIndex!==s)continue;const d=i+r;a.push({startOffset:u.startOffset,endOffset:u.endOffset,type:d===n?"search-current":"search-match"}),r++}return a}function _t({text:t,highlights:s,searchMatches:n=[],currentSearchIndex:r=-1,chunkIndex:a,onHighlightClick:i}){const u=o.useMemo(()=>Gt(s),[s]),d=o.useMemo(()=>Ut(n,a,r),[n,a,r]),l=o.useMemo(()=>Vt(t,u,d),[t,u,d]),x=o.useMemo(()=>{const c=new Map;for(const f of s)c.set(f.id,f);return c},[s]);return e.jsx("span",{className:"whitespace-pre-wrap",children:l.map((c,f)=>{const m=c.types.find(b=>b.type==="annotation"),g=c.types.find(b=>b.type==="search-current"),y=c.types.find(b=>b.type==="search-match"),h=["rounded","transition-colors"];if(m?.color&&(h.push(Wt[m.color]),h.push(zt[m.color]),h.push("cursor-pointer","px-0.5")),g&&(h.push("ring-2","ring-orange-500","dark:ring-orange-400","ring-offset-1","ring-offset-white"),m||h.push("bg-orange-100","dark:bg-orange-900/30")),y&&!g&&h.push("underline","decoration-dotted","decoration-orange-500","dark:decoration-orange-400","underline-offset-2"),m?.highlightId){const b=x.get(m.highlightId);return e.jsx("span",{className:h.join(" "),onClick:v=>{v.stopPropagation(),b&&i&&i(b)},onKeyDown:v=>{(v.key==="Enter"||v.key===" ")&&(v.preventDefault(),b&&i&&i(b))},role:"button",tabIndex:0,"data-highlight-id":m.highlightId,children:c.text},`highlight-${m.highlightId}-${f}`)}return g||y?e.jsx("span",{className:h.join(" "),"data-search-match":"true",children:c.text},`search-${f}-${c.text.length}`):e.jsx("span",{children:c.text},`text-${f}-${c.text.length}`)})})}function Qt({chunk:t,isActive:s,onRegister:n,onClick:r,showChunkNumbers:a=!0,highlights:i=[],onCreateHighlight:u,onHighlightClick:d,searchMatches:l=[],currentSearchIndex:x=-1,isBookmarked:c=!1,onSelectionAction:f,isSelectionActionLoading:m=!1}){const g=o.useRef(null),y=o.useRef(null),h=o.useRef(null),b=r?y:g,{selection:v,clearSelection:w}=wt({containerRef:h,chunkText:t.text,enabled:!!u}),k=o.useCallback(B=>{v&&u&&(u({startOffset:v.startOffset,endOffset:v.endOffset},v.text,v.contextBefore,v.contextAfter,B),w())},[v,u,w]),S=o.useCallback(B=>{v&&f&&(f(B,{text:v.text,startOffset:v.startOffset,endOffset:v.endOffset,contextBefore:v.contextBefore,contextAfter:v.contextAfter}),B==="pin"&&w())},[v,f,w]);o.useEffect(()=>(n(t.chunkIndex,b.current),()=>{n(t.chunkIndex,null)}),[t.chunkIndex,n,b]);const E=e.jsx("div",{ref:h,children:i.length>0||l.length>0?e.jsx(_t,{text:t.text,highlights:i,searchMatches:l,currentSearchIndex:x,chunkIndex:t.chunkIndex,onHighlightClick:d}):e.jsx("span",{className:"whitespace-pre-wrap",children:t.text})}),K=e.jsxs(e.Fragment,{children:[a&&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]}),c&&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:E}),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:v&&u&&e.jsx(Pt,{rect:v.rect,onSelectColor:k,onClose:w,onSelectionAction:f?S:void 0,isActionLoading:m})})]}),H=`
|
|
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:H,onClick:r,children:K}):e.jsx("div",{ref:g,id:`chunk-${t.chunkIndex}`,className:H,children:K})}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,onChunkClick:r,scrollToChunk:a,showChunkNumbers:i=!0,getHighlightsForChunk:u,onCreateHighlight:d,onHighlightClick:l,getSearchMatchesForChunk:x,currentSearchIndex:c=-1,isChunkBookmarked:f}){return o.useEffect(()=>{if(a!=null){const m=document.getElementById(`chunk-${a}`);m&&requestAnimationFrame(()=>{m.scrollIntoView({behavior:"smooth",block:"center"})})}},[a]),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(m=>{const g=u?.(m.chunkIndex)??[],y=x?.(m.chunkIndex)??[],h=f?.(m.chunkIndex)??!1;return e.jsx(Qt,{chunk:m,isActive:s===m.chunkIndex,onRegister:n,onClick:r?()=>r(m):void 0,showChunkNumbers:i,highlights:g,onCreateHighlight:d?(b,v,w,k,S)=>d(m.chunkIndex,b,v,w,k,S):void 0,onHighlightClick:l,searchMatches:y,currentSearchIndex:c,isBookmarked:h},`${m.filePath}-${m.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 ye(t){return`${Math.round((1-t)*100)}%`}function Y({filePath:t,chunkIndex:s,previewText:n,type:r,score:a,sharedKeywords:i=[],onNavigate:u,onPin:d,isPinned:l=!1,animationIndex:x=0}){const c=qt(t),f=Jt(r),m=Yt(r);return e.jsxs(R.button,{type:"button",onClick:u,custom:x,variants:Xt,initial:"hidden",animate:"visible",exit:"exit",className:`
|
|
9
|
+
zettel-slip ${m}
|
|
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:c}),e.jsxs("span",{className:"text-xs text-stone-400 dark:text-stone-500 font-mono",children:["#",s]})]}),a!==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: ${ye(a)}`,children:ye(a)})]}),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&&"..."]}),i.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-2",children:i.slice(0,3).map(g=>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:g},g))}),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:f}),e.jsx("div",{className:"flex items-center gap-1",children:d&&e.jsx("span",{role:"button",tabIndex:0,onClick:g=>{g.stopPropagation(),d()},onKeyDown:g=>{(g.key==="Enter"||g.key===" ")&&(g.stopPropagation(),g.preventDefault(),d())},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 ke({message:t}){return e.jsxs(R.div,{initial:{opacity:0},animate:{opacity:1},className:"text-center py-6 text-stone-500 dark:text-stone-400",children:[e.jsx(ss,{}),e.jsx("p",{className:"mt-2 text-sm font-serif italic",children:t})]})}function ss(){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 le(){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 ns({relatedChunks:t,isLoading:s,activeChunkIndex:n,currentFilePath:r,onNavigateToChunk:a,pinnedChunkKeys:i,onTogglePin:u,highlights:d=[],annotations:l=new Map,onUpdateNote:x,onDeleteNote:c,onDeleteHighlight:f,onChangeHighlightColor:m,backlinks:g=[],outgoingLinks:y=[],selectionSearchResults:h,isSelectionSearchLoading:b=!1,onClearSelectionSearch:v,autoSelectionResults:w=[],isAutoSearching:k=!1,selectionText:S=null}){const E=t.filter(p=>p.score<.7),K=d.length>0,H=g.length>0,B=y.length>0,W=w.length>0||k,T=h||b,N=[...g].sort((p,O)=>{const F=p.sourceKey.filePath===r,C=O.sourceKey.filePath===r;if(F!==C)return F?-1:1;const z=!!p.label,U=!!O.label;return z!==U?z?-1:1:new Date(O.createdAt).getTime()-new Date(p.createdAt).getTime()}),D=[...y].sort((p,O)=>{const F=p.targetKey.filePath===r,C=O.targetKey.filePath===r;if(F!==C)return F?-1:1;const z=!!p.label,U=!!O.label;return z!==U?z?-1:1:new Date(O.createdAt).getTime()-new Date(p.createdAt).getTime()});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(q,{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:d.length,icon:e.jsx(rs,{className:"w-3.5 h-3.5"})}),e.jsx("div",{className:"space-y-3 mt-2",children:e.jsx(A,{mode:"popLayout",children:d.map(p=>e.jsx($t,{highlight:p,annotation:l.get(p.id),onUpdateNote:O=>x?.(p.id,O),onDeleteNote:()=>{const O=l.get(p.id);O&&c?.(O.id)},onDeleteHighlight:()=>f?.(p.id),onChangeColor:O=>m?.(p.id,O)},p.id))})})]}),W&&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:w.length,icon:e.jsx(is,{className:"w-3.5 h-3.5"})}),S&&e.jsxs("span",{className:"zettel-selection-pill truncate max-w-[150px]",title:S,children:['"',S.slice(0,30),S.length>30?"...":"",'"']})]}),e.jsx("div",{className:"space-y-2 mt-2",children:k?e.jsxs("div",{className:"zettel-searching",children:[e.jsx(q,{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..."})]}):w.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:w.map((p,O)=>e.jsx(Y,{filePath:p.filePath,chunkIndex:p.chunkIndex,previewText:p.text,type:"semantic",score:p.score,onNavigate:()=>a(p.filePath,p.chunkIndex),onPin:u?()=>u(p.filePath,p.chunkIndex):void 0,isPinned:i?.has(`${p.filePath}:${p.chunkIndex}`)??!1,animationIndex:O},`${p.filePath}:${p.chunkIndex}`))})})]}),T&&!W&&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:h?us(h.action):"Searching...",count:h?.results.length,icon:e.jsx(cs,{className:"w-3.5 h-3.5"})}),v&&e.jsx("button",{type:"button",onClick:v,className:"text-stone-400 hover:text-stone-600 dark:hover:text-stone-200 transition-colors",title:"Close",children:e.jsx(ds,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"space-y-2 mt-2",children:b?e.jsx(le,{}):h?.results.length===0?e.jsx(ke,{message:"No results found"}):e.jsx(A,{mode:"popLayout",children:h?.results.map((p,O)=>e.jsx(Y,{filePath:p.filePath,chunkIndex:p.chunkIndex,previewText:p.text,type:"semantic",score:p.score,onNavigate:()=>a(p.filePath,p.chunkIndex),onPin:u?()=>u(p.filePath,p.chunkIndex):void 0,isPinned:i?.has(`${p.filePath}:${p.chunkIndex}`)??!1,animationIndex:O},`${p.filePath}:${p.chunkIndex}`))})})]}),H&&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:N.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:N.map((p,O)=>e.jsx(Y,{filePath:p.sourceKey.filePath,chunkIndex:p.sourceKey.chunkIndex,previewText:p.sourceText||"No preview available",type:"backlink",sharedKeywords:p.label?[p.label]:void 0,onNavigate:()=>a(p.sourceKey.filePath,p.sourceKey.chunkIndex),animationIndex:O},p.id))})})]}),B&&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:D.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:D.map((p,O)=>e.jsx(Y,{filePath:p.targetKey.filePath,chunkIndex:p.targetKey.chunkIndex,previewText:p.targetText||"No preview available",type:"forward",sharedKeywords:p.label?[p.label]:void 0,onNavigate:()=>a(p.targetKey.filePath,p.targetKey.chunkIndex),animationIndex:O},p.id))})})]}),e.jsxs("div",{children:[e.jsx(Q,{title:"Suggested",count:E.length,icon:e.jsx(as,{className:"w-3.5 h-3.5"})}),e.jsx("div",{className:"space-y-2 mt-2",children:e.jsx(A,{mode:"popLayout",children:E.length===0&&!s?e.jsx(ke,{message:n!==null?"No related content found":"Scroll to see related content"}):s&&E.length===0?e.jsxs(e.Fragment,{children:[e.jsx(le,{}),e.jsx(le,{})]}):E.map((p,O)=>{const F=`${p.filePath}:${p.chunkIndex}`,C=i?.has(F)??!1;return e.jsx(Y,{filePath:p.filePath,chunkIndex:p.chunkIndex,previewText:p.text,type:"semantic",score:p.score,sharedKeywords:p.explanation?.sharedKeywords,onNavigate:()=>a(p.filePath,p.chunkIndex),onPin:u?()=>u(p.filePath,p.chunkIndex):void 0,isPinned:C,animationIndex:O},F)})})})]})]})]})}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:"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 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:"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 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:"M11 19l-7-7 7-7m8 14l-7-7 7-7"})})}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:"M13 5l7 7-7 7M5 5l7 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:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})}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({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 us(t){switch(t){case"related":return"Related";case"support":return"Supporting";case"contradict":return"Contradicting";case"compare":return"Compare";case"pin":return"Pinned";default:return"Results"}}function xs({isOpen:t,onToggle:s,filePath:n,activeChunkIndex:r,relatedChunks:a,pins:i,onNavigateToChunk:u}){const{graphData:d,currentNodeId:l}=lt({filePath:n,activeChunkIndex:r,relatedChunks:a,pins:i}),x=o.useMemo(()=>{const f=new Set;for(const m of i)f.add(`${m.sourceKey.filePath}:${m.sourceKey.chunkIndex}`),f.add(`${m.targetKey.filePath}:${m.targetKey.chunkIndex}`);return f},[i]),c=f=>{u(f.filePath,f.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(je,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Graph"}),d.nodes.length>0&&e.jsxs("span",{className:"text-xs",style:{color:"var(--ws-text-muted)"},children:["(",d.nodes.length,")"]})]}),e.jsx(A,{children:t&&e.jsx(R.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(hs,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"flex-1 p-2",children:d.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(je,{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:d,currentNodeId:l,pinnedNodeIds:x,onNodeClick:c})})]})})})]})}function je({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 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:"M6 18L18 6M6 6l12 12"})})}const fs=[{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 ms({isOpen:t,onClose:s}){return e.jsx(A,{children:t&&e.jsxs(e.Fragment,{children:[e.jsx(R.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(R.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(ps,{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:fs.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 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:"M6 18L18 6M6 6l12 12"})})}function bs({isOpen:t,onClose:s}){const{settings:n,setFontSize:r,setLineHeight:a,setFontFamily:i,setShowChunkNumbers:u,setShowHeatmap:d,resetSettings:l}=we();return e.jsx(A,{children:t&&e.jsxs(e.Fragment,{children:[e.jsx(R.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-40",onClick:s}),e.jsx(R.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(x=>e.jsxs("button",{type:"button",onClick:()=>r(x),className:"flex-1 px-2 py-1.5 text-sm rounded-md transition-colors",style:n.fontSize===x?{background:"var(--ws-accent-subtle)",color:"var(--ws-accent)",fontWeight:500}:{background:"var(--ws-surface-1)",color:"var(--ws-text-secondary)"},children:[x==="sm"&&"S",x==="base"&&"M",x==="lg"&&"L",x==="xl"&&"XL"]},x))})]}),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(x=>e.jsx("button",{type:"button",onClick:()=>a(x),className:"flex-1 px-2 py-1.5 text-sm rounded-md transition-colors capitalize",style:n.lineHeight===x?{background:"var(--ws-accent-subtle)",color:"var(--ws-accent)",fontWeight:500}:{background:"var(--ws-surface-1)",color:"var(--ws-text-secondary)"},children:x},x))})]}),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:x=>i(x.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:()=>u(!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:()=>d(!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 gs({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(vs,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Display"})]})}function vs({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 ys({isOpen:t,query:s,matches:n,currentIndex:r,caseSensitive:a,onQueryChange:i,onToggleCaseSensitive:u,onNextMatch:d,onPreviousMatch:l,onGoToMatch:x,onClose:c}){const f=o.useRef(null),m=o.useRef(null);o.useEffect(()=>{t&&requestAnimationFrame(()=>{f.current?.focus(),f.current?.select()})},[t]),o.useEffect(()=>{r>=0&&m.current&&m.current.querySelector(`[data-result-index="${r}"]`)?.scrollIntoView({block:"nearest",behavior:"smooth"})},[r]);const g=o.useCallback(y=>{switch(y.key){case"Escape":y.preventDefault(),c();break;case"Enter":y.preventDefault(),y.shiftKey?l():d();break;case"n":y.target!==f.current&&(y.preventDefault(),y.shiftKey?l():d());break;case"N":y.target!==f.current&&(y.preventDefault(),l());break}},[c,d,l]);return e.jsx(A,{children:t&&e.jsx(R.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:g,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(js,{className:"w-5 h-5 flex-shrink-0"})}),e.jsx("input",{ref:f,type:"text",value:s,onChange:y=>i(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:u,className:"p-1.5 rounded text-sm font-medium transition-colors",style:a?{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(ws,{className:"w-4 h-4"})}),e.jsx("button",{type:"button",onClick:d,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(Ns,{className:"w-4 h-4"})})]}),e.jsx("button",{type:"button",onClick:c,className:"p-1 rounded transition-colors",style:{color:"var(--ws-text-muted)"},title:"Close (Esc)",children:e.jsx(Cs,{className:"w-4 h-4"})})]}),s.length>0&&e.jsx("div",{ref:m,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,h)=>e.jsxs("button",{"data-result-index":h,type:"button",onClick:()=>x(h),className:`w-full text-left px-4 py-2 transition-colors ${h===r?"border-l-2":""}`,style:h===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:ks(y.context,s,a)})]},`${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 ks(t,s,n){if(!s)return t;const r=n?s:s.toLowerCase(),i=(n?t:t.toLowerCase()).indexOf(r);if(i===-1)return t;const u=t.slice(0,i),d=t.slice(i,i+s.length),l=t.slice(i+s.length);return e.jsxs(e.Fragment,{children:[u,e.jsx("mark",{className:"bg-orange-200 dark:bg-orange-800/60 rounded px-0.5",children:d}),l]})}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:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})}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:"M5 15l7-7 7 7"})})}function Ns({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 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:"M6 18L18 6M6 6l12 12"})})}function Is({filePath:t,chunkIndex:s,onClose:n,onNavigate:r}){const{chunks:a,isLoading:i,error:u}=Ce(t),d=Ss(t);return e.jsxs(R.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:d}),e.jsxs("p",{className:"text-xs",style:{color:"var(--ws-text-muted)"},children:[a.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(Ls,{})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:i?e.jsxs("div",{className:"flex items-center justify-center h-32",children:[e.jsx(q,{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..."})]}):u?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:u.message})]}):e.jsx(Te,{chunks:a,activeChunkIndex:s,onRegisterChunk:()=>{},scrollToChunk:s})})]})}function Ss(t){const s=t.split(/[/\\]/);return s[s.length-1]||t}function Ls(){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 Ts({entries:t,activeChunkIndex:s,onNavigateToChunk:n,isOpen:r,onToggle:a,isFallback:i=!1}){const u=t.findIndex((l,x)=>{const c=t[x+1];return c?l.chunkIndex<=(s??0)&&c.chunkIndex>(s??0):l.chunkIndex<=(s??0)}),d=o.useCallback(l=>{n(l.chunkIndex)},[n]);return e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:a,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(Ms,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Contents"}),e.jsx(R.span,{animate:{rotate:r?180:0},transition:{duration:.2},children:e.jsx(Rs,{className:"w-3 h-3"})})]}),e.jsx(A,{children:r&&e.jsx(R.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"}),i&&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,x)=>e.jsx(Os,{entry:l,isCurrent:x===u,onClick:()=>d(l)},l.id))})})]})})})]})}function Os({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 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:"M4 6h16M4 10h16M4 14h16M4 18h16"})})}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:"M19 9l-7 7-7-7"})})}function $s({filePath:t,initialChunkIndex:s,onNavigate:n,onGoHome:r,pinnedChunkKeys:a,onTogglePin:i,onSaveTrail:u}){const[d,l]=o.useState(null),[x,c]=o.useState(()=>{const j=ce(t);return[{filePath:t,chunkIndex:s,label:j}]}),[f,m]=o.useState(!1),[g,y]=o.useState(!1),[h,b]=o.useState(!1),[v,w]=o.useState(!1),[k,S]=o.useState(null),E=o.useRef(null),{settings:K,cssVariables:H}=we(),{pins:B,getBacklinks:W,getPinsFromChunk:T}=Ne(),{chunks:N,isLoading:D,error:p}=Ce(t),{visibleChunkIndices:O,registerChunk:F,activeChunkIndex:C}=ht("100px"),{relatedChunks:z,isLoading:U}=ft(t,O,300,5),{results:I,isSearching:$,searchedText:L}=Rt({selectionText:k,filePath:t,chunkIndex:C??0,enabled:!d});o.useEffect(()=>{const j=()=>{const V=window.getSelection();if(!V||V.isCollapsed||!V.rangeCount){S(null);return}const J=V.toString().trim();J.length>=10?S(J):S(null)};let M;const P=()=>{clearTimeout(M),M=setTimeout(j,150)};return document.addEventListener("selectionchange",P),()=>{document.removeEventListener("selectionchange",P),clearTimeout(M)}},[]);const{entries:_,isFallback:Re}=it({chunks:N}),ee=o.useCallback(j=>{const M=document.getElementById(`chunk-${j}`);M&&M.scrollIntoView({behavior:"smooth",block:"center"})},[]),{searchState:X,isSearchOpen:te,openSearch:$e,closeSearch:se,setQuery:De,toggleCaseSensitive:Ee,nextMatch:de,previousMatch:ue,goToMatch:Ae,getMatchesForChunk:Ke}=Ct({chunks:N,onNavigateToChunk:ee}),{restorePosition:xe,hasSavedPosition:Be}=yt({filePath:t,chunks:N,activeChunkIndex:C}),Pe=o.useMemo(()=>C!==null?{filePath:t,chunkIndex:C}:null,[t,C]),{highlights:ne,annotations:re,createHighlight:he,deleteHighlight:He,updateHighlightColor:Fe,addNote:fe,updateNote:me,deleteNote:We}=kt(Pe),ze=o.useCallback(j=>j===C?ne:[],[C,ne]),Ve=o.useCallback((j,M,P,V,J,tt)=>{j===C&&he(M,P,V,J,tt)},[C,he]),Ge=o.useCallback(j=>{},[]),Ue=o.useCallback((j,M)=>{const P=re.get(j);P?me(P.id,M):fe(j,M)},[re,me,fe]),pe=o.useRef(!1);o.useEffect(()=>{if(N.length>0&&!pe.current&&!s){pe.current=!0;const j=xe();j&&requestAnimationFrame(()=>{const M=document.getElementById(`chunk-${j.chunkIndex}`);M&&M.scrollIntoView({behavior:"auto",block:"start"})})}},[N,xe,s]);const G=o.useMemo(()=>{if(C===null)return[];const j=`${t}:${C}`;return z[j]||[]},[t,C,z]),ae=o.useCallback((j,M)=>{const P=G.find(V=>V.filePath===j&&V.chunkIndex===M);c(V=>[...V,{filePath:j,chunkIndex:M,label:ce(j),connectionReason:P?.connectionReason}]),n(j,M)},[G,n]),oe=o.useCallback((j,M)=>{l({filePath:j,chunkIndex:M})},[]),_e=o.useCallback(j=>{if(!j.filePath){r();return}const M=x.findIndex(P=>P.filePath===j.filePath&&P.chunkIndex===j.chunkIndex);M!==-1&&c(P=>P.slice(0,M+1)),n(j.filePath,j.chunkIndex)},[x,n,r]),Qe=h||te||g,Ze=o.useMemo(()=>C===null?[]:W({filePath:t,chunkIndex:C}),[t,C,W]),Xe=o.useMemo(()=>C===null?[]:T({filePath:t,chunkIndex:C}),[t,C,T]),Ye=o.useCallback(()=>{if(G.length>0&&i){const j=G[0];j&&i(j.filePath,j.chunkIndex)}},[G,i]),Je=o.useCallback(()=>{if(d)l(null);else if(G.length>0){const j=G[0];j&&oe(j.filePath,j.chunkIndex)}},[d,G,oe]),qe=o.useCallback(()=>{b(!1),se(),y(!1)},[se]);gt({totalChunks:N.length,activeChunkIndex:C,onNavigateToChunk:ee,onToggleSplit:Je,onPinTopSuggestion:Ye,onOpenSearch:$e,onOpenHelp:()=>b(!0),onCloseOverlay:qe,isOverlayOpen:Qe,enabled:!0,isSearchOpen:te,onNextSearchMatch:de,onPreviousSearchMatch:ue});const et=ce(t);return e.jsxs("div",{className:"h-full flex flex-col",style:H,children:[e.jsx(Et,{items:x,onNavigate:_e,onSaveTrail:u,canSaveTrail:x.length>1}),e.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[f&&e.jsx("div",{className:"w-60 flex-shrink-0"}),e.jsxs("div",{className:`
|
|
26
|
+
flex flex-col overflow-hidden transition-all duration-300
|
|
27
|
+
${d?"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(Ts,{entries:_,activeChunkIndex:C,onNavigateToChunk:ee,isOpen:f,onToggle:()=>m(!f),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:[N.length," passages",C!==null&&` · §${C}`,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(xs,{isOpen:v,onToggle:()=>w(!v),filePath:t,activeChunkIndex:C,relatedChunks:G,pins:B,onNavigateToChunk:ae}),e.jsx("button",{type:"button",onClick:()=>b(!0),className:"p-2 rounded-lg transition-colors",style:{color:"var(--ws-text-muted)"},title:"Keyboard shortcuts (?)",children:e.jsx(Ds,{className:"w-4 h-4"})}),e.jsx(gs,{onClick:()=>y(!g)}),e.jsx(bs,{isOpen:g,onClose:()=>y(!1)})]})]}),e.jsx("div",{ref:E,className:"flex-1 overflow-y-auto px-8 py-6 book-reader",children:D?e.jsxs("div",{className:"flex items-center justify-center h-32",children:[e.jsx(q,{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..."})]}):p?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:p.message})]}):e.jsx(Te,{chunks:N,activeChunkIndex:C,onRegisterChunk:F,scrollToChunk:s,showChunkNumbers:K.showChunkNumbers,getHighlightsForChunk:ze,onCreateHighlight:Ve,onHighlightClick:Ge,getSearchMatchesForChunk:Ke,currentSearchIndex:X.currentIndex})})]}),e.jsx(A,{mode:"wait",children:d?e.jsx("div",{className:"w-[60%] border-l",style:{borderColor:"var(--ws-border)"},children:e.jsx(Is,{filePath:d.filePath,chunkIndex:d.chunkIndex,onClose:()=>l(null),onNavigate:(j,M)=>{l(null),ae(j,M)}})},"split"):e.jsx("div",{className:"w-[40%] border-l",style:{borderColor:"var(--ws-border)",background:"var(--ws-surface-1)"},children:e.jsx(ns,{relatedChunks:G,isLoading:U,activeChunkIndex:C,currentFilePath:t,onNavigateToChunk:ae,onOpenSplit:oe,pinnedChunkKeys:a,onTogglePin:i,highlights:ne,annotations:re,onUpdateNote:Ue,onDeleteNote:We,onDeleteHighlight:He,onChangeHighlightColor:Fe,backlinks:Ze,outgoingLinks:Xe,autoSelectionResults:I,isAutoSearching:$,selectionText:L})},"margin")})]}),e.jsx(ms,{isOpen:h,onClose:()=>b(!1)}),e.jsx(ys,{isOpen:te,query:X.query,matches:X.matches,currentIndex:X.currentIndex,caseSensitive:X.caseSensitive,onQueryChange:De,onToggleCaseSensitive:Ee,onNextMatch:de,onPreviousMatch:ue,onGoToMatch:Ae,onClose:se})]})}function ce(t){const s=t.split(/[/\\]/);return s[s.length-1]||t}function Ds({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:a,onClearCurrentTrail:i,onNavigateToStep:u,isOpen:d,onClose:l,trailTree:x,currentNodeId:c,onSetCurrentNode:f}){const[m,g]=o.useState(!1),[y,h]=o.useState(""),[b,v]=o.useState("current"),w=()=>{y.trim()&&(n(y.trim()),h(""),g(!1))};return d?e.jsx(R.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(R.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(Bs,{})})]}),e.jsxs("div",{className:"flex border-b",style:{borderColor:"var(--ws-border)"},children:[e.jsxs("button",{type:"button",onClick:()=>v("current"),className:`flex-1 px-4 py-2 text-sm font-medium transition-colors ${b==="current"?"border-b-2":""}`,style:b==="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:()=>v("saved"),className:`flex-1 px-4 py-2 text-sm font-medium transition-colors ${b==="saved"?"border-b-2":""}`,style:b==="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:b==="current"?e.jsx(R.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:x?e.jsx(Me,{node:x,depth:0,currentNodeId:c,onNavigate:k=>u(k.chunkKey.filePath,k.chunkKey.chunkIndex),onSetCurrent:k=>f?.(k)}):t.steps.map((k,S)=>e.jsx(As,{step:k,index:S,isLast:S===t.steps.length-1,onNavigate:()=>u(k.chunkKey.filePath,k.chunkKey.chunkIndex)},`${k.chunkKey.filePath}-${k.chunkKey.chunkIndex}-${S}`))}),e.jsxs("div",{className:"flex gap-2 pt-2 border-t",style:{borderColor:"var(--ws-border)"},children:[e.jsx("button",{type:"button",onClick:()=>g(!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:i,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(Ps,{}),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(R.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(Ks,{trail:k,onLoad:()=>{r(k.id),l()},onDelete:()=>a(k.id)},k.id))}):e.jsxs("div",{className:"text-center py-8",style:{color:"var(--ws-text-muted)"},children:[e.jsx(Hs,{}),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:m&&e.jsx(R.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(R.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=>h(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"&&g(!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:()=>g(!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 As({step:t,index:s,isLast:n,onNavigate:r}){const a=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:a}),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 Ks({trail:t,onLoad:s,onDelete:n}){const[r,a]=o.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:()=>a(!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:()=>a(!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 Bs(){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 Ps(){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 Hs(){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:a}){const[i,u]=o.useState(!0),d=Oe(t.chunkKey.filePath),l=t.id===n,x=t.children.length>1;return e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[x?e.jsx("button",{type:"button",onClick:()=>u(!i),className:"mt-1 w-5 h-5 flex items-center justify-center",style:{color:"var(--ws-text-muted)"},children:i?e.jsx(Fs,{className:"w-4 h-4"}):e.jsx(Ws,{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),a(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:d}),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,'"']})]})]})]}),i&&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(c=>e.jsx(Me,{node:c,depth:s+1,currentNodeId:n,onNavigate:r,onSetCurrent:a},c.id))})]})}function Fs({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 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:"M9 5l7 7-7 7"})})}function zs(t){try{let s=t.replace(/-/g,"+").replace(/_/g,"/");const n=s.length%4;n>0&&(s+="=".repeat(4-n));const r=atob(s),a=JSON.parse(r);if(a.v!==1)return console.error("Unsupported trail version:",a.v),null;if(!a.vault||!Array.isArray(a.steps))return console.error("Invalid trail structure"),null;for(const i of a.steps)if(typeof i.p!="string"||typeof i.c!="number")return console.error("Invalid step structure: each step must have p (string) and c (number)"),null;return a}catch(s){return console.error("Failed to decode trail:",s),null}}function Vs(){const t=window.location.hash;return t.startsWith("#trail=")?t.slice(7):null}function Gs(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 i=[],u=[];for(const l of t.steps)if(!(!l.p||typeof l.c!="number")){if(s.checkFileExists&&!s.checkFileExists(l.p)){u.push(l.p);continue}i.push({chunkKey:{filePath:l.p,chunkIndex:l.c},visitedAt:new Date().toISOString()})}if(u.length>0){const l=[...new Set(u)];n.push(`${l.length} file(s) not found and will be skipped: ${l.slice(0,3).join(", ")}${l.length>3?"...":""}`)}return i.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:i},warnings:n,errors:r}}function Js(){const[t]=ut(),s=xt(),[n,r]=o.useState(!1),[a,i]=o.useState(!1),[u,d]=o.useState(null),l=t.get("path"),x=t.get("chunk"),c=x?Number.parseInt(x,10):void 0,{pinnedChunkKeys:f,togglePin:m}=dt(),{currentTrail:g,savedTrails:y,addStep:h,saveTrail:b,loadTrail:v,deleteTrail:w,clearCurrentTrail:k}=bt();o.useEffect(()=>{const T=Vs();if(!T)return;const N=zs(T);if(!N)return;const D=Gs(N,{currentVaultId:"default"});d({decoded:N,validation:D}),i(!0),window.history.replaceState(null,"",window.location.pathname+window.location.search)},[]);const S=o.useCallback((T,N)=>{const D=new URLSearchParams({path:T});N!==void 0&&D.set("chunk",String(N)),s(`/read?${D.toString()}`),h({filePath:T,chunkIndex:N??0})},[s,h]),E=o.useCallback(()=>{s("/")},[s]),K=o.useCallback((T,N)=>{!l||c===void 0||m({filePath:l,chunkIndex:c},{filePath:T,chunkIndex:N},"","",void 0)},[l,c,m]),H=o.useCallback(()=>{r(!0)},[]),B=o.useCallback(()=>{if(!u?.validation.trail)return;const T=u.validation.trail;if(T.steps.length>0){const N=T.steps[0];if(N){for(const D of T.steps)h(D.chunkKey);s(`/read?path=${encodeURIComponent(N.chunkKey.filePath)}&chunk=${N.chunkKey.chunkIndex}`)}}i(!1),d(null)},[u,h,s]),W=o.useCallback(()=>{i(!1),d(null)},[]);return l?e.jsxs("div",{className:"h-[calc(100vh-4rem)]",children:[e.jsx($s,{filePath:l,initialChunkIndex:c,onNavigate:S,onGoHome:E,pinnedChunkKeys:f,onTogglePin:K,onSaveTrail:H}),e.jsx(Es,{currentTrail:g,savedTrails:y,onSaveTrail:b,onLoadTrail:T=>{const N=v(T);if(N&&N.steps.length>0){const D=N.steps[0];D&&S(D.chunkKey.filePath,D.chunkKey.chunkIndex)}},onDeleteTrail:w,onClearCurrentTrail:k,onNavigateToStep:S,isOpen:n,onClose:()=>r(!1)}),e.jsx(A,{children:a&&u&&e.jsx(R.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:W,children:e.jsxs(R.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:T=>T.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(Us,{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:[u.decoded.steps.length," steps"]})]})]}),u.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:u.validation.warnings[0]})}),u.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:u.validation.errors[0]})}),u.validation.success&&u.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:[u.validation.trail.steps.slice(0,5).map((T,N)=>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:[N+1,"."]}),e.jsx("span",{className:"truncate",style:{color:"var(--ws-text-secondary)"},children:T.chunkKey.filePath.split("/").pop()}),e.jsxs("span",{className:"text-xs",style:{color:"var(--ws-text-muted)"},children:["#",T.chunkKey.chunkIndex]})]},`${T.chunkKey.filePath}::${T.chunkKey.chunkIndex}`)),u.validation.trail.steps.length>5&&e.jsxs("p",{className:"text-xs pl-6",style:{color:"var(--ws-text-muted)"},children:["+",u.validation.trail.steps.length-5," more steps"]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:W,className:"px-4 py-2 text-sm rounded-lg transition-colors",style:{color:"var(--ws-text-secondary)",background:"var(--ws-surface-1)"},children:"Cancel"}),u.validation.success&&e.jsx("button",{type:"button",onClick:B,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:E,className:"px-4 py-2 bg-yellow-600 text-white rounded-lg hover:bg-yellow-700 transition-colors",children:"Go to Search"})]})})}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:"M13 7h8m0 0v8m0-8l-8 8-4-4-6 6"})})}export{Js as ReaderPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as t,j as C}from"./query-DPt-uCb6.js";import{a as p}from"./index-D068MV_o.js";import"./vendor-C2QPsZ3S.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};
|
|
@@ -0,0 +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};
|