@pretextbook/web-editor 0.4.0 → 0.4.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/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ DocumentSection,
12
12
  /** @deprecated Chapters are now plain `Division` records with type `"chapter"`. */
13
13
  DocumentChapter, } from "./types/sections";
14
14
  export type { DivisionTreeNode } from "./sectionUtils";
15
- export { parseDivisionRefs, insertDivisionRef, removeDivisionRef, moveDivisionRef, reorderDivisionRefs, normalizeSelfClosingRefs, getOrphanedDivisions, getOrphanRoots, buildDivisionTree, wrapDivisionForPreview, updateDivisionTitle, createNewSection, createIntroduction, createConclusion, stripSectionWrapper, rewrapSection, ensureSectionWrapper, mergeTwoSections, getSectionAttributes, updateSectionMetadata, stripLatexSectionWrapper, rewrapLatexSection, ensureLatexSectionWrapper, updateLatexSectionTitle, createNewLatexSection, createLatexIntroduction, createLatexConclusion, } from "./sectionUtils";
15
+ export { assembleProjectSource, parseDivisionRefs, insertDivisionRef, removeDivisionRef, moveDivisionRef, reorderDivisionRefs, normalizeSelfClosingRefs, getOrphanedDivisions, getOrphanRoots, buildDivisionTree, wrapDivisionForPreview, updateDivisionTitle, createNewSection, createIntroduction, createConclusion, stripSectionWrapper, rewrapSection, ensureSectionWrapper, mergeTwoSections, getSectionAttributes, updateSectionMetadata, stripLatexSectionWrapper, rewrapLatexSection, ensureLatexSectionWrapper, updateLatexSectionTitle, createNewLatexSection, createLatexIntroduction, createLatexConclusion, } from "./sectionUtils";
16
16
  export { default as CodeEditor } from "./components/CodeEditor";
17
17
  export { VisualEditor } from "@pretextbook/visual-editor";
18
18
  export { default as FullPreview } from "./components/FullPreview";
package/dist/index.es.js CHANGED
@@ -95542,18 +95542,35 @@ function $6(e, t) {
95542
95542
  for (let e of n) for (let t of H6(e.content)) r.has(t) && i.add(t);
95543
95543
  return n.filter((e) => !i.has(e.xmlId));
95544
95544
  }
95545
- var e8 = new Set(["part", "chapter"]), t8 = new Set([
95545
+ function e8(e, t, n) {
95546
+ let r = t.find((t) => t.xmlId === e);
95547
+ if (!r) return `<!-- missing division: ${e} -->`;
95548
+ if (n.has(e)) return `<!-- circular reference: ${e} -->`;
95549
+ let i;
95550
+ if (r.sourceFormat === "pretext") i = r.content;
95551
+ else {
95552
+ let { pretextSource: e, pretextError: t } = v3(r.sourceFormat === "latex" ? A6(r.content, r.type) : D6(r.content), r.sourceFormat), n = e ?? `<!-- conversion error: ${t} -->`;
95553
+ i = `<${r.type} xml:id="${r.xmlId}">\n<title>${r.title}</title>\n\n${n}\n</${r.type}>`;
95554
+ }
95555
+ if (r.sourceFormat !== "pretext") return i;
95556
+ let a = new Set(n).add(e);
95557
+ return i.replace(/<plus:[a-z-]+\s[^>]*ref="([^"]+)"[^>]*?(?:\/>|>\s*<\/plus:[a-z-]+>)/g, (e, n) => e8(n, t, a));
95558
+ }
95559
+ function t8(e, t) {
95560
+ return e8(t, e, /* @__PURE__ */ new Set());
95561
+ }
95562
+ var n8 = new Set(["part", "chapter"]), r8 = new Set([
95546
95563
  "book",
95547
95564
  "article",
95548
95565
  "slideshow"
95549
95566
  ]);
95550
- function n8(e, t, n) {
95551
- let r = t8.has(e) ? t : e8.has(e) ? `<book>\n${t}\n</book>` : `<article>\n${t}\n</article>`;
95567
+ function i8(e, t, n) {
95568
+ let r = r8.has(e) ? t : n8.has(e) ? `<book>\n${t}\n</book>` : `<article>\n${t}\n</article>`;
95552
95569
  return `<pretext>\n${n.trim() ? `${n.trim()}\n` : ""}${r}\n</pretext>`;
95553
95570
  }
95554
95571
  //#endregion
95555
95572
  //#region src/components/toc/ArticleToc.tsx
95556
- var r8 = ({ onOpenAssetPicker: e }) => {
95573
+ var a8 = ({ onOpenAssetPicker: e }) => {
95557
95574
  let t = E3((e) => e.divisions), r = E3((e) => e.rootDivisionId), i = E3((e) => e.activeDivisionId), a = E3((e) => e.selectSection), o = E3((e) => e.removeSection), s = E3((e) => e.divisionContentChange), c = E3((e) => e.insertAtCursor), l = E3((e) => e.startSectionEdit), u = E3((e) => e.setEditDraft), f = E3((e) => e.commitSectionEdit), p = E3((e) => e.cancelSectionEdit), m = E3((e) => e.editingId), h = E3((e) => e.editDraft), g = t ? t.find((e) => e.xmlId === r) ?? t.find((e) => e.type === "book" || e.type === "article" || e.type === "slideshow") ?? t[0] ?? null : null, v = g && t ? Q6(t, g.xmlId) : [], y = g && t ? $6(t, g.xmlId) : [], [b, x] = _(/* @__PURE__ */ new Set()), S = (e) => !b.has(e), C = (e) => {
95558
95575
  x((t) => {
95559
95576
  let n = new Set(t);
@@ -95737,7 +95754,7 @@ var r8 = ({ onOpenAssetPicker: e }) => {
95737
95754
  children: "Manage Assets"
95738
95755
  })
95739
95756
  ] });
95740
- }, i8 = ({ isCollapsed: e, onToggleCollapse: t, onOpenAssetPicker: n }) => e ? /* @__PURE__ */ (0, P.jsx)("div", {
95757
+ }, o8 = ({ isCollapsed: e, onToggleCollapse: t, onOpenAssetPicker: n }) => e ? /* @__PURE__ */ (0, P.jsx)("div", {
95741
95758
  className: "pretext-plus-editor__toc pretext-plus-editor__toc--collapsed",
95742
95759
  children: /* @__PURE__ */ (0, P.jsx)("button", {
95743
95760
  type: "button",
@@ -95765,8 +95782,8 @@ var r8 = ({ onOpenAssetPicker: e }) => {
95765
95782
  children: "✕"
95766
95783
  })
95767
95784
  })]
95768
- }), /* @__PURE__ */ (0, P.jsx)(r8, { onOpenAssetPicker: n })]
95769
- }), a8 = class extends t {
95785
+ }), /* @__PURE__ */ (0, P.jsx)(a8, { onOpenAssetPicker: n })]
95786
+ }), s8 = class extends t {
95770
95787
  state = { error: null };
95771
95788
  static getDerivedStateFromError(e) {
95772
95789
  return { error: e };
@@ -95805,7 +95822,7 @@ var r8 = ({ onOpenAssetPicker: e }) => {
95805
95822
  };
95806
95823
  //#endregion
95807
95824
  //#region src/store/editorStore.ts
95808
- function o8(e) {
95825
+ function c8(e) {
95809
95826
  let t = () => {}, n = { cbs: {
95810
95827
  selectDivision: t,
95811
95828
  addDivision: t,
@@ -95902,7 +95919,7 @@ function o8(e) {
95902
95919
  }
95903
95920
  //#endregion
95904
95921
  //#region src/store/EditorStoreProvider.tsx
95905
- function s8({ store: e, children: t }) {
95922
+ function l8({ store: e, children: t }) {
95906
95923
  return /* @__PURE__ */ (0, P.jsx)(T3.Provider, {
95907
95924
  value: e,
95908
95925
  children: t
@@ -95910,10 +95927,10 @@ function s8({ store: e, children: t }) {
95910
95927
  }
95911
95928
  //#endregion
95912
95929
  //#region src/components/Editors.tsx
95913
- var c8 = (e, t) => e.find((e) => t ? e.xmlId === t : e.type === "book" || e.type === "article" || e.type === "slideshow") ?? e[0] ?? null, l8 = (e) => {
95930
+ var u8 = (e, t) => e.find((e) => t ? e.xmlId === t : e.type === "book" || e.type === "article" || e.type === "slideshow") ?? e[0] ?? null, d8 = (e) => {
95914
95931
  let [t] = _(() => {
95915
- let t = c8(e.divisions, e.rootDivisionId), n = e.activeDivisionId ?? t?.xmlId ?? null, r = e.divisions.find((e) => e.xmlId === n) ?? t;
95916
- return o8({
95932
+ let t = u8(e.divisions, e.rootDivisionId), n = e.activeDivisionId ?? t?.xmlId ?? null, r = e.divisions.find((e) => e.xmlId === n) ?? t;
95933
+ return c8({
95917
95934
  source: r?.content ?? "",
95918
95935
  sourceFormat: r?.sourceFormat ?? "pretext",
95919
95936
  title: e.title ?? "Document Title",
@@ -95925,15 +95942,15 @@ var c8 = (e, t) => e.find((e) => t ? e.xmlId === t : e.type === "book" || e.type
95925
95942
  activeDivisionId: n
95926
95943
  });
95927
95944
  });
95928
- return /* @__PURE__ */ (0, P.jsx)(s8, {
95945
+ return /* @__PURE__ */ (0, P.jsx)(l8, {
95929
95946
  store: t.store,
95930
- children: /* @__PURE__ */ (0, P.jsx)(u8, {
95947
+ children: /* @__PURE__ */ (0, P.jsx)(f8, {
95931
95948
  ...e,
95932
95949
  bindCallbacks: t.bindCallbacks
95933
95950
  })
95934
95951
  });
95935
- }, u8 = (e) => {
95936
- let { bindCallbacks: t } = e, n = E3((e) => e.showFullPreview), r = E3((e) => e.isNarrowScreen), i = E3((e) => e.setIsNarrowScreen), a = E3((e) => e.activeTab), o = E3((e) => e.setActiveTab), s = E3((e) => e.isTocCollapsed), c = E3((e) => e.setIsTocCollapsed), l = E3((e) => e.isLatexDialogOpen), u = E3((e) => e.isConvertDialogOpen), f = E3((e) => e.isDocinfoEditorOpen), p = E3((e) => e.isAssetPickerOpen), v = E3((e) => e.openModal), y = E3((e) => e.closeModal), b = E3((e) => e.internalTitle), x = E3((e) => e.setInternalTitle), S = E3((e) => e.internalDocinfo), C = E3((e) => e.internalCommonDocinfo), w = E3((e) => e.internalUseCommonDocinfo), T = E3((e) => e.syncState), E = e.title ?? b, D = g(null), O = g(null), k = c8(e.divisions, e.rootDivisionId), [A, j] = _(() => k?.xmlId ?? null), ee = e.activeDivisionId === void 0 ? A : e.activeDivisionId, M = e.divisions.find((e) => e.xmlId === ee) ?? e.divisions[0] ?? null, te = M?.sourceFormat ?? "pretext", ne = M ? te === "latex" ? A6(M.content, M.type) : D6(M.content) : "", N = (t, n, r, i) => {
95952
+ }, f8 = (e) => {
95953
+ let { bindCallbacks: t } = e, n = E3((e) => e.showFullPreview), r = E3((e) => e.isNarrowScreen), i = E3((e) => e.setIsNarrowScreen), a = E3((e) => e.activeTab), o = E3((e) => e.setActiveTab), s = E3((e) => e.isTocCollapsed), c = E3((e) => e.setIsTocCollapsed), l = E3((e) => e.isLatexDialogOpen), u = E3((e) => e.isConvertDialogOpen), f = E3((e) => e.isDocinfoEditorOpen), p = E3((e) => e.isAssetPickerOpen), v = E3((e) => e.openModal), y = E3((e) => e.closeModal), b = E3((e) => e.internalTitle), x = E3((e) => e.setInternalTitle), S = E3((e) => e.internalDocinfo), C = E3((e) => e.internalCommonDocinfo), w = E3((e) => e.internalUseCommonDocinfo), T = E3((e) => e.syncState), E = e.title ?? b, D = g(null), O = g(null), k = u8(e.divisions, e.rootDivisionId), [A, j] = _(() => k?.xmlId ?? null), ee = e.activeDivisionId === void 0 ? A : e.activeDivisionId, M = e.divisions.find((e) => e.xmlId === ee) ?? e.divisions[0] ?? null, te = M?.sourceFormat ?? "pretext", ne = M ? te === "latex" ? A6(M.content, M.type) : D6(M.content) : "", N = (t, n, r, i) => {
95937
95954
  e.onContentChange({
95938
95955
  xmlId: t,
95939
95956
  sourceContent: n,
@@ -96007,7 +96024,7 @@ var c8 = (e, t) => e.find((e) => t ? e.xmlId === t : e.type === "book" || e.type
96007
96024
  hasFeedback: e.onFeedbackSubmit !== void 0
96008
96025
  });
96009
96026
  });
96010
- let le = e.useCommonDocinfo ?? w ? e.commonDocinfo ?? C : e.docinfo ?? S, ue = M ? te === "pretext" ? M.content : re === void 0 ? void 0 : `<${M.type} xml:id="${M.xmlId}">\n<title>${M.title}</title>\n\n${re}\n</${M.type}>` : void 0, I = M && ue !== void 0 ? n8(M.type, ue, le) : void 0, de = () => D.current?.rebuild(), fe = () => {
96027
+ let le = e.useCommonDocinfo ?? w ? e.commonDocinfo ?? C : e.docinfo ?? S, ue = M ? te === "pretext" ? M.content : re === void 0 ? void 0 : `<${M.type} xml:id="${M.xmlId}">\n<title>${M.title}</title>\n\n${re}\n</${M.type}>` : void 0, I = M && ue !== void 0 ? i8(M.type, ue, le) : void 0, de = () => D.current?.rebuild(), fe = () => {
96011
96028
  e.onSave?.(), D.current?.rebuild();
96012
96029
  }, pe = (t) => {
96013
96030
  let n = t.ctrlKey || t.metaKey;
@@ -96047,7 +96064,7 @@ var c8 = (e, t) => e.find((e) => t ? e.xmlId === t : e.type === "book" || e.type
96047
96064
  editDisabledReason: te === "markdown" ? "Visual editing is not available for Markdown documents." : te === "latex" ? "Visual editing is not available for LaTeX documents." : "",
96048
96065
  onChange: (e) => ie(e)
96049
96066
  });
96050
- let ge = /* @__PURE__ */ (0, P.jsx)(i8, {
96067
+ let ge = /* @__PURE__ */ (0, P.jsx)(o8, {
96051
96068
  isCollapsed: s,
96052
96069
  onToggleCollapse: () => c((e) => !e),
96053
96070
  onOpenAssetPicker: e.projectAssets === void 0 ? void 0 : () => v("isAssetPickerOpen")
@@ -96135,7 +96152,7 @@ var c8 = (e, t) => e.find((e) => t ? e.xmlId === t : e.type === "book" || e.type
96135
96152
  }), /* @__PURE__ */ (0, P.jsxs)("div", {
96136
96153
  className: "pretext-plus-editor__editor-displays",
96137
96154
  children: [
96138
- /* @__PURE__ */ (0, P.jsx)(a8, {
96155
+ /* @__PURE__ */ (0, P.jsx)(s8, {
96139
96156
  resetKeys: [ne, ee],
96140
96157
  children: xe
96141
96158
  }),
@@ -96185,6 +96202,6 @@ var c8 = (e, t) => e.find((e) => t ? e.xmlId === t : e.type === "book" || e.type
96185
96202
  });
96186
96203
  };
96187
96204
  //#endregion
96188
- export { tc as CodeEditor, W3 as DocinfoEditor, l8 as Editors, b3 as FeedbackLink, DR as FullPreview, wR as VisualEditor, Q6 as buildDivisionTree, h3 as convertLatexToPretext, E6 as createConclusion, T6 as createIntroduction, I6 as createLatexConclusion, F6 as createLatexIntroduction, P6 as createNewLatexSection, w6 as createNewSection, v3 as derivePretextContent, m3 as detectSourceFormat, M6 as ensureLatexSectionWrapper, k6 as ensureSectionWrapper, $6 as getOrphanRoots, Z6 as getOrphanedDivisions, R6 as getSectionAttributes, G6 as insertDivisionRef, L6 as mergeTwoSections, q6 as moveDivisionRef, Y6 as normalizeSelfClosingRefs, H6 as parseDivisionRefs, ER as postToIframe, K6 as removeDivisionRef, J6 as reorderDivisionRefs, j6 as rewrapLatexSection, O6 as rewrapSection, A6 as stripLatexSectionWrapper, D6 as stripSectionWrapper, C6 as updateDivisionTitle, N6 as updateLatexSectionTitle, z6 as updateSectionMetadata, n8 as wrapDivisionForPreview };
96205
+ export { tc as CodeEditor, W3 as DocinfoEditor, d8 as Editors, b3 as FeedbackLink, DR as FullPreview, wR as VisualEditor, t8 as assembleProjectSource, Q6 as buildDivisionTree, h3 as convertLatexToPretext, E6 as createConclusion, T6 as createIntroduction, I6 as createLatexConclusion, F6 as createLatexIntroduction, P6 as createNewLatexSection, w6 as createNewSection, v3 as derivePretextContent, m3 as detectSourceFormat, M6 as ensureLatexSectionWrapper, k6 as ensureSectionWrapper, $6 as getOrphanRoots, Z6 as getOrphanedDivisions, R6 as getSectionAttributes, G6 as insertDivisionRef, L6 as mergeTwoSections, q6 as moveDivisionRef, Y6 as normalizeSelfClosingRefs, H6 as parseDivisionRefs, ER as postToIframe, K6 as removeDivisionRef, J6 as reorderDivisionRefs, j6 as rewrapLatexSection, O6 as rewrapSection, A6 as stripLatexSectionWrapper, D6 as stripSectionWrapper, C6 as updateDivisionTitle, N6 as updateLatexSectionTitle, z6 as updateSectionMetadata, i8 as wrapDivisionForPreview };
96189
96206
 
96190
96207
  //# sourceMappingURL=index.es.js.map