Skip to content

Commit 21c964b

Browse files
committed
add page preview [need review]
1 parent 40b6061 commit 21c964b

File tree

5 files changed

+100
-75
lines changed

5 files changed

+100
-75
lines changed

src/assets/js/functions.js

+32-48
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,16 @@
11
let html2canvas = require('html2canvas');
2-
let getScreenshotOfElement = function (element, posX, posY, width, height, callback) {
2+
let getScreenshotOfElement = function (element, callback) {
33
html2canvas(element, {
4-
onrendered: function (canvas) {
5-
var context = canvas.getContext('2d');
6-
var imageData = context.getImageData(posX, posY, width, height).data;
7-
var outputCanvas = document.createElement('canvas');
8-
var outputContext = outputCanvas.getContext('2d');
9-
outputCanvas.width = width;
10-
outputCanvas.height = height;
4+
}).then(function (canvas) {
115

12-
var idata = outputContext.createImageData(width, height);
13-
idata.data.set(imageData);
14-
outputContext.putImageData(idata, 0, 0);
15-
callback(outputCanvas.toDataURL().replace("data:image/png;base64,", ""));
16-
},
17-
width: width,
18-
height: height,
19-
useCORS: true,
20-
taintTest: false,
21-
allowTaint: false
22-
});
6+
callback(canvas.toDataURL("image/png").split("data:image/png;base64,").join(''));
7+
},);
238
}
249

25-
let takeScreenShot = function (id, w, h, x = 0, y = 0) {
26-
getScreenshotOfElement(document.querySelector(id), x, y, w, h, function (data) {
27-
// in the data variable there is the base64 image
28-
// exmaple for displaying the image in an <img>
29-
return "data:image/png;base64," + data;
10+
let takeScreenShot = function (id, cl) {
11+
getScreenshotOfElement(document.querySelector(id), function (data) {
12+
let back = "data:image/png;base64," + data;
13+
cl(back);
3014
});
3115
};
3216

@@ -44,10 +28,10 @@ let clone = function (obj) {
4428
* @returns {string|*}
4529
*/
4630
let getColor = function (color) {
47-
for( const clr of window.colors) {
48-
if (clr.value === color){
49-
return clr.color;
50-
}
31+
for (const clr of window.colors) {
32+
if (clr.value === color) {
33+
return clr.color;
34+
}
5135
}
5236
return '#000000';
5337

@@ -58,28 +42,28 @@ let getColor = function (color) {
5842
* @param isActiveWidget
5943
* @returns {string|*}
6044
*/
61-
let color2web = function (color,isActiveWidget = true) {
62-
if( color === 'default' ){
63-
if ( isActiveWidget){
64-
return getColor(window.appData.project.xColor);
65-
} else {
66-
if (window.appData.project.isDark){
67-
return "#222222";
68-
}
69-
}
70-
return getColor(window.appData.project.xColor);
71-
}else{
72-
return getColor(color);
73-
}
45+
let color2web = function (color, isActiveWidget = true) {
46+
if (color === 'default') {
47+
if (isActiveWidget) {
48+
return getColor(window.appData.project.xColor);
49+
} else {
50+
if (window.appData.project.isDark) {
51+
return "#222222";
52+
}
53+
}
54+
return getColor(window.appData.project.xColor);
55+
} else {
56+
return getColor(color);
57+
}
7458
};
7559

76-
let calcPadding = function (paddingValue,scale = 1,invert = false) {
77-
let calced = paddingValue.split(',');
78-
let result ='';
79-
for( const c of calced) {
80-
result += (parseFloat(c)*scale*(invert?-1:1)).toString()+'px ';
81-
}
82-
return result;
60+
let calcPadding = function (paddingValue, scale = 1, invert = false) {
61+
let calced = paddingValue.split(',');
62+
let result = '';
63+
for (const c of calced) {
64+
result += (parseFloat(c) * scale * (invert ? -1 : 1)).toString() + 'px ';
65+
}
66+
return result;
8367
}
8468

8569
/**

src/assets/json/defaults/defPage.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"bgColor": "Colors.transparent",
77
"padding": "15",
88
"align": "center",
9+
"image":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==",
910
"children": {
1011
"visual": [],
1112
"nonvisual": []

src/components/elements/PageElement.vue

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<template>
33
<div id="page" :class="active?'active':''">
44
<div id="page-content">
5-
<slot></slot>
5+
<img :src="image !== undefined ? image:''" alt="no preview">
66
</div>
77
<h3 id="page-title">
88
<span :class="{main:isMain}">
@@ -18,7 +18,8 @@ export default {
1818
props: [
1919
'title',
2020
'active',
21-
'isMain'
21+
'isMain',
22+
'image'
2223
]
2324
}
2425
</script>
@@ -50,6 +51,11 @@ export default {
5051
margin: auto;
5152
margin-bottom: 5px;
5253
cursor: pointer;
54+
overflow: hidden;
55+
overflow-y: scroll;
56+
}
57+
#page-content img{
58+
max-width: 100%;
5359
}
5460

5561
#page-title {

src/components/elements/PropertyElement.vue

+20-1
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,23 @@
8787
</template>
8888

8989
<script>
90+
import {fnc} from '@/assets/js/functions';
9091
export default {
9192
name: "PropertyElement",
9293
mounted() {
93-
// var $ = window.jQuery;
94+
var $ = window.jQuery;
95+
let updatePreview=function () {
96+
setTimeout(function () {
97+
fnc.takeScreenShot("#preview",function (e) {
98+
self.page.image = e;
99+
});
100+
},300);
101+
};
102+
var self = this;
103+
$(document).on('change',"#property select",updatePreview)
104+
$(document).on('keyup',"#property input",updatePreview)
105+
$(document).on('keyup',"#property change",updatePreview)
106+
94107
},
95108
data: function () {
96109
return {
@@ -103,6 +116,12 @@ export default {
103116
return {}
104117
},
105118
type: Object
119+
},
120+
page: {
121+
default: function () {
122+
return {}
123+
},
124+
type: Object
106125
}
107126
}, methods: {
108127
nameCheck: function (e, isBlur) {

src/components/pages/MainAppPage.vue

+39-24
Original file line numberDiff line numberDiff line change
@@ -70,29 +70,30 @@
7070
<!-- inactive when has not page -->
7171
<!-- make device size and scale -->
7272
<!-- bgcolor and text color apply -->
73-
<div id="mobile" :class="(data.pages.length < 1?'inactive':'')"
74-
:style="'width:'+(display.landscape?display.height:display.width )* display.scale
75-
+'px;height:'+(display.landscape?display.width:display.height ) * display.scale+'px'+
76-
';background-color:'+(data.project.isDark?'#2e2e2e':data.project.bgColor)
73+
<div id="mobile" :style="'width:'+(display.landscape?display.height:display.width )* display.scale
74+
+'px;height:'+(display.landscape?display.width:display.height ) * display.scale+'px'" :class="(data.pages.length < 1?'inactive':'')">
75+
<div id="preview" :style="';background-color:'+(data.project.isDark?'#2e2e2e':data.project.bgColor)
7776
+';color:'+(data.project.isDark?'white':data.project.textColor)+' !important' ">
78-
<!-- direction of project and page padding -->
79-
<div id="dir"
80-
:style="'direction:'+(data.project.isRTL?'rtl':'ltr')+';padding:'+calcPadding(data.pages[currentPage].padding,this.display.scale)">
81-
<!-- visual components of page -->
82-
<div
83-
v-if="data.pages[currentPage] !== undefined && data.pages[currentPage].children.visual !== undefined">
77+
78+
<!-- direction of project and page padding -->
79+
<div id="dir"
80+
:style="'direction:'+(data.project.isRTL?'rtl':'ltr')+';padding:'+calcPadding(data.pages[currentPage].padding,this.display.scale)">
81+
<!-- visual components of page -->
82+
<div
83+
v-if="data.pages[currentPage] !== undefined && data.pages[currentPage].children.visual !== undefined">
8484
<span v-for="(comp,i) in data.pages[currentPage].children.visual"
8585
:key="i">
8686
<simulator @dblclick.native="removeVisual(i)" @click.native="currentProperties = comp;"
8787
:type="comp.type" :properties="comp" :scale="display.scale"
8888
:page="data.pages[currentPage]"></simulator>
8989
</span>
90-
</div>
90+
</div>
9191

92-
<drop class="drop visual" @drop="onVisualDrop" :accepts-data="(n) => isVisual(n)"></drop>
93-
<!-- <drop class="drop any" @drop="onAnyDrop" mode="cut">-->
94-
<!-- <span v-for="(n, index) in anyDropped" :key="index">Dropped : {{n}},&nbsp;</span>-->
95-
<!-- </drop>-->
92+
<drop class="drop visual" @drop="onVisualDrop" :accepts-data="(n) => isVisual(n)"></drop>
93+
<!-- <drop class="drop any" @drop="onAnyDrop" mode="cut">-->
94+
<!-- <span v-for="(n, index) in anyDropped" :key="index">Dropped : {{n}},&nbsp;</span>-->
95+
<!-- </drop>-->
96+
</div>
9697
</div>
9798
</div>
9899
</div>
@@ -125,7 +126,7 @@
125126
</h2>
126127
<!-- if project init sho properties-->
127128
<div v-if="isInitProject">
128-
<property :properties="currentProperties"></property>
129+
<property :properties="currentProperties" :page="data.pages[currentPage]"></property>
129130
</div>
130131
<div v-else class="text-center">
131132
<img src="../../assets/img/logo.svg" class="logo-sm" alt="">
@@ -137,12 +138,10 @@
137138
<!-- if project init can pages -->
138139
<div v-if="isInitProject">
139140
<!-- list of pages -->
140-
<page v-for="(page,i) in data.pages" :isMain="data.project.mainPage === i" @click.native="changePage(i)" :key="i" :title="page.name"
141+
<page v-for="(page,i) in data.pages" :image="page.image!= undefined? page.image: null"
142+
:isMain="data.project.mainPage === i" @click.native="changePage(i)" :key="i" :title="page.name"
141143
:active="currentPage === i">
142144
<i class="fa fa-times" @click="removePage(i)"></i>
143-
hello {{ i }}
144-
{{ page.name }}
145-
<!-- ***!*** need screenshot-->
146145
</page>
147146
<i class="fa fa-plus-circle" id="page-add" @click="newPage"></i>
148147
</div>
@@ -254,16 +253,23 @@ export default {
254253
removePage: function (i) { // remove page form project
255254
var self = this;
256255
// confirm before remove
257-
window.alertify.confirm('Are you sure to remove page?', 'Remove confirm', function () {
256+
window.alertify.confirm('Are you sure to element page?', 'Remove confirm', function () {
258257
self.data.pages.splice(i, 1);
259258
self.changePage(0);
260-
window.alertify.success('Page removed');
259+
window.alertify.success('element removed');
260+
setTimeout(function () {
261+
fnc.takeScreenShot("#preview", function (e) {
262+
self.data.pages[self.currentPage].image = e;
263+
self.$forceUpdate();
264+
});
265+
}, 300);
261266
}
262267
, function () {
263268
window.alertify.error('Cancel')
264269
});
265270
},
266271
visualValidator: function (component, visuals) {
272+
var self = this;
267273
if (component.type === 'appbar') {
268274
// check non duplicate app bar
269275
for (const comp of visuals) {
@@ -289,11 +295,17 @@ export default {
289295
do {
290296
nextName = false;
291297
i++;
292-
if (names.indexOf(component.type +i.toString()) > -1) {
298+
if (names.indexOf(component.type + i.toString()) > -1) {
293299
nextName = true;
294300
}
295301
} while (nextName);
296-
visuals[visuals.length -1 ].name = component.type +i.toString();
302+
visuals[visuals.length - 1].name = component.type + i.toString();
303+
304+
setTimeout(function () {
305+
fnc.takeScreenShot("#preview", function (e) {
306+
self.data.pages[self.currentPage].image = e;
307+
});
308+
}, 1000);
297309
return true;
298310
},
299311
onVisualDrop(event) { // on add a viusal component to page
@@ -415,6 +427,9 @@ export default {
415427
height: 20vh;
416428
border: 1px solid rgba(0, 0, 0, .1);
417429
border-right: 0;
430+
overflow-y: scroll;
431+
overflow-x: hidden;
432+
418433
}
419434
420435
#pages .container {

0 commit comments

Comments
 (0)