@sofereditor/react 0.5.0 → 0.7.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
@@ -1,5 +1,5 @@
1
1
  import { RefObject, JSX, ReactNode } from 'react';
2
- import { EditorDocument, EditorHistory, SerializedDocument, Selection, MarkName, MarkAttrs, BlockType, BlockAttrs, AlignValue, TableBorderPreset, ListKind, PageSettings, TableLocation, AnswerLineSpacing, TableRect, ImageEmbed, EmbedLoc, SerializedBlock, DeltaOp, Position } from '@sofereditor/core';
2
+ import { EditorDocument, EditorHistory, SerializedDocument, Selection, MarkName, MarkAttrs, BlockType, BlockAttrs, AlignValue, TableBorderPreset, ListKind, PageSettings, TableLocation, AnswerLineSpacing, TableRect, ImageEmbed, EmbedLoc, SerializedBlock, DeltaOp, Position, ClipboardSlice } from '@sofereditor/core';
3
3
 
4
4
  /**
5
5
  * Subconjunto mínimo da Awareness do y-protocols que o overlay usa. Tipar assim
@@ -264,6 +264,15 @@ interface UseEditorResult {
264
264
  cellIndex?: number;
265
265
  embed: ImageEmbed;
266
266
  } | null;
267
+ /**
268
+ * Passthrough of `UseEditorOptions.uploadImage` — `undefined` when not
269
+ * configured. Exposed so callers with the editor instance but not the
270
+ * original options (the `<Editor>` component's paste handler, notably) can
271
+ * upload an image without going through `insertImageFromFile` (which also
272
+ * inserts it — not always what's wanted, e.g. resolving `data:` embeds
273
+ * already inside a pasted slice before `insertSlice`).
274
+ */
275
+ uploadImage?: (file: File) => Promise<string>;
267
276
  }
268
277
  declare function useEditor(opts?: UseEditorOptions): UseEditorResult;
269
278
 
@@ -440,4 +449,38 @@ declare function selectionsEqual(a: Selection, b: Selection): boolean;
440
449
  declare function isTableRectSelection(sel: Selection): boolean;
441
450
  declare function applyDomSelection(root: HTMLElement, modelSel: Selection): void;
442
451
 
443
- 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, isTableRectSelection, locatePoint, readDomSelection, renderInline, selectionsEqual, sliceDelta, textOffsetWithin, useEditor, useEditorContext, usePageLayout, usePageSettings };
452
+ /**
453
+ * Converte o HTML do clipboard (Word / Google Docs / navegador) num
454
+ * `ClipboardSlice` que o editor já sabe inserir via `insertSlice`.
455
+ *
456
+ * Sempre bloco-inteiro: `openStart`/`openEnd` são `false` e `blockLevel` é
457
+ * `true` — o conteúdo colado de fora não é um fragmento de um dos blocos do
458
+ * editor, é uma sequência de blocos novos. `blockLevel: true` é o que diz a
459
+ * `insertSlice` (em `@sofereditor/core`) para adotar type/attrs do bloco
460
+ * colado em vez de tratá-lo como fragmento de seleção — ver o comentário em
461
+ * `ClipboardSlice.blockLevel`.
462
+ *
463
+ * Retorna `null` quando não sobra nada aproveitável, para o chamador (`Editor.tsx`)
464
+ * cair no ramo de texto puro em vez de engolir a colagem.
465
+ *
466
+ * Duas armadilhas reais que este módulo trata explicitamente (ver testes):
467
+ * - Google Docs embrulha o documento inteiro num `<b style="font-weight:normal"
468
+ * id="docs-internal-guid-...">` — uma tag inline por fora de blocos inteiros.
469
+ * `hasBlockDescendant` detecta isso e trata o wrapper como transparente
470
+ * (propaga as marcas resolvidas, mas não achata os blocos internos).
471
+ * - Word não usa `<ul>/<ol>/<li>` — usa `<p style="mso-list:l0 level1 ...">`
472
+ * com o marcador (número/símbolo) como texto literal dentro de um span
473
+ * `mso-list:Ignore`. `parseWordListLevel` + a exclusão desse span tratam isso.
474
+ *
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
479
+ * tamanho perdia informação real (título de 37.5pt colado do Google Docs saía
480
+ * do tamanho do corpo). Unidades que dependem do contexto de herança do
481
+ * documento de origem (em/rem/%/larger/smaller/medium) não são resolvíveis
482
+ * aqui e por isso não emitem marca — sem tamanho é melhor que tamanho errado.
483
+ */
484
+ declare function htmlToSlice(html: string): ClipboardSlice | null;
485
+
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 };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { RefObject, JSX, ReactNode } from 'react';
2
- import { EditorDocument, EditorHistory, SerializedDocument, Selection, MarkName, MarkAttrs, BlockType, BlockAttrs, AlignValue, TableBorderPreset, ListKind, PageSettings, TableLocation, AnswerLineSpacing, TableRect, ImageEmbed, EmbedLoc, SerializedBlock, DeltaOp, Position } from '@sofereditor/core';
2
+ import { EditorDocument, EditorHistory, SerializedDocument, Selection, MarkName, MarkAttrs, BlockType, BlockAttrs, AlignValue, TableBorderPreset, ListKind, PageSettings, TableLocation, AnswerLineSpacing, TableRect, ImageEmbed, EmbedLoc, SerializedBlock, DeltaOp, Position, ClipboardSlice } from '@sofereditor/core';
3
3
 
4
4
  /**
5
5
  * Subconjunto mínimo da Awareness do y-protocols que o overlay usa. Tipar assim
@@ -264,6 +264,15 @@ interface UseEditorResult {
264
264
  cellIndex?: number;
265
265
  embed: ImageEmbed;
266
266
  } | null;
267
+ /**
268
+ * Passthrough of `UseEditorOptions.uploadImage` — `undefined` when not
269
+ * configured. Exposed so callers with the editor instance but not the
270
+ * original options (the `<Editor>` component's paste handler, notably) can
271
+ * upload an image without going through `insertImageFromFile` (which also
272
+ * inserts it — not always what's wanted, e.g. resolving `data:` embeds
273
+ * already inside a pasted slice before `insertSlice`).
274
+ */
275
+ uploadImage?: (file: File) => Promise<string>;
267
276
  }
268
277
  declare function useEditor(opts?: UseEditorOptions): UseEditorResult;
269
278
 
@@ -440,4 +449,38 @@ declare function selectionsEqual(a: Selection, b: Selection): boolean;
440
449
  declare function isTableRectSelection(sel: Selection): boolean;
441
450
  declare function applyDomSelection(root: HTMLElement, modelSel: Selection): void;
442
451
 
443
- 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, isTableRectSelection, locatePoint, readDomSelection, renderInline, selectionsEqual, sliceDelta, textOffsetWithin, useEditor, useEditorContext, usePageLayout, usePageSettings };
452
+ /**
453
+ * Converte o HTML do clipboard (Word / Google Docs / navegador) num
454
+ * `ClipboardSlice` que o editor já sabe inserir via `insertSlice`.
455
+ *
456
+ * Sempre bloco-inteiro: `openStart`/`openEnd` são `false` e `blockLevel` é
457
+ * `true` — o conteúdo colado de fora não é um fragmento de um dos blocos do
458
+ * editor, é uma sequência de blocos novos. `blockLevel: true` é o que diz a
459
+ * `insertSlice` (em `@sofereditor/core`) para adotar type/attrs do bloco
460
+ * colado em vez de tratá-lo como fragmento de seleção — ver o comentário em
461
+ * `ClipboardSlice.blockLevel`.
462
+ *
463
+ * Retorna `null` quando não sobra nada aproveitável, para o chamador (`Editor.tsx`)
464
+ * cair no ramo de texto puro em vez de engolir a colagem.
465
+ *
466
+ * Duas armadilhas reais que este módulo trata explicitamente (ver testes):
467
+ * - Google Docs embrulha o documento inteiro num `<b style="font-weight:normal"
468
+ * id="docs-internal-guid-...">` — uma tag inline por fora de blocos inteiros.
469
+ * `hasBlockDescendant` detecta isso e trata o wrapper como transparente
470
+ * (propaga as marcas resolvidas, mas não achata os blocos internos).
471
+ * - Word não usa `<ul>/<ol>/<li>` — usa `<p style="mso-list:l0 level1 ...">`
472
+ * com o marcador (número/símbolo) como texto literal dentro de um span
473
+ * `mso-list:Ignore`. `parseWordListLevel` + a exclusão desse span tratam isso.
474
+ *
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
479
+ * tamanho perdia informação real (título de 37.5pt colado do Google Docs saía
480
+ * do tamanho do corpo). Unidades que dependem do contexto de herança do
481
+ * documento de origem (em/rem/%/larger/smaller/medium) não são resolvíveis
482
+ * aqui e por isso não emitem marca — sem tamanho é melhor que tamanho errado.
483
+ */
484
+ declare function htmlToSlice(html: string): ClipboardSlice | null;
485
+
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 };