@sofereditor/react 0.7.0 → 0.10.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
@@ -153,6 +153,16 @@ interface ImageCaptionRequest {
153
153
  */
154
154
  resolve: (result: ImageCaptionResult | null) => void;
155
155
  }
156
+ interface FormulaResult {
157
+ latex: string;
158
+ display: boolean;
159
+ }
160
+ interface FormulaRequest {
161
+ initialLatex: string;
162
+ initialDisplay: boolean;
163
+ /** Resolve com a fórmula, ou null no cancelamento. */
164
+ resolve: (result: FormulaResult | null) => void;
165
+ }
156
166
  interface UseEditorResult {
157
167
  doc: EditorDocument;
158
168
  history: EditorHistory;
@@ -218,6 +228,11 @@ interface UseEditorResult {
218
228
  requestImageCaption: (initialCaption?: string, initialAlign?: CaptionAlign) => Promise<ImageCaptionResult | null>;
219
229
  /** Resolver called by `<ImageCaptionDialog>` on apply/cancel. */
220
230
  resolveImageCaptionRequest: (result: ImageCaptionResult | null) => void;
231
+ formulaRequest: FormulaRequest | null;
232
+ requestFormula: (initialLatex?: string, initialDisplay?: boolean) => Promise<FormulaResult | null>;
233
+ resolveFormulaRequest: (result: FormulaResult | null) => void;
234
+ /** Renderiza o LaTeX, gera SVG + PNG e insere como embed na seleção. */
235
+ insertFormula: (latex: string, display: boolean) => Promise<void>;
221
236
  /** True iff the focus position lies inside a table cell. */
222
237
  isInTable: () => boolean;
223
238
  /** Returns `{blockIndex, row, col}` for the focus position, or null when outside a table. */
@@ -238,7 +253,14 @@ interface UseEditorResult {
238
253
  mergeRight: () => boolean;
239
254
  mergeDown: () => boolean;
240
255
  splitCell: () => boolean;
241
- setColumnWidth: (blockIndex: number, col: number, widthPx: number) => void;
256
+ /** Move a divisa `boundary` (entre a coluna `boundary` e a `boundary+1`) por `deltaPct` pontos percentuais. */
257
+ setColumnBoundary: (blockIndex: number, boundary: number, deltaPct: number, base?: number[]) => void;
258
+ /** Define a largura total da tabela como percentual da largura útil da página. */
259
+ setTableWidth: (blockIndex: number, pct: number) => void;
260
+ /** Grava a altura de UMA linha, em px. É um mínimo, não fixo. */
261
+ setRowHeight: (blockIndex: number, row: number, px: number) => void;
262
+ /** Grava o array de alturas inteiro numa única transação. */
263
+ setRowHeights: (blockIndex: number, heights: number[]) => void;
242
264
  /** Returns the table rectangle if the current selection is a multi-cell range, else null. */
243
265
  getTableRect: () => TableRect | null;
244
266
  /** True when there's a rectangular table-cell selection. */
@@ -339,6 +361,18 @@ declare function PageConfigDialog(): JSX.Element | null;
339
361
  */
340
362
  declare function ImageCaptionDialog(): JSX.Element | null;
341
363
 
364
+ /**
365
+ * Modal de fórmula. Espelha `ImageCaptionDialog` — dirigido por
366
+ * `editor.formulaRequest`.
367
+ *
368
+ * O preview usa o MESMO renderer que a inserção vai usar. Se o preview falha,
369
+ * o botão de inserir fica desabilitado: nunca inserir um embed cujo render
370
+ * falhou, senão entra no documento um <img> quebrado.
371
+ */
372
+ declare function FormulaDialog({ fontsDirectory, }: {
373
+ fontsDirectory?: string;
374
+ }): JSX.Element | null;
375
+
342
376
  /**
343
377
  * Reactive snapshot of an `EditorDocument`'s page settings. Re-renders the
344
378
  * component when `docSettings` changes (either locally via `setPageSettings`
@@ -383,14 +417,27 @@ declare function NodeView({ block, index, children, fragment, tableFragment }: N
383
417
  *
384
418
  * Keys are stable on `${blockIndex}-${runningOffset}` so React reconciliation
385
419
  * survives split/merge of runs under collaboration.
420
+ *
421
+ * `baseOffset` shifts every emitted `data-embed-offset` (and key) by a fixed
422
+ * amount. Needed when `delta` is only a SLICE of a larger model range — e.g.
423
+ * one line of a célula-lista, where each `<li>` gets its own line-local delta
424
+ * but `data-embed-offset` must stay in CELL coordinates (contract with
425
+ * `Editor.tsx`'s embed-selection and `ImageResizeOverlay`'s DOM query).
426
+ * Defaults to 0, which reproduces the old line-local numbering exactly.
386
427
  */
387
- declare function renderInline(delta: DeltaOp[], keyPrefix: number | string): ReactNode;
428
+ declare function renderInline(delta: DeltaOp[], keyPrefix: number | string, baseOffset?: number): ReactNode;
388
429
 
389
430
  interface EditorProviderProps {
390
431
  editor: UseEditorResult;
391
432
  children: ReactNode;
433
+ /**
434
+ * De onde servir as 20 fontes .woff2 do MathLive (296 KB). Sem elas o
435
+ * campo desenha com fonte do sistema — feio e SILENCIOSO. O caminho muda
436
+ * por app por causa do base path, então é o app que sabe.
437
+ */
438
+ mathliveFontsDirectory?: string;
392
439
  }
393
- declare function EditorProvider({ editor, children }: EditorProviderProps): JSX.Element;
440
+ declare function EditorProvider({ editor, children, mathliveFontsDirectory, }: EditorProviderProps): JSX.Element;
394
441
  declare function useEditorContext(): UseEditorResult;
395
442
 
396
443
  interface ToolbarProps {
@@ -472,10 +519,11 @@ declare function applyDomSelection(root: HTMLElement, modelSel: Selection): void
472
519
  * com o marcador (número/símbolo) como texto literal dentro de um span
473
520
  * `mso-list:Ignore`. `parseWordListLevel` + a exclusão desse span tratam isso.
474
521
  *
475
- * fontFamily é deliberadamente NUNCA emitida: a escola padroniza Arial e cada
476
- * documento tem sua própria tipografia (mesma decisão de `import-docx`, que
477
- * descarta `w:rFonts`). fontSize É preservado (ver `parseFontSizePt`): o
478
- * modelo já suporta a mark, a barra já tem controle de tamanho, e descartar o
522
+ * fontFamily é deliberadamente NUNCA emitida: a escola padroniza uma fonte só,
523
+ * definida no CSS (`.ed-root`) e cada documento tem sua própria tipografia
524
+ * (mesma decisão de `import-docx`, que descarta `w:rFonts`). fontSize É
525
+ * preservado (ver `parseFontSizePt`): o modelo já suporta a mark, a barra já
526
+ * tem controle de tamanho, e descartar o
479
527
  * tamanho perdia informação real (título de 37.5pt colado do Google Docs saía
480
528
  * do tamanho do corpo). Unidades que dependem do contexto de herança do
481
529
  * documento de origem (em/rem/%/larger/smaller/medium) não são resolvíveis
@@ -483,4 +531,4 @@ declare function applyDomSelection(root: HTMLElement, modelSel: Selection): void
483
531
  */
484
532
  declare function htmlToSlice(html: string): ClipboardSlice | null;
485
533
 
486
- export { A4_PAGE, type BlockFragment, type CaptionAlign, Editor, type EditorProps, EditorProvider, type EditorProviderProps, ImageCaptionDialog, type ImageCaptionRequest, type ImageCaptionResult, LinkDialog, type LinkRequest, NodeView, type NodeViewFragment, PageConfigDialog, type PageConfigRequest, type PageEntry, type PageGeometry, type PageLayout, type PageLayoutResult, type PageRenderContext, type PageRenderProp, type PageSlot, type PaginationPhase, type PendingMarks, RemoteCursorsOverlay, type TableRowFragment, Toolbar, type ToolbarProps, type UseEditorOptions, type UseEditorResult, applyDomSelection, contentHeight, contentWidth, defaultPageLayout, deltaLength, findBlockIndex, getBlockElement, getCellElement, getFragmentForOffset, htmlToSlice, isTableRectSelection, locatePoint, readDomSelection, renderInline, selectionsEqual, sliceDelta, textOffsetWithin, useEditor, useEditorContext, usePageLayout, usePageSettings };
534
+ export { A4_PAGE, type BlockFragment, type CaptionAlign, Editor, type EditorProps, EditorProvider, type EditorProviderProps, FormulaDialog, ImageCaptionDialog, type ImageCaptionRequest, type ImageCaptionResult, LinkDialog, type LinkRequest, NodeView, type NodeViewFragment, PageConfigDialog, type PageConfigRequest, type PageEntry, type PageGeometry, type PageLayout, type PageLayoutResult, type PageRenderContext, type PageRenderProp, type PageSlot, type PaginationPhase, type PendingMarks, RemoteCursorsOverlay, type TableRowFragment, Toolbar, type ToolbarProps, type UseEditorOptions, type UseEditorResult, applyDomSelection, contentHeight, contentWidth, defaultPageLayout, deltaLength, findBlockIndex, getBlockElement, getCellElement, getFragmentForOffset, htmlToSlice, isTableRectSelection, locatePoint, readDomSelection, renderInline, selectionsEqual, sliceDelta, textOffsetWithin, useEditor, useEditorContext, usePageLayout, usePageSettings };
package/dist/index.d.ts CHANGED
@@ -153,6 +153,16 @@ interface ImageCaptionRequest {
153
153
  */
154
154
  resolve: (result: ImageCaptionResult | null) => void;
155
155
  }
156
+ interface FormulaResult {
157
+ latex: string;
158
+ display: boolean;
159
+ }
160
+ interface FormulaRequest {
161
+ initialLatex: string;
162
+ initialDisplay: boolean;
163
+ /** Resolve com a fórmula, ou null no cancelamento. */
164
+ resolve: (result: FormulaResult | null) => void;
165
+ }
156
166
  interface UseEditorResult {
157
167
  doc: EditorDocument;
158
168
  history: EditorHistory;
@@ -218,6 +228,11 @@ interface UseEditorResult {
218
228
  requestImageCaption: (initialCaption?: string, initialAlign?: CaptionAlign) => Promise<ImageCaptionResult | null>;
219
229
  /** Resolver called by `<ImageCaptionDialog>` on apply/cancel. */
220
230
  resolveImageCaptionRequest: (result: ImageCaptionResult | null) => void;
231
+ formulaRequest: FormulaRequest | null;
232
+ requestFormula: (initialLatex?: string, initialDisplay?: boolean) => Promise<FormulaResult | null>;
233
+ resolveFormulaRequest: (result: FormulaResult | null) => void;
234
+ /** Renderiza o LaTeX, gera SVG + PNG e insere como embed na seleção. */
235
+ insertFormula: (latex: string, display: boolean) => Promise<void>;
221
236
  /** True iff the focus position lies inside a table cell. */
222
237
  isInTable: () => boolean;
223
238
  /** Returns `{blockIndex, row, col}` for the focus position, or null when outside a table. */
@@ -238,7 +253,14 @@ interface UseEditorResult {
238
253
  mergeRight: () => boolean;
239
254
  mergeDown: () => boolean;
240
255
  splitCell: () => boolean;
241
- setColumnWidth: (blockIndex: number, col: number, widthPx: number) => void;
256
+ /** Move a divisa `boundary` (entre a coluna `boundary` e a `boundary+1`) por `deltaPct` pontos percentuais. */
257
+ setColumnBoundary: (blockIndex: number, boundary: number, deltaPct: number, base?: number[]) => void;
258
+ /** Define a largura total da tabela como percentual da largura útil da página. */
259
+ setTableWidth: (blockIndex: number, pct: number) => void;
260
+ /** Grava a altura de UMA linha, em px. É um mínimo, não fixo. */
261
+ setRowHeight: (blockIndex: number, row: number, px: number) => void;
262
+ /** Grava o array de alturas inteiro numa única transação. */
263
+ setRowHeights: (blockIndex: number, heights: number[]) => void;
242
264
  /** Returns the table rectangle if the current selection is a multi-cell range, else null. */
243
265
  getTableRect: () => TableRect | null;
244
266
  /** True when there's a rectangular table-cell selection. */
@@ -339,6 +361,18 @@ declare function PageConfigDialog(): JSX.Element | null;
339
361
  */
340
362
  declare function ImageCaptionDialog(): JSX.Element | null;
341
363
 
364
+ /**
365
+ * Modal de fórmula. Espelha `ImageCaptionDialog` — dirigido por
366
+ * `editor.formulaRequest`.
367
+ *
368
+ * O preview usa o MESMO renderer que a inserção vai usar. Se o preview falha,
369
+ * o botão de inserir fica desabilitado: nunca inserir um embed cujo render
370
+ * falhou, senão entra no documento um <img> quebrado.
371
+ */
372
+ declare function FormulaDialog({ fontsDirectory, }: {
373
+ fontsDirectory?: string;
374
+ }): JSX.Element | null;
375
+
342
376
  /**
343
377
  * Reactive snapshot of an `EditorDocument`'s page settings. Re-renders the
344
378
  * component when `docSettings` changes (either locally via `setPageSettings`
@@ -383,14 +417,27 @@ declare function NodeView({ block, index, children, fragment, tableFragment }: N
383
417
  *
384
418
  * Keys are stable on `${blockIndex}-${runningOffset}` so React reconciliation
385
419
  * survives split/merge of runs under collaboration.
420
+ *
421
+ * `baseOffset` shifts every emitted `data-embed-offset` (and key) by a fixed
422
+ * amount. Needed when `delta` is only a SLICE of a larger model range — e.g.
423
+ * one line of a célula-lista, where each `<li>` gets its own line-local delta
424
+ * but `data-embed-offset` must stay in CELL coordinates (contract with
425
+ * `Editor.tsx`'s embed-selection and `ImageResizeOverlay`'s DOM query).
426
+ * Defaults to 0, which reproduces the old line-local numbering exactly.
386
427
  */
387
- declare function renderInline(delta: DeltaOp[], keyPrefix: number | string): ReactNode;
428
+ declare function renderInline(delta: DeltaOp[], keyPrefix: number | string, baseOffset?: number): ReactNode;
388
429
 
389
430
  interface EditorProviderProps {
390
431
  editor: UseEditorResult;
391
432
  children: ReactNode;
433
+ /**
434
+ * De onde servir as 20 fontes .woff2 do MathLive (296 KB). Sem elas o
435
+ * campo desenha com fonte do sistema — feio e SILENCIOSO. O caminho muda
436
+ * por app por causa do base path, então é o app que sabe.
437
+ */
438
+ mathliveFontsDirectory?: string;
392
439
  }
393
- declare function EditorProvider({ editor, children }: EditorProviderProps): JSX.Element;
440
+ declare function EditorProvider({ editor, children, mathliveFontsDirectory, }: EditorProviderProps): JSX.Element;
394
441
  declare function useEditorContext(): UseEditorResult;
395
442
 
396
443
  interface ToolbarProps {
@@ -472,10 +519,11 @@ declare function applyDomSelection(root: HTMLElement, modelSel: Selection): void
472
519
  * com o marcador (número/símbolo) como texto literal dentro de um span
473
520
  * `mso-list:Ignore`. `parseWordListLevel` + a exclusão desse span tratam isso.
474
521
  *
475
- * fontFamily é deliberadamente NUNCA emitida: a escola padroniza Arial e cada
476
- * documento tem sua própria tipografia (mesma decisão de `import-docx`, que
477
- * descarta `w:rFonts`). fontSize É preservado (ver `parseFontSizePt`): o
478
- * modelo já suporta a mark, a barra já tem controle de tamanho, e descartar o
522
+ * fontFamily é deliberadamente NUNCA emitida: a escola padroniza uma fonte só,
523
+ * definida no CSS (`.ed-root`) e cada documento tem sua própria tipografia
524
+ * (mesma decisão de `import-docx`, que descarta `w:rFonts`). fontSize É
525
+ * preservado (ver `parseFontSizePt`): o modelo já suporta a mark, a barra já
526
+ * tem controle de tamanho, e descartar o
479
527
  * tamanho perdia informação real (título de 37.5pt colado do Google Docs saía
480
528
  * do tamanho do corpo). Unidades que dependem do contexto de herança do
481
529
  * documento de origem (em/rem/%/larger/smaller/medium) não são resolvíveis
@@ -483,4 +531,4 @@ declare function applyDomSelection(root: HTMLElement, modelSel: Selection): void
483
531
  */
484
532
  declare function htmlToSlice(html: string): ClipboardSlice | null;
485
533
 
486
- export { A4_PAGE, type BlockFragment, type CaptionAlign, Editor, type EditorProps, EditorProvider, type EditorProviderProps, ImageCaptionDialog, type ImageCaptionRequest, type ImageCaptionResult, LinkDialog, type LinkRequest, NodeView, type NodeViewFragment, PageConfigDialog, type PageConfigRequest, type PageEntry, type PageGeometry, type PageLayout, type PageLayoutResult, type PageRenderContext, type PageRenderProp, type PageSlot, type PaginationPhase, type PendingMarks, RemoteCursorsOverlay, type TableRowFragment, Toolbar, type ToolbarProps, type UseEditorOptions, type UseEditorResult, applyDomSelection, contentHeight, contentWidth, defaultPageLayout, deltaLength, findBlockIndex, getBlockElement, getCellElement, getFragmentForOffset, htmlToSlice, isTableRectSelection, locatePoint, readDomSelection, renderInline, selectionsEqual, sliceDelta, textOffsetWithin, useEditor, useEditorContext, usePageLayout, usePageSettings };
534
+ export { A4_PAGE, type BlockFragment, type CaptionAlign, Editor, type EditorProps, EditorProvider, type EditorProviderProps, FormulaDialog, ImageCaptionDialog, type ImageCaptionRequest, type ImageCaptionResult, LinkDialog, type LinkRequest, NodeView, type NodeViewFragment, PageConfigDialog, type PageConfigRequest, type PageEntry, type PageGeometry, type PageLayout, type PageLayoutResult, type PageRenderContext, type PageRenderProp, type PageSlot, type PaginationPhase, type PendingMarks, RemoteCursorsOverlay, type TableRowFragment, Toolbar, type ToolbarProps, type UseEditorOptions, type UseEditorResult, applyDomSelection, contentHeight, contentWidth, defaultPageLayout, deltaLength, findBlockIndex, getBlockElement, getCellElement, getFragmentForOffset, htmlToSlice, isTableRectSelection, locatePoint, readDomSelection, renderInline, selectionsEqual, sliceDelta, textOffsetWithin, useEditor, useEditorContext, usePageLayout, usePageSettings };