@vizel/core 0.0.1-alpha.3 → 0.0.1-alpha.4

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.d.ts CHANGED
@@ -2575,14 +2575,15 @@ export { }
2575
2575
 
2576
2576
  declare module "@tiptap/core" {
2577
2577
  interface Commands<ReturnType> {
2578
- diagram: {
2578
+ vizelBlockMove: {
2579
2579
  /**
2580
- * Insert a diagram block
2580
+ * Move the current block up
2581
2581
  */
2582
- insertDiagram: (options: {
2583
- code: string;
2584
- type?: VizelDiagramType;
2585
- }) => ReturnType;
2582
+ moveBlockUp: () => ReturnType;
2583
+ /**
2584
+ * Move the current block down
2585
+ */
2586
+ moveBlockDown: () => ReturnType;
2586
2587
  };
2587
2588
  }
2588
2589
  }
@@ -2590,15 +2591,14 @@ declare module "@tiptap/core" {
2590
2591
 
2591
2592
  declare module "@tiptap/core" {
2592
2593
  interface Commands<ReturnType> {
2593
- vizelBlockMove: {
2594
- /**
2595
- * Move the current block up
2596
- */
2597
- moveBlockUp: () => ReturnType;
2594
+ diagram: {
2598
2595
  /**
2599
- * Move the current block down
2596
+ * Insert a diagram block
2600
2597
  */
2601
- moveBlockDown: () => ReturnType;
2598
+ insertDiagram: (options: {
2599
+ code: string;
2600
+ type?: VizelDiagramType;
2601
+ }) => ReturnType;
2602
2602
  };
2603
2603
  }
2604
2604
  }
package/dist/index35.js CHANGED
@@ -1,4 +1,4 @@
1
- import { CharacterCount as a } from "./index49.js";
1
+ import { CharacterCount as a } from "./index48.js";
2
2
  var t = a;
3
3
  export {
4
4
  a as CharacterCount,
package/dist/index37.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Node as L, createBlockMarkdownSpec as N, isActive as F, findChildren as b, defaultBlockAt as x, findParentNode as w, mergeAttributes as v } from "@tiptap/core";
2
2
  import { Plugin as z, PluginKey as G, TextSelection as R, Selection as D } from "./index38.js";
3
- import { GapCursor as H } from "./index48.js";
3
+ import { GapCursor as H } from "./index49.js";
4
4
  var S = (t, s) => s.view.domAtPos(t).node.offsetParent !== null, W = (t, s, o) => {
5
5
  for (let e = t.depth; e > 0; e -= 1) {
6
6
  const n = t.node(e), c = s(n), r = S(t.start(e), o);
package/dist/index48.js CHANGED
@@ -1,204 +1,288 @@
1
- import { keydownHandler as v } from "./index66.js";
2
- import { Plugin as w, TextSelection as m, NodeSelection as x, Selection as u } from "./index38.js";
3
- import { Fragment as h, Slice as g } from "./index57.js";
4
- import { DecorationSet as S, Decoration as A } from "./index50.js";
5
- class i extends u {
6
- /**
7
- Create a gap cursor.
8
- */
9
- constructor(e) {
10
- super(e, e);
11
- }
12
- map(e, t) {
13
- let o = e.resolve(t.map(this.head));
14
- return i.valid(o) ? new i(o) : u.near(o);
15
- }
16
- content() {
17
- return g.empty;
18
- }
19
- eq(e) {
20
- return e instanceof i && e.head == this.head;
21
- }
22
- toJSON() {
23
- return { type: "gapcursor", pos: this.head };
24
- }
25
- /**
26
- @internal
27
- */
28
- static fromJSON(e, t) {
29
- if (typeof t.pos != "number")
30
- throw new RangeError("Invalid input for GapCursor.fromJSON");
31
- return new i(e.resolve(t.pos));
32
- }
33
- /**
34
- @internal
35
- */
36
- getBookmark() {
37
- return new d(this.anchor);
1
+ import { Extension as u, callOrReturn as w, getExtensionField as S, isNodeEmpty as P, isNodeSelection as v } from "@tiptap/core";
2
+ import { Plugin as p, PluginKey as m } from "./index38.js";
3
+ import { dropCursor as z } from "./index54.js";
4
+ import { DecorationSet as f, Decoration as g } from "./index50.js";
5
+ import { gapCursor as E } from "./index49.js";
6
+ import { history as M, redo as N, undo as O } from "./index55.js";
7
+ var k = u.create({
8
+ name: "characterCount",
9
+ addOptions() {
10
+ return {
11
+ limit: null,
12
+ mode: "textSize",
13
+ textCounter: (e) => e.length,
14
+ wordCounter: (e) => e.split(" ").filter((t) => t !== "").length
15
+ };
16
+ },
17
+ addStorage() {
18
+ return {
19
+ characters: () => 0,
20
+ words: () => 0
21
+ };
22
+ },
23
+ onBeforeCreate() {
24
+ this.storage.characters = (e) => {
25
+ const t = e?.node || this.editor.state.doc;
26
+ if ((e?.mode || this.options.mode) === "textSize") {
27
+ const r = t.textBetween(0, t.content.size, void 0, " ");
28
+ return this.options.textCounter(r);
29
+ }
30
+ return t.nodeSize;
31
+ }, this.storage.words = (e) => {
32
+ const t = e?.node || this.editor.state.doc, n = t.textBetween(0, t.content.size, " ", " ");
33
+ return this.options.wordCounter(n);
34
+ };
35
+ },
36
+ addProseMirrorPlugins() {
37
+ let e = !1;
38
+ return [
39
+ new p({
40
+ key: new m("characterCount"),
41
+ appendTransaction: (t, n, r) => {
42
+ if (e)
43
+ return;
44
+ const o = this.options.limit;
45
+ if (o == null || o === 0) {
46
+ e = !0;
47
+ return;
48
+ }
49
+ const s = this.storage.characters({ node: r.doc });
50
+ if (s > o) {
51
+ const i = s - o, d = 0, a = i;
52
+ console.warn(
53
+ `[CharacterCount] Initial content exceeded limit of ${o} characters. Content was automatically trimmed.`
54
+ );
55
+ const c = r.tr.deleteRange(d, a);
56
+ return e = !0, c;
57
+ }
58
+ e = !0;
59
+ },
60
+ filterTransaction: (t, n) => {
61
+ const r = this.options.limit;
62
+ if (!t.docChanged || r === 0 || r === null || r === void 0)
63
+ return !0;
64
+ const o = this.storage.characters({ node: n.doc }), s = this.storage.characters({ node: t.doc });
65
+ if (s <= r || o > r && s > r && s <= o)
66
+ return !0;
67
+ if (o > r && s > r && s > o || !t.getMeta("paste"))
68
+ return !1;
69
+ const d = t.selection.$head.pos, a = s - r, c = d - a, l = d;
70
+ return t.deleteRange(c, l), !(this.storage.characters({ node: t.doc }) > r);
71
+ }
72
+ })
73
+ ];
38
74
  }
39
- /**
40
- @internal
41
- */
42
- static valid(e) {
43
- let t = e.parent;
44
- if (t.isTextblock || !b(e) || !y(e))
45
- return !1;
46
- let o = t.type.spec.allowGapCursor;
47
- if (o != null)
48
- return o;
49
- let r = t.contentMatchAt(e.index()).defaultType;
50
- return r && r.isTextblock;
75
+ });
76
+ u.create({
77
+ name: "dropCursor",
78
+ addOptions() {
79
+ return {
80
+ color: "currentColor",
81
+ width: 1,
82
+ class: void 0
83
+ };
84
+ },
85
+ addProseMirrorPlugins() {
86
+ return [z(this.options)];
51
87
  }
52
- /**
53
- @internal
54
- */
55
- static findGapCursorFrom(e, t, o = !1) {
56
- e: for (; ; ) {
57
- if (!o && i.valid(e))
58
- return e;
59
- let r = e.pos, s = null;
60
- for (let l = e.depth; ; l--) {
61
- let a = e.node(l);
62
- if (t > 0 ? e.indexAfter(l) < a.childCount : e.index(l) > 0) {
63
- s = a.child(t > 0 ? e.indexAfter(l) : e.index(l) - 1);
64
- break;
65
- } else if (l == 0)
66
- return null;
67
- r += t;
68
- let f = e.doc.resolve(r);
69
- if (i.valid(f))
70
- return f;
71
- }
72
- for (; ; ) {
73
- let l = t > 0 ? s.firstChild : s.lastChild;
74
- if (!l) {
75
- if (s.isAtom && !s.isText && !x.isSelectable(s)) {
76
- e = e.doc.resolve(r + s.nodeSize * t), o = !1;
77
- continue e;
88
+ });
89
+ u.create({
90
+ name: "focus",
91
+ addOptions() {
92
+ return {
93
+ className: "has-focus",
94
+ mode: "all"
95
+ };
96
+ },
97
+ addProseMirrorPlugins() {
98
+ return [
99
+ new p({
100
+ key: new m("focus"),
101
+ props: {
102
+ decorations: ({ doc: e, selection: t }) => {
103
+ const { isEditable: n, isFocused: r } = this.editor, { anchor: o } = t, s = [];
104
+ if (!n || !r)
105
+ return f.create(e, []);
106
+ let i = 0;
107
+ this.options.mode === "deepest" && e.descendants((a, c) => {
108
+ if (a.isText)
109
+ return;
110
+ if (!(o >= c && o <= c + a.nodeSize - 1))
111
+ return !1;
112
+ i += 1;
113
+ });
114
+ let d = 0;
115
+ return e.descendants((a, c) => {
116
+ if (a.isText || !(o >= c && o <= c + a.nodeSize - 1))
117
+ return !1;
118
+ if (d += 1, this.options.mode === "deepest" && i - d > 0 || this.options.mode === "shallowest" && d > 1)
119
+ return this.options.mode === "deepest";
120
+ s.push(
121
+ g.node(c, c + a.nodeSize, {
122
+ class: this.options.className
123
+ })
124
+ );
125
+ }), f.create(e, s);
78
126
  }
79
- break;
80
127
  }
81
- s = l, r += t;
82
- let a = e.doc.resolve(r);
83
- if (i.valid(a))
84
- return a;
85
- }
86
- return null;
87
- }
128
+ })
129
+ ];
88
130
  }
89
- }
90
- i.prototype.visible = !1;
91
- i.findFrom = i.findGapCursorFrom;
92
- u.jsonID("gapcursor", i);
93
- class d {
94
- constructor(e) {
95
- this.pos = e;
131
+ });
132
+ u.create({
133
+ name: "gapCursor",
134
+ addProseMirrorPlugins() {
135
+ return [E()];
136
+ },
137
+ extendNodeSchema(e) {
138
+ var t;
139
+ const n = {
140
+ name: e.name,
141
+ options: e.options,
142
+ storage: e.storage
143
+ };
144
+ return {
145
+ allowGapCursor: (t = w(S(e, "allowGapCursor", n))) != null ? t : null
146
+ };
96
147
  }
97
- map(e) {
98
- return new d(e.map(this.pos));
148
+ });
149
+ u.create({
150
+ name: "placeholder",
151
+ addOptions() {
152
+ return {
153
+ emptyEditorClass: "is-editor-empty",
154
+ emptyNodeClass: "is-empty",
155
+ placeholder: "Write something …",
156
+ showOnlyWhenEditable: !0,
157
+ showOnlyCurrent: !0,
158
+ includeChildren: !1
159
+ };
160
+ },
161
+ addProseMirrorPlugins() {
162
+ return [
163
+ new p({
164
+ key: new m("placeholder"),
165
+ props: {
166
+ decorations: ({ doc: e, selection: t }) => {
167
+ const n = this.editor.isEditable || !this.options.showOnlyWhenEditable, { anchor: r } = t, o = [];
168
+ if (!n)
169
+ return null;
170
+ const s = this.editor.isEmpty;
171
+ return e.descendants((i, d) => {
172
+ const a = r >= d && r <= d + i.nodeSize, c = !i.isLeaf && P(i);
173
+ if ((a || !this.options.showOnlyCurrent) && c) {
174
+ const l = [this.options.emptyNodeClass];
175
+ s && l.push(this.options.emptyEditorClass);
176
+ const h = g.node(d, d + i.nodeSize, {
177
+ class: l.join(" "),
178
+ "data-placeholder": typeof this.options.placeholder == "function" ? this.options.placeholder({
179
+ editor: this.editor,
180
+ node: i,
181
+ pos: d,
182
+ hasAnchor: a
183
+ }) : this.options.placeholder
184
+ });
185
+ o.push(h);
186
+ }
187
+ return this.options.includeChildren;
188
+ }), f.create(e, o);
189
+ }
190
+ }
191
+ })
192
+ ];
99
193
  }
100
- resolve(e) {
101
- let t = e.resolve(this.pos);
102
- return i.valid(t) ? new i(t) : u.near(t);
194
+ });
195
+ u.create({
196
+ name: "selection",
197
+ addOptions() {
198
+ return {
199
+ className: "selection"
200
+ };
201
+ },
202
+ addProseMirrorPlugins() {
203
+ const { editor: e, options: t } = this;
204
+ return [
205
+ new p({
206
+ key: new m("selection"),
207
+ props: {
208
+ decorations(n) {
209
+ return n.selection.empty || e.isFocused || !e.isEditable || v(n.selection) || e.view.dragging ? null : f.create(n.doc, [
210
+ g.inline(n.selection.from, n.selection.to, {
211
+ class: t.className
212
+ })
213
+ ]);
214
+ }
215
+ }
216
+ })
217
+ ];
103
218
  }
219
+ });
220
+ function C({ types: e, node: t }) {
221
+ return t && Array.isArray(e) && e.includes(t.type) || t?.type === e;
104
222
  }
105
- function C(n) {
106
- return n.isAtom || n.spec.isolating || n.spec.createGapCursor;
107
- }
108
- function b(n) {
109
- for (let e = n.depth; e >= 0; e--) {
110
- let t = n.index(e), o = n.node(e);
111
- if (t == 0) {
112
- if (o.type.spec.isolating)
113
- return !0;
114
- continue;
115
- }
116
- for (let r = o.child(t - 1); ; r = r.lastChild) {
117
- if (r.childCount == 0 && !r.inlineContent || C(r.type))
118
- return !0;
119
- if (r.inlineContent)
120
- return !1;
121
- }
223
+ u.create({
224
+ name: "trailingNode",
225
+ addOptions() {
226
+ return {
227
+ node: void 0,
228
+ notAfter: []
229
+ };
230
+ },
231
+ addProseMirrorPlugins() {
232
+ var e;
233
+ const t = new m(this.name), n = this.options.node || ((e = this.editor.schema.topNodeType.contentMatch.defaultType) == null ? void 0 : e.name) || "paragraph", r = Object.entries(this.editor.schema.nodes).map(([, o]) => o).filter((o) => (this.options.notAfter || []).concat(n).includes(o.name));
234
+ return [
235
+ new p({
236
+ key: t,
237
+ appendTransaction: (o, s, i) => {
238
+ const { doc: d, tr: a, schema: c } = i, l = t.getState(i), h = d.content.size, y = c.nodes[n];
239
+ if (l)
240
+ return a.insert(h, y.create());
241
+ },
242
+ state: {
243
+ init: (o, s) => {
244
+ const i = s.tr.doc.lastChild;
245
+ return !C({ node: i, types: r });
246
+ },
247
+ apply: (o, s) => {
248
+ if (!o.docChanged || o.getMeta("__uniqueIDTransaction"))
249
+ return s;
250
+ const i = o.doc.lastChild;
251
+ return !C({ node: i, types: r });
252
+ }
253
+ }
254
+ })
255
+ ];
122
256
  }
123
- return !0;
124
- }
125
- function y(n) {
126
- for (let e = n.depth; e >= 0; e--) {
127
- let t = n.indexAfter(e), o = n.node(e);
128
- if (t == o.childCount) {
129
- if (o.type.spec.isolating)
130
- return !0;
131
- continue;
132
- }
133
- for (let r = o.child(t); ; r = r.firstChild) {
134
- if (r.childCount == 0 && !r.inlineContent || C(r.type))
135
- return !0;
136
- if (r.inlineContent)
137
- return !1;
138
- }
257
+ });
258
+ u.create({
259
+ name: "undoRedo",
260
+ addOptions() {
261
+ return {
262
+ depth: 100,
263
+ newGroupDelay: 500
264
+ };
265
+ },
266
+ addCommands() {
267
+ return {
268
+ undo: () => ({ state: e, dispatch: t }) => O(e, t),
269
+ redo: () => ({ state: e, dispatch: t }) => N(e, t)
270
+ };
271
+ },
272
+ addProseMirrorPlugins() {
273
+ return [M(this.options)];
274
+ },
275
+ addKeyboardShortcuts() {
276
+ return {
277
+ "Mod-z": () => this.editor.commands.undo(),
278
+ "Shift-Mod-z": () => this.editor.commands.redo(),
279
+ "Mod-y": () => this.editor.commands.redo(),
280
+ // Russian keyboard layouts
281
+ "Mod-я": () => this.editor.commands.undo(),
282
+ "Shift-Mod-я": () => this.editor.commands.redo()
283
+ };
139
284
  }
140
- return !0;
141
- }
142
- function B() {
143
- return new w({
144
- props: {
145
- decorations: F,
146
- createSelectionBetween(n, e, t) {
147
- return e.pos == t.pos && i.valid(t) ? new i(t) : null;
148
- },
149
- handleClick: T,
150
- handleKeyDown: k,
151
- handleDOMEvents: { beforeinput: D }
152
- }
153
- });
154
- }
155
- const k = v({
156
- ArrowLeft: c("horiz", -1),
157
- ArrowRight: c("horiz", 1),
158
- ArrowUp: c("vert", -1),
159
- ArrowDown: c("vert", 1)
160
285
  });
161
- function c(n, e) {
162
- const t = n == "vert" ? e > 0 ? "down" : "up" : e > 0 ? "right" : "left";
163
- return function(o, r, s) {
164
- let l = o.selection, a = e > 0 ? l.$to : l.$from, f = l.empty;
165
- if (l instanceof m) {
166
- if (!s.endOfTextblock(t) || a.depth == 0)
167
- return !1;
168
- f = !1, a = o.doc.resolve(e > 0 ? a.after() : a.before());
169
- }
170
- let p = i.findGapCursorFrom(a, e, f);
171
- return p ? (r && r(o.tr.setSelection(new i(p))), !0) : !1;
172
- };
173
- }
174
- function T(n, e, t) {
175
- if (!n || !n.editable)
176
- return !1;
177
- let o = n.state.doc.resolve(e);
178
- if (!i.valid(o))
179
- return !1;
180
- let r = n.posAtCoords({ left: t.clientX, top: t.clientY });
181
- return r && r.inside > -1 && x.isSelectable(n.state.doc.nodeAt(r.inside)) ? !1 : (n.dispatch(n.state.tr.setSelection(new i(o))), !0);
182
- }
183
- function D(n, e) {
184
- if (e.inputType != "insertCompositionText" || !(n.state.selection instanceof i))
185
- return !1;
186
- let { $from: t } = n.state.selection, o = t.parent.contentMatchAt(t.index()).findWrapping(n.state.schema.nodes.text);
187
- if (!o)
188
- return !1;
189
- let r = h.empty;
190
- for (let l = o.length - 1; l >= 0; l--)
191
- r = h.from(o[l].createAndFill(null, r));
192
- let s = n.state.tr.replace(t.pos, t.pos, new g(r, 0, 0));
193
- return s.setSelection(m.near(s.doc.resolve(t.pos + 1))), n.dispatch(s), !1;
194
- }
195
- function F(n) {
196
- if (!(n.selection instanceof i))
197
- return null;
198
- let e = document.createElement("div");
199
- return e.className = "ProseMirror-gapcursor", S.create(n.doc, [A.widget(n.selection.head, e, { key: "gapcursor" })]);
200
- }
201
286
  export {
202
- i as GapCursor,
203
- B as gapCursor
287
+ k as CharacterCount
204
288
  };