Skip to content

Commit

Permalink
fix: tsconfig issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Eschricht committed Apr 18, 2024
1 parent c25c96b commit 276d915
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 60 deletions.
2 changes: 1 addition & 1 deletion packages/newsletter-subscription/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ <h1>This is a test application</h1>

<div id="newsletter-form" />

<script type="module" src="src/index.ts"></script>
<script type="module" src="src/main.ts"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion packages/newsletter-subscription/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/main.d.ts",
"types": "./dist/index.d.ts",
"files": [
"dist/"
],
Expand Down
53 changes: 51 additions & 2 deletions packages/newsletter-subscription/src/index.ts
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)
}
}
53 changes: 2 additions & 51 deletions packages/newsletter-subscription/src/main.ts
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 || {}
8 changes: 5 additions & 3 deletions packages/newsletter-subscription/tsconfig.build.json
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"
]
}
3 changes: 2 additions & 1 deletion packages/newsletter-subscription/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"isolatedModules": true
},
"references": [{ "path": "./tsconfig.node.json" }],
"include": ["src/**/*.ts", "src/**/*.js", "src/**/*.svelte", "./nortic.d.ts", "tests/**/*.spec.ts"]
"include": ["src/**/*.ts", "src/**/*.js", "src/**/*.svelte"],
"exclude": ["src/main.ts"]
}
2 changes: 1 addition & 1 deletion packages/newsletter-subscription/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default defineConfig({
plugins: [svelte(), dts()],
build: {
lib: {
entry: 'src/main.ts',
entry: 'src/index.ts',
name: 'NorticNewsletter',
fileName: (module) => {
switch (module) {
Expand Down

0 comments on commit 276d915

Please sign in to comment.