All files / lib/utils util.types.ts

100% Statements 243/243
100% Branches 4/4
100% Functions 2/2
100% Lines 243/243

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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 2441x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 202487x 202487x 1x 1x 32856x 32856x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
/*******************************************************************************
 * Copyright bei
 * Entwicklungs- und Pflegeverbund für das gemeinsame Fachverfahren gefa
 *
 *******************************************************************************/
 
/** only allow properties of T who are of type V.
 * eg KeysMatching<Person,string> means that only String properties of Person
 * are allowed.
 */
export type KeysMatching<T, V> = {
  [K in keyof T]-?: T[K] extends V ? K : never;
}[keyof T];
 
/** a simple callback/code-block to run */
export type Callback = () => void;
/** code-block who consumes the provided value */
export type Consumer<T> = (value: T) => void;
/** code-block who converts the input value to an output value */
export type Converter<T, U> = (value: T) => U;
 
/** A group of items. */
export interface ItemGroup<T> extends Item {
  /** Items within the group. */
  items: readonly T[];
}
 
/** interface to implement if the element has a label. This can be
 * used for convenience elements passed to various UI-Components
 */
export interface HasLabel {
  readonly label: string;
}
 
export interface HasSublabel {
  readonly sublabel: string;
}
 
export interface HasSublabels {
  readonly sublabels: readonly string[];
}
 
export type BadgeVariant = 'primary' | 'secondary' | 'tertiary';
export type BadgeStatus = 'basic' | 'error' | 'ok' | 'critical';
export type BadgeColor =
  | 'blue'
  | 'green'
  | 'black'
  | 'red'
  | 'orange'
  | 'dark-gray';
 
export interface HasBadge {
  readonly variant: BadgeVariant;
  readonly status: BadgeStatus;
  readonly showIcon?: boolean;
}
 
export interface HasLink {
  readonly link: string;
}
 
export interface HasHighlight {
  /** Highlight variant. */
  readonly variant:
    | 'filled'
    | 'striped'
    | 'horizontally-striped'
    | 'thick-striped'
    | 'reverse-striped'
    | 'vertically-striped'
    | 'square-dotted';
 
  /** Highlight color. */
  readonly color:
    | 'green'
    | 'red'
    | 'blue'
    | 'black'
    | 'yellow'
    | 'orange'
    | 'turquoise'
    | 'gray'
    | 'violet';
}
 
export interface WithHighlight {
  readonly highlight: HasHighlight;
}
 
export interface HasFilter {
  actions: SlotItem<FilterSlots>[];
  errorItems?: Item[];
  changedErrorItemKeys?: readonly string[];
  primaryButtonKey?: string;
  disabledActionKeys?: ReadonlySet<string>;
  value: string[];
  actionDescription?: string;
  showRemoveButton?: boolean;
  added?: boolean;
  allowAbbreviation?: boolean;
}
 
export interface WithBadge {
  readonly badge: HasLabel & HasBadge;
}
export type BadgeItem = Item & HasBadge;
 
export type LinkItem = Item & HasLink;
 
export type FilterItem = Item & HasFilter;
 
/**
 * Represents a node in a tree structure.
 * Optionally may also implement `HasSublabel` and `WithBadge` to supply secondary information
 * or an extra status badge.
 */
export interface TreeItem<T, MenuItem extends Item = Item>
  extends TreeItemBasic<T>,
    Partial<WithBadge>,
    Partial<HasSublabel>,
    Partial<WithHighlight> {
  /** Override the visual level of the node. If not set, the level is dermined automatically based on the structure. */
  readonly visualLevel?: number;
 
  /** Actions to show in a menu on the node. */
  readonly actions?: readonly MenuItem[];
  /**
   * If `true`, a menu button is shown on the node to make the actions available.
   * If `false` or not set, actions will available via a context menu only.
   */
  readonly showMenuButton?: boolean;
}
 
/**
 * Represents a basic node in a tree structure.
 */
export interface TreeItemBasic<T> extends Item {
  /**
   * Children of the item.
   * Note that `undefined` signals that the entry will always be a leaf in the tree, whereas an empty array `[]`
   * signals that there may be children added at a later time (the tree may thus reserve some extra space for controls
   * and render it like an empty intermediate node).
   */
  readonly children?: readonly T[];
}
 
export interface MenuItemWithChildren<T> extends Item {
  readonly children: readonly T[];
}
 
/**
 * Position in the filter container.
 */
export type FilterSlots = 'header' | 'footer';
 
export interface FilterAction {
  item: FilterItem;
  action: SlotItem<FilterSlots>;
}
 
export function hasSublabel(item: Item | HasSublabel): item is HasSublabel {
  return 'sublabel' in item && typeof item.sublabel === 'string';
}
 
export function hasSublabels(item: Item | HasSublabels): item is HasSublabels {
  return 'sublabels' in item && Array.isArray(item.sublabels);
}
 
/** a key type */
export type Key = string;
 
/** convenience interface to use when creating lists */
export interface Item extends HasLabel {
  readonly key: Key;
}
 
/** an item with extra data */
export interface SlotItem<S> extends Item {
  readonly slot: S;
}
 
/** a type which also can be `null` */
export type Nullable<T> = T | null;
 
/** a type who can be undefined, null or T */
export type OptionalNullable<T> = T | undefined | null;
 
/** a set of keys used to connect various parts of a widget */
export interface WidgetKeySet {
  /** base part of the keys */
  readonly baseKey: string;
  /** the widget key */
  readonly widgetKey: string;
  /** the label key */
  readonly labelKey: string;
  /** the error key */
  readonly errorKey: string;
}
 
/**
 * implemented by components who can transfer the focus to an element inside -
 * if there are multiple focusable elements the main one is focused
 */
export interface FocusableElementOwner {
  /**
   * move the focus to a focusable element
   *
   * @return true if focus is transfered
   */
  focusChild(): boolean;
}
 
export type RangeInputSlots = 'start' | 'end';
 
/** implemented by range-based components that contain focusable 'start' and 'end' slots */
export interface FocusableRangeElementOwner {
  focusRangeSlot(slot: RangeInputSlots): boolean;
}
 
// internal helper to allow iterating over all status types
export const formControlStatusTypeHelper = ['error'] as const;
/** Possible status types which can apply to a form control component. */
export type FormControlStatusType =
  (typeof formControlStatusTypeHelper)[number];
/** Representation of the combined state of a form control component, contains all messages for the currently active states. */
export type FormControlStatus = Partial<
  Record<FormControlStatusType, string[]>
>;
 
/**
 * Placeholder used instead of an actual value in case a form input control cannot handle some user input.
 */
export interface InvalidControlValue {
  /** Descriminator to ensure the type differs from objects used as actual control values, and hints at the reason/content. */
  readonly kind: 'InvalidControlInput';
 
  /** The original and unprocessed (raw) user input. */
  readonly rawValue: string;
 
  /** The error message - Note: this value is ignored when the value is set from external */
  readonly errorMessage: string;
}