@operato/attachment 1.0.0-alpha.5 → 1.0.0-alpha.9

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.
@@ -0,0 +1,112 @@
1
+ /**
2
+ * @license Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+
5
+ import '@material/mwc-icon'
6
+ import './ox-attachment-list.js'
7
+
8
+ import { PopupHandle, openPopup } from '@operato/layout'
9
+ import { css, html } from 'lit'
10
+ import { customElement, property, query } from 'lit/decorators.js'
11
+
12
+ import { OxPropertyEditor } from '@operato/property-editor'
13
+ import { i18next } from '@operato/i18n'
14
+
15
+ @customElement('ox-property-editor-attachment-selector')
16
+ export class OxPropertyEditorAttachmentSelector extends OxPropertyEditor {
17
+ static styles = [
18
+ css`
19
+ :host {
20
+ position: relative;
21
+ display: inline-block;
22
+ }
23
+
24
+ input[type='text'] {
25
+ box-sizing: border-box;
26
+ width: 100%;
27
+ height: 100%;
28
+ border: 1px solid rgba(0, 0, 0, 0.2);
29
+ }
30
+
31
+ mwc-icon {
32
+ position: absolute;
33
+ top: 0;
34
+ right: 3px;
35
+ }
36
+ `
37
+ ]
38
+
39
+ @property({ type: String }) value: string = ''
40
+ @property({ type: Object }) properties: any
41
+
42
+ private popup?: PopupHandle
43
+
44
+ render() {
45
+ return html`
46
+ <input
47
+ id="text"
48
+ type="text"
49
+ .value=${this.value || ''}
50
+ @change=${(e: KeyboardEvent) => this._onInputChanged(e)}
51
+ />
52
+
53
+ <mwc-icon @click=${() => this.openSelector()}>${this.getIconByCategory()}</mwc-icon>
54
+ `
55
+ }
56
+
57
+ getIconByCategory() {
58
+ var { category } = this.properties || {}
59
+ switch (category) {
60
+ case 'audio':
61
+ return 'library_music'
62
+ case 'video':
63
+ return 'video_library'
64
+ case 'image':
65
+ return 'image'
66
+ case 'text':
67
+ case 'application':
68
+ default:
69
+ return 'attachment'
70
+ }
71
+ }
72
+
73
+ _onInputChanged(e: KeyboardEvent) {
74
+ this.value = (e.target as HTMLInputElement).value
75
+ this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
76
+ }
77
+
78
+ openSelector() {
79
+ if (this.popup) {
80
+ delete this.popup
81
+ }
82
+
83
+ /*
84
+ * 기존 설정된 이미지가 선택된 상태가 되게 하기 위해서는 selector에 value를 전달해줄 필요가 있음.
85
+ * 주의. value는 object일 수도 있고, string일 수도 있다.
86
+ * string인 경우에는 해당 보드의 id로 해석한다.
87
+ */
88
+ var value = this.value || {}
89
+ var { category = 'application' } = this.properties || {}
90
+
91
+ var template = html`
92
+ <ox-attachment-list
93
+ .creatable=${true}
94
+ .category=${category}
95
+ @attachment-selected=${async (e: CustomEvent) => {
96
+ var attachment = e.detail.attachment
97
+ this.value = `/attachment/${attachment.path}`
98
+
99
+ this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
100
+
101
+ this.popup && this.popup.close()
102
+ }}
103
+ ></ox-attachment-list>
104
+ `
105
+
106
+ this.popup = openPopup(template, {
107
+ backdrop: true,
108
+ size: 'large',
109
+ title: i18next.t('title.select attachment')
110
+ })
111
+ }
112
+ }