@phuong-tran-redoc/document-engine-core 0.0.12

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.
Files changed (63) hide show
  1. package/LICENSE.md +19 -0
  2. package/README.md +224 -0
  3. package/package.json +30 -0
  4. package/src/constants/indent.constant.d.ts +1 -0
  5. package/src/constants/indent.constant.js +11 -0
  6. package/src/constants/index.d.ts +1 -0
  7. package/src/constants/index.js +18 -0
  8. package/src/constants/table.constant.d.ts +1 -0
  9. package/src/constants/table.constant.js +11 -0
  10. package/src/extensions/clear-content.extension.d.ts +9 -0
  11. package/src/extensions/clear-content.extension.js +19 -0
  12. package/src/extensions/indent.extension.d.ts +16 -0
  13. package/src/extensions/indent.extension.js +69 -0
  14. package/src/extensions/index.d.ts +8 -0
  15. package/src/extensions/index.js +25 -0
  16. package/src/extensions/ordered-list.extension.d.ts +13 -0
  17. package/src/extensions/ordered-list.extension.js +48 -0
  18. package/src/extensions/reset-format.extension.d.ts +9 -0
  19. package/src/extensions/reset-format.extension.js +19 -0
  20. package/src/extensions/reset-on-enter.extension.d.ts +2 -0
  21. package/src/extensions/reset-on-enter.extension.js +42 -0
  22. package/src/extensions/restricted-editing.extension.d.ts +17 -0
  23. package/src/extensions/restricted-editing.extension.js +384 -0
  24. package/src/extensions/table-resizing.extension.d.ts +6 -0
  25. package/src/extensions/table-resizing.extension.js +171 -0
  26. package/src/extensions/table-style.extension.d.ts +41 -0
  27. package/src/extensions/table-style.extension.js +499 -0
  28. package/src/extensions/text-case.extension.d.ts +13 -0
  29. package/src/extensions/text-case.extension.js +49 -0
  30. package/src/index.d.ts +7 -0
  31. package/src/index.js +24 -0
  32. package/src/models/color.model.d.ts +14 -0
  33. package/src/models/color.model.js +40 -0
  34. package/src/models/index.d.ts +1 -0
  35. package/src/models/index.js +18 -0
  36. package/src/nodes/dynamic-field.node.d.ts +49 -0
  37. package/src/nodes/dynamic-field.node.js +99 -0
  38. package/src/nodes/heading.node.d.ts +8 -0
  39. package/src/nodes/heading.node.js +23 -0
  40. package/src/nodes/index.d.ts +3 -0
  41. package/src/nodes/index.js +20 -0
  42. package/src/nodes/page-break.node.d.ts +9 -0
  43. package/src/nodes/page-break.node.js +50 -0
  44. package/src/types/index.d.ts +2 -0
  45. package/src/types/index.js +19 -0
  46. package/src/types/ordered-list.type.d.ts +1 -0
  47. package/src/types/ordered-list.type.js +4 -0
  48. package/src/types/text-case.type.d.ts +1 -0
  49. package/src/types/text-case.type.js +4 -0
  50. package/src/utils/color.util.d.ts +14 -0
  51. package/src/utils/color.util.js +41 -0
  52. package/src/utils/dom.util.d.ts +2 -0
  53. package/src/utils/dom.util.js +43 -0
  54. package/src/utils/index.d.ts +4 -0
  55. package/src/utils/index.js +21 -0
  56. package/src/utils/table.util.d.ts +36 -0
  57. package/src/utils/table.util.js +103 -0
  58. package/src/utils/text.util.d.ts +9 -0
  59. package/src/utils/text.util.js +59 -0
  60. package/src/views/block-handler.d.ts +44 -0
  61. package/src/views/block-handler.js +310 -0
  62. package/src/views/index.d.ts +1 -0
  63. package/src/views/index.js +18 -0
package/LICENSE.md ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2025 Realestatedoc (Redoc).
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,224 @@
1
+ # document-engine-core
2
+
3
+ A **framework-agnostic** document editor core library built on top of [Tiptap](https://tiptap.dev/) and [ProseMirror](https://prosemirror.net/). This library provides the foundation for building rich-text editors with custom business logic and extensions.
4
+
5
+ ---
6
+
7
+ ## 🎯 Overview
8
+
9
+ `document-engine-core` is the heart of the Document Engine system. It contains all the business logic, custom extensions, and editor functionality in a framework-agnostic manner, making it reusable across different frameworks (Angular, React, Vue, etc.).
10
+
11
+ ### Key Features
12
+
13
+ - **Framework-Agnostic:** Pure TypeScript implementation, no framework dependencies
14
+ - **Business-Focused Extensions:**
15
+ - **Dynamic Fields:** Support for placeholder fields like `{{customer_name}}`
16
+ - **Restricted Editing:** Control which parts of documents can be edited
17
+ - **Custom Nodes:** Business-specific document nodes and marks
18
+ - **Built on Proven Technology:** Leverages Tiptap and ProseMirror for robust editing
19
+ - **JSON-based Data Model:** Documents are represented as structured JSON, not raw HTML
20
+ - **TypeScript-First:** Full type safety and IntelliSense support
21
+ - **Extensible Architecture:** Easy to add custom extensions and plugins
22
+
23
+ ---
24
+
25
+ ## 📦 Installation
26
+
27
+ > ⚠️ **This is a private package. Please contact an authorized person to install it.**
28
+
29
+ ```bash
30
+ npm install @phuong-tran-redoc/document-engine-core
31
+ # or
32
+ pnpm add @phuong-tran-redoc/document-engine-core
33
+ ```
34
+
35
+ ### Peer Dependencies
36
+
37
+ ```json
38
+ {
39
+ "@tiptap/core": "^2.x.x",
40
+ "@tiptap/pm": "^2.x.x"
41
+ }
42
+ ```
43
+
44
+ ---
45
+
46
+ ## 🚀 Quick Start
47
+
48
+ ### Basic Usage
49
+
50
+ ```typescript
51
+ import { Editor } from '@tiptap/core';
52
+ import { DocumentEngineExtensions } from '@phuong-tran-redoc/document-engine-core';
53
+
54
+ // Create an editor instance with Document Engine extensions
55
+ const editor = new Editor({
56
+ element: document.querySelector('#editor'),
57
+ extensions: [...DocumentEngineExtensions],
58
+ content: '<p>Hello World!</p>',
59
+ });
60
+ ```
61
+
62
+ ### Working with Dynamic Fields
63
+
64
+ ```typescript
65
+ import { DynamicFieldExtension } from '@phuong-tran-redoc/document-engine-core';
66
+
67
+ // Insert a dynamic field
68
+ editor.commands.insertDynamicField({
69
+ name: 'customer_name',
70
+ label: 'Customer Name',
71
+ });
72
+
73
+ // Get all dynamic fields in the document
74
+ const fields = editor.commands.getDynamicFields();
75
+
76
+ // Replace field values
77
+ editor.commands.replaceDynamicFields({
78
+ customer_name: 'John Doe',
79
+ loan_amount: '50000',
80
+ });
81
+ ```
82
+
83
+ ### Restricted Editing
84
+
85
+ ```typescript
86
+ import { RestrictedEditingExtension } from '@phuong-tran-redoc/document-engine-core';
87
+
88
+ // Mark a region as editable
89
+ editor.commands.setEditableRegion();
90
+
91
+ // Lock the document (only editable regions can be modified)
92
+ editor.commands.lockDocument();
93
+
94
+ // Unlock the document
95
+ editor.commands.unlockDocument();
96
+ ```
97
+
98
+ ---
99
+
100
+ ## 🏗️ Architecture
101
+
102
+ ```
103
+ document-engine-core/
104
+ ├── extensions/ # Custom Tiptap extensions
105
+ │ ├── dynamic-field/ # Dynamic field support
106
+ │ ├── restricted/ # Restricted editing
107
+ │ └── ...
108
+ ├── nodes/ # Custom document nodes
109
+ ├── marks/ # Custom text marks
110
+ ├── plugins/ # ProseMirror plugins
111
+ ├── commands/ # Editor commands
112
+ ├── utils/ # Utility functions
113
+ └── types/ # TypeScript type definitions
114
+ ```
115
+
116
+ ---
117
+
118
+ ## 📚 Core Extensions
119
+
120
+ ### Dynamic Fields Extension
121
+
122
+ Allows inserting placeholder fields that can be replaced with real data.
123
+
124
+ **Features:**
125
+
126
+ - Insert fields: `{{field_name}}`
127
+ - List all fields in document
128
+ - Batch replace field values
129
+ - Custom field styling
130
+
131
+ ### Restricted Editing Extension
132
+
133
+ Controls which parts of the document can be edited.
134
+
135
+ **Features:**
136
+
137
+ - Mark editable regions
138
+ - Lock/unlock document
139
+ - Visual indicators for editable areas
140
+ - Keyboard navigation between editable regions
141
+
142
+ ### Custom Table Extension
143
+
144
+ Enhanced table support for business documents.
145
+
146
+ **Features:**
147
+
148
+ - Merge/split cells
149
+ - Add/remove rows and columns
150
+ - Table headers
151
+ - Cell styling
152
+
153
+ _(More extensions to be documented)_
154
+
155
+ ---
156
+
157
+ ## 🔧 Development
158
+
159
+ ### Building
160
+
161
+ Build the library:
162
+
163
+ ```bash
164
+ nx build document-engine-core
165
+ ```
166
+
167
+ ### Testing
168
+
169
+ Run unit tests:
170
+
171
+ ```bash
172
+ nx test document-engine-core
173
+ ```
174
+
175
+ ### Linting
176
+
177
+ Lint the code:
178
+
179
+ ```bash
180
+ nx lint document-engine-core
181
+ ```
182
+
183
+ ---
184
+
185
+ ## 🎨 Framework Wrappers
186
+
187
+ This core library is designed to be wrapped by framework-specific libraries:
188
+
189
+ - **Angular:** [`@phuong-tran-redoc/document-engine-angular`](../document-engine-angular)
190
+
191
+ ---
192
+
193
+ ## 📖 Documentation
194
+
195
+ - **[Live Demo](#)** - See the editor in action
196
+ - **[API Reference](#)** - Detailed API documentation
197
+ - **[Examples](#)** - Code examples and use cases
198
+ - **[Contributing](#)** - How to contribute
199
+
200
+ ---
201
+
202
+ ## 🔗 Related Resources
203
+
204
+ - [Tiptap Documentation](https://tiptap.dev)
205
+ - [ProseMirror Documentation](https://prosemirror.net)
206
+ - [Main Project Repository](#)
207
+
208
+ ---
209
+
210
+ ## 👤 Author
211
+
212
+ Developed by **Duc Phuong (Jack)**
213
+
214
+ - 💼 [LinkedIn](https://www.linkedin.com/in/tdp1999/)
215
+ - 🐙 [GitHub](https://github.com/tdp1999)
216
+ - 📧 [Email](mailto:tdp99.business@gmail.com)
217
+
218
+ ---
219
+
220
+ ## 📄 License
221
+
222
+ **MIT License**
223
+
224
+ See [LICENSE.md](./LICENSE.md) for full license text.
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@phuong-tran-redoc/document-engine-core",
3
+ "version": "0.0.12",
4
+ "type": "commonjs",
5
+ "license": "MIT",
6
+ "author": "Duc Phuong (Jack) <tdp99.business@gmail.com>",
7
+ "description": "Framework-agnostic core library for Document Engine",
8
+ "main": "./src/index.js",
9
+ "types": "./src/index.d.ts",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/phuong-tran-redoc/document-engine"
13
+ },
14
+ "publishConfig": {
15
+ "directory": "../../dist/libs/document-engine-core",
16
+ "access": "public"
17
+ },
18
+ "dependencies": {
19
+ "tslib": "^2.3.0",
20
+ "@tiptap/core": "^3.10.5",
21
+ "@tiptap/extension-heading": "^3.10.5",
22
+ "@tiptap/extension-table": "^3.10.5",
23
+ "@tiptap/pm": "^3.10.5",
24
+ "@tiptap/extension-list": "^3.10.5",
25
+ "@tiptap/extension-paragraph": "^3.10.5"
26
+ },
27
+ "peerDependencies": {
28
+ "lodash-es": "^4.17.10"
29
+ }
30
+ }
@@ -0,0 +1 @@
1
+ export declare const INDENT_DEFAULT = 40;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "INDENT_DEFAULT", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return INDENT_DEFAULT;
9
+ }
10
+ });
11
+ const INDENT_DEFAULT = 40; // in pixels
@@ -0,0 +1 @@
1
+ export * from './indent.constant';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ _export_star(require("./indent.constant"), exports);
6
+ function _export_star(from, to) {
7
+ Object.keys(from).forEach(function(k) {
8
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
9
+ Object.defineProperty(to, k, {
10
+ enumerable: true,
11
+ get: function() {
12
+ return from[k];
13
+ }
14
+ });
15
+ }
16
+ });
17
+ return from;
18
+ }
@@ -0,0 +1 @@
1
+ export declare const MIN_NEW_COL_WIDTH = 5;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "MIN_NEW_COL_WIDTH", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return MIN_NEW_COL_WIDTH;
9
+ }
10
+ });
11
+ const MIN_NEW_COL_WIDTH = 5.0;
@@ -0,0 +1,9 @@
1
+ import { Extension } from '@tiptap/core';
2
+ declare module '@tiptap/core' {
3
+ interface Commands<ReturnType> {
4
+ clear: {
5
+ clear: () => ReturnType;
6
+ };
7
+ }
8
+ }
9
+ export declare const ClearContent: Extension<any, any>;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "ClearContent", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return ClearContent;
9
+ }
10
+ });
11
+ const _core = require("@tiptap/core");
12
+ const ClearContent = _core.Extension.create({
13
+ name: 'clearContent',
14
+ addCommands () {
15
+ return {
16
+ clear: ()=>({ chain })=>chain().focus().clearContent().run()
17
+ };
18
+ }
19
+ });
@@ -0,0 +1,16 @@
1
+ import { Extension } from '@tiptap/core';
2
+ export interface IndentOptions {
3
+ types: string[];
4
+ indent: number;
5
+ }
6
+ declare module '@tiptap/core' {
7
+ interface Commands<ReturnType> {
8
+ increaseIndent: {
9
+ increaseIndent: () => ReturnType;
10
+ };
11
+ decreaseIndent: {
12
+ decreaseIndent: () => ReturnType;
13
+ };
14
+ }
15
+ }
16
+ export declare const Indent: Extension<IndentOptions, any>;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "Indent", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return Indent;
9
+ }
10
+ });
11
+ const _core = require("@tiptap/core");
12
+ const _constants = require("../constants");
13
+ const Indent = _core.Extension.create({
14
+ name: 'indent',
15
+ addOptions () {
16
+ return {
17
+ types: [
18
+ 'paragraph',
19
+ 'heading'
20
+ ],
21
+ indent: _constants.INDENT_DEFAULT
22
+ };
23
+ },
24
+ addGlobalAttributes () {
25
+ return [
26
+ {
27
+ types: this.options.types,
28
+ attributes: {
29
+ indent: {
30
+ parseHTML: (element)=>{
31
+ return Number(element.style.marginLeft.replace('px', ''));
32
+ },
33
+ renderHTML: (attributes)=>{
34
+ return {
35
+ style: `margin-left: ${attributes['indent']}px`
36
+ };
37
+ }
38
+ }
39
+ }
40
+ }
41
+ ];
42
+ },
43
+ addCommands () {
44
+ return {
45
+ increaseIndent: ()=>({ state, chain })=>{
46
+ const currentNode = state.selection.$head.parent;
47
+ const nodeType = currentNode.type;
48
+ if (!this.options.types.includes(nodeType.name)) return false;
49
+ const currentIndent = currentNode.attrs['indent'] || 0;
50
+ const newIndent = currentIndent + this.options.indent;
51
+ return chain().updateAttributes(nodeType, {
52
+ indent: newIndent
53
+ }).run();
54
+ },
55
+ decreaseIndent: ()=>({ state, chain })=>{
56
+ const currentNode = state.selection.$head.parent;
57
+ const nodeType = currentNode.type;
58
+ if (!this.options.types.includes(nodeType.name)) return false;
59
+ const currentIndent = currentNode.attrs['indent'] || 0;
60
+ const newIndent = currentIndent - this.options.indent;
61
+ if (newIndent < 0) return false;
62
+ if (newIndent === 0) return chain().resetAttributes(nodeType, 'indent').run();
63
+ return chain().updateAttributes(nodeType, {
64
+ indent: newIndent
65
+ }).run();
66
+ }
67
+ };
68
+ }
69
+ });
@@ -0,0 +1,8 @@
1
+ export * from './clear-content.extension';
2
+ export * from './indent.extension';
3
+ export * from './ordered-list.extension';
4
+ export * from './reset-format.extension';
5
+ export * from './reset-on-enter.extension';
6
+ export * from './restricted-editing.extension';
7
+ export * from './table-style.extension';
8
+ export * from './text-case.extension';
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ _export_star(require("./clear-content.extension"), exports);
6
+ _export_star(require("./indent.extension"), exports);
7
+ _export_star(require("./ordered-list.extension"), exports);
8
+ _export_star(require("./reset-format.extension"), exports);
9
+ _export_star(require("./reset-on-enter.extension"), exports);
10
+ _export_star(require("./restricted-editing.extension"), exports);
11
+ _export_star(require("./table-style.extension"), exports);
12
+ _export_star(require("./text-case.extension"), exports);
13
+ function _export_star(from, to) {
14
+ Object.keys(from).forEach(function(k) {
15
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
16
+ Object.defineProperty(to, k, {
17
+ enumerable: true,
18
+ get: function() {
19
+ return from[k];
20
+ }
21
+ });
22
+ }
23
+ });
24
+ return from;
25
+ }
@@ -0,0 +1,13 @@
1
+ import { ListStyleType } from '../types';
2
+ declare module '@tiptap/core' {
3
+ interface Commands<ReturnType> {
4
+ customOrderedList: {
5
+ toggleOrderedList: () => ReturnType;
6
+ setListStyle: (listStyleType: ListStyleType) => ReturnType;
7
+ };
8
+ }
9
+ }
10
+ export interface CustomOrderedListOptions {
11
+ listStyleType?: ListStyleType;
12
+ }
13
+ export declare const CustomOrderedList: import("@tiptap/core").Node<CustomOrderedListOptions, any>;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "CustomOrderedList", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return CustomOrderedList;
9
+ }
10
+ });
11
+ const _extensionlist = require("@tiptap/extension-list");
12
+ const CustomOrderedList = _extensionlist.OrderedList.extend({
13
+ name: 'customOrderedList',
14
+ addOptions () {
15
+ return {
16
+ ...this.parent?.(),
17
+ listStyleType: 'decimal'
18
+ };
19
+ },
20
+ addAttributes () {
21
+ return {
22
+ ...this.parent?.(),
23
+ 'data-list-style-type': {
24
+ default: this.options.listStyleType,
25
+ parseHTML: (element)=>element.getAttribute('data-list-style-type') || this.options.listStyleType,
26
+ renderHTML: (attributes)=>{
27
+ const styleType = attributes['data-list-style-type'];
28
+ if (!styleType || styleType === 'decimal') return {
29
+ 'data-list-style-type': 'decimal'
30
+ };
31
+ return {
32
+ 'data-list-style-type': attributes['data-list-style-type']
33
+ };
34
+ }
35
+ }
36
+ };
37
+ },
38
+ addCommands () {
39
+ return {
40
+ ...this.parent?.(),
41
+ setListStyle: (listStyleType)=>({ chain })=>{
42
+ return chain().focus().updateAttributes('customOrderedList', {
43
+ 'data-list-style-type': listStyleType
44
+ }).run();
45
+ }
46
+ };
47
+ }
48
+ });
@@ -0,0 +1,9 @@
1
+ import { Extension } from '@tiptap/core';
2
+ declare module '@tiptap/core' {
3
+ interface Commands<ReturnType> {
4
+ resetFormat: {
5
+ resetFormat: () => ReturnType;
6
+ };
7
+ }
8
+ }
9
+ export declare const ResetFormat: Extension<any, any>;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "ResetFormat", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return ResetFormat;
9
+ }
10
+ });
11
+ const _core = require("@tiptap/core");
12
+ const ResetFormat = _core.Extension.create({
13
+ name: 'resetFormat',
14
+ addCommands () {
15
+ return {
16
+ resetFormat: ()=>({ chain })=>chain().focus().unsetAllMarks().clearNodes().run()
17
+ };
18
+ }
19
+ });
@@ -0,0 +1,2 @@
1
+ import { Extension } from '@tiptap/core';
2
+ export declare const ResetOnEnter: Extension<any, any>;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "ResetOnEnter", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return ResetOnEnter;
9
+ }
10
+ });
11
+ const _core = require("@tiptap/core");
12
+ const ResetOnEnter = _core.Extension.create({
13
+ name: 'resetOnEnter',
14
+ addKeyboardShortcuts () {
15
+ return {
16
+ Enter: ()=>{
17
+ const disabledNodes = [
18
+ 'listItem',
19
+ 'blockquote'
20
+ ];
21
+ if (disabledNodes.some((type)=>this.editor.isActive(type))) {
22
+ return false; //Let the default Enter behavior proceed
23
+ }
24
+ // Handle Enter ourselves so we can both clear marks and reset indent on the new line
25
+ return this.editor.chain().focus().unsetAllMarks().splitBlock({
26
+ keepMarks: false
27
+ }).command(({ state, commands })=>{
28
+ const parent = state.selection.$head.parent;
29
+ const nodeType = parent.type;
30
+ const typesToReset = [
31
+ 'paragraph',
32
+ 'heading'
33
+ ];
34
+ if (typesToReset.includes(nodeType.name)) {
35
+ return commands.resetAttributes(nodeType, 'indent');
36
+ }
37
+ return true;
38
+ }).run();
39
+ }
40
+ };
41
+ }
42
+ });
@@ -0,0 +1,17 @@
1
+ import { Extension, Node } from '@tiptap/core';
2
+ export declare const EditableRegion: Node<any, any>;
3
+ export interface RestrictedEditingOptions {
4
+ editableRegionNodeName: string;
5
+ disabledNodeTypes: string[];
6
+ initialMode: 'standard' | 'restricted';
7
+ }
8
+ declare module '@tiptap/core' {
9
+ interface Commands<ReturnType> {
10
+ restrictedEditing: {
11
+ wrapSelectionInEditableRegion: () => ReturnType;
12
+ removeEditableRegion: () => ReturnType;
13
+ toggleEditableRegion: () => ReturnType;
14
+ };
15
+ }
16
+ }
17
+ export declare const RestrictedEditing: Extension<RestrictedEditingOptions, any>;