Add UnixTimestamp component#371
Merged
Merged
Conversation
Epoch numbers (seconds or milliseconds) rendered as a readable date, reusing the swappable DatePicker widget for editing. - epoch.ts: plausible-epoch band (1990-2100). isPlausibleEpoch doubles as the guard and the seconds-vs-ms detector (non-overlapping bands); epochToDate/dateToEpoch round-trip preserving the unit. - component.tsx: edits via the injected DatePicker widget; view is displayAs:'number' (default — originalNode + a UNIX badge, the ErrorIndicator pattern) or 'date' (formatted). unit defaults to 'auto'. - definition.ts: guard = epoch band; the factory wrapper flips showOnEdit:true only when a DatePicker widget is supplied (else core's number editor edits), and drops passOriginalNode in 'date' mode. Value stays a plain JSON number, so no serialization plumbing. README documents the condition-vs-guard split — the first component whose guard is a pure heuristic (safe to replace) rather than a safety contract. Demo wires two fields (seconds + ms) under "Date & Time" plus a "Show Unix as raw number?" toggle, with calendar editing. Also includes a small z-index fix on the ReactDatePicker popup. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Double-clicking the UNIX badge enters edit mode (parity with the number node beside it). - Badge background tweak. - List "UNIX Timestamp" in the demo Custom Component Library intro. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Bundle size impact
|
| Format | Base raw | PR raw | Δ raw | Base gzip | PR gzip | Δ gzip |
|---|---|---|---|---|---|---|
| esm | 11.91 KB | 13.70 KB | 🔺 +1.78 KB (+14.97%) | 4.02 KB | 4.56 KB | 🔺 +552 B (+13.40%) |
| cjs | 12.54 KB | 14.33 KB | 🔺 +1.79 KB (+14.26%) | 3.87 KB | 4.39 KB | 🔺 +531 B (+13.40%) |
Measured from build/index.{cjs,esm}.js. Gzip at level 9.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
UnixTimestamppre-built component to@json-edit-react/components— epoch numbers (seconds or milliseconds) rendered as a readable date — implementing candidate #3 from #355. It builds directly on the swappable date-picker widget landed forDatePicker.What it does
'auto'seconds-vs-ms detector. The detected/forced unit is preserved on commit; force it viacomponentProps.unit.DatePickerWidgetPropspicker asDatePicker. The definition's factory enables edit-mode rendering only when aDatePickerwidget is passed viacomponentProps; with none, core's standard number editor handles edits (showOnEditstaysfalse).displayAs: 'number'(default) renders the ordinary number node plus a small badge (defaultUNIX, viabadgeLabel) using theErrorIndicatorpassOriginalNodepattern;displayAs: 'date'shows a formatted date (optionalformatter). The factory dropspassOriginalNodein'date'mode.numberend-to-end — nostringifyReplacer/parseReviverplumbing.conditionvsguardThis is the first component whose guard is a pure heuristic rather than a safety contract (any number renders fine as a date), so the README documents replacing the
guardas the encouraged move when you want to target timestamps exclusively by key — including real timestamps that fall outside the default 1990–2100 band (microsecond/nanosecond epochs, historical/far-future dates), which an ANDedconditionwould silently reject.Demo
Adds
Unix Timestamp (seconds)andUnix Timestamp (ms)under the Custom Component Library'sDate & Timesection (showing auto-detection), wired withReactDatePickerfor calendar editing, plus aShow Unix as raw number?toggle drivingdisplayAs.Notes
minorchangeset for@json-edit-react/components.tsc --noEmit, and the demo'stsc -b --noEmitall pass.z-indexfix on theReactDatePickerpopup.🤖 Generated with Claude Code