Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebComponents / fix dropdown-selector not showing #658

Merged
merged 7 commits into from
Oct 24, 2023
41 changes: 0 additions & 41 deletions apps/webcomponents/src/app/AppOverlayContainer.ts

This file was deleted.

39 changes: 38 additions & 1 deletion apps/webcomponents/src/app/components/base.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { Component, Injector, Input, OnChanges, OnInit } from '@angular/core'
import {
Component,
ElementRef,
Injector,
Input,
OnChanges,
OnInit,
} from '@angular/core'
import {
LinkClassifierService,
LinkUsage,
Expand All @@ -10,6 +17,8 @@ import { TranslateService } from '@ngx-translate/core'
import { firstValueFrom } from 'rxjs'
import { DatasetDistribution } from '@geonetwork-ui/common/domain/record'
import { RecordsRepositoryInterface } from '@geonetwork-ui/common/domain/records-repository.interface'
import { OverlayContainer } from '@angular/cdk/overlay'
import { WebcomponentOverlayContainer } from '../webcomponent-overlay-container'

export const apiConfiguration = new Configuration()

Expand Down Expand Up @@ -40,6 +49,12 @@ export class BaseComponent implements OnChanges, OnInit {
this.searchService = injector.get(SearchApiService)
this.recordsRepository = injector.get(RecordsRepositoryInterface)
this.linkClassifier = injector.get(LinkClassifierService)

const elementRef = injector.get(ElementRef)
const overlayContainer = injector.get(
OverlayContainer
) as WebcomponentOverlayContainer
overlayContainer.setRoot(elementRef.nativeElement.shadowRoot)
}

ngOnInit() {
Expand Down Expand Up @@ -68,13 +83,35 @@ export class BaseComponent implements OnChanges, OnInit {
this.titleFont
)
this.facade.init(this.searchId)
this.copyFontFacesToDocument()
this.isInitialized = true
jahow marked this conversation as resolved.
Show resolved Hide resolved
}

changes() {
// to override
}

private copyFontFacesToDocument() {
// get the list of font face definitions in the Shadow DOM
const root = this.injector.get(ElementRef).nativeElement as HTMLElement
const styles = root.shadowRoot.styleSheets
const fontFaces = Array.from(styles).reduce(
(prev, curr) => [
...prev,
...Array.from(curr.cssRules)
.filter((rule) => rule.cssText.startsWith('@font-face'))
.map((rule) => rule.cssText),
],
[]
)

// all font faces are then copied to the document
const style = document.createElement('style')
const cssText = fontFaces.join('\n')
style.appendChild(document.createTextNode(cssText))
document.head.appendChild(style)
}

async getRecordLink(
uuid: string,
usages: LinkUsage[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200"
/>
<link
href="https://fonts.googleapis.com/css2?family=DM+Serif+Display&amp;family=Inter:wght@200;300;400;500;600;700&amp;display=swap"
rel="stylesheet"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200"
/>
<link
href="https://fonts.googleapis.com/css2?family=DM+Serif+Display&amp;family=Inter:wght@200;300;400;500;600;700&amp;display=swap"
rel="stylesheet"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200"
/>
<link
href="https://fonts.googleapis.com/css2?family=DM+Serif+Display&amp;family=Inter:wght@200;300;400;500;600;700&amp;display=swap"
rel="stylesheet"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200"
/>
<link
href="https://fonts.googleapis.com/css2?family=DM+Serif+Display&amp;family=Inter:wght@200;300;400;500;600;700&amp;display=swap"
rel="stylesheet"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200"
/>
<link
href="https://fonts.googleapis.com/css2?family=Roboto:wght@200;300;400;500;600;700&amp;display=swap"
rel="stylesheet"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200"
/>
<link
href="https://fonts.googleapis.com/css2?family=DM+Serif+Display&amp;family=Inter:wght@200;300;400;500;600;700&amp;display=swap"
rel="stylesheet"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200"
/>
<link
href="https://fonts.googleapis.com/css2?family=DM+Serif+Display&amp;family=Inter:wght@200;300;400;500;600;700&amp;display=swap"
rel="stylesheet"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
<div id="angular-app-root">
<gn-ui-fuzzy-search #searchInput class="text-[18px]"></gn-ui-fuzzy-search>
</div>
<gn-ui-fuzzy-search #searchInput class="text-[18px]"></gn-ui-fuzzy-search>
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200"
/>
<link
href="https://fonts.googleapis.com/css2?family=DM+Serif+Display&amp;family=Inter:wght@200;300;400;500;600;700&amp;display=swap"
rel="stylesheet"
Expand Down
32 changes: 32 additions & 0 deletions apps/webcomponents/src/app/webcomponent-overlay-container.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { OverlayContainer } from '@angular/cdk/overlay'
import { Platform } from '@angular/cdk/platform'
import { DOCUMENT } from '@angular/common'
import { Inject, Injectable } from '@angular/core'

@Injectable()
export class WebcomponentOverlayContainer extends OverlayContainer {
private componentRoot: HTMLElement

constructor(
@Inject(DOCUMENT) private document: Document,
platform: Platform
) {
super(document, platform)
}

setRoot(componentRoot: HTMLElement) {
this.componentRoot = componentRoot
}

protected _createContainer(): void {
const container: HTMLDivElement = this.document.createElement('div')
container.classList.add('gn-ui-overlay-container')
if (!this.componentRoot) {
throw new Error(
'Angular CDK OverlayContainer was used without proper initialization.'
)
}
this.componentRoot.appendChild(container)
this._containerElement = container
}
}
14 changes: 4 additions & 10 deletions apps/webcomponents/src/app/webcomponents.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { OverlayContainer } from '@angular/cdk/overlay'
import { Platform } from '@angular/cdk/platform'
import { CommonModule, DOCUMENT } from '@angular/common'
import { CommonModule } from '@angular/common'
import { CUSTOM_ELEMENTS_SCHEMA, Injector, NgModule } from '@angular/core'
import { createCustomElement } from '@angular/elements'
import { MatIconModule } from '@angular/material/icon'
Expand All @@ -12,6 +11,7 @@ import { UiElementsModule } from '@geonetwork-ui/ui/elements'
import { UiInputsModule } from '@geonetwork-ui/ui/inputs'
import { UiSearchModule } from '@geonetwork-ui/ui/search'
import {
EmbeddedTranslateLoader,
TRANSLATE_DEFAULT_CONFIG,
UtilI18nModule,
} from '@geonetwork-ui/util/i18n'
Expand All @@ -20,7 +20,7 @@ import { StoreModule } from '@ngrx/store'
import { StoreDevtoolsModule } from '@ngrx/store-devtools'
import { TranslateLoader, TranslateModule } from '@ngx-translate/core'
import { AppComponent } from './app.component'
import { AppOverlayContainer } from './AppOverlayContainer'
import { WebcomponentOverlayContainer } from './webcomponent-overlay-container'
import { apiConfiguration, BaseComponent } from './components/base.component'
import { GnAggregatedRecordsComponent } from './components/gn-aggregated-records/gn-aggregated-records.component'
import { GnFacetsComponent } from './components/gn-facets/gn-facets.component'
Expand All @@ -31,7 +31,6 @@ import { GnMapViewerComponent } from './components/gn-map-viewer/gn-map-viewer.c
import { FeatureMapModule } from '@geonetwork-ui/feature/map'
import { GnDatasetViewChartComponent } from './components/gn-dataset-view-chart/gn-dataset-view-chart.component'
import { FeatureDatavizModule } from '@geonetwork-ui/feature/dataviz'
import { EmbeddedTranslateLoader } from '@geonetwork-ui/util/i18n'
import { FeatureAuthModule } from '@geonetwork-ui/feature/auth'
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'

Expand Down Expand Up @@ -90,12 +89,7 @@ const CUSTOM_ELEMENTS: [new (...args) => BaseComponent, string][] = [
},
{
provide: OverlayContainer,
useFactory: (document: Document, platform: Platform) => {
const container = new AppOverlayContainer(document, platform)
container.setSelector('gn-search-input')
return container
},
deps: [DOCUMENT, Platform],
useClass: WebcomponentOverlayContainer,
},
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
Expand Down
33 changes: 28 additions & 5 deletions apps/webcomponents/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
font-family: 'Material Symbols Outlined';
font-style: normal;
font-weight: 400;
src: url(https://fonts.gstatic.com/s/materialiconsoutlined/v108/gok-H7zzDkdnRel8-DQ6KAXJ69wP1tGnf4ZGhUce.woff2)
src: url(https://fonts.gstatic.com/s/materialsymbolsoutlined/v138/kJEhBvYX7BgnkSrUwT8OhrdQw4oELdPIeeII9v6oFsLjBuVY.woff2)
format('woff2');
}
.material-symbols-outlined {
Expand All @@ -32,7 +32,7 @@
-webkit-font-smoothing: antialiased;
}

/* Material Theme */
/* These classes were extracted from the full Material theme to save size */
.cdk-overlay-pane {
position: absolute;
pointer-events: auto;
Expand All @@ -42,7 +42,6 @@
max-width: 100%;
max-height: 100%;
}

.cdk-overlay-connected-position-bounding-box {
position: absolute;
z-index: 1000;
Expand All @@ -51,7 +50,31 @@
min-width: 1px;
min-height: 1px;
}
.app-overlay-container {
.cdk-overlay-backdrop {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
z-index: 1000;
pointer-events: auto;
transition: opacity 400ms cubic-bezier(0.25, 0.8, 0.25, 1);
opacity: 0;
}
.cdk-overlay-backdrop.cdk-overlay-backdrop-showing {
opacity: 1;
}
.cdk-overlay-transparent-backdrop {
transition: visibility 1ms linear, opacity 1ms linear;
visibility: hidden;
opacity: 1;
}
.cdk-overlay-transparent-backdrop.cdk-overlay-backdrop-showing {
opacity: 0;
visibility: visible;
}

.gn-ui-overlay-container {
position: absolute;
z-index: 1000;
pointer-events: none;
Expand All @@ -60,7 +83,7 @@
height: 100%;
width: 100%;
}
.app-overlay-container:empty {
.gn-ui-overlay-container:empty {
display: none;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[action]="autoCompleteAction"
(itemSelected)="handleItemSelection($event)"
(inputSubmitted)="handleInputSubmission($event)"
(inputCleared)="handleInputCleared()"
jahow marked this conversation as resolved.
Show resolved Hide resolved
[value]="searchInputValue$ | async"
[clearOnSelection]="true"
></gn-ui-autocomplete>
Loading
Loading