Skip to content

Commit f45c7a3

Browse files
authored
Revert "chore: fix features loading" (#9573)
This reverts commit 74a8a4c.
1 parent e47d1ea commit f45c7a3

File tree

8 files changed

+35
-114
lines changed

8 files changed

+35
-114
lines changed
Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,4 @@
1-
import EventProvider from "./EventProvider.js";
2-
import type UI5Element from "./UI5Element.js";
3-
4-
abstract class ComponentFeature {
5-
// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-empty-function
6-
constructor(...args: any[]) {}
7-
static define?: () => Promise<void>;
8-
static dependencies?: Array<typeof UI5Element>
9-
}
10-
111
const features = new Map<string, any>();
12-
const componentFeatures = new Map<string, ComponentFeature>();
13-
const subscribers = new Map<typeof UI5Element, Array<string>>();
14-
15-
const EVENT_NAME = "componentFeatureLoad";
16-
const eventProvider = new EventProvider<undefined, void>();
17-
18-
const featureLoadEventName = (name: string) => `${EVENT_NAME}_${name}`;
192

203
const registerFeature = (name: string, feature: object) => {
214
features.set(name, feature);
@@ -25,44 +8,7 @@ const getFeature = <T>(name: string): T => {
258
return features.get(name) as T;
269
};
2710

28-
const registerComponentFeature = async (name: string, feature: typeof ComponentFeature) => {
29-
await Promise.all(feature.dependencies?.map(dep => dep.define()) || []);
30-
await feature.define?.();
31-
32-
componentFeatures.set(name, feature);
33-
notifyForFeatureLoad(name);
34-
};
35-
36-
const getComponentFeature = <T>(name: string): T => {
37-
return componentFeatures.get(name) as T;
38-
};
39-
40-
const subscribeForFeatureLoad = (name: string, klass: typeof UI5Element, callback: () => void) => {
41-
const subscriber = subscribers.get(klass);
42-
const isSubscribed = subscriber?.includes(name);
43-
44-
if (isSubscribed) {
45-
return;
46-
}
47-
48-
if (!subscriber) {
49-
subscribers.set(klass, [name]);
50-
} else {
51-
subscriber.push(name);
52-
}
53-
54-
eventProvider.attachEvent(featureLoadEventName(name), callback);
55-
};
56-
57-
const notifyForFeatureLoad = (name: string) => {
58-
eventProvider.fireEvent(featureLoadEventName(name), undefined);
59-
};
60-
6111
export {
6212
registerFeature,
6313
getFeature,
64-
registerComponentFeature,
65-
getComponentFeature,
66-
subscribeForFeatureLoad,
67-
ComponentFeature,
6814
};

packages/base/src/UI5Element.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import type {
3434
ComponentStylesData,
3535
ClassMap,
3636
} from "./types.js";
37-
import { subscribeForFeatureLoad } from "./FeaturesRegistry.js";
3837

3938
let autoId = 0;
4039

@@ -1140,19 +1139,15 @@ abstract class UI5Element extends HTMLElement {
11401139
return [];
11411140
}
11421141

1143-
static cacheUniqueDependencies(this: typeof UI5Element): void {
1144-
const filtered = this.dependencies.filter((dep, index, deps) => deps.indexOf(dep) === index);
1145-
uniqueDependenciesCache.set(this, filtered);
1146-
}
1147-
11481142
/**
11491143
* Returns a list of the unique dependencies for this UI5 Web Component
11501144
*
11511145
* @public
11521146
*/
11531147
static getUniqueDependencies(this: typeof UI5Element): Array<typeof UI5Element> {
11541148
if (!uniqueDependenciesCache.has(this)) {
1155-
this.cacheUniqueDependencies();
1149+
const filtered = this.dependencies.filter((dep, index, deps) => deps.indexOf(dep) === index);
1150+
uniqueDependenciesCache.set(this, filtered);
11561151
}
11571152

11581153
return uniqueDependenciesCache.get(this) || [];
@@ -1188,12 +1183,6 @@ abstract class UI5Element extends HTMLElement {
11881183

11891184
const tag = this.getMetadata().getTag();
11901185

1191-
const features = this.getMetadata().getFeatures();
1192-
1193-
features.forEach(feature => {
1194-
subscribeForFeatureLoad(feature, this, this.cacheUniqueDependencies.bind(this));
1195-
});
1196-
11971186
const definedLocally = isTagRegistered(tag);
11981187
const definedGlobally = customElements.get(tag);
11991188

packages/base/src/UI5ElementMetadata.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ type Metadata = {
4141
fastNavigation?: boolean,
4242
themeAware?: boolean,
4343
languageAware?: boolean,
44-
features?: Array<string>
4544
};
4645

4746
type State = Record<string, PropertyValue | Array<SlotValue>>;
@@ -143,14 +142,6 @@ class UI5ElementMetadata {
143142
return this.metadata.tag || "";
144143
}
145144

146-
/**
147-
* Returns the tag of the UI5 Element without the scope
148-
* @private
149-
*/
150-
getFeatures(): Array<string> {
151-
return this.metadata.features || [];
152-
}
153-
154145
/**
155146
* Returns the tag of the UI5 Element
156147
* @public

packages/base/src/decorators/customElement.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const customElement = (tagNameOrComponentSettings: string | {
2020
languageAware?: boolean,
2121
themeAware?: boolean,
2222
fastNavigation?: boolean,
23-
features?: Array<string>,
2423
} = {}): ClassDecorator => {
2524
return (target: any) => {
2625
if (!Object.prototype.hasOwnProperty.call(target, "metadata")) {
@@ -37,18 +36,12 @@ const customElement = (tagNameOrComponentSettings: string | {
3736
languageAware,
3837
themeAware,
3938
fastNavigation,
40-
features,
4139
} = tagNameOrComponentSettings;
4240

4341
target.metadata.tag = tag;
4442
if (languageAware) {
4543
target.metadata.languageAware = languageAware;
4644
}
47-
48-
if (features) {
49-
target.metadata.features = features;
50-
}
51-
5245
if (themeAware) {
5346
target.metadata.themeAware = themeAware;
5447
}

packages/main/src/Input.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959
{{> postContent }}
6060

61-
{{#if _effectiveShowSuggestions}}
61+
{{#if showSuggestions}}
6262
<span id="{{_id}}-suggestionsText" class="ui5-hidden-text">{{suggestionsText}}</span>
6363
<span id="{{_id}}-selectionText" class="ui5-hidden-text" aria-live="polite" role="status"></span>
6464
<span id="{{_id}}-suggestionsCount" class="ui5-hidden-text" aria-live="polite">{{availableSuggestionsCount}}</span>

packages/main/src/Input.ts

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
isAndroid,
1414
} from "@ui5/webcomponents-base/dist/Device.js";
1515
import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js";
16-
import { getFeature, getComponentFeature } from "@ui5/webcomponents-base/dist/FeaturesRegistry.js";
16+
import { getFeature } from "@ui5/webcomponents-base/dist/FeaturesRegistry.js";
1717
import {
1818
isUp,
1919
isDown,
@@ -199,9 +199,8 @@ type InputSuggestionScrollEventDetail = {
199199
staticAreaTemplate: InputPopoverTemplate,
200200
styles: inputStyles,
201201
staticAreaStyles: [ResponsivePopoverCommonCss, ValueStateMessageCss, SuggestionsCss],
202-
features: ["InputSuggestions"],
203202
get dependencies() {
204-
const Suggestions = getComponentFeature<typeof InputSuggestions>("InputSuggestions");
203+
const Suggestions = getFeature<typeof InputSuggestions>("InputSuggestions");
205204
return ([Popover, Icon] as Array<typeof UI5Element>).concat(Suggestions ? Suggestions.dependencies : []);
206205
},
207206
})
@@ -651,7 +650,7 @@ class Input extends UI5Element implements SuggestionComponent, IFormElement {
651650

652651
if (this.showSuggestions) {
653652
this.enableSuggestions();
654-
this.suggestionObjects = this.Suggestions?.defaultSlotProperties(this.typedInValue) || [];
653+
this.suggestionObjects = this.Suggestions!.defaultSlotProperties(this.typedInValue);
655654
}
656655

657656
this._effectiveShowClearIcon = (this.showClearIcon && !!this.value && !this.readonly && !this.disabled);
@@ -695,10 +694,6 @@ class Input extends UI5Element implements SuggestionComponent, IFormElement {
695694
}
696695
}
697696

698-
get _effectiveShowSuggestions() {
699-
return !!(this.showSuggestions && this.Suggestions);
700-
}
701-
702697
async onAfterRendering() {
703698
const innerInput = this.getInputDOMRefSync()!;
704699

@@ -794,13 +789,13 @@ class Input extends UI5Element implements SuggestionComponent, IFormElement {
794789
}
795790

796791
_handleUp(e: KeyboardEvent) {
797-
if (this.Suggestions?.isOpened()) {
792+
if (this.Suggestions && this.Suggestions.isOpened()) {
798793
this.Suggestions.onUp(e);
799794
}
800795
}
801796

802797
_handleDown(e: KeyboardEvent) {
803-
if (this.Suggestions?.isOpened()) {
798+
if (this.Suggestions && this.Suggestions.isOpened()) {
804799
this.Suggestions.onDown(e);
805800
}
806801
}
@@ -818,8 +813,8 @@ class Input extends UI5Element implements SuggestionComponent, IFormElement {
818813
}
819814

820815
_handleEnter(e: KeyboardEvent) {
821-
// if a group item is focused, this is false
822-
const suggestionItemPressed = !!(this.Suggestions?.onEnter(e));
816+
const suggestionItemPressed = !!(this.Suggestions && this.Suggestions.onEnter(e));
817+
823818
const innerInput = this.getInputDOMRefSync()!;
824819
// Check for autocompleted item
825820
const matchingItem = this.suggestionItems.find(item => {
@@ -855,29 +850,29 @@ class Input extends UI5Element implements SuggestionComponent, IFormElement {
855850

856851
_handlePageUp(e: KeyboardEvent) {
857852
if (this._isSuggestionsFocused) {
858-
this.Suggestions?.onPageUp(e);
853+
this.Suggestions!.onPageUp(e);
859854
} else {
860855
e.preventDefault();
861856
}
862857
}
863858

864859
_handlePageDown(e: KeyboardEvent) {
865860
if (this._isSuggestionsFocused) {
866-
this.Suggestions?.onPageDown(e);
861+
this.Suggestions!.onPageDown(e);
867862
} else {
868863
e.preventDefault();
869864
}
870865
}
871866

872867
_handleHome(e: KeyboardEvent) {
873868
if (this._isSuggestionsFocused) {
874-
this.Suggestions?.onHome(e);
869+
this.Suggestions!.onHome(e);
875870
}
876871
}
877872

878873
_handleEnd(e: KeyboardEvent) {
879874
if (this._isSuggestionsFocused) {
880-
this.Suggestions?.onEnd(e);
875+
this.Suggestions!.onEnd(e);
881876
}
882877
}
883878

@@ -894,7 +889,7 @@ class Input extends UI5Element implements SuggestionComponent, IFormElement {
894889
return;
895890
}
896891

897-
if (isOpen && this.Suggestions?._isItemOnTarget()) {
892+
if (isOpen && this.Suggestions!._isItemOnTarget()) {
898893
// Restore the value.
899894
this.value = this.typedInValue || this.valueBeforeItemPreview;
900895

@@ -980,8 +975,8 @@ class Input extends UI5Element implements SuggestionComponent, IFormElement {
980975
this._isValueStateFocused = false;
981976
this.hasSuggestionItemSelected = false;
982977

983-
this.Suggestions?._deselectItems();
984-
this.Suggestions?._clearItemFocus();
978+
this.Suggestions._deselectItems();
979+
this.Suggestions._clearItemFocus();
985980
}
986981

987982
_click() {
@@ -1216,9 +1211,12 @@ class Input extends UI5Element implements SuggestionComponent, IFormElement {
12161211
return;
12171212
}
12181213

1219-
const Suggestions = getComponentFeature<typeof InputSuggestions>("InputSuggestions");
1214+
const Suggestions = getFeature<typeof InputSuggestions>("InputSuggestions");
1215+
12201216
if (Suggestions) {
12211217
this.Suggestions = new Suggestions(this, "suggestionItems", true, false);
1218+
} else {
1219+
throw new Error(`You have to import "@ui5/webcomponents/dist/features/InputSuggestions.js" module to use ui5-input suggestions`);
12221220
}
12231221
}
12241222

@@ -1399,7 +1397,7 @@ class Input extends UI5Element implements SuggestionComponent, IFormElement {
13991397
return Promise.resolve(false);
14001398
}
14011399

1402-
return this.Suggestions?._isScrollable();
1400+
return this.Suggestions._isScrollable();
14031401
}
14041402

14051403
getInputId() {
@@ -1627,7 +1625,7 @@ class Input extends UI5Element implements SuggestionComponent, IFormElement {
16271625
}
16281626

16291627
get availableSuggestionsCount() {
1630-
if (this.showSuggestions && (this.value || this.Suggestions?.isOpened())) {
1628+
if (this.showSuggestions && (this.value || this.Suggestions!.isOpened())) {
16311629
const nonGroupItems = this.suggestionObjects.filter(item => !item.groupItem);
16321630

16331631
switch (nonGroupItems.length) {
@@ -1654,7 +1652,7 @@ class Input extends UI5Element implements SuggestionComponent, IFormElement {
16541652
}
16551653

16561654
get _isSuggestionsFocused() {
1657-
return !this.focused && this.Suggestions?.isOpened();
1655+
return !this.focused && this.Suggestions && this.Suggestions.isOpened();
16581656
}
16591657

16601658
/**
@@ -1737,7 +1735,12 @@ class Input extends UI5Element implements SuggestionComponent, IFormElement {
17371735
}
17381736

17391737
static async onDefine() {
1740-
Input.i18nBundle = await getI18nBundle("@ui5/webcomponents");
1738+
const Suggestions = getFeature<typeof InputSuggestions>("InputSuggestions");
1739+
1740+
[Input.i18nBundle] = await Promise.all([
1741+
getI18nBundle("@ui5/webcomponents"),
1742+
Suggestions ? Suggestions.init() : Promise.resolve(),
1743+
]);
17411744
}
17421745
}
17431746

packages/main/src/InputPopover.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{#if _effectiveShowSuggestions}}
1+
{{#if showSuggestions}}
22
<ui5-responsive-popover
33
class="{{classes.popover}}"
44
hide-arrow

packages/main/src/features/InputSuggestions.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
2-
import { ComponentFeature, registerComponentFeature } from "@ui5/webcomponents-base/dist/FeaturesRegistry.js";
2+
import { registerFeature } from "@ui5/webcomponents-base/dist/FeaturesRegistry.js";
33
import type I18nBundle from "@ui5/webcomponents-base/dist/i18nBundle.js";
44
import { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
55
// @ts-ignore
@@ -66,7 +66,7 @@ type SuggestionsAccInfo = {
6666
* @class
6767
* @private
6868
*/
69-
class Suggestions extends ComponentFeature {
69+
class Suggestions {
7070
component: SuggestionComponent;
7171
slotName: string;
7272
handleFocus: boolean;
@@ -85,7 +85,6 @@ class Suggestions extends ComponentFeature {
8585
static SCROLL_STEP = 60;
8686

8787
constructor(component: SuggestionComponent, slotName: string, highlight: boolean, handleFocus: boolean) {
88-
super();
8988
// The component, that the suggestion would plug into.
9089
this.component = component;
9190

@@ -672,13 +671,13 @@ class Suggestions extends ComponentFeature {
672671
];
673672
}
674673

675-
static async define() {
674+
static async init() {
676675
Suggestions.i18nBundle = await getI18nBundle("@ui5/webcomponents");
677676
}
678677
}
679678

680679
// Add suggestions support to the global features registry so that Input.js can use it
681-
registerComponentFeature("InputSuggestions", Suggestions);
680+
registerFeature("InputSuggestions", Suggestions);
682681

683682
export default Suggestions;
684683

0 commit comments

Comments
 (0)