@pretextbook/web-editor 0.0.17 → 0.0.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/index.es.js CHANGED
@@ -2308,9 +2308,19 @@ const wg = {
2308
2308
  const t = he(null), n = he(null), i = he(null), [, s] = He(!1), [, o] = He(!1);
2309
2309
  Se(() => () => {
2310
2310
  n.current?.dispose?.(), i.current && clearTimeout(i.current);
2311
- }, []);
2311
+ }, []), Se(() => {
2312
+ const u = t.current;
2313
+ if (!u) return;
2314
+ const d = u.getModel();
2315
+ if (d && d.getValue() !== r) {
2316
+ const h = u.getPosition(), f = u.getSelections();
2317
+ d.setValue(r), h && u.setPosition(h), f && u.setSelections(f);
2318
+ }
2319
+ }, [r]);
2312
2320
  const a = (u) => {
2313
- t.current = u, n.current?.dispose?.(), n.current = u.onDidChangeModelContent(() => {
2321
+ t.current = u;
2322
+ const d = u.getModel();
2323
+ d && d.getValue() !== r && d.setValue(r), n.current?.dispose?.(), n.current = u.onDidChangeModelContent(() => {
2314
2324
  l();
2315
2325
  }), l();
2316
2326
  }, l = () => {
@@ -2332,7 +2342,7 @@ const wg = {
2332
2342
  options: wg,
2333
2343
  height: "100%",
2334
2344
  language: "xml",
2335
- value: r,
2345
+ defaultValue: r,
2336
2346
  onMount: a,
2337
2347
  onChange: (u) => {
2338
2348
  i.current && clearTimeout(i.current), i.current = setTimeout(() => {
@@ -35026,20 +35036,38 @@ const hw = we.create({
35026
35036
  }
35027
35037
  document.body.appendChild(n), n.submit(), n.remove();
35028
35038
  }, gw = ({ content: r, title: e, onRebuild: t }) => {
35029
- const [n, i] = He(!1), s = he(null), o = Ke(() => {
35030
- const l = r, c = e || "Document Title";
35039
+ const [n, i] = He(!1), s = he(null), o = he(null), a = Ke(() => {
35040
+ const c = r, u = e || "Document Title";
35041
+ try {
35042
+ const d = s.current?.contentWindow;
35043
+ d && (o.current = {
35044
+ x: d.scrollX,
35045
+ y: d.scrollY
35046
+ });
35047
+ } catch {
35048
+ o.current = null;
35049
+ }
35031
35050
  if (i(!0), t) {
35032
- t(l, c, (d, h) => {
35033
- mw(d, h, "fullPreview");
35051
+ t(c, u, (h, f) => {
35052
+ mw(h, f, "fullPreview");
35034
35053
  });
35035
35054
  return;
35036
35055
  }
35037
35056
  }, [r, e, t]);
35038
35057
  Se(() => {
35039
- o();
35058
+ a();
35040
35059
  }, []);
35041
- const a = () => {
35042
- i(!1);
35060
+ const l = () => {
35061
+ if (i(!1), o.current) {
35062
+ try {
35063
+ s.current?.contentWindow?.scrollTo(
35064
+ o.current.x,
35065
+ o.current.y
35066
+ );
35067
+ } catch {
35068
+ }
35069
+ o.current = null;
35070
+ }
35043
35071
  };
35044
35072
  return /* @__PURE__ */ K.jsxs("div", { className: "pretext-plus-editor__full-preview", children: [
35045
35073
  /* @__PURE__ */ K.jsxs("div", { className: "pretext-plus-editor__preview-header", children: [
@@ -35048,7 +35076,7 @@ const hw = we.create({
35048
35076
  "button",
35049
35077
  {
35050
35078
  className: "pretext-plus-editor__rebuild-button",
35051
- onClick: () => o(),
35079
+ onClick: () => a(),
35052
35080
  children: "Rebuild"
35053
35081
  }
35054
35082
  )
@@ -35064,7 +35092,7 @@ const hw = we.create({
35064
35092
  ref: s,
35065
35093
  className: "pretext-plus-editor__preview-iframe",
35066
35094
  name: "fullPreview",
35067
- onLoad: a
35095
+ onLoad: l
35068
35096
  }
35069
35097
  )
35070
35098
  ] })