@clevertask/scribe 0.1.1 → 0.1.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.
@@ -7,6 +7,7 @@ export declare const initExtensions: (props: ScribeProps) => (import("@tiptap/co
7
7
  content: import("./tableOfContents").ScribeTableOfContentsItem[];
8
8
  hasCreated: boolean;
9
9
  lastSignature: string;
10
+ layoutRefreshRetries: number;
10
11
  rafId: number | null;
11
12
  refresh: () => void;
12
13
  scheduleRefresh: () => void;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../lib/components/Scribe/extension/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAqBtC,eAAO,MAAM,cAAc,GAAI,OAAO,WAAW;;;;;;;;;;;;;;2hCAmEhD,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../lib/components/Scribe/extension/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAqBtC,eAAO,MAAM,cAAc,GAAI,OAAO,WAAW;;;;;;;;;;;;;;;2hCAmEhD,CAAC"}
@@ -26,6 +26,7 @@ type ScribeTableOfContentsStorage = {
26
26
  content: ScribeTableOfContentsItem[];
27
27
  hasCreated: boolean;
28
28
  lastSignature: string;
29
+ layoutRefreshRetries: number;
29
30
  rafId: number | null;
30
31
  refresh: () => void;
31
32
  scheduleRefresh: () => void;
@@ -1 +1 @@
1
- {"version":3,"file":"tableOfContents.d.ts","sourceRoot":"","sources":["../../../../lib/components/Scribe/extension/tableOfContents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAGtD,eAAO,MAAM,6BAA6B,0BAA0B,CAAC;AAErE,KA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AC;SAC/C,CAAC;KACH;IAED,UAAU,OAAO;QACf,qBAAqB,EAAE,4BAA4B,CAAC;KACrD;CACF;AAED,eAAO,MAAM,qBAAqB,uEA8JhC,CAAC"}
1
+ {"version":3,"file":"tableOfContents.d.ts","sourceRoot":"","sources":["../../../../lib/components/Scribe/extension/tableOfContents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAGtD,eAAO,MAAM,6BAA6B,0BAA0B,CAAC;AAErE,KAAK,YAAY,GAAG,WAAW,GAAG,MAAM,CAAC;AAOzC,MAAM,MAAM,yBAAyB,GAAG;IACtC,GAAG,EAAE,WAAW,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,OAAO,CAAC;IAClB,cAAc,EAAE,OAAO,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,UAAU,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,kCAAkC,GAAG,CAC/C,KAAK,EAAE,yBAAyB,EAAE,EAClC,QAAQ,CAAC,EAAE,OAAO,KACf,IAAI,CAAC;AAEV,MAAM,MAAM,iCAAiC,GAAG,yBAAyB,GAAG,MAAM,CAAC;AAEnF,KAAK,4BAA4B,GAAG;IAClC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,CAAC,EAAE,kCAAkC,CAAC;CAC/C,CAAC;AAEF,KAAK,4BAA4B,GAAG;IAClC,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,OAAO,EAAE,yBAAyB,EAAE,CAAC;IACrC,UAAU,EAAE,OAAO,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B,YAAY,EAAE,YAAY,GAAG,IAAI,CAAC;IAClC,kBAAkB,EAAE,MAAM,IAAI,CAAC;CAChC,CAAC;AAyQF,OAAO,QAAQ,cAAc,CAAC;IAC5B,UAAU,QAAQ,CAAC,UAAU;QAC3B,qBAAqB,EAAE;YACrB,2BAA2B,EAAE,MAAM,UAAU,CAAC;SAC/C,CAAC;KACH;IAED,UAAU,OAAO;QACf,qBAAqB,EAAE,4BAA4B,CAAC;KACrD;CACF;AAED,eAAO,MAAM,qBAAqB,uEA8KhC,CAAC"}
@@ -1,11 +1,11 @@
1
- import { P as g, a as f, b as p } from "../../../index-BiBV5TQx.js";
2
- const c = "scribeTableOfContents", v = new g("scribeTableOfContents"), w = (e) => e.trim().toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "heading", C = (e, t) => {
1
+ import { P as v, a as C, b as w } from "../../../index-BiBV5TQx.js";
2
+ const u = "scribeTableOfContents", S = new v("scribeTableOfContents"), T = 10, b = (e) => e.trim().toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "heading", m = (e, t) => {
3
3
  const n = t[t.length - 1], s = [...t].reverse().find((r) => r.originalLevel <= e.node.attrs.level)?.level || 1;
4
4
  return e.node.attrs.level > (n?.originalLevel || 1) ? (n?.level || 1) + 1 : e.node.attrs.level < (n?.originalLevel || 1) ? s : n?.level || 1;
5
- }, S = (e) => (e[e.length - 1]?.itemIndex || 0) + 1, T = (e, t, n) => {
5
+ }, y = (e) => (e[e.length - 1]?.itemIndex || 0) + 1, H = (e, t, n) => {
6
6
  if (e.textContent.length === 0)
7
7
  return null;
8
- const o = w(e.textContent), s = (t.get(o) || 0) + 1, r = s === 1 ? o : `${o}-${s}`;
8
+ const o = b(e.textContent), s = (t.get(o) || 0) + 1, r = s === 1 ? o : `${o}-${s}`;
9
9
  return t.set(o, s), n === r ? n : r;
10
10
  }, d = (e, t) => {
11
11
  const n = e.tr, o = /* @__PURE__ */ new Map();
@@ -13,35 +13,35 @@ const c = "scribeTableOfContents", v = new g("scribeTableOfContents"), w = (e) =
13
13
  return e.doc.descendants((r, a) => {
14
14
  if (!t.includes(r.type.name))
15
15
  return;
16
- const i = r.attrs["data-toc-id"], l = T(r, o, i);
16
+ const i = r.attrs["data-toc-id"], l = H(r, o, i);
17
17
  i !== l && (n.setNodeMarkup(a, void 0, {
18
18
  ...r.attrs,
19
19
  "data-toc-id": l
20
20
  }), s = !0);
21
- }), s ? n.setMeta(c, !0).setMeta("addToHistory", !1) : null;
22
- }, b = (e) => {
21
+ }), s ? n.setMeta(u, !0).setMeta("addToHistory", !1) : null;
22
+ }, R = (e) => {
23
23
  const { overflowY: t } = window.getComputedStyle(e);
24
24
  return /(auto|scroll|overlay)/.test(t) && e.scrollHeight > e.clientHeight;
25
- }, m = (e) => {
25
+ }, A = (e) => {
26
26
  let t = e.parentElement;
27
27
  for (; t; ) {
28
- if (b(t))
28
+ if (R(t))
29
29
  return t;
30
30
  t = t.parentElement;
31
31
  }
32
32
  return window;
33
- }, H = (e) => typeof Window < "u" && e instanceof Window, O = (e) => H(e) ? 32 : e.getBoundingClientRect().top + 32, I = (e, t) => {
33
+ }, h = (e) => typeof Window < "u" && e instanceof Window, E = (e) => h(e) ? 32 : e.getBoundingClientRect().top + 32, c = (e) => e.isConnected && e.getClientRects().length > 0, I = (e, t) => {
34
34
  const n = e.view.nodeDOM(t);
35
35
  return n instanceof HTMLElement ? n : null;
36
- }, x = (e, t) => {
36
+ }, O = (e, t) => {
37
37
  const n = [];
38
38
  return e.state.doc.descendants((o, s) => {
39
39
  !t.includes(o.type.name) || o.textContent.length === 0 || n.push({ node: o, pos: s });
40
40
  }), n;
41
- }, y = (e, t) => {
42
- if (!t)
41
+ }, g = (e, t) => e.length === 0 ? !0 : !t || !e.every((n) => c(n.dom)) ? !1 : h(t) || c(t), L = (e, t) => {
42
+ if (!g(e, t))
43
43
  return e;
44
- const n = O(t), o = /* @__PURE__ */ new Set();
44
+ const n = E(t), o = /* @__PURE__ */ new Set();
45
45
  let s = null;
46
46
  return e.forEach((r) => {
47
47
  r.dom.getBoundingClientRect().top <= n && (s = r.id, o.add(r.id));
@@ -50,28 +50,28 @@ const c = "scribeTableOfContents", v = new g("scribeTableOfContents"), w = (e) =
50
50
  isActive: r.id === s,
51
51
  isScrolledOver: o.has(r.id)
52
52
  }));
53
- }, A = (e, t, n) => {
54
- const o = x(e, t), s = [];
53
+ }, x = (e, t, n) => {
54
+ const o = O(e, t), s = [];
55
55
  return o.forEach((r) => {
56
56
  const a = r.node.attrs["data-toc-id"], i = I(e, r.pos);
57
57
  if (!a || !i)
58
58
  return;
59
- const l = Number(r.node.attrs.level) || 1, u = C(r, s), h = S(s);
59
+ const l = Number(r.node.attrs.level) || 1, f = m(r, s), p = y(s);
60
60
  s.push({
61
61
  dom: i,
62
62
  editor: e,
63
63
  id: a,
64
64
  isActive: !1,
65
65
  isScrolledOver: !1,
66
- itemIndex: h,
67
- level: u,
66
+ itemIndex: p,
67
+ level: f,
68
68
  node: r.node,
69
69
  originalLevel: l,
70
70
  pos: r.pos,
71
71
  textContent: r.node.textContent
72
72
  });
73
- }), y(s, n);
74
- }, L = (e) => JSON.stringify(
73
+ }), L(s, n);
74
+ }, M = (e) => JSON.stringify(
75
75
  e.map((t) => ({
76
76
  id: t.id,
77
77
  isActive: t.isActive,
@@ -83,9 +83,9 @@ const c = "scribeTableOfContents", v = new g("scribeTableOfContents"), w = (e) =
83
83
  textContent: t.textContent
84
84
  }))
85
85
  ), P = (e, t, n) => {
86
- const o = L(n), s = !e.hasCreated;
86
+ const o = M(n), s = !e.hasCreated;
87
87
  e.anchors = n.map((r) => r.dom), e.content = n, !(!s && o === e.lastSignature) && (e.hasCreated = !0, e.lastSignature = o, t.onUpdate?.(n, s));
88
- }, M = f.create({
88
+ }, F = C.create({
89
89
  name: "scribeTableOfContents",
90
90
  addOptions() {
91
91
  return {
@@ -98,6 +98,7 @@ const c = "scribeTableOfContents", v = new g("scribeTableOfContents"), w = (e) =
98
98
  content: [],
99
99
  hasCreated: !1,
100
100
  lastSignature: "",
101
+ layoutRefreshRetries: 0,
101
102
  rafId: null,
102
103
  refresh: () => null,
103
104
  scheduleRefresh: () => null,
@@ -130,10 +131,10 @@ const c = "scribeTableOfContents", v = new g("scribeTableOfContents"), w = (e) =
130
131
  },
131
132
  addProseMirrorPlugins() {
132
133
  return [
133
- new p({
134
- key: v,
134
+ new w({
135
+ key: S,
135
136
  appendTransaction: (e, t, n) => typeof window > "u" || e.some(
136
- (s) => s.getMeta(c) || s.getMeta("composition")
137
+ (s) => s.getMeta(u) || s.getMeta("composition")
137
138
  ) || !e.some((s) => s.docChanged) ? null : d(n, this.options.anchorTypes)
138
139
  })
139
140
  ];
@@ -144,18 +145,18 @@ const c = "scribeTableOfContents", v = new g("scribeTableOfContents"), w = (e) =
144
145
  this.storage.scrollHandler = () => {
145
146
  this.storage.refresh();
146
147
  }, this.storage.updateScrollParent = () => {
147
- const t = m(this.editor.view.dom);
148
+ const t = A(this.editor.view.dom);
148
149
  this.storage.scrollParent !== t && (this.storage.scrollParent?.removeEventListener("scroll", this.storage.scrollHandler), this.storage.scrollParent = t, this.storage.scrollParent.addEventListener("scroll", this.storage.scrollHandler));
149
150
  }, this.storage.refresh = () => {
150
151
  if (this.editor.isDestroyed)
151
152
  return;
152
153
  this.storage.updateScrollParent();
153
- const t = A(
154
+ const t = x(
154
155
  this.editor,
155
156
  this.options.anchorTypes,
156
157
  this.storage.scrollParent
157
- );
158
- P(this.storage, this.options, t);
158
+ ), n = this.editor.view.dom.isConnected && g(t, this.storage.scrollParent);
159
+ n && (this.storage.layoutRefreshRetries = 0), P(this.storage, this.options, t), !n && this.storage.layoutRefreshRetries < T && (this.storage.layoutRefreshRetries += 1, this.storage.scheduleRefresh());
159
160
  }, this.storage.scheduleRefresh = () => {
160
161
  this.storage.rafId !== null && window.cancelAnimationFrame(this.storage.rafId), this.storage.rafId = window.requestAnimationFrame(() => {
161
162
  this.storage.rafId = null, this.storage.refresh();
@@ -175,6 +176,6 @@ const c = "scribeTableOfContents", v = new g("scribeTableOfContents"), w = (e) =
175
176
  }
176
177
  });
177
178
  export {
178
- c as SCRIBE_TABLE_OF_CONTENTS_META,
179
- M as ScribeTableOfContents
179
+ u as SCRIBE_TABLE_OF_CONTENTS_META,
180
+ F as ScribeTableOfContents
180
181
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clevertask/scribe",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "private": false,
5
5
  "description": "A Radix-based Tiptap rich text editor with a Notion-style block interface for viewing and creating content. Perfect for diverse needs like notes, documents, AI chat, Markdown parsing, and comments.",
6
6
  "keywords": [