@textbus/platform-browser 5.0.0-alpha.1 → 5.0.0-alpha.11
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/bundles/index.esm.js +26 -6
- package/bundles/index.js +24 -4
- package/bundles/parser.d.ts +2 -2
- package/bundles/selection-bridge.d.ts +3 -2
- package/package.json +6 -6
package/bundles/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import { Slot, Textbus, Adapter, Controller, Selection, RootComponentRef, ContentType, Event, invokeListener, Keyboard, Commander,
|
|
3
|
-
import { Subject, filter, fromEvent, Subscription, distinctUntilChanged, merge, map, Observable } from '@tanbo/stream';
|
|
2
|
+
import { Slot, Textbus, Adapter, Controller, Selection, RootComponentRef, Scheduler, ContentType, Event, invokeListener, Keyboard, Commander, makeError, NativeSelectionBridge, FocusManager, Component, Registry } from '@textbus/core';
|
|
3
|
+
import { Subject, filter, fromEvent, delay, Subscription, distinctUntilChanged, merge, map, Observable } from '@tanbo/stream';
|
|
4
4
|
import { InjectionToken, Injectable, Inject, Optional } from '@viewfly/core';
|
|
5
5
|
|
|
6
6
|
function createElement(tagName, options = {}) {
|
|
@@ -383,7 +383,7 @@ class DomAdapter extends Adapter {
|
|
|
383
383
|
* Textbus PC 端选区桥接实现
|
|
384
384
|
*/
|
|
385
385
|
let SelectionBridge = class SelectionBridge {
|
|
386
|
-
constructor(config, textbus, controller, selection, rootComponentRef, input, domAdapter) {
|
|
386
|
+
constructor(config, textbus, controller, selection, rootComponentRef, input, scheduler, domAdapter) {
|
|
387
387
|
Object.defineProperty(this, "config", {
|
|
388
388
|
enumerable: true,
|
|
389
389
|
configurable: true,
|
|
@@ -408,6 +408,12 @@ let SelectionBridge = class SelectionBridge {
|
|
|
408
408
|
writable: true,
|
|
409
409
|
value: input
|
|
410
410
|
});
|
|
411
|
+
Object.defineProperty(this, "scheduler", {
|
|
412
|
+
enumerable: true,
|
|
413
|
+
configurable: true,
|
|
414
|
+
writable: true,
|
|
415
|
+
value: scheduler
|
|
416
|
+
});
|
|
411
417
|
Object.defineProperty(this, "domAdapter", {
|
|
412
418
|
enumerable: true,
|
|
413
419
|
configurable: true,
|
|
@@ -792,7 +798,15 @@ let SelectionBridge = class SelectionBridge {
|
|
|
792
798
|
}
|
|
793
799
|
}));
|
|
794
800
|
}
|
|
795
|
-
|
|
801
|
+
let isUpdating = false;
|
|
802
|
+
this.subs.push(this.scheduler.onDocChange.subscribe(() => {
|
|
803
|
+
isUpdating = true;
|
|
804
|
+
}), this.scheduler.onDocChanged.pipe(delay()).subscribe(() => {
|
|
805
|
+
isUpdating = false;
|
|
806
|
+
}), fromEvent(document, 'selectionchange').pipe().subscribe(() => {
|
|
807
|
+
if (isUpdating) {
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
796
810
|
if (this.syncSelectionFromNativeSelectionChange) {
|
|
797
811
|
this.syncSelection(connector);
|
|
798
812
|
}
|
|
@@ -835,7 +849,7 @@ let SelectionBridge = class SelectionBridge {
|
|
|
835
849
|
this.getCorrectedPosition(nativeRange.endContainer, nativeRange.endOffset, isFocusEnd);
|
|
836
850
|
if ([Node.ELEMENT_NODE, Node.TEXT_NODE].includes((_a = nativeRange.commonAncestorContainer) === null || _a === void 0 ? void 0 : _a.nodeType) &&
|
|
837
851
|
startPosition && endPosition) {
|
|
838
|
-
const abstractSelection = isFocusEnd ? {
|
|
852
|
+
const abstractSelection = connector.beforeChange(isFocusEnd ? {
|
|
839
853
|
anchorSlot: startPosition.slot,
|
|
840
854
|
anchorOffset: startPosition.offset,
|
|
841
855
|
focusSlot: endPosition.slot,
|
|
@@ -845,7 +859,12 @@ let SelectionBridge = class SelectionBridge {
|
|
|
845
859
|
focusOffset: startPosition.offset,
|
|
846
860
|
anchorSlot: endPosition.slot,
|
|
847
861
|
anchorOffset: endPosition.offset
|
|
848
|
-
};
|
|
862
|
+
});
|
|
863
|
+
if (!abstractSelection) {
|
|
864
|
+
this.selectionChangeEvent.next(null);
|
|
865
|
+
connector.setSelection(null);
|
|
866
|
+
return;
|
|
867
|
+
}
|
|
849
868
|
const { focus, anchor } = this.getPositionByRange(abstractSelection);
|
|
850
869
|
if (focus && anchor) {
|
|
851
870
|
let start = anchor;
|
|
@@ -1050,6 +1069,7 @@ SelectionBridge = __decorate([
|
|
|
1050
1069
|
Selection,
|
|
1051
1070
|
RootComponentRef,
|
|
1052
1071
|
Input,
|
|
1072
|
+
Scheduler,
|
|
1053
1073
|
DomAdapter])
|
|
1054
1074
|
], SelectionBridge);
|
|
1055
1075
|
|
package/bundles/index.js
CHANGED
|
@@ -385,7 +385,7 @@ class DomAdapter extends core$1.Adapter {
|
|
|
385
385
|
* Textbus PC 端选区桥接实现
|
|
386
386
|
*/
|
|
387
387
|
exports.SelectionBridge = class SelectionBridge {
|
|
388
|
-
constructor(config, textbus, controller, selection, rootComponentRef, input, domAdapter) {
|
|
388
|
+
constructor(config, textbus, controller, selection, rootComponentRef, input, scheduler, domAdapter) {
|
|
389
389
|
Object.defineProperty(this, "config", {
|
|
390
390
|
enumerable: true,
|
|
391
391
|
configurable: true,
|
|
@@ -410,6 +410,12 @@ exports.SelectionBridge = class SelectionBridge {
|
|
|
410
410
|
writable: true,
|
|
411
411
|
value: input
|
|
412
412
|
});
|
|
413
|
+
Object.defineProperty(this, "scheduler", {
|
|
414
|
+
enumerable: true,
|
|
415
|
+
configurable: true,
|
|
416
|
+
writable: true,
|
|
417
|
+
value: scheduler
|
|
418
|
+
});
|
|
413
419
|
Object.defineProperty(this, "domAdapter", {
|
|
414
420
|
enumerable: true,
|
|
415
421
|
configurable: true,
|
|
@@ -794,7 +800,15 @@ exports.SelectionBridge = class SelectionBridge {
|
|
|
794
800
|
}
|
|
795
801
|
}));
|
|
796
802
|
}
|
|
797
|
-
|
|
803
|
+
let isUpdating = false;
|
|
804
|
+
this.subs.push(this.scheduler.onDocChange.subscribe(() => {
|
|
805
|
+
isUpdating = true;
|
|
806
|
+
}), this.scheduler.onDocChanged.pipe(stream.delay()).subscribe(() => {
|
|
807
|
+
isUpdating = false;
|
|
808
|
+
}), stream.fromEvent(document, 'selectionchange').pipe().subscribe(() => {
|
|
809
|
+
if (isUpdating) {
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
798
812
|
if (this.syncSelectionFromNativeSelectionChange) {
|
|
799
813
|
this.syncSelection(connector);
|
|
800
814
|
}
|
|
@@ -837,7 +851,7 @@ exports.SelectionBridge = class SelectionBridge {
|
|
|
837
851
|
this.getCorrectedPosition(nativeRange.endContainer, nativeRange.endOffset, isFocusEnd);
|
|
838
852
|
if ([Node.ELEMENT_NODE, Node.TEXT_NODE].includes((_a = nativeRange.commonAncestorContainer) === null || _a === void 0 ? void 0 : _a.nodeType) &&
|
|
839
853
|
startPosition && endPosition) {
|
|
840
|
-
const abstractSelection = isFocusEnd ? {
|
|
854
|
+
const abstractSelection = connector.beforeChange(isFocusEnd ? {
|
|
841
855
|
anchorSlot: startPosition.slot,
|
|
842
856
|
anchorOffset: startPosition.offset,
|
|
843
857
|
focusSlot: endPosition.slot,
|
|
@@ -847,7 +861,12 @@ exports.SelectionBridge = class SelectionBridge {
|
|
|
847
861
|
focusOffset: startPosition.offset,
|
|
848
862
|
anchorSlot: endPosition.slot,
|
|
849
863
|
anchorOffset: endPosition.offset
|
|
850
|
-
};
|
|
864
|
+
});
|
|
865
|
+
if (!abstractSelection) {
|
|
866
|
+
this.selectionChangeEvent.next(null);
|
|
867
|
+
connector.setSelection(null);
|
|
868
|
+
return;
|
|
869
|
+
}
|
|
851
870
|
const { focus, anchor } = this.getPositionByRange(abstractSelection);
|
|
852
871
|
if (focus && anchor) {
|
|
853
872
|
let start = anchor;
|
|
@@ -1052,6 +1071,7 @@ exports.SelectionBridge = __decorate([
|
|
|
1052
1071
|
core$1.Selection,
|
|
1053
1072
|
core$1.RootComponentRef,
|
|
1054
1073
|
Input,
|
|
1074
|
+
core$1.Scheduler,
|
|
1055
1075
|
DomAdapter])
|
|
1056
1076
|
], exports.SelectionBridge);
|
|
1057
1077
|
|
package/bundles/parser.d.ts
CHANGED
|
@@ -75,13 +75,13 @@ export declare class Parser {
|
|
|
75
75
|
* @param html
|
|
76
76
|
* @param rootComponentLoader
|
|
77
77
|
*/
|
|
78
|
-
parseDoc(html: string | HTMLElement, rootComponentLoader: ComponentLoader): void | Slot | Component<import("@textbus/core").State>;
|
|
78
|
+
parseDoc(html: string | HTMLElement, rootComponentLoader: ComponentLoader): void | Slot<Record<string, any>> | Component<import("@textbus/core").State>;
|
|
79
79
|
/**
|
|
80
80
|
* 将一段 HTML 或 DOM 元素解析到指定插槽
|
|
81
81
|
* @param html
|
|
82
82
|
* @param rootSlot
|
|
83
83
|
*/
|
|
84
|
-
parse(html: string | HTMLElement, rootSlot: Slot): Slot
|
|
84
|
+
parse(html: string | HTMLElement, rootSlot: Slot): Slot<Record<string, any>>;
|
|
85
85
|
private readComponent;
|
|
86
86
|
private readText;
|
|
87
87
|
private readFormats;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Observable } from '@tanbo/stream';
|
|
2
|
-
import { NativeSelectionBridge, NativeSelectionConnector, SelectionPosition, AbstractSelection, RootComponentRef, Controller, Selection, Textbus } from '@textbus/core';
|
|
2
|
+
import { NativeSelectionBridge, NativeSelectionConnector, SelectionPosition, AbstractSelection, RootComponentRef, Controller, Selection, Textbus, Scheduler } from '@textbus/core';
|
|
3
3
|
import { Rect } from './_utils/uikit';
|
|
4
4
|
import { Input } from './types';
|
|
5
5
|
import { ViewOptions } from './browser-module';
|
|
@@ -12,6 +12,7 @@ export declare class SelectionBridge implements NativeSelectionBridge {
|
|
|
12
12
|
private selection;
|
|
13
13
|
private rootComponentRef;
|
|
14
14
|
private input;
|
|
15
|
+
private scheduler;
|
|
15
16
|
private domAdapter;
|
|
16
17
|
onSelectionChange: Observable<Range | null>;
|
|
17
18
|
nativeSelection: globalThis.Selection;
|
|
@@ -25,7 +26,7 @@ export declare class SelectionBridge implements NativeSelectionBridge {
|
|
|
25
26
|
private docContainer;
|
|
26
27
|
private cacheCaretPositionTimer;
|
|
27
28
|
private oldCaretPosition;
|
|
28
|
-
constructor(config: ViewOptions, textbus: Textbus, controller: Controller, selection: Selection, rootComponentRef: RootComponentRef, input: Input, domAdapter: DomAdapter);
|
|
29
|
+
constructor(config: ViewOptions, textbus: Textbus, controller: Controller, selection: Selection, rootComponentRef: RootComponentRef, input: Input, scheduler: Scheduler, domAdapter: DomAdapter);
|
|
29
30
|
connect(connector: NativeSelectionConnector): void;
|
|
30
31
|
disConnect(): void;
|
|
31
32
|
getRect(location: SelectionPosition): Rect | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@textbus/platform-browser",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.11",
|
|
4
4
|
"description": "Textbus is a rich text editor and framework that is highly customizable and extensible to achieve rich wysiwyg effects.",
|
|
5
5
|
"main": "./bundles/index.js",
|
|
6
6
|
"module": "./bundles/index.esm.js",
|
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@tanbo/stream": "^1.2.7",
|
|
29
|
-
"@textbus/core": "^5.0.0-alpha.
|
|
29
|
+
"@textbus/core": "^5.0.0-alpha.11",
|
|
30
30
|
"@viewfly/core": "^2.0.0-alpha.3"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@rollup/plugin-commonjs": "^
|
|
34
|
-
"@rollup/plugin-typescript": "^
|
|
33
|
+
"@rollup/plugin-commonjs": "^28.0.2",
|
|
34
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
35
35
|
"rimraf": "^3.0.2",
|
|
36
|
-
"rollup": "
|
|
36
|
+
"rollup": "4.22.4",
|
|
37
37
|
"tslib": "^2.4.1"
|
|
38
38
|
},
|
|
39
39
|
"author": {
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"bugs": {
|
|
48
48
|
"url": "https://github.com/textbus/textbus.git/issues"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "2b84bdb66f554f2d1e3fce4ff3fbd4105acb4c08"
|
|
51
51
|
}
|