Add ErrorIndicator glyph component (#358)#360
Merged
Conversation
Bundle size impact
|
| Format | Base raw | PR raw | Δ raw | Base gzip | PR gzip | Δ gzip |
|---|---|---|---|---|---|---|
| esm | 13.22 KB | 13.75 KB | 🔺 +539 B (+3.98%) | 4.49 KB | 4.67 KB | 🔺 +178 B (+3.87%) |
| cjs | 13.91 KB | 14.45 KB | 🔺 +553 B (+3.88%) | 4.36 KB | 4.54 KB | 🔺 +183 B (+4.10%) |
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.
Summary
Adds⚠️ ) beside it, to flag the nodes you target. Rewires the "Validation flagging" demo example to use it instead of the red-background theme, making it the first example combining
ErrorIndicatorto@json-edit-react/components— a custom-node component that wraps the built-in node (originalNode) and adds a glyph (default@json-edit-react/utilsand@json-edit-react/components. Implements #358.How the validation state reaches the component
It doesn't — the component is a pure presentational wrapper that only knows
errorGlyph/position. Which nodes it decorates is the definition'scondition, which the factory (createDefinitionFactory) ANDs with the component's guard. The consumer wires validity there and memoizes on[validation]:So
@json-edit-react/componentstakes no dependency on@json-edit-react/utils(it accepts aFilterFunction, not aValidationState). ThecustomNodeDefinitionsarray —Object.is-compared as a node prop, memoized on[validation]— pierces the node memo when validity flips, so the marker appears/clears correctly even cross-branch. Withcondition = validity, only invalid nodes pay thepassOriginalNodecost.Guarded to value nodes
The definition's guard is
({ value }) => value === null || typeof value !== 'object'. ANDed with any consumercondition, it ensures the glyph never lands on a collection — important because AJV'sif/thenreports an error at the parent object's path as well as the leaf, which would otherwise wrap (and visually break) the whole collection. Overrideguardto opt collections back in; for collection-level marking usevalidationStyles({ within })from@json-edit-react/utils.Details
componentProps:errorGlyph(anyReactNode, default⚠️),position('before' | 'after', default'after'). Nocondition→ flags nothing (the default targeting is a deliberate no-op).ErrorIndicator/style.css(inline-flex+align-items: center+gap), injected viarollup-plugin-stylesand imported in bothcomponent.tsxanddefinition.ts(as DatePicker does) sosideEffects: falsecan't tree-shake it. A class, not inline styles, so consumers can override it.Testing
test/error-indicator.test.tsx(imported from the component's subtree, not the barrel, to avoid the barrel's ESM-only deps in Jest):conditionnever decorates a collection);errorGlyph/positionprops (glyph content + DOM order).JsonEditorwithuseValidationState): editing one node flips a different-branch node's validity and the glyph appears/clears there. Verified sharp — freezing the memo dep makes both cases fail with stale glyphs.Full suite green (487 passed / 2 todo, +7); components
tsc+ build clean; demo typecheck 0 errors; core lint + compile unaffected. Changeset:@json-edit-react/componentsminor.🤖 Generated with Claude Code