@estiva-app/ui 0.90.2 → 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.
- package/dist/AttachedCard.d.ts +30 -0
- package/dist/AttachedCard.d.ts.map +1 -0
- package/dist/AttachmentCard.d.ts +14 -0
- package/dist/AttachmentCard.d.ts.map +1 -1
- package/dist/AvatarGroup.d.ts +7 -1
- package/dist/AvatarGroup.d.ts.map +1 -1
- package/dist/CommentBox.d.ts +1 -1
- package/dist/CommentBox.d.ts.map +1 -1
- package/dist/InlineText.d.ts +5 -2
- package/dist/InlineText.d.ts.map +1 -1
- package/dist/Link.d.ts +3 -2
- package/dist/Link.d.ts.map +1 -1
- package/dist/LinkCard.d.ts +3 -3
- package/dist/LinkCard.d.ts.map +1 -1
- package/dist/LinkChip.d.ts.map +1 -1
- package/dist/LinkParts.d.ts +17 -3
- package/dist/LinkParts.d.ts.map +1 -1
- package/dist/LinkPreview.d.ts.map +1 -1
- package/dist/LinkRow.d.ts +10 -5
- package/dist/LinkRow.d.ts.map +1 -1
- package/dist/PartCard.d.ts +7 -3
- package/dist/PartCard.d.ts.map +1 -1
- package/dist/Popover.d.ts +8 -1
- package/dist/Popover.d.ts.map +1 -1
- package/dist/ReactionRow.d.ts.map +1 -1
- package/dist/RichText.d.ts.map +1 -1
- package/dist/SuggestionMenu.d.ts +6 -2
- package/dist/SuggestionMenu.d.ts.map +1 -1
- package/dist/editor.js +19 -12
- package/dist/editor.js.map +3 -3
- package/dist/eslint/has-a-page-and-a-story.d.ts.map +1 -1
- package/dist/eslint/index.js +1093 -1076
- package/dist/eslint/index.js.map +4 -4
- package/dist/eslint/no-restyled-part.d.ts +9 -4
- package/dist/eslint/no-restyled-part.d.ts.map +1 -1
- package/dist/gates/{chunk-BS5JASHV.js → chunk-P2P6AHRY.js} +2 -2
- package/dist/gates/{chunk-BS5JASHV.js.map → chunk-P2P6AHRY.js.map} +2 -2
- package/dist/gates/cli.js +1 -1
- package/dist/gates/gate-config.d.ts +4 -1
- package/dist/gates/gate-config.d.ts.map +1 -1
- package/dist/gates/hook.d.ts.map +1 -1
- package/dist/gates/index.js +2 -2
- package/dist/gates/index.js.map +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +275 -185
- package/dist/index.js.map +4 -4
- package/dist/linked.d.ts +7 -9
- package/dist/linked.d.ts.map +1 -1
- package/dist/linked.examples.d.ts.map +1 -1
- package/dist/linkedFrom.d.ts.map +1 -1
- package/dist/links.d.ts +2 -2
- package/dist/links.d.ts.map +1 -1
- package/dist/looks.d.ts +24 -0
- package/dist/looks.d.ts.map +1 -1
- package/dist/registry/{app-X2GI4WTU.js → app-IGBRDD4L.js} +3 -3
- package/dist/registry/{build-P6X3PTZP.js → build-MWN4UI23.js} +2 -2
- package/dist/registry/{chunk-P55P2QFD.js → chunk-4TWYUIOB.js} +1 -1
- package/dist/registry/chunk-4TWYUIOB.js.map +7 -0
- package/dist/registry/{chunk-V67F474L.js → chunk-NSHK76XT.js} +2 -2
- package/dist/registry/{chunk-4QWD3EBY.js → chunk-THI3SLW5.js} +1 -1
- package/dist/registry/{chunk-4QWD3EBY.js.map → chunk-THI3SLW5.js.map} +1 -1
- package/dist/registry/cli.js +3 -3
- package/dist/registry/find.d.ts +1 -1
- package/dist/registry/find.d.ts.map +1 -1
- package/dist/registry/index.js +3 -3
- package/package.json +1 -1
- package/registry.json +509 -455
- package/src/AppProvider.stories.tsx +1 -1
- package/src/AppShell.stories.tsx +1 -1
- package/src/AttachedCard.mdx +55 -0
- package/src/{CardUnder.stories.tsx → AttachedCard.stories.tsx} +10 -19
- package/src/{CardUnder.test.tsx → AttachedCard.test.tsx} +8 -8
- package/src/AttachedCard.tsx +43 -0
- package/src/AttachmentCard.stories.tsx +1 -1
- package/src/AttachmentCard.tsx +36 -14
- package/src/Avatar.stories.tsx +1 -1
- package/src/AvatarGroup.stories.tsx +1 -1
- package/src/AvatarGroup.tsx +8 -2
- package/src/Banner.stories.tsx +1 -1
- package/src/BlockHandle.stories.tsx +1 -1
- package/src/BlockNodes.stories.tsx +1 -1
- package/src/Breadcrumb.stories.tsx +1 -1
- package/src/Button.stories.tsx +1 -1
- package/src/Card.stories.tsx +1 -1
- package/src/Checkbox.stories.tsx +1 -1
- package/src/Chip.stories.tsx +1 -1
- package/src/ChipInput.stories.tsx +1 -1
- package/src/CodeBlockColours.stories.tsx +1 -1
- package/src/CollapsibleSection.stories.tsx +1 -1
- package/src/CommandPalette.stories.tsx +1 -1
- package/src/CommentBox.mdx +3 -3
- package/src/CommentBox.stories.tsx +39 -7
- package/src/CommentBox.tsx +27 -17
- package/src/CommentHighlights.stories.tsx +1 -1
- package/src/ComposerTriggers.stories.tsx +1 -1
- package/src/ConfirmDialog.stories.tsx +1 -1
- package/src/ContainerHeader.stories.tsx +1 -1
- package/src/DialogShell.stories.tsx +1 -1
- package/src/Divider.stories.tsx +1 -1
- package/src/DocumentEditor.stories.tsx +1 -1
- package/src/EditableText.stories.tsx +1 -1
- package/src/EditorBlockHandle.stories.tsx +1 -1
- package/src/EditorTableControls.stories.tsx +1 -1
- package/src/EmptyState.stories.tsx +1 -1
- package/src/EntryShell.mdx +1 -1
- package/src/EntryShell.stories.tsx +1 -1
- package/src/ErrorBoundary.stories.tsx +1 -1
- package/src/Field.stories.tsx +1 -1
- package/src/FieldLine.stories.tsx +1 -1
- package/src/FilePicker.stories.tsx +1 -1
- package/src/Form.stories.tsx +1 -1
- package/src/IconButton.stories.tsx +1 -1
- package/src/IdentityMenu.stories.tsx +1 -1
- package/src/InlineChip.stories.tsx +1 -1
- package/src/InlineText.mdx +1 -0
- package/src/InlineText.stories.tsx +6 -3
- package/src/InlineText.tsx +7 -2
- package/src/Kbd.stories.tsx +1 -1
- package/src/KindIcon.stories.tsx +1 -1
- package/src/Lightbox.stories.tsx +1 -1
- package/src/Link.mdx +3 -2
- package/src/Link.stories.tsx +1 -1
- package/src/Link.test.tsx +5 -3
- package/src/Link.tsx +5 -3
- package/src/LinkCard.mdx +5 -4
- package/src/LinkCard.stories.tsx +1 -1
- package/src/LinkCard.test.tsx +1 -1
- package/src/LinkCard.tsx +80 -57
- package/src/LinkChip.mdx +3 -3
- package/src/LinkChip.stories.tsx +1 -1
- package/src/LinkChip.test.tsx +1 -1
- package/src/LinkChip.tsx +16 -3
- package/src/LinkChips.stories.tsx +1 -1
- package/src/LinkParts.stories.tsx +1 -1
- package/src/LinkParts.tsx +40 -8
- package/src/LinkPlaces.stories.tsx +1 -1
- package/src/LinkPreview.mdx +1 -1
- package/src/LinkPreview.stories.tsx +1 -1
- package/src/LinkPreview.tsx +3 -1
- package/src/LinkRow.mdx +8 -6
- package/src/LinkRow.stories.tsx +3 -3
- package/src/LinkRow.test.tsx +3 -3
- package/src/LinkRow.tsx +71 -40
- package/src/ListColumn.stories.tsx +1 -1
- package/src/MembersDialog.stories.tsx +1 -1
- package/src/MembersPill.stories.tsx +1 -1
- package/src/Menu.stories.tsx +1 -1
- package/src/MenuItem.stories.tsx +1 -1
- package/src/NavItem.stories.tsx +1 -1
- package/src/NavTree.stories.tsx +1 -1
- package/src/Panel.stories.tsx +1 -1
- package/src/PartCard.mdx +4 -4
- package/src/PartCard.stories.tsx +11 -8
- package/src/PartCard.test.tsx +5 -3
- package/src/PartCard.tsx +33 -24
- package/src/PastedImages.stories.tsx +1 -1
- package/src/PastedMarkdown.stories.tsx +1 -1
- package/src/Person.stories.tsx +1 -1
- package/src/PersonTrigger.stories.tsx +1 -1
- package/src/Popover.stories.tsx +1 -1
- package/src/Popover.tsx +6 -2
- package/src/PreviewCard.stories.tsx +1 -1
- package/src/ProgressBar.stories.tsx +1 -1
- package/src/Property.stories.tsx +1 -1
- package/src/Rail.stories.tsx +1 -1
- package/src/RailItem.stories.tsx +1 -1
- package/src/Reaction.stories.tsx +1 -1
- package/src/ReactionPicker.stories.tsx +1 -1
- package/src/ReactionRow.stories.tsx +1 -1
- package/src/ReactionRow.tsx +3 -1
- package/src/ReferenceCards.mdx +3 -0
- package/src/ReferenceCards.stories.tsx +3 -1
- package/src/ReferenceMenu.mdx +1 -1
- package/src/ReferenceMenu.stories.tsx +1 -1
- package/src/RichText.stories.tsx +1 -1
- package/src/RichText.tsx +6 -2
- package/src/ScrollArea.stories.tsx +1 -1
- package/src/SearchInput.stories.tsx +1 -1
- package/src/SectionHeader.stories.tsx +1 -1
- package/src/SectionLabel.stories.tsx +1 -1
- package/src/Select.stories.tsx +1 -1
- package/src/SelectionToolbar.stories.tsx +1 -1
- package/src/ShowMore.stories.tsx +1 -1
- package/src/Sidebar.stories.tsx +1 -1
- package/src/Skeleton.stories.tsx +1 -1
- package/src/SuggestionMenu.mdx +4 -1
- package/src/SuggestionMenu.stories.tsx +14 -8
- package/src/SuggestionMenu.tsx +20 -3
- package/src/Tabs.stories.tsx +1 -1
- package/src/TextInput.stories.tsx +1 -1
- package/src/Textarea.stories.tsx +1 -1
- package/src/Toast.stories.tsx +1 -1
- package/src/Toolbar.stories.tsx +1 -1
- package/src/Tooltip.stories.tsx +1 -1
- package/src/TopBar.stories.tsx +1 -1
- package/src/UnreadDot.stories.tsx +1 -1
- package/src/eslint/has-a-page-and-a-story.test.ts +5 -0
- package/src/eslint/has-a-page-and-a-story.ts +11 -2
- package/src/eslint/no-restyled-part.test.ts +32 -8
- package/src/eslint/no-restyled-part.ts +50 -23
- package/src/gates/gate-config.ts +5 -2
- package/src/gates/gates.test.ts +20 -2
- package/src/gates/hook.ts +4 -3
- package/src/index.ts +2 -1
- package/src/linked.examples.ts +2 -3
- package/src/linked.ts +11 -1
- package/src/linkedFrom.ts +1 -0
- package/src/links.ts +3 -2
- package/src/looks.ts +29 -0
- package/src/registry/build.ts +1 -1
- package/src/registry/contract.test.ts +1 -1
- package/src/registry/find.ts +1 -1
- package/src/registry/registry.test.ts +12 -12
- package/src/suggestionPopup.tsx +1 -1
- package/stories/Choosing.mdx +2 -2
- package/stories/DesignTokens.mdx +1 -1
- package/stories/GettingStarted.mdx +2 -2
- package/stories/Introduction.mdx +23 -4
- package/stories/TokensPage.tsx +12 -7
- package/dist/CardUnder.d.ts +0 -31
- package/dist/CardUnder.d.ts.map +0 -1
- package/dist/registry/chunk-P55P2QFD.js.map +0 -7
- package/src/CardUnder.mdx +0 -54
- package/src/CardUnder.tsx +0 -49
- /package/dist/registry/{app-X2GI4WTU.js.map → app-IGBRDD4L.js.map} +0 -0
- /package/dist/registry/{build-P6X3PTZP.js.map → build-MWN4UI23.js.map} +0 -0
- /package/dist/registry/{chunk-V67F474L.js.map → chunk-NSHK76XT.js.map} +0 -0
package/src/RichText.stories.tsx
CHANGED
|
@@ -29,7 +29,7 @@ const EVERY_BLOCK: RichTextBlock[] = [
|
|
|
29
29
|
]
|
|
30
30
|
|
|
31
31
|
const meta = {
|
|
32
|
-
title: '
|
|
32
|
+
title: 'Writing/RichText',
|
|
33
33
|
component: RichText,
|
|
34
34
|
args: { blocks: EVERY_BLOCK, size: 'default' },
|
|
35
35
|
argTypes: { size: { control: 'inline-radio', options: ['default', 'small'] } },
|
package/src/RichText.tsx
CHANGED
|
@@ -171,7 +171,9 @@ function textWithLinks(text: string, renderText: (text: string) => ReactNode): R
|
|
|
171
171
|
if (written) {
|
|
172
172
|
return (
|
|
173
173
|
<span key={i} className="break-words">
|
|
174
|
-
<Link href={written[2]} external onClick={keepToLink}>
|
|
174
|
+
<Link href={written[2]} external onClick={keepToLink}>
|
|
175
|
+
{written[1]}
|
|
176
|
+
</Link>
|
|
175
177
|
</span>
|
|
176
178
|
)
|
|
177
179
|
}
|
|
@@ -180,7 +182,9 @@ function textWithLinks(text: string, renderText: (text: string) => ReactNode): R
|
|
|
180
182
|
return (
|
|
181
183
|
// An address has no spaces to wrap at, so it may break anywhere.
|
|
182
184
|
<span key={i} className="break-all">
|
|
183
|
-
<Link href={bare[1]} external onClick={keepToLink}>
|
|
185
|
+
<Link href={bare[1]} external onClick={keepToLink}>
|
|
186
|
+
{bare[1]}
|
|
187
|
+
</Link>
|
|
184
188
|
{bare[2]}
|
|
185
189
|
</span>
|
|
186
190
|
)
|
|
@@ -4,7 +4,7 @@ import { ScrollArea } from './ScrollArea'
|
|
|
4
4
|
|
|
5
5
|
/** A region that scrolls without taking width for its scrollbar. */
|
|
6
6
|
const meta = {
|
|
7
|
-
title: '
|
|
7
|
+
title: 'Page structure/ScrollArea',
|
|
8
8
|
component: ScrollArea,
|
|
9
9
|
parameters: { controls: { disable: true } },
|
|
10
10
|
args: { children: null },
|
|
@@ -3,7 +3,7 @@ import { SearchInput } from './SearchInput'
|
|
|
3
3
|
|
|
4
4
|
/** An inset field whose border strengthens on focus; under Signal the shortcut becomes the mono kbd chip. */
|
|
5
5
|
const meta = {
|
|
6
|
-
title: '
|
|
6
|
+
title: 'Forms & fields/SearchInput',
|
|
7
7
|
component: SearchInput,
|
|
8
8
|
decorators: [(Story) => <div className="w-[290px]"><Story /></div>],
|
|
9
9
|
} satisfies Meta<typeof SearchInput>
|
|
@@ -6,7 +6,7 @@ import { SectionHeader } from './SectionHeader'
|
|
|
6
6
|
|
|
7
7
|
/** The 32px row a section starts with. Hover it: the row fills, and its actions appear. A section that folds is CollapsibleSection, whose header this is. */
|
|
8
8
|
const meta = {
|
|
9
|
-
title: '
|
|
9
|
+
title: 'Page structure/SectionHeader',
|
|
10
10
|
component: SectionHeader,
|
|
11
11
|
decorators: [(Story) => <div className="w-[280px]"><Story /></div>],
|
|
12
12
|
args: { title: 'Section', showActions: 'hover' },
|
|
@@ -4,7 +4,7 @@ import { SectionLabel } from './SectionLabel'
|
|
|
4
4
|
|
|
5
5
|
/** Every section title renders through this span — a style change is one edit. Under Signal it becomes the mono uppercase micro-label. */
|
|
6
6
|
const meta = {
|
|
7
|
-
title: '
|
|
7
|
+
title: 'Page structure/SectionLabel',
|
|
8
8
|
component: SectionLabel,
|
|
9
9
|
args: { children: 'Starred' },
|
|
10
10
|
} satisfies Meta<typeof SectionLabel>
|
package/src/Select.stories.tsx
CHANGED
|
@@ -17,7 +17,7 @@ import { TextInput } from './TextInput'
|
|
|
17
17
|
* you stop using one.
|
|
18
18
|
*/
|
|
19
19
|
const meta = {
|
|
20
|
-
title: '
|
|
20
|
+
title: 'Forms & fields/Select',
|
|
21
21
|
component: Select,
|
|
22
22
|
parameters: { layout: 'padded' },
|
|
23
23
|
decorators: [(Story) => <div className="w-[360px]"><Story /></div>],
|
|
@@ -9,7 +9,7 @@ import { KeptSelection, SelectionToolbar, type MarkId } from './SelectionToolbar
|
|
|
9
9
|
* text you have already selected. It follows the selection by itself.
|
|
10
10
|
*/
|
|
11
11
|
const meta = {
|
|
12
|
-
title: '
|
|
12
|
+
title: 'Writing/SelectionToolbar',
|
|
13
13
|
component: SelectionToolbar,
|
|
14
14
|
parameters: { layout: 'padded' },
|
|
15
15
|
} satisfies Meta
|
package/src/ShowMore.stories.tsx
CHANGED
|
@@ -11,7 +11,7 @@ const LONG = Array.from(
|
|
|
11
11
|
|
|
12
12
|
/** Long content cut behind a fade, with "Show more" under it. Short content is drawn whole. */
|
|
13
13
|
const meta = {
|
|
14
|
-
title: '
|
|
14
|
+
title: 'Page structure/ShowMore',
|
|
15
15
|
component: ShowMore,
|
|
16
16
|
decorators: [(Story) => <div className="w-[320px]"><Story /></div>],
|
|
17
17
|
args: { children: <p className="text-caption text-text-secondary">{LONG}</p> },
|
package/src/Sidebar.stories.tsx
CHANGED
|
@@ -8,7 +8,7 @@ import { Sidebar } from './Sidebar'
|
|
|
8
8
|
const placeholder = <IconSquareRounded size={16} stroke={1.5} />
|
|
9
9
|
|
|
10
10
|
const meta = {
|
|
11
|
-
title: '
|
|
11
|
+
title: 'App frame/Sidebar',
|
|
12
12
|
component: Sidebar,
|
|
13
13
|
parameters: { layout: 'fullscreen' },
|
|
14
14
|
args: { children: null },
|
package/src/Skeleton.stories.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
|
2
2
|
import { SkeletonBar, SkeletonList, SkeletonRow } from './Skeleton'
|
|
3
3
|
|
|
4
4
|
const meta = {
|
|
5
|
-
title: '
|
|
5
|
+
title: 'Status & feedback/Skeleton',
|
|
6
6
|
component: SkeletonList,
|
|
7
7
|
} satisfies Meta<typeof SkeletonList>
|
|
8
8
|
|
package/src/SuggestionMenu.mdx
CHANGED
|
@@ -72,6 +72,9 @@ Suggestion<Command>({
|
|
|
72
72
|
Escape: the first press closes the list, the second is somebody's own.
|
|
73
73
|
- **Outside an editor**, draw `SuggestionMenu` itself with a `rect` to hang from,
|
|
74
74
|
and call `handle.current.onKeyDown(event)` from wherever the keys arrive.
|
|
75
|
+
Give `rect` as a function that says where the caret is now, as Tiptap's
|
|
76
|
+
`clientRect` does, and the list follows the caret when the page scrolls; a
|
|
77
|
+
rect alone is where the caret was, and the list stays there.
|
|
75
78
|
|
|
76
79
|
<Canvas of={SuggestionMenuStories.InAnEditor} />
|
|
77
80
|
|
|
@@ -83,7 +86,7 @@ It does these by itself. Write none of them around it.
|
|
|
83
86
|
|---|---|---|
|
|
84
87
|
| Moves through its items with the arrow keys, and wraps at the ends | an arrow-key handler | ✓ |
|
|
85
88
|
| Says what it is to assistive technology: a listbox of options, and the editor pointing at the active one | `role="listbox"`, `role="option"`, `aria-activedescendant` | ✓ |
|
|
86
|
-
| Hangs from the caret: above it, below when there is no room, never off the window | position arithmetic | |
|
|
89
|
+
| Hangs from the caret: above it, below when there is no room, never off the window, and follows it when the page scrolls | position arithmetic, a scroll listener | |
|
|
87
90
|
| Scrolls the highlighted row into view, and back to the first row when the list changes | `scrollIntoView` | |
|
|
88
91
|
| Chooses on a press without taking focus from the text | `preventDefault` on each row | |
|
|
89
92
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
2
|
import { IconSquareRounded } from '@tabler/icons-react'
|
|
3
|
-
import { useLayoutEffect, useMemo, useRef, useState, type ReactNode } from 'react'
|
|
3
|
+
import { useCallback, useLayoutEffect, useMemo, useRef, useState, type ReactNode } from 'react'
|
|
4
4
|
import { Extension } from '@tiptap/core'
|
|
5
5
|
import { EditorContent, useEditor } from '@tiptap/react'
|
|
6
6
|
import StarterKit from '@tiptap/starter-kit'
|
|
@@ -15,9 +15,14 @@ import { suggestionPopup } from './suggestionPopup'
|
|
|
15
15
|
* Focus stays in the text: the editor hands its ↑, ↓ and Enter to the list.
|
|
16
16
|
*/
|
|
17
17
|
const meta = {
|
|
18
|
-
title: '
|
|
18
|
+
title: 'Writing/SuggestionMenu',
|
|
19
19
|
component: SuggestionMenu,
|
|
20
|
-
parameters: {
|
|
20
|
+
parameters: {
|
|
21
|
+
layout: 'padded',
|
|
22
|
+
// Each example in a frame of its own on the Docs page, so its list stays in its box. Drawn on the page itself, a
|
|
23
|
+
// list near the top of the window flipped below its caret as the page scrolled, over the words (Katerina, 29 Oct).
|
|
24
|
+
docs: { story: { inline: false, height: '560px' } },
|
|
25
|
+
},
|
|
21
26
|
} satisfies Meta
|
|
22
27
|
|
|
23
28
|
export default meta
|
|
@@ -46,13 +51,14 @@ const commandRow = (c: Command): SuggestionMenuRow => ({ label: c.label, shortcu
|
|
|
46
51
|
|
|
47
52
|
/**
|
|
48
53
|
* A line of text with the caret's place marked, and the list hung from it —
|
|
49
|
-
* the way the editor hangs it
|
|
50
|
-
*
|
|
54
|
+
* the way the editor hangs it: from where a stand-in for the caret is now,
|
|
55
|
+
* asked again each time the list is placed, as Tiptap's `clientRect` is.
|
|
51
56
|
*/
|
|
52
57
|
function AtACaret<T>({ children, ...props }: { children?: ReactNode } & Omit<Parameters<typeof SuggestionMenu<T>>[0], 'rect'>) {
|
|
53
58
|
const caret = useRef<HTMLSpanElement>(null)
|
|
54
|
-
const [
|
|
55
|
-
useLayoutEffect(() =>
|
|
59
|
+
const [drawn, setDrawn] = useState(false)
|
|
60
|
+
useLayoutEffect(() => setDrawn(true), [])
|
|
61
|
+
const where = useCallback(() => caret.current?.getBoundingClientRect() ?? null, [])
|
|
56
62
|
return (
|
|
57
63
|
<div className="flex h-[520px] items-end pb-6 text-body-2 text-text-primary">
|
|
58
64
|
<p>
|
|
@@ -60,7 +66,7 @@ function AtACaret<T>({ children, ...props }: { children?: ReactNode } & Omit<Par
|
|
|
60
66
|
<span ref={caret}>/</span>
|
|
61
67
|
{children}
|
|
62
68
|
</p>
|
|
63
|
-
<SuggestionMenu<T> {...props} rect={
|
|
69
|
+
<SuggestionMenu<T> {...props} rect={drawn ? where : null} />
|
|
64
70
|
</div>
|
|
65
71
|
)
|
|
66
72
|
}
|
package/src/SuggestionMenu.tsx
CHANGED
|
@@ -60,8 +60,12 @@ export interface SuggestionMenuHandle {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
export interface SuggestionMenuProps<T> {
|
|
63
|
-
/**
|
|
64
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Where the caret is, from the editor: Tiptap's `clientRect`, asked again each
|
|
65
|
+
* time the box is placed, so it follows the caret as the page scrolls. A rect
|
|
66
|
+
* is where the caret was, and stays there. `null` closes the box.
|
|
67
|
+
*/
|
|
68
|
+
rect: (() => DOMRect | null) | DOMRect | null
|
|
65
69
|
/** The editor's own element — told which row is active. Absent in a story. */
|
|
66
70
|
editorElement?: HTMLElement | null
|
|
67
71
|
/** Names the list — "Commands", "People". */
|
|
@@ -80,6 +84,19 @@ export interface SuggestionMenuProps<T> {
|
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
export function SuggestionMenu<T>({ rect, editorElement, ariaLabel, width, maxHeight, sections, itemKey, row, onSelect, handle }: SuggestionMenuProps<T>) {
|
|
87
|
+
// The caret where it is now, and the editor it sits in, whose scrolling moves it. Given only the rect it had as the
|
|
88
|
+
// list opened, the list stayed on the screen while the text scrolled away under it (Katerina, 29 Oct).
|
|
89
|
+
const last = useRef<DOMRect | null>(null)
|
|
90
|
+
const anchor = useMemo(() => {
|
|
91
|
+
if (typeof rect !== 'function') return rect
|
|
92
|
+
return {
|
|
93
|
+
getBoundingClientRect: () => {
|
|
94
|
+
last.current = rect() ?? last.current
|
|
95
|
+
return last.current ?? new DOMRect()
|
|
96
|
+
},
|
|
97
|
+
contextElement: editorElement ?? undefined,
|
|
98
|
+
}
|
|
99
|
+
}, [rect, editorElement])
|
|
83
100
|
const shown = useMemo(() => sections.filter((section) => section.items.length > 0), [sections])
|
|
84
101
|
const items = useMemo(() => shown.flatMap((section) => section.items), [shown])
|
|
85
102
|
const keys = items.map(itemKey).join('\n')
|
|
@@ -190,7 +207,7 @@ export function SuggestionMenu<T>({ rect, editorElement, ariaLabel, width, maxHe
|
|
|
190
207
|
|
|
191
208
|
return (
|
|
192
209
|
// finalFocus={false}: focus never left the text, and a list that closes because focus moved elsewhere must not pull it back (71a4577b).
|
|
193
|
-
<Popover anchor={
|
|
210
|
+
<Popover anchor={anchor} open={rect !== null} side="top" align="left" className={width} maxHeight={maxHeight} ariaLabel={ariaLabel} finalFocus={false}>
|
|
194
211
|
{/* The list the editor drives from its caret: a listbox, because Base UI's lists need a text field of their own.
|
|
195
212
|
`gap-0.5`: 2px between rows, as a menu's — a section with a heading
|
|
196
213
|
had them from `MenuSection`, and rows without one touched. */}
|
package/src/Tabs.stories.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import { Select } from './Select'
|
|
|
4
4
|
import { TextInput } from './TextInput'
|
|
5
5
|
|
|
6
6
|
const meta = {
|
|
7
|
-
title: '
|
|
7
|
+
title: 'Forms & fields/TextInput',
|
|
8
8
|
component: TextInput,
|
|
9
9
|
parameters: { layout: 'padded' },
|
|
10
10
|
args: { placeholder: 'What is this about?' },
|
package/src/Textarea.stories.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
|
2
2
|
import { Textarea } from './Textarea'
|
|
3
3
|
|
|
4
4
|
const meta = {
|
|
5
|
-
title: '
|
|
5
|
+
title: 'Forms & fields/Textarea',
|
|
6
6
|
component: Textarea,
|
|
7
7
|
parameters: { layout: 'padded' },
|
|
8
8
|
args: { placeholder: 'Summarise the outcome or decision…', className: 'h-[109px]' },
|
package/src/Toast.stories.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import { Toast, ToastProvider, useToast } from './Toast'
|
|
|
4
4
|
|
|
5
5
|
/** The pill that confirms something happened. Positioning and auto-dismiss live in ToastProvider. */
|
|
6
6
|
const meta = {
|
|
7
|
-
title: '
|
|
7
|
+
title: 'Status & feedback/Toast',
|
|
8
8
|
component: Toast,
|
|
9
9
|
args: {
|
|
10
10
|
label: 'Changes saved',
|
package/src/Toolbar.stories.tsx
CHANGED
|
@@ -14,7 +14,7 @@ import { Toolbar, ToolbarButton, ToolbarInput, ToolbarLink, ToolbarSeparator } f
|
|
|
14
14
|
* it without the caller drawing anything.
|
|
15
15
|
*/
|
|
16
16
|
const meta = {
|
|
17
|
-
title: '
|
|
17
|
+
title: 'Buttons & links/Toolbar',
|
|
18
18
|
component: Toolbar,
|
|
19
19
|
args: { 'aria-label': 'Formatting', children: null },
|
|
20
20
|
argTypes: { children: { control: false } },
|
package/src/Tooltip.stories.tsx
CHANGED
|
@@ -6,7 +6,7 @@ import { Tooltip, WithTooltip } from './Tooltip'
|
|
|
6
6
|
import { Toolbar, ToolbarButton } from './Toolbar'
|
|
7
7
|
|
|
8
8
|
const meta = {
|
|
9
|
-
title: '
|
|
9
|
+
title: 'Menus & windows/Tooltip',
|
|
10
10
|
component: Tooltip,
|
|
11
11
|
args: { label: 'Add to starred' },
|
|
12
12
|
} satisfies Meta<typeof Tooltip>
|
package/src/TopBar.stories.tsx
CHANGED
|
@@ -16,6 +16,8 @@ const tester = new RuleTester({
|
|
|
16
16
|
|
|
17
17
|
/** Real files of this package, so the rules are tested against what they read. */
|
|
18
18
|
const src = (name: string) => fileURLToPath(new URL(`../${name}`, import.meta.url))
|
|
19
|
+
/** The package's root `stories/`: Storybook's pages and a prototype's helpers, which the gate reads too. */
|
|
20
|
+
const stories = (name: string) => fileURLToPath(new URL(`../../stories/${name}`, import.meta.url))
|
|
19
21
|
const code = 'export function Probe() {\n return null\n}\n'
|
|
20
22
|
const escaped = '// @estiva-escape(component-has-a-page, component-has-a-story): a probe file that documents itself in its own page\nexport function Probe() {\n return null\n}\n'
|
|
21
23
|
|
|
@@ -39,6 +41,8 @@ tester.run('component-has-a-page', componentHasAPage, {
|
|
|
39
41
|
{ name: 'a test file', code, filename: src('Button.test.tsx') },
|
|
40
42
|
{ name: 'a file that is not a component file at all', code, filename: src('index.ts') },
|
|
41
43
|
{ name: 'a component with its reason at the top', code: escaped, filename: src('NoPageProbe.tsx') },
|
|
44
|
+
{ name: "a helper in the root stories/, which is not a part (the One conversation prototype's Conversation.tsx)", code, filename: stories('one-conversation/Conversation.tsx') },
|
|
45
|
+
{ name: 'a page of the root stories/ drawn in a .tsx', code, filename: stories('TokensPage.tsx') },
|
|
42
46
|
],
|
|
43
47
|
invalid: [
|
|
44
48
|
{ name: 'a component with no page', code, filename: src('NoPageProbe.tsx'), errors: [{ messageId: 'missing' }] },
|
|
@@ -50,6 +54,7 @@ tester.run('component-has-a-story', componentHasAStory, {
|
|
|
50
54
|
{ name: 'a component with its story beside it', code, filename: src('Button.tsx') },
|
|
51
55
|
{ name: 'a story file, which is not itself a component', code, filename: src('Button.stories.tsx') },
|
|
52
56
|
{ name: 'a component with its reason at the top', code: escaped, filename: src('NoStoryProbe.tsx') },
|
|
57
|
+
{ name: "a helper in the root stories/, which is not a part (the One conversation prototype's Places.tsx)", code, filename: stories('one-conversation/Places.tsx') },
|
|
53
58
|
],
|
|
54
59
|
invalid: [
|
|
55
60
|
{ name: 'a component with no story', code, filename: src('NoStoryProbe.tsx'), errors: [{ messageId: 'missing' }] },
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs'
|
|
2
|
+
import { relative, sep } from 'node:path'
|
|
2
3
|
import type { Rule } from 'eslint'
|
|
3
4
|
import { ESCAPE_MESSAGES, isEscaped } from './escape'
|
|
5
|
+
import { packageDirOf } from './no-restyled-part'
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* A component of the package with no page, and one with no story (UIG-5, P2 and
|
|
@@ -21,6 +23,11 @@ import { ESCAPE_MESSAGES, isEscaped } from './escape'
|
|
|
21
23
|
* page and its story, never the other way round, so a page without a component
|
|
22
24
|
* is not this rule's business.
|
|
23
25
|
*
|
|
26
|
+
* Only the package's `src/` holds its components. The gate reads `stories/` too
|
|
27
|
+
* (a prototype there is what a build is checked against), but what lives there
|
|
28
|
+
* is Storybook's own pages and the helpers its stories draw with, not parts,
|
|
29
|
+
* so neither rule asks them for a page.
|
|
30
|
+
*
|
|
24
31
|
* A file that stays without one says why at its top: `// @estiva-escape: <why>`.
|
|
25
32
|
*/
|
|
26
33
|
interface ProgramNode {
|
|
@@ -29,9 +36,11 @@ interface ProgramNode {
|
|
|
29
36
|
range: [number, number]
|
|
30
37
|
}
|
|
31
38
|
|
|
32
|
-
/** A component file: a `.tsx` in the package's
|
|
39
|
+
/** A component file: a `.tsx` in the package's `src/` that is not a story or a test. */
|
|
33
40
|
function componentFile(filename: string): boolean {
|
|
34
|
-
|
|
41
|
+
if (!filename.endsWith('.tsx') || /\.(stories|test)\.tsx$/.test(filename)) return false
|
|
42
|
+
const dir = packageDirOf(filename)
|
|
43
|
+
return !dir || relative(dir, filename).split(sep).join('/').startsWith('src/')
|
|
35
44
|
}
|
|
36
45
|
|
|
37
46
|
function sibling(filename: string, extension: string): string {
|
|
@@ -39,13 +39,18 @@ write(
|
|
|
39
39
|
"import { Card, cn } from '@estiva-app/ui'\nexport function ConversationCard({ className, title }: { className?: string; title: string }) {\n return <Card className={cn('relative', className)}>{title}</Card>\n}\n",
|
|
40
40
|
)
|
|
41
41
|
write('app/src/components/Button.tsx', 'export function Button() {\n return null\n}\n')
|
|
42
|
-
write('pkg/package.json', '{ "name": "@estiva-app/ui" }')
|
|
42
|
+
write('pkg/package.json', '{ "name": "@estiva-app/ui", "exports": { ".": { "default": "./dist/index.js" }, "./editor": { "default": "./dist/editor.js" }, "./tokens.css": "./tokens.css" } }')
|
|
43
43
|
write('pkg/src/index.ts', "export { Link, type LinkProps } from './Link'\nexport { Card } from './Card'\nexport { cn } from './cn'\n")
|
|
44
44
|
write('pkg/src/Link.tsx', 'export function Link() {\n return null\n}\n')
|
|
45
45
|
write('pkg/src/cn.ts', 'export const cn = (...a: string[]) => a.join(" ")\n')
|
|
46
|
+
// The second entry, `@estiva-app/ui/editor`, where CommentBox lives.
|
|
47
|
+
write('pkg/src/editor.ts', "export { CommentBox, type CommentBoxProps } from './CommentBox'\n")
|
|
48
|
+
write('pkg/src/CommentBox.tsx', 'export function CommentBox() {\n return null\n}\n')
|
|
46
49
|
|
|
47
50
|
const app = join(root, 'app/src/Probe.tsx')
|
|
48
51
|
const pkg = join(root, 'pkg/src/Card.tsx')
|
|
52
|
+
/** A prototype's helper in the package's root `stories/`, which the gate reads since 28 October. */
|
|
53
|
+
const pkgStory = join(root, 'pkg/stories/one-conversation/Conversation.tsx')
|
|
49
54
|
const ui = (imports: string, body: string) => `import { ${imports} } from '@estiva-app/ui'\nexport function Probe() {\n return (\n${body}\n )\n}\n`
|
|
50
55
|
const local = (imports: string, from: string, body: string) => `import { ${imports} } from '${from}'\nexport function Probe() {\n return (\n${body}\n )\n}\n`
|
|
51
56
|
const USE_VARIANT_OR_SIZE = ' Use its `variant` or `size`.'
|
|
@@ -235,6 +240,20 @@ tester.run('no-restyled-part', noRestyledPart, {
|
|
|
235
240
|
code: local('Link', './Link', ' <Link href="/x" className="rounded-lg border">x</Link>'),
|
|
236
241
|
errors: [{ message: restyled('`rounded-lg` `border`', '`Link`', ' Use its `variant`, `truncate` or `cover`.') }],
|
|
237
242
|
},
|
|
243
|
+
{
|
|
244
|
+
name: 'in an app: a part from the editor entry, restyled',
|
|
245
|
+
filename: app,
|
|
246
|
+
code: "import { CommentBox } from '@estiva-app/ui/editor'\nexport function Probe() {\n return <CommentBox className=\"border-l-4 pl-2\" />\n}\n",
|
|
247
|
+
errors: [{ message: restyled('`border-l-4`', '`CommentBox`', noProp('CommentBox')) }],
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
// The One conversation prototype (estiva-ui concept/one-conversation 8641081, Conversation.tsx:199),
|
|
251
|
+
// which passed because only src/index.ts was read for the package's parts.
|
|
252
|
+
name: "inside the package: the editor entry's CommentBox restyled from a prototype in stories/, behind a condition",
|
|
253
|
+
filename: pkgStory,
|
|
254
|
+
code: "import { CommentBox } from '../../src/CommentBox'\nimport { cn } from '../../src/cn'\nexport function Probe({ on }: { on: boolean }) {\n return <CommentBox className={cn(on && '[&_[data-composer-editor]]:border-l-4 [&_[data-composer-editor]]:border-success-default [&_[data-composer-editor]]:pl-2')} />\n}\n",
|
|
255
|
+
errors: [{ message: restyled('`[&_[data-composer-editor]]:border-l-4` `[&_[data-composer-editor]]:border-success-default` `[&_[data-composer-editor]]:pl-2`', '`CommentBox`', noProp('CommentBox')) }],
|
|
256
|
+
},
|
|
238
257
|
{
|
|
239
258
|
name: 'inside the package: a part used in the file that declares it',
|
|
240
259
|
filename: pkg,
|
|
@@ -244,25 +263,30 @@ tester.run('no-restyled-part', noRestyledPart, {
|
|
|
244
263
|
],
|
|
245
264
|
})
|
|
246
265
|
|
|
247
|
-
/** Every part the package exports, from its own index.ts. */
|
|
266
|
+
/** Every part an entry of the package exports, from its own source: `index.ts`, and `editor.ts` for `@estiva-app/ui/editor`. */
|
|
248
267
|
const SRC = new URL('..', import.meta.url)
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
268
|
+
const partsOf = (entry: string) =>
|
|
269
|
+
[...readFileSync(new URL(entry, SRC), 'utf8').matchAll(/export \{([^}]*)\} from '\.\/[^']+'/g)]
|
|
270
|
+
.flatMap((m) => m[1].split(','))
|
|
271
|
+
.map((name) => name.trim())
|
|
272
|
+
.filter((name) => /^[A-Z][a-z]/.test(name))
|
|
273
|
+
const MAIN_PARTS = partsOf('index.ts')
|
|
274
|
+
const EDITOR_PARTS = partsOf('editor.ts').filter((name) => !MAIN_PARTS.includes(name))
|
|
275
|
+
const PARTS = [...MAIN_PARTS, ...EDITOR_PARTS]
|
|
276
|
+
const entryOf = (part: string) => (EDITOR_PARTS.includes(part) ? '@estiva-app/ui/editor' : '@estiva-app/ui')
|
|
254
277
|
|
|
255
278
|
describe('every part of the package is covered, by where it comes from', () => {
|
|
256
279
|
it('finds the parts', () => {
|
|
257
280
|
expect(PARTS.length).toBeGreaterThan(70)
|
|
258
281
|
expect(PARTS).toContain('EnterHint')
|
|
282
|
+
expect(EDITOR_PARTS).toContain('CommentBox')
|
|
259
283
|
})
|
|
260
284
|
tester.run('no-restyled-part, one case per exported part', noRestyledPart, {
|
|
261
285
|
valid: [],
|
|
262
286
|
invalid: PARTS.map((part) => ({
|
|
263
287
|
name: `${part}, restyled`,
|
|
264
288
|
filename: app,
|
|
265
|
-
code:
|
|
289
|
+
code: `import { ${part} } from '${entryOf(part)}'\nexport function Probe() {\n return (\n <${part} className="bg-bg-surface" />\n )\n}\n`,
|
|
266
290
|
errors: [{ message: restyled('`bg-bg-surface`', `\`${part}\``, PART_LOOK_PROPS[part] ? ` Use its ${PART_LOOK_PROPS[part].length === 1 ? `\`${PART_LOOK_PROPS[part][0]}\`` : `${PART_LOOK_PROPS[part].slice(0, -1).map((p) => `\`${p}\``).join(', ')} or \`${PART_LOOK_PROPS[part].at(-1)}\``}.` : noProp(part)) }],
|
|
267
291
|
})),
|
|
268
292
|
})
|
|
@@ -19,15 +19,18 @@ import { ESCAPE_MESSAGES, isEscaped } from './escape'
|
|
|
19
19
|
* of names is kept, so a part added to the package later is covered the day it
|
|
20
20
|
* is added.
|
|
21
21
|
*
|
|
22
|
-
* - In an app: anything imported from `@estiva-app/ui
|
|
23
|
-
*
|
|
22
|
+
* - In an app: anything imported from `@estiva-app/ui` or one of its other
|
|
23
|
+
* entries (`@estiva-app/ui/editor`, where `CommentBox` lives), and anything
|
|
24
|
+
* imported from the app's own files that is one of those — a re-export (Peek's
|
|
24
25
|
* `components/ui/Button.tsx`), a wrapper that hands its props on to a part
|
|
25
26
|
* (`{...rest}`), or a component that hands its own `className` on to a part
|
|
26
27
|
* (Peek's `ConversationCard` into `Card`). Relative imports and the apps' `@/`
|
|
27
28
|
* alias are followed; `@/` is the `src` folder beside the nearest
|
|
28
29
|
* `package.json`.
|
|
29
|
-
* - Inside the package (Katerina, 17 September): a name
|
|
30
|
-
*
|
|
30
|
+
* - Inside the package (Katerina, 17 September): a name one of its entries
|
|
31
|
+
* exports (`src/index.ts`, `src/editor.ts`…, read from `package.json`),
|
|
32
|
+
* imported from a sibling file or declared in the same file. Until 0.91 only
|
|
33
|
+
* `src/index.ts` was read, so `CommentBox` could be restyled from a story.
|
|
31
34
|
*
|
|
32
35
|
* **What it reads:** a string, a template, `cn()`/`clsx()` and their arguments,
|
|
33
36
|
* both sides of a condition, a `const` in the same file and the values of a
|
|
@@ -133,11 +136,13 @@ export const PART_LOOK_PROPS: Record<string, string[]> = {
|
|
|
133
136
|
Chip: ['type'],
|
|
134
137
|
KindIcon: ['tone'],
|
|
135
138
|
LinkedIcon: ['tone'],
|
|
139
|
+
LinkKey: ['tone'],
|
|
136
140
|
CollapsibleSection: ['look'],
|
|
137
141
|
Divider: ['tone', 'orientation'],
|
|
138
142
|
EmptyState: ['scope'],
|
|
139
143
|
FieldLine: ['tone'],
|
|
140
144
|
IconButton: ['variant', 'pressed', 'glow'],
|
|
145
|
+
InlineText: ['variant'],
|
|
141
146
|
InputChip: ['truncate'],
|
|
142
147
|
Kbd: ['tone'],
|
|
143
148
|
Link: ['variant', 'truncate', 'cover'],
|
|
@@ -223,7 +228,7 @@ interface ModuleFacts {
|
|
|
223
228
|
const PACKAGE = '@estiva-app/ui'
|
|
224
229
|
const moduleCache = new Map<string, ModuleFacts>()
|
|
225
230
|
const packageDirCache = new Map<string, string | null>()
|
|
226
|
-
const packagePartsCache = new Map<string, {
|
|
231
|
+
const packagePartsCache = new Map<string, { mtimes: string; parts: Set<string> }>()
|
|
227
232
|
|
|
228
233
|
function parseFile(parser: Parser, filePath: string): Node | null {
|
|
229
234
|
const code = readFileSync(filePath, 'utf8')
|
|
@@ -238,7 +243,7 @@ function parseFile(parser: Parser, filePath: string): Node | null {
|
|
|
238
243
|
}
|
|
239
244
|
|
|
240
245
|
/** The nearest folder holding a `package.json`, from a file. */
|
|
241
|
-
function packageDirOf(file: string): string | null {
|
|
246
|
+
export function packageDirOf(file: string): string | null {
|
|
242
247
|
const start = dirname(resolve(file))
|
|
243
248
|
if (packageDirCache.has(start)) return packageDirCache.get(start) ?? null
|
|
244
249
|
let dir = start
|
|
@@ -269,32 +274,53 @@ function resolveModule(fromFile: string, specifier: string): string | null {
|
|
|
269
274
|
return null
|
|
270
275
|
}
|
|
271
276
|
|
|
272
|
-
/**
|
|
277
|
+
/**
|
|
278
|
+
* The source file behind each of the package's entries: `"."` → `src/index.ts`,
|
|
279
|
+
* `"./editor"` → `src/editor.ts`, read from its `package.json` `exports`, so an
|
|
280
|
+
* entry added later is read the day it is added.
|
|
281
|
+
*/
|
|
282
|
+
function entrySources(dir: string, exports: unknown): string[] {
|
|
283
|
+
const found: string[] = []
|
|
284
|
+
for (const target of Object.values(exports && typeof exports === 'object' ? exports : {})) {
|
|
285
|
+
const built = typeof target === 'string' ? target : (target as { default?: unknown } | null)?.default
|
|
286
|
+
const match = typeof built === 'string' ? /^\.\/dist\/(.+)\.js$/.exec(built) : null
|
|
287
|
+
if (!match) continue
|
|
288
|
+
const source = [`${match[1]}.ts`, `${match[1]}.tsx`].map((name) => join(dir, 'src', name)).find((file) => existsSync(file))
|
|
289
|
+
if (source) found.push(source)
|
|
290
|
+
}
|
|
291
|
+
// A package.json with no `exports` (a test's copy of the layout) has its one entry.
|
|
292
|
+
if (!found.length && existsSync(join(dir, 'src', 'index.ts'))) found.push(join(dir, 'src', 'index.ts'))
|
|
293
|
+
return found
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** The names this package's entries export, when the file lives in `@estiva-app/ui` itself. */
|
|
273
297
|
function packagePartsFor(file: string, parser: Parser): Set<string> | null {
|
|
274
298
|
const dir = packageDirOf(file)
|
|
275
299
|
if (!dir) return null
|
|
276
|
-
let
|
|
300
|
+
let manifest: { name?: string; exports?: unknown }
|
|
277
301
|
try {
|
|
278
|
-
|
|
302
|
+
manifest = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')) as { name?: string; exports?: unknown }
|
|
279
303
|
} catch {
|
|
280
304
|
return null
|
|
281
305
|
}
|
|
282
|
-
if (name !== PACKAGE) return null
|
|
283
|
-
const
|
|
284
|
-
if (!
|
|
285
|
-
const
|
|
286
|
-
const cached = packagePartsCache.get(
|
|
287
|
-
if (cached && cached.
|
|
306
|
+
if (manifest.name !== PACKAGE) return null
|
|
307
|
+
const entries = entrySources(dir, manifest.exports)
|
|
308
|
+
if (!entries.length) return null
|
|
309
|
+
const mtimes = entries.map((entry) => `${entry}:${statSync(entry).mtimeMs}`).join('|')
|
|
310
|
+
const cached = packagePartsCache.get(dir)
|
|
311
|
+
if (cached && cached.mtimes === mtimes) return cached.parts
|
|
288
312
|
const parts = new Set<string>()
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
const
|
|
294
|
-
|
|
313
|
+
for (const entry of entries) {
|
|
314
|
+
const ast = parseFile(parser, entry)
|
|
315
|
+
for (const statement of ast ? children(ast, 'body') : []) {
|
|
316
|
+
if (statement?.type !== 'ExportNamedDeclaration' || statement.exportKind === 'type') continue
|
|
317
|
+
for (const specifier of children(statement, 'specifiers')) {
|
|
318
|
+
const exported = nameOf(child(specifier as Node, 'exported'))
|
|
319
|
+
if (specifier?.exportKind !== 'type' && exported && /^[A-Z][a-z]/.test(exported)) parts.add(exported)
|
|
320
|
+
}
|
|
295
321
|
}
|
|
296
322
|
}
|
|
297
|
-
packagePartsCache.set(
|
|
323
|
+
packagePartsCache.set(dir, { mtimes, parts })
|
|
298
324
|
return parts
|
|
299
325
|
}
|
|
300
326
|
|
|
@@ -334,7 +360,8 @@ function moduleParts(file: string, program: Node, parser: Parser, stack: Set<str
|
|
|
334
360
|
const body = children(program, 'body')
|
|
335
361
|
|
|
336
362
|
const exportsOf = (specifier: string): Map<string, PartBinding> | 'package' | null => {
|
|
337
|
-
|
|
363
|
+
// The package's other entries are the package too: `CommentBox` comes from `@estiva-app/ui/editor`.
|
|
364
|
+
if (specifier === PACKAGE || specifier.startsWith(`${PACKAGE}/`)) return 'package'
|
|
338
365
|
const target = resolveModule(file, specifier)
|
|
339
366
|
if (!target) return null
|
|
340
367
|
if (packageParts) return 'package'
|