@colixsystems/widget-sdk 0.299.0 → 0.299.1

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
@@ -90,7 +90,11 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
90
90
 
91
91
  ## Status
92
92
 
93
- `v0.299.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**.
93
+ `v0.299.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
+
95
+ ### What's new in 0.299.1
96
+
97
+ **The installed SDK can bundle a widget's web entry again.** 0.298.0 left `src/component-props.js` out of the package, so `src/webbundle.js` failed to load from an installed copy. No contract change.
94
98
 
95
99
  ### What's new in 0.299.0 (contract 1.246.0)
96
100
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colixsystems/widget-sdk",
3
- "version": "0.299.0",
3
+ "version": "0.299.1",
4
4
  "description": "Common widget interface for AppStudio. Implements WidgetManifest, WidgetContext, property schema, and helper hooks.",
5
5
  "homepage": "https://github.com/Colix-AB/AppStudio",
6
6
  "type": "module",
@@ -57,7 +57,8 @@
57
57
  "LICENSE",
58
58
  "src/webbundle.js",
59
59
  "src/dev-shims.js",
60
- "src/contract.js"
60
+ "src/contract.js",
61
+ "src/component-props.js"
61
62
  ],
62
63
  "scripts": {
63
64
  "build": "node scripts/build.js",
@@ -0,0 +1,73 @@
1
+ // The props each SDK component cannot render without, checked only where a
2
+ // host asks for it (`ctx.strictProps`): the widget check's test render. A
3
+ // production render keeps today's behaviour and never throws. Only a prop the
4
+ // element never passes counts: one passed as undefined may be a data binding
5
+ // the test render's stub rows cannot fill, which the source cannot be blamed for.
6
+ //
7
+ // Tabs keyed by `{ value, label }` items selected nothing and reported
8
+ // undefined, and every check passed because the render only proves the
9
+ // widget renders. The table is plain data, so the check's isolate reads it.
10
+
11
+ /** The prefix a strict-mode throw carries, so the check files it as its own finding. */
12
+ export const COMPONENT_PROPS_ERROR_PREFIX = "Component props: ";
13
+
14
+ /**
15
+ * Per component: `true` for a prop that must be present, or the item fields of
16
+ * which every entry of a list prop must carry one (`key` or `value` for Tabs).
17
+ */
18
+ export const COMPONENT_PROPS = Object.freeze({
19
+ Tabs: { items: ["key", "value"] },
20
+ Select: { options: ["value"] },
21
+ RadioGroup: { options: ["value"] },
22
+ Board: { columns: ["key"] },
23
+ Button: { title: true },
24
+ IconButton: { icon: true, accessibilityLabel: true },
25
+ Badge: { label: true },
26
+ Chip: { label: true },
27
+ Banner: { message: true },
28
+ ConfirmDialog: { title: true },
29
+ Tooltip: { label: true },
30
+ });
31
+
32
+ /** A Tabs item's key: `key`, or `value` when it is shaped like a Select option. */
33
+ export function tabItemKey(item) {
34
+ return item.key !== undefined ? item.key : item.value;
35
+ }
36
+
37
+ /**
38
+ * The first finding against a component's props, or null. Self-contained and
39
+ * free of template literals: the widget check pastes its source into an
40
+ * isolate's bootstrap, which is itself a template literal.
41
+ * @param {string} component
42
+ * @param {Record<string, unknown> | null | undefined} props
43
+ * @param {Record<string, Record<string, true | string[]>>} table
44
+ * @returns {string | null}
45
+ * @example componentPropsError("Tabs", { items: [{ id: "a", label: "A" }] }, COMPONENT_PROPS)
46
+ * // "<Tabs> items[0] has no key or value; each item is { key, label }."
47
+ */
48
+ export function componentPropsError(component, props, table) {
49
+ const rules = table && table[component];
50
+ if (!rules) return null;
51
+ const p = props && typeof props === "object" ? props : {};
52
+ const tag = "<" + component + ">";
53
+ for (const prop of Object.keys(rules)) {
54
+ const rule = rules[prop];
55
+ const value = p[prop];
56
+ if (rule === true) {
57
+ if (!(prop in p)) return tag + " has no " + prop + " prop; pass " + prop + ".";
58
+ continue;
59
+ }
60
+ const shape = "{ " + rule[0] + ", label }";
61
+ if (!(prop in p)) return tag + " needs " + prop + " as an array of " + shape + ".";
62
+ if (value === undefined || value === null) continue;
63
+ if (!Array.isArray(value)) return tag + " needs " + prop + " as an array of " + shape + ".";
64
+ for (let i = 0; i < value.length; i++) {
65
+ const item = value[i];
66
+ const keyed = item && typeof item === "object" && rule.some((field) => field in item);
67
+ if (!keyed) {
68
+ return tag + " " + prop + "[" + i + "] has no " + rule.join(" or ") + "; each item is " + shape + ".";
69
+ }
70
+ }
71
+ }
72
+ return null;
73
+ }