-
Notifications
You must be signed in to change notification settings - Fork 78
/
hax-preferences-dialog.js
290 lines (287 loc) · 7.75 KB
/
hax-preferences-dialog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
import { html, css } from "lit-element/lit-element.js";
import { SimpleColors } from "@lrnwebcomponents/simple-colors/simple-colors.js";
import { winEventsElement } from "@lrnwebcomponents/utils/utils.js";
/**
* @deprecatedApply - required for @apply / invoking @apply css var convention
*/
import "@polymer/polymer/lib/elements/custom-style.js";
/**
* `hax-export-dialog`
* @customElement hax-export-dialog
* `Export dialog with all export options and settings provided.`
*/
class HaxPreferencesDialog extends winEventsElement(SimpleColors) {
/**
* LitElement constructable styles enhancement
*/
static get styles() {
return [
...super.styles,
css`
:host {
display: block;
}
iron-icon:not(:defined),
paper-button:not(:defined),
app-drawer:not(:defined) {
display: none;
}
#dialog {
z-index: 1000;
margin-top: 56px;
}
#closedialog {
float: right;
top: 124px;
right: 0;
position: absolute;
padding: 8px;
margin: 0;
background-color: var(--hax-color-menu-heading-bg, #eeeeee);
color: var(--hax-color-menu-heading-color, black);
width: 40px;
height: 40px;
min-width: unset;
}
.title {
position: relative;
padding: 16px;
outline: 0;
font-weight: 600;
text-align: left;
margin: 0;
background-color: var(--hax-color-menu-heading-bg, #eeeeee);
color: var(--hax-color-menu-heading-color, black);
font-size: 18px;
line-height: 18px;
font-family: "Noto Serif", serif;
}
eco-json-schema-object {
color: white;
}
.pref-container {
text-align: left;
padding: 16px;
}
`
];
}
constructor() {
super();
this.__winEvents = {
"hax-store-property-updated": "_haxStorePropertyUpdated"
};
this.title = "Editor preferences";
import("@polymer/iron-icon/iron-icon.js");
import("@polymer/iron-icons/iron-icons.js");
import("@polymer/paper-button/paper-button.js");
import("@lrnwebcomponents/eco-json-schema-form/eco-json-schema-form.js");
import("@lrnwebcomponents/eco-json-schema-form/lib/eco-json-schema-object.js");
import("@polymer/app-layout/app-drawer/app-drawer.js");
}
updated(changedProperties) {
changedProperties.forEach((oldValue, propName) => {
// notify when any of these change
if (propName == "preferences") {
this._preferencesChanged(this[propName]);
this.dispatchEvent(
new CustomEvent(`${propName}-changed`, {
detail: {
value: this[propName]
}
})
);
}
});
}
render() {
return html`
<custom-style>
<style>
app-drawer {
--app-drawer-content-container: {
background-color: #ffffff;
}
--app-drawer-width: 320px;
}
eco-json-schema-object {
--eco-json-schema-object-form : {
-ms-flex: unset;
-webkit-flex: unset;
flex: unset;
-webkit-flex-basis: unset;
flex-basis: unset;
}
--paper-checkbox-size: 16px;
--paper-checkbox-checked-ink-color: var(--hax-color-accent1);
--paper-checkbox-label: {
font-size: 16px;
line-height: 16px;
}
}
</style>
</custom-style>
<app-drawer
id="dialog"
align="right"
transition-duration="300"
?opened="${this.opened}"
@opened-changed="${this.openedChanged}"
>
<h3 class="title">
<iron-icon icon="icons:settings"></iron-icon> ${this.title}
</h3>
<div style="height: 100%; overflow: auto;" class="pref-container">
<eco-json-schema-object
.schema="${this.schema}"
@value-changed="${this.valueChanged}"
></eco-json-schema-object>
</div>
<paper-button id="closedialog" @click="${this.closeEvent}">
<iron-icon icon="icons:cancel" title="Close dialog"></iron-icon>
</paper-button>
</app-drawer>
`;
}
openedChanged(e) {
// force close event to align data model if clicking away
if (!e.detail.value && window.HaxStore.instance.openDrawer === this) {
window.HaxStore.write("openDrawer", false, this);
}
}
closeEvent(e) {
this.opened = false;
}
static get tag() {
return "hax-preferences-dialog";
}
static get properties() {
return {
/**
* Title when open.
*/
title: {
type: String
},
/**
* Schema that has all of inputs / manages state
*/
schema: {
type: Object
},
/**
* Preferences managed for everything global about HAX.
*/
preferences: {
type: Object
},
opened: {
type: Boolean
}
};
}
firstUpdated(changedProperties) {
// JSON schema object needs delayed to ensure page repaints the form
var schema = {
$schema: "http://json-schema.org/schema#",
title: "HAX preferences",
type: "object",
properties: {
haxShowExportButton: {
title: "View source button",
type: "boolean",
value: true
},
haxRayMode: {
title: "X-Ray vision",
type: "boolean",
value: false
},
haxDeveloperMode: {
title: "Developer mode",
type: "boolean",
value: false
},
haxVoiceCommands: {
title: "Voice commands",
type: "boolean",
value: false
},
haxGithubReport: {
title: "Report issue",
type: "string",
value: false,
component: {
name: "a",
properties: {
rel: "noopener",
style:
"color: #81a3a9;font-size: 18px;top: 100vh;position: fixed;right: 0;padding: 16px;font-style: italic;",
id: "reportghissue",
href:
"https://github.com/elmsln/lrnwebcomponents/issues/new?body=URL%20base:%20" +
window.location.pathname +
"&title=[hax] Bug%20report%20from%20preference%20panel",
target: "_blank"
},
slot: "Report an issue with HAX"
}
}
}
};
this.schema = { ...schema };
// fire an event that this is a core piece of the system
this.dispatchEvent(
new CustomEvent("hax-register-core-piece", {
bubbles: true,
cancelable: true,
composed: true,
detail: {
piece: "haxPreferences",
object: this
}
})
);
}
/**
* Store updated, sync.
*/
_haxStorePropertyUpdated(e) {
if (
e.detail &&
typeof e.detail.value !== typeof undefined &&
e.detail.property &&
e.detail.property === "globalPreferences" &&
e.detail.owner !== this
) {
this.preferences = { ...e.detail.value };
}
}
/**
* Notice preferences have changed.
*/
_preferencesChanged(newValue) {
if (this.schema && this.schema.properties && window.HaxStore.ready) {
window.HaxStore.write("globalPreferences", newValue, this);
}
}
valueChanged(e) {
if (e.detail.value) {
this.preferences = { ...e.detail.value };
}
}
/**
* open the dialog
*/
open() {
this.opened = true;
}
/**
* close the dialog
*/
close() {
this.opened = false;
}
}
window.customElements.define(HaxPreferencesDialog.tag, HaxPreferencesDialog);
export { HaxPreferencesDialog };