@sofereditor/react 0.6.0 → 0.9.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.cjs +1507 -570
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +52 -3
- package/dist/index.d.ts +52 -3
- package/dist/index.js +1398 -464
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
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
|
-
|
|
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. */
|
|
@@ -264,6 +286,15 @@ interface UseEditorResult {
|
|
|
264
286
|
cellIndex?: number;
|
|
265
287
|
embed: ImageEmbed;
|
|
266
288
|
} | null;
|
|
289
|
+
/**
|
|
290
|
+
* Passthrough of `UseEditorOptions.uploadImage` — `undefined` when not
|
|
291
|
+
* configured. Exposed so callers with the editor instance but not the
|
|
292
|
+
* original options (the `<Editor>` component's paste handler, notably) can
|
|
293
|
+
* upload an image without going through `insertImageFromFile` (which also
|
|
294
|
+
* inserts it — not always what's wanted, e.g. resolving `data:` embeds
|
|
295
|
+
* already inside a pasted slice before `insertSlice`).
|
|
296
|
+
*/
|
|
297
|
+
uploadImage?: (file: File) => Promise<string>;
|
|
267
298
|
}
|
|
268
299
|
declare function useEditor(opts?: UseEditorOptions): UseEditorResult;
|
|
269
300
|
|
|
@@ -330,6 +361,18 @@ declare function PageConfigDialog(): JSX.Element | null;
|
|
|
330
361
|
*/
|
|
331
362
|
declare function ImageCaptionDialog(): JSX.Element | null;
|
|
332
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
|
+
|
|
333
376
|
/**
|
|
334
377
|
* Reactive snapshot of an `EditorDocument`'s page settings. Re-renders the
|
|
335
378
|
* component when `docSettings` changes (either locally via `setPageSettings`
|
|
@@ -380,8 +423,14 @@ declare function renderInline(delta: DeltaOp[], keyPrefix: number | string): Rea
|
|
|
380
423
|
interface EditorProviderProps {
|
|
381
424
|
editor: UseEditorResult;
|
|
382
425
|
children: ReactNode;
|
|
426
|
+
/**
|
|
427
|
+
* De onde servir as 20 fontes .woff2 do MathLive (296 KB). Sem elas o
|
|
428
|
+
* campo desenha com fonte do sistema — feio e SILENCIOSO. O caminho muda
|
|
429
|
+
* por app por causa do base path, então é o app que sabe.
|
|
430
|
+
*/
|
|
431
|
+
mathliveFontsDirectory?: string;
|
|
383
432
|
}
|
|
384
|
-
declare function EditorProvider({ editor, children }: EditorProviderProps): JSX.Element;
|
|
433
|
+
declare function EditorProvider({ editor, children, mathliveFontsDirectory, }: EditorProviderProps): JSX.Element;
|
|
385
434
|
declare function useEditorContext(): UseEditorResult;
|
|
386
435
|
|
|
387
436
|
interface ToolbarProps {
|
|
@@ -474,4 +523,4 @@ declare function applyDomSelection(root: HTMLElement, modelSel: Selection): void
|
|
|
474
523
|
*/
|
|
475
524
|
declare function htmlToSlice(html: string): ClipboardSlice | null;
|
|
476
525
|
|
|
477
|
-
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 };
|
|
526
|
+
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
|
-
|
|
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. */
|
|
@@ -264,6 +286,15 @@ interface UseEditorResult {
|
|
|
264
286
|
cellIndex?: number;
|
|
265
287
|
embed: ImageEmbed;
|
|
266
288
|
} | null;
|
|
289
|
+
/**
|
|
290
|
+
* Passthrough of `UseEditorOptions.uploadImage` — `undefined` when not
|
|
291
|
+
* configured. Exposed so callers with the editor instance but not the
|
|
292
|
+
* original options (the `<Editor>` component's paste handler, notably) can
|
|
293
|
+
* upload an image without going through `insertImageFromFile` (which also
|
|
294
|
+
* inserts it — not always what's wanted, e.g. resolving `data:` embeds
|
|
295
|
+
* already inside a pasted slice before `insertSlice`).
|
|
296
|
+
*/
|
|
297
|
+
uploadImage?: (file: File) => Promise<string>;
|
|
267
298
|
}
|
|
268
299
|
declare function useEditor(opts?: UseEditorOptions): UseEditorResult;
|
|
269
300
|
|
|
@@ -330,6 +361,18 @@ declare function PageConfigDialog(): JSX.Element | null;
|
|
|
330
361
|
*/
|
|
331
362
|
declare function ImageCaptionDialog(): JSX.Element | null;
|
|
332
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
|
+
|
|
333
376
|
/**
|
|
334
377
|
* Reactive snapshot of an `EditorDocument`'s page settings. Re-renders the
|
|
335
378
|
* component when `docSettings` changes (either locally via `setPageSettings`
|
|
@@ -380,8 +423,14 @@ declare function renderInline(delta: DeltaOp[], keyPrefix: number | string): Rea
|
|
|
380
423
|
interface EditorProviderProps {
|
|
381
424
|
editor: UseEditorResult;
|
|
382
425
|
children: ReactNode;
|
|
426
|
+
/**
|
|
427
|
+
* De onde servir as 20 fontes .woff2 do MathLive (296 KB). Sem elas o
|
|
428
|
+
* campo desenha com fonte do sistema — feio e SILENCIOSO. O caminho muda
|
|
429
|
+
* por app por causa do base path, então é o app que sabe.
|
|
430
|
+
*/
|
|
431
|
+
mathliveFontsDirectory?: string;
|
|
383
432
|
}
|
|
384
|
-
declare function EditorProvider({ editor, children }: EditorProviderProps): JSX.Element;
|
|
433
|
+
declare function EditorProvider({ editor, children, mathliveFontsDirectory, }: EditorProviderProps): JSX.Element;
|
|
385
434
|
declare function useEditorContext(): UseEditorResult;
|
|
386
435
|
|
|
387
436
|
interface ToolbarProps {
|
|
@@ -474,4 +523,4 @@ declare function applyDomSelection(root: HTMLElement, modelSel: Selection): void
|
|
|
474
523
|
*/
|
|
475
524
|
declare function htmlToSlice(html: string): ClipboardSlice | null;
|
|
476
525
|
|
|
477
|
-
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 };
|
|
526
|
+
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 };
|