@colixsystems/widget-sdk 0.301.0 → 0.303.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 +12 -2
- package/dist/linter.cjs +104 -2
- package/dist/linter.js +104 -2
- package/dist/pressable.js +36 -0
- package/dist/primitives.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -90,7 +90,15 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
90
90
|
|
|
91
91
|
## Status
|
|
92
92
|
|
|
93
|
-
`v0.
|
|
93
|
+
`v0.303.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**.
|
|
94
|
+
|
|
95
|
+
### What's new in 0.303.0 (contract 1.247.0)
|
|
96
|
+
|
|
97
|
+
**A card keeps its lift while the pointer is over a button inside it (web).** react-native-web ends a `Pressable`'s hover when the pointer enters a pressable nested in it, so a card styled with `pressableLift(state)` dropped back while the pointer sat on its own button. The SDK `Pressable` now reports `hovered` for as long as the pointer is anywhere inside it, as CSS `:hover` does, in both its style function and its children function. A press on the inner button still runs only that button's action, and a touch still never hovers. Native is unchanged: there is no hover there.
|
|
98
|
+
|
|
99
|
+
### What's new in 0.302.0 (contract 1.247.0)
|
|
100
|
+
|
|
101
|
+
**New linter rule `comment-as-jsx-text` (severity `error`, blocking).** A `//` or `/* */` written between JSX tags is not a comment: it is JSX text, which the web Player shows on screen and the native app refuses, because text must sit inside a `<Text>`. Write a comment between tags as `{/* … */}`; to show the characters themselves, put them in a string, `{"// …"}`. An `appstudio-design-ok` licence between tags is written the same way, `{/* appstudio-design-ok: <reason> */}`, and covers the element below it.
|
|
94
102
|
|
|
95
103
|
### What's new in 0.301.0 (contract 1.247.0)
|
|
96
104
|
|
|
@@ -3546,11 +3554,11 @@ A widget that works but looks unfinished is only half done. `useTheme()` is the
|
|
|
3546
3554
|
- **Answer the touch.** Every tappable card, row and list entry lifts while the pointer is over it (web) or it is pressed (touch). One declaration does both: give the Pressable a style FUNCTION and spread `pressableLift` — `<Pressable onPress={open} style={(state) => [styles.card, ...pressableLift(state)]}>`. The lift is a -2px nudge plus one elevation step from `theme.interaction`, with the web transition built in. Never hand-write hover logic or your own pressed shadows, and never fake feedback with `opacity` — a dimmed surface reads as disabling itself.
|
|
3547
3555
|
- **Size to your container — measure it, don't stretch into it.** The same widget sits in a full-width desktop section (~1400px), a half-width grid cell (~700px) and a phone (~360px), so layout built only from `flex: 1` stretches to fill whatever it is handed — a month calendar ends up with 200px day cells and swallows the page. Measure your own width with `const [width, onLayout] = useContainerWidth();`, spreading `onLayout` on an unpadded root `View` (a React Native callback, so it behaves identically on both hosts). A width of `0` means "not yet measured" and the SDK helpers answer it with the wide form, so do not special-case it — except a count or size computed from the width (a calendar day, a chart, a card grid's cards per line), which renders nothing size-dependent until the width arrives: a widget gets no declared breakpoint prop, but it can always measure. **Every form, list, table and filter bar lays out in three tiers**: `const [width, onLayout] = useContainerWidth();` then branch on `widthTier(width)` — a form is one column narrow, paired short fields at medium, a 2–3 column grid capped near 1000px wide; a list is stacked cards, one-line cards, then real columns under a header; a filter bar is one toolbar row (search, a dropdown per facet, sort) with the active filters as removable chips beneath, and a single "Filters" button opening a panel when narrow. **Cap a repeating cell** rather than giving a grid `flex: 1` — `const cell = Math.max(32, Math.min(Math.floor((usable - gap * (columns - 1)) / columns), 64));`, with a calendar day cell topping out at 56–72px on `aspectRatio: 1`, and the grid given its exact computed width plus `alignSelf: 'center'` when the cap leaves slack. **Split two co-equal surfaces in the wide tier** (`flexDirection: widthTier(width) === 'wide' ? 'row' : 'column'`, each half `{ flex: 1, minWidth: 0 }`) — a picker beside the form it feeds on a wide canvas, stacked in reading order below it. Never hardcode a width, never put `flex: 1` / `height: '100%'` on a content widget's root, and don't read the screen with `Dimensions` — the screen is not the widget. **Whatever you narrow, you centre** — a block that caps its own measure carries all three of `{ width: '100%', maxWidth: FORM_MAX, alignSelf: 'center' }`, because `alignSelf` alone stops the block stretching and sizes it to its content instead, and `maxWidth` alone leaves the widget flush left with dead space beside it; a capped wrap row lays its cells out along the MAIN axis, so it centres with `justifyContent: 'center'` on the row instead — but a card grid or a tile row is never capped. **Lay out a card grid, a tile row or a grid of capped cells with `<Grid>` by default** — it measures its own unpadded box and applies the rules below; lay one out yourself when it needs what `<Grid>` cannot express, such as masonry or cells that span lines. **A card grid fills its lines, it never wraps freely** — a free `flexWrap` strands the remainder (six cards that fit five render 5 + 1). Count the cards that fit the measured width (`const max = Math.max(1, Math.floor((width + gap) / (CARD_MIN + gap)));`), take `const lines = Math.ceil(count / max); const cols = Math.ceil(count / lines);`, and render each slice of `cols` cards as a row of `{ flex: 1, minWidth: 0 }` cells, padding the last line with empty `{ flex: 1 }` spacers so its cards keep the width of the cards above (six that fit five are 3 + 3, ten that fit four are 4 + 4 + 2). **A short value never breaks across lines** — a time, date, price, count, percentage or code takes `numberOfLines={1}` and `flexShrink: 0`, never a fixed width narrower than it, and a narrow slot re-arranges or steps the font down instead. **A metric / stat-tile row FILLS ITS ROW** — when you know the count, balance the lines (`const lines = Math.ceil(count / max); const base = Math.floor(count / lines); const extra = count % lines; const rows = Array.from({ length: lines }, (_, i) => tiles.slice(i * base + Math.min(i, extra), (i + 1) * base + Math.min(i + 1, extra)));`, with `max` 4 / 3 / 2 by tier, each tile `{ flex: 1, minWidth: 0 }`), and when the count comes from data wrap it (`{ flexDirection: 'row', flexWrap: 'wrap', gap: theme.spacing.md }`, each tile `{ flexGrow: 1, flexBasis: TILE_MIN }`, never a `maxWidth` — capped tiles cluster to one side), because a bare `flexDirection: 'row'` has no way to break and a React Native flex child defaults to `flexShrink: 0` (unlike CSS), so the tiles cannot give ground either: the row runs past its container, spilling out of the card natively and cut off by the scrolling page column on web, with nothing thrown and nothing logged, once there are enough of them (four fit where five do not). The basis is also the per-line ceiling — `Math.floor((usable + gap) / (TILE_MIN + gap))` tiles fit a line, so 240 tops out at five across a full-width ~1400px section and 320 at four; past four or five a line the tiles stop reading as cards.
|
|
3548
3556
|
- **A Grid cell that holds more than one `Text` is at least 200 wide.** A cell that holds more than one Text is at least 200 wide: `<Grid minCellWidth={150}>` makes five narrow columns at desktop width, and a card carrying a title, a duration and a price breaks words and wraps the price onto two lines there. Leave `minCellWidth` off (the default is 240) or set it to 240 or more; a width under 200 is for cells of a single `Text` (chips, avatars, icon tiles), and the publish gate refuses (`grid-cell-too-narrow`) a narrower Grid whose cell holds more than one `Text`. An action inside a card is a `<Button>`, never a `Pressable` around text.
|
|
3549
|
-
- **Never draw an icon as a text symbol.** A text child that is only a symbol or an emoji, such as "✓", "★", "→", "☰", "⚙", "⌕", "◇", "🔍" or "📞", renders at the text's size and weight and looks different per font and platform, so it reads as unfinished beside the app's line icons. Draw it with the SDK's `<Icon name="check" />` (✓ check, ★ star, → arrow-right, ☰ menu, ⌕ search), or `<IconButton>` when it is pressed; the publish gate refuses a symbol-only text child (`text-symbol-icon`). A symbol inside running text ("Steg 1 → 2", "© 2026"), a bullet or a dash stays text, and an emoji that is the content itself, such as a reaction, renders from data.
|
|
3550
3557
|
- **Compose forms — pair fields into rows, don't stack one per row.** Lay a form out with `<Form>` by default (above), which does the following for you; when it needs what `<Form>` cannot do (a multi-step wizard, a form beside a live preview, fields laid over a picture), lay the form out in three tiers and cap it near 1000px, centred with the three declarations above — never a 560–720px column alone in a wide box, which leaves a form that IS the page as a narrow strip in empty space. Put short, related fields side by side (first + last name, city + postal code, expiry + CVC): a row of `{ flexDirection: 'row', flexWrap: 'wrap', gap: theme.spacing.md }` with each field cell `{ flexGrow: 1, flexBasis: 160 }` splits the width on a wide card and wraps to stacked on a narrow phone — the right recipe for field pairs because it needs no measurement (a fixed-width column overflows a phone; when a layout needs a real column count instead of wrapping, measure your width as above). Keep wide fields (email, address, notes) full-width with `width: '100%'` — NEVER `flexBasis: '100%'`, which sizes the main axis and therefore claims the parent's whole HEIGHT in a column — cap it at two–three per row, group a long form into labelled sections, and label every input above it (not placeholder-only). Give a `multiline` field BOTH a floor and a ceiling (`{ minHeight: 150, maxHeight: 260 }`) so a long value scrolls inside the box instead of growing past its card, and keep the Save / Cancel row in normal flow below the fields, never positioned over them. A search box is `<SearchField>`, which already carries its glyph and clear control. Any other icon goes inside the field through `leadingIcon` / `trailingIcon`; never wrap a `<TextField>` in a bordered row, since it draws its own border. Put a unit beside the field as a sibling in a row (`flex: 1, minWidth: 0` on the field, so a long value shrinks instead of pushing the row past its container) rather than rebuilding the field to hold it: a hand-built bordered wrapper around a bare `TextInput` loses the app's input look and its label, focus and error handling.
|
|
3551
3558
|
- **Respond to touch.** Give every `Pressable` the lift via the function-style `style={(state) => [base, ...pressableLift(state)]}` — see "Answer the touch" above. Never dim with `opacity`, which reads as the surface disabling itself.
|
|
3552
3559
|
- **Drag and drop — show what is being dragged.** Use `<SortableList>` for a list the user reorders and `<Board>` for cards moved between columns by default: they do everything this item describes, on both hosts, and give a user who cannot drag the same moves from the handle. When the request needs what they cannot do (free-form positioning on a canvas, a drag between two widgets), build your own as follows. A drag where the item stays put reads as broken. Three things change the moment a drag starts: the **drag proxy** (the item lifts and follows the finger — `...theme.elevation.lg`, `{ scale: 1.03 }`, `opacity: 0.9`; for a tall or full-width item drag a compact `primarySoft` pill with its icon + one line of label instead), the **source placeholder** (the vacated slot keeps its height as a quiet `colors.surfaceMuted` block so the list doesn't collapse), and the **drop target** (one slot at a time highlighted with `primarySoft` or a 2px `colors.primary` border). Always animate the release — settle into the new slot, or `Animated.spring(pan, { toValue: { x: 0, y: 0 }, useNativeDriver: false })` back to the origin on cancel. Build it with `Animated` + `PanResponder` from `react-native` (the only mechanism that behaves identically on both hosts) — never HTML5 drag events (`draggable` / `onDragStart` / `dataTransfer` are web-only, and `document` / `window` are banned) — and start the drag from a `GripVertical` grip handle whenever the row is also tappable or sits in a `ScrollView`. **A board (kanban, pipeline) drops onto ANOTHER column**, which needs four more things: the board's root renders the one proxy (a column clips whatever leaves it); you hit-test the drop yourself — `measureInWindow` every column and the board when the drag starts and compare the gesture's window `moveX` (never `onLayout` frames, which are relative to a padded or scrolled parent) — highlighting exactly one target; the drop WRITES (`update(id, { [statusField]: value })` through `useDatastoreMutation`, optimistic until `refetch()`, a toast and a spring-back on failure); and three or more columns go in a `horizontal` `ScrollView` when `widthTier(width) === "narrow"`, with the grip claiming the gesture (`onStartShouldSetPanResponder`, `onPanResponderTerminationRequest: () => false`) and carrying `touchAction: 'none'` on web so a finger drag moves the card instead of scrolling the page. And because `useRef(PanResponder.create(...))` runs ONCE, everything its callbacks read — the `useCanWrite` flag included, which starts `false` — goes through a ref refreshed every render (`latest.current.canDrag`); the publish gate `widget.staleResponder` rejects a value read directly.
|
|
3553
3560
|
- **Use icons for clarity.** Pair a `lucide-react-native` icon with its label at a consistent size, coloured from the theme. The label never repeats the icon as a character — with a `Plus` icon the button says "Add item", never "+ Add item" (that renders a doubled plus).
|
|
3561
|
+
- **Never draw an icon as a text symbol.** A text child that is only a symbol or an emoji, such as "✓", "★", "→", "☰", "⚙", "⌕", "◇", "🔍" or "📞", renders at the text's size and weight and looks different per font and platform, so it reads as unfinished beside the app's line icons. Draw it with the SDK's `<Icon name="check" />` (✓ check, ★ star, → arrow-right, ☰ menu, ⌕ search), or `<IconButton>` when it is pressed; the publish gate refuses a symbol-only text child (`text-symbol-icon`). A symbol inside running text ("Steg 1 → 2", "© 2026"), a bullet or a dash stays text, and an emoji that is the content itself, such as a reaction, renders from data.
|
|
3554
3562
|
- **Use imagery deliberately.** Render pictures with the `Image` primitive (`source` takes a URL or `{ uri }`); resolve workspace assets via `useAsset()`. Give every image a sized, `radii`-clipped container so it never renders as a raw rectangle, and never hardcode a credentialed image URL — expose an `image`-type property instead. The frame is your decision, never the picture's: size it for the role (a 40–56 square avatar, a 72–96 square row thumbnail, a square photo tile, a `16 / 9` photo card, a 160–240 tall band) and let `resizeMode="cover"` crop the photo into it — photos arrive at every size and ratio, so one left to its own proportions breaks the layout. Keep `contain` for art whose whole subject must stay visible (a logo, a diagram), inside a fixed frame. When an item has a photograph, make it the card's background with the title on it — `<Card image={url} scrim="bottom">` with a function child for the colours — rather than a small picture with its text in a box underneath; keep the stacked form for a card whose text is long or dense.
|
|
3555
3563
|
- **Design the empty, loading, and error states.** A blank box on a fresh install reads as broken — show a short helper line when a list is empty, a calm loading line, and a single human sentence in `colors.danger` on error.
|
|
3556
3564
|
|
|
@@ -3963,6 +3971,8 @@ Pass `--manifest` to enable `style-field-unread` and the three editability rules
|
|
|
3963
3971
|
|
|
3964
3972
|
`text-symbol-icon` flags a JSX text child that is nothing but symbols or emoji (`<Text>✓</Text>`, `<Text>{open ? "▲" : "▼"}</Text>`, or `✓ {label}`), naming the lucide `<Icon>` to draw instead where one is obvious (✓ check, ★ star, → arrow-right, ☰ menu, ⌕ search). A symbol inside running text ("Steg 1 → 2", "© 2026"), bullets and dashes (• · – —), ×, currency signs and flag emoji pass. A warning for a human author, blocking for the AI widget agent and `/mcp/build`.
|
|
3965
3973
|
|
|
3974
|
+
`comment-as-jsx-text` refuses a `//` or `/* */` comment written between JSX tags, where it is text the web Player shows and the native app refuses. Write it as `{/* … */}`. An error.
|
|
3975
|
+
|
|
3966
3976
|
`row-action-not-gated` flags a widget that calls `update` or `delete` from `useDatastoreMutation` without a per-row permission check: no `_capabilities` read and no `useCanWrite(tableId, { recordId })`. The table-level `useCanWrite(tableId)` only answers "may create", so a list gated on it shows Edit / Delete on rows the server will refuse. A warning.
|
|
3967
3977
|
|
|
3968
3978
|
`no-html-in-content` flags an HTML tag inside a **string** — `"<strong>"`, `"<br>"`, `"<p>…</p>"`. There is no HTML renderer on either host, so the tag reaches the reader as literal text; author formatted text with `<MarkdownInput>` and render it with `<RichText>` instead. Only string and template content is scanned, so your own `<View>` / `<Text>` JSX can never trip it. A warning for a human author, blocking for the AI widget agent.
|
package/dist/linter.cjs
CHANGED
|
@@ -2459,6 +2459,106 @@ function _measuredPaddingRules(source) {
|
|
|
2459
2459
|
return findings;
|
|
2460
2460
|
}
|
|
2461
2461
|
|
|
2462
|
+
// A `//` or `/* */` between JSX tags is JSX text, not a comment: the web
|
|
2463
|
+
// Player shows it, and native throws because text must sit in a <Text>.
|
|
2464
|
+
const _JSX_TEXT_COMMENT_TAG_RE = /<(\/?)([A-Za-z][\w.]*)?/g;
|
|
2465
|
+
|
|
2466
|
+
// Whether the code character at `q` is one an element's child text follows:
|
|
2467
|
+
// the `>` ending a tag inside an open element, or the `}` of a child
|
|
2468
|
+
// expression that itself follows one.
|
|
2469
|
+
function _jsxChildBoundaries(structure) {
|
|
2470
|
+
const depth = new Int32Array(structure.length + 1);
|
|
2471
|
+
for (let i = 0; i < structure.length; i++) {
|
|
2472
|
+
const ch = structure[i];
|
|
2473
|
+
depth[i + 1] = depth[i] + (ch === "{" ? 1 : ch === "}" ? -1 : 0);
|
|
2474
|
+
}
|
|
2475
|
+
const index = _jsxScanIndex(structure);
|
|
2476
|
+
const open = _openTagStack();
|
|
2477
|
+
const tagEnds = new Set();
|
|
2478
|
+
const settle = (end) => {
|
|
2479
|
+
const top = open.top();
|
|
2480
|
+
if (top && top.depth === depth[end + 1]) tagEnds.add(end);
|
|
2481
|
+
};
|
|
2482
|
+
_JSX_TEXT_COMMENT_TAG_RE.lastIndex = 0;
|
|
2483
|
+
let token;
|
|
2484
|
+
while ((token = _JSX_TEXT_COMMENT_TAG_RE.exec(structure))) {
|
|
2485
|
+
const [, closing, name] = token;
|
|
2486
|
+
// `useState<Item>` and `a<b` are not tags.
|
|
2487
|
+
if (/[\w$)\]]/.test(structure[token.index - 1] || "")) continue;
|
|
2488
|
+
if (!name) {
|
|
2489
|
+
// A fragment, `<>` or `</>`; any other `<` is a comparison.
|
|
2490
|
+
const end = token.index + 1 + closing.length;
|
|
2491
|
+
if (structure[end] !== ">") continue;
|
|
2492
|
+
if (closing) open.pop();
|
|
2493
|
+
else open.push({ name: "", depth: depth[end + 1] });
|
|
2494
|
+
settle(end);
|
|
2495
|
+
continue;
|
|
2496
|
+
}
|
|
2497
|
+
const end = index.tagEnd(token.index);
|
|
2498
|
+
if (end === -1) break;
|
|
2499
|
+
if (closing) open.close(name);
|
|
2500
|
+
else if (!_selfClosing(structure, end)) open.push({ name, depth: depth[end + 1] });
|
|
2501
|
+
settle(end);
|
|
2502
|
+
_JSX_TEXT_COMMENT_TAG_RE.lastIndex = end + 1;
|
|
2503
|
+
}
|
|
2504
|
+
const codeBefore = (at) => {
|
|
2505
|
+
let i = at - 1;
|
|
2506
|
+
while (i >= 0 && /\s/.test(structure[i])) i--;
|
|
2507
|
+
return i;
|
|
2508
|
+
};
|
|
2509
|
+
return (q) => {
|
|
2510
|
+
for (let at = q; at >= 0; ) {
|
|
2511
|
+
if (structure[at] === ">") return tagEnds.has(at);
|
|
2512
|
+
if (structure[at] !== "}") return false;
|
|
2513
|
+
const span = index.enclosingObject(at);
|
|
2514
|
+
if (!span) return false;
|
|
2515
|
+
at = codeBefore(span[0]);
|
|
2516
|
+
}
|
|
2517
|
+
return false;
|
|
2518
|
+
};
|
|
2519
|
+
}
|
|
2520
|
+
|
|
2521
|
+
function _jsxTextCommentRules(source) {
|
|
2522
|
+
if (!source.includes("//") && !source.includes("/*")) return [];
|
|
2523
|
+
// The mask keeps a template hole's `${` but blanks its `}`; balance them.
|
|
2524
|
+
const structure = _stripNonCode(source).replace(/\$\{/g, "$ ");
|
|
2525
|
+
// Comments blanked, strings kept: a `//` inside a string is no comment.
|
|
2526
|
+
const code = _stripNonCode(source, { keepStrings: true });
|
|
2527
|
+
const childFollows = _jsxChildBoundaries(structure);
|
|
2528
|
+
const lineAt = _lineCounter(code);
|
|
2529
|
+
const sourceLines = source.split(/\r?\n/);
|
|
2530
|
+
const findings = [];
|
|
2531
|
+
let previous = -1;
|
|
2532
|
+
for (let i = 0; i < source.length - 1; i++) {
|
|
2533
|
+
if (code[i] !== " " || source[i] !== "/") {
|
|
2534
|
+
if (!/\s/.test(code[i])) previous = i;
|
|
2535
|
+
continue;
|
|
2536
|
+
}
|
|
2537
|
+
const block = source[i + 1] === "*";
|
|
2538
|
+
if (!block && source[i + 1] !== "/") continue;
|
|
2539
|
+
if (previous !== -1 && childFollows(previous)) {
|
|
2540
|
+
const line = lineAt(i);
|
|
2541
|
+
findings.push({
|
|
2542
|
+
rule: "comment-as-jsx-text",
|
|
2543
|
+
severity: "error",
|
|
2544
|
+
label:
|
|
2545
|
+
`A ${block ? "/* */" : "//"} comment written between JSX tags is ` +
|
|
2546
|
+
`text, not a comment: the web Player shows it on screen and the ` +
|
|
2547
|
+
`native app fails, because text must sit inside a <Text>. Write ` +
|
|
2548
|
+
`it as {/* … */}; to show the characters, put them in a string, ` +
|
|
2549
|
+
`{"// …"}.`,
|
|
2550
|
+
line,
|
|
2551
|
+
snippet: (sourceLines[line - 1] || "").trim().slice(0, 200),
|
|
2552
|
+
});
|
|
2553
|
+
}
|
|
2554
|
+
// Skip the rest of the comment, so a `//` inside it is not another.
|
|
2555
|
+
const end = block ? source.indexOf("*/", i + 2) : source.indexOf("\n", i + 2);
|
|
2556
|
+
if (end === -1) break;
|
|
2557
|
+
i = block ? end + 1 : end - 1;
|
|
2558
|
+
}
|
|
2559
|
+
return findings;
|
|
2560
|
+
}
|
|
2561
|
+
|
|
2462
2562
|
/**
|
|
2463
2563
|
* Narrow a split-impl widget's manifest to the platform a single bundle file
|
|
2464
2564
|
* ships to, so `import-platform-mismatch` lints each file against what it
|
|
@@ -2510,7 +2610,8 @@ const _DESIGN_OK_RE = /appstudio-design-ok\s*:\s*\S/;
|
|
|
2510
2610
|
* covers only its own line; a marker on its OWN line covers the statement
|
|
2511
2611
|
* that follows it, bracket-balanced, so a multi-line categorical palette needs
|
|
2512
2612
|
* one marker rather than forty. Balance is counted on brace-blanked code so a
|
|
2513
|
-
* bracket inside a string cannot unbalance the span.
|
|
2613
|
+
* bracket inside a string cannot unbalance the span. Between JSX tags the
|
|
2614
|
+
* marker is written inside a JSX comment, which counts as its own line.
|
|
2514
2615
|
*/
|
|
2515
2616
|
function _designExemptLines(source) {
|
|
2516
2617
|
const lines = source.split(/\r?\n/);
|
|
@@ -2519,7 +2620,7 @@ function _designExemptLines(source) {
|
|
|
2519
2620
|
for (let i = 0; i < lines.length; i += 1) {
|
|
2520
2621
|
if (!_DESIGN_OK_RE.test(lines[i])) continue;
|
|
2521
2622
|
exempt.add(i + 1);
|
|
2522
|
-
if (!/^\s*(
|
|
2623
|
+
if (!/^\s*(?:\/\/|\/\*|\*|\{\s*\/\*)/.test(lines[i])) continue;
|
|
2523
2624
|
let depth = 0;
|
|
2524
2625
|
let started = false;
|
|
2525
2626
|
for (let j = i + 1; j < lines.length; j += 1) {
|
|
@@ -3098,6 +3199,7 @@ function lintSource(source, options) {
|
|
|
3098
3199
|
// sc-4913 — soft warning: a measured width that includes the widget's own
|
|
3099
3200
|
// padding wraps the last grid column into an empty one.
|
|
3100
3201
|
findings.push(..._measuredPaddingRules(source));
|
|
3202
|
+
findings.push(..._jsxTextCommentRules(source));
|
|
3101
3203
|
// sc-6455 — soft warning: a colour/font literal the theme can never reach.
|
|
3102
3204
|
findings.push(..._hardcodedDesignRules(source));
|
|
3103
3205
|
findings.push(..._writeGatedOnUserRules(source));
|
package/dist/linter.js
CHANGED
|
@@ -2454,6 +2454,106 @@ function _measuredPaddingRules(source) {
|
|
|
2454
2454
|
return findings;
|
|
2455
2455
|
}
|
|
2456
2456
|
|
|
2457
|
+
// A `//` or `/* */` between JSX tags is JSX text, not a comment: the web
|
|
2458
|
+
// Player shows it, and native throws because text must sit in a <Text>.
|
|
2459
|
+
const _JSX_TEXT_COMMENT_TAG_RE = /<(\/?)([A-Za-z][\w.]*)?/g;
|
|
2460
|
+
|
|
2461
|
+
// Whether the code character at `q` is one an element's child text follows:
|
|
2462
|
+
// the `>` ending a tag inside an open element, or the `}` of a child
|
|
2463
|
+
// expression that itself follows one.
|
|
2464
|
+
function _jsxChildBoundaries(structure) {
|
|
2465
|
+
const depth = new Int32Array(structure.length + 1);
|
|
2466
|
+
for (let i = 0; i < structure.length; i++) {
|
|
2467
|
+
const ch = structure[i];
|
|
2468
|
+
depth[i + 1] = depth[i] + (ch === "{" ? 1 : ch === "}" ? -1 : 0);
|
|
2469
|
+
}
|
|
2470
|
+
const index = _jsxScanIndex(structure);
|
|
2471
|
+
const open = _openTagStack();
|
|
2472
|
+
const tagEnds = new Set();
|
|
2473
|
+
const settle = (end) => {
|
|
2474
|
+
const top = open.top();
|
|
2475
|
+
if (top && top.depth === depth[end + 1]) tagEnds.add(end);
|
|
2476
|
+
};
|
|
2477
|
+
_JSX_TEXT_COMMENT_TAG_RE.lastIndex = 0;
|
|
2478
|
+
let token;
|
|
2479
|
+
while ((token = _JSX_TEXT_COMMENT_TAG_RE.exec(structure))) {
|
|
2480
|
+
const [, closing, name] = token;
|
|
2481
|
+
// `useState<Item>` and `a<b` are not tags.
|
|
2482
|
+
if (/[\w$)\]]/.test(structure[token.index - 1] || "")) continue;
|
|
2483
|
+
if (!name) {
|
|
2484
|
+
// A fragment, `<>` or `</>`; any other `<` is a comparison.
|
|
2485
|
+
const end = token.index + 1 + closing.length;
|
|
2486
|
+
if (structure[end] !== ">") continue;
|
|
2487
|
+
if (closing) open.pop();
|
|
2488
|
+
else open.push({ name: "", depth: depth[end + 1] });
|
|
2489
|
+
settle(end);
|
|
2490
|
+
continue;
|
|
2491
|
+
}
|
|
2492
|
+
const end = index.tagEnd(token.index);
|
|
2493
|
+
if (end === -1) break;
|
|
2494
|
+
if (closing) open.close(name);
|
|
2495
|
+
else if (!_selfClosing(structure, end)) open.push({ name, depth: depth[end + 1] });
|
|
2496
|
+
settle(end);
|
|
2497
|
+
_JSX_TEXT_COMMENT_TAG_RE.lastIndex = end + 1;
|
|
2498
|
+
}
|
|
2499
|
+
const codeBefore = (at) => {
|
|
2500
|
+
let i = at - 1;
|
|
2501
|
+
while (i >= 0 && /\s/.test(structure[i])) i--;
|
|
2502
|
+
return i;
|
|
2503
|
+
};
|
|
2504
|
+
return (q) => {
|
|
2505
|
+
for (let at = q; at >= 0; ) {
|
|
2506
|
+
if (structure[at] === ">") return tagEnds.has(at);
|
|
2507
|
+
if (structure[at] !== "}") return false;
|
|
2508
|
+
const span = index.enclosingObject(at);
|
|
2509
|
+
if (!span) return false;
|
|
2510
|
+
at = codeBefore(span[0]);
|
|
2511
|
+
}
|
|
2512
|
+
return false;
|
|
2513
|
+
};
|
|
2514
|
+
}
|
|
2515
|
+
|
|
2516
|
+
function _jsxTextCommentRules(source) {
|
|
2517
|
+
if (!source.includes("//") && !source.includes("/*")) return [];
|
|
2518
|
+
// The mask keeps a template hole's `${` but blanks its `}`; balance them.
|
|
2519
|
+
const structure = _stripNonCode(source).replace(/\$\{/g, "$ ");
|
|
2520
|
+
// Comments blanked, strings kept: a `//` inside a string is no comment.
|
|
2521
|
+
const code = _stripNonCode(source, { keepStrings: true });
|
|
2522
|
+
const childFollows = _jsxChildBoundaries(structure);
|
|
2523
|
+
const lineAt = _lineCounter(code);
|
|
2524
|
+
const sourceLines = source.split(/\r?\n/);
|
|
2525
|
+
const findings = [];
|
|
2526
|
+
let previous = -1;
|
|
2527
|
+
for (let i = 0; i < source.length - 1; i++) {
|
|
2528
|
+
if (code[i] !== " " || source[i] !== "/") {
|
|
2529
|
+
if (!/\s/.test(code[i])) previous = i;
|
|
2530
|
+
continue;
|
|
2531
|
+
}
|
|
2532
|
+
const block = source[i + 1] === "*";
|
|
2533
|
+
if (!block && source[i + 1] !== "/") continue;
|
|
2534
|
+
if (previous !== -1 && childFollows(previous)) {
|
|
2535
|
+
const line = lineAt(i);
|
|
2536
|
+
findings.push({
|
|
2537
|
+
rule: "comment-as-jsx-text",
|
|
2538
|
+
severity: "error",
|
|
2539
|
+
label:
|
|
2540
|
+
`A ${block ? "/* */" : "//"} comment written between JSX tags is ` +
|
|
2541
|
+
`text, not a comment: the web Player shows it on screen and the ` +
|
|
2542
|
+
`native app fails, because text must sit inside a <Text>. Write ` +
|
|
2543
|
+
`it as {/* … */}; to show the characters, put them in a string, ` +
|
|
2544
|
+
`{"// …"}.`,
|
|
2545
|
+
line,
|
|
2546
|
+
snippet: (sourceLines[line - 1] || "").trim().slice(0, 200),
|
|
2547
|
+
});
|
|
2548
|
+
}
|
|
2549
|
+
// Skip the rest of the comment, so a `//` inside it is not another.
|
|
2550
|
+
const end = block ? source.indexOf("*/", i + 2) : source.indexOf("\n", i + 2);
|
|
2551
|
+
if (end === -1) break;
|
|
2552
|
+
i = block ? end + 1 : end - 1;
|
|
2553
|
+
}
|
|
2554
|
+
return findings;
|
|
2555
|
+
}
|
|
2556
|
+
|
|
2457
2557
|
/**
|
|
2458
2558
|
* Narrow a split-impl widget's manifest to the platform a single bundle file
|
|
2459
2559
|
* ships to, so `import-platform-mismatch` lints each file against what it
|
|
@@ -2505,7 +2605,8 @@ const _DESIGN_OK_RE = /appstudio-design-ok\s*:\s*\S/;
|
|
|
2505
2605
|
* covers only its own line; a marker on its OWN line covers the statement
|
|
2506
2606
|
* that follows it, bracket-balanced, so a multi-line categorical palette needs
|
|
2507
2607
|
* one marker rather than forty. Balance is counted on brace-blanked code so a
|
|
2508
|
-
* bracket inside a string cannot unbalance the span.
|
|
2608
|
+
* bracket inside a string cannot unbalance the span. Between JSX tags the
|
|
2609
|
+
* marker is written inside a JSX comment, which counts as its own line.
|
|
2509
2610
|
*/
|
|
2510
2611
|
function _designExemptLines(source) {
|
|
2511
2612
|
const lines = source.split(/\r?\n/);
|
|
@@ -2514,7 +2615,7 @@ function _designExemptLines(source) {
|
|
|
2514
2615
|
for (let i = 0; i < lines.length; i += 1) {
|
|
2515
2616
|
if (!_DESIGN_OK_RE.test(lines[i])) continue;
|
|
2516
2617
|
exempt.add(i + 1);
|
|
2517
|
-
if (!/^\s*(
|
|
2618
|
+
if (!/^\s*(?:\/\/|\/\*|\*|\{\s*\/\*)/.test(lines[i])) continue;
|
|
2518
2619
|
let depth = 0;
|
|
2519
2620
|
let started = false;
|
|
2520
2621
|
for (let j = i + 1; j < lines.length; j += 1) {
|
|
@@ -3093,6 +3194,7 @@ export function lintSource(source, options) {
|
|
|
3093
3194
|
// sc-4913 — soft warning: a measured width that includes the widget's own
|
|
3094
3195
|
// padding wraps the last grid column into an empty one.
|
|
3095
3196
|
findings.push(..._measuredPaddingRules(source));
|
|
3197
|
+
findings.push(..._jsxTextCommentRules(source));
|
|
3096
3198
|
// sc-6455 — soft warning: a colour/font literal the theme can never reach.
|
|
3097
3199
|
findings.push(..._hardcodedDesignRules(source));
|
|
3098
3200
|
findings.push(..._writeGatedOnUserRules(source));
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// The web `<Pressable>`: react-native-web's, with `hovered` following the
|
|
2
|
+
// pointer. The native build re-exports React Native's (./primitives.native.js),
|
|
3
|
+
// where no hover exists.
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { ReactNative } from "./text-scale.js";
|
|
6
|
+
|
|
7
|
+
const Base = ReactNative.Pressable;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* react-native-web ends a Pressable's hover when the pointer enters a Pressable
|
|
11
|
+
* nested in it. Here `hovered` stays true while the pointer is anywhere inside,
|
|
12
|
+
* as CSS `:hover` does, so a card keeps its lift over its own button.
|
|
13
|
+
*/
|
|
14
|
+
export const Pressable = React.forwardRef(function Pressable(props, ref) {
|
|
15
|
+
const { style, children, disabled, onPointerEnter, onPointerLeave } = props;
|
|
16
|
+
const [inside, setInside] = React.useState(false);
|
|
17
|
+
const withInside = (state) => ({ ...state, hovered: state.hovered || (inside && !disabled) });
|
|
18
|
+
return React.createElement(
|
|
19
|
+
Base,
|
|
20
|
+
{
|
|
21
|
+
...props,
|
|
22
|
+
ref,
|
|
23
|
+
onPointerEnter: (e) => {
|
|
24
|
+
if (e.pointerType !== "touch") setInside(true);
|
|
25
|
+
onPointerEnter?.(e);
|
|
26
|
+
},
|
|
27
|
+
onPointerLeave: (e) => {
|
|
28
|
+
setInside(false);
|
|
29
|
+
onPointerLeave?.(e);
|
|
30
|
+
},
|
|
31
|
+
style: typeof style === "function" ? (state) => style(withInside(state)) : style,
|
|
32
|
+
},
|
|
33
|
+
typeof children === "function" ? (state) => children(withInside(state)) : children,
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
Pressable.displayName = "Pressable";
|
package/dist/primitives.js
CHANGED
|
@@ -44,7 +44,7 @@ import { makeTextInput } from "./text-input-view.js";
|
|
|
44
44
|
|
|
45
45
|
export const Text = ReactNative.Text;
|
|
46
46
|
export const View = ReactNative.View;
|
|
47
|
-
export
|
|
47
|
+
export { Pressable } from "./pressable.js";
|
|
48
48
|
export const Image = ReactNative.Image;
|
|
49
49
|
export const ScrollView = ReactNative.ScrollView;
|
|
50
50
|
export const TextInput = makeTextInput(ReactNative.TextInput);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colixsystems/widget-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.303.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",
|