@operato/font 1.0.0-beta.17 → 1.0.0-beta.18

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 +11 -0
  2. package/custom-elements.json +841 -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-selector.d.ts +36 -0
  7. package/dist/src/font-selector.js +285 -0
  8. package/dist/src/font-selector.js.map +1 -0
  9. package/dist/src/graphql-client.d.ts +20 -0
  10. package/dist/src/graphql-client.js +109 -0
  11. package/dist/src/graphql-client.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 +30 -18
  32. package/src/font-creation-card.ts +260 -0
  33. package/src/font-selector.ts +284 -0
  34. package/src/{graphql-client.js → graphql-client.ts} +5 -6
  35. package/src/index.ts +6 -0
  36. package/src/ox-file-selector.ts +114 -0
  37. package/src/{ox-font-selector.js → ox-font-selector.ts} +32 -36
  38. package/src/{ox-property-editor-font-selector.js → ox-property-editor-font-selector.ts} +1 -2
  39. package/src/redux-font-actions.ts +21 -0
  40. package/src/{redux-font-reducers.js → redux-font-reducers.ts} +17 -9
  41. package/src/font-creation-card.js +0 -270
  42. package/src/font-selector.js +0 -287
  43. package/src/index.js +0 -6
  44. package/src/ox-file-selector.js +0 -138
  45. package/src/redux-font-actions.js +0 -20
  46. package/things-factory.config.js +0 -5
@@ -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 './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
+ }
@@ -1,11 +1,10 @@
1
- import gql from 'graphql-tag'
2
-
3
1
  import { client } from '@operato/graphql'
2
+ import gql from 'graphql-tag'
4
3
 
5
4
  /**
6
5
  * @param {Object} listParam {filters, pagination, sortings}
7
6
  */
8
- export async function fetchFontList(listParam) {
7
+ export async function fetchFontList(listParam?: { sortings?: any; filters?: any; pagination?: any }) {
9
8
  const response = await client.query({
10
9
  query: gql`
11
10
  query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {
@@ -37,7 +36,7 @@ export async function fetchFontList(listParam) {
37
36
  /**
38
37
  * @param {Object} font Font patch
39
38
  */
40
- export async function createFont(font) {
39
+ export async function createFont(font: any) {
41
40
  const response = await client.mutate({
42
41
  mutation: gql`
43
42
  mutation CreateFont($font: NewFont!) {
@@ -66,7 +65,7 @@ export async function createFont(font) {
66
65
  /**
67
66
  * @param {Object} font Font patch
68
67
  */
69
- export async function updateFont(font) {
68
+ export async function updateFont(font: any) {
70
69
  var { id, ...patch } = font
71
70
 
72
71
  const response = await client.mutate({
@@ -102,7 +101,7 @@ export async function updateFont(font) {
102
101
  /**
103
102
  * @param {String} id Font id
104
103
  */
105
- export async function deleteFont(id) {
104
+ export async function deleteFont(id: string) {
106
105
  const response = await client.mutate({
107
106
  mutation: gql`
108
107
  mutation ($id: String!) {
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
+ }
@@ -6,41 +6,39 @@ import '@material/mwc-icon'
6
6
  import './font-selector'
7
7
 
8
8
  import { css, html, LitElement } from 'lit'
9
+ import { customElement, property } from 'lit/decorators.js'
9
10
 
10
11
  import { i18next } from '@operato/i18n'
11
12
  import { openPopup } from '@operato/layout'
12
13
 
14
+ @customElement('ox-font-selector')
13
15
  export default class OxFontSelector extends LitElement {
14
- static get properties() {
15
- return {
16
- value: String,
17
- properties: Object
18
- }
19
- }
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
+ ]
20
37
 
21
- static get styles() {
22
- return [
23
- css`
24
- :host {
25
- position: relative;
26
- display: inline-block;
27
- }
28
-
29
- input[type='text'] {
30
- box-sizing: border-box;
31
- width: 100%;
32
- height: 100%;
33
- border: 1px solid rgba(0, 0, 0, 0.2);
34
- }
35
-
36
- mwc-icon {
37
- position: absolute;
38
- top: 0;
39
- right: 0;
40
- }
41
- `
42
- ]
43
- }
38
+ @property({ type: String }) value?: string
39
+ @property({ type: Object }) properties: any
40
+
41
+ popup: any
44
42
 
45
43
  render() {
46
44
  return html`
@@ -48,16 +46,16 @@ export default class OxFontSelector extends LitElement {
48
46
  id="text"
49
47
  type="text"
50
48
  .value=${this.value || ''}
51
- @change=${e => this._onInputChanged(e)}
49
+ @change=${(e: Event) => this._onInputChanged(e)}
52
50
  .placeholder=${this.getAttribute('placeholder') || ''}
53
51
  />
54
52
 
55
- <mwc-icon @click=${e => this.openSelector(e)}>font_download</mwc-icon>
53
+ <mwc-icon @click=${() => this.openSelector()}>font_download</mwc-icon>
56
54
  `
57
55
  }
58
56
 
59
- _onInputChanged(e) {
60
- this.value = e.target.value
57
+ _onInputChanged(e: Event) {
58
+ this.value = (e.target as HTMLInputElement).value
61
59
  this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
62
60
  }
63
61
 
@@ -76,7 +74,7 @@ export default class OxFontSelector extends LitElement {
76
74
  var template = html`
77
75
  <font-selector
78
76
  .creatable=${true}
79
- @font-selected=${async e => {
77
+ @font-selected=${async (e: CustomEvent) => {
80
78
  var font = e.detail.font
81
79
  this.value = font.name
82
80
 
@@ -94,5 +92,3 @@ export default class OxFontSelector extends LitElement {
94
92
  })
95
93
  }
96
94
  }
97
-
98
- customElements.define('ox-font-selector', OxFontSelector)
@@ -4,9 +4,8 @@
4
4
 
5
5
  import './ox-font-selector'
6
6
 
7
- import { html } from 'lit'
8
-
9
7
  import { OxPropertyEditor } from '@operato/property-editor'
8
+ import { html } from 'lit'
10
9
 
11
10
  export class OxPropertyEditorFontSelector extends OxPropertyEditor {
12
11
  editorTemplate() {
@@ -0,0 +1,21 @@
1
+ import * as client from './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
+ }
@@ -1,15 +1,24 @@
1
+ import { CLEAR_FONT_LIST, UPDATE_FONT_LIST } from './redux-font-actions.js'
2
+
3
+ import { Action } from 'redux'
1
4
  import WebFont from 'webfontloader'
2
5
 
3
- import { CLEAR_FONT_LIST, UPDATE_FONT_LIST } from './redux-font-actions.js'
6
+ type Font = {
7
+ name: string
8
+ provider: string
9
+ uri: string
10
+ active: boolean
11
+ files: Array<{ name: string; fullpath: string }>
12
+ }
4
13
 
5
- const reducerFont = (state = [], action) => {
14
+ const ReducerFont = (state = [], action: any) => {
6
15
  switch (action.type) {
7
16
  case UPDATE_FONT_LIST:
8
- let newState = action.list
17
+ let newState = action.list as Array<Font>
9
18
  let activatedFonts = newState.filter(font => font.active)
10
19
 
11
- let googles = []
12
- let customs = []
20
+ let googles = [] as Array<string>
21
+ let customs = [] as Array<string>
13
22
  let customFontCSS = ''
14
23
 
15
24
  activatedFonts.forEach(font => {
@@ -44,17 +53,16 @@ const reducerFont = (state = [], action) => {
44
53
  }
45
54
  })
46
55
 
47
- let style = document.head.querySelector('#custom-fonts')
56
+ let style = document.head.querySelector('#custom-fonts') as HTMLStyleElement
48
57
  if (!style) {
49
58
  style = document.createElement('style')
50
59
  style.id = 'custom-fonts'
51
- style.type = 'text/css'
52
60
  document.head.appendChild(style)
53
61
  }
54
62
  style.innerHTML = customFontCSS
55
63
 
56
64
  // TODO: typekit 등 타 서비스 지원
57
- let WebFontConfig = {}
65
+ let WebFontConfig = {} as any
58
66
  if (googles.length) {
59
67
  WebFontConfig.google = {
60
68
  families: googles
@@ -77,4 +85,4 @@ const reducerFont = (state = [], action) => {
77
85
  }
78
86
  }
79
87
 
80
- export default reducerFont
88
+ export default ReducerFont