This repository was archived by the owner on Mar 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathx-designer.html
166 lines (162 loc) · 5.27 KB
/
x-designer.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
<!--
Copyright 2013 The Polymer Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
<link rel="import" href="../polymer-layout/polymer-layout.html">
<link rel="import" href="../polymer-flex-layout/polymer-flex-layout.html">
<link rel="import" href="../polymer-ui-splitter/polymer-ui-splitter.html">
<link rel="import" href="../x-designable/x-designable.html">
<link rel="import" href="../x-palette/x-palette.html">
<link rel="import" href="../x-tree/x-tree.html">
<polymer-element name="x-designer" attributes="selected maximized">
<template>
<style>
:host {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
outline: 0;
}
#canvas {
background-color: white;
-webkit-transition: left 0.4s;
transition: left 0.4s;
/*overflow: hidden;*/
z-index: 1;
}
#tools {
width: 284px;
z-index: 1;
box-shadow: 5px 0 8px rgba(0, 0, 0, 0.16);
transition: width 0.3s;
}
#tools.maximized {
width: 0;
}
#palette {
-webkit-transition: left 0.4s;
transition: left 0.4s;
}
#tree {
height: 300px;
overflow: hidden;
}
#canvas:not(.maximized) .selected-element {
outline: solid 10px rgba(72, 154, 254, 0.20);
outline-offset: -2px;
}
</style>
<x-meta id="meta" categories="{{elements}}"></x-meta>
<polymer-flex-layout></polymer-flex-layout>
<section id="tools">
<polymer-flex-layout vertical></polymer-flex-layout>
<x-palette flex id="palette" elements="{{elements}}" canvas="{{$.canvas}}" on-palette-drag="{{paletteDrag}}" on-palette-create-drag-object="{{paletteCreateDragObject}}"></x-palette>
<polymer-ui-splitter direction="down"></polymer-ui-splitter>
<x-tree id="tree" canvas="{{$.canvas}}" selected="{{selected}}"></x-tree>
</section>
<x-designable flex id="canvas" tabIndex="-1" selected="{{selected}}" on-design-change="{{designChange}}"></x-designable>
</template>
<script>
(function() {
Polymer('x-designer', {
maximized: false,
selectedTab: 'design',
ready: function() {
this.fire('designer-ready');
},
paletteDrag: function(event, drag) {
this.$.canvas.drag(drag);
},
paletteCreateDragObject: function(event, detail) {
detail.element = this.createElement(detail.tag);
this.$.canvas.makeElementDraggable(detail.element);
},
designChange: function() {
this.$.canvas.update();
this.$.tree.update();
},
createElement: function(tag) {
var meta = this.$.meta.byId(tag);
var element = meta.createElement();
this.$.canvas.appendChild(element);
this.$.canvas.decorateElement(element);
//this.selected = element;
return element;
},
deleteElement: function() {
this.$.canvas.deleteElement();
},
selectParentElement: function() {
this.$.canvas.selectParentElement();
},
maximizedChanged: function() {
this.$.tools.classList.toggle('maximized', this.maximized);
this.$.canvas.classList.toggle('maximized', this.maximized);
this.$.canvas.dragDisabled = this.maximized;
},
inspectTarget: function(event) {
var t = event.target;
if (t) {
if (t === this.$.canvas) {
this.selected = null;
} else {
// don't allow selection within a node with meta.hideSubtree
var n = t;
while (n) {
if (n.meta && n.meta.hideSubtree) {
t = n;
break;
}
n = n.parentNode;
}
this.selected = t;
}
Platform.flush();
}
},
loadLinks: function(urls, callback) {
Polymer.import(urls, callback);
},
loadHtml: function(html) {
this.$.canvas.loadHtml(html);
},
applyPropertyBinding: function(obj, name, path) {
this.$.canvas.applyPropertyBinding(obj, name, path);
}
/*applySource: function(source) {
this.$.designElement = this.$.designElement.applySource(source);
},
sourceApplied: function(event, node) {
this.$.meta.ensureMeta(node);
// reselect selection
if (this.selected && this.selected.id) {
var selected = this.$.canvas.querySelector('#' + this.selected.id);
}
this.selected = selected || this.$.designElement;
},
publishElement: function(source) {
this.$.publisher.publishElement(source);
},
dumpPreviewSource: function(source) {
var n = this.$.designElement.elementAttributes.name;
source = source + '\n<' + n + '></' + n + '>';
return source;
},
previewElement: function(source) {
this.$.preview.open(this.dumpPreviewSource(source));
},
previewElementSource: function(source) {
this.$.preview.openSource(this.dumpPreviewSource(source));
},
clearElement: function() {
Platform.flush();
this.applySource(this.$.designElement.defaultSource);
}
*/
});
})();
</script>
</polymer-element>