@estiva-app/ui 0.83.0 → 0.85.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/dist/CommentBox.d.ts +12 -3
- package/dist/CommentBox.d.ts.map +1 -1
- package/dist/commentBoxFrame.d.ts +93 -0
- package/dist/commentBoxFrame.d.ts.map +1 -0
- package/dist/editor.d.ts +0 -1
- package/dist/editor.d.ts.map +1 -1
- package/dist/editor.js +445 -337
- package/dist/editor.js.map +4 -4
- package/dist/eslint/index.js +594 -559
- package/dist/eslint/index.js.map +4 -4
- package/dist/eslint/no-hand-rolled-behaviour.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/links.d.ts.map +1 -1
- package/dist/looks.d.ts +1 -1
- package/package.json +1 -1
- package/registry.json +16 -128
- package/src/CommentBox.mdx +15 -4
- package/src/CommentBox.stories.tsx +78 -2
- package/src/CommentBox.test.tsx +185 -3
- package/src/CommentBox.tsx +241 -76
- package/src/{ComposeBox.tsx → commentBoxFrame.tsx} +76 -25
- package/src/editor.ts +1 -1
- package/src/eslint/no-hand-rolled-behaviour.test.ts +27 -0
- package/src/eslint/no-hand-rolled-behaviour.ts +44 -0
- package/src/links.ts +4 -1
- package/src/looks.ts +1 -1
- package/src/registry/app.test.ts +3 -4
- package/src/registry/registry.test.ts +5 -5
- package/stories/Choosing.mdx +0 -1
- package/dist/ComposeBox.d.ts +0 -57
- package/dist/ComposeBox.d.ts.map +0 -1
- package/src/ComposeBox.mdx +0 -58
- package/src/ComposeBox.stories.tsx +0 -81
package/dist/eslint/index.js
CHANGED
|
@@ -121,6 +121,458 @@ var componentHasAStory = {
|
|
|
121
121
|
}
|
|
122
122
|
};
|
|
123
123
|
|
|
124
|
+
// src/eslint/no-rebuilt-behaviour.ts
|
|
125
|
+
var BASE_UI_PARTS = {
|
|
126
|
+
"alert-dialog": { use: "DialogShell", more: " To ask yes or no, `ConfirmDialog`." },
|
|
127
|
+
autocomplete: { use: "CommandPalette" },
|
|
128
|
+
avatar: { use: "Avatar" },
|
|
129
|
+
button: { use: "Button", more: " Icon only, `IconButton`." },
|
|
130
|
+
checkbox: { use: "Checkbox" },
|
|
131
|
+
collapsible: { use: "CollapsibleSection" },
|
|
132
|
+
combobox: { use: "ChipInput" },
|
|
133
|
+
dialog: { use: "DialogShell", more: " To search and act, `CommandPalette`." },
|
|
134
|
+
field: { use: "Field" },
|
|
135
|
+
fieldset: { use: "Form" },
|
|
136
|
+
form: { use: "Form" },
|
|
137
|
+
input: { use: "TextInput", more: " For a search, `SearchInput`." },
|
|
138
|
+
menu: { use: "Menu" },
|
|
139
|
+
popover: { use: "Popover" },
|
|
140
|
+
"preview-card": { use: "PreviewCard" },
|
|
141
|
+
progress: { use: "ProgressBar" },
|
|
142
|
+
"scroll-area": { use: "ScrollArea" },
|
|
143
|
+
select: { use: "Select" },
|
|
144
|
+
separator: { use: "Divider" },
|
|
145
|
+
tabs: { use: "Tabs" },
|
|
146
|
+
toast: { use: "Toast" },
|
|
147
|
+
toggle: { use: "Reaction" },
|
|
148
|
+
toolbar: { use: "Toolbar" },
|
|
149
|
+
tooltip: { use: "Tooltip", more: " Around a control, `WithTooltip`." },
|
|
150
|
+
accordion: null,
|
|
151
|
+
"checkbox-group": null,
|
|
152
|
+
"context-menu": null,
|
|
153
|
+
drawer: null,
|
|
154
|
+
menubar: null,
|
|
155
|
+
meter: null,
|
|
156
|
+
"navigation-menu": null,
|
|
157
|
+
"number-field": null,
|
|
158
|
+
"otp-field": null,
|
|
159
|
+
radio: null,
|
|
160
|
+
"radio-group": null,
|
|
161
|
+
slider: null,
|
|
162
|
+
switch: null,
|
|
163
|
+
"toggle-group": null
|
|
164
|
+
};
|
|
165
|
+
var LIST_PART = {
|
|
166
|
+
use: "Select",
|
|
167
|
+
more: " To pick several, `ChipInput`; to search and act, `CommandPalette`; to tick several in a list, `Checkbox` with `row`; for the list a text editor opens as you type, `SuggestionMenu`."
|
|
168
|
+
};
|
|
169
|
+
var MESSAGE_PART = { use: "FieldLine", more: " For a notice, `Banner`; for a message that comes and goes, `Toast`." };
|
|
170
|
+
var ROLE_PARTS = {
|
|
171
|
+
dialog: { thing: "dialog", part: { use: "DialogShell", more: " To ask yes or no, `ConfirmDialog`." } },
|
|
172
|
+
alertdialog: { thing: "dialog", part: { use: "ConfirmDialog" } },
|
|
173
|
+
menu: { thing: "menu", part: { use: "Menu" } },
|
|
174
|
+
menuitem: { thing: "menu", part: { use: "Menu" } },
|
|
175
|
+
menuitemcheckbox: { thing: "menu", part: { use: "Menu" } },
|
|
176
|
+
menuitemradio: { thing: "menu", part: { use: "Menu" } },
|
|
177
|
+
listbox: { thing: "list", part: LIST_PART },
|
|
178
|
+
option: { thing: "list", part: LIST_PART },
|
|
179
|
+
combobox: { thing: "list", part: LIST_PART },
|
|
180
|
+
tablist: { thing: "set of tabs", part: { use: "Tabs" } },
|
|
181
|
+
tab: { thing: "set of tabs", part: { use: "Tabs" } },
|
|
182
|
+
tabpanel: { thing: "set of tabs", part: { use: "Tabs" } },
|
|
183
|
+
toolbar: { thing: "toolbar", part: { use: "Toolbar" } },
|
|
184
|
+
progressbar: { thing: "progress bar", part: { use: "ProgressBar" } },
|
|
185
|
+
checkbox: { thing: "tick box", part: { use: "Checkbox" } },
|
|
186
|
+
separator: { thing: "divider", part: { use: "Divider" } },
|
|
187
|
+
button: { thing: "button", part: { use: "Button", more: " Icon only, `IconButton`." } },
|
|
188
|
+
link: { thing: "link", part: { use: "Link" } },
|
|
189
|
+
tooltip: { thing: "tooltip", part: { use: "Tooltip", more: " Around a control, `WithTooltip`." } },
|
|
190
|
+
alert: { thing: "message", part: MESSAGE_PART },
|
|
191
|
+
status: { thing: "message", part: MESSAGE_PART },
|
|
192
|
+
menubar: { thing: "menu bar", part: null },
|
|
193
|
+
switch: { thing: "switch", part: null },
|
|
194
|
+
radio: { thing: "radio button", part: null },
|
|
195
|
+
radiogroup: { thing: "radio group", part: null },
|
|
196
|
+
slider: { thing: "slider", part: null },
|
|
197
|
+
spinbutton: { thing: "number field", part: null },
|
|
198
|
+
meter: { thing: "meter", part: null }
|
|
199
|
+
};
|
|
200
|
+
var WALKING_KEYS = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Home", "End", "PageUp", "PageDown"];
|
|
201
|
+
var PAGE_EVENTS = {
|
|
202
|
+
mousedown: "press",
|
|
203
|
+
pointerdown: "press",
|
|
204
|
+
click: "press",
|
|
205
|
+
touchstart: "press",
|
|
206
|
+
keydown: "key",
|
|
207
|
+
keyup: "key",
|
|
208
|
+
keypress: "key",
|
|
209
|
+
focusin: "focus",
|
|
210
|
+
focusout: "focus",
|
|
211
|
+
scroll: "follow",
|
|
212
|
+
resize: "follow"
|
|
213
|
+
};
|
|
214
|
+
var INTERACTIVE_ELEMENTS = /* @__PURE__ */ new Set(["a", "button", "input", "select", "textarea", "summary", "iframe", "embed", "object", "audio", "video"]);
|
|
215
|
+
var SCROLL_CLASS = /^overflow(?:-[xy])?-(?:auto|scroll)$/;
|
|
216
|
+
var uses = (parts) => [
|
|
217
|
+
...new Set(parts.flatMap((p) => p ? [p.use, ...[...(p.more ?? "").matchAll(/`([A-Z]\w+)`/g)].map((m) => m[1])] : []))
|
|
218
|
+
];
|
|
219
|
+
var OWNED_BEHAVIOURS = [
|
|
220
|
+
{
|
|
221
|
+
id: "base-ui",
|
|
222
|
+
behaviour: "Is built on Base UI",
|
|
223
|
+
baseUi: Object.keys(BASE_UI_PARTS),
|
|
224
|
+
owners: uses(Object.values(BASE_UI_PARTS)),
|
|
225
|
+
reads: "an import from @base-ui/react (and the old @base-ui-components spelling)"
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
id: "portal",
|
|
229
|
+
behaviour: "Floats on top of the page",
|
|
230
|
+
baseUi: ["Dialog", "AlertDialog", "Popover", "Menu", "Select", "Combobox", "Autocomplete", "Tooltip", "PreviewCard", "Toast"],
|
|
231
|
+
owners: ["DialogShell", "ConfirmDialog", "CommandPalette", "Lightbox", "Popover", "Menu", "Select", "ChipInput", "Tooltip", "PreviewCard", "Toast"],
|
|
232
|
+
reads: "createPortal, called, or imported and never called"
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
id: "press-outside",
|
|
236
|
+
behaviour: "Closes on a press outside",
|
|
237
|
+
baseUi: ["Dialog", "AlertDialog", "Popover", "Menu", "Select", "Combobox", "Tooltip", "PreviewCard"],
|
|
238
|
+
owners: ["DialogShell", "Popover", "Menu", "Select", "PreviewCard"],
|
|
239
|
+
reads: "a mousedown, pointerdown, click or touchstart listener on window or document"
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
id: "page-keys",
|
|
243
|
+
behaviour: "Takes its keys by itself",
|
|
244
|
+
baseUi: ["Dialog", "AlertDialog", "Popover", "Menu", "Select", "Combobox", "Tooltip", "PreviewCard", "Toast"],
|
|
245
|
+
owners: ["DialogShell", "Lightbox", "Popover", "Menu", "Select", "Tabs", "Toolbar"],
|
|
246
|
+
reads: "a keydown, keyup or keypress listener on window or document"
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
id: "focus",
|
|
250
|
+
behaviour: "Holds focus inside while open, and gives it back",
|
|
251
|
+
baseUi: ["Dialog", "AlertDialog", "Popover", "Menu", "Select", "Combobox"],
|
|
252
|
+
owners: ["DialogShell", "CommandPalette", "Lightbox"],
|
|
253
|
+
reads: "a focusin or focusout listener on window or document; the Tab key compared by hand"
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
id: "scroll-lock",
|
|
257
|
+
behaviour: "Stops the page behind it scrolling",
|
|
258
|
+
baseUi: ["Dialog", "AlertDialog"],
|
|
259
|
+
owners: ["DialogShell", "Lightbox"],
|
|
260
|
+
reads: "overflow written into the style of document.body or document.documentElement"
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
id: "follow",
|
|
264
|
+
behaviour: "Stays attached to its anchor on scroll and resize",
|
|
265
|
+
baseUi: ["Popover", "Menu", "Select", "Combobox", "Tooltip", "PreviewCard", "Toast"],
|
|
266
|
+
owners: ["Popover", "Menu", "Select", "Tooltip", "PreviewCard"],
|
|
267
|
+
reads: "a scroll or resize listener on window or document"
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
id: "walking",
|
|
271
|
+
behaviour: "Moves through its items with the arrow keys",
|
|
272
|
+
baseUi: ["Menu", "Select", "Combobox", "Autocomplete", "Tabs", "Toolbar"],
|
|
273
|
+
owners: ["Menu", "Select", "ChipInput", "CommandPalette", "SuggestionMenu", "Tabs", "Toolbar"],
|
|
274
|
+
reads: `a key compared by hand with ${WALKING_KEYS.join(", ")}`
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
id: "role",
|
|
278
|
+
behaviour: "Says what it is to assistive technology",
|
|
279
|
+
baseUi: ["Dialog", "AlertDialog", "Menu", "Select", "Combobox", "Tabs", "Toolbar", "Progress", "Checkbox", "Separator", "Button"],
|
|
280
|
+
owners: uses(Object.values(ROLE_PARTS).map((r) => r.part)),
|
|
281
|
+
reads: `role written by hand: ${Object.keys(ROLE_PARTS).join(", ")}`
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
id: "tab-stop",
|
|
285
|
+
behaviour: "Is reachable with Tab",
|
|
286
|
+
baseUi: ["Button", "Toggle", "Checkbox", "Tabs", "Toolbar", "ScrollArea"],
|
|
287
|
+
owners: ["Button", "IconButton", "Link"],
|
|
288
|
+
reads: "tabIndex that can be 0 or more, on an element that is not a control"
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
id: "scroll",
|
|
292
|
+
behaviour: "Scrolls with our scrollbar",
|
|
293
|
+
baseUi: ["ScrollArea"],
|
|
294
|
+
owners: ["ScrollArea"],
|
|
295
|
+
reads: "overflow-auto or overflow-scroll (x or y, behind any variant) in a string, or overflow auto or scroll in a style"
|
|
296
|
+
}
|
|
297
|
+
];
|
|
298
|
+
var PAGE_TARGETS = /* @__PURE__ */ new Set(["window", "document", "globalThis", "self", "document.body", "document.documentElement", "window.document"]);
|
|
299
|
+
function anchorOf(node) {
|
|
300
|
+
if (node.type === "FunctionDeclaration") {
|
|
301
|
+
return node.parent && /^Export/.test(node.parent.type) ? node.parent : node;
|
|
302
|
+
}
|
|
303
|
+
let child5 = node;
|
|
304
|
+
for (let p = node.parent; p; child5 = p, p = p.parent) {
|
|
305
|
+
if (p.type === "JSXOpeningElement" || p.type === "Property" || p.type === "MethodDefinition" || p.type === "PropertyDefinition") return p;
|
|
306
|
+
if (p.type === "ArrayExpression") return child5;
|
|
307
|
+
if (p.type !== "BlockStatement" && /(Statement|Declaration)$/.test(p.type)) return p;
|
|
308
|
+
}
|
|
309
|
+
return node;
|
|
310
|
+
}
|
|
311
|
+
function enclosingFunction(node) {
|
|
312
|
+
for (let p = node.parent; p; p = p.parent) {
|
|
313
|
+
if (p.type === "FunctionDeclaration" || p.type === "FunctionExpression" || p.type === "ArrowFunctionExpression") return p;
|
|
314
|
+
}
|
|
315
|
+
return void 0;
|
|
316
|
+
}
|
|
317
|
+
function stringOf(node) {
|
|
318
|
+
if (!node) return void 0;
|
|
319
|
+
if (node.type === "Literal" && typeof node.value === "string") return node.value;
|
|
320
|
+
const quasis = node.quasis;
|
|
321
|
+
const expressions = node.expressions;
|
|
322
|
+
if (node.type === "TemplateLiteral" && expressions?.length === 0) return quasis?.[0]?.value.cooked ?? void 0;
|
|
323
|
+
return void 0;
|
|
324
|
+
}
|
|
325
|
+
function stringsOf(node) {
|
|
326
|
+
if (!node) return [];
|
|
327
|
+
if (node.type === "JSXExpressionContainer") return stringsOf(node.expression);
|
|
328
|
+
const s = stringOf(node);
|
|
329
|
+
if (s !== void 0) return [s];
|
|
330
|
+
if (node.type === "ConditionalExpression") return [...stringsOf(node.consequent), ...stringsOf(node.alternate)];
|
|
331
|
+
if (node.type === "LogicalExpression") return [...stringsOf(node.left), ...stringsOf(node.right)];
|
|
332
|
+
return [];
|
|
333
|
+
}
|
|
334
|
+
function canBeTabStop(node) {
|
|
335
|
+
if (!node) return false;
|
|
336
|
+
if (node.type === "JSXExpressionContainer") return canBeTabStop(node.expression);
|
|
337
|
+
if (node.type === "Literal") {
|
|
338
|
+
if (typeof node.value === "number") return node.value >= 0;
|
|
339
|
+
if (typeof node.value === "string") return /^\s*\d+\s*$/.test(node.value);
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
if (node.type === "ConditionalExpression") return canBeTabStop(node.consequent) || canBeTabStop(node.alternate);
|
|
343
|
+
if (node.type === "LogicalExpression") return canBeTabStop(node.left) || canBeTabStop(node.right);
|
|
344
|
+
if (node.type === "TSAsExpression" || node.type === "TSNonNullExpression") return canBeTabStop(node.expression);
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
function utilityOf(token) {
|
|
348
|
+
let depth = 0;
|
|
349
|
+
let last = -1;
|
|
350
|
+
for (let i = 0; i < token.length; i++) {
|
|
351
|
+
const c = token[i];
|
|
352
|
+
if (c === "[") depth++;
|
|
353
|
+
else if (c === "]") depth--;
|
|
354
|
+
else if (c === ":" && depth === 0) last = i;
|
|
355
|
+
}
|
|
356
|
+
return token.slice(last + 1).replace(/^!/, "").replace(/!$/, "");
|
|
357
|
+
}
|
|
358
|
+
function baseUiModule(source) {
|
|
359
|
+
const m = /^@base-ui(?:-components)?\/([^/]+)(?:\/(.+))?$/.exec(source);
|
|
360
|
+
if (!m) return void 0;
|
|
361
|
+
const [, pkg, sub] = m;
|
|
362
|
+
return pkg === "react" ? sub ?? "" : `${pkg}${sub ? `/${sub}` : ""}`;
|
|
363
|
+
}
|
|
364
|
+
function isKeySubject(node) {
|
|
365
|
+
if (!node) return false;
|
|
366
|
+
if (node.type === "Identifier") return node.name === "key" || node.name === "code";
|
|
367
|
+
if (node.type !== "MemberExpression" || node.computed) return false;
|
|
368
|
+
const property = node.property;
|
|
369
|
+
return property.type === "Identifier" && (property.name === "key" || property.name === "code");
|
|
370
|
+
}
|
|
371
|
+
function pageTarget(node, text) {
|
|
372
|
+
return (node.type === "Identifier" || node.type === "MemberExpression") && PAGE_TARGETS.has(text);
|
|
373
|
+
}
|
|
374
|
+
var noRebuiltBehaviour = {
|
|
375
|
+
meta: {
|
|
376
|
+
type: "problem",
|
|
377
|
+
docs: { description: "Behaviour @estiva-app/ui already owns, rebuilt by hand in an app" },
|
|
378
|
+
schema: [],
|
|
379
|
+
messages: {
|
|
380
|
+
baseUi: "Only @estiva-app/ui imports Base UI (`{{module}}`). Use `{{use}}` from @estiva-app/ui.{{more}}",
|
|
381
|
+
baseUiNoPart: "Only @estiva-app/ui imports Base UI (`{{module}}`), and it has no part built on it yet. Do not build one here: ask Katerina, and it gets made in @estiva-app/ui.",
|
|
382
|
+
portal: "A layer put on top of the page by hand (`createPortal`). Every floating part of @estiva-app/ui carries its own: `DialogShell` for a dialog, `Popover` for a panel, `Menu`, `Select`, `Tooltip`, `PreviewCard`, `Toast`.",
|
|
383
|
+
press: "A `{{event}}` listener on `{{target}}`: closing on a press outside, by hand. `Popover`, `Menu`, `Select`, `DialogShell` and `PreviewCard` from @estiva-app/ui close themselves.",
|
|
384
|
+
key: "A `{{event}}` listener on `{{target}}`: keys taken for the whole page, by hand. `DialogShell`, `Popover`, `Menu` and `Select` from @estiva-app/ui close on Escape themselves; `Menu`, `Select`, `Tabs` and `Toolbar` move with the arrow keys.",
|
|
385
|
+
focus: "A `{{event}}` listener on `{{target}}`: focus held by hand. `DialogShell` and `CommandPalette` from @estiva-app/ui keep focus inside and give it back.",
|
|
386
|
+
follow: "A `{{event}}` listener on `{{target}}`: following an anchor by hand. `Popover`, `Menu`, `Select`, `Tooltip` and `PreviewCard` from @estiva-app/ui stay attached to theirs.",
|
|
387
|
+
scrollLock: "The page's scroll locked by hand. `DialogShell` from @estiva-app/ui stops the page scrolling while it is open, and gives it back.",
|
|
388
|
+
walking: "Arrow keys handled by hand (`{{key}}`). `Menu`, `Select`, `ChipInput`, `CommandPalette`, `Tabs` and `Toolbar` from @estiva-app/ui move through their items themselves.",
|
|
389
|
+
tabKey: "The Tab key handled by hand. `DialogShell` and `CommandPalette` from @estiva-app/ui keep focus inside themselves.",
|
|
390
|
+
role: 'A hand-written `role="{{role}}"` is a hand-made {{thing}}. Use `{{use}}` from @estiva-app/ui.{{more}}',
|
|
391
|
+
roleNoPart: 'A hand-written `role="{{role}}"` is a hand-made {{thing}}, and @estiva-app/ui has no part for one yet. Do not build one here: ask Katerina, and it gets made in @estiva-app/ui.',
|
|
392
|
+
tabStop: "`tabIndex={{value}}` makes a `<{{element}}>` a Tab stop by hand. Use `Button`, `IconButton` or `Link` from @estiva-app/ui, which are reachable already.",
|
|
393
|
+
scrollClass: "`{{token}}` scrolls with the browser's scrollbar. Use `ScrollArea` from @estiva-app/ui, which draws ours.",
|
|
394
|
+
scrollStyle: "`{{style}}` scrolls with the browser's scrollbar. Use `ScrollArea` from @estiva-app/ui, which draws ours.",
|
|
395
|
+
...ESCAPE_MESSAGES
|
|
396
|
+
}
|
|
397
|
+
},
|
|
398
|
+
create(context) {
|
|
399
|
+
const { sourceCode } = context;
|
|
400
|
+
const text = (node) => sourceCode.getText(node);
|
|
401
|
+
const escapes = /* @__PURE__ */ new Map();
|
|
402
|
+
const escaped = (anchor) => {
|
|
403
|
+
if (!escapes.has(anchor)) escapes.set(anchor, isEscaped(context, anchor));
|
|
404
|
+
return escapes.get(anchor) === true;
|
|
405
|
+
};
|
|
406
|
+
const seen = /* @__PURE__ */ new Set();
|
|
407
|
+
const report = (anchor, at, messageId, data = {}, once = `${at.range[0]}`) => {
|
|
408
|
+
const key = `${anchor.range[0]}|${messageId}|${once}`;
|
|
409
|
+
if (seen.has(key)) return;
|
|
410
|
+
seen.add(key);
|
|
411
|
+
if (escaped(anchor)) return;
|
|
412
|
+
context.report({ loc: at.loc, messageId, data });
|
|
413
|
+
};
|
|
414
|
+
const importSource = (node, source) => {
|
|
415
|
+
const value = stringOf(source);
|
|
416
|
+
if (value === void 0) return;
|
|
417
|
+
const module = baseUiModule(value);
|
|
418
|
+
if (module === void 0) return;
|
|
419
|
+
const part = Object.hasOwn(BASE_UI_PARTS, module) ? BASE_UI_PARTS[module] : null;
|
|
420
|
+
const anchor = anchorOf(node);
|
|
421
|
+
if (part) report(anchor, node, "baseUi", { module: value, use: part.use, more: part.more ?? "" });
|
|
422
|
+
else report(anchor, node, "baseUiNoPart", { module: value });
|
|
423
|
+
};
|
|
424
|
+
const keyCompared = (node, key) => {
|
|
425
|
+
if (key === void 0) return;
|
|
426
|
+
const fn = enclosingFunction(node);
|
|
427
|
+
const anchor = anchorOf(fn ?? node);
|
|
428
|
+
if (WALKING_KEYS.includes(key)) report(anchor, node, "walking", { key }, `walking@${fn?.range[0] ?? node.range[0]}`);
|
|
429
|
+
else if (key === "Tab") report(anchor, node, "tabKey", {}, `tab@${fn?.range[0] ?? node.range[0]}`);
|
|
430
|
+
};
|
|
431
|
+
const classTokens = (node, value) => {
|
|
432
|
+
for (const token of value.split(/\s+/)) {
|
|
433
|
+
if (token && SCROLL_CLASS.test(utilityOf(token))) report(anchorOf(node), node, "scrollClass", { token }, `class@${token}`);
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
const portalImports = /* @__PURE__ */ new Map();
|
|
437
|
+
let portalCalled = false;
|
|
438
|
+
return {
|
|
439
|
+
ImportDeclaration(ruleNode) {
|
|
440
|
+
const node = ruleNode;
|
|
441
|
+
importSource(node, node.source);
|
|
442
|
+
if (stringOf(node.source) !== "react-dom") return;
|
|
443
|
+
for (const specifier of node.specifiers) {
|
|
444
|
+
const imported = specifier.imported;
|
|
445
|
+
if (specifier.type === "ImportSpecifier" && imported?.name === "createPortal") portalImports.set(specifier.local.name, node);
|
|
446
|
+
}
|
|
447
|
+
},
|
|
448
|
+
ExportNamedDeclaration(ruleNode) {
|
|
449
|
+
const node = ruleNode;
|
|
450
|
+
if (node.source) importSource(node, node.source);
|
|
451
|
+
},
|
|
452
|
+
ExportAllDeclaration(ruleNode) {
|
|
453
|
+
const node = ruleNode;
|
|
454
|
+
importSource(node, node.source);
|
|
455
|
+
},
|
|
456
|
+
ImportExpression(ruleNode) {
|
|
457
|
+
const node = ruleNode;
|
|
458
|
+
importSource(node, node.source);
|
|
459
|
+
},
|
|
460
|
+
CallExpression(ruleNode) {
|
|
461
|
+
const node = ruleNode;
|
|
462
|
+
const callee = node.callee;
|
|
463
|
+
const args = node.arguments;
|
|
464
|
+
if (callee.type === "Identifier" && callee.name === "require") importSource(node, args[0]);
|
|
465
|
+
if (callee.type === "Identifier" && portalImports.has(callee.name)) {
|
|
466
|
+
portalCalled = true;
|
|
467
|
+
report(anchorOf(node), node, "portal");
|
|
468
|
+
}
|
|
469
|
+
if (callee.type !== "MemberExpression") return;
|
|
470
|
+
const object = callee.object;
|
|
471
|
+
const property = callee.property;
|
|
472
|
+
if (property.type !== "Identifier") return;
|
|
473
|
+
if (property.name === "createPortal") {
|
|
474
|
+
report(anchorOf(node), node, "portal");
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
if (property.name === "addEventListener") {
|
|
478
|
+
const target = text(object);
|
|
479
|
+
if (!pageTarget(object, target)) return;
|
|
480
|
+
const event = stringOf(args[0]);
|
|
481
|
+
const group = event === void 0 ? void 0 : PAGE_EVENTS[event];
|
|
482
|
+
if (!event || !group) return;
|
|
483
|
+
report(anchorOf(node), node, group, { event, target });
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
if (property.name === "includes" && object.type === "ArrayExpression" && isKeySubject(args[0])) {
|
|
487
|
+
for (const element of object.elements) keyCompared(node, stringOf(element));
|
|
488
|
+
}
|
|
489
|
+
},
|
|
490
|
+
AssignmentExpression(ruleNode) {
|
|
491
|
+
const node = ruleNode;
|
|
492
|
+
const left = node.left;
|
|
493
|
+
if (left.type !== "MemberExpression") return;
|
|
494
|
+
const property = left.property;
|
|
495
|
+
const object = left.object;
|
|
496
|
+
const handler = property.type === "Identifier" ? /^on([a-z]+)$/.exec(property.name) : null;
|
|
497
|
+
if (handler && pageTarget(object, text(object)) && PAGE_EVENTS[handler[1]]) {
|
|
498
|
+
report(anchorOf(node), node, PAGE_EVENTS[handler[1]], { event: handler[1], target: text(object) });
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
if (/^document\.(?:body|documentElement)\.style\.overflow[XY]?$/.test(text(left))) report(anchorOf(node), node, "scrollLock");
|
|
502
|
+
},
|
|
503
|
+
BinaryExpression(ruleNode) {
|
|
504
|
+
const node = ruleNode;
|
|
505
|
+
if (!["===", "==", "!==", "!="].includes(node.operator)) return;
|
|
506
|
+
const left = node.left;
|
|
507
|
+
const right = node.right;
|
|
508
|
+
if (isKeySubject(left)) keyCompared(node, stringOf(right));
|
|
509
|
+
else if (isKeySubject(right)) keyCompared(node, stringOf(left));
|
|
510
|
+
},
|
|
511
|
+
SwitchCase(ruleNode) {
|
|
512
|
+
const node = ruleNode;
|
|
513
|
+
const statement2 = node.parent;
|
|
514
|
+
if (node.test && isKeySubject(statement2.discriminant)) keyCompared(node, stringOf(node.test));
|
|
515
|
+
},
|
|
516
|
+
JSXAttribute(ruleNode) {
|
|
517
|
+
const node = ruleNode;
|
|
518
|
+
const nameNode = node.name;
|
|
519
|
+
if (nameNode.type !== "JSXIdentifier") return;
|
|
520
|
+
const name = nameNode.name;
|
|
521
|
+
const element = node.parent;
|
|
522
|
+
const value = node.value;
|
|
523
|
+
if (name === "role") {
|
|
524
|
+
for (const role of stringsOf(value).flatMap((v) => v.trim().split(/\s+/))) {
|
|
525
|
+
if (!Object.hasOwn(ROLE_PARTS, role)) continue;
|
|
526
|
+
const { thing, part } = ROLE_PARTS[role];
|
|
527
|
+
if (part) report(element, node, "role", { role, thing, use: part.use, more: part.more ?? "" });
|
|
528
|
+
else report(element, node, "roleNoPart", { role, thing });
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
if (name === "tabIndex" || name === "tabindex") {
|
|
534
|
+
const tag = element.name;
|
|
535
|
+
if (tag.type !== "JSXIdentifier" || !/^[a-z]/.test(tag.name) || INTERACTIVE_ELEMENTS.has(tag.name)) return;
|
|
536
|
+
const attributes = element.attributes;
|
|
537
|
+
const editable = attributes.some((a) => a.type === "JSXAttribute" && /^contenteditable$/i.test(a.name.name ?? ""));
|
|
538
|
+
if (editable || !canBeTabStop(value)) return;
|
|
539
|
+
report(element, node, "tabStop", { value: value ? text(value).replace(/^\{|\}$/g, "") : "", element: tag.name });
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
if (name === "style" && value?.type === "JSXExpressionContainer") {
|
|
543
|
+
const object = value.expression;
|
|
544
|
+
if (object.type !== "ObjectExpression") return;
|
|
545
|
+
for (const property of object.properties) {
|
|
546
|
+
if (property.type !== "Property") continue;
|
|
547
|
+
const key = property.key;
|
|
548
|
+
const keyName = key.type === "Identifier" ? key.name : stringOf(key);
|
|
549
|
+
if (!keyName || !/^overflow[XY]?$/.test(keyName)) continue;
|
|
550
|
+
const setting = stringOf(property.value);
|
|
551
|
+
if (setting === "auto" || setting === "scroll") report(element, property, "scrollStyle", { style: `${keyName}: '${setting}'` }, `style@${keyName}`);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
},
|
|
555
|
+
Literal(ruleNode) {
|
|
556
|
+
const node = ruleNode;
|
|
557
|
+
if (typeof node.value !== "string") return;
|
|
558
|
+
const parent = node.parent;
|
|
559
|
+
if (parent && /^(Import|Export)/.test(parent.type)) return;
|
|
560
|
+
if (parent?.type === "TSLiteralType" || parent?.type === "TSExternalModuleReference") return;
|
|
561
|
+
classTokens(node, node.value);
|
|
562
|
+
},
|
|
563
|
+
TemplateElement(ruleNode) {
|
|
564
|
+
const node = ruleNode;
|
|
565
|
+
const cooked = node.value.cooked;
|
|
566
|
+
if (cooked && node.parent) classTokens(node.parent, cooked);
|
|
567
|
+
},
|
|
568
|
+
"Program:exit"() {
|
|
569
|
+
if (portalCalled) return;
|
|
570
|
+
for (const declaration of new Set(portalImports.values())) report(anchorOf(declaration), declaration, "portal");
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
};
|
|
575
|
+
|
|
124
576
|
// src/eslint/no-hand-rolled-behaviour.ts
|
|
125
577
|
var FLOATING_EVENTS = /* @__PURE__ */ new Set(["resize", "scroll", "mousedown", "pointerdown", "keydown", "keyup", "focusin", "focusout", "click"]);
|
|
126
578
|
function statement(node) {
|
|
@@ -139,11 +591,46 @@ var noHandRolledBehaviour = {
|
|
|
139
591
|
messages: {
|
|
140
592
|
portal: "A portal written by hand. Base UI's parts carry their own (Popover, Menu, Select, Tooltip, Dialog, Toast): use the part, or say why this one stays.",
|
|
141
593
|
listener: "A `{{event}}` listener on `{{target}}`. A floating part follows its anchor and closes on an outside press and on Escape by itself (Base UI Positioner and Root): use the part, or say why this one stays.",
|
|
594
|
+
scroll: "`{{what}}` scrolls with the browser's own bar, and some browsers draw none. Put what grows in a ScrollArea, with a `max-h-*` cap on its viewport (`viewportClassName`), or say why this one stays.",
|
|
142
595
|
...ESCAPE_MESSAGES
|
|
143
596
|
}
|
|
144
597
|
},
|
|
145
598
|
create(context) {
|
|
599
|
+
const reported = /* @__PURE__ */ new Set();
|
|
600
|
+
const scroll = (node, what) => {
|
|
601
|
+
let at = statement(node);
|
|
602
|
+
for (let p = node.parent; p; p = p.parent) {
|
|
603
|
+
if (p.range?.[0] === at.range[0] && p.range?.[1] === at.range[1]) {
|
|
604
|
+
if (p.parent && /^Export/.test(p.parent.type) && p.parent.loc && p.parent.range) at = { loc: p.parent.loc, range: p.parent.range };
|
|
605
|
+
break;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
const key = `${at.range[0]}:${what}`;
|
|
609
|
+
if (reported.has(key) || isEscaped(context, at)) return;
|
|
610
|
+
reported.add(key);
|
|
611
|
+
context.report({ loc: node.loc, messageId: "scroll", data: { what } });
|
|
612
|
+
};
|
|
613
|
+
const classTokens = (node, value) => {
|
|
614
|
+
for (const token of value.split(/\s+/)) if (token && SCROLL_CLASS.test(utilityOf(token))) scroll(node, token);
|
|
615
|
+
};
|
|
146
616
|
return {
|
|
617
|
+
Literal(node) {
|
|
618
|
+
const literal2 = node;
|
|
619
|
+
if (typeof literal2.value !== "string") return;
|
|
620
|
+
if (literal2.parent && /^(Import|Export)|^TSLiteralType$|^TSExternalModuleReference$/.test(literal2.parent.type)) return;
|
|
621
|
+
classTokens(node, literal2.value);
|
|
622
|
+
},
|
|
623
|
+
TemplateElement(node) {
|
|
624
|
+
const cooked = node.value.cooked;
|
|
625
|
+
if (cooked) classTokens(node, cooked);
|
|
626
|
+
},
|
|
627
|
+
Property(node) {
|
|
628
|
+
const property = node;
|
|
629
|
+
const name = property.key.type === "Identifier" ? property.key.name : typeof property.key.value === "string" ? property.key.value : void 0;
|
|
630
|
+
if (!name || !/^overflow[XY]?$/.test(name)) return;
|
|
631
|
+
const setting = property.value.type === "Literal" ? property.value.value : void 0;
|
|
632
|
+
if (setting === "auto" || setting === "scroll") scroll(node, `${name}: '${setting}'`);
|
|
633
|
+
},
|
|
147
634
|
ImportDeclaration(node) {
|
|
148
635
|
const declaration = node;
|
|
149
636
|
if (declaration.source.value !== "react-dom") return;
|
|
@@ -1559,588 +2046,136 @@ var noNativeTitle = {
|
|
|
1559
2046
|
context.report({ loc: attribute3.loc, messageId: "native" });
|
|
1560
2047
|
}
|
|
1561
2048
|
};
|
|
1562
|
-
}
|
|
1563
|
-
};
|
|
1564
|
-
|
|
1565
|
-
// src/eslint/no-raw-element.ts
|
|
1566
|
-
var RAW_ELEMENT_PARTS = {
|
|
1567
|
-
a: { use: "Link", more: " For a chip, `InlineChip`; for a whole card, `Card` with `href`." },
|
|
1568
|
-
button: { use: "Button" },
|
|
1569
|
-
textarea: { use: "Textarea" },
|
|
1570
|
-
select: { use: "Select" },
|
|
1571
|
-
dialog: { use: "DialogShell", more: " To ask yes or no, `ConfirmDialog`." },
|
|
1572
|
-
label: { use: "Field", more: " For words beside a tick box, `Checkbox` with `label`." },
|
|
1573
|
-
details: { use: "CollapsibleSection" },
|
|
1574
|
-
progress: { use: "ProgressBar" },
|
|
1575
|
-
form: { use: "Form" },
|
|
1576
|
-
meter: null,
|
|
1577
|
-
iframe: null,
|
|
1578
|
-
embed: null,
|
|
1579
|
-
object: null,
|
|
1580
|
-
audio: null,
|
|
1581
|
-
video: null,
|
|
1582
|
-
img: null
|
|
1583
|
-
};
|
|
1584
|
-
var RAW_INPUT_PARTS = {
|
|
1585
|
-
search: { use: "SearchInput" },
|
|
1586
|
-
checkbox: { use: "Checkbox" },
|
|
1587
|
-
file: { use: "FilePicker" },
|
|
1588
|
-
submit: { use: "Button" },
|
|
1589
|
-
button: { use: "Button" },
|
|
1590
|
-
reset: { use: "Button" },
|
|
1591
|
-
image: { use: "Button" },
|
|
1592
|
-
radio: null,
|
|
1593
|
-
range: null,
|
|
1594
|
-
color: null,
|
|
1595
|
-
date: null,
|
|
1596
|
-
"datetime-local": null,
|
|
1597
|
-
month: null,
|
|
1598
|
-
week: null,
|
|
1599
|
-
time: null
|
|
1600
|
-
};
|
|
1601
|
-
var TEXT_INPUT = { use: "TextInput" };
|
|
1602
|
-
var ANY_INPUT = {
|
|
1603
|
-
use: "TextInput",
|
|
1604
|
-
more: " For a search, `SearchInput`; for a tick box, `Checkbox`; to pick files, `FilePicker`."
|
|
1605
|
-
};
|
|
1606
|
-
function attribute2(element, name) {
|
|
1607
|
-
return element.attributes.find((a) => a.type === "JSXAttribute" && a.name.name === name);
|
|
1608
|
-
}
|
|
1609
|
-
function literal(attr) {
|
|
1610
|
-
const value = attr.value;
|
|
1611
|
-
if (value === null) return true;
|
|
1612
|
-
if (value.type === "Literal") return typeof value.value === "string" ? value.value : void 0;
|
|
1613
|
-
if (value.type !== "JSXExpressionContainer" || !value.expression) return void 0;
|
|
1614
|
-
const expression = value.expression;
|
|
1615
|
-
if (expression.type === "Literal" && (typeof expression.value === "string" || typeof expression.value === "boolean")) return expression.value;
|
|
1616
|
-
if (expression.type === "TemplateLiteral" && expression.expressions?.length === 0) return expression.quasis?.[0]?.value.cooked ?? void 0;
|
|
1617
|
-
return void 0;
|
|
1618
|
-
}
|
|
1619
|
-
function isOn(element, name) {
|
|
1620
|
-
const attr = attribute2(element, name);
|
|
1621
|
-
return attr !== void 0 && literal(attr) !== false;
|
|
1622
|
-
}
|
|
1623
|
-
var CLICK_HANDLERS = ["onClick", "onMouseDown", "onMouseUp", "onPointerDown", "onPointerUp", "onDoubleClick"];
|
|
1624
|
-
function onlyStops(handler) {
|
|
1625
|
-
if (!handler || handler.type !== "ArrowFunctionExpression" && handler.type !== "FunctionExpression") return false;
|
|
1626
|
-
const body = handler.body;
|
|
1627
|
-
const calls = body.type === "BlockStatement" ? body.body.map((s) => s.type === "ExpressionStatement" ? s.expression : s) : [body];
|
|
1628
|
-
return calls.length > 0 && calls.every((call) => {
|
|
1629
|
-
if (call.type !== "CallExpression") return false;
|
|
1630
|
-
const callee = call.callee;
|
|
1631
|
-
const property = callee.type === "MemberExpression" ? callee.property : void 0;
|
|
1632
|
-
return property?.type === "Identifier" && (property.name === "stopPropagation" || property.name === "preventDefault");
|
|
1633
|
-
});
|
|
1634
|
-
}
|
|
1635
|
-
function clickHandler(element) {
|
|
1636
|
-
for (const name of CLICK_HANDLERS) {
|
|
1637
|
-
const attr = attribute2(element, name);
|
|
1638
|
-
if (!attr) continue;
|
|
1639
|
-
const value = attr.value;
|
|
1640
|
-
const handler = value?.type === "JSXExpressionContainer" ? value.expression : void 0;
|
|
1641
|
-
if (!onlyStops(handler)) return name;
|
|
1642
|
-
}
|
|
1643
|
-
return void 0;
|
|
1644
|
-
}
|
|
1645
|
-
function classify(element) {
|
|
1646
|
-
if (element.name.type !== "JSXIdentifier" || !element.name.name) return null;
|
|
1647
|
-
const name = element.name.name;
|
|
1648
|
-
if (name === "input") {
|
|
1649
|
-
const attr = attribute2(element, "type");
|
|
1650
|
-
const type = attr ? literal(attr) : "text";
|
|
1651
|
-
if (typeof type !== "string") return { report: "raw", element: "<input>", part: ANY_INPUT };
|
|
1652
|
-
const key = type.toLowerCase();
|
|
1653
|
-
if (key === "hidden") return null;
|
|
1654
|
-
if (!(key in RAW_INPUT_PARTS)) return { report: "raw", element: "<input>", part: TEXT_INPUT };
|
|
1655
|
-
const part2 = RAW_INPUT_PARTS[key];
|
|
1656
|
-
const shown = `<input type="${key}">`;
|
|
1657
|
-
return part2 ? { report: "raw", element: shown, part: part2 } : { report: "noPart", element: shown };
|
|
1658
|
-
}
|
|
1659
|
-
if (!Object.hasOwn(RAW_ELEMENT_PARTS, name)) {
|
|
1660
|
-
if (!/^[a-z][a-z0-9]*$/.test(name) || name === "option" || name === "summary") return null;
|
|
1661
|
-
const handler = clickHandler(element);
|
|
1662
|
-
return handler ? { report: "clickable", element: `<${name} ${handler}>` } : null;
|
|
1663
|
-
}
|
|
1664
|
-
if ((name === "audio" || name === "video") && !isOn(element, "controls")) return null;
|
|
1665
|
-
if (name === "img" && !attribute2(element, "usemap") && !attribute2(element, "useMap")) return null;
|
|
1666
|
-
const part = RAW_ELEMENT_PARTS[name];
|
|
1667
|
-
return part ? { report: "raw", element: `<${name}>`, part } : { report: "noPart", element: `<${name}>` };
|
|
1668
|
-
}
|
|
1669
|
-
var noRawElement = {
|
|
1670
|
-
meta: {
|
|
1671
|
-
type: "problem",
|
|
1672
|
-
docs: { description: "A raw interactive element where @estiva-app/ui has a part, or where it needs one" },
|
|
1673
|
-
schema: [],
|
|
1674
|
-
messages: {
|
|
1675
|
-
raw: "Use `{{use}}` from @estiva-app/ui instead of a raw {{element}}.{{more}}",
|
|
1676
|
-
clickable: "A clickable {{element}} is a button made by hand: it takes no focus and answers no key. Use `Button` from @estiva-app/ui; for a whole card that opens something, `Card` with `href`. A handler that only stops the click (`e.stopPropagation()`) is fine.",
|
|
1677
|
-
noPart: "@estiva-app/ui has no part for a raw {{element}} yet. Do not build one here: ask Katerina, and it gets made in @estiva-app/ui.",
|
|
1678
|
-
...ESCAPE_MESSAGES
|
|
1679
|
-
}
|
|
1680
|
-
},
|
|
1681
|
-
create(context) {
|
|
1682
|
-
return {
|
|
1683
|
-
// ESLint's types know ESTree's nodes, not JSX's; the parser hands this one over.
|
|
1684
|
-
JSXOpeningElement(node) {
|
|
1685
|
-
const element = node;
|
|
1686
|
-
const found = classify(element);
|
|
1687
|
-
if (!found) return;
|
|
1688
|
-
if (isEscaped(context, element)) return;
|
|
1689
|
-
if (found.report === "clickable") context.report({ loc: element.loc, messageId: "clickable", data: { element: found.element } });
|
|
1690
|
-
else if (found.report === "noPart") context.report({ loc: element.loc, messageId: "noPart", data: { element: found.element } });
|
|
1691
|
-
else context.report({ loc: element.loc, messageId: "raw", data: { element: found.element, use: found.part.use, more: found.part.more ?? "" } });
|
|
1692
|
-
}
|
|
1693
|
-
};
|
|
1694
|
-
}
|
|
1695
|
-
};
|
|
1696
|
-
|
|
1697
|
-
// src/eslint/no-rebuilt-behaviour.ts
|
|
1698
|
-
var BASE_UI_PARTS = {
|
|
1699
|
-
"alert-dialog": { use: "DialogShell", more: " To ask yes or no, `ConfirmDialog`." },
|
|
1700
|
-
autocomplete: { use: "CommandPalette" },
|
|
1701
|
-
avatar: { use: "Avatar" },
|
|
1702
|
-
button: { use: "Button", more: " Icon only, `IconButton`." },
|
|
1703
|
-
checkbox: { use: "Checkbox" },
|
|
1704
|
-
collapsible: { use: "CollapsibleSection" },
|
|
1705
|
-
combobox: { use: "ChipInput" },
|
|
1706
|
-
dialog: { use: "DialogShell", more: " To search and act, `CommandPalette`." },
|
|
1707
|
-
field: { use: "Field" },
|
|
1708
|
-
fieldset: { use: "Form" },
|
|
1709
|
-
form: { use: "Form" },
|
|
1710
|
-
input: { use: "TextInput", more: " For a search, `SearchInput`." },
|
|
1711
|
-
menu: { use: "Menu" },
|
|
1712
|
-
popover: { use: "Popover" },
|
|
1713
|
-
"preview-card": { use: "PreviewCard" },
|
|
1714
|
-
progress: { use: "ProgressBar" },
|
|
1715
|
-
"scroll-area": { use: "ScrollArea" },
|
|
2049
|
+
}
|
|
2050
|
+
};
|
|
2051
|
+
|
|
2052
|
+
// src/eslint/no-raw-element.ts
|
|
2053
|
+
var RAW_ELEMENT_PARTS = {
|
|
2054
|
+
a: { use: "Link", more: " For a chip, `InlineChip`; for a whole card, `Card` with `href`." },
|
|
2055
|
+
button: { use: "Button" },
|
|
2056
|
+
textarea: { use: "Textarea" },
|
|
1716
2057
|
select: { use: "Select" },
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
tooltip: { use: "Tooltip", more: " Around a control, `WithTooltip`." },
|
|
1723
|
-
accordion: null,
|
|
1724
|
-
"checkbox-group": null,
|
|
1725
|
-
"context-menu": null,
|
|
1726
|
-
drawer: null,
|
|
1727
|
-
menubar: null,
|
|
2058
|
+
dialog: { use: "DialogShell", more: " To ask yes or no, `ConfirmDialog`." },
|
|
2059
|
+
label: { use: "Field", more: " For words beside a tick box, `Checkbox` with `label`." },
|
|
2060
|
+
details: { use: "CollapsibleSection" },
|
|
2061
|
+
progress: { use: "ProgressBar" },
|
|
2062
|
+
form: { use: "Form" },
|
|
1728
2063
|
meter: null,
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
switch: null,
|
|
1736
|
-
"toggle-group": null
|
|
1737
|
-
};
|
|
1738
|
-
var LIST_PART = {
|
|
1739
|
-
use: "Select",
|
|
1740
|
-
more: " To pick several, `ChipInput`; to search and act, `CommandPalette`; to tick several in a list, `Checkbox` with `row`; for the list a text editor opens as you type, `SuggestionMenu`."
|
|
2064
|
+
iframe: null,
|
|
2065
|
+
embed: null,
|
|
2066
|
+
object: null,
|
|
2067
|
+
audio: null,
|
|
2068
|
+
video: null,
|
|
2069
|
+
img: null
|
|
1741
2070
|
};
|
|
1742
|
-
var
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
checkbox: { thing: "tick box", part: { use: "Checkbox" } },
|
|
1759
|
-
separator: { thing: "divider", part: { use: "Divider" } },
|
|
1760
|
-
button: { thing: "button", part: { use: "Button", more: " Icon only, `IconButton`." } },
|
|
1761
|
-
link: { thing: "link", part: { use: "Link" } },
|
|
1762
|
-
tooltip: { thing: "tooltip", part: { use: "Tooltip", more: " Around a control, `WithTooltip`." } },
|
|
1763
|
-
alert: { thing: "message", part: MESSAGE_PART },
|
|
1764
|
-
status: { thing: "message", part: MESSAGE_PART },
|
|
1765
|
-
menubar: { thing: "menu bar", part: null },
|
|
1766
|
-
switch: { thing: "switch", part: null },
|
|
1767
|
-
radio: { thing: "radio button", part: null },
|
|
1768
|
-
radiogroup: { thing: "radio group", part: null },
|
|
1769
|
-
slider: { thing: "slider", part: null },
|
|
1770
|
-
spinbutton: { thing: "number field", part: null },
|
|
1771
|
-
meter: { thing: "meter", part: null }
|
|
2071
|
+
var RAW_INPUT_PARTS = {
|
|
2072
|
+
search: { use: "SearchInput" },
|
|
2073
|
+
checkbox: { use: "Checkbox" },
|
|
2074
|
+
file: { use: "FilePicker" },
|
|
2075
|
+
submit: { use: "Button" },
|
|
2076
|
+
button: { use: "Button" },
|
|
2077
|
+
reset: { use: "Button" },
|
|
2078
|
+
image: { use: "Button" },
|
|
2079
|
+
radio: null,
|
|
2080
|
+
range: null,
|
|
2081
|
+
color: null,
|
|
2082
|
+
date: null,
|
|
2083
|
+
"datetime-local": null,
|
|
2084
|
+
month: null,
|
|
2085
|
+
week: null,
|
|
2086
|
+
time: null
|
|
1772
2087
|
};
|
|
1773
|
-
var
|
|
1774
|
-
var
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
click: "press",
|
|
1778
|
-
touchstart: "press",
|
|
1779
|
-
keydown: "key",
|
|
1780
|
-
keyup: "key",
|
|
1781
|
-
keypress: "key",
|
|
1782
|
-
focusin: "focus",
|
|
1783
|
-
focusout: "focus",
|
|
1784
|
-
scroll: "follow",
|
|
1785
|
-
resize: "follow"
|
|
2088
|
+
var TEXT_INPUT = { use: "TextInput" };
|
|
2089
|
+
var ANY_INPUT = {
|
|
2090
|
+
use: "TextInput",
|
|
2091
|
+
more: " For a search, `SearchInput`; for a tick box, `Checkbox`; to pick files, `FilePicker`."
|
|
1786
2092
|
};
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
var uses = (parts) => [
|
|
1790
|
-
...new Set(parts.flatMap((p) => p ? [p.use, ...[...(p.more ?? "").matchAll(/`([A-Z]\w+)`/g)].map((m) => m[1])] : []))
|
|
1791
|
-
];
|
|
1792
|
-
var OWNED_BEHAVIOURS = [
|
|
1793
|
-
{
|
|
1794
|
-
id: "base-ui",
|
|
1795
|
-
behaviour: "Is built on Base UI",
|
|
1796
|
-
baseUi: Object.keys(BASE_UI_PARTS),
|
|
1797
|
-
owners: uses(Object.values(BASE_UI_PARTS)),
|
|
1798
|
-
reads: "an import from @base-ui/react (and the old @base-ui-components spelling)"
|
|
1799
|
-
},
|
|
1800
|
-
{
|
|
1801
|
-
id: "portal",
|
|
1802
|
-
behaviour: "Floats on top of the page",
|
|
1803
|
-
baseUi: ["Dialog", "AlertDialog", "Popover", "Menu", "Select", "Combobox", "Autocomplete", "Tooltip", "PreviewCard", "Toast"],
|
|
1804
|
-
owners: ["DialogShell", "ConfirmDialog", "CommandPalette", "Lightbox", "Popover", "Menu", "Select", "ChipInput", "Tooltip", "PreviewCard", "Toast"],
|
|
1805
|
-
reads: "createPortal, called, or imported and never called"
|
|
1806
|
-
},
|
|
1807
|
-
{
|
|
1808
|
-
id: "press-outside",
|
|
1809
|
-
behaviour: "Closes on a press outside",
|
|
1810
|
-
baseUi: ["Dialog", "AlertDialog", "Popover", "Menu", "Select", "Combobox", "Tooltip", "PreviewCard"],
|
|
1811
|
-
owners: ["DialogShell", "Popover", "Menu", "Select", "PreviewCard"],
|
|
1812
|
-
reads: "a mousedown, pointerdown, click or touchstart listener on window or document"
|
|
1813
|
-
},
|
|
1814
|
-
{
|
|
1815
|
-
id: "page-keys",
|
|
1816
|
-
behaviour: "Takes its keys by itself",
|
|
1817
|
-
baseUi: ["Dialog", "AlertDialog", "Popover", "Menu", "Select", "Combobox", "Tooltip", "PreviewCard", "Toast"],
|
|
1818
|
-
owners: ["DialogShell", "Lightbox", "Popover", "Menu", "Select", "Tabs", "Toolbar"],
|
|
1819
|
-
reads: "a keydown, keyup or keypress listener on window or document"
|
|
1820
|
-
},
|
|
1821
|
-
{
|
|
1822
|
-
id: "focus",
|
|
1823
|
-
behaviour: "Holds focus inside while open, and gives it back",
|
|
1824
|
-
baseUi: ["Dialog", "AlertDialog", "Popover", "Menu", "Select", "Combobox"],
|
|
1825
|
-
owners: ["DialogShell", "CommandPalette", "Lightbox"],
|
|
1826
|
-
reads: "a focusin or focusout listener on window or document; the Tab key compared by hand"
|
|
1827
|
-
},
|
|
1828
|
-
{
|
|
1829
|
-
id: "scroll-lock",
|
|
1830
|
-
behaviour: "Stops the page behind it scrolling",
|
|
1831
|
-
baseUi: ["Dialog", "AlertDialog"],
|
|
1832
|
-
owners: ["DialogShell", "Lightbox"],
|
|
1833
|
-
reads: "overflow written into the style of document.body or document.documentElement"
|
|
1834
|
-
},
|
|
1835
|
-
{
|
|
1836
|
-
id: "follow",
|
|
1837
|
-
behaviour: "Stays attached to its anchor on scroll and resize",
|
|
1838
|
-
baseUi: ["Popover", "Menu", "Select", "Combobox", "Tooltip", "PreviewCard", "Toast"],
|
|
1839
|
-
owners: ["Popover", "Menu", "Select", "Tooltip", "PreviewCard"],
|
|
1840
|
-
reads: "a scroll or resize listener on window or document"
|
|
1841
|
-
},
|
|
1842
|
-
{
|
|
1843
|
-
id: "walking",
|
|
1844
|
-
behaviour: "Moves through its items with the arrow keys",
|
|
1845
|
-
baseUi: ["Menu", "Select", "Combobox", "Autocomplete", "Tabs", "Toolbar"],
|
|
1846
|
-
owners: ["Menu", "Select", "ChipInput", "CommandPalette", "SuggestionMenu", "Tabs", "Toolbar"],
|
|
1847
|
-
reads: `a key compared by hand with ${WALKING_KEYS.join(", ")}`
|
|
1848
|
-
},
|
|
1849
|
-
{
|
|
1850
|
-
id: "role",
|
|
1851
|
-
behaviour: "Says what it is to assistive technology",
|
|
1852
|
-
baseUi: ["Dialog", "AlertDialog", "Menu", "Select", "Combobox", "Tabs", "Toolbar", "Progress", "Checkbox", "Separator", "Button"],
|
|
1853
|
-
owners: uses(Object.values(ROLE_PARTS).map((r) => r.part)),
|
|
1854
|
-
reads: `role written by hand: ${Object.keys(ROLE_PARTS).join(", ")}`
|
|
1855
|
-
},
|
|
1856
|
-
{
|
|
1857
|
-
id: "tab-stop",
|
|
1858
|
-
behaviour: "Is reachable with Tab",
|
|
1859
|
-
baseUi: ["Button", "Toggle", "Checkbox", "Tabs", "Toolbar", "ScrollArea"],
|
|
1860
|
-
owners: ["Button", "IconButton", "Link"],
|
|
1861
|
-
reads: "tabIndex that can be 0 or more, on an element that is not a control"
|
|
1862
|
-
},
|
|
1863
|
-
{
|
|
1864
|
-
id: "scroll",
|
|
1865
|
-
behaviour: "Scrolls with our scrollbar",
|
|
1866
|
-
baseUi: ["ScrollArea"],
|
|
1867
|
-
owners: ["ScrollArea"],
|
|
1868
|
-
reads: "overflow-auto or overflow-scroll (x or y, behind any variant) in a string, or overflow auto or scroll in a style"
|
|
1869
|
-
}
|
|
1870
|
-
];
|
|
1871
|
-
var PAGE_TARGETS = /* @__PURE__ */ new Set(["window", "document", "globalThis", "self", "document.body", "document.documentElement", "window.document"]);
|
|
1872
|
-
function anchorOf(node) {
|
|
1873
|
-
if (node.type === "FunctionDeclaration") {
|
|
1874
|
-
return node.parent && /^Export/.test(node.parent.type) ? node.parent : node;
|
|
1875
|
-
}
|
|
1876
|
-
let child5 = node;
|
|
1877
|
-
for (let p = node.parent; p; child5 = p, p = p.parent) {
|
|
1878
|
-
if (p.type === "JSXOpeningElement" || p.type === "Property" || p.type === "MethodDefinition" || p.type === "PropertyDefinition") return p;
|
|
1879
|
-
if (p.type === "ArrayExpression") return child5;
|
|
1880
|
-
if (p.type !== "BlockStatement" && /(Statement|Declaration)$/.test(p.type)) return p;
|
|
1881
|
-
}
|
|
1882
|
-
return node;
|
|
2093
|
+
function attribute2(element, name) {
|
|
2094
|
+
return element.attributes.find((a) => a.type === "JSXAttribute" && a.name.name === name);
|
|
1883
2095
|
}
|
|
1884
|
-
function
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
2096
|
+
function literal(attr) {
|
|
2097
|
+
const value = attr.value;
|
|
2098
|
+
if (value === null) return true;
|
|
2099
|
+
if (value.type === "Literal") return typeof value.value === "string" ? value.value : void 0;
|
|
2100
|
+
if (value.type !== "JSXExpressionContainer" || !value.expression) return void 0;
|
|
2101
|
+
const expression = value.expression;
|
|
2102
|
+
if (expression.type === "Literal" && (typeof expression.value === "string" || typeof expression.value === "boolean")) return expression.value;
|
|
2103
|
+
if (expression.type === "TemplateLiteral" && expression.expressions?.length === 0) return expression.quasis?.[0]?.value.cooked ?? void 0;
|
|
1888
2104
|
return void 0;
|
|
1889
2105
|
}
|
|
1890
|
-
function
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
const quasis = node.quasis;
|
|
1894
|
-
const expressions = node.expressions;
|
|
1895
|
-
if (node.type === "TemplateLiteral" && expressions?.length === 0) return quasis?.[0]?.value.cooked ?? void 0;
|
|
1896
|
-
return void 0;
|
|
2106
|
+
function isOn(element, name) {
|
|
2107
|
+
const attr = attribute2(element, name);
|
|
2108
|
+
return attr !== void 0 && literal(attr) !== false;
|
|
1897
2109
|
}
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
if (
|
|
1901
|
-
const
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
2110
|
+
var CLICK_HANDLERS = ["onClick", "onMouseDown", "onMouseUp", "onPointerDown", "onPointerUp", "onDoubleClick"];
|
|
2111
|
+
function onlyStops(handler) {
|
|
2112
|
+
if (!handler || handler.type !== "ArrowFunctionExpression" && handler.type !== "FunctionExpression") return false;
|
|
2113
|
+
const body = handler.body;
|
|
2114
|
+
const calls = body.type === "BlockStatement" ? body.body.map((s) => s.type === "ExpressionStatement" ? s.expression : s) : [body];
|
|
2115
|
+
return calls.length > 0 && calls.every((call) => {
|
|
2116
|
+
if (call.type !== "CallExpression") return false;
|
|
2117
|
+
const callee = call.callee;
|
|
2118
|
+
const property = callee.type === "MemberExpression" ? callee.property : void 0;
|
|
2119
|
+
return property?.type === "Identifier" && (property.name === "stopPropagation" || property.name === "preventDefault");
|
|
2120
|
+
});
|
|
1906
2121
|
}
|
|
1907
|
-
function
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
return
|
|
2122
|
+
function clickHandler(element) {
|
|
2123
|
+
for (const name of CLICK_HANDLERS) {
|
|
2124
|
+
const attr = attribute2(element, name);
|
|
2125
|
+
if (!attr) continue;
|
|
2126
|
+
const value = attr.value;
|
|
2127
|
+
const handler = value?.type === "JSXExpressionContainer" ? value.expression : void 0;
|
|
2128
|
+
if (!onlyStops(handler)) return name;
|
|
1914
2129
|
}
|
|
1915
|
-
|
|
1916
|
-
if (node.type === "LogicalExpression") return canBeTabStop(node.left) || canBeTabStop(node.right);
|
|
1917
|
-
if (node.type === "TSAsExpression" || node.type === "TSNonNullExpression") return canBeTabStop(node.expression);
|
|
1918
|
-
return false;
|
|
2130
|
+
return void 0;
|
|
1919
2131
|
}
|
|
1920
|
-
function
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
const
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
2132
|
+
function classify(element) {
|
|
2133
|
+
if (element.name.type !== "JSXIdentifier" || !element.name.name) return null;
|
|
2134
|
+
const name = element.name.name;
|
|
2135
|
+
if (name === "input") {
|
|
2136
|
+
const attr = attribute2(element, "type");
|
|
2137
|
+
const type = attr ? literal(attr) : "text";
|
|
2138
|
+
if (typeof type !== "string") return { report: "raw", element: "<input>", part: ANY_INPUT };
|
|
2139
|
+
const key = type.toLowerCase();
|
|
2140
|
+
if (key === "hidden") return null;
|
|
2141
|
+
if (!(key in RAW_INPUT_PARTS)) return { report: "raw", element: "<input>", part: TEXT_INPUT };
|
|
2142
|
+
const part2 = RAW_INPUT_PARTS[key];
|
|
2143
|
+
const shown = `<input type="${key}">`;
|
|
2144
|
+
return part2 ? { report: "raw", element: shown, part: part2 } : { report: "noPart", element: shown };
|
|
1928
2145
|
}
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
if (!node) return false;
|
|
1939
|
-
if (node.type === "Identifier") return node.name === "key" || node.name === "code";
|
|
1940
|
-
if (node.type !== "MemberExpression" || node.computed) return false;
|
|
1941
|
-
const property = node.property;
|
|
1942
|
-
return property.type === "Identifier" && (property.name === "key" || property.name === "code");
|
|
1943
|
-
}
|
|
1944
|
-
function pageTarget(node, text) {
|
|
1945
|
-
return (node.type === "Identifier" || node.type === "MemberExpression") && PAGE_TARGETS.has(text);
|
|
2146
|
+
if (!Object.hasOwn(RAW_ELEMENT_PARTS, name)) {
|
|
2147
|
+
if (!/^[a-z][a-z0-9]*$/.test(name) || name === "option" || name === "summary") return null;
|
|
2148
|
+
const handler = clickHandler(element);
|
|
2149
|
+
return handler ? { report: "clickable", element: `<${name} ${handler}>` } : null;
|
|
2150
|
+
}
|
|
2151
|
+
if ((name === "audio" || name === "video") && !isOn(element, "controls")) return null;
|
|
2152
|
+
if (name === "img" && !attribute2(element, "usemap") && !attribute2(element, "useMap")) return null;
|
|
2153
|
+
const part = RAW_ELEMENT_PARTS[name];
|
|
2154
|
+
return part ? { report: "raw", element: `<${name}>`, part } : { report: "noPart", element: `<${name}>` };
|
|
1946
2155
|
}
|
|
1947
|
-
var
|
|
2156
|
+
var noRawElement = {
|
|
1948
2157
|
meta: {
|
|
1949
2158
|
type: "problem",
|
|
1950
|
-
docs: { description: "
|
|
2159
|
+
docs: { description: "A raw interactive element where @estiva-app/ui has a part, or where it needs one" },
|
|
1951
2160
|
schema: [],
|
|
1952
2161
|
messages: {
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
press: "A `{{event}}` listener on `{{target}}`: closing on a press outside, by hand. `Popover`, `Menu`, `Select`, `DialogShell` and `PreviewCard` from @estiva-app/ui close themselves.",
|
|
1957
|
-
key: "A `{{event}}` listener on `{{target}}`: keys taken for the whole page, by hand. `DialogShell`, `Popover`, `Menu` and `Select` from @estiva-app/ui close on Escape themselves; `Menu`, `Select`, `Tabs` and `Toolbar` move with the arrow keys.",
|
|
1958
|
-
focus: "A `{{event}}` listener on `{{target}}`: focus held by hand. `DialogShell` and `CommandPalette` from @estiva-app/ui keep focus inside and give it back.",
|
|
1959
|
-
follow: "A `{{event}}` listener on `{{target}}`: following an anchor by hand. `Popover`, `Menu`, `Select`, `Tooltip` and `PreviewCard` from @estiva-app/ui stay attached to theirs.",
|
|
1960
|
-
scrollLock: "The page's scroll locked by hand. `DialogShell` from @estiva-app/ui stops the page scrolling while it is open, and gives it back.",
|
|
1961
|
-
walking: "Arrow keys handled by hand (`{{key}}`). `Menu`, `Select`, `ChipInput`, `CommandPalette`, `Tabs` and `Toolbar` from @estiva-app/ui move through their items themselves.",
|
|
1962
|
-
tabKey: "The Tab key handled by hand. `DialogShell` and `CommandPalette` from @estiva-app/ui keep focus inside themselves.",
|
|
1963
|
-
role: 'A hand-written `role="{{role}}"` is a hand-made {{thing}}. Use `{{use}}` from @estiva-app/ui.{{more}}',
|
|
1964
|
-
roleNoPart: 'A hand-written `role="{{role}}"` is a hand-made {{thing}}, and @estiva-app/ui has no part for one yet. Do not build one here: ask Katerina, and it gets made in @estiva-app/ui.',
|
|
1965
|
-
tabStop: "`tabIndex={{value}}` makes a `<{{element}}>` a Tab stop by hand. Use `Button`, `IconButton` or `Link` from @estiva-app/ui, which are reachable already.",
|
|
1966
|
-
scrollClass: "`{{token}}` scrolls with the browser's scrollbar. Use `ScrollArea` from @estiva-app/ui, which draws ours.",
|
|
1967
|
-
scrollStyle: "`{{style}}` scrolls with the browser's scrollbar. Use `ScrollArea` from @estiva-app/ui, which draws ours.",
|
|
2162
|
+
raw: "Use `{{use}}` from @estiva-app/ui instead of a raw {{element}}.{{more}}",
|
|
2163
|
+
clickable: "A clickable {{element}} is a button made by hand: it takes no focus and answers no key. Use `Button` from @estiva-app/ui; for a whole card that opens something, `Card` with `href`. A handler that only stops the click (`e.stopPropagation()`) is fine.",
|
|
2164
|
+
noPart: "@estiva-app/ui has no part for a raw {{element}} yet. Do not build one here: ask Katerina, and it gets made in @estiva-app/ui.",
|
|
1968
2165
|
...ESCAPE_MESSAGES
|
|
1969
2166
|
}
|
|
1970
2167
|
},
|
|
1971
2168
|
create(context) {
|
|
1972
|
-
const { sourceCode } = context;
|
|
1973
|
-
const text = (node) => sourceCode.getText(node);
|
|
1974
|
-
const escapes = /* @__PURE__ */ new Map();
|
|
1975
|
-
const escaped = (anchor) => {
|
|
1976
|
-
if (!escapes.has(anchor)) escapes.set(anchor, isEscaped(context, anchor));
|
|
1977
|
-
return escapes.get(anchor) === true;
|
|
1978
|
-
};
|
|
1979
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1980
|
-
const report = (anchor, at, messageId, data = {}, once = `${at.range[0]}`) => {
|
|
1981
|
-
const key = `${anchor.range[0]}|${messageId}|${once}`;
|
|
1982
|
-
if (seen.has(key)) return;
|
|
1983
|
-
seen.add(key);
|
|
1984
|
-
if (escaped(anchor)) return;
|
|
1985
|
-
context.report({ loc: at.loc, messageId, data });
|
|
1986
|
-
};
|
|
1987
|
-
const importSource = (node, source) => {
|
|
1988
|
-
const value = stringOf(source);
|
|
1989
|
-
if (value === void 0) return;
|
|
1990
|
-
const module = baseUiModule(value);
|
|
1991
|
-
if (module === void 0) return;
|
|
1992
|
-
const part = Object.hasOwn(BASE_UI_PARTS, module) ? BASE_UI_PARTS[module] : null;
|
|
1993
|
-
const anchor = anchorOf(node);
|
|
1994
|
-
if (part) report(anchor, node, "baseUi", { module: value, use: part.use, more: part.more ?? "" });
|
|
1995
|
-
else report(anchor, node, "baseUiNoPart", { module: value });
|
|
1996
|
-
};
|
|
1997
|
-
const keyCompared = (node, key) => {
|
|
1998
|
-
if (key === void 0) return;
|
|
1999
|
-
const fn = enclosingFunction(node);
|
|
2000
|
-
const anchor = anchorOf(fn ?? node);
|
|
2001
|
-
if (WALKING_KEYS.includes(key)) report(anchor, node, "walking", { key }, `walking@${fn?.range[0] ?? node.range[0]}`);
|
|
2002
|
-
else if (key === "Tab") report(anchor, node, "tabKey", {}, `tab@${fn?.range[0] ?? node.range[0]}`);
|
|
2003
|
-
};
|
|
2004
|
-
const classTokens = (node, value) => {
|
|
2005
|
-
for (const token of value.split(/\s+/)) {
|
|
2006
|
-
if (token && SCROLL_CLASS.test(utilityOf(token))) report(anchorOf(node), node, "scrollClass", { token }, `class@${token}`);
|
|
2007
|
-
}
|
|
2008
|
-
};
|
|
2009
|
-
const portalImports = /* @__PURE__ */ new Map();
|
|
2010
|
-
let portalCalled = false;
|
|
2011
2169
|
return {
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
}
|
|
2020
|
-
|
|
2021
|
-
ExportNamedDeclaration(ruleNode) {
|
|
2022
|
-
const node = ruleNode;
|
|
2023
|
-
if (node.source) importSource(node, node.source);
|
|
2024
|
-
},
|
|
2025
|
-
ExportAllDeclaration(ruleNode) {
|
|
2026
|
-
const node = ruleNode;
|
|
2027
|
-
importSource(node, node.source);
|
|
2028
|
-
},
|
|
2029
|
-
ImportExpression(ruleNode) {
|
|
2030
|
-
const node = ruleNode;
|
|
2031
|
-
importSource(node, node.source);
|
|
2032
|
-
},
|
|
2033
|
-
CallExpression(ruleNode) {
|
|
2034
|
-
const node = ruleNode;
|
|
2035
|
-
const callee = node.callee;
|
|
2036
|
-
const args = node.arguments;
|
|
2037
|
-
if (callee.type === "Identifier" && callee.name === "require") importSource(node, args[0]);
|
|
2038
|
-
if (callee.type === "Identifier" && portalImports.has(callee.name)) {
|
|
2039
|
-
portalCalled = true;
|
|
2040
|
-
report(anchorOf(node), node, "portal");
|
|
2041
|
-
}
|
|
2042
|
-
if (callee.type !== "MemberExpression") return;
|
|
2043
|
-
const object = callee.object;
|
|
2044
|
-
const property = callee.property;
|
|
2045
|
-
if (property.type !== "Identifier") return;
|
|
2046
|
-
if (property.name === "createPortal") {
|
|
2047
|
-
report(anchorOf(node), node, "portal");
|
|
2048
|
-
return;
|
|
2049
|
-
}
|
|
2050
|
-
if (property.name === "addEventListener") {
|
|
2051
|
-
const target = text(object);
|
|
2052
|
-
if (!pageTarget(object, target)) return;
|
|
2053
|
-
const event = stringOf(args[0]);
|
|
2054
|
-
const group = event === void 0 ? void 0 : PAGE_EVENTS[event];
|
|
2055
|
-
if (!event || !group) return;
|
|
2056
|
-
report(anchorOf(node), node, group, { event, target });
|
|
2057
|
-
return;
|
|
2058
|
-
}
|
|
2059
|
-
if (property.name === "includes" && object.type === "ArrayExpression" && isKeySubject(args[0])) {
|
|
2060
|
-
for (const element of object.elements) keyCompared(node, stringOf(element));
|
|
2061
|
-
}
|
|
2062
|
-
},
|
|
2063
|
-
AssignmentExpression(ruleNode) {
|
|
2064
|
-
const node = ruleNode;
|
|
2065
|
-
const left = node.left;
|
|
2066
|
-
if (left.type !== "MemberExpression") return;
|
|
2067
|
-
const property = left.property;
|
|
2068
|
-
const object = left.object;
|
|
2069
|
-
const handler = property.type === "Identifier" ? /^on([a-z]+)$/.exec(property.name) : null;
|
|
2070
|
-
if (handler && pageTarget(object, text(object)) && PAGE_EVENTS[handler[1]]) {
|
|
2071
|
-
report(anchorOf(node), node, PAGE_EVENTS[handler[1]], { event: handler[1], target: text(object) });
|
|
2072
|
-
return;
|
|
2073
|
-
}
|
|
2074
|
-
if (/^document\.(?:body|documentElement)\.style\.overflow[XY]?$/.test(text(left))) report(anchorOf(node), node, "scrollLock");
|
|
2075
|
-
},
|
|
2076
|
-
BinaryExpression(ruleNode) {
|
|
2077
|
-
const node = ruleNode;
|
|
2078
|
-
if (!["===", "==", "!==", "!="].includes(node.operator)) return;
|
|
2079
|
-
const left = node.left;
|
|
2080
|
-
const right = node.right;
|
|
2081
|
-
if (isKeySubject(left)) keyCompared(node, stringOf(right));
|
|
2082
|
-
else if (isKeySubject(right)) keyCompared(node, stringOf(left));
|
|
2083
|
-
},
|
|
2084
|
-
SwitchCase(ruleNode) {
|
|
2085
|
-
const node = ruleNode;
|
|
2086
|
-
const statement2 = node.parent;
|
|
2087
|
-
if (node.test && isKeySubject(statement2.discriminant)) keyCompared(node, stringOf(node.test));
|
|
2088
|
-
},
|
|
2089
|
-
JSXAttribute(ruleNode) {
|
|
2090
|
-
const node = ruleNode;
|
|
2091
|
-
const nameNode = node.name;
|
|
2092
|
-
if (nameNode.type !== "JSXIdentifier") return;
|
|
2093
|
-
const name = nameNode.name;
|
|
2094
|
-
const element = node.parent;
|
|
2095
|
-
const value = node.value;
|
|
2096
|
-
if (name === "role") {
|
|
2097
|
-
for (const role of stringsOf(value).flatMap((v) => v.trim().split(/\s+/))) {
|
|
2098
|
-
if (!Object.hasOwn(ROLE_PARTS, role)) continue;
|
|
2099
|
-
const { thing, part } = ROLE_PARTS[role];
|
|
2100
|
-
if (part) report(element, node, "role", { role, thing, use: part.use, more: part.more ?? "" });
|
|
2101
|
-
else report(element, node, "roleNoPart", { role, thing });
|
|
2102
|
-
return;
|
|
2103
|
-
}
|
|
2104
|
-
return;
|
|
2105
|
-
}
|
|
2106
|
-
if (name === "tabIndex" || name === "tabindex") {
|
|
2107
|
-
const tag = element.name;
|
|
2108
|
-
if (tag.type !== "JSXIdentifier" || !/^[a-z]/.test(tag.name) || INTERACTIVE_ELEMENTS.has(tag.name)) return;
|
|
2109
|
-
const attributes = element.attributes;
|
|
2110
|
-
const editable = attributes.some((a) => a.type === "JSXAttribute" && /^contenteditable$/i.test(a.name.name ?? ""));
|
|
2111
|
-
if (editable || !canBeTabStop(value)) return;
|
|
2112
|
-
report(element, node, "tabStop", { value: value ? text(value).replace(/^\{|\}$/g, "") : "", element: tag.name });
|
|
2113
|
-
return;
|
|
2114
|
-
}
|
|
2115
|
-
if (name === "style" && value?.type === "JSXExpressionContainer") {
|
|
2116
|
-
const object = value.expression;
|
|
2117
|
-
if (object.type !== "ObjectExpression") return;
|
|
2118
|
-
for (const property of object.properties) {
|
|
2119
|
-
if (property.type !== "Property") continue;
|
|
2120
|
-
const key = property.key;
|
|
2121
|
-
const keyName = key.type === "Identifier" ? key.name : stringOf(key);
|
|
2122
|
-
if (!keyName || !/^overflow[XY]?$/.test(keyName)) continue;
|
|
2123
|
-
const setting = stringOf(property.value);
|
|
2124
|
-
if (setting === "auto" || setting === "scroll") report(element, property, "scrollStyle", { style: `${keyName}: '${setting}'` }, `style@${keyName}`);
|
|
2125
|
-
}
|
|
2126
|
-
}
|
|
2127
|
-
},
|
|
2128
|
-
Literal(ruleNode) {
|
|
2129
|
-
const node = ruleNode;
|
|
2130
|
-
if (typeof node.value !== "string") return;
|
|
2131
|
-
const parent = node.parent;
|
|
2132
|
-
if (parent && /^(Import|Export)/.test(parent.type)) return;
|
|
2133
|
-
if (parent?.type === "TSLiteralType" || parent?.type === "TSExternalModuleReference") return;
|
|
2134
|
-
classTokens(node, node.value);
|
|
2135
|
-
},
|
|
2136
|
-
TemplateElement(ruleNode) {
|
|
2137
|
-
const node = ruleNode;
|
|
2138
|
-
const cooked = node.value.cooked;
|
|
2139
|
-
if (cooked && node.parent) classTokens(node.parent, cooked);
|
|
2140
|
-
},
|
|
2141
|
-
"Program:exit"() {
|
|
2142
|
-
if (portalCalled) return;
|
|
2143
|
-
for (const declaration of new Set(portalImports.values())) report(anchorOf(declaration), declaration, "portal");
|
|
2170
|
+
// ESLint's types know ESTree's nodes, not JSX's; the parser hands this one over.
|
|
2171
|
+
JSXOpeningElement(node) {
|
|
2172
|
+
const element = node;
|
|
2173
|
+
const found = classify(element);
|
|
2174
|
+
if (!found) return;
|
|
2175
|
+
if (isEscaped(context, element)) return;
|
|
2176
|
+
if (found.report === "clickable") context.report({ loc: element.loc, messageId: "clickable", data: { element: found.element } });
|
|
2177
|
+
else if (found.report === "noPart") context.report({ loc: element.loc, messageId: "noPart", data: { element: found.element } });
|
|
2178
|
+
else context.report({ loc: element.loc, messageId: "raw", data: { element: found.element, use: found.part.use, more: found.part.more ?? "" } });
|
|
2144
2179
|
}
|
|
2145
2180
|
};
|
|
2146
2181
|
}
|