Skip to content

Commit

Permalink
add methods to public API
Browse files Browse the repository at this point in the history
  • Loading branch information
bonartm committed Jul 13, 2021
1 parent 82ceea1 commit 5e88211
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/quizdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import App from './App.svelte';
import parseQuizdown from './parser.js';
import { Config } from './config.js';
import marked from './customizedMarked.js';
import type { Quiz } from './quiz';

export interface Quizdown {
register(extension: QuizdownExtension): void;
createApp(rawQuizdown: string, node: Element, config: Config): void;
register(extension: QuizdownExtension): Quizdown;
createApp(rawQuizdown: string, node: Element, config: Config): App;
parseQuizdown(rawQuizdown: string, config: Config): Quiz;
init(config: object): void;
getMarkedParser(): typeof marked;
}
Expand All @@ -14,12 +16,12 @@ export interface QuizdownExtension {
setup(quizdown: Quizdown): void;
}

function register(extension: QuizdownExtension) {
extension.setup(this);
return this;
function register(extension: QuizdownExtension): Quizdown {
extension.setup(this as Quizdown);
return this as Quizdown;
}

function createApp(rawQuizdown: string, node: Element, config: Config): void {
function createApp(rawQuizdown: string, node: Element, config: Config): App {
node.innerHTML = '';
let root: ShadowRoot;
if (!!node.shadowRoot) {
Expand All @@ -31,14 +33,15 @@ function createApp(rawQuizdown: string, node: Element, config: Config): void {
}
try {
let quiz = parseQuizdown(rawQuizdown, config);
new App({
let app = new App({
// https://github.com/sveltejs/svelte/pull/5870
target: root,
intro: false,
props: {
quiz: quiz,
},
});
return app;
} catch (e) {
root.innerHTML = `${e}. App could not render. Please check your quizdown syntax.`;
}
Expand Down Expand Up @@ -69,6 +72,7 @@ function getMarkedParser(): typeof marked {
let quizdown: Quizdown = {
init,
register,
parseQuizdown,
createApp,
getMarkedParser,
};
Expand Down

0 comments on commit 5e88211

Please sign in to comment.