@mdzip/editor 2.5.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/view.js CHANGED
@@ -70,6 +70,20 @@ const FIND_NEXT_ICON_HTML = lucideIcon(ChevronDown, FIND_ICON_CLASS);
70
70
  const FIND_CASE_ICON_HTML = lucideIcon(CaseSensitive, FIND_ICON_CLASS);
71
71
  const FIND_CLOSE_ICON_HTML = lucideIcon(X, FIND_ICON_CLASS);
72
72
  const OUTLINE_ICON_HTML = lucideIcon(TableOfContents, TOOLBAR_ICON_CLASS);
73
+ // The outline button while the panel shows: a page with the outline's column,
74
+ // and its lines, on the side the panel is on. (Not Lucide's panel-left: that's
75
+ // the contents pane's button.)
76
+ const OUTLINE_SIDE_ICON = (side) => {
77
+ const divider = side === 'left' ? 11 : 13;
78
+ const [from, to] = side === 'left' ? [5.5, 8.5] : [15.5, 18.5];
79
+ return [
80
+ ['rect', { x: 3, y: 3, width: 18, height: 18, rx: 2 }],
81
+ ['path', { d: `M${divider} 3v18` }],
82
+ ...[8, 12, 16].map((y) => ['path', { d: `M${from} ${y}h${to - from}` }])
83
+ ];
84
+ };
85
+ const OUTLINE_LEFT_ICON_HTML = lucideIcon(OUTLINE_SIDE_ICON('left'), `${TOOLBAR_ICON_CLASS} outline-side-icon`);
86
+ const OUTLINE_RIGHT_ICON_HTML = lucideIcon(OUTLINE_SIDE_ICON('right'), `${TOOLBAR_ICON_CLASS} outline-side-icon`);
73
87
  const WHITESPACE_ICON_HTML = lucideIcon(Pilcrow, TOOLBAR_ICON_CLASS);
74
88
  const FORMAT_JSON_ICON_HTML = lucideIcon(Braces, TOOLBAR_ICON_CLASS);
75
89
  const ZOOM_ICON_HTML = lucideIcon(ZoomIn, TOOLBAR_ICON_CLASS);
@@ -238,6 +252,31 @@ function fileActionTarget(target) {
238
252
  isEntryPoint: target.isEntryPoint
239
253
  };
240
254
  }
255
+ /** A host file action's text for a file. */
256
+ function fileActionLabel(action, file) {
257
+ return typeof action.label === 'function' ? action.label(file) : action.label;
258
+ }
259
+ // What a file the preview can't show is, by extension, for its card.
260
+ const FILE_KIND_NAMES = {
261
+ docx: 'Word document', doc: 'Word document', dotx: 'Word template', dot: 'Word template',
262
+ xlsx: 'Excel workbook', xls: 'Excel workbook', pptx: 'PowerPoint presentation', ppt: 'PowerPoint presentation',
263
+ odt: 'OpenDocument text', ods: 'OpenDocument spreadsheet', odp: 'OpenDocument presentation',
264
+ pdf: 'PDF document', rtf: 'Rich Text document', epub: 'EPUB book', zip: 'ZIP archive',
265
+ drawio: 'draw.io diagram', dio: 'draw.io diagram', psd: 'Photoshop image', ai: 'Illustrator file',
266
+ mp3: 'Audio', wav: 'Audio', mp4: 'Video', mov: 'Video', webm: 'Video',
267
+ ttf: 'Font', otf: 'Font', woff: 'Font', woff2: 'Font'
268
+ };
269
+ function fileKindName(path) {
270
+ const name = path.split('/').pop() ?? path;
271
+ const dot = name.lastIndexOf('.');
272
+ if (dot <= 0)
273
+ return 'File';
274
+ const extension = name.slice(dot + 1).toLowerCase();
275
+ return FILE_KIND_NAMES[extension] ?? `${extension.toUpperCase()} file`;
276
+ }
277
+ // hydrateImages' onSettled for image batches that don't drive onAssetsHydrated
278
+ // (later lazy chunks, Copy All's drain): no progress reported for them.
279
+ const NO_SETTLE = () => { };
241
280
  const ALL_HEADINGS = [1, 2, 3, 4, 5, 6];
242
281
  const ALL_LAYOUT_CONTROLS = {
243
282
  source: true,
@@ -751,6 +790,8 @@ const NON_ARCHIVE_IMAGE_SOURCE_RE = /^(?:[a-z][a-z\d+.-]*:|\/\/|#)/i;
751
790
  // image. `.drawio.svg` and `.drawio.png` end in .svg/.png and stay images.
752
791
  const DRAWIO_PATH_RE = /\.(?:drawio|dio)$/i;
753
792
  const DRAWIO_PLACEHOLDER_CLASS = 'mdzip-drawio-placeholder';
793
+ // In place of a file the preview can't show (mountFileCard).
794
+ const FILE_CARD_CLASS = 'mdzip-file-card';
754
795
  // Preview chrome the editor adds around rendered content: removed, or
755
796
  // unwrapped (children kept), when the selection is copied as HTML.
756
797
  const PREVIEW_CHROME_REMOVE_SELECTOR = [
@@ -1305,6 +1346,9 @@ export class MdzipWorkspaceView {
1305
1346
  // Null until set by the option or a drag: the style sheet's width applies.
1306
1347
  this.outlineWidth = null;
1307
1348
  this.outlineVisible = false;
1349
+ // The outline button's clicks, one after another (see animateOutlineChange).
1350
+ this.outlineButtonTurn = Promise.resolve();
1351
+ this.outlineButtonPending = 0;
1308
1352
  this.whitespaceVisible = false;
1309
1353
  // Which parts of the edit toolbar the last render showed (renderFormattingControls).
1310
1354
  this.formattingShown = false;
@@ -2545,6 +2589,12 @@ export class MdzipWorkspaceView {
2545
2589
  this.firePreviewRendered(snapshot, generation);
2546
2590
  this.fireAssetsHydrated(snapshot, generation);
2547
2591
  }
2592
+ else if (snapshot.currentPathType === 'binary') {
2593
+ this.manifestForm = null;
2594
+ this.mountFileCard(snapshot);
2595
+ this.firePreviewRendered(snapshot, generation);
2596
+ this.fireAssetsHydrated(snapshot, generation);
2597
+ }
2548
2598
  else {
2549
2599
  this.manifestForm = null;
2550
2600
  this.elPreviewContent.innerHTML = renderMdzipPreviewHtml(snapshot);
@@ -2737,6 +2787,115 @@ export class MdzipWorkspaceView {
2737
2787
  image.replaceWith(host);
2738
2788
  return host;
2739
2789
  }
2790
+ /**
2791
+ * In place of a file the preview can't show (a Word document, a ZIP): a
2792
+ * card naming it and what it is, with a button for each host file action
2793
+ * that applies to it (the `primary` one first, such as "Open in Word"),
2794
+ * then Extract… (or Download) and, in an editable document, Replace….
2795
+ */
2796
+ mountFileCard(snapshot) {
2797
+ const doc = this.elPreviewContent.ownerDocument;
2798
+ const el = (tag, className, text) => {
2799
+ const node = doc.createElement(tag);
2800
+ if (className)
2801
+ node.className = className;
2802
+ if (text !== undefined)
2803
+ node.textContent = text;
2804
+ return node;
2805
+ };
2806
+ const path = snapshot.currentPath;
2807
+ const fileName = path.split('/').pop() ?? path;
2808
+ const target = { path, isMarkdown: false, isImage: false, isManifest: false, isEntryPoint: false };
2809
+ const card = el('div', FILE_CARD_CLASS);
2810
+ card.setAttribute('role', 'group');
2811
+ card.setAttribute('aria-label', fileName);
2812
+ const icon = el('span', `${FILE_CARD_CLASS}-icon`);
2813
+ icon.setAttribute('aria-hidden', 'true');
2814
+ icon.innerHTML = '<svg viewBox="0 0 24 24" width="32" height="32" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round">'
2815
+ + '<path d="M14 2.5H6.5a2 2 0 0 0-2 2v15a2 2 0 0 0 2 2h11a2 2 0 0 0 2-2V8z"/><path d="M14 2.5V8h5.5"/></svg>';
2816
+ const body = el('div', `${FILE_CARD_CLASS}-body`);
2817
+ body.append(el('strong', `${FILE_CARD_CLASS}-title`, fileName), el('span', `${FILE_CARD_CLASS}-file`, `${fileKindName(path)} · ${path}`), el('span', `${FILE_CARD_CLASS}-text`, "The preview can't show this kind of file."));
2818
+ const note = this.options.fileNote?.(target) ?? null;
2819
+ if (note) {
2820
+ const noteEl = el('span', `${FILE_CARD_CLASS}-note`, note);
2821
+ noteEl.setAttribute('role', 'status');
2822
+ body.append(noteEl);
2823
+ }
2824
+ const row = el('div', `${FILE_CARD_CLASS}-actions`);
2825
+ // What each button does, listed under them in the same order.
2826
+ const explained = [];
2827
+ const addButton = (label, run, primary = false, action = '', description = '') => {
2828
+ if (description)
2829
+ explained.push([label, description]);
2830
+ const button = el('button', `${FILE_CARD_CLASS}-action${primary ? ` ${FILE_CARD_CLASS}-primary` : ''}`, label);
2831
+ button.type = 'button';
2832
+ if (action)
2833
+ button.dataset['fileCardAction'] = action;
2834
+ button.addEventListener('click', () => {
2835
+ void Promise.resolve()
2836
+ .then(run)
2837
+ .catch((error) => this.options.onFailed?.(error));
2838
+ });
2839
+ row.append(button);
2840
+ };
2841
+ const hostActions = (this.options.hostFileActions ?? [])
2842
+ .filter((item) => item.appliesTo?.(target) ?? true)
2843
+ .sort((a, b) => Number(!!b.primary) - Number(!!a.primary));
2844
+ for (const action of hostActions) {
2845
+ const description = typeof action.description === 'function' ? action.description(target) : (action.description ?? '');
2846
+ addButton(fileActionLabel(action, target), () => action.run(target), !!action.primary, `${HOST_FILE_ACTION_PREFIX}${action.id}`, description);
2847
+ }
2848
+ const navTarget = { kind: 'file', orphaned: false, ...target };
2849
+ for (const item of this.extractMenuItems('one', false)) {
2850
+ addButton(item.label, () => item.action === 'download'
2851
+ ? this.downloadArchiveFile(path)
2852
+ : this.extractNavTarget(navTarget, item.action), false, item.action, item.action === 'download'
2853
+ ? "Downloads a copy of the file. The document isn't changed."
2854
+ : "Saves a copy of the file outside the document, to open or change in another app. The document isn't changed.");
2855
+ }
2856
+ if (this.allowFileActions(snapshot)) {
2857
+ addButton('Replace…', () => {
2858
+ this.pendingReplacePath = path;
2859
+ this.elReplaceInput.click();
2860
+ }, false, 'replace', `Puts a file you choose in its place, still named ${fileName}. Save the document to keep it.`);
2861
+ }
2862
+ body.append(row);
2863
+ if (explained.length) {
2864
+ const list = el('ul', `${FILE_CARD_CLASS}-explain`);
2865
+ for (const [label, description] of explained) {
2866
+ const item = el('li', '');
2867
+ item.append(el('strong', '', label), doc.createTextNode(` ${description}`));
2868
+ list.append(item);
2869
+ }
2870
+ body.append(list);
2871
+ }
2872
+ const help = this.options.fileCardHelp;
2873
+ if (help) {
2874
+ const link = el('button', `${FILE_CARD_CLASS}-help`, help.label);
2875
+ link.type = 'button';
2876
+ link.addEventListener('click', () => {
2877
+ void Promise.resolve()
2878
+ .then(() => help.run(target))
2879
+ .catch((error) => this.options.onFailed?.(error));
2880
+ });
2881
+ body.append(link);
2882
+ }
2883
+ card.append(icon, body);
2884
+ this.elPreviewContent.replaceChildren(card);
2885
+ }
2886
+ /**
2887
+ * Asks the host's file actions and {@link MdzipWorkspaceViewOptions.fileNote}
2888
+ * again, for the card of a file the preview can't show: call it when a
2889
+ * label or note would now be different (the file was opened in another
2890
+ * app, or the app that opens it is now known). The contents pane's menu
2891
+ * asks each time it opens.
2892
+ */
2893
+ refreshFileActions() {
2894
+ const snapshot = this.workspace?.snapshot();
2895
+ if (snapshot?.currentPathType === 'binary' && this.elPreviewContent.querySelector(`.${FILE_CARD_CLASS}`)) {
2896
+ this.mountFileCard(snapshot);
2897
+ }
2898
+ }
2740
2899
  /**
2741
2900
  * Replaces an image of a raw draw.io diagram (`.drawio`, `.dio`) with a card
2742
2901
  * saying what it is, why the preview can't draw it yet (#59) and how to show
@@ -2776,7 +2935,7 @@ export class MdzipWorkspaceView {
2776
2935
  if (actions.length) {
2777
2936
  const row = el('span', `${DRAWIO_PLACEHOLDER_CLASS}-actions`);
2778
2937
  for (const action of actions) {
2779
- const button = el('button', `${DRAWIO_PLACEHOLDER_CLASS}-action`, action.label);
2938
+ const button = el('button', `${DRAWIO_PLACEHOLDER_CLASS}-action`, fileActionLabel(action, target));
2780
2939
  button.type = 'button';
2781
2940
  button.addEventListener('click', () => {
2782
2941
  void Promise.resolve()
@@ -2879,12 +3038,27 @@ export class MdzipWorkspaceView {
2879
3038
  }
2880
3039
  const document = this.elPreviewContent.ownerDocument;
2881
3040
  let remaining = pending.length;
3041
+ // Progress only for the batch that drives onAssetsHydrated (a later lazy
3042
+ // chunk's images pass a no-op onSettled; see the doc comment above).
3043
+ const reportsProgress = onSettled !== NO_SETTLE;
3044
+ const progress = () => {
3045
+ if (!reportsProgress || generation !== this.previewGeneration)
3046
+ return;
3047
+ try {
3048
+ this.options.onAssetsProgress?.({ loaded: pending.length - remaining, total: pending.length });
3049
+ }
3050
+ catch (error) {
3051
+ this.options.onFailed?.(error);
3052
+ }
3053
+ };
2882
3054
  const settle = () => {
2883
3055
  remaining -= 1;
3056
+ progress();
2884
3057
  if (remaining === 0) {
2885
3058
  onSettled();
2886
3059
  }
2887
3060
  };
3061
+ progress();
2888
3062
  const createImageSlot = (image) => {
2889
3063
  const slot = document.createElement('span');
2890
3064
  slot.className = animateImageHydration
@@ -2961,6 +3135,26 @@ export class MdzipWorkspaceView {
2961
3135
  }
2962
3136
  return;
2963
3137
  }
3138
+ // eagerImages: every image now, not as it nears the visible area; still
3139
+ // a few at a time per frame, as below, so a long document stays responsive.
3140
+ if (this.options.eagerImages === true) {
3141
+ let next = 0;
3142
+ const hydrateChunk = () => {
3143
+ if (generation !== this.previewGeneration || context.signal.aborted)
3144
+ return;
3145
+ const chunkStart = observerWindow.performance.now();
3146
+ while (next < pending.length && observerWindow.performance.now() - chunkStart < 8) {
3147
+ const item = pending[next];
3148
+ next += 1;
3149
+ hydrate(item.image, createImageSlot(item.image), item.source);
3150
+ }
3151
+ if (next < pending.length) {
3152
+ observerWindow.requestAnimationFrame(hydrateChunk);
3153
+ }
3154
+ };
3155
+ hydrateChunk();
3156
+ return;
3157
+ }
2964
3158
  const bySlot = new Map();
2965
3159
  const observer = new observerWindow.IntersectionObserver((entries) => {
2966
3160
  for (const entry of entries) {
@@ -3514,7 +3708,7 @@ export class MdzipWorkspaceView {
3514
3708
  this.chunkedRenderState.mounting = true;
3515
3709
  liveContext = this.chunkedRenderState.context;
3516
3710
  }
3517
- void this.mountChunkBatch(records, nextCursor, liveContext, generation, animateImageHydration, () => { })
3711
+ void this.mountChunkBatch(records, nextCursor, liveContext, generation, animateImageHydration, NO_SETTLE)
3518
3712
  .then((newCursor) => {
3519
3713
  // Record whatever this batch actually mounted regardless of
3520
3714
  // whether a newer edit has since landed — recordChunkProgress's
@@ -4267,8 +4461,7 @@ export class MdzipWorkspaceView {
4267
4461
  this.elSearchBtn.setAttribute('aria-label', findLabel);
4268
4462
  this.elWhitespaceBtn.setAttribute('aria-pressed', String(this.whitespaceVisible));
4269
4463
  this.elOutlineBtn.hidden = !showOutlineControl;
4270
- this.elOutlineBtn.classList.toggle('active', this.outlineVisible);
4271
- this.elOutlineBtn.setAttribute('aria-pressed', String(this.outlineVisible));
4464
+ this.syncOutlineButton();
4272
4465
  this.elZoomBtn.hidden = !showZoomControl;
4273
4466
  this.elWidthControls.hidden = !showWidthControl;
4274
4467
  this.elThemeControls.hidden = !showColorSchemeControl;
@@ -4731,9 +4924,32 @@ export class MdzipWorkspaceView {
4731
4924
  this.closeFind();
4732
4925
  }
4733
4926
  });
4927
+ // Off, then on the left, then on the right, then off again. Clicks in
4928
+ // quick succession each take their turn, so none is lost mid-animation.
4929
+ // (Without animation the change is done when the click returns.)
4734
4930
  this.elOutlineBtn.addEventListener('click', () => {
4735
- this.setOutlineVisible(!this.outlineVisible);
4736
- this.options.onOutlineVisibilityChanged?.(this.outlineVisible);
4931
+ const change = () => {
4932
+ if (!this.outlineVisible) {
4933
+ this.setOutlineSideFromButton('left');
4934
+ this.setOutlineVisible(true);
4935
+ this.options.onOutlineVisibilityChanged?.(true);
4936
+ }
4937
+ else if (this.outlinePosition === 'left') {
4938
+ this.setOutlineSideFromButton('right');
4939
+ }
4940
+ else {
4941
+ this.setOutlineVisible(false);
4942
+ this.options.onOutlineVisibilityChanged?.(false);
4943
+ }
4944
+ };
4945
+ if (this.outlineButtonPending === 0 && !this.canAnimateOutline()) {
4946
+ change();
4947
+ return;
4948
+ }
4949
+ const turn = () => this.animateOutlineChange(change).catch(() => { });
4950
+ this.outlineButtonPending += 1;
4951
+ const started = this.outlineButtonPending > 1 ? this.outlineButtonTurn.then(turn) : turn();
4952
+ this.outlineButtonTurn = started.finally(() => { this.outlineButtonPending -= 1; });
4737
4953
  });
4738
4954
  this.elFormatJsonBtn.addEventListener('click', () => {
4739
4955
  this.formatJson();
@@ -5513,10 +5729,70 @@ export class MdzipWorkspaceView {
5513
5729
  get outlineSide() {
5514
5730
  return this.outlinePosition;
5515
5731
  }
5516
- /** Puts the outline panel on the left or the right of the document. */
5732
+ /** Puts the outline panel on the left or the right of the document (without calling `onOutlinePositionChanged`). */
5517
5733
  setOutlinePosition(position) {
5518
5734
  this.outlinePosition = position === 'left' ? 'left' : 'right';
5519
5735
  this.syncOutlineGeometry();
5736
+ this.syncOutlineButton();
5737
+ }
5738
+ setOutlineSideFromButton(position) {
5739
+ if (this.outlinePosition === position) {
5740
+ return;
5741
+ }
5742
+ this.setOutlinePosition(position);
5743
+ this.options.onOutlinePositionChanged?.(position);
5744
+ }
5745
+ /**
5746
+ * Runs `change` (which shows, hides or moves the outline panel) with
5747
+ * movement instead of a jump: the panel slides out toward its side and
5748
+ * fades, the document glides to where it now sits, and the panel slides in
5749
+ * on its new side. The layout changes once, in the middle, so a long
5750
+ * document isn't laid out again on every frame. Instant when the system
5751
+ * asks for reduced motion, or where elements can't animate.
5752
+ */
5753
+ canAnimateOutline() {
5754
+ return typeof this.elOutlinePane.animate === 'function' && !this.prefersReducedMotion();
5755
+ }
5756
+ async animateOutlineChange(change) {
5757
+ const pane = this.elOutlinePane;
5758
+ const stack = this.elPaneStack;
5759
+ if (!this.canAnimateOutline()) {
5760
+ change();
5761
+ return;
5762
+ }
5763
+ const away = () => (this.outlinePosition === 'left' ? -16 : 16);
5764
+ // The slide-out holds its last frame until the change is made, so the
5765
+ // panel can't flash back in between.
5766
+ let out = null;
5767
+ if (!pane.hidden) {
5768
+ out = pane.animate([{ opacity: 1, transform: 'translateX(0)' }, { opacity: 0, transform: `translateX(${away()}px)` }], { duration: 120, easing: 'ease-in', fill: 'forwards' });
5769
+ await out.finished;
5770
+ }
5771
+ const before = stack.getBoundingClientRect().left;
5772
+ change();
5773
+ const dx = before - stack.getBoundingClientRect().left;
5774
+ const moves = [];
5775
+ if (Math.abs(dx) >= 1) {
5776
+ moves.push(stack.animate([{ transform: `translateX(${dx}px)` }, { transform: 'translateX(0)' }], { duration: 220, easing: 'cubic-bezier(0.2, 0.8, 0.2, 1)' }).finished);
5777
+ }
5778
+ if (!pane.hidden) {
5779
+ moves.push(pane.animate([{ opacity: 0, transform: `translateX(${away()}px)` }, { opacity: 1, transform: 'translateX(0)' }], { duration: 200, delay: 40, easing: 'ease-out', fill: 'backwards' }).finished);
5780
+ }
5781
+ out?.cancel();
5782
+ await Promise.all(moves);
5783
+ }
5784
+ // The button cycles off, left, right; its icon shows where the panel is, and
5785
+ // its tooltip says what a click does next.
5786
+ syncOutlineButton() {
5787
+ const state = !this.outlineVisible ? 'off' : this.outlinePosition;
5788
+ if (this.elOutlineBtn.dataset['outlineState'] !== state) {
5789
+ this.elOutlineBtn.dataset['outlineState'] = state;
5790
+ this.elOutlineBtn.innerHTML = state === 'off' ? OUTLINE_ICON_HTML : state === 'left' ? OUTLINE_LEFT_ICON_HTML : OUTLINE_RIGHT_ICON_HTML;
5791
+ }
5792
+ const next = !this.outlineVisible ? 'show on the left' : this.outlinePosition === 'left' ? 'move to the right' : 'hide';
5793
+ this.elOutlineBtn.classList.toggle('active', this.outlineVisible);
5794
+ this.elOutlineBtn.setAttribute('aria-pressed', String(this.outlineVisible));
5795
+ setTooltip(this.elOutlineBtn, `Outline: ${next}`);
5520
5796
  }
5521
5797
  /** The outline panel's width in pixels, as last set or dragged; null while the style sheet's width applies. */
5522
5798
  get outlinePaneWidth() {
@@ -5760,9 +6036,14 @@ export class MdzipWorkspaceView {
5760
6036
  }
5761
6037
  return true;
5762
6038
  }
6039
+ // The pane's scrollTop that puts `target` at the top, less its
6040
+ // scroll-margin-top (preview headings have one), so a heading gone to stops
6041
+ // a little below the top, as scrollIntoView() would leave it.
5763
6042
  paneTopOf(target) {
5764
6043
  const pane = this.elPreviewPane;
5765
- return pane.scrollTop + target.getBoundingClientRect().top - pane.getBoundingClientRect().top;
6044
+ const style = target.ownerDocument.defaultView?.getComputedStyle(target);
6045
+ const margin = Number.parseFloat(style?.scrollMarginTop ?? '') || 0;
6046
+ return Math.max(0, pane.scrollTop + target.getBoundingClientRect().top - pane.getBoundingClientRect().top - margin);
5766
6047
  }
5767
6048
  scrollPaneToElement(target) {
5768
6049
  this.elPreviewPane.scrollTop = this.paneTopOf(target);
@@ -7653,7 +7934,7 @@ export class MdzipWorkspaceView {
7653
7934
  this.chunkedRenderState.mounting = false;
7654
7935
  }
7655
7936
  if (generation === this.previewGeneration && !context.signal.aborted) {
7656
- this.hydrateImages(allPending, context, generation, animateImageHydration, () => { });
7937
+ this.hydrateImages(allPending, context, generation, animateImageHydration, NO_SETTLE);
7657
7938
  }
7658
7939
  }
7659
7940
  }
@@ -8215,6 +8496,15 @@ export class MdzipWorkspaceView {
8215
8496
  this.options.onColorSchemeChanged?.(this.colorScheme);
8216
8497
  }
8217
8498
  }
8499
+ /** The layout showing: `'source'` (Edit), `'split'` or `'preview'` (View). */
8500
+ get layoutMode() {
8501
+ return this.layout;
8502
+ }
8503
+ /**
8504
+ * Switches to Edit (`'source'`), Split or View (`'preview'`), as the
8505
+ * toolbar's buttons do, for example to show an imported document in View.
8506
+ * A file that can't be shown that way gets the nearest layout it can.
8507
+ */
8218
8508
  async setLayout(requested) {
8219
8509
  const snapshot = this.workspace?.snapshot();
8220
8510
  this.layout = snapshot ? this.validLayoutForSnapshot(requested, snapshot) : requested;
@@ -8361,7 +8651,7 @@ export class MdzipWorkspaceView {
8361
8651
  const file = fileActionTarget(target);
8362
8652
  return (this.options.hostFileActions ?? [])
8363
8653
  .filter((item) => item.appliesTo?.(file) ?? true)
8364
- .map((item) => ({ action: `${HOST_FILE_ACTION_PREFIX}${item.id}`, label: item.label }));
8654
+ .map((item) => ({ action: `${HOST_FILE_ACTION_PREFIX}${item.id}`, label: fileActionLabel(item, file) }));
8365
8655
  }
8366
8656
  async handleNavMenuAction(action) {
8367
8657
  const state = this.contextMenuState;
@@ -9054,6 +9344,9 @@ export class MdzipWorkspaceView {
9054
9344
  });
9055
9345
  this.elPreviewContent.replaceChildren(this.manifestForm.root);
9056
9346
  }
9347
+ // Edit as JSON only with a way back to the form: the toolbar's View button.
9348
+ // (In Split, where the JSON is beside the form, the CSS hides it anyway.)
9349
+ this.manifestForm.setEditJsonAvailable(this.controlPolicy.layout.preview);
9057
9350
  const validity = workspace.validateJsonText(snapshot.currentPath, snapshot.currentText);
9058
9351
  this.manifestForm.update(validity);
9059
9352
  this.setJsonValidity(validity, snapshot.currentPath);