UNPKG

@hitachivantara/uikit-react-core

Version:

Core React components for the NEXT Design System.

94 lines (93 loc) 2.68 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); const index = require("./index.cjs"); const reducer = (state, action) => { const query = structuredClone(state); switch (action.type) { case "reset-query": { return index.emptyGroup(); } case "set-query": return action.query; case "reset-group": { const group = index.findNodeById(action.id, query); if (group && "rules" in group) { group.rules = [index.emptyRule()]; return query; } break; } case "add-rule": { const group = index.findNodeById(action.id, query); if (group && "rules" in group) { const rule = index.emptyRule(); group.rules.push(rule); return query; } break; } case "add-group": { const group = index.findNodeById(action.id, query); if (group && "rules" in group) { group.rules.push(index.emptyGroup(true)); return query; } break; } case "remove-node": { const parent = index.findParentById(action.id, query); if (parent) { parent.rules = parent.rules.filter((rule) => rule.id !== action.id); return query; } return index.emptyGroup(); } case "set-combinator": { const node = index.findNodeById(action.id, query); if (node && "combinator" in node) { if (node.combinator !== action.combinator) { node.combinator = action.combinator; return query; } } break; } case "set-attribute": { const node = index.findNodeById(action.id, query); if (node && node.attribute !== action.attribute) { node.attribute = action.attribute ?? void 0; if (action.operator !== void 0) { node.operator = action.operator ?? void 0; node.value = action.value ?? void 0; } return query; } break; } case "set-operator": { const node = index.findNodeById(action.id, query); if (node && "attribute" in node) { if (node.operator !== action.operator) { node.operator = action.operator; if (action.value !== void 0) { node.value = action.value ?? void 0; } return query; } } break; } case "set-value": { const node = index.findNodeById(action.id, query); if (node && "operator" in node) { if ("value" in node) { node.value = action.value ?? void 0; } return query; } break; } } return query; }; exports.default = reducer;