vendor: amis 6.13.0 base (fork root)

This commit is contained in:
2026-06-16 22:14:57 +08:00
commit 8c8e4247a9
3840 changed files with 2467374 additions and 0 deletions

3
packages/amis-editor-core/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
/coverage
/lib
/esm

View File

@@ -0,0 +1,37 @@
module.exports = {
entry: {
dir: './src'
},
file: {
test: /.*(ts|tsx|js|jsx)$/
},
ignore: {
list: ['src/locale']
},
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: 'eidtor-core-i18n',
fileExtension: 'xlsx',
path: './'
},
translate: {
appId: '20230324001613652', // 私人翻译账户,如有国际化需求,请申请自己的百度翻译服务
key: 'Sprp7Mz8_yydeyhYrgE0',
host: 'http://api.fanyi.baidu.com'
}
};

View File

@@ -0,0 +1,124 @@
{
"name": "amis-editor-core",
"version": "6.13.0",
"description": "amis 可视化编辑器",
"main": "lib/index.js",
"module": "esm/index.js",
"types": "lib/index.d.ts",
"exports": {
".": {
"require": "./lib/index.js",
"import": "./esm/index.js"
},
"./lib/*": {
"require": "./lib/*",
"import": "./esm/*"
},
"./scss/*": {
"style": "./scss/*",
"require": "./scss/*",
"import": "./scss/*"
},
"./lib/style.css": "./lib/style.css",
"./*": {
"require": "./lib/*.js",
"import": "./esm/*.js"
}
},
"scripts": {
"test": "echo \"Warnings: no test specified\"",
"build": "npm run clean-dist && cross-env NODE_ENV=production rollup -c",
"build-esm": "npm run clean-dist && cross-env NODE_ENV=production rollup -c rollup.esm.config.js",
"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",
"format": "prettier --write \"{src,scss}/**/**/*.{js,jsx,ts,tsx,vue,scss,json}\""
},
"keywords": [
"amis",
"editor"
],
"author": "@fex",
"license": "ISC",
"files": [
"lib",
"esm",
"static"
],
"dependencies": {
"amis-theme-editor-helper": "*",
"axios": "0.21.1",
"deep-diff": "1.0.2",
"json-ast-comments": "^1.1.0",
"lodash": "^4.17.15",
"mobx": "^4.5.0",
"mobx-react": "^6.3.1",
"mobx-state-tree": "^3.17.3",
"react-frame-component": "^5.2.6",
"react-json-view": "^1.21.3",
"sortablejs": "^1.14.0"
},
"devDependencies": {
"@fortawesome/fontawesome-free": "^6.1.1",
"@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",
"@svgr/rollup": "^6.2.1",
"@types/async": "^2.0.45",
"@types/codemirror": "5.60.10",
"@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/qs": "^6.5.1",
"@types/react": "^18.0.24",
"@types/react-dom": "^18.0.8",
"@types/react-router": "^4.0.16",
"@types/react-router-dom": "^5.1.7",
"@types/sortablejs": "^1.10.7",
"@types/tinycolor2": "^1.4.3",
"ajv": "^8.8.2",
"autoprefixer": "^10.4.12",
"concurrently": "^6.2.0",
"cross-env": "^7.0.3",
"css-loader": "^6.2.0",
"faker": "^5.5.3",
"i18n-command": "^0.0.23-beta.15",
"mini-css-extract-plugin": "^2.3.0",
"postcss-import": "^14.1.0",
"postcss-minify": "^1.1.0",
"postcss-url": "^10.1.3",
"prettier": "^2.2.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-overlays": "5.1.1",
"react-router": "5.2.1",
"react-router-dom": "5.3.0",
"rimraf": "^3.0.2",
"rollup": "^2.73.0",
"rollup-plugin-auto-external": "^2.0.0",
"rollup-plugin-license": "^2.7.0",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-terser": "^7.0.2",
"sass": "^1.49.7",
"sass-loader": "^12.5.0",
"style-loader": "^3.2.1",
"stylelint": "^14.11.0",
"ts-loader": "^9.2.5",
"tslib": "^2.3.1",
"typescript": "^4.4.2"
},
"peerDependencies": {
"amis": "*",
"amis-core": "*",
"amis-formula": "*",
"amis-theme-editor-helper": "*",
"amis-ui": "*",
"i18n-runtime": "*",
"react": ">=16.8.6",
"react-dom": ">=16.8.6"
}
}

View File

@@ -0,0 +1,204 @@
// 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 {
name,
version,
author,
main,
module,
dependencies
} from './package.json';
import path from 'path';
import fs from 'fs';
import svgr from '@svgr/rollup';
import i18nPlugin from 'plugin-react-i18n';
import postcssImport from 'postcss-import';
import minify from 'postcss-minify';
import autoprefixer from 'autoprefixer';
import {terser} from 'rollup-plugin-terser';
import postcss from 'rollup-plugin-postcss';
import replace from '@rollup/plugin-replace';
const cssUrl = require('postcss-url');
const i18nConfig = require('./i18nConfig');
const settings = {
globals: {}
};
const pkgs = [];
// 读取所有的node_modules目录,获取所有的包名
[
path.join(__dirname, './node_modules'),
path.join(__dirname, '../../node_modules')
].forEach(dir => {
if (fs.existsSync(dir)) {
fs.readdirSync(dir).forEach(item => {
if (item.startsWith('.')) {
return;
}
if (item.startsWith('@')) {
fs.readdirSync(path.join(dir, item)).forEach(subItem => {
pkgs.push(item + '/' + subItem);
});
}
return pkgs.push(item);
});
}
});
const external = id =>
pkgs.some(pkg => id.startsWith(pkg) || ~id.indexOf(`node_modules/${pkg}`));
const input = './src/index.ts';
export default [
{
input: ['./src/index.ts', './scss/editor.scss'],
output: [
{
...settings,
dir: path.dirname(main),
format: 'cjs',
exports: 'named',
preserveModulesRoot: './src',
preserveModules: false // Keep directory structure and files
}
],
external,
plugins: getPlugins('cjs').concat([
postcss({
include: 'scss/editor.scss',
extract: path.resolve('lib/style.css'),
plugins: [
postcssImport(),
autoprefixer(),
minify(),
cssUrl({
url: 'inline',
maxSize: 10
})
]
})
])
},
{
input,
output: [
{
...settings,
dir: path.dirname(module),
format: 'esm',
exports: 'named',
preserveModulesRoot: './src',
preserveModules: false // 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:
', "tslib"], function(mod, tslib) {fullfill(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(),
resolve({
jsnext: true,
main: true
}),
replace({
preventAssignment: true,
__buildVersion: version,
__buildTime: () => new Date().toISOString()
}),
commonjs({
sourceMap: false
}),
terser({format: {quote_style: 1}}),
license({
banner: `
${name} v${version}
Copyright 2018<%= moment().format('YYYY') > 2018 ? '-' + moment().format('YYYY') : null %> ${author}
`
}),
onRollupError(error => {
console.warn(`[构建异常]${error}`);
// 构建异常时,删除 tsconfig.tsbuildinfo
fs.unlink(path.resolve(__dirname, 'tsconfig.tsbuildinfo'), () => {
console.info(
'[构建异常]已自动删除tsconfig.tsbuildinfo,请重试构建命令。'
);
});
})
];
}
function onRollupError(callback = () => {}) {
return {
name: 'onerror',
buildEnd(err) {
if (err) {
callback(err);
}
}
};
}

View File

@@ -0,0 +1,5 @@
import config from "./rollup.config";
const esmConfig = config[1];
export default esmConfig;

View File

@@ -0,0 +1,55 @@
.editor-backTop {
position: fixed;
right: 30px;
bottom: 32px;
z-index: 10000;
width: 32px;
height: 32px;
margin: 0;
padding: 0;
box-sizing: border-box;
color: rgba(0, 0, 0, 0.85);
font-size: 14px;
font-variant: tabular-nums;
line-height: 1.5715;
list-style: none;
font-feature-settings: 'tnum';
cursor: pointer;
visibility: visible;
transition: all 0.3s;
&.hidden {
visibility: hidden;
}
}
.editor-backTop:empty {
display: none;
}
.backTop-content {
width: 40px;
height: 40px;
overflow: hidden;
color: #fff;
text-align: center;
background-color: rgba($Editor-theme, 0.85);
border-radius: 20px;
transition: all 0.3s;
}
.backTop-content:hover {
background-color: $Editor-theme;
transition: all 0.3s;
}
.backTop-icon {
font-size: 20px;
line-height: 40px;
}
@media screen and (max-width: 768px) {
.editor-backTop {
right: 60px;
}
}
@media screen and (max-width: 480px) {
.editor-backTop {
right: 20px;
}
}

View File

@@ -0,0 +1,154 @@
.ae-Breadcrumb {
flex: 0 0 22px;
padding: 0;
background: #fff;
box-sizing: border-box;
border-bottom: 1px solid $editor-border-color;
z-index: 1000;
padding: 0 16px;
.ae-Breadcrumb-content {
left: 0;
height: 100%;
width: max-content;
white-space: nowrap;
height: 22px;
line-height: 22px;
background: #fff;
letter-spacing: 0;
font-family: PingFangSC-Regular;
font-size: 12px;
color: #5c5f66;
font-weight: 400;
user-select: none;
box-sizing: border-box;
transition: left ease-out 0.15s;
> ul {
list-style: none;
display: inline-block;
margin: 0;
padding: 0;
> li {
display: inline-block;
margin: 0 0 0 8px;
padding: 0;
position: relative;
&:first-child {
margin: 0;
}
> span {
display: inline-block;
padding-right: 8px;
line-height: 22px !important; // 避免被覆盖
cursor: pointer;
&:hover {
text-decoration: none;
}
}
// 同级元素选择弹层
> ul {
position: absolute;
top: 26px;
left: 0;
min-width: 100px;
max-height: 320px;
line-height: 20px; // 32 - 12
padding: 0;
font-family: PingFangSC-Regular;
font-size: 12px;
color: #151b26;
font-weight: 400;
box-shadow: 0 2px 8px 0 rgba(7, 12, 20, 0.12);
border-radius: 4px;
background: #fff;
list-style: none;
z-index: 100000; // 设置一个最大的层级
visibility: hidden;
transition: all ease-out 0.15s;
> li > span {
display: block;
padding: 6px 12px;
cursor: pointer;
&:hover {
background: $active-bg-color;
text-decoration: none;
}
&.is-active {
color: $Editor-theme;
}
}
}
&:hover > ul,
& > ul:hover {
visibility: visible;
}
}
> li:not(:last-child):after {
color: #5e626a;
content: '\003E';
}
> li:last-child > span {
font-family: PingFangSC-Medium;
font-size: 12px;
color: #151b26;
line-height: 20px;
font-weight: 500;
text-decoration: none;
}
}
}
.ae-Breadcrumb-scrollLeft-btn,
.ae-Breadcrumb-scrollRight-btn {
position: absolute;
top: 0;
left: 0;
width: 40px;
height: 41px;
background-color: #fff;
box-sizing: border-box;
box-shadow: 2px 0 20px 0 rgb(0 0 0 / 10%);
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
visibility: hidden;
z-index: 100000;
svg {
color: #151b26;
width: 16px;
height: 16px;
transform: rotate(180deg);
&:hover {
color: $editor-active-color;
}
}
}
.ae-Breadcrumb-scrollRight-btn {
left: auto;
right: 0;
box-shadow: -2px 0 20px 0 rgb(0 0 0 / 10%);
svg.icon-editor-double-arrow {
transform: rotate(0deg);
}
}
&:hover {
.ae-Breadcrumb-scrollLeft-btn,
.ae-Breadcrumb-scrollRight-btn {
visibility: visible;
}
}
}

View File

@@ -0,0 +1,58 @@
.ae-ClassNamePicker-popover {
padding: 10px;
width: 610px;
max-height: min(calc(100% - 220px), 400px);
min-height: 220px;
overflow: auto;
&.ae-PopOver--leftBottomLeftTop {
margin-top: 1px;
}
&.ae-PopOver--leftTopLeftBottom {
margin-top: -1px;
}
}
.ae-ClassNameControl-group {
margin: 10px;
display: inline-block;
width: 265px;
&.w2x {
width: 550px;
}
.ae-ClassNameControl-group {
padding-left: 65px;
margin: 0;
display: block;
width: auto;
&:not(:last-child) {
margin: 0 0 10px 0;
}
.ae-ClassNameControl-groupLabel {
float: left;
border: none;
padding-top: 5px;
padding-bottom: 0;
text-align: right;
margin: 0 0 0 -60px;
font-size: 12px;
}
}
.ae-ButtonGroup + .ae-ButtonGroup {
margin-left: 5px;
}
}
.ae-ClassNameControl-groupLabel {
border-bottom: px2rem(1px) solid lighten($color: $borderColor, $amount: 5%);
display: block;
padding-bottom: 5px;
margin-bottom: 10px;
font-size: 14px;
}

View File

@@ -0,0 +1,109 @@
.context-menu-setting {
position: relative;
width: 260px;
background: #fff;
box-shadow: -2px 0 20px 0 rgba(0, 0, 0, 0.1);
z-index: 5;
// 搞点动画?
transition: width ease-in-out 0.2s;
transform: translateZ(0);
display: flex;
flex-direction: column;
.setting-header {
flex: 0 0 48px;
font-family: PingFangSC-Regular;
font-size: 14px;
color: #141a25;
line-height: 48px;
letter-spacing: 0;
font-weight: 400;
border-bottom: 1px solid #e6e6e8;
text-align: center;
}
.setting-body {
flex: 1 1 auto;
overflow-x: hidden;
overflow-y: auto;
padding: 12px 6px;
display: flex;
justify-content: flex-start;
align-content: flex-start;
flex-wrap: wrap;
.setting-item {
margin: 0 2px 12px 6px; // 兼容右侧可能出现滚动条情况
padding-top: 12px;
flex: 0 0 112px;
height: 62px;
cursor: pointer;
box-sizing: border-box;
border: 1px solid #ddd;
border-radius: 4px;
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: center;
.icon-box {
width: 24px;
height: 24px;
box-sizing: border-box;
display: flex;
justify-content: center;
align-items: center;
> svg {
width: 24px;
height: 24px;
fill: #bcbcbc;
}
}
.setting-info {
margin-top: 4px;
flex: 1 1 auto;
font-family: PingFangSC-Regular;
font-size: 12px;
color: #141a25;
font-weight: 400;
user-select: none;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
&:hover {
background: #e9effd;
border: 1px solid $Editor-theme-color;
border-radius: 4px;
.icon-box > svg {
fill: $Editor-theme-color;
}
.setting-info {
color: $Editor-theme-color;
}
}
&.disabled {
cursor: not-allowed;
// pointer-events: none;
background: rgba(#bdbdbd, 0.15);
border: 1px solid #ddd;
border-radius: 4px;
.icon-box > svg {
fill: #bdbdbd;
}
.setting-info {
color: #bdbdbd;
}
}
}
}
}

View File

@@ -0,0 +1,40 @@
.aeDataChain {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
min-height: 300px;
&-aside {
width: 60px;
flex-shrink: 0;
border-right: 1px solid #ccc;
margin-right: 10px;
padding-right: 10px;
> ul {
list-style: none;
margin: 0;
padding: 0;
> li {
display: block;
cursor: pointer;
text-align: center;
color: #999;
padding: 2px 5px;
font-size: 12px;
&.is-active {
color: #333;
background: darken(#f6f7fb, 2.5%);
}
}
}
}
&-main {
flex-grow: 1;
flex-basis: auto;
overflow-x: auto;
}
}

View File

@@ -0,0 +1,248 @@
.editor-left-panel {
position: relative;
flex: 0 0 308px; // 48px + 260px
// min-width: 308px;
background: #fff;
overflow: visible;
box-shadow: 2px 0 20px 0 rgba(0, 0, 0, 0.1);
z-index: 5;
// 搞点动画?
transition: width ease-in-out 0.2s;
transform: translateZ(0);
// 宽度可拖拽时不增加过渡,避免卡顿
&.width-draggable {
transition: none;
}
&.fixed-status {
position: fixed;
top: 0;
left: 0;
width: auto;
height: 100%;
}
// 悬浮icon
.editor-panel-btn {
position: absolute;
top: 12px;
right: 12px;
height: 16px;
width: 16px;
z-index: 100;
display: flex;
justify-content: center;
align-items: center;
.panel-btn {
width: 16px;
height: 16px;
fill: $default-icon-color;
color: $default-icon-color;
cursor: pointer;
&:hover {
fill: $Editor-theme;
color: $Editor-theme;
}
}
}
// 折叠状态
&.hidden-status {
flex: 0 0 48px;
min-width: 48px;
width: 48px;
> .editor-panel-btn {
display: none;
}
}
// 折叠收缩 icon
.left-panel-arrow {
position: absolute;
width: 16px;
height: 50px;
top: 50%;
right: -15px;
transform: translateY(-50%);
background-color: transparent;
box-sizing: border-box;
z-index: 10;
cursor: pointer;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
&::before {
content: '';
position: absolute;
border-radius: 0 10px 10px 0;
box-sizing: border-box;
// border: 1px solid rgba(0, 0, 0, 0.1);
border-left: 0;
// box-shadow: -2px 2px 2px #f0f1f2;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: #fff;
z-index: -1;
transform: perspective(50px) rotateY(30deg);
transition: all 0.15s;
}
&::after {
content: '';
position: absolute;
width: 6px;
height: 8px;
// right: 50%;
top: 50%;
-webkit-mask-image: url(../static/side_hide_left.svg);
-webkit-mask-size: 100% 100%;
mask-size: 100% 100%;
-webkit-mask-repeat: no-repeat;
mask-repeat: no-repeat;
background-color: #a1a6b3;
transform: translate(-50%, -50%) rotate(0deg);
transition: all 0.15s;
}
&.hidden-status {
&::after {
transform: translate(-50%, -50%) rotate(180deg);
}
}
}
.editorPanel-tabs {
position: relative;
height: 100%;
display: flex;
> [class$='Tabs-linksWrapper'] {
position: relative;
flex: 0 0 48px;
border: none;
border-right: 1px solid #e6e6e8;
height: 100%;
box-sizing: border-box;
}
.editorPanel-tabs-header {
padding-top: 20px;
> li {
margin: 0 0 12px 0 !important;
padding: 0;
overflow: visible; // 避免 tooltip被遮挡
width: 48px;
height: 48px;
box-sizing: border-box;
padding: 0 3px;
display: flex !important;
flex-direction: column;
justify-content: flex-start;
align-items: center;
> a {
position: relative;
display: inline-block;
width: 100%;
height: 100%;
margin: 0 !important;
padding: 0 !important;
border: none !important;
overflow: visible; // 避免 tooltip被遮挡
display: flex;
justify-content: center;
align-items: center;
// 用于设置自定义tab面板中的icon样式
.editor-tab-icon {
position: relative;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
> svg {
width: 48px;
height: 48px;
color: #151b26;
}
&.editor-tab-s-icon > svg {
width: 16px;
height: 16px;
}
}
}
&.is-active,
&:hover {
background: #eef3fe;
> a {
background: #eef3fe;
}
.editor-tab-icon > svg {
color: $editor-active-color !important;
}
}
// 选中态左侧边框高亮
&.is-active {
padding: 0 3px 0 0;
border-left: 3px solid $editor-active-color;
}
}
}
> .editorPanel-tabs-content {
position: relative;
flex: 1 1 auto;
height: 100%;
border: none;
.editorPanel-tabs-pane {
position: relative;
height: 100%;
padding: 0;
width: $Editor-aside-width;
box-sizing: border-box;
}
}
}
// 代码编辑面板
.ae-Editor-codePane {
position: relative;
height: 100%;
// transition: width ease-out 0.3s;
max-width: 800px;
// monaco-editor 里面的,会把内容撑开。
.overflowingContentWidgets {
margin-top: -99999px;
}
}
}
.editor-code-tabs,
.editor-code-tabs-cont,
.editor-code-tabs-cont .in {
height: 100%;
}
// 左侧面板悬浮模式时的占位,避免折叠状态遮挡内容区
.editor-left-panel-fixed-placeholder {
position: relative;
flex: 0 0 48px;
background: #fff;
}

View File

@@ -0,0 +1,104 @@
@mixin minScrollBar {
// 火狐浏览器
scrollbar-width: thin;
scrollbar-color: #d4d6d9 transparent;
&::-webkit-scrollbar {
// display: none;
background-color: transparent;
width: 6px;
overflow: visible;
height: 10px !important;
}
::-webkit-scrollbar-track {
background-color: transparent;
}
&::-webkit-scrollbar-thumb {
width: 6px;
background-color: #d4d6d9; // #babac0;
border-radius: 6px;
border: 4px solid transparent;
&:hover {
background-color: rgb(92, 95, 102, 0.5);
}
}
&::-webkit-scrollbar-button {
display: none;
}
}
@mixin flexBox(
$direction: row,
$justify-content: space-between,
$align-items: center,
$wrap: nowrap
) {
display: flex;
flex-flow: $direction $wrap;
justify-content: $justify-content;
align-items: $align-items;
}
@mixin panel-icon {
fill: var(--primary);
path {
fill: var(--primary);
}
}
@mixin panel-group-bg {
background: #fafafa;
padding: #{px2rem(10px)};
border-radius: #{$Editor-borderRadius};
}
@mixin collapse-header-text {
color: #070c14;
font-weight: 500;
font-size: 12px;
}
@mixin extend-more {
position: relative;
background-color: #f7f7f9;
border-radius: px2rem(2px);
padding: px2rem(12px) px2rem(8px);
&::after {
display: block;
content: '';
height: 12px;
width: 12px;
position: absolute;
top: -6px;
left: 12px;
transform: rotate(45deg);
background-color: #f7f7f9;
}
fieldset {
margin-bottom: var(--Form-item-gap);
.cxd-Collapse-content {
background-color: transparent;
}
}
&.right::after {
right: 12px;
left: auto;
}
}
@mixin panel-sm-content {
// @extend :root;
--fonts-size-7: #{$Editor-right-panel-font-size};
--Form-input-lineHeight: #{$Editor-right-panel-line-height};
--InputGroup-select-borderColor: #{$Editor-right-panel-border-color};
--Form-input-borderColor: #{$Editor-right-panel-border-color};
}

View File

@@ -0,0 +1,341 @@
@keyframes shake {
10%,
90% {
transform: translate3d(-1px, 0, 0);
}
20%,
80% {
transform: translate3d(2px, 0, 0);
}
30%,
50%,
70% {
transform: translate3d(-4px, 0, 0);
}
40%,
60% {
transform: translate3d(4px, 0, 0);
}
}
.shake {
animation: shake 0.82s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
transform: translate3d(0, 0, 0);
backface-visibility: hidden;
perspective: 1000px;
}
.ae-Outline-panel {
display: flex;
flex-direction: column;
height: 100%;
.ae-outline-tabs {
flex: 1;
display: flex;
flex-direction: column;
min-height: 0;
.ae-outline-tabs-header {
padding: 0 12px;
}
.ae-outline-tabs-content {
flex: 1;
min-height: 0;
margin-top: 12px;
}
.ae-outline-tabs-panel.is-active {
display: flex;
flex-direction: column;
height: 100%;
padding: 0;
}
}
}
.ae-Outline {
// margin-top: 16px;
padding: 12px 10px 6px 10px;
--Tree-indent: 16px;
// width: $Editor-aside-width;
flex: 1 1 auto;
background: #fff;
&-list,
&-sublist {
list-style: none;
padding: 0;
margin: 0;
}
&-list {
// margin-left: 16px;
}
&-sublist {
// margin-left: 16px;
> .ae-Outline-node {
&::before,
&::after {
position: absolute;
content: '';
background: $editor-border-color;
display: block;
}
&::before {
width: 8px;
height: 1px;
left: calc(var(--indent) * var(--Tree-indent) - 9px);
top: 12px;
visibility: hidden; // 隐藏左侧连线(横线)
}
&::after {
width: 1px;
height: 100%;
left: calc(var(--indent) * var(--Tree-indent) - 9px);
top: 0;
visibility: hidden; // 隐藏左侧连线(竖线)
}
&:last-child::after {
height: 12px;
}
}
}
&:hover {
// hover时 显示连接线
.ae-Outline-node {
&::before,
&::after {
visibility: visible;
}
}
}
&-node {
position: relative;
padding: 0;
margin: 0;
> a {
padding: 0 8px;
padding-left: calc(var(--indent) * var(--Tree-indent));
min-width: 108px;
font-family: PingFangSC-Regular;
font-size: 12px;
color: $editor-default-color;
line-height: 24px;
font-weight: 400;
text-decoration: none;
user-select: none;
cursor: pointer;
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
&:hover {
// color: $editor-default-color; // 避免被其他全局样式覆盖
// background: $hover-bg-color;
}
}
&.has-children > a {
margin-left: 0;
}
> a:hover,
&.is-hover > a {
color: $editor-active-color;
// border-radius: 2px;
}
&.is-active {
background: $active-bg-color;
> a {
color: $editor-active-color;
// border-radius: 2px;
}
}
&.is-folded > .ae-Outline-sublist {
display: none;
}
span.has-keywords {
color: $editor-active-color;
font-weight: 600;
}
}
&-textIndent {
display: inline-block;
width: 4px;
}
&-expander {
position: relative;
left: 0;
// top: 8px;
cursor: pointer;
z-index: 2;
display: inline-flex;
justify-content: center;
align-items: center;
> svg {
width: 16px;
height: 16px;
color: $default-icon-color;
transform: rotate(0deg);
transition: transform ease-out 0.1s;
}
// &:before {
// content: '';
// display: inline-block;
// width: 0;
// height: 0;
// border-style: solid;
// border-width: 4px 0 4px 6.9px;
// border-color: transparent transparent transparent $dark;
// transform: rotate(45deg);
// }
&.is-folded > svg {
transform: rotate(-90deg);
}
}
&-tip {
color: $success;
margin-bottom: 15px;
animation: shake 0.82s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
transform: translate3d(0, 0, 0);
backface-visibility: hidden;
perspective: 1000px;
}
&-dropNode {
padding: 25px 0 0 15px;
margin-bottom: 5px;
position: relative;
background: #fff;
&:after {
pointer-events: none;
content: '';
position: absolute;
z-index: 2;
top: 0;
left: 0;
right: 0;
bottom: 0;
border: 1px dashed $editor-border-color;
}
&.is-active {
&:after {
border: 1px dashed $editor-active-color;
z-index: 3;
}
color: $editor-default-color;
background: $active-bg-color;
}
> a {
color: $editor-default-color;
position: absolute;
display: block;
width: 100%;
left: 5px;
top: 2px;
font-size: 12px;
}
}
}
.ae-DialogList {
&-wrap {
padding: 0 10px;
}
list-style: none;
margin: 8px 0 0;
padding: 0;
li {
cursor: pointer;
margin: 4px 0;
padding: 4px 10px;
font-size: 12px;
display: flex;
justify-content: space-between;
gap: px2rem(5px);
align-items: center;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
color: var(--colors-neutral-text-2);
> span {
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
}
a.ae-DialogList-iconBtn {
font-size: inherit;
color: var(--icon-color);
text-decoration: none;
cursor: pointer;
> svg {
top: px2rem(1px);
width: px2rem(16px);
height: px2rem(16px);
}
> svg.icon-copy {
top: 0;
width: px2rem(12px);
height: px2rem(12px);
}
&:hover {
color: var(--icon-onHover-color);
background: var(--colors-neutral-bg-2);
}
}
}
// li + li {
// border-top: var(--borderWidth) solid var(--borderColor);
// }
li:hover {
color: var(--Layout-fontColor--onHover);
background: $hover-bg-color;
// border-top: var(--borderWidth) solid var(--borderColor);
// border-bottom: var(--borderWidth) solid var(--borderColor);
}
&-placeholder {
color: #b4b6ba;
padding-top: px2rem(10px);
text-align: center;
vertical-align: middle;
}
}

View File

@@ -0,0 +1,491 @@
.ae-RendererList-tabs {
position: relative;
height: 100%;
padding: 0;
width: $Editor-aside-width;
overflow: hidden;
display: flex;
flex-direction: column;
justify-content: flex-start;
.ae-RendererList-tabs-header {
padding: 0 12px;
}
.ae-RendererList-tabs-content {
position: relative;
margin-top: 12px;
flex: 1 1 auto;
padding: 0 5px;
// overflow: auto;
height: 100%;
// max-height: calc(100% - 50px); // 确保不撑开
box-sizing: border-box;
// @include minScrollBar();
.ae-RendererList-tabs-panel {
position: relative;
padding: 0;
height: 100%;
}
}
}
.ae-RendererList {
height: 100%;
padding: 0 0 12px 0;
// width: $Editor-aside-width;
display: flex;
flex-direction: column;
justify-content: flex-start;
.ae-RendererList-tabs-header {
padding: 0 12px;
}
.ae-RendererList-tabs-content {
position: relative;
margin-top: 12px;
flex: 1 1 auto;
padding: 0 5px;
// overflow: auto;
height: 100%;
// max-height: calc(100% - 50px); // 确保不撑开
box-sizing: border-box;
// @include minScrollBar();
.ae-RendererList-tabs-panel {
position: relative;
padding: 0;
height: 100%;
}
}
}
.ae-RendererList {
height: 100%;
padding: 0 0 12px 0;
// width: $Editor-aside-width;
display: flex;
flex-direction: column;
&.only-base-component {
width: $Editor-aside-width;
.ae-RendererList-groupWrap {
margin: 0;
padding: 0 0 12px 0;
}
}
.ae-RendererList-tip {
padding: 0 12px;
color: $success;
}
// 用于提示类文本的样式
.ae-RendererList-group > span,
.ae-RendererList-groupWrap > span,
.ae-RendererList-placeholder {
display: inline-block;
margin: 12px;
}
&-groupWrap {
flex: 1 1 auto;
margin: 0 -5px; // 让右侧滚动条靠最右侧
padding: 0 0 12px 0;
background: #fff;
scrollbar-width: none !important; // 火狐浏览器中不显示滚动条,避免挤压组件列表
.collapse-header {
padding: 0 12px;
font-family: PingFangSC-Regular;
font-size: 12px;
color: #141a25;
letter-spacing: 0;
line-height: 20px;
font-weight: 400;
letter-spacing: 0;
height: 35px;
line-height: 35px;
cursor: pointer;
display: flex;
justify-content: space-between;
align-items: center;
// 折叠icon
.expander-icon {
> svg {
width: 10px;
height: 10px;
color: #333;
transform: rotate(90deg);
transition: transform ease-out 0.3s;
}
&.is-folded > svg {
transform: rotate(270deg);
}
}
}
}
&-group.collapse-content {
display: flex;
flex-wrap: wrap;
height: auto;
padding: 6px 0 4px 2px;
box-sizing: border-box;
// border-bottom: 1px solid $editor-border-color;
transition: height 0.3s;
&:last-child {
border-bottom: none;
}
&.is-folded {
height: 0;
padding: 0;
overflow: hidden;
&:last-child {
height: 0;
}
}
.ae-RendererList-item {
margin: 0 2px 12px 10px; // 兼容右侧可能出现滚动条情况
padding: 0 8px;
flex: 0 0 112px;
cursor: pointer;
width: 112px;
height: 32px;
border: 1px solid #e8e9eb;
border-radius: 4px;
box-sizing: border-box;
display: flex;
justify-content: flex-start;
align-items: center;
.icon-box {
width: 16px;
height: 16px;
box-sizing: border-box;
display: flex;
justify-content: center;
align-items: center;
> i {
font-size: 16px;
color: #b8babf;
}
// 新版 icon 使用 svg
svg {
width: 16px;
height: 16px;
color: #7c7d82; // icon 颜色深一点,会显得更清晰点
top: 0 !important; // 覆盖amis样式,避免未垂直居中
}
}
.ae-RendererInfo {
flex: 1 1 auto;
font-family: PingFangSC-Regular;
font-size: 12px;
color: #151b26;
letter-spacing: 0;
line-height: 20px;
font-weight: 400;
max-width: 80px;
padding: 0 8px;
user-select: none;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.ae-RendererIcon {
flex: 0 0 16px;
color: $default-icon-color;
justify-content: center;
align-items: center;
display: none; // hover 时使用flex
> svg {
width: 16px;
height: 16px;
top: 0 !important; // 覆盖amis样式,避免未垂直居中
}
&:hover {
color: $editor-active-color;
}
}
&:hover {
border-color: $editor-active-color;
.ae-RendererInfo {
max-width: 64px;
}
.ae-RendererIcon {
display: flex !important;
}
}
}
}
}
// 左侧组件面板/info提示弹窗
.ae-RendererThumb {
max-width: 328px;
min-height: 70px;
padding: 5px;
font-size: 12px;
color: #151b26;
line-height: 20px;
background: #fff;
box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.06), 0 1px 10px 0 rgba(0, 0, 0, 0.05),
0 2px 4px -1px rgba(0, 0, 0, 0.04);
transform: scale(1);
transform-origin: center top;
.ae-Renderer-title {
font-family: PingFangSC-Medium;
font-weight: 500;
font-size: 14px;
}
.ae-Renderer-info {
margin: 4px 0;
font-family: PingFangSC-Regular;
letter-spacing: 0;
font-weight: 400;
}
.ae-Renderer-preview {
position: relative;
max-height: 200px;
overflow: auto;
}
}
// 左侧插入和替换组件面板
.ae-InsertPanel-drawer {
// 右上角的关闭icon
svg.icon-close {
width: 22px;
height: 22px;
}
.ae-InsertPanel-footer {
> .action-btn {
padding: 4px 16px;
border-radius: 4px;
display: inline-flex;
justify-content: center;
align-items: center;
}
> .action-btn.action-btn-primary {
color: #fff;
background-color: #2468f2;
&:hover {
background-color: #5086f5;
}
}
> .action-btn.is-disabled {
color: #b4b6ba;
background-color: #e6e6e8;
border-color: #e6e6e8;
}
}
}
// 新版插入组件面板(抽屉弹出式)
.ae-InsertRendererPanel-drawer {
// 右上角的关闭icon
> svg.icon-close {
width: 22px;
height: 22px;
}
.ae-drawer-renderers {
width: 417px; // 确保能一行展示5个组件
border-radius: 0 !important;
.ae-drawer-title {
padding: 0 12px;
font-family: PingFangSC-Medium;
font-size: 18px;
color: #141a25;
letter-spacing: 0;
font-weight: 500;
height: 35px;
line-height: 35px;
cursor: pointer;
}
.ae-RendererList {
width: 100% !important;
}
}
.ae-RendererList-tabs {
width: 417px; // 确保能一行展示5个组件
}
}
.ae-RenderersPicker-list {
flex-grow: 1;
height: 0;
display: flex;
flex-direction: row;
margin-top: 10px;
margin-bottom: 10px;
> ul {
min-width: 40px;
margin: 0;
padding: 0;
margin-right: 20px;
user-select: none;
> li {
list-style: none;
display: block;
text-align: center;
white-space: nowrap;
&:not(:last-child) {
margin-bottom: 10px;
}
> a {
color: #666;
font-size: 14px;
cursor: pointer;
padding: 2px 10px;
border-radius: 5px;
}
&.is-active > a,
> a:hover {
text-decoration: none;
color: #333;
background: rgba(66, 133, 244, 0.1);
}
}
}
}
.ae-RenderersPicker-content {
flex-grow: 1;
width: 0;
overflow: auto;
@include minScrollBar();
> ul {
list-style: none;
margin: 0;
padding: 0;
> li {
border-radius: 4px;
margin: 0;
padding: 0;
display: flex;
flex-wrap: wrap;
flex-direction: row;
align-items: center;
border: 1px solid #e6e7e8;
color: #666;
font-size: 12px;
cursor: pointer;
&:not(:last-child) {
margin-bottom: 10px;
}
&:hover,
&.is-active {
background: rgba($Editor-hlbox--onActive-bg, 0.05);
}
&.is-active {
border: 1px solid $Editor-theme;
}
}
}
}
.ae-RenderersPicker-info {
flex-grow: 1;
width: 0;
padding: 10px;
align-self: flex-start;
user-select: none;
> h4 {
font-size: 14px;
color: #333;
padding: 0;
margin: 0 0 10px;
}
}
.ae-RendereresPicker-form {
height: 100%;
}
.ae-RenderersPicker {
height: 100%;
display: flex;
flex-direction: column;
}
.ae-RegionFilter {
margin: 10px 15px;
font-size: 12px;
color: #666;
> div {
display: inline-block;
cursor: pointer;
padding: 2px 10px;
border-radius: 5px;
&:hover,
&.is-active {
color: #333;
background: rgba(66, 133, 244, 0.1);
}
}
}
.ae-InsertPanel {
display: flex;
flex-direction: column;
padding: 15px;
width: 100%;
height: 100%;
&-title {
color: #333;
margin-bottom: 10px;
}
&-footer {
text-align: right;
> button + button,
> div + button {
margin-left: 5px;
}
}
}

View File

@@ -0,0 +1,507 @@
$right-panel-width: px2rem(280px);
$right-panel-sidetab-width: px2rem(62px);
$category-1-height: px2rem(44px);
$category-2-height: px2rem(32px);
$tooltip-bottom: '[data-tooltip][data-position=' bottom ']:hover:after';
.editor-right-panel {
position: relative;
flex: 0 0 auto;
width: $right-panel-width;
min-width: $right-panel-width;
max-width: 600px; // 避免过度拖拽
// width: 280px;
background: #fff;
box-shadow: -2px 0 20px 0 rgba(0, 0, 0, 0.1);
z-index: 5;
// 搞点动画?
transition: width ease-in-out 0.2s;
// transform: translateZ(0);
@include panel-sm-content();
// 宽度可拖拽时不增加过渡,避免卡顿
&.width-draggable {
transition: none;
}
// 用于避免右侧配置面板被超长的valueLabel撑开,导致样式异常
.#{$ns}SubForm-valueLabel {
word-break: break-all;
}
// 外层有多个tab面板
&.mul-tabs-panel {
width: calc(#{$right-panel-sidetab-width} + #{$right-panel-width});
min-width: calc(#{$right-panel-sidetab-width} + #{$right-panel-width});
// width: 328px;
// min-width: 328px; // 48px + 280px
}
// 悬浮icon
.editor-panel-btn {
position: absolute;
top: 0;
left: 0;
height: 16px;
width: 16px;
z-index: 100;
display: flex;
justify-content: center;
align-items: center;
display: none;
.panel-btn {
width: 16px;
height: 16px;
fill: $default-icon-color;
color: $default-icon-color;
cursor: pointer;
transform: rotate(-45deg);
&:hover {
fill: $Editor-theme;
color: $Editor-theme;
}
}
}
// 折叠状态
&.hidden-status {
width: 0 !important;
min-width: 0;
.editor-panel-btn {
display: none;
}
.width-draggable-icon.hasArrowIcon {
visibility: hidden;
}
.editorPanel-inner {
display: none;
}
}
&.fixed-status {
position: fixed;
top: 0;
right: 0;
width: 280px;
height: 100%;
&.mul-tabs-panel {
width: calc(#{$right-panel-sidetab-width} + #{$right-panel-width});
// width: 328px; // 48px + 280px
}
}
&.has-popover {
z-index: 1300;
}
.editorPanel-inner {
position: relative;
height: 100%;
&.has-popover {
z-index: 1300;
}
}
// 外层tabs
.editorPanel-tabs {
display: flex;
flex-direction: row-reverse;
height: 100%;
> [class$='Tabs-linksWrapper'] {
position: relative;
flex: 0 0 48px;
border: none;
}
.editorPanel-tabs-header {
padding-top: 20px;
// tab面板title
&:empty {
min-width: unset;
}
> li {
margin: 0 0 12px 0 !important;
padding: 0;
overflow: visible; // 避免 tooltip被遮挡
width: 48px;
height: 48px;
box-sizing: border-box;
padding: 0 3px;
display: flex !important;
flex-direction: column;
justify-content: flex-start;
align-items: center;
> a {
position: relative;
display: inline-block;
width: 100%;
height: 100%;
margin: 0 !important;
padding: 0 !important;
border: none !important;
overflow: visible; // 避免 tooltip被遮挡
display: flex;
justify-content: center;
align-items: center;
// 用于设置自定义tab面板中的icon样式
.editor-tab-icon {
position: relative;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
i.fa {
font-size: 16px !important;
width: 16px;
height: auto;
margin-bottom: 0 !important;
color: #151b26;
}
> svg {
width: 16px;
height: 16px;
color: #151b26;
}
// 新版icon
> svg.pluginIcon {
width: 20px;
height: 20px;
color: #151b26;
}
}
}
&.is-active,
&:hover {
background: #eef3fe;
> a {
background: #eef3fe;
}
i.fa,
.editor-tab-icon > svg {
color: $editor-active-color !important;
}
}
// 选中态左侧边框高亮
&.is-active {
padding: 0 0 0 3px;
border-right: 3px solid $editor-active-color;
}
}
}
> .editorPanel-tabs-content {
position: relative;
flex: 1 1 auto;
height: 100%;
max-width: calc(100% - 48px); // 避免被内容元素撑开
border-left: none;
.editorPanel-tabs-pane {
position: relative;
height: 100%;
padding: 0;
box-sizing: border-box;
max-width: 100%;
}
}
}
// 属性配置表单面板
.ae-Settings-content {
position: relative;
height: 100%;
padding: 10px 12px;
// 带底部操作按钮的属性配置面板
&.with-actions {
position: relative;
.editor-prop-config-tabs {
padding-bottom: 45px;
&-links {
--fonts-size-7: 14px;
}
}
.ae-Settings-actions,
> input {
position: sticky;
left: 0;
bottom: -16px;
margin-bottom: 0;
width: 100%;
line-height: 1;
display: flex;
align-items: center;
justify-content: center;
}
}
}
// 右侧面板收起箭头
.right-panel-arrow {
position: absolute;
width: 16px;
height: 50px;
top: 50%;
left: -15px;
transform: translateY(-50%);
background-color: transparent;
box-sizing: border-box;
z-index: 10;
cursor: pointer;
&::before {
content: '';
position: absolute;
border-radius: 10px 0 0 10px;
box-sizing: border-box;
// border: 1px solid rgba(0, 0, 0, 0.1);
border-right: 0;
// box-shadow: -2px 2px 2px #f0f1f2;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: #fff;
z-index: -1;
transform: perspective(50px) rotateY(-30deg);
transition: all 0.15s;
}
&::after {
content: '';
position: absolute;
width: 6px;
height: 8px;
left: 55%;
top: 50%;
-webkit-mask-image: url(../static/side_hide_left.svg);
-webkit-mask-size: 100% 100%;
mask-size: 100% 100%;
-webkit-mask-repeat: no-repeat;
mask-repeat: no-repeat;
background-color: #a1a6b3;
transform: translate(-50%, -50%) rotate(180deg);
transition: all 0.15s;
}
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
&.hidden-status {
&::after {
transform: translate(-50%, -50%) rotate(0deg);
}
}
}
}
.right-panel-pop {
@include panel-sm-content();
}
// 包裹样式
.config-wrapper-contanier {
position: relative;
margin: 0 auto 12px auto;
padding: 12px 8px;
background-color: #f7f7f9;
border-radius: 2px;
&::after {
display: block;
content: '';
height: 12px;
width: 12px;
position: absolute;
top: -6px;
left: 12px;
transform: rotate(45deg);
background-color: #f7f7f9;
}
&.hidden-tip {
&::after {
display: none;
}
}
&.tip-position-20p {
&::after {
left: 20%;
}
}
&.tip-position-30p {
&::after {
left: 30%;
}
}
&.tip-position-right-12 {
&::after {
left: auto;
right: 12px;
}
}
&.tip-position-right-55 {
&::after {
left: auto;
right: 55px;
}
}
&.tip-position-right-90 {
&::after {
left: auto;
right: 90px;
}
}
}
.ae-Settings-content {
padding: var(--gap-base);
#{$tooltip-bottom} {
margin-left: -10px;
animation-name: none;
}
.ae-Combo-item > div:first-child > #{$tooltip-bottom} {
margin-left: 15px;
}
// 内层tabs
.editor-prop-config-tabs {
display: block;
position: relative;
height: 100%;
padding: 0;
flex-direction: column;
justify-content: flex-start;
overflow: hidden;
margin: calc(0rem - (var(--gap-base)));
.old-action-tooltip-warpper {
display: block;
padding: 10px 12px 0;
// 老动作入口
.old-action-btn {
width: 100%;
}
}
// tab导航
ul[role='tablist'],
&-links {
margin: 0;
flex: 0;
border-bottom: 1px solid #d4d6d9;
display: flex;
justify-content: space-between;
z-index: 1; // 防止被panel body中的部分组件覆盖border
> li {
flex: 1;
display: flex;
height: $category-1-height;
justify-content: center;
border: 0 !important;
padding: 0 !important;
max-width: none;
align-items: stretch;
padding: 0 !important;
> a {
display: inline-block;
height: 100%;
width: 100%;
text-align: center;
padding: 2px 0 0 0 !important;
font-family: PingFangSC-Regular;
color: #84868c;
width: 100%;
--Tabs--line-active-fontSize: 14px;
--Tabs--line-fontSize: 14px;
--Tabs--line-hover-fontSize: 14px;
--Tabs--line-disabled-fontSize: 14px;
letter-spacing: 0;
font-weight: 400;
text-decoration: none;
border: none !important;
border-bottom: 2px solid #fff !important;
box-sizing: border-box;
display: flex !important;
justify-content: center !important;
align-items: center !important;
}
&.is-active > a {
color: $Editor-theme-color !important;
border-bottom: 2px solid $editor-active-color !important;
}
&:not(:last-child):after {
position: absolute;
right: 0;
top: 50%;
transform: translateY(-50%);
content: '';
width: 1px;
height: 12px;
background-color: #d8d8d8;
}
&:not(:last-child):after {
position: absolute;
right: 0;
top: 50%;
transform: translateY(-50%);
content: '';
width: 1px;
height: 12px;
background-color: #d8d8d8;
}
}
}
// tab内容
&-cont {
height: calc(100% - 45px);
position: absolute;
width: 100%;
padding: 0;
overflow-y: overlay !important;
@include minScrollBar();
margin-top: -1px;
}
div.ae-switch-more-flex {
display: flex;
line-height: 25px;
}
}
}

View File

@@ -0,0 +1,244 @@
.editor-InputSearch-panel {
position: relative;
.editor-InputSearch-content {
position: absolute;
top: 36px;
left: 12px;
width: calc(100% - 24px);
min-height: 50px;
padding: 4px 12px;
background: #fff;
box-shadow: 0 4px 5px 0 rgba(62, 72, 99, 0.06),
0 1px 10px 0 rgba(62, 72, 99, 0.05), 0 2px 4px -1px rgba(62, 72, 99, 0.04);
border-radius: 4px;
z-index: 100;
visibility: visible;
transition: all 0.3s;
display: flex;
flex-direction: column;
justify-content: flex-start;
&.hidden-status {
visibility: hidden;
}
.search-history {
flex: 0 0 auto;
margin-bottom: 12px;
padding-bottom: 4px;
font-family: PingFangSC-Regular;
font-size: 12px;
color: #080e1a;
line-height: 20px;
font-weight: 400;
&.has-border-bottom {
border-bottom: 1px solid #e6e6e8;
}
.header {
opacity: 0.5;
height: 32px;
line-height: 32px;
display: flex;
justify-content: space-between;
align-items: center;
.header-clear-icon {
cursor: pointer;
}
}
.history-cont {
position: relative;
margin: 0 -12px;
padding: 0 12px;
overflow: hidden;
// overflow-y: hidden;
display: flex;
flex-direction: column;
&.hasScrollBtn {
max-height: 192px;
&:hover {
overflow-y: auto;
padding: 0 6px 0 12px;
}
}
@include minScrollBar();
.history-item {
flex: 0 0 auto;
margin: 0 -12px;
padding: 0 12px;
opacity: 0.95;
height: 32px;
display: flex;
justify-content: space-between;
align-items: center;
&:hover {
opacity: 0.8;
background: #f0f0f0;
}
.history-keyword {
flex: 1 1 auto;
max-width: calc(100% - 16px);
color: #151a26;
user-select: none;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
cursor: pointer;
}
.delete-icon {
flex: 0 0 20px;
color: #080e1a;
display: flex;
justify-content: center;
align-items: center;
svg {
width: 12px;
height: 12px;
opacity: 0.5;
cursor: pointer;
&:hover {
fill: $Editor-theme-color;
}
}
}
}
}
}
.search-result-list {
position: relative;
flex: 0 0 auto;
font-family: PingFangSC-Regular;
font-size: 12px;
color: #080e1a;
line-height: 20px;
font-weight: 400;
margin: 0 -12px;
padding: 0 12px;
max-height: 192px;
overflow: hidden;
&.hasScrollBtn {
max-height: 192px;
&:hover {
overflow-y: auto;
padding: 0 6px 0 12px;
}
}
@include minScrollBar();
.subRenderers-header {
// padding-right: 12px;
height: 32px;
line-height: 32px;
cursor: pointer;
display: flex;
justify-content: space-between;
align-items: center;
svg {
width: 10px;
height: 10px;
opacity: 0.5;
transform: rotate(90deg);
transition: all 0.15s;
}
&.is-folded svg {
transform: rotate(270deg);
}
}
.multiple-subRenderers-list {
display: flex;
flex-direction: column;
}
.subRenderers-list {
display: flex;
flex-direction: column;
&.is-folded {
height: 0;
overflow: hidden;
}
.subRenderers-item {
flex: 0 0 32px;
padding-left: 12px;
line-height: 32px;
user-select: none;
cursor: pointer;
text-align: left;
opacity: 0.95;
&:hover {
background: #f0f0f0;
}
.is-keyword {
color: $Editor-theme-color;
}
}
// 仅有一个分类
&.only-one-tag .subRenderers-item {
margin: 0 -12px;
padding: 0 12px;
}
}
}
.tag-list {
flex: 0 0 auto;
font-family: PingFangSC-Regular;
font-size: 12px;
color: #080e1a;
line-height: 20px;
font-weight: 400;
.header {
opacity: 0.5;
}
.tag-list-cont {
margin: 4px -4px;
display: flex;
flex-wrap: wrap;
justify-items: flex-start;
.tag-item {
margin: 4px;
flex: 0 0 auto;
padding: 2px 8px;
opacity: 0.95;
border: 1px solid #f2f3f3;
background-color: #f2f3f3;
border-radius: 2px;
cursor: pointer;
&:hover {
color: $Editor-theme-color;
}
}
}
}
}
}

View File

@@ -0,0 +1,31 @@
.ae-Editor-selectionCursor {
position: absolute;
background: rgba(#23b7e5, 0.2);
border: 1px solid rgba(#23b7e5, 1);
z-index: 999999;
}
.ae-Editor-list {
.ae-Editor-listItem,
.ae-Editor-eachItem {
position: relative !important;
&::after {
position: absolute;
content: '';
width: 100%;
height: 100%;
pointer-events: all;
background: rgba(22, 40, 60, 0.2) url(../static/indication.png) repeat;
z-index: 100;
top: 0;
left: 0;
cursor: not-allowed;
}
}
.ae-Editor-eachItem:first-child::after,
.cards-items > div:first-child > div::after {
display: none;
}
}

View File

@@ -0,0 +1,70 @@
// 快捷键展示面板
.shortcut-icon-btn {
display: inline-flex;
justify-content: center;
align-items: center;
color: $default-icon-color;
cursor: pointer;
&:hover {
color: $editor-active-color;
}
}
div.shortcut-list-modal {
padding: 24px;
.shortcut-modal-header {
display: flex;
flex-direction: row;
justify-content: space-between;
.shortcut-modal-title {
font-family: PingFangSC-Medium;
font-size: 16px;
color: #141a25;
letter-spacing: 0;
line-height: 22px;
font-weight: 500;
}
svg.shortcut-modal-icon {
width: 12px;
height: 12px;
}
}
.shortcut-modal-body {
padding-top: 20px;
.shortcut-list {
display: flex;
flex-direction: column;
.shortcut-item {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 14px;
color: #828282;
letter-spacing: 0;
line-height: 30px;
.shortcut-letter {
margin: 0 2px;
display: inline-flex;
min-width: 12px;
height: 22px;
line-height: 22px;
border: 1px solid #1f38584d;
border-radius: 3px;
padding: 0 8px;
display: inline-flex;
justify-content: center;
align-items: center;
}
}
}
}
}

View File

@@ -0,0 +1,53 @@
/**
* table view 相关节点的编辑器扩展
*/
.ae-TableViewEditor {
position: relative;
&-rowLine {
position: absolute;
height: 7px;
left: 0;
right: 0;
cursor: row-resize;
user-select: none;
opacity: 0.5;
// &:hover {
// background: #4285f4;
// }
}
&-colLine {
position: absolute;
width: 7px;
top: 0;
bottom: 0;
cursor: col-resize;
user-select: none;
opacity: 0.5;
// &:hover {
// background: #4285f4;
// }
}
&-mergeIcon {
position: absolute;
bottom: -22px;
left: calc(50% - 3.5em);
color: #4285f4;
cursor: pointer;
}
td[data-selected] {
background: #cfe1fe;
}
// 这个按钮会导致单元格高宽发生变化
.ae-AddBtn {
position: absolute;
left: calc(50% - 10px);
top: calc(50% - 10px);
margin: 0;
}
}

View File

@@ -0,0 +1,30 @@
.ae-TargetName {
padding: 12px;
width: 15em;
&-list {
list-style: none;
padding: 0;
margin: 0;
user-select: none;
cursor: pointer;
}
&-node {
> span {
line-height: normal;
}
> a {
color: $text-color;
text-decoration: none;
}
&.is-active {
> a {
color: $primary;
}
}
&.is-hover {
> a {
color: $primary;
}
}
}
}

View File

@@ -0,0 +1,111 @@
// 页面设计器 3.0 UI
// 提示小气泡,带箭头
[editor-tooltip] {
position: relative;
// 默认右侧展示
&::after {
pointer-events: none;
left: calc(100% + 10px);
top: 50%;
transform: translateY(-50%);
position: absolute;
max-width: 300px;
padding: 4px 8px;
box-sizing: content-box;
content: attr(editor-tooltip);
font-family: PingFangSC-Regular;
font-size: 12px;
color: #fff;
text-align: center;
line-height: 20px;
font-weight: 400;
background: rgba(7, 12, 20, 0.85);
border: 1px solid rgba(7, 12, 20, 0.85);
border-radius: 4px;
box-shadow: 0 2px 8px 0 rgba(7, 12, 20, 0.12);
white-space: normal;
animation-fill-mode: both;
visibility: hidden;
z-index: 110; // 避免被组件搜索面板遮挡
white-space: nowrap;
}
// 默认右侧展示
&::before {
position: absolute;
content: '';
pointer-events: none;
left: calc(100% - 2px);
top: 50%;
transform: translateY(-50%);
width: 0;
margin: 0;
padding: 0;
box-sizing: content-box;
border: 6px solid rgba(7, 12, 20, 0.85);
border-color: transparent rgba(7, 12, 20, 0.85) transparent transparent;
visibility: hidden;
z-index: 100;
}
&:not(.is-disabled):hover::after,
&:not(.disabled):hover::after,
&:not(.is-disabled):hover::before,
&:not(.disabled):hover::before {
visibility: visible;
}
&.is-disabled:hover::after,
&.disabled:hover::after,
&.is-disabled:hover::before,
&.disabled:hover::before {
visibility: hidden !important;
}
&[tooltip-position='bottom']::after {
left: 50%;
top: calc(100% + 10px);
transform: translateX(-50%);
}
&[tooltip-position='bottom']::before {
left: 50%;
top: calc(100% - 2px);
transform: translateX(-50%);
border-color: transparent transparent rgba(7, 12, 20, 0.85) transparent;
}
&[tooltip-position='left']::after {
top: 50%;
right: calc(100% + 10px);
left: auto;
transform: translateY(-50%);
}
&[tooltip-position='left']::before {
top: 50%;
right: calc(100% - 2px);
left: auto;
transform: translateY(-50%);
border-color: transparent transparent transparent rgba(7, 12, 20, 0.85);
}
&[tooltip-position='top']::after {
left: 50%;
top: auto;
bottom: calc(100% + 9px);
transform: translateX(-50%);
}
&[tooltip-position='top']::before {
left: 50%;
top: auto;
bottom: calc(100% - 2px);
transform: translateX(-50%);
border-color: rgba(7, 12, 20, 0.85) transparent transparent transparent;
}
}

View File

@@ -0,0 +1,51 @@
// $Editor-btn-bg: #4285f4;
// $Editor-btn-border: darken($Editor-btn-bg, 5%);
// $Editor-btn-color: $white;
$body-bg: #f7f7f9;
// 编辑器内容区主题色
$Editor-theme: #205dd9; // #2468F2; // #4285f4;
$Editor-hlbox-bg: rgba($Editor-theme, 0.75);
$Editor-hlbox--onActive-bg: $Editor-theme; // #4285f4;
$Editor-hlbox--onActiveConfig-bg: #f39000;
$Editor-rgion-bg: $Editor-theme; // #23b7e5;
$Editor-theme-color: #2468f2;
$Editor-text-color: #141a25;
// 右侧面板
$Editor-right-panel-color: #151b26;
$Editor-right-panel-border-color: #e8e9eb;
$Editor-right-panel-font-size: 12px;
$Editor-right-panel-radios-line-height: 21px;
$Editor-right-panel-line-height: 1.6; // 32px
$Editor-aside-width: 260px;
$Editor-borderRadius: 5px;
// 页面设计器 3.0 UI 基础色调
$editor-default-color: #151b26; // 默认的字体色
$editor-active-color: #2468f2;
$editor-hover-color: #5086f5;
$editor-danger-color: #ff6966;
$editor-border-color: #e8e9eb; // 默认的边框色
$default-icon-color: #84868c; // 默认的icon颜色
$active-bg-color: #e6f0ff; // 激活态的背景色
$hover-bg-color: #f7f7f9; // 激活态的背景色
$disabled-color: #b8babf; // 禁用文字颜色
$disabled-bg-color: #f7f7f9; // 禁用背景颜色
$default-bg-color: #f7f7f9; // 默认背景颜色
// 修复 amis button 字体 14px问题
.editor-right-panel {
--button-size-md-font-size: 12px;
--button-size-default-font-size: 12px;
}
// 空容器的占位最小高度
$Editor-placehoder-height: 34px;

View File

@@ -0,0 +1,10 @@
.ae-ButtonLevel-MenuTpl {
height: 32px;
display: flex;
align-items: center;
button {
width: 100%;
height: 26px;
padding: 0;
}
}

View File

@@ -0,0 +1,166 @@
.ae-ApiControl {
position: relative;
&.border {
padding: #{px2rem(10px)};
border-radius: $Editor-borderRadius;
border: 1px solid #e6e6e8;
}
&-header {
@include flexBox();
height: #{px2rem(24px)};
position: absolute;
right: 0;
top: px2rem(-26px);
}
&-content {
@include flexBox();
align-items: stretch;
.ae-ApiControl-input {
background: var(--Form-input-bg);
border: var(--Form-input-borderWidth) solid var(--Form-input-borderColor);
border-radius: var(--Form-input-borderRadius);
line-height: var(--Form-input-lineHeight);
padding: var(--Form-input-paddingY) var(--Form-input-paddingX);
font-size: var(--Form-input-fontSize);
display: flex;
flex-flow: row nowrap;
justify-content: flex-start;
align-items: center;
flex: 1;
margin-right: #{px2rem(10px)};
// max-width: calc(100% - 52px);
height: var(--Button--sm-height);
& > input {
flex-basis: 5rem;
flex-grow: 1;
outline: 0;
background: transparent;
border: 0;
color: var(--Form-input-color);
width: 100%;
height: calc(var(--Form-input-lineHeight) * var(--Form-input-fontSize));
}
.ae-ApiControl-setting-button {
height: unset;
}
}
}
&-highlight {
width: 100%;
max-width: calc(100% - var(--fontSizeLg));
display: flex;
flex-flow: row nowrap;
justify-content: flex-start;
align-items: center;
&-tag {
display: inline-block;
background: #007bff;
padding: 3px 5px;
margin: 0 1px;
color: #fff;
font-size: 12px;
line-height: 14px;
height: 20px;
border-radius: #{px2rem(4px)};
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
max-width: 90%;
}
}
&-icon {
width: var(--fontSizeLg) !important;
height: var(--fontSizeLg) !important;
}
&-dialog {
&-body {
margin: #{px2rem(16px)} 0 #{px2rem(24px)};
.ae-ApiControl-form {
@include panel-sm-content();
.ae-ApiControl-tabContent {
max-height: 560px;
overflow-x: hidden;
overflow-y: auto;
border-bottom: 1px solid var(--borderColor);
}
.ae-ApiControl-title {
border-left: none;
font-weight: bold;
color: #333;
line-height: #{px2rem(20px)};
padding-left: 0;
}
}
}
}
&-picker {
&-dialog {
&-content {
height: 500px;
max-height: 500px;
overflow-x: hidden;
overflow-y: auto;
}
}
}
}
.ae-ApiControl-PickerBtn {
padding: 0;
&:hover > svg path {
stroke: var(--primary);
color: var(--primary);
}
}
.ae-AdaptorControl,
.ae-FunctionEditorControl {
&-func {
&-header,
&-footer {
padding-left: 8px;
font-size: 12px;
}
&-header {
margin-bottom: -20px;
}
&-footer {
margin-top: -20px;
}
&-arg {
padding: 0;
height: auto;
font-size: 12px;
vertical-align: baseline;
color: var(--primary);
}
&-editor {
margin-bottom: 0;
.cxd-EditorControl {
padding-top: 20px;
padding-bottom: 20px;
}
.cxd-MonacoEditor-placeholder {
line-height: 18px;
font-size: 12px;
}
}
}
&-desc-tooltip {
max-width: 500px;
}
}

View File

@@ -0,0 +1,47 @@
.ae-BadgeControl {
&-switch {
@include flexBox();
margin-bottom: var(--gap-base);
}
&-form {
@include panel-group-bg();
}
&-combo {
background: #fafafa;
padding: var(--gap-sm);
border: 1px dashed transparent;
border-radius: #{$Editor-borderRadius};
&:hover {
border-color: #{$Editor-theme-color};
}
}
&-buttonGroup {
> div {
align-items: center;
justify-content: space-between;
> div {
flex-grow: 0 !important;
min-width: auto !important;
}
}
}
&-position {
&--clockwise {
> i {
transform: rotate(45deg);
}
}
&--antiClockwise {
> i {
transform: rotate(-45deg);
}
}
}
}

View File

@@ -0,0 +1,174 @@
/**
* @file crud2-control.scss
* @desc CRUD2相关控件及样式
*/
.ae-CRUDConfigControl {
margin-bottom: var(--Form-item-gap);
&-list {
margin: 0;
padding: 0;
border-radius: 4px;
border: 1px solid #e8e9eb;
padding-top: 3px;
padding-bottom: 3px;
&-item {
display: flex;
align-items: center;
justify-content: space-between;
height: 30px;
padding: 0 var(--gap-sm);
&.is-draggable:hover {
background-color: #f9f9f9;
cursor: move;
}
&-dragger {
cursor: move;
margin: 0 var(--gap-sm) 0 0;
color: rgba(232, 233, 235, 1);
}
&-info {
display: flex;
align-items: center;
justify-content: flex-start;
max-width: 140px;
& > span {
max-width: 100%;
min-width: 0;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
font-weight: 500;
color: #151b26;
}
}
&-actions {
display: flex;
align-items: center;
justify-content: space-between;
margin-right: var(--gap-xs);
& > button {
color: #151b26;
margin: 0;
padding-left: 0;
padding-right: 0;
&:not(:last-child) {
margin-right: var(--gap-sm);
}
& > svg {
width: px2rem(16px);
height: px2rem(16px);
&.icon-share-link {
width: px2rem(14px);
height: px2rem(14px);
}
}
}
}
&-tag {
cursor: auto;
background-color: transparent;
border: 1px solid #2468f2;
color: #2468f2;
border-radius: 2px;
line-height: #{px2rem(18px)};
height: #{px2rem(20px)};
margin-right: #{px2rem(8px)};
scale: 0.9;
max-width: 80px;
&--cascading {
color: #531dab;
border-color: #531dab;
}
}
}
}
&-placeholder {
color: #b4b6ba;
padding-top: px2rem(10px);
text-align: center;
vertical-align: middle;
}
&-header {
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
align-items: center;
& > span:nth-child(1) {
margin-bottom: 0;
}
&-actions {
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
align-items: center;
&-switch {
margin-right: var(--gap-sm);
}
&-divider {
width: 1px;
height: 16px;
margin: 0 4px;
background-color: #dfdfdf;
}
}
}
&-dropdown {
/* margin-bottom: var(--Form-mode-default-labelGap); */
& > button {
color: #4c5664;
margin: 0;
padding-left: 0;
padding-right: 0;
font-weight: bold;
& > svg {
width: px2rem(14px);
height: px2rem(14px);
margin-right: var(--gap-xs);
}
}
}
&-footer {
display: flex;
flex-flow: row-reverse nowrap;
}
}
.ae-CRUDConfigControl-modal {
&-btn-loading {
--Spinner-color: #fff;
}
}
.ae-FieldSetting-footer {
position: absolute;
right: 0;
bottom: 35px;
&--form {
bottom: 55px;
}
}

View File

@@ -0,0 +1,98 @@
.ae-DataBindingList {
display: flex;
flex-flow: column nowrap;
justify-content: flex-start;
align-items: stretch;
height: px2rem(350px);
border: 1px solid rgba(232, 233, 235, 1);
border-radius: px2rem(4px);
overflow: scroll;
&-hint {
width: 100%;
line-height: 3;
text-align: center;
color: var(--text--muted-color);
}
&-searchBox {
width: auto;
padding: #{px2rem(12px)};
& > div {
width: 100% !important;
}
}
&-body {
@include minScrollBar();
flex: 1;
overflow-x: hidden;
overflow-y: auto;
}
&-collapse {
border: none;
background: #f7f7f9;
&-title {
display: block !important;
padding: #{px2rem(5px)} #{px2rem(12px)};
background: transparent !important;
font-size: var(--fontSizeSm);
font-weight: bold;
position: relative;
.expandIcon {
font-size: var(--fontSizeSm);
line-height: var(--fontSizeXl);
transform-origin: #{px2rem(7px)} #{px2rem(9px)};
transition: transform 0.2s;
position: absolute;
right: #{px2rem(6px)};
margin-top: 3px;
}
}
&-body {
background: #fff;
color: #303540;
> div {
padding: 5px 0;
}
}
}
&-item {
display: flex;
flex-direction: row;
align-items: baseline;
cursor: pointer;
padding: 0 var(--gap-xl); // 和标题对齐不好看,加个缩进
height: px2rem(32px);
line-height: px2rem(32px);
color: #303540;
font-weight: 400;
span {
flex-grow: 1;
}
&:hover {
background: var(--Tree-item-onHover-bg);
}
&.is-active {
color: var(--primary);
background: var(--Tree-item-onHover-bg);
}
}
&-empty {
color: #b4b6ba;
padding-top: px2rem(10px);
text-align: center;
vertical-align: middle;
}
}

View File

@@ -0,0 +1,117 @@
.ae-DateShortCutControl {
&-header {
@include flexBox();
width: 100%;
height: #{px2rem(24px)};
margin-bottom: #{px2rem(5px)};
label {
margin-right: #{px2rem(16px)};
font-size: #{px2rem(12px)};
color: #5e626a;
}
&-icon {
flex: 1;
text-align: right;
}
}
&-footer {
margin-top: #{px2rem(10px)};
&-btn {
display: inline-block;
width: 50%;
padding-right: #{px2rem(5px)};
&:last-child {
padding-left: #{px2rem(5px)};
padding-right: 0;
}
> div {
width: 100%;
}
button {
width: 100%;
}
ul {
width: 100%;
min-width: unset;
}
}
}
&-content {
@include flexBox(column, flex-start);
@include minScrollBar();
margin: 0;
padding: #{px2rem(3px)} 0;
border-radius: $Editor-borderRadius;
position: relative;
background: #f7f7f9;
&::before {
content: '';
position: absolute;
top: -6px;
left: 10px;
border-left: 9px solid transparent;
border-right: 9px solid transparent;
border-bottom: 9px solid #f7f7f9;
}
.ae-DateShortCutControlItem {
@include flexBox();
width: 100%;
padding: #{px2rem(5px)} #{px2rem(10px)};
min-height: #{px2rem(38px)};
align-items: baseline;
&:hover {
background: #e9effd;
}
&-dragging {
height: 0 !important;
padding: 0;
border-top: 2px solid var(--primary);
overflow: hidden;
background: #e9effd;
}
&-dragBar {
display: inline-flex;
margin-left: 0;
margin-right: var(--gap-sm);
margin-top: -4px;
cursor: move;
color: #8c8c8c;
}
&-content {
display: inline-block;
flex-grow: 1;
max-width: calc(100% - 32px);
text-align: left;
padding: 0 #{px2rem(5px)};
&-label {
line-height: var(--input-size-default-height);
}
}
&-close {
cursor: pointer;
}
}
}
&-empty {
@include flexBox(column, center);
height: #{px2rem(38px)};
}
}

View File

@@ -0,0 +1,515 @@
.ae-event-control {
font-size: #{px2rem(12px)};
&-header-oldentry {
height: 100px;
.add-event-dropdown {
top: 47px;
width: 100%;
}
}
&-header {
width: 100%;
padding: #{px2rem(12px)};
background: #fff;
z-index: 1;
margin-top: 1px;
.add-event-dropdown {
button {
top: 44px;
width: 100%;
color: #2468f2;
border: #{px2rem(1px)} solid #2468f2;
border-radius: #{px2rem(4px)};
span {
display: none;
}
}
.add-event-dropdown-global-event {
position: relative;
&::after {
position: absolute;
content: '全局事件';
display: flex;
align-items: center;
padding: 0 6px;
right: 4px;
top: 4px;
bottom: 4px;
font-size: 12px;
color: #fff;
background-color: #2468f2;
border-radius: 4px;
transform: scale(0.8);
transform-origin: center;
}
}
}
ul {
width: 100%;
}
}
&-header-m {
margin-top: #{px2rem(45px)} !important;
}
&-content-m {
margin-top: #{px2rem(97px)} !important;
}
&-content-l {
margin-top: #{px2rem(150px)} !important;
}
&-content {
padding: 0;
margin-top: 0;
.icon {
cursor: pointer;
color: #30343f;
width: #{px2rem(16px)};
height: #{px2rem(16px)};
&:hover {
color: #2468f2;
}
}
.event-item {
display: flex;
flex-direction: column;
&-header {
display: flex;
flex-direction: row;
justify-content: space-between;
background: #f2f2f4;
border: #{px2rem(1px)} solid #d4d6d9;
border-left: none;
border-right: none;
padding: 0 12px;
font-weight: 500;
align-items: center;
height: #{px2rem(32px)};
&-toolbar {
display: flex;
align-items: center;
& > div {
margin-right: #{px2rem(12px)};
&:last-child {
margin-right: 0;
}
}
}
.event-label {
display: flex;
align-items: center;
.event-label-key {
flex: 1;
max-width: 100px;
overflow: hidden;
text-overflow: ellipsis;
}
.global-event-tip {
width: 48px;
display: flex;
> span {
transform: scale(0.7);
transform-origin: left;
background-color: #2468f2;
border-radius: 4px;
font-size: 12px;
color: #fff;
padding: 4px 6px;
flex-shrink: 0;
text-align: center;
}
}
}
}
&-desc {
margin: #{px2rem(12px)};
color: #84868c;
button > svg {
width: #{px2rem(12px)};
height: #{px2rem(12px)};
}
}
&:last-child {
.event-item-header {
border-bottom: #{px2rem(1px)} solid #d4d6d9;
}
}
.no-bd-btm {
border-bottom: none;
}
.item-content {
@include flexBox(column, flex-start);
@include minScrollBar();
margin: 0;
padding-left: #{px2rem(12px)};
padding-right: #{px2rem(12px)};
padding-top: #{px2rem(12px)};
background: #ffffff;
list-style-type: none;
.ae-option-control-item {
background: #f7f7f9;
width: 100%;
padding: #{px2rem(8px)};
margin-bottom: #{px2rem(12px)};
border-radius: #{px2rem(4px)};
border: #{px2rem(1px)} solid transparent;
&:hover {
border: #{px2rem(1px)} solid #2468f2;
}
.action-control-header {
@include flexBox(row, space-between);
&-left,
&-right {
color: #303540;
display: flex;
align-items: center;
.icon {
color: #84868c;
&:hover {
color: #2468f2;
}
}
.action-item-actiontype {
max-width: #{px2rem(144px)};
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
}
&-right {
& > div {
margin-right: #{px2rem(8px)};
&:last-child {
margin-right: 0;
}
}
}
}
.action-control-content {
color: #84868c;
letter-spacing: 0;
line-height: #{px2rem(20px)};
font-weight: 400;
margin-top: #{px2rem(4px)};
padding-left: #{px2rem(20px)};
max-width: #{px2rem(224px)};
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
.action-desc {
display: flex;
.desc-tag {
max-width: 133px;
color: #2468f2;
display: inline-block;
margin-bottom: -5px;
}
.variable-left {
margin-left: #{px2rem(4px)};
}
.variable-right {
margin-right: #{px2rem(4px)};
}
.component-action-tag {
background-color: rgb(82, 142, 255);
display: inline-block;
color: #fff;
padding: 0 5px;
border-radius: 3px;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
width: 100%;
}
}
}
&--dragging {
height: 0 !important;
padding: 0;
border-top: 2px solid var(--primary);
overflow: hidden;
background: #e9effd;
}
&-dragBar {
display: inline-flex;
margin-left: 0;
line-height: 1;
margin-right: #{px2rem(4px)};
cursor: move;
color: #8c8c8c;
}
&-action {
padding-left: 0;
padding-right: 0;
&:not(:last-child) {
margin-right: #{px2rem(10px)};
}
&:hover {
& > svg,
& > svg path {
fill: var(--primary);
}
}
& > svg,
& > svg path {
fill: var(--text--muted-color);
}
}
}
}
}
.item-footer {
@include flexBox(row, flex-end);
padding: #{px2rem(5px)};
border-bottom-right-radius: $Editor-borderRadius;
border-bottom-left-radius: $Editor-borderRadius;
border-top: 1px solid #f2f7f3;
box-shadow: 0 0 5px rgb(8 14 26 / 6%);
clip-path: inset(-5px 0px 0px 0px);
}
}
.no-bd-btm {
border-bottom: none;
}
&-placeholder {
color: #84868c;
line-height: #{px2rem(24px)};
background: url('../static/empty.png');
text-align: center;
width: #{px2rem(124px)};
height: 100%;
padding-top: #{px2rem(300px)};
background-repeat: no-repeat;
background-size: #{px2rem(90px)} #{px2rem(90px)};
background-position: 50% 80%;
margin: 0 auto;
}
&-action-placeholder {
width: 100%;
min-height: #{px2rem(320px)};
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
color: #84868c;
line-height: #{px2rem(24px)};
&.no-settings {
min-height: #{px2rem(160px)};
}
&-img {
width: #{px2rem(64px)};
height: #{px2rem(64px)};
background: url('../static/empty.png');
background-repeat: no-repeat;
background-size: 100%;
background-position: center;
}
}
&-action-js-editor {
max-width: #{px2rem(780px)};
}
}
.ae-action-config-dialog {
*:not(svg) {
font-size: 12px;
}
.common-actions {
position: absolute;
width: 80%;
top: #{px2rem(-41px)};
left: #{px2rem(128px)};
.common-actions-label {
line-height: #{px2rem(24px)};
margin-right: 4px;
}
}
.action-config-panel {
background: #ffffff;
border: 1px solid #e8e9eb;
border-radius: 4px;
height: #{px2rem(420px)};
max-height: #{px2rem(420px)};
width: 100%;
@include panel-sm-content();
.action-panel-title {
margin: 16px 16px 12px;
line-height: 18px;
font-weight: 500;
}
.action-tree-search {
margin: 0 16px 8px;
&-input {
& > div {
background: url('../static/search.svg') no-repeat right 12px center;
padding-right: 28px;
}
}
}
.action-search-list {
.search-result-label:hover {
background: var(--Tree-item-onHover-bg-pure);
}
}
.left-panel {
height: 100%;
padding-right: 0px;
border-right: 1px solid #e8e9eb;
max-width: #{px2rem(200px)};
.action-tree {
height: calc(100% - 88px);
border-top: 1px solid #e8e9eb;
.action-tree-control {
& > div {
max-height: 100%;
}
height: 100%;
max-height: 100%;
padding: 0;
& > div > div {
margin-top: 82px;
height: 64px;
background: url('../static/empty.png') center/contain no-repeat;
color: transparent;
}
}
.action-tree-control {
ul {
li {
& > div {
flex-direction: row-reverse;
padding-left: 16px;
height: 32px;
line-height: 32px;
span .is-matched {
color: #2468f2;
}
svg {
transform: rotate(180deg);
}
.is-folded > svg {
transform: rotate(0);
}
}
& > ul {
margin-left: 0;
li > div {
padding-left: #{px2rem(32px)};
}
li > div {
&:hover {
background-color: var(--Tree-item-onHover-bg-pure);
}
}
& > li .is-checked {
background: var(--Tree-item-onChekced-bg);
&:hover {
background-color: var(--Tree-item-onChekced-bg) !important;
}
}
}
}
li .is-checked::before {
content: '';
background: url('../static/check.svg') no-repeat center center;
height: var(--Tree-itemHeight);
line-height: var(--Tree-itemHeight);
width: 15px;
margin-right: 16px;
}
}
}
}
}
.right-panel {
overflow-y: auto;
height: 100%;
padding: 0 8px 0 0;
.action-desc {
margin-left: 16px;
color: var(--Form-item-color);
}
.cmpt-action-select,
.action-btn-width {
width: auto;
min-width: #{px2rem(320px)};
}
&-container {
// max-height: calc(100% - 46px);
margin: 0px 16px 16px;
.action-panel-title {
margin-left: 0;
}
.action-exec-on {
width: 100%;
}
}
.ae-BaseRemark {
margin-left: 0;
margin-top: 5px;
}
.event-action-combo-item {
.event-action-combo {
max-width: 380px;
.#{$ns}Form-row {
width: 380px;
}
.flex-1 {
max-width: 170px;
}
}
width: 380px;
}
}
}
}
.ae-event-item-header-tip {
background: #070c14d9 !important;
box-shadow: 0 px2rem(2px) px2rem(8px) 0 rgba(7, 12, 20, 0.12);
border: none;
div {
font-size: 12px;
color: #fff;
}
& > div {
&:after {
border-top-color: #070c14d9 !important;
border-bottom-color: #070c14d9 !important;
}
}
}
.ae-action-relation-panel {
width: 255px;
max-height: 360px;
overflow: auto;
.variables-select-panel-tree {
*:not(svg) {
font-size: 12px;
}
}
}

View File

@@ -0,0 +1,51 @@
.ae-ExpressionFormulaControl {
background-color: #fff;
.btn-configured,
.btn-set-expression {
width: 100%;
font-size: 12px;
}
.btn-configured {
position: relative;
justify-content: left;
padding: var(--button-size-sm-paddingTop) 32px
var(--button-size-sm-paddingBottom) 4px;
line-height: var(--button-size-sm-lineHeight);
height: var(--button-size-sm-height);
& > span {
max-width: 100%;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
background-color: #007bff;
padding: 4px 8px;
border-radius: 4px;
color: #fff;
}
.icon {
position: absolute;
top: 0;
bottom: 0;
right: var(--button-size-default-paddingRight);
margin: auto 0 !important;
width: 12px;
height: 12px;
fill: var(--Form-input-clearBtn-color);
&:hover {
fill: var(--Form-input-clearBtn-color-onHover);
}
}
}
}
.btn-configured-tooltip {
font-size: 12px;
width: 200px;
min-height: 40px;
.CodeMirror {
height: auto;
}
}

View File

@@ -0,0 +1,94 @@
.ae-FeatureControl {
&-features {
margin: 0;
padding: 0;
}
&Item {
display: flex;
height: 30px;
margin-bottom: 12px;
position: relative;
align-items: center;
:not(:last-child) {
margin-right: px2rem(8px);
}
&-content {
flex-grow: 1;
position: relative;
display: flex;
align-items: center;
justify-content: flex-start;
& > .ae-FeatureControlItem-go {
width: 100%;
}
}
&-label {
flex-grow: 1;
height: px2rem(32px);
display: block;
line-height: px2rem(32px);
padding: 0 px2rem(8px);
border: var(--Form-input-borderWidth) solid var(--Form-input-borderColor);
border-radius: var(--Form-input-borderRadius);
text-align: center;
}
&-action {
padding: 0 6px;
svg {
width: px2rem(16px);
height: px2rem(16px);
fill: #000;
}
&:hover {
svg {
fill: $Editor-theme;
}
}
}
&-dragBar {
position: absolute;
z-index: 2;
top: 50%;
transform: translateY(-50%);
left: 3px;
cursor: move;
& > svg {
fill: #e7e7e7;
color: #e7e7e7;
}
}
&:hover &-dragBar {
& > svg {
color: transparent;
fill: transparent;
}
}
}
&-action {
display: block;
width: 100%;
&--btn {
width: 100%;
border-color: $Editor-theme;
color: $Editor-theme;
}
&--menus {
/* width: calc(100% - 12px);
margin-left: 6px; */
text-align: center;
}
}
}

View File

@@ -0,0 +1,39 @@
.ap-Flex {
background: #ececec;
margin: 0;
padding: 6px 10px;
.ap-Flex-label {
font-size: 12px;
text-align: right;
}
.ap-Flex-item {
margin-top: 4px;
> .icon-ButtonList {
display: flex;
align-items: stretch;
justify-content: stretch;
> button {
flex: 1 1 auto;
display: flex;
justify-content: center;
align-items: center;
}
}
svg.scaleX-90 {
transform: rotate(90deg);
}
svg.scaleX-180 {
transform: rotate(180deg);
}
svg.scaleX-270 {
transform: rotate(270deg);
}
}
}

View File

@@ -0,0 +1,184 @@
/* 表单项配置面板 */
.ae-formItemControl {
&-label-tip {
display: inline-block;
}
div[data-role='form-item'] {
&.ae-ExtendMore {
> label {
flex: 0;
padding: 0;
}
}
> label {
line-height: 32px;
margin: 0;
padding-top: 0;
> span {
display: inline;
}
}
}
.ae-InputRangeValue-input-group {
&-delimiter {
border: none;
padding-left: 5px;
padding-right: 5px;
line-height: 30px;
}
}
.ae-sub-content {
@include extend-more();
margin-bottom: var(--Form-item-gap);
&.is-bottom {
margin-bottom: 0;
}
}
}
/* 面板 Collapse 样式覆写,为了提高优先级,用顶层类包裹 */
.ae-Outline-panel,
.ae-Settings-content {
.ae-formItemControl {
& > div:last-child {
.ae-formItemControl-header {
border-bottom: 1px solid #e5e5e5;
}
&.is-active {
.ae-formItemControl-header {
border-bottom: none;
}
}
}
div.ae-formItemControl-header.ae-Collapse-header {
width: 100%;
padding: #{px2rem(6px)} #{px2rem(12px)};
justify-content: space-between;
align-items: unset;
border-top: 1px solid #e5e5e5;
background: #f2f2f4;
border-radius: 0 !important;
@include collapse-header-text();
i {
transform-origin: px2rem(7px) px2rem(5px);
margin-top: px2rem(5px);
transition: transform 0.1s linear;
}
}
&-body {
--Form-item-gap: 12px;
padding: var(--gap-base);
> div:first-child {
padding-top: 0;
}
.fix-icon-picker-overflow {
input {
width: 0;
}
a {
display: inline-block;
position: relative;
left: -10px;
}
}
}
}
}
/* 状态配置控件 */
.ae-StatusControl {
position: relative;
&-switch {
position: absolute;
top: px2rem(-24px);
right: 0;
}
&-content {
padding-top: px2rem(12px);
> div {
@include extend-more();
}
}
}
/* 代码块 */
.ae-Code {
background: #ebf5ff;
color: #008dcd;
padding: #{px2rem(3px)} #{$Editor-borderRadius};
border-radius: #{px2rem(3px)};
}
.ae-ExtendMore {
@include extend-more();
}
/* 加强状态按钮,后续添加在AMIS中 */
.ae-Button--enhance {
color: #{$Editor-theme-color};
border: 1px solid #{$Editor-theme-color};
&:hover,
&:focus {
color: #4f86f4 !important;
border-color: #4f86f4 !important;
}
}
/* combo 组件样式调整, 后续amis中combo支持新增button自定义就可免去样式覆盖了*/
.ae-Combo-items {
@include extend-more();
margin-top: px2rem(8px);
> div {
background: inherit;
+ div {
margin-top: px2rem(12px) !important;
}
}
}
/* 设置面板 combo 多行模式样式调整 */
.cxd-Combo--ver:not(.cxd-Combo--noBorder) > .ae-Combo-items {
margin: px2rem(8px) 0;
padding: 0;
}
.cxd-Combo--ver:not(.cxd-Combo--noBorder) > .ae-Combo-items > .cxd-Combo-item {
margin: 0;
border: none;
&:hover {
border: none !important;
}
}
.ae-Combo-items + div {
padding-left: 0px !important;
margin-bottom: px2rem(12px);
> button,
> button:hover {
color: #528eff !important;
background: #ffffff !important;
border-color: #528eff !important;
width: 100%;
height: px2rem(32px);
}
}
.form-item-gap {
margin-bottom: var(--Form-item-gap);
}

View File

@@ -0,0 +1,216 @@
div.ae-editor-FormulaControl {
position: relative;
@include flexBox();
align-items: stretch;
max-width: 100%;
}
.ae-editor-FormulaControl {
& > &-buttonWrapper {
height: auto;
}
& > &-buttonWrapper > &-button {
height: 100%;
background-color: #f7f7f9;
padding: 4px 8px;
border-radius: 0 var(--button-size-sm-top-left-border-radius)
var(--button-size-sm-bottom-right-border-radius) 0;
border-left: 0;
&:not(:disabled):not(.is-disabled):hover {
border-color: #e6f0ff;
background-color: #e6f0ff;
border-left-width: 0;
}
&:not(:disabled):not(.is-disabled):active {
border-left-width: 1;
transition: var(--Button-transition);
}
}
& &-input {
flex: 1;
height: 32px;
border-radius: var(--input-default-default-top-left-border-radius) 0 0
var(--input-default-default-bottom-left-border-radius);
max-width: calc(100% - 29px); // 避免表达式内容太长撑开面板
&.is-clearable {
padding-right: 30px; // 避免间隙过大
}
svg {
width: 12px;
height: 12px;
}
}
&-select-style {
> div {
border-radius: var(--Form-select-borderRadius) 0 0
var(--Form-select-borderRadius);
}
}
// 当有提示时底部增加点外边距
&.is-has-tooltip {
margin-bottom: 5px;
}
// 底部提示
.desc-msg {
visibility: hidden;
position: absolute;
bottom: 0;
left: 0;
transform-origin: left top;
transform: translateY(90%) scale(0.8);
font-size: 10px;
max-width: 100%;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
&.info-msg {
color: $editor-active-color; // $default-icon-color;
}
&.error-msg {
visibility: visible; // 错误类提示 固定展示
color: #f33e3e;
transform: translateY(90%) scale(0.9);
}
}
&:hover .desc-msg {
visibility: visible; // 普通提示类信息,hover时展示
}
&-custom-renderer {
width: calc(100% - 35px);
flex: 1 1 auto;
border: none;
padding: 0;
> div {
min-height: 32px;
}
> div,
&:not(.border-wrapper) > div > div {
border-radius: var(--input-default-default-top-left-border-radius) 0 0
var(--input-default-default-bottom-left-border-radius);
}
&.border-wrapper {
padding: 2px 4px;
border: 1px dashed #e8e9eb;
}
}
&-ResultBox {
position: relative;
display: flex;
flex: 1;
overflow: hidden;
border: 1px solid var(--Form-input-borderColor);
border-radius: var(--input-default-default-top-left-border-radius) 0 0
var(--input-default-default-bottom-left-border-radius);
background: var(--Form-input-bg);
font-size: var(--Form-input-fontSize);
padding: 0 8px;
&::placeholder {
color: var(--Form-input-placeholderColor);
}
&:hover {
border-color: var(--Form-input-onHover-borderColor);
}
&-wrapper {
flex: 1 1;
width: 0px; // 通过flex-grow 展开宽度
border-radius: var(--Form-input-borderRadius);
}
&-editor {
& > .CodeMirror {
height: 100%;
color: var(--Form-input-color);
font-family: inherit;
// span[class^='cm-'] {
// color: var(--input-default-default-color);
// }
// 解决上下 pre标签中表达式浮层遮挡问题
.CodeMirror-measure + div {
z-index: inherit !important;
}
pre.CodeMirror-line,
.CodeMirror pre.CodeMirror-line-like {
z-index: initial;
}
.CodeMirror-sizer {
min-height: 30px !important;
}
.CodeMirror-hscrollbar {
display: none !important;
}
.CodeMirror-scrollbar-filler {
display: none !important;
}
.CodeMirror-vscrollbar {
display: none !important;
}
.CodeMirror-scroll {
overflow: hidden !important;
}
.CodeMirror-lines {
line-height: 20px;
padding: 5px 0;
}
}
}
.cm-expression {
background: #007bff;
padding: 0px 5px;
margin: 0 1px;
color: #fff;
font-size: 12px;
border-radius: 4px;
}
}
.input-clear-icon {
position: absolute;
top: 0;
bottom: 0;
right: 8px;
margin: auto;
height: 14px;
fill: var(--Form-input-clearBtn-color);
cursor: pointer;
&:hover {
fill: var(--Form-input-clearBtn-color-onHover);
}
}
&-icon {
top: 0 !important;
font-size: #{px2rem(14px)};
&:not(:last-child) {
margin-right: var(--fontSizeSm);
}
&.is-filled {
fill: var(--primary);
color: var(--primary);
}
}
}

View File

@@ -0,0 +1,63 @@
.ae-GlobalVarPanel {
display: flex;
flex-direction: column;
height: 100%;
> .panel-header {
flex-shrink: 0;
}
}
.ae-GlobalVarManager {
border-top: 1px solid #e8e9eb;
padding: 12px;
flex: 1;
min-height: 0;
overflow: auto;
@include minScrollBar();
& > ul {
list-style: none;
margin: 0;
padding: 0;
}
&-empty {
color: #b4b6ba;
text-align: center;
vertical-align: middle;
}
&-AddBtn {
margin-top: 12px;
// position: sticky;
// bottom: 0;
}
}
.ae-GlobalVarItem {
padding: 0;
display: flex;
height: 34px;
line-height: 32px;
margin: 0 0 12px;
&-info {
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
border-radius: 4px;
padding: 0 10px;
border: 1px solid #e8e9eb;
margin-right: 10px;
}
&-actions {
width: 64px;
flex-shrink: 0;
& > button {
border: 0 !important;
}
}
}

View File

@@ -0,0 +1,35 @@
.ae-GoConfig {
height: 32px;
line-height: 32px;
position: relative;
background-color: #fff;
text-align: center;
font-size: $Editor-right-panel-font-size;
border: 1px solid #e6e6e8;
border-radius: $Editor-borderRadius;
&-trigger {
display: none;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
cursor: pointer;
color: #fff;
background-color: rgba($color: #000000, $alpha: 0.55);
}
&:hover {
border: none;
&.ae-FeatureControlItem-go {
color: transparent;
}
.ae-GoConfig-trigger {
display: block;
border-radius: $Editor-borderRadius;
}
}
}

View File

@@ -0,0 +1,27 @@
.icon-ButtonList {
button {
display: inline-flex;
align-items: center;
justify-content: center;
width: 42px;
background-color: #fff !important;
box-sizing: border-box;
svg {
margin: 0 !important;
padding: 0 !important;
width: 20px;
min-height: 20px;
}
&.is-active {
svg {
fill: $Editor-theme-color;
color: $Editor-theme-color;
}
i {
color: $Editor-theme-color;
}
}
}
}

View File

@@ -0,0 +1,13 @@
.inputFile-apiControl {
margin-top: 30px;
.ApiControl {
margin-bottom: 0;
&-header {
position: absolute;
right: 0;
top: -25px;
}
}
}

View File

@@ -0,0 +1,46 @@
.ae-KeyValMapControl-wrapper {
.ae-KeyValMapControlItem-Main {
width: 100%;
display: flex;
justify-content: space-between;
}
.ae-KeyValMapControlItem-flex {
width: 100%;
}
.ae-KeyValMapControlItem-input {
flex: 1;
margin-right: 10px;
}
.ae-ExtendMore {
position: relative;
.cxd-Container-body {
margin-top: 20px;
}
}
.ae-KeyValMapControlItem-closeBtn {
position: absolute;
top: 0;
right: 0;
font-size: 18px;
color: #151b26;
padding-right: 0.625rem;
z-index: 1;
}
.ae-KeyValMapControlItem-EditLabel {
margin-top: 10px;
}
.ae-KeyValMapControl-footer > * {
width: calc(50% - 0.375rem);
}
.ae-KeyValMapControl-footer > *:first-child {
margin-right: 0.75rem;
}
}

View File

@@ -0,0 +1,184 @@
.ae-NavControl {
&-header {
@include flexBox();
width: 100%;
height: #{px2rem(24px)};
margin-bottom: #{px2rem(12px)};
}
&-content {
@include flexBox(column, flex-start);
margin: 0;
padding: 0;
.ae-OptionControlItem {
display: block;
width: 100%;
border: 1px dashed #999;
padding: 15px;
margin-bottom: 10px;
position: relative;
.ae-closeBtn {
position: absolute;
top: 0;
right: 0;
width: 20px;
height: 20px;
font-size: 18px;
text-align: center;
line-height: 20px;
cursor: pointer;
}
.ae-navControlLinks {
display: flex;
align-items: center;
justify-content: space-between;
height: 40px;
input {
width: 120px;
}
}
}
}
&-placeholder {
display: none;
color: #999;
line-height: #{px2rem(24px)};
text-align: center;
vertical-align: middle;
width: 100%;
padding: #{px2rem(10px)};
}
&-footer {
margin-top: 10px;
}
&-footer > * {
width: calc(50% - #{px2rem(6px)});
&:first-child {
margin-right: px2rem(12px);
}
}
}
.nav-mode-gif {
width: 160px;
height: 120px;
background: url('../static/nav-mode.png');
background-repeat: no-repeat;
background-size: 100%;
margin: 10px auto 0;
}
.ae-BadgeControl {
.cxd-Form-groupColumn:nth-child(1) {
padding-right: 4px;
}
.cxd-Form-groupColumn:nth-child(2) {
padding-left: 4px;
}
.cxd-TextControl.is-focused > .cxd-TextControl-input {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
padding-left: 4px;
}
.cxd-TextControl-addOn:first-child {
border-left-width: 0.0625rem;
}
.cxd-TextControl-input {
padding: 4px;
}
}
// 自定义数据样式
.ae-NavControl-header {
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
align-items: center;
width: 100%;
height: 1.5rem;
margin-bottom: 0.75rem;
}
.ae-NavControl-wrapper {
.nav-links {
&-parent {
width: 100%;
}
&-item {
height: 32px;
margin-bottom: 8px;
padding: 0 10px 0 8px;
border-radius: 2px;
background-color: #f7f7f9;
display: flex;
justify-content: space-between;
align-items: center;
font-family: PingFangSC-Regular;
font-size: 12px;
color: #151b26;
&-icon {
margin: 0 -2px 0 8px;
color: #151b26;
}
&-dragBar {
color: #151b26;
&:hover {
color: #2468f2;
}
}
&-label {
flex: 1;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
color: #151b26;
margin-left: 8px;
}
&-actions {
width: auto;
.icon {
color: #84868c;
font-size: 14px;
cursor: pointer;
&:hover {
color: #2468f2;
}
}
.icon-edit {
margin-left: 12px;
}
.icon-delete {
margin-left: 13px;
}
}
}
&-children {
margin-left: 24px;
}
}
}
.ae-NavControl-footer {
button {
width: 100%;
}
}
.ae-NavControl-dialog {
.cxd-IconPickerControl-valueWrap {
display: flex;
}
}

View File

@@ -0,0 +1,179 @@
.ae-OptionControl {
&-header {
@include flexBox();
width: 100%;
height: #{px2rem(24px)};
margin-bottom: #{px2rem(12px)};
}
&-content {
@include flexBox(column, flex-start);
margin: 0;
padding: 0;
.ae-OptionControlItem {
display: block;
width: 100%;
&-Main {
@include flexBox();
width: 100%;
background: #fff;
padding-bottom: px2rem(12px);
}
&--dragging {
height: 0 !important;
padding: 0;
border-top: 2px solid var(--primary);
overflow: hidden;
background: #e9effd;
}
&-dragBar {
display: inline-flex;
margin-left: 0;
margin-right: var(--gap-sm);
cursor: move;
color: #8c8c8c;
}
&-checkbox {
display: inline-flex;
align-items: center;
line-height: #{px2rem(24px)};
span {
color: #080e1a;
margin-left: #{px2rem(12px)};
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 145px;
}
}
&-input {
flex: 1;
margin: 0;
margin-right: #{px2rem(12px)};
input {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
}
&-dropdown i {
margin-right: 0px;
}
&-EditLabel {
flex: 0 0 2.25rem;
padding-right: 0;
}
&-EditValue {
padding-left: 0;
}
&-closeBtn {
position: absolute;
top: 0;
right: 0;
font-size: 18px;
color: #{$Editor-right-panel-color};
padding-right: px2rem(10px);
&:hover {
color: #{$Editor-theme};
}
}
.ae-ExtendMore {
padding-right: px2rem(30px);
}
&-action-delete {
color: #d4d6d9;
padding: 0px;
}
}
}
&-placeholder {
display: none;
color: #999;
line-height: #{px2rem(24px)};
text-align: center;
vertical-align: middle;
width: 100%;
padding: #{px2rem(10px)};
}
&-footer > * {
// @include flexBox(row, flex-end);
// // background: #f2f7f3;
// padding: #{px2rem(5px)};
// border-bottom-right-radius: $Editor-borderRadius;
// border-bottom-left-radius: $Editor-borderRadius;
// border-top: 1px solid #f2f7f3;
// box-shadow: 0 0 5px rgb(8 14 26 / 6%);
// clip-path: inset(-5px 0px 0px 0px);
width: calc(50% - #{px2rem(6px)});
&:first-child {
margin-right: px2rem(12px);
}
}
}
.ae-OptionControl-PopoverEdit {
@include flexBox(column, space-between, flex-start);
padding: #{px2rem(15px)} #{px2rem(20px)};
border: none;
width: 300px;
header {
@include flexBox();
width: 100%;
height: #{px2rem(24px)};
margin-bottom: #{px2rem(10px)};
.ae-OptionControl-PopoverEdit-title {
opacity: 0.95;
font-size: var(--fontSizeMd);
color: #080e1a;
line-height: #{px2rem(24px)};
font-weight: bold;
}
.ae-OptionControl-PopoverEdit-close {
float: right;
color: var(--text--muted-color);
line-height: inherit;
text-decoration: none;
vertical-align: middle;
svg {
width: #{px2rem(12px)};
height: #{px2rem(12px)};
fill: var(--text--muted-color);
}
&:not(.is-disabled) {
cursor: pointer;
&:hover {
text-decoration: none;
color: var(--text-color);
svg {
fill: var(--text-color);
}
}
}
}
}
}

View File

@@ -0,0 +1,75 @@
// 状态组件页面设计器
.ae-Status-label {
& > span {
display: flex;
align-items: center;
}
&-tip-icon {
margin-left: 0.25rem;
line-height: 14px;
display: inline-block;
cursor: pointer;
.icon {
width: 14px;
height: 14px;
fill: #84868c;
}
}
}
.ae-Status-default-icon {
&-tooltip {
max-width: none;
}
&-tip {
font-size: 12px;
}
}
.ae-Status-control {
.cxd-Combo-itemInner {
.cxd-Form-row {
margin-right: 0;
.cxd-Form-col {
padding-left: 2px;
padding-right: 2px;
&:first-child {
flex-grow: 0;
min-width: 55px;
// 新版图标选择 占位缩小处理
.cxd-IconSelectControl {
&-input {
padding-left: 6px;
}
&-clear {
right: 4px;
}
}
// iconfont 占位缩小处理
.cxd-IconPickerControl {
&-value {
width: 12px;
overflow: hidden;
}
&-clear {
position: absolute;
right: -5px;
top: 0;
}
}
}
&:last-child {
flex-grow: 0;
}
.cxd-IconSelectControl-input-icon-id {
display: none;
}
.Theme-ColorPicker-label-out {
width: 1.35rem;
height: 1.35rem;
position: relative;
top: 0.2rem;
}
}
}
}
}

View File

@@ -0,0 +1,124 @@
.ae-SwitchMore {
flex-grow: 1;
&-switch {
@include flexBox();
justify-content: flex-end;
height: px2rem(30px);
div {
@include flexBox(row, flex-end);
background-color: #fff !important;
flex: 1;
hr {
display: inline-block;
border: 0;
margin: 0;
border-left: 1px solid #e6e6e8;
height: #{px2rem(16px)};
vertical-align: middle;
margin: 0 #{px2rem(12px)};
}
svg.icon {
margin-bottom: #{px2rem(-2px)};
}
.ae-SwitchMore-icon {
fill: var(--primary);
path {
fill: var(--primary);
}
}
}
}
.cxd-DropDown,
.cxd-DropDown > .cxd-Button {
width: 100%;
}
.action-btn {
padding: 0;
}
.open-btn {
transition: transform var(--animation-duration);
color: #b8babf;
&.opening {
transform: rotate(180deg);
}
}
&-popover {
padding: #{px2rem(12px)};
border: none;
min-width: px2rem(300px);
max-width: px2rem(640px);
header {
@include flexBox(row, flex-end);
width: 100%;
height: #{px2rem(24px)};
margin-bottom: #{px2rem(10px)};
}
.ae-SwitchMore-title {
opacity: 0.95;
font-size: var(--fontSizeMd);
color: #080e1a;
line-height: #{px2rem(24px)};
font-weight: bold;
width: 100%;
margin: 0;
}
.ae-SwitchMore-close {
float: right;
color: var(--text--muted-color);
line-height: inherit;
text-decoration: none;
vertical-align: middle;
svg {
width: #{px2rem(12px)};
height: #{px2rem(12px)};
fill: var(--text--muted-color);
}
&:not(.is-disabled) {
cursor: pointer;
&:hover {
text-decoration: none;
color: var(--text-color);
svg {
fill: var(--text-color);
}
}
}
}
}
&-extend {
position: relative;
.ae-SwitchMore {
&-switch {
position: absolute;
top: px2rem(-32px);
right: 0;
}
&-content {
padding-top: px2rem(12px);
& > div {
@include extend-more();
}
}
}
}
}

View File

@@ -0,0 +1,13 @@
/**
* @file table-column-width-control.scss
* @desc 表格列宽控件
*/
.ae-columnWidthControl {
&-header {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: baseline;
}
}

View File

@@ -0,0 +1,229 @@
.ae-TextareaFormulaControl {
position: relative;
&-input {
textarea {
resize: none;
}
}
.ae-TextareaResultBox {
position: relative;
width: 100%;
height: 100%;
display: block;
border: 1px solid var(--Form-input-borderColor);
border-radius: var(--Form-input-borderRadius);
background: var(--Form-input-bg);
font-size: var(--Form-input-fontSize);
padding-bottom: 26px;
&::placeholder {
color: var(--Form-input-placeholderColor);
}
&:hover {
border-color: var(--Form-input-onHover-borderColor);
}
&-editor {
height: 100%;
border-radius: var(--Form-input-borderRadius);
overflow: auto;
padding-left: 8px;
& > .CodeMirror {
height: 100%;
font-family: inherit;
// span[class^='cm-'] {
// color: var(--input-default-default-color);
// }
// 解决上下 pre标签中表达式浮层遮挡问题
.CodeMirror-measure + div {
z-index: inherit !important;
}
pre.CodeMirror-line,
.CodeMirror pre.CodeMirror-line-like {
z-index: initial;
}
}
}
&-placeholder {
position: absolute;
line-height: 28px;
top: 0;
left: 13px;
font-size: 12px;
color: var(--text--muted-color);
pointer-events: none;
}
&-footer {
position: absolute;
width: 100%;
background: #f7f7f9;
bottom: 0px;
height: 26px;
margin: 0;
border-radius: 0 0 4px 4px;
list-style: none;
display: flex;
flex-direction: row-reverse;
align-items: center;
> li {
margin-right: 10px;
cursor: pointer;
&.is-loading {
display: flex;
cursor: unset;
}
}
&--fullscreen {
> a {
font-size: 12px;
}
}
&-fxIcon {
> a {
font-size: 14px;
}
}
}
&-overlay {
position: absolute;
top: 1px;
left: 1px;
width: calc(100% - 4px);
height: calc(100% - 4px);
cursor: pointer;
}
}
&.is-fullscreen {
margin: 0 !important;
position: fixed !important;
top: 0;
left: 0;
bottom: 0;
right: 0;
z-index: 2147483630 !important;
width: auto !important;
height: auto !important;
.ae-TextareaResultBox {
height: 100% !important;
&-editor {
& > .CodeMirror {
height: 100%;
padding: 10px 10px 48px;
.CodeMirror-vscrollbar {
margin-bottom: 48px;
}
}
}
&-footer {
height: 48px;
> li {
margin-right: 20px;
}
&-fullscreen {
> a {
font-size: 18px;
}
}
&-fxIcon {
> a {
font-size: 20px;
}
}
}
&-placeholder {
padding: 10px;
}
}
}
}
.cm-expression {
position: relative;
display: inline-block;
border-radius: 4px;
padding: 0 5px;
margin: 0 1px 1px;
background: var(--button-primary-default-bg-color);
&-text {
display: inline-block;
position: relative;
color: #fff !important;
cursor: pointer;
max-width: 80px;
min-width: 10px;
min-height: 18px;
overflow-x: hidden;
text-overflow: ellipsis;
white-space: nowrap;
vertical-align: middle;
line-height: 16px;
&:hover {
background: var(--button-primary-hover-bg-color);
& ~ .cm-expression-popover {
display: block;
}
}
}
&-close {
font-size: 12px;
color: white;
cursor: pointer;
margin-left: 4px;
}
&-popover {
position: absolute;
display: none;
left: 0;
bottom: -30px;
transform: translate(calc(24px - 50%));
font-size: 12px;
width: max-content;
color: #fff;
border-radius: 4px;
padding: 2px 8px;
background: var(--Tooltip-bg--dark);
border: none;
box-shadow: var(--Tooltip-boxShadow--dark);
z-index: 10;
&-arrow {
position: absolute;
display: block;
width: var(--Tooltip-arrow-width);
height: var(--Tooltip-arrow-height);
margin-left: calc(var(--Tooltip-arrow-width) * -1 / 2);
left: 50%;
top: calc(var(--Tooltip-arrow-height) * -1);
&::before,
&::after {
position: absolute;
display: block;
content: '';
border-color: transparent;
border-style: solid;
border-width: 0 calc(var(--Tooltip-arrow-width) / 2)
var(--Tooltip-arrow-height) calc(var(--Tooltip-arrow-width) / 2);
}
&::before {
border-width: 0;
}
&::after {
border-bottom-color: var(--Tooltip-arrow-color--dark);
}
}
}
}

View File

@@ -0,0 +1,83 @@
.ae-TimelineItemControl {
&-header {
@include flexBox();
width: 100%;
height: #{px2rem(24px)};
margin-bottom: #{px2rem(12px)};
}
&-content {
@include flexBox(column, flex-start);
margin: 0;
padding: 0;
.ae-TimelineItemControlItem {
display: block;
width: 100%;
&-input-title {
flex: 1;
margin-left: #{px2rem(20px)};
margin-right: #{px2rem(44px)};
input {
width: 100%;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
}
&-input {
flex: 1;
margin: 0;
margin-right: #{px2rem(12px)};
}
&-Main {
@include flexBox();
width: 100%;
background: #fff;
padding-bottom: px2rem(12px);
}
&--dragging {
height: 0 !important;
padding: 0;
border-top: 2px solid var(--primary);
overflow: hidden;
background: #e9effd;
}
&-dragBar {
display: inline-flex;
margin-left: 0;
margin-right: var(--gap-sm);
cursor: move;
color: #8c8c8c;
}
&-dropdown i {
margin-right: 0px;
}
}
.ae-TimelineItemControlItem-inputDate {
margin-bottom: 0;
}
}
&-border {
background-color: #e5e5e5;
width: 100%;
height: 1px;
margin-top: 12px;
margin-bottom: 12px;
}
&-footer > * {
width: calc(50% - #{px2rem(6px)});
&:first-child {
margin-right: px2rem(12px);
}
}
}

View File

@@ -0,0 +1,160 @@
.ae-TplFormulaControl {
position: relative;
width: 100%;
display: flex;
height: var(--input-size-default-height);
.ae-TplResultBox {
position: relative;
display: flex;
flex: 1;
overflow: hidden;
border: 1px solid var(--Form-input-borderColor);
border-radius: var(--input-default-default-top-left-border-radius) 0 0
var(--input-default-default-bottom-left-border-radius);
background: var(--Form-input-bg);
font-size: var(--Form-input-fontSize);
padding: 0 8px;
.input-clear-icon {
position: absolute;
top: 0;
bottom: 0;
right: 8px;
margin: auto;
height: 14px;
fill: var(--Form-input-clearBtn-color);
cursor: pointer;
&:hover {
fill: var(--Form-input-clearBtn-color-onHover);
}
}
&::placeholder {
color: var(--Form-input-placeholderColor);
}
&:hover {
border-color: var(--Form-input-onHover-borderColor);
}
&-editor {
flex: 1 1;
width: 0px; // 通过flex-grow 展开宽度
border-radius: var(--Form-input-borderRadius);
& > .CodeMirror {
height: 100%;
color: var(--Form-input-color);
font-family: inherit;
// span[class^='cm-'] {
// color: var(--input-default-default-color);
// }
// 解决上下 pre标签中表达式浮层遮挡问题
.CodeMirror-measure + div {
z-index: inherit !important;
}
pre.CodeMirror-line,
.CodeMirror pre.CodeMirror-line-like {
z-index: initial;
}
.CodeMirror-sizer {
min-height: 30px !important;
}
.CodeMirror-hscrollbar {
display: none !important;
}
.CodeMirror-scrollbar-filler {
display: none !important;
}
.CodeMirror-vscrollbar {
display: none !important;
}
.CodeMirror-scroll {
overflow: hidden !important;
}
.CodeMirror-lines {
line-height: 20px;
padding: 5px 0;
}
}
}
.cm-expression {
background: #007bff;
padding: 0px 5px;
margin: 0 1px;
color: #fff;
font-size: 12px;
border-radius: 4px;
}
}
&-buttonWrapper {
height: auto;
}
&-button,
&-buttonWrapper-button {
height: 100%;
background-color: #f7f7f9;
padding: 4px 8px;
border-radius: 0 var(--input-default-default-top-left-border-radius)
var(--input-default-default-bottom-left-border-radius) 0;
border-left: 0;
&:not(:disabled):not(.is-disabled) {
&:hover,
&:hover:active {
border-color: #e6f0ff;
background-color: #e6f0ff;
border-left-width: 0;
}
}
}
&-icon {
font-size: #{px2rem(14px)};
&:not(:last-child) {
margin-right: var(--fontSizeSm);
}
&.is-filled {
fill: var(--primary);
color: var(--primary);
}
}
&-placeholder {
position: absolute;
line-height: 30px;
top: 0;
left: 14px;
font-size: 12px;
color: var(--text--muted-color);
pointer-events: none;
}
&-tooltip {
position: absolute;
top: 6px;
height: 18px;
z-index: 1;
cursor: pointer;
}
&.clearable {
.ae-TplResultBox {
padding-right: 28px;
}
}
.cm-expression-text {
max-width: 48px;
}
}

View File

@@ -0,0 +1,67 @@
.ae-TreeOptionControl {
&-header {
@include flexBox();
width: 100%;
height: #{px2rem(24px)};
margin-bottom: #{px2rem(12px)};
}
&-footer > * {
width: 100%;
}
}
.ae-TreeOptionControl-Modal {
.ae-TreeOptionControl-content {
margin: 0;
padding: 0;
}
.ae-TreeOptionControlItem {
display: flex;
justify-content: space-between;
align-items: center;
&:not(:first-child) {
margin-top: var(--gap-sm);
}
&-parent {
margin-top: var(--gap-sm);
}
&-son {
margin-top: var(--gap-sm);
padding-left: #{px2rem(32px)};
}
&-dragging {
height: 0 !important;
padding: 0;
border-top: 2px solid var(--primary);
overflow: hidden;
background: #e9effd;
}
&-dragBar {
display: inline-flex;
margin-left: 0;
margin-right: var(--gap-sm);
cursor: move;
color: #8c8c8c;
}
// &-btns {
// }
&-input-label {
flex: 1;
margin-right: var(--gap-sm);
margin-bottom: 0;
}
&-input-value {
margin-right: var(--gap-sm);
}
&-dropdown {
margin-right: var(--gap-sm);
svg {
font-size: var(--Button--sm-fontSize);
}
.m-r-xs {
margin-right: 2px;
font-size: #{px2rem(12px)};
}
}
}
}

View File

@@ -0,0 +1,108 @@
.ae-ValidationControl {
position: relative;
min-height: 1px; // form-item空内容时有个margin,会导致collapse上的增加按钮偏移
&-dropdown {
@include flexBox(row, space-between);
position: absolute;
top: #{px2rem(-45px)};
right: #{px2rem(20px)};
height: $category-2-height;
&-btn {
color: #141a25;
background: transparent !important;
border: none !important;
}
}
header {
@include flexBox();
width: 100%;
height: #{px2rem(24px)};
margin-bottom: #{px2rem(10px)};
}
&-item {
@include flexBox(column, flex-start, flex-start);
width: 100%;
padding: 0;
&:not(:last-child) {
margin-bottom: #{px2rem(10px)};
}
section {
width: 100%;
}
.ae-ValidationControl-item-control {
@include flexBox(row, space-between);
margin-bottom: #{px2rem(10px)};
&.is-active {
margin-bottom: #{px2rem(5px)};
}
& > div {
@include flexBox(row, flex-end);
hr {
border: 0;
margin: 0;
border-left: 1px solid #e6e6e8;
height: #{px2rem(16px)};
vertical-align: middle;
margin: 0 #{px2rem(8px)};
}
}
.ae-ValidationControl-item-actions {
@include flexBox(row, flex-end);
.ae-ValidationControl-item-action {
position: relative;
top: #{px2rem(2px)};
right: 5px;
i {
color: #83868c;
font-size: #{px2rem(16px)};
&:hover {
color: var(--primary);
}
}
&:not(:last-child) {
margin-right: #{px2rem(10px)};
}
&:hover {
& > svg,
& > svg path {
fill: var(--primary);
}
}
& > svg,
& > svg path {
fill: #83868c;
}
}
}
}
.ae-ValidationControl-item-input {
@include flexBox(column, flex-start, flex-start);
@include panel-group-bg();
margin-top: px2rem(12px);
}
}
}
.ae-ValidationControl-label-code {
background-color: #666;
padding: 0 4px;
border-radius: 2px;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,105 @@
.ae-border {
&-items {
width: 88px;
height: 88px;
flex-shrink: 0;
margin-right: 10px;
position: relative;
}
&-radius {
.ap-border-items {
height: 60px;
}
}
&-item {
position: absolute;
padding: 5px;
border-radius: 2px;
text-align: center;
cursor: pointer;
display: inline-block;
line-height: 1;
&.active {
background: linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.2));
}
&.left {
left: 0;
top: 50%;
transform: translateY(-11px);
}
&.top-left {
left: 0;
top: 0;
}
&.right {
right: 0;
top: 50%;
transform: translateY(-11px);
}
&.top-right {
right: 0;
top: 0;
}
&.top {
left: 50%;
top: 0;
transform: translateX(-11px);
}
&.bottom {
left: 50%;
bottom: 0;
transform: translateX(-11px);
}
&.bottom-left {
left: 0;
bottom: 0;
}
&.bottom-right {
bottom: 0;
right: 0;
}
&.all {
left: 50%;
top: 50%;
transform: translateX(-11px) translateY(-11px);
}
}
&-settings {
label {
flex-shrink: 0;
margin-right: 8px;
color: var(--Form-item-color);
}
.flex {
margin-bottom: 6px;
}
.ae-border-input {
min-height: 28px;
width: 100%;
}
}
&-colorpicker > div {
padding-right: 3px;
font-size: 12px;
> span {
margin-left: -4px;
margin-right: 5px;
}
}
}

View File

@@ -0,0 +1,100 @@
.ae-BoxModel {
overflow: hidden;
background-color: #e0efff;
padding: 18px;
position: relative;
&-inner {
background-color: #fff;
width: 100%;
height: 100%;
padding: 2px;
min-height: 20px;
}
&-input {
position: absolute;
text-align: center;
padding: 0;
font-size: 12px;
border: none;
background: none;
transform: scale(0.8);
color: rgba(0, 0, 0, 0.85);
-webkit-appearance: none;
&:focus {
outline: none;
}
&.left {
left: -6px;
top: 0;
height: 100%;
width: 28px;
}
&.right {
right: -6px;
top: 0;
height: 100%;
width: 28px;
}
&.top {
top: 2px;
left: 0;
right: 0;
height: 14px;
width: 100%;
}
&.bottom {
bottom: 0;
left: 0;
right: 0;
height: 14px;
width: 100%;
}
}
&-title {
opacity: 0.6;
font-size: 8px;
color: #919eab;
transform: scale(0.7);
position: absolute;
left: 8px;
}
&-line {
width: 2px;
height: 50px;
background-color: #fff;
position: absolute;
&.lt {
transform: rotate(-45deg);
top: -24px;
left: 0;
}
&.lb {
transform: rotate(45deg);
bottom: -24px;
left: 0;
}
&.rt {
transform: rotate(45deg);
top: -24px;
right: 0;
}
&.rb {
transform: rotate(-45deg);
bottom: -24px;
right: 0;
}
}
}

View File

@@ -0,0 +1,12 @@
.ae-BoxShadow {
&-group {
> div {
align-items: center;
}
}
&-unit {
flex: 0.3;
padding-top: #{px2rem(16px)};
padding-bottom: #{px2rem(16px)};
}
}

View File

@@ -0,0 +1,30 @@
.ColCount {
display: flex;
background-color: #f7f7f9;
padding: 2px;
border-radius: 4px;
&-item {
text-align: center;
line-height: 30px;
flex: 1;
min-width: 0;
height: 30px;
cursor: pointer;
&:not(.is-disabled):hover {
background: #fff;
color: #2468f2;
}
}
.is-active {
background: #fff;
color: #2468f2;
border-radius: 4px;
}
.is-disabled {
cursor: not-allowed;
color: #ccc;
}
}
.LabelAlign {
width: 100%;
}

View File

@@ -0,0 +1,28 @@
.ColSize {
display: flex;
background-color: #f7f7f9;
padding: 2px;
border-radius: 4px;
&-item {
text-align: center;
line-height: 28px;
flex: 1;
min-width: 0;
width: 32px;
height: 28px;
cursor: pointer;
&:not(.is-disabled):hover {
background: #fff;
color: #2468f2;
}
}
.is-active {
background: #fff;
color: #2468f2;
border-radius: 4px;
}
.is-disabled {
cursor: not-allowed;
color: #ccc;
}
}

View File

@@ -0,0 +1,29 @@
.ae-FlexLayout {
&-wrap {
display: grid;
grid-row-gap: 10px;
grid-column-gap: 10px;
grid-template-columns: repeat(4, auto);
margin-bottom: 10px;
}
&-item {
display: flex;
flex-direction: row;
gap: 2px;
height: 36px;
border: 1px solid rgba(0, 0, 0, 0.2);
padding: 4px;
border-radius: 4px;
cursor: pointer;
&.active {
border-color: #528eff;
}
}
&-itemColumn {
height: 100%;
background-color: #ccc;
}
}

View File

@@ -0,0 +1,28 @@
.ae-Font {
&-group-lhs {
border-radius: #{px2rem(5px)} 0 0 #{px2rem(5px)};
}
&-group-rhs {
border-radius: 0 #{px2rem(5px)} #{px2rem(5px)} 0;
}
&-group-middle {
border-radius: 0;
}
&-relative-left {
position: relative;
left: 1px;
}
&-relative-right {
position: relative;
right: 1px;
}
&-relative-right-2 {
position: relative;
right: 2px;
}
}

View File

@@ -0,0 +1,83 @@
.ae-SingleThemeCssCode {
position: relative;
border: 1px solid #e8e9eb;
border-radius: var(--input-default-default-top-left-border-radius)
var(--input-default-default-top-right-border-radius)
var(--input-default-default-bottom-right-border-radius)
var(--input-default-default-bottom-left-border-radius);
&-label {
margin-bottom: px2rem(10px);
color: #5c5f66;
font-size: 12px;
}
&-header,
&-footer {
padding: 0 4px;
}
&-content {
height: 120px;
}
&-button {
position: absolute;
top: 4px;
right: 12px;
z-index: 100;
}
&-icon {
cursor: pointer;
color: #5c5f66;
&:hover {
color: #151b26;
}
}
}
.ae-SingleThemeCssCode-custom-editor {
.suggest-widget {
width: auto !important;
left: 16px !important;
right: 0 !important;
.monaco-sash:first-child {
display: none;
}
}
}
.ae-SingleThemeCssCode-panel {
height: auto;
width: px2rem(460px);
padding: px2rem(16px);
position: relative;
&-title {
font-size: 14px;
margin-bottom: px2rem(16px);
}
&-close {
position: absolute;
top: px2rem(14px);
right: px2rem(16px);
button {
height: px2rem(16px);
padding: 0;
margin: 0;
}
}
&-content {
height: px2rem(500px);
width: 100%;
border: 1px solid #e8e9eb;
.ae-SingleThemeCssCode-content {
height: px2rem(454px);
}
}
}

View File

@@ -0,0 +1,40 @@
.ae-style-size {
&-wrapper {
@include flexBox();
}
&-slider {
flex: 5;
}
&-text {
flex: 3;
height: #{px2rem(32px)};
border-top-left-radius: #{$Editor-borderRadius} !important;
border-bottom-left-radius: #{$Editor-borderRadius} !important;
}
&-unit {
flex: 1.3;
& > div {
text-align: center;
padding: #{px2rem(5px)};
background: #f5f5f5 !important;
&:first-child {
font-weight: bold;
}
span {
margin-right: 0;
position: relative;
top: 1px;
> svg {
width: #{px2rem(8px)};
}
}
}
}
}

View File

@@ -0,0 +1,22 @@
/**
* @file 样式控件通用属性
*/
.ae-selection-code {
width: 100%;
> span {
@include flexBox();
display: flex !important;
}
code {
display: inline-block;
}
}
.ae-Display {
&-group {
@include panel-group-bg();
}
}

View File

@@ -0,0 +1,113 @@
.ThemeCssCode {
position: relative;
&-button {
position: absolute;
top: 4px;
right: 12px;
z-index: 100;
}
&-icon {
cursor: pointer;
color: #5c5f66;
&:hover {
color: #151b26;
}
}
.is-group {
overflow: auto;
}
}
.icon-theme-css {
margin-right: 10px;
}
.ThemeCssCode-editor {
height: auto;
width: px2rem(460px);
padding: px2rem(16px);
position: relative;
&-title {
font-size: 14px;
margin-bottom: px2rem(16px);
}
&-close {
position: absolute;
top: px2rem(14px);
right: px2rem(16px);
button {
height: px2rem(16px);
padding: 0;
margin: 0;
}
}
&-content {
height: px2rem(500px);
width: 100%;
&-header {
display: flex;
margin-bottom: px2rem(10px);
border-bottom: 1px solid #e8e9eb;
&-title {
margin-right: px2rem(30px);
cursor: pointer;
padding-bottom: px2rem(10px);
}
&-title--active {
color: #2468f2;
border-bottom: 2px solid #2468f2;
}
}
&-main {
overflow: auto;
height: px2rem(460px);
}
&-body--hidden {
display: none;
}
&-body {
margin-bottom: px2rem(10px);
&-title {
margin-bottom: px2rem(10px);
margin-left: px2rem(16px);
font-size: 12px;
}
&-editor {
height: 200px;
margin-bottom: px2rem(10px);
border-bottom: 1px solid #e8e9eb;
}
}
}
&-wrap {
border: 1px solid #e8e9eb;
.cxd-MonacoEditor-placeholder {
left: 1rem;
}
}
}
.editorPanel-inner {
.Theme-FontEditor {
.Theme-Wrapper-header-left {
font-weight: 400;
color: #5c5f66;
}
}
.Theme-ShadowEditor {
.Theme-Wrapper-header-left {
font-weight: 400;
color: #5c5f66;
}
}
}
.cxd-ThemeCssCode-custom-editor {
.suggest-widget {
width: auto !important;
left: 16px !important;
right: 0 !important;
.monaco-sash:first-child {
display: none;
}
}
}

View File

@@ -0,0 +1,64 @@
/**
* 兼容 1.x 里面的注册渲染器的方法。
*/
import {EditorManager, registerEditorPlugin} from './manager';
import {BasePlugin} from './plugin';
/**
* 旧版本注册渲染器编辑器的方法。
*
* @deprecated
* @param rendererName
* @param config
*/
export function RendererEditor(
rendererName: string,
config: {
name: string;
description?: string;
type?: string;
previewSchema?: any;
scaffold?: any;
}
) {
return function (Klass: new (manager: EditorManager) => BasicEditor) {
registerEditorPlugin(
class ComposedPlugin extends Klass {
rendererName: string;
name: string;
description?: string;
scaffold?: any;
previewSchema?: any;
panelTitle?: string;
panelControls?: Array<any>;
constructor(manager: EditorManager) {
super(manager);
this.rendererName = rendererName;
this.name = this.tipName || config.name;
this.description = config.description;
this.scaffold = config.scaffold || {type: config.type};
this.previewSchema = config.previewSchema || this.scaffold;
if (this.settingsSchema) {
this.panelTitle = this.settingsSchema.title;
this.panelControls = this.settingsSchema.body;
}
}
}
);
};
}
/**
* 为了兼容旧版的注册方法
* @deprecated
*/
export class BasicEditor extends BasePlugin {
tipName?: string;
settingsSchema?: {
title: string;
body: Array<any>;
};
}

View File

@@ -0,0 +1,45 @@
/**
* @file AsyncLayer.tsx
* @desc 异步加载层
*/
import React from 'react';
import {Spinner} from 'amis';
export interface AsyncLayerOptions {
fallback?: React.ReactNode;
}
export const makeAsyncLayer = (
schemaBuilderFn: () => Promise<any>,
options?: AsyncLayerOptions
) => {
const {fallback} = options || {};
const LazyComponent = React.lazy(async () => {
const schemaFormRender = await schemaBuilderFn();
return {
default: (...props: any[]) => <>{schemaFormRender(...props)}</>
};
});
return (props: any) => (
<React.Suspense
fallback={
fallback && React.isValidElement(fallback) ? (
fallback
) : (
<Spinner
show
overlay
size="sm"
tip="配置面板加载中"
tipPlacement="bottom"
className="flex"
/>
)
}
>
<LazyComponent {...props} />
</React.Suspense>
);
};

View File

@@ -0,0 +1,273 @@
import React from 'react';
import {reaction} from 'mobx';
import {Icon, resizeSensor} from 'amis';
import {EditorStoreType} from '../store/editor';
import {EditorManager} from '../manager';
import {observer} from 'mobx-react';
import {EditorNodeType} from '../store/node';
import {autobind} from '../util';
export interface BreadcrumbProps {
store: EditorStoreType;
manager: EditorManager;
}
interface BreadcrumbStates {
showLeftScrollBtn: boolean;
showRightScrollBtn: boolean;
}
@observer
export default class Breadcrumb extends React.Component<
BreadcrumbProps,
BreadcrumbStates
> {
readonly breadcrumbRef = React.createRef<HTMLDivElement>();
readonly bcnContentRef = React.createRef<HTMLDivElement>();
currentBreadcrumb: HTMLElement; // 记录当前面包屑元素
unReaction: () => void;
unSensor?: () => void;
constructor(props: any) {
super(props);
this.state = {
showLeftScrollBtn: false,
showRightScrollBtn: false
};
this.unReaction = reaction(
() => this.props.store.bcn,
() => {
// 内容变动时,自动触发一次计算
this.refreshHandleScroll(true);
}
);
}
componentDidMount() {
const scrollElem = this.getCurBreadcrumb();
const breadcrumbContainer = this.getBreadcrumbContainer();
if (!scrollElem || !breadcrumbContainer) {
return;
}
this.unSensor = resizeSensor(breadcrumbContainer, () => {
this.refreshHandleScroll();
});
}
componentWillUnmount() {
this.unReaction();
if (this.unSensor) {
this.unSensor();
delete this.unSensor;
}
}
@autobind
refreshHandleScroll(resetScroll?: boolean) {
setTimeout(() => {
this.HandleScroll(resetScroll);
}, 0);
}
@autobind
getCurBreadcrumb() {
return this.bcnContentRef.current;
}
@autobind
getBreadcrumbContainer() {
return this.breadcrumbRef.current;
}
@autobind
getScrollLeft(): string {
const curBreadcrumb = this.getCurBreadcrumb();
return curBreadcrumb ? curBreadcrumb.style.left : '0';
}
@autobind
toNumber(pxStr: string): number {
let curScrollLeft = 0;
if (!pxStr) {
return curScrollLeft;
}
return Number.parseInt(pxStr);
}
@autobind
HandleScroll(resetScroll?: boolean) {
const scrollElem = this.getCurBreadcrumb();
const scrollContainer = this.getBreadcrumbContainer();
if (!scrollElem || !scrollContainer) {
return;
}
const scrollLeft = this.toNumber(this.getScrollLeft());
const maxScrollLeft = scrollElem.offsetWidth - scrollContainer.offsetWidth;
if (resetScroll) {
scrollElem.style.left = '0';
}
this.setState({
showLeftScrollBtn: scrollLeft < 0,
showRightScrollBtn: scrollLeft > -maxScrollLeft
});
}
@autobind
handleScrollToLeft() {
// 向左滚动:看左侧内容,left + 50, 滚动内容需要右移
const scrollElem = this.getCurBreadcrumb();
if (!scrollElem) {
return;
}
const scrollLeft = this.toNumber(this.getScrollLeft());
if (scrollLeft >= -50 && scrollLeft < 0) {
scrollElem.style.left = '0';
this.refreshHandleScroll();
} else if (scrollLeft < -50) {
scrollElem.style.left = `${scrollLeft + 50}px`;
this.refreshHandleScroll();
}
}
@autobind
handleScrollToRight() {
// 向左滚动:看左侧内容,left - 50, 滚动内容需要左移
const scrollElem = this.getCurBreadcrumb();
const scrollContainer = this.getBreadcrumbContainer();
if (!scrollElem || !scrollContainer) {
return;
}
const scrollLeft = this.toNumber(this.getScrollLeft());
const maxScrollLeft =
scrollElem.offsetWidth - scrollContainer.offsetWidth + 32;
if (scrollLeft - 50 > -maxScrollLeft) {
scrollElem.style.left = `${scrollLeft - 50}px`;
} else {
scrollElem.style.left = `-${maxScrollLeft}px`;
}
this.refreshHandleScroll();
}
@autobind
handleClick(e: React.MouseEvent<HTMLAnchorElement>) {
const dom = e.currentTarget;
const id = dom.getAttribute('data-node-id')!;
const region = dom.getAttribute('data-node-region')!;
const store = this.props.store;
const manager = this.props.manager;
const node = store.getNodeById(id);
if (node?.info?.editable === false) {
return;
}
if (region) {
// 点击容器类型自动弹出「组件插入面板」有点干扰用户操作
// manager.showInsertPanel(region, id);
/** 特殊区域允许点击事件 */
store.setActiveId(id, region);
} else {
store.setActiveId(id);
}
}
@autobind
handleMouseEnter(e: React.MouseEvent<HTMLAnchorElement>) {
const dom = e.currentTarget;
const id = dom.getAttribute('data-node-id')!;
const region = dom.getAttribute('data-node-region')!;
const store = this.props.store;
store.setHoverId(id, region);
}
render() {
const {store} = this.props;
const {showLeftScrollBtn, showRightScrollBtn} = this.state;
const bcn = store.bcn;
return (
<div className="ae-Breadcrumb" ref={this.breadcrumbRef}>
{showLeftScrollBtn && (
<div
className="ae-Breadcrumb-scrollLeft-btn"
onClick={this.handleScrollToLeft}
>
<Icon icon="editor-double-arrow" className="icon" />
</div>
)}
<div className="ae-Breadcrumb-content" ref={this.bcnContentRef}>
{bcn.length ? (
<ul>
{bcn.map((item, index) => {
const nearby: Array<EditorNodeType> = (
item.parent as EditorNodeType
)?.uniqueChildren;
const region =
item.region ||
item.childRegions.find((i: any) => i.region)?.region;
return (
<li key={index}>
<span
data-node-id={item.id}
data-node-region={region}
onClick={this.handleClick}
onMouseEnter={this.handleMouseEnter}
>
{item.label}
</span>
{nearby?.length > 1 ? (
<ul className="hoverShowScrollBar">
{nearby.map(child => (
<li key={`${child.id}-${child.region}`}>
<span
data-node-id={child.id}
data-node-region={child.region}
onClick={this.handleClick}
onMouseEnter={this.handleMouseEnter}
className={
child.id === item.id &&
child.region === item.region
? 'is-active'
: ''
}
>
{child.label}
</span>
</li>
))}
</ul>
) : null}
</li>
);
})}
</ul>
) : null}
</div>
{showRightScrollBtn && (
<div
className="ae-Breadcrumb-scrollRight-btn"
onClick={this.handleScrollToRight}
>
<Icon icon="editor-double-arrow" className="icon" />
</div>
)}
</div>
);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,79 @@
import {findDOMNode} from 'react-dom';
import {JSONPipeOut} from '../util';
import React from 'react';
import {NodeWrapper} from './NodeWrapper';
export class CommonConfigWrapper extends NodeWrapper {
// 销毁的时候要把加的 aeEditor-common-config 干掉
componentWillUnmount() {
const root = findDOMNode(this) as HTMLElement;
if (!root) {
return;
}
const info = this.props.$$editor;
let dom = info.wrapperResolve ? info.wrapperResolve(root) : root;
(Array.isArray(dom) ? dom : dom ? [dom] : []).forEach(dom => {
dom.classList.remove('ae-Editor-common-config');
});
}
markDom(id: string) {
const root = findDOMNode(this) as HTMLElement;
if (!root || !id) {
return;
}
const info = this.props.$$editor;
let dom = info.wrapperResolve ? info.wrapperResolve(root) : root;
const schema = this.props.$$commonSchema;
schema &&
(Array.isArray(dom) ? dom : dom ? [dom] : []).forEach(dom => {
dom.setAttribute('data-editor-id', id);
dom.classList.add('ae-Editor-common-config');
});
}
render() {
// store 都有可能有循环引用,不能调用 JSONPipeOut
let {$$editor, $$node, $schema, store, ...rest} = this.props;
const renderer = $$editor.renderer;
rest = JSONPipeOut(rest, false);
if ($$editor.filterProps) {
rest = $$editor.filterProps.call($$editor.plugin, rest, $$node);
}
if ($$editor.renderRenderer) {
return $$editor.renderRenderer.call(
$$editor.plugin,
{
...rest,
store,
$schema,
$$editor,
...$$editor.wrapperProps,
ref: this.refFn
},
$$editor
);
}
const Component = renderer.component!;
return (
<Component
{...rest}
store={store}
$schema={$schema}
$$editor={$$editor}
{...$$editor.wrapperProps}
ref={this.refFn}
/>
);
}
}

View File

@@ -0,0 +1,135 @@
import {NodeWrapper, NodeWrapperProps} from './NodeWrapper';
import React from 'react';
import {observer} from 'mobx-react';
import {autobind} from '../util';
import type {Schema} from 'amis';
import find from 'lodash/find';
import {RegionWrapper} from './RegionWrapper';
export interface ContainerWrapperProps extends NodeWrapperProps {}
@observer
export class ContainerWrapper extends React.Component<ContainerWrapperProps> {
ref: any;
getWrappedInstance() {
return this.ref;
}
@autobind
refFn(ref: any) {
this.ref = ref;
}
/*
由于基本上容器渲染器都是通过 this.props.render('region', subScheme) 来渲染孩子节点的。
所以 ContainerWrapper 只要修改下发的 render 即可完成包裹。
*/
@autobind
renderChild(region: string, node: Schema, props: any) {
const {render, $$editor, $$node, $schema} = this.props;
if (
$$editor.regions?.find(item => item.key === region)?.hiddenOn?.($schema)
) {
return null;
}
const child = render(region, node, props);
if ($$node?.memberImmutable(region)) {
return child;
}
const config = find(
$$editor.regions,
item => item.key === region && !item.matchRegion && !item.renderMethod
);
if (config) {
const Region = config.wrapper || RegionWrapper;
return (
<Region
key={props?.key}
preferTag={config.preferTag}
name={config.key}
label={config.label}
placeholder={config.placeholder}
regionConfig={config}
editorStore={$$editor.plugin.manager.store}
wrapperResolve={config.wrapperResolve}
manager={$$editor.plugin.manager}
children={child}
rendererName={$$editor.renderer.name}
$$editor={$$editor}
node={$$node}
/>
);
}
return child;
}
render() {
const {$$editor, $$node, ...rest} = this.props;
const props: any = {};
const editorStore = $$editor.plugin.manager.store;
if (
$$editor.id &&
(editorStore.isActive($$editor.id) ||
editorStore.dropId === $$editor.id) &&
Array.isArray($$editor.regions)
) {
$$editor.regions.forEach(({key, optional}) => {
if (optional) {
return;
} else if ($$node?.memberImmutable(key)) {
return;
}
let defaultRegion: any[] = [];
// /**
// * form表单的按钮组特殊处理
// * 原因:确保编辑态也显示默认的提交按钮
// */
// if (
// key === 'actions' &&
// (typeof rest.submitText === 'undefined' || rest.submitText)
// ) {
// defaultRegion = [
// {
// type: 'submit',
// label: rest.submitText || '提交',
// primary: true
// }
// ];
// }
let region = Array.isArray(rest[key])
? rest[key]
: rest[key]
? [rest[key]]
: defaultRegion;
if (!region.length) {
region = region.concat();
region.push({children: () => null});
}
props[key] = region;
});
}
return (
<NodeWrapper
{...rest}
{...props}
$$editor={$$editor}
$$node={$$node}
render={this.renderChild}
ref={this.refFn}
/>
);
}
}

View File

@@ -0,0 +1,739 @@
import React, {Component} from 'react';
import cx from 'classnames';
import Preview from './Preview';
import {autobind} from '../util';
import {MainStore, EditorStoreType} from '../store/editor';
import {EditorManager, EditorManagerConfig, PluginClass} from '../manager';
import {reaction} from 'mobx';
import {RenderOptions, closeContextMenus, toast} from 'amis';
import {
PluginEventListener,
RendererPluginAction,
IGlobalEvent
} from '../plugin';
import {reGenerateID} from '../util';
import {SubEditor} from './SubEditor';
import Breadcrumb from './Breadcrumb';
import {destroy, isAlive} from 'mobx-state-tree';
import {ScaffoldModal} from './ScaffoldModal';
import {PopOverForm} from './PopOverForm';
import {ModalForm} from './ModalForm';
import {ContextMenuPanel} from './Panel/ContextMenuPanel';
import {LeftPanels} from './Panel/LeftPanels';
import {RightPanels} from './Panel/RightPanels';
import type {SchemaObject} from 'amis';
import type {VariableGroup, VariableOptions} from '../variable';
import type {EditorNodeType} from '../store/node';
import {MobileDevTool} from 'amis-ui';
import {LeftPanelsProps} from './Panel/LeftPanels';
import {RightPanelsProps} from './Panel/RightPanels';
export interface EditorProps extends PluginEventListener {
value: SchemaObject;
onChange: (value: SchemaObject) => void;
preview?: boolean;
isMobile?: boolean;
isSubEditor?: boolean;
autoFocus?: boolean;
className?: string;
$schemaUrl?: string;
schemas?: Array<any>;
theme?: string;
/** 工具栏模式 */
toolbarMode?: 'default' | 'mini';
/** 是否需要弹框 */
noDialog?: boolean;
/** 应用语言类型 */
appLocale?: string;
/** 是否开启多语言 */
i18nEnabled?: boolean;
showCustomRenderersPanel?: boolean;
amisDocHost?: string;
superEditorData?: any;
withSuperDataSchema?: boolean;
/** 当前 Editor 为 SubEditor 时触发的宿主节点 */
hostManager?: EditorManager;
hostNode?: EditorNodeType;
dataBindingChange?: (
value: string,
data: any,
manager?: EditorManager
) => void;
/**
* Preview 预览前可以修改配置。
* 比如把api地址替换成 proxy 地址。
*/
schemaFilter?: (schema: any, isPreview?: boolean) => any;
amisEnv?: RenderOptions;
/**
* 上下文数据,设置后,面板和脚手架表单里面可以取到这些值。
*/
ctx?: any;
data?: any;
/**
* 是否禁用内置插件
*/
disableBultinPlugin?: boolean;
/**
* 插件场景
*/
scene?: string;
disablePluginList?:
| Array<string>
| ((id: string, plugin: PluginClass) => boolean);
plugins?: Array<
| PluginClass
| [PluginClass, Record<string, any> | (() => Record<string, any>)]
>;
/**
* 传给预览器的其他属性
*/
previewProps?: any;
isHiddenProps?: (key: string) => boolean;
/**
* 事件动作面板相关配置
*/
actionOptions?: {
// 是否开启老动作配置入口
showOldEntry?: boolean;
/**
* 通用动作集(事件动作面板左侧动作树)
*/
actionTreeGetter?: (
actionTree: RendererPluginAction[]
) => RendererPluginAction[];
/**
* 自定义动作配置
*/
customActionGetter?: (manager: EditorManager) => {
[propName: string]: RendererPluginAction;
};
globalEventGetter?: (manager: EditorManager) => IGlobalEvent[];
};
/** 上下文变量 */
variables?: VariableGroup[];
/** 变量配置 */
variableOptions?: VariableOptions;
onUndo?: () => void; // 用于触发外部 undo 事件
onRedo?: () => void; // 用于触发外部 redo 事件
onSave?: () => void; // 用于触发外部 save 事件
onPreview?: (preview: boolean) => void; // 用于触发外部 预览 事件
/** 打开公式编辑器之前触发的事件 */
onFormulaEditorOpen?: (
node: EditorNodeType,
manager: EditorManager,
ctx: Record<string, any>,
host?: {
node?: EditorNodeType;
manager?: EditorManager;
}
) => Promise<void | boolean>;
getHostNodeDataSchema?: () => Promise<any>;
getAvaiableContextFields?: (node: EditorNodeType) => Promise<any>;
readonly?: boolean;
onEditorMount?: (manager: EditorManager) => void;
onEditorUnmount?: (manager: EditorManager) => void;
children?: React.ReactNode | ((manager: EditorManager) => React.ReactNode);
LeftPanelsComponent?: React.ComponentType<LeftPanelsProps>;
RightPanelsComponent?: React.ComponentType<RightPanelsProps>;
/**
* 富文本编辑器配置, 用于内联编辑
*/
richTextOptions?: any;
richTextToken?: string;
}
export default class Editor extends Component<EditorProps> {
readonly store: EditorStoreType;
readonly manager: EditorManager;
readonly mainRef = React.createRef<HTMLDivElement>();
readonly mainPreviewRef = React.createRef<HTMLDivElement>();
readonly mainPreviewBodyRef = React.createRef<any>();
toDispose: Array<Function> = [];
lastResult: any;
curCopySchemaData: any; // 用于记录当前复制的元素
static defaultProps = {
autoFocus: true
};
isInternalChange: boolean = false;
constructor(props: EditorProps) {
super(props);
const {
value,
isSubEditor = false,
onChange,
showCustomRenderersPanel,
superEditorData,
hostManager,
onEditorMount,
...rest
} = props;
const config: EditorManagerConfig = {
...rest
};
this.store = MainStore.create(
{
isMobile: props.isMobile,
theme: props.theme,
toolbarMode: props.toolbarMode || 'default',
noDialog: props.noDialog,
isSubEditor,
amisDocHost: props.amisDocHost,
superEditorData,
appLocale: props.appLocale,
appCorpusData: props?.amisEnv?.replaceText,
i18nEnabled: props?.i18nEnabled ?? false
},
config
);
this.store.setCtx(props.ctx);
this.store.setSchema(value);
if (showCustomRenderersPanel !== undefined) {
this.store.setShowCustomRenderersPanel(showCustomRenderersPanel);
}
this.manager = new EditorManager(config, this.store, hostManager);
this.store.setGlobalEvents(
config.actionOptions?.globalEventGetter?.(this.manager) || []
);
// 子编辑器不再重新设置 editorStore
if (!(props.isSubEditor && (window as any).editorStore)) {
(window as any).editorStore = this.store;
}
// 添加快捷键事件
document.addEventListener('keydown', this.handleKeyDown);
window.addEventListener('message', this.handleMessage, false);
this.toDispose.push(
reaction(
() => this.store.schemaRaw,
(raw: any) => {
this.lastResult = raw;
if (this.isInternalChange) {
return;
}
props.onChange(raw);
}
)
);
this.toDispose.push(
this.manager.on('preview2editor', () => this.manager.rebuild())
);
onEditorMount?.(this.manager);
}
componentDidMount() {
const store = this.manager.store;
if (this.props.isSubEditor) {
// 等待子编辑器动画结束重新获取高亮组件位置
setTimeout(() => {
store.calculateHighlightBox(store.highlightNodes.map(node => node.id));
}, 500);
} else {
this.manager.trigger('init', {
data: this.manager
});
}
}
componentDidUpdate(prevProps: EditorProps) {
const props = this.props;
if (props.value !== prevProps.value && props.value !== this.lastResult) {
this.isInternalChange = true;
this.store.setSchema(props.value);
this.isInternalChange = false;
}
if (props.isMobile !== prevProps.isMobile) {
this.store.setIsMobile(props.isMobile);
}
if (props.ctx !== prevProps.ctx) {
this.store.setCtx(props.ctx);
}
if (props.appLocale !== prevProps.appLocale) {
this.store.setAppLocale(props.appLocale);
}
if (props?.amisEnv?.replaceText !== prevProps?.amisEnv?.replaceText) {
this.store.setAppCorpusData(props?.amisEnv?.replaceText);
}
if (
props.actionOptions?.globalEventGetter?.(this.manager) !==
prevProps.actionOptions?.globalEventGetter?.(this.manager)
) {
this.store.setGlobalEvents(
props.actionOptions?.globalEventGetter?.(this.manager) || []
);
}
}
componentWillUnmount() {
this.props.onEditorUnmount?.(this.manager);
document.removeEventListener('keydown', this.handleKeyDown);
window.removeEventListener('message', this.handleMessage);
this.toDispose.forEach(fn => fn());
this.toDispose = [];
this.manager.dispose();
setTimeout(() => destroy(this.store), 4);
}
// 快捷功能键
@autobind
handleKeyDown(e: KeyboardEvent) {
const manager = this.manager;
const store = manager.store;
// 弹窗模式不处理
if (this.props.isSubEditor || this.props.readonly || store.activeElement) {
// e.defaultPrevented // 或者已经阻止不处理
return;
}
if (
(e.target as HTMLElement).tagName === 'BODY' &&
(e.key === 'z' || e.key === 'Z') &&
(e.metaKey || e.ctrlKey) &&
e.shiftKey
) {
e.preventDefault();
this.redo(); // 重做
return;
} else if (
(e.target as HTMLElement).tagName === 'BODY' &&
(e.key === 'z' || e.key === 'Z') &&
(e.metaKey || e.ctrlKey)
) {
e.preventDefault();
this.undo(); // 撤销
return;
} else if (
(e.target as HTMLElement).tagName === 'BODY' &&
(e.key === 's' || e.key === 'S') &&
(e.metaKey || e.ctrlKey)
) {
e.preventDefault();
this.save(); // 保存
return;
} else if (
(e.target as HTMLElement).tagName === 'BODY' &&
(e.key === 'c' || e.key === 'C') &&
(e.metaKey || e.ctrlKey)
) {
// e.preventDefault(); // 注释掉阻止默认行为的方法,允许用户copy设计器中的文字
this.copy(); // 复制
return;
} else if (
(e.target as HTMLElement).tagName === 'BODY' &&
(e.key === 'v' || e.key === 'V') &&
(e.metaKey || e.ctrlKey)
) {
e.preventDefault();
if (this.curCopySchemaData) {
this.paste(); // 粘贴
}
return;
} else if (
(e.target as HTMLElement).tagName === 'BODY' &&
e.key === 'x' &&
(e.metaKey || e.ctrlKey)
) {
e.preventDefault();
// 剪切
if (this.store.activeId) {
const node = store.getNodeById(this.store.activeId);
if (node && store.activeRegion) {
toast.warning('区域节点不允许剪切。');
} else if (store.isRootSchema(this.store.activeId)) {
toast.warning('根节点不允许剪切。');
} else if (node && node.moveable) {
this.copy(); // 复制
this.manager.del(this.store.activeId); // 删除
} else {
toast.warning('当前元素不允许剪切。');
}
}
} else if (
(e.target as HTMLElement).tagName === 'BODY' &&
e.key === 'p' &&
(e.metaKey || e.ctrlKey)
) {
// 预览
e.preventDefault(); // 避免触发系统默认的事件(打印快捷键)
this.preview();
} else if (
(e.target as HTMLElement).tagName === 'BODY' &&
e.key === 'ArrowUp' &&
(e.metaKey || e.ctrlKey)
) {
e.preventDefault();
// 向上移动
if (this.store.activeId) {
const node = store.getNodeById(this.store.activeId);
if (node && node.canMoveUp) {
this.manager.moveUp();
} else {
toast.warning('当前元素不能向上移动');
}
}
} else if (
(e.target as HTMLElement).tagName === 'BODY' &&
e.key === 'ArrowDown' &&
(e.metaKey || e.ctrlKey)
) {
e.preventDefault();
// 向下移动
if (this.store.activeId) {
const node = store.getNodeById(this.store.activeId);
if (node && node.canMoveDown) {
this.manager.moveDown();
} else {
toast.warning('当前元素不能向下移动');
}
}
} else if (
(e.target as HTMLElement).tagName === 'BODY' &&
(e.key === 'Backspace' || e.key === 'Delete')
) {
e.preventDefault();
// 删除快捷键
if (this.store.activeId) {
const node = store.getNodeById(this.store.activeId);
if (
node &&
store.activeRegion &&
node.info?.regions &&
node.info.regions.length > 1
) {
toast.warning('区域节点不可以直接删除。');
} else if (store.isRootSchema(this.store.activeId)) {
toast.warning('根节点不允许删除。');
} else if (node && (node.removable || node.removable === undefined)) {
this.manager.del(this.store.activeId);
} else {
toast.warning('当前元素不允许删除。');
}
}
return;
}
}
@autobind
handleMessage(event: any) {
if (!event.data) {
return;
}
// 增加插件动态添加事件响应机制
if (
event.data.type === 'amis-widget-register-event' &&
event.data.editorPluginName
) {
console.info(
'[amis-editor]响应动态添加插件事件:',
event.data.editorPluginName
);
this.manager.dynamicAddPlugin(event.data.editorPluginName);
}
}
// 右键菜单
@autobind
async handleContextMenu(e: React.MouseEvent<HTMLElement>) {
// inline edit 模式不要右键
if (this.store.activeElement) {
return;
}
e.persist();
await closeContextMenus();
let targetId: string = '';
let region = '';
// 如果在某个已点选的控件下面,则让当前选中的渲染器呼出右键菜单
if (this.store.activeId) {
targetId = (e.target as HTMLElement)
.closest(`[data-editor-id="${this.store.activeId}"]`)
?.getAttribute('data-editor-id')!;
} else if (this.store.selections.length) {
targetId = (e.target as HTMLElement)
.closest(
this.store.selections
.map(item => `[data-editor-id="${item}"]`)
.join(',')
)
?.getAttribute('data-editor-id')!;
}
// 没找到就近找
if (!targetId) {
const dom = (e.target as HTMLElement).closest(
'[data-editor-id], [data-hlbox-id]'
);
targetId =
dom?.getAttribute('data-editor-id') ||
dom?.getAttribute('data-hlbox-id') ||
'';
}
// 没找到看看是不是在大纲中的右键
if (!targetId) {
const node = (e.target as HTMLElement).closest(
'[data-node-id]'
) as HTMLElement;
targetId = node?.getAttribute('data-node-id')!;
if (!targetId) {
return;
}
region = node.getAttribute('data-node-region')!;
}
e.preventDefault();
e.stopPropagation();
const manager = this.manager;
let offsetX = 0;
let offsetY = 0;
// 说明是 iframe 里面
if ((e.target as HTMLElement).ownerDocument !== document) {
const rect = manager.store.getIframe()!.getBoundingClientRect();
offsetX = rect.left;
offsetY = rect.top;
}
manager.openContextMenu(targetId, region, {
x: window.scrollX + e.clientX + offsetX,
y: window.scrollY + e.clientY + offsetY,
clientX: e.clientX,
clientY: e.clientY,
target: e.target as HTMLElement
});
}
canUndo() {
return this.store.canUndo;
}
canRedo() {
return this.store.canRedo;
}
undo() {
if (this.props.onUndo) {
this.props.onUndo(); // 优先使用外部撤销方法
} else {
this.store.undo();
}
}
redo() {
if (this.props.onRedo) {
this.props.onRedo(); // 优先使用外部重做方法
} else {
this.store.redo();
}
}
// 默认数据变动都会触发前端暂存,此处主要用于执行外部保存方法
save() {
if (this.props.onSave) {
this.props.onSave();
}
}
preview() {
if (this.props.onPreview) {
this.props.onPreview(!this.props.preview);
}
}
/**
* 复制的内容以变量的形式存放
* 备注1: 系统的复制&粘贴需要开启https服务才有效,所有这里改用内存形式实现
* 备注2: 此方法不鞥实现跨页面复制&粘贴能力
* 备注3: 后续需要支持下跨页面跨浏览器复制&粘贴能力
*/
copy() {
if (this.store.activeId) {
this.curCopySchemaData = this.store.getSchema(this.store.activeId);
}
}
/**
* 粘贴上一次复制的内容
*/
paste() {
if (this.store.activeId && this.curCopySchemaData) {
if (!this.curCopySchemaData) {
// 考虑复制的元素被删除的情况
return;
}
const curSimpleSchema = this.store.getSimpleSchema(
this.curCopySchemaData
);
if (this.store.activeId === this.curCopySchemaData.$$id) {
// 复制和粘贴是同一个元素,则直接追加到当前元素后面
this.manager.appendSiblingSchema(reGenerateID(curSimpleSchema), false);
} else {
this.manager.addElem(reGenerateID(curSimpleSchema), false);
}
}
}
@autobind
getToolbarContainer() {
return this.mainRef.current;
}
render() {
const {
preview,
isMobile,
className,
theme,
appLocale,
data,
previewProps,
autoFocus,
isSubEditor,
amisEnv,
readonly,
children,
LeftPanelsComponent,
RightPanelsComponent
} = this.props;
const FinalLeftPanels = LeftPanelsComponent ?? LeftPanels;
const FinalRightPanels = RightPanelsComponent ?? RightPanels;
return (
<div
ref={this.mainRef}
className={cx(
'ae-Editor',
{
preview: preview
},
className
)}
>
<div
className={cx(
'ae-Editor-inner',
isMobile && 'ae-Editor-inner--mobile'
)}
onContextMenu={this.handleContextMenu}
>
{!preview && !readonly && (
<FinalLeftPanels
store={this.store}
manager={this.manager}
theme={theme}
/>
)}
<div className="ae-Main" ref={this.mainPreviewRef}>
{!preview && (
<div className="ae-Header">
<Breadcrumb store={this.store} manager={this.manager} />
<div
id="aeHeaderRightContainer"
className="ae-Header-Right-Container"
></div>
</div>
)}
{isMobile && (
<MobileDevTool
container={this.mainPreviewRef.current}
previewBody={
this.mainPreviewBodyRef.current?.currentDom?.current
}
onChangeScale={scale => {
if (scale >= 0) {
this.store.setScale(scale / 100);
}
}}
/>
)}
<Preview
{...previewProps}
editable={!preview}
isMobile={isMobile}
store={this.store}
manager={this.manager}
theme={theme}
appLocale={appLocale}
data={data}
amisEnv={amisEnv}
autoFocus={autoFocus}
toolbarContainer={this.getToolbarContainer}
readonly={readonly}
ref={this.mainPreviewBodyRef}
></Preview>
</div>
{!preview && (
<FinalRightPanels
store={this.store}
manager={this.manager}
theme={theme}
appLocale={appLocale}
amisEnv={amisEnv}
readonly={readonly}
/>
)}
{!preview && <ContextMenuPanel store={this.store} />}
{typeof children === 'function' ? children(this.manager) : children}
</div>
<SubEditor
store={this.store}
manager={this.manager}
theme={theme}
amisEnv={amisEnv}
readonly={readonly}
/>
<ScaffoldModal
store={this.store}
manager={this.manager}
theme={theme}
/>
<PopOverForm store={this.store} manager={this.manager} theme={theme} />
<ModalForm store={this.store} manager={this.manager} theme={theme} />
</div>
);
}
}

View File

@@ -0,0 +1,79 @@
import {findDOMNode} from 'react-dom';
import {JSONPipeOut} from '../util';
import React from 'react';
import {NodeWrapper} from './NodeWrapper';
export class FormConfigWrapper extends NodeWrapper {
// 销毁的时候要把加的 aeEditor-form-config 干掉
componentWillUnmount() {
const root = findDOMNode(this) as HTMLElement;
if (!root) {
return;
}
const info = this.props.$$editor;
let dom = info.wrapperResolve ? info.wrapperResolve(root) : root;
(Array.isArray(dom) ? dom : dom ? [dom] : []).forEach(dom => {
dom.classList.remove('ae-Editor-form-config');
});
}
markDom(id: string) {
const root = findDOMNode(this) as HTMLElement;
if (!root || !id) {
return;
}
const info = this.props.$$editor;
let dom = info.wrapperResolve ? info.wrapperResolve(root) : root;
const schema = this.props.$$formSchema;
schema &&
(Array.isArray(dom) ? dom : dom ? [dom] : []).forEach(dom => {
dom.setAttribute('data-editor-id', id);
dom.classList.add('ae-Editor-form-config');
});
}
render() {
// store 都有可能有循环引用,不能调用 JSONPipeOut
let {$$editor, $$node, $schema, store, ...rest} = this.props;
const renderer = $$editor.renderer;
rest = JSONPipeOut(rest, false);
if ($$editor.filterProps) {
rest = $$editor.filterProps.call($$editor.plugin, rest, $$node);
}
if ($$editor.renderRenderer) {
return $$editor.renderRenderer.call(
$$editor.plugin,
{
...rest,
store,
$schema,
$$editor,
...$$editor.wrapperProps,
ref: this.refFn
},
$$editor
);
}
const Component = renderer.component!;
return (
<Component
{...rest}
store={store}
$schema={$schema}
$$editor={$$editor}
{...$$editor.wrapperProps}
ref={this.refFn}
/>
);
}
}

View File

@@ -0,0 +1,406 @@
import React from 'react';
import cx from 'classnames';
import {EditorStoreType} from '../store/editor';
import {observer} from 'mobx-react';
import {EditorNodeType} from '../store/node';
import {Icon} from 'amis';
import {autobind, noop} from '../util';
import {PluginEvent, ResizeMoveEventContext} from '../plugin';
import {EditorManager} from '../manager';
import {isAlive} from 'mobx-state-tree';
export interface HighlightBoxProps {
store: EditorStoreType;
node: EditorNodeType;
id: string;
className?: string;
title: string;
toolbarContainer?: () => any;
onSwitch?: (id: string) => void;
manager: EditorManager;
children?: React.ReactNode;
readonly?: boolean;
}
export default observer(function ({
className,
store,
id,
title,
children,
node,
toolbarContainer,
onSwitch,
manager,
readonly
}: HighlightBoxProps) {
const handleWResizerMouseDown = React.useCallback(
(e: MouseEvent) => startResize(e, 'horizontal'),
[]
);
const handleHResizerMouseDown = React.useCallback(
(e: MouseEvent) => startResize(e, 'vertical'),
[]
);
const handleResizerMouseDown = React.useCallback(
(e: MouseEvent) => startResize(e, 'both'),
[]
);
const startResize = React.useCallback(
(e: MouseEvent, direction: 'horizontal' | 'vertical' | 'both') => {
const isLeftButton =
(e.button === 1 && window.event !== null) || e.button === 0;
if (!isLeftButton || e.defaultPrevented) return;
e.preventDefault();
if (!node) {
return;
}
const target = document.querySelector(`[data-editor-id="${id}"]`);
if (!target) {
return;
}
manager.disableHover = true;
const event = manager[
direction === 'both'
? 'onSizeChangeStart'
: direction === 'vertical'
? 'onHeightChangeStart'
: 'onWidthChangeStart'
](e, {
dom: target as HTMLElement,
node: node,
store: store,
resizer:
direction === 'both'
? resizerDom.current!
: direction === 'vertical'
? hResizerDom.current!
: wResizerDom.current!
}) as PluginEvent<
ResizeMoveEventContext,
{
onMove(e: MouseEvent): void;
onEnd(e: MouseEvent): void;
}
>;
const pluginOnMove = event.data?.onMove;
const pluginonEnd = event.data?.onEnd;
if (!pluginOnMove && !pluginonEnd) {
return;
}
mainRef.current?.setAttribute('data-resizing', '');
const onMove = (e: MouseEvent) => {
e.preventDefault();
pluginOnMove?.(e);
};
const onUp = (e: MouseEvent) => {
e.preventDefault();
manager.disableHover = false;
mainRef.current?.removeAttribute('data-resizing');
window.removeEventListener('mousemove', onMove);
window.removeEventListener('mouseup', onUp);
document.body.style.cursor = 'default';
// 阻止 click 事件触发。
let captureClick = (e: MouseEvent) => {
window.removeEventListener('click', captureClick, true);
e.preventDefault();
e.stopPropagation();
};
window.addEventListener('click', captureClick, true);
setTimeout(
() => window.removeEventListener('click', captureClick, true),
350
);
pluginonEnd?.(e);
};
window.addEventListener('mousemove', onMove);
window.addEventListener('mouseup', onUp);
document.body.style.cursor =
direction === 'both'
? 'nwse-resize'
: direction === 'vertical'
? 'ns-resize'
: 'ew-resize';
},
[]
);
const wResizerDom = React.useRef<HTMLElement>();
const wResizerRef = React.useCallback((ref: HTMLElement) => {
if (ref) {
ref.addEventListener('mousedown', handleWResizerMouseDown);
} else {
wResizerDom.current?.removeEventListener(
'mousedown',
handleWResizerMouseDown
);
}
wResizerDom.current = ref;
}, []);
const hResizerDom = React.useRef<HTMLElement>();
const hResizerRef = React.useCallback((ref: HTMLElement) => {
if (ref) {
ref.addEventListener('mousedown', handleHResizerMouseDown);
} else {
hResizerDom.current?.removeEventListener(
'mousedown',
handleHResizerMouseDown
);
}
hResizerDom.current = ref;
}, []);
const resizerDom = React.useRef<HTMLElement>();
const resizerRef = React.useCallback((ref: HTMLElement) => {
if (ref) {
ref.addEventListener('mousedown', handleResizerMouseDown);
} else {
resizerDom.current?.removeEventListener(
'mousedown',
handleResizerMouseDown
);
}
resizerDom.current = ref;
}, []);
const handleMouseEnter = React.useCallback(() => {
if (manager.disableHover) {
return;
}
store.setHoverId(id);
}, []);
const handleDragStart = React.useCallback((e: React.DragEvent) => {
if (manager.disableHover) {
return;
}
manager.startDrag(id, e);
}, []);
const mainRef = React.createRef<HTMLDivElement>();
const toolbars = store.sortedToolbars;
const secondaryToolbars = store.sortedSecondaryToolbars;
const specialToolbars = store.sortedSpecialToolbars;
const isActive = store.isActive(id);
const curFreeContainerId = store.parentIsFreeContainer();
const isHover =
store.isHoved(id) ||
store.dropId === id ||
store.insertOrigId === id ||
curFreeContainerId === id;
const isDraggableContainer = store.draggableContainer(id);
// todo 干掉这个逻辑
// 获取当前高亮画布宽度
const aePreviewOffsetWidth = document.getElementById(
'aePreviewHighlightBox'
)!.offsetWidth;
if (!isAlive(node)) {
return <div />;
}
// 判断是否在最右侧(考虑组件头部工具栏被遮挡的问题)
const isRightElem = aePreviewOffsetWidth - node.x < 176; // 跳过icode代码检查
const isSelected =
(isActive && !store.activeElement) || ~store.selections.indexOf(id);
React.useLayoutEffect(() => {
if (!node.draggable || !isSelected || !isAlive(node)) {
return;
}
const dom = node.getTarget() as HTMLElement;
const targets = Array.isArray(dom) ? dom : dom ? [dom] : [];
targets.forEach(item => {
item.setAttribute('draggable', 'true');
item.addEventListener('dragstart', handleDragStart as any);
});
return () => {
targets.forEach(item => {
item.removeAttribute('draggable');
item.removeEventListener('dragstart', handleDragStart as any);
});
};
}, [node.draggable, isSelected]);
/* bca-disable */
return (
<div
className={cx(
'ae-Editor-hlbox',
{
shake: id === store.insertOrigId,
focused: store.activeElement && isActive,
selected: isSelected,
hover: isHover,
regionOn: node.childRegions.some(region =>
store.isRegionHighlighted(region.id, region.region)
),
isFreeContainerElem: !!curFreeContainerId || isDraggableContainer
},
className
)}
data-hlbox-id={id}
style={{
display:
node.w && node.h && !node.info.plugin.notHighlight ? 'block' : 'none',
top: node.y,
left: node.x,
width: node.w,
height: node.h
}}
ref={mainRef}
onMouseEnter={handleMouseEnter}
draggable={node.draggable}
onDragStart={handleDragStart}
>
{isActive && !store.activeElement && !readonly ? (
<div
className={`ae-Editor-toolbarPopover ${
isRightElem ? 'is-right-elem' : ''
}`}
onClick={e => e.stopPropagation()}
>
<div className="ae-Editor-nav">
{node.host ? (
<div
className="ae-Editor-tip parent"
onClick={() => onSwitch?.(node.host.id)}
>
{node.host.label}
</div>
) : null}
<div key="tip" className="ae-Editor-tip current">
{title}
</div>
{node.firstChild ? (
<div
className="ae-Editor-tip child"
onClick={() => onSwitch?.(node.firstChild.id)}
>
{node.firstChild.label}
</div>
) : null}
</div>
<div
className={cx('ae-Editor-toolbar', {
invisible: toolbars.length === 0
})}
key="toolbar"
>
{toolbars.map(item => (
<button
key={item.id}
type="button"
draggable={item.draggable}
onDragStart={item.onDragStart}
data-id={item.id}
data-tooltip={item.tooltip || undefined}
data-position={item.placement || 'top'}
onClick={item.onClick}
>
{item.iconSvg ? (
<Icon className="icon" icon={item.iconSvg} />
) : ~item.icon!.indexOf('<') ? (
<span dangerouslySetInnerHTML={{__html: item.icon!}} />
) : (
<i className={item.icon} />
)}
</button>
))}
</div>
</div>
) : null}
{isActive && secondaryToolbars.length ? (
<div className="ae-Editor-toolbar sencondary" key="sencondary-toolbar">
{secondaryToolbars.map(item => (
<button
key={item.id}
type="button"
className={item.className}
data-id={item.id}
data-tooltip={item.tooltip || undefined}
data-position={item.placement || 'top'}
onClick={item.onClick}
>
{item.iconSvg ? (
<Icon className="icon" icon={item.iconSvg} />
) : ~item.icon!.indexOf('<') ? (
<span dangerouslySetInnerHTML={{__html: item.icon!}} />
) : (
<i className={item.icon} />
)}
</button>
))}
</div>
) : null}
{isActive && specialToolbars.length ? (
<div className="ae-Editor-toolbar special" key="special-toolbar">
{specialToolbars.map(item => (
<button
key={item.id}
type="button"
className={item.className}
data-id={item.id}
data-tooltip={item.tooltip || undefined}
data-position={item.placement || 'top'}
onClick={item.onClick}
>
{item.iconSvg ? (
<Icon className="icon" icon={item.iconSvg} />
) : ~item.icon!.indexOf('<') ? (
<span dangerouslySetInnerHTML={{__html: item.icon!}} />
) : (
<i className={item.icon} />
)}
</button>
))}
</div>
) : null}
{children}
{node.widthMutable ? (
<>
<span className="ae-border-WResizer" ref={wResizerRef}></span>
<span className="ae-WResizer" ref={wResizerRef}></span>
</>
) : null}
{node.heightMutable ? (
<>
<span className="ae-border-HResizer" ref={hResizerRef}></span>
<span className="ae-HResizer" ref={hResizerRef}></span>
</>
) : null}
{node.widthMutable && node.heightMutable ? (
<span className="ae-Resizer" ref={resizerRef}></span>
) : null}
</div>
);
});

View File

@@ -0,0 +1,358 @@
import {observer} from 'mobx-react';
import {EditorStoreType} from '../store/editor';
import React, {memo} from 'react';
import {EditorManager} from '../manager';
import Frame, {useFrame} from 'react-frame-component';
import {SchemaRenderer} from './SchemaRenderer';
import {
autobind,
closeContextMenus,
findTree,
render,
resizeSensor
} from 'amis';
import {isAlive} from 'mobx-state-tree';
/**
* 这个用了 observer,所以能最小程度的刷新,数据不变按理是不会刷新的。
*/
export interface IFramePreviewProps {
editable?: boolean;
autoFocus?: boolean;
store: EditorStoreType;
env: any;
data?: any;
manager: EditorManager;
/** 应用语言类型 */
appLocale?: string;
}
@observer
export default class IFramePreview extends React.Component<IFramePreviewProps> {
initialContent: string = '';
dialogMountRef: React.RefObject<HTMLDivElement> = React.createRef();
iframeRef: HTMLIFrameElement;
constructor(props: IFramePreviewProps) {
super(props);
const styles = [].slice
.call(document.querySelectorAll('link[rel="stylesheet"], style'))
.map((el: any) => {
return el.outerHTML;
});
styles.push(`<style>
html, body, .ae-IFramePreview, .ae-IFramePreview > .frame-content, .ae-PageWrapper {
position: relative;
width: 100%;
height: 100%;
}
html::-webkit-scrollbar,
body::-webkit-scrollbar {
display: none;
}
</style>`);
this.initialContent = `<!DOCTYPE html><html><head>${styles.join(
''
)}</head><body><div class="ae-IFramePreview AMISCSSWrapper"></div></body></html>`;
}
componentDidMount() {
if (this.props.autoFocus) {
// 一般弹框动画差不多 350ms
// 延时 350ms,在弹框中展示编辑器效果要好点。
const store = this.props.manager.store;
setTimeout(() => {
if (isAlive(store)) {
const first = findTree(
store.outline,
item => !item.isRegion && item.clickable
);
first && store.setActiveId(first.id);
}
}, 350);
} else {
this.props.manager.buildRenderersAndPanels();
}
}
@autobind
iframeRefFunc(iframe: any) {
const store = this.props.store;
this.iframeRef = iframe;
isAlive(store) && store.setIframe(iframe);
}
@autobind
getModalContainer() {
const store = this.props.store;
return store.getDoc().body;
}
@autobind
isMobile() {
return true;
}
@autobind
getDialogMountRef() {
return this.dialogMountRef.current;
}
@autobind
iframeContentDidMount() {
const body = this.iframeRef.contentWindow?.document.body;
body?.classList.add('ae-PreviewIFrameBody');
}
render() {
const {editable, store, appLocale, autoFocus, env, data, manager, ...rest} =
this.props;
return (
<Frame
className={'ae-PreviewIFrame'}
initialContent={this.initialContent}
ref={this.iframeRefFunc}
contentDidMount={this.iframeContentDidMount}
>
<InnerComponent store={store} editable={editable} manager={manager} />
<div ref={this.dialogMountRef} className="ae-PageWrapper">
{render(
editable ? store.filteredSchema : store.filteredSchemaForPreview,
{
globalVars: store.globalVariables,
...rest,
key: editable ? 'edit-mode' : 'preview-mode',
theme: env.theme,
data: data,
context: store.ctx,
locale: appLocale,
editorDialogMountNode: this.getDialogMountRef
},
{
...env,
session: `${env.session}-${
editable ? 'edit' : 'preview'
}-iframe-preview`,
SchemaRenderer: editable ? SchemaRenderer : undefined,
useMobileUI: true,
isMobile: this.isMobile,
getModalContainer: this.getModalContainer
}
)}
<InnerSvgSpirit />
</div>
</Frame>
);
}
}
function InnerComponent({
store,
editable,
manager
}: {
store: EditorStoreType;
editable?: boolean;
manager: EditorManager;
}) {
// Hook returns iframe's window and document instances from Frame context
const {document: doc, window: win} = useFrame();
const editableRef = React.useRef(editable);
const handleMouseLeave = React.useCallback(() => {
store.setHoverId('');
}, []);
const handleMouseMove = React.useCallback((e: MouseEvent) => {
const dom = e.target as HTMLElement;
const target = dom.closest(`[data-editor-id]`);
if (target) {
store.setHoverId(target.getAttribute('data-editor-id')!);
}
}, []);
const handleBodyClick = React.useCallback(() => {
closeContextMenus();
}, []);
const handleClick = React.useCallback((e: MouseEvent) => {
const target = (e.target as HTMLElement).closest(`[data-editor-id]`);
closeContextMenus();
if (e.defaultPrevented) {
return;
}
if (store.activeElement) {
// 禁用内部的点击事件
e.preventDefault();
return;
}
if (target) {
store.setActiveId(target.getAttribute('data-editor-id')!);
}
if (editableRef.current) {
// 让渲染器不可点,只能点击选中。
const event = manager.trigger('prevent-click', {
data: e
});
if (!event.prevented && !event.stoped) {
e.preventDefault();
e.stopPropagation();
}
}
}, []);
const handleDBClick = React.useCallback((e: MouseEvent) => {
const target = e.target as HTMLElement;
const hostElem = target.closest(`[data-editor-id]`) as HTMLElement;
if (hostElem) {
const node = store.getNodeById(hostElem.getAttribute('data-editor-id')!);
if (!node) {
return;
}
const rendererInfo = node.info;
// 需要支持 :scope > xxx 语法,所以才这么写
let inlineElem: HTMLElement | undefined | null = null;
const inlineSetting = (rendererInfo.inlineEditableElements || []).find(
elem => {
inlineElem = (
[].slice.call(
hostElem.querySelectorAll(elem.match)
) as Array<HTMLElement>
).find(dom => dom.contains(target));
return !!inlineElem;
}
)!;
// 如果命中了支持内联编辑的元素,则开始内联编辑
if (inlineElem && inlineSetting) {
manager.startInlineEdit(node, inlineElem, inlineSetting, e);
}
}
}, []);
const handeMouseOver = React.useCallback((e: MouseEvent) => {
if (editableRef.current) {
e.preventDefault();
e.stopPropagation();
}
}, []);
// 禁用内部的提交事件
const handleSubmit = React.useCallback((e: Event) => {
e.preventDefault();
e.stopPropagation();
}, []);
const handleDragEnter = React.useCallback((e: DragEvent) => {
if (!editable) {
return;
}
e.stopPropagation();
manager.dnd.dragEnter(e);
}, []);
const handleDragLeave = React.useCallback((e: DragEvent) => {
if (!editable) {
return;
}
e.stopPropagation();
manager.dnd.dragLeave(e);
}, []);
const handleDragOver = React.useCallback((e: DragEvent) => {
if (!editable) {
return;
}
e.stopPropagation();
manager.dnd.dragOver(e);
}, []);
const handleDrop = React.useCallback((e: DragEvent) => {
if (!editable) {
return;
}
e.stopPropagation();
manager.dnd.drop(e);
}, []);
React.useEffect(() => {
store.setDoc(doc);
const layer = doc?.querySelector('.frame-content') as HTMLElement;
doc!.addEventListener('click', handleBodyClick);
layer!.addEventListener('mouseleave', handleMouseLeave);
layer!.addEventListener('mousemove', handleMouseMove);
layer!.addEventListener('click', handleClick, true);
layer!.addEventListener('dblclick', handleDBClick);
layer!.addEventListener('mouseover', handeMouseOver);
layer!.addEventListener('submit', handleSubmit);
layer!.addEventListener('dragenter', handleDragEnter);
layer!.addEventListener('dragleave', handleDragLeave);
layer!.addEventListener('dragover', handleDragOver);
layer!.addEventListener('drop', handleDrop);
const widgetsLayer = store.getLayer();
const handleScroll = () => {
widgetsLayer?.classList.add('is-scrolling');
store.calculateHighlightBox(store.highlightNodes.map(item => item.id));
};
const handleScrollEnd = () => {
widgetsLayer?.classList.remove('is-scrolling');
};
win?.addEventListener('scroll', handleScroll, true);
win?.addEventListener('scrollend', handleScrollEnd, true);
return () => {
win?.removeEventListener('scroll', handleScroll, true);
win?.removeEventListener('scrollend', handleScrollEnd, true);
doc!.removeEventListener('click', handleBodyClick);
layer!.removeEventListener('mouseleave', handleMouseLeave);
layer!.removeEventListener('mousemove', handleMouseMove);
layer!.removeEventListener('click', handleClick);
layer!.removeEventListener('mouseover', handeMouseOver);
layer!.removeEventListener('dblclick', handleDBClick);
layer!.removeEventListener('submit', handleSubmit);
layer!.removeEventListener('dragenter', handleDragEnter);
layer!.removeEventListener('dragleave', handleDragLeave);
layer!.removeEventListener('dragover', handleDragOver);
layer!.removeEventListener('drop', handleDrop);
store.setDoc(document);
};
}, [doc]);
React.useEffect(() => {
doc
?.querySelector('body>div:first-child')
?.classList.toggle('is-edting', editable);
editableRef.current = editable;
}, [editable]);
return null;
}
const InnerSvgSpirit = memo(() => {
// @ts-ignore 这里取的是平台的变量
let spiriteIcons = window.spiriteIcons;
if (spiriteIcons) {
return (
<div
id="amis-icon-manage-mount-node"
style={{display: 'none'}}
dangerouslySetInnerHTML={{__html: spiriteIcons}}
></div>
);
} else {
return null;
}
});

View File

@@ -0,0 +1,70 @@
import React from 'react';
import Editor, {EditorProps} from './Editor';
import cx from 'classnames';
import Preview from './Preview';
import {SubEditor} from './SubEditor';
import {ScaffoldModal} from './ScaffoldModal';
import {autobind} from '../util';
import {BaseEventContext, BasicPanelItem, PluginEvent} from '../plugin';
export default class MiniEditor extends Editor {
constructor(props: EditorProps) {
super(props);
this.manager.on('build-panels', this.buildPanels);
}
componentWillUnmount() {
this.manager.off('build-panels', this.buildPanels);
}
@autobind
buildPanels(event: PluginEvent<BaseEventContext>) {
const panels: Array<BasicPanelItem> = event.context.data!;
// todo, 以后干脆不要收集。
// 因为 MiniEditor 不显示面板,所以把搜集的所有面板都干掉。
if (Array.isArray(panels)) {
panels.splice(0, panels.length);
}
}
render() {
const {preview, className, theme, data, isMobile, autoFocus, previewProps} =
this.props;
return (
<div
className={cx(
'ae-Editor',
{
preview: preview
},
className
)}
>
<div className="ae-Editor-inner" onContextMenu={this.handleContextMenu}>
<div className="ae-Main">
<Preview
{...previewProps}
isMobile={isMobile}
editable={!preview}
store={this.store}
manager={this.manager}
theme={theme}
data={data}
autoFocus={autoFocus}
appLocale={this.props.appLocale}
></Preview>
</div>
</div>
<SubEditor store={this.store} manager={this.manager} theme={theme} />
<ScaffoldModal
store={this.store}
manager={this.manager}
theme={theme}
/>
</div>
);
}
}

View File

@@ -0,0 +1,161 @@
import React from 'react';
import {EditorManager} from '../manager';
import {EditorStoreType} from '../store/editor';
import {
render,
Modal,
getTheme,
Icon,
Spinner,
Button,
Overlay,
PopOver,
Drawer
} from 'amis';
import {observer} from 'mobx-react';
import {diff} from '../util';
import {autobind, createObject} from 'amis-core';
export interface ModalFormProps {
store: EditorStoreType;
manager: EditorManager;
theme?: string;
}
@observer
export class ModalForm extends React.Component<ModalFormProps> {
@autobind
async handleConfirmClick() {
const form = this.amisScope?.getComponents()[0];
if (!form) {
return;
}
const {store} = this.props;
const modalFormContext = store.modalForm!;
try {
store.markModalFormBuzy(true);
const newValue = await form.doAction(
{
type: 'submit'
},
form.props.data,
true
);
modalFormContext.callback?.(
newValue,
diff(modalFormContext.value, newValue)
);
store.closeModalForm();
} catch (e) {
console.error(e.stack);
store.setModalFormError(e.message);
}
store.markModalFormBuzy(false);
}
amisScope: any;
@autobind
scopeRef(scoped: any) {
this.amisScope = scoped;
}
buildSchema() {
const {store} = this.props;
const modalFormContext = store.modalForm!;
return {
type: 'form',
wrapWithPanel: false,
mode: 'normal',
wrapperComponent: 'div',
initApi: modalFormContext.initApi,
api: modalFormContext.api,
body: modalFormContext.body,
submitOnChange: false,
autoFocus: true
};
}
render() {
const {store, theme, manager} = this.props;
const modalFormContext = store.modalForm;
const modalMode = store.modalMode || 'dialog';
const contents = modalFormContext
? render(
this.buildSchema(),
{
data: createObject(store.ctx, modalFormContext?.value),
manager,
scopeRef: this.scopeRef
},
{
...manager.env,
session: 'modal-form',
theme: theme
}
)
: null;
return modalMode === 'drawer' ? (
<Drawer
position={(modalFormContext?.postion as any) || 'left'}
size={modalFormContext?.size || 'md'}
theme={theme}
show={!!modalFormContext}
onHide={store.closeModalForm}
>
<div className="cxd-Drawer-header">{modalFormContext?.title}</div>
<div className="cxd-Drawer-body">{contents}</div>
<div className="cxd-Drawer-footer">
<div className="cxd-Drawer-info">
{store.modalFormError ? (
<div className="cxd-Drawer-error">{store.modalFormError}</div>
) : null}
</div>
<Button
disabled={store.modalFormBuzy}
level="primary"
onClick={this.handleConfirmClick}
>
确认
</Button>
<Button onClick={store.closeModalForm}>取消</Button>
</div>
</Drawer>
) : (
<Modal
theme={theme}
size={modalFormContext?.size || 'md'}
show={!!modalFormContext}
onHide={store.closeModalForm}
closeOnEsc={false}
>
{modalFormContext?.title ? (
<Modal.Header onClose={store.closeModalForm}>
{modalFormContext.title}
</Modal.Header>
) : null}
<Modal.Body>{contents}</Modal.Body>
<Modal.Footer>
<div className="cxd-Dialog-info">
{store.modalFormError ? (
<div className="cxd-Dialog-error">{store.modalFormError}</div>
) : null}
</div>
<Button
disabled={store.modalFormBuzy}
level="primary"
onClick={this.handleConfirmClick}
>
确认
</Button>
<Button onClick={store.closeModalForm}>取消</Button>
</Modal.Footer>
</Modal>
);
}
}

View File

@@ -0,0 +1,137 @@
import {RendererProps, isObject} from 'amis-core';
import {observer} from 'mobx-react';
import {isAlive} from 'mobx-state-tree';
import React from 'react';
import {findDOMNode} from 'react-dom';
import merge from 'lodash/merge';
import omit from 'lodash/omit';
import {RendererInfo} from '../plugin';
import {EditorNodeType} from '../store/node';
import {autobind, isEmpty} from '../util';
import {filter} from 'amis-core';
export interface NodeWrapperProps extends RendererProps {
$$editor: RendererInfo; // 当前节点信息(info)
$$node?: EditorNodeType; // 虚拟dom节点信息
}
@observer
export class NodeWrapper extends React.Component<NodeWrapperProps> {
/** 合并 Mock 配置时应该忽略的属性 */
omitMockProps = ['id', '$$id', 'enable', 'maxDisplayRows'];
componentDidMount() {
this.markDom(this.props.$$editor.id);
// 稍微等会,因为有可能别的 node 还没更新完成。
const node = this.props.$$node;
node &&
requestAnimationFrame(() => {
() => isAlive(node) && node.calculateHighlightBox();
});
}
componentDidUpdate(prevProps: NodeWrapperProps) {
this.markDom(this.props.$$editor.id);
}
ref: any;
getWrappedInstance() {
return this.ref;
}
@autobind
refFn(ref: any) {
this.ref = ref;
}
/**
* 弄点标记
*/
markDom(id: string) {
const root = findDOMNode(this) as HTMLElement;
if (!root || !id) {
return;
}
const info = this.props.$$editor;
let visible =
this.props.$$visible !== false && this.props.$$hidden !== true;
if (visible) {
const schema = this.props.$schema;
const data = this.props.data;
const id = filter(schema.id, data);
const name = filter(schema.name, data);
const states = (this.props.statusStore as any).raw.visibleState as any;
if ((states[id] ?? states[name]) === false) {
visible = false;
}
}
let dom = info.wrapperResolve ? info.wrapperResolve(root) : root;
(Array.isArray(dom) ? dom : dom ? [dom] : []).forEach(dom => {
dom.setAttribute('data-editor-id', id);
dom.setAttribute('name', this.props.id);
dom.setAttribute('data-visible', visible ? '' : 'false');
dom.setAttribute('data-hide-text', visible ? '' : '<隐藏状态>');
if (info.regions) {
dom.setAttribute('data-container', '');
} else {
dom.removeAttribute('data-container');
}
});
info.plugin?.markDom?.(dom, this.props);
}
render() {
// store 可能有循环引用,不能调用 JSONPipeOut
let {$$editor, $$node, store, ...rest} = this.props;
const renderer = $$editor.renderer;
if ($$editor.filterProps) {
rest = $$editor.filterProps.call($$editor.plugin, rest, $$node);
}
const mockProps = omit(rest?.editorSetting?.mock, this.omitMockProps);
// 自动合并假数据
if (isObject(mockProps) && !isEmpty(mockProps)) {
rest = merge(rest, mockProps);
}
if ($$editor.renderRenderer) {
return $$editor.renderRenderer.call(
$$editor.plugin,
{
...rest,
store,
...$$node?.state,
$$editor,
...$$editor.wrapperProps,
ref: this.refFn
},
$$editor
);
}
const Component = renderer.component!;
const supportRef =
Component.prototype?.isReactComponent ||
(Component as any).$$typeof === Symbol.for('react.forward_ref');
return (
<Component
{...rest}
store={store}
{...$$node?.state}
$$editor={$$editor}
{...$$editor.wrapperProps}
ref={supportRef ? this.refFn : undefined}
/>
);
}
}

View File

@@ -0,0 +1,343 @@
import React from 'react';
import {Editor} from 'amis-ui';
import {
isObjectShallowModified,
guid,
diff,
filterSchemaForConfig
} from '../../util';
import cx from 'classnames';
import {prompt, toast} from 'amis';
import debounce from 'lodash/debounce';
import isArray from 'lodash/isArray';
import findIndex from 'lodash/findIndex';
import {parse, stringify} from 'json-ast-comments';
import isPlainObject from 'lodash/isPlainObject';
const internalSchema = /^\/schemas\/(.*).json$/;
async function buildSchema(
schemaUrl: string,
definition: string,
fileUri: string,
origin: any
) {
const schemas: Array<{
uri: string;
fileMatch?: Array<any>;
schema: any;
}> = Array.isArray(origin) ? origin.concat() : [];
// 开发环境直接读取本地 schema.json 文件。
if (process.env.NODE_ENV !== 'production') {
schemas.some(item => item.uri === schemaUrl) ||
schemas.push({
uri: schemaUrl,
// @ts-ignore
schema: await import('amis/schema.json').then(item => item.default)
});
}
if (internalSchema.test(definition)) {
const rawName = RegExp.$1;
const uri = `${schemaUrl.replace(
/^(\w+\:\/\/[^\/]+)\/.*$/,
'$1'
)}/schemas/${rawName}.json`;
// 如果存在,先删掉
const idx = findIndex(schemas, item => item.fileMatch?.[0] === fileUri);
if (~idx) {
schemas.splice(idx, 1);
}
schemas.push({
uri,
fileMatch: [fileUri],
schema: {
$schema: 'http://json-schema.org/draft-07/schema#',
$ref: `${schemaUrl}#/definitions/${rawName}`
}
});
}
return schemas;
}
const codeErrorWarning = debounce(e => {
toast.warning(`代码有误,错误的地方是\n ${e.toString().split('\n')[1]}`);
}, 3000);
export interface AMisCodeEditorProps {
value: any;
onChange: (value: any, diff: any) => void;
onPaste?: (e: any) => void;
disabled?: boolean;
$schemaUrl?: string;
$schema?: string;
className?: string;
theme?: string;
}
export default class AMisCodeEditor extends React.Component<AMisCodeEditorProps> {
state = {
wrongSchema: '',
value: this.props.value,
contents: this.obj2str(this.props.value, this.props)
};
lastResult: any;
toDispose: Array<() => void> = [];
editor: any;
monaco: any;
model: any;
decorations: any;
uri = `isuda://schema/${guid()}.json`;
componentDidUpdate(prevProps: AMisCodeEditorProps) {
const props = this.props;
if (prevProps.$schema !== props.$schema && this.monaco) {
this.changeJsonOptions(props);
}
if (
isObjectShallowModified(props.value, prevProps.value) &&
isObjectShallowModified(props.value, this.lastResult)
) {
this.lastResult = null;
this.setState({
value: props.value,
contents: this.obj2str(props.value, props)
});
}
}
obj2str(value: any, props: AMisCodeEditorProps) {
// 隐藏公共配置
value = filterSchemaForConfig(value);
if (!isArray(value)) {
value = {
type: value?.type,
...value
};
}
if (isArray(value)) {
return stringify(value);
} else if (!value.type && props.$schema?.match(/PageSchema/i)) {
value.type = 'page';
} else if (!value.type) {
delete value.type;
}
delete value.$schema;
return stringify(value);
}
str2obj(str: string) {
try {
if (str === '') {
return {};
}
const curObj = parse(str);
if (codeErrorWarning) {
// 此次代码转换成功后,立即取消上一次的错误提示(避免显示上一次的错误提示)
codeErrorWarning.cancel();
}
return curObj;
} catch (e) {
codeErrorWarning(e);
return null;
}
}
emitChange = debounce(
() => {
const {onChange, value} = this.props;
let ret: any = this.str2obj(this.state.contents);
if (!ret || (!isPlainObject(ret) && !isArray(ret))) {
this.setState({
wrongSchema: this.state.contents
});
return;
}
this.setState({
wrongSchema: ''
});
delete ret.$schema;
// 补齐公共配置项目
ret = filterSchemaForConfig(ret, this.props.value);
const diffResult = diff(this.lastResult || value, ret);
this.lastResult = ret;
onChange(ret, diffResult);
},
250,
{
trailing: true,
leading: false
}
);
async changeJsonOptions(props: AMisCodeEditorProps = this.props) {
const monaco = this.monaco;
let schemaUrl =
props.$schemaUrl ||
`${window.location.protocol}//${window.location.host}/schema.json`;
if (schemaUrl.indexOf('/') === 0) {
schemaUrl = `${window.location.protocol}//${window.location.host}${schemaUrl}`;
}
const schemas = await buildSchema(
schemaUrl,
props.$schema!,
monaco.Uri.parse(this.uri).toString(),
monaco.languages.json?.jsonDefaults.diagnosticsOptions.schemas
);
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
schemas: schemas,
validate: true,
enableSchemaRequest: true,
allowComments: true
});
}
editorFactory = (
containerElement: HTMLElement,
monaco: any,
options: any
) => {
const modelUri = monaco.Uri.parse(this.uri);
this.model = monaco.editor.createModel(
this.state.contents,
'json',
modelUri
);
return monaco.editor.create(containerElement, {
autoIndent: true,
formatOnType: true,
formatOnPaste: true,
selectOnLineNumbers: true,
scrollBeyondLastLine: false,
folding: true,
scrollbar: {alwaysConsumeMouseWheel: false}, // 弹窗编辑中的编辑器有时会无法滚动
minimap: {
enabled: false
},
...options,
model: this.model
});
};
editorDidMount = (editor: any, monaco: any) => {
this.editor = editor;
this.monaco = monaco;
this.changeJsonOptions(this.props);
this.props.onPaste &&
this.toDispose.push(this.editor.onDidPaste(this.props.onPaste).dispose);
};
editorWillUnmount = (editor: any, monaco: any) => {
this.toDispose.forEach(fn => fn());
this.toDispose = [];
};
handleChange = (value: string) => {
this.setState(
{
contents: value
},
this.emitChange
);
};
handleBlur = async () => {
const {wrongSchema, value} = this.state;
if (!wrongSchema) {
return;
}
const result = await prompt(
[
{
className: 'w-full',
type: 'tpl',
label: false,
tpl: '当前有部分已更改数据因为格式不正确尚未保存,您确认要丢弃这部分更改吗?'
},
{
type: 'switch',
label: false,
option: '查看更改',
name: 'diff',
value: false
},
{
visibleOn: 'this.diff',
label: false,
type: 'diff-editor',
allowFullscreen: true,
disabled: true,
name: 'newValue',
size: 'xxl',
language: 'json',
diffValue: '${oldValue}'
}
],
{
oldValue: value,
newValue: wrongSchema
},
'请确认'
);
if (result) {
this.setState({wrongSchema: '', contents: stringify(value)});
} else {
this.editor.focus();
}
};
render() {
let {disabled, className, theme} = this.props;
return (
// @ts-ignore
<Editor
className={cx('amis-code-editor', className)}
value={this.state.contents}
onChange={this.handleChange}
onBlur={this.handleBlur}
language="json"
theme={theme}
editorFactory={this.editorFactory}
editorDidMount={this.editorDidMount}
editorWillUnmount={this.editorWillUnmount}
options={{
automaticLayout: true,
lineNumbers: 'off',
glyphMargin: false,
tabSize: 2,
wordWrap: 'on',
lineDecorationsWidth: 0,
lineNumbersMinChars: 0,
selectOnLineNumbers: true,
scrollBeyondLastLine: false,
folding: true,
minimap: {
enabled: false
},
readOnly: disabled
}}
/>
);
}
}

View File

@@ -0,0 +1,94 @@
import {observer} from 'mobx-react';
import React from 'react';
import {Tab, Tabs} from 'amis';
import RenderersPanel from './RenderersPanel';
import {PanelProps} from '../../plugin';
import {autobind} from '../../util';
type PanelStates = {
toggleCollapseFolderStatus: boolean;
};
@observer
export class AvailableRenderersPanel extends React.Component<
PanelProps,
PanelStates
> {
@autobind
handleSelect(key: string) {
if (key) {
this.props.store.changeRenderersTabsKey(key);
}
}
render() {
const {store, manager, children} = this.props;
const renderersTabsKey = store.renderersTabsKey || 'base-renderers';
const curTheme = store.theme;
const customRenderersByOrder = store.customRenderersByOrder || [];
const groupedSubRenderers = store.groupedSubRenderers || {};
const groupedCustomRenderers = store.groupedCustomRenderers || {}; // 自定义组件
return (
<div className="ae-RendererPanel">
<div className="panel-header">组件</div>
<div className="ae-RendererPanel-content">
{typeof children === 'function' ? children(this.props) : children}
{store.showCustomRenderersPanel &&
customRenderersByOrder.length > 0 && (
<Tabs
theme={curTheme}
tabsMode={'line'} // tiled
className="ae-RendererList-tabs"
linksClassName="ae-RendererList-tabs-header"
contentClassName="ae-RendererList-tabs-content"
activeKey={renderersTabsKey}
onSelect={this.handleSelect}
>
<Tab
key={'base-renderers'}
eventKey={'base-renderers'}
title={'系统组件'}
className={`ae-RendererList-tabs-panel base-renderers`}
mountOnEnter={true}
unmountOnExit={false}
>
<RenderersPanel
groupedRenderers={groupedSubRenderers}
store={store}
manager={manager}
searchRendererType={'renderer'}
/>
</Tab>
<Tab
key={'custom-renderers'}
eventKey={'custom-renderers'}
title={'自定义组件'}
className={`ae-RendererList-tabs-panel custom-renderers`}
mountOnEnter={true}
unmountOnExit={false}
>
<RenderersPanel
groupedRenderers={groupedCustomRenderers}
store={store}
manager={manager}
searchRendererType={'custom-renderer'}
/>
</Tab>
</Tabs>
)}
{(!store.showCustomRenderersPanel ||
Object.keys(groupedCustomRenderers).length < 1) && (
<RenderersPanel
className={'only-base-component'}
groupedRenderers={groupedSubRenderers}
store={store}
manager={manager}
searchRendererType={'renderer'}
/>
)}
</div>
</div>
);
}
}

View File

@@ -0,0 +1,43 @@
import React from 'react';
import {PanelProps} from '../../plugin';
import {autobind} from '../../util';
import AMisCodeEditor from './AMisCodeEditor';
export default class CodeEditorPanel extends React.Component<PanelProps> {
@autobind
handleCodePaste(e: any) {
setTimeout(() => {
this.props.manager.patchSchema(true);
// 检测是否整体粘贴组件,如果是的话对指定类型组件存在重复ID的重新生成
if (
e?.languageId === 'json' &&
e.range?.startColumn === 1 &&
e.range?.startLineNumber === 1 &&
e.range?.endColumn === 2 &&
e.range?.endLineNumber > 1
) {
this.props.manager.reGenerateNodeDuplicateID(['布局容器', '展示']);
}
}, 500);
}
render() {
const {onChange, manager, store} = this.props;
return (
<div className="ae-CodePanel">
<div className="panel-header">源码</div>
<div className="ae-CodePanel-content">
<AMisCodeEditor
value={store.valueWithoutHiddenProps}
onChange={onChange}
$schema={store.jsonSchemaUri}
$schemaUrl={manager.config.$schemaUrl}
onPaste={this.handleCodePaste}
/>
</div>
</div>
);
}
}

View File

@@ -0,0 +1,42 @@
import {observer} from 'mobx-react';
import React from 'react';
import {Icon} from 'amis';
import {EditorStoreType} from '../../store/editor';
export interface ContextMenuPanelProps {
store: EditorStoreType;
}
@observer
export class ContextMenuPanel extends React.Component<ContextMenuPanelProps> {
render() {
const store = this.props.store;
const contextMenuPanel = store.contextMenuPanel;
const menus =
contextMenuPanel && contextMenuPanel.menus ? contextMenuPanel.menus : [];
return menus && menus.length > 0 ? (
<div className="context-menu-setting">
<div className="setting-header">批量操作</div>
<div className="setting-body">
{menus.map(menu => {
return (
menu.label && (
<div
key={menu.label}
className={`setting-item ${menu.disabled ? 'disabled' : ''}`}
onClick={!menu.disabled ? menu.onSelect : null}
>
<div className="icon-box">
<Icon icon={menu.icon} className="menu-icon" />
</div>
<div className="setting-info">{menu.label}</div>
</div>
)
);
})}
</div>
</div>
) : null;
}
}

View File

@@ -0,0 +1,155 @@
import {ClassNamesFn} from 'amis-core';
import {observer} from 'mobx-react';
import React from 'react';
import {EditorStoreType} from '../../store/editor';
import {
JSONGetById,
modalsToDefinitions,
reGenerateID,
translateSchema
} from '../../util';
import {Button, Icon, ListMenu, PopOverContainer, confirm} from 'amis';
import {EditorManager} from '../../manager';
import cloneDeep from 'lodash/cloneDeep';
export interface DialogListProps {
classnames: ClassNamesFn;
store: EditorStoreType;
manager: EditorManager;
}
export default observer(function DialogList({
classnames: cx,
store,
manager
}: DialogListProps) {
const modals = store.modals.filter(item => !item.disabled);
const handleAddDialog = React.useCallback(() => {
const modal = {
type: 'dialog',
title: '未命名弹窗',
definitions: modalsToDefinitions(store.modals),
body: [
{
type: 'tpl',
tpl: '弹窗内容'
}
]
};
manager.openSubEditor({
title: '编辑弹窗',
value: modal,
onDefinitionsChange: (definitions, originDefinitions, modal) => {
store.addModal(modal, definitions);
return false;
}
});
}, []);
const handleEditDialog = React.useCallback((event: React.UIEvent<any>) => {
const index = parseInt(event.currentTarget.getAttribute('data-index')!, 10);
const modal = store.modals[index];
const modalId = modal.$$id!;
manager.openSubEditor({
title: '编辑弹窗',
value: {
type: 'dialog',
...(modal as any),
definitions: modalsToDefinitions(store.modals, {}, modal)
},
onDefinitionsChange: (definitions, originDefinitions, modal) => {
store.updateModal(modalId, modal, definitions);
return false;
}
});
}, []);
const handleDelDialog = React.useCallback(
async (event: React.UIEvent<any>) => {
event.stopPropagation();
event.preventDefault();
const index = parseInt(
event.currentTarget
.closest('[data-index]')!
.getAttribute('data-index')!,
10
);
const dialog = store.modals[index];
const refsCount = store.countModalActionRefs(dialog.$$id!);
const confirmed = await confirm(
refsCount
? `当前弹窗已关联 ${refsCount} 个事件,删除后,所配置的事件动作将一起被删除。`
: '',
`确认删除弹窗「${dialog.editorSetting?.displayName || dialog.title}」?`
);
if (confirmed) {
store.removeModal(dialog.$$id!);
}
},
[]
);
const handleCopyDialog = React.useCallback((event: React.UIEvent<any>) => {
event.stopPropagation();
event.preventDefault();
const index = parseInt(
event.currentTarget.closest('[data-index]')!.getAttribute('data-index')!,
10
);
let dialog = cloneDeep(store.modals[index]);
dialog = reGenerateID(dialog);
store.addModal({
...dialog,
title: `${dialog.title} - 复制`,
editorSetting: {
...dialog.editorSetting,
displayName: dialog.editorSetting?.displayName
? `${dialog.editorSetting?.displayName} - 复制`
: ''
}
});
}, []);
return (
<div className={cx('ae-DialogList-wrap', 'hoverShowScrollBar')}>
<Button size="sm" level="enhance" block onClick={handleAddDialog}>
新增弹窗
</Button>
{modals.length ? (
<ul className="ae-DialogList">
{modals.map((modal, index) => (
<li
className="ae-DialogList-item"
data-index={index}
key={modal.$$id || index}
onClick={handleEditDialog}
>
<span>
{`${
modal.editorSetting?.displayName ||
modal.title ||
'未命名弹窗'
}`}
</span>
<a onClick={handleCopyDialog} className="ae-DialogList-iconBtn">
<Icon className="icon" icon="copy" />
</a>
<a onClick={handleDelDialog} className="ae-DialogList-iconBtn">
<Icon className="icon" icon="trash" />
</a>
</li>
))}
</ul>
) : (
<div className="ae-DialogList-placeholder">暂无弹窗</div>
)}
</div>
);
});

View File

@@ -0,0 +1,54 @@
import {observer} from 'mobx-react';
import React from 'react';
import {EditorManager} from '../../manager';
import {EditorStoreType} from '../../store/editor';
import {Drawer} from 'amis';
import {autobind} from '../../util';
import {findDOMNode} from 'react-dom';
import {EditorNodeType} from '../../store/node';
export interface PanelsProps {
store: EditorStoreType;
manager: EditorManager;
node: EditorNodeType | undefined;
panelItem: any;
theme?: string;
}
@observer
export class DrawerPanel extends React.Component<PanelsProps> {
@autobind
getPopOverContainer() {
return findDOMNode(this) as HTMLElement;
}
render() {
const {store, manager, node, panelItem, theme} = this.props;
const id = store.activeId;
return (
<Drawer
position="left"
size="md"
theme={theme}
show={!!panelItem}
onHide={store.closeInsertPanel}
className="ae-InsertPanel-drawer"
>
{panelItem && panelItem.component ? (
<panelItem.component
key={panelItem.key}
id={id}
info={node?.info}
path={node?.path}
value={store.value}
onChange={manager.panelChangeValue}
store={store}
manager={manager}
popOverContainer={this.getPopOverContainer}
/>
) : null}
</Drawer>
);
}
}

View File

@@ -0,0 +1,59 @@
import {observer} from 'mobx-react';
import React from 'react';
import {EditorManager} from '../../manager';
import {EditorStoreType} from '../../store/editor';
import {Drawer} from 'amis';
import {autobind} from '../../util';
import {findDOMNode} from 'react-dom';
import {EditorNodeType} from '../../store/node';
export interface PanelsProps {
store: EditorStoreType;
manager: EditorManager;
node: EditorNodeType | undefined;
panelItem: any;
theme?: string;
}
@observer
export class DrawerRendererPanel extends React.Component<PanelsProps> {
@autobind
getPopOverContainer() {
return findDOMNode(this) as HTMLElement;
}
render() {
const {store, manager, node, panelItem, theme} = this.props;
const id = store.activeId;
const showInsertRenderer = store.showInsertRenderer;
return (
<Drawer
position="left"
size="md"
theme={theme}
show={showInsertRenderer}
onHide={store.closeInsertRendererPanel}
className="ae-InsertRendererPanel-drawer"
bodyClassName="ae-drawer-renderers"
>
{panelItem.title && (
<div className="ae-drawer-title">{panelItem.title}</div>
)}
{panelItem && panelItem.component ? (
<panelItem.component
key={panelItem.key}
id={id}
info={node?.info}
path={node?.path}
value={store.value}
onChange={manager.panelChangeValue}
store={store}
manager={manager}
popOverContainer={this.getPopOverContainer}
/>
) : null}
</Drawer>
);
}
}

View File

@@ -0,0 +1,182 @@
import {Button, Html, Icon, InputBox, render} from 'amis';
import find from 'lodash/find';
import {observer} from 'mobx-react';
import React from 'react';
import {PanelProps, SubRendererInfo} from '../../plugin';
import {autobind} from '../../util';
import {RendererThumb} from '../RendererThumb';
@observer
export class InsertSubRendererPanel extends React.Component<PanelProps> {
@autobind
handleLeftClick(e: React.MouseEvent) {
const tag = e.currentTarget.getAttribute('data-value')!;
const store = this.props.store;
store.setInsertTag(tag);
}
@autobind
handleClick(e: React.MouseEvent) {
const id = e.currentTarget.getAttribute('data-value')!;
const store = this.props.store;
store.setInsertSelected(id);
}
@autobind
hadnlDBClick(e: React.MouseEvent) {
const id = e.currentTarget.getAttribute('data-value')!;
const store = this.props.store;
store.setInsertSelected(id);
const manager = this.props.manager;
store.insertMode === 'replace' ? manager.replace() : manager.insert();
}
@autobind
handleInsert() {
const manager = this.props.manager;
manager.insert();
}
@autobind
handleReplace() {
const manager = this.props.manager;
manager.replace();
}
@autobind
handleCancel() {
const store = this.props.store;
store.closeInsertPanel();
}
render() {
const store = this.props.store;
const manager = this.props.manager;
const info = store.getNodeById(store.insertId)?.info!;
const regionLabel = find(
info.regions,
region => region.key === store.insertRegion
)?.label;
const grouped = store.groupedInsertRenderers;
const keys = Object.keys(grouped);
const insertTag = store.insertTag || '全部';
const list = grouped[insertTag] || grouped['全部'];
return (
<div className="ae-InsertPanel">
{store.insertMode === 'replace' ? (
<div className="ae-InsertPanel-title">更改组件类型</div>
) : (
<div className="ae-InsertPanel-title">
<span>选中组件插入到</span>&nbsp;
<code>
{info.name} &gt; {regionLabel}
</code>
</div>
)}
<div className="m-b-xs">
<InputBox
className="editor-InputSearch"
value={store.insertRenderersKeywords}
onChange={store.changeInsertRenderersKeywords}
placeholder={'输入关键字可过滤组件'}
clearable={false}
>
{store.insertRenderersKeywords ? (
<a onClick={store.resetInsertRenderersKeywords}>
<Icon icon="close" className="icon" />
</a>
) : (
<Icon icon="search" className="icon" />
)}
</InputBox>
</div>
<div className="ae-RenderersPicker-list">
<ul>
{keys.map(key => (
<li key={key} className={insertTag === key ? 'is-active' : ''}>
<a data-value={key} onClick={this.handleLeftClick}>
{key}
</a>
</li>
))}
</ul>
<div className="ae-RenderersPicker-content">
{Array.isArray(list) && list.length ? (
<ul>
{list.map(item => (
<li
key={item.id}
className={
store.insertSelected === item.id ? 'is-active' : ''
}
data-value={item.id}
onClick={this.handleClick}
onDoubleClick={this.hadnlDBClick}
>
<RendererThumb
theme={manager.env.theme}
env={manager.env}
schema={
item.previewSchema || {
type: 'tpl',
tpl: '无法预览'
}
}
/>
<div className="ae-RenderersPicker-info">
<h4>{item.name}</h4>
<div>
<Html html={item.description} />
{item.docLink ? (
<a
target="_blank"
href={store.amisDocHost + item.docLink}
>
<span>详情</span>
</a>
) : null}
</div>
</div>
</li>
))}
</ul>
) : (
<div>没有可用组件,也许你该切换容器试试。</div>
)}
</div>
</div>
<div className="ae-InsertPanel-footer">
{store.insertMode === 'replace' ? (
<Button
className="action-btn action-btn-primary"
onClick={this.handleReplace}
disabled={!store.insertSelected}
level="primary"
>
替换
</Button>
) : (
<Button
className="action-btn action-btn-primary"
onClick={this.handleInsert}
disabled={!store.insertSelected}
level="primary"
>
插入
</Button>
)}
<Button className="action-btn" onClick={this.handleCancel}>
取消
</Button>
</div>
</div>
);
}
}

View File

@@ -0,0 +1,206 @@
import {observer} from 'mobx-react';
import React from 'react';
import {Icon} from 'amis';
import cx from 'classnames';
import {EditorManager} from '../../manager';
import {EditorStoreType} from '../../store/editor';
import {Tab, Tabs} from 'amis';
import {autobind} from '../../util';
import {findDOMNode} from 'react-dom';
import find from 'lodash/find';
import {PanelItem} from '../../plugin';
import {DrawerPanel} from './DrawerPanel';
import {DrawerRendererPanel} from './DrawerRendererPanel';
export interface LeftPanelsProps {
store: EditorStoreType;
manager: EditorManager;
theme?: string;
}
interface LeftPanelsStates {
isFixedStatus: boolean;
}
@observer
export class LeftPanels extends React.Component<
LeftPanelsProps,
LeftPanelsStates
> {
constructor(props: any) {
super(props);
this.state = {
isFixedStatus: false // 默认非fixed模式
};
}
@autobind
handleHidden() {
const {changeLeftPanelOpenStatus, leftPanelOpenStatus, changeLeftPanelKey} =
this.props.store;
const nextStatus = !leftPanelOpenStatus;
changeLeftPanelOpenStatus(nextStatus);
if (nextStatus) {
// 展开则默认显示大纲面板
changeLeftPanelKey('outline');
} else {
// 折叠时则不显示任何tab面板
changeLeftPanelKey('none');
}
}
@autobind
handleFixed() {
this.setState({
isFixedStatus: !this.state.isFixedStatus
});
}
@autobind
handleSelect(key: string) {
const {changeLeftPanelOpenStatus, changeLeftPanelKey} = this.props.store;
if (key) {
// 先展开再显示指定面板内容
changeLeftPanelOpenStatus(true);
changeLeftPanelKey(key);
}
}
@autobind
getPopOverContainer() {
return findDOMNode(this) as HTMLElement;
}
render() {
const {store, manager, theme} = this.props;
const {isFixedStatus} = this.state;
const leftPanelOpenStatus = store.leftPanelOpenStatus;
const panels = store.getLeftPanels();
const id = store.activeId;
const node = store.getNodeById(id);
const panelKey = store.getLeftPanelKey();
const insertPanel =
store.insertId &&
store.insertRegion &&
find(panels, p => p.key === 'insert');
const insertRendererPanel = find(panels, p => p.key === 'insertRenderer');
const renderPanel = (panel: PanelItem) => {
return panel.render ? (
panel.render({
id,
info: node?.info,
path: node?.path,
node: node,
value: store.value,
onChange: manager.panelChangeValue,
store: store,
manager: manager,
popOverContainer: this.getPopOverContainer
})
) : panel.component ? (
<panel.component
node={node}
key={panel.key}
id={id}
info={node?.info}
path={node?.path}
value={store.value}
onChange={manager.panelChangeValue}
store={store}
manager={manager}
popOverContainer={this.getPopOverContainer}
/>
) : null;
};
return (
<>
{panels.length > 0 && (
<div
className={cx(
'editor-left-panel width-draggable',
leftPanelOpenStatus ? '' : 'hidden-status',
isFixedStatus ? 'fixed-status' : ''
)}
>
<div
className={`editor-panel-btn`}
editor-tooltip={isFixedStatus ? '关闭悬浮模式' : '开启悬浮模式'}
tooltip-position="right"
>
<Icon
icon={isFixedStatus ? 'editor-fixed' : 'editor-no-fixed'}
className="panel-btn"
onClick={this.handleFixed}
/>
</div>
<Tabs
className="editorPanel-tabs"
linksClassName="editorPanel-tabs-header"
contentClassName="editorPanel-tabs-content"
theme={theme}
activeKey={panelKey}
onSelect={this.handleSelect}
tabsMode="sidebar"
sidePosition="left"
>
{panels.map(panel => {
return panel.key !== 'insert' &&
panel.key !== 'insertRenderer' ? (
<Tab
key={panel.key}
eventKey={panel.key}
title={
panel.title ?? (
<span
className="editor-tab-icon editor-tab-s-icon"
editor-tooltip={panel.tooltip}
>
{panel.icon}
</span>
)
}
// icon={panel.icon}
className={`editorPanel-tabs-pane ae-Editor-${panel.key}Pane`}
mountOnEnter={true}
unmountOnExit={false}
>
{renderPanel(panel)}
</Tab>
) : null;
})}
</Tabs>
<div
className={cx(
'left-panel-arrow',
leftPanelOpenStatus ? '' : 'hidden-status'
)}
onClick={this.handleHidden}
></div>
</div>
)}
{isFixedStatus && (
<div className="editor-left-panel-fixed-placeholder"></div>
)}
<DrawerPanel
store={store}
manager={manager}
node={node}
panelItem={insertPanel}
theme={theme}
/>
{/* 插入组件面板(复用现有组件面板)*/}
<DrawerRendererPanel
store={store}
manager={manager}
node={node}
panelItem={insertRendererPanel}
theme={theme}
/>
</>
);
}
}

View File

@@ -0,0 +1,438 @@
import {observer} from 'mobx-react';
import React from 'react';
import {PanelProps} from '../../plugin';
import cx from 'classnames';
import {autobind, translateSchema} from '../../util';
import {Icon, InputBox, Tab, Tabs} from 'amis';
import {EditorNodeType} from '../../store/node';
import {isAlive} from 'mobx-state-tree';
import type {Schema} from 'amis';
import DialogList from './DialogList';
@observer
export class OutlinePanel extends React.Component<PanelProps> {
state = {
curSearchElemKey: '' // 用于记录用户当前输入的关键字
};
dragEnterCount = 0;
@autobind
handleClick(e: React.MouseEvent<HTMLAnchorElement>) {
const store = this.props.store;
const dom = e.currentTarget;
const id = dom.getAttribute('data-node-id')!;
const region = dom.getAttribute('data-node-region')!;
const manager = this.props.manager;
if (region) {
// 点击容器类型自动弹出「组件插入面板」有点干扰用户操作
// manager.showInsertPanel(region, id);
/** 特殊区域允许点击事件 */
if (store.activeId === id && store.activeRegion === region) {
// 重复点击则取消区域选中
store.setActiveId(id);
} else {
store.setActiveId(id, region);
}
} else {
store.setActiveId(id);
}
}
@autobind
handleDialogNodeClick(
e: React.MouseEvent<HTMLAnchorElement>,
option: Schema
) {
// const store = this.props.store;
// store.setPreviewDialogId(option.$$id);
}
@autobind
handleEnter(e: React.MouseEvent) {
const dom = e.currentTarget;
const id = dom.getAttribute('data-node-id')!;
const region = dom.getAttribute('data-node-region')!;
const store = this.props.store;
store.setHoverId(id, region);
}
@autobind
handleTabChange(key: string) {
const store = this.props.store;
if (key && isAlive(store)) {
store.changeOutlineTabsKey(key);
// if (key === 'component-outline') {
// store.setPreviewDialogId();
// }
}
}
@autobind
handleDragStart(e: React.DragEvent) {
const id = e.currentTarget!.getAttribute('data-node-id')!;
if (!id) {
return;
}
this.props.manager.startDrag(id, e);
}
timer: any;
@autobind
handleDragEnter(e: React.DragEvent) {
// this.dragEnterCount++;
const target = e.target as HTMLElement;
const dom = target.closest(`[data-node-id][data-node-region]`);
if (!dom) {
return;
}
e.preventDefault();
// 避免切换太快
clearTimeout(this.timer);
this.timer = setTimeout(() => {
const manager = this.props.manager;
const id = dom.getAttribute('data-node-id')!;
const region = dom.getAttribute('data-node-region')!; // 大纲树中的容器节点
id &&
region &&
manager.dnd.switchToRegion(e.nativeEvent, id, region, true);
}, 100);
}
// @autobind
// handleDragLeave() {
// this.dragEnterCount--;
// }
@autobind
handleDragOver(e: React.DragEvent) {
// const target = e.target as HTMLElement;
// const dom = target.closest(`[data-node-id][data-node-region]`);
// if (!dom) {
// return;
// }
// const manager = this.props.manager;
// const id = dom.getAttribute('data-node-id')!;
// const region = dom.getAttribute('data-node-region')!; // 大纲树中的容器节点
// 这个得有,否则无法触发 drop 事件
e.preventDefault();
// id && region && manager.dnd.switchToRegion(e.nativeEvent, id, region);
}
@autobind
handleDrop(e: React.DragEvent) {
const manager = this.props.manager;
manager.dnd.drop(e.nativeEvent);
}
@autobind
handleSearchElemKeyChange(searchVal: string) {
this.setState({
curSearchElemKey: searchVal
});
}
@autobind
clearSearchElemKey() {
this.setState({
curSearchElemKey: ''
});
}
@autobind
renderTitleByKeyword(rendererTitle: string, curSearchTitle: string) {
if (curSearchTitle && ~rendererTitle.indexOf(curSearchTitle)) {
const keywordStartIndex = rendererTitle.indexOf(curSearchTitle);
const keywordEndIndex = keywordStartIndex + curSearchTitle.length;
return (
<span>
{rendererTitle.substring(0, keywordStartIndex)}
<span className="has-keywords">{curSearchTitle}</span>
{rendererTitle.substring(keywordEndIndex)}
</span>
);
} else {
return rendererTitle;
}
}
renderItem(
option: EditorNodeType,
index: number,
type?: 'dialog' | 'dialogView',
indent = 0
) {
const store = this.props.store;
const {curSearchElemKey} = this.state;
const children = /*!store.dragging && */ (
option.singleRegion
? option.uniqueChildren[0]!.uniqueChildren
: option.uniqueChildren
) as Array<EditorNodeType>;
const hasChildren = children.length;
// if (store.dragging && !option.isRegion && !option.children.length) {
// return null;
// }
return (
<li
style={{'--indent': indent} as any}
className={cx('ae-Outline-node', {
'is-folded': option.folded,
'is-active':
(store.activeId === option.id && !option.region) ||
(option.isRegion &&
store.dropId === option.id &&
store.dropRegion === option.region) ||
(option.isRegion &&
store.activeId === option.id &&
store.activeRegion === option.region),
'is-region': option.isRegion,
'is-hover': !option.isRegion && store.isContextOn(option.id),
'has-children': hasChildren
// 'is-dragging':
// store.dragId === option.id && store.dragType === 'schema'
})}
key={index}
>
<a
onClick={this.handleClick}
onMouseEnter={this.handleEnter}
data-node-id={option.id}
data-node-region={option.region}
data-node-common-config={option.schema?.$$commonSchema}
data-node-form-config={option.schema?.$$formSchema}
draggable={option.draggable}
onDragStart={this.handleDragStart}
>
{hasChildren ? (
<span
onClick={option.toggleFold}
className={cx('ae-Outline-expander ae-Outline-node-icon', {
'is-folded': option.folded
})}
data-node-id={option.id}
data-node-region={option.region}
>
<Icon icon="down-arrow" />
</span>
) : (
<span className={cx('ae-Outline-textIndent')}></span>
)}
<span className="ae-Outline-node-text">
{option.isCommonConfig
? `${option.label}-[公共配置]`
: option.isFormConfig
? `${option.label}-[表单配置]`
: this.renderTitleByKeyword(
this.getDialogNodeLabel(option, type),
curSearchElemKey
)}
</span>
</a>
{hasChildren ? (
<ul className="ae-Outline-sublist">
{children.map((option, index) =>
this.renderItem(option, index, type, indent + 1)
)}
</ul>
) : null}
</li>
);
}
renderDropItem(option: EditorNodeType, index: number) {
const children = option.uniqueChildren as Array<EditorNodeType>;
const store = this.props.store;
// 当前是当前正拖拽的元素,则不显示
if (store.dragId && option.id === store.dragId) {
return null;
}
const doms: any = children
.map((option, index) => this.renderDropItem(option, index))
.filter(item => item);
if (!doms.length && !option.isRegion) {
return null;
} else if (option.isRegion) {
return (
<div
className={cx('ae-Outline-dropNode', {
'is-active':
store.dropId === option.id && store.dropRegion === option.region
})}
data-node-id={option.id}
data-node-region={option.region}
key={`${option.id}-${index}`}
>
<a>
{option.host.singleRegion
? option.host.label
: `(${option.host.label})${option.label}`}
</a>
{doms}
</div>
);
} else {
return doms;
}
}
getDialogNodeLabel(option: EditorNodeType, type?: 'dialog' | 'dialogView') {
if (!type) {
return option.label;
} else {
return this.getDialogLabel(option, true, 'dialogTitle');
}
}
getDialogLabel(
option: any,
isNode: boolean,
title: 'title' | 'dialogTitle' = 'title'
) {
let rendererTitle = '';
if (isNode) {
rendererTitle = option.label;
}
if (option.type === 'dialog' || option.type === 'drawer') {
if (!isNode || (isNode && !option.region)) {
const titleStr = translateSchema(option[title]);
if (option.type === 'drawer') {
rendererTitle = `${titleStr || '抽屉式弹窗'}(抽屉式弹窗)`;
} else {
if (option.dialogType === 'confirm') {
rendererTitle = `${titleStr || '确认对话框'}(确认对话框)`;
} else {
rendererTitle = `${titleStr || '弹窗'}(弹窗)`;
}
}
}
}
return rendererTitle;
}
renderDialogItem(option: any, index: number) {
// const store = this.props.store;
// const children = store.root.children;
// const isSelectedDialog = option.$$id === store.previewDialogId;
const dialogLabel = this.getDialogLabel(option, false);
return (
<li className={cx('ae-Outline-node')} key={index}>
<a onClick={e => this.handleDialogNodeClick(e, option)}>
<span className="ae-Outline-node-text">
{this.renderTitleByKeyword(
dialogLabel,
this.state.curSearchElemKey
)}
</span>
</a>
</li>
);
}
render() {
const {curSearchElemKey} = this.state;
const {store, manager} = this.props;
const outlineTabsKey = store.outlineTabsKey || 'component-outline';
const options = store.outline;
return (
<div className="ae-Outline-panel">
<div className="panel-header">视图结构</div>
<Tabs
className="ae-outline-tabs"
linksClassName="ae-outline-tabs-header"
contentClassName="ae-outline-tabs-content"
tabsMode="line"
onSelect={this.handleTabChange}
activeKey={outlineTabsKey}
>
<Tab
className={'ae-outline-tabs-panel'}
key={'component-outline'}
eventKey={'component-outline'}
title={'组件大纲'}
>
<InputBox
className="editor-InputSearch"
value={curSearchElemKey}
onChange={this.handleSearchElemKeyChange}
placeholder={'查询页面元素'}
clearable={false}
>
{curSearchElemKey ? (
<a onClick={this.clearSearchElemKey}>
<Icon icon="close" className="icon" />
</a>
) : (
<Icon icon="editor-search" className="icon" />
)}
</InputBox>
<hr className="margin-top" />
<div
className={cx('ae-Outline', 'hoverShowScrollBar', {
'ae-Outline--draging': store.dragging
})}
onDragOver={this.handleDragOver}
onDragEnter={this.handleDragEnter}
// onDragLeave={this.handleDragLeave}
onDrop={this.handleDrop}
>
{store.dragging ? (
<div className="ae-Outline-tip">可拖入以下区域固定拖入容器</div>
) : null}
{options.length ? (
store.dragging ? (
<div className="ae-Outline-drop">
{options.map((option, index) =>
this.renderDropItem(option, index)
)}
</div>
) : (
<ul className="ae-Outline-list">
{options.map((option, index) =>
this.renderItem(option, index)
)}
</ul>
)
) : (
<div>加载中,请稍等...</div>
)}
</div>
</Tab>
{store.isSubEditor || store.noDialog ? null : (
<Tab
className={'ae-outline-tabs-panel'}
key={'dialog-outline'}
eventKey={'dialog-outline'}
title={'弹窗列表'}
>
<DialogList manager={manager} store={store} classnames={cx} />
</Tab>
)}
</Tabs>
</div>
);
}
}

View File

@@ -0,0 +1,273 @@
import {Html, render, TestIdBuilder, TooltipWrapper} from 'amis';
import {observer} from 'mobx-react';
import React from 'react';
import cx from 'classnames';
import {Icon} from '../../icons/index';
import SearchRendererPanel from '../base/SearchRendererPanel';
import SearchCustomRendererPanel from '../base/SearchCustomRendererPanel';
import {autobind, noop, isHasPluginIcon} from '../../util';
import {EditorStoreType} from '../../store/editor';
import {EditorManager} from '../../manager';
import {SubRendererInfo} from '../../plugin';
type PanelProps = {
store: EditorStoreType;
manager: EditorManager;
groupedRenderers: {
[propName: string]: Array<SubRendererInfo>;
};
searchRendererType: string;
className?: string;
testIdBuilder?: TestIdBuilder;
};
type PanelStates = {
toggleCollapseFolderStatus: boolean;
};
@observer
export default class RenderersPanel extends React.Component<
PanelProps,
PanelStates
> {
state = {
toggleCollapseFolderStatus: false // 用于触发重新渲染组件面板的
};
// 用于记录组件分类面板的折叠状态
curCollapseFolded: {
[propName: string]: boolean;
} = {};
// 暂未使用
@autobind
handleRegionFilterClick(e: React.MouseEvent) {
let region = e.currentTarget.getAttribute('data-value')!;
const {store, manager} = this.props;
region = region === store.subRendererRegion ? '' : region;
manager.switchToRegion(region);
}
@autobind
handleDragStart(e: React.DragEvent, label: string) {
const current = e.currentTarget;
const id = current.getAttribute('data-id')!;
e.dataTransfer.setData(`dnd-dom/[data-id="${id}"]`, '');
// 将鼠标位置调整到最左侧,以免拖入的时候挡住容器信息引来混淆
e.dataTransfer!.setDragImage(e.target as any, 0, 0);
// 增加默认拖拽过程中元素
e.dataTransfer!.effectAllowed = 'copy';
}
// 组件点选使用
@autobind
handleClick(e: React.MouseEvent) {
const id = e.currentTarget.getAttribute('data-dnd-id')!;
this.props.manager.addElem(id);
}
// 改变折叠状态
@autobind
changeCollapseFoldStatus(tagKey: string, event: any) {
this.curCollapseFolded[tagKey] = !this.curCollapseFolded[tagKey];
this.setState({
toggleCollapseFolderStatus: !this.state.toggleCollapseFolderStatus
});
event.preventDefault();
event.stopPropagation();
}
renderThumb(schema: any) {
const manager = this.props.manager;
return schema ? (
render(
schema,
{
onAction: noop
},
manager.env
)
) : (
<p>没有预览图</p>
);
}
render() {
const {store, searchRendererType, className, testIdBuilder} = this.props;
const grouped = this.props.groupedRenderers || {};
const keys = Object.keys(grouped);
return (
<div className={cx('ae-RendererList', className)}>
{searchRendererType === 'renderer' && (
<SearchRendererPanel store={store} />
)}
{searchRendererType === 'custom-renderer' && (
<SearchCustomRendererPanel store={store} />
)}
<hr className="margin-top" />
{/* {node.childRegions.length ? (
<div className="ae-RegionFilter">
区域:
{node.childRegions.map(region => (
<div
className={
store.subRendererRegion === region.region ? 'is-active' : ''
}
data-value={region.region}
onClick={this.handleRegionFilterClick}
key={region.region}
>
{region.label}
</div>
))}
</div>
) : null} */}
{/*<div className="ae-RendererList-tip">
请选择以下组件拖入「{node?.label}」中
</div>*/}
<div className="ae-RendererList-groupWrap hoverShowScrollBar">
{keys.length ? (
keys.map((tag, index) => {
const items = grouped[tag];
if (!items || !items.length) {
return null;
}
return (
<React.Fragment key={tag}>
<div
key={`${tag}-head`}
className={'ae-RendererList-head collapse-header'}
onClick={(event: any) => {
this.changeCollapseFoldStatus(tag, event);
}}
>
{tag}
<div
className={cx('expander-icon', {
'is-folded': !!this.curCollapseFolded[tag]
})}
title={
!!this.curCollapseFolded[tag] ? '点击展开' : '点击折叠'
}
>
<Icon icon="right-arrow-bold" />
</div>
</div>
<div
key={`${tag}-content`}
className={cx('ae-RendererList-group collapse-content', {
'is-folded': !!this.curCollapseFolded[tag]
})}
>
{items.map((item: any) => {
const key = `${index}_${item.id}`;
const usePluginIcon = isHasPluginIcon(item);
const testid = `editor-renderer-${item.plugin.rendererName}`;
return (
<div
key={key}
className="ae-RendererList-item"
draggable
data-id={key}
data-dnd-type="subrenderer"
data-dnd-id={item.id}
data-dnd-data={JSON.stringify(
item.scaffold || {type: item.type}
)}
onDragStart={(e: React.DragEvent) =>
this.handleDragStart(e, item.name)
}
{...testIdBuilder?.getChild(testid).getTestId()}
>
<div
className="icon-box"
data-dnd-id={item.id}
title={`点击添加「${item.name}」`}
onClick={this.handleClick}
>
{usePluginIcon && <Icon icon={item.pluginIcon} />}
{!usePluginIcon && (
<i
className={cx(
'fa-fw',
item.icon || 'fa fa-circle-thin'
)}
/>
)}
</div>
<div
className="ae-RendererInfo"
data-dnd-id={item.id}
onClick={this.handleClick}
>
{item.name}
</div>
<TooltipWrapper
tooltipClassName="ae-RendererThumb"
trigger="hover"
rootClose={true}
placement="right"
tooltip={{
offset: [10, 0], // x轴偏移,避免遮挡边框
children: () => (
<div>
<div className="ae-Renderer-title">
{item.name}
</div>
{item.description || item.docLink ? (
<div className="ae-Renderer-info">
<Html
html={
item.description
? item.description
: ''
}
/>
{item.docLink && (
<a
target="_blank"
href={
store.amisDocHost + item.docLink
}
>
详情
</a>
)}
</div>
) : null}
<div className="ae-Renderer-preview">
{this.renderThumb(item.previewSchema)}
</div>
</div>
)
}}
>
<div className="ae-RendererIcon">
<Icon icon="editor-help" className="icon" />
</div>
</TooltipWrapper>
</div>
);
})}
</div>
</React.Fragment>
);
})
) : (
<span>没有找到可用组件,您可以换个关键字继续查找。</span>
)}
</div>
</div>
);
}
}

View File

@@ -0,0 +1,195 @@
import {observer} from 'mobx-react';
import React from 'react';
import {Tab, Tabs, toast} from 'amis';
import cx from 'classnames';
import {EditorManager} from '../../manager';
import {EditorStoreType} from '../../store/editor';
import {Icon} from '../../icons/index';
import {autobind, isHasPluginIcon} from '../../util';
import {findDOMNode} from 'react-dom';
import {PanelItem} from '../../plugin';
import {WidthDraggableBtn} from '../base/WidthDraggableBtn';
export interface RightPanelsProps {
store: EditorStoreType;
manager: EditorManager;
theme?: string;
appLocale?: string;
amisEnv?: any;
readonly?: boolean;
}
interface RightPanelsStates {
isOpenStatus: boolean;
isFixedStatus: boolean;
}
@observer
export class RightPanels extends React.Component<
RightPanelsProps,
RightPanelsStates
> {
constructor(props: any) {
super(props);
this.state = {
isOpenStatus: true, // 默认展开
isFixedStatus: false // 默认非fixed模式
};
}
@autobind
handleFixed() {
this.setState({
isFixedStatus: !this.state.isFixedStatus
});
}
@autobind
handleSelect(key: string) {
const store = this.props.store;
store.changePanelKey(key);
}
@autobind
handleHidden() {
this.setState({
isOpenStatus: !this.state.isOpenStatus
});
}
@autobind
getPopOverContainer() {
return findDOMNode(this) as HTMLElement;
}
@autobind
handlePanelChangeValue(
...arg: Parameters<typeof this.props.manager.panelChangeValue>
) {
const {manager} = this.props;
manager.panelChangeValue(...arg);
}
render() {
const {store, manager, theme, readonly} = this.props;
const {isOpenStatus, isFixedStatus} = this.state;
const panels = store.getPanels();
const id = store.activeId;
const node = store.getNodeById(id);
const panelKey = store.getPanelKey();
const renderPanel = (panel: PanelItem) => {
return panel.render ? (
panel.render({
id,
info: node?.info,
path: node?.path,
node: node,
value: store.value,
onChange: this.handlePanelChangeValue,
store: store,
manager: manager,
popOverContainer: this.getPopOverContainer,
readonly
})
) : panel.component ? (
<panel.component
node={node}
key={panel.key}
id={id}
info={node?.info}
path={node?.path}
value={store.value}
onChange={this.handlePanelChangeValue}
store={store}
manager={manager}
popOverContainer={this.getPopOverContainer}
readonly={readonly}
/>
) : null;
};
return panels.length > 0 ? (
<div
className={cx(
'editor-right-panel width-draggable',
'AMISCSSWrapper',
panels.length > 1 ? 'mul-tabs-panel' : '',
isOpenStatus ? '' : 'hidden-status',
isFixedStatus ? 'fixed-status' : ''
)}
>
<div
className={`editor-panel-btn`}
editor-tooltip={isFixedStatus ? '关闭悬浮模式' : '开启悬浮模式'}
tooltip-position="left"
>
<Icon
icon={isFixedStatus ? 'editor-fixed' : 'editor-no-fixed'}
className="panel-btn"
onClick={this.handleFixed}
/>
</div>
<div className="editorPanel-inner">
{panels.length === 1 ? (
renderPanel(panels[0])
) : (
<Tabs
theme={theme}
tabsMode="sidebar"
sidePosition="right"
className="editorPanel-tabs"
linksClassName="editorPanel-tabs-header"
contentClassName="editorPanel-tabs-content"
activeKey={panelKey}
onSelect={this.handleSelect}
>
{panels.map(panel => {
const usePluginIcon = isHasPluginIcon(panel);
return (
<Tab
key={panel.key}
eventKey={panel.key}
// title={panel.title}
// icon={panel.icon}
title={
<span
className="editor-tab-icon"
editor-tooltip={panel.title}
tooltip-position="left"
>
{usePluginIcon && (
<Icon
icon={panel.pluginIcon}
className="pluginIcon"
/>
)}
{!usePluginIcon && (
<Icon icon={panel.icon} className="fa" />
)}
</span>
}
className={`editorPanel-tabs-pane ae-Editor-${panel.key}Pane`}
mountOnEnter={true}
unmountOnExit={false}
>
{renderPanel(panel)}
</Tab>
);
})}
</Tabs>
)}
</div>
<WidthDraggableBtn isLeftDragIcon={true} />
<div
className={cx(
'right-panel-arrow',
isOpenStatus ? '' : 'hidden-status'
)}
onClick={this.handleHidden}
></div>
</div>
) : null;
}
}

View File

@@ -0,0 +1,58 @@
/**
* 显示可以作为 target 的名称列表
*/
import {observer} from 'mobx-react';
import cx from 'classnames';
import React from 'react';
import {PanelProps} from '../../plugin';
import {autobind} from '../../util';
@observer
export class TargetNamePanel extends React.Component<PanelProps> {
@autobind
handleClick(e: React.MouseEvent<HTMLElement>) {
const {store, manager} = this.props;
const editorId = e.currentTarget.getAttribute('data-targetname-id');
store.setActiveId(editorId!);
}
@autobind
handleEnter(e: React.MouseEvent<HTMLElement>) {
const {store, manager} = this.props;
const editorId = e.currentTarget.getAttribute('data-targetname-id');
store.setHoverId(editorId!);
}
render() {
const {store, manager} = this.props;
const targetNames = this.props.store.targetNames;
return (
<div className="ae-TargetName">
<span>当表单、列表等组件有名字时会出现在这里方便选择</span>
<ul className="ae-TargetName-list">
{targetNames.map(targetName => {
const editorId = targetName.editorId;
return (
<li
className={cx('ae-TargetName-node', {
'is-active': store.activeId === editorId,
'is-hover': store.isHoved(editorId)
})}
data-targetname-id={editorId}
onMouseEnter={this.handleEnter}
onClick={this.handleClick}
key={editorId}
>
<span className="label label-info pull-right">
{targetName.type}
</span>
<a>{targetName.name}</a>
</li>
);
})}
</ul>
</div>
);
}
}

View File

@@ -0,0 +1,89 @@
import React from 'react';
import {EditorManager} from '../manager';
import {EditorStoreType} from '../store/editor';
import {
render,
Modal,
getTheme,
Icon,
Spinner,
Button,
Overlay,
PopOver
} from 'amis';
import {observer} from 'mobx-react';
import {diff} from '../util';
import {createObject} from 'amis-core';
export interface PopOverFormProps {
store: EditorStoreType;
manager: EditorManager;
theme?: string;
}
@observer
export class PopOverForm extends React.Component<PopOverFormProps> {
overlay = React.createRef<any>();
buildSchema() {
const {store} = this.props;
const popOverFormContext = store.popOverForm!;
return {
type: 'form',
wrapWithPanel: false,
mode: 'normal',
wrapperComponent: 'div',
body: popOverFormContext.body,
submitOnChange: true,
autoFocus: true,
onFinished: (newValue: any) => {
popOverFormContext.callback?.(
newValue,
diff(popOverFormContext.value, newValue)
);
setTimeout(() => this.overlay.current?.updatePosition(), 200);
}
};
}
render() {
const {store, theme, manager} = this.props;
const popOverFormContext = store.popOverForm;
return (
<Overlay
target={popOverFormContext?.target}
placement={
'left-bottom-left-top left-top-left-bottom right-bottom-right-top right-top-right-bottom center'
}
show={!!popOverFormContext}
ref={this.overlay}
>
<PopOver
overlay
className="ae-Editor-popOverForm"
onHide={store.closePopOverForm}
>
{popOverFormContext ? (
render(
this.buildSchema(),
{
data: createObject(store.ctx, popOverFormContext?.value),
node: popOverFormContext?.node,
manager
},
{
...manager.env,
session: 'popover-form',
theme: theme
}
)
) : (
<p>Loading...</p>
)}
</PopOver>
</Overlay>
);
}
}

View File

@@ -0,0 +1,874 @@
import {
render,
toast,
resolveRenderer,
Modal,
Icon,
resizeSensor,
Spinner
} from 'amis';
import React, {Component} from 'react';
import cx from 'classnames';
import {autobind, guid, noop, reactionWithOldValue} from '../util';
import {clearStoresCache, RenderOptions} from 'amis-core';
import type {Schema} from 'amis';
import {EditorStoreType} from '../store/editor';
import {observer} from 'mobx-react';
import {EditorManager} from '../manager';
import HighlightBox from './HighlightBox';
import RegionHighlightBox from './RegionHLBox';
import {ErrorRenderer} from './base/ErrorRenderer';
import {isAlive} from 'mobx-state-tree';
import {findTree} from 'amis-core';
import BackTop from './base/BackTop';
import {reaction} from 'mobx';
import type {RendererConfig} from 'amis-core';
import IFramePreview from './IFramePreview';
import {SchemaRenderer} from './SchemaRenderer';
export interface PreviewProps {
// isEditorEnabled?: (
// info: any,
// path: string,
// renderer: any,
// schema: any
// ) => boolean;
theme?: string;
/** 应用语言类型 */
appLocale?: string;
amisEnv?: any;
className?: string;
editable?: boolean;
isMobile?: boolean;
store: EditorStoreType;
manager: EditorManager;
data?: any;
autoFocus?: boolean;
toolbarContainer?: () => any;
readonly?: boolean;
ref?: any;
}
export interface PreviewState {
ready?: boolean;
}
@observer
export default class Preview extends Component<PreviewProps> {
currentDom = React.createRef<HTMLDivElement>();
dialogReaction: any;
env: RenderOptions = {
...this.props.manager.env,
notify: (type, msg, conf) => {
if (this.props.editable) {
console.warn('[Notify]', type, msg);
return;
}
toast[type]
? toast[type](msg, conf || (type === 'error' ? '系统错误' : '系统消息'))
: console.warn('[Notify]', type, msg);
},
theme: this.props.theme,
session: `preview-${this.props.manager.id}`,
rendererResolver: this.rendererResolver.bind(this)
};
doingSelection = false;
componentDidMount() {
const currentDom = this.currentDom.current!;
currentDom.addEventListener('mouseleave', this.handleMouseLeave);
currentDom.addEventListener('mousemove', this.handleMouseMove);
currentDom.addEventListener('click', this.handleClick, true);
currentDom.addEventListener('dblclick', this.handleDBClick, true);
currentDom.addEventListener('mouseover', this.handeMouseOver);
currentDom.addEventListener('mousedown', this.handeMouseDown);
currentDom.addEventListener('submit', this.handleSubmit);
this.props.manager.on('after-update', this.handlePreviewViewChange);
}
componentWillUnmount() {
if (this.currentDom.current) {
const currentDom = this.currentDom.current!;
currentDom.removeEventListener('mouseleave', this.handleMouseLeave);
currentDom.removeEventListener('mousemove', this.handleMouseMove);
currentDom.removeEventListener('click', this.handleClick, true);
currentDom.removeEventListener('dblclick', this.handleDBClick, true);
currentDom.removeEventListener('mouseover', this.handeMouseOver);
currentDom.removeEventListener('mousedown', this.handeMouseDown);
currentDom.removeEventListener('submit', this.handleSubmit);
this.props.manager.off('after-update', this.handlePreviewViewChange);
this.dialogReaction?.();
}
setTimeout(() => clearStoresCache([this.env.session!]), 500);
}
unSensor?: () => void;
layer?: HTMLDivElement;
scrollLayer?: HTMLDivElement;
@autobind
handleLayerScroll(e: WheelEvent) {
e.preventDefault();
e.stopPropagation();
const store = this.props.store;
const iframe = store.getIframe();
if (iframe) {
iframe.contentWindow?.scrollTo({
top: iframe.contentWindow?.scrollY + e.deltaY,
behavior: 'smooth'
});
this.handlePreviewViewChange();
} else {
this.scrollLayer?.scrollTo({
top: this.scrollLayer.scrollTop + e.deltaY,
behavior: 'smooth'
});
}
}
@autobind
contentsRef(ref: HTMLDivElement | null) {
if (ref) {
this.layer = ref
.closest('.ae-Preview')!
.querySelector('.ae-Preview-widgets') as HTMLDivElement;
this.unSensor = resizeSensor(ref, this.handlePreviewViewChange);
if (this.props.isMobile) {
ref = ref.firstChild as HTMLDivElement;
}
this.scrollLayer = ref as HTMLDivElement;
this.scrollLayer.removeEventListener(
'scroll',
this.handlePreviewViewChange
);
this.scrollLayer.addEventListener('scroll', this.handlePreviewViewChange);
this.props.store.setLayer(this.layer);
this.layer.addEventListener('wheel', this.handleLayerScroll, true);
} else {
this.layer?.removeEventListener('wheel', this.handleLayerScroll, true);
this.scrollLayer?.removeEventListener(
'scroll',
this.handlePreviewViewChange
);
delete this.scrollLayer;
delete this.layer;
this.unSensor?.();
delete this.unSensor;
}
}
// 优化这块
readonly unReaction: () => void = reactionWithOldValue(
() => [this.getHighlightNodes(), this.props.store.activeId],
([ids]: [Array<string>], oldValue: [Array<string>]) => {
const store = this.props.store;
// requestAnimationFrame(() => {
// this.calculateHighlightBox(ids);
// });
store.activeHighlightNodes(ids);
let oldIds = oldValue?.[0];
if (Array.isArray(oldIds)) {
oldIds = oldIds.filter(id => !~ids.indexOf(id));
store.deActiveHighlightNodes(oldIds);
// store.resetHighlightBox(oldIds);
}
}
);
@autobind
handlePreviewViewChange() {
if (this.layer && this.scrollLayer) {
requestAnimationFrame(() => {
if (!this.layer) {
return;
}
this.layer!.style.cssText += `transform: translate(0, -${
this.scrollLayer!.scrollTop
}px);`;
});
}
requestAnimationFrame(() =>
this.calculateHighlightBox(this.getHighlightNodes())
);
}
getHighlightNodes() {
const store = this.props.store;
return store.highlightNodes.map(item => item.id);
}
@autobind
calculateHighlightBox(ids: Array<string>) {
const store = this.props.store;
this.layer && store.calculateHighlightBox(ids);
}
@autobind
handeMouseDown(e: MouseEvent) {
const isLeftButton =
(e.button === 1 && window.event !== null) || e.button === 0;
if (!this.props.editable || !isLeftButton || e.defaultPrevented) return;
// todo highlight 改成可拖拽后,框选逻辑异常了,需要修复
const store = this.props.store;
if (
e.defaultPrevented ||
(e.target as HTMLElement)?.closest('[draggable]') ||
store.activeElement
) {
return;
}
const dom = this.layer as HTMLElement;
if (!dom) {
return;
}
let cursor: HTMLDivElement | null = null;
const rect = dom.getBoundingClientRect();
const startX = e.pageX;
const startY = e.pageY;
const x = startX - rect.left;
const y = startY - rect.top;
let onMove = (e: MouseEvent) => {
if (!cursor) {
cursor = document.createElement('div');
cursor.classList.add('ae-Editor-selectionCursor');
dom.appendChild(cursor);
}
this.doingSelection = true;
const w = e.pageX - startX;
const h = e.pageY - startY;
cursor.style.cssText = `left: ${x + Math.min(w, 0)}px; top: ${
y + Math.min(h, 0)
}px; width: ${Math.abs(w)}px; height: ${Math.abs(h)}px;`;
};
let onUp = (e: MouseEvent) => {
this.doingSelection = false;
window.removeEventListener('mousemove', onMove);
window.removeEventListener('mouseup', onUp);
cursor && dom.removeChild(cursor);
const w = e.pageX - startX;
const h = e.pageY - startY;
const rect = {
x: x + Math.min(w, 0),
y: y + Math.min(h, 0),
w: Math.abs(w),
h: Math.abs(h)
};
if (Math.hypot(w, h) < 10) {
return;
}
// 阻止 click 事件触发。
let captureClick = (e: MouseEvent) => {
window.removeEventListener('click', captureClick, true);
e.preventDefault();
e.stopPropagation();
};
window.addEventListener('click', captureClick, true);
setTimeout(
() => window.removeEventListener('click', captureClick, true),
350
);
this.doSelection(rect);
};
window.addEventListener('mousemove', onMove);
window.addEventListener('mouseup', onUp);
}
/** 拖拽多选 */
doSelection(rect: {x: number; y: number; w: number; h: number}) {
const layer = this.layer;
const dom = this.currentDom.current;
if (!layer || !dom) {
return;
}
const selections: Array<HTMLElement> = [];
const layerRect = layer.getBoundingClientRect();
const frameRect = {
left: rect.x + layerRect.left,
top: rect.y + layerRect.top,
width: rect.w,
height: rect.h,
right: rect.x + layerRect.left + rect.w,
bottom: rect.y + layerRect.top + rect.h
};
const nodes = dom.querySelectorAll(`[data-editor-id]`);
[].slice.apply(nodes).forEach((node: HTMLElement) => {
if (selections.some(container => container.contains(node))) {
return;
}
const nodeRect = node.getBoundingClientRect();
// 完全包含
if (
frameRect.left <= nodeRect.left &&
frameRect.top <= nodeRect.top &&
frameRect.right >= nodeRect.right &&
frameRect.bottom >= nodeRect.bottom
) {
~selections.indexOf(node) || selections.push(node);
}
});
const ids = selections
.map(item => item.getAttribute('data-editor-id')!)
.filter((id: string, idx, list) => list.indexOf(id) === idx);
ids.length && this.props.manager.setSelection(ids);
}
@autobind
handleClick(e: MouseEvent) {
const store = this.props.store;
// 处于编辑态时,不响应点击事件
if (store.activeElement) {
// 同时阻止渲染器里面的 click 事件
e.preventDefault();
return;
}
if (
(e.target as HTMLElement).closest(
'.ae-editor-action-btn,.ae-Editor-toolbarPopover '
)
) {
// 设计器内容区中允许点击的元素,比如:回到顶部功能按钮。
// 或者高亮区的操作按钮
return;
}
if (e.defaultPrevented) {
e.stopPropagation();
return;
}
const target = (e.target as HTMLElement).closest(
`[data-editor-id],[data-hlbox-id]`
);
if (target?.matches('[data-editor-id]')) {
const curActiveId = target.getAttribute('data-editor-id');
e.metaKey
? this.props.manager.toggleSelection(curActiveId!)
: store.setActiveId(curActiveId!);
} else if (target?.matches('[data-hlbox-id]')) {
const id = target.getAttribute('data-hlbox-id')!;
const {x, y} = this.getElementPoint(e);
let elements = store.getDoc().elementsFromPoint(x, y);
let node = elements.find(
(ele: Element) =>
ele.hasAttribute('data-editor-id') &&
ele.getAttribute('data-editor-id') !== id &&
!ele.querySelector(`[data-editor-id="${id}"]`)
);
if (node) {
const nodeId = node.getAttribute('data-editor-id')!;
// 如果已经进入了内联模式
// 不要再切选中了
setTimeout(() => {
store.activeElement || store.setActiveId(nodeId);
}, 350);
}
}
if (!this.layer?.contains(e.target as HTMLElement) && this.props.editable) {
// 让渲染器不可点,只能点击选中。
const event = this.props.manager.trigger('prevent-click', {
data: e
});
if (!event.prevented && !event.stoped) {
e.preventDefault();
e.stopPropagation();
}
}
}
@autobind
handleDBClick(e: MouseEvent) {
const store = this.props.store;
let target = e.target as HTMLElement;
let hostElem = target.closest(`[data-editor-id]`) as HTMLElement;
if (!hostElem) {
const hlbox = target.closest(`[data-hlbox-id]`) as HTMLElement;
// 自由容器里面的高亮区域是可以点击的
// 当点击来自高亮区域时,需要根据位置计算出组件上点击的元素
if (hlbox) {
const {x, y} = this.getElementPoint(e);
const elements = store.getDoc().elementsFromPoint(x, y);
target = elements.find((ele: Element) => {
hostElem = ele.closest(
`[data-editor-id="${hlbox.getAttribute('data-hlbox-id')}"]`
) as HTMLElement;
return hostElem;
}) as HTMLElement;
}
}
if (hostElem) {
const node = store.getNodeById(hostElem.getAttribute('data-editor-id')!);
if (!node) {
return;
}
e.preventDefault();
const rendererInfo = node.info;
// 需要支持 :scope > xxx 语法,所以才这么写
let inlineElem: HTMLElement | undefined | null = null;
const inlineSetting = (rendererInfo.inlineEditableElements || []).find(
elem => {
inlineElem = (
[].slice.call(
hostElem.querySelectorAll(elem.match)
) as Array<HTMLElement>
).find(dom => dom.contains(target));
return !!inlineElem;
}
)!;
// 如果命中了支持内联编辑的元素,则开始内联编辑
if (inlineElem && inlineSetting) {
const manager = this.props.manager;
manager.startInlineEdit(node, inlineElem, inlineSetting, e);
}
}
}
@autobind
handleNavSwitch(id: string) {
const store = this.props.store;
store.setActiveId(id);
}
@autobind
handleMouseMove(e: MouseEvent) {
if (this.doingSelection || this.props.manager.disableHover) {
return;
}
const store = this.props.store;
const dom = e.target as HTMLElement;
if ((e.target as HTMLElement).closest('.ignore-hover-elem')) {
// 设计器内容区中忽略hover的元素,比如:region头部标签。
return;
}
const target = dom.closest(`[data-editor-id],[data-hlbox-id]`);
if (target?.matches('[data-editor-id]')) {
const curHoverId = target.getAttribute('data-editor-id');
store.setHoverId(curHoverId!);
} else if (target?.matches('[data-hlbox-id]')) {
const {x, y} = this.getElementPoint(e);
const elements = store.getDoc().elementsFromPoint(x, y);
let hostElem: HTMLElement | null = null;
for (const ele of elements) {
hostElem = ele.closest(`[data-editor-id]`) as HTMLElement;
if (hostElem) {
break;
}
}
if (hostElem) {
// 判断当前是否在子区域
const curHoverId = hostElem.getAttribute('data-editor-id');
store.setHoverId(curHoverId!);
}
}
}
getElementPoint(e: MouseEvent) {
const store = this.props.store;
let x = e.clientX;
let y = e.clientY;
const iframe = store.getIframe();
// 计算鼠标位置在页面中的实际位置,如果iframe存在,需要考虑iframe偏移量以及iframe的缩放比例
if (iframe) {
const preview: HTMLElement = (store.getLayer() as HTMLElement)
.previousSibling?.firstChild as HTMLElement;
const previewRect = preview.getBoundingClientRect();
x -= previewRect.left;
y -= previewRect.top;
// 如果有缩放比例,重新计算位置
const scale = store.getScale();
if (scale >= 0) {
x = x / scale;
y = y / scale;
}
}
return {x, y};
}
@autobind
handleMouseLeave() {
const store = this.props.store;
store.setHoverId('');
}
@autobind
handeMouseOver(e: MouseEvent) {
if (this.props.editable) {
e.preventDefault();
e.stopPropagation();
}
}
// 禁用内部的提交事件
handleSubmit(e: Event) {
e.preventDefault();
e.stopPropagation();
}
@autobind
handleDragEnter(e: React.DragEvent) {
if (!this.props.editable) {
// 非编辑态下不监听拖拽事件
return;
}
const manager = this.props.manager;
manager.dnd.dragEnter(e.nativeEvent);
}
@autobind
handleDragLeave(e: React.DragEvent) {
if (!this.props.editable) {
return;
}
const manager = this.props.manager;
manager.dnd.dragLeave(e.nativeEvent);
}
@autobind
handleDragOver(e: React.DragEvent) {
if (!this.props.editable) {
return;
}
const manager = this.props.manager;
manager.dnd.dragOver(e.nativeEvent);
}
@autobind
handleDrop(e: React.DragEvent) {
if (!this.props.editable) {
return;
}
const manager = this.props.manager;
manager.dnd.drop(e.nativeEvent);
}
@autobind
handleWidgetsDragEnter(e: React.DragEvent) {
const target = e.target as HTMLElement;
const dom = target.closest(`[data-node-id][data-node-region].region-tip`);
if (!dom) {
return;
}
e.preventDefault();
const manager = this.props.manager;
const id = dom.getAttribute('data-node-id')!;
const region = dom.getAttribute('data-node-region')!; // 大纲树中的容器节点
id && region && manager.dnd.switchToRegion(e.nativeEvent, id, region);
}
@autobind
getCurrentTarget() {
const isMobile = this.props.isMobile;
if (isMobile) {
return this.currentDom.current!.querySelector(
'.ae-Preview-inner'
) as HTMLDivElement;
} else {
return this.currentDom.current!.querySelector(
'.ae-Preview-body'
) as HTMLDivElement;
}
}
rendererResolver(path: string, schema: Schema, props: any) {
const {editable, manager} = this.props;
let renderer: RendererConfig = resolveRenderer(path, schema)!;
if (editable === false) {
return renderer;
}
renderer = renderer || {
name: 'error',
test: () => true,
component: ErrorRenderer
};
let info = manager.getEditorInfo(renderer!, path, schema);
info &&
(renderer = {
...renderer,
component: manager.makeWrapper(info, renderer)
});
return renderer;
}
render() {
const {
className,
editable,
store,
manager,
amisEnv,
theme,
isMobile,
autoFocus,
toolbarContainer,
appLocale,
...rest
} = this.props;
const env = {
...this.env,
...amisEnv
};
return (
<div
id="editor-preview-body"
onDragEnter={this.handleDragEnter}
onDragLeave={this.handleDragLeave}
onDragOver={this.handleDragOver}
onDrop={this.handleDrop}
className={cx(
'ae-Preview',
'AMISCSSWrapper',
className,
isMobile ? 'is-mobile-body' : 'is-pc-body'
)}
ref={this.currentDom}
>
<div className={cx('ae-Preview-outter')}>
<div
key={
/* contentsLayer 逻辑不一样需要更新一下 */ isMobile
? 'mobile-body'
: 'pc-body'
}
className={cx(
'ae-Preview-body',
className,
editable ? 'is-edting' : '',
isMobile ? 'is-mobile' : 'is-pc hoverShowScrollBar'
)}
ref={this.contentsRef}
>
<div className="ae-Preview-inner">
{!store.ready ? (
<div className="ae-Preview-loading">
<Spinner overlay size="lg" />
</div>
) : isMobile ? (
<IFramePreview
{...rest}
key="mobile"
editable={editable}
store={store}
env={env}
manager={manager}
autoFocus={autoFocus}
appLocale={appLocale}
></IFramePreview>
) : (
<SmartPreview
{...rest}
editable={editable}
autoFocus={autoFocus}
store={store}
env={env}
manager={manager}
key="pc"
appLocale={appLocale}
/>
)}
</div>
{this.currentDom.current && (
<BackTop
key={isMobile ? 'mobile-back-up' : 'pc-back-up'}
className="ae-editor-action-btn"
target={this.getCurrentTarget.bind(this)}
onClick={(e: any) => {
console.log(e);
}}
>
<Icon icon="back-up" className="back-top-icon" />
</BackTop>
)}
</div>
</div>
<div
onDragEnter={this.handleWidgetsDragEnter}
className="ae-Preview-widgets"
id="aePreviewHighlightBox"
>
{store.highlightNodes.map(node => (
<HighlightBox
node={node}
key={node.id}
store={store}
id={node.id}
title={node.label}
toolbarContainer={toolbarContainer}
onSwitch={this.handleNavSwitch}
manager={manager}
readonly={this.props.readonly}
>
{node.childRegions.map(region =>
!node.memberImmutable(region.region) &&
!store.activeElement &&
!this.props.readonly &&
store.isRegionActive(region.id, region.region) ? (
<RegionHighlightBox
manager={manager}
key={region.region}
store={store}
node={region}
id={region.id}
name={region.region}
title={region.label}
preferTag={region.preferTag}
isOnlyChildRegion={node.childRegions.length === 1}
/>
) : null
)}
</HighlightBox>
))}
</div>
</div>
);
}
}
/**
* 这个用了 observer,所以能最小程度的刷新,数据不变按理是不会刷新的。
*/
export interface SmartPreviewProps {
editable?: boolean;
autoFocus?: boolean;
store: EditorStoreType;
env: any;
data?: any;
manager: EditorManager;
/** 应用语言类型 */
appLocale?: string;
}
@observer
class SmartPreview extends React.Component<SmartPreviewProps> {
dialogMountRef: React.RefObject<HTMLDivElement> = React.createRef();
componentDidMount() {
const store = this.props.store;
if (this.props.autoFocus) {
// 一般弹框动画差不多 350ms
// 延时 350ms,在弹框中展示编辑器效果要好点。
setTimeout(() => {
if (isAlive(store)) {
const first = findTree(
store.outline,
item => !item.isRegion && item.clickable
);
if (first && isAlive(store)) {
let region = first.childRegions.find(
(item: any) => item.region === 'body'
)?.region;
region =
region ?? first.childRegions.find((i: any) => i.region)?.region;
store.setActiveId(first.id, region);
}
}
}, 350);
} else {
this.props.manager.buildRenderersAndPanels();
}
}
componentDidUpdate(prevProps: SmartPreviewProps) {
const props = this.props;
if (props.editable !== prevProps.editable) {
if (props.editable) {
// 当预览状态切换到设计状态
this.props.manager.trigger('preview2editor', {
data: this.props.manager
});
}
}
}
@autobind
getDialogMountRef() {
return this.dialogMountRef.current;
}
render() {
const {editable, store, appLocale, autoFocus, env, data, manager, ...rest} =
this.props;
return (
// 弹窗挂载节点
<div ref={this.dialogMountRef} className="ae-PageWrapper">
{render(
editable ? store.filteredSchema : store.filteredSchemaForPreview,
{
globalVars: store.globalVariables,
...rest,
key: editable ? 'edit-mode' : 'preview-mode',
theme: env.theme,
data: data,
context: store.ctx,
locale: appLocale,
editorDialogMountNode: this.getDialogMountRef
},
{
...env,
session: `${env.session}-${
editable ? 'edit' : 'preview'
}-smart-preview`,
SchemaRenderer: editable ? SchemaRenderer : undefined,
enableAMISDebug: !editable
}
)}
</div>
);
}
}

View File

@@ -0,0 +1,91 @@
import React from 'react';
import cx from 'classnames';
import {Icon} from 'amis';
import {EditorStoreType} from '../store/editor';
import {observer} from 'mobx-react';
import {EditorManager} from '../manager';
import {EditorNodeType} from '../store/node';
import {autobind} from '../util';
import {isAlive} from 'mobx-state-tree';
export const AddBTNSvg = `<svg viewBox="0 0 12 12">
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="plus" fill="currentColor" fill-rule="nonzero">
<polygon points="6.6 6.6 6.6 12 5.4 12 5.4 6.6 0 6.6 0 5.4 5.4 5.4 5.4 0 6.6 0 6.6 5.4 12 5.4 12 6.6"></polygon>
</g>
</g>
</svg>`;
export interface HighlightBoxProps {
store: EditorStoreType;
node: EditorNodeType;
name: string;
id: string;
className?: string;
title: string;
preferTag?: string;
manager: EditorManager;
isOnlyChildRegion: boolean;
}
// 改成 sfc 函数组件 可以消除一个警告 但是不知道为什么
// 可以消除 Can't perform a React state update on an unmounted component
export default observer(function (props: HighlightBoxProps) {
const {manager, store, id, name, title, node, isOnlyChildRegion} = props;
const handleClick = React.useCallback(() => {
manager.emptyRegion(id, name);
}, [id, name, manager]);
let isHiglight = store.isRegionHighlighted(id, name);
let isDragEnter = store.isRegionDragEnter(id, name);
const host = store.getNodeById(id)!;
const dx = node.x - host.x;
const dy = node.y - host.y;
return (
<div
data-renderer={node.host.info.renderer.name}
data-region={name}
className={cx(
'ae-Editor-rhlbox',
isDragEnter ? 'is-dragenter' : '',
store.planDropId === id ? 'region-can-be-drop' : '',
// !isOnlyChildRegion && isHiglightHover ? 'region-hover' : '',
isOnlyChildRegion || isHiglight ? 'is-highlight' : ''
// dx < 87 && dy < 21 && node.x < 190 ? 'region-label-within' : ''
)}
style={{
width: node.w,
height: node.h,
borderWidth: `${Math.max(0, dy)}px ${Math.max(
0,
host.w - dx - node.w
)}px ${Math.max(0, host.h - dy - node.h)}px ${Math.max(0, dx)}px`
}}
>
<div
data-node-id={id}
data-node-region={name}
className={`region-tip ${
isOnlyChildRegion ? 'is-only-child-region' : ''
} ignore-hover-elem`}
>
<span className="region-text">{title}</span>
{store.dragging ? null : <span className="margin-space">|</span>}
{store.dragging ? null : (
<button
type="button"
className="clear-icon-btn"
title={''}
data-tooltip={'点击清空当前区域'}
data-position={'bottom'}
onClick={handleClick}
>
<Icon icon="clear-btn" />
</button>
)}
</div>
</div>
);
});

View File

@@ -0,0 +1,128 @@
import {isAlive} from 'mobx-state-tree';
import React from 'react';
import {findDOMNode} from 'react-dom';
import {EditorManager} from '../manager';
import {RegionConfig, RendererInfo} from '../plugin';
import {needFillPlaceholder} from '../util';
import {EditorStoreType} from '../store/editor';
import {EditorNodeContext, EditorNodeType} from '../store/node';
export interface RegionWrapperProps {
name: string;
label: string;
placeholder?: string | JSX.Element;
preferTag?: string;
wrapperResolve?: (dom: HTMLElement) => HTMLElement;
editorStore: EditorStoreType;
manager: EditorManager;
rendererName?: string;
regionConfig: RegionConfig;
node?: EditorNodeType; // 虚拟dom节点信息
$$editor?: RendererInfo; // 当前节点信息(info)
children?: React.ReactNode;
}
/**
* 1.DOM标记 添加 data-region、data-region-host 和 data-renderer 属性
* 2.构建 Node store 节点。
*/
export class RegionWrapper extends React.Component<RegionWrapperProps> {
static contextType = EditorNodeContext;
parentNode: EditorNodeType;
editorNode: EditorNodeType;
UNSAFE_componentWillMount() {
this.parentNode = (this.context as any)!;
/**
* 当前parent为空时尝试通过节点id获取当前上下文
* 备注:非react容器类自定义组件需要
*/
const {$$editor, manager} = this.props;
if (!this.parentNode && $$editor && $$editor.id) {
const curContext = manager.store.getNodeById($$editor.id);
if (curContext) {
this.parentNode = curContext;
}
}
if (!this.parentNode) {
return;
}
this.editorNode = this.parentNode.addChild({
id: this.parentNode.id,
type: this.parentNode.type,
label: this.props.label,
path: `${this.parentNode.path}/${this.props.name}`,
region: this.props.name, // regions中的key值
regionInfo: this.props.regionConfig,
preferTag: this.props.preferTag
});
}
componentDidMount() {
if (this.editorNode && isAlive(this.editorNode)) {
this.editorNode &&
this.markDom(
this.editorNode.id,
this.props.name,
this.props.rendererName
);
}
}
componentDidUpdate(prevProps: RegionWrapperProps) {
this.editorNode &&
this.markDom(
this.editorNode.id,
this.props.name,
this.props.rendererName
);
}
componentWillUnmount() {
if (this.editorNode && isAlive(this.editorNode) && this.parentNode) {
this.parentNode.removeChild(this.editorNode);
}
}
/**
* 弄点标记
*/
markDom(id: string, region: string, rendererName?: string) {
const dom = findDOMNode(this) as HTMLElement;
if (!dom) {
return;
}
const wrapperResolve = this.props.wrapperResolve;
const wrapper = wrapperResolve ? wrapperResolve(dom) : dom.parentElement!;
wrapper.setAttribute('data-region', region);
wrapper.setAttribute('data-region-host', id);
rendererName && wrapper.setAttribute('data-renderer', rendererName);
}
render() {
const isLayoutItem =
this.props.rendererName === 'wrapper' ||
this.props.rendererName === 'container';
let isNeedFillPlaceholder = false;
if (needFillPlaceholder(this.props)) {
isNeedFillPlaceholder = true;
}
return (
<EditorNodeContext.Provider value={this.editorNode}>
{this.props.children}
<span
className={`ae-Region-placeholder ${
isLayoutItem ? 'layout-content' : ''
} ${isNeedFillPlaceholder ? 'fill-placeholder' : ''}`}
>
{this.props.placeholder || this.props.label}
</span>
</EditorNodeContext.Provider>
);
}
}

View File

@@ -0,0 +1,109 @@
import type {Schema} from 'amis-core';
import {LazyComponent} from 'amis-core';
import React from 'react';
import {resizeSensor, render, Icon} from 'amis';
interface ThumbProps {
schema: Schema;
theme?: string;
env: any;
}
interface ThumbStates {
scale: Boolean;
}
export class RendererThumb extends React.Component<ThumbProps, ThumbStates> {
ref: HTMLDivElement;
unSensor: Function;
constructor(props: ThumbProps) {
super(props);
this.state = {
scale: true
};
this.rootRef = this.rootRef.bind(this);
this.syncHeight = this.syncHeight.bind(this);
this.handleClick = this.handleClick.bind(this);
}
env = {
session: 'preview',
...this.props.env
};
componentWillUnmount() {
this.unSensor && this.unSensor();
}
rootRef(ref: HTMLDivElement) {
this.ref = ref;
if (ref) {
this.syncHeight();
this.unSensor = resizeSensor(
ref.firstChild?.firstChild as HTMLElement,
this.syncHeight
);
}
}
syncHeight() {
if (!this.ref) {
return;
}
const scale = this.state.scale;
const child = this.ref.firstChild as HTMLElement;
this.ref.style.cssText = `height: ${
child.scrollHeight / (scale ? 2 : 1)
}px;`;
}
handleClick(e: React.MouseEvent) {
e.preventDefault();
this.setState({
scale: !this.state.scale
});
}
render() {
const {schema, theme} = this.props;
return (
<LazyComponent
unMountOnHidden={false}
schema={schema}
component={({schema}: {schema: Schema; [key: string]: any}) => (
<div
className={`ae-RenderersPicker-thumb ${
this.state.scale ? 'is-scaled' : ''
}`}
>
<div className="ae-Editor-rendererThumbWrap">
<div
className="ae-Editor-rendererThumbIcon"
onClick={this.handleClick}
>
<Icon icon={this.state.scale ? 'zoom-in' : 'zoom-out'} />
</div>
<div ref={this.rootRef} className={`ae-Editor-rendererThumb`}>
<div className="ae-Editor-rendererThumbInner">
{render(
{
...schema,
mode:
schema.mode === 'horizontal' ? 'normal' : schema.mode
},
{
theme
},
this.env
)}
</div>
</div>
</div>
</div>
)}
/>
);
}
}

View File

@@ -0,0 +1,319 @@
import React from 'react';
import {EditorManager} from '../manager';
import {EditorStoreType} from '../store/editor';
import {render, Modal, getTheme, Icon, Spinner, Button} from 'amis';
import {observer} from 'mobx-react';
import {autobind, isObject} from '../util';
export interface SubEditorProps {
store: EditorStoreType;
manager: EditorManager;
theme?: string;
}
@observer
export class ScaffoldModal extends React.Component<SubEditorProps> {
@autobind
async handleConfirm([values]: any) {
const store = this.props.store;
const pipeOutFunc = store.scaffoldForm?.pipeOut;
values = {
...store.scaffoldForm?.value,
...values
};
if (pipeOutFunc && typeof pipeOutFunc === 'function') {
const mapped = await pipeOutFunc(values);
values = {
...mapped
};
}
store.scaffoldForm?.callback(values);
store.closeScaffoldForm();
store.scaffoldForm?.stepsBody && store.setScaffoldStep(0);
}
buildSchema() {
const {store} = this.props;
const scaffoldFormContext = store.scaffoldForm!;
let body = scaffoldFormContext.controls ?? scaffoldFormContext.body;
if (scaffoldFormContext.stepsBody) {
body = [
{
type: 'steps',
name: '__step',
className: 'ae-Steps',
steps: body.map((step, index) => ({
title: step.title,
value: index,
iconClassName: 'ae-Steps-Icon'
}))
},
...body.map((step, index) => ({
type: 'container',
visibleOn: `__step === ${index}`,
body: step.body
}))
];
}
let layout: object;
if (isObject(scaffoldFormContext.mode)) {
layout = scaffoldFormContext.mode as object;
} else {
layout = {
mode: scaffoldFormContext.mode || 'normal'
};
}
return {
type: 'form',
wrapWithPanel: false,
initApi: scaffoldFormContext.initApi,
api: scaffoldFormContext.api,
...layout,
wrapperComponent: 'div',
[scaffoldFormContext.controls ? 'controls' : 'body']: body
};
// const {store} = this.props;
// const scaffoldFormContext = store.scaffoldForm;
// return {
// show: !!scaffoldFormContext,
// size: scaffoldFormContext?.size || 'md',
// title: scaffoldFormContext?.title,
// onClose: store.closeScaffoldForm,
// onConfirm: this.handleConfirm,
// data: createObject(store.ctx, scaffoldFormContext?.value),
// body: scaffoldFormContext
// ? {
// type: 'form',
// initApi: scaffoldFormContext.initApi,
// api: scaffoldFormContext.api,
// mode: scaffoldFormContext.mode || 'normal',
// wrapperComponent: 'div',
// onValidate: scaffoldFormContext.validate,
// [scaffoldFormContext.controls ? 'controls' : 'body']:
// scaffoldFormContext.controls ?? scaffoldFormContext.body
// }
// : {
// type: 'tpl',
// tpl: 'Loading...'
// },
// actions: [
// [
// {
// type: 'submit',
// label: '确认',
// level: 'primary'
// },
// {
// type: 'button',
// label: '取消',
// actionType: 'close'
// }
// ]
// ],
// closeOnEsc: false,
// bodyClassName: 'ae-Dialog'
// // lazyRender: true
// };
}
amisScope: any;
@autobind
scopeRef(scoped: any) {
this.amisScope = scoped;
}
@autobind
goToNextStep() {
const store = this.props.store;
const form = this.amisScope?.getComponents()[0].props.store;
const step = store.scaffoldFormStep + 1;
form.setValueByName('__step', step);
/** 切换步骤导致schema重新渲染,Form数据域中的数据会丢失 */
store.updateScaffoldData(form?.data, true);
// 控制按钮
store.setScaffoldStep(step);
// 标记是否手动操作过
store.setScaffoldStepManipulated(true);
}
@autobind
goToPrevStep() {
// 不能更新props的data,控制amis不重新渲染,否则数据会重新初始化
const store = this.props.store;
const form = this.amisScope?.getComponents()[0].props.store;
const step = store.scaffoldFormStep - 1;
form.setValueByName('__step', step);
store.updateScaffoldData(form?.data, true);
// 控制按钮
store.setScaffoldStep(step);
}
@autobind
async handleConfirmClick() {
const form = this.amisScope?.getComponents()[0];
if (!form) {
return;
}
const {store} = this.props;
try {
store.setScaffoldBuzy(true);
const values = await form.doAction(
{
type: 'submit'
},
form.props.data,
true
);
await this.handleConfirm([values]);
} catch (e) {
console.log(e.stack);
store.setScaffoldError(e.message);
}
store.setScaffoldBuzy(false);
store.setScaffoldStep(0);
}
@autobind
handleCancelClick() {
this.props.store.closeScaffoldForm();
this.props.store.setScaffoldStep(0);
}
render() {
const {store, theme, manager} = this.props;
const scaffoldFormContext = store.scaffoldForm;
const cx = getTheme(theme || 'cxd').classnames;
const isStepBody = !!scaffoldFormContext?.stepsBody;
const canSkip = !!scaffoldFormContext?.canSkip;
const isLastStep =
isStepBody &&
store.scaffoldFormStep === scaffoldFormContext!.body.length - 1;
const isFirstStep = isStepBody && store.scaffoldFormStep === 0;
return (
<Modal
theme={theme}
size={scaffoldFormContext?.size || 'md'}
contentClassName={scaffoldFormContext?.className}
show={!!scaffoldFormContext}
onHide={this.handleCancelClick}
className="ae-scaffoldForm-Modal :AMISCSSWrapper"
closeOnEsc={!store.scaffoldFormBuzy}
>
<div className={cx('Modal-header')}>
{!store.scaffoldFormBuzy ? (
<a
data-position="left"
onClick={this.handleCancelClick}
className={cx('Modal-close')}
>
<Icon icon="close" className="icon" />
</a>
) : null}
<div className={cx('Modal-title')}>{scaffoldFormContext?.title}</div>
</div>
<div className={cx('Modal-body')}>
{scaffoldFormContext ? (
render(
this.buildSchema(),
{
data: store.scaffoldData,
onValidate: scaffoldFormContext.validate,
scopeRef: this.scopeRef,
manager
},
{
...manager.env,
session: 'scaffold-dialog',
theme: theme
}
)
) : (
<p>Loading...</p>
)}
</div>
<div className={cx('Modal-footer')}>
{store.scaffoldFormBuzy || store.scaffoldError ? (
<div className={cx('Dialog-info')} key="info">
<Spinner size="sm" key="info" show={store.scaffoldFormBuzy} />
{store.scaffoldError ? (
<span className={cx('Dialog-error')}>
{store.scaffoldError}
</span>
) : null}
</div>
) : null}
{isStepBody && canSkip && isFirstStep && (
<Button
onClick={this.handleConfirmClick}
disabled={store.scaffoldFormBuzy}
>
跳过向导
</Button>
)}
{isStepBody && !isFirstStep && (
<Button
level="primary"
onClick={this.goToPrevStep}
disabled={store.scaffoldFormBuzy}
>
上一步
</Button>
)}
{isStepBody && !isLastStep && (
<Button
level="primary"
onClick={this.goToNextStep}
disabled={store.scaffoldFormBuzy}
>
下一步
</Button>
)}
{(!isStepBody || isLastStep) && (
<Button
level="primary"
onClick={this.handleConfirmClick}
disabled={store.scaffoldFormBuzy}
>
确认
</Button>
)}
<Button onClick={this.handleCancelClick}>取消</Button>
</div>
</Modal>
);
}
// _render() {
// const {store, theme, manager} = this.props;
// return render(
// {
// type: 'dialog'
// },
// this.buildSchema(),
// {
// ...manager.env,
// seesion: 'scaffold-dialog',
// theme: theme
// }
// );
// }
}

View File

@@ -0,0 +1,28 @@
import React from 'react';
import {SchemaRenderer as CoreSchemaRenderer} from 'amis-core';
// 编辑态时用这个来代替默认的组件渲染
export const SchemaRenderer = React.forwardRef((props: any, ref: any) => {
const statusStore = props.statusStore;
const proxyStatusStore = React.useMemo(() => {
return statusStore.isEditorProxy
? statusStore
: new Proxy(statusStore, {
get(target, prop, receiver) {
// 始终是可见的, 否则没法编辑了
if (prop === 'visibleState') {
return {};
} else if (prop === 'isEditorProxy') {
return true;
} else if (prop === 'raw') {
return target;
}
return Reflect.get(target, prop, receiver);
}
});
}, [statusStore]);
return (
<CoreSchemaRenderer {...props} statusStore={proxyStatusStore} ref={ref} />
);
});

View File

@@ -0,0 +1,280 @@
import React from 'react';
import {EditorManager} from '../manager';
import {EditorStoreType} from '../store/editor';
import {render} from 'amis';
import {createObject, RenderOptions} from 'amis-core';
import {observer} from 'mobx-react';
import Editor from './Editor';
import {
BuildPanelEventContext,
PluginEvent,
RendererInfoResolveEventContext
} from '../plugin';
import {autobind} from '../util';
import omit from 'lodash/omit';
export interface SubEditorProps {
store: EditorStoreType;
manager: EditorManager;
theme?: string;
amisEnv?: RenderOptions;
readonly?: boolean;
}
@observer
export class SubEditor extends React.Component<SubEditorProps> {
@autobind
afterResolveEditorInfo(event: PluginEvent<RendererInfoResolveEventContext>) {
const store = this.props.store;
const context = event.context;
const slot = store.subEditorContext?.slot;
if (!slot) {
if (
context.data &&
!context.schemaPath &&
store.subEditorContext?.memberImmutable
) {
context.data.memberImmutable = store.subEditorContext?.memberImmutable;
}
return;
}
const slotPath = store.subEditorSlotPath;
if (!~context.schemaPath.indexOf(slotPath) && context.data) {
context.data.editable = false;
context.data.memberImmutable = !Array.isArray(
store.subEditorContext?.value
);
if (!context.data.memberImmutable) {
context.data.name = '容器';
}
} else if (context.schemaPath === slotPath && context.data) {
if (!Array.isArray(store.subEditorContext?.value)) {
context.data.movable = false;
context.data.removable = false;
}
context.data.typeMutable = store.subEditorContext?.typeMutable;
}
}
@autobind
handleBuildPanels(event: PluginEvent<BuildPanelEventContext>) {
const store = this.props.store;
const slot = store.subEditorContext?.slot;
if (!slot) {
return;
}
// const slotPath = store.subEditorSlotPath;
const context = event.context;
// 成员节点固定时,不展示组件面板
if (!!context.info.memberImmutable) {
const panels = context.data.concat();
context.data.splice(0, context.data.length);
const renderersPanel = panels.filter(r => r.key !== 'renderers');
renderersPanel && context.data.push(...renderersPanel);
// 默认选中大纲
context.changeLeftPanelKey = 'outline';
}
/*
// 备注: 当前逻辑有点问题(context.schemaPath 基本上都不会含 slotPath),先注释掉。
if (!~context.schemaPath.indexOf(slotPath)) {
const panels = context.data.concat();
context.data.splice(0, context.data.length);
// 如果是slot外面,一个面板都不给。
if (!context.info.memberImmutable) {
const renderersPanel = panels.find(r => r.key === 'renderers');
renderersPanel && context.data.push(renderersPanel);
}
}
*/
}
buildSchema() {
const {store, manager, amisEnv, readonly} = this.props;
const subEditorContext = store.subEditorContext;
const config = manager.config;
let superEditorData: any = store.superEditorData;
if (!!subEditorContext) {
superEditorData = createObject(
store.superEditorData,
subEditorContext?.data
);
}
const variables: any = manager.config?.variables || [];
return {
size: 'full',
title: store.subEditorContext?.title,
onClose: store.closeSubEditor,
onConfirm: store.confirmSubEditor,
body: store.subEditorContext
? {
type: 'form',
mode: 'normal',
wrapWithPanel: false,
wrapperComponent: 'div',
onValidate: async (value: any) => {
const result = await store.subEditorContext?.validate?.(value);
if (result) {
return {
schema: result
};
}
return;
},
onChange: store.subEditorOnChange,
body: [
{
name: 'schema',
asFormItem: true,
children: ({
value,
onChange
}: {
value: any;
onChange: (value: any) => void;
}) => (
<Editor
autoFocus
value={value}
ref={store.subEditorRef}
onChange={onChange}
data={store.subEditorContext?.data}
hostManager={manager}
hostNode={store.subEditorContext?.hostNode}
superEditorData={superEditorData}
schemaFilter={manager.config.schemaFilter}
theme={manager.env.theme}
afterResolveEditorInfo={this.afterResolveEditorInfo}
onBuildPanels={this.handleBuildPanels}
isMobile={store.isMobile}
isSubEditor={true}
ctx={store.ctx}
schemas={manager.config?.schemas}
variables={variables}
amisEnv={amisEnv || config.amisEnv}
appLocale={config.appLocale}
i18nEnabled={config.i18nEnabled}
plugins={config.plugins}
actionOptions={config.actionOptions}
showCustomRenderersPanel={
store.showCustomRenderersPanel ?? true
}
isHiddenProps={config.isHiddenProps}
$schemaUrl={config.$schemaUrl}
onFormulaEditorOpen={async (
node,
subEditormanager,
data
) => {
const fn = manager?.config?.onFormulaEditorOpen;
if (fn && typeof fn === 'function') {
return fn(node, subEditormanager, data, {
node: subEditorContext?.hostNode,
manager: manager
});
}
return;
}}
getHostNodeDataSchema={async () => {
await manager.getContextSchemas(manager.store.activeId);
return manager.dataSchema;
}}
getAvaiableContextFields={node =>
manager.getAvailableContextFields(node)
}
readonly={readonly}
/>
)
},
readonly && {
type: 'button',
label: '返回编辑器',
className: 'subEditor-container-back',
onClick: () => store.closeSubEditor()
}
].filter(Boolean)
}
: {
type: 'tpl',
tpl: 'Loading...'
},
actions: [
[
{
children: subEditorContext ? (
<div className="ae-DialogToolbar">
<button
type="button"
data-tooltip="撤销"
data-position="top"
disabled={!subEditorContext.canUndo}
onClick={store.undoSubEditor}
>
<i className="fa fa-undo" />
</button>
<button
type="button"
data-tooltip="重做"
data-position="top"
disabled={!subEditorContext.canRedo}
onClick={store.redoSubEditor}
>
<i className="fa fa-rotate-right" />
</button>
</div>
) : null
},
{
type: 'submit',
label: '保存',
level: 'primary'
},
{
type: 'button',
label: '取消',
actionType: 'close'
}
]
],
closeOnEsc: false,
bodyClassName: 'ae-dialog subEditor-dialog'
// lazyRender: true
};
}
render() {
const {store, theme, manager, readonly} = this.props;
if (!store.subEditorContext) {
return null;
}
return render(
{
type: readonly ? 'container' : 'dialog',
className: readonly ? 'subEditor-container' : 'subEditor-dialog',
...this.buildSchema()
},
{
show: !!store.subEditorContext,
data: {
schema: store.subEditorValue
}
},
{
...omit(manager.env, 'replaceText'),
session: 'editor-dialog',
theme: theme
}
);
}
}

View File

@@ -0,0 +1,76 @@
/**
* @file 虚拟的渲染器,也就是说其实并不存在渲染器,而是弄个假的用来编辑。
*/
import {isAlive} from 'mobx-state-tree';
import React from 'react';
import {findDOMNode} from 'react-dom';
import {RendererInfo} from '../plugin';
import {EditorNodeContext, EditorNodeType} from '../store/node';
export interface VRendererProps extends RendererInfo {
path: string;
data?: any;
widthMutable?: boolean;
children?: React.ReactNode;
}
export class VRenderer extends React.Component<VRendererProps> {
static contextType = EditorNodeContext;
editorNode: EditorNodeType;
UNSAFE_componentWillMount() {
const {data, path, widthMutable, ...info} = this.props;
const parent: EditorNodeType = this.context as any;
this.editorNode = parent.addChild({
id: info.id,
type: info.type,
label: info.name,
path: this.props.path,
schemaPath: info.schemaPath,
info: info,
getData: () => this.props.data,
widthMutable,
memberIndex: info.memberIndex
});
}
componentDidMount() {
this.markDom(this.editorNode.id);
}
componentDidUpdate() {
this.markDom(this.editorNode.id);
}
componentWillUnmount() {
if (this.editorNode && isAlive(this.editorNode)) {
const parent: EditorNodeType = this.context as any;
parent.removeChild(this.editorNode);
}
}
/**
* 弄点标记
*/
markDom(id: string) {
const root = findDOMNode(this) as HTMLElement;
if (!root) {
return;
}
const info = this.editorNode.info!;
let dom = info.wrapperResolve ? info.wrapperResolve(root) : root;
(Array.isArray(dom) ? dom : dom ? [dom] : []).forEach(dom =>
dom.setAttribute('data-editor-id', id)
);
}
render() {
return (
<EditorNodeContext.Provider value={this.editorNode}>
{this.props.children}
</EditorNodeContext.Provider>
);
}
}

View File

@@ -0,0 +1,152 @@
import React from 'react';
import cx from 'classnames';
import omit from 'lodash/omit';
import {autobind} from '../../util';
export interface BackTopProps {
visibilityHeight?: number;
onClick?: React.MouseEventHandler<HTMLElement>;
target: () => HTMLElement | Window | Document;
children?: React.ReactNode;
className?: string;
visible?: boolean;
}
export interface BackTopStates {
visible: boolean;
}
function isWindow(obj: any) {
return obj !== null && obj !== undefined && obj === obj.window;
}
function getScroll(
target: HTMLElement | Window | Document | undefined,
top: boolean
): number {
if (typeof window === 'undefined') {
return 0;
}
const method = top ? 'scrollTop' : 'scrollLeft';
let result = 0;
const _isWindow = isWindow(target);
if (_isWindow) {
result = (target as Window)[top ? 'pageYOffset' : 'pageXOffset'];
} else if (target instanceof Document) {
result = target.documentElement[method];
} else if (target) {
result = (target as HTMLElement)[method];
}
if (target && !_isWindow && typeof result !== 'number') {
result = ((target as HTMLElement).ownerDocument || (target as Document))
.documentElement?.[method];
}
return result;
}
export default class BackTop extends React.Component<
BackTopProps,
BackTopStates
> {
ref = React.createRef<HTMLDivElement>();
scrollElem: any = null;
constructor(props: any) {
super(props);
this.state = {
visible: props.visible !== undefined ? props.visible : false
};
}
componentDidMount() {
this.bindScrollEvent();
}
componentWillUnmount() {
if (this.scrollElem) {
this.scrollElem.removeEventListener('scroll', this.handleScroll);
}
}
@autobind
getDefaultTarget() {
return this.ref.current && this.ref.current.ownerDocument
? this.ref.current.ownerDocument
: window;
}
@autobind
handleScroll(e: React.UIEvent<HTMLElement> | {target: any}) {
const visibilityHeight = this.props.visibilityHeight || 400;
const scrollTop = getScroll(e.target, true);
this.setState({
visible: scrollTop > visibilityHeight!
});
}
@autobind
bindScrollEvent() {
const {target} = this.props;
this.scrollElem = target() || this.getDefaultTarget();
if (!this.scrollElem) {
return;
}
this.scrollElem.addEventListener('scroll', this.handleScroll);
this.handleScroll({
target: this.scrollElem
});
}
@autobind
scrollToTop(e: React.MouseEvent<HTMLDivElement>) {
const {onClick} = this.props;
if (!this.scrollElem) {
return;
}
this.scrollElem.scrollTo({
top: 0,
behavior: 'smooth'
});
if (typeof onClick === 'function') {
onClick(e);
}
}
render() {
const {children, className = ''} = this.props;
const classString = cx(
'editor-backTop',
className,
this.state.visible ? '' : 'hidden'
);
const divProps = omit(this.props, [
'className',
'children',
'visibilityHeight',
'target',
'visible'
]);
const defaultElement = (
<div className="backTop-content">
<div className="backTop-icon">UP</div>
</div>
);
return (
<div
{...divProps}
className={classString}
onClick={this.scrollToTop}
ref={this.ref}
>
{children || defaultElement}
</div>
);
}
}

View File

@@ -0,0 +1,7 @@
import React from 'react';
export class ErrorRenderer extends React.Component<any> {
render() {
return <div className="ae-ErrorRenderer">类型错误,无法渲染</div>;
}
}

View File

@@ -0,0 +1,237 @@
import React from 'react';
import {EditorNodeType} from '../../store/node';
import {EditorManager} from '../../manager';
import {diff, getThemeConfig} from '../../util';
import pick from 'lodash/pick';
import {
createObjectFromChain,
createObject,
extractObjectChain,
IFormStore,
render,
toast
} from 'amis';
import omit from 'lodash/omit';
import cx from 'classnames';
export const SchemaForm = React.forwardRef(
(
{
propKey,
body,
definitions,
controls,
onChange,
value,
env,
api,
popOverContainer,
submitOnChange,
node,
manager,
justify,
ctx,
pipeIn,
pipeOut,
readonly,
disabled,
appendSubmitBtn,
...rest
}: {
propKey?: string;
env: any;
body?: Array<any>;
/**
* @deprecated 用 body 代替
*/
controls?: Array<any>;
definitions?: any;
value: any;
api?: any;
onChange: (
value: any,
diff: any,
filter: (schema: any, value: any, id: string, diff?: any) => any
) => void;
popOverContainer?: () => HTMLElement | void;
submitOnChange?: boolean;
node?: EditorNodeType;
manager: EditorManager;
panelById?: string;
justify?: boolean;
ctx?: any;
pipeIn?: (value: any) => any;
pipeOut?: (value: any, oldValue: any) => any;
readonly?: boolean;
disabled?: boolean;
appendSubmitBtn?: boolean;
inheritData?: boolean;
},
ref: any
) => {
const schema = React.useMemo(() => {
let containerKey = 'body';
if (Array.isArray(controls)) {
body = controls;
containerKey = 'controls';
}
body = Array.isArray(body) ? body.concat() : [];
if (submitOnChange === false && appendSubmitBtn !== false) {
body.push({
type: 'submit',
label: '保存',
level: 'primary',
block: true,
className: 'ae-Settings-actions'
});
}
const schema: any = {
key: propKey,
mode: 'normal',
title: '',
wrapWithPanel: false,
messages: {
validateFailed: ''
},
...pick(rest, [
'mode',
'title',
'wrapWithPanel',
'messages',
'horizontal',
'inheritData'
]),
$schema: undefined,
definitions,
[containerKey]: body,
className: cx(
'config-form-content',
'ae-Settings-content',
'hoverShowScrollBar',
submitOnChange === false ? 'with-actions' : ''
),
wrapperComponent: 'div',
name: 'schemaform',
type: 'form',
api,
submitOnChange: submitOnChange !== false
};
if (justify) {
schema.mode = 'horizontal';
schema.horizontal = {
left: 4,
right: 8,
justify: true
};
}
return schema;
}, [body, controls, submitOnChange]);
const themeConfig = React.useMemo(() => getThemeConfig(), []);
const submitSubscribers = React.useRef<Array<Function>>([]);
const subscribeSubmit = React.useCallback(
(
fn: (schema: any, value: any, id: string, diff?: any) => any,
once = false
) => {
let raw = fn;
const unsubscribe = () => {
submitSubscribers.current = submitSubscribers.current.filter(
item => ((item as any).__raw ?? item) !== raw
);
};
if (once) {
fn = (schema: any, value: any, id: string, diff?: any) => {
const ret = raw(schema, value, id, diff);
unsubscribe();
return ret;
};
(fn as any).__raw = raw;
}
submitSubscribers.current.push(fn);
return unsubscribe;
},
[]
);
const [init, setInit] = React.useState(true);
const data = React.useMemo(() => {
value = value || {};
const finalValue = pipeIn ? pipeIn(value) : value;
return createObjectFromChain([
ctx,
themeConfig,
...extractObjectChain(finalValue)
]);
}, [value, themeConfig, ctx]);
const scopedRef = React.useRef<any>(null);
const scopedRefSetter = React.useCallback((ref: any) => {
scopedRef.current = ref;
}, []);
React.useImperativeHandle(ref, () => {
return {
submit: () => {
const form = scopedRef.current?.getComponentByName('schemaform');
if (!form) {
return false;
}
return form.doAction!({type: 'submit'}, form.props.data, true);
},
flush: () => {
const form = scopedRef.current?.getComponentByName('schemaform');
if (!form) {
return false;
}
return form.flush();
}
};
});
return render(
schema,
{
onFinished: async (newValue: any, action: any, store: IFormStore) => {
newValue = pipeOut ? await pipeOut(newValue, value) : newValue;
const diffValue = diff(value, newValue);
// 没有变化时不触发onChange
if (!diffValue) {
return;
}
if (readonly && !init) {
toast.error('不支持修改');
store.setPristine(value);
store.reset();
return;
}
setInit(false);
onChange(newValue, diffValue, (schema, value, id, diff) => {
return submitSubscribers.current.reduce((schema, fn) => {
return fn(schema, value, id, diff);
}, schema);
});
},
disabled,
data: data,
node: node,
manager: manager,
popOverContainer,
subscribeSchemaSubmit: subscribeSubmit,
scopeRef: scopedRefSetter
},
{
...omit(env, 'replaceText')
// theme: 'cxd' // 右侧属性配置面板固定使用cxd主题展示
}
);
}
);

Some files were not shown because too many files have changed in this diff Show More