-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtangy-form-html-editor.js
111 lines (103 loc) · 2.97 KB
/
tangy-form-html-editor.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
import {html, PolymerElement} from '@polymer/polymer/polymer-element.js'
/**
* `tangy-form-item-editor`
* ...
*
* @customElement
* @polymer
* @demo demo/index.html
*/
class TangyFormHtmlEditor extends PolymerElement {
static get template() {
return html`
<style>
:host {
display: block;
color: var(--primary-text-color);
font-size: medium;
}
paper-icon-button.small {
width: 30px;
height: 30px;
}
paper-button {
font-family: 'Roboto', 'Noto', sans-serif;
font-weight: normal;
font-size: 14px;
-webkit-font-smoothing: antialiased;
}
paper-button.indigo {
background-color: var(--paper-indigo-500);
color: white;
--paper-button-raised-keyboard-focus: {
background-color: var(--paper-pink-a200) !important;
color: white !important;
};
}
paper-button.indigo:hover {
background-color: var(--paper-indigo-400);
}
paper-button.green {
background-color: var(--paper-green-500);
color: white;
}
paper-button.green[active] {
background-color: var(--paper-red-500);
}
</style>
<div id="container"></div>
<slot></slot>
`;
}
static get properties() {
return {
form: {
type: Object,
value: undefined,
observer: 'render'
}
}
}
render() {
this.$.container.innerHTML = `
<div style="text-align: center">
<h2 style="text-align: left">Form HTML Editor</h2>
<p style="color:red">Carefully back up current HTML before editing</p>
<paper-card style="text-align: left; margin: 0 auto; width:100%; max-width: 650px;">
<div class="card-content">
<slot></slot>
</div>
<div class="card-actions">
<paper-icon-button
id="close"
icon="icons:arrow-back"/>
>
</paper-icon-button>
<paper-icon-button
id="save"
icon="icons:save"
>
</paper-icon-button>
</div>
</paper-card>
</div>
`
let juicyAceEditorEl = document.createElement('juicy-ace-editor')
juicyAceEditorEl.setAttribute('mode', 'ace/mode/html')
juicyAceEditorEl.value = this.form.markup
juicyAceEditorEl.style.height = `${window.innerHeight*.6}px`
juicyAceEditorEl.addEventListener('change', _ => _.stopPropagation())
this.appendChild(juicyAceEditorEl)
this.$.container.querySelector('#close').addEventListener('click', this.onCloseClick.bind(this))
this.$.container.querySelector('#save').addEventListener('click', this.onSaveClick.bind(this))
}
onCloseClick(event) {
this.dispatchEvent(new CustomEvent('close'))
}
onSaveClick(event) {
this.dispatchEvent(new CustomEvent('save', {
detail: this.querySelector('juicy-ace-editor').value
}))
}
}
window.customElements.define('tangy-form-html-editor', TangyFormHtmlEditor);