@payloadcms/plugin-form-builder 1.0.14 → 1.0.15

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.
Files changed (40) hide show
  1. package/dist/collections/FormSubmissions/hooks/createCharge.d.ts +3 -0
  2. package/dist/collections/FormSubmissions/hooks/createCharge.js +58 -0
  3. package/dist/collections/FormSubmissions/hooks/createCharge.js.map +1 -0
  4. package/dist/collections/FormSubmissions/hooks/sendEmail.d.ts +3 -0
  5. package/dist/collections/FormSubmissions/hooks/sendEmail.js +131 -0
  6. package/dist/collections/FormSubmissions/hooks/sendEmail.js.map +1 -0
  7. package/dist/collections/FormSubmissions/index.d.ts +3 -0
  8. package/dist/collections/FormSubmissions/index.js +139 -0
  9. package/dist/collections/FormSubmissions/index.js.map +1 -0
  10. package/dist/collections/Forms/DynamicFieldSelector.d.ts +3 -0
  11. package/dist/collections/Forms/DynamicFieldSelector.js +66 -0
  12. package/dist/collections/Forms/DynamicFieldSelector.js.map +1 -0
  13. package/dist/collections/Forms/DynamicPriceSelector.d.ts +3 -0
  14. package/dist/collections/Forms/DynamicPriceSelector.js +82 -0
  15. package/dist/collections/Forms/DynamicPriceSelector.js.map +1 -0
  16. package/dist/collections/Forms/fields.d.ts +6 -0
  17. package/dist/collections/Forms/fields.js +503 -0
  18. package/dist/collections/Forms/fields.js.map +1 -0
  19. package/dist/collections/Forms/index.d.ts +3 -0
  20. package/dist/collections/Forms/index.js +233 -0
  21. package/dist/collections/Forms/index.js.map +1 -0
  22. package/dist/index.d.ts +6 -0
  23. package/dist/index.js +55 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/mocks/serverModule.d.ts +2 -0
  26. package/dist/mocks/serverModule.js +4 -0
  27. package/dist/mocks/serverModule.js.map +1 -0
  28. package/dist/types.d.ts +174 -0
  29. package/dist/types.js +11 -0
  30. package/dist/types.js.map +1 -0
  31. package/dist/utilities/getPaymentTotal.d.ts +4 -0
  32. package/dist/utilities/getPaymentTotal.js +44 -0
  33. package/dist/utilities/getPaymentTotal.js.map +1 -0
  34. package/dist/utilities/replaceDoubleCurlys.d.ts +7 -0
  35. package/dist/utilities/replaceDoubleCurlys.js +20 -0
  36. package/dist/utilities/replaceDoubleCurlys.js.map +1 -0
  37. package/dist/utilities/serializeRichText.d.ts +10 -0
  38. package/dist/utilities/serializeRichText.js +51 -0
  39. package/dist/utilities/serializeRichText.js.map +1 -0
  40. package/package.json +1 -1
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
+ if (ar || !(i in from)) {
16
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
+ ar[i] = from[i];
18
+ }
19
+ }
20
+ return to.concat(ar || Array.prototype.slice.call(from));
21
+ };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.generateFormCollection = void 0;
27
+ var deepmerge_1 = __importDefault(require("deepmerge"));
28
+ var fields_1 = require("./fields");
29
+ // all settings can be overridden by the config
30
+ var generateFormCollection = function (formConfig) {
31
+ var _a, _b, _c, _d;
32
+ var redirect = {
33
+ name: 'redirect',
34
+ type: 'group',
35
+ admin: {
36
+ hideGutter: true,
37
+ condition: function (_, siblingData) { return (siblingData === null || siblingData === void 0 ? void 0 : siblingData.confirmationType) === 'redirect'; },
38
+ },
39
+ fields: [
40
+ {
41
+ name: 'url',
42
+ label: 'URL to redirect to',
43
+ type: 'text',
44
+ required: true,
45
+ },
46
+ ],
47
+ };
48
+ if (formConfig.redirectRelationships) {
49
+ redirect.fields.unshift({
50
+ name: 'reference',
51
+ label: 'Document to link to',
52
+ type: 'relationship',
53
+ relationTo: formConfig.redirectRelationships,
54
+ required: true,
55
+ maxDepth: 2,
56
+ admin: {
57
+ condition: function (_, siblingData) { return (siblingData === null || siblingData === void 0 ? void 0 : siblingData.type) === 'reference'; },
58
+ },
59
+ });
60
+ redirect.fields.unshift({
61
+ name: 'type',
62
+ type: 'radio',
63
+ options: [
64
+ {
65
+ label: 'Internal link',
66
+ value: 'reference',
67
+ },
68
+ {
69
+ label: 'Custom URL',
70
+ value: 'custom',
71
+ },
72
+ ],
73
+ defaultValue: 'reference',
74
+ admin: {
75
+ layout: 'horizontal',
76
+ },
77
+ });
78
+ if (redirect.fields[2].type !== 'row')
79
+ redirect.fields[2].label = 'Custom URL';
80
+ redirect.fields[2].admin = {
81
+ condition: function (_, siblingData) { return (siblingData === null || siblingData === void 0 ? void 0 : siblingData.type) === 'custom'; },
82
+ };
83
+ }
84
+ var config = __assign(__assign({}, ((formConfig === null || formConfig === void 0 ? void 0 : formConfig.formOverrides) || {})), { slug: ((_a = formConfig === null || formConfig === void 0 ? void 0 : formConfig.formOverrides) === null || _a === void 0 ? void 0 : _a.slug) || 'forms', admin: __assign({ useAsTitle: 'title', enableRichTextRelationship: false }, (((_b = formConfig === null || formConfig === void 0 ? void 0 : formConfig.formOverrides) === null || _b === void 0 ? void 0 : _b.admin) || {})), access: __assign({ read: function () { return true; } }, (((_c = formConfig === null || formConfig === void 0 ? void 0 : formConfig.formOverrides) === null || _c === void 0 ? void 0 : _c.access) || {})), fields: __spreadArray([
85
+ {
86
+ name: 'title',
87
+ type: 'text',
88
+ required: true,
89
+ },
90
+ {
91
+ name: 'fields',
92
+ type: 'blocks',
93
+ blocks: Object.entries((formConfig === null || formConfig === void 0 ? void 0 : formConfig.fields) || {})
94
+ .map(function (_a) {
95
+ var fieldKey = _a[0], fieldConfig = _a[1];
96
+ // let the config enable/disable fields with either boolean values or objects
97
+ if (fieldConfig !== false) {
98
+ var block = fields_1.fields[fieldKey];
99
+ if (block === undefined && typeof fieldConfig === 'object') {
100
+ return fieldConfig;
101
+ }
102
+ if (typeof block === 'object' && typeof fieldConfig === 'object') {
103
+ return (0, deepmerge_1.default)(block, fieldConfig, {
104
+ arrayMerge: function (_, sourceArray) { return sourceArray; },
105
+ });
106
+ }
107
+ if (typeof block === 'function') {
108
+ return block(fieldConfig);
109
+ }
110
+ return block;
111
+ }
112
+ return null;
113
+ })
114
+ .filter(Boolean),
115
+ },
116
+ {
117
+ name: 'submitButtonLabel',
118
+ type: 'text',
119
+ localized: true,
120
+ },
121
+ {
122
+ name: 'confirmationType',
123
+ type: 'radio',
124
+ admin: {
125
+ description: 'Choose whether to display an on-page message or redirect to a different page after they submit the form.',
126
+ layout: 'horizontal',
127
+ },
128
+ options: [
129
+ {
130
+ label: 'Message',
131
+ value: 'message',
132
+ },
133
+ {
134
+ label: 'Redirect',
135
+ value: 'redirect',
136
+ },
137
+ ],
138
+ defaultValue: 'message',
139
+ },
140
+ {
141
+ name: 'confirmationMessage',
142
+ type: 'richText',
143
+ localized: true,
144
+ required: true,
145
+ admin: {
146
+ condition: function (_, siblingData) { return (siblingData === null || siblingData === void 0 ? void 0 : siblingData.confirmationType) === 'message'; },
147
+ },
148
+ },
149
+ redirect,
150
+ {
151
+ name: 'emails',
152
+ type: 'array',
153
+ admin: {
154
+ description: "Send custom emails when the form submits. Use comma separated lists to send the same email to multiple recipients. To reference a value from this form, wrap that field's name with double curly brackets, i.e. {{firstName}}.",
155
+ },
156
+ fields: [
157
+ {
158
+ type: 'row',
159
+ fields: [
160
+ {
161
+ type: 'text',
162
+ name: 'emailTo',
163
+ label: 'Email To',
164
+ admin: {
165
+ width: '100%',
166
+ placeholder: '"Email Sender" <sender@email.com>',
167
+ },
168
+ },
169
+ {
170
+ type: 'text',
171
+ name: 'cc',
172
+ label: 'CC',
173
+ admin: {
174
+ width: '50%',
175
+ },
176
+ },
177
+ {
178
+ type: 'text',
179
+ name: 'bcc',
180
+ label: 'BCC',
181
+ admin: {
182
+ width: '50%',
183
+ },
184
+ },
185
+ ],
186
+ },
187
+ {
188
+ type: 'row',
189
+ fields: [
190
+ {
191
+ type: 'text',
192
+ name: 'replyTo',
193
+ label: 'Reply To',
194
+ admin: {
195
+ width: '50%',
196
+ placeholder: '"Reply To" <reply-to@email.com>',
197
+ },
198
+ },
199
+ {
200
+ type: 'text',
201
+ name: 'emailFrom',
202
+ label: 'Email From',
203
+ admin: {
204
+ width: '50%',
205
+ placeholder: '"Email From" <email-from@email.com>',
206
+ },
207
+ },
208
+ ],
209
+ },
210
+ {
211
+ type: 'text',
212
+ name: 'subject',
213
+ label: 'Subject',
214
+ defaultValue: "You've received a new message.",
215
+ required: true,
216
+ localized: true,
217
+ },
218
+ {
219
+ type: 'richText',
220
+ name: 'message',
221
+ label: 'Message',
222
+ localized: true,
223
+ admin: {
224
+ description: 'Enter the message that should be sent in this email.',
225
+ },
226
+ },
227
+ ],
228
+ }
229
+ ], (((_d = formConfig === null || formConfig === void 0 ? void 0 : formConfig.formOverrides) === null || _d === void 0 ? void 0 : _d.fields) || []), true) });
230
+ return config;
231
+ };
232
+ exports.generateFormCollection = generateFormCollection;
233
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/collections/Forms/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA6B;AAI7B,mCAAiC;AAEjC,+CAA+C;AACxC,IAAM,sBAAsB,GAAG,UAAC,UAAwB;;IAC7D,IAAM,QAAQ,GAAU;QACtB,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,OAAO;QACb,KAAK,EAAE;YACL,UAAU,EAAE,IAAI;YAChB,SAAS,EAAE,UAAC,CAAC,EAAE,WAAW,IAAK,OAAA,CAAA,WA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,MAAM,KAAI,EAAE,CAAC,UAE/C,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAjOY,QAAA,sBAAsB,0BAiOlC"}
@@ -0,0 +1,6 @@
1
+ import type { Config } from 'payload/config';
2
+ import type { PluginConfig } from './types';
3
+ export { fields } from './collections/Forms/fields';
4
+ export { getPaymentTotal } from './utilities/getPaymentTotal';
5
+ declare const FormBuilder: (incomingFormConfig: PluginConfig) => (config: Config) => Config;
6
+ export default FormBuilder;
package/dist/index.js ADDED
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
+ if (ar || !(i in from)) {
16
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
+ ar[i] = from[i];
18
+ }
19
+ }
20
+ return to.concat(ar || Array.prototype.slice.call(from));
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.getPaymentTotal = exports.fields = void 0;
24
+ var Forms_1 = require("./collections/Forms");
25
+ var FormSubmissions_1 = require("./collections/FormSubmissions");
26
+ var fields_1 = require("./collections/Forms/fields");
27
+ Object.defineProperty(exports, "fields", { enumerable: true, get: function () { return fields_1.fields; } });
28
+ var getPaymentTotal_1 = require("./utilities/getPaymentTotal");
29
+ Object.defineProperty(exports, "getPaymentTotal", { enumerable: true, get: function () { return getPaymentTotal_1.getPaymentTotal; } });
30
+ var FormBuilder = function (incomingFormConfig) {
31
+ return function (config) {
32
+ var formConfig = __assign(__assign({}, incomingFormConfig), { fields: __assign({ text: true, textarea: true, select: true, email: true, state: true, country: true, number: true, checkbox: true, message: true, payment: false }, incomingFormConfig.fields) });
33
+ return __assign(__assign({}, config), {
34
+ // admin: {
35
+ // ...config.admin,
36
+ // webpack: (webpackConfig) => ({
37
+ // ...webpackConfig,
38
+ // resolve: {
39
+ // ...webpackConfig.resolve,
40
+ // alias: {
41
+ // ...webpackConfig.resolve.alias,
42
+ // [path.resolve(__dirname, 'collections/FormSubmissions/hooks/sendEmail.ts')]: path.resolve(__dirname, 'mocks/serverModule.js'),
43
+ // [path.resolve(__dirname, 'collections/FormSubmissions/hooks/createCharge.ts')]: path.resolve(__dirname, 'mocks/serverModule.js'),
44
+ // },
45
+ // },
46
+ // })
47
+ // },
48
+ collections: __spreadArray(__spreadArray([], ((config === null || config === void 0 ? void 0 : config.collections) || []), true), [
49
+ (0, Forms_1.generateFormCollection)(formConfig),
50
+ (0, FormSubmissions_1.generateSubmissionCollection)(formConfig),
51
+ ], false) });
52
+ };
53
+ };
54
+ exports.default = FormBuilder;
55
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAEA,6CAA4D;AAC5D,iEAA4E;AAG5E,qDAAmD;AAA1C,gGAAA,MAAM,OAAA;AACf,+DAA6D;AAApD,kHAAA,eAAe,OAAA;AAExB,IAAM,WAAW,GACf,UAAC,kBAAgC;IACjC,OAAA,UAAC,MAAc;QACb,IAAM,UAAU,yBACX,kBAAkB,KACrB,MAAM,aACJ,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,IAAI,EACd,MAAM,EAAE,IAAI,EACZ,KAAK,EAAE,IAAI,EACX,KAAK,EAAE,IAAI,EACX,OAAO,EAAE,IAAI,EACb,MAAM,EAAE,IAAI,EACZ,QAAQ,EAAE,IAAI,EACd,OAAO,EAAE,IAAI,EACb,OAAO,EAAE,KAAK,IACX,kBAAkB,CAAC,MAAM,IAE/B,CAAA;QAED,6BACK,MAAM;YACT,WAAW;YACX,qBAAqB;YACrB,mCAAmC;YACnC,wBAAwB;YACxB,iBAAiB;YACjB,kCAAkC;YAClC,iBAAiB;YACjB,0CAA0C;YAC1C,yIAAyI;YACzI,4IAA4I;YAC5I,WAAW;YACX,SAAS;YACT,OAAO;YACP,KAAK;YACL,WAAW,kCACN,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,WAAW,KAAI,EAAE,CAAC;gBAC9B,IAAA,8BAAsB,EAAC,UAAU,CAAC;gBAClC,IAAA,8CAA4B,EAAC,UAAU,CAAC;yBAE3C;IACH,CAAC;AAxCD,CAwCC,CAAA;AAEH,kBAAe,WAAW,CAAA"}
@@ -0,0 +1,2 @@
1
+ declare const _default: {};
2
+ export default _default;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = {};
4
+ //# sourceMappingURL=serverModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serverModule.js","sourceRoot":"","sources":["../../src/mocks/serverModule.js"],"names":[],"mappings":";;AAAA,kBAAe,EAAE,CAAA"}
@@ -0,0 +1,174 @@
1
+ import type { Block, CollectionConfig, Field } from 'payload/types';
2
+ export interface BlockConfig {
3
+ block: Block;
4
+ validate?: (value: unknown) => boolean | string;
5
+ }
6
+ export declare function isValidBlockConfig(blockConfig: BlockConfig | string): blockConfig is BlockConfig;
7
+ export interface FieldValues {
8
+ [key: string]: string | number | boolean | null | undefined;
9
+ }
10
+ export type PaymentFieldConfig = Partial<Field> & {
11
+ paymentProcessor: Partial<SelectField>;
12
+ };
13
+ export type FieldConfig = Partial<Field> | PaymentFieldConfig;
14
+ export interface FieldsConfig {
15
+ select?: boolean | FieldConfig;
16
+ text?: boolean | FieldConfig;
17
+ textarea?: boolean | FieldConfig;
18
+ email?: boolean | FieldConfig;
19
+ state?: boolean | FieldConfig;
20
+ country?: boolean | FieldConfig;
21
+ checkbox?: boolean | FieldConfig;
22
+ number?: boolean | FieldConfig;
23
+ message?: boolean | FieldConfig;
24
+ payment?: boolean | FieldConfig;
25
+ [key: string]: boolean | FieldConfig | undefined;
26
+ }
27
+ export type BeforeEmail = (emails: FormattedEmail[]) => FormattedEmail[] | Promise<FormattedEmail[]>;
28
+ export type HandlePayment = (data: any) => void;
29
+ export interface PluginConfig {
30
+ fields?: FieldsConfig;
31
+ formSubmissionOverrides?: Partial<CollectionConfig>;
32
+ formOverrides?: Partial<CollectionConfig>;
33
+ beforeEmail?: BeforeEmail;
34
+ handlePayment?: HandlePayment;
35
+ redirectRelationships?: string[];
36
+ }
37
+ export interface TextField {
38
+ blockType: 'text';
39
+ blockName?: string;
40
+ width?: number;
41
+ name: string;
42
+ label?: string;
43
+ defaultValue?: string;
44
+ required?: boolean;
45
+ }
46
+ export interface TextAreaField {
47
+ blockType: 'textarea';
48
+ blockName?: string;
49
+ width?: number;
50
+ name: string;
51
+ label?: string;
52
+ defaultValue?: string;
53
+ required?: boolean;
54
+ }
55
+ export interface SelectFieldOption {
56
+ label: string;
57
+ value: string;
58
+ }
59
+ export interface SelectField {
60
+ blockType: 'select';
61
+ blockName?: string;
62
+ width?: number;
63
+ name: string;
64
+ label?: string;
65
+ defaultValue?: string;
66
+ required?: boolean;
67
+ options: SelectFieldOption[];
68
+ }
69
+ export interface PriceCondition {
70
+ fieldToUse: string;
71
+ condition: 'equals' | 'notEquals' | 'hasValue';
72
+ valueForCondition: string;
73
+ operator: 'add' | 'subtract' | 'multiply' | 'divide';
74
+ valueType: 'static' | 'valueOfField';
75
+ valueForOperator: string | number;
76
+ }
77
+ export interface PaymentField {
78
+ blockType: 'payment';
79
+ blockName?: string;
80
+ width?: number;
81
+ name: string;
82
+ label?: string;
83
+ defaultValue?: string;
84
+ required?: boolean;
85
+ paymentProcessor: string;
86
+ basePrice: number;
87
+ priceConditions: PriceCondition[];
88
+ }
89
+ export interface EmailField {
90
+ blockType: 'email';
91
+ blockName?: string;
92
+ width?: number;
93
+ name: string;
94
+ label?: string;
95
+ defaultValue?: string;
96
+ required?: boolean;
97
+ }
98
+ export interface StateField {
99
+ blockType: 'state';
100
+ blockName?: string;
101
+ width?: number;
102
+ name: string;
103
+ label?: string;
104
+ defaultValue?: string;
105
+ required?: boolean;
106
+ }
107
+ export interface CountryField {
108
+ blockType: 'country';
109
+ blockName?: string;
110
+ width?: number;
111
+ name: string;
112
+ label?: string;
113
+ defaultValue?: string;
114
+ required?: boolean;
115
+ }
116
+ export interface CheckboxField {
117
+ blockType: 'checkbox';
118
+ blockName?: string;
119
+ width?: number;
120
+ name: string;
121
+ label?: string;
122
+ defaultValue?: boolean;
123
+ required?: boolean;
124
+ }
125
+ export interface MessageField {
126
+ blockType: 'message';
127
+ blockName?: string;
128
+ message: unknown;
129
+ }
130
+ export type FormFieldBlock = TextField | TextAreaField | SelectField | EmailField | StateField | CountryField | CheckboxField | MessageField | PaymentField;
131
+ export interface Email {
132
+ emailTo: string;
133
+ emailFrom: string;
134
+ cc?: string;
135
+ bcc?: string;
136
+ replyTo?: string;
137
+ subject: string;
138
+ message?: any;
139
+ }
140
+ export interface FormattedEmail {
141
+ to: string;
142
+ cc?: string;
143
+ bcc?: string;
144
+ from: string;
145
+ subject: string;
146
+ html: string;
147
+ replyTo: string;
148
+ }
149
+ export interface Redirect {
150
+ type: 'reference' | 'custom';
151
+ reference?: {
152
+ relationTo: string;
153
+ value: string | unknown;
154
+ };
155
+ url: string;
156
+ }
157
+ export interface Form {
158
+ id: string;
159
+ title: string;
160
+ fields: FormFieldBlock[];
161
+ submitButtonLabel?: string;
162
+ confirmationType: 'message' | 'redirect';
163
+ confirmationMessage?: any;
164
+ redirect?: Redirect;
165
+ emails: Email[];
166
+ }
167
+ export interface SubmissionValue {
168
+ field: string;
169
+ value: unknown;
170
+ }
171
+ export interface FormSubmission {
172
+ form: string | Form;
173
+ submissionData: SubmissionValue[];
174
+ }
package/dist/types.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isValidBlockConfig = void 0;
4
+ function isValidBlockConfig(blockConfig) {
5
+ var _a, _b;
6
+ return (typeof blockConfig !== 'string' &&
7
+ typeof ((_a = blockConfig === null || blockConfig === void 0 ? void 0 : blockConfig.block) === null || _a === void 0 ? void 0 : _a.slug) === 'string' &&
8
+ Array.isArray((_b = blockConfig === null || blockConfig === void 0 ? void 0 : blockConfig.block) === null || _b === void 0 ? void 0 : _b.fields));
9
+ }
10
+ exports.isValidBlockConfig = isValidBlockConfig;
11
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAOA,SAAgB,kBAAkB,CAAC,WAAiC;;IAClE,OAAO,CACL,OAAO,WAAW,KAAK,QAAQ;QAC/B,OAAO,CAAA,MAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,KAAK,0CAAE,IAAI,CAAA,KAAK,QAAQ;QAC5C,KAAK,CAAC,OAAO,CAAC,MAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,KAAK,0CAAE,MAAM,CAAC,CAC1C,CAAA;AACH,CAAC;AAND,gDAMC"}
@@ -0,0 +1,4 @@
1
+ import type { FieldValues, PaymentField } from '../types';
2
+ export declare const getPaymentTotal: (args: Partial<PaymentField> & {
3
+ fieldValues: FieldValues;
4
+ }) => number;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPaymentTotal = void 0;
4
+ var getPaymentTotal = function (args) {
5
+ var _a = args.basePrice, basePrice = _a === void 0 ? 0 : _a, priceConditions = args.priceConditions, fieldValues = args.fieldValues;
6
+ var total = basePrice;
7
+ if (Array.isArray(priceConditions) && priceConditions.length > 0) {
8
+ priceConditions.forEach(function (priceCondition) {
9
+ var condition = priceCondition.condition, valueForCondition = priceCondition.valueForCondition, fieldToUse = priceCondition.fieldToUse, operator = priceCondition.operator, valueType = priceCondition.valueType, valueForOperator = priceCondition.valueForOperator;
10
+ var valueOfField = fieldValues === null || fieldValues === void 0 ? void 0 : fieldValues[fieldToUse];
11
+ if (valueOfField) {
12
+ if (condition === 'hasValue' ||
13
+ (condition === 'equals' && valueOfField === valueForCondition) ||
14
+ (condition === 'notEquals' && valueOfField !== valueForCondition)) {
15
+ var valueToUse = Number(valueType === 'valueOfField' ? valueOfField : valueForOperator);
16
+ switch (operator) {
17
+ case 'add': {
18
+ total += valueToUse;
19
+ break;
20
+ }
21
+ case 'subtract': {
22
+ total -= valueToUse;
23
+ break;
24
+ }
25
+ case 'multiply': {
26
+ total *= valueToUse;
27
+ break;
28
+ }
29
+ case 'divide': {
30
+ total /= valueToUse;
31
+ break;
32
+ }
33
+ default: {
34
+ break;
35
+ }
36
+ }
37
+ }
38
+ }
39
+ });
40
+ }
41
+ return total;
42
+ };
43
+ exports.getPaymentTotal = getPaymentTotal;
44
+ //# sourceMappingURL=getPaymentTotal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPaymentTotal.js","sourceRoot":"","sources":["../../src/utilities/getPaymentTotal.ts"],"names":[],"mappings":";;;AAEO,IAAM,eAAe,GAAG,UAC7B,IAEC;IAEO,IAAA,KAAgD,IAAI,UAAvC,EAAb,SAAS,mBAAG,CAAC,KAAA,EAAE,eAAe,GAAkB,IAAI,gBAAtB,EAAE,WAAW,GAAK,IAAI,YAAT,CAAS;IAE5D,IAAI,KAAK,GAAG,SAAS,CAAA;IAErB,IAAI,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE;QAChE,eAAe,CAAC,OAAO,CAAC,UAAC,cAA8B;YAC7C,IAAA,SAAS,GACf,cAAc,UADC,EAAE,iBAAiB,GAClC,cAAc,kBADoB,EAAE,UAAU,GAC9C,cAAc,WADgC,EAAE,QAAQ,GACxD,cAAc,SAD0C,EAAE,SAAS,GACnE,cAAc,UADqD,EAAE,gBAAgB,GACrF,cAAc,iBADuE,CACvE;YAEhB,IAAM,YAAY,GAAG,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAG,UAAU,CAAC,CAAA;YAE9C,IAAI,YAAY,EAAE;gBAChB,IACE,SAAS,KAAK,UAAU;oBACxB,CAAC,SAAS,KAAK,QAAQ,IAAI,YAAY,KAAK,iBAAiB,CAAC;oBAC9D,CAAC,SAAS,KAAK,WAAW,IAAI,YAAY,KAAK,iBAAiB,CAAC,EACjE;oBACA,IAAM,UAAU,GAAG,MAAM,CAAC,SAAS,KAAK,cAAc,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAA;oBACzF,QAAQ,QAAQ,EAAE;wBAChB,KAAK,KAAK,CAAC,CAAC;4BACV,KAAK,IAAI,UAAU,CAAA;4BACnB,MAAK;yBACN;wBACD,KAAK,UAAU,CAAC,CAAC;4BACf,KAAK,IAAI,UAAU,CAAA;4BACnB,MAAK;yBACN;wBACD,KAAK,UAAU,CAAC,CAAC;4BACf,KAAK,IAAI,UAAU,CAAA;4BACnB,MAAK;yBACN;wBACD,KAAK,QAAQ,CAAC,CAAC;4BACb,KAAK,IAAI,UAAU,CAAA;4BACnB,MAAK;yBACN;wBACD,OAAO,CAAC,CAAC;4BACP,MAAK;yBACN;qBACF;iBACF;aACF;QACH,CAAC,CAAC,CAAA;KACH;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAlDY,QAAA,eAAe,mBAkD3B"}
@@ -0,0 +1,7 @@
1
+ interface EmailVariable {
2
+ field: string;
3
+ value: string;
4
+ }
5
+ type EmailVariables = EmailVariable[];
6
+ export declare const replaceDoubleCurlys: (str: string, variables?: EmailVariables) => string;
7
+ export {};
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.replaceDoubleCurlys = void 0;
4
+ var replaceDoubleCurlys = function (str, variables) {
5
+ var regex = /{{(.+?)}}/g;
6
+ if (str && variables) {
7
+ return str.replace(regex, function (_, variable) {
8
+ var foundVariable = variables.find(function (_a) {
9
+ var fieldName = _a.field;
10
+ return variable === fieldName;
11
+ });
12
+ if (foundVariable)
13
+ return foundVariable.value;
14
+ return variable;
15
+ });
16
+ }
17
+ return str;
18
+ };
19
+ exports.replaceDoubleCurlys = replaceDoubleCurlys;
20
+ //# sourceMappingURL=replaceDoubleCurlys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replaceDoubleCurlys.js","sourceRoot":"","sources":["../../src/utilities/replaceDoubleCurlys.ts"],"names":[],"mappings":";;;AAOO,IAAM,mBAAmB,GAAG,UAAC,GAAW,EAAE,SAA0B;IACzE,IAAM,KAAK,GAAG,YAAY,CAAA;IAC1B,IAAI,GAAG,IAAI,SAAS,EAAE;QACpB,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,UAAC,CAAC,EAAE,QAAQ;YACpC,IAAM,aAAa,GAAG,SAAS,CAAC,IAAI,CAAC,UAAC,EAAoB;oBAAX,SAAS,WAAA;gBAAO,OAAA,QAAQ,KAAK,SAAS;YAAtB,CAAsB,CAAC,CAAA;YACtF,IAAI,aAAa;gBAAE,OAAO,aAAa,CAAC,KAAK,CAAA;YAC7C,OAAO,QAAQ,CAAA;QACjB,CAAC,CAAC,CAAA;KACH;IACD,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAVY,QAAA,mBAAmB,uBAU/B"}
@@ -0,0 +1,10 @@
1
+ interface Node {
2
+ bold?: boolean;
3
+ code?: boolean;
4
+ italic?: boolean;
5
+ type?: string;
6
+ url?: string;
7
+ children?: Node[];
8
+ }
9
+ export declare const serialize: (children?: Node[], submissionData?: any) => string | undefined;
10
+ export {};