@sofereditor/core 0.6.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.cjs +20 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -648,6 +648,22 @@ declare function insertText(ctx: CommandContext, text: string, marks?: Partial<R
|
|
|
648
648
|
declare function insertParagraph(ctx: CommandContext): void;
|
|
649
649
|
declare function deleteBackward(ctx: CommandContext): void;
|
|
650
650
|
declare function deleteForward(ctx: CommandContext): void;
|
|
651
|
+
/**
|
|
652
|
+
* `true` quando o caractere imediatamente ANTES (`"backward"`) ou DEPOIS
|
|
653
|
+
* (`"forward"`) da posição atual do caret é um embed de imagem. Só considera
|
|
654
|
+
* seleção COLAPSADA — o caso de um embed inteiro SELECIONADO (range de 1
|
|
655
|
+
* caractere) é responsabilidade de `getSelectedEmbed` no chamador.
|
|
656
|
+
*
|
|
657
|
+
* Existe para `Editor.tsx` decidir se Backspace/Delete precisam ser tratados
|
|
658
|
+
* no `onKeyDown` em vez de esperar `beforeinput`: o `<figure>` de um embed é
|
|
659
|
+
* `contenteditable=false`, e quando a seleção do DOM pousa nele (o que
|
|
660
|
+
* acontece depois de inserir ou clicar numa imagem) o navegador NUNCA
|
|
661
|
+
* dispara `beforeinput` — o caminho normal de delete fica mudo. Resolvido
|
|
662
|
+
* consultando o MODELO em vez de inspecionar a seleção do DOM (que pode
|
|
663
|
+
* pousar de formas diferentes por navegador): determinístico e testável sem
|
|
664
|
+
* montar um editor real.
|
|
665
|
+
*/
|
|
666
|
+
declare function isEmbedAdjacentToCaret(ctx: CommandContext, direction: "backward" | "forward"): boolean;
|
|
651
667
|
/**
|
|
652
668
|
* Toggle a mark across the current selection.
|
|
653
669
|
* - If the selection is collapsed: no-op (the UI layer handles pendingMarks).
|
|
@@ -916,4 +932,4 @@ declare class EditorHistory {
|
|
|
916
932
|
destroy(): void;
|
|
917
933
|
}
|
|
918
934
|
|
|
919
|
-
export { ANSWER_LINE_COLOR, ANSWER_LINE_MAX, type AlignValue, type AnswerLineSpacing, BLANK_MIN_RUN, BLANK_STYLE, BLOCK_SPECS, type BlockAttrs, type BlockType, CLEAR_ALL_MARKS, COMMAND_ORIGIN, type CellAttrs, type CellBorderColors, type CellBorderPos, type ClipboardSlice, type CommandContext, type CommentAttr, DEFAULT_PAGE_SETTINGS, type DeltaOp, type DirValue, EditorDocument, EditorHistory, type EmbedLoc, type EncodedCursor, type EncodedCursorPoint, 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, SOFER_MIME, type Selection, type SerializedBlock, type SerializedCell, type SerializedDocument, type StyleRecord, TABLE_BORDER_COLOR, TABLE_GUIDE_COLOR, TRACKED_ORIGINS, type TableBorderPreset, type TableLocation, type TableRect, answerLineStyle, cellBorderColors, cellBorderStyle, cellsInRect, clearRectCells, collapsedSelection, comparePositions, createBlock, createCell, createTableBlock, decodeSelection, dedentList, defaultAttrsFor, deleteBackward, deleteForward, deleteSelection, deleteTable, deleteTableColumn, deleteTableRow, deltaLength, detectPreset, encodeSelection, expandTableRect, getBlockId, getMarksInRange, indentList, insertAnswerLines, insertImage, insertParagraph, insertSlice, insertTable, insertTableColumn, insertTableRow, insertText, isCollapsed, isCommandOrigin, isImageEmbed, isKnownBlockType, isLegacySerializedDocument, isMarkUniformInRange, mergeDown, mergeRight, mergeSelection, mmToPx, moveEmbedAnchor, moveToNextCell, moveToPrevCell, newBlockId, orderedRange, positionsEqual, pxToMm, removeMark, sameTextRun, serializeSelection, setBlockAttr, setBlockAttrAtIndex, setBlockType, setCellAttr, setColumnWidth, setImageAttrs, setMark, sliceDelta, sliceToInlineDelta, sliceToText, spanOf, splitCell, splitListItem, splitUnderscoreRuns, styleToCssText, tableLocationOf, tableRectSelection, toggleList, toggleMark, withDefaults };
|
|
935
|
+
export { ANSWER_LINE_COLOR, ANSWER_LINE_MAX, type AlignValue, type AnswerLineSpacing, BLANK_MIN_RUN, BLANK_STYLE, BLOCK_SPECS, type BlockAttrs, type BlockType, CLEAR_ALL_MARKS, COMMAND_ORIGIN, type CellAttrs, type CellBorderColors, type CellBorderPos, type ClipboardSlice, type CommandContext, type CommentAttr, DEFAULT_PAGE_SETTINGS, type DeltaOp, type DirValue, EditorDocument, EditorHistory, type EmbedLoc, type EncodedCursor, type EncodedCursorPoint, 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, SOFER_MIME, type Selection, type SerializedBlock, type SerializedCell, type SerializedDocument, type StyleRecord, TABLE_BORDER_COLOR, TABLE_GUIDE_COLOR, TRACKED_ORIGINS, type TableBorderPreset, type TableLocation, type TableRect, answerLineStyle, cellBorderColors, cellBorderStyle, cellsInRect, clearRectCells, collapsedSelection, comparePositions, createBlock, createCell, createTableBlock, decodeSelection, dedentList, defaultAttrsFor, deleteBackward, deleteForward, deleteSelection, deleteTable, deleteTableColumn, deleteTableRow, deltaLength, detectPreset, encodeSelection, expandTableRect, getBlockId, getMarksInRange, indentList, insertAnswerLines, insertImage, insertParagraph, insertSlice, insertTable, insertTableColumn, insertTableRow, insertText, isCollapsed, isCommandOrigin, isEmbedAdjacentToCaret, isImageEmbed, isKnownBlockType, isLegacySerializedDocument, isMarkUniformInRange, mergeDown, mergeRight, mergeSelection, mmToPx, moveEmbedAnchor, moveToNextCell, moveToPrevCell, newBlockId, orderedRange, positionsEqual, pxToMm, removeMark, sameTextRun, serializeSelection, setBlockAttr, setBlockAttrAtIndex, setBlockType, setCellAttr, setColumnWidth, setImageAttrs, setMark, sliceDelta, sliceToInlineDelta, sliceToText, spanOf, splitCell, splitListItem, splitUnderscoreRuns, styleToCssText, tableLocationOf, tableRectSelection, toggleList, toggleMark, withDefaults };
|
package/dist/index.d.ts
CHANGED
|
@@ -648,6 +648,22 @@ declare function insertText(ctx: CommandContext, text: string, marks?: Partial<R
|
|
|
648
648
|
declare function insertParagraph(ctx: CommandContext): void;
|
|
649
649
|
declare function deleteBackward(ctx: CommandContext): void;
|
|
650
650
|
declare function deleteForward(ctx: CommandContext): void;
|
|
651
|
+
/**
|
|
652
|
+
* `true` quando o caractere imediatamente ANTES (`"backward"`) ou DEPOIS
|
|
653
|
+
* (`"forward"`) da posição atual do caret é um embed de imagem. Só considera
|
|
654
|
+
* seleção COLAPSADA — o caso de um embed inteiro SELECIONADO (range de 1
|
|
655
|
+
* caractere) é responsabilidade de `getSelectedEmbed` no chamador.
|
|
656
|
+
*
|
|
657
|
+
* Existe para `Editor.tsx` decidir se Backspace/Delete precisam ser tratados
|
|
658
|
+
* no `onKeyDown` em vez de esperar `beforeinput`: o `<figure>` de um embed é
|
|
659
|
+
* `contenteditable=false`, e quando a seleção do DOM pousa nele (o que
|
|
660
|
+
* acontece depois de inserir ou clicar numa imagem) o navegador NUNCA
|
|
661
|
+
* dispara `beforeinput` — o caminho normal de delete fica mudo. Resolvido
|
|
662
|
+
* consultando o MODELO em vez de inspecionar a seleção do DOM (que pode
|
|
663
|
+
* pousar de formas diferentes por navegador): determinístico e testável sem
|
|
664
|
+
* montar um editor real.
|
|
665
|
+
*/
|
|
666
|
+
declare function isEmbedAdjacentToCaret(ctx: CommandContext, direction: "backward" | "forward"): boolean;
|
|
651
667
|
/**
|
|
652
668
|
* Toggle a mark across the current selection.
|
|
653
669
|
* - If the selection is collapsed: no-op (the UI layer handles pendingMarks).
|
|
@@ -916,4 +932,4 @@ declare class EditorHistory {
|
|
|
916
932
|
destroy(): void;
|
|
917
933
|
}
|
|
918
934
|
|
|
919
|
-
export { ANSWER_LINE_COLOR, ANSWER_LINE_MAX, type AlignValue, type AnswerLineSpacing, BLANK_MIN_RUN, BLANK_STYLE, BLOCK_SPECS, type BlockAttrs, type BlockType, CLEAR_ALL_MARKS, COMMAND_ORIGIN, type CellAttrs, type CellBorderColors, type CellBorderPos, type ClipboardSlice, type CommandContext, type CommentAttr, DEFAULT_PAGE_SETTINGS, type DeltaOp, type DirValue, EditorDocument, EditorHistory, type EmbedLoc, type EncodedCursor, type EncodedCursorPoint, 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, SOFER_MIME, type Selection, type SerializedBlock, type SerializedCell, type SerializedDocument, type StyleRecord, TABLE_BORDER_COLOR, TABLE_GUIDE_COLOR, TRACKED_ORIGINS, type TableBorderPreset, type TableLocation, type TableRect, answerLineStyle, cellBorderColors, cellBorderStyle, cellsInRect, clearRectCells, collapsedSelection, comparePositions, createBlock, createCell, createTableBlock, decodeSelection, dedentList, defaultAttrsFor, deleteBackward, deleteForward, deleteSelection, deleteTable, deleteTableColumn, deleteTableRow, deltaLength, detectPreset, encodeSelection, expandTableRect, getBlockId, getMarksInRange, indentList, insertAnswerLines, insertImage, insertParagraph, insertSlice, insertTable, insertTableColumn, insertTableRow, insertText, isCollapsed, isCommandOrigin, isImageEmbed, isKnownBlockType, isLegacySerializedDocument, isMarkUniformInRange, mergeDown, mergeRight, mergeSelection, mmToPx, moveEmbedAnchor, moveToNextCell, moveToPrevCell, newBlockId, orderedRange, positionsEqual, pxToMm, removeMark, sameTextRun, serializeSelection, setBlockAttr, setBlockAttrAtIndex, setBlockType, setCellAttr, setColumnWidth, setImageAttrs, setMark, sliceDelta, sliceToInlineDelta, sliceToText, spanOf, splitCell, splitListItem, splitUnderscoreRuns, styleToCssText, tableLocationOf, tableRectSelection, toggleList, toggleMark, withDefaults };
|
|
935
|
+
export { ANSWER_LINE_COLOR, ANSWER_LINE_MAX, type AlignValue, type AnswerLineSpacing, BLANK_MIN_RUN, BLANK_STYLE, BLOCK_SPECS, type BlockAttrs, type BlockType, CLEAR_ALL_MARKS, COMMAND_ORIGIN, type CellAttrs, type CellBorderColors, type CellBorderPos, type ClipboardSlice, type CommandContext, type CommentAttr, DEFAULT_PAGE_SETTINGS, type DeltaOp, type DirValue, EditorDocument, EditorHistory, type EmbedLoc, type EncodedCursor, type EncodedCursorPoint, 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, SOFER_MIME, type Selection, type SerializedBlock, type SerializedCell, type SerializedDocument, type StyleRecord, TABLE_BORDER_COLOR, TABLE_GUIDE_COLOR, TRACKED_ORIGINS, type TableBorderPreset, type TableLocation, type TableRect, answerLineStyle, cellBorderColors, cellBorderStyle, cellsInRect, clearRectCells, collapsedSelection, comparePositions, createBlock, createCell, createTableBlock, decodeSelection, dedentList, defaultAttrsFor, deleteBackward, deleteForward, deleteSelection, deleteTable, deleteTableColumn, deleteTableRow, deltaLength, detectPreset, encodeSelection, expandTableRect, getBlockId, getMarksInRange, indentList, insertAnswerLines, insertImage, insertParagraph, insertSlice, insertTable, insertTableColumn, insertTableRow, insertText, isCollapsed, isCommandOrigin, isEmbedAdjacentToCaret, isImageEmbed, isKnownBlockType, isLegacySerializedDocument, isMarkUniformInRange, mergeDown, mergeRight, mergeSelection, mmToPx, moveEmbedAnchor, moveToNextCell, moveToPrevCell, newBlockId, orderedRange, positionsEqual, pxToMm, removeMark, sameTextRun, serializeSelection, setBlockAttr, setBlockAttrAtIndex, setBlockType, setCellAttr, setColumnWidth, setImageAttrs, setMark, sliceDelta, sliceToInlineDelta, sliceToText, spanOf, splitCell, splitListItem, splitUnderscoreRuns, styleToCssText, tableLocationOf, tableRectSelection, toggleList, toggleMark, withDefaults };
|
package/dist/index.js
CHANGED
|
@@ -1044,6 +1044,24 @@ function deleteForward(ctx) {
|
|
|
1044
1044
|
}
|
|
1045
1045
|
});
|
|
1046
1046
|
}
|
|
1047
|
+
function isEmbedAdjacentToCaret(ctx, direction) {
|
|
1048
|
+
const sel = ctx.getSelection();
|
|
1049
|
+
if (!isCollapsed(sel)) return false;
|
|
1050
|
+
const pos = sel.focus;
|
|
1051
|
+
const yText = ctx.doc.textAt(pos.blockIndex, pos.cellIndex);
|
|
1052
|
+
if (!yText) return false;
|
|
1053
|
+
const delta = yText.toDelta();
|
|
1054
|
+
let cursor = 0;
|
|
1055
|
+
for (const op of delta) {
|
|
1056
|
+
const len = typeof op.insert === "string" ? op.insert.length : 1;
|
|
1057
|
+
const opStart = cursor;
|
|
1058
|
+
const opEnd = cursor + len;
|
|
1059
|
+
cursor = opEnd;
|
|
1060
|
+
const matches = direction === "backward" ? opEnd === pos.offset : opStart === pos.offset;
|
|
1061
|
+
if (matches) return isImageEmbed(op.insert);
|
|
1062
|
+
}
|
|
1063
|
+
return false;
|
|
1064
|
+
}
|
|
1047
1065
|
var booleanMarks = /* @__PURE__ */ new Set(["bold", "italic", "underline", "strike"]);
|
|
1048
1066
|
function toggleMark(ctx, name, value) {
|
|
1049
1067
|
const sel = ctx.getSelection();
|
|
@@ -2249,6 +2267,7 @@ export {
|
|
|
2249
2267
|
insertText,
|
|
2250
2268
|
isCollapsed,
|
|
2251
2269
|
isCommandOrigin,
|
|
2270
|
+
isEmbedAdjacentToCaret,
|
|
2252
2271
|
isImageEmbed,
|
|
2253
2272
|
isKnownBlockType,
|
|
2254
2273
|
isLegacySerializedDocument,
|