@vitus-labs/elements 2.3.0 → 2.5.0

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.
Files changed (2) hide show
  1. package/lib/index.d.ts +28 -23
  2. package/package.json +3 -3
package/lib/index.d.ts CHANGED
@@ -318,6 +318,8 @@ type ExtendedProps = {
318
318
  even: boolean;
319
319
  position: number;
320
320
  };
321
+ /** Loose item-callback param — uniformly typed across branches. */
322
+ type LooseItem = SimpleValue | ObjectValue | Record<string, SimpleValue>;
321
323
  /**
322
324
  * Iterator over an array of strings/numbers. Each item is wrapped in
323
325
  * `{ [valueName]: item }` and that object is what callbacks see + what's
@@ -332,44 +334,47 @@ type SimpleProps<T extends SimpleValue> = {
332
334
  * passed to the component as its children.
333
335
  */
334
336
  valueName?: string; /** Optional wrapper around each item. */
335
- wrapComponent?: ElementType; /** Stable key per item (defaults to index). */
336
- itemKey?: (item: T, index: number) => SimpleValue; /** Extra props merged onto the rendered component, optionally per-item. */
337
- itemProps?: TObj | ((item: {
338
- [k: string]: T;
339
- }, ext: ExtendedProps) => TObj); /** Extra props merged onto the wrapper, optionally per-item. */
340
- wrapProps?: TObj | ((item: {
341
- [k: string]: T;
342
- }, ext: ExtendedProps) => TObj);
343
- children?: never;
337
+ wrapComponent?: ElementType; /** Stable key per item pick a key, or compute it. */
338
+ itemKey?: keyof ObjectValue | ((item: LooseItem, index: number) => SimpleValue); /** Extra props merged onto the rendered component, optionally per-item. */
339
+ itemProps?: TObj | ((item: LooseItem, ext: ExtendedProps) => TObj); /** Extra props merged onto the wrapper, optionally per-item. */
340
+ wrapProps?: TObj | ((item: LooseItem, ext: ExtendedProps) => TObj); /** Children are ignored at runtime when `data` is present. */
341
+ children?: ReactNode;
344
342
  };
345
343
  /**
346
344
  * Iterator over an array of objects. Each item is spread onto the rendered
347
345
  * component as props. Per-item `component` overrides also work — when an
348
346
  * item carries its own `component` field, the wrapper is bypassed.
347
+ *
348
+ * `itemKey` keeps the per-`T` narrowing (`keyof T`) so direct callers
349
+ * benefit from key-completion against the concrete `T`. itemProps /
350
+ * wrapProps share the loose signature for forwarding compatibility.
349
351
  */
350
352
  type ObjectProps<T extends ObjectValue> = {
351
353
  data: Array<T | MaybeNull>; /** Default React component to be rendered per item (item-level `component` overrides). */
352
- component: ElementType; /** `valueName` is meaningless when iterating objects TS forbids it. */
353
- valueName?: never; /** Optional wrapper around each item. */
354
+ component: ElementType; /** `valueName` is meaningless when iterating objects (runtime ignores it). */
355
+ valueName?: string; /** Optional wrapper around each item. */
354
356
  wrapComponent?: ElementType; /** Stable key per item — pick a key from the item, or compute it. */
355
- itemKey?: keyof T | ((item: T, index: number) => SimpleValue); /** Extra props merged onto the rendered component, optionally per-item. */
356
- itemProps?: TObj | ((item: T, ext: ExtendedProps) => TObj); /** Extra props merged onto the wrapper, optionally per-item. */
357
- wrapProps?: TObj | ((item: T, ext: ExtendedProps) => TObj);
358
- children?: never;
357
+ itemKey?: keyof T | ((item: LooseItem, index: number) => SimpleValue); /** Extra props merged onto the rendered component, optionally per-item. */
358
+ itemProps?: TObj | ((item: LooseItem, ext: ExtendedProps) => TObj); /** Extra props merged onto the wrapper, optionally per-item. */
359
+ wrapProps?: TObj | ((item: LooseItem, ext: ExtendedProps) => TObj); /** Children are ignored at runtime when `data` is present. */
360
+ children?: ReactNode;
359
361
  };
360
362
  /**
361
- * Iterator over `children` — no `data`/`component`. Each child gets
362
- * positional metadata via `itemProps` and an optional `wrapComponent`.
363
+ * Iterator over `children` — no `data`/`component` at runtime. Each
364
+ * child gets positional metadata via `itemProps` and an optional
365
+ * `wrapComponent`. data/component/valueName/itemKey are accepted at the
366
+ * type level for forwarding compatibility but ignored at runtime when
367
+ * `children` is the active discriminator.
363
368
  */
364
369
  type ChildrenProps = {
365
370
  children: ReactNode;
366
- data?: never;
367
- component?: never;
368
- valueName?: never;
369
- itemKey?: never;
371
+ data?: Array<SimpleValue | ObjectValue | MaybeNull>;
372
+ component?: ElementType;
373
+ valueName?: string;
374
+ itemKey?: keyof ObjectValue | ((item: LooseItem, index: number) => SimpleValue);
370
375
  wrapComponent?: ElementType;
371
- itemProps?: TObj | ((_: Record<string, never>, ext: ExtendedProps) => TObj);
372
- wrapProps?: TObj | ((_: Record<string, never>, ext: ExtendedProps) => TObj);
376
+ itemProps?: TObj | ((item: LooseItem, ext: ExtendedProps) => TObj);
377
+ wrapProps?: TObj | ((item: LooseItem, ext: ExtendedProps) => TObj);
373
378
  };
374
379
  type PropsCallback = TObj | ((itemProps: Record<string, never> | Record<string, SimpleValue> | ObjectValue, extendedProps: ExtendedProps) => TObj);
375
380
  type LooseProps = Partial<{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitus-labs/elements",
3
- "version": "2.3.0",
3
+ "version": "2.5.0",
4
4
  "license": "MIT",
5
5
  "author": "Vit Bokisch <vit@bokisch.cz>",
6
6
  "maintainers": [
@@ -57,8 +57,8 @@
57
57
  "typecheck": "tsc --noEmit"
58
58
  },
59
59
  "peerDependencies": {
60
- "@vitus-labs/core": "^2.3.0",
61
- "@vitus-labs/unistyle": "^2.3.0",
60
+ "@vitus-labs/core": "^2.5.0",
61
+ "@vitus-labs/unistyle": "^2.5.0",
62
62
  "react": ">= 19",
63
63
  "react-dom": ">= 19",
64
64
  "react-native": ">= 0.76"