@sprucelabs/spruce-form-utils 17.0.0 → 17.2.0
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/build/__tests__/implementation/FormCard/formCardAssert.d.ts +8 -0
- package/build/__tests__/implementation/FormCard/formCardAssert.js +25 -0
- package/build/__tests__/support/SpyFormCard.d.ts +9 -0
- package/build/__tests__/support/SpyFormCard.js +13 -0
- package/build/esm/__tests__/implementation/FormCard/formCardAssert.d.ts +8 -0
- package/build/esm/__tests__/implementation/FormCard/formCardAssert.js +20 -0
- package/build/esm/__tests__/support/SpyFormCard.d.ts +9 -0
- package/build/esm/__tests__/support/SpyFormCard.js +7 -0
- package/build/esm/index-module.d.ts +12 -1
- package/build/esm/index-module.js +3 -1
- package/build/esm/viewControllers/FormCard.vc.d.ts +23 -0
- package/build/esm/viewControllers/FormCard.vc.js +79 -0
- package/build/index-module.d.ts +12 -1
- package/build/index-module.js +6 -3
- package/build/viewControllers/FormCard.vc.d.ts +23 -0
- package/build/viewControllers/FormCard.vc.js +70 -0
- package/package.json +59 -46
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Card, ViewController } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import { ViewFixture } from '@sprucelabs/spruce-test-fixtures';
|
|
3
|
+
import { FormCardViewControllerOptions } from '../../../viewControllers/FormCard.vc';
|
|
4
|
+
declare const formCardAssert: {
|
|
5
|
+
beforeEach(views: Pick<ViewFixture, 'setController'>): void;
|
|
6
|
+
configurationEquals(vc: ViewController<Card>, expected: FormCardViewControllerOptions): void;
|
|
7
|
+
};
|
|
8
|
+
export default formCardAssert;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
|
|
7
|
+
const test_utils_1 = require("@sprucelabs/test-utils");
|
|
8
|
+
const FormCard_vc_1 = __importDefault(require("../../../viewControllers/FormCard.vc"));
|
|
9
|
+
const SpyFormCard_1 = __importDefault(require("../../support/SpyFormCard"));
|
|
10
|
+
let wasBeforeEachCalled = false;
|
|
11
|
+
const formCardAssert = {
|
|
12
|
+
beforeEach(views) {
|
|
13
|
+
wasBeforeEachCalled = true;
|
|
14
|
+
views.setController('forms.card', SpyFormCard_1.default);
|
|
15
|
+
},
|
|
16
|
+
configurationEquals(vc, expected) {
|
|
17
|
+
test_utils_1.assert.isTrue(wasBeforeEachCalled, "You need to call formCardAssert.beforeEach() in your test's beforeEach() before you create any views!");
|
|
18
|
+
const spy = heartwood_view_controllers_1.vcAssert.assertControllerInstanceOf(vc, FormCard_vc_1.default);
|
|
19
|
+
const keys = Object.keys(expected);
|
|
20
|
+
for (const key of keys) {
|
|
21
|
+
test_utils_1.assert.isEqualDeep(spy.constructorOptions[key], expected[key]);
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
exports.default = formCardAssert;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CardViewController, FormViewController, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import { Schema } from '@sprucelabs/schema';
|
|
3
|
+
import FormCardViewController, { FormCardViewControllerOptions } from '../../viewControllers/FormCard.vc';
|
|
4
|
+
export default class SpyFormCard<S extends Schema = Schema> extends FormCardViewController<S> {
|
|
5
|
+
formVc: FormViewController<S>;
|
|
6
|
+
cardVc: CardViewController;
|
|
7
|
+
constructorOptions: FormCardViewControllerOptions<S>;
|
|
8
|
+
constructor(options: ViewControllerOptions & FormCardViewControllerOptions<S>);
|
|
9
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const FormCard_vc_1 = __importDefault(require("../../viewControllers/FormCard.vc"));
|
|
7
|
+
class SpyFormCard extends FormCard_vc_1.default {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super(options);
|
|
10
|
+
this.constructorOptions = options;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.default = SpyFormCard;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Card, ViewController } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import { ViewFixture } from '@sprucelabs/spruce-test-fixtures';
|
|
3
|
+
import { FormCardViewControllerOptions } from '../../../viewControllers/FormCard.vc';
|
|
4
|
+
declare const formCardAssert: {
|
|
5
|
+
beforeEach(views: Pick<ViewFixture, 'setController'>): void;
|
|
6
|
+
configurationEquals(vc: ViewController<Card>, expected: FormCardViewControllerOptions): void;
|
|
7
|
+
};
|
|
8
|
+
export default formCardAssert;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { vcAssert, } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import { assert } from '@sprucelabs/test-utils';
|
|
3
|
+
import FormCardViewController from '../../../viewControllers/FormCard.vc.js';
|
|
4
|
+
import SpyFormCard from '../../support/SpyFormCard.js';
|
|
5
|
+
let wasBeforeEachCalled = false;
|
|
6
|
+
const formCardAssert = {
|
|
7
|
+
beforeEach(views) {
|
|
8
|
+
wasBeforeEachCalled = true;
|
|
9
|
+
views.setController('forms.card', SpyFormCard);
|
|
10
|
+
},
|
|
11
|
+
configurationEquals(vc, expected) {
|
|
12
|
+
assert.isTrue(wasBeforeEachCalled, "You need to call formCardAssert.beforeEach() in your test's beforeEach() before you create any views!");
|
|
13
|
+
const spy = vcAssert.assertControllerInstanceOf(vc, FormCardViewController);
|
|
14
|
+
const keys = Object.keys(expected);
|
|
15
|
+
for (const key of keys) {
|
|
16
|
+
assert.isEqualDeep(spy.constructorOptions[key], expected[key]);
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
export default formCardAssert;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CardViewController, FormViewController, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import { Schema } from '@sprucelabs/schema';
|
|
3
|
+
import FormCardViewController, { FormCardViewControllerOptions } from '../../viewControllers/FormCard.vc';
|
|
4
|
+
export default class SpyFormCard<S extends Schema = Schema> extends FormCardViewController<S> {
|
|
5
|
+
formVc: FormViewController<S>;
|
|
6
|
+
cardVc: CardViewController;
|
|
7
|
+
constructorOptions: FormCardViewControllerOptions<S>;
|
|
8
|
+
constructor(options: ViewControllerOptions & FormCardViewControllerOptions<S>);
|
|
9
|
+
}
|
|
@@ -1,6 +1,17 @@
|
|
|
1
|
+
import FormCardViewController from './viewControllers/FormCard.vc';
|
|
1
2
|
export { default as formAssert } from './__tests__/support/formAssert';
|
|
2
3
|
export { default as formCompletionCalculator } from './completing/formCompletionCalculator';
|
|
3
4
|
export { default as FormPlayerCardViewController } from './completing/FormPlayerCard.vc';
|
|
4
5
|
export { default as FormCardViewController } from './viewControllers/FormCard.vc';
|
|
5
|
-
export
|
|
6
|
+
export * from './viewControllers/FormCard.vc';
|
|
7
|
+
export { default as SpyFormCardViewController } from './__tests__/support/SpyFormCard';
|
|
8
|
+
export { default as formCardAssert } from './__tests__/implementation/FormCard/formCardAssert';
|
|
6
9
|
export * from './types/types-module';
|
|
10
|
+
declare module '@sprucelabs/heartwood-view-controllers/build/types/heartwood.types' {
|
|
11
|
+
interface ViewControllerMap {
|
|
12
|
+
'forms.card': FormCardViewController;
|
|
13
|
+
}
|
|
14
|
+
interface ViewControllerOptionsMap {
|
|
15
|
+
'forms.card': ConstructorParameters<typeof FormCardViewController>[0];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -2,5 +2,7 @@ export { default as formAssert } from './__tests__/support/formAssert.js';
|
|
|
2
2
|
export { default as formCompletionCalculator } from './completing/formCompletionCalculator.js';
|
|
3
3
|
export { default as FormPlayerCardViewController } from './completing/FormPlayerCard.vc.js';
|
|
4
4
|
export { default as FormCardViewController } from './viewControllers/FormCard.vc.js';
|
|
5
|
-
export
|
|
5
|
+
export * from './viewControllers/FormCard.vc.js';
|
|
6
|
+
export { default as SpyFormCardViewController } from './__tests__/support/SpyFormCard.js';
|
|
7
|
+
export { default as formCardAssert } from './__tests__/implementation/FormCard/formCardAssert.js';
|
|
6
8
|
export * from './types/types-module.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AbstractViewController, Card, CardHeader, FormSection, FormViewController, FormViewControllerOptions, CardViewController as HeartwoodCardViewController, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import { Schema, SchemaFieldNames, SchemaFieldValueType, SchemaPartialValues } from '@sprucelabs/schema';
|
|
3
|
+
export default class FormCardViewController<S extends Schema = any> extends AbstractViewController<Card> {
|
|
4
|
+
static id: string;
|
|
5
|
+
protected formVc: FormViewController<S>;
|
|
6
|
+
protected cardVc: HeartwoodCardViewController;
|
|
7
|
+
constructor(options: ViewControllerOptions & FormCardViewControllerOptions<S>);
|
|
8
|
+
private CardVc;
|
|
9
|
+
getIsValid(): boolean;
|
|
10
|
+
validate(): Partial<Record<Extract<keyof S["fields"], string>, import("@sprucelabs/heartwood-view-controllers").TypedFieldError<S, Extract<keyof S["fields"], string>>[]>>;
|
|
11
|
+
setValues(values: SchemaPartialValues<S>): Promise<void>;
|
|
12
|
+
getValues(): SchemaPartialValues<S, false>;
|
|
13
|
+
setValue<N extends SchemaFieldNames<S>>(fieldName: N, value: SchemaFieldValueType<S, N>): Promise<void>;
|
|
14
|
+
getValue<N extends SchemaFieldNames<S>>(field: N): SchemaFieldValueType<S, N> | null | undefined;
|
|
15
|
+
render(): import("@sprucelabs/heartwood-view-controllers").SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
16
|
+
}
|
|
17
|
+
export type FormCardViewControllerOptions<S extends Schema = Schema> = Partial<{
|
|
18
|
+
header?: CardHeader;
|
|
19
|
+
fields?: FormSection<S>['fields'];
|
|
20
|
+
} & Omit<FormViewControllerOptions<S>, 'schema'>> & {
|
|
21
|
+
schema: S;
|
|
22
|
+
};
|
|
23
|
+
export declare function buildFormCard<S extends Schema>(options: FormCardViewControllerOptions<S>): FormCardViewControllerOptions<Schema>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
import { AbstractViewController, } from '@sprucelabs/heartwood-view-controllers';
|
|
22
|
+
import { assertOptions, } from '@sprucelabs/schema';
|
|
23
|
+
class FormCardViewController extends AbstractViewController {
|
|
24
|
+
constructor(options) {
|
|
25
|
+
super(options);
|
|
26
|
+
const _a = assertOptions(options, ['schema']), { fields, id, header } = _a, form = __rest(_a, ["fields", "id", "header"]);
|
|
27
|
+
if (!fields && !form.sections) {
|
|
28
|
+
assertOptions(options, ['sections', 'fields'], 'You have to supply either fields or sections to your form card!');
|
|
29
|
+
}
|
|
30
|
+
if (fields) {
|
|
31
|
+
form.sections = [{ fields }];
|
|
32
|
+
}
|
|
33
|
+
this.formVc = this.Controller('form', form);
|
|
34
|
+
this.cardVc = this.CardVc({ id, header });
|
|
35
|
+
}
|
|
36
|
+
CardVc(options) {
|
|
37
|
+
return this.Controller('card', Object.assign(Object.assign({}, options), { body: {
|
|
38
|
+
sections: [
|
|
39
|
+
{
|
|
40
|
+
form: this.formVc.render(),
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
} }));
|
|
44
|
+
}
|
|
45
|
+
getIsValid() {
|
|
46
|
+
return this.formVc.isValid();
|
|
47
|
+
}
|
|
48
|
+
validate() {
|
|
49
|
+
const errors = this.formVc.validate();
|
|
50
|
+
if (Object.keys(errors).length > 0) {
|
|
51
|
+
this.cardVc.payAttentionToMe();
|
|
52
|
+
}
|
|
53
|
+
return errors;
|
|
54
|
+
}
|
|
55
|
+
setValues(values) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
yield this.formVc.setValues(Object.assign({}, values));
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
getValues() {
|
|
61
|
+
return this.formVc.getValues();
|
|
62
|
+
}
|
|
63
|
+
setValue(fieldName, value) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
yield this.formVc.setValue(fieldName, value);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
getValue(field) {
|
|
69
|
+
return this.formVc.getValue(field);
|
|
70
|
+
}
|
|
71
|
+
render() {
|
|
72
|
+
return this.cardVc.render();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
FormCardViewController.id = 'card';
|
|
76
|
+
export default FormCardViewController;
|
|
77
|
+
export function buildFormCard(options) {
|
|
78
|
+
return options;
|
|
79
|
+
}
|
package/build/index-module.d.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
+
import FormCardViewController from './viewControllers/FormCard.vc';
|
|
1
2
|
export { default as formAssert } from './__tests__/support/formAssert';
|
|
2
3
|
export { default as formCompletionCalculator } from './completing/formCompletionCalculator';
|
|
3
4
|
export { default as FormPlayerCardViewController } from './completing/FormPlayerCard.vc';
|
|
4
5
|
export { default as FormCardViewController } from './viewControllers/FormCard.vc';
|
|
5
|
-
export
|
|
6
|
+
export * from './viewControllers/FormCard.vc';
|
|
7
|
+
export { default as SpyFormCardViewController } from './__tests__/support/SpyFormCard';
|
|
8
|
+
export { default as formCardAssert } from './__tests__/implementation/FormCard/formCardAssert';
|
|
6
9
|
export * from './types/types-module';
|
|
10
|
+
declare module '@sprucelabs/heartwood-view-controllers/build/types/heartwood.types' {
|
|
11
|
+
interface ViewControllerMap {
|
|
12
|
+
'forms.card': FormCardViewController;
|
|
13
|
+
}
|
|
14
|
+
interface ViewControllerOptionsMap {
|
|
15
|
+
'forms.card': ConstructorParameters<typeof FormCardViewController>[0];
|
|
16
|
+
}
|
|
17
|
+
}
|
package/build/index-module.js
CHANGED
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.SpyFormCardViewController = exports.FormCardViewController = exports.FormPlayerCardViewController = exports.formCompletionCalculator = exports.formAssert = void 0;
|
|
20
|
+
exports.formCardAssert = exports.SpyFormCardViewController = exports.FormCardViewController = exports.FormPlayerCardViewController = exports.formCompletionCalculator = exports.formAssert = void 0;
|
|
21
21
|
var formAssert_1 = require("./__tests__/support/formAssert");
|
|
22
22
|
Object.defineProperty(exports, "formAssert", { enumerable: true, get: function () { return __importDefault(formAssert_1).default; } });
|
|
23
23
|
var formCompletionCalculator_1 = require("./completing/formCompletionCalculator");
|
|
@@ -26,6 +26,9 @@ var FormPlayerCard_vc_1 = require("./completing/FormPlayerCard.vc");
|
|
|
26
26
|
Object.defineProperty(exports, "FormPlayerCardViewController", { enumerable: true, get: function () { return __importDefault(FormPlayerCard_vc_1).default; } });
|
|
27
27
|
var FormCard_vc_1 = require("./viewControllers/FormCard.vc");
|
|
28
28
|
Object.defineProperty(exports, "FormCardViewController", { enumerable: true, get: function () { return __importDefault(FormCard_vc_1).default; } });
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
__exportStar(require("./viewControllers/FormCard.vc"), exports);
|
|
30
|
+
var SpyFormCard_1 = require("./__tests__/support/SpyFormCard");
|
|
31
|
+
Object.defineProperty(exports, "SpyFormCardViewController", { enumerable: true, get: function () { return __importDefault(SpyFormCard_1).default; } });
|
|
32
|
+
var formCardAssert_1 = require("./__tests__/implementation/FormCard/formCardAssert");
|
|
33
|
+
Object.defineProperty(exports, "formCardAssert", { enumerable: true, get: function () { return __importDefault(formCardAssert_1).default; } });
|
|
31
34
|
__exportStar(require("./types/types-module"), exports);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AbstractViewController, Card, CardHeader, FormSection, FormViewController, FormViewControllerOptions, CardViewController as HeartwoodCardViewController, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import { Schema, SchemaFieldNames, SchemaFieldValueType, SchemaPartialValues } from '@sprucelabs/schema';
|
|
3
|
+
export default class FormCardViewController<S extends Schema = any> extends AbstractViewController<Card> {
|
|
4
|
+
static id: string;
|
|
5
|
+
protected formVc: FormViewController<S>;
|
|
6
|
+
protected cardVc: HeartwoodCardViewController;
|
|
7
|
+
constructor(options: ViewControllerOptions & FormCardViewControllerOptions<S>);
|
|
8
|
+
private CardVc;
|
|
9
|
+
getIsValid(): boolean;
|
|
10
|
+
validate(): Partial<Record<Extract<keyof S["fields"], string>, import("@sprucelabs/heartwood-view-controllers").TypedFieldError<S, Extract<keyof S["fields"], string>>[]>>;
|
|
11
|
+
setValues(values: SchemaPartialValues<S>): Promise<void>;
|
|
12
|
+
getValues(): SchemaPartialValues<S, false>;
|
|
13
|
+
setValue<N extends SchemaFieldNames<S>>(fieldName: N, value: SchemaFieldValueType<S, N>): Promise<void>;
|
|
14
|
+
getValue<N extends SchemaFieldNames<S>>(field: N): SchemaFieldValueType<S, N> | null | undefined;
|
|
15
|
+
render(): import("@sprucelabs/heartwood-view-controllers").SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
16
|
+
}
|
|
17
|
+
export type FormCardViewControllerOptions<S extends Schema = Schema> = Partial<{
|
|
18
|
+
header?: CardHeader;
|
|
19
|
+
fields?: FormSection<S>['fields'];
|
|
20
|
+
} & Omit<FormViewControllerOptions<S>, 'schema'>> & {
|
|
21
|
+
schema: S;
|
|
22
|
+
};
|
|
23
|
+
export declare function buildFormCard<S extends Schema>(options: FormCardViewControllerOptions<S>): FormCardViewControllerOptions<Schema>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.buildFormCard = void 0;
|
|
15
|
+
const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
|
|
16
|
+
const schema_1 = require("@sprucelabs/schema");
|
|
17
|
+
class FormCardViewController extends heartwood_view_controllers_1.AbstractViewController {
|
|
18
|
+
constructor(options) {
|
|
19
|
+
super(options);
|
|
20
|
+
const _a = (0, schema_1.assertOptions)(options, ['schema']), { fields, id, header } = _a, form = __rest(_a, ["fields", "id", "header"]);
|
|
21
|
+
if (!fields && !form.sections) {
|
|
22
|
+
(0, schema_1.assertOptions)(options, ['sections', 'fields'], 'You have to supply either fields or sections to your form card!');
|
|
23
|
+
}
|
|
24
|
+
if (fields) {
|
|
25
|
+
form.sections = [{ fields }];
|
|
26
|
+
}
|
|
27
|
+
this.formVc = this.Controller('form', form);
|
|
28
|
+
this.cardVc = this.CardVc({ id, header });
|
|
29
|
+
}
|
|
30
|
+
CardVc(options) {
|
|
31
|
+
return this.Controller('card', Object.assign(Object.assign({}, options), { body: {
|
|
32
|
+
sections: [
|
|
33
|
+
{
|
|
34
|
+
form: this.formVc.render(),
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
} }));
|
|
38
|
+
}
|
|
39
|
+
getIsValid() {
|
|
40
|
+
return this.formVc.isValid();
|
|
41
|
+
}
|
|
42
|
+
validate() {
|
|
43
|
+
const errors = this.formVc.validate();
|
|
44
|
+
if (Object.keys(errors).length > 0) {
|
|
45
|
+
this.cardVc.payAttentionToMe();
|
|
46
|
+
}
|
|
47
|
+
return errors;
|
|
48
|
+
}
|
|
49
|
+
async setValues(values) {
|
|
50
|
+
await this.formVc.setValues(Object.assign({}, values));
|
|
51
|
+
}
|
|
52
|
+
getValues() {
|
|
53
|
+
return this.formVc.getValues();
|
|
54
|
+
}
|
|
55
|
+
async setValue(fieldName, value) {
|
|
56
|
+
await this.formVc.setValue(fieldName, value);
|
|
57
|
+
}
|
|
58
|
+
getValue(field) {
|
|
59
|
+
return this.formVc.getValue(field);
|
|
60
|
+
}
|
|
61
|
+
render() {
|
|
62
|
+
return this.cardVc.render();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
FormCardViewController.id = 'card';
|
|
66
|
+
exports.default = FormCardViewController;
|
|
67
|
+
function buildFormCard(options) {
|
|
68
|
+
return options;
|
|
69
|
+
}
|
|
70
|
+
exports.buildFormCard = buildFormCard;
|
package/package.json
CHANGED
|
@@ -1,48 +1,61 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
2
|
+
"name": "@sprucelabs/spruce-form-utils",
|
|
3
|
+
"description": "Support for working with forms and Sprucebot. 📄",
|
|
4
|
+
"version": "17.2.0",
|
|
5
|
+
"skill": {
|
|
6
|
+
"namespace": "forms"
|
|
7
|
+
},
|
|
8
|
+
"homepage": "https://github.com/sprucelabsai/spruce-forms-skill",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/sprucelabsai/spruce-forms-skill/issues"
|
|
11
|
+
},
|
|
12
|
+
"main": "./build/index-module.js",
|
|
13
|
+
"types": "./build/index-module.d.ts",
|
|
14
|
+
"module": "./build/esm/index-module.js",
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"files": [
|
|
17
|
+
"build/index-module.js",
|
|
18
|
+
"build/index-module.d.ts",
|
|
19
|
+
"build/esm/index-module.js",
|
|
20
|
+
"build/esm/index-module.d.ts",
|
|
21
|
+
"build/__tests__/support/formAssert.js",
|
|
22
|
+
"build/__tests__/support/formAssert.d.ts",
|
|
23
|
+
"build/esm/__tests__/support/formAssert.js",
|
|
24
|
+
"build/esm/__tests__/support/formAssert.d.ts",
|
|
25
|
+
"build/completing/FormPlayerCard.vc.js",
|
|
26
|
+
"build/completing/FormPlayerCard.vc.d.ts",
|
|
27
|
+
"build/esm/completing/FormPlayerCard.vc.js",
|
|
28
|
+
"build/esm/completing/FormPlayerCard.vc.d.ts",
|
|
29
|
+
"build/completing/formCompletionCalculator.js",
|
|
30
|
+
"build/completing/formCompletionCalculator.d.ts",
|
|
31
|
+
"build/esm/completing/formCompletionCalculator.js",
|
|
32
|
+
"build/esm/completing/formCompletionCalculator.d.ts",
|
|
33
|
+
"build/types/types-module.js",
|
|
34
|
+
"build/types/types-module.d.ts",
|
|
35
|
+
"build/esm/types/types-module.js",
|
|
36
|
+
"build/esm/types/types-module.d.ts",
|
|
37
|
+
"build/__tests__/implementation/FormCard/formCardAssert.js",
|
|
38
|
+
"build/__tests__/implementation/FormCard/formCardAssert.d.ts",
|
|
39
|
+
"build/esm/__tests__/implementation/FormCard/formCardAssert.js",
|
|
40
|
+
"build/esm/__tests__/implementation/FormCard/formCardAssert.d.ts",
|
|
41
|
+
"build/__tests__/support/SpyFormCard.js",
|
|
42
|
+
"build/__tests__/support/SpyFormCard.d.ts",
|
|
43
|
+
"build/esm/__tests__/support/SpyFormCard.js",
|
|
44
|
+
"build/esm/__tests__/support/SpyFormCard.d.ts",
|
|
45
|
+
"build/viewControllers/FormCard.vc.js",
|
|
46
|
+
"build/viewControllers/FormCard.vc.d.ts",
|
|
47
|
+
"build/esm/viewControllers/FormCard.vc.js",
|
|
48
|
+
"build/esm/viewControllers/FormCard.vc.d.ts"
|
|
49
|
+
],
|
|
50
|
+
"keywords": [],
|
|
51
|
+
"scripts": {
|
|
52
|
+
"release": "npm publish"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@sprucelabs/test-utils": "latest",
|
|
56
|
+
"@sprucelabs/spruce-image-utils": "latest"
|
|
57
|
+
},
|
|
58
|
+
"engines": {
|
|
59
|
+
"yarn": "1.x"
|
|
60
|
+
}
|
|
48
61
|
}
|