oasis-editor 0.0.48 → 0.0.50
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/{OasisEditorApp-BFOkmiiJ.js → OasisEditorApp-C7bDMr2_.js} +179 -179
- package/dist/core/commands/text.d.ts +3 -10
- package/dist/core/commands/textDeletion.d.ts +4 -0
- package/dist/core/commands/textEditing.d.ts +7 -0
- package/dist/{index-BBU0ZXCs.js → index-CXzR3Cux.js} +1 -1
- package/dist/oasis-editor.js +1 -1
- package/dist/oasis-editor.umd.cjs +2 -2
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
import { n as normalizeSelection, g as getParagraphs, c as createEditorParagraphFromRuns, a as getParagraphLength, b as createEditorRun, d as getDocumentSections, e as createEditorStyledRun, f as getParagraphText, h as getActiveZone, i as getActiveSectionIndex, p as positionToParagraphOffset, j as paragraphOffsetToPosition, k as clampPosition, l as findParagraphIndex, m as createCollapsedSelection, o as isSelectionCollapsed, E as EMU_PER_PX, q as createEditorParagraph, r as getBlockParagraphs, s as createEditorFootnote, t as createFootnoteReferenceRun, u as renumberFootnotes, v as iterateFootnoteReferenceRuns, w as getFootnoteDisplayMarker, x as findParagraphTableLocation, y as buildTableCellLayout, z as createSignal, A as createEffect, B as onCleanup, C as buildCanvasLayoutSnapshot, D as on, F as onMount, G as debounce, H as unwrap, I as getDocumentParagraphs, P as PT_PER_PX, J as createEditorTableCell, K as createEditorTableRow, L as createEditorTable, M as getDocumentSectionsCanonical, N as createEditorDocument, O as getPageContentWidth, Q as getDocumentPageSettings, R as getTableCellContentWidthForParagraph, S as resolveResizedDimensions, T as resolveImageSrc, U as resolveTextBoxRenderHeight, V as TWIPS_PER_POINT, W as PX_PER_INCH, X as TWIPS_PER_INCH, Y as resolveEffectiveParagraphStyle, Z as resolveEffectiveTextStyleForParagraph, _ as EMU_PER_PT, $ as iterateEndnoteReferenceRuns, a0 as JSZip, a1 as imageContentTypeDefaults, a2 as imageExtensionFromMime, a3 as pxToPt$1, a4 as resolveFloatingObjectRect, a5 as getTextBoxFloatingGeometry, a6 as getPresetPathSegments, a7 as projectBlocksLayout, a8 as buildListLabels, a9 as textStyleToFontSizePt, aa as PX_PER_POINT, ab as DEFAULT_FONT_SIZE_PX, ac as isDoubleUnderlineStyle, ad as isWavyUnderlineStyle, ae as underlineStyleLineWidthPx, af as underlineStyleDashArray, ag as resolveListLabel, ah as getListLabelInset, ai as getAlignedListLabelInset, aj as getParagraphBorderInsets, ak as buildSegmentTable, al as buildCanvasTableLayout, am as normalizeFamily, an as ROBOTO_FONT_FILES, ao as loadFontAsset, ap as OFFICE_COMPAT_FONT_FAMILIES, aq as buildSfnt, ar as defaultFontDecoderRegistry, as as SfntFontProgram, at as collectPdfFontFamilies, au as projectDocumentLayout, av as getPageHeaderZoneTop, aw as getPageBodyTop, ax as getPageColumnRects, ay as findFootnoteReference, az as FOOTNOTE_MARKER_GUTTER_PX, aA as resolveImporterForFile, aB as createEditorStateFromDocument, aC as getDocumentParagraphsCanonical, aD as getToolbarStyleState, aE as STANDARD_FONT_SIZES_PT, aF as fontSizePxToPt, aG as probeLocalFontFamilies, aH as createInitialEditorState, aI as parseFontSizePtToPx, aJ as formatFontSizePt, aK as underlineStyleToCssDecorationStyle, aL as listKindForTag, aM as isParagraphTag, aN as collectInlineRuns, aO as parseParagraphStyle, aP as getCachedCanvasImage, aQ as getHeadingLevel, aR as preciseFontModeVersion, aS as isPreciseFontModeEnabled, aT as togglePreciseFontMode, aU as nextFontSizePt, aV as previousFontSizePt, aW as fontSizePtToPx, aX as createDefaultToolbarPreset, aY as MenuRegistry, aZ as createToolbarRegistry, a_ as Editor, a$ as resolveCommandRef, b0 as commandRefName, b1 as InlineShell, b2 as BalloonShell, b3 as DocumentShell, b4 as createMemo, b5 as getCaretRectFromSnapshot, b6 as getParagraphRectFromSnapshot, b7 as createComponent, b8 as CaretOverlay, b9 as Show, ba as createRenderEffect, bb as style, bc as setAttribute, bd as setStyleProperty, be as memo, bf as template, bg as useI18n, bh as insert, bi as use, bj as addEventListener, bk as Dialog, bl as delegateEvents, bm as className, bn as For, bo as UNDERLINE_STYLE_OPTIONS, bp as Tabs, bq as measureParagraphMinContentWidthPx, br as getEditableBlocksForZone, bs as findParagraphLocation, bt as createSectionBoundaryParagraph, bu as normalizePageSettings, bv as DEFAULT_EDITOR_PAGE_SETTINGS, bw as markStart, bx as markEnd, by as getParagraphEntries, bz as getParagraphById, bA as PluginUiHost, bB as OasisEditorEditor, bC as perfTimer, bD as OasisBrandMark, bE as setPreciseFontPreference, bF as setWelcomeSeen, bG as enablePreciseFontMode, bH as createOasisEditorClient, bI as createEditorZoom, bJ as startLongTaskObserver, bK as installGlobalReport, bL as applyStoredPreciseFontPreference, bM as getWelcomeSeen, bN as isLocalFontAccessSupported, bO as EDITOR_SCROLL_PADDING_PX, bP as Toolbar, bQ as OasisEditorLoading, bR as I18nProvider, bS as createEditorLogger, bT as createTranslator, bU as registerDomStatsSurface } from "./index-
|
|
4
|
+
import { n as normalizeSelection, g as getParagraphs, c as createEditorParagraphFromRuns, a as getParagraphLength, b as createEditorRun, d as getDocumentSections, e as createEditorStyledRun, f as getParagraphText, h as getActiveZone, i as getActiveSectionIndex, p as positionToParagraphOffset, j as paragraphOffsetToPosition, k as clampPosition, l as findParagraphIndex, m as createCollapsedSelection, o as isSelectionCollapsed, E as EMU_PER_PX, q as createEditorParagraph, r as getBlockParagraphs, s as createEditorFootnote, t as createFootnoteReferenceRun, u as renumberFootnotes, v as iterateFootnoteReferenceRuns, w as getFootnoteDisplayMarker, x as findParagraphTableLocation, y as buildTableCellLayout, z as createSignal, A as createEffect, B as onCleanup, C as buildCanvasLayoutSnapshot, D as on, F as onMount, G as debounce, H as unwrap, I as getDocumentParagraphs, P as PT_PER_PX, J as createEditorTableCell, K as createEditorTableRow, L as createEditorTable, M as getDocumentSectionsCanonical, N as createEditorDocument, O as getPageContentWidth, Q as getDocumentPageSettings, R as getTableCellContentWidthForParagraph, S as resolveResizedDimensions, T as resolveImageSrc, U as resolveTextBoxRenderHeight, V as TWIPS_PER_POINT, W as PX_PER_INCH, X as TWIPS_PER_INCH, Y as resolveEffectiveParagraphStyle, Z as resolveEffectiveTextStyleForParagraph, _ as EMU_PER_PT, $ as iterateEndnoteReferenceRuns, a0 as JSZip, a1 as imageContentTypeDefaults, a2 as imageExtensionFromMime, a3 as pxToPt$1, a4 as resolveFloatingObjectRect, a5 as getTextBoxFloatingGeometry, a6 as getPresetPathSegments, a7 as projectBlocksLayout, a8 as buildListLabels, a9 as textStyleToFontSizePt, aa as PX_PER_POINT, ab as DEFAULT_FONT_SIZE_PX, ac as isDoubleUnderlineStyle, ad as isWavyUnderlineStyle, ae as underlineStyleLineWidthPx, af as underlineStyleDashArray, ag as resolveListLabel, ah as getListLabelInset, ai as getAlignedListLabelInset, aj as getParagraphBorderInsets, ak as buildSegmentTable, al as buildCanvasTableLayout, am as normalizeFamily, an as ROBOTO_FONT_FILES, ao as loadFontAsset, ap as OFFICE_COMPAT_FONT_FAMILIES, aq as buildSfnt, ar as defaultFontDecoderRegistry, as as SfntFontProgram, at as collectPdfFontFamilies, au as projectDocumentLayout, av as getPageHeaderZoneTop, aw as getPageBodyTop, ax as getPageColumnRects, ay as findFootnoteReference, az as FOOTNOTE_MARKER_GUTTER_PX, aA as resolveImporterForFile, aB as createEditorStateFromDocument, aC as getDocumentParagraphsCanonical, aD as getToolbarStyleState, aE as STANDARD_FONT_SIZES_PT, aF as fontSizePxToPt, aG as probeLocalFontFamilies, aH as createInitialEditorState, aI as parseFontSizePtToPx, aJ as formatFontSizePt, aK as underlineStyleToCssDecorationStyle, aL as listKindForTag, aM as isParagraphTag, aN as collectInlineRuns, aO as parseParagraphStyle, aP as getCachedCanvasImage, aQ as getHeadingLevel, aR as preciseFontModeVersion, aS as isPreciseFontModeEnabled, aT as togglePreciseFontMode, aU as nextFontSizePt, aV as previousFontSizePt, aW as fontSizePtToPx, aX as createDefaultToolbarPreset, aY as MenuRegistry, aZ as createToolbarRegistry, a_ as Editor, a$ as resolveCommandRef, b0 as commandRefName, b1 as InlineShell, b2 as BalloonShell, b3 as DocumentShell, b4 as createMemo, b5 as getCaretRectFromSnapshot, b6 as getParagraphRectFromSnapshot, b7 as createComponent, b8 as CaretOverlay, b9 as Show, ba as createRenderEffect, bb as style, bc as setAttribute, bd as setStyleProperty, be as memo, bf as template, bg as useI18n, bh as insert, bi as use, bj as addEventListener, bk as Dialog, bl as delegateEvents, bm as className, bn as For, bo as UNDERLINE_STYLE_OPTIONS, bp as Tabs, bq as measureParagraphMinContentWidthPx, br as getEditableBlocksForZone, bs as findParagraphLocation, bt as createSectionBoundaryParagraph, bu as normalizePageSettings, bv as DEFAULT_EDITOR_PAGE_SETTINGS, bw as markStart, bx as markEnd, by as getParagraphEntries, bz as getParagraphById, bA as PluginUiHost, bB as OasisEditorEditor, bC as perfTimer, bD as OasisBrandMark, bE as setPreciseFontPreference, bF as setWelcomeSeen, bG as enablePreciseFontMode, bH as createOasisEditorClient, bI as createEditorZoom, bJ as startLongTaskObserver, bK as installGlobalReport, bL as applyStoredPreciseFontPreference, bM as getWelcomeSeen, bN as isLocalFontAccessSupported, bO as EDITOR_SCROLL_PADDING_PX, bP as Toolbar, bQ as OasisEditorLoading, bR as I18nProvider, bS as createEditorLogger, bT as createTranslator, bU as registerDomStatsSurface } from "./index-CXzR3Cux.js";
|
|
5
5
|
function getSelectedObjectRun(state, predicate) {
|
|
6
6
|
const normalized = normalizeSelection(state);
|
|
7
7
|
if (normalized.isCollapsed || normalized.startIndex !== normalized.endIndex || normalized.endParagraphOffset - normalized.startParagraphOffset !== 1) {
|
|
@@ -2219,184 +2219,6 @@ function rejectRevisionsInSelection(state) {
|
|
|
2219
2219
|
}
|
|
2220
2220
|
return nextState;
|
|
2221
2221
|
}
|
|
2222
|
-
function isLetter(char) {
|
|
2223
|
-
return new RegExp("\\p{L}", "u").test(char);
|
|
2224
|
-
}
|
|
2225
|
-
function toSentenceCase(text) {
|
|
2226
|
-
let result = "";
|
|
2227
|
-
let capitalizeNext = true;
|
|
2228
|
-
for (const char of text.toLowerCase()) {
|
|
2229
|
-
if (capitalizeNext && isLetter(char)) {
|
|
2230
|
-
result += char.toUpperCase();
|
|
2231
|
-
capitalizeNext = false;
|
|
2232
|
-
} else {
|
|
2233
|
-
result += char;
|
|
2234
|
-
if (char === "." || char === "!" || char === "?") {
|
|
2235
|
-
capitalizeNext = true;
|
|
2236
|
-
}
|
|
2237
|
-
}
|
|
2238
|
-
}
|
|
2239
|
-
return result;
|
|
2240
|
-
}
|
|
2241
|
-
function toCapitalizedWords(text) {
|
|
2242
|
-
let result = "";
|
|
2243
|
-
let prevIsLetter = false;
|
|
2244
|
-
for (const char of text) {
|
|
2245
|
-
const letter = isLetter(char);
|
|
2246
|
-
result += letter && !prevIsLetter ? char.toUpperCase() : char;
|
|
2247
|
-
prevIsLetter = letter;
|
|
2248
|
-
}
|
|
2249
|
-
return result;
|
|
2250
|
-
}
|
|
2251
|
-
function toToggledCase(text) {
|
|
2252
|
-
let result = "";
|
|
2253
|
-
for (const char of text) {
|
|
2254
|
-
const upper = char.toUpperCase();
|
|
2255
|
-
const lower = char.toLowerCase();
|
|
2256
|
-
if (char === lower && char !== upper) {
|
|
2257
|
-
result += upper;
|
|
2258
|
-
} else if (char === upper && char !== lower) {
|
|
2259
|
-
result += lower;
|
|
2260
|
-
} else {
|
|
2261
|
-
result += char;
|
|
2262
|
-
}
|
|
2263
|
-
}
|
|
2264
|
-
return result;
|
|
2265
|
-
}
|
|
2266
|
-
function applyCaseTransform(text, mode) {
|
|
2267
|
-
switch (mode) {
|
|
2268
|
-
case "lower":
|
|
2269
|
-
return text.toLowerCase();
|
|
2270
|
-
case "upper":
|
|
2271
|
-
return text.toUpperCase();
|
|
2272
|
-
case "capitalize":
|
|
2273
|
-
return toCapitalizedWords(text);
|
|
2274
|
-
case "toggle":
|
|
2275
|
-
return toToggledCase(text);
|
|
2276
|
-
case "sentence":
|
|
2277
|
-
default:
|
|
2278
|
-
return toSentenceCase(text);
|
|
2279
|
-
}
|
|
2280
|
-
}
|
|
2281
|
-
function transformSelectedText(state, transform) {
|
|
2282
|
-
const normalized = normalizeSelection(state);
|
|
2283
|
-
if (normalized.isCollapsed) {
|
|
2284
|
-
return state;
|
|
2285
|
-
}
|
|
2286
|
-
const paragraphs = getParagraphs(state);
|
|
2287
|
-
const nextParagraphs = paragraphs.map((paragraph, paragraphIndex) => {
|
|
2288
|
-
if (paragraphIndex < normalized.startIndex || paragraphIndex > normalized.endIndex) {
|
|
2289
|
-
return paragraph;
|
|
2290
|
-
}
|
|
2291
|
-
const startOffset = paragraphIndex === normalized.startIndex ? normalized.startParagraphOffset : 0;
|
|
2292
|
-
const endOffset = paragraphIndex === normalized.endIndex ? normalized.endParagraphOffset : getParagraphLength(paragraph);
|
|
2293
|
-
const selectedText = sliceRuns(paragraph, startOffset, endOffset).map((run) => run.text).join("");
|
|
2294
|
-
const transformed = transform(selectedText);
|
|
2295
|
-
let cursor = 0;
|
|
2296
|
-
return mapRunsInRange(paragraph, startOffset, endOffset, (run) => {
|
|
2297
|
-
const length = run.text.length;
|
|
2298
|
-
const nextText = transformed.slice(cursor, cursor + length);
|
|
2299
|
-
cursor += length;
|
|
2300
|
-
return { ...run, text: nextText };
|
|
2301
|
-
});
|
|
2302
|
-
});
|
|
2303
|
-
return cloneStateWithParagraphs(
|
|
2304
|
-
state,
|
|
2305
|
-
nextParagraphs,
|
|
2306
|
-
preserveSelectionByParagraphOffsets(nextParagraphs, normalized)
|
|
2307
|
-
);
|
|
2308
|
-
}
|
|
2309
|
-
function changeSelectedTextCase(state, mode) {
|
|
2310
|
-
return transformSelectedText(state, (text) => applyCaseTransform(text, mode));
|
|
2311
|
-
}
|
|
2312
|
-
function toggleTextStyle(state, key) {
|
|
2313
|
-
const normalized = normalizeSelection(state);
|
|
2314
|
-
if (normalized.isCollapsed) {
|
|
2315
|
-
return state;
|
|
2316
|
-
}
|
|
2317
|
-
const paragraphs = getParagraphs(state);
|
|
2318
|
-
const touchedParagraphs = paragraphs.slice(
|
|
2319
|
-
normalized.startIndex,
|
|
2320
|
-
normalized.endIndex + 1
|
|
2321
|
-
);
|
|
2322
|
-
const touchedRuns = touchedParagraphs.flatMap((paragraph, relativeIndex) => {
|
|
2323
|
-
const paragraphIndex = normalized.startIndex + relativeIndex;
|
|
2324
|
-
const startOffset = paragraphIndex === normalized.startIndex ? normalized.startParagraphOffset : 0;
|
|
2325
|
-
const endOffset = paragraphIndex === normalized.endIndex ? normalized.endParagraphOffset : getParagraphLength(paragraph);
|
|
2326
|
-
return sliceRuns(paragraph, startOffset, endOffset);
|
|
2327
|
-
}).filter((run) => run.text.length > 0);
|
|
2328
|
-
if (touchedRuns.length === 0) {
|
|
2329
|
-
return state;
|
|
2330
|
-
}
|
|
2331
|
-
const shouldEnable = !touchedRuns.every((run) => {
|
|
2332
|
-
var _a;
|
|
2333
|
-
return Boolean((_a = run.styles) == null ? void 0 : _a[key]);
|
|
2334
|
-
});
|
|
2335
|
-
const nextParagraphs = paragraphs.map((paragraph, paragraphIndex) => {
|
|
2336
|
-
if (paragraphIndex < normalized.startIndex || paragraphIndex > normalized.endIndex) {
|
|
2337
|
-
return paragraph;
|
|
2338
|
-
}
|
|
2339
|
-
const startOffset = paragraphIndex === normalized.startIndex ? normalized.startParagraphOffset : 0;
|
|
2340
|
-
const endOffset = paragraphIndex === normalized.endIndex ? normalized.endParagraphOffset : getParagraphLength(paragraph);
|
|
2341
|
-
return mapRunsInRange(paragraph, startOffset, endOffset, (run) => ({
|
|
2342
|
-
...run,
|
|
2343
|
-
styles: setBooleanStyle(run.styles, key, shouldEnable)
|
|
2344
|
-
}));
|
|
2345
|
-
});
|
|
2346
|
-
return cloneStateWithParagraphs(
|
|
2347
|
-
state,
|
|
2348
|
-
nextParagraphs,
|
|
2349
|
-
preserveSelectionByParagraphOffsets(nextParagraphs, normalized)
|
|
2350
|
-
);
|
|
2351
|
-
}
|
|
2352
|
-
function clearSelectedTextFormatting(state) {
|
|
2353
|
-
const normalized = normalizeSelection(state);
|
|
2354
|
-
if (normalized.isCollapsed) {
|
|
2355
|
-
return state;
|
|
2356
|
-
}
|
|
2357
|
-
const paragraphs = getParagraphs(state);
|
|
2358
|
-
const nextParagraphs = paragraphs.map((paragraph, paragraphIndex) => {
|
|
2359
|
-
if (paragraphIndex < normalized.startIndex || paragraphIndex > normalized.endIndex) {
|
|
2360
|
-
return paragraph;
|
|
2361
|
-
}
|
|
2362
|
-
const startOffset = paragraphIndex === normalized.startIndex ? normalized.startParagraphOffset : 0;
|
|
2363
|
-
const endOffset = paragraphIndex === normalized.endIndex ? normalized.endParagraphOffset : getParagraphLength(paragraph);
|
|
2364
|
-
return mapRunsInRange(paragraph, startOffset, endOffset, (run) => {
|
|
2365
|
-
var _a;
|
|
2366
|
-
const link = (_a = run.styles) == null ? void 0 : _a.link;
|
|
2367
|
-
const styles = link != null && link !== "" ? { link } : {};
|
|
2368
|
-
return { ...run, styles };
|
|
2369
|
-
});
|
|
2370
|
-
});
|
|
2371
|
-
return cloneStateWithParagraphs(
|
|
2372
|
-
state,
|
|
2373
|
-
nextParagraphs,
|
|
2374
|
-
preserveSelectionByParagraphOffsets(nextParagraphs, normalized)
|
|
2375
|
-
);
|
|
2376
|
-
}
|
|
2377
|
-
function setTextStyleValue(state, key, value) {
|
|
2378
|
-
const normalized = normalizeSelection(state);
|
|
2379
|
-
if (normalized.isCollapsed) {
|
|
2380
|
-
return state;
|
|
2381
|
-
}
|
|
2382
|
-
const paragraphs = getParagraphs(state);
|
|
2383
|
-
const nextParagraphs = paragraphs.map((paragraph, paragraphIndex) => {
|
|
2384
|
-
if (paragraphIndex < normalized.startIndex || paragraphIndex > normalized.endIndex) {
|
|
2385
|
-
return paragraph;
|
|
2386
|
-
}
|
|
2387
|
-
const startOffset = paragraphIndex === normalized.startIndex ? normalized.startParagraphOffset : 0;
|
|
2388
|
-
const endOffset = paragraphIndex === normalized.endIndex ? normalized.endParagraphOffset : getParagraphLength(paragraph);
|
|
2389
|
-
return mapRunsInRange(paragraph, startOffset, endOffset, (run) => ({
|
|
2390
|
-
...run,
|
|
2391
|
-
styles: setValueStyle(run.styles, key, value)
|
|
2392
|
-
}));
|
|
2393
|
-
});
|
|
2394
|
-
return cloneStateWithParagraphs(
|
|
2395
|
-
state,
|
|
2396
|
-
nextParagraphs,
|
|
2397
|
-
preserveSelectionByParagraphOffsets(nextParagraphs, normalized)
|
|
2398
|
-
);
|
|
2399
|
-
}
|
|
2400
2222
|
function cloneFragmentRuns(runs) {
|
|
2401
2223
|
return runs.map(cloneRun);
|
|
2402
2224
|
}
|
|
@@ -2856,6 +2678,184 @@ function deleteForward(state) {
|
|
|
2856
2678
|
withSelection(paragraphOffsetToPosition(mergedParagraph, offset))
|
|
2857
2679
|
);
|
|
2858
2680
|
}
|
|
2681
|
+
function toggleTextStyle(state, key) {
|
|
2682
|
+
const normalized = normalizeSelection(state);
|
|
2683
|
+
if (normalized.isCollapsed) {
|
|
2684
|
+
return state;
|
|
2685
|
+
}
|
|
2686
|
+
const paragraphs = getParagraphs(state);
|
|
2687
|
+
const touchedParagraphs = paragraphs.slice(
|
|
2688
|
+
normalized.startIndex,
|
|
2689
|
+
normalized.endIndex + 1
|
|
2690
|
+
);
|
|
2691
|
+
const touchedRuns = touchedParagraphs.flatMap((paragraph, relativeIndex) => {
|
|
2692
|
+
const paragraphIndex = normalized.startIndex + relativeIndex;
|
|
2693
|
+
const startOffset = paragraphIndex === normalized.startIndex ? normalized.startParagraphOffset : 0;
|
|
2694
|
+
const endOffset = paragraphIndex === normalized.endIndex ? normalized.endParagraphOffset : getParagraphLength(paragraph);
|
|
2695
|
+
return sliceRuns(paragraph, startOffset, endOffset);
|
|
2696
|
+
}).filter((run) => run.text.length > 0);
|
|
2697
|
+
if (touchedRuns.length === 0) {
|
|
2698
|
+
return state;
|
|
2699
|
+
}
|
|
2700
|
+
const shouldEnable = !touchedRuns.every((run) => {
|
|
2701
|
+
var _a;
|
|
2702
|
+
return Boolean((_a = run.styles) == null ? void 0 : _a[key]);
|
|
2703
|
+
});
|
|
2704
|
+
const nextParagraphs = paragraphs.map((paragraph, paragraphIndex) => {
|
|
2705
|
+
if (paragraphIndex < normalized.startIndex || paragraphIndex > normalized.endIndex) {
|
|
2706
|
+
return paragraph;
|
|
2707
|
+
}
|
|
2708
|
+
const startOffset = paragraphIndex === normalized.startIndex ? normalized.startParagraphOffset : 0;
|
|
2709
|
+
const endOffset = paragraphIndex === normalized.endIndex ? normalized.endParagraphOffset : getParagraphLength(paragraph);
|
|
2710
|
+
return mapRunsInRange(paragraph, startOffset, endOffset, (run) => ({
|
|
2711
|
+
...run,
|
|
2712
|
+
styles: setBooleanStyle(run.styles, key, shouldEnable)
|
|
2713
|
+
}));
|
|
2714
|
+
});
|
|
2715
|
+
return cloneStateWithParagraphs(
|
|
2716
|
+
state,
|
|
2717
|
+
nextParagraphs,
|
|
2718
|
+
preserveSelectionByParagraphOffsets(nextParagraphs, normalized)
|
|
2719
|
+
);
|
|
2720
|
+
}
|
|
2721
|
+
function clearSelectedTextFormatting(state) {
|
|
2722
|
+
const normalized = normalizeSelection(state);
|
|
2723
|
+
if (normalized.isCollapsed) {
|
|
2724
|
+
return state;
|
|
2725
|
+
}
|
|
2726
|
+
const paragraphs = getParagraphs(state);
|
|
2727
|
+
const nextParagraphs = paragraphs.map((paragraph, paragraphIndex) => {
|
|
2728
|
+
if (paragraphIndex < normalized.startIndex || paragraphIndex > normalized.endIndex) {
|
|
2729
|
+
return paragraph;
|
|
2730
|
+
}
|
|
2731
|
+
const startOffset = paragraphIndex === normalized.startIndex ? normalized.startParagraphOffset : 0;
|
|
2732
|
+
const endOffset = paragraphIndex === normalized.endIndex ? normalized.endParagraphOffset : getParagraphLength(paragraph);
|
|
2733
|
+
return mapRunsInRange(paragraph, startOffset, endOffset, (run) => {
|
|
2734
|
+
var _a;
|
|
2735
|
+
const link = (_a = run.styles) == null ? void 0 : _a.link;
|
|
2736
|
+
const styles = link != null && link !== "" ? { link } : {};
|
|
2737
|
+
return { ...run, styles };
|
|
2738
|
+
});
|
|
2739
|
+
});
|
|
2740
|
+
return cloneStateWithParagraphs(
|
|
2741
|
+
state,
|
|
2742
|
+
nextParagraphs,
|
|
2743
|
+
preserveSelectionByParagraphOffsets(nextParagraphs, normalized)
|
|
2744
|
+
);
|
|
2745
|
+
}
|
|
2746
|
+
function setTextStyleValue(state, key, value) {
|
|
2747
|
+
const normalized = normalizeSelection(state);
|
|
2748
|
+
if (normalized.isCollapsed) {
|
|
2749
|
+
return state;
|
|
2750
|
+
}
|
|
2751
|
+
const paragraphs = getParagraphs(state);
|
|
2752
|
+
const nextParagraphs = paragraphs.map((paragraph, paragraphIndex) => {
|
|
2753
|
+
if (paragraphIndex < normalized.startIndex || paragraphIndex > normalized.endIndex) {
|
|
2754
|
+
return paragraph;
|
|
2755
|
+
}
|
|
2756
|
+
const startOffset = paragraphIndex === normalized.startIndex ? normalized.startParagraphOffset : 0;
|
|
2757
|
+
const endOffset = paragraphIndex === normalized.endIndex ? normalized.endParagraphOffset : getParagraphLength(paragraph);
|
|
2758
|
+
return mapRunsInRange(paragraph, startOffset, endOffset, (run) => ({
|
|
2759
|
+
...run,
|
|
2760
|
+
styles: setValueStyle(run.styles, key, value)
|
|
2761
|
+
}));
|
|
2762
|
+
});
|
|
2763
|
+
return cloneStateWithParagraphs(
|
|
2764
|
+
state,
|
|
2765
|
+
nextParagraphs,
|
|
2766
|
+
preserveSelectionByParagraphOffsets(nextParagraphs, normalized)
|
|
2767
|
+
);
|
|
2768
|
+
}
|
|
2769
|
+
function isLetter(char) {
|
|
2770
|
+
return new RegExp("\\p{L}", "u").test(char);
|
|
2771
|
+
}
|
|
2772
|
+
function toSentenceCase(text) {
|
|
2773
|
+
let result = "";
|
|
2774
|
+
let capitalizeNext = true;
|
|
2775
|
+
for (const char of text.toLowerCase()) {
|
|
2776
|
+
if (capitalizeNext && isLetter(char)) {
|
|
2777
|
+
result += char.toUpperCase();
|
|
2778
|
+
capitalizeNext = false;
|
|
2779
|
+
} else {
|
|
2780
|
+
result += char;
|
|
2781
|
+
if (char === "." || char === "!" || char === "?") {
|
|
2782
|
+
capitalizeNext = true;
|
|
2783
|
+
}
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
return result;
|
|
2787
|
+
}
|
|
2788
|
+
function toCapitalizedWords(text) {
|
|
2789
|
+
let result = "";
|
|
2790
|
+
let prevIsLetter = false;
|
|
2791
|
+
for (const char of text) {
|
|
2792
|
+
const letter = isLetter(char);
|
|
2793
|
+
result += letter && !prevIsLetter ? char.toUpperCase() : char;
|
|
2794
|
+
prevIsLetter = letter;
|
|
2795
|
+
}
|
|
2796
|
+
return result;
|
|
2797
|
+
}
|
|
2798
|
+
function toToggledCase(text) {
|
|
2799
|
+
let result = "";
|
|
2800
|
+
for (const char of text) {
|
|
2801
|
+
const upper = char.toUpperCase();
|
|
2802
|
+
const lower = char.toLowerCase();
|
|
2803
|
+
if (char === lower && char !== upper) {
|
|
2804
|
+
result += upper;
|
|
2805
|
+
} else if (char === upper && char !== lower) {
|
|
2806
|
+
result += lower;
|
|
2807
|
+
} else {
|
|
2808
|
+
result += char;
|
|
2809
|
+
}
|
|
2810
|
+
}
|
|
2811
|
+
return result;
|
|
2812
|
+
}
|
|
2813
|
+
function applyCaseTransform(text, mode) {
|
|
2814
|
+
switch (mode) {
|
|
2815
|
+
case "lower":
|
|
2816
|
+
return text.toLowerCase();
|
|
2817
|
+
case "upper":
|
|
2818
|
+
return text.toUpperCase();
|
|
2819
|
+
case "capitalize":
|
|
2820
|
+
return toCapitalizedWords(text);
|
|
2821
|
+
case "toggle":
|
|
2822
|
+
return toToggledCase(text);
|
|
2823
|
+
case "sentence":
|
|
2824
|
+
default:
|
|
2825
|
+
return toSentenceCase(text);
|
|
2826
|
+
}
|
|
2827
|
+
}
|
|
2828
|
+
function transformSelectedText(state, transform) {
|
|
2829
|
+
const normalized = normalizeSelection(state);
|
|
2830
|
+
if (normalized.isCollapsed) {
|
|
2831
|
+
return state;
|
|
2832
|
+
}
|
|
2833
|
+
const paragraphs = getParagraphs(state);
|
|
2834
|
+
const nextParagraphs = paragraphs.map((paragraph, paragraphIndex) => {
|
|
2835
|
+
if (paragraphIndex < normalized.startIndex || paragraphIndex > normalized.endIndex) {
|
|
2836
|
+
return paragraph;
|
|
2837
|
+
}
|
|
2838
|
+
const startOffset = paragraphIndex === normalized.startIndex ? normalized.startParagraphOffset : 0;
|
|
2839
|
+
const endOffset = paragraphIndex === normalized.endIndex ? normalized.endParagraphOffset : getParagraphLength(paragraph);
|
|
2840
|
+
const selectedText = sliceRuns(paragraph, startOffset, endOffset).map((run) => run.text).join("");
|
|
2841
|
+
const transformed = transform(selectedText);
|
|
2842
|
+
let cursor = 0;
|
|
2843
|
+
return mapRunsInRange(paragraph, startOffset, endOffset, (run) => {
|
|
2844
|
+
const length = run.text.length;
|
|
2845
|
+
const nextText = transformed.slice(cursor, cursor + length);
|
|
2846
|
+
cursor += length;
|
|
2847
|
+
return { ...run, text: nextText };
|
|
2848
|
+
});
|
|
2849
|
+
});
|
|
2850
|
+
return cloneStateWithParagraphs(
|
|
2851
|
+
state,
|
|
2852
|
+
nextParagraphs,
|
|
2853
|
+
preserveSelectionByParagraphOffsets(nextParagraphs, normalized)
|
|
2854
|
+
);
|
|
2855
|
+
}
|
|
2856
|
+
function changeSelectedTextCase(state, mode) {
|
|
2857
|
+
return transformSelectedText(state, (text) => applyCaseTransform(text, mode));
|
|
2858
|
+
}
|
|
2859
2859
|
function getLinkAtSelection(state) {
|
|
2860
2860
|
var _a, _b, _c;
|
|
2861
2861
|
const normalized = normalizeSelection(state);
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare function moveOrCopySelectionToPosition(state: EditorState, targetPosition: EditorPosition, options?: {
|
|
4
|
-
copy?: boolean;
|
|
5
|
-
}): EditorState;
|
|
6
|
-
export declare function insertTextAtSelection(state: EditorState, text: string, styleOverride?: EditorTextStyle): EditorState;
|
|
7
|
-
export declare function insertPlainTextAtSelection(state: EditorState, text: string, styleOverride?: EditorTextStyle): EditorState;
|
|
8
|
-
export declare function deleteBackward(state: EditorState): EditorState;
|
|
9
|
-
export declare function deleteForward(state: EditorState): EditorState;
|
|
10
|
-
export { type TextCaseMode, transformSelectedText, changeSelectedTextCase, } from './textCase.js';
|
|
1
|
+
export { moveOrCopySelectionToPosition, insertTextAtSelection, insertPlainTextAtSelection, } from './textEditing.js';
|
|
2
|
+
export { deleteBackward, deleteForward } from './textDeletion.js';
|
|
11
3
|
export { toggleTextStyle, clearSelectedTextFormatting, setTextStyleValue, } from './textFormatting.js';
|
|
4
|
+
export { type TextCaseMode, transformSelectedText, changeSelectedTextCase, } from './textCase.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { EditorPosition, EditorState, EditorTextStyle } from '../model.js';
|
|
2
|
+
|
|
3
|
+
export declare function moveOrCopySelectionToPosition(state: EditorState, targetPosition: EditorPosition, options?: {
|
|
4
|
+
copy?: boolean;
|
|
5
|
+
}): EditorState;
|
|
6
|
+
export declare function insertTextAtSelection(state: EditorState, text: string, styleOverride?: EditorTextStyle): EditorState;
|
|
7
|
+
export declare function insertPlainTextAtSelection(state: EditorState, text: string, styleOverride?: EditorTextStyle): EditorState;
|
|
@@ -2483,7 +2483,7 @@ function OasisEditorAppLazy(props = {}) {
|
|
|
2483
2483
|
onCleanup(() => {
|
|
2484
2484
|
cancelled = true;
|
|
2485
2485
|
});
|
|
2486
|
-
import("./OasisEditorApp-
|
|
2486
|
+
import("./OasisEditorApp-C7bDMr2_.js").then((m) => {
|
|
2487
2487
|
cancelled = true;
|
|
2488
2488
|
setProgress(1);
|
|
2489
2489
|
setTimeout(() => setApp(() => m.OasisEditorApp), 180);
|
package/dist/oasis-editor.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b2, bV, bW, bX, bY, bZ, bk, b_, b3, a_, b$, c0, c1, b1, c2, aY, c3, c4, c5, c6, c7, bQ, c8, c9, ca, cb, cc, cd, ce, cf, cg, ch, ci, bp, cj, bP, ck, bX as bX2, c0 as c02, c2 as c22, cb as cb2, cd as cd2, ci as ci2, cl, b0, aX, cm, cn, co, aZ, cp, cq, a$ } from "./index-
|
|
1
|
+
import { b2, bV, bW, bX, bY, bZ, bk, b_, b3, a_, b$, c0, c1, b1, c2, aY, c3, c4, c5, c6, c7, bQ, c8, c9, ca, cb, cc, cd, ce, cf, cg, ch, ci, bp, cj, bP, ck, bX as bX2, c0 as c02, c2 as c22, cb as cb2, cd as cd2, ci as ci2, cl, b0, aX, cm, cn, co, aZ, cp, cq, a$ } from "./index-CXzR3Cux.js";
|
|
2
2
|
export {
|
|
3
3
|
b2 as BalloonShell,
|
|
4
4
|
bV as Button,
|