@kerebron/extension-codemirror 0.1.3 → 0.2.0

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 (87) hide show
  1. package/assets/codemirror.css +80 -0
  2. package/package.json +6 -4
  3. package/esm/editor/src/CoreEditor.d.ts +0 -25
  4. package/esm/editor/src/CoreEditor.d.ts.map +0 -1
  5. package/esm/editor/src/CoreEditor.js +0 -194
  6. package/esm/editor/src/Extension.d.ts +0 -26
  7. package/esm/editor/src/Extension.d.ts.map +0 -1
  8. package/esm/editor/src/Extension.js +0 -33
  9. package/esm/editor/src/ExtensionManager.d.ts +0 -32
  10. package/esm/editor/src/ExtensionManager.d.ts.map +0 -1
  11. package/esm/editor/src/ExtensionManager.js +0 -253
  12. package/esm/editor/src/Mark.d.ts +0 -18
  13. package/esm/editor/src/Mark.d.ts.map +0 -1
  14. package/esm/editor/src/Mark.js +0 -34
  15. package/esm/editor/src/Node.d.ts +0 -27
  16. package/esm/editor/src/Node.d.ts.map +0 -1
  17. package/esm/editor/src/Node.js +0 -43
  18. package/esm/editor/src/commands/CommandManager.d.ts +0 -20
  19. package/esm/editor/src/commands/CommandManager.d.ts.map +0 -1
  20. package/esm/editor/src/commands/CommandManager.js +0 -60
  21. package/esm/editor/src/commands/createChainableState.d.ts +0 -3
  22. package/esm/editor/src/commands/createChainableState.d.ts.map +0 -1
  23. package/esm/editor/src/commands/createChainableState.js +0 -29
  24. package/esm/editor/src/commands/mod.d.ts +0 -49
  25. package/esm/editor/src/commands/mod.d.ts.map +0 -1
  26. package/esm/editor/src/commands/mod.js +0 -928
  27. package/esm/editor/src/mod.d.ts +0 -6
  28. package/esm/editor/src/mod.d.ts.map +0 -1
  29. package/esm/editor/src/mod.js +0 -5
  30. package/esm/editor/src/nodeToTreeString.d.ts +0 -4
  31. package/esm/editor/src/nodeToTreeString.d.ts.map +0 -1
  32. package/esm/editor/src/nodeToTreeString.js +0 -56
  33. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts +0 -23
  34. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts.map +0 -1
  35. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.js +0 -163
  36. package/esm/editor/src/plugins/input-rules/mod.d.ts +0 -3
  37. package/esm/editor/src/plugins/input-rules/mod.d.ts.map +0 -1
  38. package/esm/editor/src/plugins/input-rules/mod.js +0 -2
  39. package/esm/editor/src/plugins/input-rules/rulebuilders.d.ts +0 -5
  40. package/esm/editor/src/plugins/input-rules/rulebuilders.d.ts.map +0 -1
  41. package/esm/editor/src/plugins/input-rules/rulebuilders.js +0 -50
  42. package/esm/editor/src/types.d.ts +0 -29
  43. package/esm/editor/src/types.d.ts.map +0 -1
  44. package/esm/editor/src/types.js +0 -1
  45. package/esm/editor/src/utilities/createNodeFromContent.d.ts +0 -8
  46. package/esm/editor/src/utilities/createNodeFromContent.d.ts.map +0 -1
  47. package/esm/editor/src/utilities/createNodeFromContent.js +0 -33
  48. package/esm/editor/src/utilities/getHtmlAttributes.d.ts +0 -4
  49. package/esm/editor/src/utilities/getHtmlAttributes.d.ts.map +0 -1
  50. package/esm/editor/src/utilities/getHtmlAttributes.js +0 -47
  51. package/esm/editor/src/utilities/mod.d.ts +0 -3
  52. package/esm/editor/src/utilities/mod.d.ts.map +0 -1
  53. package/esm/editor/src/utilities/mod.js +0 -2
  54. package/esm/extension-codemirror/src/ExtensionCodeMirror.d.ts +0 -5
  55. package/esm/extension-codemirror/src/ExtensionCodeMirror.d.ts.map +0 -1
  56. package/esm/extension-codemirror/src/ExtensionCodeMirror.js +0 -4
  57. package/esm/extension-codemirror/src/NodeCodeMirror.d.ts +0 -27
  58. package/esm/extension-codemirror/src/NodeCodeMirror.d.ts.map +0 -1
  59. package/esm/extension-codemirror/src/NodeCodeMirror.js +0 -187
  60. package/esm/extension-codemirror/src/NodeDocumentCode.d.ts +0 -7
  61. package/esm/extension-codemirror/src/NodeDocumentCode.d.ts.map +0 -1
  62. package/esm/extension-codemirror/src/NodeDocumentCode.js +0 -37
  63. package/esm/extension-codemirror/src/codeMirrorBlockNodeView.d.ts +0 -6
  64. package/esm/extension-codemirror/src/codeMirrorBlockNodeView.d.ts.map +0 -1
  65. package/esm/extension-codemirror/src/codeMirrorBlockNodeView.js +0 -265
  66. package/esm/extension-codemirror/src/defaults.d.ts +0 -6
  67. package/esm/extension-codemirror/src/defaults.d.ts.map +0 -1
  68. package/esm/extension-codemirror/src/defaults.js +0 -57
  69. package/esm/extension-codemirror/src/languageLoaders.d.ts +0 -5
  70. package/esm/extension-codemirror/src/languageLoaders.d.ts.map +0 -1
  71. package/esm/extension-codemirror/src/languageLoaders.js +0 -113
  72. package/esm/extension-codemirror/src/languages.d.ts +0 -109
  73. package/esm/extension-codemirror/src/languages.d.ts.map +0 -1
  74. package/esm/extension-codemirror/src/languages.js +0 -110
  75. package/esm/extension-codemirror/src/types.d.ts +0 -29
  76. package/esm/extension-codemirror/src/types.d.ts.map +0 -1
  77. package/esm/extension-codemirror/src/types.js +0 -1
  78. package/esm/extension-codemirror/src/utils.d.ts +0 -39
  79. package/esm/extension-codemirror/src/utils.d.ts.map +0 -1
  80. package/esm/extension-codemirror/src/utils.js +0 -199
  81. package/esm/extension-codemirror/src/y-remote-selections.d.ts +0 -15
  82. package/esm/extension-codemirror/src/y-remote-selections.d.ts.map +0 -1
  83. package/esm/extension-codemirror/src/y-remote-selections.js +0 -273
  84. package/esm/extension-codemirror/src/y-sync.d.ts +0 -11
  85. package/esm/extension-codemirror/src/y-sync.d.ts.map +0 -1
  86. package/esm/extension-codemirror/src/y-sync.js +0 -29
  87. package/esm/package.json +0 -3
@@ -1,6 +0,0 @@
1
- export * from './CoreEditor.js';
2
- export * from './Extension.js';
3
- export * from './Mark.js';
4
- export * from './Node.js';
5
- export * from './nodeToTreeString.js';
6
- //# sourceMappingURL=mod.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/editor/src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC"}
@@ -1,5 +0,0 @@
1
- export * from './CoreEditor.js';
2
- export * from './Extension.js';
3
- export * from './Mark.js';
4
- export * from './Node.js';
5
- export * from './nodeToTreeString.js';
@@ -1,4 +0,0 @@
1
- import { Node } from 'prosemirror-model';
2
- export declare function nodeToTreeString(node: Node | Node[] | readonly Node[], level?: number, currentPos?: number): string;
3
- export declare function debugNode(node: Node | Node[]): void;
4
- //# sourceMappingURL=nodeToTreeString.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nodeToTreeString.d.ts","sourceRoot":"","sources":["../../../src/editor/src/nodeToTreeString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAYzC,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,GAAG,SAAS,IAAI,EAAE,EACrC,KAAK,SAAI,EACT,UAAU,SAAI,UA0Df;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,QAE5C"}
@@ -1,56 +0,0 @@
1
- function trimText(str, maxLen = 20) {
2
- str = str.replaceAll('\n', '\\n');
3
- if (str.length <= maxLen) {
4
- return str;
5
- }
6
- return str.slice(0, maxLen) + '...';
7
- }
8
- export function nodeToTreeString(node, level = 0, currentPos = 0) {
9
- let delim = '';
10
- for (let i = 0; i < level; i++) {
11
- delim += ' ';
12
- }
13
- let output = '';
14
- if (Array.isArray(node)) {
15
- for (const child of node) {
16
- output += delim +
17
- nodeToTreeString(child, level + 1, currentPos).replace(/\s+$/gm, '') +
18
- '\n';
19
- }
20
- return output;
21
- }
22
- // https://prosemirror.net/docs/guide/#doc.indexing
23
- let line = '';
24
- // if (node.type) {
25
- line += ` - [${node.type.name}] `;
26
- // } else {
27
- // line += ` - `;
28
- // }
29
- line += `pos: ${currentPos}, `;
30
- line += `nodeSize: ${node.nodeSize}, `; // isLeaf ? 1 : 2 + this.content.size
31
- line += `epos: ${currentPos + node.nodeSize}, `; // isLeaf ? 1 : 2 + this.content.size
32
- if (node.content) {
33
- line += `fragment.size: ${node.content.size}, `;
34
- }
35
- output += (delim + line) + '\n';
36
- let marksLine = '';
37
- if (node.marks) {
38
- for (const mark of node.marks) {
39
- marksLine += `(${mark.type.name}), `;
40
- }
41
- }
42
- if (marksLine) {
43
- output += (delim + ' ' + marksLine) + '\n';
44
- }
45
- if (node.text) {
46
- output += (delim + ' "' + trimText(node.text) + '"') + '\n';
47
- }
48
- node.forEach((child, offset) => {
49
- output +=
50
- nodeToTreeString(child, level + 1, currentPos + offset + 1).replace(/\s+$/gm, '') + '\n'; // + (node.isLeaf ? 1 : 2)
51
- });
52
- return output;
53
- }
54
- export function debugNode(node) {
55
- console.debug(nodeToTreeString(node));
56
- }
@@ -1,23 +0,0 @@
1
- import { Command, EditorState, Plugin, Transaction } from 'prosemirror-state';
2
- export declare class InputRule {
3
- readonly match: RegExp;
4
- handler: (state: EditorState, match: RegExpMatchArray, start: number, end: number) => Transaction | null;
5
- undoable: boolean;
6
- inCode: boolean | 'only';
7
- constructor(match: RegExp, handler: string | ((state: EditorState, match: RegExpMatchArray, start: number, end: number) => Transaction | null), options?: {
8
- undoable?: boolean;
9
- inCode?: boolean | 'only';
10
- });
11
- }
12
- type PluginState = {
13
- transform: Transaction;
14
- from: number;
15
- to: number;
16
- text: string;
17
- } | null;
18
- export declare class InputRulesPlugin extends Plugin<PluginState> {
19
- constructor(rules: readonly InputRule[]);
20
- }
21
- export declare const undoInputRule: Command;
22
- export {};
23
- //# sourceMappingURL=InputRulesPlugin.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InputRulesPlugin.d.ts","sourceRoot":"","sources":["../../../../../src/editor/src/plugins/input-rules/InputRulesPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,WAAW,EACX,MAAM,EAEN,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAO3B,qBAAa,SAAS;IA8BlB,QAAQ,CAAC,KAAK,EAAE,MAAM;IA5BxB,OAAO,EAAE,CACP,KAAK,EAAE,WAAW,EAClB,KAAK,EAAE,gBAAgB,EACvB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,KACR,WAAW,GAAG,IAAI,CAAC;IAGxB,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC;gBAmBd,KAAK,EAAE,MAAM,EACtB,OAAO,EACH,MAAM,GACN,CAAC,CACD,KAAK,EAAE,WAAW,EAClB,KAAK,EAAE,gBAAgB,EACvB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,KACR,WAAW,GAAG,IAAI,CAAC,EAC1B,OAAO,GAAE;QAIP,QAAQ,CAAC,EAAE,OAAO,CAAC;QAInB,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;KACtB;CAST;AA0BD,KAAK,WAAW,GAAG;IACjB,SAAS,EAAE,WAAW,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,IAAI,CAAC;AAKT,qBAAa,gBAAiB,SAAQ,MAAM,CAAC,WAAW,CAAC;gBAC3C,KAAK,EAAE,SAAS,SAAS,EAAE;CAgCxC;AAsCD,eAAO,MAAM,aAAa,EAAE,OA4B3B,CAAC"}
@@ -1,163 +0,0 @@
1
- import { Plugin, } from 'prosemirror-state';
2
- /// Input rules are regular expressions describing a piece of text
3
- /// that, when typed, causes something to happen. This might be
4
- /// changing two dashes into an emdash, wrapping a paragraph starting
5
- /// with `"> "` into a blockquote, or something entirely different.
6
- export class InputRule {
7
- // :: (RegExp, union<string, (state: EditorState, match: [string], start: number, end: number) → ?Transaction>)
8
- /// Create an input rule. The rule applies when the user typed
9
- /// something and the text directly in front of the cursor matches
10
- /// `match`, which should end with `$`.
11
- ///
12
- /// The `handler` can be a string, in which case the matched text, or
13
- /// the first matched group in the regexp, is replaced by that
14
- /// string.
15
- ///
16
- /// Or a it can be a function, which will be called with the match
17
- /// array produced by
18
- /// [`RegExp.exec`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec),
19
- /// as well as the start and end of the matched range, and which can
20
- /// return a [transaction](#state.Transaction) that describes the
21
- /// rule's effect, or null to indicate the input was not handled.
22
- constructor(
23
- /// @internal
24
- match, handler, options = {}) {
25
- Object.defineProperty(this, "match", {
26
- enumerable: true,
27
- configurable: true,
28
- writable: true,
29
- value: match
30
- });
31
- /// @internal
32
- Object.defineProperty(this, "handler", {
33
- enumerable: true,
34
- configurable: true,
35
- writable: true,
36
- value: void 0
37
- });
38
- /// @internal
39
- Object.defineProperty(this, "undoable", {
40
- enumerable: true,
41
- configurable: true,
42
- writable: true,
43
- value: void 0
44
- });
45
- Object.defineProperty(this, "inCode", {
46
- enumerable: true,
47
- configurable: true,
48
- writable: true,
49
- value: void 0
50
- });
51
- this.match = match;
52
- this.handler = typeof handler == 'string'
53
- ? stringHandler(handler)
54
- : handler;
55
- this.undoable = options.undoable !== false;
56
- this.inCode = options.inCode || false;
57
- }
58
- }
59
- function stringHandler(string) {
60
- return function (state, match, start, end) {
61
- let insert = string;
62
- if (match[1]) {
63
- let offset = match[0].lastIndexOf(match[1]);
64
- insert += match[0].slice(offset + match[1].length);
65
- start += offset;
66
- let cutOff = start - end;
67
- if (cutOff > 0) {
68
- insert = match[0].slice(offset - cutOff, offset) + insert;
69
- start = end;
70
- }
71
- }
72
- return state.tr.insertText(insert, start, end);
73
- };
74
- }
75
- const MAX_MATCH = 500;
76
- /// Create an input rules plugin. When enabled, it will cause text
77
- /// input that matches any of the given rules to trigger the rule's
78
- /// action.
79
- export class InputRulesPlugin extends Plugin {
80
- constructor(rules) {
81
- super({
82
- state: {
83
- init() {
84
- return null;
85
- },
86
- apply(tr, prev) {
87
- let stored = tr.getMeta(this);
88
- if (stored)
89
- return stored;
90
- return tr.selectionSet || tr.docChanged ? null : prev;
91
- },
92
- },
93
- props: {
94
- handleTextInput(view, from, to, text) {
95
- return run(view, from, to, text, rules, InputRulesPlugin);
96
- },
97
- handleDOMEvents: {
98
- compositionend: (view) => {
99
- setTimeout(() => {
100
- let { $cursor } = view.state.selection;
101
- if ($cursor) {
102
- run(view, $cursor.pos, $cursor.pos, '', rules, plugin);
103
- }
104
- });
105
- },
106
- },
107
- },
108
- isInputRules: true,
109
- });
110
- }
111
- }
112
- function run(view, from, to, text, rules, plugin) {
113
- if (view.composing)
114
- return false;
115
- let state = view.state, $from = state.doc.resolve(from);
116
- let textBefore = $from.parent.textBetween(Math.max(0, $from.parentOffset - MAX_MATCH), $from.parentOffset, null, '\ufffc') + text;
117
- for (let i = 0; i < rules.length; i++) {
118
- let rule = rules[i];
119
- if ($from.parent.type.spec.code) {
120
- if (!rule.inCode)
121
- continue;
122
- }
123
- else if (rule.inCode === 'only') {
124
- continue;
125
- }
126
- let match = rule.match.exec(textBefore);
127
- let tr = match &&
128
- rule.handler(state, match, from - (match[0].length - text.length), to);
129
- if (!tr)
130
- continue;
131
- if (rule.undoable)
132
- tr.setMeta(plugin, { transform: tr, from, to, text });
133
- view.dispatch(tr);
134
- return true;
135
- }
136
- return false;
137
- }
138
- /// This is a command that will undo an input rule, if applying such a
139
- /// rule was the last thing that the user did.
140
- export const undoInputRule = (state, dispatch) => {
141
- let plugins = state.plugins;
142
- for (let i = 0; i < plugins.length; i++) {
143
- let plugin = plugins[i], undoable;
144
- if (plugin.spec.isInputRules && (undoable = plugin.getState(state))) {
145
- if (dispatch) {
146
- let tr = state.tr, toUndo = undoable.transform;
147
- for (let j = toUndo.steps.length - 1; j >= 0; j--) {
148
- tr.step(toUndo.steps[j].invert(toUndo.docs[j]));
149
- }
150
- if (undoable.text) {
151
- let marks = tr.doc.resolve(undoable.from).marks();
152
- tr.replaceWith(undoable.from, undoable.to, state.schema.text(undoable.text, marks));
153
- }
154
- else {
155
- tr.delete(undoable.from, undoable.to);
156
- }
157
- dispatch(tr);
158
- }
159
- return true;
160
- }
161
- }
162
- return false;
163
- };
@@ -1,3 +0,0 @@
1
- export * from './InputRulesPlugin.js';
2
- export * from './rulebuilders.js';
3
- //# sourceMappingURL=mod.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../../src/editor/src/plugins/input-rules/mod.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from './InputRulesPlugin.js';
2
- export * from './rulebuilders.js';
@@ -1,5 +0,0 @@
1
- import { Attrs, Node, NodeType } from 'prosemirror-model';
2
- import { InputRule } from './InputRulesPlugin.js';
3
- export declare function wrappingInputRule(regexp: RegExp, nodeType: NodeType, getAttrs?: Attrs | null | ((matches: RegExpMatchArray) => Attrs | null), joinPredicate?: (match: RegExpMatchArray, node: Node) => boolean): InputRule;
4
- export declare function textblockTypeInputRule(regexp: RegExp, nodeType: NodeType, getAttrs?: Attrs | null | ((match: RegExpMatchArray) => Attrs | null)): InputRule;
5
- //# sourceMappingURL=rulebuilders.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rulebuilders.d.ts","sourceRoot":"","sources":["../../../../../src/editor/src/plugins/input-rules/rulebuilders.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAiBlD,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,QAAQ,GAAE,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,gBAAgB,KAAK,KAAK,GAAG,IAAI,CAAQ,EAC7E,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE,IAAI,KAAK,OAAO,aAmBjE;AAQD,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,QAAQ,GAAE,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,gBAAgB,KAAK,KAAK,GAAG,IAAI,CAAQ,aAgB5E"}
@@ -1,50 +0,0 @@
1
- import { canJoin, findWrapping } from 'prosemirror-transform';
2
- import { InputRule } from './InputRulesPlugin.js';
3
- /// Build an input rule for automatically wrapping a textblock when a
4
- /// given string is typed. The `regexp` argument is
5
- /// directly passed through to the `InputRule` constructor. You'll
6
- /// probably want the regexp to start with `^`, so that the pattern can
7
- /// only occur at the start of a textblock.
8
- ///
9
- /// `nodeType` is the type of node to wrap in. If it needs attributes,
10
- /// you can either pass them directly, or pass a function that will
11
- /// compute them from the regular expression match.
12
- ///
13
- /// By default, if there's a node with the same type above the newly
14
- /// wrapped node, the rule will try to [join](#transform.Transform.join) those
15
- /// two nodes. You can pass a join predicate, which takes a regular
16
- /// expression match and the node before the wrapped node, and can
17
- /// return a boolean to indicate whether a join should happen.
18
- export function wrappingInputRule(regexp, nodeType, getAttrs = null, joinPredicate) {
19
- return new InputRule(regexp, (state, match, start, end) => {
20
- let attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs;
21
- let tr = state.tr.delete(start, end);
22
- let $start = tr.doc.resolve(start), range = $start.blockRange(), wrapping = range && findWrapping(range, nodeType, attrs);
23
- if (!wrapping)
24
- return null;
25
- tr.wrap(range, wrapping);
26
- let before = tr.doc.resolve(start - 1).nodeBefore;
27
- if (before && before.type == nodeType && canJoin(tr.doc, start - 1) &&
28
- (!joinPredicate || joinPredicate(match, before))) {
29
- tr.join(start - 1);
30
- }
31
- return tr;
32
- });
33
- }
34
- /// Build an input rule that changes the type of a textblock when the
35
- /// matched text is typed into it. You'll usually want to start your
36
- /// regexp with `^` to that it is only matched at the start of a
37
- /// textblock. The optional `getAttrs` parameter can be used to compute
38
- /// the new node's attributes, and works the same as in the
39
- /// `wrappingInputRule` function.
40
- export function textblockTypeInputRule(regexp, nodeType, getAttrs = null) {
41
- return new InputRule(regexp, (state, match, start, end) => {
42
- let $start = state.doc.resolve(start);
43
- let attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs;
44
- if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType))
45
- return null;
46
- return state.tr
47
- .delete(start, end)
48
- .setBlockType(start, start, nodeType, attrs);
49
- });
50
- }
@@ -1,29 +0,0 @@
1
- import type { ParseOptions } from 'prosemirror-model';
2
- import type { Extension } from './Extension.js';
3
- import type { Mark } from './Mark.js';
4
- import type { Node } from './Node.js';
5
- export type AnyExtension = (Extension | Node | Mark) & {
6
- requires: Set<AnyExtension | string>;
7
- };
8
- export type Extensions = AnyExtension[];
9
- export type Content = JSONContent | JSONContent[] | null;
10
- export interface EditorOptions {
11
- element: Element;
12
- content: Content;
13
- parseOptions: ParseOptions;
14
- extensions: Extensions;
15
- topNode?: string;
16
- }
17
- export type JSONContent = {
18
- type?: string;
19
- attrs?: Record<string, any>;
20
- content?: JSONContent[];
21
- marks?: {
22
- type: string;
23
- attrs?: Record<string, any>;
24
- [key: string]: any;
25
- }[];
26
- text?: string;
27
- [key: string]: any;
28
- };
29
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/editor/src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,MAAM,YAAY,GAAG,CAAC,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC,GAAG;IACrD,QAAQ,EAAE,GAAG,CAAC,YAAY,GAAG,MAAM,CAAC,CAAC;CACtC,CAAC;AACF,MAAM,MAAM,UAAU,GAAG,YAAY,EAAE,CAAC;AAExC,MAAM,MAAM,OAAO,GAAG,WAAW,GAAG,WAAW,EAAE,GAAG,IAAI,CAAC;AAEzD,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,YAAY,CAAC;IAC3B,UAAU,EAAE,UAAU,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,OAAO,CAAC,EAAE,WAAW,EAAE,CAAC;IACxB,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,EAAE,CAAC;IACJ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,CAAC"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,8 +0,0 @@
1
- import { Fragment, Node as ProseMirrorNode, Schema } from 'prosemirror-model';
2
- import type { Content } from '../types.js';
3
- export type CreateNodeFromContentOptions = {
4
- errorOnInvalidContent?: boolean;
5
- };
6
- export declare function createNodeFromObject(content: Content | ProseMirrorNode | Fragment, schema: Schema, options?: CreateNodeFromContentOptions): ProseMirrorNode | Fragment;
7
- export declare function createNodeFromContent(content: Content | ProseMirrorNode | Fragment, schema: Schema, options?: CreateNodeFromContentOptions): ProseMirrorNode | Fragment;
8
- //# sourceMappingURL=createNodeFromContent.d.ts.map
@@ -1 +0,0 @@
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,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,MAAM,4BAA4B,GAAG;IACzC,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC,CAAC;AAEF,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,OAAO,GAAG,eAAe,GAAG,QAAQ,EAC7C,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,4BAA4B,GACrC,eAAe,GAAG,QAAQ,CAiC5B;AAED,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,OAAO,GAAG,eAAe,GAAG,QAAQ,EAC7C,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,4BAA4B,GACrC,eAAe,GAAG,QAAQ,CAY5B"}
@@ -1,33 +0,0 @@
1
- import { Fragment, Node as ProseMirrorNode } from 'prosemirror-model';
2
- export function createNodeFromObject(content, schema, options) {
3
- try {
4
- // if the JSON Content is an array of nodes, create a fragment for each node
5
- if (Array.isArray(content) && content.length > 0) {
6
- return Fragment.fromArray(content.map((item) => schema.nodeFromJSON(item)));
7
- }
8
- const node = schema.nodeFromJSON(content);
9
- if (options?.errorOnInvalidContent) {
10
- node.check();
11
- }
12
- return node;
13
- }
14
- catch (error) {
15
- if (options?.errorOnInvalidContent) {
16
- throw new Error('Invalid JSON content', {
17
- cause: error,
18
- });
19
- }
20
- console.warn('Invalid content.', 'Passed value:', content, 'Error:', error);
21
- return schema.topNodeType.createAndFill(null, []);
22
- }
23
- }
24
- export function createNodeFromContent(content, schema, options) {
25
- if (content instanceof ProseMirrorNode || content instanceof Fragment) {
26
- return content;
27
- }
28
- const isJSONContent = typeof content === 'object' && content !== null;
29
- if (isJSONContent) {
30
- createNodeFromObject(content, schema, options);
31
- }
32
- return schema.topNodeType.createAndFill(null, []);
33
- }
@@ -1,4 +0,0 @@
1
- export declare function getHtmlAttributes(extension: any, node: any): {};
2
- export declare function setHtmlAttributes(extension: any, element: any): {};
3
- export declare function addAttributesToSchema(spec: any, extension: any): void;
4
- //# sourceMappingURL=getHtmlAttributes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getHtmlAttributes.d.ts","sourceRoot":"","sources":["../../../../src/editor/src/utilities/getHtmlAttributes.ts"],"names":[],"mappings":"AAAA,wBAAgB,iBAAiB,CAAC,SAAS,KAAA,EAAE,IAAI,KAAA,MAkBhD;AAED,wBAAgB,iBAAiB,CAAC,SAAS,KAAA,EAAE,OAAO,KAAA,MAcnD;AAED,wBAAgB,qBAAqB,CAAC,IAAI,KAAA,EAAE,SAAS,KAAA,QAcpD"}
@@ -1,47 +0,0 @@
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
- }
@@ -1,3 +0,0 @@
1
- export * from './getHtmlAttributes.js';
2
- export * from './createNodeFromContent.js';
3
- //# sourceMappingURL=mod.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../src/editor/src/utilities/mod.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from './getHtmlAttributes.js';
2
- export * from './createNodeFromContent.js';
@@ -1,5 +0,0 @@
1
- export * from './NodeDocumentCode.js';
2
- export * from './NodeCodeMirror.js';
3
- export declare class ExtensionCodeMirror {
4
- }
5
- //# sourceMappingURL=ExtensionCodeMirror.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ExtensionCodeMirror.d.ts","sourceRoot":"","sources":["../../../src/extension-codemirror/src/ExtensionCodeMirror.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AAEpC,qBAAa,mBAAmB;CAC/B"}
@@ -1,4 +0,0 @@
1
- export * from './NodeDocumentCode.js';
2
- export * from './NodeCodeMirror.js';
3
- export class ExtensionCodeMirror {
4
- }
@@ -1,27 +0,0 @@
1
- import { Plugin, PluginKey } from 'prosemirror-state';
2
- import type { NodeSpec, NodeType, Schema } from 'prosemirror-model';
3
- import { Converter, type CoreEditor, Node } from '../../editor/src/mod.js';
4
- import { type Commands, type CommandShortcuts } from '../../editor/src/commands/mod.js';
5
- import { type InputRule } from '../../editor/src/plugins/input-rules/mod.js';
6
- export declare const codeMirrorBlockKey: PluginKey<any>;
7
- export declare class NodeCodeMirror extends Node {
8
- name: string;
9
- automerge: {
10
- block: string;
11
- attrParsers: {
12
- fromAutomerge: (block: any) => {
13
- lang: any;
14
- };
15
- fromProsemirror: (node: any) => {
16
- lang: any;
17
- };
18
- };
19
- };
20
- getConverters(editor: CoreEditor, schema: Schema): Record<string, Converter>;
21
- getNodeSpec(): NodeSpec;
22
- getInputRules(type: NodeType): InputRule[];
23
- getCommands(editor: CoreEditor, type: NodeType): Partial<Commands>;
24
- getKeyboardShortcuts(): Partial<CommandShortcuts>;
25
- getProseMirrorPlugins(editor: CoreEditor): Plugin[];
26
- }
27
- //# sourceMappingURL=NodeCodeMirror.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NodeCodeMirror.d.ts","sourceRoot":"","sources":["../../../src/extension-codemirror/src/NodeCodeMirror.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,EAAE,SAAS,EAAa,MAAM,mBAAmB,CAAC;AAC9E,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEpE,OAAO,EAAE,SAAS,EAAE,KAAK,UAAU,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,gBAAgB,EAEtB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,KAAK,SAAS,EAEf,MAAM,6CAA6C,CAAC;AAQrD,eAAO,MAAM,kBAAkB,gBAAoC,CAAC;AAoBpE,qBAAa,cAAe,SAAQ,IAAI;IAC7B,IAAI,SAAgB;IAG7B,SAAS;;;;;;;;;;MAMP;IAEO,aAAa,CACpB,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,MAAM,GACb,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;IAgDnB,WAAW,IAAI,QAAQ;IA0BvB,aAAa,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,EAAE;IAQ1C,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAUlE,oBAAoB,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAUjD,qBAAqB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,EAAE;CAkD7D"}