dsh-linked-workspace 0.34.0 → 0.35.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/lib/client.js CHANGED
@@ -2200,6 +2200,46 @@ function isInsideRoot(root, target) {
2200
2200
  return full === base || full.indexOf(base + '/') === 0
2201
2201
  }
2202
2202
 
2203
+ // A render error in this subtree used to escape to dsh-better-sidebar, which
2204
+ // then showed its own error banner for the tab — and re-rendered the same
2205
+ // broken subtree on every restart. Catch it here instead, explain, offer a retry.
2206
+ var TabBoundary = (function () {
2207
+ var Base = React && typeof React.Component === 'function' ? React.Component : null;
2208
+ // Without a Component to extend there is nothing to catch with; fall back
2209
+ // to a pass-through so the tab still renders.
2210
+ if (!Base) return function (props) { return props.children; };
2211
+
2212
+ function Boundary(props) {
2213
+ Base.call(this, props);
2214
+ this.state = { error: null };
2215
+ this.retry = this.retry.bind(this);
2216
+ }
2217
+
2218
+ Boundary.prototype = Object.create(Base.prototype);
2219
+ Boundary.prototype.constructor = Boundary;
2220
+ Boundary.getDerivedStateFromError = function (error) { return { error: error }; };
2221
+
2222
+ Boundary.prototype.componentDidCatch = function (error) {
2223
+ try { console.error('[dsh-linked-workspace] tab render failed', error); } catch (ignored) { /* no console */ }
2224
+ };
2225
+
2226
+ Boundary.prototype.retry = function () {
2227
+ this.setState({ error: null });
2228
+ };
2229
+
2230
+ Boundary.prototype.render = function () {
2231
+ if (!this.state.error) return this.props.children;
2232
+ var t = this.props.t || function (key) { return key; };
2233
+ var detail = this.state.error && this.state.error.message ? this.state.error.message : String(this.state.error);
2234
+ return h('div', { className: 'rw-tab-crash' },
2235
+ h(Banner, { kind: 'error' }, t('tabCrashed')),
2236
+ h('div', { className: 'rw-muted', style: { marginTop: 4 } }, detail),
2237
+ h('button', { type: 'button', className: 'rw-btn', style: { marginTop: 8 }, onClick: this.retry }, IconRefresh(13), t('retry')));
2238
+ };
2239
+
2240
+ return Boundary;
2241
+ })();
2242
+
2203
2243
  var TREE_TAB_TYPE = 'dsh-linked-workspace';
2204
2244
  // Remote workspaces get their own page kind: the two modes show different
2205
2245
  // trees (local ⇄ remote pair vs. a plain remote root), so a session must be
@@ -2640,7 +2680,7 @@ function isInsideRoot(root, target) {
2640
2680
  csvTable: '表格',
2641
2681
  csvSource: '源码',
2642
2682
  csvEmpty: '没有可显示的数据',
2643
- csvTruncated: '仅显示前 1000 行',
2683
+ csvTruncated: '仅显示前 20000 行(其余请在文本模式查看)',
2644
2684
  moveTitle: '移动到…',
2645
2685
  moveMessage: '选择「{{name}}」要移动到的目录',
2646
2686
  moveMessageMany: '选择这 {{count}} 项要移动到的目录',
@@ -2833,10 +2873,14 @@ function isInsideRoot(root, target) {
2833
2873
  docTable: '表格',
2834
2874
  docSheet: '工作表',
2835
2875
  docSlide: '幻灯片',
2836
- docPdfTitle: '标题',
2837
- docPdfAuthor: '作者',
2838
- docPageOf: '第 {page} / {total} 页',
2876
+ docPageOf: '第 {{page}} / {{total}} 页',
2839
2877
  docExportDone: '已导出 PDF:{path}',
2878
+ docRenderEmpty: '这一页没有渲染出内容,点「重新加载」再试一次。',
2879
+ docPageView: '逐页视图',
2880
+ docRenderedView: '渲染视图',
2881
+ outline: '目录',
2882
+ closeOutline: '关闭目录',
2883
+ tabCrashed: '这个标签页渲染时出错了。点「重试」可以重新渲染,或关掉它再从「+」打开。',
2840
2884
  docPreviewFailed: '预览失败',
2841
2885
  previewTooLarge: '这个文件太大({{chars}} 字符,上限 {{limit}}),没有生成预览;可以在编辑器里查看,或下载后用别的工具打开。',
2842
2886
  previewTooLargeBytes: '这个文件太大({{bytes}}),没有生成预览;可以在编辑器里查看,或下载后用别的工具打开。',
@@ -3264,7 +3308,7 @@ function isInsideRoot(root, target) {
3264
3308
  csvTable: 'Table',
3265
3309
  csvSource: 'Source',
3266
3310
  csvEmpty: 'No rows to show',
3267
- csvTruncated: 'Showing the first 1000 rows',
3311
+ csvTruncated: 'Showing the first 20000 rows only (text mode shows the rest)',
3268
3312
  moveTitle: 'Move to…',
3269
3313
  moveMessage: 'Choose the destination folder for "{{name}}"',
3270
3314
  moveMessageMany: 'Choose the destination folder for these {{count}} items',
@@ -3457,10 +3501,14 @@ function isInsideRoot(root, target) {
3457
3501
  docTable: 'Table',
3458
3502
  docSheet: 'Sheet',
3459
3503
  docSlide: 'Slide',
3460
- docPdfTitle: 'Title',
3461
- docPdfAuthor: 'Author',
3462
- docPageOf: 'Page {page} / {total}',
3504
+ docPageOf: 'Page {{page}} / {{total}}',
3463
3505
  docExportDone: 'Exported PDF: {path}',
3506
+ docRenderEmpty: 'This page rendered empty; try reloading it.',
3507
+ docPageView: 'Page by page',
3508
+ docRenderedView: 'Rendered view',
3509
+ outline: 'Outline',
3510
+ closeOutline: 'Close the outline',
3511
+ tabCrashed: 'This tab failed to render. Retry re-renders it; you can also close it and open it from "+".',
3464
3512
  docPreviewFailed: 'Preview failed',
3465
3513
  previewTooLarge: 'Too large to preview ({{chars}} characters, the ceiling is {{limit}}). Read it in the editor, or download it and open it elsewhere.',
3466
3514
  previewTooLargeBytes: 'Too large to preview ({{bytes}}). Read it in the editor, or download it and open it elsewhere.',
@@ -3868,7 +3916,7 @@ function isInsideRoot(root, target) {
3868
3916
  * Host methods the running DSH process does not have yet, the directory
3869
3917
  * pane says so instead of surfacing an unrelated error.
3870
3918
  */
3871
- var HOST_API_REVISION = 16;
3919
+ var HOST_API_REVISION = 18;
3872
3920
  var hostInfoProbe = null;
3873
3921
 
3874
3922
  function probeHostInfo() {
@@ -3941,15 +3989,33 @@ function isInsideRoot(root, target) {
3941
3989
  return known + (locale === 'zh' ? ':' : ': ') + detail + hint;
3942
3990
  }
3943
3991
 
3992
+ // Points at the Host's read-only byte route. Remote paths are absolute
3993
+ // inside the workspace; local ones are absolute on this machine and the Host
3994
+ // only serves them when they sit inside a configured workspace.
3995
+ function rawFileUrl(scope, local, filePath) {
3996
+ var normalized = String(filePath || '').split('\\').join('/');
3997
+ if (normalized === '') return '';
3998
+ var segments = normalized.split('/').filter(function (part) { return part !== ''; });
3999
+ if (segments.length === 0) return '';
4000
+ var encoded = segments.map(encodeURIComponent).join('/');
4001
+ if (local) return '/dsh-linked-workspace/fs/local/' + encoded;
4002
+ if (!scope || !scope.id) return '';
4003
+ if (scope.kind === 'linked') return '/dsh-linked-workspace/fs/linked/' + encodeURIComponent(scope.id) + '/remote/' + encoded;
4004
+ if (scope.kind === 'remote') return '/dsh-linked-workspace/fs/remote/' + encodeURIComponent(scope.id) + '/' + encoded;
4005
+ return '';
4006
+ }
4007
+
3944
4008
  function documentKindOf(path) {
3945
4009
  var ext = String(path || '').toLowerCase().match(/\.[^./\\]+$/);
3946
4010
  if (!ext) return '';
3947
4011
  var value = ext[0];
3948
4012
  if (value === '.md' || value === '.markdown') return 'markdown';
3949
4013
  if (value === '.pdf') return 'pdf';
3950
- if (value === '.docx') return 'docx';
3951
- if (value === '.xlsx') return 'xlsx';
3952
- if (value === '.pptx') return 'pptx';
4014
+ // Every office format is converted before it is shown, so the client only
4015
+ // needs to know that it is one: doc/docx/odt, xls/xlsx/ods, ppt/pptx/odp.
4016
+ if (value === '.doc' || value === '.docx' || value === '.odt') return 'office';
4017
+ if (value === '.xls' || value === '.xlsx' || value === '.ods') return 'office';
4018
+ if (value === '.ppt' || value === '.pptx' || value === '.odp') return 'office';
3953
4019
  if (value === '.csv' || value === '.tsv') return 'csv';
3954
4020
  if (value === '.html' || value === '.htm') return 'html';
3955
4021
  if (value === '.png' || value === '.jpg' || value === '.jpeg' || value === '.gif'
@@ -4049,6 +4115,14 @@ function isInsideRoot(root, target) {
4049
4115
  return index <= 0 ? '/' : clean.slice(0, index);
4050
4116
  }
4051
4117
 
4118
+ function byteLengthOf(text) {
4119
+ var value = typeof text === 'string' ? text : '';
4120
+ if (typeof TextEncoder === 'function') {
4121
+ try { return new TextEncoder().encode(value).length; } catch (error) { /* fall through */ }
4122
+ }
4123
+ return value.length;
4124
+ }
4125
+
4052
4126
  function formatBytes(size) {
4053
4127
  var value = Number(size) || 0;
4054
4128
  if (value < 1024) return value + ' B';
@@ -4480,6 +4554,18 @@ function isInsideRoot(root, target) {
4480
4554
  '.rw-doc-preview th,.rw-doc-preview td{border:1px solid var(--dsw-alias-border-l2);padding:5px 8px}',
4481
4555
  '.rw-doc-preview img{max-width:100%}',
4482
4556
  '.rw-doc-preview blockquote{border-left:3px solid var(--dsw-alias-border-l2);margin:0;padding-left:10px;color:var(--dsw-alias-label-secondary)}',
4557
+ '.rw-html-source{flex:1 1 auto;min-height:0;resize:none;border:0;border-radius:0;font-family:var(--dsw-alias-font-mono,ui-monospace,SFMono-Regular,Menlo,monospace);font-size:12px;line-height:1.55}',
4558
+ '.rw-tab-crash{padding:14px;display:flex;flex-direction:column;align-items:flex-start}',
4559
+ '.rw-toc{position:absolute;top:8px;right:10px;z-index:3;width:min(240px,62%);max-height:70%;display:flex;flex-direction:column;background:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-border-l1);border-radius:8px;box-shadow:0 6px 20px rgba(0,0,0,.18);overflow:hidden}',
4560
+ '.rw-toc-head{display:flex;align-items:center;justify-content:space-between;gap:6px;padding:5px 6px 5px 9px;font-size:11px;color:var(--dsw-alias-label-secondary);border-bottom:1px solid var(--dsw-alias-border-l1)}',
4561
+ '.rw-toc-list{display:flex;flex-direction:column;overflow:auto;padding:3px}',
4562
+ '.rw-toc-item{display:block;width:100%;text-align:left;border:0;background:transparent;color:var(--dsw-alias-label-primary);font:inherit;font-size:11.5px;line-height:16px;padding:3px 5px;border-radius:5px;cursor:pointer;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}',
4563
+ '.rw-toc-item:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.12))}',
4564
+ '.rw-toc-l1{font-weight:600}',
4565
+ '.rw-toc-l2{padding-left:14px}',
4566
+ '.rw-toc-l3{padding-left:24px;color:var(--dsw-alias-label-secondary)}',
4567
+ '.rw-doc-frame{flex:1 1 auto;width:100%;min-height:0;border:0;background:#fff}',
4568
+ '.rw-doc-page{display:block;margin:0 auto;max-width:100%;background:#fff;box-shadow:0 1px 3px rgba(0,0,0,.18);border-radius:2px}',
4483
4569
  '.rw-doc-pdf-page{display:block;max-width:100%;margin:0 auto 10px;border:1px solid var(--dsw-alias-border-l2);box-shadow:0 2px 10px rgba(0,0,0,.08);background:#fff}',
4484
4570
  '.rw-doc-field{display:flex;align-items:center;gap:8px;margin:6px 0}',
4485
4571
  '.rw-doc-field label{font-size:11.5px;color:var(--dsw-alias-label-tertiary);min-width:38px}',
@@ -4599,7 +4685,7 @@ function isInsideRoot(root, target) {
4599
4685
  '.rw-csv-wrap{flex:1 1 auto;min-height:0;overflow:auto;background:var(--dsw-alias-bg-base)}',
4600
4686
  '.rw-csv-table{border-collapse:collapse;font:12px/18px ui-monospace,"Cascadia Code",Consolas,monospace;min-width:100%}',
4601
4687
  '.rw-csv-table th{position:sticky;top:0;z-index:1;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-tertiary);font-weight:600;text-align:left;padding:4px 8px;border:1px solid var(--dsw-alias-border-l1);white-space:nowrap}',
4602
- '.rw-csv-table td{padding:3px 8px;border:1px solid var(--dsw-alias-border-l1);vertical-align:top;max-width:360px;overflow-wrap:anywhere}',
4688
+ '.rw-csv-table td{height:26px;box-sizing:border-box;padding:3px 8px;border:1px solid var(--dsw-alias-border-l1);vertical-align:top;max-width:360px;overflow-wrap:anywhere}',
4603
4689
  '.rw-csv-table tr:nth-child(even) td{background:color-mix(in srgb,var(--dsw-alias-bg-layer-1) 52%,transparent)}',
4604
4690
  '.rw-csv-note{padding:5px 9px;font-size:10.5px;color:var(--dsw-alias-label-tertiary);border-top:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1)}',
4605
4691
  '.rw-queue-row{display:flex;align-items:center;gap:8px;padding:5px 0;border-bottom:1px solid var(--dsw-alias-border-l1);font-size:12px}',
@@ -5783,6 +5869,7 @@ function isInsideRoot(root, target) {
5783
5869
  var zoom = zoomState[0];
5784
5870
  var setZoom = zoomState[1];
5785
5871
  var stageRef = useRef(null);
5872
+ var fallbackRef = useRef(false);
5786
5873
  var params = scopeParams(scope);
5787
5874
  var MIN_ZOOM = 0.05;
5788
5875
  var MAX_ZOOM = 8;
@@ -5809,12 +5896,12 @@ function isInsideRoot(root, target) {
5809
5896
  }
5810
5897
  setNatural(null);
5811
5898
  setView({ loading: true, error: null, data: null });
5812
- var request = local ? { path: filePath } : Object.assign({ path: filePath }, params);
5813
- apiCall(local ? 'local.media' : 'media.read', request).then(function (result) {
5814
- setView({ loading: false, error: null, data: result });
5815
- }).catch(function (error) {
5816
- setView({ loading: false, error: error, data: null });
5817
- });
5899
+ var url = rawFileUrl(scope, local, filePath);
5900
+ if (url === '') {
5901
+ setView({ loading: false, error: new Error(t('noWorkspace')), data: null });
5902
+ return;
5903
+ }
5904
+ setView({ loading: false, error: null, data: { url: url, mime: '' } });
5818
5905
  }, [scopeKeyOf(scope), filePath, local]);
5819
5906
 
5820
5907
  useEffect(function () { load(); }, [load]);
@@ -5822,6 +5909,7 @@ function isInsideRoot(root, target) {
5822
5909
  useEffect(function () {
5823
5910
  setZoom(1);
5824
5911
  setNatural(null);
5912
+ fallbackRef.current = false;
5825
5913
  }, [filePath]);
5826
5914
 
5827
5915
  useEffect(function () {
@@ -5894,7 +5982,7 @@ function isInsideRoot(root, target) {
5894
5982
  h('div', { className: 'rw-image-canvas' },
5895
5983
  h('img', {
5896
5984
  className: 'rw-image',
5897
- src: 'data:' + data.mime + ';base64,' + data.base64,
5985
+ src: data.url,
5898
5986
  alt: name,
5899
5987
  style: imageStyle,
5900
5988
  onLoad: function (event) {
@@ -5903,8 +5991,33 @@ function isInsideRoot(root, target) {
5903
5991
  setNatural({ width: image.naturalWidth, height: image.naturalHeight });
5904
5992
  }
5905
5993
  },
5906
- onError: function () {
5907
- setView({ loading: false, error: new Error(t('imageLoadError')), data: null });
5994
+ onError: function (event) {
5995
+ var url = event.currentTarget.currentSrc || data.url;
5996
+ if (fallbackRef.current || local || !scope) {
5997
+ setView({ loading: false, error: new Error(t('imageLoadError')), data: null });
5998
+ return;
5999
+ }
6000
+ fallbackRef.current = true;
6001
+ // Ask the route why, then read the bytes over the JSON channel:
6002
+ // that path never depends on a subresource request succeeding.
6003
+ fetch(url, { credentials: 'same-origin' }).then(function (response) {
6004
+ if (response.ok) return '';
6005
+ return response.text().then(function (body) { return response.status + ' ' + String(body || '').trim().slice(0, 160); });
6006
+ }, function () { return ''; }).then(function (reason) {
6007
+ apiCall('media.read', Object.assign({ path: filePath }, params)).then(function (result) {
6008
+ setView({
6009
+ loading: false,
6010
+ error: null,
6011
+ data: {
6012
+ url: 'data:' + String(result.mime || 'application/octet-stream') + ';base64,' + String(result.base64 || ''),
6013
+ mime: result.mime,
6014
+ size: result.size,
6015
+ },
6016
+ });
6017
+ }, function (error) {
6018
+ setView({ loading: false, error: reason ? new Error(reason) : error, data: null });
6019
+ });
6020
+ });
5908
6021
  },
5909
6022
  }))),
5910
6023
  h('div', { className: 'rw-editor-status' },
@@ -5922,39 +6035,62 @@ function isInsideRoot(root, target) {
5922
6035
  var scope = props.scope;
5923
6036
  var local = props.local === true;
5924
6037
  var filePath = props.path;
5925
- var state = useState({ loading: true, error: null, data: null });
6038
+ var state = useState({ loading: true, error: null, data: null, editing: false, draft: '', saving: false, notice: '', dirty: false });
5926
6039
  var view = state[0];
5927
6040
  var setView = state[1];
5928
6041
  var params = scopeParams(scope);
5929
6042
 
6043
+ function patch(next) { setView(function (previous) { return Object.assign({}, previous, next); }); }
6044
+
5930
6045
  var load = useCallback(function () {
5931
6046
  if (!filePath || (!local && !scope)) {
5932
- setView({ loading: false, error: new Error(t('noWorkspace')), data: null });
6047
+ setView({ loading: false, error: new Error(t('noWorkspace')), data: null, editing: false, draft: '', saving: false, notice: '', dirty: false });
5933
6048
  return;
5934
6049
  }
5935
- setView({ loading: true, error: null, data: null });
6050
+ setView(function (previous) { return Object.assign({}, previous, { loading: true, error: null }); });
5936
6051
  var request = local ? { path: filePath, preview: true } : Object.assign({ path: filePath, preview: true }, params);
5937
6052
  apiCall(local ? 'local.read' : 'fs.read', request).then(function (result) {
5938
6053
  if (result.tooLarge || result.truncated) {
5939
6054
  setView({
5940
6055
  loading: false,
5941
6056
  error: new Error(t('htmlPreviewTooLarge', { size: formatBytes(result.size), limit: formatBytes(PREVIEW_MAX_BYTES) })),
5942
- data: null,
6057
+ data: null, editing: false, draft: '', saving: false, notice: '', dirty: false,
5943
6058
  });
5944
6059
  return;
5945
6060
  }
5946
6061
  if (result.binary) {
5947
- setView({ loading: false, error: new Error(t('htmlPreviewBinary')), data: null });
6062
+ setView({ loading: false, error: new Error(t('htmlPreviewBinary')), data: null, editing: false, draft: '', saving: false, notice: '', dirty: false });
5948
6063
  return;
5949
6064
  }
5950
- setView({ loading: false, error: null, data: result });
6065
+ setView({
6066
+ loading: false, error: null, data: result,
6067
+ draft: typeof result.content === 'string' ? result.content : '',
6068
+ editing: false, saving: false, notice: '', dirty: false,
6069
+ });
5951
6070
  }).catch(function (error) {
5952
- setView({ loading: false, error: error, data: null });
6071
+ setView({ loading: false, error: error, data: null, editing: false, draft: '', saving: false, notice: '', dirty: false });
5953
6072
  });
5954
6073
  }, [scopeKeyOf(scope), filePath, local]);
5955
6074
 
5956
6075
  useEffect(function () { load(); }, [load]);
5957
6076
 
6077
+ function save() {
6078
+ if (view.saving || !view.dirty) return;
6079
+ patch({ saving: true, error: null, notice: '' });
6080
+ var request = local
6081
+ ? { path: filePath, content: view.draft, expectedMtime: view.data ? view.data.mtime : undefined }
6082
+ : Object.assign({ path: filePath, content: view.draft, expectedMtime: view.data ? view.data.mtime : undefined }, params);
6083
+ apiCall(local ? 'local.write' : 'fs.write', request).then(function (result) {
6084
+ patch({
6085
+ saving: false, dirty: false, notice: t('saved'),
6086
+ data: Object.assign({}, view.data, { content: view.draft, size: result.size, mtime: result.mtime }),
6087
+ });
6088
+ if (typeof props.onSaved === 'function') props.onSaved();
6089
+ }).catch(function (error) {
6090
+ patch({ saving: false, error: error });
6091
+ });
6092
+ }
6093
+
5958
6094
  var name = basename(filePath) || t('fileTabTitle');
5959
6095
  var header = h('div', { className: 'rw-image-head' },
5960
6096
  h(FileGlyph, { name: name, size: 15 }),
@@ -5962,35 +6098,65 @@ function isInsideRoot(root, target) {
5962
6098
  h('span', { className: 'rw-editor-name', title: name }, name),
5963
6099
  h('span', { className: 'rw-editor-path', title: filePath }, filePath)),
5964
6100
  h('div', { className: 'rw-actions' },
6101
+ h('button', {
6102
+ type: 'button',
6103
+ className: 'rw-btn rw-btn-sm',
6104
+ onClick: function () { patch({ editing: !view.editing, notice: '' }); },
6105
+ disabled: view.loading,
6106
+ }, view.editing ? t('docPreview') : t('docEdit')),
6107
+ view.editing
6108
+ ? h('button', { type: 'button', className: 'rw-btn rw-btn-sm rw-btn-primary', onClick: save, disabled: view.saving || !view.dirty }, view.saving ? Spinner(12) : IconSave(12), view.saving ? t('saving') : t('save'))
6109
+ : null,
5965
6110
  h('button', { type: 'button', className: 'rw-btn rw-btn-sm', onClick: load, disabled: view.loading }, IconRefresh(12), t('reload'))));
5966
6111
 
5967
6112
  if (view.loading) {
5968
6113
  return h('div', { className: 'rw-html-preview' }, header,
5969
6114
  h('div', { className: 'rw-editor-message' }, Spinner(14), t('loading')));
5970
6115
  }
5971
- if (view.error) {
6116
+ if (view.error && !view.data) {
5972
6117
  return h('div', { className: 'rw-html-preview' }, header,
5973
6118
  h('div', { className: 'rw-editor-message' },
5974
6119
  h(Banner, { kind: 'error' }, t('htmlLoadError') + ':' + messageOf(view.error, t, locale)),
5975
6120
  h('button', { type: 'button', className: 'rw-btn', onClick: load }, IconRefresh(13), t('retry'))));
5976
6121
  }
5977
- var data = view.data;
6122
+ var data = view.data || {};
6123
+ // A real src lets the page pull its relative css/js/img through the same
6124
+ // read-only route; sandbox still keeps it in an opaque origin away from
6125
+ // the DSH UI.
6126
+ var htmlUrl = rawFileUrl(scope, local, filePath);
6127
+ var stage = view.editing
6128
+ ? h('textarea', {
6129
+ className: 'rw-doc-textarea rw-html-source',
6130
+ value: view.draft,
6131
+ spellCheck: false,
6132
+ onChange: function (event) { patch({ draft: event.currentTarget.value, dirty: true, notice: '' }); },
6133
+ onKeyDown: function (event) {
6134
+ if ((event.ctrlKey || event.metaKey) && (event.key === 's' || event.key === 'S')) {
6135
+ event.preventDefault();
6136
+ save();
6137
+ }
6138
+ },
6139
+ })
6140
+ : h('iframe', {
6141
+ className: 'rw-html-frame',
6142
+ title: name,
6143
+ // allow-scripts runs the page's own JS (charts need it) inside an
6144
+ // opaque origin: no access to the DSH UI, its storage or the tree.
6145
+ sandbox: 'allow-scripts',
6146
+ src: htmlUrl,
6147
+ });
6148
+
5978
6149
  return h('div', { className: 'rw-html-preview' },
5979
6150
  header,
5980
- h('div', { className: 'rw-html-stage' },
5981
- h('iframe', {
5982
- className: 'rw-html-frame',
5983
- title: name,
5984
- // allow-scripts runs the page's own JS (charts need it) inside an
5985
- // opaque origin: no access to the DSH UI, its storage or the tree.
5986
- sandbox: 'allow-scripts',
5987
- srcDoc: data.content || '',
5988
- })),
6151
+ view.notice ? h('div', { style: { padding: '6px 10px 0' } }, h(Banner, { kind: 'success' }, view.notice)) : null,
6152
+ view.error && view.data ? h('div', { style: { padding: '6px 10px 0' } }, h(Banner, { kind: 'error' }, messageOf(view.error, t, locale))) : null,
6153
+ h('div', { className: 'rw-html-stage' }, stage),
5989
6154
  h('div', { className: 'rw-editor-status' },
5990
6155
  h('span', { className: 'rw-status-chip' }, 'HTML'),
5991
- h('span', { className: 'rw-status-chip' }, formatBytes(data.size || 0)),
6156
+ h('span', { className: 'rw-status-chip' }, formatBytes(byteLengthOf(view.draft))),
6157
+ view.dirty ? h('span', { className: 'rw-status-chip rw-status-warn' }, t('dirty')) : null,
5992
6158
  h('span', { className: 'rw-fill', style: { flex: '1 1 auto' } }),
5993
- h('span', { className: 'rw-status-chip' }, t('htmlSandboxed'))));
6159
+ h('span', { className: 'rw-status-chip' }, view.editing ? t('docEdit') : t('htmlSandboxed'))));
5994
6160
  }
5995
6161
 
5996
6162
  // ── editor ─────────────────────────────────────────────────────────────
@@ -6404,10 +6570,13 @@ function isInsideRoot(root, target) {
6404
6570
  if (!csvMode) return [];
6405
6571
  var text = content.length > 1000000 ? content.slice(0, 1000000) : content;
6406
6572
  var delimiter = csvDelimiterOf(filePath, text);
6407
- return parseDelimited(text, delimiter).slice(0, 1000).map(function (row) {
6573
+ return parseDelimited(text, delimiter).slice(0, 20000).map(function (row) {
6408
6574
  return row.slice(0, 80);
6409
6575
  });
6410
6576
  }, [content, filePath, csvMode]);
6577
+ var csvWindowRef = useState({ start: 0, count: 60 });
6578
+ var csvWindow = csvWindowRef[0];
6579
+ var setCsvWindow = csvWindowRef[1];
6411
6580
  var highlighted = useMemo(function () {
6412
6581
  if (!editable) return null;
6413
6582
  return highlightNodes(content, language, theme, 180000);
@@ -6489,22 +6658,49 @@ function isInsideRoot(root, target) {
6489
6658
  var canView = Boolean(load.file && !load.file.binary && !load.file.tooLarge);
6490
6659
  var csvColumnCount = 0;
6491
6660
  csvRows.forEach(function (row) { if (row.length > csvColumnCount) csvColumnCount = row.length; });
6661
+ var CSV_ROW_PX = 26;
6662
+ var csvBodyRows = csvRows.length > 0 ? csvRows.slice(1) : [];
6663
+ var csvStart = Math.min(csvWindow.start, Math.max(0, csvBodyRows.length - 1));
6664
+ var csvEnd = Math.min(csvBodyRows.length, csvStart + csvWindow.count);
6665
+ var csvSpacer = function (rows) {
6666
+ return rows > 0
6667
+ ? h('tr', { key: 'sp' + rows, 'aria-hidden': 'true' }, h('td', {
6668
+ colSpan: Math.max(csvColumnCount, 1),
6669
+ style: { height: rows * CSV_ROW_PX + 'px', padding: 0, border: 0 },
6670
+ }))
6671
+ : null;
6672
+ };
6492
6673
  var csvTable = csvRows.length === 0
6493
6674
  ? h('div', { className: 'rw-editor-message' }, t('csvEmpty'))
6494
- : h('div', { className: 'rw-csv-wrap' },
6495
- h('table', { className: 'rw-csv-table' },
6496
- h('thead', null, h('tr', null,
6497
- Array.from({ length: csvColumnCount }, function (_, index) {
6498
- return h('th', { key: 'h' + index, title: csvRows[0][index] || '' }, csvRows[0][index] || '');
6499
- }))),
6500
- h('tbody', null, csvRows.slice(1).map(function (row, rowIndex) {
6675
+ : h('div', {
6676
+ className: 'rw-csv-wrap',
6677
+ onScroll: function (event) {
6678
+ var node = event.currentTarget;
6679
+ var height = Number(node.clientHeight) || 480;
6680
+ var start = Math.max(0, Math.floor(node.scrollTop / CSV_ROW_PX) - 6);
6681
+ var count = Math.ceil(height / CSV_ROW_PX) + 12;
6682
+ setCsvWindow(function (previous) {
6683
+ return previous.start === start && previous.count === count ? previous : { start: start, count: count };
6684
+ });
6685
+ },
6686
+ },
6687
+ h('table', { className: 'rw-csv-table' },
6688
+ h('thead', null, h('tr', null,
6689
+ Array.from({ length: csvColumnCount }, function (_, index) {
6690
+ return h('th', { key: 'h' + index, title: csvRows[0][index] || '' }, csvRows[0][index] || '');
6691
+ }))),
6692
+ h('tbody', null,
6693
+ csvSpacer(csvStart),
6694
+ csvBodyRows.slice(csvStart, csvEnd).map(function (row, index) {
6695
+ var rowIndex = csvStart + index;
6501
6696
  return h('tr', { key: 'r' + rowIndex },
6502
6697
  Array.from({ length: csvColumnCount }, function (_, columnIndex) {
6503
6698
  var value = row[columnIndex] === undefined ? '' : row[columnIndex];
6504
6699
  return h('td', { key: 'c' + columnIndex, title: value }, value);
6505
6700
  }));
6506
- }))),
6507
- csvRows.length >= 1000 ? h('div', { className: 'rw-csv-note' }, t('csvTruncated')) : null);
6701
+ }),
6702
+ csvSpacer(csvBodyRows.length - csvEnd))),
6703
+ csvRows.length >= 20000 ? h('div', { className: 'rw-csv-note' }, t('csvTruncated')) : null);
6508
6704
  var body = canView
6509
6705
  ? (csvMode && showCsvTable
6510
6706
  ? csvTable
@@ -8052,6 +8248,9 @@ function rememberShowHidden(value) {
8052
8248
  var onOpenLink = props.onOpenLink;
8053
8249
  var settings = useRuntimeSettings();
8054
8250
  var kind = documentKindOf(path);
8251
+ // Word/Excel/PowerPoint are rendered through a PDF: the preview keeps the real
8252
+ // layout and is read-only, because the PDF cannot be written back as .docx.
8253
+ var officeKind = kind === 'office';
8055
8254
  var viewKey = (local ? 'local' : ((scope && scope.kind ? scope.kind : 'remote') + ':' + ((scope && scope.id) || ''))) + '|' + path;
8056
8255
  var rememberedView = recallView(viewKey);
8057
8256
  var stateRef = useState({
@@ -8062,7 +8261,13 @@ function rememberShowHidden(value) {
8062
8261
  sheet: rememberedView ? Number(rememberedView.sheet) || 0 : 0,
8063
8262
  slide: rememberedView ? Number(rememberedView.slide) || 0 : 0,
8064
8263
  updates: {}, pptxUpdates: {}, rotations: {}, deleted: {}, pdfLoading: false, notice: '', warn: '',
8065
- findOpen: false, findQuery: '', findIndex: 0,
8264
+ findOpen: false, findQuery: '', findIndex: 0, findReplace: '',
8265
+ office: null,
8266
+ frameUrl: '',
8267
+ frameMode: 'render',
8268
+ tocOpen: false,
8269
+ toc: [],
8270
+ zoom: 1,
8066
8271
  });
8067
8272
  var state = stateRef[0];
8068
8273
  var setState = stateRef[1];
@@ -8070,6 +8275,27 @@ function rememberShowHidden(value) {
8070
8275
  var docBodyRef = useRef(null);
8071
8276
  var docPreviewRef = useRef(null);
8072
8277
 
8278
+ useEffect(function () {
8279
+ var node = docPreviewRef.current;
8280
+ if (!node || !state.html) {
8281
+ if (state.toc.length > 0) patch({ toc: [] });
8282
+ return;
8283
+ }
8284
+ var headings = node.querySelectorAll('h1, h2, h3');
8285
+ var items = [];
8286
+ for (var index = 0; index < headings.length; index += 1) {
8287
+ var element = headings[index];
8288
+ var text = (element.textContent || '').replace(/\s+/g, ' ').trim();
8289
+ if (text === '') continue;
8290
+ var id = 'rw-toc-' + index;
8291
+ element.id = id;
8292
+ items.push({ id: id, level: element.tagName === 'H1' ? 1 : element.tagName === 'H2' ? 2 : 3, text: text });
8293
+ }
8294
+ // A single heading is not an outline; keep the toolbar quiet below two.
8295
+ if (items.length < 2) items = [];
8296
+ patch({ toc: items });
8297
+ }, [state.html]);
8298
+
8073
8299
  function patch(next) {
8074
8300
  setState(function (previous) { return Object.assign({}, previous, next); });
8075
8301
  }
@@ -8149,8 +8375,55 @@ function rememberShowHidden(value) {
8149
8375
  if (anchorOf(event)) event.preventDefault();
8150
8376
  }
8151
8377
 
8378
+ function loadOffice(index) {
8379
+ patch({ loading: true, error: '', notice: '', warn: '' });
8380
+ return apiCall('docs.officePdf', params()).then(function (result) {
8381
+ patch({
8382
+ loading: false,
8383
+ frameUrl: String(result.url || ''),
8384
+ office: { png: '', page: 0, pageCount: Number(result.pageCount) || 0, engine: result.engine || '' },
8385
+ page: 0,
8386
+ });
8387
+ }, function (error) {
8388
+ // No renderer (or a failed conversion): the raster path still works and
8389
+ // the panel keeps telling the user what happened.
8390
+ if (!error || (error.code !== 'NO_RENDERER' && error.code !== 'DOC_UNSUPPORTED')) {
8391
+ patch({ error: messageOf(error, t, locale) });
8392
+ }
8393
+ return apiCall('docs.officePage', params({ page: index })).then(function (result) {
8394
+ var rendered = (result.pages && result.pages[0]) || {};
8395
+ patch({
8396
+ loading: false,
8397
+ office: { png: rendered.png || '', page: Number(rendered.index) || 0, pageCount: Number(result.pageCount) || 0, engine: result.engine || '' },
8398
+ page: Number(rendered.index) || 0,
8399
+ });
8400
+ }).catch(function (fallbackError) {
8401
+ patch({ loading: false, error: messageOf(fallbackError, t, locale) });
8402
+ if (fallbackError && fallbackError.code === 'FS_NOT_FOUND' && typeof props.onMissing === 'function') props.onMissing(path);
8403
+ });
8404
+ });
8405
+ }
8406
+
8407
+ function goOfficePage(index) {
8408
+ if (!state.office) return;
8409
+ if (index < 0 || index >= state.office.pageCount || index === state.office.page) return;
8410
+ patch({ pdfLoading: true });
8411
+ apiCall('docs.officePage', params({ page: index })).then(function (result) {
8412
+ var rendered = (result.pages && result.pages[0]) || {};
8413
+ patch({
8414
+ pdfLoading: false,
8415
+ page: Number(rendered.index) || 0,
8416
+ office: Object.assign({}, state.office, { png: rendered.png || state.office.png, page: Number(rendered.index) || 0 }),
8417
+ });
8418
+ }).catch(function (error) {
8419
+ patch({ pdfLoading: false, error: messageOf(error, t, locale) });
8420
+ });
8421
+ }
8422
+
8152
8423
  function load() {
8424
+ if (officeKind) return loadOffice(Number((recallView(viewKey) || {}).page) || 0);
8153
8425
  patch({ loading: true, error: '', notice: '', warn: '' });
8426
+ if (kind === 'pdf') patch({ frameUrl: rawFileUrl(scope, local, path) });
8154
8427
  apiCall('docs.read', params()).then(function (result) {
8155
8428
  var remembered = recallView(viewKey);
8156
8429
  patch({
@@ -8211,6 +8484,7 @@ function rememberShowHidden(value) {
8211
8484
  }, [state.dirty]);
8212
8485
 
8213
8486
  function save() {
8487
+ if (officeKind) return Promise.resolve(false);
8214
8488
  if (state.saving) return Promise.resolve(false);
8215
8489
  patch({ saving: true, error: '', notice: '' });
8216
8490
  var data = {};
@@ -8306,6 +8580,38 @@ function rememberShowHidden(value) {
8306
8580
  if (docTextareaRef.current) docTextareaRef.current.focus();
8307
8581
  }
8308
8582
 
8583
+ // Same matching rule as docMatches: plain case-insensitive text, no
8584
+ // regex, so the replacement stays predictable.
8585
+ function replaceRange(text, at, length) {
8586
+ return text.slice(0, at) + state.findReplace + text.slice(at + length);
8587
+ }
8588
+
8589
+ function replaceDocCurrent() {
8590
+ var matches = docMatches();
8591
+ if (matches.length === 0) return;
8592
+ var index = Math.min(Math.max(state.findIndex, 0), matches.length - 1);
8593
+ var at = matches[index];
8594
+ var nextText = replaceRange(state.text, at, state.findQuery.length);
8595
+ patch({ text: nextText, dirty: true, html: '', findIndex: index });
8596
+ var area = docTextareaRef.current;
8597
+ if (area) {
8598
+ area.focus();
8599
+ var caret = at + state.findReplace.length;
8600
+ area.setSelectionRange(caret, caret);
8601
+ }
8602
+ }
8603
+
8604
+ function replaceDocAll() {
8605
+ var matches = docMatches();
8606
+ if (matches.length === 0) return;
8607
+ var text = state.text;
8608
+ // Back to front: the earlier offsets stay valid while splicing.
8609
+ for (var cursor = matches.length - 1; cursor >= 0; cursor -= 1) {
8610
+ text = replaceRange(text, matches[cursor], state.findQuery.length);
8611
+ }
8612
+ patch({ text: text, dirty: true, html: '', findIndex: 0 });
8613
+ }
8614
+
8309
8615
  useEffect(function () {
8310
8616
  if (!settings.autoSave || !state.dirty || state.saving) return undefined;
8311
8617
  var timer = setTimeout(function () { saveRef.current(); }, 900);
@@ -8363,7 +8669,8 @@ function rememberShowHidden(value) {
8363
8669
  }
8364
8670
 
8365
8671
  function goPdfPage(index) {
8366
- if (index < 0 || index >= (state.data.pageCount || 0)) return;
8672
+ var known = Number(state.data.pageCount) || 0;
8673
+ if (index < 0 || (known > 0 && index >= known)) return;
8367
8674
  var cached = (state.data.pages || []).filter(function (page) { return page.index === index; })[0];
8368
8675
  if (cached) {
8369
8676
  patch({ page: index });
@@ -8373,6 +8680,8 @@ function rememberShowHidden(value) {
8373
8680
  apiCall('docs.pdfPage', params({ page: index })).then(function (result) {
8374
8681
  var pages = (state.data.pages || []).filter(function (page) { return page.index !== result.pages[0].index; }).concat(result.pages);
8375
8682
  pages.sort(function (left, right) { return left.index - right.index; });
8683
+ // The first page response also carries the total.
8684
+ if (Number(result.pageCount) > 0) state.data.pageCount = Number(result.pageCount);
8376
8685
  patch({ data: Object.assign({}, state.data, { pages: pages }), page: index, pdfLoading: false });
8377
8686
  }).catch(function (error) {
8378
8687
  patch({ pdfLoading: false, error: messageOf(error, t, locale) });
@@ -8396,7 +8705,41 @@ function rememberShowHidden(value) {
8396
8705
  h('span', { className: 'rw-hint', style: { flex: '1 1 auto', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, title: path }, path),
8397
8706
  kind === 'markdown' ? h('button', { type: 'button', className: 'rw-btn rw-btn-sm', onClick: showPreview }, state.preview ? t('docEdit') : t('docPreview')) : null,
8398
8707
  kind === 'markdown' ? h('button', { type: 'button', className: 'rw-btn rw-btn-sm', onClick: exportPdf, disabled: state.saving }, IconDownload(12), t('exportPdf')) : null,
8399
- h('button', { type: 'button', className: 'rw-btn rw-btn-sm rw-btn-primary', onClick: save, disabled: state.saving || !state.dirty }, state.saving ? Spinner(12) : IconSave(12), state.saving ? t('saving') : t('save')));
8708
+ kind === 'pdf' || officeKind
8709
+ ? h('button', {
8710
+ type: 'button',
8711
+ className: 'rw-btn rw-btn-sm',
8712
+ onClick: function () {
8713
+ var nextMode = state.frameMode === 'render' ? 'pages' : 'render';
8714
+ patch({ frameMode: nextMode });
8715
+ if (nextMode === 'pages' && kind === 'pdf' && !(state.data && Number(state.data.pageCount) > 0)) goPdfPage(0);
8716
+ },
8717
+ }, state.frameMode === 'render' ? t('docPageView') : t('docRenderedView'))
8718
+ : null,
8719
+ (kind === 'pdf' || officeKind) && state.data
8720
+ ? h('div', { className: 'rw-inline' },
8721
+ h('button', { type: 'button', className: 'rw-btn rw-btn-sm', title: t('imageZoomOut'), onClick: function () { patch({ zoom: Math.max(0.5, Math.round(state.zoom / 1.25 * 100) / 100) }); } }, '−'),
8722
+ h('button', { type: 'button', className: 'rw-btn rw-btn-sm', title: t('imageZoomIn'), onClick: function () { patch({ zoom: Math.min(4, Math.round(state.zoom * 1.25 * 100) / 100) }); } }, '+'),
8723
+ h('button', { type: 'button', className: 'rw-btn rw-btn-sm', onClick: function () { patch({ zoom: 1 }); } }, Math.round(state.zoom * 100) + '%'))
8724
+ : null,
8725
+ officeKind && state.office && state.frameMode === 'pages'
8726
+ ? h('div', { className: 'rw-inline' },
8727
+ h('button', { type: 'button', className: 'rw-btn rw-btn-sm', disabled: state.pdfLoading || state.office.page <= 0, onClick: function () { goOfficePage(state.office.page - 1); } }, '‹'),
8728
+ h('span', { className: 'rw-hint' }, (state.office.page + 1) + ' / ' + Math.max(state.office.pageCount, 1)),
8729
+ h('button', { type: 'button', className: 'rw-btn rw-btn-sm', disabled: state.pdfLoading || state.office.page >= state.office.pageCount - 1, onClick: function () { goOfficePage(state.office.page + 1); } }, '›'))
8730
+ : null,
8731
+ kind === 'markdown' && state.preview && state.toc.length > 0
8732
+ ? h('button', {
8733
+ type: 'button',
8734
+ className: 'rw-chip-btn' + (state.tocOpen ? ' is-on' : ''),
8735
+ title: t('outline'),
8736
+ 'aria-pressed': state.tocOpen ? 'true' : 'false',
8737
+ onClick: function () { patch({ tocOpen: !state.tocOpen }); },
8738
+ }, t('outline'))
8739
+ : null,
8740
+ officeKind || kind === 'pdf'
8741
+ ? h('button', { type: 'button', className: 'rw-btn rw-btn-sm', onClick: function () { if (officeKind) loadOffice(state.office ? state.office.page : 0); else load(); }, disabled: state.loading || state.pdfLoading }, IconRefresh(13), t('reload'))
8742
+ : h('button', { type: 'button', className: 'rw-btn rw-btn-sm rw-btn-primary', onClick: save, disabled: state.saving || !state.dirty }, state.saving ? Spinner(12) : IconSave(12), state.saving ? t('saving') : t('save')));
8400
8743
 
8401
8744
  if (state.loading) {
8402
8745
  return h('div', { className: 'rw-doc' }, toolbar, h('div', { className: 'rw-editor-message' }, Spinner(14), t('loading')));
@@ -8409,12 +8752,36 @@ function rememberShowHidden(value) {
8409
8752
  }
8410
8753
 
8411
8754
  var body = null;
8755
+ // PDF and Office both arrive as a real PDF over the byte route: the
8756
+ // browser's viewer gives text selection, search and the outline for free.
8757
+ // The per-page raster view stays one click away for the old workflows.
8758
+ var framed = (kind === 'pdf' || officeKind) && state.frameMode === 'render' && state.frameUrl !== '';
8412
8759
  if (kind === 'markdown') {
8413
8760
  body = state.preview
8414
8761
  ? h('div', { className: 'rw-doc-body', ref: docBodyRef, onScroll: rememberScroll },
8415
8762
  state.previewLoading ? h('div', { className: 'rw-editor-message' }, Spinner(14), t('loading')) : null,
8416
8763
  state.html ? h('style', { 'data-rw-katex': '1', dangerouslySetInnerHTML: { __html: state.css || '' } }) : null,
8417
- state.html ? h('div', { ref: docPreviewRef, className: 'rw-doc-preview', onScroll: rememberScroll, onClick: previewLink, onAuxClick: previewAuxClick, onDragStart: previewDragStart, dangerouslySetInnerHTML: { __html: state.html } }) : null)
8764
+ state.html ? h('div', { ref: docPreviewRef, className: 'rw-doc-preview', onScroll: rememberScroll, onClick: previewLink, onAuxClick: previewAuxClick, onDragStart: previewDragStart, dangerouslySetInnerHTML: { __html: state.html } }) : null,
8765
+ state.tocOpen && state.toc.length > 0
8766
+ ? h('div', { className: 'rw-toc' },
8767
+ h('div', { className: 'rw-toc-head' },
8768
+ h('span', null, t('outline')),
8769
+ h('button', {
8770
+ type: 'button', className: 'rw-icon-btn', title: t('closeOutline'),
8771
+ onClick: function () { patch({ tocOpen: false }); },
8772
+ }, IconClose(12))),
8773
+ h('div', { className: 'rw-toc-list' }, state.toc.map(function (item) {
8774
+ return h('button', {
8775
+ key: item.id,
8776
+ type: 'button',
8777
+ className: 'rw-toc-item rw-toc-l' + item.level,
8778
+ title: item.text,
8779
+ onClick: function () {
8780
+ var target = document.getElementById(item.id);
8781
+ if (target && typeof target.scrollIntoView === 'function') target.scrollIntoView({ block: 'start', behavior: 'smooth' });
8782
+ },
8783
+ }, item.text);
8784
+ }))) : null)
8418
8785
  : h('div', { className: 'rw-doc-body', ref: docBodyRef, onScroll: rememberScroll },
8419
8786
  state.findOpen ? h('div', { className: 'rw-find-bar rw-doc-find' },
8420
8787
  h('input', {
@@ -8438,6 +8805,20 @@ function rememberShowHidden(value) {
8438
8805
  })()),
8439
8806
  h('button', { type: 'button', className: 'rw-btn rw-btn-sm', title: t('findPrev'), onClick: function () { stepDocMatch(-1); } }, h('span', { style: { display: 'inline-flex', transform: 'rotate(180deg)' } }, IconChevron(12))),
8440
8807
  h('button', { type: 'button', className: 'rw-btn rw-btn-sm', title: t('findNext'), onClick: function () { stepDocMatch(1); } }, IconChevron(12)),
8808
+ h('input', {
8809
+ className: 'rw-input',
8810
+ value: state.findReplace,
8811
+ placeholder: t('replacePlaceholder'),
8812
+ 'aria-label': t('replacePlaceholder'),
8813
+ spellCheck: false,
8814
+ onChange: function (event) { patch({ findReplace: event.currentTarget.value }); },
8815
+ onKeyDown: function (event) {
8816
+ if (event.key === 'Enter') { event.preventDefault(); replaceDocCurrent(); }
8817
+ if (event.key === 'Escape') { event.preventDefault(); closeDocFind(); }
8818
+ },
8819
+ }),
8820
+ h('button', { type: 'button', className: 'rw-btn rw-btn-sm', disabled: docMatches().length === 0, onClick: replaceDocCurrent }, t('replaceOne')),
8821
+ h('button', { type: 'button', className: 'rw-btn rw-btn-sm', disabled: docMatches().length === 0, onClick: replaceDocAll }, t('replaceAll')),
8441
8822
  h('button', { type: 'button', className: 'rw-icon-btn', title: t('close'), onClick: closeDocFind }, IconClose(12)))
8442
8823
  : null,
8443
8824
  h('textarea', {
@@ -8449,11 +8830,6 @@ function rememberShowHidden(value) {
8449
8830
  var total = state.data.pageCount || 0;
8450
8831
  var current = (state.data.pages || []).filter(function (page) { return page.index === state.page; })[0] || null;
8451
8832
  body = h('div', { className: 'rw-doc-body' },
8452
- h('div', { className: 'rw-doc-field' },
8453
- h('label', null, t('docPdfTitle')),
8454
- h('input', { className: 'rw-doc-input', style: { flex: '1 1 auto' }, value: (state.data.metadata && state.data.metadata.title) || '', onChange: function (event) { patch({ data: Object.assign({}, state.data, { metadata: Object.assign({}, state.data.metadata, { title: event.currentTarget.value }) }), dirty: true }); } }),
8455
- h('label', null, t('docPdfAuthor')),
8456
- h('input', { className: 'rw-doc-input', style: { flex: '1 1 auto' }, value: (state.data.metadata && state.data.metadata.author) || '', onChange: function (event) { patch({ data: Object.assign({}, state.data, { metadata: Object.assign({}, state.data.metadata, { author: event.currentTarget.value }) }), dirty: true }); } })),
8457
8833
  h('div', { className: 'rw-inline', style: { justifyContent: 'space-between', margin: '6px 0' } },
8458
8834
  h('div', { className: 'rw-inline' },
8459
8835
  h('button', { type: 'button', className: 'rw-btn rw-btn-sm', disabled: state.page <= 0, onClick: function () { stepPdfPage(-1); } }, '‹'),
@@ -8463,71 +8839,26 @@ function rememberShowHidden(value) {
8463
8839
  h('button', { type: 'button', className: 'rw-btn rw-btn-sm', disabled: !current, onClick: function () { var rotations = Object.assign({}, state.rotations); rotations[state.page] = ((rotations[state.page] || (current && current.rotation) || 0) + 90) % 360; patch({ rotations: rotations, dirty: true }); } }, t('docRotate')),
8464
8840
  h('button', { type: 'button', className: 'rw-btn rw-btn-sm rw-btn-danger', disabled: total <= 1, onClick: function () { var deleted = Object.assign({}, state.deleted); deleted[state.page] = true; var next = state.page + 1; while (next < total && deleted[next]) next += 1; if (next >= total) { next = state.page - 1; while (next >= 0 && deleted[next]) next -= 1; } var nextPage = next >= 0 ? next : state.page; patch({ deleted: deleted, dirty: true, page: nextPage }); if (next >= 0 && !((state.data.pages || []).some(function (page) { return page.index === next; }))) goPdfPage(next); } }, t('docDeletePage')))),
8465
8841
  state.pdfLoading ? h('div', { className: 'rw-editor-message' }, Spinner(14), t('loading')) : null,
8466
- current ? h('img', { className: 'rw-doc-pdf-page', src: current.png, style: { transform: 'rotate(' + ((state.rotations[current.index] || current.rotation || 0) % 360) + 'deg)' } }) : null);
8467
- } else if (kind === 'docx' && state.data) {
8468
- var paragraphs = state.data.paragraphs || [];
8469
- var tables = state.data.tables || [];
8470
- body = h('div', { className: 'rw-doc-body' },
8471
- paragraphs.map(function (paragraph, index) {
8472
- return h('div', { key: 'p' + index, className: 'rw-doc-block' },
8473
- h('div', { className: 'rw-doc-block-label' }, (paragraph.style || t('docParagraph')) + ' · ' + (index + 1)),
8474
- h('textarea', { value: paragraph.text || '', onChange: function (event) { updateParagraph(index, event.currentTarget.value); } }));
8475
- }),
8476
- tables.map(function (rows, tableIndex) {
8477
- return h('div', { key: 't' + tableIndex },
8478
- h('div', { className: 'rw-doc-block-label' }, t('docTable') + ' ' + (tableIndex + 1)),
8479
- h('table', { className: 'rw-doc-table' }, h('tbody', null,
8480
- rows.map(function (row, rowIndex) {
8481
- return h('tr', { key: rowIndex }, row.map(function (cell, cellIndex) {
8482
- return h('td', { key: cellIndex }, h('input', { value: cell || '', onChange: function (event) { updateTableCell(tableIndex, rowIndex, cellIndex, event.currentTarget.value); } }));
8483
- }));
8484
- }))));
8485
- }));
8486
- } else if (kind === 'xlsx' && state.data) {
8487
- var sheets = state.data.sheets || [];
8488
- var active = sheets[Math.min(state.sheet, Math.max(sheets.length - 1, 0))] || { name: '', rows: [] };
8489
- var columns = Math.max(active.maxCol || 0, 8);
8490
- var header = h('tr', null, h('th', null, ''), Array.from({ length: columns }, function (_, index) { return h('th', { key: index }, String.fromCharCode(65 + index)); }));
8491
- var gridRows = (active.rows || []).map(function (row, rowIndex) {
8492
- return h('tr', { key: rowIndex },
8493
- h('th', null, String(rowIndex + 1)),
8494
- Array.from({ length: columns }, function (_, colIndex) {
8495
- var cell = String.fromCharCode(65 + colIndex) + (rowIndex + 1);
8496
- var value = row[colIndex];
8497
- return h('td', { key: colIndex }, h('input', {
8498
- value: value === null || value === undefined ? '' : String(value),
8499
- onChange: function (event) { updateCell(active.name, cell, event.currentTarget.value); },
8500
- }));
8501
- }));
8502
- });
8503
- body = h('div', { className: 'rw-doc-body', style: { padding: 0, overflow: 'hidden' } },
8504
- h('div', { className: 'rw-doc-tabs' }, sheets.map(function (sheet, index) {
8505
- return h('button', { key: sheet.name, type: 'button', className: 'rw-doc-tab' + (index === state.sheet ? ' is-on' : ''), onClick: function () { patch({ sheet: index }); } }, sheet.name);
8506
- })),
8507
- active.truncated
8508
- ? h('div', { className: 'rw-doc-note' }, t('sheetTruncated', { rows: active.maxRow || 0, cols: active.maxCol || 0 }))
8509
- : null,
8510
- (state.data.sheetCount || sheets.length) > sheets.length
8511
- ? h('div', { className: 'rw-doc-note' }, t('sheetMore'))
8512
- : null,
8513
- h('div', { style: { flex: '1 1 auto', overflow: 'auto', padding: 8 } },
8514
- h('table', { className: 'rw-doc-grid' },
8515
- h('thead', null, header),
8516
- h('tbody', null, gridRows))));
8517
- } else if (kind === 'pptx' && state.data) {
8518
- var slides = state.data.slides || [];
8519
- var slide = slides[Math.min(state.slide, Math.max(slides.length - 1, 0))] || { texts: [] };
8520
- body = h('div', { className: 'rw-doc-body' },
8521
- h('div', { className: 'rw-inline', style: { justifyContent: 'space-between', marginBottom: 6 } },
8522
- h('div', { className: 'rw-inline' },
8523
- h('button', { type: 'button', className: 'rw-btn rw-btn-sm', disabled: state.slide <= 0, onClick: function () { patch({ slide: state.slide - 1 }); } }, '‹'),
8524
- h('span', { className: 'rw-hint' }, (state.slide + 1) + ' / ' + slides.length),
8525
- h('button', { type: 'button', className: 'rw-btn rw-btn-sm', disabled: state.slide >= slides.length - 1, onClick: function () { patch({ slide: state.slide + 1 }); } }, '›'))),
8526
- (slide.texts || []).map(function (item) {
8527
- return h('div', { key: item.shape, className: 'rw-doc-block' },
8528
- h('div', { className: 'rw-doc-block-label' }, (item.name || t('docSlide')) + ' · ' + item.shape),
8529
- h('textarea', { value: (state.pptxUpdates[state.slide + ':' + item.shape] || item).text || '', onChange: function (event) { updateSlideText(state.slide, item.shape, event.currentTarget.value); } }));
8842
+ current ? h('img', { className: 'rw-doc-pdf-page', src: current.png, style: { width: Math.round(state.zoom * 100) + '%', maxWidth: state.zoom <= 1 ? '100%' : 'none', transform: 'rotate(' + ((state.rotations[current.index] || current.rotation || 0) % 360) + 'deg)' } }) : null);
8843
+ } else if (framed) {
8844
+ // A widened frame has to be able to scroll.
8845
+ body = h('div', { className: 'rw-doc-body', style: { padding: 0, overflow: 'auto' } },
8846
+ h('iframe', {
8847
+ className: 'rw-doc-frame',
8848
+ title: basename(path),
8849
+ src: state.frameUrl,
8850
+ // The browser viewer lays out at the frame's width, so widening the
8851
+ // frame is the zoom it understands.
8852
+ style: { width: Math.round(state.zoom * 100) + '%', height: Math.round(state.zoom * 100) + '%', minWidth: '100%', minHeight: '100%' },
8530
8853
  }));
8854
+ } else if (officeKind && state.office) {
8855
+ // A rendered page is the whole point: the layout came out of LibreOffice,
8856
+ // so nothing here re-flows the document.
8857
+ body = h('div', { className: 'rw-doc-body', ref: docBodyRef, onScroll: rememberScroll },
8858
+ state.pdfLoading ? h('div', { className: 'rw-editor-message' }, Spinner(14), t('loading')) : null,
8859
+ state.office.png
8860
+ ? h('img', { className: 'rw-doc-page', alt: basename(path), src: state.office.png, style: { width: Math.round(state.zoom * 100) + '%', maxWidth: state.zoom <= 1 ? '100%' : 'none' } })
8861
+ : h('div', { className: 'rw-editor-message' }, t('docRenderEmpty')));
8531
8862
  }
8532
8863
 
8533
8864
  return h('div', { className: 'rw-doc' }, toolbar,
@@ -14751,7 +15082,8 @@ function rememberShowHidden(value) {
14751
15082
  component: function (props) {
14752
15083
  var currentLocale = useLocale(ctx);
14753
15084
  var t = useMemo(function () { return makeT(currentLocale); }, [currentLocale]);
14754
- return h(RemoteDirectoryTab, Object.assign({}, props, { ctx: ctx, t: t, locale: currentLocale, variant: 'linked' }));
15085
+ return h(TabBoundary, { t: t },
15086
+ h(RemoteDirectoryTab, Object.assign({}, props, { ctx: ctx, t: t, locale: currentLocale, variant: 'linked' })));
14755
15087
  },
14756
15088
  });
14757
15089
  if (track !== false) tabDisposers.push(function () { disposeLinkedTab(); });
@@ -14777,7 +15109,8 @@ function rememberShowHidden(value) {
14777
15109
  component: function (props) {
14778
15110
  var currentLocale = useLocale(ctx);
14779
15111
  var t = useMemo(function () { return makeT(currentLocale); }, [currentLocale]);
14780
- return h(RemoteDirectoryTab, Object.assign({}, props, { ctx: ctx, t: t, locale: currentLocale, variant: 'remote' }));
15112
+ return h(TabBoundary, { t: t },
15113
+ h(RemoteDirectoryTab, Object.assign({}, props, { ctx: ctx, t: t, locale: currentLocale, variant: 'remote' })));
14781
15114
  },
14782
15115
  });
14783
15116
  if (track !== false) tabDisposers.push(function () { disposeRemoteTab(); });