diff --git a/.umirc.js b/.umirc.js index 4beaa59e7..64d29e29e 100644 --- a/.umirc.js +++ b/.umirc.js @@ -100,3 +100,4 @@ export default defineConfig({ plugins: [require.resolve('./scripts/dumi-plugin/redirect')], // more config: https://d.umijs.org/config }); + diff --git a/docs/form-render/api/props.md b/docs/form-render/api/props.md index 797a3b36c..d3ae46304 100644 --- a/docs/form-render/api/props.md +++ b/docs/form-render/api/props.md @@ -20,7 +20,7 @@ toc: content | colon | 是否显示 label 后面的冒号 | `boolean` | true | | widgets | 自定义组件,当内置组件无法满足时使用,详见[Widgets](#widgets) | `Record` | - | | watch | 监听表单的数据变化,详见[Watch](#watch) | `Record void \| { handler:(val:any) => void,immediate?: boolean }>` | - | -| removeHiddenData | 提交数据的时候是否去掉已经被隐藏的元素的数据,默认不隐藏 | `boolean` | true | +| removeHiddenData | 提交数据的时候是否去掉已经被隐藏的元素的数据,默认隐藏 | `boolean` | true | | readOnly | 只读模式,一般用于预览展示,全文 text 展示 | `boolean` | false | | className | 顶层 className | `string` | - | | style | 顶层 style | `CSSProperties` | - | diff --git a/docs/form-render/faq.md b/docs/form-render/faq.md index 5495716b2..d4734a8e0 100644 --- a/docs/form-render/faq.md +++ b/docs/form-render/faq.md @@ -1,7 +1,6 @@ --- order: 7 toc: false -hide: true --- # 常见问题 diff --git a/docs/form-render/migrate.md b/docs/form-render/migrate.md index 79c3803b3..3cbf28b8d 100644 --- a/docs/form-render/migrate.md +++ b/docs/form-render/migrate.md @@ -2,7 +2,6 @@ order: 6 title: 0.x 到 1.x 升级方案 toc: content -hide: true --- # 升级方案 diff --git a/docs/generator/index.md b/docs/generator/index.md index ffd2d82b9..e20d5604d 100644 --- a/docs/generator/index.md +++ b/docs/generator/index.md @@ -91,6 +91,8 @@ export default Demo; | onChange | 表单 data 变化回调 | 表单的 data | | onSchemaChange | 表单 schema 变化回调 | 导出的 schema | | onCanvasSelect | 画布组件选择回调 | 选中项的 schema | +| onSelectItemCopy | 画布组件选择复制事件回调 | 复制前的schema,复制后的schema,复制前的ID,复制后的ID | + ### Methods diff --git a/docs/index.md b/docs/index.md index 8df5023ca..ba8a661e2 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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 diff --git a/packages/form-render/CHANGELOG.md b/packages/form-render/CHANGELOG.md index 7da51cb55..b00a44590 100644 --- a/packages/form-render/CHANGELOG.md +++ b/packages/form-render/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog + +## 1.14.17 +- [!] 图片组件格式放宽限制,支持网络链接 +## 1.14.15 +- [!] removeErrorField 无法完全清除(同步被多个组件调用) ## 1.14.14 - [!] 修复 theme Ts 类型声明 diff --git a/packages/form-render/LICENSE b/packages/form-render/LICENSE new file mode 100644 index 000000000..a68fd737b --- /dev/null +++ b/packages/form-render/LICENSE @@ -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. diff --git a/packages/form-render/package.json b/packages/form-render/package.json index eb1bfd5d1..98fcf56e4 100644 --- a/packages/form-render/package.json +++ b/packages/form-render/package.json @@ -1,6 +1,6 @@ { "name": "form-render", - "version": "1.14.14", + "version": "1.14.17", "description": "通过 JSON Schema 生成标准 Form,常用于自定义搭建配置界面生成", "keywords": [ "Form", diff --git a/packages/form-render/src/form-render-core/src/getDescriptorSimple.ts b/packages/form-render/src/form-render-core/src/getDescriptorSimple.ts index 419e186f7..6bb7f6056 100644 --- a/packages/form-render/src/form-render-core/src/getDescriptorSimple.ts +++ b/packages/form-render/src/form-render-core/src/getDescriptorSimple.ts @@ -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) { @@ -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的格式 diff --git a/packages/form-render/src/form-render-core/src/useForm.js b/packages/form-render/src/form-render-core/src/useForm.js index bd254fc46..6bd38ede0 100644 --- a/packages/form-render/src/form-render-core/src/useForm.js +++ b/packages/form-render/src/form-render-core/src/useForm.js @@ -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 }); }; diff --git a/packages/form-render/src/widgets/antd/dateRange.js b/packages/form-render/src/widgets/antd/dateRange.js index e5c26fd8f..2c982f306 100644 --- a/packages/form-render/src/widgets/antd/dateRange.js +++ b/packages/form-render/src/widgets/antd/dateRange.js @@ -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; } } diff --git a/packages/table-render/CHANGELOG.md b/packages/table-render/CHANGELOG.md index bb8c83a9f..d090332b0 100644 --- a/packages/table-render/CHANGELOG.md +++ b/packages/table-render/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +### 1.3.15 +- [+] 修复 search schema 被篡改 + +### 1.3.14 +- [+] 修复 `refresh` stay 之后 分页数据不更新 ### 1.3.11 - [+] 修复 `refresh` stay 参数不生效 ### 1.3.10 diff --git a/packages/table-render/LICENSE b/packages/table-render/LICENSE new file mode 100644 index 000000000..a68fd737b --- /dev/null +++ b/packages/table-render/LICENSE @@ -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. diff --git a/packages/table-render/package.json b/packages/table-render/package.json index 7a2709806..5de84cdd1 100644 --- a/packages/table-render/package.json +++ b/packages/table-render/package.json @@ -1,6 +1,6 @@ { "name": "table-render", - "version": "1.3.13", + "version": "1.3.15", "description": "中后台表格解决方案", "keywords": [ "TableRender", diff --git a/packages/table-render/src/components/Search.tsx b/packages/table-render/src/components/Search.tsx index a3a0479af..1f2441438 100644 --- a/packages/table-render/src/components/Search.tsx +++ b/packages/table-render/src/components/Search.tsx @@ -165,7 +165,7 @@ const Search: ( onFinish, ...props, form, - schema: formSchema, + schema: cloneDeep(formSchema), widgets: { searchBtn: () => , ...props.widgets, diff --git a/packages/table-render/src/components/index.tsx b/packages/table-render/src/components/index.tsx index 42bd7ca2f..f32ef54c2 100644 --- a/packages/table-render/src/components/index.tsx +++ b/packages/table-render/src/components/index.tsx @@ -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 => { @@ -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, diff --git a/tools/schema-generator/CHANGELOG.md b/tools/schema-generator/CHANGELOG.md index 1d850eb54..c8c6888b1 100644 --- a/tools/schema-generator/CHANGELOG.md +++ b/tools/schema-generator/CHANGELOG.md @@ -1,5 +1,8 @@ # Change Log +### 2.8.5 +- [!] 修复schema 默认有 labelWidth时,配置项重新设置 lableWidth,预览区没有效果 + ### 2.8.1 - [!] 支持 React18 diff --git a/tools/schema-generator/LICENSE b/tools/schema-generator/LICENSE new file mode 100644 index 000000000..a68fd737b --- /dev/null +++ b/tools/schema-generator/LICENSE @@ -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. diff --git a/tools/schema-generator/package.json b/tools/schema-generator/package.json index a043f4782..2b9bfd6f1 100644 --- a/tools/schema-generator/package.json +++ b/tools/schema-generator/package.json @@ -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", diff --git a/tools/schema-generator/src/Provider.jsx b/tools/schema-generator/src/Provider.jsx index 7e9f148c1..616624171 100644 --- a/tools/schema-generator/src/Provider.jsx +++ b/tools/schema-generator/src/Provider.jsx @@ -62,6 +62,7 @@ function Provider(props, ref) { fieldWrapperRender, elementRender, prefixCls, + onSelectItemCopy, } = props; const transformer = { @@ -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)); @@ -215,6 +216,7 @@ function Provider(props, ref) { onChange, errorFields, onItemErrorChange: setErrorFields, + onSelectItemCopy, userProps, frProps, displaySchema, diff --git a/tools/schema-generator/src/components/Canvas/core/Wrapper.jsx b/tools/schema-generator/src/components/Canvas/core/Wrapper.jsx index 7c3257551..31969dfa3 100644 --- a/tools/schema-generator/src/components/Canvas/core/Wrapper.jsx +++ b/tools/schema-generator/src/components/Canvas/core/Wrapper.jsx @@ -5,6 +5,7 @@ import { copyItem, dropItem, getKeyFromUniqueId, + idToSchema, isObject, } from '../../../utils'; import { useGlobal, useStore } from '../../../utils/hooks'; @@ -19,6 +20,7 @@ function Wrapper({ $id, item, inside = false, children, style }) { userProps, errorFields, fieldWrapperRender, + onSelectItemCopy, } = useStore(); const { controlButtons, @@ -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 diff --git a/tools/schema-generator/src/components/Canvas/core/index.jsx b/tools/schema-generator/src/components/Canvas/core/index.jsx index 102a6f276..2df12023b 100644 --- a/tools/schema-generator/src/components/Canvas/core/index.jsx +++ b/tools/schema-generator/src/components/Canvas/core/index.jsx @@ -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', diff --git a/tools/schema-generator/src/components/Sidebar/Element.jsx b/tools/schema-generator/src/components/Sidebar/Element.jsx index 32468cd7a..f809518f9 100644 --- a/tools/schema-generator/src/components/Sidebar/Element.jsx +++ b/tools/schema-generator/src/components/Sidebar/Element.jsx @@ -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, @@ -52,6 +53,7 @@ const Element = ({ text, name, schema, icon, fixedName }) => { const widgetProps = { text, icon, + popover, onClick: handleElementClick, }; @@ -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 ( -
  • - {icon} - {t(text)} -
  • - ); + if (popover?.content) { + return +
  • + {icon} + {t(text)} +
  • +
    + } else { + return ( +
  • + {icon} + {t(text)} +
  • + ); + } + }; diff --git a/tools/schema-generator/src/index.d.ts b/tools/schema-generator/src/index.d.ts index 8c7767dbf..922291b05 100644 --- a/tools/schema-generator/src/index.d.ts +++ b/tools/schema-generator/src/index.d.ts @@ -107,6 +107,8 @@ export interface FRGeneratorProps { onSchemaChange?: (schema: any) => void; /** 画布组件选择回调 */ onCanvasSelect?: (schema: any) => void; + /** 画布组件选择后复制按钮回调 */ + onSelectItemCopy: (preSchema: any, curSchema: any, preId: any, curId:any) => void; } export interface SettingsProps { @@ -116,6 +118,8 @@ export interface SettingsProps { export interface CanvasProps { /** 画布组件选择回调 */ onCanvasSelect?: (schema: any) => void; + /** 画布组件选择后复制按钮回调 */ + onSelectItemCopy: (preSchema: any, curSchema: any, preId: any, curId: any) => void; } export interface SidebarProps { diff --git a/tools/schema-generator/src/settings/index.js b/tools/schema-generator/src/settings/index.js index 1c94b5ddf..bb24e89b1 100644 --- a/tools/schema-generator/src/settings/index.js +++ b/tools/schema-generator/src/settings/index.js @@ -109,6 +109,9 @@ export const elements = [ { text: '输入框', name: 'input', + popover: { + content: '可以输入内容' + }, schema: { title: '输入框', type: 'string', @@ -161,6 +164,10 @@ export const elements = [ }, { text: '大输入框', + popover: { + title: '介绍', + content: '可以输入多行内容' + }, name: 'textarea', schema: { title: '编辑框', @@ -203,6 +210,10 @@ export const elements = [ { text: '日期选择', name: 'date', + popover: { + title: '略缩图', + content: + }, schema: { title: '日期选择', type: 'string',