UNPKG

@synergy-design-system/components

Version:
57 lines (55 loc) 1.52 kB
// src/utilities/defaultSettings/sort.ts var COMPONENT_UPDATE_ORDER = { // Container components that depend on base components update last SynButtonGroup: { dependsOn: ["SynButton", "SynRadioButton"], priority: 10 }, SynRadioGroup: { dependsOn: ["SynRadio", "SynRadioButton"], priority: 10 }, SynTagGroup: { dependsOn: ["SynTag"], priority: 10 } }; var getComponentPriority = (component) => { var _a, _b; return (_b = (_a = COMPONENT_UPDATE_ORDER[component]) == null ? void 0 : _a.priority) != null ? _b : 5; }; var sortComponentsForUpdate = (components) => { const visited = /* @__PURE__ */ new Set(); const visiting = /* @__PURE__ */ new Set(); const result = []; const visit = (component) => { if (visiting.has(component)) { return; } if (visited.has(component)) { return; } visiting.add(component); const config = COMPONENT_UPDATE_ORDER[component]; if (config == null ? void 0 : config.dependsOn) { config.dependsOn.forEach((dep) => { if (components.includes(dep)) { visit(dep); } }); } visiting.delete(component); visited.add(component); result.push(component); }; const sortedByPriority = [...components].sort( (a, b) => getComponentPriority(a) - getComponentPriority(b) ); sortedByPriority.forEach((component) => visit(component)); return result; }; export { getComponentPriority, sortComponentsForUpdate }; //# sourceMappingURL=chunk.EYAGKVTX.js.map