-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ifc-api-improvements): Improve URL and link generation APIs
- Loading branch information
1 parent
eda9b01
commit 6f77f9d
Showing
11 changed files
with
292 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Client } from '../client'; | ||
const PATH_ATTR = 'path'; | ||
|
||
/** | ||
* A custom element responsible for rendering an anchor element, turning a path | ||
* within the current application to a full top-level url. | ||
* It is registered as `ifc-client-link` within client.ts | ||
*/ | ||
|
||
export default class IfcClientLinkElement extends HTMLElement { | ||
private _client: Client; | ||
|
||
/** @internal */ | ||
constructor(clientInstance: any) { | ||
super(); | ||
this._client = clientInstance; | ||
} | ||
|
||
/** | ||
* @internal | ||
* @inheritdoc | ||
*/ | ||
static get observedAttributes() { | ||
return [PATH_ATTR]; | ||
} | ||
|
||
/** | ||
* @internal | ||
* @inheritdoc | ||
*/ | ||
public connectedCallback() { | ||
const content = this.innerHTML; | ||
let path = this.getAttribute(PATH_ATTR) || ''; | ||
path = this._client.urlFromClientPath(path); | ||
this.innerHTML = `<a target='_top' href=${path}>${content}</a>`; | ||
} | ||
|
||
/** | ||
* @internal | ||
* @inheritdoc | ||
*/ | ||
public attributeChangedCallback( | ||
name: string, | ||
oldValue: string | null, | ||
newValue: string | null | ||
) { | ||
if (name === PATH_ATTR && oldValue !== newValue) { | ||
let path = this.getAttribute(PATH_ATTR) || ''; | ||
path = this._client.urlFromClientPath(path); | ||
this.firstElementChild?.setAttribute('href', path); | ||
} | ||
} | ||
} |
Oops, something went wrong.