@jackuait/blok 0.4.1-beta.17 → 0.4.1-beta.18

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/blok.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { B as s, v as a } from "./chunks/blok-BmQiBq7w.mjs";
2
- import { D as A } from "./chunks/inline-tool-convert-f0-Y0Vcm.mjs";
1
+ import { B as s, v as a } from "./chunks/blok-YehXQjcP.mjs";
2
+ import { D as A } from "./chunks/inline-tool-convert-n3QzrC92.mjs";
3
3
  export {
4
4
  s as Blok,
5
5
  A as DATA_ATTR,
@@ -19,7 +19,7 @@ var jt = (a, t) => {
19
19
  t.indexOf(o) < 0 && _e.call(a, o) && (e[o] = a[o]);
20
20
  return e;
21
21
  };
22
- import { i as N, g as jo, a as g, b as ve, c as E, l as I, S as y, d as Yo, e as Vo, D as m, t as C, f as j, h as bo, P as O, j as Ht, k as V, m as A, n as Bt, o as ht, p as ko, q as nt, T as Yt, r as Ft, s as v, I as Xo, u as qo, v as ct, w as oe, x as Zo, y as Go, z as Jo, A as vo, B as Qo, C as Bo, E as wo, F as tn, G as ze, H as en, J as on, K as nn, L as Be, M as Ue, N as sn, O as Ke, Q as We, R as rn, U as an, V as ln, W as cn, X as dn, Y as ne, Z as _t, _ as hn, $ as un, a0 as pn, a1 as $e, a2 as fn, a3 as gn, a4 as mn, a5 as bn, a6 as kn, a7 as vn, a8 as Bn } from "./inline-tool-convert-f0-Y0Vcm.mjs";
22
+ import { i as N, g as jo, a as g, b as ve, c as E, l as I, S as y, d as Yo, e as Vo, D as m, t as C, f as j, h as bo, P as O, j as Ht, k as V, m as A, n as Bt, o as ht, p as ko, q as nt, T as Yt, r as Ft, s as v, I as Xo, u as qo, v as ct, w as oe, x as Zo, y as Go, z as Jo, A as vo, B as Qo, C as Bo, E as wo, F as tn, G as ze, H as en, J as on, K as nn, L as Be, M as Ue, N as sn, O as Ke, Q as We, R as rn, U as an, V as ln, W as cn, X as dn, Y as ne, Z as _t, _ as hn, $ as un, a0 as pn, a1 as $e, a2 as fn, a3 as gn, a4 as mn, a5 as bn, a6 as kn, a7 as vn, a8 as Bn } from "./inline-tool-convert-n3QzrC92.mjs";
23
23
  function wn(a) {
24
24
  return a && a.__esModule && Object.prototype.hasOwnProperty.call(a, "default") ? a.default : a;
25
25
  }
@@ -1471,7 +1471,7 @@ class Hn {
1471
1471
  * @returns {Promise<NotifierModule>} loaded notifier module
1472
1472
  */
1473
1473
  loadNotifierModule() {
1474
- return this.notifierModule !== null ? Promise.resolve(this.notifierModule) : (this.loadingPromise === null && (this.loadingPromise = import("./index-CvHTp5IA.mjs").then((t) => {
1474
+ return this.notifierModule !== null ? Promise.resolve(this.notifierModule) : (this.loadingPromise === null && (this.loadingPromise = import("./index-BtI3WrPm.mjs").then((t) => {
1475
1475
  const e = t;
1476
1476
  if (!this.isNotifierModule(e))
1477
1477
  throw new Error('notifier module does not expose a "show" method.');
@@ -6511,7 +6511,7 @@ class $s extends T {
6511
6511
  async ensureI18nextLoaded(t, e) {
6512
6512
  if (this.i18nextWrapper !== null)
6513
6513
  return;
6514
- const { loadI18next: o } = await import("./i18next-loader-CtUJZQir.mjs");
6514
+ const { loadI18next: o } = await import("./i18next-loader-CkHKDgdv.mjs");
6515
6515
  this.i18nextWrapper = await o(t, e);
6516
6516
  }
6517
6517
  /**
@@ -10022,12 +10022,8 @@ const uo = /* @__PURE__ */ new Set([
10022
10022
  return;
10023
10023
  }
10024
10024
  const n = t.getData(this.MIME_TYPE), s = t.getData("text/plain"), r = t.getData("text/html");
10025
- if (n)
10026
- try {
10027
- this.insertBlokData(JSON.parse(n));
10028
- return;
10029
- } catch (p) {
10030
- }
10025
+ if (n && await this.handleBlokDataPaste(n, s))
10026
+ return;
10031
10027
  const l = Object.fromEntries(
10032
10028
  Object.keys(this.toolsTags).map((p) => {
10033
10029
  var b;
@@ -10044,6 +10040,31 @@ const uo = /* @__PURE__ */ new Set([
10044
10040
  ), h = Z(r, d), u = g.isHTMLString(h);
10045
10041
  !h.trim() || h.trim() === s || !u ? await this.processText(s) : await this.processText(h, !0);
10046
10042
  }
10043
+ /**
10044
+ * Handles pasting of Blok JSON data, with pattern matching priority.
10045
+ * For plain text that might match a pattern (like URLs), tries pattern matching first.
10046
+ * This handles the case where text is cut and pasted within the same editor -
10047
+ * we want pattern matching to still work for things like embed URLs.
10048
+ * @param blokData - serialized Blok JSON data
10049
+ * @param plainData - plain text content from clipboard
10050
+ * @returns true if paste was handled, false otherwise
10051
+ */
10052
+ async handleBlokDataPaste(t, e) {
10053
+ try {
10054
+ const o = JSON.parse(t), s = e && this.toolsPatterns.length > 0 ? await this.processPattern(e) : void 0;
10055
+ return s ? (await this.insertPatternMatch(s), !0) : (this.insertBlokData(o), !0);
10056
+ } catch (o) {
10057
+ return !1;
10058
+ }
10059
+ }
10060
+ /**
10061
+ * Inserts a matched pattern as a new block
10062
+ * @param patternResult - the matched pattern with tool and event
10063
+ */
10064
+ async insertPatternMatch(t) {
10065
+ const { BlockManager: e, Caret: o } = this.Blok, n = e.currentBlock && e.currentBlock.tool.isDefault && e.currentBlock.isEmpty, s = await e.paste(t.tool, t.event, n);
10066
+ o.setToBlock(s, o.positions.END);
10067
+ }
10047
10068
  /**
10048
10069
  * Process pasted text and divide them into Blocks
10049
10070
  * @param {string} data - text to process. Can be HTML or plain.
@@ -1,4 +1,4 @@
1
- import { e as i } from "./blok-BmQiBq7w.mjs";
1
+ import { e as i } from "./blok-YehXQjcP.mjs";
2
2
  const l = async (e, r) => {
3
3
  const n = (await import("./i18next-CugVlwWp.mjs")).default.createInstance(), s = {
4
4
  lng: e,
@@ -1,4 +1,4 @@
1
- import { t as f, q as i } from "./inline-tool-convert-f0-Y0Vcm.mjs";
1
+ import { t as f, q as i } from "./inline-tool-convert-n3QzrC92.mjs";
2
2
  const a = {
3
3
  wrapper: i(
4
4
  "fixed z-[2] bottom-5 left-5",
@@ -18,7 +18,7 @@ let nt = (o = 21) => {
18
18
  return t;
19
19
  };
20
20
  var ot = /* @__PURE__ */ ((o) => (o.VERBOSE = "VERBOSE", o.INFO = "INFO", o.WARN = "WARN", o.ERROR = "ERROR", o))(ot || {});
21
- const rt = () => "0.4.1-beta.17", Ct = {
21
+ const rt = () => "0.4.1-beta.18", Ct = {
22
22
  BACKSPACE: 8,
23
23
  TAB: 9,
24
24
  ENTER: 13,
package/dist/full.mjs CHANGED
@@ -10,10 +10,10 @@ var e = (a, l, o) => l in a ? n(a, l, { enumerable: !0, configurable: !0, writab
10
10
  d.call(l, o) && e(a, o, l[o]);
11
11
  return a;
12
12
  }, r = (a, l) => t(a, c(l));
13
- import { B as v, v as A } from "./chunks/blok-BmQiBq7w.mjs";
13
+ import { B as v, v as A } from "./chunks/blok-YehXQjcP.mjs";
14
14
  import { List as p, Header as f, Paragraph as I, Link as k, Italic as u, Bold as B } from "./tools.mjs";
15
15
  import { defaultBlockTools as H, defaultInlineTools as P } from "./tools.mjs";
16
- import { D as _ } from "./chunks/inline-tool-convert-f0-Y0Vcm.mjs";
16
+ import { D as _ } from "./chunks/inline-tool-convert-n3QzrC92.mjs";
17
17
  const m = {
18
18
  paragraph: {
19
19
  class: I,
package/dist/tools.mjs CHANGED
@@ -10,8 +10,8 @@ var U = (f, t, e) => t in f ? nt(f, t, { enumerable: !0, configurable: !0, writa
10
10
  it.call(t, e) && U(f, e, t[e]);
11
11
  return f;
12
12
  }, P = (f, t) => rt(f, st(t));
13
- import { t as x, D as m, a9 as et, aa as at, ab as lt, A as ct, ac as dt, ad as ut, ae as ht, af as ft, ag as pt, ah as mt, ai as G, aj as j, ak as $, f as A, al as gt, am as Et, S as H, P as Tt, an as Ct, l as At, J as yt } from "./chunks/inline-tool-convert-f0-Y0Vcm.mjs";
14
- import { a0 as Dt } from "./chunks/inline-tool-convert-f0-Y0Vcm.mjs";
13
+ import { t as x, D as m, a9 as et, aa as at, ab as lt, A as ct, ac as dt, ad as ut, ae as ht, af as ft, ag as pt, ah as mt, ai as G, aj as j, ak as $, f as A, al as gt, am as Et, S as H, P as Tt, an as Ct, l as At, J as yt } from "./chunks/inline-tool-convert-n3QzrC92.mjs";
14
+ import { a0 as Dt } from "./chunks/inline-tool-convert-n3QzrC92.mjs";
15
15
  const W = [
16
16
  "empty:before:pointer-events-none",
17
17
  "empty:before:text-gray-text",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jackuait/blok",
3
- "version": "0.4.1-beta.17",
3
+ "version": "0.4.1-beta.18",
4
4
  "description": "Blok — headless, highly extensible rich text editor built for developers who need to implement a block-based editing experience (similar to Notion) without building it from scratch",
5
5
  "module": "dist/blok.mjs",
6
6
  "types": "./types/index.d.ts",
@@ -270,14 +270,10 @@ export class Paste extends Module {
270
270
  const normalizedHtmlData = rawHtmlData;
271
271
 
272
272
  /**
273
- * If Blok json is passed, insert it
273
+ * If Blok json is passed, check if we should try pattern matching first
274
274
  */
275
- if (blokData) {
276
- try {
277
- this.insertBlokData(JSON.parse(blokData));
278
-
279
- return;
280
- } catch (_e) { } // Do nothing and continue execution as usual if error appears
275
+ if (blokData && await this.handleBlokDataPaste(blokData, plainData)) {
276
+ return;
281
277
  }
282
278
 
283
279
  /** Add all tags that can be substituted to sanitizer configuration */
@@ -307,6 +303,50 @@ export class Paste extends Module {
307
303
  }
308
304
  }
309
305
 
306
+ /**
307
+ * Handles pasting of Blok JSON data, with pattern matching priority.
308
+ * For plain text that might match a pattern (like URLs), tries pattern matching first.
309
+ * This handles the case where text is cut and pasted within the same editor -
310
+ * we want pattern matching to still work for things like embed URLs.
311
+ * @param blokData - serialized Blok JSON data
312
+ * @param plainData - plain text content from clipboard
313
+ * @returns true if paste was handled, false otherwise
314
+ */
315
+ private async handleBlokDataPaste(blokData: string, plainData: string): Promise<boolean> {
316
+ try {
317
+ const parsedBlokData = JSON.parse(blokData) as Pick<SavedData, 'id' | 'data' | 'tool'>[];
318
+ const shouldTryPatternMatch = plainData && this.toolsPatterns.length > 0;
319
+ const patternResult = shouldTryPatternMatch ? await this.processPattern(plainData) : undefined;
320
+
321
+ if (patternResult) {
322
+ await this.insertPatternMatch(patternResult);
323
+
324
+ return true;
325
+ }
326
+
327
+ this.insertBlokData(parsedBlokData);
328
+
329
+ return true;
330
+ } catch (_e) {
331
+ return false;
332
+ }
333
+ }
334
+
335
+ /**
336
+ * Inserts a matched pattern as a new block
337
+ * @param patternResult - the matched pattern with tool and event
338
+ */
339
+ private async insertPatternMatch(patternResult: { event: PasteEvent; tool: string }): Promise<void> {
340
+ const { BlockManager, Caret } = this.Blok;
341
+ const needToReplaceCurrentBlock = BlockManager.currentBlock &&
342
+ BlockManager.currentBlock.tool.isDefault &&
343
+ BlockManager.currentBlock.isEmpty;
344
+
345
+ const insertedBlock = await BlockManager.paste(patternResult.tool, patternResult.event, needToReplaceCurrentBlock);
346
+
347
+ Caret.setToBlock(insertedBlock, Caret.positions.END);
348
+ }
349
+
310
350
  /**
311
351
  * Process pasted text and divide them into Blocks
312
352
  * @param {string} data - text to process. Can be HTML or plain.