Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
dist
node_modules
.DS_Store
/package/coverage
tsconfig.node.tsbuildinfo
tsconfig.app.tsbuildinfo
16 changes: 8 additions & 8 deletions examples/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
"preview": "vite preview"
},
"dependencies": {
"@tiptap/core": "^2.26.1",
"@tiptap/extension-document": "^2.26.1",
"@tiptap/extension-list-item": "^2.26.1",
"@tiptap/extension-ordered-list": "^2.26.1",
"@tiptap/extension-placeholder": "^2.26.1",
"@tiptap/pm": "^2.26.1",
"@tiptap/react": "^2.26.1",
"@tiptap/starter-kit": "^2.26.1",
"@tiptap/core": "^3.0.0",
"@tiptap/extension-document": "^3.0.0",
"@tiptap/extension-list-item": "^3.0.0",
"@tiptap/extension-ordered-list": "^3.0.0",
"@tiptap/extension-placeholder": "^3.0.0",
"@tiptap/pm": "^3.0.0",
"@tiptap/react": "^3.0.0",
"@tiptap/starter-kit": "^3.0.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"tiptap-footnotes": "workspace:^"
Expand Down
24 changes: 12 additions & 12 deletions package/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tiptap-footnotes",
"version": "2.0.4",
"version": "3.0.0",
"description": "A footnotes extension for Tiptap",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -27,24 +27,24 @@
],
"license": "MIT",
"devDependencies": {
"@tiptap/core": "^2.26.1",
"@tiptap/extension-document": "^2.26.1",
"@tiptap/extension-list-item": "^2.26.1",
"@tiptap/extension-ordered-list": "^2.26.1",
"@tiptap/extension-paragraph": "^2.26.1",
"@tiptap/extension-text": "^2.26.1",
"@tiptap/pm": "^2.26.1",
"@tiptap/core": "^3.0.0",
"@tiptap/extension-document": "^3.0.0",
"@tiptap/extension-list-item": "^3.0.0",
"@tiptap/extension-ordered-list": "^3.0.0",
"@tiptap/extension-paragraph": "^3.0.0",
"@tiptap/extension-text": "^3.0.0",
"@tiptap/pm": "^3.0.0",
"esbuild": "^0.21.5",
"jsdom": "^24.1.3",
"tsup": "^8.5.0",
"typescript": "^5.8.3",
"vitest": "^2.1.9"
},
"peerDependencies": {
"@tiptap/core": "^2.4.0",
"@tiptap/extension-list-item": "^2.4.0",
"@tiptap/extension-ordered-list": "^2.4.0",
"@tiptap/pm": "^2.4.0"
"@tiptap/core": "^3.0.0",
"@tiptap/extension-list-item": "^3.0.0",
"@tiptap/extension-ordered-list": "^3.0.0",
"@tiptap/pm": "^3.0.0"
},
"dependencies": {
"uuid": "^11.1.0"
Expand Down
29 changes: 29 additions & 0 deletions package/src/footnotes/footnote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const Footnote = ListItem.extend<FootnoteOptions>({

addOptions() {
return {
HTMLAttributes: {},
bulletListTypeName: 'bulletList',
orderedListTypeName: 'orderedList',
...this.parent?.(),
content: "paragraph+",
};
Expand Down Expand Up @@ -101,6 +104,31 @@ const Footnote = ListItem.extend<FootnoteOptions>({
},
addKeyboardShortcuts() {
return {
// when inside a footnote, Mod-a should select only the footnote content
"Mod-a": ({ editor }) => {
try {
const { selection } = editor.state;
const { $from } = selection;

for (let depth = $from.depth; depth >= 0; depth--) {
const node = $from.node(depth);
if (node.type.name === "footnote") {
const start = $from.start(depth);
const end = $from.end(depth);

editor.commands.setTextSelection({
from: start + 1,
to: end - 1,
});
return true;
}
}

return false;
} catch (e) {
return false;
}
},
// when the user presses tab, adjust the text selection to be at the end of the next footnote
Tab: ({ editor }) => {
try {
Expand Down Expand Up @@ -154,6 +182,7 @@ const Footnote = ListItem.extend<FootnoteOptions>({
},
};
},

});

export default Footnote;
26 changes: 1 addition & 25 deletions package/src/footnotes/footnotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,7 @@ const Footnotes = OrderedList.extend({
},

addKeyboardShortcuts() {
return {
// override the default behavior of Mod-a:
// rather than selecting the whole text content of the editor, only select the text inside the current footnote
"Mod-a": ({ editor }) => {
try {
const { selection } = editor.state;
const { $from } = selection;
// footnote listItems are at depth 2, we are getting the start & end position of the parent list item from the current cursor position
const start = $from.start(2);
const startNode = editor.$pos(start);

if (startNode.node.type.name != "footnote") return false;

const end = $from.end(2);

editor.commands.setTextSelection({
from: start + 1,
to: end - 1,
});
return true;
} catch (e) {
return false;
}
},
};
return {};
},
addCommands() {
return {};
Expand Down
8 changes: 2 additions & 6 deletions package/src/footnotes/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ const FootnoteRules = Extension.create({
filterTransaction(tr) {
const { from, to } = tr.selection;

// allow transactions on the whole document
const minPos = TextSelection.atStart(tr.doc).from;
const maxPos = TextSelection.atEnd(tr.doc).to;
const resolvedFrom = minMax(0, minPos, maxPos);
const resolvedEnd = minMax(tr.doc.content.size, minPos, maxPos);
if (from == resolvedFrom && to == resolvedEnd) return true;
// Allow full document selections (Mod-a/Ctrl-a)
if (from === 0 && to === tr.doc.content.size) return true;

let selectedFootnotes = false;
let selectedContent = false;
Expand Down
Loading