cron-human 1.1.5 → 1.1.7

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/dist/ui/app.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useState, useEffect } from 'react';
2
+ import React, { useState, useEffect } from 'react';
3
3
  import { Box, Text, useInput, useApp } from 'ink';
4
4
  import { InputSection } from './components/InputSection.js';
5
5
  import { PreviewSection } from './components/PreviewSection.js';
@@ -19,6 +19,8 @@ export const App = () => {
19
19
  const [timezone, setTimezone] = useState(undefined);
20
20
  const [timezoneInput, setTimezoneInput] = useState('');
21
21
  const [inputMode, setInputMode] = useState('cron');
22
+ const inputModeRef = React.useRef(inputMode);
23
+ inputModeRef.current = inputMode;
22
24
  const [showPresets, setShowPresets] = useState(false);
23
25
  const [allowSeconds, setAllowSeconds] = useState(false);
24
26
  const [focus, setFocus] = useState(FocusArea.Input);
@@ -36,12 +38,11 @@ export const App = () => {
36
38
  exit();
37
39
  return;
38
40
  }
39
- // Global Shortcuts (Paste, Reset, Toggles)
40
41
  if (key.ctrl && input === 'v') {
41
42
  if (focus === FocusArea.Input && !showPresets) {
42
43
  clipboardy.read().then(text => {
43
44
  if (text) {
44
- if (inputMode === 'timezone') {
45
+ if (inputModeRef.current === 'timezone') {
45
46
  setTimezoneInput(text.trim());
46
47
  }
47
48
  else {
@@ -56,7 +57,7 @@ export const App = () => {
56
57
  }
57
58
  }
58
59
  if (key.ctrl && input === 'r') {
59
- if (inputMode === 'timezone') {
60
+ if (inputModeRef.current === 'timezone') {
60
61
  setTimezoneInput('');
61
62
  }
62
63
  else {
@@ -66,25 +67,27 @@ export const App = () => {
66
67
  return;
67
68
  }
68
69
  if (key.ctrl && input === 't') {
70
+ if (showPresets)
71
+ return;
69
72
  setInputMode('timezone');
70
73
  setTimezoneInput(timezone || '');
71
74
  setFocus(FocusArea.Input);
72
75
  return;
73
76
  }
74
77
  if (key.ctrl && input === 'p') {
78
+ if (inputModeRef.current === 'timezone')
79
+ return;
75
80
  setShowPresets(prev => !prev);
76
81
  return;
77
82
  }
78
- // Mode Specific Handling
79
83
  if (inputMode === 'timezone') {
80
84
  if (key.escape) {
81
85
  setInputMode('cron');
82
86
  setFocus(FocusArea.Input);
83
87
  return;
84
88
  }
85
- return; // Let TextInput handle typing
89
+ return;
86
90
  }
87
- // Cron Mode Handling
88
91
  if (input === 'q' && !key.ctrl && focus !== FocusArea.Input) {
89
92
  exit();
90
93
  return;
@@ -99,10 +102,6 @@ export const App = () => {
99
102
  });
100
103
  return;
101
104
  }
102
- if (key.ctrl && input === 's') { // Save? Or just implicit.
103
- // Placeholder if needed
104
- }
105
- // Navigation etc handled by components or below
106
105
  if (focus === FocusArea.Options) {
107
106
  if (input === ' ') {
108
107
  setAllowSeconds(prev => !prev);
@@ -3,13 +3,10 @@ import { useRef } from 'react';
3
3
  import { Box, Text, useInput } from 'ink';
4
4
  import TextInput from 'ink-text-input';
5
5
  export const InputSection = ({ value, onChange, onSubmit, isFocused, label = "Cron Expression:" }) => {
6
- // FIX: ink-text-input adds characters even if Ctrl is held (except Ctrl+C).
7
- // We safeguard against this by tracking the Ctrl key state.
8
6
  const ctrlHeld = useRef(false);
9
7
  useInput((_input, key) => {
10
8
  ctrlHeld.current = key.ctrl;
11
- }, { isActive: true }); // Always track, or at least when focused
12
- // To attempt "Context" feature simply:
9
+ }, { isActive: true });
13
10
  const parts = value.trim().split(/\s+/);
14
11
  let helpText = "";
15
12
  if (parts.length > 5)
@@ -17,10 +14,6 @@ export const InputSection = ({ value, onChange, onSubmit, isFocused, label = "Cr
17
14
  else
18
15
  helpText = "Fields: Min Hour Day Month Weekday";
19
16
  return (_jsxs(Box, { borderStyle: "round", borderColor: isFocused ? "green" : "gray", paddingX: 1, flexDirection: "column", children: [_jsx(Text, { bold: true, color: isFocused ? "green" : "white", children: label }), _jsx(Box, { children: _jsx(TextInput, { value: value, onChange: (val) => {
20
- // FIX: Defer the update to allow useInput (below/parent) to update ctrlHeld state.
21
- // ink events bubble child->parent. TextInput (child) fires onChange.
22
- // Then InputSection (parent) useInput fires.
23
- // By deferring, we check ctrlHeld *after* useInput has run for this event.
24
17
  setTimeout(() => {
25
18
  if (!ctrlHeld.current) {
26
19
  onChange(val);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cron-human",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "description": "A CLI that converts cron expressions to human-readable English and prints next run times",
5
5
  "main": "dist/lib.js",
6
6
  "types": "dist/lib.d.ts",