@vocdoni/chakra-components
Version:
Vocdoni's Chakra UI Components
1,231 lines (1,200 loc) • 248 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// ../../node_modules/react-string-replace/index.js
var require_react_string_replace = __commonJS({
"../../node_modules/react-string-replace/index.js"(exports2, module2) {
var isRegExp = function(re) {
return re instanceof RegExp;
};
var escapeRegExp = function escapeRegExp2(string) {
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g, reHasRegExpChar = RegExp(reRegExpChar.source);
return string && reHasRegExpChar.test(string) ? string.replace(reRegExpChar, "\\$&") : string;
};
var isString2 = function(value) {
return typeof value === "string";
};
var flatten = function(array) {
var newArray = [];
array.forEach(function(item) {
if (Array.isArray(item)) {
newArray = newArray.concat(item);
} else {
newArray.push(item);
}
});
return newArray;
};
function replaceString(str, match2, fn) {
var curCharStart = 0;
var curCharLen = 0;
if (str === "") {
return str;
} else if (!str || !isString2(str)) {
throw new TypeError("First argument to react-string-replace#replaceString must be a string");
}
var re = match2;
if (!isRegExp(re)) {
re = new RegExp("(" + escapeRegExp(re) + ")", "gi");
}
var result = str.split(re);
for (var i2 = 1, length = result.length; i2 < length; i2 += 2) {
if (result[i2] === void 0 || result[i2 - 1] === void 0) {
console.warn("reactStringReplace: Encountered undefined value during string replacement. Your RegExp may not be working the way you expect.");
continue;
}
curCharLen = result[i2].length;
curCharStart += result[i2 - 1].length;
result[i2] = fn(result[i2], i2, curCharStart);
curCharStart += curCharLen;
}
return result;
}
module2.exports = function reactStringReplace2(source, match2, fn) {
if (!Array.isArray(source)) source = [source];
return flatten(source.map(function(x2) {
return isString2(x2) ? replaceString(x2, match2, fn) : x2;
}));
};
}
});
// src/index.ts
var index_exports = {};
__export(index_exports, {
ActionCancel: () => ActionCancel,
ActionContinue: () => ActionContinue,
ActionEnd: () => ActionEnd,
ActionPause: () => ActionPause,
ActionsProvider: () => ActionsProvider,
ApprovalChoice: () => ApprovalChoice,
Avatar: () => Avatar,
Balance: () => Balance,
ClientProvider: () => ClientProvider,
ConfirmModal: () => ConfirmModal,
ConfirmModalTheme: () => ConfirmModalTheme,
ConfirmProvider: () => ConfirmProvider,
Election: () => Election,
ElectionActions: () => ElectionActions,
ElectionDescription: () => ElectionDescription,
ElectionHeader: () => ElectionHeader,
ElectionQuestion: () => ElectionQuestion,
ElectionQuestions: () => ElectionQuestions,
ElectionQuestionsForm: () => ElectionQuestionsForm,
ElectionResults: () => ElectionResults,
ElectionSchedule: () => ElectionSchedule,
ElectionScheduleTheme: () => ElectionScheduleTheme,
ElectionStatusBadge: () => ElectionStatusBadge,
ElectionTitle: () => ElectionTitle,
ElectionTitleTheme: () => ElectionTitleTheme,
EllipsisButton: () => EllipsisButton,
Envelope: () => Envelope,
EnvelopeTheme: () => EnvelopeTheme,
FieldSwitcher: () => FieldSwitcher,
HR: () => HR,
HorizontalRulerTheme: () => HorizontalRulerTheme,
Image: () => Image,
Markdown: () => Markdown,
MultiChoice: () => MultiChoice,
OrganizationAvatar: () => OrganizationAvatar,
OrganizationDescription: () => OrganizationDescription,
OrganizationHeader: () => OrganizationHeader,
OrganizationImage: () => OrganizationImage,
OrganizationName: () => OrganizationName,
Pagination: () => Pagination,
PaginationButton: () => PaginationButton,
PaginationTheme: () => PaginationTheme,
QuestionChoice: () => QuestionChoice,
QuestionChoiceTheme: () => QuestionChoiceTheme,
QuestionTheme: () => QuestionTheme,
QuestionTip: () => QuestionTip,
QuestionsConfirmation: () => QuestionsConfirmation,
QuestionsConfirmationTheme: () => QuestionsConfirmationTheme,
QuestionsFormProvider: () => QuestionsFormProvider,
QuestionsTheme: () => QuestionsTheme,
QuestionsTipTheme: () => QuestionsTipTheme,
QuestionsTypeBadge: () => QuestionsTypeBadge,
QuestionsTypeBadgeTheme: () => QuestionsTypeBadgeTheme,
ResultsTheme: () => ResultsTheme,
RoutedPagination: () => RoutedPagination,
SingleChoice: () => SingleChoice,
SpreadsheetAccess: () => SpreadsheetAccess,
VoteButton: () => VoteButton,
VoteWeight: () => VoteWeight,
VoteWeightTheme: () => VoteWeightTheme,
Voted: () => Voted,
actionsAnatomy: () => actionsAnatomy,
confirmAnatomy: () => confirmAnatomy,
ellipsisButtonAnatomy: () => ellipsisButtonAnatomy,
emptyQuestionsAnatomy: () => emptyQuestionsAnatomy,
envelopeAnatomy: () => envelopeAnatomy,
environment: () => environment,
linkify: () => linkify,
paginationAnatomy: () => paginationAnatomy,
questionAnatomy: () => questionAnatomy,
questionChoiceAnatomy: () => questionChoiceAnatomy,
questionTipAnatomy: () => questionTipAnatomy,
questionTypeBadgeAnatomy: () => questionTypeBadgeAnatomy,
questionsAnatomy: () => questionsAnatomy,
questionsConfirmationAnatomy: () => questionsConfirmationAnatomy,
questionsEmptyAnatomy: () => questionsEmptyAnatomy,
questionsErrorAnatomy: () => questionsErrorAnatomy,
results: () => results,
resultsAnatomy: () => resultsAnatomy,
signModalAnatomy: () => signModalAnatomy,
spreadsheetAccessAnatomy: () => spreadsheetAccessAnatomy,
theme: () => theme3,
useConfirm: () => useConfirm,
useQuestionsForm: () => useQuestionsForm,
voteWeightAnatomy: () => voteWeightAnatomy,
votedAnatomy: () => votedAnatomy
});
module.exports = __toCommonJS(index_exports);
// src/client.tsx
var import_react53 = require("@chakra-ui/react");
var import_react_providers35 = require("@vocdoni/react-providers");
// ../../node_modules/ts-deepmerge/esm/index.js
var isObject = (obj) => {
if (typeof obj === "object" && obj !== null) {
if (typeof Object.getPrototypeOf === "function") {
const prototype = Object.getPrototypeOf(obj);
return prototype === Object.prototype || prototype === null;
}
return Object.prototype.toString.call(obj) === "[object Object]";
}
return false;
};
var merge = (...objects) => objects.reduce((result, current) => {
if (Array.isArray(current)) {
throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");
}
Object.keys(current).forEach((key) => {
if (["__proto__", "constructor", "prototype"].includes(key)) {
return;
}
if (Array.isArray(result[key]) && Array.isArray(current[key])) {
result[key] = merge.options.mergeArrays ? merge.options.uniqueArrayItems ? Array.from(new Set(result[key].concat(current[key]))) : [...result[key], ...current[key]] : current[key];
} else if (isObject(result[key]) && isObject(current[key])) {
result[key] = merge(result[key], current[key]);
} else {
result[key] = current[key] === void 0 ? merge.options.allowUndefinedOverrides ? current[key] : result[key] : current[key];
}
});
return result;
}, {});
var defaultOptions = {
allowUndefinedOverrides: true,
mergeArrays: true,
uniqueArrayItems: true
};
merge.options = defaultOptions;
merge.withOptions = (options, ...objects) => {
merge.options = Object.assign(Object.assign({}, defaultOptions), options);
const result = merge(...objects);
merge.options = defaultOptions;
return result;
};
var esm_default = merge;
// src/components/Account/Balance.tsx
var import_react = require("@chakra-ui/react");
var import_react_providers = require("@vocdoni/react-providers");
var import_jsx_runtime = require("react/jsx-runtime");
var Balance = (props) => {
const { balance, localize: localize2 } = (0, import_react_providers.useClient)();
if (balance < 0) {
return null;
}
let color = "teal";
if (balance < 50 && balance > 20) {
color = "yellow";
} else if (balance <= 20) {
color = "red";
}
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Tag, { size: "sm", colorScheme: color, ...props, children: localize2("balance", { balance }) });
};
// src/components/Election/Actions/Actions.tsx
var import_react16 = require("@chakra-ui/react");
var import_react_providers9 = require("@vocdoni/react-providers");
var import_sdk5 = require("@vocdoni/sdk");
// ../../node_modules/react-icons/lib/esm/iconBase.js
var import_react3 = __toESM(require("react"));
// ../../node_modules/react-icons/lib/esm/iconContext.js
var import_react2 = __toESM(require("react"));
var DefaultContext = {
color: void 0,
size: void 0,
className: void 0,
style: void 0,
attr: void 0
};
var IconContext = import_react2.default.createContext && import_react2.default.createContext(DefaultContext);
// ../../node_modules/react-icons/lib/esm/iconBase.js
var __assign = function() {
__assign = Object.assign || function(t2) {
for (var s3, i2 = 1, n = arguments.length; i2 < n; i2++) {
s3 = arguments[i2];
for (var p in s3) if (Object.prototype.hasOwnProperty.call(s3, p)) t2[p] = s3[p];
}
return t2;
};
return __assign.apply(this, arguments);
};
var __rest = function(s3, e2) {
var t2 = {};
for (var p in s3) if (Object.prototype.hasOwnProperty.call(s3, p) && e2.indexOf(p) < 0) t2[p] = s3[p];
if (s3 != null && typeof Object.getOwnPropertySymbols === "function") for (var i2 = 0, p = Object.getOwnPropertySymbols(s3); i2 < p.length; i2++) {
if (e2.indexOf(p[i2]) < 0 && Object.prototype.propertyIsEnumerable.call(s3, p[i2])) t2[p[i2]] = s3[p[i2]];
}
return t2;
};
function Tree2Element(tree) {
return tree && tree.map(function(node, i2) {
return import_react3.default.createElement(node.tag, __assign({
key: i2
}, node.attr), Tree2Element(node.child));
});
}
function GenIcon(data) {
return function(props) {
return import_react3.default.createElement(IconBase, __assign({
attr: __assign({}, data.attr)
}, props), Tree2Element(data.child));
};
}
function IconBase(props) {
var elem = function(conf) {
var attr = props.attr, size = props.size, title = props.title, svgProps = __rest(props, ["attr", "size", "title"]);
var computedSize = size || conf.size || "1em";
var className;
if (conf.className) className = conf.className;
if (props.className) className = (className ? className + " " : "") + props.className;
return import_react3.default.createElement("svg", __assign({
stroke: "currentColor",
fill: "currentColor",
strokeWidth: "0"
}, conf.attr, attr, svgProps, {
className,
style: __assign(__assign({
color: props.color || conf.color
}, conf.style), props.style),
height: computedSize,
width: computedSize,
xmlns: "http://www.w3.org/2000/svg"
}), title && import_react3.default.createElement("title", null, title), props.children);
};
return IconContext !== void 0 ? import_react3.default.createElement(IconContext.Consumer, null, function(conf) {
return elem(conf);
}) : elem(DefaultContext);
}
// ../../node_modules/react-icons/fa/index.esm.js
function FaPause(props) {
return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 448 512" }, "child": [{ "tag": "path", "attr": { "d": "M144 479H48c-26.5 0-48-21.5-48-48V79c0-26.5 21.5-48 48-48h96c26.5 0 48 21.5 48 48v352c0 26.5-21.5 48-48 48zm304-48V79c0-26.5-21.5-48-48-48h-96c-26.5 0-48 21.5-48 48v352c0 26.5 21.5 48 48 48h96c26.5 0 48-21.5 48-48z" } }] })(props);
}
function FaPlay(props) {
return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 448 512" }, "child": [{ "tag": "path", "attr": { "d": "M424.4 214.7L72.4 6.6C43.8-10.3 0 6.1 0 47.9V464c0 37.5 40.7 60.1 72.4 41.3l352-208c31.4-18.5 31.5-64.1 0-82.6z" } }] })(props);
}
function FaStop(props) {
return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 448 512" }, "child": [{ "tag": "path", "attr": { "d": "M400 32H48C21.5 32 0 53.5 0 80v352c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V80c0-26.5-21.5-48-48-48z" } }] })(props);
}
// ../../node_modules/react-icons/im/index.esm.js
function ImCross(props) {
return GenIcon({ "tag": "svg", "attr": { "version": "1.1", "viewBox": "0 0 16 16" }, "child": [{ "tag": "path", "attr": { "d": "M15.854 12.854c-0-0-0-0-0-0l-4.854-4.854 4.854-4.854c0-0 0-0 0-0 0.052-0.052 0.090-0.113 0.114-0.178 0.066-0.178 0.028-0.386-0.114-0.529l-2.293-2.293c-0.143-0.143-0.351-0.181-0.529-0.114-0.065 0.024-0.126 0.062-0.178 0.114 0 0-0 0-0 0l-4.854 4.854-4.854-4.854c-0-0-0-0-0-0-0.052-0.052-0.113-0.090-0.178-0.114-0.178-0.066-0.386-0.029-0.529 0.114l-2.293 2.293c-0.143 0.143-0.181 0.351-0.114 0.529 0.024 0.065 0.062 0.126 0.114 0.178 0 0 0 0 0 0l4.854 4.854-4.854 4.854c-0 0-0 0-0 0-0.052 0.052-0.090 0.113-0.114 0.178-0.066 0.178-0.029 0.386 0.114 0.529l2.293 2.293c0.143 0.143 0.351 0.181 0.529 0.114 0.065-0.024 0.126-0.062 0.178-0.114 0-0 0-0 0-0l4.854-4.854 4.854 4.854c0 0 0 0 0 0 0.052 0.052 0.113 0.090 0.178 0.114 0.178 0.066 0.386 0.029 0.529-0.114l2.293-2.293c0.143-0.143 0.181-0.351 0.114-0.529-0.024-0.065-0.062-0.126-0.114-0.178z" } }] })(props);
}
// src/components/Election/Actions/ActionsProvider.tsx
var import_react_providers3 = require("@vocdoni/react-providers");
// src/components/Election/Actions/use-actions-toast.ts
var import_react4 = require("@chakra-ui/react");
var import_react_providers2 = require("@vocdoni/react-providers");
var import_react5 = require("react");
var useActionsToast = () => {
const tRef = (0, import_react5.useRef)();
const { info, error } = (0, import_react_providers2.useActions)();
const toast = (0, import_react4.useToast)();
(0, import_react5.useEffect)(() => {
if (toast && info === null && tRef.current) {
toast.close(tRef.current);
}
if (info && toast) {
tRef.current = toast({
title: info.title,
description: info.description,
status: "info",
duration: null,
isClosable: false
});
}
if (error && toast) {
toast({
title: error.title,
description: error.description,
status: "error",
duration: 7e3,
isClosable: false
});
}
}, [info, error, toast]);
};
// src/components/Election/Actions/ActionsProvider.tsx
var import_jsx_runtime2 = require("react/jsx-runtime");
var ActionsProvider = (props) => {
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_providers3.ActionsProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChakraInternalActionsProvider, { ...props }) });
};
var ChakraInternalActionsProvider = ({ children }) => {
useActionsToast();
return children;
};
// src/components/Election/Actions/Cancel.tsx
var import_react12 = require("@chakra-ui/react");
var import_react_providers5 = require("@vocdoni/react-providers");
var import_sdk = require("@vocdoni/sdk");
// src/components/layout/ConfirmModal/ConfirmModal.tsx
var import_react7 = require("@chakra-ui/react");
// src/components/layout/ConfirmModal/ConfirmProvider.tsx
var import_react6 = require("react");
var import_jsx_runtime3 = require("react/jsx-runtime");
var useConfirmProvider = () => {
const [state, setState] = (0, import_react6.useState)({
prompt: null,
isOpen: false,
proceed: null,
cancel: null
});
const confirm = (prompt) => new Promise((resolve, reject) => {
setState({
prompt,
isOpen: true,
proceed: resolve,
cancel: reject
});
}).then(
() => {
setState({ ...state, isOpen: false });
return true;
},
() => {
setState({ ...state, isOpen: false });
return false;
}
);
return { ...state, confirm };
};
var ConfirmContext = (0, import_react6.createContext)(void 0);
var useConfirm = () => {
const ctxt = (0, import_react6.useContext)(ConfirmContext);
if (!ctxt) {
throw new Error(
"useConfirm returned `undefined`, maybe you forgot to wrap the component within <ConfirmProvider />?"
);
}
return ctxt;
};
var ConfirmProvider = ({ children }) => {
const value = useConfirmProvider();
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(ConfirmContext.Provider, { value, children: [
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ConfirmModal, {}),
children
] });
};
// src/components/layout/ConfirmModal/ConfirmModal.tsx
var import_jsx_runtime4 = require("react/jsx-runtime");
var ConfirmModal = () => {
const styles = (0, import_react7.useMultiStyleConfig)("ConfirmModal");
const { prompt, isOpen, cancel } = useConfirm();
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react7.Modal, { isOpen, onClose: cancel, children: [
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react7.ModalOverlay, { sx: styles.overlay }),
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react7.ModalContent, { sx: styles.content, children: prompt })
] });
};
// src/components/layout/HR.tsx
var import_react8 = require("@chakra-ui/react");
var import_jsx_runtime5 = require("react/jsx-runtime");
var HR = (props) => {
const { variant, ...rest } = props;
const styles = (0, import_react8.useStyleConfig)("HorizontalRuler", { variant });
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react8.chakra.div, { __css: styles, ...rest, as: "hr" });
};
HR.displayName = "HorizontalRuler";
// src/components/layout/Image.tsx
var import_react9 = require("@chakra-ui/react");
var import_jsx_runtime6 = require("react/jsx-runtime");
var linkify = (link, gateway) => {
if (typeof link === "undefined") {
return;
}
if (!link.startsWith("ipfs")) {
return link;
}
const matches = link.match(/(?:ipfs:\/\/)?(.*)/);
if (!matches) {
return link;
}
const [, pin] = matches;
return gateway + pin;
};
var Image = ({ src, ...props }) => {
if (!src && !props.fallbackSrc && !props.fallback) return null;
const link = linkify(src, props.gateway || "https://infura-ipfs.io/ipfs/");
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react9.Image, { src: link, ...props });
};
var Avatar = ({ src, ...props }) => {
if (!src) return null;
const link = linkify(src, props.gateway || "https://infura-ipfs.io/ipfs/");
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react9.Avatar, { src: link, ...props });
};
// src/components/layout/Markdown.tsx
var import_react10 = require("@chakra-ui/react");
var import_react_markdown = __toESM(require("react-markdown"), 1);
var import_remark_gfm = __toESM(require("remark-gfm"), 1);
var import_jsx_runtime7 = require("react/jsx-runtime");
var MD = ({ children, ...rest }) => {
if (!children) {
return null;
}
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
import_react_markdown.default,
{
remarkPlugins: [import_remark_gfm.default],
components: {
a: ({ node, children: children2, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react10.Link, { ...props, target: "_blank", children: children2 }),
h1: ({ node, children: children2, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react10.Heading, { size: "lg", mt: 5, mb: 4, ...props, children: children2 }),
h2: ({ node, children: children2, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react10.Heading, { size: "md", mt: 5, mb: 4, ...props, children: children2 }),
h3: ({ node, children: children2, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react10.Heading, { as: "h3", size: "sm", mt: 5, mb: 4, ...props, children: children2 }),
ol: ({ node, children: children2, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react10.OrderedList, { ...props, children: children2 }),
ul: ({ node, children: children2, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react10.UnorderedList, { ...props, children: children2 }),
li: ({ node, children: children2, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react10.ListItem, { ...props, children: children2 }),
p: ({ node, children: children2, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react10.Text, { fontWeight: "medium", mb: 4, children: children2 }),
table: ({ node, children: children2, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react10.Box, { overflowX: "auto", maxW: "full", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react10.Table, { ...props, children: children2 }) }),
tr: ({ node, children: children2, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react10.Tr, { ...props, children: children2 }),
code: ({ node, children: children2, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react10.Code, { ...props, children: children2 })
},
...rest,
children
}
);
};
var Markdown = (0, import_react10.chakra)(MD);
Markdown.displayName = "Markdown";
// src/components/Election/Actions/ConfirmActionModal.tsx
var import_react11 = require("@chakra-ui/react");
var import_react_providers4 = require("@vocdoni/react-providers");
var import_jsx_runtime8 = require("react/jsx-runtime");
var ConfirmActionModal = ({ title, description, confirm, cancel, ...rest }) => {
const mstyles = (0, import_react11.useMultiStyleConfig)("ConfirmModal");
const styles = (0, import_react11.useMultiStyleConfig)("QuestionsConfirmation", rest);
const { cancel: cancelFn, proceed } = useConfirm();
const { localize: localize2 } = (0, import_react_providers4.useClient)();
const _confirm = confirm || localize2("actions.confirm");
const _cancel = cancel || localize2("actions.cancel");
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react11.ModalHeader, { sx: mstyles.header, children: title }),
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react11.ModalCloseButton, { sx: mstyles.close }),
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react11.ModalBody, { sx: mstyles.body, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react11.Text, { sx: styles.description, children: description }) }),
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_react11.ModalFooter, { sx: mstyles.footer, children: [
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react11.Button, { onClick: cancelFn, variant: "ghost", sx: mstyles.cancel, children: _cancel }),
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react11.Button, { onClick: proceed, sx: mstyles.confirm, children: _confirm })
] })
] });
};
// src/components/Election/Actions/Cancel.tsx
var import_jsx_runtime9 = require("react/jsx-runtime");
var ActionCancel = (0, import_react12.forwardRef)((props, ref) => {
const { account, localize: localize2 } = (0, import_react_providers5.useClient)();
const { confirm } = useConfirm();
const { election } = (0, import_react_providers5.useElection)();
const {
cancel,
disabled,
loading: { cancel: loading }
} = (0, import_react_providers5.useActions)();
const handle = async () => {
if (await confirm(
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
ConfirmActionModal,
{
title: localize2("confirm.cancel_process_title"),
description: localize2("actions.cancel_description", {
election
}),
confirm: localize2("confirm.cancel_process_button"),
cancel: localize2("confirm.cancel_button")
}
)
)) {
await cancel();
}
};
if (!election || !(election instanceof import_sdk.PublishedElection) || !(0, import_sdk.areEqualHexStrings)(election.organizationId, account?.address)) {
return null;
}
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
import_react12.Button,
{
ref,
isLoading: loading,
onClick: handle,
isDisabled: disabled || [import_sdk.ElectionStatus.CANCELED, import_sdk.ElectionStatus.ENDED, import_sdk.ElectionStatus.RESULTS].includes(election.status),
children: localize2("actions.cancel"),
shouldWrapChildren: true,
...props
}
);
});
// src/components/Election/Actions/Continue.tsx
var import_react13 = require("@chakra-ui/react");
var import_react_providers6 = require("@vocdoni/react-providers");
var import_sdk2 = require("@vocdoni/sdk");
var import_jsx_runtime10 = require("react/jsx-runtime");
var ActionContinue = (0, import_react13.forwardRef)((props, ref) => {
const { account, localize: localize2 } = (0, import_react_providers6.useClient)();
const { election } = (0, import_react_providers6.useElection)();
const {
resume,
disabled,
loading: { continue: loading }
} = (0, import_react_providers6.useActions)();
if (!election || !(election instanceof import_sdk2.PublishedElection) || !(0, import_sdk2.areEqualHexStrings)(election.organizationId, account?.address)) {
return null;
}
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
import_react13.Button,
{
ref,
isLoading: loading,
onClick: resume,
isDisabled: disabled || election.status !== import_sdk2.ElectionStatus.PAUSED,
children: localize2("actions.continue"),
shouldWrapChildren: true,
...props
}
);
});
// src/components/Election/Actions/End.tsx
var import_react14 = require("@chakra-ui/react");
var import_react_providers7 = require("@vocdoni/react-providers");
var import_sdk3 = require("@vocdoni/sdk");
var import_jsx_runtime11 = require("react/jsx-runtime");
var ActionEnd = (0, import_react14.forwardRef)((props, ref) => {
const { account, localize: localize2 } = (0, import_react_providers7.useClient)();
const { confirm } = useConfirm();
const { election } = (0, import_react_providers7.useElection)();
const {
end,
loading: { end: loading },
disabled
} = (0, import_react_providers7.useActions)();
const handle = async () => {
if (await confirm(
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
ConfirmActionModal,
{
title: localize2("confirm.end_process_title"),
description: localize2("actions.end_description", {
election
}),
confirm: localize2("confirm.end_process_button"),
cancel: localize2("confirm.cancel_button")
}
)
)) {
await end();
}
};
if (!election || !(election instanceof import_sdk3.PublishedElection) || !(0, import_sdk3.areEqualHexStrings)(election.organizationId, account?.address)) {
return null;
}
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
import_react14.Button,
{
ref,
isLoading: loading,
onClick: handle,
isDisabled: disabled || [import_sdk3.ElectionStatus.RESULTS, import_sdk3.ElectionStatus.ENDED, import_sdk3.ElectionStatus.CANCELED, import_sdk3.ElectionStatus.UPCOMING].includes(
election.status
),
children: localize2("actions.end"),
shouldWrapChildren: true,
...props
}
);
});
// src/components/Election/Actions/Pause.tsx
var import_react15 = require("@chakra-ui/react");
var import_react_providers8 = require("@vocdoni/react-providers");
var import_sdk4 = require("@vocdoni/sdk");
var import_jsx_runtime12 = require("react/jsx-runtime");
var ActionPause = (0, import_react15.forwardRef)((props, ref) => {
const { account, localize: localize2 } = (0, import_react_providers8.useClient)();
const { election } = (0, import_react_providers8.useElection)();
const {
pause,
disabled,
loading: { pause: loading }
} = (0, import_react_providers8.useActions)();
if (!election || !(election instanceof import_sdk4.PublishedElection) || !(0, import_sdk4.areEqualHexStrings)(election.organizationId, account?.address))
return null;
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
import_react15.Button,
{
ref,
isLoading: loading,
onClick: pause,
isDisabled: disabled || election?.status !== import_sdk4.ElectionStatus.ONGOING,
children: localize2("actions.pause"),
shouldWrapChildren: true,
...props
}
);
});
// src/components/Election/Actions/Actions.tsx
var import_jsx_runtime13 = require("react/jsx-runtime");
var Cancel = (0, import_react16.chakra)(ImCross);
var Play = (0, import_react16.chakra)(FaPlay);
var Pause = (0, import_react16.chakra)(FaPause);
var Stop = (0, import_react16.chakra)(FaStop);
var ElectionActions = (props) => {
const { localize: localize2, account } = (0, import_react_providers9.useClient)();
const { election } = (0, import_react_providers9.useElection)();
const styles = (0, import_react16.useMultiStyleConfig)("ElectionActions");
if (!election || !(election instanceof import_sdk5.PublishedElection) || election && !(0, import_sdk5.areEqualHexStrings)(election.organizationId, account?.address) || [import_sdk5.ElectionStatus.CANCELED, import_sdk5.ElectionStatus.ENDED, import_sdk5.ElectionStatus.RESULTS].includes(election.status)) {
return null;
}
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_react16.ButtonGroup, { size: "sm", isAttached: true, variant: "outline", position: "relative", sx: styles.group, ...props, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(ActionsProvider, { children: [
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
ActionContinue,
{
as: import_react16.IconButton,
"aria-label": localize2("actions.continue"),
title: localize2("actions.continue"),
sx: styles.buttons,
icon: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Play, { sx: styles.icons })
}
),
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
ActionPause,
{
as: import_react16.IconButton,
"aria-label": localize2("actions.pause"),
title: localize2("actions.pause"),
sx: styles.buttons,
icon: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Pause, { sx: styles.icons })
}
),
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
ActionEnd,
{
as: import_react16.IconButton,
"aria-label": localize2("actions.end"),
title: localize2("actions.end"),
sx: styles.buttons,
icon: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Stop, { sx: styles.icons })
}
),
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
ActionCancel,
{
as: import_react16.IconButton,
"aria-label": localize2("actions.cancel"),
title: localize2("actions.cancel"),
sx: styles.buttons,
icon: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Cancel, { sx: styles.icons })
}
)
] }) });
};
// src/components/Election/Description.tsx
var import_react17 = require("@chakra-ui/react");
var import_react_providers10 = require("@vocdoni/react-providers");
var import_sdk6 = require("@vocdoni/sdk");
var import_jsx_runtime14 = require("react/jsx-runtime");
var ElectionDescription = (props) => {
const styles = (0, import_react17.useStyleConfig)("ElectionDescription", props);
const { election } = (0, import_react_providers10.useElection)();
if (!election || !(election instanceof import_sdk6.PublishedElection) || !election.description) {
return null;
}
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Markdown, { ...props, sx: styles, children: election.description.default });
};
ElectionDescription.displayName = "ElectionDescription";
// src/components/Election/Election.tsx
var import_react21 = require("@chakra-ui/react");
var import_react_providers12 = require("@vocdoni/react-providers");
var import_sdk8 = require("@vocdoni/sdk");
// src/components/Election/SpreadsheetAccess.tsx
var import_react19 = require("@chakra-ui/react");
var import_wallet = require("@ethersproject/wallet");
var import_react_providers11 = require("@vocdoni/react-providers");
var import_sdk7 = require("@vocdoni/sdk");
var import_react20 = require("react");
// ../../node_modules/react-hook-form/dist/index.esm.mjs
var import_react18 = __toESM(require("react"), 1);
var isCheckBoxInput = (element) => element.type === "checkbox";
var isDateObject = (value) => value instanceof Date;
var isNullOrUndefined = (value) => value == null;
var isObjectType = (value) => typeof value === "object";
var isObject2 = (value) => !isNullOrUndefined(value) && !Array.isArray(value) && isObjectType(value) && !isDateObject(value);
var getEventValue = (event) => isObject2(event) && event.target ? isCheckBoxInput(event.target) ? event.target.checked : event.target.value : event;
var getNodeParentName = (name) => name.substring(0, name.search(/\.\d+(\.|$)/)) || name;
var isNameInFieldArray = (names, name) => names.has(getNodeParentName(name));
var isPlainObject = (tempObject) => {
const prototypeCopy = tempObject.constructor && tempObject.constructor.prototype;
return isObject2(prototypeCopy) && prototypeCopy.hasOwnProperty("isPrototypeOf");
};
var isWeb = typeof window !== "undefined" && typeof window.HTMLElement !== "undefined" && typeof document !== "undefined";
function cloneObject(data) {
let copy;
const isArray = Array.isArray(data);
const isFileListInstance = typeof FileList !== "undefined" ? data instanceof FileList : false;
if (data instanceof Date) {
copy = new Date(data);
} else if (!(isWeb && (data instanceof Blob || isFileListInstance)) && (isArray || isObject2(data))) {
copy = isArray ? [] : Object.create(Object.getPrototypeOf(data));
if (!isArray && !isPlainObject(data)) {
copy = data;
} else {
for (const key in data) {
if (data.hasOwnProperty(key)) {
copy[key] = cloneObject(data[key]);
}
}
}
} else {
return data;
}
return copy;
}
var isKey = (value) => /^\w*$/.test(value);
var isUndefined = (val) => val === void 0;
var compact = (value) => Array.isArray(value) ? value.filter(Boolean) : [];
var stringToPath = (input) => compact(input.replace(/["|']|\]/g, "").split(/\.|\[/));
var get = (object, path, defaultValue) => {
if (!path || !isObject2(object)) {
return defaultValue;
}
const result = (isKey(path) ? [path] : stringToPath(path)).reduce((result2, key) => isNullOrUndefined(result2) ? result2 : result2[key], object);
return isUndefined(result) || result === object ? isUndefined(object[path]) ? defaultValue : object[path] : result;
};
var isBoolean = (value) => typeof value === "boolean";
var set = (object, path, value) => {
let index = -1;
const tempPath = isKey(path) ? [path] : stringToPath(path);
const length = tempPath.length;
const lastIndex = length - 1;
while (++index < length) {
const key = tempPath[index];
let newValue = value;
if (index !== lastIndex) {
const objValue = object[key];
newValue = isObject2(objValue) || Array.isArray(objValue) ? objValue : !isNaN(+tempPath[index + 1]) ? [] : {};
}
if (key === "__proto__" || key === "constructor" || key === "prototype") {
return;
}
object[key] = newValue;
object = object[key];
}
};
var EVENTS = {
BLUR: "blur",
FOCUS_OUT: "focusout",
CHANGE: "change"
};
var VALIDATION_MODE = {
onBlur: "onBlur",
onChange: "onChange",
onSubmit: "onSubmit",
onTouched: "onTouched",
all: "all"
};
var INPUT_VALIDATION_RULES = {
max: "max",
min: "min",
maxLength: "maxLength",
minLength: "minLength",
pattern: "pattern",
required: "required",
validate: "validate"
};
var HookFormContext = import_react18.default.createContext(null);
HookFormContext.displayName = "HookFormContext";
var useFormContext = () => import_react18.default.useContext(HookFormContext);
var FormProvider = (props) => {
const { children, ...data } = props;
return import_react18.default.createElement(HookFormContext.Provider, { value: data }, children);
};
var getProxyFormState = (formState, control, localProxyFormState, isRoot = true) => {
const result = {
defaultValues: control._defaultValues
};
for (const key in formState) {
Object.defineProperty(result, key, {
get: () => {
const _key = key;
if (control._proxyFormState[_key] !== VALIDATION_MODE.all) {
control._proxyFormState[_key] = !isRoot || VALIDATION_MODE.all;
}
localProxyFormState && (localProxyFormState[_key] = true);
return formState[_key];
}
});
}
return result;
};
var useIsomorphicLayoutEffect = typeof window !== "undefined" ? import_react18.default.useLayoutEffect : import_react18.default.useEffect;
function useFormState(props) {
const methods = useFormContext();
const { control = methods.control, disabled, name, exact } = props || {};
const [formState, updateFormState] = import_react18.default.useState(control._formState);
const _localProxyFormState = import_react18.default.useRef({
isDirty: false,
isLoading: false,
dirtyFields: false,
touchedFields: false,
validatingFields: false,
isValidating: false,
isValid: false,
errors: false
});
useIsomorphicLayoutEffect(() => control._subscribe({
name,
formState: _localProxyFormState.current,
exact,
callback: (formState2) => {
!disabled && updateFormState({
...control._formState,
...formState2
});
}
}), [name, disabled, exact]);
import_react18.default.useEffect(() => {
_localProxyFormState.current.isValid && control._setValid(true);
}, [control]);
return import_react18.default.useMemo(() => getProxyFormState(formState, control, _localProxyFormState.current, false), [formState, control]);
}
var isString = (value) => typeof value === "string";
var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) => {
if (isString(names)) {
isGlobal && _names.watch.add(names);
return get(formValues, names, defaultValue);
}
if (Array.isArray(names)) {
return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName), get(formValues, fieldName)));
}
isGlobal && (_names.watchAll = true);
return formValues;
};
var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
function deepEqual(object1, object2, _internal_visited = /* @__PURE__ */ new WeakSet()) {
if (isPrimitive(object1) || isPrimitive(object2)) {
return object1 === object2;
}
if (isDateObject(object1) && isDateObject(object2)) {
return object1.getTime() === object2.getTime();
}
const keys1 = Object.keys(object1);
const keys2 = Object.keys(object2);
if (keys1.length !== keys2.length) {
return false;
}
if (_internal_visited.has(object1) || _internal_visited.has(object2)) {
return true;
}
_internal_visited.add(object1);
_internal_visited.add(object2);
for (const key of keys1) {
const val1 = object1[key];
if (!keys2.includes(key)) {
return false;
}
if (key !== "ref") {
const val2 = object2[key];
if (isDateObject(val1) && isDateObject(val2) || isObject2(val1) && isObject2(val2) || Array.isArray(val1) && Array.isArray(val2) ? !deepEqual(val1, val2, _internal_visited) : val1 !== val2) {
return false;
}
}
}
return true;
}
function useWatch(props) {
const methods = useFormContext();
const { control = methods.control, name, defaultValue, disabled, exact, compute } = props || {};
const _defaultValue = import_react18.default.useRef(defaultValue);
const _compute = import_react18.default.useRef(compute);
const _computeFormValues = import_react18.default.useRef(void 0);
_compute.current = compute;
const defaultValueMemo = import_react18.default.useMemo(() => control._getWatch(name, _defaultValue.current), [control, name]);
const [value, updateValue] = import_react18.default.useState(_compute.current ? _compute.current(defaultValueMemo) : defaultValueMemo);
useIsomorphicLayoutEffect(() => control._subscribe({
name,
formState: {
values: true
},
exact,
callback: (formState) => {
if (!disabled) {
const formValues = generateWatchOutput(name, control._names, formState.values || control._formValues, false, _defaultValue.current);
if (_compute.current) {
const computedFormValues = _compute.current(formValues);
if (!deepEqual(computedFormValues, _computeFormValues.current)) {
updateValue(computedFormValues);
_computeFormValues.current = computedFormValues;
}
} else {
updateValue(formValues);
}
}
}
}), [control, disabled, name, exact]);
import_react18.default.useEffect(() => control._removeUnmounted());
return value;
}
function useController(props) {
const methods = useFormContext();
const { name, disabled, control = methods.control, shouldUnregister, defaultValue } = props;
const isArrayField = isNameInFieldArray(control._names.array, name);
const defaultValueMemo = import_react18.default.useMemo(() => get(control._formValues, name, get(control._defaultValues, name, defaultValue)), [control, name, defaultValue]);
const value = useWatch({
control,
name,
defaultValue: defaultValueMemo,
exact: true
});
const formState = useFormState({
control,
name,
exact: true
});
const _props = import_react18.default.useRef(props);
const _registerProps = import_react18.default.useRef(control.register(name, {
...props.rules,
value,
...isBoolean(props.disabled) ? { disabled: props.disabled } : {}
}));
_props.current = props;
const fieldState = import_react18.default.useMemo(() => Object.defineProperties({}, {
invalid: {
enumerable: true,
get: () => !!get(formState.errors, name)
},
isDirty: {
enumerable: true,
get: () => !!get(formState.dirtyFields, name)
},
isTouched: {
enumerable: true,
get: () => !!get(formState.touchedFields, name)
},
isValidating: {
enumerable: true,
get: () => !!get(formState.validatingFields, name)
},
error: {
enumerable: true,
get: () => get(formState.errors, name)
}
}), [formState, name]);
const onChange = import_react18.default.useCallback((event) => _registerProps.current.onChange({
target: {
value: getEventValue(event),
name
},
type: EVENTS.CHANGE
}), [name]);
const onBlur = import_react18.default.useCallback(() => _registerProps.current.onBlur({
target: {
value: get(control._formValues, name),
name
},
type: EVENTS.BLUR
}), [name, control._formValues]);
const ref = import_react18.default.useCallback((elm) => {
const field2 = get(control._fields, name);
if (field2 && elm) {
field2._f.ref = {
focus: () => elm.focus && elm.focus(),
select: () => elm.select && elm.select(),
setCustomValidity: (message) => elm.setCustomValidity(message),
reportValidity: () => elm.reportValidity()
};
}
}, [control._fields, name]);
const field = import_react18.default.useMemo(() => ({
name,
value,
...isBoolean(disabled) || formState.disabled ? { disabled: formState.disabled || disabled } : {},
onChange,
onBlur,
ref
}), [name, disabled, formState.disabled, onChange, onBlur, ref, value]);
import_react18.default.useEffect(() => {
const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
control.register(name, {
..._props.current.rules,
...isBoolean(_props.current.disabled) ? { disabled: _props.current.disabled } : {}
});
const updateMounted = (name2, value2) => {
const field2 = get(control._fields, name2);
if (field2 && field2._f) {
field2._f.mount = value2;
}
};
updateMounted(name, true);
if (_shouldUnregisterField) {
const value2 = cloneObject(get(control._options.defaultValues, name));
set(control._defaultValues, name, value2);
if (isUndefined(get(control._formValues, name))) {
set(control._formValues, name, value2);
}
}
!isArrayField && control.register(name);
return () => {
(isArrayField ? _shouldUnregisterField && !control._state.action : _shouldUnregisterField) ? control.unregister(name) : updateMounted(name, false);
};
}, [name, control, isArrayField, shouldUnregister]);
import_react18.default.useEffect(() => {
control._setDisabledField({
disabled,
name
});
}, [disabled, name, control]);
return import_react18.default.useMemo(() => ({
field,
formState,
fieldState
}), [field, formState, fieldState]);
}
var Controller = (props) => props.render(useController(props));
var appendErrors = (name, validateAllFieldCriteria, errors, type, message) => validateAllFieldCriteria ? {
...errors[name],
types: {
...errors[name] && errors[name].types ? errors[name].types : {},
[type]: message || true
}
} : {};
var convertToArrayPayload = (value) => Array.isArray(value) ? value : [value];
var createSubject = () => {
let _observers = [];
const next = (value) => {
for (const observer of _observers) {
observer.next && observer.next(value);
}
};
const subscribe = (observer) => {
_observers.push(observer);
return {
unsubscribe: () => {
_observers = _observers.filter((o) => o !== observer);
}
};
};
const unsubscribe = () => {
_observers = [];
};
return {
get observers() {
return _observers;
},
next,
subscribe,
unsubscribe
};
};
var isEmptyObject = (value) => isObject2(value) && !Object.keys(value).length;
var isFileInput = (element) => element.type === "file";
var isFunction = (value) => typeof value === "function";
var isHTMLElement = (value) => {
if (!isWeb) {
return false;
}
const owner = value ? value.ownerDocument : 0;
return value instanceof (owner && owner.defaultView ? owner.defaultView.HTMLElement : HTMLElement);
};
var isMultipleSelect = (element) => element.type === `select-multiple`;
var isRadioInput = (element) => element.type === "radio";
var isRadioOrCheckbox = (ref) => isRadioInput(ref) || isCheckBoxInput(ref);
var live = (ref) => isHTMLElement(ref) && ref.isConnected;
function baseGet(object, updatePath) {
const length = updatePath.slice(0, -1).length;
let index = 0;
while (index < length) {
object = isUndefined(object) ? index++ : object[updatePath[index++]];
}
return object;
}
function isEmptyArray(obj) {
for (const key in obj) {
if (obj.hasOwnProperty(key) && !isUndefined(obj[key])) {
return false;
}
}
return true;
}
function unset(object, path) {
const paths = Array.isArray(path) ? path : isKey(path) ? [path] : stringToPath(path);
const childObject = paths.length === 1 ? object : baseGet(object, paths);
const index = paths.length - 1;
const key = paths[index];
if (childObject) {
delete childObject[key];
}
if (index !== 0 && (isObject2(childObject) && isEmptyObject(childObject) || Array.isArray(childObject) && isEmptyArray(childObject))) {
unset(object, paths.slice(0, -1));
}
return object;
}
var objectHasFunction = (data) => {
for (const key in data) {
if (isFunction(data[key])) {
return true;
}
}
return false;
};
function markFieldsDirty(data, fields = {}) {
const isParentNodeArray = Array.isArray(data);
if (isObject2(data) || isParentNodeArray) {
for (const key in data) {
if (Array.isArray(data[key]) || isObject2(data[key]) && !objectHasFunction(data[key])) {
fields[key] = Array.isArray(data[key]) ? [] : {};
markFieldsDirty(data[key], fields[key]);
} else if (!isNullOrUndefined(data[key])) {
fields[key] = true;
}
}
}
return fields;
}
function getDirtyFieldsFromDefaultValues(data, formValues, dirtyFieldsFromValues) {
const isParentNodeArray = Array.isArray(data);
if (isObject2(data) || isParentNodeArray) {
for (const key in data) {
if (Array.isArray(data[key]) || isObject2(data[key]) && !objectHasFunction(data[key])) {
if (isUndefined(formValues) || isPrimitive(dirtyFieldsFromValues[key])) {
dirtyFieldsFromValues[key] = Array.isArray(data[key]) ? markFieldsDirty(data[key], []) : { ...markFieldsDirty(data[key]) };
} else {
getDirtyFieldsFromDefaultValues(data[key], isNullOrUndefined