Skip to content

Commit

Permalink
Updated Stage
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaesc committed Nov 9, 2017
1 parent 766c544 commit 0c22732
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 39 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Expand Up @@ -29,16 +29,20 @@ module.exports = {
'js': 'never',
'vue': 'never'
}],
'quotes': 'off',
'semi': 'off',
// allow optionalDependencies
'import/no-extraneous-dependencies': ['error', {
'optionalDependencies': ['test/unit/index.js']
}],
'space-before-function-paren': 'off',
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
'no-param-reassign': 'off',
'no-underscore-dangle': 'off',
'max-len': 'off',
'no-plusplus': 'off',
'no-unused-vars': 'off',
'linebreak-style': 'off',
'import/no-duplicates': 'off',
'import/no-webpack-loader-syntax': 'off',
Expand Down
2 changes: 1 addition & 1 deletion build/webpack.base.conf.js
Expand Up @@ -11,7 +11,7 @@ function resolve (dir) {
module.exports = {
entry: {
docs: './docs/docs.js',
['vue-konva']: './src/lib.js'
['vue-konva']: './src/lib.js',
},
output: {
path: config.build.assetsRoot,
Expand Down
3 changes: 3 additions & 0 deletions build/webpack.lib.conf.js
Expand Up @@ -32,6 +32,9 @@ const webpackConfig = merge(baseWebpackConfig, {
library: '[name]',
libraryTarget: 'umd'
},
externals: {
"konva": "konva"
},
plugins: [
// http://vuejs.github.io/vue-loader/en/workflow/production.html
new webpack.DefinePlugin({
Expand Down
23 changes: 16 additions & 7 deletions docs/App.vue
@@ -1,25 +1,34 @@
<template>
<div id="app">
<img src="./assets/logo.png">
<HelloWorld/>
<v-rect></v-rect>
<v-stage :config="configKonva"></v-stage>
</div>
</template>

<script>
import HelloWorld from './components/HelloWorld'
import HelloWorld from "./components/HelloWorld";
export default {
name: 'app',
name: "app",
components: {
HelloWorld
},
data() {
return {
configKonva: {
width: "200",
height: "200",
id: "ff"
}
};
},
mounted() {
}
}
};
</script>

<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
font-family: "Avenir", Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
Expand Down
2 changes: 1 addition & 1 deletion lib/vue-konva.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/vue-konva.min.js.map

Large diffs are not rendered by default.

35 changes: 20 additions & 15 deletions package.json
Expand Up @@ -2,7 +2,11 @@
"name": "vue-konva",
"version": "0.0.0",
"description": "Vue binding to canvas element via Konva framework",
"keywords": ["vue", "konva", "canvas"],
"keywords": [
"vue",
"konva",
"canvas"
],
"homepage": "https://github.com/rafaesc/vue-konva#readme",
"author": "Rafael Escala <rafaesc92@gmail.com>",
"main": "lib/vue-konva.min.js",
Expand Down Expand Up @@ -38,34 +42,36 @@
"babel-core": "^6.22.1",
"babel-eslint": "^7.1.1",
"babel-loader": "^7.1.1",
"babel-plugin-istanbul": "^4.1.1",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-preset-env": "^1.3.2",
"babel-preset-stage-2": "^6.22.0",
"babel-register": "^6.22.0",
"chai": "^4.1.2",
"chalk": "^2.0.1",
"connect-history-api-fallback": "^1.3.0",
"copy-webpack-plugin": "^4.0.1",
"cross-env": "^5.0.1",
"css-loader": "^0.28.0",
"eslint": "^3.19.0",
"eslint-config-airbnb-base": "^11.1.3",
"eslint-config-standard": "^10.2.1",
"eslint-friendly-formatter": "^3.0.0",
"eslint-import-resolver-webpack": "^0.8.1",
"eslint-loader": "^1.7.1",
"eslint-plugin-html": "^3.0.0",
"eslint-config-standard": "^10.2.1",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^3.0.1",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-node": "^5.2.0",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^3.0.1",
"eventsource-polyfill": "^0.9.6",
"express": "^4.14.1",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^1.1.4",
"friendly-errors-webpack-plugin": "^1.6.1",
"html-webpack-plugin": "^2.30.1",
"http-proxy-middleware": "^0.17.3",
"webpack-bundle-analyzer": "^2.9.0",
"cross-env": "^5.0.1",
"inject-loader": "^3.0.0",
"karma": "^1.4.1",
"karma-coverage": "^1.1.1",
"karma-mocha": "^1.3.0",
Expand All @@ -75,26 +81,25 @@
"karma-sourcemap-loader": "^0.3.7",
"karma-spec-reporter": "0.0.31",
"karma-webpack": "^2.0.2",
"konva": "^1.7.6",
"mocha": "^3.2.0",
"npm-run-all": "^4.0.2",
"chai": "^4.1.2",
"sinon": "^4.0.0",
"sinon-chai": "^2.8.0",
"inject-loader": "^3.0.0",
"babel-plugin-istanbul": "^4.1.1",
"phantomjs-prebuilt": "^2.1.14",
"semver": "^5.3.0",
"shelljs": "^0.7.6",
"opn": "^5.1.0",
"optimize-css-assets-webpack-plugin": "^3.2.0",
"ora": "^1.2.0",
"phantomjs-prebuilt": "^2.1.14",
"portfinder": "^1.0.13",
"rimraf": "^2.6.0",
"semver": "^5.3.0",
"shelljs": "^0.7.6",
"sinon": "^4.0.0",
"sinon-chai": "^2.8.0",
"url-loader": "^0.5.8",
"vue-loader": "^13.3.0",
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.5.2",
"portfinder": "^1.0.13",
"webpack": "^3.6.0",
"webpack-bundle-analyzer": "^2.9.0",
"webpack-dev-middleware": "^1.12.0",
"webpack-hot-middleware": "^2.18.2",
"webpack-merge": "^4.1.0"
Expand Down
7 changes: 0 additions & 7 deletions src/components/Rect.vue

This file was deleted.

100 changes: 100 additions & 0 deletions src/components/Stage.vue
@@ -0,0 +1,100 @@
<template>
<div>{{this.config}}</div>
</template>

<script>
let cacheConfig = {};
export default {
props: ["config"],
mounted() {
this._stage = new window.Konva.Stage({
width: this.config.width,
height: this.config.height,
container: this.$el
});
console.clear();
cacheConfig = this.config;
applyNodeProps(this._stage, this.config);
},
updated() {
applyNodeProps(this._stage, this.config, cacheConfig);
cacheConfig = this.config;
},
beforeDestroy() {
this._stage.destroy();
}
};
function updatePicture(node) {
var drawingNode = node.getLayer() || node.getStage();
drawingNode && drawingNode.batchDraw();
}
function applyNodeProps(instance, props, oldProps = {}) {
if ("id" in props) {
const message = `VueKonva: You are using "id" attribute for Konva node. In some very rare cases it may produce bugs. Currently we recommend not to use it and use "name" attribute instead.`;
console.warn(message);
}
var updatedProps = {};
var hasUpdates = false;
for (let key in oldProps) {
var isEvent = key.slice(0, 2) === "on";
var propChanged = oldProps[key] !== props[key];
if (isEvent && propChanged) {
var eventName = key.substr(2).toLowerCase();
if (eventName.substr(0, 7) === "content") {
eventName =
"content" +
eventName.substr(7, 1).toUpperCase() +
eventName.substr(8);
}
instance.off(eventName, oldProps[key]);
}
var toRemove = !props.hasOwnProperty(key);
if (toRemove) {
instance.setAttr(key, undefined);
}
}
for (let key in props) {
let isEvent = key.slice(0, 2) === "on";
var toAdd = oldProps[key] !== props[key];
if (isEvent && toAdd) {
let eventName = key.substr(2).toLowerCase();
if (eventName.substr(0, 7) === "content") {
eventName =
"content" +
eventName.substr(7, 1).toUpperCase() +
eventName.substr(8);
}
if (props[key]) {
instance.on(eventName, props[key]);
}
}
if (
!isEvent &&
(props[key] !== oldProps[key] || props[key] !== instance.getAttr(key))
) {
hasUpdates = true;
updatedProps[key] = props[key];
}
}
if (hasUpdates) {
instance.setAttrs(updatedProps);
updatePicture(instance);
var val, prop;
for (prop in updatedProps) {
val = updatedProps[prop];
if (val instanceof window.Image && !val.complete) {
var node = instance;
val.addEventListener("load", function() {
var layer = node.getLayer();
layer && layer.batchDraw();
});
}
}
}
}
</script>
9 changes: 6 additions & 3 deletions src/lib.js
@@ -1,9 +1,12 @@
import Rect from './components/Rect'
import Stage from './components/Stage'

const componentPrefix = 'v'
if (typeof window !== 'undefined' && !window.Konva) {
require('konva');
}

const componentPrefix = 'v'
const components = {
Rect
Stage
}

const VueKonva = {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -3611,6 +3611,10 @@ klaw@^1.0.0:
optionalDependencies:
graceful-fs "^4.1.9"

konva@^1.7.6:
version "1.7.6"
resolved "https://registry.yarnpkg.com/konva/-/konva-1.7.6.tgz#7aceef1058b04127077c8f44653556b35b1133e6"

last-call-webpack-plugin@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/last-call-webpack-plugin/-/last-call-webpack-plugin-2.1.2.tgz#ad80c6e310998294d2ed2180a68e9589e4768c44"
Expand Down Expand Up @@ -6107,10 +6111,6 @@ vue-loader@^13.3.0:
vue-style-loader "^3.0.0"
vue-template-es2015-compiler "^1.6.0"

vue-router@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-3.0.1.tgz#d9b05ad9c7420ba0f626d6500d693e60092cc1e9"

vue-style-loader@^3.0.0, vue-style-loader@^3.0.1:
version "3.0.3"
resolved "https://registry.yarnpkg.com/vue-style-loader/-/vue-style-loader-3.0.3.tgz#623658f81506aef9d121cdc113a4f5c9cac32df7"
Expand Down

0 comments on commit 0c22732

Please sign in to comment.