|
| 1 | + |
| 2 | +import { registerComponent } from "../config"; |
| 3 | +import { QPlainTextEdit, QPlainTextEditEvents } from "@nodegui/nodegui"; |
| 4 | +import { ViewProps, setProps as setViewProps } from "../View"; |
| 5 | + |
| 6 | +interface PlainTextEditProps extends ViewProps { |
| 7 | + children?: string; |
| 8 | + text?: string; |
| 9 | +} |
| 10 | + |
| 11 | +const setProps = ( |
| 12 | + widget: QPlainTextEdit, |
| 13 | + newProps: PlainTextEditProps, |
| 14 | + oldProps: PlainTextEditProps |
| 15 | +) => { |
| 16 | + const setter: PlainTextEditProps = { |
| 17 | + set text(text: string) { |
| 18 | + text ? widget.setPlainText(text) : widget.clear(); |
| 19 | + }, |
| 20 | + }; |
| 21 | + Object.assign(setter, newProps); |
| 22 | + setViewProps(widget, newProps, oldProps); |
| 23 | +}; |
| 24 | + |
| 25 | +export const PlainTextEdit = registerComponent<PlainTextEditProps>({ |
| 26 | + id: "plaintextedit", |
| 27 | + getContext() { |
| 28 | + return {}; |
| 29 | + }, |
| 30 | + shouldSetTextContent: () => { |
| 31 | + return true; |
| 32 | + }, |
| 33 | + createInstance: newProps => { |
| 34 | + const widget = new QPlainTextEdit(); |
| 35 | + setProps(widget, newProps, {}); |
| 36 | + return widget; |
| 37 | + }, |
| 38 | + finalizeInitialChildren: () => { |
| 39 | + return false; |
| 40 | + }, |
| 41 | + commitMount: (instance, newProps, internalInstanceHandle) => { |
| 42 | + return; |
| 43 | + }, |
| 44 | + prepareUpdate: ( |
| 45 | + instance, |
| 46 | + oldProps, |
| 47 | + newProps, |
| 48 | + rootContainerInstance, |
| 49 | + hostContext |
| 50 | + ) => { |
| 51 | + return true; |
| 52 | + }, |
| 53 | + commitUpdate: (instance, updatePayload, oldProps, newProps, finishedWork) => { |
| 54 | + setProps(instance as QPlainTextEdit, newProps, oldProps); |
| 55 | + } |
| 56 | +}); |
0 commit comments