@colixsystems/widget-sdk 0.360.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 CHANGED
@@ -56,7 +56,7 @@ The data layer lives in **four separate domain-client packages**, each instantia
56
56
  | **DATASTORE** | `useDatastoreFigure(table, { aggregate, column, filter })` (optional: options) | `{ value, text, truncated, loading, fetching, error, refetch }` | `records(table).list` (a count reads the envelope total; a sum or average up to 1000 rows) — `datastore.read:*`. One count / sum / average for a `<Stat>`, computed exactly as the built-in Stat widget does. |
57
57
  | **DATASTORE** | `useDatastoreRecord(table, id, options)` (optional: options) | `{ data, loading, fetching, error, refetch }` — a refetch of the same record keeps `data` while `fetching`; `{ includeCapabilities: true }` adds `data._capabilities` | `records(table).get` — `datastore.read:<table>` |
58
58
  | **DATASTORE** | `useDatastoreSchema(tableId)` | `{ schema, loading, error, refetch }` | `schema(tableId)` — `datastore.read:<table>` |
59
- | **DATASTORE** | `useBoundColumns(tableId, shape, props)` | `{ columns, resolved, missing, loading, error }` | `schema(tableId)` (built on `useDatastoreSchema`) — `datastore.read:<table>`. Resolves author-bound column NAMES from `props` by exact name → case-insensitive name → first unclaimed column matching `shape[key].dataType`, so a column an author renamed after install still resolves instead of `record[props.titleField]` reading `undefined`. `columns` holds the resolved NAME (`record[columns.titleField]`); `resolved` holds the full `Column`; `missing` lists non-`optional` keys that never resolved. Falsy `tableId` collapses to `{ columns: {}, resolved: {}, missing: Object.keys(shape), loading: false, error: null }`. |
59
+ | **DATASTORE** | `useBoundColumns(tableId, shape, props)` | `{ columns, resolved, missing, loading, error }` | `schema(tableId)` (built on `useDatastoreSchema`) — `datastore.read:<table>`. Resolves author-bound column NAMES from `props` by exact name → case-insensitive name. A `dataType` match alone never binds: a name that matches no column is listed in `missing` instead of showing another column. `columns` holds the resolved NAME (`record[columns.titleField]`); `resolved` holds the full `Column`; `missing` lists non-`optional` keys that never resolved. Falsy `tableId` collapses to `{ columns: {}, resolved: {}, missing: Object.keys(shape), loading: false, error: null }`. |
60
60
  | **DATASTORE** | `useInterpretDraft(tableId)` | `{ interpret, interpreting, error, result, available }` | `interpret(tableId, body)` — `datastore.read:<table>`. Turns ONE sentence a user typed ("walk at 11 am tomorrow") into DRAFT column values so a form can prefill itself. IMPERATIVE: call `interpret(text, { fields?, timeZone? })` from an event handler, never on mount. It DRAFTS and writes nothing — show the values for review, then submit through `useDatastoreMutation().create`. Resolves to `{ values, unresolved }`; `values` is keyed by column NAME (the shape `create()` takes) and `unresolved` names the fields the sentence did not state. Only text / number / boolean / date / datetime / array columns are drafted — `FILE`, `RELATION`, `USER` and `USER_GROUP` carry ids and are never guessed. Fails closed to an empty draft. **Every call spends the workspace's AI credits** and is rate-limited per actor, so call it once per user action (never on mount or in a render loop); once the workspace runs out the call is refused with a generic 429 — an app user is deliberately **not** told the workspace's billing state, since they have never heard of an AI credit and cannot buy one. Never surface a raw error to the person filling the form: say drafting is unavailable and keep every field editable by hand. `available` is false where the host brokers no interpreter. |
61
61
  | **AGENTS** | `useAgent(agentRef, { files }?)` | `{ send, cancel, reset, messages, sending, resuming, error, available, acceptsFiles, fileLimits }` | `ctx.agents` — `ai.invoke:*`. Hold a conversation with one of the WORKSPACE's own AI agents (an author-written name + system prompt). Sending is IMPERATIVE: call `send(text)` from an event handler, never on mount — the first send opens the conversation, so a widget nobody types into costs nothing. On mount the hook DOES reopen the caller's most recent thread with this agent, so a refresh or a navigation keeps the conversation instead of starting a blank one; that resume only READS and spends no credit. `resuming` is true while it runs — render a loading state, not an empty thread. `messages` is the running transcript, oldest first. You **cannot** set or read the system prompt, replay an edited transcript, or pick a model: the server assembles every turn from the stored prompt plus the stored history, and `content` is the only thing that reaches the wire. `reset()` drops the thread (a "new chat" affordance), and the new thread is the one a later mount resumes. **Every send spends the workspace's AI credits** and is rate-limited per caller AND per workspace. Rejects with `AgentError`; branch on `.code` — `AI_QUOTA_EXCEEDED` (429) is the workspace's credit ceiling and will NOT clear on a retry, unlike `RATE_LIMITED`, so never offer "try again" for it, and `AGENT_DISABLED` (409) means the author turned it off, so hide the affordance. Never surface a raw error or the workspace's billing state to an app user. `available` is false when no agent is bound or the host brokers none — render a visible unbound state, never a blank box. An assistant message that used a tool also carries **`activity`** — what the agent DID with the user's data: the table it read (with the `search` text and `filters` it read with), or the table and columns it CHANGED (never the values, and never a row the permissions refused), with `count` when a create added many rows in one step. **Render a write.** A reply saying "done!" is not evidence a row was written, and if the agent got it wrong the user has no other way to notice. A talk-only turn omits the key entirely. **Files:** with `{ files: true }` the hook asks once (no credit) whether the agent reads files — `acceptsFiles`, `fileLimits` — and `send(text, { files })` sends Filestore images or PDFs with the turn. |
62
62
  | **ACTIONS** | `useAction(actionRef)` | `{ available, run, enqueue, running, result, error }` | `ctx.actions` — `actions.run:*`. Run one of the workspace's Actions from an event handler (never on mount) and read the value it passed to `respond()`, or `enqueue` it to run later with its normal limits and no answer. The Action needs the app trigger. `available` is false when nothing is bound or the host brokers no client. Errors are `ActionError` with a stable `code`. |
@@ -93,7 +93,15 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
93
93
 
94
94
  ## Status
95
95
 
96
- `v0.360.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**.
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.
101
+
102
+ ### What's new in 0.361.0 (contract 1.297.0)
103
+
104
+ **`useBoundColumns` no longer guesses a column by type.** A key whose bound name matches no column, exactly or case-insensitively, now reads `undefined` and is listed in `missing` (unless `optional: true`). It used to take the first free column of the key's `dataType`, so a widget could show the wrong column with no warning, while the Studio's Properties panel and the preview showed the prop unbound. Pick the column in the Properties panel, or declare `ui.autoFill: { names, types }` on the `columnRef` so the Studio picks one by type when the table is chosen and stores it. `dataType` stays in the shape as the column type the key expects. Behaviour change; minor bump.
97
105
 
98
106
  ### What's new in 0.360.0 (contract 1.296.0)
99
107
 
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, textInLanguage } = require("./sdk-texts.cjs");
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
@@ -2169,9 +2169,10 @@ const HOOKS = [
2169
2169
  description:
2170
2170
  "sc-5206 — resolve author-bound column NAMES from a widget's own props, built on useDatastoreSchema. shape is " +
2171
2171
  "{ [propKey]: { dataType?, optional? } }; props is the widget's own props carrying author-bound column names (e.g. props.titleField === " +
2172
- "'Title'). Resolution order per key: (1) an exact name match on props[key], (2) a case-insensitive name match, (3) the first column whose " +
2173
- "data_type matches shape[key].dataType that no EARLIER key in this call already claimed, (4) unresolved. Unresolved NEVER throws — the key " +
2174
- "reads undefined, so a column an author renamed after install still resolves instead of crashing the widget. Returns { columns, resolved, " +
2172
+ "'Title'). Resolution order per key: (1) an exact name match on props[key], (2) a case-insensitive name match, each skipping a column an " +
2173
+ "EARLIER key in this call already claimed, (3) unresolved. A dataType match alone never binds: dataType states the column type the key " +
2174
+ "expects. Unresolved NEVER throws — the key reads undefined and is named in missing, so a stale or unset binding degrades visibly instead " +
2175
+ "of crashing the widget or showing another column. Returns { columns, resolved, " +
2175
2176
  "missing, loading, error }: columns holds the resolved column NAME — a drop-in replacement for record[props.titleField] -> " +
2176
2177
  "record[columns.titleField]; resolved holds the full Column object (snake_case verbatim, as useDatastoreSchema returns it) so a caller can " +
2177
2178
  "inspect resolved.<key>.data_type; missing lists every key whose spec is not optional:true and did not resolve. Falsy tableId collapses to " +
@@ -5667,7 +5668,7 @@ const SDK_TEXTS = Object.freeze({ ...SHARED_TRANSLATION_KEYS, ...COMPONENT_TEXTS
5667
5668
  /** `key`'s built-in text in `locale`, English when that language ships none. */
5668
5669
  function sdkText(key, locale, values) {
5669
5670
  const entry = SDK_TEXTS[key];
5670
- return entry ? textInLanguage(entry, locale, values) : key;
5671
+ return entry ? localizedText(entry, locale, values) : key;
5671
5672
  }
5672
5673
 
5673
5674
  const CONTRACT = deepFreeze({
@@ -7276,7 +7277,12 @@ const CONTRACT = deepFreeze({
7276
7277
  // 1.296.0: additive (sc-18707) — a template column may declare
7277
7278
  // `rentalStart` / `rentalEnd` (and `rentalByNight` on the end); the
7278
7279
  // server prices a rental by its days or nights.
7279
- version: "1.296.0",
7280
+ // 1.297.0: behaviour (sc-16663) — `useBoundColumns` no longer binds a key
7281
+ // to the first free column of its `dataType`; a name that matches no
7282
+ // column is `missing`, as the Studio and preview binders already showed.
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",
7280
7286
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
7281
7287
  hooks: HOOKS,
7282
7288
  primitives: PRIMITIVES,
@@ -7885,5 +7891,6 @@ module.exports = {
7885
7891
  SDK_TEXTS,
7886
7892
  sdkText,
7887
7893
  fillSdkText,
7894
+ localizedText,
7888
7895
  formatDateForDisplay,
7889
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, textInLanguage } from "./sdk-texts.js";
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({
@@ -2164,9 +2164,10 @@ const HOOKS = [
2164
2164
  description:
2165
2165
  "sc-5206 — resolve author-bound column NAMES from a widget's own props, built on useDatastoreSchema. shape is " +
2166
2166
  "{ [propKey]: { dataType?, optional? } }; props is the widget's own props carrying author-bound column names (e.g. props.titleField === " +
2167
- "'Title'). Resolution order per key: (1) an exact name match on props[key], (2) a case-insensitive name match, (3) the first column whose " +
2168
- "data_type matches shape[key].dataType that no EARLIER key in this call already claimed, (4) unresolved. Unresolved NEVER throws — the key " +
2169
- "reads undefined, so a column an author renamed after install still resolves instead of crashing the widget. Returns { columns, resolved, " +
2167
+ "'Title'). Resolution order per key: (1) an exact name match on props[key], (2) a case-insensitive name match, each skipping a column an " +
2168
+ "EARLIER key in this call already claimed, (3) unresolved. A dataType match alone never binds: dataType states the column type the key " +
2169
+ "expects. Unresolved NEVER throws — the key reads undefined and is named in missing, so a stale or unset binding degrades visibly instead " +
2170
+ "of crashing the widget or showing another column. Returns { columns, resolved, " +
2170
2171
  "missing, loading, error }: columns holds the resolved column NAME — a drop-in replacement for record[props.titleField] -> " +
2171
2172
  "record[columns.titleField]; resolved holds the full Column object (snake_case verbatim, as useDatastoreSchema returns it) so a caller can " +
2172
2173
  "inspect resolved.<key>.data_type; missing lists every key whose spec is not optional:true and did not resolve. Falsy tableId collapses to " +
@@ -5662,7 +5663,7 @@ const SDK_TEXTS = Object.freeze({ ...SHARED_TRANSLATION_KEYS, ...COMPONENT_TEXTS
5662
5663
  /** `key`'s built-in text in `locale`, English when that language ships none. */
5663
5664
  function sdkText(key, locale, values) {
5664
5665
  const entry = SDK_TEXTS[key];
5665
- return entry ? textInLanguage(entry, locale, values) : key;
5666
+ return entry ? localizedText(entry, locale, values) : key;
5666
5667
  }
5667
5668
 
5668
5669
  const CONTRACT = deepFreeze({
@@ -7271,7 +7272,12 @@ const CONTRACT = deepFreeze({
7271
7272
  // 1.296.0: additive (sc-18707) — a template column may declare
7272
7273
  // `rentalStart` / `rentalEnd` (and `rentalByNight` on the end); the
7273
7274
  // server prices a rental by its days or nights.
7274
- version: "1.296.0",
7275
+ // 1.297.0: behaviour (sc-16663) — `useBoundColumns` no longer binds a key
7276
+ // to the first free column of its `dataType`; a name that matches no
7277
+ // column is `missing`, as the Studio and preview binders already showed.
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",
7275
7281
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
7276
7282
  hooks: HOOKS,
7277
7283
  primitives: PRIMITIVES,
@@ -7880,5 +7886,6 @@ export {
7880
7886
  SDK_TEXTS,
7881
7887
  sdkText,
7882
7888
  fillSdkText,
7889
+ localizedText,
7883
7890
  formatDateForDisplay,
7884
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, textInLanguage } from "./sdk-texts.js";
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 textInLanguage(COMPONENT_TEXTS[unit === "day" ? "picker_today" : "picker_now"], locale);
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 textInLanguage(COMPONENT_TEXTS[field === "hour" ? "picker_hour" : "picker_minute"], locale);
95
+ return localizedText(COMPONENT_TEXTS[field === "hour" ? "picker_hour" : "picker_minute"], locale);
96
96
  }
97
97
 
98
98
  export function twoDigits(value) {
package/dist/hooks.js CHANGED
@@ -3393,13 +3393,6 @@ export function useDatastoreSchema(tableId) {
3393
3393
  return { schema, loading, error, refetch };
3394
3394
  }
3395
3395
 
3396
- // Columns reach widgets as wire `data_type`; manifest-derived ones carry
3397
- // `dataType`. The shipped widgets already read both — keep one reading here.
3398
- function columnType(column) {
3399
- if (!column) return undefined;
3400
- return column.data_type ?? column.dataType;
3401
- }
3402
-
3403
3396
  // Identity for the claimed-set. Falls back to the name so an id-less column
3404
3397
  // can't claim `undefined` and starve every later key.
3405
3398
  function columnKey(column) {
@@ -3415,12 +3408,14 @@ function columnKey(column) {
3415
3408
  * (e.g. `props.titleField === "Title"`).
3416
3409
  *
3417
3410
  * Resolution order per key: (1) an exact `name` match on `props[key]`,
3418
- * (2) a case-insensitive name match, (3) the first column whose `dataType`
3419
- * matches `shape[key].dataType` that no EARLIER key in this same call
3420
- * already claimed (so two RELATION columns in one shape don't both resolve
3421
- * to the same column), (4) unresolved. Unresolved never throws — the key
3422
- * simply reads `undefined` — so a column an author renamed after install,
3423
- * or never bound, degrades instead of crashing.
3411
+ * (2) a case-insensitive name match, each skipping a column an EARLIER key in
3412
+ * this same call already claimed, (3) unresolved. A `dataType` match alone
3413
+ * never binds (sc-16663): it showed the wrong column with no warning, and the
3414
+ * Studio and preview binders never guess without a `ui.autoFill` hint.
3415
+ * `dataType` states the column type the key expects. Unresolved never
3416
+ * throws — the key reads `undefined` and is named in `missing` — so a
3417
+ * column an author renamed after install, or never bound, degrades visibly
3418
+ * instead of crashing.
3424
3419
  *
3425
3420
  * Returns `{ columns, resolved, missing, loading, error }`. `columns` holds
3426
3421
  * the resolved column NAME — a drop-in replacement for
@@ -3523,24 +3518,9 @@ export function useBoundColumns(tableId, shape, props) {
3523
3518
  });
3524
3519
 
3525
3520
  for (const key of stillUnresolved) {
3526
- const spec = shape[key] || {};
3527
- // Columns reach widgets as wire `data_type`, but manifest-derived ones
3528
- // carry `dataType` — read both, as the shipped widgets already do.
3529
- const types = spec.dataType
3530
- ? Array.isArray(spec.dataType)
3531
- ? spec.dataType
3532
- : [spec.dataType]
3533
- : null;
3534
- const match =
3535
- types &&
3536
- schemaColumns.find((c) => free(c) && types.includes(columnType(c)));
3537
- if (match) {
3538
- take(key, match);
3539
- } else {
3540
- columns[key] = undefined;
3541
- resolved[key] = undefined;
3542
- if (spec.optional !== true) missing.push(key);
3543
- }
3521
+ columns[key] = undefined;
3522
+ resolved[key] = undefined;
3523
+ if ((shape[key] || {}).optional !== true) missing.push(key);
3544
3524
  }
3545
3525
  return { columns, resolved, missing, loading, error };
3546
3526
  // eslint-disable-next-line react-hooks/exhaustive-deps
package/dist/index.d.ts CHANGED
@@ -2134,6 +2134,7 @@ export function useDatastoreSchema(
2134
2134
 
2135
2135
  /** sc-5206 — one prop key `useBoundColumns` resolves to a schema column. */
2136
2136
  export interface BoundColumnSpec {
2137
+ /** The column type the key expects. Never picks a column on its own. */
2137
2138
  dataType?: string | string[];
2138
2139
  /** When true, an unresolved key is omitted from `missing`. */
2139
2140
  optional?: boolean;
@@ -2154,11 +2155,10 @@ export interface BoundColumnsResult {
2154
2155
 
2155
2156
  /**
2156
2157
  * sc-5206 — resolve author-bound column NAMES from a widget's own props,
2157
- * built on `useDatastoreSchema`. Falls back name -> case-insensitive name ->
2158
- * first unclaimed column matching `dataType`, so a column an author renamed
2159
- * after install still resolves. Never throws for a missing column — an
2160
- * unresolved key reads `undefined` and, when not `optional: true`, is named
2161
- * in `missing`. Falsy `tableId` collapses to `{ columns: {}, resolved: {},
2158
+ * built on `useDatastoreSchema`. Matches the bound name exactly, then
2159
+ * case-insensitively; a `dataType` match alone never binds. Never throws for a
2160
+ * missing column — an unresolved key reads `undefined` and, when not
2161
+ * `optional: true`, is named in `missing`. Falsy `tableId` collapses to `{ columns: {}, resolved: {},
2162
2162
  * missing: Object.keys(shape), loading: false, error: null }`.
2163
2163
  */
2164
2164
  export function useBoundColumns<TProps = Record<string, unknown>>(
@@ -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
@@ -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
@@ -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 textInLanguage(entry, locale, values) {
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
- textInLanguage,
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 textInLanguage(entry, locale, values) {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colixsystems/widget-sdk",
3
- "version": "0.360.0",
3
+ "version": "0.362.0",
4
4
  "description": "Common widget interface for AppStudio. Implements WidgetManifest, WidgetContext, property schema, and helper hooks.",
5
5
  "repository": {
6
6
  "type": "git",
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, textInLanguage } from "./sdk-texts.js";
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({
@@ -2164,9 +2164,10 @@ const HOOKS = [
2164
2164
  description:
2165
2165
  "sc-5206 — resolve author-bound column NAMES from a widget's own props, built on useDatastoreSchema. shape is " +
2166
2166
  "{ [propKey]: { dataType?, optional? } }; props is the widget's own props carrying author-bound column names (e.g. props.titleField === " +
2167
- "'Title'). Resolution order per key: (1) an exact name match on props[key], (2) a case-insensitive name match, (3) the first column whose " +
2168
- "data_type matches shape[key].dataType that no EARLIER key in this call already claimed, (4) unresolved. Unresolved NEVER throws — the key " +
2169
- "reads undefined, so a column an author renamed after install still resolves instead of crashing the widget. Returns { columns, resolved, " +
2167
+ "'Title'). Resolution order per key: (1) an exact name match on props[key], (2) a case-insensitive name match, each skipping a column an " +
2168
+ "EARLIER key in this call already claimed, (3) unresolved. A dataType match alone never binds: dataType states the column type the key " +
2169
+ "expects. Unresolved NEVER throws — the key reads undefined and is named in missing, so a stale or unset binding degrades visibly instead " +
2170
+ "of crashing the widget or showing another column. Returns { columns, resolved, " +
2170
2171
  "missing, loading, error }: columns holds the resolved column NAME — a drop-in replacement for record[props.titleField] -> " +
2171
2172
  "record[columns.titleField]; resolved holds the full Column object (snake_case verbatim, as useDatastoreSchema returns it) so a caller can " +
2172
2173
  "inspect resolved.<key>.data_type; missing lists every key whose spec is not optional:true and did not resolve. Falsy tableId collapses to " +
@@ -5662,7 +5663,7 @@ const SDK_TEXTS = Object.freeze({ ...SHARED_TRANSLATION_KEYS, ...COMPONENT_TEXTS
5662
5663
  /** `key`'s built-in text in `locale`, English when that language ships none. */
5663
5664
  function sdkText(key, locale, values) {
5664
5665
  const entry = SDK_TEXTS[key];
5665
- return entry ? textInLanguage(entry, locale, values) : key;
5666
+ return entry ? localizedText(entry, locale, values) : key;
5666
5667
  }
5667
5668
 
5668
5669
  const CONTRACT = deepFreeze({
@@ -7271,7 +7272,12 @@ const CONTRACT = deepFreeze({
7271
7272
  // 1.296.0: additive (sc-18707) — a template column may declare
7272
7273
  // `rentalStart` / `rentalEnd` (and `rentalByNight` on the end); the
7273
7274
  // server prices a rental by its days or nights.
7274
- version: "1.296.0",
7275
+ // 1.297.0: behaviour (sc-16663) — `useBoundColumns` no longer binds a key
7276
+ // to the first free column of its `dataType`; a name that matches no
7277
+ // column is `missing`, as the Studio and preview binders already showed.
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",
7275
7281
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
7276
7282
  hooks: HOOKS,
7277
7283
  primitives: PRIMITIVES,
@@ -7880,5 +7886,6 @@ export {
7880
7886
  SDK_TEXTS,
7881
7887
  sdkText,
7882
7888
  fillSdkText,
7889
+ localizedText,
7883
7890
  formatDateForDisplay,
7884
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 textInLanguage(entry, locale, values) {
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);