@threadlabs/looma 0.45.2 → 0.46.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.
- package/EXPRESSIVE-MARKDOWN.md +23 -17
- package/components/ui-section/ui-section.html +18 -7
- package/components/ui-site-header/ui-site-header.html +25 -6
- package/components/ui-site-header/ui-site-header.js +4 -3
- package/dist/index.js +1 -1
- package/docs/catalog.json +3 -3
- package/editor/chunks/expressmark.js +1562 -0
- package/editor/chunks/extensions.js +327 -1051
- package/editor/expressmark.d.ts +17 -5
- package/editor/expressmark.js +1 -1037
- package/editor/extensions/footnote.d.ts +7 -12
- package/editor/extensions/index.d.ts +2 -2
- package/editor/extensions/index.js +3 -3
- package/editor/extensions/link-definition.d.ts +10 -0
- package/editor/index.js +3 -3
- package/markdown/fixtures.d.ts +1 -1
- package/markdown/fixtures.js +22 -16
- package/markdown/index.d.ts +2 -3
- package/markdown/index.js +2 -3
- package/package.json +2 -9
- package/styles/ui-section.css +12 -3
- package/styles/ui-site-header.css +54 -6
- package/vanilla/UiSection.js +6 -5
- package/vanilla/UiSiteHeader.js +29 -44
- package/vue/UiSection.vue +19 -12
- package/vue/UiSiteHeader.d.ts +2 -2
- package/vue/UiSiteHeader.vue +157 -72
- package/vue/chunks/UiSection.js +32 -29
- package/vue/chunks/UiSiteHeader.js +27 -49
- package/vue/components.css +151 -8
- package/vue/editor/LoomaEditor.d.ts +1 -1
- package/vue/editor/index.js +225 -186
- package/editor/chunks/reference-display.js +0 -453
- package/editor/extensions/markdown.d.ts +0 -16
- package/markdown/markdown-it.d.ts +0 -21
- package/markdown/markdown-it.js +0 -562
package/vue/editor/index.js
CHANGED
|
@@ -1816,7 +1816,6 @@ var labelFrom = (href, prefix) => href?.startsWith(`#${prefix}`) ? href.slice(pr
|
|
|
1816
1816
|
var LOOMA_FOOTNOTE_LABEL = /^[^\s\]]+$/;
|
|
1817
1817
|
var LOOMA_FOOTNOTE_INSERTED = "loomaFootnoteInserted";
|
|
1818
1818
|
var REFERENCE = "loomaFootnoteReference";
|
|
1819
|
-
var NOTES = "loomaFootnotes";
|
|
1820
1819
|
var NOTE = "loomaFootnote";
|
|
1821
1820
|
var isLabel = (label) => LOOMA_FOOTNOTE_LABEL.test(label);
|
|
1822
1821
|
/** Every label a reference or note in `doc` uses. */
|
|
@@ -1845,13 +1844,6 @@ function findLoomaFootnote(doc, label) {
|
|
|
1845
1844
|
});
|
|
1846
1845
|
return found;
|
|
1847
1846
|
}
|
|
1848
|
-
function mapReferences(node, change) {
|
|
1849
|
-
if (node.type.name === REFERENCE) return change(node);
|
|
1850
|
-
if (node.isLeaf) return node;
|
|
1851
|
-
const children = [];
|
|
1852
|
-
node.content.forEach((child) => children.push(mapReferences(child, change)));
|
|
1853
|
-
return node.copy(Fragment$1.from(children));
|
|
1854
|
-
}
|
|
1855
1847
|
function noteAt(doc, position) {
|
|
1856
1848
|
const $position = doc.resolve(position);
|
|
1857
1849
|
for (let depth = $position.depth; depth > 0; depth--) {
|
|
@@ -1864,120 +1856,115 @@ function noteAt(doc, position) {
|
|
|
1864
1856
|
return null;
|
|
1865
1857
|
}
|
|
1866
1858
|
/**
|
|
1867
|
-
*
|
|
1868
|
-
*
|
|
1869
|
-
*
|
|
1870
|
-
*
|
|
1871
|
-
* reference points to leaves the document; a reference with no note gets one back, the note it last
|
|
1872
|
-
* had in this editor (so cutting a reference and pasting it keeps its note) or an empty one.
|
|
1873
|
-
* @invariant Changing nothing but text inside a note never rebuilds the section.
|
|
1859
|
+
* Looma Markdown's footnote numbering for `content`, in document order. Notes are numbered by first
|
|
1860
|
+
* reference, in the text and then in the notes, and every reference has its note's number and its
|
|
1861
|
+
* place among that note's references. The first note for a label is its note, as with Markdown's
|
|
1862
|
+
* definitions; any other note, or one nothing refers to, has no number.
|
|
1874
1863
|
*/
|
|
1875
|
-
function
|
|
1876
|
-
const
|
|
1877
|
-
const
|
|
1878
|
-
const
|
|
1879
|
-
const
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
node,
|
|
1884
|
-
position
|
|
1885
|
-
});
|
|
1886
|
-
node.forEach((note) => {
|
|
1887
|
-
if (!notes.has(note.attrs.label)) notes.set(note.attrs.label, note);
|
|
1888
|
-
});
|
|
1889
|
-
return false;
|
|
1890
|
-
}
|
|
1891
|
-
if (node.type.name === REFERENCE) body.push({
|
|
1892
|
-
node,
|
|
1893
|
-
position
|
|
1864
|
+
function numberFootnotes(content) {
|
|
1865
|
+
const references = [];
|
|
1866
|
+
const notes = [];
|
|
1867
|
+
const first = /* @__PURE__ */ new Map();
|
|
1868
|
+
const visit = (fragment, note) => fragment.forEach((node) => {
|
|
1869
|
+
if (node.type.name === REFERENCE) references.push({
|
|
1870
|
+
label: String(node.attrs.label),
|
|
1871
|
+
note
|
|
1894
1872
|
});
|
|
1873
|
+
else if (node.type.name === NOTE) {
|
|
1874
|
+
notes.push(node);
|
|
1875
|
+
if (!first.has(node.attrs.label)) first.set(node.attrs.label, node);
|
|
1876
|
+
visit(node.content, node);
|
|
1877
|
+
} else visit(node.content, note);
|
|
1895
1878
|
});
|
|
1896
|
-
|
|
1879
|
+
visit(content, null);
|
|
1897
1880
|
const order = [];
|
|
1898
1881
|
const counts = /* @__PURE__ */ new Map();
|
|
1899
|
-
const numbered = (
|
|
1900
|
-
|
|
1882
|
+
const numbered = /* @__PURE__ */ new Map();
|
|
1883
|
+
const number = (index) => {
|
|
1884
|
+
const { label } = references[index];
|
|
1901
1885
|
if (!counts.has(label)) order.push(label);
|
|
1902
1886
|
counts.set(label, (counts.get(label) ?? 0) + 1);
|
|
1903
|
-
|
|
1904
|
-
...reference.attrs,
|
|
1887
|
+
numbered.set(index, {
|
|
1905
1888
|
number: order.indexOf(label) + 1,
|
|
1906
1889
|
occurrence: counts.get(label)
|
|
1907
|
-
};
|
|
1908
|
-
return attrs.number === reference.attrs.number && attrs.occurrence === reference.attrs.occurrence ? reference : reference.type.create(attrs, null, reference.marks);
|
|
1890
|
+
});
|
|
1909
1891
|
};
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
const note = notes.get(label) ?? known.get(label) ?? schema.nodes[NOTE].create({ label }, schema.nodes.paragraph.create());
|
|
1919
|
-
built.push(mapReferences(note, numbered));
|
|
1920
|
-
}
|
|
1921
|
-
const wanted = built.map((note) => note.attrs.count === counts.get(note.attrs.label) ? note : note.type.create({
|
|
1922
|
-
...note.attrs,
|
|
1923
|
-
count: counts.get(note.attrs.label)
|
|
1924
|
-
}, note.content));
|
|
1925
|
-
for (const note of [...notes.values(), ...wanted]) known.set(note.attrs.label, note);
|
|
1926
|
-
const section = wanted.length ? schema.nodes[NOTES].create(null, wanted) : null;
|
|
1927
|
-
const last = doc.lastChild?.type.name === NOTES ? {
|
|
1928
|
-
node: doc.lastChild,
|
|
1929
|
-
position: doc.content.size - doc.lastChild.nodeSize
|
|
1930
|
-
} : null;
|
|
1931
|
-
if (!(section && last && sections.length === 1 && last.node.eq(section)) && (sections.length || section)) {
|
|
1932
|
-
const { selection } = state;
|
|
1933
|
-
const inside = noteAt(doc, selection.from);
|
|
1934
|
-
const keep = inside && selection.to <= inside.start + inside.node.nodeSize ? {
|
|
1935
|
-
label: inside.node.attrs.label,
|
|
1936
|
-
start: inside.start
|
|
1937
|
-
} : null;
|
|
1938
|
-
for (const { node, position } of [...sections].reverse()) if (node !== last?.node) transaction.delete(position, position + node.nodeSize);
|
|
1939
|
-
if (last) {
|
|
1940
|
-
const position = transaction.mapping.map(last.position);
|
|
1941
|
-
if (section) transaction.replaceWith(position, position + last.node.nodeSize, section);
|
|
1942
|
-
else transaction.delete(position, position + last.node.nodeSize);
|
|
1943
|
-
} else if (section) transaction.insert(transaction.doc.content.size, section);
|
|
1944
|
-
const moved = keep && findLoomaFootnote(transaction.doc, keep.label);
|
|
1945
|
-
if (keep && moved) {
|
|
1946
|
-
const json = selection.toJSON();
|
|
1947
|
-
json.anchor += moved.position - keep.start;
|
|
1948
|
-
if (json.head !== void 0) json.head += moved.position - keep.start;
|
|
1949
|
-
try {
|
|
1950
|
-
transaction.setSelection(Selection.fromJSON(transaction.doc, json));
|
|
1951
|
-
} catch {}
|
|
1952
|
-
}
|
|
1953
|
-
}
|
|
1954
|
-
return transaction.docChanged ? transaction : null;
|
|
1955
|
-
}
|
|
1956
|
-
function appendBackLinks(item, label, number, count) {
|
|
1957
|
-
const document = item.ownerDocument;
|
|
1958
|
-
let paragraph = item.lastElementChild;
|
|
1959
|
-
if (paragraph?.nodeName !== "P") item.append(paragraph = document.createElement("p"));
|
|
1960
|
-
for (let occurrence = 1; occurrence <= count; occurrence++) {
|
|
1961
|
-
const link = document.createElement("a");
|
|
1962
|
-
link.setAttribute("href", `#fnref:${label}${occurrence > 1 ? `:${occurrence}` : ""}`);
|
|
1963
|
-
link.setAttribute("data-footnote-backref", "");
|
|
1964
|
-
link.setAttribute("aria-label", `Back to reference ${number}${occurrence > 1 ? `-${occurrence}` : ""}`);
|
|
1965
|
-
link.append("↩");
|
|
1966
|
-
if (occurrence > 1) link.append(Object.assign(document.createElement("sup"), { textContent: String(occurrence) }));
|
|
1967
|
-
paragraph.append(" ", link);
|
|
1892
|
+
references.forEach((reference, index) => {
|
|
1893
|
+
if (!reference.note) number(index);
|
|
1894
|
+
});
|
|
1895
|
+
for (let at = 0; at < order.length; at++) {
|
|
1896
|
+
const note = first.get(order[at]);
|
|
1897
|
+
references.forEach((reference, index) => {
|
|
1898
|
+
if (note && reference.note === note) number(index);
|
|
1899
|
+
});
|
|
1968
1900
|
}
|
|
1901
|
+
return {
|
|
1902
|
+
order,
|
|
1903
|
+
counts,
|
|
1904
|
+
references: references.map((_reference, index) => numbered.get(index) ?? {
|
|
1905
|
+
number: null,
|
|
1906
|
+
occurrence: 1
|
|
1907
|
+
}),
|
|
1908
|
+
notes: notes.map((note) => ({
|
|
1909
|
+
number: first.get(note.attrs.label) === note && counts.has(note.attrs.label) ? order.indexOf(note.attrs.label) + 1 : null,
|
|
1910
|
+
count: counts.get(note.attrs.label) ?? 1
|
|
1911
|
+
}))
|
|
1912
|
+
};
|
|
1969
1913
|
}
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1914
|
+
/**
|
|
1915
|
+
* Keeps footnotes on Looma Markdown's rule (`numberFootnotes`). Each note stays where its definition
|
|
1916
|
+
* is written. Removing a note's last reference removes the note; a reference with no note gets one
|
|
1917
|
+
* back at the end of the document, the note it last had in this editor (so cutting a reference and
|
|
1918
|
+
* pasting it keeps its note) or an empty one. A note nothing has referred to in this editor, as a
|
|
1919
|
+
* document may define one, stays.
|
|
1920
|
+
* @invariant Changing nothing but text inside a note never moves or renumbers a note.
|
|
1921
|
+
*/
|
|
1922
|
+
function footnoteTransaction(state, previous, known) {
|
|
1923
|
+
const { doc, schema } = state;
|
|
1924
|
+
const references = [];
|
|
1925
|
+
const notes = [];
|
|
1926
|
+
doc.descendants((node, position) => {
|
|
1927
|
+
if (node.type.name === REFERENCE) references.push({
|
|
1928
|
+
node,
|
|
1929
|
+
position
|
|
1930
|
+
});
|
|
1931
|
+
if (node.type.name === NOTE) notes.push({
|
|
1932
|
+
node,
|
|
1933
|
+
position
|
|
1934
|
+
});
|
|
1935
|
+
});
|
|
1936
|
+
if (!references.length && !notes.length) return null;
|
|
1937
|
+
previous?.descendants((node) => {
|
|
1938
|
+
if (node.type.name === NOTE && !known.has(node.attrs.label)) known.set(node.attrs.label, node);
|
|
1939
|
+
});
|
|
1940
|
+
const numbering = numberFootnotes(doc.content);
|
|
1941
|
+
const transaction = state.tr;
|
|
1942
|
+
const update = ({ node, position }, attrs) => {
|
|
1943
|
+
if (Object.entries(attrs).some(([key, value]) => node.attrs[key] !== value)) transaction.setNodeMarkup(position, void 0, {
|
|
1944
|
+
...node.attrs,
|
|
1945
|
+
...attrs
|
|
1978
1946
|
});
|
|
1979
|
-
return dom;
|
|
1980
1947
|
};
|
|
1948
|
+
references.forEach((reference, index) => update(reference, numbering.references[index]));
|
|
1949
|
+
notes.forEach((note, index) => {
|
|
1950
|
+
update(note, numbering.notes[index]);
|
|
1951
|
+
known.set(note.node.attrs.label, note.node);
|
|
1952
|
+
});
|
|
1953
|
+
const referenced = /* @__PURE__ */ new Set();
|
|
1954
|
+
previous?.descendants((node) => {
|
|
1955
|
+
if (node.type.name === REFERENCE) referenced.add(String(node.attrs.label));
|
|
1956
|
+
});
|
|
1957
|
+
for (const { node, position } of [...notes].reverse()) if (referenced.has(node.attrs.label) && !numbering.counts.has(node.attrs.label)) transaction.delete(transaction.mapping.map(position), transaction.mapping.map(position + node.nodeSize));
|
|
1958
|
+
for (const label of numbering.order) {
|
|
1959
|
+
if (notes.some(({ node }) => node.attrs.label === label)) continue;
|
|
1960
|
+
const note = known.get(label) ?? schema.nodes[NOTE].create({ label }, schema.nodes.paragraph.create());
|
|
1961
|
+
transaction.insert(transaction.doc.content.size, note.type.create({
|
|
1962
|
+
...note.attrs,
|
|
1963
|
+
number: numbering.order.indexOf(label) + 1,
|
|
1964
|
+
count: numbering.counts.get(label)
|
|
1965
|
+
}, note.content));
|
|
1966
|
+
}
|
|
1967
|
+
return transaction.docChanged ? transaction : null;
|
|
1981
1968
|
}
|
|
1982
1969
|
Node$1.create({
|
|
1983
1970
|
name: REFERENCE,
|
|
@@ -2072,59 +2059,150 @@ Node$1.create({
|
|
|
2072
2059
|
};
|
|
2073
2060
|
}
|
|
2074
2061
|
});
|
|
2062
|
+
function appendBackLinks(item, label, number, count) {
|
|
2063
|
+
const document = item.ownerDocument;
|
|
2064
|
+
let paragraph = item.lastElementChild;
|
|
2065
|
+
if (paragraph?.nodeName !== "P") item.append(paragraph = document.createElement("p"));
|
|
2066
|
+
for (let occurrence = 1; occurrence <= count; occurrence++) {
|
|
2067
|
+
const link = document.createElement("a");
|
|
2068
|
+
link.setAttribute("href", `#fnref:${label}${occurrence > 1 ? `:${occurrence}` : ""}`);
|
|
2069
|
+
link.setAttribute("data-footnote-backref", "");
|
|
2070
|
+
link.setAttribute("aria-label", `Back to reference ${number}${occurrence > 1 ? `-${occurrence}` : ""}`);
|
|
2071
|
+
link.append("↩");
|
|
2072
|
+
if (occurrence > 1) link.append(Object.assign(document.createElement("sup"), { textContent: String(occurrence) }));
|
|
2073
|
+
paragraph.append(" ", link);
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
function installSerializer(schema) {
|
|
2077
|
+
const serializer = DOMSerializer.fromSchema(schema);
|
|
2078
|
+
if (Object.prototype.hasOwnProperty.call(serializer, "serializeFragment")) return;
|
|
2079
|
+
const serializeFragment = serializer.serializeFragment;
|
|
2080
|
+
serializer.serializeFragment = function(fragment, options = {}, target) {
|
|
2081
|
+
const dom = serializeFragment.call(this, fragment, options, target);
|
|
2082
|
+
if (target) return dom;
|
|
2083
|
+
const numbering = numberFootnotes(fragment);
|
|
2084
|
+
const references = [...dom.querySelectorAll("a[data-footnote-ref]")];
|
|
2085
|
+
const elements = [...dom.querySelectorAll("[data-looma-footnote]")];
|
|
2086
|
+
if (references.length !== numbering.references.length || elements.length !== numbering.notes.length) return dom;
|
|
2087
|
+
references.forEach((link, index) => {
|
|
2088
|
+
const { number, occurrence } = numbering.references[index];
|
|
2089
|
+
const label = labelFrom(link.getAttribute("href"), "fn:");
|
|
2090
|
+
if (number !== null) link.textContent = String(number);
|
|
2091
|
+
link.id = `fnref:${label}${occurrence > 1 ? `:${occurrence}` : ""}`;
|
|
2092
|
+
});
|
|
2093
|
+
const document = dom.ownerDocument;
|
|
2094
|
+
const items = [];
|
|
2095
|
+
elements.forEach((element, index) => {
|
|
2096
|
+
const { number, count } = numbering.notes[index];
|
|
2097
|
+
const label = element.getAttribute("data-label") ?? "";
|
|
2098
|
+
element.remove();
|
|
2099
|
+
if (number === null) return;
|
|
2100
|
+
const item = document.createElement("li");
|
|
2101
|
+
item.id = `fn:${label}`;
|
|
2102
|
+
item.append(...element.querySelector(":scope > li").childNodes);
|
|
2103
|
+
appendBackLinks(item, label, number, count);
|
|
2104
|
+
items.push({
|
|
2105
|
+
number,
|
|
2106
|
+
item
|
|
2107
|
+
});
|
|
2108
|
+
});
|
|
2109
|
+
if (!items.length) return dom;
|
|
2110
|
+
const section = document.createElement("section");
|
|
2111
|
+
section.setAttribute("data-footnotes", "");
|
|
2112
|
+
section.className = "footnotes";
|
|
2113
|
+
section.append(Object.assign(document.createElement("h2"), {
|
|
2114
|
+
id: "footnote:label",
|
|
2115
|
+
className: "sr-only",
|
|
2116
|
+
textContent: "Footnotes"
|
|
2117
|
+
}));
|
|
2118
|
+
section.append(document.createElement("ol"));
|
|
2119
|
+
section.lastElementChild.append(...items.sort((a, b) => a.number - b.number).map(({ item }) => item));
|
|
2120
|
+
dom.append(section);
|
|
2121
|
+
return dom;
|
|
2122
|
+
};
|
|
2123
|
+
}
|
|
2124
|
+
var known = /* @__PURE__ */ new WeakMap();
|
|
2125
|
+
var knownNotes = (editor) => known.get(editor) ?? known.set(editor, /* @__PURE__ */ new Map()).get(editor);
|
|
2075
2126
|
Node$1.create({
|
|
2076
|
-
name:
|
|
2127
|
+
name: NOTE,
|
|
2077
2128
|
group: "block",
|
|
2078
|
-
content:
|
|
2079
|
-
|
|
2129
|
+
content: "block+",
|
|
2130
|
+
defining: true,
|
|
2131
|
+
addAttributes() {
|
|
2132
|
+
return {
|
|
2133
|
+
label: {
|
|
2134
|
+
default: "",
|
|
2135
|
+
parseHTML: (element) => element.getAttribute("data-label") ?? labelFrom(`#${element.id}`, "fn:") ?? "",
|
|
2136
|
+
renderHTML: () => ({})
|
|
2137
|
+
},
|
|
2138
|
+
number: {
|
|
2139
|
+
default: null,
|
|
2140
|
+
renderHTML: () => ({})
|
|
2141
|
+
},
|
|
2142
|
+
count: {
|
|
2143
|
+
default: 1,
|
|
2144
|
+
parseHTML: (element) => element.querySelectorAll("a[data-footnote-backref]").length || 1,
|
|
2145
|
+
renderHTML: () => ({})
|
|
2146
|
+
}
|
|
2147
|
+
};
|
|
2148
|
+
},
|
|
2080
2149
|
parseHTML() {
|
|
2081
|
-
return [
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2150
|
+
return [
|
|
2151
|
+
{
|
|
2152
|
+
tag: "section[data-footnotes]",
|
|
2153
|
+
priority: 1100,
|
|
2154
|
+
skip: true
|
|
2155
|
+
},
|
|
2156
|
+
{
|
|
2157
|
+
tag: "section[data-footnotes] > h2",
|
|
2158
|
+
priority: 1100,
|
|
2159
|
+
ignore: true
|
|
2160
|
+
},
|
|
2161
|
+
{
|
|
2162
|
+
tag: "section[data-footnotes] > ol",
|
|
2163
|
+
priority: 1100,
|
|
2164
|
+
skip: true
|
|
2165
|
+
},
|
|
2166
|
+
{
|
|
2167
|
+
tag: "section[data-footnotes] > ol > li",
|
|
2168
|
+
priority: 1100
|
|
2169
|
+
},
|
|
2170
|
+
{
|
|
2171
|
+
tag: ":is(ol, ul)[data-looma-footnote]",
|
|
2172
|
+
priority: 1100,
|
|
2173
|
+
contentElement: ":scope > li"
|
|
2174
|
+
},
|
|
2175
|
+
{
|
|
2176
|
+
tag: "a[data-footnote-backref]",
|
|
2177
|
+
priority: 1100,
|
|
2178
|
+
ignore: true
|
|
2179
|
+
}
|
|
2180
|
+
];
|
|
2085
2181
|
},
|
|
2086
|
-
renderHTML() {
|
|
2182
|
+
renderHTML({ node }) {
|
|
2183
|
+
const { label, number } = node.attrs;
|
|
2087
2184
|
return [
|
|
2088
|
-
"
|
|
2185
|
+
number === null ? "ul" : "ol",
|
|
2089
2186
|
{
|
|
2090
|
-
"data-
|
|
2091
|
-
|
|
2187
|
+
"data-looma-footnote": "",
|
|
2188
|
+
"data-label": label,
|
|
2189
|
+
id: `fn:${label}`,
|
|
2190
|
+
...number === null ? {} : { start: number }
|
|
2092
2191
|
},
|
|
2093
|
-
[
|
|
2094
|
-
"h2",
|
|
2095
|
-
{
|
|
2096
|
-
id: "footnote:label",
|
|
2097
|
-
class: "sr-only"
|
|
2098
|
-
},
|
|
2099
|
-
"Footnotes"
|
|
2100
|
-
],
|
|
2101
|
-
["ol", 0]
|
|
2192
|
+
["li", 0]
|
|
2102
2193
|
];
|
|
2103
2194
|
},
|
|
2104
2195
|
onBeforeCreate() {
|
|
2105
2196
|
installSerializer(this.editor.schema);
|
|
2106
2197
|
},
|
|
2107
2198
|
onCreate() {
|
|
2108
|
-
const transaction = footnoteTransaction(this.editor.state, this.
|
|
2199
|
+
const transaction = footnoteTransaction(this.editor.state, null, knownNotes(this.editor));
|
|
2109
2200
|
if (transaction) this.editor.view.dispatch(transaction.setMeta("addToHistory", false));
|
|
2110
2201
|
},
|
|
2111
|
-
addStorage: () => ({ known: /* @__PURE__ */ new Map() }),
|
|
2112
2202
|
addProseMirrorPlugins() {
|
|
2113
2203
|
return [new Plugin({
|
|
2114
|
-
appendTransaction: (transactions,
|
|
2115
|
-
props: { transformPasted: (slice) =>
|
|
2116
|
-
const kept = [];
|
|
2117
|
-
slice.content.forEach((node) => {
|
|
2118
|
-
if (node.type.name === NOTES) node.forEach((note) => {
|
|
2119
|
-
this.storage.known.set(note.attrs.label, note);
|
|
2120
|
-
});
|
|
2121
|
-
else kept.push(node);
|
|
2122
|
-
});
|
|
2123
|
-
if (!kept.length || kept.length === slice.content.childCount) return slice;
|
|
2124
|
-
const content = Fragment$1.from(kept);
|
|
2125
|
-
const open = Slice.maxOpen(content);
|
|
2126
|
-
return new Slice(content, kept[0] === slice.content.firstChild ? slice.openStart : open.openStart, kept.at(-1) === slice.content.lastChild ? slice.openEnd : open.openEnd);
|
|
2127
|
-
} }
|
|
2204
|
+
appendTransaction: (transactions, oldState, state) => transactions.some((transaction) => transaction.docChanged) ? footnoteTransaction(state, oldState.doc, knownNotes(this.editor)) : null,
|
|
2205
|
+
props: { transformPasted: (slice) => slice.openEnd && slice.content.lastChild?.type.name === NOTE ? new Slice(slice.content, slice.openStart, 0) : slice }
|
|
2128
2206
|
})];
|
|
2129
2207
|
},
|
|
2130
2208
|
addCommands() {
|
|
@@ -2150,10 +2228,8 @@ Node$1.create({
|
|
|
2150
2228
|
occurrence
|
|
2151
2229
|
});
|
|
2152
2230
|
if (!findLoomaFootnote(tr.doc, name)) {
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
else tr.insert(tr.doc.content.size, state.schema.nodes[NOTES].create(null, note));
|
|
2156
|
-
tr.setSelection(TextSelection.create(tr.doc, tr.doc.content.size - 3));
|
|
2231
|
+
tr.insert(tr.doc.content.size, state.schema.nodes[NOTE].create({ label: name }, state.schema.nodes.paragraph.create()));
|
|
2232
|
+
tr.setSelection(TextSelection.create(tr.doc, tr.doc.content.size - 2));
|
|
2157
2233
|
}
|
|
2158
2234
|
tr.scrollIntoView();
|
|
2159
2235
|
return true;
|
|
@@ -2196,43 +2272,6 @@ Node$1.create({
|
|
|
2196
2272
|
};
|
|
2197
2273
|
}
|
|
2198
2274
|
});
|
|
2199
|
-
Node$1.create({
|
|
2200
|
-
name: NOTE,
|
|
2201
|
-
content: "block+",
|
|
2202
|
-
defining: true,
|
|
2203
|
-
addAttributes() {
|
|
2204
|
-
return {
|
|
2205
|
-
label: {
|
|
2206
|
-
default: "",
|
|
2207
|
-
parseHTML: (element) => labelFrom(`#${element.id}`, "fn:") ?? "",
|
|
2208
|
-
renderHTML: () => ({})
|
|
2209
|
-
},
|
|
2210
|
-
count: {
|
|
2211
|
-
default: 1,
|
|
2212
|
-
parseHTML: (element) => element.querySelectorAll("a[data-footnote-backref]").length || 1,
|
|
2213
|
-
renderHTML: () => ({})
|
|
2214
|
-
}
|
|
2215
|
-
};
|
|
2216
|
-
},
|
|
2217
|
-
parseHTML() {
|
|
2218
|
-
return [{
|
|
2219
|
-
tag: "li",
|
|
2220
|
-
priority: 1100,
|
|
2221
|
-
context: `${NOTES}/`
|
|
2222
|
-
}, {
|
|
2223
|
-
tag: "a[data-footnote-backref]",
|
|
2224
|
-
priority: 1100,
|
|
2225
|
-
ignore: true
|
|
2226
|
-
}];
|
|
2227
|
-
},
|
|
2228
|
-
renderHTML({ node }) {
|
|
2229
|
-
return [
|
|
2230
|
-
"li",
|
|
2231
|
-
{ id: `fn:${node.attrs.label}` },
|
|
2232
|
-
0
|
|
2233
|
-
];
|
|
2234
|
-
}
|
|
2235
|
-
});
|
|
2236
2275
|
//#endregion
|
|
2237
2276
|
//#region src/editor/footnote-editing.ts
|
|
2238
2277
|
var content = (note) => ({
|
|
@@ -2251,7 +2290,7 @@ var LOOMA_FOOTNOTE_EDITING_IDLE = Object.freeze({
|
|
|
2251
2290
|
* Document-wide normalizers and node-view callbacks stay with the parent editor.
|
|
2252
2291
|
*/
|
|
2253
2292
|
function footnoteContentExtensions(editor) {
|
|
2254
|
-
return editor.extensionManager.extensions.filter((extension) => extension.type === "node" || extension.type === "mark").filter((extension) =>
|
|
2293
|
+
return editor.extensionManager.extensions.filter((extension) => extension.type === "node" || extension.type === "mark").filter((extension) => extension.name !== "loomaFootnote").map((extension) => {
|
|
2255
2294
|
const attributes = Object.fromEntries(editor.extensionManager.attributes.filter((attribute) => attribute.type === extension.name).map((attribute) => [attribute.name, { ...attribute.attribute }]));
|
|
2256
2295
|
const schema = {
|
|
2257
2296
|
addAttributes: () => attributes,
|