@react-typed-forms/schemas 7.3.2 → 8.1.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.
package/src/tailwind.tsx CHANGED
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import { DefaultRendererOptions } from "./renderers";
3
3
 
4
- export const defaultTailwindTheme: DefaultRendererOptions = {
4
+ export const defaultTailwindTheme = {
5
5
  label: {
6
6
  groupLabelClass: "font-bold",
7
7
  requiredElement: <span className="text-red-500"> *</span>,
@@ -26,4 +26,4 @@ export const defaultTailwindTheme: DefaultRendererOptions = {
26
26
  data: {
27
27
  displayOnlyClass: "flex flex-row items-center gap-2",
28
28
  },
29
- };
29
+ } satisfies DefaultRendererOptions;
package/src/types.ts CHANGED
@@ -65,6 +65,7 @@ export interface ControlDefinition {
65
65
  title?: string | null;
66
66
  styleClass?: string | null;
67
67
  layoutClass?: string | null;
68
+ labelClass?: string | null;
68
69
  dynamic?: DynamicProperty[] | null;
69
70
  adornments?: ControlAdornment[] | null;
70
71
  children?: ControlDefinition[] | null;
@@ -90,7 +91,8 @@ export enum DynamicPropertyType {
90
91
  Display = "Display",
91
92
  Style = "Style",
92
93
  LayoutStyle = "LayoutStyle",
93
- AllowedOptions = "AllowedOptions"
94
+ AllowedOptions = "AllowedOptions",
95
+ Label = "Label",
94
96
  }
95
97
 
96
98
  export interface EntityExpression {
package/src/util.ts CHANGED
@@ -389,18 +389,25 @@ export function cleanDataForSchema(
389
389
 
390
390
  export function getAllReferencedClasses(c: ControlDefinition): string[] {
391
391
  const childClasses = c.children?.flatMap(getAllReferencedClasses);
392
- const tc = clsx(c.styleClass, c.layoutClass);
392
+ const tc = clsx(
393
+ getOverrideClass(c.styleClass),
394
+ getOverrideClass(c.layoutClass),
395
+ getOverrideClass(c.labelClass),
396
+ );
393
397
  if (childClasses && !tc) return childClasses;
394
398
  if (!tc) return [];
395
399
  if (childClasses) return [tc, ...childClasses];
396
400
  return [tc];
397
401
  }
398
402
 
399
- export function jsonPathString(jsonPath: JsonPath[]) {
403
+ export function jsonPathString(
404
+ jsonPath: JsonPath[],
405
+ customIndex?: (n: number) => string,
406
+ ) {
400
407
  let out = "";
401
408
  jsonPath.forEach((v, i) => {
402
409
  if (typeof v === "number") {
403
- out += "[" + v + "]";
410
+ out += customIndex?.(v) ?? "[" + v + "]";
404
411
  } else {
405
412
  if (i > 0) out += ".";
406
413
  out += v;
@@ -408,3 +415,31 @@ export function jsonPathString(jsonPath: JsonPath[]) {
408
415
  });
409
416
  return out;
410
417
  }
418
+
419
+ export function findChildDefinition(
420
+ parent: ControlDefinition,
421
+ childPath: number | number[],
422
+ ): ControlDefinition {
423
+ if (Array.isArray(childPath)) {
424
+ let base = parent;
425
+ childPath.forEach((x) => (base = base.children![x]));
426
+ return base;
427
+ }
428
+ return parent.children![childPath];
429
+ }
430
+
431
+ export function getOverrideClass(className?: string | null) {
432
+ if (className && className.startsWith("@ ")) {
433
+ return className.substring(2);
434
+ }
435
+ return className;
436
+ }
437
+
438
+ export function rendererClass(
439
+ controlClass?: string | null,
440
+ globalClass?: string | null,
441
+ ) {
442
+ const oc = getOverrideClass(controlClass);
443
+ if (oc === controlClass) return clsx(controlClass, globalClass);
444
+ return oc ? oc : undefined;
445
+ }