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 +12 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +12 -3
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -40421,9 +40421,16 @@ const JsonViewer = ({
|
|
|
40421
40421
|
}, `btn-down-${value}`);
|
|
40422
40422
|
};
|
|
40423
40423
|
const getLevel = (levelName, data, id, objTemplate = []) => {
|
|
40424
|
+
const isArray = Object.prototype.toString.call(data) === "[object Array]";
|
|
40424
40425
|
const primitiveValues = typeof data !== "string" ? getPrimitiveValues(Object(data)) : data; /** Get all primitive values from data, is data is already a string data is returned */
|
|
40425
40426
|
const objectValues = getObjectValues(data); /** Get all objects from data */
|
|
40426
|
-
|
|
40427
|
+
|
|
40428
|
+
// Check if this is an array of primitives (all values are primitives, no nested objects)
|
|
40429
|
+
const isArrayOfPrimitives = isArray && objectValues && Object.keys(objectValues).length === 0 && primitiveValues && Object.keys(primitiveValues).length > 0;
|
|
40430
|
+
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 : [];
|
|
40431
|
+
|
|
40432
|
+
// For arrays of primitives, use numeric indices sorted numerically
|
|
40433
|
+
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;
|
|
40427
40434
|
let primitiveRender = /*#__PURE__*/jsx(Fragment$1, {});
|
|
40428
40435
|
if (primitiveValues && Object.keys(primitiveValues).length > 0 || objectValues && Object.keys(objectValues).length > 0) {
|
|
40429
40436
|
primitiveRender = /*#__PURE__*/jsx(Accordion, {
|
|
@@ -40432,7 +40439,7 @@ const JsonViewer = ({
|
|
|
40432
40439
|
isParentClick: isParentClick,
|
|
40433
40440
|
id: `${levelName}-${id}`,
|
|
40434
40441
|
isLastSon: !(objectValues && Object.keys(objectValues).length > 0),
|
|
40435
|
-
children: [primitiveValues && Object.keys(primitiveValues).length > 0 /** It validates if there is primitive calues and print them */ ? printPrimitiveValues(primitiveValues, id,
|
|
40442
|
+
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) => {
|
|
40436
40443
|
return getLevel(objectTemplate.length > 0 ? `${levelName}-${index + 1}` : key, objectValues[key], `${key}-${id}-${index}`, objectTemplate);
|
|
40437
40444
|
}) : null]
|
|
40438
40445
|
}, `json-accordion-${levelName}-${id}`);
|
|
@@ -40444,7 +40451,9 @@ const JsonViewer = ({
|
|
|
40444
40451
|
data.forEach(element => {
|
|
40445
40452
|
objectTemplate = getNewKeys(objectTemplate, Object.keys(getPrimitiveValues(element)));
|
|
40446
40453
|
});
|
|
40447
|
-
|
|
40454
|
+
// Sort numerically if all keys are numeric, otherwise sort alphabetically
|
|
40455
|
+
const allNumeric = objectTemplate.every(key => /^\d+$/.test(key));
|
|
40456
|
+
return allNumeric ? objectTemplate.sort((a, b) => parseInt(a, 10) - parseInt(b, 10)) : objectTemplate.sort();
|
|
40448
40457
|
};
|
|
40449
40458
|
const getNewKeys = (objectTemplate, newKeys) => {
|
|
40450
40459
|
newKeys.forEach(key => {
|