@colixsystems/widget-sdk 0.337.1 → 0.337.2

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
@@ -91,7 +91,11 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
91
91
 
92
92
  ## Status
93
93
 
94
- `v0.337.1` — 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**.
94
+ `v0.337.2` — 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**.
95
+
96
+ ### What's new in 0.337.2 (contract 1.275.0)
97
+
98
+ **A `mode="datetime"` `<DateTimePicker>` works on Android.** Android has no combined date-and-time dialog, so the field opens the date dialog and then the time dialog, and emits once both are answered. Before, it showed only the date dialog, kept the time of day it opened with, and the widget crashed as the dialog closed (`Cannot read property 'dismiss' of undefined`). Cancelling either dialog changes nothing. iOS keeps its single date-and-time picker. Fix-only: no prop or export changed.
95
99
 
96
100
  ### What's new in 0.337.1 (contract 1.275.0)
97
101
 
@@ -0,0 +1,29 @@
1
+ // REQ-WSDK-PLATFORM §6 — the dialogs the native `<DateTimePicker>` walks
2
+ // through. Pure, so it is unit-tested without React Native.
3
+
4
+ /**
5
+ * The OS dialog modes one pick opens, in order. Android has no combined
6
+ * dialog, and its picker library cannot dismiss a "datetime" one.
7
+ *
8
+ * @param {"date" | "time" | "datetime"} mode
9
+ * @param {string} os — `Platform.OS`.
10
+ * @returns {Array<"date" | "time" | "datetime">}
11
+ */
12
+ export function osDialogModes(mode, os) {
13
+ return mode === "datetime" && os === "android" ? ["date", "time"] : [mode];
14
+ }
15
+
16
+ /**
17
+ * The draft parts with the fields one dialog answered taken from `picked`.
18
+ *
19
+ * @param {{year: number, month: number, day: number, hours: number, minutes: number}} draft
20
+ * @param {Date} picked
21
+ * @param {"date" | "time" | "datetime"} dialogMode
22
+ */
23
+ export function applyDialogPick(draft, picked, dialogMode) {
24
+ const date = { year: picked.getFullYear(), month: picked.getMonth(), day: picked.getDate() };
25
+ const time = { hours: picked.getHours(), minutes: picked.getMinutes() };
26
+ if (dialogMode === "date") return { ...draft, ...date };
27
+ if (dialogMode === "time") return { ...draft, ...time };
28
+ return { ...draft, ...date, ...time };
29
+ }
@@ -9,7 +9,8 @@ import RNDateTimePicker from "@react-native-community/datetimepicker";
9
9
  import { View, Pressable, Platform } from "react-native";
10
10
  import { Text } from "./bounded-text.native.js";
11
11
  import { makeDateTimePicker } from "./datetimepicker-view.js";
12
- import { nowParts, partsToDate, valueToParts } from "./datetimepicker-format.js";
12
+ import { nowParts, partsToDate } from "./datetimepicker-format.js";
13
+ import { osDialogModes, applyDialogPick } from "./datetimepicker-os-steps.js";
13
14
  import { clampToBounds } from "./datetimepicker-calendar.js";
14
15
 
15
16
  function boundDate(parts, mode) {
@@ -17,23 +18,43 @@ function boundDate(parts, mode) {
17
18
  return partsToDate(parts);
18
19
  }
19
20
 
20
- function OsPicker({ open, onClose, mode, parts, bounds, onPick }) {
21
+ function OsPicker({ open, ...dialog }) {
21
22
  if (!open) return null;
22
- const start = parts ? { ...nowParts(), ...dropEmpty(parts) } : clampToBounds(nowParts(), bounds);
23
+ return React.createElement(OsDialogs, dialog);
24
+ }
25
+
26
+ // Mounted per pick, so each one starts from the field's current value.
27
+ function OsDialogs({ onClose, mode, parts, bounds, onPick }) {
28
+ const modes = osDialogModes(mode, Platform.OS);
29
+ const [step, setStep] = React.useState(0);
30
+ const [draft, setDraft] = React.useState(() =>
31
+ parts ? { ...nowParts(), ...dropEmpty(parts) } : clampToBounds(nowParts(), bounds),
32
+ );
33
+ const latest = React.useRef(null);
34
+ latest.current = { onClose, onPick, bounds, modes, step, draft };
35
+ // Stable: Android reopens its dialog whenever onChange changes.
36
+ const onChange = React.useCallback((event, picked) => {
37
+ const { onClose, onPick, bounds, modes, step, draft } = latest.current;
38
+ // Android reports a cancelled dialog as "dismissed".
39
+ const cancelled = (event && event.type === "dismissed") || !(picked instanceof Date);
40
+ const next = cancelled ? null : applyDialogPick(draft, picked, modes[step]);
41
+ if (next && step + 1 < modes.length) {
42
+ setDraft(next);
43
+ setStep(step + 1);
44
+ return;
45
+ }
46
+ onClose();
47
+ // Android's time dialog cannot be bounded, so a pick is clamped here.
48
+ if (next) onPick(clampToBounds(next, bounds));
49
+ }, []);
50
+ const dialogMode = modes[step];
23
51
  return React.createElement(RNDateTimePicker, {
24
- value: partsToDate(start),
25
- // iOS honours "datetime"; Android shows its date dialog for it.
26
- mode,
27
- minimumDate: boundDate(bounds.min, mode),
28
- maximumDate: boundDate(bounds.max, mode),
29
- onChange: (event, picked) => {
30
- onClose();
31
- // Android reports a cancelled dialog as "dismissed".
32
- if (event && event.type === "dismissed") return;
33
- if (!(picked instanceof Date)) return;
34
- // Android's time dialog cannot be bounded, so a pick is clamped here.
35
- onPick(clampToBounds(valueToParts(picked.toISOString(), "datetime"), bounds));
36
- },
52
+ key: dialogMode,
53
+ value: partsToDate(draft),
54
+ mode: dialogMode,
55
+ minimumDate: boundDate(bounds.min, dialogMode),
56
+ maximumDate: boundDate(bounds.max, dialogMode),
57
+ onChange,
37
58
  });
38
59
  }
39
60
 
package/dist/host.d.ts CHANGED
@@ -473,6 +473,13 @@ export function isDarkSurface(input?: {
473
473
  theme?: unknown;
474
474
  } | null): boolean;
475
475
 
476
+ /** sc-17703 — how the signed-in visitor's account button is drawn. */
477
+ export type AccountButtonStyle = "name" | "avatar";
478
+ export const ACCOUNT_BUTTON_STYLES: readonly AccountButtonStyle[];
479
+ export const DEFAULT_ACCOUNT_BUTTON_STYLE: AccountButtonStyle;
480
+ /** The account button's style from a whole `theme_config`; unset is "name". */
481
+ export function resolveAccountButtonStyle(theme: unknown): AccountButtonStyle;
482
+
476
483
  /** The logo a surface draws: the dark-surface variant only beside an app logo. */
477
484
  export function resolveAppLogo<T>(
478
485
  logo: T | null | undefined,
package/dist/host.js CHANGED
@@ -131,6 +131,9 @@ export {
131
131
  topNavigationPageIds,
132
132
  isDarkSurface,
133
133
  resolveAppLogo,
134
+ ACCOUNT_BUTTON_STYLES,
135
+ DEFAULT_ACCOUNT_BUTTON_STYLE,
136
+ resolveAccountButtonStyle,
134
137
  } from "./navigation.js";
135
138
 
136
139
  // sc-5717: the codec behind `useWidgetRoute()` — how a widget's own internal
@@ -918,6 +918,26 @@ function borderWidthOr(...values) {
918
918
  }
919
919
  return BORDER_WIDTH_MIN;
920
920
  }
921
+
922
+ // sc-17703: how the signed-in visitor's account button is drawn. `name` is the
923
+ // avatar, name and chevron pill. `avatar` is the bare avatar circle, which
924
+ // leaves the app's brand more room. Both open the same account menu.
925
+ const ACCOUNT_BUTTON_STYLES = ["name", "avatar"];
926
+ const DEFAULT_ACCOUNT_BUTTON_STYLE = "name";
927
+
928
+ /**
929
+ * The account button's style, resolved for every host.
930
+ *
931
+ * @param {unknown} theme — the whole `theme_config`.
932
+ * @returns {"name"|"avatar"}
933
+ */
934
+ function resolveAccountButtonStyle(theme) {
935
+ const config = isPlainObject(theme) ? theme : {};
936
+ const account = isPlainObject(config.account) ? config.account : {};
937
+ return ACCOUNT_BUTTON_STYLES.includes(account.buttonStyle)
938
+ ? account.buttonStyle
939
+ : DEFAULT_ACCOUNT_BUTTON_STYLE;
940
+ }
921
941
  module.exports = {
922
942
  normaliseNavigation,
923
943
  menuItemCap,
@@ -950,4 +970,7 @@ module.exports = {
950
970
  resolvePageBars,
951
971
  drawsTopNavigation,
952
972
  topNavigationPageIds,
973
+ ACCOUNT_BUTTON_STYLES,
974
+ DEFAULT_ACCOUNT_BUTTON_STYLE,
975
+ resolveAccountButtonStyle,
953
976
  };
@@ -913,3 +913,23 @@ function borderWidthOr(...values) {
913
913
  }
914
914
  return BORDER_WIDTH_MIN;
915
915
  }
916
+
917
+ // sc-17703: how the signed-in visitor's account button is drawn. `name` is the
918
+ // avatar, name and chevron pill. `avatar` is the bare avatar circle, which
919
+ // leaves the app's brand more room. Both open the same account menu.
920
+ export const ACCOUNT_BUTTON_STYLES = ["name", "avatar"];
921
+ export const DEFAULT_ACCOUNT_BUTTON_STYLE = "name";
922
+
923
+ /**
924
+ * The account button's style, resolved for every host.
925
+ *
926
+ * @param {unknown} theme — the whole `theme_config`.
927
+ * @returns {"name"|"avatar"}
928
+ */
929
+ export function resolveAccountButtonStyle(theme) {
930
+ const config = isPlainObject(theme) ? theme : {};
931
+ const account = isPlainObject(config.account) ? config.account : {};
932
+ return ACCOUNT_BUTTON_STYLES.includes(account.buttonStyle)
933
+ ? account.buttonStyle
934
+ : DEFAULT_ACCOUNT_BUTTON_STYLE;
935
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colixsystems/widget-sdk",
3
- "version": "0.337.1",
3
+ "version": "0.337.2",
4
4
  "description": "Common widget interface for AppStudio. Implements WidgetManifest, WidgetContext, property schema, and helper hooks.",
5
5
  "repository": {
6
6
  "type": "git",