@estiva-app/ui 0.90.1 → 0.91.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.
Files changed (235) hide show
  1. package/dist/AttachedCard.d.ts +30 -0
  2. package/dist/AttachedCard.d.ts.map +1 -0
  3. package/dist/AttachmentCard.d.ts +14 -0
  4. package/dist/AttachmentCard.d.ts.map +1 -1
  5. package/dist/AvatarGroup.d.ts +7 -1
  6. package/dist/AvatarGroup.d.ts.map +1 -1
  7. package/dist/CommentBox.d.ts +1 -1
  8. package/dist/CommentBox.d.ts.map +1 -1
  9. package/dist/InlineChip.d.ts +22 -13
  10. package/dist/InlineChip.d.ts.map +1 -1
  11. package/dist/InlineText.d.ts +5 -2
  12. package/dist/InlineText.d.ts.map +1 -1
  13. package/dist/Link.d.ts +3 -2
  14. package/dist/Link.d.ts.map +1 -1
  15. package/dist/LinkCard.d.ts +3 -3
  16. package/dist/LinkCard.d.ts.map +1 -1
  17. package/dist/LinkChip.d.ts.map +1 -1
  18. package/dist/LinkParts.d.ts +17 -3
  19. package/dist/LinkParts.d.ts.map +1 -1
  20. package/dist/LinkPreview.d.ts.map +1 -1
  21. package/dist/LinkRow.d.ts +10 -5
  22. package/dist/LinkRow.d.ts.map +1 -1
  23. package/dist/PartCard.d.ts +7 -3
  24. package/dist/PartCard.d.ts.map +1 -1
  25. package/dist/Popover.d.ts +8 -1
  26. package/dist/Popover.d.ts.map +1 -1
  27. package/dist/ReactionRow.d.ts.map +1 -1
  28. package/dist/RichText.d.ts.map +1 -1
  29. package/dist/SuggestionMenu.d.ts +6 -2
  30. package/dist/SuggestionMenu.d.ts.map +1 -1
  31. package/dist/editor.js +19 -12
  32. package/dist/editor.js.map +3 -3
  33. package/dist/eslint/has-a-page-and-a-story.d.ts.map +1 -1
  34. package/dist/eslint/index.js +1093 -1076
  35. package/dist/eslint/index.js.map +4 -4
  36. package/dist/eslint/no-restyled-part.d.ts +9 -4
  37. package/dist/eslint/no-restyled-part.d.ts.map +1 -1
  38. package/dist/gates/{chunk-BS5JASHV.js → chunk-P2P6AHRY.js} +2 -2
  39. package/dist/gates/{chunk-BS5JASHV.js.map → chunk-P2P6AHRY.js.map} +2 -2
  40. package/dist/gates/cli.js +1 -1
  41. package/dist/gates/gate-config.d.ts +4 -1
  42. package/dist/gates/gate-config.d.ts.map +1 -1
  43. package/dist/gates/hook.d.ts.map +1 -1
  44. package/dist/gates/index.js +2 -2
  45. package/dist/gates/index.js.map +2 -2
  46. package/dist/index.d.ts +2 -2
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +283 -192
  49. package/dist/index.js.map +4 -4
  50. package/dist/linked.d.ts +7 -9
  51. package/dist/linked.d.ts.map +1 -1
  52. package/dist/linked.examples.d.ts.map +1 -1
  53. package/dist/linkedFrom.d.ts.map +1 -1
  54. package/dist/links.d.ts +2 -2
  55. package/dist/links.d.ts.map +1 -1
  56. package/dist/looks.d.ts +24 -0
  57. package/dist/looks.d.ts.map +1 -1
  58. package/dist/registry/{app-X2GI4WTU.js → app-IGBRDD4L.js} +3 -3
  59. package/dist/registry/{build-P6X3PTZP.js → build-MWN4UI23.js} +2 -2
  60. package/dist/registry/{chunk-P55P2QFD.js → chunk-4TWYUIOB.js} +1 -1
  61. package/dist/registry/chunk-4TWYUIOB.js.map +7 -0
  62. package/dist/registry/{chunk-V67F474L.js → chunk-NSHK76XT.js} +2 -2
  63. package/dist/registry/{chunk-4QWD3EBY.js → chunk-THI3SLW5.js} +1 -1
  64. package/dist/registry/{chunk-4QWD3EBY.js.map → chunk-THI3SLW5.js.map} +1 -1
  65. package/dist/registry/cli.js +3 -3
  66. package/dist/registry/find.d.ts +1 -1
  67. package/dist/registry/find.d.ts.map +1 -1
  68. package/dist/registry/index.js +3 -3
  69. package/package.json +1 -1
  70. package/registry.json +511 -457
  71. package/src/AppProvider.stories.tsx +1 -1
  72. package/src/AppShell.stories.tsx +1 -1
  73. package/src/AttachedCard.mdx +55 -0
  74. package/src/{CardUnder.stories.tsx → AttachedCard.stories.tsx} +10 -19
  75. package/src/{CardUnder.test.tsx → AttachedCard.test.tsx} +8 -8
  76. package/src/AttachedCard.tsx +43 -0
  77. package/src/AttachmentCard.stories.tsx +1 -1
  78. package/src/AttachmentCard.tsx +36 -14
  79. package/src/Avatar.stories.tsx +1 -1
  80. package/src/AvatarGroup.stories.tsx +1 -1
  81. package/src/AvatarGroup.tsx +8 -2
  82. package/src/Banner.stories.tsx +1 -1
  83. package/src/BlockHandle.stories.tsx +1 -1
  84. package/src/BlockNodes.stories.tsx +1 -1
  85. package/src/Breadcrumb.stories.tsx +1 -1
  86. package/src/Button.stories.tsx +1 -1
  87. package/src/Card.stories.tsx +1 -1
  88. package/src/Checkbox.stories.tsx +1 -1
  89. package/src/Chip.stories.tsx +1 -1
  90. package/src/ChipInput.stories.tsx +1 -1
  91. package/src/CodeBlockColours.stories.tsx +1 -1
  92. package/src/CollapsibleSection.stories.tsx +1 -1
  93. package/src/CommandPalette.stories.tsx +1 -1
  94. package/src/CommentBox.mdx +3 -3
  95. package/src/CommentBox.stories.tsx +39 -7
  96. package/src/CommentBox.tsx +27 -17
  97. package/src/CommentHighlights.stories.tsx +1 -1
  98. package/src/ComposerTriggers.stories.tsx +1 -1
  99. package/src/ConfirmDialog.stories.tsx +1 -1
  100. package/src/ContainerHeader.stories.tsx +1 -1
  101. package/src/DialogShell.stories.tsx +1 -1
  102. package/src/Divider.stories.tsx +1 -1
  103. package/src/DocumentEditor.stories.tsx +1 -1
  104. package/src/EditableText.stories.tsx +1 -1
  105. package/src/EditorBlockHandle.stories.tsx +1 -1
  106. package/src/EditorTableControls.stories.tsx +1 -1
  107. package/src/EmptyState.stories.tsx +1 -1
  108. package/src/EntryShell.mdx +1 -1
  109. package/src/EntryShell.stories.tsx +1 -1
  110. package/src/ErrorBoundary.stories.tsx +1 -1
  111. package/src/Field.stories.tsx +1 -1
  112. package/src/FieldLine.stories.tsx +1 -1
  113. package/src/FilePicker.stories.tsx +1 -1
  114. package/src/Form.stories.tsx +1 -1
  115. package/src/IconButton.stories.tsx +1 -1
  116. package/src/IdentityMenu.stories.tsx +1 -1
  117. package/src/InlineChip.mdx +4 -2
  118. package/src/InlineChip.stories.tsx +1 -1
  119. package/src/InlineChip.test.tsx +3 -2
  120. package/src/InlineChip.tsx +24 -14
  121. package/src/InlineText.mdx +1 -0
  122. package/src/InlineText.stories.tsx +6 -3
  123. package/src/InlineText.tsx +7 -2
  124. package/src/Kbd.stories.tsx +1 -1
  125. package/src/KindIcon.stories.tsx +1 -1
  126. package/src/Lightbox.stories.tsx +1 -1
  127. package/src/Link.mdx +3 -2
  128. package/src/Link.stories.tsx +1 -1
  129. package/src/Link.test.tsx +5 -3
  130. package/src/Link.tsx +5 -3
  131. package/src/LinkCard.mdx +5 -4
  132. package/src/LinkCard.stories.tsx +1 -1
  133. package/src/LinkCard.test.tsx +1 -1
  134. package/src/LinkCard.tsx +80 -57
  135. package/src/LinkChip.mdx +3 -3
  136. package/src/LinkChip.stories.tsx +1 -1
  137. package/src/LinkChip.test.tsx +1 -1
  138. package/src/LinkChip.tsx +16 -3
  139. package/src/LinkChips.stories.tsx +1 -1
  140. package/src/LinkParts.stories.tsx +1 -1
  141. package/src/LinkParts.tsx +40 -8
  142. package/src/LinkPlaces.stories.tsx +1 -1
  143. package/src/LinkPreview.mdx +1 -1
  144. package/src/LinkPreview.stories.tsx +1 -1
  145. package/src/LinkPreview.tsx +3 -1
  146. package/src/LinkRow.mdx +8 -6
  147. package/src/LinkRow.stories.tsx +3 -3
  148. package/src/LinkRow.test.tsx +3 -3
  149. package/src/LinkRow.tsx +71 -40
  150. package/src/ListColumn.stories.tsx +1 -1
  151. package/src/MembersDialog.stories.tsx +1 -1
  152. package/src/MembersPill.stories.tsx +1 -1
  153. package/src/Menu.stories.tsx +1 -1
  154. package/src/MenuItem.stories.tsx +1 -1
  155. package/src/NavItem.stories.tsx +1 -1
  156. package/src/NavTree.stories.tsx +1 -1
  157. package/src/Panel.stories.tsx +1 -1
  158. package/src/PartCard.mdx +4 -4
  159. package/src/PartCard.stories.tsx +11 -8
  160. package/src/PartCard.test.tsx +5 -3
  161. package/src/PartCard.tsx +33 -24
  162. package/src/PastedImages.stories.tsx +1 -1
  163. package/src/PastedMarkdown.stories.tsx +1 -1
  164. package/src/Person.stories.tsx +1 -1
  165. package/src/PersonTrigger.stories.tsx +1 -1
  166. package/src/Popover.stories.tsx +1 -1
  167. package/src/Popover.tsx +6 -2
  168. package/src/PreviewCard.stories.tsx +1 -1
  169. package/src/ProgressBar.stories.tsx +1 -1
  170. package/src/Property.stories.tsx +1 -1
  171. package/src/Rail.stories.tsx +1 -1
  172. package/src/RailItem.stories.tsx +1 -1
  173. package/src/Reaction.stories.tsx +1 -1
  174. package/src/ReactionPicker.stories.tsx +1 -1
  175. package/src/ReactionRow.stories.tsx +1 -1
  176. package/src/ReactionRow.tsx +3 -1
  177. package/src/ReferenceCards.mdx +3 -0
  178. package/src/ReferenceCards.stories.tsx +3 -1
  179. package/src/ReferenceMenu.mdx +1 -1
  180. package/src/ReferenceMenu.stories.tsx +1 -1
  181. package/src/RichText.stories.tsx +1 -1
  182. package/src/RichText.tsx +6 -2
  183. package/src/ScrollArea.stories.tsx +1 -1
  184. package/src/SearchInput.stories.tsx +1 -1
  185. package/src/SectionHeader.stories.tsx +1 -1
  186. package/src/SectionLabel.stories.tsx +1 -1
  187. package/src/Select.stories.tsx +1 -1
  188. package/src/SelectionToolbar.stories.tsx +1 -1
  189. package/src/ShowMore.stories.tsx +1 -1
  190. package/src/Sidebar.stories.tsx +1 -1
  191. package/src/Skeleton.stories.tsx +1 -1
  192. package/src/SuggestionMenu.mdx +4 -1
  193. package/src/SuggestionMenu.stories.tsx +14 -8
  194. package/src/SuggestionMenu.tsx +20 -3
  195. package/src/Tabs.stories.tsx +1 -1
  196. package/src/TextInput.stories.tsx +1 -1
  197. package/src/Textarea.stories.tsx +1 -1
  198. package/src/Toast.stories.tsx +1 -1
  199. package/src/Toolbar.stories.tsx +1 -1
  200. package/src/Tooltip.stories.tsx +1 -1
  201. package/src/Tooltip.test.tsx +5 -4
  202. package/src/Tooltip.tsx +1 -1
  203. package/src/TopBar.stories.tsx +1 -1
  204. package/src/UnreadDot.stories.tsx +1 -1
  205. package/src/eslint/has-a-page-and-a-story.test.ts +5 -0
  206. package/src/eslint/has-a-page-and-a-story.ts +11 -2
  207. package/src/eslint/no-restyled-part.test.ts +32 -8
  208. package/src/eslint/no-restyled-part.ts +50 -23
  209. package/src/gates/gate-config.ts +5 -2
  210. package/src/gates/gates.test.ts +20 -2
  211. package/src/gates/hook.ts +4 -3
  212. package/src/index.ts +2 -1
  213. package/src/linked.examples.ts +2 -3
  214. package/src/linked.ts +11 -1
  215. package/src/linkedFrom.ts +1 -0
  216. package/src/links.ts +3 -2
  217. package/src/looks.ts +29 -0
  218. package/src/registry/build.ts +1 -1
  219. package/src/registry/contract.test.ts +1 -1
  220. package/src/registry/find.ts +1 -1
  221. package/src/registry/registry.test.ts +12 -12
  222. package/src/suggestionPopup.tsx +1 -1
  223. package/stories/Choosing.mdx +2 -2
  224. package/stories/DesignTokens.mdx +1 -1
  225. package/stories/GettingStarted.mdx +2 -2
  226. package/stories/Introduction.mdx +23 -4
  227. package/stories/TokensPage.tsx +12 -7
  228. package/dist/CardUnder.d.ts +0 -31
  229. package/dist/CardUnder.d.ts.map +0 -1
  230. package/dist/registry/chunk-P55P2QFD.js.map +0 -7
  231. package/src/CardUnder.mdx +0 -54
  232. package/src/CardUnder.tsx +0 -49
  233. /package/dist/registry/{app-X2GI4WTU.js.map → app-IGBRDD4L.js.map} +0 -0
  234. /package/dist/registry/{build-P6X3PTZP.js.map → build-MWN4UI23.js.map} +0 -0
  235. /package/dist/registry/{chunk-V67F474L.js.map → chunk-NSHK76XT.js.map} +0 -0
@@ -2,7 +2,8 @@
2
2
  import { createRequire } from "node:module";
3
3
 
4
4
  // src/eslint/has-a-page-and-a-story.ts
5
- import { existsSync } from "node:fs";
5
+ import { existsSync as existsSync2 } from "node:fs";
6
+ import { relative, sep } from "node:path";
6
7
 
7
8
  // src/eslint/escape.ts
8
9
  var ESCAPE_MARKER = "@estiva-escape";
@@ -62,1179 +63,1195 @@ function isEscaped(context, node) {
62
63
  return true;
63
64
  }
64
65
 
65
- // src/eslint/has-a-page-and-a-story.ts
66
- function componentFile(filename) {
67
- return filename.endsWith(".tsx") && !/\.(stories|test)\.tsx$/.test(filename);
66
+ // src/eslint/no-restyled-part.ts
67
+ import { existsSync, readFileSync, statSync } from "node:fs";
68
+ import { dirname, join, resolve } from "node:path";
69
+ var PLACEMENT = [
70
+ { what: "space around", pattern: /^m[xytrblse]?-/ },
71
+ { what: "space inside", pattern: /^p[xytrblse]?-/ },
72
+ { what: "width and height", pattern: /^(?:w|h|size|min-w|min-h|max-w|max-h)-/ },
73
+ { what: "shown, and how it lays out", pattern: /^(?:hidden|block|inline|inline-block|inline-flex|inline-grid|flex|grid|contents|flow-root)$/ },
74
+ { what: "its place in a row or a grid", pattern: /^(?:grow|shrink)$|^(?:flex|basis|grow|shrink|order|gap|gap-x|gap-y|space-x|space-y|col|row|grid-cols|grid-rows|grid-flow|auto-cols|auto-rows)-/ },
75
+ { what: "alignment", pattern: /^(?:self|justify|justify-items|justify-self|items|place-content|place-items|place-self)-|^content-(?!\[)/ },
76
+ { what: "position", pattern: /^(?:static|relative|absolute|fixed|sticky)$|^(?:inset|inset-x|inset-y|top|right|bottom|left|start|end|z)-/ },
77
+ // Draws nothing: it names the part, so what is inside can answer its hover (`group-hover:`).
78
+ { what: "a name for hover", pattern: /^(?:group|peer)(?:\/[\w-]+)?$/ }
79
+ ];
80
+ var PLACEMENT_STYLE = /^(?:margin|padding|inset|scrollMargin)(?:Top|Right|Bottom|Left|Block|Inline|BlockStart|BlockEnd|InlineStart|InlineEnd)?$|^(?:width|height|minWidth|minHeight|maxWidth|maxHeight|inlineSize|blockSize|minInlineSize|minBlockSize|maxInlineSize|maxBlockSize)$|^(?:display|flex|flexGrow|flexShrink|flexBasis|order|gap|rowGap|columnGap|alignSelf|justifySelf|placeSelf|gridArea|gridColumn|gridColumnStart|gridColumnEnd|gridRow|gridRowStart|gridRowEnd)$|^(?:position|top|right|bottom|left|zIndex|transform|translate)$/;
81
+ var REACHING_VARIANT = /^\[|^(?:before|after|placeholder|file|marker|selection|first-letter|first-line|backdrop|\*|\*\*)$/;
82
+ function splitClass(token) {
83
+ const variants = [];
84
+ let current = "";
85
+ let depth = 0;
86
+ for (const character of token) {
87
+ if (character === "[") depth += 1;
88
+ if (character === "]") depth -= 1;
89
+ if (character === ":" && depth === 0) {
90
+ variants.push(current);
91
+ current = "";
92
+ } else current += character;
93
+ }
94
+ return { variants, utility: current.replace(/^!/, "").replace(/!$/, "").replace(/^-/, "") };
68
95
  }
69
- function sibling(filename, extension) {
70
- return filename.replace(/\.tsx$/, extension);
96
+ function isPlacement(token) {
97
+ const { variants, utility } = splitClass(token);
98
+ if (variants.some((variant) => REACHING_VARIANT.test(variant))) return false;
99
+ return PLACEMENT.some(({ pattern }) => pattern.test(utility));
71
100
  }
72
- function reportOnFile(context, program, messageId, data) {
73
- const anchor = program.body[0] ?? program;
74
- if (anchor.loc && anchor.range && isEscaped(context, { loc: anchor.loc, range: anchor.range })) return;
75
- context.report({ loc: anchor.loc ?? program.loc, messageId, data });
101
+ var FIELDS_LAYOUT = /^(?:block|flex|grid|inline-flex|inline-grid|contents|flow-root)$|^(?:gap|gap-x|gap-y|space-x|space-y|grid-cols|grid-rows|grid-flow|auto-cols|auto-rows|items|justify|justify-items|place-content|place-items)-|^flex-(?:row|col|wrap|nowrap)|^content-(?!\[)/;
102
+ var isFieldsLayout = (token) => {
103
+ const { variants, utility } = splitClass(token);
104
+ return !variants.some((variant) => REACHING_VARIANT.test(variant)) && FIELDS_LAYOUT.test(utility);
105
+ };
106
+ var isSpacing = (token) => {
107
+ const { variants, utility } = splitClass(token);
108
+ return !variants.some((variant) => REACHING_VARIANT.test(variant)) && /^(?:gap|gap-x|gap-y|space-x|space-y)-/.test(utility);
109
+ };
110
+ var isPadding = (token) => {
111
+ const { variants, utility } = splitClass(token);
112
+ return !variants.some((variant) => REACHING_VARIANT.test(variant)) && /^p[xytrblse]?-/.test(utility);
113
+ };
114
+ var PART_LOOK_PROPS = {
115
+ AppShell: ["variant"],
116
+ Avatar: ["size"],
117
+ AvatarGroup: ["size"],
118
+ Banner: ["tone"],
119
+ Button: ["variant", "size"],
120
+ Card: ["fill", "hover", "attention", "selected", "active", "hovered", "quietUntilHover", "unreadable", "clip"],
121
+ Checkbox: ["row"],
122
+ Chip: ["type"],
123
+ KindIcon: ["tone"],
124
+ LinkedIcon: ["tone"],
125
+ LinkKey: ["tone"],
126
+ CollapsibleSection: ["look"],
127
+ Divider: ["tone", "orientation"],
128
+ EmptyState: ["scope"],
129
+ FieldLine: ["tone"],
130
+ IconButton: ["variant", "pressed", "glow"],
131
+ InlineText: ["variant"],
132
+ InputChip: ["truncate"],
133
+ Kbd: ["tone"],
134
+ Link: ["variant", "truncate", "cover"],
135
+ MenuItem: ["size", "selected", "destructive"],
136
+ MenuSub: ["selected"],
137
+ NavItem: ["active"],
138
+ Person: ["size"],
139
+ ProgressBar: ["variant"],
140
+ Property: ["layout"],
141
+ RailItem: ["active"],
142
+ Reaction: ["pressed"],
143
+ ReactionPicker: ["surface"],
144
+ RichText: ["size"],
145
+ SectionHeader: ["hover", "look"],
146
+ SectionLabel: ["tone", "truncate"],
147
+ ShowMore: ["surface"],
148
+ Select: ["size"],
149
+ Tabs: ["size"],
150
+ TextInput: ["size"],
151
+ Toast: ["type"],
152
+ Toolbar: ["surface"],
153
+ ToolbarButton: ["variant", "pressed", "glow"],
154
+ TopBar: ["variant"]
155
+ };
156
+ var CLASS_PROP = /^(?:className|[a-z][A-Za-z]*ClassName)$/;
157
+ var child = (node, key) => node[key];
158
+ var children = (node, key) => node[key] ?? [];
159
+ var nameOf = (node) => node?.type === "Identifier" || node?.type === "JSXIdentifier" ? node.name : node?.type === "Literal" && typeof node.value === "string" ? node.value : void 0;
160
+ function walk(root, visit) {
161
+ const stack = [root];
162
+ while (stack.length) {
163
+ const node = stack.pop();
164
+ visit(node);
165
+ for (const key of Object.keys(node)) {
166
+ if (key === "parent" || key === "loc" || key === "range" || key === "tokens" || key === "comments") continue;
167
+ const value = node[key];
168
+ if (Array.isArray(value)) for (const item of value) {
169
+ if (item && typeof item.type === "string") stack.push(item);
170
+ }
171
+ else if (value && typeof value.type === "string") stack.push(value);
172
+ }
173
+ }
76
174
  }
77
- var componentHasAPage = {
78
- meta: {
79
- type: "problem",
80
- docs: { description: "Every component of the package has a usage page beside it" },
81
- schema: [],
82
- messages: {
83
- missing: "{{name}} has no page. Write {{page}} beside it \u2014 what it is, when, when not, how, and what it owns \u2014 or say why not at the top of the file.",
84
- ...ESCAPE_MESSAGES
175
+ var PACKAGE = "@estiva-app/ui";
176
+ var moduleCache = /* @__PURE__ */ new Map();
177
+ var packageDirCache = /* @__PURE__ */ new Map();
178
+ var packagePartsCache = /* @__PURE__ */ new Map();
179
+ function parseFile(parser, filePath) {
180
+ const code2 = readFileSync(filePath, "utf8");
181
+ const options = { filePath, ecmaVersion: "latest", sourceType: "module", ecmaFeatures: { jsx: filePath.endsWith("x") }, range: true, loc: true };
182
+ try {
183
+ if (parser.parseForESLint) return parser.parseForESLint(code2, options).ast;
184
+ if (parser.parse) return parser.parse(code2, options);
185
+ } catch {
186
+ }
187
+ return null;
188
+ }
189
+ function packageDirOf(file) {
190
+ const start = dirname(resolve(file));
191
+ if (packageDirCache.has(start)) return packageDirCache.get(start) ?? null;
192
+ let dir = start;
193
+ for (; ; ) {
194
+ if (existsSync(join(dir, "package.json"))) break;
195
+ const up = dirname(dir);
196
+ if (up === dir) {
197
+ dir = "";
198
+ break;
85
199
  }
86
- },
87
- create(context) {
88
- return {
89
- Program(node) {
90
- const filename = context.filename;
91
- if (!componentFile(filename)) return;
92
- const page = sibling(filename, ".mdx");
93
- if (existsSync(page)) return;
94
- const name = filename.split(/[\\/]/).pop() ?? filename;
95
- reportOnFile(context, node, "missing", { name, page: page.split(/[\\/]/).pop() ?? page });
200
+ dir = up;
201
+ }
202
+ packageDirCache.set(start, dir || null);
203
+ return dir || null;
204
+ }
205
+ function resolveModule(fromFile, specifier) {
206
+ let base;
207
+ if (specifier.startsWith(".")) base = resolve(dirname(fromFile), specifier);
208
+ else if (specifier.startsWith("@/")) {
209
+ const dir = packageDirOf(fromFile);
210
+ if (!dir) return null;
211
+ base = join(dir, "src", specifier.slice(2));
212
+ } else return null;
213
+ for (const candidate of [base, `${base}.tsx`, `${base}.ts`, join(base, "index.tsx"), join(base, "index.ts")]) {
214
+ if (existsSync(candidate) && statSync(candidate).isFile()) return candidate;
215
+ }
216
+ return null;
217
+ }
218
+ function entrySources(dir, exports) {
219
+ const found = [];
220
+ for (const target of Object.values(exports && typeof exports === "object" ? exports : {})) {
221
+ const built = typeof target === "string" ? target : target?.default;
222
+ const match = typeof built === "string" ? /^\.\/dist\/(.+)\.js$/.exec(built) : null;
223
+ if (!match) continue;
224
+ const source = [`${match[1]}.ts`, `${match[1]}.tsx`].map((name) => join(dir, "src", name)).find((file) => existsSync(file));
225
+ if (source) found.push(source);
226
+ }
227
+ if (!found.length && existsSync(join(dir, "src", "index.ts"))) found.push(join(dir, "src", "index.ts"));
228
+ return found;
229
+ }
230
+ function packagePartsFor(file, parser) {
231
+ const dir = packageDirOf(file);
232
+ if (!dir) return null;
233
+ let manifest;
234
+ try {
235
+ manifest = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
236
+ } catch {
237
+ return null;
238
+ }
239
+ if (manifest.name !== PACKAGE) return null;
240
+ const entries = entrySources(dir, manifest.exports);
241
+ if (!entries.length) return null;
242
+ const mtimes = entries.map((entry) => `${entry}:${statSync(entry).mtimeMs}`).join("|");
243
+ const cached = packagePartsCache.get(dir);
244
+ if (cached && cached.mtimes === mtimes) return cached.parts;
245
+ const parts = /* @__PURE__ */ new Set();
246
+ for (const entry of entries) {
247
+ const ast = parseFile(parser, entry);
248
+ for (const statement2 of ast ? children(ast, "body") : []) {
249
+ if (statement2?.type !== "ExportNamedDeclaration" || statement2.exportKind === "type") continue;
250
+ for (const specifier of children(statement2, "specifiers")) {
251
+ const exported = nameOf(child(specifier, "exported"));
252
+ if (specifier?.exportKind !== "type" && exported && /^[A-Z][a-z]/.test(exported)) parts.add(exported);
96
253
  }
97
- };
254
+ }
98
255
  }
99
- };
100
- var componentHasAStory = {
101
- meta: {
102
- type: "problem",
103
- docs: { description: "Every component of the package has a story beside it" },
104
- schema: [],
105
- messages: {
106
- missing: "{{name}} has no story. Write {{story}} beside it, so it can be seen and reviewed, or say why not at the top of the file.",
107
- ...ESCAPE_MESSAGES
256
+ packagePartsCache.set(dir, { mtimes, parts });
257
+ return parts;
258
+ }
259
+ function functionComponents(program) {
260
+ const found = /* @__PURE__ */ new Map();
261
+ const unwrap = (node) => {
262
+ let current = node;
263
+ while (current?.type === "CallExpression" && children(current, "arguments").length) {
264
+ const callee = child(current, "callee");
265
+ const text = callee?.type === "Identifier" ? nameOf(callee) : callee?.type === "MemberExpression" ? nameOf(child(callee, "property")) : void 0;
266
+ if (text !== "forwardRef" && text !== "memo") return null;
267
+ current = children(current, "arguments")[0];
108
268
  }
109
- },
110
- create(context) {
111
- return {
112
- Program(node) {
113
- const filename = context.filename;
114
- if (!componentFile(filename)) return;
115
- const story = sibling(filename, ".stories.tsx");
116
- if (existsSync(story)) return;
117
- const name = filename.split(/[\\/]/).pop() ?? filename;
118
- reportOnFile(context, node, "missing", { name, story: story.split(/[\\/]/).pop() ?? story });
269
+ return current?.type === "ArrowFunctionExpression" || current?.type === "FunctionExpression" ? current : null;
270
+ };
271
+ walk(program, (node) => {
272
+ if (node.type === "FunctionDeclaration") {
273
+ const name = nameOf(child(node, "id"));
274
+ if (name && /^[A-Z]/.test(name)) found.set(name, node);
275
+ } else if (node.type === "VariableDeclarator") {
276
+ const name = nameOf(child(node, "id"));
277
+ const fn = unwrap(child(node, "init"));
278
+ if (name && /^[A-Z]/.test(name) && fn) found.set(name, fn);
279
+ }
280
+ });
281
+ return found;
282
+ }
283
+ function moduleParts(file, program, parser, stack) {
284
+ const locals = /* @__PURE__ */ new Map();
285
+ const packageParts = packagePartsFor(file, parser);
286
+ const body = children(program, "body");
287
+ const exportsOf = (specifier) => {
288
+ if (specifier === PACKAGE || specifier.startsWith(`${PACKAGE}/`)) return "package";
289
+ const target = resolveModule(file, specifier);
290
+ if (!target) return null;
291
+ if (packageParts) return "package";
292
+ return moduleExports(target, parser, stack);
293
+ };
294
+ for (const statement2 of body) {
295
+ if (statement2?.type !== "ImportDeclaration" || statement2.importKind === "type") continue;
296
+ const source = exportsOf(String(child(statement2, "source").value));
297
+ if (!source) continue;
298
+ for (const specifier of children(statement2, "specifiers")) {
299
+ if (!specifier || specifier.importKind === "type") continue;
300
+ const local = nameOf(child(specifier, "local"));
301
+ if (!local) continue;
302
+ if (specifier.type === "ImportNamespaceSpecifier") {
303
+ if (source === "package" && !packageParts) locals.set(local, "namespace");
304
+ continue;
119
305
  }
120
- };
306
+ const imported = specifier.type === "ImportDefaultSpecifier" ? "default" : nameOf(child(specifier, "imported"));
307
+ if (!imported) continue;
308
+ if (source === "package") {
309
+ const isPart2 = packageParts ? packageParts.has(imported) : /^[A-Z]/.test(imported);
310
+ if (isPart2) locals.set(local, { part: imported, props: "all" });
311
+ } else if (source.has(imported)) locals.set(local, source.get(imported));
312
+ }
121
313
  }
122
- };
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"
314
+ const components = functionComponents(program);
315
+ if (packageParts) {
316
+ for (const name of components.keys()) if (packageParts.has(name) && !locals.has(name)) locals.set(name, { part: name, props: "all" });
296
317
  }
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;
318
+ if (!packageParts) {
319
+ let changed = true;
320
+ for (let round = 0; changed && round < 10; round += 1) {
321
+ changed = false;
322
+ for (const [name, fn] of components) {
323
+ const binding = handsOnTo(fn, (tag) => bindingOfTag(tag, locals));
324
+ if (!binding) continue;
325
+ const next = { ...binding, via: name };
326
+ const previous = locals.get(name);
327
+ if (!previous || JSON.stringify(previous) !== JSON.stringify(next)) {
328
+ if (previous && previous !== "namespace" && !previous.via) continue;
329
+ locals.set(name, next);
330
+ changed = true;
331
+ }
332
+ }
333
+ }
302
334
  }
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;
335
+ const exports = /* @__PURE__ */ new Map();
336
+ const localBinding = (name) => {
337
+ const binding = name ? locals.get(name) : void 0;
338
+ return binding && binding !== "namespace" ? binding : void 0;
339
+ };
340
+ for (const statement2 of body) {
341
+ if (!statement2) continue;
342
+ if (statement2.type === "ExportNamedDeclaration") {
343
+ const declaration = child(statement2, "declaration");
344
+ if (declaration?.type === "FunctionDeclaration") {
345
+ const name = nameOf(child(declaration, "id"));
346
+ const binding = localBinding(name);
347
+ if (name && binding) exports.set(name, binding);
348
+ } else if (declaration?.type === "VariableDeclaration") {
349
+ for (const declarator of children(declaration, "declarations")) {
350
+ const name = nameOf(child(declarator, "id"));
351
+ const init = child(declarator, "init");
352
+ const binding = localBinding(name) ?? (init?.type === "Identifier" ? localBinding(nameOf(init)) : void 0);
353
+ if (name && binding) exports.set(name, binding);
354
+ }
355
+ }
356
+ const source = child(statement2, "source");
357
+ const from = source ? exportsOf(String(source.value)) : null;
358
+ for (const specifier of children(statement2, "specifiers")) {
359
+ if (!specifier || specifier.exportKind === "type") continue;
360
+ const local = nameOf(child(specifier, "local"));
361
+ const exported = nameOf(child(specifier, "exported"));
362
+ if (!local || !exported) continue;
363
+ if (!source) {
364
+ const binding = localBinding(local);
365
+ if (binding) exports.set(exported, binding);
366
+ } else if (from === "package") {
367
+ if (/^[A-Z]/.test(local)) exports.set(exported, { part: local, props: "all" });
368
+ } else if (from?.has(local)) exports.set(exported, from.get(local));
369
+ }
370
+ } else if (statement2.type === "ExportAllDeclaration" && !child(statement2, "exported")) {
371
+ const from = exportsOf(String(child(statement2, "source").value));
372
+ if (from && from !== "package") for (const [name, binding] of from) exports.set(name, binding);
373
+ } else if (statement2.type === "ExportDefaultDeclaration") {
374
+ const declaration = child(statement2, "declaration");
375
+ const name = declaration?.type === "Identifier" ? nameOf(declaration) : nameOf(child(declaration, "id"));
376
+ const binding = localBinding(name);
377
+ if (binding) exports.set("default", binding);
378
+ }
308
379
  }
309
- return node;
380
+ return { locals, exports };
381
+ }
382
+ function partsOfFile(file, program, parser) {
383
+ return moduleParts(file, program, parser, /* @__PURE__ */ new Set([file])).locals;
384
+ }
385
+ function moduleExports(file, parser, stack) {
386
+ const mtime = statSync(file).mtimeMs;
387
+ const cached = moduleCache.get(file);
388
+ if (cached && cached.mtime === mtime) return cached.exports;
389
+ if (stack.has(file)) return /* @__PURE__ */ new Map();
390
+ stack.add(file);
391
+ const program = parseFile(parser, file);
392
+ const exports = program ? moduleParts(file, program, parser, stack).exports : /* @__PURE__ */ new Map();
393
+ stack.delete(file);
394
+ moduleCache.set(file, { mtime, exports });
395
+ return exports;
396
+ }
397
+ function bindingOfTag(tag, locals) {
398
+ if (!tag) return void 0;
399
+ if (tag.type === "JSXIdentifier") {
400
+ const binding = locals.get(tag.name);
401
+ return binding && binding !== "namespace" ? binding : void 0;
402
+ }
403
+ if (tag.type === "JSXMemberExpression") {
404
+ const object = child(tag, "object");
405
+ const property = nameOf(child(tag, "property"));
406
+ if (object?.type === "JSXIdentifier" && locals.get(object.name) === "namespace" && property) return { part: property, props: "all" };
407
+ }
408
+ return void 0;
409
+ }
410
+ function handsOnTo(fn, bindingOf) {
411
+ const param = children(fn, "params")[0];
412
+ if (!param) return void 0;
413
+ let restName;
414
+ let propsName;
415
+ const classParams = /* @__PURE__ */ new Map();
416
+ if (param.type === "ObjectPattern") {
417
+ for (const property of children(param, "properties")) {
418
+ if (!property) continue;
419
+ if (property.type === "RestElement") restName = nameOf(child(property, "argument"));
420
+ else if (property.type === "Property") {
421
+ const key = nameOf(child(property, "key"));
422
+ let value = child(property, "value");
423
+ if (value?.type === "AssignmentPattern") value = child(value, "left");
424
+ const local = nameOf(value);
425
+ if (key && local && CLASS_PROP.test(key)) classParams.set(local, key);
426
+ }
427
+ }
428
+ } else if (param.type === "Identifier") propsName = nameOf(param);
429
+ let wrapper;
430
+ const forwarded = { props: {} };
431
+ const body = child(fn, "body");
432
+ if (!body) return void 0;
433
+ walk(body, (node) => {
434
+ if (wrapper || node.type !== "JSXOpeningElement") return;
435
+ const binding = bindingOf(child(node, "name"));
436
+ if (!binding) return;
437
+ for (const attribute3 of children(node, "attributes")) {
438
+ if (!attribute3) continue;
439
+ if (attribute3.type === "JSXSpreadAttribute") {
440
+ const argument = nameOf(child(attribute3, "argument"));
441
+ if (argument && (argument === restName || argument === propsName)) wrapper = { part: binding.part, props: binding.props };
442
+ continue;
443
+ }
444
+ const prop = nameOf(child(attribute3, "name"));
445
+ if (!prop || !CLASS_PROP.test(prop)) continue;
446
+ const partProp = binding.props === "all" ? prop : binding.props[prop];
447
+ if (!partProp) continue;
448
+ walk(attribute3, (inner) => {
449
+ let callerProp;
450
+ if (inner.type === "Identifier") callerProp = classParams.get(inner.name);
451
+ if (inner.type === "MemberExpression" && nameOf(child(inner, "object")) === propsName) {
452
+ const key = nameOf(child(inner, "property"));
453
+ if (key && CLASS_PROP.test(key)) callerProp = key;
454
+ }
455
+ if (!callerProp) return;
456
+ if (forwarded.part && forwarded.part !== binding.part) return;
457
+ forwarded.part = binding.part;
458
+ forwarded.props[callerProp] = partProp;
459
+ });
460
+ }
461
+ });
462
+ if (wrapper) return wrapper;
463
+ return forwarded.part ? { part: forwarded.part, props: forwarded.props } : void 0;
310
464
  }
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;
465
+ var CLASS_FUNCTIONS = /* @__PURE__ */ new Set(["cn", "clsx", "cx", "twMerge", "classNames"]);
466
+ function constantOf(identifier, scope) {
467
+ let current = scope;
468
+ while (current) {
469
+ const variable = current.set.get(identifier.name);
470
+ if (variable) {
471
+ const definition = variable.defs[0];
472
+ if (variable.defs.length !== 1 || definition?.type !== "Variable") return void 0;
473
+ if (definition.parent?.kind !== "const") return void 0;
474
+ return child(definition.node, "init") ?? void 0;
475
+ }
476
+ current = current.upper;
314
477
  }
315
478
  return void 0;
316
479
  }
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;
480
+ function classesOf(value, scopeOf, asMap = false, seen = /* @__PURE__ */ new Set()) {
481
+ if (!value || seen.has(value) || seen.size > 200) return [];
482
+ seen.add(value);
483
+ const read = (node, map = false) => classesOf(node, scopeOf, map, seen);
484
+ const words2 = (text) => typeof text === "string" ? text.split(/\s+/).filter(Boolean) : [];
485
+ switch (value.type) {
486
+ case "Literal":
487
+ return words2(value.value);
488
+ case "TemplateLiteral":
489
+ return [...children(value, "quasis").flatMap((quasi) => words2((quasi?.value).cooked)), ...children(value, "expressions").flatMap((e) => read(e))];
490
+ case "JSXExpressionContainer":
491
+ case "TSAsExpression":
492
+ case "TSSatisfiesExpression":
493
+ case "TSNonNullExpression":
494
+ case "ChainExpression":
495
+ return read(child(value, "expression"), asMap);
496
+ case "ConditionalExpression":
497
+ return [...read(child(value, "consequent")), ...read(child(value, "alternate"))];
498
+ case "LogicalExpression":
499
+ return value.operator === "&&" ? read(child(value, "right")) : [...read(child(value, "left")), ...read(child(value, "right"))];
500
+ case "BinaryExpression":
501
+ return value.operator === "+" ? [...read(child(value, "left")), ...read(child(value, "right"))] : [];
502
+ case "ArrayExpression":
503
+ return children(value, "elements").flatMap((e) => read(e));
504
+ case "ObjectExpression":
505
+ return children(value, "properties").flatMap((property) => {
506
+ if (property?.type !== "Property") return [];
507
+ return asMap ? read(child(property, "value"), true) : property.computed ? [] : words2(nameOf(child(property, "key")));
508
+ });
509
+ case "CallExpression": {
510
+ const callee = child(value, "callee");
511
+ return callee?.type === "Identifier" && CLASS_FUNCTIONS.has(callee.name) ? children(value, "arguments").flatMap((a) => read(a)) : [];
512
+ }
513
+ case "Identifier": {
514
+ const constant = constantOf(value, scopeOf(value));
515
+ return constant ? read(constant, asMap) : [];
516
+ }
517
+ case "MemberExpression": {
518
+ const object = child(value, "object");
519
+ const target = object?.type === "Identifier" ? constantOf(object, scopeOf(object)) : object;
520
+ const map = target?.type === "TSAsExpression" || target?.type === "TSSatisfiesExpression" ? child(target, "expression") : target;
521
+ if (map?.type !== "ObjectExpression") return [];
522
+ const property = child(value, "property");
523
+ const key = value.computed ? property?.type === "Literal" ? String(property.value) : void 0 : nameOf(property);
524
+ return children(map, "properties").flatMap((entry) => {
525
+ if (entry?.type !== "Property") return [];
526
+ if (key !== void 0 && nameOf(child(entry, "key")) !== key) return [];
527
+ return read(child(entry, "value"), true);
528
+ });
529
+ }
530
+ default:
531
+ return [];
355
532
  }
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
533
  }
374
- var noRebuiltBehaviour = {
534
+ var code = (items) => items.map((item) => `\`${item}\``).join(" ");
535
+ var or = (items) => items.length === 1 ? code(items) : `${items.slice(0, -1).map((i) => `\`${i}\``).join(", ")} or \`${items[items.length - 1]}\``;
536
+ var noRestyledPart = {
375
537
  meta: {
376
538
  type: "problem",
377
- docs: { description: "Behaviour @estiva-app/ui already owns, rebuilt by hand in an app" },
539
+ docs: { description: "Only placement passes into a part of @estiva-app/ui through a class prop" },
378
540
  schema: [],
379
541
  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.",
542
+ restyled: "{{classes}} on {{where}} changes how it looks. A part of @estiva-app/ui is placed from outside, never restyled: only space, size, flex and grid, and position pass in.{{use}} A look for what is around it goes on your own element around it.",
543
+ restyledStyle: "{{keys}} in the `style` of {{where}} changes how it looks. A part of @estiva-app/ui is placed from outside, never restyled, by class or by style: only space, size, flex and grid, and position pass in.{{use}} A look for what is around it goes on your own element around it.",
544
+ emptyStatePadding: "{{classes}} pads {{where}}. EmptyState takes no padding (Katerina, 14 September): its room comes from the box its rows live in, so put the padding on that box.",
545
+ formLayout: '{{classes}} lays out the fields of {{where}}. A Form places its own fields, 24px apart (Katerina, 28 September), so every form reads the same: remove it. A form that is not a list of fields (a field and its button, a composer) says `layout="free"` and lays itself out.',
546
+ formSpacedFromOutside: "{{classes}} on the box around `Form` spaces the form from what is beside it, so the gap above its first field is not the form\u2019s 24px. Put what is beside it inside the `Form`, as one block before the fields, and drop the box: the Form puts 24px between them (Katerina, 1 October; MoveDialog in Peek does this).",
395
547
  ...ESCAPE_MESSAGES
396
548
  }
397
549
  },
398
550
  create(context) {
399
- const { sourceCode } = context;
400
- const text = (node) => sourceCode.getText(node);
551
+ const parser = context.languageOptions?.parser ?? {};
552
+ const file = context.filename;
553
+ const sourceCode = context.sourceCode;
554
+ const scopeOf = (node) => sourceCode.getScope(node);
555
+ let locals;
401
556
  const escapes = /* @__PURE__ */ new Map();
402
557
  const escaped = (anchor) => {
403
558
  if (!escapes.has(anchor)) escapes.set(anchor, isEscaped(context, anchor));
404
559
  return escapes.get(anchor) === true;
405
560
  };
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 });
561
+ const placesItsFields = (element) => !children(element, "attributes").some((attribute3) => {
562
+ if (attribute3?.type !== "JSXAttribute" || nameOf(child(attribute3, "name")) !== "layout") return false;
563
+ const value = child(attribute3, "value");
564
+ const literal2 = value?.type === "JSXExpressionContainer" ? child(value, "expression") : value;
565
+ return !(literal2?.type === "Literal" && literal2.value === "fields");
566
+ });
567
+ const check = (element, binding, prop, value, at) => {
568
+ const partProp = binding.props === "all" ? prop : binding.props[prop];
569
+ if (!partProp || !value) return;
570
+ const classes = classesOf(value, scopeOf);
571
+ const handedOn = binding.props === "all" ? "its props" : `its \`${prop}\``;
572
+ const via = binding.via && binding.via !== binding.part ? `\`${binding.via}\` (it hands ${handedOn} to \`${binding.part}\`)` : `\`${binding.part}\``;
573
+ const where = `${via}${partProp === "className" ? "" : `'s \`${partProp}\``}`;
574
+ const restyled = [...new Set(classes.filter((token) => !isPlacement(token)))];
575
+ const padding = binding.part === "EmptyState" && binding.props === "all" ? [...new Set(classes.filter(isPadding))] : [];
576
+ const layout = binding.part === "Form" && partProp === "className" && placesItsFields(element) ? [...new Set(classes.filter(isFieldsLayout))] : [];
577
+ if (!restyled.length && !padding.length && !layout.length) return;
578
+ if (escaped(element)) return;
579
+ if (restyled.length) {
580
+ const props = PART_LOOK_PROPS[binding.part];
581
+ const use = props ? ` Use its ${or(props)}.` : ` \`${binding.part}\` has no prop for this yet: ask Katerina, and it gets made in @estiva-app/ui.`;
582
+ context.report({ loc: at.loc, messageId: "restyled", data: { classes: code(restyled), where, use } });
583
+ }
584
+ if (padding.length) context.report({ loc: at.loc, messageId: "emptyStatePadding", data: { classes: code(padding), where } });
585
+ if (layout.length) context.report({ loc: at.loc, messageId: "formLayout", data: { classes: code(layout), where } });
423
586
  };
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]}`);
587
+ const checkStyle = (element, binding, value, at) => {
588
+ if (binding.props !== "all" || value?.type !== "JSXExpressionContainer") return;
589
+ let object = child(value, "expression");
590
+ if (object?.type === "Identifier") object = constantOf(object, scopeOf(object));
591
+ while (object?.type === "TSAsExpression" || object?.type === "TSSatisfiesExpression") object = child(object, "expression");
592
+ if (object?.type !== "ObjectExpression") return;
593
+ const keys = children(object, "properties").map((property) => property?.type === "Property" && !property.computed ? nameOf(child(property, "key")) : void 0).filter((key) => !!key && !key.startsWith("--") && !PLACEMENT_STYLE.test(key));
594
+ if (!keys.length || escaped(element)) return;
595
+ const props = PART_LOOK_PROPS[binding.part];
596
+ const use = props ? ` Use its ${or(props)}.` : ` \`${binding.part}\` has no prop for this yet: ask Katerina, and it gets made in @estiva-app/ui.`;
597
+ const where = binding.via && binding.via !== binding.part ? `\`${binding.via}\` (it hands its props to \`${binding.part}\`)` : `\`${binding.part}\``;
598
+ context.report({ loc: at.loc, messageId: "restyledStyle", data: { keys: code([...new Set(keys)]), where, use } });
430
599
  };
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
- }
600
+ const checkSpacedFromOutside = (opening) => {
601
+ const form = opening.parent;
602
+ const box = form?.parent;
603
+ if (form?.type !== "JSXElement" || box?.type !== "JSXElement") return;
604
+ const beside = children(box, "children").filter((node) => {
605
+ if (!node || node === form) return false;
606
+ if (node.type === "JSXText") return String(node.value).trim() !== "";
607
+ if (node.type === "JSXExpressionContainer") return child(node, "expression")?.type !== "JSXEmptyExpression";
608
+ return true;
609
+ });
610
+ if (!beside.length) return;
611
+ const boxOpening = child(box, "openingElement");
612
+ const spacing = children(boxOpening, "attributes").flatMap((attribute3) => {
613
+ if (attribute3?.type !== "JSXAttribute") return [];
614
+ const prop = nameOf(child(attribute3, "name"));
615
+ return prop === "className" || prop === "bodyClassName" ? classesOf(child(attribute3, "value"), scopeOf).filter(isSpacing) : [];
616
+ });
617
+ if (!spacing.length || escaped(opening)) return;
618
+ context.report({ loc: opening.loc, messageId: "formSpacedFromOutside", data: { classes: code([...new Set(spacing)]) } });
435
619
  };
436
- const portalImports = /* @__PURE__ */ new Map();
437
- let portalCalled = false;
438
620
  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));
621
+ Program(program) {
622
+ locals = moduleParts(file, program, parser, /* @__PURE__ */ new Set([file])).locals;
515
623
  },
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;
624
+ JSXOpeningElement(ruleNode) {
625
+ const element = ruleNode;
626
+ const binding = locals && bindingOfTag(child(element, "name"), locals);
627
+ if (!binding) return;
628
+ if (binding.part === "Form" && binding.props === "all" && placesItsFields(element)) checkSpacedFromOutside(element);
629
+ for (const attribute3 of children(element, "attributes")) {
630
+ if (!attribute3) continue;
631
+ if (attribute3.type === "JSXAttribute") {
632
+ const prop = nameOf(child(attribute3, "name"));
633
+ if (prop && CLASS_PROP.test(prop)) check(element, binding, prop, child(attribute3, "value"), attribute3);
634
+ else if (prop === "style") checkStyle(element, binding, child(attribute3, "value"), attribute3);
635
+ continue;
530
636
  }
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}`);
637
+ let spread = child(attribute3, "argument");
638
+ if (spread?.type === "Identifier") spread = constantOf(spread, scopeOf(spread));
639
+ while (spread?.type === "TSAsExpression" || spread?.type === "TSSatisfiesExpression") spread = child(spread, "expression");
640
+ if (spread?.type !== "ObjectExpression") continue;
641
+ for (const property of children(spread, "properties")) {
642
+ const key = property?.type === "Property" && !property.computed ? nameOf(child(property, "key")) : void 0;
643
+ if (key && CLASS_PROP.test(key)) check(element, binding, key, child(property, "value"), property);
552
644
  }
553
645
  }
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
646
  }
572
647
  };
573
648
  }
574
649
  };
575
650
 
576
- // src/eslint/no-hand-rolled-behaviour.ts
577
- var FLOATING_EVENTS = /* @__PURE__ */ new Set(["resize", "scroll", "mousedown", "pointerdown", "keydown", "keyup", "focusin", "focusout", "click"]);
578
- function statement(node) {
579
- for (let p = node.parent; p; p = p.parent) {
580
- if (!/(Statement|Declaration)$/.test(p.type)) continue;
581
- if (p.loc && p.range) return { loc: p.loc, range: p.range };
582
- break;
583
- }
584
- return { loc: node.loc, range: node.range };
651
+ // src/eslint/has-a-page-and-a-story.ts
652
+ function componentFile(filename) {
653
+ if (!filename.endsWith(".tsx") || /\.(stories|test)\.tsx$/.test(filename)) return false;
654
+ const dir = packageDirOf(filename);
655
+ return !dir || relative(dir, filename).split(sep).join("/").startsWith("src/");
585
656
  }
586
- var noHandRolledBehaviour = {
657
+ function sibling(filename, extension) {
658
+ return filename.replace(/\.tsx$/, extension);
659
+ }
660
+ function reportOnFile(context, program, messageId, data) {
661
+ const anchor = program.body[0] ?? program;
662
+ if (anchor.loc && anchor.range && isEscaped(context, { loc: anchor.loc, range: anchor.range })) return;
663
+ context.report({ loc: anchor.loc ?? program.loc, messageId, data });
664
+ }
665
+ var componentHasAPage = {
587
666
  meta: {
588
667
  type: "problem",
589
- docs: { description: "Overlay behaviour written by hand where Base UI has a part (D6)" },
668
+ docs: { description: "Every component of the package has a usage page beside it" },
590
669
  schema: [],
591
670
  messages: {
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.",
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.",
671
+ missing: "{{name}} has no page. Write {{page}} beside it \u2014 what it is, when, when not, how, and what it owns \u2014 or say why not at the top of the file.",
595
672
  ...ESCAPE_MESSAGES
596
673
  }
597
674
  },
598
675
  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
- }
676
+ return {
677
+ Program(node) {
678
+ const filename = context.filename;
679
+ if (!componentFile(filename)) return;
680
+ const page = sibling(filename, ".mdx");
681
+ if (existsSync2(page)) return;
682
+ const name = filename.split(/[\\/]/).pop() ?? filename;
683
+ reportOnFile(context, node, "missing", { name, page: page.split(/[\\/]/).pop() ?? page });
607
684
  }
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
685
  };
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
- },
634
- ImportDeclaration(node) {
635
- const declaration = node;
636
- if (declaration.source.value !== "react-dom") return;
637
- for (const specifier of declaration.specifiers) {
638
- if (specifier.type !== "ImportSpecifier" || specifier.imported?.name !== "createPortal") continue;
639
- if (isEscaped(context, declaration)) return;
640
- context.report({ loc: declaration.loc, messageId: "portal" });
641
- return;
642
- }
643
- },
644
- CallExpression(node) {
645
- const call = node;
646
- const { callee } = call;
647
- if (callee.type === "Identifier" && callee.name === "createPortal") {
648
- if (isEscaped(context, statement(call))) return;
649
- context.report({ loc: call.loc, messageId: "portal" });
650
- return;
651
- }
652
- if (callee.type !== "MemberExpression" || callee.property?.name !== "addEventListener") return;
653
- const target = callee.object?.type === "Identifier" ? callee.object.name : void 0;
654
- if (target !== "window" && target !== "document") return;
655
- const [first] = call.arguments;
656
- const event = first?.type === "Literal" && typeof first.value === "string" ? first.value : void 0;
657
- if (!event || !FLOATING_EVENTS.has(event)) return;
658
- if (isEscaped(context, statement(call))) return;
659
- context.report({ loc: call.loc, messageId: "listener", data: { event, target } });
686
+ }
687
+ };
688
+ var componentHasAStory = {
689
+ meta: {
690
+ type: "problem",
691
+ docs: { description: "Every component of the package has a story beside it" },
692
+ schema: [],
693
+ messages: {
694
+ missing: "{{name}} has no story. Write {{story}} beside it, so it can be seen and reviewed, or say why not at the top of the file.",
695
+ ...ESCAPE_MESSAGES
696
+ }
697
+ },
698
+ create(context) {
699
+ return {
700
+ Program(node) {
701
+ const filename = context.filename;
702
+ if (!componentFile(filename)) return;
703
+ const story = sibling(filename, ".stories.tsx");
704
+ if (existsSync2(story)) return;
705
+ const name = filename.split(/[\\/]/).pop() ?? filename;
706
+ reportOnFile(context, node, "missing", { name, story: story.split(/[\\/]/).pop() ?? story });
660
707
  }
661
708
  };
662
709
  }
663
710
  };
664
711
 
665
- // src/eslint/no-handmade-empty-state.ts
666
- import { statSync as statSync2 } from "node:fs";
667
-
668
- // src/eslint/no-restyled-part.ts
669
- import { existsSync as existsSync2, readFileSync, statSync } from "node:fs";
670
- import { dirname, join, resolve } from "node:path";
671
- var PLACEMENT = [
672
- { what: "space around", pattern: /^m[xytrblse]?-/ },
673
- { what: "space inside", pattern: /^p[xytrblse]?-/ },
674
- { what: "width and height", pattern: /^(?:w|h|size|min-w|min-h|max-w|max-h)-/ },
675
- { what: "shown, and how it lays out", pattern: /^(?:hidden|block|inline|inline-block|inline-flex|inline-grid|flex|grid|contents|flow-root)$/ },
676
- { what: "its place in a row or a grid", pattern: /^(?:grow|shrink)$|^(?:flex|basis|grow|shrink|order|gap|gap-x|gap-y|space-x|space-y|col|row|grid-cols|grid-rows|grid-flow|auto-cols|auto-rows)-/ },
677
- { what: "alignment", pattern: /^(?:self|justify|justify-items|justify-self|items|place-content|place-items|place-self)-|^content-(?!\[)/ },
678
- { what: "position", pattern: /^(?:static|relative|absolute|fixed|sticky)$|^(?:inset|inset-x|inset-y|top|right|bottom|left|start|end|z)-/ },
679
- // Draws nothing: it names the part, so what is inside can answer its hover (`group-hover:`).
680
- { what: "a name for hover", pattern: /^(?:group|peer)(?:\/[\w-]+)?$/ }
681
- ];
682
- var PLACEMENT_STYLE = /^(?:margin|padding|inset|scrollMargin)(?:Top|Right|Bottom|Left|Block|Inline|BlockStart|BlockEnd|InlineStart|InlineEnd)?$|^(?:width|height|minWidth|minHeight|maxWidth|maxHeight|inlineSize|blockSize|minInlineSize|minBlockSize|maxInlineSize|maxBlockSize)$|^(?:display|flex|flexGrow|flexShrink|flexBasis|order|gap|rowGap|columnGap|alignSelf|justifySelf|placeSelf|gridArea|gridColumn|gridColumnStart|gridColumnEnd|gridRow|gridRowStart|gridRowEnd)$|^(?:position|top|right|bottom|left|zIndex|transform|translate)$/;
683
- var REACHING_VARIANT = /^\[|^(?:before|after|placeholder|file|marker|selection|first-letter|first-line|backdrop|\*|\*\*)$/;
684
- function splitClass(token) {
685
- const variants = [];
686
- let current = "";
687
- let depth = 0;
688
- for (const character of token) {
689
- if (character === "[") depth += 1;
690
- if (character === "]") depth -= 1;
691
- if (character === ":" && depth === 0) {
692
- variants.push(current);
693
- current = "";
694
- } else current += character;
695
- }
696
- return { variants, utility: current.replace(/^!/, "").replace(/!$/, "").replace(/^-/, "") };
697
- }
698
- function isPlacement(token) {
699
- const { variants, utility } = splitClass(token);
700
- if (variants.some((variant) => REACHING_VARIANT.test(variant))) return false;
701
- return PLACEMENT.some(({ pattern }) => pattern.test(utility));
702
- }
703
- var FIELDS_LAYOUT = /^(?:block|flex|grid|inline-flex|inline-grid|contents|flow-root)$|^(?:gap|gap-x|gap-y|space-x|space-y|grid-cols|grid-rows|grid-flow|auto-cols|auto-rows|items|justify|justify-items|place-content|place-items)-|^flex-(?:row|col|wrap|nowrap)|^content-(?!\[)/;
704
- var isFieldsLayout = (token) => {
705
- const { variants, utility } = splitClass(token);
706
- return !variants.some((variant) => REACHING_VARIANT.test(variant)) && FIELDS_LAYOUT.test(utility);
712
+ // src/eslint/no-rebuilt-behaviour.ts
713
+ var BASE_UI_PARTS = {
714
+ "alert-dialog": { use: "DialogShell", more: " To ask yes or no, `ConfirmDialog`." },
715
+ autocomplete: { use: "CommandPalette" },
716
+ avatar: { use: "Avatar" },
717
+ button: { use: "Button", more: " Icon only, `IconButton`." },
718
+ checkbox: { use: "Checkbox" },
719
+ collapsible: { use: "CollapsibleSection" },
720
+ combobox: { use: "ChipInput" },
721
+ dialog: { use: "DialogShell", more: " To search and act, `CommandPalette`." },
722
+ field: { use: "Field" },
723
+ fieldset: { use: "Form" },
724
+ form: { use: "Form" },
725
+ input: { use: "TextInput", more: " For a search, `SearchInput`." },
726
+ menu: { use: "Menu" },
727
+ popover: { use: "Popover" },
728
+ "preview-card": { use: "PreviewCard" },
729
+ progress: { use: "ProgressBar" },
730
+ "scroll-area": { use: "ScrollArea" },
731
+ select: { use: "Select" },
732
+ separator: { use: "Divider" },
733
+ tabs: { use: "Tabs" },
734
+ toast: { use: "Toast" },
735
+ toggle: { use: "Reaction" },
736
+ toolbar: { use: "Toolbar" },
737
+ tooltip: { use: "Tooltip", more: " Around a control, `WithTooltip`." },
738
+ accordion: null,
739
+ "checkbox-group": null,
740
+ "context-menu": null,
741
+ drawer: null,
742
+ menubar: null,
743
+ meter: null,
744
+ "navigation-menu": null,
745
+ "number-field": null,
746
+ "otp-field": null,
747
+ radio: null,
748
+ "radio-group": null,
749
+ slider: null,
750
+ switch: null,
751
+ "toggle-group": null
707
752
  };
708
- var isSpacing = (token) => {
709
- const { variants, utility } = splitClass(token);
710
- return !variants.some((variant) => REACHING_VARIANT.test(variant)) && /^(?:gap|gap-x|gap-y|space-x|space-y)-/.test(utility);
753
+ var LIST_PART = {
754
+ use: "Select",
755
+ 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`."
711
756
  };
712
- var isPadding = (token) => {
713
- const { variants, utility } = splitClass(token);
714
- return !variants.some((variant) => REACHING_VARIANT.test(variant)) && /^p[xytrblse]?-/.test(utility);
757
+ var MESSAGE_PART = { use: "FieldLine", more: " For a notice, `Banner`; for a message that comes and goes, `Toast`." };
758
+ var ROLE_PARTS = {
759
+ dialog: { thing: "dialog", part: { use: "DialogShell", more: " To ask yes or no, `ConfirmDialog`." } },
760
+ alertdialog: { thing: "dialog", part: { use: "ConfirmDialog" } },
761
+ menu: { thing: "menu", part: { use: "Menu" } },
762
+ menuitem: { thing: "menu", part: { use: "Menu" } },
763
+ menuitemcheckbox: { thing: "menu", part: { use: "Menu" } },
764
+ menuitemradio: { thing: "menu", part: { use: "Menu" } },
765
+ listbox: { thing: "list", part: LIST_PART },
766
+ option: { thing: "list", part: LIST_PART },
767
+ combobox: { thing: "list", part: LIST_PART },
768
+ tablist: { thing: "set of tabs", part: { use: "Tabs" } },
769
+ tab: { thing: "set of tabs", part: { use: "Tabs" } },
770
+ tabpanel: { thing: "set of tabs", part: { use: "Tabs" } },
771
+ toolbar: { thing: "toolbar", part: { use: "Toolbar" } },
772
+ progressbar: { thing: "progress bar", part: { use: "ProgressBar" } },
773
+ checkbox: { thing: "tick box", part: { use: "Checkbox" } },
774
+ separator: { thing: "divider", part: { use: "Divider" } },
775
+ button: { thing: "button", part: { use: "Button", more: " Icon only, `IconButton`." } },
776
+ link: { thing: "link", part: { use: "Link" } },
777
+ tooltip: { thing: "tooltip", part: { use: "Tooltip", more: " Around a control, `WithTooltip`." } },
778
+ alert: { thing: "message", part: MESSAGE_PART },
779
+ status: { thing: "message", part: MESSAGE_PART },
780
+ menubar: { thing: "menu bar", part: null },
781
+ switch: { thing: "switch", part: null },
782
+ radio: { thing: "radio button", part: null },
783
+ radiogroup: { thing: "radio group", part: null },
784
+ slider: { thing: "slider", part: null },
785
+ spinbutton: { thing: "number field", part: null },
786
+ meter: { thing: "meter", part: null }
715
787
  };
716
- var PART_LOOK_PROPS = {
717
- AppShell: ["variant"],
718
- Avatar: ["size"],
719
- AvatarGroup: ["size"],
720
- Banner: ["tone"],
721
- Button: ["variant", "size"],
722
- Card: ["fill", "hover", "attention", "selected", "active", "hovered", "quietUntilHover", "unreadable", "clip"],
723
- Checkbox: ["row"],
724
- Chip: ["type"],
725
- KindIcon: ["tone"],
726
- LinkedIcon: ["tone"],
727
- CollapsibleSection: ["look"],
728
- Divider: ["tone", "orientation"],
729
- EmptyState: ["scope"],
730
- FieldLine: ["tone"],
731
- IconButton: ["variant", "pressed", "glow"],
732
- InputChip: ["truncate"],
733
- Kbd: ["tone"],
734
- Link: ["variant", "truncate", "cover"],
735
- MenuItem: ["size", "selected", "destructive"],
736
- MenuSub: ["selected"],
737
- NavItem: ["active"],
738
- Person: ["size"],
739
- ProgressBar: ["variant"],
740
- Property: ["layout"],
741
- RailItem: ["active"],
742
- Reaction: ["pressed"],
743
- ReactionPicker: ["surface"],
744
- RichText: ["size"],
745
- SectionHeader: ["hover", "look"],
746
- SectionLabel: ["tone", "truncate"],
747
- ShowMore: ["surface"],
748
- Select: ["size"],
749
- Tabs: ["size"],
750
- TextInput: ["size"],
751
- Toast: ["type"],
752
- Toolbar: ["surface"],
753
- ToolbarButton: ["variant", "pressed", "glow"],
754
- TopBar: ["variant"]
788
+ var WALKING_KEYS = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Home", "End", "PageUp", "PageDown"];
789
+ var PAGE_EVENTS = {
790
+ mousedown: "press",
791
+ pointerdown: "press",
792
+ click: "press",
793
+ touchstart: "press",
794
+ keydown: "key",
795
+ keyup: "key",
796
+ keypress: "key",
797
+ focusin: "focus",
798
+ focusout: "focus",
799
+ scroll: "follow",
800
+ resize: "follow"
755
801
  };
756
- var CLASS_PROP = /^(?:className|[a-z][A-Za-z]*ClassName)$/;
757
- var child = (node, key) => node[key];
758
- var children = (node, key) => node[key] ?? [];
759
- var nameOf = (node) => node?.type === "Identifier" || node?.type === "JSXIdentifier" ? node.name : node?.type === "Literal" && typeof node.value === "string" ? node.value : void 0;
760
- function walk(root, visit) {
761
- const stack = [root];
762
- while (stack.length) {
763
- const node = stack.pop();
764
- visit(node);
765
- for (const key of Object.keys(node)) {
766
- if (key === "parent" || key === "loc" || key === "range" || key === "tokens" || key === "comments") continue;
767
- const value = node[key];
768
- if (Array.isArray(value)) for (const item of value) {
769
- if (item && typeof item.type === "string") stack.push(item);
770
- }
771
- else if (value && typeof value.type === "string") stack.push(value);
772
- }
773
- }
774
- }
775
- var PACKAGE = "@estiva-app/ui";
776
- var moduleCache = /* @__PURE__ */ new Map();
777
- var packageDirCache = /* @__PURE__ */ new Map();
778
- var packagePartsCache = /* @__PURE__ */ new Map();
779
- function parseFile(parser, filePath) {
780
- const code2 = readFileSync(filePath, "utf8");
781
- const options = { filePath, ecmaVersion: "latest", sourceType: "module", ecmaFeatures: { jsx: filePath.endsWith("x") }, range: true, loc: true };
782
- try {
783
- if (parser.parseForESLint) return parser.parseForESLint(code2, options).ast;
784
- if (parser.parse) return parser.parse(code2, options);
785
- } catch {
786
- }
787
- return null;
788
- }
789
- function packageDirOf(file) {
790
- const start = dirname(resolve(file));
791
- if (packageDirCache.has(start)) return packageDirCache.get(start) ?? null;
792
- let dir = start;
793
- for (; ; ) {
794
- if (existsSync2(join(dir, "package.json"))) break;
795
- const up = dirname(dir);
796
- if (up === dir) {
797
- dir = "";
798
- break;
799
- }
800
- dir = up;
801
- }
802
- packageDirCache.set(start, dir || null);
803
- return dir || null;
804
- }
805
- function resolveModule(fromFile, specifier) {
806
- let base;
807
- if (specifier.startsWith(".")) base = resolve(dirname(fromFile), specifier);
808
- else if (specifier.startsWith("@/")) {
809
- const dir = packageDirOf(fromFile);
810
- if (!dir) return null;
811
- base = join(dir, "src", specifier.slice(2));
812
- } else return null;
813
- for (const candidate of [base, `${base}.tsx`, `${base}.ts`, join(base, "index.tsx"), join(base, "index.ts")]) {
814
- if (existsSync2(candidate) && statSync(candidate).isFile()) return candidate;
802
+ var INTERACTIVE_ELEMENTS = /* @__PURE__ */ new Set(["a", "button", "input", "select", "textarea", "summary", "iframe", "embed", "object", "audio", "video"]);
803
+ var SCROLL_CLASS = /^overflow(?:-[xy])?-(?:auto|scroll)$/;
804
+ var uses = (parts) => [
805
+ ...new Set(parts.flatMap((p) => p ? [p.use, ...[...(p.more ?? "").matchAll(/`([A-Z]\w+)`/g)].map((m) => m[1])] : []))
806
+ ];
807
+ var OWNED_BEHAVIOURS = [
808
+ {
809
+ id: "base-ui",
810
+ behaviour: "Is built on Base UI",
811
+ baseUi: Object.keys(BASE_UI_PARTS),
812
+ owners: uses(Object.values(BASE_UI_PARTS)),
813
+ reads: "an import from @base-ui/react (and the old @base-ui-components spelling)"
814
+ },
815
+ {
816
+ id: "portal",
817
+ behaviour: "Floats on top of the page",
818
+ baseUi: ["Dialog", "AlertDialog", "Popover", "Menu", "Select", "Combobox", "Autocomplete", "Tooltip", "PreviewCard", "Toast"],
819
+ owners: ["DialogShell", "ConfirmDialog", "CommandPalette", "Lightbox", "Popover", "Menu", "Select", "ChipInput", "Tooltip", "PreviewCard", "Toast"],
820
+ reads: "createPortal, called, or imported and never called"
821
+ },
822
+ {
823
+ id: "press-outside",
824
+ behaviour: "Closes on a press outside",
825
+ baseUi: ["Dialog", "AlertDialog", "Popover", "Menu", "Select", "Combobox", "Tooltip", "PreviewCard"],
826
+ owners: ["DialogShell", "Popover", "Menu", "Select", "PreviewCard"],
827
+ reads: "a mousedown, pointerdown, click or touchstart listener on window or document"
828
+ },
829
+ {
830
+ id: "page-keys",
831
+ behaviour: "Takes its keys by itself",
832
+ baseUi: ["Dialog", "AlertDialog", "Popover", "Menu", "Select", "Combobox", "Tooltip", "PreviewCard", "Toast"],
833
+ owners: ["DialogShell", "Lightbox", "Popover", "Menu", "Select", "Tabs", "Toolbar"],
834
+ reads: "a keydown, keyup or keypress listener on window or document"
835
+ },
836
+ {
837
+ id: "focus",
838
+ behaviour: "Holds focus inside while open, and gives it back",
839
+ baseUi: ["Dialog", "AlertDialog", "Popover", "Menu", "Select", "Combobox"],
840
+ owners: ["DialogShell", "CommandPalette", "Lightbox"],
841
+ reads: "a focusin or focusout listener on window or document; the Tab key compared by hand"
842
+ },
843
+ {
844
+ id: "scroll-lock",
845
+ behaviour: "Stops the page behind it scrolling",
846
+ baseUi: ["Dialog", "AlertDialog"],
847
+ owners: ["DialogShell", "Lightbox"],
848
+ reads: "overflow written into the style of document.body or document.documentElement"
849
+ },
850
+ {
851
+ id: "follow",
852
+ behaviour: "Stays attached to its anchor on scroll and resize",
853
+ baseUi: ["Popover", "Menu", "Select", "Combobox", "Tooltip", "PreviewCard", "Toast"],
854
+ owners: ["Popover", "Menu", "Select", "Tooltip", "PreviewCard"],
855
+ reads: "a scroll or resize listener on window or document"
856
+ },
857
+ {
858
+ id: "walking",
859
+ behaviour: "Moves through its items with the arrow keys",
860
+ baseUi: ["Menu", "Select", "Combobox", "Autocomplete", "Tabs", "Toolbar"],
861
+ owners: ["Menu", "Select", "ChipInput", "CommandPalette", "SuggestionMenu", "Tabs", "Toolbar"],
862
+ reads: `a key compared by hand with ${WALKING_KEYS.join(", ")}`
863
+ },
864
+ {
865
+ id: "role",
866
+ behaviour: "Says what it is to assistive technology",
867
+ baseUi: ["Dialog", "AlertDialog", "Menu", "Select", "Combobox", "Tabs", "Toolbar", "Progress", "Checkbox", "Separator", "Button"],
868
+ owners: uses(Object.values(ROLE_PARTS).map((r) => r.part)),
869
+ reads: `role written by hand: ${Object.keys(ROLE_PARTS).join(", ")}`
870
+ },
871
+ {
872
+ id: "tab-stop",
873
+ behaviour: "Is reachable with Tab",
874
+ baseUi: ["Button", "Toggle", "Checkbox", "Tabs", "Toolbar", "ScrollArea"],
875
+ owners: ["Button", "IconButton", "Link"],
876
+ reads: "tabIndex that can be 0 or more, on an element that is not a control"
877
+ },
878
+ {
879
+ id: "scroll",
880
+ behaviour: "Scrolls with our scrollbar",
881
+ baseUi: ["ScrollArea"],
882
+ owners: ["ScrollArea"],
883
+ reads: "overflow-auto or overflow-scroll (x or y, behind any variant) in a string, or overflow auto or scroll in a style"
815
884
  }
816
- return null;
817
- }
818
- function packagePartsFor(file, parser) {
819
- const dir = packageDirOf(file);
820
- if (!dir) return null;
821
- let name;
822
- try {
823
- name = JSON.parse(readFileSync(join(dir, "package.json"), "utf8")).name;
824
- } catch {
825
- return null;
885
+ ];
886
+ var PAGE_TARGETS = /* @__PURE__ */ new Set(["window", "document", "globalThis", "self", "document.body", "document.documentElement", "window.document"]);
887
+ function anchorOf(node) {
888
+ if (node.type === "FunctionDeclaration") {
889
+ return node.parent && /^Export/.test(node.parent.type) ? node.parent : node;
826
890
  }
827
- if (name !== PACKAGE) return null;
828
- const index = join(dir, "src", "index.ts");
829
- if (!existsSync2(index)) return null;
830
- const mtime = statSync(index).mtimeMs;
831
- const cached = packagePartsCache.get(index);
832
- if (cached && cached.mtime === mtime) return cached.parts;
833
- const parts = /* @__PURE__ */ new Set();
834
- const ast = parseFile(parser, index);
835
- for (const statement2 of ast ? children(ast, "body") : []) {
836
- if (statement2?.type !== "ExportNamedDeclaration" || statement2.exportKind === "type") continue;
837
- for (const specifier of children(statement2, "specifiers")) {
838
- const exported = nameOf(child(specifier, "exported"));
839
- if (specifier?.exportKind !== "type" && exported && /^[A-Z][a-z]/.test(exported)) parts.add(exported);
840
- }
891
+ let child5 = node;
892
+ for (let p = node.parent; p; child5 = p, p = p.parent) {
893
+ if (p.type === "JSXOpeningElement" || p.type === "Property" || p.type === "MethodDefinition" || p.type === "PropertyDefinition") return p;
894
+ if (p.type === "ArrayExpression") return child5;
895
+ if (p.type !== "BlockStatement" && /(Statement|Declaration)$/.test(p.type)) return p;
841
896
  }
842
- packagePartsCache.set(index, { mtime, parts });
843
- return parts;
844
- }
845
- function functionComponents(program) {
846
- const found = /* @__PURE__ */ new Map();
847
- const unwrap = (node) => {
848
- let current = node;
849
- while (current?.type === "CallExpression" && children(current, "arguments").length) {
850
- const callee = child(current, "callee");
851
- const text = callee?.type === "Identifier" ? nameOf(callee) : callee?.type === "MemberExpression" ? nameOf(child(callee, "property")) : void 0;
852
- if (text !== "forwardRef" && text !== "memo") return null;
853
- current = children(current, "arguments")[0];
854
- }
855
- return current?.type === "ArrowFunctionExpression" || current?.type === "FunctionExpression" ? current : null;
856
- };
857
- walk(program, (node) => {
858
- if (node.type === "FunctionDeclaration") {
859
- const name = nameOf(child(node, "id"));
860
- if (name && /^[A-Z]/.test(name)) found.set(name, node);
861
- } else if (node.type === "VariableDeclarator") {
862
- const name = nameOf(child(node, "id"));
863
- const fn = unwrap(child(node, "init"));
864
- if (name && /^[A-Z]/.test(name) && fn) found.set(name, fn);
865
- }
866
- });
867
- return found;
897
+ return node;
868
898
  }
869
- function moduleParts(file, program, parser, stack) {
870
- const locals = /* @__PURE__ */ new Map();
871
- const packageParts = packagePartsFor(file, parser);
872
- const body = children(program, "body");
873
- const exportsOf = (specifier) => {
874
- if (specifier === PACKAGE) return "package";
875
- const target = resolveModule(file, specifier);
876
- if (!target) return null;
877
- if (packageParts) return "package";
878
- return moduleExports(target, parser, stack);
879
- };
880
- for (const statement2 of body) {
881
- if (statement2?.type !== "ImportDeclaration" || statement2.importKind === "type") continue;
882
- const source = exportsOf(String(child(statement2, "source").value));
883
- if (!source) continue;
884
- for (const specifier of children(statement2, "specifiers")) {
885
- if (!specifier || specifier.importKind === "type") continue;
886
- const local = nameOf(child(specifier, "local"));
887
- if (!local) continue;
888
- if (specifier.type === "ImportNamespaceSpecifier") {
889
- if (source === "package" && !packageParts) locals.set(local, "namespace");
890
- continue;
891
- }
892
- const imported = specifier.type === "ImportDefaultSpecifier" ? "default" : nameOf(child(specifier, "imported"));
893
- if (!imported) continue;
894
- if (source === "package") {
895
- const isPart2 = packageParts ? packageParts.has(imported) : /^[A-Z]/.test(imported);
896
- if (isPart2) locals.set(local, { part: imported, props: "all" });
897
- } else if (source.has(imported)) locals.set(local, source.get(imported));
898
- }
899
- }
900
- const components = functionComponents(program);
901
- if (packageParts) {
902
- for (const name of components.keys()) if (packageParts.has(name) && !locals.has(name)) locals.set(name, { part: name, props: "all" });
903
- }
904
- if (!packageParts) {
905
- let changed = true;
906
- for (let round = 0; changed && round < 10; round += 1) {
907
- changed = false;
908
- for (const [name, fn] of components) {
909
- const binding = handsOnTo(fn, (tag) => bindingOfTag(tag, locals));
910
- if (!binding) continue;
911
- const next = { ...binding, via: name };
912
- const previous = locals.get(name);
913
- if (!previous || JSON.stringify(previous) !== JSON.stringify(next)) {
914
- if (previous && previous !== "namespace" && !previous.via) continue;
915
- locals.set(name, next);
916
- changed = true;
917
- }
918
- }
919
- }
920
- }
921
- const exports = /* @__PURE__ */ new Map();
922
- const localBinding = (name) => {
923
- const binding = name ? locals.get(name) : void 0;
924
- return binding && binding !== "namespace" ? binding : void 0;
925
- };
926
- for (const statement2 of body) {
927
- if (!statement2) continue;
928
- if (statement2.type === "ExportNamedDeclaration") {
929
- const declaration = child(statement2, "declaration");
930
- if (declaration?.type === "FunctionDeclaration") {
931
- const name = nameOf(child(declaration, "id"));
932
- const binding = localBinding(name);
933
- if (name && binding) exports.set(name, binding);
934
- } else if (declaration?.type === "VariableDeclaration") {
935
- for (const declarator of children(declaration, "declarations")) {
936
- const name = nameOf(child(declarator, "id"));
937
- const init = child(declarator, "init");
938
- const binding = localBinding(name) ?? (init?.type === "Identifier" ? localBinding(nameOf(init)) : void 0);
939
- if (name && binding) exports.set(name, binding);
940
- }
941
- }
942
- const source = child(statement2, "source");
943
- const from = source ? exportsOf(String(source.value)) : null;
944
- for (const specifier of children(statement2, "specifiers")) {
945
- if (!specifier || specifier.exportKind === "type") continue;
946
- const local = nameOf(child(specifier, "local"));
947
- const exported = nameOf(child(specifier, "exported"));
948
- if (!local || !exported) continue;
949
- if (!source) {
950
- const binding = localBinding(local);
951
- if (binding) exports.set(exported, binding);
952
- } else if (from === "package") {
953
- if (/^[A-Z]/.test(local)) exports.set(exported, { part: local, props: "all" });
954
- } else if (from?.has(local)) exports.set(exported, from.get(local));
955
- }
956
- } else if (statement2.type === "ExportAllDeclaration" && !child(statement2, "exported")) {
957
- const from = exportsOf(String(child(statement2, "source").value));
958
- if (from && from !== "package") for (const [name, binding] of from) exports.set(name, binding);
959
- } else if (statement2.type === "ExportDefaultDeclaration") {
960
- const declaration = child(statement2, "declaration");
961
- const name = declaration?.type === "Identifier" ? nameOf(declaration) : nameOf(child(declaration, "id"));
962
- const binding = localBinding(name);
963
- if (binding) exports.set("default", binding);
964
- }
899
+ function enclosingFunction(node) {
900
+ for (let p = node.parent; p; p = p.parent) {
901
+ if (p.type === "FunctionDeclaration" || p.type === "FunctionExpression" || p.type === "ArrowFunctionExpression") return p;
965
902
  }
966
- return { locals, exports };
903
+ return void 0;
967
904
  }
968
- function partsOfFile(file, program, parser) {
969
- return moduleParts(file, program, parser, /* @__PURE__ */ new Set([file])).locals;
905
+ function stringOf(node) {
906
+ if (!node) return void 0;
907
+ if (node.type === "Literal" && typeof node.value === "string") return node.value;
908
+ const quasis = node.quasis;
909
+ const expressions = node.expressions;
910
+ if (node.type === "TemplateLiteral" && expressions?.length === 0) return quasis?.[0]?.value.cooked ?? void 0;
911
+ return void 0;
970
912
  }
971
- function moduleExports(file, parser, stack) {
972
- const mtime = statSync(file).mtimeMs;
973
- const cached = moduleCache.get(file);
974
- if (cached && cached.mtime === mtime) return cached.exports;
975
- if (stack.has(file)) return /* @__PURE__ */ new Map();
976
- stack.add(file);
977
- const program = parseFile(parser, file);
978
- const exports = program ? moduleParts(file, program, parser, stack).exports : /* @__PURE__ */ new Map();
979
- stack.delete(file);
980
- moduleCache.set(file, { mtime, exports });
981
- return exports;
913
+ function stringsOf(node) {
914
+ if (!node) return [];
915
+ if (node.type === "JSXExpressionContainer") return stringsOf(node.expression);
916
+ const s = stringOf(node);
917
+ if (s !== void 0) return [s];
918
+ if (node.type === "ConditionalExpression") return [...stringsOf(node.consequent), ...stringsOf(node.alternate)];
919
+ if (node.type === "LogicalExpression") return [...stringsOf(node.left), ...stringsOf(node.right)];
920
+ return [];
982
921
  }
983
- function bindingOfTag(tag, locals) {
984
- if (!tag) return void 0;
985
- if (tag.type === "JSXIdentifier") {
986
- const binding = locals.get(tag.name);
987
- return binding && binding !== "namespace" ? binding : void 0;
922
+ function canBeTabStop(node) {
923
+ if (!node) return false;
924
+ if (node.type === "JSXExpressionContainer") return canBeTabStop(node.expression);
925
+ if (node.type === "Literal") {
926
+ if (typeof node.value === "number") return node.value >= 0;
927
+ if (typeof node.value === "string") return /^\s*\d+\s*$/.test(node.value);
928
+ return false;
988
929
  }
989
- if (tag.type === "JSXMemberExpression") {
990
- const object = child(tag, "object");
991
- const property = nameOf(child(tag, "property"));
992
- if (object?.type === "JSXIdentifier" && locals.get(object.name) === "namespace" && property) return { part: property, props: "all" };
930
+ if (node.type === "ConditionalExpression") return canBeTabStop(node.consequent) || canBeTabStop(node.alternate);
931
+ if (node.type === "LogicalExpression") return canBeTabStop(node.left) || canBeTabStop(node.right);
932
+ if (node.type === "TSAsExpression" || node.type === "TSNonNullExpression") return canBeTabStop(node.expression);
933
+ return false;
934
+ }
935
+ function utilityOf(token) {
936
+ let depth = 0;
937
+ let last = -1;
938
+ for (let i = 0; i < token.length; i++) {
939
+ const c = token[i];
940
+ if (c === "[") depth++;
941
+ else if (c === "]") depth--;
942
+ else if (c === ":" && depth === 0) last = i;
993
943
  }
994
- return void 0;
944
+ return token.slice(last + 1).replace(/^!/, "").replace(/!$/, "");
995
945
  }
996
- function handsOnTo(fn, bindingOf) {
997
- const param = children(fn, "params")[0];
998
- if (!param) return void 0;
999
- let restName;
1000
- let propsName;
1001
- const classParams = /* @__PURE__ */ new Map();
1002
- if (param.type === "ObjectPattern") {
1003
- for (const property of children(param, "properties")) {
1004
- if (!property) continue;
1005
- if (property.type === "RestElement") restName = nameOf(child(property, "argument"));
1006
- else if (property.type === "Property") {
1007
- const key = nameOf(child(property, "key"));
1008
- let value = child(property, "value");
1009
- if (value?.type === "AssignmentPattern") value = child(value, "left");
1010
- const local = nameOf(value);
1011
- if (key && local && CLASS_PROP.test(key)) classParams.set(local, key);
1012
- }
946
+ function baseUiModule(source) {
947
+ const m = /^@base-ui(?:-components)?\/([^/]+)(?:\/(.+))?$/.exec(source);
948
+ if (!m) return void 0;
949
+ const [, pkg, sub] = m;
950
+ return pkg === "react" ? sub ?? "" : `${pkg}${sub ? `/${sub}` : ""}`;
951
+ }
952
+ function isKeySubject(node) {
953
+ if (!node) return false;
954
+ if (node.type === "Identifier") return node.name === "key" || node.name === "code";
955
+ if (node.type !== "MemberExpression" || node.computed) return false;
956
+ const property = node.property;
957
+ return property.type === "Identifier" && (property.name === "key" || property.name === "code");
958
+ }
959
+ function pageTarget(node, text) {
960
+ return (node.type === "Identifier" || node.type === "MemberExpression") && PAGE_TARGETS.has(text);
961
+ }
962
+ var noRebuiltBehaviour = {
963
+ meta: {
964
+ type: "problem",
965
+ docs: { description: "Behaviour @estiva-app/ui already owns, rebuilt by hand in an app" },
966
+ schema: [],
967
+ messages: {
968
+ baseUi: "Only @estiva-app/ui imports Base UI (`{{module}}`). Use `{{use}}` from @estiva-app/ui.{{more}}",
969
+ 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.",
970
+ 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`.",
971
+ 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.",
972
+ 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.",
973
+ focus: "A `{{event}}` listener on `{{target}}`: focus held by hand. `DialogShell` and `CommandPalette` from @estiva-app/ui keep focus inside and give it back.",
974
+ 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.",
975
+ 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.",
976
+ walking: "Arrow keys handled by hand (`{{key}}`). `Menu`, `Select`, `ChipInput`, `CommandPalette`, `Tabs` and `Toolbar` from @estiva-app/ui move through their items themselves.",
977
+ tabKey: "The Tab key handled by hand. `DialogShell` and `CommandPalette` from @estiva-app/ui keep focus inside themselves.",
978
+ role: 'A hand-written `role="{{role}}"` is a hand-made {{thing}}. Use `{{use}}` from @estiva-app/ui.{{more}}',
979
+ 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.',
980
+ tabStop: "`tabIndex={{value}}` makes a `<{{element}}>` a Tab stop by hand. Use `Button`, `IconButton` or `Link` from @estiva-app/ui, which are reachable already.",
981
+ scrollClass: "`{{token}}` scrolls with the browser's scrollbar. Use `ScrollArea` from @estiva-app/ui, which draws ours.",
982
+ scrollStyle: "`{{style}}` scrolls with the browser's scrollbar. Use `ScrollArea` from @estiva-app/ui, which draws ours.",
983
+ ...ESCAPE_MESSAGES
1013
984
  }
1014
- } else if (param.type === "Identifier") propsName = nameOf(param);
1015
- let wrapper;
1016
- const forwarded = { props: {} };
1017
- const body = child(fn, "body");
1018
- if (!body) return void 0;
1019
- walk(body, (node) => {
1020
- if (wrapper || node.type !== "JSXOpeningElement") return;
1021
- const binding = bindingOf(child(node, "name"));
1022
- if (!binding) return;
1023
- for (const attribute3 of children(node, "attributes")) {
1024
- if (!attribute3) continue;
1025
- if (attribute3.type === "JSXSpreadAttribute") {
1026
- const argument = nameOf(child(attribute3, "argument"));
1027
- if (argument && (argument === restName || argument === propsName)) wrapper = { part: binding.part, props: binding.props };
1028
- continue;
985
+ },
986
+ create(context) {
987
+ const { sourceCode } = context;
988
+ const text = (node) => sourceCode.getText(node);
989
+ const escapes = /* @__PURE__ */ new Map();
990
+ const escaped = (anchor) => {
991
+ if (!escapes.has(anchor)) escapes.set(anchor, isEscaped(context, anchor));
992
+ return escapes.get(anchor) === true;
993
+ };
994
+ const seen = /* @__PURE__ */ new Set();
995
+ const report = (anchor, at, messageId, data = {}, once = `${at.range[0]}`) => {
996
+ const key = `${anchor.range[0]}|${messageId}|${once}`;
997
+ if (seen.has(key)) return;
998
+ seen.add(key);
999
+ if (escaped(anchor)) return;
1000
+ context.report({ loc: at.loc, messageId, data });
1001
+ };
1002
+ const importSource = (node, source) => {
1003
+ const value = stringOf(source);
1004
+ if (value === void 0) return;
1005
+ const module = baseUiModule(value);
1006
+ if (module === void 0) return;
1007
+ const part = Object.hasOwn(BASE_UI_PARTS, module) ? BASE_UI_PARTS[module] : null;
1008
+ const anchor = anchorOf(node);
1009
+ if (part) report(anchor, node, "baseUi", { module: value, use: part.use, more: part.more ?? "" });
1010
+ else report(anchor, node, "baseUiNoPart", { module: value });
1011
+ };
1012
+ const keyCompared = (node, key) => {
1013
+ if (key === void 0) return;
1014
+ const fn = enclosingFunction(node);
1015
+ const anchor = anchorOf(fn ?? node);
1016
+ if (WALKING_KEYS.includes(key)) report(anchor, node, "walking", { key }, `walking@${fn?.range[0] ?? node.range[0]}`);
1017
+ else if (key === "Tab") report(anchor, node, "tabKey", {}, `tab@${fn?.range[0] ?? node.range[0]}`);
1018
+ };
1019
+ const classTokens = (node, value) => {
1020
+ for (const token of value.split(/\s+/)) {
1021
+ if (token && SCROLL_CLASS.test(utilityOf(token))) report(anchorOf(node), node, "scrollClass", { token }, `class@${token}`);
1029
1022
  }
1030
- const prop = nameOf(child(attribute3, "name"));
1031
- if (!prop || !CLASS_PROP.test(prop)) continue;
1032
- const partProp = binding.props === "all" ? prop : binding.props[prop];
1033
- if (!partProp) continue;
1034
- walk(attribute3, (inner) => {
1035
- let callerProp;
1036
- if (inner.type === "Identifier") callerProp = classParams.get(inner.name);
1037
- if (inner.type === "MemberExpression" && nameOf(child(inner, "object")) === propsName) {
1038
- const key = nameOf(child(inner, "property"));
1039
- if (key && CLASS_PROP.test(key)) callerProp = key;
1023
+ };
1024
+ const portalImports = /* @__PURE__ */ new Map();
1025
+ let portalCalled = false;
1026
+ return {
1027
+ ImportDeclaration(ruleNode) {
1028
+ const node = ruleNode;
1029
+ importSource(node, node.source);
1030
+ if (stringOf(node.source) !== "react-dom") return;
1031
+ for (const specifier of node.specifiers) {
1032
+ const imported = specifier.imported;
1033
+ if (specifier.type === "ImportSpecifier" && imported?.name === "createPortal") portalImports.set(specifier.local.name, node);
1040
1034
  }
1041
- if (!callerProp) return;
1042
- if (forwarded.part && forwarded.part !== binding.part) return;
1043
- forwarded.part = binding.part;
1044
- forwarded.props[callerProp] = partProp;
1045
- });
1046
- }
1047
- });
1048
- if (wrapper) return wrapper;
1049
- return forwarded.part ? { part: forwarded.part, props: forwarded.props } : void 0;
1050
- }
1051
- var CLASS_FUNCTIONS = /* @__PURE__ */ new Set(["cn", "clsx", "cx", "twMerge", "classNames"]);
1052
- function constantOf(identifier, scope) {
1053
- let current = scope;
1054
- while (current) {
1055
- const variable = current.set.get(identifier.name);
1056
- if (variable) {
1057
- const definition = variable.defs[0];
1058
- if (variable.defs.length !== 1 || definition?.type !== "Variable") return void 0;
1059
- if (definition.parent?.kind !== "const") return void 0;
1060
- return child(definition.node, "init") ?? void 0;
1061
- }
1062
- current = current.upper;
1035
+ },
1036
+ ExportNamedDeclaration(ruleNode) {
1037
+ const node = ruleNode;
1038
+ if (node.source) importSource(node, node.source);
1039
+ },
1040
+ ExportAllDeclaration(ruleNode) {
1041
+ const node = ruleNode;
1042
+ importSource(node, node.source);
1043
+ },
1044
+ ImportExpression(ruleNode) {
1045
+ const node = ruleNode;
1046
+ importSource(node, node.source);
1047
+ },
1048
+ CallExpression(ruleNode) {
1049
+ const node = ruleNode;
1050
+ const callee = node.callee;
1051
+ const args = node.arguments;
1052
+ if (callee.type === "Identifier" && callee.name === "require") importSource(node, args[0]);
1053
+ if (callee.type === "Identifier" && portalImports.has(callee.name)) {
1054
+ portalCalled = true;
1055
+ report(anchorOf(node), node, "portal");
1056
+ }
1057
+ if (callee.type !== "MemberExpression") return;
1058
+ const object = callee.object;
1059
+ const property = callee.property;
1060
+ if (property.type !== "Identifier") return;
1061
+ if (property.name === "createPortal") {
1062
+ report(anchorOf(node), node, "portal");
1063
+ return;
1064
+ }
1065
+ if (property.name === "addEventListener") {
1066
+ const target = text(object);
1067
+ if (!pageTarget(object, target)) return;
1068
+ const event = stringOf(args[0]);
1069
+ const group = event === void 0 ? void 0 : PAGE_EVENTS[event];
1070
+ if (!event || !group) return;
1071
+ report(anchorOf(node), node, group, { event, target });
1072
+ return;
1073
+ }
1074
+ if (property.name === "includes" && object.type === "ArrayExpression" && isKeySubject(args[0])) {
1075
+ for (const element of object.elements) keyCompared(node, stringOf(element));
1076
+ }
1077
+ },
1078
+ AssignmentExpression(ruleNode) {
1079
+ const node = ruleNode;
1080
+ const left = node.left;
1081
+ if (left.type !== "MemberExpression") return;
1082
+ const property = left.property;
1083
+ const object = left.object;
1084
+ const handler = property.type === "Identifier" ? /^on([a-z]+)$/.exec(property.name) : null;
1085
+ if (handler && pageTarget(object, text(object)) && PAGE_EVENTS[handler[1]]) {
1086
+ report(anchorOf(node), node, PAGE_EVENTS[handler[1]], { event: handler[1], target: text(object) });
1087
+ return;
1088
+ }
1089
+ if (/^document\.(?:body|documentElement)\.style\.overflow[XY]?$/.test(text(left))) report(anchorOf(node), node, "scrollLock");
1090
+ },
1091
+ BinaryExpression(ruleNode) {
1092
+ const node = ruleNode;
1093
+ if (!["===", "==", "!==", "!="].includes(node.operator)) return;
1094
+ const left = node.left;
1095
+ const right = node.right;
1096
+ if (isKeySubject(left)) keyCompared(node, stringOf(right));
1097
+ else if (isKeySubject(right)) keyCompared(node, stringOf(left));
1098
+ },
1099
+ SwitchCase(ruleNode) {
1100
+ const node = ruleNode;
1101
+ const statement2 = node.parent;
1102
+ if (node.test && isKeySubject(statement2.discriminant)) keyCompared(node, stringOf(node.test));
1103
+ },
1104
+ JSXAttribute(ruleNode) {
1105
+ const node = ruleNode;
1106
+ const nameNode = node.name;
1107
+ if (nameNode.type !== "JSXIdentifier") return;
1108
+ const name = nameNode.name;
1109
+ const element = node.parent;
1110
+ const value = node.value;
1111
+ if (name === "role") {
1112
+ for (const role of stringsOf(value).flatMap((v) => v.trim().split(/\s+/))) {
1113
+ if (!Object.hasOwn(ROLE_PARTS, role)) continue;
1114
+ const { thing, part } = ROLE_PARTS[role];
1115
+ if (part) report(element, node, "role", { role, thing, use: part.use, more: part.more ?? "" });
1116
+ else report(element, node, "roleNoPart", { role, thing });
1117
+ return;
1118
+ }
1119
+ return;
1120
+ }
1121
+ if (name === "tabIndex" || name === "tabindex") {
1122
+ const tag = element.name;
1123
+ if (tag.type !== "JSXIdentifier" || !/^[a-z]/.test(tag.name) || INTERACTIVE_ELEMENTS.has(tag.name)) return;
1124
+ const attributes = element.attributes;
1125
+ const editable = attributes.some((a) => a.type === "JSXAttribute" && /^contenteditable$/i.test(a.name.name ?? ""));
1126
+ if (editable || !canBeTabStop(value)) return;
1127
+ report(element, node, "tabStop", { value: value ? text(value).replace(/^\{|\}$/g, "") : "", element: tag.name });
1128
+ return;
1129
+ }
1130
+ if (name === "style" && value?.type === "JSXExpressionContainer") {
1131
+ const object = value.expression;
1132
+ if (object.type !== "ObjectExpression") return;
1133
+ for (const property of object.properties) {
1134
+ if (property.type !== "Property") continue;
1135
+ const key = property.key;
1136
+ const keyName = key.type === "Identifier" ? key.name : stringOf(key);
1137
+ if (!keyName || !/^overflow[XY]?$/.test(keyName)) continue;
1138
+ const setting = stringOf(property.value);
1139
+ if (setting === "auto" || setting === "scroll") report(element, property, "scrollStyle", { style: `${keyName}: '${setting}'` }, `style@${keyName}`);
1140
+ }
1141
+ }
1142
+ },
1143
+ Literal(ruleNode) {
1144
+ const node = ruleNode;
1145
+ if (typeof node.value !== "string") return;
1146
+ const parent = node.parent;
1147
+ if (parent && /^(Import|Export)/.test(parent.type)) return;
1148
+ if (parent?.type === "TSLiteralType" || parent?.type === "TSExternalModuleReference") return;
1149
+ classTokens(node, node.value);
1150
+ },
1151
+ TemplateElement(ruleNode) {
1152
+ const node = ruleNode;
1153
+ const cooked = node.value.cooked;
1154
+ if (cooked && node.parent) classTokens(node.parent, cooked);
1155
+ },
1156
+ "Program:exit"() {
1157
+ if (portalCalled) return;
1158
+ for (const declaration of new Set(portalImports.values())) report(anchorOf(declaration), declaration, "portal");
1159
+ }
1160
+ };
1063
1161
  }
1064
- return void 0;
1065
- }
1066
- function classesOf(value, scopeOf, asMap = false, seen = /* @__PURE__ */ new Set()) {
1067
- if (!value || seen.has(value) || seen.size > 200) return [];
1068
- seen.add(value);
1069
- const read = (node, map = false) => classesOf(node, scopeOf, map, seen);
1070
- const words2 = (text) => typeof text === "string" ? text.split(/\s+/).filter(Boolean) : [];
1071
- switch (value.type) {
1072
- case "Literal":
1073
- return words2(value.value);
1074
- case "TemplateLiteral":
1075
- return [...children(value, "quasis").flatMap((quasi) => words2((quasi?.value).cooked)), ...children(value, "expressions").flatMap((e) => read(e))];
1076
- case "JSXExpressionContainer":
1077
- case "TSAsExpression":
1078
- case "TSSatisfiesExpression":
1079
- case "TSNonNullExpression":
1080
- case "ChainExpression":
1081
- return read(child(value, "expression"), asMap);
1082
- case "ConditionalExpression":
1083
- return [...read(child(value, "consequent")), ...read(child(value, "alternate"))];
1084
- case "LogicalExpression":
1085
- return value.operator === "&&" ? read(child(value, "right")) : [...read(child(value, "left")), ...read(child(value, "right"))];
1086
- case "BinaryExpression":
1087
- return value.operator === "+" ? [...read(child(value, "left")), ...read(child(value, "right"))] : [];
1088
- case "ArrayExpression":
1089
- return children(value, "elements").flatMap((e) => read(e));
1090
- case "ObjectExpression":
1091
- return children(value, "properties").flatMap((property) => {
1092
- if (property?.type !== "Property") return [];
1093
- return asMap ? read(child(property, "value"), true) : property.computed ? [] : words2(nameOf(child(property, "key")));
1094
- });
1095
- case "CallExpression": {
1096
- const callee = child(value, "callee");
1097
- return callee?.type === "Identifier" && CLASS_FUNCTIONS.has(callee.name) ? children(value, "arguments").flatMap((a) => read(a)) : [];
1098
- }
1099
- case "Identifier": {
1100
- const constant = constantOf(value, scopeOf(value));
1101
- return constant ? read(constant, asMap) : [];
1102
- }
1103
- case "MemberExpression": {
1104
- const object = child(value, "object");
1105
- const target = object?.type === "Identifier" ? constantOf(object, scopeOf(object)) : object;
1106
- const map = target?.type === "TSAsExpression" || target?.type === "TSSatisfiesExpression" ? child(target, "expression") : target;
1107
- if (map?.type !== "ObjectExpression") return [];
1108
- const property = child(value, "property");
1109
- const key = value.computed ? property?.type === "Literal" ? String(property.value) : void 0 : nameOf(property);
1110
- return children(map, "properties").flatMap((entry) => {
1111
- if (entry?.type !== "Property") return [];
1112
- if (key !== void 0 && nameOf(child(entry, "key")) !== key) return [];
1113
- return read(child(entry, "value"), true);
1114
- });
1115
- }
1116
- default:
1117
- return [];
1162
+ };
1163
+
1164
+ // src/eslint/no-hand-rolled-behaviour.ts
1165
+ var FLOATING_EVENTS = /* @__PURE__ */ new Set(["resize", "scroll", "mousedown", "pointerdown", "keydown", "keyup", "focusin", "focusout", "click"]);
1166
+ function statement(node) {
1167
+ for (let p = node.parent; p; p = p.parent) {
1168
+ if (!/(Statement|Declaration)$/.test(p.type)) continue;
1169
+ if (p.loc && p.range) return { loc: p.loc, range: p.range };
1170
+ break;
1118
1171
  }
1172
+ return { loc: node.loc, range: node.range };
1119
1173
  }
1120
- var code = (items) => items.map((item) => `\`${item}\``).join(" ");
1121
- var or = (items) => items.length === 1 ? code(items) : `${items.slice(0, -1).map((i) => `\`${i}\``).join(", ")} or \`${items[items.length - 1]}\``;
1122
- var noRestyledPart = {
1174
+ var noHandRolledBehaviour = {
1123
1175
  meta: {
1124
1176
  type: "problem",
1125
- docs: { description: "Only placement passes into a part of @estiva-app/ui through a class prop" },
1177
+ docs: { description: "Overlay behaviour written by hand where Base UI has a part (D6)" },
1126
1178
  schema: [],
1127
1179
  messages: {
1128
- restyled: "{{classes}} on {{where}} changes how it looks. A part of @estiva-app/ui is placed from outside, never restyled: only space, size, flex and grid, and position pass in.{{use}} A look for what is around it goes on your own element around it.",
1129
- restyledStyle: "{{keys}} in the `style` of {{where}} changes how it looks. A part of @estiva-app/ui is placed from outside, never restyled, by class or by style: only space, size, flex and grid, and position pass in.{{use}} A look for what is around it goes on your own element around it.",
1130
- emptyStatePadding: "{{classes}} pads {{where}}. EmptyState takes no padding (Katerina, 14 September): its room comes from the box its rows live in, so put the padding on that box.",
1131
- formLayout: '{{classes}} lays out the fields of {{where}}. A Form places its own fields, 24px apart (Katerina, 28 September), so every form reads the same: remove it. A form that is not a list of fields (a field and its button, a composer) says `layout="free"` and lays itself out.',
1132
- formSpacedFromOutside: "{{classes}} on the box around `Form` spaces the form from what is beside it, so the gap above its first field is not the form\u2019s 24px. Put what is beside it inside the `Form`, as one block before the fields, and drop the box: the Form puts 24px between them (Katerina, 1 October; MoveDialog in Peek does this).",
1180
+ 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.",
1181
+ 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.",
1182
+ 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.",
1133
1183
  ...ESCAPE_MESSAGES
1134
1184
  }
1135
1185
  },
1136
1186
  create(context) {
1137
- const parser = context.languageOptions?.parser ?? {};
1138
- const file = context.filename;
1139
- const sourceCode = context.sourceCode;
1140
- const scopeOf = (node) => sourceCode.getScope(node);
1141
- let locals;
1142
- const escapes = /* @__PURE__ */ new Map();
1143
- const escaped = (anchor) => {
1144
- if (!escapes.has(anchor)) escapes.set(anchor, isEscaped(context, anchor));
1145
- return escapes.get(anchor) === true;
1146
- };
1147
- const placesItsFields = (element) => !children(element, "attributes").some((attribute3) => {
1148
- if (attribute3?.type !== "JSXAttribute" || nameOf(child(attribute3, "name")) !== "layout") return false;
1149
- const value = child(attribute3, "value");
1150
- const literal2 = value?.type === "JSXExpressionContainer" ? child(value, "expression") : value;
1151
- return !(literal2?.type === "Literal" && literal2.value === "fields");
1152
- });
1153
- const check = (element, binding, prop, value, at) => {
1154
- const partProp = binding.props === "all" ? prop : binding.props[prop];
1155
- if (!partProp || !value) return;
1156
- const classes = classesOf(value, scopeOf);
1157
- const handedOn = binding.props === "all" ? "its props" : `its \`${prop}\``;
1158
- const via = binding.via && binding.via !== binding.part ? `\`${binding.via}\` (it hands ${handedOn} to \`${binding.part}\`)` : `\`${binding.part}\``;
1159
- const where = `${via}${partProp === "className" ? "" : `'s \`${partProp}\``}`;
1160
- const restyled = [...new Set(classes.filter((token) => !isPlacement(token)))];
1161
- const padding = binding.part === "EmptyState" && binding.props === "all" ? [...new Set(classes.filter(isPadding))] : [];
1162
- const layout = binding.part === "Form" && partProp === "className" && placesItsFields(element) ? [...new Set(classes.filter(isFieldsLayout))] : [];
1163
- if (!restyled.length && !padding.length && !layout.length) return;
1164
- if (escaped(element)) return;
1165
- if (restyled.length) {
1166
- const props = PART_LOOK_PROPS[binding.part];
1167
- const use = props ? ` Use its ${or(props)}.` : ` \`${binding.part}\` has no prop for this yet: ask Katerina, and it gets made in @estiva-app/ui.`;
1168
- context.report({ loc: at.loc, messageId: "restyled", data: { classes: code(restyled), where, use } });
1187
+ const reported = /* @__PURE__ */ new Set();
1188
+ const scroll = (node, what) => {
1189
+ let at = statement(node);
1190
+ for (let p = node.parent; p; p = p.parent) {
1191
+ if (p.range?.[0] === at.range[0] && p.range?.[1] === at.range[1]) {
1192
+ if (p.parent && /^Export/.test(p.parent.type) && p.parent.loc && p.parent.range) at = { loc: p.parent.loc, range: p.parent.range };
1193
+ break;
1194
+ }
1169
1195
  }
1170
- if (padding.length) context.report({ loc: at.loc, messageId: "emptyStatePadding", data: { classes: code(padding), where } });
1171
- if (layout.length) context.report({ loc: at.loc, messageId: "formLayout", data: { classes: code(layout), where } });
1172
- };
1173
- const checkStyle = (element, binding, value, at) => {
1174
- if (binding.props !== "all" || value?.type !== "JSXExpressionContainer") return;
1175
- let object = child(value, "expression");
1176
- if (object?.type === "Identifier") object = constantOf(object, scopeOf(object));
1177
- while (object?.type === "TSAsExpression" || object?.type === "TSSatisfiesExpression") object = child(object, "expression");
1178
- if (object?.type !== "ObjectExpression") return;
1179
- const keys = children(object, "properties").map((property) => property?.type === "Property" && !property.computed ? nameOf(child(property, "key")) : void 0).filter((key) => !!key && !key.startsWith("--") && !PLACEMENT_STYLE.test(key));
1180
- if (!keys.length || escaped(element)) return;
1181
- const props = PART_LOOK_PROPS[binding.part];
1182
- const use = props ? ` Use its ${or(props)}.` : ` \`${binding.part}\` has no prop for this yet: ask Katerina, and it gets made in @estiva-app/ui.`;
1183
- const where = binding.via && binding.via !== binding.part ? `\`${binding.via}\` (it hands its props to \`${binding.part}\`)` : `\`${binding.part}\``;
1184
- context.report({ loc: at.loc, messageId: "restyledStyle", data: { keys: code([...new Set(keys)]), where, use } });
1196
+ const key = `${at.range[0]}:${what}`;
1197
+ if (reported.has(key) || isEscaped(context, at)) return;
1198
+ reported.add(key);
1199
+ context.report({ loc: node.loc, messageId: "scroll", data: { what } });
1185
1200
  };
1186
- const checkSpacedFromOutside = (opening) => {
1187
- const form = opening.parent;
1188
- const box = form?.parent;
1189
- if (form?.type !== "JSXElement" || box?.type !== "JSXElement") return;
1190
- const beside = children(box, "children").filter((node) => {
1191
- if (!node || node === form) return false;
1192
- if (node.type === "JSXText") return String(node.value).trim() !== "";
1193
- if (node.type === "JSXExpressionContainer") return child(node, "expression")?.type !== "JSXEmptyExpression";
1194
- return true;
1195
- });
1196
- if (!beside.length) return;
1197
- const boxOpening = child(box, "openingElement");
1198
- const spacing = children(boxOpening, "attributes").flatMap((attribute3) => {
1199
- if (attribute3?.type !== "JSXAttribute") return [];
1200
- const prop = nameOf(child(attribute3, "name"));
1201
- return prop === "className" || prop === "bodyClassName" ? classesOf(child(attribute3, "value"), scopeOf).filter(isSpacing) : [];
1202
- });
1203
- if (!spacing.length || escaped(opening)) return;
1204
- context.report({ loc: opening.loc, messageId: "formSpacedFromOutside", data: { classes: code([...new Set(spacing)]) } });
1201
+ const classTokens = (node, value) => {
1202
+ for (const token of value.split(/\s+/)) if (token && SCROLL_CLASS.test(utilityOf(token))) scroll(node, token);
1205
1203
  };
1206
1204
  return {
1207
- Program(program) {
1208
- locals = moduleParts(file, program, parser, /* @__PURE__ */ new Set([file])).locals;
1205
+ Literal(node) {
1206
+ const literal2 = node;
1207
+ if (typeof literal2.value !== "string") return;
1208
+ if (literal2.parent && /^(Import|Export)|^TSLiteralType$|^TSExternalModuleReference$/.test(literal2.parent.type)) return;
1209
+ classTokens(node, literal2.value);
1209
1210
  },
1210
- JSXOpeningElement(ruleNode) {
1211
- const element = ruleNode;
1212
- const binding = locals && bindingOfTag(child(element, "name"), locals);
1213
- if (!binding) return;
1214
- if (binding.part === "Form" && binding.props === "all" && placesItsFields(element)) checkSpacedFromOutside(element);
1215
- for (const attribute3 of children(element, "attributes")) {
1216
- if (!attribute3) continue;
1217
- if (attribute3.type === "JSXAttribute") {
1218
- const prop = nameOf(child(attribute3, "name"));
1219
- if (prop && CLASS_PROP.test(prop)) check(element, binding, prop, child(attribute3, "value"), attribute3);
1220
- else if (prop === "style") checkStyle(element, binding, child(attribute3, "value"), attribute3);
1221
- continue;
1222
- }
1223
- let spread = child(attribute3, "argument");
1224
- if (spread?.type === "Identifier") spread = constantOf(spread, scopeOf(spread));
1225
- while (spread?.type === "TSAsExpression" || spread?.type === "TSSatisfiesExpression") spread = child(spread, "expression");
1226
- if (spread?.type !== "ObjectExpression") continue;
1227
- for (const property of children(spread, "properties")) {
1228
- const key = property?.type === "Property" && !property.computed ? nameOf(child(property, "key")) : void 0;
1229
- if (key && CLASS_PROP.test(key)) check(element, binding, key, child(property, "value"), property);
1230
- }
1211
+ TemplateElement(node) {
1212
+ const cooked = node.value.cooked;
1213
+ if (cooked) classTokens(node, cooked);
1214
+ },
1215
+ Property(node) {
1216
+ const property = node;
1217
+ const name = property.key.type === "Identifier" ? property.key.name : typeof property.key.value === "string" ? property.key.value : void 0;
1218
+ if (!name || !/^overflow[XY]?$/.test(name)) return;
1219
+ const setting = property.value.type === "Literal" ? property.value.value : void 0;
1220
+ if (setting === "auto" || setting === "scroll") scroll(node, `${name}: '${setting}'`);
1221
+ },
1222
+ ImportDeclaration(node) {
1223
+ const declaration = node;
1224
+ if (declaration.source.value !== "react-dom") return;
1225
+ for (const specifier of declaration.specifiers) {
1226
+ if (specifier.type !== "ImportSpecifier" || specifier.imported?.name !== "createPortal") continue;
1227
+ if (isEscaped(context, declaration)) return;
1228
+ context.report({ loc: declaration.loc, messageId: "portal" });
1229
+ return;
1230
+ }
1231
+ },
1232
+ CallExpression(node) {
1233
+ const call = node;
1234
+ const { callee } = call;
1235
+ if (callee.type === "Identifier" && callee.name === "createPortal") {
1236
+ if (isEscaped(context, statement(call))) return;
1237
+ context.report({ loc: call.loc, messageId: "portal" });
1238
+ return;
1231
1239
  }
1240
+ if (callee.type !== "MemberExpression" || callee.property?.name !== "addEventListener") return;
1241
+ const target = callee.object?.type === "Identifier" ? callee.object.name : void 0;
1242
+ if (target !== "window" && target !== "document") return;
1243
+ const [first] = call.arguments;
1244
+ const event = first?.type === "Literal" && typeof first.value === "string" ? first.value : void 0;
1245
+ if (!event || !FLOATING_EVENTS.has(event)) return;
1246
+ if (isEscaped(context, statement(call))) return;
1247
+ context.report({ loc: call.loc, messageId: "listener", data: { event, target } });
1232
1248
  }
1233
1249
  };
1234
1250
  }
1235
1251
  };
1236
1252
 
1237
1253
  // src/eslint/no-handmade-empty-state.ts
1254
+ import { statSync as statSync2 } from "node:fs";
1238
1255
  var child2 = (node, key) => node[key];
1239
1256
  var children2 = (node, key) => (node[key] ?? []).filter((n) => !!n);
1240
1257
  var nameOf2 = (node) => node?.type === "Identifier" || node?.type === "JSXIdentifier" ? node.name : void 0;
@@ -1586,7 +1603,7 @@ var noHandmadeHeader = {
1586
1603
 
1587
1604
  // src/eslint/no-copied-look.ts
1588
1605
  import { existsSync as existsSync4, readFileSync as readFileSync3, readdirSync, statSync as statSync3 } from "node:fs";
1589
- import { dirname as dirname3, join as join3, relative, resolve as resolve2 } from "node:path";
1606
+ import { dirname as dirname3, join as join3, relative as relative2, resolve as resolve2 } from "node:path";
1590
1607
 
1591
1608
  // src/eslint/looks-of.ts
1592
1609
  import { existsSync as existsSync3, readFileSync as readFileSync2 } from "node:fs";
@@ -1885,7 +1902,7 @@ function ownLooks(repoDir) {
1885
1902
  const text = readFileSync3(path, "utf8");
1886
1903
  const source = parseForLooks(path, text);
1887
1904
  const exported = name.endsWith(".tsx") ? [...componentsOf(source).keys()].filter((n) => exportedNames(source).has(n)) : [];
1888
- const file = relative(repoDir, path).replace(/\\/g, "/");
1905
+ const file = relative2(repoDir, path).replace(/\\/g, "/");
1889
1906
  const looks = [...looksOf(source, exported)].flatMap(([part, lists]) => lists.map((l) => ({ part, file, look: l.split(" "), from: "own" })));
1890
1907
  if (text.includes("_CLASSES")) for (const [part, lists] of sharedLooksOf(source)) for (const l of lists) looks.push({ part, file, look: l.split(" "), from: "shared" });
1891
1908
  cached = { mtime, looks };
@@ -1917,7 +1934,7 @@ var noCopiedLook = {
1917
1934
  const inPackage = nameOf3(repoDir) === PACKAGE2;
1918
1935
  return {
1919
1936
  Program() {
1920
- const here = relative(repoDir, file).replace(/\\/g, "/");
1937
+ const here = relative2(repoDir, file).replace(/\\/g, "/");
1921
1938
  const source = parseForLooks(file, context.sourceCode.text);
1922
1939
  const declared = new Set(componentsOf(source).keys());
1923
1940
  const looks = [...inPackage ? [] : shippedLooks(repoDir), ...ownLooks(repoDir)].filter((l) => l.file !== here && !declared.has(l.part));