@operato/attribute 1.2.41

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 (68) hide show
  1. package/.editorconfig +29 -0
  2. package/.storybook/main.js +3 -0
  3. package/.storybook/server.mjs +8 -0
  4. package/CHANGELOG.md +11 -0
  5. package/README.md +75 -0
  6. package/dist/src/grist-editor/index.d.ts +1 -0
  7. package/dist/src/grist-editor/index.js +7 -0
  8. package/dist/src/grist-editor/index.js.map +1 -0
  9. package/dist/src/grist-editor/ox-grist-editor-attribute.d.ts +12 -0
  10. package/dist/src/grist-editor/ox-grist-editor-attribute.js +81 -0
  11. package/dist/src/grist-editor/ox-grist-editor-attribute.js.map +1 -0
  12. package/dist/src/grist-editor/ox-grist-editor-attributes.d.ts +12 -0
  13. package/dist/src/grist-editor/ox-grist-editor-attributes.js +81 -0
  14. package/dist/src/grist-editor/ox-grist-editor-attributes.js.map +1 -0
  15. package/dist/src/grist-editor/ox-popup-attribute.d.ts +13 -0
  16. package/dist/src/grist-editor/ox-popup-attribute.js +92 -0
  17. package/dist/src/grist-editor/ox-popup-attribute.js.map +1 -0
  18. package/dist/src/grist-editor/ox-popup-attributes.d.ts +13 -0
  19. package/dist/src/grist-editor/ox-popup-attributes.js +92 -0
  20. package/dist/src/grist-editor/ox-popup-attributes.js.map +1 -0
  21. package/dist/src/index.d.ts +1 -0
  22. package/dist/src/index.js +2 -0
  23. package/dist/src/index.js.map +1 -0
  24. package/dist/src/ox-attribute-form.d.ts +14 -0
  25. package/dist/src/ox-attribute-form.js +199 -0
  26. package/dist/src/ox-attribute-form.js.map +1 -0
  27. package/dist/src/ox-attribute-view.d.ts +12 -0
  28. package/dist/src/ox-attribute-view.js +176 -0
  29. package/dist/src/ox-attribute-view.js.map +1 -0
  30. package/dist/src/types.d.ts +23 -0
  31. package/dist/src/types.js +2 -0
  32. package/dist/src/types.js.map +1 -0
  33. package/dist/stories/ox-attribute-form.stories.d.ts +18 -0
  34. package/dist/stories/ox-attribute-form.stories.js +80 -0
  35. package/dist/stories/ox-attribute-form.stories.js.map +1 -0
  36. package/dist/stories/ox-attribute-view.stories.d.ts +18 -0
  37. package/dist/stories/ox-attribute-view.stories.js +73 -0
  38. package/dist/stories/ox-attribute-view.stories.js.map +1 -0
  39. package/dist/stories/ox-grist-editor-attribute.stories.d.ts +25 -0
  40. package/dist/stories/ox-grist-editor-attribute.stories.js +310 -0
  41. package/dist/stories/ox-grist-editor-attribute.stories.js.map +1 -0
  42. package/dist/stories/ox-grist-editor-attributes.stories.d.ts +25 -0
  43. package/dist/stories/ox-grist-editor-attributes.stories.js +310 -0
  44. package/dist/stories/ox-grist-editor-attributes.stories.js.map +1 -0
  45. package/dist/tsconfig.tsbuildinfo +1 -0
  46. package/package.json +106 -0
  47. package/src/grist-editor/index.ts +10 -0
  48. package/src/grist-editor/ox-grist-editor-attributes.ts +94 -0
  49. package/src/grist-editor/ox-popup-attributes.ts +93 -0
  50. package/src/index.ts +1 -0
  51. package/src/ox-attribute-form.ts +218 -0
  52. package/src/ox-attribute-view.ts +182 -0
  53. package/src/types.ts +23 -0
  54. package/stories/ox-attribute-form.stories.ts +94 -0
  55. package/stories/ox-attribute-view.stories.ts +87 -0
  56. package/stories/ox-grist-editor-attributes.stories.ts +328 -0
  57. package/themes/app-theme.css +142 -0
  58. package/themes/form-theme.css +75 -0
  59. package/themes/grist-theme.css +194 -0
  60. package/themes/oops-theme.css +26 -0
  61. package/themes/report-theme.css +47 -0
  62. package/translations/en.json +4 -0
  63. package/translations/ko.json +4 -0
  64. package/translations/ms.json +4 -0
  65. package/translations/zh.json +1 -0
  66. package/tsconfig.json +23 -0
  67. package/web-dev-server.config.mjs +27 -0
  68. package/web-test-runner.config.mjs +41 -0
package/package.json ADDED
@@ -0,0 +1,106 @@
1
+ {
2
+ "name": "@operato/attribute",
3
+ "description": "WebApplication attribute supporting components following open-wc recommendations",
4
+ "author": "heartyoh",
5
+ "version": "1.2.41",
6
+ "main": "dist/src/index.js",
7
+ "module": "dist/src/index.js",
8
+ "exports": {
9
+ ".": "./dist/src/index.js",
10
+ "./grist-editor": "./dist/src/grist-editor/index.js",
11
+ "./grist-editor/ox-grist-editor-attributes.js": "./dist/src/grist-editor/ox-grist-editor-attributes.js",
12
+ "./ox-attribute-form.js": "./dist/src/ox-attribute-form.js",
13
+ "./ox-attribute-view.js": "./dist/src/ox-attribute-view.js",
14
+ "./types.js": "./dist/src/types.js"
15
+ },
16
+ "typesVersions": {
17
+ "*": {
18
+ "grist-editor": [
19
+ "dist/src/grist-editor/index.d.ts"
20
+ ],
21
+ "grist-editor/ox-grist-editor-attributes.js": [
22
+ "dist/src/grist-editor/ox-grist-editor-attributes.d.ts"
23
+ ],
24
+ "ox-attribute-form.js": [
25
+ "dist/src/ox-attribute-form.d.ts"
26
+ ],
27
+ "ox-attribute-view.js": [
28
+ "dist/src/ox-attribute-view.d.ts"
29
+ ],
30
+ "types.js": [
31
+ "dist/src/types.d.ts"
32
+ ]
33
+ }
34
+ },
35
+ "license": "MIT",
36
+ "publishConfig": {
37
+ "access": "public",
38
+ "@operato:registry": "https://registry.npmjs.org"
39
+ },
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "git+https://github.com/hatiolab/operato.git",
43
+ "directory": "webcomponents/attribute"
44
+ },
45
+ "scripts": {
46
+ "analyze": "cem analyze --litelement",
47
+ "start": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wds\"",
48
+ "build": "tsc && npm run analyze -- --exclude dist",
49
+ "prepublish": "tsc && npm run analyze -- --exclude dist",
50
+ "lint": "eslint --ext .ts,.html . --ignore-path .gitignore && prettier \"**/*.ts\" --check --ignore-path .gitignore",
51
+ "format": "eslint --ext .ts,.html . --fix --ignore-path .gitignore && prettier \"**/*.ts\" --write --ignore-path .gitignore",
52
+ "test": "tsc && wtr --coverage",
53
+ "test:watch": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wtr --watch\"",
54
+ "storybook": "tsc && npm run analyze -- --exclude dist && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wds -c .storybook/server.mjs\"",
55
+ "storybook:build": "tsc && npm run analyze -- --exclude dist && build-storybook"
56
+ },
57
+ "dependencies": {
58
+ "@material/mwc-button": "^0.27.0",
59
+ "@material/mwc-icon": "^0.27.0",
60
+ "@material/mwc-icon-button": "^0.27.0",
61
+ "@operato/data-grist": "^1.2.39",
62
+ "@operato/graphql": "^1.2.35",
63
+ "@operato/grist-editor": "^1.2.40",
64
+ "@operato/i18n": "^1.2.35",
65
+ "@operato/input": "^1.2.39",
66
+ "@operato/popup": "^1.2.38",
67
+ "@operato/property-editor": "^1.2.40",
68
+ "@operato/shell": "^1.2.38",
69
+ "@operato/styles": "^1.2.35",
70
+ "@operato/utils": "^1.2.35",
71
+ "lit": "^2.5.0"
72
+ },
73
+ "devDependencies": {
74
+ "@custom-elements-manifest/analyzer": "^0.8.1",
75
+ "@hatiolab/prettier-config": "^1.0.0",
76
+ "@open-wc/eslint-config": "^10.0.0",
77
+ "@open-wc/testing": "^3.1.6",
78
+ "@typescript-eslint/eslint-plugin": "^5.59.1",
79
+ "@typescript-eslint/parser": "^5.59.1",
80
+ "@web/dev-server": "^0.2.1",
81
+ "@web/dev-server-storybook": "^0.7.1",
82
+ "@web/test-runner": "^0.16.1",
83
+ "concurrently": "^8.0.1",
84
+ "eslint": "^8.39.0",
85
+ "eslint-config-prettier": "^8.3.0",
86
+ "husky": "^8.0.1",
87
+ "lint-staged": "^13.2.2",
88
+ "prettier": "^2.4.1",
89
+ "tslib": "^2.3.1",
90
+ "typescript": "^5.0.4"
91
+ },
92
+ "customElements": "custom-elements.json",
93
+ "prettier": "@hatiolab/prettier-config",
94
+ "husky": {
95
+ "hooks": {
96
+ "pre-commit": "lint-staged"
97
+ }
98
+ },
99
+ "lint-staged": {
100
+ "*.ts": [
101
+ "eslint --fix",
102
+ "prettier --write"
103
+ ]
104
+ },
105
+ "gitHead": "b5584b413b09193583b4be1652e4bfebcc6d8d7a"
106
+ }
@@ -0,0 +1,10 @@
1
+ import { OxGristRendererJson5, registerEditor, registerRenderer } from '@operato/data-grist'
2
+
3
+ import { OxGristEditorAttribute } from './ox-grist-editor-attributes'
4
+
5
+ /* register grist renderer/editor for id */
6
+ registerEditor('attributes', OxGristEditorAttribute)
7
+
8
+ registerRenderer('attributes', OxGristRendererJson5)
9
+
10
+ export * from './ox-grist-editor-attributes'
@@ -0,0 +1,94 @@
1
+ /**
2
+ * @license Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+
5
+ import './ox-popup-attributes.js'
6
+
7
+ import { html } from 'lit'
8
+ import { customElement } from 'lit/decorators.js'
9
+ import { cloneDeep } from 'lodash-es'
10
+
11
+ import { OxGristEditor } from '@operato/data-grist'
12
+ import { i18next } from '@operato/i18n'
13
+ import { openPopup, PopupHandle } from '@operato/popup'
14
+
15
+ @customElement('ox-grist-editor-attributes')
16
+ export class OxGristEditorAttribute extends OxGristEditor {
17
+ private popup?: PopupHandle
18
+
19
+ get editorTemplate() {
20
+ const value = typeof this.value === 'object' ? JSON.stringify(this.value) : this.value
21
+ return html`<div tabindex="0">${value || ''}</div> `
22
+ }
23
+
24
+ _onclick(e: Event): void {
25
+ e.stopPropagation()
26
+ this.openPopup()
27
+ }
28
+
29
+ _onkeydown(e: KeyboardEvent): void {
30
+ const key = e.key
31
+ if (key == 'Enter') {
32
+ e.stopPropagation()
33
+ this.openPopup()
34
+ }
35
+ }
36
+
37
+ async openPopup() {
38
+ if (this.popup) {
39
+ delete this.popup
40
+ }
41
+
42
+ var { options } = this.column.record
43
+ var { attributeSet } = options || {}
44
+
45
+ if (typeof options === 'function') {
46
+ options = await options.call(this, this.value, this.column, this.record, this.row, this.field)
47
+ }
48
+
49
+ const { name, help, objectified = false } = options
50
+
51
+ const confirmCallback = (newval: any) => {
52
+ this.dispatchEvent(
53
+ new CustomEvent('field-change', {
54
+ bubbles: true,
55
+ composed: true,
56
+ detail: {
57
+ before: this.value,
58
+ after: !objectified ? JSON.stringify(newval) : newval,
59
+ record: this.record,
60
+ column: this.column,
61
+ row: this.row
62
+ }
63
+ })
64
+ )
65
+ }
66
+
67
+ try {
68
+ var value: any =
69
+ !objectified && typeof this.value === 'string' ? JSON.parse(this.value) : cloneDeep(this.value || {})
70
+ } catch (e) {
71
+ var value: any = {}
72
+ }
73
+
74
+ /*
75
+ 주의 : 이 팝업 템플릿은 layout 모듈에 의해서 render 되므로,
76
+ layout의 구성에 변화가 발생하면, 다시 render된다.
77
+ 이 팝업이 떠 있는 상태에서, 또 다른 팝업이 뜨는 경우도 layout 구성의 변화를 야기한다. (overlay의 갯수의 증가)
78
+ 이 경우 value, options, confirmCallback 등 클로져를 사용한 것들이 초기 바인딩된 값으로 다시 바인딩되게 되는데,
79
+ 만약, 템플릿 내부에서 이들 속성의 레퍼런스가 변화했다면, 원래 상태로 되돌아가는 현상이 발생하게 된다.
80
+ 따라서, 가급적 이들 속성의 레퍼런스를 변화시키지 않는 것이 좋다.
81
+ */
82
+ var template = html`
83
+ <ox-popup-attributes .value=${value} .attributeSet=${attributeSet} .confirmCallback=${confirmCallback}>
84
+ </ox-popup-attributes>
85
+ `
86
+
87
+ this.popup = openPopup(template, {
88
+ backdrop: true,
89
+ size: 'large',
90
+ title: `${name?.toUpperCase() || ''} ${i18next.t('field.attributes')}`,
91
+ help
92
+ })
93
+ }
94
+ }
@@ -0,0 +1,93 @@
1
+ import '../ox-attribute-form.js'
2
+
3
+ import { css, html, LitElement } from 'lit'
4
+ import { customElement, property } from 'lit/decorators.js'
5
+
6
+ import { i18next } from '@operato/i18n'
7
+ import { closePopup } from '@operato/popup'
8
+ import { ScrollbarStyles } from '@operato/styles'
9
+
10
+ import { AttributeSet } from '../types.js'
11
+
12
+ @customElement('ox-popup-attributes')
13
+ export class OxPopupAttributes extends LitElement {
14
+ static styles = [
15
+ ScrollbarStyles,
16
+ css`
17
+ :host {
18
+ display: flex;
19
+ flex-direction: column;
20
+
21
+ background-color: #fff;
22
+
23
+ width: var(--overlay-center-normal-width, 50%);
24
+ height: var(--overlay-center-normal-height, 50%);
25
+ }
26
+
27
+ ox-data-item-spec {
28
+ flex: 1;
29
+ overflow-y: auto;
30
+ padding: var(--padding-wide);
31
+ }
32
+
33
+ span {
34
+ flex: 1;
35
+
36
+ display: flex;
37
+ align-items: center;
38
+ justify-content: center;
39
+
40
+ color: var(--primary-color);
41
+ }
42
+
43
+ .button-container {
44
+ display: flex;
45
+ margin-left: auto;
46
+ }
47
+ `
48
+ ]
49
+
50
+ @property({ type: Object }) value: any
51
+ @property({ type: Object }) attributeSet?: AttributeSet
52
+ @property({ type: Object }) confirmCallback!: (newval: any) => void
53
+
54
+ render() {
55
+ var attributeSet = this.attributeSet || {}
56
+
57
+ return html`
58
+ <ox-attribute-form .value=${this.value} .attributeSet=${attributeSet} @change=${this.onChange.bind(this)}>
59
+ </ox-attribute-form>
60
+
61
+ <div class="button-container">
62
+ <mwc-button @click=${this.onCancel.bind(this)}>${i18next.t('button.cancel')}</mwc-button>
63
+ <mwc-button @click=${this.onConfirm.bind(this)}>${i18next.t('button.confirm')}</mwc-button>
64
+ </div>
65
+ `
66
+ }
67
+
68
+ private onChange(e: CustomEvent) {
69
+ e.stopPropagation()
70
+
71
+ /*
72
+ 주의 : 이 팝업 템플릿은 layout 모듈에 의해서 render 되므로,
73
+ layout의 구성에 변화가 발생하면, 다시 render된다.
74
+ 이 팝업이 떠 있는 상태에서, 또 다른 팝업이 뜨는 경우도 layout 구성의 변화를 야기한다. (overlay의 갯수의 증가)
75
+ 이 경우 value, options, confirmCallback 등 클로져를 사용한 것들이 초기 바인딩된 값으로 다시 바인딩되게 되는데,
76
+ 만약, 템플릿 내부에서 이들 속성의 레퍼런스가 변화했다면, 원래 상태로 되돌아가는 현상이 발생하게 된다.
77
+ 따라서, 가급적 이들 속성의 레퍼런스를 변화시키지 않는 것이 좋다.
78
+ (이 팝업 클래스를 템플릿으로 사용한 곳의 코드를 참조하세요.)
79
+ =>
80
+ 이런 이유로, Object.assign(...)을 사용하였다.
81
+ */
82
+ this.value = e.detail
83
+ }
84
+
85
+ private onCancel(e: Event) {
86
+ closePopup(this)
87
+ }
88
+
89
+ private onConfirm(e: Event) {
90
+ this.confirmCallback && this.confirmCallback(this.value)
91
+ closePopup(this)
92
+ }
93
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './types.js'
@@ -0,0 +1,218 @@
1
+ import '@operato/input/ox-input-file.js'
2
+
3
+ import { css, html, LitElement } from 'lit'
4
+ import { customElement, property } from 'lit/decorators.js'
5
+
6
+ import { AttributeSet } from './types.js'
7
+
8
+ @customElement('ox-attribute-form')
9
+ export class OxAttributeForm extends LitElement {
10
+ static styles = css`
11
+ :host {
12
+ display: flex;
13
+ flex-direction: row;
14
+ --item-description-font: normal 0.8rem/1rem var(--theme-font);
15
+ --item-description-color: var(--page-description-color);
16
+ }
17
+
18
+ h2 {
19
+ margin: var(--title-margin);
20
+ font: var(--title-font);
21
+ color: var(--title-text-color);
22
+ text-transform: capitalize;
23
+ text-align: center;
24
+ }
25
+
26
+ h3 {
27
+ margin: var(--page-description-margin);
28
+ font: var(--page-description-font);
29
+ color: var(--page-description-color);
30
+ text-transform: capitalize;
31
+ text-align: center;
32
+ }
33
+
34
+ form {
35
+ flex: 1;
36
+
37
+ display: flex;
38
+ flex-direction: column;
39
+ }
40
+
41
+ label {
42
+ display: grid;
43
+
44
+ grid-template-rows: auto 1fr;
45
+ grid-template-columns: 1fr 5fr;
46
+ grid-template-areas: 'name description' 'empty inputs';
47
+
48
+ grid-gap: 9px;
49
+ align-items: center;
50
+ margin-bottom: var(--margin-default);
51
+ }
52
+
53
+ label:nth-child(odd) {
54
+ background-color: var(--main-section-background-color);
55
+ padding: var(--padding-default) 0;
56
+ }
57
+
58
+ div[name] {
59
+ grid-area: name;
60
+ font: var(--label-font);
61
+ color: var(--label-color);
62
+ text-align: right;
63
+ }
64
+
65
+ div[description] {
66
+ grid-area: description;
67
+ opacity: 0.7;
68
+ font: var(--item-description-font);
69
+ color: var(--item-description-color);
70
+ text-align: left;
71
+ }
72
+
73
+ div[description] * {
74
+ vertical-align: middle;
75
+ }
76
+
77
+ div[description] mwc-icon {
78
+ margin-top: -3px;
79
+ font-size: 0.9rem;
80
+ }
81
+
82
+ div[elements] {
83
+ grid-area: inputs;
84
+ display: flex;
85
+ flex-direction: row;
86
+ flex-wrap: wrap;
87
+ gap: 10px;
88
+ padding-right: var(--padding-default);
89
+ }
90
+
91
+ div[elements] * {
92
+ flex: 1;
93
+ }
94
+
95
+ div[elements] input,
96
+ div[elements] select {
97
+ border: var(--input-field-border);
98
+ border-radius: var(--input-field-border-radius);
99
+ padding: var(--input-field-padding);
100
+ font: var(--input-field-font);
101
+ }
102
+
103
+ @media only screen and (max-width: 460px) {
104
+ label {
105
+ display: grid;
106
+
107
+ grid-template-rows: auto auto 1fr;
108
+ grid-template-columns: 1fr;
109
+ grid-template-areas: 'name' 'description' 'inputs';
110
+
111
+ grid-gap: 9px;
112
+ align-items: center;
113
+ margin-bottom: var(--margin-default);
114
+ }
115
+
116
+ div[name] {
117
+ text-align: left;
118
+ }
119
+ }
120
+ `
121
+
122
+ @property({ type: Object }) attributeSet?: AttributeSet
123
+ @property({ type: Object }) value?: { [tag: string]: any }
124
+
125
+ render() {
126
+ return html` <form @change=${(e: Event) => this.onChange(e)}>
127
+ <h2>${this.attributeSet?.entity || ''}</h2>
128
+ <h3>${this.attributeSet?.description || ''}</h3>
129
+ ${this.buildInputs()}
130
+ </form>`
131
+ }
132
+
133
+ private onChange(e: Event) {
134
+ this.value = this.buildValue()
135
+
136
+ this.dispatchEvent(
137
+ new CustomEvent('change', {
138
+ bubbles: true,
139
+ composed: true,
140
+ detail: this.value
141
+ })
142
+ )
143
+ }
144
+
145
+ private buildInputs() {
146
+ const items = this.attributeSet?.items.filter(item => item.active)
147
+
148
+ return (items || []).map(item => {
149
+ const { name, description, tag, type, options = {} } = item
150
+
151
+ const value = this.value && this.value[tag]
152
+
153
+ switch (type) {
154
+ case 'select':
155
+ var element = html` <select .name=${tag}>
156
+ <option value=""></option>
157
+ ${(options.options || []).map(
158
+ option => html`<option value=${option.value} ?selected=${option.value === value}>${option.text}</option>`
159
+ )}
160
+ </select>`
161
+ break
162
+
163
+ case 'boolean':
164
+ var element = html` <input type="checkbox" name=${tag} .checked=${value} />`
165
+ break
166
+
167
+ case 'number':
168
+ var element = html` <input type="number" name=${tag} value=${value} />`
169
+ break
170
+
171
+ case 'date':
172
+ var element = html` <input type="date" name=${tag} value=${value} />`
173
+ break
174
+
175
+ case 'datetime':
176
+ var element = html` <input type="datetime-local" name=${tag} value=${value} />`
177
+ break
178
+
179
+ case 'file':
180
+ var element = html`<ox-input-file
181
+ name=${tag}
182
+ label="Attach Files"
183
+ accept="*/*"
184
+ multiple="true"
185
+ hide-filelist
186
+ ></ox-input-file>`
187
+
188
+ case 'string':
189
+ default:
190
+ var element = html` <input type="text" name=${tag} value=${value} />`
191
+ }
192
+
193
+ return html` <label .title=${description}>
194
+ <div name>${name}</div>
195
+ <div description><mwc-icon>info_outline</mwc-icon> ${description}</div>
196
+ <div elements>${element}</div>
197
+ </label>`
198
+ })
199
+ }
200
+
201
+ private buildValue() {
202
+ const items = this.attributeSet!.items
203
+
204
+ return (items || []).reduce((sum, item) => {
205
+ const { tag, type } = item
206
+
207
+ const editors = Array.prototype.slice.call(
208
+ this.renderRoot.querySelectorAll(`[name=${tag}]`) as NodeListOf<HTMLInputElement>
209
+ ) as HTMLInputElement[]
210
+
211
+ if (editors.length > 0) {
212
+ sum[tag] = editors.map(editor => (type === 'boolean' ? editor.checked : editor.value))
213
+ }
214
+
215
+ return sum
216
+ }, {} as { [tag: string]: any })
217
+ }
218
+ }
@@ -0,0 +1,182 @@
1
+ import '@operato/input/ox-input-file.js'
2
+
3
+ import { css, html, LitElement } from 'lit'
4
+ import { customElement, property } from 'lit/decorators.js'
5
+
6
+ import { AttributeSet } from './types.js'
7
+
8
+ @customElement('ox-attribute-view')
9
+ export class OxAttributeView extends LitElement {
10
+ static styles = css`
11
+ :host {
12
+ display: flex;
13
+ flex-direction: row;
14
+
15
+ --item-description-font: normal 0.8rem/1rem var(--theme-font);
16
+ --item-description-color: var(--page-description-color);
17
+ }
18
+
19
+ h2 {
20
+ margin: var(--title-margin);
21
+ font: var(--title-font);
22
+ color: var(--title-text-color);
23
+ text-transform: capitalize;
24
+ text-align: center;
25
+ }
26
+
27
+ h3 {
28
+ margin: var(--page-description-margin);
29
+ font: var(--page-description-font);
30
+ color: var(--page-description-color);
31
+ text-transform: capitalize;
32
+ text-align: center;
33
+ }
34
+
35
+ form {
36
+ flex: 1;
37
+
38
+ display: flex;
39
+ flex-direction: column;
40
+ }
41
+
42
+ label {
43
+ display: grid;
44
+
45
+ grid-template-rows: auto 1fr;
46
+ grid-template-columns: 1fr 5fr;
47
+ grid-template-areas: 'name description' 'empty inputs';
48
+
49
+ grid-gap: 9px;
50
+ align-items: center;
51
+ margin-bottom: var(--margin-default);
52
+ }
53
+
54
+ label:nth-child(odd) {
55
+ background-color: var(--main-section-background-color);
56
+ padding: var(--padding-default) 0;
57
+ }
58
+
59
+ div[name] {
60
+ grid-area: name;
61
+ font: var(--label-font);
62
+ color: var(--label-color);
63
+ text-align: right;
64
+ }
65
+
66
+ div[description] {
67
+ grid-area: description;
68
+ opacity: 0.7;
69
+ font: var(--item-description-font);
70
+ color: var(--item-description-color);
71
+ text-align: left;
72
+ }
73
+
74
+ div[description] * {
75
+ vertical-align: middle;
76
+ }
77
+
78
+ div[description] mwc-icon {
79
+ margin-top: -3px;
80
+ font-size: 0.9rem;
81
+ }
82
+
83
+ div[elements] {
84
+ grid-area: inputs;
85
+ display: flex;
86
+ flex-direction: row;
87
+ flex-wrap: wrap;
88
+ gap: 10px;
89
+ padding-right: var(--padding-default);
90
+ }
91
+
92
+ div[elements] * {
93
+ flex: 1;
94
+ }
95
+
96
+ div[elements] input,
97
+ div[elements] select {
98
+ border: var(--input-field-border);
99
+ border-radius: var(--input-field-border-radius);
100
+ padding: var(--input-field-padding);
101
+ font: var(--input-field-font);
102
+ }
103
+
104
+ @media only screen and (max-width: 460px) {
105
+ label {
106
+ display: grid;
107
+
108
+ grid-template-rows: auto auto 1fr;
109
+ grid-template-columns: 1fr;
110
+ grid-template-areas: 'name' 'description' 'inputs';
111
+
112
+ grid-gap: 9px;
113
+ align-items: center;
114
+ margin-bottom: var(--margin-default);
115
+ }
116
+
117
+ div[name] {
118
+ text-align: left;
119
+ }
120
+ }
121
+ `
122
+
123
+ @property({ type: Object }) attributeSet?: AttributeSet
124
+ @property({ type: Object }) value?: { [tag: string]: any }
125
+
126
+ render() {
127
+ return html`<form>
128
+ <h2>${this.attributeSet?.entity || ''}</h2>
129
+ <h3>${this.attributeSet?.description || ''}</h3>
130
+ ${this.buildEntryViews()}
131
+ </form> `
132
+ }
133
+
134
+ private buildEntryViews() {
135
+ const items = this.attributeSet?.items.filter(item => item.active)
136
+
137
+ return (items || []).map(item => {
138
+ const { name, description, tag, type, options = {} } = item
139
+
140
+ const value = this.value && this.value[tag]
141
+
142
+ switch (type) {
143
+ case 'select':
144
+ var element = html` <select .name=${tag} disabled>
145
+ <option value=""></option>
146
+ ${(options.options || []).map(
147
+ option => html`<option value=${option.value} ?selected=${option.value === value}>${option.text}</option>`
148
+ )}
149
+ </select>`
150
+ break
151
+
152
+ case 'boolean':
153
+ var element = html` <input type="checkbox" name=${tag} .checked=${value} disabled />`
154
+ break
155
+
156
+ case 'number':
157
+ var element = html` <input type="number" name=${tag} value=${value} disabled />`
158
+ break
159
+
160
+ case 'file':
161
+ var element = html`<ox-input-file
162
+ name=${tag}
163
+ label="Attach Files"
164
+ accept="*/*"
165
+ multiple="true"
166
+ hide-filelist
167
+ disabled
168
+ ></ox-input-file>`
169
+
170
+ case 'string':
171
+ default:
172
+ var element = html` <input type="text" name=${tag} value=${value} disabled />`
173
+ }
174
+
175
+ return html` <label .title=${description}>
176
+ <div name>${name}</div>
177
+ <div description><mwc-icon>info_outline</mwc-icon> ${description}</div>
178
+ <div elements>${element}</div>
179
+ </label>`
180
+ })
181
+ }
182
+ }