@gjermundgaraba/pixel-paper 0.2.0 → 0.2.1

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.
@@ -111,15 +111,15 @@ export declare const update: (model: Model, message: Message, context?: UpdateCo
111
111
  } | {
112
112
  readonly _tag: "GotAnimationMessage";
113
113
  readonly message: {
114
- readonly _tag: "Hid";
115
- } | {
116
- readonly _tag: "Showed";
117
- } | {
118
114
  readonly _tag: "CompletedWaitForPaint";
119
115
  readonly generation: number;
120
116
  } | {
121
117
  readonly _tag: "EndedAnimation";
122
118
  readonly generation: number;
119
+ } | {
120
+ readonly _tag: "Hid";
121
+ } | {
122
+ readonly _tag: "Showed";
123
123
  };
124
124
  } | {
125
125
  readonly _tag: "RequestedClose";
@@ -230,15 +230,15 @@ export declare const view: import("foldkit/submodel").View<{
230
230
  } | {
231
231
  readonly _tag: "GotAnimationMessage";
232
232
  readonly message: {
233
- readonly _tag: "Hid";
234
- } | {
235
- readonly _tag: "Showed";
236
- } | {
237
233
  readonly _tag: "CompletedWaitForPaint";
238
234
  readonly generation: number;
239
235
  } | {
240
236
  readonly _tag: "EndedAnimation";
241
237
  readonly generation: number;
238
+ } | {
239
+ readonly _tag: "Hid";
240
+ } | {
241
+ readonly _tag: "Showed";
242
242
  };
243
243
  } | {
244
244
  readonly _tag: "RequestedClose";
@@ -38,11 +38,11 @@ export declare const update: (model: Model, message: Message) => Readonly<{
38
38
  model: {
39
39
  readonly id: string;
40
40
  readonly state: {
41
+ readonly _tag: "Idle";
42
+ } | {
41
43
  readonly _tag: "Copied";
42
44
  } | {
43
45
  readonly _tag: "Copying";
44
- } | {
45
- readonly _tag: "Idle";
46
46
  };
47
47
  };
48
48
  commands?: Update.Commands<{
@@ -74,11 +74,11 @@ export type ViewInputs = Readonly<{
74
74
  export declare const view: import("foldkit/submodel").View<{
75
75
  readonly id: string;
76
76
  readonly state: {
77
+ readonly _tag: "Idle";
78
+ } | {
77
79
  readonly _tag: "Copied";
78
80
  } | {
79
81
  readonly _tag: "Copying";
80
- } | {
81
- readonly _tag: "Idle";
82
82
  };
83
83
  }, {
84
84
  readonly _tag: "FailedCopyText";
@@ -108,15 +108,15 @@ export declare const update: (model: Model, message: Message, context?: UpdateCo
108
108
  } | {
109
109
  readonly _tag: "GotAnimationMessage";
110
110
  readonly message: {
111
- readonly _tag: "Hid";
112
- } | {
113
- readonly _tag: "Showed";
114
- } | {
115
111
  readonly _tag: "CompletedWaitForPaint";
116
112
  readonly generation: number;
117
113
  } | {
118
114
  readonly _tag: "EndedAnimation";
119
115
  readonly generation: number;
116
+ } | {
117
+ readonly _tag: "Hid";
118
+ } | {
119
+ readonly _tag: "Showed";
120
120
  };
121
121
  } | {
122
122
  readonly _tag: "RequestedClose";
@@ -235,15 +235,15 @@ export declare const view: import("foldkit/submodel").View<{
235
235
  } | {
236
236
  readonly _tag: "GotAnimationMessage";
237
237
  readonly message: {
238
- readonly _tag: "Hid";
239
- } | {
240
- readonly _tag: "Showed";
241
- } | {
242
238
  readonly _tag: "CompletedWaitForPaint";
243
239
  readonly generation: number;
244
240
  } | {
245
241
  readonly _tag: "EndedAnimation";
246
242
  readonly generation: number;
243
+ } | {
244
+ readonly _tag: "Hid";
245
+ } | {
246
+ readonly _tag: "Showed";
247
247
  };
248
248
  } | {
249
249
  readonly _tag: "RequestedClose";
@@ -120,15 +120,15 @@ export declare const update: (model: Model, message: Message) => Readonly<{
120
120
  } | {
121
121
  readonly _tag: "GotAnimationMessage";
122
122
  readonly message: {
123
- readonly _tag: "Hid";
124
- } | {
125
- readonly _tag: "Showed";
126
- } | {
127
123
  readonly _tag: "CompletedWaitForPaint";
128
124
  readonly generation: number;
129
125
  } | {
130
126
  readonly _tag: "EndedAnimation";
131
127
  readonly generation: number;
128
+ } | {
129
+ readonly _tag: "Hid";
130
+ } | {
131
+ readonly _tag: "Showed";
132
132
  };
133
133
  } | {
134
134
  readonly _tag: "RequestedClose";
@@ -211,15 +211,15 @@ export declare const view: import("foldkit/submodel").View<{
211
211
  } | {
212
212
  readonly _tag: "GotAnimationMessage";
213
213
  readonly message: {
214
- readonly _tag: "Hid";
215
- } | {
216
- readonly _tag: "Showed";
217
- } | {
218
214
  readonly _tag: "CompletedWaitForPaint";
219
215
  readonly generation: number;
220
216
  } | {
221
217
  readonly _tag: "EndedAnimation";
222
218
  readonly generation: number;
219
+ } | {
220
+ readonly _tag: "Hid";
221
+ } | {
222
+ readonly _tag: "Showed";
223
223
  };
224
224
  } | {
225
225
  readonly _tag: "RequestedClose";
@@ -3,11 +3,7 @@ import { spec } from "./markdown-editor.js";
3
3
  import { afterEmission, afterSource } from "./reconcile.js";
4
4
  import { createEngine } from "./engine.js";
5
5
  // src/markdown-editor/element.ts
6
- const MIRRORED_ATTRIBUTES = [
7
- "aria-describedby",
8
- "aria-invalid",
9
- "aria-required"
10
- ];
6
+ const MIRRORED_ATTRIBUTES = ["aria-describedby", "aria-invalid"];
11
7
  const MOTION_END_EVENTS = ["animationend", "transitionend"];
12
8
  const mirroredAttributes = (textarea) => __foldkitBrandViewResult((Object.fromEntries(MIRRORED_ATTRIBUTES.flatMap((name) => {
13
9
  const value = textarea.getAttribute(name);
@@ -19,6 +15,14 @@ const namedBy = (textarea) => {
19
15
  if (label.id === "") label.id = `${textarea.id}-label`;
20
16
  return __foldkitBrandViewResult(({ "aria-labelledby": label.id }), "@gjermundgaraba/pixel-paper/markdown-editor/element.js#namedBy");
21
17
  };
18
+ const createEngineOrReport = (config) => {
19
+ try {
20
+ return __foldkitBrandViewResult((createEngine(config)), "@gjermundgaraba/pixel-paper/markdown-editor/element.js#createEngineOrReport");
21
+ } catch (error) {
22
+ reportError(error);
23
+ return;
24
+ }
25
+ };
22
26
  var MarkdownEditorElement = class extends HTMLElement {
23
27
  static formAssociated = true;
24
28
  #source = "";
@@ -58,7 +62,7 @@ var MarkdownEditorElement = class extends HTMLElement {
58
62
  ...namedBy(textarea),
59
63
  ...mirroredAttributes(textarea)
60
64
  }), "@gjermundgaraba/pixel-paper/markdown-editor/element.js#accessAttributes"));
61
- const engine = createEngine({
65
+ const engine = createEngineOrReport({
62
66
  parent: surface,
63
67
  doc: this.#source,
64
68
  attributes: accessAttributes(),
@@ -68,6 +72,10 @@ var MarkdownEditorElement = class extends HTMLElement {
68
72
  this.dispatchEvent(new CustomEvent("value-change", { detail: { value: doc } }));
69
73
  }
70
74
  });
75
+ if (engine === void 0) {
76
+ surface.remove();
77
+ return;
78
+ }
71
79
  const syncAccess = () => {
72
80
  engine.configureAccess(accessAttributes(), this.#isDisabled);
73
81
  };
@@ -10,6 +10,7 @@ import { EditorView, keymap } from "@codemirror/view";
10
10
  import { GFM, MarkdownParser } from "@lezer/markdown";
11
11
  // src/markdown-editor/engine.ts
12
12
  const DIFF_TIMEOUT_MS = 50;
13
+ const historyCompartment = new Compartment();
13
14
  const language = new Language(commonmarkLanguage.data, commonmarkLanguage.parser instanceof MarkdownParser ? commonmarkLanguage.parser.configure(GFM) : commonmarkLanguage.parser, [], "markdown");
14
15
  /** Who is named by what, and whether the document may change. `readOnly` alone lets Enter and
15
16
  * the Markdown keymap edit, so the filter refuses every change but an outside one. */
@@ -21,16 +22,18 @@ const accessExtension = (attributes, isReadOnly) => __foldkitBrandViewResult(([
21
22
  ...isReadOnly ? { "aria-disabled": "true" } : {}
22
23
  })
23
24
  ]), "@gjermundgaraba/pixel-paper/markdown-editor/engine.js#accessExtension");
24
- /** The editor's state. No line separator is set, so CRLF text parses like LF text. Tab stays
25
- * unbound, so it leaves the field. */
25
+ /** The editor's state. No line separator is set, so CRLF text parses like LF text, and the
26
+ * first edit hands it back with LF line endings. Tab stays unbound and nothing inside the
27
+ * field takes focus, so Tab leaves the field. Mod-Enter only opens a link at the caret, so
28
+ * elsewhere it does nothing, as in a textarea. */
26
29
  const editorState = (doc, extensions = []) => __foldkitBrandViewResult((EditorState.create({
27
30
  doc,
28
31
  extensions: [
29
- history(),
32
+ historyCompartment.of(history()),
30
33
  language,
31
34
  liveMarkdown(),
32
35
  Prec.high(keymap.of(markdownKeymap)),
33
- keymap.of([...defaultKeymap, ...historyKeymap]),
36
+ keymap.of([...defaultKeymap.filter(({ key }) => __foldkitBrandViewResult((key !== "Mod-Enter"), "@gjermundgaraba/pixel-paper/markdown-editor/engine.js#anonymous~2")), ...historyKeymap]),
34
37
  EditorView.lineWrapping,
35
38
  EditorView.contentAttributes.of({
36
39
  spellcheck: "true",
@@ -41,20 +44,23 @@ const editorState = (doc, extensions = []) => __foldkitBrandViewResult((EditorSt
41
44
  ]
42
45
  })), "@gjermundgaraba/pixel-paper/markdown-editor/engine.js#editorState");
43
46
  /** The whole document to send up after these transactions, if one of them was a local edit. */
44
- const emission = (transactions, state) => __foldkitBrandViewResult((transactions.some((transaction) => __foldkitBrandViewResult((transaction.docChanged && transaction.annotation(Transaction.remote) !== true), "@gjermundgaraba/pixel-paper/markdown-editor/engine.js#anonymous~2")) ? state.doc.toString() : void 0), "@gjermundgaraba/pixel-paper/markdown-editor/engine.js#emission");
45
- /** A minimal edit from the document to an outside value: the caret survives it, and undo keeps
46
- * to what was typed. */
47
- const externalChange = (state, source) => {
48
- const current = state.doc.toString();
47
+ const emission = (transactions, state) => __foldkitBrandViewResult((transactions.some((transaction) => __foldkitBrandViewResult((transaction.docChanged && transaction.annotation(Transaction.remote) !== true), "@gjermundgaraba/pixel-paper/markdown-editor/engine.js#anonymous~3")) ? state.doc.toString() : void 0), "@gjermundgaraba/pixel-paper/markdown-editor/engine.js#emission");
48
+ /** Puts an outside value in as a minimal edit, so the caret stays on the same text, and ends
49
+ * the undo history. Typed edits left in it would map onto letters of the outside text, and
50
+ * undo would delete those. Dropping the history field and adding it back starts it empty. */
51
+ const applyExternal = (target, source) => {
52
+ const current = target.state.doc.toString();
49
53
  const next = withLfLineEndings(source);
50
- return __foldkitBrandViewResult(({
54
+ target.dispatch(target.state.update({
51
55
  changes: diff(current, next, { timeout: DIFF_TIMEOUT_MS }).map(({ fromA, toA, fromB, toB }) => (__foldkitBrandViewResult(({
52
56
  from: fromA,
53
57
  to: toA,
54
58
  insert: next.slice(fromB, toB)
55
- }), "@gjermundgaraba/pixel-paper/markdown-editor/engine.js#anonymous~3"))),
56
- annotations: [Transaction.remote.of(true), Transaction.addToHistory.of(false)]
57
- }), "@gjermundgaraba/pixel-paper/markdown-editor/engine.js#externalChange");
59
+ }), "@gjermundgaraba/pixel-paper/markdown-editor/engine.js#anonymous~4"))),
60
+ annotations: Transaction.remote.of(true),
61
+ effects: historyCompartment.reconfigure([])
62
+ }));
63
+ target.dispatch(target.state.update({ effects: historyCompartment.reconfigure(history()) }));
58
64
  };
59
65
  /** Mounts CodeMirror in `parent`, and returns what the element drives it with. */
60
66
  const createEngine = (config) => {
@@ -75,7 +81,7 @@ const createEngine = (config) => {
75
81
  view.requestMeasure();
76
82
  },
77
83
  applyExternal: (source) => {
78
- view.dispatch(externalChange(view.state, source));
84
+ applyExternal(view, source);
79
85
  },
80
86
  configureAccess: (attributes, isReadOnly) => {
81
87
  view.dispatch({ effects: access.reconfigure(accessExtension(attributes, isReadOnly)) });
@@ -85,4 +91,4 @@ const createEngine = (config) => {
85
91
  }
86
92
  }), "@gjermundgaraba/pixel-paper/markdown-editor/engine.js#createEngine");
87
93
  };
88
- export { accessExtension, createEngine, editorState, emission, externalChange };
94
+ export { accessExtension, applyExternal, createEngine, editorState, emission };
@@ -34,12 +34,6 @@ const spanOf = (className, text) => {
34
34
  span.textContent = text;
35
35
  return __foldkitBrandViewResult((span), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#spanOf");
36
36
  };
37
- const typographyWidget = (text, isDivider) => __foldkitBrandViewResult((new DrawnWidget({
38
- key: `typography:${isDivider}:${text}`,
39
- draw: () => __foldkitBrandViewResult((spanOf(isDivider ? "lmd-labeled-rule" : "", text)), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#draw"),
40
- estimatedHeight: UNKNOWN_HEIGHT,
41
- takesOwnEvents: false
42
- })), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#typographyWidget");
43
37
  const checkboxWidget = (isChecked) => __foldkitBrandViewResult((new DrawnWidget({
44
38
  key: `checkbox:${isChecked}`,
45
39
  draw: () => {
@@ -47,17 +41,18 @@ const checkboxWidget = (isChecked) => __foldkitBrandViewResult((new DrawnWidget(
47
41
  box.type = "checkbox";
48
42
  box.checked = isChecked;
49
43
  box.className = "lmd-check";
50
- return __foldkitBrandViewResult((box), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#draw~2");
44
+ box.tabIndex = -1;
45
+ return __foldkitBrandViewResult((box), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#draw");
51
46
  },
52
47
  estimatedHeight: UNKNOWN_HEIGHT,
53
48
  takesOwnEvents: false
54
49
  })), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#checkboxWidget");
55
- const listMarkWidget = (text) => __foldkitBrandViewResult((new DrawnWidget({
56
- key: `list-mark:${text}`,
57
- draw: () => __foldkitBrandViewResult((spanOf("lmd-bullet", text)), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#draw~3"),
50
+ const bulletWidget = new DrawnWidget({
51
+ key: "bullet",
52
+ draw: () => __foldkitBrandViewResult((spanOf("lmd-bullet", "•")), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#draw~2"),
58
53
  estimatedHeight: UNKNOWN_HEIGHT,
59
54
  takesOwnEvents: true
60
- })), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#listMarkWidget");
55
+ });
61
56
  const imageWidget = (source, alt) => __foldkitBrandViewResult((new DrawnWidget({
62
57
  key: `image:${source}\n${alt}`,
63
58
  draw: () => {
@@ -65,48 +60,23 @@ const imageWidget = (source, alt) => __foldkitBrandViewResult((new DrawnWidget({
65
60
  const safeSource = safeImageSource(source, document.baseURI);
66
61
  if (safeSource === void 0) {
67
62
  box.append(spanOf("lmd-img-note", alt === "" ? "Image not shown" : alt));
68
- return __foldkitBrandViewResult((box), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#draw~4");
63
+ return __foldkitBrandViewResult((box), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#draw~3");
69
64
  }
70
65
  const image = document.createElement("img");
71
66
  image.className = "lmd-img";
72
67
  image.alt = alt;
68
+ image.referrerPolicy = "no-referrer";
73
69
  image.addEventListener("error", () => {
74
70
  image.replaceWith(spanOf("lmd-img-note", alt === "" ? "Image not found" : `Image not found: ${alt}`));
75
71
  }, { once: true });
76
72
  image.src = safeSource;
77
73
  box.append(image);
78
- return __foldkitBrandViewResult((box), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#draw~4");
74
+ return __foldkitBrandViewResult((box), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#draw~3");
79
75
  },
80
76
  estimatedHeight: IMAGE_ESTIMATED_HEIGHT,
81
77
  takesOwnEvents: false
82
78
  })), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#imageWidget");
83
79
  const isList = (node) => __foldkitBrandViewResult((node?.name === "BulletList" || node?.name === "OrderedList"), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#isList");
84
- const listDepth = (item) => {
85
- let depth = 0;
86
- for (let node = item.parent; node !== null; node = node.parent) if (isList(node)) depth += 1;
87
- return __foldkitBrandViewResult((depth), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#listDepth");
88
- };
89
- const firstMarkOf = (state, item) => {
90
- const mark = item.parent?.firstChild?.getChild("ListMark");
91
- return __foldkitBrandViewResult((mark === void 0 || mark === null ? void 0 : state.sliceDoc(mark.from, mark.to)), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#firstMarkOf");
92
- };
93
- const itemNumber = (state, item) => {
94
- const start = Number(/^\d+/u.exec(firstMarkOf(state, item) ?? "")?.[0] ?? 1);
95
- let index = 0;
96
- for (let node = item.prevSibling; node !== null; node = node.prevSibling) if (node.name === "ListItem") index += 1;
97
- return __foldkitBrandViewResult((start + index), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#itemNumber");
98
- };
99
- const listDelimiter = (state, item) => __foldkitBrandViewResult((/[.)]$/u.exec(firstMarkOf(state, item) ?? "")?.[0] ?? "."), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#listDelimiter");
100
- const outlineNumber = (state, item) => {
101
- const parts = [];
102
- for (let node = item; node !== null; node = node.parent) if (node.name === "ListItem" && node.parent?.name === "OrderedList") parts.unshift(itemNumber(state, node));
103
- return __foldkitBrandViewResult((`${parts.join(".")}${listDelimiter(state, item)}`), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#outlineNumber");
104
- };
105
- const listMarker = (state, item) => {
106
- const list = item.parent;
107
- if (list?.name === "BulletList") return __foldkitBrandViewResult((Array.from({ length: listDepth(item) }, () => __foldkitBrandViewResult(("•"), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#anonymous~2")).join(" ")), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#listMarker");
108
- return __foldkitBrandViewResult((list?.name === "OrderedList" ? outlineNumber(state, item) : ""), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#listMarker");
109
- };
110
80
  const hide = Decoration.replace({});
111
81
  const mark = (className) => __foldkitBrandViewResult((Decoration.mark({ class: className })), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#mark");
112
82
  const line = (className) => __foldkitBrandViewResult((Decoration.line({ class: className })), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#line");
@@ -123,32 +93,20 @@ const HIDDEN_MARKS = /* @__PURE__ */ new Set([
123
93
  "LinkMark",
124
94
  "URL"
125
95
  ]);
126
- const LABELED_RULE = /^ {0,3}---[ \t]+(?<title>\S(?:[^\n]*?\S)?)[ \t]+---[ \t]*$/gmu;
127
96
  const ATX_HEADING = /^ATXHeading(?<level>\d)$/u;
128
- const STANDALONE_DASHES = /(?<![\S\\])--(?!\S)/gu;
129
- const NOT_PLAIN_TEXT = /Code|Link|URL|Image|HTML|HorizontalRule|Table|Escape/u;
130
- const isLinkLike = (node) => __foldkitBrandViewResult((node?.name === "Link" || node?.name === "Image"), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#isLinkLike");
131
- const normalizedLabel = (label) => __foldkitBrandViewResult((label.trim().replaceAll(/\s+/gu, " ").toLowerCase()), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#normalizedLabel");
132
- const linkDefinitions = (state) => {
133
- const labels = /* @__PURE__ */ new Set();
134
- for (let node = syntaxTree(state).topNode.firstChild; node !== null; node = node.nextSibling) {
135
- const label = node.name === "LinkReference" ? node.getChild("LinkLabel") : null;
136
- if (label !== null) labels.add(normalizedLabel(state.sliceDoc(label.from + 1, label.to - 1)));
137
- }
138
- return __foldkitBrandViewResult((labels), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#linkDefinitions");
139
- };
140
- const bracketedText = (state, node) => {
141
- const label = node.getChild("LinkLabel");
142
- const text = label === null ? "" : state.sliceDoc(label.from + 1, label.to - 1);
143
- const [opening, closing] = node.getChildren("LinkMark");
144
- return __foldkitBrandViewResult((normalizedLabel(text) === "" && opening !== void 0 && closing !== void 0 ? state.sliceDoc(opening.to, closing.from) : text), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#bracketedText");
145
- };
146
- const isPlainBrackets = (state, node, definitions = linkDefinitions(state)) => __foldkitBrandViewResult((isLinkLike(node) && node.getChild("URL") === null && !definitions.has(normalizedLabel(bracketedText(state, node)))), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#isPlainBrackets");
147
- const build = (view) => {
148
- const { state } = view;
97
+ const ANGLE_BRACKETED = /^<(?<destination>.*)>$/su;
98
+ const EMAIL = /^[^\s:@]+@[^\s:@]+$/u;
99
+ const URL_OWNERS = /* @__PURE__ */ new Set([
100
+ "Link",
101
+ "Image",
102
+ "LinkReference"
103
+ ]);
104
+ const isPlainBrackets = (node) => __foldkitBrandViewResult(((node.name === "Link" || node.name === "Image") && node.getChild("URL") === null), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#isPlainBrackets");
105
+ const isBareUrl = (node) => __foldkitBrandViewResult((node.name === "URL" && !URL_OWNERS.has(node.parent?.name ?? "")), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#isBareUrl");
106
+ /** The live layer's decorations over the visible ranges, as a ViewPlugin may provide them. */
107
+ const liveDecorations = (state, visibleRanges, isFocused) => {
149
108
  const { ranges } = state.selection;
150
- const isFocused = view.hasFocus;
151
- const touched = (from, to) => __foldkitBrandViewResult((isFocused && ranges.some((range) => __foldkitBrandViewResult((range.from <= to && range.to >= from), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#anonymous~3"))), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#touched");
109
+ const touched = (from, to) => __foldkitBrandViewResult((isFocused && ranges.some((range) => __foldkitBrandViewResult((range.from <= to && range.to >= from), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#anonymous~2"))), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#touched");
152
110
  const activeLine = (position) => {
153
111
  const { from, to } = state.doc.lineAt(position);
154
112
  return __foldkitBrandViewResult((touched(from, to)), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#activeLine");
@@ -186,137 +144,108 @@ const build = (view) => {
186
144
  }
187
145
  };
188
146
  const hideWithFollowingSpace = (from, to) => {
189
- add(from, Math.min(to + 1, state.doc.lineAt(from).to), hide);
147
+ add(from, state.sliceDoc(to, to + 1) === " " ? to + 1 : to, hide);
190
148
  };
191
- const labeledRanges = [];
192
- const definitions = linkDefinitions(state);
193
- for (const { from, to } of view.visibleRanges) {
194
- const text = state.sliceDoc(from, to);
195
- syntaxTree(state).iterate({
196
- from,
197
- to,
198
- enter: (node) => {
199
- if (labeledRanges.some(([start, end]) => __foldkitBrandViewResult((node.from >= start && node.to <= end), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#anonymous~4"))) return __foldkitBrandViewResult((false), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
200
- const { name } = node;
201
- const { parent } = node.node;
202
- if (name === "Paragraph" && parent?.name === "Document") {
203
- const paragraph = state.sliceDoc(node.from, node.to);
204
- for (const match of paragraph.matchAll(LABELED_RULE)) {
205
- const start = node.from + match.index;
206
- const end = start + match[0].length;
207
- const title = match.groups?.["title"];
208
- if (title !== void 0 && !activeLine(start)) {
209
- labeledRanges.push([start, end]);
210
- replace(start, end, typographyWidget(title, true));
211
- }
212
- }
213
- }
214
- const level = ATX_HEADING.exec(name)?.groups?.["level"];
215
- if (level !== void 0) {
216
- addLine(state.doc.lineAt(node.from).from, line(`lmd-h lmd-h${level}`));
217
- return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
218
- }
219
- if (name === "HeaderMark" && parent?.name.startsWith("ATXHeading") === true) {
220
- if (!activeLine(node.from)) hideWithFollowingSpace(node.from, node.to);
221
- return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
222
- }
223
- if (isLinkLike(node.node) && isPlainBrackets(state, node.node, definitions)) return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
224
- if (name === "LinkMark" && parent !== null && isPlainBrackets(state, parent, definitions)) return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
225
- if (name === "Escape") {
226
- if (!touched(node.from, node.to)) add(node.from, node.from + 1, hide);
227
- return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
228
- }
229
- if (name === "Image") {
230
- const url = node.node.getChild("URL");
231
- if (url !== null && !touched(node.from, node.to)) {
232
- const alt = state.sliceDoc(node.from + 2, Math.max(node.from + 2, url.from - 2));
233
- replace(node.from, node.to, imageWidget(state.sliceDoc(url.from, url.to), alt));
234
- }
235
- return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
236
- }
237
- const inlineClass = INLINE.get(name);
238
- if (inlineClass !== void 0) {
239
- add(node.from, node.to, mark(inlineClass));
240
- return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
241
- }
242
- if (name === "URL" && !isLinkLike(parent)) {
243
- add(node.from, node.to, mark("lmd-link"));
244
- return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
245
- }
246
- if (parent !== null && (HIDDEN_MARKS.has(name) || name === "CodeMark" && parent.name === "InlineCode")) {
247
- if (!touched(parent.from, parent.to)) add(node.from, node.to, hide);
248
- return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
249
- }
250
- if (name === "FencedCode" || name === "CodeBlock") {
251
- addLines(node.from, node.to, "lmd-codeblock");
252
- return __foldkitBrandViewResult((false), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
253
- }
254
- if (name === "Blockquote") {
255
- addLines(node.from, node.to, "lmd-quote");
256
- return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
257
- }
258
- if (name === "QuoteMark") {
259
- if (!activeLine(node.from)) hideWithFollowingSpace(node.from, node.to);
260
- return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
261
- }
262
- if (name === "HorizontalRule") {
263
- if (!activeLine(node.from)) {
264
- addLine(state.doc.lineAt(node.from).from, line("lmd-hr"));
265
- add(node.from, node.to, hide);
266
- }
267
- return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
268
- }
269
- if (name === "Table") {
270
- addLines(node.from, node.to, "lmd-table");
271
- return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
272
- }
273
- if (name === "ListMark" && parent !== null && isList(parent.parent)) {
274
- if (activeLine(node.from)) return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
275
- if (parent.getChild("Task") === null) replace(node.from, node.to, listMarkWidget(listMarker(state, parent)));
276
- else hideWithFollowingSpace(node.from, node.to);
277
- return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
278
- }
279
- if (name === "TaskMarker" && !touched(node.from, node.to)) {
280
- const isChecked = /x/iu.test(state.sliceDoc(node.from, node.to));
281
- replace(node.from, node.to, checkboxWidget(isChecked));
282
- if (isChecked && parent !== null) add(node.to, parent.to, mark("lmd-done"));
149
+ for (const { from, to } of visibleRanges) syntaxTree(state).iterate({
150
+ from,
151
+ to,
152
+ enter: (node) => {
153
+ const { name } = node;
154
+ const { parent } = node.node;
155
+ const level = ATX_HEADING.exec(name)?.groups?.["level"];
156
+ if (level !== void 0) {
157
+ addLine(state.doc.lineAt(node.from).from, line(`lmd-h lmd-h${level}`));
158
+ return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
159
+ }
160
+ if (name === "HeaderMark" && parent?.name.startsWith("ATXHeading") === true) {
161
+ if (!activeLine(node.from)) hideWithFollowingSpace(node.from, node.to);
162
+ return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
163
+ }
164
+ if (name === "LinkReference") return __foldkitBrandViewResult((false), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
165
+ if (isPlainBrackets(node.node)) return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
166
+ if (name === "LinkMark" && parent !== null && isPlainBrackets(parent)) return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
167
+ if (name === "Escape") {
168
+ if (!touched(node.from, node.to)) add(node.from, node.from + 1, hide);
169
+ return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
170
+ }
171
+ if (name === "Image") {
172
+ const url = node.node.getChild("URL");
173
+ if (url !== null && !touched(node.from, node.to)) {
174
+ const alt = state.sliceDoc(node.from + 2, Math.max(node.from + 2, url.from - 2));
175
+ replace(node.from, node.to, imageWidget(state.sliceDoc(url.from, url.to).replace(ANGLE_BRACKETED, "$<destination>"), alt));
283
176
  }
284
177
  return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
285
178
  }
286
- });
287
- for (const match of text.matchAll(STANDALONE_DASHES)) {
288
- const start = from + match.index;
289
- const end = start + 2;
290
- if (!touched(start, end)) {
291
- let node = syntaxTree(state).resolveInner(start, 1);
292
- let isPlain = true;
293
- while (node !== null && isPlain) {
294
- isPlain = !NOT_PLAIN_TEXT.test(node.name);
295
- node = node.parent;
179
+ const inlineClass = INLINE.get(name);
180
+ if (inlineClass !== void 0) {
181
+ add(node.from, node.to, mark(inlineClass));
182
+ return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
183
+ }
184
+ if (isBareUrl(node.node)) {
185
+ add(node.from, node.to, mark("lmd-link"));
186
+ return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
187
+ }
188
+ if (parent !== null && (HIDDEN_MARKS.has(name) || name === "CodeMark" && parent.name === "InlineCode")) {
189
+ if (!touched(parent.from, parent.to)) add(node.from, node.to, hide);
190
+ return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
191
+ }
192
+ if (name === "FencedCode" || name === "CodeBlock") {
193
+ addLines(node.from, node.to, "lmd-codeblock");
194
+ return __foldkitBrandViewResult((false), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
195
+ }
196
+ if (name === "Blockquote") {
197
+ addLines(node.from, node.to, "lmd-quote");
198
+ return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
199
+ }
200
+ if (name === "QuoteMark") {
201
+ if (!activeLine(node.from)) hideWithFollowingSpace(node.from, node.to);
202
+ return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
203
+ }
204
+ if (name === "HorizontalRule") {
205
+ if (!activeLine(node.from)) {
206
+ addLine(state.doc.lineAt(node.from).from, line("lmd-hr"));
207
+ add(node.from, node.to, hide);
296
208
  }
297
- if (isPlain) replace(start, end, typographyWidget("—", false));
209
+ return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
298
210
  }
211
+ if (name === "Table") {
212
+ addLines(node.from, node.to, "lmd-table");
213
+ return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
214
+ }
215
+ if (name === "ListMark" && parent !== null && isList(parent.parent)) {
216
+ if (activeLine(node.from)) return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
217
+ if (parent.getChild("Task") !== null) hideWithFollowingSpace(node.from, node.to);
218
+ else if (parent.parent?.name === "BulletList") replace(node.from, node.to, bulletWidget);
219
+ return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
220
+ }
221
+ if (name === "TaskMarker" && !touched(node.from, node.to)) {
222
+ const isChecked = /x/iu.test(state.sliceDoc(node.from, node.to));
223
+ replace(node.from, node.to, checkboxWidget(isChecked));
224
+ if (isChecked && parent !== null) add(node.to, parent.to, mark("lmd-done"));
225
+ }
226
+ return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter");
299
227
  }
300
- }
301
- placed.sort((left, right) => __foldkitBrandViewResult((left.from - right.from || left.decoration.startSide - right.decoration.startSide), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#anonymous~5"));
228
+ });
229
+ placed.sort((left, right) => __foldkitBrandViewResult((left.from - right.from || left.decoration.startSide - right.decoration.startSide), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#anonymous~3"));
230
+ const staysOnItsLine = (from, to) => __foldkitBrandViewResult((to <= state.doc.lineAt(from).to), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#staysOnItsLine");
302
231
  const builder = new RangeSetBuilder();
303
232
  let lastReplaceEnd = -1;
304
233
  for (const { from, to, decoration, isReplace } of placed) {
305
234
  const isRangeReplace = from !== to && isReplace;
306
- if (!isRangeReplace || from >= lastReplaceEnd) {
235
+ if (!isRangeReplace || from >= lastReplaceEnd && staysOnItsLine(from, to)) {
307
236
  builder.add(from, to, decoration);
308
237
  if (isRangeReplace) lastReplaceEnd = to;
309
238
  }
310
239
  }
311
- return __foldkitBrandViewResult((builder.finish()), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#build");
240
+ return __foldkitBrandViewResult((builder.finish()), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#liveDecorations");
312
241
  };
313
242
  const DELIMITER_ROW = /^\s*\|?[\s:|-]+\|?\s*$/u;
314
- const tableCells = (row) => __foldkitBrandViewResult((row.trim().replaceAll(/^\||\|$/gu, "").split(/(?<!\\)\|/u).map((cell) => __foldkitBrandViewResult((cell.trim().replaceAll(String.raw`\|`, "|")), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#anonymous~6"))), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#tableCells");
243
+ const tableCells = (row) => __foldkitBrandViewResult((row.trim().replaceAll(/^\||\|$/gu, "").split(/(?<!\\)\|/u).map((cell) => __foldkitBrandViewResult((cell.trim().replaceAll(String.raw`\|`, "|")), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#anonymous~4"))), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#tableCells");
315
244
  const tableOf = (source) => {
316
245
  const table = document.createElement("table");
317
246
  const head = table.createTHead();
318
247
  const body = table.createTBody();
319
- const rows = source.split("\n").filter((row) => __foldkitBrandViewResult((row.trim() !== ""), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#anonymous~7"));
248
+ const rows = source.split("\n").filter((row) => __foldkitBrandViewResult((row.trim() !== ""), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#anonymous~5"));
320
249
  table.className = "lmd-table-view";
321
250
  for (const [index, row] of rows.entries()) if (index !== 1 || !DELIMITER_ROW.test(row)) {
322
251
  const tableRow = document.createElement("tr");
@@ -347,13 +276,13 @@ const tableWidget = (text) => __foldkitBrandViewResult((new DrawnWidget({
347
276
  view.dispatch({ selection: { anchor: Math.min(target.from + 2, target.to) } });
348
277
  view.focus();
349
278
  });
350
- return __foldkitBrandViewResult((dom), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#draw~5");
279
+ return __foldkitBrandViewResult((dom), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#draw~4");
351
280
  },
352
281
  estimatedHeight: TABLE_ROW_HEIGHT * text.split("\n").length,
353
282
  takesOwnEvents: true
354
283
  })), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#tableWidget");
355
284
  const lastValueOf = (transaction, type, held) => {
356
- const last = transaction.effects.findLast((effect) => __foldkitBrandViewResult((effect.is(type)), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#anonymous~9"));
285
+ const last = transaction.effects.findLast((effect) => __foldkitBrandViewResult((effect.is(type)), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#anonymous~7"));
357
286
  return __foldkitBrandViewResult((last === void 0 ? held : last.value), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#lastValueOf");
358
287
  };
359
288
  const setFocus = StateEffect.define();
@@ -384,7 +313,7 @@ const buildTables = (state, isFocused) => {
384
313
  if (node.name !== "Table") return __foldkitBrandViewResult((node.name === "Document" || node.name.endsWith("List") || node.name === "ListItem" || node.name === "Blockquote"), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#enter~2");
385
314
  const { from } = state.doc.lineAt(node.from);
386
315
  const { to } = state.doc.lineAt(node.to);
387
- const isInside = state.selection.ranges.some((range) => __foldkitBrandViewResult((range.from <= to && range.to >= from), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#anonymous~11"));
316
+ const isInside = state.selection.ranges.some((range) => __foldkitBrandViewResult((range.from <= to && range.to >= from), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#anonymous~9"));
388
317
  if (from === node.from && !(isFocused && isInside)) builder.add(from, to, Decoration.replace({
389
318
  widget: tableWidget(state.sliceDoc(from, to)),
390
319
  block: true
@@ -411,15 +340,16 @@ const tablesField = StateField.define({
411
340
  decorations: buildTables(transaction.state, isFocused)
412
341
  }), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#update~2");
413
342
  },
414
- provide: (field) => __foldkitBrandViewResult((EditorView.decorations.from(field, (value) => __foldkitBrandViewResult((value.decorations), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#anonymous~12"))), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#provide")
343
+ provide: (field) => __foldkitBrandViewResult((EditorView.decorations.from(field, (value) => __foldkitBrandViewResult((value.decorations), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#anonymous~10"))), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#provide")
415
344
  });
416
345
  const linkHref = (state, node) => {
417
346
  const url = node.name === "Link" ? node.getChild("URL") : node;
418
347
  if (url === null) return;
419
- const href = state.sliceDoc(url.from, url.to);
420
- return __foldkitBrandViewResult((/^www\./iu.test(href) ? `https://${href}` : href), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#linkHref");
348
+ const href = state.sliceDoc(url.from, url.to).replace(ANGLE_BRACKETED, "$<destination>");
349
+ if (/^www\./iu.test(href)) return __foldkitBrandViewResult((`https://${href}`), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#linkHref");
350
+ return __foldkitBrandViewResult((node.name === "URL" && EMAIL.test(href) ? `mailto:${href}` : href), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#linkHref");
421
351
  };
422
- const isLinkNode = (state, node) => __foldkitBrandViewResult((!isPlainBrackets(state, node) && (node.name === "Link" || node.name === "URL" && !isLinkLike(node.parent))), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#isLinkNode");
352
+ const isLinkNode = (node) => __foldkitBrandViewResult((node.name === "Link" && !isPlainBrackets(node) || isBareUrl(node)), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#isLinkNode");
423
353
  const toggleCheckbox = (view, box) => {
424
354
  const position = view.posAtDOM(box);
425
355
  const text = view.state.sliceDoc(position, position + 3);
@@ -432,7 +362,7 @@ const toggleCheckbox = (view, box) => {
432
362
  return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#toggleCheckbox");
433
363
  };
434
364
  const linkAt = (state, position, side) => {
435
- for (let node = syntaxTree(state).resolveInner(position, side); node !== null; node = node.parent) if (isLinkNode(state, node)) return __foldkitBrandViewResult((linkHref(state, node)), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#linkAt");
365
+ for (let node = syntaxTree(state).resolveInner(position, side); node !== null; node = node.parent) if (isLinkNode(node)) return __foldkitBrandViewResult((linkHref(state, node)), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#linkAt");
436
366
  };
437
367
  const openLink = (url) => {
438
368
  const href = safeHref(url, document.baseURI);
@@ -453,14 +383,14 @@ const liveMarkdown = () => {
453
383
  decorations;
454
384
  isStale = false;
455
385
  constructor(view) {
456
- this.decorations = build(view);
386
+ this.decorations = liveDecorations(view.state, view.visibleRanges, view.hasFocus);
457
387
  }
458
388
  update(update) {
459
389
  if (update.view.composing || update.state.field(pointerDownField) && !update.docChanged) {
460
390
  this.decorations = this.decorations.map(update.changes);
461
391
  this.isStale = true;
462
392
  } else if (this.isStale || update.docChanged || update.selectionSet || update.focusChanged || update.viewportChanged || syntaxTree(update.startState) !== syntaxTree(update.state)) {
463
- this.decorations = build(update.view);
393
+ this.decorations = liveDecorations(update.state, update.view.visibleRanges, update.view.hasFocus);
464
394
  this.isStale = false;
465
395
  }
466
396
  }
@@ -472,7 +402,8 @@ const liveMarkdown = () => {
472
402
  }, 0);
473
403
  } },
474
404
  eventHandlers: { mousedown: (event, view) => {
475
- if (event.target instanceof HTMLInputElement && event.target.classList.contains("lmd-check") && toggleCheckbox(view, event.target)) {
405
+ const box = event.target instanceof HTMLInputElement && event.target.classList.contains("lmd-check") ? event.target : void 0;
406
+ if (box !== void 0 && (event.button !== 0 || toggleCheckbox(view, box))) {
476
407
  event.preventDefault();
477
408
  return __foldkitBrandViewResult((true), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#mousedown");
478
409
  }
@@ -500,8 +431,8 @@ const liveMarkdown = () => {
500
431
  key: "Mod-Enter",
501
432
  run: openLinkAtCaret
502
433
  }])),
503
- EditorView.focusChangeEffect.of((_, isFocusing) => __foldkitBrandViewResult((setFocus.of(isFocusing)), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#anonymous~14")),
434
+ EditorView.focusChangeEffect.of((_, isFocusing) => __foldkitBrandViewResult((setFocus.of(isFocusing)), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#anonymous~12")),
504
435
  liveMarkdownTheme
505
436
  ]), "@gjermundgaraba/pixel-paper/markdown-editor/live/live.js#liveMarkdown");
506
437
  };
507
- export { liveMarkdown };
438
+ export { liveDecorations, liveMarkdown };
@@ -77,21 +77,6 @@ const liveMarkdownTheme = EditorView.baseTheme({
77
77
  paddingLeft: "var(--space-m) !important",
78
78
  color: "var(--muted)"
79
79
  },
80
- ".lmd-labeled-rule": {
81
- display: "inline-flex",
82
- width: "100%",
83
- alignItems: "center",
84
- gap: "var(--space-s)",
85
- color: "var(--muted)",
86
- verticalAlign: "middle"
87
- },
88
- ".lmd-labeled-rule::before, .lmd-labeled-rule::after": {
89
- content: "\"\"",
90
- flex: "1",
91
- minWidth: "var(--space-s)",
92
- height: "var(--hair)",
93
- background: "var(--rule)"
94
- },
95
80
  ".lmd-hr": {
96
81
  height: "0.8em",
97
82
  background: "linear-gradient(var(--rule), var(--rule)) center / 100% var(--hair) no-repeat"
@@ -99,10 +84,10 @@ const liveMarkdownTheme = EditorView.baseTheme({
99
84
  ".lmd-bullet": {
100
85
  color: "var(--muted)",
101
86
  display: "inline-block",
102
- minWidth: "0.7em",
103
- fontVariantNumeric: "tabular-nums"
87
+ minWidth: "0.7em"
104
88
  },
105
89
  ".lmd-check": {
90
+ width: "auto",
106
91
  margin: "0 var(--space-s) 0 0",
107
92
  verticalAlign: "-2px",
108
93
  cursor: "pointer",
@@ -2,10 +2,10 @@ import { ViewConfig as ViewConfig$1 } from "../textarea-field/textarea-field.js"
2
2
  import { Schema } from "effect";
3
3
  import { Html, HtmlBuilder } from "foldkit/html";
4
4
  /** Configuration for rendering a Markdown editor with `view`. */
5
- export type ViewConfig<Message> = Pick<ViewConfig$1<Message>, "id" | "label" | "value" | "onInput" | "help" | "error" | "isRequired" | "rows">;
5
+ export type ViewConfig<Message> = Pick<ViewConfig$1<Message>, "id" | "label" | "value" | "onInput" | "help" | "error" | "rows">;
6
6
  /** A labelled Markdown field, edited in place: its marks show only around the caret, and the
7
- * text it hands back is the Markdown string, untouched where nobody typed. Without
8
- * `defineMarkdownEditorElement` it is a plain `TextareaField`, which is also what tests see.
9
- * With it, the element takes the textarea's place and drives `onInput` itself, because a
10
- * textarea cannot carry a CRLF document. */
7
+ * text it hands back is the Markdown string as typed, except that the first edit turns CRLF
8
+ * line endings into LF. Without `defineMarkdownEditorElement` it is a plain `TextareaField`,
9
+ * which is also what tests see, and so is a field whose editor fails to mount. With it, the
10
+ * element takes the textarea's place and drives `onInput` itself. */
11
11
  export declare const view: <Message>(config: ViewConfig<Message>, h: HtmlBuilder<Message>) => Html;
@@ -11,10 +11,10 @@ const spec = define({
11
11
  events: { "value-change": Schema.Struct({ value: Schema.String }) }
12
12
  });
13
13
  /** A labelled Markdown field, edited in place: its marks show only around the caret, and the
14
- * text it hands back is the Markdown string, untouched where nobody typed. Without
15
- * `defineMarkdownEditorElement` it is a plain `TextareaField`, which is also what tests see.
16
- * With it, the element takes the textarea's place and drives `onInput` itself, because a
17
- * textarea cannot carry a CRLF document. */
14
+ * text it hands back is the Markdown string as typed, except that the first edit turns CRLF
15
+ * line endings into LF. Without `defineMarkdownEditorElement` it is a plain `TextareaField`,
16
+ * which is also what tests see, and so is a field whose editor fails to mount. With it, the
17
+ * element takes the textarea's place and drives `onInput` itself. */
18
18
  const view = (config, h) => {
19
19
  const host = spec.withMessage(h);
20
20
  return __foldkitBrandViewResult((host([host.Source(config.value), host.OnValueChange(({ value }) => __foldkitBrandViewResult((config.onInput(value)), "@gjermundgaraba/pixel-paper/markdown-editor/markdown-editor.js#anonymous"))], [view$1(config, h)])), "@gjermundgaraba/pixel-paper/markdown-editor/markdown-editor.js#view");
@@ -69,16 +69,16 @@ export declare const update: (model: Model, message: Message) => Readonly<{
69
69
  };
70
70
  commands?: Update.Commands<{
71
71
  readonly _tag: "CompletedFocus";
72
- } | {
73
- readonly _tag: "CompletedFocusEdge";
74
72
  } | {
75
73
  readonly _tag: "ClickedToggle";
74
+ } | {
75
+ readonly _tag: "PressedEscape";
76
+ } | {
77
+ readonly _tag: "CompletedFocusEdge";
76
78
  } | {
77
79
  readonly _tag: "CompletedPlaceSlip";
78
80
  } | {
79
81
  readonly _tag: "LeftSlip";
80
- } | {
81
- readonly _tag: "PressedEscape";
82
82
  } | {
83
83
  readonly _tag: "PressedTab";
84
84
  } | {
@@ -114,11 +114,11 @@ export declare const BindSlip: Mount.MountDefinitionWithArgs<"BindSlip", {
114
114
  isEnd: Schema.Boolean;
115
115
  edge: Schema.Literals<readonly ["First", "Last"]>;
116
116
  }, {
117
+ readonly _tag: "PressedEscape";
118
+ } | {
117
119
  readonly _tag: "CompletedPlaceSlip";
118
120
  } | {
119
121
  readonly _tag: "LeftSlip";
120
- } | {
121
- readonly _tag: "PressedEscape";
122
122
  } | {
123
123
  readonly _tag: "PressedTab";
124
124
  }>;
@@ -164,16 +164,16 @@ export declare const view: import("foldkit/submodel").View<{
164
164
  readonly edge: "First" | "Last";
165
165
  }, {
166
166
  readonly _tag: "CompletedFocus";
167
- } | {
168
- readonly _tag: "CompletedFocusEdge";
169
167
  } | {
170
168
  readonly _tag: "ClickedToggle";
169
+ } | {
170
+ readonly _tag: "PressedEscape";
171
+ } | {
172
+ readonly _tag: "CompletedFocusEdge";
171
173
  } | {
172
174
  readonly _tag: "CompletedPlaceSlip";
173
175
  } | {
174
176
  readonly _tag: "LeftSlip";
175
- } | {
176
- readonly _tag: "PressedEscape";
177
177
  } | {
178
178
  readonly _tag: "PressedTab";
179
179
  } | {
@@ -119,10 +119,6 @@ export declare const update: (model: Model, message: Message) => Readonly<{
119
119
  }>;
120
120
  };
121
121
  commands?: Update.Commands<{
122
- readonly _tag: "ClickedToggle";
123
- } | {
124
- readonly _tag: "PressedEscape";
125
- } | {
126
122
  readonly _tag: "CompletedShowRailDrawer";
127
123
  } | {
128
124
  readonly _tag: "CompletedHideRailDrawer";
@@ -136,11 +132,15 @@ export declare const update: (model: Model, message: Message) => Readonly<{
136
132
  readonly _tag: "ClickedClose";
137
133
  } | {
138
134
  readonly _tag: "ClickedOpen";
135
+ } | {
136
+ readonly _tag: "ClickedToggle";
139
137
  } | {
140
138
  readonly _tag: "ClosedDrawer";
141
139
  } | {
142
140
  readonly _tag: "MovedSplitter";
143
141
  readonly clientX: number;
142
+ } | {
143
+ readonly _tag: "PressedEscape";
144
144
  } | {
145
145
  readonly _tag: "PressedSplitter";
146
146
  readonly pointerId: number;
@@ -187,10 +187,6 @@ export declare const subscriptions: <Prefix extends string>(keyPrefix: Prefix) =
187
187
  readonly width: number;
188
188
  }>;
189
189
  }, {
190
- readonly _tag: "ClickedToggle";
191
- } | {
192
- readonly _tag: "PressedEscape";
193
- } | {
194
190
  readonly _tag: "CompletedShowRailDrawer";
195
191
  } | {
196
192
  readonly _tag: "CompletedHideRailDrawer";
@@ -204,11 +200,15 @@ export declare const subscriptions: <Prefix extends string>(keyPrefix: Prefix) =
204
200
  readonly _tag: "ClickedClose";
205
201
  } | {
206
202
  readonly _tag: "ClickedOpen";
203
+ } | {
204
+ readonly _tag: "ClickedToggle";
207
205
  } | {
208
206
  readonly _tag: "ClosedDrawer";
209
207
  } | {
210
208
  readonly _tag: "MovedSplitter";
211
209
  readonly clientX: number;
210
+ } | {
211
+ readonly _tag: "PressedEscape";
212
212
  } | {
213
213
  readonly _tag: "PressedSplitter";
214
214
  readonly pointerId: number;
@@ -237,10 +237,6 @@ export declare const subscriptions: <Prefix extends string>(keyPrefix: Prefix) =
237
237
  readonly width: number;
238
238
  }>;
239
239
  }, {
240
- readonly _tag: "ClickedToggle";
241
- } | {
242
- readonly _tag: "PressedEscape";
243
- } | {
244
240
  readonly _tag: "CompletedShowRailDrawer";
245
241
  } | {
246
242
  readonly _tag: "CompletedHideRailDrawer";
@@ -254,11 +250,15 @@ export declare const subscriptions: <Prefix extends string>(keyPrefix: Prefix) =
254
250
  readonly _tag: "ClickedClose";
255
251
  } | {
256
252
  readonly _tag: "ClickedOpen";
253
+ } | {
254
+ readonly _tag: "ClickedToggle";
257
255
  } | {
258
256
  readonly _tag: "ClosedDrawer";
259
257
  } | {
260
258
  readonly _tag: "MovedSplitter";
261
259
  readonly clientX: number;
260
+ } | {
261
+ readonly _tag: "PressedEscape";
262
262
  } | {
263
263
  readonly _tag: "PressedSplitter";
264
264
  readonly pointerId: number;
@@ -341,10 +341,6 @@ export declare const view: import("foldkit/submodel").View<{
341
341
  readonly width: number;
342
342
  }>;
343
343
  }, {
344
- readonly _tag: "ClickedToggle";
345
- } | {
346
- readonly _tag: "PressedEscape";
347
- } | {
348
344
  readonly _tag: "CompletedShowRailDrawer";
349
345
  } | {
350
346
  readonly _tag: "CompletedHideRailDrawer";
@@ -358,11 +354,15 @@ export declare const view: import("foldkit/submodel").View<{
358
354
  readonly _tag: "ClickedClose";
359
355
  } | {
360
356
  readonly _tag: "ClickedOpen";
357
+ } | {
358
+ readonly _tag: "ClickedToggle";
361
359
  } | {
362
360
  readonly _tag: "ClosedDrawer";
363
361
  } | {
364
362
  readonly _tag: "MovedSplitter";
365
363
  readonly clientX: number;
364
+ } | {
365
+ readonly _tag: "PressedEscape";
366
366
  } | {
367
367
  readonly _tag: "PressedSplitter";
368
368
  readonly pointerId: number;
@@ -315,15 +315,15 @@ export declare const update: (model: Model, message: Message) => Readonly<{
315
315
  readonly _tag: "GotAnimationMessage";
316
316
  readonly entryId: string;
317
317
  readonly message: {
318
+ readonly _tag: "Hid";
319
+ } | {
320
+ readonly _tag: "Showed";
321
+ } | {
318
322
  readonly _tag: "CompletedWaitForPaint";
319
323
  readonly generation: number;
320
324
  } | {
321
325
  readonly _tag: "EndedAnimation";
322
326
  readonly generation: number;
323
- } | {
324
- readonly _tag: "Hid";
325
- } | {
326
- readonly _tag: "Showed";
327
327
  };
328
328
  } | {
329
329
  readonly _tag: "HoveredEntry";
@@ -509,15 +509,15 @@ export declare const view: import("foldkit/submodel").View<{
509
509
  readonly _tag: "GotAnimationMessage";
510
510
  readonly entryId: string;
511
511
  readonly message: {
512
+ readonly _tag: "Hid";
513
+ } | {
514
+ readonly _tag: "Showed";
515
+ } | {
512
516
  readonly _tag: "CompletedWaitForPaint";
513
517
  readonly generation: number;
514
518
  } | {
515
519
  readonly _tag: "EndedAnimation";
516
520
  readonly generation: number;
517
- } | {
518
- readonly _tag: "Hid";
519
- } | {
520
- readonly _tag: "Showed";
521
521
  };
522
522
  } | {
523
523
  readonly _tag: "HoveredEntry";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjermundgaraba/pixel-paper",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Printed-paper Foldkit components, tokens and stylesheet.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1678,7 +1678,7 @@ pp-markdown-editor {
1678
1678
  position: relative;
1679
1679
  }
1680
1680
 
1681
- pp-markdown-editor:defined textarea {
1681
+ pp-markdown-editor:has(.markdown-surface) textarea {
1682
1682
  position: absolute;
1683
1683
  width: 1px;
1684
1684
  height: 1px;