@tsed/react-formio 1.13.3 → 1.13.4
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/form/form.stories.d.ts +25 -0
- package/dist/components/form/useForm.hook.d.ts +5 -1
- package/dist/index.js +33 -9
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +41 -17
- package/dist/index.modern.js.map +1 -1
- package/package.json +4 -4
- package/src/components/form/form.stories.tsx +58 -1
- package/src/components/form/useForm.hook.ts +37 -8
package/dist/index.modern.js
CHANGED
|
@@ -10,7 +10,6 @@ import Choices from 'choices.js';
|
|
|
10
10
|
import PropTypes from 'prop-types';
|
|
11
11
|
import { useTable, useFilters, useGroupBy, useSortBy, usePagination } from 'react-table';
|
|
12
12
|
import AllComponents from 'formiojs/components';
|
|
13
|
-
import noop$1, { get } from 'lodash';
|
|
14
13
|
import cloneDeep from 'lodash/cloneDeep';
|
|
15
14
|
import isEqual from 'lodash/isEqual';
|
|
16
15
|
import FormioUtils from 'formiojs/utils';
|
|
@@ -19,9 +18,10 @@ import FormioFormBuilder from 'formiojs/FormBuilder';
|
|
|
19
18
|
import Tooltip from 'tooltip.js';
|
|
20
19
|
import uniq from 'lodash/uniq';
|
|
21
20
|
import camelCase from 'lodash/camelCase';
|
|
21
|
+
import noop$1 from 'lodash';
|
|
22
22
|
import ReactDOM from 'react-dom';
|
|
23
23
|
import { createAction, createReducer, combine } from '@tsed/redux-utils';
|
|
24
|
-
import get
|
|
24
|
+
import get from 'lodash/get';
|
|
25
25
|
|
|
26
26
|
function _extends() {
|
|
27
27
|
_extends = Object.assign || function (target) {
|
|
@@ -868,9 +868,14 @@ function Card({
|
|
|
868
868
|
}, children));
|
|
869
869
|
}
|
|
870
870
|
|
|
871
|
-
function
|
|
871
|
+
function useEvent(event, callback, events) {
|
|
872
872
|
useEffect(() => {
|
|
873
|
-
|
|
873
|
+
if (callback) {
|
|
874
|
+
// if (event === "onChange") {
|
|
875
|
+
// callback = callLast(callback, 200);
|
|
876
|
+
// }
|
|
877
|
+
events.set(event, callback);
|
|
878
|
+
}
|
|
874
879
|
}, [callback, event, events]);
|
|
875
880
|
}
|
|
876
881
|
|
|
@@ -888,7 +893,24 @@ function useEvents(funcs) {
|
|
|
888
893
|
}
|
|
889
894
|
};
|
|
890
895
|
|
|
891
|
-
|
|
896
|
+
useEvent("onBlur", funcs["onBlur"], events.current);
|
|
897
|
+
useEvent("onPrevPage", funcs["onPrevPage"], events.current);
|
|
898
|
+
useEvent("onNextPage", funcs["onNextPage"], events.current);
|
|
899
|
+
useEvent("onCancel", funcs["onCancel"], events.current);
|
|
900
|
+
useEvent("onChange", funcs["onChange"], events.current);
|
|
901
|
+
useEvent("onCustomEvent", funcs["onCustomEvent"], events.current);
|
|
902
|
+
useEvent("onComponentChange", funcs["onComponentChange"], events.current);
|
|
903
|
+
useEvent("onSubmit", funcs["onSubmit"], events.current);
|
|
904
|
+
useEvent("onAsyncSubmit", funcs["onAsyncSubmit"], events.current);
|
|
905
|
+
useEvent("onSubmitDone", funcs["onSubmitDone"], events.current);
|
|
906
|
+
useEvent("onFormLoad", funcs["onFormLoad"], events.current);
|
|
907
|
+
useEvent("onError", funcs["onError"], events.current);
|
|
908
|
+
useEvent("onRender", funcs["onRender"], events.current);
|
|
909
|
+
useEvent("onAttach", funcs["onAttach"], events.current);
|
|
910
|
+
useEvent("onBuild", funcs["onBuild"], events.current);
|
|
911
|
+
useEvent("onFocus", funcs["onFocus"], events.current);
|
|
912
|
+
useEvent("onBlur", funcs["onBlur"], events.current);
|
|
913
|
+
useEvent("onInitialized", funcs["onInitialized"], events.current);
|
|
892
914
|
return {
|
|
893
915
|
events,
|
|
894
916
|
emit,
|
|
@@ -946,10 +968,8 @@ function useForm(props) {
|
|
|
946
968
|
if (event.startsWith("formio.")) {
|
|
947
969
|
const eventName = `on${event.charAt(7).toUpperCase()}${event.slice(8)}`;
|
|
948
970
|
|
|
949
|
-
if (eventName === "onChange") {
|
|
950
|
-
|
|
951
|
-
return;
|
|
952
|
-
}
|
|
971
|
+
if (eventName === "onChange" && !args[0].changed) {
|
|
972
|
+
return;
|
|
953
973
|
}
|
|
954
974
|
|
|
955
975
|
emit(eventName, ...args, instance.current);
|
|
@@ -972,6 +992,10 @@ function useForm(props) {
|
|
|
972
992
|
useEffect(() => {
|
|
973
993
|
if (instance.current) {
|
|
974
994
|
instance.current.ready.then(formio => {
|
|
995
|
+
if (isEqual(formio.submission.data, submission == null ? void 0 : submission.data)) {
|
|
996
|
+
return;
|
|
997
|
+
}
|
|
998
|
+
|
|
975
999
|
submission && (formio.submission = cloneDeep(submission));
|
|
976
1000
|
});
|
|
977
1001
|
}
|
|
@@ -8048,12 +8072,12 @@ function selectRoot(name, state) {
|
|
|
8048
8072
|
|
|
8049
8073
|
return state => selectRoot(name, state);
|
|
8050
8074
|
}
|
|
8051
|
-
const selectError = (name, state) => get
|
|
8052
|
-
const selectIsActive = (name, state) => get
|
|
8075
|
+
const selectError = (name, state) => get(selectRoot(name, state), "error");
|
|
8076
|
+
const selectIsActive = (name, state) => get(selectRoot(name, state), "isActive");
|
|
8053
8077
|
function oneOfIsActive(...names) {
|
|
8054
8078
|
return state => {
|
|
8055
8079
|
return !!names.find(name => {
|
|
8056
|
-
return get
|
|
8080
|
+
return get(state, `${name}.isActive`, get(state, `${name}.current.isActive`));
|
|
8057
8081
|
});
|
|
8058
8082
|
};
|
|
8059
8083
|
}
|
|
@@ -8098,7 +8122,7 @@ const saveAction = (formId, action, done = noop) => async dispatch => {
|
|
|
8098
8122
|
dispatch(sendAction(ACTION, {
|
|
8099
8123
|
action
|
|
8100
8124
|
}));
|
|
8101
|
-
const formio = getFormio(formId, get
|
|
8125
|
+
const formio = getFormio(formId, get(action, "data._id", ""));
|
|
8102
8126
|
|
|
8103
8127
|
try {
|
|
8104
8128
|
const result = await formio.saveAction(action);
|
|
@@ -8382,9 +8406,9 @@ const authReducer = createReducer({
|
|
|
8382
8406
|
}, createInitialState$4)(AUTH);
|
|
8383
8407
|
|
|
8384
8408
|
const selectAuth = state => selectRoot(AUTH, state);
|
|
8385
|
-
const selectUser = state => get
|
|
8386
|
-
const selectRoles = state => get
|
|
8387
|
-
const selectIsAuthenticated = state => get
|
|
8409
|
+
const selectUser = state => get(selectAuth(state), "user");
|
|
8410
|
+
const selectRoles = state => get(selectAuth(state), "roles");
|
|
8411
|
+
const selectIsAuthenticated = state => get(selectAuth(state), "authenticated");
|
|
8388
8412
|
|
|
8389
8413
|
function hasRole(auth, role) {
|
|
8390
8414
|
return auth.is[role];
|
|
@@ -8410,7 +8434,7 @@ function checkRoleFormAccess(auth, form, roles) {
|
|
|
8410
8434
|
return true;
|
|
8411
8435
|
}
|
|
8412
8436
|
|
|
8413
|
-
return roles.includes("owner") && get
|
|
8437
|
+
return roles.includes("owner") && get(form, "owner") === get(auth, "user._id");
|
|
8414
8438
|
}
|
|
8415
8439
|
|
|
8416
8440
|
return true;
|