dsh-linked-workspace 0.8.2 → 0.9.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/CHANGELOG.md +31 -0
- package/README.en.md +31 -0
- package/README.md +31 -0
- package/docs/API.md +7 -3
- package/docs/VERIFY.md +25 -0
- package/lib/client.js +625 -34
- package/lib/index.js +326 -18
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -1937,10 +1937,24 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
1937
1937
|
return scheme + ': URL';
|
|
1938
1938
|
}
|
|
1939
1939
|
|
|
1940
|
+
// Complete attribute policy for the document preview. Inline styles are dropped
|
|
1941
|
+
// as well: `position:fixed; inset:0; z-index:99999` can cover the whole Harness
|
|
1942
|
+
// window, which turns a preview into a clickjacking / phishing surface without
|
|
1943
|
+
// a single line of script.
|
|
1944
|
+
function attributeViolation(name, value, tagName) {
|
|
1945
|
+
if (String(name || '').toLowerCase() === 'style') return 'inline style';
|
|
1946
|
+
return urlAttributeViolation(name, value, tagName);
|
|
1947
|
+
}
|
|
1948
|
+
|
|
1940
1949
|
var TREE_TAB_TYPE = 'dsh-linked-workspace';
|
|
1941
1950
|
var REMOTE_TAB_TYPE = 'dsh-linked-workspace:remote';
|
|
1942
1951
|
// One tree page; a folder with 20k entries must not render 20k rows.
|
|
1943
1952
|
var TREE_PAGE_SIZE = 500;
|
|
1953
|
+
var TREE_PAGE_MAX = 5000;
|
|
1954
|
+
// Background tree refresh interval per directory. The app ticks every 4 s,
|
|
1955
|
+
// but a full remote listing on a huge folder is expensive; 15 s keeps the
|
|
1956
|
+
// tree fresh without hammering the SSH channel.
|
|
1957
|
+
var REFRESH_MIN_INTERVAL_MS = 15000;
|
|
1944
1958
|
var linkedLocalKeys = new Set();
|
|
1945
1959
|
var linkedWorkspaceKeys = new Set();
|
|
1946
1960
|
var hasRemoteDirectories = false;
|
|
@@ -2156,6 +2170,35 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
2156
2170
|
noEntries: '空目录',
|
|
2157
2171
|
loadMore: '加载更多(剩余 {{count}} 项)',
|
|
2158
2172
|
loadMoreShort: '加载更多',
|
|
2173
|
+
pickerTruncated: '目录项过多,仅显示前 {{count}} 项;可直接在输入框中输入路径',
|
|
2174
|
+
filterPlaceholder: '按名称过滤…',
|
|
2175
|
+
filterEmpty: '没有匹配当前过滤条件的条目',
|
|
2176
|
+
searchTruncated: '结果过多,仅显示前 200 条;请输入更精确的关键词',
|
|
2177
|
+
findPlaceholder: '查找…',
|
|
2178
|
+
replacePlaceholder: '替换为…',
|
|
2179
|
+
findCounter: '第 {{index}} / {{total}} 个',
|
|
2180
|
+
findNoMatch: '无匹配',
|
|
2181
|
+
findNext: '下一个',
|
|
2182
|
+
findPrev: '上一个',
|
|
2183
|
+
replaceOne: '替换',
|
|
2184
|
+
replaceAll: '全部替换',
|
|
2185
|
+
compareTitle: '本地与远端对比',
|
|
2186
|
+
compareOnlyLocal: '仅本地存在',
|
|
2187
|
+
compareOnlyRemote: '仅远端存在',
|
|
2188
|
+
compareChanged: '大小或时间不同',
|
|
2189
|
+
compareNone: '无',
|
|
2190
|
+
compareTruncated: '文件过多,对比结果已截断(最多 4000 个文件 / 12 层)',
|
|
2191
|
+
compareFailed: '对比失败',
|
|
2192
|
+
ctxCompare: '与本地对比…',
|
|
2193
|
+
ctxTerminalHere: '在此打开终端',
|
|
2194
|
+
ctxTransferSelected: '传输所选的 {{count}} 项',
|
|
2195
|
+
ctxDeleteSelected: '删除所选的 {{count}} 项',
|
|
2196
|
+
deleteManyTitle: '批量删除',
|
|
2197
|
+
deleteManyMessage: '确定删除所选的 {{count}} 个项目吗?此操作不可撤销。',
|
|
2198
|
+
dropNeedsDesktop: '当前浏览器无法读取被拖入文件的路径,请在 DSH 桌面窗口中拖拽',
|
|
2199
|
+
dropImported: '已导入 {{count}} 个文件',
|
|
2200
|
+
dropSkipped: '{{count}} 个文件被跳过(过大或不是普通文件)',
|
|
2201
|
+
dropDirUnsupported: '暂不支持把远程目录拖拽到本地,请使用右键「传输」',
|
|
2159
2202
|
sheetTruncated: '仅显示前 {{rows}} 行 × {{cols}} 列',
|
|
2160
2203
|
sheetMore: '工作表较多,仅显示前 20 个',
|
|
2161
2204
|
noCredential: '缺少凭据',
|
|
@@ -2489,6 +2532,35 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
2489
2532
|
noEntries: 'Empty directory',
|
|
2490
2533
|
loadMore: 'Load more ({{count}} left)',
|
|
2491
2534
|
loadMoreShort: 'Load more',
|
|
2535
|
+
pickerTruncated: 'Too many entries; only the first {{count}} are shown. Type a path directly.',
|
|
2536
|
+
filterPlaceholder: 'Filter by name…',
|
|
2537
|
+
filterEmpty: 'No entries match the current filter',
|
|
2538
|
+
searchTruncated: 'Too many results; showing the first 200. Narrow the query.',
|
|
2539
|
+
findPlaceholder: 'Find…',
|
|
2540
|
+
replacePlaceholder: 'Replace with…',
|
|
2541
|
+
findCounter: '{{index}} / {{total}}',
|
|
2542
|
+
findNoMatch: 'No match',
|
|
2543
|
+
findNext: 'Next match',
|
|
2544
|
+
findPrev: 'Previous match',
|
|
2545
|
+
replaceOne: 'Replace',
|
|
2546
|
+
replaceAll: 'Replace all',
|
|
2547
|
+
compareTitle: 'Local vs remote comparison',
|
|
2548
|
+
compareOnlyLocal: 'Local only',
|
|
2549
|
+
compareOnlyRemote: 'Remote only',
|
|
2550
|
+
compareChanged: 'Different size or time',
|
|
2551
|
+
compareNone: 'None',
|
|
2552
|
+
compareTruncated: 'Too many files; the comparison was truncated (4000 files / 12 levels).',
|
|
2553
|
+
compareFailed: 'Comparison failed',
|
|
2554
|
+
ctxCompare: 'Compare with local…',
|
|
2555
|
+
ctxTerminalHere: 'Open terminal here',
|
|
2556
|
+
ctxTransferSelected: 'Transfer selected ({{count}})',
|
|
2557
|
+
ctxDeleteSelected: 'Delete selected ({{count}})',
|
|
2558
|
+
deleteManyTitle: 'Delete multiple',
|
|
2559
|
+
deleteManyMessage: 'Delete the {{count}} selected items? This cannot be undone.',
|
|
2560
|
+
dropNeedsDesktop: 'This browser cannot read dropped file paths; drag files in the DSH desktop window',
|
|
2561
|
+
dropImported: 'Imported {{count}} file(s)',
|
|
2562
|
+
dropSkipped: '{{count}} file(s) skipped (too large or not a regular file)',
|
|
2563
|
+
dropDirUnsupported: 'Dropping a remote folder onto local is not supported yet; use Transfer instead',
|
|
2492
2564
|
sheetTruncated: 'Showing the first {{rows}} rows × {{cols}} columns',
|
|
2493
2565
|
sheetMore: 'Showing the first 20 worksheets only',
|
|
2494
2566
|
noCredential: 'No credentials',
|
|
@@ -2897,7 +2969,7 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
2897
2969
|
parsed.querySelectorAll('script,style,iframe,object,embed,link,meta,base,form').forEach(function (node) { node.remove(); });
|
|
2898
2970
|
parsed.querySelectorAll('*').forEach(function (element) {
|
|
2899
2971
|
Array.from(element.attributes).forEach(function (attribute) {
|
|
2900
|
-
if (
|
|
2972
|
+
if (attributeViolation(attribute.name, attribute.value, element.tagName)) {
|
|
2901
2973
|
element.removeAttribute(attribute.name);
|
|
2902
2974
|
}
|
|
2903
2975
|
});
|
|
@@ -3297,6 +3369,22 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
3297
3369
|
'.rw-load-more{width:100%;border:0;background:transparent;cursor:pointer;text-align:left;font:inherit;font-size:11.5px;color:var(--dsw-alias-brand-primary)}',
|
|
3298
3370
|
'.rw-load-more:hover{text-decoration:underline}',
|
|
3299
3371
|
'.rw-load-more:disabled{opacity:.6;cursor:default}',
|
|
3372
|
+
'.rw-filter-row{padding:4px 8px;border-bottom:1px solid var(--dsw-alias-border-l1)}',
|
|
3373
|
+
'.rw-filter-row .rw-input{width:100%}',
|
|
3374
|
+
'.rw-find-bar{display:flex;align-items:center;gap:6px;flex-wrap:wrap;padding:6px 10px;border-bottom:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-l1)}',
|
|
3375
|
+
'.rw-find-bar .rw-input{height:26px;font-size:11.5px;min-width:120px;flex:0 1 160px}',
|
|
3376
|
+
'.rw-find-counter{font-size:11px;color:var(--dsw-alias-label-tertiary);white-space:nowrap}',
|
|
3377
|
+
'.rw-compare-root{font-family:ui-monospace,Consolas,monospace;font-size:11px}',
|
|
3378
|
+
'.rw-compare-section{margin:0 0 8px}',
|
|
3379
|
+
'.rw-compare-title{font-size:11.5px;font-weight:600;padding:2px 0}',
|
|
3380
|
+
'.rw-compare-empty{font-size:11px;color:var(--dsw-alias-label-tertiary);padding-left:8px}',
|
|
3381
|
+
'.rw-compare-row{display:flex;width:100%;gap:8px;align-items:center;border:0;background:transparent;cursor:pointer;text-align:left;font:inherit;font-size:11px;padding:3px 6px;border-radius:4px}',
|
|
3382
|
+
'.rw-compare-row:hover{background:var(--dsw-alias-interactive-bg-hover)}',
|
|
3383
|
+
'.rw-compare-path{flex:1 1 auto;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
|
|
3384
|
+
'.rw-compare-size{flex:0 0 auto;color:var(--dsw-alias-label-tertiary)}',
|
|
3385
|
+
'.rw-dialog-note{font-size:11px;color:var(--dsw-alias-label-tertiary);padding:2px 0}',
|
|
3386
|
+
'.rw-dialog-error{color:var(--dsw-alias-state-error-primary)}',
|
|
3387
|
+
'.rw-row.is-drop-target{outline:1px dashed var(--dsw-alias-brand-primary);outline-offset:-1px}',
|
|
3300
3388
|
'.rw-doc-tab{padding:2px 8px;border:1px solid transparent;border-radius:5px;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:11.5px;cursor:pointer;white-space:nowrap}',
|
|
3301
3389
|
'.rw-doc-tab.is-on{background:var(--dsw-alias-bg-layer-2);border-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-primary)}',
|
|
3302
3390
|
'.rw-doc-grid{width:100%;border-collapse:collapse;font-size:11.5px}',
|
|
@@ -3718,7 +3806,7 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
3718
3806
|
var locale = props.locale;
|
|
3719
3807
|
var initialPath = props.initialPath || '';
|
|
3720
3808
|
var root = props.root || '';
|
|
3721
|
-
var state = useState({ loading: true, listing: null, error: '', input: initialPath, creating: false, folderName: '' });
|
|
3809
|
+
var state = useState({ loading: true, listing: null, error: '', input: initialPath, creating: false, folderName: '', filter: '' });
|
|
3722
3810
|
var local = state[0];
|
|
3723
3811
|
var setLocal = state[1];
|
|
3724
3812
|
|
|
@@ -3726,7 +3814,7 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
3726
3814
|
setLocal(function (previous) { return Object.assign({}, previous, { loading: true, error: '', input: path || previous.input }); });
|
|
3727
3815
|
apiCall('local.browse', path ? { path: path } : {}).then(function (result) {
|
|
3728
3816
|
setLocal(function (previous) {
|
|
3729
|
-
return Object.assign({}, previous, { loading: false, listing: result, error: '', input: result.path });
|
|
3817
|
+
return Object.assign({}, previous, { loading: false, listing: result, error: '', input: result.path, filter: '' });
|
|
3730
3818
|
});
|
|
3731
3819
|
}).catch(function (error) {
|
|
3732
3820
|
setLocal(function (previous) {
|
|
@@ -3764,6 +3852,14 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
3764
3852
|
|
|
3765
3853
|
var listing = local.listing;
|
|
3766
3854
|
var entries = listing ? listing.entries : [];
|
|
3855
|
+
// A folder with thousands of sub-folders must not build thousands of DOM
|
|
3856
|
+
// rows; the input box below still accepts any path.
|
|
3857
|
+
var PICKER_LIMIT = 500;
|
|
3858
|
+
var filterText = String(local.filter || '').trim().toLowerCase();
|
|
3859
|
+
var matchedEntries = filterText === '' ? entries : entries.filter(function (entry) {
|
|
3860
|
+
return String(entry.name || '').toLowerCase().indexOf(filterText) !== -1;
|
|
3861
|
+
});
|
|
3862
|
+
var shownEntries = matchedEntries.slice(0, PICKER_LIMIT);
|
|
3767
3863
|
var crumbs = useMemo(function () {
|
|
3768
3864
|
if (!listing || !listing.path) return [];
|
|
3769
3865
|
var path = listing.path;
|
|
@@ -3811,17 +3907,31 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
3811
3907
|
}, drive.name);
|
|
3812
3908
|
}))
|
|
3813
3909
|
: null,
|
|
3910
|
+
h('div', { className: 'rw-filter-row' },
|
|
3911
|
+
h('input', {
|
|
3912
|
+
className: 'rw-input', style: { height: 26, fontSize: 11.5 },
|
|
3913
|
+
value: local.filter,
|
|
3914
|
+
placeholder: t('filterPlaceholder'),
|
|
3915
|
+
'aria-label': t('filterPlaceholder'),
|
|
3916
|
+
spellCheck: false,
|
|
3917
|
+
onChange: function (event) { setLocal(function (previous) { return Object.assign({}, previous, { filter: event.currentTarget.value }); }); },
|
|
3918
|
+
})),
|
|
3814
3919
|
h('div', { className: 'rw-browser-list', role: 'list' },
|
|
3815
3920
|
local.error
|
|
3816
3921
|
? h('div', { className: 'rw-row-msg' }, IconAlert(12), local.error)
|
|
3817
3922
|
: entries.length === 0
|
|
3818
3923
|
? h('div', { className: 'rw-row-msg' }, t('emptyFolder'))
|
|
3819
|
-
:
|
|
3924
|
+
: matchedEntries.length === 0
|
|
3925
|
+
? h('div', { className: 'rw-row-msg' }, t('filterEmpty'))
|
|
3926
|
+
: shownEntries.map(function (entry) {
|
|
3820
3927
|
return h('button', {
|
|
3821
3928
|
key: entry.path, type: 'button', className: 'rw-browser-row', role: 'listitem',
|
|
3822
3929
|
onClick: function () { navigate(entry.path); },
|
|
3823
3930
|
}, h('span', { className: 'rw-dir-icon' }, IconFolder(13, false)), h('span', null, entry.name));
|
|
3824
|
-
})
|
|
3931
|
+
}),
|
|
3932
|
+
matchedEntries.length > PICKER_LIMIT
|
|
3933
|
+
? h('div', { className: 'rw-row-msg' }, t('pickerTruncated', { count: PICKER_LIMIT }))
|
|
3934
|
+
: null),
|
|
3825
3935
|
h('div', { className: 'rw-browser-actions', style: { padding: '8px', gap: 8 } },
|
|
3826
3936
|
h('div', { className: 'rw-inline', style: { minWidth: 0, flex: '1 1 auto' } },
|
|
3827
3937
|
h('input', {
|
|
@@ -3865,7 +3975,7 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
3865
3975
|
var t = props.t;
|
|
3866
3976
|
var locale = props.locale;
|
|
3867
3977
|
var hostId = props.hostId;
|
|
3868
|
-
var state = useState({ loading: true, listing: null, error: '', input: props.initialPath || '' });
|
|
3978
|
+
var state = useState({ loading: true, listing: null, error: '', input: props.initialPath || '', filter: '' });
|
|
3869
3979
|
var remote = state[0];
|
|
3870
3980
|
var setRemote = state[1];
|
|
3871
3981
|
|
|
@@ -3877,7 +3987,7 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
3877
3987
|
setRemote(function (previous) { return Object.assign({}, previous, { loading: true, error: '' }); });
|
|
3878
3988
|
apiCall('hosts.browse', { hostId: hostId, path: path || undefined }).then(function (result) {
|
|
3879
3989
|
setRemote(function (previous) {
|
|
3880
|
-
return Object.assign({}, previous, { loading: false, listing: result, error: '', input: result.path });
|
|
3990
|
+
return Object.assign({}, previous, { loading: false, listing: result, error: '', input: result.path, filter: '' });
|
|
3881
3991
|
});
|
|
3882
3992
|
}).catch(function (error) {
|
|
3883
3993
|
setRemote(function (previous) { return Object.assign({}, previous, { loading: false, error: messageOf(error, t, locale) }); });
|
|
@@ -3893,6 +4003,13 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
3893
4003
|
|
|
3894
4004
|
var listing = remote.listing;
|
|
3895
4005
|
var dirs = listing ? (listing.entries || []).filter(function (entry) { return entry.type === 'dir'; }) : [];
|
|
4006
|
+
var PICKER_LIMIT = 500;
|
|
4007
|
+
var filterText = String(remote.filter || '').trim().toLowerCase();
|
|
4008
|
+
var matchedDirs = filterText === '' ? dirs : dirs.filter(function (entry) {
|
|
4009
|
+
return String(entry.name || '').toLowerCase().indexOf(filterText) !== -1;
|
|
4010
|
+
});
|
|
4011
|
+
var shownDirs = matchedDirs.slice(0, PICKER_LIMIT);
|
|
4012
|
+
var pickerTruncated = matchedDirs.length > PICKER_LIMIT || Boolean(listing && listing.hasMore);
|
|
3896
4013
|
var crumbs = useMemo(function () {
|
|
3897
4014
|
if (!listing || !listing.path) return [];
|
|
3898
4015
|
var pieces = listing.path.split('/').filter(function (piece) { return piece !== ''; });
|
|
@@ -3919,17 +4036,31 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
3919
4036
|
h('button', { type: 'button', className: 'rw-crumb', title: crumb.path, onClick: function () { navigate(crumb.path); } }, crumb.label));
|
|
3920
4037
|
})),
|
|
3921
4038
|
remote.loading ? Spinner(13) : null),
|
|
4039
|
+
h('div', { className: 'rw-filter-row' },
|
|
4040
|
+
h('input', {
|
|
4041
|
+
className: 'rw-input', style: { height: 26, fontSize: 11.5 },
|
|
4042
|
+
value: remote.filter,
|
|
4043
|
+
placeholder: t('filterPlaceholder'),
|
|
4044
|
+
'aria-label': t('filterPlaceholder'),
|
|
4045
|
+
spellCheck: false,
|
|
4046
|
+
onChange: function (event) { setRemote(function (previous) { return Object.assign({}, previous, { filter: event.currentTarget.value }); }); },
|
|
4047
|
+
})),
|
|
3922
4048
|
h('div', { className: 'rw-browser-list', role: 'list' },
|
|
3923
4049
|
remote.error
|
|
3924
4050
|
? h('div', { className: 'rw-row-msg' }, IconAlert(12), remote.error)
|
|
3925
4051
|
: dirs.length === 0
|
|
3926
4052
|
? h('div', { className: 'rw-row-msg' }, t('noEntries'))
|
|
3927
|
-
:
|
|
4053
|
+
: matchedDirs.length === 0
|
|
4054
|
+
? h('div', { className: 'rw-row-msg' }, t('filterEmpty'))
|
|
4055
|
+
: shownDirs.map(function (entry) {
|
|
3928
4056
|
return h('button', {
|
|
3929
4057
|
key: entry.path, type: 'button', className: 'rw-browser-row', role: 'listitem',
|
|
3930
4058
|
onClick: function () { navigate(entry.path); },
|
|
3931
4059
|
}, h('span', { className: 'rw-dir-icon' }, IconFolder(13, false)), h('span', null, entry.name));
|
|
3932
|
-
})
|
|
4060
|
+
}),
|
|
4061
|
+
pickerTruncated
|
|
4062
|
+
? h('div', { className: 'rw-row-msg' }, t('pickerTruncated', { count: PICKER_LIMIT }))
|
|
4063
|
+
: null),
|
|
3933
4064
|
h('div', { className: 'rw-browser-actions', style: { padding: '8px' } },
|
|
3934
4065
|
h('span', { className: 'rw-hint rw-input-mono', title: remote.input || (listing && listing.path) || '' },
|
|
3935
4066
|
(listing && listing.path) || (remote.input !== '' ? remote.input : t('home'))),
|
|
@@ -4368,6 +4499,12 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
4368
4499
|
event.preventDefault();
|
|
4369
4500
|
saveFile(false);
|
|
4370
4501
|
}
|
|
4502
|
+
if (mod && (event.key === 'f' || event.key === 'F') && !event.shiftKey) {
|
|
4503
|
+
// Ctrl+F inside the editor opens the in-file find bar; the browser
|
|
4504
|
+
// find dialog cannot see textarea content anyway.
|
|
4505
|
+
event.preventDefault();
|
|
4506
|
+
openFind();
|
|
4507
|
+
}
|
|
4371
4508
|
}
|
|
4372
4509
|
window.addEventListener('keydown', onKey, true);
|
|
4373
4510
|
return function () { window.removeEventListener('keydown', onKey, true); };
|
|
@@ -4382,6 +4519,129 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
4382
4519
|
if (gutterRef.current) gutterRef.current.scrollTop = target.scrollTop;
|
|
4383
4520
|
}
|
|
4384
4521
|
|
|
4522
|
+
// ── in-file find / replace ──────────────────────────────────────────
|
|
4523
|
+
var findInputRef = useRef(null);
|
|
4524
|
+
var findState = useState({ open: false, query: '', replace: '', caseSensitive: false, index: 0 });
|
|
4525
|
+
var find = findState[0];
|
|
4526
|
+
var setFind = findState[1];
|
|
4527
|
+
var FIND_MATCH_LIMIT = 5000;
|
|
4528
|
+
var findResult = useMemo(function () {
|
|
4529
|
+
if (!find.open || find.query === '') return { list: [], truncated: false };
|
|
4530
|
+
var text = content;
|
|
4531
|
+
var needle = find.caseSensitive ? find.query : find.query.toLowerCase();
|
|
4532
|
+
var haystack = find.caseSensitive ? text : text.toLowerCase();
|
|
4533
|
+
var list = [];
|
|
4534
|
+
var from = 0;
|
|
4535
|
+
while (list.length < FIND_MATCH_LIMIT) {
|
|
4536
|
+
var at = haystack.indexOf(needle, from);
|
|
4537
|
+
if (at === -1) break;
|
|
4538
|
+
list.push(at);
|
|
4539
|
+
from = at + Math.max(needle.length, 1);
|
|
4540
|
+
}
|
|
4541
|
+
// The list is capped so a huge file cannot freeze the editor, but the
|
|
4542
|
+
// counter must not pretend the cap is the real number of matches.
|
|
4543
|
+
var truncated = list.length === FIND_MATCH_LIMIT && haystack.indexOf(needle, from) !== -1;
|
|
4544
|
+
return { list: list, truncated: truncated };
|
|
4545
|
+
}, [content, find.open, find.query, find.caseSensitive]);
|
|
4546
|
+
var findMatches = findResult.list;
|
|
4547
|
+
var findIndex = findMatches.length === 0 ? -1 : Math.min(Math.max(find.index, 0), findMatches.length - 1);
|
|
4548
|
+
|
|
4549
|
+
function focusMatch(index) {
|
|
4550
|
+
var target = textareaRef.current;
|
|
4551
|
+
var at = findMatches.length === 0 ? -1 : findMatches[Math.min(Math.max(index, 0), findMatches.length - 1)];
|
|
4552
|
+
if (!target || at < 0) return;
|
|
4553
|
+
target.focus();
|
|
4554
|
+
target.selectionStart = at;
|
|
4555
|
+
target.selectionEnd = at + find.query.length;
|
|
4556
|
+
// Re-focusing makes the textarea scroll the selection into view.
|
|
4557
|
+
target.blur();
|
|
4558
|
+
target.focus();
|
|
4559
|
+
}
|
|
4560
|
+
|
|
4561
|
+
function stepMatch(delta) {
|
|
4562
|
+
if (findMatches.length === 0) return;
|
|
4563
|
+
var next = (findIndex + delta + findMatches.length) % findMatches.length;
|
|
4564
|
+
setFind(function (previous) { return Object.assign({}, previous, { index: next }); });
|
|
4565
|
+
focusMatch(next);
|
|
4566
|
+
}
|
|
4567
|
+
|
|
4568
|
+
function openFind() {
|
|
4569
|
+
setFind(function (previous) { return Object.assign({}, previous, { open: true }); });
|
|
4570
|
+
requestAnimationFrame(function () {
|
|
4571
|
+
if (findInputRef.current) {
|
|
4572
|
+
findInputRef.current.focus();
|
|
4573
|
+
findInputRef.current.select();
|
|
4574
|
+
}
|
|
4575
|
+
});
|
|
4576
|
+
}
|
|
4577
|
+
|
|
4578
|
+
function closeFind() {
|
|
4579
|
+
setFind({ open: false, query: '', replace: '', caseSensitive: false, index: 0 });
|
|
4580
|
+
}
|
|
4581
|
+
|
|
4582
|
+
function replaceCurrent() {
|
|
4583
|
+
if (findMatches.length === 0 || !editable) return;
|
|
4584
|
+
var at = findMatches[findIndex];
|
|
4585
|
+
var next = content.slice(0, at) + find.replace + content.slice(at + find.query.length);
|
|
4586
|
+
setContent(next);
|
|
4587
|
+
setDirty(true);
|
|
4588
|
+
setSave({ saving: false, conflict: false, error: '', ok: false });
|
|
4589
|
+
setFind(function (previous) { return Object.assign({}, previous, { index: Math.min(previous.index, Math.max(findMatches.length - 1, 0)) }); });
|
|
4590
|
+
}
|
|
4591
|
+
|
|
4592
|
+
function replaceAll() {
|
|
4593
|
+
if (findMatches.length === 0 || !editable || find.query === '') return;
|
|
4594
|
+
var escaped = find.query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
4595
|
+
var pattern = new RegExp(escaped, find.caseSensitive ? 'g' : 'gi');
|
|
4596
|
+
var next = content.replace(pattern, function () { return find.replace; });
|
|
4597
|
+
setContent(next);
|
|
4598
|
+
setDirty(true);
|
|
4599
|
+
setSave({ saving: false, conflict: false, error: '', ok: false });
|
|
4600
|
+
setFind(function (previous) { return Object.assign({}, previous, { index: 0 }); });
|
|
4601
|
+
}
|
|
4602
|
+
|
|
4603
|
+
function renderFindBar() {
|
|
4604
|
+
if (!find.open) return null;
|
|
4605
|
+
var counterTotal = findResult.truncated ? String(findMatches.length) + '+' : findMatches.length;
|
|
4606
|
+
var counter = findMatches.length === 0 ? t('findNoMatch') : t('findCounter', { index: findIndex + 1, total: counterTotal });
|
|
4607
|
+
return h('div', { className: 'rw-find-bar', role: 'search' },
|
|
4608
|
+
h('input', {
|
|
4609
|
+
ref: findInputRef,
|
|
4610
|
+
className: 'rw-input',
|
|
4611
|
+
value: find.query,
|
|
4612
|
+
placeholder: t('findPlaceholder'),
|
|
4613
|
+
'aria-label': t('findPlaceholder'),
|
|
4614
|
+
spellCheck: false,
|
|
4615
|
+
onChange: function (event) {
|
|
4616
|
+
var value = event.currentTarget.value;
|
|
4617
|
+
setFind(function (previous) { return Object.assign({}, previous, { query: value, index: 0 }); });
|
|
4618
|
+
},
|
|
4619
|
+
onKeyDown: function (event) {
|
|
4620
|
+
if (event.key === 'Enter') { event.preventDefault(); stepMatch(event.shiftKey ? -1 : 1); }
|
|
4621
|
+
if (event.key === 'Escape') { event.preventDefault(); closeFind(); }
|
|
4622
|
+
},
|
|
4623
|
+
}),
|
|
4624
|
+
h('span', { className: 'rw-find-counter' }, counter),
|
|
4625
|
+
h('button', { type: 'button', className: 'rw-btn rw-btn-sm', title: t('findNext'), disabled: findMatches.length === 0, onClick: function () { stepMatch(1); } }, IconChevron(12)),
|
|
4626
|
+
h('button', { type: 'button', className: 'rw-btn rw-btn-sm', title: t('findPrev'), disabled: findMatches.length === 0, onClick: function () { stepMatch(-1); } }, h('span', { style: { display: 'inline-flex', transform: 'rotate(180deg)' } }, IconChevron(12))),
|
|
4627
|
+
h('input', {
|
|
4628
|
+
className: 'rw-input',
|
|
4629
|
+
value: find.replace,
|
|
4630
|
+
placeholder: t('replacePlaceholder'),
|
|
4631
|
+
'aria-label': t('replacePlaceholder'),
|
|
4632
|
+
spellCheck: false,
|
|
4633
|
+
disabled: !editable,
|
|
4634
|
+
onChange: function (event) {
|
|
4635
|
+
var value = event.currentTarget.value;
|
|
4636
|
+
setFind(function (previous) { return Object.assign({}, previous, { replace: value }); });
|
|
4637
|
+
},
|
|
4638
|
+
onKeyDown: function (event) { if (event.key === 'Enter') { event.preventDefault(); replaceCurrent(); } },
|
|
4639
|
+
}),
|
|
4640
|
+
h('button', { type: 'button', className: 'rw-btn rw-btn-sm', disabled: !editable || findMatches.length === 0, onClick: replaceCurrent }, t('replaceOne')),
|
|
4641
|
+
h('button', { type: 'button', className: 'rw-btn rw-btn-sm', disabled: !editable || findMatches.length === 0, onClick: replaceAll }, t('replaceAll')),
|
|
4642
|
+
h('button', { type: 'button', className: 'rw-icon-btn', title: t('close'), onClick: closeFind }, IconClose(12)));
|
|
4643
|
+
}
|
|
4644
|
+
|
|
4385
4645
|
var file = load.file;
|
|
4386
4646
|
var lineCount = useMemo(function () {
|
|
4387
4647
|
if (content.length > 200000) return null;
|
|
@@ -4544,6 +4804,7 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
4544
4804
|
return h('div', { className: 'rw-editor', style: containerStyle },
|
|
4545
4805
|
header,
|
|
4546
4806
|
banner ? h('div', { style: { padding: '8px 10px 0' } }, banner) : null,
|
|
4807
|
+
renderFindBar(),
|
|
4547
4808
|
body,
|
|
4548
4809
|
h('div', { className: 'rw-editor-status' },
|
|
4549
4810
|
h('span', { className: 'rw-status-chip' }, 'UTF-8'),
|
|
@@ -4613,10 +4874,20 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
4613
4874
|
var cache = cacheState[0];
|
|
4614
4875
|
var setCache = cacheState[1];
|
|
4615
4876
|
var pending = useRef(new Set());
|
|
4877
|
+
var lastRefreshAt = useRef(new Map());
|
|
4616
4878
|
|
|
4617
4879
|
useEffect(function () {
|
|
4618
4880
|
if (!props.refreshTick) return;
|
|
4619
|
-
|
|
4881
|
+
// A background refresh costs one full listing per expanded directory, so
|
|
4882
|
+
// it stays quiet while the tab is hidden and never runs more often than
|
|
4883
|
+
// REFRESH_MIN_INTERVAL_MS per directory.
|
|
4884
|
+
if (typeof document !== 'undefined' && document.hidden) return;
|
|
4885
|
+
var now = Date.now();
|
|
4886
|
+
Array.from(expanded).forEach(function (path) {
|
|
4887
|
+
var at = lastRefreshAt.current.get(path) || 0;
|
|
4888
|
+
if (now - at < REFRESH_MIN_INTERVAL_MS) return;
|
|
4889
|
+
load(path, true);
|
|
4890
|
+
});
|
|
4620
4891
|
}, [props.refreshTick]);
|
|
4621
4892
|
|
|
4622
4893
|
function toggle(path) {
|
|
@@ -4628,8 +4899,8 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
4628
4899
|
});
|
|
4629
4900
|
}
|
|
4630
4901
|
|
|
4631
|
-
function listRequest(path, offset) {
|
|
4632
|
-
var params = { path: path, limit: TREE_PAGE_SIZE, offset: offset };
|
|
4902
|
+
function listRequest(path, offset, limit) {
|
|
4903
|
+
var params = { path: path, limit: limit || TREE_PAGE_SIZE, offset: offset };
|
|
4633
4904
|
return props.kind === 'local'
|
|
4634
4905
|
? apiCall('local.list', params)
|
|
4635
4906
|
: apiCall('fs.list', Object.assign(params, scopeParams(props.scope)));
|
|
@@ -4644,23 +4915,44 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
4644
4915
|
function load(path, silent) {
|
|
4645
4916
|
if (pending.current.has(path)) return;
|
|
4646
4917
|
pending.current.add(path);
|
|
4918
|
+
lastRefreshAt.current.set(path, Date.now());
|
|
4919
|
+
var previousRecord = cache.entries.get(path) || {};
|
|
4920
|
+
// A silent refresh keeps as many rows as the user already loaded:
|
|
4921
|
+
// re-reading only the first page would drop everything past it.
|
|
4922
|
+
var keep = silent ? Math.max(Number(previousRecord.raw) || 0, TREE_PAGE_SIZE) : TREE_PAGE_SIZE;
|
|
4923
|
+
keep = Math.min(keep, TREE_PAGE_MAX);
|
|
4647
4924
|
setCache(function (previous) {
|
|
4648
4925
|
var entries = new Map(previous.entries);
|
|
4649
4926
|
var existing = entries.get(path) || {};
|
|
4650
|
-
entries.set(path, { loading: !silent, error: null, entries: existing.entries || [], loaded: existing.loaded });
|
|
4927
|
+
entries.set(path, { loading: !silent, error: null, entries: existing.entries || [], loaded: existing.loaded, raw: existing.raw, total: existing.total, hasMore: existing.hasMore });
|
|
4651
4928
|
return { entries: entries };
|
|
4652
4929
|
});
|
|
4653
|
-
listRequest(path, 0).then(function (result) {
|
|
4930
|
+
listRequest(path, 0, keep).then(function (result) {
|
|
4654
4931
|
pending.current.delete(path);
|
|
4655
4932
|
setCache(function (previous) {
|
|
4656
4933
|
var next = new Map(previous.entries);
|
|
4934
|
+
var existing = next.get(path) || {};
|
|
4935
|
+
var fresh = applyEntries(result.entries || []);
|
|
4936
|
+
var freshPaths = new Set(fresh.map(function (entry) { return entry.path; }));
|
|
4937
|
+
// Keep rows beyond the refreshed page so a silent refresh cannot
|
|
4938
|
+
// shrink a list the user scrolled many pages into.
|
|
4939
|
+
var retained = silent
|
|
4940
|
+
? (existing.entries || []).filter(function (entry) { return !freshPaths.has(entry.path); })
|
|
4941
|
+
: [];
|
|
4942
|
+
var pageRaw = (result.entries || []).length;
|
|
4943
|
+
var raw = silent ? Math.max(Number(existing.raw) || 0, pageRaw) : pageRaw;
|
|
4944
|
+
var total = Number(result.total) || pageRaw + retained.length;
|
|
4657
4945
|
next.set(path, {
|
|
4658
4946
|
loading: false,
|
|
4659
4947
|
error: null,
|
|
4660
4948
|
loaded: true,
|
|
4661
|
-
entries:
|
|
4662
|
-
|
|
4663
|
-
|
|
4949
|
+
entries: fresh.concat(retained),
|
|
4950
|
+
raw: raw,
|
|
4951
|
+
total: total,
|
|
4952
|
+
// A silent refresh asks for `keep` rows; when everything is already
|
|
4953
|
+
// loaded the server still reports hasMore for the page it did not
|
|
4954
|
+
// return, so trust the row counts instead of the flag alone.
|
|
4955
|
+
hasMore: Boolean(result.hasMore) && raw < total,
|
|
4664
4956
|
});
|
|
4665
4957
|
return { entries: next };
|
|
4666
4958
|
});
|
|
@@ -4682,13 +4974,18 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
4682
4974
|
function loadMore(path) {
|
|
4683
4975
|
var record = cache.entries.get(path);
|
|
4684
4976
|
if (!record || record.loadingMore || !record.hasMore) return;
|
|
4977
|
+
// Offset is the number of RAW entries already fetched, not the number of
|
|
4978
|
+
// visible rows: hidden entries are filtered out of the list but still
|
|
4979
|
+
// occupy positions in the server-side listing.
|
|
4980
|
+
var offset = Number(record.raw);
|
|
4981
|
+
if (!Number.isFinite(offset)) offset = (record.entries || []).length;
|
|
4685
4982
|
setCache(function (previous) {
|
|
4686
4983
|
var next = new Map(previous.entries);
|
|
4687
4984
|
var current = next.get(path);
|
|
4688
4985
|
if (current) next.set(path, Object.assign({}, current, { loadingMore: true }));
|
|
4689
4986
|
return { entries: next };
|
|
4690
4987
|
});
|
|
4691
|
-
listRequest(path,
|
|
4988
|
+
listRequest(path, offset).then(function (result) {
|
|
4692
4989
|
setCache(function (previous) {
|
|
4693
4990
|
var next = new Map(previous.entries);
|
|
4694
4991
|
var current = next.get(path) || { entries: [] };
|
|
@@ -4696,6 +4993,7 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
4696
4993
|
loadingMore: false,
|
|
4697
4994
|
loaded: true,
|
|
4698
4995
|
entries: current.entries.concat(applyEntries(result.entries || [])),
|
|
4996
|
+
raw: offset + (result.entries || []).length,
|
|
4699
4997
|
total: Number(result.total) || current.total,
|
|
4700
4998
|
hasMore: Boolean(result.hasMore),
|
|
4701
4999
|
}));
|
|
@@ -4711,7 +5009,19 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
4711
5009
|
});
|
|
4712
5010
|
}
|
|
4713
5011
|
|
|
4714
|
-
return h('div', {
|
|
5012
|
+
return h('div', {
|
|
5013
|
+
className: 'rw-tree',
|
|
5014
|
+
role: 'tree',
|
|
5015
|
+
'aria-label': t('allFiles'),
|
|
5016
|
+
onDragOver: function (event) {
|
|
5017
|
+
if (!props.onDropOnPath) return;
|
|
5018
|
+
event.preventDefault();
|
|
5019
|
+
try { event.dataTransfer.dropEffect = 'copy'; } catch (error) { /* ignore */ }
|
|
5020
|
+
},
|
|
5021
|
+
onDrop: function (event) {
|
|
5022
|
+
if (props.onDropOnPath) props.onDropOnPath(rootPath, event);
|
|
5023
|
+
},
|
|
5024
|
+
}, h(TreeDirectory, {
|
|
4715
5025
|
path: rootPath,
|
|
4716
5026
|
name: props.rootName || t('allFiles'),
|
|
4717
5027
|
depth: 0,
|
|
@@ -4727,7 +5037,14 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
4727
5037
|
onPin: props.onPin,
|
|
4728
5038
|
onSelectPath: props.onSelectPath,
|
|
4729
5039
|
onContextMenu: props.onContextMenu,
|
|
5040
|
+
onDragStart: props.onDragStartRow
|
|
5041
|
+
? function (event, info) { props.onDragStartRow(props.kind, event, info); }
|
|
5042
|
+
: null,
|
|
5043
|
+
onDropOnPath: props.onDropOnPath
|
|
5044
|
+
? function (path, event) { props.onDropOnPath(props.kind, path, event); }
|
|
5045
|
+
: null,
|
|
4730
5046
|
selectedPath: props.selectedPath || '',
|
|
5047
|
+
selectedSet: props.selectedPaths && props.selectedPaths.length > 0 ? new Set(props.selectedPaths) : null,
|
|
4731
5048
|
}));
|
|
4732
5049
|
}
|
|
4733
5050
|
|
|
@@ -4878,6 +5195,7 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
4878
5195
|
state.error ? h(Banner, { kind: 'error' }, state.error) : null,
|
|
4879
5196
|
state.loading ? h('div', { className: 'rw-hint-row' }, Spinner(12), t('loading')) : null,
|
|
4880
5197
|
!state.loading && total === 0 ? h('div', { className: 'rw-hint-row' }, t('searchEmpty')) : null,
|
|
5198
|
+
!state.loading && state.truncated ? h('div', { className: 'rw-hint-row' }, t('searchTruncated')) : null,
|
|
4881
5199
|
groups.map(function (group) {
|
|
4882
5200
|
if (group.entries.length === 0) return null;
|
|
4883
5201
|
return h('div', { key: group.side, className: 'rw-change-group' },
|
|
@@ -5114,6 +5432,37 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
5114
5432
|
h('button', { type: 'button', className: 'rw-btn rw-btn-sm', onClick: props.onClose }, props.t('close'))));
|
|
5115
5433
|
}
|
|
5116
5434
|
|
|
5435
|
+
function CompareDialog(props) {
|
|
5436
|
+
var t = props.t;
|
|
5437
|
+
var data = props.data;
|
|
5438
|
+
function section(key, title, rows, count, side) {
|
|
5439
|
+
return h('div', { key: key, className: 'rw-compare-section' },
|
|
5440
|
+
h('div', { className: 'rw-compare-title' }, title + ' (' + count + ')'),
|
|
5441
|
+
count === 0
|
|
5442
|
+
? h('div', { className: 'rw-compare-empty' }, t('compareNone'))
|
|
5443
|
+
: rows.map(function (row) {
|
|
5444
|
+
var size = row.size != null ? row.size : row.localSize;
|
|
5445
|
+
return h('button', {
|
|
5446
|
+
key: row.path,
|
|
5447
|
+
type: 'button',
|
|
5448
|
+
className: 'rw-compare-row',
|
|
5449
|
+
title: row.path,
|
|
5450
|
+
onClick: function () { props.onOpen(side, row.path); },
|
|
5451
|
+
},
|
|
5452
|
+
h('span', { className: 'rw-compare-path' }, row.path),
|
|
5453
|
+
h('span', { className: 'rw-compare-size' }, typeof size === 'number' ? formatBytes(size) : ''));
|
|
5454
|
+
}));
|
|
5455
|
+
}
|
|
5456
|
+
return h(DialogShell, { title: props.title, onClose: props.onClose },
|
|
5457
|
+
h('div', { className: 'rw-dialog-message rw-compare-root', title: data.localPath }, data.localPath),
|
|
5458
|
+
section('onlyLocal', t('compareOnlyLocal'), data.onlyLocal || [], data.counts.onlyLocal, 'local'),
|
|
5459
|
+
section('onlyRemote', t('compareOnlyRemote'), data.onlyRemote || [], data.counts.onlyRemote, 'remote'),
|
|
5460
|
+
section('changed', t('compareChanged'), data.changed || [], data.counts.changed, 'remote'),
|
|
5461
|
+
data.truncated ? h('div', { className: 'rw-dialog-note' }, t('compareTruncated')) : null,
|
|
5462
|
+
h('div', { className: 'rw-dialog-actions' },
|
|
5463
|
+
h('button', { type: 'button', className: 'rw-btn rw-btn-sm', onClick: props.onClose }, t('close'))));
|
|
5464
|
+
}
|
|
5465
|
+
|
|
5117
5466
|
function MoveDialog(props) {
|
|
5118
5467
|
var picker = props.side === 'local'
|
|
5119
5468
|
? h(LocalPathPicker, {
|
|
@@ -5505,6 +5854,9 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
5505
5854
|
var selectedEntryState = useState(null);
|
|
5506
5855
|
var selectedEntry = selectedEntryState[0];
|
|
5507
5856
|
var setSelectedEntry = selectedEntryState[1];
|
|
5857
|
+
var multiState = useState([]);
|
|
5858
|
+
var multi = multiState[0];
|
|
5859
|
+
var setMulti = multiState[1];
|
|
5508
5860
|
var showHiddenState = useState(true);
|
|
5509
5861
|
var showHidden = showHiddenState[0];
|
|
5510
5862
|
var setShowHidden = showHiddenState[1];
|
|
@@ -5605,6 +5957,20 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
5605
5957
|
var fileDirtyState = useState({});
|
|
5606
5958
|
var fileDirty = fileDirtyState[0];
|
|
5607
5959
|
var setFileDirty = fileDirtyState[1];
|
|
5960
|
+
|
|
5961
|
+
// Closing the browser tab or reloading the page would silently drop
|
|
5962
|
+
// unsaved edits: ask for confirmation while any open file is dirty.
|
|
5963
|
+
useEffect(function () {
|
|
5964
|
+
var dirty = openFiles.some(function (file) { return Boolean(fileDirty[file.key]); });
|
|
5965
|
+
if (!dirty) return undefined;
|
|
5966
|
+
function onBeforeUnload(event) {
|
|
5967
|
+
event.preventDefault();
|
|
5968
|
+
event.returnValue = '';
|
|
5969
|
+
return '';
|
|
5970
|
+
}
|
|
5971
|
+
window.addEventListener('beforeunload', onBeforeUnload);
|
|
5972
|
+
return function () { window.removeEventListener('beforeunload', onBeforeUnload); };
|
|
5973
|
+
}, [openFiles, fileDirty]);
|
|
5608
5974
|
var saveHandlersRef = useRef({});
|
|
5609
5975
|
var directoryTabId = props.tab && props.tab.id;
|
|
5610
5976
|
|
|
@@ -5679,6 +6045,19 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
5679
6045
|
data.reload();
|
|
5680
6046
|
}
|
|
5681
6047
|
|
|
6048
|
+
function openCompare(path) {
|
|
6049
|
+
if (!selected) return;
|
|
6050
|
+
setDialog({ kind: 'compare', loading: true, error: '', data: null });
|
|
6051
|
+
apiCall('fs.compare', Object.assign({ path: path }, scopeParams(scopeRef))).then(function (result) {
|
|
6052
|
+
setDialog({
|
|
6053
|
+
kind: 'compare', loading: false, error: '',
|
|
6054
|
+
data: result, root: result.path, localPath: result.localPath,
|
|
6055
|
+
});
|
|
6056
|
+
}).catch(function (error) {
|
|
6057
|
+
setDialog({ kind: 'compare', loading: false, error: t('compareFailed') + ':' + messageOf(error, t, locale), data: null });
|
|
6058
|
+
});
|
|
6059
|
+
}
|
|
6060
|
+
|
|
5682
6061
|
function updateOpenMode(next) {
|
|
5683
6062
|
apiCall('settings.update', { fileOpenMode: next }).then(function (result) {
|
|
5684
6063
|
runtimeSettings.apply({ fileOpenMode: result && result.fileOpenMode ? result.fileOpenMode : next });
|
|
@@ -5688,9 +6067,10 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
5688
6067
|
});
|
|
5689
6068
|
}
|
|
5690
6069
|
|
|
5691
|
-
function openTerminal(side) {
|
|
6070
|
+
function openTerminal(side, atPath) {
|
|
5692
6071
|
if (!selected) return;
|
|
5693
6072
|
var request = { side: side };
|
|
6073
|
+
if (typeof atPath === 'string' && atPath !== '') request.path = atPath;
|
|
5694
6074
|
if (selected.kind === 'linked') request.linkedId = selected.id;
|
|
5695
6075
|
else request.workspaceId = selected.id;
|
|
5696
6076
|
apiCall('terminal.open', request).then(function () {
|
|
@@ -5840,6 +6220,49 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
5840
6220
|
showNotice('error', t('actionFailed') + ':' + messageOf(error, t, locale));
|
|
5841
6221
|
}
|
|
5842
6222
|
|
|
6223
|
+
// Ctrl/Cmd-click toggles an entry in the multi-selection; a plain click
|
|
6224
|
+
// collapses the selection to that entry (Shift extends it).
|
|
6225
|
+
function updateSelection(side, info) {
|
|
6226
|
+
if (!info || typeof info.path !== 'string') return;
|
|
6227
|
+
var event = info.event;
|
|
6228
|
+
var entry = { side: side, path: info.path, name: info.name, isDir: Boolean(info.isDir) };
|
|
6229
|
+
setSelectedEntry(entry);
|
|
6230
|
+
var toggle = Boolean(event && (event.ctrlKey || event.metaKey));
|
|
6231
|
+
var extend = Boolean(event && event.shiftKey);
|
|
6232
|
+
setMulti(function (previous) {
|
|
6233
|
+
var exists = previous.some(function (item) { return item.side === side && item.path === entry.path; });
|
|
6234
|
+
if (extend) return exists ? previous : previous.concat([entry]);
|
|
6235
|
+
if (toggle) {
|
|
6236
|
+
return exists
|
|
6237
|
+
? previous.filter(function (item) { return !(item.side === side && item.path === entry.path); })
|
|
6238
|
+
: previous.concat([entry]);
|
|
6239
|
+
}
|
|
6240
|
+
return [entry];
|
|
6241
|
+
});
|
|
6242
|
+
}
|
|
6243
|
+
|
|
6244
|
+
function selectedOn(side) {
|
|
6245
|
+
return multi.filter(function (item) { return item.side === side; });
|
|
6246
|
+
}
|
|
6247
|
+
|
|
6248
|
+
function selectionFor(side) {
|
|
6249
|
+
var list = selectedOn(side);
|
|
6250
|
+
if (list.length > 0) return list;
|
|
6251
|
+
if (selectedEntry && selectedEntry.side === side) return [selectedEntry];
|
|
6252
|
+
return [];
|
|
6253
|
+
}
|
|
6254
|
+
|
|
6255
|
+
function transferSelection() {
|
|
6256
|
+
var list = multi.length > 0 ? multi : (selectedEntry ? [selectedEntry] : []);
|
|
6257
|
+
list.forEach(function (item) { enqueueTransfer(item.side, item.path, item.name); });
|
|
6258
|
+
}
|
|
6259
|
+
|
|
6260
|
+
function deleteSelection() {
|
|
6261
|
+
var list = multi.length > 0 ? multi : (selectedEntry ? [selectedEntry] : []);
|
|
6262
|
+
if (list.length === 0) return;
|
|
6263
|
+
setDialog({ kind: 'deleteMany', entries: list });
|
|
6264
|
+
}
|
|
6265
|
+
|
|
5843
6266
|
function copyPathToClipboard(text) {
|
|
5844
6267
|
try {
|
|
5845
6268
|
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
@@ -5949,6 +6372,94 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
5949
6372
|
}).catch(noticeError);
|
|
5950
6373
|
}
|
|
5951
6374
|
|
|
6375
|
+
function confirmDeleteMany(entries) {
|
|
6376
|
+
var list = Array.isArray(entries) ? entries : [];
|
|
6377
|
+
var failures = [];
|
|
6378
|
+
var chain = Promise.resolve();
|
|
6379
|
+
list.forEach(function (entry) {
|
|
6380
|
+
chain = chain.then(function () {
|
|
6381
|
+
var method = entry.side === 'remote' ? 'fs.delete' : 'local.delete';
|
|
6382
|
+
var params = entry.side === 'remote'
|
|
6383
|
+
? Object.assign({ path: entry.path }, scopeParams(scopeRef))
|
|
6384
|
+
: { path: entry.path, root: selected.localPath };
|
|
6385
|
+
return apiCall(method, params).then(function () {
|
|
6386
|
+
setMulti(function (previous) {
|
|
6387
|
+
return previous.filter(function (item) { return !(item.side === entry.side && item.path === entry.path); });
|
|
6388
|
+
});
|
|
6389
|
+
}).catch(function (error) { failures.push(error); });
|
|
6390
|
+
});
|
|
6391
|
+
});
|
|
6392
|
+
chain.then(function () {
|
|
6393
|
+
if (failures.length > 0) showNotice('error', messageOf(failures[0], t, locale));
|
|
6394
|
+
else showNotice('success', t('deleteDone'));
|
|
6395
|
+
refreshTree();
|
|
6396
|
+
});
|
|
6397
|
+
}
|
|
6398
|
+
|
|
6399
|
+
var DRAG_MIME = 'application/x-dsh-linked-entry';
|
|
6400
|
+
|
|
6401
|
+
function beginDragRow(side, event, info) {
|
|
6402
|
+
if (!event.dataTransfer || !info) return;
|
|
6403
|
+
try {
|
|
6404
|
+
event.dataTransfer.setData(DRAG_MIME, JSON.stringify({
|
|
6405
|
+
side: side, path: info.path, name: info.name, isDir: Boolean(info.isDir),
|
|
6406
|
+
}));
|
|
6407
|
+
event.dataTransfer.effectAllowed = 'copy';
|
|
6408
|
+
} catch (error) { /* drag payload unsupported */ }
|
|
6409
|
+
}
|
|
6410
|
+
|
|
6411
|
+
// Drop target handling for both trees: OS files are imported into the
|
|
6412
|
+
// target directory, while an entry dragged from the other tree is pushed
|
|
6413
|
+
// across the boundary (remote→local or local→remote).
|
|
6414
|
+
function dropOnPath(side, targetDir, event) {
|
|
6415
|
+
event.preventDefault();
|
|
6416
|
+
event.stopPropagation();
|
|
6417
|
+
var transfer = event.dataTransfer;
|
|
6418
|
+
if (!transfer || typeof targetDir !== 'string' || targetDir === '') return;
|
|
6419
|
+
var files = Array.prototype.slice.call(transfer.files || []);
|
|
6420
|
+
var osPaths = files.map(function (file) {
|
|
6421
|
+
return file && typeof file.path === 'string' ? file.path : '';
|
|
6422
|
+
}).filter(Boolean);
|
|
6423
|
+
if (files.length > 0 && osPaths.length === 0) {
|
|
6424
|
+
showNotice('error', t('dropNeedsDesktop'));
|
|
6425
|
+
return;
|
|
6426
|
+
}
|
|
6427
|
+
if (osPaths.length > 0) {
|
|
6428
|
+
var payload = side === 'remote'
|
|
6429
|
+
? Object.assign({ path: targetDir, paths: osPaths }, scopeParams(scopeRef))
|
|
6430
|
+
: { dir: targetDir, paths: osPaths };
|
|
6431
|
+
apiCall(side === 'remote' ? 'fs.upload' : 'local.import', payload).then(function (result) {
|
|
6432
|
+
var count = side === 'remote' ? Number(result.files) || 0 : Number(result.copied) || 0;
|
|
6433
|
+
showNotice('success', t('dropImported', { count: count }));
|
|
6434
|
+
if (Number(result.skipped) > 0) showNotice('warn', t('dropSkipped', { count: result.skipped }));
|
|
6435
|
+
refreshTree();
|
|
6436
|
+
}).catch(noticeError);
|
|
6437
|
+
return;
|
|
6438
|
+
}
|
|
6439
|
+
var raw = '';
|
|
6440
|
+
try { raw = transfer.getData(DRAG_MIME); } catch (error) { raw = ''; }
|
|
6441
|
+
if (!raw) return;
|
|
6442
|
+
var entry;
|
|
6443
|
+
try { entry = JSON.parse(raw); } catch (error) { return; }
|
|
6444
|
+
if (!entry || typeof entry.path !== 'string' || entry.side === side) return;
|
|
6445
|
+
if (entry.side === 'remote') {
|
|
6446
|
+
if (entry.isDir) {
|
|
6447
|
+
showNotice('error', t('dropDirUnsupported'));
|
|
6448
|
+
return;
|
|
6449
|
+
}
|
|
6450
|
+
apiCall('fs.pullToLocal', Object.assign({ path: entry.path, targetDir: targetDir }, scopeParams(scopeRef))).then(function () {
|
|
6451
|
+
showNotice('success', t('dropImported', { count: 1 }));
|
|
6452
|
+
refreshTree();
|
|
6453
|
+
}).catch(noticeError);
|
|
6454
|
+
return;
|
|
6455
|
+
}
|
|
6456
|
+
apiCall('fs.upload', Object.assign({ path: targetDir, paths: [entry.path] }, scopeParams(scopeRef))).then(function (result) {
|
|
6457
|
+
if (Number(result.skipped) > 0) showNotice('warn', t('dropSkipped', { count: result.skipped }));
|
|
6458
|
+
else showNotice('success', t('dropImported', { count: Number(result.files) || 1 }));
|
|
6459
|
+
refreshTree();
|
|
6460
|
+
}).catch(noticeError);
|
|
6461
|
+
}
|
|
6462
|
+
|
|
5952
6463
|
function submitRenamed(side, oldPath, name) {
|
|
5953
6464
|
var target = joinChildPath(parentPathOf(oldPath, side), name, side);
|
|
5954
6465
|
if (target === oldPath) return;
|
|
@@ -6054,6 +6565,14 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
6054
6565
|
}
|
|
6055
6566
|
var canPaste = clipboard !== null && clipboard.side === menu.side && menu.isDir;
|
|
6056
6567
|
var items = [];
|
|
6568
|
+
var batch = multi.filter(function (item) { return item.side === menu.side; });
|
|
6569
|
+
if (batch.length > 1) {
|
|
6570
|
+
items.push({ label: t('ctxTransferSelected', { count: batch.length }), onSelect: function () {
|
|
6571
|
+
batch.forEach(function (item) { enqueueTransfer(item.side, item.path, item.name); });
|
|
6572
|
+
} });
|
|
6573
|
+
items.push({ label: t('ctxDeleteSelected', { count: batch.length }), onSelect: deleteSelection });
|
|
6574
|
+
items.push({ separator: true });
|
|
6575
|
+
}
|
|
6057
6576
|
if (isRemote) {
|
|
6058
6577
|
items.push({ label: t('ctxTransfer'), onSelect: function () { enqueueTransfer('remote', menu.path, menu.name); } });
|
|
6059
6578
|
items.push({ label: t('ctxDownload'), onSelect: function () { downloadEntry(menu); } });
|
|
@@ -6097,8 +6616,12 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
6097
6616
|
} });
|
|
6098
6617
|
if (menu.isDir) {
|
|
6099
6618
|
items.push({ separator: true });
|
|
6619
|
+
items.push({ label: t('ctxTerminalHere'), onSelect: function () { openTerminal(menu.side, menu.path); } });
|
|
6100
6620
|
items = items.concat(newEntryMenuItems(menu, t, setDialog));
|
|
6101
6621
|
}
|
|
6622
|
+
if (menu.isDir && menu.side === 'remote' && selected && selected.kind === 'linked') {
|
|
6623
|
+
items.push({ label: t('ctxCompare'), onSelect: function () { openCompare(menu.path); } });
|
|
6624
|
+
}
|
|
6102
6625
|
items.push({ separator: true });
|
|
6103
6626
|
items.push({ label: t('ctxProperties'), onSelect: function () { showProperties(menu.side, menu.path); } });
|
|
6104
6627
|
return items;
|
|
@@ -6106,6 +6629,27 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
6106
6629
|
|
|
6107
6630
|
function renderDialog() {
|
|
6108
6631
|
if (!dialog) return null;
|
|
6632
|
+
if (dialog.kind === 'compare') {
|
|
6633
|
+
return dialog.loading
|
|
6634
|
+
? h(DialogShell, { title: t('compareTitle'), onClose: function () { setDialog(null); } },
|
|
6635
|
+
h('div', { className: 'rw-dialog-message' }, Spinner(13), t('loading')))
|
|
6636
|
+
: dialog.error
|
|
6637
|
+
? h(DialogShell, { title: t('compareTitle'), onClose: function () { setDialog(null); } },
|
|
6638
|
+
h('div', { className: 'rw-dialog-message rw-dialog-error' }, dialog.error),
|
|
6639
|
+
h('div', { className: 'rw-dialog-actions' },
|
|
6640
|
+
h('button', { type: 'button', className: 'rw-btn rw-btn-sm', onClick: function () { setDialog(null); } }, t('close'))))
|
|
6641
|
+
: h(CompareDialog, {
|
|
6642
|
+
t: t,
|
|
6643
|
+
title: t('compareTitle'),
|
|
6644
|
+
data: dialog.data,
|
|
6645
|
+
onClose: function () { setDialog(null); },
|
|
6646
|
+
onOpen: function (side, relative) {
|
|
6647
|
+
var root = dialog.root;
|
|
6648
|
+
var target = side === 'local' ? dialog.localPath : root;
|
|
6649
|
+
openInternalFile(side === 'local' ? 'local' : 'remote', target + (target.endsWith('/') || target.endsWith('\\') ? '' : side === 'local' ? '\\' : '/') + relative.split('/').join(side === 'local' ? '\\' : '/'));
|
|
6650
|
+
},
|
|
6651
|
+
});
|
|
6652
|
+
}
|
|
6109
6653
|
if (dialog.kind === 'props') {
|
|
6110
6654
|
return h(PropertiesDialog, { t: t, title: dialog.title, rows: dialog.rows, onClose: function () { setDialog(null); } });
|
|
6111
6655
|
}
|
|
@@ -6131,6 +6675,16 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
6131
6675
|
onConfirm: function () { setDialog(null); confirmDelete(dialog); },
|
|
6132
6676
|
});
|
|
6133
6677
|
}
|
|
6678
|
+
if (dialog.kind === 'deleteMany') {
|
|
6679
|
+
return h(ConfirmDialog, {
|
|
6680
|
+
t: t,
|
|
6681
|
+
title: t('deleteManyTitle'),
|
|
6682
|
+
message: t('deleteManyMessage', { count: dialog.entries.length }),
|
|
6683
|
+
confirmLabel: t('deleteConfirm'),
|
|
6684
|
+
onClose: function () { setDialog(null); },
|
|
6685
|
+
onConfirm: function () { setDialog(null); confirmDeleteMany(dialog.entries); },
|
|
6686
|
+
});
|
|
6687
|
+
}
|
|
6134
6688
|
if (dialog.kind === 'move') {
|
|
6135
6689
|
return h(MoveDialog, {
|
|
6136
6690
|
t: t, locale: locale,
|
|
@@ -6202,7 +6756,7 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
6202
6756
|
}
|
|
6203
6757
|
var alive = true;
|
|
6204
6758
|
var timer = setTimeout(function () {
|
|
6205
|
-
setSearch(function (previous) { return { loading: true, remote: previous.remote, local: previous.local, error: null }; });
|
|
6759
|
+
setSearch(function (previous) { return { loading: true, remote: previous.remote, local: previous.local, truncated: false, error: null }; });
|
|
6206
6760
|
var scopeNow = sourceScopeOf(selected);
|
|
6207
6761
|
var jobs = [apiCall('fs.search', Object.assign({ side: 'remote', query: query, maxResults: 200 }, scopeParams(scopeNow))).catch(function (error) {
|
|
6208
6762
|
return { ok: false, entries: [], error: messageOf(error, t, locale) };
|
|
@@ -6220,6 +6774,7 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
6220
6774
|
loading: false,
|
|
6221
6775
|
remote: results[0] && results[0].entries ? results[0].entries : [],
|
|
6222
6776
|
local: results[1] && results[1].entries ? results[1].entries : [],
|
|
6777
|
+
truncated: Boolean((results[0] && results[0].truncated) || (results[1] && results[1].truncated)),
|
|
6223
6778
|
error: (results[0] && results[0].error) || (results[1] && results[1].error) || null,
|
|
6224
6779
|
});
|
|
6225
6780
|
});
|
|
@@ -6269,7 +6824,10 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
6269
6824
|
locale: locale,
|
|
6270
6825
|
showHidden: showHidden,
|
|
6271
6826
|
selectedPath: selectedEntry && selectedEntry.side === 'remote' ? selectedEntry.path : '',
|
|
6272
|
-
|
|
6827
|
+
selectedPaths: selectionFor('remote').map(function (item) { return item.path; }),
|
|
6828
|
+
onSelectPath: function (info) { updateSelection('remote', info); },
|
|
6829
|
+
onDragStartRow: beginDragRow,
|
|
6830
|
+
onDropOnPath: dropOnPath,
|
|
6273
6831
|
onSelect: function (filePath) { openByMode('remote', filePath, { pinned: false, preview: true }); },
|
|
6274
6832
|
onPin: function (filePath) { pinByMode('remote', filePath); },
|
|
6275
6833
|
onContextMenu: function (info) { setSelectedEntry(Object.assign({ side: 'remote' }, info)); openContextMenu('remote', info); },
|
|
@@ -6290,7 +6848,10 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
6290
6848
|
locale: locale,
|
|
6291
6849
|
showHidden: showHidden,
|
|
6292
6850
|
selectedPath: selectedEntry && selectedEntry.side === 'local' ? selectedEntry.path : '',
|
|
6293
|
-
|
|
6851
|
+
selectedPaths: selectionFor('local').map(function (item) { return item.path; }),
|
|
6852
|
+
onSelectPath: function (info) { updateSelection('local', info); },
|
|
6853
|
+
onDragStartRow: beginDragRow,
|
|
6854
|
+
onDropOnPath: dropOnPath,
|
|
6294
6855
|
onSelect: function (filePath) { openByMode('local', filePath, { pinned: false, preview: true }); },
|
|
6295
6856
|
onPin: function (filePath) { pinByMode('local', filePath); },
|
|
6296
6857
|
refreshTick: localTick,
|
|
@@ -6374,13 +6935,13 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
6374
6935
|
localEnabled: !remoteOnly && selected.kind === 'linked',
|
|
6375
6936
|
showHidden: showHidden,
|
|
6376
6937
|
onToggleHidden: function () { setShowHidden(!showHidden); },
|
|
6377
|
-
transferEnabled: !remoteOnly && Boolean(selectedEntry),
|
|
6938
|
+
transferEnabled: !remoteOnly && (multi.length > 0 || Boolean(selectedEntry)),
|
|
6378
6939
|
transferSelected: function () {
|
|
6379
|
-
if (!selectedEntry) {
|
|
6940
|
+
if (multi.length === 0 && !selectedEntry) {
|
|
6380
6941
|
showNotice('info', t('selectFirst'));
|
|
6381
6942
|
return;
|
|
6382
6943
|
}
|
|
6383
|
-
|
|
6944
|
+
transferSelection();
|
|
6384
6945
|
},
|
|
6385
6946
|
onMode: function (next) { setMode(next); },
|
|
6386
6947
|
onToggleSearch: function () { setSearchOpen(!searchOpen); },
|
|
@@ -6533,10 +7094,13 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
6533
7094
|
onPin: onPin,
|
|
6534
7095
|
onSelectPath: onSelectPath,
|
|
6535
7096
|
onContextMenu: onContextMenu,
|
|
7097
|
+
onDragStart: props.onDragStart,
|
|
7098
|
+
onDropOnPath: props.onDropOnPath,
|
|
6536
7099
|
selectedPath: selectedPath,
|
|
7100
|
+
selectedSet: props.selectedSet,
|
|
6537
7101
|
}));
|
|
6538
7102
|
} else if (child.type === 'file' || child.type === 'symlink') {
|
|
6539
|
-
var active = selectedPath === child.path;
|
|
7103
|
+
var active = selectedPath === child.path || Boolean(props.selectedSet && props.selectedSet.has(child.path));
|
|
6540
7104
|
children.push(h('button', {
|
|
6541
7105
|
key: child.path,
|
|
6542
7106
|
type: 'button',
|
|
@@ -6546,8 +7110,12 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
6546
7110
|
className: 'rw-row' + (active ? ' is-active' : ''),
|
|
6547
7111
|
style: { paddingLeft: 6 + (depth + 1) * 12 },
|
|
6548
7112
|
title: child.path,
|
|
7113
|
+
draggable: Boolean(props.onDragStart),
|
|
7114
|
+
onDragStart: function (event) {
|
|
7115
|
+
if (props.onDragStart) props.onDragStart(event, { path: child.path, name: child.name, isDir: false });
|
|
7116
|
+
},
|
|
6549
7117
|
onClick: function (event) {
|
|
6550
|
-
if (onSelectPath) onSelectPath({ path: child.path, name: child.name, isDir: false });
|
|
7118
|
+
if (onSelectPath) onSelectPath({ path: child.path, name: child.name, isDir: false, event: event });
|
|
6551
7119
|
if (event.detail !== 2) onSelect(child.path);
|
|
6552
7120
|
},
|
|
6553
7121
|
onDoubleClick: function () { if (onPin) onPin(child.path); },
|
|
@@ -6575,7 +7143,7 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
6575
7143
|
}, entry.loadingMore ? Spinner(12) : null,
|
|
6576
7144
|
entry.moreError
|
|
6577
7145
|
? messageOf(entry.moreError, t, locale)
|
|
6578
|
-
: t('loadMore', { count: Math.max((entry.total || 0) - entry.entries.length, 0) })));
|
|
7146
|
+
: t('loadMore', { count: Math.max((entry.total || 0) - (Number.isFinite(entry.raw) ? entry.raw : entry.entries.length), 0) })));
|
|
6579
7147
|
}
|
|
6580
7148
|
}
|
|
6581
7149
|
}
|
|
@@ -6586,17 +7154,33 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
6586
7154
|
role: 'treeitem',
|
|
6587
7155
|
'aria-level': depth + 1,
|
|
6588
7156
|
'aria-expanded': isOpen,
|
|
6589
|
-
className: 'rw-row' + (selectedPath === path ? ' is-active' : ''),
|
|
7157
|
+
className: 'rw-row' + (selectedPath === path || (props.selectedSet && props.selectedSet.has(path)) ? ' is-active' : ''),
|
|
6590
7158
|
style: { paddingLeft: 6 + depth * 12 },
|
|
6591
7159
|
title: path,
|
|
7160
|
+
draggable: Boolean(props.onDragStart),
|
|
7161
|
+
onDragStart: function (event) {
|
|
7162
|
+
if (props.onDragStart) props.onDragStart(event, { path: path, name: name, isDir: true });
|
|
7163
|
+
},
|
|
6592
7164
|
onClick: function (event) {
|
|
6593
|
-
if (onSelectPath) onSelectPath({ path: path, name: name, isDir: true });
|
|
7165
|
+
if (onSelectPath) onSelectPath({ path: path, name: name, isDir: true, event: event });
|
|
6594
7166
|
if (event.detail !== 2) toggle(path);
|
|
6595
7167
|
},
|
|
6596
7168
|
onKeyDown: function (event) {
|
|
6597
7169
|
if (event.key === 'ArrowRight' && !isOpen) { event.preventDefault(); toggle(path); }
|
|
6598
7170
|
else if (event.key === 'ArrowLeft' && isOpen) { event.preventDefault(); toggle(path); }
|
|
6599
7171
|
},
|
|
7172
|
+
onDragOver: function (event) {
|
|
7173
|
+
if (!props.onDropOnPath) return;
|
|
7174
|
+
event.preventDefault();
|
|
7175
|
+
event.stopPropagation();
|
|
7176
|
+
try { event.dataTransfer.dropEffect = 'copy'; } catch (error) { /* ignore */ }
|
|
7177
|
+
event.currentTarget.classList.add('is-drop-target');
|
|
7178
|
+
},
|
|
7179
|
+
onDragLeave: function (event) { event.currentTarget.classList.remove('is-drop-target'); },
|
|
7180
|
+
onDrop: function (event) {
|
|
7181
|
+
event.currentTarget.classList.remove('is-drop-target');
|
|
7182
|
+
if (props.onDropOnPath) props.onDropOnPath(path, event);
|
|
7183
|
+
},
|
|
6600
7184
|
onContextMenu: function (event) {
|
|
6601
7185
|
if (!onContextMenu) return;
|
|
6602
7186
|
event.preventDefault();
|
|
@@ -6639,15 +7223,18 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
6639
7223
|
}
|
|
6640
7224
|
|
|
6641
7225
|
function load(path) {
|
|
7226
|
+
// Ref-based guard: a state setter callback is not a lock, so checking
|
|
7227
|
+
// record.loading inside setCache would still fire duplicate requests.
|
|
7228
|
+
if (pending.current.has(path)) return;
|
|
7229
|
+
pending.current.add(path);
|
|
6642
7230
|
setCache(function (previous) {
|
|
6643
|
-
var record = previous.entries.get(path);
|
|
6644
|
-
if (record && record.loading) return previous;
|
|
6645
7231
|
var entries = new Map(previous.entries);
|
|
6646
7232
|
var existing = entries.get(path) || {};
|
|
6647
7233
|
entries.set(path, { loading: true, error: null, entries: existing.entries || [], loaded: existing.loaded });
|
|
6648
7234
|
return { entries: entries };
|
|
6649
7235
|
});
|
|
6650
7236
|
apiCall('fs.list', listRequest(path, 0)).then(function (result) {
|
|
7237
|
+
pending.current.delete(path);
|
|
6651
7238
|
setCache(function (previous) {
|
|
6652
7239
|
var entries = new Map(previous.entries);
|
|
6653
7240
|
entries.set(path, {
|
|
@@ -6655,6 +7242,7 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
6655
7242
|
error: null,
|
|
6656
7243
|
loaded: true,
|
|
6657
7244
|
entries: result.entries || [],
|
|
7245
|
+
raw: (result.entries || []).length,
|
|
6658
7246
|
total: Number(result.total) || (result.entries || []).length,
|
|
6659
7247
|
hasMore: Boolean(result.hasMore),
|
|
6660
7248
|
});
|
|
@@ -6666,6 +7254,7 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
6666
7254
|
return next;
|
|
6667
7255
|
});
|
|
6668
7256
|
}).catch(function (error) {
|
|
7257
|
+
pending.current.delete(path);
|
|
6669
7258
|
setCache(function (previous) {
|
|
6670
7259
|
var entries = new Map(previous.entries);
|
|
6671
7260
|
entries.set(path, { loading: false, error: error, loaded: false, entries: [] });
|
|
@@ -6677,13 +7266,14 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
6677
7266
|
function loadMore(path) {
|
|
6678
7267
|
var record = cache.entries.get(path);
|
|
6679
7268
|
if (!record || record.loadingMore || !record.hasMore) return;
|
|
7269
|
+
var offset = Number.isFinite(Number(record.raw)) ? Number(record.raw) : (record.entries || []).length;
|
|
6680
7270
|
setCache(function (previous) {
|
|
6681
7271
|
var entries = new Map(previous.entries);
|
|
6682
7272
|
var current = entries.get(path);
|
|
6683
7273
|
if (current) entries.set(path, Object.assign({}, current, { loadingMore: true }));
|
|
6684
7274
|
return { entries: entries };
|
|
6685
7275
|
});
|
|
6686
|
-
apiCall('fs.list', listRequest(path,
|
|
7276
|
+
apiCall('fs.list', listRequest(path, offset)).then(function (result) {
|
|
6687
7277
|
setCache(function (previous) {
|
|
6688
7278
|
var entries = new Map(previous.entries);
|
|
6689
7279
|
var current = entries.get(path) || { entries: [] };
|
|
@@ -6691,6 +7281,7 @@ function urlAttributeViolation(name, value, tagName) {
|
|
|
6691
7281
|
loadingMore: false,
|
|
6692
7282
|
loaded: true,
|
|
6693
7283
|
entries: current.entries.concat(result.entries || []),
|
|
7284
|
+
raw: offset + (result.entries || []).length,
|
|
6694
7285
|
total: Number(result.total) || current.total,
|
|
6695
7286
|
hasMore: Boolean(result.hasMore),
|
|
6696
7287
|
}));
|