amotify-ex-spreadsheet 0.0.1

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,51 @@
1
+ import { Input } from 'amotify/@fn';
2
+ declare global {
3
+ var ExcelJS: any;
4
+ }
5
+ declare namespace SpreadSheet {
6
+ interface Instance {
7
+ fn: Class;
8
+ prototype: Class;
9
+ (v: any, a: string): any;
10
+ }
11
+ interface Class {
12
+ isValid(): boolean;
13
+ getWorkbook(): any;
14
+ updateFileName(fileName: string): void;
15
+ updateMerges(merges: Merge[][]): void;
16
+ updateStyles(styles: Style[][]): void;
17
+ toJson(): {
18
+ fileName: string;
19
+ sheets: {
20
+ sheetName: string;
21
+ rows: any[];
22
+ }[];
23
+ };
24
+ export(type?: 'xlsx' | 'csv'): void;
25
+ }
26
+ type Json = {
27
+ fileName: string;
28
+ sheets: Sheet[];
29
+ };
30
+ type Sheet = {
31
+ sheetName: string;
32
+ rows: Row[];
33
+ merges?: Merge[];
34
+ styles?: Style[];
35
+ };
36
+ type Row = (string | number)[];
37
+ type Merge = [string, string] | [null, null];
38
+ type Style = {
39
+ type: 'cell' | 'row' | 'column';
40
+ target: string | number | (string | number)[];
41
+ values: {
42
+ [key: string]: any;
43
+ };
44
+ };
45
+ type Methods = {
46
+ readFromFile(file: Input.Filer.CustomFile): Promise<SpreadSheet.Class>;
47
+ readFromJson(v: SpreadSheet.Json): Promise<SpreadSheet.Class>;
48
+ };
49
+ }
50
+ declare const SpreadSheet: SpreadSheet.Methods;
51
+ export { SpreadSheet, SpreadSheet as default };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ var m=(e,r,t)=>new Promise((o,l)=>{var c=n=>{try{s(t.next(n))}catch(i){l(i)}},a=n=>{try{s(t.throw(n))}catch(i){l(i)}},s=n=>n.done?o(n.value):Promise.resolve(n.value).then(c,a);s((t=t.apply(e,r)).next())});import d from"@mingoo/jsmin";const h=(e,r)=>new h.fn.SpreadSheet(e,r);h.fn=h.prototype={},d.extend({SpreadSheet:function(e,r){this.ok=!0;try{this.workbook=e,this.fileName=r}catch(t){console.log(t),this.ok=!1}return this},isValid:function(){return this.ok},getWorkbook:function(){return this.workbook},updateFileName:function(e){return this.fileName=e,this},updateMerges:function(e){this.toJson().sheets.forEach((t,o)=>{let l=e[o];const c=this.workbook.getWorksheet(t.sheetName);for(let[a,s]of l)a&&s&&c.mergeCells(a+":"+s)})},updateStyles:function(e){this.toJson().sheets.forEach((t,o)=>{let l=e[o];const c=this.workbook.getWorksheet(t.sheetName);for(let a of l){let{type:s,target:n,values:i}=a,y=d.flatArray(n);for(let[p,f]of Object.entries(i))for(let u of y)c["get"+s.toCapital()](u)[p]=f}})},toJson:function(){let e={fileName:this.fileName,sheets:[]};return this.workbook.eachSheet((r,t)=>{let o={sheetName:r.name,rows:[]};r.eachRow((l,c)=>{let[a,...s]=l.values;o.rows.push(s)}),e.sheets.push(o)}),e},export:function(e){return m(this,null,function*(){e=e||"xlsx";const r=yield this.workbook[e].writeBuffer(),t=new Blob([r],{type:"application/octet-binary"}),o=document.createElement("a");o.href=(global.URL||global.webkitURL).createObjectURL(t),o.download=this.fileName+"."+e,o.click(),o.remove()})}},h),h.fn.SpreadSheet.prototype=h.fn,h.fn.SpreadSheet.prototype.constructor=h;let S="https://cdn.amotify.com/@env/@foreign/exceljs.min.js";const g={readFromFile:e=>m(void 0,null,function*(){if(global.ExcelJS||(yield d.CDNReader(S)),!global.ExcelJS)return;let r=e.type,t=e.name.replace(/\.[^/.]+$/,"");if(r.match(/csv/)){const a=(yield e.text()).split(/[\n\r]+/).map(i=>i.split(/,/)),s=new ExcelJS.Workbook,n=s.addWorksheet("Sheet1");return a.forEach(i=>n.addRow(i)),h(s,t)}const o=new ExcelJS.Workbook,l=(yield e.read("binaryString")).target.result;return h(yield o.xlsx.load(l),t)}),readFromJson:e=>m(void 0,null,function*(){if(global.ExcelJS||(yield d.CDNReader(S)),!global.ExcelJS)return;let{sheets:r,fileName:t=""}=e;t=t||d.uuid.gen();const o=new ExcelJS.Workbook;return r.forEach((l,c)=>{let{sheetName:a,rows:s,merges:n=[],styles:i=[]}=l;a=a||"\u30B7\u30FC\u30C8"+(c+1),o.addWorksheet(a);const y=o.getWorksheet(a);y.addRows(s);for(let[p,f]of n)p&&f&&y.mergeCells(p+":"+f);for(let p of i){let{type:f,target:u,values:k}=p,w=d.flatArray(u);for(let[b,x]of Object.entries(k))for(let v of w)y["get"+f.toCapital()](v)[b]=x}}),h(o,t)})};export{g as SpreadSheet,g as default};
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "amotify-ex-spreadsheet",
3
+ "version": "0.0.1",
4
+ "description": "amotify spreadsheet extension",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "clean": "rimraf dist",
9
+ "start": "run-p start:*",
10
+ "start:clean": "rimraf dist",
11
+ "start:esbuild": "nodemon bundler.ts --watch",
12
+ "start:declaration": "npx tsc --declaration --emitDeclarationOnly --skipLibCheck --declarationDir './dist' --watch"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/IkkoKoyama/amotify-ex-spreadsheet.git"
17
+ },
18
+ "keywords": [
19
+ "amotify",
20
+ "extension"
21
+ ],
22
+ "author": "IkkoKoyama <mingoo.master@gmail.com>",
23
+ "license": "MIT",
24
+ "bugs": {
25
+ "url": "https://github.com/IkkoKoyama/amotify-ex-spreadsheet/issues"
26
+ },
27
+ "homepage": "https://github.com/IkkoKoyama/amotify-ex-spreadsheet#readme",
28
+ "dependencies": {
29
+ "@mingoo/jsmin": "^0.0.21",
30
+ "@types/react": "^18.3.1",
31
+ "amotify": "^0.1.56",
32
+ "esbuild": "^0.20.2",
33
+ "nodemon": "^3.0.1",
34
+ "npm-run-all": "^4.1.5",
35
+ "prop-types": "^15.8.1",
36
+ "react": "^18.3.1",
37
+ "rimraf": "^5.0.5",
38
+ "ts-loader": "^9.5.1",
39
+ "typescript": "^5.4.5"
40
+ }
41
+ }