@sprucelabs/spruce-form-utils 18.1.5 → 18.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { AbstractViewController, FormViewController, SwipeCardViewController, ViewControllerOptions, Router } from '@sprucelabs/heartwood-view-controllers';
1
+ import { AbstractViewController, FormViewController, SwipeCardViewController, ViewControllerOptions, Button, Router } from '@sprucelabs/heartwood-view-controllers';
2
2
  import { SpruceSchemas } from '@sprucelabs/spruce-core-schemas';
3
3
  export default class FormPlayerCardViewController extends AbstractViewController<SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card> {
4
4
  private swipeVc;
@@ -10,6 +10,9 @@ export default class FormPlayerCardViewController extends AbstractViewController
10
10
  private onSaveAndBeDoneHandler?;
11
11
  private uploader;
12
12
  private uploads;
13
+ protected doneButtonLabel: string;
14
+ protected shouldRenderSaveProgressButton: boolean;
15
+ protected additionalButtons: Button[];
13
16
  constructor(options: FormPlayerCardViewControllerOptions & ViewControllerOptions);
14
17
  private SwipeVc;
15
18
  private handleSlideChange;
@@ -47,6 +50,9 @@ export type FormPlayerCardViewControllerOptions = Partial<FormPlayerImportObject
47
50
  isBusy?: boolean;
48
51
  id?: string;
49
52
  onSaveAndBeDone?: () => Promise<void> | void;
53
+ doneButtonLabel?: string;
54
+ shouldRenderSaveProgressButton?: boolean;
55
+ additionalButtons?: Button[];
50
56
  };
51
57
  export type PlayerLoadOptions = Partial<FormPlayerImportObject> & {
52
58
  router?: Router;
@@ -8,8 +8,12 @@ class FormPlayerCardViewController extends heartwood_view_controllers_1.Abstract
8
8
  super(options);
9
9
  this.shouldIgnoreChanges = false;
10
10
  this.uploads = {};
11
- const { onChange, isBusy, id, onSaveAndBeDone, ...builderSource } = options;
11
+ const { onChange, isBusy, id, onSaveAndBeDone, doneButtonLabel, shouldRenderSaveProgressButton, additionalButtons, ...builderSource } = options;
12
12
  this.builderSource = (0, heartwood_view_controllers_1.removeUniversalViewOptions)(builderSource);
13
+ this.doneButtonLabel = doneButtonLabel !== null && doneButtonLabel !== void 0 ? doneButtonLabel : 'Save and be done';
14
+ this.shouldRenderSaveProgressButton =
15
+ shouldRenderSaveProgressButton !== null && shouldRenderSaveProgressButton !== void 0 ? shouldRenderSaveProgressButton : true;
16
+ this.additionalButtons = additionalButtons !== null && additionalButtons !== void 0 ? additionalButtons : [];
13
17
  this.onSaveAndBeDoneHandler = onSaveAndBeDone;
14
18
  this.swipeVc = this.SwipeVc(id, this.builderSource);
15
19
  if (!options.pages || isBusy) {
@@ -36,17 +40,18 @@ class FormPlayerCardViewController extends heartwood_view_controllers_1.Abstract
36
40
  var _a, _b, _c, _d;
37
41
  const totalPages = (_b = (_a = this.builderSource.pages) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
38
42
  const currentPage = (_d = (_c = this.swipeVc) === null || _c === void 0 ? void 0 : _c.getPresentSlide()) !== null && _d !== void 0 ? _d : 0;
39
- const buttons = [
40
- {
43
+ const buttons = [...this.additionalButtons];
44
+ if (this.shouldRenderSaveProgressButton) {
45
+ buttons.push({
41
46
  id: 'saveProgress',
42
47
  label: 'Save progress',
43
48
  onClick: this.handleClickSaveProgress.bind(this),
44
- },
45
- ];
49
+ });
50
+ }
46
51
  if (totalPages === currentPage + 1) {
47
52
  buttons.push({
48
53
  id: 'save',
49
- label: 'Save and be done',
54
+ label: this.doneButtonLabel,
50
55
  type: 'primary',
51
56
  onClick: this.handleClickSaveAndDone.bind(this),
52
57
  });
@@ -1,4 +1,4 @@
1
- import { AbstractViewController, FormViewController, SwipeCardViewController, ViewControllerOptions, Router } from '@sprucelabs/heartwood-view-controllers';
1
+ import { AbstractViewController, FormViewController, SwipeCardViewController, ViewControllerOptions, Button, Router } from '@sprucelabs/heartwood-view-controllers';
2
2
  import { SpruceSchemas } from '@sprucelabs/spruce-core-schemas';
3
3
  export default class FormPlayerCardViewController extends AbstractViewController<SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card> {
4
4
  private swipeVc;
@@ -10,6 +10,9 @@ export default class FormPlayerCardViewController extends AbstractViewController
10
10
  private onSaveAndBeDoneHandler?;
11
11
  private uploader;
12
12
  private uploads;
13
+ protected doneButtonLabel: string;
14
+ protected shouldRenderSaveProgressButton: boolean;
15
+ protected additionalButtons: Button[];
13
16
  constructor(options: FormPlayerCardViewControllerOptions & ViewControllerOptions);
14
17
  private SwipeVc;
15
18
  private handleSlideChange;
@@ -47,6 +50,9 @@ export type FormPlayerCardViewControllerOptions = Partial<FormPlayerImportObject
47
50
  isBusy?: boolean;
48
51
  id?: string;
49
52
  onSaveAndBeDone?: () => Promise<void> | void;
53
+ doneButtonLabel?: string;
54
+ shouldRenderSaveProgressButton?: boolean;
55
+ additionalButtons?: Button[];
50
56
  };
51
57
  export type PlayerLoadOptions = Partial<FormPlayerImportObject> & {
52
58
  router?: Router;
@@ -26,8 +26,12 @@ class FormPlayerCardViewController extends AbstractViewController {
26
26
  super(options);
27
27
  this.shouldIgnoreChanges = false;
28
28
  this.uploads = {};
29
- const { onChange, isBusy, id, onSaveAndBeDone } = options, builderSource = __rest(options, ["onChange", "isBusy", "id", "onSaveAndBeDone"]);
29
+ const { onChange, isBusy, id, onSaveAndBeDone, doneButtonLabel, shouldRenderSaveProgressButton, additionalButtons } = options, builderSource = __rest(options, ["onChange", "isBusy", "id", "onSaveAndBeDone", "doneButtonLabel", "shouldRenderSaveProgressButton", "additionalButtons"]);
30
30
  this.builderSource = removeUniversalViewOptions(builderSource);
31
+ this.doneButtonLabel = doneButtonLabel !== null && doneButtonLabel !== void 0 ? doneButtonLabel : 'Save and be done';
32
+ this.shouldRenderSaveProgressButton =
33
+ shouldRenderSaveProgressButton !== null && shouldRenderSaveProgressButton !== void 0 ? shouldRenderSaveProgressButton : true;
34
+ this.additionalButtons = additionalButtons !== null && additionalButtons !== void 0 ? additionalButtons : [];
31
35
  this.onSaveAndBeDoneHandler = onSaveAndBeDone;
32
36
  this.swipeVc = this.SwipeVc(id, this.builderSource);
33
37
  if (!options.pages || isBusy) {
@@ -54,17 +58,18 @@ class FormPlayerCardViewController extends AbstractViewController {
54
58
  var _a, _b, _c, _d;
55
59
  const totalPages = (_b = (_a = this.builderSource.pages) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
56
60
  const currentPage = (_d = (_c = this.swipeVc) === null || _c === void 0 ? void 0 : _c.getPresentSlide()) !== null && _d !== void 0 ? _d : 0;
57
- const buttons = [
58
- {
61
+ const buttons = [...this.additionalButtons];
62
+ if (this.shouldRenderSaveProgressButton) {
63
+ buttons.push({
59
64
  id: 'saveProgress',
60
65
  label: 'Save progress',
61
66
  onClick: this.handleClickSaveProgress.bind(this),
62
- },
63
- ];
67
+ });
68
+ }
64
69
  if (totalPages === currentPage + 1) {
65
70
  buttons.push({
66
71
  id: 'save',
67
- label: 'Save and be done',
72
+ label: this.doneButtonLabel,
68
73
  type: 'primary',
69
74
  onClick: this.handleClickSaveAndDone.bind(this),
70
75
  });
@@ -1,4 +1,4 @@
1
- import { AbstractViewController, ViewControllerOptions, Card, Router, SpruceSchemas, ViewController } from '@sprucelabs/heartwood-view-controllers';
1
+ import { AbstractViewController, ViewControllerOptions, Card, Router, SpruceSchemas, ViewController, Button } from '@sprucelabs/heartwood-view-controllers';
2
2
  import FormPlayerCardViewController from '../completing/FormPlayerCard.vc';
3
3
  export default class RemoteFormCardViewController extends AbstractViewController<Card> {
4
4
  static id: string;
@@ -21,6 +21,9 @@ export default class RemoteFormCardViewController extends AbstractViewController
21
21
  export interface RemoteFormCardViewControllerOptions {
22
22
  onDone: RemoteFormCardOnDoneHandler;
23
23
  onError: RemoteFormCardOnErrorHandler;
24
+ doneButtonLabel?: string;
25
+ shouldRenderSaveProgressButton?: boolean;
26
+ additionalButtons?: Button[];
24
27
  }
25
28
  export type RemoteFormCardOnDoneHandler = () => void | Promise<void>;
26
29
  export type RemoteFormCardOnErrorHandler = (error: Error) => void | Promise<void>;
@@ -14,13 +14,10 @@ class RemoteFormCardViewController extends AbstractViewController {
14
14
  const { onDone, onError } = options;
15
15
  this.onDoneHandler = onDone;
16
16
  this.onErrorHandler = onError;
17
- this.playerVc = this.FormPlayerCard();
17
+ this.playerVc = this.FormPlayerCard(options);
18
18
  }
19
- FormPlayerCard() {
20
- return this.Controller('forms.form-player-card', {
21
- onChange: this.handlePlayerChange.bind(this),
22
- onSaveAndBeDone: this.handleSaveAndBeDone.bind(this),
23
- });
19
+ FormPlayerCard(options) {
20
+ return this.Controller('forms.form-player-card', Object.assign({ onChange: this.handlePlayerChange.bind(this), onSaveAndBeDone: this.handleSaveAndBeDone.bind(this) }, options));
24
21
  }
25
22
  load(options) {
26
23
  return __awaiter(this, void 0, void 0, function* () {
@@ -1,4 +1,4 @@
1
- import { AbstractViewController, ViewControllerOptions, Card, Router, SpruceSchemas, ViewController } from '@sprucelabs/heartwood-view-controllers';
1
+ import { AbstractViewController, ViewControllerOptions, Card, Router, SpruceSchemas, ViewController, Button } from '@sprucelabs/heartwood-view-controllers';
2
2
  import FormPlayerCardViewController from '../completing/FormPlayerCard.vc';
3
3
  export default class RemoteFormCardViewController extends AbstractViewController<Card> {
4
4
  static id: string;
@@ -21,6 +21,9 @@ export default class RemoteFormCardViewController extends AbstractViewController
21
21
  export interface RemoteFormCardViewControllerOptions {
22
22
  onDone: RemoteFormCardOnDoneHandler;
23
23
  onError: RemoteFormCardOnErrorHandler;
24
+ doneButtonLabel?: string;
25
+ shouldRenderSaveProgressButton?: boolean;
26
+ additionalButtons?: Button[];
24
27
  }
25
28
  export type RemoteFormCardOnDoneHandler = () => void | Promise<void>;
26
29
  export type RemoteFormCardOnErrorHandler = (error: Error) => void | Promise<void>;
@@ -7,12 +7,13 @@ class RemoteFormCardViewController extends heartwood_view_controllers_1.Abstract
7
7
  const { onDone, onError } = options;
8
8
  this.onDoneHandler = onDone;
9
9
  this.onErrorHandler = onError;
10
- this.playerVc = this.FormPlayerCard();
10
+ this.playerVc = this.FormPlayerCard(options);
11
11
  }
12
- FormPlayerCard() {
12
+ FormPlayerCard(options) {
13
13
  return this.Controller('forms.form-player-card', {
14
14
  onChange: this.handlePlayerChange.bind(this),
15
15
  onSaveAndBeDone: this.handleSaveAndBeDone.bind(this),
16
+ ...options,
16
17
  });
17
18
  }
18
19
  async load(options) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-form-utils",
3
3
  "description": "Support for working with forms and Sprucebot. 📄",
4
- "version": "18.1.5",
4
+ "version": "18.2.1",
5
5
  "skill": {
6
6
  "namespace": "forms"
7
7
  },