Skip to content

Commit

Permalink
🔀 fix: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
ONLY-yours committed Dec 20, 2023
2 parents 1ad2603 + 111e14d commit 1df83ce
Show file tree
Hide file tree
Showing 27 changed files with 4,612 additions and 2,306 deletions.
15 changes: 11 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
# Changelog

## [Version 0.32.0-rc.3](https://github.com/ant-design/pro-editor/compare/v0.32.0-rc.2...v0.32.0-rc.3)
## [Version 0.32.0](https://github.com/ant-design/pro-editor/compare/v0.31.1...v0.32.0)

<sup>Released on **2023-12-20**</sup>

#### ✨ 新特性

- SortableList support handle control.

#### 🐛 修复

- Fix markdown & highlight not support memo, remove demo old api.
- Fix creatorButtonProps and add demos.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's improved

- SortableList support handle control ([6a1ea43](https://github.com/ant-design/pro-editor/commit/6a1ea43))

#### What's fixed

- Fix markdown & highlight not support memo ([136850f](https://github.com/ant-design/pro-editor/commit/136850f))
- Remove demo old api ([fd9ff8c](https://github.com/ant-design/pro-editor/commit/fd9ff8c))
- Fix creatorButtonProps and add demos ([4f37d45](https://github.com/ant-design/pro-editor/commit/4f37d45))

</details>

Expand Down
36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ant-design/pro-editor",
"version": "0.32.0-rc.3",
"version": "0.32.0",
"description": "🌟 Lightweight Editor UI Framework",
"homepage": "https://github.com/ant-design/pro-editor",
"bugs": {
Expand Down Expand Up @@ -62,15 +62,15 @@
"@ant-design/icons": "^5.2.6",
"@ant-design/pro-components": "^2.6.43",
"@antv/dw-random": "^1.1.7",
"@babel/runtime": "^7.23.4",
"@babel/runtime": "^7.23.6",
"@dnd-kit/core": "^6.1.0",
"@dnd-kit/modifiers": "^6.0.1",
"@dnd-kit/sortable": "^7.0.2",
"@dnd-kit/utilities": "^3.2.2",
"@emotion/styled": "^11.11.0",
"@faker-js/faker": "^7.6.0",
"@floating-ui/react": "^0.24.8",
"@mui/material": "^5.14.18",
"@mui/material": "^5.15.1",
"@textea/json-viewer": "^3.2.3",
"ahooks": "^3.7.8",
"classnames": "^2.3.2",
Expand All @@ -94,7 +94,7 @@
"lodash.unionby": "^4.8.0",
"lodash.uniq": "^4.5.0",
"mockjs": "^1.1.0",
"nanoid": "^5.0.3",
"nanoid": "^5.0.4",
"polished": "^4.2.2",
"prettier": "^2.8.8",
"rc-util": "^5.38.1",
Expand All @@ -115,51 +115,51 @@
"umi-request": "^1.4.0",
"use-merge-value": "^1.2.0",
"yjs": "^13.6.10",
"zustand": "^4.4.6",
"zustand": "^4.4.7",
"zustand-middleware-yjs": "^1.3.1",
"zustand-utils": "^1.3.1"
},
"devDependencies": {
"@emotion/jest": "^11.11.0",
"@lobehub/i18n-cli": "^1.15.0",
"@testing-library/jest-dom": "^6.1.4",
"@lobehub/i18n-cli": "^1.15.3",
"@testing-library/jest-dom": "^6.1.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^14.5.1",
"@types/color": "^3.0.6",
"@types/json-schema": "^7.0.15",
"@types/react": "^18.2.38",
"@types/react-dom": "^18.2.17",
"@umijs/lint": "^4.0.88",
"@types/react": "^18.2.45",
"@types/react-dom": "^18.2.18",
"@umijs/lint": "^4.0.89",
"@vitest/coverage-v8": "latest",
"antd": "^5.11.4",
"antd-style": "^3.5.2",
"antd": "^5.12.4",
"antd-style": "^3.6.1",
"babel-plugin-antd-style": "^1.0.4",
"commitlint": "^17.8.1",
"commitlint-config-gitmoji": "^2.3.1",
"conventional-changelog-gitmoji-config": "^1.5.2",
"dumi": "^2.2.14",
"dumi": "^2.2.16",
"dumi-theme-antd-style": "latest",
"eslint": "^8.54.0",
"father": "^4.3.7",
"eslint": "^8.56.0",
"father": "^4.3.8",
"gh-pages": "^5.0.0",
"glob": "^10.3.10",
"husky": "^8.0.3",
"jsdom": "^22.1.0",
"lint-staged": "^13.3.0",
"prettier-plugin-organize-imports": "^3.2.4",
"prettier-plugin-packagejson": "^2.4.6",
"prettier-plugin-packagejson": "^2.4.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rxjs-spy": "^8.0.2",
"semantic-release": "^21.1.2",
"semantic-release-config-gitmoji": "^1.5.3",
"stylelint": "^15.11.0",
"typescript": "^5.3.2",
"typescript": "^5.3.3",
"vitest": "latest",
"wait-on": "^6.0.1",
"y-protocols": "^1.0.6",
"y-webrtc": "^10.2.6",
"y-websocket": "^1.5.0",
"y-websocket": "^1.5.1",
"zundo": "beta"
},
"peerDependencies": {
Expand Down
15 changes: 14 additions & 1 deletion src/ColumnList/ColumnItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
ColumnItemList,
CreatorButtonProps,
DeleteAction,
HandleAction,
useSortableList,
Expand Down Expand Up @@ -77,10 +78,21 @@ interface ItemRenderProps<T = any> {
listeners: any;
actions?: React.ReactNode[];
hideRemove?: boolean;
creatorButtonProps: CreatorButtonProps | false;
}

const ColumnItem = memo<ItemRenderProps>(
({ item, index, prefixCls, columns, listeners, actions, hideRemove, dragging }) => {
({
item,
index,
prefixCls,
columns,
listeners,
actions,
hideRemove,
dragging,
creatorButtonProps,
}) => {
const { styles } = useStyle(prefixCls);
const instance = useSortableList();
return (
Expand All @@ -105,6 +117,7 @@ const ColumnItem = memo<ItemRenderProps>(
prefixCls,
style,
placeholder: col.placeholder,
creatorButtonProps,
};
switch (col.type) {
default:
Expand Down
83 changes: 55 additions & 28 deletions src/ColumnList/ColumnList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
CreatorButtonProps,
SortableList,
SortableListProps,
SortableListRef,
Expand All @@ -17,35 +18,61 @@ export interface ColumnListProps<T = any> extends SortableListProps<T> {
const ColumnList: <T>(props: ColumnListProps<T>) => ReturnType<FC> = forwardRef<
SortableListRef,
ColumnListProps
>(({ prefixCls: customPrefixCls, className, columns, actions, hideRemove, ...props }, ref) => {
const prefixCls = getPrefixCls('column-list', customPrefixCls);
const { cx } = useStyle(prefixCls);
>(
(
{
prefixCls: customPrefixCls,
className,
columns,
actions,
hideRemove,
creatorButtonProps,
...props
},
ref,
) => {
const prefixCls = getPrefixCls('column-list', customPrefixCls);
const { cx } = useStyle(prefixCls);

const renderItem = useCallback(
(item, { index, listeners, dragging }) => (
<ColumnItem
columns={columns}
item={item}
dragging={dragging}
listeners={listeners}
index={index}
prefixCls={prefixCls}
actions={typeof actions === 'function' ? actions(item, index) : actions}
hideRemove={hideRemove}
/>
),
[prefixCls, columns],
);
// ColumnList 默认有添加一行按钮
const customCreatorButtonProps: CreatorButtonProps | false =
creatorButtonProps === false
? false
: {
position: 'bottom' as const,
// 默认生成空数据
record: () => ({}),
...creatorButtonProps,
};

const renderItem = useCallback(
(item, { index, listeners, dragging }) => (
<ColumnItem
columns={columns}
item={item}
dragging={dragging}
listeners={listeners}
index={index}
prefixCls={prefixCls}
actions={typeof actions === 'function' ? actions(item, index) : actions}
creatorButtonProps={customCreatorButtonProps}
hideRemove={hideRemove}
/>
),
[prefixCls, columns],
);

return (
<SortableList
ref={ref}
renderItem={renderItem}
renderHeader={() => <Header prefixCls={prefixCls} columns={columns} />}
className={cx(prefixCls, className)}
{...props}
/>
);
});
return (
<SortableList
ref={ref}
renderItem={renderItem}
renderHeader={() => <Header prefixCls={prefixCls} columns={columns} />}
className={cx(prefixCls, className)}
creatorButtonProps={customCreatorButtonProps}
{...props}
/>
);
},
);

export default ColumnList;
1 change: 1 addition & 0 deletions src/ColumnList/demos/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default () => (
<ActionIcon
icon={<EditFilled />}
key={'edit'}
style={{ height: 22 }}
tabIndex={-1}
onClick={() => message.info(field.dataIndex)}
/>,
Expand Down
2 changes: 1 addition & 1 deletion src/ColumnList/demos/creatorButtonProps.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* title: 自定义初始化
* description: 可通过 `creatorButtonProps` 来自定义初始化逻辑,id 的生成逻辑是必须的。
* description: 可通过 `creatorButtonProps` 来自定义初始化逻辑
*/
import type { ColumnItemList } from '@ant-design/pro-editor';
import { ColumnList } from '@ant-design/pro-editor';
Expand Down
68 changes: 68 additions & 0 deletions src/ColumnList/demos/creatorButtonPropsFalse.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* title: 关闭添加能力
* description: 可通过 `creatorButtonProps={false}` 来关闭添加功能,包括添加一行按钮,回车添加以及空状态添加
*/
import type { ColumnItemList } from '@ant-design/pro-editor';
import { ColumnList } from '@ant-design/pro-editor';
import { tableColumnValueOptions } from './mock_data/options';

type SchemaItem = {
title: string;
valueType?: string;
dataIndex: string;
};

const INIT_VALUES = [
{
dataIndex: 'productName',
valueType: 'text',
title: '产品名称',
color: undefined,
},
{
dataIndex: 'productComment',
valueType: 'text',
title: '产品介绍',
color: undefined,
},
{
dataIndex: 'orderStatus',
valueType: 'text',
title: '订单状态',
},
];

/**
* 创建一个随机的索引标记符,请勿在生产环境使用
*/
export const randomIndex = () => Math.random() * 10000;

const columns: ColumnItemList<SchemaItem> = [
{
title: '列标题',
dataIndex: 'title',
type: 'input',
},
{
title: '值类型',
dataIndex: 'valueType',
type: 'select',
options: tableColumnValueOptions,
},
{
title: '字段',
dataIndex: 'dataIndex',
type: 'select',
},
];

export default () => (
<ColumnList<SchemaItem>
columns={columns}
initialValues={INIT_VALUES}
onChange={(values) => {
console.log('onChange', values);
}}
creatorButtonProps={false}
/>
);
13 changes: 9 additions & 4 deletions src/ColumnList/demos/customCreate.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* title: 自定义创建逻辑
* description: 你可以设置 `creatorButtonProps={false}` 来关闭默认的创建效果,然后自定义创建逻辑
* description: 你可以设置 `style` 属性来隐藏默认添加按钮,然后自定义创建按钮
*/
import { PlusCircleTwoTone } from '@ant-design/icons';
import type { ColumnItemList, SortableListRef } from '@ant-design/pro-editor';
Expand Down Expand Up @@ -58,9 +58,14 @@ const columns: ColumnItemList<SchemaItem> = [
export default () => {
const ref = useRef<SortableListRef<SchemaItem>>(null);

const handleCreate = () => {
const createNewRecord = () => {
const id = `id-${randomIndex()}}`;
ref.current.addItem({ dataIndex: id, title: `new-${id}`, valueType: 'text' });
return { dataIndex: '', title: `new-${id}`, valueType: 'text' };
};

const handleCreate = () => {
const data = createNewRecord();
ref.current.addItem(data);
};

return (
Expand Down Expand Up @@ -93,7 +98,7 @@ export default () => {
onChange={(values) => {
console.log('onChange', values);
}}
creatorButtonProps={false}
creatorButtonProps={{ style: { display: 'none' }, record: createNewRecord }}
/>
</>
);
Expand Down
Loading

0 comments on commit 1df83ce

Please sign in to comment.