@threadlabs/looma 0.29.14 → 0.29.15
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.
|
@@ -618,6 +618,7 @@ function getTableOfContentsEntries(doc, depth = 3) {
|
|
|
618
618
|
const entries = [];
|
|
619
619
|
const ancestors = [];
|
|
620
620
|
doc.descendants((node, position) => {
|
|
621
|
+
if (node.type.name === "loomaTableOfContents") return false;
|
|
621
622
|
if (node.type.name !== "heading" || node.attrs.level > depth || !node.textContent.trim()) return;
|
|
622
623
|
const level = Number(node.attrs.level);
|
|
623
624
|
while (ancestors.length && ancestors[ancestors.length - 1] >= level) ancestors.pop();
|
|
@@ -661,7 +662,10 @@ function anchorTransaction(state, previous) {
|
|
|
661
662
|
let hasToc = false;
|
|
662
663
|
const headings = [];
|
|
663
664
|
state.doc.descendants((node, position) => {
|
|
664
|
-
if (node.type.name === "loomaTableOfContents")
|
|
665
|
+
if (node.type.name === "loomaTableOfContents") {
|
|
666
|
+
hasToc = true;
|
|
667
|
+
return false;
|
|
668
|
+
}
|
|
665
669
|
if (node.type.name === "heading") headings.push({
|
|
666
670
|
node,
|
|
667
671
|
position
|
|
@@ -670,6 +674,7 @@ function anchorTransaction(state, previous) {
|
|
|
670
674
|
if (!headings.length) return null;
|
|
671
675
|
const before = /* @__PURE__ */ new Map();
|
|
672
676
|
previous?.descendants((node) => {
|
|
677
|
+
if (node.type.name === "loomaTableOfContents") return false;
|
|
673
678
|
if (node.type.name === "heading" && typeof node.attrs.id === "string") before.set(node.attrs.id, node.textContent.trim());
|
|
674
679
|
});
|
|
675
680
|
const custom = (node) => {
|
package/editor/expressmark.js
CHANGED
|
@@ -486,7 +486,7 @@ function editorDocumentToExpressmark(document, options = {}) {
|
|
|
486
486
|
let automaticToc = false;
|
|
487
487
|
const colors = /* @__PURE__ */ new Set();
|
|
488
488
|
const urls = /* @__PURE__ */ new Set();
|
|
489
|
-
const visit = (node) => {
|
|
489
|
+
const visit = (node, insideToc = false) => {
|
|
490
490
|
const attrs = node.attrs ?? {};
|
|
491
491
|
if (node.type === "tableCell" || node.type === "tableHeader") {
|
|
492
492
|
if (attrs.backgroundColor != null && !colors.has(attrs.backgroundColor)) {
|
|
@@ -520,14 +520,14 @@ function editorDocumentToExpressmark(document, options = {}) {
|
|
|
520
520
|
urls.add(key);
|
|
521
521
|
}
|
|
522
522
|
}
|
|
523
|
-
if (node.type === "loomaTableOfContents" && !node.content?.length) automaticToc = true;
|
|
524
|
-
if (node.type === "heading") headings.push({
|
|
523
|
+
if (!insideToc && node.type === "loomaTableOfContents" && !node.content?.length) automaticToc = true;
|
|
524
|
+
if (!insideToc && node.type === "heading") headings.push({
|
|
525
525
|
node,
|
|
526
526
|
text: (node.content ?? []).map((child) => child.text ?? "").join(""),
|
|
527
527
|
id: string(node.attrs?.id),
|
|
528
528
|
level: Number(node.attrs?.level ?? 1)
|
|
529
529
|
});
|
|
530
|
-
for (const child of node.content ?? []) visit(child);
|
|
530
|
+
for (const child of node.content ?? []) visit(child, insideToc || node.type === "loomaTableOfContents");
|
|
531
531
|
};
|
|
532
532
|
visit(document);
|
|
533
533
|
const headingIds = /* @__PURE__ */ new WeakMap();
|
package/package.json
CHANGED
package/vue/editor/index.js
CHANGED
|
@@ -10256,6 +10256,7 @@ function getTableOfContentsEntries$1(doc, depth = 3) {
|
|
|
10256
10256
|
const entries = [];
|
|
10257
10257
|
const ancestors = [];
|
|
10258
10258
|
doc.descendants((node, position) => {
|
|
10259
|
+
if (node.type.name === "loomaTableOfContents") return false;
|
|
10259
10260
|
if (node.type.name !== "heading" || node.attrs.level > depth || !node.textContent.trim()) return;
|
|
10260
10261
|
const level = Number(node.attrs.level);
|
|
10261
10262
|
while (ancestors.length && ancestors[ancestors.length - 1] >= level) ancestors.pop();
|
|
@@ -10299,7 +10300,10 @@ function anchorTransaction(state, previous) {
|
|
|
10299
10300
|
let hasToc = false;
|
|
10300
10301
|
const headings = [];
|
|
10301
10302
|
state.doc.descendants((node, position) => {
|
|
10302
|
-
if (node.type.name === "loomaTableOfContents")
|
|
10303
|
+
if (node.type.name === "loomaTableOfContents") {
|
|
10304
|
+
hasToc = true;
|
|
10305
|
+
return false;
|
|
10306
|
+
}
|
|
10303
10307
|
if (node.type.name === "heading") headings.push({
|
|
10304
10308
|
node,
|
|
10305
10309
|
position
|
|
@@ -10308,6 +10312,7 @@ function anchorTransaction(state, previous) {
|
|
|
10308
10312
|
if (!headings.length) return null;
|
|
10309
10313
|
const before = /* @__PURE__ */ new Map();
|
|
10310
10314
|
previous?.descendants((node) => {
|
|
10315
|
+
if (node.type.name === "loomaTableOfContents") return false;
|
|
10311
10316
|
if (node.type.name === "heading" && typeof node.attrs.id === "string") before.set(node.attrs.id, node.textContent.trim());
|
|
10312
10317
|
});
|
|
10313
10318
|
const custom = (node) => {
|