@operato/data-tree 1.1.61

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/package.json ADDED
@@ -0,0 +1,80 @@
1
+ {
2
+ "name": "@operato/data-tree",
3
+ "version": "1.1.61",
4
+ "description": "User interface for tree structure data",
5
+ "author": "heartyoh",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.js",
8
+ "publishConfig": {
9
+ "access": "public",
10
+ "@operato:registry": "https://registry.npmjs.org"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/hatiolab/operato.git",
15
+ "directory": "webcomponents/data-tree"
16
+ },
17
+ "exports": {
18
+ ".": "./dist/src/index.js",
19
+ "./ox-tree.js": "./dist/src/ox-tree.js"
20
+ },
21
+ "typesVersions": {
22
+ "*": {
23
+ "ox-grist.js": [
24
+ "dist/src/ox-tree.d.ts"
25
+ ]
26
+ }
27
+ },
28
+ "scripts": {
29
+ "analyze": "cem analyze --litelement",
30
+ "start": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wds\"",
31
+ "build": "tsc && npm run analyze -- --exclude dist",
32
+ "prepublish": "tsc && npm run analyze -- --exclude dist",
33
+ "lint": "eslint --ext .ts,.html . --ignore-path ../../.gitignore && prettier \"**/*.ts\" --check --ignore-path ../../.gitignore",
34
+ "format": "eslint --ext .ts,.html . --fix --ignore-path ../../.gitignore && prettier \"**/*.ts\" --write --ignore-path ../../.gitignore",
35
+ "test": "tsc && wtr --coverage",
36
+ "test:watch": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wtr --watch\"",
37
+ "storybook": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wds -c .storybook/server.mjs\"",
38
+ "storybook:build": "tsc && build-storybook"
39
+ },
40
+ "dependencies": {
41
+ "@operato/styles": "^1.1.53",
42
+ "i18next": "^21.5.4",
43
+ "lit": "^2.5.0",
44
+ "lodash-es": "^4.17.21"
45
+ },
46
+ "devDependencies": {
47
+ "@custom-elements-manifest/analyzer": "^0.4.17",
48
+ "@hatiolab/prettier-config": "^1.0.0",
49
+ "@open-wc/eslint-config": "^8.0.2",
50
+ "@open-wc/testing": "^3.1.6",
51
+ "@types/lodash-es": "^4.17.5",
52
+ "@typescript-eslint/eslint-plugin": "^4.33.0",
53
+ "@typescript-eslint/parser": "^4.33.0",
54
+ "@web/dev-server": "^0.1.34",
55
+ "@web/dev-server-storybook": "^0.5.4",
56
+ "@web/test-runner": "^0.15.0",
57
+ "concurrently": "^5.3.0",
58
+ "eslint": "^7.32.0",
59
+ "eslint-config-prettier": "^8.3.0",
60
+ "husky": "^8.0.1",
61
+ "lint-staged": "^10.5.4",
62
+ "prettier": "^2.4.1",
63
+ "tslib": "^2.3.1",
64
+ "typescript": "^4.8.4"
65
+ },
66
+ "customElements": "custom-elements.json",
67
+ "prettier": "@hatiolab/prettier-config",
68
+ "husky": {
69
+ "hooks": {
70
+ "pre-commit": "lint-staged"
71
+ }
72
+ },
73
+ "lint-staged": {
74
+ "*.ts": [
75
+ "eslint --fix",
76
+ "prettier --write"
77
+ ]
78
+ },
79
+ "gitHead": "7b3fe5be41bdb4d84619a89232459bc3b5913418"
80
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './ox-tree'
package/src/ox-tree.ts ADDED
@@ -0,0 +1,212 @@
1
+ import { LitElement, css, html, TemplateResult } from 'lit'
2
+ import { customElement, property, state } from 'lit/decorators.js'
3
+
4
+ type TreeItem = {
5
+ label: string
6
+ children?: TreeItem[]
7
+ status?: { [state: string]: boolean | string }
8
+ }
9
+
10
+ @customElement('ox-tree')
11
+ export class OxTree extends LitElement {
12
+ static styles = [
13
+ css`
14
+ ul {
15
+ list-style: none;
16
+ padding-left: 20px;
17
+ overflow: hidden;
18
+ position: relative;
19
+ }
20
+
21
+ li {
22
+ cursor: pointer;
23
+ overflow: hidden;
24
+ }
25
+
26
+ span[expander] {
27
+ display: inline-block;
28
+ vertical-align: middle;
29
+ width: 20px;
30
+ height: 20px;
31
+ cursor: pointer;
32
+ position: relative;
33
+ }
34
+
35
+ span[expander]::before {
36
+ position: absolute;
37
+ top: 8px;
38
+ left: 6px;
39
+ display: block;
40
+ content: ' ';
41
+ border: 4px solid transparent;
42
+ border-top: 4px solid rgba(0, 0, 0, 0.65);
43
+ }
44
+
45
+ li[collapsed] > span[expander]::before {
46
+ transform: rotate(-90deg);
47
+ }
48
+
49
+ li[leaf] {
50
+ padding-left: 20px;
51
+ }
52
+
53
+ span[checkbox] {
54
+ display: inline-block;
55
+ vertical-align: middle;
56
+ width: 20px;
57
+ height: 20px;
58
+ cursor: pointer;
59
+ position: relative;
60
+ }
61
+
62
+ span[checkbox]::before {
63
+ cursor: pointer;
64
+ position: absolute;
65
+ top: 2px;
66
+ content: ' ';
67
+ display: block;
68
+ width: 16px;
69
+ height: 16px;
70
+ border: 1px solid #d9d9d9;
71
+ border-radius: 2px;
72
+ }
73
+
74
+ li[checked='checked'] > span[checkbox]::before {
75
+ background-color: #1890ff;
76
+ border-color: #1890ff;
77
+ }
78
+
79
+ li[checked='checked'] > span[checkbox]::after {
80
+ position: absolute;
81
+ content: ' ';
82
+ display: block;
83
+ top: 4px;
84
+ left: 5px;
85
+ width: 5px;
86
+ height: 9px;
87
+ border: 2px solid #fff;
88
+ border-top: none;
89
+ border-left: none;
90
+ -webkit-transform: rotate(45deg);
91
+ -ms-transform: rotate(45deg);
92
+ transform: rotate(45deg);
93
+ }
94
+
95
+ li[checked='half-checked'] > span[checkbox]::before {
96
+ background-color: #1890ff;
97
+ border-color: #1890ff;
98
+ }
99
+
100
+ li[checked='half-checked'] > span[checkbox]::after {
101
+ position: absolute;
102
+ content: ' ';
103
+ display: block;
104
+ top: 9px;
105
+ left: 3px;
106
+ width: 10px;
107
+ height: 2px;
108
+ background-color: #fff;
109
+ }
110
+ `
111
+ ]
112
+
113
+ @property({ type: Object }) data?: TreeItem
114
+
115
+ render() {
116
+ return this.data
117
+ ? html`
118
+ <ul @click=${this.onClickItem.bind(this)}>
119
+ ${this.renderItem(this.data)}
120
+ </ul>
121
+ `
122
+ : html``
123
+ }
124
+
125
+ renderItem(item: TreeItem): TemplateResult {
126
+ const { label, children, status = {} } = item
127
+ const expandable = children && children.length > 0
128
+ const { collapsed, checked } = status
129
+
130
+ return html`
131
+ <li checked=${checked} ?collapsed=${collapsed} ?leaf=${!expandable} .item=${item}>
132
+ ${expandable ? html` <span expander @click=${this.onClickExpander.bind(this)}></span> ` : html``}
133
+ <span checkbox></span>
134
+ ${label}
135
+ ${expandable && !collapsed
136
+ ? html`
137
+ <ul>
138
+ ${children.map(child => this.renderItem(child))}
139
+ </ul>
140
+ `
141
+ : html``}
142
+ </li>
143
+ `
144
+ }
145
+
146
+ onClickExpander(e: MouseEvent) {
147
+ e.stopPropagation()
148
+
149
+ const target = e.target as HTMLSpanElement
150
+ const itemElement = target!.closest('li') as HTMLLIElement
151
+
152
+ var item = (itemElement as any).item
153
+ item.status = {
154
+ ...item.status,
155
+ collapsed: !itemElement.hasAttribute('collapsed')
156
+ }
157
+
158
+ this.requestUpdate()
159
+ }
160
+
161
+ onClickItem(e: MouseEvent) {
162
+ e.stopPropagation()
163
+
164
+ const target = e.target as HTMLSpanElement
165
+ const itemElement = target!.closest('li') as HTMLLIElement
166
+
167
+ var item = (itemElement as any).item
168
+ var checked = itemElement.getAttribute('checked') || ''
169
+
170
+ this.walkTreeCheckedUpdate(item, checked == '' || checked == 'unchecked' ? 'checked' : 'unchecked')
171
+ this.updateCheckedAll(this.data!)
172
+
173
+ this.requestUpdate()
174
+ }
175
+
176
+ walkTreeCheckedUpdate(item: TreeItem, checked: string = '') {
177
+ const { children, status } = item
178
+ children?.forEach(child => this.walkTreeCheckedUpdate(child, checked))
179
+ item.status = {
180
+ ...status,
181
+ checked
182
+ }
183
+ }
184
+
185
+ updateCheckedAll(item: TreeItem) {
186
+ const { children, status } = item
187
+ if (!children || children.length == 0) {
188
+ return
189
+ }
190
+
191
+ children.forEach(child => this.updateCheckedAll(child))
192
+
193
+ var checked: string = ''
194
+
195
+ children.forEach(child => {
196
+ const { status = {} } = child
197
+
198
+ if (status.checked == 'half-checked') {
199
+ checked = 'half-checked'
200
+ } else if (status.checked == 'checked') {
201
+ checked = checked == 'checked' || checked == '' ? 'checked' : 'half-checked'
202
+ } else {
203
+ checked = checked == 'unchecked' || checked == '' ? 'unchecked' : 'half-checked'
204
+ }
205
+ })
206
+
207
+ item.status = {
208
+ ...status,
209
+ checked
210
+ }
211
+ }
212
+ }
@@ -0,0 +1,64 @@
1
+ import '../src/ox-tree.js'
2
+ import '@material/mwc-icon'
3
+
4
+ import { html, TemplateResult } from 'lit'
5
+
6
+ export default {
7
+ title: '3 modes in ox-tree',
8
+ component: 'ox-tree',
9
+ argTypes: {
10
+ data: { control: 'object' }
11
+ }
12
+ }
13
+
14
+ interface Story<T> {
15
+ (args: T): TemplateResult
16
+ args?: Partial<T>
17
+ argTypes?: Record<string, unknown>
18
+ }
19
+
20
+ interface ArgTypes {
21
+ data: object
22
+ }
23
+
24
+ const Template: Story<ArgTypes> = ({ data }: ArgTypes) => html`
25
+ <link href="https://fonts.googleapis.com/css?family=Material+Icons&display=block" rel="stylesheet" />
26
+
27
+ <ox-tree .data=${data}></ox-tree>
28
+ `
29
+
30
+ export const Regular = Template.bind({})
31
+ Regular.args = {
32
+ data: {
33
+ label: 'AAAAA',
34
+ children: [
35
+ {
36
+ label: 'AAAAA-1',
37
+ children: [
38
+ {
39
+ label: 'AAAAA-2'
40
+ }
41
+ ]
42
+ },
43
+ {
44
+ label: 'BBBBB-1',
45
+ children: [
46
+ {
47
+ label: 'BBBBB-2'
48
+ },
49
+ {
50
+ label: 'BBBBB-21'
51
+ }
52
+ ]
53
+ },
54
+ {
55
+ label: 'CCCCC-1',
56
+ children: [
57
+ {
58
+ label: 'CCCCC-2'
59
+ }
60
+ ]
61
+ }
62
+ ]
63
+ }
64
+ }
@@ -0,0 +1,142 @@
1
+ body {
2
+ /* theme color */
3
+ --primary-color-rgb: 130, 105, 96;
4
+ --primary-color: rgb(var(--primary-color-rgb));
5
+ --secondary-color-rgb: 78, 78, 90;
6
+ --secondary-color: rgb(var(--secondary-color-rgb));
7
+ --focus-color: var(--theme-white-color);
8
+ --primary-background-color: var(--secondary-color);
9
+ --secondary-background-color: #283644;
10
+ --main-section-background-color: #f5f2ee;
11
+ --theme-white-color: #fff;
12
+ --theme-black-color: rgba(0, 0, 0, 0.9);
13
+
14
+ --focus-background-color: var(--primary-color);
15
+ --primary-text-color: #3c3938;
16
+ --secondary-text-color: var(--primary-color);
17
+
18
+ --opacity-dark-color: rgba(0, 0, 0, 0.4);
19
+ --opacity-light-color: rgba(255, 255, 255, 0.8);
20
+
21
+ /* status color */
22
+ --status-success-color: #35a24a;
23
+ --status-warning-color: #ee8d03;
24
+ --status-danger-color: #d14946;
25
+ --status-info-color: #398ace;
26
+
27
+ /* common style */
28
+ --border-radius: 4px;
29
+ --border-dark-color: 1px solid rgba(0, 0, 0, 0.15);
30
+ --border-light-color: 1px solid rgba(255, 255, 255, 0.3);
31
+
32
+ --box-shadow: 2px 2px 3px 0px rgba(0, 0, 0, 0.1);
33
+
34
+ --theme-font: 'Noto', Helvetica;
35
+
36
+ --margin-default: 9px;
37
+ --margin-narrow: 4px;
38
+ --margin-wide: 15px;
39
+ --padding-default: var(--margin-default);
40
+ --padding-narrow: var(--margin-narrow);
41
+ --padding-wide: var(--margin-wide);
42
+
43
+ --scrollbar-thumb-color: rgba(57, 78, 100, 0.5);
44
+ --scrollbar-thumb-hover-color: var(--primary-color);
45
+
46
+ --fontsize-default: 14px;
47
+ --fontsize-small: 13px;
48
+ --fontsize-large: 16px;
49
+
50
+ /* app layout style */
51
+ --app-grid-template-area: 'header header header' 'nav main aside' 'nav footer aside';
52
+
53
+ /* title & description style */
54
+ --title-margin: var(--margin-narrow) 0;
55
+ --title-font: bold 24px var(--theme-font);
56
+ --title-text-color: var(--secondary-color);
57
+ --title-font-mobile: bold 20px var(--theme-font);
58
+
59
+ --page-description-margin: var(--margin-narrow) 0 var(--margin-wide) 0;
60
+ --page-description-font: normal var(--fontsize-default) / 1.2rem var(--theme-font);
61
+ --page-description-color: var(--secondary-text-color);
62
+
63
+ --subtitle-padding: 12px 5px 3px 5px;
64
+ --subtitle-font: bold 18px var(--theme-font);
65
+ --subtitle-text-color: var(--primary-color);
66
+ --subtitle-border-bottom: 1px solid var(--primary-color);
67
+
68
+ /* icon style */
69
+ --icon-tiny-size: 24px;
70
+ --icon-default-size: 36px;
71
+ --icon-big-size: 48px;
72
+ --icon-default-color: var(--theme-white-color);
73
+
74
+ /* material design component themes */
75
+ --mdc-theme-on-primary: var(--theme-white-color);
76
+ --mdc-theme-primary: var(--secondary-text-color);
77
+ --mdc-theme-on-secondary: var(--theme-white-color);
78
+ --mdc-theme-secondary: var(--primary-color);
79
+ --mdc-button-outline-color: var(--primary-color);
80
+ --mdc-danger-button-primary-color: var(--status-danger-color);
81
+ --mdc-danger-button-outline-color: var(--status-danger-color);
82
+ --mdc-button-outline-width: 1px;
83
+ --mdc-button-horizontal-padding: 16px;
84
+
85
+ /* button style */
86
+ --button-background-color: #fafbfc;
87
+ --button-background-focus-color: var(--primary-color);
88
+ --button-border: var(--border-dark-color);
89
+ --button-border-radius: var(--border-radius);
90
+ --button-margin: var(--margin-default) var(--margin-default) var(--margin-default) 0;
91
+ --button-padding: var(--padding-default);
92
+ --button-color: var(--secondary-color);
93
+ --button-font: normal 15px var(--theme-font);
94
+ --button-text-transform: capitalize;
95
+ --button-active-box-shadow: 1px 1px 1px 0px rgba(0, 0, 0, 0.2);
96
+ --button-activ-border: 1px solid var(--primary-color);
97
+
98
+ --button-primary-background-color: var(--primary-color);
99
+ --button-primary-active-background-color: var(--status-success-color);
100
+ --button-primary-padding: var(--margin-default) var(--margin-wide);
101
+ --button-primary-color: var(--theme-white-color);
102
+ --button-primary-font: bold 16px var(--theme-font);
103
+
104
+ /* table style */
105
+ --th-padding: var(--padding-default) 0 var(--padding-default) var(--padding-default);
106
+ --th-border-top: 2px solid var(--secondary-color);
107
+ --th-text-transform: capitalize;
108
+ --th-font: bold var(--fontsize-small) var(--theme-font);
109
+ --th-color: rgba(var(--secondary-color-rgb), 0.8);
110
+
111
+ --tr-background-color: var(--theme-white-color);
112
+ --tr-background-odd-color: rgba(255, 255, 255, 0.4);
113
+ --tr-background-hover-color: #e1f5fe;
114
+ --td-border-bottom: 1px solid rgba(0, 0, 0, 0.09);
115
+ --td-padding: var(--padding-default);
116
+ --td-font: normal 13px var(--theme-font);
117
+ --td-color: var(--secondary-color);
118
+
119
+ /* form style */
120
+ --label-font: normal var(--fontsize-default) var(--theme-font);
121
+ --label-color: var(--secondary-color);
122
+ --label-text-transform: capitalize;
123
+ --input-margin: var(--margin-narrow) 0;
124
+ --input-padding: var(--padding-default);
125
+ --input-min-width: 200px;
126
+ --input-font: normal var(--fontsize-default) var(--theme-font);
127
+ --input-hint-font: normal var(--fontsize-small) var(--theme-font);
128
+ --input-hint-color: #666;
129
+ --input-container-max-width: 900px;
130
+ --fieldset-margin: var(--padding-wide) 0;
131
+ --fieldset-padding: 0 var(--padding-wide) var(--padding-wide) var(--padding-wide);
132
+ --legend-padding: var(--padding-default) 0;
133
+ --legend-color: var(--secondary-text-color);
134
+ --legend-font: bold 16px var(--theme-font);
135
+ }
136
+
137
+ @media only screen and (max-width: 460px) {
138
+ body {
139
+ /* subtitle style */
140
+ --subtitle-margin: 0;
141
+ }
142
+ }
@@ -0,0 +1,75 @@
1
+ body {
2
+ --form-border: none;
3
+ --form-margin: var(--margin-wide);
4
+ --form-max-width: 700px;
5
+ --form-multi-column-max-width: 100%;
6
+ --form-sublabel-font: normal 13px var(--theme-font);
7
+ --form-sublabel-color: var(--secondary-color);
8
+ --form-grid-gap: 12px 5px;
9
+
10
+ --legend-padding: var(--padding-default) 0;
11
+ --legend-font: bold 16px var(--theme-font);
12
+ --legend-text-color: var(--secondary-text-color);
13
+ --legend-border-bottom: 1px solid var(--primary-color);
14
+
15
+ --label-padding: 3px 0;
16
+ --label-font: normal 14px var(--theme-font);
17
+ --label-color: var(--secondary-color);
18
+
19
+ --input-field-border: 1px solid rgba(0, 0, 0, 0.2);
20
+ --input-field-border-radius: var(--border-radius);
21
+ --input-field-padding: 2px 9px;
22
+ --input-field-font: normal 14px var(--theme-font);
23
+
24
+ --search-panel-background-color: rgba(0, 0, 0, 0.1);
25
+ --search-panel-search-iconbutton-size: var(--icon-default-size);
26
+ --search-form-icon-color: var(--primary-color);
27
+ --search-form-box-shadow: 0 2px 3px 1px rgba(0, 0, 0, 0.15);
28
+ --search-form-box-padding: 15px 30px 15px 15px;
29
+ --search-form-background-color: #fff;
30
+ --search-form-narrow-background-color: var(--primary-color);
31
+ --search-form-narrow-text-color: #fff;
32
+
33
+ --file-uploader-border: 1px solid rgba(0, 0, 0, 0.1);
34
+ --file-uploader-background-color: var(--main-section-background-color);
35
+ --file-uploader-font: normal 12px/20px var(--theme-font);
36
+ --file-uploader-color: var(--secondary-color);
37
+ --file-uploader-icon-color: var(--primary-color);
38
+ --file-uploader-candrop-background-color: #fffde9;
39
+ --file-uploader-label-padding: 3px 20px;
40
+ --file-uploader-label-border-radius: var(--border-radius);
41
+ --file-uploader-label-background-color: var(--secondary-color);
42
+ --file-uploader-label-font: normal 12px var(--theme-font);
43
+ --file-uploader-label-color: #fff;
44
+ --file-uploader-li-padding: 2px 5px 0px 5px;
45
+ --file-uploader-li-border-bottom: 1px dotted rgba(0, 0, 0, 0.1);
46
+ --file-uploader-li-icon-margin: 2px 0 2px 5px;
47
+ --file-uploader-li-icon-font: normal 15px var(--mdc-icon-font, 'Material Icons');
48
+ --file-uploader-li-icon-focus-color: var(--primary-color);
49
+ }
50
+
51
+ @media screen and (max-width: 480px) {
52
+ body {
53
+ --label-font: normal 15px var(--theme-font);
54
+ }
55
+ }
56
+
57
+ @media (min-width: 481px) and (max-width: 1024px) {
58
+ body {
59
+ --form-margin: 15px 0;
60
+ --form-multi-column-max-width: 100%;
61
+ --form-container-padding: 0 9px 12px 9px;
62
+ --label-font: normal 14px var(--theme-font);
63
+ --input-field-font: normal 15px var(--theme-font);
64
+ --input-field-padding: 3px 5px;
65
+ }
66
+ }
67
+
68
+ @media only screen and (max-width: 925px) {
69
+ body {
70
+ --form-margin: 14px 0;
71
+ --form-multi-column-max-width: 100%;
72
+ --form-container-padding: 0 9px 12px 9px;
73
+ --input-field-padding: 3px 5px;
74
+ }
75
+ }