@gorgo/medusa-integration 0.0.1
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/.medusa/server/src/admin/index.js +2259 -0
- package/.medusa/server/src/admin/index.mjs +2257 -0
- package/.medusa/server/src/api/admin/integrations/[provider_id]/enable/route.d.ts +5 -0
- package/.medusa/server/src/api/admin/integrations/[provider_id]/enable/route.js +17 -0
- package/.medusa/server/src/api/admin/integrations/[provider_id]/route.d.ts +7 -0
- package/.medusa/server/src/api/admin/integrations/[provider_id]/route.js +46 -0
- package/.medusa/server/src/api/admin/integrations/[provider_id]/test-connection/route.d.ts +3 -0
- package/.medusa/server/src/api/admin/integrations/[provider_id]/test-connection/route.js +16 -0
- package/.medusa/server/src/api/admin/integrations/_helpers.d.ts +16 -0
- package/.medusa/server/src/api/admin/integrations/_helpers.js +52 -0
- package/.medusa/server/src/api/admin/integrations/middlewares.d.ts +2 -0
- package/.medusa/server/src/api/admin/integrations/middlewares.js +21 -0
- package/.medusa/server/src/api/admin/integrations/route.d.ts +3 -0
- package/.medusa/server/src/api/admin/integrations/route.js +11 -0
- package/.medusa/server/src/api/admin/integrations/validators.d.ts +11 -0
- package/.medusa/server/src/api/admin/integrations/validators.js +15 -0
- package/.medusa/server/src/api/middlewares.d.ts +2 -0
- package/.medusa/server/src/api/middlewares.js +10 -0
- package/.medusa/server/src/index.d.ts +10 -0
- package/.medusa/server/src/index.js +22 -0
- package/.medusa/server/src/jobs/test-integration-connections.d.ts +16 -0
- package/.medusa/server/src/jobs/test-integration-connections.js +53 -0
- package/.medusa/server/src/modules/integration/descriptor/__tests__/build-zod.unit.spec.d.ts +1 -0
- package/.medusa/server/src/modules/integration/descriptor/__tests__/build-zod.unit.spec.js +64 -0
- package/.medusa/server/src/modules/integration/descriptor/__tests__/define.unit.spec.d.ts +1 -0
- package/.medusa/server/src/modules/integration/descriptor/__tests__/define.unit.spec.js +41 -0
- package/.medusa/server/src/modules/integration/descriptor/__tests__/introspect.unit.spec.d.ts +1 -0
- package/.medusa/server/src/modules/integration/descriptor/__tests__/introspect.unit.spec.js +93 -0
- package/.medusa/server/src/modules/integration/descriptor/__tests__/validate.unit.spec.d.ts +1 -0
- package/.medusa/server/src/modules/integration/descriptor/__tests__/validate.unit.spec.js +64 -0
- package/.medusa/server/src/modules/integration/descriptor/build-zod.d.ts +8 -0
- package/.medusa/server/src/modules/integration/descriptor/build-zod.js +82 -0
- package/.medusa/server/src/modules/integration/descriptor/define.d.ts +74 -0
- package/.medusa/server/src/modules/integration/descriptor/define.js +31 -0
- package/.medusa/server/src/modules/integration/descriptor/index.d.ts +5 -0
- package/.medusa/server/src/modules/integration/descriptor/index.js +22 -0
- package/.medusa/server/src/modules/integration/descriptor/introspect.d.ts +5 -0
- package/.medusa/server/src/modules/integration/descriptor/introspect.js +67 -0
- package/.medusa/server/src/modules/integration/descriptor/meta.d.ts +7 -0
- package/.medusa/server/src/modules/integration/descriptor/meta.js +3 -0
- package/.medusa/server/src/modules/integration/descriptor/option.d.ts +104 -0
- package/.medusa/server/src/modules/integration/descriptor/option.js +3 -0
- package/.medusa/server/src/modules/integration/descriptor/validate.d.ts +29 -0
- package/.medusa/server/src/modules/integration/descriptor/validate.js +69 -0
- package/.medusa/server/src/modules/integration/index.d.ts +22 -0
- package/.medusa/server/src/modules/integration/index.js +15 -0
- package/.medusa/server/src/modules/integration/loaders/index.d.ts +1 -0
- package/.medusa/server/src/modules/integration/loaders/index.js +9 -0
- package/.medusa/server/src/modules/integration/loaders/load-providers.d.ts +5 -0
- package/.medusa/server/src/modules/integration/loaders/load-providers.js +35 -0
- package/.medusa/server/src/modules/integration/migrations/Migration20260610215533.d.ts +5 -0
- package/.medusa/server/src/modules/integration/migrations/Migration20260610215533.js +18 -0
- package/.medusa/server/src/modules/integration/migrations/Migration20260618154037.d.ts +5 -0
- package/.medusa/server/src/modules/integration/migrations/Migration20260618154037.js +27 -0
- package/.medusa/server/src/modules/integration/migrations/Migration20260622120502.d.ts +5 -0
- package/.medusa/server/src/modules/integration/migrations/Migration20260622120502.js +14 -0
- package/.medusa/server/src/modules/integration/migrations/Migration20260701095518.d.ts +5 -0
- package/.medusa/server/src/modules/integration/migrations/Migration20260701095518.js +14 -0
- package/.medusa/server/src/modules/integration/migrations/Migration20260708072033.d.ts +5 -0
- package/.medusa/server/src/modules/integration/migrations/Migration20260708072033.js +14 -0
- package/.medusa/server/src/modules/integration/models/integration.d.ts +13 -0
- package/.medusa/server/src/modules/integration/models/integration.js +27 -0
- package/.medusa/server/src/modules/integration/services/__tests__/crypto.unit.spec.d.ts +1 -0
- package/.medusa/server/src/modules/integration/services/__tests__/crypto.unit.spec.js +33 -0
- package/.medusa/server/src/modules/integration/services/__tests__/integration-provider.unit.spec.d.ts +1 -0
- package/.medusa/server/src/modules/integration/services/__tests__/integration-provider.unit.spec.js +77 -0
- package/.medusa/server/src/modules/integration/services/__tests__/secrets.unit.spec.d.ts +1 -0
- package/.medusa/server/src/modules/integration/services/__tests__/secrets.unit.spec.js +33 -0
- package/.medusa/server/src/modules/integration/services/crypto.d.ts +10 -0
- package/.medusa/server/src/modules/integration/services/crypto.js +41 -0
- package/.medusa/server/src/modules/integration/services/index.d.ts +3 -0
- package/.medusa/server/src/modules/integration/services/index.js +11 -0
- package/.medusa/server/src/modules/integration/services/integration-module.d.ts +113 -0
- package/.medusa/server/src/modules/integration/services/integration-module.js +219 -0
- package/.medusa/server/src/modules/integration/services/integration-provider.d.ts +49 -0
- package/.medusa/server/src/modules/integration/services/integration-provider.js +76 -0
- package/.medusa/server/src/modules/integration/services/secrets.d.ts +11 -0
- package/.medusa/server/src/modules/integration/services/secrets.js +31 -0
- package/.medusa/server/src/modules/integration/types/index.d.ts +13 -0
- package/.medusa/server/src/modules/integration/types/index.js +10 -0
- package/.medusa/server/src/modules/integration/utils/abstract-integration-provider.d.ts +39 -0
- package/.medusa/server/src/modules/integration/utils/abstract-integration-provider.js +42 -0
- package/.medusa/server/src/modules/integration/utils/index.d.ts +1 -0
- package/.medusa/server/src/modules/integration/utils/index.js +6 -0
- package/.medusa/server/src/subscribers/invalidate-options-cache.d.ts +5 -0
- package/.medusa/server/src/subscribers/invalidate-options-cache.js +13 -0
- package/.medusa/server/src/types/bundles.d.ts +1 -0
- package/.medusa/server/src/types/bundles.js +38 -0
- package/.medusa/server/src/types/http/index.d.ts +1 -0
- package/.medusa/server/src/types/http/index.js +18 -0
- package/.medusa/server/src/types/http/integration/admin/entities.d.ts +32 -0
- package/.medusa/server/src/types/http/integration/admin/entities.js +3 -0
- package/.medusa/server/src/types/http/integration/admin/index.d.ts +2 -0
- package/.medusa/server/src/types/http/integration/admin/index.js +19 -0
- package/.medusa/server/src/types/http/integration/admin/responses.d.ts +19 -0
- package/.medusa/server/src/types/http/integration/admin/responses.js +3 -0
- package/.medusa/server/src/types/http/integration/index.d.ts +1 -0
- package/.medusa/server/src/types/http/integration/index.js +18 -0
- package/.medusa/server/src/types/index.d.ts +3 -0
- package/.medusa/server/src/types/index.js +20 -0
- package/.medusa/server/src/types/integration/common.d.ts +70 -0
- package/.medusa/server/src/types/integration/common.js +3 -0
- package/.medusa/server/src/types/integration/index.d.ts +1 -0
- package/.medusa/server/src/types/integration/index.js +18 -0
- package/.medusa/server/src/workflows/integration/index.d.ts +2 -0
- package/.medusa/server/src/workflows/integration/index.js +19 -0
- package/.medusa/server/src/workflows/integration/steps/apply-integration-section.d.ts +22 -0
- package/.medusa/server/src/workflows/integration/steps/apply-integration-section.js +70 -0
- package/.medusa/server/src/workflows/integration/steps/delete-integration-record.d.ts +6 -0
- package/.medusa/server/src/workflows/integration/steps/delete-integration-record.js +16 -0
- package/.medusa/server/src/workflows/integration/steps/emit-integration-event.d.ts +5 -0
- package/.medusa/server/src/workflows/integration/steps/emit-integration-event.js +11 -0
- package/.medusa/server/src/workflows/integration/steps/index.d.ts +6 -0
- package/.medusa/server/src/workflows/integration/steps/index.js +16 -0
- package/.medusa/server/src/workflows/integration/steps/run-test-connection.d.ts +4 -0
- package/.medusa/server/src/workflows/integration/steps/run-test-connection.js +20 -0
- package/.medusa/server/src/workflows/integration/steps/set-integration-enabled.d.ts +19 -0
- package/.medusa/server/src/workflows/integration/steps/set-integration-enabled.js +27 -0
- package/.medusa/server/src/workflows/integration/steps/upsert-integration-record.d.ts +9 -0
- package/.medusa/server/src/workflows/integration/steps/upsert-integration-record.js +18 -0
- package/.medusa/server/src/workflows/integration/workflows/delete-integration.d.ts +7 -0
- package/.medusa/server/src/workflows/integration/workflows/delete-integration.js +18 -0
- package/.medusa/server/src/workflows/integration/workflows/index.d.ts +4 -0
- package/.medusa/server/src/workflows/integration/workflows/index.js +12 -0
- package/.medusa/server/src/workflows/integration/workflows/set-integration-enabled.d.ts +20 -0
- package/.medusa/server/src/workflows/integration/workflows/set-integration-enabled.js +20 -0
- package/.medusa/server/src/workflows/integration/workflows/test-integration-connection.d.ts +5 -0
- package/.medusa/server/src/workflows/integration/workflows/test-integration-connection.js +21 -0
- package/.medusa/server/src/workflows/integration/workflows/upsert-integration.d.ts +8 -0
- package/.medusa/server/src/workflows/integration/workflows/upsert-integration.js +30 -0
- package/LICENSE +21 -0
- package/README.md +46 -0
- package/package.json +79 -0
|
@@ -0,0 +1,2259 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
+
const adminSdk = require("@medusajs/admin-sdk");
|
|
4
|
+
const icons = require("@medusajs/icons");
|
|
5
|
+
const ui = require("@medusajs/ui");
|
|
6
|
+
const reactQuery = require("@tanstack/react-query");
|
|
7
|
+
const reactI18next = require("react-i18next");
|
|
8
|
+
const reactRouterDom = require("react-router-dom");
|
|
9
|
+
const Medusa = require("@medusajs/js-sdk");
|
|
10
|
+
const React = require("react");
|
|
11
|
+
const components = require("@medusajs/dashboard/components");
|
|
12
|
+
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
13
|
+
const Medusa__default = /* @__PURE__ */ _interopDefault(Medusa);
|
|
14
|
+
const React__default = /* @__PURE__ */ _interopDefault(React);
|
|
15
|
+
const sdk = new Medusa__default.default({
|
|
16
|
+
baseUrl: "/",
|
|
17
|
+
debug: false,
|
|
18
|
+
auth: {
|
|
19
|
+
type: "session"
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const IntegrationIcon = ({
|
|
23
|
+
src,
|
|
24
|
+
alt,
|
|
25
|
+
size = "base"
|
|
26
|
+
}) => {
|
|
27
|
+
const dim = size === "small" ? "h-6 w-6" : "h-8 w-8";
|
|
28
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
29
|
+
"div",
|
|
30
|
+
{
|
|
31
|
+
className: ui.clx(
|
|
32
|
+
"bg-ui-bg-component shadow-borders-base flex shrink-0 items-center justify-center overflow-hidden rounded-md",
|
|
33
|
+
dim
|
|
34
|
+
),
|
|
35
|
+
children: src ? /* @__PURE__ */ jsxRuntime.jsx("img", { src, alt, className: "h-full w-full object-cover" }) : /* @__PURE__ */ jsxRuntime.jsx(icons.PuzzleSolid, { className: "text-ui-fg-subtle" })
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
const IntegrationsPage = () => {
|
|
40
|
+
const { t } = reactI18next.useTranslation();
|
|
41
|
+
const { data, isLoading } = reactQuery.useQuery({
|
|
42
|
+
queryKey: ["integration-overview"],
|
|
43
|
+
queryFn: () => sdk.client.fetch("/admin/integrations")
|
|
44
|
+
});
|
|
45
|
+
const items = (data == null ? void 0 : data.integrations) ?? [];
|
|
46
|
+
const byModule = items.reduce((acc, i) => {
|
|
47
|
+
var _a;
|
|
48
|
+
(acc[_a = i.module] ?? (acc[_a] = [])).push(i);
|
|
49
|
+
return acc;
|
|
50
|
+
}, {});
|
|
51
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
|
|
52
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: t("integration.list.title") }) }),
|
|
53
|
+
isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center px-6 py-8", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Spinner, { className: "text-ui-fg-subtle animate-spin" }) }) : items.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: t("integration.list.empty") }) }) : Object.entries(byModule).map(([module2, group]) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-6 py-4", children: [
|
|
54
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: t(`integration.modules.${module2}`) }),
|
|
55
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-2 flex flex-col gap-2", children: group.map((i) => {
|
|
56
|
+
const configured = i.is_configured && i.is_enabled;
|
|
57
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
58
|
+
reactRouterDom.Link,
|
|
59
|
+
{
|
|
60
|
+
to: `/settings/integrations/${i.provider_id}`,
|
|
61
|
+
className: "flex items-center justify-between rounded-md border px-3 py-2 hover:bg-ui-bg-base-hover",
|
|
62
|
+
children: [
|
|
63
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
64
|
+
/* @__PURE__ */ jsxRuntime.jsx(IntegrationIcon, { src: i.icon, alt: t(i.display_name), size: "small" }),
|
|
65
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", children: t(i.display_name) }),
|
|
66
|
+
i.instance_id && /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { size: "2xsmall", color: "grey", children: i.instance_id })
|
|
67
|
+
] }),
|
|
68
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
69
|
+
i.last_test_status === "ok" && /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { color: "green", size: "2xsmall", children: t("integration.list.tested") }),
|
|
70
|
+
i.last_test_status === "fail" && /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { color: "red", size: "2xsmall", children: t("integration.list.testFailed") }),
|
|
71
|
+
i.is_configured && !i.is_complete ? /* @__PURE__ */ jsxRuntime.jsx(ui.StatusBadge, { color: "orange", children: t("integration.status.incomplete") }) : /* @__PURE__ */ jsxRuntime.jsx(ui.StatusBadge, { color: configured ? "green" : "grey", children: !i.is_configured ? t("integration.status.notConfigured") : i.is_enabled ? t("integration.status.enabled") : t("integration.status.disabled") })
|
|
72
|
+
] })
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
i.provider_id
|
|
76
|
+
);
|
|
77
|
+
}) })
|
|
78
|
+
] }, module2))
|
|
79
|
+
] });
|
|
80
|
+
};
|
|
81
|
+
const config = adminSdk.defineRouteConfig({
|
|
82
|
+
label: "integration.list.title",
|
|
83
|
+
translationNs: "translation",
|
|
84
|
+
icon: icons.CogSixTooth
|
|
85
|
+
});
|
|
86
|
+
const IntegrationsBreadcrumb = () => {
|
|
87
|
+
const { t } = reactI18next.useTranslation();
|
|
88
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: t("integration.list.title") });
|
|
89
|
+
};
|
|
90
|
+
const handle$1 = {
|
|
91
|
+
breadcrumb: () => /* @__PURE__ */ jsxRuntime.jsx(IntegrationsBreadcrumb, {})
|
|
92
|
+
};
|
|
93
|
+
const Dash = () => /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "text-ui-fg-subtle", children: "-" });
|
|
94
|
+
const IntegrationFieldValue = ({
|
|
95
|
+
field,
|
|
96
|
+
value,
|
|
97
|
+
secretConfigured = false
|
|
98
|
+
}) => {
|
|
99
|
+
var _a;
|
|
100
|
+
const { t } = reactI18next.useTranslation();
|
|
101
|
+
if (field.readonly && (value == null || value === "")) value = field.readonlyValue;
|
|
102
|
+
if (field.secret || field.control === "secret") {
|
|
103
|
+
return secretConfigured ? /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "••••••••" }) : /* @__PURE__ */ jsxRuntime.jsx(Dash, {});
|
|
104
|
+
}
|
|
105
|
+
if (field.control === "switch") {
|
|
106
|
+
if (value == null) return /* @__PURE__ */ jsxRuntime.jsx(Dash, {});
|
|
107
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { size: "2xsmall", color: value ? "green" : "grey", children: value ? t("integration.status.enabled") : t("integration.status.disabled") });
|
|
108
|
+
}
|
|
109
|
+
if (field.control === "json") {
|
|
110
|
+
if (Array.isArray(value)) {
|
|
111
|
+
return value.length ? /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: t("integration.form.items", { count: value.length }) }) : /* @__PURE__ */ jsxRuntime.jsx(Dash, {});
|
|
112
|
+
}
|
|
113
|
+
if (value == null) return /* @__PURE__ */ jsxRuntime.jsx(Dash, {});
|
|
114
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: t("integration.status.configured") });
|
|
115
|
+
}
|
|
116
|
+
if (value == null || value === "") return /* @__PURE__ */ jsxRuntime.jsx(Dash, {});
|
|
117
|
+
if (field.control === "select") {
|
|
118
|
+
const labelKey = (_a = field.optionLabels) == null ? void 0 : _a[String(value)];
|
|
119
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { size: "2xsmall", color: "grey", children: labelKey ? t(labelKey) : String(value) });
|
|
120
|
+
}
|
|
121
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: String(value) });
|
|
122
|
+
};
|
|
123
|
+
var isCheckBoxInput = (element) => element.type === "checkbox";
|
|
124
|
+
var isDateObject = (value) => value instanceof Date;
|
|
125
|
+
var isNullOrUndefined = (value) => value == null;
|
|
126
|
+
const isObjectType = (value) => typeof value === "object";
|
|
127
|
+
var isObject = (value) => !isNullOrUndefined(value) && !Array.isArray(value) && isObjectType(value) && !isDateObject(value);
|
|
128
|
+
var getEventValue = (event) => isObject(event) && event.target ? isCheckBoxInput(event.target) ? event.target.checked : event.target.value : event;
|
|
129
|
+
var getNodeParentName = (name) => name.substring(0, name.search(/\.\d+(\.|$)/)) || name;
|
|
130
|
+
var isNameInFieldArray = (names, name) => names.has(getNodeParentName(name));
|
|
131
|
+
var isPlainObject = (tempObject) => {
|
|
132
|
+
const prototypeCopy = tempObject.constructor && tempObject.constructor.prototype;
|
|
133
|
+
return isObject(prototypeCopy) && prototypeCopy.hasOwnProperty("isPrototypeOf");
|
|
134
|
+
};
|
|
135
|
+
var isWeb = typeof window !== "undefined" && typeof window.HTMLElement !== "undefined" && typeof document !== "undefined";
|
|
136
|
+
function cloneObject(data) {
|
|
137
|
+
let copy;
|
|
138
|
+
const isArray = Array.isArray(data);
|
|
139
|
+
if (data instanceof Date) {
|
|
140
|
+
copy = new Date(data);
|
|
141
|
+
} else if (data instanceof Set) {
|
|
142
|
+
copy = new Set(data);
|
|
143
|
+
} else if (!(isWeb && (data instanceof Blob || data instanceof FileList)) && (isArray || isObject(data))) {
|
|
144
|
+
copy = isArray ? [] : {};
|
|
145
|
+
if (!isArray && !isPlainObject(data)) {
|
|
146
|
+
copy = data;
|
|
147
|
+
} else {
|
|
148
|
+
for (const key in data) {
|
|
149
|
+
if (data.hasOwnProperty(key)) {
|
|
150
|
+
copy[key] = cloneObject(data[key]);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
} else {
|
|
155
|
+
return data;
|
|
156
|
+
}
|
|
157
|
+
return copy;
|
|
158
|
+
}
|
|
159
|
+
var compact = (value) => Array.isArray(value) ? value.filter(Boolean) : [];
|
|
160
|
+
var isUndefined = (val) => val === void 0;
|
|
161
|
+
var get = (object, path, defaultValue) => {
|
|
162
|
+
if (!path || !isObject(object)) {
|
|
163
|
+
return defaultValue;
|
|
164
|
+
}
|
|
165
|
+
const result = compact(path.split(/[,[\].]+?/)).reduce((result2, key) => isNullOrUndefined(result2) ? result2 : result2[key], object);
|
|
166
|
+
return isUndefined(result) || result === object ? isUndefined(object[path]) ? defaultValue : object[path] : result;
|
|
167
|
+
};
|
|
168
|
+
var isBoolean = (value) => typeof value === "boolean";
|
|
169
|
+
const EVENTS = {
|
|
170
|
+
BLUR: "blur",
|
|
171
|
+
FOCUS_OUT: "focusout",
|
|
172
|
+
CHANGE: "change"
|
|
173
|
+
};
|
|
174
|
+
const VALIDATION_MODE = {
|
|
175
|
+
onBlur: "onBlur",
|
|
176
|
+
onChange: "onChange",
|
|
177
|
+
onSubmit: "onSubmit",
|
|
178
|
+
onTouched: "onTouched",
|
|
179
|
+
all: "all"
|
|
180
|
+
};
|
|
181
|
+
const INPUT_VALIDATION_RULES = {
|
|
182
|
+
max: "max",
|
|
183
|
+
min: "min",
|
|
184
|
+
maxLength: "maxLength",
|
|
185
|
+
minLength: "minLength",
|
|
186
|
+
pattern: "pattern",
|
|
187
|
+
required: "required",
|
|
188
|
+
validate: "validate"
|
|
189
|
+
};
|
|
190
|
+
const HookFormContext = React__default.default.createContext(null);
|
|
191
|
+
const useFormContext = () => React__default.default.useContext(HookFormContext);
|
|
192
|
+
var getProxyFormState = (formState, control, localProxyFormState, isRoot = true) => {
|
|
193
|
+
const result = {
|
|
194
|
+
defaultValues: control._defaultValues
|
|
195
|
+
};
|
|
196
|
+
for (const key in formState) {
|
|
197
|
+
Object.defineProperty(result, key, {
|
|
198
|
+
get: () => {
|
|
199
|
+
const _key = key;
|
|
200
|
+
if (control._proxyFormState[_key] !== VALIDATION_MODE.all) {
|
|
201
|
+
control._proxyFormState[_key] = !isRoot || VALIDATION_MODE.all;
|
|
202
|
+
}
|
|
203
|
+
localProxyFormState && (localProxyFormState[_key] = true);
|
|
204
|
+
return formState[_key];
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
return result;
|
|
209
|
+
};
|
|
210
|
+
var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
|
|
211
|
+
var shouldRenderFormState = (formStateData, _proxyFormState, updateFormState, isRoot) => {
|
|
212
|
+
updateFormState(formStateData);
|
|
213
|
+
const { name, ...formState } = formStateData;
|
|
214
|
+
return isEmptyObject(formState) || Object.keys(formState).length >= Object.keys(_proxyFormState).length || Object.keys(formState).find((key) => _proxyFormState[key] === (!isRoot || VALIDATION_MODE.all));
|
|
215
|
+
};
|
|
216
|
+
var convertToArrayPayload = (value) => Array.isArray(value) ? value : [value];
|
|
217
|
+
var shouldSubscribeByName = (name, signalName, exact) => !name || !signalName || name === signalName || convertToArrayPayload(name).some((currentName) => currentName && (exact ? currentName === signalName : currentName.startsWith(signalName) || signalName.startsWith(currentName)));
|
|
218
|
+
function useSubscribe(props) {
|
|
219
|
+
const _props = React__default.default.useRef(props);
|
|
220
|
+
_props.current = props;
|
|
221
|
+
React__default.default.useEffect(() => {
|
|
222
|
+
const subscription = !props.disabled && _props.current.subject && _props.current.subject.subscribe({
|
|
223
|
+
next: _props.current.next
|
|
224
|
+
});
|
|
225
|
+
return () => {
|
|
226
|
+
subscription && subscription.unsubscribe();
|
|
227
|
+
};
|
|
228
|
+
}, [props.disabled]);
|
|
229
|
+
}
|
|
230
|
+
function useFormState(props) {
|
|
231
|
+
const methods = useFormContext();
|
|
232
|
+
const { control = methods.control, disabled, name, exact } = props || {};
|
|
233
|
+
const [formState, updateFormState] = React__default.default.useState(control._formState);
|
|
234
|
+
const _mounted = React__default.default.useRef(true);
|
|
235
|
+
const _localProxyFormState = React__default.default.useRef({
|
|
236
|
+
isDirty: false,
|
|
237
|
+
isLoading: false,
|
|
238
|
+
dirtyFields: false,
|
|
239
|
+
touchedFields: false,
|
|
240
|
+
isValidating: false,
|
|
241
|
+
isValid: false,
|
|
242
|
+
errors: false
|
|
243
|
+
});
|
|
244
|
+
const _name = React__default.default.useRef(name);
|
|
245
|
+
_name.current = name;
|
|
246
|
+
useSubscribe({
|
|
247
|
+
disabled,
|
|
248
|
+
next: (value) => _mounted.current && shouldSubscribeByName(_name.current, value.name, exact) && shouldRenderFormState(value, _localProxyFormState.current, control._updateFormState) && updateFormState({
|
|
249
|
+
...control._formState,
|
|
250
|
+
...value
|
|
251
|
+
}),
|
|
252
|
+
subject: control._subjects.state
|
|
253
|
+
});
|
|
254
|
+
React__default.default.useEffect(() => {
|
|
255
|
+
_mounted.current = true;
|
|
256
|
+
_localProxyFormState.current.isValid && control._updateValid(true);
|
|
257
|
+
return () => {
|
|
258
|
+
_mounted.current = false;
|
|
259
|
+
};
|
|
260
|
+
}, [control]);
|
|
261
|
+
return getProxyFormState(formState, control, _localProxyFormState.current, false);
|
|
262
|
+
}
|
|
263
|
+
var isString = (value) => typeof value === "string";
|
|
264
|
+
var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) => {
|
|
265
|
+
if (isString(names)) {
|
|
266
|
+
isGlobal && _names.watch.add(names);
|
|
267
|
+
return get(formValues, names, defaultValue);
|
|
268
|
+
}
|
|
269
|
+
if (Array.isArray(names)) {
|
|
270
|
+
return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName), get(formValues, fieldName)));
|
|
271
|
+
}
|
|
272
|
+
isGlobal && (_names.watchAll = true);
|
|
273
|
+
return formValues;
|
|
274
|
+
};
|
|
275
|
+
function useWatch(props) {
|
|
276
|
+
const methods = useFormContext();
|
|
277
|
+
const { control = methods.control, name, defaultValue, disabled, exact } = props || {};
|
|
278
|
+
const _name = React__default.default.useRef(name);
|
|
279
|
+
_name.current = name;
|
|
280
|
+
useSubscribe({
|
|
281
|
+
disabled,
|
|
282
|
+
subject: control._subjects.values,
|
|
283
|
+
next: (formState) => {
|
|
284
|
+
if (shouldSubscribeByName(_name.current, formState.name, exact)) {
|
|
285
|
+
updateValue(cloneObject(generateWatchOutput(_name.current, control._names, formState.values || control._formValues, false, defaultValue)));
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
const [value, updateValue] = React__default.default.useState(control._getWatch(name, defaultValue));
|
|
290
|
+
React__default.default.useEffect(() => control._removeUnmounted());
|
|
291
|
+
return value;
|
|
292
|
+
}
|
|
293
|
+
var isKey = (value) => /^\w*$/.test(value);
|
|
294
|
+
var stringToPath = (input) => compact(input.replace(/["|']|\]/g, "").split(/\.|\[/));
|
|
295
|
+
var set = (object, path, value) => {
|
|
296
|
+
let index = -1;
|
|
297
|
+
const tempPath = isKey(path) ? [path] : stringToPath(path);
|
|
298
|
+
const length = tempPath.length;
|
|
299
|
+
const lastIndex = length - 1;
|
|
300
|
+
while (++index < length) {
|
|
301
|
+
const key = tempPath[index];
|
|
302
|
+
let newValue = value;
|
|
303
|
+
if (index !== lastIndex) {
|
|
304
|
+
const objValue = object[key];
|
|
305
|
+
newValue = isObject(objValue) || Array.isArray(objValue) ? objValue : !isNaN(+tempPath[index + 1]) ? [] : {};
|
|
306
|
+
}
|
|
307
|
+
object[key] = newValue;
|
|
308
|
+
object = object[key];
|
|
309
|
+
}
|
|
310
|
+
return object;
|
|
311
|
+
};
|
|
312
|
+
function useController(props) {
|
|
313
|
+
const methods = useFormContext();
|
|
314
|
+
const { name, disabled, control = methods.control, shouldUnregister } = props;
|
|
315
|
+
const isArrayField = isNameInFieldArray(control._names.array, name);
|
|
316
|
+
const value = useWatch({
|
|
317
|
+
control,
|
|
318
|
+
name,
|
|
319
|
+
defaultValue: get(control._formValues, name, get(control._defaultValues, name, props.defaultValue)),
|
|
320
|
+
exact: true
|
|
321
|
+
});
|
|
322
|
+
const formState = useFormState({
|
|
323
|
+
control,
|
|
324
|
+
name
|
|
325
|
+
});
|
|
326
|
+
const _registerProps = React__default.default.useRef(control.register(name, {
|
|
327
|
+
...props.rules,
|
|
328
|
+
value,
|
|
329
|
+
...isBoolean(props.disabled) ? { disabled: props.disabled } : {}
|
|
330
|
+
}));
|
|
331
|
+
React__default.default.useEffect(() => {
|
|
332
|
+
const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
|
|
333
|
+
const updateMounted = (name2, value2) => {
|
|
334
|
+
const field = get(control._fields, name2);
|
|
335
|
+
if (field) {
|
|
336
|
+
field._f.mount = value2;
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
updateMounted(name, true);
|
|
340
|
+
if (_shouldUnregisterField) {
|
|
341
|
+
const value2 = cloneObject(get(control._options.defaultValues, name));
|
|
342
|
+
set(control._defaultValues, name, value2);
|
|
343
|
+
if (isUndefined(get(control._formValues, name))) {
|
|
344
|
+
set(control._formValues, name, value2);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
return () => {
|
|
348
|
+
(isArrayField ? _shouldUnregisterField && !control._state.action : _shouldUnregisterField) ? control.unregister(name) : updateMounted(name, false);
|
|
349
|
+
};
|
|
350
|
+
}, [name, control, isArrayField, shouldUnregister]);
|
|
351
|
+
React__default.default.useEffect(() => {
|
|
352
|
+
if (get(control._fields, name)) {
|
|
353
|
+
control._updateDisabledField({
|
|
354
|
+
disabled,
|
|
355
|
+
fields: control._fields,
|
|
356
|
+
name,
|
|
357
|
+
value: get(control._fields, name)._f.value
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
}, [disabled, name, control]);
|
|
361
|
+
return {
|
|
362
|
+
field: {
|
|
363
|
+
name,
|
|
364
|
+
value,
|
|
365
|
+
...isBoolean(disabled) || isBoolean(formState.disabled) ? { disabled: formState.disabled || disabled } : {},
|
|
366
|
+
onChange: React__default.default.useCallback((event) => _registerProps.current.onChange({
|
|
367
|
+
target: {
|
|
368
|
+
value: getEventValue(event),
|
|
369
|
+
name
|
|
370
|
+
},
|
|
371
|
+
type: EVENTS.CHANGE
|
|
372
|
+
}), [name]),
|
|
373
|
+
onBlur: React__default.default.useCallback(() => _registerProps.current.onBlur({
|
|
374
|
+
target: {
|
|
375
|
+
value: get(control._formValues, name),
|
|
376
|
+
name
|
|
377
|
+
},
|
|
378
|
+
type: EVENTS.BLUR
|
|
379
|
+
}), [name, control]),
|
|
380
|
+
ref: (elm) => {
|
|
381
|
+
const field = get(control._fields, name);
|
|
382
|
+
if (field && elm) {
|
|
383
|
+
field._f.ref = {
|
|
384
|
+
focus: () => elm.focus(),
|
|
385
|
+
select: () => elm.select(),
|
|
386
|
+
setCustomValidity: (message) => elm.setCustomValidity(message),
|
|
387
|
+
reportValidity: () => elm.reportValidity()
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
},
|
|
392
|
+
formState,
|
|
393
|
+
fieldState: Object.defineProperties({}, {
|
|
394
|
+
invalid: {
|
|
395
|
+
enumerable: true,
|
|
396
|
+
get: () => !!get(formState.errors, name)
|
|
397
|
+
},
|
|
398
|
+
isDirty: {
|
|
399
|
+
enumerable: true,
|
|
400
|
+
get: () => !!get(formState.dirtyFields, name)
|
|
401
|
+
},
|
|
402
|
+
isTouched: {
|
|
403
|
+
enumerable: true,
|
|
404
|
+
get: () => !!get(formState.touchedFields, name)
|
|
405
|
+
},
|
|
406
|
+
error: {
|
|
407
|
+
enumerable: true,
|
|
408
|
+
get: () => get(formState.errors, name)
|
|
409
|
+
}
|
|
410
|
+
})
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
const Controller = (props) => props.render(useController(props));
|
|
414
|
+
var appendErrors = (name, validateAllFieldCriteria, errors, type, message) => validateAllFieldCriteria ? {
|
|
415
|
+
...errors[name],
|
|
416
|
+
types: {
|
|
417
|
+
...errors[name] && errors[name].types ? errors[name].types : {},
|
|
418
|
+
[type]: message || true
|
|
419
|
+
}
|
|
420
|
+
} : {};
|
|
421
|
+
var getValidationModes = (mode) => ({
|
|
422
|
+
isOnSubmit: !mode || mode === VALIDATION_MODE.onSubmit,
|
|
423
|
+
isOnBlur: mode === VALIDATION_MODE.onBlur,
|
|
424
|
+
isOnChange: mode === VALIDATION_MODE.onChange,
|
|
425
|
+
isOnAll: mode === VALIDATION_MODE.all,
|
|
426
|
+
isOnTouch: mode === VALIDATION_MODE.onTouched
|
|
427
|
+
});
|
|
428
|
+
var isWatched = (name, _names, isBlurEvent) => !isBlurEvent && (_names.watchAll || _names.watch.has(name) || [..._names.watch].some((watchName) => name.startsWith(watchName) && /^\.\w+/.test(name.slice(watchName.length))));
|
|
429
|
+
const iterateFieldsByAction = (fields, action, fieldsNames, abortEarly) => {
|
|
430
|
+
for (const key of fieldsNames || Object.keys(fields)) {
|
|
431
|
+
const field = get(fields, key);
|
|
432
|
+
if (field) {
|
|
433
|
+
const { _f, ...currentField } = field;
|
|
434
|
+
if (_f) {
|
|
435
|
+
if (_f.refs && _f.refs[0] && action(_f.refs[0], key) && !abortEarly) {
|
|
436
|
+
break;
|
|
437
|
+
} else if (_f.ref && action(_f.ref, _f.name) && !abortEarly) {
|
|
438
|
+
break;
|
|
439
|
+
} else {
|
|
440
|
+
iterateFieldsByAction(currentField, action);
|
|
441
|
+
}
|
|
442
|
+
} else if (isObject(currentField)) {
|
|
443
|
+
iterateFieldsByAction(currentField, action);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
var updateFieldArrayRootError = (errors, error, name) => {
|
|
449
|
+
const fieldArrayErrors = compact(get(errors, name));
|
|
450
|
+
set(fieldArrayErrors, "root", error[name]);
|
|
451
|
+
set(errors, name, fieldArrayErrors);
|
|
452
|
+
return errors;
|
|
453
|
+
};
|
|
454
|
+
var isFileInput = (element) => element.type === "file";
|
|
455
|
+
var isFunction = (value) => typeof value === "function";
|
|
456
|
+
var isHTMLElement = (value) => {
|
|
457
|
+
if (!isWeb) {
|
|
458
|
+
return false;
|
|
459
|
+
}
|
|
460
|
+
const owner = value ? value.ownerDocument : 0;
|
|
461
|
+
return value instanceof (owner && owner.defaultView ? owner.defaultView.HTMLElement : HTMLElement);
|
|
462
|
+
};
|
|
463
|
+
var isMessage = (value) => isString(value);
|
|
464
|
+
var isRadioInput = (element) => element.type === "radio";
|
|
465
|
+
var isRegex = (value) => value instanceof RegExp;
|
|
466
|
+
const defaultResult = {
|
|
467
|
+
value: false,
|
|
468
|
+
isValid: false
|
|
469
|
+
};
|
|
470
|
+
const validResult = { value: true, isValid: true };
|
|
471
|
+
var getCheckboxValue = (options) => {
|
|
472
|
+
if (Array.isArray(options)) {
|
|
473
|
+
if (options.length > 1) {
|
|
474
|
+
const values = options.filter((option) => option && option.checked && !option.disabled).map((option) => option.value);
|
|
475
|
+
return { value: values, isValid: !!values.length };
|
|
476
|
+
}
|
|
477
|
+
return options[0].checked && !options[0].disabled ? (
|
|
478
|
+
// @ts-expect-error expected to work in the browser
|
|
479
|
+
options[0].attributes && !isUndefined(options[0].attributes.value) ? isUndefined(options[0].value) || options[0].value === "" ? validResult : { value: options[0].value, isValid: true } : validResult
|
|
480
|
+
) : defaultResult;
|
|
481
|
+
}
|
|
482
|
+
return defaultResult;
|
|
483
|
+
};
|
|
484
|
+
const defaultReturn = {
|
|
485
|
+
isValid: false,
|
|
486
|
+
value: null
|
|
487
|
+
};
|
|
488
|
+
var getRadioValue = (options) => Array.isArray(options) ? options.reduce((previous, option) => option && option.checked && !option.disabled ? {
|
|
489
|
+
isValid: true,
|
|
490
|
+
value: option.value
|
|
491
|
+
} : previous, defaultReturn) : defaultReturn;
|
|
492
|
+
function getValidateError(result, ref, type = "validate") {
|
|
493
|
+
if (isMessage(result) || Array.isArray(result) && result.every(isMessage) || isBoolean(result) && !result) {
|
|
494
|
+
return {
|
|
495
|
+
type,
|
|
496
|
+
message: isMessage(result) ? result : "",
|
|
497
|
+
ref
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
var getValueAndMessage = (validationData) => isObject(validationData) && !isRegex(validationData) ? validationData : {
|
|
502
|
+
value: validationData,
|
|
503
|
+
message: ""
|
|
504
|
+
};
|
|
505
|
+
var validateField = async (field, formValues, validateAllFieldCriteria, shouldUseNativeValidation, isFieldArray) => {
|
|
506
|
+
const { ref, refs, required, maxLength, minLength, min, max, pattern, validate, name, valueAsNumber, mount, disabled } = field._f;
|
|
507
|
+
const inputValue = get(formValues, name);
|
|
508
|
+
if (!mount || disabled) {
|
|
509
|
+
return {};
|
|
510
|
+
}
|
|
511
|
+
const inputRef = refs ? refs[0] : ref;
|
|
512
|
+
const setCustomValidity = (message) => {
|
|
513
|
+
if (shouldUseNativeValidation && inputRef.reportValidity) {
|
|
514
|
+
inputRef.setCustomValidity(isBoolean(message) ? "" : message || "");
|
|
515
|
+
inputRef.reportValidity();
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
const error = {};
|
|
519
|
+
const isRadio = isRadioInput(ref);
|
|
520
|
+
const isCheckBox = isCheckBoxInput(ref);
|
|
521
|
+
const isRadioOrCheckbox2 = isRadio || isCheckBox;
|
|
522
|
+
const isEmpty = (valueAsNumber || isFileInput(ref)) && isUndefined(ref.value) && isUndefined(inputValue) || isHTMLElement(ref) && ref.value === "" || inputValue === "" || Array.isArray(inputValue) && !inputValue.length;
|
|
523
|
+
const appendErrorsCurry = appendErrors.bind(null, name, validateAllFieldCriteria, error);
|
|
524
|
+
const getMinMaxMessage = (exceedMax, maxLengthMessage, minLengthMessage, maxType = INPUT_VALIDATION_RULES.maxLength, minType = INPUT_VALIDATION_RULES.minLength) => {
|
|
525
|
+
const message = exceedMax ? maxLengthMessage : minLengthMessage;
|
|
526
|
+
error[name] = {
|
|
527
|
+
type: exceedMax ? maxType : minType,
|
|
528
|
+
message,
|
|
529
|
+
ref,
|
|
530
|
+
...appendErrorsCurry(exceedMax ? maxType : minType, message)
|
|
531
|
+
};
|
|
532
|
+
};
|
|
533
|
+
if (isFieldArray ? !Array.isArray(inputValue) || !inputValue.length : required && (!isRadioOrCheckbox2 && (isEmpty || isNullOrUndefined(inputValue)) || isBoolean(inputValue) && !inputValue || isCheckBox && !getCheckboxValue(refs).isValid || isRadio && !getRadioValue(refs).isValid)) {
|
|
534
|
+
const { value, message } = isMessage(required) ? { value: !!required, message: required } : getValueAndMessage(required);
|
|
535
|
+
if (value) {
|
|
536
|
+
error[name] = {
|
|
537
|
+
type: INPUT_VALIDATION_RULES.required,
|
|
538
|
+
message,
|
|
539
|
+
ref: inputRef,
|
|
540
|
+
...appendErrorsCurry(INPUT_VALIDATION_RULES.required, message)
|
|
541
|
+
};
|
|
542
|
+
if (!validateAllFieldCriteria) {
|
|
543
|
+
setCustomValidity(message);
|
|
544
|
+
return error;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
if (!isEmpty && (!isNullOrUndefined(min) || !isNullOrUndefined(max))) {
|
|
549
|
+
let exceedMax;
|
|
550
|
+
let exceedMin;
|
|
551
|
+
const maxOutput = getValueAndMessage(max);
|
|
552
|
+
const minOutput = getValueAndMessage(min);
|
|
553
|
+
if (!isNullOrUndefined(inputValue) && !isNaN(inputValue)) {
|
|
554
|
+
const valueNumber = ref.valueAsNumber || (inputValue ? +inputValue : inputValue);
|
|
555
|
+
if (!isNullOrUndefined(maxOutput.value)) {
|
|
556
|
+
exceedMax = valueNumber > maxOutput.value;
|
|
557
|
+
}
|
|
558
|
+
if (!isNullOrUndefined(minOutput.value)) {
|
|
559
|
+
exceedMin = valueNumber < minOutput.value;
|
|
560
|
+
}
|
|
561
|
+
} else {
|
|
562
|
+
const valueDate = ref.valueAsDate || new Date(inputValue);
|
|
563
|
+
const convertTimeToDate = (time) => /* @__PURE__ */ new Date((/* @__PURE__ */ new Date()).toDateString() + " " + time);
|
|
564
|
+
const isTime = ref.type == "time";
|
|
565
|
+
const isWeek = ref.type == "week";
|
|
566
|
+
if (isString(maxOutput.value) && inputValue) {
|
|
567
|
+
exceedMax = isTime ? convertTimeToDate(inputValue) > convertTimeToDate(maxOutput.value) : isWeek ? inputValue > maxOutput.value : valueDate > new Date(maxOutput.value);
|
|
568
|
+
}
|
|
569
|
+
if (isString(minOutput.value) && inputValue) {
|
|
570
|
+
exceedMin = isTime ? convertTimeToDate(inputValue) < convertTimeToDate(minOutput.value) : isWeek ? inputValue < minOutput.value : valueDate < new Date(minOutput.value);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
if (exceedMax || exceedMin) {
|
|
574
|
+
getMinMaxMessage(!!exceedMax, maxOutput.message, minOutput.message, INPUT_VALIDATION_RULES.max, INPUT_VALIDATION_RULES.min);
|
|
575
|
+
if (!validateAllFieldCriteria) {
|
|
576
|
+
setCustomValidity(error[name].message);
|
|
577
|
+
return error;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
if ((maxLength || minLength) && !isEmpty && (isString(inputValue) || isFieldArray && Array.isArray(inputValue))) {
|
|
582
|
+
const maxLengthOutput = getValueAndMessage(maxLength);
|
|
583
|
+
const minLengthOutput = getValueAndMessage(minLength);
|
|
584
|
+
const exceedMax = !isNullOrUndefined(maxLengthOutput.value) && inputValue.length > +maxLengthOutput.value;
|
|
585
|
+
const exceedMin = !isNullOrUndefined(minLengthOutput.value) && inputValue.length < +minLengthOutput.value;
|
|
586
|
+
if (exceedMax || exceedMin) {
|
|
587
|
+
getMinMaxMessage(exceedMax, maxLengthOutput.message, minLengthOutput.message);
|
|
588
|
+
if (!validateAllFieldCriteria) {
|
|
589
|
+
setCustomValidity(error[name].message);
|
|
590
|
+
return error;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
if (pattern && !isEmpty && isString(inputValue)) {
|
|
595
|
+
const { value: patternValue, message } = getValueAndMessage(pattern);
|
|
596
|
+
if (isRegex(patternValue) && !inputValue.match(patternValue)) {
|
|
597
|
+
error[name] = {
|
|
598
|
+
type: INPUT_VALIDATION_RULES.pattern,
|
|
599
|
+
message,
|
|
600
|
+
ref,
|
|
601
|
+
...appendErrorsCurry(INPUT_VALIDATION_RULES.pattern, message)
|
|
602
|
+
};
|
|
603
|
+
if (!validateAllFieldCriteria) {
|
|
604
|
+
setCustomValidity(message);
|
|
605
|
+
return error;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
if (validate) {
|
|
610
|
+
if (isFunction(validate)) {
|
|
611
|
+
const result = await validate(inputValue, formValues);
|
|
612
|
+
const validateError = getValidateError(result, inputRef);
|
|
613
|
+
if (validateError) {
|
|
614
|
+
error[name] = {
|
|
615
|
+
...validateError,
|
|
616
|
+
...appendErrorsCurry(INPUT_VALIDATION_RULES.validate, validateError.message)
|
|
617
|
+
};
|
|
618
|
+
if (!validateAllFieldCriteria) {
|
|
619
|
+
setCustomValidity(validateError.message);
|
|
620
|
+
return error;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
} else if (isObject(validate)) {
|
|
624
|
+
let validationResult = {};
|
|
625
|
+
for (const key in validate) {
|
|
626
|
+
if (!isEmptyObject(validationResult) && !validateAllFieldCriteria) {
|
|
627
|
+
break;
|
|
628
|
+
}
|
|
629
|
+
const validateError = getValidateError(await validate[key](inputValue, formValues), inputRef, key);
|
|
630
|
+
if (validateError) {
|
|
631
|
+
validationResult = {
|
|
632
|
+
...validateError,
|
|
633
|
+
...appendErrorsCurry(key, validateError.message)
|
|
634
|
+
};
|
|
635
|
+
setCustomValidity(validateError.message);
|
|
636
|
+
if (validateAllFieldCriteria) {
|
|
637
|
+
error[name] = validationResult;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
if (!isEmptyObject(validationResult)) {
|
|
642
|
+
error[name] = {
|
|
643
|
+
ref: inputRef,
|
|
644
|
+
...validationResult
|
|
645
|
+
};
|
|
646
|
+
if (!validateAllFieldCriteria) {
|
|
647
|
+
return error;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
setCustomValidity(true);
|
|
653
|
+
return error;
|
|
654
|
+
};
|
|
655
|
+
function baseGet(object, updatePath) {
|
|
656
|
+
const length = updatePath.slice(0, -1).length;
|
|
657
|
+
let index = 0;
|
|
658
|
+
while (index < length) {
|
|
659
|
+
object = isUndefined(object) ? index++ : object[updatePath[index++]];
|
|
660
|
+
}
|
|
661
|
+
return object;
|
|
662
|
+
}
|
|
663
|
+
function isEmptyArray(obj) {
|
|
664
|
+
for (const key in obj) {
|
|
665
|
+
if (obj.hasOwnProperty(key) && !isUndefined(obj[key])) {
|
|
666
|
+
return false;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
return true;
|
|
670
|
+
}
|
|
671
|
+
function unset(object, path) {
|
|
672
|
+
const paths = Array.isArray(path) ? path : isKey(path) ? [path] : stringToPath(path);
|
|
673
|
+
const childObject = paths.length === 1 ? object : baseGet(object, paths);
|
|
674
|
+
const index = paths.length - 1;
|
|
675
|
+
const key = paths[index];
|
|
676
|
+
if (childObject) {
|
|
677
|
+
delete childObject[key];
|
|
678
|
+
}
|
|
679
|
+
if (index !== 0 && (isObject(childObject) && isEmptyObject(childObject) || Array.isArray(childObject) && isEmptyArray(childObject))) {
|
|
680
|
+
unset(object, paths.slice(0, -1));
|
|
681
|
+
}
|
|
682
|
+
return object;
|
|
683
|
+
}
|
|
684
|
+
var createSubject = () => {
|
|
685
|
+
let _observers = [];
|
|
686
|
+
const next = (value) => {
|
|
687
|
+
for (const observer of _observers) {
|
|
688
|
+
observer.next && observer.next(value);
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
const subscribe = (observer) => {
|
|
692
|
+
_observers.push(observer);
|
|
693
|
+
return {
|
|
694
|
+
unsubscribe: () => {
|
|
695
|
+
_observers = _observers.filter((o) => o !== observer);
|
|
696
|
+
}
|
|
697
|
+
};
|
|
698
|
+
};
|
|
699
|
+
const unsubscribe = () => {
|
|
700
|
+
_observers = [];
|
|
701
|
+
};
|
|
702
|
+
return {
|
|
703
|
+
get observers() {
|
|
704
|
+
return _observers;
|
|
705
|
+
},
|
|
706
|
+
next,
|
|
707
|
+
subscribe,
|
|
708
|
+
unsubscribe
|
|
709
|
+
};
|
|
710
|
+
};
|
|
711
|
+
var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
|
|
712
|
+
function deepEqual(object1, object2) {
|
|
713
|
+
if (isPrimitive(object1) || isPrimitive(object2)) {
|
|
714
|
+
return object1 === object2;
|
|
715
|
+
}
|
|
716
|
+
if (isDateObject(object1) && isDateObject(object2)) {
|
|
717
|
+
return object1.getTime() === object2.getTime();
|
|
718
|
+
}
|
|
719
|
+
const keys1 = Object.keys(object1);
|
|
720
|
+
const keys2 = Object.keys(object2);
|
|
721
|
+
if (keys1.length !== keys2.length) {
|
|
722
|
+
return false;
|
|
723
|
+
}
|
|
724
|
+
for (const key of keys1) {
|
|
725
|
+
const val1 = object1[key];
|
|
726
|
+
if (!keys2.includes(key)) {
|
|
727
|
+
return false;
|
|
728
|
+
}
|
|
729
|
+
if (key !== "ref") {
|
|
730
|
+
const val2 = object2[key];
|
|
731
|
+
if (isDateObject(val1) && isDateObject(val2) || isObject(val1) && isObject(val2) || Array.isArray(val1) && Array.isArray(val2) ? !deepEqual(val1, val2) : val1 !== val2) {
|
|
732
|
+
return false;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
return true;
|
|
737
|
+
}
|
|
738
|
+
var isMultipleSelect = (element) => element.type === `select-multiple`;
|
|
739
|
+
var isRadioOrCheckbox = (ref) => isRadioInput(ref) || isCheckBoxInput(ref);
|
|
740
|
+
var live = (ref) => isHTMLElement(ref) && ref.isConnected;
|
|
741
|
+
var objectHasFunction = (data) => {
|
|
742
|
+
for (const key in data) {
|
|
743
|
+
if (isFunction(data[key])) {
|
|
744
|
+
return true;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
return false;
|
|
748
|
+
};
|
|
749
|
+
function markFieldsDirty(data, fields = {}) {
|
|
750
|
+
const isParentNodeArray = Array.isArray(data);
|
|
751
|
+
if (isObject(data) || isParentNodeArray) {
|
|
752
|
+
for (const key in data) {
|
|
753
|
+
if (Array.isArray(data[key]) || isObject(data[key]) && !objectHasFunction(data[key])) {
|
|
754
|
+
fields[key] = Array.isArray(data[key]) ? [] : {};
|
|
755
|
+
markFieldsDirty(data[key], fields[key]);
|
|
756
|
+
} else if (!isNullOrUndefined(data[key])) {
|
|
757
|
+
fields[key] = true;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
return fields;
|
|
762
|
+
}
|
|
763
|
+
function getDirtyFieldsFromDefaultValues(data, formValues, dirtyFieldsFromValues) {
|
|
764
|
+
const isParentNodeArray = Array.isArray(data);
|
|
765
|
+
if (isObject(data) || isParentNodeArray) {
|
|
766
|
+
for (const key in data) {
|
|
767
|
+
if (Array.isArray(data[key]) || isObject(data[key]) && !objectHasFunction(data[key])) {
|
|
768
|
+
if (isUndefined(formValues) || isPrimitive(dirtyFieldsFromValues[key])) {
|
|
769
|
+
dirtyFieldsFromValues[key] = Array.isArray(data[key]) ? markFieldsDirty(data[key], []) : { ...markFieldsDirty(data[key]) };
|
|
770
|
+
} else {
|
|
771
|
+
getDirtyFieldsFromDefaultValues(data[key], isNullOrUndefined(formValues) ? {} : formValues[key], dirtyFieldsFromValues[key]);
|
|
772
|
+
}
|
|
773
|
+
} else {
|
|
774
|
+
dirtyFieldsFromValues[key] = !deepEqual(data[key], formValues[key]);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
return dirtyFieldsFromValues;
|
|
779
|
+
}
|
|
780
|
+
var getDirtyFields = (defaultValues, formValues) => getDirtyFieldsFromDefaultValues(defaultValues, formValues, markFieldsDirty(formValues));
|
|
781
|
+
var getFieldValueAs = (value, { valueAsNumber, valueAsDate, setValueAs }) => isUndefined(value) ? value : valueAsNumber ? value === "" ? NaN : value ? +value : value : valueAsDate && isString(value) ? new Date(value) : setValueAs ? setValueAs(value) : value;
|
|
782
|
+
function getFieldValue(_f) {
|
|
783
|
+
const ref = _f.ref;
|
|
784
|
+
if (_f.refs ? _f.refs.every((ref2) => ref2.disabled) : ref.disabled) {
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
if (isFileInput(ref)) {
|
|
788
|
+
return ref.files;
|
|
789
|
+
}
|
|
790
|
+
if (isRadioInput(ref)) {
|
|
791
|
+
return getRadioValue(_f.refs).value;
|
|
792
|
+
}
|
|
793
|
+
if (isMultipleSelect(ref)) {
|
|
794
|
+
return [...ref.selectedOptions].map(({ value }) => value);
|
|
795
|
+
}
|
|
796
|
+
if (isCheckBoxInput(ref)) {
|
|
797
|
+
return getCheckboxValue(_f.refs).value;
|
|
798
|
+
}
|
|
799
|
+
return getFieldValueAs(isUndefined(ref.value) ? _f.ref.value : ref.value, _f);
|
|
800
|
+
}
|
|
801
|
+
var getResolverOptions = (fieldsNames, _fields, criteriaMode, shouldUseNativeValidation) => {
|
|
802
|
+
const fields = {};
|
|
803
|
+
for (const name of fieldsNames) {
|
|
804
|
+
const field = get(_fields, name);
|
|
805
|
+
field && set(fields, name, field._f);
|
|
806
|
+
}
|
|
807
|
+
return {
|
|
808
|
+
criteriaMode,
|
|
809
|
+
names: [...fieldsNames],
|
|
810
|
+
fields,
|
|
811
|
+
shouldUseNativeValidation
|
|
812
|
+
};
|
|
813
|
+
};
|
|
814
|
+
var getRuleValue = (rule) => isUndefined(rule) ? rule : isRegex(rule) ? rule.source : isObject(rule) ? isRegex(rule.value) ? rule.value.source : rule.value : rule;
|
|
815
|
+
var hasValidation = (options) => options.mount && (options.required || options.min || options.max || options.maxLength || options.minLength || options.pattern || options.validate);
|
|
816
|
+
function schemaErrorLookup(errors, _fields, name) {
|
|
817
|
+
const error = get(errors, name);
|
|
818
|
+
if (error || isKey(name)) {
|
|
819
|
+
return {
|
|
820
|
+
error,
|
|
821
|
+
name
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
const names = name.split(".");
|
|
825
|
+
while (names.length) {
|
|
826
|
+
const fieldName = names.join(".");
|
|
827
|
+
const field = get(_fields, fieldName);
|
|
828
|
+
const foundError = get(errors, fieldName);
|
|
829
|
+
if (field && !Array.isArray(field) && name !== fieldName) {
|
|
830
|
+
return { name };
|
|
831
|
+
}
|
|
832
|
+
if (foundError && foundError.type) {
|
|
833
|
+
return {
|
|
834
|
+
name: fieldName,
|
|
835
|
+
error: foundError
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
names.pop();
|
|
839
|
+
}
|
|
840
|
+
return {
|
|
841
|
+
name
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
var skipValidation = (isBlurEvent, isTouched, isSubmitted, reValidateMode, mode) => {
|
|
845
|
+
if (mode.isOnAll) {
|
|
846
|
+
return false;
|
|
847
|
+
} else if (!isSubmitted && mode.isOnTouch) {
|
|
848
|
+
return !(isTouched || isBlurEvent);
|
|
849
|
+
} else if (isSubmitted ? reValidateMode.isOnBlur : mode.isOnBlur) {
|
|
850
|
+
return !isBlurEvent;
|
|
851
|
+
} else if (isSubmitted ? reValidateMode.isOnChange : mode.isOnChange) {
|
|
852
|
+
return isBlurEvent;
|
|
853
|
+
}
|
|
854
|
+
return true;
|
|
855
|
+
};
|
|
856
|
+
var unsetEmptyArray = (ref, name) => !compact(get(ref, name)).length && unset(ref, name);
|
|
857
|
+
const defaultOptions = {
|
|
858
|
+
mode: VALIDATION_MODE.onSubmit,
|
|
859
|
+
reValidateMode: VALIDATION_MODE.onChange,
|
|
860
|
+
shouldFocusError: true
|
|
861
|
+
};
|
|
862
|
+
function createFormControl(props = {}, flushRootRender) {
|
|
863
|
+
let _options = {
|
|
864
|
+
...defaultOptions,
|
|
865
|
+
...props
|
|
866
|
+
};
|
|
867
|
+
let _formState = {
|
|
868
|
+
submitCount: 0,
|
|
869
|
+
isDirty: false,
|
|
870
|
+
isLoading: isFunction(_options.defaultValues),
|
|
871
|
+
isValidating: false,
|
|
872
|
+
isSubmitted: false,
|
|
873
|
+
isSubmitting: false,
|
|
874
|
+
isSubmitSuccessful: false,
|
|
875
|
+
isValid: false,
|
|
876
|
+
touchedFields: {},
|
|
877
|
+
dirtyFields: {},
|
|
878
|
+
errors: _options.errors || {},
|
|
879
|
+
disabled: false
|
|
880
|
+
};
|
|
881
|
+
let _fields = {};
|
|
882
|
+
let _defaultValues = isObject(_options.defaultValues) || isObject(_options.values) ? cloneObject(_options.defaultValues || _options.values) || {} : {};
|
|
883
|
+
let _formValues = _options.shouldUnregister ? {} : cloneObject(_defaultValues);
|
|
884
|
+
let _state = {
|
|
885
|
+
action: false,
|
|
886
|
+
mount: false,
|
|
887
|
+
watch: false
|
|
888
|
+
};
|
|
889
|
+
let _names = {
|
|
890
|
+
mount: /* @__PURE__ */ new Set(),
|
|
891
|
+
unMount: /* @__PURE__ */ new Set(),
|
|
892
|
+
array: /* @__PURE__ */ new Set(),
|
|
893
|
+
watch: /* @__PURE__ */ new Set()
|
|
894
|
+
};
|
|
895
|
+
let delayErrorCallback;
|
|
896
|
+
let timer = 0;
|
|
897
|
+
const _proxyFormState = {
|
|
898
|
+
isDirty: false,
|
|
899
|
+
dirtyFields: false,
|
|
900
|
+
touchedFields: false,
|
|
901
|
+
isValidating: false,
|
|
902
|
+
isValid: false,
|
|
903
|
+
errors: false
|
|
904
|
+
};
|
|
905
|
+
const _subjects = {
|
|
906
|
+
values: createSubject(),
|
|
907
|
+
array: createSubject(),
|
|
908
|
+
state: createSubject()
|
|
909
|
+
};
|
|
910
|
+
const shouldCaptureDirtyFields = props.resetOptions && props.resetOptions.keepDirtyValues;
|
|
911
|
+
const validationModeBeforeSubmit = getValidationModes(_options.mode);
|
|
912
|
+
const validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
|
|
913
|
+
const shouldDisplayAllAssociatedErrors = _options.criteriaMode === VALIDATION_MODE.all;
|
|
914
|
+
const debounce = (callback) => (wait) => {
|
|
915
|
+
clearTimeout(timer);
|
|
916
|
+
timer = setTimeout(callback, wait);
|
|
917
|
+
};
|
|
918
|
+
const _updateValid = async (shouldUpdateValid) => {
|
|
919
|
+
if (_proxyFormState.isValid || shouldUpdateValid) {
|
|
920
|
+
const isValid = _options.resolver ? isEmptyObject((await _executeSchema()).errors) : await executeBuiltInValidation(_fields, true);
|
|
921
|
+
if (isValid !== _formState.isValid) {
|
|
922
|
+
_subjects.state.next({
|
|
923
|
+
isValid
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
};
|
|
928
|
+
const _updateIsValidating = (value) => _proxyFormState.isValidating && _subjects.state.next({
|
|
929
|
+
isValidating: value
|
|
930
|
+
});
|
|
931
|
+
const _updateFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndState = true) => {
|
|
932
|
+
if (args && method) {
|
|
933
|
+
_state.action = true;
|
|
934
|
+
if (shouldUpdateFieldsAndState && Array.isArray(get(_fields, name))) {
|
|
935
|
+
const fieldValues = method(get(_fields, name), args.argA, args.argB);
|
|
936
|
+
shouldSetValues && set(_fields, name, fieldValues);
|
|
937
|
+
}
|
|
938
|
+
if (shouldUpdateFieldsAndState && Array.isArray(get(_formState.errors, name))) {
|
|
939
|
+
const errors = method(get(_formState.errors, name), args.argA, args.argB);
|
|
940
|
+
shouldSetValues && set(_formState.errors, name, errors);
|
|
941
|
+
unsetEmptyArray(_formState.errors, name);
|
|
942
|
+
}
|
|
943
|
+
if (_proxyFormState.touchedFields && shouldUpdateFieldsAndState && Array.isArray(get(_formState.touchedFields, name))) {
|
|
944
|
+
const touchedFields = method(get(_formState.touchedFields, name), args.argA, args.argB);
|
|
945
|
+
shouldSetValues && set(_formState.touchedFields, name, touchedFields);
|
|
946
|
+
}
|
|
947
|
+
if (_proxyFormState.dirtyFields) {
|
|
948
|
+
_formState.dirtyFields = getDirtyFields(_defaultValues, _formValues);
|
|
949
|
+
}
|
|
950
|
+
_subjects.state.next({
|
|
951
|
+
name,
|
|
952
|
+
isDirty: _getDirty(name, values),
|
|
953
|
+
dirtyFields: _formState.dirtyFields,
|
|
954
|
+
errors: _formState.errors,
|
|
955
|
+
isValid: _formState.isValid
|
|
956
|
+
});
|
|
957
|
+
} else {
|
|
958
|
+
set(_formValues, name, values);
|
|
959
|
+
}
|
|
960
|
+
};
|
|
961
|
+
const updateErrors = (name, error) => {
|
|
962
|
+
set(_formState.errors, name, error);
|
|
963
|
+
_subjects.state.next({
|
|
964
|
+
errors: _formState.errors
|
|
965
|
+
});
|
|
966
|
+
};
|
|
967
|
+
const _setErrors = (errors) => {
|
|
968
|
+
_formState.errors = errors;
|
|
969
|
+
_subjects.state.next({
|
|
970
|
+
errors: _formState.errors,
|
|
971
|
+
isValid: false
|
|
972
|
+
});
|
|
973
|
+
};
|
|
974
|
+
const updateValidAndValue = (name, shouldSkipSetValueAs, value, ref) => {
|
|
975
|
+
const field = get(_fields, name);
|
|
976
|
+
if (field) {
|
|
977
|
+
const defaultValue = get(_formValues, name, isUndefined(value) ? get(_defaultValues, name) : value);
|
|
978
|
+
isUndefined(defaultValue) || ref && ref.defaultChecked || shouldSkipSetValueAs ? set(_formValues, name, shouldSkipSetValueAs ? defaultValue : getFieldValue(field._f)) : setFieldValue(name, defaultValue);
|
|
979
|
+
_state.mount && _updateValid();
|
|
980
|
+
}
|
|
981
|
+
};
|
|
982
|
+
const updateTouchAndDirty = (name, fieldValue, isBlurEvent, shouldDirty, shouldRender) => {
|
|
983
|
+
let shouldUpdateField = false;
|
|
984
|
+
let isPreviousDirty = false;
|
|
985
|
+
const output = {
|
|
986
|
+
name
|
|
987
|
+
};
|
|
988
|
+
const disabledField = get(_fields, name) && get(_fields, name)._f.disabled;
|
|
989
|
+
if (!isBlurEvent || shouldDirty) {
|
|
990
|
+
if (_proxyFormState.isDirty) {
|
|
991
|
+
isPreviousDirty = _formState.isDirty;
|
|
992
|
+
_formState.isDirty = output.isDirty = _getDirty();
|
|
993
|
+
shouldUpdateField = isPreviousDirty !== output.isDirty;
|
|
994
|
+
}
|
|
995
|
+
const isCurrentFieldPristine = disabledField || deepEqual(get(_defaultValues, name), fieldValue);
|
|
996
|
+
isPreviousDirty = !disabledField && get(_formState.dirtyFields, name);
|
|
997
|
+
isCurrentFieldPristine || disabledField ? unset(_formState.dirtyFields, name) : set(_formState.dirtyFields, name, true);
|
|
998
|
+
output.dirtyFields = _formState.dirtyFields;
|
|
999
|
+
shouldUpdateField = shouldUpdateField || _proxyFormState.dirtyFields && isPreviousDirty !== !isCurrentFieldPristine;
|
|
1000
|
+
}
|
|
1001
|
+
if (isBlurEvent) {
|
|
1002
|
+
const isPreviousFieldTouched = get(_formState.touchedFields, name);
|
|
1003
|
+
if (!isPreviousFieldTouched) {
|
|
1004
|
+
set(_formState.touchedFields, name, isBlurEvent);
|
|
1005
|
+
output.touchedFields = _formState.touchedFields;
|
|
1006
|
+
shouldUpdateField = shouldUpdateField || _proxyFormState.touchedFields && isPreviousFieldTouched !== isBlurEvent;
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
shouldUpdateField && shouldRender && _subjects.state.next(output);
|
|
1010
|
+
return shouldUpdateField ? output : {};
|
|
1011
|
+
};
|
|
1012
|
+
const shouldRenderByError = (name, isValid, error, fieldState) => {
|
|
1013
|
+
const previousFieldError = get(_formState.errors, name);
|
|
1014
|
+
const shouldUpdateValid = _proxyFormState.isValid && isBoolean(isValid) && _formState.isValid !== isValid;
|
|
1015
|
+
if (props.delayError && error) {
|
|
1016
|
+
delayErrorCallback = debounce(() => updateErrors(name, error));
|
|
1017
|
+
delayErrorCallback(props.delayError);
|
|
1018
|
+
} else {
|
|
1019
|
+
clearTimeout(timer);
|
|
1020
|
+
delayErrorCallback = null;
|
|
1021
|
+
error ? set(_formState.errors, name, error) : unset(_formState.errors, name);
|
|
1022
|
+
}
|
|
1023
|
+
if ((error ? !deepEqual(previousFieldError, error) : previousFieldError) || !isEmptyObject(fieldState) || shouldUpdateValid) {
|
|
1024
|
+
const updatedFormState = {
|
|
1025
|
+
...fieldState,
|
|
1026
|
+
...shouldUpdateValid && isBoolean(isValid) ? { isValid } : {},
|
|
1027
|
+
errors: _formState.errors,
|
|
1028
|
+
name
|
|
1029
|
+
};
|
|
1030
|
+
_formState = {
|
|
1031
|
+
..._formState,
|
|
1032
|
+
...updatedFormState
|
|
1033
|
+
};
|
|
1034
|
+
_subjects.state.next(updatedFormState);
|
|
1035
|
+
}
|
|
1036
|
+
_updateIsValidating(false);
|
|
1037
|
+
};
|
|
1038
|
+
const _executeSchema = async (name) => _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
|
|
1039
|
+
const executeSchemaAndUpdateState = async (names) => {
|
|
1040
|
+
const { errors } = await _executeSchema(names);
|
|
1041
|
+
if (names) {
|
|
1042
|
+
for (const name of names) {
|
|
1043
|
+
const error = get(errors, name);
|
|
1044
|
+
error ? set(_formState.errors, name, error) : unset(_formState.errors, name);
|
|
1045
|
+
}
|
|
1046
|
+
} else {
|
|
1047
|
+
_formState.errors = errors;
|
|
1048
|
+
}
|
|
1049
|
+
return errors;
|
|
1050
|
+
};
|
|
1051
|
+
const executeBuiltInValidation = async (fields, shouldOnlyCheckValid, context = {
|
|
1052
|
+
valid: true
|
|
1053
|
+
}) => {
|
|
1054
|
+
for (const name in fields) {
|
|
1055
|
+
const field = fields[name];
|
|
1056
|
+
if (field) {
|
|
1057
|
+
const { _f, ...fieldValue } = field;
|
|
1058
|
+
if (_f) {
|
|
1059
|
+
const isFieldArrayRoot = _names.array.has(_f.name);
|
|
1060
|
+
const fieldError = await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation && !shouldOnlyCheckValid, isFieldArrayRoot);
|
|
1061
|
+
if (fieldError[_f.name]) {
|
|
1062
|
+
context.valid = false;
|
|
1063
|
+
if (shouldOnlyCheckValid) {
|
|
1064
|
+
break;
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
!shouldOnlyCheckValid && (get(fieldError, _f.name) ? isFieldArrayRoot ? updateFieldArrayRootError(_formState.errors, fieldError, _f.name) : set(_formState.errors, _f.name, fieldError[_f.name]) : unset(_formState.errors, _f.name));
|
|
1068
|
+
}
|
|
1069
|
+
fieldValue && await executeBuiltInValidation(fieldValue, shouldOnlyCheckValid, context);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
return context.valid;
|
|
1073
|
+
};
|
|
1074
|
+
const _removeUnmounted = () => {
|
|
1075
|
+
for (const name of _names.unMount) {
|
|
1076
|
+
const field = get(_fields, name);
|
|
1077
|
+
field && (field._f.refs ? field._f.refs.every((ref) => !live(ref)) : !live(field._f.ref)) && unregister(name);
|
|
1078
|
+
}
|
|
1079
|
+
_names.unMount = /* @__PURE__ */ new Set();
|
|
1080
|
+
};
|
|
1081
|
+
const _getDirty = (name, data) => (name && data && set(_formValues, name, data), !deepEqual(getValues(), _defaultValues));
|
|
1082
|
+
const _getWatch = (names, defaultValue, isGlobal) => generateWatchOutput(names, _names, {
|
|
1083
|
+
..._state.mount ? _formValues : isUndefined(defaultValue) ? _defaultValues : isString(names) ? { [names]: defaultValue } : defaultValue
|
|
1084
|
+
}, isGlobal, defaultValue);
|
|
1085
|
+
const _getFieldArray = (name) => compact(get(_state.mount ? _formValues : _defaultValues, name, props.shouldUnregister ? get(_defaultValues, name, []) : []));
|
|
1086
|
+
const setFieldValue = (name, value, options = {}) => {
|
|
1087
|
+
const field = get(_fields, name);
|
|
1088
|
+
let fieldValue = value;
|
|
1089
|
+
if (field) {
|
|
1090
|
+
const fieldReference = field._f;
|
|
1091
|
+
if (fieldReference) {
|
|
1092
|
+
!fieldReference.disabled && set(_formValues, name, getFieldValueAs(value, fieldReference));
|
|
1093
|
+
fieldValue = isHTMLElement(fieldReference.ref) && isNullOrUndefined(value) ? "" : value;
|
|
1094
|
+
if (isMultipleSelect(fieldReference.ref)) {
|
|
1095
|
+
[...fieldReference.ref.options].forEach((optionRef) => optionRef.selected = fieldValue.includes(optionRef.value));
|
|
1096
|
+
} else if (fieldReference.refs) {
|
|
1097
|
+
if (isCheckBoxInput(fieldReference.ref)) {
|
|
1098
|
+
fieldReference.refs.length > 1 ? fieldReference.refs.forEach((checkboxRef) => (!checkboxRef.defaultChecked || !checkboxRef.disabled) && (checkboxRef.checked = Array.isArray(fieldValue) ? !!fieldValue.find((data) => data === checkboxRef.value) : fieldValue === checkboxRef.value)) : fieldReference.refs[0] && (fieldReference.refs[0].checked = !!fieldValue);
|
|
1099
|
+
} else {
|
|
1100
|
+
fieldReference.refs.forEach((radioRef) => radioRef.checked = radioRef.value === fieldValue);
|
|
1101
|
+
}
|
|
1102
|
+
} else if (isFileInput(fieldReference.ref)) {
|
|
1103
|
+
fieldReference.ref.value = "";
|
|
1104
|
+
} else {
|
|
1105
|
+
fieldReference.ref.value = fieldValue;
|
|
1106
|
+
if (!fieldReference.ref.type) {
|
|
1107
|
+
_subjects.values.next({
|
|
1108
|
+
name,
|
|
1109
|
+
values: { ..._formValues }
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
(options.shouldDirty || options.shouldTouch) && updateTouchAndDirty(name, fieldValue, options.shouldTouch, options.shouldDirty, true);
|
|
1116
|
+
options.shouldValidate && trigger(name);
|
|
1117
|
+
};
|
|
1118
|
+
const setValues = (name, value, options) => {
|
|
1119
|
+
for (const fieldKey in value) {
|
|
1120
|
+
const fieldValue = value[fieldKey];
|
|
1121
|
+
const fieldName = `${name}.${fieldKey}`;
|
|
1122
|
+
const field = get(_fields, fieldName);
|
|
1123
|
+
(_names.array.has(name) || !isPrimitive(fieldValue) || field && !field._f) && !isDateObject(fieldValue) ? setValues(fieldName, fieldValue, options) : setFieldValue(fieldName, fieldValue, options);
|
|
1124
|
+
}
|
|
1125
|
+
};
|
|
1126
|
+
const setValue = (name, value, options = {}) => {
|
|
1127
|
+
const field = get(_fields, name);
|
|
1128
|
+
const isFieldArray = _names.array.has(name);
|
|
1129
|
+
const cloneValue = cloneObject(value);
|
|
1130
|
+
set(_formValues, name, cloneValue);
|
|
1131
|
+
if (isFieldArray) {
|
|
1132
|
+
_subjects.array.next({
|
|
1133
|
+
name,
|
|
1134
|
+
values: { ..._formValues }
|
|
1135
|
+
});
|
|
1136
|
+
if ((_proxyFormState.isDirty || _proxyFormState.dirtyFields) && options.shouldDirty) {
|
|
1137
|
+
_subjects.state.next({
|
|
1138
|
+
name,
|
|
1139
|
+
dirtyFields: getDirtyFields(_defaultValues, _formValues),
|
|
1140
|
+
isDirty: _getDirty(name, cloneValue)
|
|
1141
|
+
});
|
|
1142
|
+
}
|
|
1143
|
+
} else {
|
|
1144
|
+
field && !field._f && !isNullOrUndefined(cloneValue) ? setValues(name, cloneValue, options) : setFieldValue(name, cloneValue, options);
|
|
1145
|
+
}
|
|
1146
|
+
isWatched(name, _names) && _subjects.state.next({ ..._formState });
|
|
1147
|
+
_subjects.values.next({
|
|
1148
|
+
name,
|
|
1149
|
+
values: { ..._formValues }
|
|
1150
|
+
});
|
|
1151
|
+
!_state.mount && flushRootRender();
|
|
1152
|
+
};
|
|
1153
|
+
const onChange = async (event) => {
|
|
1154
|
+
const target = event.target;
|
|
1155
|
+
let name = target.name;
|
|
1156
|
+
let isFieldValueUpdated = true;
|
|
1157
|
+
const field = get(_fields, name);
|
|
1158
|
+
const getCurrentFieldValue = () => target.type ? getFieldValue(field._f) : getEventValue(event);
|
|
1159
|
+
const _updateIsFieldValueUpdated = (fieldValue) => {
|
|
1160
|
+
isFieldValueUpdated = Number.isNaN(fieldValue) || fieldValue === get(_formValues, name, fieldValue);
|
|
1161
|
+
};
|
|
1162
|
+
if (field) {
|
|
1163
|
+
let error;
|
|
1164
|
+
let isValid;
|
|
1165
|
+
const fieldValue = getCurrentFieldValue();
|
|
1166
|
+
const isBlurEvent = event.type === EVENTS.BLUR || event.type === EVENTS.FOCUS_OUT;
|
|
1167
|
+
const shouldSkipValidation = !hasValidation(field._f) && !_options.resolver && !get(_formState.errors, name) && !field._f.deps || skipValidation(isBlurEvent, get(_formState.touchedFields, name), _formState.isSubmitted, validationModeAfterSubmit, validationModeBeforeSubmit);
|
|
1168
|
+
const watched = isWatched(name, _names, isBlurEvent);
|
|
1169
|
+
set(_formValues, name, fieldValue);
|
|
1170
|
+
if (isBlurEvent) {
|
|
1171
|
+
field._f.onBlur && field._f.onBlur(event);
|
|
1172
|
+
delayErrorCallback && delayErrorCallback(0);
|
|
1173
|
+
} else if (field._f.onChange) {
|
|
1174
|
+
field._f.onChange(event);
|
|
1175
|
+
}
|
|
1176
|
+
const fieldState = updateTouchAndDirty(name, fieldValue, isBlurEvent, false);
|
|
1177
|
+
const shouldRender = !isEmptyObject(fieldState) || watched;
|
|
1178
|
+
!isBlurEvent && _subjects.values.next({
|
|
1179
|
+
name,
|
|
1180
|
+
type: event.type,
|
|
1181
|
+
values: { ..._formValues }
|
|
1182
|
+
});
|
|
1183
|
+
if (shouldSkipValidation) {
|
|
1184
|
+
_proxyFormState.isValid && _updateValid();
|
|
1185
|
+
return shouldRender && _subjects.state.next({ name, ...watched ? {} : fieldState });
|
|
1186
|
+
}
|
|
1187
|
+
!isBlurEvent && watched && _subjects.state.next({ ..._formState });
|
|
1188
|
+
_updateIsValidating(true);
|
|
1189
|
+
if (_options.resolver) {
|
|
1190
|
+
const { errors } = await _executeSchema([name]);
|
|
1191
|
+
_updateIsFieldValueUpdated(fieldValue);
|
|
1192
|
+
if (isFieldValueUpdated) {
|
|
1193
|
+
const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
|
|
1194
|
+
const errorLookupResult = schemaErrorLookup(errors, _fields, previousErrorLookupResult.name || name);
|
|
1195
|
+
error = errorLookupResult.error;
|
|
1196
|
+
name = errorLookupResult.name;
|
|
1197
|
+
isValid = isEmptyObject(errors);
|
|
1198
|
+
}
|
|
1199
|
+
} else {
|
|
1200
|
+
error = (await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
|
|
1201
|
+
_updateIsFieldValueUpdated(fieldValue);
|
|
1202
|
+
if (isFieldValueUpdated) {
|
|
1203
|
+
if (error) {
|
|
1204
|
+
isValid = false;
|
|
1205
|
+
} else if (_proxyFormState.isValid) {
|
|
1206
|
+
isValid = await executeBuiltInValidation(_fields, true);
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
if (isFieldValueUpdated) {
|
|
1211
|
+
field._f.deps && trigger(field._f.deps);
|
|
1212
|
+
shouldRenderByError(name, isValid, error, fieldState);
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
};
|
|
1216
|
+
const _focusInput = (ref, key) => {
|
|
1217
|
+
if (get(_formState.errors, key) && ref.focus) {
|
|
1218
|
+
ref.focus();
|
|
1219
|
+
return 1;
|
|
1220
|
+
}
|
|
1221
|
+
return;
|
|
1222
|
+
};
|
|
1223
|
+
const trigger = async (name, options = {}) => {
|
|
1224
|
+
let isValid;
|
|
1225
|
+
let validationResult;
|
|
1226
|
+
const fieldNames = convertToArrayPayload(name);
|
|
1227
|
+
_updateIsValidating(true);
|
|
1228
|
+
if (_options.resolver) {
|
|
1229
|
+
const errors = await executeSchemaAndUpdateState(isUndefined(name) ? name : fieldNames);
|
|
1230
|
+
isValid = isEmptyObject(errors);
|
|
1231
|
+
validationResult = name ? !fieldNames.some((name2) => get(errors, name2)) : isValid;
|
|
1232
|
+
} else if (name) {
|
|
1233
|
+
validationResult = (await Promise.all(fieldNames.map(async (fieldName) => {
|
|
1234
|
+
const field = get(_fields, fieldName);
|
|
1235
|
+
return await executeBuiltInValidation(field && field._f ? { [fieldName]: field } : field);
|
|
1236
|
+
}))).every(Boolean);
|
|
1237
|
+
!(!validationResult && !_formState.isValid) && _updateValid();
|
|
1238
|
+
} else {
|
|
1239
|
+
validationResult = isValid = await executeBuiltInValidation(_fields);
|
|
1240
|
+
}
|
|
1241
|
+
_subjects.state.next({
|
|
1242
|
+
...!isString(name) || _proxyFormState.isValid && isValid !== _formState.isValid ? {} : { name },
|
|
1243
|
+
..._options.resolver || !name ? { isValid } : {},
|
|
1244
|
+
errors: _formState.errors,
|
|
1245
|
+
isValidating: false
|
|
1246
|
+
});
|
|
1247
|
+
options.shouldFocus && !validationResult && iterateFieldsByAction(_fields, _focusInput, name ? fieldNames : _names.mount);
|
|
1248
|
+
return validationResult;
|
|
1249
|
+
};
|
|
1250
|
+
const getValues = (fieldNames) => {
|
|
1251
|
+
const values = {
|
|
1252
|
+
..._defaultValues,
|
|
1253
|
+
..._state.mount ? _formValues : {}
|
|
1254
|
+
};
|
|
1255
|
+
return isUndefined(fieldNames) ? values : isString(fieldNames) ? get(values, fieldNames) : fieldNames.map((name) => get(values, name));
|
|
1256
|
+
};
|
|
1257
|
+
const getFieldState = (name, formState) => ({
|
|
1258
|
+
invalid: !!get((formState || _formState).errors, name),
|
|
1259
|
+
isDirty: !!get((formState || _formState).dirtyFields, name),
|
|
1260
|
+
isTouched: !!get((formState || _formState).touchedFields, name),
|
|
1261
|
+
error: get((formState || _formState).errors, name)
|
|
1262
|
+
});
|
|
1263
|
+
const clearErrors = (name) => {
|
|
1264
|
+
name && convertToArrayPayload(name).forEach((inputName) => unset(_formState.errors, inputName));
|
|
1265
|
+
_subjects.state.next({
|
|
1266
|
+
errors: name ? _formState.errors : {}
|
|
1267
|
+
});
|
|
1268
|
+
};
|
|
1269
|
+
const setError = (name, error, options) => {
|
|
1270
|
+
const ref = (get(_fields, name, { _f: {} })._f || {}).ref;
|
|
1271
|
+
set(_formState.errors, name, {
|
|
1272
|
+
...error,
|
|
1273
|
+
ref
|
|
1274
|
+
});
|
|
1275
|
+
_subjects.state.next({
|
|
1276
|
+
name,
|
|
1277
|
+
errors: _formState.errors,
|
|
1278
|
+
isValid: false
|
|
1279
|
+
});
|
|
1280
|
+
options && options.shouldFocus && ref && ref.focus && ref.focus();
|
|
1281
|
+
};
|
|
1282
|
+
const watch = (name, defaultValue) => isFunction(name) ? _subjects.values.subscribe({
|
|
1283
|
+
next: (payload) => name(_getWatch(void 0, defaultValue), payload)
|
|
1284
|
+
}) : _getWatch(name, defaultValue, true);
|
|
1285
|
+
const unregister = (name, options = {}) => {
|
|
1286
|
+
for (const fieldName of name ? convertToArrayPayload(name) : _names.mount) {
|
|
1287
|
+
_names.mount.delete(fieldName);
|
|
1288
|
+
_names.array.delete(fieldName);
|
|
1289
|
+
if (!options.keepValue) {
|
|
1290
|
+
unset(_fields, fieldName);
|
|
1291
|
+
unset(_formValues, fieldName);
|
|
1292
|
+
}
|
|
1293
|
+
!options.keepError && unset(_formState.errors, fieldName);
|
|
1294
|
+
!options.keepDirty && unset(_formState.dirtyFields, fieldName);
|
|
1295
|
+
!options.keepTouched && unset(_formState.touchedFields, fieldName);
|
|
1296
|
+
!_options.shouldUnregister && !options.keepDefaultValue && unset(_defaultValues, fieldName);
|
|
1297
|
+
}
|
|
1298
|
+
_subjects.values.next({
|
|
1299
|
+
values: { ..._formValues }
|
|
1300
|
+
});
|
|
1301
|
+
_subjects.state.next({
|
|
1302
|
+
..._formState,
|
|
1303
|
+
...!options.keepDirty ? {} : { isDirty: _getDirty() }
|
|
1304
|
+
});
|
|
1305
|
+
!options.keepIsValid && _updateValid();
|
|
1306
|
+
};
|
|
1307
|
+
const _updateDisabledField = ({ disabled, name, field, fields, value }) => {
|
|
1308
|
+
if (isBoolean(disabled)) {
|
|
1309
|
+
const inputValue = disabled ? void 0 : isUndefined(value) ? getFieldValue(field ? field._f : get(fields, name)._f) : value;
|
|
1310
|
+
set(_formValues, name, inputValue);
|
|
1311
|
+
updateTouchAndDirty(name, inputValue, false, false, true);
|
|
1312
|
+
}
|
|
1313
|
+
};
|
|
1314
|
+
const register = (name, options = {}) => {
|
|
1315
|
+
let field = get(_fields, name);
|
|
1316
|
+
const disabledIsDefined = isBoolean(options.disabled);
|
|
1317
|
+
set(_fields, name, {
|
|
1318
|
+
...field || {},
|
|
1319
|
+
_f: {
|
|
1320
|
+
...field && field._f ? field._f : { ref: { name } },
|
|
1321
|
+
name,
|
|
1322
|
+
mount: true,
|
|
1323
|
+
...options
|
|
1324
|
+
}
|
|
1325
|
+
});
|
|
1326
|
+
_names.mount.add(name);
|
|
1327
|
+
if (field) {
|
|
1328
|
+
_updateDisabledField({
|
|
1329
|
+
field,
|
|
1330
|
+
disabled: options.disabled,
|
|
1331
|
+
name
|
|
1332
|
+
});
|
|
1333
|
+
} else {
|
|
1334
|
+
updateValidAndValue(name, true, options.value);
|
|
1335
|
+
}
|
|
1336
|
+
return {
|
|
1337
|
+
...disabledIsDefined ? { disabled: options.disabled } : {},
|
|
1338
|
+
..._options.progressive ? {
|
|
1339
|
+
required: !!options.required,
|
|
1340
|
+
min: getRuleValue(options.min),
|
|
1341
|
+
max: getRuleValue(options.max),
|
|
1342
|
+
minLength: getRuleValue(options.minLength),
|
|
1343
|
+
maxLength: getRuleValue(options.maxLength),
|
|
1344
|
+
pattern: getRuleValue(options.pattern)
|
|
1345
|
+
} : {},
|
|
1346
|
+
name,
|
|
1347
|
+
onChange,
|
|
1348
|
+
onBlur: onChange,
|
|
1349
|
+
ref: (ref) => {
|
|
1350
|
+
if (ref) {
|
|
1351
|
+
register(name, options);
|
|
1352
|
+
field = get(_fields, name);
|
|
1353
|
+
const fieldRef = isUndefined(ref.value) ? ref.querySelectorAll ? ref.querySelectorAll("input,select,textarea")[0] || ref : ref : ref;
|
|
1354
|
+
const radioOrCheckbox = isRadioOrCheckbox(fieldRef);
|
|
1355
|
+
const refs = field._f.refs || [];
|
|
1356
|
+
if (radioOrCheckbox ? refs.find((option) => option === fieldRef) : fieldRef === field._f.ref) {
|
|
1357
|
+
return;
|
|
1358
|
+
}
|
|
1359
|
+
set(_fields, name, {
|
|
1360
|
+
_f: {
|
|
1361
|
+
...field._f,
|
|
1362
|
+
...radioOrCheckbox ? {
|
|
1363
|
+
refs: [
|
|
1364
|
+
...refs.filter(live),
|
|
1365
|
+
fieldRef,
|
|
1366
|
+
...Array.isArray(get(_defaultValues, name)) ? [{}] : []
|
|
1367
|
+
],
|
|
1368
|
+
ref: { type: fieldRef.type, name }
|
|
1369
|
+
} : { ref: fieldRef }
|
|
1370
|
+
}
|
|
1371
|
+
});
|
|
1372
|
+
updateValidAndValue(name, false, void 0, fieldRef);
|
|
1373
|
+
} else {
|
|
1374
|
+
field = get(_fields, name, {});
|
|
1375
|
+
if (field._f) {
|
|
1376
|
+
field._f.mount = false;
|
|
1377
|
+
}
|
|
1378
|
+
(_options.shouldUnregister || options.shouldUnregister) && !(isNameInFieldArray(_names.array, name) && _state.action) && _names.unMount.add(name);
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
};
|
|
1382
|
+
};
|
|
1383
|
+
const _focusError = () => _options.shouldFocusError && iterateFieldsByAction(_fields, _focusInput, _names.mount);
|
|
1384
|
+
const _disableForm = (disabled) => {
|
|
1385
|
+
if (isBoolean(disabled)) {
|
|
1386
|
+
_subjects.state.next({ disabled });
|
|
1387
|
+
iterateFieldsByAction(_fields, (ref, name) => {
|
|
1388
|
+
let requiredDisabledState = disabled;
|
|
1389
|
+
const currentField = get(_fields, name);
|
|
1390
|
+
if (currentField && isBoolean(currentField._f.disabled)) {
|
|
1391
|
+
requiredDisabledState || (requiredDisabledState = currentField._f.disabled);
|
|
1392
|
+
}
|
|
1393
|
+
ref.disabled = requiredDisabledState;
|
|
1394
|
+
}, 0, false);
|
|
1395
|
+
}
|
|
1396
|
+
};
|
|
1397
|
+
const handleSubmit = (onValid, onInvalid) => async (e) => {
|
|
1398
|
+
if (e) {
|
|
1399
|
+
e.preventDefault && e.preventDefault();
|
|
1400
|
+
e.persist && e.persist();
|
|
1401
|
+
}
|
|
1402
|
+
let fieldValues = cloneObject(_formValues);
|
|
1403
|
+
_subjects.state.next({
|
|
1404
|
+
isSubmitting: true
|
|
1405
|
+
});
|
|
1406
|
+
if (_options.resolver) {
|
|
1407
|
+
const { errors, values } = await _executeSchema();
|
|
1408
|
+
_formState.errors = errors;
|
|
1409
|
+
fieldValues = values;
|
|
1410
|
+
} else {
|
|
1411
|
+
await executeBuiltInValidation(_fields);
|
|
1412
|
+
}
|
|
1413
|
+
unset(_formState.errors, "root");
|
|
1414
|
+
if (isEmptyObject(_formState.errors)) {
|
|
1415
|
+
_subjects.state.next({
|
|
1416
|
+
errors: {}
|
|
1417
|
+
});
|
|
1418
|
+
await onValid(fieldValues, e);
|
|
1419
|
+
} else {
|
|
1420
|
+
if (onInvalid) {
|
|
1421
|
+
await onInvalid({ ..._formState.errors }, e);
|
|
1422
|
+
}
|
|
1423
|
+
_focusError();
|
|
1424
|
+
setTimeout(_focusError);
|
|
1425
|
+
}
|
|
1426
|
+
_subjects.state.next({
|
|
1427
|
+
isSubmitted: true,
|
|
1428
|
+
isSubmitting: false,
|
|
1429
|
+
isSubmitSuccessful: isEmptyObject(_formState.errors),
|
|
1430
|
+
submitCount: _formState.submitCount + 1,
|
|
1431
|
+
errors: _formState.errors
|
|
1432
|
+
});
|
|
1433
|
+
};
|
|
1434
|
+
const resetField = (name, options = {}) => {
|
|
1435
|
+
if (get(_fields, name)) {
|
|
1436
|
+
if (isUndefined(options.defaultValue)) {
|
|
1437
|
+
setValue(name, get(_defaultValues, name));
|
|
1438
|
+
} else {
|
|
1439
|
+
setValue(name, options.defaultValue);
|
|
1440
|
+
set(_defaultValues, name, options.defaultValue);
|
|
1441
|
+
}
|
|
1442
|
+
if (!options.keepTouched) {
|
|
1443
|
+
unset(_formState.touchedFields, name);
|
|
1444
|
+
}
|
|
1445
|
+
if (!options.keepDirty) {
|
|
1446
|
+
unset(_formState.dirtyFields, name);
|
|
1447
|
+
_formState.isDirty = options.defaultValue ? _getDirty(name, get(_defaultValues, name)) : _getDirty();
|
|
1448
|
+
}
|
|
1449
|
+
if (!options.keepError) {
|
|
1450
|
+
unset(_formState.errors, name);
|
|
1451
|
+
_proxyFormState.isValid && _updateValid();
|
|
1452
|
+
}
|
|
1453
|
+
_subjects.state.next({ ..._formState });
|
|
1454
|
+
}
|
|
1455
|
+
};
|
|
1456
|
+
const _reset = (formValues, keepStateOptions = {}) => {
|
|
1457
|
+
const updatedValues = formValues ? cloneObject(formValues) : _defaultValues;
|
|
1458
|
+
const cloneUpdatedValues = cloneObject(updatedValues);
|
|
1459
|
+
const values = formValues && !isEmptyObject(formValues) ? cloneUpdatedValues : _defaultValues;
|
|
1460
|
+
if (!keepStateOptions.keepDefaultValues) {
|
|
1461
|
+
_defaultValues = updatedValues;
|
|
1462
|
+
}
|
|
1463
|
+
if (!keepStateOptions.keepValues) {
|
|
1464
|
+
if (keepStateOptions.keepDirtyValues || shouldCaptureDirtyFields) {
|
|
1465
|
+
for (const fieldName of _names.mount) {
|
|
1466
|
+
get(_formState.dirtyFields, fieldName) ? set(values, fieldName, get(_formValues, fieldName)) : setValue(fieldName, get(values, fieldName));
|
|
1467
|
+
}
|
|
1468
|
+
} else {
|
|
1469
|
+
if (isWeb && isUndefined(formValues)) {
|
|
1470
|
+
for (const name of _names.mount) {
|
|
1471
|
+
const field = get(_fields, name);
|
|
1472
|
+
if (field && field._f) {
|
|
1473
|
+
const fieldReference = Array.isArray(field._f.refs) ? field._f.refs[0] : field._f.ref;
|
|
1474
|
+
if (isHTMLElement(fieldReference)) {
|
|
1475
|
+
const form = fieldReference.closest("form");
|
|
1476
|
+
if (form) {
|
|
1477
|
+
form.reset();
|
|
1478
|
+
break;
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
_fields = {};
|
|
1485
|
+
}
|
|
1486
|
+
_formValues = props.shouldUnregister ? keepStateOptions.keepDefaultValues ? cloneObject(_defaultValues) : {} : cloneObject(values);
|
|
1487
|
+
_subjects.array.next({
|
|
1488
|
+
values: { ...values }
|
|
1489
|
+
});
|
|
1490
|
+
_subjects.values.next({
|
|
1491
|
+
values: { ...values }
|
|
1492
|
+
});
|
|
1493
|
+
}
|
|
1494
|
+
_names = {
|
|
1495
|
+
mount: /* @__PURE__ */ new Set(),
|
|
1496
|
+
unMount: /* @__PURE__ */ new Set(),
|
|
1497
|
+
array: /* @__PURE__ */ new Set(),
|
|
1498
|
+
watch: /* @__PURE__ */ new Set(),
|
|
1499
|
+
watchAll: false,
|
|
1500
|
+
focus: ""
|
|
1501
|
+
};
|
|
1502
|
+
!_state.mount && flushRootRender();
|
|
1503
|
+
_state.mount = !_proxyFormState.isValid || !!keepStateOptions.keepIsValid;
|
|
1504
|
+
_state.watch = !!props.shouldUnregister;
|
|
1505
|
+
_subjects.state.next({
|
|
1506
|
+
submitCount: keepStateOptions.keepSubmitCount ? _formState.submitCount : 0,
|
|
1507
|
+
isDirty: keepStateOptions.keepDirty ? _formState.isDirty : !!(keepStateOptions.keepDefaultValues && !deepEqual(formValues, _defaultValues)),
|
|
1508
|
+
isSubmitted: keepStateOptions.keepIsSubmitted ? _formState.isSubmitted : false,
|
|
1509
|
+
dirtyFields: keepStateOptions.keepDirtyValues ? _formState.dirtyFields : keepStateOptions.keepDefaultValues && formValues ? getDirtyFields(_defaultValues, formValues) : {},
|
|
1510
|
+
touchedFields: keepStateOptions.keepTouched ? _formState.touchedFields : {},
|
|
1511
|
+
errors: keepStateOptions.keepErrors ? _formState.errors : {},
|
|
1512
|
+
isSubmitSuccessful: keepStateOptions.keepIsSubmitSuccessful ? _formState.isSubmitSuccessful : false,
|
|
1513
|
+
isSubmitting: false
|
|
1514
|
+
});
|
|
1515
|
+
};
|
|
1516
|
+
const reset = (formValues, keepStateOptions) => _reset(isFunction(formValues) ? formValues(_formValues) : formValues, keepStateOptions);
|
|
1517
|
+
const setFocus = (name, options = {}) => {
|
|
1518
|
+
const field = get(_fields, name);
|
|
1519
|
+
const fieldReference = field && field._f;
|
|
1520
|
+
if (fieldReference) {
|
|
1521
|
+
const fieldRef = fieldReference.refs ? fieldReference.refs[0] : fieldReference.ref;
|
|
1522
|
+
if (fieldRef.focus) {
|
|
1523
|
+
fieldRef.focus();
|
|
1524
|
+
options.shouldSelect && fieldRef.select();
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
};
|
|
1528
|
+
const _updateFormState = (updatedFormState) => {
|
|
1529
|
+
_formState = {
|
|
1530
|
+
..._formState,
|
|
1531
|
+
...updatedFormState
|
|
1532
|
+
};
|
|
1533
|
+
};
|
|
1534
|
+
const _resetDefaultValues = () => isFunction(_options.defaultValues) && _options.defaultValues().then((values) => {
|
|
1535
|
+
reset(values, _options.resetOptions);
|
|
1536
|
+
_subjects.state.next({
|
|
1537
|
+
isLoading: false
|
|
1538
|
+
});
|
|
1539
|
+
});
|
|
1540
|
+
return {
|
|
1541
|
+
control: {
|
|
1542
|
+
register,
|
|
1543
|
+
unregister,
|
|
1544
|
+
getFieldState,
|
|
1545
|
+
handleSubmit,
|
|
1546
|
+
setError,
|
|
1547
|
+
_executeSchema,
|
|
1548
|
+
_getWatch,
|
|
1549
|
+
_getDirty,
|
|
1550
|
+
_updateValid,
|
|
1551
|
+
_removeUnmounted,
|
|
1552
|
+
_updateFieldArray,
|
|
1553
|
+
_updateDisabledField,
|
|
1554
|
+
_getFieldArray,
|
|
1555
|
+
_reset,
|
|
1556
|
+
_resetDefaultValues,
|
|
1557
|
+
_updateFormState,
|
|
1558
|
+
_disableForm,
|
|
1559
|
+
_subjects,
|
|
1560
|
+
_proxyFormState,
|
|
1561
|
+
_setErrors,
|
|
1562
|
+
get _fields() {
|
|
1563
|
+
return _fields;
|
|
1564
|
+
},
|
|
1565
|
+
get _formValues() {
|
|
1566
|
+
return _formValues;
|
|
1567
|
+
},
|
|
1568
|
+
get _state() {
|
|
1569
|
+
return _state;
|
|
1570
|
+
},
|
|
1571
|
+
set _state(value) {
|
|
1572
|
+
_state = value;
|
|
1573
|
+
},
|
|
1574
|
+
get _defaultValues() {
|
|
1575
|
+
return _defaultValues;
|
|
1576
|
+
},
|
|
1577
|
+
get _names() {
|
|
1578
|
+
return _names;
|
|
1579
|
+
},
|
|
1580
|
+
set _names(value) {
|
|
1581
|
+
_names = value;
|
|
1582
|
+
},
|
|
1583
|
+
get _formState() {
|
|
1584
|
+
return _formState;
|
|
1585
|
+
},
|
|
1586
|
+
set _formState(value) {
|
|
1587
|
+
_formState = value;
|
|
1588
|
+
},
|
|
1589
|
+
get _options() {
|
|
1590
|
+
return _options;
|
|
1591
|
+
},
|
|
1592
|
+
set _options(value) {
|
|
1593
|
+
_options = {
|
|
1594
|
+
..._options,
|
|
1595
|
+
...value
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
},
|
|
1599
|
+
trigger,
|
|
1600
|
+
register,
|
|
1601
|
+
handleSubmit,
|
|
1602
|
+
watch,
|
|
1603
|
+
setValue,
|
|
1604
|
+
getValues,
|
|
1605
|
+
reset,
|
|
1606
|
+
resetField,
|
|
1607
|
+
clearErrors,
|
|
1608
|
+
unregister,
|
|
1609
|
+
setError,
|
|
1610
|
+
setFocus,
|
|
1611
|
+
getFieldState
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1614
|
+
function useForm(props = {}) {
|
|
1615
|
+
const _formControl = React__default.default.useRef();
|
|
1616
|
+
const _values = React__default.default.useRef();
|
|
1617
|
+
const [formState, updateFormState] = React__default.default.useState({
|
|
1618
|
+
isDirty: false,
|
|
1619
|
+
isValidating: false,
|
|
1620
|
+
isLoading: isFunction(props.defaultValues),
|
|
1621
|
+
isSubmitted: false,
|
|
1622
|
+
isSubmitting: false,
|
|
1623
|
+
isSubmitSuccessful: false,
|
|
1624
|
+
isValid: false,
|
|
1625
|
+
submitCount: 0,
|
|
1626
|
+
dirtyFields: {},
|
|
1627
|
+
touchedFields: {},
|
|
1628
|
+
errors: props.errors || {},
|
|
1629
|
+
disabled: false,
|
|
1630
|
+
defaultValues: isFunction(props.defaultValues) ? void 0 : props.defaultValues
|
|
1631
|
+
});
|
|
1632
|
+
if (!_formControl.current) {
|
|
1633
|
+
_formControl.current = {
|
|
1634
|
+
...createFormControl(props, () => updateFormState((formState2) => ({ ...formState2 }))),
|
|
1635
|
+
formState
|
|
1636
|
+
};
|
|
1637
|
+
}
|
|
1638
|
+
const control = _formControl.current.control;
|
|
1639
|
+
control._options = props;
|
|
1640
|
+
useSubscribe({
|
|
1641
|
+
subject: control._subjects.state,
|
|
1642
|
+
next: (value) => {
|
|
1643
|
+
if (shouldRenderFormState(value, control._proxyFormState, control._updateFormState, true)) {
|
|
1644
|
+
updateFormState({ ...control._formState });
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
});
|
|
1648
|
+
React__default.default.useEffect(() => control._disableForm(props.disabled), [control, props.disabled]);
|
|
1649
|
+
React__default.default.useEffect(() => {
|
|
1650
|
+
if (control._proxyFormState.isDirty) {
|
|
1651
|
+
const isDirty = control._getDirty();
|
|
1652
|
+
if (isDirty !== formState.isDirty) {
|
|
1653
|
+
control._subjects.state.next({
|
|
1654
|
+
isDirty
|
|
1655
|
+
});
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
}, [control, formState.isDirty]);
|
|
1659
|
+
React__default.default.useEffect(() => {
|
|
1660
|
+
if (props.values && !deepEqual(props.values, _values.current)) {
|
|
1661
|
+
control._reset(props.values, control._options.resetOptions);
|
|
1662
|
+
_values.current = props.values;
|
|
1663
|
+
updateFormState((state) => ({ ...state }));
|
|
1664
|
+
} else {
|
|
1665
|
+
control._resetDefaultValues();
|
|
1666
|
+
}
|
|
1667
|
+
}, [props.values, control]);
|
|
1668
|
+
React__default.default.useEffect(() => {
|
|
1669
|
+
if (props.errors) {
|
|
1670
|
+
control._setErrors(props.errors);
|
|
1671
|
+
}
|
|
1672
|
+
}, [props.errors, control]);
|
|
1673
|
+
React__default.default.useEffect(() => {
|
|
1674
|
+
if (!control._state.mount) {
|
|
1675
|
+
control._updateValid();
|
|
1676
|
+
control._state.mount = true;
|
|
1677
|
+
}
|
|
1678
|
+
if (control._state.watch) {
|
|
1679
|
+
control._state.watch = false;
|
|
1680
|
+
control._subjects.state.next({ ...control._formState });
|
|
1681
|
+
}
|
|
1682
|
+
control._removeUnmounted();
|
|
1683
|
+
});
|
|
1684
|
+
_formControl.current.formState = getProxyFormState(formState, control);
|
|
1685
|
+
return _formControl.current;
|
|
1686
|
+
}
|
|
1687
|
+
const jsonToText = (v) => v === void 0 || v === "" ? "" : JSON.stringify(v, null, 2);
|
|
1688
|
+
const JsonField = ({ field, f }) => {
|
|
1689
|
+
const { t } = reactI18next.useTranslation();
|
|
1690
|
+
const [raw, setRaw] = React.useState(() => jsonToText(f.value));
|
|
1691
|
+
const [error, setError] = React.useState(null);
|
|
1692
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1693
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1694
|
+
ui.Textarea,
|
|
1695
|
+
{
|
|
1696
|
+
rows: 6,
|
|
1697
|
+
className: "font-mono",
|
|
1698
|
+
placeholder: field.placeholder ? t(field.placeholder) : "[]",
|
|
1699
|
+
value: raw,
|
|
1700
|
+
disabled: field.readonly === true,
|
|
1701
|
+
onBlur: f.onBlur,
|
|
1702
|
+
onChange: (e) => {
|
|
1703
|
+
const text = e.target.value;
|
|
1704
|
+
setRaw(text);
|
|
1705
|
+
if (text.trim() === "") {
|
|
1706
|
+
setError(null);
|
|
1707
|
+
f.onChange(void 0);
|
|
1708
|
+
return;
|
|
1709
|
+
}
|
|
1710
|
+
try {
|
|
1711
|
+
f.onChange(JSON.parse(text));
|
|
1712
|
+
setError(null);
|
|
1713
|
+
} catch {
|
|
1714
|
+
setError(t("integration.form.invalidJson"));
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
),
|
|
1719
|
+
error && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xsmall", className: "text-ui-fg-error", children: error })
|
|
1720
|
+
] });
|
|
1721
|
+
};
|
|
1722
|
+
const IntegrationField = ({
|
|
1723
|
+
field,
|
|
1724
|
+
control,
|
|
1725
|
+
secretConfigured = false
|
|
1726
|
+
}) => {
|
|
1727
|
+
const { t } = reactI18next.useTranslation();
|
|
1728
|
+
const enforceRequired = field.required && field.control !== "switch" && !(field.control === "secret" && secretConfigured);
|
|
1729
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
1730
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Label, { size: "small", weight: "plus", children: [
|
|
1731
|
+
t(field.label),
|
|
1732
|
+
field.required ? " *" : ""
|
|
1733
|
+
] }),
|
|
1734
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1735
|
+
Controller,
|
|
1736
|
+
{
|
|
1737
|
+
name: field.name,
|
|
1738
|
+
control,
|
|
1739
|
+
rules: {
|
|
1740
|
+
required: enforceRequired ? t("integration.form.required", { field: t(field.label) }) : false
|
|
1741
|
+
},
|
|
1742
|
+
render: ({ field: f, fieldState }) => {
|
|
1743
|
+
var _a;
|
|
1744
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1745
|
+
renderControl(field, f, secretConfigured, t),
|
|
1746
|
+
((_a = fieldState.error) == null ? void 0 : _a.message) && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xsmall", className: "text-ui-fg-error", children: fieldState.error.message })
|
|
1747
|
+
] });
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
),
|
|
1751
|
+
field.hint && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xsmall", className: "text-ui-fg-subtle", children: t(field.hint) })
|
|
1752
|
+
] });
|
|
1753
|
+
};
|
|
1754
|
+
function renderControl(field, f, secretConfigured, t) {
|
|
1755
|
+
const placeholder = field.placeholder ? t(field.placeholder) : void 0;
|
|
1756
|
+
const disabled = field.readonly === true;
|
|
1757
|
+
switch (field.control) {
|
|
1758
|
+
case "switch":
|
|
1759
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Switch, { checked: !!f.value, onCheckedChange: f.onChange, disabled });
|
|
1760
|
+
case "select":
|
|
1761
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { value: f.value ?? "", onValueChange: f.onChange, disabled, children: [
|
|
1762
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, { placeholder }) }),
|
|
1763
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: (field.options ?? []).map((o) => {
|
|
1764
|
+
var _a;
|
|
1765
|
+
const labelKey = (_a = field.optionLabels) == null ? void 0 : _a[o];
|
|
1766
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: o, children: labelKey ? t(labelKey) : o }, o);
|
|
1767
|
+
}) })
|
|
1768
|
+
] });
|
|
1769
|
+
case "number":
|
|
1770
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1771
|
+
ui.Input,
|
|
1772
|
+
{
|
|
1773
|
+
type: "number",
|
|
1774
|
+
placeholder,
|
|
1775
|
+
value: f.value ?? "",
|
|
1776
|
+
disabled,
|
|
1777
|
+
onChange: (e) => f.onChange(e.target.value === "" ? void 0 : e.target.valueAsNumber)
|
|
1778
|
+
}
|
|
1779
|
+
);
|
|
1780
|
+
case "secret":
|
|
1781
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1782
|
+
ui.Input,
|
|
1783
|
+
{
|
|
1784
|
+
type: "password",
|
|
1785
|
+
placeholder: secretConfigured ? t("integration.form.keepSecret") : placeholder ?? "",
|
|
1786
|
+
value: f.value ?? "",
|
|
1787
|
+
disabled,
|
|
1788
|
+
onChange: f.onChange
|
|
1789
|
+
}
|
|
1790
|
+
);
|
|
1791
|
+
case "json":
|
|
1792
|
+
return /* @__PURE__ */ jsxRuntime.jsx(JsonField, { field, f });
|
|
1793
|
+
default:
|
|
1794
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1795
|
+
ui.Input,
|
|
1796
|
+
{
|
|
1797
|
+
placeholder,
|
|
1798
|
+
value: f.value ?? "",
|
|
1799
|
+
disabled,
|
|
1800
|
+
onChange: f.onChange
|
|
1801
|
+
}
|
|
1802
|
+
);
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
function isFieldVisible(field, values) {
|
|
1806
|
+
const rule = field.visibleWhen;
|
|
1807
|
+
if (!rule) return true;
|
|
1808
|
+
return values[rule.field] === rule.equals;
|
|
1809
|
+
}
|
|
1810
|
+
function sectionDefaults(section, values) {
|
|
1811
|
+
const out = {};
|
|
1812
|
+
for (const f of section.fields) {
|
|
1813
|
+
if (f.readonly) out[f.name] = f.readonlyValue;
|
|
1814
|
+
else if (f.secret || f.control === "secret") out[f.name] = "";
|
|
1815
|
+
else if (f.control === "switch") out[f.name] = (values == null ? void 0 : values[f.name]) ?? false;
|
|
1816
|
+
else if (f.control === "json") out[f.name] = values == null ? void 0 : values[f.name];
|
|
1817
|
+
else out[f.name] = (values == null ? void 0 : values[f.name]) ?? "";
|
|
1818
|
+
}
|
|
1819
|
+
return out;
|
|
1820
|
+
}
|
|
1821
|
+
const EditSectionDrawer = ({
|
|
1822
|
+
open,
|
|
1823
|
+
onOpenChange,
|
|
1824
|
+
providerId,
|
|
1825
|
+
section,
|
|
1826
|
+
values,
|
|
1827
|
+
hasSecrets = false
|
|
1828
|
+
}) => {
|
|
1829
|
+
const { t } = reactI18next.useTranslation();
|
|
1830
|
+
const qc = reactQuery.useQueryClient();
|
|
1831
|
+
const [defaults] = React.useState(() => sectionDefaults(section, values));
|
|
1832
|
+
const form = useForm({ values: defaults });
|
|
1833
|
+
const current = form.watch();
|
|
1834
|
+
const visibilityValues = { ...values, ...current };
|
|
1835
|
+
const save = reactQuery.useMutation({
|
|
1836
|
+
mutationFn: (sectionValues) => sdk.client.fetch(`/admin/integrations/${providerId}`, {
|
|
1837
|
+
method: "POST",
|
|
1838
|
+
// Only this section's values + its id — the server validates just this section and
|
|
1839
|
+
// merges over the rest of the stored config (keeping blank/untouched secrets).
|
|
1840
|
+
body: { section_id: section.id, values: sectionValues }
|
|
1841
|
+
}),
|
|
1842
|
+
onSuccess: () => {
|
|
1843
|
+
ui.toast.success(t("integration.toast.saved"));
|
|
1844
|
+
qc.invalidateQueries({ queryKey: ["integration", providerId] });
|
|
1845
|
+
qc.invalidateQueries({ queryKey: ["integration-overview"] });
|
|
1846
|
+
onOpenChange(false);
|
|
1847
|
+
},
|
|
1848
|
+
onError: (e) => ui.toast.error((e == null ? void 0 : e.message) ?? t("integration.toast.saveFailed"))
|
|
1849
|
+
});
|
|
1850
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Drawer, { open, onOpenChange, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Content, { children: [
|
|
1851
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Drawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Drawer.Title, { children: t(section.title) }) }),
|
|
1852
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Drawer.Body, { className: "flex flex-1 flex-col gap-y-4 overflow-auto", children: section.fields.filter((f) => isFieldVisible(f, visibilityValues)).map((f) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1853
|
+
IntegrationField,
|
|
1854
|
+
{
|
|
1855
|
+
field: f,
|
|
1856
|
+
control: form.control,
|
|
1857
|
+
secretConfigured: hasSecrets
|
|
1858
|
+
},
|
|
1859
|
+
f.name
|
|
1860
|
+
)) }),
|
|
1861
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Drawer.Footer, { children: [
|
|
1862
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Drawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", disabled: save.isPending, children: t("integration.actions.cancel") }) }),
|
|
1863
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1864
|
+
ui.Button,
|
|
1865
|
+
{
|
|
1866
|
+
size: "small",
|
|
1867
|
+
isLoading: save.isPending,
|
|
1868
|
+
onClick: form.handleSubmit((v) => save.mutate(v)),
|
|
1869
|
+
children: t("integration.actions.save")
|
|
1870
|
+
}
|
|
1871
|
+
)
|
|
1872
|
+
] })
|
|
1873
|
+
] }) });
|
|
1874
|
+
};
|
|
1875
|
+
const testColor = (s) => s === "ok" ? "green" : s === "fail" ? "red" : "grey";
|
|
1876
|
+
const Row = ({ label, children }) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle grid grid-cols-2 px-6 py-4", children: [
|
|
1877
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: label }),
|
|
1878
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-x-2", children })
|
|
1879
|
+
] });
|
|
1880
|
+
const EditPage = () => {
|
|
1881
|
+
const { t } = reactI18next.useTranslation();
|
|
1882
|
+
const { provider_id } = reactRouterDom.useParams();
|
|
1883
|
+
const qc = reactQuery.useQueryClient();
|
|
1884
|
+
const navigate = reactRouterDom.useNavigate();
|
|
1885
|
+
const prompt = ui.usePrompt();
|
|
1886
|
+
const [editingSection, setEditingSection] = React.useState(null);
|
|
1887
|
+
const { data, isLoading } = reactQuery.useQuery({
|
|
1888
|
+
queryKey: ["integration", provider_id],
|
|
1889
|
+
queryFn: () => sdk.client.fetch(`/admin/integrations/${provider_id}`)
|
|
1890
|
+
});
|
|
1891
|
+
const descriptor = data == null ? void 0 : data.descriptor;
|
|
1892
|
+
const record = data == null ? void 0 : data.integration;
|
|
1893
|
+
const isConfigured = !!record;
|
|
1894
|
+
const isComplete = (data == null ? void 0 : data.is_complete) ?? false;
|
|
1895
|
+
const invalidate = () => {
|
|
1896
|
+
qc.invalidateQueries({ queryKey: ["integration", provider_id] });
|
|
1897
|
+
qc.invalidateQueries({ queryKey: ["integration-overview"] });
|
|
1898
|
+
};
|
|
1899
|
+
const test = reactQuery.useMutation({
|
|
1900
|
+
mutationFn: () => sdk.client.fetch(
|
|
1901
|
+
`/admin/integrations/${provider_id}/test-connection`,
|
|
1902
|
+
{ method: "POST" }
|
|
1903
|
+
),
|
|
1904
|
+
onSuccess: (r) => {
|
|
1905
|
+
r.status === "ok" ? ui.toast.success(t("integration.toast.connectionOk")) : ui.toast.warning(r.message ?? r.status);
|
|
1906
|
+
invalidate();
|
|
1907
|
+
},
|
|
1908
|
+
onError: (e) => ui.toast.error((e == null ? void 0 : e.message) ?? t("integration.toast.testFailed"))
|
|
1909
|
+
});
|
|
1910
|
+
const toggleEnabled = reactQuery.useMutation({
|
|
1911
|
+
mutationFn: (next) => sdk.client.fetch(`/admin/integrations/${provider_id}/enable`, {
|
|
1912
|
+
method: "POST",
|
|
1913
|
+
body: { is_enabled: next }
|
|
1914
|
+
}),
|
|
1915
|
+
onSuccess: (_d, next) => {
|
|
1916
|
+
ui.toast.success(next ? t("integration.toast.enabled") : t("integration.toast.disabled"));
|
|
1917
|
+
invalidate();
|
|
1918
|
+
},
|
|
1919
|
+
onError: (e) => ui.toast.error((e == null ? void 0 : e.message) ?? t("integration.toast.updateFailed"))
|
|
1920
|
+
});
|
|
1921
|
+
const remove = reactQuery.useMutation({
|
|
1922
|
+
mutationFn: () => sdk.client.fetch(`/admin/integrations/${provider_id}`, { method: "DELETE" }),
|
|
1923
|
+
onSuccess: () => {
|
|
1924
|
+
ui.toast.success(t("integration.toast.deleted"));
|
|
1925
|
+
invalidate();
|
|
1926
|
+
navigate("/settings/integrations");
|
|
1927
|
+
},
|
|
1928
|
+
onError: (e) => ui.toast.error((e == null ? void 0 : e.message) ?? t("integration.toast.deleteFailed"))
|
|
1929
|
+
});
|
|
1930
|
+
const onDelete = async () => {
|
|
1931
|
+
const confirmed = await prompt({
|
|
1932
|
+
title: t("integration.delete.title"),
|
|
1933
|
+
description: t("integration.delete.description", {
|
|
1934
|
+
name: descriptor ? t(descriptor.displayName) : ""
|
|
1935
|
+
}),
|
|
1936
|
+
confirmText: t("integration.actions.delete"),
|
|
1937
|
+
cancelText: t("integration.actions.cancel")
|
|
1938
|
+
});
|
|
1939
|
+
if (confirmed) remove.mutate();
|
|
1940
|
+
};
|
|
1941
|
+
if (isLoading) {
|
|
1942
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "flex items-center justify-center p-8", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Spinner, { className: "text-ui-fg-subtle animate-spin" }) });
|
|
1943
|
+
}
|
|
1944
|
+
if (!descriptor) {
|
|
1945
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-6", children: [
|
|
1946
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: t("integration.unknown", { id: provider_id }) }),
|
|
1947
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Link, { to: "/settings/integrations", className: "text-ui-fg-interactive", children: t("integration.back") })
|
|
1948
|
+
] });
|
|
1949
|
+
}
|
|
1950
|
+
const editing = descriptor.sections.find((s) => s.id === editingSection) ?? null;
|
|
1951
|
+
const sectionData = {
|
|
1952
|
+
providerId: provider_id,
|
|
1953
|
+
pluginId: descriptor.pluginId,
|
|
1954
|
+
values: (record == null ? void 0 : record.values) ?? {},
|
|
1955
|
+
isComplete
|
|
1956
|
+
};
|
|
1957
|
+
const renderSection = (section) => /* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: section.id, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
|
|
1958
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-6 py-4", children: [
|
|
1959
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: t(section.title) }),
|
|
1960
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
|
|
1961
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "small", variant: "transparent", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisHorizontal, {}) }) }),
|
|
1962
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Content, { children: /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Item, { className: "gap-x-2", onClick: () => setEditingSection(section.id), children: [
|
|
1963
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, { className: "text-ui-fg-subtle" }),
|
|
1964
|
+
t("integration.actions.edit")
|
|
1965
|
+
] }) })
|
|
1966
|
+
] })
|
|
1967
|
+
] }),
|
|
1968
|
+
section.fields.filter((f) => isFieldVisible(f, (record == null ? void 0 : record.values) ?? {})).map((f) => {
|
|
1969
|
+
var _a;
|
|
1970
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Row, { label: t(f.label), children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1971
|
+
IntegrationFieldValue,
|
|
1972
|
+
{
|
|
1973
|
+
field: f,
|
|
1974
|
+
value: (_a = record == null ? void 0 : record.values) == null ? void 0 : _a[f.name],
|
|
1975
|
+
secretConfigured: !!(record == null ? void 0 : record.has_secrets)
|
|
1976
|
+
}
|
|
1977
|
+
) }, f.name);
|
|
1978
|
+
})
|
|
1979
|
+
] }, section.id) });
|
|
1980
|
+
const mainSections = descriptor.sections.filter((s) => s.column !== "side");
|
|
1981
|
+
const sideSections = descriptor.sections.filter((s) => s.column === "side");
|
|
1982
|
+
const main = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1983
|
+
/* @__PURE__ */ jsxRuntime.jsx(components.LayoutComposer.Entry, { id: "main", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
|
|
1984
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-6 py-4", children: [
|
|
1985
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
|
|
1986
|
+
/* @__PURE__ */ jsxRuntime.jsx(IntegrationIcon, { src: descriptor.icon, alt: t(descriptor.displayName) }),
|
|
1987
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-1", children: [
|
|
1988
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
|
|
1989
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: t(descriptor.displayName) }),
|
|
1990
|
+
descriptor.instanceId && /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { size: "2xsmall", color: "grey", children: descriptor.instanceId })
|
|
1991
|
+
] }),
|
|
1992
|
+
descriptor.description && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: t(descriptor.description) })
|
|
1993
|
+
] })
|
|
1994
|
+
] }),
|
|
1995
|
+
isConfigured && /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
|
|
1996
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "small", variant: "transparent", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisHorizontal, {}) }) }),
|
|
1997
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
|
|
1998
|
+
descriptor.hasTestConnection && record.is_enabled && isComplete && /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Item, { disabled: test.isPending, onClick: () => test.mutate(), children: t("integration.actions.test") }),
|
|
1999
|
+
isConfigured && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2000
|
+
ui.DropdownMenu.Item,
|
|
2001
|
+
{
|
|
2002
|
+
disabled: toggleEnabled.isPending,
|
|
2003
|
+
onClick: () => toggleEnabled.mutate(!record.is_enabled),
|
|
2004
|
+
children: record.is_enabled ? t("integration.actions.disable") : t("integration.actions.enable")
|
|
2005
|
+
}
|
|
2006
|
+
),
|
|
2007
|
+
isConfigured && /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
|
|
2008
|
+
isConfigured && /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Item, { className: "gap-x-2", onClick: onDelete, children: [
|
|
2009
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
|
|
2010
|
+
t("integration.actions.delete")
|
|
2011
|
+
] })
|
|
2012
|
+
] })
|
|
2013
|
+
] })
|
|
2014
|
+
] }),
|
|
2015
|
+
/* @__PURE__ */ jsxRuntime.jsx(Row, { label: t("integration.labels.status"), children: !isConfigured ? /* @__PURE__ */ jsxRuntime.jsx(ui.StatusBadge, { color: "grey", children: t("integration.status.notConfigured") }) : !isComplete ? /* @__PURE__ */ jsxRuntime.jsx(ui.StatusBadge, { color: "orange", children: t("integration.status.incomplete") }) : /* @__PURE__ */ jsxRuntime.jsx(ui.StatusBadge, { color: record.is_enabled ? "green" : "grey", children: record.is_enabled ? t("integration.status.enabled") : t("integration.status.disabled") }) }),
|
|
2016
|
+
/* @__PURE__ */ jsxRuntime.jsx(Row, { label: t("integration.labels.module"), children: /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { size: "2xsmall", color: "grey", children: t(`integration.modules.${descriptor.module}`) }) }),
|
|
2017
|
+
/* @__PURE__ */ jsxRuntime.jsx(Row, { label: t("integration.labels.lastTest"), children: (record == null ? void 0 : record.last_test_status) ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2018
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.StatusBadge, { color: testColor(record.last_test_status), children: t(`integration.testStatus.${record.last_test_status}`) }),
|
|
2019
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", leading: "compact", className: "text-ui-fg-subtle", children: [
|
|
2020
|
+
record.last_test_at && new Date(record.last_test_at).toLocaleString(),
|
|
2021
|
+
record.last_test_message ? ` · ${record.last_test_message}` : ""
|
|
2022
|
+
] })
|
|
2023
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "text-ui-fg-subtle", children: t("integration.labels.neverTested") }) })
|
|
2024
|
+
] }) }),
|
|
2025
|
+
mainSections.map(renderSection),
|
|
2026
|
+
editing && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2027
|
+
EditSectionDrawer,
|
|
2028
|
+
{
|
|
2029
|
+
open: true,
|
|
2030
|
+
onOpenChange: (open) => !open && setEditingSection(null),
|
|
2031
|
+
providerId: provider_id,
|
|
2032
|
+
section: editing,
|
|
2033
|
+
values: (record == null ? void 0 : record.values) ?? {},
|
|
2034
|
+
hasSecrets: !!(record == null ? void 0 : record.has_secrets)
|
|
2035
|
+
},
|
|
2036
|
+
editing.id
|
|
2037
|
+
)
|
|
2038
|
+
] });
|
|
2039
|
+
const side = /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: sideSections.map(renderSection) });
|
|
2040
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2041
|
+
components.LayoutComposer,
|
|
2042
|
+
{
|
|
2043
|
+
widgetsZonePrefix: `gorgo.integration.${descriptor.pluginId}`,
|
|
2044
|
+
preferredLayoutId: descriptor.preferredLayoutId,
|
|
2045
|
+
sections: { main, side },
|
|
2046
|
+
data: sectionData,
|
|
2047
|
+
hasOutlet: false
|
|
2048
|
+
}
|
|
2049
|
+
);
|
|
2050
|
+
};
|
|
2051
|
+
const IntegrationBreadcrumb = ({ params }) => {
|
|
2052
|
+
const { t } = reactI18next.useTranslation();
|
|
2053
|
+
const providerId = params.provider_id;
|
|
2054
|
+
const { data } = reactQuery.useQuery({
|
|
2055
|
+
queryKey: ["integration", providerId],
|
|
2056
|
+
queryFn: () => sdk.client.fetch(`/admin/integrations/${providerId}`),
|
|
2057
|
+
enabled: !!providerId
|
|
2058
|
+
});
|
|
2059
|
+
const descriptor = data == null ? void 0 : data.descriptor;
|
|
2060
|
+
if (!descriptor) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: providerId });
|
|
2061
|
+
const name = t(descriptor.displayName);
|
|
2062
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: descriptor.instanceId ? `${name} · ${descriptor.instanceId}` : name });
|
|
2063
|
+
};
|
|
2064
|
+
const handle = {
|
|
2065
|
+
breadcrumb: ({ params }) => /* @__PURE__ */ jsxRuntime.jsx(IntegrationBreadcrumb, { params })
|
|
2066
|
+
};
|
|
2067
|
+
const integration$1 = {
|
|
2068
|
+
list: {
|
|
2069
|
+
title: "Integrations",
|
|
2070
|
+
empty: "No integrations registered. Declare providers under the integration plugin's options.providers in medusa-config.",
|
|
2071
|
+
tested: "tested",
|
|
2072
|
+
testFailed: "test failed"
|
|
2073
|
+
},
|
|
2074
|
+
status: {
|
|
2075
|
+
notConfigured: "Not configured",
|
|
2076
|
+
incomplete: "Incomplete",
|
|
2077
|
+
enabled: "Enabled",
|
|
2078
|
+
disabled: "Disabled",
|
|
2079
|
+
configured: "Configured"
|
|
2080
|
+
},
|
|
2081
|
+
labels: {
|
|
2082
|
+
status: "Status",
|
|
2083
|
+
module: "Module",
|
|
2084
|
+
lastTest: "Last test",
|
|
2085
|
+
neverTested: "Never tested"
|
|
2086
|
+
},
|
|
2087
|
+
modules: {
|
|
2088
|
+
payment: "Payment",
|
|
2089
|
+
fulfillment: "Fulfillment",
|
|
2090
|
+
marketplace: "Marketplace",
|
|
2091
|
+
crm: "CRM",
|
|
2092
|
+
erp: "ERP",
|
|
2093
|
+
pim: "PIM",
|
|
2094
|
+
notification: "Notification",
|
|
2095
|
+
feed: "Feed",
|
|
2096
|
+
tax: "Tax",
|
|
2097
|
+
other: "Other"
|
|
2098
|
+
},
|
|
2099
|
+
testStatus: {
|
|
2100
|
+
ok: "OK",
|
|
2101
|
+
fail: "Failed",
|
|
2102
|
+
skipped: "Skipped"
|
|
2103
|
+
},
|
|
2104
|
+
actions: {
|
|
2105
|
+
test: "Test connection",
|
|
2106
|
+
enable: "Enable",
|
|
2107
|
+
disable: "Disable",
|
|
2108
|
+
"delete": "Delete",
|
|
2109
|
+
edit: "Edit",
|
|
2110
|
+
save: "Save",
|
|
2111
|
+
cancel: "Cancel"
|
|
2112
|
+
},
|
|
2113
|
+
"delete": {
|
|
2114
|
+
title: "Delete configuration",
|
|
2115
|
+
description: "Remove the stored configuration for {{name}}? This can't be undone."
|
|
2116
|
+
},
|
|
2117
|
+
form: {
|
|
2118
|
+
required: "{{field}} is required",
|
|
2119
|
+
invalidJson: "Invalid JSON",
|
|
2120
|
+
keepSecret: "•••••• — leave blank to keep",
|
|
2121
|
+
items: "{{count}} items"
|
|
2122
|
+
},
|
|
2123
|
+
toast: {
|
|
2124
|
+
saved: "Saved",
|
|
2125
|
+
saveFailed: "Save failed",
|
|
2126
|
+
connectionOk: "Connection OK",
|
|
2127
|
+
testFailed: "Test failed",
|
|
2128
|
+
enabled: "Enabled",
|
|
2129
|
+
disabled: "Disabled",
|
|
2130
|
+
deleted: "Configuration deleted",
|
|
2131
|
+
deleteFailed: "Delete failed",
|
|
2132
|
+
updateFailed: "Update failed"
|
|
2133
|
+
},
|
|
2134
|
+
unknown: 'Unknown integration "{{id}}".',
|
|
2135
|
+
back: "Back to integrations"
|
|
2136
|
+
};
|
|
2137
|
+
const en = {
|
|
2138
|
+
integration: integration$1
|
|
2139
|
+
};
|
|
2140
|
+
const integration = {
|
|
2141
|
+
list: {
|
|
2142
|
+
title: "Интеграции",
|
|
2143
|
+
empty: "Нет зарегистрированных интеграций. Объявите провайдеров в options.providers плагина интеграций в medusa-config.",
|
|
2144
|
+
tested: "проверено",
|
|
2145
|
+
testFailed: "ошибка проверки"
|
|
2146
|
+
},
|
|
2147
|
+
status: {
|
|
2148
|
+
notConfigured: "Не настроено",
|
|
2149
|
+
incomplete: "Не завершено",
|
|
2150
|
+
enabled: "Включено",
|
|
2151
|
+
disabled: "Выключено",
|
|
2152
|
+
configured: "Настроено"
|
|
2153
|
+
},
|
|
2154
|
+
labels: {
|
|
2155
|
+
status: "Статус",
|
|
2156
|
+
module: "Модуль",
|
|
2157
|
+
lastTest: "Последняя проверка",
|
|
2158
|
+
neverTested: "Не проверялось"
|
|
2159
|
+
},
|
|
2160
|
+
modules: {
|
|
2161
|
+
payment: "Платежи",
|
|
2162
|
+
fulfillment: "Доставка",
|
|
2163
|
+
marketplace: "Маркетплейс",
|
|
2164
|
+
crm: "CRM",
|
|
2165
|
+
erp: "ERP",
|
|
2166
|
+
pim: "PIM",
|
|
2167
|
+
notification: "Уведомления",
|
|
2168
|
+
feed: "Фиды",
|
|
2169
|
+
tax: "Налоги",
|
|
2170
|
+
other: "Прочее"
|
|
2171
|
+
},
|
|
2172
|
+
testStatus: {
|
|
2173
|
+
ok: "OK",
|
|
2174
|
+
fail: "Ошибка",
|
|
2175
|
+
skipped: "Пропущено"
|
|
2176
|
+
},
|
|
2177
|
+
actions: {
|
|
2178
|
+
test: "Проверить соединение",
|
|
2179
|
+
enable: "Включить",
|
|
2180
|
+
disable: "Выключить",
|
|
2181
|
+
"delete": "Удалить",
|
|
2182
|
+
edit: "Редактировать",
|
|
2183
|
+
save: "Сохранить",
|
|
2184
|
+
cancel: "Отмена"
|
|
2185
|
+
},
|
|
2186
|
+
"delete": {
|
|
2187
|
+
title: "Удалить конфигурацию",
|
|
2188
|
+
description: "Удалить сохранённую конфигурацию «{{name}}»? Это действие необратимо."
|
|
2189
|
+
},
|
|
2190
|
+
form: {
|
|
2191
|
+
required: "Поле «{{field}}» обязательно",
|
|
2192
|
+
invalidJson: "Некорректный JSON",
|
|
2193
|
+
keepSecret: "•••••• — оставьте пустым, чтобы не менять",
|
|
2194
|
+
items: "{{count}} шт."
|
|
2195
|
+
},
|
|
2196
|
+
toast: {
|
|
2197
|
+
saved: "Сохранено",
|
|
2198
|
+
saveFailed: "Не удалось сохранить",
|
|
2199
|
+
connectionOk: "Соединение установлено",
|
|
2200
|
+
testFailed: "Проверка не удалась",
|
|
2201
|
+
enabled: "Включено",
|
|
2202
|
+
disabled: "Выключено",
|
|
2203
|
+
deleted: "Конфигурация удалена",
|
|
2204
|
+
deleteFailed: "Не удалось удалить",
|
|
2205
|
+
updateFailed: "Не удалось обновить"
|
|
2206
|
+
},
|
|
2207
|
+
unknown: "Неизвестная интеграция «{{id}}».",
|
|
2208
|
+
back: "К интеграциям"
|
|
2209
|
+
};
|
|
2210
|
+
const ru = {
|
|
2211
|
+
integration
|
|
2212
|
+
};
|
|
2213
|
+
const i18nTranslations0 = {
|
|
2214
|
+
en: { translation: en },
|
|
2215
|
+
ru: { translation: ru }
|
|
2216
|
+
};
|
|
2217
|
+
const widgetModule = { widgets: [] };
|
|
2218
|
+
const routeModule = {
|
|
2219
|
+
routes: [
|
|
2220
|
+
{
|
|
2221
|
+
Component: IntegrationsPage,
|
|
2222
|
+
path: "/settings/integrations",
|
|
2223
|
+
handle: handle$1
|
|
2224
|
+
},
|
|
2225
|
+
{
|
|
2226
|
+
Component: EditPage,
|
|
2227
|
+
path: "/settings/integrations/:provider_id",
|
|
2228
|
+
handle
|
|
2229
|
+
}
|
|
2230
|
+
]
|
|
2231
|
+
};
|
|
2232
|
+
const menuItemModule = {
|
|
2233
|
+
menuItems: [
|
|
2234
|
+
{
|
|
2235
|
+
label: config.label,
|
|
2236
|
+
icon: config.icon,
|
|
2237
|
+
path: "/settings/integrations",
|
|
2238
|
+
nested: void 0,
|
|
2239
|
+
rank: void 0,
|
|
2240
|
+
translationNs: config.translationNs
|
|
2241
|
+
}
|
|
2242
|
+
]
|
|
2243
|
+
};
|
|
2244
|
+
const formModule = { customFields: {} };
|
|
2245
|
+
const displayModule = {
|
|
2246
|
+
displays: {}
|
|
2247
|
+
};
|
|
2248
|
+
const i18nModule = { resources: i18nTranslations0 };
|
|
2249
|
+
const layoutModule = { layouts: [] };
|
|
2250
|
+
const plugin = {
|
|
2251
|
+
widgetModule,
|
|
2252
|
+
routeModule,
|
|
2253
|
+
menuItemModule,
|
|
2254
|
+
formModule,
|
|
2255
|
+
displayModule,
|
|
2256
|
+
i18nModule,
|
|
2257
|
+
layoutModule
|
|
2258
|
+
};
|
|
2259
|
+
module.exports = plugin;
|