All files / src/symbol index.tsx

100% Statements 91/91
65.97% Branches 64/97
100% Functions 6/6
100% Lines 81/81

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126        22x     2316x 2316x 2316x 266x 266x 266x       266x 266x 266x   266x 266x 266x 264x     22x   22x 134x 134x 134x 134x 134x 134x 134x 132x     22x   22x 1158x 1158x 1158x 1158x   1158x               1158x 1157x     22x   22x     121x 121x 121x 121x 121x 121x 121x 121x 121x 121x 121x 120x     22x   22x 121x 121x 121x 121x 15x 15x 15x 15x 14x   106x 106x 106x 106x 105x     22x             22x 240x 240x 240x 121x 121x 15x 15x 15x 15x 14x   106x 106x 106x 106x 105x     22x  
import { useSymbolsStore, type SymbolsElement, type SymbolsElementResult } from '../store/Symbols';
import { type TagType } from '../store/Types';
import { useExpandsStore } from '../store/Expands';
 
export const Quote = <T extends object>(
  props: { isNumber?: boolean } & React.HTMLAttributes<HTMLElement> & SymbolsElementResult<T>,
) => {
  const { Quote: Comp = {} } = useSymbolsStore();
  const { isNumber, value, parentValue, keyName, keys, ...other } = props;
  if (isNumber) return null;
  const { as, render, ...reset } = Comp;
  const Elm = as || 'span';
  const elmProps = { ...other, ...reset };
  // Trim the leading and trailing spaces in children,
  // and set it to undefined if it's an empty string or contains only spaces.
  // https://github.com/uiwjs/react-json-view/issues/86
  Eif (typeof elmProps.children === 'string') {
    const trimmed = elmProps.children.trim();
    elmProps.children = trimmed || undefined;
  }
  let result = { value, parentValue, keyName, keys: keys || (keyName ? [keyName] : []) };
  const child = render && typeof render === 'function' && render(elmProps, result);
  if (child) return child;
  return <Elm {...elmProps} />;
};
 
Quote.displayName = 'JVR.Quote';
 
export const ValueQuote = (props: React.HTMLAttributes<HTMLElement>) => {
  const { ValueQuote: Comp = {} } = useSymbolsStore();
  const { ...other } = props;
  const { as, render, ...reset } = Comp;
  const Elm = as || 'span';
  const elmProps = { ...other, ...reset };
  const child = render && typeof render === 'function' && render(elmProps, {});
  if (child) return child;
  return <Elm {...elmProps} />;
};
 
ValueQuote.displayName = 'JVR.ValueQuote';
 
export const Colon = <T extends object>(props: SymbolsElementResult<T>) => {
  const { value, parentValue, keyName, keys } = props;
  const { Colon: Comp = {} } = useSymbolsStore();
  const { as, render, ...reset } = Comp;
  const Elm = as || 'span';
  const child =
    render &&
    typeof render === 'function' &&
    render(reset, {
      value,
      parentValue,
      keyName,
      keys: keys || (keyName ? [keyName] : []),
    });
  if (child) return child;
  return <Elm {...reset} />;
};
 
Colon.displayName = 'JVR.Colon';
 
export const Arrow = <T extends TagType, K extends object>(
  props: SymbolsElement<T> & { expandKey: string } & SymbolsElementResult<K>,
) => {
  const { Arrow: Comp = {} } = useSymbolsStore();
  const expands = useExpandsStore();
  const { expandKey, style: resetStyle, value, parentValue, keyName, keys } = props;
  const isExpanded = !!expands[expandKey];
  const { as, style, render, ...reset } = Comp;
  const Elm = as || 'span';
  const isRender = render && typeof render === 'function';
  const elmProps = { ...reset, 'data-expanded': isExpanded, style: { ...style, ...resetStyle } };
  const result = { value, parentValue, keyName, keys: keys || (keyName ? [keyName] : []) };
  const child = isRender && render(elmProps, result);
  if (child) return child;
  return <Elm {...reset} style={{ ...style, ...resetStyle }} />;
};
 
Arrow.displayName = 'JVR.Arrow';
 
export const BracketsOpen = <K extends object>(props: { isBrackets?: boolean } & SymbolsElementResult<K>) => {
  const { isBrackets, value, parentValue, keyName, keys } = props;
  const { BracketsLeft = {}, BraceLeft = {} } = useSymbolsStore();
  const result = { value, parentValue, keyName, keys: keys || (keyName ? [keyName] : []) };
  if (isBrackets) {
    const { as, render, ...reset } = BracketsLeft;
    const BracketsLeftComp = as || 'span';
    const child = render && typeof render === 'function' && render(reset, result);
    if (child) return child;
    return <BracketsLeftComp {...reset} />;
  }
  const { as: elm, render, ...resetProps } = BraceLeft;
  const BraceLeftComp = elm || 'span';
  const child = render && typeof render === 'function' && render(resetProps, result);
  if (child) return child;
  return <BraceLeftComp {...resetProps} />;
};
 
BracketsOpen.displayName = 'JVR.BracketsOpen';
 
type BracketsProps = {
  isBrackets?: boolean;
  isVisiable?: boolean;
};
 
export const BracketsClose = <K extends object>(props: BracketsProps & SymbolsElementResult<K>) => {
  const { isBrackets, isVisiable, value, parentValue, keyName, keys } = props;
  const result = { value, parentValue, keyName, keys: keys || (keyName ? [keyName] : []) };
  if (!isVisiable) return null;
  const { BracketsRight = {}, BraceRight = {} } = useSymbolsStore();
  if (isBrackets) {
    const { as, render, ...reset } = BracketsRight;
    const BracketsRightComp = as || 'span';
    const child = render && typeof render === 'function' && render(reset, result);
    if (child) return child;
    return <BracketsRightComp {...reset} />;
  }
  const { as: elm, render, ...reset } = BraceRight;
  const BraceRightComp = elm || 'span';
  const child = render && typeof render === 'function' && render(reset, result);
  if (child) return child;
  return <BraceRightComp {...reset} />;
};
 
BracketsClose.displayName = 'JVR.BracketsClose';