Commit 0393dd69 authored by fanxuehui's avatar fanxuehui

feat: carding module

parent 7377058c
const { distPath, theme } = require('./config'); const { distPath, theme } = require('./config');
const { CleanWebpackPlugin } = require('clean-webpack-plugin'); const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path'); const path = require('path');
module.exports = { module.exports = {
output: { output: {
path: distPath, path: distPath,
...@@ -56,12 +56,5 @@ module.exports = { ...@@ -56,12 +56,5 @@ module.exports = {
externals: { externals: {
swiper: 'Swiper', swiper: 'Swiper',
}, },
plugins: [ plugins: [new CleanWebpackPlugin()],
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
hash: false,
template: path.join(__dirname, '../src/index.html'),
filename: 'index.html',
}),
],
}; };
...@@ -2,18 +2,19 @@ const webpack = require('webpack'); ...@@ -2,18 +2,19 @@ const webpack = require('webpack');
const merge = require('webpack-merge'); const merge = require('webpack-merge');
const { host, port } = require('./config'); const { host, port } = require('./config');
const webpackBaseConfig = require('./webpack.base.js'); const webpackBaseConfig = require('./webpack.base.js');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const { distPath } = require('./config');
module.exports = merge(webpackBaseConfig, { module.exports = merge(webpackBaseConfig, {
mode: 'development', mode: 'development',
entry: [ entry: [
`webpack-dev-server/client?http://${host}:${port}`, `webpack-dev-server/client?http://${host}:${port}`,
'webpack/hot/only-dev-server', 'webpack/hot/only-dev-server',
`../src/index.ts`, path.join(__dirname, `../fixtures/index.tsx`),
], ],
devtool: 'inline-source-map', devtool: 'inline-source-map',
module: { module: {},
rules: [].concat(getStyle(true)),
},
output: { output: {
publicPath: '/', publicPath: '/',
filename: 'assets/[hash:8].[name].js', filename: 'assets/[hash:8].[name].js',
...@@ -22,6 +23,11 @@ module.exports = merge(webpackBaseConfig, { ...@@ -22,6 +23,11 @@ module.exports = merge(webpackBaseConfig, {
plugins: [ plugins: [
new webpack.HotModuleReplacementPlugin(), new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({}), new webpack.DefinePlugin({}),
new HtmlWebpackPlugin({
hash: false,
template: path.join(__dirname, '../fixtures/index.html'),
filename: 'index.html',
}),
], ],
devServer: { devServer: {
host, host,
......
...@@ -5,5 +5,7 @@ ...@@ -5,5 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title> <title>Document</title>
</head> </head>
<body></body> <body>
<div id="app"></div>
</body>
</html> </html>
import React from 'react';
import { render } from 'react-dom';
import JimuEditor from '../src/jimu-editor/index';
function Canvas() {
return <div>extended Canvas</div>;
}
render(
<JimuEditor controls={[]} canvas={Canvas}></JimuEditor>,
document.getElementById('app')
);
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
"main": "./lib/index.js", "main": "./lib/index.js",
"bin": {}, "bin": {},
"scripts": { "scripts": {
"start": "tsc -w -p .", "start": "npm run dev",
"dev": "webpack-dev-server --config build/webpack.base.js --open", "dev": "webpack-dev-server --config build/webpack.dev.js --open",
"clean": "rimraf lib", "clean": "rimraf lib",
"test": "npm run lint", "test": "npm run lint",
"lint": "eslint src test", "lint": "eslint src test",
......
function foo(bar: string): void {
console.log(bar);
}
foo('');
export default foo;
import React from 'react';
function JimuEditor(props: { a: string }) {
console.log(props);
}
import React, { FC } from 'react';
import { JimuEditorProps } from './shared/interfaces';
import Stage from './components/stage';
import Header from './components/header';
import { StoreProvider } from './store';
function JimuEditor({ canvas, controls }: JimuEditorProps) {
return (
<StoreProvider>
<Header></Header>
<Stage></Stage>
</StoreProvider>
);
}
export default JimuEditor;
import React from 'react';
function Canvas() {
return <div>canvas</div>;
}
export default Canvas;
import React from 'react';
import { useStores } from '../hooks/use-store';
import { observer } from 'mobx-react';
function Header() {
const { scopeStore } = useStores();
return <div>Header</div>;
}
export default observer(Header);
// 物料图标注入点
// 注入点容器可替换
import React from 'react';
import { observer } from 'mobx-react';
import { useStores } from '../../hooks/use-store';
import Canvas from '../canvas';
function Stage() {
const { scopeStore } = useStores();
const handleClick = () => {};
return (
<div onClick={handleClick}>
stage
<Canvas></Canvas>
</div>
);
}
export default observer(Stage);
import React from 'react';
import { storesContext } from '../../store';
export const useStores = () => React.useContext(storesContext);
import React from 'react'; import JimuEditor from './app';
export default JimuEditor;
import { ReactElement } from 'react'; import {
ReactElement,
Component,
FunctionComponent,
CSSProperties,
} from 'react';
// 积木编辑器props // 积木编辑器props
export interface JimuEditorProps { export interface JimuEditorProps {
Stage: ReactElement; canvas?: Component | FunctionComponent;
controls: IControls[]; controls?: IControls[];
} }
// 控件类型 // 控件类型
export interface IControls { export interface IControls {
Entity?: ReactElement; Entity?: Component | FunctionComponent;
options: IControlsOptions; options: IControlsOptions;
} }
export interface IControlsOptions { export interface IControlsOptions {
...@@ -37,11 +42,17 @@ export interface IWrappedWidget { ...@@ -37,11 +42,17 @@ export interface IWrappedWidget {
events: IEvent[]; events: IEvent[];
} }
export interface IWidget { export interface IWidget {
Editor: ReactElement; Editor: Component | FunctionComponent;
Layer: ReactElement; Layer: Component | FunctionComponent;
Stele: ReactElement; Stele: Component | FunctionComponent;
meta: IMeta; meta: IMeta;
} }
export interface WrappedWidget {
type: string;
style: CSSStyleRule;
id: string;
widget: IWidget;
}
export interface IMeta { export interface IMeta {
script: string; script: string;
deps: string[]; deps: string[];
...@@ -69,3 +80,14 @@ export interface IEvent { ...@@ -69,3 +80,14 @@ export interface IEvent {
des: string; des: string;
pub?: string; pub?: string;
} }
// 产出JSON格式
export interface IPage {
attr: IPageAttr;
widgetList: IWidget[];
}
export interface IPageAttr {
style: CSSProperties;
name: string;
id: string;
}
import React, { createContext } from 'react';
import { ScopeStore } from './scope';
import { StageStore } from './stage';
const stores = {
stageStore: new StageStore(),
scopeStore: new ScopeStore(),
};
export const storesContext = createContext(stores);
export const StoreProvider = ({ children }) => {
return (
<storesContext.Provider value={stores}>{children}</storesContext.Provider>
);
};
// 编辑器扩展和外部参数管理
import { observable, action, computed } from 'mobx';
export class ScopeStore {
@observable
controls = [];
@observable
props = { test: 2 };
@action
changeProps(props) {
console.log(props, this.props);
this.props = props;
}
}
// 舞台数据
import { observable, action, computed } from 'mobx';
import { IPage } from '../shared/interfaces';
export class StageStore {
@observable
data: IPage = {
attr: {
style: { width: 100 },
id: '',
name: '',
},
widgetList: [],
};
@observable
targetWidgetId: string = '';
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment