-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
63 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,52 @@ | ||
import { EmbeddedSubscriptionForm } from './main' | ||
// import './app.css' | ||
import App from './App.svelte' | ||
import type * as Types from './types' | ||
import { mergeOptionsDeep } from './utils/mergeOptions' | ||
|
||
window.EmbeddedSubscriptionForm = EmbeddedSubscriptionForm || {} | ||
export { NewsletterSubscriptionError, submitSubscription } from './api' | ||
|
||
export type NorticNewsletterOptions = Types.NorticNewsletterOptions | ||
export type SubmitOptions = Types.SubmitOptions | ||
export type SubmitOptionsBase = Types.SubmitOptionsBase | ||
|
||
export class EmbeddedSubscriptionForm { | ||
private app: App | ||
private options: Types.NorticNewsletterOptions | ||
|
||
constructor(target: string | HTMLElement, options: Types.NorticNewsletterOptions) { | ||
this.options = options | ||
const el = typeof target === 'string' ? document.querySelector(target) : target | ||
|
||
if (!el) | ||
throw new Error('Target not found') | ||
|
||
if (!(el instanceof HTMLElement)) | ||
throw new Error('Target must be an HTMLElement') | ||
|
||
this.app = new App({ | ||
target: el, | ||
props: { options: this.options }, | ||
}) | ||
} | ||
|
||
update(newOptions: Partial<Types.NorticNewsletterOptions>) { | ||
this.options = mergeOptionsDeep(this.options, newOptions) | ||
this.app.$set({ options: this.options }) | ||
this.options.onUpdate?.() | ||
} | ||
|
||
destroy() { | ||
this.options.onDestroy?.() | ||
this.app.$destroy() | ||
} | ||
|
||
reset() { | ||
this.options.onReset?.() | ||
this.app.$set({ options: this.options }) | ||
this.app.resetForm() | ||
} | ||
|
||
_toggleSubscribeCompleted(value?: boolean) { | ||
this.app.toggleSubscribeCompleted(value) | ||
} | ||
} |
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,52 +1,3 @@ | ||
// import './app.css' | ||
import App from './App.svelte' | ||
import type * as Types from './types' | ||
import { mergeOptionsDeep } from './utils/mergeOptions' | ||
import { EmbeddedSubscriptionForm } from '.' | ||
|
||
export { NewsletterSubscriptionError, submitSubscription } from './api' | ||
|
||
export type NorticNewsletterOptions = Types.NorticNewsletterOptions | ||
export type SubmitOptions = Types.SubmitOptions | ||
export type SubmitOptionsBase = Types.SubmitOptionsBase | ||
|
||
export class EmbeddedSubscriptionForm { | ||
private app: App | ||
private options: Types.NorticNewsletterOptions | ||
|
||
constructor(target: string | HTMLElement, options: Types.NorticNewsletterOptions) { | ||
this.options = options | ||
const el = typeof target === 'string' ? document.querySelector(target) : target | ||
|
||
if (!el) | ||
throw new Error('Target not found') | ||
|
||
if (!(el instanceof HTMLElement)) | ||
throw new Error('Target must be an HTMLElement') | ||
|
||
this.app = new App({ | ||
target: el, | ||
props: { options: this.options }, | ||
}) | ||
} | ||
|
||
update(newOptions: Partial<Types.NorticNewsletterOptions>) { | ||
this.options = mergeOptionsDeep(this.options, newOptions) | ||
this.app.$set({ options: this.options }) | ||
this.options.onUpdate?.() | ||
} | ||
|
||
destroy() { | ||
this.options.onDestroy?.() | ||
this.app.$destroy() | ||
} | ||
|
||
reset() { | ||
this.options.onReset?.() | ||
this.app.$set({ options: this.options }) | ||
this.app.resetForm() | ||
} | ||
|
||
_toggleSubscribeCompleted(value?: boolean) { | ||
this.app.toggleSubscribeCompleted(value) | ||
} | ||
} | ||
window.EmbeddedSubscriptionForm = EmbeddedSubscriptionForm || {} |
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,14 +1,16 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"rootDir": ".", | ||
"baseUrl": "./src", | ||
"rootDir": "./src", | ||
"typeRoots": ["./node_modules/@types", "./nortic.d.ts"], | ||
"skipLibCheck": true | ||
}, | ||
"include": [ | ||
"./src/**/*.ts"], | ||
"exclude": [ | ||
"./node_modules/**", | ||
"./dist/**", | ||
"./src/main.ts" | ||
"./src/index.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
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