@operato/scene-excel 8.0.0-beta.1 → 9.0.0-beta.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.
package/src/excel.ts DELETED
@@ -1,153 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import * as XLSX from 'xlsx'
6
-
7
- import { Component, ComponentNature, DataSource, Properties, RectPath, Shape } from '@hatiolab/things-scene'
8
-
9
- const NATURE: ComponentNature = {
10
- mutable: false,
11
- resizable: true,
12
- rotatable: true,
13
- properties: [
14
- {
15
- type: 'attachment-selector',
16
- label: 'src',
17
- name: 'src',
18
- placeholder: 'Excel File URL'
19
- },
20
- {
21
- type: 'number',
22
- label: 'period',
23
- name: 'period',
24
- placeholder: 'seconds'
25
- }
26
- ],
27
- help: 'scene/component/excel'
28
- }
29
-
30
- async function fetchData(url: string) {
31
- if (!url.startsWith('data:')) {
32
- // prevent read from cache
33
- if (url.indexOf('?') !== -1) {
34
- url = url + `&ts=${Date.now()}`
35
- } else {
36
- url = url + `?ts=${Date.now()}`
37
- }
38
- }
39
-
40
- const file = await fetch(url, {
41
- method: 'GET',
42
- headers: {
43
- 'Content-Type': 'application/xlsx'
44
- },
45
- credentials: 'include'
46
- })
47
-
48
- const workbook: XLSX.WorkBook = XLSX.read(await file.arrayBuffer(), { type: 'array' })
49
-
50
- var result: { [key: string]: unknown } = {}
51
- workbook.SheetNames.forEach((sheet: string) => {
52
- var roa = XLSX.utils.sheet_to_json(workbook.Sheets[sheet])
53
- if (roa.length) {
54
- result[sheet] = roa
55
- }
56
- })
57
-
58
- console.log('result', result)
59
- return result
60
- }
61
-
62
- export default class Excel extends DataSource(RectPath(Shape)) {
63
- static _image: HTMLImageElement
64
-
65
- static get image() {
66
- if (!Excel._image) {
67
- Excel._image = new Image()
68
- Excel._image.src = new URL('../icons/symbol-excel.png', import.meta.url).href
69
- }
70
-
71
- return Excel._image
72
- }
73
-
74
- private repeatTimer?: NodeJS.Timeout
75
- private src?: string
76
-
77
- dispose() {
78
- this._stopRepeater()
79
- super.dispose()
80
- }
81
-
82
- ready() {
83
- const { src } = this.state
84
-
85
- if (src) {
86
- this._initInterval()
87
- }
88
- }
89
-
90
- render(context: CanvasRenderingContext2D) {
91
- var { left, top, width, height } = this.bounds
92
-
93
- context.beginPath()
94
- this.drawImage(context, Excel.image, left, top, width, height)
95
- }
96
-
97
- get nature() {
98
- return NATURE
99
- }
100
-
101
- _initInterval() {
102
- this._stopRepeater()
103
- this._startRepeater()
104
- }
105
-
106
- _startRepeater() {
107
- var { src, period } = this.state
108
- period = Number(period)
109
-
110
- var fetchable = true
111
-
112
- if (period && this.app.isViewMode) {
113
- this.repeatTimer = setInterval(() => {
114
- fetchable &&
115
- this.repeatTimer &&
116
- requestAnimationFrame(() => {
117
- fetchable = true
118
- fetchData(src).then(data => {
119
- this.setState('data', data)
120
- })
121
- })
122
- fetchable = false
123
- }, period * 1000)
124
- }
125
-
126
- fetchData(src).then(data => {
127
- this.setState('data', data)
128
- })
129
- }
130
-
131
- _stopRepeater() {
132
- if (this.repeatTimer) clearTimeout(this.repeatTimer)
133
-
134
- delete this.repeatTimer
135
- }
136
-
137
- ondropfile(transfered: any, files: any) {
138
- for (let i = 0; i < transfered.length; i++) {
139
- if (/\.xlsx?$/.test(transfered[i].name)) {
140
- this.src = files[i]
141
- return
142
- }
143
- }
144
- }
145
-
146
- onchange(after: Properties, before: Properties) {
147
- if ('period' in after || 'src' in after) {
148
- this._initInterval()
149
- }
150
- }
151
- }
152
-
153
- Component.register('excel', Excel)
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- import Excel from './excel'
2
-
3
- export default [Excel]
@@ -1,18 +0,0 @@
1
- const icon = new URL('../../icons/icon-excel.png', import.meta.url).href
2
-
3
- export default {
4
- type: 'excel',
5
- description: 'excel',
6
- group: 'dataSource',
7
- /* line|shape|textAndMedia|chartAndGauge|table|container|dataSource|IoT|3D|warehouse|form|etc */
8
- icon,
9
- model: {
10
- type: 'excel',
11
- left: 10,
12
- top: 10,
13
- width: 100,
14
- height: 100,
15
- fillStyle: 'cyan',
16
- strokeStyle: 'darkgray'
17
- }
18
- }
@@ -1,3 +0,0 @@
1
- import excel from './excel'
2
-
3
- export default [excel]
package/tsconfig.json DELETED
@@ -1,23 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2018",
4
- "module": "esnext",
5
- "moduleResolution": "node",
6
- "noEmitOnError": true,
7
- "lib": ["es2019", "dom"],
8
- "strict": true,
9
- "esModuleInterop": false,
10
- "allowJs": true,
11
- "allowSyntheticDefaultImports": true,
12
- "experimentalDecorators": true,
13
- "importHelpers": true,
14
- "outDir": "dist",
15
- "sourceMap": true,
16
- "inlineSources": true,
17
- "rootDir": "src",
18
- "declaration": true,
19
- "incremental": true,
20
- "skipLibCheck": true
21
- },
22
- "include": ["**/*.ts", "*.d.ts"]
23
- }