vendor: amis 6.13.0 base (fork root)
This commit is contained in:
25
packages/amis-editor/examples/App.tsx
Normal file
25
packages/amis-editor/examples/App.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
import * as React from 'react';
|
||||
import {AlertComponent, ToastComponent, ContextMenu} from 'amis';
|
||||
// @ts-ignore
|
||||
import AMisSchemaEditor from './Editor';
|
||||
import {Link} from 'react-router-dom';
|
||||
export default class App extends React.PureComponent {
|
||||
render() {
|
||||
// 备注: 如果需要改用antd主题,还需要将index.html换成index-antd.html
|
||||
const curTheme = 'cxd'; // 默认使用cxd主题
|
||||
return (
|
||||
<div className="Editor-Demo">
|
||||
<div id="headerBar" className="Editor-header">
|
||||
<div className="Editor-title">
|
||||
amis 可视化编辑器
|
||||
<Link to="/basic">面板模版</Link>
|
||||
</div>
|
||||
</div>
|
||||
<AMisSchemaEditor theme={curTheme} />
|
||||
<ToastComponent theme={curTheme} />
|
||||
<AlertComponent theme={curTheme} />
|
||||
<ContextMenu theme={curTheme} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
853
packages/amis-editor/examples/Editor.tsx
Normal file
853
packages/amis-editor/examples/Editor.tsx
Normal file
@@ -0,0 +1,853 @@
|
||||
/* eslint-disable */
|
||||
import * as React from 'react';
|
||||
import {
|
||||
Editor,
|
||||
ShortcutKey,
|
||||
BasePlugin,
|
||||
setThemeConfig,
|
||||
PluginEvent,
|
||||
GlobalVariableEventContext,
|
||||
GlobalVariablesEventContext
|
||||
} from '../src/index';
|
||||
import {Select, Renderer, uuid, Button} from 'amis';
|
||||
import {currentLocale} from 'i18n-runtime';
|
||||
import {Portal} from 'react-overlays';
|
||||
import {Icon} from './icons/index';
|
||||
import LayoutList from './layout/index';
|
||||
import {cxdData} from 'amis-theme-editor-helper';
|
||||
|
||||
// 测试组织属性配置面板的国际化,可以放开如下注释
|
||||
// import './renderer/InputTextI18n';
|
||||
// import './renderer/TextareaI18n';
|
||||
// import './utils/overwriteSchemaTpl';
|
||||
// const i18nEnabled = true;
|
||||
const i18nEnabled = false;
|
||||
setThemeConfig(cxdData);
|
||||
|
||||
const schema = {
|
||||
type: 'page',
|
||||
title: 'Simple Form Page',
|
||||
regions: ['body'],
|
||||
body: [
|
||||
{
|
||||
type: 'form',
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'a',
|
||||
label: 'Text'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const formSchema = {
|
||||
type: 'doc-entity',
|
||||
fields: []
|
||||
};
|
||||
|
||||
const schemas = [
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
'amisUser': {
|
||||
type: 'object',
|
||||
title: '用户信息',
|
||||
properties: {
|
||||
id: {
|
||||
type: 'string',
|
||||
title: '用户ID'
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
title: '用户名'
|
||||
},
|
||||
email: {
|
||||
type: 'string',
|
||||
title: '邮箱'
|
||||
},
|
||||
nickName: {
|
||||
type: 'string',
|
||||
title: '昵称'
|
||||
},
|
||||
phone: {
|
||||
type: 'string',
|
||||
title: '手机号'
|
||||
},
|
||||
avatar: {
|
||||
type: 'string',
|
||||
title: '用户头像'
|
||||
}
|
||||
}
|
||||
},
|
||||
'amisApp': {
|
||||
type: 'object',
|
||||
title: '应用信息',
|
||||
properties: {
|
||||
id: {
|
||||
type: 'string',
|
||||
title: '应用ID'
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
title: '应用名称'
|
||||
},
|
||||
logo: {
|
||||
type: 'string',
|
||||
title: '应用Logo'
|
||||
},
|
||||
env: {
|
||||
type: 'string',
|
||||
title: '当前运行环境'
|
||||
}
|
||||
}
|
||||
},
|
||||
'amisCompany': {
|
||||
type: 'object',
|
||||
title: '组织信息',
|
||||
properties: {
|
||||
id: {
|
||||
type: 'string',
|
||||
title: '组织ID'
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
title: '组织名称'
|
||||
},
|
||||
logo: {
|
||||
type: 'string',
|
||||
title: '组织Logo'
|
||||
},
|
||||
key: {
|
||||
type: 'string',
|
||||
title: '组织标识'
|
||||
}
|
||||
}
|
||||
},
|
||||
'window:location': {
|
||||
type: 'object',
|
||||
title: '浏览器变量',
|
||||
properties: {
|
||||
href: {
|
||||
type: 'string',
|
||||
title: 'href'
|
||||
},
|
||||
origin: {
|
||||
type: 'string',
|
||||
title: 'origin'
|
||||
},
|
||||
protocol: {
|
||||
type: 'string',
|
||||
title: 'protocol'
|
||||
},
|
||||
host: {
|
||||
type: 'string',
|
||||
title: 'host'
|
||||
},
|
||||
hostname: {
|
||||
type: 'string',
|
||||
title: 'hostname'
|
||||
},
|
||||
port: {
|
||||
type: 'string',
|
||||
title: 'port'
|
||||
},
|
||||
pathname: {
|
||||
type: 'string',
|
||||
title: 'pathname'
|
||||
},
|
||||
search: {
|
||||
type: 'string',
|
||||
title: 'search'
|
||||
},
|
||||
hash: {
|
||||
type: 'string',
|
||||
title: 'hash'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
__query: {
|
||||
title: '页面入参',
|
||||
type: 'object',
|
||||
required: [],
|
||||
properties: {
|
||||
name: {
|
||||
type: 'string',
|
||||
title: '用户名'
|
||||
}
|
||||
}
|
||||
},
|
||||
__page: {
|
||||
title: '页面变量',
|
||||
type: 'object',
|
||||
required: [],
|
||||
properties: {
|
||||
num: {
|
||||
type: 'number',
|
||||
title: '数量'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
const variableSchemas = {
|
||||
type: 'object',
|
||||
$id: 'appVariables',
|
||||
properties: {
|
||||
ProductName: {
|
||||
type: 'string',
|
||||
title: '产品名称',
|
||||
default: '对象存储'
|
||||
},
|
||||
Banlance: {
|
||||
type: 'number',
|
||||
title: '账户余额',
|
||||
default: '0.00'
|
||||
},
|
||||
ProductNum: {
|
||||
type: 'integer',
|
||||
title: '产品数量',
|
||||
default: '0.00'
|
||||
},
|
||||
isOnline: {
|
||||
type: 'boolean',
|
||||
title: '是否线上环境',
|
||||
default: 'false'
|
||||
},
|
||||
ProductList: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
title: '产品名称'
|
||||
},
|
||||
title: '产品列表',
|
||||
default: '["BOS", "CFS", "PFS", "CloudFlow", "MongoDB"]'
|
||||
},
|
||||
PROFILE: {
|
||||
type: 'object',
|
||||
title: '个人信息',
|
||||
properties: {
|
||||
FirstName: {
|
||||
type: 'string',
|
||||
title: '名字'
|
||||
},
|
||||
Age: {
|
||||
type: 'integer',
|
||||
title: '年龄'
|
||||
},
|
||||
Address: {
|
||||
type: 'object',
|
||||
title: '地址',
|
||||
required: ['street', 'postcode'],
|
||||
properties: {
|
||||
street: {
|
||||
type: 'string',
|
||||
title: '街道名称'
|
||||
},
|
||||
postcode: {
|
||||
type: 'number',
|
||||
title: '邮编'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
default: {
|
||||
ProductName: 'BCC',
|
||||
Banlance: 1234.888,
|
||||
ProductNum: 10,
|
||||
isOnline: false,
|
||||
ProductList: ['BCC', 'BOS', 'VPC'],
|
||||
PROFILE: {
|
||||
FirstName: 'Amis',
|
||||
Age: 18,
|
||||
Address: {
|
||||
street: 'ShangDi',
|
||||
postcode: 100001
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const variableDefaultData = {
|
||||
appVariables: {
|
||||
ProductName: 'BCC',
|
||||
Banlance: 1234.888,
|
||||
ProductNum: 10,
|
||||
isOnline: false,
|
||||
ProductList: ['BCC', 'BOS', 'VPC'],
|
||||
PROFILE: {
|
||||
FirstName: 'Amis',
|
||||
Age: 18,
|
||||
Address: {
|
||||
street: 'ShangDi',
|
||||
postcode: 100001
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const variables: any = [
|
||||
{
|
||||
name: 'appVariables',
|
||||
title: '内存变量',
|
||||
parentId: 'root',
|
||||
order: 1,
|
||||
schema: variableSchemas
|
||||
}
|
||||
];
|
||||
|
||||
const EditorType = {
|
||||
EDITOR: 'editor',
|
||||
MOBILE: 'mobile',
|
||||
FORM: 'form'
|
||||
};
|
||||
|
||||
const editorLanguages = [
|
||||
{
|
||||
label: '简体中文',
|
||||
value: 'zh-CN'
|
||||
},
|
||||
{
|
||||
label: 'English',
|
||||
value: 'en-US'
|
||||
}
|
||||
];
|
||||
|
||||
const globalEvents = [
|
||||
{
|
||||
name: 'globalEventA',
|
||||
label: '全局事件A',
|
||||
description: '全局事件动作A',
|
||||
mapping: [
|
||||
{
|
||||
key: 'name',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
key: 'age',
|
||||
type: 'number'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'globalEventB',
|
||||
label: '全局事件B',
|
||||
description: '全局事件动作A',
|
||||
mapping: [
|
||||
{
|
||||
key: 'name',
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
/**
|
||||
* 自定义渲染器示例
|
||||
*/
|
||||
// @Renderer({
|
||||
// type: 'my-renderer',
|
||||
// name: 'my-renderer'
|
||||
// })
|
||||
// export class MyRenderer extends React.Component {
|
||||
// static defaultProps = {
|
||||
// target: 'world'
|
||||
// };
|
||||
|
||||
// render() {
|
||||
// const {target, width, height} = this.props;
|
||||
|
||||
// return (
|
||||
// <p style={{width: width || 'auto', height: height || 'auto'}}>
|
||||
// Hello {target}!
|
||||
// </p>
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 自定义渲染器编辑插件
|
||||
*/
|
||||
class MyRendererPlugin extends BasePlugin {
|
||||
// 这里要跟对应的渲染器名字对应上
|
||||
// 注册渲染器的时候会要求指定渲染器名字
|
||||
rendererName = 'my-renderer';
|
||||
|
||||
// 暂时只支持这个,配置后会开启代码编辑器
|
||||
$schema = '/schemas/UnkownSchema.json';
|
||||
|
||||
// 用来配置名称和描述
|
||||
name = '自定义渲染器';
|
||||
description = '这只是个示例';
|
||||
|
||||
// tag,决定会在哪个 tab 下面显示的
|
||||
tags = ['自定义', '表单项'];
|
||||
|
||||
// 图标
|
||||
icon = 'fa fa-user';
|
||||
|
||||
// 用来生成预览图的
|
||||
previewSchema = {
|
||||
type: 'my-renderer',
|
||||
target: 'demo'
|
||||
};
|
||||
|
||||
// 拖入组件里面时的初始数据
|
||||
scaffold = {
|
||||
type: 'my-renderer',
|
||||
target: '233'
|
||||
};
|
||||
|
||||
// 右侧面板相关
|
||||
panelTitle = '自定义组件';
|
||||
panelBody = [
|
||||
{
|
||||
type: 'tabs',
|
||||
tabsMode: 'line',
|
||||
className: 'm-t-n-xs',
|
||||
contentClassName: 'no-border p-l-none p-r-none',
|
||||
tabs: [
|
||||
{
|
||||
title: '常规',
|
||||
body: [
|
||||
{
|
||||
name: 'target',
|
||||
label: 'Target',
|
||||
type: 'input-text'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
title: '外观',
|
||||
body: []
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
// /**
|
||||
// * 配置了 panelControls 自动生成配置面板
|
||||
// * @param context
|
||||
// * @param panels
|
||||
// */
|
||||
// buildEditorPanel(context, panels) {
|
||||
// panels.push({
|
||||
// key: 'xxxx',
|
||||
// title: '设置',
|
||||
// render: () => {
|
||||
// return <div>面板内容</div>;
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
// scaffoldForm = {
|
||||
// title: '标题',
|
||||
// body: [
|
||||
// {
|
||||
// name: 'target',
|
||||
// label: 'Target',
|
||||
// type: 'input-text'
|
||||
// }
|
||||
// ]
|
||||
// };
|
||||
|
||||
// onActive(event) {
|
||||
// const context = event.context;
|
||||
|
||||
// if (context.info?.plugin !== this || !context.node) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// const node = context.node;
|
||||
// node.setHeightMutable(true);
|
||||
// node.setWidthMutable(true);
|
||||
// }
|
||||
|
||||
// onWidthChangeStart(event) {
|
||||
// return this.onSizeChangeStart(event, 'horizontal');
|
||||
// }
|
||||
|
||||
// onHeightChangeStart(event) {
|
||||
// return this.onSizeChangeStart(event, 'vertical');
|
||||
// }
|
||||
|
||||
// onSizeChangeStart(event, direction = 'both') {
|
||||
// const context = event.context;
|
||||
// const node = context.node;
|
||||
// if (node.info?.plugin !== this) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// const resizer = context.resizer;
|
||||
// const dom = context.dom;
|
||||
// const frameRect = dom.parentElement.getBoundingClientRect();
|
||||
// const rect = dom.getBoundingClientRect();
|
||||
// const startX = context.nativeEvent.pageX;
|
||||
// const startY = context.nativeEvent.pageY;
|
||||
|
||||
// event.setData({
|
||||
// onMove: e => {
|
||||
// const dy = e.pageY - startY;
|
||||
// const dx = e.pageX - startX;
|
||||
// const height = Math.max(50, rect.height + dy);
|
||||
// const width = Math.max(100, Math.min(rect.width + dx, frameRect.width));
|
||||
// const state = {
|
||||
// width,
|
||||
// height
|
||||
// };
|
||||
|
||||
// if (direction === 'both') {
|
||||
// resizer.setAttribute('data-value', `${width}px x ${height}px`);
|
||||
// } else if (direction === 'vertical') {
|
||||
// resizer.setAttribute('data-value', `${height}px`);
|
||||
// delete state.width;
|
||||
// } else {
|
||||
// resizer.setAttribute('data-value', `${width}px`);
|
||||
// delete state.height;
|
||||
// }
|
||||
|
||||
// node.updateState(state);
|
||||
|
||||
// requestAnimationFrame(() => {
|
||||
// node.calculateHighlightBox();
|
||||
// });
|
||||
// },
|
||||
// onEnd: e => {
|
||||
// const dy = e.pageY - startY;
|
||||
// const dx = e.pageX - startX;
|
||||
// const height = Math.max(50, rect.height + dy);
|
||||
// const width = Math.max(100, Math.min(rect.width + dx, frameRect.width));
|
||||
// const state = {
|
||||
// width,
|
||||
// height
|
||||
// };
|
||||
|
||||
// if (direction === 'vertical') {
|
||||
// delete state.width;
|
||||
// } else if (direction === 'horizontal') {
|
||||
// delete state.height;
|
||||
// }
|
||||
|
||||
// resizer.removeAttribute('data-value');
|
||||
// node.updateSchema(state);
|
||||
// requestAnimationFrame(() => {
|
||||
// node.calculateHighlightBox();
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
popOverBody = [
|
||||
{
|
||||
name: 'target',
|
||||
label: 'Target',
|
||||
type: 'input-text'
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
LayoutList.push(MyRendererPlugin);
|
||||
|
||||
export default class AMisSchemaEditor extends React.Component<any, any> {
|
||||
state: any = {
|
||||
preview: localStorage.getItem('editting_preview') ? true : false,
|
||||
type: localStorage.getItem('editting_preview_type') || EditorType.EDITOR,
|
||||
schema: localStorage.getItem('editting_schema')
|
||||
? JSON.parse(localStorage.getItem('editting_schema')!)
|
||||
: schema,
|
||||
curLanguage: currentLocale() // 获取当前语料类型
|
||||
};
|
||||
|
||||
constructor(props: any) {
|
||||
super(props);
|
||||
|
||||
if (i18nEnabled) {
|
||||
this.state = {
|
||||
...this.state,
|
||||
replaceText: {
|
||||
'i18n:1189fb5d-ac5b-4558-b363-068ce5decc99': uuid()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const type =
|
||||
localStorage.getItem('editting_preview_type') || EditorType.EDITOR;
|
||||
|
||||
this.state.schema = this.getSchema(type);
|
||||
}
|
||||
|
||||
getSchema(type: string) {
|
||||
if (type === EditorType.FORM) {
|
||||
const schema = localStorage.getItem('editting_schema_form');
|
||||
|
||||
if (schema) {
|
||||
return JSON.parse(schema);
|
||||
}
|
||||
return formSchema;
|
||||
}
|
||||
|
||||
const lsSchema = localStorage.getItem('editting_schema');
|
||||
|
||||
if (lsSchema) {
|
||||
return JSON.parse(lsSchema);
|
||||
}
|
||||
|
||||
return schema;
|
||||
}
|
||||
|
||||
handleChange = (value: any) => {
|
||||
const type = this.state.type;
|
||||
|
||||
if (type === EditorType.FORM) {
|
||||
localStorage.setItem('editting_schema_form', JSON.stringify(value));
|
||||
} else {
|
||||
localStorage.setItem('editting_schema', JSON.stringify(value));
|
||||
}
|
||||
|
||||
this.setState({
|
||||
schema: value
|
||||
});
|
||||
};
|
||||
|
||||
changeLocale(value: any) {
|
||||
localStorage.setItem('suda-i18n-locale', value);
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
onSave = () => {
|
||||
const curSchema = this.state.schema;
|
||||
localStorage.setItem('editting_schema', JSON.stringify(curSchema));
|
||||
};
|
||||
|
||||
handlePreviewChange = (preview: any) => {
|
||||
localStorage.setItem('editting_preview', preview ? 'true' : '');
|
||||
|
||||
this.setState({
|
||||
preview: !!preview
|
||||
});
|
||||
};
|
||||
|
||||
togglePreview = () => {
|
||||
this.handlePreviewChange(!this.state.preview);
|
||||
};
|
||||
|
||||
handleTypeChange = (editorType: any) => {
|
||||
const type = editorType || EditorType.EDITOR;
|
||||
localStorage.setItem('editting_preview_type', type);
|
||||
|
||||
this.setState({
|
||||
type: type,
|
||||
schema: this.getSchema(type)
|
||||
});
|
||||
};
|
||||
|
||||
clearCache = () => {
|
||||
localStorage.removeItem('editting_schema');
|
||||
this.setState({
|
||||
schema: schema
|
||||
});
|
||||
};
|
||||
|
||||
renderEditor() {
|
||||
const {theme} = this.props;
|
||||
const {preview, type, schema} = this.state;
|
||||
const isMobile = type === EditorType.MOBILE;
|
||||
const {replaceText} = this.state;
|
||||
|
||||
return (
|
||||
<Editor
|
||||
preview={preview}
|
||||
isMobile={isMobile}
|
||||
value={schema}
|
||||
schemas={schemas}
|
||||
variables={variables}
|
||||
onChange={this.handleChange}
|
||||
onPreview={this.handlePreviewChange}
|
||||
onSave={this.onSave}
|
||||
className="is-fixed"
|
||||
i18nEnabled={i18nEnabled}
|
||||
theme={theme || 'cxd'}
|
||||
showCustomRenderersPanel={true}
|
||||
plugins={LayoutList} // 存放常见布局组件
|
||||
$schemaUrl={`${location.protocol}//${location.host}/schema.json`}
|
||||
actionOptions={{
|
||||
showOldEntry: false,
|
||||
globalEventGetter: () => globalEvents
|
||||
}}
|
||||
onGlobalVariableInit={onGlobalVariableInit}
|
||||
onGlobalVariableSave={onGlobalVariableSave}
|
||||
onGlobalVariableDelete={onGlobalVariableDelete}
|
||||
amisEnv={
|
||||
{
|
||||
variable: {
|
||||
id: 'appVariables',
|
||||
namespace: 'appVariables',
|
||||
schema: variableSchemas,
|
||||
data: variableDefaultData
|
||||
},
|
||||
replaceText
|
||||
} as any
|
||||
}
|
||||
ctx={{
|
||||
__page: {
|
||||
num: 2
|
||||
},
|
||||
...variableDefaultData
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
const {preview, type, curLanguage} = this.state;
|
||||
return (
|
||||
<div className="Editor-inner">
|
||||
<Portal container={() => document.querySelector('#headerBar') as any}>
|
||||
<>
|
||||
<div className="Editor-view-mode-group-container">
|
||||
<div className="Editor-view-mode-group">
|
||||
<div
|
||||
className={`Editor-view-mode-btn ${
|
||||
type === EditorType.EDITOR ? 'is-active' : ''
|
||||
}`}
|
||||
onClick={() => {
|
||||
this.handleTypeChange(EditorType.EDITOR);
|
||||
}}
|
||||
>
|
||||
<Icon icon="pc-preview" title="PC模式" />
|
||||
</div>
|
||||
<div
|
||||
className={`Editor-view-mode-btn ${
|
||||
type === EditorType.MOBILE ? 'is-active' : ''
|
||||
}`}
|
||||
onClick={() => {
|
||||
this.handleTypeChange(EditorType.MOBILE);
|
||||
}}
|
||||
>
|
||||
<Icon icon="h5-preview" title="移动模式" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="Editor-header-actions">
|
||||
<ShortcutKey />
|
||||
{
|
||||
// @ts-ignore
|
||||
// vite编译时替换
|
||||
__editor_i18n ? (
|
||||
<Select
|
||||
className="margin-left-space "
|
||||
options={editorLanguages}
|
||||
value={curLanguage}
|
||||
clearable={false}
|
||||
onChange={(e: any) => this.changeLocale(e.value)}
|
||||
/>
|
||||
) : null
|
||||
}
|
||||
|
||||
{i18nEnabled && (
|
||||
<Button
|
||||
className="ml-2"
|
||||
level="info"
|
||||
onClick={() => {
|
||||
let _uuid = uuid();
|
||||
console.log('点击测试国际化按钮', _uuid);
|
||||
this.setState({
|
||||
appLocale: _uuid,
|
||||
replaceText: {
|
||||
'i18n:1189fb5d-ac5b-4558-b363-068ce5decc99': _uuid
|
||||
}
|
||||
});
|
||||
}}
|
||||
>
|
||||
切换语料内容
|
||||
</Button>
|
||||
)}
|
||||
|
||||
<div
|
||||
className={`header-action-btn ${preview ? 'primary' : ''}`}
|
||||
onClick={() => {
|
||||
this.togglePreview();
|
||||
}}
|
||||
>
|
||||
{preview ? '编辑' : '预览'}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
</Portal>
|
||||
|
||||
{this.renderEditor()}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 通过 localstorage 存储全局变量
|
||||
// 实际场景肯定是后端存储到数据库里面
|
||||
// 可以参考这个利用这三个事件来实现全局变量的增删改查
|
||||
function getGlobalVariablesFromStorage(): Array<any> {
|
||||
const key = 'amis-editor-example-global-variable';
|
||||
let globalVariables = localStorage.getItem(key);
|
||||
let variables: Array<any> = [];
|
||||
|
||||
if (globalVariables) {
|
||||
variables = JSON.parse(globalVariables);
|
||||
}
|
||||
|
||||
return variables;
|
||||
}
|
||||
|
||||
function saveGlobalVariablesToStorage(variables: Array<any>) {
|
||||
const key = 'amis-editor-example-global-variable';
|
||||
localStorage.setItem(key, JSON.stringify(variables));
|
||||
}
|
||||
|
||||
function onGlobalVariableInit(event: PluginEvent<GlobalVariablesEventContext>) {
|
||||
event.setData(getGlobalVariablesFromStorage() || []);
|
||||
}
|
||||
|
||||
function onGlobalVariableSave(event: PluginEvent<GlobalVariableEventContext>) {
|
||||
const item = event.data;
|
||||
const variables = getGlobalVariablesFromStorage();
|
||||
const idx = item.id
|
||||
? variables.findIndex((it: any) => it.id === item.id)
|
||||
: -1;
|
||||
|
||||
if (idx === -1) {
|
||||
item.id = uuid();
|
||||
variables.push(item);
|
||||
} else {
|
||||
variables[idx] = item;
|
||||
}
|
||||
|
||||
saveGlobalVariablesToStorage(variables);
|
||||
}
|
||||
|
||||
function onGlobalVariableDelete(
|
||||
event: PluginEvent<GlobalVariableEventContext>
|
||||
) {
|
||||
const item = event.data;
|
||||
const variables = getGlobalVariablesFromStorage();
|
||||
const idx = item.id
|
||||
? variables.findIndex((it: any) => it.id === item.id)
|
||||
: -1;
|
||||
|
||||
if (idx === -1) {
|
||||
return;
|
||||
} else {
|
||||
variables.splice(idx, 1);
|
||||
}
|
||||
|
||||
saveGlobalVariablesToStorage(variables);
|
||||
}
|
||||
561
packages/amis-editor/examples/_corpus-i18n.scss
Normal file
561
packages/amis-editor/examples/_corpus-i18n.scss
Normal file
@@ -0,0 +1,561 @@
|
||||
$ns: cxd-;
|
||||
|
||||
.#{$ns}InputI18n-container {
|
||||
.#{$ns}InputI18n-inner-container {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.#{$ns}InputI18n-addon-container {
|
||||
position: absolute;
|
||||
top: 1px;
|
||||
height: calc(100% - 2px);
|
||||
right: 1px;
|
||||
background: #f7f7f9;
|
||||
border-radius: 0px 3px 3px 0px;
|
||||
width: 30px;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--Form-input-borderColor) !important;
|
||||
background: #e6f0ff !important;
|
||||
}
|
||||
|
||||
.CorpusI18n-input-icon.icon {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
}
|
||||
|
||||
.#{$ns}InputI18n-addon-active {
|
||||
background: #e6f0ff;
|
||||
color: var(--link-color);
|
||||
}
|
||||
|
||||
.#{$ns}InputI18n-fx-container {
|
||||
position: absolute;
|
||||
top: 1px;
|
||||
height: calc(100% - 2px);
|
||||
right: 1px;
|
||||
border-radius: 0px 3px 3px 0px;
|
||||
width: 30px;
|
||||
cursor: pointer;
|
||||
|
||||
.CorpusI18n-input-icon.icon {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-60%, -50%);
|
||||
font-size: 24px;
|
||||
}
|
||||
}
|
||||
|
||||
.#{$ns}InputI18n-fx-active {
|
||||
color: var(--link-color);
|
||||
}
|
||||
|
||||
.#{$ns}InputI18n-overlay {
|
||||
position: absolute;
|
||||
top: 1px;
|
||||
left: 1px;
|
||||
bottom: 1px;
|
||||
right: 31px;
|
||||
width: calc(100% - 32px);
|
||||
height: calc(100% - 2px);
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
.#{$ns}InputI18n-multi-container {
|
||||
.#{$ns}InputBox {
|
||||
input {
|
||||
padding-right: 30px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.#{$ns}CorpusI18n {
|
||||
&-textarea {
|
||||
.#{$ns}Form-label {
|
||||
padding: var(--Form-input-paddingY) 0;
|
||||
.#{$ns}TplField {
|
||||
font-size: px2rem(12px);
|
||||
}
|
||||
}
|
||||
.#{$ns}Form-value {
|
||||
padding-right: 0;
|
||||
.#{$ns}TextareaControl-input {
|
||||
font-size: px2rem(12px);
|
||||
}
|
||||
}
|
||||
}
|
||||
&-static {
|
||||
.#{$ns}Form-label {
|
||||
padding-left: 0;
|
||||
.#{$ns}TplField {
|
||||
font-size: px2rem(12px);
|
||||
}
|
||||
}
|
||||
.#{$ns}Form-value {
|
||||
.#{$ns}PlainField {
|
||||
font-size: px2rem(12px);
|
||||
}
|
||||
}
|
||||
}
|
||||
.#{$ns}Panel {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.CorpusI18n-icon.icon {
|
||||
top: 0 !important;
|
||||
}
|
||||
|
||||
.#{$ns}FormulaPickerI18n {
|
||||
.#{$ns}Modal-header {
|
||||
font-weight: bold;
|
||||
}
|
||||
&-tab {
|
||||
padding: var(--gap-base) 0;
|
||||
.#{$ns}FormulaEditor-content .#{$ns}FormulaEditor-header {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.RichTextI18n {
|
||||
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);
|
||||
&::placeholder {
|
||||
color: var(--Form-input-placeholderColor);
|
||||
}
|
||||
|
||||
&:hover {
|
||||
border-color: var(--Form-input-onHover-borderColor);
|
||||
}
|
||||
|
||||
.fr-toolbar.fr-top {
|
||||
border-radius: var(--Form-input-borderRadius);
|
||||
}
|
||||
|
||||
&-editor {
|
||||
height: 100%;
|
||||
border-radius: var(--Form-input-borderRadius);
|
||||
overflow: auto;
|
||||
& > .CodeMirror {
|
||||
height: 100%;
|
||||
padding-bottom: 26px;
|
||||
.CodeMirror-lines {
|
||||
padding-bottom: 30px;
|
||||
}
|
||||
.CodeMirror-vscrollbar {
|
||||
margin-bottom: 26px;
|
||||
}
|
||||
|
||||
// 解决上下 pre标签中表达式浮层遮挡问题
|
||||
.CodeMirror-measure + div {
|
||||
z-index: inherit !important;
|
||||
}
|
||||
pre.CodeMirror-line,
|
||||
.CodeMirror pre.CodeMirror-line-like {
|
||||
z-index: initial;
|
||||
}
|
||||
}
|
||||
|
||||
.cm-expression {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
|
||||
.expression-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;
|
||||
|
||||
.expression-popover-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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.cm-expression-text {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
padding: 0 5px;
|
||||
border-radius: 3px;
|
||||
color: #fff;
|
||||
margin: 0 1px 1px;
|
||||
background: var(--button-primary-default-bg-color);
|
||||
cursor: pointer;
|
||||
width: 40px;
|
||||
overflow-x: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
vertical-align: middle;
|
||||
|
||||
&:hover {
|
||||
background: var(--button-primary-hover-bg-color);
|
||||
& ~ .expression-popover {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&-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;
|
||||
}
|
||||
&-fxIcon {
|
||||
> a {
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&-overlay {
|
||||
position: absolute;
|
||||
z-index: 5;
|
||||
top: 1px;
|
||||
left: 1px;
|
||||
width: calc(100% - 4px);
|
||||
height: calc(100% - 4px);
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
.RichTextI18n-enabled-container {
|
||||
padding-bottom: 20px;
|
||||
|
||||
.RichTextI18n-footer-fxIcon {
|
||||
.icon-corpus-i18n {
|
||||
color: var(--body-color);
|
||||
}
|
||||
}
|
||||
|
||||
.RichTextI18n-footer-matched-fxIcon {
|
||||
.icon-corpus-i18n {
|
||||
color: var(--link-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.TextareaI18n {
|
||||
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);
|
||||
&::placeholder {
|
||||
color: var(--Form-input-placeholderColor);
|
||||
}
|
||||
|
||||
&:hover {
|
||||
border-color: var(--Form-input-onHover-borderColor);
|
||||
}
|
||||
|
||||
.#{$ns}TextareaControl > textarea {
|
||||
border: 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;
|
||||
}
|
||||
&-corpusIcon {
|
||||
> a {
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&-overlay {
|
||||
position: absolute;
|
||||
top: 1px;
|
||||
left: 1px;
|
||||
width: calc(100% - 4px);
|
||||
height: calc(100% - 4px);
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
.TextareaI18n-multi-container {
|
||||
padding-bottom: 26px;
|
||||
|
||||
.TextareaI18n-footer-corpusIcon {
|
||||
.icon-corpus-i18n {
|
||||
color: var(--body-color);
|
||||
}
|
||||
}
|
||||
|
||||
.TextareaI18n-footer-highlight-corpusIcon {
|
||||
.icon-corpus-i18n {
|
||||
color: var(--link-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.#{$ns}CorpusConfigDialog-container {
|
||||
z-index: 9999;
|
||||
}
|
||||
|
||||
.#{$ns}CorpusConfigDialog-confirm-dialog {
|
||||
z-index: 10000;
|
||||
}
|
||||
|
||||
.#{$ns}CorpusConfigDialogBody {
|
||||
margin-bottom: 1rem;
|
||||
.corpus-keyword-searchbox {
|
||||
width: 20rem;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.operate-tip-container {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
|
||||
.create-tip,
|
||||
.update-tip {
|
||||
font-size: 12px;
|
||||
|
||||
.dot {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background-color: #28a745;
|
||||
display: block;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
left: -10px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.Corpus-FormItem-container {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 10px;
|
||||
|
||||
.Corpus-FormItem-label {
|
||||
position: relative;
|
||||
top: 6px;
|
||||
width: 70px;
|
||||
margin-right: 10px;
|
||||
text-align: right;
|
||||
word-wrap: break-word;
|
||||
word-break: break-all;
|
||||
font-weight: 500px;
|
||||
}
|
||||
|
||||
.#{$ns}TextareaControl {
|
||||
width: 240px;
|
||||
}
|
||||
}
|
||||
|
||||
.CorpusTablePicker-container {
|
||||
.CorpusTablePicker-outer-container {
|
||||
width: 100%;
|
||||
overflow-x: auto;
|
||||
}
|
||||
.CorpusTablePicker-inner-container {
|
||||
width: fit-content;
|
||||
min-width: 100%;
|
||||
}
|
||||
.CorpusTablePicker-Header-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background-color: #f7f8fa;
|
||||
padding: 10px 20px;
|
||||
padding-left: 40px;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.CorpusTablePicker-Body-container {
|
||||
.CorpusTablePicker-BodyRow-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border-bottom: 1px solid #f2f2f2;
|
||||
padding: 10px 20px;
|
||||
padding-left: 40px;
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
position: relative;
|
||||
|
||||
&:hover {
|
||||
background-color: #e6f0ff;
|
||||
}
|
||||
|
||||
.CorpusTablePicker-radio {
|
||||
position: absolute;
|
||||
left: 10px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
border: 1px solid #f2f2f2;
|
||||
}
|
||||
}
|
||||
|
||||
.CorpusTablePicker-BodyColumn-item {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
overflow: hidden;
|
||||
/*! autoprefixer: off */
|
||||
-webkit-box-orient: vertical;
|
||||
word-wrap: break-word;
|
||||
word-break: break-all;
|
||||
padding-right: 20px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.#{$ns}Pagination-wrap {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.CorpusDetailPanel-container {
|
||||
border: 1px solid #f7f8fa;
|
||||
border-top-left-radius: 4px;
|
||||
border-top-right-radius: 4px;
|
||||
font-size: 12px;
|
||||
margin-top: 16px;
|
||||
.CorpusDetailPanel-Header-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
background-color: #f7f8fa;
|
||||
padding: 5px 20px;
|
||||
.CorpusDetailPanel-Header-title {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.CorpusDetailPanel-Header-buttons-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
.#{$ns}Button {
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.CorpusDetailPanel-Body-container {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
padding: 20px;
|
||||
padding-bottom: 0;
|
||||
|
||||
.CorpusDetailPanel-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
word-wrap: break-word;
|
||||
word-break: break-all;
|
||||
width: 50%;
|
||||
margin-bottom: 20px;
|
||||
|
||||
.CorpusDetailPanel-label {
|
||||
width: 80px;
|
||||
margin-right: 10px;
|
||||
font-weight: 500;
|
||||
word-wrap: break-word;
|
||||
word-break: break-all;
|
||||
text-align: right;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.CorpusDetailPanel-textarea-label {
|
||||
position: relative;
|
||||
top: 8px;
|
||||
}
|
||||
|
||||
.CorpusDetailPanel-content {
|
||||
word-wrap: break-word;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.#{$ns}CorpusDetailPanel-textarea {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.#{$ns}CorpusDetailPanel-button-tooltip {
|
||||
z-index: 20000;
|
||||
}
|
||||
82
packages/amis-editor/examples/component/Doc.tsx
Normal file
82
packages/amis-editor/examples/component/Doc.tsx
Normal file
@@ -0,0 +1,82 @@
|
||||
import React from 'react';
|
||||
import Markdown from 'react-markdown';
|
||||
import remarkGfm from 'remark-gfm';
|
||||
import {Prism as SyntaxHighlighter} from 'react-syntax-highlighter';
|
||||
import {darcula} from 'react-syntax-highlighter/dist/esm/styles/prism';
|
||||
import {getSchemaTpl, tipedLabel} from 'amis-editor-core';
|
||||
import 'amis';
|
||||
import '../../src/index';
|
||||
import PanelPreview from './PanelPreview';
|
||||
export interface DocProps {
|
||||
children?: string | null | undefined;
|
||||
}
|
||||
|
||||
export function mdComment(fun: Function) {
|
||||
const txt = fun.toString();
|
||||
return txt;
|
||||
}
|
||||
|
||||
function str2schema(code: string) {
|
||||
const fn = new Function('getSchemaTpl', 'tipedLabel', `return [${code}]`);
|
||||
return fn.call(null, getSchemaTpl, tipedLabel);
|
||||
}
|
||||
|
||||
export default function Doc({children}: DocProps) {
|
||||
return (
|
||||
<div className="markdown">
|
||||
<div className="markdown-body">
|
||||
<Markdown
|
||||
children={children}
|
||||
remarkPlugins={[remarkGfm]}
|
||||
components={{
|
||||
pre(props) {
|
||||
if ((props.children as any)?.props?.className) {
|
||||
return <>{props.children}</>;
|
||||
}
|
||||
|
||||
return <code>{props.children}</code>;
|
||||
},
|
||||
code(props) {
|
||||
const {children, className, node, ref, ...rest} = props;
|
||||
const match = /language-(\w+)/.exec(className || '');
|
||||
|
||||
if (match?.[1] === 'schema') {
|
||||
const schema = str2schema(children as string);
|
||||
|
||||
return (
|
||||
<div className="schema-tpl-preview">
|
||||
<code>
|
||||
<SyntaxHighlighter
|
||||
{...rest}
|
||||
PreTag="div"
|
||||
children={String(children).replace(/\n$/, '')}
|
||||
language={'jsx'}
|
||||
style={darcula}
|
||||
/>
|
||||
</code>
|
||||
|
||||
<PanelPreview schema={schema} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return match ? (
|
||||
<SyntaxHighlighter
|
||||
{...rest}
|
||||
PreTag="div"
|
||||
children={String(children).replace(/\n$/, '')}
|
||||
language={match[1]}
|
||||
style={darcula}
|
||||
/>
|
||||
) : (
|
||||
<code {...rest} className={className}>
|
||||
{children}
|
||||
</code>
|
||||
);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
60
packages/amis-editor/examples/component/PanelPreview.tsx
Normal file
60
packages/amis-editor/examples/component/PanelPreview.tsx
Normal file
@@ -0,0 +1,60 @@
|
||||
import {JsonView, render} from 'amis';
|
||||
import cx from 'classnames';
|
||||
import React from 'react';
|
||||
export interface PanelPreviewProps {
|
||||
schema: any;
|
||||
}
|
||||
|
||||
export default function (props: PanelPreviewProps) {
|
||||
const schema = React.useMemo(() => {
|
||||
return {
|
||||
type: 'form',
|
||||
mode: 'normal',
|
||||
wrapWithPanel: false,
|
||||
className: cx('config-form-content', 'ae-Settings-content'),
|
||||
wrapperComponent: 'div',
|
||||
body: Array.isArray(props.schema) ? props.schema : [props.schema],
|
||||
submitOnChange: true,
|
||||
submitOnInit: true
|
||||
};
|
||||
}, [JSON.stringify(props.schema)]);
|
||||
const [data, setData] = React.useState({});
|
||||
const onFinished = React.useCallback((data: any) => {
|
||||
setData(data);
|
||||
return false;
|
||||
}, []);
|
||||
const onJsonEdit = React.useCallback((e: any) => {
|
||||
setData(e.updated_src);
|
||||
}, []);
|
||||
const dom = React.useRef<HTMLDivElement | null>(null);
|
||||
// const popOverContainer = React.useCallback(() => {
|
||||
// return dom.current;
|
||||
// }, []);
|
||||
|
||||
return (
|
||||
<div className="PanelPreview" ref={dom}>
|
||||
<div className="AMISCSSWrapper editor-right-panel">
|
||||
{render(
|
||||
schema,
|
||||
{
|
||||
data: data,
|
||||
onFinished: onFinished
|
||||
// popOverContainer
|
||||
},
|
||||
{
|
||||
// theme: 'cxd' // 右侧属性配置面板固定使用cxd主题展示
|
||||
}
|
||||
)}
|
||||
</div>
|
||||
<JsonView
|
||||
name={false}
|
||||
src={data}
|
||||
theme={'rjv-default'}
|
||||
enableClipboard={false}
|
||||
onEdit={onJsonEdit}
|
||||
onDelete={onJsonEdit}
|
||||
onAdd={onJsonEdit}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
1
packages/amis-editor/examples/icons/corpus-i18n.svg
Normal file
1
packages/amis-editor/examples/icons/corpus-i18n.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg width="15" height="15" xmlns="http://www.w3.org/2000/svg"><g transform="translate(1 1)" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"><circle cx="6.5" cy="6.5" r="6.5"/><ellipse cx="6.5" cy="6.5" rx="6.5" ry="2.5"/><ellipse transform="rotate(-90 6.5 6.5)" cx="6.5" cy="6.5" rx="6.5" ry="2.5"/></g></svg>
|
||||
|
After Width: | Height: | Size: 364 B |
1
packages/amis-editor/examples/icons/h5-preview.svg
Normal file
1
packages/amis-editor/examples/icons/h5-preview.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><g fill="none"><path d="M0 0h16v16H0z"/><path d="M13 1.5a.5.5 0 0 1 .5.5v12a.5.5 0 0 1-.5.5H3a.5.5 0 0 1-.5-.5V2a.5.5 0 0 1 .5-.5Zm-.5 1h-9v11h9v-11ZM9 11.66a.5.5 0 0 1 .09.992L9 12.66H7a.5.5 0 0 1-.09-.992L7 11.66h2Z" fill="currentColor"/></g></svg>
|
||||
|
After Width: | Height: | Size: 311 B |
18
packages/amis-editor/examples/icons/index.tsx
Normal file
18
packages/amis-editor/examples/icons/index.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* @file 内置 svg 图标
|
||||
*/
|
||||
|
||||
import {Icon, registerIcon} from 'amis';
|
||||
|
||||
// @ts-ignore
|
||||
import PCPreview from './pc-preview.svg';
|
||||
// @ts-ignore
|
||||
import H5Preview from './h5-preview.svg';
|
||||
registerIcon('pc-preview', PCPreview);
|
||||
registerIcon('h5-preview', H5Preview);
|
||||
|
||||
// @ts-ignore
|
||||
import CorpusI18n from './corpus-i18n.svg';
|
||||
registerIcon('corpus-i18n', CorpusI18n);
|
||||
|
||||
export {Icon};
|
||||
1
packages/amis-editor/examples/icons/pc-preview.svg
Normal file
1
packages/amis-editor/examples/icons/pc-preview.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg viewBox="0 0 17 16" xmlns="http://www.w3.org/2000/svg"><g fill="none" fill-rule="evenodd"><path d="M16.037 0h-16v16h16z"/><path d="M6.037 14a.5.5 0 0 1-.09-.992l.09-.008h1.5v-1.5h-5.5a.5.5 0 0 1-.5-.5V2.542a.5.5 0 0 1 .5-.5h12a.5.5 0 0 1 .5.5V11a.5.5 0 0 1-.5.5h-5.5V13h1.5a.5.5 0 0 1 .09.992l-.09.008h-4Zm7.5-10.959h-11V10.5h11V3.041Z" fill="currentColor"/></g></svg>
|
||||
|
After Width: | Height: | Size: 374 B |
40
packages/amis-editor/examples/layout/index.ts
Normal file
40
packages/amis-editor/examples/layout/index.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
// 常见布局
|
||||
import Layout1_1 from './plugin/Layout1_1';
|
||||
import Layout1_2 from './plugin/Layout1_2';
|
||||
import Layout1_3 from './plugin/Layout1_3';
|
||||
import Layout1_1_v2 from './plugin/Layout1_1_v2';
|
||||
import Layout1_1_1 from './plugin/Layout1_1_1';
|
||||
import Layout1_2_3 from './plugin/Layout1_2_3';
|
||||
import Layout1_1_1_v2 from './plugin/Layout1_1_1_v2';
|
||||
import Layout1_2_v2 from './plugin/Layout1_2_v2';
|
||||
import Layout2_1_v2 from './plugin/Layout2_1_v2';
|
||||
import Layout1_2_v3 from './plugin/Layout1_2_v3';
|
||||
import Layout2_1_v3 from './plugin/Layout2_1_v3';
|
||||
import Layout1_2_v4 from './plugin/Layout1_2_v4';
|
||||
// import Layout_fixed_top from './plugin/Layout_fixed_top';
|
||||
// import Layout_fixed_bottom from './plugin/Layout_fixed_bottom';
|
||||
// import Layout_fixed from './plugin/Layout_fixed';
|
||||
import Layout_scroll_x from './plugin/Layout_scroll_x';
|
||||
import Layout_scroll_y from './plugin/Layout_scroll_y';
|
||||
|
||||
const LayoutList: Array<any> = [
|
||||
Layout1_1,
|
||||
Layout1_2,
|
||||
Layout1_3,
|
||||
Layout1_1_v2,
|
||||
Layout1_1_1,
|
||||
Layout1_2_3,
|
||||
Layout1_1_1_v2,
|
||||
Layout1_2_v2,
|
||||
Layout2_1_v2,
|
||||
Layout1_2_v3,
|
||||
Layout2_1_v3,
|
||||
Layout1_2_v4,
|
||||
// Layout_fixed_top,
|
||||
// Layout_fixed_bottom,
|
||||
// Layout_fixed,
|
||||
Layout_scroll_x,
|
||||
Layout_scroll_y
|
||||
];
|
||||
|
||||
export default LayoutList;
|
||||
42
packages/amis-editor/examples/layout/plugin/Layout1_1.tsx
Normal file
42
packages/amis-editor/examples/layout/plugin/Layout1_1.tsx
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* @file Flex 常见布局 1:1 左右均分
|
||||
*/
|
||||
import {FlexPluginBase} from '../../../src/plugin/Layout/FlexPluginBase';
|
||||
|
||||
export default class Layout1_1 extends FlexPluginBase {
|
||||
name = '左右均分';
|
||||
isBaseComponent = false;
|
||||
pluginIcon = 'layout-2cols-plugin';
|
||||
description = '常见布局:左右均分布局(基于 CSS Flex 实现的布局容器)。';
|
||||
tags = ['常见布局'];
|
||||
order = 200;
|
||||
scaffold: any = {
|
||||
type: 'flex',
|
||||
className: 'p-1',
|
||||
items: [
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'block'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'block'
|
||||
}
|
||||
}
|
||||
],
|
||||
alignItems: 'stretch'
|
||||
};
|
||||
}
|
||||
53
packages/amis-editor/examples/layout/plugin/Layout1_1_1.tsx
Normal file
53
packages/amis-editor/examples/layout/plugin/Layout1_1_1.tsx
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* @file Flex 常见布局 1:1:1 三栏均分
|
||||
*/
|
||||
import {FlexPluginBase} from '../../../src/plugin/Layout/FlexPluginBase';
|
||||
|
||||
export default class Layout1_1_1 extends FlexPluginBase {
|
||||
name = '三栏均分';
|
||||
isBaseComponent = false;
|
||||
pluginIcon = 'layout-3cols-plugin';
|
||||
description = '常见布局:三栏均分布局(基于 CSS Flex 实现的布局容器)。';
|
||||
tags = ['常见布局'];
|
||||
order = 300;
|
||||
scaffold: any = {
|
||||
type: 'flex',
|
||||
className: 'p-1',
|
||||
items: [
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'block'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'block'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
display: 'block',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1
|
||||
}
|
||||
}
|
||||
],
|
||||
alignItems: 'stretch'
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* @file Flex 常见布局 上中下布局
|
||||
*/
|
||||
import {FlexPluginBase} from '../../../src/plugin/Layout/FlexPluginBase';
|
||||
|
||||
export default class Layout1_1_1_v2 extends FlexPluginBase {
|
||||
name = '上中下';
|
||||
isBaseComponent = false;
|
||||
pluginIcon = 'layout-3row-plugin';
|
||||
description = '常见布局:上中下布局(基于 CSS Flex 实现的布局容器)。';
|
||||
tags = ['常见布局'];
|
||||
order = 303;
|
||||
scaffold: any = {
|
||||
type: 'flex',
|
||||
className: 'p-1',
|
||||
items: [
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'flex-start',
|
||||
alignItems: 'stretch'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'flex-start',
|
||||
alignItems: 'stretch'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'flex-start',
|
||||
alignItems: 'stretch'
|
||||
}
|
||||
}
|
||||
],
|
||||
direction: 'column',
|
||||
justify: 'center',
|
||||
alignItems: 'stretch'
|
||||
};
|
||||
}
|
||||
50
packages/amis-editor/examples/layout/plugin/Layout1_1_v2.tsx
Normal file
50
packages/amis-editor/examples/layout/plugin/Layout1_1_v2.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* @file Flex 常见布局 上下布局
|
||||
*/
|
||||
import {FlexPluginBase} from '../../../src/plugin/Layout/FlexPluginBase';
|
||||
|
||||
export default class Layout1_1_v2 extends FlexPluginBase {
|
||||
name = '上下布局';
|
||||
isBaseComponent = false;
|
||||
pluginIcon = 'layout-2row-plugin';
|
||||
description = '常见布局:上下布局(基于 CSS Flex 实现的布局容器)。';
|
||||
tags = ['常见布局'];
|
||||
order = 203;
|
||||
scaffold: any = {
|
||||
type: 'flex',
|
||||
className: 'p-1',
|
||||
items: [
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'flex-start',
|
||||
alignItems: 'stretch'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'flex-start',
|
||||
alignItems: 'stretch'
|
||||
}
|
||||
}
|
||||
],
|
||||
direction: 'column',
|
||||
justify: 'center',
|
||||
alignItems: 'stretch'
|
||||
};
|
||||
}
|
||||
42
packages/amis-editor/examples/layout/plugin/Layout1_2.tsx
Normal file
42
packages/amis-editor/examples/layout/plugin/Layout1_2.tsx
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* @file Flex 常见布局 1:2
|
||||
*/
|
||||
import {FlexPluginBase} from '../../../src/plugin/Layout/FlexPluginBase';
|
||||
|
||||
export default class Layout1_2 extends FlexPluginBase {
|
||||
name = '1:2 布局';
|
||||
isBaseComponent = false;
|
||||
pluginIcon = 'layout-2cols-plugin';
|
||||
description = '常见布局:1:2 布局(基于 CSS Flex 实现的布局容器)。';
|
||||
tags = ['常见布局'];
|
||||
order = 201;
|
||||
scaffold: any = {
|
||||
type: 'flex',
|
||||
className: 'p-1',
|
||||
items: [
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'block'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 2,
|
||||
display: 'block'
|
||||
}
|
||||
}
|
||||
],
|
||||
alignItems: 'stretch'
|
||||
};
|
||||
}
|
||||
53
packages/amis-editor/examples/layout/plugin/Layout1_2_3.tsx
Normal file
53
packages/amis-editor/examples/layout/plugin/Layout1_2_3.tsx
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* @file Flex 常见布局 1:2:3
|
||||
*/
|
||||
import {FlexPluginBase} from '../../../src/plugin/Layout/FlexPluginBase';
|
||||
|
||||
export default class Layout1_2_3 extends FlexPluginBase {
|
||||
name = '1:2:3 三栏';
|
||||
isBaseComponent = false;
|
||||
pluginIcon = 'layout-3cols-plugin';
|
||||
description = '常见布局:1:2:3 三栏布局(基于 CSS Flex 实现的布局容器)。';
|
||||
tags = ['常见布局'];
|
||||
order = 301;
|
||||
scaffold: any = {
|
||||
type: 'flex',
|
||||
className: 'p-1',
|
||||
items: [
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'block'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 2,
|
||||
display: 'block'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
display: 'block',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 3
|
||||
}
|
||||
}
|
||||
],
|
||||
alignItems: 'stretch'
|
||||
};
|
||||
}
|
||||
72
packages/amis-editor/examples/layout/plugin/Layout1_2_v2.tsx
Normal file
72
packages/amis-editor/examples/layout/plugin/Layout1_2_v2.tsx
Normal file
@@ -0,0 +1,72 @@
|
||||
import {FlexPluginBase} from '../../../src/plugin/Layout/FlexPluginBase';
|
||||
|
||||
export default class Layout1_2_v2 extends FlexPluginBase {
|
||||
name = '一拖二';
|
||||
isBaseComponent = false;
|
||||
pluginIcon = 'layout-1with2-plugin';
|
||||
description = '常见布局:一拖二布局(基于 CSS Flex 实现的布局容器)。';
|
||||
tags = ['常见布局'];
|
||||
order = 303;
|
||||
scaffold: any = {
|
||||
type: 'flex',
|
||||
className: 'p-1',
|
||||
items: [
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '0 0 auto',
|
||||
flexBasis: '100px',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'flex-start',
|
||||
alignItems: 'stretch'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'flex',
|
||||
items: [
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'block'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'block'
|
||||
}
|
||||
}
|
||||
],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
padding: 0
|
||||
},
|
||||
alignItems: 'stretch'
|
||||
}
|
||||
],
|
||||
style: {
|
||||
overflowX: 'auto',
|
||||
margin: '0',
|
||||
maxWidth: 'auto',
|
||||
height: '350px',
|
||||
overflowY: 'auto'
|
||||
},
|
||||
direction: 'column',
|
||||
justify: 'center',
|
||||
alignItems: 'stretch',
|
||||
isFixedHeight: true
|
||||
};
|
||||
}
|
||||
74
packages/amis-editor/examples/layout/plugin/Layout1_2_v3.tsx
Normal file
74
packages/amis-editor/examples/layout/plugin/Layout1_2_v3.tsx
Normal file
@@ -0,0 +1,74 @@
|
||||
import {FlexPluginBase} from '../../../src/plugin/Layout/FlexPluginBase';
|
||||
|
||||
export default class Layout1_2_v3 extends FlexPluginBase {
|
||||
name = '左一右二';
|
||||
isBaseComponent = false;
|
||||
pluginIcon = 'layout-1-2-plugin';
|
||||
description = '常见布局:左一右二布局(基于 CSS Flex 实现的布局容器)。';
|
||||
tags = ['常见布局'];
|
||||
order = 304;
|
||||
scaffold: any = {
|
||||
type: 'flex',
|
||||
className: 'p-1',
|
||||
items: [
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '0 0 auto',
|
||||
flexBasis: '250px',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'flex-start',
|
||||
alignItems: 'stretch'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'flex',
|
||||
items: [
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'block'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'block'
|
||||
}
|
||||
}
|
||||
],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
margin: '0'
|
||||
},
|
||||
alignItems: 'stretch',
|
||||
direction: 'column',
|
||||
justify: 'center'
|
||||
}
|
||||
],
|
||||
style: {
|
||||
overflowX: 'auto',
|
||||
margin: '0',
|
||||
maxWidth: 'auto',
|
||||
height: '350px',
|
||||
overflowY: 'auto'
|
||||
},
|
||||
direction: 'row',
|
||||
justify: 'center',
|
||||
alignItems: 'stretch',
|
||||
isFixedHeight: true
|
||||
};
|
||||
}
|
||||
107
packages/amis-editor/examples/layout/plugin/Layout1_2_v4.tsx
Normal file
107
packages/amis-editor/examples/layout/plugin/Layout1_2_v4.tsx
Normal file
@@ -0,0 +1,107 @@
|
||||
import {FlexPluginBase} from '../../../src/plugin/Layout/FlexPluginBase';
|
||||
|
||||
export default class Layout1_2_v4 extends FlexPluginBase {
|
||||
name = '经典布局';
|
||||
isBaseComponent = false;
|
||||
pluginIcon = 'layout-3-1-plugin';
|
||||
description = '常见布局:经典布局(基于 CSS Flex 实现的布局容器)。';
|
||||
tags = ['常见布局'];
|
||||
order = 307;
|
||||
scaffold: any = {
|
||||
type: 'flex',
|
||||
className: 'p-1',
|
||||
items: [
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '0 0 auto',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'flex-start',
|
||||
alignItems: 'stretch'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'flex',
|
||||
items: [
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '0 0 auto',
|
||||
flexBasis: '250px',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'flex-start',
|
||||
alignItems: 'stretch'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'flex',
|
||||
items: [
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'block'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'block'
|
||||
}
|
||||
}
|
||||
],
|
||||
style: {
|
||||
position: 'static',
|
||||
overflowX: 'auto',
|
||||
overflowY: 'auto',
|
||||
margin: '0',
|
||||
flex: '1 1 auto',
|
||||
flexGrow: 1,
|
||||
flexBasis: 'auto'
|
||||
},
|
||||
alignItems: 'stretch',
|
||||
direction: 'column',
|
||||
justify: 'center',
|
||||
isFixedHeight: false,
|
||||
isFixedWidth: false
|
||||
}
|
||||
],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
overflowX: 'auto',
|
||||
margin: '0',
|
||||
maxWidth: 'auto',
|
||||
overflowY: 'auto',
|
||||
position: 'static',
|
||||
minWidth: 'auto',
|
||||
width: 'auto',
|
||||
maxHeight: 'auto',
|
||||
minHeight: '300px'
|
||||
},
|
||||
direction: 'row',
|
||||
justify: 'flex-start',
|
||||
alignItems: 'stretch',
|
||||
isFixedHeight: false,
|
||||
isFixedWidth: false
|
||||
}
|
||||
],
|
||||
direction: 'column',
|
||||
justify: 'center',
|
||||
alignItems: 'stretch'
|
||||
};
|
||||
}
|
||||
42
packages/amis-editor/examples/layout/plugin/Layout1_3.tsx
Normal file
42
packages/amis-editor/examples/layout/plugin/Layout1_3.tsx
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* @file Flex 常见布局 1:3
|
||||
*/
|
||||
import {FlexPluginBase} from '../../../src/plugin/Layout/FlexPluginBase';
|
||||
|
||||
export default class Layout1_3 extends FlexPluginBase {
|
||||
name = '1:3 布局';
|
||||
isBaseComponent = false;
|
||||
pluginIcon = 'layout-2cols-plugin';
|
||||
description = '常见布局:1:3 布局(基于 CSS Flex 实现的布局容器)。';
|
||||
tags = ['常见布局'];
|
||||
order = 202;
|
||||
scaffold: any = {
|
||||
type: 'flex',
|
||||
className: 'p-1',
|
||||
items: [
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'block'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 3,
|
||||
display: 'block'
|
||||
}
|
||||
}
|
||||
],
|
||||
alignItems: 'stretch'
|
||||
};
|
||||
}
|
||||
75
packages/amis-editor/examples/layout/plugin/Layout2_1_v2.tsx
Normal file
75
packages/amis-editor/examples/layout/plugin/Layout2_1_v2.tsx
Normal file
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* @file Flex 常见布局 二拖一布局
|
||||
*/
|
||||
import {FlexPluginBase} from '../../../src/plugin/Layout/FlexPluginBase';
|
||||
|
||||
export default class Layout2_1_v2 extends FlexPluginBase {
|
||||
name = '二拖一';
|
||||
isBaseComponent = false; // 在自定义组件面板中展示
|
||||
pluginIcon = 'layout-2with1-plugin';
|
||||
description = '常见布局:二拖一布局(基于 CSS Flex 实现的布局容器)。';
|
||||
tags = ['常见布局'];
|
||||
order = 305;
|
||||
scaffold: any = {
|
||||
type: 'flex',
|
||||
className: 'p-1',
|
||||
items: [
|
||||
{
|
||||
type: 'flex',
|
||||
items: [
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'block'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'block'
|
||||
}
|
||||
}
|
||||
],
|
||||
style: {
|
||||
flex: '0 0 auto',
|
||||
flexBasis: '100px'
|
||||
},
|
||||
alignItems: 'stretch'
|
||||
},
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: '200px',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'flex-start',
|
||||
alignItems: 'stretch'
|
||||
}
|
||||
}
|
||||
],
|
||||
style: {
|
||||
overflowX: 'auto',
|
||||
margin: '0',
|
||||
maxWidth: 'auto',
|
||||
height: '350px',
|
||||
overflowY: 'auto'
|
||||
},
|
||||
direction: 'column',
|
||||
justify: 'center',
|
||||
alignItems: 'stretch',
|
||||
isFixedHeight: true
|
||||
};
|
||||
}
|
||||
73
packages/amis-editor/examples/layout/plugin/Layout2_1_v3.tsx
Normal file
73
packages/amis-editor/examples/layout/plugin/Layout2_1_v3.tsx
Normal file
@@ -0,0 +1,73 @@
|
||||
import {FlexPluginBase} from '../../../src/plugin/Layout/FlexPluginBase';
|
||||
|
||||
export default class Layout2_1_v3 extends FlexPluginBase {
|
||||
name = '左二右一';
|
||||
isBaseComponent = false; // 在自定义组件面板中展示
|
||||
pluginIcon = 'layout-2-1-plugin';
|
||||
description = '常见布局:左二右一布局(基于 CSS Flex 实现的布局容器)。';
|
||||
tags = ['常见布局'];
|
||||
order = 306;
|
||||
scaffold: any = {
|
||||
type: 'flex',
|
||||
className: 'p-1',
|
||||
items: [
|
||||
{
|
||||
type: 'flex',
|
||||
items: [
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'block'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'block'
|
||||
}
|
||||
}
|
||||
],
|
||||
style: {
|
||||
flex: '1 1 auto'
|
||||
},
|
||||
alignItems: 'stretch',
|
||||
direction: 'column',
|
||||
justify: 'center'
|
||||
},
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '0 0 auto',
|
||||
flexBasis: '250px',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'flex-start',
|
||||
alignItems: 'stretch'
|
||||
}
|
||||
}
|
||||
],
|
||||
style: {
|
||||
overflowX: 'auto',
|
||||
margin: '0',
|
||||
maxWidth: 'auto',
|
||||
height: '350px',
|
||||
overflowY: 'auto'
|
||||
},
|
||||
direction: 'row',
|
||||
justify: 'center',
|
||||
alignItems: 'stretch',
|
||||
isFixedHeight: true
|
||||
};
|
||||
}
|
||||
23
packages/amis-editor/examples/layout/plugin/Layout_fixed.tsx
Normal file
23
packages/amis-editor/examples/layout/plugin/Layout_fixed.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
import {FlexPluginBase} from '../../../src/plugin/Layout/FlexPluginBase';
|
||||
|
||||
export default class Layout_fixed extends FlexPluginBase {
|
||||
name = '悬浮容器';
|
||||
isBaseComponent = false;
|
||||
pluginIcon = 'layout-fixed-plugin';
|
||||
description = '常见布局:悬浮容器(基于 CSS Flex 实现的布局容器)。';
|
||||
tags = ['常见布局'];
|
||||
order = -1;
|
||||
scaffold: any = {
|
||||
type: 'container',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
position: 'fixed',
|
||||
inset: 'auto 50px 50px auto',
|
||||
zIndex: 10,
|
||||
minWidth: '80px',
|
||||
minHeight: '80px'
|
||||
},
|
||||
originPosition: 'right-bottom'
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import {FlexPluginBase} from '../../../src/plugin/Layout/FlexPluginBase';
|
||||
|
||||
export default class Layout_fixed_bottom extends FlexPluginBase {
|
||||
name = '吸底容器';
|
||||
isBaseComponent = false;
|
||||
pluginIcon = 'flex-container-plugin';
|
||||
description = '常见布局:吸底容器(基于 CSS Flex 实现的布局容器)。';
|
||||
tags = ['常见布局'];
|
||||
order = 501;
|
||||
scaffold: any = {
|
||||
type: 'flex',
|
||||
className: 'p-1',
|
||||
items: [
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'flex-start',
|
||||
alignItems: 'stretch'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'flex-start',
|
||||
alignItems: 'stretch'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'flex-start',
|
||||
alignItems: 'stretch'
|
||||
}
|
||||
}
|
||||
],
|
||||
style: {
|
||||
position: 'fixed',
|
||||
inset: 'auto auto 0 0',
|
||||
zIndex: 2,
|
||||
width: '100%',
|
||||
overflowX: 'auto',
|
||||
margin: '0',
|
||||
overflowY: 'auto',
|
||||
height: 'auto'
|
||||
},
|
||||
isFixedWidth: true,
|
||||
direction: 'row',
|
||||
justify: 'center',
|
||||
alignItems: 'stretch',
|
||||
isFixedHeight: false,
|
||||
originPosition: 'right-bottom'
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import {FlexPluginBase} from '../../../src/plugin/Layout/FlexPluginBase';
|
||||
|
||||
export default class Layout_fixed_top extends FlexPluginBase {
|
||||
name = '吸顶容器';
|
||||
isBaseComponent = false;
|
||||
pluginIcon = 'flex-container-plugin';
|
||||
description = '常见布局:吸顶容器(基于 CSS Flex 实现的布局容器)。';
|
||||
tags = ['常见布局'];
|
||||
order = 502;
|
||||
scaffold: any = {
|
||||
type: 'flex',
|
||||
className: 'p-1',
|
||||
items: [
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'block'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1,
|
||||
display: 'block'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'wrapper',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '1 1 auto',
|
||||
display: 'block',
|
||||
flexBasis: 'auto',
|
||||
flexGrow: 1
|
||||
}
|
||||
}
|
||||
],
|
||||
style: {
|
||||
position: 'fixed',
|
||||
inset: '0 auto auto 0',
|
||||
zIndex: 10,
|
||||
width: '100%',
|
||||
overflowX: 'auto',
|
||||
margin: '0',
|
||||
overflowY: 'auto'
|
||||
},
|
||||
isFixedWidth: true,
|
||||
direction: 'row',
|
||||
justify: 'center',
|
||||
alignItems: 'stretch',
|
||||
isFixedHeight: false,
|
||||
originPosition: 'right-bottom'
|
||||
};
|
||||
}
|
||||
132
packages/amis-editor/examples/layout/plugin/Layout_scroll_x.tsx
Normal file
132
packages/amis-editor/examples/layout/plugin/Layout_scroll_x.tsx
Normal file
@@ -0,0 +1,132 @@
|
||||
import {FlexPluginBase} from '../../../src/plugin/Layout/FlexPluginBase';
|
||||
|
||||
export default class Layout_scroll_x extends FlexPluginBase {
|
||||
name = 'x轴滚动容器';
|
||||
isBaseComponent = false;
|
||||
pluginIcon = 'layout-3cols-plugin';
|
||||
description = 'x轴滚动容器: 基于 CSS Flex 实现的布局容器。';
|
||||
order = 505;
|
||||
scaffold: any = {
|
||||
type: 'flex',
|
||||
className: 'p-1',
|
||||
items: [
|
||||
{
|
||||
type: 'container',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
wrapperBody: false,
|
||||
style: {
|
||||
flex: '0 0 auto',
|
||||
flexBasis: '200px',
|
||||
display: 'block',
|
||||
position: 'static',
|
||||
minWidth: 'auto',
|
||||
minHeight: 'auto'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'container',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
wrapperBody: false,
|
||||
style: {
|
||||
flex: '0 0 auto',
|
||||
flexBasis: '200px',
|
||||
display: 'block',
|
||||
position: 'static',
|
||||
minWidth: 'auto',
|
||||
minHeight: 'auto'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'container',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
wrapperBody: false,
|
||||
style: {
|
||||
flex: '0 0 auto',
|
||||
display: 'block',
|
||||
position: 'static',
|
||||
minWidth: 'auto',
|
||||
minHeight: 'auto',
|
||||
flexBasis: '200px'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'container',
|
||||
wrapperBody: false,
|
||||
size: 'xs',
|
||||
body: [],
|
||||
style: {
|
||||
flex: '0 0 auto',
|
||||
flexBasis: '200px',
|
||||
display: 'block',
|
||||
position: 'static',
|
||||
minWidth: 'auto',
|
||||
minHeight: 'auto'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'container',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
wrapperBody: false,
|
||||
style: {
|
||||
flex: '0 0 auto',
|
||||
flexBasis: '200px',
|
||||
display: 'block',
|
||||
position: 'static',
|
||||
minWidth: 'auto',
|
||||
minHeight: 'auto'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'container',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
wrapperBody: false,
|
||||
style: {
|
||||
flex: '0 0 auto',
|
||||
flexBasis: '200px',
|
||||
display: 'block',
|
||||
position: 'static',
|
||||
minWidth: 'auto',
|
||||
minHeight: 'auto'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'container',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
wrapperBody: false,
|
||||
style: {
|
||||
flex: '0 0 auto',
|
||||
flexBasis: '200px',
|
||||
display: 'block',
|
||||
position: 'static',
|
||||
minWidth: 'auto',
|
||||
minHeight: 'auto'
|
||||
}
|
||||
}
|
||||
],
|
||||
direction: 'row',
|
||||
justify: 'flex-start',
|
||||
alignItems: 'stretch',
|
||||
style: {
|
||||
position: 'static',
|
||||
minHeight: 'auto',
|
||||
maxWidth: '1080px',
|
||||
minWidth: 'auto',
|
||||
height: '200px',
|
||||
overflowX: 'scroll',
|
||||
overflowY: 'scroll',
|
||||
margin: '0 auto'
|
||||
},
|
||||
isFixedHeight: true,
|
||||
isFixedWidth: false
|
||||
};
|
||||
|
||||
onPreview2editor(event: any) {
|
||||
console.log('onPreview2editor-event:', event);
|
||||
}
|
||||
}
|
||||
114
packages/amis-editor/examples/layout/plugin/Layout_scroll_y.tsx
Normal file
114
packages/amis-editor/examples/layout/plugin/Layout_scroll_y.tsx
Normal file
@@ -0,0 +1,114 @@
|
||||
import {FlexPluginBase} from '../../../src/plugin/Layout/FlexPluginBase';
|
||||
|
||||
export default class Layout_scroll_y extends FlexPluginBase {
|
||||
name = 'y轴滚动容器';
|
||||
isBaseComponent = false;
|
||||
pluginIcon = 'layout-3row-plugin';
|
||||
description = 'y轴滚动容器: 基于 CSS Flex 实现的布局容器。';
|
||||
order = 504;
|
||||
scaffold: any = {
|
||||
type: 'flex',
|
||||
className: 'p-1',
|
||||
items: [
|
||||
{
|
||||
type: 'container',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
wrapperBody: false,
|
||||
style: {
|
||||
flex: '0 0 auto',
|
||||
flexBasis: '60px',
|
||||
display: 'block',
|
||||
minWidth: 'auto',
|
||||
minHeight: 'auto'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'container',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
wrapperBody: false,
|
||||
style: {
|
||||
flex: '0 0 auto',
|
||||
flexBasis: '60px',
|
||||
display: 'block',
|
||||
position: 'static',
|
||||
minWidth: 'auto',
|
||||
minHeight: 'auto'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'container',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
wrapperBody: false,
|
||||
style: {
|
||||
flex: '0 0 auto',
|
||||
flexBasis: '60px',
|
||||
display: 'block',
|
||||
position: 'static',
|
||||
minWidth: 'auto',
|
||||
minHeight: 'auto'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'container',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
wrapperBody: false,
|
||||
style: {
|
||||
flex: '0 0 auto',
|
||||
flexBasis: '60px',
|
||||
display: 'block',
|
||||
position: 'static',
|
||||
minWidth: 'auto',
|
||||
minHeight: 'auto'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'container',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
wrapperBody: false,
|
||||
style: {
|
||||
flex: '0 0 auto',
|
||||
flexBasis: '60px',
|
||||
display: 'block',
|
||||
position: 'static',
|
||||
minWidth: 'auto',
|
||||
minHeight: 'auto'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'container',
|
||||
size: 'xs',
|
||||
body: [],
|
||||
wrapperBody: false,
|
||||
style: {
|
||||
flex: '0 0 auto',
|
||||
flexBasis: '60px',
|
||||
display: 'block',
|
||||
position: 'static',
|
||||
minWidth: 'auto',
|
||||
minHeight: 'auto'
|
||||
}
|
||||
}
|
||||
],
|
||||
direction: 'column',
|
||||
justify: 'flex-start',
|
||||
alignItems: 'stretch',
|
||||
style: {
|
||||
position: 'static',
|
||||
minHeight: 'auto',
|
||||
maxWidth: 'auto',
|
||||
minWidth: 'auto',
|
||||
height: '200px',
|
||||
width: 'auto',
|
||||
overflowX: 'auto',
|
||||
overflowY: 'scroll',
|
||||
margin: '0'
|
||||
},
|
||||
isFixedHeight: true,
|
||||
isFixedWidth: false
|
||||
};
|
||||
}
|
||||
166
packages/amis-editor/examples/renderer/InputTextI18n.tsx
Normal file
166
packages/amis-editor/examples/renderer/InputTextI18n.tsx
Normal file
@@ -0,0 +1,166 @@
|
||||
/**
|
||||
* @file client/renderer/InputTextI18n.tsx
|
||||
* @description 支持国际化的 input-text 组件
|
||||
*/
|
||||
|
||||
import {
|
||||
FormControlProps,
|
||||
FormItem,
|
||||
makeTranslator,
|
||||
autobind
|
||||
} from '../../../amis-core/src/index';
|
||||
import React from 'react';
|
||||
import {Icon, InputBox} from '../../../amis-ui/src/index';
|
||||
import {InputBoxProps} from '../../../amis-ui/src/components/InputBox';
|
||||
import cx from 'classnames';
|
||||
import {getEnv} from 'mobx-state-tree';
|
||||
import {pick} from 'lodash';
|
||||
import {LocaleProps} from 'amis-core';
|
||||
|
||||
/** 语料 key 正则表达式 */
|
||||
export const corpusKeyReg =
|
||||
/^i18n:[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$/;
|
||||
|
||||
interface InputTextI18nProps extends InputBoxProps, LocaleProps {
|
||||
classPrefix: string;
|
||||
i18nEnabled?: boolean;
|
||||
disabled?: boolean;
|
||||
maxLength?: number;
|
||||
minLength?: number;
|
||||
onI18nChange?: (value: string) => void;
|
||||
}
|
||||
|
||||
export class InputTextI18n extends React.Component<InputTextI18nProps> {
|
||||
constructor(props: InputTextI18nProps) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
render() {
|
||||
let {
|
||||
value,
|
||||
classPrefix,
|
||||
i18nEnabled,
|
||||
className,
|
||||
disabled,
|
||||
translate = makeTranslator(this.props.locale),
|
||||
placeholder,
|
||||
onI18nChange,
|
||||
...rest
|
||||
} = this.props;
|
||||
|
||||
const restProps = rest
|
||||
? pick(rest, [
|
||||
'onBlur',
|
||||
'placeholder',
|
||||
'disabled',
|
||||
'readOnly',
|
||||
'onClear',
|
||||
'hasError',
|
||||
'prefix',
|
||||
'children',
|
||||
'borderMode'
|
||||
])
|
||||
: {};
|
||||
|
||||
const isMatch = corpusKeyReg.test(value!);
|
||||
const _value = i18nEnabled ? translate(value) : value;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cx(className, `${classPrefix}InputI18n-container`, {
|
||||
[`${classPrefix}InputI18n-multi-container`]: i18nEnabled
|
||||
})}
|
||||
>
|
||||
<div className={cx(`${classPrefix}InputI18n-inner-container`)}>
|
||||
<InputBox
|
||||
{...restProps}
|
||||
value={_value}
|
||||
clearable={false}
|
||||
onChange={this.onInputChange}
|
||||
placeholder={placeholder}
|
||||
disabled={disabled}
|
||||
></InputBox>
|
||||
{i18nEnabled && !disabled ? (
|
||||
<div
|
||||
className={cx(`${classPrefix}InputI18n-addon-container`, {
|
||||
[`${classPrefix}InputI18n-addon-active`]: isMatch
|
||||
})}
|
||||
onClick={this.onClickI18nBtn}
|
||||
>
|
||||
<Icon
|
||||
icon="corpus-i18n"
|
||||
className="icon cursor-pointer CorpusI18n-input-icon"
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{isMatch && i18nEnabled ? (
|
||||
<div
|
||||
className={cx(`${classPrefix}InputI18n-overlay`)}
|
||||
onClick={this.onClickI18nBtn}
|
||||
></div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@autobind
|
||||
onClickI18nBtn() {
|
||||
const {value} = this.props;
|
||||
if (corpusKeyReg.test(value!)) {
|
||||
this.props?.onChange?.('');
|
||||
this.props.onI18nChange?.('');
|
||||
return;
|
||||
}
|
||||
let _uuid = 'i18n:1189fb5d-ac5b-4558-b363-068ce5decc99';
|
||||
this.props?.onChange?.(_uuid);
|
||||
this.props.onI18nChange?.(_uuid);
|
||||
}
|
||||
|
||||
@autobind
|
||||
onInputChange(value: string) {
|
||||
this.props.onChange?.(value);
|
||||
}
|
||||
}
|
||||
|
||||
interface InputTextI18nControlProps extends FormControlProps {}
|
||||
|
||||
class InputTextI18nControl extends React.Component<InputTextI18nControlProps> {
|
||||
constructor(props: InputTextI18nControlProps) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
onChange,
|
||||
value,
|
||||
classPrefix,
|
||||
className,
|
||||
classnames,
|
||||
placeholder,
|
||||
disabled,
|
||||
...rest
|
||||
} = this.props;
|
||||
const {i18nEnabled} = getEnv((window as any).editorStore);
|
||||
|
||||
return (
|
||||
<InputTextI18n
|
||||
{...rest}
|
||||
i18nEnabled={i18nEnabled}
|
||||
onChange={onChange}
|
||||
classPrefix={classPrefix}
|
||||
classnames={classnames}
|
||||
value={value}
|
||||
placeholder={placeholder}
|
||||
className={className}
|
||||
disabled={disabled}
|
||||
></InputTextI18n>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@FormItem({
|
||||
type: 'input-text-i18n'
|
||||
})
|
||||
export class InputTextI18nRenderer extends InputTextI18nControl {}
|
||||
83
packages/amis-editor/examples/renderer/TextareaI18n.tsx
Normal file
83
packages/amis-editor/examples/renderer/TextareaI18n.tsx
Normal file
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* @file client/renderer/TextAreaI18n.tsx
|
||||
* @description 支持国际化的 textarea 组件
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import {
|
||||
autobind,
|
||||
FormControlProps,
|
||||
FormItem
|
||||
} from '../../../amis-core/src/index';
|
||||
import {Icon, Textarea} from '../../../amis-ui/src/index';
|
||||
import cx from 'classnames';
|
||||
|
||||
/** 语料 key 正则表达式 */
|
||||
export const corpusKeyReg =
|
||||
/^i18n:[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$/;
|
||||
|
||||
export interface TextareaI18nProps extends FormControlProps {}
|
||||
|
||||
class TextareaI18n extends React.Component<TextareaI18nProps> {
|
||||
@autobind
|
||||
onClickI18nBtn() {
|
||||
const {value} = this.props;
|
||||
if (corpusKeyReg.test(value!)) {
|
||||
this.props?.onChange?.('');
|
||||
return;
|
||||
}
|
||||
let _uuid = 'i18n:1189fb5d-ac5b-4558-b363-068ce5decc99';
|
||||
this.props?.onChange?.(_uuid);
|
||||
}
|
||||
|
||||
render() {
|
||||
const {value, onChange, className} = this.props;
|
||||
|
||||
const isMatch = corpusKeyReg.test(value!);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
className={cx(
|
||||
'TextareaI18n',
|
||||
className,
|
||||
'TextareaI18n-multi-container'
|
||||
)}
|
||||
>
|
||||
<Textarea
|
||||
value={value}
|
||||
clearable={false}
|
||||
onChange={onChange}
|
||||
></Textarea>
|
||||
|
||||
{
|
||||
<ul className={cx('TextareaI18n-footer')}>
|
||||
<li
|
||||
className={cx('TextareaI18n-footer-corpusIcon', {
|
||||
'TextareaI18n-footer-highlight-corpusIcon': isMatch
|
||||
})}
|
||||
onClick={this.onClickI18nBtn}
|
||||
>
|
||||
<a data-tooltip="多语言" data-position="top">
|
||||
<Icon icon="corpus-i18n" className="icon" />
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
}
|
||||
|
||||
{isMatch ? (
|
||||
<div
|
||||
className={cx('TextareaI18n-overlay')}
|
||||
onClick={this.onClickI18nBtn}
|
||||
></div>
|
||||
) : null}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@FormItem({
|
||||
type: 'textarea-i18n'
|
||||
})
|
||||
export class TextAreaI18nRenderer extends TextareaI18n {}
|
||||
21
packages/amis-editor/examples/route/Basic.md
Normal file
21
packages/amis-editor/examples/route/Basic.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# 基本模版
|
||||
|
||||
## 表单项名字
|
||||
|
||||
`formItemName`
|
||||
|
||||
```schema
|
||||
getSchemaTpl('formItemName', {
|
||||
value: 'name'
|
||||
})
|
||||
```
|
||||
|
||||
## 表单项展示模式
|
||||
|
||||
`formItemMode`
|
||||
|
||||
```schema
|
||||
getSchemaTpl('formItemMode', {
|
||||
|
||||
})
|
||||
```
|
||||
117
packages/amis-editor/examples/route/Formula.md
Normal file
117
packages/amis-editor/examples/route/Formula.md
Normal file
@@ -0,0 +1,117 @@
|
||||
# 公式相关
|
||||
|
||||
公式输入相关组件规范说明。
|
||||
|
||||
## 显隐表达式
|
||||
|
||||
比如:`visibleOn`, `disabledOn` 因为存在两种表达式的写法,所以这里需要明确区分。
|
||||
|
||||
- 没有初始值时出现「点击编写表达式」按钮,点击会弹出一个表达式编辑器。
|
||||
- 初始值存在时,且为 js 表达式(即不是 `${` 和 `}`包裹的)时,直接用文本输入框展示与输入。
|
||||
- 初始值存在时,且为 `${` 和 `}`包裹的公式表达式时,用公式编辑器展示,同时点击后,会弹出一个表达式编辑器,能直接回显当前公式
|
||||
- 公式弹窗内部始终是公式语法,不存在模版拼接语法。
|
||||
- 当 js 表达式被删除后,只能用新版公式编辑器了。
|
||||
|
||||
```schema
|
||||
getSchemaTpl('expressionFormulaControl', {
|
||||
label: '无默认值',
|
||||
name: 'var1'
|
||||
}),
|
||||
|
||||
getSchemaTpl('expressionFormulaControl', {
|
||||
label: '默认值为旧语法',
|
||||
name: 'var2',
|
||||
value: 'data.a == 1'
|
||||
}),
|
||||
|
||||
getSchemaTpl('expressionFormulaControl', {
|
||||
label: '默认值为新语法',
|
||||
name: 'var3',
|
||||
value: '\\${a == 1 ? "1" : a == 2 ? "二" : a == 3 ? "三" : "一个很长的表达式"}'
|
||||
})
|
||||
```
|
||||
|
||||
## 文本输入框默认值
|
||||
|
||||
默认展示为文本输入框,通过点击 `+fx` 来添加公式片段,公式部分高亮展示,是整体高亮,而不是表达式内部 token 高亮(变量名、操作符、字面量等会用不同的方式高亮)。整体高亮内部不细化高亮,展示 tooltip 时再细化高亮,并且点击后开始编辑点击部分公式,注意这里是编辑局部公式,而不是整个默认值输入框。
|
||||
|
||||
值格式中如果没有出现 `${` 和 `}` 包裹的公式,则认为是普通文本,如果存在,则会做公式处理。当时用户直接通过文本输入框输入公式时,会当成时输入普通文本,如果用户输入了 `$` 符号,要将其转成 `\\$`,这样就不会被误认为是公式了。要添加公式片段,用户必须通过点击 `+fx` 按钮添加。`+fx` 可以添加多个片段。
|
||||
|
||||
```schema
|
||||
getSchemaTpl('tplFormulaControl', {
|
||||
name: 'value',
|
||||
label: '默认值'
|
||||
}),
|
||||
|
||||
getSchemaTpl('tplFormulaControl', {
|
||||
name: 'value2',
|
||||
label: '默认值',
|
||||
value: 'My name is \\${name}'
|
||||
})
|
||||
```
|
||||
|
||||
## 多行文本输入框默认值
|
||||
|
||||
```schema
|
||||
getSchemaTpl('textareaDefaultValue', {
|
||||
name: 'var1',
|
||||
value: 'My name is \\${name}'
|
||||
})
|
||||
```
|
||||
|
||||
## 数字输入框默认值
|
||||
|
||||
默认展示为数字输入框,通过点击 `fx` 输入公式,因为不是文本,无法拼接,所以默认值要么是公式,要么是静态值。
|
||||
|
||||
```schema
|
||||
getSchemaTpl('valueFormula', {
|
||||
mode: 'vertical',
|
||||
rendererSchema: (schema) => ({
|
||||
type: 'input-number',
|
||||
...schema,
|
||||
displayMode: 'base'
|
||||
}),
|
||||
valueType: 'number' // 期望数值类型
|
||||
})
|
||||
```
|
||||
|
||||
## 日期输入框默认值
|
||||
|
||||
```schema
|
||||
getSchemaTpl('valueFormula', {
|
||||
mode: 'vertical',
|
||||
rendererSchema: (schema) => ({
|
||||
type: 'input-date',
|
||||
...schema
|
||||
}),
|
||||
placeholder: '请选择静态值',
|
||||
header: '表达式或相对值',
|
||||
DateTimeType: 1,
|
||||
label: tipedLabel('默认值', '支持例如: <code>now、+3days、-2weeks、+1hour、+2years</code> 等(minute|min|hour|day|week|month|year|weekday|second|millisecond)这种相对值用法')
|
||||
})
|
||||
```
|
||||
|
||||
## 选项类输入框默认值
|
||||
|
||||
```schema
|
||||
getSchemaTpl('valueFormula', {
|
||||
rendererSchema: (schema) => ({
|
||||
...schema,
|
||||
type: 'select',
|
||||
options: [
|
||||
{
|
||||
label: '选项1',
|
||||
value: '1'
|
||||
},
|
||||
{
|
||||
label: '选项2',
|
||||
value: '2'
|
||||
}
|
||||
]
|
||||
}),
|
||||
// 默认值组件设计有些问题,自动发起了请求,接口数据作为了默认值选项,接口形式应该是设置静态值或者FX
|
||||
needDeleteProps: ['source'],
|
||||
// 当数据源是自定义静态选项时,不额外配置默认值,在选项上直接勾选即可,放开会有个bug:当去掉勾选时,默认值配置组件不清空,只是schema清空了value
|
||||
visibleOn: 'this.selectFirst !== true && this.source != null'
|
||||
})
|
||||
```
|
||||
316
packages/amis-editor/examples/style.scss
Normal file
316
packages/amis-editor/examples/style.scss
Normal file
@@ -0,0 +1,316 @@
|
||||
@import '../../amis-ui/scss/functions';
|
||||
@import '../../amis-ui/scss/variables';
|
||||
@import '../../amis-ui/scss/helper';
|
||||
@import './corpus-i18n';
|
||||
|
||||
$editor-default-color: #151b26; // 默认的字体色
|
||||
$editor-active-color: #2468f2;
|
||||
$editor-hover-color: #5086f5;
|
||||
$editor-border-color: #e8e9eb; // 默认的边框色
|
||||
$default-icon-color: #84868c; // 默认的icon颜色
|
||||
|
||||
$active-bg-color: #e6f0ff; // 激活态的背景色
|
||||
$hover-bg-color: #f7f7f9; // 激活态的背景色
|
||||
|
||||
$disabled-color: #b8babf; // 禁用文字颜色
|
||||
$disabled-bg-color: #f7f7f9; // 禁用背景颜色
|
||||
|
||||
.page-play,
|
||||
.page-edit {
|
||||
&:before {
|
||||
display: table;
|
||||
content: ' ';
|
||||
}
|
||||
&:after {
|
||||
clear: both;
|
||||
display: block;
|
||||
content: '';
|
||||
height: 0;
|
||||
}
|
||||
.app-content {
|
||||
position: absolute;
|
||||
top: 50px;
|
||||
bottom: 0;
|
||||
height: auto;
|
||||
left: 0;
|
||||
right: 0;
|
||||
}
|
||||
.app-content-body {
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.Editor-Demo {
|
||||
position: relative;
|
||||
height: 100vh;
|
||||
min-height: 510px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.Editor-header {
|
||||
flex: 0 0 48px;
|
||||
position: relative;
|
||||
background: #fff;
|
||||
// box-shadow: 0 2px 7px 0 rgba(232,232,232,0.50);
|
||||
display: flex;
|
||||
border-bottom: 1px solid $editor-border-color;
|
||||
box-sizing: border-box;
|
||||
z-index: 1000;
|
||||
|
||||
svg {
|
||||
display: inline-block;
|
||||
width: 16px;
|
||||
}
|
||||
|
||||
.Editor-title {
|
||||
flex: 1 1 565px;
|
||||
padding: 0 15px;
|
||||
font-family: PingFangSC-Medium;
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
letter-spacing: 0;
|
||||
user-select: none;
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.Editor-view-mode-group-container {
|
||||
flex: 0 1 150px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
.Editor-view-mode-group {
|
||||
font-size: 14px;
|
||||
font-family: PingFangSC-Regular;
|
||||
// color: #fff;
|
||||
letter-spacing: 0;
|
||||
text-align: center;
|
||||
width: 100px;
|
||||
height: 32px;
|
||||
border-radius: 4px;
|
||||
font-weight: 400;
|
||||
background-color: #f2f2f4;
|
||||
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
.Editor-view-mode-btn {
|
||||
user-select: none;
|
||||
padding: 0;
|
||||
border-radius: 4px;
|
||||
width: 40px;
|
||||
height: 24px;
|
||||
cursor: pointer;
|
||||
transition: transform ease-out 0.2s;
|
||||
display: inline-flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
margin-right: 12px;
|
||||
|
||||
svg {
|
||||
color: $editor-default-color;
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
&:hover > svg {
|
||||
color: $editor-active-color;
|
||||
}
|
||||
|
||||
&.is-active {
|
||||
background: $editor-active-color;
|
||||
|
||||
svg {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background: #5086f5;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.Editor-header-actions {
|
||||
flex: 1 1 565px;
|
||||
padding: 0 24px;
|
||||
font-size: 12px;
|
||||
white-space: nowrap;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
|
||||
.header-action-item {
|
||||
margin-left: 18px;
|
||||
user-select: none;
|
||||
cursor: pointer;
|
||||
transition: transform ease-out 0.2s;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
> svg {
|
||||
width: 16px;
|
||||
fill: $editor-default-color;
|
||||
}
|
||||
|
||||
&:hover > svg {
|
||||
fill: $editor-active-color;
|
||||
}
|
||||
|
||||
&.disabled {
|
||||
cursor: not-allowed;
|
||||
|
||||
> svg {
|
||||
fill: $disabled-color;
|
||||
}
|
||||
}
|
||||
|
||||
// 历史记录icon单独处理
|
||||
> svg.icon-editor-history {
|
||||
color: $editor-default-color;
|
||||
|
||||
&:hover {
|
||||
color: $editor-active-color;
|
||||
}
|
||||
|
||||
&.disabled,
|
||||
&.disabled:hover {
|
||||
cursor: not-allowed;
|
||||
color: $disabled-color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.header-action-btn {
|
||||
margin-left: 8px;
|
||||
user-select: none;
|
||||
cursor: pointer;
|
||||
padding: 0 16px;
|
||||
min-width: 72px;
|
||||
height: 32px;
|
||||
font-family: PingFangSC-Regular;
|
||||
font-size: 12px;
|
||||
line-height: 20px;
|
||||
color: #fff;
|
||||
font-weight: 400;
|
||||
background: $editor-active-color;
|
||||
border-color: 1px solid $editor-active-color;
|
||||
border-radius: 4px;
|
||||
transition: transform ease-out 0.2s;
|
||||
display: inline-flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
&.preview-btn {
|
||||
color: #151a26;
|
||||
border: 1px solid #dadbdd;
|
||||
background: #fff;
|
||||
border-radius: 4px;
|
||||
|
||||
&:hover {
|
||||
color: $editor-active-color;
|
||||
border-color: $editor-active-color;
|
||||
background: #fff;
|
||||
}
|
||||
}
|
||||
|
||||
&:hover {
|
||||
color: #fff;
|
||||
background: $editor-hover-color;
|
||||
border-color: $editor-hover-color;
|
||||
}
|
||||
|
||||
&.disabled {
|
||||
cursor: not-allowed;
|
||||
color: $disabled-color;
|
||||
background-color: $disabled-bg-color;
|
||||
border-color: $disabled-bg-color;
|
||||
}
|
||||
}
|
||||
|
||||
.margin-left-space {
|
||||
margin-left: 80px;
|
||||
}
|
||||
}
|
||||
}
|
||||
.Editor-inner {
|
||||
position: relative;
|
||||
flex: 1 1 auto;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.resizer {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
margin-left: -2px;
|
||||
width: 4px;
|
||||
background: lighten($dark, 20%);
|
||||
z-index: 1;
|
||||
cursor: col-resize;
|
||||
|
||||
&:hover {
|
||||
background: $dark;
|
||||
}
|
||||
}
|
||||
|
||||
.doc-shcema-preview-popover {
|
||||
box-shadow: none;
|
||||
margin-top: -1px;
|
||||
padding: 0 45px;
|
||||
left: 0 !important;
|
||||
width: 100%;
|
||||
z-index: 1;
|
||||
background: transparent;
|
||||
border: none;
|
||||
|
||||
.doc-schema-preview {
|
||||
border: 1px solid #ddd;
|
||||
background: rgb(240, 243, 244);
|
||||
position: relative;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
#root > .a-Select-popover {
|
||||
z-index: 1500;
|
||||
}
|
||||
|
||||
.schema-tpl-preview {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: flex-start;
|
||||
|
||||
> *:first-child {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
background-color: rgb(43, 43, 43);
|
||||
}
|
||||
}
|
||||
|
||||
.PanelPreview {
|
||||
background-color: #fff;
|
||||
padding: 0 20px 20px 20px;
|
||||
position: relative;
|
||||
width: 400px;
|
||||
flex-shrink: 0;
|
||||
|
||||
> .editor-right-panel {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
> .react-json-view {
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
142
packages/amis-editor/examples/utils/overwriteSchemaTpl.tsx
Normal file
142
packages/amis-editor/examples/utils/overwriteSchemaTpl.tsx
Normal file
@@ -0,0 +1,142 @@
|
||||
import {remarkTpl} from '../../src/index';
|
||||
import {getSchemaTpl, setSchemaTpl} from '../../../amis-editor-core/src/index';
|
||||
|
||||
/** 国际化组件类型 */
|
||||
enum I18nComptType {
|
||||
InputText = 'input-text',
|
||||
Textarea = 'textarea',
|
||||
TextareaFormula = 'textarea-formula',
|
||||
RichText = 'rich-text',
|
||||
ButtonLabel = 'button-label'
|
||||
}
|
||||
|
||||
/** 缓存已经重写过的 tpl 名称 */
|
||||
const overwriteNames: {[propName: string]: boolean} = {};
|
||||
|
||||
/** 重写 schema tpl */
|
||||
const overwriteSchemaTpl = (
|
||||
name: string,
|
||||
i18nType = I18nComptType.InputText,
|
||||
options?: {[key: string]: any}
|
||||
) => {
|
||||
if (overwriteNames[name]) {
|
||||
throw new Error(name + 'has been rewritten');
|
||||
}
|
||||
overwriteNames[name] = true;
|
||||
|
||||
const getType = () => {
|
||||
if (i18nType === I18nComptType.InputText) {
|
||||
return 'input-text-i18n';
|
||||
}
|
||||
if (i18nType === I18nComptType.Textarea) {
|
||||
return 'textarea-i18n';
|
||||
}
|
||||
return 'input-text-i18n';
|
||||
};
|
||||
|
||||
setSchemaTpl(
|
||||
name,
|
||||
getSchemaTpl(
|
||||
name,
|
||||
options
|
||||
? options
|
||||
: {
|
||||
type: getType()
|
||||
}
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
overwriteSchemaTpl('label');
|
||||
overwriteSchemaTpl('btnLabel');
|
||||
overwriteSchemaTpl('placeholder');
|
||||
overwriteSchemaTpl('startPlaceholder');
|
||||
overwriteSchemaTpl('endPlaceholder');
|
||||
overwriteSchemaTpl('option');
|
||||
overwriteSchemaTpl('description', I18nComptType.Textarea);
|
||||
overwriteSchemaTpl('pageTitle');
|
||||
overwriteSchemaTpl('pageSubTitle', I18nComptType.Textarea);
|
||||
overwriteSchemaTpl('tpl:rich-text', I18nComptType.RichText);
|
||||
overwriteSchemaTpl('prefix');
|
||||
overwriteSchemaTpl('suffix');
|
||||
overwriteSchemaTpl('unit');
|
||||
overwriteSchemaTpl('optionsTip');
|
||||
overwriteSchemaTpl('tableCellRemark');
|
||||
overwriteSchemaTpl('title');
|
||||
overwriteSchemaTpl('caption');
|
||||
overwriteSchemaTpl('imageCaption');
|
||||
overwriteSchemaTpl('inputBody');
|
||||
overwriteSchemaTpl('stepSubTitle');
|
||||
overwriteSchemaTpl('stepDescription');
|
||||
overwriteSchemaTpl('taskNameLabel');
|
||||
overwriteSchemaTpl('operationLabel');
|
||||
overwriteSchemaTpl('statusLabel');
|
||||
overwriteSchemaTpl('remarkLabel');
|
||||
overwriteSchemaTpl('inputArrayItem');
|
||||
overwriteSchemaTpl('actionPrevLabel');
|
||||
overwriteSchemaTpl('actionNextLabel');
|
||||
overwriteSchemaTpl('actionNextSaveLabel');
|
||||
overwriteSchemaTpl('actionFinishLabel');
|
||||
overwriteSchemaTpl('imgCaption', I18nComptType.Textarea);
|
||||
overwriteSchemaTpl('taskRemark', I18nComptType.Textarea);
|
||||
overwriteSchemaTpl('tooltip', I18nComptType.Textarea);
|
||||
overwriteSchemaTpl('anchorTitle');
|
||||
overwriteSchemaTpl('avatarText');
|
||||
overwriteSchemaTpl('cardTitle');
|
||||
overwriteSchemaTpl('cardSubTitle');
|
||||
overwriteSchemaTpl('cardsPlaceholder');
|
||||
overwriteSchemaTpl('cardDesc', I18nComptType.Textarea);
|
||||
overwriteSchemaTpl('imageTitle');
|
||||
overwriteSchemaTpl('imageDesc', I18nComptType.Textarea);
|
||||
overwriteSchemaTpl('fetchSuccess');
|
||||
overwriteSchemaTpl('fetchFailed');
|
||||
overwriteSchemaTpl('saveOrderSuccess');
|
||||
overwriteSchemaTpl('saveOrderFailed');
|
||||
overwriteSchemaTpl('quickSaveSuccess');
|
||||
overwriteSchemaTpl('quickSaveFailed');
|
||||
overwriteSchemaTpl('saveSuccess');
|
||||
overwriteSchemaTpl('saveFailed');
|
||||
overwriteSchemaTpl('validateFailed');
|
||||
overwriteSchemaTpl('tablePlaceholder');
|
||||
overwriteSchemaTpl('collapseOpenHeader');
|
||||
overwriteSchemaTpl('matrixColumnLabel');
|
||||
overwriteSchemaTpl('matrixRowLabel');
|
||||
overwriteSchemaTpl('matrixRowTitle');
|
||||
overwriteSchemaTpl('submitText');
|
||||
overwriteSchemaTpl('tpl:btnLabel', I18nComptType.ButtonLabel);
|
||||
overwriteSchemaTpl('switchOption');
|
||||
overwriteSchemaTpl('createBtnLabel');
|
||||
overwriteSchemaTpl('tableCellPlaceholder');
|
||||
overwriteSchemaTpl('addOnLabel');
|
||||
overwriteSchemaTpl('onText');
|
||||
overwriteSchemaTpl('offText');
|
||||
overwriteSchemaTpl('propertyTitle');
|
||||
overwriteSchemaTpl('propertyLabel');
|
||||
overwriteSchemaTpl('propertyContent');
|
||||
overwriteSchemaTpl('draggableTip');
|
||||
overwriteSchemaTpl('deleteConfirmText');
|
||||
overwriteSchemaTpl('optionsLabel');
|
||||
overwriteSchemaTpl('checkAllLabel');
|
||||
overwriteSchemaTpl('name');
|
||||
overwriteSchemaTpl('anchorNavTitle');
|
||||
|
||||
setSchemaTpl(
|
||||
'remark',
|
||||
remarkTpl({
|
||||
name: 'remark',
|
||||
label: '控件提示',
|
||||
labelRemark:
|
||||
'在输入控件旁展示提示,注意控件宽度需设置,否则提示触发图标将自动换行',
|
||||
i18nEnabled: true
|
||||
})
|
||||
);
|
||||
|
||||
setSchemaTpl(
|
||||
'labelRemark',
|
||||
remarkTpl({
|
||||
name: 'labelRemark',
|
||||
label: '标题提示',
|
||||
labelRemark: '在标题旁展示提示',
|
||||
i18nEnabled: true
|
||||
})
|
||||
);
|
||||
Reference in New Issue
Block a user