@overmap-ai/core 1.0.33-revamp-forms-builder.16 → 1.0.33-revamp-forms-builder.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/forms/fields/NumberField/NumberField.d.ts +9 -1
- package/dist/forms/fields/constants.d.ts +9 -1
- package/dist/forms/fields/index.d.ts +0 -1
- package/dist/forms/fields/utils.d.ts +1 -3
- package/dist/overmap-core.js +221 -224
- package/dist/overmap-core.js.map +1 -1
- package/dist/overmap-core.umd.cjs +221 -224
- package/dist/overmap-core.umd.cjs.map +1 -1
- package/package.json +1 -1
|
@@ -5,7 +5,15 @@ import { ChangeEvent, ReactNode } from "react";
|
|
|
5
5
|
import { FontFamilyIcon } from "@radix-ui/react-icons";
|
|
6
6
|
import { ISerializedField, SerializedNumberField } from "../../typings";
|
|
7
7
|
export type NumberFieldValue = number | "";
|
|
8
|
-
export declare const emptyNumberField:
|
|
8
|
+
export declare const emptyNumberField: {
|
|
9
|
+
type: string;
|
|
10
|
+
minimum: number;
|
|
11
|
+
maximum: number;
|
|
12
|
+
integers: boolean;
|
|
13
|
+
label: string;
|
|
14
|
+
required: boolean;
|
|
15
|
+
description: string;
|
|
16
|
+
};
|
|
9
17
|
export interface NumberFieldOptions extends ChildFieldOptions<NumberFieldValue> {
|
|
10
18
|
maximum?: number;
|
|
11
19
|
minimum?: number;
|
|
@@ -25,7 +25,15 @@ export declare const FieldTypeToEmptyFieldMapping: {
|
|
|
25
25
|
required: boolean;
|
|
26
26
|
description: string;
|
|
27
27
|
};
|
|
28
|
-
readonly number:
|
|
28
|
+
readonly number: {
|
|
29
|
+
type: string;
|
|
30
|
+
minimum: number;
|
|
31
|
+
maximum: number;
|
|
32
|
+
integers: boolean;
|
|
33
|
+
label: string;
|
|
34
|
+
required: boolean;
|
|
35
|
+
description: string;
|
|
36
|
+
};
|
|
29
37
|
readonly boolean: {
|
|
30
38
|
type: string;
|
|
31
39
|
label: string;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { AnyField, ISchema, ISerializedOnlyField, SchemaMeta } from "./typings";
|
|
2
2
|
import { FieldSection } from "./FieldSection";
|
|
3
|
-
import { FieldValue,
|
|
3
|
+
import { FieldValue, ISerializedField, SerializedCondition } from "../typings";
|
|
4
4
|
import { UserFormRevision } from "../../typings";
|
|
5
|
-
import { FormikUserFormRevision } from "../builder";
|
|
6
5
|
/** Deserializes anything but a FieldSection.
|
|
7
6
|
* @see `deserialize` for most use cases
|
|
8
7
|
*/
|
|
@@ -12,5 +11,4 @@ export declare const deserialize: (serialized: ISerializedField) => AnyField | F
|
|
|
12
11
|
export type PartialFormRevision = Pick<UserFormRevision, "title" | "fields" | "description"> & Partial<UserFormRevision>;
|
|
13
12
|
export declare function formRevisionToSchema(formRevision: PartialFormRevision, meta?: Partial<SchemaMeta>): ISchema;
|
|
14
13
|
export declare function valueIsFile(v: FieldValue | Promise<File>[] | undefined): v is File[] | Promise<File>[];
|
|
15
|
-
export declare const valueIsFormikUserFormRevision: (form: FormikUserFormRevision | Form) => form is FormikUserFormRevision;
|
|
16
14
|
export declare function isConditionMet<TValue extends FieldValue | Promise<File>[]>(condition: TValue extends FieldValue ? SerializedCondition<TValue> | null : null, value: TValue): boolean;
|
package/dist/overmap-core.js
CHANGED
|
@@ -8126,6 +8126,173 @@ const NumberInput$1 = memo(function NumberInput2(props) {
|
|
|
8126
8126
|
}
|
|
8127
8127
|
) }) });
|
|
8128
8128
|
});
|
|
8129
|
+
const emptyNumberField = {
|
|
8130
|
+
...emptyBaseField,
|
|
8131
|
+
type: "number",
|
|
8132
|
+
minimum: Number.MIN_SAFE_INTEGER,
|
|
8133
|
+
maximum: Number.MAX_SAFE_INTEGER,
|
|
8134
|
+
integers: false
|
|
8135
|
+
};
|
|
8136
|
+
const valueIsFormikUserFormRevision$1 = (form) => {
|
|
8137
|
+
return "fields" in form;
|
|
8138
|
+
};
|
|
8139
|
+
const _NumberField = class _NumberField extends BaseField {
|
|
8140
|
+
constructor(options) {
|
|
8141
|
+
const {
|
|
8142
|
+
minimum = Number.MIN_SAFE_INTEGER,
|
|
8143
|
+
maximum = Number.MAX_SAFE_INTEGER,
|
|
8144
|
+
integers = false,
|
|
8145
|
+
...base
|
|
8146
|
+
} = options;
|
|
8147
|
+
super({ ...base, type: "number" });
|
|
8148
|
+
__publicField(this, "minimum");
|
|
8149
|
+
__publicField(this, "maximum");
|
|
8150
|
+
__publicField(this, "integers");
|
|
8151
|
+
this.minimum = minimum;
|
|
8152
|
+
this.maximum = maximum;
|
|
8153
|
+
this.integers = integers;
|
|
8154
|
+
}
|
|
8155
|
+
getValueFromChangeEvent(event) {
|
|
8156
|
+
const number = Number.parseFloat(event.target.value);
|
|
8157
|
+
if (Number.isNaN(number))
|
|
8158
|
+
return "";
|
|
8159
|
+
return number;
|
|
8160
|
+
}
|
|
8161
|
+
static getFieldCreationSchema(parentPath = "") {
|
|
8162
|
+
const path = parentPath && `${parentPath}.`;
|
|
8163
|
+
return [
|
|
8164
|
+
{
|
|
8165
|
+
field: new _NumberField({
|
|
8166
|
+
label: "Minimum",
|
|
8167
|
+
description: "Minimum value",
|
|
8168
|
+
integers: true,
|
|
8169
|
+
required: false,
|
|
8170
|
+
identifier: `${path}minimum`,
|
|
8171
|
+
formValidators: [this._validateMin(parentPath)]
|
|
8172
|
+
}),
|
|
8173
|
+
showDirectly: false
|
|
8174
|
+
},
|
|
8175
|
+
{
|
|
8176
|
+
field: new _NumberField({
|
|
8177
|
+
label: "Maximum",
|
|
8178
|
+
description: "Maximum value",
|
|
8179
|
+
integers: true,
|
|
8180
|
+
required: false,
|
|
8181
|
+
identifier: `${path}maximum`,
|
|
8182
|
+
formValidators: [this._validateMax(parentPath)]
|
|
8183
|
+
}),
|
|
8184
|
+
showDirectly: false
|
|
8185
|
+
},
|
|
8186
|
+
{
|
|
8187
|
+
field: new BooleanField({
|
|
8188
|
+
label: "Integers",
|
|
8189
|
+
description: "Whole numbers only",
|
|
8190
|
+
required: false,
|
|
8191
|
+
identifier: `${path}integers`
|
|
8192
|
+
}),
|
|
8193
|
+
showDirectly: false
|
|
8194
|
+
}
|
|
8195
|
+
];
|
|
8196
|
+
}
|
|
8197
|
+
getFieldValidators() {
|
|
8198
|
+
const validators = super.getFieldValidators();
|
|
8199
|
+
const min = this.minimum;
|
|
8200
|
+
const max = this.maximum;
|
|
8201
|
+
if (typeof min === "number") {
|
|
8202
|
+
validators.push((value) => {
|
|
8203
|
+
if (typeof value === "number" && value < min) {
|
|
8204
|
+
return `Must be at least ${this.minimum}.`;
|
|
8205
|
+
}
|
|
8206
|
+
});
|
|
8207
|
+
}
|
|
8208
|
+
if (typeof max === "number") {
|
|
8209
|
+
validators.push((value) => {
|
|
8210
|
+
if (typeof value === "number" && value > max) {
|
|
8211
|
+
return `Must be at most ${this.maximum}.`;
|
|
8212
|
+
}
|
|
8213
|
+
});
|
|
8214
|
+
}
|
|
8215
|
+
if (this.integers) {
|
|
8216
|
+
validators.push((value) => {
|
|
8217
|
+
if (typeof value === "number" && !Number.isInteger(value)) {
|
|
8218
|
+
return "Must be a whole number.";
|
|
8219
|
+
}
|
|
8220
|
+
});
|
|
8221
|
+
}
|
|
8222
|
+
return validators;
|
|
8223
|
+
}
|
|
8224
|
+
serialize() {
|
|
8225
|
+
return {
|
|
8226
|
+
...super._serialize(),
|
|
8227
|
+
minimum: this.minimum,
|
|
8228
|
+
maximum: this.maximum,
|
|
8229
|
+
integers: this.integers
|
|
8230
|
+
};
|
|
8231
|
+
}
|
|
8232
|
+
static deserialize(data) {
|
|
8233
|
+
if (data.type !== "number")
|
|
8234
|
+
throw new Error("Type mismatch.");
|
|
8235
|
+
return new _NumberField(data);
|
|
8236
|
+
}
|
|
8237
|
+
getInput(props) {
|
|
8238
|
+
return /* @__PURE__ */ jsx(NumberInput$1, { field: this, ...props });
|
|
8239
|
+
}
|
|
8240
|
+
};
|
|
8241
|
+
__publicField(_NumberField, "fieldTypeName", "Number");
|
|
8242
|
+
__publicField(_NumberField, "fieldTypeDescription", "Allows specifying a number within a given range.");
|
|
8243
|
+
__publicField(_NumberField, "Icon", FontFamilyIcon);
|
|
8244
|
+
__publicField(_NumberField, "_validateMin", (path) => (value, allValues) => {
|
|
8245
|
+
const field = valueIsFormikUserFormRevision$1(allValues) ? get(allValues, path) : allValues;
|
|
8246
|
+
if (typeof field.maximum === "number" && typeof value === "number" && field.maximum < value) {
|
|
8247
|
+
return "Minimum cannot be greater than minimum.";
|
|
8248
|
+
}
|
|
8249
|
+
return null;
|
|
8250
|
+
});
|
|
8251
|
+
__publicField(_NumberField, "_validateMax", (path) => (value, allValues) => {
|
|
8252
|
+
const field = valueIsFormikUserFormRevision$1(allValues) ? get(allValues, path) : allValues;
|
|
8253
|
+
if (typeof field.minimum === "number" && typeof value === "number" && field.minimum > value) {
|
|
8254
|
+
return "Maximum cannot be less than minimum.";
|
|
8255
|
+
}
|
|
8256
|
+
return null;
|
|
8257
|
+
});
|
|
8258
|
+
let NumberField = _NumberField;
|
|
8259
|
+
const DateInput = memo(function DateInput2(props) {
|
|
8260
|
+
const [{ inputId, labelId, size, severity, helpText, label, fieldProps }, rest] = useFormikInput(props);
|
|
8261
|
+
const color = useSeverityColor(severity);
|
|
8262
|
+
const value = fieldProps.value ? fieldProps.value.split("T")[0] : "";
|
|
8263
|
+
return /* @__PURE__ */ jsx(InputWithLabelAndHelpText, { helpText, severity, children: /* @__PURE__ */ jsx(InputWithLabel, { size, severity, inputId, labelId, label, children: /* @__PURE__ */ jsx(TextField$1.Input, { ...rest, ...fieldProps, type: "date", id: inputId, color, value }) }) });
|
|
8264
|
+
});
|
|
8265
|
+
const emptyDateField = {
|
|
8266
|
+
...emptyBaseField,
|
|
8267
|
+
type: "date"
|
|
8268
|
+
};
|
|
8269
|
+
const _DateField = class _DateField extends BaseField {
|
|
8270
|
+
constructor(options) {
|
|
8271
|
+
super({ ...options, type: "date" });
|
|
8272
|
+
__publicField(this, "onlyValidateAfterTouched", false);
|
|
8273
|
+
}
|
|
8274
|
+
serialize() {
|
|
8275
|
+
return super._serialize();
|
|
8276
|
+
}
|
|
8277
|
+
getValueFromChangeEvent(event) {
|
|
8278
|
+
return new Date(event.target.value).toISOString();
|
|
8279
|
+
}
|
|
8280
|
+
static deserialize(data) {
|
|
8281
|
+
if (data.type !== "date")
|
|
8282
|
+
throw new Error("Type mismatch.");
|
|
8283
|
+
return new _DateField(data);
|
|
8284
|
+
}
|
|
8285
|
+
getInput(props) {
|
|
8286
|
+
return /* @__PURE__ */ jsx(DateInput, { field: this, ...props });
|
|
8287
|
+
}
|
|
8288
|
+
};
|
|
8289
|
+
__publicField(_DateField, "fieldTypeName", "Date");
|
|
8290
|
+
__publicField(_DateField, "fieldTypeDescription", "Allows specifying a date.");
|
|
8291
|
+
__publicField(_DateField, "Icon", CalendarIcon);
|
|
8292
|
+
let DateField = _DateField;
|
|
8293
|
+
const valueIsFormikUserFormRevision = (form) => {
|
|
8294
|
+
return "fields" in form;
|
|
8295
|
+
};
|
|
8129
8296
|
class StringOrTextField extends BaseField {
|
|
8130
8297
|
constructor(options) {
|
|
8131
8298
|
const { minLength, maxLength = 5e3, ...base } = options;
|
|
@@ -8325,40 +8492,6 @@ __publicField(_TextField, "fieldTypeName", "Paragraph");
|
|
|
8325
8492
|
__publicField(_TextField, "fieldTypeDescription", "Paragraph fields can hold up to 5000 characters and can have multiple lines.");
|
|
8326
8493
|
__publicField(_TextField, "Icon", RowsIcon);
|
|
8327
8494
|
let TextField = _TextField;
|
|
8328
|
-
const DateInput = memo(function DateInput2(props) {
|
|
8329
|
-
const [{ inputId, labelId, size, severity, helpText, label, fieldProps }, rest] = useFormikInput(props);
|
|
8330
|
-
const color = useSeverityColor(severity);
|
|
8331
|
-
const value = fieldProps.value ? fieldProps.value.split("T")[0] : "";
|
|
8332
|
-
return /* @__PURE__ */ jsx(InputWithLabelAndHelpText, { helpText, severity, children: /* @__PURE__ */ jsx(InputWithLabel, { size, severity, inputId, labelId, label, children: /* @__PURE__ */ jsx(TextField$1.Input, { ...rest, ...fieldProps, type: "date", id: inputId, color, value }) }) });
|
|
8333
|
-
});
|
|
8334
|
-
const emptyDateField = {
|
|
8335
|
-
...emptyBaseField,
|
|
8336
|
-
type: "date"
|
|
8337
|
-
};
|
|
8338
|
-
const _DateField = class _DateField extends BaseField {
|
|
8339
|
-
constructor(options) {
|
|
8340
|
-
super({ ...options, type: "date" });
|
|
8341
|
-
__publicField(this, "onlyValidateAfterTouched", false);
|
|
8342
|
-
}
|
|
8343
|
-
serialize() {
|
|
8344
|
-
return super._serialize();
|
|
8345
|
-
}
|
|
8346
|
-
getValueFromChangeEvent(event) {
|
|
8347
|
-
return new Date(event.target.value).toISOString();
|
|
8348
|
-
}
|
|
8349
|
-
static deserialize(data) {
|
|
8350
|
-
if (data.type !== "date")
|
|
8351
|
-
throw new Error("Type mismatch.");
|
|
8352
|
-
return new _DateField(data);
|
|
8353
|
-
}
|
|
8354
|
-
getInput(props) {
|
|
8355
|
-
return /* @__PURE__ */ jsx(DateInput, { field: this, ...props });
|
|
8356
|
-
}
|
|
8357
|
-
};
|
|
8358
|
-
__publicField(_DateField, "fieldTypeName", "Date");
|
|
8359
|
-
__publicField(_DateField, "fieldTypeDescription", "Allows specifying a date.");
|
|
8360
|
-
__publicField(_DateField, "Icon", CalendarIcon);
|
|
8361
|
-
let DateField = _DateField;
|
|
8362
8495
|
const SelectInput = memo(function SelectInput2(props) {
|
|
8363
8496
|
const [{ inputId, labelId, size, severity, helpText, label, fieldProps, field }, rest] = useFormikInput(props);
|
|
8364
8497
|
const { onChange, onBlur } = fieldProps;
|
|
@@ -8884,6 +9017,16 @@ __publicField(_MultiSelectField, "fieldTypeName", "Multi-select");
|
|
|
8884
9017
|
__publicField(_MultiSelectField, "fieldTypeDescription", "Allows the user to select a multiple options from a list of options.");
|
|
8885
9018
|
__publicField(_MultiSelectField, "Icon", CheckboxIcon);
|
|
8886
9019
|
let MultiSelectField = _MultiSelectField;
|
|
9020
|
+
const FieldInputCloner = memo(function FieldInputCloner2({ field, ...props }) {
|
|
9021
|
+
const [{ value: identifier }] = useField(field.options.clonedFieldIdentifier);
|
|
9022
|
+
const deserializedField = useMemo(() => {
|
|
9023
|
+
const options = field.options.getFieldToClone(identifier);
|
|
9024
|
+
if (!options)
|
|
9025
|
+
return null;
|
|
9026
|
+
return deserialize(options);
|
|
9027
|
+
}, [field.options, identifier]);
|
|
9028
|
+
return useFieldInput(deserializedField, props);
|
|
9029
|
+
});
|
|
8887
9030
|
const emptyCustomField = {
|
|
8888
9031
|
...emptyBaseField,
|
|
8889
9032
|
type: "custom"
|
|
@@ -8907,6 +9050,11 @@ class CustomField extends BaseField {
|
|
|
8907
9050
|
}
|
|
8908
9051
|
__publicField(CustomField, "fieldTypeName", "Custom");
|
|
8909
9052
|
__publicField(CustomField, "fieldTypeDescription", "Allows re-rendering of field already in the form");
|
|
9053
|
+
class FieldInputClonerField extends CustomField {
|
|
9054
|
+
constructor(options) {
|
|
9055
|
+
super(options, FieldInputCloner);
|
|
9056
|
+
}
|
|
9057
|
+
}
|
|
8910
9058
|
const previewImage = "_previewImage_1ig84_1";
|
|
8911
9059
|
const styles$4 = {
|
|
8912
9060
|
previewImage
|
|
@@ -9194,20 +9342,45 @@ const FieldTypeToEmptyFieldMapping = {
|
|
|
9194
9342
|
"multi-string": emptyMultiStringField,
|
|
9195
9343
|
"multi-select": emptyMultiSelectField
|
|
9196
9344
|
};
|
|
9197
|
-
const
|
|
9198
|
-
const
|
|
9199
|
-
const
|
|
9200
|
-
|
|
9201
|
-
|
|
9202
|
-
|
|
9203
|
-
|
|
9204
|
-
|
|
9205
|
-
|
|
9206
|
-
});
|
|
9207
|
-
class FieldInputClonerField extends CustomField {
|
|
9208
|
-
constructor(options) {
|
|
9209
|
-
super(options, FieldInputCloner);
|
|
9345
|
+
const deserializeField = (serializedField) => {
|
|
9346
|
+
const fieldType = serializedField.type;
|
|
9347
|
+
const fieldCls = FieldTypeToClsMapping[fieldType];
|
|
9348
|
+
console.log(serializedField, fieldType, fieldCls);
|
|
9349
|
+
return fieldCls.deserialize(serializedField);
|
|
9350
|
+
};
|
|
9351
|
+
const deserialize = (serialized) => {
|
|
9352
|
+
if (serialized.type === "section") {
|
|
9353
|
+
return FieldSection.deserialize(serialized);
|
|
9210
9354
|
}
|
|
9355
|
+
return deserializeField(serialized);
|
|
9356
|
+
};
|
|
9357
|
+
function formRevisionToSchema(formRevision, meta = {}) {
|
|
9358
|
+
const { readonly = false } = meta;
|
|
9359
|
+
return {
|
|
9360
|
+
title: formRevision.title,
|
|
9361
|
+
description: formRevision.description,
|
|
9362
|
+
fields: formRevision.fields.map((serializedField) => deserialize(serializedField)),
|
|
9363
|
+
meta: { readonly }
|
|
9364
|
+
};
|
|
9365
|
+
}
|
|
9366
|
+
function valueIsFile(v) {
|
|
9367
|
+
return Array.isArray(v) && v.some((v2) => v2 instanceof File || v2 instanceof Promise);
|
|
9368
|
+
}
|
|
9369
|
+
function isConditionMet(condition, value) {
|
|
9370
|
+
if (!condition)
|
|
9371
|
+
return true;
|
|
9372
|
+
if (valueIsFile(value) || valueIsFile(condition.value))
|
|
9373
|
+
throw new Error("Conditions do not support file uploads");
|
|
9374
|
+
const valueAsPrimitive = Array.isArray(value) ? value.map((v) => typeof v === "string" ? v : v.value) : value;
|
|
9375
|
+
const valueToCompare = Array.isArray(condition.value) ? condition.value.map((v) => typeof v === "string" ? v : v.value) : condition.value;
|
|
9376
|
+
if (Array.isArray(valueToCompare) && Array.isArray(valueAsPrimitive)) {
|
|
9377
|
+
for (const v of valueToCompare) {
|
|
9378
|
+
if (!valueAsPrimitive.includes(v))
|
|
9379
|
+
return false;
|
|
9380
|
+
}
|
|
9381
|
+
return true;
|
|
9382
|
+
}
|
|
9383
|
+
return valueToCompare === value;
|
|
9211
9384
|
}
|
|
9212
9385
|
const useFieldInput = (field, props) => {
|
|
9213
9386
|
return useMemo(() => {
|
|
@@ -9391,176 +9564,6 @@ const _FieldSection = class _FieldSection extends BaseFormElement {
|
|
|
9391
9564
|
__publicField(_FieldSection, "fieldTypeName", "Section");
|
|
9392
9565
|
__publicField(_FieldSection, "fieldTypeDescription", "Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");
|
|
9393
9566
|
let FieldSection = _FieldSection;
|
|
9394
|
-
const deserializeField = (serializedField) => {
|
|
9395
|
-
const fieldType = serializedField.type;
|
|
9396
|
-
const fieldCls = FieldTypeToClsMapping[fieldType];
|
|
9397
|
-
console.log(serializedField, fieldType, fieldCls);
|
|
9398
|
-
return fieldCls.deserialize(serializedField);
|
|
9399
|
-
};
|
|
9400
|
-
const deserialize = (serialized) => {
|
|
9401
|
-
if (serialized.type === "section") {
|
|
9402
|
-
return FieldSection.deserialize(serialized);
|
|
9403
|
-
}
|
|
9404
|
-
return deserializeField(serialized);
|
|
9405
|
-
};
|
|
9406
|
-
function formRevisionToSchema(formRevision, meta = {}) {
|
|
9407
|
-
const { readonly = false } = meta;
|
|
9408
|
-
return {
|
|
9409
|
-
title: formRevision.title,
|
|
9410
|
-
description: formRevision.description,
|
|
9411
|
-
fields: formRevision.fields.map((serializedField) => deserialize(serializedField)),
|
|
9412
|
-
meta: { readonly }
|
|
9413
|
-
};
|
|
9414
|
-
}
|
|
9415
|
-
function valueIsFile(v) {
|
|
9416
|
-
return Array.isArray(v) && v.some((v2) => v2 instanceof File || v2 instanceof Promise);
|
|
9417
|
-
}
|
|
9418
|
-
const valueIsFormikUserFormRevision = (form) => {
|
|
9419
|
-
return "fields" in form;
|
|
9420
|
-
};
|
|
9421
|
-
function isConditionMet(condition, value) {
|
|
9422
|
-
if (!condition)
|
|
9423
|
-
return true;
|
|
9424
|
-
if (valueIsFile(value) || valueIsFile(condition.value))
|
|
9425
|
-
throw new Error("Conditions do not support file uploads");
|
|
9426
|
-
const valueAsPrimitive = Array.isArray(value) ? value.map((v) => typeof v === "string" ? v : v.value) : value;
|
|
9427
|
-
const valueToCompare = Array.isArray(condition.value) ? condition.value.map((v) => typeof v === "string" ? v : v.value) : condition.value;
|
|
9428
|
-
if (Array.isArray(valueToCompare) && Array.isArray(valueAsPrimitive)) {
|
|
9429
|
-
for (const v of valueToCompare) {
|
|
9430
|
-
if (!valueAsPrimitive.includes(v))
|
|
9431
|
-
return false;
|
|
9432
|
-
}
|
|
9433
|
-
return true;
|
|
9434
|
-
}
|
|
9435
|
-
return valueToCompare === value;
|
|
9436
|
-
}
|
|
9437
|
-
const emptyNumberField = {
|
|
9438
|
-
...emptyBaseField,
|
|
9439
|
-
type: "number",
|
|
9440
|
-
minimum: Number.MIN_SAFE_INTEGER,
|
|
9441
|
-
maximum: Number.MAX_SAFE_INTEGER,
|
|
9442
|
-
integers: false
|
|
9443
|
-
};
|
|
9444
|
-
const _NumberField = class _NumberField extends BaseField {
|
|
9445
|
-
constructor(options) {
|
|
9446
|
-
const {
|
|
9447
|
-
minimum = Number.MIN_SAFE_INTEGER,
|
|
9448
|
-
maximum = Number.MAX_SAFE_INTEGER,
|
|
9449
|
-
integers = false,
|
|
9450
|
-
...base
|
|
9451
|
-
} = options;
|
|
9452
|
-
super({ ...base, type: "number" });
|
|
9453
|
-
__publicField(this, "minimum");
|
|
9454
|
-
__publicField(this, "maximum");
|
|
9455
|
-
__publicField(this, "integers");
|
|
9456
|
-
this.minimum = minimum;
|
|
9457
|
-
this.maximum = maximum;
|
|
9458
|
-
this.integers = integers;
|
|
9459
|
-
}
|
|
9460
|
-
getValueFromChangeEvent(event) {
|
|
9461
|
-
const number = Number.parseFloat(event.target.value);
|
|
9462
|
-
if (Number.isNaN(number))
|
|
9463
|
-
return "";
|
|
9464
|
-
return number;
|
|
9465
|
-
}
|
|
9466
|
-
static getFieldCreationSchema(parentPath = "") {
|
|
9467
|
-
const path = parentPath && `${parentPath}.`;
|
|
9468
|
-
return [
|
|
9469
|
-
{
|
|
9470
|
-
field: new _NumberField({
|
|
9471
|
-
label: "Minimum",
|
|
9472
|
-
description: "Minimum value",
|
|
9473
|
-
integers: true,
|
|
9474
|
-
required: false,
|
|
9475
|
-
identifier: `${path}minimum`,
|
|
9476
|
-
formValidators: [this._validateMin(parentPath)]
|
|
9477
|
-
}),
|
|
9478
|
-
showDirectly: false
|
|
9479
|
-
},
|
|
9480
|
-
{
|
|
9481
|
-
field: new _NumberField({
|
|
9482
|
-
label: "Maximum",
|
|
9483
|
-
description: "Maximum value",
|
|
9484
|
-
integers: true,
|
|
9485
|
-
required: false,
|
|
9486
|
-
identifier: `${path}maximum`,
|
|
9487
|
-
formValidators: [this._validateMax(parentPath)]
|
|
9488
|
-
}),
|
|
9489
|
-
showDirectly: false
|
|
9490
|
-
},
|
|
9491
|
-
{
|
|
9492
|
-
field: new BooleanField({
|
|
9493
|
-
label: "Integers",
|
|
9494
|
-
description: "Whole numbers only",
|
|
9495
|
-
required: false,
|
|
9496
|
-
identifier: `${path}integers`
|
|
9497
|
-
}),
|
|
9498
|
-
showDirectly: false
|
|
9499
|
-
}
|
|
9500
|
-
];
|
|
9501
|
-
}
|
|
9502
|
-
getFieldValidators() {
|
|
9503
|
-
const validators = super.getFieldValidators();
|
|
9504
|
-
const min = this.minimum;
|
|
9505
|
-
const max = this.maximum;
|
|
9506
|
-
if (typeof min === "number") {
|
|
9507
|
-
validators.push((value) => {
|
|
9508
|
-
if (typeof value === "number" && value < min) {
|
|
9509
|
-
return `Must be at least ${this.minimum}.`;
|
|
9510
|
-
}
|
|
9511
|
-
});
|
|
9512
|
-
}
|
|
9513
|
-
if (typeof max === "number") {
|
|
9514
|
-
validators.push((value) => {
|
|
9515
|
-
if (typeof value === "number" && value > max) {
|
|
9516
|
-
return `Must be at most ${this.maximum}.`;
|
|
9517
|
-
}
|
|
9518
|
-
});
|
|
9519
|
-
}
|
|
9520
|
-
if (this.integers) {
|
|
9521
|
-
validators.push((value) => {
|
|
9522
|
-
if (typeof value === "number" && !Number.isInteger(value)) {
|
|
9523
|
-
return "Must be a whole number.";
|
|
9524
|
-
}
|
|
9525
|
-
});
|
|
9526
|
-
}
|
|
9527
|
-
return validators;
|
|
9528
|
-
}
|
|
9529
|
-
serialize() {
|
|
9530
|
-
return {
|
|
9531
|
-
...super._serialize(),
|
|
9532
|
-
minimum: this.minimum,
|
|
9533
|
-
maximum: this.maximum,
|
|
9534
|
-
integers: this.integers
|
|
9535
|
-
};
|
|
9536
|
-
}
|
|
9537
|
-
static deserialize(data) {
|
|
9538
|
-
if (data.type !== "number")
|
|
9539
|
-
throw new Error("Type mismatch.");
|
|
9540
|
-
return new _NumberField(data);
|
|
9541
|
-
}
|
|
9542
|
-
getInput(props) {
|
|
9543
|
-
return /* @__PURE__ */ jsx(NumberInput$1, { field: this, ...props });
|
|
9544
|
-
}
|
|
9545
|
-
};
|
|
9546
|
-
__publicField(_NumberField, "fieldTypeName", "Number");
|
|
9547
|
-
__publicField(_NumberField, "fieldTypeDescription", "Allows specifying a number within a given range.");
|
|
9548
|
-
__publicField(_NumberField, "Icon", FontFamilyIcon);
|
|
9549
|
-
__publicField(_NumberField, "_validateMin", (path) => (value, allValues) => {
|
|
9550
|
-
const field = valueIsFormikUserFormRevision(allValues) ? get(allValues, path) : allValues;
|
|
9551
|
-
if (typeof field.maximum === "number" && typeof value === "number" && field.maximum < value) {
|
|
9552
|
-
return "Minimum cannot be greater than minimum.";
|
|
9553
|
-
}
|
|
9554
|
-
return null;
|
|
9555
|
-
});
|
|
9556
|
-
__publicField(_NumberField, "_validateMax", (path) => (value, allValues) => {
|
|
9557
|
-
const field = valueIsFormikUserFormRevision(allValues) ? get(allValues, path) : allValues;
|
|
9558
|
-
if (typeof field.minimum === "number" && typeof value === "number" && field.minimum > value) {
|
|
9559
|
-
return "Maximum cannot be less than minimum.";
|
|
9560
|
-
}
|
|
9561
|
-
return null;
|
|
9562
|
-
});
|
|
9563
|
-
let NumberField = _NumberField;
|
|
9564
9567
|
const hasKeys = (errors) => {
|
|
9565
9568
|
return Object.keys(errors).length > 0;
|
|
9566
9569
|
};
|
|
@@ -11007,8 +11010,6 @@ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
|
|
|
11007
11010
|
DateField,
|
|
11008
11011
|
DateInput,
|
|
11009
11012
|
FieldSection,
|
|
11010
|
-
FieldTypeToClsMapping,
|
|
11011
|
-
FieldTypeToEmptyFieldMapping,
|
|
11012
11013
|
FormBrowser,
|
|
11013
11014
|
FormBuilder,
|
|
11014
11015
|
FormRenderer,
|
|
@@ -11047,8 +11048,7 @@ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
|
|
|
11047
11048
|
useFieldInput,
|
|
11048
11049
|
useFieldInputs,
|
|
11049
11050
|
useFormikInput,
|
|
11050
|
-
valueIsFile
|
|
11051
|
-
valueIsFormikUserFormRevision
|
|
11051
|
+
valueIsFile
|
|
11052
11052
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
11053
11053
|
export {
|
|
11054
11054
|
APIError,
|
|
@@ -11073,8 +11073,6 @@ export {
|
|
|
11073
11073
|
EmailDomainsService,
|
|
11074
11074
|
EmailVerificationService,
|
|
11075
11075
|
FieldSection,
|
|
11076
|
-
FieldTypeToClsMapping,
|
|
11077
|
-
FieldTypeToEmptyFieldMapping,
|
|
11078
11076
|
FileService,
|
|
11079
11077
|
FormBrowser,
|
|
11080
11078
|
FormBuilder,
|
|
@@ -11492,7 +11490,6 @@ export {
|
|
|
11492
11490
|
userReducer,
|
|
11493
11491
|
userSlice,
|
|
11494
11492
|
valueIsFile,
|
|
11495
|
-
valueIsFormikUserFormRevision,
|
|
11496
11493
|
warningColor,
|
|
11497
11494
|
workspaceReducer,
|
|
11498
11495
|
workspaceSlice,
|