piral-forms 1.6.0-beta.7216 → 1.6.0-beta.7243

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/lib/actions.js CHANGED
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateFormState = void 0;
4
- const piral_core_1 = require("piral-core");
1
+ import { updateKey, removeIndicator } from 'piral-core';
5
2
  function getNewFormState(newState, patch) {
6
3
  if (patch.active === false && !newState.submitting) {
7
- return piral_core_1.removeIndicator;
4
+ return removeIndicator;
8
5
  }
9
- return newState.active || newState.submitting || newState.changed ? newState : piral_core_1.removeIndicator;
6
+ return newState.active || newState.submitting || newState.changed ? newState : removeIndicator;
10
7
  }
11
- function updateFormState(ctx, id, initial, patch) {
8
+ export function updateFormState(ctx, id, initial, patch) {
12
9
  ctx.dispatch((state) => {
13
10
  const newState = {
14
11
  ...initial,
@@ -18,9 +15,8 @@ function updateFormState(ctx, id, initial, patch) {
18
15
  const updatedState = getNewFormState(newState, patch);
19
16
  return {
20
17
  ...state,
21
- forms: (0, piral_core_1.updateKey)(state.forms, id, updatedState),
18
+ forms: updateKey(state.forms, id, updatedState),
22
19
  };
23
20
  });
24
21
  }
25
- exports.updateFormState = updateFormState;
26
22
  //# sourceMappingURL=actions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"actions.js","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":";;;AAAA,2CAA4E;AAG5E,SAAS,eAAe,CAAC,QAAuB,EAAE,KAA6B;IAC7E,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE;QAClD,OAAO,4BAAe,CAAC;KACxB;IAED,OAAO,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,IAAI,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,4BAAe,CAAC;AACjG,CAA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AAY,GAAG,eAAe,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QACtD,OAAO;YACL,GAAG,KAAK;YACR,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,EAAE,YAAY,CAAC;SAChD,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
package/lib/create.js CHANGED
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createFormsApi = void 0;
4
- const actions = require("./actions");
5
- const withForm_1 = require("./withForm");
1
+ import * as actions from './actions';
2
+ import { withForm } from './withForm';
6
3
  /**
7
4
  * Creates new Pilet API extensions for enhancing forms.
8
5
  */
9
- function createFormsApi(config = {}) {
6
+ export function createFormsApi(config = {}) {
10
7
  return (context) => {
11
8
  context.defineActions(actions);
12
9
  context.dispatch((state) => ({
@@ -15,10 +12,9 @@ function createFormsApi(config = {}) {
15
12
  }));
16
13
  return {
17
14
  createForm(options) {
18
- return (component) => (0, withForm_1.withForm)(component, options);
15
+ return (component) => withForm(component, options);
19
16
  },
20
17
  };
21
18
  };
22
19
  }
23
- exports.createFormsApi = createFormsApi;
24
20
  //# sourceMappingURL=create.js.map
package/lib/create.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":";;;AAAA,qCAAqC;AAErC,yCAAsC;AAQtC;;GAEG;AACH,SAAgB,cAAc,CAAC,SAAsB,EAAE;IACrD,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAE/B,OAAO,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YAC3B,GAAG,KAAK;YACR,KAAK,EAAE,EAAE;SACV,CAAC,CAAC,CAAC;QAEJ,OAAO;YACL,UAAU,CAAC,OAAO;gBAChB,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,IAAA,mBAAQ,EAAC,SAAS,EAAE,OAAO,CAAC,CAAC;YACrD,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAfD,wCAeC"}
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAQtC;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,SAAsB,EAAE;IACrD,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAE/B,OAAO,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YAC3B,GAAG,KAAK;YACR,KAAK,EAAE,EAAE;SACV,CAAC,CAAC,CAAC;QAEJ,OAAO;YACL,UAAU,CAAC,OAAO;gBAChB,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;YACrD,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
package/lib/index.js CHANGED
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./create"), exports);
5
- tslib_1.__exportStar(require("./types"), exports);
6
- tslib_1.__exportStar(require("./useForm"), exports);
7
- tslib_1.__exportStar(require("./usePrompt"), exports);
8
- tslib_1.__exportStar(require("./withForm"), exports);
1
+ export * from './create';
2
+ export * from './types';
3
+ export * from './useForm';
4
+ export * from './usePrompt';
5
+ export * from './withForm';
9
6
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mDAAyB;AACzB,kDAAwB;AACxB,oDAA0B;AAC1B,sDAA4B;AAC5B,qDAA2B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
package/lib/types.js CHANGED
@@ -1,3 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
3
2
  //# sourceMappingURL=types.js.map
package/lib/useForm.js CHANGED
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useForm = void 0;
4
- const react_1 = require("react");
5
- const piral_core_1 = require("piral-core");
6
- const usePrompt_1 = require("./usePrompt");
1
+ import { useState, useEffect } from 'react';
2
+ import { isfunc, useAction, useGlobalState, isSame, generateId } from 'piral-core';
3
+ import { usePrompt } from './usePrompt';
7
4
  const defaultMessage = 'Are you sure you want to discard the form data?';
8
5
  function createDefaultState(data) {
9
6
  return {
@@ -19,16 +16,16 @@ function updateData(id, state, updateState, newData, options) {
19
16
  const { onChange } = options;
20
17
  updateState(id, state, {
21
18
  currentData: newData,
22
- changed: !(0, piral_core_1.isSame)(newData, state.initialData),
19
+ changed: !isSame(newData, state.initialData),
23
20
  error: undefined,
24
21
  });
25
- if ((0, piral_core_1.isfunc)(onChange)) {
22
+ if (isfunc(onChange)) {
26
23
  Promise.resolve(onChange(newData))
27
24
  .then((data) => {
28
25
  const updatedData = { ...newData, ...data };
29
26
  updateState(id, state, {
30
27
  currentData: updatedData,
31
- changed: !(0, piral_core_1.isSame)(updatedData, state.initialData),
28
+ changed: !isSame(updatedData, state.initialData),
32
29
  error: undefined,
33
30
  });
34
31
  })
@@ -43,7 +40,7 @@ function submitData(id, state, updateState, options) {
43
40
  changed: !!wait,
44
41
  submitting: true,
45
42
  });
46
- if ((0, piral_core_1.isfunc)(onSubmit)) {
43
+ if (isfunc(onSubmit)) {
47
44
  Promise.resolve(onSubmit(state.currentData))
48
45
  .then(() => updateState(id, state, {
49
46
  initialData: state.currentData,
@@ -93,13 +90,13 @@ function createProps(id, state, updateState, options) {
93
90
  * @param options The options used for creating the form.
94
91
  * @param existingId The existing id of the form, if any.
95
92
  */
96
- function useForm(initialData, history, options, existingId) {
93
+ export function useForm(initialData, history, options, existingId) {
97
94
  const { silent, message = defaultMessage } = options;
98
- const [id] = (0, react_1.useState)(existingId || piral_core_1.generateId);
99
- const state = (0, piral_core_1.useGlobalState)((m) => m.forms[id] || createDefaultState(initialData));
100
- const updateState = (0, piral_core_1.useAction)('updateFormState');
101
- (0, usePrompt_1.usePrompt)(!silent && state.changed, history, message);
102
- (0, react_1.useEffect)(() => {
95
+ const [id] = useState(existingId || generateId);
96
+ const state = useGlobalState((m) => m.forms[id] || createDefaultState(initialData));
97
+ const updateState = useAction('updateFormState');
98
+ usePrompt(!silent && state.changed, history, message);
99
+ useEffect(() => {
103
100
  updateState(id, state, {
104
101
  active: true,
105
102
  });
@@ -109,5 +106,4 @@ function useForm(initialData, history, options, existingId) {
109
106
  }, [state.submitting]);
110
107
  return createProps(id, state, updateState, options);
111
108
  }
112
- exports.useForm = useForm;
113
109
  //# sourceMappingURL=useForm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useForm.js","sourceRoot":"","sources":["../src/useForm.ts"],"names":[],"mappings":";;;AACA,iCAAuD;AACvD,2CAAmF;AACnF,2CAAwC;AAGxC,MAAM,cAAc,GAAG,iDAAiD,CAAC;AAMzE,SAAS,kBAAkB,CAAY,IAAe;IACpD,OAAO;QACL,MAAM,EAAE,IAAI;QACZ,WAAW,EAAE,IAAI;QACjB,WAAW,EAAE,IAAI;QACjB,OAAO,EAAE,KAAK;QACd,UAAU,EAAE,KAAK;QACjB,KAAK,EAAE,SAAS;KACjB,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CACjB,EAAU,EACV,KAAoB,EACpB,WAAyB,EACzB,OAAkB,EAClB,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AAG,EAAE,CACV,WAAW,CAAC,EAAE,EAAE,KAAK,EAAE;YACrB,MAAM,EAAE,KAAK;SACd,CAAC,CAAC;IACP,CAAC,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;IACvB,OAAO,WAAW,CAAC,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;AACtD,CAAC"}
package/lib/usePromise.js CHANGED
@@ -1,18 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.usePromise = void 0;
4
- const react_1 = require("react");
1
+ import { useState, useEffect } from 'react';
5
2
  /**
6
3
  * Hook for introducing a complete local loading state for a promise.
7
4
  * @param promise The callback for the promise to wait for.
8
5
  */
9
- function usePromise(promise) {
10
- const [result, setResult] = (0, react_1.useState)({
6
+ export function usePromise(promise) {
7
+ const [result, setResult] = useState({
11
8
  loading: true,
12
9
  data: undefined,
13
10
  error: undefined,
14
11
  });
15
- (0, react_1.useEffect)(() => {
12
+ useEffect(() => {
16
13
  let cancelled = false;
17
14
  promise().then((data) => !cancelled && setResult({ data, error: undefined, loading: false }), (error) => !cancelled && setResult({ data: undefined, error, loading: false }));
18
15
  return () => {
@@ -21,5 +18,4 @@ function usePromise(promise) {
21
18
  }, []);
22
19
  return result;
23
20
  }
24
- exports.usePromise = usePromise;
25
21
  //# sourceMappingURL=usePromise.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"usePromise.js","sourceRoot":"","sources":["../src/usePromise.ts"],"names":[],"mappings":";;;AAAA,iCAA4C;AAW5C;;;GAGG;AACH,SAAgB,UAAU,CAAI,OAAyB;IACrD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,IAAA,gBAAQ,EAAsB;QACxD,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;KACjB,CAAC,CAAC;IACH,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,SAAS,GAAG,KAAK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YACV,SAAS,GAAG,IAAI,CAAC;QACnB,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/lib/usePrompt.js CHANGED
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.usePrompt = void 0;
4
- const react_1 = require("react");
5
- const piral_core_1 = require("piral-core");
1
+ import { useEffect } from 'react';
2
+ import { isfunc } from 'piral-core';
6
3
  /**
7
4
  * Hook to notify the user in case of potential data loss when
8
5
  * performing a page transition (internal or external).
@@ -10,11 +7,11 @@ const piral_core_1 = require("piral-core");
10
7
  * @param history The history of the currently used router.
11
8
  * @param message The message to display when the prompt is shown.
12
9
  */
13
- function usePrompt(active, history, message, onTransition) {
14
- (0, react_1.useEffect)(() => {
10
+ export function usePrompt(active, history, message, onTransition) {
11
+ useEffect(() => {
15
12
  if (active) {
16
13
  const beforeUnload = (ev) => {
17
- const msg = (0, piral_core_1.isfunc)(message) ? message() : message;
14
+ const msg = isfunc(message) ? message() : message;
18
15
  ev.returnValue = msg;
19
16
  return msg;
20
17
  };
@@ -30,5 +27,4 @@ function usePrompt(active, history, message, onTransition) {
30
27
  return () => { };
31
28
  }, [active, message]);
32
29
  }
33
- exports.usePrompt = usePrompt;
34
30
  //# sourceMappingURL=usePrompt.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"usePrompt.js","sourceRoot":"","sources":["../src/usePrompt.ts"],"names":[],"mappings":";;;AAAA,iCAAkC;AAClC,2CAAoC;AAIpC;;;;;;GAMG;AACH,SAAgB,SAAS,CACvB,MAAe,EACf,OAAgB,EAChB,OAAsB,EACtB,YAA2C;IAE3C,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,MAAM,EAAE;YACV,MAAM,YAAY,GAAG,CAAC,EAAqB,EAAE,EAAE;gBAC7C,MAAM,GAAG,GAAG,IAAA,mBAAM,EAAC,OAAO,CAAC,CAAC,CAAC,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ACF,MAAM,QAAQ,GAAG,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;YAC9D,MAAM,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAClD,MAAM,CAAC,gBAAgB,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;YACtD,OAAO,GAAG,EAAE;gBACV,QAAQ,IAAI,QAAQ,EAAE,CAAC;gBACvB,OAAO,IAAI,OAAO,EAAE,CAAC;gBACrB,MAAM,CAAC,mBAAmB,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;YAC3D,CAAC,CAAC;SACH;QAED,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;IAClB,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AACxB,CAAC"}
package/lib/withForm.js CHANGED
@@ -1,31 +1,27 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withForm = void 0;
4
- const React = require("react");
5
- const react_router_dom_1 = require("react-router-dom");
6
- const piral_core_1 = require("piral-core");
7
- const useForm_1 = require("./useForm");
8
- const usePromise_1 = require("./usePromise");
9
- function withForm(Component, options) {
1
+ import * as React from 'react';
2
+ import { withRouter } from 'react-router-dom';
3
+ import { RegisteredLoadingIndicator, RegisteredErrorInfo } from 'piral-core';
4
+ import { useForm } from './useForm';
5
+ import { usePromise } from './usePromise';
6
+ export function withForm(Component, options) {
10
7
  const FormView = (props) => {
11
- const formProps = (0, useForm_1.useForm)(props.initialData, props.history, options);
8
+ const formProps = useForm(props.initialData, props.history, options);
12
9
  return (React.createElement("form", { onSubmit: formProps.submit },
13
10
  React.createElement(Component, { ...props, ...formProps })));
14
11
  };
15
12
  const FormLoader = (props) => {
16
13
  const { loadData, emptyData } = options;
17
- const { loading, data, error } = (0, usePromise_1.usePromise)(() => typeof loadData !== 'function' ? Promise.resolve(emptyData) : loadData(props));
14
+ const { loading, data, error } = usePromise(() => typeof loadData !== 'function' ? Promise.resolve(emptyData) : loadData(props));
18
15
  if (loading) {
19
- return React.createElement(piral_core_1.RegisteredLoadingIndicator, null);
16
+ return React.createElement(RegisteredLoadingIndicator, null);
20
17
  }
21
18
  else if (data) {
22
19
  return React.createElement(FormView, { ...props, initialData: data });
23
20
  }
24
21
  else {
25
- return React.createElement(piral_core_1.RegisteredErrorInfo, { type: "form", error: error });
22
+ return React.createElement(RegisteredErrorInfo, { type: "form", error: error });
26
23
  }
27
24
  };
28
- return (0, react_router_dom_1.withRouter)(FormLoader);
25
+ return withRouter(FormLoader);
29
26
  }
30
- exports.withForm = withForm;
31
27
  //# sourceMappingURL=withForm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"withForm.js","sourceRoot":"","sources":["../src/withForm.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,uDAAmE;AACnE,2CAA6E;AAC7E,uCAAoC;AACpC,6CAA0C;AAG1C,SAAgB,QAAQ,CACtB,SAA6D,EAC7D,OAAoD;IAEpD,MAAM,QAAQ,GAAwE,CAAC,KAAK,EAAE,EAAE;QAC9F,MAAM,SAAS,GAAG,IAAA,iBAAO,EAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACrE,OAAO,CACL,8BAAM,QAAQ,EAAE,SAAS,CAAC,MAAM;YAC9B,oBAAC,SAAS,OAAK,KAAK,KAAM,SAAS,GAAI,CAClC,CACR,CAAC;IACJ,CAAC,CAAC;IACF,MAAM,UAAU,GAA2C,CAAC,KAAK,EAAE,EAAE;QACnE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;QACxC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAA,uBAAU,EAAC,GAAG,EAAE,CAC/C,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,C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,EAAE,KAAK,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAC/C,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAC9E,CAAC;QAEF,IAAI,OAAO,EAAE;YACX,OAAO,oBAAC,0BAA0B,OAAG,CAAC;SACvC;aAAM,IAAI,IAAI,EAAE;YACf,OAAO,oBAAC,QAAQ,OAAK,KAAK,EAAE,WAAW,EAAE,IAAI,GAAI,CAAC;SACnD;aAAM;YACL,OAAO,oBAAC,mBAAmB,IAAC,IAAI,EAAC,MAAM,EAAC,KAAK,EAAE,KAAK,GAAI,CAAC;SAC1D;IACH,CAAC,CAAC;IAEF,OAAO,UAAU,CAAC,UAAU,CAAQ,CAAC;AACvC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-forms",
3
- "version": "1.6.0-beta.7216",
3
+ "version": "1.6.0-beta.7243",
4
4
  "description": "Plugin for providing advanced form support in Piral.",
5
5
  "keywords": [
6
6
  "piral",
@@ -16,29 +16,16 @@
16
16
  "author": "smapiot",
17
17
  "homepage": "https://piral.io",
18
18
  "license": "MIT",
19
- "module": "esm/index.js",
19
+ "module": "lib/index.js",
20
20
  "main": "lib/index.js",
21
21
  "typings": "lib/index.d.ts",
22
22
  "exports": {
23
- ".": {
24
- "import": "./esm/index.js",
25
- "require": "./lib/index.js"
26
- },
27
- "./esm/*": {
28
- "import": "./esm/*"
29
- },
30
- "./lib/*": {
31
- "require": "./lib/*"
32
- },
33
- "./_/*": {
34
- "import": "./esm/*.js",
35
- "require": "./lib/*.js"
36
- },
23
+ ".": "./lib/index.js",
24
+ "./lib/*": "./lib/*",
37
25
  "./package.json": "./package.json"
38
26
  },
39
27
  "sideEffects": false,
40
28
  "files": [
41
- "esm",
42
29
  "lib",
43
30
  "src",
44
31
  "piral-forms.min.js"
@@ -52,10 +39,9 @@
52
39
  },
53
40
  "scripts": {
54
41
  "cleanup": "rimraf esm lib piral-forms.min.js",
55
- "build": "yarn build:bundle && yarn build:commonjs && yarn build:esnext",
42
+ "build": "yarn build:bundle && yarn build:esnext",
56
43
  "build:bundle": "esbuild src/index.ts --outfile=piral-forms.min.js --bundle --external:piral-core --external:react --external:react-router-dom --minify --global-name=piralForms",
57
- "build:commonjs": "tsc --project tsconfig.json --outDir lib --module commonjs",
58
- "build:esnext": "tsc --project tsconfig.json --outDir esm --module esnext",
44
+ "build:esnext": "tsc --project tsconfig.json --outDir lib --module esnext",
59
45
  "typedoc": "typedoc --json ../../../docs/types/piral-forms.json src --exclude \"src/**/*.test.*\"",
60
46
  "test": "echo \"Error: run tests from root\" && exit 1"
61
47
  },
@@ -63,9 +49,9 @@
63
49
  "@types/history": "^4.7.8",
64
50
  "@types/react": "^18.0.0",
65
51
  "@types/react-router-dom": "^5.1.6",
66
- "piral-core": "1.6.0-beta.7216",
52
+ "piral-core": "1.6.0-beta.7243",
67
53
  "react": "^18.0.0",
68
54
  "react-router-dom": "^5.2.0"
69
55
  },
70
- "gitHead": "bd3742af68fc25af93ed9b37021d2d69a6f40f18"
56
+ "gitHead": "bbb6e4f78c61b6ef753099a5b378ad2708565ce3"
71
57
  }
package/esm/actions.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { GlobalStateContext } from 'piral-core';
2
- import { FormDataState } from './types';
3
- export declare function updateFormState(ctx: GlobalStateContext, id: string, initial: FormDataState, patch: Partial<FormDataState>): void;
package/esm/actions.js DELETED
@@ -1,22 +0,0 @@
1
- import { updateKey, removeIndicator } from 'piral-core';
2
- function getNewFormState(newState, patch) {
3
- if (patch.active === false && !newState.submitting) {
4
- return removeIndicator;
5
- }
6
- return newState.active || newState.submitting || newState.changed ? newState : removeIndicator;
7
- }
8
- export function updateFormState(ctx, id, initial, patch) {
9
- ctx.dispatch((state) => {
10
- const newState = {
11
- ...initial,
12
- ...(state.forms[id] || {}),
13
- ...patch,
14
- };
15
- const updatedState = getNewFormState(newState, patch);
16
- return {
17
- ...state,
18
- forms: updateKey(state.forms, id, updatedState),
19
- };
20
- });
21
- }
22
- //# sourceMappingURL=actions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"actions.js","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAsB,MAAM,YAAY,CAAC;AAG5E,SAAS,eAAe,CAAC,QAAuB,EAAE,KAA6B;IAC7E,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE;QAClD,OAAO,eAAe,CAAC;KACxB;IAED,OAAO,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,IAAI,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,eAAe,CAAC;AACjG,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,GAAuB,EACvB,EAAU,EACV,OAAsB,EACtB,KAA6B;IAE7B,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE;QACrB,MAAM,QAAQ,GAAG;YACf,GAAG,OAAO;YACV,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC;YAC1B,GAAG,KAAK;SACT,CAAC;QACF,MAAM,YAAY,GAAG,eAAe,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QACtD,OAAO;YACL,GAAG,KAAK;YACR,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,EAAE,YAAY,CAAC;SAChD,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
package/esm/create.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import { PiralPlugin } from 'piral-core';
2
- import { PiletFormsApi } from './types';
3
- /**
4
- * Available configuration options for the forms plugin.
5
- */
6
- export interface FormsConfig {
7
- }
8
- /**
9
- * Creates new Pilet API extensions for enhancing forms.
10
- */
11
- export declare function createFormsApi(config?: FormsConfig): PiralPlugin<PiletFormsApi>;
package/esm/create.js DELETED
@@ -1,20 +0,0 @@
1
- import * as actions from './actions';
2
- import { withForm } from './withForm';
3
- /**
4
- * Creates new Pilet API extensions for enhancing forms.
5
- */
6
- export function createFormsApi(config = {}) {
7
- return (context) => {
8
- context.defineActions(actions);
9
- context.dispatch((state) => ({
10
- ...state,
11
- forms: {},
12
- }));
13
- return {
14
- createForm(options) {
15
- return (component) => withForm(component, options);
16
- },
17
- };
18
- };
19
- }
20
- //# sourceMappingURL=create.js.map
package/esm/create.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAQtC;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,SAAsB,EAAE;IACrD,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAE/B,OAAO,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YAC3B,GAAG,KAAK;YACR,KAAK,EAAE,EAAE;SACV,CAAC,CAAC,CAAC;QAEJ,OAAO;YACL,UAAU,CAAC,OAAO;gBAChB,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;YACrD,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
package/esm/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from './create';
2
- export * from './types';
3
- export * from './useForm';
4
- export * from './usePrompt';
5
- export * from './withForm';
package/esm/index.js DELETED
@@ -1,6 +0,0 @@
1
- export * from './create';
2
- export * from './types';
3
- export * from './useForm';
4
- export * from './usePrompt';
5
- export * from './withForm';
6
- //# sourceMappingURL=index.js.map
package/esm/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
package/esm/types.d.ts DELETED
@@ -1,170 +0,0 @@
1
- import type { ComponentType, ChangeEvent, FC } from 'react';
2
- declare module 'piral-core/lib/types/custom' {
3
- interface PiletCustomApi extends PiletFormsApi {
4
- }
5
- interface PiralCustomState {
6
- /**
7
- * The relevant state for the active forms.
8
- */
9
- forms: FormsState;
10
- }
11
- interface PiralCustomActions {
12
- /**
13
- * Sets the form data from the provided original state and patch data.
14
- * @param id The id of the form.
15
- * @param original The initial state of the form.
16
- * @param patch The provided patch.
17
- */
18
- updateFormState(id: string, original: FormDataState, patch: Partial<FormDataState>): void;
19
- }
20
- interface PiralCustomRegistryState {
21
- }
22
- interface PiralCustomErrors {
23
- form: FormErrorInfoProps;
24
- }
25
- }
26
- /**
27
- * The error used when a form submission resulted in an error.
28
- */
29
- export interface FormErrorInfoProps {
30
- /**
31
- * The type of the error.
32
- */
33
- type: 'form';
34
- /**
35
- * The provided error details.
36
- */
37
- error: any;
38
- /**
39
- * The name of the pilet emitting the error.
40
- */
41
- pilet?: string;
42
- }
43
- export interface FormDataState {
44
- /**
45
- * Gets the usage status of the form - true means
46
- * the form is actively being used, false is the
47
- * status for forms that are not used any more.
48
- */
49
- active: boolean;
50
- /**
51
- * Indicates that the form is currently submitting.
52
- */
53
- submitting: boolean;
54
- /**
55
- * Stores the potential error of the form.
56
- */
57
- error: any;
58
- /**
59
- * The initial data to use.
60
- */
61
- initialData: any;
62
- /**
63
- * The current data that has been submitted.
64
- */
65
- currentData: any;
66
- /**
67
- * Gets or sets if th current data is different from
68
- * the initial data.
69
- */
70
- changed: boolean;
71
- }
72
- export interface FormsState {
73
- /**
74
- * Gets the state of forms that are currently not actively used.
75
- */
76
- [id: string]: FormDataState;
77
- }
78
- export interface FormProps<TFormData> {
79
- /**
80
- * Submits the current form.
81
- * @param data The data to submit.
82
- */
83
- submit(): void;
84
- /**
85
- * Resets the current form.
86
- */
87
- reset(): void;
88
- /**
89
- * Indicats an error while submitting the form.
90
- */
91
- error?: any;
92
- /**
93
- * Indicates that the form is currently submitting.
94
- */
95
- submitting: boolean;
96
- /**
97
- * Gets if the form data has been changed.
98
- */
99
- changed: boolean;
100
- /**
101
- * Gets the current form data.
102
- */
103
- formData: TFormData;
104
- /**
105
- * Sets the (partially) updated form data. If no current form data is
106
- * given this is treated as the initial state.
107
- * @param data The updated form data.
108
- */
109
- setFormData<TKeys extends keyof TFormData>(data: Pick<TFormData, TKeys>): void;
110
- /**
111
- * Changes the form field given by the name of the input element that
112
- * emits the corresponding event.
113
- * @param e The event arguments.
114
- */
115
- changeForm(e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>): void;
116
- }
117
- export interface FormCreator<TFormData, TRequiredProps> {
118
- /**
119
- * Form function for wrapping a component.
120
- */
121
- <TProps extends TRequiredProps>(component: ComponentType<TProps & FormProps<TFormData>>): FC<TProps>;
122
- }
123
- /**
124
- * Potential value types for defining a prompt message.
125
- */
126
- export type PromptMessage = string | (() => string);
127
- export interface InputFormOptions<TFormData, TProps> {
128
- /**
129
- * If enabled does not notify the user that form data could be lost on page transitions.
130
- */
131
- silent?: boolean;
132
- /**
133
- * If enabled forces the user to stay on the form until onSubmit has finished.
134
- */
135
- wait?: boolean;
136
- /**
137
- * Optionally, overrides the message to show when the form data would be lost.
138
- */
139
- message?: PromptMessage;
140
- /**
141
- * Loads the initial form data from the provided props, which are the auxiliary props given
142
- * to the form component.
143
- */
144
- loadData?(props: TProps): Promise<TFormData>;
145
- /**
146
- * Sets the initial data of the form.
147
- */
148
- emptyData: TFormData;
149
- /**
150
- * Callback to be invoked when the form is submitted.
151
- * In case of an error reject the promise. The error will be handed back to the
152
- * form.
153
- * @param data The entered form data.
154
- */
155
- onSubmit(data: TFormData): Promise<void>;
156
- /**
157
- * Callback to be invoked when the form data has changed.
158
- * Has the ability of changing the form data by returning
159
- * a promise leading to the modified form data.
160
- * @param data The currently entered form data.
161
- */
162
- onChange?(data: TFormData): Promise<Partial<TFormData>>;
163
- }
164
- export interface PiletFormsApi {
165
- /**
166
- * Creates an input form for tracking user input intelligently.
167
- * @param options The options for creating the form.
168
- */
169
- createForm<TFormData, TProps = {}>(options: InputFormOptions<TFormData, TProps>): FormCreator<TFormData, TProps>;
170
- }
package/esm/types.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
package/esm/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/esm/useForm.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import type { History } from 'history';
2
- import { FormProps, InputFormOptions } from './types';
3
- /**
4
- * Hook for using a form locally that blocks if a transition is performed.
5
- * @param initialData The initial data of the form.
6
- * @param history The history to listen / block for changes / transitions.
7
- * @param options The options used for creating the form.
8
- * @param existingId The existing id of the form, if any.
9
- */
10
- export declare function useForm<TFormData>(initialData: TFormData, history: History, options: InputFormOptions<TFormData, any>, existingId?: string): FormProps<TFormData>;
package/esm/useForm.js DELETED
@@ -1,109 +0,0 @@
1
- import { useState, useEffect } from 'react';
2
- import { isfunc, useAction, useGlobalState, isSame, generateId } from 'piral-core';
3
- import { usePrompt } from './usePrompt';
4
- const defaultMessage = 'Are you sure you want to discard the form data?';
5
- function createDefaultState(data) {
6
- return {
7
- active: true,
8
- currentData: data,
9
- initialData: data,
10
- changed: false,
11
- submitting: false,
12
- error: undefined,
13
- };
14
- }
15
- function updateData(id, state, updateState, newData, options) {
16
- const { onChange } = options;
17
- updateState(id, state, {
18
- currentData: newData,
19
- changed: !isSame(newData, state.initialData),
20
- error: undefined,
21
- });
22
- if (isfunc(onChange)) {
23
- Promise.resolve(onChange(newData))
24
- .then((data) => {
25
- const updatedData = { ...newData, ...data };
26
- updateState(id, state, {
27
- currentData: updatedData,
28
- changed: !isSame(updatedData, state.initialData),
29
- error: undefined,
30
- });
31
- })
32
- .catch((error) => updateState(id, state, {
33
- error,
34
- }));
35
- }
36
- }
37
- function submitData(id, state, updateState, options) {
38
- const { onSubmit, wait } = options;
39
- updateState(id, state, {
40
- changed: !!wait,
41
- submitting: true,
42
- });
43
- if (isfunc(onSubmit)) {
44
- Promise.resolve(onSubmit(state.currentData))
45
- .then(() => updateState(id, state, {
46
- initialData: state.currentData,
47
- changed: false,
48
- submitting: false,
49
- }))
50
- .catch((error) => updateState(id, state, {
51
- error,
52
- changed: true,
53
- submitting: false,
54
- }));
55
- }
56
- }
57
- function createProps(id, state, updateState, options) {
58
- return {
59
- changed: state.changed,
60
- formData: state.currentData,
61
- error: state.error,
62
- submit(e) {
63
- e && e.preventDefault();
64
- if (state.changed) {
65
- submitData(id, state, updateState, options);
66
- }
67
- return false;
68
- },
69
- submitting: state.submitting,
70
- reset() {
71
- updateState(id, state, {
72
- currentData: state.initialData,
73
- changed: false,
74
- error: undefined,
75
- });
76
- },
77
- setFormData(updatedData) {
78
- updateData(id, state, updateState, { ...state.currentData, ...updatedData }, options);
79
- },
80
- changeForm(e) {
81
- const { name, value } = e.target;
82
- updateData(id, state, updateState, { ...state.currentData, [name]: value }, options);
83
- },
84
- };
85
- }
86
- /**
87
- * Hook for using a form locally that blocks if a transition is performed.
88
- * @param initialData The initial data of the form.
89
- * @param history The history to listen / block for changes / transitions.
90
- * @param options The options used for creating the form.
91
- * @param existingId The existing id of the form, if any.
92
- */
93
- export function useForm(initialData, history, options, existingId) {
94
- const { silent, message = defaultMessage } = options;
95
- const [id] = useState(existingId || generateId);
96
- const state = useGlobalState((m) => m.forms[id] || createDefaultState(initialData));
97
- const updateState = useAction('updateFormState');
98
- usePrompt(!silent && state.changed, history, message);
99
- useEffect(() => {
100
- updateState(id, state, {
101
- active: true,
102
- });
103
- return () => updateState(id, state, {
104
- active: false,
105
- });
106
- }, [state.submitting]);
107
- return createProps(id, state, updateState, options);
108
- }
109
- //# sourceMappingURL=useForm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useForm.js","sourceRoot":"","sources":["../src/useForm.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAa,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACnF,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,MAAM,cAAc,GAAG,iDAAiD,CAAC;AAMzE,SAAS,kBAAkB,CAAY,IAAe;IACpD,OAAO;QACL,MAAM,EAAE,IAAI;QACZ,WAAW,EAAE,IAAI;QACjB,WAAW,EAAE,IAAI;QACjB,OAAO,EAAE,KAAK;QACd,UAAU,EAAE,KAAK;QACjB,KAAK,EAAE,SAAS;KACjB,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CACjB,EAAU,EACV,KAAoB,EACpB,WAAyB,EACzB,OAAkB,EAClB,OAAyC;IAEzC,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC7B,WAAW,CAAC,EAAE,EAAE,KAAK,EAAE;QACrB,WAAW,EAAE,OAAO;QACpB,OAAO,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,WAAW,CAAC;QAC5C,KAAK,EAAE,SAAS;KACjB,CAAC,CAAC;IAEH,IAAI,MAAM,CAAC,QAAQ,CAAC,EAAE;QACpB,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;aAC/B,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;YACb,MAAM,WAAW,GAAG,EAAE,GAAG,OAAO,EAAE,GAAG,IAAI,EAAE,CAAC;YAC5C,WAAW,CAAC,EA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W,CAAC,CAAC,CAAC;IACpF,MAAM,WAAW,GAAG,SAAS,CAAC,iBAAiB,CAAC,CAAC;IACjD,SAAS,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACtD,SAAS,CAAC,GAAG,EAAE;QACb,WAAW,CAAC,EAAE,EAAE,KAAK,EAAE;YACrB,MAAM,EAAE,IAAI;SACb,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE,CACV,WAAW,CAAC,EAAE,EAAE,KAAK,EAAE;YACrB,MAAM,EAAE,KAAK;SACd,CAAC,CAAC;IACP,CAAC,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;IACvB,OAAO,WAAW,CAAC,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;AACtD,CAAC"}
@@ -1,13 +0,0 @@
1
- /**
2
- * The currently captured Promise state.
3
- */
4
- export interface UsePromiseResult<T> {
5
- loading: boolean;
6
- data: T;
7
- error: any;
8
- }
9
- /**
10
- * Hook for introducing a complete local loading state for a promise.
11
- * @param promise The callback for the promise to wait for.
12
- */
13
- export declare function usePromise<T>(promise: () => Promise<T>): UsePromiseResult<T>;
package/esm/usePromise.js DELETED
@@ -1,21 +0,0 @@
1
- import { useState, useEffect } from 'react';
2
- /**
3
- * Hook for introducing a complete local loading state for a promise.
4
- * @param promise The callback for the promise to wait for.
5
- */
6
- export function usePromise(promise) {
7
- const [result, setResult] = useState({
8
- loading: true,
9
- data: undefined,
10
- error: undefined,
11
- });
12
- useEffect(() => {
13
- let cancelled = false;
14
- promise().then((data) => !cancelled && setResult({ data, error: undefined, loading: false }), (error) => !cancelled && setResult({ data: undefined, error, loading: false }));
15
- return () => {
16
- cancelled = true;
17
- };
18
- }, []);
19
- return result;
20
- }
21
- //# sourceMappingURL=usePromise.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"usePromise.js","sourceRoot":"","sources":["../src/usePromise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAW5C;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAI,OAAyB;IACrD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAsB;QACxD,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;KACjB,CAAC,CAAC;IACH,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,SAAS,GAAG,KAAK,CAAC;QAEtB,OAAO,EAAE,CAAC,IAAI,CACZ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,SAAS,IAAI,SAAS,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAC7E,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,SAAS,IAAI,SAAS,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAC/E,CAAC;QAEF,OAAO,GAAG,EAAE;YACV,SAAS,GAAG,IAAI,CAAC;QACnB,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -1,10 +0,0 @@
1
- import type { History, Location } from 'history';
2
- import { PromptMessage } from './types';
3
- /**
4
- * Hook to notify the user in case of potential data loss when
5
- * performing a page transition (internal or external).
6
- * @param active True if the prompt should be shown, otherwise false.
7
- * @param history The history of the currently used router.
8
- * @param message The message to display when the prompt is shown.
9
- */
10
- export declare function usePrompt(active: boolean, history: History, message: PromptMessage, onTransition?: (location: Location) => void): void;
package/esm/usePrompt.js DELETED
@@ -1,30 +0,0 @@
1
- import { useEffect } from 'react';
2
- import { isfunc } from 'piral-core';
3
- /**
4
- * Hook to notify the user in case of potential data loss when
5
- * performing a page transition (internal or external).
6
- * @param active True if the prompt should be shown, otherwise false.
7
- * @param history The history of the currently used router.
8
- * @param message The message to display when the prompt is shown.
9
- */
10
- export function usePrompt(active, history, message, onTransition) {
11
- useEffect(() => {
12
- if (active) {
13
- const beforeUnload = (ev) => {
14
- const msg = isfunc(message) ? message() : message;
15
- ev.returnValue = msg;
16
- return msg;
17
- };
18
- const unlisten = onTransition && history.listen(onTransition);
19
- const unblock = message && history.block(message);
20
- window.addEventListener('beforeunload', beforeUnload);
21
- return () => {
22
- unlisten && unlisten();
23
- unblock && unblock();
24
- window.removeEventListener('beforeunload', beforeUnload);
25
- };
26
- }
27
- return () => { };
28
- }, [active, message]);
29
- }
30
- //# sourceMappingURL=usePrompt.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"usePrompt.js","sourceRoot":"","sources":["../src/usePrompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAIpC;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CACvB,MAAe,EACf,OAAgB,EAChB,OAAsB,EACtB,YAA2C;IAE3C,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,MAAM,EAAE;YACV,MAAM,YAAY,GAAG,CAAC,EAAqB,EAAE,EAAE;gBAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;gBAClD,EAAE,CAAC,WAAW,GAAG,GAAG,CAAC;gBACrB,OAAO,GAAG,CAAC;YACb,CAAC,CAAC;YACF,MAAM,QAAQ,GAAG,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;YAC9D,MAAM,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAClD,MAAM,CAAC,gBAAgB,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;YACtD,OAAO,GAAG,EAAE;gBACV,QAAQ,IAAI,QAAQ,EAAE,CAAC;gBACvB,OAAO,IAAI,OAAO,EAAE,CAAC;gBACrB,MAAM,CAAC,mBAAmB,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;YAC3D,CAAC,CAAC;SACH;QAED,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;IAClB,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AACxB,CAAC"}
package/esm/withForm.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import * as React from 'react';
2
- import { InputFormOptions, FormProps } from './types';
3
- export declare function withForm<TFormData, TRequiredProps, TProps extends TRequiredProps>(Component: React.ComponentType<TProps & FormProps<TFormData>>, options: InputFormOptions<TFormData, TRequiredProps>): React.FC<TProps>;
package/esm/withForm.js DELETED
@@ -1,27 +0,0 @@
1
- import * as React from 'react';
2
- import { withRouter } from 'react-router-dom';
3
- import { RegisteredLoadingIndicator, RegisteredErrorInfo } from 'piral-core';
4
- import { useForm } from './useForm';
5
- import { usePromise } from './usePromise';
6
- export function withForm(Component, options) {
7
- const FormView = (props) => {
8
- const formProps = useForm(props.initialData, props.history, options);
9
- return (React.createElement("form", { onSubmit: formProps.submit },
10
- React.createElement(Component, { ...props, ...formProps })));
11
- };
12
- const FormLoader = (props) => {
13
- const { loadData, emptyData } = options;
14
- const { loading, data, error } = usePromise(() => typeof loadData !== 'function' ? Promise.resolve(emptyData) : loadData(props));
15
- if (loading) {
16
- return React.createElement(RegisteredLoadingIndicator, null);
17
- }
18
- else if (data) {
19
- return React.createElement(FormView, { ...props, initialData: data });
20
- }
21
- else {
22
- return React.createElement(RegisteredErrorInfo, { type: "form", error: error });
23
- }
24
- };
25
- return withRouter(FormLoader);
26
- }
27
- //# sourceMappingURL=withForm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"withForm.js","sourceRoot":"","sources":["../src/withForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,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