@inshapardaz/likhari-react 0.1.26-dev.242 → 0.1.26
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/EditorRoot.d.ts +0 -3
- package/dist/EditorRoot.d.ts.map +1 -1
- package/dist/EditorRoot.js +2 -5
- package/dist/components/Toolbar.d.ts +1 -4
- package/dist/components/Toolbar.d.ts.map +1 -1
- package/dist/components/Toolbar.js +6 -22
- package/dist/i18n/strings.d.ts +0 -5
- package/dist/i18n/strings.d.ts.map +1 -1
- package/dist/i18n/strings.js +0 -15
- package/package.json +1 -1
- package/dist/thesaurus/thesaurusStores.d.ts +0 -45
- package/dist/thesaurus/thesaurusStores.d.ts.map +0 -1
- package/dist/thesaurus/thesaurusStores.js +0 -131
package/dist/EditorRoot.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ import { type DraftRestoreMode } from './components/DraftRestore.js';
|
|
|
7
7
|
import { type AutoCorrectStore } from './autocorrect/autoCorrectStores.js';
|
|
8
8
|
import type { UrduNormalizationOptions } from './normalization/urduNormalize.js';
|
|
9
9
|
import type { PunctuationOptions } from './autocorrect/punctuationRules.js';
|
|
10
|
-
import { type ThesaurusStore } from './thesaurus/thesaurusStores.js';
|
|
11
10
|
import { type CompletionStore } from './autocomplete/completionStores.js';
|
|
12
11
|
import { type UserWordStore } from './spellcheck/userWords.js';
|
|
13
12
|
import type { SpellLanguage } from './spellcheck/spellDictionaries.js';
|
|
@@ -26,8 +25,6 @@ export interface EditorRootProps {
|
|
|
26
25
|
dictionaryStores?: UserWordStore[];
|
|
27
26
|
/** Where autocomplete words come from, combined per language. Defaults to the dictionaries and the user's words. Pass a stable array. */
|
|
28
27
|
completionStores?: CompletionStore[];
|
|
29
|
-
/** Where synonyms come from, merged in order. Defaults to English WordNet. Pass a stable array. */
|
|
30
|
-
thesaurusStores?: ThesaurusStore[];
|
|
31
28
|
/** The language autocomplete works in: 'auto' follows each block's direction (English for LTR, Urdu for RTL). */
|
|
32
29
|
autoCompleteLanguage?: SpellLanguage | 'auto';
|
|
33
30
|
/** Urdu normalisation applied as part of auto-correct. Diacritics are kept unless `removeDiacritics` is set. */
|
package/dist/EditorRoot.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorRoot.d.ts","sourceRoot":"","sources":["../src/EditorRoot.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAY1D,OAAO,KAAK,EAA8B,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEjF,OAAO,EAAyB,KAAK,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AACvF,OAAO,EAAwB,KAAK,mBAAmB,EAAE,KAAK,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAKzH,OAAO,EAAyB,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AAOjE,OAAO,EAAgB,KAAK,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAIhF,OAAO,EAAgC,KAAK,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACtG,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAC9E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAIzE,OAAO,
|
|
1
|
+
{"version":3,"file":"EditorRoot.d.ts","sourceRoot":"","sources":["../src/EditorRoot.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAY1D,OAAO,KAAK,EAA8B,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEjF,OAAO,EAAyB,KAAK,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AACvF,OAAO,EAAwB,KAAK,mBAAmB,EAAE,KAAK,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAKzH,OAAO,EAAyB,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AAOjE,OAAO,EAA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,MAAM,EAAE,QAAQ,GAAG,MAAM,CAAC;IACrC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,GAAG,IAAI,CAAC;IAClD,iBAAiB,IAAI,OAAO,CAAC;IAC7B,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACnC,KAAK,IAAI,IAAI,CAAC;CACf;AAQD,eAAO,MAAM,UAAU,uGAubrB,CAAC"}
|
package/dist/EditorRoot.js
CHANGED
|
@@ -33,7 +33,6 @@ import { localStorageAutoCorrectStore } from './autocorrect/autoCorrectStores.js
|
|
|
33
33
|
import { SpellcheckPanel } from './components/SpellcheckPanel.js';
|
|
34
34
|
import { SpellHighlightPlugin } from './spellcheck/SpellHighlightPlugin.js';
|
|
35
35
|
import { AutocompletePlugin } from './autocomplete/AutocompletePlugin.js';
|
|
36
|
-
import { wordNetThesaurusStore } from './thesaurus/thesaurusStores.js';
|
|
37
36
|
import { dictionaryCompletionStore } from './autocomplete/completionStores.js';
|
|
38
37
|
import { loadUserWords, localStorageUserWordStore } from './spellcheck/userWords.js';
|
|
39
38
|
import { LeaveDialog } from './components/LeaveDialog.js';
|
|
@@ -46,8 +45,6 @@ const DEFAULT_AUTOSAVE_MAX_BYTES = 2000000;
|
|
|
46
45
|
const DEFAULT_AUTOSAVE_MAX_DRAFTS = 20;
|
|
47
46
|
/** Used when the host passes no stores: corrections are kept in this browser. */
|
|
48
47
|
const DEFAULT_AUTOCORRECT_STORES = [localStorageAutoCorrectStore()];
|
|
49
|
-
/** Used when the host passes no thesaurus stores: English synonyms from WordNet, loaded on first use. */
|
|
50
|
-
const DEFAULT_THESAURUS_STORES = [wordNetThesaurusStore()];
|
|
51
48
|
/** Used when the host passes no completion stores: the dictionary's words and the user's added words. */
|
|
52
49
|
const DEFAULT_COMPLETION_STORES = [dictionaryCompletionStore()];
|
|
53
50
|
/** Used when the host passes no dictionary stores: added words are kept in this browser. */
|
|
@@ -58,7 +55,7 @@ function initialEditorStateJson(initialContent) {
|
|
|
58
55
|
const state = defaultFormatRegistry.parse(initialContent.format, initialContent.value);
|
|
59
56
|
return JSON.stringify(state);
|
|
60
57
|
}
|
|
61
|
-
export const EditorRoot = forwardRef(function EditorRoot({ documentId, autoCorrectStores, dictionaryStores, completionStores,
|
|
58
|
+
export const EditorRoot = forwardRef(function EditorRoot({ documentId, autoCorrectStores, dictionaryStores, completionStores, autoCompleteLanguage = 'auto', urduNormalization, punctuation, initialContent, featureConfig, featurePreset, theme, colorScheme, accentColor, locale = 'en', placeholder, height = '480px', onChange, onSave, showSave = Boolean(onSave), onImageUpload, fetchImage, fontOptions, autosave = true, restoreDraft = 'prompt', navigationGuard = 'confirm', onDraftRestored, autosaveDelayMs = DEFAULT_AUTOSAVE_DELAY_MS, autosaveMaxBytes = DEFAULT_AUTOSAVE_MAX_BYTES, autosaveMaxDrafts = DEFAULT_AUTOSAVE_MAX_DRAFTS, }, ref) {
|
|
62
59
|
const config = useMemo(() => resolveFeatureConfig(featureConfig, featurePreset), [featureConfig, featurePreset]);
|
|
63
60
|
const strings = useMemo(() => getStrings(locale), [locale]);
|
|
64
61
|
const resolvedPlaceholder = placeholder ?? strings.editor.placeholder;
|
|
@@ -311,7 +308,7 @@ export const EditorRoot = forwardRef(function EditorRoot({ documentId, autoCorre
|
|
|
311
308
|
// rather than colliding on a shared one.
|
|
312
309
|
const portalTargetId = useId();
|
|
313
310
|
const portalTargetSelector = `#${CSS.escape(portalTargetId)}`;
|
|
314
|
-
return (_jsx(EditorThemeProvider, { theme: theme, colorScheme: colorScheme, accentColor: accentColor, scopeElementId: portalTargetId, children: _jsxs("div", { className: "likhari-root", dir: dir, ref: rootElementRef, "data-document-id": documentId, style: { height: typeof height === 'number' ? `${height}px` : height }, children: [_jsx("div", { id: portalTargetId, className: "likhari-portal-target" }), _jsx(PortalTargetContext.Provider, { value: portalTargetSelector, children: _jsxs(UiStringsContext.Provider, { value: strings, children: [_jsx(ImageOptionsContext.Provider, { value: imageOptions, children: _jsxs(LexicalComposer, { initialConfig: initialConfig, children: [_jsx(Toolbar, { config: config, dictionaryStores: wordStores,
|
|
311
|
+
return (_jsx(EditorThemeProvider, { theme: theme, colorScheme: colorScheme, accentColor: accentColor, scopeElementId: portalTargetId, children: _jsxs("div", { className: "likhari-root", dir: dir, ref: rootElementRef, "data-document-id": documentId, style: { height: typeof height === 'number' ? `${height}px` : height }, children: [_jsx("div", { id: portalTargetId, className: "likhari-portal-target" }), _jsx(PortalTargetContext.Provider, { value: portalTargetSelector, children: _jsxs(UiStringsContext.Provider, { value: strings, children: [_jsx(ImageOptionsContext.Provider, { value: imageOptions, children: _jsxs(LexicalComposer, { initialConfig: initialConfig, children: [_jsx(Toolbar, { config: config, dictionaryStores: wordStores, onAddAutoCorrect: config.language.autocorrect ? openAutoCorrectFor : undefined, onSave: handleSave, findOpen: openPanel === 'find', onToggleFind: () => togglePanel('find'), spellOpen: openPanel === 'spell', onToggleSpell: () => togglePanel('spell'), autoCorrectOpen: openPanel === 'autocorrect', onToggleAutoCorrect: () => togglePanel('autocorrect'), isDirty: isDirty, showSave: showSave, fontOptions: fontOptions, direction: dir, locale: locale, drafts: autosave
|
|
315
312
|
? { currentId: draftId, maxBytes: autosaveMaxBytes, adoptOnRestore: !documentId, onRestored: handleDraftRestored }
|
|
316
313
|
: undefined }), documentId && (_jsx(DraftRestore, { draftId: documentId, mode: restoreDraft, initialJson: initialContentJsonRef.current, locale: locale, onRestored: handleDraftRestored })), _jsxs("div", { className: "likhari-canvas-frame", children: [config.findReplace && openPanel === 'find' && _jsx(FindReplaceBar, { strings: strings, dir: dir, onClose: () => setOpenPanel(null) }), config.language.spellCheck && openPanel === 'spell' && (_jsx(SpellcheckPanel, { strings: strings, dir: dir, dictionaryStores: wordStores, onAddAutoCorrect: config.language.autocorrect ? openAutoCorrectFor : undefined, onClose: () => setOpenPanel(null) })), config.language.autocorrect && openPanel === 'autocorrect' && (_jsx(AutoCorrectPanel, { strings: strings, dir: dir, stores: stores, initialFrom: autoCorrectPrefill?.from, initialLanguage: autoCorrectPrefill?.language, onSaved: () => setAutoCorrectVersion((v) => v + 1), onClose: () => setOpenPanel(null) }, autoCorrectPrefill?.id ?? 0)), _jsx("div", { className: "likhari-canvas", children: _jsx(RichTextPlugin, { contentEditable: _jsx(ContentEditable, { className: "likhari-content-editable", dir: dir, spellCheck: false, "aria-label": strings.editor.contentLabel }), placeholder: _jsx("div", { className: "likhari-placeholder", children: resolvedPlaceholder }), ErrorBoundary: LexicalErrorBoundary }) })] }), config.history && _jsx(HistoryPlugin, {}), (config.lists.bullet || config.lists.numbered || config.lists.check) && _jsx(ListPlugin, {}), config.lists.check && _jsx(CheckListPlugin, {}), config.links && _jsx(LinkPlugin, {}), config.links && _jsx(LinkPastePlugin, {}), config.blocks.pageBreak && _jsx(PageBreakPlugin, {}), config.language.spellCheck && _jsx(SpellHighlightPlugin, {}), config.language.autocomplete && (_jsx(AutocompletePlugin, { label: strings.autoComplete.label, stores: resolvedCompletionStores, language: autoCompleteLanguage })), (config.language.autocorrect || config.language.textCleanup) && _jsx(AutoCorrectPlugin, { stores: stores, version: autoCorrectVersion, enabled: true, typing: config.language.autocorrect, urduNormalization: urduNormalization, punctuation: punctuation }), config.columns && _jsx(LayoutPlugin, {}), config.footnotes && _jsx(FootnotePlugin, {}), config.poetry.enabled && _jsx(PoetryPlugin, {}), config.poetry.enabled && _jsx(PoetryResizer, {}), config.tables && _jsx(TablePlugin, { hasCellMerge: true, hasTabHandler: true }), config.blocks.horizontalRule && _jsx(HorizontalRulePlugin, {}), _jsx(EditorInstancePlugin, { instanceRef: editorInstanceRef }), _jsx(OnChangePlugin, { onChange: handleChange })] }) }), _jsx(LeaveDialog, { opened: leavePrompt !== null, canSave: Boolean(onSave), canSaveDraft: autosave || navigationGuard === 'save-draft', draftFailed: leavePrompt?.draftFailed ?? false, onSave: () => {
|
|
317
314
|
handleSave();
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type SpellLanguage } from '../spellcheck/spellDictionaries.js';
|
|
2
|
-
import { type ThesaurusStore } from '../thesaurus/thesaurusStores.js';
|
|
3
2
|
import { type UserWordStore } from '../spellcheck/userWords.js';
|
|
4
3
|
import { type DraftsToolbarOptions } from './DraftsDialog.js';
|
|
5
4
|
import type { ResolvedEditorFeatureConfig } from '@inshapardaz/likhari-core';
|
|
@@ -7,8 +6,6 @@ import { type FontOption } from '../fonts/index.js';
|
|
|
7
6
|
import type { Locale } from '../i18n/strings.js';
|
|
8
7
|
export interface ToolbarProps {
|
|
9
8
|
config: ResolvedEditorFeatureConfig;
|
|
10
|
-
/** Where synonyms come from. */
|
|
11
|
-
thesaurusStores?: ThesaurusStore[];
|
|
12
9
|
/** Where words added to the dictionary are saved. */
|
|
13
10
|
dictionaryStores?: UserWordStore[];
|
|
14
11
|
/** Opens the auto-correct panel with the word filled in. */
|
|
@@ -34,5 +31,5 @@ export interface ToolbarProps {
|
|
|
34
31
|
/** Autosave drafts: when set, the toolbar offers a Drafts button that lists and restores them. */
|
|
35
32
|
drafts?: DraftsToolbarOptions;
|
|
36
33
|
}
|
|
37
|
-
export declare function Toolbar({ config, dictionaryStores,
|
|
34
|
+
export declare function Toolbar({ config, dictionaryStores, onAddAutoCorrect, onSave, isDirty, showSave, findOpen, onToggleFind, spellOpen, onToggleSpell, autoCorrectOpen, onToggleAutoCorrect, fontOptions, direction, locale, drafts }: ToolbarProps): import("react").JSX.Element;
|
|
38
35
|
//# sourceMappingURL=Toolbar.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toolbar.d.ts","sourceRoot":"","sources":["../../src/components/Toolbar.tsx"],"names":[],"mappings":"AA0CA,OAAO,EAAc,KAAK,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACjF,OAAO,
|
|
1
|
+
{"version":3,"file":"Toolbar.d.ts","sourceRoot":"","sources":["../../src/components/Toolbar.tsx"],"names":[],"mappings":"AA0CA,OAAO,EAAc,KAAK,aAAa,EAAE,MAAM,iC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gB,EAAE,MAAM,EAAE,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,+BAqnCjT"}
|
|
@@ -11,7 +11,6 @@ import { $findMatchingParent, $insertNodeToNearestRoot } from '@lexical/utils';
|
|
|
11
11
|
import { CORRECT_DOCUMENT_COMMAND } from '../autocorrect/AutoCorrectPlugin.js';
|
|
12
12
|
import { $replaceMatch } from '../find/findReplaceActions.js';
|
|
13
13
|
import { getSpeller } from '../spellcheck/spellDictionaries.js';
|
|
14
|
-
import { lookupSynonyms } from '../thesaurus/thesaurusStores.js';
|
|
15
14
|
import { addUserWord, ignoreWord } from '../spellcheck/userWords.js';
|
|
16
15
|
import { $wordAtDomPoint, textPointAt } from '../spellcheck/spellingMenu.js';
|
|
17
16
|
import { INSERT_HORIZONTAL_RULE_COMMAND } from '@lexical/react/LexicalHorizontalRuleNode';
|
|
@@ -186,7 +185,7 @@ function PoetryMenuItems({ strings, layout, scale, centered, onAction, }) {
|
|
|
186
185
|
};
|
|
187
186
|
return (_jsxs(_Fragment, { children: [_jsx(Menu.Label, { children: t.menuLabel }), item(IconColumns1, t.singleColumn, setLayout('single'), layout === 'single'), item(IconColumns2, t.twoColumn, setLayout('two-column'), layout === 'two-column'), item(IconArrowsShuffle, t.staggered, setLayout('staggered'), layout === 'staggered'), _jsx(Menu.Divider, {}), _jsx(Menu.Divider, {}), item(IconRowInsertTop, t.insertCoupletBefore, () => $insertCoupletRelativeToSelection('before')), item(IconRowInsertBottom, t.insertCoupletAfter, () => $insertCoupletRelativeToSelection('after')), item(IconArrowsMinimize, t.tighterSpacing, () => $adjustPoetrySpacing(-1), !canStep(POETRY_SPACINGS, scale.spacing, -1)), item(IconArrowsMaximize, t.looserSpacing, () => $adjustPoetrySpacing(1), !canStep(POETRY_SPACINGS, scale.spacing, 1)), layout === 'staggered' && (_jsxs(_Fragment, { children: [item(IconArrowsMinimize, t.narrowerCouplets, () => $adjustPoetryStagger(-1), !canStep(POETRY_STAGGERS, scale.stagger, -1)), item(IconArrowsMaximize, t.widerCouplets, () => $adjustPoetryStagger(1), !canStep(POETRY_STAGGERS, scale.stagger, 1))] })), layout === 'two-column' && (_jsxs(_Fragment, { children: [item(IconAlignCenter, centered ? t.uncenterCouplet : t.centerCouplet, () => $setCoupletCentered(!centered)), item(IconColumns2, t.narrowerGutter, () => $adjustPoetryGutter(-1), !canStep(POETRY_GUTTERS, scale.gutter, -1)), item(IconColumns2, t.widerGutter, () => $adjustPoetryGutter(1), !canStep(POETRY_GUTTERS, scale.gutter, 1))] })), item(IconTrash, t.deleteCouplet, $deletePoetryCouplet, false, 'red'), item(IconTrash, t.deletePoetry, $deletePoetryBlock, false, 'red')] }));
|
|
188
187
|
}
|
|
189
|
-
export function Toolbar({ config, dictionaryStores = [],
|
|
188
|
+
export function Toolbar({ config, dictionaryStores = [], onAddAutoCorrect, onSave, isDirty, showSave, findOpen = false, onToggleFind, spellOpen = false, onToggleSpell, autoCorrectOpen = false, onToggleAutoCorrect, fontOptions = DEFAULT_FONT_OPTIONS, direction = 'ltr', locale = 'en', drafts }) {
|
|
190
189
|
const [editor] = useLexicalComposerContext();
|
|
191
190
|
const [state, setState] = useState(INITIAL_STATE);
|
|
192
191
|
const strings = useStrings(locale);
|
|
@@ -484,7 +483,7 @@ export function Toolbar({ config, dictionaryStores = [], thesaurusStores = [], o
|
|
|
484
483
|
const anchor = config.links ? (target?.closest?.('a') ?? null) : null;
|
|
485
484
|
const cell = config.tables ? (target?.closest?.('td, th') ?? null) : null;
|
|
486
485
|
const couplet = config.poetry.enabled ? (target?.closest?.('.likhari-poetry') ?? null) : null;
|
|
487
|
-
const point = config.language.spellCheck
|
|
486
|
+
const point = config.language.spellCheck ? textPointAt(event.clientX, event.clientY) : null;
|
|
488
487
|
const menu = { x: event.clientX, y: event.clientY };
|
|
489
488
|
let word = null;
|
|
490
489
|
editor.update(() => {
|
|
@@ -522,11 +521,8 @@ export function Toolbar({ config, dictionaryStores = [], thesaurusStores = [], o
|
|
|
522
521
|
if (point)
|
|
523
522
|
word = $wordAtDomPoint(point.node, point.offset);
|
|
524
523
|
}, { discrete: true });
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
menu.thesaurus = { language, word: word.word, match: word.match };
|
|
528
|
-
}
|
|
529
|
-
if (word && config.language.spellCheck) {
|
|
524
|
+
if (word) {
|
|
525
|
+
const language = word.direction === 'rtl' ? 'ur' : 'en';
|
|
530
526
|
const speller = getSpeller(language);
|
|
531
527
|
if (speller) {
|
|
532
528
|
const checked = await speller;
|
|
@@ -536,20 +532,12 @@ export function Toolbar({ config, dictionaryStores = [], thesaurusStores = [], o
|
|
|
536
532
|
}
|
|
537
533
|
}
|
|
538
534
|
setContextMenu(menu);
|
|
539
|
-
if (word && menu.thesaurus) {
|
|
540
|
-
// Synonyms can take a while (the first WordNet lookup downloads the database), so the menu
|
|
541
|
-
// is already open and fills in when they arrive, unless the user has moved on.
|
|
542
|
-
const items = await lookupSynonyms(thesaurusStores, word.word, language);
|
|
543
|
-
setContextMenu((current) => current && current.x === menu.x && current.y === menu.y && current.thesaurus
|
|
544
|
-
? { ...current, thesaurus: { ...current.thesaurus, items } }
|
|
545
|
-
: current);
|
|
546
|
-
}
|
|
547
535
|
};
|
|
548
536
|
return editor.registerRootListener((root, previous) => {
|
|
549
537
|
previous?.removeEventListener('contextmenu', onContextMenu);
|
|
550
538
|
root?.addEventListener('contextmenu', onContextMenu);
|
|
551
539
|
});
|
|
552
|
-
}, [editor, config.links, config.tables, config.poetry.enabled, config.language.spellCheck
|
|
540
|
+
}, [editor, config.links, config.tables, config.poetry.enabled, config.language.spellCheck]);
|
|
553
541
|
// Cut and copy put the selected text on the clipboard as plain text.
|
|
554
542
|
const copyOrCut = (cut) => async () => {
|
|
555
543
|
restoreSelection();
|
|
@@ -857,11 +845,7 @@ export function Toolbar({ config, dictionaryStores = [], thesaurusStores = [], o
|
|
|
857
845
|
}, children: strings.contextMenu.addToDictionary }), onAddAutoCorrect && config.language.autocorrect && (_jsx(Menu.Item, { onClick: () => {
|
|
858
846
|
onAddAutoCorrect(contextMenu.spelling.word, contextMenu.spelling.language);
|
|
859
847
|
setContextMenu(null);
|
|
860
|
-
}, children: strings.contextMenu.addToAutoCorrect })), _jsx(Menu.Divider, {})] })), contextMenu?.
|
|
861
|
-
const match = contextMenu.thesaurus.match;
|
|
862
|
-
editor.update(() => $replaceMatch(match, synonym), { discrete: true });
|
|
863
|
-
editor.focus();
|
|
864
|
-
}, children: synonym }, synonym))), _jsx(Menu.Divider, {})] })), contextMenu?.link !== undefined && (_jsxs(_Fragment, { children: [_jsx(LinkMenuItems, { url: contextMenu.link, onEdit: () => {
|
|
848
|
+
}, children: strings.contextMenu.addToAutoCorrect })), _jsx(Menu.Divider, {})] })), contextMenu?.link !== undefined && (_jsxs(_Fragment, { children: [_jsx(LinkMenuItems, { url: contextMenu.link, onEdit: () => {
|
|
865
849
|
restoreSelection();
|
|
866
850
|
openLinkDialog();
|
|
867
851
|
}, onRemove: removeLink, strings: strings }), _jsx(Menu.Divider, {})] })), contextMenu?.table && (_jsxs(_Fragment, { children: [_jsx(TableMenuItems, { strings: strings, direction: direction, rows: contextMenu.table.rows, columns: contextMenu.table.columns, canMergeCells: state.canMergeCells, canUnmergeCell: state.canUnmergeCell, onAction: runMenuAction }), _jsx(Menu.Divider, {})] })), contextMenu?.poetry && (_jsxs(_Fragment, { children: [_jsx(PoetryMenuItems, { strings: strings, layout: state.poetryLayout, scale: state.poetryScale, centered: state.poetryCentered, onAction: runMenuAction }), _jsx(Menu.Divider, {})] })), _jsx(Menu.Item, { leftSection: _jsx(IconCut, { size: ICON_SIZE, stroke: ICON_STROKE }), onClick: () => void copyOrCut(true)(), children: strings.contextMenu.cut }), _jsx(Menu.Item, { leftSection: _jsx(IconCopy, { size: ICON_SIZE, stroke: ICON_STROKE }), onClick: () => void copyOrCut(false)(), children: strings.contextMenu.copy }), _jsx(Menu.Item, { leftSection: _jsx(IconClipboard, { size: ICON_SIZE, stroke: ICON_STROKE }), onClick: () => void paste(), children: strings.contextMenu.paste }), _jsx(Menu.Item, { leftSection: _jsx(IconSelectAll, { size: ICON_SIZE, stroke: ICON_STROKE }), onClick: runMenuAction(() => $selectAll()), children: strings.contextMenu.selectAll })] })] }), _jsxs("div", { "aria-hidden": "true", ref: toolbarMeasureRef, style: {
|
package/dist/i18n/strings.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/i18n/strings.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;+DAC+D;AAC/D,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,cAAc,CAAC;AAElD,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE;QACN,mGAAmG;QACnG,WAAW,EAAE,MAAM,CAAC;QACpB,gDAAgD;QAChD,YAAY,EAAE,MAAM,CAAC;QACrB,sEAAsE;QACtE,cAAc,EAAE,MAAM,CAAC;KACxB,CAAC;IACF,MAAM,EAAE;QACN,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,OAAO,EAAE;QACP,gEAAgE;QAChE,SAAS,EAAE,MAAM,CAAC;QAClB,IAAI,EAAE,MAAM,CAAC;QACb,0CAA0C;QAC1C,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,eAAe,EAAE,MAAM,CAAC;QACxB,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC;QACnB,qBAAqB,EAAE,MAAM,CAAC;QAC9B,QAAQ,E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AK,MAAM,CAAC;SAC3C,CAAC;KACH,CAAC;IACF,eAAe,EAAE;QACf,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC;QACpB,eAAe,EAAE,MAAM,CAAC;QACxB,eAAe,EAAE,MAAM,CAAC;QACxB,YAAY,EAAE,MAAM,CAAC;QACrB,QAAQ,EAAE,CAAC,OAAO,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAE,GAAG,IAAI,KAAK,MAAM,CAAC;QACxE,MAAM,EAAE;YACN,cAAc,EAAE,MAAM,CAAC;YACvB,YAAY,EAAE,MAAM,CAAC;YACrB,UAAU,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC;SAC3C,CAAC;KACH,CAAC;IACF,SAAS,EAAE;QACT,SAAS,EAAE,MAAM,CAAC;QAClB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,UAAU,EAAE,MAAM,CAAC;QACnB,UAAU,EAAE,MAAM,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC;QACpB,aAAa,EAAE,MAAM,CAAC;QACtB,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;CACH;AAqzBD,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAI3C,CAAC;AAEF;;sDAEsD;AACtD,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAElD"}
|
package/dist/i18n/strings.js
CHANGED
|
@@ -190,11 +190,6 @@ const en = {
|
|
|
190
190
|
autoComplete: {
|
|
191
191
|
label: 'Suggestions',
|
|
192
192
|
},
|
|
193
|
-
thesaurus: {
|
|
194
|
-
synonyms: 'Synonyms',
|
|
195
|
-
loading: 'Loading synonyms…',
|
|
196
|
-
none: 'No synonyms',
|
|
197
|
-
},
|
|
198
193
|
link: {
|
|
199
194
|
menuLabel: 'Link',
|
|
200
195
|
noUrl: '(no URL)',
|
|
@@ -466,11 +461,6 @@ const ur = {
|
|
|
466
461
|
autoComplete: {
|
|
467
462
|
label: 'تجاویز',
|
|
468
463
|
},
|
|
469
|
-
thesaurus: {
|
|
470
|
-
synonyms: 'مترادفات',
|
|
471
|
-
loading: 'مترادفات لوڈ ہو رہے ہیں…',
|
|
472
|
-
none: 'کوئی مترادف نہیں',
|
|
473
|
-
},
|
|
474
464
|
link: {
|
|
475
465
|
menuLabel: 'لنک',
|
|
476
466
|
noUrl: '(کوئی یو آر ایل نہیں)',
|
|
@@ -742,11 +732,6 @@ const paShahmukhi = {
|
|
|
742
732
|
autoComplete: {
|
|
743
733
|
label: 'تجویزاں',
|
|
744
734
|
},
|
|
745
|
-
thesaurus: {
|
|
746
|
-
synonyms: 'ہم معنی لفظ',
|
|
747
|
-
loading: 'ہم معنی لبھ رہے نیں…',
|
|
748
|
-
none: 'کوئی ہم معنی نئیں',
|
|
749
|
-
},
|
|
750
735
|
link: {
|
|
751
736
|
menuLabel: 'لنک',
|
|
752
737
|
noUrl: '(کوئی یو آر ایل نئیں)',
|
package/package.json
CHANGED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { SpellLanguage } from '../spellcheck/spellDictionaries.js';
|
|
2
|
-
/**
|
|
3
|
-
* Where synonyms come from. The host can pass several; their synonyms are merged
|
|
4
|
-
* in order, without repeats. A failing store is skipped.
|
|
5
|
-
*/
|
|
6
|
-
export interface ThesaurusStore {
|
|
7
|
-
readonly id: string;
|
|
8
|
-
/** Synonyms of `word` in `language`. Returns [] when there are none. */
|
|
9
|
-
lookup(word: string, language: SpellLanguage): Promise<string[]>;
|
|
10
|
-
}
|
|
11
|
-
/** One WordNet index entry for a lemma in one part of speech: its synset offsets. */
|
|
12
|
-
interface IndexEntry {
|
|
13
|
-
pos: string;
|
|
14
|
-
offsets: string[];
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Parses a WordNet `index.<pos>` file: lemma → the synsets it belongs to. Lines
|
|
18
|
-
* starting with a space are the licence header.
|
|
19
|
-
*/
|
|
20
|
-
export declare function parseWordNetIndex(text: string, pos: string): Map<string, IndexEntry[]>;
|
|
21
|
-
/**
|
|
22
|
-
* Parses a WordNet `data.<pos>` file: synset offset → the words in that synset.
|
|
23
|
-
* Multi-word entries use underscores in WordNet; they are returned with spaces.
|
|
24
|
-
*/
|
|
25
|
-
export declare function parseWordNetData(text: string): Map<string, string[]>;
|
|
26
|
-
/**
|
|
27
|
-
* English synonyms from WordNet. The database is about 35MB, so it is fetched
|
|
28
|
-
* from `baseUrl` on the first lookup, and only the files needed are read.
|
|
29
|
-
* Browsers cache the files after that.
|
|
30
|
-
*/
|
|
31
|
-
export declare function wordNetThesaurusStore(options?: {
|
|
32
|
-
baseUrl?: string;
|
|
33
|
-
fetch?: typeof fetch;
|
|
34
|
-
}): ThesaurusStore;
|
|
35
|
-
/** Synonyms from a service. `GET {url}?word=…&language=xx` returns a JSON array of strings. */
|
|
36
|
-
export declare function apiThesaurusStore(options: {
|
|
37
|
-
id?: string;
|
|
38
|
-
url: string;
|
|
39
|
-
headers?: Record<string, string>;
|
|
40
|
-
fetch?: typeof fetch;
|
|
41
|
-
}): ThesaurusStore;
|
|
42
|
-
/** Synonyms of `word` from all stores, merged in order without repeats, at most `limit`. */
|
|
43
|
-
export declare function lookupSynonyms(stores: ThesaurusStore[], word: string, language: SpellLanguage, limit?: number): Promise<string[]>;
|
|
44
|
-
export {};
|
|
45
|
-
//# sourceMappingURL=thesaurusStores.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"thesaurusStores.d.ts","sourceRoot":"","sources":["../../src/thesaurus/thesaurusStores.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAErE;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC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it belongs to. Lines
|
|
4
|
-
* starting with a space are the licence header.
|
|
5
|
-
*/
|
|
6
|
-
export function parseWordNetIndex(text, pos) {
|
|
7
|
-
const entries = new Map();
|
|
8
|
-
for (const line of text.split('\n')) {
|
|
9
|
-
if (line === '' || line.startsWith(' '))
|
|
10
|
-
continue;
|
|
11
|
-
const fields = line.split(' ');
|
|
12
|
-
const lemma = fields[0];
|
|
13
|
-
const synsetCount = Number(fields[2]);
|
|
14
|
-
const pointerCount = Number(fields[3]);
|
|
15
|
-
// lemma pos synset_cnt p_cnt [pointer...] sense_cnt tagsense_cnt offset...
|
|
16
|
-
const offsets = fields.slice(4 + pointerCount + 2, 4 + pointerCount + 2 + synsetCount);
|
|
17
|
-
const list = entries.get(lemma) ?? [];
|
|
18
|
-
list.push({ pos, offsets });
|
|
19
|
-
entries.set(lemma, list);
|
|
20
|
-
}
|
|
21
|
-
return entries;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Parses a WordNet `data.<pos>` file: synset offset → the words in that synset.
|
|
25
|
-
* Multi-word entries use underscores in WordNet; they are returned with spaces.
|
|
26
|
-
*/
|
|
27
|
-
export function parseWordNetData(text) {
|
|
28
|
-
const synsets = new Map();
|
|
29
|
-
for (const line of text.split('\n')) {
|
|
30
|
-
if (line === '' || line.startsWith(' '))
|
|
31
|
-
continue;
|
|
32
|
-
const fields = line.split(' ');
|
|
33
|
-
const offset = fields[0];
|
|
34
|
-
const wordCount = parseInt(fields[3], 16);
|
|
35
|
-
const words = [];
|
|
36
|
-
for (let i = 0; i < wordCount; i++) {
|
|
37
|
-
// Each word is followed by its lex_id; a "(a)"-style marker is not part of the word.
|
|
38
|
-
const word = fields[4 + i * 2].replace(/\(.*\)$/, '').replace(/_/g, ' ');
|
|
39
|
-
words.push(word);
|
|
40
|
-
}
|
|
41
|
-
synsets.set(offset, words);
|
|
42
|
-
}
|
|
43
|
-
return synsets;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* English synonyms from WordNet. The database is about 35MB, so it is fetched
|
|
47
|
-
* from `baseUrl` on the first lookup, and only the files needed are read.
|
|
48
|
-
* Browsers cache the files after that.
|
|
49
|
-
*/
|
|
50
|
-
export function wordNetThesaurusStore(options = {}) {
|
|
51
|
-
const base = options.baseUrl ?? 'https://cdn.jsdelivr.net/npm/wordnet-db@3.1.14/dict/';
|
|
52
|
-
const doFetch = options.fetch ?? fetch;
|
|
53
|
-
const indexes = new Map();
|
|
54
|
-
const datas = new Map();
|
|
55
|
-
const text = async (file) => {
|
|
56
|
-
const response = await doFetch(`${base}${file}`);
|
|
57
|
-
if (!response.ok)
|
|
58
|
-
throw new Error(`WordNet file failed to load: ${file}`);
|
|
59
|
-
return response.text();
|
|
60
|
-
};
|
|
61
|
-
const indexFor = (pos) => {
|
|
62
|
-
let loaded = indexes.get(pos);
|
|
63
|
-
if (!loaded) {
|
|
64
|
-
loaded = text(`index.${pos}`).then((t) => parseWordNetIndex(t, pos));
|
|
65
|
-
indexes.set(pos, loaded);
|
|
66
|
-
}
|
|
67
|
-
return loaded;
|
|
68
|
-
};
|
|
69
|
-
const dataFor = (pos) => {
|
|
70
|
-
let loaded = datas.get(pos);
|
|
71
|
-
if (!loaded) {
|
|
72
|
-
loaded = text(`data.${pos}`).then(parseWordNetData);
|
|
73
|
-
datas.set(pos, loaded);
|
|
74
|
-
}
|
|
75
|
-
return loaded;
|
|
76
|
-
};
|
|
77
|
-
return {
|
|
78
|
-
id: 'wordnet',
|
|
79
|
-
async lookup(word, language) {
|
|
80
|
-
if (language !== 'en')
|
|
81
|
-
return [];
|
|
82
|
-
const lemma = word.trim().toLowerCase().replace(/ /g, '_');
|
|
83
|
-
if (lemma === '')
|
|
84
|
-
return [];
|
|
85
|
-
const synonyms = new Set();
|
|
86
|
-
for (const pos of POS_FILES) {
|
|
87
|
-
const entries = (await indexFor(pos)).get(lemma);
|
|
88
|
-
if (!entries)
|
|
89
|
-
continue;
|
|
90
|
-
const synsets = await dataFor(pos);
|
|
91
|
-
for (const entry of entries) {
|
|
92
|
-
for (const offset of entry.offsets) {
|
|
93
|
-
for (const synonym of synsets.get(offset) ?? []) {
|
|
94
|
-
if (synonym.toLowerCase() !== lemma.replace(/_/g, ' '))
|
|
95
|
-
synonyms.add(synonym);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return [...synonyms];
|
|
101
|
-
},
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
/** Synonyms from a service. `GET {url}?word=…&language=xx` returns a JSON array of strings. */
|
|
105
|
-
export function apiThesaurusStore(options) {
|
|
106
|
-
const doFetch = options.fetch ?? fetch;
|
|
107
|
-
return {
|
|
108
|
-
id: options.id ?? 'api',
|
|
109
|
-
async lookup(word, language) {
|
|
110
|
-
const query = `?word=${encodeURIComponent(word)}&language=${encodeURIComponent(language)}`;
|
|
111
|
-
const response = await doFetch(`${options.url}${query}`, { headers: options.headers });
|
|
112
|
-
if (!response.ok)
|
|
113
|
-
throw new Error(`Thesaurus API failed: ${response.status}`);
|
|
114
|
-
const data = await response.json();
|
|
115
|
-
return Array.isArray(data) ? data.filter((s) => typeof s === 'string') : [];
|
|
116
|
-
},
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
/** Synonyms of `word` from all stores, merged in order without repeats, at most `limit`. */
|
|
120
|
-
export async function lookupSynonyms(stores, word, language, limit = 10) {
|
|
121
|
-
const results = await Promise.allSettled(stores.map((store) => store.lookup(word, language)));
|
|
122
|
-
const merged = new Set();
|
|
123
|
-
for (const result of results) {
|
|
124
|
-
if (result.status !== 'fulfilled')
|
|
125
|
-
continue;
|
|
126
|
-
for (const synonym of result.value)
|
|
127
|
-
if (synonym !== word)
|
|
128
|
-
merged.add(synonym);
|
|
129
|
-
}
|
|
130
|
-
return [...merged].slice(0, limit);
|
|
131
|
-
}
|