diff --git a/rollup.config.vanilla-types.js b/rollup.config.vanilla-types.js index 5d1c8141..84ec4817 100644 --- a/rollup.config.vanilla-types.js +++ b/rollup.config.vanilla-types.js @@ -12,23 +12,5 @@ export default { format: 'es' } ], - plugins: [dts(), exportJsonEditorClass()] -} - -// The DTS plugin doesn't export the JsonEditor class that is generated by Svelte whilst compiling, -// so we append an export for it manually. Similarly, the CreateJSONEditorProps interface is not -// exported by DTS, so we add an export for it too. -function exportJsonEditorClass() { - return { - name: 'export-json-editor', - transform: (code, id) => { - if (id.endsWith('index-vanilla.d.ts')) { - const customExports = 'export type { JsonEditor, CreateJSONEditorProps }' - - return `${code}\n${customExports}\n` - } - - return code - } - } + plugins: [dts()] } diff --git a/src/lib/index-vanilla.ts b/src/lib/index-vanilla.ts index 88be5b7f..c7f97766 100644 --- a/src/lib/index-vanilla.ts +++ b/src/lib/index-vanilla.ts @@ -1,4 +1,4 @@ -import JSONEditorComponent from './components/JSONEditor.svelte' +import JsonEditor from './components/JSONEditor.svelte' import type { JSONEditorPropsOptional } from '$lib/types' import { mount, unmount } from 'svelte' @@ -6,13 +6,15 @@ import { mount, unmount } from 'svelte' // since we cannot use it in the vanilla environment starting in Svelte 5. export * from './index' -interface CreateJSONEditorProps { +export interface CreateJSONEditorProps { target: HTMLDivElement props: JSONEditorPropsOptional } -export function createJSONEditor({ target, props }: Parameters[1]) { - const editor = mount(JSONEditorComponent, { target, props }) +export { JsonEditor } + +export function createJSONEditor({ target, props }: Parameters[1]): JsonEditor { + const editor = mount(JsonEditor, { target, props }) editor.destroy = async () => { unmount(editor) @@ -20,12 +22,10 @@ export function createJSONEditor({ target, props }: Parameters[1]) return new Promise((resolve) => setTimeout(resolve)) } - return editor + return editor as JsonEditor } /** - * JSONEditor class - * @constructor * @deprecated The constructor "new JSONEditor(...)" is deprecated. Please use "createJSONEditor(...)" instead. */ export function JSONEditor({ target, props }: CreateJSONEditorProps) {