Skip to content

Commit 13dc7a4

Browse files
authored
feat(compat): enable scoping for custom elements in compat package only (#7514)
1 parent 98ede3f commit 13dc7a4

File tree

11 files changed

+58
-13
lines changed

11 files changed

+58
-13
lines changed

.storybook/preview.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import './scoping.js';
12
import '@ui5/webcomponents-icons/dist/AllIcons.js';
23
import '@ui5/webcomponents-base/dist/features/F6Navigation.js';
34
import type { Preview } from '@storybook/react';

.storybook/scoping.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { setCompatCustomElementsScopingSuffix } from '@ui5/webcomponents-compat/dist/utils/CompatCustomElementsScope.js';
2+
3+
setCompatCustomElementsScopingSuffix('compat');

packages/cli/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ You can find an interactive documentation in our [Storybook](https://sap.github.
1616

1717
- [Wrapper generation](https://sap.github.io/ui5-webcomponents-react/v2/?path=/docs/knowledge-base-bring-your-own-web-components--docs)
1818
- [Code-mod](https://sap.github.io/ui5-webcomponents-react/v2/?path=/docs/migration-guide--docs#codemod)
19-
- [Patch compatibility table](https://sap.github.io/ui5-webcomponents-react/v2/?path=/docs/legacy-components-docs--docs#experimental-patch-script)
19+
- ~~[Patch compatibility table](https://sap.github.io/ui5-webcomponents-react/v2/?path=/docs/legacy-components-docs--docs#experimental-patch-script)~~ (deprecated in favor of [compatibility package scoping](https://sap.github.io/ui5-webcomponents-react/v2/?path=/docs/legacy-components-docs--docs#using-the-compat-v1-table-together-with-the-v2-table-in-one-application))
2020

2121
## Contribute
2222

packages/cli/src/bin/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ switch (command) {
125125

126126
case 'patch-compat-table': {
127127
const patchesPath = relative(process.cwd(), fileURLToPath(new URL('../../patches', import.meta.url)));
128-
128+
console.warn(
129+
'This command is deprecated and will be removed in the future. Please apply scoping to the "compat" table and its subcomponents manually: https://sap.github.io/ui5-webcomponents-react/v2/?path=/docs/legacy-components-docs--docs#using-the-compat-v1-table-together-with-the-v2-table-in-one-application',
130+
);
129131
try {
130132
await $`patch-package --patch-dir ${patchesPath}`;
131133
console.log('Patches applied successfully!');

packages/compat/README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ Components in this package will not receive any new features. Only critical bugs
1414
npm install @ui5/webcomponents-react-compat
1515
```
1616

17-
> ⚠️ **Warning:** It is not supported using the v1 `Table` and the v2 `Table` in the same application!
17+
> ⚠️ **Warning:** It is not supported using the v1 `Table` and the v2 `Table` in the same application without "compat" package scoping!
1818
1919
> ⚠️ **Warning:** Please only import components from this package via the file path!
2020
2121
## Compatibility
2222

23-
The legacy v1 (compat) `Table` and the modern v2 `Table` component and some subcomponents both register the same custom element names for `ui5-table`, `ui5-table-row` and `ui5-table-cell`, which will lead to conflicts when they coexist in the same application.
23+
The legacy v1 (compat) `Table` and the modern v2 `Table` component and some subcomponents both register the same custom element names for `ui5-table`, `ui5-table-row` and `ui5-table-cell`, which will lead to conflicts when they coexist in the same application. To solve this, please see the section about scoping below.
2424

2525
### Recommendation
2626

@@ -44,13 +44,32 @@ Following are the imports of duplicate custom element names:
4444
- `TableCell` (`ui5-table-cell`): `import "@ui5/webcomponents-compat/dist/TableCell.js";`
4545
- `TableRow` (`ui5-table-row`): `import "@ui5/webcomponents-compat/dist/TableRow.js";`
4646

47-
### Experimental Patch Script
47+
### Using the Compat (v1) Table Together with the v2 Table in One Application
48+
49+
As of **v2.12.0** of `@ui5/webcomponents-compat`, a dedicated **scoping mechanism** is available for custom elements from the compat package.
50+
51+
> **Note:** This feature is different from the general [scoping mechanism](https://sap.github.io/ui5-webcomponents/docs/advanced/scoping/) and applies **only** to custom elements from the compatibility package (Table and its subcomponents).
52+
53+
Setting up scoping for the compat package is done in the same way as general scoping, but with specific methods coming from `@ui5/webcomponents-compat`.
54+
55+
```js
56+
//scoping.js
57+
import { setCompatCustomElementsScopingSuffix } from '@ui5/webcomponents-compat/dist/utils/CompatCustomElementsScope.js';
58+
setCompatCustomElementsScopingSuffix('compat');
59+
60+
// app main file, e.g index.js, main.tsx, etc.
61+
import './scoping.js';
62+
// now, all other component imports - the scoping config import must be the first import of the app
63+
import { Table } from '@ui5/webcomponents-react-compat';
64+
```
65+
66+
### Experimental Patch Script (deprecated)
67+
68+
> ⚠️ **Deprecated**: This script is deprecated in favor of scoping the "compat" package components!
4869
4970
The `patch-compat-table` script (included in the `@ui5/webcomponents-react-cli` package) is developed to address specific compatibility issues that arise when using the legacy v1 Table component in conjunction with the `FilterBar` or `VariantManagement` components. These components internally rely on the v2 `Table`, and therefore conflicts will occur when using the v1 `Table`.
5071
The script will change the custom element name by adding a `-v1` suffix (via [patch-package](https://github.com/ds300/patch-package)) to all duplicate v1 table components.
5172

52-
> ⚠️ **Experimental**: This script is in experimental state and not subject to semantic versioning.
53-
5473
> ⚠️ **Temporary Solution:** This script is intended as a temporary workaround. It is strongly recommended to plan for a migration to the v2 Table component to ensure long-term compatibility and support.
5574
5675
<details style="cursor:auto;">

packages/compat/src/components/Table/Table.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import * as ComponentStories from './Table.stories';
1616
children={
1717
<Text>
1818
Using the Table from the <code>compat</code> package and the <code>main</code> package in the same application is
19-
not supported!
19+
not supported without scoping the compat package.
2020
</Text>
2121
}
2222
design="Critical"

packages/compat/src/components/Table/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ import type {
88
import type { TableRowClickEventDetail } from '@ui5/webcomponents-compat/dist/TableRow.js';
99
import type TableGrowingMode from '@ui5/webcomponents-compat/dist/types/TableGrowingMode.js';
1010
import type TableMode from '@ui5/webcomponents-compat/dist/types/TableMode.js';
11+
import { getCompatCustomElementsScopingSuffix } from '@ui5/webcomponents-compat/dist/utils/CompatCustomElementsScope.js';
1112
import type { CommonProps, Ui5CustomEvent, Ui5DomRef, UI5WCSlotsNode } from '@ui5/webcomponents-react-base';
1213
import { withWebComponent } from '@ui5/webcomponents-react-base/dist/wrapper/withWebComponent.js';
1314
import type { ReactNode } from 'react';
1415

16+
const compatScopingSuffix = getCompatCustomElementsScopingSuffix();
17+
const tagSuffix = compatScopingSuffix ? `-${compatScopingSuffix}` : '';
18+
1519
interface TableAttributes {
1620
/**
1721
* Defines the accessible ARIA name of the component.
@@ -269,7 +273,7 @@ interface TablePropTypes
269273
* @deprecated Deprecated as of version 2.12.0, use `@ui5/webcomponents/dist/Table.js` instead.
270274
*/
271275
const Table = withWebComponent<TablePropTypes, TableDomRef>(
272-
'ui5-table',
276+
`ui5-table${tagSuffix}`,
273277
[
274278
'accessibleName',
275279
'accessibleNameRef',

packages/compat/src/components/TableCell/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
'use client';
22

33
import '@ui5/webcomponents-compat/dist/TableCell.js';
4+
import { getCompatCustomElementsScopingSuffix } from '@ui5/webcomponents-compat/dist/utils/CompatCustomElementsScope.js';
45
import type { CommonProps, Ui5DomRef } from '@ui5/webcomponents-react-base';
56
import { withWebComponent } from '@ui5/webcomponents-react-base/dist/wrapper/withWebComponent.js';
67
import type { ReactNode } from 'react';
78

9+
const compatScopingSuffix = getCompatCustomElementsScopingSuffix();
10+
const tagSuffix = compatScopingSuffix ? `-${compatScopingSuffix}` : '';
11+
812
interface TableCellAttributes {}
913

1014
interface TableCellDomRef extends Required<TableCellAttributes>, Ui5DomRef {}
@@ -22,7 +26,7 @@ interface TableCellPropTypes extends TableCellAttributes, Omit<CommonProps, 'chi
2226
* __Note__: This is a UI5 Web Component! [Repository](https://github.com/SAP/ui5-webcomponents) | [Documentation](https://sap.github.io/ui5-webcomponents/)
2327
* @deprecated Deprecated as of version 2.12.0, use `@ui5/webcomponents/dist/TableCell.js` instead.
2428
*/
25-
const TableCell = withWebComponent<TableCellPropTypes, TableCellDomRef>('ui5-table-cell', [], [], [], []);
29+
const TableCell = withWebComponent<TableCellPropTypes, TableCellDomRef>(`ui5-table-cell${tagSuffix}`, [], [], [], []);
2630

2731
TableCell.displayName = 'TableCell';
2832

packages/compat/src/components/TableColumn/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
import '@ui5/webcomponents-compat/dist/TableColumn.js';
44
import type TableColumnPopinDisplay from '@ui5/webcomponents-compat/dist/types/TableColumnPopinDisplay.js';
5+
import { getCompatCustomElementsScopingSuffix } from '@ui5/webcomponents-compat/dist/utils/CompatCustomElementsScope.js';
56
import type { CommonProps, Ui5DomRef } from '@ui5/webcomponents-react-base';
67
import { withWebComponent } from '@ui5/webcomponents-react-base/dist/wrapper/withWebComponent.js';
78
import type { ReactNode } from 'react';
89

10+
const compatScopingSuffix = getCompatCustomElementsScopingSuffix();
11+
const tagSuffix = compatScopingSuffix ? `-${compatScopingSuffix}` : '';
12+
913
interface TableColumnAttributes {
1014
/**
1115
* According to your `minWidth` settings, the component can be hidden
@@ -64,7 +68,7 @@ interface TableColumnPropTypes
6468
* @deprecated Deprecated as of version 2.12.0, use `@ui5/webcomponents/dist/Table.js` instead.
6569
*/
6670
const TableColumn = withWebComponent<TableColumnPropTypes, TableColumnDomRef>(
67-
'ui5-table-column',
71+
`ui5-table-column${tagSuffix}`,
6872
['minWidth', 'popinDisplay', 'popinText'],
6973
['demandPopin'],
7074
[],

packages/compat/src/components/TableGroupRow/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
'use client';
22

33
import '@ui5/webcomponents-compat/dist/TableGroupRow.js';
4+
import { getCompatCustomElementsScopingSuffix } from '@ui5/webcomponents-compat/dist/utils/CompatCustomElementsScope.js';
45
import type { CommonProps, Ui5DomRef } from '@ui5/webcomponents-react-base';
56
import { withWebComponent } from '@ui5/webcomponents-react-base/dist/wrapper/withWebComponent.js';
67
import type { ReactNode } from 'react';
78

9+
const compatScopingSuffix = getCompatCustomElementsScopingSuffix();
10+
const tagSuffix = compatScopingSuffix ? `-${compatScopingSuffix}` : '';
11+
812
interface TableGroupRowAttributes {}
913

1014
interface TableGroupRowDomRef extends Required<TableGroupRowAttributes>, Ui5DomRef {}
@@ -27,7 +31,7 @@ interface TableGroupRowPropTypes extends TableGroupRowAttributes, Omit<CommonPro
2731
* @deprecated Deprecated as of version 2.12.0, use `@ui5/webcomponents/dist/Table.js` instead.
2832
*/
2933
const TableGroupRow = withWebComponent<TableGroupRowPropTypes, TableGroupRowDomRef>(
30-
'ui5-table-group-row',
34+
`ui5-table-group-row${tagSuffix}`,
3135
[],
3236
[],
3337
[],

0 commit comments

Comments
 (0)