@chalabi/svelte-sheets 2.0.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.
@@ -0,0 +1,42 @@
1
+ import type { Config } from "./defaultconfig.js";
2
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
3
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
4
+ $$bindings?: Bindings;
5
+ } & Exports;
6
+ (internal: unknown, props: Props & {
7
+ $$events?: Events;
8
+ $$slots?: Slots;
9
+ }): Exports & {
10
+ $set?: any;
11
+ $on?: any;
12
+ };
13
+ z_$$bindings?: Bindings;
14
+ }
15
+ declare const Sheet: $$__sveltets_2_IsomorphicComponent<{
16
+ [x: string]: any;
17
+ data?: (string | number | boolean)[][];
18
+ columns?: any[];
19
+ rows?: any[];
20
+ mergeCells?: Record<string, number[]>;
21
+ style?: {
22
+ [cellIndex: string]: string;
23
+ };
24
+ selected?: [string, string];
25
+ extended?: [string, string];
26
+ currentValue?: string | number | boolean;
27
+ clipboard: [string, string];
28
+ options: Config;
29
+ className?: string;
30
+ theme?: "light" | "dark" | string;
31
+ startY?: number;
32
+ startX?: number;
33
+ endY?: number;
34
+ endX?: number;
35
+ onInputChange?: (value: any, row: any, column: any) => void;
36
+ }, {
37
+ [evt: string]: CustomEvent<any>;
38
+ }, {}, {
39
+ onInputChange: (value: any, row: any, column: any) => void;
40
+ }, string>;
41
+ type Sheet = InstanceType<typeof Sheet>;
42
+ export default Sheet;
@@ -0,0 +1,69 @@
1
+ <script lang="ts">import XLSX from "xlsx";
2
+ import { convert } from "./convert.js";
3
+ export let sheetNames;
4
+ export let sheets = [];
5
+ export let active = 0;
6
+ // declare all possible table object
7
+ let fileinput;
8
+ let files;
9
+ $: files && files[0] && reader && reader.readAsArrayBuffer(files[0]);
10
+ let reader;
11
+ if (FileReader != undefined) {
12
+ reader = new FileReader();
13
+ reader.onload = () => {
14
+ sheets = [];
15
+ active = 0;
16
+ const wb = XLSX.read(new Uint8Array(reader.result), {
17
+ type: "array",
18
+ cellFormula: true,
19
+ cellStyles: true,
20
+ });
21
+ sheets = convert(wb);
22
+ sheetNames = sheets.map((s) => s.sheetName);
23
+ };
24
+ }
25
+ </script>
26
+
27
+ <input
28
+ type="file"
29
+ class="hidden"
30
+ name="file"
31
+ bind:this={fileinput}
32
+ bind:files
33
+ />
34
+
35
+ <div class="flex">
36
+ <button on:click={(_) => fileinput.click()}>Open XLSX file</button>
37
+ {#each sheetNames as sn, i}
38
+ <div
39
+ on:click={(_) => {
40
+ active = i;
41
+ }}
42
+ class={"ml-4 cursor-pointer " + (i == active ? "active" : "")}
43
+ >
44
+ {sn}
45
+ </div>
46
+ {/each}
47
+ </div>
48
+
49
+ <style>
50
+ .hidden {
51
+ height: 0;
52
+ width: 0;
53
+ opacity: 0;
54
+ }
55
+ .active {
56
+ border-bottom: 1px solid teal;
57
+ }
58
+ .flex {
59
+ display: flex;
60
+ justify-content: center;
61
+ align-items: center;
62
+ }
63
+ .ml-4 {
64
+ margin-left: 1rem;
65
+ }
66
+ .cursor-pointer {
67
+ cursor: pointer;
68
+ }
69
+ </style>
@@ -0,0 +1,22 @@
1
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
2
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
3
+ $$bindings?: Bindings;
4
+ } & Exports;
5
+ (internal: unknown, props: Props & {
6
+ $$events?: Events;
7
+ $$slots?: Slots;
8
+ }): Exports & {
9
+ $set?: any;
10
+ $on?: any;
11
+ };
12
+ z_$$bindings?: Bindings;
13
+ }
14
+ declare const Toolbar: $$__sveltets_2_IsomorphicComponent<{
15
+ sheetNames: any;
16
+ sheets?: any[];
17
+ active?: number;
18
+ }, {
19
+ [evt: string]: CustomEvent<any>;
20
+ }, {}, {}, string>;
21
+ type Toolbar = InstanceType<typeof Toolbar>;
22
+ export default Toolbar;
@@ -0,0 +1 @@
1
+ export declare function copypaste(node: any): void;
@@ -0,0 +1,24 @@
1
+ // copy-paste action (also support cut)
2
+ export function copypaste(node) {
3
+ const keyPressed = {};
4
+ function onKeyDown(e) {
5
+ keyPressed[e.keyCode] = true;
6
+ if (keyPressed[91] && keyPressed[88]) {
7
+ e.preventDefault();
8
+ node.dispatchEvent(new CustomEvent("cut"));
9
+ }
10
+ if (keyPressed[91] && keyPressed[88]) {
11
+ e.preventDefault();
12
+ node.dispatchEvent(new CustomEvent("paste"));
13
+ }
14
+ if (keyPressed[91] && keyPressed[88]) {
15
+ e.preventDefault();
16
+ node.dispatchEvent(new CustomEvent("copy"));
17
+ }
18
+ }
19
+ function onKeyUp(e) {
20
+ keyPressed[e.keyCode] = false;
21
+ }
22
+ node.addEventListener("keydown", onKeyDown);
23
+ node.addEventListener("keyup", onKeyUp);
24
+ }
@@ -0,0 +1,3 @@
1
+ export declare function draggable(node: any): {
2
+ destroy(): void;
3
+ };
@@ -0,0 +1,37 @@
1
+ export function draggable(node) {
2
+ let x;
3
+ let y;
4
+ function handleMousedown(event) {
5
+ x = event.clientX;
6
+ y = event.clientY;
7
+ node.dispatchEvent(new CustomEvent("dragging", {
8
+ detail: { x: 0, y: 0 },
9
+ }));
10
+ window.addEventListener("mousemove", handleMousemove);
11
+ window.addEventListener("mouseup", handleMouseup);
12
+ }
13
+ function handleMousemove(event) {
14
+ const dx = event.clientX - x;
15
+ const dy = event.clientY - y;
16
+ // x = event.clientX;
17
+ // y = event.clientY;
18
+ node.dispatchEvent(new CustomEvent("dragging", {
19
+ detail: { x: dx, y: dy },
20
+ }));
21
+ }
22
+ function handleMouseup(event) {
23
+ const dx = event.clientX - x;
24
+ const dy = event.clientY - y;
25
+ node.dispatchEvent(new CustomEvent("dragging", {
26
+ detail: { x: dx, y: dy },
27
+ }));
28
+ window.removeEventListener("mousemove", handleMousemove);
29
+ window.removeEventListener("mouseup", handleMouseup);
30
+ }
31
+ node.addEventListener("mousedown", handleMousedown);
32
+ return {
33
+ destroy() {
34
+ node.removeEventListener("mousedown", handleMousedown);
35
+ },
36
+ };
37
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./copypaste.js";
2
+ export * from "./draggable.js";
3
+ export * from "./resizable.js";
4
+ export * from "./rightclick.js";
5
+ export * from "./selected.js";
@@ -0,0 +1,5 @@
1
+ export * from "./copypaste.js";
2
+ export * from "./draggable.js";
3
+ export * from "./resizable.js";
4
+ export * from "./rightclick.js";
5
+ export * from "./selected.js";
@@ -0,0 +1,3 @@
1
+ export declare function resizable(node: any): {
2
+ destroy(): void;
3
+ };
@@ -0,0 +1,37 @@
1
+ export function resizable(node) {
2
+ let x;
3
+ let y;
4
+ function handleMousedown(event) {
5
+ x = event.clientX;
6
+ y = event.clientY;
7
+ node.dispatchEvent(new CustomEvent("resizing", {
8
+ detail: { x: 0, y: 0 },
9
+ }));
10
+ window.addEventListener("mousemove", handleMousemove);
11
+ window.addEventListener("mouseup", handleMouseup);
12
+ }
13
+ function handleMousemove(event) {
14
+ const dx = event.clientX - x;
15
+ const dy = event.clientY - y;
16
+ x = event.clientX;
17
+ y = event.clientY;
18
+ node.dispatchEvent(new CustomEvent("resizing", {
19
+ detail: { x: dx, y: dy },
20
+ }));
21
+ }
22
+ function handleMouseup(event) {
23
+ const dx = event.clientX - x;
24
+ const dy = event.clientY - y;
25
+ node.dispatchEvent(new CustomEvent("resizing", {
26
+ detail: { x: dx, y: dy },
27
+ }));
28
+ window.removeEventListener("mousemove", handleMousemove);
29
+ window.removeEventListener("mouseup", handleMouseup);
30
+ }
31
+ node.addEventListener("mousedown", handleMousedown);
32
+ return {
33
+ destroy() {
34
+ node.removeEventListener("mousedown", handleMousedown);
35
+ },
36
+ };
37
+ }
@@ -0,0 +1 @@
1
+ export declare function rightclick(node: any): void;
@@ -0,0 +1 @@
1
+ export function rightclick(node) { }
@@ -0,0 +1,5 @@
1
+ export declare function selection(node: any, { selection, rows, columns }: {
2
+ selection: any;
3
+ rows: any;
4
+ columns: any;
5
+ }): void;
@@ -0,0 +1,10 @@
1
+ import XLSX from "xlsx";
2
+ export function selection(node, { selection, rows, columns }) {
3
+ const viewport = node.getBoundingClientRect();
4
+ const topleft = XLSX.utils.decode_cell(selection[0]);
5
+ const bottomRight = XLSX.utils.decode_cell(selection[1]);
6
+ const top = node.getElementByClassName(".top");
7
+ const bottom = node.getElementByClassName(".bottom");
8
+ const left = node.getElementByClassName(".left");
9
+ const right = node.getElementByClassName(".right");
10
+ }
@@ -0,0 +1,16 @@
1
+ export declare function getColumnName(i: any): string;
2
+ /**
3
+ * Convert jexcel id to excel like column name
4
+ *
5
+ * @param string id
6
+ * @return string id
7
+ */
8
+ export declare function getColumnNameFromId(cellId: any): string;
9
+ /**
10
+ * Convert excel like column to jexcel id
11
+ *
12
+ * @param string id
13
+ * @return string id
14
+ */
15
+ export declare function getIdFromColumnName(id: any, arr: any): any;
16
+ export declare function convert(workbook: any): any[];
@@ -0,0 +1,164 @@
1
+ export function getColumnName(i) {
2
+ var letter = "";
3
+ if (i > 701) {
4
+ letter += String.fromCharCode(64 + parseInt(i / 676));
5
+ letter += String.fromCharCode(64 + parseInt((i % 676) / 26));
6
+ }
7
+ else if (i > 25) {
8
+ letter += String.fromCharCode(64 + parseInt(i / 26));
9
+ }
10
+ letter += String.fromCharCode(65 + (i % 26));
11
+ return letter;
12
+ }
13
+ /**
14
+ * Convert jexcel id to excel like column name
15
+ *
16
+ * @param string id
17
+ * @return string id
18
+ */
19
+ export function getColumnNameFromId(cellId) {
20
+ if (!Array.isArray(cellId)) {
21
+ cellId = cellId.split("-");
22
+ }
23
+ return getColumnName(parseInt(cellId[0])) + (parseInt(cellId[1]) + 1);
24
+ }
25
+ /**
26
+ * Convert excel like column to jexcel id
27
+ *
28
+ * @param string id
29
+ * @return string id
30
+ */
31
+ export function getIdFromColumnName(id, arr) {
32
+ // Get the letters
33
+ var t = /^[a-zA-Z]+/.exec(id);
34
+ if (t) {
35
+ // Base 26 calculation
36
+ var code = 0;
37
+ for (var i = 0; i < t[0].length; i++) {
38
+ code +=
39
+ parseInt(t[0].charCodeAt(i) - 64) * Math.pow(26, t[0].length - 1 - i);
40
+ }
41
+ code--;
42
+ // Make sure jexcel starts on zero
43
+ if (code < 0) {
44
+ code = 0;
45
+ }
46
+ // Number
47
+ var number = parseInt(/[0-9]+$/.exec(id));
48
+ if (number > 0) {
49
+ number--;
50
+ }
51
+ if (arr == true) {
52
+ id = [code, number];
53
+ }
54
+ else {
55
+ id = code + "-" + number;
56
+ }
57
+ }
58
+ return id;
59
+ }
60
+ export function convert(workbook) {
61
+ var spreadsheets = [];
62
+ workbook.SheetNames.forEach(function (sheetName) {
63
+ var spreadsheet = {
64
+ rows: [],
65
+ columns: [],
66
+ data: [],
67
+ style: {},
68
+ sheetName: sheetName,
69
+ mergeCells: [],
70
+ };
71
+ // Column widths
72
+ var temp = workbook.Sheets[sheetName]["!cols"];
73
+ if (temp && temp.length) {
74
+ for (var i = 0; i < temp.length; i++) {
75
+ spreadsheet.columns[i] = {};
76
+ if (temp[i] && temp[i].wpx) {
77
+ spreadsheet.columns[i].width = temp[i].wpx + "px";
78
+ }
79
+ }
80
+ }
81
+ // Rows heights
82
+ var temp = workbook.Sheets[sheetName]["!rows"];
83
+ if (temp && temp.length) {
84
+ for (var i = 0; i < temp.length; i++) {
85
+ if (temp[i] && temp[i].hpx) {
86
+ spreadsheet.rows[i] = {};
87
+ spreadsheet.rows[i].height = temp[i].hpx + "px";
88
+ }
89
+ }
90
+ }
91
+ // Merge cells
92
+ var temp = workbook.Sheets[sheetName]["!merges"];
93
+ if (temp && temp.length > 0) {
94
+ for (var i = 0; i < temp.length; i++) {
95
+ var x1 = temp[i].s.c;
96
+ var y1 = temp[i].s.r;
97
+ var x2 = temp[i].e.c;
98
+ var y2 = temp[i].e.r;
99
+ var key = getColumnNameFromId([x1, y1]);
100
+ spreadsheet.mergeCells[key] = [x2 - x1 + 1, y2 - y1 + 1];
101
+ }
102
+ }
103
+ // Data container
104
+ var max_x = 0;
105
+ var max_y = 0;
106
+ var temp = Object.keys(workbook.Sheets[sheetName]);
107
+ for (var i = 0; i < temp.length; i++) {
108
+ if (temp[i].substr(0, 1) != "!") {
109
+ var cell = workbook.Sheets[sheetName][temp[i]];
110
+ var info = getIdFromColumnName(temp[i], true);
111
+ if (!spreadsheet.data[info[1]]) {
112
+ spreadsheet.data[info[1]] = [];
113
+ }
114
+ spreadsheet.data[info[1]][info[0]] = cell.f ? "=" + cell.f : cell.w;
115
+ if (max_x < info[0]) {
116
+ max_x = info[0];
117
+ }
118
+ if (max_y < info[1]) {
119
+ max_y = info[1];
120
+ }
121
+ // Style
122
+ if (cell.style && Object.keys(cell.style).length > 0) {
123
+ spreadsheet.style[temp[i]] = cell.style;
124
+ }
125
+ if (cell.s && cell.s.fgColor) {
126
+ if (spreadsheet.style[temp[i]]) {
127
+ spreadsheet.style[temp[i]] += ";";
128
+ }
129
+ // console.log(
130
+ // "style bg-color ",
131
+ // spreadsheet.style[temp[i]],
132
+ // cell.s.fgColor.rgb
133
+ // );
134
+ spreadsheet.style[temp[i]] =
135
+ (spreadsheet.style[temp[i]] || "") +
136
+ "background-color:#" +
137
+ cell.s.fgColor.rgb;
138
+ }
139
+ }
140
+ }
141
+ // ensure we have enough columns to display all the data
142
+ const maxColumns = spreadsheet.data.reduce((acc, cur) => (cur.length > acc ? (acc = cur.length) : acc), 0);
143
+ spreadsheet.columns = spreadsheet.columns.slice(0, maxColumns);
144
+ for (var i = 0; i <= maxColumns; i++) {
145
+ if (!spreadsheet.columns[i]) {
146
+ spreadsheet.columns[i] = { width: "100px" };
147
+ }
148
+ }
149
+ for (var j = 0; j <= max_y; j++) {
150
+ for (var i = 0; i <= max_x; i++) {
151
+ if (!spreadsheet.data[j]) {
152
+ spreadsheet.data[j] = [];
153
+ }
154
+ if (!spreadsheet.data[j][i]) {
155
+ if (maxColumns < i) {
156
+ spreadsheet.data[j][i] = "";
157
+ }
158
+ }
159
+ }
160
+ }
161
+ spreadsheets.push(spreadsheet);
162
+ });
163
+ return spreadsheets;
164
+ }
@@ -0,0 +1,138 @@
1
+ export declare const defaultconfig: {
2
+ url: any;
3
+ copyCompatibility: boolean;
4
+ root: any;
5
+ colHeaders: any[];
6
+ colWidths: any[];
7
+ colAlignments: any[];
8
+ nestedHeaders: any;
9
+ defaultColWidth: number;
10
+ defaultColAlign: string;
11
+ minSpareRows: number;
12
+ minSpareCols: number;
13
+ minDimensions: number[];
14
+ allowExport: boolean;
15
+ includeHeadersOnDownload: boolean;
16
+ includeHeadersOnCopy: boolean;
17
+ columnSorting: boolean;
18
+ columnDrag: boolean;
19
+ columnResize: boolean;
20
+ rowResize: boolean;
21
+ rowDrag: boolean;
22
+ editable: boolean;
23
+ readOnly: boolean;
24
+ disableHover: boolean;
25
+ allowInsertRow: boolean;
26
+ allowManualInsertRow: boolean;
27
+ allowInsertColumn: boolean;
28
+ allowManualInsertColumn: boolean;
29
+ allowDeleteRow: boolean;
30
+ allowDeletingAllRows: boolean;
31
+ allowDeleteColumn: boolean;
32
+ allowRenameColumn: boolean;
33
+ allowComments: boolean;
34
+ wordWrap: boolean;
35
+ imageOptions: any;
36
+ csv: any;
37
+ csvFileName: string;
38
+ csvHeaders: boolean;
39
+ csvDelimiter: string;
40
+ parseTableFirstRowAsHeader: boolean;
41
+ parseTableAutoCellType: boolean;
42
+ selectionCopy: boolean;
43
+ toolbar: any;
44
+ search: boolean;
45
+ pagination: boolean;
46
+ paginationOptions: any;
47
+ fullscreen: boolean;
48
+ lazyLoading: boolean;
49
+ loadingSpin: boolean;
50
+ tableOverflow: boolean;
51
+ tableHeight: string;
52
+ tableWidth: any;
53
+ meta: any;
54
+ style: any;
55
+ parseFormulas: boolean;
56
+ autoIncrement: boolean;
57
+ autoCasting: boolean;
58
+ secureFormulas: boolean;
59
+ stripHTML: boolean;
60
+ stripHTMLOnCopy: boolean;
61
+ filters: boolean;
62
+ footers: any;
63
+ onundo: any;
64
+ onredo: any;
65
+ onload: any;
66
+ onchange: any;
67
+ oncomments: any;
68
+ onbeforechange: any;
69
+ onafterchanges: any;
70
+ onbeforeinsertrow: any;
71
+ oninsertrow: any;
72
+ onbeforeinsertcolumn: any;
73
+ oninsertcolumn: any;
74
+ onbeforedeleterow: any;
75
+ ondeleterow: any;
76
+ onbeforedeletecolumn: any;
77
+ ondeletecolumn: any;
78
+ onmoverow: any;
79
+ onmovecolumn: any;
80
+ onresizerow: any;
81
+ onresizecolumn: any;
82
+ onsort: any;
83
+ onselection: any;
84
+ oncopy: any;
85
+ onpaste: any;
86
+ onbeforepaste: any;
87
+ onmerge: any;
88
+ onfocus: any;
89
+ onblur: any;
90
+ onchangeheader: any;
91
+ oncreateeditor: any;
92
+ oneditionstart: any;
93
+ oneditionend: any;
94
+ onchangestyle: any;
95
+ onchangemeta: any;
96
+ onchangepage: any;
97
+ onbeforesave: any;
98
+ onsave: any;
99
+ onevent: any;
100
+ persistance: boolean;
101
+ updateTable: any;
102
+ detachForUpdates: boolean;
103
+ freezeColumns: any;
104
+ text: {
105
+ noRecordsFound: string;
106
+ showingPage: string;
107
+ show: string;
108
+ search: string;
109
+ entries: string;
110
+ columnName: string;
111
+ insertANewColumnBefore: string;
112
+ insertANewColumnAfter: string;
113
+ deleteSelectedColumns: string;
114
+ renameThisColumn: string;
115
+ orderAscending: string;
116
+ orderDescending: string;
117
+ insertANewRowBefore: string;
118
+ insertANewRowAfter: string;
119
+ deleteSelectedRows: string;
120
+ editComments: string;
121
+ addComments: string;
122
+ comments: string;
123
+ clearComments: string;
124
+ copy: string;
125
+ paste: string;
126
+ saveAs: string;
127
+ about: string;
128
+ areYouSureToDeleteTheSelectedRows: string;
129
+ areYouSureToDeleteTheSelectedColumns: string;
130
+ thisActionWillDestroyAnyExistingMergedCellsAreYouSure: string;
131
+ thisActionWillClearYourSearchResultsAreYouSure: string;
132
+ thereIsAConflictWithAnotherMergedCell: string;
133
+ invalidMergeProperties: string;
134
+ cellAlreadyMerged: string;
135
+ noCellsSelected: string;
136
+ };
137
+ };
138
+ export type Config = typeof defaultconfig;