@jsonui/core 0.10.8 → 0.10.10

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/dist/cjs/index.js CHANGED
@@ -21,6 +21,9 @@ const JSON_SEPARATOR = '/';
21
21
  const STORE_ROOT_PATH = '/storeRoot';/**
22
22
  * Shared helpers for function handlers.
23
23
  */
24
+ const isRecord$1 = (value) => {
25
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
26
+ };
24
27
  const hasAnyError$1 = (value) => {
25
28
  if (value === null || value === undefined)
26
29
  return false;
@@ -530,10 +533,12 @@ const hasAnyTouched = (value) => {
530
533
  };
531
534
  const createGetModifier = (formStore) => {
532
535
  return async (params, ctx) => {
533
- const storeName = params.store;
534
- const path = params.path;
535
- const type = params.type;
536
- const jsonataDef = params.jsonataDef;
536
+ const storeName = !!params?.store && typeof params.store === 'string' ? params.store : '';
537
+ const path = !!params?.path && typeof params.path === 'string' ? params.path : '/';
538
+ const type = !!params?.type && typeof params.type === 'string' ? params.type : undefined;
539
+ const jsonataDef = params?.jsonataDef;
540
+ if (storeName.length === 0)
541
+ return undefined;
537
542
  const resolvedStoreName = type === 'ERROR' ? `${storeName}${ERROR_STORE_SUFFIX}` : type === 'TOUCH' ? `${storeName}${TOUCH_STORE_SUFFIX}` : storeName;
538
543
  // Path modifiers are keyed by the logical/base store (e.g. "data"),
539
544
  // not by shadow stores like "data.error".
@@ -620,7 +625,7 @@ const BREAKPOINT_ORDER = ['base', 'xs', 'sm', 'md', 'lg', 'xl'];/**
620
625
  * Pure and synchronous; no dependencies.
621
626
  */
622
627
  const isResponsiveStyle = (style) => {
623
- if (typeof style !== 'object')
628
+ if (typeof style !== 'object' || Array.isArray(style))
624
629
  return false;
625
630
  const keys = Object.keys(style);
626
631
  return keys.some((k) => BREAKPOINT_ORDER.includes(k));
@@ -635,7 +640,7 @@ const mergeResponsive = (responsive, currentBreakpoint) => {
635
640
  for (let i = 0; i <= idx; i++) {
636
641
  const key = BREAKPOINT_ORDER[i];
637
642
  const block = responsive[key];
638
- if (block && typeof block === 'object') {
643
+ if (block && typeof block === 'object' && !Array.isArray(block)) {
639
644
  Object.assign(merged, block);
640
645
  }
641
646
  }
@@ -796,7 +801,7 @@ const stringifyValidationError = (error) => {
796
801
  };
797
802
  const buildValidationRegistry = (rules) => {
798
803
  const registry = {};
799
- if (!rules || rules.length === 0)
804
+ if (!Array.isArray(rules) || rules.length === 0)
800
805
  return registry;
801
806
  const ajv = new Ajv({ allErrors: true, strict: false });
802
807
  // TODO: check test how looks like in jsonui
@@ -805,9 +810,18 @@ const buildValidationRegistry = (rules) => {
805
810
  for (const rule of rules) {
806
811
  if (rule.schema === undefined || rule.schema === null || !rule.store || !rule.path)
807
812
  continue;
808
- const validate = ajv.compile(rule.schema);
809
- const byStore = registry[rule.store] ?? (registry[rule.store] = {});
810
- const list = byStore[rule.path] ?? (byStore[rule.path] = []);
813
+ const schema = rule.schema;
814
+ const store = rule.store;
815
+ const path = rule.path;
816
+ if (schema === undefined || schema === null)
817
+ continue;
818
+ if (typeof store !== 'string' || store.length === 0)
819
+ continue;
820
+ if (typeof path !== 'string' || path.length === 0)
821
+ continue;
822
+ const validate = ajv.compile(schema);
823
+ const byStore = registry[store] ?? (registry[store] = {});
824
+ const list = byStore[path] ?? (byStore[path] = []);
811
825
  list.push(validate);
812
826
  }
813
827
  return registry;
@@ -901,7 +915,7 @@ const runValidationsForPath = (registry, formStore, storeName, path) => {
901
915
  // Example: action path '/a/b/c' should trigger validators registered for
902
916
  // '/', '/a', '/a/b', and '/a/b/c'.
903
917
  for (const [rulePath, validators] of Object.entries(storeValidators)) {
904
- if (!validators)
918
+ if (!Array.isArray(validators) || validators.length === 0)
905
919
  continue;
906
920
  if (!isPathPrefix(rulePath, path))
907
921
  continue;
@@ -917,7 +931,7 @@ const runValidationsForPath = (registry, formStore, storeName, path) => {
917
931
  for (const err of validate.errors) {
918
932
  if (!err.message)
919
933
  continue;
920
- const instancePath = err.instancePath;
934
+ const instancePath = typeof err.instancePath === 'string' ? err.instancePath : '';
921
935
  // instancePath is relative to rulePath, e.g. '/0/score'
922
936
  let targetPath;
923
937
  if (rulePath === '' || rulePath === '/') {
@@ -988,8 +1002,11 @@ const collectGetModifierDependencies = (val, currentPath, deps, effectivePathMod
988
1002
  collectGetModifierDependencies(v, currentPath, deps, effectivePathModifiers);
989
1003
  }
990
1004
  }
991
- };const runValidationSpecsFromNode = async (node, modifiers, ctx, componentStoreName, componentLogicalPath) => {
992
- const rawValidation = node[V_VALIDATIONS];
1005
+ };const isRecord = (value) => {
1006
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
1007
+ };
1008
+ const runValidationSpecsFromNode = async (node, modifiers, ctx, componentStoreName, componentLogicalPath) => {
1009
+ const rawValidation = isRecord(node) ? node[V_VALIDATIONS] : undefined;
993
1010
  if (!rawValidation || !Array.isArray(rawValidation) || rawValidation.length === 0)
994
1011
  return;
995
1012
  if (!componentStoreName || componentLogicalPath == null)
@@ -1004,7 +1021,8 @@ const runRenderNodeResolution = async ({ node, modifiers, ctx, currentPath, effe
1004
1021
  const props = {};
1005
1022
  const deps = [];
1006
1023
  const resolvedSlots = {};
1007
- for (const [key, value] of Object.entries(node)) {
1024
+ const nodeEntries = isRecord(node) ? Object.entries(node) : [];
1025
+ for (const [key, value] of nodeEntries) {
1008
1026
  if (key.startsWith('$child') || !key.startsWith('$')) {
1009
1027
  collectGetModifierDependencies(value, currentPath, deps, effectivePathModifiers);
1010
1028
  if (key.startsWith('$child')) {
@@ -1015,12 +1033,17 @@ const runRenderNodeResolution = async ({ node, modifiers, ctx, currentPath, effe
1015
1033
  }
1016
1034
  }
1017
1035
  }
1018
- if (props.style != null && typeof props.style === 'object') {
1019
- const resolved = resolveStyle(props.style, {
1020
- platform: stylePlatform,
1021
- breakpoint: styleBreakpoint,
1022
- });
1023
- props.style = resolved ?? props.style;
1036
+ if (props.style != null) {
1037
+ if (typeof props.style !== 'object' || Array.isArray(props.style)) {
1038
+ delete props.style;
1039
+ }
1040
+ else {
1041
+ const resolved = resolveStyle(props.style, {
1042
+ platform: stylePlatform,
1043
+ breakpoint: styleBreakpoint,
1044
+ });
1045
+ props.style = resolved ?? props.style;
1046
+ }
1024
1047
  }
1025
1048
  const resolvedComponentPath = componentStore && componentPath != null ? resolveStorePath(componentPath, currentPath, effectivePathModifiers, componentStore) : undefined;
1026
1049
  await runValidationSpecsFromNode(node, modifiers, ctx, componentStore, resolvedComponentPath);
@@ -1042,7 +1065,8 @@ const runRenderNodeResolution = async ({ node, modifiers, ctx, currentPath, effe
1042
1065
  return undefined;
1043
1066
  return async (e) => {
1044
1067
  // TODO: research, why componentProps need
1045
- const resolvedParams = { ...componentProps, ...params };
1068
+ const safeComponentProps = typeof componentProps === 'object' ? componentProps : {};
1069
+ const resolvedParams = { ...safeComponentProps, ...params };
1046
1070
  // Case 1: value from event (input onChange) – only when the model
1047
1071
  // did NOT define a value explicitly.
1048
1072
  if (!hasExplicitValue && e != null && typeof e === 'object' && 'target' in e) {
@@ -1059,8 +1083,8 @@ const runRenderNodeResolution = async ({ node, modifiers, ctx, currentPath, effe
1059
1083
  if (result instanceof Promise)
1060
1084
  await result;
1061
1085
  // Run validations for this store/path if configured
1062
- const storeName = resolvedParams.store;
1063
- const rawPath = resolvedParams.path;
1086
+ const storeName = typeof resolvedParams.store === 'string' ? resolvedParams.store : undefined;
1087
+ const rawPath = typeof resolvedParams.path === 'string' ? resolvedParams.path : undefined;
1064
1088
  if (validators && storeName && rawPath) {
1065
1089
  // Resolve to logical path so validations work with lists, pathModifiers,
1066
1090
  // and relative paths (e.g. "score" inside /players/0).
@@ -1115,4 +1139,4 @@ const t = (params, ctx) => {
1115
1139
  jsonata,
1116
1140
  isNotTouchedOrHasError,
1117
1141
  t,
1118
- };exports.ACTION_KEY=ACTION_KEY;exports.BREAKPOINT_ORDER=BREAKPOINT_ORDER;exports.DEFAULT_BREAKPOINTS=DEFAULT_BREAKPOINTS;exports.ERROR_STORE_SUFFIX=ERROR_STORE_SUFFIX;exports.FormStore=FormStore;exports.LIST_ITEM=LIST_ITEM;exports.LIST_ITEM_PER_PAGE=LIST_ITEM_PER_PAGE;exports.LIST_LENGTH=LIST_LENGTH;exports.LIST_PAGE=LIST_PAGE;exports.LIST_SEMAPHORE=LIST_SEMAPHORE;exports.MODIFIER_KEY=MODIFIER_KEY;exports.PATH_MODIFIERS_KEY=PATH_MODIFIERS_KEY;exports.TOUCH_STORE_SUFFIX=TOUCH_STORE_SUFFIX;exports.V_CHILDREN=V_CHILDREN;exports.V_COMP=V_COMP;exports.V_VALIDATIONS=V_VALIDATIONS;exports.actions=actions;exports.buildValidationRegistry=buildValidationRegistry;exports.computeListSliceRange=computeListSliceRange;exports.expandSimplifiedNode=expandSimplifiedNode;exports.getOwnPathModifiers=getOwnPathModifiers;exports.isPathPrefix=isPathPrefix$1;exports.mergeEffectivePathModifiers=mergeEffectivePathModifiers;exports.modifiers=modifiers;exports.normalizePath=normalizePath;exports.resolveAction=resolveAction;exports.resolveStorePath=resolveStorePath;exports.runRenderNodeResolution=runRenderNodeResolution;//# sourceMappingURL=index.js.map
1142
+ };exports.ACTION_KEY=ACTION_KEY;exports.BREAKPOINT_ORDER=BREAKPOINT_ORDER;exports.DEFAULT_BREAKPOINTS=DEFAULT_BREAKPOINTS;exports.ERROR_STORE_SUFFIX=ERROR_STORE_SUFFIX;exports.FormStore=FormStore;exports.LIST_ITEM=LIST_ITEM;exports.LIST_ITEM_PER_PAGE=LIST_ITEM_PER_PAGE;exports.LIST_LENGTH=LIST_LENGTH;exports.LIST_PAGE=LIST_PAGE;exports.LIST_SEMAPHORE=LIST_SEMAPHORE;exports.MODIFIER_KEY=MODIFIER_KEY;exports.PATH_MODIFIERS_KEY=PATH_MODIFIERS_KEY;exports.TOUCH_STORE_SUFFIX=TOUCH_STORE_SUFFIX;exports.V_CHILDREN=V_CHILDREN;exports.V_COMP=V_COMP;exports.V_VALIDATIONS=V_VALIDATIONS;exports.actions=actions;exports.buildValidationRegistry=buildValidationRegistry;exports.computeListSliceRange=computeListSliceRange;exports.expandSimplifiedNode=expandSimplifiedNode;exports.getOwnPathModifiers=getOwnPathModifiers;exports.isPathPrefix=isPathPrefix$1;exports.isRecord=isRecord$1;exports.mergeEffectivePathModifiers=mergeEffectivePathModifiers;exports.modifiers=modifiers;exports.normalizePath=normalizePath;exports.resolveAction=resolveAction;exports.resolveStorePath=resolveStorePath;exports.runRenderNodeResolution=runRenderNodeResolution;//# sourceMappingURL=index.js.map