Skip to content

Commit 55e1527

Browse files
authored
feat: enable scoping for components in compat package (#11822)
This PR introduces a new scoping mechanism specifically for components in the compatibility package. A new module, `@ui5/webcomponents-compat/dist/utils/CompatCustomElementsScope.js`, has been added. It provides two functions: * `getCompatCustomElementsScopingSuffix()`: Returns a `string | undefined` representing the currently configured compatibility suffix. * `setCompatCustomElementsScopingSuffix(suffix: string)`: Sets the compatibility scoping suffix. > **Note:** This feature is different from the general [scoping mechanism](https://sap.github.io/ui5-webcomponents/nightly/docs/advanced/scoping/) and applies **only** to components from the compatibility package. When this feature is used, tag names are formatted as follows: * **No suffixes set**: `{tag}` (f.e ui5-table) * **Only compatibility suffix set**: `{tag}-{compatSuffix}` (f.e ui5-table-compat) * **Both compatibility and general scoping suffixes set**: `{tag}-{compatSuffix}-{suffix}` (f.e ui5-table-compat-1a35aff) Fixes: #11807 Related to: #10492, #11260
1 parent 18f7fa7 commit 55e1527

15 files changed

+262
-1
lines changed

packages/base/src/CustomElementsScopeUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const setCustomElementsScopingSuffix = (suffix: string) => {
4343
* @public
4444
* @returns {String|undefined}
4545
*/
46-
const getCustomElementsScopingSuffix = () => {
46+
const getCustomElementsScopingSuffix = (): string | undefined => {
4747
return suf;
4848
};
4949

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import "./utils/combined-suffix.js";
2+
import Table from "../../src/Table.js";
3+
import TableCell from "../../src/TableCell.js";
4+
import TableRow from "../../src/TableRow.js";
5+
import TableGroupRow from "../../src/TableGroupRow.js";
6+
import TableColumn from "../../src/TableColumn.js";
7+
import modifyTag from "./utils/modifyTag.js";
8+
9+
describe("Package compatibility scoping", () => {
10+
it("Compat and general suffix", () => {
11+
cy.mount(
12+
<Table>
13+
<TableColumn slot="columns">
14+
Product
15+
</TableColumn>
16+
17+
<TableGroupRow>Group</TableGroupRow>
18+
19+
<TableRow>
20+
<TableCell>
21+
Product 1
22+
</TableCell>
23+
</TableRow>
24+
</Table>
25+
);
26+
27+
[
28+
Table.getMetadata().getPureTag(),
29+
TableCell.getMetadata().getPureTag(),
30+
TableRow.getMetadata().getPureTag(),
31+
TableGroupRow.getMetadata().getPureTag(),
32+
TableColumn.getMetadata().getPureTag()
33+
].map(tag => modifyTag(tag, "compat", "demo"))
34+
.forEach(tag => {
35+
cy.get(tag)
36+
.should("exist");
37+
38+
cy.get(tag)
39+
.shadow()
40+
.find("*")
41+
.should("exist");
42+
})
43+
});
44+
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import "./utils/legacy-suffix.js";
2+
import Table from "../../src/Table.js";
3+
import TableCell from "../../src/TableCell.js";
4+
import TableRow from "../../src/TableRow.js";
5+
import TableGroupRow from "../../src/TableGroupRow.js";
6+
import TableColumn from "../../src/TableColumn.js";
7+
import modifyTag from "./utils/modifyTag.js";
8+
9+
describe("Package compatibility scoping", () => {
10+
it("Compat suffix", () => {
11+
cy.mount(
12+
<Table>
13+
<TableColumn slot="columns">
14+
Product
15+
</TableColumn>
16+
17+
<TableGroupRow>Group</TableGroupRow>
18+
19+
<TableRow>
20+
<TableCell>
21+
Product 1
22+
</TableCell>
23+
</TableRow>
24+
</Table>
25+
);
26+
27+
[
28+
Table.getMetadata().getPureTag(),
29+
TableCell.getMetadata().getPureTag(),
30+
TableRow.getMetadata().getPureTag(),
31+
TableGroupRow.getMetadata().getPureTag(),
32+
TableColumn.getMetadata().getPureTag()
33+
].map(tag => modifyTag(tag, "compat"))
34+
.forEach(tag => {
35+
cy.get(tag)
36+
.should("exist");
37+
38+
cy.get(tag)
39+
.shadow()
40+
.find("*")
41+
.should("exist");
42+
})
43+
});
44+
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import "./utils/suffix.js";
2+
import Table from "../../src/Table.js";
3+
import TableCell from "../../src/TableCell.js";
4+
import TableRow from "../../src/TableRow.js";
5+
import TableGroupRow from "../../src/TableGroupRow.js";
6+
import TableColumn from "../../src/TableColumn.js";
7+
import modifyTag from "./utils/modifyTag.js";
8+
9+
describe("Table", () => {
10+
it("tests doesn't fire loadMore with ArrowDown on last row", () => {
11+
cy.mount(
12+
<Table>
13+
<TableColumn slot="columns">
14+
Product
15+
</TableColumn>
16+
17+
<TableGroupRow>Group</TableGroupRow>
18+
19+
<TableRow>
20+
<TableCell>
21+
Product 1
22+
</TableCell>
23+
</TableRow>
24+
</Table>
25+
);
26+
27+
[
28+
Table.getMetadata().getPureTag(),
29+
TableCell.getMetadata().getPureTag(),
30+
TableRow.getMetadata().getPureTag(),
31+
TableGroupRow.getMetadata().getPureTag(),
32+
TableColumn.getMetadata().getPureTag()
33+
].map(tag => modifyTag(tag, undefined, "demo"))
34+
.forEach(tag => {
35+
cy.get(tag)
36+
.should("exist");
37+
38+
cy.get(tag)
39+
.shadow()
40+
.find("*")
41+
.should("exist");
42+
})
43+
});
44+
});
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import Table from "../../src/Table.js";
2+
import TableCell from "../../src/TableCell.js";
3+
import TableRow from "../../src/TableRow.js";
4+
import TableGroupRow from "../../src/TableGroupRow.js";
5+
import TableColumn from "../../src/TableColumn.js";
6+
import modifyTag from "./utils/modifyTag.js";
7+
8+
describe("Package compatibility scoping", () => {
9+
it("Without suffix", () => {
10+
cy.mount(
11+
<Table>
12+
<TableColumn slot="columns">
13+
Product
14+
</TableColumn>
15+
16+
<TableGroupRow>Group</TableGroupRow>
17+
18+
<TableRow>
19+
<TableCell>
20+
Product 1
21+
</TableCell>
22+
</TableRow>
23+
</Table>
24+
);
25+
26+
[
27+
Table.getMetadata().getPureTag(),
28+
TableCell.getMetadata().getPureTag(),
29+
TableRow.getMetadata().getPureTag(),
30+
TableGroupRow.getMetadata().getPureTag(),
31+
TableColumn.getMetadata().getPureTag()
32+
].map(tag => modifyTag(tag))
33+
.forEach(tag => {
34+
cy.get(tag)
35+
.should("exist");
36+
37+
cy.get(tag)
38+
.shadow()
39+
.find("*")
40+
.should("exist");
41+
})
42+
});
43+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { setCustomElementsScopingSuffix } from "@ui5/webcomponents-base/dist/CustomElementsScope.js";
2+
import { setCompatCustomElementsScopingSuffix } from "../../../src/utils/CompatCustomElementsScope.js";
3+
4+
setCustomElementsScopingSuffix("demo")
5+
setCompatCustomElementsScopingSuffix("compat")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { setCompatCustomElementsScopingSuffix } from "../../../src/utils/CompatCustomElementsScope.js";
2+
3+
setCompatCustomElementsScopingSuffix("compat")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const modifyTag = (tag: string, legacySuffix?: string, suffix?: string) => {
2+
return [tag, legacySuffix, suffix].filter(Boolean).join("-");
3+
}
4+
5+
export default modifyTag;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { setCustomElementsScopingSuffix } from "@ui5/webcomponents-base/dist/CustomElementsScope.js";
2+
3+
setCustomElementsScopingSuffix("demo")

packages/compat/src/Table.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import TableTemplate from "./TableTemplate.js";
5959

6060
// Styles
6161
import tableStyles from "./generated/themes/Table.css.js";
62+
import { patchScopingSuffix } from "./utils/CompatCustomElementsScope.js";
6263

6364
/**
6465
* Interface for components that may be slotted inside a `ui5-table` as rows
@@ -1194,6 +1195,8 @@ class Table extends UI5Element {
11941195
}
11951196
}
11961197

1198+
patchScopingSuffix(Table);
1199+
11971200
Table.define();
11981201

11991202
export default Table;

0 commit comments

Comments
 (0)