UNPKG

@visactor/vue-vtable

Version:

The vue version of VTable

32 lines (29 loc) 1.17 kB
import { register } from '@visactor/vtable'; import { DynamicRenderEditor } from './editor.js'; import { isValid } from '@visactor/vutils'; const DYNAMIC_RENDER_EDITOR = 'dynamic-render-editor'; function checkRenderEditor(column, getEditCustomNode) { const { editor } = column || {}; const key = getRenderEditorColumnKeyField(column); if (!isValid(key) || editor !== DYNAMIC_RENDER_EDITOR) { return false; } if (typeof getEditCustomNode === 'function') { column.getEditCustomNode = getEditCustomNode; return true; } return typeof column.getEditCustomNode === 'function'; } function getRenderEditorColumnKeyField(column) { const { field, key } = column || {}; return isValid(key) ? key : field; } function getRenderEditor(create, currentContext) { let renderEditor = register.editor(DYNAMIC_RENDER_EDITOR); if (!renderEditor && !!create) { renderEditor = new DynamicRenderEditor(currentContext); register.editor(DYNAMIC_RENDER_EDITOR, renderEditor); } return renderEditor; } export { checkRenderEditor, getRenderEditor, getRenderEditorColumnKeyField };