Commit 0393dd69 authored by fanxuehui's avatar fanxuehui

feat: carding module

parent 7377058c
const { distPath, theme } = require('./config');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
module.exports = {
output: {
path: distPath,
......@@ -56,12 +56,5 @@ module.exports = {
externals: {
swiper: 'Swiper',
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
hash: false,
template: path.join(__dirname, '../src/index.html'),
filename: 'index.html',
}),
],
plugins: [new CleanWebpackPlugin()],
};
......@@ -2,18 +2,19 @@ const webpack = require('webpack');
const merge = require('webpack-merge');
const { host, port } = require('./config');
const webpackBaseConfig = require('./webpack.base.js');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const { distPath } = require('./config');
module.exports = merge(webpackBaseConfig, {
mode: 'development',
entry: [
`webpack-dev-server/client?http://${host}:${port}`,
'webpack/hot/only-dev-server',
`../src/index.ts`,
path.join(__dirname, `../fixtures/index.tsx`),
],
devtool: 'inline-source-map',
module: {
rules: [].concat(getStyle(true)),
},
module: {},
output: {
publicPath: '/',
filename: 'assets/[hash:8].[name].js',
......@@ -22,6 +23,11 @@ module.exports = merge(webpackBaseConfig, {
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({}),
new HtmlWebpackPlugin({
hash: false,
template: path.join(__dirname, '../fixtures/index.html'),
filename: 'index.html',
}),
],
devServer: {
host,
......
......@@ -5,5 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body></body>
<body>
<div id="app"></div>
</body>
</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 @@
"main": "./lib/index.js",
"bin": {},
"scripts": {
"start": "tsc -w -p .",
"dev": "webpack-dev-server --config build/webpack.base.js --open",
"start": "npm run dev",
"dev": "webpack-dev-server --config build/webpack.dev.js --open",
"clean": "rimraf lib",
"test": "npm run lint",
"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
export interface JimuEditorProps {
Stage: ReactElement;
controls: IControls[];
canvas?: Component | FunctionComponent;
controls?: IControls[];
}
// 控件类型
export interface IControls {
Entity?: ReactElement;
Entity?: Component | FunctionComponent;
options: IControlsOptions;
}
export interface IControlsOptions {
......@@ -37,11 +42,17 @@ export interface IWrappedWidget {
events: IEvent[];
}
export interface IWidget {
Editor: ReactElement;
Layer: ReactElement;
Stele: ReactElement;
Editor: Component | FunctionComponent;
Layer: Component | FunctionComponent;
Stele: Component | FunctionComponent;
meta: IMeta;
}
export interface WrappedWidget {
type: string;
style: CSSStyleRule;
id: string;
widget: IWidget;
}
export interface IMeta {
script: string;
deps: string[];
......@@ -69,3 +80,14 @@ export interface IEvent {
des: 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