11// Copyright (c) 2026 David Walker
22// Licensed under the MIT License.
33
4+
45(() => {
56 var __defProp = Object.defineProperty;
67 var __export = (target, all) => {
3162131622 }
3162231623 function splitListItem(itemType, itemAttrs) {
3162331624 return function(state, dispatch) {
31624- let { $from, $to, node: node2 } = state.selection;
31625- if (node2 && node2 .isBlock || $from.depth < 2 || !$from.sameParent($to))
31625+ let { $from, $to, node } = state.selection;
31626+ if (node && node .isBlock || $from.depth < 2 || !$from.sameParent($to))
3162631627 return false;
3162731628 let grandParent = $from.node(-1);
3162831629 if (grandParent.type != itemType)
@@ -31637,71 +31638,31 @@
3163731638 wrap2 = Fragment.from($from.node(d).copy(wrap2));
3163831639 let depthAfter = $from.indexAfter(-1) < $from.node(-2).childCount ? 1 : $from.indexAfter(-2) < $from.node(-3).childCount ? 2 : 3;
3163931640 wrap2 = wrap2.append(Fragment.from(itemType.createAndFill()));
31640- let start = $from.before($from.depth - (depthBefore - 1)), end = $from.after($from.depth - (depthAfter - 1)) ;
31641- let tr = state.tr.replace(start, end , new Slice(wrap2, 4 - depthBefore, 0));
31641+ let start = $from.before($from.depth - (depthBefore - 1));
31642+ let tr2 = state.tr.replace(start, $from.after(-depthAfter) , new Slice(wrap2, 4 - depthBefore, 0));
3164231643 let sel = -1;
31643- tr.doc.nodesBetween(start, tr.doc.content.size, (node3, pos2) => {
31644- if (sel > -1) return false;
31645- if (node3.isTextblock && node3.content.size == 0) sel = pos2 + 1;
31644+ tr2.doc.nodesBetween(start, tr2.doc.content.size, (node2, pos) => {
31645+ if (sel > -1)
31646+ return false;
31647+ if (node2.isTextblock && node2.content.size == 0)
31648+ sel = pos + 1;
3164631649 });
31647- if (sel > -1) tr.setSelection(TextSelection.near(tr.doc.resolve(sel)));
31648- dispatch(tr.scrollIntoView());
31650+ if (sel > -1)
31651+ tr2.setSelection(Selection.near(tr2.doc.resolve(sel)));
31652+ dispatch(tr2.scrollIntoView());
3164931653 }
3165031654 return true;
3165131655 }
3165231656 let nextType = $to.pos == $from.end() ? grandParent.contentMatchAt(0).defaultType : null;
3165331657 let tr = state.tr.delete($from.pos, $to.pos);
31654- let types2 = nextType ? [itemAttrs ? { type: itemType, attrs: itemAttrs } : null, { type: nextType }] : void 0;
31655- if (!canSplit(tr.doc, $from.pos, 2, types2 ))
31658+ let types = nextType ? [itemAttrs ? { type: itemType, attrs: itemAttrs } : null, { type: nextType }] : void 0;
31659+ if (!canSplit(tr.doc, $from.pos, 2, types ))
3165631660 return false;
3165731661 if (dispatch)
31658- dispatch(tr.split($from.pos, 2, types2 ).scrollIntoView());
31662+ dispatch(tr.split($from.pos, 2, types ).scrollIntoView());
3165931663 return true;
3166031664 };
3166131665 }
31662- function liftListItem(itemType) {
31663- return function(state, dispatch) {
31664- let { $from, $to } = state.selection;
31665- let range = $from.blockRange($to, (node2) => node2.childCount > 0 && node2.firstChild.type == itemType);
31666- if (!range) return false;
31667- if (!dispatch) return true;
31668- if ($from.node(range.depth - 1).type == itemType)
31669- return liftToOuterList(state, dispatch, itemType, range);
31670- return liftOutOfList(state, dispatch, range);
31671- };
31672- }
31673- function liftToOuterList(state, dispatch, itemType, range) {
31674- let tr = state.tr, end = range.end, endOfList = range.$to.end(range.depth);
31675- if (end < endOfList) {
31676- tr.step(new ReplaceAroundStep(end - 1, endOfList, end, endOfList, new Slice(Fragment.from(itemType.create(null, range.parent.copy())), 1, 0), 1, true));
31677- range = new NodeRange(tr.doc.resolve(range.$from.pos), tr.doc.resolve(endOfList), range.depth);
31678- }
31679- let target = liftTarget(range);
31680- if (target == null) return false;
31681- tr.lift(range, target);
31682- let $after = tr.doc.resolve(end - 1);
31683- if ($after.nodeBefore && $after.nodeBefore.type == itemType && canJoin(tr.doc, end - 1))
31684- tr.join(end - 1);
31685- dispatch(tr.scrollIntoView());
31686- return true;
31687- }
31688- function liftOutOfList(state, dispatch, range) {
31689- let tr = state.tr, list = range.parent;
31690- for (let pos2 = range.end, i = range.endIndex - 1, e = range.startIndex; i > e; i--) {
31691- pos2 -= list.child(i).nodeSize;
31692- tr.delete(pos2 - 1, pos2 + 1);
31693- }
31694- let $start = tr.doc.resolve(range.start), item = $start.nodeAfter;
31695- if (tr.mapping.map(range.end) != range.start + $start.nodeAfter.nodeSize) return false;
31696- let atStart = range.startIndex == 0, atEnd = range.endIndex == list.childCount;
31697- let parent = $start.node(-1), indexBefore = $start.index(-1);
31698- if (!parent.canReplace(indexBefore + (atStart ? 0 : 1), indexBefore + 1, item.content.append(atEnd ? Fragment.empty : Fragment.from(list.copy()))))
31699- return false;
31700- let start = $start.pos, end = start + item.nodeSize;
31701- tr.step(new ReplaceAroundStep(start - (atStart ? 1 : 0), end + (atEnd ? 1 : 0), start + 1, end - 1, new Slice((atStart ? Fragment.empty : Fragment.from(list.copy(Fragment.empty))).append(atEnd ? Fragment.empty : Fragment.from(list.copy(Fragment.empty))), atStart ? 0 : 1, atEnd ? 0 : 1), atStart ? 0 : 1));
31702- dispatch(tr.scrollIntoView());
31703- return true;
31704- }
3170531666
3170631667 // src/blazer-markdown-editor.js
3170731668 var tNodes = tableNodes({
@@ -31937,22 +31898,22 @@
3193731898 }
3193831899 function findTableMarkdownRange(state) {
3193931900 const { $head } = state.selection;
31940- const paragraph = $head.parent;
31941- if (paragraph .type.name !== "paragraph") return null;
31901+ const paragraph2 = $head.parent;
31902+ if (paragraph2 .type.name !== "paragraph") return null;
3194231903 const paragraphDepth = $head.depth;
3194331904 const paragraphFrom = $head.before(paragraphDepth);
3194431905 const paragraphTo = $head.after(paragraphDepth);
31945- const text2 = paragraph .textContent;
31906+ const text2 = paragraph2 .textContent;
3194631907 const lines = text2.split("\n");
3194731908 if (lines.length === 2) {
31948- const headerCells = parseHeaderCells(lines[0]);
31949- const separatorCells = parseSeparatorCells(lines[1]);
31950- if (!headerCells || !separatorCells || separatorCells .length !== headerCells .length) return null;
31909+ const headerCells2 = parseHeaderCells(lines[0]);
31910+ const separatorCells2 = parseSeparatorCells(lines[1]);
31911+ if (!headerCells2 || !separatorCells2 || separatorCells2 .length !== headerCells2 .length) return null;
3195131912 return {
3195231913 from: paragraphFrom,
3195331914 to: paragraphTo,
31954- headerCells,
31955- aligns: getAlignments(separatorCells )
31915+ headerCells: headerCells2 ,
31916+ aligns: getAlignments(separatorCells2 )
3195631917 };
3195731918 }
3195831919 const containerDepth = paragraphDepth - 1;
@@ -31998,18 +31959,18 @@
3199831959 const atEnd = $from.parentOffset === $from.parent.content.size;
3199931960 const atStart = $from.parentOffset === 0;
3200031961 if (atStart) {
32001- const tr2 = state.tr.insert($from.before(), schema2.node("paragraph"));
32002- dispatch(tr2 .scrollIntoView());
31962+ const tr = state.tr.insert($from.before(), schema2.node("paragraph"));
31963+ dispatch(tr .scrollIntoView());
3200331964 } else if (atEnd) {
3200431965 const after = $from.after();
32005- const tr2 = state.tr.insert(after, schema2.node("paragraph"));
32006- tr2 .setSelection(TextSelection.near(tr2 .doc.resolve(after + 1)));
32007- dispatch(tr2 .scrollIntoView());
31966+ const tr = state.tr.insert(after, schema2.node("paragraph"));
31967+ tr .setSelection(TextSelection.near(tr .doc.resolve(after + 1)));
31968+ dispatch(tr .scrollIntoView());
3200831969 } else {
32009- const tr2 = state.tr.split($from.pos);
32010- const $new = tr2 .doc.resolve(tr2 .mapping.map($from.pos, 1));
32011- tr2 .setNodeMarkup($new.before($new.depth), schema2.nodes.paragraph);
32012- dispatch(tr2 .scrollIntoView());
31970+ const tr = state.tr.split($from.pos);
31971+ const $new = tr .doc.resolve(tr .mapping.map($from.pos, 1));
31972+ tr .setNodeMarkup($new.before($new.depth), schema2.nodes.paragraph);
31973+ dispatch(tr .scrollIntoView());
3201331974 }
3201431975 }
3201531976 return true;
@@ -32019,24 +31980,30 @@
3201931980 let cellDepth = -1;
3202031981 for (let d = $head.depth; d > 0; d--) {
3202131982 const name = $head.node(d).type.name;
32022- if (name === "table_cell" || name === "table_header") { cellDepth = d; break; }
31983+ if (name === "table_cell" || name === "table_header") {
31984+ cellDepth = d;
31985+ break;
31986+ }
3202331987 }
3202431988 if (cellDepth < 0) return false;
3202531989 const prevNode = $head.nodeBefore;
3202631990 const atEnd = $head.parentOffset === $head.parent.content.size;
3202731991 if (atEnd && prevNode && prevNode.type.name === "hard_break") {
3202831992 let tableDepth = -1;
3202931993 for (let d = cellDepth; d > 0; d--) {
32030- if ($head.node(d).type.name === "table") { tableDepth = d; break; }
31994+ if ($head.node(d).type.name === "table") {
31995+ tableDepth = d;
31996+ break;
31997+ }
3203131998 }
3203231999 if (tableDepth < 0) return false;
3203332000 if (dispatch) {
32034- const tr2 = state.tr;
32035- tr2 .delete($head.pos - 1, $head.pos);
32036- const afterTable = tr2 .mapping.map($head.after(tableDepth));
32037- tr2 .insert(afterTable, schema2.node("paragraph"));
32038- tr2 .setSelection(TextSelection.near(tr2 .doc.resolve(afterTable + 1)));
32039- dispatch(tr2 .scrollIntoView());
32001+ const tr = state.tr;
32002+ tr .delete($head.pos - 1, $head.pos);
32003+ const afterTable = tr .mapping.map($head.after(tableDepth));
32004+ tr .insert(afterTable, schema2.node("paragraph"));
32005+ tr .setSelection(TextSelection.near(tr .doc.resolve(afterTable + 1)));
32006+ dispatch(tr .scrollIntoView());
3204032007 }
3204132008 return true;
3204232009 }
3214032107 return;
3214132108 }
3214232109 const $h = view.state.selection.$head;
32143- let inTbl = false, tblDom = null;
32110+ let inTbl = false;
32111+ let tblDom = null;
3214432112 for (let d = $h.depth; d > 0; d--) {
3214532113 if ($h.node(d).type.name === "table") {
3214632114 inTbl = true;
@@ -32202,24 +32170,24 @@
3220232170 const { $from } = selection;
3220332171 const marks = $from.marks();
3220432172 const direct = marks.find((m) => m.type === linkMarkType);
32205- if (( direct == null ? void 0 : direct .attrs) && direct.attrs .href) return direct.attrs.href;
32173+ if (direct? .attrs? .href) return direct.attrs.href;
3220632174 const before = $from.nodeBefore;
32207- if (before == null ? void 0 : before .marks) {
32175+ if (before? .marks) {
3220832176 const m = before.marks.find((mark) => mark.type === linkMarkType);
32209- if ((m == null ? void 0 : m .attrs) && m.attrs .href) return m.attrs.href;
32177+ if (m? .attrs? .href) return m.attrs.href;
3221032178 }
3221132179 const after = $from.nodeAfter;
32212- if (after == null ? void 0 : after .marks) {
32180+ if (after? .marks) {
3221332181 const m = after.marks.find((mark) => mark.type === linkMarkType);
32214- if ((m == null ? void 0 : m .attrs) && m.attrs .href) return m.attrs.href;
32182+ if (m? .attrs? .href) return m.attrs.href;
3221532183 }
3221632184 return null;
3221732185 }
3221832186 let href = null;
3221932187 state.doc.nodesBetween(selection.from, selection.to, (node) => {
3222032188 if (!node.isText || !node.marks || href) return;
3222132189 const mark = node.marks.find((m) => m.type === linkMarkType);
32222- if (( mark == null ? void 0 : mark .attrs) && mark.attrs .href) href = mark.attrs.href;
32190+ if (mark? .attrs? .href) href = mark.attrs.href;
3222332191 });
3222432192 return href;
3222532193 }
0 commit comments