Skip to content

1.x generator增加onSelectItemCopy画布选择复制事件回调方法 #1637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e4d0540
1.x 文档发布测试
Feb 22, 2023
fa11c3c
文案修改
Feb 22, 2023
bea1982
修改文档
lhbxs Mar 4, 2023
08e9e76
fix:修复schema 默认有 labelWidth时,配置项重新设置 lableWidth,预览区没有效果
Mar 9, 2023
515abd3
Merge pull request #1077 from alibaba/fix-gen
lhbxs Mar 9, 2023
37c78f8
fix(form-render):removeErrorField 无法完全清除(多次调用)
Mar 15, 2023
bd66229
移除 demo
Mar 15, 2023
e4f9a75
移除 demo
Mar 15, 2023
80f6556
发布
Mar 15, 2023
5bc0e19
Merge pull request #1096 from alibaba/fix-removeErrorField
lhbxs Mar 15, 2023
ba8a3af
修改 v2版本跳转路径
Mar 23, 2023
2ab84f8
兼容 disableDate 外部传入
Apr 15, 2023
7c8fbaa
兼容 disableDate 外部传入
Apr 15, 2023
bdd7cdd
Merge pull request #1162 from alibaba/fix-disableDate
lhbxs Apr 20, 2023
f0eee30
fix: schema-generator 布局错乱
lhbxs Apr 21, 2023
d497656
fix: schema-generator 布局错乱
lhbxs Apr 21, 2023
8eb9957
去除调试
lhbxs Apr 21, 2023
5972276
Merge pull request #1175 from alibaba/fix-schema-generator-layout
lhbxs Apr 21, 2023
ad44bb4
feat: 增加 license
May 10, 2023
70d7f9f
feat: fr-generator 增加 License
May 10, 2023
479a574
Merge pull request #1223 from alibaba/feat-license
lhbxs May 10, 2023
1785210
feat: 迭代开发
Jun 30, 2023
7fe9875
Merge pull request #1324 from alibaba/fix-image-rule
lhbxs Jun 30, 2023
47f2d0e
feat: 兼容图片格式校验
Jul 4, 2023
3a8d571
feat(generator): 新增pop交互,用于介绍组件。
u-hey Jul 25, 2023
070b4b4
Merge pull request #1352 from alibaba/feat-generator-setting
lhbxs Jul 27, 2023
98d1e51
git pull
Sep 22, 2023
f701c87
fix: 修复分页逻辑
Sep 22, 2023
ffce6b4
fix: 修复 `refresh` stay 之后 分页数据不更新
Sep 22, 2023
afad269
Merge pull request #1392 from alibaba/refresh
lhbxs Sep 22, 2023
7d7d9a9
feat: 修复 schema 被篡改
Jan 3, 2024
4601d42
feat: 修复 schema 被篡改
Jan 3, 2024
596329b
Merge pull request #1457 from alibaba/table-render-v1
lhbxs Jan 3, 2024
bdb70a7
feat: 放出文档
Feb 4, 2024
2b5caa8
feat:generate增加onSelectItemCopy方法
Mar 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .umirc.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,4 @@ export default defineConfig({
plugins: [require.resolve('./scripts/dumi-plugin/redirect')],
// more config: https://d.umijs.org/config
});

2 changes: 1 addition & 1 deletion docs/form-render/api/props.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ toc: content
| colon | 是否显示 label 后面的冒号 | `boolean` | true |
| widgets | 自定义组件,当内置组件无法满足时使用,详见[Widgets](#widgets) | `Record<string, ReactNode>` | - |
| watch | 监听表单的数据变化,详见[Watch](#watch) | `Record<string, (val: any) => void \| { handler:(val:any) => void,immediate?: boolean }>` | - |
| removeHiddenData | 提交数据的时候是否去掉已经被隐藏的元素的数据,默认不隐藏 | `boolean` | true |
| removeHiddenData | 提交数据的时候是否去掉已经被隐藏的元素的数据,默认隐藏 | `boolean` | true |
| readOnly | 只读模式,一般用于预览展示,全文 text 展示 | `boolean` | false |
| className | 顶层 className | `string` | - |
| style | 顶层 style | `CSSProperties` | - |
Expand Down
1 change: 0 additions & 1 deletion docs/form-render/faq.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
order: 7
toc: false
hide: true
---

# 常见问题
Expand Down
1 change: 0 additions & 1 deletion docs/form-render/migrate.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
order: 6
title: 0.x 到 1.x 升级方案
toc: content
hide: true
---

# 升级方案
Expand Down
2 changes: 2 additions & 0 deletions docs/generator/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export default Demo;
| onChange | 表单 data 变化回调 | 表单的 data |
| onSchemaChange | 表单 schema 变化回调 | 导出的 schema |
| onCanvasSelect | 画布组件选择回调 | 选中项的 schema |
| onSelectItemCopy | 画布组件选择复制事件回调 | 复制前的schema,复制后的schema,复制前的ID,复制后的ID |


### Methods

Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ hero:
link: /playground
- text: 开始使用
link: /form-render
- text: V2 alpha
link: 'https://xrender2.vercel.app/form-render/migrate'
- text: V2 版
link: 'https://xrender.fun/'
features:
- icon: https://qpluspicture.oss-cn-beijing.aliyuncs.com/k21jAW/006-parade-5.png
title: FormRender
Expand Down
5 changes: 5 additions & 0 deletions packages/form-render/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog


## 1.14.17
- [!] 图片组件格式放宽限制,支持网络链接
## 1.14.15
- [!] removeErrorField 无法完全清除(同步被多个组件调用)
## 1.14.14
- [!] 修复 theme Ts 类型声明

Expand Down
21 changes: 21 additions & 0 deletions packages/form-render/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019-present XRender Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion packages/form-render/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "form-render",
"version": "1.14.14",
"version": "1.14.17",
"description": "通过 JSON Schema 生成标准 Form,常用于自定义搭建配置界面生成",
"keywords": [
"Form",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { isObject } from './utils';
import { Schema } from '../../index';
import { RuleItem, RuleType } from 'async-validator';
import { orderBy } from 'lodash-es';
import { isUrl } from '../../utils';

// 校验时间格式
function validatorTime(value?: string) {
Expand Down Expand Up @@ -78,7 +79,11 @@ function validatorImage(value?: string) {

// 从0.x迁移过来的正则
const imagePattern = '([/|.|w|s|-])*.(?:jpg|gif|png|bmp|apng|webp|jpeg|json)';
return new RegExp(imagePattern).test(value);

// image 里也可以填写网络链接
const _isUrl = isUrl(value);
const _isImg = new RegExp(imagePattern).test(value);
return _isUrl || _isImg;
}

// 将x-render的schema转为async-validator的格式
Expand Down
4 changes: 4 additions & 0 deletions packages/form-render/src/form-render-core/src/useForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ const useForm = props => {
let newOutError = _outErrorFields.current.filter(item => {
return item.name.indexOf(path) === -1;
});

_outErrorFields.current = newOutError;
_errorFields.current = newError;

setState({ errorFields: newError, outErrorFields: newOutError });
};

Expand Down
8 changes: 6 additions & 2 deletions packages/form-render/src/widgets/antd/dateRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,20 @@ const DateRange = ({ onChange, format, value, style, ...rest }) => {
}

if (props.disabledDate && typeof props.disabledDate === 'string') {
const func = methods[props.disabledDate];
const func = methods?.[props.disabledDate];
if (typeof func === 'function') {
dateParams.disabledDate = func;
} else {
dateParams.disabledDate = undefined;
}
}

if (props.disabledTime && typeof props.disabledTime === 'string') {
const func = methods[props.disabledTime];
const func = methods?.[props.disabledTime];
if (typeof func === 'function') {
dateParams.disabledTime = func;
} else {
dateParams.disabledTime = undefined;
}
}

Expand Down
5 changes: 5 additions & 0 deletions packages/table-render/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

### 1.3.15
- [+] 修复 search schema 被篡改

### 1.3.14
- [+] 修复 `refresh` stay 之后 分页数据不更新
### 1.3.11
- [+] 修复 `refresh` stay 参数不生效
### 1.3.10
Expand Down
21 changes: 21 additions & 0 deletions packages/table-render/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019-present XRender Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion packages/table-render/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "table-render",
"version": "1.3.13",
"version": "1.3.15",
"description": "中后台表格解决方案",
"keywords": [
"TableRender",
Expand Down
2 changes: 1 addition & 1 deletion packages/table-render/src/components/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ const Search: <RecordType extends object = any>(
onFinish,
...props,
form,
schema: formSchema,
schema: cloneDeep(formSchema),
widgets: {
searchBtn: () => <MySearchBtn {...btnProps} />,
...props.widgets,
Expand Down
16 changes: 10 additions & 6 deletions packages/table-render/src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,19 @@ const useTableRoot = props => {
.then(res => {
// TODO:这里校验res是否规范
const { rows, total, pageSize, ...extraData } = res;
const newPagination = {
..._pagination,
total,
pageSize: pageSize || _pageSize,
};

set({
loading: false,
dataSource: rows,
...extraData,
pagination: {
..._pagination,
total,
pageSize: pageSize || _pageSize,
},
pagination: newPagination,
});
paginationRef.current = newPagination;
afterSearch.current({ rows, total, pageSize, ...extraData });
})
.catch(err => {
Expand All @@ -101,8 +104,9 @@ const useTableRoot = props => {
params?: { tab?: string | number; stay?: boolean },
moreSearch?: any
) => {
const _stay = (params && params.stay) || false;
const _stay = params?.stay || false;
const _search = moreSearch || {};

doSearch(
{
current: _stay ? paginationRef?.current?.current : 1,
Expand Down
3 changes: 3 additions & 0 deletions tools/schema-generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

### 2.8.5
- [!] 修复schema 默认有 labelWidth时,配置项重新设置 lableWidth,预览区没有效果

### 2.8.1

- [!] 支持 React18
Expand Down
21 changes: 21 additions & 0 deletions tools/schema-generator/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019-present XRender Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 2 additions & 1 deletion tools/schema-generator/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "fr-generator",
"version": "2.8.5-beta.3",
"version": "2.9.0-beta.1",
"main": "dist/index.js",
"module": "dist/index.esm.js",
"typings": "dist/index.d.ts",
"license": "MIT",
"scripts": {
"beta": "npm publish --tag beta",
"build": "father-build",
Expand Down
4 changes: 3 additions & 1 deletion tools/schema-generator/src/Provider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function Provider(props, ref) {
fieldWrapperRender,
elementRender,
prefixCls,
onSelectItemCopy,
} = props;

const transformer = {
Expand Down Expand Up @@ -139,7 +140,7 @@ function Provider(props, ref) {

let _schema = {};
if (schema) {
_schema = combineSchema(schema); // TODO: 要不要判断是否都是object
_schema = combineSchema({ ...schema, ...frProps }); // TODO: 要不要判断是否都是object
}
const flatten = flattenSchema(_schema);
const flattenWithData = transformer.from(dataToFlatten(flatten, formData));
Expand Down Expand Up @@ -215,6 +216,7 @@ function Provider(props, ref) {
onChange,
errorFields,
onItemErrorChange: setErrorFields,
onSelectItemCopy,
userProps,
frProps,
displaySchema,
Expand Down
5 changes: 5 additions & 0 deletions tools/schema-generator/src/components/Canvas/core/Wrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
copyItem,
dropItem,
getKeyFromUniqueId,
idToSchema,
isObject,
} from '../../../utils';
import { useGlobal, useStore } from '../../../utils/hooks';
Expand All @@ -19,6 +20,7 @@ function Wrapper({ $id, item, inside = false, children, style }) {
userProps,
errorFields,
fieldWrapperRender,
onSelectItemCopy,
} = useStore();
const {
controlButtons,
Expand Down Expand Up @@ -142,9 +144,12 @@ function Wrapper({ $id, item, inside = false, children, style }) {
const handleItemCopy = e => {
e.stopPropagation();
if (errorFields?.length) return;
const preSchema = idToSchema(flatten);
const [newFlatten, newId] = copyItem(flatten, $id, getId);
onFlattenChange(newFlatten);
setGlobal({ selected: newId });
const curSchema = idToSchema(newFlatten);
onSelectItemCopy && onSelectItemCopy(preSchema, curSchema, $id, newId);
};

// 一些computed
Expand Down
4 changes: 2 additions & 2 deletions tools/schema-generator/src/components/Canvas/core/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ const FR = ({ id = '#', preview, displaySchema }) => {
let contentClass = 'fr-content';

let columnStyle = {};
if (width) {
if (!isComplex && width) {
columnStyle = {
width,
paddingRight: '12px',
};
} else if (column > 1) {
} else if (!isComplex && column > 1) {
columnStyle = {
width: `calc(100% /${column})`,
paddingRight: '12px',
Expand Down
28 changes: 20 additions & 8 deletions tools/schema-generator/src/components/Sidebar/Element.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import { Popover } from 'antd';
import { useDrag } from 'react-dnd';
import { useTranslation } from 'react-i18next';
import { addItem } from '../../utils';
import { useGlobal, useStore } from '../../utils/hooks';
import './Element.less';

const Element = ({ text, name, schema, icon, fixedName }) => {
const Element = ({ text, name, schema, icon, fixedName, popover }) => {
const setGlobal = useGlobal();
const {
selected,
Expand Down Expand Up @@ -52,6 +53,7 @@ const Element = ({ text, name, schema, icon, fixedName }) => {
const widgetProps = {
text,
icon,
popover,
onClick: handleElementClick,
};

Expand All @@ -69,12 +71,22 @@ const Element = ({ text, name, schema, icon, fixedName }) => {
export default Element;

// 目前没有用icon,但是可以补上
const WidgetUI = ({ onClick, text, icon }) => {
const WidgetUI = ({ onClick, text, icon, popover }) => {
const { t } = useTranslation(["components"]);
return (
<li className="left-item" onClick={onClick}>
{icon}
{t(text)}
</li>
);
if (popover?.content) {
return <Popover title={popover?.title || ''} content={popover?.content} mouseLeaveDelay={0}>
<li className="left-item" onClick={onClick}>
{icon}
{t(text)}
</li>
</Popover>
} else {
return (
<li className="left-item" onClick={onClick}>
{icon}
{t(text)}
</li>
);
}

};
Loading