@multiplatform.one/config 7.83.2 → 7.84.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/lint.mjs +28 -1
- package/package.json +3 -3
- package/press-lint.d.ts +2 -0
- package/press-lint.mjs +103 -0
- package/src/press-lint.spec.ts +63 -1
package/lint.mjs
CHANGED
|
@@ -83,6 +83,10 @@
|
|
|
83
83
|
* with `pressStyle` / `focusVisibleStyle` and no press handler of its own
|
|
84
84
|
* inside a JSX pressable. On native it claims the responder and the
|
|
85
85
|
* pressable's onPress never runs. See press-lint.mjs.
|
|
86
|
+
* 18. Fail on a NATIVE FOCUS-WITHIN (FZ-8991) — a `focusWithinStyle` that
|
|
87
|
+
* renders on native, outside an `isWeb` gate. On native it hands every
|
|
88
|
+
* descendant focus events, a label takes the touch, and the pressable's
|
|
89
|
+
* onPress never runs. See press-lint.mjs.
|
|
86
90
|
*
|
|
87
91
|
* Usage:
|
|
88
92
|
* import { runConventionChecks } from "@multiplatform.one/config/lint";
|
|
@@ -98,7 +102,11 @@ import { dirname, join, relative } from "node:path";
|
|
|
98
102
|
import { pathToFileURL } from "node:url";
|
|
99
103
|
import { DRAWING_PRAGMA, isDrawingFile, readDrawingRegistry } from "./drawing-registry.mjs";
|
|
100
104
|
import { findHexEscapes } from "./oxlint.mjs";
|
|
101
|
-
import {
|
|
105
|
+
import {
|
|
106
|
+
exportedPressClaimants,
|
|
107
|
+
findNativeFocusWithin,
|
|
108
|
+
findNestedPressClaimants,
|
|
109
|
+
} from "./press-lint.mjs";
|
|
102
110
|
import { readHexEscapeRegistry, readSizeRecipeEscapeRegistry } from "./spec-registry.mjs";
|
|
103
111
|
|
|
104
112
|
/**
|
|
@@ -2626,6 +2634,20 @@ function checkNativePressOwner() {
|
|
|
2626
2634
|
return violations;
|
|
2627
2635
|
}
|
|
2628
2636
|
|
|
2637
|
+
/** FZ-8991 NATIVE-FOCUS-WITHIN: see press-lint.mjs. */
|
|
2638
|
+
function checkNativeFocusWithin() {
|
|
2639
|
+
/** @type {string[]} */
|
|
2640
|
+
const violations = [];
|
|
2641
|
+
walkOwnedSource((filePath) => {
|
|
2642
|
+
if (!/\.(?:tsx|jsx|ts)$/.test(filePath) || /\.(?:spec|test)\./.test(filePath)) return;
|
|
2643
|
+
const src = readFileSync(filePath, "utf8");
|
|
2644
|
+
const rel = relative(ROOT, filePath).replaceAll("\\", "/");
|
|
2645
|
+
for (const hit of findNativeFocusWithin(src, filePath))
|
|
2646
|
+
violations.push(`${rel}:${hit.line} — focusWithinStyle renders on native; gate it on isWeb`);
|
|
2647
|
+
});
|
|
2648
|
+
return violations;
|
|
2649
|
+
}
|
|
2650
|
+
|
|
2629
2651
|
/**
|
|
2630
2652
|
* Run structural convention checks over a consumer tree.
|
|
2631
2653
|
*
|
|
@@ -2661,6 +2683,7 @@ export function runConventionChecks(options = {}) {
|
|
|
2661
2683
|
const hugContent = checkHugContent();
|
|
2662
2684
|
const responsiveParity = checkResponsiveParity();
|
|
2663
2685
|
const nativePressOwner = checkNativePressOwner();
|
|
2686
|
+
const nativeFocusWithin = checkNativeFocusWithin();
|
|
2664
2687
|
const oneTabBar = checkOneTabBar();
|
|
2665
2688
|
let failed = false;
|
|
2666
2689
|
|
|
@@ -2681,6 +2704,10 @@ export function runConventionChecks(options = {}) {
|
|
|
2681
2704
|
'Convention (FZ-7792 NATIVE-PRESS-OWNER, check 17): one view owns a press. On native, a view with pressStyle or focusVisibleStyle and no handler claims the touch, and React Native gives it to the deepest claimant, so a pressable\'s onPress never runs when the tap lands on that child. Put `group="<name>"` on the pressable and move the child\'s press look to `"$group-<name>-press"`.',
|
|
2682
2705
|
nativePressOwner,
|
|
2683
2706
|
],
|
|
2707
|
+
[
|
|
2708
|
+
"Convention (FZ-8991 NATIVE-FOCUS-WITHIN, check 18): no focusWithinStyle on native. Tamagui then gives every descendant focus events, a label inside a pressable takes the touch, and its onPress never runs. The ring follows keyboard focus: spread it as `{...(isWeb ? { focusWithinStyle: ring } : undefined)}`.",
|
|
2709
|
+
nativeFocusWithin,
|
|
2710
|
+
],
|
|
2684
2711
|
[
|
|
2685
2712
|
"Convention (LC-150 TAB-BAR-ANATOMY): one bottom tab bar for every MPO app. A phone app renders TabBar from @multiplatform.one/components with items (an icon component and a label) and nothing else; the bar owns its metrics and the theme its colours. An app-local tab bar, a navigator's own tab bar, or tabBar* styling options fork the look.",
|
|
2686
2713
|
oneTabBar,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@multiplatform.one/config",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.84.1",
|
|
4
4
|
"description": "Shared build and test configuration presets for multiplatform.one",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"config",
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
"access": "public"
|
|
115
115
|
},
|
|
116
116
|
"dependencies": {
|
|
117
|
-
"@multiplatform.one/utils": "^7.
|
|
117
|
+
"@multiplatform.one/utils": "^7.84.1",
|
|
118
118
|
"@tamagui/vite-plugin": "2.7.6",
|
|
119
119
|
"@vitejs/plugin-react": "^6.1.2",
|
|
120
120
|
"dotenv": "^17.4.2",
|
|
@@ -124,7 +124,7 @@
|
|
|
124
124
|
"vite": "^8.0.10",
|
|
125
125
|
"vite-plugin-external": "^6.2.2",
|
|
126
126
|
"vite-plugin-i18next-loader": "^3.1.3",
|
|
127
|
-
"vitest": "^4.1.
|
|
127
|
+
"vitest": "^4.1.12"
|
|
128
128
|
},
|
|
129
129
|
"devDependencies": {
|
|
130
130
|
"tsdown": "^0.21.10"
|
package/press-lint.d.ts
CHANGED
package/press-lint.mjs
CHANGED
|
@@ -253,3 +253,106 @@ export function findNestedPressClaimants(source, filename, imported = new Set())
|
|
|
253
253
|
visit(file, undefined, undefined);
|
|
254
254
|
return found;
|
|
255
255
|
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* NATIVE-FOCUS-WITHIN (FZ-8991): no `focusWithinStyle` that renders on native.
|
|
259
|
+
*
|
|
260
|
+
* On native, tamagui wraps a focusWithinStyle host's children in a context
|
|
261
|
+
* that gives every descendant focus events, and a label inside a pressable
|
|
262
|
+
* then takes the touch: the pressable's onPress never runs (the ViewSwitcher
|
|
263
|
+
* segments on iOS). The ring it paints follows keyboard focus, so it belongs
|
|
264
|
+
* to web only.
|
|
265
|
+
*
|
|
266
|
+
* Flagged: a `focusWithinStyle` JSX attribute or object key in a file that
|
|
267
|
+
* renders on native (not `*.web.*`), unless it sits on the web side of an
|
|
268
|
+
* `isWeb` / `Platform.OS === "web"` / `TAMAGUI_TARGET === "web"` condition
|
|
269
|
+
* (`isWeb ? { focusWithinStyle } : …`, `isWeb && …`, `!isWeb ? … : { … }`,
|
|
270
|
+
* or under `if (isWeb)`).
|
|
271
|
+
*
|
|
272
|
+
* @param {string} source
|
|
273
|
+
* @param {string} filename
|
|
274
|
+
* @returns {{ line: number }[]}
|
|
275
|
+
*/
|
|
276
|
+
export function findNativeFocusWithin(source, filename) {
|
|
277
|
+
if (!source.includes("focusWithinStyle") || /\.web\.[cm]?[jt]sx?$/.test(filename)) return [];
|
|
278
|
+
const file = ts.createSourceFile(
|
|
279
|
+
filename,
|
|
280
|
+
source,
|
|
281
|
+
ts.ScriptTarget.Latest,
|
|
282
|
+
true,
|
|
283
|
+
ts.ScriptKind.TSX,
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* true: the condition holds only on web; false: only off web; undefined: neither.
|
|
288
|
+
* @param {ts.Expression} expr
|
|
289
|
+
* @returns {boolean | undefined}
|
|
290
|
+
*/
|
|
291
|
+
function webCondition(expr) {
|
|
292
|
+
const e = unwrap(expr);
|
|
293
|
+
if (ts.isPrefixUnaryExpression(e) && e.operator === ts.SyntaxKind.ExclamationToken) {
|
|
294
|
+
const inner = webCondition(e.operand);
|
|
295
|
+
return inner === undefined ? undefined : !inner;
|
|
296
|
+
}
|
|
297
|
+
if (ts.isIdentifier(e)) return e.text === "isWeb" ? true : undefined;
|
|
298
|
+
if (ts.isPropertyAccessExpression(e)) return e.name.text === "isWeb" ? true : undefined;
|
|
299
|
+
if (ts.isBinaryExpression(e)) {
|
|
300
|
+
const op = e.operatorToken.kind;
|
|
301
|
+
const eq =
|
|
302
|
+
op === ts.SyntaxKind.EqualsEqualsEqualsToken || op === ts.SyntaxKind.EqualsEqualsToken;
|
|
303
|
+
const ne =
|
|
304
|
+
op === ts.SyntaxKind.ExclamationEqualsEqualsToken ||
|
|
305
|
+
op === ts.SyntaxKind.ExclamationEqualsToken;
|
|
306
|
+
if (eq || ne) {
|
|
307
|
+
const sides = [unwrap(e.left), unwrap(e.right)];
|
|
308
|
+
const web = sides.some((side) => ts.isStringLiteral(side) && side.text === "web");
|
|
309
|
+
const target = sides.some((side) =>
|
|
310
|
+
/(?:Platform\.OS|TAMAGUI_TARGET)$/.test(side.getText(file)),
|
|
311
|
+
);
|
|
312
|
+
if (web && target) return eq;
|
|
313
|
+
}
|
|
314
|
+
if (op === ts.SyntaxKind.AmpersandAmpersandToken)
|
|
315
|
+
return webCondition(e.left) === true || webCondition(e.right) === true ? true : undefined;
|
|
316
|
+
}
|
|
317
|
+
return undefined;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** @param {ts.Node} node */
|
|
321
|
+
function webGated(node) {
|
|
322
|
+
for (let child = node, parent = node.parent; parent; child = parent, parent = parent.parent) {
|
|
323
|
+
if (ts.isConditionalExpression(parent) && child !== parent.condition) {
|
|
324
|
+
const web = webCondition(parent.condition);
|
|
325
|
+
if (web !== undefined && web === (child === parent.whenTrue)) return true;
|
|
326
|
+
}
|
|
327
|
+
if (
|
|
328
|
+
ts.isBinaryExpression(parent) &&
|
|
329
|
+
parent.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken &&
|
|
330
|
+
child === parent.right &&
|
|
331
|
+
webCondition(parent.left) === true
|
|
332
|
+
)
|
|
333
|
+
return true;
|
|
334
|
+
if (ts.isIfStatement(parent) && child !== parent.expression) {
|
|
335
|
+
const web = webCondition(parent.expression);
|
|
336
|
+
if (web !== undefined && web === (child === parent.thenStatement)) return true;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** @type {{ line: number }[]} */
|
|
343
|
+
const found = [];
|
|
344
|
+
/** @param {ts.Node} node */
|
|
345
|
+
function visit(node) {
|
|
346
|
+
const named =
|
|
347
|
+
(ts.isJsxAttribute(node) && node.name.getText(file) === "focusWithinStyle") ||
|
|
348
|
+
((ts.isPropertyAssignment(node) || ts.isShorthandPropertyAssignment(node)) &&
|
|
349
|
+
keyName(node.name) === "focusWithinStyle");
|
|
350
|
+
if (named && !webGated(node)) {
|
|
351
|
+
const { line } = file.getLineAndCharacterOfPosition(node.getStart(file));
|
|
352
|
+
found.push({ line: line + 1 });
|
|
353
|
+
}
|
|
354
|
+
ts.forEachChild(node, visit);
|
|
355
|
+
}
|
|
356
|
+
visit(file);
|
|
357
|
+
return found;
|
|
358
|
+
}
|
package/src/press-lint.spec.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
1
3
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
exportedPressClaimants,
|
|
6
|
+
findNativeFocusWithin,
|
|
7
|
+
findNestedPressClaimants,
|
|
8
|
+
} from "../press-lint.mjs";
|
|
3
9
|
|
|
4
10
|
const find = (source: string, imported?: Set<string>) =>
|
|
5
11
|
findNestedPressClaimants(source, "Fixture.tsx", imported).map((hit) => `${hit.tag}<${hit.owner}`);
|
|
@@ -113,3 +119,59 @@ describe("exportedPressClaimants", () => {
|
|
|
113
119
|
expect(exportedPressClaimants(source, "Fixture.tsx").sort()).toEqual(["Pill", "Ring"]);
|
|
114
120
|
});
|
|
115
121
|
});
|
|
122
|
+
|
|
123
|
+
describe("findNativeFocusWithin (FZ-8991 NATIVE-FOCUS-WITHIN)", () => {
|
|
124
|
+
const lines = (source: string, filename = "ViewSwitcher.tsx") =>
|
|
125
|
+
findNativeFocusWithin(source, filename).map((hit) => hit.line);
|
|
126
|
+
|
|
127
|
+
it("flags main's ViewSwitcher: the group's ring rendered on native too", () => {
|
|
128
|
+
const source = `export function ViewSwitcher() {
|
|
129
|
+
return (
|
|
130
|
+
<ToggleGroup
|
|
131
|
+
focusStyle={groupRing}
|
|
132
|
+
focusVisibleStyle={groupRing}
|
|
133
|
+
focusWithinStyle={groupRing}
|
|
134
|
+
>
|
|
135
|
+
<ToggleGroup.Item value="table" />
|
|
136
|
+
</ToggleGroup>
|
|
137
|
+
);
|
|
138
|
+
}`;
|
|
139
|
+
expect(lines(source)).toEqual([6]);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("passes the lane's ViewSwitcher: the ring spread only on web", () => {
|
|
143
|
+
const viewSwitcher = fileURLToPath(
|
|
144
|
+
new URL("../../components/src/layouts/ViewSwitcher.tsx", import.meta.url),
|
|
145
|
+
);
|
|
146
|
+
const source = readFileSync(viewSwitcher, "utf8");
|
|
147
|
+
expect(source).toContain("focusWithinStyle");
|
|
148
|
+
expect(findNativeFocusWithin(source, viewSwitcher)).toEqual([]);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("flags the key in a styled config, a spread object and a non-web branch", () => {
|
|
152
|
+
const source = `
|
|
153
|
+
const Frame = styled(View, { focusWithinStyle: { outlineWidth: 2 } });
|
|
154
|
+
const a = <View {...{ focusWithinStyle: ring }} />;
|
|
155
|
+
const b = <View {...(isWeb ? undefined : { focusWithinStyle: ring })} />;
|
|
156
|
+
const c = <View {...(isNative && { focusWithinStyle: ring })} />;`;
|
|
157
|
+
expect(lines(source)).toEqual([2, 3, 4, 5]);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("passes every web gate", () => {
|
|
161
|
+
const source = `
|
|
162
|
+
const a = <View {...(isWeb ? { focusWithinStyle: ring } : undefined)} />;
|
|
163
|
+
const b = <View {...(isWeb && { focusWithinStyle: ring })} />;
|
|
164
|
+
const c = <View {...(!isWeb ? undefined : { focusWithinStyle: ring })} />;
|
|
165
|
+
const d = <View {...(Platform.OS === "web" ? { focusWithinStyle: ring } : {})} />;
|
|
166
|
+
const e = <View {...(process.env.TAMAGUI_TARGET === "web" && { focusWithinStyle })} />;
|
|
167
|
+
if (isWeb) props.focusWithinStyle = ring;
|
|
168
|
+
if (isWeb) Object.assign(props, { focusWithinStyle: ring });`;
|
|
169
|
+
expect(lines(source)).toEqual([]);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("skips files that only render on web", () => {
|
|
173
|
+
const source = `const a = <View focusWithinStyle={ring} />;`;
|
|
174
|
+
expect(lines(source, "Frame.web.tsx")).toEqual([]);
|
|
175
|
+
expect(lines(source, "Frame.tsx")).toEqual([1]);
|
|
176
|
+
});
|
|
177
|
+
});
|