@textbus/platform-browser 4.0.0-alpha.12 → 4.0.0-alpha.15
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/browser-module.d.ts +16 -3
- package/bundles/index.esm.js +84 -54
- package/bundles/index.js +83 -53
- package/package.json +3 -3
@@ -1,4 +1,4 @@
|
|
1
|
-
import { ComponentLiteral, Module } from '@textbus/core';
|
1
|
+
import { Component, ComponentInstance, ComponentLiteral, Module, Textbus } from '@textbus/core';
|
2
2
|
import { Provider } from '@viewfly/core';
|
3
3
|
import { AttributeLoader, ComponentLoader, FormatLoader } from './parser';
|
4
4
|
import { DomAdapter } from './dom-adapter';
|
@@ -17,8 +17,6 @@ export interface ViewOptions {
|
|
17
17
|
formatLoaders?: FormatLoader<any>[];
|
18
18
|
/** 属性加载器 */
|
19
19
|
attributeLoaders?: AttributeLoader<any>[];
|
20
|
-
/** 默认内容 */
|
21
|
-
content?: string | ComponentLiteral;
|
22
20
|
/** 使用 contentEditable 作为编辑器控制可编辑范围 */
|
23
21
|
useContentEditable?: boolean;
|
24
22
|
}
|
@@ -28,6 +26,21 @@ export declare class BrowserModule implements Module {
|
|
28
26
|
providers: Provider[];
|
29
27
|
private workbench;
|
30
28
|
constructor(host: HTMLElement, config: ViewOptions);
|
29
|
+
/**
|
30
|
+
* 解析 HTML 并返回一个组件实例
|
31
|
+
* @param html 要解析的 HTML
|
32
|
+
* @param rootComponentLoader 文档根组件加载器
|
33
|
+
* @param textbus
|
34
|
+
*/
|
35
|
+
readDocumentByHTML(html: string, rootComponentLoader: ComponentLoader, textbus: Textbus): ComponentInstance;
|
36
|
+
/**
|
37
|
+
* 将组件数据解析到组件实例中
|
38
|
+
* @param data 要解析的 JSON 数据
|
39
|
+
* @param rootComponent 根组件
|
40
|
+
* @param textbus
|
41
|
+
*/
|
42
|
+
readDocumentByComponentLiteral(data: ComponentLiteral, rootComponent: Component, textbus: Textbus): ComponentInstance;
|
43
|
+
onAfterStartup(textbus: Textbus): void;
|
31
44
|
onDestroy(): void;
|
32
45
|
private static createLayout;
|
33
46
|
}
|
package/bundles/index.esm.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import 'reflect-metadata';
|
2
|
-
import { Slot, Textbus, ViewAdapter, createBidirectionalMapping, ComponentInstance, VElement, VTextNode, Controller, Selection, RootComponentRef, ContentType, Event, invokeListener, Keyboard, Commander, Scheduler, NativeSelectionBridge, FocusManager } from '@textbus/core';
|
2
|
+
import { Slot, Textbus, ViewAdapter, createBidirectionalMapping, ComponentInstance, VElement, VTextNode, Controller, Selection, RootComponentRef, ContentType, Event, invokeListener, Keyboard, Commander, Scheduler, makeError, NativeSelectionBridge, FocusManager, Registry } from '@textbus/core';
|
3
3
|
import { Subject, filter, fromEvent, Subscription, distinctUntilChanged, merge, map, Observable } from '@tanbo/stream';
|
4
4
|
import { InjectionToken, Injectable, Inject, Optional } from '@viewfly/core';
|
5
5
|
|
@@ -375,26 +375,7 @@ class DomAdapter extends ViewAdapter {
|
|
375
375
|
return [];
|
376
376
|
}
|
377
377
|
const rootVNode = this.slotRootVElementCaches.get(slot);
|
378
|
-
|
379
|
-
if (vElement.location) {
|
380
|
-
result.push(nativeNode);
|
381
|
-
}
|
382
|
-
for (let i = 0; i < vElement.children.length; i++) {
|
383
|
-
const vChild = vElement.children[i];
|
384
|
-
const nativeChild = nativeNode.childNodes[i];
|
385
|
-
if (vChild instanceof VElement) {
|
386
|
-
getNodes(vChild, nativeChild, result);
|
387
|
-
}
|
388
|
-
else if (vChild instanceof VTextNode) {
|
389
|
-
result.push(nativeChild);
|
390
|
-
}
|
391
|
-
else {
|
392
|
-
result.push(this.getNativeNodeByComponent(vChild));
|
393
|
-
}
|
394
|
-
}
|
395
|
-
return result;
|
396
|
-
};
|
397
|
-
return getNodes(rootVNode, rootNativeNode, []);
|
378
|
+
return getNodes(this, rootVNode, rootNativeNode, []);
|
398
379
|
}
|
399
380
|
/**
|
400
381
|
* 获取原生节点的原始数据在文档中的位置
|
@@ -410,40 +391,59 @@ class DomAdapter extends ViewAdapter {
|
|
410
391
|
}
|
411
392
|
const slot = this.slotRootNativeElementCaches.get(slotRootNode);
|
412
393
|
const rootVNode = this.slotRootVElementCaches.get(slot);
|
413
|
-
const getLocation = (target, tree, vNodeTree) => {
|
414
|
-
if (target === tree) {
|
415
|
-
return Object.assign({}, vNodeTree.location);
|
416
|
-
}
|
417
|
-
const childNodes = tree.childNodes;
|
418
|
-
for (let i = 0; i < childNodes.length; i++) {
|
419
|
-
const child = vNodeTree.children[i];
|
420
|
-
const nativeChild = tree.childNodes[i];
|
421
|
-
if (nativeChild === target) {
|
422
|
-
if (child instanceof ComponentInstance) {
|
423
|
-
const index = child.parent.indexOf(child);
|
424
|
-
return {
|
425
|
-
slot: child.parent,
|
426
|
-
startIndex: index,
|
427
|
-
endIndex: index + 1
|
428
|
-
};
|
429
|
-
}
|
430
|
-
return child.location;
|
431
|
-
}
|
432
|
-
else if (child instanceof VElement) {
|
433
|
-
let r = null;
|
434
|
-
if (nativeChild.nodeType === Node.ELEMENT_NODE) {
|
435
|
-
r = getLocation(target, nativeChild, child);
|
436
|
-
}
|
437
|
-
if (r) {
|
438
|
-
return r;
|
439
|
-
}
|
440
|
-
}
|
441
|
-
}
|
442
|
-
return null;
|
443
|
-
};
|
444
394
|
return getLocation(node, slotRootNode, rootVNode);
|
445
395
|
}
|
446
396
|
}
|
397
|
+
function getNodes(adapter, vElement, nativeNode, result) {
|
398
|
+
if (vElement.location) {
|
399
|
+
result.push(nativeNode);
|
400
|
+
}
|
401
|
+
for (let i = 0; i < vElement.children.length; i++) {
|
402
|
+
const vChild = vElement.children[i];
|
403
|
+
const nativeChild = nativeNode.childNodes[i];
|
404
|
+
if (vChild instanceof VElement) {
|
405
|
+
getNodes(adapter, vChild, nativeChild, result);
|
406
|
+
}
|
407
|
+
else if (vChild instanceof VTextNode) {
|
408
|
+
result.push(nativeChild);
|
409
|
+
}
|
410
|
+
else {
|
411
|
+
result.push(adapter.getNativeNodeByComponent(vChild));
|
412
|
+
}
|
413
|
+
}
|
414
|
+
return result;
|
415
|
+
}
|
416
|
+
function getLocation(target, tree, vNodeTree) {
|
417
|
+
if (target === tree) {
|
418
|
+
return Object.assign({}, vNodeTree.location);
|
419
|
+
}
|
420
|
+
const childNodes = tree.childNodes;
|
421
|
+
for (let i = 0; i < childNodes.length; i++) {
|
422
|
+
const child = vNodeTree.children[i];
|
423
|
+
const nativeChild = tree.childNodes[i];
|
424
|
+
if (nativeChild === target) {
|
425
|
+
if (child instanceof ComponentInstance) {
|
426
|
+
const index = child.parent.indexOf(child);
|
427
|
+
return {
|
428
|
+
slot: child.parent,
|
429
|
+
startIndex: index,
|
430
|
+
endIndex: index + 1
|
431
|
+
};
|
432
|
+
}
|
433
|
+
return child.location;
|
434
|
+
}
|
435
|
+
else if (child instanceof VElement) {
|
436
|
+
let r = null;
|
437
|
+
if (nativeChild.nodeType === Node.ELEMENT_NODE) {
|
438
|
+
r = getLocation(target, nativeChild, child);
|
439
|
+
}
|
440
|
+
if (r) {
|
441
|
+
return r;
|
442
|
+
}
|
443
|
+
}
|
444
|
+
}
|
445
|
+
return null;
|
446
|
+
}
|
447
447
|
|
448
448
|
/**
|
449
449
|
* Textbus PC 端选区桥接实现
|
@@ -2041,8 +2041,8 @@ let NativeInput = class NativeInput extends Input {
|
|
2041
2041
|
});
|
2042
2042
|
}));
|
2043
2043
|
}
|
2044
|
-
handlePaste(
|
2045
|
-
const slot = this.parser.parse(
|
2044
|
+
handlePaste(dom, text) {
|
2045
|
+
const slot = this.parser.parse(dom, new Slot([
|
2046
2046
|
ContentType.BlockComponent,
|
2047
2047
|
ContentType.InlineComponent,
|
2048
2048
|
ContentType.Text
|
@@ -2295,6 +2295,7 @@ NativeInput = __decorate([
|
|
2295
2295
|
Controller])
|
2296
2296
|
], NativeInput);
|
2297
2297
|
|
2298
|
+
const browserErrorFn = makeError('BrowserModule');
|
2298
2299
|
class BrowserModule {
|
2299
2300
|
constructor(host, config) {
|
2300
2301
|
this.host = host;
|
@@ -2357,6 +2358,35 @@ class BrowserModule {
|
|
2357
2358
|
this.workbench = wrapper;
|
2358
2359
|
this.host.append(wrapper);
|
2359
2360
|
}
|
2361
|
+
/**
|
2362
|
+
* 解析 HTML 并返回一个组件实例
|
2363
|
+
* @param html 要解析的 HTML
|
2364
|
+
* @param rootComponentLoader 文档根组件加载器
|
2365
|
+
* @param textbus
|
2366
|
+
*/
|
2367
|
+
readDocumentByHTML(html, rootComponentLoader, textbus) {
|
2368
|
+
const parser = textbus.get(Parser);
|
2369
|
+
const doc = parser.parseDoc(html, rootComponentLoader);
|
2370
|
+
if (doc instanceof ComponentInstance) {
|
2371
|
+
return doc;
|
2372
|
+
}
|
2373
|
+
throw browserErrorFn('rootComponentLoader must return a component instance.');
|
2374
|
+
}
|
2375
|
+
/**
|
2376
|
+
* 将组件数据解析到组件实例中
|
2377
|
+
* @param data 要解析的 JSON 数据
|
2378
|
+
* @param rootComponent 根组件
|
2379
|
+
* @param textbus
|
2380
|
+
*/
|
2381
|
+
readDocumentByComponentLiteral(data, rootComponent, textbus) {
|
2382
|
+
const registry = textbus.get(Registry);
|
2383
|
+
return registry.createComponentByFactory(data, rootComponent);
|
2384
|
+
}
|
2385
|
+
onAfterStartup(textbus) {
|
2386
|
+
if (this.config.autoFocus) {
|
2387
|
+
textbus.focus();
|
2388
|
+
}
|
2389
|
+
}
|
2360
2390
|
onDestroy() {
|
2361
2391
|
this.workbench.remove();
|
2362
2392
|
}
|
package/bundles/index.js
CHANGED
@@ -377,26 +377,7 @@ class DomAdapter extends core$1.ViewAdapter {
|
|
377
377
|
return [];
|
378
378
|
}
|
379
379
|
const rootVNode = this.slotRootVElementCaches.get(slot);
|
380
|
-
|
381
|
-
if (vElement.location) {
|
382
|
-
result.push(nativeNode);
|
383
|
-
}
|
384
|
-
for (let i = 0; i < vElement.children.length; i++) {
|
385
|
-
const vChild = vElement.children[i];
|
386
|
-
const nativeChild = nativeNode.childNodes[i];
|
387
|
-
if (vChild instanceof core$1.VElement) {
|
388
|
-
getNodes(vChild, nativeChild, result);
|
389
|
-
}
|
390
|
-
else if (vChild instanceof core$1.VTextNode) {
|
391
|
-
result.push(nativeChild);
|
392
|
-
}
|
393
|
-
else {
|
394
|
-
result.push(this.getNativeNodeByComponent(vChild));
|
395
|
-
}
|
396
|
-
}
|
397
|
-
return result;
|
398
|
-
};
|
399
|
-
return getNodes(rootVNode, rootNativeNode, []);
|
380
|
+
return getNodes(this, rootVNode, rootNativeNode, []);
|
400
381
|
}
|
401
382
|
/**
|
402
383
|
* 获取原生节点的原始数据在文档中的位置
|
@@ -412,40 +393,59 @@ class DomAdapter extends core$1.ViewAdapter {
|
|
412
393
|
}
|
413
394
|
const slot = this.slotRootNativeElementCaches.get(slotRootNode);
|
414
395
|
const rootVNode = this.slotRootVElementCaches.get(slot);
|
415
|
-
const getLocation = (target, tree, vNodeTree) => {
|
416
|
-
if (target === tree) {
|
417
|
-
return Object.assign({}, vNodeTree.location);
|
418
|
-
}
|
419
|
-
const childNodes = tree.childNodes;
|
420
|
-
for (let i = 0; i < childNodes.length; i++) {
|
421
|
-
const child = vNodeTree.children[i];
|
422
|
-
const nativeChild = tree.childNodes[i];
|
423
|
-
if (nativeChild === target) {
|
424
|
-
if (child instanceof core$1.ComponentInstance) {
|
425
|
-
const index = child.parent.indexOf(child);
|
426
|
-
return {
|
427
|
-
slot: child.parent,
|
428
|
-
startIndex: index,
|
429
|
-
endIndex: index + 1
|
430
|
-
};
|
431
|
-
}
|
432
|
-
return child.location;
|
433
|
-
}
|
434
|
-
else if (child instanceof core$1.VElement) {
|
435
|
-
let r = null;
|
436
|
-
if (nativeChild.nodeType === Node.ELEMENT_NODE) {
|
437
|
-
r = getLocation(target, nativeChild, child);
|
438
|
-
}
|
439
|
-
if (r) {
|
440
|
-
return r;
|
441
|
-
}
|
442
|
-
}
|
443
|
-
}
|
444
|
-
return null;
|
445
|
-
};
|
446
396
|
return getLocation(node, slotRootNode, rootVNode);
|
447
397
|
}
|
448
398
|
}
|
399
|
+
function getNodes(adapter, vElement, nativeNode, result) {
|
400
|
+
if (vElement.location) {
|
401
|
+
result.push(nativeNode);
|
402
|
+
}
|
403
|
+
for (let i = 0; i < vElement.children.length; i++) {
|
404
|
+
const vChild = vElement.children[i];
|
405
|
+
const nativeChild = nativeNode.childNodes[i];
|
406
|
+
if (vChild instanceof core$1.VElement) {
|
407
|
+
getNodes(adapter, vChild, nativeChild, result);
|
408
|
+
}
|
409
|
+
else if (vChild instanceof core$1.VTextNode) {
|
410
|
+
result.push(nativeChild);
|
411
|
+
}
|
412
|
+
else {
|
413
|
+
result.push(adapter.getNativeNodeByComponent(vChild));
|
414
|
+
}
|
415
|
+
}
|
416
|
+
return result;
|
417
|
+
}
|
418
|
+
function getLocation(target, tree, vNodeTree) {
|
419
|
+
if (target === tree) {
|
420
|
+
return Object.assign({}, vNodeTree.location);
|
421
|
+
}
|
422
|
+
const childNodes = tree.childNodes;
|
423
|
+
for (let i = 0; i < childNodes.length; i++) {
|
424
|
+
const child = vNodeTree.children[i];
|
425
|
+
const nativeChild = tree.childNodes[i];
|
426
|
+
if (nativeChild === target) {
|
427
|
+
if (child instanceof core$1.ComponentInstance) {
|
428
|
+
const index = child.parent.indexOf(child);
|
429
|
+
return {
|
430
|
+
slot: child.parent,
|
431
|
+
startIndex: index,
|
432
|
+
endIndex: index + 1
|
433
|
+
};
|
434
|
+
}
|
435
|
+
return child.location;
|
436
|
+
}
|
437
|
+
else if (child instanceof core$1.VElement) {
|
438
|
+
let r = null;
|
439
|
+
if (nativeChild.nodeType === Node.ELEMENT_NODE) {
|
440
|
+
r = getLocation(target, nativeChild, child);
|
441
|
+
}
|
442
|
+
if (r) {
|
443
|
+
return r;
|
444
|
+
}
|
445
|
+
}
|
446
|
+
}
|
447
|
+
return null;
|
448
|
+
}
|
449
449
|
|
450
450
|
/**
|
451
451
|
* Textbus PC 端选区桥接实现
|
@@ -2043,8 +2043,8 @@ let NativeInput = class NativeInput extends Input {
|
|
2043
2043
|
});
|
2044
2044
|
}));
|
2045
2045
|
}
|
2046
|
-
handlePaste(
|
2047
|
-
const slot = this.parser.parse(
|
2046
|
+
handlePaste(dom, text) {
|
2047
|
+
const slot = this.parser.parse(dom, new core$1.Slot([
|
2048
2048
|
core$1.ContentType.BlockComponent,
|
2049
2049
|
core$1.ContentType.InlineComponent,
|
2050
2050
|
core$1.ContentType.Text
|
@@ -2297,6 +2297,7 @@ NativeInput = __decorate([
|
|
2297
2297
|
core$1.Controller])
|
2298
2298
|
], NativeInput);
|
2299
2299
|
|
2300
|
+
const browserErrorFn = core$1.makeError('BrowserModule');
|
2300
2301
|
class BrowserModule {
|
2301
2302
|
constructor(host, config) {
|
2302
2303
|
this.host = host;
|
@@ -2359,6 +2360,35 @@ class BrowserModule {
|
|
2359
2360
|
this.workbench = wrapper;
|
2360
2361
|
this.host.append(wrapper);
|
2361
2362
|
}
|
2363
|
+
/**
|
2364
|
+
* 解析 HTML 并返回一个组件实例
|
2365
|
+
* @param html 要解析的 HTML
|
2366
|
+
* @param rootComponentLoader 文档根组件加载器
|
2367
|
+
* @param textbus
|
2368
|
+
*/
|
2369
|
+
readDocumentByHTML(html, rootComponentLoader, textbus) {
|
2370
|
+
const parser = textbus.get(exports.Parser);
|
2371
|
+
const doc = parser.parseDoc(html, rootComponentLoader);
|
2372
|
+
if (doc instanceof core$1.ComponentInstance) {
|
2373
|
+
return doc;
|
2374
|
+
}
|
2375
|
+
throw browserErrorFn('rootComponentLoader must return a component instance.');
|
2376
|
+
}
|
2377
|
+
/**
|
2378
|
+
* 将组件数据解析到组件实例中
|
2379
|
+
* @param data 要解析的 JSON 数据
|
2380
|
+
* @param rootComponent 根组件
|
2381
|
+
* @param textbus
|
2382
|
+
*/
|
2383
|
+
readDocumentByComponentLiteral(data, rootComponent, textbus) {
|
2384
|
+
const registry = textbus.get(core$1.Registry);
|
2385
|
+
return registry.createComponentByFactory(data, rootComponent);
|
2386
|
+
}
|
2387
|
+
onAfterStartup(textbus) {
|
2388
|
+
if (this.config.autoFocus) {
|
2389
|
+
textbus.focus();
|
2390
|
+
}
|
2391
|
+
}
|
2362
2392
|
onDestroy() {
|
2363
2393
|
this.workbench.remove();
|
2364
2394
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@textbus/platform-browser",
|
3
|
-
"version": "4.0.0-alpha.
|
3
|
+
"version": "4.0.0-alpha.15",
|
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,7 +26,7 @@
|
|
26
26
|
],
|
27
27
|
"dependencies": {
|
28
28
|
"@tanbo/stream": "^1.2.0",
|
29
|
-
"@textbus/core": "^4.0.0-alpha.
|
29
|
+
"@textbus/core": "^4.0.0-alpha.15",
|
30
30
|
"@viewfly/core": "^0.3.0",
|
31
31
|
"reflect-metadata": "^0.1.13"
|
32
32
|
},
|
@@ -48,5 +48,5 @@
|
|
48
48
|
"bugs": {
|
49
49
|
"url": "https://github.com/textbus/textbus.git/issues"
|
50
50
|
},
|
51
|
-
"gitHead": "
|
51
|
+
"gitHead": "e3c96a118993009a8c4dce7e6504db02226f0da6"
|
52
52
|
}
|