@operato/app 1.0.0-alpha.2 → 1.0.0-alpha.20

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 (51) hide show
  1. package/@types/global/index.d.ts +2 -0
  2. package/CHANGELOG.md +159 -0
  3. package/demo/data-grist-test.html +456 -0
  4. package/dist/src/grist/code-editor.js +8 -3
  5. package/dist/src/grist/code-editor.js.map +1 -1
  6. package/dist/src/grist/index.js +2 -0
  7. package/dist/src/grist/index.js.map +1 -1
  8. package/dist/src/grist/object-editor.d.ts +1 -1
  9. package/dist/src/grist/object-editor.js +1 -1
  10. package/dist/src/grist/object-editor.js.map +1 -1
  11. package/dist/src/grist/parameters-editor-builder.d.ts +4 -0
  12. package/dist/src/grist/parameters-editor-builder.js +118 -0
  13. package/dist/src/grist/parameters-editor-builder.js.map +1 -0
  14. package/dist/src/grist/parameters-editor-popup.d.ts +13 -0
  15. package/dist/src/grist/parameters-editor-popup.js +111 -0
  16. package/dist/src/grist/parameters-editor-popup.js.map +1 -0
  17. package/dist/src/grist/parameters-editor.d.ts +19 -0
  18. package/dist/src/grist/parameters-editor.js +105 -0
  19. package/dist/src/grist/parameters-editor.js.map +1 -0
  20. package/dist/src/input/ox-input-background-pattern.d.ts +31 -0
  21. package/dist/src/input/ox-input-background-pattern.js +150 -0
  22. package/dist/src/input/ox-input-background-pattern.js.map +1 -0
  23. package/dist/src/input/ox-input-color-gradient.d.ts +25 -0
  24. package/dist/src/input/ox-input-color-gradient.js +318 -0
  25. package/dist/src/input/ox-input-color-gradient.js.map +1 -0
  26. package/dist/src/input/ox-input-fill-style.d.ts +42 -0
  27. package/dist/src/input/ox-input-fill-style.js +325 -0
  28. package/dist/src/input/ox-input-fill-style.js.map +1 -0
  29. package/dist/src/input/ox-input-graphql.d.ts +36 -0
  30. package/dist/src/input/ox-input-graphql.js +161 -0
  31. package/dist/src/input/ox-input-graphql.js.map +1 -0
  32. package/dist/src/property-editor/index.d.ts +24 -0
  33. package/dist/src/property-editor/index.js +58 -0
  34. package/dist/src/property-editor/index.js.map +1 -0
  35. package/dist/src/property-editor/ox-property-editor-graphql.d.ts +5 -0
  36. package/dist/src/property-editor/ox-property-editor-graphql.js +15 -0
  37. package/dist/src/property-editor/ox-property-editor-graphql.js.map +1 -0
  38. package/dist/tsconfig.tsbuildinfo +1 -1
  39. package/package.json +31 -12
  40. package/src/grist/code-editor.ts +2 -3
  41. package/src/grist/index.ts +2 -0
  42. package/src/grist/object-editor.ts +1 -1
  43. package/src/grist/parameters-editor-builder.ts +128 -0
  44. package/src/grist/parameters-editor-popup.ts +106 -0
  45. package/src/grist/parameters-editor.ts +112 -0
  46. package/src/input/ox-input-background-pattern.ts +166 -0
  47. package/src/input/ox-input-color-gradient.ts +341 -0
  48. package/src/input/ox-input-fill-style.ts +360 -0
  49. package/src/input/ox-input-graphql.ts +169 -0
  50. package/src/property-editor/index.ts +59 -0
  51. package/src/property-editor/ox-property-editor-graphql.ts +12 -0
package/package.json CHANGED
@@ -3,17 +3,24 @@
3
3
  "description": "WebApplication production supporting components following open-wc recommendations",
4
4
  "license": "MIT",
5
5
  "author": "heartyoh",
6
- "version": "1.0.0-alpha.2",
6
+ "version": "1.0.0-alpha.20",
7
7
  "main": "dist/src/index.js",
8
8
  "module": "dist/src/index.js",
9
9
  "exports": {
10
10
  ".": "./dist/src/index.js",
11
+ "./property-editor.js": "./dist/src/property-editor/index.js",
11
12
  "./grist/id-input.js": "./dist/src/grist/id-input.js",
12
13
  "./grist/id-selector.js": "./dist/src/grist/id-selector.js",
13
14
  "./grist/id-renderer.js": "./dist/src/grist/id-renderer.js",
14
15
  "./grist/object-selector.js": "./dist/src/grist/object-selector.js",
15
- "./grist/object-renderer.js": "./dist/src/grist/object-renderer.js",
16
- "./grist/code-editor.js": "./dist/src/grist/code-editor.js"
16
+ "./grist/object-editor.js": "./dist/src/grist/object-editor.js",
17
+ "./grist/code-editor.js": "./dist/src/grist/code-editor.js",
18
+ "./grist/parameters-editor.js": "./dist/src/grist/parameters-editor.js",
19
+ "./input/ox-input-graphql.js": "./dist/src/input/ox-input-graphql.js",
20
+ "./input/ox-input-background-pattern.js": "./dist/src/input/ox-input-background-pattern.js",
21
+ "./input/ox-input-color-gradient.js": "./dist/src/input/ox-input-color-gradient.js",
22
+ "./input/ox-input-fill-style.js": "./dist/src/input/ox-input-fill-style.js",
23
+ "./property-editor/ox-property-editor-graphql.js": "./dist/src/property-editor/ox-property-editor-graphql.js"
17
24
  },
18
25
  "publishConfig": {
19
26
  "access": "public",
@@ -37,17 +44,29 @@
37
44
  "storybook:build": "tsc && npm run analyze -- --exclude dist && build-storybook"
38
45
  },
39
46
  "dependencies": {
47
+ "@graphql-tools/load": "^7.3.2",
48
+ "@graphql-tools/url-loader": "^7.2.0",
49
+ "@graphql-tools/wrap": "^8.1.1",
40
50
  "@material/mwc-button": "^0.25.3",
41
51
  "@material/mwc-icon": "^0.25.3",
42
52
  "@material/mwc-icon-button": "^0.25.3",
43
- "@operato/data-grist": "^1.0.0-alpha.2",
44
- "@operato/form": "^1.0.0-alpha.2",
45
- "@operato/graphql": "^1.0.0-alpha.2",
46
- "@operato/i18n": "^1.0.0-alpha.2",
47
- "@operato/layout": "^1.0.0-alpha.2",
48
- "@operato/shell": "^1.0.0-alpha.2",
49
- "@operato/styles": "^1.0.0-alpha.2",
50
- "@operato/utils": "^1.0.0-alpha.2",
53
+ "@operato/attachment": "^1.0.0-alpha.20",
54
+ "@operato/data-grist": "^1.0.0-alpha.20",
55
+ "@operato/font": "^1.0.0-alpha.20",
56
+ "@operato/form": "^1.0.0-alpha.20",
57
+ "@operato/graphql": "^1.0.0-alpha.20",
58
+ "@operato/i18n": "^1.0.0-alpha.20",
59
+ "@operato/input": "^1.0.0-alpha.20",
60
+ "@operato/layout": "^1.0.0-alpha.20",
61
+ "@operato/property-editor": "^1.0.0-alpha.20",
62
+ "@operato/shell": "^1.0.0-alpha.20",
63
+ "@operato/styles": "^1.0.0-alpha.20",
64
+ "@operato/utils": "^1.0.0-alpha.20",
65
+ "codemirror": "^5.59.1",
66
+ "codemirror-graphql": "^0.15.2",
67
+ "cross-fetch": "^3.1.5",
68
+ "graphql": "^15.7.2",
69
+ "graphql-tag": "^2.12.6",
51
70
  "lit": "^2.2.0"
52
71
  },
53
72
  "devDependencies": {
@@ -82,5 +101,5 @@
82
101
  "prettier --write"
83
102
  ]
84
103
  },
85
- "gitHead": "122374f065ee52631f5afa755e0c41ddd40b1e20"
104
+ "gitHead": "5dfb4809dcd75e15b2ccc1af713d0977a1840e7e"
86
105
  }
@@ -1,9 +1,9 @@
1
1
  import '@material/mwc-icon'
2
- import {} from '@operato/shell'
3
2
 
4
3
  import { InputEditor, RecordConfig } from '@operato/data-grist'
5
4
  import { client, gqlContext } from '@operato/graphql'
6
5
 
6
+ import { customElement } from 'lit/decorators.js'
7
7
  import gql from 'graphql-tag'
8
8
  import { html } from 'lit'
9
9
 
@@ -31,6 +31,7 @@ const FETCH_COMMON_CODE_GQL = (codeName: string) => gql`
31
31
  }
32
32
  `
33
33
 
34
+ @customElement('code-editor')
34
35
  export class CodeEditor extends InputEditor {
35
36
  async firstUpdated() {
36
37
  super.firstUpdated()
@@ -74,5 +75,3 @@ export class CodeEditor extends InputEditor {
74
75
  `
75
76
  }
76
77
  }
77
-
78
- customElements.define('code-editor', CodeEditor)
@@ -3,9 +3,11 @@ import { registerEditor, registerRenderer } from '@operato/data-grist'
3
3
  import { CodeEditor } from './code-editor'
4
4
  import { IdInput } from './id-input.js'
5
5
  import { IdRenderer } from './id-renderer.js'
6
+ import { ObjectEditor } from './object-editor'
6
7
 
7
8
  /* register grist renderer/editor for id */
8
9
  registerEditor('id', IdInput)
10
+ registerEditor('object', ObjectEditor as any)
9
11
  registerEditor('code', CodeEditor)
10
12
 
11
13
  registerRenderer('id', IdRenderer)
@@ -1,5 +1,5 @@
1
1
  import '@material/mwc-icon'
2
- import '../../elements/object-selector'
2
+ import './object-selector.js'
3
3
 
4
4
  import { ColumnConfig, GristData, GristRecord, ZERO_COLUMN, ZERO_CONFIG, ZERO_RECORD } from '@operato/data-grist'
5
5
  import { LitElement, TemplateResult, css, html } from 'lit'
@@ -0,0 +1,128 @@
1
+ /**
2
+ * @license Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+
5
+ import { LitElement, PropertyValues, html } from 'lit'
6
+ import { OxPropertyEditor, PropertySpec } from '@operato/property-editor'
7
+ import { customElement, property } from 'lit/decorators.js'
8
+
9
+ import { connect } from 'pwa-helpers/connect-mixin'
10
+ import { store } from '@operato/shell'
11
+
12
+ /**
13
+ 모든 에디터들은 change 이벤트를 지원해야 한다. 또한, 모든 에디터들은 value속성에 값을 가져야 한다.
14
+
15
+ Example:
16
+
17
+ <ox-parameters-editor-builder value="{{value}}">
18
+ <label>Center X</label>
19
+ <input type="number" .value="${value.cx}">
20
+ <label>Width</label>
21
+ <input type="number" .value="${value.width}">
22
+ </ox-parameters-editor-builder>
23
+ */
24
+
25
+ const DEFAULT_VALUE = {
26
+ legend: '',
27
+ number: 0,
28
+ angle: 0,
29
+ string: '',
30
+ text: '',
31
+ textarea: '',
32
+ checkbox: false,
33
+ select: '',
34
+ color: '#000000',
35
+ 'solidcolor-stops': null,
36
+ 'gradientcolor-stops': null,
37
+ 'gltf-selector': '',
38
+ 'image-selector': '',
39
+ multiplecolor: null,
40
+ editortable: null,
41
+ imageselector: '',
42
+ options: null,
43
+ date: null
44
+ } as any
45
+
46
+ @customElement('ox-parameters-editor-builder')
47
+ class ParametersEditorBuilder extends connect(store)(LitElement) {
48
+ @property({ type: Object }) value: any
49
+ @property({ type: Array }) props?: PropertySpec[]
50
+ @property({ type: Object }) host: any
51
+
52
+ render() {
53
+ return html`<slot></slot>`
54
+ }
55
+
56
+ firstUpdated() {
57
+ this.addEventListener('change', this._onValueChanged.bind(this))
58
+ }
59
+
60
+ updated(changes: PropertyValues<this>) {
61
+ changes.has('props') && this._onPropsChanged(this.props)
62
+ changes.has('value') && this._setValues()
63
+ }
64
+
65
+ _onPropsChanged(props: PropertySpec[] | undefined) {
66
+ this.textContent = ''
67
+ ;(props || []).forEach(prop => {
68
+ let elementType = OxPropertyEditor.getEditor(prop.type)
69
+ if (!elementType) {
70
+ console.warn('Property Editor not defined', prop.type)
71
+ return
72
+ }
73
+ let element = document.createElement(elementType) as OxPropertyEditor
74
+
75
+ element.label = prop.label
76
+ element.type = prop.type
77
+ element.placeholder = prop.placeholder
78
+ element.host = this.host
79
+ // element.context = this.context
80
+ element.setAttribute('name', prop.name)
81
+
82
+ if (prop.observe) {
83
+ element.observe = prop.observe
84
+ }
85
+ element.property = prop.property
86
+ element.setAttribute('property-editor', '')
87
+
88
+ this.appendChild(element)
89
+ })
90
+ }
91
+
92
+ _setValues() {
93
+ var value = this.value || {}
94
+ Array.from(this.querySelectorAll('[name]')).forEach(propertyEditor => {
95
+ const editor = propertyEditor as OxPropertyEditor
96
+ let name = editor.getAttribute('name')
97
+ editor.value = value[name!] === undefined ? DEFAULT_VALUE[editor.type] : value[name!]
98
+ })
99
+ }
100
+
101
+ _getValues() {
102
+ var value = {} as any
103
+ Array.from(this.querySelectorAll('[name]')).forEach(propertyEditor => {
104
+ const editor = propertyEditor as OxPropertyEditor
105
+ let name = editor.getAttribute('name')
106
+ value[name!] = editor.value === undefined ? DEFAULT_VALUE[editor.type] : editor.value
107
+ })
108
+
109
+ return value
110
+ }
111
+
112
+ _onValueChanged(e: Event) {
113
+ e.stopPropagation()
114
+ var prop = e.target as HTMLElement
115
+
116
+ if (!prop || !prop.hasAttribute('property-editor')) {
117
+ return
118
+ }
119
+
120
+ this.dispatchEvent(
121
+ new CustomEvent('property-change', {
122
+ bubbles: true,
123
+ composed: true,
124
+ detail: this._getValues()
125
+ })
126
+ )
127
+ }
128
+ }
@@ -0,0 +1,106 @@
1
+ import { LitElement, css, html } from 'lit'
2
+ import { customElement, property } from 'lit/decorators.js'
3
+
4
+ import { ScrollbarStyles } from '@operato/styles'
5
+ import { i18next } from '@operato/i18n'
6
+
7
+ @customElement('ox-parameters-editor-popup')
8
+ export class ParametersEditorPopup extends LitElement {
9
+ static styles = [
10
+ ScrollbarStyles,
11
+ css`
12
+ :host {
13
+ display: flex;
14
+ flex-direction: column;
15
+
16
+ background-color: #fff;
17
+
18
+ width: var(--overlay-center-normal-width, 50%);
19
+ height: var(--overlay-center-normal-height, 50%);
20
+ }
21
+
22
+ ox-parameters-editor-builder {
23
+ flex: 1;
24
+ overflow-y: auto;
25
+ }
26
+
27
+ span {
28
+ flex: 1;
29
+
30
+ display: flex;
31
+ align-items: center;
32
+ justify-content: center;
33
+
34
+ color: var(--primary-color);
35
+ }
36
+
37
+ .button-container {
38
+ display: flex;
39
+ margin-left: auto;
40
+ }
41
+ `
42
+ ]
43
+
44
+ @property({ type: Object }) value: any
45
+ @property({ type: Object }) props: any
46
+ @property({ type: Object }) host: any
47
+ @property({ type: Object }) context: any
48
+ @property({ type: Object }) confirmCallback!: (newval: any) => void
49
+
50
+ render() {
51
+ var props = this.props instanceof Array ? this.props : []
52
+
53
+ return html`
54
+ ${props.length > 0
55
+ ? html`
56
+ <ox-parameters-editor-builder
57
+ .value=${this.value}
58
+ .props=${props}
59
+ .host=${this.host}
60
+ .context=${this.context}
61
+ @property-change=${this.onChange.bind(this)}
62
+ >
63
+ </ox-parameters-editor-builder>
64
+ `
65
+ : html` <span><i18n-msg msgid="text.no properties to set"></i18n-msg></span> `}
66
+
67
+ <div class="button-container">
68
+ <mwc-button @click=${this.onCancel.bind(this)}>${i18next.t('button.cancel')}</mwc-button>
69
+ <mwc-button @click=${this.onConfirm.bind(this)}>${i18next.t('button.confirm')}</mwc-button>
70
+ </div>
71
+ `
72
+ }
73
+
74
+ private onChange(e: CustomEvent) {
75
+ e.stopPropagation()
76
+
77
+ /*
78
+ 주의 : 이 팝업 템플릿은 layout 모듈에 의해서 render 되므로,
79
+ layout의 구성에 변화가 발생하면, 다시 render된다.
80
+ 이 팝업이 떠 있는 상태에서, 또 다른 팝업이 뜨는 경우도 layout 구성의 변화를 야기한다. (overlay의 갯수의 증가)
81
+ 이 경우 value, options, confirmCallback 등 클로져를 사용한 것들이 초기 바인딩된 값으로 다시 바인딩되게 되는데,
82
+ 만약, 템플릿 내부에서 이들 속성의 레퍼런스가 변화했다면, 원래 상태로 되돌아가는 현상이 발생하게 된다.
83
+ 따라서, 가급적 이들 속성의 레퍼런스를 변화시키지 않는 것이 좋다.
84
+ (이 팝업 클래스를 템플릿으로 사용한 곳의 코드를 참조하세요.)
85
+ =>
86
+ 이런 이유로, Object.assign(...)을 사용하였다.
87
+ */
88
+ if (!this.value) {
89
+ this.value = {}
90
+ }
91
+
92
+ for (let key in this.value) {
93
+ delete this.value[key]
94
+ }
95
+ Object.assign(this.value, e.detail)
96
+ }
97
+
98
+ private onCancel(e: Event) {
99
+ history.back()
100
+ }
101
+
102
+ private onConfirm(e: Event) {
103
+ this.confirmCallback && this.confirmCallback(this.value)
104
+ history.back()
105
+ }
106
+ }
@@ -0,0 +1,112 @@
1
+ /**
2
+ * @license Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+
5
+ import './parameters-editor-builder.js'
6
+ import './parameters-editor-popup.js'
7
+
8
+ import { ColumnConfig, GristRecord } from '@operato/data-grist'
9
+ import { LitElement, css, html } from 'lit'
10
+ import { PopupHandle, openPopup } from '@operato/layout'
11
+ import { customElement, property } from 'lit/decorators.js'
12
+
13
+ import { i18next } from '@operato/i18n'
14
+
15
+ @customElement('ox-parameters-editor')
16
+ export class ParametersEditor extends LitElement {
17
+ static styles = css`
18
+ :host {
19
+ color: black;
20
+
21
+ overflow: hidden;
22
+ text-overflow: ellipsis;
23
+ }
24
+ `
25
+
26
+ @property({ type: Object }) value: any
27
+ @property({ type: Object }) column!: ColumnConfig
28
+ @property({ type: Object }) record!: GristRecord
29
+ @property({ type: Number }) row!: number
30
+ @property({ type: Object }) field!: any
31
+
32
+ private popup?: PopupHandle
33
+
34
+ render() {
35
+ const value = typeof this.value === 'object' ? JSON.stringify(this.value) : this.value
36
+ return html` ${value || ''} `
37
+ }
38
+
39
+ async firstUpdated() {
40
+ await this.updateComplete
41
+
42
+ this.renderRoot.addEventListener('click', e => {
43
+ e.stopPropagation()
44
+
45
+ this.openSelector()
46
+ })
47
+
48
+ this.openSelector()
49
+ }
50
+
51
+ async openSelector() {
52
+ if (this.popup) {
53
+ delete this.popup
54
+ }
55
+
56
+ var { options } = this.column.record
57
+
58
+ if (typeof options === 'function') {
59
+ options = await options.call(this, this.value, this.column, this.record, this.row, this.field)
60
+ }
61
+
62
+ const { name, help, spec, context, objectified = false } = options
63
+
64
+ const confirmCallback = (newval: any) => {
65
+ this.dispatchEvent(
66
+ new CustomEvent('field-change', {
67
+ bubbles: true,
68
+ composed: true,
69
+ detail: {
70
+ before: this.value,
71
+ after: !objectified ? JSON.stringify(newval) : newval,
72
+ record: this.record,
73
+ column: this.column,
74
+ row: this.row
75
+ }
76
+ })
77
+ )
78
+ }
79
+
80
+ try {
81
+ var value: any = !objectified && typeof this.value === 'string' ? JSON.parse(this.value) : this.value
82
+ } catch (e) {
83
+ var value: any = {}
84
+ }
85
+
86
+ /*
87
+ 주의 : 이 팝업 템플릿은 layout 모듈에 의해서 render 되므로,
88
+ layout의 구성에 변화가 발생하면, 다시 render된다.
89
+ 이 팝업이 떠 있는 상태에서, 또 다른 팝업이 뜨는 경우도 layout 구성의 변화를 야기한다. (overlay의 갯수의 증가)
90
+ 이 경우 value, options, confirmCallback 등 클로져를 사용한 것들이 초기 바인딩된 값으로 다시 바인딩되게 되는데,
91
+ 만약, 템플릿 내부에서 이들 속성의 레퍼런스가 변화했다면, 원래 상태로 되돌아가는 현상이 발생하게 된다.
92
+ 따라서, 가급적 이들 속성의 레퍼런스를 변화시키지 않는 것이 좋다.
93
+ */
94
+ var template = html`
95
+ <ox-parameters-editor-popup
96
+ .value=${value}
97
+ .props=${spec}
98
+ .host=${this.record}
99
+ .context=${context}
100
+ .confirmCallback=${confirmCallback}
101
+ >
102
+ </ox-parameters-editor-popup>
103
+ `
104
+
105
+ this.popup = openPopup(template, {
106
+ backdrop: true,
107
+ size: 'large',
108
+ title: `${name?.toUpperCase() || ''} ${i18next.t('field.params')}`,
109
+ help
110
+ })
111
+ }
112
+ }
@@ -0,0 +1,166 @@
1
+ /**
2
+ * @license Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+
5
+ import '@operato/i18n/ox-i18n.js'
6
+ import '@operato/attachment/ox-attachment-selector.js'
7
+
8
+ import { css, html } from 'lit'
9
+ import { customElement, property } from 'lit/decorators.js'
10
+
11
+ import { OxFormField } from '@operato/input'
12
+
13
+ export type BackgroundPatternOption = {
14
+ image?: HTMLImageElement | string
15
+ align?: 'left-top' | 'top' | 'right-top' | 'left' | 'center' | 'right' | 'left-bottom' | 'bottom' | 'right-bottom'
16
+ offsetX?: number
17
+ offsetY?: number
18
+ width?: number
19
+ height?: number
20
+ fitPattern?: boolean
21
+ }
22
+
23
+ /**
24
+ * 컴포넌트의 fill pattern을 편집하는 element
25
+ *
26
+ * Example:
27
+ * <ox-input-background-pattern
28
+ * @change="${e => { this.pattern = e.target.value }}"
29
+ * .value=${this.pattern}"
30
+ * ></ox-input-background-pattern>
31
+ */
32
+
33
+ @customElement('ox-input-background-pattern')
34
+ export class OxInputBackgroundPattern extends OxFormField {
35
+ static styles = css`
36
+ :host,
37
+ .grid-10 {
38
+ display: grid;
39
+ grid-template-columns: repeat(10, 1fr);
40
+ grid-gap: 5px;
41
+ grid-auto-rows: minmax(24px, auto);
42
+
43
+ align-items: center;
44
+ }
45
+
46
+ * {
47
+ align-self: stretch;
48
+ }
49
+
50
+ label {
51
+ grid-column: span 2;
52
+ text-align: right;
53
+ text-transform: capitalize;
54
+
55
+ align-self: center;
56
+ }
57
+
58
+ .grid-10 {
59
+ grid-column: span 10;
60
+ }
61
+
62
+ select,
63
+ input,
64
+ [custom-editor] {
65
+ grid-column: span 8;
66
+ }
67
+
68
+ select {
69
+ height: 100%;
70
+ border: 1px solid rgba(0, 0, 0, 0.2);
71
+ }
72
+
73
+ input[type='checkbox'] {
74
+ grid-column: 3 / 4;
75
+ align-self: center;
76
+ }
77
+
78
+ input[type='checkbox'] ~ label {
79
+ grid-column: span 7;
80
+ text-align: left;
81
+ }
82
+
83
+ .grid-10 > input[type='number'] {
84
+ grid-column: span 3;
85
+ border: 1px solid rgba(0, 0, 0, 0.2);
86
+ }
87
+
88
+ .grid-10 > label {
89
+ grid-column: span 2;
90
+ text-align: right;
91
+ }
92
+ `
93
+
94
+ @property({ type: Object }) value?: BackgroundPatternOption
95
+
96
+ render() {
97
+ const value = this.value || ({} as BackgroundPatternOption)
98
+
99
+ return html`
100
+ <label> <ox-i18n msgid="label.image" auto="">image</ox-i18n> </label>
101
+
102
+ <ox-attachment-selector
103
+ value-key="image"
104
+ .value=${value.image || ''}
105
+ .properties=${{
106
+ category: 'image'
107
+ }}
108
+ custom-editor
109
+ ></ox-attachment-selector>
110
+
111
+ <label> <ox-i18n msgid="label.align" auto="">align</ox-i18n> </label>
112
+
113
+ <select value-key="align" class="select-content" .value=${value.align}>
114
+ <option value="left-top">Left Top</option>
115
+ <option value="top">Top</option>
116
+ <option value="right-top">Right Top</option>
117
+ <option value="left">Left</option>
118
+ <option value="center">Center</option>
119
+ <option value="right">Right</option>
120
+ <option value="left-bottom">Left Bottom</option>
121
+ <option value="bottom">Bottom</option>
122
+ <option value="right-bottom">Right Bottom</option>
123
+ </select>
124
+
125
+ <div class="grid-10">
126
+ <label> <ox-i18n msgid="label.offset-x" auto="">offsetX</ox-i18n> </label>
127
+ <input type="number" value-key="offsetX" .value=${value.offsetX} />
128
+
129
+ <label> <ox-i18n msgid="label.offset-y" auto="">offsetY</ox-i18n> </label>
130
+ <input type="number" value-key="offsetY" .value=${value.offsetY} />
131
+
132
+ <label> <ox-i18n msgid="label.width" auto="">width</ox-i18n> </label>
133
+ <input type="number" value-key="width" .value=${value.width} />
134
+
135
+ <label> <ox-i18n msgid="label.height" auto="">height</ox-i18n> </label>
136
+ <input type="number" value-key="height" .value=${value.height} />
137
+ </div>
138
+
139
+ <div class="grid-10">
140
+ <input value-key="fitPattern" type="checkbox" .checked=${value.fitPattern} required />
141
+ <label> <ox-i18n msgid="label.fit" auto="">Fit</ox-i18n> </label>
142
+ </div>
143
+ `
144
+ }
145
+
146
+ firstUpdated() {
147
+ this.renderRoot.addEventListener('change', this._onChange.bind(this))
148
+ }
149
+
150
+ _onChange(e: Event) {
151
+ var element = e.target as HTMLInputElement
152
+ var key = element.getAttribute('value-key')
153
+ var value: any = element.value
154
+
155
+ if (key == 'fitPattern') {
156
+ value = element.checked
157
+ }
158
+
159
+ this.value = {
160
+ ...this.value,
161
+ [key!]: value
162
+ }
163
+
164
+ this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
165
+ }
166
+ }