@kedataindo/docflow-plugins 0.0.89 → 0.0.91
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/dist/index.cjs +57 -17
- package/dist/index.d.cts +21 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.js +43 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -92,6 +92,7 @@ __export(index_exports, {
|
|
|
92
92
|
rejectAllSuggestions: () => rejectAllSuggestions,
|
|
93
93
|
rejectSuggestion: () => rejectSuggestion,
|
|
94
94
|
sanitizeCiteprocHtml: () => sanitizeCiteprocHtml,
|
|
95
|
+
scrollEditorToPos: () => scrollEditorToPos,
|
|
95
96
|
setDocumentMode: () => setDocumentMode,
|
|
96
97
|
setSuggestionAuthor: () => setSuggestionAuthor,
|
|
97
98
|
slashMenuPlugin: () => slashMenuPlugin,
|
|
@@ -639,6 +640,44 @@ var footnotePlugin = (0, import_docflow_core12.definePlugin)({
|
|
|
639
640
|
// src/toc.ts
|
|
640
641
|
var import_core4 = require("@tiptap/core");
|
|
641
642
|
var import_docflow_core13 = require("@kedataindo/docflow-core");
|
|
643
|
+
|
|
644
|
+
// src/editorScroll.ts
|
|
645
|
+
var import_state = require("@tiptap/pm/state");
|
|
646
|
+
function scrollEditorToPos(editor, pos, options = {}) {
|
|
647
|
+
const { state, view } = editor;
|
|
648
|
+
const clamped = Math.min(Math.max(0, pos), state.doc.content.size);
|
|
649
|
+
let anchor = clamped;
|
|
650
|
+
if (options.focus !== false) {
|
|
651
|
+
const selection = import_state.TextSelection.near(state.doc.resolve(clamped), 1);
|
|
652
|
+
if (!state.selection.eq(selection)) {
|
|
653
|
+
view.dispatch(state.tr.setSelection(selection));
|
|
654
|
+
}
|
|
655
|
+
editor.commands.focus();
|
|
656
|
+
anchor = view.state.selection.from;
|
|
657
|
+
}
|
|
658
|
+
const editorDom = view.dom;
|
|
659
|
+
const scrollEl = editorDom.closest?.(".docs-editor-scroll") ?? null;
|
|
660
|
+
let coords = null;
|
|
661
|
+
try {
|
|
662
|
+
coords = view.coordsAtPos(anchor);
|
|
663
|
+
} catch {
|
|
664
|
+
coords = null;
|
|
665
|
+
}
|
|
666
|
+
if (!scrollEl || !coords) {
|
|
667
|
+
editorDom.scrollIntoView?.({ block: "start" });
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
const scrollRect = scrollEl.getBoundingClientRect();
|
|
671
|
+
const top = scrollEl.scrollTop + (coords.top - scrollRect.top) - scrollEl.clientHeight / 3;
|
|
672
|
+
const target = Math.max(0, top);
|
|
673
|
+
try {
|
|
674
|
+
scrollEl.scrollTo({ top: target, behavior: "smooth" });
|
|
675
|
+
} catch {
|
|
676
|
+
scrollEl.scrollTop = target;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
// src/toc.ts
|
|
642
681
|
function collectHeadingsFromDoc(doc) {
|
|
643
682
|
const headings = [];
|
|
644
683
|
doc.descendants((node, pos) => {
|
|
@@ -846,8 +885,7 @@ var TocNode = import_core4.Node.create({
|
|
|
846
885
|
const entry = event.target?.closest?.("[data-toc-entry]");
|
|
847
886
|
if (!entry) return;
|
|
848
887
|
const pos = Number(entry.getAttribute("data-pos") ?? 0);
|
|
849
|
-
|
|
850
|
-
editor.chain().focus().setTextSelection(clamped).scrollIntoView().run();
|
|
888
|
+
scrollEditorToPos(editor, pos);
|
|
851
889
|
};
|
|
852
890
|
refresh.addEventListener("click", onRefresh);
|
|
853
891
|
dom.addEventListener("click", onEntryClick);
|
|
@@ -2404,7 +2442,7 @@ var citationPlugin = (0, import_docflow_core17.definePlugin)({
|
|
|
2404
2442
|
|
|
2405
2443
|
// src/ai.ts
|
|
2406
2444
|
var import_core9 = require("@tiptap/core");
|
|
2407
|
-
var
|
|
2445
|
+
var import_state3 = require("@tiptap/pm/state");
|
|
2408
2446
|
var import_view = require("@tiptap/pm/view");
|
|
2409
2447
|
var import_tiptap_markdown = require("tiptap-markdown");
|
|
2410
2448
|
var import_docflow_core18 = require("@kedataindo/docflow-core");
|
|
@@ -2412,7 +2450,7 @@ var import_docflow_core18 = require("@kedataindo/docflow-core");
|
|
|
2412
2450
|
// src/markdownInsert.ts
|
|
2413
2451
|
var import_core8 = require("@tiptap/core");
|
|
2414
2452
|
var import_model = require("@tiptap/pm/model");
|
|
2415
|
-
var
|
|
2453
|
+
var import_state2 = require("@tiptap/pm/state");
|
|
2416
2454
|
var import_transform = require("@tiptap/pm/transform");
|
|
2417
2455
|
function mdParser(editor) {
|
|
2418
2456
|
const storage = editor.storage.markdown;
|
|
@@ -2448,7 +2486,7 @@ function selectionToInsertionEnd(tr, startLen, bias) {
|
|
|
2448
2486
|
map.forEach((_from, _to, _newFrom, newTo) => {
|
|
2449
2487
|
if (end === 0) end = newTo;
|
|
2450
2488
|
});
|
|
2451
|
-
tr.setSelection(
|
|
2489
|
+
tr.setSelection(import_state2.Selection.near(tr.doc.resolve(end), bias));
|
|
2452
2490
|
}
|
|
2453
2491
|
function insertMarkdownBlock(editor, view, from, to, markdown) {
|
|
2454
2492
|
const fragment = markdownToFragment(editor, markdown, { inline: false });
|
|
@@ -2491,7 +2529,7 @@ function insertMarkdownBlock(editor, view, from, to, markdown) {
|
|
|
2491
2529
|
}
|
|
2492
2530
|
|
|
2493
2531
|
// src/ai.ts
|
|
2494
|
-
var aiPluginKey = new
|
|
2532
|
+
var aiPluginKey = new import_state3.PluginKey("docflow-ai");
|
|
2495
2533
|
var CONTEXT_CHARS = 1500;
|
|
2496
2534
|
function getAIPreview(editor) {
|
|
2497
2535
|
return editor.storage.ai ? editor.storage.ai.preview ?? null : null;
|
|
@@ -2727,7 +2765,7 @@ var AIExtension = import_core9.Extension.create({
|
|
|
2727
2765
|
};
|
|
2728
2766
|
}
|
|
2729
2767
|
return [
|
|
2730
|
-
new
|
|
2768
|
+
new import_state3.Plugin({
|
|
2731
2769
|
key: aiPluginKey,
|
|
2732
2770
|
state: {
|
|
2733
2771
|
init: () => null,
|
|
@@ -2899,7 +2937,7 @@ var commentPlugin = {
|
|
|
2899
2937
|
|
|
2900
2938
|
// src/suggestChanges.ts
|
|
2901
2939
|
var import_core11 = require("@tiptap/core");
|
|
2902
|
-
var
|
|
2940
|
+
var import_state4 = require("@tiptap/pm/state");
|
|
2903
2941
|
var import_transform2 = require("@tiptap/pm/transform");
|
|
2904
2942
|
var import_docflow_core19 = require("@kedataindo/docflow-core");
|
|
2905
2943
|
var SUGGESTION_INSERT = "suggestionInsert";
|
|
@@ -2907,7 +2945,7 @@ var SUGGESTION_DELETE = "suggestionDelete";
|
|
|
2907
2945
|
var SUGGESTION_FORMAT = "suggestionFormat";
|
|
2908
2946
|
var FORMAT_MARKS = /* @__PURE__ */ new Set(["bold", "italic", "underline", "strike", "highlight"]);
|
|
2909
2947
|
var SUGGEST_APPLIED_META = "suggestChanges:applied";
|
|
2910
|
-
var suggestChangesKey = new
|
|
2948
|
+
var suggestChangesKey = new import_state4.PluginKey("suggestChanges");
|
|
2911
2949
|
var suggestionAttributes = () => ({
|
|
2912
2950
|
suggestionId: {
|
|
2913
2951
|
default: null,
|
|
@@ -3029,7 +3067,7 @@ var SuggestChanges = import_core11.Extension.create({
|
|
|
3029
3067
|
if (storage) storage.suggestions = getSuggestions(editor);
|
|
3030
3068
|
};
|
|
3031
3069
|
return [
|
|
3032
|
-
new
|
|
3070
|
+
new import_state4.Plugin({
|
|
3033
3071
|
key: suggestChangesKey,
|
|
3034
3072
|
state: {
|
|
3035
3073
|
init: () => ({ mode: "editing", author: {} }),
|
|
@@ -3117,7 +3155,7 @@ var SuggestChanges = import_core11.Extension.create({
|
|
|
3117
3155
|
const id = adjacentRunId(view.state, from, SUGGESTION_DELETE) ?? newSuggestionId();
|
|
3118
3156
|
const tr = view.state.tr.addMark(from, to, del.create(markAttrs(id, current.author)));
|
|
3119
3157
|
if (event.key === "Backspace" && selection.empty) {
|
|
3120
|
-
tr.setSelection(
|
|
3158
|
+
tr.setSelection(import_state4.TextSelection.create(tr.doc, from));
|
|
3121
3159
|
}
|
|
3122
3160
|
view.dispatch(tr);
|
|
3123
3161
|
return true;
|
|
@@ -3715,8 +3753,8 @@ var smartElementsPlugin = (0, import_docflow_core20.definePlugin)({
|
|
|
3715
3753
|
// src/tablePageSplit.ts
|
|
3716
3754
|
var import_docflow_core21 = require("@kedataindo/docflow-core");
|
|
3717
3755
|
var import_core13 = require("@tiptap/core");
|
|
3718
|
-
var
|
|
3719
|
-
var PLUGIN_KEY = new
|
|
3756
|
+
var import_state5 = require("@tiptap/pm/state");
|
|
3757
|
+
var PLUGIN_KEY = new import_state5.PluginKey("docflow/table-page-split");
|
|
3720
3758
|
var SPLIT_MARK = "head";
|
|
3721
3759
|
var MAX_SPLIT_DEPTH = 16;
|
|
3722
3760
|
function readPageContentHeightPx(view, editor) {
|
|
@@ -3891,6 +3929,7 @@ function runSplitPass(view, editor) {
|
|
|
3891
3929
|
tr.replaceWith(pos, pos + node.nodeSize, chain);
|
|
3892
3930
|
}
|
|
3893
3931
|
tr.setMeta(PLUGIN_KEY, { splitAtRow: -1 });
|
|
3932
|
+
tr.setMeta("addToHistory", false);
|
|
3894
3933
|
v.dispatch(tr);
|
|
3895
3934
|
}
|
|
3896
3935
|
var TablePageSplitExtension = import_core13.Extension.create({
|
|
@@ -3901,7 +3940,7 @@ var TablePageSplitExtension = import_core13.Extension.create({
|
|
|
3901
3940
|
const ext = this;
|
|
3902
3941
|
const editorRef = ext.editor ?? null;
|
|
3903
3942
|
return [
|
|
3904
|
-
new
|
|
3943
|
+
new import_state5.Plugin({
|
|
3905
3944
|
key: PLUGIN_KEY,
|
|
3906
3945
|
view(_editorView) {
|
|
3907
3946
|
viewRef = _editorView;
|
|
@@ -3940,7 +3979,7 @@ var tablePageSplitPlugin = (0, import_docflow_core21.definePlugin)({
|
|
|
3940
3979
|
|
|
3941
3980
|
// src/slashMenu.ts
|
|
3942
3981
|
var import_core14 = require("@tiptap/core");
|
|
3943
|
-
var
|
|
3982
|
+
var import_state6 = require("@tiptap/pm/state");
|
|
3944
3983
|
var import_docflow_core22 = require("@kedataindo/docflow-core");
|
|
3945
3984
|
var slashState = {
|
|
3946
3985
|
open: false,
|
|
@@ -3999,8 +4038,8 @@ var SlashMenuExtension = import_core14.Extension.create({
|
|
|
3999
4038
|
name: "slashMenu",
|
|
4000
4039
|
addProseMirrorPlugins() {
|
|
4001
4040
|
return [
|
|
4002
|
-
new
|
|
4003
|
-
key: new
|
|
4041
|
+
new import_state6.Plugin({
|
|
4042
|
+
key: new import_state6.PluginKey("slashMenu"),
|
|
4004
4043
|
props: {
|
|
4005
4044
|
handleTextInput(view, from, _to, text) {
|
|
4006
4045
|
if (text === "/") {
|
|
@@ -4186,6 +4225,7 @@ var defaultPlugins = [
|
|
|
4186
4225
|
rejectAllSuggestions,
|
|
4187
4226
|
rejectSuggestion,
|
|
4188
4227
|
sanitizeCiteprocHtml,
|
|
4228
|
+
scrollEditorToPos,
|
|
4189
4229
|
setDocumentMode,
|
|
4190
4230
|
setSuggestionAuthor,
|
|
4191
4231
|
slashMenuPlugin,
|
package/dist/index.d.cts
CHANGED
|
@@ -216,6 +216,26 @@ declare function markdownToFragment(editor: Editor, markdown: string, opts: {
|
|
|
216
216
|
*/
|
|
217
217
|
declare function insertMarkdownBlock(editor: Editor, view: EditorView, from: number, to: number, markdown: string): void;
|
|
218
218
|
|
|
219
|
+
/**
|
|
220
|
+
* Scroll the editor so document position `pos` is visible.
|
|
221
|
+
*
|
|
222
|
+
* Works with the paginated surface: the scrollable element is the
|
|
223
|
+
* `.docs-editor-scroll` wrapper (DocsEditor), NOT the window — a plain
|
|
224
|
+
* `scrollIntoView()` on the geo-point lands on the wrong page once
|
|
225
|
+
* PaginationPlus has cloned/offset the page frames. We resolve the target from
|
|
226
|
+
* `coordsAtPos` and move the container's scrollTop instead, which is correct in
|
|
227
|
+
* both paginated and pageless mode.
|
|
228
|
+
*
|
|
229
|
+
* Falls back to the native `scrollIntoView` on the editor element when there is
|
|
230
|
+
* no scroll container (bare editor / non-DOM environments such as tests).
|
|
231
|
+
*
|
|
232
|
+
* @param options.focus move the caret to `pos` (default true). Set false when
|
|
233
|
+
* the caller has already placed the selection.
|
|
234
|
+
*/
|
|
235
|
+
declare function scrollEditorToPos(editor: Editor, pos: number, options?: {
|
|
236
|
+
focus?: boolean;
|
|
237
|
+
}): void;
|
|
238
|
+
|
|
219
239
|
/**
|
|
220
240
|
* Phase 9 P9-4 — comment plugin.
|
|
221
241
|
*
|
|
@@ -360,4 +380,4 @@ declare const slashMenuPlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
|
|
|
360
380
|
|
|
361
381
|
declare const defaultPlugins: _kedata_indonesia_docflow_core.DocsEditorPlugin[];
|
|
362
382
|
|
|
363
|
-
export { AIExtension, type AIPreviewState, BibliographyNode, CitationEngineExtension, CitationNode, CiteEngine, type CommentMarkAttrs, CommentMark as CommentMarkExtension, DateChipNode, DropdownChipNode, FileChipNode, FootnoteNode, LocationChipNode, PageBreak, PeopleChipNode, type PlaceholderPluginOptions, SUGGESTION_DELETE, SUGGESTION_FORMAT, SUGGESTION_INSERT, SlashMenuExtension, type SuggestionAuthor, SuggestionDeleteMark, SuggestionFormatMark, SuggestionInsertMark, type SuggestionSummary, TocEntryNode, TocNode, TocPageNumNode, acceptAllSuggestions, acceptSuggestion, aiPlugin, aiPluginKey, alignmentPlugin, blockquotePlugin, citationPlugin, codeBlockPlugin, collectHeadings, commentPlugin, createPlaceholderPlugin, defaultPlugins, fontSizePlugin, footnotePlugin, formattingPlugin, getAIPreview, getCitationEngine, getSuggestions, headingsPlugin, highlightPlugin, imagePlugin, insertMarkdownBlock, linkPlugin, listsPlugin, markdownToFragment, onSlashStateChange, pageBreakPlugin, placeholderPlugin, regenerateToc, registerSlashCommands, rejectAllSuggestions, rejectSuggestion, setDocumentMode, setSuggestionAuthor, slashMenuPlugin, slashState, smartElementsPlugin, suggestChangesPlugin, tablePageSplitPlugin, tablePlugin, textColorPlugin, tocPlugin };
|
|
383
|
+
export { AIExtension, type AIPreviewState, BibliographyNode, CitationEngineExtension, CitationNode, CiteEngine, type CommentMarkAttrs, CommentMark as CommentMarkExtension, DateChipNode, DropdownChipNode, FileChipNode, FootnoteNode, LocationChipNode, PageBreak, PeopleChipNode, type PlaceholderPluginOptions, SUGGESTION_DELETE, SUGGESTION_FORMAT, SUGGESTION_INSERT, SlashMenuExtension, type SuggestionAuthor, SuggestionDeleteMark, SuggestionFormatMark, SuggestionInsertMark, type SuggestionSummary, TocEntryNode, TocNode, TocPageNumNode, acceptAllSuggestions, acceptSuggestion, aiPlugin, aiPluginKey, alignmentPlugin, blockquotePlugin, citationPlugin, codeBlockPlugin, collectHeadings, commentPlugin, createPlaceholderPlugin, defaultPlugins, fontSizePlugin, footnotePlugin, formattingPlugin, getAIPreview, getCitationEngine, getSuggestions, headingsPlugin, highlightPlugin, imagePlugin, insertMarkdownBlock, linkPlugin, listsPlugin, markdownToFragment, onSlashStateChange, pageBreakPlugin, placeholderPlugin, regenerateToc, registerSlashCommands, rejectAllSuggestions, rejectSuggestion, scrollEditorToPos, setDocumentMode, setSuggestionAuthor, slashMenuPlugin, slashState, smartElementsPlugin, suggestChangesPlugin, tablePageSplitPlugin, tablePlugin, textColorPlugin, tocPlugin };
|
package/dist/index.d.ts
CHANGED
|
@@ -216,6 +216,26 @@ declare function markdownToFragment(editor: Editor, markdown: string, opts: {
|
|
|
216
216
|
*/
|
|
217
217
|
declare function insertMarkdownBlock(editor: Editor, view: EditorView, from: number, to: number, markdown: string): void;
|
|
218
218
|
|
|
219
|
+
/**
|
|
220
|
+
* Scroll the editor so document position `pos` is visible.
|
|
221
|
+
*
|
|
222
|
+
* Works with the paginated surface: the scrollable element is the
|
|
223
|
+
* `.docs-editor-scroll` wrapper (DocsEditor), NOT the window — a plain
|
|
224
|
+
* `scrollIntoView()` on the geo-point lands on the wrong page once
|
|
225
|
+
* PaginationPlus has cloned/offset the page frames. We resolve the target from
|
|
226
|
+
* `coordsAtPos` and move the container's scrollTop instead, which is correct in
|
|
227
|
+
* both paginated and pageless mode.
|
|
228
|
+
*
|
|
229
|
+
* Falls back to the native `scrollIntoView` on the editor element when there is
|
|
230
|
+
* no scroll container (bare editor / non-DOM environments such as tests).
|
|
231
|
+
*
|
|
232
|
+
* @param options.focus move the caret to `pos` (default true). Set false when
|
|
233
|
+
* the caller has already placed the selection.
|
|
234
|
+
*/
|
|
235
|
+
declare function scrollEditorToPos(editor: Editor, pos: number, options?: {
|
|
236
|
+
focus?: boolean;
|
|
237
|
+
}): void;
|
|
238
|
+
|
|
219
239
|
/**
|
|
220
240
|
* Phase 9 P9-4 — comment plugin.
|
|
221
241
|
*
|
|
@@ -360,4 +380,4 @@ declare const slashMenuPlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
|
|
|
360
380
|
|
|
361
381
|
declare const defaultPlugins: _kedata_indonesia_docflow_core.DocsEditorPlugin[];
|
|
362
382
|
|
|
363
|
-
export { AIExtension, type AIPreviewState, BibliographyNode, CitationEngineExtension, CitationNode, CiteEngine, type CommentMarkAttrs, CommentMark as CommentMarkExtension, DateChipNode, DropdownChipNode, FileChipNode, FootnoteNode, LocationChipNode, PageBreak, PeopleChipNode, type PlaceholderPluginOptions, SUGGESTION_DELETE, SUGGESTION_FORMAT, SUGGESTION_INSERT, SlashMenuExtension, type SuggestionAuthor, SuggestionDeleteMark, SuggestionFormatMark, SuggestionInsertMark, type SuggestionSummary, TocEntryNode, TocNode, TocPageNumNode, acceptAllSuggestions, acceptSuggestion, aiPlugin, aiPluginKey, alignmentPlugin, blockquotePlugin, citationPlugin, codeBlockPlugin, collectHeadings, commentPlugin, createPlaceholderPlugin, defaultPlugins, fontSizePlugin, footnotePlugin, formattingPlugin, getAIPreview, getCitationEngine, getSuggestions, headingsPlugin, highlightPlugin, imagePlugin, insertMarkdownBlock, linkPlugin, listsPlugin, markdownToFragment, onSlashStateChange, pageBreakPlugin, placeholderPlugin, regenerateToc, registerSlashCommands, rejectAllSuggestions, rejectSuggestion, setDocumentMode, setSuggestionAuthor, slashMenuPlugin, slashState, smartElementsPlugin, suggestChangesPlugin, tablePageSplitPlugin, tablePlugin, textColorPlugin, tocPlugin };
|
|
383
|
+
export { AIExtension, type AIPreviewState, BibliographyNode, CitationEngineExtension, CitationNode, CiteEngine, type CommentMarkAttrs, CommentMark as CommentMarkExtension, DateChipNode, DropdownChipNode, FileChipNode, FootnoteNode, LocationChipNode, PageBreak, PeopleChipNode, type PlaceholderPluginOptions, SUGGESTION_DELETE, SUGGESTION_FORMAT, SUGGESTION_INSERT, SlashMenuExtension, type SuggestionAuthor, SuggestionDeleteMark, SuggestionFormatMark, SuggestionInsertMark, type SuggestionSummary, TocEntryNode, TocNode, TocPageNumNode, acceptAllSuggestions, acceptSuggestion, aiPlugin, aiPluginKey, alignmentPlugin, blockquotePlugin, citationPlugin, codeBlockPlugin, collectHeadings, commentPlugin, createPlaceholderPlugin, defaultPlugins, fontSizePlugin, footnotePlugin, formattingPlugin, getAIPreview, getCitationEngine, getSuggestions, headingsPlugin, highlightPlugin, imagePlugin, insertMarkdownBlock, linkPlugin, listsPlugin, markdownToFragment, onSlashStateChange, pageBreakPlugin, placeholderPlugin, regenerateToc, registerSlashCommands, rejectAllSuggestions, rejectSuggestion, scrollEditorToPos, setDocumentMode, setSuggestionAuthor, slashMenuPlugin, slashState, smartElementsPlugin, suggestChangesPlugin, tablePageSplitPlugin, tablePlugin, textColorPlugin, tocPlugin };
|
package/dist/index.js
CHANGED
|
@@ -532,6 +532,44 @@ var footnotePlugin = definePlugin12({
|
|
|
532
532
|
// src/toc.ts
|
|
533
533
|
import { Extension, Node as Node4, mergeAttributes as mergeAttributes4 } from "@tiptap/core";
|
|
534
534
|
import { definePlugin as definePlugin13 } from "@kedataindo/docflow-core";
|
|
535
|
+
|
|
536
|
+
// src/editorScroll.ts
|
|
537
|
+
import { TextSelection } from "@tiptap/pm/state";
|
|
538
|
+
function scrollEditorToPos(editor, pos, options = {}) {
|
|
539
|
+
const { state, view } = editor;
|
|
540
|
+
const clamped = Math.min(Math.max(0, pos), state.doc.content.size);
|
|
541
|
+
let anchor = clamped;
|
|
542
|
+
if (options.focus !== false) {
|
|
543
|
+
const selection = TextSelection.near(state.doc.resolve(clamped), 1);
|
|
544
|
+
if (!state.selection.eq(selection)) {
|
|
545
|
+
view.dispatch(state.tr.setSelection(selection));
|
|
546
|
+
}
|
|
547
|
+
editor.commands.focus();
|
|
548
|
+
anchor = view.state.selection.from;
|
|
549
|
+
}
|
|
550
|
+
const editorDom = view.dom;
|
|
551
|
+
const scrollEl = editorDom.closest?.(".docs-editor-scroll") ?? null;
|
|
552
|
+
let coords = null;
|
|
553
|
+
try {
|
|
554
|
+
coords = view.coordsAtPos(anchor);
|
|
555
|
+
} catch {
|
|
556
|
+
coords = null;
|
|
557
|
+
}
|
|
558
|
+
if (!scrollEl || !coords) {
|
|
559
|
+
editorDom.scrollIntoView?.({ block: "start" });
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
const scrollRect = scrollEl.getBoundingClientRect();
|
|
563
|
+
const top = scrollEl.scrollTop + (coords.top - scrollRect.top) - scrollEl.clientHeight / 3;
|
|
564
|
+
const target = Math.max(0, top);
|
|
565
|
+
try {
|
|
566
|
+
scrollEl.scrollTo({ top: target, behavior: "smooth" });
|
|
567
|
+
} catch {
|
|
568
|
+
scrollEl.scrollTop = target;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
// src/toc.ts
|
|
535
573
|
function collectHeadingsFromDoc(doc) {
|
|
536
574
|
const headings = [];
|
|
537
575
|
doc.descendants((node, pos) => {
|
|
@@ -739,8 +777,7 @@ var TocNode = Node4.create({
|
|
|
739
777
|
const entry = event.target?.closest?.("[data-toc-entry]");
|
|
740
778
|
if (!entry) return;
|
|
741
779
|
const pos = Number(entry.getAttribute("data-pos") ?? 0);
|
|
742
|
-
|
|
743
|
-
editor.chain().focus().setTextSelection(clamped).scrollIntoView().run();
|
|
780
|
+
scrollEditorToPos(editor, pos);
|
|
744
781
|
};
|
|
745
782
|
refresh.addEventListener("click", onRefresh);
|
|
746
783
|
dom.addEventListener("click", onEntryClick);
|
|
@@ -2792,7 +2829,7 @@ var commentPlugin = {
|
|
|
2792
2829
|
|
|
2793
2830
|
// src/suggestChanges.ts
|
|
2794
2831
|
import { Extension as Extension4, Mark as Mark2, mergeAttributes as mergeAttributes8 } from "@tiptap/core";
|
|
2795
|
-
import { Plugin as Plugin2, PluginKey as PluginKey2, TextSelection } from "@tiptap/pm/state";
|
|
2832
|
+
import { Plugin as Plugin2, PluginKey as PluginKey2, TextSelection as TextSelection2 } from "@tiptap/pm/state";
|
|
2796
2833
|
import { AddMarkStep, RemoveMarkStep } from "@tiptap/pm/transform";
|
|
2797
2834
|
import { definePlugin as definePlugin19 } from "@kedataindo/docflow-core";
|
|
2798
2835
|
var SUGGESTION_INSERT = "suggestionInsert";
|
|
@@ -3010,7 +3047,7 @@ var SuggestChanges = Extension4.create({
|
|
|
3010
3047
|
const id = adjacentRunId(view.state, from, SUGGESTION_DELETE) ?? newSuggestionId();
|
|
3011
3048
|
const tr = view.state.tr.addMark(from, to, del.create(markAttrs(id, current.author)));
|
|
3012
3049
|
if (event.key === "Backspace" && selection.empty) {
|
|
3013
|
-
tr.setSelection(
|
|
3050
|
+
tr.setSelection(TextSelection2.create(tr.doc, from));
|
|
3014
3051
|
}
|
|
3015
3052
|
view.dispatch(tr);
|
|
3016
3053
|
return true;
|
|
@@ -3784,6 +3821,7 @@ function runSplitPass(view, editor) {
|
|
|
3784
3821
|
tr.replaceWith(pos, pos + node.nodeSize, chain);
|
|
3785
3822
|
}
|
|
3786
3823
|
tr.setMeta(PLUGIN_KEY, { splitAtRow: -1 });
|
|
3824
|
+
tr.setMeta("addToHistory", false);
|
|
3787
3825
|
v.dispatch(tr);
|
|
3788
3826
|
}
|
|
3789
3827
|
var TablePageSplitExtension = Extension5.create({
|
|
@@ -4078,6 +4116,7 @@ export {
|
|
|
4078
4116
|
rejectAllSuggestions,
|
|
4079
4117
|
rejectSuggestion,
|
|
4080
4118
|
sanitizeCiteprocHtml,
|
|
4119
|
+
scrollEditorToPos,
|
|
4081
4120
|
setDocumentMode,
|
|
4082
4121
|
setSuggestionAuthor,
|
|
4083
4122
|
slashMenuPlugin,
|