@sobree/core 0.1.10 → 0.1.11

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.
@@ -65,6 +65,13 @@ export interface CreateSobreeOptions {
65
65
  * viewport yourself.
66
66
  */
67
67
  fitOnMount?: FitOnMount;
68
+ /**
69
+ * Show a small, non-interactive `@sobree/core` version badge at the
70
+ * bottom-centre of the screen. Off by default. A debug aid for
71
+ * confirming which renderer build is live (e.g. past a stale cache
72
+ * after a deploy). Forwarded to `SobreeOptions.versionBadge`.
73
+ */
74
+ versionBadge?: boolean;
68
75
  }
69
76
  /**
70
77
  * The editor handle returned by `createSobree()`. Proxies the most-used
package/dist/index.d.ts CHANGED
@@ -12,6 +12,7 @@
12
12
  */
13
13
  export { createSobree } from './createSobree';
14
14
  export type { CreateSobreeOptions, SobreeContent, SobreeHandle, } from './createSobree';
15
+ export { VERSION } from './version';
15
16
  export { parseMarkdown } from './markdown/parse';
16
17
  export { Sobree } from './sobree';
17
18
  export type { SobreeMode, SobreeOptions, SobreeEvent, SobreeEventPayload, SobreeUnsubscribe, } from './sobree';
package/dist/index.js CHANGED
@@ -1439,16 +1439,16 @@ function Rs(t, e = [], n = {}) {
1439
1439
  function st(t, e = {}) {
1440
1440
  return { kind: "text", text: t, properties: e };
1441
1441
  }
1442
- function gh(t, e = {}) {
1442
+ function yh(t, e = {}) {
1443
1443
  return { kind: "text", text: t, properties: { ...e, italic: !0 } };
1444
1444
  }
1445
- function mh(t, e = {}) {
1445
+ function wh(t, e = {}) {
1446
1446
  return { kind: "text", text: t, properties: { ...e, bold: !0 } };
1447
1447
  }
1448
- function bh() {
1448
+ function kh() {
1449
1449
  return { kind: "break", type: "line" };
1450
1450
  }
1451
- function yh() {
1451
+ function vh() {
1452
1452
  return { kind: "break", type: "page" };
1453
1453
  }
1454
1454
  function en() {
@@ -1501,13 +1501,13 @@ function en() {
1501
1501
  function St(t, e) {
1502
1502
  return t.body.push(e), t;
1503
1503
  }
1504
- function wh(t, e) {
1504
+ function xh(t, e) {
1505
1505
  return { type: t, partId: e };
1506
1506
  }
1507
- function kh(t) {
1507
+ function Sh(t) {
1508
1508
  return t.kind === "paragraph";
1509
1509
  }
1510
- function vh(t) {
1510
+ function Th(t) {
1511
1511
  return t.kind === "table";
1512
1512
  }
1513
1513
  function Or(t) {
@@ -4087,7 +4087,7 @@ const Lc = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4087
4087
  isBlobHash: ti,
4088
4088
  sha256Hex: on
4089
4089
  }, Symbol.toStringTag, { value: "Module" }));
4090
- function xh() {
4090
+ function Eh() {
4091
4091
  const t = /* @__PURE__ */ new Map();
4092
4092
  return {
4093
4093
  async put(e) {
@@ -4106,7 +4106,7 @@ function xh() {
4106
4106
  }
4107
4107
  };
4108
4108
  }
4109
- function Sh(t) {
4109
+ function Ah(t) {
4110
4110
  const e = t.baseUrl.replace(/\/+$/, ""), n = t.fetch ?? globalThis.fetch;
4111
4111
  if (!n)
4112
4112
  throw new Error("fetchBlobStore: no global `fetch` available. Pass one via opts.fetch.");
@@ -10315,7 +10315,22 @@ function Zd(t) {
10315
10315
  const i = t.getDocument(), o = i.sections.slice(), s = o.length - 1, a = o[s];
10316
10316
  a && (o.push(structuredClone(a)), t.setDocument({ ...i, sections: o }));
10317
10317
  }
10318
- class Qd {
10318
+ const Qd = "0.1.11", eh = Qd;
10319
+ function th(t = document) {
10320
+ const e = t.createElement("div");
10321
+ return e.className = "sobree-version-badge", e.textContent = `@sobree/core v${eh}`, e.setAttribute("aria-hidden", "true"), Object.assign(e.style, {
10322
+ position: "fixed",
10323
+ bottom: "6px",
10324
+ left: "50%",
10325
+ transform: "translateX(-50%)",
10326
+ pointerEvents: "none",
10327
+ userSelect: "none",
10328
+ zIndex: "2147483647",
10329
+ font: "11px/1.4 system-ui, -apple-system, sans-serif",
10330
+ color: "rgba(0, 0, 0, 0.4)"
10331
+ }), t.body.appendChild(e), () => e.remove();
10332
+ }
10333
+ class nh {
10319
10334
  constructor(e, n = {}) {
10320
10335
  w(this, "editor");
10321
10336
  w(this, "stack");
@@ -10324,6 +10339,8 @@ class Qd {
10324
10339
  /** Guards a single in-flight `document.fonts.ready` repagination so
10325
10340
  * repeated triggers while fonts load coalesce into one re-run. */
10326
10341
  w(this, "fontSettleScheduled", !1);
10342
+ /** Removes the version badge (when `versionBadge` is on). `null` otherwise. */
10343
+ w(this, "versionBadgeTeardown", null);
10327
10344
  w(this, "listeners", {
10328
10345
  change: /* @__PURE__ */ new Set(),
10329
10346
  paginate: /* @__PURE__ */ new Set(),
@@ -10339,11 +10356,11 @@ class Qd {
10339
10356
  /** Detachers for default + user-provided plugins, run in reverse on
10340
10357
  * `destroy` so attach order is mirrored on teardown. */
10341
10358
  w(this, "pluginDetachers", []);
10342
- this.setup = n.pageSetup ?? eh(n.initialDocument), this.stack = new Wd(e, this.setup);
10359
+ this.setup = n.pageSetup ?? rh(n.initialDocument), this.stack = new Wd(e, this.setup);
10343
10360
  const r = {
10344
10361
  contentHosts: () => this.stack.contentHosts
10345
10362
  };
10346
- n.initialDocument && (r.initialDocument = n.initialDocument), n.changeDebounceMs !== void 0 && (r.changeDebounceMs = n.changeDebounceMs), n.ydoc && (r.ydoc = n.ydoc), n.blobStore && (r.blobStore = n.blobStore), n.trackChanges && (r.trackChanges = n.trackChanges), this.editor = new Bf(this.stack.root, r), this.pluginDetachers.push(Jd(this.editor)), this.syncStackSections(), this.syncSetupFromDocument(), typeof requestAnimationFrame < "u" && requestAnimationFrame(() => this.paginateUnlessZoneEditing()), this.detachChange = this.editor.on("change", (i) => {
10363
+ n.initialDocument && (r.initialDocument = n.initialDocument), n.changeDebounceMs !== void 0 && (r.changeDebounceMs = n.changeDebounceMs), n.ydoc && (r.ydoc = n.ydoc), n.blobStore && (r.blobStore = n.blobStore), n.trackChanges && (r.trackChanges = n.trackChanges), this.editor = new Bf(this.stack.root, r), this.pluginDetachers.push(Jd(this.editor)), n.versionBadge && (this.versionBadgeTeardown = th()), this.syncStackSections(), this.syncSetupFromDocument(), typeof requestAnimationFrame < "u" && requestAnimationFrame(() => this.paginateUnlessZoneEditing()), this.detachChange = this.editor.on("change", (i) => {
10347
10364
  this.syncSetupFromDocument(), this.syncStackSections(), this.paginateUnlessZoneEditing();
10348
10365
  for (const o of this.listeners.change)
10349
10366
  try {
@@ -10455,7 +10472,7 @@ class Qd {
10455
10472
  /** Project the current `setup` into `doc.sections[0]` and commit. */
10456
10473
  writeSetupToSection0() {
10457
10474
  const e = this.editor.getDocument(), { section: n, headerFooterBodies: r } = Ue(this.setup), i = e.sections[0];
10458
- if (i && th(i, n)) return;
10475
+ if (i && ih(i, n)) return;
10459
10476
  const o = e.sections.slice();
10460
10477
  o[0] = n, this.editor.setDocument({
10461
10478
  ...e,
@@ -10646,7 +10663,7 @@ class Qd {
10646
10663
  const e = this.editor.getDocument(), n = e.sections[0];
10647
10664
  if (!n) return;
10648
10665
  const r = $t(n, e.headerFooterBodies), i = { ...this.setup, ...r };
10649
- if (n.headerRefs.length === 0 && (i.header = gt()), n.footerRefs.length === 0 && (i.footer = gt()), !nh(this.setup, i)) {
10666
+ if (n.headerRefs.length === 0 && (i.header = gt()), n.footerRefs.length === 0 && (i.footer = gt()), !oh(this.setup, i)) {
10650
10667
  this.setup = i, this.stack.updateSetup(this.setup);
10651
10668
  for (const o of this.listeners.setup)
10652
10669
  try {
@@ -10657,17 +10674,17 @@ class Qd {
10657
10674
  }
10658
10675
  }
10659
10676
  destroy() {
10660
- var e, n;
10661
- for (let r = this.pluginDetachers.length - 1; r >= 0; r--)
10677
+ var e, n, r;
10678
+ for (let i = this.pluginDetachers.length - 1; i >= 0; i--)
10662
10679
  try {
10663
- (n = (e = this.pluginDetachers)[r]) == null || n.call(e);
10664
- } catch (i) {
10665
- console.error("[sobree] plugin detach threw:", i);
10680
+ (n = (e = this.pluginDetachers)[i]) == null || n.call(e);
10681
+ } catch (o) {
10682
+ console.error("[sobree] plugin detach threw:", o);
10666
10683
  }
10667
- this.pluginDetachers.length = 0, this.detachChange(), this.detachPaginate(), this.detachTrackChanges(), this.listeners.change.clear(), this.listeners.paginate.clear(), this.listeners.setup.clear(), this.listeners["mode-change"].clear(), this.listeners["track-changes-change"].clear(), this.listeners["docx:import"].clear(), this.listeners["docx:export"].clear(), this.editor.destroy(), this.stack.destroy();
10684
+ this.pluginDetachers.length = 0, (r = this.versionBadgeTeardown) == null || r.call(this), this.versionBadgeTeardown = null, this.detachChange(), this.detachPaginate(), this.detachTrackChanges(), this.listeners.change.clear(), this.listeners.paginate.clear(), this.listeners.setup.clear(), this.listeners["mode-change"].clear(), this.listeners["track-changes-change"].clear(), this.listeners["docx:import"].clear(), this.listeners["docx:export"].clear(), this.editor.destroy(), this.stack.destroy();
10668
10685
  }
10669
10686
  }
10670
- function eh(t) {
10687
+ function rh(t) {
10671
10688
  const e = structuredClone($r);
10672
10689
  if (!t) return e;
10673
10690
  const n = t.sections[0];
@@ -10684,22 +10701,23 @@ function gt() {
10684
10701
  differentLast: !1
10685
10702
  };
10686
10703
  }
10687
- function th(t, e) {
10704
+ function ih(t, e) {
10688
10705
  return JSON.stringify(t) === JSON.stringify(e);
10689
10706
  }
10690
- function nh(t, e) {
10707
+ function oh(t, e) {
10691
10708
  return JSON.stringify(t) === JSON.stringify(e);
10692
10709
  }
10693
- function Th(t, e = {}) {
10694
- const n = rh(t), { initialDocument: r, deferredDocx: i } = ih(e.content), o = new ws(n), s = {
10710
+ function Ch(t, e = {}) {
10711
+ const n = sh(t), { initialDocument: r, deferredDocx: i } = ah(e.content), o = new ws(n), s = {
10695
10712
  ...r && { initialDocument: r },
10696
10713
  ...e.pageSetup && { pageSetup: e.pageSetup },
10697
10714
  ...e.changeDebounceMs !== void 0 && {
10698
10715
  changeDebounceMs: e.changeDebounceMs
10699
10716
  },
10700
10717
  ...e.ydoc && { ydoc: e.ydoc },
10701
- ...e.blobStore && { blobStore: e.blobStore }
10702
- }, a = new Qd(o.slot, s), c = {
10718
+ ...e.blobStore && { blobStore: e.blobStore },
10719
+ ...e.versionBadge && { versionBadge: !0 }
10720
+ }, a = new nh(o.slot, s), c = {
10703
10721
  editor: a.editor,
10704
10722
  sobree: a,
10705
10723
  viewport: o,
@@ -10769,7 +10787,7 @@ function Th(t, e = {}) {
10769
10787
  }
10770
10788
  };
10771
10789
  }
10772
- function rh(t) {
10790
+ function sh(t) {
10773
10791
  if (typeof t == "string") {
10774
10792
  const e = document.querySelector(t);
10775
10793
  if (!(e instanceof HTMLElement))
@@ -10778,10 +10796,10 @@ function rh(t) {
10778
10796
  }
10779
10797
  return t;
10780
10798
  }
10781
- function ih(t) {
10782
- return t === void 0 ? { initialDocument: void 0, deferredDocx: void 0 } : typeof t == "string" ? { initialDocument: Or(t), deferredDocx: void 0 } : oh(t) ? { initialDocument: void 0, deferredDocx: t } : { initialDocument: t, deferredDocx: void 0 };
10799
+ function ah(t) {
10800
+ return t === void 0 ? { initialDocument: void 0, deferredDocx: void 0 } : typeof t == "string" ? { initialDocument: Or(t), deferredDocx: void 0 } : ch(t) ? { initialDocument: void 0, deferredDocx: t } : { initialDocument: t, deferredDocx: void 0 };
10783
10801
  }
10784
- function oh(t) {
10802
+ function ch(t) {
10785
10803
  return typeof Blob < "u" && t instanceof Blob || t instanceof ArrayBuffer || t instanceof Uint8Array;
10786
10804
  }
10787
10805
  function xr(t) {
@@ -10790,8 +10808,8 @@ function xr(t) {
10790
10808
  });
10791
10809
  return e;
10792
10810
  }
10793
- const et = 12, sh = 8;
10794
- function Eh(t, e) {
10811
+ const et = 12, lh = 8;
10812
+ function Nh(t, e) {
10795
10813
  const n = `:scope > .sobree-floating-corner[data-placement="${e}"]`, r = t.querySelector(n);
10796
10814
  if (r) return r;
10797
10815
  const i = document.createElement("div");
@@ -10800,7 +10818,7 @@ function Eh(t, e) {
10800
10818
  display: "flex",
10801
10819
  flexDirection: e.startsWith("bottom-") ? "column-reverse" : "column",
10802
10820
  alignItems: e.endsWith("-right") ? "flex-end" : "flex-start",
10803
- gap: `${sh}px`,
10821
+ gap: `${lh}px`,
10804
10822
  // Don't intercept clicks on the underlying paper — only the
10805
10823
  // children should be interactive.
10806
10824
  pointerEvents: "none",
@@ -10812,13 +10830,13 @@ function Eh(t, e) {
10812
10830
  s.style.pointerEvents = "auto";
10813
10831
  }).observe(i, { childList: !0 }), t.appendChild(i), i;
10814
10832
  }
10815
- function Ah(t) {
10816
- const { zone: e, kind: n, stackRoot: r, getSetup: i, setSetup: o, onExit: s } = t, a = ah(e, n, r, i()), l = i()[n][a];
10833
+ function Ph(t) {
10834
+ const { zone: e, kind: n, stackRoot: r, getSetup: i, setSetup: o, onExit: s } = t, a = uh(e, n, r, i()), l = i()[n][a];
10817
10835
  e.replaceChildren();
10818
10836
  const u = document.createTextNode(l);
10819
10837
  e.appendChild(u), e.classList.remove("is-empty"), r.classList.add("is-zone-editing");
10820
10838
  const f = r.contentEditable;
10821
- r.contentEditable = "false", e.contentEditable = "true", e.focus(), ch(u);
10839
+ r.contentEditable = "false", e.contentEditable = "true", e.focus(), fh(u);
10822
10840
  let d = !1;
10823
10841
  const h = () => {
10824
10842
  if (d) return;
@@ -10835,19 +10853,19 @@ function Ah(t) {
10835
10853
  };
10836
10854
  return e.addEventListener("blur", p), e.addEventListener("keydown", y), document.addEventListener("mousedown", m, !0), h;
10837
10855
  }
10838
- function ah(t, e, n, r) {
10856
+ function uh(t, e, n, r) {
10839
10857
  const i = Array.from(n.querySelectorAll(".paper")), o = t.closest(".paper");
10840
10858
  if (!o) return "default";
10841
10859
  const s = i.indexOf(o) + 1, a = i.length, c = r[e];
10842
10860
  return s === 1 && c.differentFirst ? "first" : s === a && c.differentLast && a > 1 ? "last" : "default";
10843
10861
  }
10844
- function ch(t) {
10862
+ function fh(t) {
10845
10863
  const e = document.createRange();
10846
10864
  e.setStart(t, t.length), e.collapse(!0);
10847
10865
  const n = window.getSelection();
10848
10866
  n == null || n.removeAllRanges(), n == null || n.addRange(e);
10849
10867
  }
10850
- class Ch {
10868
+ class Ih {
10851
10869
  constructor(e, n = {}) {
10852
10870
  w(this, "ydoc");
10853
10871
  w(this, "commands");
@@ -11142,7 +11160,7 @@ function Sr(t) {
11142
11160
  focus: t.range.to.offset
11143
11161
  };
11144
11162
  }
11145
- function lh(t) {
11163
+ function dh(t) {
11146
11164
  if (!t || typeof t != "object") return !1;
11147
11165
  const e = t;
11148
11166
  if (!e.user || typeof e.user != "object") return !1;
@@ -11156,7 +11174,7 @@ function lh(t) {
11156
11174
  }
11157
11175
  return !0;
11158
11176
  }
11159
- function uh(t, e, n) {
11177
+ function hh(t, e, n) {
11160
11178
  const r = n.publishOwnSelection ?? !0, i = {
11161
11179
  user: n.user,
11162
11180
  selection: r ? Sr(t.selection.get()) : null
@@ -11173,7 +11191,7 @@ function uh(t, e, n) {
11173
11191
  const s = () => {
11174
11192
  const c = /* @__PURE__ */ new Map();
11175
11193
  for (const [l, u] of e.getStates())
11176
- lh(u) && c.set(l, u);
11194
+ dh(u) && c.set(l, u);
11177
11195
  return c;
11178
11196
  }, a = (c) => {
11179
11197
  n.onChange && n.onChange(s());
@@ -11191,19 +11209,19 @@ function uh(t, e, n) {
11191
11209
  }
11192
11210
  };
11193
11211
  }
11194
- const fh = "sobree-presence-overlay";
11195
- function Nh(t, e, n) {
11212
+ const ph = "sobree-presence-overlay";
11213
+ function Rh(t, e, n) {
11196
11214
  const r = n.container, i = n.blockHost ?? r;
11197
11215
  getComputedStyle(r).position === "static" && (r.style.position = "relative");
11198
11216
  const s = document.createElement("div");
11199
- s.className = fh, s.style.cssText = "position:absolute; inset:0; pointer-events:none; z-index:2;", r.appendChild(s);
11217
+ s.className = ph, s.style.cssText = "position:absolute; inset:0; pointer-events:none; z-index:2;", r.appendChild(s);
11200
11218
  let a = /* @__PURE__ */ new Map();
11201
11219
  const c = (f) => {
11202
11220
  a = f, s.replaceChildren();
11203
11221
  for (const [d, h] of f) {
11204
11222
  if (d === e.clientID || !h.selection) continue;
11205
11223
  const p = i.querySelector(
11206
- `[data-block-id="${dh(h.selection.blockId)}"]`
11224
+ `[data-block-id="${gh(h.selection.blockId)}"]`
11207
11225
  );
11208
11226
  if (!p) continue;
11209
11227
  const y = p.getBoundingClientRect(), m = r.getBoundingClientRect(), x = document.createElement("div");
@@ -11211,7 +11229,7 @@ function Nh(t, e, n) {
11211
11229
  const S = document.createElement("span");
11212
11230
  S.className = "sobree-caret-label", S.textContent = h.user.name, S.style.cssText = `position:absolute; top:-1.4em; left:0; padding:0 4px; background:${h.user.color}; color:#fff; font:11px/1.4 system-ui, sans-serif; border-radius:3px 3px 3px 0; white-space:nowrap;`, x.appendChild(S), s.appendChild(x);
11213
11231
  }
11214
- }, l = uh(t, e, {
11232
+ }, l = hh(t, e, {
11215
11233
  ...n,
11216
11234
  onChange(f) {
11217
11235
  c(f), n.onChange && n.onChange(f);
@@ -11227,7 +11245,7 @@ function Nh(t, e, n) {
11227
11245
  }
11228
11246
  };
11229
11247
  }
11230
- function dh(t) {
11248
+ function gh(t) {
11231
11249
  return typeof CSS < "u" && typeof CSS.escape == "function" ? CSS.escape(t) : t.replace(/(["\\])/g, "\\$1");
11232
11250
  }
11233
11251
  export {
@@ -11237,7 +11255,7 @@ export {
11237
11255
  $r as DEFAULT_PAGE_SETUP,
11238
11256
  Bf as Editor,
11239
11257
  xo as FontFaceRegistry,
11240
- Ch as HeadlessSobree,
11258
+ Ih as HeadlessSobree,
11241
11259
  ii as History,
11242
11260
  ol as MARK_COMMAND_DEFS,
11243
11261
  il as MARK_ON,
@@ -11245,38 +11263,39 @@ export {
11245
11263
  tn as PAGE_SIZES,
11246
11264
  Od as Paper,
11247
11265
  Wd as PaperStack,
11248
- Qd as Sobree,
11266
+ nh as Sobree,
11267
+ eh as VERSION,
11249
11268
  ws as Viewport,
11250
11269
  St as appendBlock,
11251
11270
  pi as applyDocumentToYDoc,
11252
- uh as attachPresence,
11253
- Nh as attachPresenceOverlay,
11271
+ hh as attachPresence,
11272
+ Rh as attachPresenceOverlay,
11254
11273
  Jd as attachSections,
11255
11274
  zs as blocksToTemplate,
11256
11275
  ro as canEmbed,
11257
- Th as createSobree,
11276
+ Ch as createSobree,
11258
11277
  Is as defaultMargins,
11259
11278
  Ps as defaultPageSize,
11260
11279
  Ns as defaultSection,
11261
11280
  en as defaultStyles,
11262
11281
  Ji as deobfuscate,
11263
11282
  wo as embedFontIntoDoc,
11264
- gh as emphasis,
11283
+ yh as emphasis,
11265
11284
  Qt as emptyDocument,
11266
- Ah as enterZoneEdit,
11267
- Sh as fetchBlobStore,
11285
+ Ph as enterZoneEdit,
11286
+ Ah as fetchBlobStore,
11268
11287
  Qi as generateFontKey,
11269
- Eh as getFloatingCorner,
11288
+ Nh as getFloatingCorner,
11270
11289
  Rs as heading,
11271
- xh as inMemoryBlobStore,
11290
+ Eh as inMemoryBlobStore,
11272
11291
  ti as isBlobHash,
11273
11292
  bi as isMarkActive,
11274
- kh as isParagraph,
11275
- lh as isPresenceState,
11276
- vh as isTable,
11277
- wh as makeHeaderFooterRef,
11293
+ Sh as isParagraph,
11294
+ dh as isPresenceState,
11295
+ Th as isTable,
11296
+ xh as makeHeaderFooterRef,
11278
11297
  Zi as obfuscate,
11279
- yh as pageBreak,
11298
+ vh as pageBreak,
11280
11299
  Fe as paragraph,
11281
11300
  Or as parseMarkdown,
11282
11301
  Sr as presenceSelectionFromEditor,
@@ -11287,8 +11306,8 @@ export {
11287
11306
  Zr as resolveStyleCascade,
11288
11307
  li as seedYDoc,
11289
11308
  on as sha256Hex,
11290
- bh as softBreak,
11291
- mh as strong,
11309
+ kh as softBreak,
11310
+ wh as strong,
11292
11311
  _s as templateToBlocks,
11293
11312
  st as text,
11294
11313
  sl as toggleMark