Skip to content

Commit

Permalink
feature: 新增插件能力
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrow-js committed Oct 22, 2020
1 parent 310f2cf commit c34c2ca
Show file tree
Hide file tree
Showing 66 changed files with 1,622 additions and 343 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions packages/plugin-demo/sparrow-test-box/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "sparrow-test-box",
"version": "0.1.0",
"license": "MIT",
"description": "",
"dependencies": {
"@lukeed/uuid": "^1.0.1",
"@sparrow-vue/sparrow-utils": "^1.0.6",
"cheerio": "^1.0.0-rc.3"
},
"main": "./dist/index.js",
"scripts": {
"build-ts": "tsc",
"watch-ts": "tsc -w"
},
"devDependencies": {
"@babel/template": "^7.8.3",
"@types/cheerio": "^0.22.15",
"@types/execa": "^2.0.0",
"@types/mocha": "^5.2.5",
"@types/node": "^10.5.5",
"@types/prettier": "^1.19.0",
"@vue/cli-plugin-babel": "^4.1.1",
"@vue/cli-plugin-eslint": "^4.1.1",
"@vue/cli-service": "^4.1.1",
"@vue/eslint-config-standard": "^5.0.1",
"cross-env": "^5.2.0",
"midway-bin": "1",
"midway-mock": "1",
"npm-run-all": "^4.1.5",
"ts-node": "^8.0.2",
"tslib": "^1.8.1",
"typescript": "^3.2.0",
"vue-template-compiler": "^2.6.11"
},
"sparrow": {
"name": "sparrow-test-component",
"description": "Test sparrow"
}
}
5 changes: 5 additions & 0 deletions packages/plugin-demo/sparrow-test-box/sparrow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "sparrow-test-box",
"description": "Test sparrow box",
"thumb": "https://unpkg.com/@sparrow-vue/[email protected]/assets/box.png"
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

import Component from './Component';
import {Box} from '@sparrow-vue/sparrow-utils';
import * as _ from 'lodash';

export default class Divider extends Component{
export default class Divider extends Box{
name: string = 'Divider';
config: any = {};
$fragment: any;
Expand All @@ -28,11 +28,10 @@ export default class Divider extends Component{
const type = this.storage.get('preview_view_status') || 0;
let divider = '';
if (type === 0) {
divider = `<el-divider ${this._attrStr}></el-divider> <div>asdasd</div>`
divider = `<div class="drag-box clearfix" ${this._attrStr}></div>`
} else {
divider = `
<el-divider ${this._attrStr}></el-divider>
<div>asdasd</div>
<div class="drag-box clearfix" ${this._attrStr}></div>
`;
}
return divider;
Expand Down
56 changes: 56 additions & 0 deletions packages/plugin-demo/sparrow-test-component/dist/config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions packages/plugin-demo/sparrow-test-component/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "sparrow-test-component",
"version": "0.1.2",
"version": "0.1.6",
"license": "MIT",
"description": "",
"dependencies": {
"@lukeed/uuid": "^1.0.1",
"@sparrow-vue/sparrow-utils": "^1.0.10",
"cheerio": "^1.0.0-rc.3"
},
"main": "./dist/index.js",
Expand Down
53 changes: 53 additions & 0 deletions packages/plugin-demo/sparrow-test-component/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
export default {
model: {
attr: {
direction: "",
'content-position': '',
},
custom: {
label: '输入文本',
},
},
schema: {
fields: [
{
type: 'object',
label: '',
model: 'attr',
schema: {
fields: [
{
type: "select",
label: "direction",
model: "direction",
multi: true,
values: ["horizontal", "vertical", ""]
},
{
type: "select",
label: "content-position",
model: "content-position",
multi: true,
values: ["left", "right", "center", ""]
},
]
}
},
{
type: 'object',
label: '',
model: 'custom',
schema: {
fields: [
{
type: "input",
inputType: "text",
label: "label",
model: "label"
}
]
}
}
]
},
}
55 changes: 55 additions & 0 deletions packages/plugin-demo/sparrow-test-component/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

import {Component, VueParse} from '@sparrow-vue/sparrow-utils';
import * as _ from 'lodash';
import * as fsExtra from 'fs-extra';
import * as path from 'path';
const cwd = process.cwd();
export default class TestComponent extends Component{
name: string = 'TestComponent';
config: any = {};
$fragment: any;
vueParse: any;

constructor (params: any, storge: any) {
super(storge);
this.initVueParse();
const {initType} = params;
if (initType === 'auto' ) {
this.config = params;
} else {
this.config = _.cloneDeep(require('./config').default);
}
this.setAttrsToStr();
}

private initVueParse () {
const fileStr:string = fsExtra.readFileSync(path.join(__dirname, '..', 'src/index.vue'), 'utf8');
this.vueParse = new VueParse(this.uuid, fileStr);
}

public insertEditText (params) {
this.config.model.custom.label = params.value;
}


public fragment () {

const type = this.storage.get('preview_view_status') || 0;
let divider = '';
if (type === 0) {
divider = `
<div>
<el-button :plain="true" @click="open">打开消息提示</el-button>
<el-button :plain="true" @click="openVn">VNode</el-button>
<div>`
} else {
divider = `
<div>
<el-button :plain="true" @click="open">打开消息提示</el-button>
<el-button :plain="true" @click="openVn">VNode</el-button>
<div>
`;
}
return divider;
}
}
29 changes: 29 additions & 0 deletions packages/plugin-demo/sparrow-test-component/src/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<template>
<div>
<el-button :plain="true" @click="open">打开消息提示</el-button>
<el-button :plain="true" @click="openVn">VNode</el-button>
<div>
</template>

<script>
export default {
methods: {
open() {
this.$message('这是一条消息提示');
},
openVn() {
const h = this.$createElement;
this.$message({
message: h('p', null, [
h('span', null, '内容可以是 '),
h('i', { style: 'color: teal' }, 'VNode')
])
});
}
}
}
</script>
<style lang="scss" scoped>
</style>
20 changes: 20 additions & 0 deletions packages/plugin-demo/sparrow-test-component/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compileOnSave": true,
"compilerOptions": {
"target": "ES2017",
"module": "commonjs",
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"resolveJsonModule": true,
"inlineSourceMap":true,
"noImplicitThis": true,
"stripInternal": true,
"pretty": true,
"outDir": "dist",
"lib": ["es2017", "dom"]
},
"include": [
"src"
]
}
Loading

0 comments on commit c34c2ca

Please sign in to comment.