@vectoriox/iox-ui 5.193.0 → 5.194.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 +186 -122
- package/fesm2022/vectoriox-iox-ui-forms-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-harness-core.mjs +193 -95
- package/fesm2022/vectoriox-iox-ui-harness-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui.mjs +194 -132
- package/fesm2022/vectoriox-iox-ui.mjs.map +1 -1
- package/forms-core/index.d.ts +17 -2
- package/harness-core/index.d.ts +102 -12
- package/index.d.ts +7 -5
- package/package.json +1 -1
- package/src/forms-core/messages.ts +72 -1
- package/src/forms-core/submit-lifecycle.ts +4 -5
- package/src/harness-core/business-types.ts +14 -9
- package/src/harness-core/harness-spec.generated.ts +168 -84
- package/src/harness-core/lint.ts +29 -11
package/index.d.ts
CHANGED
|
@@ -1255,12 +1255,13 @@ interface RegisteredField {
|
|
|
1255
1255
|
*
|
|
1256
1256
|
* Translation belongs to the consumer, not the library: the CMS client has ngx-translate, the SSR
|
|
1257
1257
|
* engine has the page's locale bundle. Providing this token is how each one plugs its own in. The
|
|
1258
|
-
* default below
|
|
1259
|
-
*
|
|
1258
|
+
* default below reads forms-core's ONE message catalog (`formMessage`) in the PAGE's language — the third argument,
|
|
1259
|
+
* `pageLanguageOf` the field — so a consumer that provides nothing (the engine, the builder's Preview) shows the site's
|
|
1260
|
+
* sentences, never raw keys and never English on a Hebrew page (iox-client-engine#15).
|
|
1260
1261
|
*/
|
|
1261
|
-
type FormMessageResolver = (key: string, params?: Record<string, any
|
|
1262
|
+
type FormMessageResolver = (key: string, params?: Record<string, any>, lang?: string | null) => string;
|
|
1262
1263
|
declare const IOX_FORM_MESSAGES: InjectionToken<FormMessageResolver>;
|
|
1263
|
-
/** `{{n}}` / `{{field}}`
|
|
1264
|
+
/** The catalog's sentence in the page's language, `{{n}}` / `{{field}}` placed — forms-core `formMessage`. */
|
|
1264
1265
|
declare const defaultMessageResolver: FormMessageResolver;
|
|
1265
1266
|
/**
|
|
1266
1267
|
* Per-form runtime. **Provided by `IoxFormComponent`**, so every Field created into that form's
|
|
@@ -1531,7 +1532,8 @@ declare class IoxFieldComponent implements OnInit, AfterViewInit, OnDestroy {
|
|
|
1531
1532
|
get fieldName(): string;
|
|
1532
1533
|
/** Failing AND allowed to say so — or forced, while an author designs the state. */
|
|
1533
1534
|
get invalid(): boolean;
|
|
1534
|
-
/** The message a visitor reads
|
|
1535
|
+
/** The message a visitor reads, in the page's language (`pageLanguageOf`) — IOX_FORM_MESSAGES, whose default is
|
|
1536
|
+
* forms-core's ONE catalog (iox-client-engine#15). */
|
|
1535
1537
|
get errorText(): string;
|
|
1536
1538
|
/** The field's spec under the name its form gave it — forms-core `fieldSpecOf`, the reading the saved spec uses. */
|
|
1537
1539
|
private toSpec;
|
package/package.json
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// the page's locale bundle). The backend returns the key too, so a server-side rejection renders in
|
|
9
9
|
// the visitor's language rather than in the server's.
|
|
10
10
|
|
|
11
|
+
import { formLanguageOf } from './form-words';
|
|
11
12
|
import { RuleName } from './form.model';
|
|
12
13
|
|
|
13
14
|
/** Namespace for every forms validation key. Keep in sync with `en.json` / `he.json`. */
|
|
@@ -79,7 +80,8 @@ export const FORM_ERROR_KEYS = Object.freeze({
|
|
|
79
80
|
Server: `${MESSAGE_NAMESPACE}.form.server`,
|
|
80
81
|
});
|
|
81
82
|
|
|
82
|
-
/** The English
|
|
83
|
+
/** The English column of the ONE forms message catalog (`formMessage`) — what a site in any language the catalog does not
|
|
84
|
+
* hold reads, and what a consumer that has not added the keys yet still shows. */
|
|
83
85
|
export const DEFAULT_EN_MESSAGES: Readonly<Record<string, string>> = Object.freeze({
|
|
84
86
|
[RULE_MESSAGE_KEYS[RuleName.Required]]: 'This field is required',
|
|
85
87
|
[RULE_MESSAGE_KEYS[RuleName.MinLength]]: 'Use at least {{n}} characters',
|
|
@@ -111,3 +113,72 @@ export const DEFAULT_EN_MESSAGES: Readonly<Record<string, string>> = Object.free
|
|
|
111
113
|
[DATE_MESSAGE_KEYS.Max]: 'Choose an earlier date',
|
|
112
114
|
[SUBMIT_MESSAGE_KEYS.Sent]: 'Sent',
|
|
113
115
|
});
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The Hebrew column (iox-client-engine#15). A visitor is spoken to in the plural imperative, like every other word a site
|
|
119
|
+
* says (`form-words.ts`: בחרו, כתבו לנו). Every key of the English column has its entry here — a spec holds that.
|
|
120
|
+
*/
|
|
121
|
+
const HE_MESSAGES: Readonly<Record<string, string>> = /* @__PURE__ */ Object.freeze({
|
|
122
|
+
[RULE_MESSAGE_KEYS[RuleName.Required]]: 'שדה חובה',
|
|
123
|
+
[RULE_MESSAGE_KEYS[RuleName.MinLength]]: 'כתבו לפחות {{n}} תווים',
|
|
124
|
+
[RULE_MESSAGE_KEYS[RuleName.MaxLength]]: 'כתבו עד {{n}} תווים',
|
|
125
|
+
[RULE_MESSAGE_KEYS[RuleName.Min]]: 'הזינו {{n}} או יותר',
|
|
126
|
+
[RULE_MESSAGE_KEYS[RuleName.Max]]: 'הזינו {{n}} או פחות',
|
|
127
|
+
[RULE_MESSAGE_KEYS[RuleName.Pattern]]: 'בדקו את צורת הערך',
|
|
128
|
+
[RULE_MESSAGE_KEYS[RuleName.Matches]]: 'הערך צריך להתאים לשדה {{field}}',
|
|
129
|
+
[RULE_MESSAGE_KEYS[RuleName.Accepted]]: 'סמנו כדי להמשיך',
|
|
130
|
+
[RULE_MESSAGE_KEYS[RuleName.FileType]]: 'סוג הקובץ הזה לא מתקבל',
|
|
131
|
+
[RULE_MESSAGE_KEYS[RuleName.FileSize]]: 'הקובץ גדול מ-{{n}}MB',
|
|
132
|
+
[PATTERN_MESSAGE_KEYS['email']]: 'הזינו כתובת אימייל תקינה',
|
|
133
|
+
[PATTERN_MESSAGE_KEYS['phone']]: 'הזינו מספר טלפון תקין',
|
|
134
|
+
[PATTERN_MESSAGE_KEYS['url']]: 'הזינו כתובת אתר תקינה',
|
|
135
|
+
[PATTERN_MESSAGE_KEYS['digits']]: 'ספרות בלבד',
|
|
136
|
+
[PATTERN_MESSAGE_KEYS['letters']]: 'אותיות בלבד',
|
|
137
|
+
[PATTERN_MESSAGE_KEYS['slug']]: 'אותיות לטיניות קטנות, ספרות ומקפים',
|
|
138
|
+
[FORM_ERROR_KEYS.Network]: 'לא הצלחנו להגיע לשרת — בדקו את החיבור ונסו שוב',
|
|
139
|
+
[FORM_ERROR_KEYS.Rejected]: 'יש תשובות שצריך לתקן',
|
|
140
|
+
[FORM_ERROR_KEYS.Spam]: 'לא יכולנו לקבל את השליחה הזו',
|
|
141
|
+
[FORM_ERROR_KEYS.RateLimited]: 'יותר מדי ניסיונות — חכו רגע ונסו שוב',
|
|
142
|
+
[FORM_ERROR_KEYS.Server]: 'משהו השתבש אצלנו — התשובות שלכם עדיין כאן',
|
|
143
|
+
[RULE_MESSAGE_KEYS[RuleName.OneOf]]: 'בחרו אחת מהאפשרויות',
|
|
144
|
+
[RULE_MESSAGE_KEYS[RuleName.ValidDate]]: 'בחרו תאריך מלוח השנה',
|
|
145
|
+
[CHOICE_MESSAGE_KEYS.One]: 'בחרו אפשרות',
|
|
146
|
+
[CHOICE_MESSAGE_KEYS.Some]: 'בחרו לפחות אחת',
|
|
147
|
+
[CHOICE_MESSAGE_KEYS.Date]: 'בחרו תאריך',
|
|
148
|
+
[DATE_MESSAGE_KEYS.Min]: 'בחרו תאריך מאוחר יותר',
|
|
149
|
+
[DATE_MESSAGE_KEYS.Max]: 'בחרו תאריך מוקדם יותר',
|
|
150
|
+
[SUBMIT_MESSAGE_KEYS.Sent]: 'נשלח',
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
/** The catalog, by the language `formLanguageOf` reads. */
|
|
154
|
+
const FORM_MESSAGES: Readonly<Record<string, Readonly<Record<string, string>>>> = /* @__PURE__ */ Object.freeze({
|
|
155
|
+
en: DEFAULT_EN_MESSAGES,
|
|
156
|
+
he: HE_MESSAGES,
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
/** The languages the catalog holds. */
|
|
160
|
+
export const FORM_MESSAGE_LANGUAGES: readonly string[] = Object.freeze(['en', 'he']);
|
|
161
|
+
|
|
162
|
+
/** The whole column for `lang` (`he-IL` → he, `iw` → he) — English for a language the catalog does not hold. */
|
|
163
|
+
export function formMessages(lang?: string | null): Readonly<Record<string, string>> {
|
|
164
|
+
const language = formLanguageOf(lang);
|
|
165
|
+
return Object.prototype.hasOwnProperty.call(FORM_MESSAGES, language) ? FORM_MESSAGES[language] : DEFAULT_EN_MESSAGES;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** `{{n}}` / `{{field}}` placed where the sentence's grammar put them; a missing param reads as ''. */
|
|
169
|
+
export function interpolateMessage(template: string, params?: Readonly<Record<string, unknown>> | null): string {
|
|
170
|
+
if (!params) return template;
|
|
171
|
+
return template.replace(/\{\{(\w+)\}\}/g, (_, name: string) => String(params[name] ?? ''));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* A message KEY as the sentence a visitor reads, in the page's language — THE reading both renderers make (the
|
|
176
|
+
* component path's default `IOX_FORM_MESSAGES`, the string runtime's): `lang`'s sentence, else the English one, else the
|
|
177
|
+
* key itself (an author's own message, which travels as its text).
|
|
178
|
+
*/
|
|
179
|
+
export function formMessage(key: string, params?: Readonly<Record<string, unknown>> | null, lang?: string | null): string {
|
|
180
|
+
const own = formMessages(lang);
|
|
181
|
+
const template = Object.prototype.hasOwnProperty.call(own, key) ? own[key]
|
|
182
|
+
: Object.prototype.hasOwnProperty.call(DEFAULT_EN_MESSAGES, key) ? DEFAULT_EN_MESSAGES[key] : key;
|
|
183
|
+
return interpolateMessage(template, params);
|
|
184
|
+
}
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
import { FeedbackTiming, FieldSpec, FormSpec } from './form.model';
|
|
13
13
|
import { formLanguageOf, formWords } from './form-words';
|
|
14
|
+
import { formMessage, SUBMIT_MESSAGE_KEYS } from './messages';
|
|
14
15
|
import { SubmitResponse } from './transport';
|
|
15
16
|
import { FieldError } from './validate';
|
|
16
17
|
|
|
@@ -146,12 +147,10 @@ export enum SubmitLabelClass {
|
|
|
146
147
|
export const SUBMIT_CHECK_SVG = `<svg class="${SubmitLabelClass.Check}" width="16" height="16" viewBox="0 0 24 24" aria-hidden="true" focusable="false">` +
|
|
147
148
|
'<path d="M5 12.5l4.5 4.5L19 7.5" pathLength="100" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/></svg>';
|
|
148
149
|
|
|
149
|
-
/** "Sent" in the site's language, for a button whose author wrote no Sent words
|
|
150
|
-
*
|
|
151
|
-
const SENT_WORDS: Readonly<Record<string, string>> = Object.freeze({ en: 'Sent', he: 'נשלח' });
|
|
152
|
-
|
|
150
|
+
/** "Sent" in the site's language, for a button whose author wrote no Sent words — the forms message catalog's
|
|
151
|
+
* (`formMessage`), the document's `lang` picking, like the date picker's words. */
|
|
153
152
|
export function sentWord(lang: string | null | undefined): string {
|
|
154
|
-
return
|
|
153
|
+
return formMessage(SUBMIT_MESSAGE_KEYS.Sent, null, lang);
|
|
155
154
|
}
|
|
156
155
|
|
|
157
156
|
/** "While sending" in the site's language (iox-ui#158). The English one is the SubmitButton's baseline
|
|
@@ -82,18 +82,23 @@ export interface LookCondition {
|
|
|
82
82
|
readonly between?: ReadonlyArray<string>;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
/** A rule's line, in English and in Hebrew (vectoriox/iox-cms-client#128 — the contract's `sayHe`, gated by build-spec). */
|
|
86
|
+
export interface RuleLine {
|
|
87
87
|
readonly say: string;
|
|
88
|
+
readonly sayHe: string;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface LookRule extends RuleLine {
|
|
92
|
+
readonly when: LookCondition;
|
|
88
93
|
}
|
|
89
94
|
|
|
90
|
-
export type CheckRule =
|
|
91
|
-
| { readonly check: `${AvoidCheck.NeedsFamily}`; readonly family: string
|
|
92
|
-
| { readonly check: `${AvoidCheck.NeedsFact}`; readonly fact: FactKey
|
|
93
|
-
| { readonly check: `${AvoidCheck.ImageHero}
|
|
94
|
-
| { readonly check: `${AvoidCheck.NoPattern}`; readonly pattern: string
|
|
95
|
-
| { readonly check: `${AvoidCheck.BrandHue}`; readonly from: number; readonly to: number; readonly minChroma: number
|
|
96
|
-
| { readonly check: `${AvoidCheck.CopyLength}`; readonly max: `${CopyLength}
|
|
95
|
+
export type CheckRule = RuleLine & (
|
|
96
|
+
| { readonly check: `${AvoidCheck.NeedsFamily}`; readonly family: string }
|
|
97
|
+
| { readonly check: `${AvoidCheck.NeedsFact}`; readonly fact: FactKey }
|
|
98
|
+
| { readonly check: `${AvoidCheck.ImageHero}` }
|
|
99
|
+
| { readonly check: `${AvoidCheck.NoPattern}`; readonly pattern: string }
|
|
100
|
+
| { readonly check: `${AvoidCheck.BrandHue}`; readonly from: number; readonly to: number; readonly minChroma: number }
|
|
101
|
+
| { readonly check: `${AvoidCheck.CopyLength}`; readonly max: `${CopyLength}` });
|
|
97
102
|
|
|
98
103
|
export type AvoidRule = LookRule | CheckRule;
|
|
99
104
|
|