@colixsystems/widget-sdk 0.308.0 → 0.313.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 +36 -5
- package/dist/contract.cjs +109 -18
- package/dist/contract.js +109 -18
- package/dist/devserver.js +4 -30
- package/dist/flatten-entry.js +30 -0
- package/dist/hooks.js +3 -2
- package/dist/host.d.ts +10 -0
- package/dist/host.js +4 -0
- package/dist/index.d.ts +5 -2
- package/dist/linter.cjs +149 -26
- package/dist/linter.js +149 -26
- package/dist/webbundle.js +1 -1
- package/package.json +13 -7
- package/src/contract.js +109 -18
- package/src/webbundle.js +1 -1
package/dist/linter.cjs
CHANGED
|
@@ -2276,6 +2276,30 @@ function _openTagStack() {
|
|
|
2276
2276
|
};
|
|
2277
2277
|
}
|
|
2278
2278
|
|
|
2279
|
+
/**
|
|
2280
|
+
* The next opening tag in `structure` from `_JSX_TOKEN_RE`'s position, keeping
|
|
2281
|
+
* `open` in step with the fragments and closing tags passed on the way.
|
|
2282
|
+
*/
|
|
2283
|
+
function _nextOpeningTag(structure, open, fragmentFrame) {
|
|
2284
|
+
let token;
|
|
2285
|
+
while ((token = _JSX_TOKEN_RE.exec(structure))) {
|
|
2286
|
+
const [, closing, name] = token;
|
|
2287
|
+
if (!name) {
|
|
2288
|
+
// A fragment, `<>` or `</>`; any other `<` is a comparison.
|
|
2289
|
+
if (structure[token.index + 1 + closing.length] !== ">") continue;
|
|
2290
|
+
if (closing) open.pop();
|
|
2291
|
+
else open.push(fragmentFrame(token));
|
|
2292
|
+
continue;
|
|
2293
|
+
}
|
|
2294
|
+
if (closing) {
|
|
2295
|
+
open.close(name);
|
|
2296
|
+
continue;
|
|
2297
|
+
}
|
|
2298
|
+
return token;
|
|
2299
|
+
}
|
|
2300
|
+
return null;
|
|
2301
|
+
}
|
|
2302
|
+
|
|
2279
2303
|
function _fieldInBorderedRowRules(source) {
|
|
2280
2304
|
const findings = [];
|
|
2281
2305
|
const scan = {
|
|
@@ -2310,19 +2334,8 @@ function _fieldInBorderedRowRules(source) {
|
|
|
2310
2334
|
const open = _openTagStack();
|
|
2311
2335
|
_JSX_TOKEN_RE.lastIndex = 0;
|
|
2312
2336
|
let token;
|
|
2313
|
-
while ((token =
|
|
2314
|
-
const
|
|
2315
|
-
if (!name) {
|
|
2316
|
-
// A fragment, `<>` or `</>`; any other `<` is a comparison.
|
|
2317
|
-
if (structure[token.index + 1 + closing.length] !== ">") continue;
|
|
2318
|
-
if (closing) open.pop();
|
|
2319
|
-
else open.push(null);
|
|
2320
|
-
continue;
|
|
2321
|
-
}
|
|
2322
|
-
if (closing) {
|
|
2323
|
-
open.close(name);
|
|
2324
|
-
continue;
|
|
2325
|
-
}
|
|
2337
|
+
while ((token = _nextOpeningTag(structure, open, () => null))) {
|
|
2338
|
+
const name = token[2];
|
|
2326
2339
|
const end = scan.index.tagEnd(token.index);
|
|
2327
2340
|
if (end === -1) break;
|
|
2328
2341
|
const tag = { name, attrs: [token.index + token[0].length, end], borderedRow: undefined };
|
|
@@ -2386,20 +2399,14 @@ function _gridCellWidthRules(source) {
|
|
|
2386
2399
|
const open = _openTagStack();
|
|
2387
2400
|
_JSX_TOKEN_RE.lastIndex = 0;
|
|
2388
2401
|
let token;
|
|
2389
|
-
|
|
2390
|
-
|
|
2402
|
+
// A fragment is transparent: its children are its parent's children.
|
|
2403
|
+
const fragment = () => {
|
|
2404
|
+
const parent = open.top();
|
|
2405
|
+
return { name: "", narrow: parent && parent.narrow, cell: parent && parent.cell };
|
|
2406
|
+
};
|
|
2407
|
+
while ((token = _nextOpeningTag(structure, open, fragment))) {
|
|
2408
|
+
const name = token[2];
|
|
2391
2409
|
const parent = open.top();
|
|
2392
|
-
if (!name) {
|
|
2393
|
-
if (structure[token.index + 1 + closing.length] !== ">") continue;
|
|
2394
|
-
// A fragment is transparent: its children are its parent's children.
|
|
2395
|
-
if (closing) open.pop();
|
|
2396
|
-
else open.push({ name: "", narrow: parent && parent.narrow, cell: parent && parent.cell });
|
|
2397
|
-
continue;
|
|
2398
|
-
}
|
|
2399
|
-
if (closing) {
|
|
2400
|
-
open.close(name);
|
|
2401
|
-
continue;
|
|
2402
|
-
}
|
|
2403
2410
|
const end = index.tagEnd(token.index);
|
|
2404
2411
|
if (end === -1) break;
|
|
2405
2412
|
const tag = { name, narrow: undefined, cell: parent && parent.cell };
|
|
@@ -2429,6 +2436,120 @@ function _gridCellWidthRules(source) {
|
|
|
2429
2436
|
return findings;
|
|
2430
2437
|
}
|
|
2431
2438
|
|
|
2439
|
+
// sc-16682 — two sibling patterns a production build's widgets shipped.
|
|
2440
|
+
//
|
|
2441
|
+
// An action beside an <EmptyState> sits outside its panel; EmptyState takes
|
|
2442
|
+
// its action as `children`. Flagged when a Button or Pressable is the next
|
|
2443
|
+
// element after an EmptyState, or the first child of the View that is.
|
|
2444
|
+
//
|
|
2445
|
+
// Field labels in two styles: one field given the SDK `label`, another
|
|
2446
|
+
// labelled by a <Text> drawn just before it, so the two labels render in
|
|
2447
|
+
// different type. Only a Text that is the control's previous sibling counts
|
|
2448
|
+
// as its label, which keeps a heading above a whole form out of it.
|
|
2449
|
+
const _EMPTY_STATE_ACTION_TAGS = new Set(["Button", "Pressable"]);
|
|
2450
|
+
const _SELF_LABELLED_FIELD_TAGS = new Set([
|
|
2451
|
+
"TextField",
|
|
2452
|
+
"Select",
|
|
2453
|
+
"RadioGroup",
|
|
2454
|
+
"PeoplePicker",
|
|
2455
|
+
"FileUpload",
|
|
2456
|
+
"FormField",
|
|
2457
|
+
]);
|
|
2458
|
+
const _LABELLABLE_CONTROL_TAGS = new Set([
|
|
2459
|
+
..._SELF_LABELLED_FIELD_TAGS,
|
|
2460
|
+
"TextInput",
|
|
2461
|
+
"ChipGroup",
|
|
2462
|
+
"DateTimePicker",
|
|
2463
|
+
]);
|
|
2464
|
+
const _LABEL_ATTR_RE = /(?:^|\s)label\s*=/;
|
|
2465
|
+
|
|
2466
|
+
function _siblingRules(source) {
|
|
2467
|
+
if (!source.includes("<EmptyState") && !source.includes("label")) return [];
|
|
2468
|
+
const structure = _stripNonCode(source);
|
|
2469
|
+
const index = _jsxScanIndex(structure);
|
|
2470
|
+
const lineAt = _lineCounter(structure);
|
|
2471
|
+
const sourceLines = source.split(/\r?\n/);
|
|
2472
|
+
const findings = [];
|
|
2473
|
+
const report = (rule, at, label) => {
|
|
2474
|
+
const line = lineAt(at);
|
|
2475
|
+
findings.push({
|
|
2476
|
+
rule,
|
|
2477
|
+
severity: "warning",
|
|
2478
|
+
label,
|
|
2479
|
+
line,
|
|
2480
|
+
snippet: (sourceLines[line - 1] || "").trim().slice(0, 200),
|
|
2481
|
+
});
|
|
2482
|
+
};
|
|
2483
|
+
// Not when the two are alternatives (`empty ? <EmptyState /> : <Button />`)
|
|
2484
|
+
// or sit in separate expressions (`{a && <EmptyState />}{b && <Button />}`).
|
|
2485
|
+
const renderedTogether = (emptyState, at) => {
|
|
2486
|
+
let depth = 0;
|
|
2487
|
+
for (let i = emptyState.at; i < at; i++) {
|
|
2488
|
+
const ch = structure[i];
|
|
2489
|
+
if (ch === "{") depth++;
|
|
2490
|
+
else if (ch === "}" && --depth < 0) return false;
|
|
2491
|
+
else if (ch === ":" && depth === 0) return false;
|
|
2492
|
+
}
|
|
2493
|
+
return true;
|
|
2494
|
+
};
|
|
2495
|
+
const afterEmptyState = (tag) =>
|
|
2496
|
+
tag && tag.name === "EmptyState" ? tag : null;
|
|
2497
|
+
let sdkLabelled = null;
|
|
2498
|
+
let ownLabelled = null;
|
|
2499
|
+
const open = _openTagStack();
|
|
2500
|
+
_JSX_TOKEN_RE.lastIndex = 0;
|
|
2501
|
+
let token;
|
|
2502
|
+
const fragment = (at) => ({ name: "", at: at.index, before: null, last: null });
|
|
2503
|
+
while ((token = _nextOpeningTag(structure, open, fragment))) {
|
|
2504
|
+
const name = token[2];
|
|
2505
|
+
// `useState<Item>` and `a<B` are not tags.
|
|
2506
|
+
if (/[\w$)\]]/.test(structure[token.index - 1] || "")) continue;
|
|
2507
|
+
const end = index.tagEnd(token.index);
|
|
2508
|
+
if (end === -1) break;
|
|
2509
|
+
const parent = open.top();
|
|
2510
|
+
const before = parent ? parent.last : null;
|
|
2511
|
+
const tag = { name, at: token.index, before, last: null };
|
|
2512
|
+
if (parent) parent.last = tag;
|
|
2513
|
+
if (_EMPTY_STATE_ACTION_TAGS.has(name) && parent) {
|
|
2514
|
+
const emptyState =
|
|
2515
|
+
afterEmptyState(before) ||
|
|
2516
|
+
(parent.name === "View" && !before ? afterEmptyState(parent.before) : null);
|
|
2517
|
+
if (emptyState && renderedTogether(emptyState, token.index)) {
|
|
2518
|
+
report(
|
|
2519
|
+
"empty-state-action-outside",
|
|
2520
|
+
token.index,
|
|
2521
|
+
`This <${name}> sits beside the <EmptyState>, outside its panel. ` +
|
|
2522
|
+
`EmptyState takes its action as children: ` +
|
|
2523
|
+
`<EmptyState title={…}><Button title={…} onPress={…} /></EmptyState> ` +
|
|
2524
|
+
`draws it inside the panel, under the message.`,
|
|
2525
|
+
);
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
if (_LABELLABLE_CONTROL_TAGS.has(name)) {
|
|
2529
|
+
const labelled = _LABEL_ATTR_RE.test(structure.slice(token.index + token[0].length, end));
|
|
2530
|
+
if (labelled && _SELF_LABELLED_FIELD_TAGS.has(name)) {
|
|
2531
|
+
if (!sdkLabelled) sdkLabelled = tag;
|
|
2532
|
+
} else if (!labelled && before && before.name === "Text") {
|
|
2533
|
+
if (!ownLabelled) ownLabelled = { tag, label: before };
|
|
2534
|
+
}
|
|
2535
|
+
}
|
|
2536
|
+
if (!_selfClosing(structure, end)) open.push(tag);
|
|
2537
|
+
_JSX_TOKEN_RE.lastIndex = end + 1;
|
|
2538
|
+
}
|
|
2539
|
+
if (sdkLabelled && ownLabelled) {
|
|
2540
|
+
report(
|
|
2541
|
+
"field-label-styles-mixed",
|
|
2542
|
+
ownLabelled.label.at,
|
|
2543
|
+
`This <Text> labels the <${ownLabelled.tag.name}> after it, while ` +
|
|
2544
|
+
`line ${lineAt(sdkLabelled.at)} gives <${sdkLabelled.name}> the ` +
|
|
2545
|
+
`SDK label, so the form shows labels in two styles. Label every ` +
|
|
2546
|
+
`field one way: the label prop, or <FormField label> round a ` +
|
|
2547
|
+
`control that has none.`,
|
|
2548
|
+
);
|
|
2549
|
+
}
|
|
2550
|
+
return findings;
|
|
2551
|
+
}
|
|
2552
|
+
|
|
2432
2553
|
// sc-4913 — a measured frame INCLUDES the element's own padding.
|
|
2433
2554
|
//
|
|
2434
2555
|
// `onLayout` reports the frame width, and padding sits inside that frame. A
|
|
@@ -3264,6 +3385,8 @@ function lintSource(source, options) {
|
|
|
3264
3385
|
findings.push(..._fieldInBorderedRowRules(source));
|
|
3265
3386
|
// sc-15754 — a Grid cell under 200px holding more than one Text is refused.
|
|
3266
3387
|
findings.push(..._gridCellWidthRules(source));
|
|
3388
|
+
// sc-16682 — soft warnings: an action beside an EmptyState, mixed field labels.
|
|
3389
|
+
findings.push(..._siblingRules(source));
|
|
3267
3390
|
// sc-4913 — soft warning: a measured width that includes the widget's own
|
|
3268
3391
|
// padding wraps the last grid column into an empty one.
|
|
3269
3392
|
findings.push(..._measuredPaddingRules(source));
|
package/dist/linter.js
CHANGED
|
@@ -2271,6 +2271,30 @@ function _openTagStack() {
|
|
|
2271
2271
|
};
|
|
2272
2272
|
}
|
|
2273
2273
|
|
|
2274
|
+
/**
|
|
2275
|
+
* The next opening tag in `structure` from `_JSX_TOKEN_RE`'s position, keeping
|
|
2276
|
+
* `open` in step with the fragments and closing tags passed on the way.
|
|
2277
|
+
*/
|
|
2278
|
+
function _nextOpeningTag(structure, open, fragmentFrame) {
|
|
2279
|
+
let token;
|
|
2280
|
+
while ((token = _JSX_TOKEN_RE.exec(structure))) {
|
|
2281
|
+
const [, closing, name] = token;
|
|
2282
|
+
if (!name) {
|
|
2283
|
+
// A fragment, `<>` or `</>`; any other `<` is a comparison.
|
|
2284
|
+
if (structure[token.index + 1 + closing.length] !== ">") continue;
|
|
2285
|
+
if (closing) open.pop();
|
|
2286
|
+
else open.push(fragmentFrame(token));
|
|
2287
|
+
continue;
|
|
2288
|
+
}
|
|
2289
|
+
if (closing) {
|
|
2290
|
+
open.close(name);
|
|
2291
|
+
continue;
|
|
2292
|
+
}
|
|
2293
|
+
return token;
|
|
2294
|
+
}
|
|
2295
|
+
return null;
|
|
2296
|
+
}
|
|
2297
|
+
|
|
2274
2298
|
function _fieldInBorderedRowRules(source) {
|
|
2275
2299
|
const findings = [];
|
|
2276
2300
|
const scan = {
|
|
@@ -2305,19 +2329,8 @@ function _fieldInBorderedRowRules(source) {
|
|
|
2305
2329
|
const open = _openTagStack();
|
|
2306
2330
|
_JSX_TOKEN_RE.lastIndex = 0;
|
|
2307
2331
|
let token;
|
|
2308
|
-
while ((token =
|
|
2309
|
-
const
|
|
2310
|
-
if (!name) {
|
|
2311
|
-
// A fragment, `<>` or `</>`; any other `<` is a comparison.
|
|
2312
|
-
if (structure[token.index + 1 + closing.length] !== ">") continue;
|
|
2313
|
-
if (closing) open.pop();
|
|
2314
|
-
else open.push(null);
|
|
2315
|
-
continue;
|
|
2316
|
-
}
|
|
2317
|
-
if (closing) {
|
|
2318
|
-
open.close(name);
|
|
2319
|
-
continue;
|
|
2320
|
-
}
|
|
2332
|
+
while ((token = _nextOpeningTag(structure, open, () => null))) {
|
|
2333
|
+
const name = token[2];
|
|
2321
2334
|
const end = scan.index.tagEnd(token.index);
|
|
2322
2335
|
if (end === -1) break;
|
|
2323
2336
|
const tag = { name, attrs: [token.index + token[0].length, end], borderedRow: undefined };
|
|
@@ -2381,20 +2394,14 @@ function _gridCellWidthRules(source) {
|
|
|
2381
2394
|
const open = _openTagStack();
|
|
2382
2395
|
_JSX_TOKEN_RE.lastIndex = 0;
|
|
2383
2396
|
let token;
|
|
2384
|
-
|
|
2385
|
-
|
|
2397
|
+
// A fragment is transparent: its children are its parent's children.
|
|
2398
|
+
const fragment = () => {
|
|
2399
|
+
const parent = open.top();
|
|
2400
|
+
return { name: "", narrow: parent && parent.narrow, cell: parent && parent.cell };
|
|
2401
|
+
};
|
|
2402
|
+
while ((token = _nextOpeningTag(structure, open, fragment))) {
|
|
2403
|
+
const name = token[2];
|
|
2386
2404
|
const parent = open.top();
|
|
2387
|
-
if (!name) {
|
|
2388
|
-
if (structure[token.index + 1 + closing.length] !== ">") continue;
|
|
2389
|
-
// A fragment is transparent: its children are its parent's children.
|
|
2390
|
-
if (closing) open.pop();
|
|
2391
|
-
else open.push({ name: "", narrow: parent && parent.narrow, cell: parent && parent.cell });
|
|
2392
|
-
continue;
|
|
2393
|
-
}
|
|
2394
|
-
if (closing) {
|
|
2395
|
-
open.close(name);
|
|
2396
|
-
continue;
|
|
2397
|
-
}
|
|
2398
2405
|
const end = index.tagEnd(token.index);
|
|
2399
2406
|
if (end === -1) break;
|
|
2400
2407
|
const tag = { name, narrow: undefined, cell: parent && parent.cell };
|
|
@@ -2424,6 +2431,120 @@ function _gridCellWidthRules(source) {
|
|
|
2424
2431
|
return findings;
|
|
2425
2432
|
}
|
|
2426
2433
|
|
|
2434
|
+
// sc-16682 — two sibling patterns a production build's widgets shipped.
|
|
2435
|
+
//
|
|
2436
|
+
// An action beside an <EmptyState> sits outside its panel; EmptyState takes
|
|
2437
|
+
// its action as `children`. Flagged when a Button or Pressable is the next
|
|
2438
|
+
// element after an EmptyState, or the first child of the View that is.
|
|
2439
|
+
//
|
|
2440
|
+
// Field labels in two styles: one field given the SDK `label`, another
|
|
2441
|
+
// labelled by a <Text> drawn just before it, so the two labels render in
|
|
2442
|
+
// different type. Only a Text that is the control's previous sibling counts
|
|
2443
|
+
// as its label, which keeps a heading above a whole form out of it.
|
|
2444
|
+
const _EMPTY_STATE_ACTION_TAGS = new Set(["Button", "Pressable"]);
|
|
2445
|
+
const _SELF_LABELLED_FIELD_TAGS = new Set([
|
|
2446
|
+
"TextField",
|
|
2447
|
+
"Select",
|
|
2448
|
+
"RadioGroup",
|
|
2449
|
+
"PeoplePicker",
|
|
2450
|
+
"FileUpload",
|
|
2451
|
+
"FormField",
|
|
2452
|
+
]);
|
|
2453
|
+
const _LABELLABLE_CONTROL_TAGS = new Set([
|
|
2454
|
+
..._SELF_LABELLED_FIELD_TAGS,
|
|
2455
|
+
"TextInput",
|
|
2456
|
+
"ChipGroup",
|
|
2457
|
+
"DateTimePicker",
|
|
2458
|
+
]);
|
|
2459
|
+
const _LABEL_ATTR_RE = /(?:^|\s)label\s*=/;
|
|
2460
|
+
|
|
2461
|
+
function _siblingRules(source) {
|
|
2462
|
+
if (!source.includes("<EmptyState") && !source.includes("label")) return [];
|
|
2463
|
+
const structure = _stripNonCode(source);
|
|
2464
|
+
const index = _jsxScanIndex(structure);
|
|
2465
|
+
const lineAt = _lineCounter(structure);
|
|
2466
|
+
const sourceLines = source.split(/\r?\n/);
|
|
2467
|
+
const findings = [];
|
|
2468
|
+
const report = (rule, at, label) => {
|
|
2469
|
+
const line = lineAt(at);
|
|
2470
|
+
findings.push({
|
|
2471
|
+
rule,
|
|
2472
|
+
severity: "warning",
|
|
2473
|
+
label,
|
|
2474
|
+
line,
|
|
2475
|
+
snippet: (sourceLines[line - 1] || "").trim().slice(0, 200),
|
|
2476
|
+
});
|
|
2477
|
+
};
|
|
2478
|
+
// Not when the two are alternatives (`empty ? <EmptyState /> : <Button />`)
|
|
2479
|
+
// or sit in separate expressions (`{a && <EmptyState />}{b && <Button />}`).
|
|
2480
|
+
const renderedTogether = (emptyState, at) => {
|
|
2481
|
+
let depth = 0;
|
|
2482
|
+
for (let i = emptyState.at; i < at; i++) {
|
|
2483
|
+
const ch = structure[i];
|
|
2484
|
+
if (ch === "{") depth++;
|
|
2485
|
+
else if (ch === "}" && --depth < 0) return false;
|
|
2486
|
+
else if (ch === ":" && depth === 0) return false;
|
|
2487
|
+
}
|
|
2488
|
+
return true;
|
|
2489
|
+
};
|
|
2490
|
+
const afterEmptyState = (tag) =>
|
|
2491
|
+
tag && tag.name === "EmptyState" ? tag : null;
|
|
2492
|
+
let sdkLabelled = null;
|
|
2493
|
+
let ownLabelled = null;
|
|
2494
|
+
const open = _openTagStack();
|
|
2495
|
+
_JSX_TOKEN_RE.lastIndex = 0;
|
|
2496
|
+
let token;
|
|
2497
|
+
const fragment = (at) => ({ name: "", at: at.index, before: null, last: null });
|
|
2498
|
+
while ((token = _nextOpeningTag(structure, open, fragment))) {
|
|
2499
|
+
const name = token[2];
|
|
2500
|
+
// `useState<Item>` and `a<B` are not tags.
|
|
2501
|
+
if (/[\w$)\]]/.test(structure[token.index - 1] || "")) continue;
|
|
2502
|
+
const end = index.tagEnd(token.index);
|
|
2503
|
+
if (end === -1) break;
|
|
2504
|
+
const parent = open.top();
|
|
2505
|
+
const before = parent ? parent.last : null;
|
|
2506
|
+
const tag = { name, at: token.index, before, last: null };
|
|
2507
|
+
if (parent) parent.last = tag;
|
|
2508
|
+
if (_EMPTY_STATE_ACTION_TAGS.has(name) && parent) {
|
|
2509
|
+
const emptyState =
|
|
2510
|
+
afterEmptyState(before) ||
|
|
2511
|
+
(parent.name === "View" && !before ? afterEmptyState(parent.before) : null);
|
|
2512
|
+
if (emptyState && renderedTogether(emptyState, token.index)) {
|
|
2513
|
+
report(
|
|
2514
|
+
"empty-state-action-outside",
|
|
2515
|
+
token.index,
|
|
2516
|
+
`This <${name}> sits beside the <EmptyState>, outside its panel. ` +
|
|
2517
|
+
`EmptyState takes its action as children: ` +
|
|
2518
|
+
`<EmptyState title={…}><Button title={…} onPress={…} /></EmptyState> ` +
|
|
2519
|
+
`draws it inside the panel, under the message.`,
|
|
2520
|
+
);
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
if (_LABELLABLE_CONTROL_TAGS.has(name)) {
|
|
2524
|
+
const labelled = _LABEL_ATTR_RE.test(structure.slice(token.index + token[0].length, end));
|
|
2525
|
+
if (labelled && _SELF_LABELLED_FIELD_TAGS.has(name)) {
|
|
2526
|
+
if (!sdkLabelled) sdkLabelled = tag;
|
|
2527
|
+
} else if (!labelled && before && before.name === "Text") {
|
|
2528
|
+
if (!ownLabelled) ownLabelled = { tag, label: before };
|
|
2529
|
+
}
|
|
2530
|
+
}
|
|
2531
|
+
if (!_selfClosing(structure, end)) open.push(tag);
|
|
2532
|
+
_JSX_TOKEN_RE.lastIndex = end + 1;
|
|
2533
|
+
}
|
|
2534
|
+
if (sdkLabelled && ownLabelled) {
|
|
2535
|
+
report(
|
|
2536
|
+
"field-label-styles-mixed",
|
|
2537
|
+
ownLabelled.label.at,
|
|
2538
|
+
`This <Text> labels the <${ownLabelled.tag.name}> after it, while ` +
|
|
2539
|
+
`line ${lineAt(sdkLabelled.at)} gives <${sdkLabelled.name}> the ` +
|
|
2540
|
+
`SDK label, so the form shows labels in two styles. Label every ` +
|
|
2541
|
+
`field one way: the label prop, or <FormField label> round a ` +
|
|
2542
|
+
`control that has none.`,
|
|
2543
|
+
);
|
|
2544
|
+
}
|
|
2545
|
+
return findings;
|
|
2546
|
+
}
|
|
2547
|
+
|
|
2427
2548
|
// sc-4913 — a measured frame INCLUDES the element's own padding.
|
|
2428
2549
|
//
|
|
2429
2550
|
// `onLayout` reports the frame width, and padding sits inside that frame. A
|
|
@@ -3259,6 +3380,8 @@ export function lintSource(source, options) {
|
|
|
3259
3380
|
findings.push(..._fieldInBorderedRowRules(source));
|
|
3260
3381
|
// sc-15754 — a Grid cell under 200px holding more than one Text is refused.
|
|
3261
3382
|
findings.push(..._gridCellWidthRules(source));
|
|
3383
|
+
// sc-16682 — soft warnings: an action beside an EmptyState, mixed field labels.
|
|
3384
|
+
findings.push(..._siblingRules(source));
|
|
3262
3385
|
// sc-4913 — soft warning: a measured width that includes the widget's own
|
|
3263
3386
|
// padding wraps the last grid column into an empty one.
|
|
3264
3387
|
findings.push(..._measuredPaddingRules(source));
|
package/dist/webbundle.js
CHANGED
|
@@ -40,7 +40,7 @@ export async function loadEsbuild() {
|
|
|
40
40
|
return await import("esbuild");
|
|
41
41
|
} catch {
|
|
42
42
|
throw new Error(
|
|
43
|
-
"Bundling a widget's web entry needs
|
|
43
|
+
"Bundling a widget's web entry needs `esbuild`, an optional peer of the SDK.\n" +
|
|
44
44
|
"Install it in your widget project:\n" +
|
|
45
45
|
" npm install --save-dev esbuild",
|
|
46
46
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colixsystems/widget-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.313.0",
|
|
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",
|
|
@@ -77,7 +77,9 @@
|
|
|
77
77
|
"react-native": "*",
|
|
78
78
|
"react-dom": ">=18.0.0",
|
|
79
79
|
"react-native-web": ">=0.19.0",
|
|
80
|
-
"react-native-webview": ">=13.7.0"
|
|
80
|
+
"react-native-webview": ">=13.7.0",
|
|
81
|
+
"esbuild": "^0.28.0",
|
|
82
|
+
"sucrase": "^3.35.0"
|
|
81
83
|
},
|
|
82
84
|
"peerDependenciesMeta": {
|
|
83
85
|
"react": {
|
|
@@ -94,12 +96,14 @@
|
|
|
94
96
|
},
|
|
95
97
|
"react-native-webview": {
|
|
96
98
|
"optional": true
|
|
99
|
+
},
|
|
100
|
+
"esbuild": {
|
|
101
|
+
"optional": true
|
|
102
|
+
},
|
|
103
|
+
"sucrase": {
|
|
104
|
+
"optional": true
|
|
97
105
|
}
|
|
98
106
|
},
|
|
99
|
-
"optionalDependencies": {
|
|
100
|
-
"esbuild": "^0.28.0",
|
|
101
|
-
"sucrase": "^3.35.0"
|
|
102
|
-
},
|
|
103
107
|
"keywords": [
|
|
104
108
|
"appstudio",
|
|
105
109
|
"widget",
|
|
@@ -108,6 +112,8 @@
|
|
|
108
112
|
],
|
|
109
113
|
"license": "MIT",
|
|
110
114
|
"devDependencies": {
|
|
111
|
-
"@babel/parser": "^7.29.7"
|
|
115
|
+
"@babel/parser": "^7.29.7",
|
|
116
|
+
"esbuild": "^0.28.0",
|
|
117
|
+
"sucrase": "^3.35.0"
|
|
112
118
|
}
|
|
113
119
|
}
|
package/src/contract.js
CHANGED
|
@@ -2509,7 +2509,7 @@ const HOOKS = [
|
|
|
2509
2509
|
currency:
|
|
2510
2510
|
"string // the ISO code this workspace charges its app users in, e.g. \"SEK\"",
|
|
2511
2511
|
formatMoney:
|
|
2512
|
-
"(minorUnits) => string //
|
|
2512
|
+
"(minorUnits, { decimals: \"always\" }?) => string // 79500 -> \"795 kr\", 9950 -> \"99,50 kr\": a whole amount shows no decimals; pass { decimals: \"always\" } for a receipt or invoice total (\"795,00 kr\"). Renders identically on web and native. NEVER write a currency symbol or code yourself",
|
|
2513
2513
|
},
|
|
2514
2514
|
requiredContextSlice: ["workspace.currency"],
|
|
2515
2515
|
scopes: null,
|
|
@@ -4973,8 +4973,8 @@ const VETTED_IMPORTS = [
|
|
|
4973
4973
|
description:
|
|
4974
4974
|
"RevenueCat in-app purchase (StoreKit / Play Billing). PREFER usePurchases() from the SDK, which already runs on the " +
|
|
4975
4975
|
"app's configured, signed-in customer. Import this directly only for what the hook does not cover, and NEVER call " +
|
|
4976
|
-
"Purchases.configure, logIn or logOut — the app owns them
|
|
4977
|
-
"connected RevenueCat. Native-only because no browser offers store billing: author it in widget.native.jsx and give " +
|
|
4976
|
+
"Purchases.configure, logIn or logOut — the app owns them. The package is in the app only when the workspace " +
|
|
4977
|
+
"connected RevenueCat: a store build of a workspace that has not is refused while a widget imports it. Native-only because no browser offers store billing: author it in widget.native.jsx and give " +
|
|
4978
4978
|
"widget.web.jsx a visible 'available in the app' state.",
|
|
4979
4979
|
},
|
|
4980
4980
|
{
|
|
@@ -5163,6 +5163,8 @@ const ALLOWED_BARE_IMPORTS = [
|
|
|
5163
5163
|
// * react-native, lucide-react-native, react-native-svg,
|
|
5164
5164
|
// react-native-qrcode-svg: share the host's react-native-web instance
|
|
5165
5165
|
// (sc-1265, sc-6105).
|
|
5166
|
+
// * react-native-safe-area-context: its hooks read the host's provider,
|
|
5167
|
+
// which an inlined copy cannot see (sc-16577).
|
|
5166
5168
|
// * date-fns and the maths set: an agent widget is transpiled, not
|
|
5167
5169
|
// bundled, so the host must resolve its bare imports (sc-7191).
|
|
5168
5170
|
const HOST_EXTERNAL_SPECIFIERS = [
|
|
@@ -5177,6 +5179,7 @@ const HOST_EXTERNAL_SPECIFIERS = [
|
|
|
5177
5179
|
"date-fns",
|
|
5178
5180
|
"react-native-qrcode-svg",
|
|
5179
5181
|
"react-native",
|
|
5182
|
+
"react-native-safe-area-context",
|
|
5180
5183
|
"decimal.js",
|
|
5181
5184
|
"d3-scale",
|
|
5182
5185
|
"d3-shape",
|
|
@@ -5333,18 +5336,6 @@ function normaliseCurrencyCode(value) {
|
|
|
5333
5336
|
return code || CHARGE_CURRENCY;
|
|
5334
5337
|
}
|
|
5335
5338
|
|
|
5336
|
-
/**
|
|
5337
|
-
* `formatMoneyIn("SEK", 45000)` → `"450,00 kr"`.
|
|
5338
|
-
*
|
|
5339
|
-
* Takes MINOR units — the same unit `requestPayment` charges in — so there is no
|
|
5340
|
-
* conversion step for a widget to get wrong. Renders from `CURRENCY_FORMATS`
|
|
5341
|
-
* rather than `Intl.NumberFormat`, which does not produce identical output in
|
|
5342
|
-
* the exported Expo app and react-native-web; this string sits beside the amount
|
|
5343
|
-
* the buyer is actually charged, so the two hosts must agree exactly.
|
|
5344
|
-
*
|
|
5345
|
-
* A non-finite amount renders as zero rather than "NaN": a price whose data has
|
|
5346
|
-
* not loaded should read as an amount, never as a broken string in a checkout.
|
|
5347
|
-
*/
|
|
5348
5339
|
/**
|
|
5349
5340
|
* sc-5717 — value equality for a stored widget-route value: is this key still
|
|
5350
5341
|
* at the default its widget declared?
|
|
@@ -5360,7 +5351,22 @@ function sameWidgetRouteValue(a, b) {
|
|
|
5360
5351
|
}
|
|
5361
5352
|
return Object.is(a, b);
|
|
5362
5353
|
}
|
|
5363
|
-
|
|
5354
|
+
/**
|
|
5355
|
+
* `formatMoneyIn("SEK", 79500)` → `"795 kr"`; `formatMoneyIn("SEK", 9950)` → `"99,50 kr"`.
|
|
5356
|
+
*
|
|
5357
|
+
* Takes MINOR units — the same unit `requestPayment` charges in — so there is no
|
|
5358
|
+
* conversion step for a widget to get wrong. Renders from `CURRENCY_FORMATS`
|
|
5359
|
+
* rather than `Intl.NumberFormat`, which does not produce identical output in
|
|
5360
|
+
* the exported Expo app and react-native-web; this string sits beside the amount
|
|
5361
|
+
* the buyer is actually charged, so the two hosts must agree exactly.
|
|
5362
|
+
*
|
|
5363
|
+
* A whole amount drops its decimals, as shops and menus write prices.
|
|
5364
|
+
* `{ decimals: "always" }` keeps them, for a receipt or invoice total.
|
|
5365
|
+
*
|
|
5366
|
+
* A non-finite amount renders as zero rather than "NaN": a price whose data has
|
|
5367
|
+
* not loaded should read as an amount, never as a broken string in a checkout.
|
|
5368
|
+
*/
|
|
5369
|
+
function formatMoneyIn(currency, minorUnits, options) {
|
|
5364
5370
|
const code = normaliseCurrencyCode(currency);
|
|
5365
5371
|
const fmt = CURRENCY_FORMATS[code] || {
|
|
5366
5372
|
...CURRENCY_FORMAT_FALLBACK,
|
|
@@ -5373,7 +5379,9 @@ function formatMoneyIn(currency, minorUnits) {
|
|
|
5373
5379
|
const whole = fmt.decimals > 0 ? digits.slice(0, -fmt.decimals) : digits;
|
|
5374
5380
|
const cents = fmt.decimals > 0 ? digits.slice(-fmt.decimals) : "";
|
|
5375
5381
|
const grouped = whole.replace(/\B(?=(\d{3})+(?!\d))/g, fmt.groupSeparator);
|
|
5376
|
-
const
|
|
5382
|
+
const alwaysDecimals = Boolean(options && options.decimals === "always");
|
|
5383
|
+
const showCents = cents !== "" && (alwaysDecimals || /[1-9]/.test(cents));
|
|
5384
|
+
const body = showCents ? `${grouped}${fmt.decimalSeparator}${cents}` : grouped;
|
|
5377
5385
|
const gap = fmt.space ? " " : "";
|
|
5378
5386
|
const withSymbol =
|
|
5379
5387
|
fmt.position === "before"
|
|
@@ -6940,7 +6948,11 @@ const CONTRACT = deepFreeze({
|
|
|
6940
6948
|
// `filterList` condition and a query's array-form `filter` take
|
|
6941
6949
|
// `{ operator: "in", value: [a, b] }`; on a list column it matches a row
|
|
6942
6950
|
// holding any of the values. At most 100; no `valueMode` applies.
|
|
6943
|
-
|
|
6951
|
+
// 1.253.0: fix (sc-16577) — `react-native-safe-area-context` is host-resolved,
|
|
6952
|
+
// so `useSafeAreaInsets()` returns zeros on web as documented instead of throwing.
|
|
6953
|
+
// 1.254.0: `formatMoney` shows a whole amount without decimals ("795 kr");
|
|
6954
|
+
// `formatMoney(minor, { decimals: "always" })` keeps them ("795,00 kr").
|
|
6955
|
+
version: "1.254.0",
|
|
6944
6956
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6945
6957
|
hooks: HOOKS,
|
|
6946
6958
|
primitives: PRIMITIVES,
|
|
@@ -7292,6 +7304,82 @@ function deriveSurfaceTokens(backgroundColor) {
|
|
|
7292
7304
|
};
|
|
7293
7305
|
}
|
|
7294
7306
|
|
|
7307
|
+
// The theme_config keys that state a light page's own surface set, by token.
|
|
7308
|
+
const THEME_SURFACE_COLOR_KEYS = Object.freeze({
|
|
7309
|
+
surfaceMuted: "surfaceMutedColor",
|
|
7310
|
+
border: "surfaceBorderColor",
|
|
7311
|
+
onSurfaceMuted: "mutedTextColor",
|
|
7312
|
+
});
|
|
7313
|
+
// How far a look's muted panel and border step from its page toward its ink.
|
|
7314
|
+
const LIGHT_SURFACE_MIX = Object.freeze({ surfaceMuted: 0.04, border: 0.12 });
|
|
7315
|
+
// Slate's own saturation, so a tinted set is as quiet as the default one.
|
|
7316
|
+
const LIGHT_SURFACE_MAX_SATURATION = 0.2;
|
|
7317
|
+
const LIGHT_SURFACE_TEXT_STEP = 0.01;
|
|
7318
|
+
|
|
7319
|
+
function isLightBackground(backgroundColor) {
|
|
7320
|
+
return readableTextColor(backgroundColor, "dark", "light") === "dark";
|
|
7321
|
+
}
|
|
7322
|
+
|
|
7323
|
+
/**
|
|
7324
|
+
* The page's surface set for a stored theme: `deriveSurfaceTokens` of its
|
|
7325
|
+
* background, with the theme's own `THEME_SURFACE_COLOR_KEYS` over it while
|
|
7326
|
+
* that background is light. A dark page keeps the derivation, so a light set
|
|
7327
|
+
* left on the theme never paints it. `null` when the background is unusable.
|
|
7328
|
+
*/
|
|
7329
|
+
function themeSurfaceTokens(themeConfig) {
|
|
7330
|
+
const cfg = themeConfig && typeof themeConfig === "object" ? themeConfig : {};
|
|
7331
|
+
const derived = deriveSurfaceTokens(cfg.backgroundColor);
|
|
7332
|
+
if (!derived || !isLightBackground(cfg.backgroundColor)) return derived;
|
|
7333
|
+
const out = { ...derived };
|
|
7334
|
+
for (const [token, key] of Object.entries(THEME_SURFACE_COLOR_KEYS)) {
|
|
7335
|
+
if (isHexColor(cfg[key])) out[token] = cfg[key];
|
|
7336
|
+
}
|
|
7337
|
+
return out;
|
|
7338
|
+
}
|
|
7339
|
+
|
|
7340
|
+
/**
|
|
7341
|
+
* The surface set a look's LIGHT background wants, as theme_config keys: the
|
|
7342
|
+
* muted panel and border step toward the ink in the background's own hue, and
|
|
7343
|
+
* the muted text keeps the default's weight in that hue, darkened until it
|
|
7344
|
+
* reads at WCAG AA on the surface, the muted panel and the page. `null` for a
|
|
7345
|
+
* dark or unusable background, which `deriveSurfaceTokens` already covers.
|
|
7346
|
+
*/
|
|
7347
|
+
/** The hues of the contract's own slate: a page tinted within them already matches it. */
|
|
7348
|
+
const SLATE_HUES = Object.freeze({ from: 195, to: 225 });
|
|
7349
|
+
|
|
7350
|
+
/** Whether a page has a hue of its own; white, grey and slate-blue keep the contract's colours. */
|
|
7351
|
+
function hasOwnTint(backgroundColor) {
|
|
7352
|
+
const channels = hexChannels(backgroundColor);
|
|
7353
|
+
if (Math.max(...channels) - Math.min(...channels) <= 2) return false;
|
|
7354
|
+
const [hue] = hexToHsl(backgroundColor);
|
|
7355
|
+
return hue < SLATE_HUES.from || hue > SLATE_HUES.to;
|
|
7356
|
+
}
|
|
7357
|
+
|
|
7358
|
+
function deriveLightSurfaceColors(backgroundColor, inkColor) {
|
|
7359
|
+
if (!isHexColor(backgroundColor) || !isLightBackground(backgroundColor) || !hasOwnTint(backgroundColor)) return null;
|
|
7360
|
+
const base = DEFAULT_THEME_TOKENS.colors;
|
|
7361
|
+
const [hue, saturation] = hexToHsl(backgroundColor);
|
|
7362
|
+
const tint = Math.min(saturation, LIGHT_SURFACE_MAX_SATURATION);
|
|
7363
|
+
const ink = isHexColor(inkColor) ? inkColor : base.onSurface;
|
|
7364
|
+
const tone = hslToHex(hue, tint, hexToHsl(ink)[2]);
|
|
7365
|
+
const surfaceMuted = mixHex(backgroundColor, tone, LIGHT_SURFACE_MIX.surfaceMuted);
|
|
7366
|
+
const backdrops = [base.surface, surfaceMuted, backgroundColor];
|
|
7367
|
+
let lightness = hexToHsl(base.onSurfaceMuted)[2];
|
|
7368
|
+
let text = hslToHex(hue, tint, lightness);
|
|
7369
|
+
while (
|
|
7370
|
+
lightness > 0 &&
|
|
7371
|
+
backdrops.some((backdrop) => contrastRatio(text, backdrop) < ACCENT_TEXT_MIN_CONTRAST)
|
|
7372
|
+
) {
|
|
7373
|
+
lightness = Math.max(0, lightness - LIGHT_SURFACE_TEXT_STEP);
|
|
7374
|
+
text = hslToHex(hue, tint, lightness);
|
|
7375
|
+
}
|
|
7376
|
+
return {
|
|
7377
|
+
[THEME_SURFACE_COLOR_KEYS.surfaceMuted]: surfaceMuted,
|
|
7378
|
+
[THEME_SURFACE_COLOR_KEYS.border]: mixHex(backgroundColor, tone, LIGHT_SURFACE_MIX.border),
|
|
7379
|
+
[THEME_SURFACE_COLOR_KEYS.onSurfaceMuted]: text,
|
|
7380
|
+
};
|
|
7381
|
+
}
|
|
7382
|
+
|
|
7295
7383
|
// sc-8370: WCAG 1.4.3 for text, 1.4.11 for a control's boundary.
|
|
7296
7384
|
const INK_CONTRAST = Object.freeze({ text: 4.5, boundary: 3 });
|
|
7297
7385
|
|
|
@@ -7445,6 +7533,9 @@ export {
|
|
|
7445
7533
|
deriveAccentTints,
|
|
7446
7534
|
deriveStatusColors,
|
|
7447
7535
|
deriveSurfaceTokens,
|
|
7536
|
+
themeSurfaceTokens,
|
|
7537
|
+
deriveLightSurfaceColors,
|
|
7538
|
+
THEME_SURFACE_COLOR_KEYS,
|
|
7448
7539
|
inkForBackdrop,
|
|
7449
7540
|
INK_CONTRAST,
|
|
7450
7541
|
gradientAngleToVector,
|
package/src/webbundle.js
CHANGED
|
@@ -40,7 +40,7 @@ export async function loadEsbuild() {
|
|
|
40
40
|
return await import("esbuild");
|
|
41
41
|
} catch {
|
|
42
42
|
throw new Error(
|
|
43
|
-
"Bundling a widget's web entry needs
|
|
43
|
+
"Bundling a widget's web entry needs `esbuild`, an optional peer of the SDK.\n" +
|
|
44
44
|
"Install it in your widget project:\n" +
|
|
45
45
|
" npm install --save-dev esbuild",
|
|
46
46
|
);
|