-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1850 from VisActor/feat/inputEditorConfig
Feat/input editor config
- Loading branch information
Showing
9 changed files
with
157 additions
and
15 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
common/changes/@visactor/vtable/feat-inputEditorConfig_2024-06-05-03-03.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"comment": "feat: add textArea editor\n\n", | ||
"type": "none", | ||
"packageName": "@visactor/vtable" | ||
} | ||
], | ||
"packageName": "@visactor/vtable", | ||
"email": "892739385@qq.com" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { InputEditor } from './input-editor'; | ||
import { DateInputEditor } from './date-input-editor'; | ||
import { ListEditor } from './list-editor'; | ||
export { InputEditor, DateInputEditor, ListEditor }; | ||
import { TextAreaEditor } from './textArea-editor'; | ||
export { InputEditor, DateInputEditor, ListEditor, TextAreaEditor }; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import type { EditContext, IEditor, RectProps } from './types'; | ||
|
||
export interface TextAreaEditorConfig { | ||
readonly?: boolean; | ||
} | ||
|
||
export class TextAreaEditor implements IEditor { | ||
editorType: string = 'TextArea'; | ||
editorConfig: TextAreaEditorConfig; | ||
container: HTMLElement; | ||
successCallback?: () => void; | ||
element?: HTMLTextAreaElement; | ||
|
||
constructor(editorConfig?: TextAreaEditorConfig) { | ||
this.editorConfig = editorConfig || {}; | ||
} | ||
|
||
createElement() { | ||
const input = document.createElement('textArea') as HTMLTextAreaElement; | ||
if (this.editorConfig?.readonly) { | ||
input.setAttribute('readonly', `${this.editorConfig.readonly}`); | ||
} | ||
input.style.resize = 'none'; | ||
input.style.position = 'absolute'; | ||
input.style.padding = '4px'; | ||
input.style.width = '100%'; | ||
input.style.height = '100%'; | ||
input.style.boxSizing = 'border-box'; | ||
this.element = input; | ||
|
||
this.container.appendChild(input); | ||
|
||
// 监听键盘事件 | ||
input.addEventListener('keydown', (e: KeyboardEvent) => { | ||
const _isSelectAll = e.key === 'a' && (e.ctrlKey || e.metaKey); | ||
const _isTextAreaNewLine = e.key === 'Enter' && e.shiftKey; | ||
if (_isSelectAll || _isTextAreaNewLine) { | ||
// 阻止冒泡 防止处理成表格全选事件 | ||
e.stopPropagation(); | ||
} | ||
}); | ||
} | ||
|
||
setValue(value: string) { | ||
this.element.value = typeof value !== 'undefined' ? value : ''; | ||
} | ||
|
||
getValue() { | ||
return this.element.value; | ||
} | ||
|
||
onStart({ value, referencePosition, container, endEdit }: EditContext<string>) { | ||
this.container = container; | ||
this.successCallback = endEdit; | ||
if (!this.element) { | ||
this.createElement(); | ||
|
||
if (value !== undefined && value !== null) { | ||
this.setValue(value); | ||
} | ||
if (referencePosition?.rect) { | ||
this.adjustPosition(referencePosition.rect); | ||
} | ||
} | ||
this.element.focus(); | ||
// do nothing | ||
} | ||
|
||
adjustPosition(rect: RectProps) { | ||
this.element.style.top = rect.top + 'px'; | ||
this.element.style.left = rect.left + 'px'; | ||
this.element.style.width = rect.width + 'px'; | ||
this.element.style.height = rect.height + 'px'; | ||
} | ||
|
||
endEditing() { | ||
// do nothing | ||
} | ||
|
||
onEnd() { | ||
// do nothing | ||
this.container.removeChild(this.element); | ||
this.element = undefined; | ||
} | ||
|
||
isEditorElement(target: HTMLElement) { | ||
return target === this.element; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters