@form-engine-ts/core 2.9.6 → 3.1.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/README.md +2 -1
- package/dist/index.cjs +63 -1
- package/dist/index.d.cts +13 -2
- package/dist/index.d.ts +13 -2
- package/dist/index.js +62 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,7 +29,8 @@ if (!result.valid) console.error(result.issues);
|
|
|
29
29
|
Add `pages` to partition every field into an accessible wizard and use `validatePageAnswers(schema, pageIndex, values)`
|
|
30
30
|
for step-scoped validation. Schemas without `pages` remain single-page forms.
|
|
31
31
|
|
|
32
|
-
Store authoring-time translations on forms, fields, options, and pages. `resolveLocalizedSchema` applies
|
|
32
|
+
Store authoring-time translations on forms, fields, options, and pages. `resolveLocalizedSchema(schema, locale)` applies
|
|
33
|
+
them synchronously and returns the original schema when no locale is supplied,
|
|
33
34
|
while `populateSchemaTranslations` fills them through an injected `AsyncTranslationAdapter`. Population defaults to
|
|
34
35
|
`overwrite: "missing-only"`, accepts per-slot `shouldOverwrite` and `createMetadata` callbacks, and returns
|
|
35
36
|
`{ schema, report }` with updated and skipped translation slots.
|
package/dist/index.cjs
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
DEFAULT_FIELD_TYPE_DEFINITIONS: () => DEFAULT_FIELD_TYPE_DEFINITIONS,
|
|
23
24
|
aggregateResponses: () => aggregateResponses,
|
|
24
25
|
assertValidFormSchema: () => assertValidFormSchema,
|
|
25
26
|
assertVersionMutable: () => assertVersionMutable,
|
|
@@ -1523,6 +1524,66 @@ function transformFieldType(field, nextType) {
|
|
|
1523
1524
|
return { ...common, type: nextType, options };
|
|
1524
1525
|
}
|
|
1525
1526
|
|
|
1527
|
+
// src/fieldTypes.ts
|
|
1528
|
+
var DEFAULT_FIELD_TYPE_DEFINITIONS = [
|
|
1529
|
+
{
|
|
1530
|
+
type: "text",
|
|
1531
|
+
labelKey: "builder.fields.typeText",
|
|
1532
|
+
defaultLabel: "\u4E00\u884C\u30C6\u30AD\u30B9\u30C8",
|
|
1533
|
+
category: "text",
|
|
1534
|
+
hasOptions: false
|
|
1535
|
+
},
|
|
1536
|
+
{
|
|
1537
|
+
type: "textarea",
|
|
1538
|
+
labelKey: "builder.fields.typeTextarea",
|
|
1539
|
+
defaultLabel: "\u9577\u6587\u30C6\u30AD\u30B9\u30C8",
|
|
1540
|
+
category: "text",
|
|
1541
|
+
hasOptions: false
|
|
1542
|
+
},
|
|
1543
|
+
{
|
|
1544
|
+
type: "number",
|
|
1545
|
+
labelKey: "builder.fields.typeNumber",
|
|
1546
|
+
defaultLabel: "\u6570\u5024",
|
|
1547
|
+
category: "number",
|
|
1548
|
+
hasOptions: false
|
|
1549
|
+
},
|
|
1550
|
+
{
|
|
1551
|
+
type: "rating",
|
|
1552
|
+
labelKey: "builder.fields.typeRating",
|
|
1553
|
+
defaultLabel: "\u8A55\u4FA1",
|
|
1554
|
+
category: "number",
|
|
1555
|
+
hasOptions: false
|
|
1556
|
+
},
|
|
1557
|
+
{
|
|
1558
|
+
type: "radio",
|
|
1559
|
+
labelKey: "builder.fields.typeRadio",
|
|
1560
|
+
defaultLabel: "\u5358\u4E00\u9078\u629E (\u30E9\u30B8\u30AA\u30DC\u30BF\u30F3)",
|
|
1561
|
+
category: "choice",
|
|
1562
|
+
hasOptions: true
|
|
1563
|
+
},
|
|
1564
|
+
{
|
|
1565
|
+
type: "checkbox",
|
|
1566
|
+
labelKey: "builder.fields.typeCheckbox",
|
|
1567
|
+
defaultLabel: "\u30C1\u30A7\u30C3\u30AF\u30DC\u30C3\u30AF\u30B9",
|
|
1568
|
+
category: "choice",
|
|
1569
|
+
hasOptions: false
|
|
1570
|
+
},
|
|
1571
|
+
{
|
|
1572
|
+
type: "select",
|
|
1573
|
+
labelKey: "builder.fields.typeSelect",
|
|
1574
|
+
defaultLabel: "\u30C9\u30ED\u30C3\u30D7\u30C0\u30A6\u30F3",
|
|
1575
|
+
category: "choice",
|
|
1576
|
+
hasOptions: true
|
|
1577
|
+
},
|
|
1578
|
+
{
|
|
1579
|
+
type: "multi-select",
|
|
1580
|
+
labelKey: "builder.fields.typeMultiSelect",
|
|
1581
|
+
defaultLabel: "\u8907\u6570\u9078\u629E",
|
|
1582
|
+
category: "choice",
|
|
1583
|
+
hasOptions: true
|
|
1584
|
+
}
|
|
1585
|
+
];
|
|
1586
|
+
|
|
1526
1587
|
// src/pagination.ts
|
|
1527
1588
|
function asFormResponse2(submission) {
|
|
1528
1589
|
return {
|
|
@@ -2035,7 +2096,7 @@ function translationSlots(schema, locale) {
|
|
|
2035
2096
|
return descriptors;
|
|
2036
2097
|
}
|
|
2037
2098
|
function resolveLocalizedSchema(schema, targetLocale) {
|
|
2038
|
-
if (targetLocale.length === 0 || targetLocale === schema.defaultLocale) return schema;
|
|
2099
|
+
if (targetLocale === void 0 || targetLocale.length === 0 || targetLocale === schema.defaultLocale) return schema;
|
|
2039
2100
|
const formTranslation = schema.translations?.[targetLocale];
|
|
2040
2101
|
const completionMessage = formTranslation?.completionMessage ?? schema.completionMessage;
|
|
2041
2102
|
return {
|
|
@@ -2418,6 +2479,7 @@ function assertVersionMutable(status) {
|
|
|
2418
2479
|
}
|
|
2419
2480
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2420
2481
|
0 && (module.exports = {
|
|
2482
|
+
DEFAULT_FIELD_TYPE_DEFINITIONS,
|
|
2421
2483
|
aggregateResponses,
|
|
2422
2484
|
assertValidFormSchema,
|
|
2423
2485
|
assertVersionMutable,
|
package/dist/index.d.cts
CHANGED
|
@@ -418,6 +418,15 @@ interface FormAnalytics {
|
|
|
418
418
|
type Question = FormField;
|
|
419
419
|
type QuestionType = FieldType;
|
|
420
420
|
type ChoiceOption = FieldOption;
|
|
421
|
+
/** Translation keys reserved for the form builder UI. */
|
|
422
|
+
type BuilderTranslationKey = `builder.${string}`;
|
|
423
|
+
interface FieldTypeDefinition {
|
|
424
|
+
readonly type: QuestionType;
|
|
425
|
+
readonly labelKey: BuilderTranslationKey;
|
|
426
|
+
readonly defaultLabel: string;
|
|
427
|
+
readonly category: "text" | "choice" | "number" | "advanced";
|
|
428
|
+
readonly hasOptions: boolean;
|
|
429
|
+
}
|
|
421
430
|
interface FormResponse extends ExtensibleNode {
|
|
422
431
|
readonly responseId: string;
|
|
423
432
|
readonly formId: string;
|
|
@@ -531,6 +540,8 @@ declare function dispatchWebhook<T>(event: FormEvent<T>, config: WebhookConfig,
|
|
|
531
540
|
*/
|
|
532
541
|
declare function transformFieldType(field: FormField, nextType: QuestionType): FormField;
|
|
533
542
|
|
|
543
|
+
declare const DEFAULT_FIELD_TYPE_DEFINITIONS: readonly FieldTypeDefinition[];
|
|
544
|
+
|
|
534
545
|
interface PaginationIteratorOptions {
|
|
535
546
|
readonly pageSize?: number;
|
|
536
547
|
readonly maxItems?: number;
|
|
@@ -611,7 +622,7 @@ interface TranslationReport {
|
|
|
611
622
|
readonly updatedSlots: readonly TranslationSlot[];
|
|
612
623
|
readonly skippedSlots: readonly TranslationSlot[];
|
|
613
624
|
}
|
|
614
|
-
declare function resolveLocalizedSchema(schema: FormSchema, targetLocale
|
|
625
|
+
declare function resolveLocalizedSchema(schema: FormSchema, targetLocale?: string): FormSchema;
|
|
615
626
|
declare function populateSchemaTranslations(schema: FormSchema, targetLocales: readonly string[], adapter: AsyncTranslationAdapter, options?: PopulateTranslationOptions): Promise<{
|
|
616
627
|
readonly schema: FormSchema;
|
|
617
628
|
readonly report: TranslationReport;
|
|
@@ -627,4 +638,4 @@ declare function calculatePageVisibility(schema: FormSchema, currentAnswers: Rea
|
|
|
627
638
|
declare function calculateFieldVisibility(schema: FormSchema, currentAnswers: Readonly<Record<string, unknown>>): Readonly<Record<string, boolean>>;
|
|
628
639
|
declare function selectVisibleAnswers(schema: FormSchema, currentAnswers: FormValues): FormValues;
|
|
629
640
|
|
|
630
|
-
export { type AccumulatorReport, type AccumulatorResponse, type AccumulatorSkipReason, type AnswerValidationResult, type AsyncTranslationAdapter, type BaseField, type CheckboxField, type CheckboxQuestionAggregate, type ChoiceDistributionEntry, type ChoiceOption, type ChoiceQuestionAggregate, type CloneVersionOptions, type CollectedLocales, type ConditionOperator, type ConditionValue, type CreateSubmissionOptions, type CrossTabulationResult, type CsvColumnContext, type CsvColumnDef, type CsvExportOptions, type DeleteDraftOptions, type DisplayCondition, type ExtensibleNode, type FieldOption, type FieldType, type FormAnalytics, type FormEvent, type FormEventType, type FormField, type FormPage, type FormPolicy, type FormResponse, type FormSchema, type FormStorageAdapter, type FormSubmission, type FormValue, type FormValues, type FormVersionRecord, type FormVersionState, type FormVersionStatus, type JsonValue, type LocalizedText, type MultiSelectField, type NodeWritableStream, type NumberField, type NumberQuestionAggregate, type NumericSummary, type OptionAggregate, type PagedSubmissionStorageAdapter, type PaginationIteratorOptions, type PopulateTranslationOptions, type PublishDraftOptions, type PublishDraftResult, type Question, type QuestionAggregate, type QuestionType, type RatingField, type ResponseAccumulator, type ResponseAccumulatorOptions, type Result, type SchemaIssue, type SchemaStructureIssue, type SchemaStructureIssueType, type SchemaTranslations, type SchemaValidationResult, type SelectField, type StorageAdapter, type StorageCommitError, type StreamCsvOptions, type SubmissionCursorValue, type SubmissionFilter, type SubmissionPage, type SubmissionPageQueryOptions, type SubmissionQueryOptions, type TextAnswerCursorValue, type TextAnswerItem, type TextAnswerPage, type TextAnswerPageQueryOptions, type TextField, type TextQuestionAggregate, type TranslationAdapter, type TranslationReport, type TranslationSlot, type ValidateFormSchemaOptions, type ValidationCode, type ValidationError, type ValidationIssue, type VersionTransitionError, type VersionTransitionEvent, type VersionTransitionPlan, type VersionedFormStorageAdapter, type WebhookConfig, type WebhookDispatchResult, aggregateResponses, assertValidFormSchema, assertVersionMutable, calculateChoiceDistribution, calculateCrossTabulation, calculateFieldVisibility, calculateNumericSummary, calculatePageVisibility, cloneVersionToDraft, collectSchemaLocales, createCloneTransitionPlan, createDeleteDraftTransitionPlan, createPublishTransitionPlan, createResponseAccumulator, createSubmission, decodeSubmissionCursor, decodeTextAnswerCursor, deleteDraft, dispatchWebhook, encodeSubmissionCursor, encodeTextAnswerCursor, escapeCsvCell, exportResponsesToCsv, exportResponsesToCsvStream, isDisplayConditionSatisfied, isQuestionVisible, iterateSubmissionPages, jsonValuesEqual, matchesSubmissionFilter, matchesSubmissionPageFilters, normalizeSubmissionPageSize, pipeResponsesToCsvStream, populateSchemaTranslations, publishDraft, resolveFormTranslation, resolveLocalizedSchema, sanitizeSchema, selectVisibleAnswers, transformFieldType, validateAnswers, validateFormSchema, validatePageAnswers, validateSchemaStructure };
|
|
641
|
+
export { type AccumulatorReport, type AccumulatorResponse, type AccumulatorSkipReason, type AnswerValidationResult, type AsyncTranslationAdapter, type BaseField, type BuilderTranslationKey, type CheckboxField, type CheckboxQuestionAggregate, type ChoiceDistributionEntry, type ChoiceOption, type ChoiceQuestionAggregate, type CloneVersionOptions, type CollectedLocales, type ConditionOperator, type ConditionValue, type CreateSubmissionOptions, type CrossTabulationResult, type CsvColumnContext, type CsvColumnDef, type CsvExportOptions, DEFAULT_FIELD_TYPE_DEFINITIONS, type DeleteDraftOptions, type DisplayCondition, type ExtensibleNode, type FieldOption, type FieldType, type FieldTypeDefinition, type FormAnalytics, type FormEvent, type FormEventType, type FormField, type FormPage, type FormPolicy, type FormResponse, type FormSchema, type FormStorageAdapter, type FormSubmission, type FormValue, type FormValues, type FormVersionRecord, type FormVersionState, type FormVersionStatus, type JsonValue, type LocalizedText, type MultiSelectField, type NodeWritableStream, type NumberField, type NumberQuestionAggregate, type NumericSummary, type OptionAggregate, type PagedSubmissionStorageAdapter, type PaginationIteratorOptions, type PopulateTranslationOptions, type PublishDraftOptions, type PublishDraftResult, type Question, type QuestionAggregate, type QuestionType, type RatingField, type ResponseAccumulator, type ResponseAccumulatorOptions, type Result, type SchemaIssue, type SchemaStructureIssue, type SchemaStructureIssueType, type SchemaTranslations, type SchemaValidationResult, type SelectField, type StorageAdapter, type StorageCommitError, type StreamCsvOptions, type SubmissionCursorValue, type SubmissionFilter, type SubmissionPage, type SubmissionPageQueryOptions, type SubmissionQueryOptions, type TextAnswerCursorValue, type TextAnswerItem, type TextAnswerPage, type TextAnswerPageQueryOptions, type TextField, type TextQuestionAggregate, type TranslationAdapter, type TranslationReport, type TranslationSlot, type ValidateFormSchemaOptions, type ValidationCode, type ValidationError, type ValidationIssue, type VersionTransitionError, type VersionTransitionEvent, type VersionTransitionPlan, type VersionedFormStorageAdapter, type WebhookConfig, type WebhookDispatchResult, aggregateResponses, assertValidFormSchema, assertVersionMutable, calculateChoiceDistribution, calculateCrossTabulation, calculateFieldVisibility, calculateNumericSummary, calculatePageVisibility, cloneVersionToDraft, collectSchemaLocales, createCloneTransitionPlan, createDeleteDraftTransitionPlan, createPublishTransitionPlan, createResponseAccumulator, createSubmission, decodeSubmissionCursor, decodeTextAnswerCursor, deleteDraft, dispatchWebhook, encodeSubmissionCursor, encodeTextAnswerCursor, escapeCsvCell, exportResponsesToCsv, exportResponsesToCsvStream, isDisplayConditionSatisfied, isQuestionVisible, iterateSubmissionPages, jsonValuesEqual, matchesSubmissionFilter, matchesSubmissionPageFilters, normalizeSubmissionPageSize, pipeResponsesToCsvStream, populateSchemaTranslations, publishDraft, resolveFormTranslation, resolveLocalizedSchema, sanitizeSchema, selectVisibleAnswers, transformFieldType, validateAnswers, validateFormSchema, validatePageAnswers, validateSchemaStructure };
|
package/dist/index.d.ts
CHANGED
|
@@ -418,6 +418,15 @@ interface FormAnalytics {
|
|
|
418
418
|
type Question = FormField;
|
|
419
419
|
type QuestionType = FieldType;
|
|
420
420
|
type ChoiceOption = FieldOption;
|
|
421
|
+
/** Translation keys reserved for the form builder UI. */
|
|
422
|
+
type BuilderTranslationKey = `builder.${string}`;
|
|
423
|
+
interface FieldTypeDefinition {
|
|
424
|
+
readonly type: QuestionType;
|
|
425
|
+
readonly labelKey: BuilderTranslationKey;
|
|
426
|
+
readonly defaultLabel: string;
|
|
427
|
+
readonly category: "text" | "choice" | "number" | "advanced";
|
|
428
|
+
readonly hasOptions: boolean;
|
|
429
|
+
}
|
|
421
430
|
interface FormResponse extends ExtensibleNode {
|
|
422
431
|
readonly responseId: string;
|
|
423
432
|
readonly formId: string;
|
|
@@ -531,6 +540,8 @@ declare function dispatchWebhook<T>(event: FormEvent<T>, config: WebhookConfig,
|
|
|
531
540
|
*/
|
|
532
541
|
declare function transformFieldType(field: FormField, nextType: QuestionType): FormField;
|
|
533
542
|
|
|
543
|
+
declare const DEFAULT_FIELD_TYPE_DEFINITIONS: readonly FieldTypeDefinition[];
|
|
544
|
+
|
|
534
545
|
interface PaginationIteratorOptions {
|
|
535
546
|
readonly pageSize?: number;
|
|
536
547
|
readonly maxItems?: number;
|
|
@@ -611,7 +622,7 @@ interface TranslationReport {
|
|
|
611
622
|
readonly updatedSlots: readonly TranslationSlot[];
|
|
612
623
|
readonly skippedSlots: readonly TranslationSlot[];
|
|
613
624
|
}
|
|
614
|
-
declare function resolveLocalizedSchema(schema: FormSchema, targetLocale
|
|
625
|
+
declare function resolveLocalizedSchema(schema: FormSchema, targetLocale?: string): FormSchema;
|
|
615
626
|
declare function populateSchemaTranslations(schema: FormSchema, targetLocales: readonly string[], adapter: AsyncTranslationAdapter, options?: PopulateTranslationOptions): Promise<{
|
|
616
627
|
readonly schema: FormSchema;
|
|
617
628
|
readonly report: TranslationReport;
|
|
@@ -627,4 +638,4 @@ declare function calculatePageVisibility(schema: FormSchema, currentAnswers: Rea
|
|
|
627
638
|
declare function calculateFieldVisibility(schema: FormSchema, currentAnswers: Readonly<Record<string, unknown>>): Readonly<Record<string, boolean>>;
|
|
628
639
|
declare function selectVisibleAnswers(schema: FormSchema, currentAnswers: FormValues): FormValues;
|
|
629
640
|
|
|
630
|
-
export { type AccumulatorReport, type AccumulatorResponse, type AccumulatorSkipReason, type AnswerValidationResult, type AsyncTranslationAdapter, type BaseField, type CheckboxField, type CheckboxQuestionAggregate, type ChoiceDistributionEntry, type ChoiceOption, type ChoiceQuestionAggregate, type CloneVersionOptions, type CollectedLocales, type ConditionOperator, type ConditionValue, type CreateSubmissionOptions, type CrossTabulationResult, type CsvColumnContext, type CsvColumnDef, type CsvExportOptions, type DeleteDraftOptions, type DisplayCondition, type ExtensibleNode, type FieldOption, type FieldType, type FormAnalytics, type FormEvent, type FormEventType, type FormField, type FormPage, type FormPolicy, type FormResponse, type FormSchema, type FormStorageAdapter, type FormSubmission, type FormValue, type FormValues, type FormVersionRecord, type FormVersionState, type FormVersionStatus, type JsonValue, type LocalizedText, type MultiSelectField, type NodeWritableStream, type NumberField, type NumberQuestionAggregate, type NumericSummary, type OptionAggregate, type PagedSubmissionStorageAdapter, type PaginationIteratorOptions, type PopulateTranslationOptions, type PublishDraftOptions, type PublishDraftResult, type Question, type QuestionAggregate, type QuestionType, type RatingField, type ResponseAccumulator, type ResponseAccumulatorOptions, type Result, type SchemaIssue, type SchemaStructureIssue, type SchemaStructureIssueType, type SchemaTranslations, type SchemaValidationResult, type SelectField, type StorageAdapter, type StorageCommitError, type StreamCsvOptions, type SubmissionCursorValue, type SubmissionFilter, type SubmissionPage, type SubmissionPageQueryOptions, type SubmissionQueryOptions, type TextAnswerCursorValue, type TextAnswerItem, type TextAnswerPage, type TextAnswerPageQueryOptions, type TextField, type TextQuestionAggregate, type TranslationAdapter, type TranslationReport, type TranslationSlot, type ValidateFormSchemaOptions, type ValidationCode, type ValidationError, type ValidationIssue, type VersionTransitionError, type VersionTransitionEvent, type VersionTransitionPlan, type VersionedFormStorageAdapter, type WebhookConfig, type WebhookDispatchResult, aggregateResponses, assertValidFormSchema, assertVersionMutable, calculateChoiceDistribution, calculateCrossTabulation, calculateFieldVisibility, calculateNumericSummary, calculatePageVisibility, cloneVersionToDraft, collectSchemaLocales, createCloneTransitionPlan, createDeleteDraftTransitionPlan, createPublishTransitionPlan, createResponseAccumulator, createSubmission, decodeSubmissionCursor, decodeTextAnswerCursor, deleteDraft, dispatchWebhook, encodeSubmissionCursor, encodeTextAnswerCursor, escapeCsvCell, exportResponsesToCsv, exportResponsesToCsvStream, isDisplayConditionSatisfied, isQuestionVisible, iterateSubmissionPages, jsonValuesEqual, matchesSubmissionFilter, matchesSubmissionPageFilters, normalizeSubmissionPageSize, pipeResponsesToCsvStream, populateSchemaTranslations, publishDraft, resolveFormTranslation, resolveLocalizedSchema, sanitizeSchema, selectVisibleAnswers, transformFieldType, validateAnswers, validateFormSchema, validatePageAnswers, validateSchemaStructure };
|
|
641
|
+
export { type AccumulatorReport, type AccumulatorResponse, type AccumulatorSkipReason, type AnswerValidationResult, type AsyncTranslationAdapter, type BaseField, type BuilderTranslationKey, type CheckboxField, type CheckboxQuestionAggregate, type ChoiceDistributionEntry, type ChoiceOption, type ChoiceQuestionAggregate, type CloneVersionOptions, type CollectedLocales, type ConditionOperator, type ConditionValue, type CreateSubmissionOptions, type CrossTabulationResult, type CsvColumnContext, type CsvColumnDef, type CsvExportOptions, DEFAULT_FIELD_TYPE_DEFINITIONS, type DeleteDraftOptions, type DisplayCondition, type ExtensibleNode, type FieldOption, type FieldType, type FieldTypeDefinition, type FormAnalytics, type FormEvent, type FormEventType, type FormField, type FormPage, type FormPolicy, type FormResponse, type FormSchema, type FormStorageAdapter, type FormSubmission, type FormValue, type FormValues, type FormVersionRecord, type FormVersionState, type FormVersionStatus, type JsonValue, type LocalizedText, type MultiSelectField, type NodeWritableStream, type NumberField, type NumberQuestionAggregate, type NumericSummary, type OptionAggregate, type PagedSubmissionStorageAdapter, type PaginationIteratorOptions, type PopulateTranslationOptions, type PublishDraftOptions, type PublishDraftResult, type Question, type QuestionAggregate, type QuestionType, type RatingField, type ResponseAccumulator, type ResponseAccumulatorOptions, type Result, type SchemaIssue, type SchemaStructureIssue, type SchemaStructureIssueType, type SchemaTranslations, type SchemaValidationResult, type SelectField, type StorageAdapter, type StorageCommitError, type StreamCsvOptions, type SubmissionCursorValue, type SubmissionFilter, type SubmissionPage, type SubmissionPageQueryOptions, type SubmissionQueryOptions, type TextAnswerCursorValue, type TextAnswerItem, type TextAnswerPage, type TextAnswerPageQueryOptions, type TextField, type TextQuestionAggregate, type TranslationAdapter, type TranslationReport, type TranslationSlot, type ValidateFormSchemaOptions, type ValidationCode, type ValidationError, type ValidationIssue, type VersionTransitionError, type VersionTransitionEvent, type VersionTransitionPlan, type VersionedFormStorageAdapter, type WebhookConfig, type WebhookDispatchResult, aggregateResponses, assertValidFormSchema, assertVersionMutable, calculateChoiceDistribution, calculateCrossTabulation, calculateFieldVisibility, calculateNumericSummary, calculatePageVisibility, cloneVersionToDraft, collectSchemaLocales, createCloneTransitionPlan, createDeleteDraftTransitionPlan, createPublishTransitionPlan, createResponseAccumulator, createSubmission, decodeSubmissionCursor, decodeTextAnswerCursor, deleteDraft, dispatchWebhook, encodeSubmissionCursor, encodeTextAnswerCursor, escapeCsvCell, exportResponsesToCsv, exportResponsesToCsvStream, isDisplayConditionSatisfied, isQuestionVisible, iterateSubmissionPages, jsonValuesEqual, matchesSubmissionFilter, matchesSubmissionPageFilters, normalizeSubmissionPageSize, pipeResponsesToCsvStream, populateSchemaTranslations, publishDraft, resolveFormTranslation, resolveLocalizedSchema, sanitizeSchema, selectVisibleAnswers, transformFieldType, validateAnswers, validateFormSchema, validatePageAnswers, validateSchemaStructure };
|
package/dist/index.js
CHANGED
|
@@ -1455,6 +1455,66 @@ function transformFieldType(field, nextType) {
|
|
|
1455
1455
|
return { ...common, type: nextType, options };
|
|
1456
1456
|
}
|
|
1457
1457
|
|
|
1458
|
+
// src/fieldTypes.ts
|
|
1459
|
+
var DEFAULT_FIELD_TYPE_DEFINITIONS = [
|
|
1460
|
+
{
|
|
1461
|
+
type: "text",
|
|
1462
|
+
labelKey: "builder.fields.typeText",
|
|
1463
|
+
defaultLabel: "\u4E00\u884C\u30C6\u30AD\u30B9\u30C8",
|
|
1464
|
+
category: "text",
|
|
1465
|
+
hasOptions: false
|
|
1466
|
+
},
|
|
1467
|
+
{
|
|
1468
|
+
type: "textarea",
|
|
1469
|
+
labelKey: "builder.fields.typeTextarea",
|
|
1470
|
+
defaultLabel: "\u9577\u6587\u30C6\u30AD\u30B9\u30C8",
|
|
1471
|
+
category: "text",
|
|
1472
|
+
hasOptions: false
|
|
1473
|
+
},
|
|
1474
|
+
{
|
|
1475
|
+
type: "number",
|
|
1476
|
+
labelKey: "builder.fields.typeNumber",
|
|
1477
|
+
defaultLabel: "\u6570\u5024",
|
|
1478
|
+
category: "number",
|
|
1479
|
+
hasOptions: false
|
|
1480
|
+
},
|
|
1481
|
+
{
|
|
1482
|
+
type: "rating",
|
|
1483
|
+
labelKey: "builder.fields.typeRating",
|
|
1484
|
+
defaultLabel: "\u8A55\u4FA1",
|
|
1485
|
+
category: "number",
|
|
1486
|
+
hasOptions: false
|
|
1487
|
+
},
|
|
1488
|
+
{
|
|
1489
|
+
type: "radio",
|
|
1490
|
+
labelKey: "builder.fields.typeRadio",
|
|
1491
|
+
defaultLabel: "\u5358\u4E00\u9078\u629E (\u30E9\u30B8\u30AA\u30DC\u30BF\u30F3)",
|
|
1492
|
+
category: "choice",
|
|
1493
|
+
hasOptions: true
|
|
1494
|
+
},
|
|
1495
|
+
{
|
|
1496
|
+
type: "checkbox",
|
|
1497
|
+
labelKey: "builder.fields.typeCheckbox",
|
|
1498
|
+
defaultLabel: "\u30C1\u30A7\u30C3\u30AF\u30DC\u30C3\u30AF\u30B9",
|
|
1499
|
+
category: "choice",
|
|
1500
|
+
hasOptions: false
|
|
1501
|
+
},
|
|
1502
|
+
{
|
|
1503
|
+
type: "select",
|
|
1504
|
+
labelKey: "builder.fields.typeSelect",
|
|
1505
|
+
defaultLabel: "\u30C9\u30ED\u30C3\u30D7\u30C0\u30A6\u30F3",
|
|
1506
|
+
category: "choice",
|
|
1507
|
+
hasOptions: true
|
|
1508
|
+
},
|
|
1509
|
+
{
|
|
1510
|
+
type: "multi-select",
|
|
1511
|
+
labelKey: "builder.fields.typeMultiSelect",
|
|
1512
|
+
defaultLabel: "\u8907\u6570\u9078\u629E",
|
|
1513
|
+
category: "choice",
|
|
1514
|
+
hasOptions: true
|
|
1515
|
+
}
|
|
1516
|
+
];
|
|
1517
|
+
|
|
1458
1518
|
// src/pagination.ts
|
|
1459
1519
|
function asFormResponse2(submission) {
|
|
1460
1520
|
return {
|
|
@@ -1967,7 +2027,7 @@ function translationSlots(schema, locale) {
|
|
|
1967
2027
|
return descriptors;
|
|
1968
2028
|
}
|
|
1969
2029
|
function resolveLocalizedSchema(schema, targetLocale) {
|
|
1970
|
-
if (targetLocale.length === 0 || targetLocale === schema.defaultLocale) return schema;
|
|
2030
|
+
if (targetLocale === void 0 || targetLocale.length === 0 || targetLocale === schema.defaultLocale) return schema;
|
|
1971
2031
|
const formTranslation = schema.translations?.[targetLocale];
|
|
1972
2032
|
const completionMessage = formTranslation?.completionMessage ?? schema.completionMessage;
|
|
1973
2033
|
return {
|
|
@@ -2349,6 +2409,7 @@ function assertVersionMutable(status) {
|
|
|
2349
2409
|
}
|
|
2350
2410
|
}
|
|
2351
2411
|
export {
|
|
2412
|
+
DEFAULT_FIELD_TYPE_DEFINITIONS,
|
|
2352
2413
|
aggregateResponses,
|
|
2353
2414
|
assertValidFormSchema,
|
|
2354
2415
|
assertVersionMutable,
|