@vulcanjs/react-ui 0.6.7 → 0.6.8-alpha.4
Sign up to get free protection for your applications and to get access to all the features.
- 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 +1 -1
- package/dist/components/VulcanComponents/index.d.ts.map +1 -1
- 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/index.d.ts +4 -0
- package/dist/components/core/index.d.ts.map +1 -0
- package/dist/components/core/typings.d.ts.map +0 -0
- package/dist/components/form/FieldErrors.d.ts +6 -0
- package/dist/components/form/Form/Form.d.ts +4 -0
- package/dist/components/form/Form/fields.d.ts +22 -0
- package/dist/components/form/Form/index.d.ts +3 -0
- package/dist/components/form/Form/typings.d.ts +76 -0
- package/dist/components/form/Form/utils.d.ts +2 -0
- package/dist/components/form/FormComponent.d.ts +31 -0
- package/dist/components/form/FormComponentInner.d.ts +32 -0
- package/dist/components/form/FormComponentLoader.d.ts +15 -0
- package/dist/components/form/FormContainer.d.ts +18 -0
- package/dist/components/form/FormContext.d.ts +25 -0
- package/dist/components/form/FormElement.d.ts +4 -0
- package/dist/components/form/FormError.d.ts +11 -0
- package/dist/components/form/FormErrors.d.ts +3 -0
- package/dist/components/form/FormGroup.d.ts +30 -0
- package/dist/components/form/FormIntl.d.ts +15 -0
- package/dist/components/form/FormLayout.d.ts +10 -0
- package/dist/components/form/FormNestedArray.d.ts +26 -0
- package/dist/components/form/FormNestedArrayLayout.d.ts +18 -0
- package/dist/components/form/FormNestedDivider.d.ts +13 -0
- package/dist/components/form/FormNestedItem.d.ts +52 -0
- package/dist/components/form/FormNestedObject.d.ts +35 -0
- package/dist/components/form/FormOptionLabel.d.ts +5 -0
- package/dist/components/form/FormSubmit.d.ts +38 -0
- package/dist/components/form/core/Button.d.ts +4 -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/FormComponent.d.ts +27 -2
- package/dist/components/form/core/FormComponentInner.d.ts +30 -2
- package/dist/components/form/core/FormContainer.d.ts.map +0 -0
- package/dist/components/form/core/FormContext.d.ts.map +0 -0
- package/dist/components/form/core/Loading.d.ts +3 -0
- 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 -1
- package/dist/components/form/index.d.ts.map +1 -1
- package/dist/components/form/inputs/AutocompleteMultiple.d.ts +1 -1
- package/dist/components/form/inputs/BasicInputs.d.ts +1 -1
- package/dist/components/form/inputs/Checkboxgroup.d.ts +1 -1
- package/dist/components/form/inputs/FormItem.d.ts +1 -1
- package/dist/components/form/inputs/FormOptionLabel.d.ts +1 -1
- package/dist/components/form/inputs/RadioGroup.d.ts +1 -1
- package/dist/components/form/inputs/SelectInputs.d.ts +1 -1
- package/dist/components/form/modules/formFragments.d.ts +16 -0
- package/dist/components/form/modules/path_utils.d.ts +6 -0
- package/dist/components/form/modules/schema_utils.d.ts +14 -0
- package/dist/components/form/modules/utils.d.ts +17 -0
- package/dist/components/form/typings.d.ts +2 -0
- package/dist/components/form/typings.d.ts.map +1 -1
- package/dist/components/form/ui_utils.d.ts +3 -0
- package/dist/components/form/useBlockTransition/block.d.ts +4 -0
- package/dist/components/form/useBlockTransition/useBlockTransition.d.ts +5 -0
- package/dist/components/form/useWarnOnUnsaved/index.d.ts +2 -0
- package/dist/components/form/useWarnOnUnsaved/useWarnOnUnsaved.d.ts +5 -0
- package/dist/components/form/utils/formFragments.d.ts.map +0 -0
- package/dist/components/form/utils/index.d.ts.map +0 -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 +0 -0
- package/dist/components/form/utils/utils.d.ts.map +0 -0
- package/dist/componentsHelpers.d.ts.map +0 -0
- package/dist/decorators/autocomplete.d.ts +8 -0
- package/dist/decorators/index.d.ts +4 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +449 -440
- package/dist/index.js.map +1 -1
- package/dist/testing/ExpectedErrorBoundary.d.ts.map +0 -0
- package/dist/testing.d.ts.map +0 -0
- package/dist/testing.js +0 -0
- package/dist/testing.js.map +0 -0
- package/package.json +8 -8
package/dist/index.js
CHANGED
@@ -579,6 +579,338 @@ var require_tslib = __commonJS({
|
|
579
579
|
// index.ts
|
580
580
|
init_esm_shims();
|
581
581
|
|
582
|
+
// components/core/index.ts
|
583
|
+
init_esm_shims();
|
584
|
+
|
585
|
+
// components/core/LoadingButton.tsx
|
586
|
+
init_esm_shims();
|
587
|
+
import React4 from "react";
|
588
|
+
|
589
|
+
// components/VulcanComponents/Consumer.tsx
|
590
|
+
init_esm_shims();
|
591
|
+
import { deprecate } from "@vulcanjs/utils";
|
592
|
+
import React3, { useContext } from "react";
|
593
|
+
|
594
|
+
// components/VulcanComponents/Context.ts
|
595
|
+
init_esm_shims();
|
596
|
+
import React2 from "react";
|
597
|
+
|
598
|
+
// components/VulcanComponents/Dummy.tsx
|
599
|
+
init_esm_shims();
|
600
|
+
import React from "react";
|
601
|
+
var Dummy = /* @__PURE__ */ __name(() => /* @__PURE__ */ React.createElement("span", null, "You have not setup VulcanComponentsProvider. Please add following code in your app:", " ", /* @__PURE__ */ React.createElement("code", null, `import { VulcanComponentsProvider } from "@vulcanjs/react-ui"; const YourApp = <VulcanComponentsProvider>{/* your app */}</VulcanComponentsProvider>;}`)), "Dummy");
|
602
|
+
|
603
|
+
// components/VulcanComponents/Context.ts
|
604
|
+
var dummyHandler = {
|
605
|
+
get(target, property) {
|
606
|
+
if (property in target) {
|
607
|
+
return target[property];
|
608
|
+
}
|
609
|
+
console.log(`Property ${property} not in possible Vulcan components, returning Dummy`);
|
610
|
+
return Dummy;
|
611
|
+
}
|
612
|
+
};
|
613
|
+
var VulcanComponentsContext = React2.createContext(new Proxy({
|
614
|
+
__not_initialized: true
|
615
|
+
}, dummyHandler));
|
616
|
+
VulcanComponentsContext.displayName = "VulcanComponentsContext";
|
617
|
+
|
618
|
+
// components/VulcanComponents/Consumer.tsx
|
619
|
+
function _extends() {
|
620
|
+
_extends = Object.assign || function(target) {
|
621
|
+
for (var i = 1; i < arguments.length; i++) {
|
622
|
+
var source = arguments[i];
|
623
|
+
for (var key in source) {
|
624
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
625
|
+
target[key] = source[key];
|
626
|
+
}
|
627
|
+
}
|
628
|
+
}
|
629
|
+
return target;
|
630
|
+
};
|
631
|
+
return _extends.apply(this, arguments);
|
632
|
+
}
|
633
|
+
__name(_extends, "_extends");
|
634
|
+
var VulcanComponentsConsumer = VulcanComponentsContext.Consumer;
|
635
|
+
var useVulcanComponents = /* @__PURE__ */ __name(() => {
|
636
|
+
const val = useContext(VulcanComponentsContext);
|
637
|
+
return val;
|
638
|
+
}, "useVulcanComponents");
|
639
|
+
var withVulcanComponents = /* @__PURE__ */ __name((C) => (props) => {
|
640
|
+
const vulcanComponents = useVulcanComponents();
|
641
|
+
deprecate("0.0.0", "Using withVulcanComponents HOC => prefer useVulcanComponents with hooks");
|
642
|
+
return /* @__PURE__ */ React3.createElement(C, _extends({
|
643
|
+
vulcanComponents
|
644
|
+
}, props));
|
645
|
+
}, "withVulcanComponents");
|
646
|
+
|
647
|
+
// components/core/LoadingButton.tsx
|
648
|
+
function _extends2() {
|
649
|
+
_extends2 = Object.assign || function(target) {
|
650
|
+
for (var i = 1; i < arguments.length; i++) {
|
651
|
+
var source = arguments[i];
|
652
|
+
for (var key in source) {
|
653
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
654
|
+
target[key] = source[key];
|
655
|
+
}
|
656
|
+
}
|
657
|
+
}
|
658
|
+
return target;
|
659
|
+
};
|
660
|
+
return _extends2.apply(this, arguments);
|
661
|
+
}
|
662
|
+
__name(_extends2, "_extends");
|
663
|
+
var LoadingButton = /* @__PURE__ */ __name((_a) => {
|
664
|
+
var _b = _a, { loading, label, onClick, children, className = "" } = _b, rest = __objRest(_b, ["loading", "label", "onClick", "children", "className"]);
|
665
|
+
const Components2 = useVulcanComponents();
|
666
|
+
const wrapperStyle = {
|
667
|
+
position: "relative"
|
668
|
+
};
|
669
|
+
const labelStyle = loading ? {
|
670
|
+
opacity: 0.5
|
671
|
+
} : {};
|
672
|
+
const loadingStyle = loading ? {
|
673
|
+
position: "absolute",
|
674
|
+
top: 0,
|
675
|
+
bottom: 0,
|
676
|
+
left: 0,
|
677
|
+
right: 0,
|
678
|
+
display: "flex",
|
679
|
+
justifyContent: "center",
|
680
|
+
alignItems: "center"
|
681
|
+
} : {
|
682
|
+
display: "none"
|
683
|
+
};
|
684
|
+
return /* @__PURE__ */ React4.createElement(Components2.Button, _extends2({
|
685
|
+
className: `loading-button ${loading ? "loading-button-loading" : "loading-button-notloading"} ${className}`,
|
686
|
+
onClick
|
687
|
+
}, rest), /* @__PURE__ */ React4.createElement("span", {
|
688
|
+
style: wrapperStyle
|
689
|
+
}, /* @__PURE__ */ React4.createElement("span", {
|
690
|
+
style: labelStyle
|
691
|
+
}, label || children), /* @__PURE__ */ React4.createElement("span", {
|
692
|
+
style: loadingStyle
|
693
|
+
}, /* @__PURE__ */ React4.createElement(Components2.Loading, null))));
|
694
|
+
}, "LoadingButton");
|
695
|
+
|
696
|
+
// components/core/MutationButton.tsx
|
697
|
+
init_esm_shims();
|
698
|
+
import React5, { useState } from "react";
|
699
|
+
import { useMutation } from "@apollo/client";
|
700
|
+
|
701
|
+
// ../../node_modules/graphql-tag/lib/index.js
|
702
|
+
init_esm_shims();
|
703
|
+
|
704
|
+
// ../../node_modules/tslib/modules/index.js
|
705
|
+
init_esm_shims();
|
706
|
+
var import_tslib = __toESM(require_tslib(), 1);
|
707
|
+
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;
|
708
|
+
|
709
|
+
// ../../node_modules/graphql-tag/lib/index.js
|
710
|
+
import { parse } from "graphql";
|
711
|
+
var docCache = /* @__PURE__ */ new Map();
|
712
|
+
var fragmentSourceMap = /* @__PURE__ */ new Map();
|
713
|
+
var printFragmentWarnings = true;
|
714
|
+
var experimentalFragmentVariables = false;
|
715
|
+
function normalize(string) {
|
716
|
+
return string.replace(/[\s,]+/g, " ").trim();
|
717
|
+
}
|
718
|
+
__name(normalize, "normalize");
|
719
|
+
function cacheKeyFromLoc(loc) {
|
720
|
+
return normalize(loc.source.body.substring(loc.start, loc.end));
|
721
|
+
}
|
722
|
+
__name(cacheKeyFromLoc, "cacheKeyFromLoc");
|
723
|
+
function processFragments(ast) {
|
724
|
+
var seenKeys = /* @__PURE__ */ new Set();
|
725
|
+
var definitions = [];
|
726
|
+
ast.definitions.forEach(function(fragmentDefinition) {
|
727
|
+
if (fragmentDefinition.kind === "FragmentDefinition") {
|
728
|
+
var fragmentName = fragmentDefinition.name.value;
|
729
|
+
var sourceKey = cacheKeyFromLoc(fragmentDefinition.loc);
|
730
|
+
var sourceKeySet = fragmentSourceMap.get(fragmentName);
|
731
|
+
if (sourceKeySet && !sourceKeySet.has(sourceKey)) {
|
732
|
+
if (printFragmentWarnings) {
|
733
|
+
console.warn("Warning: fragment with name " + fragmentName + " already exists.\ngraphql-tag enforces all fragment names across your application to be unique; read more about\nthis in the docs: http://dev.apollodata.com/core/fragments.html#unique-names");
|
734
|
+
}
|
735
|
+
} else if (!sourceKeySet) {
|
736
|
+
fragmentSourceMap.set(fragmentName, sourceKeySet = /* @__PURE__ */ new Set());
|
737
|
+
}
|
738
|
+
sourceKeySet.add(sourceKey);
|
739
|
+
if (!seenKeys.has(sourceKey)) {
|
740
|
+
seenKeys.add(sourceKey);
|
741
|
+
definitions.push(fragmentDefinition);
|
742
|
+
}
|
743
|
+
} else {
|
744
|
+
definitions.push(fragmentDefinition);
|
745
|
+
}
|
746
|
+
});
|
747
|
+
return __assign(__assign({}, ast), {
|
748
|
+
definitions
|
749
|
+
});
|
750
|
+
}
|
751
|
+
__name(processFragments, "processFragments");
|
752
|
+
function stripLoc(doc) {
|
753
|
+
var workSet = new Set(doc.definitions);
|
754
|
+
workSet.forEach(function(node) {
|
755
|
+
if (node.loc)
|
756
|
+
delete node.loc;
|
757
|
+
Object.keys(node).forEach(function(key) {
|
758
|
+
var value = node[key];
|
759
|
+
if (value && typeof value === "object") {
|
760
|
+
workSet.add(value);
|
761
|
+
}
|
762
|
+
});
|
763
|
+
});
|
764
|
+
var loc = doc.loc;
|
765
|
+
if (loc) {
|
766
|
+
delete loc.startToken;
|
767
|
+
delete loc.endToken;
|
768
|
+
}
|
769
|
+
return doc;
|
770
|
+
}
|
771
|
+
__name(stripLoc, "stripLoc");
|
772
|
+
function parseDocument(source) {
|
773
|
+
var cacheKey = normalize(source);
|
774
|
+
if (!docCache.has(cacheKey)) {
|
775
|
+
var parsed = parse(source, {
|
776
|
+
experimentalFragmentVariables,
|
777
|
+
allowLegacyFragmentVariables: experimentalFragmentVariables
|
778
|
+
});
|
779
|
+
if (!parsed || parsed.kind !== "Document") {
|
780
|
+
throw new Error("Not a valid GraphQL document.");
|
781
|
+
}
|
782
|
+
docCache.set(cacheKey, stripLoc(processFragments(parsed)));
|
783
|
+
}
|
784
|
+
return docCache.get(cacheKey);
|
785
|
+
}
|
786
|
+
__name(parseDocument, "parseDocument");
|
787
|
+
function gql(literals) {
|
788
|
+
var args = [];
|
789
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
790
|
+
args[_i - 1] = arguments[_i];
|
791
|
+
}
|
792
|
+
if (typeof literals === "string") {
|
793
|
+
literals = [
|
794
|
+
literals
|
795
|
+
];
|
796
|
+
}
|
797
|
+
var result = literals[0];
|
798
|
+
args.forEach(function(arg, i) {
|
799
|
+
if (arg && arg.kind === "Document") {
|
800
|
+
result += arg.loc.source.body;
|
801
|
+
} else {
|
802
|
+
result += arg;
|
803
|
+
}
|
804
|
+
result += literals[i + 1];
|
805
|
+
});
|
806
|
+
return parseDocument(result);
|
807
|
+
}
|
808
|
+
__name(gql, "gql");
|
809
|
+
function resetCaches() {
|
810
|
+
docCache.clear();
|
811
|
+
fragmentSourceMap.clear();
|
812
|
+
}
|
813
|
+
__name(resetCaches, "resetCaches");
|
814
|
+
function disableFragmentWarnings() {
|
815
|
+
printFragmentWarnings = false;
|
816
|
+
}
|
817
|
+
__name(disableFragmentWarnings, "disableFragmentWarnings");
|
818
|
+
function enableExperimentalFragmentVariables() {
|
819
|
+
experimentalFragmentVariables = true;
|
820
|
+
}
|
821
|
+
__name(enableExperimentalFragmentVariables, "enableExperimentalFragmentVariables");
|
822
|
+
function disableExperimentalFragmentVariables() {
|
823
|
+
experimentalFragmentVariables = false;
|
824
|
+
}
|
825
|
+
__name(disableExperimentalFragmentVariables, "disableExperimentalFragmentVariables");
|
826
|
+
var extras = {
|
827
|
+
gql,
|
828
|
+
resetCaches,
|
829
|
+
disableFragmentWarnings,
|
830
|
+
enableExperimentalFragmentVariables,
|
831
|
+
disableExperimentalFragmentVariables
|
832
|
+
};
|
833
|
+
(function(gql_1) {
|
834
|
+
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;
|
835
|
+
})(gql || (gql = {}));
|
836
|
+
gql["default"] = gql;
|
837
|
+
var lib_default = gql;
|
838
|
+
|
839
|
+
// components/core/MutationButton.tsx
|
840
|
+
function _extends3() {
|
841
|
+
_extends3 = Object.assign || function(target) {
|
842
|
+
for (var i = 1; i < arguments.length; i++) {
|
843
|
+
var source = arguments[i];
|
844
|
+
for (var key in source) {
|
845
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
846
|
+
target[key] = source[key];
|
847
|
+
}
|
848
|
+
}
|
849
|
+
}
|
850
|
+
return target;
|
851
|
+
};
|
852
|
+
return _extends3.apply(this, arguments);
|
853
|
+
}
|
854
|
+
__name(_extends3, "_extends");
|
855
|
+
var MutationButton = /* @__PURE__ */ __name((props) => {
|
856
|
+
const Components2 = useVulcanComponents();
|
857
|
+
const [loading, setLoading] = useState(false);
|
858
|
+
const [error1, setError] = useState();
|
859
|
+
const {
|
860
|
+
mutation,
|
861
|
+
loadingButtonProps = {},
|
862
|
+
label
|
863
|
+
} = props;
|
864
|
+
let { mutationArguments } = props;
|
865
|
+
const mutationAsNode = typeof mutation === "string" ? lib_default`
|
866
|
+
${mutation}
|
867
|
+
` : mutation;
|
868
|
+
const [mutationFunc] = useMutation(mutationAsNode);
|
869
|
+
const handleClick = /* @__PURE__ */ __name(async (e) => {
|
870
|
+
e.preventDefault();
|
871
|
+
setLoading(true);
|
872
|
+
setError(void 0);
|
873
|
+
const {
|
874
|
+
submitCallback,
|
875
|
+
successCallback,
|
876
|
+
errorCallback
|
877
|
+
} = props;
|
878
|
+
try {
|
879
|
+
if (submitCallback) {
|
880
|
+
const callbackReturn = await submitCallback(mutationArguments);
|
881
|
+
if (callbackReturn && callbackReturn.mutationArguments) {
|
882
|
+
mutationArguments = callbackReturn.mutationArguments;
|
883
|
+
}
|
884
|
+
}
|
885
|
+
const result = await mutationFunc({
|
886
|
+
variables: mutationArguments
|
887
|
+
});
|
888
|
+
if (successCallback) {
|
889
|
+
await successCallback(result);
|
890
|
+
}
|
891
|
+
} catch (error) {
|
892
|
+
setError(error);
|
893
|
+
if (errorCallback) {
|
894
|
+
await errorCallback(error);
|
895
|
+
}
|
896
|
+
} finally {
|
897
|
+
setLoading(false);
|
898
|
+
}
|
899
|
+
}, "handleClick");
|
900
|
+
const loadingButton = /* @__PURE__ */ React5.createElement(Components2.LoadingButton, _extends3({
|
901
|
+
loading,
|
902
|
+
onClick: handleClick,
|
903
|
+
label
|
904
|
+
}, loadingButtonProps));
|
905
|
+
if (error1) {
|
906
|
+
return /* @__PURE__ */ React5.createElement(Components2.TooltipTrigger, {
|
907
|
+
trigger: loadingButton,
|
908
|
+
defaultShow: true
|
909
|
+
}, error1.message.replace("GraphQL error: ", ""));
|
910
|
+
}
|
911
|
+
return loadingButton;
|
912
|
+
}, "MutationButton");
|
913
|
+
|
582
914
|
// components/core/typings.ts
|
583
915
|
init_esm_shims();
|
584
916
|
|
@@ -587,10 +919,10 @@ init_esm_shims();
|
|
587
919
|
|
588
920
|
// components/form/core/FormContext.tsx
|
589
921
|
init_esm_shims();
|
590
|
-
import
|
591
|
-
var FormContext = /* @__PURE__ */
|
922
|
+
import React6, { useContext as useContext2 } from "react";
|
923
|
+
var FormContext = /* @__PURE__ */ React6.createContext(void 0);
|
592
924
|
var useFormContext = /* @__PURE__ */ __name(() => {
|
593
|
-
const formContext =
|
925
|
+
const formContext = useContext2(FormContext);
|
594
926
|
if (!formContext)
|
595
927
|
throw new Error(`A component is trying to access form context but it is undefined. Please wrap your component with a <Form>.
|
596
928
|
You may be importing "FormContext" from different packages or have accidentaly made a copy of it?
|
@@ -603,7 +935,7 @@ init_esm_shims();
|
|
603
935
|
|
604
936
|
// components/form/core/Form/Form.tsx
|
605
937
|
init_esm_shims();
|
606
|
-
import
|
938
|
+
import React7, { useEffect as useEffect2, useRef as useRef2, useState as useState2 } from "react";
|
607
939
|
import { runCallbacks, getErrors } from "@vulcanjs/core";
|
608
940
|
import { useIntlContext as useIntlContext2 } from "@vulcanjs/react-i18n";
|
609
941
|
import { removeProperty } from "@vulcanjs/utils";
|
@@ -1270,67 +1602,9 @@ var useWarnOnUnsaved = /* @__PURE__ */ __name(({ isChanged, warnUnsavedChanges }
|
|
1270
1602
|
});
|
1271
1603
|
}, "useWarnOnUnsaved");
|
1272
1604
|
|
1273
|
-
// components/VulcanComponents/Consumer.tsx
|
1274
|
-
init_esm_shims();
|
1275
|
-
import { deprecate } from "@vulcanjs/utils";
|
1276
|
-
import React4, { useContext as useContext2 } from "react";
|
1277
|
-
|
1278
|
-
// components/VulcanComponents/Context.ts
|
1279
|
-
init_esm_shims();
|
1280
|
-
import React3 from "react";
|
1281
|
-
|
1282
|
-
// components/VulcanComponents/Dummy.tsx
|
1283
|
-
init_esm_shims();
|
1284
|
-
import React2 from "react";
|
1285
|
-
var Dummy = /* @__PURE__ */ __name(() => /* @__PURE__ */ React2.createElement("span", null, "You have not setup VulcanComponentsProvider. Please add following code in your app:", " ", /* @__PURE__ */ React2.createElement("code", null, `import { VulcanComponentsProvider } from "@vulcanjs/react-ui"; const YourApp = <VulcanComponentsProvider>{/* your app */}</VulcanComponentsProvider>;}`)), "Dummy");
|
1286
|
-
|
1287
|
-
// components/VulcanComponents/Context.ts
|
1288
|
-
var dummyHandler = {
|
1289
|
-
get(target, property) {
|
1290
|
-
if (property in target) {
|
1291
|
-
return target[property];
|
1292
|
-
}
|
1293
|
-
console.log(`Property ${property} not in possible Vulcan components, returning Dummy`);
|
1294
|
-
return Dummy;
|
1295
|
-
}
|
1296
|
-
};
|
1297
|
-
var VulcanComponentsContext = React3.createContext(new Proxy({
|
1298
|
-
__not_initialized: true
|
1299
|
-
}, dummyHandler));
|
1300
|
-
VulcanComponentsContext.displayName = "VulcanComponentsContext";
|
1301
|
-
|
1302
|
-
// components/VulcanComponents/Consumer.tsx
|
1303
|
-
function _extends() {
|
1304
|
-
_extends = Object.assign || function(target) {
|
1305
|
-
for (var i = 1; i < arguments.length; i++) {
|
1306
|
-
var source = arguments[i];
|
1307
|
-
for (var key in source) {
|
1308
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
1309
|
-
target[key] = source[key];
|
1310
|
-
}
|
1311
|
-
}
|
1312
|
-
}
|
1313
|
-
return target;
|
1314
|
-
};
|
1315
|
-
return _extends.apply(this, arguments);
|
1316
|
-
}
|
1317
|
-
__name(_extends, "_extends");
|
1318
|
-
var VulcanComponentsConsumer = VulcanComponentsContext.Consumer;
|
1319
|
-
var useVulcanComponents = /* @__PURE__ */ __name(() => {
|
1320
|
-
const val = useContext2(VulcanComponentsContext);
|
1321
|
-
return val;
|
1322
|
-
}, "useVulcanComponents");
|
1323
|
-
var withVulcanComponents = /* @__PURE__ */ __name((C) => (props) => {
|
1324
|
-
const vulcanComponents = useVulcanComponents();
|
1325
|
-
deprecate("0.0.0", "Using withVulcanComponents HOC => prefer useVulcanComponents with hooks");
|
1326
|
-
return /* @__PURE__ */ React4.createElement(C, _extends({
|
1327
|
-
vulcanComponents
|
1328
|
-
}, props));
|
1329
|
-
}, "withVulcanComponents");
|
1330
|
-
|
1331
1605
|
// components/form/core/Form/Form.tsx
|
1332
|
-
function
|
1333
|
-
|
1606
|
+
function _extends4() {
|
1607
|
+
_extends4 = Object.assign || function(target) {
|
1334
1608
|
for (var i = 1; i < arguments.length; i++) {
|
1335
1609
|
var source = arguments[i];
|
1336
1610
|
for (var key in source) {
|
@@ -1341,9 +1615,9 @@ function _extends2() {
|
|
1341
1615
|
}
|
1342
1616
|
return target;
|
1343
1617
|
};
|
1344
|
-
return
|
1618
|
+
return _extends4.apply(this, arguments);
|
1345
1619
|
}
|
1346
|
-
__name(
|
1620
|
+
__name(_extends4, "_extends");
|
1347
1621
|
var compactParent = /* @__PURE__ */ __name((object, path) => {
|
1348
1622
|
const parentPath = getParentPath(path);
|
1349
1623
|
const compactIfArray = /* @__PURE__ */ __name((x) => Array.isArray(x) ? compact2(x) : x, "compactIfArray");
|
@@ -1440,7 +1714,7 @@ var FormWarnUnsaved = /* @__PURE__ */ __name(({ isChanged, warnUnsavedChanges, c
|
|
1440
1714
|
isChanged,
|
1441
1715
|
warnUnsavedChanges
|
1442
1716
|
});
|
1443
|
-
return /* @__PURE__ */
|
1717
|
+
return /* @__PURE__ */ React7.createElement(React7.Fragment, null, children);
|
1444
1718
|
}, "FormWarnUnsaved");
|
1445
1719
|
var getData = /* @__PURE__ */ __name((customArgs, props, state, { submitFormCallbacks, form }) => {
|
1446
1720
|
const { currentDocument } = state;
|
@@ -1498,7 +1772,7 @@ var Form = /* @__PURE__ */ __name((props) => {
|
|
1498
1772
|
const successFormCallbacks = [];
|
1499
1773
|
const failureFormCallbacks = [];
|
1500
1774
|
const intl = useIntlContext2();
|
1501
|
-
const [errors, setErrors] =
|
1775
|
+
const [errors, setErrors] = useState2([]);
|
1502
1776
|
const throwError = /* @__PURE__ */ __name((error) => {
|
1503
1777
|
let formErrors = getErrors(error);
|
1504
1778
|
console.log(formErrors);
|
@@ -1510,14 +1784,14 @@ var Form = /* @__PURE__ */ __name((props) => {
|
|
1510
1784
|
const clearFieldErrors = /* @__PURE__ */ __name((path) => {
|
1511
1785
|
setErrors((prevErrors) => prevErrors.filter((error) => error.path !== path));
|
1512
1786
|
}, "clearFieldErrors");
|
1513
|
-
const [deletedValues, setDeletedValues] =
|
1787
|
+
const [deletedValues, setDeletedValues] = useState2([]);
|
1514
1788
|
const addToDeletedValues = /* @__PURE__ */ __name((name) => {
|
1515
1789
|
setDeletedValues((prevDeletedValues) => [
|
1516
1790
|
...prevDeletedValues,
|
1517
1791
|
name
|
1518
1792
|
]);
|
1519
1793
|
}, "addToDeletedValues");
|
1520
|
-
const [callbacks, setCallbacks] =
|
1794
|
+
const [callbacks, setCallbacks] = useState2({
|
1521
1795
|
submitFormCallbacks: [],
|
1522
1796
|
successFormCallbacks: [],
|
1523
1797
|
failureFormCallbacks: []
|
@@ -1548,11 +1822,11 @@ var Form = /* @__PURE__ */ __name((props) => {
|
|
1548
1822
|
failureFormCallbacks: []
|
1549
1823
|
});
|
1550
1824
|
}, "clearFormCallbacks");
|
1551
|
-
const [currentValues, setCurrentValues] =
|
1825
|
+
const [currentValues, setCurrentValues] = useState2({});
|
1552
1826
|
const submitFormContext = /* @__PURE__ */ __name((formType) => (event) => {
|
1553
1827
|
submitForm(formType)(event);
|
1554
1828
|
}, "submitFormContext");
|
1555
|
-
const [currentDocument, setCurrentDocument] =
|
1829
|
+
const [currentDocument, setCurrentDocument] = useState2(initialDocument);
|
1556
1830
|
const updateCurrentValues = /* @__PURE__ */ __name((newValues, options = {}) => {
|
1557
1831
|
const { mode = "overwrite" } = options;
|
1558
1832
|
const { changeCallback } = props;
|
@@ -1593,8 +1867,8 @@ var Form = /* @__PURE__ */ __name((props) => {
|
|
1593
1867
|
props.refetch();
|
1594
1868
|
}
|
1595
1869
|
}, "refetchForm");
|
1596
|
-
const [disabled, setDisabled] =
|
1597
|
-
const [success, setSuccess] =
|
1870
|
+
const [disabled, setDisabled] = useState2(false);
|
1871
|
+
const [success, setSuccess] = useState2(false);
|
1598
1872
|
const clearForm = /* @__PURE__ */ __name((options = {}) => {
|
1599
1873
|
const { document: optionsDocument } = options;
|
1600
1874
|
const document = optionsDocument ? merge2({}, props.prefilledProps, optionsDocument) : null;
|
@@ -1717,224 +1991,86 @@ var Form = /* @__PURE__ */ __name((props) => {
|
|
1717
1991
|
mutationErrorCallback(document1, error);
|
1718
1992
|
}
|
1719
1993
|
}
|
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-tag/lib/index.js
|
1810
|
-
import { parse } from "graphql";
|
1811
|
-
var docCache = /* @__PURE__ */ new Map();
|
1812
|
-
var fragmentSourceMap = /* @__PURE__ */ new Map();
|
1813
|
-
var printFragmentWarnings = true;
|
1814
|
-
var experimentalFragmentVariables = false;
|
1815
|
-
function normalize(string) {
|
1816
|
-
return string.replace(/[\s,]+/g, " ").trim();
|
1817
|
-
}
|
1818
|
-
__name(normalize, "normalize");
|
1819
|
-
function cacheKeyFromLoc(loc) {
|
1820
|
-
return normalize(loc.source.body.substring(loc.start, loc.end));
|
1821
|
-
}
|
1822
|
-
__name(cacheKeyFromLoc, "cacheKeyFromLoc");
|
1823
|
-
function processFragments(ast) {
|
1824
|
-
var seenKeys = /* @__PURE__ */ new Set();
|
1825
|
-
var definitions = [];
|
1826
|
-
ast.definitions.forEach(function(fragmentDefinition) {
|
1827
|
-
if (fragmentDefinition.kind === "FragmentDefinition") {
|
1828
|
-
var fragmentName = fragmentDefinition.name.value;
|
1829
|
-
var sourceKey = cacheKeyFromLoc(fragmentDefinition.loc);
|
1830
|
-
var sourceKeySet = fragmentSourceMap.get(fragmentName);
|
1831
|
-
if (sourceKeySet && !sourceKeySet.has(sourceKey)) {
|
1832
|
-
if (printFragmentWarnings) {
|
1833
|
-
console.warn("Warning: fragment with name " + fragmentName + " already exists.\ngraphql-tag enforces all fragment names across your application to be unique; read more about\nthis in the docs: http://dev.apollodata.com/core/fragments.html#unique-names");
|
1834
|
-
}
|
1835
|
-
} else if (!sourceKeySet) {
|
1836
|
-
fragmentSourceMap.set(fragmentName, sourceKeySet = /* @__PURE__ */ new Set());
|
1837
|
-
}
|
1838
|
-
sourceKeySet.add(sourceKey);
|
1839
|
-
if (!seenKeys.has(sourceKey)) {
|
1840
|
-
seenKeys.add(sourceKey);
|
1841
|
-
definitions.push(fragmentDefinition);
|
1842
|
-
}
|
1843
|
-
} else {
|
1844
|
-
definitions.push(fragmentDefinition);
|
1845
|
-
}
|
1846
|
-
});
|
1847
|
-
return __assign(__assign({}, ast), {
|
1848
|
-
definitions
|
1849
|
-
});
|
1850
|
-
}
|
1851
|
-
__name(processFragments, "processFragments");
|
1852
|
-
function stripLoc(doc) {
|
1853
|
-
var workSet = new Set(doc.definitions);
|
1854
|
-
workSet.forEach(function(node) {
|
1855
|
-
if (node.loc)
|
1856
|
-
delete node.loc;
|
1857
|
-
Object.keys(node).forEach(function(key) {
|
1858
|
-
var value = node[key];
|
1859
|
-
if (value && typeof value === "object") {
|
1860
|
-
workSet.add(value);
|
1861
|
-
}
|
1862
|
-
});
|
1863
|
-
});
|
1864
|
-
var loc = doc.loc;
|
1865
|
-
if (loc) {
|
1866
|
-
delete loc.startToken;
|
1867
|
-
delete loc.endToken;
|
1868
|
-
}
|
1869
|
-
return doc;
|
1870
|
-
}
|
1871
|
-
__name(stripLoc, "stripLoc");
|
1872
|
-
function parseDocument(source) {
|
1873
|
-
var cacheKey = normalize(source);
|
1874
|
-
if (!docCache.has(cacheKey)) {
|
1875
|
-
var parsed = parse(source, {
|
1876
|
-
experimentalFragmentVariables,
|
1877
|
-
allowLegacyFragmentVariables: experimentalFragmentVariables
|
1878
|
-
});
|
1879
|
-
if (!parsed || parsed.kind !== "Document") {
|
1880
|
-
throw new Error("Not a valid GraphQL document.");
|
1881
|
-
}
|
1882
|
-
docCache.set(cacheKey, stripLoc(processFragments(parsed)));
|
1883
|
-
}
|
1884
|
-
return docCache.get(cacheKey);
|
1885
|
-
}
|
1886
|
-
__name(parseDocument, "parseDocument");
|
1887
|
-
function gql(literals) {
|
1888
|
-
var args = [];
|
1889
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
1890
|
-
args[_i - 1] = arguments[_i];
|
1891
|
-
}
|
1892
|
-
if (typeof literals === "string") {
|
1893
|
-
literals = [
|
1894
|
-
literals
|
1895
|
-
];
|
1896
|
-
}
|
1897
|
-
var result = literals[0];
|
1898
|
-
args.forEach(function(arg, i) {
|
1899
|
-
if (arg && arg.kind === "Document") {
|
1900
|
-
result += arg.loc.source.body;
|
1901
|
-
} else {
|
1902
|
-
result += arg;
|
1994
|
+
}, "submitForm");
|
1995
|
+
const deleteDocumentWithConfirm = /* @__PURE__ */ __name(() => {
|
1996
|
+
const document = currentDocument;
|
1997
|
+
const documentId = props.document._id;
|
1998
|
+
const documentTitle = document.title || document.name || "";
|
1999
|
+
const deleteDocumentConfirm = intl.formatMessage({
|
2000
|
+
id: "forms.delete_confirm"
|
2001
|
+
}, {
|
2002
|
+
title: documentTitle
|
2003
|
+
});
|
2004
|
+
if (window.confirm(deleteDocumentConfirm)) {
|
2005
|
+
deleteDocument({
|
2006
|
+
input: {
|
2007
|
+
id: documentId
|
2008
|
+
}
|
2009
|
+
}).then((mutationResult) => {
|
2010
|
+
if (props.removeSuccessCallback)
|
2011
|
+
props.removeSuccessCallback({
|
2012
|
+
documentId,
|
2013
|
+
documentTitle
|
2014
|
+
});
|
2015
|
+
refetchForm();
|
2016
|
+
}).catch((error) => {
|
2017
|
+
console.log(error);
|
2018
|
+
});
|
1903
2019
|
}
|
1904
|
-
|
2020
|
+
}, "deleteDocumentWithConfirm");
|
2021
|
+
const { successComponent, document: document1, currentUser, model, warnUnsavedChanges } = props;
|
2022
|
+
const FormComponents = useVulcanComponents();
|
2023
|
+
const formType1 = document1 ? "edit" : "new";
|
2024
|
+
const mutableFields = formType1 === "edit" ? getEditableFields(schema, currentUser, initialDocument) : getInsertableFields(schema, currentUser);
|
2025
|
+
const { formLayoutProps, formGroupProps } = getChildrenProps(props, {
|
2026
|
+
disabled,
|
2027
|
+
currentDocument
|
2028
|
+
}, {
|
2029
|
+
formType: formType1
|
2030
|
+
}, {
|
2031
|
+
deleteDocument: deleteDocumentWithConfirm
|
1905
2032
|
});
|
1906
|
-
|
1907
|
-
|
1908
|
-
|
1909
|
-
|
1910
|
-
|
1911
|
-
|
1912
|
-
|
1913
|
-
|
1914
|
-
|
1915
|
-
|
1916
|
-
|
1917
|
-
|
1918
|
-
|
1919
|
-
|
1920
|
-
|
1921
|
-
|
1922
|
-
|
1923
|
-
|
1924
|
-
|
1925
|
-
|
1926
|
-
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
|
1935
|
-
|
1936
|
-
|
1937
|
-
|
2033
|
+
const isChanged = isNotSameDocument(initialDocument, currentDocument);
|
2034
|
+
return success && successComponent ? successComponent : /* @__PURE__ */ React7.createElement(FormWarnUnsaved, {
|
2035
|
+
isChanged,
|
2036
|
+
warnUnsavedChanges
|
2037
|
+
}, /* @__PURE__ */ React7.createElement(FormContext.Provider, {
|
2038
|
+
value: {
|
2039
|
+
throwError,
|
2040
|
+
clearForm,
|
2041
|
+
refetchForm,
|
2042
|
+
isChanged,
|
2043
|
+
submitForm: submitFormContext(formType1),
|
2044
|
+
addToDeletedValues,
|
2045
|
+
updateCurrentValues,
|
2046
|
+
getDocument: () => currentDocument,
|
2047
|
+
getLabel: (fieldName, fieldLocale) => getLabel(model, flatSchema, intl, fieldName, fieldLocale),
|
2048
|
+
initialDocument,
|
2049
|
+
addToSubmitForm,
|
2050
|
+
addToSuccessForm,
|
2051
|
+
addToFailureForm,
|
2052
|
+
clearFormCallbacks,
|
2053
|
+
errors,
|
2054
|
+
currentValues,
|
2055
|
+
deletedValues,
|
2056
|
+
clearFieldErrors
|
2057
|
+
}
|
2058
|
+
}, /* @__PURE__ */ React7.createElement(FormComponents.FormLayout, _extends4({}, formLayoutProps), getFieldGroups(props, {
|
2059
|
+
currentDocument,
|
2060
|
+
schema,
|
2061
|
+
flatSchema,
|
2062
|
+
originalSchema
|
2063
|
+
}, intl, mutableFields, intl.formatMessage).map((group, i) => /* @__PURE__ */ React7.createElement(FormComponents.FormGroup, _extends4({
|
2064
|
+
key: i
|
2065
|
+
}, formGroupProps(group)))))));
|
2066
|
+
}, "Form");
|
2067
|
+
|
2068
|
+
// components/form/core/Form/typings.ts
|
2069
|
+
init_esm_shims();
|
2070
|
+
|
2071
|
+
// components/form/core/FormContainer.tsx
|
2072
|
+
init_esm_shims();
|
2073
|
+
import React10 from "react";
|
1938
2074
|
|
1939
2075
|
// components/form/utils/formFragments.ts
|
1940
2076
|
var formFragments_exports = {};
|
@@ -2097,8 +2233,8 @@ import { useContext as useContext3 } from "react";
|
|
2097
2233
|
|
2098
2234
|
// components/VulcanCurrentUser/Context.ts
|
2099
2235
|
init_esm_shims();
|
2100
|
-
import
|
2101
|
-
var VulcanCurrentUserContext =
|
2236
|
+
import React8 from "react";
|
2237
|
+
var VulcanCurrentUserContext = React8.createContext({
|
2102
2238
|
currentUser: null,
|
2103
2239
|
loading: false
|
2104
2240
|
});
|
@@ -2109,9 +2245,9 @@ var useVulcanCurrentUser = /* @__PURE__ */ __name(() => useContext3(VulcanCurren
|
|
2109
2245
|
|
2110
2246
|
// components/VulcanCurrentUser/Provider.tsx
|
2111
2247
|
init_esm_shims();
|
2112
|
-
import
|
2113
|
-
function
|
2114
|
-
|
2248
|
+
import React9 from "react";
|
2249
|
+
function _extends5() {
|
2250
|
+
_extends5 = Object.assign || function(target) {
|
2115
2251
|
for (var i = 1; i < arguments.length; i++) {
|
2116
2252
|
var source = arguments[i];
|
2117
2253
|
for (var key in source) {
|
@@ -2122,19 +2258,19 @@ function _extends3() {
|
|
2122
2258
|
}
|
2123
2259
|
return target;
|
2124
2260
|
};
|
2125
|
-
return
|
2261
|
+
return _extends5.apply(this, arguments);
|
2126
2262
|
}
|
2127
|
-
__name(
|
2263
|
+
__name(_extends5, "_extends");
|
2128
2264
|
var VulcanCurrentUserProvider = /* @__PURE__ */ __name((_a) => {
|
2129
2265
|
var _b = _a, { value } = _b, props = __objRest(_b, ["value"]);
|
2130
|
-
return /* @__PURE__ */
|
2266
|
+
return /* @__PURE__ */ React9.createElement(VulcanCurrentUserContext.Provider, _extends5({
|
2131
2267
|
value
|
2132
2268
|
}, props));
|
2133
2269
|
}, "VulcanCurrentUserProvider");
|
2134
2270
|
|
2135
2271
|
// components/form/core/FormContainer.tsx
|
2136
|
-
function
|
2137
|
-
|
2272
|
+
function _extends6() {
|
2273
|
+
_extends6 = Object.assign || function(target) {
|
2138
2274
|
for (var i = 1; i < arguments.length; i++) {
|
2139
2275
|
var source = arguments[i];
|
2140
2276
|
for (var key in source) {
|
@@ -2145,9 +2281,9 @@ function _extends4() {
|
|
2145
2281
|
}
|
2146
2282
|
return target;
|
2147
2283
|
};
|
2148
|
-
return
|
2284
|
+
return _extends6.apply(this, arguments);
|
2149
2285
|
}
|
2150
|
-
__name(
|
2286
|
+
__name(_extends6, "_extends");
|
2151
2287
|
var debugForm = debugVulcan("form");
|
2152
2288
|
var useFragments = /* @__PURE__ */ __name((props, formType) => {
|
2153
2289
|
let queryFragment;
|
@@ -2271,9 +2407,9 @@ var FormContainer = /* @__PURE__ */ __name((props) => {
|
|
2271
2407
|
await deleteDocument(variables);
|
2272
2408
|
}, "deleteDocumentAndRefetch");
|
2273
2409
|
if (isEdit && loading) {
|
2274
|
-
return /* @__PURE__ */
|
2410
|
+
return /* @__PURE__ */ React10.createElement(VulcanComponents.Loading, null);
|
2275
2411
|
}
|
2276
|
-
return /* @__PURE__ */
|
2412
|
+
return /* @__PURE__ */ React10.createElement(VulcanComponents.Form, _extends6({
|
2277
2413
|
document: document1,
|
2278
2414
|
loading: loading || loadingCurrentUser,
|
2279
2415
|
createDocument: createAndReturnDocument,
|
@@ -2338,10 +2474,10 @@ init_esm_shims();
|
|
2338
2474
|
|
2339
2475
|
// components/VulcanComponents/Provider.tsx
|
2340
2476
|
init_esm_shims();
|
2341
|
-
import
|
2477
|
+
import React11 from "react";
|
2342
2478
|
import { debugVulcan as debugVulcan2 } from "@vulcanjs/utils";
|
2343
|
-
function
|
2344
|
-
|
2479
|
+
function _extends7() {
|
2480
|
+
_extends7 = Object.assign || function(target) {
|
2345
2481
|
for (var i = 1; i < arguments.length; i++) {
|
2346
2482
|
var source = arguments[i];
|
2347
2483
|
for (var key in source) {
|
@@ -2352,9 +2488,9 @@ function _extends5() {
|
|
2352
2488
|
}
|
2353
2489
|
return target;
|
2354
2490
|
};
|
2355
|
-
return
|
2491
|
+
return _extends7.apply(this, arguments);
|
2356
2492
|
}
|
2357
|
-
__name(
|
2493
|
+
__name(_extends7, "_extends");
|
2358
2494
|
var debugComponents = debugVulcan2("components");
|
2359
2495
|
var VulcanComponentsProvider = /* @__PURE__ */ __name((_a) => {
|
2360
2496
|
var _b = _a, { value } = _b, props = __objRest(_b, ["value"]);
|
@@ -2372,147 +2508,18 @@ var VulcanComponentsProvider = /* @__PURE__ */ __name((_a) => {
|
|
2372
2508
|
"useVulcanComponents" from index instead of Consumer.`);
|
2373
2509
|
}
|
2374
2510
|
});
|
2375
|
-
return /* @__PURE__ */
|
2511
|
+
return /* @__PURE__ */ React11.createElement(VulcanComponentsContext.Provider, _extends7({
|
2376
2512
|
value: mergedComponents
|
2377
2513
|
}, props));
|
2378
2514
|
}, "VulcanComponentsProvider");
|
2379
2515
|
|
2380
2516
|
// components/VulcanComponents/typings.ts
|
2381
2517
|
init_esm_shims();
|
2382
|
-
import
|
2518
|
+
import React12 from "react";
|
2383
2519
|
|
2384
2520
|
// components/VulcanComponents/defaultVulcanComponents/index.ts
|
2385
2521
|
init_esm_shims();
|
2386
2522
|
|
2387
|
-
// components/core/LoadingButton.tsx
|
2388
|
-
init_esm_shims();
|
2389
|
-
import React11 from "react";
|
2390
|
-
function _extends6() {
|
2391
|
-
_extends6 = Object.assign || function(target) {
|
2392
|
-
for (var i = 1; i < arguments.length; i++) {
|
2393
|
-
var source = arguments[i];
|
2394
|
-
for (var key in source) {
|
2395
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
2396
|
-
target[key] = source[key];
|
2397
|
-
}
|
2398
|
-
}
|
2399
|
-
}
|
2400
|
-
return target;
|
2401
|
-
};
|
2402
|
-
return _extends6.apply(this, arguments);
|
2403
|
-
}
|
2404
|
-
__name(_extends6, "_extends");
|
2405
|
-
var LoadingButton = /* @__PURE__ */ __name((_a) => {
|
2406
|
-
var _b = _a, { loading, label, onClick, children, className = "" } = _b, rest = __objRest(_b, ["loading", "label", "onClick", "children", "className"]);
|
2407
|
-
const Components2 = useVulcanComponents();
|
2408
|
-
const wrapperStyle = {
|
2409
|
-
position: "relative"
|
2410
|
-
};
|
2411
|
-
const labelStyle = loading ? {
|
2412
|
-
opacity: 0.5
|
2413
|
-
} : {};
|
2414
|
-
const loadingStyle = loading ? {
|
2415
|
-
position: "absolute",
|
2416
|
-
top: 0,
|
2417
|
-
bottom: 0,
|
2418
|
-
left: 0,
|
2419
|
-
right: 0,
|
2420
|
-
display: "flex",
|
2421
|
-
justifyContent: "center",
|
2422
|
-
alignItems: "center"
|
2423
|
-
} : {
|
2424
|
-
display: "none"
|
2425
|
-
};
|
2426
|
-
return /* @__PURE__ */ React11.createElement(Components2.Button, _extends6({
|
2427
|
-
className: `loading-button ${loading ? "loading-button-loading" : "loading-button-notloading"} ${className}`,
|
2428
|
-
onClick
|
2429
|
-
}, rest), /* @__PURE__ */ React11.createElement("span", {
|
2430
|
-
style: wrapperStyle
|
2431
|
-
}, /* @__PURE__ */ React11.createElement("span", {
|
2432
|
-
style: labelStyle
|
2433
|
-
}, label || children), /* @__PURE__ */ React11.createElement("span", {
|
2434
|
-
style: loadingStyle
|
2435
|
-
}, /* @__PURE__ */ React11.createElement(Components2.Loading, null))));
|
2436
|
-
}, "LoadingButton");
|
2437
|
-
|
2438
|
-
// components/core/MutationButton.tsx
|
2439
|
-
init_esm_shims();
|
2440
|
-
import React12, { useState as useState2 } from "react";
|
2441
|
-
import { useMutation } from "@apollo/client";
|
2442
|
-
function _extends7() {
|
2443
|
-
_extends7 = Object.assign || function(target) {
|
2444
|
-
for (var i = 1; i < arguments.length; i++) {
|
2445
|
-
var source = arguments[i];
|
2446
|
-
for (var key in source) {
|
2447
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
2448
|
-
target[key] = source[key];
|
2449
|
-
}
|
2450
|
-
}
|
2451
|
-
}
|
2452
|
-
return target;
|
2453
|
-
};
|
2454
|
-
return _extends7.apply(this, arguments);
|
2455
|
-
}
|
2456
|
-
__name(_extends7, "_extends");
|
2457
|
-
var MutationButton = /* @__PURE__ */ __name((props) => {
|
2458
|
-
const Components2 = useVulcanComponents();
|
2459
|
-
const [loading, setLoading] = useState2(false);
|
2460
|
-
const [error1, setError] = useState2();
|
2461
|
-
const {
|
2462
|
-
mutation,
|
2463
|
-
loadingButtonProps = {},
|
2464
|
-
label
|
2465
|
-
} = props;
|
2466
|
-
let { mutationArguments } = props;
|
2467
|
-
const mutationAsNode = typeof mutation === "string" ? lib_default`
|
2468
|
-
${mutation}
|
2469
|
-
` : mutation;
|
2470
|
-
const [mutationFunc] = useMutation(mutationAsNode);
|
2471
|
-
const handleClick = /* @__PURE__ */ __name(async (e) => {
|
2472
|
-
e.preventDefault();
|
2473
|
-
setLoading(true);
|
2474
|
-
setError(void 0);
|
2475
|
-
const {
|
2476
|
-
submitCallback,
|
2477
|
-
successCallback,
|
2478
|
-
errorCallback
|
2479
|
-
} = props;
|
2480
|
-
try {
|
2481
|
-
if (submitCallback) {
|
2482
|
-
const callbackReturn = await submitCallback(mutationArguments);
|
2483
|
-
if (callbackReturn && callbackReturn.mutationArguments) {
|
2484
|
-
mutationArguments = callbackReturn.mutationArguments;
|
2485
|
-
}
|
2486
|
-
}
|
2487
|
-
const result = await mutationFunc({
|
2488
|
-
variables: mutationArguments
|
2489
|
-
});
|
2490
|
-
if (successCallback) {
|
2491
|
-
await successCallback(result);
|
2492
|
-
}
|
2493
|
-
} catch (error) {
|
2494
|
-
setError(error);
|
2495
|
-
if (errorCallback) {
|
2496
|
-
await errorCallback(error);
|
2497
|
-
}
|
2498
|
-
} finally {
|
2499
|
-
setLoading(false);
|
2500
|
-
}
|
2501
|
-
}, "handleClick");
|
2502
|
-
const loadingButton = /* @__PURE__ */ React12.createElement(Components2.LoadingButton, _extends7({
|
2503
|
-
loading,
|
2504
|
-
onClick: handleClick,
|
2505
|
-
label
|
2506
|
-
}, loadingButtonProps));
|
2507
|
-
if (error1) {
|
2508
|
-
return /* @__PURE__ */ React12.createElement(Components2.TooltipTrigger, {
|
2509
|
-
trigger: loadingButton,
|
2510
|
-
defaultShow: true
|
2511
|
-
}, error1.message.replace("GraphQL error: ", ""));
|
2512
|
-
}
|
2513
|
-
return loadingButton;
|
2514
|
-
}, "MutationButton");
|
2515
|
-
|
2516
2523
|
// components/form/core/index.ts
|
2517
2524
|
init_esm_shims();
|
2518
2525
|
|
@@ -2611,6 +2618,8 @@ export {
|
|
2611
2618
|
Form,
|
2612
2619
|
FormContainer,
|
2613
2620
|
FormContext,
|
2621
|
+
LoadingButton,
|
2622
|
+
MutationButton,
|
2614
2623
|
SmartForm,
|
2615
2624
|
VulcanComponentsConsumer,
|
2616
2625
|
VulcanComponentsContext,
|