dsh-plugin-library 0.1.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/dist/client.js ADDED
@@ -0,0 +1,2730 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "dsh-plugin-library",
3
+ factory: function (require) {
4
+ var module = { exports: {} };
5
+ var exports = module.exports;
6
+ var __create = Object.create;
7
+ var __defProp = Object.defineProperty;
8
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
+ var __getOwnPropNames = Object.getOwnPropertyNames;
10
+ var __getProtoOf = Object.getPrototypeOf;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __commonJS = (cb, mod) => function __require() {
13
+ try {
14
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
15
+ } catch (e) {
16
+ throw mod = 0, e;
17
+ }
18
+ };
19
+ var __export = (target, all) => {
20
+ for (var name2 in all)
21
+ __defProp(target, name2, { get: all[name2], enumerable: true });
22
+ };
23
+ var __copyProps = (to, from, except, desc) => {
24
+ if (from && typeof from === "object" || typeof from === "function") {
25
+ for (let key of __getOwnPropNames(from))
26
+ if (!__hasOwnProp.call(to, key) && key !== except)
27
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
28
+ }
29
+ return to;
30
+ };
31
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
32
+ // If the importer is in node compatibility mode or this is not an ESM
33
+ // file that has been converted to a CommonJS file using a Babel-
34
+ // compatible transform (i.e. "__esModule" has not been set), then set
35
+ // "default" to the CommonJS "module.exports" for node compatibility.
36
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
37
+ mod
38
+ ));
39
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
40
+
41
+ // packages/library/node_modules/papaparse/papaparse.min.js
42
+ var require_papaparse_min = __commonJS({
43
+ "packages/library/node_modules/papaparse/papaparse.min.js"(exports, module2) {
44
+ ((e, t) => {
45
+ "function" == typeof define && define.amd ? define([], t) : "object" == typeof module2 && "undefined" != typeof exports ? module2.exports = t() : e.Papa = t();
46
+ })(exports, function r() {
47
+ var n = "undefined" != typeof self ? self : "undefined" != typeof window ? window : void 0 !== n ? n : {};
48
+ var d, s = !n.document && !!n.postMessage, a = n.IS_PAPA_WORKER || false, o = {}, h = 0, v = {};
49
+ function u(e) {
50
+ this._handle = null, this._finished = false, this._completed = false, this._halted = false, this._input = null, this._baseIndex = 0, this._partialLine = "", this._rowCount = 0, this._start = 0, this._nextChunk = null, this.isFirstChunk = true, this._completeResults = { data: [], errors: [], meta: {} }, function(e2) {
51
+ var t = b(e2);
52
+ t.chunkSize = parseInt(t.chunkSize), e2.step || e2.chunk || (t.chunkSize = null);
53
+ this._handle = new i(t), (this._handle.streamer = this)._config = t;
54
+ }.call(this, e), this.parseChunk = function(t, e2) {
55
+ var i2 = parseInt(this._config.skipFirstNLines) || 0;
56
+ if (this.isFirstChunk && 0 < i2) {
57
+ let e3 = this._config.newline;
58
+ e3 || (r2 = this._config.quoteChar || '"', e3 = this._handle.guessLineEndings(t, r2)), t = [...t.split(e3).slice(i2)].join(e3);
59
+ }
60
+ this.isFirstChunk && U(this._config.beforeFirstChunk) && void 0 !== (r2 = this._config.beforeFirstChunk(t)) && (t = r2), this.isFirstChunk = false, this._halted = false;
61
+ var i2 = this._partialLine + t, r2 = (this._partialLine = "", this._handle.parse(i2, this._baseIndex, !this._finished));
62
+ if (!this._handle.paused() && !this._handle.aborted()) {
63
+ t = r2.meta.cursor, i2 = (this._finished || (this._partialLine = i2.substring(t - this._baseIndex), this._baseIndex = t), r2 && r2.data && (this._rowCount += r2.data.length), this._finished || this._config.preview && this._rowCount >= this._config.preview);
64
+ if (a) n.postMessage({ results: r2, workerId: v.WORKER_ID, finished: i2 });
65
+ else if (U(this._config.chunk) && !e2) {
66
+ if (this._config.chunk(r2, this._handle), this._handle.paused() || this._handle.aborted()) return void (this._halted = true);
67
+ this._completeResults = r2 = void 0;
68
+ }
69
+ return this._config.step || this._config.chunk || (this._completeResults.data = this._completeResults.data.concat(r2.data), this._completeResults.errors = this._completeResults.errors.concat(r2.errors), this._completeResults.meta = r2.meta), this._completed || !i2 || !U(this._config.complete) || r2 && r2.meta.aborted || (this._config.complete(this._completeResults, this._input), this._completed = true), i2 || r2 && r2.meta.paused || this._nextChunk(), r2;
70
+ }
71
+ this._halted = true;
72
+ }, this._sendError = function(e2) {
73
+ U(this._config.error) ? this._config.error(e2) : a && this._config.error && n.postMessage({ workerId: v.WORKER_ID, error: e2, finished: false });
74
+ };
75
+ }
76
+ function f(e) {
77
+ var r2;
78
+ (e = e || {}).chunkSize || (e.chunkSize = v.RemoteChunkSize), u.call(this, e), this._nextChunk = s ? function() {
79
+ this._readChunk(), this._chunkLoaded();
80
+ } : function() {
81
+ this._readChunk();
82
+ }, this.stream = function(e2) {
83
+ this._input = e2, this._nextChunk();
84
+ }, this._readChunk = function() {
85
+ if (this._finished) this._chunkLoaded();
86
+ else {
87
+ if (r2 = new XMLHttpRequest(), this._config.withCredentials && (r2.withCredentials = this._config.withCredentials), s || (r2.onload = y(this._chunkLoaded, this), r2.onerror = y(this._chunkError, this)), r2.open(this._config.downloadRequestBody ? "POST" : "GET", this._input, !s), this._config.downloadRequestHeaders) {
88
+ var e2, t = this._config.downloadRequestHeaders;
89
+ for (e2 in t) r2.setRequestHeader(e2, t[e2]);
90
+ }
91
+ var i2;
92
+ this._config.chunkSize && (i2 = this._start + this._config.chunkSize - 1, r2.setRequestHeader("Range", "bytes=" + this._start + "-" + i2));
93
+ try {
94
+ r2.send(this._config.downloadRequestBody);
95
+ } catch (e3) {
96
+ this._chunkError(e3.message);
97
+ }
98
+ s && 0 === r2.status && this._chunkError();
99
+ }
100
+ }, this._chunkLoaded = function() {
101
+ 4 === r2.readyState && (r2.status < 200 || 400 <= r2.status ? this._chunkError() : (this._start += this._config.chunkSize || r2.responseText.length, this._finished = !this._config.chunkSize || this._start >= ((e2) => null !== (e2 = e2.getResponseHeader("Content-Range")) ? parseInt(e2.substring(e2.lastIndexOf("/") + 1)) : -1)(r2), this.parseChunk(r2.responseText)));
102
+ }, this._chunkError = function(e2) {
103
+ e2 = r2.statusText || e2;
104
+ this._sendError(new Error(e2));
105
+ };
106
+ }
107
+ function l(e) {
108
+ (e = e || {}).chunkSize || (e.chunkSize = v.LocalChunkSize), u.call(this, e);
109
+ var i2, r2, n2 = "undefined" != typeof FileReader;
110
+ this.stream = function(e2) {
111
+ this._input = e2, r2 = e2.slice || e2.webkitSlice || e2.mozSlice, n2 ? ((i2 = new FileReader()).onload = y(this._chunkLoaded, this), i2.onerror = y(this._chunkError, this)) : i2 = new FileReaderSync(), this._nextChunk();
112
+ }, this._nextChunk = function() {
113
+ this._finished || this._config.preview && !(this._rowCount < this._config.preview) || this._readChunk();
114
+ }, this._readChunk = function() {
115
+ var e2 = this._input, t = (this._config.chunkSize && (t = Math.min(this._start + this._config.chunkSize, this._input.size), e2 = r2.call(e2, this._start, t)), i2.readAsText(e2, this._config.encoding));
116
+ n2 || this._chunkLoaded({ target: { result: t } });
117
+ }, this._chunkLoaded = function(e2) {
118
+ this._start += this._config.chunkSize, this._finished = !this._config.chunkSize || this._start >= this._input.size, this.parseChunk(e2.target.result);
119
+ }, this._chunkError = function() {
120
+ this._sendError(i2.error);
121
+ };
122
+ }
123
+ function c(e) {
124
+ var i2;
125
+ u.call(this, e = e || {}), this.stream = function(e2) {
126
+ return i2 = e2, this._nextChunk();
127
+ }, this._nextChunk = function() {
128
+ var e2, t;
129
+ if (!this._finished) return e2 = this._config.chunkSize, i2 = e2 ? (t = i2.substring(0, e2), i2.substring(e2)) : (t = i2, ""), this._finished = !i2, this.parseChunk(t);
130
+ };
131
+ }
132
+ function p(e) {
133
+ u.call(this, e = e || {});
134
+ var t = [], i2 = true, r2 = false;
135
+ this.pause = function() {
136
+ u.prototype.pause.apply(this, arguments), this._input.pause();
137
+ }, this.resume = function() {
138
+ u.prototype.resume.apply(this, arguments), this._input.resume();
139
+ }, this.stream = function(e2) {
140
+ this._input = e2, this._input.on("data", this._streamData), this._input.on("end", this._streamEnd), this._input.on("error", this._streamError);
141
+ }, this._checkIsFinished = function() {
142
+ r2 && 1 === t.length && (this._finished = true);
143
+ }, this._nextChunk = function() {
144
+ this._checkIsFinished(), t.length ? this.parseChunk(t.shift()) : i2 = true;
145
+ }, this._streamData = y(function(e2) {
146
+ try {
147
+ t.push("string" == typeof e2 ? e2 : e2.toString(this._config.encoding)), i2 && (i2 = false, this._checkIsFinished(), this.parseChunk(t.shift()));
148
+ } catch (e3) {
149
+ this._streamError(e3);
150
+ }
151
+ }, this), this._streamError = y(function(e2) {
152
+ this._streamCleanUp(), this._sendError(e2);
153
+ }, this), this._streamEnd = y(function() {
154
+ this._streamCleanUp(), r2 = true, this._streamData("");
155
+ }, this), this._streamCleanUp = y(function() {
156
+ this._input.removeListener("data", this._streamData), this._input.removeListener("end", this._streamEnd), this._input.removeListener("error", this._streamError);
157
+ }, this);
158
+ }
159
+ function i(m2) {
160
+ var n2, s2, a2, t, o2 = Math.pow(2, 53), h2 = -o2, u2 = /^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/, d2 = /^((\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)))$/, i2 = this, r2 = 0, f2 = 0, l2 = false, e = false, c2 = [], p2 = { data: [], errors: [], meta: {} };
161
+ function y2(e2) {
162
+ return "greedy" === m2.skipEmptyLines ? "" === e2.join("").trim() : 1 === e2.length && 0 === e2[0].length;
163
+ }
164
+ function g2() {
165
+ if (p2 && a2 && (k("Delimiter", "UndetectableDelimiter", "Unable to auto-detect delimiting character; defaulted to '" + v.DefaultDelimiter + "'"), a2 = false), m2.skipEmptyLines && (p2.data = p2.data.filter(function(e3) {
166
+ return !y2(e3);
167
+ })), _2()) {
168
+ let t3 = function(e3, t4) {
169
+ U(m2.transformHeader) && (e3 = m2.transformHeader(e3, t4)), c2.push(e3);
170
+ };
171
+ var t2 = t3;
172
+ if (p2) if (Array.isArray(p2.data[0])) {
173
+ for (var e2 = 0; _2() && e2 < p2.data.length; e2++) p2.data[e2].forEach(t3);
174
+ p2.data.splice(0, 1);
175
+ } else p2.data.forEach(t3);
176
+ }
177
+ function i3(e3, t3) {
178
+ for (var i4 = m2.header ? {} : [], r4 = 0; r4 < e3.length; r4++) {
179
+ var n3 = r4, s3 = e3[r4], s3 = ((e4, t4) => ((e5) => (m2.dynamicTypingFunction && void 0 === m2.dynamicTyping[e5] && (m2.dynamicTyping[e5] = m2.dynamicTypingFunction(e5)), true === (m2.dynamicTyping[e5] || m2.dynamicTyping)))(e4) ? "true" === t4 || "TRUE" === t4 || "false" !== t4 && "FALSE" !== t4 && (((e5) => {
180
+ if (u2.test(e5)) {
181
+ e5 = parseFloat(e5);
182
+ if (h2 < e5 && e5 < o2) return 1;
183
+ }
184
+ })(t4) ? parseFloat(t4) : d2.test(t4) ? new Date(t4) : "" === t4 ? null : t4) : t4)(n3 = m2.header ? r4 >= c2.length ? "__parsed_extra" : c2[r4] : n3, s3 = m2.transform ? m2.transform(s3, n3) : s3);
185
+ "__parsed_extra" === n3 ? (i4[n3] = i4[n3] || [], i4[n3].push(s3)) : i4[n3] = s3;
186
+ }
187
+ return m2.header && (r4 > c2.length ? k("FieldMismatch", "TooManyFields", "Too many fields: expected " + c2.length + " fields but parsed " + r4, f2 + t3) : r4 < c2.length && k("FieldMismatch", "TooFewFields", "Too few fields: expected " + c2.length + " fields but parsed " + r4, f2 + t3)), i4;
188
+ }
189
+ var r3;
190
+ p2 && (m2.header || m2.dynamicTyping || m2.transform) && (r3 = 1, !p2.data.length || Array.isArray(p2.data[0]) ? (p2.data = p2.data.map(i3), r3 = p2.data.length) : p2.data = i3(p2.data, 0), m2.header && p2.meta && (p2.meta.fields = c2), f2 += r3);
191
+ }
192
+ function _2() {
193
+ return m2.header && 0 === c2.length;
194
+ }
195
+ function k(e2, t2, i3, r3) {
196
+ e2 = { type: e2, code: t2, message: i3 };
197
+ void 0 !== r3 && (e2.row = r3), p2.errors.push(e2);
198
+ }
199
+ U(m2.step) && (t = m2.step, m2.step = function(e2) {
200
+ p2 = e2, _2() ? g2() : (g2(), 0 !== p2.data.length && (r2 += e2.data.length, m2.preview && r2 > m2.preview ? s2.abort() : (p2.data = p2.data[0], t(p2, i2))));
201
+ }), this.parse = function(e2, t2, i3) {
202
+ var r3 = m2.quoteChar || '"', r3 = (m2.newline || (m2.newline = this.guessLineEndings(e2, r3)), a2 = false, m2.delimiter ? U(m2.delimiter) && (m2.delimiter = m2.delimiter(e2), p2.meta.delimiter = m2.delimiter) : ((r3 = ((e3, t3, i4, r4, n3) => {
203
+ var s3, a3, o3, h3;
204
+ n3 = n3 || [",", " ", "|", ";", v.RECORD_SEP, v.UNIT_SEP];
205
+ for (var u3 = 0; u3 < n3.length; u3++) {
206
+ for (var d3, f3 = n3[u3], l3 = 0, c3 = 0, p3 = 0, g3 = (o3 = void 0, new E({ comments: r4, delimiter: f3, newline: t3, preview: 10 }).parse(e3)), _3 = 0; _3 < g3.data.length; _3++) i4 && y2(g3.data[_3]) ? p3++ : (d3 = g3.data[_3].length, c3 += d3, void 0 === o3 ? o3 = d3 : 0 < d3 && (l3 += Math.abs(d3 - o3), o3 = d3));
207
+ 0 < g3.data.length && (c3 /= g3.data.length - p3), (void 0 === a3 || l3 <= a3) && (void 0 === h3 || h3 < c3) && 1.99 < c3 && (a3 = l3, s3 = f3, h3 = c3);
208
+ }
209
+ return { successful: !!(m2.delimiter = s3), bestDelimiter: s3 };
210
+ })(e2, m2.newline, m2.skipEmptyLines, m2.comments, m2.delimitersToGuess)).successful ? m2.delimiter = r3.bestDelimiter : (a2 = true, m2.delimiter = v.DefaultDelimiter), p2.meta.delimiter = m2.delimiter), b(m2));
211
+ return m2.preview && m2.header && r3.preview++, n2 = e2, s2 = new E(r3), p2 = s2.parse(n2, t2, i3), g2(), l2 ? { meta: { paused: true } } : p2 || { meta: { paused: false } };
212
+ }, this.paused = function() {
213
+ return l2;
214
+ }, this.pause = function() {
215
+ l2 = true, s2.abort(), n2 = U(m2.chunk) ? "" : n2.substring(s2.getCharIndex());
216
+ }, this.resume = function() {
217
+ i2.streamer._halted ? (l2 = false, i2.streamer.parseChunk(n2, true)) : setTimeout(i2.resume, 3);
218
+ }, this.aborted = function() {
219
+ return e;
220
+ }, this.abort = function() {
221
+ e = true, s2.abort(), p2.meta.aborted = true, U(m2.complete) && m2.complete(p2), n2 = "";
222
+ }, this.guessLineEndings = function(e2, t2) {
223
+ e2 = e2.substring(0, 1048576);
224
+ var t2 = new RegExp(P(t2) + "([^]*?)" + P(t2), "gm"), i3 = (e2 = e2.replace(t2, "")).split("\r"), t2 = e2.split("\n"), e2 = 1 < t2.length && t2[0].length < i3[0].length;
225
+ if (1 === i3.length || e2) return "\n";
226
+ for (var r3 = 0, n3 = 0; n3 < i3.length; n3++) "\n" === i3[n3][0] && r3++;
227
+ return r3 >= i3.length / 2 ? "\r\n" : "\r";
228
+ };
229
+ }
230
+ function P(e) {
231
+ return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
232
+ }
233
+ function E(C) {
234
+ var S = (C = C || {}).delimiter, O = C.newline, x = C.comments, I = C.step, A = C.preview, T = C.fastMode, D = null, L = false, F = null == C.quoteChar ? '"' : C.quoteChar, j = F;
235
+ if (void 0 !== C.escapeChar && (j = C.escapeChar), ("string" != typeof S || -1 < v.BAD_DELIMITERS.indexOf(S)) && (S = ","), x === S) throw new Error("Comment character same as delimiter");
236
+ true === x ? x = "#" : ("string" != typeof x || -1 < v.BAD_DELIMITERS.indexOf(x)) && (x = false), "\n" !== O && "\r" !== O && "\r\n" !== O && (O = "\n");
237
+ var z = 0, M = false;
238
+ this.parse = function(i2, t, r2) {
239
+ if ("string" != typeof i2) throw new Error("Input must be a string");
240
+ var n2 = i2.length, e = S.length, s2 = O.length, a2 = x.length, o2 = U(I), h2 = [], u2 = [], d2 = [], f2 = z = 0;
241
+ if (!i2) return w();
242
+ if (T || false !== T && -1 === i2.indexOf(F)) {
243
+ for (var l2 = i2.split(O), c2 = 0; c2 < l2.length; c2++) {
244
+ if (d2 = l2[c2], z += d2.length, c2 !== l2.length - 1) z += O.length;
245
+ else if (r2) return w();
246
+ if (!x || d2.substring(0, a2) !== x) {
247
+ if (o2) {
248
+ if (h2 = [], k(d2.split(S)), R(), M) return w();
249
+ } else k(d2.split(S));
250
+ if (A && A <= c2) return h2 = h2.slice(0, A), w(true);
251
+ }
252
+ }
253
+ return w();
254
+ }
255
+ for (var p2 = i2.indexOf(S, z), g2 = i2.indexOf(O, z), _2 = new RegExp(P(j) + P(F), "g"), m2 = i2.indexOf(F, z); ; ) if (i2[z] === F) for (m2 = z, z++; ; ) {
256
+ if (-1 === (m2 = i2.indexOf(F, m2 + 1))) return r2 || u2.push({ type: "Quotes", code: "MissingQuotes", message: "Quoted field unterminated", row: h2.length, index: z }), E2();
257
+ if (m2 === n2 - 1) return E2(i2.substring(z, m2).replace(_2, F));
258
+ if (F === j && i2[m2 + 1] === j) m2++;
259
+ else if (F === j || 0 === m2 || i2[m2 - 1] !== j) {
260
+ -1 !== p2 && p2 < m2 + 1 && (p2 = i2.indexOf(S, m2 + 1));
261
+ var y2 = v2(-1 === (g2 = -1 !== g2 && g2 < m2 + 1 ? i2.indexOf(O, m2 + 1) : g2) ? p2 : Math.min(p2, g2));
262
+ if (i2.substr(m2 + 1 + y2, e) === S) {
263
+ d2.push(i2.substring(z, m2).replace(_2, F)), i2[z = m2 + 1 + y2 + e] !== F && (m2 = i2.indexOf(F, z)), p2 = i2.indexOf(S, z), g2 = i2.indexOf(O, z);
264
+ break;
265
+ }
266
+ y2 = v2(g2);
267
+ if (i2.substring(m2 + 1 + y2, m2 + 1 + y2 + s2) === O) {
268
+ if (d2.push(i2.substring(z, m2).replace(_2, F)), b2(m2 + 1 + y2 + s2), p2 = i2.indexOf(S, z), m2 = i2.indexOf(F, z), o2 && (R(), M)) return w();
269
+ if (A && h2.length >= A) return w(true);
270
+ break;
271
+ }
272
+ u2.push({ type: "Quotes", code: "InvalidQuotes", message: "Trailing quote on quoted field is malformed", row: h2.length, index: z }), m2++;
273
+ }
274
+ }
275
+ else if (x && 0 === d2.length && i2.substring(z, z + a2) === x) {
276
+ if (-1 === g2) return w();
277
+ z = g2 + s2, g2 = i2.indexOf(O, z), p2 = i2.indexOf(S, z);
278
+ } else if (-1 !== p2 && (p2 < g2 || -1 === g2)) d2.push(i2.substring(z, p2)), z = p2 + e, p2 = i2.indexOf(S, z);
279
+ else {
280
+ if (-1 === g2) break;
281
+ if (d2.push(i2.substring(z, g2)), b2(g2 + s2), o2 && (R(), M)) return w();
282
+ if (A && h2.length >= A) return w(true);
283
+ }
284
+ return E2();
285
+ function k(e2) {
286
+ h2.push(e2), f2 = z;
287
+ }
288
+ function v2(e2) {
289
+ var t2 = 0;
290
+ return t2 = -1 !== e2 && (e2 = i2.substring(m2 + 1, e2)) && "" === e2.trim() ? e2.length : t2;
291
+ }
292
+ function E2(e2) {
293
+ return r2 || (void 0 === e2 && (e2 = i2.substring(z)), d2.push(e2), z = n2, k(d2), o2 && R()), w();
294
+ }
295
+ function b2(e2) {
296
+ z = e2, k(d2), d2 = [], g2 = i2.indexOf(O, z);
297
+ }
298
+ function w(e2) {
299
+ if (C.header && !t && h2.length && !L) {
300
+ var s3 = h2[0], a3 = /* @__PURE__ */ Object.create(null), o3 = new Set(s3);
301
+ let n3 = false;
302
+ for (let r3 = 0; r3 < s3.length; r3++) {
303
+ let i3 = s3[r3];
304
+ if (a3[i3 = U(C.transformHeader) ? C.transformHeader(i3, r3) : i3]) {
305
+ let e3, t2 = a3[i3];
306
+ for (; e3 = i3 + "_" + t2, t2++, o3.has(e3); ) ;
307
+ o3.add(e3), s3[r3] = e3, a3[i3]++, n3 = true, (D = null === D ? {} : D)[e3] = i3;
308
+ } else a3[i3] = 1, s3[r3] = i3;
309
+ o3.add(i3);
310
+ }
311
+ n3 && console.warn("Duplicate headers found and renamed."), L = true;
312
+ }
313
+ return { data: h2, errors: u2, meta: { delimiter: S, linebreak: O, aborted: M, truncated: !!e2, cursor: f2 + (t || 0), renamedHeaders: D } };
314
+ }
315
+ function R() {
316
+ I(w()), h2 = [], u2 = [];
317
+ }
318
+ }, this.abort = function() {
319
+ M = true;
320
+ }, this.getCharIndex = function() {
321
+ return z;
322
+ };
323
+ }
324
+ function g(e) {
325
+ var t = e.data, i2 = o[t.workerId], r2 = false;
326
+ if (t.error) i2.userError(t.error, t.file);
327
+ else if (t.results && t.results.data) {
328
+ var n2 = { abort: function() {
329
+ r2 = true, _(t.workerId, { data: [], errors: [], meta: { aborted: true } });
330
+ }, pause: m, resume: m };
331
+ if (U(i2.userStep)) {
332
+ for (var s2 = 0; s2 < t.results.data.length && (i2.userStep({ data: t.results.data[s2], errors: t.results.errors, meta: t.results.meta }, n2), !r2); s2++) ;
333
+ delete t.results;
334
+ } else U(i2.userChunk) && (i2.userChunk(t.results, n2, t.file), delete t.results);
335
+ }
336
+ t.finished && !r2 && _(t.workerId, t.results);
337
+ }
338
+ function _(e, t) {
339
+ var i2 = o[e];
340
+ U(i2.userComplete) && i2.userComplete(t), i2.terminate(), delete o[e];
341
+ }
342
+ function m() {
343
+ throw new Error("Not implemented.");
344
+ }
345
+ function b(e) {
346
+ if ("object" != typeof e || null === e) return e;
347
+ var t, i2 = Array.isArray(e) ? [] : {};
348
+ for (t in e) i2[t] = b(e[t]);
349
+ return i2;
350
+ }
351
+ function y(e, t) {
352
+ return function() {
353
+ e.apply(t, arguments);
354
+ };
355
+ }
356
+ function U(e) {
357
+ return "function" == typeof e;
358
+ }
359
+ return v.parse = function(e, t) {
360
+ var i2 = (t = t || {}).dynamicTyping || false;
361
+ U(i2) && (t.dynamicTypingFunction = i2, i2 = {});
362
+ if (t.dynamicTyping = i2, t.transform = !!U(t.transform) && t.transform, !t.worker || !v.WORKERS_SUPPORTED) return i2 = null, v.NODE_STREAM_INPUT, "string" == typeof e ? (e = ((e2) => 65279 !== e2.charCodeAt(0) ? e2 : e2.slice(1))(e), i2 = new (t.download ? f : c)(t)) : true === e.readable && U(e.read) && U(e.on) ? i2 = new p(t) : (n.File && e instanceof File || e instanceof Object) && (i2 = new l(t)), i2.stream(e);
363
+ (i2 = (() => {
364
+ var e2;
365
+ return !!v.WORKERS_SUPPORTED && (e2 = (() => {
366
+ var e3 = n.URL || n.webkitURL || null, t2 = r.toString();
367
+ return v.BLOB_URL || (v.BLOB_URL = e3.createObjectURL(new Blob(["var global = (function() { if (typeof self !== 'undefined') { return self; } if (typeof window !== 'undefined') { return window; } if (typeof global !== 'undefined') { return global; } return {}; })(); global.IS_PAPA_WORKER=true; ", "(", t2, ")();"], { type: "text/javascript" })));
368
+ })(), (e2 = new n.Worker(e2)).onmessage = g, e2.id = h++, o[e2.id] = e2);
369
+ })()).userStep = t.step, i2.userChunk = t.chunk, i2.userComplete = t.complete, i2.userError = t.error, t.step = U(t.step), t.chunk = U(t.chunk), t.complete = U(t.complete), t.error = U(t.error), delete t.worker, i2.postMessage({ input: e, config: t, workerId: i2.id });
370
+ }, v.unparse = function(e, t) {
371
+ var n2 = false, _2 = true, m2 = ",", y2 = "\r\n", s2 = '"', a2 = s2 + s2, i2 = false, r2 = null, o2 = false, h2 = ((() => {
372
+ if ("object" == typeof t) {
373
+ if ("string" != typeof t.delimiter || v.BAD_DELIMITERS.filter(function(e2) {
374
+ return -1 !== t.delimiter.indexOf(e2);
375
+ }).length || (m2 = t.delimiter), "boolean" != typeof t.quotes && "function" != typeof t.quotes && !Array.isArray(t.quotes) || (n2 = t.quotes), "boolean" != typeof t.skipEmptyLines && "string" != typeof t.skipEmptyLines || (i2 = t.skipEmptyLines), "string" == typeof t.newline && (y2 = t.newline), "string" == typeof t.quoteChar && (s2 = t.quoteChar), "boolean" == typeof t.header && (_2 = t.header), Array.isArray(t.columns)) {
376
+ if (0 === t.columns.length) throw new Error("Option columns is empty");
377
+ r2 = t.columns;
378
+ }
379
+ void 0 !== t.escapeChar && (a2 = t.escapeChar + s2), t.escapeFormulae instanceof RegExp ? o2 = t.escapeFormulae : "boolean" == typeof t.escapeFormulae && t.escapeFormulae && (o2 = /^[=+\-@\t\r].*$/);
380
+ }
381
+ })(), new RegExp(P(s2), "g"));
382
+ "string" == typeof e && (e = JSON.parse(e));
383
+ if (Array.isArray(e)) {
384
+ if (!e.length || Array.isArray(e[0])) return u2(null, e, i2);
385
+ if ("object" == typeof e[0]) return u2(r2 || Object.keys(e[0]), e, i2);
386
+ } else if ("object" == typeof e) return "string" == typeof e.data && (e.data = JSON.parse(e.data)), Array.isArray(e.data) && (e.fields || (e.fields = e.meta && e.meta.fields || r2), e.fields || (e.fields = Array.isArray(e.data[0]) ? e.fields : "object" == typeof e.data[0] ? Object.keys(e.data[0]) : []), Array.isArray(e.data[0]) || "object" == typeof e.data[0] || (e.data = [e.data])), u2(e.fields || [], e.data || [], i2);
387
+ throw new Error("Unable to serialize unrecognized input");
388
+ function u2(e2, t2, i3) {
389
+ var r3 = "", n3 = ("string" == typeof e2 && (e2 = JSON.parse(e2)), "string" == typeof t2 && (t2 = JSON.parse(t2)), Array.isArray(e2) && 0 < e2.length), s3 = !Array.isArray(t2[0]);
390
+ if (n3 && _2) {
391
+ for (var a3 = 0; a3 < e2.length; a3++) 0 < a3 && (r3 += m2), r3 += k(e2[a3], a3);
392
+ 0 < t2.length && (r3 += y2);
393
+ }
394
+ for (var o3 = 0; o3 < t2.length; o3++) {
395
+ var h3 = (n3 ? e2 : t2[o3]).length, u3 = false, d2 = n3 ? 0 === Object.keys(t2[o3]).length : 0 === t2[o3].length;
396
+ if (i3 && !n3 && (u3 = "greedy" === i3 ? "" === t2[o3].join("").trim() : 1 === t2[o3].length && 0 === t2[o3][0].length), "greedy" === i3 && n3) {
397
+ for (var f2 = [], l2 = 0; l2 < h3; l2++) {
398
+ var c2 = s3 ? e2[l2] : l2;
399
+ f2.push(t2[o3][c2]);
400
+ }
401
+ u3 = "" === f2.join("").trim();
402
+ }
403
+ if (!u3) {
404
+ for (var p2 = 0; p2 < h3; p2++) {
405
+ 0 < p2 && !d2 && (r3 += m2);
406
+ var g2 = n3 && s3 ? e2[p2] : p2;
407
+ r3 += k(t2[o3][g2], p2);
408
+ }
409
+ o3 < t2.length - 1 && (!i3 || 0 < h3 && !d2) && (r3 += y2);
410
+ }
411
+ }
412
+ return r3;
413
+ }
414
+ function k(e2, t2) {
415
+ var i3, r3;
416
+ return null == e2 ? "" : e2.constructor === Date ? JSON.stringify(e2).slice(1, 25) : (r3 = false, o2 && "string" == typeof e2 && o2.test(e2) && (e2 = "'" + e2, r3 = true), i3 = e2.toString().replace(h2, a2), (r3 = r3 || true === n2 || "function" == typeof n2 && n2(e2, t2) || Array.isArray(n2) && n2[t2] || ((e3, t3) => {
417
+ for (var i4 = 0; i4 < t3.length; i4++) if (-1 < e3.indexOf(t3[i4])) return true;
418
+ return false;
419
+ })(i3, v.BAD_DELIMITERS) || -1 < i3.indexOf(m2) || " " === i3.charAt(0) || " " === i3.charAt(i3.length - 1)) ? s2 + i3 + s2 : i3);
420
+ }
421
+ }, v.RECORD_SEP = String.fromCharCode(30), v.UNIT_SEP = String.fromCharCode(31), v.BYTE_ORDER_MARK = "\uFEFF", v.BAD_DELIMITERS = ["\r", "\n", '"', v.BYTE_ORDER_MARK], v.WORKERS_SUPPORTED = !s && !!n.Worker, v.NODE_STREAM_INPUT = 1, v.LocalChunkSize = 10485760, v.RemoteChunkSize = 5242880, v.DefaultDelimiter = ",", v.Parser = E, v.ParserHandle = i, v.NetworkStreamer = f, v.FileStreamer = l, v.StringStreamer = c, v.ReadableStreamStreamer = p, n.jQuery && ((d = n.jQuery).fn.parse = function(o2) {
422
+ var i2 = o2.config || {}, h2 = [];
423
+ return this.each(function(e2) {
424
+ if (!("INPUT" === d(this).prop("tagName").toUpperCase() && "file" === d(this).attr("type").toLowerCase() && n.FileReader) || !this.files || 0 === this.files.length) return true;
425
+ for (var t = 0; t < this.files.length; t++) h2.push({ file: this.files[t], inputElem: this, instanceConfig: d.extend({}, i2) });
426
+ }), e(), this;
427
+ function e() {
428
+ if (0 === h2.length) U(o2.complete) && o2.complete();
429
+ else {
430
+ var e2, t, i3, r2, n2 = h2[0];
431
+ if (U(o2.before)) {
432
+ var s2 = o2.before(n2.file, n2.inputElem);
433
+ if ("object" == typeof s2) {
434
+ if ("abort" === s2.action) return e2 = "AbortError", t = n2.file, i3 = n2.inputElem, r2 = s2.reason, void (U(o2.error) && o2.error({ name: e2 }, t, i3, r2));
435
+ if ("skip" === s2.action) return void u2();
436
+ "object" == typeof s2.config && (n2.instanceConfig = d.extend(n2.instanceConfig, s2.config));
437
+ } else if ("skip" === s2) return void u2();
438
+ }
439
+ var a2 = n2.instanceConfig.complete;
440
+ n2.instanceConfig.complete = function(e3) {
441
+ U(a2) && a2(e3, n2.file, n2.inputElem), u2();
442
+ }, v.parse(n2.file, n2.instanceConfig);
443
+ }
444
+ }
445
+ function u2() {
446
+ h2.splice(0, 1), e();
447
+ }
448
+ }), a && (n.onmessage = function(e) {
449
+ e = e.data;
450
+ void 0 === v.WORKER_ID && e && (v.WORKER_ID = e.workerId);
451
+ "string" == typeof e.input ? n.postMessage({ workerId: v.WORKER_ID, results: v.parse(e.input, e.config), finished: true }) : (n.File && e.input instanceof File || e.input instanceof Object) && (e = v.parse(e.input, e.config)) && n.postMessage({ workerId: v.WORKER_ID, results: e, finished: true });
452
+ }), (f.prototype = Object.create(u.prototype)).constructor = f, (l.prototype = Object.create(u.prototype)).constructor = l, (c.prototype = Object.create(c.prototype)).constructor = c, (p.prototype = Object.create(u.prototype)).constructor = p, v;
453
+ });
454
+ }
455
+ });
456
+
457
+ // packages/library/client.tsx
458
+ var client_exports = {};
459
+ __export(client_exports, {
460
+ apply: () => apply,
461
+ inject: () => inject,
462
+ name: () => name
463
+ });
464
+ module.exports = __toCommonJS(client_exports);
465
+
466
+ // packages/library/src/panel.tsx
467
+ var React = __toESM(require("react"), 1);
468
+ var import_react4 = require("react");
469
+
470
+ // shared/ui/primitives.tsx
471
+ var import_react = require("react");
472
+
473
+ // shared/ui/icons.tsx
474
+ var import_jsx_runtime = require("react/jsx-runtime");
475
+ function Svg({ size = 16, className, children }) {
476
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
477
+ "svg",
478
+ {
479
+ width: size,
480
+ height: size,
481
+ viewBox: "0 0 24 24",
482
+ fill: "none",
483
+ stroke: "currentColor",
484
+ strokeWidth: 1.8,
485
+ strokeLinecap: "round",
486
+ strokeLinejoin: "round",
487
+ "aria-hidden": "true",
488
+ focusable: "false",
489
+ className,
490
+ style: { display: "block", flex: "none" },
491
+ children
492
+ }
493
+ );
494
+ }
495
+ var IconClose = (p) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Svg, { ...p, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6 6l12 12M18 6 6 18" }) });
496
+
497
+ // shared/ui/tokens.ts
498
+ var baseCss = `
499
+ .dshs-root {
500
+ height: 100%;
501
+ min-height: 0;
502
+ overflow: auto;
503
+ color: var(--dsw-alias-label-primary);
504
+ background: var(--dsw-alias-bg-base);
505
+ font-size: 14px;
506
+ line-height: 1.55;
507
+ -webkit-font-smoothing: antialiased;
508
+ --dshs-muted: var(--dsw-alias-label-secondary);
509
+ }
510
+ .dshs-page { max-width: 1180px; margin: 0 auto; padding: 24px 32px 72px; }
511
+ .dshs-page--wide { max-width: 1320px; }
512
+
513
+ .dshs-title { margin: 0; font-size: 24px; line-height: 1.25; font-weight: 700; letter-spacing: -0.01em; }
514
+ .dshs-subtitle { margin: 6px 0 0; color: var(--dshs-muted); font-size: 13.5px; }
515
+ .dshs-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin: 18px 0 22px; }
516
+ .dshs-section { margin-top: 28px; }
517
+ .dshs-section__title { margin: 0 0 12px; font-size: 14px; font-weight: 650; }
518
+
519
+ .dshs-card {
520
+ border: 1px solid var(--dsw-alias-border-l1);
521
+ border-radius: 12px;
522
+ background: var(--dsw-alias-bg-layer-1);
523
+ overflow: hidden;
524
+ }
525
+ .dshs-row {
526
+ display: flex; align-items: center; gap: 12px;
527
+ padding: 12px 16px;
528
+ border-top: 1px solid var(--dsw-alias-border-l1);
529
+ }
530
+ .dshs-row:first-child { border-top: 0; }
531
+ .dshs-row__main { flex: 1; min-width: 0; }
532
+ .dshs-row__name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
533
+ .dshs-row__meta { color: var(--dshs-muted); font-size: 12.5px; overflow-wrap: anywhere; }
534
+
535
+ .dshs-muted { color: var(--dshs-muted); }
536
+ .dshs-idle { color: var(--dsw-alias-state-idle-primary); }
537
+ .dshs-error { color: var(--dsw-alias-state-error-primary); }
538
+ .dshs-warn { color: var(--dsw-alias-state-warn-primary); }
539
+ .dshs-ok { color: var(--dsw-alias-state-success-primary); }
540
+ .dshs-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; overflow-wrap: anywhere; }
541
+ .dshs-empty { padding: 40px 16px; text-align: center; color: var(--dshs-muted); }
542
+ .dshs-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
543
+ .dshs-stack { display: flex; flex-direction: column; gap: 12px; }
544
+ .dshs-inline { display: flex; align-items: center; gap: 8px; }
545
+ .dshs-grow { flex: 1; min-width: 0; }
546
+ `;
547
+ var layoutCss = `
548
+ /* ---- capability switcher: the tabs across the top of every panel ---- */
549
+ .dshs-caps { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
550
+ .dshs-cap {
551
+ display: inline-flex; align-items: center; gap: 7px;
552
+ height: 34px; padding: 0 13px;
553
+ border: 1px solid transparent; border-radius: 9px;
554
+ background: transparent; color: var(--dshs-muted);
555
+ font: inherit; font-size: 13.5px; cursor: pointer;
556
+ }
557
+ .dshs-cap:hover:not(:disabled) { background: var(--dsw-alias-bg-layer-2); color: var(--dsw-alias-label-primary); }
558
+ .dshs-cap[aria-current="page"] {
559
+ background: var(--dsw-alias-bg-layer-2);
560
+ border-color: var(--dsw-alias-border-l1);
561
+ color: var(--dsw-alias-label-primary);
562
+ font-weight: 600;
563
+ }
564
+ .dshs-cap:disabled { opacity: 0.45; cursor: default; }
565
+ .dshs-cap:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 1px; }
566
+
567
+ /* ---- toolbar: search plus actions, under the switcher ---- */
568
+ .dshs-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
569
+ .dshs-toolbar .dshs-search { flex: 1; min-width: 200px; max-width: 380px; }
570
+
571
+ /* ---- filter chips (\u5168\u90E8 / \u9ED8\u8BA4 / \u6211\u7684) ---- */
572
+ .dshs-segmented {
573
+ display: inline-flex; align-items: center; gap: 4px;
574
+ padding: 3px; border: 1px solid var(--dsw-alias-border-l1); border-radius: 10px;
575
+ background: var(--dsw-alias-bg-layer-1);
576
+ }
577
+ .dshs-segmented button {
578
+ height: 28px; padding: 0 14px;
579
+ border: 0; border-radius: 7px; background: transparent;
580
+ color: var(--dshs-muted); font: inherit; font-size: 13px; cursor: pointer;
581
+ }
582
+ .dshs-segmented button:hover:not([aria-pressed="true"]) { color: var(--dsw-alias-label-primary); }
583
+ .dshs-segmented button[aria-pressed="true"] {
584
+ background: var(--dsw-alias-bg-layer-2);
585
+ color: var(--dsw-alias-label-primary);
586
+ font-weight: 600;
587
+ }
588
+ .dshs-segmented button:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 1px; }
589
+
590
+ /* ---- count line ---- */
591
+ .dshs-count { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 22px 0 12px; color: var(--dshs-muted); font-size: 13px; }
592
+
593
+ /* ---- card grid ---- */
594
+ .dshs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(276px, 1fr)); gap: 16px; }
595
+ .dshs-grid--wide { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
596
+
597
+ .dshs-tilecard {
598
+ display: flex; flex-direction: column; gap: 10px;
599
+ padding: 16px;
600
+ border: 1px solid var(--dsw-alias-border-l1); border-radius: 12px;
601
+ background: var(--dsw-alias-bg-layer-1);
602
+ color: inherit; text-align: left; font: inherit;
603
+ }
604
+ .dshs-tilecard--interactive { cursor: pointer; transition: border-color 120ms ease, background 120ms ease; }
605
+ .dshs-tilecard--interactive:hover { border-color: var(--dsw-alias-border-l2); background: var(--dsw-alias-bg-layer-2); }
606
+ .dshs-tilecard--muted { opacity: 0.62; }
607
+ .dshs-tilecard__head { display: flex; align-items: flex-start; gap: 12px; }
608
+ .dshs-tilecard__title { font-size: 15px; font-weight: 650; overflow-wrap: anywhere; }
609
+ .dshs-tilecard__sub { margin-top: 3px; color: var(--dshs-muted); font-size: 12.5px; overflow-wrap: anywhere; }
610
+ .dshs-tilecard__body { color: var(--dshs-muted); font-size: 13px; }
611
+ .dshs-tilecard__foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: auto; padding-top: 2px; color: var(--dshs-muted); font-size: 12.5px; }
612
+
613
+ /* ---- icon tile: the coloured square every card leads with ---- */
614
+ .dshs-tile {
615
+ display: grid; place-items: center;
616
+ width: 42px; height: 42px; flex: none;
617
+ border-radius: 11px;
618
+ background: var(--dsw-alias-bg-layer-2);
619
+ color: var(--dsw-alias-label-primary);
620
+ font-size: 16px; font-weight: 700; line-height: 1;
621
+ user-select: none;
622
+ }
623
+ .dshs-tile--lg { width: 52px; height: 52px; border-radius: 14px; font-size: 19px; }
624
+ .dshs-tile--sm { width: 32px; height: 32px; border-radius: 9px; font-size: 13px; }
625
+ /* Hues are mixed into the theme surface so they survive both themes. */
626
+ .dshs-tile[data-hue="0"] { background: color-mix(in srgb, #14b8a6 22%, var(--dsw-alias-bg-layer-2)); color: #14b8a6; }
627
+ .dshs-tile[data-hue="1"] { background: color-mix(in srgb, #6366f1 22%, var(--dsw-alias-bg-layer-2)); color: #818cf8; }
628
+ .dshs-tile[data-hue="2"] { background: color-mix(in srgb, #f97316 22%, var(--dsw-alias-bg-layer-2)); color: #fb923c; }
629
+ .dshs-tile[data-hue="3"] { background: color-mix(in srgb, #a855f7 22%, var(--dsw-alias-bg-layer-2)); color: #c084fc; }
630
+ .dshs-tile[data-hue="4"] { background: color-mix(in srgb, #0ea5e9 22%, var(--dsw-alias-bg-layer-2)); color: #38bdf8; }
631
+ .dshs-tile[data-hue="5"] { background: color-mix(in srgb, #ec4899 22%, var(--dsw-alias-bg-layer-2)); color: #f472b6; }
632
+ .dshs-tile[data-hue="6"] { background: color-mix(in srgb, #22c55e 22%, var(--dsw-alias-bg-layer-2)); color: #4ade80; }
633
+ .dshs-tile[data-hue="7"] { background: color-mix(in srgb, #eab308 22%, var(--dsw-alias-bg-layer-2)); color: #facc15; }
634
+
635
+ /* ---- tag chips and status pills ---- */
636
+ .dshs-tags { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
637
+ .dshs-tag {
638
+ padding: 2px 9px;
639
+ border: 1px solid var(--dsw-alias-border-l1); border-radius: 999px;
640
+ color: var(--dshs-muted); font-size: 11.5px; line-height: 1.7; white-space: nowrap;
641
+ }
642
+ .dshs-pill {
643
+ display: inline-flex; align-items: center; gap: 5px;
644
+ padding: 2px 9px;
645
+ border: 1px solid var(--dsw-alias-border-l1); border-radius: 999px;
646
+ font-size: 11.5px; line-height: 1.7; white-space: nowrap;
647
+ color: var(--dshs-muted);
648
+ }
649
+ .dshs-pill--ok { color: var(--dsw-alias-state-success-primary); border-color: color-mix(in srgb, var(--dsw-alias-state-success-primary) 45%, transparent); }
650
+ .dshs-pill--warn { color: var(--dsw-alias-state-warn-primary); border-color: color-mix(in srgb, var(--dsw-alias-state-warn-primary) 45%, transparent); }
651
+ .dshs-pill--error { color: var(--dsw-alias-state-error-primary); border-color: color-mix(in srgb, var(--dsw-alias-state-error-primary) 45%, transparent); }
652
+ .dshs-pill--idle { color: var(--dsw-alias-state-idle-primary); }
653
+ .dshs-pill__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
654
+
655
+ /* ---- two-pane layout used by the library ---- */
656
+ .dshs-split { display: grid; grid-template-columns: minmax(220px, 280px) minmax(0, 1fr); gap: 20px; align-items: start; }
657
+ @media (max-width: 860px) { .dshs-split { grid-template-columns: minmax(0, 1fr); } }
658
+
659
+ /* ---- empty state with a leading icon tile ---- */
660
+ .dshs-blank { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 56px 20px; text-align: center; }
661
+ .dshs-blank__title { font-size: 17px; font-weight: 650; }
662
+ .dshs-blank__text { color: var(--dshs-muted); max-width: 420px; }
663
+ `;
664
+ var controlsCss = `
665
+ .dshs-btn {
666
+ display: inline-flex; align-items: center; justify-content: center; gap: 6px;
667
+ height: 34px; padding: 0 14px;
668
+ border: 1px solid var(--dsw-alias-border-l1);
669
+ border-radius: 9px;
670
+ background: var(--dsw-alias-bg-layer-1);
671
+ color: var(--dsw-alias-label-primary);
672
+ font: inherit; font-size: 13.5px; cursor: pointer;
673
+ white-space: nowrap;
674
+ }
675
+ .dshs-btn:hover:not(:disabled) { border-color: var(--dsw-alias-border-l2); background: var(--dsw-alias-bg-layer-2); }
676
+ .dshs-btn:disabled { opacity: 0.5; cursor: not-allowed; }
677
+ .dshs-btn:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 1px; }
678
+ /* The reference's primary action is a filled, high-contrast button. */
679
+ .dshs-btn--primary {
680
+ background: var(--dsw-alias-label-primary);
681
+ border-color: var(--dsw-alias-label-primary);
682
+ color: var(--dsw-alias-bg-base);
683
+ font-weight: 600;
684
+ }
685
+ .dshs-btn--primary:hover:not(:disabled) { opacity: 0.88; background: var(--dsw-alias-label-primary); border-color: var(--dsw-alias-label-primary); }
686
+ .dshs-btn--ghost { background: transparent; border-color: transparent; color: var(--dshs-muted); }
687
+ .dshs-btn--ghost:hover:not(:disabled) { background: var(--dsw-alias-bg-layer-2); color: var(--dsw-alias-label-primary); }
688
+ .dshs-btn--danger { color: var(--dsw-alias-state-error-primary); }
689
+ .dshs-btn--danger:hover:not(:disabled) { border-color: color-mix(in srgb, var(--dsw-alias-state-error-primary) 45%, transparent); }
690
+ .dshs-btn--sm { height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }
691
+ .dshs-iconbtn {
692
+ display: inline-flex; align-items: center; justify-content: center;
693
+ width: 30px; height: 30px; padding: 0;
694
+ border: 1px solid transparent; border-radius: 8px;
695
+ background: transparent; color: var(--dshs-muted); cursor: pointer;
696
+ }
697
+ .dshs-iconbtn:hover:not(:disabled) { background: var(--dsw-alias-bg-layer-2); color: var(--dsw-alias-label-primary); }
698
+ .dshs-iconbtn:disabled { opacity: 0.45; cursor: not-allowed; }
699
+ .dshs-iconbtn:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 1px; }
700
+
701
+ .dshs-input, .dshs-textarea, .dshs-select {
702
+ width: 100%; box-sizing: border-box;
703
+ min-height: 34px; padding: 7px 11px;
704
+ border: 1px solid var(--dsw-alias-border-l1); border-radius: 9px;
705
+ background: var(--dsw-alias-bg-layer-1);
706
+ color: var(--dsw-alias-label-primary);
707
+ font: inherit; font-size: 13.5px;
708
+ }
709
+ .dshs-textarea { min-height: 96px; resize: vertical; line-height: 1.6; }
710
+ .dshs-select { appearance: auto; }
711
+ .dshs-input:focus-visible, .dshs-textarea:focus-visible, .dshs-select:focus-visible {
712
+ outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: -1px; border-color: var(--dsw-alias-brand-primary);
713
+ }
714
+ .dshs-input::placeholder, .dshs-textarea::placeholder { color: var(--dsw-alias-state-idle-primary); }
715
+ .dshs-field { display: flex; flex-direction: column; gap: 6px; }
716
+ .dshs-field__label { font-size: 12.5px; font-weight: 550; color: var(--dshs-muted); }
717
+ .dshs-field__hint { font-size: 12px; color: var(--dshs-muted); }
718
+ .dshs-field__error { font-size: 12px; color: var(--dsw-alias-state-error-primary); }
719
+
720
+ .dshs-badge {
721
+ display: inline-flex; align-items: center; gap: 4px;
722
+ padding: 1px 8px; border-radius: 999px;
723
+ border: 1px solid var(--dsw-alias-border-l1);
724
+ font-size: 11.5px; color: var(--dshs-muted); white-space: nowrap;
725
+ }
726
+ .dshs-badge--ok { color: var(--dsw-alias-state-success-primary); border-color: color-mix(in srgb, var(--dsw-alias-state-success-primary) 45%, transparent); }
727
+ .dshs-badge--warn { color: var(--dsw-alias-state-warn-primary); border-color: color-mix(in srgb, var(--dsw-alias-state-warn-primary) 45%, transparent); }
728
+ .dshs-badge--error { color: var(--dsw-alias-state-error-primary); border-color: color-mix(in srgb, var(--dsw-alias-state-error-primary) 45%, transparent); }
729
+ .dshs-badge--idle { color: var(--dsw-alias-state-idle-primary); }
730
+
731
+ .dshs-switch {
732
+ position: relative; flex: none;
733
+ width: 34px; height: 20px; padding: 0;
734
+ border: 1px solid var(--dsw-alias-border-l2); border-radius: 999px;
735
+ background: var(--dsw-alias-bg-layer-2); cursor: pointer; transition: background 120ms ease;
736
+ }
737
+ .dshs-switch[aria-checked="true"] { background: var(--dsw-alias-brand-primary); border-color: var(--dsw-alias-brand-primary); }
738
+ .dshs-switch:disabled { opacity: 0.5; cursor: not-allowed; }
739
+ .dshs-switch:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 2px; }
740
+ .dshs-switch__knob {
741
+ position: absolute; top: 1px; left: 1px;
742
+ width: 16px; height: 16px; border-radius: 50%;
743
+ background: var(--dsw-alias-bg-base); transition: transform 120ms ease;
744
+ }
745
+ .dshs-switch[aria-checked="true"] .dshs-switch__knob { transform: translateX(14px); }
746
+
747
+ .dshs-spinner {
748
+ width: 14px; height: 14px; flex: none;
749
+ border: 2px solid var(--dsw-alias-border-l2); border-top-color: var(--dsw-alias-brand-primary);
750
+ border-radius: 50%; animation: dshs-spin 700ms linear infinite;
751
+ }
752
+ @keyframes dshs-spin { to { transform: rotate(360deg); } }
753
+ @media (prefers-reduced-motion: reduce) { .dshs-spinner { animation-duration: 2s; } }
754
+ `;
755
+ var modalCss = `
756
+ .dshs-overlay {
757
+ position: fixed; inset: 0; z-index: 60;
758
+ display: flex; align-items: center; justify-content: center;
759
+ padding: 24px;
760
+ background: color-mix(in srgb, var(--dsw-alias-bg-base) 62%, transparent);
761
+ }
762
+ .dshs-modal {
763
+ display: flex; flex-direction: column;
764
+ width: min(600px, 100%); max-height: min(84vh, 760px);
765
+ border: 1px solid var(--dsw-alias-border-l1); border-radius: 14px;
766
+ background: var(--dsw-alias-bg-overlay);
767
+ box-shadow: 0 16px 48px rgb(0 0 0 / 26%);
768
+ }
769
+ .dshs-modal__head { display: flex; align-items: center; gap: 12px; padding: 18px 20px 12px; }
770
+ .dshs-modal__title { margin: 0; font-size: 16px; font-weight: 650; flex: 1; }
771
+ .dshs-modal__body { padding: 4px 20px 18px; overflow: auto; }
772
+ .dshs-modal__foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px 18px; border-top: 1px solid var(--dsw-alias-border-l1); }
773
+ `;
774
+ var allCss = `${baseCss}
775
+ ${layoutCss}
776
+ ${controlsCss}
777
+ ${modalCss}`;
778
+
779
+ // shared/ui/primitives.tsx
780
+ var import_jsx_runtime2 = require("react/jsx-runtime");
781
+ function Styles() {
782
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("style", { "data-dsh-plugin-ui": "1", children: allCss });
783
+ }
784
+ function Button({
785
+ variant = "default",
786
+ size = "md",
787
+ type = "button",
788
+ disabled = false,
789
+ onClick,
790
+ ariaLabel,
791
+ title,
792
+ children
793
+ }) {
794
+ const classes = ["dshs-btn"];
795
+ if (variant !== "default") classes.push(`dshs-btn--${variant}`);
796
+ if (size === "sm") classes.push("dshs-btn--sm");
797
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type, className: classes.join(" "), disabled, onClick, "aria-label": ariaLabel, title, children });
798
+ }
799
+ function IconButton({
800
+ label,
801
+ disabled = false,
802
+ onClick,
803
+ children
804
+ }) {
805
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "dshs-iconbtn", "aria-label": label, title: label, disabled, onClick, children });
806
+ }
807
+ function Input({
808
+ value,
809
+ onChange,
810
+ placeholder,
811
+ disabled = false,
812
+ type = "text",
813
+ ariaLabel,
814
+ autoFocus = false,
815
+ onEnter
816
+ }) {
817
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
818
+ "input",
819
+ {
820
+ className: "dshs-input",
821
+ type,
822
+ value,
823
+ placeholder,
824
+ disabled,
825
+ "aria-label": ariaLabel,
826
+ autoFocus,
827
+ onKeyDown: onEnter ? (event) => {
828
+ if (event.key === "Enter" && !event.nativeEvent.isComposing) onEnter();
829
+ } : void 0,
830
+ onChange: (event) => onChange(event.currentTarget.value)
831
+ }
832
+ );
833
+ }
834
+ function Textarea({
835
+ value,
836
+ onChange,
837
+ placeholder,
838
+ rows = 4,
839
+ disabled = false,
840
+ ariaLabel
841
+ }) {
842
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
843
+ "textarea",
844
+ {
845
+ className: "dshs-textarea",
846
+ value,
847
+ rows,
848
+ placeholder,
849
+ disabled,
850
+ "aria-label": ariaLabel,
851
+ onChange: (event) => onChange(event.currentTarget.value)
852
+ }
853
+ );
854
+ }
855
+ function Select({
856
+ value,
857
+ options,
858
+ onChange,
859
+ disabled = false,
860
+ ariaLabel
861
+ }) {
862
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
863
+ "select",
864
+ {
865
+ className: "dshs-select",
866
+ value,
867
+ disabled,
868
+ "aria-label": ariaLabel,
869
+ onChange: (event) => onChange(event.currentTarget.value),
870
+ children: options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: option.value, children: option.label }, option.value))
871
+ }
872
+ );
873
+ }
874
+ function Modal({
875
+ open = false,
876
+ title,
877
+ closeLabel = "\u5173\u95ED",
878
+ onClose,
879
+ footer,
880
+ className,
881
+ children
882
+ }) {
883
+ const panelRef = (0, import_react.useRef)(null);
884
+ const restoreRef = (0, import_react.useRef)(null);
885
+ (0, import_react.useEffect)(() => {
886
+ if (!open) return;
887
+ restoreRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
888
+ const panel = panelRef.current;
889
+ const first = panel?.querySelector('input, textarea, select, button, [tabindex]:not([tabindex="-1"])');
890
+ (first ?? panel)?.focus();
891
+ return () => restoreRef.current?.focus?.();
892
+ }, [open]);
893
+ (0, import_react.useEffect)(() => {
894
+ if (!open) return void 0;
895
+ const onKeyDown = (event) => {
896
+ if (event.key === "Escape") {
897
+ event.preventDefault();
898
+ event.stopPropagation();
899
+ onClose();
900
+ return;
901
+ }
902
+ if (event.key !== "Tab") return;
903
+ const panel = panelRef.current;
904
+ if (panel === null) return;
905
+ const focusable = [...panel.querySelectorAll('input, textarea, select, button, [tabindex]:not([tabindex="-1"])')].filter((node) => !node.hasAttribute("disabled"));
906
+ if (focusable.length === 0) return;
907
+ const first = focusable[0];
908
+ const last = focusable[focusable.length - 1];
909
+ const active = document.activeElement;
910
+ if (event.shiftKey && (active === first || !panel.contains(active))) {
911
+ event.preventDefault();
912
+ last.focus();
913
+ } else if (!event.shiftKey && active === last) {
914
+ event.preventDefault();
915
+ first.focus();
916
+ }
917
+ };
918
+ document.addEventListener("keydown", onKeyDown, true);
919
+ return () => document.removeEventListener("keydown", onKeyDown, true);
920
+ }, [open, onClose]);
921
+ if (!open) return null;
922
+ if (className !== void 0) {
923
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
924
+ "div",
925
+ {
926
+ className: "dshs-overlay",
927
+ onMouseDown: (event) => {
928
+ if (event.target === event.currentTarget) onClose();
929
+ },
930
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className, role: "dialog", "aria-modal": "true", "aria-label": title, tabIndex: -1, ref: panelRef, children: [
931
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Styles, {}),
932
+ children
933
+ ] })
934
+ }
935
+ );
936
+ }
937
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
938
+ "div",
939
+ {
940
+ className: "dshs-overlay",
941
+ onMouseDown: (event) => {
942
+ if (event.target === event.currentTarget) onClose();
943
+ },
944
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dshs-modal", role: "dialog", "aria-modal": "true", "aria-label": title, tabIndex: -1, ref: panelRef, children: [
945
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Styles, {}),
946
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dshs-modal__head", children: [
947
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h2", { className: "dshs-modal__title", children: title }),
948
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IconButton, { label: closeLabel, onClick: onClose, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IconClose, {}) })
949
+ ] }),
950
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dshs-modal__body", children }),
951
+ footer !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dshs-modal__foot", children: footer })
952
+ ] })
953
+ }
954
+ );
955
+ }
956
+
957
+ // shared/ui/capabilities.tsx
958
+ var import_jsx_runtime3 = require("react/jsx-runtime");
959
+ function glyph(paths) {
960
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
961
+ "svg",
962
+ {
963
+ width: 15,
964
+ height: 15,
965
+ viewBox: "0 0 24 24",
966
+ fill: "none",
967
+ stroke: "currentColor",
968
+ strokeWidth: 1.8,
969
+ strokeLinecap: "round",
970
+ strokeLinejoin: "round",
971
+ "aria-hidden": "true",
972
+ style: { display: "block" },
973
+ children: paths.map((path) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: path }, path))
974
+ }
975
+ );
976
+ }
977
+ var CAPABILITIES = [
978
+ { key: "dsh-plugin-experts", label: "\u4E13\u5BB6", icon: glyph(["M9 8a3 3 0 1 0 0 .01", "M3 19a6 6 0 0 1 12 0", "M16 5.5a3 3 0 0 1 0 5.9", "M17.5 19a6 6 0 0 0-2-4.5"]) },
979
+ { key: "dsh-plugin-skills", label: "\u6280\u80FD", icon: glyph(["m9 8-4 4 4 4", "m15 8 4 4-4 4"]) },
980
+ { key: "dsh-plugin-connectors", label: "\u8FDE\u63A5\u5668", icon: glyph(["M9 3v6", "M15 3v6", "M6 9h12v3a6 6 0 0 1-12 0z", "M12 18v3"]) },
981
+ { key: "dsh-plugin-projects", label: "\u9879\u76EE", icon: glyph(["M4 6h9", "M4 12h9", "M4 18h6", "M17.5 4v4", "M17.5 12v4"]) },
982
+ { key: "dsh-plugin-library", label: "\u8D44\u6599\u5E93", icon: glyph(["M5 4h9a2 2 0 0 1 2 2v14H7a2 2 0 0 1-2-2z", "M8 4v16", "M16 8h3v12"]) }
983
+ ];
984
+
985
+ // shared/ui/navigation.ts
986
+ function createNavFace(ctx, current) {
987
+ const available = () => {
988
+ const keys = /* @__PURE__ */ new Set();
989
+ const entries = ctx.slots?.entriesOfSlot("main") ?? [];
990
+ for (const entry of entries) {
991
+ const key = entry?.options?.key;
992
+ if (typeof key === "string") keys.add(key);
993
+ }
994
+ keys.add(current);
995
+ return keys;
996
+ };
997
+ return {
998
+ current,
999
+ available,
1000
+ open: (key) => {
1001
+ if (key === current) return;
1002
+ ctx.layout?.selectPanel(key);
1003
+ }
1004
+ };
1005
+ }
1006
+
1007
+ // shared/ui/host.ts
1008
+ var import_react2 = require("react");
1009
+ var HostCallFailure = class extends Error {
1010
+ code;
1011
+ constructor(error) {
1012
+ super(error.message);
1013
+ this.name = "HostCallFailure";
1014
+ this.code = error.code;
1015
+ }
1016
+ };
1017
+ async function hostCall(feature, endpoint, payload, signal, timeoutMs = 15e3) {
1018
+ const deadline = AbortSignal.timeout(timeoutMs);
1019
+ const combined = signal === void 0 ? deadline : AbortSignal.any([signal, deadline]);
1020
+ let response;
1021
+ try {
1022
+ response = await fetch(`/api/dsh-skills/${feature}`, {
1023
+ method: "POST",
1024
+ credentials: "same-origin",
1025
+ headers: { "content-type": "application/json", accept: "application/json" },
1026
+ body: JSON.stringify({ endpoint, payload }),
1027
+ signal: combined
1028
+ });
1029
+ } catch (cause) {
1030
+ if (deadline.aborted) {
1031
+ throw new HostCallFailure({ code: "host/timeout", message: `${feature}.${endpoint} \u8D85\u8FC7 ${Math.round(timeoutMs / 1e3)} \u79D2\u6CA1\u6709\u54CD\u5E94\u3002` });
1032
+ }
1033
+ throw cause;
1034
+ }
1035
+ if (!response.ok) {
1036
+ throw new HostCallFailure({ code: `http/${response.status}`, message: `Host \u8DEF\u7531\u8FD4\u56DE ${response.status}` });
1037
+ }
1038
+ const body = await response.json();
1039
+ if (body.ok !== true) {
1040
+ throw new HostCallFailure(body.error ?? { code: "unknown", message: "Host \u8FD4\u56DE\u4E86\u65E0\u6CD5\u8BC6\u522B\u7684\u54CD\u5E94" });
1041
+ }
1042
+ return body.value;
1043
+ }
1044
+
1045
+ // packages/library/src/management.ts
1046
+ var FEATURE = "library";
1047
+ function decodeBase64(base64) {
1048
+ const binary = atob(base64);
1049
+ const bytes = new Uint8Array(binary.length);
1050
+ for (let index = 0; index < binary.length; index += 1) bytes[index] = binary.charCodeAt(index);
1051
+ return bytes;
1052
+ }
1053
+ function originalBlob(original, mediaType) {
1054
+ return new Blob([decodeBase64(original.base64)], { type: mediaType ?? original.mediaType });
1055
+ }
1056
+ var library = {
1057
+ overview: () => hostCall(FEATURE, "overview"),
1058
+ tree: () => hostCall(FEATURE, "tree"),
1059
+ detail: (assetId) => hostCall(FEATURE, "asset", { assetId }),
1060
+ createFolder: (name2, parentId) => hostCall(FEATURE, "create-folder", { name: name2, parentId }),
1061
+ createText: (name2, content, parentId) => hostCall(FEATURE, "create-text", { name: name2, content, parentId }),
1062
+ importPath: (path, parentId, name2) => hostCall(FEATURE, "import", { path, parentId, name: name2 }),
1063
+ rename: (nodeId, name2) => hostCall(FEATURE, "rename", { nodeId, name: name2 }),
1064
+ move: (nodeId, parentId) => hostCall(FEATURE, "move", { nodeId, parentId }),
1065
+ remove: (nodeId) => hostCall(FEATURE, "remove", { nodeId }),
1066
+ setEnabled: (assetId, enabled) => hostCall(FEATURE, "set-enabled", { assetId, enabled }),
1067
+ /**
1068
+ * Open (or re-open) a draft over one revision's derived text.
1069
+ *
1070
+ * Opening the same `(assetId, revisionId)` again returns the existing draft
1071
+ * with its edits intact, which is what makes 取消 → 编辑 pick up where the
1072
+ * editor left off.
1073
+ */
1074
+ createDraft: (assetId, revisionId) => hostCall(FEATURE, "create-draft", { assetId, revisionId }),
1075
+ /**
1076
+ * Save a draft's full text. `expectedRevision` is the token from the last
1077
+ * read; a stale one is refused, not applied.
1078
+ */
1079
+ updateDraft: (draftId, content, expectedRevision) => hostCall(FEATURE, "update-draft", { draftId, content, expectedRevision }),
1080
+ /**
1081
+ * Commit a draft as a new immutable revision and return the asset's entry.
1082
+ * The previous revision stays readable and unchanged.
1083
+ */
1084
+ publishDraft: (draftId, expectedRevision) => hostCall(FEATURE, "publish-draft", { draftId, expectedRevision }),
1085
+ search: (query, kind) => hostCall(FEATURE, "search", { query, kind }),
1086
+ readText: (assetId, revisionId) => hostCall(FEATURE, "read-text", { assetId, revisionId }),
1087
+ readOriginal: (assetId, revisionId) => hostCall(FEATURE, "read-original", { assetId, revisionId }),
1088
+ /** Disk facts for the current original: where it lives, and whether its bytes still match the revision. */
1089
+ originalPath: (assetId) => hostCall(FEATURE, "original-path", { assetId }),
1090
+ /** Hand the original to the OS default application, or to one specific registered handler. */
1091
+ openInSystem: (assetId, appId) => hostCall(FEATURE, "open-in-system", { assetId, appId }),
1092
+ /** The applications registered for this file, OS preference order first. */
1093
+ fileApplications: (assetId) => hostCall(FEATURE, "file-applications", { assetId }),
1094
+ /** Re-read the (possibly externally edited) original into a new revision. */
1095
+ importExternal: (assetId) => hostCall(FEATURE, "import-external", { assetId })
1096
+ };
1097
+ var KIND_LABELS = {
1098
+ markdown: "Markdown",
1099
+ text: "TXT",
1100
+ html: "HTML",
1101
+ json: "JSON",
1102
+ csv: "CSV",
1103
+ log: "\u65E5\u5FD7",
1104
+ binary: "\u4E8C\u8FDB\u5236"
1105
+ };
1106
+ var CONVERSION_LABELS = {
1107
+ ready: "\u53EF\u641C\u7D22",
1108
+ unavailable: "\u65E0\u6587\u672C\u8F6C\u6362",
1109
+ failed: "\u8F6C\u6362\u5931\u8D25"
1110
+ };
1111
+
1112
+ // packages/library/src/styles.ts
1113
+ var libraryCss = `${modalCss}
1114
+ ${controlsCss}
1115
+
1116
+ /* ---- upstream scope: local aliases + the two-pane grid -------------------- */
1117
+
1118
+ .wd-library{--bg:var(--dsw-alias-bg-base);--line:var(--dsw-alias-border-l2);--muted:var(--dsw-alias-label-tertiary);--hover:var(--dsw-alias-interactive-bg-hover);--text:var(--dsw-alias-label-primary);display:grid;grid-template-columns:292px minmax(0,1fr)}
1119
+ .wd-library{height:100%;min-height:0;background:var(--bg);color:var(--text);font:14px/1.5 "PingFang SC","Microsoft YaHei",sans-serif}.wd-library *{box-sizing:border-box}.wd-library button,.wd-library input,.wd-library textarea{font:inherit;color:inherit}
1120
+
1121
+ /* Upstream's colour:inherit rule above is written for its own plain buttons and
1122
+ is scoped to every button in the panel. Its selector carries a higher
1123
+ specificity than the shared kit's variants, so the kit's primary fill ended up
1124
+ with near-white text on a white fill \u2014 a blank box where \u53D1\u5E03\u65B0\u7248\u672C belongs.
1125
+ The kit's variants own their contrast, so restate it above that rule. */
1126
+ .wd-library .dshs-btn--primary{color:var(--dsw-alias-bg-base)}
1127
+ .wd-library .dshs-btn--danger{color:var(--dsw-alias-state-error-primary)}
1128
+ .wd-library .dshs-btn--ghost{color:var(--muted)}
1129
+ .wd-library .dshs-btn:not(.dshs-btn--primary):not(.dshs-btn--danger):not(.dshs-btn--ghost){color:var(--text)}
1130
+
1131
+ /* ---- sidebar --------------------------------------------------------------- */
1132
+
1133
+ .wd-library-sidebar{display:flex;flex-direction:column;border-right:1px solid var(--line)}
1134
+ .wd-library-sidebar{min-height:0;background:var(--dsw-alias-bg-base)}.wd-library-sidebar>header{display:flex;align-items:center;gap:10px}.wd-library-sidebar>header{height:70px;padding:0 18px}.wd-library-sidebar h1{margin:0}.wd-library-sidebar h1{font-size:24px}.wd-library-nav-toggle{display:none}.wd-library-nav{display:grid;gap:3px}.wd-library-nav{padding:0 12px 18px}.wd-library-nav button{text-align:left;display:flex;align-items:center;gap:12px;cursor:pointer}.wd-library-nav button{height:42px;padding:0 12px;border:0;border-radius:8px;background:transparent;font-size:15px}.wd-library-nav button:hover,.wd-library-nav button.active{background:var(--hover)}.wd-library-section-title{display:flex;align-items:center;justify-content:space-between}.wd-library-section-title{padding:10px 18px 8px;color:var(--muted)}.wd-library-section-title button{width:28px;cursor:pointer}.wd-library-section-title button{height:28px;border:0;background:transparent;border-radius:6px;font-size:20px}.wd-library-section-title button:hover{background:var(--hover)}
1135
+
1136
+ .wd-library-tree{flex:1;overflow:auto}
1137
+ .wd-library-tree{min-height:0;padding:0 8px 20px}.wd-library-tree-row{display:flex;align-items:center;cursor:pointer;gap:6px}.wd-library-tree-row{height:37px;border-radius:7px;padding-right:6px}.wd-library-tree-row:hover,.wd-library-tree-row.selected{background:var(--hover)}.wd-library-tree-row.disabled{opacity:.52}.wd-library-disclosure,.wd-library-more{cursor:pointer}.wd-library-disclosure,.wd-library-more{border:0;background:transparent}.wd-library-disclosure{width:18px}.wd-library-disclosure{padding:0;color:var(--dsw-alias-label-tertiary)}.wd-library-kind{flex:0 0 22px;width:22px;display:grid;place-items:center}.wd-library-kind{height:22px;border-radius:5px;background:#3778df;color:white;font-size:10px;font-weight:700}.wd-library-kind.kind-folder{background:transparent;font-size:16px}.wd-library-kind.kind-pdf{background:#df4b4b}.wd-library-kind.kind-docx{background:#3478d4}.wd-library-kind.kind-pptx{background:#e7772d}.wd-library-kind.kind-text{background:#7e6bd6}.wd-library-kind.kind-json,.wd-library-kind.kind-csv,.wd-library-kind.kind-log,.wd-library-kind.kind-binary{background:#7e6bd6}.wd-library-name{min-width:0;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.wd-library-more{opacity:0;color:var(--dsw-alias-label-tertiary);padding:2px 5px;border-radius:5px}.wd-library-tree-row:hover .wd-library-more,.wd-library-tree-row.selected .wd-library-more{opacity:1}.wd-library-more:hover{background:var(--dsw-alias-interactive-bg-hover)}.wd-library-sidebar footer{border-top:1px solid var(--line)}.wd-library-sidebar footer{padding:14px 18px;color:var(--dsw-alias-label-dimmed);font-size:12px}.wd-library-upload{position:absolute;width:1px;pointer-events:none}.wd-library-upload{height:1px;opacity:0}
1138
+
1139
+ /* ---- content pane: document view ------------------------------------------- */
1140
+
1141
+ .wd-library-content{min-width:0;overflow:auto;position:relative}
1142
+ .wd-library-content{min-height:0;background:var(--dsw-alias-bg-base)}.wd-library-document-header{position:sticky;top:0;z-index:2;display:flex;align-items:center;justify-content:space-between;border-bottom:1px solid var(--line);backdrop-filter:blur(12px)}.wd-library-document-header{height:64px;padding:0 30px;background:var(--dsw-alias-bg-base)}.wd-library-document-header>div{min-width:0;display:flex;align-items:center;gap:10px}.wd-library-document-header span{max-width:42vw;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.wd-library-document-header span,.wd-library-document-header b{color:var(--dsw-alias-label-tertiary);font-weight:400}.wd-library-document-header strong{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.wd-library-document-header em{font-style:normal}.wd-library-document-header em{color:#e9ad5e;border:1px solid #72552c;border-radius:12px;padding:1px 8px;font-size:12px}.wd-library-head-actions button{cursor:pointer}.wd-library-head-actions button{border:0;background:transparent;border-radius:7px;padding:7px 10px}.wd-library-head-actions button:hover{background:var(--hover)}.wd-library-document-body{height:calc(100% - 64px);min-height:540px;padding:30px clamp(24px,4vw,64px);background:var(--dsw-alias-bg-base)}
1143
+
1144
+ .wd-library-conversion-warning{max-width:920px;margin:0 auto 14px}
1145
+ .wd-library-conversion-warning{padding:12px 14px;border:1px solid #76532b;border-radius:8px;background:#2d2519;color:#e6bd77}.wd-library-original{max-width:980px;margin:0 auto}.wd-library-original{min-height:calc(100vh - 170px);border:1px solid var(--dsw-alias-border-l2);border-radius:3px;background:var(--dsw-alias-bg-layer-1);padding:48px 64px;color:var(--dsw-alias-label-primary);box-shadow:0 4px 22px #0003}.wd-library-original.markdown{max-width:960px}.wd-library-original.text{max-width:960px}.wd-library-original pre{margin:0;white-space:pre-wrap;word-break:break-word}.wd-library-original pre{font:15px/1.85 "PingFang SC","Microsoft YaHei",sans-serif}.wd-library-meta{margin-bottom:30px}.wd-library-meta{color:var(--dsw-alias-label-secondary);font-size:12px}.wd-library-markdown{font:16px/1.85 "PingFang SC","Microsoft YaHei",sans-serif}.wd-library-markdown h1{margin:0 0 30px}.wd-library-markdown h1{font-size:34px;line-height:1.3}.wd-library-markdown h2{margin:38px 0 14px}.wd-library-markdown h2{font-size:26px;line-height:1.4}.wd-library-markdown h3{margin:30px 0 10px}.wd-library-markdown h3{font-size:21px}.wd-library-markdown h4,.wd-library-markdown h5,.wd-library-markdown h6{margin:24px 0 8px}.wd-library-markdown h4,.wd-library-markdown h5,.wd-library-markdown h6{font-size:17px}.wd-library-markdown p{margin:0 0 16px}.wd-library-markdown ul{margin:4px 0 20px}.wd-library-markdown ul{padding-left:26px}.wd-library-markdown li{margin:5px 0}.wd-library-markdown code{padding:2px 5px;border-radius:4px;background:var(--dsw-alias-bg-layer-2);color:light-dark(#dc2626,#fca5a5);font:13px/1.6 ui-monospace,SFMono-Regular,Menlo,monospace}.wd-library-markdown .md-code{overflow:auto}.wd-library-markdown .md-code{padding:18px;border-radius:8px;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary)}.wd-library-markdown .md-code code{padding:0;background:transparent;color:inherit}.wd-library-markdown hr{border-top:1px solid var(--dsw-alias-border-l2);margin:30px 0}.wd-library-markdown hr{border:0}.wd-library-pdf,.wd-library-office-preview,.wd-library-html{display:block;width:100%;overflow:hidden}.wd-library-pdf,.wd-library-office-preview,.wd-library-html{height:100%;min-height:calc(100vh - 112px);border:1px solid var(--dsw-alias-border-l2);border-radius:10px;background:white}.wd-library-html{border-radius:5px}
1146
+
1147
+ /* ---- content pane: draft editor (this repo's kit-classed port) -------------- */
1148
+
1149
+ .wd-library-editor{display:flex;flex-direction:column}
1150
+ .wd-library-editor{height:calc(100vh - 132px)}
1151
+ .wd-library-editor-bar{display:flex;align-items:center;gap:12px;margin-bottom:12px}
1152
+ .wd-library-editor-bar span{margin-right:auto}
1153
+ .wd-library-editor-bar span{color:var(--muted)}
1154
+ /* Upstream forces the primary fill on the editor bar's \u53D1\u5E03\u65B0\u7248\u672C (its
1155
+ Button with className "primary"). The kit marks that button
1156
+ with the dshs-btn--primary class; restate upstream's intent against the kit class. */
1157
+ .wd-library-editor-bar button.primary,
1158
+ .wd-library-editor-bar button.dshs-btn--primary,
1159
+ .wd-library-list-view form button{cursor:pointer}
1160
+ .wd-library-editor-bar button.primary,
1161
+ .wd-library-editor-bar button.dshs-btn--primary,
1162
+ .wd-library-list-view form button{background:var(--dsw-alias-button-primary-fill);color:var(--dsw-alias-label-primary-inverted);border-color:var(--dsw-alias-border-l2)}
1163
+ .wd-library-diff{display:grid;grid-template-columns:1fr 1fr;gap:10px;margin-bottom:10px}
1164
+ .wd-library-diff{height:32%;min-height:150px}
1165
+ .wd-library-diff section{min-width:0;display:flex;flex-direction:column;overflow:hidden}
1166
+ .wd-library-diff section{border:1px solid var(--line);border-radius:9px;background:var(--dsw-alias-bg-layer-1)}
1167
+ .wd-library-diff b{border-bottom:1px solid var(--line)}
1168
+ .wd-library-diff b{padding:8px 12px;font-size:12px;color:var(--dsw-alias-label-tertiary)}
1169
+ .wd-library-diff pre{flex:1;overflow:auto;margin:0;white-space:pre-wrap;word-break:break-word}
1170
+ .wd-library-diff pre{padding:12px;font:12px/1.55 ui-monospace,SFMono-Regular,Menlo,monospace}
1171
+ .wd-library-editor textarea{flex:1;width:100%;resize:none}
1172
+ .wd-library-editor textarea{border:1px solid var(--line);border-radius:10px;background:var(--dsw-alias-bg-layer-1);padding:24px;font:14px/1.75 ui-monospace,SFMono-Regular,Menlo,monospace}
1173
+ /* The editor was built on the kit's classed controls before the shell landed;
1174
+ these two selectors keep that markup working inside the upstream frame. */
1175
+ .dshs-library-editor{display:flex;flex-direction:column}
1176
+ .dshs-library-editor__bar{display:flex;align-items:center;gap:12px}
1177
+ .dshs-library-editor__bar span{margin-right:auto}
1178
+ .dshs-library-editor__bar span{color:var(--muted)}
1179
+
1180
+ /* ---- content pane: list views, welcome, results ----------------------------- */
1181
+
1182
+ .wd-library-welcome{display:grid;place-content:center;justify-items:center;text-align:center}
1183
+ .wd-library-welcome{height:100%;color:var(--dsw-alias-label-tertiary)}.wd-library-welcome-icon{width:58px;display:grid;place-items:center}.wd-library-welcome-icon{height:58px;border-radius:14px;background:var(--dsw-alias-bg-layer-2);font-size:27px}.wd-library-welcome h2{margin:18px 0 2px}.wd-library-welcome h2{color:var(--dsw-alias-label-primary)}.wd-library-welcome p{margin:0 0 20px}.wd-library-list-view{max-width:900px;margin:0 auto}.wd-library-list-view{padding:58px 44px}.wd-library-list-view h2{margin:0 0 22px}.wd-library-list-view h2{font-size:28px}.wd-library-list-view form{display:flex;gap:10px;margin-bottom:10px}.wd-library-list-view :is(input,.wd-form-input,.dshs-input){flex:1}.wd-library-list-view input{background:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-border-l2);border-radius:9px;padding:11px 14px;outline:none}.wd-library-list-view input:focus{border-color:var(--dsw-alias-border-l2)}.wd-library-filters{display:flex;gap:8px;align-items:center;margin-bottom:22px}.wd-library-filters select,.wd-library-filters label{border:1px solid var(--dsw-alias-border-l2);border-radius:8px;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-tertiary);padding:7px 10px}.wd-library-filters label{display:flex;align-items:center;gap:7px}.wd-library-filters :is(input,.wd-form-input,.dshs-input){width:130px}.wd-library-filters input{border:0;padding:0;background:transparent}.wd-library-results{border-top:1px solid var(--line)}.wd-library-results>button{width:100%;display:flex;align-items:center;gap:12px;border-bottom:1px solid var(--line);text-align:left;cursor:pointer}.wd-library-results>button{padding:14px 8px;border:0;background:transparent}.wd-library-results>button:hover{background:var(--dsw-alias-bg-layer-1)}.wd-library-results>button>span:nth-child(2){display:grid;gap:3px;min-width:0;flex:1}.wd-library-results strong{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.wd-library-results small{color:var(--dsw-alias-label-tertiary)}.wd-library-excerpt{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:680px}.wd-library-excerpt{color:var(--dsw-alias-label-tertiary);font-size:12px}.wd-library-results i{font-style:normal}.wd-library-results i{color:var(--dsw-alias-label-dimmed);font-size:20px}.wd-library-state{margin:40px auto;max-width:620px;text-align:center}.wd-library-state{padding:32px;border:1px dashed var(--dsw-alias-border-l2);border-radius:12px;color:var(--dsw-alias-label-tertiary)}
1184
+
1185
+ /* ---- popover, toasts, dialogs ------------------------------------------------ */
1186
+
1187
+ .wd-library-popover{position:fixed;z-index:20;width:196px}
1188
+ .wd-library-popover{padding:6px;border:1px solid var(--dsw-alias-border-l2);border-radius:10px;background:var(--dsw-alias-bg-layer-2);box-shadow:0 14px 38px rgba(0,0,0,.42)}.wd-library-popover button{display:block;width:100%;text-align:left;cursor:pointer}.wd-library-popover button{border:0;background:transparent;border-radius:6px;padding:9px 10px}.wd-library-popover button:hover{background:var(--dsw-alias-interactive-bg-hover)}.wd-library-popover button.danger{color:#ff7979}.wd-library-popover hr{border-top:1px solid var(--dsw-alias-border-l2);margin:5px}.wd-library-popover hr{border:0}.wd-library-toast{position:fixed;top:76px;right:24px;z-index:15;max-width:440px}.wd-library-toast{padding:11px 16px;border-radius:8px;background:#21382c;color:#a9e5c3;box-shadow:0 8px 30px var(--dsw-alias-bg-mask-2)}.wd-library-toast.error{background:#452424;color:#ffb0b0}
1189
+
1190
+ /* Upstream's dialog rules are prefixed .wd-dialog (its Modal). The kit Modal
1191
+ renders the same container class inside a .dshs-overlay, so the prefix is
1192
+ the one difference; the rules themselves are upstream's. */
1193
+ .dshs-overlay .library-action-dialog,.dshs-overlay .library-move-dialog{width:min(500px,calc(100vw - 48px))}
1194
+ .dshs-overlay .library-action-dialog,.dshs-overlay .library-move-dialog{padding:28px;max-height:calc(100vh - 48px);overflow:auto}
1195
+ .library-action-dialog h2,.library-move-dialog h2{margin:0 40px 8px 0}
1196
+ .library-action-dialog h2,.library-move-dialog h2{font-size:20px}
1197
+ .library-action-dialog p,.library-move-dialog p{margin:0 0 22px}
1198
+ .library-action-dialog p,.library-move-dialog p{color:var(--dsw-alias-label-tertiary)}
1199
+ .library-action-dialog label{display:grid;gap:8px}
1200
+ .library-action-dialog label{color:var(--dsw-alias-label-secondary)}
1201
+ .library-action-dialog :is(input,.wd-form-input,.dshs-input){width:100%}
1202
+ .library-action-dialog input{height:42px;padding:0 12px;border:1px solid var(--dsw-alias-border-l2);border-radius:8px;background:var(--dsw-alias-bg-layer-1);outline:none}
1203
+ .library-action-dialog input:focus{border-color:#7c9ee8;box-shadow:0 0 0 2px #4269b844}
1204
+ .library-action-dialog select{height:42px;padding:0 12px;border:1px solid var(--dsw-alias-border-l2);border-radius:8px;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);outline:none}
1205
+ .library-dialog-actions{display:flex;justify-content:flex-end;gap:9px;margin-top:24px}
1206
+ .library-dialog-actions button{min-width:78px;cursor:pointer}
1207
+ .library-dialog-actions button{border:1px solid var(--dsw-alias-border-l2);border-radius:8px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);padding:8px 16px}
1208
+ .library-dialog-actions button.primary{background:var(--dsw-alias-button-primary-fill);color:var(--dsw-alias-label-primary-inverted);border-color:var(--dsw-alias-border-l2)}
1209
+ .library-dialog-actions button.danger{background:#b94242;border-color:#b94242;color:var(--dsw-alias-label-primary)}
1210
+ .library-move-targets{overflow:auto;display:grid;gap:4px}
1211
+ .library-move-targets{max-height:45vh}
1212
+ .library-move-targets button{display:flex;align-items:center;gap:9px;width:100%;text-align:left;cursor:pointer}
1213
+ .library-move-targets button{border:0;border-radius:7px;background:transparent;color:var(--dsw-alias-label-primary);padding:10px}
1214
+ .library-move-targets button:hover{background:var(--dsw-alias-interactive-bg-hover)}
1215
+ .library-move-targets span{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1216
+ .library-move-targets i{font-style:normal}
1217
+ .library-move-targets i{color:var(--dsw-alias-label-tertiary)}
1218
+
1219
+ /* ---- upstream media query ----------------------------------------------------- */
1220
+
1221
+ @media(max-width:760px){.wd-library{grid-template-columns:1fr}.wd-library-sidebar{display:none}.wd-library-document-body{padding:18px}.wd-library-list-view{padding:28px 18px}.wd-library-nav-toggle{display:block}}
1222
+
1223
+ /* ---- this repo's earlier editor port (kept; see deviation 5) ------------------ */
1224
+
1225
+ .dshs-library-editor__bar strong { font-size: 13.5px; font-weight: 650; }
1226
+ /* A definite height is what makes the two diff panes independent, fixed-size
1227
+ boxes. Without it this column is content-height, the diff grid's percentage
1228
+ height resolves against an indefinite parent and collapses to auto, and each
1229
+ pane's flexible pre then resolves against content \u2014 so the panes grew with
1230
+ the document and one long revision pushed the other off the screen. Upstream's
1231
+ own rule gives the editor a viewport-derived height; this port has to state
1232
+ the same thing, or the sizing inside it does nothing. */
1233
+ .dshs-library-editor { height: 100%; min-height: 420px; }
1234
+ .dshs-library-diff {
1235
+ display: grid;
1236
+ grid-template-columns: 1fr 1fr;
1237
+ grid-template-rows: 220px;
1238
+ gap: 10px;
1239
+ /* A fixed row track plus min-height:0 on the panes: the grid no longer sizes
1240
+ to the longest document, and each pane scrolls its own text. */
1241
+ min-height: 0;
1242
+ flex: none;
1243
+ margin-bottom: 10px;
1244
+ }
1245
+ .dshs-library-diff section {
1246
+ min-width: 0;
1247
+ /* The grid item must be allowed to shrink below its content, otherwise the
1248
+ row track is treated as a floor and the boxes grow again. */
1249
+ min-height: 0;
1250
+ display: flex;
1251
+ flex-direction: column;
1252
+ overflow: hidden;
1253
+ border: 1px solid var(--dsw-alias-border-l2);
1254
+ border-radius: 9px;
1255
+ background: var(--dsw-alias-bg-layer-1);
1256
+ }
1257
+ .dshs-library-diff b {
1258
+ flex: none;
1259
+ padding: 8px 12px;
1260
+ font-size: 12px;
1261
+ color: var(--dsw-alias-label-tertiary);
1262
+ border-bottom: 1px solid var(--dsw-alias-border-l2);
1263
+ }
1264
+ .dshs-library-diff pre {
1265
+ flex: 1;
1266
+ min-height: 0;
1267
+ overflow: auto;
1268
+ margin: 0;
1269
+ padding: 12px;
1270
+ white-space: pre-wrap;
1271
+ word-break: break-word;
1272
+ font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
1273
+ }
1274
+ .dshs-library-editor .dshs-textarea {
1275
+ flex: 1;
1276
+ min-height: 220px;
1277
+ resize: none;
1278
+ padding: 16px 18px;
1279
+ font: 14px/1.75 ui-monospace, SFMono-Regular, Menlo, monospace;
1280
+ }
1281
+ @media (max-width: 760px) {
1282
+ /* One column, and the two boxes keep their own height rather than stacking
1283
+ into one auto-height run. */
1284
+ .dshs-library-diff { grid-template-columns: 1fr; grid-template-rows: 220px 220px; }
1285
+ .dshs-library-editor__bar { flex-wrap: wrap; }
1286
+ }
1287
+ `;
1288
+
1289
+ // packages/library/src/csv/CsvDocument.tsx
1290
+ var import_react3 = require("react");
1291
+
1292
+ // packages/library/src/csv/csv.ts
1293
+ var Papa = __toESM(require_papaparse_min(), 1);
1294
+ var csvLimits = { rows: 1500, columns: 120, cells: 24e3 };
1295
+ var delimiters = [",", ";", " "];
1296
+ function bom(bytes) {
1297
+ if (bytes.length >= 3 && bytes[0] === 239 && bytes[1] === 187 && bytes[2] === 191) return { encoding: "utf-8", length: 3 };
1298
+ if (bytes.length >= 2 && bytes[0] === 255 && bytes[1] === 254) return { encoding: "utf-16le", length: 2 };
1299
+ if (bytes.length >= 2 && bytes[0] === 254 && bytes[1] === 255) return { encoding: "utf-16be", length: 2 };
1300
+ return void 0;
1301
+ }
1302
+ function decodeCsvBytes(bytes) {
1303
+ const marker = bom(bytes);
1304
+ const body = marker ? bytes.subarray(marker.length) : bytes;
1305
+ let text, encoding;
1306
+ if (marker) {
1307
+ encoding = marker.encoding;
1308
+ text = new TextDecoder(encoding).decode(body);
1309
+ } else {
1310
+ try {
1311
+ text = new TextDecoder("utf-8", { fatal: true }).decode(body);
1312
+ encoding = "utf-8";
1313
+ } catch {
1314
+ try {
1315
+ text = new TextDecoder("gb18030", { fatal: true }).decode(body);
1316
+ encoding = "gb18030";
1317
+ } catch {
1318
+ text = new TextDecoder("utf-8").decode(body);
1319
+ encoding = "utf-8";
1320
+ }
1321
+ }
1322
+ }
1323
+ const binary = !marker && text.includes("\0");
1324
+ return { text, encoding, binary };
1325
+ }
1326
+ function parseCsv(text, limits = csvLimits) {
1327
+ const result = Papa.parse(text, {
1328
+ delimiter: "",
1329
+ // auto-detect among `delimiters`
1330
+ delimitersToGuess: delimiters,
1331
+ skipEmptyLines: "greedy",
1332
+ preview: limits.rows + 1
1333
+ });
1334
+ const delimiter = result.meta.delimiter === ";" || result.meta.delimiter === " " ? result.meta.delimiter : ",";
1335
+ let rawWidth = 0;
1336
+ for (const row of result.data) if (row.length > rawWidth) rawWidth = row.length;
1337
+ const columns = Math.min(rawWidth, limits.columns);
1338
+ const capacity = Math.max(1, Math.floor(limits.cells / Math.max(columns, 1)));
1339
+ const shown = result.data.slice(0, Math.min(limits.rows, capacity));
1340
+ const clip = (row) => row.length > columns ? row.slice(0, columns) : row;
1341
+ return {
1342
+ header: clip(shown[0] ?? []),
1343
+ rows: shown.slice(1).map(clip),
1344
+ columns,
1345
+ delimiter,
1346
+ truncatedRows: result.data.length > shown.length,
1347
+ truncatedColumns: rawWidth > limits.columns
1348
+ };
1349
+ }
1350
+
1351
+ // packages/library/src/csv/csv-css.ts
1352
+ var csvCss = `.wd-csv{display:flex;flex-direction:column;height:100%;min-height:0;min-width:0;overflow:hidden;font-family:system-ui,-apple-system,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif;font-size:13px;line-height:1.5;color:var(--dsw-alias-label-primary,#e7e7e7)}
1353
+ .wd-csv-note{flex-shrink:0;padding:6px 12px;font-size:12px;line-height:1.6;color:var(--dsw-alias-label-secondary,#a5a5a5);background:var(--dsw-alias-bg-layer-2,#2c2c2e);border-bottom:1px solid var(--dsw-alias-border-l2,#ffffff1f)}
1354
+ .wd-csv-scroll{flex:1;min-height:0;min-width:0;overflow:auto;overscroll-behavior:contain;outline:none}
1355
+ .wd-csv-scroll:focus-visible{outline:1px solid var(--dsw-alias-border-l4,#ffffff33);outline-offset:-1px}
1356
+ .wd-csv-table{border-collapse:separate;border-spacing:0;min-width:100%;color:inherit;font-variant-numeric:tabular-nums}
1357
+ .wd-csv-table th,.wd-csv-table td{padding:3px 10px;text-align:left;vertical-align:top;box-sizing:border-box;border-right:1px solid var(--dsw-alias-border-l2,#ffffff1f);border-bottom:1px solid var(--dsw-alias-border-l2,#ffffff1f)}
1358
+ .wd-csv-table thead th{position:sticky;top:0;z-index:2;font-weight:600;white-space:nowrap;background:var(--dsw-alias-bg-layer-2,#2c2c2e);border-top:1px solid var(--dsw-alias-border-l2,#ffffff1f);border-bottom:1px solid var(--dsw-alias-border-l3,#ffffff29)}
1359
+ .wd-csv-table .wd-csv-rownum{position:sticky;left:0;z-index:1;width:1%;min-width:40px;text-align:right;font-weight:400;color:var(--dsw-alias-label-tertiary,#adb2b8);background:var(--dsw-alias-bg-layer-1,#232324);border-left:1px solid var(--dsw-alias-border-l2,#ffffff1f);border-right:1px solid var(--dsw-alias-border-l2,#ffffff1f);user-select:none}
1360
+ .wd-csv-table thead .wd-csv-rownum{z-index:3;border-bottom:1px solid var(--dsw-alias-border-l3,#ffffff29)}
1361
+ .wd-csv-table tbody tr:nth-child(even) td{background:var(--dsw-alias-bg-skeleton,#ffffff14)}
1362
+ .wd-csv-table tbody tr:nth-child(even) .wd-csv-rownum{background:linear-gradient(var(--dsw-alias-bg-skeleton,#ffffff14),var(--dsw-alias-bg-skeleton,#ffffff14)),var(--dsw-alias-bg-layer-1,#232324)}
1363
+ .wd-csv-table tbody tr:hover td{background:var(--dsw-alias-interactive-bg-hover,#ffffff14)}
1364
+ .wd-csv-table tbody tr:hover .wd-csv-rownum{background:linear-gradient(var(--dsw-alias-interactive-bg-hover,#ffffff14),var(--dsw-alias-interactive-bg-hover,#ffffff14)),var(--dsw-alias-bg-layer-1,#232324)}
1365
+ .wd-csv.nowrap .wd-csv-table td{white-space:nowrap;max-width:320px;overflow:hidden;text-overflow:ellipsis}
1366
+ .wd-csv.wrap .wd-csv-table td{white-space:pre-wrap;overflow-wrap:anywhere;max-width:380px}
1367
+ .wd-csv.wrap .wd-csv-table td,.wd-csv.wrap .wd-csv-table thead th:not(.wd-csv-rownum){min-width:96px}
1368
+ .wd-csv-table td.wd-csv-num{text-align:right}
1369
+ .wd-csv-status{flex-shrink:0;display:flex;align-items:center;gap:6px;padding:4px 12px;font-size:12px;color:var(--dsw-alias-label-tertiary,#adb2b8);border-top:1px solid var(--dsw-alias-border-l2,#ffffff1f);white-space:nowrap;overflow:hidden}
1370
+ .wd-csv-status>span{flex-shrink:0}
1371
+ .wd-csv-status .wd-csv-clip{color:var(--dsw-alias-label-secondary,#cfd3d6);overflow:hidden;text-overflow:ellipsis;flex-shrink:1}
1372
+ .wd-csv-empty{flex:1;display:flex;align-items:center;justify-content:center;padding:32px 16px;text-align:center;color:var(--dsw-alias-label-secondary,#a5a5a5)}
1373
+ `;
1374
+
1375
+ // packages/library/src/csv/CsvDocument.tsx
1376
+ var import_jsx_runtime4 = require("react/jsx-runtime");
1377
+ var encodingLabels = {
1378
+ "utf-8": "UTF-8",
1379
+ "gb18030": "GB18030",
1380
+ "utf-16le": "UTF-16 LE",
1381
+ "utf-16be": "UTF-16 BE"
1382
+ };
1383
+ var delimiterLabels = {
1384
+ ",": "\u9017\u53F7\u5206\u9694",
1385
+ ";": "\u5206\u53F7\u5206\u9694",
1386
+ " ": "\u5236\u8868\u7B26\u5206\u9694"
1387
+ };
1388
+ var numeric = /^-?\d+(?:\.\d+)?$/;
1389
+ function cellTitle(value) {
1390
+ return value.length > 300 ? `${value.slice(0, 300)}\u2026` : value || void 0;
1391
+ }
1392
+ function cellClass(value) {
1393
+ return value.length <= 20 && numeric.test(value.trim()) ? "wd-csv-num" : void 0;
1394
+ }
1395
+ var Grid = function Grid2({ table }) {
1396
+ const { columns } = table;
1397
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("table", { className: "wd-csv-table", children: [
1398
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("tr", { children: [
1399
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("th", { className: "wd-csv-rownum", scope: "col", "aria-label": "\u884C\u53F7" }),
1400
+ Array.from({ length: columns }, (_, column) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("th", { scope: "col", title: cellTitle(table.header[column] ?? ""), children: table.header[column] ?? "" }, column))
1401
+ ] }) }),
1402
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("tbody", { children: table.rows.map((row, index) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("tr", { children: [
1403
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("th", { className: "wd-csv-rownum", scope: "row", children: index + 1 }),
1404
+ Array.from({ length: columns }, (_, column) => {
1405
+ const value = column < row.length ? row[column] : "";
1406
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("td", { className: cellClass(value), title: cellTitle(value), children: value }, column);
1407
+ })
1408
+ ] }, index)) })
1409
+ ] });
1410
+ };
1411
+ function CsvGrid(props) {
1412
+ const { bytes, wrap = false } = props;
1413
+ const decoded = (0, import_react3.useMemo)(() => decodeCsvBytes(bytes), [bytes]);
1414
+ const table = (0, import_react3.useMemo)(() => parseCsv(decoded?.text ?? ""), [decoded]);
1415
+ const empty = !table.header.length && !table.rows.length;
1416
+ const clipped = table.truncatedRows || table.truncatedColumns;
1417
+ if (!decoded) return null;
1418
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("section", { className: `wd-csv ${wrap ? "wrap" : "nowrap"}`, "aria-label": "CSV \u8868\u683C\u9884\u89C8", children: [
1419
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("style", { children: csvCss }),
1420
+ decoded.binary && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "wd-csv-note", role: "note", children: "\u6587\u4EF6\u5305\u542B NUL \u5B57\u8282\uFF0C\u770B\u8D77\u6765\u4E0D\u662F\u6587\u672C CSV\u3002\u53EF\u5728\u9884\u89C8\u83DC\u5355\u5207\u6362\u5230\u201C\u7EAF\u6587\u672C\u201D\u67E5\u770B\u539F\u59CB\u5185\u5BB9\u3002" }),
1421
+ empty ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "wd-csv-empty", children: "CSV \u6587\u4EF6\u4E2D\u6CA1\u6709\u53EF\u663E\u793A\u7684\u6570\u636E\u3002" }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "wd-csv-scroll", tabIndex: 0, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Grid, { table }) }),
1422
+ !empty && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("footer", { className: "wd-csv-status", children: [
1423
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: encodingLabels[decoded.encoding] }),
1424
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: "\xB7" }),
1425
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: table.columns > 1 ? delimiterLabels[table.delimiter] : "\u5355\u5217" }),
1426
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: "\xB7" }),
1427
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
1428
+ table.columns,
1429
+ " \u5217 \xD7 ",
1430
+ table.rows.length,
1431
+ " \u884C"
1432
+ ] }),
1433
+ clipped && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "wd-csv-clip", children: [
1434
+ "\xB7 \u6587\u4EF6\u8F83\u5927\uFF0C\u4EC5\u663E\u793A\u524D ",
1435
+ table.rows.length,
1436
+ " \u884C\u3001",
1437
+ table.columns,
1438
+ " \u5217"
1439
+ ] })
1440
+ ] })
1441
+ ] });
1442
+ }
1443
+
1444
+ // packages/library/src/panel.tsx
1445
+ var import_jsx_runtime5 = require("react/jsx-runtime");
1446
+ function reason(error) {
1447
+ return error instanceof Error ? error.message : String(error);
1448
+ }
1449
+ var DOWNLOAD_REVOKE_MS = 1e4;
1450
+ function when(value) {
1451
+ if (value === void 0 || value.length === 0) return "";
1452
+ const parsed = new Date(value);
1453
+ return Number.isNaN(parsed.getTime()) ? value : parsed.toLocaleString();
1454
+ }
1455
+ function sourceOf(source) {
1456
+ if (source === "task") return { label: "\u672C\u5730\u4EA7\u7269", task: true };
1457
+ if (source === "created") return { label: "\u65B0\u5EFA\u8D44\u6599", task: false };
1458
+ if (source === void 0 || source === "import") return { label: "\u4E0A\u4F20\u5BFC\u5165", task: false };
1459
+ return { label: source, task: false };
1460
+ }
1461
+ var KIND_BADGE = {
1462
+ markdown: "M",
1463
+ text: "T",
1464
+ html: "</>",
1465
+ json: "{}",
1466
+ csv: "C",
1467
+ log: "L",
1468
+ binary: "B"
1469
+ };
1470
+ var SOURCE_OPTIONS = [
1471
+ { value: "", label: "\u5168\u90E8\u6765\u6E90" },
1472
+ { value: "upload", label: "\u4E0A\u4F20\u5BFC\u5165" },
1473
+ { value: "created", label: "\u65B0\u5EFA\u8D44\u6599" },
1474
+ { value: "task", label: "\u672C\u5730\u4EA7\u7269" }
1475
+ ];
1476
+ var CREATE_SUFFIXES = {
1477
+ markdown: [".md", ".markdown"],
1478
+ text: [".txt"]
1479
+ };
1480
+ function createdName(name2, format) {
1481
+ const lower = name2.toLocaleLowerCase();
1482
+ const suffix = CREATE_SUFFIXES[format].find((candidate) => lower.endsWith(candidate));
1483
+ if (suffix !== void 0) return { name: name2, stem: name2.slice(0, name2.length - suffix.length) };
1484
+ return { name: `${name2}${CREATE_SUFFIXES[format][0]}`, stem: name2 };
1485
+ }
1486
+ function seedBody(format, stem) {
1487
+ return format === "markdown" ? `# ${stem}
1488
+ ` : "\n";
1489
+ }
1490
+ function extensionOf(name2) {
1491
+ const dot = name2.lastIndexOf(".");
1492
+ return dot === -1 ? "" : name2.slice(dot + 1).toLowerCase();
1493
+ }
1494
+ var IMAGE_TYPES = {
1495
+ png: "image/png",
1496
+ jpg: "image/jpeg",
1497
+ jpeg: "image/jpeg",
1498
+ gif: "image/gif",
1499
+ webp: "image/webp",
1500
+ bmp: "image/bmp",
1501
+ svg: "image/svg+xml",
1502
+ avif: "image/avif",
1503
+ ico: "image/x-icon"
1504
+ };
1505
+ function previewKindOf(name2, kind, mediaType) {
1506
+ const extension = extensionOf(name2);
1507
+ const type = mediaType.toLowerCase();
1508
+ if (extension === "pdf" || type === "application/pdf") return "pdf";
1509
+ if (kind === "html" || extension === "html" || extension === "htm" || type === "text/html") return "html";
1510
+ if (kind === "csv" || extension === "csv" || type === "text/csv") return "csv";
1511
+ if (type.startsWith("image/") || IMAGE_TYPES[extension] !== void 0) return "image";
1512
+ return void 0;
1513
+ }
1514
+ function isolatedHtml(source) {
1515
+ const policy = `<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data: blob:; media-src data: blob:; font-src data:; style-src 'unsafe-inline'; script-src 'unsafe-inline'; connect-src 'none'; frame-src 'none';">`;
1516
+ return /<head(?:\s[^>]*)?>/i.test(source) ? source.replace(/<head(?:\s[^>]*)?>/i, (match) => `${match}${policy}`) : `${policy}${source}`;
1517
+ }
1518
+ function anchorOf(element) {
1519
+ if (element === null) return void 0;
1520
+ const rect = element.getBoundingClientRect();
1521
+ return { left: rect.left, top: rect.bottom, right: rect.right };
1522
+ }
1523
+ function place(anchor, width, height) {
1524
+ return {
1525
+ left: Math.max(8, Math.min(anchor.left, window.innerWidth - width - 8)),
1526
+ top: Math.max(8, Math.min(anchor.top + 6, window.innerHeight - height - 8))
1527
+ };
1528
+ }
1529
+ function LibraryPanel({
1530
+ management = library
1531
+ }) {
1532
+ const [nodes, setNodes] = (0, import_react4.useState)([]);
1533
+ const [selected, setSelected] = (0, import_react4.useState)(void 0);
1534
+ const [content, setContent] = (0, import_react4.useState)("");
1535
+ const [expanded, setExpanded] = (0, import_react4.useState)(/* @__PURE__ */ new Set());
1536
+ const [view, setView] = (0, import_react4.useState)("library");
1537
+ const [query, setQuery] = (0, import_react4.useState)("");
1538
+ const [searchKind, setSearchKind] = (0, import_react4.useState)("");
1539
+ const [searchSource, setSearchSource] = (0, import_react4.useState)("");
1540
+ const [searchAfter, setSearchAfter] = (0, import_react4.useState)("");
1541
+ const [hits, setHits] = (0, import_react4.useState)([]);
1542
+ const [searched, setSearched] = (0, import_react4.useState)(false);
1543
+ const [phase, setPhase] = (0, import_react4.useState)("loading");
1544
+ const [busy, setBusy] = (0, import_react4.useState)(false);
1545
+ const [error, setError] = (0, import_react4.useState)("");
1546
+ const [notice, setNotice] = (0, import_react4.useState)("");
1547
+ const [dialog, setDialog] = (0, import_react4.useState)(void 0);
1548
+ const [popover, setPopover] = (0, import_react4.useState)(void 0);
1549
+ const [draft, setDraft] = (0, import_react4.useState)(void 0);
1550
+ const [draftContent, setDraftContent] = (0, import_react4.useState)("");
1551
+ const [preview, setPreview] = (0, import_react4.useState)(void 0);
1552
+ const [previewLoading, setPreviewLoading] = (0, import_react4.useState)(false);
1553
+ const previewUrlRef = (0, import_react4.useRef)("");
1554
+ const previewToken = (0, import_react4.useRef)(0);
1555
+ const openToken = (0, import_react4.useRef)(0);
1556
+ const [external, setExternal] = (0, import_react4.useState)(void 0);
1557
+ const refresh = (0, import_react4.useCallback)(async () => {
1558
+ try {
1559
+ const next = await management.tree();
1560
+ const rows = Array.isArray(next) ? next : [];
1561
+ setNodes(rows);
1562
+ setPhase("ready");
1563
+ setError("");
1564
+ setSelected((current) => current === void 0 ? void 0 : rows.find((row) => row.id === current.id));
1565
+ return rows;
1566
+ } catch (cause) {
1567
+ setError(reason(cause));
1568
+ setPhase("error");
1569
+ return [];
1570
+ }
1571
+ }, [management]);
1572
+ (0, import_react4.useEffect)(() => {
1573
+ void refresh();
1574
+ }, [refresh]);
1575
+ (0, import_react4.useEffect)(() => {
1576
+ if (popover === void 0) return void 0;
1577
+ let armed = false;
1578
+ const timer = window.setTimeout(() => {
1579
+ armed = true;
1580
+ }, 0);
1581
+ const close = () => {
1582
+ if (armed) setPopover(void 0);
1583
+ };
1584
+ window.addEventListener("click", close);
1585
+ return () => {
1586
+ window.clearTimeout(timer);
1587
+ window.removeEventListener("click", close);
1588
+ };
1589
+ }, [popover]);
1590
+ const clearPreview = (0, import_react4.useCallback)(() => {
1591
+ previewToken.current += 1;
1592
+ const url = previewUrlRef.current;
1593
+ previewUrlRef.current = "";
1594
+ setPreview(void 0);
1595
+ setPreviewLoading(false);
1596
+ if (url.length > 0) URL.revokeObjectURL(url);
1597
+ }, []);
1598
+ (0, import_react4.useEffect)(() => () => {
1599
+ previewToken.current += 1;
1600
+ if (previewUrlRef.current.length > 0) URL.revokeObjectURL(previewUrlRef.current);
1601
+ previewUrlRef.current = "";
1602
+ }, []);
1603
+ (0, import_react4.useEffect)(() => {
1604
+ if (selected === void 0) clearPreview();
1605
+ }, [selected, clearPreview]);
1606
+ (0, import_react4.useEffect)(() => {
1607
+ const asset = selected?.asset;
1608
+ if (asset === void 0 || asset.status === "disabled") {
1609
+ setExternal(void 0);
1610
+ return;
1611
+ }
1612
+ let live = true;
1613
+ void management.originalPath(asset.id).then((facts) => {
1614
+ if (live) setExternal(facts.exists ? { absolutePath: facts.absolutePath, matchesRevision: facts.matchesRevision } : void 0);
1615
+ }).catch(() => {
1616
+ if (live) setExternal(void 0);
1617
+ });
1618
+ return () => {
1619
+ live = false;
1620
+ };
1621
+ }, [selected, management]);
1622
+ const pathOf = (0, import_react4.useCallback)((parentId) => {
1623
+ const names = [];
1624
+ const seen = /* @__PURE__ */ new Set();
1625
+ let current = parentId;
1626
+ while (current !== void 0 && !seen.has(current)) {
1627
+ seen.add(current);
1628
+ const row = nodes.find((node) => node.id === current);
1629
+ if (row === void 0) break;
1630
+ names.unshift(row.name);
1631
+ current = row.parentId;
1632
+ }
1633
+ return names.length === 0 ? "\u6211\u7684\u8D44\u6599" : `\u6211\u7684\u8D44\u6599 / ${names.join(" / ")}`;
1634
+ }, [nodes]);
1635
+ const hitRow = (0, import_react4.useCallback)((hit) => {
1636
+ const node = nodes.find((row) => row.id === hit.nodeId);
1637
+ return {
1638
+ id: hit.nodeId,
1639
+ name: hit.name,
1640
+ kind: hit.kind,
1641
+ ...node !== void 0 ? { node } : {},
1642
+ assetId: hit.assetId,
1643
+ revisionNumber: hit.revisionNumber,
1644
+ conversionStatus: hit.conversionStatus,
1645
+ ...node?.asset !== void 0 ? { source: node.asset.source } : {},
1646
+ updatedAt: hit.updatedAt,
1647
+ excerpt: hit.excerpt,
1648
+ path: hit.folderPath
1649
+ };
1650
+ }, [nodes]);
1651
+ const loadResults = (0, import_react4.useCallback)(async (next, options) => {
1652
+ setPopover(void 0);
1653
+ openToken.current += 1;
1654
+ clearPreview();
1655
+ setSelected(void 0);
1656
+ setView(next);
1657
+ if (options?.silent !== true) {
1658
+ setBusy(true);
1659
+ setError("");
1660
+ setNotice("");
1661
+ }
1662
+ try {
1663
+ const found = await management.search(
1664
+ next === "search" ? query : "",
1665
+ next === "search" && searchKind !== "" ? searchKind : void 0
1666
+ );
1667
+ let rows = Array.isArray(found) ? found : [];
1668
+ const wantedSource = next === "outputs" ? "task" : searchSource;
1669
+ if (wantedSource.length > 0) {
1670
+ rows = rows.filter((hit) => {
1671
+ const node = nodes.find((row) => row.id === hit.nodeId);
1672
+ const raw = node?.asset?.source;
1673
+ const normalized = raw === void 0 || raw === "import" ? "upload" : raw;
1674
+ return normalized === wantedSource;
1675
+ });
1676
+ }
1677
+ if (searchAfter.length > 0) {
1678
+ const after = (/* @__PURE__ */ new Date(`${searchAfter}T00:00:00`)).getTime();
1679
+ if (!Number.isNaN(after)) {
1680
+ rows = rows.filter((hit) => {
1681
+ const stamp = new Date(hit.updatedAt).getTime();
1682
+ return !Number.isNaN(stamp) && stamp >= after;
1683
+ });
1684
+ }
1685
+ }
1686
+ if (next !== "search") {
1687
+ rows = [...rows].sort((left, right) => left.updatedAt < right.updatedAt ? 1 : -1);
1688
+ }
1689
+ setHits(rows);
1690
+ setSearched(true);
1691
+ } catch (cause) {
1692
+ setError(reason(cause));
1693
+ setHits([]);
1694
+ setSearched(true);
1695
+ } finally {
1696
+ if (options?.silent !== true) setBusy(false);
1697
+ }
1698
+ }, [management, query, searchKind, searchAfter, nodes, clearPreview]);
1699
+ const loadOriginal = (0, import_react4.useCallback)(async (node, kind, token) => {
1700
+ const asset = node.asset;
1701
+ if (asset === void 0) return;
1702
+ const generation = previewToken.current;
1703
+ setPreviewLoading(true);
1704
+ const live = () => openToken.current === token && previewToken.current === generation;
1705
+ try {
1706
+ const original = await management.readOriginal(asset.id, node.revision?.id);
1707
+ if (!live()) return;
1708
+ if (kind === "html") {
1709
+ setPreview({ kind: "html", html: new TextDecoder().decode(decodeBase64(original.base64)) });
1710
+ return;
1711
+ }
1712
+ if (kind === "csv") {
1713
+ setPreview({ kind: "csv", bytes: decodeBase64(original.base64) });
1714
+ return;
1715
+ }
1716
+ const name2 = original.name.length > 0 ? original.name : node.name;
1717
+ const extension = extensionOf(name2);
1718
+ const type = kind === "pdf" ? "application/pdf" : original.mediaType.startsWith("image/") ? original.mediaType : IMAGE_TYPES[extension] ?? original.mediaType;
1719
+ const url = URL.createObjectURL(originalBlob(original, type));
1720
+ previewUrlRef.current = url;
1721
+ setPreview({ kind, url });
1722
+ } catch (cause) {
1723
+ if (!live()) return;
1724
+ setError(reason(cause));
1725
+ } finally {
1726
+ if (live()) setPreviewLoading(false);
1727
+ }
1728
+ }, [management]);
1729
+ const downloadOriginal = (0, import_react4.useCallback)(async () => {
1730
+ const node = selected;
1731
+ const asset = node?.asset;
1732
+ if (node === void 0 || asset === void 0) return;
1733
+ setBusy(true);
1734
+ setError("");
1735
+ try {
1736
+ const original = await management.readOriginal(asset.id, node.revision?.id);
1737
+ const url = URL.createObjectURL(originalBlob(original));
1738
+ const anchor = document.createElement("a");
1739
+ anchor.href = url;
1740
+ anchor.download = original.name.length > 0 ? original.name : node.name;
1741
+ anchor.click();
1742
+ window.setTimeout(() => URL.revokeObjectURL(url), DOWNLOAD_REVOKE_MS);
1743
+ } catch (cause) {
1744
+ setError(reason(cause));
1745
+ } finally {
1746
+ setBusy(false);
1747
+ }
1748
+ }, [management, selected]);
1749
+ const beginEdit = (0, import_react4.useCallback)(async () => {
1750
+ const node = selected;
1751
+ if (node?.asset === void 0) return;
1752
+ setBusy(true);
1753
+ setError("");
1754
+ setNotice("");
1755
+ try {
1756
+ const next = await management.createDraft(node.asset.id, node.revision?.id);
1757
+ setDraft(next);
1758
+ setDraftContent(next.content);
1759
+ } catch (cause) {
1760
+ setError(reason(cause));
1761
+ } finally {
1762
+ setBusy(false);
1763
+ }
1764
+ }, [management, selected]);
1765
+ const cancelEdit = (0, import_react4.useCallback)(() => {
1766
+ setDraft(void 0);
1767
+ setDraftContent("");
1768
+ setNotice("");
1769
+ setError("");
1770
+ }, []);
1771
+ const publishDraft = (0, import_react4.useCallback)(async () => {
1772
+ const current = draft;
1773
+ if (current === void 0) return;
1774
+ setBusy(true);
1775
+ setError("");
1776
+ setNotice("");
1777
+ try {
1778
+ const saved = draftContent === current.content ? current : await management.updateDraft(current.id, draftContent, current.revision);
1779
+ const entry = await management.publishDraft(saved.id, saved.revision);
1780
+ setSelected(entry);
1781
+ setContent(draftContent);
1782
+ setDraft(void 0);
1783
+ setDraftContent("");
1784
+ await refresh();
1785
+ setNotice(`\u5DF2\u53D1\u5E03\u4E3A\u65B0\u4FEE\u8BA2\uFF08\u7B2C ${entry.revision?.number ?? 1} \u7248\uFF09\uFF1B\u65E7\u4FEE\u8BA2\u4ECD\u7136\u53EA\u8BFB\u53EF\u67E5\u3002`);
1786
+ } catch (cause) {
1787
+ setError(reason(cause));
1788
+ } finally {
1789
+ setBusy(false);
1790
+ }
1791
+ }, [draft, draftContent, management, refresh]);
1792
+ const openNode = (0, import_react4.useCallback)(async (node) => {
1793
+ if (node.kind === "folder") {
1794
+ setExpanded((previous) => {
1795
+ const next = new Set(previous);
1796
+ if (next.has(node.id)) next.delete(node.id);
1797
+ else next.add(node.id);
1798
+ return next;
1799
+ });
1800
+ return;
1801
+ }
1802
+ openToken.current += 1;
1803
+ const token = openToken.current;
1804
+ setPopover(void 0);
1805
+ setError("");
1806
+ setNotice("");
1807
+ setView("library");
1808
+ setSelected(node);
1809
+ setContent("");
1810
+ setDraft(void 0);
1811
+ setDraftContent("");
1812
+ clearPreview();
1813
+ const asset = node.asset;
1814
+ const revision = node.revision;
1815
+ if (asset === void 0 || revision === void 0) return;
1816
+ if (asset.status === "disabled") return;
1817
+ if (revision.conversionStatus === "ready") {
1818
+ try {
1819
+ const text = await management.readText(asset.id, revision.id);
1820
+ if (openToken.current !== token) return;
1821
+ setContent(typeof text === "string" ? text : "");
1822
+ } catch (cause) {
1823
+ if (openToken.current !== token) return;
1824
+ setError(reason(cause));
1825
+ }
1826
+ }
1827
+ const previewKind = previewKindOf(node.name, asset.kind, asset.mediaType);
1828
+ if (previewKind !== void 0) await loadOriginal(node, previewKind, token);
1829
+ }, [management, clearPreview, loadOriginal]);
1830
+ const openRow = (0, import_react4.useCallback)(async (row) => {
1831
+ let node = row.node;
1832
+ if (node === void 0 && row.assetId !== void 0) {
1833
+ try {
1834
+ node = (await management.detail(row.assetId)).node;
1835
+ } catch (cause) {
1836
+ setError(reason(cause));
1837
+ return;
1838
+ }
1839
+ }
1840
+ if (node === void 0) return;
1841
+ await openNode(node);
1842
+ }, [management, openNode]);
1843
+ const act = (0, import_react4.useCallback)(async (operation, message) => {
1844
+ setBusy(true);
1845
+ setError("");
1846
+ try {
1847
+ await operation();
1848
+ await refresh();
1849
+ const current = selected;
1850
+ if (current?.asset !== void 0 && current.revision?.conversionStatus === "ready" && current.asset.status === "active") {
1851
+ try {
1852
+ const text = await management.readText(current.asset.id, current.revision.id);
1853
+ setContent(typeof text === "string" ? text : "");
1854
+ } catch {
1855
+ }
1856
+ }
1857
+ if (message !== void 0) setNotice(message);
1858
+ } catch (cause) {
1859
+ setError(reason(cause));
1860
+ } finally {
1861
+ setBusy(false);
1862
+ }
1863
+ }, [management, refresh, selected]);
1864
+ const openCreate = (0, import_react4.useCallback)((event, parentId) => {
1865
+ event.stopPropagation();
1866
+ const anchor = anchorOf(event.currentTarget);
1867
+ if (anchor === void 0) return;
1868
+ setPopover({ kind: "create", ...parentId !== void 0 ? { parentId } : {}, ...place(anchor, 200, 210) });
1869
+ }, []);
1870
+ const openEntryMenu = (0, import_react4.useCallback)((event, node) => {
1871
+ event.stopPropagation();
1872
+ const anchor = anchorOf(event.currentTarget);
1873
+ if (anchor === void 0) return;
1874
+ setPopover({ kind: "entry", node, ...place(anchor, 200, 300) });
1875
+ }, []);
1876
+ const openAppMenu = (0, import_react4.useCallback)(async (event, assetId) => {
1877
+ event.stopPropagation();
1878
+ const anchor = anchorOf(event.currentTarget);
1879
+ if (anchor === void 0) return;
1880
+ let applications = [];
1881
+ try {
1882
+ applications = (await management.fileApplications(assetId)).applications;
1883
+ } catch {
1884
+ applications = [];
1885
+ }
1886
+ setPopover({ kind: "apps", assetId, applications, ...place(anchor, 200, 300) });
1887
+ }, [management]);
1888
+ const submit = (0, import_react4.useCallback)(() => {
1889
+ const current = dialog;
1890
+ if (current === void 0) return;
1891
+ switch (current.kind) {
1892
+ case "create-text": {
1893
+ const value = current.name.trim();
1894
+ if (value.length === 0) return;
1895
+ const target = createdName(value, current.format);
1896
+ const body = current.content.length > 0 ? current.content : seedBody(current.format, target.stem);
1897
+ setDialog(void 0);
1898
+ void act(
1899
+ () => management.createText(target.name, body, current.parentId),
1900
+ "\u8D44\u6599\u5DF2\u521B\u5EFA\uFF1B\u6B63\u6587\u5199\u5165\u4E86\u5B83\u7684\u7B2C\u4E00\u4E2A\u4E0D\u53EF\u53D8\u4FEE\u8BA2\u3002"
1901
+ );
1902
+ return;
1903
+ }
1904
+ case "create-folder": {
1905
+ const value = current.value.trim();
1906
+ if (value.length === 0) return;
1907
+ setDialog(void 0);
1908
+ void act(() => management.createFolder(value, current.parentId), "\u6587\u4EF6\u5939\u5DF2\u521B\u5EFA\u3002");
1909
+ return;
1910
+ }
1911
+ case "import": {
1912
+ const path = current.path.trim();
1913
+ if (path.length === 0) return;
1914
+ const name2 = current.name.trim();
1915
+ setDialog(void 0);
1916
+ void act(
1917
+ () => management.importPath(path, current.parentId, name2.length > 0 ? name2 : void 0),
1918
+ "\u5BFC\u5165\u5B8C\u6210\uFF1B\u76F8\u540C\u5B57\u8282\u4F1A\u590D\u7528\u5DF2\u6709\u4FEE\u8BA2\u3002"
1919
+ );
1920
+ return;
1921
+ }
1922
+ case "rename": {
1923
+ const value = current.value.trim();
1924
+ if (value.length === 0) return;
1925
+ setDialog(void 0);
1926
+ void act(() => management.rename(current.node.id, value), "\u5DF2\u91CD\u547D\u540D\u3002");
1927
+ return;
1928
+ }
1929
+ case "move": {
1930
+ const target = current.parentId;
1931
+ setDialog(void 0);
1932
+ void act(() => management.move(current.node.id, target.length > 0 ? target : void 0), "\u5DF2\u79FB\u52A8\u3002");
1933
+ return;
1934
+ }
1935
+ case "remove":
1936
+ setDialog(void 0);
1937
+ void act(() => management.remove(current.node.id), "\u5DF2\u5220\u9664\uFF08\u539F\u4EF6\u4ECD\u4FDD\u7559\u5728\u78C1\u76D8\u4E0A\uFF09\u3002");
1938
+ return;
1939
+ default:
1940
+ return;
1941
+ }
1942
+ }, [dialog, act, management]);
1943
+ const createItems = (0, import_react4.useCallback)((parentId) => {
1944
+ const openImport = () => {
1945
+ setDialog({ kind: "import", ...parentId !== void 0 ? { parentId } : {}, path: "", name: "" });
1946
+ setPopover(void 0);
1947
+ };
1948
+ const openText = (format) => {
1949
+ setDialog({
1950
+ kind: "create-text",
1951
+ format,
1952
+ ...parentId !== void 0 ? { parentId } : {},
1953
+ name: format === "markdown" ? "\u672A\u547D\u540D\u6587\u6863.md" : "\u672A\u547D\u540D\u6587\u672C.txt",
1954
+ content: ""
1955
+ });
1956
+ setPopover(void 0);
1957
+ };
1958
+ return [
1959
+ { label: "\u65B0\u5EFA\u6587\u6863\uFF08.md\uFF09", onSelect: () => openText("markdown") },
1960
+ { label: "\u65B0\u5EFA\u6587\u672C\uFF08.txt\uFF09", onSelect: () => openText("text") },
1961
+ {
1962
+ label: "\u65B0\u5EFA\u6587\u4EF6\u5939",
1963
+ onSelect: () => {
1964
+ setDialog({ kind: "create-folder", ...parentId !== void 0 ? { parentId } : {}, value: "" });
1965
+ setPopover(void 0);
1966
+ }
1967
+ },
1968
+ { label: "\u5BFC\u5165\u6587\u4EF6", onSelect: openImport }
1969
+ ];
1970
+ }, []);
1971
+ const entryItems = (0, import_react4.useCallback)((node, anchor) => {
1972
+ const items = [];
1973
+ if (node.kind === "folder") {
1974
+ items.push({
1975
+ label: "\u5728\u6B64\u65B0\u5EFA\u6216\u5BFC\u5165",
1976
+ onSelect: () => {
1977
+ setPopover({ kind: "create", parentId: node.id, ...place(anchor, 200, 210) });
1978
+ }
1979
+ });
1980
+ }
1981
+ items.push({
1982
+ label: "\u79FB\u52A8\u5230\u2026",
1983
+ onSelect: () => {
1984
+ setDialog({ kind: "move", node, parentId: "" });
1985
+ setPopover(void 0);
1986
+ }
1987
+ });
1988
+ items.push({
1989
+ label: "\u91CD\u547D\u540D",
1990
+ onSelect: () => {
1991
+ setDialog({ kind: "rename", node, value: node.name });
1992
+ setPopover(void 0);
1993
+ }
1994
+ });
1995
+ if (node.asset !== void 0) {
1996
+ const disabled = node.asset.status === "disabled";
1997
+ items.push({
1998
+ label: disabled ? "\u91CD\u65B0\u542F\u7528" : "\u505C\u7528",
1999
+ onSelect: () => {
2000
+ setPopover(void 0);
2001
+ void act(
2002
+ () => management.setEnabled(node.asset.id, disabled),
2003
+ disabled ? "\u5DF2\u91CD\u65B0\u542F\u7528\u3002" : "\u5DF2\u505C\u7528\uFF1A\u5B83\u4E0D\u518D\u51FA\u73B0\u5728\u641C\u7D22\u7ED3\u679C\u91CC\uFF0C\u4E5F\u4E0D\u80FD\u7528\u4E8E\u4EFB\u52A1\u3002"
2004
+ );
2005
+ }
2006
+ });
2007
+ }
2008
+ items.push({
2009
+ label: "\u5220\u9664",
2010
+ danger: true,
2011
+ onSelect: () => {
2012
+ setDialog({ kind: "remove", node });
2013
+ setPopover(void 0);
2014
+ }
2015
+ });
2016
+ return items;
2017
+ }, [management, act]);
2018
+ const childFolders = (0, import_react4.useMemo)(() => nodes.filter((node) => node.kind === "folder"), [nodes]);
2019
+ const moveTargets = (0, import_react4.useCallback)((node) => {
2020
+ const blocked = /* @__PURE__ */ new Set([node.id]);
2021
+ let grew = true;
2022
+ while (grew) {
2023
+ grew = false;
2024
+ for (const row of nodes) {
2025
+ if (row.parentId !== void 0 && blocked.has(row.parentId) && !blocked.has(row.id)) {
2026
+ blocked.add(row.id);
2027
+ grew = true;
2028
+ }
2029
+ }
2030
+ }
2031
+ return nodes.filter((row) => row.kind === "folder" && !blocked.has(row.id));
2032
+ }, [nodes]);
2033
+ const resultRows = (0, import_react4.useMemo)(() => {
2034
+ if (view === "search") return hits.map(hitRow);
2035
+ if (view === "recent") {
2036
+ return hits.map(hitRow).sort((left, right) => (left.updatedAt ?? "") < (right.updatedAt ?? "") ? 1 : -1);
2037
+ }
2038
+ if (view === "outputs") {
2039
+ return hits.map(hitRow).filter((row) => row.source === "task").sort((left, right) => (left.updatedAt ?? "") < (right.updatedAt ?? "") ? 1 : -1);
2040
+ }
2041
+ return [];
2042
+ }, [view, hits, hitRow]);
2043
+ const isEditable = (node) => node?.editable === true;
2044
+ const draftEditor = (current) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dshs-library-editor", children: [
2045
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dshs-library-editor__bar", children: [
2046
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: "\u7F16\u8F91\u8349\u7A3F" }),
2047
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "\u53D1\u5E03\u540E\u751F\u6210\u65B0\u7684\u53EA\u8BFB\u4FEE\u8BA2" }),
2048
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Button, { size: "sm", disabled: busy, onClick: cancelEdit, children: "\u53D6\u6D88" }),
2049
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Button, { variant: "primary", size: "sm", disabled: busy, onClick: () => void publishDraft(), children: "\u53D1\u5E03\u65B0\u7248\u672C" })
2050
+ ] }),
2051
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dshs-library-diff", children: [
2052
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { children: [
2053
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("b", { children: "\u5F53\u524D\u4FEE\u8BA2" }),
2054
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("pre", { children: current.content })
2055
+ ] }),
2056
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { children: [
2057
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("b", { children: "\u8349\u7A3F\u9884\u89C8" }),
2058
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("pre", { children: draftContent })
2059
+ ] })
2060
+ ] }),
2061
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2062
+ Textarea,
2063
+ {
2064
+ value: draftContent,
2065
+ onChange: setDraftContent,
2066
+ rows: 18,
2067
+ disabled: busy,
2068
+ ariaLabel: "\u8349\u7A3F\u5185\u5BB9"
2069
+ }
2070
+ ),
2071
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("p", { style: { margin: 0, fontSize: 12, color: "var(--muted)" }, children: [
2072
+ "\u8349\u7A3F\u4FDD\u5B58\u5728\u672C\u673A\uFF0C\u4E0D\u4F1A\u6539\u52A8\u5DF2\u6709\u4FEE\u8BA2\uFF1B\u70B9\u300C\u53D1\u5E03\u65B0\u7248\u672C\u300D\u624D\u4F1A\u5199\u5165\u4E00\u4E2A\u65B0\u7684\u4E0D\u53EF\u53D8\u4FEE\u8BA2\uFF08\u7B2C ",
2073
+ current.number + 1,
2074
+ " \u7248\u8D77\uFF09\u3002 \u5185\u5BB9\u4E0E\u539F\u4FEE\u8BA2\u5B8C\u5168\u4E00\u81F4\u65F6\u4E0D\u4F1A\u91CD\u590D\u5199\u5165\u3002"
2075
+ ] })
2076
+ ] });
2077
+ const documentBody = (node) => {
2078
+ const revision = node.revision;
2079
+ const asset = node.asset;
2080
+ if (draft !== void 0) return draftEditor(draft);
2081
+ if (asset === void 0 || revision === void 0) {
2082
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "wd-library-state", children: "\u8FD9\u4E2A\u8282\u70B9\u6CA1\u6709\u53EF\u8BFB\u7684\u4FEE\u8BA2\u8BB0\u5F55\u3002" });
2083
+ }
2084
+ if (asset.status === "disabled") {
2085
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "wd-library-state", children: "\u8FD9\u4EFD\u8D44\u6599\u5DF2\u505C\u7528\u3002\u91CD\u65B0\u542F\u7528\u540E\u624D\u80FD\u67E5\u770B\u6216\u7528\u4E8E\u4EFB\u52A1\u3002" });
2086
+ }
2087
+ const previewKind = previewKindOf(node.name, asset.kind, asset.mediaType);
2088
+ if (previewKind !== void 0) {
2089
+ if (previewLoading) {
2090
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "wd-library-state", children: "\u6B63\u5728\u8BFB\u53D6\u539F\u4EF6\u2026" });
2091
+ }
2092
+ if (preview?.kind === "html") {
2093
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2094
+ "iframe",
2095
+ {
2096
+ className: "wd-library-html",
2097
+ title: node.name,
2098
+ sandbox: "allow-scripts",
2099
+ srcDoc: isolatedHtml(preview.html)
2100
+ }
2101
+ );
2102
+ }
2103
+ if (preview !== void 0) {
2104
+ if (preview.kind === "csv") return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(CsvGrid, { bytes: preview.bytes });
2105
+ return preview.kind === "pdf" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("iframe", { className: "wd-library-pdf", title: node.name, src: preview.url }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("img", { src: preview.url, alt: node.name, style: { maxWidth: "100%", borderRadius: 10, border: "1px solid var(--dsw-alias-border-l2)" } });
2106
+ }
2107
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "wd-library-state", children: "\u539F\u4EF6\u8BFB\u53D6\u5931\u8D25\uFF0C\u4E0A\u65B9\u63D0\u793A\u8BF4\u660E\u4E86\u539F\u56E0\uFF1B\u53EF\u4EE5\u7528\u4E0A\u65B9\u7684\u300C\u4E0B\u8F7D\u300D\u628A\u5B83\u53D6\u56DE\u3002" });
2108
+ }
2109
+ if (revision.conversionStatus === "failed") {
2110
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "wd-library-state", children: "\u6587\u672C\u8F6C\u6362\u5931\u8D25\uFF0C\u56E0\u6B64\u6682\u65F6\u4E0D\u53EF\u641C\u7D22\u3002\u539F\u4EF6\u5DF2\u5B8C\u6574\u4FDD\u5B58\uFF0C\u53EF\u4EE5\u7528\u4E0A\u65B9\u7684\u300C\u4E0B\u8F7D\u300D\u53D6\u56DE\uFF1B\u8FD9\u4E2A\u683C\u5F0F\u4E0D\u80FD\u5728\u6D4F\u89C8\u5668\u91CC\u9884\u89C8\u3002" });
2111
+ }
2112
+ if (revision.conversionStatus === "unavailable") {
2113
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "wd-library-state", children: [
2114
+ "\u8BE5\u683C\u5F0F\uFF08",
2115
+ KIND_LABELS[asset.kind],
2116
+ "\uFF09\u6CA1\u6709\u6587\u672C\u8F6C\u6362\uFF0C\u6D4F\u89C8\u5668\u4E5F\u4E0D\u80FD\u76F4\u63A5\u9884\u89C8\u3002\u539F\u4EF6\u4ECD\u4FDD\u7559\u5728\u672C\u673A\u78C1\u76D8\u4E0A\uFF0C\u53EF\u4EE5\u7528\u4E0A\u65B9\u7684\u300C\u4E0B\u8F7D\u300D\u53D6\u56DE\u3002"
2117
+ ] });
2118
+ }
2119
+ if (content.length === 0) return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "wd-library-state", children: "\u8FD9\u4EFD\u4FEE\u8BA2\u7684\u6D3E\u751F\u6B63\u6587\u662F\u7A7A\u7684\u3002" });
2120
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("article", { className: `wd-library-original ${asset.kind}`, children: [
2121
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "wd-library-meta", children: [
2122
+ "\u4FEE\u8BA2 ",
2123
+ revision.number,
2124
+ " \xB7 \u539F\u59CB\u5185\u5BB9"
2125
+ ] }),
2126
+ asset.kind === "markdown" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(MarkdownDocument, { content }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("pre", { children: content })
2127
+ ] });
2128
+ };
2129
+ const renderTree = (parentId, depth) => nodes.filter((node) => node.parentId === parentId).map((node) => {
2130
+ const folderOpen = expanded.has(node.id);
2131
+ const isSelected = node.asset !== void 0 && selected?.id === node.id;
2132
+ const rowClass = `wd-library-tree-row${isSelected ? " selected" : ""}${node.asset?.status === "disabled" ? " disabled" : ""}`;
2133
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
2134
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
2135
+ "div",
2136
+ {
2137
+ className: rowClass,
2138
+ style: { paddingLeft: 12 + depth * 16 },
2139
+ "aria-selected": isSelected || void 0,
2140
+ onClick: () => void openNode(node),
2141
+ children: [
2142
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2143
+ "button",
2144
+ {
2145
+ type: "button",
2146
+ className: "wd-library-disclosure",
2147
+ tabIndex: -1,
2148
+ "aria-hidden": node.kind !== "folder" || void 0,
2149
+ "aria-label": node.kind === "folder" ? folderOpen ? `\u6298\u53E0 ${node.name}` : `\u5C55\u5F00 ${node.name}` : void 0,
2150
+ onClick: (event) => {
2151
+ event.stopPropagation();
2152
+ void openNode(node);
2153
+ },
2154
+ children: node.kind === "folder" ? folderOpen ? "\u2304" : "\u203A" : ""
2155
+ }
2156
+ ),
2157
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: `wd-library-kind kind-${node.asset?.kind ?? "folder"}`, children: node.kind === "folder" ? "\u{1F4C1}" : KIND_BADGE[node.asset?.kind ?? "binary"] }),
2158
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "wd-library-name", children: node.name }),
2159
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2160
+ "button",
2161
+ {
2162
+ type: "button",
2163
+ className: "wd-library-more",
2164
+ "aria-label": `${node.name} \u66F4\u591A\u64CD\u4F5C`,
2165
+ onClick: (event) => openEntryMenu(event, node),
2166
+ children: "\u2022\u2022\u2022"
2167
+ }
2168
+ )
2169
+ ]
2170
+ }
2171
+ ),
2172
+ node.kind === "folder" && folderOpen ? renderTree(node.id, depth + 1) : null
2173
+ ] }, node.id);
2174
+ });
2175
+ const submitDisabled = busy || dialog?.kind === "create-text" && dialog.name.trim().length === 0 || dialog?.kind === "create-folder" && dialog.value.trim().length === 0 || dialog?.kind === "import" && dialog.path.trim().length === 0 || dialog?.kind === "rename" && dialog.value.trim().length === 0;
2176
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { className: "wd-library", children: [
2177
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("style", { children: libraryCss }),
2178
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("aside", { className: "wd-library-sidebar", children: [
2179
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("header", { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h1", { children: "\u8D44\u6599\u5E93" }) }),
2180
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("nav", { className: "wd-library-nav", children: [
2181
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
2182
+ "button",
2183
+ {
2184
+ type: "button",
2185
+ className: view === "search" ? "active" : "",
2186
+ onClick: () => {
2187
+ setView("search");
2188
+ setSelected(void 0);
2189
+ },
2190
+ children: [
2191
+ "\u2315 ",
2192
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "\u641C\u7D22" })
2193
+ ]
2194
+ }
2195
+ ),
2196
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
2197
+ "button",
2198
+ {
2199
+ type: "button",
2200
+ className: view === "recent" ? "active" : "",
2201
+ onClick: () => void loadResults("recent"),
2202
+ children: [
2203
+ "\u25F7 ",
2204
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "\u6700\u8FD1" })
2205
+ ]
2206
+ }
2207
+ ),
2208
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
2209
+ "button",
2210
+ {
2211
+ type: "button",
2212
+ className: view === "outputs" ? "active" : "",
2213
+ onClick: () => void loadResults("outputs"),
2214
+ children: [
2215
+ "\u25B1 ",
2216
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "\u672C\u5730\u4EA7\u7269" })
2217
+ ]
2218
+ }
2219
+ )
2220
+ ] }),
2221
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "wd-library-section-title", children: [
2222
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "\u6211\u7684\u8D44\u6599" }),
2223
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", "aria-label": "\u65B0\u5EFA\u6216\u5BFC\u5165", disabled: busy, onClick: (event) => openCreate(event), children: "\uFF0B" })
2224
+ ] }),
2225
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "wd-library-tree", onClick: () => setView("library"), children: [
2226
+ phase === "loading" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "wd-library-tree-hint", children: "\u8BFB\u53D6\u76EE\u5F55\u2026" }),
2227
+ phase === "error" && nodes.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "wd-library-tree-hint", children: "\u76EE\u5F55\u8BFB\u53D6\u5931\u8D25\uFF1A\u4E0A\u65B9\u63D0\u793A\u8BF4\u660E\u4E86\u539F\u56E0\u3002" }),
2228
+ phase !== "loading" && nodes.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "wd-library-tree-hint", children: "\u8D44\u6599\u5E93\u8FD8\u662F\u7A7A\u7684\u3002\u7528 \uFF0B \u65B0\u5EFA\u6587\u6863\uFF08.md\uFF09\u3001\u65B0\u5EFA\u6587\u672C\uFF08.txt\uFF09\uFF0C\u6216\u7528\u300C\u5BFC\u5165\u6587\u4EF6\u300D\u586B\u5199\u6587\u4EF6\u5728\u672C\u673A\u4E0A\u7684\u7EDD\u5BF9\u8DEF\u5F84\u3002" }),
2229
+ nodes.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { role: "tree", "aria-label": "\u6211\u7684\u8D44\u6599", children: renderTree(void 0, 0) })
2230
+ ] }),
2231
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("footer", { children: "\u672C\u5730\u8D44\u6599\u5E93 \xB7 \u4EC5\u5F53\u524D\u8BBE\u5907" })
2232
+ ] }),
2233
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("main", { className: "wd-library-content", children: [
2234
+ notice.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "wd-library-toast", role: "status", children: notice }),
2235
+ error.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "wd-library-toast error", role: "alert", children: error }),
2236
+ selected !== void 0 && view === "library" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
2237
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("header", { className: "wd-library-document-header", children: [
2238
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
2239
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: pathOf(selected.parentId) }),
2240
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("b", { children: "/" }),
2241
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: selected.name }),
2242
+ selected.asset?.status === "disabled" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("em", { children: "\u5DF2\u505C\u7528" }) : selected.revision?.conversionStatus === "failed" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("em", { children: "\u8F6C\u6362\u5931\u8D25" }) : null
2243
+ ] }),
2244
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "wd-library-head-actions", children: [
2245
+ isEditable(selected) && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2246
+ Button,
2247
+ {
2248
+ size: "sm",
2249
+ disabled: busy || selected.revision?.conversionStatus !== "ready",
2250
+ title: selected.draft !== void 0 ? `\u7EE7\u7EED\u7F16\u8F91 ${selected.name} \u7684\u8349\u7A3F\uFF1B\u53D1\u5E03\u540E\u751F\u6210\u65B0\u7684\u53EA\u8BFB\u4FEE\u8BA2\u3002` : `\u7F16\u8F91 ${selected.name}\uFF1B\u53D1\u5E03\u540E\u751F\u6210\u65B0\u7684\u53EA\u8BFB\u4FEE\u8BA2\uFF0C\u65E7\u4FEE\u8BA2\u4FDD\u6301\u4E0D\u53D8\u3002`,
2251
+ onClick: () => void beginEdit(),
2252
+ children: "\u7F16\u8F91"
2253
+ }
2254
+ ),
2255
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2256
+ "button",
2257
+ {
2258
+ type: "button",
2259
+ disabled: busy || selected.asset === void 0 || selected.asset.status === "disabled",
2260
+ title: selected.asset?.status === "disabled" ? "\u8FD9\u4EFD\u8D44\u6599\u5DF2\u505C\u7528\uFF0CHost \u4F1A\u62D2\u7EDD\u8BFB\u53D6\u539F\u4EF6\uFF1B\u5148\u91CD\u65B0\u542F\u7528\u518D\u6253\u5F00\u3002" : `\u7528\u7CFB\u7EDF\u9ED8\u8BA4\u7A0B\u5E8F\u6253\u5F00 ${selected.name}\uFF08WPS / PowerPoint / \u9884\u89C8 \u2026\uFF09\uFF1B\u4FDD\u5B58\u540E\u70B9\u300C\u5BFC\u5165\u65B0\u7248\u672C\u300D\u628A\u4FEE\u6539\u843D\u6210\u65B0\u4FEE\u8BA2`,
2261
+ onClick: () => void act(() => management.openInSystem(selected.asset.id), "\u5DF2\u4EA4\u7ED9\u7CFB\u7EDF\u9ED8\u8BA4\u7A0B\u5E8F\u6253\u5F00\u3002"),
2262
+ children: "\u7CFB\u7EDF\u6253\u5F00"
2263
+ }
2264
+ ),
2265
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2266
+ "button",
2267
+ {
2268
+ type: "button",
2269
+ "aria-label": "\u9009\u62E9\u6253\u5F00\u65B9\u5F0F",
2270
+ title: "\u9009\u62E9\u7528\u54EA\u4E2A\u7A0B\u5E8F\u6253\u5F00",
2271
+ disabled: busy || selected.asset === void 0 || selected.asset.status === "disabled",
2272
+ onClick: (event) => void openAppMenu(event, selected.asset.id),
2273
+ children: "\u25BE"
2274
+ }
2275
+ ),
2276
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2277
+ "button",
2278
+ {
2279
+ type: "button",
2280
+ disabled: busy || selected.asset === void 0 || selected.asset.status === "disabled",
2281
+ title: selected.asset?.status === "disabled" ? "\u8FD9\u4EFD\u8D44\u6599\u5DF2\u505C\u7528\uFF0CHost \u4F1A\u62D2\u7EDD\u8BFB\u53D6\u539F\u4EF6\uFF1B\u5148\u91CD\u65B0\u542F\u7528\u518D\u4E0B\u8F7D\u3002" : `\u4E0B\u8F7D ${selected.name} \u7684\u539F\u59CB\u5B57\u8282`,
2282
+ onClick: () => void downloadOriginal(),
2283
+ children: "\u4E0B\u8F7D"
2284
+ }
2285
+ ),
2286
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2287
+ "button",
2288
+ {
2289
+ type: "button",
2290
+ "aria-label": "\u66F4\u591A\u64CD\u4F5C",
2291
+ disabled: busy,
2292
+ onClick: (event) => openEntryMenu(event, selected),
2293
+ children: "\u2022\u2022\u2022"
2294
+ }
2295
+ )
2296
+ ] })
2297
+ ] }),
2298
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "wd-library-document-body", "data-kind": selected.asset?.kind, children: [
2299
+ external !== void 0 && !external.matchesRevision && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "wd-library-conversion-warning", children: [
2300
+ "\u6587\u4EF6\u5728\u672C\u673A\u88AB\u5916\u90E8\u7A0B\u5E8F\u4FEE\u6539\u8FC7\uFF08",
2301
+ external.absolutePath,
2302
+ "\uFF09\u2014\u2014\u8D44\u6599\u5E93\u91CC\u7684\u8FD8\u662F\u65E7\u4FEE\u8BA2\u3002",
2303
+ " ",
2304
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2305
+ "button",
2306
+ {
2307
+ type: "button",
2308
+ disabled: busy,
2309
+ onClick: () => void act(() => management.importExternal(selected.asset.id), "\u5DF2\u628A\u5916\u90E8\u4FEE\u6539\u5BFC\u5165\u4E3A\u65B0\u4FEE\u8BA2\u3002"),
2310
+ children: "\u5BFC\u5165\u65B0\u7248\u672C"
2311
+ }
2312
+ )
2313
+ ] }),
2314
+ selected.revision !== void 0 && selected.revision.conversionWarnings.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "wd-library-conversion-warning", children: selected.revision.conversionWarnings.join(" ") }),
2315
+ documentBody(selected),
2316
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "wd-library-meta", style: { marginTop: 14 }, children: [
2317
+ KIND_LABELS[selected.asset?.kind ?? "binary"],
2318
+ " \xB7 ",
2319
+ sourceOf(selected.asset?.source).label,
2320
+ " ",
2321
+ "\xB7 \u4FEE\u8BA2 ",
2322
+ selected.revision?.number ?? 1,
2323
+ " \xB7 ",
2324
+ when(selected.updatedAt),
2325
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("br", {}),
2326
+ "asset ",
2327
+ selected.asset?.id,
2328
+ " \xB7 revision ",
2329
+ selected.revision?.id,
2330
+ " \xB7 SHA-256 ",
2331
+ selected.revision?.originalSha256.slice(0, 16),
2332
+ "\u2026"
2333
+ ] })
2334
+ ] })
2335
+ ] }) : view === "search" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "wd-library-list-view", children: [
2336
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h2", { children: "\u641C\u7D22" }),
2337
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("form", { onSubmit: (event) => {
2338
+ event.preventDefault();
2339
+ void loadResults("search");
2340
+ }, children: [
2341
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2342
+ Input,
2343
+ {
2344
+ autoFocus: true,
2345
+ value: query,
2346
+ onChange: setQuery,
2347
+ placeholder: "\u641C\u7D22\u8D44\u6599\u540D\u79F0\u548C\u5185\u5BB9",
2348
+ ariaLabel: "\u641C\u7D22\u8D44\u6599"
2349
+ }
2350
+ ),
2351
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Button, { type: "submit", disabled: busy, children: "\u641C\u7D22" })
2352
+ ] }),
2353
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "wd-library-filters", children: [
2354
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2355
+ Select,
2356
+ {
2357
+ ariaLabel: "\u8D44\u6599\u7C7B\u578B",
2358
+ value: searchKind,
2359
+ onChange: (next) => setSearchKind(next),
2360
+ options: [
2361
+ { value: "", label: "\u5168\u90E8\u7C7B\u578B" },
2362
+ ...Object.entries(KIND_LABELS).map(([value, label]) => ({ value, label }))
2363
+ ]
2364
+ }
2365
+ ),
2366
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2367
+ Select,
2368
+ {
2369
+ ariaLabel: "\u8D44\u6599\u6765\u6E90",
2370
+ value: searchSource,
2371
+ onChange: setSearchSource,
2372
+ options: SOURCE_OPTIONS
2373
+ }
2374
+ ),
2375
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { children: [
2376
+ "\u66F4\u65B0\u65E5\u671F\u4ECE",
2377
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2378
+ "input",
2379
+ {
2380
+ className: "dshs-input",
2381
+ type: "date",
2382
+ "aria-label": "\u66F4\u65B0\u65E5\u671F\u4ECE",
2383
+ value: searchAfter,
2384
+ onChange: (event) => setSearchAfter(event.currentTarget.value)
2385
+ }
2386
+ )
2387
+ ] })
2388
+ ] }),
2389
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { style: { margin: "0 0 14px", fontSize: 12.5, color: "var(--muted)" }, children: "\u5173\u952E\u8BCD\u4E0E\u8D44\u6599\u7C7B\u578B\u7531 Host \u68C0\u7D22\u6D3E\u751F\u6B63\u6587\uFF1B\u300C\u8D44\u6599\u6765\u6E90\u300D\u548C\u300C\u66F4\u65B0\u65E5\u671F\u300D\u5728\u8BFB\u53D6\u7ED3\u679C\u540E\u4E8E\u672C\u9875\u8FC7\u6EE4\u3002" }),
2390
+ busy ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "wd-library-state", children: "\u6B63\u5728\u641C\u7D22\u2026" }) : searched ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ResultList, { rows: resultRows, onOpen: (row) => void openRow(row) }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "wd-library-state", children: "\u8F93\u5165\u5173\u952E\u8BCD\u540E\u70B9\u300C\u641C\u7D22\u300D\uFF1B\u7559\u7A7A\u641C\u7D22\u4F1A\u5217\u51FA\u5168\u90E8\u53EF\u641C\u7D22\u7684\u8D44\u6599\u3002" })
2391
+ ] }) : view === "recent" || view === "outputs" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "wd-library-list-view", children: [
2392
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h2", { children: view === "recent" ? "\u6700\u8FD1" : "\u672C\u5730\u4EA7\u7269" }),
2393
+ busy ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "wd-library-state", children: "\u6B63\u5728\u8BFB\u53D6\u2026" }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2394
+ ResultList,
2395
+ {
2396
+ rows: resultRows,
2397
+ empty: view === "recent" ? "\u8FD8\u6CA1\u6709\u5BFC\u5165\u4EFB\u4F55\u8D44\u6599\u3002" : "\u8FD8\u6CA1\u6709\u4EFB\u52A1\u5199\u5165\u7684\u672C\u5730\u4EA7\u7269\u3002",
2398
+ onOpen: (row) => void openRow(row)
2399
+ }
2400
+ )
2401
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "wd-library-welcome", children: [
2402
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "wd-library-welcome-icon", children: "\u25A4" }),
2403
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h2", { children: "\u6211\u7684\u8D44\u6599" }),
2404
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: "\u4ECE\u5DE6\u4FA7\u9009\u62E9\u8D44\u6599\uFF0C\u5728\u8FD9\u91CC\u67E5\u770B\u539F\u59CB\u5185\u5BB9\u3002" }),
2405
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Button, { variant: "primary", disabled: busy, onClick: (event) => openCreate(event), children: "\u65B0\u5EFA\u6216\u5BFC\u5165\u8D44\u6599" })
2406
+ ] })
2407
+ ] }),
2408
+ popover !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2409
+ "div",
2410
+ {
2411
+ className: "wd-library-popover",
2412
+ role: "menu",
2413
+ "aria-label": "\u8D44\u6599\u64CD\u4F5C",
2414
+ style: { left: popover.left, top: popover.top },
2415
+ onClick: (event) => event.stopPropagation(),
2416
+ onKeyDown: (event) => {
2417
+ if (event.key === "Escape") setPopover(void 0);
2418
+ },
2419
+ children: popover.kind === "create" ? createItems(popover.parentId).map((item) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", role: "menuitem", onClick: () => item.onSelect?.(), children: item.label }, item.label)) : popover.kind === "apps" ? [
2420
+ { id: void 0, name: "\u7CFB\u7EDF\u9ED8\u8BA4\u7A0B\u5E8F" },
2421
+ ...popover.applications.filter((app) => typeof app.id === "string" && app.id.length > 0)
2422
+ ].map((app) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
2423
+ "button",
2424
+ {
2425
+ type: "button",
2426
+ role: "menuitem",
2427
+ style: { display: "flex", alignItems: "center", gap: 8, width: "100%", textAlign: "left" },
2428
+ onClick: () => {
2429
+ setPopover(void 0);
2430
+ void act(
2431
+ () => management.openInSystem(popover.assetId, app.id),
2432
+ app.id === void 0 ? "\u5DF2\u4EA4\u7ED9\u7CFB\u7EDF\u9ED8\u8BA4\u7A0B\u5E8F\u6253\u5F00\u3002" : `\u5DF2\u4EA4\u7ED9 ${app.name} \u6253\u5F00\u3002`
2433
+ );
2434
+ },
2435
+ children: [
2436
+ app.icon !== void 0 && app.icon.startsWith("data:image/") && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("img", { src: app.icon, alt: "", width: 16, height: 16, style: { borderRadius: 3, flexShrink: 0 } }),
2437
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { style: { flex: 1 }, children: [
2438
+ app.id === void 0 ? "\u7CFB\u7EDF\u9ED8\u8BA4\u7A0B\u5E8F" : app.name,
2439
+ app.default === true ? "\uFF08\u9ED8\u8BA4\uFF09" : ""
2440
+ ] })
2441
+ ]
2442
+ },
2443
+ app.id ?? "default"
2444
+ )) : entryItems(popover.node, { left: popover.left, top: popover.top, right: popover.left + 200 }).map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(React.Fragment, { children: [
2445
+ popover.node.kind === "folder" && index === 1 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("hr", {}) : null,
2446
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2447
+ "button",
2448
+ {
2449
+ type: "button",
2450
+ role: "menuitem",
2451
+ className: item.danger === true ? "danger" : "",
2452
+ onClick: () => item.onSelect?.(),
2453
+ children: item.label
2454
+ }
2455
+ )
2456
+ ] }, item.label))
2457
+ }
2458
+ ),
2459
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2460
+ Modal,
2461
+ {
2462
+ open: dialog !== void 0,
2463
+ title: dialog?.kind === "create-text" ? dialog.format === "markdown" ? "\u65B0\u5EFA Markdown \u6587\u6863" : "\u65B0\u5EFA TXT \u6587\u672C" : dialog?.kind === "create-folder" ? "\u65B0\u5EFA\u6587\u4EF6\u5939" : dialog?.kind === "import" ? "\u5BFC\u5165\u6587\u4EF6" : dialog?.kind === "rename" ? "\u91CD\u547D\u540D" : dialog?.kind === "move" ? "\u79FB\u52A8\u8D44\u6599" : "\u5220\u9664\u8D44\u6599",
2464
+ className: "library-action-dialog",
2465
+ onClose: () => setDialog(void 0),
2466
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
2467
+ "form",
2468
+ {
2469
+ className: "library-action-form",
2470
+ onSubmit: (event) => {
2471
+ event.preventDefault();
2472
+ if (!submitDisabled) submit();
2473
+ },
2474
+ children: [
2475
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h2", { children: dialog?.kind === "create-text" ? dialog.format === "markdown" ? "\u65B0\u5EFA Markdown \u6587\u6863" : "\u65B0\u5EFA TXT \u6587\u672C" : dialog?.kind === "create-folder" ? "\u65B0\u5EFA\u6587\u4EF6\u5939" : dialog?.kind === "import" ? "\u5BFC\u5165\u6587\u4EF6" : dialog?.kind === "rename" ? "\u91CD\u547D\u540D" : dialog?.kind === "move" ? "\u79FB\u52A8\u8D44\u6599" : "\u5220\u9664\u8D44\u6599" }),
2476
+ dialog?.kind === "create-text" && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { children: [
2477
+ "\u540D\u79F0",
2478
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2479
+ Input,
2480
+ {
2481
+ autoFocus: true,
2482
+ value: dialog.name,
2483
+ onChange: (name2) => setDialog({ ...dialog, name: name2 }),
2484
+ onEnter: submitDisabled ? void 0 : submit,
2485
+ placeholder: dialog.format === "markdown" ? "\u672A\u547D\u540D\u6587\u6863.md" : "\u672A\u547D\u540D\u6587\u672C.txt"
2486
+ }
2487
+ ),
2488
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("small", { children: "\u6CA1\u6709\u540E\u7F00\u65F6\u4F1A\u81EA\u52A8\u8865\u4E0A .md / .txt\uFF1B\u6B63\u6587\u4EE5\u300C# \u540D\u79F0\u300D\u4F5C\u4E3A\u8D77\u59CB\u3002" })
2489
+ ] }),
2490
+ dialog?.kind === "create-folder" && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { children: [
2491
+ "\u6587\u4EF6\u5939\u540D\u79F0",
2492
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Input, { value: dialog.value, onChange: (value) => setDialog({ ...dialog, value }), placeholder: "\u4F8B\u5982 \u4EA7\u54C1\u8D44\u6599" })
2493
+ ] }),
2494
+ dialog?.kind === "import" && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
2495
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { children: [
2496
+ "\u7EDD\u5BF9\u8DEF\u5F84",
2497
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2498
+ Input,
2499
+ {
2500
+ autoFocus: true,
2501
+ value: dialog.path,
2502
+ onChange: (path) => setDialog({ ...dialog, path }),
2503
+ placeholder: "/Users/me/Documents/\u9700\u6C42.md"
2504
+ }
2505
+ ),
2506
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("small", { children: "\u7531 Host \u7528 fs \u670D\u52A1\u8BFB\u53D6\u8BE5\u6587\u4EF6\uFF1B\u5BFC\u5165\u540E\u539F\u59CB\u5B57\u8282\u4E0D\u53EF\u4FEE\u6539\u3002" })
2507
+ ] }),
2508
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { children: [
2509
+ "\u4FDD\u5B58\u540D\u79F0\uFF08\u53EF\u9009\uFF09",
2510
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Input, { value: dialog.name, onChange: (name2) => setDialog({ ...dialog, name: name2 }), placeholder: "\u7559\u7A7A\u5219\u4F7F\u7528\u6587\u4EF6\u540D" })
2511
+ ] }),
2512
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { children: [
2513
+ "\u76EE\u6807\u6587\u4EF6\u5939",
2514
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2515
+ Select,
2516
+ {
2517
+ value: dialog.parentId ?? "",
2518
+ ariaLabel: "\u76EE\u6807\u6587\u4EF6\u5939",
2519
+ onChange: (parentId) => setDialog({ ...dialog, parentId: parentId.length > 0 ? parentId : void 0 }),
2520
+ options: [
2521
+ { value: "", label: "\u6211\u7684\u8D44\u6599\uFF08\u6839\u76EE\u5F55\uFF09" },
2522
+ ...childFolders.map((node) => ({ value: node.id, label: `${pathOf(node.parentId)} / ${node.name}` }))
2523
+ ]
2524
+ }
2525
+ )
2526
+ ] }),
2527
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("small", { children: "\u8FD9\u91CC\u6CA1\u6709\u6D4F\u89C8\u5668\u7684\u6587\u4EF6\u9009\u62E9\u6846\uFF1A\u9762\u677F\u8DD1\u5728\u6D4F\u89C8\u5668\u91CC\uFF0C\u800C\u539F\u6587\u5728 Host \u7684\u78C1\u76D8\u4E0A\uFF0C\u6240\u4EE5\u6309\u7EDD\u5BF9\u8DEF\u5F84\u5BFC\u5165\u3002 \u652F\u6301 .md / .txt / .html / .json / .csv / .log \u7684\u6587\u672C\u8F6C\u6362\uFF0C\u5176\u4ED6\u683C\u5F0F\u6309\u539F\u6837\u4FDD\u5B58\u5E76\u6807\u8BB0\u4E3A\u300C\u65E0\u6587\u672C\u8F6C\u6362\u300D\u3002" })
2528
+ ] }),
2529
+ dialog?.kind === "rename" && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { children: [
2530
+ "\u65B0\u540D\u79F0",
2531
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Input, { autoFocus: true, value: dialog.value, onChange: (value) => setDialog({ ...dialog, value }) })
2532
+ ] }),
2533
+ dialog?.kind === "move" && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
2534
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: "\u9009\u62E9\u65B0\u7684\u4FDD\u5B58\u4F4D\u7F6E" }),
2535
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "library-move-targets", children: [
2536
+ moveTargets(dialog.node).length === 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "wd-library-tree-hint", children: "\u6CA1\u6709\u53EF\u79FB\u52A8\u8FDB\u53BB\u7684\u6587\u4EF6\u5939\u3002" }),
2537
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { type: "button", onClick: () => {
2538
+ setDialog({ ...dialog, parentId: "" });
2539
+ }, children: [
2540
+ "\u{1F4C1} ",
2541
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "\u6211\u7684\u8D44\u6599\uFF08\u6839\u76EE\u5F55\uFF09" }),
2542
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("i", { children: "\u203A" })
2543
+ ] }),
2544
+ moveTargets(dialog.node).map((node) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
2545
+ "button",
2546
+ {
2547
+ type: "button",
2548
+ onClick: () => {
2549
+ setDialog({ ...dialog, parentId: node.id });
2550
+ },
2551
+ children: [
2552
+ "\u{1F4C1} ",
2553
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { children: [
2554
+ pathOf(node.parentId),
2555
+ " / ",
2556
+ node.name
2557
+ ] }),
2558
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("i", { children: "\u203A" })
2559
+ ]
2560
+ },
2561
+ node.id
2562
+ ))
2563
+ ] }),
2564
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "library-dialog-actions", children: [
2565
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Button, { type: "button", disabled: busy, onClick: () => setDialog(void 0), children: "\u53D6\u6D88" }),
2566
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Button, { type: "submit", variant: "primary", className: "primary", disabled: busy, children: "\u786E\u5B9A" })
2567
+ ] })
2568
+ ] }),
2569
+ dialog?.kind === "remove" && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("p", { children: [
2570
+ "\u5220\u9664\u300C",
2571
+ dialog.node.name,
2572
+ "\u300D\uFF1F\u6811\u91CC\u4E0D\u518D\u663E\u793A\u3001\u4E5F\u4E0D\u518D\u80FD\u88AB\u8BFB\u53D6\uFF0C\u4F46\u539F\u59CB\u5B57\u8282\u4E0E\u4FEE\u8BA2\u8BB0\u5F55\u4F1A\u4FDD\u7559\u5728\u78C1\u76D8\u4E0A\u3002\u6B64\u64CD\u4F5C\u65E0\u6CD5\u64A4\u9500\u3002"
2573
+ ] }),
2574
+ dialog?.kind !== "move" && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "library-dialog-actions", children: [
2575
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Button, { type: "button", disabled: busy, onClick: () => setDialog(void 0), children: "\u53D6\u6D88" }),
2576
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2577
+ Button,
2578
+ {
2579
+ type: "submit",
2580
+ variant: dialog?.kind === "remove" ? "danger" : "primary",
2581
+ className: dialog?.kind === "remove" ? "danger" : "primary",
2582
+ disabled: submitDisabled,
2583
+ children: dialog?.kind === "remove" ? "\u5220\u9664" : "\u786E\u5B9A"
2584
+ }
2585
+ )
2586
+ ] })
2587
+ ]
2588
+ }
2589
+ )
2590
+ }
2591
+ )
2592
+ ] });
2593
+ }
2594
+ function ResultList({
2595
+ rows,
2596
+ empty,
2597
+ onOpen
2598
+ }) {
2599
+ if (rows.length === 0) {
2600
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "wd-library-state", children: empty ?? "\u6CA1\u6709\u627E\u5230\u8D44\u6599\u3002" });
2601
+ }
2602
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "wd-library-results", children: rows.map((row) => {
2603
+ const meta = [
2604
+ KIND_LABELS[row.node?.asset?.kind ?? row.kind ?? "binary"],
2605
+ row.path ?? "\u6211\u7684\u8D44\u6599",
2606
+ `\u4FEE\u8BA2 ${row.revisionNumber ?? 1}`,
2607
+ CONVERSION_LABELS[row.conversionStatus ?? "unavailable"]
2608
+ ];
2609
+ const second = [sourceOf(row.source).label, when(row.updatedAt)].filter((part) => part.length > 0).join(" \xB7 ");
2610
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
2611
+ "button",
2612
+ {
2613
+ type: "button",
2614
+ onClick: () => onOpen(row),
2615
+ children: [
2616
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: `wd-library-kind kind-${row.node?.asset?.kind ?? row.kind ?? "folder"}`, children: row.node?.kind === "folder" ? "\u{1F4C1}" : KIND_BADGE[row.node?.asset?.kind ?? row.kind ?? "binary"] }),
2617
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { children: [
2618
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: row.name }),
2619
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("small", { children: meta.join(" \xB7 ") }),
2620
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("small", { children: [
2621
+ second,
2622
+ row.node !== void 0 ? "" : " \xB7 \uFF08\u641C\u7D22\u7ED3\u679C\uFF1B\u8D44\u6599\u53EF\u80FD\u5DF2\u4E0D\u5728\u76EE\u5F55\u91CC\uFF09"
2623
+ ] }),
2624
+ row.excerpt !== void 0 && row.excerpt.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "wd-library-excerpt", children: row.excerpt })
2625
+ ] }),
2626
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("i", { children: "\u203A" })
2627
+ ]
2628
+ },
2629
+ `${row.id}-${row.revisionNumber ?? 0}`
2630
+ );
2631
+ }) });
2632
+ }
2633
+ function MarkdownDocument({ content }) {
2634
+ const rows = content.replace(/\r\n?/g, "\n").split("\n");
2635
+ const blocks = [];
2636
+ let code;
2637
+ let list = [];
2638
+ const flushList = () => {
2639
+ if (list.length === 0) return;
2640
+ const items = list;
2641
+ blocks.push(
2642
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("ul", { children: items.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("li", { children: inlineMarkdown(item) }, index)) }, `list-${blocks.length}`)
2643
+ );
2644
+ list = [];
2645
+ };
2646
+ rows.forEach((row, index) => {
2647
+ if (/^```/.test(row)) {
2648
+ if (code !== void 0) {
2649
+ const lines = code;
2650
+ blocks.push(
2651
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("pre", { className: "md-code", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("code", { children: lines.join("\n") }) }, `code-${index}`)
2652
+ );
2653
+ code = void 0;
2654
+ } else {
2655
+ flushList();
2656
+ code = [];
2657
+ }
2658
+ return;
2659
+ }
2660
+ if (code !== void 0) {
2661
+ code.push(row);
2662
+ return;
2663
+ }
2664
+ const heading = /^(#{1,6})\s+(.+)$/.exec(row);
2665
+ if (heading !== null) {
2666
+ flushList();
2667
+ blocks.push(
2668
+ React.createElement(
2669
+ `h${heading[1].length}`,
2670
+ { key: `h-${index}` },
2671
+ inlineMarkdown(heading[2])
2672
+ )
2673
+ );
2674
+ return;
2675
+ }
2676
+ const bullet = /^[-*+]\s+(.+)$/.exec(row);
2677
+ if (bullet !== null) {
2678
+ list.push(bullet[1]);
2679
+ return;
2680
+ }
2681
+ flushList();
2682
+ if (/^---+$/.test(row.trim())) blocks.push(/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("hr", {}, `hr-${index}`));
2683
+ else if (row.trim().length > 0) blocks.push(/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: inlineMarkdown(row) }, `p-${index}`));
2684
+ });
2685
+ flushList();
2686
+ if (code !== void 0) {
2687
+ blocks.push(
2688
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("pre", { className: "md-code", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("code", { children: code.join("\n") }) }, "code-last")
2689
+ );
2690
+ }
2691
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "wd-library-markdown", children: blocks });
2692
+ }
2693
+ function inlineMarkdown(value) {
2694
+ const parts = value.split(/(`[^`]+`|\*\*[^*]+\*\*)/g);
2695
+ return parts.map((part, index) => {
2696
+ if (part.startsWith("`")) return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("code", { children: part.slice(1, -1) }, index);
2697
+ if (part.startsWith("**")) return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: part.slice(2, -2) }, index);
2698
+ return part;
2699
+ });
2700
+ }
2701
+
2702
+ // packages/library/client.tsx
2703
+ var import_jsx_runtime6 = require("react/jsx-runtime");
2704
+ var PANEL_ID = "dsh-plugin-library";
2705
+ var name = "dsh-plugin-library-client";
2706
+ var inject = ["slots", "layout"];
2707
+ function LibraryIcon({ size = 16 }) {
2708
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", style: { display: "block" }, children: [
2709
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("path", { d: "M5 4h9l4 4v12H5z", stroke: "currentColor", strokeWidth: 1.8, strokeLinejoin: "round" }),
2710
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("path", { d: "M14 4v4h4M8 13h7M8 16.5h4.5", stroke: "currentColor", strokeWidth: 1.8, strokeLinecap: "round" })
2711
+ ] });
2712
+ }
2713
+ function apply(ctx) {
2714
+ const nav = createNavFace(ctx, PANEL_ID);
2715
+ ctx.slots.inject("main", () => ctx.slots.register({
2716
+ name: "main",
2717
+ key: PANEL_ID,
2718
+ inject: () => ({ management: library, nav })
2719
+ }, LibraryPanel));
2720
+ ctx.slots.inject("sidebar.panellist", () => ctx.slots.register({
2721
+ name: "sidebar.panellist",
2722
+ id: PANEL_ID,
2723
+ order: 46,
2724
+ label: "\u8D44\u6599\u5E93"
2725
+ }, LibraryIcon));
2726
+ }
2727
+
2728
+ return module.exports;
2729
+ },
2730
+ });