Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(gates): an item or a shared control's own button is not hand-rolled

esengine3025080386b2
diff --git a/tools/baselines/theme-drift.json b/tools/baselines/theme-drift.json
index 0495c73dc..d9c50c19d 100644
--- a/tools/baselines/theme-drift.json
+++ b/tools/baselines/theme-drift.json
@@ -100,23 +100,17 @@
"components/AudioWavePreview.tsx": 1,
"components/BuildDialog.tsx": 6,
"components/BuildSizePanel.tsx": 1,
- "components/Button.tsx": 1,
"components/ColorControl.tsx": 1,
"components/CreatePopover.tsx": 1,
"components/ErrorBoundary.tsx": 1,
"components/FindingLocations.tsx": 2,
"components/FindUsagesDialog.tsx": 1,
- "components/IconButton.tsx": 1,
"components/MarkdownView.tsx": 2,
- "components/Menu.tsx": 3,
"components/OverlayMenu.tsx": 1,
- "components/QuickOpen.tsx": 3,
+ "components/QuickOpen.tsx": 2,
"components/SaveButton.tsx": 1,
- "components/Segmented.tsx": 1,
- "components/Select.tsx": 2,
"components/SettingsDialog.tsx": 2,
"components/SettingsRow.tsx": 5,
- "components/SuggestInput.tsx": 1,
"components/TilemapPickerDialog.tsx": 1,
"components/Toaster.tsx": 2,
"components/Transport.tsx": 1,
@@ -130,7 +124,6 @@
"layout/SubsystemIndicator.tsx": 1,
"layout/Toolbar.tsx": 6,
"layout/WindowControls.tsx": 3,
- "panels/CollisionBrushPalette.tsx": 1,
"panels/ContentBrowser.tsx": 8,
"panels/ControllersPanel.tsx": 7,
"panels/Details.tsx": 30,
@@ -138,7 +131,7 @@
"panels/HealthPanel.tsx": 1,
"panels/HistoryPanel.tsx": 5,
"panels/inspector/componentDecorators.tsx": 12,
- "panels/inspector/controls.tsx": 26,
+ "panels/inspector/controls.tsx": 21,
"panels/LightingPanel.tsx": 2,
"panels/Outliner.tsx": 1,
"panels/OutputLog.tsx": 1,
@@ -149,7 +142,7 @@
"panels/Sequencer.tsx": 9,
"panels/SpineDiagnosticsSection.tsx": 1,
"panels/SpinePreviewPane.tsx": 1,
- "panels/TilemapPainter.tsx": 12,
+ "panels/TilemapPainter.tsx": 11,
"panels/TilesetEditor.tsx": 26,
"panels/UIWidgetsPanel.tsx": 1,
"panels/Viewport.tsx": 6,
diff --git a/tools/check-theme.mjs b/tools/check-theme.mjs
index 3b33ba3fa..16750b954 100644
--- a/tools/check-theme.mjs
+++ b/tools/check-theme.mjs
@@ -384,6 +384,15 @@ const nativeTitles = () => {
return out;
};
+/** The shared controls themselves: the one `<button>` each renders is the component. */
+const PRIMITIVES = new Set([
+ 'components/Button.tsx', 'components/IconButton.tsx', 'components/Menu.tsx',
+ 'components/Select.tsx', 'components/Segmented.tsx',
+]);
+
+/** A button that declares itself an item of a list, tab strip or menu is not an action button. */
+const ITEM_ROLE = /\brole=(?:"|\{?['"`])(?:option|tab|menuitem|menuitemcheckbox|menuitemradio|radio)\b/;
+
/**
* Buttons the editor hand-rolled rather than took from `<Button>`/`<IconButton>`.
* A ratchet, not a rule: a raw `<button>` in a tile cell is right.
@@ -397,7 +406,8 @@ const handRolledByFile = () => {
if (!/\.tsx$/.test(e.name)) continue;
const text = readFileSync(full, 'utf8');
const rel = path.relative(path.join(ROOT, 'desktop', 'src'), full).replaceAll(path.sep, '/');
- const n = [...text.matchAll(/<button\b/g)].length;
+ if (PRIMITIVES.has(rel)) continue;
+ const n = [...text.matchAll(/<button\b([^<]*?)\/?>/gs)].filter((m) => !ITEM_ROLE.test(m[1])).length;
if (n > 0) out[rel] = n;
}
};