@sofereditor/core 0.1.0 → 0.2.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.
package/dist/index.d.cts CHANGED
@@ -25,6 +25,27 @@ interface PageSettings {
25
25
  * This is purely a UI hint — it's recomputed from width/height when needed.
26
26
  */
27
27
  preset?: PagePreset;
28
+ /**
29
+ * Free-form title persisted on the document for a consumer-rendered
30
+ * "system header" (e.g. a non-editable letterhead/identification block
31
+ * drawn on page 1 via `renderPageHeader`). Stored in `docSettings` so it
32
+ * survives serialization and is visible to every client/consumer of the
33
+ * `SerializedDocument`, including headless exports.
34
+ *
35
+ * The renderer is application-defined — this field just transports the
36
+ * title string. Use it when the header content is part of the document
37
+ * (and therefore must round-trip through exports), not a UI chrome
38
+ * decoration.
39
+ */
40
+ systemHeaderTitle?: string;
41
+ /**
42
+ * Owner/author display name for the same consumer-rendered system
43
+ * header (see [[systemHeaderTitle]]). Useful when the header should
44
+ * show the document's CREATOR, not the current viewer (e.g. an author
45
+ * name on a doc viewed by a third party). Persisted in `docSettings`
46
+ * for consistent rendering across clients and headless renderers.
47
+ */
48
+ systemHeaderAuthor?: string;
28
49
  }
29
50
  /** Page sizes in CSS px @ 96dpi. */
30
51
  declare const PAGE_PRESETS: {
@@ -67,6 +88,7 @@ type BlockType = "paragraph" | "heading" | "blockquote" | "codeBlock" | "listIte
67
88
  type AlignValue = "left" | "center" | "right" | "justify";
68
89
  type DirValue = "ltr" | "rtl";
69
90
  type ListKind = "bullet" | "ordered";
91
+ type ListStyleType = "decimal" | "lower-alpha" | "upper-alpha" | "lower-roman" | "upper-roman";
70
92
  /** Maximum supported list nesting (0 = top level). */
71
93
  declare const MAX_LIST_LEVEL = 5;
72
94
  interface BlockAttrs {
@@ -80,6 +102,20 @@ interface BlockAttrs {
80
102
  listKind?: ListKind;
81
103
  /** Only meaningful when `type === "listItem"`. 0..MAX_LIST_LEVEL. */
82
104
  listLevel?: number;
105
+ /**
106
+ * Only meaningful when `type === "listItem"` and `listKind === "ordered"`.
107
+ * When set on a listItem, that item starts a NEW list group whose first
108
+ * `<ol>` carries `start={listStart}`. Used to renumerate questions or pick
109
+ * up an interrupted sequence.
110
+ */
111
+ listStart?: number;
112
+ /**
113
+ * Only meaningful when `type === "listItem"`. Overrides the default per-level
114
+ * CSS cycle (decimal → lower-alpha → lower-roman) with an explicit style.
115
+ * Like `listStart`, setting this on a listItem breaks the group so the new
116
+ * `<ol>` carries the requested `list-style-type`.
117
+ */
118
+ listStyle?: ListStyleType;
83
119
  /** Only meaningful when `type === "table"`. */
84
120
  rows?: number;
85
121
  /** Only meaningful when `type === "table"`. */
@@ -598,4 +634,4 @@ declare class EditorHistory {
598
634
  destroy(): void;
599
635
  }
600
636
 
601
- export { type AlignValue, BLOCK_SPECS, type BlockAttrs, type BlockType, COMMAND_ORIGIN, type CellAttrs, type CommandContext, type CommentAttr, DEFAULT_PAGE_SETTINGS, type DeltaOp, type DirValue, EditorDocument, EditorHistory, type ImageEmbed, type ImageLayout, type InsertContent, type LegacySerializedDocument, type LinkAttr, type ListKind, MARGIN_PRESETS, MAX_LIST_LEVEL, type MarkAttrs, type MarkName, type MarkValue, PAGE_PRESETS, type PagePreset, type PageSettings, type Position, type Selection, type SerializedBlock, type SerializedCell, type SerializedDocument, TRACKED_ORIGINS, type TableLocation, type TableRect, cellsInRect, clearRectCells, collapsedSelection, comparePositions, createBlock, createCell, createTableBlock, dedentList, defaultAttrsFor, deleteBackward, deleteForward, deleteTable, deleteTableColumn, deleteTableRow, deltaLength, detectPreset, expandTableRect, getMarksInRange, indentList, insertImage, insertParagraph, insertTable, insertTableColumn, insertTableRow, insertText, isCollapsed, isCommandOrigin, isImageEmbed, isKnownBlockType, isLegacySerializedDocument, isMarkUniformInRange, mergeDown, mergeRight, mergeSelection, mmToPx, moveToNextCell, moveToPrevCell, orderedRange, positionsEqual, pxToMm, removeMark, sameTextRun, setBlockAttr, setBlockType, setColumnWidth, setImageAttrs, setMark, sliceDelta, spanOf, splitCell, splitListItem, tableLocationOf, tableRectSelection, toggleList, toggleMark, withDefaults };
637
+ export { type AlignValue, BLOCK_SPECS, type BlockAttrs, type BlockType, COMMAND_ORIGIN, type CellAttrs, type CommandContext, type CommentAttr, DEFAULT_PAGE_SETTINGS, type DeltaOp, type DirValue, EditorDocument, EditorHistory, type ImageEmbed, type ImageLayout, type InsertContent, type LegacySerializedDocument, type LinkAttr, type ListKind, type ListStyleType, MARGIN_PRESETS, MAX_LIST_LEVEL, type MarkAttrs, type MarkName, type MarkValue, PAGE_PRESETS, type PagePreset, type PageSettings, type Position, type Selection, type SerializedBlock, type SerializedCell, type SerializedDocument, TRACKED_ORIGINS, type TableLocation, type TableRect, cellsInRect, clearRectCells, collapsedSelection, comparePositions, createBlock, createCell, createTableBlock, dedentList, defaultAttrsFor, deleteBackward, deleteForward, deleteTable, deleteTableColumn, deleteTableRow, deltaLength, detectPreset, expandTableRect, getMarksInRange, indentList, insertImage, insertParagraph, insertTable, insertTableColumn, insertTableRow, insertText, isCollapsed, isCommandOrigin, isImageEmbed, isKnownBlockType, isLegacySerializedDocument, isMarkUniformInRange, mergeDown, mergeRight, mergeSelection, mmToPx, moveToNextCell, moveToPrevCell, orderedRange, positionsEqual, pxToMm, removeMark, sameTextRun, setBlockAttr, setBlockType, setColumnWidth, setImageAttrs, setMark, sliceDelta, spanOf, splitCell, splitListItem, tableLocationOf, tableRectSelection, toggleList, toggleMark, withDefaults };
package/dist/index.d.ts CHANGED
@@ -25,6 +25,27 @@ interface PageSettings {
25
25
  * This is purely a UI hint — it's recomputed from width/height when needed.
26
26
  */
27
27
  preset?: PagePreset;
28
+ /**
29
+ * Free-form title persisted on the document for a consumer-rendered
30
+ * "system header" (e.g. a non-editable letterhead/identification block
31
+ * drawn on page 1 via `renderPageHeader`). Stored in `docSettings` so it
32
+ * survives serialization and is visible to every client/consumer of the
33
+ * `SerializedDocument`, including headless exports.
34
+ *
35
+ * The renderer is application-defined — this field just transports the
36
+ * title string. Use it when the header content is part of the document
37
+ * (and therefore must round-trip through exports), not a UI chrome
38
+ * decoration.
39
+ */
40
+ systemHeaderTitle?: string;
41
+ /**
42
+ * Owner/author display name for the same consumer-rendered system
43
+ * header (see [[systemHeaderTitle]]). Useful when the header should
44
+ * show the document's CREATOR, not the current viewer (e.g. an author
45
+ * name on a doc viewed by a third party). Persisted in `docSettings`
46
+ * for consistent rendering across clients and headless renderers.
47
+ */
48
+ systemHeaderAuthor?: string;
28
49
  }
29
50
  /** Page sizes in CSS px @ 96dpi. */
30
51
  declare const PAGE_PRESETS: {
@@ -67,6 +88,7 @@ type BlockType = "paragraph" | "heading" | "blockquote" | "codeBlock" | "listIte
67
88
  type AlignValue = "left" | "center" | "right" | "justify";
68
89
  type DirValue = "ltr" | "rtl";
69
90
  type ListKind = "bullet" | "ordered";
91
+ type ListStyleType = "decimal" | "lower-alpha" | "upper-alpha" | "lower-roman" | "upper-roman";
70
92
  /** Maximum supported list nesting (0 = top level). */
71
93
  declare const MAX_LIST_LEVEL = 5;
72
94
  interface BlockAttrs {
@@ -80,6 +102,20 @@ interface BlockAttrs {
80
102
  listKind?: ListKind;
81
103
  /** Only meaningful when `type === "listItem"`. 0..MAX_LIST_LEVEL. */
82
104
  listLevel?: number;
105
+ /**
106
+ * Only meaningful when `type === "listItem"` and `listKind === "ordered"`.
107
+ * When set on a listItem, that item starts a NEW list group whose first
108
+ * `<ol>` carries `start={listStart}`. Used to renumerate questions or pick
109
+ * up an interrupted sequence.
110
+ */
111
+ listStart?: number;
112
+ /**
113
+ * Only meaningful when `type === "listItem"`. Overrides the default per-level
114
+ * CSS cycle (decimal → lower-alpha → lower-roman) with an explicit style.
115
+ * Like `listStart`, setting this on a listItem breaks the group so the new
116
+ * `<ol>` carries the requested `list-style-type`.
117
+ */
118
+ listStyle?: ListStyleType;
83
119
  /** Only meaningful when `type === "table"`. */
84
120
  rows?: number;
85
121
  /** Only meaningful when `type === "table"`. */
@@ -598,4 +634,4 @@ declare class EditorHistory {
598
634
  destroy(): void;
599
635
  }
600
636
 
601
- export { type AlignValue, BLOCK_SPECS, type BlockAttrs, type BlockType, COMMAND_ORIGIN, type CellAttrs, type CommandContext, type CommentAttr, DEFAULT_PAGE_SETTINGS, type DeltaOp, type DirValue, EditorDocument, EditorHistory, type ImageEmbed, type ImageLayout, type InsertContent, type LegacySerializedDocument, type LinkAttr, type ListKind, MARGIN_PRESETS, MAX_LIST_LEVEL, type MarkAttrs, type MarkName, type MarkValue, PAGE_PRESETS, type PagePreset, type PageSettings, type Position, type Selection, type SerializedBlock, type SerializedCell, type SerializedDocument, TRACKED_ORIGINS, type TableLocation, type TableRect, cellsInRect, clearRectCells, collapsedSelection, comparePositions, createBlock, createCell, createTableBlock, dedentList, defaultAttrsFor, deleteBackward, deleteForward, deleteTable, deleteTableColumn, deleteTableRow, deltaLength, detectPreset, expandTableRect, getMarksInRange, indentList, insertImage, insertParagraph, insertTable, insertTableColumn, insertTableRow, insertText, isCollapsed, isCommandOrigin, isImageEmbed, isKnownBlockType, isLegacySerializedDocument, isMarkUniformInRange, mergeDown, mergeRight, mergeSelection, mmToPx, moveToNextCell, moveToPrevCell, orderedRange, positionsEqual, pxToMm, removeMark, sameTextRun, setBlockAttr, setBlockType, setColumnWidth, setImageAttrs, setMark, sliceDelta, spanOf, splitCell, splitListItem, tableLocationOf, tableRectSelection, toggleList, toggleMark, withDefaults };
637
+ export { type AlignValue, BLOCK_SPECS, type BlockAttrs, type BlockType, COMMAND_ORIGIN, type CellAttrs, type CommandContext, type CommentAttr, DEFAULT_PAGE_SETTINGS, type DeltaOp, type DirValue, EditorDocument, EditorHistory, type ImageEmbed, type ImageLayout, type InsertContent, type LegacySerializedDocument, type LinkAttr, type ListKind, type ListStyleType, MARGIN_PRESETS, MAX_LIST_LEVEL, type MarkAttrs, type MarkName, type MarkValue, PAGE_PRESETS, type PagePreset, type PageSettings, type Position, type Selection, type SerializedBlock, type SerializedCell, type SerializedDocument, TRACKED_ORIGINS, type TableLocation, type TableRect, cellsInRect, clearRectCells, collapsedSelection, comparePositions, createBlock, createCell, createTableBlock, dedentList, defaultAttrsFor, deleteBackward, deleteForward, deleteTable, deleteTableColumn, deleteTableRow, deltaLength, detectPreset, expandTableRect, getMarksInRange, indentList, insertImage, insertParagraph, insertTable, insertTableColumn, insertTableRow, insertText, isCollapsed, isCommandOrigin, isImageEmbed, isKnownBlockType, isLegacySerializedDocument, isMarkUniformInRange, mergeDown, mergeRight, mergeSelection, mmToPx, moveToNextCell, moveToPrevCell, orderedRange, positionsEqual, pxToMm, removeMark, sameTextRun, setBlockAttr, setBlockType, setColumnWidth, setImageAttrs, setMark, sliceDelta, spanOf, splitCell, splitListItem, tableLocationOf, tableRectSelection, toggleList, toggleMark, withDefaults };
package/dist/index.js CHANGED
@@ -121,7 +121,9 @@ var EditorDocument = class _EditorDocument {
121
121
  marginTop: pick("marginTop") ?? DEFAULT_PAGE_SETTINGS.marginTop,
122
122
  marginBottom: pick("marginBottom") ?? DEFAULT_PAGE_SETTINGS.marginBottom,
123
123
  marginLeft: pick("marginLeft") ?? DEFAULT_PAGE_SETTINGS.marginLeft,
124
- marginRight: pick("marginRight") ?? DEFAULT_PAGE_SETTINGS.marginRight
124
+ marginRight: pick("marginRight") ?? DEFAULT_PAGE_SETTINGS.marginRight,
125
+ systemHeaderTitle: pick("systemHeaderTitle"),
126
+ systemHeaderAuthor: pick("systemHeaderAuthor")
125
127
  };
126
128
  merged.preset = detectPreset(merged.width, merged.height);
127
129
  return merged;
@@ -257,6 +259,17 @@ var EditorDocument = class _EditorDocument {
257
259
  */
258
260
  loadFromJSON(serialized) {
259
261
  const { blocks: sourceBlocks, pageSettings } = normalizeSerialized(serialized);
262
+ const LOCK_KEY = "__importLock";
263
+ const LOCK_TTL_MS = 5e3;
264
+ const existing = this.docSettings.get(LOCK_KEY);
265
+ if (typeof existing === "number" && Date.now() - existing < LOCK_TTL_MS) {
266
+ const ageMs = Date.now() - existing;
267
+ console.warn(
268
+ `[EditorDocument.loadFromJSON] import j\xE1 em andamento (${ageMs}ms atr\xE1s, TTL ${LOCK_TTL_MS}ms) \u2014 ignorando esta chamada para evitar duplica\xE7\xE3o de blocks.`
269
+ );
270
+ return;
271
+ }
272
+ this.docSettings.set(LOCK_KEY, Date.now());
260
273
  this.ydoc.transact(() => {
261
274
  if (this.blocks.length > 0) {
262
275
  this.blocks.delete(0, this.blocks.length);
@@ -276,6 +289,7 @@ var EditorDocument = class _EditorDocument {
276
289
  this.docSettings.set(k, v);
277
290
  }
278
291
  }
292
+ this.docSettings.delete(LOCK_KEY);
279
293
  }, "import");
280
294
  }
281
295
  /** Build a fresh `EditorDocument` from a `SerializedDocument`. */