@operato/font 1.0.0-beta.9 → 1.0.6
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.
- package/CHANGELOG.md +392 -0
- package/custom-elements.json +855 -0
- package/dist/src/font-creation-card.d.ts +18 -0
- package/dist/src/font-creation-card.js +258 -0
- package/dist/src/font-creation-card.js.map +1 -0
- package/dist/src/font-graphql-client.d.ts +20 -0
- package/dist/src/font-graphql-client.js +109 -0
- package/dist/src/font-graphql-client.js.map +1 -0
- package/dist/src/font-selector.d.ts +36 -0
- package/dist/src/font-selector.js +285 -0
- package/dist/src/font-selector.js.map +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.js +6 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/ox-file-selector.d.ts +12 -0
- package/dist/src/ox-file-selector.js +129 -0
- package/dist/src/ox-file-selector.js.map +1 -0
- package/dist/src/ox-font-selector.d.ts +15 -0
- package/dist/src/ox-font-selector.js +88 -0
- package/dist/src/ox-font-selector.js.map +1 -0
- package/dist/src/ox-property-editor-font-selector.d.ts +8 -0
- package/dist/src/ox-property-editor-font-selector.js +13 -0
- package/dist/src/ox-property-editor-font-selector.js.map +1 -0
- package/dist/src/redux-font-actions.d.ts +7 -0
- package/dist/src/redux-font-actions.js +19 -0
- package/dist/src/redux-font-actions.js.map +1 -0
- package/dist/src/redux-font-reducers.d.ts +12 -0
- package/dist/src/redux-font-reducers.js +70 -0
- package/dist/src/redux-font-reducers.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +78 -20
- package/src/font-creation-card.ts +260 -0
- package/src/{graphql-client.js → font-graphql-client.ts} +35 -26
- package/src/font-selector.ts +284 -0
- package/src/index.ts +6 -0
- package/src/ox-file-selector.ts +114 -0
- package/src/ox-font-selector.ts +94 -0
- package/src/ox-property-editor-font-selector.ts +17 -0
- package/src/redux-font-actions.ts +21 -0
- package/src/redux-font-reducers.ts +88 -0
- package/src/font-creation-card.js +0 -311
- package/src/font-selector.js +0 -465
- package/src/index.js +0 -3
- package/src/ox-font-selector.js +0 -102
- package/src/ox-property-editor-font-selector.js +0 -25
- package/things-factory.config.js +0 -5
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import './ox-file-selector'
|
|
2
|
+
|
|
3
|
+
import { LitElement, css, html } from 'lit'
|
|
4
|
+
import { customElement, property } from 'lit/decorators.js'
|
|
5
|
+
import { i18next, localize } from '@operato/i18n'
|
|
6
|
+
|
|
7
|
+
@customElement('font-creation-card')
|
|
8
|
+
export class FontCreationCard extends localize(i18next)(LitElement) {
|
|
9
|
+
static styles = [
|
|
10
|
+
css`
|
|
11
|
+
:host {
|
|
12
|
+
position: relative;
|
|
13
|
+
|
|
14
|
+
padding: 0;
|
|
15
|
+
margin: 0;
|
|
16
|
+
height: 100%;
|
|
17
|
+
|
|
18
|
+
-webkit-transform-style: preserve-3d;
|
|
19
|
+
transform-style: preserve-3d;
|
|
20
|
+
-webkit-transition: all 0.5s ease-in-out;
|
|
21
|
+
transition: all 0.5s ease-in-out;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
:host(.flipped) {
|
|
25
|
+
-webkit-transform: var(--card-list-flip-transform);
|
|
26
|
+
transform: var(--card-list-flip-transform);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
[front],
|
|
30
|
+
[back] {
|
|
31
|
+
position: absolute;
|
|
32
|
+
|
|
33
|
+
width: 100%;
|
|
34
|
+
height: 100%;
|
|
35
|
+
margin: 0;
|
|
36
|
+
padding: 0;
|
|
37
|
+
|
|
38
|
+
border: var(--card-list-create-border);
|
|
39
|
+
border-radius: var(--card-list-create-border-radius);
|
|
40
|
+
|
|
41
|
+
background-color: #fff;
|
|
42
|
+
|
|
43
|
+
-webkit-backface-visibility: hidden;
|
|
44
|
+
backface-visibility: hidden;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
[front] {
|
|
48
|
+
display: flex;
|
|
49
|
+
flex-direction: column;
|
|
50
|
+
align-items: center;
|
|
51
|
+
justify-content: center;
|
|
52
|
+
|
|
53
|
+
text-align: center;
|
|
54
|
+
font-size: 0.8em;
|
|
55
|
+
color: var(--card-list-create-color);
|
|
56
|
+
text-transform: capitalize;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
[front] mwc-icon {
|
|
60
|
+
font-size: 3.5em;
|
|
61
|
+
color: var(--card-list-create-icon-color);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
[back] {
|
|
65
|
+
-webkit-transform: var(--card-list-flip-transform);
|
|
66
|
+
transform: var(--card-list-flip-transform);
|
|
67
|
+
box-sizing: border-box;
|
|
68
|
+
display: grid;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
[back] form {
|
|
72
|
+
padding: var(--card-list-create-form-padding);
|
|
73
|
+
width: 100%;
|
|
74
|
+
height: 100%;
|
|
75
|
+
box-sizing: border-box;
|
|
76
|
+
display: grid;
|
|
77
|
+
grid-template-columns: 1fr;
|
|
78
|
+
grid-template-rows: auto 1fr auto;
|
|
79
|
+
justify-content: center;
|
|
80
|
+
align-items: center;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
[back] form .props {
|
|
84
|
+
width: 100%;
|
|
85
|
+
height: 100%;
|
|
86
|
+
box-sizing: border-box;
|
|
87
|
+
display: grid;
|
|
88
|
+
grid-template-columns: repeat(10, 1fr);
|
|
89
|
+
grid-row-gap: 7px;
|
|
90
|
+
justify-content: center;
|
|
91
|
+
align-items: center;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
[back] form .props label {
|
|
95
|
+
grid-column: span 4;
|
|
96
|
+
font: var(--card-list-create-label-font);
|
|
97
|
+
color: var(--card-list-create-label-color);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
[back] form .props input,
|
|
101
|
+
[back] form .props select {
|
|
102
|
+
grid-column: span 6;
|
|
103
|
+
background-color: #fff;
|
|
104
|
+
border: var(--card-list-create-input-border);
|
|
105
|
+
border-radius: var(--card-list-create-input-border-radius);
|
|
106
|
+
font: var(--card-list-create-input-font);
|
|
107
|
+
color: var(--card-list-create-input-color);
|
|
108
|
+
width: -moz-available;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
ox-file-selector {
|
|
112
|
+
grid-column: span 6;
|
|
113
|
+
font: var(--card-list-create-input-font);
|
|
114
|
+
border: none;
|
|
115
|
+
box-sizing: border-box;
|
|
116
|
+
padding: 0;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
[back] input[type='submit'] {
|
|
120
|
+
background-color: var(--button-background-color) !important;
|
|
121
|
+
font: var(--button-font);
|
|
122
|
+
color: var(--button-color) !important;
|
|
123
|
+
border-radius: var(--button-radius);
|
|
124
|
+
border: var(--button-border);
|
|
125
|
+
grid-column: span 10;
|
|
126
|
+
grid-row: auto / -1;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.hidden {
|
|
130
|
+
display: none !important;
|
|
131
|
+
}
|
|
132
|
+
`
|
|
133
|
+
]
|
|
134
|
+
|
|
135
|
+
@property({ type: String }) provider: string = 'google'
|
|
136
|
+
@property({ type: Array }) googleFonts: Array<string> = []
|
|
137
|
+
@property({ type: Array }) files?: Array<any>
|
|
138
|
+
|
|
139
|
+
providers: Array<{ value: string; display: string }> = [
|
|
140
|
+
{ value: 'google', display: 'Google' },
|
|
141
|
+
// TODO 구글 외 폰트 서비스 구현
|
|
142
|
+
// { value: 'typekit', display: 'Typekit' },
|
|
143
|
+
{ value: 'custom', display: 'Custom' }
|
|
144
|
+
]
|
|
145
|
+
|
|
146
|
+
render() {
|
|
147
|
+
let isProviderGoogle = this.provider == 'google' && this.googleFonts.length > 0
|
|
148
|
+
let isFileAttached = this.files && this.files.length > 0 ? true : false
|
|
149
|
+
|
|
150
|
+
return html`
|
|
151
|
+
<div @click=${(e: Event) => this.onClickFlip(e)} front><mwc-icon>add_circle_outline</mwc-icon>create font</div>
|
|
152
|
+
|
|
153
|
+
<div @click=${(e: Event) => this.onClickFlip(e)} back>
|
|
154
|
+
<form @submit=${(e: Event) => this.onClickSubmit(e)}>
|
|
155
|
+
<div class="props">
|
|
156
|
+
<label>${i18next.t('label.provider')}</label>
|
|
157
|
+
<select
|
|
158
|
+
name="provider"
|
|
159
|
+
@change=${(e: Event) => {
|
|
160
|
+
this.provider = (e.target as HTMLInputElement).value
|
|
161
|
+
if (this.provider === 'google') {
|
|
162
|
+
fetch(`/all-google-fonts`).then(async response => {
|
|
163
|
+
if (response.ok) this.googleFonts = await response.json()
|
|
164
|
+
else {
|
|
165
|
+
console.warn(
|
|
166
|
+
`(${response.url}) ${response.status} ${response.statusText}. Could not load Google fonts.`
|
|
167
|
+
)
|
|
168
|
+
}
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
}}
|
|
172
|
+
>
|
|
173
|
+
${this.providers.map(
|
|
174
|
+
p => html` <option value=${p.value} ?selected=${this.provider == p.value}>${p.display}</option> `
|
|
175
|
+
)}
|
|
176
|
+
</select>
|
|
177
|
+
|
|
178
|
+
<label>${i18next.t('label.name')}</label>
|
|
179
|
+
<input type="text" name="${isProviderGoogle ? '' : 'name'}" ?hidden=${isProviderGoogle} />
|
|
180
|
+
<select name="${isProviderGoogle ? 'name' : ''}" ?hidden=${!isProviderGoogle}>
|
|
181
|
+
<option value=""> </option>
|
|
182
|
+
${isProviderGoogle && this.googleFonts.map(f => html` <option value=${f}>${f}</option> `)}
|
|
183
|
+
</select>
|
|
184
|
+
|
|
185
|
+
<label ?hidden=${this.provider != 'custom'}>${i18next.t('label.uri')}</label>
|
|
186
|
+
<input
|
|
187
|
+
?hidden=${this.provider != 'custom'}
|
|
188
|
+
?disabled=${isFileAttached}
|
|
189
|
+
.value=${isFileAttached ? this.files![0].name : ''}
|
|
190
|
+
type="text"
|
|
191
|
+
name="uri"
|
|
192
|
+
/>
|
|
193
|
+
<!-- display when attachment module is imported -->
|
|
194
|
+
<label ?hidden=${this.provider != 'custom'}>${i18next.t('label.file')}</label>
|
|
195
|
+
<ox-file-selector
|
|
196
|
+
class="${this.provider != 'custom' ? 'hidden' : ''}"
|
|
197
|
+
name="file"
|
|
198
|
+
label="${i18next.t('label.select file')}"
|
|
199
|
+
accept=".ttf,.otf,.woff,.woff2,.eot,.svg,.svgz"
|
|
200
|
+
multiple
|
|
201
|
+
@file-change=${(e: CustomEvent) => {
|
|
202
|
+
this.files = Array.from(e.detail.files)
|
|
203
|
+
}}
|
|
204
|
+
></ox-file-selector>
|
|
205
|
+
<!------------------------------------------------>
|
|
206
|
+
|
|
207
|
+
<label for="checkbox-active" @click=${(e: Event) => e.stopPropagation()}>
|
|
208
|
+
${i18next.t('label.active')}
|
|
209
|
+
</label>
|
|
210
|
+
<input id="checkbox-active" type="checkbox" name="active" checked />
|
|
211
|
+
</div>
|
|
212
|
+
<div></div>
|
|
213
|
+
<input type="submit" value=${i18next.t('button.create')} />
|
|
214
|
+
</form>
|
|
215
|
+
</div>
|
|
216
|
+
`
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
onClickFlip(e: Event) {
|
|
220
|
+
const target = e.target as HTMLElement
|
|
221
|
+
const currentTarget = e.currentTarget as HTMLElement
|
|
222
|
+
|
|
223
|
+
if (!['INPUT', 'SELECT', 'OPTION'].find(tagName => tagName === target.tagName)) {
|
|
224
|
+
if (currentTarget.hasAttribute('front')) this.reset() // 입력 폼으로 뒤집기 전에 한 번 리셋
|
|
225
|
+
this.classList.toggle('flipped')
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
async onClickSubmit(e: Event) {
|
|
230
|
+
e.preventDefault()
|
|
231
|
+
e.stopPropagation()
|
|
232
|
+
|
|
233
|
+
var form = e.target as HTMLFormElement
|
|
234
|
+
|
|
235
|
+
var detail = {} as any
|
|
236
|
+
|
|
237
|
+
detail.name = (form.elements.namedItem('name') as HTMLInputElement).value
|
|
238
|
+
detail.provider = (form.elements.namedItem('provider') as HTMLInputElement).value
|
|
239
|
+
detail.active = (form.elements.namedItem('active') as HTMLInputElement).checked
|
|
240
|
+
|
|
241
|
+
if (this.provider === 'custom') {
|
|
242
|
+
detail.uri = (form.elements.namedItem('uri') as HTMLInputElement).value
|
|
243
|
+
if (this.files && this.files.length > 0) {
|
|
244
|
+
detail.files = this.files
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
this.dispatchEvent(new CustomEvent('create-font', { detail }))
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
reset() {
|
|
252
|
+
var form = this.renderRoot.querySelector('form')
|
|
253
|
+
if (form) {
|
|
254
|
+
form.reset()
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
this.files = []
|
|
258
|
+
this.classList.remove('flipped')
|
|
259
|
+
}
|
|
260
|
+
}
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import { client } from
|
|
2
|
-
import gql from
|
|
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
|
-
|
|
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
|
+
}
|