Skip to content

Commit

Permalink
refactor: rename eventPreprocessor to schemaFunctionPreprocessor
Browse files Browse the repository at this point in the history
  • Loading branch information
tinymins committed Aug 29, 2024
1 parent 79f9765 commit 720cc53
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ const DRIP_TABLE_SIDEBAR = [
{ title: '默认组件库名 defaultComponentLib', link: '/drip-table/props/default-component-lib' },
{ title: '组件插槽 slots', link: '/drip-table/props/slots' },
{ title: '附加透传数据 ext', link: '/drip-table/props/ext' },
{ title: '事件预处理 eventPreprocessor', link: '/drip-table/props/event-preprocessor' },
{ title: '指定行可展开 rowExpandable', link: '/drip-table/props/row-expandable' },
{ title: '行展开渲染函数 expandedRowRender', link: '/drip-table/props/expanded-row-render' },
{ title: '子表默认展开项 defaultExpandedRowKeys', link: '/drip-table/props/default-expanded-row-keys' },
{ title: '子表默认展开 defaultExpandAllRows', link: '/drip-table/props/default-expand-all-rows' },
{ title: '行头插槽是否显示 rowHeaderVisible', link: '/drip-table/props/row-header-visible' },
{ title: '行尾插槽是否显示 rowFooterVisible', link: '/drip-table/props/row-footer-visible' },
{ title: '方法预处理 schemaFunctionPreprocessor', link: '/drip-table/props/schema-function-preprocessor' },
{ title: '组件加载完成 componentDidMount', link: '/drip-table/props/component-did-mount' },
{ title: '组件更新完成 componentDidUpdate', link: '/drip-table/props/component-did-update' },
{ title: '组件即将卸载 componentWillUnmount', link: '/drip-table/props/component-will-unmount' },
Expand Down
2 changes: 1 addition & 1 deletion docs/drip-table/props/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ toc: content
| [emptyText](/drip-table/props/empty-text) | 表格无数据时提示语 | × | [🔗 示例](/drip-table/props/empty-text) |
| [subtableTitle](/drip-table/props/subtable-title) | 子表顶部自定义渲染函数 | × | [🔗 示例](/drip-table/props/subtable-title) |
| [subtableFooter](/drip-table/props/subtable-footer) | 子表底部自定义渲染函数 | × | [🔗 示例](/drip-table/props/subtable-footer) |
| [eventPreprocessor](/drip-table/props/event-preprocessor) | Schema 函数预处理 | × | [🔗 示例](/drip-table/props/event-preprocessor) |
| [rowExpandable](/drip-table/props/row-expandable) | 获取指定行是否可展开 | × | [🔗 示例](/drip-table/props/row-expandable) |
| [expandedRowRender](/drip-table/props/expanded-row-render) | 行展开自定义渲染函数 | × | [🔗 示例](/drip-table/props/expanded-row-render) |
| [rowSelectable](/drip-table/props/row-selectable) | 获取指定行是否可选择 | × | [🔗 示例](/drip-table/props/row-selectable) |
| [rowHeaderVisible](/drip-table/schema/row-header-visible) | 行头部插槽是否可见 | × | [🔗 示例](/drip-table/schema/row-header-visible) |
| [rowFooterVisible](/drip-table/schema/row-footer-visible) | 行尾部插槽是否可见 | × | [🔗 示例](/drip-table/schema/row-footer-visible) |
| [schemaFunctionPreprocessor](/drip-table/props/schema-function-preprocessor) | Schema 函数预处理 | × | [🔗 示例](/drip-table/props/schema-function-preprocessor) |
| [componentDidMount](/drip-table/props/component-did-mount) | 生命周期:组件加载完成 | × | [🔗 示例](/drip-table/props/component-did-mount) |
| [componentDidUpdate](/drip-table/props/component-did-update) | 生命周期:组件更新完成 | × | [🔗 示例](/drip-table/props/component-did-update) |
| [componentWillUnmount](/drip-table/props/component-will-unmount) | 生命周期:组件即将卸载 | × | [🔗 示例](/drip-table/props/component-will-unmount) |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
title: 事件预处理 eventPreprocessor
title: 函数预处理 schemaFunctionPreprocessor
toc: content
---

## 表格事件预处理 eventPreprocessor
## 表格 Schema 函数预处理 schemaFunctionPreprocessor

- 描述:表格 Schema 中事件函数预处理
- 描述:表格 Schema 中的函数预处理
- 类型:

```typescript
Expand Down Expand Up @@ -113,7 +113,7 @@ const Demo = () => {
schema={schema}
dataSource={dataSource}
components={{ custom: customComponents }}
eventPreprocessor={(event, props) => {
schemaFunctionPreprocessor={(event, props) => {
if (event.bTwiceEvent) {
return event(props);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ ExtraOptions extends Partial<DripTableExtraOptions> = never,
execute,
safeExecute,
finalizeString,
eventPreprocessor: void 0,
schemaFunctionPreprocessor: void 0,
},
)
: () => <div />;
Expand Down
2 changes: 1 addition & 1 deletion packages/drip-table/src/layouts/calendar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ExtraOptions extends Partial<DripTableExtraOptions> = never,
execute,
safeExecute,
finalizeString,
eventPreprocessor: tableProps.eventPreprocessor,
schemaFunctionPreprocessor: tableProps.schemaFunctionPreprocessor,
};

return (
Expand Down
2 changes: 1 addition & 1 deletion packages/drip-table/src/layouts/card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ExtraOptions extends Partial<DripTableExtraOptions> = never,
execute,
safeExecute,
finalizeString,
eventPreprocessor: tableProps.eventPreprocessor,
schemaFunctionPreprocessor: tableProps.schemaFunctionPreprocessor,
};

const mergedColumns = useMemo(() => {
Expand Down
16 changes: 8 additions & 8 deletions packages/drip-table/src/layouts/table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import * as childrenLike from '@/utils/children-like';
import { parseCSS, parseReactCSS, setElementCSS, stringifyCSS } from '@/utils/dom';
import { encodeJSON } from '@/utils/json';
import { indexValue, parseNumber, setValue } from '@/utils/operator';
import { type SandboxEventPreprocess } from '@/utils/sandbox';
import { type SandboxFunctionPreprocess } from '@/utils/sandbox';
import DripTableBuiltInComponents, { type DripTableBuiltInColumnSchema, type DripTableComponentProps } from '@/components/cell-components';
import { preventEvent } from '@/components/cell-components/utils';
import Checkbox from '@/components/react-components/checkbox';
Expand Down Expand Up @@ -223,11 +223,11 @@ const hookColumRender = <
return column;
};

function hookSchemaEventRaiser<T>(schema: T, eventPreprocessor: SandboxEventPreprocess, props: Record<string, unknown>): T {
function hookSchemaEventRaiser<T>(schema: T, schemaFunctionPreprocessor: SandboxFunctionPreprocess, props: Record<string, unknown>): T {
if (schema && typeof schema === 'object') {
return Object.fromEntries(
Object.entries(schema)
.map(([k, v]) => [k, typeof v === 'function' ? eventPreprocessor(v, props) : hookSchemaEventRaiser(v, eventPreprocessor, props)]),
.map(([k, v]) => [k, typeof v === 'function' ? schemaFunctionPreprocessor(v, props) : hookSchemaEventRaiser(v, schemaFunctionPreprocessor, props)]),
) as T;
}
return schema;
Expand Down Expand Up @@ -293,8 +293,8 @@ export const columnRenderGenerator = <
if (hiddenTranslator(false, translatorContext)) {
return null;
}
const finalColumnSchema = extraProps.eventPreprocessor
? hookSchemaEventRaiser(columnSchema, extraProps.eventPreprocessor, { value, record, recordIndex, ext })
const finalColumnSchema = extraProps.schemaFunctionPreprocessor
? hookSchemaEventRaiser(columnSchema, extraProps.schemaFunctionPreprocessor, { value, record, recordIndex, ext })
: columnSchema;
return (
<BuiltInComponent
Expand Down Expand Up @@ -345,8 +345,8 @@ export const columnRenderGenerator = <
if (hiddenTranslator(false, translatorContext)) {
return null;
}
const finalColumnSchema = extraProps.eventPreprocessor
? hookSchemaEventRaiser(columnSchema, extraProps.eventPreprocessor, { value, record, recordIndex, ext })
const finalColumnSchema = extraProps.schemaFunctionPreprocessor
? hookSchemaEventRaiser(columnSchema, extraProps.schemaFunctionPreprocessor, { value, record, recordIndex, ext })
: columnSchema;
return (
<ExtraComponent
Expand Down Expand Up @@ -1273,7 +1273,7 @@ function TableLayout<
execute,
safeExecute,
finalizeString,
eventPreprocessor: tableProps.eventPreprocessor,
schemaFunctionPreprocessor: tableProps.schemaFunctionPreprocessor,
};
const visibleColumns = childrenLike.filterRecursive(
tableProps.schema.columns,
Expand Down
2 changes: 1 addition & 1 deletion packages/drip-table/src/layouts/table/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ export interface DripTableColumnRenderOptions<
execute: SandboxExecute;
safeExecute: SandboxSafeExecute;
finalizeString: FinalizeString;
eventPreprocessor: DripTableProps<RecordType, ExtraOptions>['eventPreprocessor'];
schemaFunctionPreprocessor: DripTableProps<RecordType, ExtraOptions>['schemaFunctionPreprocessor'];
};
}
4 changes: 2 additions & 2 deletions packages/drip-table/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { SchemaObject } from 'ajv';
import type React from 'react';

import type { AjvOptions } from '@/utils/ajv';
import type { SandboxCreateExecutor, SandboxEventPreprocess } from '@/utils/sandbox';
import type { SandboxCreateExecutor, SandboxFunctionPreprocess } from '@/utils/sandbox';
import type { DripTableBuiltInColumnSchema, DripTableBuiltInComponentEvent, DripTableComponentProps } from '@/components/cell-components';
import type { PaginationProps } from '@/components/react-components/pagination';
import type { DripTableSlotSchema } from '@/components/react-components/slot-render';
Expand Down Expand Up @@ -894,7 +894,7 @@ export interface DripTableProps<
/**
* 新版事件还原器
*/
eventPreprocessor?: SandboxEventPreprocess;
schemaFunctionPreprocessor?: SandboxFunctionPreprocess;
/**
* 渲染子表时用于透传父级信息,仅限内部使用
* @internal
Expand Down
2 changes: 1 addition & 1 deletion packages/drip-table/src/utils/ajv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,12 +484,12 @@ const getDripTablePropsAjvSchema = (options?: AjvOptions) => {
emptyText: { instanceof: 'Function' },
subtableTitle: { instanceof: 'Function' },
subtableFooter: { instanceof: 'Function' },
eventPreprocessor: { instanceof: 'Function' },
rowExpandable: { instanceof: 'Function' },
expandedRowRender: { instanceof: 'Function' },
rowHeaderVisible: { instanceof: 'Function' },
rowFooterVisible: { instanceof: 'Function' },
rowSelectable: { instanceof: 'Function' },
schemaFunctionPreprocessor: { instanceof: 'Function' },
componentDidMount: { instanceof: 'Function' },
componentDidUpdate: { instanceof: 'Function' },
componentWillUnmount: { instanceof: 'Function' },
Expand Down
2 changes: 1 addition & 1 deletion packages/drip-table/src/utils/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export type SandboxSafeExecute =
*/
<T = unknown>(script: string, context: Record<string, unknown>, defaultValue?: T) => T | undefined;

export type SandboxEventPreprocess =
export type SandboxFunctionPreprocess =
/**
* Schema 中函数通用预处理
*/
Expand Down

0 comments on commit 720cc53

Please sign in to comment.