@trendr/core 0.2.4 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trendr/core",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "direct-mode TUI renderer with JSX, signals, and per-cell diffing",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/input.js CHANGED
@@ -153,7 +153,23 @@ export function createInputHandler(stream) {
153
153
  }
154
154
  }
155
155
 
156
+ function isPaste(data) {
157
+ const s = typeof data === 'string' ? data : data.toString()
158
+ return s.length > 1 && !s.startsWith('\x1b') && (s.includes('\n') || s.includes('\r'))
159
+ }
160
+
156
161
  function onData(data) {
162
+ if (isPaste(data)) {
163
+ const text = (typeof data === 'string' ? data : data.toString()).replace(/\r\n?/g, '\n')
164
+ const event = { key: 'paste', text, ctrl: false, meta: false, shift: false, raw: text }
165
+ event.stopPropagation = () => { event._stopped = true }
166
+ const snapshot = [...keyListeners].reverse()
167
+ for (const fn of snapshot) {
168
+ fn(event)
169
+ if (event._stopped) break
170
+ }
171
+ return
172
+ }
157
173
  for (const key of splitKeys(data)) {
158
174
  dispatch(key)
159
175
  }
package/src/text-area.js CHANGED
@@ -87,7 +87,7 @@ function ensureVisible(cursorRow, scroll, height, totalLines) {
87
87
  return scroll
88
88
  }
89
89
 
90
- export function TextArea({ onSubmit, onCancel, onChange, placeholder, focused = true, maxHeight = 10, clearOnSubmit = true, cursor: cursorProp, value: valueProp }) {
90
+ export function TextArea({ onSubmit, onCancel, onChange, placeholder, focused = true, maxHeight = 10, clearOnSubmit = true, cursor: cursorProp, value: valueProp, submitOnEnter = false }) {
91
91
  const [value, setValue] = createSignal('')
92
92
  const [cursor, setCursor] = createSignal(0)
93
93
  const _prev = registerHook(() => ({ value: undefined }))
@@ -115,7 +115,21 @@ export function TextArea({ onSubmit, onCancel, onChange, placeholder, focused =
115
115
  const v = value()
116
116
  const c = cursor()
117
117
 
118
- if (meta && key === '\r') {
118
+ if (key === 'paste') {
119
+ const pasted = event.text || ''
120
+ update(v.slice(0, c) + pasted + v.slice(c), c + pasted.length)
121
+ event.stopPropagation()
122
+ return
123
+ }
124
+
125
+ const isSubmitKey = submitOnEnter
126
+ ? (key === 'return' && !meta)
127
+ : (meta && key === '\r')
128
+ const isNewlineKey = submitOnEnter
129
+ ? (meta && key === '\r')
130
+ : (key === 'return')
131
+
132
+ if (isSubmitKey) {
119
133
  if (onSubmit) onSubmit(v)
120
134
  if (clearOnSubmit) update('', 0)
121
135
  ref.scroll = 0
@@ -123,7 +137,7 @@ export function TextArea({ onSubmit, onCancel, onChange, placeholder, focused =
123
137
  return
124
138
  }
125
139
 
126
- if (key === 'return') {
140
+ if (isNewlineKey) {
127
141
  update(v.slice(0, c) + '\n' + v.slice(c), c + 1)
128
142
  event.stopPropagation()
129
143
  return