@mikedown/web-component 0.0.0-stage → 0.3.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.
@@ -0,0 +1,684 @@
1
+ var __typeError = (msg) => {
2
+ throw TypeError(msg);
3
+ };
4
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
9
+
10
+ // src/element.ts
11
+ import { bindMikeDownValue } from "@mikedown/core";
12
+
13
+ // src/hooks.ts
14
+ var connectHook = null;
15
+ function runConnectHook(element) {
16
+ connectHook?.(element);
17
+ }
18
+ var styledTags = /* @__PURE__ */ new WeakMap();
19
+ function ensureDisplayStyle(doc, tag) {
20
+ let tags = styledTags.get(doc);
21
+ if (!tags) {
22
+ tags = /* @__PURE__ */ new Set();
23
+ styledTags.set(doc, tags);
24
+ }
25
+ if (tags.has(tag)) {
26
+ return;
27
+ }
28
+ tags.add(tag);
29
+ const css = `:where(${tag}) { display: block; }`;
30
+ const view = doc.defaultView;
31
+ try {
32
+ if (view && "adoptedStyleSheets" in doc && typeof view.CSSStyleSheet?.prototype.replaceSync === "function") {
33
+ const sheet = new view.CSSStyleSheet();
34
+ sheet.replaceSync(css);
35
+ doc.adoptedStyleSheets = [...doc.adoptedStyleSheets, sheet];
36
+ return;
37
+ }
38
+ } catch {
39
+ }
40
+ const style = doc.createElement("style");
41
+ style.setAttribute("data-mikedown-element", tag);
42
+ style.textContent = css;
43
+ doc.head.appendChild(style);
44
+ }
45
+
46
+ // src/element.ts
47
+ var OBSERVED = [
48
+ "value",
49
+ "theme",
50
+ "readonly",
51
+ "disabled",
52
+ "placeholder",
53
+ "name",
54
+ "required",
55
+ "min-height",
56
+ "dark-selector",
57
+ "spellcheck-dictionary-url",
58
+ "features",
59
+ "debounce",
60
+ "aria-label",
61
+ "aria-labelledby"
62
+ ];
63
+ var REBUILD_ON = /* @__PURE__ */ new Set(["placeholder", "spellcheck-dictionary-url", "features", "dark-selector", "debounce", "aria-label", "aria-labelledby"]);
64
+ var UPGRADE_PROPS = [
65
+ "value",
66
+ "defaultValue",
67
+ "theme",
68
+ "readOnly",
69
+ "disabled",
70
+ "placeholder",
71
+ "name",
72
+ "required",
73
+ "minHeight",
74
+ "darkSelector",
75
+ "spellcheckDictionaryUrl",
76
+ "features",
77
+ "settings",
78
+ "host"
79
+ ];
80
+ var VALUE_MISSING_MESSAGE = "Please fill out this field.";
81
+ var Base = typeof HTMLElement === "undefined" ? class {
82
+ } : HTMLElement;
83
+ function dedentScriptText(text) {
84
+ const lines = text.replace(/^\r?\n/, "").replace(/\s+$/, "").split(/\r?\n/);
85
+ const indents = lines.filter((l) => l.trim()).map((l) => /^[ \t]*/.exec(l)[0].length);
86
+ const cut = indents.length ? Math.min(...indents) : 0;
87
+ return lines.map((l) => l.slice(cut)).join("\n") + (lines.length && lines.some((l) => l.trim()) ? "\n" : "");
88
+ }
89
+ function parseTheme(value) {
90
+ return value === "light" || value === "dark" ? value : "auto";
91
+ }
92
+ var _internals, _binding, _value, _defaultValue, _valueSetByProperty, _initialized, _featuresAttrCache, _settings, _host, _ai, _formDisabled, _rebuildQueued, _fallbackInput, _fallbackForm, _MikeDownElement_instances, upgradeProperty_fn, readInitialValue_fn, create_fn, destroy_fn, scheduleRebuild_fn, setValue_fn, accessibleName_fn, isDisabled_fn, applyDisabled_fn, applyMinHeight_fn, setOrRemove_fn, hasFormInternals_fn, valueMissing_fn, syncForm_fn, syncValidity_fn, attachFallbackForm_fn, detachFallbackForm_fn, _onFallbackReset;
93
+ var MikeDownElement = class extends Base {
94
+ constructor() {
95
+ super();
96
+ __privateAdd(this, _MikeDownElement_instances);
97
+ __privateAdd(this, _internals);
98
+ __privateAdd(this, _binding, null);
99
+ /** Current value: the last text the editor reported, or the last one set. */
100
+ __privateAdd(this, _value, "");
101
+ /** Reset target: the `value` attribute, else the child source's text at first connect. */
102
+ __privateAdd(this, _defaultValue, "");
103
+ __privateAdd(this, _valueSetByProperty, false);
104
+ __privateAdd(this, _initialized, false);
105
+ __privateAdd(this, _featuresAttrCache, { raw: null, parsed: null });
106
+ __privateAdd(this, _settings, {});
107
+ __privateAdd(this, _host, {});
108
+ __privateAdd(this, _ai);
109
+ __privateAdd(this, _formDisabled, false);
110
+ __privateAdd(this, _rebuildQueued, false);
111
+ __privateAdd(this, _fallbackInput, null);
112
+ __privateAdd(this, _fallbackForm, null);
113
+ __privateAdd(this, _onFallbackReset, () => {
114
+ this.formResetCallback();
115
+ });
116
+ let internals = null;
117
+ try {
118
+ internals = typeof this.attachInternals === "function" ? this.attachInternals() : null;
119
+ } catch {
120
+ internals = null;
121
+ }
122
+ __privateSet(this, _internals, internals);
123
+ this.addEventListener("click", (event) => {
124
+ if (event.target !== this) {
125
+ return;
126
+ }
127
+ const active = this.ownerDocument.activeElement;
128
+ if (active && this.contains(active)) {
129
+ return;
130
+ }
131
+ this.focus();
132
+ });
133
+ this.addEventListener("change", (event) => {
134
+ if (event.target !== this) {
135
+ event.stopImmediatePropagation();
136
+ }
137
+ });
138
+ }
139
+ static get observedAttributes() {
140
+ return [...OBSERVED];
141
+ }
142
+ // ── Lifecycle ─────────────────────────────────────────────────────────────
143
+ connectedCallback() {
144
+ if (!__privateGet(this, _initialized)) {
145
+ __privateSet(this, _initialized, true);
146
+ for (const prop of UPGRADE_PROPS) {
147
+ __privateMethod(this, _MikeDownElement_instances, upgradeProperty_fn).call(this, prop);
148
+ }
149
+ __privateMethod(this, _MikeDownElement_instances, readInitialValue_fn).call(this);
150
+ }
151
+ ensureDisplayStyle(this.ownerDocument, this.localName);
152
+ __privateMethod(this, _MikeDownElement_instances, applyMinHeight_fn).call(this);
153
+ __privateMethod(this, _MikeDownElement_instances, attachFallbackForm_fn).call(this);
154
+ runConnectHook(this);
155
+ __privateMethod(this, _MikeDownElement_instances, create_fn).call(this);
156
+ }
157
+ disconnectedCallback() {
158
+ __privateMethod(this, _MikeDownElement_instances, destroy_fn).call(this);
159
+ __privateMethod(this, _MikeDownElement_instances, detachFallbackForm_fn).call(this);
160
+ }
161
+ attributeChangedCallback(name, oldValue, newValue) {
162
+ if (oldValue === newValue) {
163
+ return;
164
+ }
165
+ switch (name) {
166
+ case "value":
167
+ __privateSet(this, _defaultValue, newValue ?? "");
168
+ if (__privateGet(this, _initialized)) {
169
+ __privateMethod(this, _MikeDownElement_instances, setValue_fn).call(this, newValue ?? "");
170
+ }
171
+ break;
172
+ case "theme":
173
+ __privateGet(this, _binding)?.setTheme(parseTheme(newValue));
174
+ break;
175
+ case "readonly":
176
+ __privateGet(this, _binding)?.setReadOnly(newValue !== null);
177
+ break;
178
+ case "disabled":
179
+ __privateMethod(this, _MikeDownElement_instances, applyDisabled_fn).call(this);
180
+ break;
181
+ case "required":
182
+ __privateMethod(this, _MikeDownElement_instances, syncValidity_fn).call(this);
183
+ break;
184
+ case "name":
185
+ if (__privateGet(this, _fallbackInput)) {
186
+ __privateGet(this, _fallbackInput).name = newValue ?? "";
187
+ }
188
+ break;
189
+ case "min-height":
190
+ __privateMethod(this, _MikeDownElement_instances, applyMinHeight_fn).call(this);
191
+ break;
192
+ default:
193
+ if (REBUILD_ON.has(name)) {
194
+ __privateMethod(this, _MikeDownElement_instances, scheduleRebuild_fn).call(this);
195
+ }
196
+ }
197
+ }
198
+ // ── Form-associated callbacks ─────────────────────────────────────────────
199
+ formResetCallback() {
200
+ __privateMethod(this, _MikeDownElement_instances, setValue_fn).call(this, __privateGet(this, _defaultValue));
201
+ __privateSet(this, _valueSetByProperty, false);
202
+ }
203
+ formDisabledCallback(disabled) {
204
+ __privateSet(this, _formDisabled, disabled);
205
+ __privateMethod(this, _MikeDownElement_instances, applyDisabled_fn).call(this);
206
+ }
207
+ formStateRestoreCallback(state) {
208
+ if (typeof state === "string") {
209
+ __privateMethod(this, _MikeDownElement_instances, setValue_fn).call(this, state);
210
+ }
211
+ }
212
+ // ── Value ─────────────────────────────────────────────────────────────────
213
+ /** The markdown. Setting it loads the text as the pristine baseline and fires no `change`. */
214
+ get value() {
215
+ return __privateGet(this, _value);
216
+ }
217
+ set value(markdown) {
218
+ __privateSet(this, _valueSetByProperty, true);
219
+ __privateMethod(this, _MikeDownElement_instances, setValue_fn).call(this, markdown == null ? "" : String(markdown));
220
+ }
221
+ /** The `value` attribute: the initial value and the target of a form reset. */
222
+ get defaultValue() {
223
+ return this.getAttribute("value") ?? __privateGet(this, _defaultValue);
224
+ }
225
+ set defaultValue(markdown) {
226
+ this.setAttribute("value", markdown == null ? "" : String(markdown));
227
+ }
228
+ // ── Reflected attributes ──────────────────────────────────────────────────
229
+ get theme() {
230
+ return parseTheme(this.getAttribute("theme"));
231
+ }
232
+ set theme(theme) {
233
+ this.setAttribute("theme", parseTheme(theme));
234
+ }
235
+ get readOnly() {
236
+ return this.hasAttribute("readonly");
237
+ }
238
+ set readOnly(on) {
239
+ this.toggleAttribute("readonly", !!on);
240
+ }
241
+ get disabled() {
242
+ return this.hasAttribute("disabled");
243
+ }
244
+ set disabled(on) {
245
+ this.toggleAttribute("disabled", !!on);
246
+ }
247
+ get required() {
248
+ return this.hasAttribute("required");
249
+ }
250
+ set required(on) {
251
+ this.toggleAttribute("required", !!on);
252
+ }
253
+ get placeholder() {
254
+ return this.getAttribute("placeholder") ?? "";
255
+ }
256
+ set placeholder(text) {
257
+ __privateMethod(this, _MikeDownElement_instances, setOrRemove_fn).call(this, "placeholder", text);
258
+ }
259
+ get name() {
260
+ return this.getAttribute("name") ?? "";
261
+ }
262
+ set name(name) {
263
+ __privateMethod(this, _MikeDownElement_instances, setOrRemove_fn).call(this, "name", name);
264
+ }
265
+ /** CSS length for the editor's minimum height (`--mikedown-min-height`). Default 240px. */
266
+ get minHeight() {
267
+ return this.getAttribute("min-height") ?? "";
268
+ }
269
+ set minHeight(value) {
270
+ __privateMethod(this, _MikeDownElement_instances, setOrRemove_fn).call(this, "min-height", value);
271
+ }
272
+ /** With `theme="auto"`: dark when `element.closest(selector)` matches, else light. */
273
+ get darkSelector() {
274
+ return this.getAttribute("dark-selector") ?? "";
275
+ }
276
+ set darkSelector(selector) {
277
+ __privateMethod(this, _MikeDownElement_instances, setOrRemove_fn).call(this, "dark-selector", selector);
278
+ }
279
+ /** Folder base of the spell-check dictionaries (core appends `/en/` or `/en-GB/`). */
280
+ get spellcheckDictionaryUrl() {
281
+ return this.getAttribute("spellcheck-dictionary-url") ?? "";
282
+ }
283
+ set spellcheckDictionaryUrl(url) {
284
+ __privateMethod(this, _MikeDownElement_instances, setOrRemove_fn).call(this, "spellcheck-dictionary-url", url);
285
+ }
286
+ /** Milliseconds of quiet before `change` fires. Default 150. */
287
+ get debounce() {
288
+ const n = Number(this.getAttribute("debounce"));
289
+ return this.hasAttribute("debounce") && Number.isFinite(n) && n >= 0 ? n : 150;
290
+ }
291
+ set debounce(ms) {
292
+ this.setAttribute("debounce", String(ms));
293
+ }
294
+ /** Feature switches. The `features` attribute takes the same object as JSON. Changing them rebuilds the editor. */
295
+ get features() {
296
+ const raw = this.getAttribute("features");
297
+ if (raw !== __privateGet(this, _featuresAttrCache).raw) {
298
+ let parsed = null;
299
+ if (raw) {
300
+ try {
301
+ const json = JSON.parse(raw);
302
+ if (json && typeof json === "object" && !Array.isArray(json)) {
303
+ parsed = json;
304
+ } else {
305
+ console.warn("<mikedown-editor>: the features attribute must be a JSON object.");
306
+ }
307
+ } catch {
308
+ console.warn("<mikedown-editor>: the features attribute is not valid JSON.");
309
+ }
310
+ }
311
+ __privateSet(this, _featuresAttrCache, { raw, parsed });
312
+ }
313
+ return { ...__privateGet(this, _featuresAttrCache).parsed ?? {} };
314
+ }
315
+ set features(features) {
316
+ if (features) {
317
+ this.setAttribute("features", JSON.stringify(features));
318
+ } else {
319
+ this.removeAttribute("features");
320
+ }
321
+ }
322
+ // ── Properties only ───────────────────────────────────────────────────────
323
+ /** Core settings (fonts, content width, ...). Applied live through `handle.updateSettings`. */
324
+ get settings() {
325
+ return { ...__privateGet(this, _settings) };
326
+ }
327
+ set settings(settings) {
328
+ __privateSet(this, _settings, { ...settings ?? {} });
329
+ __privateGet(this, _binding)?.handle.updateSettings(__privateGet(this, _settings));
330
+ }
331
+ /**
332
+ * Host methods (`uploadImage`, `openLink`, `resolveImageSrc`, ...). Core turns a
333
+ * feature on only when its method is present, so a change rebuilds the editor.
334
+ */
335
+ get host() {
336
+ return __privateGet(this, _host);
337
+ }
338
+ set host(host) {
339
+ __privateSet(this, _host, host ?? {});
340
+ __privateMethod(this, _MikeDownElement_instances, scheduleRebuild_fn).call(this);
341
+ }
342
+ /**
343
+ * The AI host group (`complete`, and for tier 2 `listEngines`, `testEngine`, ...). A property only: it holds
344
+ * functions, so there is no attribute. Wins over `host.ai`. Core turns the AI features on when it is present,
345
+ * so a change rebuilds the editor. Core ships no provider SDK; the page supplies the transport.
346
+ */
347
+ get ai() {
348
+ return __privateGet(this, _ai) ?? __privateGet(this, _host).ai;
349
+ }
350
+ set ai(ai) {
351
+ __privateSet(this, _ai, ai ?? void 0);
352
+ __privateMethod(this, _MikeDownElement_instances, scheduleRebuild_fn).call(this);
353
+ }
354
+ /** The editor handle while connected, else null. */
355
+ get handle() {
356
+ return __privateGet(this, _binding)?.handle ?? null;
357
+ }
358
+ // ── Form and validity ─────────────────────────────────────────────────────
359
+ get form() {
360
+ return __privateGet(this, _internals) && "form" in __privateGet(this, _internals) ? __privateGet(this, _internals).form : this.closest("form");
361
+ }
362
+ get labels() {
363
+ return __privateGet(this, _internals)?.labels ?? [];
364
+ }
365
+ get type() {
366
+ return this.localName;
367
+ }
368
+ get validity() {
369
+ if (__privateMethod(this, _MikeDownElement_instances, hasFormInternals_fn).call(this)) {
370
+ return __privateGet(this, _internals).validity;
371
+ }
372
+ const valueMissing = __privateMethod(this, _MikeDownElement_instances, valueMissing_fn).call(this);
373
+ return { valueMissing, valid: !valueMissing };
374
+ }
375
+ get validationMessage() {
376
+ if (__privateMethod(this, _MikeDownElement_instances, hasFormInternals_fn).call(this)) {
377
+ return __privateGet(this, _internals).validationMessage;
378
+ }
379
+ return __privateMethod(this, _MikeDownElement_instances, valueMissing_fn).call(this) ? VALUE_MISSING_MESSAGE : "";
380
+ }
381
+ get willValidate() {
382
+ if (__privateMethod(this, _MikeDownElement_instances, hasFormInternals_fn).call(this)) {
383
+ return __privateGet(this, _internals).willValidate;
384
+ }
385
+ return !__privateMethod(this, _MikeDownElement_instances, isDisabled_fn).call(this) && !this.readOnly;
386
+ }
387
+ checkValidity() {
388
+ if (__privateMethod(this, _MikeDownElement_instances, hasFormInternals_fn).call(this)) {
389
+ return __privateGet(this, _internals).checkValidity();
390
+ }
391
+ if (!this.willValidate || !__privateMethod(this, _MikeDownElement_instances, valueMissing_fn).call(this)) {
392
+ return true;
393
+ }
394
+ this.dispatchEvent(new Event("invalid", { cancelable: true }));
395
+ return false;
396
+ }
397
+ reportValidity() {
398
+ if (__privateMethod(this, _MikeDownElement_instances, hasFormInternals_fn).call(this)) {
399
+ return __privateGet(this, _internals).reportValidity();
400
+ }
401
+ const ok = this.checkValidity();
402
+ if (!ok) {
403
+ this.focus();
404
+ }
405
+ return ok;
406
+ }
407
+ /** Focus the editable surface. */
408
+ focus(options) {
409
+ if (__privateGet(this, _binding)) {
410
+ __privateGet(this, _binding).focus();
411
+ } else {
412
+ super.focus(options);
413
+ }
414
+ }
415
+ };
416
+ _internals = new WeakMap();
417
+ _binding = new WeakMap();
418
+ _value = new WeakMap();
419
+ _defaultValue = new WeakMap();
420
+ _valueSetByProperty = new WeakMap();
421
+ _initialized = new WeakMap();
422
+ _featuresAttrCache = new WeakMap();
423
+ _settings = new WeakMap();
424
+ _host = new WeakMap();
425
+ _ai = new WeakMap();
426
+ _formDisabled = new WeakMap();
427
+ _rebuildQueued = new WeakMap();
428
+ _fallbackInput = new WeakMap();
429
+ _fallbackForm = new WeakMap();
430
+ _MikeDownElement_instances = new WeakSet();
431
+ // ── Internals ─────────────────────────────────────────────────────────────
432
+ upgradeProperty_fn = function(prop) {
433
+ if (Object.prototype.hasOwnProperty.call(this, prop)) {
434
+ const value = this[prop];
435
+ delete this[prop];
436
+ this[prop] = value;
437
+ }
438
+ };
439
+ /** `value` attribute, else a child <textarea> or <script type="text/markdown">, which is then hidden. */
440
+ readInitialValue_fn = function() {
441
+ const source = this.querySelector(
442
+ ':scope > textarea, :scope > script[type="text/markdown"]'
443
+ );
444
+ let sourceText = null;
445
+ if (source && source.localName === "textarea") {
446
+ const textarea = source;
447
+ sourceText = textarea.value;
448
+ if (!this.hasAttribute("name") && textarea.name) {
449
+ this.setAttribute("name", textarea.name);
450
+ }
451
+ if (!this.hasAttribute("required") && textarea.required) {
452
+ this.setAttribute("required", "");
453
+ }
454
+ if (!this.hasAttribute("placeholder") && textarea.placeholder) {
455
+ this.setAttribute("placeholder", textarea.placeholder);
456
+ }
457
+ textarea.hidden = true;
458
+ textarea.style.display = "none";
459
+ textarea.disabled = true;
460
+ textarea.setAttribute("aria-hidden", "true");
461
+ } else if (source) {
462
+ sourceText = dedentScriptText(source.textContent ?? "");
463
+ }
464
+ const attr = this.getAttribute("value");
465
+ __privateSet(this, _defaultValue, attr ?? sourceText ?? "");
466
+ if (!__privateGet(this, _valueSetByProperty)) {
467
+ __privateSet(this, _value, __privateGet(this, _defaultValue));
468
+ }
469
+ };
470
+ create_fn = function() {
471
+ if (__privateGet(this, _binding) || !this.isConnected) {
472
+ return;
473
+ }
474
+ const { ariaLabel, ariaLabelledBy } = __privateMethod(this, _MikeDownElement_instances, accessibleName_fn).call(this);
475
+ const userHost = __privateGet(this, _host);
476
+ const ai = __privateGet(this, _ai) ?? userHost.ai;
477
+ const binding = bindMikeDownValue(this, {
478
+ initialValue: __privateGet(this, _value),
479
+ debounceMs: this.debounce,
480
+ theme: this.theme,
481
+ darkSelector: this.darkSelector || void 0,
482
+ readOnly: this.readOnly,
483
+ disabled: __privateMethod(this, _MikeDownElement_instances, isDisabled_fn).call(this),
484
+ placeholder: this.getAttribute("placeholder") ?? void 0,
485
+ spellcheckDictionaryUrl: this.spellcheckDictionaryUrl || void 0,
486
+ features: this.features,
487
+ settings: __privateGet(this, _settings),
488
+ ariaLabel,
489
+ ariaLabelledBy,
490
+ host: {
491
+ ...userHost,
492
+ ...ai ? { ai } : {},
493
+ // Every keystroke keeps `value`, the form value and validity current;
494
+ // the debounced `change` event comes from onValue below.
495
+ onChange: (markdown, meta) => {
496
+ userHost.onChange?.(markdown, meta);
497
+ __privateSet(this, _value, markdown);
498
+ __privateMethod(this, _MikeDownElement_instances, syncForm_fn).call(this);
499
+ }
500
+ },
501
+ onValue: (markdown) => {
502
+ __privateSet(this, _value, markdown);
503
+ __privateMethod(this, _MikeDownElement_instances, syncForm_fn).call(this);
504
+ this.dispatchEvent(
505
+ new CustomEvent("change", { detail: { value: markdown }, bubbles: true, composed: true })
506
+ );
507
+ }
508
+ });
509
+ __privateSet(this, _binding, binding);
510
+ __privateMethod(this, _MikeDownElement_instances, syncForm_fn).call(this);
511
+ queueMicrotask(() => {
512
+ if (__privateGet(this, _binding) !== binding) {
513
+ return;
514
+ }
515
+ this.dispatchEvent(
516
+ new CustomEvent("ready", { detail: { handle: binding.handle }, bubbles: true, composed: true })
517
+ );
518
+ });
519
+ };
520
+ destroy_fn = function() {
521
+ const binding = __privateGet(this, _binding);
522
+ if (!binding) {
523
+ return;
524
+ }
525
+ binding.destroy();
526
+ __privateSet(this, _binding, null);
527
+ };
528
+ scheduleRebuild_fn = function() {
529
+ if (!__privateGet(this, _binding) || __privateGet(this, _rebuildQueued)) {
530
+ return;
531
+ }
532
+ __privateSet(this, _rebuildQueued, true);
533
+ queueMicrotask(() => {
534
+ __privateSet(this, _rebuildQueued, false);
535
+ if (!__privateGet(this, _binding) || !this.isConnected) {
536
+ return;
537
+ }
538
+ const hadFocus = this.contains(this.ownerDocument.activeElement);
539
+ __privateMethod(this, _MikeDownElement_instances, destroy_fn).call(this);
540
+ __privateMethod(this, _MikeDownElement_instances, create_fn).call(this);
541
+ if (hadFocus) {
542
+ __privateGet(this, _binding)?.focus();
543
+ }
544
+ });
545
+ };
546
+ setValue_fn = function(markdown) {
547
+ __privateSet(this, _value, markdown);
548
+ __privateGet(this, _binding)?.setValue(markdown);
549
+ __privateMethod(this, _MikeDownElement_instances, syncForm_fn).call(this);
550
+ };
551
+ accessibleName_fn = function() {
552
+ const labelledBy = this.getAttribute("aria-labelledby");
553
+ if (labelledBy) {
554
+ return { ariaLabelledBy: labelledBy };
555
+ }
556
+ const label = this.getAttribute("aria-label");
557
+ if (label) {
558
+ return { ariaLabel: label };
559
+ }
560
+ const labels = Array.from(__privateGet(this, _internals)?.labels ?? []);
561
+ if (!labels.length) {
562
+ return {};
563
+ }
564
+ const ids = labels.map((el, i) => {
565
+ if (!el.id) {
566
+ el.id = `${this.id || "mikedown-editor"}-label${labels.length > 1 ? `-${i + 1}` : ""}`;
567
+ }
568
+ return el.id;
569
+ });
570
+ return { ariaLabelledBy: ids.join(" ") };
571
+ };
572
+ isDisabled_fn = function() {
573
+ return this.hasAttribute("disabled") || __privateGet(this, _formDisabled);
574
+ };
575
+ applyDisabled_fn = function() {
576
+ __privateGet(this, _binding)?.setDisabled(__privateMethod(this, _MikeDownElement_instances, isDisabled_fn).call(this));
577
+ if (__privateGet(this, _fallbackInput)) {
578
+ __privateGet(this, _fallbackInput).disabled = __privateMethod(this, _MikeDownElement_instances, isDisabled_fn).call(this);
579
+ }
580
+ __privateMethod(this, _MikeDownElement_instances, syncValidity_fn).call(this);
581
+ };
582
+ applyMinHeight_fn = function() {
583
+ const value = this.getAttribute("min-height");
584
+ if (value) {
585
+ this.style.setProperty("--mikedown-min-height", /^\d+(\.\d+)?$/.test(value) ? `${value}px` : value);
586
+ } else {
587
+ this.style.removeProperty("--mikedown-min-height");
588
+ }
589
+ };
590
+ setOrRemove_fn = function(attr, value) {
591
+ if (value == null || value === "") {
592
+ this.removeAttribute(attr);
593
+ } else {
594
+ this.setAttribute(attr, String(value));
595
+ }
596
+ };
597
+ hasFormInternals_fn = function() {
598
+ return !!__privateGet(this, _internals) && typeof __privateGet(this, _internals).setFormValue === "function";
599
+ };
600
+ valueMissing_fn = function() {
601
+ return this.required && !__privateMethod(this, _MikeDownElement_instances, isDisabled_fn).call(this) && __privateGet(this, _value).trim() === "";
602
+ };
603
+ syncForm_fn = function() {
604
+ if (__privateMethod(this, _MikeDownElement_instances, hasFormInternals_fn).call(this)) {
605
+ __privateGet(this, _internals).setFormValue(__privateGet(this, _value), __privateGet(this, _value));
606
+ } else if (__privateGet(this, _fallbackInput)) {
607
+ __privateGet(this, _fallbackInput).value = __privateGet(this, _value);
608
+ }
609
+ __privateMethod(this, _MikeDownElement_instances, syncValidity_fn).call(this);
610
+ };
611
+ syncValidity_fn = function() {
612
+ if (!__privateMethod(this, _MikeDownElement_instances, hasFormInternals_fn).call(this) || typeof __privateGet(this, _internals).setValidity !== "function") {
613
+ return;
614
+ }
615
+ if (__privateMethod(this, _MikeDownElement_instances, valueMissing_fn).call(this)) {
616
+ const anchor = this.querySelector(".ProseMirror") ?? void 0;
617
+ __privateGet(this, _internals).setValidity({ valueMissing: true }, VALUE_MISSING_MESSAGE, anchor);
618
+ } else {
619
+ __privateGet(this, _internals).setValidity({});
620
+ }
621
+ };
622
+ /**
623
+ * Without ElementInternals form support (jsdom, very old browsers) a hidden
624
+ * <input> carries the value, and the form's reset event resets it.
625
+ */
626
+ attachFallbackForm_fn = function() {
627
+ if (__privateMethod(this, _MikeDownElement_instances, hasFormInternals_fn).call(this)) {
628
+ return;
629
+ }
630
+ if (!__privateGet(this, _fallbackInput)) {
631
+ const input = this.ownerDocument.createElement("input");
632
+ input.type = "hidden";
633
+ input.setAttribute("data-mikedown-form-value", "");
634
+ __privateSet(this, _fallbackInput, input);
635
+ }
636
+ __privateGet(this, _fallbackInput).name = this.name;
637
+ __privateGet(this, _fallbackInput).disabled = __privateMethod(this, _MikeDownElement_instances, isDisabled_fn).call(this);
638
+ __privateGet(this, _fallbackInput).value = __privateGet(this, _value);
639
+ if (__privateGet(this, _fallbackInput).parentNode !== this) {
640
+ this.appendChild(__privateGet(this, _fallbackInput));
641
+ }
642
+ const form = this.closest("form");
643
+ if (form !== __privateGet(this, _fallbackForm)) {
644
+ __privateGet(this, _fallbackForm)?.removeEventListener("reset", __privateGet(this, _onFallbackReset));
645
+ form?.addEventListener("reset", __privateGet(this, _onFallbackReset));
646
+ __privateSet(this, _fallbackForm, form);
647
+ }
648
+ };
649
+ detachFallbackForm_fn = function() {
650
+ __privateGet(this, _fallbackForm)?.removeEventListener("reset", __privateGet(this, _onFallbackReset));
651
+ __privateSet(this, _fallbackForm, null);
652
+ };
653
+ _onFallbackReset = new WeakMap();
654
+ MikeDownElement.formAssociated = true;
655
+
656
+ // src/index.ts
657
+ var DEFAULT_TAG = "mikedown-editor";
658
+ function defineMikeDownElement(tag = DEFAULT_TAG) {
659
+ if (typeof customElements === "undefined") {
660
+ return MikeDownElement;
661
+ }
662
+ const existing = customElements.get(tag);
663
+ if (existing) {
664
+ return existing;
665
+ }
666
+ const registry = customElements;
667
+ const baseTaken = baseDefined || !!registry.getName?.(MikeDownElement);
668
+ const ctor = baseTaken ? class extends MikeDownElement {
669
+ } : MikeDownElement;
670
+ customElements.define(tag, ctor);
671
+ if (ctor === MikeDownElement) {
672
+ baseDefined = true;
673
+ }
674
+ return ctor;
675
+ }
676
+ var baseDefined = false;
677
+
678
+ export {
679
+ dedentScriptText,
680
+ MikeDownElement,
681
+ DEFAULT_TAG,
682
+ defineMikeDownElement
683
+ };
684
+ //# sourceMappingURL=chunk-WZVZGW65.js.map