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

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