@colixsystems/widget-sdk 0.361.0 → 0.362.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 +5 -1
- package/dist/contract.cjs +6 -3
- package/dist/contract.js +6 -3
- package/dist/datetimepicker-names.js +3 -3
- package/dist/index.d.ts +22 -0
- package/dist/index.js +1 -0
- package/dist/index.native.js +1 -0
- package/dist/sdk-texts.cjs +11 -3
- package/dist/sdk-texts.js +10 -2
- package/package.json +1 -1
- package/src/contract.js +6 -3
- package/src/sdk-texts.js +10 -2
package/README.md
CHANGED
|
@@ -93,7 +93,11 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
93
93
|
|
|
94
94
|
## Status
|
|
95
95
|
|
|
96
|
-
`v0.
|
|
96
|
+
`v0.362.0` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
|
|
97
|
+
|
|
98
|
+
### What's new in 0.362.0 (contract 1.298.0)
|
|
99
|
+
|
|
100
|
+
**`localizedText(entry, locale, values)` reads a text in the app's language. It is for the platform's built-in widgets.** An entry holds one text per language, English required: `{ en: "Upload failed.", sv: "Uppladdningen misslyckades." }`. It reads the exact locale, then its primary language (`sv-SE` reads `sv`), then English, and fills each `{name}` slot from `values`. Norwegian written `no` or `nn` reads an entry's `nb` text. The SDK's own default texts ship only English and Swedish, so Norwegian still reads English there. A count text ships `{ one, other }` per language and takes the form `values.count` needs (`Intl.PluralRules`), `other` without a count. A plain string entry, such as a workspace's own wording, only has its slots filled. Text read through it never reaches the workspace's Translations admin, so a marketplace widget ships its text in `manifest.translations` and reads it with `useI18n().t()` instead. Additive.
|
|
97
101
|
|
|
98
102
|
### What's new in 0.361.0 (contract 1.297.0)
|
|
99
103
|
|
package/dist/contract.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
5
|
const { COMPONENT_PROPS, COMPONENT_PROPS_ERROR_PREFIX, componentPropsError, tabItemKey } = require("./component-props.cjs");
|
|
6
|
-
const { COMPONENT_TEXTS, fillSdkText,
|
|
6
|
+
const { COMPONENT_TEXTS, fillSdkText, localizedText } = require("./sdk-texts.cjs");
|
|
7
7
|
const { formatDateForDisplay } = require("./date-label.cjs");
|
|
8
8
|
|
|
9
9
|
// The widget SDK contract: the ONE source the linter, the AI agents, the
|
|
@@ -5668,7 +5668,7 @@ const SDK_TEXTS = Object.freeze({ ...SHARED_TRANSLATION_KEYS, ...COMPONENT_TEXTS
|
|
|
5668
5668
|
/** `key`'s built-in text in `locale`, English when that language ships none. */
|
|
5669
5669
|
function sdkText(key, locale, values) {
|
|
5670
5670
|
const entry = SDK_TEXTS[key];
|
|
5671
|
-
return entry ?
|
|
5671
|
+
return entry ? localizedText(entry, locale, values) : key;
|
|
5672
5672
|
}
|
|
5673
5673
|
|
|
5674
5674
|
const CONTRACT = deepFreeze({
|
|
@@ -7280,7 +7280,9 @@ const CONTRACT = deepFreeze({
|
|
|
7280
7280
|
// 1.297.0: behaviour (sc-16663) — `useBoundColumns` no longer binds a key
|
|
7281
7281
|
// to the first free column of its `dataType`; a name that matches no
|
|
7282
7282
|
// column is `missing`, as the Studio and preview binders already showed.
|
|
7283
|
-
|
|
7283
|
+
// 1.298.0 (sc-18635): additive — `localizedText(entry, locale, values)`
|
|
7284
|
+
// reads a nine-language text table; `no` and `nn` read `nb`.
|
|
7285
|
+
version: "1.298.0",
|
|
7284
7286
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7285
7287
|
hooks: HOOKS,
|
|
7286
7288
|
primitives: PRIMITIVES,
|
|
@@ -7889,5 +7891,6 @@ module.exports = {
|
|
|
7889
7891
|
SDK_TEXTS,
|
|
7890
7892
|
sdkText,
|
|
7891
7893
|
fillSdkText,
|
|
7894
|
+
localizedText,
|
|
7892
7895
|
formatDateForDisplay,
|
|
7893
7896
|
};
|
package/dist/contract.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// the compiler's generated layout `elevationStyles`, and widgets reading
|
|
10
10
|
// `useTheme().elevation` — so a widget shadow and a container shadow match.
|
|
11
11
|
import { COMPONENT_PROPS, COMPONENT_PROPS_ERROR_PREFIX, componentPropsError, tabItemKey } from "./component-props.js";
|
|
12
|
-
import { COMPONENT_TEXTS, fillSdkText,
|
|
12
|
+
import { COMPONENT_TEXTS, fillSdkText, localizedText } from "./sdk-texts.js";
|
|
13
13
|
import { formatDateForDisplay } from "./date-label.js";
|
|
14
14
|
|
|
15
15
|
const ELEVATION = Object.freeze({
|
|
@@ -5663,7 +5663,7 @@ const SDK_TEXTS = Object.freeze({ ...SHARED_TRANSLATION_KEYS, ...COMPONENT_TEXTS
|
|
|
5663
5663
|
/** `key`'s built-in text in `locale`, English when that language ships none. */
|
|
5664
5664
|
function sdkText(key, locale, values) {
|
|
5665
5665
|
const entry = SDK_TEXTS[key];
|
|
5666
|
-
return entry ?
|
|
5666
|
+
return entry ? localizedText(entry, locale, values) : key;
|
|
5667
5667
|
}
|
|
5668
5668
|
|
|
5669
5669
|
const CONTRACT = deepFreeze({
|
|
@@ -7275,7 +7275,9 @@ const CONTRACT = deepFreeze({
|
|
|
7275
7275
|
// 1.297.0: behaviour (sc-16663) — `useBoundColumns` no longer binds a key
|
|
7276
7276
|
// to the first free column of its `dataType`; a name that matches no
|
|
7277
7277
|
// column is `missing`, as the Studio and preview binders already showed.
|
|
7278
|
-
|
|
7278
|
+
// 1.298.0 (sc-18635): additive — `localizedText(entry, locale, values)`
|
|
7279
|
+
// reads a nine-language text table; `no` and `nn` read `nb`.
|
|
7280
|
+
version: "1.298.0",
|
|
7279
7281
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7280
7282
|
hooks: HOOKS,
|
|
7281
7283
|
primitives: PRIMITIVES,
|
|
@@ -7884,5 +7886,6 @@ export {
|
|
|
7884
7886
|
SDK_TEXTS,
|
|
7885
7887
|
sdkText,
|
|
7886
7888
|
fillSdkText,
|
|
7889
|
+
localizedText,
|
|
7887
7890
|
formatDateForDisplay,
|
|
7888
7891
|
};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { normaliseMode, partsToDate } from "./datetimepicker-format.js";
|
|
5
5
|
import { WEEK_LENGTH } from "./datetimepicker-calendar.js";
|
|
6
|
-
import { COMPONENT_TEXTS,
|
|
6
|
+
import { COMPONENT_TEXTS, localizedText } from "./sdk-texts.js";
|
|
7
7
|
|
|
8
8
|
const ENGLISH_MONTHS = [
|
|
9
9
|
"January", "February", "March", "April", "May", "June",
|
|
@@ -80,7 +80,7 @@ export function relativeNowLabel(locale, mode) {
|
|
|
80
80
|
const text = new Intl.RelativeTimeFormat(locale || undefined, { numeric: "auto" }).format(0, unit);
|
|
81
81
|
return capitalise(text, locale);
|
|
82
82
|
} catch {
|
|
83
|
-
return
|
|
83
|
+
return localizedText(COMPONENT_TEXTS[unit === "day" ? "picker_today" : "picker_now"], locale);
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -92,7 +92,7 @@ export function fieldName(locale, field) {
|
|
|
92
92
|
} catch {
|
|
93
93
|
// Older engines and Hermes lack `dateTimeField`.
|
|
94
94
|
}
|
|
95
|
-
return
|
|
95
|
+
return localizedText(COMPONENT_TEXTS[field === "hour" ? "picker_hour" : "picker_minute"], locale);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
export function twoDigits(value) {
|
package/dist/index.d.ts
CHANGED
|
@@ -6545,6 +6545,28 @@ export interface MarkdownInputHandle {
|
|
|
6545
6545
|
insertText(text: string): boolean;
|
|
6546
6546
|
}
|
|
6547
6547
|
|
|
6548
|
+
// ------------------------------------------------------- localized text
|
|
6549
|
+
|
|
6550
|
+
/** One text in each language it ships, English required; a count text has `one` / `other` forms. */
|
|
6551
|
+
export type LocalizedTextEntry = { en: string | { one: string; other: string } } & Record<
|
|
6552
|
+
string,
|
|
6553
|
+
string | { one: string; other: string }
|
|
6554
|
+
>;
|
|
6555
|
+
|
|
6556
|
+
/**
|
|
6557
|
+
* `entry`'s text in `locale`, each `{name}` slot filled from `values`. Reads
|
|
6558
|
+
* the exact locale, then its primary language (`sv-SE` reads `sv`; `no` and
|
|
6559
|
+
* `nn` read `nb`), then English. A count text takes the form `values.count`
|
|
6560
|
+
* needs in that language, `other` without a count. A plain string entry only
|
|
6561
|
+
* has its slots filled. For the platform's built-in widgets: a marketplace
|
|
6562
|
+
* widget ships its text in `manifest.translations` and reads it with `useI18n().t`.
|
|
6563
|
+
*/
|
|
6564
|
+
export function localizedText(
|
|
6565
|
+
entry: LocalizedTextEntry | string,
|
|
6566
|
+
locale: string | null | undefined,
|
|
6567
|
+
values?: Record<string, string | number>,
|
|
6568
|
+
): string;
|
|
6569
|
+
|
|
6548
6570
|
// ------------------------------------------------------- theme derivation
|
|
6549
6571
|
// sc-3696: the colour maths both hosts resolve `useTheme()` with. Exported so
|
|
6550
6572
|
// the Player (frontend/src/services/widgetTheme.js) and the exported app's
|
package/dist/index.js
CHANGED
|
@@ -233,6 +233,7 @@ export {
|
|
|
233
233
|
hexAlphaPercent,
|
|
234
234
|
clampSpacingScale,
|
|
235
235
|
scaleSpacing,
|
|
236
|
+
localizedText,
|
|
236
237
|
} from "./contract.js";
|
|
237
238
|
// sc-8104 — the curated emoji set ships WITH the SDK (plain string data, no
|
|
238
239
|
// dependency), and the reaction model is shared so Newsfeed and Chat group
|
package/dist/index.native.js
CHANGED
|
@@ -226,6 +226,7 @@ export {
|
|
|
226
226
|
hexAlphaPercent,
|
|
227
227
|
clampSpacingScale,
|
|
228
228
|
scaleSpacing,
|
|
229
|
+
localizedText,
|
|
229
230
|
} from "./contract.js";
|
|
230
231
|
// sc-8104 — the curated emoji set ships WITH the SDK (plain string data, no
|
|
231
232
|
// dependency), and the reaction model is shared so Newsfeed and Chat group
|
package/dist/sdk-texts.cjs
CHANGED
|
@@ -123,6 +123,9 @@ const COMPONENT_TEXTS = Object.freeze({
|
|
|
123
123
|
link_address_label: { en: "Link address", sv: "Länkadress" },
|
|
124
124
|
});
|
|
125
125
|
|
|
126
|
+
// Norwegian turns up as "no" and "nn" as well as "nb"; Bokmål reads for all three.
|
|
127
|
+
const LANGUAGE_ALIASES = Object.freeze({ no: "nb", nn: "nb" });
|
|
128
|
+
|
|
126
129
|
/** The language of `entry` that `locale` reads: itself, its primary language (`sv-SE` reads `sv`), else English. */
|
|
127
130
|
function languageIn(entry, locale) {
|
|
128
131
|
const ships = (language) => Object.prototype.hasOwnProperty.call(entry, language);
|
|
@@ -130,6 +133,8 @@ function languageIn(entry, locale) {
|
|
|
130
133
|
if (ships(locale)) return locale;
|
|
131
134
|
const primary = locale.split(/[-_]/)[0].toLowerCase();
|
|
132
135
|
if (ships(primary)) return primary;
|
|
136
|
+
const alias = LANGUAGE_ALIASES[primary];
|
|
137
|
+
if (alias && ships(alias)) return alias;
|
|
133
138
|
}
|
|
134
139
|
return "en";
|
|
135
140
|
}
|
|
@@ -144,9 +149,12 @@ function pluralCategory(language, count) {
|
|
|
144
149
|
|
|
145
150
|
/**
|
|
146
151
|
* `entry`'s text in `locale`, slots filled from `values`. A plural text takes
|
|
147
|
-
* the form `values.count` needs, and `other` when no count is given.
|
|
152
|
+
* the form `values.count` needs, and `other` when no count is given. A plain
|
|
153
|
+
* string entry is already in its language and only has its slots filled.
|
|
148
154
|
*/
|
|
149
|
-
function
|
|
155
|
+
function localizedText(entry, locale, values) {
|
|
156
|
+
if (typeof entry === "string") return fillSdkText(entry, values);
|
|
157
|
+
if (!entry || typeof entry !== "object") return "";
|
|
150
158
|
const language = languageIn(entry, locale);
|
|
151
159
|
const text = entry[language];
|
|
152
160
|
if (typeof text === "string") return fillSdkText(text, values);
|
|
@@ -164,6 +172,6 @@ function fillSdkText(text, values) {
|
|
|
164
172
|
}
|
|
165
173
|
module.exports = {
|
|
166
174
|
COMPONENT_TEXTS,
|
|
167
|
-
|
|
175
|
+
localizedText,
|
|
168
176
|
fillSdkText,
|
|
169
177
|
};
|
package/dist/sdk-texts.js
CHANGED
|
@@ -119,6 +119,9 @@ export const COMPONENT_TEXTS = Object.freeze({
|
|
|
119
119
|
link_address_label: { en: "Link address", sv: "Länkadress" },
|
|
120
120
|
});
|
|
121
121
|
|
|
122
|
+
// Norwegian turns up as "no" and "nn" as well as "nb"; Bokmål reads for all three.
|
|
123
|
+
const LANGUAGE_ALIASES = Object.freeze({ no: "nb", nn: "nb" });
|
|
124
|
+
|
|
122
125
|
/** The language of `entry` that `locale` reads: itself, its primary language (`sv-SE` reads `sv`), else English. */
|
|
123
126
|
function languageIn(entry, locale) {
|
|
124
127
|
const ships = (language) => Object.prototype.hasOwnProperty.call(entry, language);
|
|
@@ -126,6 +129,8 @@ function languageIn(entry, locale) {
|
|
|
126
129
|
if (ships(locale)) return locale;
|
|
127
130
|
const primary = locale.split(/[-_]/)[0].toLowerCase();
|
|
128
131
|
if (ships(primary)) return primary;
|
|
132
|
+
const alias = LANGUAGE_ALIASES[primary];
|
|
133
|
+
if (alias && ships(alias)) return alias;
|
|
129
134
|
}
|
|
130
135
|
return "en";
|
|
131
136
|
}
|
|
@@ -140,9 +145,12 @@ function pluralCategory(language, count) {
|
|
|
140
145
|
|
|
141
146
|
/**
|
|
142
147
|
* `entry`'s text in `locale`, slots filled from `values`. A plural text takes
|
|
143
|
-
* the form `values.count` needs, and `other` when no count is given.
|
|
148
|
+
* the form `values.count` needs, and `other` when no count is given. A plain
|
|
149
|
+
* string entry is already in its language and only has its slots filled.
|
|
144
150
|
*/
|
|
145
|
-
export function
|
|
151
|
+
export function localizedText(entry, locale, values) {
|
|
152
|
+
if (typeof entry === "string") return fillSdkText(entry, values);
|
|
153
|
+
if (!entry || typeof entry !== "object") return "";
|
|
146
154
|
const language = languageIn(entry, locale);
|
|
147
155
|
const text = entry[language];
|
|
148
156
|
if (typeof text === "string") return fillSdkText(text, values);
|
package/package.json
CHANGED
package/src/contract.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// the compiler's generated layout `elevationStyles`, and widgets reading
|
|
10
10
|
// `useTheme().elevation` — so a widget shadow and a container shadow match.
|
|
11
11
|
import { COMPONENT_PROPS, COMPONENT_PROPS_ERROR_PREFIX, componentPropsError, tabItemKey } from "./component-props.js";
|
|
12
|
-
import { COMPONENT_TEXTS, fillSdkText,
|
|
12
|
+
import { COMPONENT_TEXTS, fillSdkText, localizedText } from "./sdk-texts.js";
|
|
13
13
|
import { formatDateForDisplay } from "./date-label.js";
|
|
14
14
|
|
|
15
15
|
const ELEVATION = Object.freeze({
|
|
@@ -5663,7 +5663,7 @@ const SDK_TEXTS = Object.freeze({ ...SHARED_TRANSLATION_KEYS, ...COMPONENT_TEXTS
|
|
|
5663
5663
|
/** `key`'s built-in text in `locale`, English when that language ships none. */
|
|
5664
5664
|
function sdkText(key, locale, values) {
|
|
5665
5665
|
const entry = SDK_TEXTS[key];
|
|
5666
|
-
return entry ?
|
|
5666
|
+
return entry ? localizedText(entry, locale, values) : key;
|
|
5667
5667
|
}
|
|
5668
5668
|
|
|
5669
5669
|
const CONTRACT = deepFreeze({
|
|
@@ -7275,7 +7275,9 @@ const CONTRACT = deepFreeze({
|
|
|
7275
7275
|
// 1.297.0: behaviour (sc-16663) — `useBoundColumns` no longer binds a key
|
|
7276
7276
|
// to the first free column of its `dataType`; a name that matches no
|
|
7277
7277
|
// column is `missing`, as the Studio and preview binders already showed.
|
|
7278
|
-
|
|
7278
|
+
// 1.298.0 (sc-18635): additive — `localizedText(entry, locale, values)`
|
|
7279
|
+
// reads a nine-language text table; `no` and `nn` read `nb`.
|
|
7280
|
+
version: "1.298.0",
|
|
7279
7281
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7280
7282
|
hooks: HOOKS,
|
|
7281
7283
|
primitives: PRIMITIVES,
|
|
@@ -7884,5 +7886,6 @@ export {
|
|
|
7884
7886
|
SDK_TEXTS,
|
|
7885
7887
|
sdkText,
|
|
7886
7888
|
fillSdkText,
|
|
7889
|
+
localizedText,
|
|
7887
7890
|
formatDateForDisplay,
|
|
7888
7891
|
};
|
package/src/sdk-texts.js
CHANGED
|
@@ -119,6 +119,9 @@ export const COMPONENT_TEXTS = Object.freeze({
|
|
|
119
119
|
link_address_label: { en: "Link address", sv: "Länkadress" },
|
|
120
120
|
});
|
|
121
121
|
|
|
122
|
+
// Norwegian turns up as "no" and "nn" as well as "nb"; Bokmål reads for all three.
|
|
123
|
+
const LANGUAGE_ALIASES = Object.freeze({ no: "nb", nn: "nb" });
|
|
124
|
+
|
|
122
125
|
/** The language of `entry` that `locale` reads: itself, its primary language (`sv-SE` reads `sv`), else English. */
|
|
123
126
|
function languageIn(entry, locale) {
|
|
124
127
|
const ships = (language) => Object.prototype.hasOwnProperty.call(entry, language);
|
|
@@ -126,6 +129,8 @@ function languageIn(entry, locale) {
|
|
|
126
129
|
if (ships(locale)) return locale;
|
|
127
130
|
const primary = locale.split(/[-_]/)[0].toLowerCase();
|
|
128
131
|
if (ships(primary)) return primary;
|
|
132
|
+
const alias = LANGUAGE_ALIASES[primary];
|
|
133
|
+
if (alias && ships(alias)) return alias;
|
|
129
134
|
}
|
|
130
135
|
return "en";
|
|
131
136
|
}
|
|
@@ -140,9 +145,12 @@ function pluralCategory(language, count) {
|
|
|
140
145
|
|
|
141
146
|
/**
|
|
142
147
|
* `entry`'s text in `locale`, slots filled from `values`. A plural text takes
|
|
143
|
-
* the form `values.count` needs, and `other` when no count is given.
|
|
148
|
+
* the form `values.count` needs, and `other` when no count is given. A plain
|
|
149
|
+
* string entry is already in its language and only has its slots filled.
|
|
144
150
|
*/
|
|
145
|
-
export function
|
|
151
|
+
export function localizedText(entry, locale, values) {
|
|
152
|
+
if (typeof entry === "string") return fillSdkText(entry, values);
|
|
153
|
+
if (!entry || typeof entry !== "object") return "";
|
|
146
154
|
const language = languageIn(entry, locale);
|
|
147
155
|
const text = entry[language];
|
|
148
156
|
if (typeof text === "string") return fillSdkText(text, values);
|