@commercetools/nimbus-mcp 3.0.0 → 3.1.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/data/docs/route-manifest.json +1407 -794
- package/data/docs/routes/components-data-display-data-table.json +66 -34
- package/data/docs/routes/components-data-display-draggable-list.json +62 -7
- package/data/docs/routes/components-inputs-checkbox.json +2 -2
- package/data/docs/routes/components-layout-splitter.json +654 -0
- package/data/docs/routes/components-utilities-region.json +265 -0
- package/data/docs/routes/home-getting-started-bundler-plugins.json +248 -0
- package/data/docs/routes/hooks-usedraganddrop.json +310 -0
- package/data/docs/routes/patterns-actions.json +78 -0
- package/data/docs/routes/patterns-dialogs-confirmation-dialog.json +391 -0
- package/data/docs/routes/patterns-dialogs-form-dialog.json +358 -0
- package/data/docs/routes/patterns-dialogs.json +2 -2
- package/data/docs/routes/patterns-pages-public-page-layout.json +371 -0
- package/data/docs/routes/patterns-pages.json +78 -0
- package/data/docs/search-index.json +1 -1
- package/data/docs/types/AccordionContent.json +32 -32
- package/data/docs/types/AccordionHeader.json +102 -102
- package/data/docs/types/AccordionItem.json +28 -28
- package/data/docs/types/AccordionRoot.json +15 -15
- package/data/docs/types/AlertDescription.json +8 -8
- package/data/docs/types/AlertDismissButton.json +89 -89
- package/data/docs/types/AlertTitle.json +8 -8
- package/data/docs/types/Avatar.json +2 -2
- package/data/docs/types/Badge.json +2 -2
- package/data/docs/types/Body.json +6 -6
- package/data/docs/types/Box.json +6 -6
- package/data/docs/types/Button.json +97 -97
- package/data/docs/types/Calendar.json +111 -65
- package/data/docs/types/Caption.json +6 -6
- package/data/docs/types/CardRoot.json +2 -2
- package/data/docs/types/Cell.json +20 -20
- package/data/docs/types/Checkbox.json +99 -99
- package/data/docs/types/Code.json +10 -10
- package/data/docs/types/CollapsibleMotionContent.json +2 -2
- package/data/docs/types/CollapsibleMotionRoot.json +2 -2
- package/data/docs/types/CollapsibleMotionTrigger.json +4 -4
- package/data/docs/types/Column.json +8 -8
- package/data/docs/types/ColumnGroup.json +8 -8
- package/data/docs/types/ColumnHeader.json +18 -18
- package/data/docs/types/ComboBoxListBox.json +80 -80
- package/data/docs/types/ComboBoxOption.json +77 -77
- package/data/docs/types/ComboBoxPopover.json +77 -77
- package/data/docs/types/ComboBoxRoot.json +8 -8
- package/data/docs/types/ComboBoxSection.json +29 -29
- package/data/docs/types/ComboBoxTrigger.json +6 -6
- package/data/docs/types/ConfirmationDialog.json +224 -0
- package/data/docs/types/Content.json +2 -2
- package/data/docs/types/DataTable.json +17 -2
- package/data/docs/types/DataTableBody.json +24 -24
- package/data/docs/types/DataTableHeader.json +31 -31
- package/data/docs/types/DataTableRoot.json +17 -2
- package/data/docs/types/DataTableTable.json +35 -20
- package/data/docs/types/DateInput.json +84 -84
- package/data/docs/types/DatePicker.json +65 -65
- package/data/docs/types/DateRangePicker.json +99 -99
- package/data/docs/types/DateRangePickerField.json +99 -99
- package/data/docs/types/DefaultPageBackLink.json +16 -16
- package/data/docs/types/DefaultPageRoot.json +2 -2
- package/data/docs/types/DialogCloseTrigger.json +87 -87
- package/data/docs/types/DialogTrigger.json +2 -2
- package/data/docs/types/DragAndDropItemData.json +9 -0
- package/data/docs/types/DragAndDropProps.json +9 -0
- package/data/docs/types/DraggableListField.json +159 -70
- package/data/docs/types/DraggableListItem.json +63 -63
- package/data/docs/types/DraggableListRoot.json +159 -70
- package/data/docs/types/DrawerCloseTrigger.json +87 -87
- package/data/docs/types/DrawerTrigger.json +2 -2
- package/data/docs/types/FieldErrors.json +2 -2
- package/data/docs/types/Flex.json +22 -22
- package/data/docs/types/Footer.json +6 -6
- package/data/docs/types/FormDialog.json +198 -0
- package/data/docs/types/FormFieldRoot.json +2 -2
- package/data/docs/types/Grid.json +24 -24
- package/data/docs/types/Group.json +12 -12
- package/data/docs/types/Header.json +6 -6
- package/data/docs/types/Heading.json +8 -8
- package/data/docs/types/Icon.json +4 -4
- package/data/docs/types/IconButton.json +97 -97
- package/data/docs/types/IconToggleButton.json +84 -84
- package/data/docs/types/Image.json +30 -30
- package/data/docs/types/Indicator.json +6 -6
- package/data/docs/types/InlineSvg.json +2 -2
- package/data/docs/types/Item.json +6 -6
- package/data/docs/types/Kbd.json +8 -8
- package/data/docs/types/Link.json +31 -31
- package/data/docs/types/ListIndicator.json +6 -6
- package/data/docs/types/ListItem.json +6 -6
- package/data/docs/types/ListRoot.json +10 -10
- package/data/docs/types/LoadingSpinner.json +2 -2
- package/data/docs/types/MakeElementFocusable.json +19 -19
- package/data/docs/types/MenuItem.json +75 -75
- package/data/docs/types/MenuRoot.json +63 -63
- package/data/docs/types/MenuSection.json +35 -54
- package/data/docs/types/MenuSubmenuTrigger.json +5 -5
- package/data/docs/types/MenuTrigger.json +102 -102
- package/data/docs/types/MultilineTextInput.json +134 -134
- package/data/docs/types/MultilineTextInputField.json +131 -131
- package/data/docs/types/NumberInput.json +100 -100
- package/data/docs/types/NumberInputField.json +95 -95
- package/data/docs/types/PageContentColumn.json +6 -6
- package/data/docs/types/PageContentRoot.json +6 -6
- package/data/docs/types/PasswordInput.json +129 -129
- package/data/docs/types/PasswordInputField.json +129 -129
- package/data/docs/types/ProgressBar.json +14 -14
- package/data/docs/types/PublicPageLayout.json +99 -0
- package/data/docs/types/RadioInputOption.json +64 -64
- package/data/docs/types/RadioInputRoot.json +55 -55
- package/data/docs/types/RangeCalendar.json +90 -71
- package/data/docs/types/Region.json +114 -0
- package/data/docs/types/RegionProvider.json +25 -0
- package/data/docs/types/RegionTarget.json +112 -0
- package/data/docs/types/RichTextInput.json +2 -2
- package/data/docs/types/Root.json +10 -10
- package/data/docs/types/Row.json +6 -6
- package/data/docs/types/SPLITTER_SIZE_TOKENS.json +9 -0
- package/data/docs/types/ScrollArea.json +2 -2
- package/data/docs/types/SearchInput.json +136 -136
- package/data/docs/types/SearchInputField.json +131 -131
- package/data/docs/types/SelectOption.json +66 -66
- package/data/docs/types/SelectOptionGroup.json +22 -22
- package/data/docs/types/SelectOptions.json +74 -74
- package/data/docs/types/SelectRoot.json +102 -102
- package/data/docs/types/Separator.json +4 -4
- package/data/docs/types/SimpleGrid.json +28 -28
- package/data/docs/types/SplitButton.json +12 -12
- package/data/docs/types/Splitter.json +12 -0
- package/data/docs/types/SplitterAside.json +27 -0
- package/data/docs/types/SplitterHandle.json +27 -0
- package/data/docs/types/SplitterMain.json +27 -0
- package/data/docs/types/SplitterRoot.json +271 -0
- package/data/docs/types/SplitterSizeToken.json +9 -0
- package/data/docs/types/Stack.json +2 -2
- package/data/docs/types/StepsNextTrigger.json +2 -2
- package/data/docs/types/StepsPrevTrigger.json +2 -2
- package/data/docs/types/StepsRoot.json +2 -2
- package/data/docs/types/StepsTrigger.json +2 -2
- package/data/docs/types/Switch.json +38 -38
- package/data/docs/types/TabNavItem.json +18 -18
- package/data/docs/types/TabNavRoot.json +2 -2
- package/data/docs/types/TableBody.json +6 -6
- package/data/docs/types/TableCaption.json +6 -6
- package/data/docs/types/TableCell.json +20 -20
- package/data/docs/types/TableColumn.json +8 -8
- package/data/docs/types/TableColumnGroup.json +8 -8
- package/data/docs/types/TableColumnHeader.json +18 -18
- package/data/docs/types/TableFooter.json +6 -6
- package/data/docs/types/TableHeader.json +6 -6
- package/data/docs/types/TableRoot.json +32 -32
- package/data/docs/types/TableRow.json +6 -6
- package/data/docs/types/TableScrollArea.json +6 -6
- package/data/docs/types/TabsTab.json +2 -2
- package/data/docs/types/TagGroupRoot.json +27 -27
- package/data/docs/types/TagGroupTag.json +68 -68
- package/data/docs/types/TagGroupTagList.json +18 -18
- package/data/docs/types/Text.json +8 -8
- package/data/docs/types/TextInput.json +132 -132
- package/data/docs/types/TextInputField.json +129 -129
- package/data/docs/types/TimeInput.json +78 -78
- package/data/docs/types/ToggleButton.json +86 -86
- package/data/docs/types/ToggleButtonGroupButton.json +33 -33
- package/data/docs/types/ToggleButtonGroupRoot.json +20 -20
- package/data/docs/types/Toolbar.json +12 -12
- package/data/docs/types/TooltipContent.json +31 -31
- package/data/docs/types/TooltipRoot.json +18 -18
- package/data/docs/types/Trigger.json +4 -4
- package/data/docs/types/UseDragAndDropOptions.json +9 -0
- package/data/docs/types/VisuallyHidden.json +7 -7
- package/data/docs/types/createArrayHandlers.json +12 -0
- package/data/docs/types/createItemsFromCsvDrop.json +833 -0
- package/data/docs/types/createItemsFromDirectoryDrop.json +833 -0
- package/data/docs/types/createItemsFromFileDrop.json +833 -0
- package/data/docs/types/createItemsFromImageDrop.json +833 -0
- package/data/docs/types/createItemsFromJsonDrop.json +833 -0
- package/data/docs/types/createItemsFromTextDrop.json +12 -0
- package/data/docs/types/createListDataHandlers.json +102 -0
- package/data/docs/types/manifest.json +29 -2
- package/data/docs/types/useDragAndDrop.json +174 -0
- package/data/docs/types/useRegion.json +1052 -0
- package/data/docs/types/useResponsiveSplitterSizes.json +143 -0
- package/package.json +6 -6
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"id": "Components-Region",
|
|
4
|
+
"title": "Region",
|
|
5
|
+
"exportName": "Region",
|
|
6
|
+
"description": "A headless primitive for named content projection — render content into a named region elsewhere in the layout while it stays in your React tree.",
|
|
7
|
+
"lifecycleState": "Beta",
|
|
8
|
+
"order": 999,
|
|
9
|
+
"repoPath": "packages/nimbus/src/components/region/region.mdx",
|
|
10
|
+
"menu": [
|
|
11
|
+
"Components",
|
|
12
|
+
"Utilities",
|
|
13
|
+
"Region"
|
|
14
|
+
],
|
|
15
|
+
"route": "components/utilities/region",
|
|
16
|
+
"tags": [
|
|
17
|
+
"component",
|
|
18
|
+
"utility",
|
|
19
|
+
"portal",
|
|
20
|
+
"layout",
|
|
21
|
+
"provider"
|
|
22
|
+
],
|
|
23
|
+
"toc": [
|
|
24
|
+
{
|
|
25
|
+
"value": "Overview",
|
|
26
|
+
"href": "#overview",
|
|
27
|
+
"depth": 2,
|
|
28
|
+
"numbering": [
|
|
29
|
+
1,
|
|
30
|
+
1
|
|
31
|
+
],
|
|
32
|
+
"parent": "root"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"value": "When to use",
|
|
36
|
+
"href": "#when-to-use",
|
|
37
|
+
"depth": 2,
|
|
38
|
+
"numbering": [
|
|
39
|
+
1,
|
|
40
|
+
2
|
|
41
|
+
],
|
|
42
|
+
"parent": "root"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"value": "When not to use",
|
|
46
|
+
"href": "#when-not-to-use",
|
|
47
|
+
"depth": 2,
|
|
48
|
+
"numbering": [
|
|
49
|
+
1,
|
|
50
|
+
3
|
|
51
|
+
],
|
|
52
|
+
"parent": "root"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"value": "Anatomy",
|
|
56
|
+
"href": "#anatomy",
|
|
57
|
+
"depth": 2,
|
|
58
|
+
"numbering": [
|
|
59
|
+
1,
|
|
60
|
+
4
|
|
61
|
+
],
|
|
62
|
+
"parent": "root"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"value": "Example",
|
|
66
|
+
"href": "#example",
|
|
67
|
+
"depth": 2,
|
|
68
|
+
"numbering": [
|
|
69
|
+
1,
|
|
70
|
+
5
|
|
71
|
+
],
|
|
72
|
+
"parent": "root"
|
|
73
|
+
}
|
|
74
|
+
],
|
|
75
|
+
"layout": "app-frame",
|
|
76
|
+
"tabs": [
|
|
77
|
+
{
|
|
78
|
+
"key": "overview",
|
|
79
|
+
"title": "Overview",
|
|
80
|
+
"order": 0
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"key": "dev",
|
|
84
|
+
"title": "Implementation",
|
|
85
|
+
"order": 3
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
},
|
|
89
|
+
"mdx": "\n## Overview\n\nRegion is a headless primitive for **named content projection**: render content\ninto a slot somewhere else in the layout — an aside, a toolbar, a detail pane —\nfrom a component that lives somewhere else entirely, even a different package.\n\nIt is the structured form of `createPortal`. You **place a target** with\n`<Region name=\"…\" />` to mark where a region renders, and **fill it** from\nanywhere with `useRegion(name)`. Projected content paints at the target but stays\na child of its author in the React tree, so all ancestor context — routing, intl,\ndata clients, permissions — is preserved. A target can also publish a **value**\n(typically control callbacks plus state), so its host can hand consumers a way to\ndrive it.\n\nThe scope, `Region.Provider`, is mounted **ambiently inside `NimbusProvider`**, so\nin a Nimbus app you place targets and call `useRegion` without ever wrapping a\nprovider yourself.\n\nRegion renders no visual chrome of its own; it is a coordination primitive, not\na styled component.\n\n## When to use\n\n- A shell or layout owns a slot (a side panel, a header action area) that a\n feature elsewhere needs to fill.\n- Content must be **authored** deep in the tree (to keep its context) but\n **rendered** at a fixed location.\n- A target's host wants to expose controls (open/close, select) to whoever fills\n it, without prop-drilling.\n\nFor a user-resizable two-pane layout, compose Region with\n[Splitter](/components/layout/splitter): mount the splitter, put a\n`<Region name=\"…\" />` in the aside, and let a consumer fill it and toggle it — see\nthe implementation tab.\n\n## When not to use\n\n- You own both the content and its location and they're in the same place — just\n render it directly.\n- You need overlay portalling (modals, tooltips, popovers) — those are handled\n by the overlay components, not Region.\n\n## Anatomy\n\n- **`<Region name=\"…\" />`** — the **target**: marks where a named region renders\n and registers its DOM node. It is layout-transparent (`display: contents`), so\n projected content lays out as a direct child of the target's parent — no extra\n wrapper box. Backed by a `chakra.div`, so it accepts style props; pass\n `display=\"block\"` (etc.) if you want it to be a real box. Can publish a `value`.\n- **`useRegion(name)`** — returns a stable `Region` portal component to fill the\n named region, plus the `value` its target published. Resolves safely (`null`\n value, portal renders nothing) before a target mounts.\n- **`Region.Provider`** — the scope. Mounted ambiently by `NimbusProvider`;\n reuses an ancestor's scope when nested, so you rarely write it directly.\n\nNote the two sides share the name `Region`: the top-level `<Region name>` is the\n**target**, while the `Region` you get from `useRegion` is the **filler**. Place\nwith the former, fill with the latter.\n\n## Example\n\n```jsx live-dev\nconst Sidebar = () => {\n // fill the region — `Region` here is the filler from the hook\n const { Region: Filler } = useRegion(\"docs-sidebar\");\n return (\n <Filler>\n <Box p=\"300\" bg=\"teal.3\">\n Authored over here, painted in the target over there.\n </Box>\n </Filler>\n );\n};\n\nconst App = () => (\n // No Region.Provider needed — NimbusProvider supplies the scope ambiently.\n <Stack direction=\"row\" gap=\"400\">\n <Box flexGrow=\"1\" p=\"300\" bg=\"amber.3\">\n <Text>Content area</Text>\n <Sidebar />\n </Box>\n <Box width=\"240px\" minHeight=\"120px\" bg=\"neutral.3\" p=\"200\">\n <Region name=\"docs-sidebar\" />\n </Box>\n </Stack>\n);\n```\n",
|
|
90
|
+
"views": {
|
|
91
|
+
"overview": {
|
|
92
|
+
"mdx": "\n## Overview\n\nRegion is a headless primitive for **named content projection**: render content\ninto a slot somewhere else in the layout — an aside, a toolbar, a detail pane —\nfrom a component that lives somewhere else entirely, even a different package.\n\nIt is the structured form of `createPortal`. You **place a target** with\n`<Region name=\"…\" />` to mark where a region renders, and **fill it** from\nanywhere with `useRegion(name)`. Projected content paints at the target but stays\na child of its author in the React tree, so all ancestor context — routing, intl,\ndata clients, permissions — is preserved. A target can also publish a **value**\n(typically control callbacks plus state), so its host can hand consumers a way to\ndrive it.\n\nThe scope, `Region.Provider`, is mounted **ambiently inside `NimbusProvider`**, so\nin a Nimbus app you place targets and call `useRegion` without ever wrapping a\nprovider yourself.\n\nRegion renders no visual chrome of its own; it is a coordination primitive, not\na styled component.\n\n## When to use\n\n- A shell or layout owns a slot (a side panel, a header action area) that a\n feature elsewhere needs to fill.\n- Content must be **authored** deep in the tree (to keep its context) but\n **rendered** at a fixed location.\n- A target's host wants to expose controls (open/close, select) to whoever fills\n it, without prop-drilling.\n\nFor a user-resizable two-pane layout, compose Region with\n[Splitter](/components/layout/splitter): mount the splitter, put a\n`<Region name=\"…\" />` in the aside, and let a consumer fill it and toggle it — see\nthe implementation tab.\n\n## When not to use\n\n- You own both the content and its location and they're in the same place — just\n render it directly.\n- You need overlay portalling (modals, tooltips, popovers) — those are handled\n by the overlay components, not Region.\n\n## Anatomy\n\n- **`<Region name=\"…\" />`** — the **target**: marks where a named region renders\n and registers its DOM node. It is layout-transparent (`display: contents`), so\n projected content lays out as a direct child of the target's parent — no extra\n wrapper box. Backed by a `chakra.div`, so it accepts style props; pass\n `display=\"block\"` (etc.) if you want it to be a real box. Can publish a `value`.\n- **`useRegion(name)`** — returns a stable `Region` portal component to fill the\n named region, plus the `value` its target published. Resolves safely (`null`\n value, portal renders nothing) before a target mounts.\n- **`Region.Provider`** — the scope. Mounted ambiently by `NimbusProvider`;\n reuses an ancestor's scope when nested, so you rarely write it directly.\n\nNote the two sides share the name `Region`: the top-level `<Region name>` is the\n**target**, while the `Region` you get from `useRegion` is the **filler**. Place\nwith the former, fill with the latter.\n\n## Example\n\n```jsx live-dev\nconst Sidebar = () => {\n // fill the region — `Region` here is the filler from the hook\n const { Region: Filler } = useRegion(\"docs-sidebar\");\n return (\n <Filler>\n <Box p=\"300\" bg=\"teal.3\">\n Authored over here, painted in the target over there.\n </Box>\n </Filler>\n );\n};\n\nconst App = () => (\n // No Region.Provider needed — NimbusProvider supplies the scope ambiently.\n <Stack direction=\"row\" gap=\"400\">\n <Box flexGrow=\"1\" p=\"300\" bg=\"amber.3\">\n <Text>Content area</Text>\n <Sidebar />\n </Box>\n <Box width=\"240px\" minHeight=\"120px\" bg=\"neutral.3\" p=\"200\">\n <Region name=\"docs-sidebar\" />\n </Box>\n </Stack>\n);\n```\n",
|
|
93
|
+
"toc": [
|
|
94
|
+
{
|
|
95
|
+
"value": "Overview",
|
|
96
|
+
"href": "#overview",
|
|
97
|
+
"depth": 2,
|
|
98
|
+
"numbering": [
|
|
99
|
+
1,
|
|
100
|
+
1
|
|
101
|
+
],
|
|
102
|
+
"parent": "root"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"value": "When to use",
|
|
106
|
+
"href": "#when-to-use",
|
|
107
|
+
"depth": 2,
|
|
108
|
+
"numbering": [
|
|
109
|
+
1,
|
|
110
|
+
2
|
|
111
|
+
],
|
|
112
|
+
"parent": "root"
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"value": "When not to use",
|
|
116
|
+
"href": "#when-not-to-use",
|
|
117
|
+
"depth": 2,
|
|
118
|
+
"numbering": [
|
|
119
|
+
1,
|
|
120
|
+
3
|
|
121
|
+
],
|
|
122
|
+
"parent": "root"
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"value": "Anatomy",
|
|
126
|
+
"href": "#anatomy",
|
|
127
|
+
"depth": 2,
|
|
128
|
+
"numbering": [
|
|
129
|
+
1,
|
|
130
|
+
4
|
|
131
|
+
],
|
|
132
|
+
"parent": "root"
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"value": "Example",
|
|
136
|
+
"href": "#example",
|
|
137
|
+
"depth": 2,
|
|
138
|
+
"numbering": [
|
|
139
|
+
1,
|
|
140
|
+
5
|
|
141
|
+
],
|
|
142
|
+
"parent": "root"
|
|
143
|
+
}
|
|
144
|
+
]
|
|
145
|
+
},
|
|
146
|
+
"dev": {
|
|
147
|
+
"mdx": "\n## Getting started\n\n### Import\n\n```tsx\nimport { Region, useRegion, type RegionProps } from \"@commercetools/nimbus\";\n```\n\n### Mental model\n\n`Region` is the structured form of `createPortal`. Three pieces:\n\n- **`<Region name=\"…\" />`** — the **target**: marks where a named region renders.\n It registers its DOM node under `name` and can publish a `value` (control\n callbacks + state) for consumers.\n- **`useRegion(name)`** — returns `{ Region, value }`: a stable `Region` portal\n component to **fill** the target, and the published `value`.\n- **`Region.Provider`** — the scope. **Mounted ambiently by `NimbusProvider`**, so\n in a Nimbus app you never write it: place targets and call `useRegion`\n directly. It is still exported for standalone use (tests, non-Nimbus roots).\n\nRegions are addressed by **name**, not by tree position — a consumer reaches a\nregion by name regardless of how deeply nested it is. `useRegion` resolves to a\n`null` value (and a portal that renders nothing) before a target mounts, so it is\nalways safe to call.\n\n> **One name, two sides.** The top-level `<Region name>` is the *target*; the\n> `Region` returned by `useRegion` is the *filler*. They can't share a binding in\n> one scope — alias the hook's: `const { Region: Sidebar } = useRegion(\"x\")`.\n\n> **Single occupancy.** A region name is one-to-one on both sides: **exactly one\n> target** and **at most one active filler** at a time. Two targets sharing a name\n> orphan one another (only the last to mount holds the slot); two fillers stack\n> their content into the one target in an undefined order. Both are bugs, so in\n> development each logs a `console.error` naming the region. The fix is always the\n> same — give each its own name. (The registry also releases a target's slot\n> owner-checked, so a stale duplicate unmounting never wipes the live region.)\n\n### Basic usage\n\nContent rendered through the `Region` filler paints at the target but stays a\nchild of its author in the React tree, so all ancestor context (router, intl,\ndata client, permissions) is preserved.\n\n```jsx live-dev\nconst Sidebar = () => {\n const { Region: Filler } = useRegion(\"getting-started-sidebar\");\n return (\n <Filler>\n <Box p=\"300\" bg=\"teal.3\">\n Authored here, painted in the target.\n </Box>\n </Filler>\n );\n};\n\n// No Region.Provider — NimbusProvider supplies the scope ambiently.\nconst App = () => (\n <Stack direction=\"row\" gap=\"400\">\n <Box flexGrow=\"1\" p=\"300\" bg=\"amber.3\">\n <Text>Content area</Text>\n <Sidebar />\n </Box>\n <Box width=\"240px\" minHeight=\"120px\" bg=\"neutral.3\" p=\"200\">\n <Region name=\"getting-started-sidebar\" />\n </Box>\n </Stack>\n);\n```\n\n## Layout: the target renders no box (`display: contents`)\n\nA portal needs a real DOM node as its container — there is no API to portal \"into\na position.\" So `<Region name>` must render *an* element. But it renders that\nelement with **`display: contents`**, which makes the element generate **no box of\nits own**: its children participate in the layout of the target's *parent*, as if\nthe wrapper were not there. Since projected content are DOM children of that\nelement, they lay out exactly where the target sits — a flex/grid parent treats\nthe projected root as a direct child. You get precise layout with no extra wrapper.\n\nConsequences worth knowing:\n\n- A `display: contents` element can't carry its own visual box — no background,\n padding, border, `position: relative`, or scroll container. Put those on the\n **projected content** (or the target's parent) instead.\n- The target is a `chakra.div`, so it accepts style props. To make it a real box\n again, override the display: `<Region name=\"x\" display=\"block\" p=\"400\" />`.\n\n## Publishing a value\n\nA target can publish a `value` so its host hands consumers a way to drive it —\ntypically control callbacks plus reactive state. Consumers read it from\n`useRegion(name).value`.\n\n```tsx\n// host: publish controls on the target\n<Region name=\"detail\" value={{ isOpen, open, close }} />;\n\n// consumer: read them\nconst { value } = useRegion<DetailControls>(\"detail\");\nvalue?.open();\n```\n\nType the value at the consumer boundary with `useRegion<T>` — the registry treats\nit as opaque, so the generic is where the shape is declared.\n\n## Composition: a shell-owned side panel (with Splitter)\n\n`Region` composes with [Splitter](/components/layout/splitter) to build a\nshell-owned, remotely-controlled side panel — **without the Splitter depending on\nRegion**. The shell mounts the splitter, puts a `<Region name>` in the aside that\npublishes the collapse controls, and drives the splitter through its existing\ncontrolled `collapsed` / `onCollapsedChange`. A consumer anywhere fills the pane\nand opens/closes it via `useRegion`.\n\n```tsx\nconst ShellSidePanel = ({ children }) => {\n const [open, setOpen] = useState(false);\n\n // Stable callbacks; value memoized on the reactive bit (see Performance below).\n const commands = useRef({\n expand: () => setOpen(true),\n collapse: () => setOpen(false),\n toggle: () => setOpen((o) => !o),\n }).current;\n const controller = useMemo(\n () => ({ isCollapsed: !open, ...commands }),\n [open, commands]\n );\n\n return (\n <Splitter.Root collapsible collapsed={!open} onCollapsedChange={(c) => setOpen(!c)}>\n <Splitter.Main>{children}</Splitter.Main>\n <Splitter.Handle />\n <Splitter.Aside>\n <Region name=\"app-side-panel\" value={controller} />\n </Splitter.Aside>\n </Splitter.Root>\n );\n};\n\n// A consumer that owns no splitter markup:\nconst SidePanel = ({ panel }) => {\n const { Region: Aside, value } = useRegion(\"app-side-panel\");\n const expand = value?.expand;\n const collapse = value?.collapse;\n useEffect(() => {\n expand?.();\n return () => collapse?.();\n }, [expand, collapse]);\n return <Aside>{panel}</Aside>;\n};\n```\n\n## Performance\n\n`Region.Provider` wraps the entire application (it's inside `NimbusProvider`), so\nfilling a region must not re-render the app. That holds because of four things —\none in the primitive, three at your call site:\n\n1. **External store (primitive).** The registry is read via\n `useSyncExternalStore`. Publishing a node or value notifies only that name's\n consumers; `Region.Provider` itself never re-renders.\n2. **Stable `children` (host).** Pass the app through as a `children` prop so the\n host's own state changes (e.g. a collapse toggle) bail out of the app subtree\n rather than re-rendering it.\n3. **Stable callbacks + memoized value (host).** Keep published callbacks\n ref-backed so their identity never changes, and `useMemo` the value object on\n its reactive field. Registering then only churns when something meaningful\n changes.\n4. **Depend on the callbacks, not the value object (consumer).** A published\n value object changes identity when its reactive state changes. In effects,\n depend on the stable callbacks (`value?.expand`), not the whole `value` —\n otherwise an expand-on-mount effect re-runs on every state change and can\n ping-pong.\n\n## SSR\n\n`useRegion` and the `Region` filler use a server snapshot of `null`: there are no\ntargets during server rendering and `createPortal` is client-only. A region\ntherefore resolves to nothing on the server and hydrates on the client. Author\ncontent unconditionally and let the portal render it once the target mounts.\n\n## Nested providers share one namespace\n\n`Region.Provider` reuses an ancestor's registry when nested — it does not create\nan isolated scope. Two targets with the same name collide even if they live under\ndifferent `Region.Provider` wrappers. If you need logical isolation between\nsubsystems, use a naming convention (e.g. `\"app-shell:sidebar\"` vs\n`\"admin:sidebar\"`).\n\n## When not to use\n\n- You own both the content and its location and they're co-located — render it\n directly.\n- You need overlay portalling (modals, tooltips, popovers) — use the overlay\n components, not `Region`.\n",
|
|
148
|
+
"toc": [
|
|
149
|
+
{
|
|
150
|
+
"value": "Getting started",
|
|
151
|
+
"href": "#getting-started",
|
|
152
|
+
"depth": 2,
|
|
153
|
+
"numbering": [
|
|
154
|
+
1,
|
|
155
|
+
1
|
|
156
|
+
],
|
|
157
|
+
"parent": "root"
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
"value": "Import",
|
|
161
|
+
"href": "#import",
|
|
162
|
+
"depth": 3,
|
|
163
|
+
"numbering": [
|
|
164
|
+
1,
|
|
165
|
+
1,
|
|
166
|
+
1
|
|
167
|
+
],
|
|
168
|
+
"parent": "root"
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
"value": "Mental model",
|
|
172
|
+
"href": "#mental-model",
|
|
173
|
+
"depth": 3,
|
|
174
|
+
"numbering": [
|
|
175
|
+
1,
|
|
176
|
+
1,
|
|
177
|
+
2
|
|
178
|
+
],
|
|
179
|
+
"parent": "root"
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
"value": "Basic usage",
|
|
183
|
+
"href": "#basic-usage",
|
|
184
|
+
"depth": 3,
|
|
185
|
+
"numbering": [
|
|
186
|
+
1,
|
|
187
|
+
1,
|
|
188
|
+
3
|
|
189
|
+
],
|
|
190
|
+
"parent": "root"
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
"value": "Layout: the target renders no box (display: contents)",
|
|
194
|
+
"href": "#layout-the-target-renders-no-box-display-contents",
|
|
195
|
+
"depth": 2,
|
|
196
|
+
"numbering": [
|
|
197
|
+
1,
|
|
198
|
+
2
|
|
199
|
+
],
|
|
200
|
+
"parent": "root"
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
"value": "Publishing a value",
|
|
204
|
+
"href": "#publishing-a-value",
|
|
205
|
+
"depth": 2,
|
|
206
|
+
"numbering": [
|
|
207
|
+
1,
|
|
208
|
+
3
|
|
209
|
+
],
|
|
210
|
+
"parent": "root"
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
"value": "Composition: a shell-owned side panel (with Splitter)",
|
|
214
|
+
"href": "#composition-a-shell-owned-side-panel-with-splitter",
|
|
215
|
+
"depth": 2,
|
|
216
|
+
"numbering": [
|
|
217
|
+
1,
|
|
218
|
+
4
|
|
219
|
+
],
|
|
220
|
+
"parent": "root"
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
"value": "Performance",
|
|
224
|
+
"href": "#performance",
|
|
225
|
+
"depth": 2,
|
|
226
|
+
"numbering": [
|
|
227
|
+
1,
|
|
228
|
+
5
|
|
229
|
+
],
|
|
230
|
+
"parent": "root"
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
"value": "SSR",
|
|
234
|
+
"href": "#ssr",
|
|
235
|
+
"depth": 2,
|
|
236
|
+
"numbering": [
|
|
237
|
+
1,
|
|
238
|
+
6
|
|
239
|
+
],
|
|
240
|
+
"parent": "root"
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
"value": "Nested providers share one namespace",
|
|
244
|
+
"href": "#nested-providers-share-one-namespace",
|
|
245
|
+
"depth": 2,
|
|
246
|
+
"numbering": [
|
|
247
|
+
1,
|
|
248
|
+
7
|
|
249
|
+
],
|
|
250
|
+
"parent": "root"
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
"value": "When not to use",
|
|
254
|
+
"href": "#when-not-to-use",
|
|
255
|
+
"depth": 2,
|
|
256
|
+
"numbering": [
|
|
257
|
+
1,
|
|
258
|
+
8
|
|
259
|
+
],
|
|
260
|
+
"parent": "root"
|
|
261
|
+
}
|
|
262
|
+
]
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"id": "Home-BundlerPlugins-1749667200000",
|
|
4
|
+
"title": "Bundler Plugins",
|
|
5
|
+
"description": "Webpack and Vite plugins for optional Nimbus dependency resolution",
|
|
6
|
+
"order": 7,
|
|
7
|
+
"repoPath": "packages/nimbus/src/docs/home-bundler-plugins.mdx",
|
|
8
|
+
"menu": [
|
|
9
|
+
"Home",
|
|
10
|
+
"Getting Started",
|
|
11
|
+
"Bundler Plugins"
|
|
12
|
+
],
|
|
13
|
+
"route": "home/getting-started/bundler-plugins",
|
|
14
|
+
"tags": [
|
|
15
|
+
"guide",
|
|
16
|
+
"plugins",
|
|
17
|
+
"webpack",
|
|
18
|
+
"vite",
|
|
19
|
+
"build",
|
|
20
|
+
"optional-dependency"
|
|
21
|
+
],
|
|
22
|
+
"toc": [
|
|
23
|
+
{
|
|
24
|
+
"value": "When to use",
|
|
25
|
+
"href": "#when-to-use",
|
|
26
|
+
"depth": 2,
|
|
27
|
+
"numbering": [
|
|
28
|
+
1,
|
|
29
|
+
1
|
|
30
|
+
],
|
|
31
|
+
"parent": "root"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"value": "Entry points",
|
|
35
|
+
"href": "#entry-points",
|
|
36
|
+
"depth": 2,
|
|
37
|
+
"numbering": [
|
|
38
|
+
1,
|
|
39
|
+
2
|
|
40
|
+
],
|
|
41
|
+
"parent": "root"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"value": "Vite",
|
|
45
|
+
"href": "#vite",
|
|
46
|
+
"depth": 2,
|
|
47
|
+
"numbering": [
|
|
48
|
+
1,
|
|
49
|
+
3
|
|
50
|
+
],
|
|
51
|
+
"parent": "root"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"value": "Webpack",
|
|
55
|
+
"href": "#webpack",
|
|
56
|
+
"depth": 2,
|
|
57
|
+
"numbering": [
|
|
58
|
+
1,
|
|
59
|
+
4
|
|
60
|
+
],
|
|
61
|
+
"parent": "root"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"value": "How detection works",
|
|
65
|
+
"href": "#how-detection-works",
|
|
66
|
+
"depth": 2,
|
|
67
|
+
"numbering": [
|
|
68
|
+
1,
|
|
69
|
+
5
|
|
70
|
+
],
|
|
71
|
+
"parent": "root"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"value": "What gets stubbed",
|
|
75
|
+
"href": "#what-gets-stubbed",
|
|
76
|
+
"depth": 2,
|
|
77
|
+
"numbering": [
|
|
78
|
+
1,
|
|
79
|
+
6
|
|
80
|
+
],
|
|
81
|
+
"parent": "root"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"value": "Writing safe shared code",
|
|
85
|
+
"href": "#writing-safe-shared-code",
|
|
86
|
+
"depth": 2,
|
|
87
|
+
"numbering": [
|
|
88
|
+
1,
|
|
89
|
+
7
|
|
90
|
+
],
|
|
91
|
+
"parent": "root"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"value": "Guard with a runtime check",
|
|
95
|
+
"href": "#guard-with-a-runtime-check",
|
|
96
|
+
"depth": 3,
|
|
97
|
+
"numbering": [
|
|
98
|
+
1,
|
|
99
|
+
7,
|
|
100
|
+
1
|
|
101
|
+
],
|
|
102
|
+
"parent": "root"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"value": "Guard with lazy imports",
|
|
106
|
+
"href": "#guard-with-lazy-imports",
|
|
107
|
+
"depth": 3,
|
|
108
|
+
"numbering": [
|
|
109
|
+
1,
|
|
110
|
+
7,
|
|
111
|
+
2
|
|
112
|
+
],
|
|
113
|
+
"parent": "root"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"value": "Feature flags",
|
|
117
|
+
"href": "#feature-flags",
|
|
118
|
+
"depth": 3,
|
|
119
|
+
"numbering": [
|
|
120
|
+
1,
|
|
121
|
+
7,
|
|
122
|
+
3
|
|
123
|
+
],
|
|
124
|
+
"parent": "root"
|
|
125
|
+
}
|
|
126
|
+
],
|
|
127
|
+
"icon": "Extension",
|
|
128
|
+
"layout": "app-frame",
|
|
129
|
+
"tabs": [
|
|
130
|
+
{
|
|
131
|
+
"key": "overview",
|
|
132
|
+
"title": "Overview",
|
|
133
|
+
"order": 0
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
},
|
|
137
|
+
"mdx": "\n# Bundler Plugins\n\nNimbus ships Vite and webpack plugins that let build tools treat\n`@commercetools/nimbus` as an **optional dependency**. When Nimbus is installed,\nthe plugins are no-ops. When it is not installed, they stub every Nimbus import\nso the build succeeds and zero Nimbus code lands in the bundle.\n\n**The plugins solve build errors, not runtime errors.** Stubbed imports resolve\nto `undefined` — any code that renders a Nimbus component or calls a Nimbus\nfunction will fail at runtime unless it is guarded. See\n[Writing safe shared code](#writing-safe-shared-code) for patterns.\n\n## When to use\n\nUse these plugins in **shared build tooling** that produces bundles for\napplications that may or may not depend on Nimbus. Without the plugins, any\n`import … from '@commercetools/nimbus'` in shared code causes a build failure\nfor apps that haven't installed Nimbus.\n\nThe typical scenario: a shared package imports Nimbus components but is consumed\nby both Nimbus-enabled apps and non-Nimbus apps. The plugins let the shared\npackage compile in both environments. The shared code itself is responsible for\nchecking whether Nimbus is available before rendering anything from it.\n\n## Entry points\n\n| Entry point | Export |\n| --------------------------------------- | -------------------------------- |\n| `@commercetools/nimbus/plugins/vite` | `UNSAFE_nimbusOptionalDependency` |\n| `@commercetools/nimbus/plugins/webpack` | `UNSAFE_NimbusOptionalDependencyPlugin` |\n| `@commercetools/nimbus/plugins/stub` | _(empty CJS module)_ |\n\nAll entry points are standalone — they do **not** import the Nimbus runtime.\n\n## Vite\n\n```ts\n// vite.config.ts\nimport { UNSAFE_nimbusOptionalDependency } from \"@commercetools/nimbus/plugins/vite\";\n\nexport default defineConfig({\n plugins: [UNSAFE_nimbusOptionalDependency()],\n});\n```\n\nThe plugin runs with `enforce: \"pre\"` so its `resolveId` hook fires before\nVite's default resolver (required in monorepos where Vite would otherwise follow\nthe workspace symlink). Matching imports are redirected via `resolveId` + `load`\nto a virtual CJS module (`module.exports = {}`). The `.cjs` extension on the\nvirtual ID triggers Rolldown's CJS-to-ESM interop, allowing named imports to\nresolve to `undefined` at runtime instead of failing with `MISSING_EXPORT`. No\nphysical file is written to disk.\n\n## Webpack\n\n```js\n// webpack.config.js\nconst {\n UNSAFE_NimbusOptionalDependencyPlugin,\n} = require(\"@commercetools/nimbus/plugins/webpack\");\n\nmodule.exports = {\n plugins: [new UNSAFE_NimbusOptionalDependencyPlugin()],\n};\n```\n\nThe plugin accesses webpack's built-in `NormalModuleReplacementPlugin` via\n`compiler.webpack` (webpack 5+). It redirects matching imports to the physical\n`@commercetools/nimbus/plugins/stub` entry point (`module.exports = {}`).\nWebpack's CJS-to-ESM interop is natively lenient — unmatched named imports\nresolve to `undefined` at runtime without a build error.\n\n## How detection works\n\nAt build startup, the plugin calls:\n\n```js\nrequire.resolve(\"@commercetools/nimbus\", { paths: [process.cwd()] });\n```\n\n- **Resolves** → Nimbus is installed. The plugin becomes a **no-op**.\n- **Throws** → Nimbus is not installed. The plugin activates and stubs all\n matching imports.\n\n`{ paths: [process.cwd()] }` checks from the **application root**, not the\nplugin's own `node_modules`. This matters in monorepos where the build tool may\nhave Nimbus while the app being built does not.\n\nBoth plugins accept a `{ cwd }` option to override detection, and\n`{ UNSAFE_forceStub: true }` to bypass detection entirely — useful when\ndependency hoisting causes Nimbus to resolve from a parent `node_modules` even\nthough the app never declared it.\n\n## What gets stubbed\n\n| Import | Stubbed? |\n| --------------------------------------------- | -------- |\n| `@commercetools/nimbus` | Yes |\n| `@commercetools/nimbus/components/Button` | Yes |\n| `@commercetools/nimbus/setup-jsdom-polyfills` | Yes |\n| `@commercetools/nimbus/plugins/webpack` | No |\n| `@commercetools/nimbus/plugins/vite` | No |\n| `@commercetools/nimbus/plugins/stub` | No |\n| `@commercetools/nimbus/plugins` | No |\n| `@commercetools/nimbus-icons` | No |\n| `@commercetools/nimbus-tokens` | No |\n\nThe `/plugins` and `/plugins/*` subpaths are excluded to avoid circular\nreplacement.\n\n## Writing safe shared code\n\nWhen stubbing is active, every named import from `@commercetools/nimbus`\n(`Button`, `NimbusProvider`, etc.) is `undefined`. Default and namespace imports\n(`import Nimbus from …` or `import * as Nimbus from …`) resolve to the truthy\n`{}` stub object — guard with individual named imports, not `if (!Nimbus)`.\n\nCode that uses these values without a guard will crash at runtime. The build will not warn you — from the\nbundler's perspective, the import succeeded.\n\n### Guard with a runtime check\n\n```tsx\nimport { Button } from \"@commercetools/nimbus\";\n\nfunction MyAction({ label, onClick }) {\n // Button is undefined when Nimbus is stubbed out\n if (!Button) {\n return <button onClick={onClick}>{label}</button>;\n }\n return <Button onPress={onClick}>{label}</Button>;\n}\n```\n\n### Guard with lazy imports\n\n```tsx\nconst NimbusButton = lazy(() =>\n import(\"@commercetools/nimbus\").then((m) => ({ default: m.Button }))\n);\n\nfunction MyAction({ label, onClick }) {\n return (\n <Suspense fallback={<button onClick={onClick}>{label}</button>}>\n <NimbusButton onPress={onClick}>{label}</NimbusButton>\n </Suspense>\n );\n}\n```\n\n### Feature flags\n\nIf your app already has a feature-flag system, gate the entire Nimbus code path\nbehind a flag rather than checking individual imports:\n\n```tsx\nif (flags.nimbusEnabled) {\n return <NimbusButton onPress={onClick}>{label}</NimbusButton>;\n}\nreturn <button onClick={onClick}>{label}</button>;\n```\n\nThe key principle: **the plugins make the build pass, your code makes the app\nwork.** Any path that touches a Nimbus import must handle the possibility that\nit resolved to `undefined`.\n",
|
|
138
|
+
"views": {
|
|
139
|
+
"overview": {
|
|
140
|
+
"mdx": "\n# Bundler Plugins\n\nNimbus ships Vite and webpack plugins that let build tools treat\n`@commercetools/nimbus` as an **optional dependency**. When Nimbus is installed,\nthe plugins are no-ops. When it is not installed, they stub every Nimbus import\nso the build succeeds and zero Nimbus code lands in the bundle.\n\n**The plugins solve build errors, not runtime errors.** Stubbed imports resolve\nto `undefined` — any code that renders a Nimbus component or calls a Nimbus\nfunction will fail at runtime unless it is guarded. See\n[Writing safe shared code](#writing-safe-shared-code) for patterns.\n\n## When to use\n\nUse these plugins in **shared build tooling** that produces bundles for\napplications that may or may not depend on Nimbus. Without the plugins, any\n`import … from '@commercetools/nimbus'` in shared code causes a build failure\nfor apps that haven't installed Nimbus.\n\nThe typical scenario: a shared package imports Nimbus components but is consumed\nby both Nimbus-enabled apps and non-Nimbus apps. The plugins let the shared\npackage compile in both environments. The shared code itself is responsible for\nchecking whether Nimbus is available before rendering anything from it.\n\n## Entry points\n\n| Entry point | Export |\n| --------------------------------------- | -------------------------------- |\n| `@commercetools/nimbus/plugins/vite` | `UNSAFE_nimbusOptionalDependency` |\n| `@commercetools/nimbus/plugins/webpack` | `UNSAFE_NimbusOptionalDependencyPlugin` |\n| `@commercetools/nimbus/plugins/stub` | _(empty CJS module)_ |\n\nAll entry points are standalone — they do **not** import the Nimbus runtime.\n\n## Vite\n\n```ts\n// vite.config.ts\nimport { UNSAFE_nimbusOptionalDependency } from \"@commercetools/nimbus/plugins/vite\";\n\nexport default defineConfig({\n plugins: [UNSAFE_nimbusOptionalDependency()],\n});\n```\n\nThe plugin runs with `enforce: \"pre\"` so its `resolveId` hook fires before\nVite's default resolver (required in monorepos where Vite would otherwise follow\nthe workspace symlink). Matching imports are redirected via `resolveId` + `load`\nto a virtual CJS module (`module.exports = {}`). The `.cjs` extension on the\nvirtual ID triggers Rolldown's CJS-to-ESM interop, allowing named imports to\nresolve to `undefined` at runtime instead of failing with `MISSING_EXPORT`. No\nphysical file is written to disk.\n\n## Webpack\n\n```js\n// webpack.config.js\nconst {\n UNSAFE_NimbusOptionalDependencyPlugin,\n} = require(\"@commercetools/nimbus/plugins/webpack\");\n\nmodule.exports = {\n plugins: [new UNSAFE_NimbusOptionalDependencyPlugin()],\n};\n```\n\nThe plugin accesses webpack's built-in `NormalModuleReplacementPlugin` via\n`compiler.webpack` (webpack 5+). It redirects matching imports to the physical\n`@commercetools/nimbus/plugins/stub` entry point (`module.exports = {}`).\nWebpack's CJS-to-ESM interop is natively lenient — unmatched named imports\nresolve to `undefined` at runtime without a build error.\n\n## How detection works\n\nAt build startup, the plugin calls:\n\n```js\nrequire.resolve(\"@commercetools/nimbus\", { paths: [process.cwd()] });\n```\n\n- **Resolves** → Nimbus is installed. The plugin becomes a **no-op**.\n- **Throws** → Nimbus is not installed. The plugin activates and stubs all\n matching imports.\n\n`{ paths: [process.cwd()] }` checks from the **application root**, not the\nplugin's own `node_modules`. This matters in monorepos where the build tool may\nhave Nimbus while the app being built does not.\n\nBoth plugins accept a `{ cwd }` option to override detection, and\n`{ UNSAFE_forceStub: true }` to bypass detection entirely — useful when\ndependency hoisting causes Nimbus to resolve from a parent `node_modules` even\nthough the app never declared it.\n\n## What gets stubbed\n\n| Import | Stubbed? |\n| --------------------------------------------- | -------- |\n| `@commercetools/nimbus` | Yes |\n| `@commercetools/nimbus/components/Button` | Yes |\n| `@commercetools/nimbus/setup-jsdom-polyfills` | Yes |\n| `@commercetools/nimbus/plugins/webpack` | No |\n| `@commercetools/nimbus/plugins/vite` | No |\n| `@commercetools/nimbus/plugins/stub` | No |\n| `@commercetools/nimbus/plugins` | No |\n| `@commercetools/nimbus-icons` | No |\n| `@commercetools/nimbus-tokens` | No |\n\nThe `/plugins` and `/plugins/*` subpaths are excluded to avoid circular\nreplacement.\n\n## Writing safe shared code\n\nWhen stubbing is active, every named import from `@commercetools/nimbus`\n(`Button`, `NimbusProvider`, etc.) is `undefined`. Default and namespace imports\n(`import Nimbus from …` or `import * as Nimbus from …`) resolve to the truthy\n`{}` stub object — guard with individual named imports, not `if (!Nimbus)`.\n\nCode that uses these values without a guard will crash at runtime. The build will not warn you — from the\nbundler's perspective, the import succeeded.\n\n### Guard with a runtime check\n\n```tsx\nimport { Button } from \"@commercetools/nimbus\";\n\nfunction MyAction({ label, onClick }) {\n // Button is undefined when Nimbus is stubbed out\n if (!Button) {\n return <button onClick={onClick}>{label}</button>;\n }\n return <Button onPress={onClick}>{label}</Button>;\n}\n```\n\n### Guard with lazy imports\n\n```tsx\nconst NimbusButton = lazy(() =>\n import(\"@commercetools/nimbus\").then((m) => ({ default: m.Button }))\n);\n\nfunction MyAction({ label, onClick }) {\n return (\n <Suspense fallback={<button onClick={onClick}>{label}</button>}>\n <NimbusButton onPress={onClick}>{label}</NimbusButton>\n </Suspense>\n );\n}\n```\n\n### Feature flags\n\nIf your app already has a feature-flag system, gate the entire Nimbus code path\nbehind a flag rather than checking individual imports:\n\n```tsx\nif (flags.nimbusEnabled) {\n return <NimbusButton onPress={onClick}>{label}</NimbusButton>;\n}\nreturn <button onClick={onClick}>{label}</button>;\n```\n\nThe key principle: **the plugins make the build pass, your code makes the app\nwork.** Any path that touches a Nimbus import must handle the possibility that\nit resolved to `undefined`.\n",
|
|
141
|
+
"toc": [
|
|
142
|
+
{
|
|
143
|
+
"value": "When to use",
|
|
144
|
+
"href": "#when-to-use",
|
|
145
|
+
"depth": 2,
|
|
146
|
+
"numbering": [
|
|
147
|
+
1,
|
|
148
|
+
1
|
|
149
|
+
],
|
|
150
|
+
"parent": "root"
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"value": "Entry points",
|
|
154
|
+
"href": "#entry-points",
|
|
155
|
+
"depth": 2,
|
|
156
|
+
"numbering": [
|
|
157
|
+
1,
|
|
158
|
+
2
|
|
159
|
+
],
|
|
160
|
+
"parent": "root"
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"value": "Vite",
|
|
164
|
+
"href": "#vite",
|
|
165
|
+
"depth": 2,
|
|
166
|
+
"numbering": [
|
|
167
|
+
1,
|
|
168
|
+
3
|
|
169
|
+
],
|
|
170
|
+
"parent": "root"
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
"value": "Webpack",
|
|
174
|
+
"href": "#webpack",
|
|
175
|
+
"depth": 2,
|
|
176
|
+
"numbering": [
|
|
177
|
+
1,
|
|
178
|
+
4
|
|
179
|
+
],
|
|
180
|
+
"parent": "root"
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
"value": "How detection works",
|
|
184
|
+
"href": "#how-detection-works",
|
|
185
|
+
"depth": 2,
|
|
186
|
+
"numbering": [
|
|
187
|
+
1,
|
|
188
|
+
5
|
|
189
|
+
],
|
|
190
|
+
"parent": "root"
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
"value": "What gets stubbed",
|
|
194
|
+
"href": "#what-gets-stubbed",
|
|
195
|
+
"depth": 2,
|
|
196
|
+
"numbering": [
|
|
197
|
+
1,
|
|
198
|
+
6
|
|
199
|
+
],
|
|
200
|
+
"parent": "root"
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
"value": "Writing safe shared code",
|
|
204
|
+
"href": "#writing-safe-shared-code",
|
|
205
|
+
"depth": 2,
|
|
206
|
+
"numbering": [
|
|
207
|
+
1,
|
|
208
|
+
7
|
|
209
|
+
],
|
|
210
|
+
"parent": "root"
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
"value": "Guard with a runtime check",
|
|
214
|
+
"href": "#guard-with-a-runtime-check",
|
|
215
|
+
"depth": 3,
|
|
216
|
+
"numbering": [
|
|
217
|
+
1,
|
|
218
|
+
7,
|
|
219
|
+
1
|
|
220
|
+
],
|
|
221
|
+
"parent": "root"
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
"value": "Guard with lazy imports",
|
|
225
|
+
"href": "#guard-with-lazy-imports",
|
|
226
|
+
"depth": 3,
|
|
227
|
+
"numbering": [
|
|
228
|
+
1,
|
|
229
|
+
7,
|
|
230
|
+
2
|
|
231
|
+
],
|
|
232
|
+
"parent": "root"
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
"value": "Feature flags",
|
|
236
|
+
"href": "#feature-flags",
|
|
237
|
+
"depth": 3,
|
|
238
|
+
"numbering": [
|
|
239
|
+
1,
|
|
240
|
+
7,
|
|
241
|
+
3
|
|
242
|
+
],
|
|
243
|
+
"parent": "root"
|
|
244
|
+
}
|
|
245
|
+
]
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|