-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(PAYMENTS-19008) rewrite sdk to lit
- Loading branch information
Showing
15 changed files
with
260 additions
and
227 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -66,6 +66,7 @@ | |
"dependencies": { | ||
"currency-format": "^1.0.13", | ||
"i18next": "^23.4.6", | ||
"lit": "^3.1.3", | ||
"tsyringe": "^4.8.0" | ||
} | ||
} |
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,77 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import { FormLoader } from '../form/form-loader'; | ||
import { container } from 'tsyringe'; | ||
import { createFinishLoadingEvent } from '../../shared/loading-state/dispatch-finish-loading-event.function'; | ||
import { isLoadingCssClassName } from '../../shared/loading-state/is-loading-css-class-name.const'; | ||
import { html, LitElement, TemplateResult } from 'lit'; | ||
|
||
export abstract class LitWebComponentAbstract extends LitElement { | ||
protected formLoader: FormLoader = container.resolve(FormLoader); | ||
|
||
protected eventListeners: Array<{ | ||
element: Element; | ||
eventType: string; | ||
listener(event: Event): void; | ||
}> = []; | ||
|
||
public disconnectedCallback(): void { | ||
super.disconnectedCallback(); | ||
this.removeAllEventListeners(); | ||
} | ||
|
||
public createRenderRoot(): LitElement { | ||
return this; | ||
} | ||
|
||
protected abstract render(): void; | ||
|
||
protected renderByCondition( | ||
condition: boolean, | ||
template: TemplateResult<1>, | ||
defaultValue: TemplateResult<1> = html``, | ||
): TemplateResult<1> { | ||
return condition ? template : defaultValue; | ||
} | ||
|
||
protected addEventListenerToElement( | ||
element: Element, | ||
eventType: string, | ||
listener: (event: Event) => void, | ||
): void { | ||
element.addEventListener(eventType, listener); | ||
this.eventListeners.push({ element, eventType, listener }); | ||
} | ||
|
||
protected removeAllEventListeners(): void { | ||
this.eventListeners.forEach((item) => { | ||
item.element.removeEventListener(item.eventType, item.listener); | ||
}); | ||
this.eventListeners = []; | ||
} | ||
|
||
protected getJsonOrNull(data: string): unknown | null { | ||
try { | ||
return JSON.parse(data); | ||
} catch (err: unknown) { | ||
return null; | ||
} | ||
} | ||
|
||
protected finishLoadingFormControlHandler(componentName: string): void { | ||
this.formLoader.setFieldLoaded(componentName); | ||
} | ||
|
||
protected startLoadingComponentHandler(): void { | ||
this.classList.add(isLoadingCssClassName); | ||
} | ||
|
||
protected finishLoadingComponentHandler(componentName: string): void { | ||
this.classList.remove(isLoadingCssClassName); | ||
this.dispatchFinishLoadingEvent(componentName); | ||
} | ||
|
||
protected dispatchFinishLoadingEvent(componentName: string): void { | ||
this.dispatchEvent(createFinishLoadingEvent(componentName)); | ||
this.formLoader.setFieldLoaded(componentName); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/core/web-components/secure-component/lit-secure-component.abstract.ts
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,16 @@ | ||
import { headlessCheckoutAppUrl } from '../../../features/headless-checkout/environment'; | ||
import { LitWebComponentAbstract } from '../lit-web-component.abstract'; | ||
import { property } from 'lit/decorators.js'; | ||
|
||
export abstract class LitSecureComponentAbstract extends LitWebComponentAbstract { | ||
@property({ attribute: false }) | ||
protected componentName: string | null = null; | ||
|
||
protected getSecureHtml(): string { | ||
if (!this.componentName) { | ||
throw new Error('Component name is required'); | ||
} | ||
|
||
return `<iframe src='${headlessCheckoutAppUrl}/secure-components/${this.componentName}'></iframe>`; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/features/headless-checkout/web-components/card-number/card-number.component.scss
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
psdk-card-number { | ||
psdk-card-number, psdk-lit-card-number { | ||
.wrapper { | ||
position: relative; | ||
} | ||
|
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
26 changes: 0 additions & 26 deletions
26
src/features/headless-checkout/web-components/card-number/card-number.template.ts
This file was deleted.
Oops, something went wrong.
19 changes: 7 additions & 12 deletions
19
src/features/headless-checkout/web-components/phone-component/phone.component.ts
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
3 changes: 2 additions & 1 deletion
3
...atures/headless-checkout/web-components/text-component/text-component.config.interface.ts
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { ControlComponentConfig } from '../control-component-config.interface'; | ||
import { TextConfigTooltip } from './text-config-tooltip.interface'; | ||
import { TemplateResult } from 'lit'; | ||
|
||
export interface TextComponentConfig extends ControlComponentConfig { | ||
secureHtml: string; | ||
additionalControls?: string; | ||
additionalControls?: TemplateResult<1>; | ||
tooltip?: TextConfigTooltip; | ||
} |
Oops, something went wrong.