@mikedown/web-component 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/LICENSE.md +21 -0
- package/README.md +258 -2
- package/THIRD_PARTY_NOTICES.md +2319 -0
- package/dist/chunk-E72SZEON.js +668 -0
- package/dist/chunk-E72SZEON.js.map +1 -0
- package/dist/define-BYCiu-_6.d.ts +96 -0
- package/dist/define.d.ts +2 -0
- package/dist/define.js +11 -0
- package/dist/define.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/mikedown-editor.standalone.js +316 -0
- package/package.json +74 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/element.ts","../src/hooks.ts","../src/index.ts"],"sourcesContent":["/**\n * <mikedown-editor>: the MikeDown editor as a form-associated custom element.\n *\n * Light DOM on purpose: core's menus and dialogs mount in a `.mikedown-portal`\n * on <body>, its stylesheet is scoped to `.mikedown-root` / `.mikedown-portal`\n * in the document, and ProseMirror's selection handling is unreliable inside a\n * shadow root. Value glue (debounce, blur flush, pristine loads, theme `auto`)\n * comes from core's `bindMikeDownValue`.\n */\n\nimport { bindMikeDownValue } from '@mikedown/core';\nimport type {\n BindingTheme,\n MikeDownBinding,\n MikeDownEditorHandle,\n MikeDownFeatures,\n MikeDownHost,\n MikeDownSettings,\n} from '@mikedown/core';\nimport { ensureDisplayStyle, runConnectHook } from './hooks';\n\n/** Detail of the `change` event. */\nexport interface MikeDownChangeEventDetail {\n value: string;\n}\n\n/** Detail of the `ready` event. */\nexport interface MikeDownReadyEventDetail {\n handle: MikeDownEditorHandle;\n}\n\nexport type MikeDownElementTheme = BindingTheme;\n\n/** Host methods the element accepts. `onChange` runs before the element's own handling. */\nexport type MikeDownElementHost = Partial<MikeDownHost>;\n\nconst OBSERVED = [\n 'value',\n 'theme',\n 'readonly',\n 'disabled',\n 'placeholder',\n 'name',\n 'required',\n 'min-height',\n 'dark-selector',\n 'spellcheck-dictionary-url',\n 'features',\n 'debounce',\n 'aria-label',\n 'aria-labelledby',\n] as const;\n\n/** Attributes read only when the editor is created: a change rebuilds it (the value is kept). */\nconst REBUILD_ON = new Set(['placeholder', 'spellcheck-dictionary-url', 'features', 'dark-selector', 'debounce', 'aria-label', 'aria-labelledby']);\n\n/** Properties a framework may set before the element is upgraded. */\nconst UPGRADE_PROPS = [\n 'value',\n 'defaultValue',\n 'theme',\n 'readOnly',\n 'disabled',\n 'placeholder',\n 'name',\n 'required',\n 'minHeight',\n 'darkSelector',\n 'spellcheckDictionaryUrl',\n 'features',\n 'settings',\n 'host',\n] as const;\n\nconst VALUE_MISSING_MESSAGE = 'Please fill out this field.';\n\n/** SSR-safe base: importing the module on a server must not throw. */\nconst Base = (typeof HTMLElement === 'undefined' ? class {} : HTMLElement) as typeof HTMLElement;\n\n/** Drop one leading newline and the common indentation of a server-rendered <script> body. */\nexport function dedentScriptText(text: string): string {\n const lines = text.replace(/^\\r?\\n/, '').replace(/\\s+$/, '').split(/\\r?\\n/);\n const indents = lines.filter((l) => l.trim()).map((l) => /^[ \\t]*/.exec(l)![0].length);\n const cut = indents.length ? Math.min(...indents) : 0;\n return lines.map((l) => l.slice(cut)).join('\\n') + (lines.length && lines.some((l) => l.trim()) ? '\\n' : '');\n}\n\nfunction parseTheme(value: string | null): BindingTheme {\n return value === 'light' || value === 'dark' ? value : 'auto';\n}\n\nexport class MikeDownElement extends Base {\n static formAssociated = true;\n\n static get observedAttributes(): string[] {\n return [...OBSERVED];\n }\n\n readonly #internals: ElementInternals | null;\n #binding: MikeDownBinding | null = null;\n /** Current value: the last text the editor reported, or the last one set. */\n #value = '';\n /** Reset target: the `value` attribute, else the child source's text at first connect. */\n #defaultValue = '';\n #valueSetByProperty = false;\n #initialized = false;\n #featuresAttrCache: { raw: string | null; parsed: Partial<MikeDownFeatures> | null } = { raw: null, parsed: null };\n #settings: Partial<MikeDownSettings> = {};\n #host: MikeDownElementHost = {};\n #formDisabled = false;\n #rebuildQueued = false;\n #fallbackInput: HTMLInputElement | null = null;\n #fallbackForm: HTMLFormElement | null = null;\n\n constructor() {\n super();\n let internals: ElementInternals | null = null;\n try {\n internals = typeof this.attachInternals === 'function' ? this.attachInternals() : null;\n } catch {\n internals = null;\n }\n this.#internals = internals;\n\n // A click whose target is the element itself comes from a <label for> (or\n // the element's own padding): move focus into the editor.\n this.addEventListener('click', (event) => {\n if (event.target !== this) {return;}\n const active = this.ownerDocument.activeElement;\n if (active && this.contains(active)) {return;}\n this.focus();\n });\n\n // Native `change` events from inputs inside the editor (find bar, dialogs)\n // would bubble out looking like the element's own. Registered first, so it\n // runs before any listener a page adds to the element.\n this.addEventListener('change', (event) => {\n if (event.target !== this) {event.stopImmediatePropagation();}\n });\n }\n\n // ── Lifecycle ─────────────────────────────────────────────────────────────\n\n connectedCallback(): void {\n if (!this.#initialized) {\n this.#initialized = true;\n for (const prop of UPGRADE_PROPS) {this.#upgradeProperty(prop);}\n this.#readInitialValue();\n }\n ensureDisplayStyle(this.ownerDocument, this.localName);\n this.#applyMinHeight();\n this.#attachFallbackForm();\n runConnectHook(this as unknown as HTMLElement & { features: Record<string, unknown> });\n this.#create();\n }\n\n disconnectedCallback(): void {\n this.#destroy();\n this.#detachFallbackForm();\n }\n\n attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void {\n if (oldValue === newValue) {return;}\n switch (name) {\n case 'value':\n this.#defaultValue = newValue ?? '';\n if (this.#initialized) {this.#setValue(newValue ?? '');}\n break;\n case 'theme':\n this.#binding?.setTheme(parseTheme(newValue));\n break;\n case 'readonly':\n this.#binding?.setReadOnly(newValue !== null);\n break;\n case 'disabled':\n this.#applyDisabled();\n break;\n case 'required':\n this.#syncValidity();\n break;\n case 'name':\n if (this.#fallbackInput) {this.#fallbackInput.name = newValue ?? '';}\n break;\n case 'min-height':\n this.#applyMinHeight();\n break;\n default:\n if (REBUILD_ON.has(name)) {this.#scheduleRebuild();}\n }\n }\n\n // ── Form-associated callbacks ─────────────────────────────────────────────\n\n formResetCallback(): void {\n this.#setValue(this.#defaultValue);\n this.#valueSetByProperty = false;\n }\n\n formDisabledCallback(disabled: boolean): void {\n this.#formDisabled = disabled;\n this.#applyDisabled();\n }\n\n formStateRestoreCallback(state: unknown): void {\n if (typeof state === 'string') {this.#setValue(state);}\n }\n\n // ── Value ─────────────────────────────────────────────────────────────────\n\n /** The markdown. Setting it loads the text as the pristine baseline and fires no `change`. */\n get value(): string {\n return this.#value;\n }\n set value(markdown: string) {\n this.#valueSetByProperty = true;\n this.#setValue(markdown == null ? '' : String(markdown));\n }\n\n /** The `value` attribute: the initial value and the target of a form reset. */\n get defaultValue(): string {\n return this.getAttribute('value') ?? this.#defaultValue;\n }\n set defaultValue(markdown: string) {\n this.setAttribute('value', markdown == null ? '' : String(markdown));\n }\n\n // ── Reflected attributes ──────────────────────────────────────────────────\n\n get theme(): BindingTheme {\n return parseTheme(this.getAttribute('theme'));\n }\n set theme(theme: BindingTheme) {\n this.setAttribute('theme', parseTheme(theme));\n }\n\n get readOnly(): boolean {\n return this.hasAttribute('readonly');\n }\n set readOnly(on: boolean) {\n this.toggleAttribute('readonly', !!on);\n }\n\n get disabled(): boolean {\n return this.hasAttribute('disabled');\n }\n set disabled(on: boolean) {\n this.toggleAttribute('disabled', !!on);\n }\n\n get required(): boolean {\n return this.hasAttribute('required');\n }\n set required(on: boolean) {\n this.toggleAttribute('required', !!on);\n }\n\n get placeholder(): string {\n return this.getAttribute('placeholder') ?? '';\n }\n set placeholder(text: string) {\n this.#setOrRemove('placeholder', text);\n }\n\n get name(): string {\n return this.getAttribute('name') ?? '';\n }\n set name(name: string) {\n this.#setOrRemove('name', name);\n }\n\n /** CSS length for the editor's minimum height (`--mikedown-min-height`). Default 240px. */\n get minHeight(): string {\n return this.getAttribute('min-height') ?? '';\n }\n set minHeight(value: string) {\n this.#setOrRemove('min-height', value);\n }\n\n /** With `theme=\"auto\"`: dark when `element.closest(selector)` matches, else light. */\n get darkSelector(): string {\n return this.getAttribute('dark-selector') ?? '';\n }\n set darkSelector(selector: string) {\n this.#setOrRemove('dark-selector', selector);\n }\n\n /** Folder base of the spell-check dictionaries (core appends `/en/` or `/en-GB/`). */\n get spellcheckDictionaryUrl(): string {\n return this.getAttribute('spellcheck-dictionary-url') ?? '';\n }\n set spellcheckDictionaryUrl(url: string) {\n this.#setOrRemove('spellcheck-dictionary-url', url);\n }\n\n /** Milliseconds of quiet before `change` fires. Default 150. */\n get debounce(): number {\n const n = Number(this.getAttribute('debounce'));\n return this.hasAttribute('debounce') && Number.isFinite(n) && n >= 0 ? n : 150;\n }\n set debounce(ms: number) {\n this.setAttribute('debounce', String(ms));\n }\n\n /** Feature switches. The `features` attribute takes the same object as JSON. Changing them rebuilds the editor. */\n get features(): Partial<MikeDownFeatures> {\n const raw = this.getAttribute('features');\n if (raw !== this.#featuresAttrCache.raw) {\n let parsed: Partial<MikeDownFeatures> | null = null;\n if (raw) {\n try {\n const json: unknown = JSON.parse(raw);\n if (json && typeof json === 'object' && !Array.isArray(json)) {parsed = json as Partial<MikeDownFeatures>;}\n else {console.warn('<mikedown-editor>: the features attribute must be a JSON object.');}\n } catch {\n console.warn('<mikedown-editor>: the features attribute is not valid JSON.');\n }\n }\n this.#featuresAttrCache = { raw, parsed };\n }\n return { ...(this.#featuresAttrCache.parsed ?? {}) };\n }\n set features(features: Partial<MikeDownFeatures> | null) {\n // Reflected as JSON (every flag is a boolean); the attribute change schedules the rebuild.\n if (features) {this.setAttribute('features', JSON.stringify(features));}\n else {this.removeAttribute('features');}\n }\n\n // ── Properties only ───────────────────────────────────────────────────────\n\n /** Core settings (fonts, content width, ...). Applied live through `handle.updateSettings`. */\n get settings(): Partial<MikeDownSettings> {\n return { ...this.#settings };\n }\n set settings(settings: Partial<MikeDownSettings> | null) {\n this.#settings = { ...(settings ?? {}) };\n this.#binding?.handle.updateSettings(this.#settings);\n }\n\n /**\n * Host methods (`uploadImage`, `openLink`, `resolveImageSrc`, ...). Core turns a\n * feature on only when its method is present, so a change rebuilds the editor.\n */\n get host(): MikeDownElementHost {\n return this.#host;\n }\n set host(host: MikeDownElementHost | null) {\n this.#host = host ?? {};\n this.#scheduleRebuild();\n }\n\n /** The editor handle while connected, else null. */\n get handle(): MikeDownEditorHandle | null {\n return this.#binding?.handle ?? null;\n }\n\n // ── Form and validity ─────────────────────────────────────────────────────\n\n get form(): HTMLFormElement | null {\n return this.#internals && 'form' in this.#internals ? this.#internals.form : this.closest('form');\n }\n\n get labels(): NodeList | HTMLLabelElement[] {\n return this.#internals?.labels ?? [];\n }\n\n get type(): string {\n return this.localName;\n }\n\n get validity(): ValidityState {\n if (this.#hasFormInternals()) {return this.#internals!.validity;}\n const valueMissing = this.#valueMissing();\n return { valueMissing, valid: !valueMissing } as ValidityState;\n }\n\n get validationMessage(): string {\n if (this.#hasFormInternals()) {return this.#internals!.validationMessage;}\n return this.#valueMissing() ? VALUE_MISSING_MESSAGE : '';\n }\n\n get willValidate(): boolean {\n if (this.#hasFormInternals()) {return this.#internals!.willValidate;}\n return !this.#isDisabled() && !this.readOnly;\n }\n\n checkValidity(): boolean {\n if (this.#hasFormInternals()) {return this.#internals!.checkValidity();}\n if (!this.willValidate || !this.#valueMissing()) {return true;}\n this.dispatchEvent(new Event('invalid', { cancelable: true }));\n return false;\n }\n\n reportValidity(): boolean {\n if (this.#hasFormInternals()) {return this.#internals!.reportValidity();}\n const ok = this.checkValidity();\n if (!ok) {this.focus();}\n return ok;\n }\n\n /** Focus the editable surface. */\n override focus(options?: FocusOptions): void {\n if (this.#binding) {this.#binding.focus();}\n else {super.focus(options);}\n }\n\n // ── Internals ─────────────────────────────────────────────────────────────\n\n #upgradeProperty(prop: (typeof UPGRADE_PROPS)[number]): void {\n if (Object.prototype.hasOwnProperty.call(this, prop)) {\n const value = (this as Record<string, unknown>)[prop];\n delete (this as Record<string, unknown>)[prop];\n (this as Record<string, unknown>)[prop] = value;\n }\n }\n\n /** `value` attribute, else a child <textarea> or <script type=\"text/markdown\">, which is then hidden. */\n #readInitialValue(): void {\n const source = this.querySelector<HTMLTextAreaElement | HTMLScriptElement>(\n ':scope > textarea, :scope > script[type=\"text/markdown\"]',\n );\n let sourceText: string | null = null;\n if (source && source.localName === 'textarea') {\n const textarea = source as HTMLTextAreaElement;\n sourceText = textarea.value;\n // Server-rendered pages put name/required/placeholder on the textarea.\n if (!this.hasAttribute('name') && textarea.name) {this.setAttribute('name', textarea.name);}\n if (!this.hasAttribute('required') && textarea.required) {this.setAttribute('required', '');}\n if (!this.hasAttribute('placeholder') && textarea.placeholder) {this.setAttribute('placeholder', textarea.placeholder);}\n // Hidden and disabled, so it neither shows nor submits a second value.\n textarea.hidden = true;\n textarea.style.display = 'none';\n textarea.disabled = true;\n textarea.setAttribute('aria-hidden', 'true');\n } else if (source) {\n sourceText = dedentScriptText(source.textContent ?? '');\n }\n\n const attr = this.getAttribute('value');\n this.#defaultValue = attr ?? sourceText ?? '';\n if (!this.#valueSetByProperty) {this.#value = this.#defaultValue;}\n }\n\n #create(): void {\n if (this.#binding || !this.isConnected) {return;}\n const { ariaLabel, ariaLabelledBy } = this.#accessibleName();\n const userHost = this.#host;\n const binding = bindMikeDownValue(this, {\n initialValue: this.#value,\n debounceMs: this.debounce,\n theme: this.theme,\n darkSelector: this.darkSelector || undefined,\n readOnly: this.readOnly,\n disabled: this.#isDisabled(),\n placeholder: this.getAttribute('placeholder') ?? undefined,\n spellcheckDictionaryUrl: this.spellcheckDictionaryUrl || undefined,\n features: this.features,\n settings: this.#settings,\n ariaLabel,\n ariaLabelledBy,\n host: {\n ...userHost,\n // Every keystroke keeps `value`, the form value and validity current;\n // the debounced `change` event comes from onValue below.\n onChange: (markdown: string, meta: { pristine: boolean }) => {\n userHost.onChange?.(markdown, meta);\n this.#value = markdown;\n this.#syncForm();\n },\n },\n onValue: (markdown: string) => {\n this.#value = markdown;\n this.#syncForm();\n this.dispatchEvent(\n new CustomEvent<MikeDownChangeEventDetail>('change', { detail: { value: markdown }, bubbles: true, composed: true }),\n );\n },\n });\n this.#binding = binding;\n this.#syncForm();\n // A microtask later, so a listener added right after appendChild (or\n // after the define script ran on parsed markup) still hears it.\n queueMicrotask(() => {\n if (this.#binding !== binding) {return;}\n this.dispatchEvent(\n new CustomEvent<MikeDownReadyEventDetail>('ready', { detail: { handle: binding.handle }, bubbles: true, composed: true }),\n );\n });\n }\n\n #destroy(): void {\n const binding = this.#binding;\n if (!binding) {return;}\n // destroy() flushes a pending change first (onValue keeps #value current).\n binding.destroy();\n this.#binding = null;\n }\n\n #scheduleRebuild(): void {\n if (!this.#binding || this.#rebuildQueued) {return;}\n this.#rebuildQueued = true;\n queueMicrotask(() => {\n this.#rebuildQueued = false;\n if (!this.#binding || !this.isConnected) {return;}\n const hadFocus = this.contains(this.ownerDocument.activeElement);\n this.#destroy();\n this.#create();\n if (hadFocus) {this.#binding?.focus();}\n });\n }\n\n #setValue(markdown: string): void {\n this.#value = markdown;\n this.#binding?.setValue(markdown);\n this.#syncForm();\n }\n\n #accessibleName(): { ariaLabel?: string; ariaLabelledBy?: string } {\n // ARIA precedence: aria-labelledby, then aria-label, then <label> elements.\n const labelledBy = this.getAttribute('aria-labelledby');\n if (labelledBy) {return { ariaLabelledBy: labelledBy };}\n const label = this.getAttribute('aria-label');\n if (label) {return { ariaLabel: label };}\n const labels = Array.from((this.#internals?.labels ?? []) as ArrayLike<HTMLElement>);\n if (!labels.length) {return {};}\n const ids = labels.map((el, i) => {\n if (!el.id) {el.id = `${this.id || 'mikedown-editor'}-label${labels.length > 1 ? `-${i + 1}` : ''}`;}\n return el.id;\n });\n return { ariaLabelledBy: ids.join(' ') };\n }\n\n #isDisabled(): boolean {\n return this.hasAttribute('disabled') || this.#formDisabled;\n }\n\n #applyDisabled(): void {\n this.#binding?.setDisabled(this.#isDisabled());\n if (this.#fallbackInput) {this.#fallbackInput.disabled = this.#isDisabled();}\n this.#syncValidity();\n }\n\n #applyMinHeight(): void {\n const value = this.getAttribute('min-height');\n if (value) {this.style.setProperty('--mikedown-min-height', /^\\d+(\\.\\d+)?$/.test(value) ? `${value}px` : value);}\n else {this.style.removeProperty('--mikedown-min-height');}\n }\n\n #setOrRemove(attr: string, value: string | null | undefined): void {\n if (value == null || value === '') {this.removeAttribute(attr);}\n else {this.setAttribute(attr, String(value));}\n }\n\n #hasFormInternals(): boolean {\n return !!this.#internals && typeof this.#internals.setFormValue === 'function';\n }\n\n #valueMissing(): boolean {\n return this.required && !this.#isDisabled() && this.#value.trim() === '';\n }\n\n #syncForm(): void {\n if (this.#hasFormInternals()) {\n this.#internals!.setFormValue(this.#value, this.#value);\n } else if (this.#fallbackInput) {\n this.#fallbackInput.value = this.#value;\n }\n this.#syncValidity();\n }\n\n #syncValidity(): void {\n if (!this.#hasFormInternals() || typeof this.#internals!.setValidity !== 'function') {return;}\n if (this.#valueMissing()) {\n const anchor = this.querySelector<HTMLElement>('.ProseMirror') ?? undefined;\n this.#internals!.setValidity({ valueMissing: true }, VALUE_MISSING_MESSAGE, anchor);\n } else {\n this.#internals!.setValidity({});\n }\n }\n\n /**\n * Without ElementInternals form support (jsdom, very old browsers) a hidden\n * <input> carries the value, and the form's reset event resets it.\n */\n #attachFallbackForm(): void {\n if (this.#hasFormInternals()) {return;}\n if (!this.#fallbackInput) {\n const input = this.ownerDocument.createElement('input');\n input.type = 'hidden';\n input.setAttribute('data-mikedown-form-value', '');\n this.#fallbackInput = input;\n }\n this.#fallbackInput.name = this.name;\n this.#fallbackInput.disabled = this.#isDisabled();\n this.#fallbackInput.value = this.#value;\n if (this.#fallbackInput.parentNode !== this) {this.appendChild(this.#fallbackInput);}\n const form = this.closest('form');\n if (form !== this.#fallbackForm) {\n this.#fallbackForm?.removeEventListener('reset', this.#onFallbackReset);\n form?.addEventListener('reset', this.#onFallbackReset);\n this.#fallbackForm = form;\n }\n }\n\n #detachFallbackForm(): void {\n this.#fallbackForm?.removeEventListener('reset', this.#onFallbackReset);\n this.#fallbackForm = null;\n }\n\n #onFallbackReset = (): void => {\n this.formResetCallback();\n };\n}\n","/**\n * Internal hooks shared by the element and the CDN entry. Not part of the\n * public API: the standalone bundle registers a connect hook that injects the\n * core stylesheet and KaTeX CSS; npm users import `@mikedown/core/styles.css`\n * themselves, so nothing is registered there.\n */\n\nexport type ConnectHook = (element: HTMLElement & { features: Record<string, unknown> }) => void;\n\nlet connectHook: ConnectHook | null = null;\n\nexport function setConnectHook(hook: ConnectHook | null): void {\n connectHook = hook;\n}\n\nexport function runConnectHook(element: HTMLElement & { features: Record<string, unknown> }): void {\n connectHook?.(element);\n}\n\nconst styledTags = new WeakMap<Document, Set<string>>();\n\n/**\n * `display: block` for the tag, at zero specificity so any page rule wins.\n * Uses a constructed stylesheet where supported (no inline <style>, so a\n * strict `style-src` CSP is fine), else one guarded <style> per tag.\n */\nexport function ensureDisplayStyle(doc: Document, tag: string): void {\n let tags = styledTags.get(doc);\n if (!tags) {\n tags = new Set();\n styledTags.set(doc, tags);\n }\n if (tags.has(tag)) {return;}\n tags.add(tag);\n const css = `:where(${tag}) { display: block; }`;\n const view = doc.defaultView as (Window & typeof globalThis) | null;\n try {\n if (view && 'adoptedStyleSheets' in doc && typeof view.CSSStyleSheet?.prototype.replaceSync === 'function') {\n const sheet = new view.CSSStyleSheet();\n sheet.replaceSync(css);\n doc.adoptedStyleSheets = [...doc.adoptedStyleSheets, sheet];\n return;\n }\n } catch {\n // Fall through to a <style> element.\n }\n const style = doc.createElement('style');\n style.setAttribute('data-mikedown-element', tag);\n style.textContent = css;\n doc.head.appendChild(style);\n}\n","/**\n * @mikedown/web-component: <mikedown-editor>, a form-associated custom element\n * around @mikedown/core.\n *\n * import { defineMikeDownElement } from '@mikedown/web-component';\n * import '@mikedown/core/styles.css';\n * defineMikeDownElement(); // registers <mikedown-editor>\n *\n * or, for the side effect alone: `import '@mikedown/web-component/define'`.\n */\n\nimport { MikeDownElement } from './element';\n\nexport { MikeDownElement, dedentScriptText } from './element';\nexport type {\n MikeDownChangeEventDetail,\n MikeDownReadyEventDetail,\n MikeDownElementTheme,\n MikeDownElementHost,\n} from './element';\n\nexport const DEFAULT_TAG = 'mikedown-editor';\n\n/**\n * Register the element under `tag` (default `mikedown-editor`) and return its\n * constructor. Safe to call more than once: a tag that is already defined is\n * left alone and its existing constructor returned. A second tag gets its own\n * subclass, since one class can only be registered once.\n */\nexport function defineMikeDownElement(tag: string = DEFAULT_TAG): CustomElementConstructor {\n if (typeof customElements === 'undefined') {return MikeDownElement;}\n const existing = customElements.get(tag);\n if (existing) {return existing;}\n const registry = customElements as CustomElementRegistry & { getName?(ctor: CustomElementConstructor): string | null };\n const baseTaken = baseDefined || !!registry.getName?.(MikeDownElement);\n const ctor = baseTaken ? class extends MikeDownElement {} : MikeDownElement;\n customElements.define(tag, ctor);\n if (ctor === MikeDownElement) {baseDefined = true;}\n return ctor;\n}\n\nlet baseDefined = false;\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'mikedown-editor': MikeDownElement;\n }\n}\n"],"mappings":";;;;;;;;;;AAUA,SAAS,yBAAyB;;;ACDlC,IAAI,cAAkC;AAM/B,SAAS,eAAe,SAAoE;AACjG,gBAAc,OAAO;AACvB;AAEA,IAAM,aAAa,oBAAI,QAA+B;AAO/C,SAAS,mBAAmB,KAAe,KAAmB;AACnE,MAAI,OAAO,WAAW,IAAI,GAAG;AAC7B,MAAI,CAAC,MAAM;AACT,WAAO,oBAAI,IAAI;AACf,eAAW,IAAI,KAAK,IAAI;AAAA,EAC1B;AACA,MAAI,KAAK,IAAI,GAAG,GAAG;AAAC;AAAA,EAAO;AAC3B,OAAK,IAAI,GAAG;AACZ,QAAM,MAAM,UAAU,GAAG;AACzB,QAAM,OAAO,IAAI;AACjB,MAAI;AACF,QAAI,QAAQ,wBAAwB,OAAO,OAAO,KAAK,eAAe,UAAU,gBAAgB,YAAY;AAC1G,YAAM,QAAQ,IAAI,KAAK,cAAc;AACrC,YAAM,YAAY,GAAG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Ae,oBAAoB,SAAS,mBAAK,iBAAgB;AACtE,UAAM,iBAAiB,SAAS,mBAAK,iBAAgB;AACrD,uBAAK,eAAgB;AAAA,EACvB;AACF;AAEA,wBAAmB,WAAS;AAC1B,qBAAK,gBAAe,oBAAoB,SAAS,mBAAK,iBAAgB;AACtE,qBAAK,eAAgB;AACvB;AAEA;AArgBW,gBACJ,iBAAiB;;;AEvEnB,IAAM,cAAc;AAQpB,SAAS,sBAAsB,MAAc,aAAuC;AACzF,MAAI,OAAO,mBAAmB,aAAa;AAAC,WAAO;AAAA,EAAgB;AACnE,QAAM,WAAW,eAAe,IAAI,GAAG;AACvC,MAAI,UAAU;AAAC,WAAO;AAAA,EAAS;AAC/B,QAAM,WAAW;AACjB,QAAM,YAAY,eAAe,CAAC,CAAC,SAAS,UAAU,eAAe;AACrE,QAAM,OAAO,YAAY,cAAc,gBAAgB;AAAA,EAAC,IAAI;AAC5D,iBAAe,OAAO,KAAK,IAAI;AAC/B,MAAI,SAAS,iBAAiB;AAAC,kBAAc;AAAA,EAAK;AAClD,SAAO;AACT;AAEA,IAAI,cAAc;","names":[]}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { BindingTheme, MikeDownFeatures, MikeDownSettings, MikeDownHost, MikeDownEditorHandle } from '@mikedown/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* <mikedown-editor>: the MikeDown editor as a form-associated custom element.
|
|
5
|
+
*
|
|
6
|
+
* Light DOM on purpose: core's menus and dialogs mount in a `.mikedown-portal`
|
|
7
|
+
* on <body>, its stylesheet is scoped to `.mikedown-root` / `.mikedown-portal`
|
|
8
|
+
* in the document, and ProseMirror's selection handling is unreliable inside a
|
|
9
|
+
* shadow root. Value glue (debounce, blur flush, pristine loads, theme `auto`)
|
|
10
|
+
* comes from core's `bindMikeDownValue`.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** Detail of the `change` event. */
|
|
14
|
+
interface MikeDownChangeEventDetail {
|
|
15
|
+
value: string;
|
|
16
|
+
}
|
|
17
|
+
/** Detail of the `ready` event. */
|
|
18
|
+
interface MikeDownReadyEventDetail {
|
|
19
|
+
handle: MikeDownEditorHandle;
|
|
20
|
+
}
|
|
21
|
+
type MikeDownElementTheme = BindingTheme;
|
|
22
|
+
/** Host methods the element accepts. `onChange` runs before the element's own handling. */
|
|
23
|
+
type MikeDownElementHost = Partial<MikeDownHost>;
|
|
24
|
+
/** SSR-safe base: importing the module on a server must not throw. */
|
|
25
|
+
declare const Base: typeof HTMLElement;
|
|
26
|
+
/** Drop one leading newline and the common indentation of a server-rendered <script> body. */
|
|
27
|
+
declare function dedentScriptText(text: string): string;
|
|
28
|
+
declare class MikeDownElement extends Base {
|
|
29
|
+
#private;
|
|
30
|
+
static formAssociated: boolean;
|
|
31
|
+
static get observedAttributes(): string[];
|
|
32
|
+
constructor();
|
|
33
|
+
connectedCallback(): void;
|
|
34
|
+
disconnectedCallback(): void;
|
|
35
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
36
|
+
formResetCallback(): void;
|
|
37
|
+
formDisabledCallback(disabled: boolean): void;
|
|
38
|
+
formStateRestoreCallback(state: unknown): void;
|
|
39
|
+
/** The markdown. Setting it loads the text as the pristine baseline and fires no `change`. */
|
|
40
|
+
get value(): string;
|
|
41
|
+
set value(markdown: string);
|
|
42
|
+
/** The `value` attribute: the initial value and the target of a form reset. */
|
|
43
|
+
get defaultValue(): string;
|
|
44
|
+
set defaultValue(markdown: string);
|
|
45
|
+
get theme(): BindingTheme;
|
|
46
|
+
set theme(theme: BindingTheme);
|
|
47
|
+
get readOnly(): boolean;
|
|
48
|
+
set readOnly(on: boolean);
|
|
49
|
+
get disabled(): boolean;
|
|
50
|
+
set disabled(on: boolean);
|
|
51
|
+
get required(): boolean;
|
|
52
|
+
set required(on: boolean);
|
|
53
|
+
get placeholder(): string;
|
|
54
|
+
set placeholder(text: string);
|
|
55
|
+
get name(): string;
|
|
56
|
+
set name(name: string);
|
|
57
|
+
/** CSS length for the editor's minimum height (`--mikedown-min-height`). Default 240px. */
|
|
58
|
+
get minHeight(): string;
|
|
59
|
+
set minHeight(value: string);
|
|
60
|
+
/** With `theme="auto"`: dark when `element.closest(selector)` matches, else light. */
|
|
61
|
+
get darkSelector(): string;
|
|
62
|
+
set darkSelector(selector: string);
|
|
63
|
+
/** Folder base of the spell-check dictionaries (core appends `/en/` or `/en-GB/`). */
|
|
64
|
+
get spellcheckDictionaryUrl(): string;
|
|
65
|
+
set spellcheckDictionaryUrl(url: string);
|
|
66
|
+
/** Milliseconds of quiet before `change` fires. Default 150. */
|
|
67
|
+
get debounce(): number;
|
|
68
|
+
set debounce(ms: number);
|
|
69
|
+
/** Feature switches. The `features` attribute takes the same object as JSON. Changing them rebuilds the editor. */
|
|
70
|
+
get features(): Partial<MikeDownFeatures>;
|
|
71
|
+
set features(features: Partial<MikeDownFeatures> | null);
|
|
72
|
+
/** Core settings (fonts, content width, ...). Applied live through `handle.updateSettings`. */
|
|
73
|
+
get settings(): Partial<MikeDownSettings>;
|
|
74
|
+
set settings(settings: Partial<MikeDownSettings> | null);
|
|
75
|
+
/**
|
|
76
|
+
* Host methods (`uploadImage`, `openLink`, `resolveImageSrc`, ...). Core turns a
|
|
77
|
+
* feature on only when its method is present, so a change rebuilds the editor.
|
|
78
|
+
*/
|
|
79
|
+
get host(): MikeDownElementHost;
|
|
80
|
+
set host(host: MikeDownElementHost | null);
|
|
81
|
+
/** The editor handle while connected, else null. */
|
|
82
|
+
get handle(): MikeDownEditorHandle | null;
|
|
83
|
+
get form(): HTMLFormElement | null;
|
|
84
|
+
get labels(): NodeList | HTMLLabelElement[];
|
|
85
|
+
get type(): string;
|
|
86
|
+
get validity(): ValidityState;
|
|
87
|
+
get validationMessage(): string;
|
|
88
|
+
get willValidate(): boolean;
|
|
89
|
+
checkValidity(): boolean;
|
|
90
|
+
reportValidity(): boolean;
|
|
91
|
+
/** Focus the editable surface. */
|
|
92
|
+
focus(options?: FocusOptions): void;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export { MikeDownElement as M, dedentScriptText as e };
|
|
96
|
+
export type { MikeDownChangeEventDetail as a, MikeDownElementHost as b, MikeDownElementTheme as c, MikeDownReadyEventDetail as d };
|
package/dist/define.d.ts
ADDED
package/dist/define.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/define.ts"],"sourcesContent":["/**\n * Side-effect entry: `import '@mikedown/web-component/define'` registers\n * <mikedown-editor> (once; a second import or an earlier definition is left alone).\n */\nimport { defineMikeDownElement } from './index';\n\ndefineMikeDownElement();\n\nexport { MikeDownElement } from './element';\n"],"mappings":";;;;;;AAMA,sBAAsB;","names":[]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { M as MikeDownElement } from './define-BYCiu-_6.js';
|
|
2
|
+
export { a as MikeDownChangeEventDetail, b as MikeDownElementHost, c as MikeDownElementTheme, d as MikeDownReadyEventDetail, e as dedentScriptText } from './define-BYCiu-_6.js';
|
|
3
|
+
import '@mikedown/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @mikedown/web-component: <mikedown-editor>, a form-associated custom element
|
|
7
|
+
* around @mikedown/core.
|
|
8
|
+
*
|
|
9
|
+
* import { defineMikeDownElement } from '@mikedown/web-component';
|
|
10
|
+
* import '@mikedown/core/styles.css';
|
|
11
|
+
* defineMikeDownElement(); // registers <mikedown-editor>
|
|
12
|
+
*
|
|
13
|
+
* or, for the side effect alone: `import '@mikedown/web-component/define'`.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
declare const DEFAULT_TAG = "mikedown-editor";
|
|
17
|
+
/**
|
|
18
|
+
* Register the element under `tag` (default `mikedown-editor`) and return its
|
|
19
|
+
* constructor. Safe to call more than once: a tag that is already defined is
|
|
20
|
+
* left alone and its existing constructor returned. A second tag gets its own
|
|
21
|
+
* subclass, since one class can only be registered once.
|
|
22
|
+
*/
|
|
23
|
+
declare function defineMikeDownElement(tag?: string): CustomElementConstructor;
|
|
24
|
+
declare global {
|
|
25
|
+
interface HTMLElementTagNameMap {
|
|
26
|
+
'mikedown-editor': MikeDownElement;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { DEFAULT_TAG, MikeDownElement, defineMikeDownElement };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|