@operato/scene-tab 1.1.5 → 1.1.14

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.
Files changed (61) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/assets/favicon.ico +0 -0
  3. package/assets/images/spinner.png +0 -0
  4. package/demo/index.html +240 -204
  5. package/dist/index.d.ts +2 -0
  6. package/dist/index.js +2 -0
  7. package/dist/index.js.map +1 -1
  8. package/dist/tab-button.js +3 -1
  9. package/dist/tab-button.js.map +1 -1
  10. package/dist/tab-card.d.ts +10 -0
  11. package/dist/tab-card.js +65 -0
  12. package/dist/tab-card.js.map +1 -0
  13. package/dist/tab-container.d.ts +20 -0
  14. package/dist/tab-container.js +167 -0
  15. package/dist/tab-container.js.map +1 -0
  16. package/dist/tab.js +17 -13
  17. package/dist/tab.js.map +1 -1
  18. package/dist/templates/index.d.ts +16 -3
  19. package/dist/templates/index.js +3 -2
  20. package/dist/templates/index.js.map +1 -1
  21. package/dist/templates/tab-container.d.ts +16 -0
  22. package/dist/templates/tab-container.js +17 -0
  23. package/dist/templates/tab-container.js.map +1 -0
  24. package/dist/templates/tab.d.ts +0 -1
  25. package/dist/templates/tab.js +2 -3
  26. package/dist/templates/tab.js.map +1 -1
  27. package/helps/scene/component/tab-container.ko.md +58 -0
  28. package/helps/scene/component/tab-container.md +57 -0
  29. package/helps/scene/component/tab-container.zh.md +59 -0
  30. package/helps/scene/images/button-evnet-mapping-01.png +0 -0
  31. package/helps/scene/images/button-evnet-mapping-02.png +0 -0
  32. package/helps/scene/images/button-evnet-mapping-03.png +0 -0
  33. package/helps/scene/images/tab-button-finish-01.gif +0 -0
  34. package/helps/scene/images/tab-container-03.png +0 -0
  35. package/helps/scene/images/tab-container-create-01.png +0 -0
  36. package/helps/scene/images/tab-container-create-02.png +0 -0
  37. package/helps/scene/images/tab-container-create-03.png +0 -0
  38. package/helps/scene/images/tab-container-setting-01.png +0 -0
  39. package/icons/tab-container.png +0 -0
  40. package/logs/.08636eb59927f12972f6774f5947c8507b3564c2-audit.json +20 -0
  41. package/logs/.5e5d741d8b7784a2fbad65eedc0fd46946aaf6f2-audit.json +20 -0
  42. package/logs/application-2022-11-13-11.log +14 -0
  43. package/logs/application-2022-11-13-12.log +6 -0
  44. package/logs/connections-2022-11-13-11.log +70 -0
  45. package/logs/connections-2022-11-13-12.log +35 -0
  46. package/package.json +2 -2
  47. package/src/index.ts +3 -0
  48. package/src/tab-button.ts +3 -3
  49. package/src/tab-card.ts +76 -0
  50. package/src/tab-container.ts +204 -0
  51. package/src/tab.ts +18 -12
  52. package/src/templates/index.ts +3 -2
  53. package/src/templates/tab-container.ts +17 -0
  54. package/src/templates/tab.ts +2 -3
  55. package/things-scene.config.js +2 -2
  56. package/translations/en.json +4 -0
  57. package/translations/ko.json +4 -0
  58. package/translations/ms.json +4 -0
  59. package/translations/zh.json +4 -0
  60. package/tsconfig.tsbuildinfo +1 -1
  61. package/images/icon-button.png +0 -0
@@ -0,0 +1,57 @@
1
+ # tab-container
2
+
3
+ ## example
4
+
5
+ Control the TabContainer layer by triggering events on the rectangular component
6
+
7
+ > -**Apply a click event to a square component and deliver it to TabContainers** -**If you change the value property of TabContainer, the TabCard will be changed.**
8
+
9
+ ![gif][gif-01]
10
+
11
+ [gif-01]: ../images/tab-button-finish-01.gif
12
+
13
+ 1. It creates TabContainer with three layers.
14
+
15
+ ![tab-container][tab-container-create]
16
+
17
+ 2. Text is put in each layer for distinction.
18
+
19
+ ![tab-container][tab-container-text]
20
+
21
+ 3. The ID of the TabContainer is designated as 'indoor'.
22
+
23
+ ![tab-container][tab-container-id]
24
+
25
+ 4. Add button event
26
+
27
+ - After drawing 3 squares, select 'indoor' as the variable information in the 'effect window'.
28
+ (In the variable information, a list of IDs of basic events and components is shown.)
29
+ ![buttonEvent][button-02]
30
+
31
+ - Map values for each square. (When clicking the square, data of '0' is passed to the component with the 'indoor' ID.)
32
+ - 1layer - 0
33
+ - 2layer - 1
34
+ - 3layer - 2
35
+
36
+ ![buttonEvent][button-03]
37
+
38
+ [button-02]: ../images/button-evnet-mapping-02.png
39
+ [button-03]: ../images/button-evnet-mapping-03.png
40
+
41
+ 5. TabContainer setting
42
+
43
+ - Set the data binding setting of the TabContainer component as shown in the figure below.
44
+ (Setting to change its value property when receiving data)
45
+
46
+ ![buttonEvent][tab-container-setting]
47
+
48
+ 6. check result
49
+
50
+ - If all settings are complete, you can see that the TabContainer layer changes every time you click the square as shown below.
51
+ ![gif-01]
52
+
53
+ [gif-01]: ../images/tab-button-finish-01.gif
54
+ [tab-container-create]: ../images/tab-container-create-01.png
55
+ [tab-container-text]: ../images/tab-container-create-02.png
56
+ [tab-container-id]: ../images/tab-container-create-03.png
57
+ [tab-container-setting]: ../images/tab-container-setting-01.png
@@ -0,0 +1,59 @@
1
+ # tab-container
2
+
3
+ ## example
4
+
5
+ 通过触发矩形组件上的事件来控制室内层
6
+
7
+ > - **将矩形组件的 click 事件传递到 TabContainer 组件**
8
+ > - **更改 TabContainer 组件的 value 属性 TabCard 会发生变化**
9
+
10
+ ![gif][gif-01]
11
+
12
+ [gif-01]: ../images/tab-button-finish-01.gif
13
+
14
+ 1. 创建具有三层的 tab-container
15
+
16
+ ![tab-container][tab-container-create]
17
+
18
+ 2. 为了区分为每层更改显示层数
19
+
20
+ ![tab-container][tab-container-text]
21
+
22
+ 3. 指定室内地图的 ID。
23
+
24
+ ![tab-container][tab-container-id]
25
+
26
+ 4. 增加按钮
27
+
28
+ - 绘制 3 个矩形后,在“效果窗口”中的点击事件中 'indoor' 作为变量信息。
29
+ (在变量信息中,显示基本事件处理方法和组件的 ID 的列表。)
30
+ ![buttonEvent][button-02]
31
+
32
+ - 每个矩形的地图值。 (单击矩形时,数据“0”将传递到具有 'indoor' ID 的组件。)
33
+ - 1층 - 0
34
+ - 2층 - 1
35
+ - 3층 - 2
36
+
37
+ ![buttonEvent][button-03]
38
+
39
+ [button-02]: ../images/button-evnet-mapping-02.png
40
+ [button-03]: ../images/button-evnet-mapping-03.png
41
+
42
+ 5. tab-container 配置
43
+
44
+ - 如下图设置室内地图组件的数据绑定设置。
45
+ (设置为在接收数据时更改其 value 属性)
46
+
47
+ ![buttonEvent][tab-container-setting]
48
+
49
+ 6. 确认结果
50
+
51
+ - 如果所有设置均已完成,则每次单击矩形时,都可以看到室内地图图层发生变化,如下所示。
52
+ ![gif-01]
53
+
54
+ [gif-01]: ../images/tab-button-finish-01.gif
55
+
56
+ [tab-container-create]: ../images/tab-container-create-01.png
57
+ [tab-container-text]: ../images/tab-container-create-02.png
58
+ [tab-container-id]: ../images/tab-container-create-03.png
59
+ [tab-container-setting]: ../images/tab-container-setting-01.png
Binary file
@@ -0,0 +1,20 @@
1
+ {
2
+ "keep": {
3
+ "days": true,
4
+ "amount": 2
5
+ },
6
+ "auditLog": "logs/.08636eb59927f12972f6774f5947c8507b3564c2-audit.json",
7
+ "files": [
8
+ {
9
+ "date": 1668305631867,
10
+ "name": "logs/application-2022-11-13-11.log",
11
+ "hash": "1a4fca34a06957f0bc9147bd1998aaea9986f560f3845b16e24ba2561354870c"
12
+ },
13
+ {
14
+ "date": 1668310621750,
15
+ "name": "logs/application-2022-11-13-12.log",
16
+ "hash": "a6e92b1ff5d1c59348091f85a4b8ce1ebea0994b1d64a91dae0e13226b57bbc5"
17
+ }
18
+ ],
19
+ "hashType": "sha256"
20
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "keep": {
3
+ "days": true,
4
+ "amount": 14
5
+ },
6
+ "auditLog": "logs/.5e5d741d8b7784a2fbad65eedc0fd46946aaf6f2-audit.json",
7
+ "files": [
8
+ {
9
+ "date": 1668305632737,
10
+ "name": "logs/connections-2022-11-13-11.log",
11
+ "hash": "92b5a5784b7ecd0a635f48151736b7f4694661cb60da2f3356fc2c3763067370"
12
+ },
13
+ {
14
+ "date": 1668310623258,
15
+ "name": "logs/connections-2022-11-13-12.log",
16
+ "hash": "9827208d4a25978610634d4d0297f8b056db5eec06278d5b1baf16df63c4b684"
17
+ }
18
+ ],
19
+ "hashType": "sha256"
20
+ }
@@ -0,0 +1,14 @@
1
+ 2022-11-13T11:13:52+09:00 info: File Storage is Ready.
2
+ 2022-11-13T11:13:52+09:00 error: oracledb module loading failed
3
+ 2022-11-13T11:14:05+09:00 info: File Storage is Ready.
4
+ 2022-11-13T11:14:05+09:00 error: oracledb module loading failed
5
+ 2022-11-13T11:14:06+09:00 info: Default DataSource established
6
+ 2022-11-13T11:14:06+09:00 info: Transaction DataSource established
7
+ 2022-11-13T11:14:07+09:00 info: 🚀 Server ready at http://0.0.0.0:3000/graphql
8
+ 2022-11-13T11:14:07+09:00 info: 🚀 Subscriptions ready at ws://0.0.0.0:3000/graphql
9
+ 2022-11-13T11:47:26+09:00 info: File Storage is Ready.
10
+ 2022-11-13T11:47:26+09:00 error: oracledb module loading failed
11
+ 2022-11-13T11:47:27+09:00 info: Default DataSource established
12
+ 2022-11-13T11:47:27+09:00 info: Transaction DataSource established
13
+ 2022-11-13T11:47:28+09:00 info: 🚀 Server ready at http://0.0.0.0:3000/graphql
14
+ 2022-11-13T11:47:28+09:00 info: 🚀 Subscriptions ready at ws://0.0.0.0:3000/graphql
@@ -0,0 +1,6 @@
1
+ 2022-11-13T12:37:02+09:00 info: File Storage is Ready.
2
+ 2022-11-13T12:37:03+09:00 error: oracledb module loading failed
3
+ 2022-11-13T12:37:04+09:00 info: Default DataSource established
4
+ 2022-11-13T12:37:04+09:00 info: Transaction DataSource established
5
+ 2022-11-13T12:37:04+09:00 info: 🚀 Server ready at http://0.0.0.0:3000/graphql
6
+ 2022-11-13T12:37:04+09:00 info: 🚀 Subscriptions ready at ws://0.0.0.0:3000/graphql
@@ -0,0 +1,70 @@
1
+ 2022-11-13T11:14:07+09:00 info: Initializing ConnectionManager...
2
+ 2022-11-13T11:14:07+09:00 info: Connector 'echo-back-server' started to ready
3
+ 2022-11-13T11:14:07+09:00 info: Connector 'echo-back' started to ready
4
+ 2022-11-13T11:14:07+09:00 info: Connector 'http-connector' started to ready
5
+ 2022-11-13T11:14:07+09:00 info: Connector 'graphql-connector' started to ready
6
+ 2022-11-13T11:14:07+09:00 info: Connector 'sqlite-connector' started to ready
7
+ 2022-11-13T11:14:07+09:00 info: Connector 'postgresql-connector' started to ready
8
+ 2022-11-13T11:14:07+09:00 info: Connector 'mqtt-connector' started to ready
9
+ 2022-11-13T11:14:07+09:00 info: Connector 'mssql-connector' started to ready
10
+ 2022-11-13T11:14:07+09:00 info: Connector 'oracle-connector' started to ready
11
+ 2022-11-13T11:14:07+09:00 info: Connector 'mysql-connector' started to ready
12
+ 2022-11-13T11:14:07+09:00 info: Connector 'socket-server' started to ready
13
+ 2022-11-13T11:14:07+09:00 info: echo-back-servers are ready
14
+ 2022-11-13T11:14:07+09:00 info: echo-back connections are ready
15
+ 2022-11-13T11:14:07+09:00 info: http-connector connections are ready
16
+ 2022-11-13T11:14:07+09:00 info: graphql-connector connections are ready
17
+ 2022-11-13T11:14:07+09:00 info: sqlite-connector connections are ready
18
+ 2022-11-13T11:14:07+09:00 info: postgresql-connector connections are ready
19
+ 2022-11-13T11:14:07+09:00 info: mqtt-connector connections are ready
20
+ 2022-11-13T11:14:07+09:00 info: mssql-connector connections are ready
21
+ 2022-11-13T11:14:07+09:00 info: oracle-connector connections are ready
22
+ 2022-11-13T11:14:07+09:00 info: mysql-connector connections are ready
23
+ 2022-11-13T11:14:07+09:00 info: socket servers are ready
24
+ 2022-11-13T11:14:07+09:00 info: All connector for 'echo-back-server' ready
25
+ 2022-11-13T11:14:07+09:00 info: All connector for 'echo-back' ready
26
+ 2022-11-13T11:14:07+09:00 info: All connector for 'http-connector' ready
27
+ 2022-11-13T11:14:07+09:00 info: All connector for 'graphql-connector' ready
28
+ 2022-11-13T11:14:07+09:00 info: All connector for 'sqlite-connector' ready
29
+ 2022-11-13T11:14:07+09:00 info: All connector for 'postgresql-connector' ready
30
+ 2022-11-13T11:14:07+09:00 info: All connector for 'mqtt-connector' ready
31
+ 2022-11-13T11:14:07+09:00 info: All connector for 'mssql-connector' ready
32
+ 2022-11-13T11:14:07+09:00 info: All connector for 'oracle-connector' ready
33
+ 2022-11-13T11:14:07+09:00 info: All connector for 'mysql-connector' ready
34
+ 2022-11-13T11:14:07+09:00 info: All connector for 'socket-server' ready
35
+ 2022-11-13T11:14:07+09:00 info: ConnectionManager initialization done:
36
+ 2022-11-13T11:47:28+09:00 info: Initializing ConnectionManager...
37
+ 2022-11-13T11:47:28+09:00 info: Connector 'echo-back-server' started to ready
38
+ 2022-11-13T11:47:28+09:00 info: Connector 'echo-back' started to ready
39
+ 2022-11-13T11:47:28+09:00 info: Connector 'http-connector' started to ready
40
+ 2022-11-13T11:47:28+09:00 info: Connector 'graphql-connector' started to ready
41
+ 2022-11-13T11:47:28+09:00 info: Connector 'sqlite-connector' started to ready
42
+ 2022-11-13T11:47:28+09:00 info: Connector 'postgresql-connector' started to ready
43
+ 2022-11-13T11:47:28+09:00 info: Connector 'mqtt-connector' started to ready
44
+ 2022-11-13T11:47:28+09:00 info: Connector 'mssql-connector' started to ready
45
+ 2022-11-13T11:47:28+09:00 info: Connector 'oracle-connector' started to ready
46
+ 2022-11-13T11:47:28+09:00 info: Connector 'mysql-connector' started to ready
47
+ 2022-11-13T11:47:28+09:00 info: Connector 'socket-server' started to ready
48
+ 2022-11-13T11:47:28+09:00 info: echo-back-servers are ready
49
+ 2022-11-13T11:47:28+09:00 info: echo-back connections are ready
50
+ 2022-11-13T11:47:28+09:00 info: http-connector connections are ready
51
+ 2022-11-13T11:47:28+09:00 info: graphql-connector connections are ready
52
+ 2022-11-13T11:47:28+09:00 info: sqlite-connector connections are ready
53
+ 2022-11-13T11:47:28+09:00 info: postgresql-connector connections are ready
54
+ 2022-11-13T11:47:28+09:00 info: mqtt-connector connections are ready
55
+ 2022-11-13T11:47:28+09:00 info: mssql-connector connections are ready
56
+ 2022-11-13T11:47:28+09:00 info: oracle-connector connections are ready
57
+ 2022-11-13T11:47:28+09:00 info: mysql-connector connections are ready
58
+ 2022-11-13T11:47:28+09:00 info: socket servers are ready
59
+ 2022-11-13T11:47:28+09:00 info: All connector for 'echo-back-server' ready
60
+ 2022-11-13T11:47:28+09:00 info: All connector for 'echo-back' ready
61
+ 2022-11-13T11:47:28+09:00 info: All connector for 'http-connector' ready
62
+ 2022-11-13T11:47:28+09:00 info: All connector for 'graphql-connector' ready
63
+ 2022-11-13T11:47:28+09:00 info: All connector for 'sqlite-connector' ready
64
+ 2022-11-13T11:47:28+09:00 info: All connector for 'postgresql-connector' ready
65
+ 2022-11-13T11:47:28+09:00 info: All connector for 'mqtt-connector' ready
66
+ 2022-11-13T11:47:28+09:00 info: All connector for 'mssql-connector' ready
67
+ 2022-11-13T11:47:28+09:00 info: All connector for 'oracle-connector' ready
68
+ 2022-11-13T11:47:28+09:00 info: All connector for 'mysql-connector' ready
69
+ 2022-11-13T11:47:28+09:00 info: All connector for 'socket-server' ready
70
+ 2022-11-13T11:47:28+09:00 info: ConnectionManager initialization done:
@@ -0,0 +1,35 @@
1
+ 2022-11-13T12:37:05+09:00 info: Initializing ConnectionManager...
2
+ 2022-11-13T12:37:05+09:00 info: Connector 'echo-back-server' started to ready
3
+ 2022-11-13T12:37:05+09:00 info: Connector 'echo-back' started to ready
4
+ 2022-11-13T12:37:05+09:00 info: Connector 'http-connector' started to ready
5
+ 2022-11-13T12:37:05+09:00 info: Connector 'graphql-connector' started to ready
6
+ 2022-11-13T12:37:05+09:00 info: Connector 'sqlite-connector' started to ready
7
+ 2022-11-13T12:37:05+09:00 info: Connector 'postgresql-connector' started to ready
8
+ 2022-11-13T12:37:05+09:00 info: Connector 'mqtt-connector' started to ready
9
+ 2022-11-13T12:37:05+09:00 info: Connector 'mssql-connector' started to ready
10
+ 2022-11-13T12:37:05+09:00 info: Connector 'oracle-connector' started to ready
11
+ 2022-11-13T12:37:05+09:00 info: Connector 'mysql-connector' started to ready
12
+ 2022-11-13T12:37:05+09:00 info: Connector 'socket-server' started to ready
13
+ 2022-11-13T12:37:05+09:00 info: echo-back-servers are ready
14
+ 2022-11-13T12:37:05+09:00 info: echo-back connections are ready
15
+ 2022-11-13T12:37:05+09:00 info: http-connector connections are ready
16
+ 2022-11-13T12:37:05+09:00 info: graphql-connector connections are ready
17
+ 2022-11-13T12:37:05+09:00 info: sqlite-connector connections are ready
18
+ 2022-11-13T12:37:05+09:00 info: postgresql-connector connections are ready
19
+ 2022-11-13T12:37:05+09:00 info: mqtt-connector connections are ready
20
+ 2022-11-13T12:37:05+09:00 info: mssql-connector connections are ready
21
+ 2022-11-13T12:37:05+09:00 info: oracle-connector connections are ready
22
+ 2022-11-13T12:37:05+09:00 info: mysql-connector connections are ready
23
+ 2022-11-13T12:37:05+09:00 info: socket servers are ready
24
+ 2022-11-13T12:37:05+09:00 info: All connector for 'echo-back-server' ready
25
+ 2022-11-13T12:37:05+09:00 info: All connector for 'echo-back' ready
26
+ 2022-11-13T12:37:05+09:00 info: All connector for 'http-connector' ready
27
+ 2022-11-13T12:37:05+09:00 info: All connector for 'graphql-connector' ready
28
+ 2022-11-13T12:37:05+09:00 info: All connector for 'sqlite-connector' ready
29
+ 2022-11-13T12:37:05+09:00 info: All connector for 'postgresql-connector' ready
30
+ 2022-11-13T12:37:05+09:00 info: All connector for 'mqtt-connector' ready
31
+ 2022-11-13T12:37:05+09:00 info: All connector for 'mssql-connector' ready
32
+ 2022-11-13T12:37:05+09:00 info: All connector for 'oracle-connector' ready
33
+ 2022-11-13T12:37:05+09:00 info: All connector for 'mysql-connector' ready
34
+ 2022-11-13T12:37:05+09:00 info: All connector for 'socket-server' ready
35
+ 2022-11-13T12:37:05+09:00 info: ConnectionManager initialization done:
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Tab style container for Things Scene",
4
4
  "license": "MIT",
5
5
  "author": "heartyoh",
6
- "version": "1.1.5",
6
+ "version": "1.1.14",
7
7
  "main": "dist/index.js",
8
8
  "module": "dist/index.js",
9
9
  "things-scene": true,
@@ -57,5 +57,5 @@
57
57
  "prettier --write"
58
58
  ]
59
59
  },
60
- "gitHead": "412dd47dbdd764d4bf0e13ca423b35667e641784"
60
+ "gitHead": "19643cfbb5de4f874ae7d0374d264828c3b6ad74"
61
61
  }
package/src/index.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  /*
2
2
  * Copyright © HatioLab Inc. All rights reserved.
3
3
  */
4
+
5
+ export { default as TabCard } from './tab-card'
6
+ export { default as TabContainer } from './tab-container'
4
7
  export { default as Tab } from './tab'
5
8
  export { default as TabButton } from './tab-button'
package/src/tab-button.ts CHANGED
@@ -25,7 +25,7 @@ export default class TabButton extends RectPath(Component) {
25
25
 
26
26
  prerender(context: CanvasRenderingContext2D) {
27
27
  super.prerender(context)
28
- let { fillStyle, activeFillStyle, activeLineColor, activeLineWidth, fontColor, activeFontColor } = this.model
28
+ let { fillStyle, activeFillStyle, activeLineColor, activeLineWidth, fontColor, activeFontColor } = this.state
29
29
 
30
30
  // backup style
31
31
  if (!this.hasOwnProperty('_fillStyle')) {
@@ -76,7 +76,7 @@ export default class TabButton extends RectPath(Component) {
76
76
  }
77
77
 
78
78
  onclick(e: MouseEvent) {
79
- (this.parent as Tab).activeIndex = this.index
79
+ ;(this.parent as Tab).activeIndex = this.index
80
80
  this.parent.invalidate()
81
81
  }
82
82
 
@@ -90,7 +90,7 @@ export default class TabButton extends RectPath(Component) {
90
90
  if (after.hasOwnProperty('lineWidth')) this._fontColor = after.fontColor
91
91
 
92
92
  if (after.hasOwnProperty('text')) {
93
- (this.parent as Tab).reference.getAt(this.index).set('text', after.text)
93
+ ;(this.parent as Tab).reference.getAt(this.index).set('text', after.text)
94
94
  }
95
95
 
96
96
  this.invalidate()
@@ -0,0 +1,76 @@
1
+ /*
2
+ * Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+ import { Component, ComponentNature, Container } from '@hatiolab/things-scene'
5
+
6
+ import TabContainer from './tab-container'
7
+
8
+ const NATURE: ComponentNature = {
9
+ mutable: false,
10
+ resizable: true,
11
+ rotatable: true,
12
+ properties: [
13
+ {
14
+ type: 'action',
15
+ label: 'remove',
16
+ name: 'remove',
17
+ property: {
18
+ icon: 'remove_circle',
19
+ action: function (tabCard: TabCard) {
20
+ let tabContainer = tabCard.parent as TabContainer
21
+ tabContainer.removeComponent(tabCard)
22
+ tabContainer.set('activeIndex', 0)
23
+ }
24
+ }
25
+ }
26
+ ]
27
+ }
28
+
29
+ export default class TabCard extends Container {
30
+ private _clickPoint?: Component
31
+
32
+ get hasTextProperty() {
33
+ return false
34
+ }
35
+
36
+ get showMoveHandle() {
37
+ return false
38
+ }
39
+
40
+ /*
41
+ * PATH 리스트를 직접 수정할 수 있는 지를 결정한다.
42
+ *
43
+ * 일반적으로 PATH는 바운드 생성을 위해서 논리적으로 생성되므로, 직접 수정하지 않는다.(return false)
44
+ * 그러나, 각 꼭지점들이 개별로 움직이는 다각형류는 path 라는 모델데이타를 가지므로, 직접수정이 가능할 수 있다.(return true)
45
+ *
46
+ * Immutable 컴포넌트의 형상을 바꾸는 방법은 바운드를 이용한 리사이즈나, 특별한 컨트롤을 통해서 가능하다.
47
+ */
48
+ get mutable() {
49
+ return false
50
+ }
51
+
52
+ /*
53
+ * BOUND를 통해서 리사이즈를 할 수 있는 지를 결정한다.
54
+ *
55
+ * 일반적으로 면적을 갖는 컴포넌트는 대체로 가능하다.(return true)
56
+ * 그러나, LINE 등 면적을 가지지않는 컴포넌트는 가능하지 않도록 정의한다.(return false)
57
+ */
58
+ get resizable() {
59
+ return false
60
+ }
61
+
62
+ /*
63
+ * 회전을 할 수 있는 지를 결정한다.
64
+ *
65
+ * 일반적으로 모든 컴포넌트는 가능하다.(return true)
66
+ */
67
+ get rotatable() {
68
+ return false
69
+ }
70
+
71
+ get nature() {
72
+ return NATURE
73
+ }
74
+ }
75
+
76
+ Component.register('tab-card', TabCard)
@@ -0,0 +1,204 @@
1
+ /*
2
+ * Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+ import { CardLayout, Component, ComponentNature, Container, Model, POINT, State } from '@hatiolab/things-scene'
5
+
6
+ import TabCard from './tab-card'
7
+
8
+ const LABEL_WIDTH = 25
9
+ const LABEL_HEIGHT = 25
10
+
11
+ function rgba(r: number, g: number, b: number, a: number) {
12
+ return `rgba(${r}, ${g}, ${b}, ${a})`
13
+ }
14
+
15
+ const NATURE: ComponentNature = {
16
+ mutable: false,
17
+ resizable: true,
18
+ rotatable: true,
19
+ properties: [
20
+ {
21
+ type: 'action',
22
+ label: 'add-card',
23
+ name: 'addCard',
24
+ property: {
25
+ icon: 'add_circle',
26
+ action: (tabContainer: TabContainer) => {
27
+ tabContainer.addCard()
28
+ }
29
+ }
30
+ },
31
+ {
32
+ type: 'number',
33
+ label: 'active index',
34
+ name: 'activeIndex'
35
+ }
36
+ ],
37
+ 'value-property': 'activeIndex',
38
+ help: 'scene/component/tab-container'
39
+ }
40
+
41
+ export default class TabContainer extends Container {
42
+ private _focused: boolean = false
43
+ private __down_point?: POINT
44
+
45
+ get nature() {
46
+ return NATURE
47
+ }
48
+
49
+ get layout() {
50
+ return CardLayout
51
+ }
52
+
53
+ get layoutConfig() {
54
+ return this.get('layoutConfig')
55
+ }
56
+
57
+ set layoutConfig(config) {
58
+ this.set('layoutConfig', config)
59
+ }
60
+
61
+ get activeCard(): TabCard {
62
+ return this.components[this.get('layoutConfig').activeIndex] as TabCard
63
+ }
64
+
65
+ get activeIndex() {
66
+ return this.get('activeIndex')
67
+ }
68
+
69
+ set activeIndex(activeIndex: number) {
70
+ this.set('activeIndex', Number(activeIndex))
71
+ }
72
+
73
+ ready() {
74
+ super.ready()
75
+
76
+ if (this.components.length == 0) this.addCard()
77
+ }
78
+
79
+ postrender(context: CanvasRenderingContext2D) {
80
+ if (!this.app.isViewMode && this._focused) {
81
+ var { left, top, width, fillStyle } = this.state
82
+
83
+ // tabCard 선택 탭 그리기
84
+ for (let i = 0; i < this.components.length; i++) {
85
+ context.beginPath()
86
+
87
+ context.rect(left - LABEL_WIDTH, top + i * LABEL_HEIGHT, LABEL_WIDTH, LABEL_HEIGHT)
88
+
89
+ let color = 255 - ((20 * (i + 1)) % 255)
90
+ context.fillStyle = rgba(color, color, color, 1)
91
+ context.fill()
92
+
93
+ context.closePath()
94
+ }
95
+
96
+ context.beginPath()
97
+
98
+ context.moveTo(left, top)
99
+ context.lineTo(left - LABEL_WIDTH, top)
100
+ context.lineTo(left - LABEL_WIDTH, top + this.components.length * LABEL_HEIGHT)
101
+ context.lineTo(left, top + this.components.length * LABEL_HEIGHT)
102
+
103
+ context.strokeStyle = '#ccc'
104
+ context.stroke()
105
+
106
+ context.closePath()
107
+ }
108
+
109
+ super.postrender(context)
110
+ }
111
+
112
+ contains(x: number, y: number) {
113
+ var contains = super.contains(x, y)
114
+
115
+ if (this.app.isViewMode) return contains
116
+
117
+ var { left, top, width } = this.bounds
118
+ var h = LABEL_HEIGHT
119
+
120
+ contains =
121
+ contains ||
122
+ // card selector 영역에 포함되는지
123
+ (x < Math.max(left - LABEL_WIDTH, left) &&
124
+ x > Math.min(left - LABEL_WIDTH, left) &&
125
+ y < Math.max(top + h * this.size(), top) &&
126
+ y > Math.min(top + h * this.size(), top))
127
+
128
+ if (contains) this._focused = true
129
+ else this._focused = false
130
+
131
+ this.invalidate()
132
+ return contains
133
+ }
134
+
135
+ onchange(after: State) {
136
+ if ('activeIndex' in after) {
137
+ this.layoutConfig = {
138
+ ...this.layoutConfig,
139
+ activeIndex: after.activeIndex
140
+ }
141
+ }
142
+ }
143
+
144
+ onmouseup(e: MouseEvent) {
145
+ var down_point = this.__down_point
146
+ delete this.__down_point
147
+
148
+ if (!down_point || down_point.x != e.offsetX || down_point.y != e.offsetY) {
149
+ return
150
+ }
151
+
152
+ var point = this.transcoordC2S(e.offsetX, e.offsetY)
153
+
154
+ var { left, top } = this.state
155
+
156
+ var x = point.x - left
157
+ var y = point.y - top
158
+
159
+ if (x > 0) return
160
+
161
+ y /= LABEL_HEIGHT
162
+ y = Math.floor(y)
163
+
164
+ if (!this.layoutConfig) this.layoutConfig = {}
165
+
166
+ if (y >= this.components.length) return
167
+
168
+ // /* 생성 버튼이 클릭되면, 새로운 tabCard를 추가한다. */
169
+ // if(y == this.components.length) {
170
+ // this.add(Model.compile({
171
+ // type: 'tab-card',
172
+ // width: 100,
173
+ // height: 100
174
+ // }))
175
+ // }
176
+ this.set('activeIndex', y)
177
+ }
178
+
179
+ onmousedown(e: MouseEvent) {
180
+ this.__down_point = {
181
+ x: e.offsetX,
182
+ y: e.offsetY
183
+ }
184
+ }
185
+
186
+ addCard() {
187
+ const color = 255 - ((20 * (this.components.length + 1)) % 255)
188
+ const hex = color.toString(16)
189
+
190
+ const tabCard = Model.compile({
191
+ type: 'tab-card',
192
+ fillStyle: `#${hex}${hex}${hex}`,
193
+ top: 0,
194
+ left: 0,
195
+ width: 100,
196
+ height: 100
197
+ })
198
+
199
+ this.addComponent(tabCard)
200
+ this.set('activeIndex', this.components.length - 1)
201
+ }
202
+ }
203
+
204
+ Component.register('tab-container', TabContainer)