@pretextbook/web-editor 0.12.0 → 0.14.0

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.
@@ -151,7 +151,7 @@ export declare function updateLatexDivisionMetadata(division: Division, changes:
151
151
  * Returns `null` when the conversion fails, so callers can disable the convert
152
152
  * action / fall back.
153
153
  */
154
- export declare function latexDivisionToTaggedPretext(division: Pick<Division, "content" | "type" | "xmlId" | "title">): string | null;
154
+ export declare function latexDivisionToTaggedPretext(division: Pick<Division, "source" | "type" | "xmlId" | "title">): string | null;
155
155
  /** Create a new blank LaTeX section as a `Division`. */
156
156
  export declare function createNewLatexSection(title?: string): DocumentSection;
157
157
  /** Create a blank LaTeX introduction. */
@@ -217,7 +217,7 @@ export declare function extractDivisionMetadata(content: string): {
217
217
  * Pass `null` for `xmlId` or `label` to remove the attribute entirely.
218
218
  * Omit a key (or pass `undefined`) to leave it unchanged.
219
219
  *
220
- * Returns a new `DocumentSection` with updated `content`, `title`, and `type`.
220
+ * Returns a new `DocumentSection` with updated `source`, `title`, and `type`.
221
221
  */
222
222
  export declare function updateSectionMetadata(section: DocumentSection, changes: {
223
223
  title?: string;
@@ -248,6 +248,7 @@ export declare function parseMarkdownFrontmatter(content: string): {
248
248
  type: DivisionType;
249
249
  xmlId: string;
250
250
  label: string;
251
+ title: string;
251
252
  body: string;
252
253
  } | null;
253
254
  /** Build a `---`-fenced frontmatter block for a markdown division. */
@@ -255,15 +256,23 @@ export declare function buildMarkdownFrontmatter(meta: {
255
256
  type: DivisionType;
256
257
  xmlId: string;
257
258
  label: string;
259
+ title?: string;
258
260
  }): string;
259
- /** Extract a markdown division's leading `# heading` text, or `null` if none. */
261
+ /**
262
+ * Extract a markdown division's leading `# heading` text, or `null` if none.
263
+ * Legacy fallback only — titles now live in frontmatter's `title` key; see
264
+ * {@link extractMarkdownDivisionMetadata}. Kept so documents saved before the
265
+ * frontmatter-title migration still show a real title instead of "Untitled".
266
+ */
260
267
  export declare function deriveMarkdownTitle(body: string): string | null;
261
268
  /**
262
269
  * Derive a markdown division's title, type, `xml:id`, and `label` directly from
263
- * its source — the frontmatter for the structural metadata and the leading
264
- * `# heading` for the title. Markdown analogue of {@link extractDivisionMetadata};
265
- * returns `null` when the frontmatter is absent/malformed (both common
266
- * mid-edit), so callers can skip the update rather than clobber metadata.
270
+ * its source — all from the frontmatter block. Markdown analogue of
271
+ * {@link extractDivisionMetadata}; returns `null` when the frontmatter is
272
+ * absent/malformed (both common mid-edit), so callers can skip the update
273
+ * rather than clobber metadata. When the frontmatter carries no `title` (a
274
+ * document predating the migration to a frontmatter title), falls back to the
275
+ * body's leading `# heading`.
267
276
  */
268
277
  export declare function extractMarkdownDivisionMetadata(content: string): {
269
278
  title: string;
@@ -273,12 +282,12 @@ export declare function extractMarkdownDivisionMetadata(content: string): {
273
282
  } | null;
274
283
  /**
275
284
  * Update the title, type (`division`), `xml:id`, and `label` of a markdown
276
- * division. Structural metadata is rewritten in the frontmatter block; a title
277
- * change rewrites the body's leading `# heading`. Markdown analogue of
278
- * {@link updateSectionMetadata} (which is XML-only and would wrongly inject a
279
- * `<title>` element). Pass `null`/empty for `label` to clear it; omit a key to
280
- * leave it unchanged. The `xml:id` is never cleared — it is the division's
281
- * identity — so an empty value falls back to the record's existing id.
285
+ * division all rewritten in the frontmatter block; the body is left
286
+ * untouched. Markdown analogue of {@link updateSectionMetadata} (which is
287
+ * XML-only and would wrongly inject a `<title>` element). Pass `null`/empty
288
+ * for `label` to clear it; omit a key to leave it unchanged. The `xml:id` is
289
+ * never cleared — it is the division's identity — so an empty value falls
290
+ * back to the record's existing id.
282
291
  */
283
292
  export declare function updateMarkdownDivisionMetadata(division: Division, changes: {
284
293
  title?: string;
@@ -306,8 +315,12 @@ export declare function canEmbedDivisionRefs(sourceFormat: SourceFormat): boolea
306
315
  *
307
316
  * Only direct children are returned — the function does not recurse.
308
317
  * Call it for each division in the pool to build the full tree.
318
+ *
319
+ * `sourceFormat` is the parent division's format: only that format's include
320
+ * syntax is scanned, and its verbatim spans are blanked first, so example
321
+ * placeholders in code samples don't become phantom children.
309
322
  */
310
- export declare function parseDivisionRefs(content: string): string[];
323
+ export declare function parseDivisionRefs(content: string, sourceFormat: SourceFormat): string[];
311
324
  /**
312
325
  * Like {@link parseDivisionRefs} but also returns the division type inferred
313
326
  * from the tag name (e.g. `<plus:chapter ref="x"/>` → `{ type: "chapter", xmlId: "x" }`).
@@ -318,7 +331,7 @@ export declare function parseDivisionRefs(content: string): string[];
318
331
  * skipped. The generic `<plus:division ref="x"/>` alias falls back to type
319
332
  * `"section"`, matching {@link tagToType}'s default for unrecognised tags.
320
333
  */
321
- export declare function parseDivisionRefsWithTypes(content: string): {
334
+ export declare function parseDivisionRefsWithTypes(content: string, sourceFormat: SourceFormat): {
322
335
  xmlId: string;
323
336
  type: DivisionType;
324
337
  }[];
@@ -340,7 +353,7 @@ export interface AssetRef {
340
353
  * disjoint tag set (`image`/`doenet`) so the two kinds of include are never
341
354
  * conflated.
342
355
  */
343
- export declare function parseAssetRefs(content: string): AssetRef[];
356
+ export declare function parseAssetRefs(content: string, sourceFormat: SourceFormat): AssetRef[];
344
357
  /**
345
358
  * Rewrite every asset placeholder for `oldRef` in `content` to use `newRef`
346
359
  * instead, leaving any other attributes (e.g. `width="50%"`) untouched. The
@@ -6,8 +6,8 @@ export type AssetKind = "image" | "doenet";
6
6
  export interface Asset {
7
7
  /** Stable server-assigned identifier (hidden from users). */
8
8
  id: string;
9
- /** Human-readable display name shown in the library UI. */
10
- name: string;
9
+ /** Human-readable display title shown in the library UI. */
10
+ title: string;
11
11
  /** Short reference used when authoring references, e.g. `"euler-painting"`.
12
12
  * Authors write e.g. `<plus:image ref="euler-painting"/>` and the build system
13
13
  * resolves it to the necessary core PreTeXt markup based upon the kind of
@@ -26,28 +26,29 @@ export interface Asset {
26
26
  /**
27
27
  * Whether this asset is backed by an uploaded/fetched file rather than
28
28
  * being defined purely by `source`. File-based image assets emit a
29
- * `source` attribute on the generated `<image>` element (from
30
- * {@link fileRef}, falling back to {@link url}); non-file image assets
31
- * carry no `source` attribute and rely entirely on their authored
29
+ * `source` attribute on the generated `<image>` element built from this
30
+ * asset's {@link ref} plus a file extension (e.g. `ref="euler-painting"`
31
+ * with a PNG upload emits `source="euler-painting.png"`); non-file image
32
+ * assets carry no `source` attribute and rely entirely on their authored
32
33
  * `source` content.
33
34
  */
34
35
  isFile?: boolean;
35
36
  /**
36
- * Publicly accessible URL used **only** as the asset-manager thumbnail
37
- * (`<img src={url}>`). It is no longer the value written to the `<image>`
38
- * `source` attribute — use {@link fileRef} for that. It remains the
39
- * `source` fallback when `fileRef` is absent, for backwards compatibility.
37
+ * Publicly accessible URL used as the asset-manager thumbnail
38
+ * (`<img src={url}>`). Its filename extension (if any) is also used, as a
39
+ * fallback after {@link fileRef}, to determine the extension appended to
40
+ * `ref` for the generated `<image source="...">` attribute. The URL itself
41
+ * (e.g. a UUID-based storage key) is never written into the document.
40
42
  */
41
43
  url?: string;
42
44
  /**
43
- * The exact string emitted as the `source` attribute of the generated
44
- * `<image>` element for a file-backed asset typically a bare external
45
- * filename like `"euler-painting.png"`. The PreTeXt build server treats
46
- * `<image source="X">` as an external-asset filename and prepends
47
- * `external/` itself, so this must be a bare filename, not a URL.
45
+ * The server-assigned storage filename for a file-backed asset (e.g. a
46
+ * UUID-based key). Its extension, if present, is used to build the
47
+ * `source` attribute of the generated `<image>` element as
48
+ * `"{ref}.{extension}"` the rest of this value (e.g. the UUID itself)
49
+ * is never written into the document.
48
50
  *
49
- * Only meaningful when {@link isFile} is true. When absent, the emit sites
50
- * fall back to {@link url} so existing hosts keep working unchanged.
51
+ * Only meaningful when {@link isFile} is true.
51
52
  */
52
53
  fileRef?: string;
53
54
  /** Mime type for the asset, if applicable. Used for hints only. */
@@ -76,7 +77,7 @@ export interface FeedbackSubmission {
76
77
  }
77
78
  /**
78
79
  * Represents the full content state of the editor at any point in time.
79
- * When `sourceFormat` is `"pretext"`, `pretextSource` mirrors `sourceContent`.
80
+ * When `sourceFormat` is `"pretext"`, `pretextSource` mirrors `source`.
80
81
  * When `sourceFormat` is `"latex"`, `pretextSource` holds the result of
81
82
  * converting the LaTeX source, or `pretextError` holds a description of why
82
83
  * conversion failed.
@@ -86,11 +87,11 @@ export interface FeedbackSubmission {
86
87
  */
87
88
  export interface EditorContentState {
88
89
  /** The raw source string as typed/loaded by the user. */
89
- sourceContent: string;
90
- /** The format of `sourceContent`. */
90
+ source: string;
91
+ /** The format of `source`. */
91
92
  sourceFormat: SourceFormat;
92
93
  /**
93
- * The PreTeXt XML derived from `sourceContent`.
94
+ * The PreTeXt XML derived from `source`.
94
95
  * Present when conversion succeeded (or when the source is already PreTeXt).
95
96
  */
96
97
  pretextSource?: string;
@@ -4,7 +4,7 @@ import type { SourceFormat } from "./editor";
4
4
  * section, worksheet, etc. — is a `Division`. Divisions are stored as a flat
5
5
  * pool of records on the host (Rails) side; hierarchy is expressed by
6
6
  * embedding `<plus:division ref="xml-id"/>` placeholder tags inside a parent
7
- * division's `content`.
7
+ * division's `source`.
8
8
  *
9
9
  * Type-specific aliases (`<plus:chapter ref="..."/>`, `<plus:section ref="..."/>`)
10
10
  * are accepted by the editor as equivalent to `<plus:division ref="..."/>`.
@@ -59,7 +59,7 @@ export interface Division {
59
59
  * child refs as `::section{ref="child-id"}` leaf directives, and LaTeX as
60
60
  * `\plus{section}{child-id}` macros.
61
61
  */
62
- content: string;
62
+ source: string;
63
63
  }
64
64
  /**
65
65
  * @deprecated Use `DivisionType` instead. This alias will be removed in a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pretextbook/web-editor",
3
- "version": "0.12.0",
3
+ "version": "0.14.0",
4
4
  "private": false,
5
5
  "description": "A web-based editor for PreTeXt documents, with simple preview functionality",
6
6
  "keywords": [
@@ -51,8 +51,8 @@
51
51
  "@monaco-editor/react": "^4.8.0-rc.3",
52
52
  "@pretextbook/completions": "^0.0.3",
53
53
  "@pretextbook/format": "^0.2.0",
54
- "@pretextbook/latex-pretext": "^0.0.11",
55
- "@pretextbook/remark-pretext": "^0.0.9",
54
+ "@pretextbook/latex-pretext": "^0.0.12",
55
+ "@pretextbook/remark-pretext": "^0.0.10",
56
56
  "@pretextbook/visual-editor": "^0.0.6",
57
57
  "@tailwindcss/vite": "^4.1.18",
58
58
  "constrained-editor-plugin": "^1.4.0",