Comparing version 2.0.7 to 2.0.8
declare module '*.css'; |
@@ -17,3 +17,4 @@ import { marked } from 'marked'; | ||
}>; | ||
type CartaEventType = 'carta-render' | 'carta-render-ssr'; | ||
declare const cartaEvents: readonly ["carta-render", "carta-render-ssr"]; | ||
type CartaEventType = (typeof cartaEvents)[number]; | ||
export type CartaListener<K extends CartaEventType | keyof HTMLElementEventMap> = [ | ||
@@ -126,4 +127,6 @@ type: K, | ||
readonly highlightRules: ShjLanguageDefinition; | ||
readonly listeners: CartaListeners; | ||
readonly textareaListeners: CartaListeners; | ||
readonly cartaListeners: CartaListeners; | ||
readonly components: CartaExtensionComponents; | ||
readonly dispatcher: EventTarget; | ||
private _input; | ||
@@ -130,0 +133,0 @@ private _renderer; |
@@ -8,2 +8,3 @@ import { marked } from 'marked'; | ||
import { loadCustomLanguage, highlight, highlightAutodetect } from './highlight.js'; | ||
const cartaEvents = ['carta-render', 'carta-render-ssr']; | ||
export class Carta { | ||
@@ -15,4 +16,6 @@ options; | ||
highlightRules; | ||
listeners; | ||
textareaListeners; | ||
cartaListeners; | ||
components; | ||
dispatcher = new EventTarget(); | ||
_input; | ||
@@ -31,5 +34,7 @@ _renderer; | ||
this.prefixes = []; | ||
this.listeners = []; | ||
this.textareaListeners = []; | ||
this.cartaListeners = []; | ||
this.components = []; | ||
this.highlightRules = []; | ||
const listeners = []; | ||
for (const ext of options?.extensions ?? []) { | ||
@@ -39,6 +44,13 @@ this.keyboardShortcuts.push(...(ext.shortcuts ?? [])); | ||
this.prefixes.push(...(ext.prefixes ?? [])); | ||
this.listeners.push(...(ext.listeners ?? [])); | ||
this.components.push(...(ext.components ?? [])); | ||
this.highlightRules.push(...(ext.highlightRules ?? [])); | ||
listeners.push(...(ext.listeners ?? [])); | ||
} | ||
// Split different listeners | ||
this.textareaListeners = listeners.filter((it) => !cartaEvents.includes(it[0])); | ||
this.cartaListeners = listeners.filter((it) => cartaEvents.includes(it[0])); | ||
// Setup carta listeners | ||
this.cartaListeners.forEach((it) => { | ||
this.dispatcher.addEventListener(...it); | ||
}); | ||
// Load default keyboard shortcuts | ||
@@ -84,3 +96,3 @@ this.keyboardShortcuts.push(...defaultKeyboardShortcuts.filter((shortcut) => options?.disableShortcuts === true | ||
const dirty = await marked.parse(markdown, { async: true }); | ||
this._input?.textarea.dispatchEvent(new CustomEvent('carta-render', { detail: { carta: this } })); | ||
this.dispatcher.dispatchEvent(new CustomEvent('carta-render', { detail: { carta: this } })); | ||
return (this.options?.sanitizer && this.options?.sanitizer(dirty)) ?? dirty; | ||
@@ -95,3 +107,3 @@ } | ||
const dirty = marked.parse(markdown, { async: false }); | ||
this._input?.textarea.dispatchEvent(new CustomEvent('carta-render-ssr', { detail: { carta: this } })); | ||
this.dispatcher.dispatchEvent(new CustomEvent('carta-render-ssr', { detail: { carta: this } })); | ||
if (this.options?.sanitizer) | ||
@@ -110,3 +122,3 @@ return this.options.sanitizer(dirty); | ||
prefixes: this.prefixes, | ||
listeners: this.listeners, | ||
listeners: this.textareaListeners, | ||
callback: callback, | ||
@@ -113,0 +125,0 @@ historyOpts: this.options?.historyOptions |
@@ -14,3 +14,3 @@ { | ||
}, | ||
"version": "2.0.7", | ||
"version": "2.0.8", | ||
"scripts": { | ||
@@ -17,0 +17,0 @@ "dev": "vite dev", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
164447
200
4705