xlsx-svelte-viewer 0.1.1 → 0.2.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.
@@ -5,14 +5,16 @@
5
5
  onworkbookerror?: EditorEventHandlers['workbook-error'];
6
6
  onselectionchange?: EditorEventHandlers['selection-change'];
7
7
  ondirtychange?: EditorEventHandlers['dirty-change'];
8
+ onreadonlychange?: EditorEventHandlers['readonly-change'];
9
+ onribboncustomize?: EditorEventHandlers['ribbon-customize'];
8
10
  onready?: EditorEventHandlers['ready'];
9
11
  };
10
- let { workbook, bytes, src, fileName, readOnly = false, locale = 'en', theme = 'auto', authorName = 'Author', showToolbar = true, showFormulaBar = true, hiddenActions = [], themeColors, onworkbookchange, onworkbookerror, onselectionchange, ondirtychange, onready }: Props = $props();
12
+ let { workbook, bytes, src, fileName, readOnly = false, locale = 'en', theme = 'auto', authorName = 'Author', showToolbar = true, showFormulaBar = true, hiddenActions = [], themeColors, onworkbookchange, onworkbookerror, onselectionchange, ondirtychange, onreadonlychange, onribboncustomize, onready }: Props = $props();
11
13
  let binding: EditorBinding | undefined;
12
14
  const handle = deferredHandle(() => binding);
13
15
  function attach(host: HTMLElement, options: Props) {
14
16
  const normalized = (value: Props) => ({ ...pickEditorProps(value),
15
- ...eventOptions({ 'workbook-change': value.onworkbookchange, 'workbook-error': value.onworkbookerror, 'selection-change': value.onselectionchange, 'dirty-change': value.ondirtychange, ready: value.onready }) });
17
+ ...eventOptions({ 'workbook-change': value.onworkbookchange, 'workbook-error': value.onworkbookerror, 'selection-change': value.onselectionchange, 'dirty-change': value.ondirtychange, 'readonly-change': value.onreadonlychange, 'ribbon-customize': value.onribboncustomize, ready: value.onready }) });
16
18
  binding = mountEditor(host, normalized(options));
17
19
  return { update(next: Props) { binding?.update(normalized(next)); }, destroy() { binding?.destroy(); binding = undefined; } };
18
20
  }
@@ -28,4 +30,4 @@
28
30
  export function isDirty() { return handle.dirty; }
29
31
  export function getElement() { return binding?.element; }
30
32
  </script>
31
- <div use:attach={{ workbook, bytes, src, fileName, readOnly, locale, theme, authorName, showToolbar, showFormulaBar, hiddenActions, themeColors, onworkbookchange, onworkbookerror, onselectionchange, ondirtychange, onready }}></div>
33
+ <div use:attach={{ workbook, bytes, src, fileName, readOnly, locale, theme, authorName, showToolbar, showFormulaBar, hiddenActions, themeColors, onworkbookchange, onworkbookerror, onselectionchange, ondirtychange, onreadonlychange, onribboncustomize, onready }}></div>
package/dist/runtime.d.ts CHANGED
@@ -291,6 +291,9 @@ declare class EditorCore {
291
291
  private stopSession;
292
292
  private renderQueued;
293
293
  private lastSelection;
294
+ private readonly sheetSelections;
295
+ /** The worksheet object on screen, to notice sheets inserted, moved or deleted around it. */
296
+ private shownSheet;
294
297
  /** Automatic or manual calculation: the workbook's own mode (`calcPr calcMode`). */
295
298
  get calculation(): CalculationMode;
296
299
  constructor(host: HTMLElement);
@@ -303,6 +306,12 @@ declare class EditorCore {
303
306
  private createSession;
304
307
  private onSessionChange;
305
308
  setActiveSheet(index: number, force?: boolean): void;
309
+ /**
310
+ * After an edit that inserted, moved or deleted sheets: keep showing the same worksheet at its
311
+ * new index, or, when it was deleted, switch to the nearest visible sheet (always announcing
312
+ * `sheet-change` and restoring that sheet's selection, even when the index is unchanged).
313
+ */
314
+ private followShownSheet;
306
315
  /** Text width for the core's automatic row heights, from the grid's canvas measurer. */
307
316
  private measureText;
308
317
  /** Switches automatic or manual calculation on the live session (one undo step, saved). */
@@ -541,6 +550,10 @@ interface EditorEventOptions {
541
550
  onWorkbookError?: ((error: Error) => void) | undefined;
542
551
  onSelectionChange?: ((detail: SelectionChangeDetail) => void) | undefined;
543
552
  onDirtyChange?: ((dirty: boolean) => void) | undefined;
553
+ /** The user toggled Editing / Viewing (or `readOnly` changed); lets a controlled parent sync. */
554
+ onReadOnlyChange?: ((readOnly: boolean) => void) | undefined;
555
+ /** The user changed the shown ribbon commands (File > Options > Customize Ribbon). */
556
+ onRibbonCustomize?: ((hiddenActions: string[]) => void) | undefined;
544
557
  /** Called once, after the element is created and attached. */
545
558
  onReady?: ((element: XlsxEditorElement) => void) | undefined;
546
559
  }
@@ -550,7 +563,7 @@ interface EditorOptions extends EditorProps, EditorEventOptions {
550
563
  declare const EDITOR_PROP_KEYS: readonly ["workbook", "bytes", "src", "fileName", "readOnly", "locale", "theme", "authorName", "showToolbar", "showFormulaBar", "hiddenActions", "themeColors"];
551
564
  type EditorPropKey = (typeof EDITOR_PROP_KEYS)[number];
552
565
  /** Single source of truth for the element events every adapter surfaces. */
553
- declare const EDITOR_EVENT_NAMES: readonly ["workbook-change", "workbook-error", "selection-change", "dirty-change"];
566
+ declare const EDITOR_EVENT_NAMES: readonly ["workbook-change", "workbook-error", "selection-change", "dirty-change", "readonly-change", "ribbon-customize"];
554
567
  type EditorEventName = (typeof EDITOR_EVENT_NAMES)[number];
555
568
  /** One handler per bound event (unwrapped payload); a missing key is a compile error in every adapter. */
556
569
  interface EditorEventHandlers {
@@ -558,6 +571,8 @@ interface EditorEventHandlers {
558
571
  'workbook-error': EditorEventOptions['onWorkbookError'];
559
572
  'selection-change': EditorEventOptions['onSelectionChange'];
560
573
  'dirty-change': EditorEventOptions['onDirtyChange'];
574
+ 'readonly-change': EditorEventOptions['onReadOnlyChange'];
575
+ 'ribbon-customize': EditorEventOptions['onRibbonCustomize'];
561
576
  ready?: EditorEventOptions['onReady'];
562
577
  }
563
578
  /** Copies exactly the shared props out of a framework's props/instance object. */