@yorha2b-lab/autodev 7.7.2 → 7.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yorha2b-lab/autodev",
3
- "version": "7.7.2",
3
+ "version": "7.7.3",
4
4
  "description": "基于 AI 视觉与语义协议的前端 (React+Antd) 代码构筑与旧系统重构引擎",
5
5
  "bin": {
6
6
  "bunker": "bin/bunker.js"
@@ -0,0 +1,21 @@
1
+ import { SortableContainer } from 'react-sortable-hoc'
2
+
3
+ const SortableBody = SortableContainer(props => <tbody {...props} />)
4
+
5
+ const arrayMoveImmutable = (array, oldIndex, newIndex) => {
6
+ const newArray = [...array]
7
+ const [item] = newArray.splice(oldIndex, 1)
8
+ newArray.splice(newIndex, 0, item)
9
+ return newArray
10
+ }
11
+
12
+ export const DraggableContainer = ({ props, setDataSource }) => {
13
+
14
+ const onSortEnd = ({ oldIndex, newIndex }) => {
15
+ if (oldIndex !== newIndex) {
16
+ setDataSource(prev => arrayMoveImmutable(prev.slice(), oldIndex, newIndex))
17
+ }
18
+ }
19
+
20
+ return <SortableBody useDragHandle disableAutoscroll helperClass='row-dragging' onSortEnd={onSortEnd} {...props} />
21
+ }
@@ -1,3 +1,4 @@
1
+ import { SortableElement } from 'react-sortable-hoc'
1
2
  import { Form, Input, InputNumber, Select, Checkbox } from 'antd'
2
3
  import React, { useRef, useState, useEffect, useContext } from 'react'
3
4
 
@@ -7,6 +8,8 @@ import React, { useRef, useState, useEffect, useContext } from 'react'
7
8
  */
8
9
  const EditableContext = React.createContext(null)
9
10
 
11
+ const SortableItem = SortableElement((props) => <tr {...props} />)
12
+
10
13
  /**
11
14
  * @component EditableRow
12
15
  * @description [地堡战术行容器] 每一行都是一个独立的逻辑闭环。
@@ -33,7 +36,7 @@ export const EditableRow = ({ index, record, ...props }) => {
33
36
  return (
34
37
  <Form form={form} component={false} onValuesChange={(changedValue, allValue) => props?.onValuesChange?.({ changedValue, allValue, form })}>
35
38
  <EditableContext.Provider value={form}>
36
- <tr {...props} />
39
+ <SortableItem index={index} {...props} />
37
40
  </EditableContext.Provider>
38
41
  </Form>
39
42
  )
@@ -88,7 +88,7 @@ export const MyForm = ({ formItems, externalForm, labelCol, wrapperCol, tablePro
88
88
  const form = externalForm || internalForm
89
89
 
90
90
  return (
91
- <Form form={form} layout={layout} preserve={false} labelCol={labelCol} wrapperCol={wrapperCol} onValuesChange={onValuesChange}>
91
+ <Form form={form} layout={layout} preserve={false} labelCol={labelCol} wrapperCol={wrapperCol} onValuesChange={onValuesChange} scrollToFirstError={{ behavior: 'smooth', block: 'center' }}>
92
92
  <Row gutter={[24, 0]}>
93
93
  <FormRenderer form={form} formItems={formItems} tableProps={tableProps} />
94
94
  </Row>
@@ -1,4 +1,5 @@
1
- import { Space, Table } from 'antd'
1
+ import { Table } from 'antd'
2
+ import { DraggableContainer } from './DraggableContainer'
2
3
  import { EditableRow, EditableCell } from './EditableCell'
3
4
  import { useRef, useMemo, useEffect, useCallback } from 'react'
4
5
 
@@ -54,12 +55,10 @@ import { useRef, useMemo, useEffect, useCallback } from 'react'
54
55
  * }}
55
56
  * />
56
57
  */
57
- export const MyTable = ({ size, query, total, search, autoScroll, onChange, setSearch, pagination, renderAction, rowClassName, customSave, setDataSource, lineFormChange, columns = [], rowSelection, rowKey = 'id', loading = false, dataSource = [], scroll = { x: 'max-content' }, isLocalPaging = false, ...restProps }) => {
58
+ export const MyTable = ({ size, query, total, search, autoScroll, onChange, pagination, renderAction, rowClassName, customSave, setDataSource, lineFormChange, columns = [], rowSelection, rowKey = 'id', loading = false, dataSource = [], scroll = { x: 'max-content' }, isLocalPaging = false, ...restProps }) => {
58
59
 
59
60
  const tableRef = useRef(null)
60
61
  const hasScrolledRef = useRef(false)
61
- const dataSourceRef = useRef(dataSource)
62
- dataSourceRef.current = dataSource
63
62
 
64
63
  /**
65
64
  * @description [权限侦察] 自动扫描列配置。若存在 editType 型号,则激活“骇入模式(编辑模式)”。
@@ -69,18 +68,19 @@ export const MyTable = ({ size, query, total, search, autoScroll, onChange, setS
69
68
  /**
70
69
  * @function handleSave
71
70
  * @description [原子级物理封存] 执行数据更新协议。
71
+ * 采用函数式状态更新(prev => ...)以彻底消除闭航陷阱(Stale Closure),确保数据高频修改时的绝对准确。
72
+ *
72
73
  * @param {Object} row - 修改后的行片段
73
74
  */
74
75
  const handleSave = useCallback((row) => {
75
- const prev = dataSourceRef.current
76
- const index = prev.findIndex(item => row[rowKey] === item[rowKey])
77
- if (index === -1) return
78
- const item = prev[index]
79
- const updatedRow = { ...item, ...row }
80
- const newData = [...prev]
81
- newData.splice(index, 1, updatedRow)
82
- setDataSource(newData)
83
- customSave?.(updatedRow, newData)
76
+ setDataSource(prev => {
77
+ const newData = [...prev]
78
+ const index = newData.findIndex(item => row[rowKey] === item[rowKey])
79
+ const item = newData[index]
80
+ newData.splice(index, 1, { ...item, ...row })
81
+ customSave?.({ ...item, ...row }, newData)
82
+ return newData
83
+ })
84
84
  }, [rowKey, customSave, setDataSource])
85
85
 
86
86
  /**
@@ -91,8 +91,9 @@ export const MyTable = ({ size, query, total, search, autoScroll, onChange, setS
91
91
  body: {
92
92
  row: EditableRow,
93
93
  cell: EditableCell,
94
+ wrapper: props => <DraggableContainer props={props} setDataSource={setDataSource} />,
94
95
  }
95
- }), [])
96
+ }), [setDataSource])
96
97
 
97
98
  /**
98
99
  * @constant mergedColumns
@@ -102,37 +103,10 @@ export const MyTable = ({ size, query, total, search, autoScroll, onChange, setS
102
103
  const mergedColumns = useMemo(() => {
103
104
  return columns.map(col => {
104
105
  if (!col.editType) {
105
- let currentCol = { ...col }
106
106
  if (col.renderAction && renderAction?.[col.dataIndex]) {
107
- currentCol.render = renderAction[col.dataIndex]
108
- }
109
- if (col.search) {
110
- currentCol = {
111
- ...currentCol,
112
- filterSearch: true,
113
- onFilter: (value, record) => col.remote ? undefined : col.customFilter({ value, record, dataIndex: col.dataIndex }),
114
- filterDropdown: ({ close, confirm, selectedKeys, clearFilters, setSelectedKeys }) => (
115
- <Space direction='vertical' style={{ padding: 12 }}>
116
- {col.customFilterDropdown({ dataIndex: col.dataIndex, selectedKeys, setSelectedKeys })}
117
- <div style={{ display: 'flex' }}>
118
- <a style={{ marginLeft: 'auto', marginRight: 8 }} onClick={() => {
119
- if (col.remote) {
120
- setSearch(prev => ({ ...prev, pageNo: 1, [col.dataIndex]: col.formatFilter?.(selectedKeys) ?? selectedKeys?.toString() }))
121
- }
122
- confirm()
123
- }}>确定</a>
124
- <a onClick={() => {
125
- if (col.remote) {
126
- setSearch(prev => ({ ...prev, pageNo: 1, [col.dataIndex]: undefined }))
127
- }
128
- clearFilters()
129
- }}>重置</a>
130
- </div>
131
- </Space>
132
- ),
133
- }
107
+ return { ...col, render: renderAction[col.dataIndex] }
134
108
  }
135
- return currentCol
109
+ return col
136
110
  }
137
111
  return {
138
112
  ...col,
@@ -141,7 +115,6 @@ export const MyTable = ({ size, query, total, search, autoScroll, onChange, setS
141
115
  handleSave,
142
116
  title: col.title,
143
117
  rules: col.rules,
144
- extra: col.extra,
145
118
  options: col.options,
146
119
  editType: col.editType,
147
120
  dataIndex: col.dataIndex,
@@ -174,7 +147,7 @@ export const MyTable = ({ size, query, total, search, autoScroll, onChange, setS
174
147
  }),
175
148
  ...(typeof pagination === 'object' ? pagination : {})
176
149
  }
177
- }, [total, search, pagination])
150
+ }, [total, search, pagination, isLocalPaging])
178
151
 
179
152
  /**
180
153
  * @description [视觉追踪协议] 当检测到 query.rowIndex 信号时,执行“物理重定向”。