@damiro/stylo 0.12.0 → 0.13.1

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/README.md CHANGED
@@ -180,7 +180,9 @@ whole canvas. See [Canvas header](./docs/wiki/reference/props.md#canvas-header).
180
180
 
181
181
  `inPlace`, `codeLanguages`, `wikiLinkSource`, and `tagSource` are read once,
182
182
  when the editing surface mounts — give `<Stylo>` a `key` derived from the
183
- config to apply a change. Every other prop is fully reactive. See
183
+ config to apply a change. (`codeLanguages` is the exception in `preview`,
184
+ which is a pure function of its props and picks up a change immediately, no
185
+ `key` needed.) Every other prop is fully reactive. See
184
186
  [props · applied at mount](./docs/wiki/reference/props.md#config-applied-at-mount).
185
187
 
186
188
  Pass `wikiLinkSource` — `(query) => { target, label? }[]`, sync or async — to
@@ -208,9 +210,10 @@ full grammar set is ~110 lazy chunks). See
208
210
  Every colour is a `--stylo-*` custom property; override any of them on `.stylo`
209
211
  or an ancestor. A dark palette ships built in and activates under a `.dark` or
210
212
  `[data-theme="dark"]` ancestor — the `next-themes` / shadcn convention.
211
- `--stylo-font-size` (default `0.9375rem`) sets the base editor size and
212
- everything inside scales from it; `--stylo-font-family` and
213
- `--stylo-font-family-mono` set the prose and code fonts.
213
+ `--stylo-font-size` (default `0.9375rem`) sets the base size for the in-place
214
+ canvas, `source`, and `preview` alike — everything inside each scales from it;
215
+ `--stylo-font-family` and `--stylo-font-family-mono` set the prose and code
216
+ fonts.
214
217
 
215
218
  ---
216
219
 
@@ -1,5 +1,5 @@
1
- import { i as e, r as t, t as n } from "./frontmatter-DTCC0gaa.js";
2
- import { S as r, _ as i, a, b as o, c as s, d as c, f as l, g as u, h as d, i as f, l as p, m, n as h, o as g, p as _, r as ee, s as v, t as te, u as ne, v as re, x as y, y as b } from "./useCodeMirror-BI1kEPRE.js";
1
+ import { a as e, o as t, r as n } from "./highlight-B4c0sXF_.js";
2
+ import { S as r, _ as i, a, b as o, c as s, d as c, f as l, g as u, h as d, i as f, l as p, m, n as h, o as g, p as _, r as ee, s as v, t as te, u as ne, v as re, x as y, y as b } from "./useCodeMirror-C3DKpax1.js";
3
3
  import { a as ie, i as x } from "./config-DTBxVhtH.js";
4
4
  import { a as S, n as ae, o as oe, r as C, t as w } from "./embed-Dsu6b-MV.js";
5
5
  import { t as se } from "./katex-BfiLlqfN.js";
@@ -468,18 +468,18 @@ function ct(e, t) {
468
468
  }
469
469
  //#endregion
470
470
  //#region src/inplace/wikilinks.ts
471
- function lt(e, n, r, i, a, o) {
472
- let s = e.state.doc.sliceString(n, r);
471
+ function lt(t, n, r, i, a, o) {
472
+ let s = t.state.doc.sliceString(n, r);
473
473
  if (!s.includes("[[")) return;
474
- let c = e.state.facet(L) != null;
475
- for (let r of s.matchAll(t)) {
476
- let [t = "", s = "", l] = r, u = s.trim(), d = n + (r.index ?? 0);
477
- if (!u || V(a, d + 1) || c && d > 0 && e.state.doc.sliceString(d - 1, d) === "!") continue;
478
- let f = d + t.length, p = l == null ? d + 2 : d + 2 + s.length + 1, m = f - 2;
474
+ let c = t.state.facet(L) != null;
475
+ for (let r of s.matchAll(e)) {
476
+ let [e = "", s = "", l] = r, u = s.trim(), d = n + (r.index ?? 0);
477
+ if (!u || V(a, d + 1) || c && d > 0 && t.state.doc.sliceString(d - 1, d) === "!") continue;
478
+ let f = d + e.length, p = l == null ? d + 2 : d + 2 + s.length + 1, m = f - 2;
479
479
  o.push(D.mark({
480
480
  class: "cm-inplace-link cm-inplace-wikilink",
481
481
  attributes: { "data-stylo-wikilink": u }
482
- }).range(p, m)), i.has(e.state.doc.lineAt(d).number) || (o.push(D.replace({}).range(d, p)), o.push(D.replace({}).range(m, f)));
482
+ }).range(p, m)), i.has(t.state.doc.lineAt(d).number) || (o.push(D.replace({}).range(d, p)), o.push(D.replace({}).range(m, f)));
483
483
  }
484
484
  }
485
485
  //#endregion
@@ -559,15 +559,15 @@ var ht = {
559
559
  function H(e, t) {
560
560
  return e.facet(R) === "never" || !B(e).has(t);
561
561
  }
562
- function U(e, n, r = !1, i = !1) {
563
- let a = e.doc.lineAt(n);
564
- if (!i && !H(e, a.number)) return null;
565
- let o = e.facet(I), s = F(e);
566
- for (let t of [-1, 1]) for (let i = s.resolveInner(n, t); i; i = i.parent) {
567
- let t = ht[i.name];
568
- if (t) {
569
- if (!o[t.toggle]) break;
570
- let e = i.getChildren(t.markType), n = e[0], r = e[e.length - 1];
562
+ function U(t, n, r = !1, i = !1) {
563
+ let a = t.doc.lineAt(n);
564
+ if (!i && !H(t, a.number)) return null;
565
+ let o = t.facet(I), s = F(t);
566
+ for (let e of [-1, 1]) for (let i = s.resolveInner(n, e); i; i = i.parent) {
567
+ let e = ht[i.name];
568
+ if (e) {
569
+ if (!o[e.toggle]) break;
570
+ let t = i.getChildren(e.markType), n = t[0], r = t[t.length - 1];
571
571
  if (!n || !r || n === r) break;
572
572
  return {
573
573
  from: i.from,
@@ -578,26 +578,26 @@ function U(e, n, r = !1, i = !1) {
578
578
  };
579
579
  }
580
580
  if (i.name === "Link") {
581
- if (r || e.doc.sliceString(Math.max(0, i.from - 1), i.from) === "[" || !o.links) break;
582
- let t = i.getChildren("LinkMark");
583
- if (t.length < 2) break;
581
+ if (r || t.doc.sliceString(Math.max(0, i.from - 1), i.from) === "[" || !o.links) break;
582
+ let e = i.getChildren("LinkMark");
583
+ if (e.length < 2) break;
584
584
  return {
585
585
  from: i.from,
586
586
  to: i.to,
587
- contentFrom: t[0].to,
588
- contentTo: t[1].from,
587
+ contentFrom: e[0].to,
588
+ contentTo: e[1].from,
589
589
  kind: "link"
590
590
  };
591
591
  }
592
592
  }
593
- if (o.wikilinks && !r) for (let e of a.text.matchAll(t)) {
594
- let t = a.from + (e.index ?? 0), r = t + e[0].length;
595
- if (n < t || n > r) continue;
596
- let i = e[1] ?? "", o = e[2] != null;
593
+ if (o.wikilinks && !r) for (let t of a.text.matchAll(e)) {
594
+ let e = a.from + (t.index ?? 0), r = e + t[0].length;
595
+ if (n < e || n > r) continue;
596
+ let i = t[1] ?? "", o = t[2] != null;
597
597
  return {
598
- from: t,
598
+ from: e,
599
599
  to: r,
600
- contentFrom: t + 2 + (o ? i.length + 1 : 0),
600
+ contentFrom: e + 2 + (o ? i.length + 1 : 0),
601
601
  contentTo: r - 2,
602
602
  kind: "link"
603
603
  };
@@ -1331,7 +1331,7 @@ var ln = /!\[\[[^\]\n]+?\]\]/, un = [
1331
1331
  }
1332
1332
  },
1333
1333
  {
1334
- re: new RegExp(t.source),
1334
+ re: new RegExp(e.source),
1335
1335
  build: (e) => {
1336
1336
  let t = Z("span", "cm-inplace-wikilink", document.createTextNode(e[2] || e[1] || ""));
1337
1337
  return t.dataset.styloWikilink = e[1] ?? "", t;
@@ -1924,11 +1924,11 @@ function zn(e, t) {
1924
1924
  }
1925
1925
  return null;
1926
1926
  }
1927
- function Bn(e, n) {
1928
- let r = e.state.doc.lineAt(n);
1929
- for (let e of r.text.matchAll(t)) {
1930
- let t = r.from + (e.index ?? 0), i = t + e[0].length;
1931
- if (!(n < t || n > i)) return Rn(t, i, (e[1] ?? "").trim());
1927
+ function Bn(t, n) {
1928
+ let r = t.state.doc.lineAt(n);
1929
+ for (let t of r.text.matchAll(e)) {
1930
+ let e = r.from + (t.index ?? 0), i = e + t[0].length;
1931
+ if (!(n < e || n > i)) return Rn(e, i, (t[1] ?? "").trim());
1932
1932
  }
1933
1933
  return null;
1934
1934
  }
@@ -2021,14 +2021,14 @@ var Wn = P.define({
2021
2021
  };
2022
2022
  }, this.contentDOM.addEventListener("pointerdown", this.onPointerDown, !0), this.onContextMenu = (t) => {
2023
2023
  let n = t.target;
2024
- e.state.facet(Ce) && (n?.closest(".cm-inplace-table-edit") || (t.preventDefault(), this.longPress.cancel(), !(Date.now() - this.longPressAt < 700) && this.openMenuAt(t.clientX, t.clientY, n)));
2024
+ !e.state.facet(Ce) || e.state.readOnly || n?.closest(".cm-inplace-table-edit") || (t.preventDefault(), this.longPress.cancel(), !(Date.now() - this.longPressAt < 700) && this.openMenuAt(t.clientX, t.clientY, n));
2025
2025
  }, this.contentDOM.addEventListener("contextmenu", this.onContextMenu), this.longPress = an(this.contentDOM, { onLongPress: (e, t, n) => {
2026
2026
  this.longPressAt = Date.now(), this.openMenuAt(e, t, n);
2027
2027
  } });
2028
2028
  }
2029
2029
  openMenuAt(e, t, n) {
2030
2030
  let r = this.view;
2031
- if (!r.state.facet(Ce) || n?.closest(".cm-inplace-table-edit")) return;
2031
+ if (!r.state.facet(Ce) || r.state.readOnly || n?.closest(".cm-inplace-table-edit")) return;
2032
2032
  let i = n?.closest(".cm-inplace-hr");
2033
2033
  if (i) {
2034
2034
  let n = r.posAtDOM(i);
@@ -2089,7 +2089,7 @@ function Yn(e) {
2089
2089
  };
2090
2090
  }
2091
2091
  function Xn(e, t, n) {
2092
- if (e.state.facet(ke) !== "bar" || e.state.field(Kn, !1)) return null;
2092
+ if (e.state.facet(ke) !== "bar" || e.state.readOnly || e.state.field(Kn, !1)) return null;
2093
2093
  let r = Yn(e);
2094
2094
  if (!r) return null;
2095
2095
  let { box: i, inCell: a } = r;
@@ -2140,8 +2140,8 @@ var Zn = class {
2140
2140
  e.dom.appendChild(this.bar), t.addEventListener("scroll", this.onScroll, !0), t.addEventListener("selectionchange", this.onSelectionChange);
2141
2141
  }
2142
2142
  update(e) {
2143
- let t = e.startState.field(Kn, !1) !== e.state.field(Kn, !1);
2144
- (e.selectionSet || e.docChanged || e.focusChanged || t) && this.schedule();
2143
+ let t = e.startState.field(Kn, !1) !== e.state.field(Kn, !1), n = e.startState.readOnly !== e.state.readOnly;
2144
+ (e.selectionSet || e.docChanged || e.focusChanged || t || n) && this.schedule();
2145
2145
  }
2146
2146
  schedule() {
2147
2147
  this.view.requestMeasure({
@@ -2661,7 +2661,7 @@ function mr(e = {}) {
2661
2661
  //#endregion
2662
2662
  //#region src/inplace/InPlaceView.tsx
2663
2663
  var hr = () => () => {}, gr = () => null;
2664
- function _r({ value: t, onChange: n, readOnly: i, placeholder: a, onWikiLinkClick: o, onLinkClick: s, inPlace: c, codeLanguages: l, wikiLinkSource: u, tagSource: d, embedSource: f, onResolveError: p, onSave: m, onViewChange: h, canvasHeader: g }) {
2664
+ function _r({ value: e, onChange: n, readOnly: i, placeholder: a, onWikiLinkClick: o, onLinkClick: s, inPlace: c, codeLanguages: l, wikiLinkSource: u, tagSource: d, embedSource: f, onResolveError: p, onSave: m, onViewChange: h, canvasHeader: g }) {
2665
2665
  let _ = T(o);
2666
2666
  _.current = o;
2667
2667
  let ee = T(s);
@@ -2678,7 +2678,7 @@ function _r({ value: t, onChange: n, readOnly: i, placeholder: a, onWikiLinkClic
2678
2678
  inPlace: c,
2679
2679
  embedRegistry: f ? v : void 0
2680
2680
  }), ...S ? [ue.of(S.panel)] : []]), w = te({
2681
- value: t,
2681
+ value: e,
2682
2682
  onChange: n,
2683
2683
  readOnly: i,
2684
2684
  placeholder: a,
@@ -2691,7 +2691,7 @@ function _r({ value: t, onChange: n, readOnly: i, placeholder: a, onWikiLinkClic
2691
2691
  onViewChange: ie
2692
2692
  });
2693
2693
  return /* @__PURE__ */ _e("div", {
2694
- className: e.inplace,
2694
+ className: t.inplace,
2695
2695
  ref: w,
2696
2696
  children: [f && ne.map((e) => de(/* @__PURE__ */ ge(oe, {
2697
2697
  reference: e.ref,
@@ -2704,4 +2704,4 @@ function _r({ value: t, onChange: n, readOnly: i, placeholder: a, onWikiLinkClic
2704
2704
  //#endregion
2705
2705
  export { _r as InPlaceView };
2706
2706
 
2707
- //# sourceMappingURL=InPlaceView-BWc06Jso.js.map
2707
+ //# sourceMappingURL=InPlaceView-DJzxnK6B.js.map