@kerebron/legacy-compat 0.8.4 → 0.8.5

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/kerebron.js CHANGED
@@ -7093,6 +7093,350 @@ function setPathValue(e, t, n) {
7093
7093
  }
7094
7094
  }
7095
7095
  //#endregion
7096
+ //#region ../editor/src/search/query.ts
7097
+ var SearchQuery = class {
7098
+ search;
7099
+ caseSensitive;
7100
+ literal;
7101
+ regexp;
7102
+ replace;
7103
+ valid;
7104
+ wholeWord;
7105
+ filter;
7106
+ impl;
7107
+ constructor(e) {
7108
+ this.search = e.search, this.caseSensitive = !!e.caseSensitive, this.literal = !!e.literal, this.regexp = !!e.regexp, this.replace = e.replace || "", this.valid = !!this.search && !(this.regexp && !validRegExp(this.search)), this.wholeWord = !!e.wholeWord, this.filter = e.filter || null, this.impl = this.valid ? this.regexp ? new RegExpQuery(this) : new StringQuery(this) : nullQuery;
7109
+ }
7110
+ eq(e) {
7111
+ return this.search == e.search && this.replace == e.replace && this.caseSensitive == e.caseSensitive && this.regexp == e.regexp && this.wholeWord == e.wholeWord;
7112
+ }
7113
+ findNext(e, t = 0, n = e.doc.content.size) {
7114
+ for (;;) {
7115
+ if (t >= n) return null;
7116
+ let r = this.impl.findNext(e, t, n);
7117
+ if (!r || this.checkResult(e, r)) return r;
7118
+ t = r.from + 1;
7119
+ }
7120
+ }
7121
+ findPrev(e, t = e.doc.content.size, n = 0) {
7122
+ for (;;) {
7123
+ if (t <= n) return null;
7124
+ let r = this.impl.findPrev(e, t, n);
7125
+ if (!r || this.checkResult(e, r)) return r;
7126
+ t = r.to - 1;
7127
+ }
7128
+ }
7129
+ checkResult(e, t) {
7130
+ return (!this.wholeWord || checkWordBoundary(e, t.from) && checkWordBoundary(e, t.to)) && (!this.filter || this.filter(e, t));
7131
+ }
7132
+ unquote(e) {
7133
+ return this.literal ? e : e.replace(/\\([nrt\\])/g, (e, t) => t == "n" ? "\n" : t == "r" ? "\r" : t == "t" ? " " : "\\");
7134
+ }
7135
+ getReplacements(e, t) {
7136
+ let n = e.doc.resolve(t.from).marksAcross(e.doc.resolve(t.to)), r = [], a = Fragment.empty, o = t.from, { match: s } = t, c = s ? getGroupIndices(s) : [[0, t.to - t.from]], l = parseReplacement(this.unquote(this.replace)), u;
7137
+ for (let s of l) if (typeof s == "string") a = a.addToEnd(e.schema.text(s, n));
7138
+ else if (u = c[s.group], u) {
7139
+ let n = t.matchStart + u[0], c = t.matchStart + u[1];
7140
+ s.copy ? a = a.append(e.doc.slice(n, c).content) : ((a != Fragment.empty || n > o) && (r.push({
7141
+ from: o,
7142
+ to: n,
7143
+ insert: new Slice(a, 0, 0)
7144
+ }), a = Fragment.empty), o = c);
7145
+ }
7146
+ return (a != Fragment.empty || o < t.to) && r.push({
7147
+ from: o,
7148
+ to: t.to,
7149
+ insert: new Slice(a, 0, 0)
7150
+ }), r;
7151
+ }
7152
+ }, nullQuery = new class {
7153
+ findNext() {
7154
+ return null;
7155
+ }
7156
+ findPrev() {
7157
+ return null;
7158
+ }
7159
+ }(), StringQuery = class {
7160
+ query;
7161
+ string;
7162
+ constructor(e) {
7163
+ this.query = e;
7164
+ let t = e.unquote(e.search);
7165
+ e.caseSensitive || (t = t.toLowerCase()), this.string = t;
7166
+ }
7167
+ findNext(e, t, n) {
7168
+ return scanTextblocks(e.doc, t, n, (e, r) => {
7169
+ let a = Math.max(t, r), o = textContent(e).slice(a - r, Math.min(e.content.size, n - r)), s = (this.query.caseSensitive ? o : o.toLowerCase()).indexOf(this.string);
7170
+ return s < 0 ? null : {
7171
+ from: a + s,
7172
+ to: a + s + this.string.length,
7173
+ match: null,
7174
+ matchStart: r
7175
+ };
7176
+ });
7177
+ }
7178
+ findPrev(e, t, n) {
7179
+ return scanTextblocks(e.doc, t, n, (e, r) => {
7180
+ let a = Math.max(r, n), o = textContent(e).slice(a - r, Math.min(e.content.size, t - r));
7181
+ this.query.caseSensitive || (o = o.toLowerCase());
7182
+ let s = o.lastIndexOf(this.string);
7183
+ return s < 0 ? null : {
7184
+ from: a + s,
7185
+ to: a + s + this.string.length,
7186
+ match: null,
7187
+ matchStart: r
7188
+ };
7189
+ });
7190
+ }
7191
+ }, baseFlags = "g" + (/x/.unicode == null ? "" : "u") + (/x/.hasIndices == null ? "" : "d"), RegExpQuery = class {
7192
+ query;
7193
+ regexp;
7194
+ constructor(e) {
7195
+ this.query = e, this.regexp = new RegExp(e.search, baseFlags + (e.caseSensitive ? "" : "i"));
7196
+ }
7197
+ findNext(e, t, n) {
7198
+ return scanTextblocks(e.doc, t, n, (e, r) => {
7199
+ let a = textContent(e).slice(0, Math.min(e.content.size, n - r));
7200
+ this.regexp.lastIndex = t - r;
7201
+ let o = this.regexp.exec(a);
7202
+ return o ? {
7203
+ from: r + o.index,
7204
+ to: r + o.index + o[0].length,
7205
+ match: o,
7206
+ matchStart: r
7207
+ } : null;
7208
+ });
7209
+ }
7210
+ findPrev(e, t, n) {
7211
+ return scanTextblocks(e.doc, t, n, (e, n) => {
7212
+ let r = textContent(e).slice(0, Math.min(e.content.size, t - n)), a;
7213
+ for (let e = 0;;) {
7214
+ this.regexp.lastIndex = e;
7215
+ let t = this.regexp.exec(r);
7216
+ if (!t) break;
7217
+ a = t, e = t.index + 1;
7218
+ }
7219
+ return a ? {
7220
+ from: n + a.index,
7221
+ to: n + a.index + a[0].length,
7222
+ match: a,
7223
+ matchStart: n
7224
+ } : null;
7225
+ });
7226
+ }
7227
+ };
7228
+ function getGroupIndices(e) {
7229
+ if (e.indices) return e.indices;
7230
+ let t = [[0, e[0].length]];
7231
+ for (let n = 1, r = 0; n < e.length; n++) {
7232
+ let a = e[n] ? e[0].indexOf(e[n], r) : -1;
7233
+ t.push(a < 0 ? void 0 : [a, r = a + e[n].length]);
7234
+ }
7235
+ return t;
7236
+ }
7237
+ function parseReplacement(e) {
7238
+ let t = [], n = -1;
7239
+ function r(e) {
7240
+ let n = t.length - 1;
7241
+ n > -1 && typeof t[n] == "string" ? t[n] += e : t.push(e);
7242
+ }
7243
+ for (; e.length;) {
7244
+ let a = /\$([$&\d+])/.exec(e);
7245
+ if (!a) return r(e), t;
7246
+ if (a.index > 0 && r(e.slice(0, a.index + +(a[1] == "$"))), a[1] != "$") {
7247
+ let e = a[1] == "&" ? 0 : +a[1];
7248
+ n >= e ? t.push({
7249
+ group: e,
7250
+ copy: !0
7251
+ }) : (n = e || 1e3, t.push({
7252
+ group: e,
7253
+ copy: !1
7254
+ }));
7255
+ }
7256
+ e = e.slice(a.index + a[0].length);
7257
+ }
7258
+ return t;
7259
+ }
7260
+ function validRegExp(e) {
7261
+ try {
7262
+ return new RegExp(e, baseFlags), !0;
7263
+ } catch {
7264
+ return !1;
7265
+ }
7266
+ }
7267
+ var TextContentCache = /* @__PURE__ */ new WeakMap();
7268
+ function textContent(e) {
7269
+ let t = TextContentCache.get(e);
7270
+ if (t) return t;
7271
+ let n = "";
7272
+ for (let t = 0; t < e.childCount; t++) {
7273
+ let r = e.child(t);
7274
+ r.isText ? n += r.text : r.isLeaf ? n += "" : n += " " + textContent(r) + " ";
7275
+ }
7276
+ return TextContentCache.set(e, n), n;
7277
+ }
7278
+ function scanTextblocks(e, t, n, r, a = 0) {
7279
+ if (e.inlineContent) return r(e, a);
7280
+ if (!e.isLeaf) if (t > n) for (let o = e.childCount - 1, s = a + e.content.size; o >= 0 && s > n; o--) {
7281
+ let a = e.child(o);
7282
+ if (s -= a.nodeSize, s < t) {
7283
+ let e = scanTextblocks(a, t, n, r, s + 1);
7284
+ if (e != null) return e;
7285
+ }
7286
+ }
7287
+ else for (let o = 0, s = a; o < e.childCount && s < n; o++) {
7288
+ let a = e.child(o), c = s;
7289
+ if (s += a.nodeSize, s > t) {
7290
+ let e = scanTextblocks(a, t, n, r, c + 1);
7291
+ if (e != null) return e;
7292
+ }
7293
+ }
7294
+ return null;
7295
+ }
7296
+ function checkWordBoundary(e, t) {
7297
+ let n = e.doc.resolve(t), r = n.nodeBefore, a = n.nodeAfter;
7298
+ return !r || !a || !r.isText || !a.isText ? !0 : !/\p{L}$/u.test(r.text) || !/^\p{L}/u.test(a.text);
7299
+ }
7300
+ //#endregion
7301
+ //#region ../editor/src/search/search.ts
7302
+ var SearchState = class {
7303
+ query;
7304
+ range;
7305
+ deco;
7306
+ constructor(e, t, n) {
7307
+ this.query = e, this.range = t, this.deco = n;
7308
+ }
7309
+ };
7310
+ function buildMatchDeco(e, t, n) {
7311
+ if (!t.valid) return DecorationSet.empty;
7312
+ let r = [], a = e.selection;
7313
+ for (let o = n ? n.from : 0, s = n ? n.to : e.doc.content.size;;) {
7314
+ let n = t.findNext(e, o, s);
7315
+ if (!n) break;
7316
+ let c = n.from == a.from && n.to == a.to ? "kb-active-search-match" : "kb-search-match";
7317
+ r.push(Decoration.inline(n.from, n.to, { class: c })), o = n.to;
7318
+ }
7319
+ return DecorationSet.create(e.doc, r);
7320
+ }
7321
+ var searchKey = new PluginKey("search");
7322
+ function createSearchPlugin(e = {}) {
7323
+ return new Plugin({
7324
+ key: searchKey,
7325
+ state: {
7326
+ init(t, n) {
7327
+ let r = e.initialQuery || new SearchQuery({ search: "" }), a = e.initialRange || null;
7328
+ return new SearchState(r, a, buildMatchDeco(n, r, a));
7329
+ },
7330
+ apply(e, t, n, r) {
7331
+ let a = e.getMeta(searchKey);
7332
+ if (a) return new SearchState(a.query, a.range, buildMatchDeco(r, a.query, a.range));
7333
+ if (e.docChanged || e.selectionSet) {
7334
+ let n = t.range;
7335
+ if (n) {
7336
+ let t = e.mapping.map(n.from, 1), r = e.mapping.map(n.to, -1);
7337
+ n = t < r ? {
7338
+ from: t,
7339
+ to: r
7340
+ } : null;
7341
+ }
7342
+ t = new SearchState(t.query, n, buildMatchDeco(r, t.query, n));
7343
+ }
7344
+ return t;
7345
+ }
7346
+ },
7347
+ props: { decorations: (e) => searchKey.getState(e).deco }
7348
+ });
7349
+ }
7350
+ function setSearchState(e, t, n = null) {
7351
+ return e.setMeta(searchKey, {
7352
+ query: t,
7353
+ range: n
7354
+ });
7355
+ }
7356
+ function nextMatch(e, t, n, r, a) {
7357
+ let o = e.range || {
7358
+ from: 0,
7359
+ to: t.doc.content.size
7360
+ }, s = e.query.findNext(t, Math.max(a, o.from), o.to);
7361
+ return !s && n && (s = e.query.findNext(t, o.from, Math.min(r, o.to))), s;
7362
+ }
7363
+ function prevMatch(e, t, n, r, a) {
7364
+ let o = e.range || {
7365
+ from: 0,
7366
+ to: t.doc.content.size
7367
+ }, s = e.query.findPrev(t, Math.min(r, o.to), o.from);
7368
+ return !s && n && (s = e.query.findPrev(t, o.to, Math.max(a, o.from))), s;
7369
+ }
7370
+ function findCommand(e, t) {
7371
+ return (n, r) => {
7372
+ let a = searchKey.getState(n);
7373
+ if (!a || !a.query.valid) return !1;
7374
+ let { from: o, to: s } = n.selection, c = t > 0 ? nextMatch(a, n, e, o, s) : prevMatch(a, n, e, o, s);
7375
+ if (!c) return !1;
7376
+ let l = TextSelection.create(n.doc, c.from, c.to);
7377
+ return r && r(n.tr.setSelection(l).scrollIntoView()), !0;
7378
+ };
7379
+ }
7380
+ var findNext = findCommand(!0, 1), findNextNoWrap = findCommand(!1, 1), findPrev = findCommand(!0, -1), findPrevNoWrap = findCommand(!1, -1);
7381
+ function replaceCommand(e, t) {
7382
+ return (n, r) => {
7383
+ let a = searchKey.getState(n);
7384
+ if (!a || !a.query.valid) return !1;
7385
+ let { from: o } = n.selection, s = nextMatch(a, n, e, o, o);
7386
+ if (!s) return !1;
7387
+ if (!r) return !0;
7388
+ if (n.selection.from == s.from && n.selection.to == s.to) {
7389
+ let o = n.tr, c = a.query.getReplacements(n, s);
7390
+ for (let e = c.length - 1; e >= 0; e--) {
7391
+ let { from: t, to: n, insert: r } = c[e];
7392
+ o.replace(t, n, r);
7393
+ }
7394
+ let l = t && nextMatch(a, n, e, s.from, s.to);
7395
+ l ? o.setSelection(TextSelection.create(o.doc, o.mapping.map(l.from, 1), o.mapping.map(l.to, -1))) : o.setSelection(TextSelection.create(o.doc, s.from, o.mapping.map(s.to, 1))), r(o.scrollIntoView());
7396
+ } else if (t) r(n.tr.setSelection(TextSelection.create(n.doc, s.from, s.to)).scrollIntoView());
7397
+ else return !1;
7398
+ return !0;
7399
+ };
7400
+ }
7401
+ var replaceNext = replaceCommand(!0, !0), replaceNextNoWrap = replaceCommand(!1, !0), replaceCurrent = replaceCommand(!1, !1), replaceAll = (e, t) => {
7402
+ let n = searchKey.getState(e);
7403
+ if (!n) return !1;
7404
+ let r = [], a = n.range || {
7405
+ from: 0,
7406
+ to: e.doc.content.size
7407
+ };
7408
+ for (let t = a.from;;) {
7409
+ let o = n.query.findNext(e, t, a.to);
7410
+ if (!o) break;
7411
+ r.push(o), t = o.to;
7412
+ }
7413
+ if (t) {
7414
+ let a = e.tr;
7415
+ for (let t = r.length - 1; t >= 0; t--) {
7416
+ let o = r[t], s = n.query.getReplacements(e, o);
7417
+ for (let e = s.length - 1; e >= 0; e--) {
7418
+ let { from: t, to: n, insert: r } = s[e];
7419
+ a.replace(t, n, r);
7420
+ }
7421
+ }
7422
+ t(a);
7423
+ }
7424
+ return !0;
7425
+ }, searchFactory = (e, t = null) => (n, r) => {
7426
+ let a = n.tr;
7427
+ return setSearchState(a, e, t), r && r(a), !0;
7428
+ }, searchCommandFactories = {
7429
+ search: searchFactory,
7430
+ findNext: () => findNext,
7431
+ findNextNoWrap: () => findNextNoWrap,
7432
+ findPrev: () => findPrev,
7433
+ findPrevNoWrap: () => findPrevNoWrap,
7434
+ replaceNext: () => replaceNext,
7435
+ replaceNextNoWrap: () => replaceNextNoWrap,
7436
+ replaceCurrent: () => replaceCurrent,
7437
+ replaceAll: () => replaceAll
7438
+ };
7439
+ //#endregion
7096
7440
  //#region ../editor/src/ExtensionManager.ts
7097
7441
  function splitExtensions(e) {
7098
7442
  return {
@@ -7149,7 +7493,7 @@ var ExtensionManager = class {
7149
7493
  let t = r.get(e);
7150
7494
  t && r.set(e, firstCommand$1((t, n, r) => (console.debug(`Key: ${e}`), !0), t));
7151
7495
  }
7152
- this.converters = o, this.plugins.push(new InputRulesPlugin(n)), this.plugins.push(new KeymapPlugin(Object.fromEntries(r))), this.plugins.push(new TrackSelecionPlugin(e));
7496
+ this.converters = o, this.plugins.push(new InputRulesPlugin(n)), this.plugins.push(new KeymapPlugin(Object.fromEntries(r))), this.plugins.push(createSearchPlugin()), this.plugins.push(new TrackSelecionPlugin(e));
7153
7497
  }
7154
7498
  setupExtensions(e) {
7155
7499
  let t = /* @__PURE__ */ new Map(), n = (e) => {
@@ -7712,7 +8056,7 @@ var insertBlockBefore = (e, t) => (n, r) => {
7712
8056
  run = {};
7713
8057
  debug = !0;
7714
8058
  constructor(e) {
7715
- this.editor = e, this.mergeCommandFactories(baseCommandFactories, "baseCommand"), this.mergeCommandFactories(keyCommandFactories, "key"), this.mergeCommandFactories(replaceCommandFactories, "replace");
8059
+ this.editor = e, this.mergeCommandFactories(baseCommandFactories, "baseCommand"), this.mergeCommandFactories(keyCommandFactories, "key"), this.mergeCommandFactories(replaceCommandFactories, "replace"), this.mergeCommandFactories(searchCommandFactories, "search");
7716
8060
  }
7717
8061
  mergeCommandFactories(e, t) {
7718
8062
  for (let n in e) {
@@ -23329,7 +23673,9 @@ async function mdToPmConverterText(e, t, n) {
23329
23673
  getAttrs: (e) => ({ lang: e.attrGet("lang") || void 0 }),
23330
23674
  noCloseToken: !0
23331
23675
  },
23332
- hr: { node: "hr" },
23676
+ hr: { custom: (e, t, r, a) => {
23677
+ e.openNode(n.nodes.paragraph, {}), e.addNode(n.nodes.hr, {}), e.closeNode();
23678
+ } },
23333
23679
  image: {
23334
23680
  node: "image",
23335
23681
  getAttrs: (e) => {