This repository has been archived by the owner on Jul 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhax-export-dialog.html
295 lines (289 loc) · 8.85 KB
/
hax-export-dialog.html
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
291
292
293
294
295
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../app-layout/app-drawer/app-drawer.html">
<link rel="import" href="../paper-icon-button/paper-icon-button.html">
<link rel="import" href="../paper-input/paper-input.html">
<link rel="import" href="../paper-button/paper-button.html">
<link rel="import" href="../mtz-file-download-behavior/mtz-file-download-behavior.html">
<link rel="import" href="../simple-colors/simple-colors.html">
<!--
`hax-export-dialog`
Export dialog with all export options and settings provided.
@demo demo/index.html
@microcopy - the mental model for this element
-
-->
<dom-module id="hax-export-dialog">
<template>
<style>
:host {
display: block;
}
#dialog {
z-index: 1000;
margin-top: 64px;
}
paper-icon-button#closedialog {
float: right;
top: 135px;
right: 0;
position: absolute;
padding: 4px;
margin: 0;
color: var(--simple-colors-light-green-background1);
}
.title {
margin-top: 32px;
text-align: center;
padding: 16px;
margin: 0;
background-color: rgba(0, 0, 0, 0.5);
font-size: 32px;
font-weight: bold;
font-family: sans-serif;
text-transform: uppercase;
color: var(--simple-colors-light-green-background1);
}
.pref-container {
text-align: left;
padding: 16px;
}
app-drawer {
--app-drawer-content-container: {
background-color: rgba(0, 0, 0, 0.7);
};
--app-drawer-width: 320px;
}
paper-button {
color: #222222;
text-transform: none;
margin:0;
background-color: #F8F8F8;
display: flex;
border-radius: 0px;
border-style: solid;
border-width: 1px;
min-width: unset;
}
paper-button:focus,
paper-button:hover {
background-color: var(--simple-colors-light-green-background1);
border-color: var(--simple-colors-light-green-background1);
outline: 2px solid var(--simple-colors-light-green-background1);
}
.buttons paper-button {
color: black;
font-size: 12px;
font-weight: bold;
text-transform: none;
}
#textarea {
margin-bottom: 16px;
padding: 10px;
width: 90%;
font-size: 10px;
resize: none;
width: 80%;
width: -webkit-fill-available;
background-color: transparent;
color: #EEEEEE;
font-family: monospace;
}
</style>
<app-drawer id="dialog" align="right">
<h3 class="title">[[title]]</h3>
<div style="height: 100%; overflow: auto;" class="pref-container">
<textarea id="textarea" rows="20"></textarea>
<div class="buttons">
<paper-button id="downloadfull" raised>Download as full file</paper-button>
<paper-button id="download" raised>Download HTML contents only</paper-button>
<paper-button id="copy" raised>Copy to clipboard</paper-button>
<paper-button id="import" raised hidden$="[[!globalPreferences.haxDeveloperMode]]">Import textarea into HAX</paper-button>
<paper-button id="elementexport" raised hidden$="[[!globalPreferences.haxDeveloperMode]]">Copy as HAX schema to clipboard</paper-button>
<paper-button id="close" raised>Close dialog</paper-button>
</div>
</div>
<paper-icon-button id="closedialog" on-tap="close" icon="icons:cancel" title="Close dialog"></paper-icon-button>
</app-drawer>
</template>
<script>
Polymer({
is: 'hax-export-dialog',
listeners: {
'download.tap': 'download',
'downloadfull.tap': 'downloadfull',
'import.tap': 'importContent',
'copy.tap': 'selectBody',
'close.tap': 'close',
'elementexport.tap': 'htmlToHaxElements',
},
behaviors: [
mtz.FileDownloadBehavior,
simpleColorsBehaviors,
],
properties: {
/**
* Title when open.
*/
title: {
type: String,
value: 'Export',
},
/**
* Access to the global properties object.
*/
globalPreferences: {
type: Object,
value: {},
},
},
/**
* Ready life cycle.
*/
ready: function() {
document.body.appendChild(this);
document.body.addEventListener('hax-store-property-updated', this._haxStorePropertyUpdated.bind(this));
},
/**
* Attached to the DOM, now fire that we exist.
*/
attached: function() {
// fire an event that this is the manager
this.fire('hax-register-export', this);
},
/**
* Detached life cycle
*/
detached: function () {
document.body.removeEventListener('hax-store-property-updated', this._haxStorePropertyUpdated.bind(this));
},
/**
* Store updated, sync.
*/
_haxStorePropertyUpdated: function(e) {
if (e.detail && typeof e.detail.value !== typeof undefined && e.detail.property) {
if (typeof e.detail.value === 'object') {
this.set(e.detail.property, null);
}
this.set(e.detail.property, e.detail.value);
}
},
/**
* Download file.
*/
download: function(e) {
const data = this.contentToFile(false);
this.downloadFromData(data, 'html', 'my-new-code');
},
/**
* Download file.
*/
downloadfull: function(e) {
const data = this.contentToFile(true);
this.downloadFromData(data, 'html', 'my-new-webpage');
},
/**
* Download file.
*/
importContent: function(e) {
// import contents of this text area into the activeHaxBody
const htmlBody = this.$.textarea.value;
return Polymer.HaxStore.instance.activeHaxBody.importContent(htmlBody);
},
/**
* selectBody
*/
selectBody: function(e) {
this.$.textarea.focus();
this.$.textarea.select();
document.execCommand('copy');
},
/**
* HTML to HAX Elements
*/
htmlToHaxElements: function(e) {
let elements = Polymer.HaxStore.htmlToHaxElements(this.$.textarea.value);
var str = JSON.stringify(elements, null, 2);
let val = this.$.textarea.value;
this.$.textarea.value = str;
this.$.textarea.focus();
this.$.textarea.select();
document.execCommand('copy');
this.$.textarea.value = val;
},
/**
* Output entire thing as a file.
*/
contentToFile: function(full) {
var content = '';
// if you want full HTML headers or not
if (full) {
let elementList = Polymer.HaxStore.instance.elementList;
// @todo obviously not sustainable
let url = 'https://lrnwebcomponents.github.io/hax-body/components';
content = `
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">
<title>hax-body demo</title>
<script src="${url}/webcomponentsjs/webcomponents-lite.js">`;
content += '</';
content += 'script>';
content += `
<style>
body {
padding: 32px;
}
</style>
<script>
/* this script must run before Polymer is imported */
window.Polymer = {
dom: 'shady',
lazyRegister: true
};
`;
content += '</';
content += 'script>';
var ignoreList = ['iframe', 'a', 'img', 'hr', 'p'];
for (var index in elementList) {
if (ignoreList.indexOf(index) === -1) {
content += '<link rel="import" href="' + url + '/' + index + '/' + index + '.html" />' + "\n";
}
}
content += '</head><body>';
content += Polymer.HaxStore.instance.activeHaxBody.haxToContent();
content += '</body></html>';
}
else {
content = Polymer.HaxStore.instance.activeHaxBody.haxToContent();
}
return content;
},
/**
* Toggle ourselves.
*/
toggleDialog: function() {
if (this.$.dialog.opened) {
this.close();
}
else {
this.$.textarea.value = this.contentToFile(false);
Polymer.HaxStore.instance.closeAllDrawers(this);
}
},
/**
* open the dialog
*/
open: function() {
this.$.dialog.open();
},
/**
* close the dialog
*/
close: function() {
this.$.dialog.close();
},
});
</script>
</dom-module>