@trendr/core 0.4.8 → 0.4.10
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/README.md +4 -4
- package/package.json +1 -1
- package/src/ansi.js +2 -2
- package/src/input.js +2 -0
- package/src/text-area.js +15 -4
package/README.md
CHANGED
|
@@ -305,15 +305,15 @@ const { status, data } = useAsync(fetchUsers, { immediate: true })
|
|
|
305
305
|
|
|
306
306
|
```jsx
|
|
307
307
|
useMouse((event) => {
|
|
308
|
-
// event.action: 'press' | 'release' | 'drag' | 'scroll'
|
|
309
|
-
// event.button: 'left' | 'middle' | 'right' (press/release only)
|
|
310
|
-
// event.direction: 'up' | 'down' (scroll only)
|
|
308
|
+
// event.action: 'press' | 'release' | 'drag' | 'move' | 'scroll'
|
|
309
|
+
// event.button: 'left' | 'middle' | 'right' (press/release/drag only)
|
|
310
|
+
// event.direction: 'up' | 'down' | 'left' | 'right' (scroll only)
|
|
311
311
|
// event.x, event.y: 0-based terminal coordinates
|
|
312
312
|
// event.stopPropagation(): prevent other handlers from receiving this event
|
|
313
313
|
})
|
|
314
314
|
```
|
|
315
315
|
|
|
316
|
-
Mouse is enabled automatically. Built-in components support click, scroll wheel, and scrollbar dragging.
|
|
316
|
+
Mouse is enabled automatically. Passive pointer movement is reported as `move`, so it can be combined with `useLayout()` to derive hover state. Built-in components support click, scroll wheel, and scrollbar dragging.
|
|
317
317
|
|
|
318
318
|
### useStdout
|
|
319
319
|
|
package/package.json
CHANGED
package/src/ansi.js
CHANGED
|
@@ -19,8 +19,8 @@ export const sgrReset = `${ESC}0m`
|
|
|
19
19
|
export const setTitle = (title) => `\x1b]2;${title}\x07`
|
|
20
20
|
export const osc52Copy = (text) => `\x1b]52;c;${Buffer.from(text, 'utf8').toString('base64')}\x07`
|
|
21
21
|
|
|
22
|
-
export const enableMouse = `${ESC}?
|
|
23
|
-
export const disableMouse = `${ESC}?
|
|
22
|
+
export const enableMouse = `${ESC}?1003h${ESC}?1006h`
|
|
23
|
+
export const disableMouse = `${ESC}?1003l${ESC}?1006l`
|
|
24
24
|
|
|
25
25
|
export const BOLD = 1
|
|
26
26
|
export const DIM = 2
|
package/src/input.js
CHANGED
|
@@ -53,6 +53,8 @@ export function parseMouse(raw) {
|
|
|
53
53
|
return { type: 'mouse', action: 'scroll', direction, x, y }
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
if (motion && button === 3) return { type: 'mouse', action: 'move', x, y }
|
|
57
|
+
|
|
56
58
|
const buttonName = extended
|
|
57
59
|
? (button === 0 ? 'back' : button === 1 ? 'forward' : button === 2 ? 'button10' : 'button11')
|
|
58
60
|
: (button === 0 ? 'left' : button === 1 ? 'middle' : 'right')
|
package/src/text-area.js
CHANGED
|
@@ -124,7 +124,7 @@ function ensureVisible(cursorRow, scroll, height, totalLines) {
|
|
|
124
124
|
return scroll
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
export function TextArea({ onSubmit, onCancel, onChange, onKeyDown, placeholder, focused = true, maxHeight = 10, clearOnSubmit = true, cursor: cursorProp, value: valueProp, submitOnEnter = false, color }) {
|
|
127
|
+
export function TextArea({ onSubmit, onCancel, onChange, onKeyDown, placeholder, focused = true, maxHeight = 10, clearOnSubmit = true, cursor: cursorProp, value: valueProp, submitOnEnter = false, color, lineCounter = false }) {
|
|
128
128
|
const [value, setValue] = createSignal('')
|
|
129
129
|
const [cursor, setCursor] = createSignal(0)
|
|
130
130
|
if (valueProp !== undefined && valueProp !== value()) {
|
|
@@ -319,7 +319,11 @@ export function TextArea({ onSubmit, onCancel, onChange, onKeyDown, placeholder,
|
|
|
319
319
|
const lineMap = wrapForEditor(v, effectiveWidth)
|
|
320
320
|
const displayPos = cursorToDisplay(c, lineMap, v)
|
|
321
321
|
|
|
322
|
-
|
|
322
|
+
// an active counter reserves the bottom row for itself so it can never
|
|
323
|
+
// overlap text or the cursor; overflow state costs one visible text row
|
|
324
|
+
const counterActive = lineCounter && lineMap.length > maxHeight
|
|
325
|
+
const boxMax = counterActive ? Math.max(1, maxHeight - 1) : maxHeight
|
|
326
|
+
const displayHeight = Math.max(1, Math.min(lineMap.length, boxMax))
|
|
323
327
|
ref.scroll = ensureVisible(displayPos.row, ref.scroll, displayHeight, lineMap.length)
|
|
324
328
|
const scroll = ref.scroll
|
|
325
329
|
|
|
@@ -365,8 +369,15 @@ export function TextArea({ onSubmit, onCancel, onChange, onKeyDown, placeholder,
|
|
|
365
369
|
})
|
|
366
370
|
})
|
|
367
371
|
|
|
372
|
+
const counter = counterActive
|
|
373
|
+
? jsx('box', {
|
|
374
|
+
style: { flexDirection: 'row', height: 1 },
|
|
375
|
+
children: jsx('text', { style: { color: muted, dim: true }, children: `${displayPos.row + 1}/${lineMap.length}` }),
|
|
376
|
+
})
|
|
377
|
+
: null
|
|
378
|
+
|
|
368
379
|
return jsx('box', {
|
|
369
|
-
style: { flexDirection: 'column', height: displayHeight, minHeight: 1, flexGrow: 1 },
|
|
370
|
-
children: rows,
|
|
380
|
+
style: { flexDirection: 'column', height: displayHeight + (counterActive ? 1 : 0), minHeight: 1, flexGrow: 1 },
|
|
381
|
+
children: counter ? [...rows, counter] : rows,
|
|
371
382
|
})
|
|
372
383
|
}
|