Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion packages/renderless/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentiny/vue-renderless",
"version": "3.19.4",
"version": "3.19.5",
"private": true,
"description": "An enterprise-class UI component library, support both Vue.js 2 and Vue.js 3, as well as PC and mobile.",
"author": "OpenTiny Team",
Expand Down
9 changes: 6 additions & 3 deletions packages/renderless/src/transfer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,20 @@ export const clearQuery = (refs: ITransferRenderlessParams['refs']) => (which: '

/** SortableJs 插件的回调逻辑, 添加,删除,更新事件后,触发本函数 */
export const logicFun =
({ props, emit, state }: Pick<ITransferRenderlessParams, 'emit' | 'props' | 'state'>) =>
({ props, emit, state, vm }: Pick<ITransferRenderlessParams, 'emit' | 'props' | 'state'>) =>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Update type annotation to include vm parameter

The type annotation is missing the vm parameter in the Pick type utility.

Apply this fix:

-({ props, emit, state, vm }: Pick<ITransferRenderlessParams, 'emit' | 'props' | 'state'>) =>
+({ props, emit, state, vm }: Pick<ITransferRenderlessParams, 'emit' | 'props' | 'state' | 'vm'>) =>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
({ props, emit, state, vm }: Pick<ITransferRenderlessParams, 'emit' | 'props' | 'state'>) =>
({ props, emit, state, vm }: Pick<ITransferRenderlessParams, 'emit' | 'props' | 'state' | 'vm'>) =>

({ event, isAdd, pullMode }: { event: any; isAdd?: boolean; pullMode?: 'sort' }) => {
let currentValue = props.modelValue.slice()
let movedKeys = []

if (pullMode) {
currentValue.splice(event.newIndex, 0, currentValue.splice(event.oldIndex, 1)[0])
} else {
const rightPanel = vm.$refs.rightPanel
const leftPanel = vm.$refs.leftPanel

Comment on lines +228 to +230
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add null checks for panel refs

The panel refs should be checked for null to prevent runtime errors.

Apply this fix:

-      const rightPanel = vm.$refs.rightPanel
-      const leftPanel = vm.$refs.leftPanel
+      const rightPanel = vm.$refs.rightPanel
+      const leftPanel = vm.$refs.leftPanel
+      
+      if (!rightPanel?.state?.filteredData || !leftPanel?.state?.filteredData) {
+        return
+      }

Committable suggestion skipped: line range outside the PR's diff.

const key = isAdd
? state.targetData[event.oldIndex][props.props.key]
: state.sourceData[event.oldIndex][props.props.key]
? rightPanel.state.filteredData[event.oldIndex][props.props.key]
: leftPanel.state.filteredData[event.oldIndex][props.props.key]
Comment on lines +232 to +233
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add bounds check for array access

The array access using oldIndex should be bounds-checked to prevent undefined access.

Apply this fix:

-        ? rightPanel.state.filteredData[event.oldIndex][props.props.key]
-        : leftPanel.state.filteredData[event.oldIndex][props.props.key]
+        ? (rightPanel.state.filteredData[event.oldIndex] || {})[props.props.key]
+        : (leftPanel.state.filteredData[event.oldIndex] || {})[props.props.key]

Additionally, consider adding validation:

+      if (event.oldIndex < 0 || 
+          (isAdd && event.oldIndex >= rightPanel.state.filteredData.length) ||
+          (!isAdd && event.oldIndex >= leftPanel.state.filteredData.length)) {
+        return
+      }

Committable suggestion skipped: line range outside the PR's diff.

const index = isAdd ? state.rightChecked.indexOf(key) : state.leftChecked.indexOf(key)
const valueIndex = currentValue.indexOf(key)

Expand Down
4 changes: 2 additions & 2 deletions packages/renderless/src/transfer/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const initState = ({ reactive, computed, api, props, h, slots }): ITransferState
export const renderless = (
props: ITransferProps,
{ computed, onMounted, reactive, h }: ISharedRenderlessParamHooks,
{ $prefix, emit, refs, parent, slots }: ITransferRenderlessParamUtils
{ $prefix, emit, refs, parent, slots, vm }: ITransferRenderlessParamUtils
) => {
const api = {} as ITransferApi
const Tree = $prefix + 'Tree'
Expand All @@ -80,7 +80,7 @@ export const renderless = (
addToRight: addToRight({ emit, refs, props, state, Tree }),
onTargetCheckedChange: onTargetCheckedChange({ emit, state }),
onSourceCheckedChange: onSourceCheckedChange({ emit, state }),
logicFun: logicFun({ props, emit, state }),
logicFun: logicFun({ props, emit, state, vm }),
getTargetData: getTargetData({ props, state, Tree, Table }),
sortableEvent: sortableEvent({ api, droppanel: DROPPANEL, props, queryDom: TRANSFERPANEL, refs })
})
Expand Down
Loading