@chalabi/svelte-sheets 2.0.2 → 2.0.3

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/Readme.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Ultra fast excel sheets in the browser. Hugely inspired by JExcel, built on XLSX shoulders.
4
4
 
5
- => Find a live example [Here](https://ticruz38.github.io/svelte-sheets/)
5
+ => Find a live example [Here](https://chalabi2.github.io/svelte-sheets/)
6
6
 
7
7
  ### Motivation
8
8
 
package/dist/Sheet.svelte CHANGED
@@ -84,8 +84,8 @@ let extendRaf = null;
84
84
  // implement virtual list
85
85
  export let startY = 0;
86
86
  export let startX = 0;
87
- export let endY = 0;
88
- export let endX = 0;
87
+ export let endY = 50; // Initial render batch
88
+ export let endX = 20; // Initial render batch
89
89
  // virtual list state
90
90
  let height_map = [];
91
91
  let width_map = [];
@@ -227,7 +227,7 @@ function refresh(data, viewport_height, viewport_width) {
227
227
  let scrollLeft;
228
228
  let scrollTop;
229
229
  $: (function scrollX() {
230
- if (!scrollLeft || !colElements)
230
+ if (scrollLeft === undefined || !colElements)
231
231
  return;
232
232
  // if (!scrollLeft) ;
233
233
  // horizontal scrolling
@@ -261,7 +261,7 @@ $: (function scrollX() {
261
261
  right = remaining * average_width;
262
262
  })();
263
263
  $: (function scrollY() {
264
- if (!scrollTop || !rowElements)
264
+ if (scrollTop === undefined || !rowElements)
265
265
  return;
266
266
  // vertical scrolling
267
267
  for (let v = 0; v < rowElements.length; v += 1) {
@@ -315,6 +315,53 @@ onMount(() => {
315
315
  // document.addEventListener("touchmove", jexcel.touchEndControls);
316
316
  document === null || document === void 0 ? void 0 : document.addEventListener("keydown", onKeyDown);
317
317
  document === null || document === void 0 ? void 0 : document.addEventListener("keyup", onKeyUp);
318
+ // Initialize hotkeys in browser only
319
+ hotkeys("ctrl+z, command+z", function (e) {
320
+ if (isReadOnly)
321
+ return;
322
+ e.preventDefault();
323
+ cmdz = true;
324
+ if (historyIndex == 0)
325
+ return;
326
+ historyIndex -= 1;
327
+ const res = JSON.parse(history[historyIndex]);
328
+ data = res.data;
329
+ columns = res.columns;
330
+ rows = res.rows;
331
+ style = res.style;
332
+ setTimeout((_) => (cmdz = false), 10);
333
+ });
334
+ hotkeys("ctrl+shift+z, command+shift+z", function (e) {
335
+ if (isReadOnly)
336
+ return;
337
+ console.log("redo");
338
+ e.preventDefault();
339
+ cmdz = true;
340
+ if (history.length - 1 == historyIndex)
341
+ return;
342
+ historyIndex = historyIndex + 1;
343
+ const res = JSON.parse(history[historyIndex]);
344
+ data = res.data;
345
+ columns = res.columns;
346
+ rows = res.rows;
347
+ style = res.style;
348
+ setTimeout((_) => (cmdz = false), 10);
349
+ });
350
+ hotkeys("ctrl+c, command+c, ctrl+x, command+x", function (e, handler) {
351
+ var _a;
352
+ if (isReadOnly && ((_a = handler === null || handler === void 0 ? void 0 : handler.key) === null || _a === void 0 ? void 0 : _a.includes("x")))
353
+ return;
354
+ e.preventDefault();
355
+ clipboard = JSON.stringify(selected);
356
+ });
357
+ hotkeys("ctrl+v, command+v", function (e) {
358
+ if (isReadOnly)
359
+ return;
360
+ e.preventDefault();
361
+ if (!clipboard)
362
+ return;
363
+ data = pasteSelection(data, JSON.parse(clipboard), selected);
364
+ });
318
365
  }
319
366
  });
320
367
  function onMouseDown(e) {
@@ -521,52 +568,6 @@ function onKeyUp(e) {
521
568
  // on keyup just reinitialize everything
522
569
  keypressed[e.keyCode] = false;
523
570
  }
524
- hotkeys("ctrl+z, command+z", function (e) {
525
- if (isReadOnly)
526
- return;
527
- e.preventDefault();
528
- cmdz = true;
529
- if (historyIndex == 0)
530
- return;
531
- historyIndex -= 1;
532
- const res = JSON.parse(history[historyIndex]);
533
- data = res.data;
534
- columns = res.columns;
535
- rows = res.rows;
536
- style = res.style;
537
- setTimeout((_) => (cmdz = false), 10);
538
- });
539
- hotkeys("ctrl+shift+z, command+shift+z", function (e) {
540
- if (isReadOnly)
541
- return;
542
- console.log("redo");
543
- e.preventDefault();
544
- cmdz = true;
545
- if (history.length - 1 == historyIndex)
546
- return;
547
- historyIndex = historyIndex + 1;
548
- const res = JSON.parse(history[historyIndex]);
549
- data = res.data;
550
- columns = res.columns;
551
- rows = res.rows;
552
- style = res.style;
553
- setTimeout((_) => (cmdz = false), 10);
554
- });
555
- hotkeys("ctrl+c, command+c, ctrl+x, command+x", function (e, handler) {
556
- var _a;
557
- if (isReadOnly && ((_a = handler === null || handler === void 0 ? void 0 : handler.key) === null || _a === void 0 ? void 0 : _a.includes("x")))
558
- return;
559
- e.preventDefault();
560
- clipboard = JSON.stringify(selected);
561
- });
562
- hotkeys("ctrl+v, command+v", function (e) {
563
- if (isReadOnly)
564
- return;
565
- e.preventDefault();
566
- if (!clipboard)
567
- return;
568
- data = pasteSelection(data, JSON.parse(clipboard), selected);
569
- });
570
571
  function onKeyDown(e) {
571
572
  keypressed[e.keyCode] = true;
572
573
  if (!!edition) {
@@ -634,6 +635,9 @@ $: (() => {
634
635
  }
635
636
  data = d;
636
637
  }
638
+ else if (!columns.length) {
639
+ columns = Array.from({ length: data[0].length }, () => ({}));
640
+ }
637
641
  }
638
642
  // Adjust minimal dimensions
639
643
  var j = 0;
@@ -669,8 +673,8 @@ let rowLine;
669
673
  let square;
670
674
  let squareX;
671
675
  let squareY;
672
- let topLeft;
673
- let bottomRight;
676
+ let topLeft = { c: 0, r: 0 };
677
+ let bottomRight = { c: 0, r: 0 };
674
678
  $: if (mounted) {
675
679
  if (extendRaf)
676
680
  cancelAnimationFrame(extendRaf);
@@ -864,7 +868,7 @@ function historyPush(data, rows, columns, style) {
864
868
  {/each}
865
869
  </tr>
866
870
  </thead>
867
- <tbody class="draggable" bind:this={viewport} on:scroll={handle_scroll}>
871
+ <tbody class="draggable" on:scroll={handle_scroll}>
868
872
  {#each visibleY as r}
869
873
  <tr
870
874
  class="virtual-row"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chalabi/svelte-sheets",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "Run your excel sheet in the browser!",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",