@operato/font 1.0.0-beta.9 → 1.0.0

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 (46) hide show
  1. package/CHANGELOG.md +351 -0
  2. package/custom-elements.json +855 -0
  3. package/dist/src/font-creation-card.d.ts +18 -0
  4. package/dist/src/font-creation-card.js +258 -0
  5. package/dist/src/font-creation-card.js.map +1 -0
  6. package/dist/src/font-graphql-client.d.ts +20 -0
  7. package/dist/src/font-graphql-client.js +109 -0
  8. package/dist/src/font-graphql-client.js.map +1 -0
  9. package/dist/src/font-selector.d.ts +36 -0
  10. package/dist/src/font-selector.js +285 -0
  11. package/dist/src/font-selector.js.map +1 -0
  12. package/dist/src/index.d.ts +5 -0
  13. package/dist/src/index.js +6 -0
  14. package/dist/src/index.js.map +1 -0
  15. package/dist/src/ox-file-selector.d.ts +12 -0
  16. package/dist/src/ox-file-selector.js +129 -0
  17. package/dist/src/ox-file-selector.js.map +1 -0
  18. package/dist/src/ox-font-selector.d.ts +15 -0
  19. package/dist/src/ox-font-selector.js +88 -0
  20. package/dist/src/ox-font-selector.js.map +1 -0
  21. package/dist/src/ox-property-editor-font-selector.d.ts +8 -0
  22. package/dist/src/ox-property-editor-font-selector.js +13 -0
  23. package/dist/src/ox-property-editor-font-selector.js.map +1 -0
  24. package/dist/src/redux-font-actions.d.ts +7 -0
  25. package/dist/src/redux-font-actions.js +19 -0
  26. package/dist/src/redux-font-actions.js.map +1 -0
  27. package/dist/src/redux-font-reducers.d.ts +12 -0
  28. package/dist/src/redux-font-reducers.js +70 -0
  29. package/dist/src/redux-font-reducers.js.map +1 -0
  30. package/dist/tsconfig.tsbuildinfo +1 -0
  31. package/package.json +65 -20
  32. package/src/font-creation-card.ts +260 -0
  33. package/src/{graphql-client.js → font-graphql-client.ts} +35 -26
  34. package/src/font-selector.ts +284 -0
  35. package/src/index.ts +6 -0
  36. package/src/ox-file-selector.ts +114 -0
  37. package/src/ox-font-selector.ts +94 -0
  38. package/src/ox-property-editor-font-selector.ts +17 -0
  39. package/src/redux-font-actions.ts +21 -0
  40. package/src/redux-font-reducers.ts +88 -0
  41. package/src/font-creation-card.js +0 -311
  42. package/src/font-selector.js +0 -465
  43. package/src/index.js +0 -3
  44. package/src/ox-font-selector.js +0 -102
  45. package/src/ox-property-editor-font-selector.js +0 -25
  46. package/things-factory.config.js +0 -5
@@ -1,17 +1,13 @@
1
- import { client } from "@operato/graphql";
2
- import gql from "graphql-tag";
1
+ import { client } from '@operato/graphql'
2
+ import gql from 'graphql-tag'
3
3
 
4
4
  /**
5
5
  * @param {Object} listParam {filters, pagination, sortings}
6
6
  */
7
- export async function fetchFontList(listParam) {
7
+ export async function fetchFontList(listParam?: { sortings?: any; filters?: any; pagination?: any }) {
8
8
  const response = await client.query({
9
9
  query: gql`
10
- query (
11
- $filters: [Filter!]
12
- $pagination: Pagination
13
- $sortings: [Sorting!]
14
- ) {
10
+ query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {
15
11
  fonts(filters: $filters, pagination: $pagination, sortings: $sortings) {
16
12
  items {
17
13
  id
@@ -20,6 +16,10 @@ export async function fetchFontList(listParam) {
20
16
  uri
21
17
  path
22
18
  active
19
+ files {
20
+ name
21
+ fullpath
22
+ }
23
23
  createdAt
24
24
  updatedAt
25
25
  }
@@ -27,16 +27,16 @@ export async function fetchFontList(listParam) {
27
27
  }
28
28
  }
29
29
  `,
30
- variables: listParam,
31
- });
30
+ variables: listParam
31
+ })
32
32
 
33
- return response.data && response.data.fonts;
33
+ return response.data && response.data.fonts
34
34
  }
35
35
 
36
36
  /**
37
37
  * @param {Object} font Font patch
38
38
  */
39
- export async function createFont(font) {
39
+ export async function createFont(font: any) {
40
40
  const response = await client.mutate({
41
41
  mutation: gql`
42
42
  mutation CreateFont($font: NewFont!) {
@@ -52,18 +52,21 @@ export async function createFont(font) {
52
52
  }
53
53
  `,
54
54
  variables: {
55
- font: { active: false, ...font },
55
+ font: { active: false, ...font }
56
56
  },
57
- });
57
+ context: {
58
+ hasUpload: true
59
+ }
60
+ })
58
61
 
59
- return response.data;
62
+ return response.data
60
63
  }
61
64
 
62
65
  /**
63
66
  * @param {Object} font Font patch
64
67
  */
65
- export async function updateFont(font) {
66
- var { id, ...patch } = font;
68
+ export async function updateFont(font: any) {
69
+ var { id, ...patch } = font
67
70
 
68
71
  const response = await client.mutate({
69
72
  mutation: gql`
@@ -72,7 +75,10 @@ export async function updateFont(font) {
72
75
  id
73
76
  name
74
77
  provider
75
- uri
78
+ files {
79
+ name
80
+ fullpath
81
+ }
76
82
  path
77
83
  active
78
84
  createdAt
@@ -82,17 +88,20 @@ export async function updateFont(font) {
82
88
  `,
83
89
  variables: {
84
90
  id,
85
- patch,
91
+ patch
86
92
  },
87
- });
93
+ context: {
94
+ hasUpload: true
95
+ }
96
+ })
88
97
 
89
- return response.data;
98
+ return response.data
90
99
  }
91
100
 
92
101
  /**
93
102
  * @param {String} id Font id
94
103
  */
95
- export async function deleteFont(id) {
104
+ export async function deleteFont(id: string) {
96
105
  const response = await client.mutate({
97
106
  mutation: gql`
98
107
  mutation ($id: String!) {
@@ -100,9 +109,9 @@ export async function deleteFont(id) {
100
109
  }
101
110
  `,
102
111
  variables: {
103
- id,
104
- },
105
- });
112
+ id
113
+ }
114
+ })
106
115
 
107
- return response.data;
116
+ return response.data
108
117
  }
@@ -0,0 +1,284 @@
1
+ import './font-creation-card'
2
+
3
+ import { css, html, LitElement, PropertyValues } from 'lit'
4
+ import { customElement, property, query } from 'lit/decorators.js'
5
+ import { connect } from 'pwa-helpers/connect-mixin.js'
6
+
7
+ import Headroom from '@operato/headroom'
8
+ import { i18next, localize } from '@operato/i18n'
9
+ import { pulltorefresh } from '@operato/pull-to-refresh'
10
+ import { store } from '@operato/shell'
11
+ import { HeadroomStyles, ScrollbarStyles } from '@operato/styles'
12
+
13
+ import { createFont, deleteFont, updateFont } from './font-graphql-client'
14
+ import { actionUpdateFontList } from './redux-font-actions'
15
+
16
+ @customElement('font-selector')
17
+ export class FontSelector extends localize(i18next)(connect(store)(LitElement)) {
18
+ static styles = [
19
+ ScrollbarStyles,
20
+ HeadroomStyles,
21
+ css`
22
+ :host {
23
+ display: flex;
24
+ flex-direction: column;
25
+ overflow: hidden;
26
+ background-color: var(--popup-content-background-color);
27
+
28
+ position: relative;
29
+ }
30
+
31
+ #main {
32
+ overflow: auto;
33
+ padding: var(--popup-content-padding);
34
+ display: grid;
35
+ grid-template-columns: var(--card-list-template);
36
+ grid-auto-rows: var(--card-list-rows-height);
37
+ grid-gap: 20px;
38
+ box-sizing: border-box;
39
+ }
40
+
41
+ #main .card {
42
+ display: flex;
43
+ flex-direction: column;
44
+ align-items: center;
45
+ overflow: hidden;
46
+ border-radius: var(--card-list-border-radius);
47
+ border: var(--font-selector-border);
48
+ background-color: var(--card-list-background-color);
49
+
50
+ position: relative;
51
+ }
52
+
53
+ .card .button-container {
54
+ position: absolute;
55
+ right: 0;
56
+ height: 100%;
57
+ display: flex;
58
+ direction: rtl;
59
+ flex-direction: column;
60
+ flex-wrap: wrap;
61
+ }
62
+
63
+ .card .button-container > mwc-icon {
64
+ background-color: var(--font-selector-icon-background-color);
65
+ text-align: center;
66
+ width: var(--font-selector-icon-size);
67
+ height: var(--font-selector-icon-size);
68
+ font: var(--font-selector-icon-font);
69
+ color: var(--font-selector-icon-color);
70
+ }
71
+
72
+ .card .button-container > mwc-icon:last-child {
73
+ border-bottom-left-radius: 12px;
74
+ }
75
+
76
+ .card .button-container > mwc-icon:hover,
77
+ .card .button-container > mwc-icon:active {
78
+ background-color: var(--primary-color);
79
+ color: #fff;
80
+ }
81
+
82
+ #main .card.create {
83
+ overflow: visible;
84
+ background-color: initial;
85
+ }
86
+
87
+ #main .card:hover {
88
+ cursor: pointer;
89
+ }
90
+
91
+ [face] {
92
+ flex: 1;
93
+ }
94
+
95
+ [name] {
96
+ background-color: var(--board-renderer-name-background-color);
97
+ opacity: 0.8;
98
+ margin-top: -35px;
99
+ width: 100%;
100
+ color: #fff;
101
+ font-weight: bolder;
102
+ font-size: 13px;
103
+ text-indent: 7px;
104
+ }
105
+
106
+ [provider] {
107
+ background-color: rgba(0, 0, 0, 0.7);
108
+ width: 100%;
109
+ min-height: 15px;
110
+ font-size: 0.6rem;
111
+ color: #fff;
112
+ text-indent: 7px;
113
+ }
114
+
115
+ #filter {
116
+ padding: var(--popup-content-padding);
117
+ background-color: var(--font-tools-background-color);
118
+ box-shadow: var(--box-shadow);
119
+
120
+ position: absolute;
121
+ width: 100%;
122
+ box-sizing: border-box;
123
+ z-index: 1;
124
+ }
125
+
126
+ #filter * {
127
+ font-size: 15px;
128
+ }
129
+
130
+ select {
131
+ text-transform: capitalize;
132
+ float: right;
133
+ }
134
+ `
135
+ ]
136
+
137
+ @property({ type: Array }) fonts: Array<any> = []
138
+ @property({ type: Boolean }) creatable: boolean = false
139
+ @property({ type: String }) provider: string = ''
140
+
141
+ @query('#main') main!: HTMLElement
142
+ @query('#filter') filter!: HTMLElement
143
+ @query('font-creation-card') creationCard!: { reset: () => {} }
144
+
145
+ showGotoTop: boolean = false
146
+
147
+ render() {
148
+ var fonts = this.fonts || []
149
+
150
+ return html`
151
+ <div id="filter">
152
+ <select
153
+ @change=${(e: Event) => {
154
+ this.provider = (e.currentTarget as HTMLInputElement).value
155
+ }}
156
+ >
157
+ <option value="">--${i18next.t('text.please choose a provider')}--</option>
158
+ ${['google', 'custom'].map(provider => html` <option value=${provider}>${provider}</option> `)}
159
+ </select>
160
+ </div>
161
+
162
+ <div id="main">
163
+ ${this.creatable
164
+ ? html`
165
+ <font-creation-card
166
+ class="card create"
167
+ @create-font=${(e: CustomEvent) => this.onCreateFont(e)}
168
+ ></font-creation-card>
169
+ `
170
+ : html``}
171
+ ${fonts
172
+ .filter(font => (this.provider ? font.provider === this.provider : true))
173
+ .map(
174
+ font => html`
175
+ <div class="card" @click=${(e: Event) => this.onClickSelect(font)}>
176
+ <div face>
177
+ <font .face=${font.name}>ABCDEFGHIJKLMN</font>
178
+ <font .face=${font.name}>abcdefghijklmn</font>
179
+ </div>
180
+ <div name>${font.name}</div>
181
+ <div provider>${font.provider}</div>
182
+ <div class="button-container">
183
+ <mwc-icon
184
+ @click=${(e: Event) => {
185
+ e.stopPropagation()
186
+ this.toggleActive(font)
187
+ }}
188
+ >${font.active ? 'check_box' : 'check_box_outline_blank'}</mwc-icon
189
+ >
190
+ <mwc-icon
191
+ @click=${(e: Event) => {
192
+ e.stopPropagation()
193
+ this.deleteFont(font)
194
+ }}
195
+ >delete</mwc-icon
196
+ >
197
+ </div>
198
+ </div>
199
+ `
200
+ )}
201
+ </div>
202
+ `
203
+ }
204
+
205
+ async firstUpdated() {
206
+ var list = this.renderRoot.querySelector('#main')
207
+
208
+ pulltorefresh({
209
+ container: this.renderRoot,
210
+ scrollable: list,
211
+ refresh: () => {
212
+ return this.refresh()
213
+ }
214
+ })
215
+
216
+ /* for headroom */
217
+ this.main.addEventListener('scroll', e => {
218
+ const target = e.target as HTMLElement
219
+ this.showGotoTop = target.scrollTop !== 0
220
+ })
221
+
222
+ await this.requestUpdate()
223
+
224
+ var originPaddingTop = parseFloat(getComputedStyle(this.main, null).getPropertyValue('padding-top'))
225
+ this.main.style.paddingTop = this.filter.clientHeight + originPaddingTop + 'px'
226
+ var headroom = new Headroom(this.filter, {
227
+ scroller: this.main
228
+ })
229
+ headroom.init()
230
+ }
231
+
232
+ stateChanged(state: any) {
233
+ this.fonts = state.font
234
+ }
235
+
236
+ updated(changes: PropertyValues<this>) {
237
+ if (changes.has('fonts')) {
238
+ this.creationCard.reset()
239
+ }
240
+ }
241
+
242
+ async refresh() {
243
+ return store.dispatch(actionUpdateFontList() as any)
244
+ }
245
+
246
+ async toggleActive(font: { id: string; active: boolean }) {
247
+ try {
248
+ await updateFont({ id: font.id, active: !font.active })
249
+ this.refresh()
250
+ } catch (e) {
251
+ console.error(e)
252
+ }
253
+ }
254
+
255
+ async onCreateFont(e: CustomEvent) {
256
+ try {
257
+ await createFont(e.detail)
258
+ this.refresh()
259
+ } catch (e) {
260
+ console.error(e)
261
+ }
262
+ }
263
+
264
+ async deleteFont(font: { id: string }) {
265
+ try {
266
+ await deleteFont(font.id)
267
+ this.refresh()
268
+ } catch (e) {
269
+ console.error(e)
270
+ }
271
+ }
272
+
273
+ onClickSelect(font: any) {
274
+ this.dispatchEvent(
275
+ new CustomEvent('font-selected', {
276
+ composed: true,
277
+ bubbles: true,
278
+ detail: {
279
+ font
280
+ }
281
+ })
282
+ )
283
+ }
284
+ }
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from './font-selector.js'
2
+ export * from './ox-font-selector.js'
3
+ export * from './ox-property-editor-font-selector.js'
4
+
5
+ export * from './redux-font-actions.js'
6
+ export { default as ReducerFont } from './redux-font-reducers.js'
@@ -0,0 +1,114 @@
1
+ import '@material/mwc-icon'
2
+ import '@material/mwc-icon-button'
3
+
4
+ import { LitElement, css, html } from 'lit'
5
+ import { customElement, property } from 'lit/decorators.js'
6
+
7
+ @customElement('ox-file-selector')
8
+ export class OxFileSelector extends LitElement {
9
+ static styles = [
10
+ css`
11
+ :host {
12
+ flex: 1;
13
+ display: flex;
14
+ flex-direction: column;
15
+ position: relative;
16
+ overflow: hidden;
17
+ }
18
+
19
+ #input-box {
20
+ display: flex;
21
+ width: 100%;
22
+ height: 100%;
23
+ }
24
+
25
+ input[type='file'] {
26
+ position: absolute;
27
+ width: 0px;
28
+ height: 0px;
29
+ padding: 0;
30
+ margin: -1px;
31
+ overflow: hidden;
32
+ clip: rect(0, 0, 0, 0);
33
+ border: 0;
34
+ }
35
+
36
+ label {
37
+ padding: unset;
38
+ width: 100%;
39
+ height: 100%;
40
+ box-sizing: border-box;
41
+ display: flex;
42
+ align-items: center;
43
+ justify-content: center;
44
+
45
+ color: var(--file-selector-color, #999);
46
+ font-size: inherit;
47
+ line-height: normal;
48
+ vertical-align: middle;
49
+ background-color: var(--file-selector-bg-color, #fdfdfd);
50
+ cursor: pointer;
51
+ border: var(--file-selector-border, 1px solid #ebebeb);
52
+ border-radius: var(--file-selector-border-radius, 0.25em);
53
+ }
54
+
55
+ /* named upload */
56
+ .upload-name {
57
+ flex: 1;
58
+ padding: 0.5em 0.75em; /* label의 패딩값과 일치 */
59
+ font-size: inherit;
60
+ font-family: inherit;
61
+ line-height: normal;
62
+ vertical-align: middle;
63
+ background-color: #f5f5f5;
64
+ border: 1px solid #ebebeb;
65
+ border-bottom-color: #e2e2e2;
66
+ border-radius: 0.25em;
67
+ -webkit-appearance: none; /* 네이티브 외형 감추기 */
68
+ -moz-appearance: none;
69
+ appearance: none;
70
+ }
71
+ `
72
+ ]
73
+
74
+ @property({ type: String }) label: string = 'select file'
75
+ @property({ type: String }) accept?: string
76
+ @property({ type: Boolean, attribute: 'show-filename' }) showFilename: boolean = false
77
+ @property({ type: Boolean, attribute: 'multiple' }) multiple: boolean = false
78
+ @property({ type: Array }) _files: Array<any> = []
79
+
80
+ render() {
81
+ return html`
82
+ <div id="input-box">
83
+ ${this.showFilename
84
+ ? html`
85
+ <input class="upload-name" value=${this._files.map(f => f.name).join(', ') || this.label} disabled />
86
+ `
87
+ : html``}
88
+ <label for="input-file">${this.label}</label>
89
+ <input
90
+ id="input-file"
91
+ type="file"
92
+ accept="${this.accept}"
93
+ class="upload-hidden"
94
+ ?multiple=${this.multiple}
95
+ hidden
96
+ @change=${(e: Event) => {
97
+ const el = e.currentTarget as HTMLInputElement
98
+ this.dispatchEvent(
99
+ new CustomEvent('file-change', {
100
+ bubbles: true,
101
+ composed: true,
102
+ detail: {
103
+ files: el.files
104
+ }
105
+ })
106
+ )
107
+
108
+ el.value = ''
109
+ }}
110
+ />
111
+ </div>
112
+ `
113
+ }
114
+ }
@@ -0,0 +1,94 @@
1
+ /**
2
+ * @license Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+
5
+ import '@material/mwc-icon'
6
+ import './font-selector'
7
+
8
+ import { css, html, LitElement } from 'lit'
9
+ import { customElement, property } from 'lit/decorators.js'
10
+
11
+ import { i18next } from '@operato/i18n'
12
+ import { openPopup } from '@operato/layout'
13
+
14
+ @customElement('ox-font-selector')
15
+ export default class OxFontSelector 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: 0;
34
+ }
35
+ `
36
+ ]
37
+
38
+ @property({ type: String }) value?: string
39
+ @property({ type: Object }) properties: any
40
+
41
+ popup: any
42
+
43
+ render() {
44
+ return html`
45
+ <input
46
+ id="text"
47
+ type="text"
48
+ .value=${this.value || ''}
49
+ @change=${(e: Event) => this._onInputChanged(e)}
50
+ .placeholder=${this.getAttribute('placeholder') || ''}
51
+ />
52
+
53
+ <mwc-icon @click=${() => this.openSelector()}>font_download</mwc-icon>
54
+ `
55
+ }
56
+
57
+ _onInputChanged(e: Event) {
58
+ this.value = (e.target as HTMLInputElement).value
59
+ this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
60
+ }
61
+
62
+ openSelector() {
63
+ if (this.popup) {
64
+ delete this.popup
65
+ }
66
+
67
+ /*
68
+ * 기존 설정된 보드가 선택된 상태가 되게 하기 위해서는 selector에 value를 전달해줄 필요가 있음.
69
+ * 주의. value는 object일 수도 있고, string일 수도 있다.
70
+ * string인 경우에는 해당 보드의 id로 해석한다.
71
+ */
72
+ var value = this.value || {}
73
+
74
+ var template = html`
75
+ <font-selector
76
+ .creatable=${true}
77
+ @font-selected=${async (e: CustomEvent) => {
78
+ var font = e.detail.font
79
+ this.value = font.name
80
+
81
+ this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
82
+
83
+ this.popup && this.popup.close()
84
+ }}
85
+ ></font-selector>
86
+ `
87
+
88
+ this.popup = openPopup(template, {
89
+ backdrop: true,
90
+ size: 'large',
91
+ title: i18next.t('title.select font')
92
+ })
93
+ }
94
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+
5
+ import './ox-font-selector'
6
+
7
+ import { html } from 'lit'
8
+
9
+ import { OxPropertyEditor, PropertySpec } from '@operato/property-editor'
10
+
11
+ export class OxPropertyEditorFontSelector extends OxPropertyEditor {
12
+ editorTemplate(value: any, spec: PropertySpec) {
13
+ return html` <ox-font-selector id="editor" .value=${value} .properties=${spec.property}></ox-font-selector> `
14
+ }
15
+ }
16
+
17
+ customElements.define('ox-property-editor-font-selector', OxPropertyEditorFontSelector)
@@ -0,0 +1,21 @@
1
+ import * as client from './font-graphql-client'
2
+
3
+ export const UPDATE_FONT_LIST = 'UPDATE_FONT_LIST'
4
+ export const CLEAR_FONT_LIST = 'CLEAR_FONT_LIST'
5
+
6
+ export const actionUpdateFontList =
7
+ (listParams?: { sortings?: any; filters?: any; pagination?: any }) => async (dispatch: any) => {
8
+ try {
9
+ const fonts = await client.fetchFontList(listParams || { filters: [] })
10
+
11
+ dispatch({
12
+ type: UPDATE_FONT_LIST,
13
+ list: fonts && fonts.items
14
+ })
15
+ } catch (error) {
16
+ console.error(error)
17
+ dispatch({
18
+ type: CLEAR_FONT_LIST
19
+ })
20
+ }
21
+ }