Skip to content

Commit

Permalink
feat: 主题编辑器渲染器开源
Browse files Browse the repository at this point in the history
  • Loading branch information
qkiroc committed Nov 20, 2023
1 parent 71c7b72 commit c0fbe81
Show file tree
Hide file tree
Showing 73 changed files with 18,062 additions and 36 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ _site
node_modules
/dist
/lib
**/esm
**/lib
/sdk
/public
/gh-pages
Expand All @@ -26,6 +28,7 @@ node_modules
/npm
/mock/cfc/cfc.zip
.rollup.cache
/theme-npm

dist
tsconfig.tsbuildinfo
Expand Down
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"typescript.tsdk": "node_modules/typescript/lib",
"gitHistory.showEditorTitleMenuBarIcons": false,
"files.exclude": {
"**/lib": true,
"**/esm": true,
// "**/lib": true,
// "**/esm": true,
"**/sdk": true,
"**/tsconfig.tsbuildinfo": true,
"**/schema.json": true,
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"packages/amis-ui",
"packages/amis",
"packages/amis-editor-core",
"packages/amis-editor"
"packages/amis-editor",
"packages/amis-theme-editor-helper"
],
"scripts": {
"fis3-serve": "fis3 server start --www ./public --port 8888 --no-daemon --no-browse",
Expand Down Expand Up @@ -85,7 +86,7 @@
"magic-string": "^0.26.7",
"marked": "^4.2.1",
"monaco-editor": "0.30.1",
"plugin-react-i18n": "1.0.1",
"plugin-react-i18n": "1.0.4",
"postcss-scss": "^4.0.6",
"prismjs": "^1.29.0",
"react": "^18.2.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/amis-editor/examples/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import {currentLocale} from 'i18n-runtime';
import {Portal} from 'react-overlays';
import {Icon} from './icons/index';
import LayoutList from './layout/index';
import themeConfig from 'amis-theme-editor-helper/lib/systemTheme/cxd';
import {cxdData} from 'amis-theme-editor-helper';

// 测试组织属性配置面板的国际化,可以放开如下注释
// import './renderer/InputTextI18n';
// import './renderer/TextareaI18n';
// import './utils/overwriteSchemaTpl';
// const i18nEnabled = true;
const i18nEnabled = false;
setThemeConfig(themeConfig);
setThemeConfig(cxdData);

const schema = {
type: 'page',
Expand Down
11 changes: 1 addition & 10 deletions packages/amis-editor/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,7 @@ import './renderer/InputRangeValueControl';
import './renderer/FunctionEditorControl';
import './renderer/ListItemControl';

import 'amis-theme-editor/lib/locale/zh-CN';
import 'amis-theme-editor/lib/locale/en-US';
import 'amis-theme-editor/lib/renderers/Border';
import 'amis-theme-editor/lib/renderers/ColorPicker';
import 'amis-theme-editor/lib/renderers/Font';
import 'amis-theme-editor/lib/renderers/PaddingAndMargin';
import 'amis-theme-editor/lib/renderers/Radius';
import 'amis-theme-editor/lib/renderers/Shadow';
import 'amis-theme-editor/lib/renderers/Size';
import 'amis-theme-editor/lib/renderers.css';
import 'amis-theme-editor-helper';

export * from './component/BaseControl';
export * from './icons/index';
35 changes: 35 additions & 0 deletions packages/amis-theme-editor-helper/i18nConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module.exports = {
entry: {
dir: './src'
},
file: {
test: /.*(ts|tsx|js|jsx)$/
},
includes: ['src/renderers'],
importInfo: {
source: 'i18n-runtime',
imported: 'i18n',
local: '_i18n'
},
i18nModule: 'i18n-runtime',
languages: [
{
name: 'en-US',
path: './src/locale'
},
{
name: 'zh-CN',
path: './src/locale'
}
],
output: {
fileName: 'theme-editor-i18n',
fileExtension: 'xlsx',
path: './'
},
translate: {
appId: '',
key: '',
host: 'http://api.fanyi.baidu.com'
}
};
69 changes: 69 additions & 0 deletions packages/amis-theme-editor-helper/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"name": "amis-theme-editor-helper",
"version": "2.0.22-beta.9",
"description": "amis主题编辑器通用方法",
"main": "lib/index.js",
"module": "esm/index.js",
"types": "lib/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "npm run clean-dist && NODE_ENV=production rollup -c ",
"clean-dist": "rimraf lib/** esm/**",
"i18n:update": "npx i18n update --config=./i18nConfig.js",
"i18n:translate": "npx i18n translate --config=./i18nConfig.js --l=en-US",
"i18n:merge": "npx i18n merge --config=./i18nConfig.js --l=en-US"
},
"keywords": [
"amis",
"theme-editor-helper"
],
"author": "@fex",
"license": "ISC",
"files": [
"lib",
"esm"
],
"lint-staged": {
"{src,scss,examples}/**/**/*.{js,jsx,ts,tsx,scss,json}": [
"prettier --write"
]
},
"dependencies": {
"react": "^18.2.0",
"react-color": "^2.19.3",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@rollup/plugin-url": "^7.0.0",
"@svgr/rollup": "^6.4.0",
"@types/async": "^2.0.45",
"@types/classnames": "^2.2.3",
"@types/codemirror": "^5.60.5",
"@types/deep-diff": "^1.0.0",
"@types/history": "^4.6.0",
"@types/hoist-non-react-statics": "^3.0.1",
"@types/lodash": "^4.14.76",
"@types/node": "^14.0.24",
"@types/react": "^18.0.24",
"@types/react-dom": "^18.0.8",
"@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.3.0",
"@rollup/plugin-typescript": "^8.3.2",
"rollup": "^2.73.0",
"rollup-plugin-auto-external": "^2.0.0",
"rollup-plugin-license": "^2.7.0",
"@types/react-color": "^3.0.6",
"tslib": "^2.3.1",
"typescript": "^4.6.4",
"sass": "^1.49.7",
"sass-loader": "^12.5.0",
"style-loader": "^3.2.1"
},
"peerDependencies": {
"amis": "*",
"amis-core": "*",
"amis-ui": "*",
"i18n-runtime": "*"
}
}
149 changes: 149 additions & 0 deletions packages/amis-theme-editor-helper/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
// rollup.config.js
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import resolve from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import license from 'rollup-plugin-license';
import autoExternal from 'rollup-plugin-auto-external';
import postcss from 'rollup-plugin-postcss';
import {
name,
version,
author,
main,
module,
dependencies
} from './package.json';
import path from 'path';
import svgr from '@svgr/rollup';
import fs from 'fs';
import i18nPlugin from 'plugin-react-i18n';

const i18nConfig = require('./i18nConfig');

const settings = {
globals: {}
};

const external = id =>
new RegExp(
`^(?:${Object.keys(dependencies ?? {})
.concat(fs.readdirSync(path.join(__dirname, '../../node_modules')))
.map(value =>
value.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d')
)
.join('|')})`
).test(id);
const input = ['./src/index.ts'];

export default [
{
input,

output: [
{
...settings,
dir: path.dirname(main),
format: 'cjs',
exports: 'named',
preserveModulesRoot: './src',
preserveModules: true // Keep directory structure and files
}
],
external,
plugins: getPlugins('cjs')
},
{
input,

output: [
{
...settings,
dir: path.dirname(module),
format: 'esm',
exports: 'named',
preserveModulesRoot: './src',
preserveModules: true // Keep directory structure and files
}
],
external,
plugins: getPlugins('esm')
}
];

function transpileDynamicImportForCJS(options) {
return {
name: 'transpile-dynamic-import-for-cjs',
renderDynamicImport({format, targetModuleId}) {
if (format !== 'cjs') {
return null;
}

return {
left: 'Promise.resolve().then(function() {return new Promise(function(fullfill) {require([',
right:
'], function(mod) {fullfill(require("tslib").__importStar(mod))})})})'
};

// return {
// left: 'Promise.resolve().then(function() {return new Promise(function(fullfill) {require.ensure([',
// right:
// '], function(r) {fullfill(_interopDefaultLegacy(r("' +
// targetModuleId +
// '")))})})})'
// };
}
};
}

function getPlugins(format = 'esm') {
const typeScriptOptions = {
typescript: require('typescript'),
sourceMap: false,
outputToFilesystem: true,
...(format === 'esm'
? {
compilerOptions: {
rootDir: './src',
outDir: path.dirname(module)
}
}
: {
compilerOptions: {
rootDir: './src',
outDir: path.dirname(main)
}
})
};

return [
i18nPlugin(i18nConfig),
typescript(typeScriptOptions),
svgr({
svgProps: {
className: 'icon'
},
prettier: false,
dimensions: false
}),
transpileDynamicImportForCJS(),
autoExternal(),
json(),
postcss({
minimize: true
}),
resolve({
jsnext: true,
main: true
}),
commonjs({
sourceMap: false
}),
license({
banner: `
${name} v${version}
Copyright 2018<%= moment().format('YYYY') > 2018 ? '-' + moment().format('YYYY') : null %> ${author}
`
})
];
}
Loading

0 comments on commit c0fbe81

Please sign in to comment.