odant-work 1.0.103 → 1.0.105

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.
Files changed (72) hide show
  1. package/$server/$folder/$class/$ai/handlers/pages/form/system/ai/$handler/class.js +15 -12
  2. package/$server/$folder/$class/$module/$mcp/handlers/pages/form/system/mcp/$handler/class.js +17 -24
  3. package/$server/$folder/$class/$module/$provider/handlers/pages/form/system/ai/$handler/class.js +15 -12
  4. package/$server/$folder/$class/$structure/$project/class.js +39 -5
  5. package/$server/$folder/$class/$structure/$project/handlers/pages/form/system/modules/$handler/class.js +40 -25
  6. package/$server/$folder/$class/$structure/$project/handlers/pages/form/system/requisites/$handler/class.js +1 -0
  7. package/$server/$folder/$class/$structure/$server/handlers/pages/form/system/license/$handler/class.js +13 -12
  8. package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/agent/$handler/class.js +11 -1
  9. package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/messengers/$handler/class.js +11 -1
  10. package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/profile/$handler/class.js +1 -0
  11. package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/requisites/$handler/class.js +3 -0
  12. package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/settings/$handler/class.js +261 -0
  13. package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/skills/$handler/class.js +11 -1
  14. package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/tokens/$handler/class.js +2 -0
  15. package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/users/$handler/class.js +1 -0
  16. package/$server/$folder/$class/$structure/class.js +15 -0
  17. package/$server/$folder/$class/$structure/handlers/pages/form/chat/$handler/class.js +17 -4
  18. package/$server/$folder/$class/$structure/handlers/pages/form/system/agent/$handler/class.js +19 -40
  19. package/$server/$folder/$class/$structure/handlers/pages/form/system/database/$handler/class.js +1 -0
  20. package/$server/$folder/$class/$structure/handlers/pages/form/system/messengers/$handler/class.js +1 -0
  21. package/$server/$folder/$class/$structure/handlers/pages/form/system/skills/$handler/class.js +276 -179
  22. package/$server/$folder/$class/$structure/handlers/pages/form/system/staff/$handler/class.js +1 -0
  23. package/$server/$folder/$class/ai/system.md +2 -2
  24. package/$server/$folder/$class/class.js +5 -1
  25. package/$server/$folder/$class/handlers/pages/form/system/requisites/$handler/class.js +39 -45
  26. package/$server/$folder/$file/$html/handlers/preview/$handler/preview.js +7 -0
  27. package/$server/$folder/$file/$image/handlers/preview/$handler/preview.js +11 -0
  28. package/$server/$folder/$file/$md/handlers/preview/$handler/preview.js +29 -8
  29. package/$server/$folder/$file/$office/handlers/preview/$handler/preview.js +6 -0
  30. package/$server/$folder/$file/$task/handlers/pages/form/file/$handler/class.js +34 -2
  31. package/$server/$folder/$file/$task/handlers/pages/form/file/$handler/ui/feed.js +14 -11
  32. package/$server/$folder/$file/$task/handlers/preview/$handler/preview.js +1 -0
  33. package/$server/$folder/$file/$txt/handlers/preview/$handler/preview.js +9 -0
  34. package/$server/$folder/$file/$video/handlers/preview/$handler/preview.js +15 -0
  35. package/$server/$folder/handlers/pages/form/$handler/class.js +187 -3
  36. package/$server/$folder/handlers/pages/form/folder/$handler/class.js +3 -114
  37. package/$server/$folder/lib/explorer/explorer.js +63 -0
  38. package/$server/$folder/lib/folder-browser/folder-browser.js +793 -0
  39. package/$server/$folder/lib/folder-browser/readme.md +5 -0
  40. package/$server/$folder/lib/tree/tree.js +61 -20
  41. package/AGENTS.md +2 -2
  42. package/MODULES/$domain/handlers/pages/form/system/mcp/$handler/class.js +10 -21
  43. package/MODULES//320/234/320/276/320/264/320/265/320/273/320/270/Local/$provider/handlers/pages/form/system/engine/$handler/class.js +1 -0
  44. package/MODULES//320/234/320/276/320/264/320/265/320/273/320/270/Local/$provider/handlers/pages/form/system/models/$handler/class.js +5 -10
  45. package/MODULES//320/234/320/276/320/264/320/265/320/273/320/270/Local/$provider/handlers/pages/form/system/training/$handler/class.js +1 -0
  46. package/MODULES//320/243/321/207/321/221/321/202 /320/270 /320/277/321/200/320/276/321/206/320/265/321/201/321/201/321/213/Register/OPERATIONS//320/240/320/265/320/260/320/273/320/270/320/267/320/260/321/206/320/270/321/217//320/237/320/276/320/272/321/203/320/277/320/260/321/202/320/265/320/273/321/216/$operation/print//320/241/321/207/321/221/321/202 /320/275/320/260 /320/276/320/277/320/273/320/260/321/202/321/203.html" +5 -1
  47. package/MODULES//320/243/321/207/321/221/321/202 /320/270 /320/277/321/200/320/276/321/206/320/265/321/201/321/201/321/213/Register/OPERATIONS//320/240/320/265/320/260/320/273/320/270/320/267/320/260/321/206/320/270/321/217//320/237/320/276/320/272/321/203/320/277/320/260/321/202/320/265/320/273/321/216/$operation/print//320/242/320/276/320/262/320/260/321/200/320/275/320/260/321/217 /320/275/320/260/320/272/320/273/320/260/320/264/320/275/320/260/321/217.html" +1 -1
  48. package/NODES/$node/handlers/pages/form/network/$handler/class.js +552 -36
  49. package/oda/components/icon/icon.js +20 -7
  50. package/oda/components/layouts/editor-form/editor-form.js +54 -9
  51. package/package.json +1 -1
  52. package/sources/client.js +24 -0
  53. package/sources/data/print.js +27 -3
  54. package/sources/host/websocket.js +28 -1
  55. package/sources/modules/agent/index.js +25 -6
  56. package/sources/modules/agent/permissions.js +4 -2
  57. package/sources/modules/agent/scope.js +72 -5
  58. package/sources/modules/agent/session.js +59 -6
  59. package/sources/modules/agent/tools/work/classes.js +16 -1
  60. package/sources/modules/license/index.js +120 -0
  61. package/sources/modules/nodes/registry.js +57 -7
  62. package/sources/modules/trainer/local-engine.js +22 -9
  63. package/sources/modules/user-profile/user-profile.js +0 -129
  64. package/sources/modules/user-profile/user-tokens.js +381 -86
  65. package/sources/server/access/gateway.js +32 -5
  66. package/sources/server/class/base-template.js +18 -18
  67. package/sources/server/class.js +9 -0
  68. package/sources/server/folder.js +5 -1
  69. package/sources/server/handler.js +6 -0
  70. package/sources/server/node.js +16 -0
  71. package/sources/server/server.js +14 -5
  72. package/sources/server/user.js +3 -0
@@ -0,0 +1,793 @@
1
+ const TEXT_PREVIEW_EXTS = new Set([
2
+ 'js', 'mjs', 'cjs', 'ts', 'tsx', 'jsx', 'json', 'json5',
3
+ 'css', 'scss', 'less', 'xml', 'yml', 'yaml', 'toml', 'ini',
4
+ 'conf', 'env', 'sh', 'bash', 'ps1', 'cmd', 'bat', 'py', 'rb',
5
+ 'go', 'rs', 'java', 'c', 'cpp', 'h', 'hpp', 'sql', 'log',
6
+ 'csv', 'tsv', 'txt', 'md', 'gitignore', 'editorconfig', 'npmrc', 'lock',
7
+ ]);
8
+ const TEXT_PREVIEW_NAMES = new Set(['dockerfile', 'makefile', 'license', 'readme', 'changelog']);
9
+ const MAX_TEXT_PREVIEW_CHARS = 512 * 1024;
10
+
11
+ export const FOLDER_BROWSER_COMPONENT = {
12
+ imports: '~/lib//tree.js, oda//splitter, oda//button, oda//icon',
13
+ template: /* html */`
14
+ <style>
15
+ :host {
16
+ @apply --vertical;
17
+ overflow: hidden;
18
+ @apply --content;
19
+ min-height: 0;
20
+ min-width: 0;
21
+ }
22
+ .folder-bar {
23
+ @apply --horizontal;
24
+ align-items: center;
25
+ gap: 10px;
26
+ padding: 6px 10px;
27
+ flex-shrink: 0;
28
+ box-sizing: border-box;
29
+ }
30
+ .search-wrap {
31
+ @apply --horizontal;
32
+ align-items: center;
33
+ gap: 4px;
34
+ flex: 1;
35
+ min-width: 0;
36
+ max-width: 560px;
37
+ background: color-mix(in oklch, var(--content-background) 94%, transparent);
38
+ color: var(--content-color);
39
+ border-radius: 6px;
40
+ padding: 2px 8px;
41
+ border: 1px solid color-mix(in oklch, var(--content-color) 18%, transparent);
42
+ }
43
+ .search-wrap:focus-within {
44
+ background: var(--content-background);
45
+ box-shadow: 0 0 0 2px color-mix(in oklch, var(--accent-back, #fff) 35%, transparent);
46
+ }
47
+ .search-input {
48
+ flex: 1;
49
+ min-width: 0;
50
+ border: none;
51
+ outline: none;
52
+ background: transparent;
53
+ color: var(--content-color);
54
+ font: inherit;
55
+ font-size: 13px;
56
+ padding: 3px 2px;
57
+ }
58
+ .search-action {
59
+ cursor: pointer;
60
+ opacity: 0.72;
61
+ color: var(--content-color);
62
+ flex-shrink: 0;
63
+ }
64
+ .search-action:hover {
65
+ opacity: 1;
66
+ }
67
+ .sys-toggle {
68
+ @apply --horizontal;
69
+ align-items: center;
70
+ gap: 6px;
71
+ font-size: 12.5px;
72
+ color: inherit;
73
+ cursor: pointer;
74
+ user-select: none;
75
+ white-space: nowrap;
76
+ flex-shrink: 0;
77
+ margin-left: auto;
78
+ }
79
+ .sys-toggle input {
80
+ margin: 0;
81
+ cursor: pointer;
82
+ accent-color: var(--content-background);
83
+ }
84
+ .bar-actions {
85
+ @apply --horizontal;
86
+ align-items: center;
87
+ gap: 6px;
88
+ margin-left: auto;
89
+ flex-shrink: 0;
90
+ }
91
+ .folder-body {
92
+ @apply --horizontal;
93
+ flex: 1;
94
+ min-height: 0;
95
+ min-width: 0;
96
+ overflow: hidden;
97
+ }
98
+ .tree-pane {
99
+ @apply --vertical;
100
+ flex: 1;
101
+ min-width: 220px;
102
+ min-height: 0;
103
+ overflow: hidden;
104
+ }
105
+ oda-splitter {
106
+ background: var(--subtle-border, var(--border-color));
107
+ flex-shrink: 0;
108
+ }
109
+ .preview-pane {
110
+ @apply --vertical;
111
+ flex-shrink: 0;
112
+ min-width: 240px;
113
+ min-height: 0;
114
+ overflow: hidden;
115
+ background: var(--content-background);
116
+ color: var(--content-color);
117
+ }
118
+ .preview-head {
119
+ @apply --horizontal;
120
+ align-items: center;
121
+ gap: 8px;
122
+ padding: 6px 10px;
123
+ border-bottom: 1px solid var(--subtle-border, var(--border-color));
124
+ background: var(--subtle-background, var(--content-background));
125
+ flex-shrink: 0;
126
+ min-width: 0;
127
+ }
128
+ .preview-title-wrap {
129
+ @apply --vertical;
130
+ min-width: 0;
131
+ overflow: hidden;
132
+ }
133
+ .preview-title {
134
+ font-size: 13px;
135
+ font-weight: 600;
136
+ white-space: nowrap;
137
+ overflow: hidden;
138
+ text-overflow: ellipsis;
139
+ }
140
+ .preview-sub {
141
+ font-size: 11px;
142
+ color: var(--muted-color);
143
+ white-space: nowrap;
144
+ overflow: hidden;
145
+ text-overflow: ellipsis;
146
+ }
147
+ .preview-size {
148
+ font-size: 11.5px;
149
+ color: var(--muted-color);
150
+ white-space: nowrap;
151
+ flex-shrink: 0;
152
+ }
153
+ .preview-head oda-button {
154
+ flex-shrink: 0;
155
+ border-radius: 6px;
156
+ padding: 3px 8px;
157
+ font-size: 12px;
158
+ border: 1px solid var(--subtle-border, var(--border-color));
159
+ }
160
+ .preview-stage {
161
+ @apply --vertical;
162
+ flex: 1;
163
+ min-height: 0;
164
+ min-width: 0;
165
+ overflow: hidden;
166
+ position: relative;
167
+ }
168
+ .preview-comp-wrap {
169
+ @apply --vertical;
170
+ flex: 1;
171
+ min-height: 0;
172
+ min-width: 0;
173
+ overflow: auto;
174
+ }
175
+ .preview-code {
176
+ margin: 0;
177
+ padding: 12px 14px;
178
+ flex: 1;
179
+ min-height: 0;
180
+ overflow: auto;
181
+ font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
182
+ font-size: 12.5px;
183
+ line-height: 1.5;
184
+ tab-size: 4;
185
+ white-space: pre;
186
+ user-select: text;
187
+ background: var(--content-background);
188
+ color: var(--content-color);
189
+ }
190
+ .preview-trunc {
191
+ padding: 6px 12px;
192
+ font-size: 12px;
193
+ color: var(--muted-color);
194
+ background: var(--subtle-background);
195
+ border-bottom: 1px solid var(--subtle-border, var(--border-color));
196
+ flex-shrink: 0;
197
+ }
198
+ .preview-pdf {
199
+ flex: 1;
200
+ width: 100%;
201
+ height: 100%;
202
+ border: none;
203
+ min-height: 0;
204
+ background: #fff;
205
+ }
206
+ .preview-empty {
207
+ @apply --vertical;
208
+ align-items: center;
209
+ justify-content: center;
210
+ text-align: center;
211
+ gap: 8px;
212
+ flex: 1;
213
+ padding: 24px;
214
+ min-height: 0;
215
+ overflow: auto;
216
+ }
217
+ .empty-title {
218
+ font-size: 14px;
219
+ font-weight: 600;
220
+ word-break: break-word;
221
+ }
222
+ .empty-sub {
223
+ font-size: 12.5px;
224
+ color: var(--muted-color);
225
+ }
226
+ .empty-hint {
227
+ font-size: 12.5px;
228
+ color: var(--muted-color);
229
+ max-width: 360px;
230
+ line-height: 1.45;
231
+ }
232
+ @media (max-width: 560px) {
233
+ .folder-bar {
234
+ flex-wrap: wrap;
235
+ gap: 6px;
236
+ }
237
+ .search-wrap {
238
+ max-width: none;
239
+ }
240
+ .folder-body {
241
+ flex-direction: column;
242
+ }
243
+ .tree-pane {
244
+ min-width: 0;
245
+ min-height: 140px;
246
+ }
247
+ .preview-pane {
248
+ width: 100% !important;
249
+ max-width: 100% !important;
250
+ min-width: 0;
251
+ height: 55%;
252
+ border-top: 1px solid var(--subtle-border, var(--border-color));
253
+ }
254
+ }
255
+ </style>
256
+ <div class="folder-bar" accent-invert>
257
+ <div class="search-wrap">
258
+ <input class="search-input" type="search"
259
+ :placeholder="searchPlaceholderText"
260
+ :value="searchFilter"
261
+ @input="onSearchInput($event)"
262
+ @keydown="onSearchKey($event)">
263
+ <oda-icon ~if="searchFilter" icon="icons:close" :icon-size="15" class="search-action" title="Сбросить фильтр" @tap="clearSearch()"></oda-icon>
264
+ <oda-icon ~if="allowGlobalSearch" icon="icons:search" :icon-size="17" class="search-action" title="Глобальный поиск (Enter)" @tap="runGlobalSearch()"></oda-icon>
265
+ </div>
266
+ <label ~if="!hideSystemToggle && isBoss" class="sys-toggle">
267
+ <input type="checkbox" :checked="showSystem" @change="onShowSystemChange($event)">
268
+ <span>Показать системные</span>
269
+ </label>
270
+ <div class="bar-actions" ~if="barActions?.length">
271
+ <oda-button ~for="barActions"
272
+ :icon="$for.item.icon || ''"
273
+ :icon-size="15"
274
+ :label="$for.item.label || ''"
275
+ :title="$for.item.title || $for.item.label || ''"
276
+ @tap="onBarAction($for.item)"></oda-button>
277
+ </div>
278
+ </div>
279
+ <div class="folder-body">
280
+ <div class="tree-pane">
281
+ <item-tree id="folderTree" flex
282
+ :$item="storage"
283
+ :filter="searchFilter"
284
+ :hide-system="!effectiveShowSystem"
285
+ :restore-state="false"
286
+ :auto-run="false"
287
+ show-size
288
+ allow-focus
289
+ :show-tools="showTreeTools"
290
+ menu-mode="both"
291
+ items-selector="entries"
292
+ hide-tops="1"
293
+ hide-roots="1"
294
+ :execute="openEntry"
295
+ @focused-item-changed="onTreeFocusChanged($event)">
296
+ </item-tree>
297
+ </div>
298
+ <oda-splitter ~if="showPreviewPane && !isMobile" left ::width="previewWidth" :min="240" :size="4"></oda-splitter>
299
+ <div ~if="showPreviewPane" class="preview-pane" :style="previewPaneStyle">
300
+ <div class="preview-head" ~if="previewTarget">
301
+ <oda-icon :icon="previewTarget.icon || (isPreviewFile ? 'files:document' : 'fontawesome:r-folder')" :icon-size="18"></oda-icon>
302
+ <div class="preview-title-wrap" flex>
303
+ <div class="preview-title" :title="previewTitle">{{previewTitle}}</div>
304
+ <div class="preview-sub" ~if="previewRelPath" :title="previewRelPath">{{previewRelPath}}</div>
305
+ </div>
306
+ <span class="preview-size" ~if="previewSizeText">{{previewSizeText}}</span>
307
+ <oda-button ~if="canOpenPreviewTarget" icon="icons:open-in-new" :icon-size="15" label="Открыть" title="Открыть в отдельной вкладке" @tap="openPreviewTarget()"></oda-button>
308
+ <oda-button ~if="isPreviewFile" icon="icons:file-download" :icon-size="15" label="Скачать" title="Скачать файл" @tap="downloadPreviewTarget()"></oda-button>
309
+ <oda-button ~if="isMobile" icon="icons:close" :icon-size="16" title="Закрыть предпросмотр" @tap="closeMobilePreview()"></oda-button>
310
+ </div>
311
+ <div class="preview-stage">
312
+ <div ~if="!previewTarget" class="preview-empty">
313
+ <oda-icon icon="fontawesome:r-folder-open" :icon-size="40" style="opacity: 0.35;"></oda-icon>
314
+ <div class="empty-title">{{storageTitle}}</div>
315
+ <div class="empty-hint">{{effectiveEmptyHint}}</div>
316
+ </div>
317
+ <div ~if="previewTarget && !isPreviewFile" class="preview-empty">
318
+ <oda-icon :icon="previewTarget.icon || 'fontawesome:r-folder'" :icon-size="40" style="opacity: 0.45;"></oda-icon>
319
+ <div class="empty-title">{{previewTitle}}</div>
320
+ <div class="empty-sub" ~if="previewSizeText">Размер: {{previewSizeText}}</div>
321
+ <div class="empty-hint">Это папка. Выберите файл внутри для предпросмотра или откройте двойным кликом.</div>
322
+ </div>
323
+ <div ~if="isPreviewFile && previewMode === 'loading'" class="preview-empty">
324
+ <oda-icon icon="spinners:8-dots-rotate" :icon-size="28"></oda-icon>
325
+ <div class="empty-hint">Загрузка предпросмотра…</div>
326
+ </div>
327
+ <div ~if="isPreviewFile && previewMode === 'component' && previewTag" class="preview-comp-wrap">
328
+ <div ~is="previewTag" full-height flex :$item="previewTarget"></div>
329
+ </div>
330
+ <div ~if="isPreviewFile && previewMode === 'text' && previewTruncated" class="preview-trunc">
331
+ Показаны первые 512 КБ файла. Нажмите «Открыть» или «Скачать» для полного просмотра.
332
+ </div>
333
+ <pre ~if="isPreviewFile && previewMode === 'text'" class="preview-code">{{previewText}}</pre>
334
+ <iframe ~if="isPreviewFile && previewMode === 'pdf'" class="preview-pdf" :src="previewPdfUrl"></iframe>
335
+ <div ~if="isPreviewFile && previewMode === 'error'" class="preview-empty">
336
+ <oda-icon icon="icons:warning" :icon-size="32" style="color: var(--error-color);"></oda-icon>
337
+ <div class="empty-title">Не удалось загрузить предпросмотр</div>
338
+ <div class="empty-hint">{{previewError}}</div>
339
+ </div>
340
+ <div ~if="isPreviewFile && previewMode === 'binary'" class="preview-empty">
341
+ <oda-icon :icon="previewTarget.icon || 'files:document'" :icon-size="40" style="opacity: 0.45;"></oda-icon>
342
+ <div class="empty-title">{{previewTitle}}</div>
343
+ <div class="empty-sub" ~if="previewExt">Формат: .{{previewExt}}<span ~if="previewSizeText"> · {{previewSizeText}}</span></div>
344
+ <div class="empty-hint">Предпросмотр для этого типа файлов недоступен. Используйте кнопки «Открыть» или «Скачать» выше.</div>
345
+ </div>
346
+ </div>
347
+ </div>
348
+ </div>
349
+ `,
350
+ showSystem: false,
351
+ hideSystemToggle: false,
352
+ defaultHideSystem: true,
353
+ allowGlobalSearch: true,
354
+ showTreeTools: true,
355
+ barActions: [],
356
+ emptyHintText: '',
357
+ rootTitle: '',
358
+ rootFolder: {
359
+ $def: null,
360
+ set() {
361
+ this.focusedItem = null;
362
+ this._clearPreview();
363
+ this.invalidate?.('storage');
364
+ },
365
+ },
366
+ searchFilter: '',
367
+ _isBoss: false,
368
+ focusedItem: null,
369
+ previewWidth: {
370
+ $def: 480,
371
+ $save: true,
372
+ },
373
+ previewMode: 'empty',
374
+ previewTag: '',
375
+ previewText: '',
376
+ previewTruncated: false,
377
+ previewPdfUrl: '',
378
+ previewError: '',
379
+ previewSizeText: '',
380
+ $item: {
381
+ $def: null,
382
+ set(n) {
383
+ this.focusedItem = null;
384
+ this._clearPreview();
385
+ this._syncIsBoss(n);
386
+ },
387
+ },
388
+ attached() {
389
+ if (this.$item)
390
+ this._syncIsBoss(this.$item);
391
+ },
392
+ _syncIsBoss(it = this.$item) {
393
+ if (!it) {
394
+ this._isBoss = false;
395
+ return;
396
+ }
397
+ if (WORK?.DEV_MODE) {
398
+ this._isBoss = true;
399
+ return;
400
+ }
401
+ const seq = (this._bossSeq = (this._bossSeq || 0) + 1);
402
+ Promise.resolve(it.isBoss)
403
+ .then(v => {
404
+ if (seq === this._bossSeq)
405
+ this._isBoss = Boolean(v);
406
+ })
407
+ .catch(() => {
408
+ if (seq === this._bossSeq)
409
+ this._isBoss = false;
410
+ });
411
+ },
412
+ get isBoss() {
413
+ return Boolean(this._isBoss);
414
+ },
415
+ get effectiveShowSystem() {
416
+ if (!this.defaultHideSystem)
417
+ return true;
418
+ return Boolean(this._isBoss && this.showSystem);
419
+ },
420
+ get isMobile() {
421
+ const topW = typeof top !== 'undefined' ? top.innerWidth : (typeof window !== 'undefined' ? window.innerWidth : 1280);
422
+ const selfW = this.clientWidth || (typeof window !== 'undefined' ? window.innerWidth : 1280);
423
+ return Boolean((ODA.states?.mobileMode && topW <= 768) || selfW < 560);
424
+ },
425
+ get storage() {
426
+ return this.rootFolder || this.$item?.storage_folder;
427
+ },
428
+ get storageTitle() {
429
+ return this.rootTitle || this.$item?.DATA?.label || this.$item?.label || this.$item?.id || 'Файлы';
430
+ },
431
+ get searchPlaceholderText() {
432
+ return this.allowGlobalSearch ? 'Поиск в дереве (Enter — глобальный)…' : 'Поиск в дереве…';
433
+ },
434
+ get effectiveEmptyHint() {
435
+ return this.emptyHintText || 'Выберите файл в дереве слева для предпросмотра. Двойной клик или Enter открывает элемент в отдельной вкладке.';
436
+ },
437
+ get previewTarget() {
438
+ return this.focusedItem || null;
439
+ },
440
+ get isPreviewFile() {
441
+ const it = this.previewTarget;
442
+ if (!it)
443
+ return false;
444
+ return (typeof CORE !== 'undefined' && CORE.$file && it instanceof CORE.$file) || it.type === '$file';
445
+ },
446
+ get previewTitle() {
447
+ const it = this.previewTarget;
448
+ return it?.label || it?.DATA?.label || it?.id || '';
449
+ },
450
+ get previewExt() {
451
+ const it = this.previewTarget;
452
+ if (!it)
453
+ return '';
454
+ const id = String(it.id || it.path || '');
455
+ const idx = id.lastIndexOf('.');
456
+ return idx > -1 ? id.slice(idx + 1).toLowerCase() : '';
457
+ },
458
+ get previewRelPath() {
459
+ const it = this.previewTarget;
460
+ if (!it)
461
+ return '';
462
+ const full = String(it.path || it.short || '');
463
+ const root = String(this.storage?.path || '');
464
+ let rel = (root && full.startsWith(root + '/')) ? full.slice(root.length + 1) : full;
465
+ const raw = (typeof R !== 'undefined' && it?.[R]?.target) ? it[R].target : it;
466
+ const scope = (raw && Object.prototype.hasOwnProperty.call(raw, '_layerScope')) ? String(raw._layerScope || '') : '';
467
+ if (scope) {
468
+ const tag = it.isInherit ? `унаследован: ${scope}` : 'локальный слой';
469
+ rel = rel ? `${rel} (${tag})` : tag;
470
+ }
471
+ return rel;
472
+ },
473
+ get canOpenPreviewTarget() {
474
+ const it = this.previewTarget;
475
+ if (!it)
476
+ return false;
477
+ return this.isPreviewFile || it.type !== '$folder';
478
+ },
479
+ get showPreviewPane() {
480
+ if (this.isMobile)
481
+ return this.isPreviewFile;
482
+ return true;
483
+ },
484
+ get previewPaneStyle() {
485
+ if (this.isMobile)
486
+ return '';
487
+ const w = Math.max(240, Number(this.previewWidth) || 480);
488
+ return `width: ${w}px; max-width: 72%;`;
489
+ },
490
+ onSearchInput(e) {
491
+ this.searchFilter = e?.target?.value ?? '';
492
+ },
493
+ onSearchKey(e) {
494
+ if (e.key === 'Enter' && this.allowGlobalSearch) {
495
+ e.preventDefault();
496
+ e.stopPropagation();
497
+ this.runGlobalSearch();
498
+ }
499
+ else if (e.key === 'Escape' && this.searchFilter) {
500
+ e.preventDefault();
501
+ e.stopPropagation();
502
+ this.clearSearch();
503
+ }
504
+ },
505
+ clearSearch() {
506
+ this.searchFilter = '';
507
+ },
508
+ runGlobalSearch() {
509
+ if (this.allowGlobalSearch)
510
+ this.$('#folderTree')?.runGlobalSearch?.();
511
+ },
512
+ onBarAction(act) {
513
+ if (typeof act?.onClick === 'function')
514
+ act.onClick();
515
+ },
516
+ onShowSystemChange(e) {
517
+ const next = Boolean(e?.target?.checked);
518
+ if (next) {
519
+ const entries = this.storage?.[R]?.cache?.entries;
520
+ if (Array.isArray(entries)) {
521
+ for (const ent of entries) {
522
+ const id = String(ent?.id || '');
523
+ if (id.startsWith('$') || id.startsWith('#'))
524
+ ent.expanded = false;
525
+ }
526
+ }
527
+ }
528
+ this.showSystem = next;
529
+ if (!next && this.focusedItem) {
530
+ const id = String(this.focusedItem.id || '');
531
+ const p = String(this.focusedItem.path || '');
532
+ if (id.startsWith('$') || id.startsWith('#') || p.includes('/$') || p.includes('/#')) {
533
+ const tree = this.$('#folderTree');
534
+ if (tree)
535
+ tree.focusedItem = null;
536
+ this.focusedItem = null;
537
+ this._clearPreview();
538
+ }
539
+ }
540
+ },
541
+ onTreeFocusChanged(e) {
542
+ const next = (e?.detail && 'value' in e.detail) ? e.detail.value : this.$('#folderTree')?.focusedItem;
543
+ const item = next || null;
544
+ this.focusedItem = item;
545
+ this._syncPreview(item);
546
+ },
547
+ closeMobilePreview() {
548
+ const tree = this.$('#folderTree');
549
+ if (tree)
550
+ tree.focusedItem = null;
551
+ this.focusedItem = null;
552
+ this._clearPreview();
553
+ },
554
+ openPreviewTarget() {
555
+ if (this.previewTarget)
556
+ this.openEntry(this.previewTarget);
557
+ },
558
+ downloadPreviewTarget() {
559
+ this.previewTarget?.download?.();
560
+ },
561
+ _clearPreview() {
562
+ this._previewSeq = (this._previewSeq || 0) + 1;
563
+ this.previewMode = 'empty';
564
+ this.previewTag = '';
565
+ this.previewText = '';
566
+ this.previewTruncated = false;
567
+ this.previewPdfUrl = '';
568
+ this.previewError = '';
569
+ this.previewSizeText = '';
570
+ },
571
+ async _syncPreview(item) {
572
+ const seq = (this._previewSeq = (this._previewSeq || 0) + 1);
573
+ this.previewTag = '';
574
+ this.previewText = '';
575
+ this.previewTruncated = false;
576
+ this.previewPdfUrl = '';
577
+ this.previewError = '';
578
+ this.previewSizeText = '';
579
+ if (!item) {
580
+ this.previewMode = 'empty';
581
+ return;
582
+ }
583
+ if (item.size !== undefined) {
584
+ Promise.resolve(item.size).then(sz => {
585
+ if (seq === this._previewSeq && sz)
586
+ this.previewSizeText = String(sz);
587
+ }).catch(() => {});
588
+ }
589
+ const isFile = (typeof CORE !== 'undefined' && CORE.$file && item instanceof CORE.$file) || item.type === '$file';
590
+ if (!isFile) {
591
+ this.previewMode = 'folder';
592
+ return;
593
+ }
594
+ this.previewMode = 'loading';
595
+ try {
596
+ const hasPreview = typeof CORE?.$file?.loadPreview === 'function'
597
+ ? await CORE.$file.loadPreview(item)
598
+ : false;
599
+ if (seq !== this._previewSeq)
600
+ return;
601
+ if (hasPreview && item.ext) {
602
+ this.previewTag = item.ext + '-preview';
603
+ this.previewMode = 'component';
604
+ return;
605
+ }
606
+ const ext = this.previewExt;
607
+ if (ext === 'pdf' && item.url) {
608
+ this.previewPdfUrl = item.url;
609
+ this.previewMode = 'pdf';
610
+ return;
611
+ }
612
+ const nameLower = String(item.id || '').toLowerCase();
613
+ if ((TEXT_PREVIEW_EXTS.has(ext) || TEXT_PREVIEW_NAMES.has(nameLower)) && typeof item.load === 'function') {
614
+ const raw = await item.load();
615
+ if (seq !== this._previewSeq)
616
+ return;
617
+ let txt;
618
+ if (raw?.DATA instanceof Blob)
619
+ txt = await raw.DATA.text();
620
+ else if (raw instanceof Blob)
621
+ txt = await raw.text();
622
+ else if (raw && typeof raw === 'object')
623
+ txt = JSON.stringify(raw, null, 2);
624
+ else
625
+ txt = String(raw ?? '');
626
+ if (seq !== this._previewSeq)
627
+ return;
628
+ if (txt.length > MAX_TEXT_PREVIEW_CHARS) {
629
+ this.previewTruncated = true;
630
+ this.previewText = txt.slice(0, MAX_TEXT_PREVIEW_CHARS);
631
+ }
632
+ else {
633
+ this.previewText = txt;
634
+ }
635
+ this.previewMode = 'text';
636
+ return;
637
+ }
638
+ this.previewMode = 'binary';
639
+ }
640
+ catch (err) {
641
+ if (seq !== this._previewSeq)
642
+ return;
643
+ this.previewError = String(err?.message || err || 'Ошибка загрузки');
644
+ this.previewMode = 'error';
645
+ }
646
+ },
647
+ openEntry(item) {
648
+ if (!item)
649
+ return;
650
+ if (item.type === '$handler') {
651
+ item.execute?.();
652
+ return;
653
+ }
654
+ if (typeof window?.execute === 'function') {
655
+ window.execute(item);
656
+ return;
657
+ }
658
+ item.execute?.();
659
+ },
660
+ };
661
+
662
+ function wrapLayerEntry(realEntry, { parent, scope, isOwn }) {
663
+ if (!realEntry)
664
+ return null;
665
+ const isInherit = !isOwn;
666
+ const raw = realEntry?.[R]?.target || realEntry;
667
+ try {
668
+ if (raw.DATA && typeof raw.DATA === 'object')
669
+ raw.DATA.isInherit = isInherit;
670
+ Object.defineProperty(raw, '_layerScope', {
671
+ value: typeof scope === 'string' ? scope : String(scope || ''),
672
+ writable: true,
673
+ configurable: true,
674
+ enumerable: false,
675
+ });
676
+ }
677
+ catch { /* ignore */ }
678
+ return realEntry;
679
+ }
680
+
681
+ /**
682
+ * Собрать виртуальную объединённую папку из слоёв WORK (~) по убыванию силы (от базового к локальному).
683
+ * Папки с одинаковым id рекурсивно объединяются, файлы перекрываются более сильным слоем.
684
+ */
685
+ export function buildMergedLayerFolder(layerEntries = [], { id = 'ai', label = 'ai', path = '', parent = null, icon = 'fontawesome:r-folder' } = {}) {
686
+ const validLayers = (Array.isArray(layerEntries) ? layerEntries : []).filter(l => l?.item);
687
+ const hasOwn = validLayers.some(l => l.isOwn);
688
+ const strong = validLayers.at(-1);
689
+ const nodePath = path || strong?.item?.path || `/${id}`;
690
+ const node = {
691
+ id,
692
+ name: id,
693
+ label: label || id,
694
+ path: nodePath,
695
+ short: nodePath,
696
+ icon,
697
+ type: '$folder',
698
+ isInherit: !hasOwn,
699
+ expanded: false,
700
+ parent,
701
+ tools: [],
702
+ DATA: {
703
+ id,
704
+ label: label || id,
705
+ path: nodePath,
706
+ type: '$folder',
707
+ icon,
708
+ isInherit: !hasOwn,
709
+ },
710
+ _entriesCache: null,
711
+ _entriesPromise: null,
712
+ reset() {
713
+ this._entriesCache = null;
714
+ this._entriesPromise = null;
715
+ },
716
+ get entries() {
717
+ if (Array.isArray(this._entriesCache))
718
+ return this._entriesCache;
719
+ if (!this._entriesPromise) {
720
+ this._entriesPromise = (async () => {
721
+ const layerLists = await Promise.all(validLayers.map(async l => {
722
+ const list = await Promise.resolve(l.item?.entries).catch(() => []);
723
+ return { layer: l, list: Array.isArray(list) ? list : [] };
724
+ }));
725
+ const byId = new Map();
726
+ for (const { layer, list } of layerLists) {
727
+ for (const entry of list) {
728
+ if (!entry?.id || String(entry.id).startsWith('.') || String(entry.id).startsWith('$') || String(entry.id).startsWith('#'))
729
+ continue;
730
+ const isFile = (typeof CORE !== 'undefined' && CORE.$file && entry instanceof CORE.$file) || entry.type === '$file';
731
+ if (!byId.has(entry.id)) {
732
+ byId.set(entry.id, { isFile, layers: [] });
733
+ }
734
+ const rec = byId.get(entry.id);
735
+ if (isFile) {
736
+ rec.isFile = true;
737
+ rec.winner = { entry, layer };
738
+ }
739
+ else {
740
+ if (rec.isFile) {
741
+ rec.isFile = false;
742
+ rec.layers = [];
743
+ }
744
+ rec.layers.push({ item: entry, scope: layer.scope, isOwn: layer.isOwn });
745
+ }
746
+ }
747
+ }
748
+ const out = [];
749
+ for (const [entryId, rec] of byId.entries()) {
750
+ if (rec.isFile && rec.winner) {
751
+ out.push(wrapLayerEntry(rec.winner.entry, {
752
+ parent: node,
753
+ scope: rec.winner.layer.scope,
754
+ isOwn: rec.winner.layer.isOwn,
755
+ }));
756
+ }
757
+ else if (!rec.isFile && rec.layers.length) {
758
+ const topL = rec.layers.at(-1);
759
+ out.push(buildMergedLayerFolder(rec.layers, {
760
+ id: entryId,
761
+ label: topL?.item?.label || entryId,
762
+ path: `${nodePath}/${entryId}`,
763
+ parent: node,
764
+ icon: topL?.item?.icon || 'fontawesome:r-folder',
765
+ }));
766
+ }
767
+ }
768
+ out.sort((a, b) => {
769
+ const aFile = a.type === '$file' ? 1 : 0;
770
+ const bFile = b.type === '$file' ? 1 : 0;
771
+ if (aFile !== bFile)
772
+ return aFile - bFile;
773
+ return String(a.label || a.id).localeCompare(String(b.label || b.id), 'ru');
774
+ });
775
+ this._entriesCache = out;
776
+ this.DATA.hasItems = out.length > 0;
777
+ return out;
778
+ })();
779
+ }
780
+ return this._entriesPromise;
781
+ },
782
+ get items() {
783
+ return this.entries;
784
+ },
785
+ };
786
+ return node;
787
+ }
788
+
789
+ if (typeof ODA === 'function' && !customElements.get('work-folder-browser')) {
790
+ ODA(Object.defineProperties({
791
+ is: 'work-folder-browser',
792
+ }, Object.getOwnPropertyDescriptors(FOLDER_BROWSER_COMPONENT)));
793
+ }