kiban-design-system 1.1.12 → 1.1.13

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/index.cjs.js CHANGED
@@ -40441,9 +40441,16 @@ const JsonViewer = ({
40441
40441
  }, `btn-down-${value}`);
40442
40442
  };
40443
40443
  const getLevel = (levelName, data, id, objTemplate = []) => {
40444
+ const isArray = Object.prototype.toString.call(data) === "[object Array]";
40444
40445
  const primitiveValues = typeof data !== "string" ? getPrimitiveValues(Object(data)) : data; /** Get all primitive values from data, is data is already a string data is returned */
40445
40446
  const objectValues = getObjectValues(data); /** Get all objects from data */
40446
- const objectTemplate = Object.prototype.toString.call(data) === "[object Array]" /** Validate if data is an object */ ? getObjectTemplate(data) /** If it is an array, iterates within it to obtain the object that has more attributes than others to use as a template for the other objects in the array */ : objTemplate.length > 0 && Object.keys(primitiveValues).length === 0 /** If the objTemplate parameter is different from null and primitiveValues exist, it is because it continues to iterate within the same array (it makes recursion in this function) and the template is the same */ ? objTemplate : [];
40447
+
40448
+ // Check if this is an array of primitives (all values are primitives, no nested objects)
40449
+ const isArrayOfPrimitives = isArray && objectValues && Object.keys(objectValues).length === 0 && primitiveValues && Object.keys(primitiveValues).length > 0;
40450
+ const objectTemplate = isArray && !isArrayOfPrimitives /** Validate if data is an array and not an array of primitives */ ? getObjectTemplate(data) /** If it is an array, iterates within it to obtain the object that has more attributes than others to use as a template for the other objects in the array */ : objTemplate.length > 0 && Object.keys(primitiveValues).length === 0 /** If the objTemplate parameter is different from null and primitiveValues exist, it is because it continues to iterate within the same array (it makes recursion in this function) and the template is the same */ ? objTemplate : [];
40451
+
40452
+ // For arrays of primitives, use numeric indices sorted numerically
40453
+ const keysToUse = isArrayOfPrimitives ? Object.keys(primitiveValues).map(key => parseInt(key, 10)).filter(num => !isNaN(num)).sort((a, b) => a - b).map(num => String(num)) : objectTemplate;
40447
40454
  let primitiveRender = /*#__PURE__*/jsxRuntime.jsx(React2.Fragment, {});
40448
40455
  if (primitiveValues && Object.keys(primitiveValues).length > 0 || objectValues && Object.keys(objectValues).length > 0) {
40449
40456
  primitiveRender = /*#__PURE__*/jsxRuntime.jsx(Accordion, {
@@ -40452,7 +40459,7 @@ const JsonViewer = ({
40452
40459
  isParentClick: isParentClick,
40453
40460
  id: `${levelName}-${id}`,
40454
40461
  isLastSon: !(objectValues && Object.keys(objectValues).length > 0),
40455
- children: [primitiveValues && Object.keys(primitiveValues).length > 0 /** It validates if there is primitive calues and print them */ ? printPrimitiveValues(primitiveValues, id, objectTemplate) : null, objectValues && Object.keys(objectValues).length > 0 /** It validates that there are object type values, iterates over each one doing recursion when calling the function itself */ ? Object.keys(objectValues).map((key, index) => {
40462
+ children: [primitiveValues && Object.keys(primitiveValues).length > 0 /** It validates if there is primitive calues and print them */ ? printPrimitiveValues(primitiveValues, id, keysToUse) : null, objectValues && Object.keys(objectValues).length > 0 /** It validates that there are object type values, iterates over each one doing recursion when calling the function itself */ ? Object.keys(objectValues).map((key, index) => {
40456
40463
  return getLevel(objectTemplate.length > 0 ? `${levelName}-${index + 1}` : key, objectValues[key], `${key}-${id}-${index}`, objectTemplate);
40457
40464
  }) : null]
40458
40465
  }, `json-accordion-${levelName}-${id}`);
@@ -40464,7 +40471,9 @@ const JsonViewer = ({
40464
40471
  data.forEach(element => {
40465
40472
  objectTemplate = getNewKeys(objectTemplate, Object.keys(getPrimitiveValues(element)));
40466
40473
  });
40467
- return objectTemplate.sort();
40474
+ // Sort numerically if all keys are numeric, otherwise sort alphabetically
40475
+ const allNumeric = objectTemplate.every(key => /^\d+$/.test(key));
40476
+ return allNumeric ? objectTemplate.sort((a, b) => parseInt(a, 10) - parseInt(b, 10)) : objectTemplate.sort();
40468
40477
  };
40469
40478
  const getNewKeys = (objectTemplate, newKeys) => {
40470
40479
  newKeys.forEach(key => {