Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ember-basic-dropdown/src/template-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

import type BasicDropdownComponent from './components/basic-dropdown';
import type BasicDropdownWormholeComponent from './components/basic-dropdown-wormhole';
import type BasicDropdownContentTrigger from './components/basic-dropdown-trigger';
import type BasicDropdownContentComponent from './components/basic-dropdown-content';
import type DropdownTriggerModifier from './modifiers/basic-dropdown-trigger';

export default interface Registry {
BasicDropdown: typeof BasicDropdownComponent;
BasicDropdownWormhole: typeof BasicDropdownWormholeComponent;
BasicDropdownTrigger: typeof BasicDropdownContentTrigger;
BasicDropdownContent: typeof BasicDropdownContentComponent;
'basic-dropdown-trigger': typeof DropdownTriggerModifier;
}
7 changes: 2 additions & 5 deletions test-app/app/components/my-custom-content.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import templateOnly from '@ember/component/template-only';
import type { BasicDropdownContentSignature } from 'ember-basic-dropdown/components/basic-dropdown-content';

export interface MyCustomContentSignature {
Element: Element;
}

export default templateOnly<MyCustomContentSignature>();
export default templateOnly<BasicDropdownContentSignature>();
7 changes: 2 additions & 5 deletions test-app/app/components/my-custom-trigger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import templateOnly from '@ember/component/template-only';
import type { BasicDropdownTriggerSignature } from 'ember-basic-dropdown/components/basic-dropdown-trigger';

export interface MyCustomTriggerSignature {
Element: Element;
}

export default templateOnly<MyCustomTriggerSignature>();
export default templateOnly<BasicDropdownTriggerSignature>();
6 changes: 6 additions & 0 deletions test-app/app/components/shadow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ export default class ShadowComponent extends Component<{
},
);
}

declare module '@glint/environment-ember-loose/registry' {
export default interface Registry {
Shadow: typeof ShadowComponent;
}
}
1 change: 1 addition & 0 deletions test-app/app/config/environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ declare const config: {
locationType: 'history' | 'hash' | 'none';
rootURL: string;
APP: Record<string, unknown>;
'ember-basic-dropdown': Record<string, unknown>;
};

export default config;
29 changes: 0 additions & 29 deletions test-app/app/controllers/application.js

This file was deleted.

35 changes: 35 additions & 0 deletions test-app/app/controllers/application.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type ApplicationInstance from '@ember/application/instance';
import Controller from '@ember/controller';
import type Owner from '@ember/owner';
import type environment from 'test-app/config/environment';
import { getOwner } from '@ember/owner';

// @ts-expect-error Cannot find name 'FastBoot'.
const isFastBoot = typeof FastBoot !== 'undefined';

export default class extends Controller {
shadowDom = false;

constructor(owner: Owner) {
super(owner);

const config = (getOwner(this) as ApplicationInstance).resolveRegistration(
'config:environment',
) as typeof environment;

this.shadowDom = (config.APP['shadowDom'] as boolean) ?? false;

if (!this.shadowDom || isFastBoot) {
return;
}

customElements.define(
'shadow-root',
class extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
}
},
);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import type ApplicationInstance from '@ember/application/instance';
import config from 'test-app/config/environment';

// @ts-expect-error Public property 'isFastBoot' of exported class
const isFastBoot = typeof FastBoot !== 'undefined';

export function initialize(appInstance) {
if (config.environment !== 'test' || isFastBoot || !config.APP.shadowDom) {
export function initialize(appInstance: ApplicationInstance) {
if (config.environment !== 'test' || isFastBoot || !config.APP['shadowDom']) {
return;
}

let appRootElement = appInstance.rootElement;
let appRootElement = appInstance.rootElement as HTMLElement | null;

if (typeof appRootElement === 'string') {
appRootElement = document.querySelector(appRootElement);
appRootElement = document.querySelector(
appRootElement,
) as HTMLElement | null;
}
const targetElement =
appRootElement || document.getElementsByTagName('body')[0];
Expand All @@ -23,11 +26,11 @@ export function initialize(appInstance) {
const wormhole = document.createElement('div');
wormhole.id = 'ember-basic-dropdown-wormhole';

hostElement.shadowRoot.appendChild(wormhole);
hostElement.shadowRoot.appendChild(rootElement);
targetElement.appendChild(hostElement);
hostElement.shadowRoot?.appendChild(wormhole);
hostElement.shadowRoot?.appendChild(rootElement);
targetElement?.appendChild(hostElement);

config.APP.rootElement = '#ember-basic-dropdown-wormhole';
config.APP['rootElement'] = '#ember-basic-dropdown-wormhole';
appInstance.set('rootElement', rootElement);
}

Expand Down
Loading