@inshapardaz/likhari-react 0.1.21-dev.203 → 0.1.21-dev.205
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/autocorrect/AutoCorrectPlugin.d.ts.map +1 -1
- package/dist/autocorrect/AutoCorrectPlugin.js +5 -3
- package/dist/autocorrect/autoCorrectActions.d.ts +6 -0
- package/dist/autocorrect/autoCorrectActions.d.ts.map +1 -1
- package/dist/autocorrect/autoCorrectActions.js +26 -1
- package/dist/components/Toolbar.d.ts.map +1 -1
- package/dist/components/Toolbar.js +3 -3
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoCorrectPlugin.d.ts","sourceRoot":"","sources":["../../src/autocorrect/AutoCorrectPlugin.tsx"],"names":[],"mappings":"AAEA,OAAO,EAA4E,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"AutoCorrectPlugin.d.ts","sourceRoot":"","sources":["../../src/autocorrect/AutoCorrectPlugin.tsx"],"names":[],"mappings":"AAEA,OAAO,EAA4E,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAQxH,OAAO,EAA0B,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACrF,OAAO,EAAuB,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAiB,KAAK,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAG9F,sFAAsF;AACtF,kFAAkF;AAClF,eAAO,MAAM,wBAAwB,EAAE,cAAc,CAAC,IAAI,CAA6C,CAAC;AAMxG;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,MAAM,EACN,OAAO,EACP,OAAO,EACP,iBAAiB,EACjB,WAAW,GACZ,EAAE;IACD,MAAM,EAAE,gBAAgB,EAAE,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,mFAAmF;IACnF,iBAAiB,CAAC,EAAE,wBAAwB,CAAC;IAC7C,kEAAkE;IAClE,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC,QA0FA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
2
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
3
|
import { $getSelection, $isRangeSelection, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
|
|
4
|
-
import { $correctDocument, $correctPunctuationBeforeCaret, $correctPunctuationDocument, $correctWordBeforeCaret } from './autoCorrectActions.js';
|
|
4
|
+
import { $correctDocument, $correctPunctuationBeforeCaret, $correctPunctuationDocument, $correctWordBeforeCaret, $preservingSelection, } from './autoCorrectActions.js';
|
|
5
5
|
import { activePunctuationRules } from './punctuationRules.js';
|
|
6
6
|
import { loadAutoCorrections } from './autoCorrectStores.js';
|
|
7
7
|
import { normalizeUrdu } from '../normalization/urduNormalize.js';
|
|
@@ -54,8 +54,10 @@ export function AutoCorrectPlugin({ stores, version, enabled, urduNormalization,
|
|
|
54
54
|
return;
|
|
55
55
|
return editor.registerCommand(CORRECT_DOCUMENT_COMMAND, () => {
|
|
56
56
|
editor.update(() => {
|
|
57
|
-
$
|
|
58
|
-
|
|
57
|
+
$preservingSelection(() => {
|
|
58
|
+
$correctPunctuationDocument(punctuationRules.current);
|
|
59
|
+
$correctDocument(tables.current.get('en') ?? new Map(), rtlTable.current, normalizeRtl);
|
|
60
|
+
});
|
|
59
61
|
}, { discrete: true });
|
|
60
62
|
return true;
|
|
61
63
|
}, COMMAND_PRIORITY_EDITOR);
|
|
@@ -24,4 +24,10 @@ export declare function $correctPunctuationBeforeCaret(rules: PunctuationRule[])
|
|
|
24
24
|
* Where two matches overlap, the longer one wins. Returns how many were applied.
|
|
25
25
|
*/
|
|
26
26
|
export declare function $correctPunctuationDocument(rules: PunctuationRule[]): number;
|
|
27
|
+
/**
|
|
28
|
+
* Runs `change` and then puts the caret back where it was. Replacements move the
|
|
29
|
+
* selection onto each match they make, so a whole-document pass would otherwise
|
|
30
|
+
* leave the caret at the last match, or at the end of the document.
|
|
31
|
+
*/
|
|
32
|
+
export declare function $preservingSelection(change: () => void): void;
|
|
27
33
|
//# sourceMappingURL=autoCorrectActions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autoCorrectActions.d.ts","sourceRoot":"","sources":["../../src/autocorrect/autoCorrectActions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"autoCorrectActions.d.ts","sourceRoot":"","sources":["../../src/autocorrect/autoCorrectActions.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAM1D;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAiCjH;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACxB,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACxB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GACtC,MAAM,CA8BR;AAQD;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,eAAe,EAAE,GAAG,OAAO,CAqBhF;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,eAAe,EAAE,GAAG,MAAM,CA2B5E;AAID;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,IAAI,GAAG,IAAI,CAoB7D"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $getRoot, $getSelection, $isRangeSelection, $isTextNode } from 'lexical';
|
|
1
|
+
import { $createRangeSelection, $getNodeByKey, $getRoot, $getSelection, $isRangeSelection, $isTextNode, $setSelection, } from 'lexical';
|
|
2
2
|
import { $locate, $replaceMatch, $textGroups } from '../find/findReplaceActions.js';
|
|
3
3
|
import { wordsIn } from '../spellcheck/spellDictionaries.js';
|
|
4
4
|
/** The part of a word that counts as word characters at its end. */
|
|
@@ -141,3 +141,28 @@ export function $correctPunctuationDocument(rules) {
|
|
|
141
141
|
}
|
|
142
142
|
return applied;
|
|
143
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Runs `change` and then puts the caret back where it was. Replacements move the
|
|
146
|
+
* selection onto each match they make, so a whole-document pass would otherwise
|
|
147
|
+
* leave the caret at the last match, or at the end of the document.
|
|
148
|
+
*/
|
|
149
|
+
export function $preservingSelection(change) {
|
|
150
|
+
const before = $getSelection();
|
|
151
|
+
const saved = $isRangeSelection(before)
|
|
152
|
+
? {
|
|
153
|
+
anchor: { key: before.anchor.key, offset: before.anchor.offset, type: before.anchor.type },
|
|
154
|
+
focus: { key: before.focus.key, offset: before.focus.offset, type: before.focus.type },
|
|
155
|
+
}
|
|
156
|
+
: null;
|
|
157
|
+
change();
|
|
158
|
+
if (!saved) {
|
|
159
|
+
$setSelection(null);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (!$getNodeByKey(saved.anchor.key) || !$getNodeByKey(saved.focus.key))
|
|
163
|
+
return;
|
|
164
|
+
const selection = $createRangeSelection();
|
|
165
|
+
selection.anchor.set(saved.anchor.key, saved.anchor.offset, saved.anchor.type);
|
|
166
|
+
selection.focus.set(saved.focus.key, saved.focus.offset, saved.focus.type);
|
|
167
|
+
$setSelection(selection);
|
|
168
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toolbar.d.ts","sourceRoot":"","sources":["../../src/components/Toolbar.tsx"],"names":[],"mappings":"AAsFA,OAAO,EAAgB,KAAK,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEzE,OAAO,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,OAAO,EAAE,QAAQ,EAAE,QAAgB,EAAE,YAAY,EAAE,SAAiB,EAAE,aAAa,EAAE,eAAuB,EAAE,mBAAmB,EAAE,WAAkC,EAAE,SAAiB,EAAE,MAAa,EAAE,MAAM,EAAE,EAAE,YAAY,+BAglCxQ"}
|
|
@@ -30,7 +30,7 @@ import { CANVAS_FONT_DEFAULTS, DEFAULT_FONT_OPTIONS, FONT_SIZES_PX } from '../fo
|
|
|
30
30
|
import { setStyleProperty } from '../utils/style.js';
|
|
31
31
|
import { useStrings } from '../i18n/useStrings.js';
|
|
32
32
|
import { usePortalTarget } from '../PortalTargetContext.js';
|
|
33
|
-
import { IconAbc, IconAlignCenter, IconAlignJustified, IconAlignLeft, IconAlignRight, IconArrowBackUp, IconArrowForwardUp, IconBold, IconClearFormatting, IconDeviceFloppy, IconDots, IconHistory, IconExternalLink, IconFeather, IconH1, IconH2, IconH3, IconH4, IconH5, IconH6, IconIndentDecrease, IconIndentIncrease, IconItalic, IconLetterCase, IconLetterCaseLower, IconLetterCaseUpper, IconLink, IconLinkOff, IconList, IconListCheck, IconListNumbers, IconPageBreak, IconPencil, IconPhoto, IconPilcrow, IconQuote, IconSeparatorHorizontal, IconSparkles, IconStrikethrough, IconSubscript, IconSuperscript, IconArrowMergeBoth, IconArrowsSplit2, IconColumnInsertLeft, IconColumnInsertRight, IconColumnRemove, IconColumns,
|
|
33
|
+
import { IconAbc, IconAlignCenter, IconAlignJustified, IconAlignLeft, IconAlignRight, IconArrowBackUp, IconArrowForwardUp, IconBold, IconClearFormatting, IconDeviceFloppy, IconDots, IconHistory, IconExternalLink, IconFeather, IconH1, IconH2, IconH3, IconH4, IconH5, IconH6, IconIndentDecrease, IconIndentIncrease, IconItalic, IconLetterCase, IconLetterCaseLower, IconLetterCaseUpper, IconLink, IconLinkOff, IconList, IconListCheck, IconListNumbers, IconPageBreak, IconPencil, IconPhoto, IconPilcrow, IconQuote, IconSeparatorHorizontal, IconSparkles, IconStrikethrough, IconSubscript, IconSuperscript, IconArrowMergeBoth, IconArrowsSplit2, IconColumnInsertLeft, IconColumnInsertRight, IconColumnRemove, IconColumns, IconSearch, IconColumns1, IconColumns2, IconNumber1Small, IconRowInsertBottom, IconRowInsertTop, IconRowRemove, IconArrowsMaximize, IconArrowsMinimize, IconArrowsShuffle, IconTable, IconTableMinus, IconTrash, IconTableOptions, IconTextSize, IconTypography, IconUnderline, IconWand, } from '@tabler/icons-react';
|
|
34
34
|
/** Sentinel for "no inline style": Lexical returns the default it is given when
|
|
35
35
|
* the selection has none, so this tells "unstyled" (show the canvas default)
|
|
36
36
|
* apart from "styled with a value the dropdown doesn't list" (show nothing). */
|
|
@@ -638,7 +638,7 @@ export function Toolbar({ config, onSave, isDirty, showSave, findOpen = false, o
|
|
|
638
638
|
config.columns ||
|
|
639
639
|
config.footnotes ||
|
|
640
640
|
config.poetry.enabled;
|
|
641
|
-
const showLanguageGroup = config.language.autocorrect || config.language.
|
|
641
|
+
const showLanguageGroup = config.language.autocorrect || config.language.spellCheck;
|
|
642
642
|
// The "script & cleanup" and "indent/outdent" groups (UI spec §3.3) render
|
|
643
643
|
// as normal inline toolbar groups whenever there's room, and only move
|
|
644
644
|
// into the "..." overflow menu when the measured toolbar content doesn't
|
|
@@ -812,7 +812,7 @@ export function Toolbar({ config, onSave, isDirty, showSave, findOpen = false, o
|
|
|
812
812
|
showStubInsertGroup && (_jsxs("div", { className: "likhari-toolbar-group likhari-toolbar-group--collapse-tablet", children: [(config.images.linked || config.images.embedded) && (_jsx(ToolbarButton, { icon: IconPhoto, title: strings.toolbar.insertImage, onClick: openImageDialog })), config.blocks.pageBreak && (_jsx(ToolbarButton, { icon: IconPageBreak, title: strings.toolbar.insertPageBreak, onClick: () => editor.dispatchCommand(INSERT_PAGE_BREAK_COMMAND, undefined) })), config.tables && _jsx(ToolbarButton, { icon: IconTable, title: strings.toolbar.insertTable, onClick: openTableDialog }), config.columns && _jsx(ToolbarButton, { icon: IconColumns, title: strings.toolbar.insertColumns, onClick: openLayoutDialog }), config.footnotes && (_jsx(ToolbarButton, { icon: IconNumber1Small, title: strings.toolbar.insertFootnote, onClick: () => editor.dispatchCommand(INSERT_FOOTNOTE_COMMAND, undefined) })), config.blocks.horizontalRule && (_jsx(ToolbarButton, { icon: IconSeparatorHorizontal, title: strings.toolbar.insertHorizontalRule, onClick: () => editor.dispatchCommand(INSERT_HORIZONTAL_RULE_COMMAND, undefined) })), config.findReplace && (_jsx(ToolbarButton, { icon: IconSearch, title: strings.findReplace.toggle, active: findOpen, onClick: onToggleFind })), config.poetry.enabled && locale !== 'en' && (_jsx(ToolbarButton, { icon: IconFeather, title: strings.toolbar.insertPoetryCouplet, onClick: () => editor.dispatchCommand(INSERT_POETRY_COUPLET_COMMAND, { layout: config.poetry.defaultLayout }) }))] }, "stubInsert")),
|
|
813
813
|
config.tables && state.inTable && (_jsx("div", { className: "likhari-toolbar-group", children: _jsxs(Menu, { position: "bottom-start", withinPortal: true, portalProps: { target: portalTarget }, shadow: "sm", width: 240, onOpen: snapshotSelection, children: [_jsx(Menu.Target, { children: _jsx("button", { type: "button", className: "likhari-toolbar-button", "data-active": "true", "aria-pressed": "true", "aria-haspopup": "menu", "aria-label": strings.toolbar.tableOptions, title: strings.toolbar.tableOptions, onMouseDown: (e) => e.preventDefault(), children: _jsx(IconTableOptions, { size: ICON_SIZE, stroke: ICON_STROKE }) }) }), _jsx(Menu.Dropdown, { children: _jsx(TableMenuItems, { strings: strings, direction: direction, rows: state.tableRows, columns: state.tableColumns, canMergeCells: state.canMergeCells, canUnmergeCell: state.canUnmergeCell, onAction: runMenuAction }) })] }) }, "tableActions")),
|
|
814
814
|
config.poetry.enabled && state.inPoetry && (_jsx("div", { className: "likhari-toolbar-group", children: _jsxs(Menu, { position: "bottom-start", withinPortal: true, portalProps: { target: portalTarget }, shadow: "sm", width: 200, onOpen: snapshotSelection, children: [_jsx(Menu.Target, { children: _jsx("button", { type: "button", className: "likhari-toolbar-button", "data-active": "true", "aria-pressed": "true", "aria-haspopup": "menu", "aria-label": strings.toolbar.poetryOptions, title: strings.toolbar.poetryOptions, onMouseDown: (e) => e.preventDefault(), children: _jsx(IconFeather, { size: ICON_SIZE, stroke: ICON_STROKE }) }) }), _jsx(Menu.Dropdown, { children: _jsx(PoetryMenuItems, { strings: strings, layout: state.poetryLayout, scale: state.poetryScale, centered: state.poetryCentered, onAction: runMenuAction }) })] }) }, "poetryActions")),
|
|
815
|
-
showLanguageGroup && (_jsxs("div", { className: "likhari-toolbar-group likhari-toolbar-group--collapse-tablet", children: [config.language.autocorrect && (_jsx(ToolbarButton, { icon: IconWand, title: strings.toolbar.autocorrect, active: autoCorrectOpen, onClick: onToggleAutoCorrect })), config.language.autocorrect && (_jsx(ToolbarButton, { icon:
|
|
815
|
+
showLanguageGroup && (_jsxs("div", { className: "likhari-toolbar-group likhari-toolbar-group--collapse-tablet", children: [config.language.autocorrect && (_jsx(ToolbarButton, { icon: IconWand, title: strings.toolbar.autocorrect, active: autoCorrectOpen, onClick: onToggleAutoCorrect })), config.language.autocorrect && (_jsx(ToolbarButton, { icon: IconSparkles, title: strings.autoCorrect.correctDocument, onClick: () => editor.dispatchCommand(CORRECT_DOCUMENT_COMMAND, undefined) })), config.language.spellCheck && (_jsx(ToolbarButton, { icon: IconAbc, title: strings.toolbar.spellChecker, active: spellOpen, onClick: onToggleSpell }))] }, "language")),
|
|
816
816
|
];
|
|
817
817
|
return (_jsxs("div", { className: "likhari-toolbar", role: "toolbar", "aria-label": strings.toolbar.ariaLabel, ref: toolbarContainerRef, children: [fixedGroups, movableGroups
|
|
818
818
|
.filter((group) => !overflowGroupKeys.has(group.key))
|