@celljs/ta-boundaries 0.0.0-stage → 4.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +19 -0
- package/README.md +15 -2
- package/host/index.mjs +361 -0
- package/package.json +62 -4
- package/web/index.js +732 -0
package/README.en.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @celljs/ta-boundaries
|
|
2
|
+
|
|
3
|
+
English | [简体中文](./README.md)
|
|
4
|
+
|
|
5
|
+
Directory marks for Ta: mark a directory as **work** or **private**, and the conversations in it (and in the directories
|
|
6
|
+
inside it) show a small label after their name. Design: `docs/design/ta-boundaries.md`.
|
|
7
|
+
|
|
8
|
+
- From the menu of a conversation, Mark the directory…: general, work or private, with a name to show (Client A).
|
|
9
|
+
- Settings → Privacy & security → Directory marks lists them, to remove one or clear them all. Marks follow you to your
|
|
10
|
+
other computers.
|
|
11
|
+
- A cloud Ta of a company takes unmarked directories for work; a general mark on a directory undoes it there.
|
|
12
|
+
- It is the one package of Ta that answers which boundary a directory is in (`TaExtensionHost.boundaries`). Turned
|
|
13
|
+
off, every directory is general, and Ta is as it was without it.
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
ta call @celljs/ta-boundaries of /path/to/dir
|
|
17
|
+
ta call @celljs/ta-boundaries mark /path/to/dir work 'Client A'
|
|
18
|
+
ta call @celljs/ta-boundaries unmark /path/to/dir
|
|
19
|
+
```
|
package/README.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @celljs/ta-boundaries
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[English](./README.en.md) | 简体中文
|
|
4
|
+
|
|
5
|
+
Ta 的"目录标记":把目录标成**公司**的或**私密**的,这个目录(和它下面的子目录)里的对话,名字后面会显示一个小标签。设计见 `docs/design/ta-boundaries.md`。
|
|
6
|
+
|
|
7
|
+
- 在对话的菜单里选"目录标记…":通用 / 公司 / 私密,可以起显示名(客户 A)。
|
|
8
|
+
- 设置 → 隐私与安全 → 目录标记:列出所有标记,可以移除或清除全部。标记跟着你的几台电脑同步。
|
|
9
|
+
- 公司网关领到的云端 Ta:没标记的目录都算公司的;在某个目录上标"通用",这个目录就不算。
|
|
10
|
+
- 它是 Ta 里唯一回答"某个目录在哪个边界"的包(`TaExtensionHost.boundaries`)。关掉它,所有目录都算通用,Ta 和没有它时一样。
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
ta call @celljs/ta-boundaries of /path/to/dir
|
|
14
|
+
ta call @celljs/ta-boundaries mark /path/to/dir work '客户 A'
|
|
15
|
+
ta call @celljs/ta-boundaries unmark /path/to/dir
|
|
16
|
+
```
|
package/host/index.mjs
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
// ../ta-protocol/esm/common/location.js
|
|
2
|
+
var TaLocation;
|
|
3
|
+
(function(TaLocation2) {
|
|
4
|
+
TaLocation2.SSH = "ssh://";
|
|
5
|
+
TaLocation2.CLOUD = "ta://";
|
|
6
|
+
const CLOUD_NAME = /^[a-z0-9][a-z0-9-]{0,39}$/;
|
|
7
|
+
const HOST = /^(?!-)[\w.@:%+[\]-]+$/;
|
|
8
|
+
function isRemote(location) {
|
|
9
|
+
return location.startsWith(TaLocation2.SSH) || location.startsWith(TaLocation2.CLOUD);
|
|
10
|
+
}
|
|
11
|
+
TaLocation2.isRemote = isRemote;
|
|
12
|
+
function isCloud(host2) {
|
|
13
|
+
return !!host2 && host2.startsWith(TaLocation2.CLOUD);
|
|
14
|
+
}
|
|
15
|
+
TaLocation2.isCloud = isCloud;
|
|
16
|
+
function isCloudName(name) {
|
|
17
|
+
return CLOUD_NAME.test(name);
|
|
18
|
+
}
|
|
19
|
+
TaLocation2.isCloudName = isCloudName;
|
|
20
|
+
function cloud(name, path2 = "") {
|
|
21
|
+
return `${TaLocation2.CLOUD}${name}${path2 ? normalize(path2) : ""}`;
|
|
22
|
+
}
|
|
23
|
+
TaLocation2.cloud = cloud;
|
|
24
|
+
function cloudName(hostOrLocation) {
|
|
25
|
+
if (!hostOrLocation.startsWith(TaLocation2.CLOUD)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const rest = hostOrLocation.slice(TaLocation2.CLOUD.length);
|
|
29
|
+
const slash = rest.indexOf("/");
|
|
30
|
+
return slash < 0 ? rest : rest.slice(0, slash);
|
|
31
|
+
}
|
|
32
|
+
TaLocation2.cloudName = cloudName;
|
|
33
|
+
function parse(location) {
|
|
34
|
+
var _a;
|
|
35
|
+
if (!isRemote(location)) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (location.startsWith(TaLocation2.CLOUD)) {
|
|
39
|
+
const name = (_a = cloudName(location)) !== null && _a !== undefined ? _a : "";
|
|
40
|
+
if (!isCloudName(name)) {
|
|
41
|
+
throw new Error(`${JSON.stringify(location)} names no cloud workspace: write ta://<name>/<path>.`);
|
|
42
|
+
}
|
|
43
|
+
const path3 = location.slice(TaLocation2.CLOUD.length + name.length);
|
|
44
|
+
return { host: `${TaLocation2.CLOUD}${name}`, path: path3 ? normalize(path3) : "" };
|
|
45
|
+
}
|
|
46
|
+
const rest = location.slice(TaLocation2.SSH.length);
|
|
47
|
+
const slash = rest.indexOf("/");
|
|
48
|
+
const host2 = slash < 0 ? rest : rest.slice(0, slash);
|
|
49
|
+
const path2 = slash < 0 ? "" : normalize(rest.slice(slash));
|
|
50
|
+
if (!isHost(host2)) {
|
|
51
|
+
throw new Error(`${JSON.stringify(location)} names no host: write ssh://<host>/<path>, the host as ssh takes it.`);
|
|
52
|
+
}
|
|
53
|
+
return { host: host2, path: path2 };
|
|
54
|
+
}
|
|
55
|
+
TaLocation2.parse = parse;
|
|
56
|
+
function isHost(host2) {
|
|
57
|
+
return isCloud(host2) ? isCloudName(host2.slice(TaLocation2.CLOUD.length)) : HOST.test(host2);
|
|
58
|
+
}
|
|
59
|
+
TaLocation2.isHost = isHost;
|
|
60
|
+
const FLAGS = /^-[46AaCfGgKkMNnqsTtVvXxYy]+$/;
|
|
61
|
+
function readHost(input) {
|
|
62
|
+
const words = input.trim().split(/\s+/).filter(Boolean);
|
|
63
|
+
if (words[0] === "ssh") {
|
|
64
|
+
words.shift();
|
|
65
|
+
}
|
|
66
|
+
let destination;
|
|
67
|
+
let port;
|
|
68
|
+
let user;
|
|
69
|
+
const options = [];
|
|
70
|
+
for (let i = 0;i < words.length; i++) {
|
|
71
|
+
const word = words[i];
|
|
72
|
+
const glued = /^-([pl])(.+)$/.exec(word);
|
|
73
|
+
if (word === "-p" || word === "-l" || glued) {
|
|
74
|
+
const value = glued ? glued[2] : words[++i];
|
|
75
|
+
if (value === undefined) {
|
|
76
|
+
return { error: "invalid" };
|
|
77
|
+
}
|
|
78
|
+
if ((glued ? glued[1] : word[1]) === "p") {
|
|
79
|
+
port = value;
|
|
80
|
+
} else {
|
|
81
|
+
user = value;
|
|
82
|
+
}
|
|
83
|
+
} else if (word === "-o" || word.startsWith("-o")) {
|
|
84
|
+
const value = word === "-o" ? words[++i] : word.slice(2);
|
|
85
|
+
const option = /^(port|user)\s*=?\s*(.+)$/i.exec(value !== null && value !== undefined ? value : "");
|
|
86
|
+
if (!option) {
|
|
87
|
+
options.push(`-o ${value !== null && value !== undefined ? value : ""}`.trim());
|
|
88
|
+
} else if (option[1].toLowerCase() === "port") {
|
|
89
|
+
port = option[2];
|
|
90
|
+
} else {
|
|
91
|
+
user = option[2];
|
|
92
|
+
}
|
|
93
|
+
} else if (FLAGS.test(word)) {} else if (word.startsWith("-")) {
|
|
94
|
+
options.push(/^-[bBcDeEFiIJLmOQRSwW]$/.test(word) && words[i + 1] !== undefined ? `${word} ${words[++i]}` : word);
|
|
95
|
+
} else if (destination === undefined) {
|
|
96
|
+
destination = word;
|
|
97
|
+
} else {
|
|
98
|
+
return { error: "invalid" };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (options.length > 0) {
|
|
102
|
+
return { error: "options", options };
|
|
103
|
+
}
|
|
104
|
+
if (!destination) {
|
|
105
|
+
return { error: "empty" };
|
|
106
|
+
}
|
|
107
|
+
let host2 = destination.replace(/^ssh:\/\//, "").replace(/\/.*$/, "");
|
|
108
|
+
if (user && !host2.includes("@")) {
|
|
109
|
+
host2 = `${user}@${host2}`;
|
|
110
|
+
}
|
|
111
|
+
if (port) {
|
|
112
|
+
if (!/^\d{1,5}$/.test(port) || /:\d+$/.test(host2)) {
|
|
113
|
+
return { error: "invalid" };
|
|
114
|
+
}
|
|
115
|
+
host2 = port === "22" ? host2 : `${host2}:${port}`;
|
|
116
|
+
}
|
|
117
|
+
return isHost(host2) ? { host: host2 } : { error: "invalid" };
|
|
118
|
+
}
|
|
119
|
+
TaLocation2.readHost = readHost;
|
|
120
|
+
function ssh(host2, path2 = "") {
|
|
121
|
+
return isCloud(host2) ? `${host2}${path2 ? normalize(path2) : ""}` : `${TaLocation2.SSH}${host2}${path2 ? normalize(path2) : ""}`;
|
|
122
|
+
}
|
|
123
|
+
TaLocation2.ssh = ssh;
|
|
124
|
+
function hostLabel(host2) {
|
|
125
|
+
if (isCloud(host2)) {
|
|
126
|
+
return host2.slice(TaLocation2.CLOUD.length);
|
|
127
|
+
}
|
|
128
|
+
const name = host2.replace(/^[^@]*@/, "").replace(/^\[(.*)\](?::\d+)?$/, "$1").replace(/^([^:]*):\d+$/, "$1");
|
|
129
|
+
return /^[\d.]+$/.test(name) || name.includes(":") ? name : name.split(".")[0] || name;
|
|
130
|
+
}
|
|
131
|
+
TaLocation2.hostLabel = hostLabel;
|
|
132
|
+
function host(location) {
|
|
133
|
+
var _a;
|
|
134
|
+
return isRemote(location) ? (_a = parse(location)) === null || _a === undefined ? undefined : _a.host : undefined;
|
|
135
|
+
}
|
|
136
|
+
TaLocation2.host = host;
|
|
137
|
+
function path(location) {
|
|
138
|
+
var _a;
|
|
139
|
+
var _b;
|
|
140
|
+
return (_b = (_a = parse(location)) === null || _a === undefined ? undefined : _a.path) !== null && _b !== undefined ? _b : location;
|
|
141
|
+
}
|
|
142
|
+
TaLocation2.path = path;
|
|
143
|
+
function parent(location) {
|
|
144
|
+
const remote = parse(location);
|
|
145
|
+
if (remote) {
|
|
146
|
+
const above = remote.path ? parentPath(remote.path) : undefined;
|
|
147
|
+
return above === undefined ? undefined : ssh(remote.host, above);
|
|
148
|
+
}
|
|
149
|
+
return parentPath(location);
|
|
150
|
+
}
|
|
151
|
+
TaLocation2.parent = parent;
|
|
152
|
+
function child(location, name) {
|
|
153
|
+
const remote = parse(location);
|
|
154
|
+
if (remote) {
|
|
155
|
+
return ssh(remote.host, childPath(remote.path || "/", name));
|
|
156
|
+
}
|
|
157
|
+
return childPath(location, name);
|
|
158
|
+
}
|
|
159
|
+
TaLocation2.child = child;
|
|
160
|
+
function basename(location) {
|
|
161
|
+
const remote = parse(location);
|
|
162
|
+
const path2 = (remote ? remote.path : location).replace(/[\\/]+$/, "");
|
|
163
|
+
const name = path2.slice(Math.max(path2.lastIndexOf("/"), path2.lastIndexOf("\\")) + 1);
|
|
164
|
+
return name || (remote === null || remote === undefined ? undefined : remote.host) || location;
|
|
165
|
+
}
|
|
166
|
+
TaLocation2.basename = basename;
|
|
167
|
+
function homeRelative(location) {
|
|
168
|
+
var _a;
|
|
169
|
+
const remote = parse(location);
|
|
170
|
+
const path2 = remote ? remote.path ? remote.path.slice(1) : "~" : location;
|
|
171
|
+
const match = /^~(?:[\\/]+(.*))?$/.exec(path2);
|
|
172
|
+
return match ? ((_a = match[1]) !== null && _a !== undefined ? _a : "").replace(/[\\/]+$/, "") : undefined;
|
|
173
|
+
}
|
|
174
|
+
TaLocation2.homeRelative = homeRelative;
|
|
175
|
+
function isAbsolute(location) {
|
|
176
|
+
if (homeRelative(location) !== undefined) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
return isRemote(location) || /^([\\/]|[A-Za-z]:)/.test(location);
|
|
180
|
+
}
|
|
181
|
+
TaLocation2.isAbsolute = isAbsolute;
|
|
182
|
+
function parentPath(path2) {
|
|
183
|
+
const trimmed = path2.replace(/[\\/]+$/, "");
|
|
184
|
+
const at = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));
|
|
185
|
+
if (at < 0) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const head = trimmed.slice(0, at);
|
|
189
|
+
return head === "" || /^[A-Za-z]:$/.test(head) ? head + trimmed[at] : head;
|
|
190
|
+
}
|
|
191
|
+
function childPath(path2, name) {
|
|
192
|
+
const separator = path2.includes("/") || !path2.includes("\\") ? "/" : "\\";
|
|
193
|
+
return path2.endsWith(separator) ? path2 + name : path2 + separator + name;
|
|
194
|
+
}
|
|
195
|
+
function normalize(path2) {
|
|
196
|
+
const squeezed = `/${path2}`.replace(/\/+/g, "/");
|
|
197
|
+
return squeezed.length > 1 ? squeezed.replace(/\/$/, "") : squeezed;
|
|
198
|
+
}
|
|
199
|
+
})(TaLocation || (TaLocation = {}));
|
|
200
|
+
|
|
201
|
+
// web-src/boundaries-protocol.ts
|
|
202
|
+
var NAME = "@celljs/ta-boundaries";
|
|
203
|
+
var Keys = { MARKS: "marks", FALLBACK: "fallback" };
|
|
204
|
+
var MARK_KINDS = ["general", "work", "private"];
|
|
205
|
+
var NAME_MAX = 16;
|
|
206
|
+
var MARKS_MAX = 500;
|
|
207
|
+
var BoundaryMarks;
|
|
208
|
+
((BoundaryMarks) => {
|
|
209
|
+
const GENERAL = { kind: "general" };
|
|
210
|
+
function key(location) {
|
|
211
|
+
const trimmed = location.trim();
|
|
212
|
+
const remote = TaLocation.parse(trimmed);
|
|
213
|
+
if (remote) {
|
|
214
|
+
return TaLocation.ssh(remote.host, remote.path.length > 1 ? remote.path.replace(/[\\/]+$/, "") : remote.path);
|
|
215
|
+
}
|
|
216
|
+
return trimmed.length > 1 ? trimmed.replace(/(?<=[^\\/:])[\\/]+$/, "") : trimmed;
|
|
217
|
+
}
|
|
218
|
+
BoundaryMarks.key = key;
|
|
219
|
+
function parse(value) {
|
|
220
|
+
if (!Array.isArray(value)) {
|
|
221
|
+
return [];
|
|
222
|
+
}
|
|
223
|
+
const seen = new Set;
|
|
224
|
+
const marks = [];
|
|
225
|
+
for (const item of value) {
|
|
226
|
+
if (!item || typeof item.location !== "string" || !item.location.trim() || !MARK_KINDS.includes(item.kind)) {
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
const location = key(item.location);
|
|
230
|
+
if (seen.has(location)) {
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
seen.add(location);
|
|
234
|
+
const name = typeof item.name === "string" ? item.name.trim().slice(0, NAME_MAX) : "";
|
|
235
|
+
marks.push({ location, kind: item.kind, ...name ? { name } : {}, at: typeof item.at === "number" ? item.at : 0 });
|
|
236
|
+
}
|
|
237
|
+
return marks.slice(0, MARKS_MAX);
|
|
238
|
+
}
|
|
239
|
+
BoundaryMarks.parse = parse;
|
|
240
|
+
function fallback(value) {
|
|
241
|
+
return value === "work" ? "work" : undefined;
|
|
242
|
+
}
|
|
243
|
+
BoundaryMarks.fallback = fallback;
|
|
244
|
+
function of(marks, fallback2, location) {
|
|
245
|
+
if (location?.trim()) {
|
|
246
|
+
const byLocation = new Map(marks.map((mark) => [mark.location, mark]));
|
|
247
|
+
let at = key(location);
|
|
248
|
+
for (let depth = 0;at && depth < 64; depth++) {
|
|
249
|
+
const mark = byLocation.get(at);
|
|
250
|
+
if (mark) {
|
|
251
|
+
return mark.kind === "general" ? GENERAL : { kind: mark.kind, root: mark.location, ...mark.name ? { name: mark.name } : {} };
|
|
252
|
+
}
|
|
253
|
+
at = TaLocation.parent(at);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return fallback2 ? { kind: fallback2 } : GENERAL;
|
|
257
|
+
}
|
|
258
|
+
BoundaryMarks.of = of;
|
|
259
|
+
function own(marks, location) {
|
|
260
|
+
const at = key(location);
|
|
261
|
+
return marks.find((mark) => mark.location === at);
|
|
262
|
+
}
|
|
263
|
+
BoundaryMarks.own = own;
|
|
264
|
+
function set(marks, fallback2, location, kind, name, at) {
|
|
265
|
+
const where = key(location);
|
|
266
|
+
const others = marks.filter((mark) => mark.location !== where);
|
|
267
|
+
const without = of(others, fallback2, where).kind;
|
|
268
|
+
const shown = name?.trim().slice(0, NAME_MAX);
|
|
269
|
+
if (kind === without && !shown) {
|
|
270
|
+
return others;
|
|
271
|
+
}
|
|
272
|
+
return [...others, { location: where, kind, ...shown ? { name: shown } : {}, at }].slice(-MARKS_MAX);
|
|
273
|
+
}
|
|
274
|
+
BoundaryMarks.set = set;
|
|
275
|
+
function unset(marks, location) {
|
|
276
|
+
const where = key(location);
|
|
277
|
+
return marks.filter((mark) => mark.location !== where);
|
|
278
|
+
}
|
|
279
|
+
BoundaryMarks.unset = unset;
|
|
280
|
+
})(BoundaryMarks ||= {});
|
|
281
|
+
|
|
282
|
+
// web-src/boundaries-host.ts
|
|
283
|
+
class BoundariesHost {
|
|
284
|
+
host;
|
|
285
|
+
env;
|
|
286
|
+
now;
|
|
287
|
+
marks = [];
|
|
288
|
+
fallback;
|
|
289
|
+
stops = [];
|
|
290
|
+
writing = Promise.resolve();
|
|
291
|
+
constructor(host, env = process.env, now = Date.now) {
|
|
292
|
+
this.host = host;
|
|
293
|
+
this.env = env;
|
|
294
|
+
this.now = now;
|
|
295
|
+
}
|
|
296
|
+
async start() {
|
|
297
|
+
this.fallback = this.env.TA_ACCOUNT_KIND === "cloud" ? "work" : undefined;
|
|
298
|
+
await this.read();
|
|
299
|
+
if (BoundaryMarks.fallback(await this.host.getExtensionData(NAME, Keys.FALLBACK)) !== this.fallback) {
|
|
300
|
+
await this.host.setExtensionData(NAME, Keys.FALLBACK, this.fallback ?? null);
|
|
301
|
+
}
|
|
302
|
+
this.stops.push(this.host.onExtensionData((name, key, cwd) => name === NAME && key === Keys.MARKS && !cwd && void this.read()));
|
|
303
|
+
const stop = this.host.boundaries?.provide({ of: (location) => this.of(location) });
|
|
304
|
+
if (stop) {
|
|
305
|
+
this.stops.push(stop);
|
|
306
|
+
}
|
|
307
|
+
return this;
|
|
308
|
+
}
|
|
309
|
+
dispose() {
|
|
310
|
+
for (const stop of this.stops.splice(0)) {
|
|
311
|
+
stop();
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
of(location) {
|
|
315
|
+
return BoundaryMarks.of(this.marks, this.fallback, typeof location === "string" ? location : undefined);
|
|
316
|
+
}
|
|
317
|
+
list() {
|
|
318
|
+
return { marks: this.marks, ...this.fallback ? { fallback: this.fallback } : {} };
|
|
319
|
+
}
|
|
320
|
+
mark(location, kind, name) {
|
|
321
|
+
if (typeof location !== "string" || !location.trim()) {
|
|
322
|
+
throw new Error("Name the directory to mark: a path or ssh://<host>/<path>.");
|
|
323
|
+
}
|
|
324
|
+
if (!MARK_KINDS.includes(kind)) {
|
|
325
|
+
throw new Error(`A directory is marked ${MARK_KINDS.join(", ")}.`);
|
|
326
|
+
}
|
|
327
|
+
return this.change((marks) => BoundaryMarks.set(marks, this.fallback, location, kind, typeof name === "string" ? name : undefined, this.now()));
|
|
328
|
+
}
|
|
329
|
+
unmark(location) {
|
|
330
|
+
if (typeof location !== "string" || !location.trim()) {
|
|
331
|
+
throw new Error("Name the directory: a path or ssh://<host>/<path>.");
|
|
332
|
+
}
|
|
333
|
+
return this.change((marks) => BoundaryMarks.unset(marks, location));
|
|
334
|
+
}
|
|
335
|
+
clear() {
|
|
336
|
+
return this.change(() => []);
|
|
337
|
+
}
|
|
338
|
+
async read() {
|
|
339
|
+
this.marks = BoundaryMarks.parse(await this.host.getExtensionData(NAME, Keys.MARKS));
|
|
340
|
+
}
|
|
341
|
+
change(update) {
|
|
342
|
+
const next = this.writing.then(async () => {
|
|
343
|
+
await this.read();
|
|
344
|
+
this.marks = update(this.marks);
|
|
345
|
+
await this.host.setExtensionData(NAME, Keys.MARKS, this.marks.length ? this.marks : null);
|
|
346
|
+
return { marks: this.marks };
|
|
347
|
+
});
|
|
348
|
+
this.writing = next.catch(() => {
|
|
349
|
+
return;
|
|
350
|
+
});
|
|
351
|
+
return next;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// web-src/host.ts
|
|
356
|
+
function activate(host) {
|
|
357
|
+
return new BoundariesHost(host).start();
|
|
358
|
+
}
|
|
359
|
+
export {
|
|
360
|
+
activate as default
|
|
361
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ta-boundaries",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "4.30.0",
|
|
4
|
+
"description": "A pi package for Ta: directories marked as work or private, the boundary of each conversation, which Ta's memory, recall and vault keep to",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-package"
|
|
7
|
+
],
|
|
8
|
+
"homepage": "https://github.com/cellbang/ta",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/cellbang/ta/issues"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/cellbang/cell.git"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"files": [
|
|
18
|
+
"web",
|
|
19
|
+
"host",
|
|
20
|
+
"!**/*.map"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc -b && bun build web-src/index.tsx --format esm --target browser --outfile web/index.js && bun build web-src/host.ts --format esm --target node --outfile host/index.mjs",
|
|
24
|
+
"clean": "rm -rf lib web host *.tsbuildinfo",
|
|
25
|
+
"test": "bun test ./lib",
|
|
26
|
+
"watch": "tsc -b -w --preserveWatchOutput"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@celljs/ta-protocol": "4.30.0",
|
|
30
|
+
"@celljs/ta-web": "4.30.0",
|
|
31
|
+
"@types/react": "^19.3.0"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"pi": {
|
|
37
|
+
"title": {
|
|
38
|
+
"en": "Directory marks",
|
|
39
|
+
"zh-CN": "目录标记",
|
|
40
|
+
"zh-TW": "目錄標記",
|
|
41
|
+
"ja-JP": "フォルダーのマーク"
|
|
42
|
+
},
|
|
43
|
+
"summary": {
|
|
44
|
+
"en": "Mark a directory as work or private: its conversations show a small label after their name, so you see at a glance where you are.",
|
|
45
|
+
"zh-CN": "把目录标成公司的或私密的:这个目录里的对话名字后面会显示一个小标签,一眼看出在哪儿做事。",
|
|
46
|
+
"zh-TW": "把目錄標成公司的或私密的:這個目錄裡的對話名字後面會顯示一個小標籤,一眼看出在哪裡做事。",
|
|
47
|
+
"ja-JP": "フォルダーを仕事用やプライベートとしてマークします。そのフォルダーの会話は名前の後ろに小さなラベルが付き、どこで作業しているかがひと目で分かります。"
|
|
48
|
+
},
|
|
49
|
+
"icon": "FolderLock",
|
|
50
|
+
"group": "tools",
|
|
51
|
+
"web": [
|
|
52
|
+
"./web/index.js"
|
|
53
|
+
],
|
|
54
|
+
"host": "./host/index.mjs",
|
|
55
|
+
"sync": [
|
|
56
|
+
"marks"
|
|
57
|
+
],
|
|
58
|
+
"permissions": {
|
|
59
|
+
"host": {
|
|
60
|
+
"*": "settings.manage"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
package/web/index.js
ADDED
|
@@ -0,0 +1,732 @@
|
|
|
1
|
+
// ../ta-protocol/esm/common/location.js
|
|
2
|
+
var TaLocation;
|
|
3
|
+
(function(TaLocation2) {
|
|
4
|
+
TaLocation2.SSH = "ssh://";
|
|
5
|
+
TaLocation2.CLOUD = "ta://";
|
|
6
|
+
const CLOUD_NAME = /^[a-z0-9][a-z0-9-]{0,39}$/;
|
|
7
|
+
const HOST = /^(?!-)[\w.@:%+[\]-]+$/;
|
|
8
|
+
function isRemote(location) {
|
|
9
|
+
return location.startsWith(TaLocation2.SSH) || location.startsWith(TaLocation2.CLOUD);
|
|
10
|
+
}
|
|
11
|
+
TaLocation2.isRemote = isRemote;
|
|
12
|
+
function isCloud(host2) {
|
|
13
|
+
return !!host2 && host2.startsWith(TaLocation2.CLOUD);
|
|
14
|
+
}
|
|
15
|
+
TaLocation2.isCloud = isCloud;
|
|
16
|
+
function isCloudName(name) {
|
|
17
|
+
return CLOUD_NAME.test(name);
|
|
18
|
+
}
|
|
19
|
+
TaLocation2.isCloudName = isCloudName;
|
|
20
|
+
function cloud(name, path2 = "") {
|
|
21
|
+
return `${TaLocation2.CLOUD}${name}${path2 ? normalize(path2) : ""}`;
|
|
22
|
+
}
|
|
23
|
+
TaLocation2.cloud = cloud;
|
|
24
|
+
function cloudName(hostOrLocation) {
|
|
25
|
+
if (!hostOrLocation.startsWith(TaLocation2.CLOUD)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const rest = hostOrLocation.slice(TaLocation2.CLOUD.length);
|
|
29
|
+
const slash = rest.indexOf("/");
|
|
30
|
+
return slash < 0 ? rest : rest.slice(0, slash);
|
|
31
|
+
}
|
|
32
|
+
TaLocation2.cloudName = cloudName;
|
|
33
|
+
function parse(location) {
|
|
34
|
+
var _a;
|
|
35
|
+
if (!isRemote(location)) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (location.startsWith(TaLocation2.CLOUD)) {
|
|
39
|
+
const name = (_a = cloudName(location)) !== null && _a !== undefined ? _a : "";
|
|
40
|
+
if (!isCloudName(name)) {
|
|
41
|
+
throw new Error(`${JSON.stringify(location)} names no cloud workspace: write ta://<name>/<path>.`);
|
|
42
|
+
}
|
|
43
|
+
const path3 = location.slice(TaLocation2.CLOUD.length + name.length);
|
|
44
|
+
return { host: `${TaLocation2.CLOUD}${name}`, path: path3 ? normalize(path3) : "" };
|
|
45
|
+
}
|
|
46
|
+
const rest = location.slice(TaLocation2.SSH.length);
|
|
47
|
+
const slash = rest.indexOf("/");
|
|
48
|
+
const host2 = slash < 0 ? rest : rest.slice(0, slash);
|
|
49
|
+
const path2 = slash < 0 ? "" : normalize(rest.slice(slash));
|
|
50
|
+
if (!isHost(host2)) {
|
|
51
|
+
throw new Error(`${JSON.stringify(location)} names no host: write ssh://<host>/<path>, the host as ssh takes it.`);
|
|
52
|
+
}
|
|
53
|
+
return { host: host2, path: path2 };
|
|
54
|
+
}
|
|
55
|
+
TaLocation2.parse = parse;
|
|
56
|
+
function isHost(host2) {
|
|
57
|
+
return isCloud(host2) ? isCloudName(host2.slice(TaLocation2.CLOUD.length)) : HOST.test(host2);
|
|
58
|
+
}
|
|
59
|
+
TaLocation2.isHost = isHost;
|
|
60
|
+
const FLAGS = /^-[46AaCfGgKkMNnqsTtVvXxYy]+$/;
|
|
61
|
+
function readHost(input) {
|
|
62
|
+
const words = input.trim().split(/\s+/).filter(Boolean);
|
|
63
|
+
if (words[0] === "ssh") {
|
|
64
|
+
words.shift();
|
|
65
|
+
}
|
|
66
|
+
let destination;
|
|
67
|
+
let port;
|
|
68
|
+
let user;
|
|
69
|
+
const options = [];
|
|
70
|
+
for (let i = 0;i < words.length; i++) {
|
|
71
|
+
const word = words[i];
|
|
72
|
+
const glued = /^-([pl])(.+)$/.exec(word);
|
|
73
|
+
if (word === "-p" || word === "-l" || glued) {
|
|
74
|
+
const value = glued ? glued[2] : words[++i];
|
|
75
|
+
if (value === undefined) {
|
|
76
|
+
return { error: "invalid" };
|
|
77
|
+
}
|
|
78
|
+
if ((glued ? glued[1] : word[1]) === "p") {
|
|
79
|
+
port = value;
|
|
80
|
+
} else {
|
|
81
|
+
user = value;
|
|
82
|
+
}
|
|
83
|
+
} else if (word === "-o" || word.startsWith("-o")) {
|
|
84
|
+
const value = word === "-o" ? words[++i] : word.slice(2);
|
|
85
|
+
const option = /^(port|user)\s*=?\s*(.+)$/i.exec(value !== null && value !== undefined ? value : "");
|
|
86
|
+
if (!option) {
|
|
87
|
+
options.push(`-o ${value !== null && value !== undefined ? value : ""}`.trim());
|
|
88
|
+
} else if (option[1].toLowerCase() === "port") {
|
|
89
|
+
port = option[2];
|
|
90
|
+
} else {
|
|
91
|
+
user = option[2];
|
|
92
|
+
}
|
|
93
|
+
} else if (FLAGS.test(word)) {} else if (word.startsWith("-")) {
|
|
94
|
+
options.push(/^-[bBcDeEFiIJLmOQRSwW]$/.test(word) && words[i + 1] !== undefined ? `${word} ${words[++i]}` : word);
|
|
95
|
+
} else if (destination === undefined) {
|
|
96
|
+
destination = word;
|
|
97
|
+
} else {
|
|
98
|
+
return { error: "invalid" };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (options.length > 0) {
|
|
102
|
+
return { error: "options", options };
|
|
103
|
+
}
|
|
104
|
+
if (!destination) {
|
|
105
|
+
return { error: "empty" };
|
|
106
|
+
}
|
|
107
|
+
let host2 = destination.replace(/^ssh:\/\//, "").replace(/\/.*$/, "");
|
|
108
|
+
if (user && !host2.includes("@")) {
|
|
109
|
+
host2 = `${user}@${host2}`;
|
|
110
|
+
}
|
|
111
|
+
if (port) {
|
|
112
|
+
if (!/^\d{1,5}$/.test(port) || /:\d+$/.test(host2)) {
|
|
113
|
+
return { error: "invalid" };
|
|
114
|
+
}
|
|
115
|
+
host2 = port === "22" ? host2 : `${host2}:${port}`;
|
|
116
|
+
}
|
|
117
|
+
return isHost(host2) ? { host: host2 } : { error: "invalid" };
|
|
118
|
+
}
|
|
119
|
+
TaLocation2.readHost = readHost;
|
|
120
|
+
function ssh(host2, path2 = "") {
|
|
121
|
+
return isCloud(host2) ? `${host2}${path2 ? normalize(path2) : ""}` : `${TaLocation2.SSH}${host2}${path2 ? normalize(path2) : ""}`;
|
|
122
|
+
}
|
|
123
|
+
TaLocation2.ssh = ssh;
|
|
124
|
+
function hostLabel(host2) {
|
|
125
|
+
if (isCloud(host2)) {
|
|
126
|
+
return host2.slice(TaLocation2.CLOUD.length);
|
|
127
|
+
}
|
|
128
|
+
const name = host2.replace(/^[^@]*@/, "").replace(/^\[(.*)\](?::\d+)?$/, "$1").replace(/^([^:]*):\d+$/, "$1");
|
|
129
|
+
return /^[\d.]+$/.test(name) || name.includes(":") ? name : name.split(".")[0] || name;
|
|
130
|
+
}
|
|
131
|
+
TaLocation2.hostLabel = hostLabel;
|
|
132
|
+
function host(location) {
|
|
133
|
+
var _a;
|
|
134
|
+
return isRemote(location) ? (_a = parse(location)) === null || _a === undefined ? undefined : _a.host : undefined;
|
|
135
|
+
}
|
|
136
|
+
TaLocation2.host = host;
|
|
137
|
+
function path(location) {
|
|
138
|
+
var _a;
|
|
139
|
+
var _b;
|
|
140
|
+
return (_b = (_a = parse(location)) === null || _a === undefined ? undefined : _a.path) !== null && _b !== undefined ? _b : location;
|
|
141
|
+
}
|
|
142
|
+
TaLocation2.path = path;
|
|
143
|
+
function parent(location) {
|
|
144
|
+
const remote = parse(location);
|
|
145
|
+
if (remote) {
|
|
146
|
+
const above = remote.path ? parentPath(remote.path) : undefined;
|
|
147
|
+
return above === undefined ? undefined : ssh(remote.host, above);
|
|
148
|
+
}
|
|
149
|
+
return parentPath(location);
|
|
150
|
+
}
|
|
151
|
+
TaLocation2.parent = parent;
|
|
152
|
+
function child(location, name) {
|
|
153
|
+
const remote = parse(location);
|
|
154
|
+
if (remote) {
|
|
155
|
+
return ssh(remote.host, childPath(remote.path || "/", name));
|
|
156
|
+
}
|
|
157
|
+
return childPath(location, name);
|
|
158
|
+
}
|
|
159
|
+
TaLocation2.child = child;
|
|
160
|
+
function basename(location) {
|
|
161
|
+
const remote = parse(location);
|
|
162
|
+
const path2 = (remote ? remote.path : location).replace(/[\\/]+$/, "");
|
|
163
|
+
const name = path2.slice(Math.max(path2.lastIndexOf("/"), path2.lastIndexOf("\\")) + 1);
|
|
164
|
+
return name || (remote === null || remote === undefined ? undefined : remote.host) || location;
|
|
165
|
+
}
|
|
166
|
+
TaLocation2.basename = basename;
|
|
167
|
+
function homeRelative(location) {
|
|
168
|
+
var _a;
|
|
169
|
+
const remote = parse(location);
|
|
170
|
+
const path2 = remote ? remote.path ? remote.path.slice(1) : "~" : location;
|
|
171
|
+
const match = /^~(?:[\\/]+(.*))?$/.exec(path2);
|
|
172
|
+
return match ? ((_a = match[1]) !== null && _a !== undefined ? _a : "").replace(/[\\/]+$/, "") : undefined;
|
|
173
|
+
}
|
|
174
|
+
TaLocation2.homeRelative = homeRelative;
|
|
175
|
+
function isAbsolute(location) {
|
|
176
|
+
if (homeRelative(location) !== undefined) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
return isRemote(location) || /^([\\/]|[A-Za-z]:)/.test(location);
|
|
180
|
+
}
|
|
181
|
+
TaLocation2.isAbsolute = isAbsolute;
|
|
182
|
+
function parentPath(path2) {
|
|
183
|
+
const trimmed = path2.replace(/[\\/]+$/, "");
|
|
184
|
+
const at = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));
|
|
185
|
+
if (at < 0) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const head = trimmed.slice(0, at);
|
|
189
|
+
return head === "" || /^[A-Za-z]:$/.test(head) ? head + trimmed[at] : head;
|
|
190
|
+
}
|
|
191
|
+
function childPath(path2, name) {
|
|
192
|
+
const separator = path2.includes("/") || !path2.includes("\\") ? "/" : "\\";
|
|
193
|
+
return path2.endsWith(separator) ? path2 + name : path2 + separator + name;
|
|
194
|
+
}
|
|
195
|
+
function normalize(path2) {
|
|
196
|
+
const squeezed = `/${path2}`.replace(/\/+/g, "/");
|
|
197
|
+
return squeezed.length > 1 ? squeezed.replace(/\/$/, "") : squeezed;
|
|
198
|
+
}
|
|
199
|
+
})(TaLocation || (TaLocation = {}));
|
|
200
|
+
|
|
201
|
+
// web-src/boundaries-protocol.ts
|
|
202
|
+
var Keys = { MARKS: "marks", FALLBACK: "fallback" };
|
|
203
|
+
var MARK_KINDS = ["general", "work", "private"];
|
|
204
|
+
var NAME_MAX = 16;
|
|
205
|
+
var MARKS_MAX = 500;
|
|
206
|
+
var BoundaryMarks;
|
|
207
|
+
((BoundaryMarks) => {
|
|
208
|
+
const GENERAL = { kind: "general" };
|
|
209
|
+
function key(location) {
|
|
210
|
+
const trimmed = location.trim();
|
|
211
|
+
const remote = TaLocation.parse(trimmed);
|
|
212
|
+
if (remote) {
|
|
213
|
+
return TaLocation.ssh(remote.host, remote.path.length > 1 ? remote.path.replace(/[\\/]+$/, "") : remote.path);
|
|
214
|
+
}
|
|
215
|
+
return trimmed.length > 1 ? trimmed.replace(/(?<=[^\\/:])[\\/]+$/, "") : trimmed;
|
|
216
|
+
}
|
|
217
|
+
BoundaryMarks.key = key;
|
|
218
|
+
function parse(value) {
|
|
219
|
+
if (!Array.isArray(value)) {
|
|
220
|
+
return [];
|
|
221
|
+
}
|
|
222
|
+
const seen = new Set;
|
|
223
|
+
const marks = [];
|
|
224
|
+
for (const item of value) {
|
|
225
|
+
if (!item || typeof item.location !== "string" || !item.location.trim() || !MARK_KINDS.includes(item.kind)) {
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
const location = key(item.location);
|
|
229
|
+
if (seen.has(location)) {
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
seen.add(location);
|
|
233
|
+
const name = typeof item.name === "string" ? item.name.trim().slice(0, NAME_MAX) : "";
|
|
234
|
+
marks.push({ location, kind: item.kind, ...name ? { name } : {}, at: typeof item.at === "number" ? item.at : 0 });
|
|
235
|
+
}
|
|
236
|
+
return marks.slice(0, MARKS_MAX);
|
|
237
|
+
}
|
|
238
|
+
BoundaryMarks.parse = parse;
|
|
239
|
+
function fallback(value) {
|
|
240
|
+
return value === "work" ? "work" : undefined;
|
|
241
|
+
}
|
|
242
|
+
BoundaryMarks.fallback = fallback;
|
|
243
|
+
function of(marks, fallback2, location) {
|
|
244
|
+
if (location?.trim()) {
|
|
245
|
+
const byLocation = new Map(marks.map((mark) => [mark.location, mark]));
|
|
246
|
+
let at = key(location);
|
|
247
|
+
for (let depth = 0;at && depth < 64; depth++) {
|
|
248
|
+
const mark = byLocation.get(at);
|
|
249
|
+
if (mark) {
|
|
250
|
+
return mark.kind === "general" ? GENERAL : { kind: mark.kind, root: mark.location, ...mark.name ? { name: mark.name } : {} };
|
|
251
|
+
}
|
|
252
|
+
at = TaLocation.parent(at);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return fallback2 ? { kind: fallback2 } : GENERAL;
|
|
256
|
+
}
|
|
257
|
+
BoundaryMarks.of = of;
|
|
258
|
+
function own(marks, location) {
|
|
259
|
+
const at = key(location);
|
|
260
|
+
return marks.find((mark) => mark.location === at);
|
|
261
|
+
}
|
|
262
|
+
BoundaryMarks.own = own;
|
|
263
|
+
function set(marks, fallback2, location, kind, name, at) {
|
|
264
|
+
const where = key(location);
|
|
265
|
+
const others = marks.filter((mark) => mark.location !== where);
|
|
266
|
+
const without = of(others, fallback2, where).kind;
|
|
267
|
+
const shown = name?.trim().slice(0, NAME_MAX);
|
|
268
|
+
if (kind === without && !shown) {
|
|
269
|
+
return others;
|
|
270
|
+
}
|
|
271
|
+
return [...others, { location: where, kind, ...shown ? { name: shown } : {}, at }].slice(-MARKS_MAX);
|
|
272
|
+
}
|
|
273
|
+
BoundaryMarks.set = set;
|
|
274
|
+
function unset(marks, location) {
|
|
275
|
+
const where = key(location);
|
|
276
|
+
return marks.filter((mark) => mark.location !== where);
|
|
277
|
+
}
|
|
278
|
+
BoundaryMarks.unset = unset;
|
|
279
|
+
})(BoundaryMarks ||= {});
|
|
280
|
+
|
|
281
|
+
// ../ta-protocol/esm/common/language.js
|
|
282
|
+
var TaLanguageUtil;
|
|
283
|
+
(function(TaLanguageUtil2) {
|
|
284
|
+
TaLanguageUtil2.ALL = ["zh-CN", "zh-TW", "en-US", "ja-JP"];
|
|
285
|
+
TaLanguageUtil2.NAMES = { "zh-CN": "简体中文", "zh-TW": "繁體中文", "en-US": "English", "ja-JP": "日本語" };
|
|
286
|
+
function of(tag) {
|
|
287
|
+
const said = (tag !== null && tag !== undefined ? tag : "").toLowerCase().replace(/_/g, "-");
|
|
288
|
+
if (/^zh(\b|-)/.test(said)) {
|
|
289
|
+
return /-hant\b/.test(said) || !/-hans\b/.test(said) && /-(tw|hk|mo)\b/.test(said) ? "zh-TW" : "zh-CN";
|
|
290
|
+
}
|
|
291
|
+
return /^ja(\b|-)/.test(said) ? "ja-JP" : "en-US";
|
|
292
|
+
}
|
|
293
|
+
TaLanguageUtil2.of = of;
|
|
294
|
+
function server(env = typeof process === "undefined" ? {} : process.env) {
|
|
295
|
+
return of(env.TA_LANGUAGE || env.LC_ALL || env.LC_MESSAGES || env.LANG);
|
|
296
|
+
}
|
|
297
|
+
TaLanguageUtil2.server = server;
|
|
298
|
+
function pick(language, words) {
|
|
299
|
+
return words[of(language)];
|
|
300
|
+
}
|
|
301
|
+
TaLanguageUtil2.pick = pick;
|
|
302
|
+
function say(words) {
|
|
303
|
+
return words[server()];
|
|
304
|
+
}
|
|
305
|
+
TaLanguageUtil2.say = say;
|
|
306
|
+
function chinese(language) {
|
|
307
|
+
return of(language).startsWith("zh");
|
|
308
|
+
}
|
|
309
|
+
TaLanguageUtil2.chinese = chinese;
|
|
310
|
+
function cjk(language) {
|
|
311
|
+
return of(language) !== "en-US";
|
|
312
|
+
}
|
|
313
|
+
TaLanguageUtil2.cjk = cjk;
|
|
314
|
+
function list(language, items) {
|
|
315
|
+
return items.join(cjk(language) ? "、" : ", ");
|
|
316
|
+
}
|
|
317
|
+
TaLanguageUtil2.list = list;
|
|
318
|
+
})(TaLanguageUtil || (TaLanguageUtil = {}));
|
|
319
|
+
|
|
320
|
+
// web-src/i18n.ts
|
|
321
|
+
var ZH = {
|
|
322
|
+
title: "目录标记",
|
|
323
|
+
menu: "目录标记…",
|
|
324
|
+
work: "公司",
|
|
325
|
+
private: "私密",
|
|
326
|
+
general: "通用",
|
|
327
|
+
workHint: "公司的事。名字后显示“公司”。",
|
|
328
|
+
privateHint: "只属于你。名字后显示“私密”和一把锁。",
|
|
329
|
+
generalHint: "和平常一样,不显示标签。",
|
|
330
|
+
generalCloudHint: "这台云端 Ta 没标记的目录都算公司的;选这个让这里不算。",
|
|
331
|
+
below: "下面的子目录也跟着它。",
|
|
332
|
+
from: "跟着上级目录 {dir}",
|
|
333
|
+
nameLabel: "显示名",
|
|
334
|
+
namePlaceholder: "可不填,比如 客户 A",
|
|
335
|
+
done: "完成",
|
|
336
|
+
tagTitle: "{dir} 是{kind}目录",
|
|
337
|
+
listLabel: "标记过的目录",
|
|
338
|
+
listHint: "在对话的菜单里选“目录标记…”来标。标记跟着你的几台电脑走。",
|
|
339
|
+
emptyTitle: "还没有标记的目录",
|
|
340
|
+
emptyHint: "在对话的菜单里选“目录标记…”",
|
|
341
|
+
remove: "移除",
|
|
342
|
+
clear: "清除全部标记",
|
|
343
|
+
clearTitle: "清除全部 {count} 个目录标记?",
|
|
344
|
+
clearHint: "这些目录都回到通用。",
|
|
345
|
+
cloudLabel: "没标记的目录",
|
|
346
|
+
cloudHint: "这是公司的云端 Ta,没标记的目录都算公司的。",
|
|
347
|
+
failed: "没改成:{message}"
|
|
348
|
+
};
|
|
349
|
+
var ZH_TW = {
|
|
350
|
+
title: "目錄標記",
|
|
351
|
+
menu: "目錄標記…",
|
|
352
|
+
work: "公司",
|
|
353
|
+
private: "私密",
|
|
354
|
+
general: "通用",
|
|
355
|
+
workHint: "公司的事。名字後顯示「公司」。",
|
|
356
|
+
privateHint: "只屬於你。名字後顯示「私密」和一把鎖。",
|
|
357
|
+
generalHint: "和平常一樣,不顯示標籤。",
|
|
358
|
+
generalCloudHint: "這台雲端 Ta 沒標記的目錄都算公司的;選這個讓這裡不算。",
|
|
359
|
+
below: "下面的子目錄也跟著它。",
|
|
360
|
+
from: "跟著上層目錄 {dir}",
|
|
361
|
+
nameLabel: "顯示名稱",
|
|
362
|
+
namePlaceholder: "可不填,例如 客戶 A",
|
|
363
|
+
done: "完成",
|
|
364
|
+
tagTitle: "{dir} 是{kind}目錄",
|
|
365
|
+
listLabel: "標記過的目錄",
|
|
366
|
+
listHint: "在對話的選單裡選「目錄標記…」來標。標記會跟著你的幾台電腦走。",
|
|
367
|
+
emptyTitle: "還沒有標記的目錄",
|
|
368
|
+
emptyHint: "在對話的選單裡選「目錄標記…」",
|
|
369
|
+
remove: "移除",
|
|
370
|
+
clear: "清除全部標記",
|
|
371
|
+
clearTitle: "清除全部 {count} 個目錄標記?",
|
|
372
|
+
clearHint: "這些目錄都回到通用。",
|
|
373
|
+
cloudLabel: "沒標記的目錄",
|
|
374
|
+
cloudHint: "這是公司的雲端 Ta,沒標記的目錄都算公司的。",
|
|
375
|
+
failed: "沒改成:{message}"
|
|
376
|
+
};
|
|
377
|
+
var EN = {
|
|
378
|
+
title: "Directory marks",
|
|
379
|
+
menu: "Mark the directory…",
|
|
380
|
+
work: "Work",
|
|
381
|
+
private: "Private",
|
|
382
|
+
general: "General",
|
|
383
|
+
workHint: "For work. “Work” after the name.",
|
|
384
|
+
privateHint: "Yours alone. “Private” and a lock after the name.",
|
|
385
|
+
generalHint: "As usual, no label.",
|
|
386
|
+
generalCloudHint: "This cloud Ta takes unmarked directories for work; pick this so that this one is not.",
|
|
387
|
+
below: "The directories inside it go with it.",
|
|
388
|
+
from: "As the directory above it, {dir}",
|
|
389
|
+
nameLabel: "Shown as",
|
|
390
|
+
namePlaceholder: "Optional, such as Client A",
|
|
391
|
+
done: "Done",
|
|
392
|
+
tagTitle: "{dir} is a {kind} directory",
|
|
393
|
+
listLabel: "Marked directories",
|
|
394
|
+
listHint: "Mark one from the menu of a conversation, Mark the directory…. Marks go with you to your other computers.",
|
|
395
|
+
emptyTitle: "No directory marked yet",
|
|
396
|
+
emptyHint: "Pick Mark the directory… in the menu of a conversation",
|
|
397
|
+
remove: "Remove",
|
|
398
|
+
clear: "Clear all marks",
|
|
399
|
+
clearTitle: "Clear all {count} marks?",
|
|
400
|
+
clearHint: "Those directories are general again.",
|
|
401
|
+
cloudLabel: "Unmarked directories",
|
|
402
|
+
cloudHint: "This is a cloud Ta of your company: unmarked directories are for work.",
|
|
403
|
+
failed: "Not changed: {message}"
|
|
404
|
+
};
|
|
405
|
+
var JA = {
|
|
406
|
+
title: "フォルダーのマーク",
|
|
407
|
+
menu: "フォルダーをマーク…",
|
|
408
|
+
work: "仕事",
|
|
409
|
+
private: "プライベート",
|
|
410
|
+
general: "通常",
|
|
411
|
+
workHint: "仕事用。名前の後ろに「仕事」と表示されます。",
|
|
412
|
+
privateHint: "あなただけのもの。名前の後ろに「プライベート」と鍵が表示されます。",
|
|
413
|
+
generalHint: "いつもどおり。ラベルは表示されません。",
|
|
414
|
+
generalCloudHint: "このクラウド Ta ではマークのないフォルダーは仕事用です。これを選ぶとここは対象外になります。",
|
|
415
|
+
below: "中のフォルダーも同じになります。",
|
|
416
|
+
from: "上のフォルダー {dir} と同じ",
|
|
417
|
+
nameLabel: "表示名",
|
|
418
|
+
namePlaceholder: "任意(例:クライアント A)",
|
|
419
|
+
done: "完了",
|
|
420
|
+
tagTitle: "{dir} は{kind}のフォルダーです",
|
|
421
|
+
listLabel: "マークしたフォルダー",
|
|
422
|
+
listHint: "会話のメニューの「フォルダーをマーク…」でマークします。マークはお使いのほかのコンピューターにも引き継がれます。",
|
|
423
|
+
emptyTitle: "マークしたフォルダーはまだありません",
|
|
424
|
+
emptyHint: "会話のメニューで「フォルダーをマーク…」を選んでください",
|
|
425
|
+
remove: "削除",
|
|
426
|
+
clear: "すべてのマークを消去",
|
|
427
|
+
clearTitle: "{count} 件のマークをすべて消去しますか?",
|
|
428
|
+
clearHint: "それらのフォルダーは通常に戻ります。",
|
|
429
|
+
cloudLabel: "マークのないフォルダー",
|
|
430
|
+
cloudHint: "これは会社のクラウド Ta です。マークのないフォルダーは仕事用になります。",
|
|
431
|
+
failed: "変更できませんでした:{message}"
|
|
432
|
+
};
|
|
433
|
+
var WORDS = { "zh-CN": ZH, "zh-TW": ZH_TW, "en-US": EN, "ja-JP": JA };
|
|
434
|
+
var BoundaryWords;
|
|
435
|
+
((BoundaryWords) => {
|
|
436
|
+
function of(language) {
|
|
437
|
+
return TaLanguageUtil.pick(language, WORDS);
|
|
438
|
+
}
|
|
439
|
+
BoundaryWords.of = of;
|
|
440
|
+
function format(text, values) {
|
|
441
|
+
return text.replace(/\{(\w+)\}/g, (whole, key) => (key in values) ? String(values[key]) : whole);
|
|
442
|
+
}
|
|
443
|
+
BoundaryWords.format = format;
|
|
444
|
+
})(BoundaryWords ||= {});
|
|
445
|
+
|
|
446
|
+
// web-src/react.ts
|
|
447
|
+
var React;
|
|
448
|
+
function bind(react) {
|
|
449
|
+
React = react;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// web-src/style.ts
|
|
453
|
+
var STYLE = `
|
|
454
|
+
.ta-bnd-picker { display: flex; flex-direction: column; gap: 12px; min-width: min(360px, 80vw); }
|
|
455
|
+
.ta-bnd-path { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ta-muted); font-family: var(--ta-mono); font-size: calc(12px * var(--ta-font-scale)); }
|
|
456
|
+
.ta-bnd-kinds { display: flex; flex-direction: column; margin: 0; padding: 0; border: none; }
|
|
457
|
+
.ta-bnd-kind { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 52px; padding: 6px 2px; border: none; border-bottom: 1px solid var(--ta-border-muted); background: none; color: var(--ta-text); font: inherit; text-align: left; cursor: pointer; }
|
|
458
|
+
.ta-bnd-kind:last-child { border-bottom: none; }
|
|
459
|
+
.ta-bnd-kind-main { display: flex; flex: 1; flex-direction: column; gap: 2px; min-width: 0; }
|
|
460
|
+
.ta-bnd-kind-title { display: flex; align-items: center; gap: 6px; font-weight: 500; }
|
|
461
|
+
.ta-bnd-kind-hint { color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
|
|
462
|
+
.ta-bnd-check { display: inline-flex; flex: none; align-items: center; justify-content: center; width: 18px; height: 18px; color: var(--ta-accent); }
|
|
463
|
+
.ta-bnd-name { display: flex; flex-direction: column; gap: 6px; }
|
|
464
|
+
.ta-bnd-name > span { color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
|
|
465
|
+
.ta-bnd-note { color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
|
|
466
|
+
.ta-bnd-foot { display: flex; justify-content: flex-end; }
|
|
467
|
+
.ta-bnd-tag { display: inline-flex; flex: none; align-items: center; gap: 2px; height: calc(16px * var(--ta-font-scale)); padding: 0 5px; border-radius: 4px; font-size: calc(10.5px * var(--ta-font-scale)); font-weight: 500; line-height: calc(16px * var(--ta-font-scale)); white-space: nowrap; }
|
|
468
|
+
.ta-bnd-tag[data-kind='work'] { background: color-mix(in oklab, var(--ta-blue) 13%, transparent); color: var(--ta-blue); }
|
|
469
|
+
.ta-bnd-tag[data-kind='private'] { background: color-mix(in oklab, var(--ta-muted) 14%, transparent); color: var(--ta-muted); }
|
|
470
|
+
.ta-bnd-list { display: flex; width: 100%; flex-direction: column; margin: 0; padding: 0; list-style: none; }
|
|
471
|
+
.ta-bnd-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; padding: 6px 0; border-bottom: 1px solid var(--ta-border-muted); }
|
|
472
|
+
.ta-bnd-list li:last-child { border-bottom: none; }
|
|
473
|
+
.ta-bnd-item { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
|
|
474
|
+
.ta-bnd-item-title { display: flex; align-items: center; gap: 6px; min-width: 0; }
|
|
475
|
+
.ta-bnd-item-title > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
476
|
+
`;
|
|
477
|
+
function injectStyle() {
|
|
478
|
+
const element = document.createElement("style");
|
|
479
|
+
element.dataset.taPackage = "ta-boundaries";
|
|
480
|
+
element.textContent = STYLE;
|
|
481
|
+
document.head.appendChild(element);
|
|
482
|
+
return () => element.remove();
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// web-src/index.tsx
|
|
486
|
+
class MarksStore {
|
|
487
|
+
pi;
|
|
488
|
+
marks = [];
|
|
489
|
+
fallback;
|
|
490
|
+
listeners = new Set;
|
|
491
|
+
constructor(pi) {
|
|
492
|
+
this.pi = pi;
|
|
493
|
+
this.read();
|
|
494
|
+
pi.storage.onChange((keys) => (keys.includes(Keys.MARKS) || keys.includes(Keys.FALLBACK)) && void this.read());
|
|
495
|
+
}
|
|
496
|
+
subscribe = (listener) => {
|
|
497
|
+
this.listeners.add(listener);
|
|
498
|
+
return () => this.listeners.delete(listener);
|
|
499
|
+
};
|
|
500
|
+
of(location) {
|
|
501
|
+
return BoundaryMarks.of(this.marks, this.fallback, location);
|
|
502
|
+
}
|
|
503
|
+
async read() {
|
|
504
|
+
const [marks, fallback] = await Promise.all([this.pi.storage.get(Keys.MARKS), this.pi.storage.get(Keys.FALLBACK)]).catch(() => [undefined, undefined]);
|
|
505
|
+
this.marks = BoundaryMarks.parse(marks);
|
|
506
|
+
this.fallback = BoundaryMarks.fallback(fallback);
|
|
507
|
+
for (const listener of this.listeners) {
|
|
508
|
+
listener();
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
function useMarks(store) {
|
|
513
|
+
const [, tick] = React.useReducer((n) => n + 1, 0);
|
|
514
|
+
React.useEffect(() => store.subscribe(tick), [store]);
|
|
515
|
+
return store;
|
|
516
|
+
}
|
|
517
|
+
var message = (error) => error instanceof Error ? error.message : String(error);
|
|
518
|
+
function kindWord(words, kind) {
|
|
519
|
+
return kind === "work" ? words.work : kind === "private" ? words.private : words.general;
|
|
520
|
+
}
|
|
521
|
+
function Tag({ pi, kind, name }) {
|
|
522
|
+
const words = BoundaryWords.of(pi.ui.language);
|
|
523
|
+
if (kind === "general") {
|
|
524
|
+
return null;
|
|
525
|
+
}
|
|
526
|
+
const Lock = pi.ui.icons.Lock;
|
|
527
|
+
return /* @__PURE__ */ React.createElement("span", {
|
|
528
|
+
className: "ta-bnd-tag",
|
|
529
|
+
"data-kind": kind
|
|
530
|
+
}, kind === "private" && /* @__PURE__ */ React.createElement(Lock, {
|
|
531
|
+
size: 9
|
|
532
|
+
}), name || kindWord(words, kind));
|
|
533
|
+
}
|
|
534
|
+
function Picker({ pi, store, location, close }) {
|
|
535
|
+
useMarks(store);
|
|
536
|
+
const words = BoundaryWords.of(pi.ui.language);
|
|
537
|
+
const own = BoundaryMarks.own(store.marks, location);
|
|
538
|
+
const now = store.of(location);
|
|
539
|
+
const inherited = !own && now.root && now.root !== BoundaryMarks.key(location) ? now.root : undefined;
|
|
540
|
+
const [name, setName] = React.useState(own?.name ?? "");
|
|
541
|
+
const [busy, run] = pi.ui.useBusy();
|
|
542
|
+
const Check = pi.ui.icons.Check;
|
|
543
|
+
const choose = (kind) => pi.callHost("mark", location, kind, kind === "general" ? "" : name).catch((error) => pi.ui.notify(BoundaryWords.format(words.failed, { message: message(error) }), "error"));
|
|
544
|
+
const saveName = () => {
|
|
545
|
+
if (now.kind !== "general" && !inherited && (own?.name ?? "") !== name.trim()) {
|
|
546
|
+
return choose(own?.kind ?? now.kind);
|
|
547
|
+
}
|
|
548
|
+
return Promise.resolve();
|
|
549
|
+
};
|
|
550
|
+
const kinds = ["general", "work", "private"];
|
|
551
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
552
|
+
className: "ta-bnd-picker"
|
|
553
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
554
|
+
className: "ta-bnd-path",
|
|
555
|
+
title: location
|
|
556
|
+
}, location), /* @__PURE__ */ React.createElement("fieldset", {
|
|
557
|
+
className: "ta-bnd-kinds",
|
|
558
|
+
"aria-label": words.title,
|
|
559
|
+
disabled: busy
|
|
560
|
+
}, kinds.map((kind) => {
|
|
561
|
+
const on = now.kind === kind;
|
|
562
|
+
return /* @__PURE__ */ React.createElement("button", {
|
|
563
|
+
key: kind,
|
|
564
|
+
type: "button",
|
|
565
|
+
className: "ta-bnd-kind",
|
|
566
|
+
"aria-pressed": on,
|
|
567
|
+
onClick: () => void run(() => choose(kind))
|
|
568
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
569
|
+
className: "ta-bnd-kind-main"
|
|
570
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
571
|
+
className: "ta-bnd-kind-title"
|
|
572
|
+
}, kindWord(words, kind), /* @__PURE__ */ React.createElement(Tag, {
|
|
573
|
+
pi,
|
|
574
|
+
kind
|
|
575
|
+
})), /* @__PURE__ */ React.createElement("span", {
|
|
576
|
+
className: "ta-bnd-kind-hint"
|
|
577
|
+
}, kind === "work" ? words.workHint : kind === "private" ? words.privateHint : store.fallback ? words.generalCloudHint : words.generalHint)), /* @__PURE__ */ React.createElement("span", {
|
|
578
|
+
className: "ta-bnd-check"
|
|
579
|
+
}, on && /* @__PURE__ */ React.createElement(Check, {
|
|
580
|
+
size: 16,
|
|
581
|
+
strokeWidth: 2.5
|
|
582
|
+
})));
|
|
583
|
+
})), now.kind !== "general" && !inherited && /* @__PURE__ */ React.createElement("label", {
|
|
584
|
+
className: "ta-bnd-name"
|
|
585
|
+
}, /* @__PURE__ */ React.createElement("span", null, words.nameLabel), /* @__PURE__ */ React.createElement("input", {
|
|
586
|
+
className: "ta-input",
|
|
587
|
+
value: name,
|
|
588
|
+
maxLength: NAME_MAX,
|
|
589
|
+
placeholder: words.namePlaceholder,
|
|
590
|
+
onChange: (event) => setName(event.target.value),
|
|
591
|
+
onKeyDown: (event) => event.key === "Enter" && void run(() => saveName().then(close))
|
|
592
|
+
})), /* @__PURE__ */ React.createElement("div", {
|
|
593
|
+
className: "ta-bnd-note"
|
|
594
|
+
}, inherited ? BoundaryWords.format(words.from, { dir: inherited }) : words.below), /* @__PURE__ */ React.createElement("div", {
|
|
595
|
+
className: "ta-bnd-foot"
|
|
596
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
597
|
+
type: "button",
|
|
598
|
+
className: "ta-button ta-primary",
|
|
599
|
+
onClick: () => void run(() => saveName().then(close))
|
|
600
|
+
}, words.done)));
|
|
601
|
+
}
|
|
602
|
+
function openPicker(pi, store, location) {
|
|
603
|
+
pi.ui.custom(({ close }) => /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
604
|
+
title: BoundaryWords.of(pi.ui.language).title,
|
|
605
|
+
onClose: close
|
|
606
|
+
}, /* @__PURE__ */ React.createElement(Picker, {
|
|
607
|
+
pi,
|
|
608
|
+
store,
|
|
609
|
+
location,
|
|
610
|
+
close
|
|
611
|
+
})));
|
|
612
|
+
}
|
|
613
|
+
function MarkRow({ pi, mark }) {
|
|
614
|
+
const words = BoundaryWords.of(pi.ui.language);
|
|
615
|
+
const [busy, run] = pi.ui.useBusy();
|
|
616
|
+
const remove = () => pi.callHost("unmark", mark.location).catch((error) => pi.ui.notify(BoundaryWords.format(words.failed, { message: message(error) }), "error"));
|
|
617
|
+
return /* @__PURE__ */ React.createElement("li", null, /* @__PURE__ */ React.createElement("span", {
|
|
618
|
+
className: "ta-bnd-item"
|
|
619
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
620
|
+
className: "ta-bnd-item-title"
|
|
621
|
+
}, /* @__PURE__ */ React.createElement("span", null, TaLocation.basename(mark.location)), mark.kind === "general" ? /* @__PURE__ */ React.createElement("span", {
|
|
622
|
+
className: "ta-bnd-kind-hint"
|
|
623
|
+
}, words.general) : /* @__PURE__ */ React.createElement(Tag, {
|
|
624
|
+
pi,
|
|
625
|
+
kind: mark.kind,
|
|
626
|
+
name: mark.name
|
|
627
|
+
})), /* @__PURE__ */ React.createElement("span", {
|
|
628
|
+
className: "ta-bnd-path",
|
|
629
|
+
title: mark.location
|
|
630
|
+
}, mark.location)), /* @__PURE__ */ React.createElement("button", {
|
|
631
|
+
type: "button",
|
|
632
|
+
className: `ta-button${busy ? " ta-busy" : ""}`,
|
|
633
|
+
"aria-busy": busy || undefined,
|
|
634
|
+
disabled: busy,
|
|
635
|
+
onClick: () => void run(remove)
|
|
636
|
+
}, busy && /* @__PURE__ */ React.createElement("span", {
|
|
637
|
+
className: "ta-spinner ta-busy-mark"
|
|
638
|
+
}), /* @__PURE__ */ React.createElement("span", null, words.remove)));
|
|
639
|
+
}
|
|
640
|
+
function settings(pi, store) {
|
|
641
|
+
const words = () => BoundaryWords.of(pi.ui.language);
|
|
642
|
+
function Marks() {
|
|
643
|
+
useMarks(store);
|
|
644
|
+
const w = words();
|
|
645
|
+
if (!store.marks.length) {
|
|
646
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
647
|
+
compact: true,
|
|
648
|
+
title: w.emptyTitle,
|
|
649
|
+
hint: w.emptyHint
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
return /* @__PURE__ */ React.createElement("ul", {
|
|
653
|
+
className: "ta-bnd-list"
|
|
654
|
+
}, store.marks.map((mark) => /* @__PURE__ */ React.createElement(MarkRow, {
|
|
655
|
+
key: mark.location,
|
|
656
|
+
pi,
|
|
657
|
+
mark
|
|
658
|
+
})));
|
|
659
|
+
}
|
|
660
|
+
function Clear() {
|
|
661
|
+
useMarks(store);
|
|
662
|
+
const w = words();
|
|
663
|
+
const [busy, run] = pi.ui.useBusy();
|
|
664
|
+
const clear = async () => {
|
|
665
|
+
if (await pi.ui.confirm(BoundaryWords.format(w.clearTitle, { count: store.marks.length }), w.clearHint, { confirmLabel: w.clear, danger: true })) {
|
|
666
|
+
await pi.callHost("clear").catch((error) => pi.ui.notify(BoundaryWords.format(w.failed, { message: message(error) }), "error"));
|
|
667
|
+
}
|
|
668
|
+
};
|
|
669
|
+
return /* @__PURE__ */ React.createElement("button", {
|
|
670
|
+
type: "button",
|
|
671
|
+
className: `ta-button${busy ? " ta-busy" : ""}`,
|
|
672
|
+
"aria-busy": busy || undefined,
|
|
673
|
+
disabled: busy || !store.marks.length,
|
|
674
|
+
onClick: () => void run(clear)
|
|
675
|
+
}, busy && /* @__PURE__ */ React.createElement("span", {
|
|
676
|
+
className: "ta-spinner ta-busy-mark"
|
|
677
|
+
}), /* @__PURE__ */ React.createElement("span", null, w.clear));
|
|
678
|
+
}
|
|
679
|
+
function Cloud() {
|
|
680
|
+
useMarks(store);
|
|
681
|
+
return store.fallback ? /* @__PURE__ */ React.createElement(Tag, {
|
|
682
|
+
pi,
|
|
683
|
+
kind: "work"
|
|
684
|
+
}) : /* @__PURE__ */ React.createElement("span", {
|
|
685
|
+
className: "ta-bnd-kind-hint"
|
|
686
|
+
}, words().general);
|
|
687
|
+
}
|
|
688
|
+
return {
|
|
689
|
+
title: () => words().title,
|
|
690
|
+
icon: pi.ui.icons.FolderLock ?? pi.ui.icons.Lock,
|
|
691
|
+
group: "privacy",
|
|
692
|
+
rows: [
|
|
693
|
+
{ key: "marks", label: () => words().listLabel, description: () => words().listHint, render: Marks, stacked: true },
|
|
694
|
+
{ key: "cloud", label: () => words().cloudLabel, description: () => store.fallback ? words().cloudHint : words().generalHint, render: Cloud },
|
|
695
|
+
{ key: "clear", label: "", render: Clear }
|
|
696
|
+
]
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
function activate(pi) {
|
|
700
|
+
bind(pi.React);
|
|
701
|
+
const removeStyle = injectStyle();
|
|
702
|
+
const store = new MarksStore(pi);
|
|
703
|
+
pi.registerChatTag?.({
|
|
704
|
+
tag: (chat) => {
|
|
705
|
+
const boundary = store.of(chat.cwd);
|
|
706
|
+
if (boundary.kind !== "work" && boundary.kind !== "private") {
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
const words = BoundaryWords.of(pi.ui.language);
|
|
710
|
+
const kind = kindWord(words, boundary.kind);
|
|
711
|
+
return {
|
|
712
|
+
text: boundary.name || kind,
|
|
713
|
+
tone: boundary.kind === "work" ? "blue" : "gray",
|
|
714
|
+
title: BoundaryWords.format(words.tagTitle, { dir: boundary.root ?? chat.cwd, kind })
|
|
715
|
+
};
|
|
716
|
+
},
|
|
717
|
+
subscribe: store.subscribe
|
|
718
|
+
});
|
|
719
|
+
pi.registerSessionMenu((session) => session.cwd ? [
|
|
720
|
+
{
|
|
721
|
+
key: "ta-boundaries",
|
|
722
|
+
label: BoundaryWords.of(pi.ui.language).menu,
|
|
723
|
+
icon: pi.ui.icons.FolderLock ?? pi.ui.icons.Lock,
|
|
724
|
+
run: () => openPicker(pi, store, session.cwd)
|
|
725
|
+
}
|
|
726
|
+
] : []);
|
|
727
|
+
pi.registerSettings(settings(pi, store));
|
|
728
|
+
return removeStyle;
|
|
729
|
+
}
|
|
730
|
+
export {
|
|
731
|
+
activate as default
|
|
732
|
+
};
|