@kerebron/extension-dev-toolkit 0.3.2

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 (61) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +67 -0
  3. package/esm/editor/src/CoreEditor.d.ts +31 -0
  4. package/esm/editor/src/CoreEditor.d.ts.map +1 -0
  5. package/esm/editor/src/CoreEditor.js +200 -0
  6. package/esm/editor/src/DummyEditorView.d.ts +60 -0
  7. package/esm/editor/src/DummyEditorView.d.ts.map +1 -0
  8. package/esm/editor/src/DummyEditorView.js +277 -0
  9. package/esm/editor/src/Extension.d.ts +26 -0
  10. package/esm/editor/src/Extension.d.ts.map +1 -0
  11. package/esm/editor/src/Extension.js +33 -0
  12. package/esm/editor/src/ExtensionManager.d.ts +33 -0
  13. package/esm/editor/src/ExtensionManager.d.ts.map +1 -0
  14. package/esm/editor/src/ExtensionManager.js +272 -0
  15. package/esm/editor/src/Mark.d.ts +20 -0
  16. package/esm/editor/src/Mark.d.ts.map +1 -0
  17. package/esm/editor/src/Mark.js +40 -0
  18. package/esm/editor/src/Node.d.ts +29 -0
  19. package/esm/editor/src/Node.d.ts.map +1 -0
  20. package/esm/editor/src/Node.js +49 -0
  21. package/esm/editor/src/commands/CommandManager.d.ts +16 -0
  22. package/esm/editor/src/commands/CommandManager.d.ts.map +1 -0
  23. package/esm/editor/src/commands/CommandManager.js +61 -0
  24. package/esm/editor/src/commands/createChainableState.d.ts +3 -0
  25. package/esm/editor/src/commands/createChainableState.d.ts.map +1 -0
  26. package/esm/editor/src/commands/createChainableState.js +29 -0
  27. package/esm/editor/src/commands/mod.d.ts +55 -0
  28. package/esm/editor/src/commands/mod.d.ts.map +1 -0
  29. package/esm/editor/src/commands/mod.js +883 -0
  30. package/esm/editor/src/mod.d.ts +7 -0
  31. package/esm/editor/src/mod.d.ts.map +1 -0
  32. package/esm/editor/src/mod.js +6 -0
  33. package/esm/editor/src/nodeToTreeString.d.ts +10 -0
  34. package/esm/editor/src/nodeToTreeString.d.ts.map +1 -0
  35. package/esm/editor/src/nodeToTreeString.js +74 -0
  36. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts +23 -0
  37. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts.map +1 -0
  38. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.js +163 -0
  39. package/esm/editor/src/plugins/keymap/keymap.d.ts +11 -0
  40. package/esm/editor/src/plugins/keymap/keymap.d.ts.map +1 -0
  41. package/esm/editor/src/plugins/keymap/keymap.js +125 -0
  42. package/esm/editor/src/plugins/keymap/w3c-keyname.d.ts +4 -0
  43. package/esm/editor/src/plugins/keymap/w3c-keyname.d.ts.map +1 -0
  44. package/esm/editor/src/plugins/keymap/w3c-keyname.js +124 -0
  45. package/esm/editor/src/types.d.ts +34 -0
  46. package/esm/editor/src/types.d.ts.map +1 -0
  47. package/esm/editor/src/types.js +1 -0
  48. package/esm/editor/src/utilities/SmartOutput.d.ts +39 -0
  49. package/esm/editor/src/utilities/SmartOutput.d.ts.map +1 -0
  50. package/esm/editor/src/utilities/SmartOutput.js +213 -0
  51. package/esm/editor/src/utilities/createNodeFromContent.d.ts +9 -0
  52. package/esm/editor/src/utilities/createNodeFromContent.d.ts.map +1 -0
  53. package/esm/editor/src/utilities/createNodeFromContent.js +32 -0
  54. package/esm/editor/src/utilities/getHtmlAttributes.d.ts +9 -0
  55. package/esm/editor/src/utilities/getHtmlAttributes.d.ts.map +1 -0
  56. package/esm/editor/src/utilities/getHtmlAttributes.js +47 -0
  57. package/esm/extension-dev-toolkit/src/mod.d.ts +13 -0
  58. package/esm/extension-dev-toolkit/src/mod.d.ts.map +1 -0
  59. package/esm/extension-dev-toolkit/src/mod.js +50 -0
  60. package/esm/package.json +3 -0
  61. package/package.json +23 -0
@@ -0,0 +1,213 @@
1
+ export class SmartOutput {
2
+ constructor() {
3
+ Object.defineProperty(this, "_rowPos", {
4
+ enumerable: true,
5
+ configurable: true,
6
+ writable: true,
7
+ value: 0
8
+ });
9
+ Object.defineProperty(this, "_colPos", {
10
+ enumerable: true,
11
+ configurable: true,
12
+ writable: true,
13
+ value: 0
14
+ });
15
+ Object.defineProperty(this, "chunks", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: []
20
+ });
21
+ Object.defineProperty(this, "metas", {
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true,
25
+ value: []
26
+ });
27
+ }
28
+ log(text, item) {
29
+ this.chunks.push(text);
30
+ this.metas.push({
31
+ colPos: this._colPos,
32
+ rowPos: this._rowPos,
33
+ item,
34
+ });
35
+ const lines = text.split('\n');
36
+ if (lines.length === 1) {
37
+ this._colPos += lines[lines.length - 1].length;
38
+ }
39
+ else {
40
+ this._rowPos += lines.length - 1;
41
+ this._colPos = lines[lines.length - 1].length;
42
+ }
43
+ }
44
+ get chunkPos() {
45
+ return this.chunks.length;
46
+ }
47
+ rollback(pos) {
48
+ this.chunks.splice(pos);
49
+ this.metas.splice(pos);
50
+ }
51
+ get rowPos() {
52
+ return this._rowPos;
53
+ }
54
+ get colPos() {
55
+ return this._colPos;
56
+ }
57
+ endsWith(text) {
58
+ return this.chunks.join('').endsWith(text);
59
+ }
60
+ toString() {
61
+ return this.chunks.join('');
62
+ }
63
+ getSourceMap(mapper) {
64
+ const mappingRows = [];
65
+ let lastRow = -1;
66
+ let lastCol = -1;
67
+ for (const meta of this.metas) {
68
+ while (meta.rowPos >= mappingRows.length) {
69
+ mappingRows.push([]);
70
+ }
71
+ if (lastRow != meta.rowPos || lastCol != meta.colPos) {
72
+ const currentRow = mappingRows[meta.rowPos];
73
+ const mapping = mapper(meta.item, meta.rowPos, meta.colPos);
74
+ if (mapping) {
75
+ currentRow.push([
76
+ meta.colPos,
77
+ mapping.sourceNo,
78
+ mapping.sourceRowPos,
79
+ mapping.sourceColPos,
80
+ ]);
81
+ }
82
+ }
83
+ lastRow = meta.rowPos;
84
+ lastCol = meta.colPos;
85
+ }
86
+ const mappings = mappingRows
87
+ .map((row) => row.map((group) => encode(group))
88
+ .join(','))
89
+ .join(';');
90
+ mappingRows.forEach((row, rowNo) => {
91
+ // console.log('g', rowNo, row);
92
+ row.forEach((group) => {
93
+ const enc = encode(group);
94
+ // console.log('g', rowNo, group, enc, decode(enc));
95
+ });
96
+ });
97
+ return {
98
+ version: 3,
99
+ file: '',
100
+ sourceRoot: '',
101
+ sources: [],
102
+ sourcesContent: [],
103
+ names: [],
104
+ mappings,
105
+ };
106
+ }
107
+ }
108
+ const BASE64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
109
+ function toVLQ(value) {
110
+ const vlq = [];
111
+ const isNegative = value < 0;
112
+ value = Math.abs(value);
113
+ if (value === 0) {
114
+ vlq.push(0);
115
+ return vlq;
116
+ }
117
+ while (value > 0) {
118
+ let digit = value & 0x1F;
119
+ value >>= 5;
120
+ if (value > 0) {
121
+ digit |= 0x20;
122
+ }
123
+ vlq.push(digit);
124
+ if (vlq.length === 1) {
125
+ digit = isNegative ? (digit | 0x1) : (digit & ~0x1);
126
+ vlq[0] = digit;
127
+ }
128
+ }
129
+ return vlq;
130
+ }
131
+ function encodeVLQ(input) {
132
+ const numbers = Array.isArray(input) ? input : [input];
133
+ let result = '';
134
+ for (const num of numbers) {
135
+ const vlq = toVLQ(num);
136
+ for (const digit of vlq) {
137
+ result += BASE64_CHARS[digit];
138
+ }
139
+ }
140
+ return result;
141
+ }
142
+ /** @type {Record<string, number>} */
143
+ let char_to_integer = {};
144
+ /** @type {Record<number, string>} */
145
+ let integer_to_char = {};
146
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
147
+ .split('')
148
+ .forEach(function (char, i) {
149
+ char_to_integer[char] = i;
150
+ integer_to_char[i] = char;
151
+ });
152
+ /** @param {string} string */
153
+ export function decode(string) {
154
+ /** @type {number[]} */
155
+ let result = [];
156
+ let shift = 0;
157
+ let value = 0;
158
+ for (let i = 0; i < string.length; i += 1) {
159
+ let integer = char_to_integer[string[i]];
160
+ if (integer === undefined) {
161
+ throw new Error('Invalid character (' + string[i] + ')');
162
+ }
163
+ const has_continuation_bit = integer & 32;
164
+ integer &= 31;
165
+ value += integer << shift;
166
+ if (has_continuation_bit) {
167
+ shift += 5;
168
+ }
169
+ else {
170
+ const should_negate = value & 1;
171
+ value >>>= 1;
172
+ if (should_negate) {
173
+ result.push(value === 0 ? -0x80000000 : -value);
174
+ }
175
+ else {
176
+ result.push(value);
177
+ }
178
+ // reset
179
+ value = shift = 0;
180
+ }
181
+ }
182
+ return result;
183
+ }
184
+ /** @param {number | number[]} value */
185
+ export function encode(value) {
186
+ if (typeof value === 'number') {
187
+ return encode_integer(value);
188
+ }
189
+ let result = '';
190
+ for (let i = 0; i < value.length; i += 1) {
191
+ result += encode_integer(value[i]);
192
+ }
193
+ return result;
194
+ }
195
+ /** @param {number} num */
196
+ function encode_integer(num) {
197
+ let result = '';
198
+ if (num < 0) {
199
+ num = (-num << 1) | 1;
200
+ }
201
+ else {
202
+ num <<= 1;
203
+ }
204
+ do {
205
+ let clamped = num & 31;
206
+ num >>>= 5;
207
+ if (num > 0) {
208
+ clamped |= 32;
209
+ }
210
+ result += integer_to_char[clamped];
211
+ } while (num > 0);
212
+ return result;
213
+ }
@@ -0,0 +1,9 @@
1
+ import { Fragment, Node as ProseMirrorNode, Schema } from 'prosemirror-model';
2
+ import type { JSONContent } from '../types.js';
3
+ export type CreateNodeFromContentOptions = {
4
+ errorOnInvalidContent?: boolean;
5
+ };
6
+ export declare function createNodeFromObject(content: JSONContent | ProseMirrorNode | Fragment, schema: Schema, options?: CreateNodeFromContentOptions): ProseMirrorNode;
7
+ export declare function createNodeFromArray(content: JSONContent[], schema: Schema): Fragment;
8
+ export declare function createNodeFromContent(content: JSONContent | ProseMirrorNode | Fragment, schema: Schema, options?: CreateNodeFromContentOptions): ProseMirrorNode | Fragment;
9
+ //# sourceMappingURL=createNodeFromContent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createNodeFromContent.d.ts","sourceRoot":"","sources":["../../../../src/editor/src/utilities/createNodeFromContent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,IAAI,eAAe,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE9E,OAAO,KAAK,EAAW,WAAW,EAAE,MAAM,aAAa,CAAC;AAExD,MAAM,MAAM,4BAA4B,GAAG;IACzC,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC,CAAC;AAEF,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,WAAW,GAAG,eAAe,GAAG,QAAQ,EACjD,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,4BAA4B,GACrC,eAAe,CA0BjB;AAED,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,WAAW,EAAE,EACtB,MAAM,EAAE,MAAM,GACb,QAAQ,CAIV;AAED,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,WAAW,GAAG,eAAe,GAAG,QAAQ,EACjD,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,4BAA4B,GACrC,eAAe,GAAG,QAAQ,CAY5B"}
@@ -0,0 +1,32 @@
1
+ import { Fragment, Node as ProseMirrorNode } from 'prosemirror-model';
2
+ export function createNodeFromObject(content, schema, options) {
3
+ try {
4
+ const node = schema.nodeFromJSON(content);
5
+ if (options?.errorOnInvalidContent) {
6
+ node.check();
7
+ }
8
+ return node;
9
+ }
10
+ catch (error) {
11
+ if (options?.errorOnInvalidContent) {
12
+ throw new Error('Invalid JSON content', {
13
+ cause: error,
14
+ });
15
+ }
16
+ console.warn('Invalid content.', 'Passed value:', content, 'Error:', error);
17
+ return schema.topNodeType.createAndFill(null, []);
18
+ }
19
+ }
20
+ export function createNodeFromArray(content, schema) {
21
+ return Fragment.fromArray(content.map((item) => schema.nodeFromJSON(item)));
22
+ }
23
+ export function createNodeFromContent(content, schema, options) {
24
+ if (content instanceof ProseMirrorNode || content instanceof Fragment) {
25
+ return content;
26
+ }
27
+ const isJSONContent = typeof content === 'object' && content !== null;
28
+ if (isJSONContent) {
29
+ return createNodeFromObject(content, schema, options);
30
+ }
31
+ return schema.topNodeType.createAndFill(null, []);
32
+ }
@@ -0,0 +1,9 @@
1
+ import type { MarkSpec, Node as ProseMirrorNode, NodeSpec } from 'prosemirror-model';
2
+ import type { Mark } from '../Mark.js';
3
+ import type { Node } from '../Node.js';
4
+ type MarkOfNode = Mark | Node;
5
+ export declare function getHtmlAttributes(extension: MarkOfNode, node: ProseMirrorNode): Record<string, any>;
6
+ export declare function setHtmlAttributes(extension: MarkOfNode, element: HTMLElement): Record<string, any>;
7
+ export declare function addAttributesToSchema(spec: MarkSpec | NodeSpec, extension: MarkOfNode): void;
8
+ export {};
9
+ //# sourceMappingURL=getHtmlAttributes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getHtmlAttributes.d.ts","sourceRoot":"","sources":["../../../../src/editor/src/utilities/getHtmlAttributes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,IAAI,IAAI,eAAe,EACvB,QAAQ,EACT,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,KAAK,UAAU,GAAG,IAAI,GAAG,IAAI,CAAC;AAE9B,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,UAAU,EACrB,IAAI,EAAE,eAAe,uBAmBtB;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,uBAc5E;AAED,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,QAAQ,GAAG,QAAQ,EACzB,SAAS,EAAE,UAAU,QAetB"}
@@ -0,0 +1,47 @@
1
+ export function getHtmlAttributes(extension, node) {
2
+ const attrs = {};
3
+ if (extension.attributes) {
4
+ for (const [key, value] of Object.entries(extension.attributes)) {
5
+ if ('undefined' !== typeof node.attrs[key]) {
6
+ attrs[key] = node.attrs[key];
7
+ }
8
+ else {
9
+ if (value.toDom) {
10
+ attrs[key] = value.toDom(node);
11
+ }
12
+ else {
13
+ attrs[key] = value.default;
14
+ }
15
+ }
16
+ }
17
+ }
18
+ return attrs;
19
+ }
20
+ export function setHtmlAttributes(extension, element) {
21
+ const attrs = {};
22
+ if (extension.attributes) {
23
+ for (const [key, value] of Object.entries(extension.attributes)) {
24
+ if (value.fromDom) {
25
+ attrs[key] = value.fromDom(element);
26
+ }
27
+ else {
28
+ attrs[key] = value.default;
29
+ }
30
+ }
31
+ }
32
+ return attrs;
33
+ }
34
+ export function addAttributesToSchema(spec, extension) {
35
+ const attrs = {};
36
+ if (extension.attributes) {
37
+ if (!spec.attrs) {
38
+ spec.attrs = {};
39
+ }
40
+ for (const [key, value] of Object.entries(extension.attributes)) {
41
+ spec.attrs[key] = value;
42
+ if (!value.toDom) {
43
+ value.toDom = (node) => node.attrs[key];
44
+ }
45
+ }
46
+ }
47
+ }
@@ -0,0 +1,13 @@
1
+ import { CommandFactories, type CoreEditor, Extension } from '../../editor/src/mod.js';
2
+ import { CommandShortcuts } from '../../editor/src/commands/mod.js';
3
+ export interface DevToolkitConfig {
4
+ }
5
+ export declare class ExtensionDevToolkit extends Extension {
6
+ protected config: DevToolkitConfig;
7
+ name: string;
8
+ private visible;
9
+ constructor(config?: DevToolkitConfig);
10
+ getCommandFactories(editor: CoreEditor): Partial<CommandFactories>;
11
+ getKeyboardShortcuts(): Partial<CommandShortcuts>;
12
+ }
13
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/extension-dev-toolkit/src/mod.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,KAAK,UAAU,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACvF,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAGpE,MAAM,WAAW,gBAAgB;CAChC;AAED,qBAAa,mBAAoB,SAAQ,SAAS;cAKjB,MAAM,EAAE,gBAAgB;IAJvD,IAAI,SAAiB;IAErB,OAAO,CAAC,OAAO,CAAS;gBAEO,MAAM,GAAE,gBAAqB;IAInD,mBAAmB,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAkBlE,oBAAoB,IAAI,OAAO,CAAC,gBAAgB,CAAC;CAM3D"}
@@ -0,0 +1,50 @@
1
+ import { applyDevTools, removeDevTools } from 'prosemirror-dev-toolkit';
2
+ import { Extension } from '../../editor/src/mod.js';
3
+ import { EditorView } from 'prosemirror-view';
4
+ export class ExtensionDevToolkit extends Extension {
5
+ constructor(config = {}) {
6
+ super(config);
7
+ Object.defineProperty(this, "config", {
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true,
11
+ value: config
12
+ });
13
+ Object.defineProperty(this, "name", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: 'dev_toolkit'
18
+ });
19
+ Object.defineProperty(this, "visible", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: false
24
+ });
25
+ }
26
+ getCommandFactories(editor) {
27
+ const commands = {
28
+ toggleDevToolkit: () => () => {
29
+ if (this.visible) {
30
+ removeDevTools();
31
+ this.visible = !this.visible;
32
+ }
33
+ else {
34
+ if (editor.view instanceof EditorView) {
35
+ applyDevTools(editor.view, { devToolsExpanded: true });
36
+ this.visible = !this.visible;
37
+ }
38
+ }
39
+ return true;
40
+ },
41
+ };
42
+ return commands;
43
+ }
44
+ getKeyboardShortcuts() {
45
+ const shortcuts = {
46
+ 'Ctrl-`': 'toggleDevToolkit',
47
+ };
48
+ return shortcuts;
49
+ }
50
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@kerebron/extension-dev-toolkit",
3
+ "version": "0.3.2",
4
+ "license": "MIT",
5
+ "module": "./esm/extension-dev-toolkit/src/mod.js",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./esm/extension-dev-toolkit/src/mod.js"
9
+ }
10
+ },
11
+ "scripts": {},
12
+ "dependencies": {
13
+ "prosemirror-dev-toolkit": "1.1.8",
14
+ "prosemirror-model": "1.25.3",
15
+ "prosemirror-state": "1.4.3",
16
+ "prosemirror-transform": "1.10.4",
17
+ "prosemirror-view": "1.40.0"
18
+ },
19
+ "devDependencies": {
20
+ "@types/node": "^20.9.0"
21
+ },
22
+ "_generatedBy": "dnt@dev"
23
+ }