@kedataindo/docflow-plugins 0.0.3

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 ADDED
@@ -0,0 +1,423 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ FontSizeExtension: () => import_docflow_core13.FontSizeExtension,
34
+ FootnoteNode: () => FootnoteNode,
35
+ PageBreak: () => PageBreak,
36
+ alignmentPlugin: () => alignmentPlugin,
37
+ blockquotePlugin: () => blockquotePlugin,
38
+ codeBlockPlugin: () => codeBlockPlugin,
39
+ createPlaceholderPlugin: () => createPlaceholderPlugin,
40
+ defaultPlugins: () => defaultPlugins,
41
+ fontSizePlugin: () => fontSizePlugin,
42
+ footnotePlugin: () => footnotePlugin,
43
+ formattingPlugin: () => formattingPlugin,
44
+ headingsPlugin: () => headingsPlugin,
45
+ imagePlugin: () => imagePlugin,
46
+ linkPlugin: () => linkPlugin,
47
+ listsPlugin: () => listsPlugin,
48
+ pageBreakPlugin: () => pageBreakPlugin,
49
+ placeholderPlugin: () => placeholderPlugin,
50
+ tablePlugin: () => tablePlugin
51
+ });
52
+ module.exports = __toCommonJS(index_exports);
53
+
54
+ // src/formatting.ts
55
+ var import_docflow_core = require("@kedata-indonesia/docflow-core");
56
+ var import_extension_underline = __toESM(require("@tiptap/extension-underline"), 1);
57
+ var formattingPlugin = (0, import_docflow_core.definePlugin)({
58
+ id: "formatting",
59
+ tiptapExtensions: [import_extension_underline.default],
60
+ toolbar: [
61
+ { id: "bold", label: "Bold", action: "toggleBold", iconComponent: "Bold" },
62
+ { id: "italic", label: "Italic", action: "toggleItalic", iconComponent: "Italic" },
63
+ { id: "underline", label: "Underline", action: "toggleUnderline", iconComponent: "Underline" },
64
+ { id: "strike", label: "Strikethrough", action: "toggleStrike", iconComponent: "Strikethrough" }
65
+ ]
66
+ });
67
+
68
+ // src/headings.ts
69
+ var import_docflow_core2 = require("@kedata-indonesia/docflow-core");
70
+ function toggleHeading(level) {
71
+ return (editor) => {
72
+ const commands = editor.commands;
73
+ return commands.toggleHeading({ level });
74
+ };
75
+ }
76
+ var headingsPlugin = (0, import_docflow_core2.definePlugin)({
77
+ id: "headings",
78
+ toolbar: [
79
+ { id: "heading-1", label: "Heading 1", action: "toggleHeading1", iconComponent: "Heading1" },
80
+ { id: "heading-2", label: "Heading 2", action: "toggleHeading2", iconComponent: "Heading2" },
81
+ { id: "heading-3", label: "Heading 3", action: "toggleHeading3", iconComponent: "Heading3" },
82
+ { id: "heading-4", label: "Heading 4", action: "toggleHeading4", iconComponent: "Heading4" },
83
+ { id: "heading-5", label: "Heading 5", action: "toggleHeading5", iconComponent: "Heading5" },
84
+ { id: "heading-6", label: "Heading 6", action: "toggleHeading6", iconComponent: "Heading6" }
85
+ ],
86
+ slashCommands: [
87
+ { name: "Heading 1", command: "toggleHeading1" },
88
+ { name: "Heading 2", command: "toggleHeading2" },
89
+ { name: "Heading 3", command: "toggleHeading3" }
90
+ ],
91
+ commands: {
92
+ toggleHeading1: toggleHeading(1),
93
+ toggleHeading2: toggleHeading(2),
94
+ toggleHeading3: toggleHeading(3),
95
+ toggleHeading4: toggleHeading(4),
96
+ toggleHeading5: toggleHeading(5),
97
+ toggleHeading6: toggleHeading(6)
98
+ }
99
+ });
100
+
101
+ // src/lists.ts
102
+ var import_docflow_core3 = require("@kedata-indonesia/docflow-core");
103
+ var import_extension_task_list = __toESM(require("@tiptap/extension-task-list"), 1);
104
+ var import_extension_task_item = __toESM(require("@tiptap/extension-task-item"), 1);
105
+ var listsPlugin = (0, import_docflow_core3.definePlugin)({
106
+ id: "lists",
107
+ tiptapExtensions: [import_extension_task_list.default, import_extension_task_item.default.configure({ nested: true })],
108
+ toolbar: [
109
+ { id: "bullet-list", label: "Bullet List", action: "toggleBulletList", iconComponent: "List" },
110
+ { id: "ordered-list", label: "Ordered List", action: "toggleOrderedList", iconComponent: "ListOrdered" },
111
+ { id: "task-list", label: "Task List", action: "toggleTaskList", iconComponent: "CheckSquare" }
112
+ ],
113
+ slashCommands: [
114
+ { name: "Bullet List", command: "toggleBulletList" },
115
+ { name: "Ordered List", command: "toggleOrderedList" },
116
+ { name: "Task List", command: "toggleTaskList" }
117
+ ]
118
+ });
119
+
120
+ // src/alignment.ts
121
+ var import_docflow_core4 = require("@kedata-indonesia/docflow-core");
122
+ var import_extension_text_align = __toESM(require("@tiptap/extension-text-align"), 1);
123
+ function setAlign(alignment) {
124
+ return (editor) => editor.commands.setTextAlign(alignment);
125
+ }
126
+ var alignmentPlugin = (0, import_docflow_core4.definePlugin)({
127
+ id: "alignment",
128
+ tiptapExtensions: [
129
+ import_extension_text_align.default.configure({ types: ["heading", "paragraph"] })
130
+ ],
131
+ toolbar: [
132
+ { id: "align-left", label: "Align Left", action: "alignLeft", iconComponent: "AlignLeft" },
133
+ { id: "align-center", label: "Align Center", action: "alignCenter", iconComponent: "AlignCenter" },
134
+ { id: "align-right", label: "Align Right", action: "alignRight", iconComponent: "AlignRight" },
135
+ { id: "align-justify", label: "Align Justify", action: "alignJustify", iconComponent: "AlignJustify" }
136
+ ],
137
+ commands: {
138
+ alignLeft: setAlign("left"),
139
+ alignCenter: setAlign("center"),
140
+ alignRight: setAlign("right"),
141
+ alignJustify: setAlign("justify")
142
+ }
143
+ });
144
+
145
+ // src/link.ts
146
+ var import_docflow_core5 = require("@kedata-indonesia/docflow-core");
147
+ var import_extension_link = __toESM(require("@tiptap/extension-link"), 1);
148
+ var linkPlugin = (0, import_docflow_core5.definePlugin)({
149
+ id: "link",
150
+ tiptapExtensions: [import_extension_link.default.configure({ openOnClick: false })],
151
+ toolbar: [
152
+ { id: "set-link", label: "Link", action: "setLink", iconComponent: "Link" }
153
+ ],
154
+ slashCommands: [{ name: "Link", command: "setLink" }],
155
+ commands: {
156
+ setLink: (editor, ...args) => {
157
+ if (editor.isActive("link")) {
158
+ return editor.chain().focus().unsetLink().run();
159
+ }
160
+ const attrs = args[0];
161
+ const url = attrs?.href ?? (typeof window !== "undefined" && typeof window.prompt === "function" ? window.prompt("Enter link URL:", "https://") : null);
162
+ if (url) {
163
+ return editor.chain().focus().setLink({ href: url, target: "_blank" }).run();
164
+ }
165
+ return false;
166
+ }
167
+ }
168
+ });
169
+
170
+ // src/image.ts
171
+ var import_docflow_core6 = require("@kedata-indonesia/docflow-core");
172
+ var import_extension_image = __toESM(require("@tiptap/extension-image"), 1);
173
+ var DEFAULT_IMAGE_SRC = "https://via.placeholder.com/300x200";
174
+ var imagePlugin = (0, import_docflow_core6.definePlugin)({
175
+ id: "image",
176
+ tiptapExtensions: [import_extension_image.default],
177
+ toolbar: [{ id: "insert-image", label: "Image", action: "insertImage", iconComponent: "Image" }],
178
+ slashCommands: [{ name: "Image", command: "insertImage" }],
179
+ commands: {
180
+ insertImage: (editor, ...args) => {
181
+ const options = args[0];
182
+ const src = options?.src ?? (typeof window !== "undefined" && typeof window.prompt === "function" ? window.prompt("Enter image URL:", "https://") : null) ?? DEFAULT_IMAGE_SRC;
183
+ if (!src) return false;
184
+ return editor.commands.setImage({ src });
185
+ }
186
+ }
187
+ });
188
+
189
+ // src/table.ts
190
+ var import_docflow_core7 = require("@kedata-indonesia/docflow-core");
191
+ var import_extension_table = __toESM(require("@tiptap/extension-table"), 1);
192
+ var import_extension_table_row = __toESM(require("@tiptap/extension-table-row"), 1);
193
+ var import_extension_table_cell = __toESM(require("@tiptap/extension-table-cell"), 1);
194
+ var import_extension_table_header = __toESM(require("@tiptap/extension-table-header"), 1);
195
+ var tablePlugin = (0, import_docflow_core7.definePlugin)({
196
+ id: "table",
197
+ tiptapExtensions: [
198
+ import_extension_table.default.configure({ resizable: true }),
199
+ import_extension_table_row.default,
200
+ import_extension_table_cell.default,
201
+ import_extension_table_header.default
202
+ ],
203
+ toolbar: [
204
+ { id: "insert-table", label: "Insert Table", action: "insertTable", args: [{ rows: 3, cols: 3, withHeaderRow: true }], iconComponent: "Table" }
205
+ ],
206
+ slashCommands: [{ name: "Table", command: "insertTable" }]
207
+ });
208
+
209
+ // src/blockquote.ts
210
+ var import_docflow_core8 = require("@kedata-indonesia/docflow-core");
211
+ var blockquotePlugin = (0, import_docflow_core8.definePlugin)({
212
+ id: "blockquote",
213
+ toolbar: [{ id: "blockquote", label: "Blockquote", action: "toggleBlockquote", iconComponent: "Quote" }],
214
+ slashCommands: [{ name: "Blockquote", command: "toggleBlockquote" }]
215
+ });
216
+
217
+ // src/codeBlock.ts
218
+ var import_docflow_core9 = require("@kedata-indonesia/docflow-core");
219
+ var codeBlockPlugin = (0, import_docflow_core9.definePlugin)({
220
+ id: "code-block",
221
+ toolbar: [{ id: "code-block", label: "Code Block", action: "toggleCodeBlock", iconComponent: "Code" }],
222
+ slashCommands: [{ name: "Code Block", command: "toggleCodeBlock" }]
223
+ });
224
+
225
+ // src/placeholder.ts
226
+ var import_docflow_core10 = require("@kedata-indonesia/docflow-core");
227
+ var import_extension_placeholder = __toESM(require("@tiptap/extension-placeholder"), 1);
228
+ function createPlaceholderPlugin(options = {}) {
229
+ return (0, import_docflow_core10.definePlugin)({
230
+ id: "placeholder",
231
+ tiptapExtensions: [
232
+ import_extension_placeholder.default.configure({
233
+ placeholder: options.placeholder ?? "Start writing\u2026"
234
+ })
235
+ ]
236
+ });
237
+ }
238
+ var placeholderPlugin = createPlaceholderPlugin();
239
+
240
+ // src/pageBreak.ts
241
+ var import_core = require("@tiptap/core");
242
+ var import_docflow_core11 = require("@kedata-indonesia/docflow-core");
243
+ var PageBreak = import_core.Node.create({
244
+ name: "pageBreak",
245
+ group: "block",
246
+ selectable: false,
247
+ draggable: false,
248
+ parseHTML() {
249
+ return [{ tag: 'div[data-page-break="true"]' }];
250
+ },
251
+ renderHTML({ HTMLAttributes }) {
252
+ return [
253
+ "div",
254
+ (0, import_core.mergeAttributes)(HTMLAttributes, {
255
+ "data-page-break": "true",
256
+ "data-node-type": "pageBreak",
257
+ class: "docs-editor-page-break"
258
+ }),
259
+ ["span", { class: "docs-editor-page-break__label" }, "Page break"]
260
+ ];
261
+ },
262
+ addNodeView() {
263
+ return () => {
264
+ const dom = document.createElement("div");
265
+ dom.className = "docs-editor-page-break";
266
+ dom.setAttribute("data-page-break", "true");
267
+ dom.setAttribute("data-node-type", "pageBreak");
268
+ dom.setAttribute("contenteditable", "false");
269
+ const inner = document.createElement("div");
270
+ inner.className = "docs-editor-page-break__inner";
271
+ const line = document.createElement("div");
272
+ line.className = "docs-editor-page-break__line";
273
+ const label = document.createElement("span");
274
+ label.className = "docs-editor-page-break__label-text";
275
+ label.textContent = "Page break";
276
+ inner.appendChild(line);
277
+ inner.appendChild(label);
278
+ dom.appendChild(inner);
279
+ return {
280
+ dom,
281
+ contentDOM: void 0
282
+ };
283
+ };
284
+ }
285
+ });
286
+ var pageBreakPlugin = (0, import_docflow_core11.definePlugin)({
287
+ id: "pageBreak",
288
+ tiptapExtensions: [PageBreak],
289
+ toolbar: [
290
+ { id: "insert-page-break", label: "Page Break", action: "insertPageBreak", iconComponent: "FileText" }
291
+ ],
292
+ slashCommands: [{ name: "Page Break", command: "insertPageBreak" }],
293
+ commands: {
294
+ insertPageBreak: (editor) => editor.chain().focus().insertContent({ type: "pageBreak" }).run()
295
+ }
296
+ });
297
+
298
+ // src/footnote.ts
299
+ var import_core2 = require("@tiptap/core");
300
+ var import_docflow_core12 = require("@kedata-indonesia/docflow-core");
301
+ var FootnoteNode = import_core2.Node.create({
302
+ name: "footnote",
303
+ group: "inline",
304
+ inline: true,
305
+ selectable: true,
306
+ draggable: false,
307
+ atom: true,
308
+ addAttributes() {
309
+ return {
310
+ content: {
311
+ default: "",
312
+ parseHTML: (el) => el.getAttribute("data-footnote-content") ?? "",
313
+ renderHTML: (attrs) => ({ "data-footnote-content": attrs.content })
314
+ }
315
+ };
316
+ },
317
+ parseHTML() {
318
+ return [{ tag: 'span[data-node-type="footnote"]' }];
319
+ },
320
+ renderHTML({ HTMLAttributes }) {
321
+ return ["span", (0, import_core2.mergeAttributes)(HTMLAttributes, {
322
+ "data-node-type": "footnote",
323
+ class: "docs-footnote-ref"
324
+ }), "1"];
325
+ },
326
+ // Return type cast to `any` to bypass TipTap's strict NodeViewRenderer typing.
327
+ // At runtime this returns a valid ProseMirror NodeView { dom, update }.
328
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
329
+ addNodeView() {
330
+ return (props) => {
331
+ const node = props.node ?? props;
332
+ const attrs = node && typeof node === "object" && "attrs" in node ? node.attrs : {};
333
+ const dom = document.createElement("span");
334
+ dom.className = "docs-footnote-ref";
335
+ dom.setAttribute("data-node-type", "footnote");
336
+ dom.setAttribute("data-footnote-content", String(attrs.content ?? ""));
337
+ dom.textContent = "1";
338
+ return {
339
+ dom,
340
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
341
+ update(updatedNode) {
342
+ try {
343
+ const updatedAttrs = updatedNode?.attrs ?? {};
344
+ dom.setAttribute("data-footnote-content", String(updatedAttrs.content ?? ""));
345
+ } catch {
346
+ }
347
+ return true;
348
+ }
349
+ };
350
+ };
351
+ }
352
+ });
353
+ var footnotePlugin = (0, import_docflow_core12.definePlugin)({
354
+ id: "footnote",
355
+ tiptapExtensions: [FootnoteNode],
356
+ toolbar: [
357
+ { id: "insert-footnote", label: "Catatan Kaki", action: "insertFootnote", iconComponent: "FileText" }
358
+ ],
359
+ slashCommands: [{ name: "Catatan Kaki", command: "insertFootnote" }],
360
+ commands: {
361
+ insertFootnote: (editor, ...args) => {
362
+ const attrs = args[0];
363
+ return editor.chain().focus().insertContent({ type: "footnote", attrs: { content: attrs?.content ?? "" } }).run();
364
+ }
365
+ }
366
+ });
367
+
368
+ // src/fontSize.ts
369
+ var import_docflow_core13 = require("@kedata-indonesia/docflow-core");
370
+ var fontSizePlugin = (0, import_docflow_core13.definePlugin)({
371
+ id: "font-size",
372
+ tiptapExtensions: [import_docflow_core13.FontSizeExtension],
373
+ commands: {
374
+ setFontSize: (editor, ...args) => {
375
+ const size = args[0] || "16px";
376
+ if (size === "16px") {
377
+ editor.commands.unsetFontSize();
378
+ } else {
379
+ editor.commands.setFontSize(size);
380
+ }
381
+ editor.commands.focus();
382
+ return true;
383
+ }
384
+ }
385
+ });
386
+
387
+ // src/index.ts
388
+ var defaultPlugins = [
389
+ formattingPlugin,
390
+ headingsPlugin,
391
+ listsPlugin,
392
+ alignmentPlugin,
393
+ linkPlugin,
394
+ imagePlugin,
395
+ tablePlugin,
396
+ blockquotePlugin,
397
+ codeBlockPlugin,
398
+ placeholderPlugin,
399
+ pageBreakPlugin,
400
+ footnotePlugin,
401
+ fontSizePlugin
402
+ ];
403
+ // Annotate the CommonJS export names for ESM import in node:
404
+ 0 && (module.exports = {
405
+ FontSizeExtension,
406
+ FootnoteNode,
407
+ PageBreak,
408
+ alignmentPlugin,
409
+ blockquotePlugin,
410
+ codeBlockPlugin,
411
+ createPlaceholderPlugin,
412
+ defaultPlugins,
413
+ fontSizePlugin,
414
+ footnotePlugin,
415
+ formattingPlugin,
416
+ headingsPlugin,
417
+ imagePlugin,
418
+ linkPlugin,
419
+ listsPlugin,
420
+ pageBreakPlugin,
421
+ placeholderPlugin,
422
+ tablePlugin
423
+ });
@@ -0,0 +1,47 @@
1
+ import * as _kedata_indonesia_docflow_core from '@kedata-indonesia/docflow-core';
2
+ export { DocsEditorPlugin, FontSizeExtension, SlashCommand, ToolbarItem } from '@kedata-indonesia/docflow-core';
3
+ import { Node } from '@tiptap/core';
4
+
5
+ declare const formattingPlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
6
+
7
+ declare const headingsPlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
8
+
9
+ declare const listsPlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
10
+
11
+ declare const alignmentPlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
12
+
13
+ declare const linkPlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
14
+
15
+ declare const imagePlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
16
+
17
+ declare const tablePlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
18
+
19
+ declare const blockquotePlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
20
+
21
+ declare const codeBlockPlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
22
+
23
+ interface PlaceholderPluginOptions {
24
+ placeholder?: string;
25
+ }
26
+ declare function createPlaceholderPlugin(options?: PlaceholderPluginOptions): _kedata_indonesia_docflow_core.DocsEditorPlugin;
27
+ declare const placeholderPlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
28
+
29
+ declare const PageBreak: Node<any, any>;
30
+ declare const pageBreakPlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
31
+
32
+ declare const FootnoteNode: Node<any, any>;
33
+ declare const footnotePlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
34
+
35
+ /**
36
+ * fontSizePlugin — provides the `setFontSize` command action for toolbar use.
37
+ *
38
+ * Registers FontSizeExtension (fontSize attribute on TextStyle mark) via
39
+ * tiptapExtensions so it is only added ONCE through the plugin system.
40
+ * Previously it was hardcoded in Editor.ts which, combined with Vite
41
+ * module alias duplication, caused "Duplicate extension names" warnings.
42
+ */
43
+ declare const fontSizePlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
44
+
45
+ declare const defaultPlugins: _kedata_indonesia_docflow_core.DocsEditorPlugin[];
46
+
47
+ export { FootnoteNode, PageBreak, type PlaceholderPluginOptions, alignmentPlugin, blockquotePlugin, codeBlockPlugin, createPlaceholderPlugin, defaultPlugins, fontSizePlugin, footnotePlugin, formattingPlugin, headingsPlugin, imagePlugin, linkPlugin, listsPlugin, pageBreakPlugin, placeholderPlugin, tablePlugin };
@@ -0,0 +1,47 @@
1
+ import * as _kedata_indonesia_docflow_core from '@kedata-indonesia/docflow-core';
2
+ export { DocsEditorPlugin, FontSizeExtension, SlashCommand, ToolbarItem } from '@kedata-indonesia/docflow-core';
3
+ import { Node } from '@tiptap/core';
4
+
5
+ declare const formattingPlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
6
+
7
+ declare const headingsPlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
8
+
9
+ declare const listsPlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
10
+
11
+ declare const alignmentPlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
12
+
13
+ declare const linkPlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
14
+
15
+ declare const imagePlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
16
+
17
+ declare const tablePlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
18
+
19
+ declare const blockquotePlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
20
+
21
+ declare const codeBlockPlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
22
+
23
+ interface PlaceholderPluginOptions {
24
+ placeholder?: string;
25
+ }
26
+ declare function createPlaceholderPlugin(options?: PlaceholderPluginOptions): _kedata_indonesia_docflow_core.DocsEditorPlugin;
27
+ declare const placeholderPlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
28
+
29
+ declare const PageBreak: Node<any, any>;
30
+ declare const pageBreakPlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
31
+
32
+ declare const FootnoteNode: Node<any, any>;
33
+ declare const footnotePlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
34
+
35
+ /**
36
+ * fontSizePlugin — provides the `setFontSize` command action for toolbar use.
37
+ *
38
+ * Registers FontSizeExtension (fontSize attribute on TextStyle mark) via
39
+ * tiptapExtensions so it is only added ONCE through the plugin system.
40
+ * Previously it was hardcoded in Editor.ts which, combined with Vite
41
+ * module alias duplication, caused "Duplicate extension names" warnings.
42
+ */
43
+ declare const fontSizePlugin: _kedata_indonesia_docflow_core.DocsEditorPlugin;
44
+
45
+ declare const defaultPlugins: _kedata_indonesia_docflow_core.DocsEditorPlugin[];
46
+
47
+ export { FootnoteNode, PageBreak, type PlaceholderPluginOptions, alignmentPlugin, blockquotePlugin, codeBlockPlugin, createPlaceholderPlugin, defaultPlugins, fontSizePlugin, footnotePlugin, formattingPlugin, headingsPlugin, imagePlugin, linkPlugin, listsPlugin, pageBreakPlugin, placeholderPlugin, tablePlugin };
package/dist/index.js ADDED
@@ -0,0 +1,369 @@
1
+ // src/formatting.ts
2
+ import { definePlugin } from "@kedata-indonesia/docflow-core";
3
+ import Underline from "@tiptap/extension-underline";
4
+ var formattingPlugin = definePlugin({
5
+ id: "formatting",
6
+ tiptapExtensions: [Underline],
7
+ toolbar: [
8
+ { id: "bold", label: "Bold", action: "toggleBold", iconComponent: "Bold" },
9
+ { id: "italic", label: "Italic", action: "toggleItalic", iconComponent: "Italic" },
10
+ { id: "underline", label: "Underline", action: "toggleUnderline", iconComponent: "Underline" },
11
+ { id: "strike", label: "Strikethrough", action: "toggleStrike", iconComponent: "Strikethrough" }
12
+ ]
13
+ });
14
+
15
+ // src/headings.ts
16
+ import { definePlugin as definePlugin2 } from "@kedata-indonesia/docflow-core";
17
+ function toggleHeading(level) {
18
+ return (editor) => {
19
+ const commands = editor.commands;
20
+ return commands.toggleHeading({ level });
21
+ };
22
+ }
23
+ var headingsPlugin = definePlugin2({
24
+ id: "headings",
25
+ toolbar: [
26
+ { id: "heading-1", label: "Heading 1", action: "toggleHeading1", iconComponent: "Heading1" },
27
+ { id: "heading-2", label: "Heading 2", action: "toggleHeading2", iconComponent: "Heading2" },
28
+ { id: "heading-3", label: "Heading 3", action: "toggleHeading3", iconComponent: "Heading3" },
29
+ { id: "heading-4", label: "Heading 4", action: "toggleHeading4", iconComponent: "Heading4" },
30
+ { id: "heading-5", label: "Heading 5", action: "toggleHeading5", iconComponent: "Heading5" },
31
+ { id: "heading-6", label: "Heading 6", action: "toggleHeading6", iconComponent: "Heading6" }
32
+ ],
33
+ slashCommands: [
34
+ { name: "Heading 1", command: "toggleHeading1" },
35
+ { name: "Heading 2", command: "toggleHeading2" },
36
+ { name: "Heading 3", command: "toggleHeading3" }
37
+ ],
38
+ commands: {
39
+ toggleHeading1: toggleHeading(1),
40
+ toggleHeading2: toggleHeading(2),
41
+ toggleHeading3: toggleHeading(3),
42
+ toggleHeading4: toggleHeading(4),
43
+ toggleHeading5: toggleHeading(5),
44
+ toggleHeading6: toggleHeading(6)
45
+ }
46
+ });
47
+
48
+ // src/lists.ts
49
+ import { definePlugin as definePlugin3 } from "@kedata-indonesia/docflow-core";
50
+ import TaskList from "@tiptap/extension-task-list";
51
+ import TaskItem from "@tiptap/extension-task-item";
52
+ var listsPlugin = definePlugin3({
53
+ id: "lists",
54
+ tiptapExtensions: [TaskList, TaskItem.configure({ nested: true })],
55
+ toolbar: [
56
+ { id: "bullet-list", label: "Bullet List", action: "toggleBulletList", iconComponent: "List" },
57
+ { id: "ordered-list", label: "Ordered List", action: "toggleOrderedList", iconComponent: "ListOrdered" },
58
+ { id: "task-list", label: "Task List", action: "toggleTaskList", iconComponent: "CheckSquare" }
59
+ ],
60
+ slashCommands: [
61
+ { name: "Bullet List", command: "toggleBulletList" },
62
+ { name: "Ordered List", command: "toggleOrderedList" },
63
+ { name: "Task List", command: "toggleTaskList" }
64
+ ]
65
+ });
66
+
67
+ // src/alignment.ts
68
+ import { definePlugin as definePlugin4 } from "@kedata-indonesia/docflow-core";
69
+ import TextAlign from "@tiptap/extension-text-align";
70
+ function setAlign(alignment) {
71
+ return (editor) => editor.commands.setTextAlign(alignment);
72
+ }
73
+ var alignmentPlugin = definePlugin4({
74
+ id: "alignment",
75
+ tiptapExtensions: [
76
+ TextAlign.configure({ types: ["heading", "paragraph"] })
77
+ ],
78
+ toolbar: [
79
+ { id: "align-left", label: "Align Left", action: "alignLeft", iconComponent: "AlignLeft" },
80
+ { id: "align-center", label: "Align Center", action: "alignCenter", iconComponent: "AlignCenter" },
81
+ { id: "align-right", label: "Align Right", action: "alignRight", iconComponent: "AlignRight" },
82
+ { id: "align-justify", label: "Align Justify", action: "alignJustify", iconComponent: "AlignJustify" }
83
+ ],
84
+ commands: {
85
+ alignLeft: setAlign("left"),
86
+ alignCenter: setAlign("center"),
87
+ alignRight: setAlign("right"),
88
+ alignJustify: setAlign("justify")
89
+ }
90
+ });
91
+
92
+ // src/link.ts
93
+ import { definePlugin as definePlugin5 } from "@kedata-indonesia/docflow-core";
94
+ import Link from "@tiptap/extension-link";
95
+ var linkPlugin = definePlugin5({
96
+ id: "link",
97
+ tiptapExtensions: [Link.configure({ openOnClick: false })],
98
+ toolbar: [
99
+ { id: "set-link", label: "Link", action: "setLink", iconComponent: "Link" }
100
+ ],
101
+ slashCommands: [{ name: "Link", command: "setLink" }],
102
+ commands: {
103
+ setLink: (editor, ...args) => {
104
+ if (editor.isActive("link")) {
105
+ return editor.chain().focus().unsetLink().run();
106
+ }
107
+ const attrs = args[0];
108
+ const url = attrs?.href ?? (typeof window !== "undefined" && typeof window.prompt === "function" ? window.prompt("Enter link URL:", "https://") : null);
109
+ if (url) {
110
+ return editor.chain().focus().setLink({ href: url, target: "_blank" }).run();
111
+ }
112
+ return false;
113
+ }
114
+ }
115
+ });
116
+
117
+ // src/image.ts
118
+ import { definePlugin as definePlugin6 } from "@kedata-indonesia/docflow-core";
119
+ import Image from "@tiptap/extension-image";
120
+ var DEFAULT_IMAGE_SRC = "https://via.placeholder.com/300x200";
121
+ var imagePlugin = definePlugin6({
122
+ id: "image",
123
+ tiptapExtensions: [Image],
124
+ toolbar: [{ id: "insert-image", label: "Image", action: "insertImage", iconComponent: "Image" }],
125
+ slashCommands: [{ name: "Image", command: "insertImage" }],
126
+ commands: {
127
+ insertImage: (editor, ...args) => {
128
+ const options = args[0];
129
+ const src = options?.src ?? (typeof window !== "undefined" && typeof window.prompt === "function" ? window.prompt("Enter image URL:", "https://") : null) ?? DEFAULT_IMAGE_SRC;
130
+ if (!src) return false;
131
+ return editor.commands.setImage({ src });
132
+ }
133
+ }
134
+ });
135
+
136
+ // src/table.ts
137
+ import { definePlugin as definePlugin7 } from "@kedata-indonesia/docflow-core";
138
+ import Table from "@tiptap/extension-table";
139
+ import TableRow from "@tiptap/extension-table-row";
140
+ import TableCell from "@tiptap/extension-table-cell";
141
+ import TableHeader from "@tiptap/extension-table-header";
142
+ var tablePlugin = definePlugin7({
143
+ id: "table",
144
+ tiptapExtensions: [
145
+ Table.configure({ resizable: true }),
146
+ TableRow,
147
+ TableCell,
148
+ TableHeader
149
+ ],
150
+ toolbar: [
151
+ { id: "insert-table", label: "Insert Table", action: "insertTable", args: [{ rows: 3, cols: 3, withHeaderRow: true }], iconComponent: "Table" }
152
+ ],
153
+ slashCommands: [{ name: "Table", command: "insertTable" }]
154
+ });
155
+
156
+ // src/blockquote.ts
157
+ import { definePlugin as definePlugin8 } from "@kedata-indonesia/docflow-core";
158
+ var blockquotePlugin = definePlugin8({
159
+ id: "blockquote",
160
+ toolbar: [{ id: "blockquote", label: "Blockquote", action: "toggleBlockquote", iconComponent: "Quote" }],
161
+ slashCommands: [{ name: "Blockquote", command: "toggleBlockquote" }]
162
+ });
163
+
164
+ // src/codeBlock.ts
165
+ import { definePlugin as definePlugin9 } from "@kedata-indonesia/docflow-core";
166
+ var codeBlockPlugin = definePlugin9({
167
+ id: "code-block",
168
+ toolbar: [{ id: "code-block", label: "Code Block", action: "toggleCodeBlock", iconComponent: "Code" }],
169
+ slashCommands: [{ name: "Code Block", command: "toggleCodeBlock" }]
170
+ });
171
+
172
+ // src/placeholder.ts
173
+ import { definePlugin as definePlugin10 } from "@kedata-indonesia/docflow-core";
174
+ import Placeholder from "@tiptap/extension-placeholder";
175
+ function createPlaceholderPlugin(options = {}) {
176
+ return definePlugin10({
177
+ id: "placeholder",
178
+ tiptapExtensions: [
179
+ Placeholder.configure({
180
+ placeholder: options.placeholder ?? "Start writing\u2026"
181
+ })
182
+ ]
183
+ });
184
+ }
185
+ var placeholderPlugin = createPlaceholderPlugin();
186
+
187
+ // src/pageBreak.ts
188
+ import { Node, mergeAttributes } from "@tiptap/core";
189
+ import { definePlugin as definePlugin11 } from "@kedata-indonesia/docflow-core";
190
+ var PageBreak = Node.create({
191
+ name: "pageBreak",
192
+ group: "block",
193
+ selectable: false,
194
+ draggable: false,
195
+ parseHTML() {
196
+ return [{ tag: 'div[data-page-break="true"]' }];
197
+ },
198
+ renderHTML({ HTMLAttributes }) {
199
+ return [
200
+ "div",
201
+ mergeAttributes(HTMLAttributes, {
202
+ "data-page-break": "true",
203
+ "data-node-type": "pageBreak",
204
+ class: "docs-editor-page-break"
205
+ }),
206
+ ["span", { class: "docs-editor-page-break__label" }, "Page break"]
207
+ ];
208
+ },
209
+ addNodeView() {
210
+ return () => {
211
+ const dom = document.createElement("div");
212
+ dom.className = "docs-editor-page-break";
213
+ dom.setAttribute("data-page-break", "true");
214
+ dom.setAttribute("data-node-type", "pageBreak");
215
+ dom.setAttribute("contenteditable", "false");
216
+ const inner = document.createElement("div");
217
+ inner.className = "docs-editor-page-break__inner";
218
+ const line = document.createElement("div");
219
+ line.className = "docs-editor-page-break__line";
220
+ const label = document.createElement("span");
221
+ label.className = "docs-editor-page-break__label-text";
222
+ label.textContent = "Page break";
223
+ inner.appendChild(line);
224
+ inner.appendChild(label);
225
+ dom.appendChild(inner);
226
+ return {
227
+ dom,
228
+ contentDOM: void 0
229
+ };
230
+ };
231
+ }
232
+ });
233
+ var pageBreakPlugin = definePlugin11({
234
+ id: "pageBreak",
235
+ tiptapExtensions: [PageBreak],
236
+ toolbar: [
237
+ { id: "insert-page-break", label: "Page Break", action: "insertPageBreak", iconComponent: "FileText" }
238
+ ],
239
+ slashCommands: [{ name: "Page Break", command: "insertPageBreak" }],
240
+ commands: {
241
+ insertPageBreak: (editor) => editor.chain().focus().insertContent({ type: "pageBreak" }).run()
242
+ }
243
+ });
244
+
245
+ // src/footnote.ts
246
+ import { Node as Node2, mergeAttributes as mergeAttributes2 } from "@tiptap/core";
247
+ import { definePlugin as definePlugin12 } from "@kedata-indonesia/docflow-core";
248
+ var FootnoteNode = Node2.create({
249
+ name: "footnote",
250
+ group: "inline",
251
+ inline: true,
252
+ selectable: true,
253
+ draggable: false,
254
+ atom: true,
255
+ addAttributes() {
256
+ return {
257
+ content: {
258
+ default: "",
259
+ parseHTML: (el) => el.getAttribute("data-footnote-content") ?? "",
260
+ renderHTML: (attrs) => ({ "data-footnote-content": attrs.content })
261
+ }
262
+ };
263
+ },
264
+ parseHTML() {
265
+ return [{ tag: 'span[data-node-type="footnote"]' }];
266
+ },
267
+ renderHTML({ HTMLAttributes }) {
268
+ return ["span", mergeAttributes2(HTMLAttributes, {
269
+ "data-node-type": "footnote",
270
+ class: "docs-footnote-ref"
271
+ }), "1"];
272
+ },
273
+ // Return type cast to `any` to bypass TipTap's strict NodeViewRenderer typing.
274
+ // At runtime this returns a valid ProseMirror NodeView { dom, update }.
275
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
276
+ addNodeView() {
277
+ return (props) => {
278
+ const node = props.node ?? props;
279
+ const attrs = node && typeof node === "object" && "attrs" in node ? node.attrs : {};
280
+ const dom = document.createElement("span");
281
+ dom.className = "docs-footnote-ref";
282
+ dom.setAttribute("data-node-type", "footnote");
283
+ dom.setAttribute("data-footnote-content", String(attrs.content ?? ""));
284
+ dom.textContent = "1";
285
+ return {
286
+ dom,
287
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
288
+ update(updatedNode) {
289
+ try {
290
+ const updatedAttrs = updatedNode?.attrs ?? {};
291
+ dom.setAttribute("data-footnote-content", String(updatedAttrs.content ?? ""));
292
+ } catch {
293
+ }
294
+ return true;
295
+ }
296
+ };
297
+ };
298
+ }
299
+ });
300
+ var footnotePlugin = definePlugin12({
301
+ id: "footnote",
302
+ tiptapExtensions: [FootnoteNode],
303
+ toolbar: [
304
+ { id: "insert-footnote", label: "Catatan Kaki", action: "insertFootnote", iconComponent: "FileText" }
305
+ ],
306
+ slashCommands: [{ name: "Catatan Kaki", command: "insertFootnote" }],
307
+ commands: {
308
+ insertFootnote: (editor, ...args) => {
309
+ const attrs = args[0];
310
+ return editor.chain().focus().insertContent({ type: "footnote", attrs: { content: attrs?.content ?? "" } }).run();
311
+ }
312
+ }
313
+ });
314
+
315
+ // src/fontSize.ts
316
+ import { definePlugin as definePlugin13, FontSizeExtension } from "@kedata-indonesia/docflow-core";
317
+ var fontSizePlugin = definePlugin13({
318
+ id: "font-size",
319
+ tiptapExtensions: [FontSizeExtension],
320
+ commands: {
321
+ setFontSize: (editor, ...args) => {
322
+ const size = args[0] || "16px";
323
+ if (size === "16px") {
324
+ editor.commands.unsetFontSize();
325
+ } else {
326
+ editor.commands.setFontSize(size);
327
+ }
328
+ editor.commands.focus();
329
+ return true;
330
+ }
331
+ }
332
+ });
333
+
334
+ // src/index.ts
335
+ var defaultPlugins = [
336
+ formattingPlugin,
337
+ headingsPlugin,
338
+ listsPlugin,
339
+ alignmentPlugin,
340
+ linkPlugin,
341
+ imagePlugin,
342
+ tablePlugin,
343
+ blockquotePlugin,
344
+ codeBlockPlugin,
345
+ placeholderPlugin,
346
+ pageBreakPlugin,
347
+ footnotePlugin,
348
+ fontSizePlugin
349
+ ];
350
+ export {
351
+ FontSizeExtension,
352
+ FootnoteNode,
353
+ PageBreak,
354
+ alignmentPlugin,
355
+ blockquotePlugin,
356
+ codeBlockPlugin,
357
+ createPlaceholderPlugin,
358
+ defaultPlugins,
359
+ fontSizePlugin,
360
+ footnotePlugin,
361
+ formattingPlugin,
362
+ headingsPlugin,
363
+ imagePlugin,
364
+ linkPlugin,
365
+ listsPlugin,
366
+ pageBreakPlugin,
367
+ placeholderPlugin,
368
+ tablePlugin
369
+ };
package/package.json ADDED
@@ -0,0 +1,90 @@
1
+ {
2
+ "name": "@kedataindo/docflow-plugins",
3
+ "version": "0.0.3",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ }
14
+ },
15
+ "publishConfig": {
16
+ "registry": "https://registry.npmjs.org",
17
+ "access": "public"
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "dependencies": {
23
+ "@kedataindo/docflow-core": "0.0.2"
24
+ },
25
+ "peerDependencies": {
26
+ "@tiptap/core": "^2.11.0",
27
+ "@tiptap/extension-image": "^2.11.0",
28
+ "@tiptap/extension-link": "^2.11.0",
29
+ "@tiptap/extension-placeholder": "^2.11.0",
30
+ "@tiptap/extension-strike": "^2.11.0",
31
+ "@tiptap/extension-table": "^2.11.0",
32
+ "@tiptap/extension-table-cell": "^2.11.0",
33
+ "@tiptap/extension-table-header": "^2.11.0",
34
+ "@tiptap/extension-table-row": "^2.11.0",
35
+ "@tiptap/extension-task-item": "^2.11.0",
36
+ "@tiptap/extension-task-list": "^2.11.0",
37
+ "@tiptap/extension-text-align": "^2.11.0",
38
+ "@tiptap/extension-underline": "^2.11.0"
39
+ },
40
+ "peerDependenciesMeta": {
41
+ "@tiptap/extension-image": {
42
+ "optional": true
43
+ },
44
+ "@tiptap/extension-link": {
45
+ "optional": true
46
+ },
47
+ "@tiptap/extension-placeholder": {
48
+ "optional": true
49
+ },
50
+ "@tiptap/extension-strike": {
51
+ "optional": true
52
+ },
53
+ "@tiptap/extension-table": {
54
+ "optional": true
55
+ },
56
+ "@tiptap/extension-table-cell": {
57
+ "optional": true
58
+ },
59
+ "@tiptap/extension-table-header": {
60
+ "optional": true
61
+ },
62
+ "@tiptap/extension-table-row": {
63
+ "optional": true
64
+ },
65
+ "@tiptap/extension-task-item": {
66
+ "optional": true
67
+ },
68
+ "@tiptap/extension-task-list": {
69
+ "optional": true
70
+ },
71
+ "@tiptap/extension-text-align": {
72
+ "optional": true
73
+ },
74
+ "@tiptap/extension-underline": {
75
+ "optional": true
76
+ }
77
+ },
78
+ "devDependencies": {
79
+ "@tiptap/pm": "^2.11.0",
80
+ "happy-dom": "^20.10.6",
81
+ "tsup": "^8.3.0",
82
+ "typescript": "^5.6.3",
83
+ "vitest": "^2.1.3"
84
+ },
85
+ "scripts": {
86
+ "build": "tsup src/index.ts --format esm,cjs --dts",
87
+ "typecheck": "tsc --noEmit",
88
+ "test:unit": "vitest run"
89
+ }
90
+ }