@operato/scene-excel 9.0.0-beta.2 → 9.0.0-beta.22
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/excel.js +18 -12
- package/dist/excel.js.map +1 -1
- package/package.json +4 -4
- package/things-scene.config.js +1 -1
package/dist/excel.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Copyright © HatioLab Inc. All rights reserved.
|
|
3
3
|
*/
|
|
4
|
+
var Excel_1;
|
|
5
|
+
import { __decorate } from "tslib";
|
|
4
6
|
import * as XLSX from 'xlsx';
|
|
5
|
-
import {
|
|
7
|
+
import { DataSource, RectPath, Shape, sceneComponent } from '@hatiolab/things-scene';
|
|
6
8
|
const NATURE = {
|
|
7
9
|
mutable: false,
|
|
8
10
|
resizable: true,
|
|
@@ -51,13 +53,13 @@ async function fetchData(url) {
|
|
|
51
53
|
console.log('result', result);
|
|
52
54
|
return result;
|
|
53
55
|
}
|
|
54
|
-
|
|
56
|
+
let Excel = Excel_1 = class Excel extends DataSource(RectPath(Shape)) {
|
|
55
57
|
static get image() {
|
|
56
|
-
if (!
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
if (!Excel_1._image) {
|
|
59
|
+
Excel_1._image = new Image();
|
|
60
|
+
Excel_1._image.src = new URL('../icons/symbol-excel.png', import.meta.url).href;
|
|
59
61
|
}
|
|
60
|
-
return
|
|
62
|
+
return Excel_1._image;
|
|
61
63
|
}
|
|
62
64
|
dispose() {
|
|
63
65
|
this._stopRepeater();
|
|
@@ -72,7 +74,7 @@ export default class Excel extends DataSource(RectPath(Shape)) {
|
|
|
72
74
|
render(context) {
|
|
73
75
|
var { left, top, width, height } = this.bounds;
|
|
74
76
|
context.beginPath();
|
|
75
|
-
this.drawImage(context,
|
|
77
|
+
this.drawImage(context, Excel_1.image, left, top, width, height);
|
|
76
78
|
}
|
|
77
79
|
get nature() {
|
|
78
80
|
return NATURE;
|
|
@@ -103,9 +105,10 @@ export default class Excel extends DataSource(RectPath(Shape)) {
|
|
|
103
105
|
});
|
|
104
106
|
}
|
|
105
107
|
_stopRepeater() {
|
|
106
|
-
if (this.repeatTimer)
|
|
107
|
-
|
|
108
|
-
|
|
108
|
+
if (this.repeatTimer) {
|
|
109
|
+
clearInterval(this.repeatTimer);
|
|
110
|
+
}
|
|
111
|
+
this.repeatTimer = null;
|
|
109
112
|
}
|
|
110
113
|
ondropfile(transfered, files) {
|
|
111
114
|
for (let i = 0; i < transfered.length; i++) {
|
|
@@ -120,6 +123,9 @@ export default class Excel extends DataSource(RectPath(Shape)) {
|
|
|
120
123
|
this._initInterval();
|
|
121
124
|
}
|
|
122
125
|
}
|
|
123
|
-
}
|
|
124
|
-
|
|
126
|
+
};
|
|
127
|
+
Excel = Excel_1 = __decorate([
|
|
128
|
+
sceneComponent('excel')
|
|
129
|
+
], Excel);
|
|
130
|
+
export default Excel;
|
|
125
131
|
//# sourceMappingURL=excel.js.map
|
package/dist/excel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"excel.js","sourceRoot":"","sources":["../src/excel.ts"],"names":[],"mappings":"AAAA;;GAEG
|
|
1
|
+
{"version":3,"file":"excel.js","sourceRoot":"","sources":["../src/excel.ts"],"names":[],"mappings":"AAAA;;GAEG;;;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAE5B,OAAO,EAAmB,UAAU,EAAc,QAAQ,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAEjH,MAAM,MAAM,GAAoB;IAC9B,OAAO,EAAE,KAAK;IACd,SAAS,EAAE,IAAI;IACf,SAAS,EAAE,IAAI;IACf,UAAU,EAAE;QACV;YACE,IAAI,EAAE,qBAAqB;YAC3B,KAAK,EAAE,KAAK;YACZ,IAAI,EAAE,KAAK;YACX,WAAW,EAAE,gBAAgB;SAC9B;QACD;YACE,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE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AAI,QAAQ,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK,EAAE,CAAC;YACxC,IAAI,CAAC,aAAa,EAAE,CAAA;QACtB,CAAC;IACH,CAAC;CACF,CAAA;AA3FoB,KAAK;IADzB,cAAc,CAAC,OAAO,CAAC;GACH,KAAK,CA2FzB;eA3FoB,KAAK","sourcesContent":["/*\n * Copyright © HatioLab Inc. All rights reserved.\n */\n\nimport * as XLSX from 'xlsx'\n\nimport { ComponentNature, DataSource, Properties, RectPath, Shape, sceneComponent } from '@hatiolab/things-scene'\n\nconst NATURE: ComponentNature = {\n mutable: false,\n resizable: true,\n rotatable: true,\n properties: [\n {\n type: 'attachment-selector',\n label: 'src',\n name: 'src',\n placeholder: 'Excel File URL'\n },\n {\n type: 'number',\n label: 'period',\n name: 'period',\n placeholder: 'seconds'\n }\n ],\n help: 'scene/component/excel'\n}\n\nasync function fetchData(url: string) {\n if (!url.startsWith('data:')) {\n // prevent read from cache\n if (url.indexOf('?') !== -1) {\n url = url + `&ts=${Date.now()}`\n } else {\n url = url + `?ts=${Date.now()}`\n }\n }\n\n const file = await fetch(url, {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/xlsx'\n },\n credentials: 'include'\n })\n\n const workbook: XLSX.WorkBook = XLSX.read(await file.arrayBuffer(), { type: 'array' })\n\n var result: { [key: string]: unknown } = {}\n workbook.SheetNames.forEach((sheet: string) => {\n var roa = XLSX.utils.sheet_to_json(workbook.Sheets[sheet])\n if (roa.length) {\n result[sheet] = roa\n }\n })\n\n console.log('result', result)\n return result\n}\n\n@sceneComponent('excel')\nexport default class Excel extends DataSource(RectPath(Shape)) {\n static _image: HTMLImageElement\n\n static get image() {\n if (!Excel._image) {\n Excel._image = new Image()\n Excel._image.src = new URL('../icons/symbol-excel.png', import.meta.url).href\n }\n\n return Excel._image\n }\n\n private repeatTimer?: NodeJS.Timeout | null\n private src?: string\n\n dispose() {\n this._stopRepeater()\n super.dispose()\n }\n\n ready() {\n const { src } = this.state\n\n if (src) {\n this._initInterval()\n }\n }\n\n render(context: CanvasRenderingContext2D) {\n var { left, top, width, height } = this.bounds\n\n context.beginPath()\n this.drawImage(context, Excel.image, left, top, width, height)\n }\n\n get nature() {\n return NATURE\n }\n\n _initInterval() {\n this._stopRepeater()\n this._startRepeater()\n }\n\n _startRepeater() {\n var { src, period } = this.state\n period = Number(period)\n\n var fetchable = true\n\n if (period && this.app.isViewMode) {\n this.repeatTimer = setInterval(() => {\n fetchable &&\n this.repeatTimer &&\n requestAnimationFrame(() => {\n fetchable = true\n fetchData(src).then(data => {\n this.setState('data', data)\n })\n })\n fetchable = false\n }, period * 1000)\n }\n\n fetchData(src).then(data => {\n this.setState('data', data)\n })\n }\n\n _stopRepeater() {\n if (this.repeatTimer) {\n clearInterval(this.repeatTimer)\n }\n\n this.repeatTimer = null\n }\n\n ondropfile(transfered: any, files: any) {\n for (let i = 0; i < transfered.length; i++) {\n if (/\\.xlsx?$/.test(transfered[i].name)) {\n this.src = files[i]\n return\n }\n }\n }\n\n onchange(after: Properties, before: Properties) {\n if ('period' in after || 'src' in after) {\n this._initInterval()\n }\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@operato/scene-excel",
|
|
3
3
|
"description": "Excel integration component for things-scene",
|
|
4
|
-
"version": "9.0.0-beta.
|
|
4
|
+
"version": "9.0.0-beta.22",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "heartyoh",
|
|
7
7
|
"main": "dist/index.js",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"@typescript-eslint/parser": "^4.33.0",
|
|
40
40
|
"@web/dev-server": "^0.1.28",
|
|
41
41
|
"concurrently": "^8.0.1",
|
|
42
|
-
"eslint": "^
|
|
43
|
-
"eslint-config-prettier": "^
|
|
42
|
+
"eslint": "^9.18.0",
|
|
43
|
+
"eslint-config-prettier": "^10.0.1",
|
|
44
44
|
"husky": "^8.0.3",
|
|
45
45
|
"lint-staged": "^13.2.2",
|
|
46
46
|
"prettier": "^2.4.1",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"prettier --write"
|
|
60
60
|
]
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "3309c293eadf2a3fc7c20191d32bd72f5b1d7ab7"
|
|
63
63
|
}
|
package/things-scene.config.js
CHANGED