MCPcopy Create free account
hub / github.com/SplootCode/splootcode / EditBox

Class EditBox

packages/editor/src/components/edit_box.tsx:23–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21
22@observer
23export class EditBox extends React.Component<EditBoxProps, EditBoxState> {
24 editTextArea: React.RefObject<HTMLTextAreaElement>
25 inputBox: React.RefObject<HTMLInputElement>
26
27 constructor(props: EditBoxProps) {
28 super(props)
29 const editBoxData = this.props.editBoxData
30 this.editTextArea = React.createRef()
31 this.inputBox = React.createRef()
32
33 this.state = {
34 userInput: editBoxData.contents, // Get current edit value
35 }
36 }
37
38 render() {
39 const { userInput } = this.state
40 const { editorX, editorY, editBoxData, selection } = this.props
41 const { x, y } = editBoxData
42
43 const hidden = selection.isHidden
44 const positionStyles: React.CSSProperties = {
45 position: 'absolute',
46 left: x + editorX - 1 + 'px',
47 top: y + editorY + 'px',
48 opacity: hidden ? 0 : 1,
49 }
50
51 if (editBoxData.node.layout.boxType === NodeBoxType.STRING) {
52 return (
53 <div style={positionStyles}>
54 <div className="edit-box edit-box-string">
55 <textarea
56 ref={this.editTextArea}
57 autoFocus
58 defaultValue={userInput}
59 onChange={this.onChange}
60 onKeyDown={this.onKeyDown}
61 />
62 </div>
63 </div>
64 )
65 }
66
67 return (
68 <div style={positionStyles}>
69 <div className="edit-box">
70 <input
71 ref={this.inputBox}
72 autoFocus
73 type="text"
74 value={userInput}
75 onChange={this.onChange}
76 onKeyDown={this.onKeyDown}
77 />
78 </div>
79 </div>
80 )

Callers

nothing calls this directly

Calls 5

stringLiteralDimensionsFunction · 0.90
stringWidthFunction · 0.90
exitEditMethod · 0.80
deleteSelectedNodeMethod · 0.80
updatePropertyEditMethod · 0.80

Tested by

no test coverage detected