@vulcanjs/react-ui 0.6.6-y.8 → 0.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/VulcanComponents/Consumer.d.ts.map +0 -0
- package/dist/components/VulcanComponents/Context.d.ts.map +0 -0
- package/dist/components/VulcanComponents/Dummy.d.ts.map +0 -0
- package/dist/components/VulcanComponents/Provider.d.ts.map +0 -0
- package/dist/components/VulcanComponents/defaultVulcanComponents/index.d.ts.map +0 -0
- package/dist/components/VulcanComponents/index.d.ts.map +0 -0
- package/dist/components/VulcanComponents/typings.d.ts.map +0 -0
- package/dist/components/VulcanCurrentUser/Consumer.d.ts.map +0 -0
- package/dist/components/VulcanCurrentUser/Context.d.ts.map +0 -0
- package/dist/components/VulcanCurrentUser/Provider.d.ts.map +0 -0
- package/dist/components/VulcanCurrentUser/index.d.ts.map +0 -0
- package/dist/components/core/LoadingButton.d.ts.map +0 -0
- package/dist/components/core/MutationButton.d.ts.map +0 -0
- package/dist/components/core/typings.d.ts.map +0 -0
- package/dist/components/form/core/Form/Form.d.ts.map +0 -0
- package/dist/components/form/core/Form/fields.d.ts.map +0 -0
- package/dist/components/form/core/Form/index.d.ts.map +0 -0
- package/dist/components/form/core/Form/typings.d.ts.map +0 -0
- package/dist/components/form/core/Form/utils.d.ts.map +0 -0
- package/dist/components/form/core/FormContainer.d.ts.map +1 -1
- package/dist/components/form/core/FormContext.d.ts.map +1 -1
- package/dist/components/form/core/index.d.ts.map +0 -0
- package/dist/components/form/hooks/useBlockTransition/block.d.ts.map +0 -0
- package/dist/components/form/hooks/useBlockTransition/useBlockTransition.d.ts.map +0 -0
- package/dist/components/form/hooks/useWarnOnUnsaved/index.d.ts.map +0 -0
- package/dist/components/form/hooks/useWarnOnUnsaved/useWarnOnUnsaved.d.ts.map +0 -0
- package/dist/components/form/index.d.ts +1 -0
- package/dist/components/form/index.d.ts.map +1 -1
- package/dist/components/form/typings.d.ts.map +0 -0
- package/dist/components/form/utils/formFragments.d.ts.map +0 -0
- package/dist/components/form/utils/index.d.ts +6 -0
- package/dist/components/form/utils/index.d.ts.map +1 -0
- package/dist/components/form/utils/path_utils.d.ts.map +0 -0
- package/dist/components/form/utils/schema_utils.d.ts.map +0 -0
- package/dist/components/form/utils/ui_utils.d.ts.map +1 -0
- package/dist/components/form/utils/utils.d.ts.map +0 -0
- package/dist/componentsHelpers.d.ts.map +0 -0
- package/dist/index.d.ts.map +0 -0
- package/dist/index.js +1104 -931
- package/dist/index.js.map +1 -1
- package/dist/testing/ExpectedErrorBoundary.d.ts +14 -0
- package/dist/testing/ExpectedErrorBoundary.d.ts.map +1 -0
- package/dist/testing.d.ts +2 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +34 -0
- package/dist/testing.js.map +1 -0
- package/package.json +13 -5
package/dist/index.js
CHANGED
@@ -40,6 +40,10 @@ var __esm = (fn, res) => function __init() {
|
|
40
40
|
var __commonJS = (cb, mod) => function __require() {
|
41
41
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
42
42
|
};
|
43
|
+
var __export = (target, all) => {
|
44
|
+
for (var name in all)
|
45
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
46
|
+
};
|
43
47
|
var __copyProps = (to, from, except, desc) => {
|
44
48
|
if (from && typeof from === "object" || typeof from === "function") {
|
45
49
|
for (let key of __getOwnPropNames(from))
|
@@ -588,7 +592,9 @@ var FormContext = /* @__PURE__ */ React.createContext(void 0);
|
|
588
592
|
var useFormContext = /* @__PURE__ */ __name(() => {
|
589
593
|
const formContext = useContext(FormContext);
|
590
594
|
if (!formContext)
|
591
|
-
throw new Error(
|
595
|
+
throw new Error(`A component is trying to access form context but it is undefined. Please wrap your component with a <Form>.
|
596
|
+
You may be importing "FormContext" from different packages or have accidentaly made a copy of it?
|
597
|
+
FormContext is exposed by "@vulcanjs/react-ui".`);
|
592
598
|
return formContext;
|
593
599
|
}, "useFormContext");
|
594
600
|
|
@@ -597,12 +603,12 @@ init_esm_shims();
|
|
597
603
|
|
598
604
|
// components/form/core/Form/Form.tsx
|
599
605
|
init_esm_shims();
|
600
|
-
import
|
606
|
+
import React5, { useEffect as useEffect2, useRef as useRef2, useState } from "react";
|
601
607
|
import { runCallbacks, getErrors } from "@vulcanjs/core";
|
602
608
|
import { useIntlContext as useIntlContext2 } from "@vulcanjs/react-i18n";
|
603
609
|
import { removeProperty } from "@vulcanjs/utils";
|
604
610
|
import cloneDeep from "lodash/cloneDeep.js";
|
605
|
-
import
|
611
|
+
import compact2 from "lodash/compact.js";
|
606
612
|
import get2 from "lodash/get.js";
|
607
613
|
import isObject from "lodash/isObject.js";
|
608
614
|
import mapValues from "lodash/mapValues.js";
|
@@ -618,10 +624,33 @@ import without from "lodash/without.js";
|
|
618
624
|
import isEmpty from "lodash/isEmpty.js";
|
619
625
|
|
620
626
|
// components/form/utils/schema_utils.ts
|
627
|
+
var schema_utils_exports = {};
|
628
|
+
__export(schema_utils_exports, {
|
629
|
+
convertSchema: () => convertSchema,
|
630
|
+
formProperties: () => formProperties,
|
631
|
+
getEditableFields: () => getEditableFields,
|
632
|
+
getFieldSchema: () => getFieldSchema,
|
633
|
+
getInsertableFields: () => getInsertableFields,
|
634
|
+
getNestedFieldSchemaOrType: () => getNestedFieldSchemaOrType,
|
635
|
+
getSchemaType: () => getSchemaType,
|
636
|
+
getValidFields: () => getValidFields,
|
637
|
+
schemaProperties: () => schemaProperties
|
638
|
+
});
|
621
639
|
init_esm_shims();
|
622
640
|
import { canCreateField, canUpdateField } from "@vulcanjs/permissions";
|
623
641
|
|
624
642
|
// components/form/utils/utils.ts
|
643
|
+
var utils_exports = {};
|
644
|
+
__export(utils_exports, {
|
645
|
+
deepValue: () => deepValue,
|
646
|
+
flatten: () => flatten,
|
647
|
+
getDeletedValues: () => getDeletedValues,
|
648
|
+
getFieldType: () => getFieldType,
|
649
|
+
getNestedDeletedValues: () => getNestedDeletedValues,
|
650
|
+
getNullValue: () => getNullValue,
|
651
|
+
isEmptyValue: () => isEmptyValue,
|
652
|
+
mergeValue: () => mergeValue
|
653
|
+
});
|
625
654
|
init_esm_shims();
|
626
655
|
import merge from "lodash/merge.js";
|
627
656
|
import find from "lodash/find.js";
|
@@ -630,6 +659,14 @@ import set from "lodash/set.js";
|
|
630
659
|
import size from "lodash/size.js";
|
631
660
|
|
632
661
|
// components/form/utils/path_utils.ts
|
662
|
+
var path_utils_exports = {};
|
663
|
+
__export(path_utils_exports, {
|
664
|
+
filterPathsByPrefix: () => filterPathsByPrefix,
|
665
|
+
getParentPath: () => getParentPath,
|
666
|
+
joinPath: () => joinPath,
|
667
|
+
removePrefix: () => removePrefix,
|
668
|
+
splitPath: () => splitPath
|
669
|
+
});
|
633
670
|
init_esm_shims();
|
634
671
|
import toPath from "lodash/toPath.js";
|
635
672
|
import initial from "lodash/initial.js";
|
@@ -638,12 +675,93 @@ import takeRight from "lodash/takeRight.js";
|
|
638
675
|
var splitPath = /* @__PURE__ */ __name((string) => toPath(string), "splitPath");
|
639
676
|
var joinPath = /* @__PURE__ */ __name((array) => array.reduce((string, item) => string + (Number.isNaN(Number(item)) ? `${string === "" ? "" : "."}${item}` : `[${item}]`), ""), "joinPath");
|
640
677
|
var getParentPath = flow(splitPath, initial, joinPath);
|
678
|
+
var removePrefix = /* @__PURE__ */ __name((prefix, paths) => {
|
679
|
+
const explodedPrefix = splitPath(prefix);
|
680
|
+
return paths.map((path) => {
|
681
|
+
if (path === prefix) {
|
682
|
+
return path;
|
683
|
+
}
|
684
|
+
const explodedPath = splitPath(path);
|
685
|
+
const explodedSuffix = takeRight(explodedPath, explodedPath.length - explodedPrefix.length);
|
686
|
+
return joinPath(explodedSuffix);
|
687
|
+
});
|
688
|
+
}, "removePrefix");
|
689
|
+
var filterPathsByPrefix = /* @__PURE__ */ __name((prefix, paths) => paths.filter((path) => path === prefix || path.startsWith(`${prefix}.`) || path.startsWith(`${prefix}[`)), "filterPathsByPrefix");
|
641
690
|
|
642
691
|
// components/form/utils/utils.ts
|
692
|
+
var deepValue = /* @__PURE__ */ __name(function(obj, path) {
|
693
|
+
const pathArray = path.split(".");
|
694
|
+
for (var i = 0; i < pathArray.length; i++) {
|
695
|
+
obj = obj[pathArray[i]];
|
696
|
+
}
|
697
|
+
return obj;
|
698
|
+
}, "deepValue");
|
699
|
+
var flatten = /* @__PURE__ */ __name(function(data) {
|
700
|
+
var result = {};
|
701
|
+
function recurse(cur, prop) {
|
702
|
+
if (Object.prototype.toString.call(cur) !== "[object Object]") {
|
703
|
+
result[prop] = cur;
|
704
|
+
} else if (Array.isArray(cur)) {
|
705
|
+
for (var i = 0, l = cur.length; i < l; i++)
|
706
|
+
recurse(cur[i], prop + "[" + i + "]");
|
707
|
+
if (l == 0)
|
708
|
+
result[prop] = [];
|
709
|
+
} else {
|
710
|
+
var isEmpty2 = true;
|
711
|
+
for (var p in cur) {
|
712
|
+
isEmpty2 = false;
|
713
|
+
recurse(cur[p], prop ? prop + "." + p : p);
|
714
|
+
}
|
715
|
+
if (isEmpty2 && prop)
|
716
|
+
result[prop] = {};
|
717
|
+
}
|
718
|
+
}
|
719
|
+
__name(recurse, "recurse");
|
720
|
+
recurse(data, "");
|
721
|
+
return result;
|
722
|
+
}, "flatten");
|
643
723
|
var isEmptyValue = /* @__PURE__ */ __name((value) => typeof value === "undefined" || value === null || value === "" || Array.isArray(value) && value.length === 0, "isEmptyValue");
|
724
|
+
var mergeValue = /* @__PURE__ */ __name(({ currentValue, documentValue, deletedValues: deletedFields, path, locale, datatype }) => {
|
725
|
+
if (locale) {
|
726
|
+
return currentValue || documentValue || "";
|
727
|
+
}
|
728
|
+
const deletedValues = getNestedDeletedValues(path, deletedFields);
|
729
|
+
const hasDeletedValues = !!size(deletedValues);
|
730
|
+
if ((Array.isArray(currentValue) || hasDeletedValues) && find(datatype, [
|
731
|
+
"type",
|
732
|
+
Array
|
733
|
+
])) {
|
734
|
+
return merge([], documentValue, currentValue, deletedValues);
|
735
|
+
} else if ((isPlainObject(currentValue) || hasDeletedValues) && find(datatype, [
|
736
|
+
"type",
|
737
|
+
Object
|
738
|
+
])) {
|
739
|
+
return merge({}, documentValue, currentValue, deletedValues);
|
740
|
+
}
|
741
|
+
return void 0;
|
742
|
+
}, "mergeValue");
|
743
|
+
var getDeletedValues = /* @__PURE__ */ __name((deletedFields, accumulator = {}) => deletedFields.reduce((deletedValues, path) => set(deletedValues, path, null), accumulator), "getDeletedValues");
|
744
|
+
var getNestedDeletedValues = /* @__PURE__ */ __name((prefix, deletedFields, accumulator = {}) => getDeletedValues(removePrefix(prefix, filterPathsByPrefix(prefix, deletedFields)), accumulator), "getNestedDeletedValues");
|
644
745
|
var getFieldType = /* @__PURE__ */ __name((fieldSchema) => fieldSchema.type, "getFieldType");
|
746
|
+
var getNullValue = /* @__PURE__ */ __name((datatype) => {
|
747
|
+
const fieldType = getFieldType(datatype);
|
748
|
+
if (fieldType === Array) {
|
749
|
+
return [];
|
750
|
+
} else if (fieldType === Boolean) {
|
751
|
+
return false;
|
752
|
+
} else if (fieldType === String) {
|
753
|
+
return "";
|
754
|
+
} else if (fieldType === Number) {
|
755
|
+
return "";
|
756
|
+
} else {
|
757
|
+
return null;
|
758
|
+
}
|
759
|
+
}, "getNullValue");
|
645
760
|
|
646
761
|
// components/form/utils/schema_utils.ts
|
762
|
+
var getValidFields = /* @__PURE__ */ __name((schema) => {
|
763
|
+
return Object.keys(schema).filter((fieldName) => !fieldName.includes("$") && !fieldName.includes("."));
|
764
|
+
}, "getValidFields");
|
647
765
|
var getInsertableFields = /* @__PURE__ */ __name(function(schema, user) {
|
648
766
|
const fields = Object.keys(schema).filter(function(fieldName) {
|
649
767
|
var field = schema[fieldName];
|
@@ -662,7 +780,7 @@ var isNestedSchema = /* @__PURE__ */ __name((schema) => {
|
|
662
780
|
return typeof schema === "object";
|
663
781
|
}, "isNestedSchema");
|
664
782
|
var convertSchema = /* @__PURE__ */ __name((schema, options = {}) => {
|
665
|
-
const { flatten = false, removeArrays = true } = options;
|
783
|
+
const { flatten: flatten2 = false, removeArrays = true } = options;
|
666
784
|
let jsonSchema = {};
|
667
785
|
Object.keys(schema).forEach((fieldName) => {
|
668
786
|
if (removeArrays && fieldName.includes("$")) {
|
@@ -674,7 +792,7 @@ var convertSchema = /* @__PURE__ */ __name((schema, options = {}) => {
|
|
674
792
|
jsonSchema[fieldName].arrayFieldSchema = getFieldSchema(`${fieldName}.$`, schema);
|
675
793
|
if (isNestedSchema(subSchemaOrType)) {
|
676
794
|
const convertedSubSchema = convertSchema(subSchemaOrType, options);
|
677
|
-
if (
|
795
|
+
if (flatten2) {
|
678
796
|
jsonSchema = __spreadValues(__spreadValues({}, jsonSchema), convertedSubSchema);
|
679
797
|
} else {
|
680
798
|
jsonSchema[fieldName].schema = convertedSubSchema;
|
@@ -1152,12 +1270,10 @@ var useWarnOnUnsaved = /* @__PURE__ */ __name(({ isChanged, warnUnsavedChanges }
|
|
1152
1270
|
});
|
1153
1271
|
}, "useWarnOnUnsaved");
|
1154
1272
|
|
1155
|
-
// components/VulcanComponents/
|
1156
|
-
init_esm_shims();
|
1157
|
-
|
1158
|
-
// components/VulcanComponents/Provider.tsx
|
1273
|
+
// components/VulcanComponents/Consumer.tsx
|
1159
1274
|
init_esm_shims();
|
1160
|
-
import
|
1275
|
+
import { deprecate } from "@vulcanjs/utils";
|
1276
|
+
import React4, { useContext as useContext2 } from "react";
|
1161
1277
|
|
1162
1278
|
// components/VulcanComponents/Context.ts
|
1163
1279
|
init_esm_shims();
|
@@ -1184,9 +1300,6 @@ var VulcanComponentsContext = React3.createContext(new Proxy({
|
|
1184
1300
|
VulcanComponentsContext.displayName = "VulcanComponentsContext";
|
1185
1301
|
|
1186
1302
|
// components/VulcanComponents/Consumer.tsx
|
1187
|
-
init_esm_shims();
|
1188
|
-
import { deprecate } from "@vulcanjs/utils";
|
1189
|
-
import React4, { useContext as useContext2 } from "react";
|
1190
1303
|
function _extends() {
|
1191
1304
|
_extends = Object.assign || function(target) {
|
1192
1305
|
for (var i = 1; i < arguments.length; i++) {
|
@@ -1215,8 +1328,7 @@ var withVulcanComponents = /* @__PURE__ */ __name((C) => (props) => {
|
|
1215
1328
|
}, props));
|
1216
1329
|
}, "withVulcanComponents");
|
1217
1330
|
|
1218
|
-
// components/
|
1219
|
-
import { debugVulcan } from "@vulcanjs/utils";
|
1331
|
+
// components/form/core/Form/Form.tsx
|
1220
1332
|
function _extends2() {
|
1221
1333
|
_extends2 = Object.assign || function(target) {
|
1222
1334
|
for (var i = 1; i < arguments.length; i++) {
|
@@ -1232,161 +1344,530 @@ function _extends2() {
|
|
1232
1344
|
return _extends2.apply(this, arguments);
|
1233
1345
|
}
|
1234
1346
|
__name(_extends2, "_extends");
|
1235
|
-
var
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1347
|
+
var compactParent = /* @__PURE__ */ __name((object, path) => {
|
1348
|
+
const parentPath = getParentPath(path);
|
1349
|
+
const compactIfArray = /* @__PURE__ */ __name((x) => Array.isArray(x) ? compact2(x) : x, "compactIfArray");
|
1350
|
+
update(object, parentPath, compactIfArray);
|
1351
|
+
}, "compactParent");
|
1352
|
+
var getDefaultValues = /* @__PURE__ */ __name((convertedSchema) => {
|
1353
|
+
return pickBy(mapValues(convertedSchema, (field) => field.defaultValue), (value) => value);
|
1354
|
+
}, "getDefaultValues");
|
1355
|
+
var compactObject = /* @__PURE__ */ __name((o) => omitBy(o, (f) => f === null || f === void 0), "compactObject");
|
1356
|
+
var getInitialStateFromProps = /* @__PURE__ */ __name((nextProps) => {
|
1357
|
+
const schema = nextProps.schema || nextProps.model.schema;
|
1358
|
+
const convertedSchema = convertSchema(schema);
|
1359
|
+
const formType = nextProps.document ? "edit" : "new";
|
1360
|
+
const defaultValues = formType === "new" ? getDefaultValues(convertedSchema) : {};
|
1361
|
+
const initialDocument = merge2({}, defaultValues, nextProps.prefilledProps, compactObject(nextProps.document));
|
1362
|
+
Object.keys(convertedSchema).forEach((key) => {
|
1363
|
+
let minCount = convertedSchema[key].minCount;
|
1364
|
+
if (minCount) {
|
1365
|
+
initialDocument[key] = initialDocument[key] || [];
|
1366
|
+
while (initialDocument[key].length < minCount)
|
1367
|
+
initialDocument[key].push({});
|
1250
1368
|
}
|
1251
1369
|
});
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
function _extends3() {
|
1268
|
-
_extends3 = Object.assign || function(target) {
|
1269
|
-
for (var i = 1; i < arguments.length; i++) {
|
1270
|
-
var source = arguments[i];
|
1271
|
-
for (var key in source) {
|
1272
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
1273
|
-
target[key] = source[key];
|
1274
|
-
}
|
1275
|
-
}
|
1276
|
-
}
|
1277
|
-
return target;
|
1370
|
+
removeProperty(initialDocument, "__typename");
|
1371
|
+
return {
|
1372
|
+
disabled: nextProps.disabled,
|
1373
|
+
errors: [],
|
1374
|
+
deletedValues: [],
|
1375
|
+
currentValues: {},
|
1376
|
+
originalSchema: convertSchema(schema, {
|
1377
|
+
removeArrays: false
|
1378
|
+
}),
|
1379
|
+
schema: convertedSchema,
|
1380
|
+
flatSchema: convertSchema(schema, {
|
1381
|
+
flatten: true
|
1382
|
+
}),
|
1383
|
+
initialDocument,
|
1384
|
+
currentDocument: initialDocument
|
1278
1385
|
};
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
const
|
1285
|
-
const
|
1286
|
-
|
1386
|
+
}, "getInitialStateFromProps");
|
1387
|
+
var getChildrenProps = /* @__PURE__ */ __name((props, state, options, callbacks) => {
|
1388
|
+
const { currentUser, repeatErrors, submitLabel, cancelLabel, revertLabel, cancelCallback, revertCallback, id, model, prefilledProps, itemProperties, contextName, showRemove, showDelete } = props;
|
1389
|
+
const { disabled, currentDocument } = state;
|
1390
|
+
const { formType } = options;
|
1391
|
+
const { deleteDocument } = callbacks;
|
1392
|
+
const commonProps = {
|
1393
|
+
document: currentDocument,
|
1394
|
+
formType,
|
1395
|
+
currentUser,
|
1396
|
+
disabled,
|
1397
|
+
prefilledProps,
|
1398
|
+
itemProperties,
|
1399
|
+
contextName
|
1287
1400
|
};
|
1288
|
-
const
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1300
|
-
}
|
1301
|
-
|
1401
|
+
const docClassName = `document-${formType}`;
|
1402
|
+
const modelName = model.name.toLowerCase();
|
1403
|
+
const formProps = {
|
1404
|
+
className: `${docClassName} ${docClassName}-${modelName}`,
|
1405
|
+
id
|
1406
|
+
};
|
1407
|
+
const formGroupProps = /* @__PURE__ */ __name((group) => __spreadValues(__spreadProps(__spreadValues({
|
1408
|
+
key: group.name
|
1409
|
+
}, group), {
|
1410
|
+
group: omit(group, [
|
1411
|
+
"fields"
|
1412
|
+
])
|
1413
|
+
}), commonProps), "formGroupProps");
|
1414
|
+
const formSubmitProps = {
|
1415
|
+
model,
|
1416
|
+
currentUser,
|
1417
|
+
submitLabel,
|
1418
|
+
cancelLabel,
|
1419
|
+
revertLabel,
|
1420
|
+
cancelCallback,
|
1421
|
+
revertCallback,
|
1422
|
+
document: currentDocument,
|
1423
|
+
deleteDocument: formType === "edit" && showRemove && showDelete && deleteDocument || null
|
1424
|
+
};
|
1425
|
+
const formLayoutProps = {
|
1426
|
+
formProps,
|
1427
|
+
repeatErrors,
|
1428
|
+
submitProps: formSubmitProps,
|
1429
|
+
commonProps
|
1302
1430
|
};
|
1303
|
-
return /* @__PURE__ */ React7.createElement(Components2.Button, _extends3({
|
1304
|
-
className: `loading-button ${loading ? "loading-button-loading" : "loading-button-notloading"} ${className}`,
|
1305
|
-
onClick
|
1306
|
-
}, rest), /* @__PURE__ */ React7.createElement("span", {
|
1307
|
-
style: wrapperStyle
|
1308
|
-
}, /* @__PURE__ */ React7.createElement("span", {
|
1309
|
-
style: labelStyle
|
1310
|
-
}, label || children), /* @__PURE__ */ React7.createElement("span", {
|
1311
|
-
style: loadingStyle
|
1312
|
-
}, /* @__PURE__ */ React7.createElement(Components2.Loading, null))));
|
1313
|
-
}, "LoadingButton");
|
1314
|
-
|
1315
|
-
// components/core/MutationButton.tsx
|
1316
|
-
init_esm_shims();
|
1317
|
-
import React8, { useState } from "react";
|
1318
|
-
import { useMutation } from "@apollo/client";
|
1319
|
-
|
1320
|
-
// ../../node_modules/graphql-tag/lib/index.js
|
1321
|
-
init_esm_shims();
|
1322
|
-
|
1323
|
-
// ../../node_modules/tslib/modules/index.js
|
1324
|
-
init_esm_shims();
|
1325
|
-
var import_tslib = __toESM(require_tslib(), 1);
|
1326
|
-
var { __extends, __assign, __rest, __decorate, __param, __metadata, __awaiter, __generator, __exportStar, __createBinding, __values, __read, __spread, __spreadArrays, __spreadArray, __await, __asyncGenerator, __asyncDelegator, __asyncValues, __makeTemplateObject, __importStar, __importDefault, __classPrivateFieldGet, __classPrivateFieldSet, __classPrivateFieldIn } = import_tslib.default;
|
1327
|
-
|
1328
|
-
// ../../node_modules/graphql/index.mjs
|
1329
|
-
init_esm_shims();
|
1330
|
-
|
1331
|
-
// ../../node_modules/graphql/language/parser.mjs
|
1332
|
-
init_esm_shims();
|
1333
|
-
|
1334
|
-
// ../../node_modules/graphql/error/syntaxError.mjs
|
1335
|
-
init_esm_shims();
|
1336
|
-
|
1337
|
-
// ../../node_modules/graphql/error/GraphQLError.mjs
|
1338
|
-
init_esm_shims();
|
1339
|
-
|
1340
|
-
// ../../node_modules/graphql/jsutils/isObjectLike.mjs
|
1341
|
-
init_esm_shims();
|
1342
|
-
function _typeof(obj) {
|
1343
|
-
"@babel/helpers - typeof";
|
1344
|
-
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
1345
|
-
_typeof = /* @__PURE__ */ __name(function _typeof5(obj2) {
|
1346
|
-
return typeof obj2;
|
1347
|
-
}, "_typeof");
|
1348
|
-
} else {
|
1349
|
-
_typeof = /* @__PURE__ */ __name(function _typeof5(obj2) {
|
1350
|
-
return obj2 && typeof Symbol === "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
|
1351
|
-
}, "_typeof");
|
1352
|
-
}
|
1353
|
-
return _typeof(obj);
|
1354
|
-
}
|
1355
|
-
__name(_typeof, "_typeof");
|
1356
|
-
function isObjectLike(value) {
|
1357
|
-
return _typeof(value) == "object" && value !== null;
|
1358
|
-
}
|
1359
|
-
__name(isObjectLike, "isObjectLike");
|
1360
|
-
|
1361
|
-
// ../../node_modules/graphql/polyfills/symbols.mjs
|
1362
|
-
init_esm_shims();
|
1363
|
-
var SYMBOL_ITERATOR = typeof Symbol === "function" && Symbol.iterator != null ? Symbol.iterator : "@@iterator";
|
1364
|
-
var SYMBOL_ASYNC_ITERATOR = typeof Symbol === "function" && Symbol.asyncIterator != null ? Symbol.asyncIterator : "@@asyncIterator";
|
1365
|
-
var SYMBOL_TO_STRING_TAG = typeof Symbol === "function" && Symbol.toStringTag != null ? Symbol.toStringTag : "@@toStringTag";
|
1366
|
-
|
1367
|
-
// ../../node_modules/graphql/language/location.mjs
|
1368
|
-
init_esm_shims();
|
1369
|
-
function getLocation(source, position) {
|
1370
|
-
var lineRegexp = /\r\n|[\n\r]/g;
|
1371
|
-
var line = 1;
|
1372
|
-
var column = position + 1;
|
1373
|
-
var match;
|
1374
|
-
while ((match = lineRegexp.exec(source.body)) && match.index < position) {
|
1375
|
-
line += 1;
|
1376
|
-
column = position + 1 - (match.index + match[0].length);
|
1377
|
-
}
|
1378
1431
|
return {
|
1379
|
-
|
1380
|
-
|
1432
|
+
commonProps,
|
1433
|
+
formSubmitProps,
|
1434
|
+
formGroupProps,
|
1435
|
+
formLayoutProps
|
1381
1436
|
};
|
1382
|
-
}
|
1383
|
-
__name(
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
return
|
1389
|
-
}
|
1437
|
+
}, "getChildrenProps");
|
1438
|
+
var FormWarnUnsaved = /* @__PURE__ */ __name(({ isChanged, warnUnsavedChanges, children }) => {
|
1439
|
+
useWarnOnUnsaved({
|
1440
|
+
isChanged,
|
1441
|
+
warnUnsavedChanges
|
1442
|
+
});
|
1443
|
+
return /* @__PURE__ */ React5.createElement(React5.Fragment, null, children);
|
1444
|
+
}, "FormWarnUnsaved");
|
1445
|
+
var getData = /* @__PURE__ */ __name((customArgs, props, state, { submitFormCallbacks, form }) => {
|
1446
|
+
const { currentDocument } = state;
|
1447
|
+
const { model, prefilledProps } = props;
|
1448
|
+
let data = prefilledProps || {};
|
1449
|
+
data = omitBy(data, (value, key) => key.endsWith(".$"));
|
1450
|
+
const args = __spreadValues({
|
1451
|
+
schema: model.schema,
|
1452
|
+
excludeRemovedFields: false,
|
1453
|
+
excludeHiddenFields: false,
|
1454
|
+
replaceIntlFields: true,
|
1455
|
+
addExtraFields: false
|
1456
|
+
}, customArgs);
|
1457
|
+
const fields = getFieldNames(props, currentDocument, args);
|
1458
|
+
data = __spreadValues(__spreadValues({}, data), pick2(currentDocument, ...fields));
|
1459
|
+
state.deletedValues.forEach((path) => {
|
1460
|
+
if (path.includes(".")) {
|
1461
|
+
compactParent(data, path);
|
1462
|
+
}
|
1463
|
+
});
|
1464
|
+
data = runCallbacks({
|
1465
|
+
callbacks: submitFormCallbacks,
|
1466
|
+
iterator: data,
|
1467
|
+
args: [
|
1468
|
+
{}
|
1469
|
+
]
|
1470
|
+
});
|
1471
|
+
return data;
|
1472
|
+
}, "getData");
|
1473
|
+
var Form = /* @__PURE__ */ __name((props) => {
|
1474
|
+
const { initCallback, createDocument, updateDocument, deleteDocument } = props;
|
1475
|
+
const initialState = getInitialStateFromProps(props);
|
1476
|
+
const { schema, originalSchema, flatSchema, initialDocument } = initialState;
|
1477
|
+
const isFirstRender = useRef2(true);
|
1478
|
+
useEffect2(() => {
|
1479
|
+
if (isFirstRender.current) {
|
1480
|
+
isFirstRender.current = false;
|
1481
|
+
return;
|
1482
|
+
}
|
1483
|
+
if (initCallback)
|
1484
|
+
initCallback(initialState.currentDocument);
|
1485
|
+
}, [
|
1486
|
+
initCallback
|
1487
|
+
]);
|
1488
|
+
const defaultProps = {
|
1489
|
+
layout: "horizontal",
|
1490
|
+
prefilledProps: {},
|
1491
|
+
repeatErrors: false,
|
1492
|
+
showRemove: true,
|
1493
|
+
showDelete: true
|
1494
|
+
};
|
1495
|
+
const allProps = __spreadValues(__spreadValues({}, defaultProps), props);
|
1496
|
+
const defaultValues = {};
|
1497
|
+
const submitFormCallbacks = [];
|
1498
|
+
const successFormCallbacks = [];
|
1499
|
+
const failureFormCallbacks = [];
|
1500
|
+
const intl = useIntlContext2();
|
1501
|
+
const [errors, setErrors] = useState([]);
|
1502
|
+
const throwError = /* @__PURE__ */ __name((error) => {
|
1503
|
+
let formErrors = getErrors(error);
|
1504
|
+
console.log(formErrors);
|
1505
|
+
setErrors((prevErrors) => [
|
1506
|
+
...prevErrors,
|
1507
|
+
...formErrors
|
1508
|
+
]);
|
1509
|
+
}, "throwError");
|
1510
|
+
const clearFieldErrors = /* @__PURE__ */ __name((path) => {
|
1511
|
+
setErrors((prevErrors) => prevErrors.filter((error) => error.path !== path));
|
1512
|
+
}, "clearFieldErrors");
|
1513
|
+
const [deletedValues, setDeletedValues] = useState([]);
|
1514
|
+
const addToDeletedValues = /* @__PURE__ */ __name((name) => {
|
1515
|
+
setDeletedValues((prevDeletedValues) => [
|
1516
|
+
...prevDeletedValues,
|
1517
|
+
name
|
1518
|
+
]);
|
1519
|
+
}, "addToDeletedValues");
|
1520
|
+
const [callbacks, setCallbacks] = useState({
|
1521
|
+
submitFormCallbacks: [],
|
1522
|
+
successFormCallbacks: [],
|
1523
|
+
failureFormCallbacks: []
|
1524
|
+
});
|
1525
|
+
const addToSubmitForm = /* @__PURE__ */ __name((callback) => {
|
1526
|
+
setCallbacks((cbs) => __spreadValues({}, cbs));
|
1527
|
+
}, "addToSubmitForm");
|
1528
|
+
const addToSuccessForm = /* @__PURE__ */ __name((callback) => {
|
1529
|
+
setCallbacks((cbs) => __spreadProps(__spreadValues({}, cbs), {
|
1530
|
+
successFormCallbacks: [
|
1531
|
+
...cbs.successFormCallbacks,
|
1532
|
+
callback
|
1533
|
+
]
|
1534
|
+
}));
|
1535
|
+
}, "addToSuccessForm");
|
1536
|
+
const addToFailureForm = /* @__PURE__ */ __name((callback) => {
|
1537
|
+
setCallbacks((cbs) => __spreadProps(__spreadValues({}, cbs), {
|
1538
|
+
failureFormCallbacks: [
|
1539
|
+
...cbs.failureFormCallbacks,
|
1540
|
+
callback
|
1541
|
+
]
|
1542
|
+
}));
|
1543
|
+
}, "addToFailureForm");
|
1544
|
+
const clearFormCallbacks = /* @__PURE__ */ __name(() => {
|
1545
|
+
setCallbacks({
|
1546
|
+
submitFormCallbacks: [],
|
1547
|
+
successFormCallbacks: [],
|
1548
|
+
failureFormCallbacks: []
|
1549
|
+
});
|
1550
|
+
}, "clearFormCallbacks");
|
1551
|
+
const [currentValues, setCurrentValues] = useState({});
|
1552
|
+
const submitFormContext = /* @__PURE__ */ __name((formType) => (event) => {
|
1553
|
+
submitForm(formType)(event);
|
1554
|
+
}, "submitFormContext");
|
1555
|
+
const [currentDocument, setCurrentDocument] = useState(initialDocument);
|
1556
|
+
const updateCurrentValues = /* @__PURE__ */ __name((newValues, options = {}) => {
|
1557
|
+
const { mode = "overwrite" } = options;
|
1558
|
+
const { changeCallback } = props;
|
1559
|
+
const newState = {
|
1560
|
+
currentValues: cloneDeep(currentValues),
|
1561
|
+
currentDocument: cloneDeep(currentDocument),
|
1562
|
+
deletedValues: cloneDeep(deletedValues)
|
1563
|
+
};
|
1564
|
+
Object.keys(newValues).forEach((key) => {
|
1565
|
+
const path = key;
|
1566
|
+
let value = newValues[key];
|
1567
|
+
if (isEmptyValue(value)) {
|
1568
|
+
unset(newState.currentValues, path);
|
1569
|
+
set2(newState.currentDocument, path, null);
|
1570
|
+
newState.deletedValues = [
|
1571
|
+
...newState.deletedValues,
|
1572
|
+
path
|
1573
|
+
];
|
1574
|
+
} else {
|
1575
|
+
set2(newState.currentValues, path, value);
|
1576
|
+
if (mode === "merge" && (Array.isArray(value) || isObject(value))) {
|
1577
|
+
const oldValue = get2(newState.currentDocument, path);
|
1578
|
+
set2(newState.currentDocument, path, merge2(oldValue, value));
|
1579
|
+
} else {
|
1580
|
+
set2(newState.currentDocument, path, value);
|
1581
|
+
}
|
1582
|
+
newState.deletedValues = without(newState.deletedValues, path);
|
1583
|
+
}
|
1584
|
+
});
|
1585
|
+
if (changeCallback)
|
1586
|
+
changeCallback(newState.currentDocument);
|
1587
|
+
setCurrentValues(newState.currentValues);
|
1588
|
+
setCurrentDocument(newState.currentDocument);
|
1589
|
+
setDeletedValues(newState.deletedValues);
|
1590
|
+
}, "updateCurrentValues");
|
1591
|
+
const refetchForm = /* @__PURE__ */ __name(() => {
|
1592
|
+
if (props.refetch) {
|
1593
|
+
props.refetch();
|
1594
|
+
}
|
1595
|
+
}, "refetchForm");
|
1596
|
+
const [disabled, setDisabled] = useState(false);
|
1597
|
+
const [success, setSuccess] = useState(false);
|
1598
|
+
const clearForm = /* @__PURE__ */ __name((options = {}) => {
|
1599
|
+
const { document: optionsDocument } = options;
|
1600
|
+
const document = optionsDocument ? merge2({}, props.prefilledProps, optionsDocument) : null;
|
1601
|
+
setErrors([]);
|
1602
|
+
setCurrentValues({});
|
1603
|
+
setDeletedValues([]);
|
1604
|
+
setCurrentDocument(document || initialDocument);
|
1605
|
+
setDisabled(false);
|
1606
|
+
}, "clearForm");
|
1607
|
+
const newMutationSuccessCallback = /* @__PURE__ */ __name(function(result) {
|
1608
|
+
mutationSuccessCallback(result, "new");
|
1609
|
+
}, "newMutationSuccessCallback");
|
1610
|
+
const editMutationSuccessCallback = /* @__PURE__ */ __name(function(result) {
|
1611
|
+
mutationSuccessCallback(result, "edit");
|
1612
|
+
}, "editMutationSuccessCallback");
|
1613
|
+
const formRef = useRef2(null);
|
1614
|
+
const mutationSuccessCallback = /* @__PURE__ */ __name(function(result, mutationType) {
|
1615
|
+
setDisabled(false);
|
1616
|
+
setSuccess(true);
|
1617
|
+
if (mutationType === "new")
|
1618
|
+
refetchForm();
|
1619
|
+
let { document } = result;
|
1620
|
+
if (formRef.current) {
|
1621
|
+
clearForm({
|
1622
|
+
document: mutationType === "edit" ? document : void 0
|
1623
|
+
});
|
1624
|
+
}
|
1625
|
+
document = runCallbacks({
|
1626
|
+
callbacks: successFormCallbacks,
|
1627
|
+
iterator: document,
|
1628
|
+
args: [
|
1629
|
+
{
|
1630
|
+
form: formRef.current
|
1631
|
+
}
|
1632
|
+
]
|
1633
|
+
});
|
1634
|
+
if (props.successCallback)
|
1635
|
+
props.successCallback(document, {
|
1636
|
+
form: this
|
1637
|
+
});
|
1638
|
+
}, "mutationSuccessCallback");
|
1639
|
+
const mutationErrorCallback = /* @__PURE__ */ __name((document, error) => {
|
1640
|
+
setDisabled(false);
|
1641
|
+
console.error("// graphQL Error");
|
1642
|
+
console.error(error);
|
1643
|
+
runCallbacks({
|
1644
|
+
callbacks: failureFormCallbacks,
|
1645
|
+
iterator: error,
|
1646
|
+
args: [
|
1647
|
+
{
|
1648
|
+
error,
|
1649
|
+
form: formRef.current
|
1650
|
+
}
|
1651
|
+
]
|
1652
|
+
});
|
1653
|
+
if (!isEmpty(error)) {
|
1654
|
+
throwError(error);
|
1655
|
+
}
|
1656
|
+
if (props.errorCallback)
|
1657
|
+
props.errorCallback(document, error, {
|
1658
|
+
form: void 0
|
1659
|
+
});
|
1660
|
+
}, "mutationErrorCallback");
|
1661
|
+
const submitForm = /* @__PURE__ */ __name((formType) => async (event) => {
|
1662
|
+
var _a, _b;
|
1663
|
+
event && event.preventDefault();
|
1664
|
+
event && event.stopPropagation();
|
1665
|
+
const { contextName } = props;
|
1666
|
+
if (disabled) {
|
1667
|
+
return;
|
1668
|
+
}
|
1669
|
+
setErrors([]);
|
1670
|
+
setDisabled(true);
|
1671
|
+
let data = getData({
|
1672
|
+
replaceIntlFields: true,
|
1673
|
+
addExtraFields: false,
|
1674
|
+
mutableFields
|
1675
|
+
}, props, {
|
1676
|
+
currentDocument,
|
1677
|
+
deletedValues
|
1678
|
+
}, {
|
1679
|
+
form: formRef.current,
|
1680
|
+
submitFormCallbacks
|
1681
|
+
});
|
1682
|
+
if (props.submitCallback) {
|
1683
|
+
data = props.submitCallback(data) || data;
|
1684
|
+
}
|
1685
|
+
if (formType === "new") {
|
1686
|
+
try {
|
1687
|
+
const result = await createDocument({
|
1688
|
+
input: {
|
1689
|
+
data,
|
1690
|
+
contextName
|
1691
|
+
}
|
1692
|
+
});
|
1693
|
+
if ((_a = result.errors) == null ? void 0 : _a.length) {
|
1694
|
+
mutationErrorCallback(document1, result.errors[0]);
|
1695
|
+
} else {
|
1696
|
+
newMutationSuccessCallback(result);
|
1697
|
+
}
|
1698
|
+
} catch (error) {
|
1699
|
+
mutationErrorCallback(document1, error);
|
1700
|
+
}
|
1701
|
+
} else {
|
1702
|
+
try {
|
1703
|
+
const documentId = currentDocument._id;
|
1704
|
+
const result = await updateDocument({
|
1705
|
+
input: {
|
1706
|
+
id: documentId,
|
1707
|
+
data,
|
1708
|
+
contextName
|
1709
|
+
}
|
1710
|
+
});
|
1711
|
+
if ((_b = result.errors) == null ? void 0 : _b.length) {
|
1712
|
+
mutationErrorCallback(document1, result.errors[0]);
|
1713
|
+
} else {
|
1714
|
+
editMutationSuccessCallback(result);
|
1715
|
+
}
|
1716
|
+
} catch (error) {
|
1717
|
+
mutationErrorCallback(document1, error);
|
1718
|
+
}
|
1719
|
+
}
|
1720
|
+
}, "submitForm");
|
1721
|
+
const deleteDocumentWithConfirm = /* @__PURE__ */ __name(() => {
|
1722
|
+
const document = currentDocument;
|
1723
|
+
const documentId = props.document._id;
|
1724
|
+
const documentTitle = document.title || document.name || "";
|
1725
|
+
const deleteDocumentConfirm = intl.formatMessage({
|
1726
|
+
id: "forms.delete_confirm"
|
1727
|
+
}, {
|
1728
|
+
title: documentTitle
|
1729
|
+
});
|
1730
|
+
if (window.confirm(deleteDocumentConfirm)) {
|
1731
|
+
deleteDocument({
|
1732
|
+
input: {
|
1733
|
+
id: documentId
|
1734
|
+
}
|
1735
|
+
}).then((mutationResult) => {
|
1736
|
+
if (props.removeSuccessCallback)
|
1737
|
+
props.removeSuccessCallback({
|
1738
|
+
documentId,
|
1739
|
+
documentTitle
|
1740
|
+
});
|
1741
|
+
refetchForm();
|
1742
|
+
}).catch((error) => {
|
1743
|
+
console.log(error);
|
1744
|
+
});
|
1745
|
+
}
|
1746
|
+
}, "deleteDocumentWithConfirm");
|
1747
|
+
const { successComponent, document: document1, currentUser, model, warnUnsavedChanges } = props;
|
1748
|
+
const FormComponents = useVulcanComponents();
|
1749
|
+
const formType1 = document1 ? "edit" : "new";
|
1750
|
+
const mutableFields = formType1 === "edit" ? getEditableFields(schema, currentUser, initialDocument) : getInsertableFields(schema, currentUser);
|
1751
|
+
const { formLayoutProps, formGroupProps } = getChildrenProps(props, {
|
1752
|
+
disabled,
|
1753
|
+
currentDocument
|
1754
|
+
}, {
|
1755
|
+
formType: formType1
|
1756
|
+
}, {
|
1757
|
+
deleteDocument: deleteDocumentWithConfirm
|
1758
|
+
});
|
1759
|
+
const isChanged = isNotSameDocument(initialDocument, currentDocument);
|
1760
|
+
return success && successComponent ? successComponent : /* @__PURE__ */ React5.createElement(FormWarnUnsaved, {
|
1761
|
+
isChanged,
|
1762
|
+
warnUnsavedChanges
|
1763
|
+
}, /* @__PURE__ */ React5.createElement(FormContext.Provider, {
|
1764
|
+
value: {
|
1765
|
+
throwError,
|
1766
|
+
clearForm,
|
1767
|
+
refetchForm,
|
1768
|
+
isChanged,
|
1769
|
+
submitForm: submitFormContext(formType1),
|
1770
|
+
addToDeletedValues,
|
1771
|
+
updateCurrentValues,
|
1772
|
+
getDocument: () => currentDocument,
|
1773
|
+
getLabel: (fieldName, fieldLocale) => getLabel(model, flatSchema, intl, fieldName, fieldLocale),
|
1774
|
+
initialDocument,
|
1775
|
+
addToSubmitForm,
|
1776
|
+
addToSuccessForm,
|
1777
|
+
addToFailureForm,
|
1778
|
+
clearFormCallbacks,
|
1779
|
+
errors,
|
1780
|
+
currentValues,
|
1781
|
+
deletedValues,
|
1782
|
+
clearFieldErrors
|
1783
|
+
}
|
1784
|
+
}, /* @__PURE__ */ React5.createElement(FormComponents.FormLayout, _extends2({}, formLayoutProps), getFieldGroups(props, {
|
1785
|
+
currentDocument,
|
1786
|
+
schema,
|
1787
|
+
flatSchema,
|
1788
|
+
originalSchema
|
1789
|
+
}, intl, mutableFields, intl.formatMessage).map((group, i) => /* @__PURE__ */ React5.createElement(FormComponents.FormGroup, _extends2({
|
1790
|
+
key: i
|
1791
|
+
}, formGroupProps(group)))))));
|
1792
|
+
}, "Form");
|
1793
|
+
|
1794
|
+
// components/form/core/Form/typings.ts
|
1795
|
+
init_esm_shims();
|
1796
|
+
|
1797
|
+
// components/form/core/FormContainer.tsx
|
1798
|
+
init_esm_shims();
|
1799
|
+
import React8 from "react";
|
1800
|
+
|
1801
|
+
// ../../node_modules/graphql-tag/lib/index.js
|
1802
|
+
init_esm_shims();
|
1803
|
+
|
1804
|
+
// ../../node_modules/tslib/modules/index.js
|
1805
|
+
init_esm_shims();
|
1806
|
+
var import_tslib = __toESM(require_tslib(), 1);
|
1807
|
+
var { __extends, __assign, __rest, __decorate, __param, __metadata, __awaiter, __generator, __exportStar, __createBinding, __values, __read, __spread, __spreadArrays, __spreadArray, __await, __asyncGenerator, __asyncDelegator, __asyncValues, __makeTemplateObject, __importStar, __importDefault, __classPrivateFieldGet, __classPrivateFieldSet, __classPrivateFieldIn } = import_tslib.default;
|
1808
|
+
|
1809
|
+
// ../../node_modules/graphql/index.mjs
|
1810
|
+
init_esm_shims();
|
1811
|
+
|
1812
|
+
// ../../node_modules/graphql/language/parser.mjs
|
1813
|
+
init_esm_shims();
|
1814
|
+
|
1815
|
+
// ../../node_modules/graphql/error/syntaxError.mjs
|
1816
|
+
init_esm_shims();
|
1817
|
+
|
1818
|
+
// ../../node_modules/graphql/error/GraphQLError.mjs
|
1819
|
+
init_esm_shims();
|
1820
|
+
|
1821
|
+
// ../../node_modules/graphql/jsutils/isObjectLike.mjs
|
1822
|
+
init_esm_shims();
|
1823
|
+
function _typeof(obj) {
|
1824
|
+
"@babel/helpers - typeof";
|
1825
|
+
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
1826
|
+
_typeof = /* @__PURE__ */ __name(function _typeof5(obj2) {
|
1827
|
+
return typeof obj2;
|
1828
|
+
}, "_typeof");
|
1829
|
+
} else {
|
1830
|
+
_typeof = /* @__PURE__ */ __name(function _typeof5(obj2) {
|
1831
|
+
return obj2 && typeof Symbol === "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
|
1832
|
+
}, "_typeof");
|
1833
|
+
}
|
1834
|
+
return _typeof(obj);
|
1835
|
+
}
|
1836
|
+
__name(_typeof, "_typeof");
|
1837
|
+
function isObjectLike(value) {
|
1838
|
+
return _typeof(value) == "object" && value !== null;
|
1839
|
+
}
|
1840
|
+
__name(isObjectLike, "isObjectLike");
|
1841
|
+
|
1842
|
+
// ../../node_modules/graphql/polyfills/symbols.mjs
|
1843
|
+
init_esm_shims();
|
1844
|
+
var SYMBOL_ITERATOR = typeof Symbol === "function" && Symbol.iterator != null ? Symbol.iterator : "@@iterator";
|
1845
|
+
var SYMBOL_ASYNC_ITERATOR = typeof Symbol === "function" && Symbol.asyncIterator != null ? Symbol.asyncIterator : "@@asyncIterator";
|
1846
|
+
var SYMBOL_TO_STRING_TAG = typeof Symbol === "function" && Symbol.toStringTag != null ? Symbol.toStringTag : "@@toStringTag";
|
1847
|
+
|
1848
|
+
// ../../node_modules/graphql/language/location.mjs
|
1849
|
+
init_esm_shims();
|
1850
|
+
function getLocation(source, position) {
|
1851
|
+
var lineRegexp = /\r\n|[\n\r]/g;
|
1852
|
+
var line = 1;
|
1853
|
+
var column = position + 1;
|
1854
|
+
var match;
|
1855
|
+
while ((match = lineRegexp.exec(source.body)) && match.index < position) {
|
1856
|
+
line += 1;
|
1857
|
+
column = position + 1 - (match.index + match[0].length);
|
1858
|
+
}
|
1859
|
+
return {
|
1860
|
+
line,
|
1861
|
+
column
|
1862
|
+
};
|
1863
|
+
}
|
1864
|
+
__name(getLocation, "getLocation");
|
1865
|
+
|
1866
|
+
// ../../node_modules/graphql/language/printLocation.mjs
|
1867
|
+
init_esm_shims();
|
1868
|
+
function printLocation(location) {
|
1869
|
+
return printSourceLocation(location.source, getLocation(location.source, location.start));
|
1870
|
+
}
|
1390
1871
|
__name(printLocation, "printLocation");
|
1391
1872
|
function printSourceLocation(source, sourceLocation) {
|
1392
1873
|
var firstLineColumnOffset = source.locationOffset.column - 1;
|
@@ -3561,145 +4042,67 @@ __name(parseDocument, "parseDocument");
|
|
3561
4042
|
function gql(literals) {
|
3562
4043
|
var args = [];
|
3563
4044
|
for (var _i = 1; _i < arguments.length; _i++) {
|
3564
|
-
args[_i - 1] = arguments[_i];
|
3565
|
-
}
|
3566
|
-
if (typeof literals === "string") {
|
3567
|
-
literals = [
|
3568
|
-
literals
|
3569
|
-
];
|
3570
|
-
}
|
3571
|
-
var result = literals[0];
|
3572
|
-
args.forEach(function(arg, i) {
|
3573
|
-
if (arg && arg.kind === "Document") {
|
3574
|
-
result += arg.loc.source.body;
|
3575
|
-
} else {
|
3576
|
-
result += arg;
|
3577
|
-
}
|
3578
|
-
result += literals[i + 1];
|
3579
|
-
});
|
3580
|
-
return parseDocument(result);
|
3581
|
-
}
|
3582
|
-
__name(gql, "gql");
|
3583
|
-
function resetCaches() {
|
3584
|
-
docCache.clear();
|
3585
|
-
fragmentSourceMap.clear();
|
3586
|
-
}
|
3587
|
-
__name(resetCaches, "resetCaches");
|
3588
|
-
function disableFragmentWarnings() {
|
3589
|
-
printFragmentWarnings = false;
|
3590
|
-
}
|
3591
|
-
__name(disableFragmentWarnings, "disableFragmentWarnings");
|
3592
|
-
function enableExperimentalFragmentVariables() {
|
3593
|
-
experimentalFragmentVariables = true;
|
3594
|
-
}
|
3595
|
-
__name(enableExperimentalFragmentVariables, "enableExperimentalFragmentVariables");
|
3596
|
-
function disableExperimentalFragmentVariables() {
|
3597
|
-
experimentalFragmentVariables = false;
|
3598
|
-
}
|
3599
|
-
__name(disableExperimentalFragmentVariables, "disableExperimentalFragmentVariables");
|
3600
|
-
var extras = {
|
3601
|
-
gql,
|
3602
|
-
resetCaches,
|
3603
|
-
disableFragmentWarnings,
|
3604
|
-
enableExperimentalFragmentVariables,
|
3605
|
-
disableExperimentalFragmentVariables
|
3606
|
-
};
|
3607
|
-
(function(gql_1) {
|
3608
|
-
gql_1.gql = extras.gql, gql_1.resetCaches = extras.resetCaches, gql_1.disableFragmentWarnings = extras.disableFragmentWarnings, gql_1.enableExperimentalFragmentVariables = extras.enableExperimentalFragmentVariables, gql_1.disableExperimentalFragmentVariables = extras.disableExperimentalFragmentVariables;
|
3609
|
-
})(gql || (gql = {}));
|
3610
|
-
gql["default"] = gql;
|
3611
|
-
var lib_default = gql;
|
3612
|
-
|
3613
|
-
// components/core/MutationButton.tsx
|
3614
|
-
function _extends4() {
|
3615
|
-
_extends4 = Object.assign || function(target) {
|
3616
|
-
for (var i = 1; i < arguments.length; i++) {
|
3617
|
-
var source = arguments[i];
|
3618
|
-
for (var key in source) {
|
3619
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
3620
|
-
target[key] = source[key];
|
3621
|
-
}
|
3622
|
-
}
|
3623
|
-
}
|
3624
|
-
return target;
|
3625
|
-
};
|
3626
|
-
return _extends4.apply(this, arguments);
|
3627
|
-
}
|
3628
|
-
__name(_extends4, "_extends");
|
3629
|
-
var MutationButton = /* @__PURE__ */ __name((props) => {
|
3630
|
-
const Components2 = useVulcanComponents();
|
3631
|
-
const [loading, setLoading] = useState(false);
|
3632
|
-
const [error1, setError] = useState();
|
3633
|
-
const {
|
3634
|
-
mutation,
|
3635
|
-
loadingButtonProps = {},
|
3636
|
-
label
|
3637
|
-
} = props;
|
3638
|
-
let { mutationArguments } = props;
|
3639
|
-
const mutationAsNode = typeof mutation === "string" ? lib_default`
|
3640
|
-
${mutation}
|
3641
|
-
` : mutation;
|
3642
|
-
const [mutationFunc] = useMutation(mutationAsNode);
|
3643
|
-
const handleClick = /* @__PURE__ */ __name(async (e) => {
|
3644
|
-
e.preventDefault();
|
3645
|
-
setLoading(true);
|
3646
|
-
setError(void 0);
|
3647
|
-
const {
|
3648
|
-
submitCallback,
|
3649
|
-
successCallback,
|
3650
|
-
errorCallback
|
3651
|
-
} = props;
|
3652
|
-
try {
|
3653
|
-
if (submitCallback) {
|
3654
|
-
const callbackReturn = await submitCallback(mutationArguments);
|
3655
|
-
if (callbackReturn && callbackReturn.mutationArguments) {
|
3656
|
-
mutationArguments = callbackReturn.mutationArguments;
|
3657
|
-
}
|
3658
|
-
}
|
3659
|
-
const result = await mutationFunc({
|
3660
|
-
variables: mutationArguments
|
3661
|
-
});
|
3662
|
-
if (successCallback) {
|
3663
|
-
await successCallback(result);
|
3664
|
-
}
|
3665
|
-
} catch (error) {
|
3666
|
-
setError(error);
|
3667
|
-
if (errorCallback) {
|
3668
|
-
await errorCallback(error);
|
3669
|
-
}
|
3670
|
-
} finally {
|
3671
|
-
setLoading(false);
|
3672
|
-
}
|
3673
|
-
}, "handleClick");
|
3674
|
-
const loadingButton = /* @__PURE__ */ React8.createElement(Components2.LoadingButton, _extends4({
|
3675
|
-
loading,
|
3676
|
-
onClick: handleClick,
|
3677
|
-
label
|
3678
|
-
}, loadingButtonProps));
|
3679
|
-
if (error1) {
|
3680
|
-
return /* @__PURE__ */ React8.createElement(Components2.TooltipTrigger, {
|
3681
|
-
trigger: loadingButton,
|
3682
|
-
defaultShow: true
|
3683
|
-
}, error1.message.replace("GraphQL error: ", ""));
|
4045
|
+
args[_i - 1] = arguments[_i];
|
3684
4046
|
}
|
3685
|
-
|
3686
|
-
|
3687
|
-
|
3688
|
-
|
3689
|
-
|
3690
|
-
|
3691
|
-
|
3692
|
-
|
3693
|
-
|
4047
|
+
if (typeof literals === "string") {
|
4048
|
+
literals = [
|
4049
|
+
literals
|
4050
|
+
];
|
4051
|
+
}
|
4052
|
+
var result = literals[0];
|
4053
|
+
args.forEach(function(arg, i) {
|
4054
|
+
if (arg && arg.kind === "Document") {
|
4055
|
+
result += arg.loc.source.body;
|
4056
|
+
} else {
|
4057
|
+
result += arg;
|
4058
|
+
}
|
4059
|
+
result += literals[i + 1];
|
4060
|
+
});
|
4061
|
+
return parseDocument(result);
|
4062
|
+
}
|
4063
|
+
__name(gql, "gql");
|
4064
|
+
function resetCaches() {
|
4065
|
+
docCache.clear();
|
4066
|
+
fragmentSourceMap.clear();
|
4067
|
+
}
|
4068
|
+
__name(resetCaches, "resetCaches");
|
4069
|
+
function disableFragmentWarnings() {
|
4070
|
+
printFragmentWarnings = false;
|
4071
|
+
}
|
4072
|
+
__name(disableFragmentWarnings, "disableFragmentWarnings");
|
4073
|
+
function enableExperimentalFragmentVariables() {
|
4074
|
+
experimentalFragmentVariables = true;
|
4075
|
+
}
|
4076
|
+
__name(enableExperimentalFragmentVariables, "enableExperimentalFragmentVariables");
|
4077
|
+
function disableExperimentalFragmentVariables() {
|
4078
|
+
experimentalFragmentVariables = false;
|
4079
|
+
}
|
4080
|
+
__name(disableExperimentalFragmentVariables, "disableExperimentalFragmentVariables");
|
4081
|
+
var extras = {
|
4082
|
+
gql,
|
4083
|
+
resetCaches,
|
4084
|
+
disableFragmentWarnings,
|
4085
|
+
enableExperimentalFragmentVariables,
|
4086
|
+
disableExperimentalFragmentVariables
|
4087
|
+
};
|
4088
|
+
(function(gql_1) {
|
4089
|
+
gql_1.gql = extras.gql, gql_1.resetCaches = extras.resetCaches, gql_1.disableFragmentWarnings = extras.disableFragmentWarnings, gql_1.enableExperimentalFragmentVariables = extras.enableExperimentalFragmentVariables, gql_1.disableExperimentalFragmentVariables = extras.disableExperimentalFragmentVariables;
|
4090
|
+
})(gql || (gql = {}));
|
4091
|
+
gql["default"] = gql;
|
4092
|
+
var lib_default = gql;
|
3694
4093
|
|
3695
4094
|
// components/form/utils/formFragments.ts
|
4095
|
+
var formFragments_exports = {};
|
4096
|
+
__export(formFragments_exports, {
|
4097
|
+
default: () => formFragments_default
|
4098
|
+
});
|
3696
4099
|
init_esm_shims();
|
3697
4100
|
import _uniq from "lodash/uniq.js";
|
3698
4101
|
import _intersection from "lodash/intersection.js";
|
3699
4102
|
import { getCreateableFields, getUpdateableFields, getFragmentFieldNames } from "@vulcanjs/schema";
|
3700
4103
|
import { getFieldFragment } from "@vulcanjs/graphql";
|
3701
4104
|
import { capitalize as capitalize2 } from "@vulcanjs/utils";
|
3702
|
-
import
|
4105
|
+
import compact3 from "lodash/compact.js";
|
3703
4106
|
var intlSuffix = "_intl";
|
3704
4107
|
var getFragmentName = /* @__PURE__ */ __name((formType, multiTypeName, fragmentType) => [
|
3705
4108
|
multiTypeName,
|
@@ -3815,7 +4218,7 @@ var getFormFragments = /* @__PURE__ */ __name(({ formType = "new", model, fields
|
|
3815
4218
|
throw new Error(`Model ${model.name} with fields ${mutationFieldNames} yield an empty mutation fragment.`);
|
3816
4219
|
}
|
3817
4220
|
const generatedMutationFragment = lib_default(mutationFragmentText);
|
3818
|
-
const extraQueries =
|
4221
|
+
const extraQueries = compact3(getQueryFieldNames({
|
3819
4222
|
schema,
|
3820
4223
|
options: {
|
3821
4224
|
formType
|
@@ -3838,7 +4241,7 @@ var formFragments_default = getFormFragments;
|
|
3838
4241
|
import { getFragmentName as getFragmentName2 } from "@vulcanjs/graphql";
|
3839
4242
|
import { capitalize as capitalize3 } from "@vulcanjs/utils";
|
3840
4243
|
import { useSingle, useCreate, useUpdate, useDelete } from "@vulcanjs/react-hooks";
|
3841
|
-
import { debugVulcan
|
4244
|
+
import { debugVulcan } from "@vulcanjs/utils";
|
3842
4245
|
|
3843
4246
|
// components/VulcanCurrentUser/index.ts
|
3844
4247
|
init_esm_shims();
|
@@ -3848,210 +4251,22 @@ init_esm_shims();
|
|
3848
4251
|
import { useContext as useContext3 } from "react";
|
3849
4252
|
|
3850
4253
|
// components/VulcanCurrentUser/Context.ts
|
3851
|
-
init_esm_shims();
|
3852
|
-
import
|
3853
|
-
var VulcanCurrentUserContext =
|
3854
|
-
currentUser: null,
|
3855
|
-
loading: false
|
3856
|
-
});
|
3857
|
-
|
3858
|
-
// components/VulcanCurrentUser/Consumer.tsx
|
3859
|
-
var VulcanCurrentUserConsumer = VulcanCurrentUserContext.Consumer;
|
3860
|
-
var useVulcanCurrentUser = /* @__PURE__ */ __name(() => useContext3(VulcanCurrentUserContext), "useVulcanCurrentUser");
|
3861
|
-
|
3862
|
-
// components/VulcanCurrentUser/Provider.tsx
|
3863
|
-
init_esm_shims();
|
3864
|
-
import React10 from "react";
|
3865
|
-
function _extends5() {
|
3866
|
-
_extends5 = Object.assign || function(target) {
|
3867
|
-
for (var i = 1; i < arguments.length; i++) {
|
3868
|
-
var source = arguments[i];
|
3869
|
-
for (var key in source) {
|
3870
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
3871
|
-
target[key] = source[key];
|
3872
|
-
}
|
3873
|
-
}
|
3874
|
-
}
|
3875
|
-
return target;
|
3876
|
-
};
|
3877
|
-
return _extends5.apply(this, arguments);
|
3878
|
-
}
|
3879
|
-
__name(_extends5, "_extends");
|
3880
|
-
var VulcanCurrentUserProvider = /* @__PURE__ */ __name((_a) => {
|
3881
|
-
var _b = _a, { value } = _b, props = __objRest(_b, ["value"]);
|
3882
|
-
return /* @__PURE__ */ React10.createElement(VulcanCurrentUserContext.Provider, _extends5({
|
3883
|
-
value
|
3884
|
-
}, props));
|
3885
|
-
}, "VulcanCurrentUserProvider");
|
3886
|
-
|
3887
|
-
// components/form/core/FormContainer.tsx
|
3888
|
-
function _extends6() {
|
3889
|
-
_extends6 = Object.assign || function(target) {
|
3890
|
-
for (var i = 1; i < arguments.length; i++) {
|
3891
|
-
var source = arguments[i];
|
3892
|
-
for (var key in source) {
|
3893
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
3894
|
-
target[key] = source[key];
|
3895
|
-
}
|
3896
|
-
}
|
3897
|
-
}
|
3898
|
-
return target;
|
3899
|
-
};
|
3900
|
-
return _extends6.apply(this, arguments);
|
3901
|
-
}
|
3902
|
-
__name(_extends6, "_extends");
|
3903
|
-
var debugForm = debugVulcan2("form");
|
3904
|
-
var useFragments = /* @__PURE__ */ __name((props, formType) => {
|
3905
|
-
let queryFragment;
|
3906
|
-
let queryFragmentName;
|
3907
|
-
let mutationFragment;
|
3908
|
-
let mutationFragmentName;
|
3909
|
-
if (props.queryFragment) {
|
3910
|
-
if (typeof props.queryFragment === "string") {
|
3911
|
-
queryFragment = lib_default`
|
3912
|
-
${props.queryFragment}
|
3913
|
-
`;
|
3914
|
-
if (!props.queryFragmentName)
|
3915
|
-
throw new Error("When using a string queryFragment, queryFragmentName is mandatory");
|
3916
|
-
queryFragmentName = props.queryFragmentName;
|
3917
|
-
} else {
|
3918
|
-
queryFragment = props.queryFragment;
|
3919
|
-
queryFragmentName = props.queryFragmentName || getFragmentName2(props.queryFragment);
|
3920
|
-
}
|
3921
|
-
}
|
3922
|
-
if (props.mutationFragment) {
|
3923
|
-
if (typeof props.mutationFragment === "string") {
|
3924
|
-
mutationFragment = lib_default`
|
3925
|
-
${props.mutationFragment}
|
3926
|
-
`;
|
3927
|
-
if (!props.mutationFragmentName)
|
3928
|
-
throw new Error("When using a string mutationFragment, mutationFragmentName is mandatory");
|
3929
|
-
queryFragmentName = props.mutationFragmentName;
|
3930
|
-
} else {
|
3931
|
-
mutationFragment = props.mutationFragment;
|
3932
|
-
mutationFragmentName = props.mutationFragmentName || getFragmentName2(props.mutationFragment);
|
3933
|
-
}
|
3934
|
-
}
|
3935
|
-
let autoFormFragments;
|
3936
|
-
if (!props.queryFragment || !props.mutationFragment) {
|
3937
|
-
const { model, fields, addFields } = props;
|
3938
|
-
autoFormFragments = formFragments_default({
|
3939
|
-
formType,
|
3940
|
-
model,
|
3941
|
-
fields,
|
3942
|
-
addFields
|
3943
|
-
});
|
3944
|
-
}
|
3945
|
-
if (!props.queryFragment) {
|
3946
|
-
queryFragment = autoFormFragments.queryFragment;
|
3947
|
-
queryFragmentName = autoFormFragments.queryFragmentName;
|
3948
|
-
}
|
3949
|
-
if (!props.mutationFragment) {
|
3950
|
-
mutationFragment = autoFormFragments.mutationFragment;
|
3951
|
-
mutationFragmentName = autoFormFragments.mutationFragmentName;
|
3952
|
-
}
|
3953
|
-
return {
|
3954
|
-
mutationFragment,
|
3955
|
-
mutationFragmentName,
|
3956
|
-
queryFragment,
|
3957
|
-
queryFragmentName
|
3958
|
-
};
|
3959
|
-
}, "useFragments");
|
3960
|
-
var FormContainer = /* @__PURE__ */ __name((props) => {
|
3961
|
-
const { model, documentId, slug, fields, addFields, currentUser: currentUserFromProps, loadingCurrentUser: loadingCurrentUserFromProps } = props;
|
3962
|
-
const { schema } = model;
|
3963
|
-
const isEdit = documentId || slug;
|
3964
|
-
const selector = {
|
3965
|
-
documentId,
|
3966
|
-
slug
|
3967
|
-
};
|
3968
|
-
const formType = isEdit ? "edit" : "new";
|
3969
|
-
const VulcanComponents = useVulcanComponents();
|
3970
|
-
const prefix = `${model.name}${capitalize3(formType)}`;
|
3971
|
-
const childProps = {
|
3972
|
-
formType,
|
3973
|
-
schema
|
3974
|
-
};
|
3975
|
-
const { mutationFragment, mutationFragmentName, queryFragment, queryFragmentName } = useFragments(props, formType);
|
3976
|
-
const mutationOptions = {
|
3977
|
-
model,
|
3978
|
-
fragment: mutationFragment,
|
3979
|
-
fragmentName: mutationFragmentName
|
3980
|
-
};
|
3981
|
-
const queryOptions = {
|
3982
|
-
model,
|
3983
|
-
fragment: queryFragment,
|
3984
|
-
fragmentName: queryFragmentName,
|
3985
|
-
input: {
|
3986
|
-
id: documentId,
|
3987
|
-
enableCache: false
|
3988
|
-
},
|
3989
|
-
queryOptions: {
|
3990
|
-
fetchPolicy: "network-only",
|
3991
|
-
pollInterval: 0,
|
3992
|
-
skip: formType === "new"
|
3993
|
-
}
|
3994
|
-
};
|
3995
|
-
const { data, document: document1, loading, refetch } = useSingle(queryOptions);
|
3996
|
-
if (formType !== "new") {
|
3997
|
-
debugForm("useSingle result", "data", data, "document", document1, "loading", loading);
|
3998
|
-
}
|
3999
|
-
const [createDocument] = useCreate(mutationOptions);
|
4000
|
-
const [updateDocument] = useUpdate(mutationOptions);
|
4001
|
-
const [deleteDocument] = useDelete(mutationOptions);
|
4002
|
-
const { currentUser: currentUserFromContext, loading: loadingCurrentUserFromContext } = useVulcanCurrentUser();
|
4003
|
-
const shouldGetCurrentUserFromProps = typeof currentUserFromProps !== "undefined";
|
4004
|
-
const currentUser = shouldGetCurrentUserFromProps ? currentUserFromProps : currentUserFromContext;
|
4005
|
-
const loadingCurrentUser = shouldGetCurrentUserFromProps ? loadingCurrentUserFromProps : loadingCurrentUserFromContext;
|
4006
|
-
const createAndReturnDocument = /* @__PURE__ */ __name(async (variables) => {
|
4007
|
-
const result = await createDocument(variables);
|
4008
|
-
const { errors, document } = result;
|
4009
|
-
return {
|
4010
|
-
document,
|
4011
|
-
errors
|
4012
|
-
};
|
4013
|
-
}, "createAndReturnDocument");
|
4014
|
-
const updateAndReturnDocument = /* @__PURE__ */ __name(async (variables) => {
|
4015
|
-
const result = await updateDocument(variables);
|
4016
|
-
const { errors, document } = result;
|
4017
|
-
return {
|
4018
|
-
document,
|
4019
|
-
errors
|
4020
|
-
};
|
4021
|
-
}, "updateAndReturnDocument");
|
4022
|
-
const deleteDocumentAndRefetch = /* @__PURE__ */ __name(async (variables) => {
|
4023
|
-
await deleteDocument(variables);
|
4024
|
-
}, "deleteDocumentAndRefetch");
|
4025
|
-
if (isEdit && loading) {
|
4026
|
-
return /* @__PURE__ */ React11.createElement(VulcanComponents.Loading, null);
|
4027
|
-
}
|
4028
|
-
return /* @__PURE__ */ React11.createElement(VulcanComponents.Form, _extends6({
|
4029
|
-
document: document1,
|
4030
|
-
loading: loading || loadingCurrentUser,
|
4031
|
-
createDocument: createAndReturnDocument,
|
4032
|
-
updateDocument: updateAndReturnDocument,
|
4033
|
-
deleteDocument: deleteDocumentAndRefetch,
|
4034
|
-
refetch,
|
4035
|
-
currentUser
|
4036
|
-
}, childProps, props));
|
4037
|
-
}, "FormContainer");
|
4038
|
-
var SmartForm = FormContainer;
|
4039
|
-
|
4040
|
-
// components/VulcanComponents/defaultVulcanComponents/index.ts
|
4041
|
-
var defaultFormComponents = {
|
4042
|
-
Form,
|
4043
|
-
SmartForm: FormContainer
|
4044
|
-
};
|
4045
|
-
var defaultDatatableComponents = {};
|
4046
|
-
var defaultCellComponents = {};
|
4047
|
-
var defaultCoreComponents = {
|
4048
|
-
MutationButton,
|
4049
|
-
LoadingButton
|
4050
|
-
};
|
4254
|
+
init_esm_shims();
|
4255
|
+
import React6 from "react";
|
4256
|
+
var VulcanCurrentUserContext = React6.createContext({
|
4257
|
+
currentUser: null,
|
4258
|
+
loading: false
|
4259
|
+
});
|
4051
4260
|
|
4052
|
-
// components/
|
4053
|
-
|
4054
|
-
|
4261
|
+
// components/VulcanCurrentUser/Consumer.tsx
|
4262
|
+
var VulcanCurrentUserConsumer = VulcanCurrentUserContext.Consumer;
|
4263
|
+
var useVulcanCurrentUser = /* @__PURE__ */ __name(() => useContext3(VulcanCurrentUserContext), "useVulcanCurrentUser");
|
4264
|
+
|
4265
|
+
// components/VulcanCurrentUser/Provider.tsx
|
4266
|
+
init_esm_shims();
|
4267
|
+
import React7 from "react";
|
4268
|
+
function _extends3() {
|
4269
|
+
_extends3 = Object.assign || function(target) {
|
4055
4270
|
for (var i = 1; i < arguments.length; i++) {
|
4056
4271
|
var source = arguments[i];
|
4057
4272
|
for (var key in source) {
|
@@ -4062,459 +4277,412 @@ function _extends7() {
|
|
4062
4277
|
}
|
4063
4278
|
return target;
|
4064
4279
|
};
|
4065
|
-
return
|
4280
|
+
return _extends3.apply(this, arguments);
|
4066
4281
|
}
|
4067
|
-
__name(
|
4068
|
-
var
|
4069
|
-
|
4070
|
-
|
4071
|
-
|
4072
|
-
},
|
4073
|
-
|
4074
|
-
|
4075
|
-
|
4076
|
-
|
4077
|
-
|
4078
|
-
|
4079
|
-
|
4080
|
-
|
4081
|
-
|
4082
|
-
|
4083
|
-
Object.keys(convertedSchema).forEach((key) => {
|
4084
|
-
let minCount = convertedSchema[key].minCount;
|
4085
|
-
if (minCount) {
|
4086
|
-
initialDocument[key] = initialDocument[key] || [];
|
4087
|
-
while (initialDocument[key].length < minCount)
|
4088
|
-
initialDocument[key].push({});
|
4089
|
-
}
|
4090
|
-
});
|
4091
|
-
removeProperty(initialDocument, "__typename");
|
4092
|
-
return {
|
4093
|
-
disabled: nextProps.disabled,
|
4094
|
-
errors: [],
|
4095
|
-
deletedValues: [],
|
4096
|
-
currentValues: {},
|
4097
|
-
originalSchema: convertSchema(schema, {
|
4098
|
-
removeArrays: false
|
4099
|
-
}),
|
4100
|
-
schema: convertedSchema,
|
4101
|
-
flatSchema: convertSchema(schema, {
|
4102
|
-
flatten: true
|
4103
|
-
}),
|
4104
|
-
initialDocument,
|
4105
|
-
currentDocument: initialDocument
|
4106
|
-
};
|
4107
|
-
}, "getInitialStateFromProps");
|
4108
|
-
var getChildrenProps = /* @__PURE__ */ __name((props, state, options, callbacks) => {
|
4109
|
-
const { currentUser, repeatErrors, submitLabel, cancelLabel, revertLabel, cancelCallback, revertCallback, id, model, prefilledProps, itemProperties, contextName, showRemove, showDelete } = props;
|
4110
|
-
const { disabled, currentDocument } = state;
|
4111
|
-
const { formType } = options;
|
4112
|
-
const { deleteDocument } = callbacks;
|
4113
|
-
const commonProps = {
|
4114
|
-
document: currentDocument,
|
4115
|
-
formType,
|
4116
|
-
currentUser,
|
4117
|
-
disabled,
|
4118
|
-
prefilledProps,
|
4119
|
-
itemProperties,
|
4120
|
-
contextName
|
4121
|
-
};
|
4122
|
-
const docClassName = `document-${formType}`;
|
4123
|
-
const modelName = model.name.toLowerCase();
|
4124
|
-
const formProps = {
|
4125
|
-
className: `${docClassName} ${docClassName}-${modelName}`,
|
4126
|
-
id
|
4127
|
-
};
|
4128
|
-
const formGroupProps = /* @__PURE__ */ __name((group) => __spreadValues(__spreadProps(__spreadValues({
|
4129
|
-
key: group.name
|
4130
|
-
}, group), {
|
4131
|
-
group: omit(group, [
|
4132
|
-
"fields"
|
4133
|
-
])
|
4134
|
-
}), commonProps), "formGroupProps");
|
4135
|
-
const formSubmitProps = {
|
4136
|
-
model,
|
4137
|
-
currentUser,
|
4138
|
-
submitLabel,
|
4139
|
-
cancelLabel,
|
4140
|
-
revertLabel,
|
4141
|
-
cancelCallback,
|
4142
|
-
revertCallback,
|
4143
|
-
document: currentDocument,
|
4144
|
-
deleteDocument: formType === "edit" && showRemove && showDelete && deleteDocument || null
|
4145
|
-
};
|
4146
|
-
const formLayoutProps = {
|
4147
|
-
formProps,
|
4148
|
-
repeatErrors,
|
4149
|
-
submitProps: formSubmitProps,
|
4150
|
-
commonProps
|
4151
|
-
};
|
4152
|
-
return {
|
4153
|
-
commonProps,
|
4154
|
-
formSubmitProps,
|
4155
|
-
formGroupProps,
|
4156
|
-
formLayoutProps
|
4157
|
-
};
|
4158
|
-
}, "getChildrenProps");
|
4159
|
-
var FormWarnUnsaved = /* @__PURE__ */ __name(({ isChanged, warnUnsavedChanges, children }) => {
|
4160
|
-
useWarnOnUnsaved({
|
4161
|
-
isChanged,
|
4162
|
-
warnUnsavedChanges
|
4163
|
-
});
|
4164
|
-
return /* @__PURE__ */ React12.createElement(React12.Fragment, null, children);
|
4165
|
-
}, "FormWarnUnsaved");
|
4166
|
-
var getData = /* @__PURE__ */ __name((customArgs, props, state, { submitFormCallbacks, form }) => {
|
4167
|
-
const { currentDocument } = state;
|
4168
|
-
const { model, prefilledProps } = props;
|
4169
|
-
let data = prefilledProps || {};
|
4170
|
-
data = omitBy(data, (value, key) => key.endsWith(".$"));
|
4171
|
-
const args = __spreadValues({
|
4172
|
-
schema: model.schema,
|
4173
|
-
excludeRemovedFields: false,
|
4174
|
-
excludeHiddenFields: false,
|
4175
|
-
replaceIntlFields: true,
|
4176
|
-
addExtraFields: false
|
4177
|
-
}, customArgs);
|
4178
|
-
const fields = getFieldNames(props, currentDocument, args);
|
4179
|
-
data = __spreadValues(__spreadValues({}, data), pick2(currentDocument, ...fields));
|
4180
|
-
state.deletedValues.forEach((path) => {
|
4181
|
-
if (path.includes(".")) {
|
4182
|
-
compactParent(data, path);
|
4183
|
-
}
|
4184
|
-
});
|
4185
|
-
data = runCallbacks({
|
4186
|
-
callbacks: submitFormCallbacks,
|
4187
|
-
iterator: data,
|
4188
|
-
args: [
|
4189
|
-
{}
|
4190
|
-
]
|
4191
|
-
});
|
4192
|
-
return data;
|
4193
|
-
}, "getData");
|
4194
|
-
var Form = /* @__PURE__ */ __name((props) => {
|
4195
|
-
const { initCallback, createDocument, updateDocument, deleteDocument } = props;
|
4196
|
-
const initialState = getInitialStateFromProps(props);
|
4197
|
-
const { schema, originalSchema, flatSchema, initialDocument } = initialState;
|
4198
|
-
const isFirstRender = useRef2(true);
|
4199
|
-
useEffect2(() => {
|
4200
|
-
if (isFirstRender.current) {
|
4201
|
-
isFirstRender.current = false;
|
4202
|
-
return;
|
4203
|
-
}
|
4204
|
-
if (initCallback)
|
4205
|
-
initCallback(initialState.currentDocument);
|
4206
|
-
}, [
|
4207
|
-
initCallback
|
4208
|
-
]);
|
4209
|
-
const defaultProps = {
|
4210
|
-
layout: "horizontal",
|
4211
|
-
prefilledProps: {},
|
4212
|
-
repeatErrors: false,
|
4213
|
-
showRemove: true,
|
4214
|
-
showDelete: true
|
4215
|
-
};
|
4216
|
-
const allProps = __spreadValues(__spreadValues({}, defaultProps), props);
|
4217
|
-
const defaultValues = {};
|
4218
|
-
const submitFormCallbacks = [];
|
4219
|
-
const successFormCallbacks = [];
|
4220
|
-
const failureFormCallbacks = [];
|
4221
|
-
const intl = useIntlContext2();
|
4222
|
-
const [errors, setErrors] = useState2([]);
|
4223
|
-
const throwError = /* @__PURE__ */ __name((error) => {
|
4224
|
-
let formErrors = getErrors(error);
|
4225
|
-
console.log(formErrors);
|
4226
|
-
setErrors((prevErrors) => [
|
4227
|
-
...prevErrors,
|
4228
|
-
...formErrors
|
4229
|
-
]);
|
4230
|
-
}, "throwError");
|
4231
|
-
const clearFieldErrors = /* @__PURE__ */ __name((path) => {
|
4232
|
-
setErrors((prevErrors) => prevErrors.filter((error) => error.path !== path));
|
4233
|
-
}, "clearFieldErrors");
|
4234
|
-
const [deletedValues, setDeletedValues] = useState2([]);
|
4235
|
-
const addToDeletedValues = /* @__PURE__ */ __name((name) => {
|
4236
|
-
setDeletedValues((prevDeletedValues) => [
|
4237
|
-
...prevDeletedValues,
|
4238
|
-
name
|
4239
|
-
]);
|
4240
|
-
}, "addToDeletedValues");
|
4241
|
-
const [callbacks, setCallbacks] = useState2({
|
4242
|
-
submitFormCallbacks: [],
|
4243
|
-
successFormCallbacks: [],
|
4244
|
-
failureFormCallbacks: []
|
4245
|
-
});
|
4246
|
-
const addToSubmitForm = /* @__PURE__ */ __name((callback) => {
|
4247
|
-
setCallbacks((cbs) => __spreadValues({}, cbs));
|
4248
|
-
}, "addToSubmitForm");
|
4249
|
-
const addToSuccessForm = /* @__PURE__ */ __name((callback) => {
|
4250
|
-
setCallbacks((cbs) => __spreadProps(__spreadValues({}, cbs), {
|
4251
|
-
successFormCallbacks: [
|
4252
|
-
...cbs.successFormCallbacks,
|
4253
|
-
callback
|
4254
|
-
]
|
4255
|
-
}));
|
4256
|
-
}, "addToSuccessForm");
|
4257
|
-
const addToFailureForm = /* @__PURE__ */ __name((callback) => {
|
4258
|
-
setCallbacks((cbs) => __spreadProps(__spreadValues({}, cbs), {
|
4259
|
-
failureFormCallbacks: [
|
4260
|
-
...cbs.failureFormCallbacks,
|
4261
|
-
callback
|
4262
|
-
]
|
4263
|
-
}));
|
4264
|
-
}, "addToFailureForm");
|
4265
|
-
const clearFormCallbacks = /* @__PURE__ */ __name(() => {
|
4266
|
-
setCallbacks({
|
4267
|
-
submitFormCallbacks: [],
|
4268
|
-
successFormCallbacks: [],
|
4269
|
-
failureFormCallbacks: []
|
4270
|
-
});
|
4271
|
-
}, "clearFormCallbacks");
|
4272
|
-
const [currentValues, setCurrentValues] = useState2({});
|
4273
|
-
const submitFormContext = /* @__PURE__ */ __name((formType) => (event) => {
|
4274
|
-
submitForm(formType)(event);
|
4275
|
-
}, "submitFormContext");
|
4276
|
-
const [currentDocument, setCurrentDocument] = useState2(initialDocument);
|
4277
|
-
const updateCurrentValues = /* @__PURE__ */ __name((newValues, options = {}) => {
|
4278
|
-
const { mode = "overwrite" } = options;
|
4279
|
-
const { changeCallback } = props;
|
4280
|
-
const newState = {
|
4281
|
-
currentValues: cloneDeep(currentValues),
|
4282
|
-
currentDocument: cloneDeep(currentDocument),
|
4283
|
-
deletedValues: cloneDeep(deletedValues)
|
4284
|
-
};
|
4285
|
-
Object.keys(newValues).forEach((key) => {
|
4286
|
-
const path = key;
|
4287
|
-
let value = newValues[key];
|
4288
|
-
if (isEmptyValue(value)) {
|
4289
|
-
unset(newState.currentValues, path);
|
4290
|
-
set2(newState.currentDocument, path, null);
|
4291
|
-
newState.deletedValues = [
|
4292
|
-
...newState.deletedValues,
|
4293
|
-
path
|
4294
|
-
];
|
4295
|
-
} else {
|
4296
|
-
set2(newState.currentValues, path, value);
|
4297
|
-
if (mode === "merge" && (Array.isArray(value) || isObject(value))) {
|
4298
|
-
const oldValue = get2(newState.currentDocument, path);
|
4299
|
-
set2(newState.currentDocument, path, merge2(oldValue, value));
|
4300
|
-
} else {
|
4301
|
-
set2(newState.currentDocument, path, value);
|
4282
|
+
__name(_extends3, "_extends");
|
4283
|
+
var VulcanCurrentUserProvider = /* @__PURE__ */ __name((_a) => {
|
4284
|
+
var _b = _a, { value } = _b, props = __objRest(_b, ["value"]);
|
4285
|
+
return /* @__PURE__ */ React7.createElement(VulcanCurrentUserContext.Provider, _extends3({
|
4286
|
+
value
|
4287
|
+
}, props));
|
4288
|
+
}, "VulcanCurrentUserProvider");
|
4289
|
+
|
4290
|
+
// components/form/core/FormContainer.tsx
|
4291
|
+
function _extends4() {
|
4292
|
+
_extends4 = Object.assign || function(target) {
|
4293
|
+
for (var i = 1; i < arguments.length; i++) {
|
4294
|
+
var source = arguments[i];
|
4295
|
+
for (var key in source) {
|
4296
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
4297
|
+
target[key] = source[key];
|
4302
4298
|
}
|
4303
|
-
newState.deletedValues = without(newState.deletedValues, path);
|
4304
4299
|
}
|
4305
|
-
});
|
4306
|
-
if (changeCallback)
|
4307
|
-
changeCallback(newState.currentDocument);
|
4308
|
-
setCurrentValues(newState.currentValues);
|
4309
|
-
setCurrentDocument(newState.currentDocument);
|
4310
|
-
setDeletedValues(newState.deletedValues);
|
4311
|
-
}, "updateCurrentValues");
|
4312
|
-
const refetchForm = /* @__PURE__ */ __name(() => {
|
4313
|
-
if (props.refetch) {
|
4314
|
-
props.refetch();
|
4315
|
-
}
|
4316
|
-
}, "refetchForm");
|
4317
|
-
const [disabled, setDisabled] = useState2(false);
|
4318
|
-
const [success, setSuccess] = useState2(false);
|
4319
|
-
const clearForm = /* @__PURE__ */ __name((options = {}) => {
|
4320
|
-
const { document: optionsDocument } = options;
|
4321
|
-
const document = optionsDocument ? merge2({}, props.prefilledProps, optionsDocument) : null;
|
4322
|
-
setErrors([]);
|
4323
|
-
setCurrentValues({});
|
4324
|
-
setDeletedValues([]);
|
4325
|
-
setCurrentDocument(document || initialDocument);
|
4326
|
-
setDisabled(false);
|
4327
|
-
}, "clearForm");
|
4328
|
-
const newMutationSuccessCallback = /* @__PURE__ */ __name(function(result) {
|
4329
|
-
mutationSuccessCallback(result, "new");
|
4330
|
-
}, "newMutationSuccessCallback");
|
4331
|
-
const editMutationSuccessCallback = /* @__PURE__ */ __name(function(result) {
|
4332
|
-
mutationSuccessCallback(result, "edit");
|
4333
|
-
}, "editMutationSuccessCallback");
|
4334
|
-
const formRef = useRef2(null);
|
4335
|
-
const mutationSuccessCallback = /* @__PURE__ */ __name(function(result, mutationType) {
|
4336
|
-
setDisabled(false);
|
4337
|
-
setSuccess(true);
|
4338
|
-
if (mutationType === "new")
|
4339
|
-
refetchForm();
|
4340
|
-
let { document } = result;
|
4341
|
-
if (formRef.current) {
|
4342
|
-
clearForm({
|
4343
|
-
document: mutationType === "edit" ? document : void 0
|
4344
|
-
});
|
4345
4300
|
}
|
4346
|
-
|
4347
|
-
|
4348
|
-
|
4349
|
-
|
4350
|
-
|
4351
|
-
|
4352
|
-
|
4353
|
-
|
4354
|
-
|
4355
|
-
|
4356
|
-
|
4357
|
-
|
4358
|
-
|
4359
|
-
|
4360
|
-
|
4361
|
-
|
4362
|
-
|
4363
|
-
|
4364
|
-
|
4365
|
-
|
4366
|
-
|
4367
|
-
|
4368
|
-
{
|
4369
|
-
error,
|
4370
|
-
form: formRef.current
|
4371
|
-
}
|
4372
|
-
]
|
4373
|
-
});
|
4374
|
-
if (!isEmpty(error)) {
|
4375
|
-
throwError(error);
|
4301
|
+
return target;
|
4302
|
+
};
|
4303
|
+
return _extends4.apply(this, arguments);
|
4304
|
+
}
|
4305
|
+
__name(_extends4, "_extends");
|
4306
|
+
var debugForm = debugVulcan("form");
|
4307
|
+
var useFragments = /* @__PURE__ */ __name((props, formType) => {
|
4308
|
+
let queryFragment;
|
4309
|
+
let queryFragmentName;
|
4310
|
+
let mutationFragment;
|
4311
|
+
let mutationFragmentName;
|
4312
|
+
if (props.queryFragment) {
|
4313
|
+
if (typeof props.queryFragment === "string") {
|
4314
|
+
queryFragment = lib_default`
|
4315
|
+
${props.queryFragment}
|
4316
|
+
`;
|
4317
|
+
if (!props.queryFragmentName)
|
4318
|
+
throw new Error("When using a string queryFragment, queryFragmentName is mandatory");
|
4319
|
+
queryFragmentName = props.queryFragmentName;
|
4320
|
+
} else {
|
4321
|
+
queryFragment = props.queryFragment;
|
4322
|
+
queryFragmentName = props.queryFragmentName || getFragmentName2(props.queryFragment);
|
4376
4323
|
}
|
4377
|
-
|
4378
|
-
|
4379
|
-
|
4380
|
-
|
4381
|
-
|
4382
|
-
|
4383
|
-
|
4384
|
-
|
4385
|
-
|
4386
|
-
|
4387
|
-
|
4388
|
-
|
4324
|
+
}
|
4325
|
+
if (props.mutationFragment) {
|
4326
|
+
if (typeof props.mutationFragment === "string") {
|
4327
|
+
mutationFragment = lib_default`
|
4328
|
+
${props.mutationFragment}
|
4329
|
+
`;
|
4330
|
+
if (!props.mutationFragmentName)
|
4331
|
+
throw new Error("When using a string mutationFragment, mutationFragmentName is mandatory");
|
4332
|
+
queryFragmentName = props.mutationFragmentName;
|
4333
|
+
} else {
|
4334
|
+
mutationFragment = props.mutationFragment;
|
4335
|
+
mutationFragmentName = props.mutationFragmentName || getFragmentName2(props.mutationFragment);
|
4389
4336
|
}
|
4390
|
-
|
4391
|
-
|
4392
|
-
|
4393
|
-
|
4394
|
-
|
4395
|
-
|
4396
|
-
|
4397
|
-
|
4398
|
-
|
4399
|
-
}, {
|
4400
|
-
form: formRef.current,
|
4401
|
-
submitFormCallbacks
|
4337
|
+
}
|
4338
|
+
let autoFormFragments;
|
4339
|
+
if (!props.queryFragment || !props.mutationFragment) {
|
4340
|
+
const { model, fields, addFields } = props;
|
4341
|
+
autoFormFragments = formFragments_default({
|
4342
|
+
formType,
|
4343
|
+
model,
|
4344
|
+
fields,
|
4345
|
+
addFields
|
4402
4346
|
});
|
4403
|
-
|
4404
|
-
|
4347
|
+
}
|
4348
|
+
if (!props.queryFragment) {
|
4349
|
+
queryFragment = autoFormFragments.queryFragment;
|
4350
|
+
queryFragmentName = autoFormFragments.queryFragmentName;
|
4351
|
+
}
|
4352
|
+
if (!props.mutationFragment) {
|
4353
|
+
mutationFragment = autoFormFragments.mutationFragment;
|
4354
|
+
mutationFragmentName = autoFormFragments.mutationFragmentName;
|
4355
|
+
}
|
4356
|
+
return {
|
4357
|
+
mutationFragment,
|
4358
|
+
mutationFragmentName,
|
4359
|
+
queryFragment,
|
4360
|
+
queryFragmentName
|
4361
|
+
};
|
4362
|
+
}, "useFragments");
|
4363
|
+
var FormContainer = /* @__PURE__ */ __name((props) => {
|
4364
|
+
const { model, documentId, slug, fields, addFields, currentUser: currentUserFromProps, loadingCurrentUser: loadingCurrentUserFromProps } = props;
|
4365
|
+
const { schema } = model;
|
4366
|
+
const isEdit = documentId || slug;
|
4367
|
+
const selector = {
|
4368
|
+
documentId,
|
4369
|
+
slug
|
4370
|
+
};
|
4371
|
+
const formType = isEdit ? "edit" : "new";
|
4372
|
+
const VulcanComponents = useVulcanComponents();
|
4373
|
+
const prefix = `${model.name}${capitalize3(formType)}`;
|
4374
|
+
const childProps = {
|
4375
|
+
formType,
|
4376
|
+
schema
|
4377
|
+
};
|
4378
|
+
const { mutationFragment, mutationFragmentName, queryFragment, queryFragmentName } = useFragments(props, formType);
|
4379
|
+
const mutationOptions = {
|
4380
|
+
model,
|
4381
|
+
fragment: mutationFragment,
|
4382
|
+
fragmentName: mutationFragmentName
|
4383
|
+
};
|
4384
|
+
const queryOptions = {
|
4385
|
+
model,
|
4386
|
+
fragment: queryFragment,
|
4387
|
+
fragmentName: queryFragmentName,
|
4388
|
+
input: {
|
4389
|
+
id: documentId,
|
4390
|
+
enableCache: false
|
4391
|
+
},
|
4392
|
+
queryOptions: {
|
4393
|
+
fetchPolicy: "network-only",
|
4394
|
+
pollInterval: 0,
|
4395
|
+
skip: formType === "new"
|
4405
4396
|
}
|
4406
|
-
|
4407
|
-
|
4408
|
-
|
4409
|
-
|
4410
|
-
|
4411
|
-
|
4412
|
-
|
4413
|
-
|
4414
|
-
|
4415
|
-
|
4416
|
-
|
4417
|
-
|
4397
|
+
};
|
4398
|
+
const { data, document: document1, loading, refetch } = useSingle(queryOptions);
|
4399
|
+
if (formType !== "new") {
|
4400
|
+
debugForm("useSingle result", "data", data, "document", document1, "loading", loading);
|
4401
|
+
}
|
4402
|
+
const [createDocument] = useCreate(mutationOptions);
|
4403
|
+
const [updateDocument] = useUpdate(mutationOptions);
|
4404
|
+
const [deleteDocument] = useDelete(mutationOptions);
|
4405
|
+
const { currentUser: currentUserFromContext, loading: loadingCurrentUserFromContext } = useVulcanCurrentUser();
|
4406
|
+
const shouldGetCurrentUserFromProps = typeof currentUserFromProps !== "undefined";
|
4407
|
+
const currentUser = shouldGetCurrentUserFromProps ? currentUserFromProps : currentUserFromContext;
|
4408
|
+
const loadingCurrentUser = shouldGetCurrentUserFromProps ? loadingCurrentUserFromProps : loadingCurrentUserFromContext;
|
4409
|
+
const createAndReturnDocument = /* @__PURE__ */ __name(async (variables) => {
|
4410
|
+
const result = await createDocument(variables);
|
4411
|
+
const { errors, document } = result;
|
4412
|
+
return {
|
4413
|
+
document,
|
4414
|
+
errors
|
4415
|
+
};
|
4416
|
+
}, "createAndReturnDocument");
|
4417
|
+
const updateAndReturnDocument = /* @__PURE__ */ __name(async (variables) => {
|
4418
|
+
const result = await updateDocument(variables);
|
4419
|
+
const { errors, document } = result;
|
4420
|
+
return {
|
4421
|
+
document,
|
4422
|
+
errors
|
4423
|
+
};
|
4424
|
+
}, "updateAndReturnDocument");
|
4425
|
+
const deleteDocumentAndRefetch = /* @__PURE__ */ __name(async (variables) => {
|
4426
|
+
await deleteDocument(variables);
|
4427
|
+
}, "deleteDocumentAndRefetch");
|
4428
|
+
if (isEdit && loading) {
|
4429
|
+
return /* @__PURE__ */ React8.createElement(VulcanComponents.Loading, null);
|
4430
|
+
}
|
4431
|
+
return /* @__PURE__ */ React8.createElement(VulcanComponents.Form, _extends4({
|
4432
|
+
document: document1,
|
4433
|
+
loading: loading || loadingCurrentUser,
|
4434
|
+
createDocument: createAndReturnDocument,
|
4435
|
+
updateDocument: updateAndReturnDocument,
|
4436
|
+
deleteDocument: deleteDocumentAndRefetch,
|
4437
|
+
refetch,
|
4438
|
+
currentUser
|
4439
|
+
}, childProps, props));
|
4440
|
+
}, "FormContainer");
|
4441
|
+
var SmartForm = FormContainer;
|
4442
|
+
|
4443
|
+
// components/form/utils/index.ts
|
4444
|
+
init_esm_shims();
|
4445
|
+
|
4446
|
+
// components/form/utils/ui_utils.ts
|
4447
|
+
var ui_utils_exports = {};
|
4448
|
+
__export(ui_utils_exports, {
|
4449
|
+
getHtmlInputProps: () => getHtmlInputProps,
|
4450
|
+
whitelistInputProps: () => whitelistInputProps
|
4451
|
+
});
|
4452
|
+
init_esm_shims();
|
4453
|
+
import pick3 from "lodash/pick.js";
|
4454
|
+
var getHtmlInputProps = /* @__PURE__ */ __name((props) => {
|
4455
|
+
const { name, path, options, label, onChange, onBlur, value, disabled } = props;
|
4456
|
+
const inputProperties = __spreadProps(__spreadValues({}, props.inputProperties), {
|
4457
|
+
name,
|
4458
|
+
path,
|
4459
|
+
options,
|
4460
|
+
label,
|
4461
|
+
onChange,
|
4462
|
+
onBlur,
|
4463
|
+
value,
|
4464
|
+
disabled
|
4465
|
+
});
|
4466
|
+
return __spreadProps(__spreadValues({}, props), {
|
4467
|
+
inputProperties
|
4468
|
+
});
|
4469
|
+
}, "getHtmlInputProps");
|
4470
|
+
var whitelistInputProps = /* @__PURE__ */ __name((props) => {
|
4471
|
+
const whitelist = [
|
4472
|
+
"name",
|
4473
|
+
"path",
|
4474
|
+
"options",
|
4475
|
+
"label",
|
4476
|
+
"onChange",
|
4477
|
+
"onBlur",
|
4478
|
+
"value",
|
4479
|
+
"disabled",
|
4480
|
+
"placeholder"
|
4481
|
+
];
|
4482
|
+
const value = props.value;
|
4483
|
+
let safeValue = value;
|
4484
|
+
if (value === null)
|
4485
|
+
safeValue = void 0;
|
4486
|
+
return __spreadProps(__spreadValues({}, pick3(props, whitelist)), {
|
4487
|
+
value: safeValue
|
4488
|
+
});
|
4489
|
+
}, "whitelistInputProps");
|
4490
|
+
|
4491
|
+
// components/VulcanComponents/index.ts
|
4492
|
+
init_esm_shims();
|
4493
|
+
|
4494
|
+
// components/VulcanComponents/Provider.tsx
|
4495
|
+
init_esm_shims();
|
4496
|
+
import React9 from "react";
|
4497
|
+
import { debugVulcan as debugVulcan2 } from "@vulcanjs/utils";
|
4498
|
+
function _extends5() {
|
4499
|
+
_extends5 = Object.assign || function(target) {
|
4500
|
+
for (var i = 1; i < arguments.length; i++) {
|
4501
|
+
var source = arguments[i];
|
4502
|
+
for (var key in source) {
|
4503
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
4504
|
+
target[key] = source[key];
|
4418
4505
|
}
|
4419
|
-
} catch (error) {
|
4420
|
-
mutationErrorCallback(document1, error);
|
4421
4506
|
}
|
4507
|
+
}
|
4508
|
+
return target;
|
4509
|
+
};
|
4510
|
+
return _extends5.apply(this, arguments);
|
4511
|
+
}
|
4512
|
+
__name(_extends5, "_extends");
|
4513
|
+
var debugComponents = debugVulcan2("components");
|
4514
|
+
var VulcanComponentsProvider = /* @__PURE__ */ __name((_a) => {
|
4515
|
+
var _b = _a, { value } = _b, props = __objRest(_b, ["value"]);
|
4516
|
+
const currentComponents = useVulcanComponents();
|
4517
|
+
debugComponents("Current components __not_initialized?", currentComponents.__not_initialized);
|
4518
|
+
const mergedComponents = __spreadValues(__spreadValues({}, (currentComponents == null ? void 0 : currentComponents.__not_initialized) ? {} : currentComponents || {}), value || {});
|
4519
|
+
debugComponents("Merged components", mergedComponents);
|
4520
|
+
Object.keys(mergedComponents).forEach((componentName) => {
|
4521
|
+
if (mergedComponents[componentName]) {
|
4522
|
+
mergedComponents[componentName].displayName = "Vulcan." + componentName;
|
4422
4523
|
} else {
|
4423
|
-
|
4424
|
-
|
4425
|
-
|
4426
|
-
|
4427
|
-
|
4428
|
-
|
4429
|
-
|
4430
|
-
|
4431
|
-
|
4432
|
-
|
4433
|
-
|
4434
|
-
|
4435
|
-
|
4524
|
+
console.warn(`Encountered an undefined component: ${componentName}.
|
4525
|
+
The component may not be registered, or import failed.
|
4526
|
+
For instance due to an infinite import loop when importing
|
4527
|
+
"useVulcanComponents" from index instead of Consumer.`);
|
4528
|
+
}
|
4529
|
+
});
|
4530
|
+
return /* @__PURE__ */ React9.createElement(VulcanComponentsContext.Provider, _extends5({
|
4531
|
+
value: mergedComponents
|
4532
|
+
}, props));
|
4533
|
+
}, "VulcanComponentsProvider");
|
4534
|
+
|
4535
|
+
// components/VulcanComponents/typings.ts
|
4536
|
+
init_esm_shims();
|
4537
|
+
import React10 from "react";
|
4538
|
+
|
4539
|
+
// components/VulcanComponents/defaultVulcanComponents/index.ts
|
4540
|
+
init_esm_shims();
|
4541
|
+
|
4542
|
+
// components/core/LoadingButton.tsx
|
4543
|
+
init_esm_shims();
|
4544
|
+
import React11 from "react";
|
4545
|
+
function _extends6() {
|
4546
|
+
_extends6 = Object.assign || function(target) {
|
4547
|
+
for (var i = 1; i < arguments.length; i++) {
|
4548
|
+
var source = arguments[i];
|
4549
|
+
for (var key in source) {
|
4550
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
4551
|
+
target[key] = source[key];
|
4436
4552
|
}
|
4437
|
-
} catch (error) {
|
4438
|
-
mutationErrorCallback(document1, error);
|
4439
4553
|
}
|
4440
4554
|
}
|
4441
|
-
|
4442
|
-
|
4443
|
-
|
4444
|
-
|
4445
|
-
|
4446
|
-
|
4447
|
-
|
4448
|
-
|
4449
|
-
|
4450
|
-
|
4451
|
-
|
4452
|
-
|
4453
|
-
|
4454
|
-
|
4555
|
+
return target;
|
4556
|
+
};
|
4557
|
+
return _extends6.apply(this, arguments);
|
4558
|
+
}
|
4559
|
+
__name(_extends6, "_extends");
|
4560
|
+
var LoadingButton = /* @__PURE__ */ __name((_a) => {
|
4561
|
+
var _b = _a, { loading, label, onClick, children, className = "" } = _b, rest = __objRest(_b, ["loading", "label", "onClick", "children", "className"]);
|
4562
|
+
const Components2 = useVulcanComponents();
|
4563
|
+
const wrapperStyle = {
|
4564
|
+
position: "relative"
|
4565
|
+
};
|
4566
|
+
const labelStyle = loading ? {
|
4567
|
+
opacity: 0.5
|
4568
|
+
} : {};
|
4569
|
+
const loadingStyle = loading ? {
|
4570
|
+
position: "absolute",
|
4571
|
+
top: 0,
|
4572
|
+
bottom: 0,
|
4573
|
+
left: 0,
|
4574
|
+
right: 0,
|
4575
|
+
display: "flex",
|
4576
|
+
justifyContent: "center",
|
4577
|
+
alignItems: "center"
|
4578
|
+
} : {
|
4579
|
+
display: "none"
|
4580
|
+
};
|
4581
|
+
return /* @__PURE__ */ React11.createElement(Components2.Button, _extends6({
|
4582
|
+
className: `loading-button ${loading ? "loading-button-loading" : "loading-button-notloading"} ${className}`,
|
4583
|
+
onClick
|
4584
|
+
}, rest), /* @__PURE__ */ React11.createElement("span", {
|
4585
|
+
style: wrapperStyle
|
4586
|
+
}, /* @__PURE__ */ React11.createElement("span", {
|
4587
|
+
style: labelStyle
|
4588
|
+
}, label || children), /* @__PURE__ */ React11.createElement("span", {
|
4589
|
+
style: loadingStyle
|
4590
|
+
}, /* @__PURE__ */ React11.createElement(Components2.Loading, null))));
|
4591
|
+
}, "LoadingButton");
|
4592
|
+
|
4593
|
+
// components/core/MutationButton.tsx
|
4594
|
+
init_esm_shims();
|
4595
|
+
import React12, { useState as useState2 } from "react";
|
4596
|
+
import { useMutation } from "@apollo/client";
|
4597
|
+
function _extends7() {
|
4598
|
+
_extends7 = Object.assign || function(target) {
|
4599
|
+
for (var i = 1; i < arguments.length; i++) {
|
4600
|
+
var source = arguments[i];
|
4601
|
+
for (var key in source) {
|
4602
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
4603
|
+
target[key] = source[key];
|
4455
4604
|
}
|
4456
|
-
}
|
4457
|
-
if (props.removeSuccessCallback)
|
4458
|
-
props.removeSuccessCallback({
|
4459
|
-
documentId,
|
4460
|
-
documentTitle
|
4461
|
-
});
|
4462
|
-
refetchForm();
|
4463
|
-
}).catch((error) => {
|
4464
|
-
console.log(error);
|
4465
|
-
});
|
4605
|
+
}
|
4466
4606
|
}
|
4467
|
-
|
4468
|
-
|
4469
|
-
|
4470
|
-
|
4471
|
-
|
4472
|
-
|
4473
|
-
|
4474
|
-
|
4475
|
-
|
4476
|
-
|
4477
|
-
|
4478
|
-
|
4479
|
-
|
4480
|
-
|
4481
|
-
|
4482
|
-
|
4483
|
-
|
4484
|
-
|
4485
|
-
|
4486
|
-
|
4487
|
-
|
4488
|
-
|
4489
|
-
|
4490
|
-
|
4491
|
-
|
4492
|
-
|
4493
|
-
|
4494
|
-
|
4495
|
-
|
4496
|
-
|
4497
|
-
|
4498
|
-
|
4499
|
-
|
4500
|
-
|
4501
|
-
|
4502
|
-
|
4503
|
-
|
4607
|
+
return target;
|
4608
|
+
};
|
4609
|
+
return _extends7.apply(this, arguments);
|
4610
|
+
}
|
4611
|
+
__name(_extends7, "_extends");
|
4612
|
+
var MutationButton = /* @__PURE__ */ __name((props) => {
|
4613
|
+
const Components2 = useVulcanComponents();
|
4614
|
+
const [loading, setLoading] = useState2(false);
|
4615
|
+
const [error1, setError] = useState2();
|
4616
|
+
const {
|
4617
|
+
mutation,
|
4618
|
+
loadingButtonProps = {},
|
4619
|
+
label
|
4620
|
+
} = props;
|
4621
|
+
let { mutationArguments } = props;
|
4622
|
+
const mutationAsNode = typeof mutation === "string" ? lib_default`
|
4623
|
+
${mutation}
|
4624
|
+
` : mutation;
|
4625
|
+
const [mutationFunc] = useMutation(mutationAsNode);
|
4626
|
+
const handleClick = /* @__PURE__ */ __name(async (e) => {
|
4627
|
+
e.preventDefault();
|
4628
|
+
setLoading(true);
|
4629
|
+
setError(void 0);
|
4630
|
+
const {
|
4631
|
+
submitCallback,
|
4632
|
+
successCallback,
|
4633
|
+
errorCallback
|
4634
|
+
} = props;
|
4635
|
+
try {
|
4636
|
+
if (submitCallback) {
|
4637
|
+
const callbackReturn = await submitCallback(mutationArguments);
|
4638
|
+
if (callbackReturn && callbackReturn.mutationArguments) {
|
4639
|
+
mutationArguments = callbackReturn.mutationArguments;
|
4640
|
+
}
|
4641
|
+
}
|
4642
|
+
const result = await mutationFunc({
|
4643
|
+
variables: mutationArguments
|
4644
|
+
});
|
4645
|
+
if (successCallback) {
|
4646
|
+
await successCallback(result);
|
4647
|
+
}
|
4648
|
+
} catch (error) {
|
4649
|
+
setError(error);
|
4650
|
+
if (errorCallback) {
|
4651
|
+
await errorCallback(error);
|
4652
|
+
}
|
4653
|
+
} finally {
|
4654
|
+
setLoading(false);
|
4504
4655
|
}
|
4505
|
-
},
|
4506
|
-
|
4507
|
-
|
4508
|
-
|
4509
|
-
|
4510
|
-
},
|
4511
|
-
|
4512
|
-
|
4513
|
-
|
4656
|
+
}, "handleClick");
|
4657
|
+
const loadingButton = /* @__PURE__ */ React12.createElement(Components2.LoadingButton, _extends7({
|
4658
|
+
loading,
|
4659
|
+
onClick: handleClick,
|
4660
|
+
label
|
4661
|
+
}, loadingButtonProps));
|
4662
|
+
if (error1) {
|
4663
|
+
return /* @__PURE__ */ React12.createElement(Components2.TooltipTrigger, {
|
4664
|
+
trigger: loadingButton,
|
4665
|
+
defaultShow: true
|
4666
|
+
}, error1.message.replace("GraphQL error: ", ""));
|
4667
|
+
}
|
4668
|
+
return loadingButton;
|
4669
|
+
}, "MutationButton");
|
4514
4670
|
|
4515
|
-
// components/form/core/
|
4671
|
+
// components/form/core/index.ts
|
4516
4672
|
init_esm_shims();
|
4517
4673
|
|
4674
|
+
// components/VulcanComponents/defaultVulcanComponents/index.ts
|
4675
|
+
var defaultFormComponents = {
|
4676
|
+
Form,
|
4677
|
+
SmartForm: FormContainer
|
4678
|
+
};
|
4679
|
+
var defaultDatatableComponents = {};
|
4680
|
+
var defaultCellComponents = {};
|
4681
|
+
var defaultCoreComponents = {
|
4682
|
+
MutationButton,
|
4683
|
+
LoadingButton
|
4684
|
+
};
|
4685
|
+
|
4518
4686
|
// componentsHelpers.tsx
|
4519
4687
|
init_esm_shims();
|
4520
4688
|
import React13 from "react";
|
@@ -4611,12 +4779,17 @@ export {
|
|
4611
4779
|
defaultDatatableComponents,
|
4612
4780
|
defaultFormComponents,
|
4613
4781
|
delayedComponent,
|
4782
|
+
formFragments_exports as formFragmentsUtils,
|
4614
4783
|
getRawComponent,
|
4615
4784
|
instantiateComponent,
|
4616
4785
|
mergeWithComponents,
|
4786
|
+
path_utils_exports as pathUtils,
|
4787
|
+
schema_utils_exports as schemaUtils,
|
4788
|
+
ui_utils_exports as uiUtils,
|
4617
4789
|
useFormContext,
|
4618
4790
|
useVulcanComponents,
|
4619
4791
|
useVulcanCurrentUser,
|
4792
|
+
utils_exports as utils,
|
4620
4793
|
withVulcanComponents
|
4621
4794
|
};
|
4622
4795
|
//# sourceMappingURL=index.js.map
|