@vectoriox/iox-ui 5.187.0 → 5.188.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/fesm2022/vectoriox-iox-ui-forms-core.mjs +111 -11
- package/fesm2022/vectoriox-iox-ui-forms-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui.mjs +110 -10
- package/fesm2022/vectoriox-iox-ui.mjs.map +1 -1
- package/forms-core/index.d.ts +59 -3
- package/package.json +1 -1
- package/src/forms-core/form-presets.ts +5 -3
- package/src/forms-core/form-words.ts +140 -0
- package/src/forms-core/public-api.ts +1 -0
- package/src/forms-core/submit-lifecycle.ts +3 -8
package/forms-core/index.d.ts
CHANGED
|
@@ -626,6 +626,61 @@ declare function isChannelFilled(href: unknown): boolean;
|
|
|
626
626
|
/** A WhatsApp or web channel opens in a new tab; a call or an email hands over to the device. */
|
|
627
627
|
declare function channelOpensNewTab(kind: ChannelKind | string): boolean;
|
|
628
628
|
|
|
629
|
+
/**
|
|
630
|
+
* FORM WORDS — what a form part says the moment it lands on a page, in the SITE's language (iox-ui#159).
|
|
631
|
+
*
|
|
632
|
+
* ONE table for the words nobody wrote yet: a new Field's label, the plain Form's Name / Email / Send, each field kind's
|
|
633
|
+
* label and starter choices (the Forms tray's Checkbox, Radio group, …), and a second channel's words (WhatsApp, Call
|
|
634
|
+
* us, …). The builder's Form type, its field-kind presets and `addFormChannel`, and the admin's channel panel all read
|
|
635
|
+
* it — a Hebrew site gets Hebrew parts from the tray, never English it has to retype. The English column IS the
|
|
636
|
+
* baseline the builder's configs carry; `formWordIn` turns an untouched baseline word into the site's language.
|
|
637
|
+
*
|
|
638
|
+
* Data + lookups only: framework-free, like the rest of forms-core. The preset forms' own words stay in
|
|
639
|
+
* `form-presets.ts` (`FORM_PRESET_WORDS_HE`); "While sending" and "Sent" in `submit-lifecycle.ts`.
|
|
640
|
+
*/
|
|
641
|
+
|
|
642
|
+
/** The field kinds the tray offers as their own rows — the Field's `control` values (builder `FIELD_KIND_PRESETS`). */
|
|
643
|
+
type FieldKindControl = 'checkbox' | 'switch' | 'radio' | 'choices' | 'select' | 'range' | 'date' | 'time';
|
|
644
|
+
/** A field kind's seeded words: its label and, for a kind with choices, one choice per line (`optionsText`). */
|
|
645
|
+
interface FieldKindWords {
|
|
646
|
+
label: string;
|
|
647
|
+
optionsText?: string;
|
|
648
|
+
}
|
|
649
|
+
interface FormWords {
|
|
650
|
+
/** A new Field's label — the Field type's own default. */
|
|
651
|
+
field: string;
|
|
652
|
+
/** The plain Form's two fields and its button. */
|
|
653
|
+
name: string;
|
|
654
|
+
email: string;
|
|
655
|
+
send: string;
|
|
656
|
+
kinds: Readonly<Record<FieldKindControl, FieldKindWords>>;
|
|
657
|
+
/** A second channel's words beside Send, by kind (premium N2). */
|
|
658
|
+
channels: Readonly<Record<`${ChannelKind}`, string>>;
|
|
659
|
+
}
|
|
660
|
+
declare enum FormWordsLanguage {
|
|
661
|
+
En = "en",
|
|
662
|
+
He = "he"
|
|
663
|
+
}
|
|
664
|
+
/** The language a form speaks for a `lang` attribute or site locale: design-core's subtag (`he-IL` → `he`), the old
|
|
665
|
+
* `iw` read as `he`; '' when none. */
|
|
666
|
+
declare function formLanguageOf(lang: string | null | undefined): string;
|
|
667
|
+
/** The words in a site's language — English for any language the table does not hold, and when none is given. */
|
|
668
|
+
declare function formWords(lang?: string | null): FormWords;
|
|
669
|
+
/** The baseline — what a builder config carries before anyone writes. */
|
|
670
|
+
declare function baselineFormWords(): FormWords;
|
|
671
|
+
/** A field kind's seeded label and choices in `lang`; undefined for a control the tray does not offer as a row. */
|
|
672
|
+
declare function fieldKindWords(control: string, lang?: string | null): FieldKindWords | undefined;
|
|
673
|
+
/** A channel's words in `lang` ('' for an unknown kind — the caller keeps what it has). */
|
|
674
|
+
declare function channelWords(kind: string, lang?: string | null): string;
|
|
675
|
+
/** The plain-form slots `formWordIn` can carry across languages. */
|
|
676
|
+
type FormWordSlot = 'field' | 'name' | 'email' | 'send';
|
|
677
|
+
/**
|
|
678
|
+
* An UNTOUCHED baseline word in `lang`: when `value` is the English word one of `slots` carries, the site language's word
|
|
679
|
+
* for that slot; anything an author wrote (or an empty value) comes back as it is. How a freshly created Form, Field or
|
|
680
|
+
* submit button speaks the site's language without a second copy of its config.
|
|
681
|
+
*/
|
|
682
|
+
declare function formWordIn(value: unknown, lang: string | null | undefined, slots: readonly FormWordSlot[]): unknown;
|
|
683
|
+
|
|
629
684
|
/**
|
|
630
685
|
* FORM PRESETS — a complete, working form as one insert: its fields, its submit label and the words of
|
|
631
686
|
* its Success and Error blocks. ONE definition (W1.1): the builder's Forms tray builds a preset from
|
|
@@ -693,7 +748,8 @@ declare const FORM_PRESETS: readonly FormPresetDef[];
|
|
|
693
748
|
* site asks, answers and fails in Hebrew). */
|
|
694
749
|
declare function formPresetById(id: string | null | undefined, lang?: string | null): FormPresetDef | undefined;
|
|
695
750
|
/** A preset's words on a Hebrew site: per field (by order) its label, help, placeholder and choices; the submit, the
|
|
696
|
-
* messages, the channel
|
|
751
|
+
* messages, the inbox name, and a channel label only where it is not the kind's own (`channelWords`). A choice's words
|
|
752
|
+
* ARE its value (`optionsText`). */
|
|
697
753
|
interface FormPresetWords {
|
|
698
754
|
formName: string;
|
|
699
755
|
fields: ReadonlyArray<Partial<Pick<FormPresetField, 'label' | 'help' | 'placeholder' | 'optionsText'>>>;
|
|
@@ -928,5 +984,5 @@ interface FieldMarkupOptions {
|
|
|
928
984
|
/** A Field's whole element, as the string renderer writes it. */
|
|
929
985
|
declare function fieldHtml(props: Record<string, any> | null | undefined, options: FieldMarkupOptions): string;
|
|
930
986
|
|
|
931
|
-
export { CALENDAR_ROWS, CHANNEL_KINDS, CHOICE_MESSAGE_KEYS, CalendarKey, ChannelKind, ChoiceAppearance, ControlType, DATE_EMPTY_ATTRIBUTE, DATE_ICON_SVG, DATE_MAX_ATTRIBUTE, DATE_MESSAGE_KEYS, DATE_MIN_ATTRIBUTE, DATE_PICKER_WORDS, DEFAULT_BUSY_WORDS, DEFAULT_EN_MESSAGES, EMAIL_TO_OWNER, FIELD_GROUP_NODE_TYPE, FIELD_NODE_TYPE, FORM_ACTIONS_ROLE, FORM_AFTER_SEND_ATTRIBUTE, FORM_AFTER_SEND_TRAIT, FORM_ANNOUNCER_ATTRIBUTE, FORM_CHANNEL_ROLE, FORM_CONTENT_TYPES, FORM_ERROR_KEYS, FORM_FIELDS_ATTRIBUTE, FORM_HONEYPOT_CLASS, FORM_NODE_TYPE, FORM_PRESETS, FORM_PRESET_WORDS_HE, FORM_STATE_ATTRIBUTE, FeedbackTiming, FormAfterSend, FormPresetId, FormRenderState, HONEYPOT_FIELD, IMPLIED_PATTERN, INITIAL_FORM_STATE, INTERACTIVE_HOST_TAGS, InteractiveTag, MESSAGE_NAMESPACE, OPTION_CONTROLS, PATTERN_MESSAGE_KEYS, PATTERN_PRESETS, PATTERN_PRESET_OPTIONS, PatternPreset, RENDERED_AT_FIELD, RULE_DESCRIPTORS, RULE_MESSAGE_KEYS, RuleName, RuleParamKind, STORE_ACTION, SUBMIT_BUTTON_NODE_TYPE, SUBMIT_CHECK_SVG, SUBMIT_KEEP_ENABLED_ATTRIBUTE, SUBMIT_MESSAGE_KEYS, SubmitLabelClass, addDaysIso, addMonthsIso, addableRules, applyServerErrors, baseFieldName, busyWord, calendarKeyTarget, calendarMonth, channelHref, channelOpensNewTab, choiceAppearanceOf, clampIso, clientFormSpec, collectFieldNodes, collectFormSpec, dateBoundRules, dateOfIso, datePickerWords, deriveFieldName, emailsOwner, failureAnnouncement, fieldDateRange, fieldHtml, fieldOptionsOf, fieldSpecOf, findFormContentInHosts, firstInvalidField, formAfterSend, formChromeHtml, formContentInHost, formFieldNameMap, formFieldNames, formPresetById, formPresetIn, formatDateInWords, inputTypeOf, interpretSubmitResponse, isChannelFilled, isDateBoundParams, isDateField, isFormContent, isInteractiveHost, isIsoDate, isMultiValueField, isoOfDate, normaliseAnswers, onFieldBlur, onFieldChange, onSubmitAttempt, parseChannelHref, parseClientFormSpec, parseDateBound, parseFieldOptions, planFormPresetIds, presetFormActions, resetFormState, resolveDateBound, rulesFor, sentWord, shouldShowError, submitBusyWords, submitButtonLabelsHtml, submitButtonView, submitEndpointPath, submitOutcome, todayIso, uniqueFieldName, uniqueFieldNames, validateField, validateForm, weekStartFor, withAntiSpamFields };
|
|
932
|
-
export type { CalendarDay, CalendarMonth, CalendarOptions, ClientFormSpec, DateBoundParams, DatePickerWords, FieldError, FieldMarkupOptions, FieldOption, FieldOptionSource, FieldResult, FieldSpec, FormNodeLike, FormPresetChannel, FormPresetDef, FormPresetField, FormResult, FormRuntimeState, FormSpec, FormTransport, MisplacedFormContent, NestingNode, RuleDescriptor, SubmitAction, SubmitButtonView, SubmitLabels, SubmitOutcome, SubmitRequest, SubmitResponse, ValidateOptions, ValidationRule };
|
|
987
|
+
export { CALENDAR_ROWS, CHANNEL_KINDS, CHOICE_MESSAGE_KEYS, CalendarKey, ChannelKind, ChoiceAppearance, ControlType, DATE_EMPTY_ATTRIBUTE, DATE_ICON_SVG, DATE_MAX_ATTRIBUTE, DATE_MESSAGE_KEYS, DATE_MIN_ATTRIBUTE, DATE_PICKER_WORDS, DEFAULT_BUSY_WORDS, DEFAULT_EN_MESSAGES, EMAIL_TO_OWNER, FIELD_GROUP_NODE_TYPE, FIELD_NODE_TYPE, FORM_ACTIONS_ROLE, FORM_AFTER_SEND_ATTRIBUTE, FORM_AFTER_SEND_TRAIT, FORM_ANNOUNCER_ATTRIBUTE, FORM_CHANNEL_ROLE, FORM_CONTENT_TYPES, FORM_ERROR_KEYS, FORM_FIELDS_ATTRIBUTE, FORM_HONEYPOT_CLASS, FORM_NODE_TYPE, FORM_PRESETS, FORM_PRESET_WORDS_HE, FORM_STATE_ATTRIBUTE, FeedbackTiming, FormAfterSend, FormPresetId, FormRenderState, FormWordsLanguage, HONEYPOT_FIELD, IMPLIED_PATTERN, INITIAL_FORM_STATE, INTERACTIVE_HOST_TAGS, InteractiveTag, MESSAGE_NAMESPACE, OPTION_CONTROLS, PATTERN_MESSAGE_KEYS, PATTERN_PRESETS, PATTERN_PRESET_OPTIONS, PatternPreset, RENDERED_AT_FIELD, RULE_DESCRIPTORS, RULE_MESSAGE_KEYS, RuleName, RuleParamKind, STORE_ACTION, SUBMIT_BUTTON_NODE_TYPE, SUBMIT_CHECK_SVG, SUBMIT_KEEP_ENABLED_ATTRIBUTE, SUBMIT_MESSAGE_KEYS, SubmitLabelClass, addDaysIso, addMonthsIso, addableRules, applyServerErrors, baseFieldName, baselineFormWords, busyWord, calendarKeyTarget, calendarMonth, channelHref, channelOpensNewTab, channelWords, choiceAppearanceOf, clampIso, clientFormSpec, collectFieldNodes, collectFormSpec, dateBoundRules, dateOfIso, datePickerWords, deriveFieldName, emailsOwner, failureAnnouncement, fieldDateRange, fieldHtml, fieldKindWords, fieldOptionsOf, fieldSpecOf, findFormContentInHosts, firstInvalidField, formAfterSend, formChromeHtml, formContentInHost, formFieldNameMap, formFieldNames, formLanguageOf, formPresetById, formPresetIn, formWordIn, formWords, formatDateInWords, inputTypeOf, interpretSubmitResponse, isChannelFilled, isDateBoundParams, isDateField, isFormContent, isInteractiveHost, isIsoDate, isMultiValueField, isoOfDate, normaliseAnswers, onFieldBlur, onFieldChange, onSubmitAttempt, parseChannelHref, parseClientFormSpec, parseDateBound, parseFieldOptions, planFormPresetIds, presetFormActions, resetFormState, resolveDateBound, rulesFor, sentWord, shouldShowError, submitBusyWords, submitButtonLabelsHtml, submitButtonView, submitEndpointPath, submitOutcome, todayIso, uniqueFieldName, uniqueFieldNames, validateField, validateForm, weekStartFor, withAntiSpamFields };
|
|
988
|
+
export type { CalendarDay, CalendarMonth, CalendarOptions, ClientFormSpec, DateBoundParams, DatePickerWords, FieldError, FieldKindControl, FieldKindWords, FieldMarkupOptions, FieldOption, FieldOptionSource, FieldResult, FieldSpec, FormNodeLike, FormPresetChannel, FormPresetDef, FormPresetField, FormResult, FormRuntimeState, FormSpec, FormTransport, FormWordSlot, FormWords, MisplacedFormContent, NestingNode, RuleDescriptor, SubmitAction, SubmitButtonView, SubmitLabels, SubmitOutcome, SubmitRequest, SubmitResponse, ValidateOptions, ValidationRule };
|
package/package.json
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import type { ChannelKind } from './channel';
|
|
10
10
|
import { STORE_ACTION } from './collect';
|
|
11
|
+
import { channelWords } from './form-words';
|
|
11
12
|
import type { SubmitAction } from './form.model';
|
|
12
13
|
|
|
13
14
|
export enum FormPresetId {
|
|
@@ -168,7 +169,8 @@ export function formPresetById(id: string | null | undefined, lang?: string | nu
|
|
|
168
169
|
}
|
|
169
170
|
|
|
170
171
|
/** A preset's words on a Hebrew site: per field (by order) its label, help, placeholder and choices; the submit, the
|
|
171
|
-
* messages, the channel
|
|
172
|
+
* messages, the inbox name, and a channel label only where it is not the kind's own (`channelWords`). A choice's words
|
|
173
|
+
* ARE its value (`optionsText`). */
|
|
172
174
|
interface FormPresetWords {
|
|
173
175
|
formName: string;
|
|
174
176
|
fields: ReadonlyArray<Partial<Pick<FormPresetField, 'label' | 'help' | 'placeholder' | 'optionsText'>>>;
|
|
@@ -217,7 +219,6 @@ export const FORM_PRESET_WORDS_HE: Readonly<Record<`${FormPresetId}`, FormPreset
|
|
|
217
219
|
submitLabel: 'שליחה',
|
|
218
220
|
successText: 'תודה — נחזור אליכם בקרוב.',
|
|
219
221
|
errorText: 'לא הצלחנו לשלוח את הפרטים. נסו שוב — התשובות שלכם עדיין כאן.',
|
|
220
|
-
channel: 'שלחו לנו הודעה בוואטסאפ',
|
|
221
222
|
},
|
|
222
223
|
});
|
|
223
224
|
|
|
@@ -230,7 +231,8 @@ export function formPresetIn(def: FormPresetDef, lang?: string | null): FormPres
|
|
|
230
231
|
formName: he.formName,
|
|
231
232
|
fields: def.fields.map((f, i) => ({ ...f, ...(he.fields[i] ?? {}) })),
|
|
232
233
|
submitLabel: he.submitLabel, successText: he.successText, errorText: he.errorText,
|
|
233
|
-
|
|
234
|
+
// The channel's words are the kind's own (`form-words.ts`, iox-ui#159) unless the preset says otherwise.
|
|
235
|
+
...(def.channel ? { channel: { ...def.channel, label: he.channel ?? (channelWords(def.channel.kind, 'he') || def.channel.label) } } : {}),
|
|
234
236
|
};
|
|
235
237
|
}
|
|
236
238
|
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FORM WORDS — what a form part says the moment it lands on a page, in the SITE's language (iox-ui#159).
|
|
3
|
+
*
|
|
4
|
+
* ONE table for the words nobody wrote yet: a new Field's label, the plain Form's Name / Email / Send, each field kind's
|
|
5
|
+
* label and starter choices (the Forms tray's Checkbox, Radio group, …), and a second channel's words (WhatsApp, Call
|
|
6
|
+
* us, …). The builder's Form type, its field-kind presets and `addFormChannel`, and the admin's channel panel all read
|
|
7
|
+
* it — a Hebrew site gets Hebrew parts from the tray, never English it has to retype. The English column IS the
|
|
8
|
+
* baseline the builder's configs carry; `formWordIn` turns an untouched baseline word into the site's language.
|
|
9
|
+
*
|
|
10
|
+
* Data + lookups only: framework-free, like the rest of forms-core. The preset forms' own words stay in
|
|
11
|
+
* `form-presets.ts` (`FORM_PRESET_WORDS_HE`); "While sending" and "Sent" in `submit-lifecycle.ts`.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { languageOf } from '@vectoriox/iox-ui/design-core';
|
|
15
|
+
|
|
16
|
+
import type { ChannelKind } from './channel';
|
|
17
|
+
|
|
18
|
+
/** The field kinds the tray offers as their own rows — the Field's `control` values (builder `FIELD_KIND_PRESETS`). */
|
|
19
|
+
export type FieldKindControl = 'checkbox' | 'switch' | 'radio' | 'choices' | 'select' | 'range' | 'date' | 'time';
|
|
20
|
+
|
|
21
|
+
/** A field kind's seeded words: its label and, for a kind with choices, one choice per line (`optionsText`). */
|
|
22
|
+
export interface FieldKindWords {
|
|
23
|
+
label: string;
|
|
24
|
+
optionsText?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface FormWords {
|
|
28
|
+
/** A new Field's label — the Field type's own default. */
|
|
29
|
+
field: string;
|
|
30
|
+
/** The plain Form's two fields and its button. */
|
|
31
|
+
name: string;
|
|
32
|
+
email: string;
|
|
33
|
+
send: string;
|
|
34
|
+
kinds: Readonly<Record<FieldKindControl, FieldKindWords>>;
|
|
35
|
+
/** A second channel's words beside Send, by kind (premium N2). */
|
|
36
|
+
channels: Readonly<Record<`${ChannelKind}`, string>>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export enum FormWordsLanguage {
|
|
40
|
+
En = 'en',
|
|
41
|
+
He = 'he',
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const CHOICES_EN = 'First choice\nSecond choice\nThird choice';
|
|
45
|
+
const CHOICES_HE = 'אפשרות ראשונה\nאפשרות שנייה\nאפשרות שלישית';
|
|
46
|
+
|
|
47
|
+
// `@__PURE__` + literal keys: a renderer that never reads the table (the engine's field runtime) drops it.
|
|
48
|
+
const FORM_WORDS: Readonly<Record<FormWordsLanguage, FormWords>> = /* @__PURE__ */ Object.freeze({
|
|
49
|
+
en: {
|
|
50
|
+
field: 'Label',
|
|
51
|
+
name: 'Name',
|
|
52
|
+
email: 'Email',
|
|
53
|
+
send: 'Send',
|
|
54
|
+
kinds: {
|
|
55
|
+
checkbox: { label: 'I agree' },
|
|
56
|
+
switch: { label: 'Enable' },
|
|
57
|
+
radio: { label: 'Pick one', optionsText: CHOICES_EN },
|
|
58
|
+
choices: { label: 'What do you need?', optionsText: CHOICES_EN },
|
|
59
|
+
select: { label: 'Choose', optionsText: CHOICES_EN },
|
|
60
|
+
range: { label: 'How much' },
|
|
61
|
+
date: { label: 'Date' },
|
|
62
|
+
time: { label: 'Time' },
|
|
63
|
+
},
|
|
64
|
+
channels: {
|
|
65
|
+
whatsapp: 'Message us on WhatsApp',
|
|
66
|
+
phone: 'Call us',
|
|
67
|
+
email: 'Email us',
|
|
68
|
+
link: 'Book online',
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
he: {
|
|
72
|
+
field: 'שם השדה',
|
|
73
|
+
name: 'שם',
|
|
74
|
+
email: 'אימייל',
|
|
75
|
+
send: 'שליחה',
|
|
76
|
+
kinds: {
|
|
77
|
+
checkbox: { label: 'אני מאשר/ת' },
|
|
78
|
+
switch: { label: 'הפעלה' },
|
|
79
|
+
radio: { label: 'בחרו אחת', optionsText: CHOICES_HE },
|
|
80
|
+
choices: { label: 'מה אתם צריכים?', optionsText: CHOICES_HE },
|
|
81
|
+
select: { label: 'בחירה', optionsText: CHOICES_HE },
|
|
82
|
+
range: { label: 'כמה' },
|
|
83
|
+
date: { label: 'תאריך' },
|
|
84
|
+
time: { label: 'שעה' },
|
|
85
|
+
},
|
|
86
|
+
channels: {
|
|
87
|
+
whatsapp: 'שלחו לנו הודעה בוואטסאפ',
|
|
88
|
+
phone: 'התקשרו אלינו',
|
|
89
|
+
email: 'כתבו לנו',
|
|
90
|
+
link: 'הזמנה אונליין',
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
/** The language a form speaks for a `lang` attribute or site locale: design-core's subtag (`he-IL` → `he`), the old
|
|
96
|
+
* `iw` read as `he`; '' when none. */
|
|
97
|
+
export function formLanguageOf(lang: string | null | undefined): string {
|
|
98
|
+
const language = languageOf(lang);
|
|
99
|
+
return language === 'iw' ? 'he' : language;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** The words in a site's language — English for any language the table does not hold, and when none is given. */
|
|
103
|
+
export function formWords(lang?: string | null): FormWords {
|
|
104
|
+
return ownWord(FORM_WORDS, formLanguageOf(lang)) ?? FORM_WORDS[FormWordsLanguage.En];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** The baseline — what a builder config carries before anyone writes. */
|
|
108
|
+
export function baselineFormWords(): FormWords {
|
|
109
|
+
return FORM_WORDS[FormWordsLanguage.En];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** A field kind's seeded label and choices in `lang`; undefined for a control the tray does not offer as a row. */
|
|
113
|
+
export function fieldKindWords(control: string, lang?: string | null): FieldKindWords | undefined {
|
|
114
|
+
return ownWord(formWords(lang).kinds, control);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** A channel's words in `lang` ('' for an unknown kind — the caller keeps what it has). */
|
|
118
|
+
export function channelWords(kind: string, lang?: string | null): string {
|
|
119
|
+
return ownWord(formWords(lang).channels, kind) ?? '';
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** A table's own entry — never an inherited `constructor` or `toString` for a key someone typed. */
|
|
123
|
+
function ownWord<T>(table: Readonly<Record<string, T>>, key: string): T | undefined {
|
|
124
|
+
return Object.prototype.hasOwnProperty.call(table, key) ? table[key] : undefined;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** The plain-form slots `formWordIn` can carry across languages. */
|
|
128
|
+
export type FormWordSlot = 'field' | 'name' | 'email' | 'send';
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* An UNTOUCHED baseline word in `lang`: when `value` is the English word one of `slots` carries, the site language's word
|
|
132
|
+
* for that slot; anything an author wrote (or an empty value) comes back as it is. How a freshly created Form, Field or
|
|
133
|
+
* submit button speaks the site's language without a second copy of its config.
|
|
134
|
+
*/
|
|
135
|
+
export function formWordIn(value: unknown, lang: string | null | undefined, slots: readonly FormWordSlot[]): unknown {
|
|
136
|
+
if (typeof value !== 'string' || !value) return value;
|
|
137
|
+
const base = baselineFormWords();
|
|
138
|
+
const slot = slots.find(s => base[s] === value);
|
|
139
|
+
return slot ? formWords(lang)[slot] : value;
|
|
140
|
+
}
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { FeedbackTiming, FieldSpec, FormSpec } from './form.model';
|
|
13
|
+
import { formLanguageOf } from './form-words';
|
|
13
14
|
import { SubmitResponse } from './transport';
|
|
14
15
|
import { FieldError } from './validate';
|
|
15
16
|
|
|
@@ -145,13 +146,7 @@ export const SUBMIT_CHECK_SVG = `<svg class="${SubmitLabelClass.Check}" width="1
|
|
|
145
146
|
const SENT_WORDS: Readonly<Record<string, string>> = Object.freeze({ en: 'Sent', he: 'נשלח' });
|
|
146
147
|
|
|
147
148
|
export function sentWord(lang: string | null | undefined): string {
|
|
148
|
-
return SENT_WORDS[
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/** A `lang` attribute's language: `he-IL` → `he` (and the old `iw`). */
|
|
152
|
-
function languageOf(lang: string | null | undefined): string {
|
|
153
|
-
const language = String(lang ?? '').toLowerCase().split(/[-_]/)[0];
|
|
154
|
-
return language === 'iw' ? 'he' : language;
|
|
149
|
+
return SENT_WORDS[formLanguageOf(lang)] ?? SENT_WORDS['en'];
|
|
155
150
|
}
|
|
156
151
|
|
|
157
152
|
/** "While sending" in the site's language (iox-ui#158). The English one is the SubmitButton's baseline
|
|
@@ -162,7 +157,7 @@ const BUSY_WORDS: Readonly<Record<string, string>> = Object.freeze({ en: 'Sendin
|
|
|
162
157
|
export const DEFAULT_BUSY_WORDS = BUSY_WORDS['en'];
|
|
163
158
|
|
|
164
159
|
export function busyWord(lang: string | null | undefined): string {
|
|
165
|
-
return BUSY_WORDS[
|
|
160
|
+
return BUSY_WORDS[formLanguageOf(lang)] ?? DEFAULT_BUSY_WORDS;
|
|
166
161
|
}
|
|
167
162
|
|
|
168
163
|
/**
|