@textbus/platform-browser 3.0.0-alpha.43 → 3.0.0-alpha.45
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/dom-support/parser.d.ts +1 -0
- package/bundles/index.esm.js +177 -169
- package/bundles/index.js +175 -168
- package/bundles/public-api.d.ts +0 -1
- package/bundles/viewer.d.ts +1 -0
- package/package.json +3 -3
- package/bundles/preset/_api.d.ts +0 -1
- package/bundles/preset/default-shortcut.d.ts +0 -5
package/bundles/index.esm.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import 'reflect-metadata';
|
2
2
|
import { InjectionToken, Injectable, Inject, Injector, Optional } from '@tanbo/di';
|
3
|
-
import { VTextNode, VElement, Controller, Selection, RootComponentRef, Renderer, Scheduler, Slot, ContentType, Keyboard, Commander,
|
3
|
+
import { VTextNode, VElement, Controller, Selection, RootComponentRef, Renderer, Scheduler, Slot, ContentType, Keyboard, Commander, makeError, Starter, NativeRenderer, NativeSelectionBridge, OutputRenderer, Registry, invokeListener, History } from '@textbus/core';
|
4
4
|
import { Subject, filter, fromEvent, Subscription, merge, map, Observable, distinctUntilChanged } from '@tanbo/stream';
|
5
5
|
|
6
6
|
function createElement(tagName, options = {}) {
|
@@ -1250,9 +1250,11 @@ let Parser = Parser_1 = class Parser {
|
|
1250
1250
|
}
|
1251
1251
|
parse(html, rootSlot) {
|
1252
1252
|
const element = Parser_1.parseHTML(html);
|
1253
|
-
|
1253
|
+
const formatItems = this.readFormats(element, rootSlot, []);
|
1254
|
+
this.applyFormats(rootSlot, formatItems);
|
1255
|
+
return rootSlot;
|
1254
1256
|
}
|
1255
|
-
readComponent(el, slot) {
|
1257
|
+
readComponent(el, slot, formatItems) {
|
1256
1258
|
if (el.nodeType === Node.ELEMENT_NODE) {
|
1257
1259
|
if (el.tagName === 'BR') {
|
1258
1260
|
slot.insert('\n');
|
@@ -1271,7 +1273,7 @@ let Parser = Parser_1 = class Parser {
|
|
1271
1273
|
return;
|
1272
1274
|
}
|
1273
1275
|
}
|
1274
|
-
this.readFormats(el, slot);
|
1276
|
+
this.readFormats(el, slot, formatItems);
|
1275
1277
|
}
|
1276
1278
|
else if (el.nodeType === Node.TEXT_NODE) {
|
1277
1279
|
const textContent = el.textContent;
|
@@ -1281,23 +1283,26 @@ let Parser = Parser_1 = class Parser {
|
|
1281
1283
|
slot.insert(textContent);
|
1282
1284
|
}
|
1283
1285
|
}
|
1284
|
-
readFormats(el, slot) {
|
1285
|
-
const
|
1286
|
-
this.formatLoaders.filter(f => {
|
1286
|
+
readFormats(el, slot, formatItems) {
|
1287
|
+
const formats = this.formatLoaders.filter(f => {
|
1287
1288
|
return f.match(el);
|
1288
|
-
}).
|
1289
|
-
|
1290
|
-
slot.applyFormat(v.formatter, {
|
1291
|
-
startIndex: 0,
|
1292
|
-
endIndex: slot.length,
|
1293
|
-
value: v.value
|
1294
|
-
});
|
1289
|
+
}).map(f => {
|
1290
|
+
return f.read(el);
|
1295
1291
|
});
|
1296
|
-
slot.
|
1292
|
+
const startIndex = slot.index;
|
1297
1293
|
Array.from(el.childNodes).forEach(child => {
|
1298
|
-
this.readComponent(child, slot);
|
1294
|
+
this.readComponent(child, slot, formatItems);
|
1299
1295
|
});
|
1300
|
-
|
1296
|
+
const endIndex = slot.index;
|
1297
|
+
formatItems.unshift(...formats.map(i => {
|
1298
|
+
return {
|
1299
|
+
formatter: i.formatter,
|
1300
|
+
value: i.value,
|
1301
|
+
startIndex,
|
1302
|
+
endIndex
|
1303
|
+
};
|
1304
|
+
}));
|
1305
|
+
return formatItems;
|
1301
1306
|
}
|
1302
1307
|
readSlot(childSlot, slotRootElement, slotContentElement) {
|
1303
1308
|
this.attributeLoaders.filter(a => {
|
@@ -1306,7 +1311,15 @@ let Parser = Parser_1 = class Parser {
|
|
1306
1311
|
const r = a.read(slotRootElement);
|
1307
1312
|
childSlot.setAttribute(r.attribute, r.value);
|
1308
1313
|
});
|
1309
|
-
|
1314
|
+
const childFormatItems = this.readFormats(slotContentElement, childSlot, []);
|
1315
|
+
this.applyFormats(childSlot, childFormatItems);
|
1316
|
+
return childSlot;
|
1317
|
+
}
|
1318
|
+
applyFormats(slot, formatItems) {
|
1319
|
+
formatItems.forEach(i => {
|
1320
|
+
slot.retain(i.startIndex);
|
1321
|
+
slot.retain(i.endIndex - i.startIndex, i.formatter, i.value, true);
|
1322
|
+
});
|
1310
1323
|
}
|
1311
1324
|
};
|
1312
1325
|
Parser = Parser_1 = __decorate([
|
@@ -2183,145 +2196,6 @@ OutputTranslator = OutputTranslator_1 = __decorate([
|
|
2183
2196
|
Injectable()
|
2184
2197
|
], OutputTranslator);
|
2185
2198
|
|
2186
|
-
/**
|
2187
|
-
* Textbus PC 端默认按键绑定
|
2188
|
-
*/
|
2189
|
-
function setDefaultShortcut(injector) {
|
2190
|
-
const selection = injector.get(Selection);
|
2191
|
-
const keyboard = injector.get(Keyboard);
|
2192
|
-
const history = injector.get(History);
|
2193
|
-
const commander = injector.get(Commander);
|
2194
|
-
keyboard.addShortcut({
|
2195
|
-
keymap: {
|
2196
|
-
key: 'Enter'
|
2197
|
-
},
|
2198
|
-
action: () => {
|
2199
|
-
commander.break();
|
2200
|
-
}
|
2201
|
-
});
|
2202
|
-
keyboard.addShortcut({
|
2203
|
-
keymap: {
|
2204
|
-
key: 'Enter',
|
2205
|
-
shiftKey: true
|
2206
|
-
},
|
2207
|
-
action: () => {
|
2208
|
-
const startOffset = selection.startOffset;
|
2209
|
-
const startSlot = selection.startSlot;
|
2210
|
-
const isToEnd = startOffset === startSlot.length || startSlot.isEmpty;
|
2211
|
-
const content = isToEnd ? '\n\n' : '\n';
|
2212
|
-
const isInserted = commander.insert(content);
|
2213
|
-
if (isInserted && isToEnd) {
|
2214
|
-
selection.setPosition(startSlot, startOffset + 1);
|
2215
|
-
}
|
2216
|
-
}
|
2217
|
-
});
|
2218
|
-
keyboard.addShortcut({
|
2219
|
-
keymap: {
|
2220
|
-
key: ['Delete', 'Backspace']
|
2221
|
-
},
|
2222
|
-
action: (key) => {
|
2223
|
-
commander.delete(key === 'Backspace');
|
2224
|
-
}
|
2225
|
-
});
|
2226
|
-
keyboard.addShortcut({
|
2227
|
-
keymap: {
|
2228
|
-
key: ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown']
|
2229
|
-
},
|
2230
|
-
action: (key) => {
|
2231
|
-
switch (key) {
|
2232
|
-
case 'ArrowLeft':
|
2233
|
-
selection.toPrevious();
|
2234
|
-
break;
|
2235
|
-
case 'ArrowRight':
|
2236
|
-
selection.toNext();
|
2237
|
-
break;
|
2238
|
-
case 'ArrowUp':
|
2239
|
-
selection.toPreviousLine();
|
2240
|
-
break;
|
2241
|
-
case 'ArrowDown':
|
2242
|
-
selection.toNextLine();
|
2243
|
-
break;
|
2244
|
-
}
|
2245
|
-
}
|
2246
|
-
});
|
2247
|
-
keyboard.addShortcut({
|
2248
|
-
keymap: {
|
2249
|
-
key: ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'],
|
2250
|
-
shiftKey: true
|
2251
|
-
},
|
2252
|
-
action: (key) => {
|
2253
|
-
switch (key) {
|
2254
|
-
case 'ArrowLeft':
|
2255
|
-
selection.wrapToBefore();
|
2256
|
-
break;
|
2257
|
-
case 'ArrowRight':
|
2258
|
-
selection.wrapToAfter();
|
2259
|
-
break;
|
2260
|
-
case 'ArrowUp':
|
2261
|
-
selection.wrapToPreviousLine();
|
2262
|
-
break;
|
2263
|
-
case 'ArrowDown':
|
2264
|
-
selection.wrapToNextLine();
|
2265
|
-
break;
|
2266
|
-
}
|
2267
|
-
}
|
2268
|
-
});
|
2269
|
-
keyboard.addShortcut({
|
2270
|
-
keymap: {
|
2271
|
-
key: 'Tab'
|
2272
|
-
},
|
2273
|
-
action: () => {
|
2274
|
-
commander.insert(' ');
|
2275
|
-
}
|
2276
|
-
});
|
2277
|
-
keyboard.addShortcut({
|
2278
|
-
keymap: {
|
2279
|
-
key: 'a',
|
2280
|
-
ctrlKey: true
|
2281
|
-
},
|
2282
|
-
action: () => {
|
2283
|
-
selection.selectAll();
|
2284
|
-
}
|
2285
|
-
});
|
2286
|
-
keyboard.addShortcut({
|
2287
|
-
keymap: {
|
2288
|
-
key: 'c',
|
2289
|
-
ctrlKey: true
|
2290
|
-
},
|
2291
|
-
action: () => {
|
2292
|
-
commander.copy();
|
2293
|
-
}
|
2294
|
-
});
|
2295
|
-
keyboard.addShortcut({
|
2296
|
-
keymap: {
|
2297
|
-
key: 'x',
|
2298
|
-
ctrlKey: true
|
2299
|
-
},
|
2300
|
-
action: () => {
|
2301
|
-
commander.cut();
|
2302
|
-
}
|
2303
|
-
});
|
2304
|
-
keyboard.addShortcut({
|
2305
|
-
keymap: {
|
2306
|
-
key: 'z',
|
2307
|
-
ctrlKey: true
|
2308
|
-
},
|
2309
|
-
action: () => {
|
2310
|
-
history.back();
|
2311
|
-
}
|
2312
|
-
});
|
2313
|
-
keyboard.addShortcut({
|
2314
|
-
keymap: {
|
2315
|
-
key: 'z',
|
2316
|
-
ctrlKey: true,
|
2317
|
-
shiftKey: true
|
2318
|
-
},
|
2319
|
-
action: () => {
|
2320
|
-
history.forward();
|
2321
|
-
}
|
2322
|
-
});
|
2323
|
-
}
|
2324
|
-
|
2325
2199
|
const editorError = makeError('CoreEditor');
|
2326
2200
|
/**
|
2327
2201
|
* Textbus PC 端编辑器
|
@@ -2416,17 +2290,7 @@ class Viewer extends Starter {
|
|
2416
2290
|
const parser = this.get(Parser);
|
2417
2291
|
const registry = this.get(Registry);
|
2418
2292
|
const doc = this.get(VIEW_DOCUMENT);
|
2419
|
-
|
2420
|
-
keyboard.addShortcut({
|
2421
|
-
keymap: {
|
2422
|
-
key: 's',
|
2423
|
-
ctrlKey: true
|
2424
|
-
},
|
2425
|
-
action: () => {
|
2426
|
-
this.saveEvent.next();
|
2427
|
-
}
|
2428
|
-
});
|
2429
|
-
setDefaultShortcut(this);
|
2293
|
+
this.initDefaultShortcut();
|
2430
2294
|
let component;
|
2431
2295
|
const content = this.options.content;
|
2432
2296
|
if (content) {
|
@@ -2575,6 +2439,150 @@ class Viewer extends Starter {
|
|
2575
2439
|
throw editorError('please wait for the editor to initialize before getting the content!');
|
2576
2440
|
}
|
2577
2441
|
}
|
2442
|
+
initDefaultShortcut() {
|
2443
|
+
const selection = this.get(Selection);
|
2444
|
+
const keyboard = this.get(Keyboard);
|
2445
|
+
const history = this.get(History);
|
2446
|
+
const commander = this.get(Commander);
|
2447
|
+
keyboard.addShortcut({
|
2448
|
+
keymap: {
|
2449
|
+
key: 's',
|
2450
|
+
ctrlKey: true
|
2451
|
+
},
|
2452
|
+
action: () => {
|
2453
|
+
this.saveEvent.next();
|
2454
|
+
}
|
2455
|
+
});
|
2456
|
+
keyboard.addShortcut({
|
2457
|
+
keymap: {
|
2458
|
+
key: 'Enter'
|
2459
|
+
},
|
2460
|
+
action: () => {
|
2461
|
+
commander.break();
|
2462
|
+
}
|
2463
|
+
});
|
2464
|
+
keyboard.addShortcut({
|
2465
|
+
keymap: {
|
2466
|
+
key: 'Enter',
|
2467
|
+
shiftKey: true
|
2468
|
+
},
|
2469
|
+
action: () => {
|
2470
|
+
const startOffset = selection.startOffset;
|
2471
|
+
const startSlot = selection.startSlot;
|
2472
|
+
const isToEnd = startOffset === startSlot.length || startSlot.isEmpty;
|
2473
|
+
const content = isToEnd ? '\n\n' : '\n';
|
2474
|
+
const isInserted = commander.insert(content);
|
2475
|
+
if (isInserted && isToEnd) {
|
2476
|
+
selection.setPosition(startSlot, startOffset + 1);
|
2477
|
+
}
|
2478
|
+
}
|
2479
|
+
});
|
2480
|
+
keyboard.addShortcut({
|
2481
|
+
keymap: {
|
2482
|
+
key: ['Delete', 'Backspace']
|
2483
|
+
},
|
2484
|
+
action: (key) => {
|
2485
|
+
commander.delete(key === 'Backspace');
|
2486
|
+
}
|
2487
|
+
});
|
2488
|
+
keyboard.addShortcut({
|
2489
|
+
keymap: {
|
2490
|
+
key: ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown']
|
2491
|
+
},
|
2492
|
+
action: (key) => {
|
2493
|
+
switch (key) {
|
2494
|
+
case 'ArrowLeft':
|
2495
|
+
selection.toPrevious();
|
2496
|
+
break;
|
2497
|
+
case 'ArrowRight':
|
2498
|
+
selection.toNext();
|
2499
|
+
break;
|
2500
|
+
case 'ArrowUp':
|
2501
|
+
selection.toPreviousLine();
|
2502
|
+
break;
|
2503
|
+
case 'ArrowDown':
|
2504
|
+
selection.toNextLine();
|
2505
|
+
break;
|
2506
|
+
}
|
2507
|
+
}
|
2508
|
+
});
|
2509
|
+
keyboard.addShortcut({
|
2510
|
+
keymap: {
|
2511
|
+
key: ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'],
|
2512
|
+
shiftKey: true
|
2513
|
+
},
|
2514
|
+
action: (key) => {
|
2515
|
+
switch (key) {
|
2516
|
+
case 'ArrowLeft':
|
2517
|
+
selection.wrapToBefore();
|
2518
|
+
break;
|
2519
|
+
case 'ArrowRight':
|
2520
|
+
selection.wrapToAfter();
|
2521
|
+
break;
|
2522
|
+
case 'ArrowUp':
|
2523
|
+
selection.wrapToPreviousLine();
|
2524
|
+
break;
|
2525
|
+
case 'ArrowDown':
|
2526
|
+
selection.wrapToNextLine();
|
2527
|
+
break;
|
2528
|
+
}
|
2529
|
+
}
|
2530
|
+
});
|
2531
|
+
keyboard.addShortcut({
|
2532
|
+
keymap: {
|
2533
|
+
key: 'Tab'
|
2534
|
+
},
|
2535
|
+
action: () => {
|
2536
|
+
commander.insert(' ');
|
2537
|
+
}
|
2538
|
+
});
|
2539
|
+
keyboard.addShortcut({
|
2540
|
+
keymap: {
|
2541
|
+
key: 'a',
|
2542
|
+
ctrlKey: true
|
2543
|
+
},
|
2544
|
+
action: () => {
|
2545
|
+
selection.selectAll();
|
2546
|
+
}
|
2547
|
+
});
|
2548
|
+
keyboard.addShortcut({
|
2549
|
+
keymap: {
|
2550
|
+
key: 'c',
|
2551
|
+
ctrlKey: true
|
2552
|
+
},
|
2553
|
+
action: () => {
|
2554
|
+
commander.copy();
|
2555
|
+
}
|
2556
|
+
});
|
2557
|
+
keyboard.addShortcut({
|
2558
|
+
keymap: {
|
2559
|
+
key: 'x',
|
2560
|
+
ctrlKey: true
|
2561
|
+
},
|
2562
|
+
action: () => {
|
2563
|
+
commander.cut();
|
2564
|
+
}
|
2565
|
+
});
|
2566
|
+
keyboard.addShortcut({
|
2567
|
+
keymap: {
|
2568
|
+
key: 'z',
|
2569
|
+
ctrlKey: true
|
2570
|
+
},
|
2571
|
+
action: () => {
|
2572
|
+
history.back();
|
2573
|
+
}
|
2574
|
+
});
|
2575
|
+
keyboard.addShortcut({
|
2576
|
+
keymap: {
|
2577
|
+
key: 'z',
|
2578
|
+
ctrlKey: true,
|
2579
|
+
shiftKey: true
|
2580
|
+
},
|
2581
|
+
action: () => {
|
2582
|
+
history.forward();
|
2583
|
+
}
|
2584
|
+
});
|
2585
|
+
}
|
2578
2586
|
initDocStyleSheetsAndScripts(options) {
|
2579
2587
|
var _a;
|
2580
2588
|
const loaders = [];
|
@@ -2674,4 +2682,4 @@ class Viewer extends Starter {
|
|
2674
2682
|
}
|
2675
2683
|
}
|
2676
2684
|
|
2677
|
-
export { CollaborateCursor, CollaborateSelectionAwarenessDelegate, DomRenderer, EDITOR_OPTIONS, Input, MagicInput, NativeInput, OutputTranslator, Parser, SelectionBridge, VIEW_CONTAINER, VIEW_DOCUMENT, VIEW_MASK, Viewer, createElement, createTextNode, getLayoutRectByRange, isMac, isSafari, isWindows
|
2685
|
+
export { CollaborateCursor, CollaborateSelectionAwarenessDelegate, DomRenderer, EDITOR_OPTIONS, Input, MagicInput, NativeInput, OutputTranslator, Parser, SelectionBridge, VIEW_CONTAINER, VIEW_DOCUMENT, VIEW_MASK, Viewer, createElement, createTextNode, getLayoutRectByRange, isMac, isSafari, isWindows };
|
package/bundles/index.js
CHANGED
@@ -1252,9 +1252,11 @@ exports.Parser = Parser_1 = class Parser {
|
|
1252
1252
|
}
|
1253
1253
|
parse(html, rootSlot) {
|
1254
1254
|
const element = Parser_1.parseHTML(html);
|
1255
|
-
|
1255
|
+
const formatItems = this.readFormats(element, rootSlot, []);
|
1256
|
+
this.applyFormats(rootSlot, formatItems);
|
1257
|
+
return rootSlot;
|
1256
1258
|
}
|
1257
|
-
readComponent(el, slot) {
|
1259
|
+
readComponent(el, slot, formatItems) {
|
1258
1260
|
if (el.nodeType === Node.ELEMENT_NODE) {
|
1259
1261
|
if (el.tagName === 'BR') {
|
1260
1262
|
slot.insert('\n');
|
@@ -1273,7 +1275,7 @@ exports.Parser = Parser_1 = class Parser {
|
|
1273
1275
|
return;
|
1274
1276
|
}
|
1275
1277
|
}
|
1276
|
-
this.readFormats(el, slot);
|
1278
|
+
this.readFormats(el, slot, formatItems);
|
1277
1279
|
}
|
1278
1280
|
else if (el.nodeType === Node.TEXT_NODE) {
|
1279
1281
|
const textContent = el.textContent;
|
@@ -1283,23 +1285,26 @@ exports.Parser = Parser_1 = class Parser {
|
|
1283
1285
|
slot.insert(textContent);
|
1284
1286
|
}
|
1285
1287
|
}
|
1286
|
-
readFormats(el, slot) {
|
1287
|
-
const
|
1288
|
-
this.formatLoaders.filter(f => {
|
1288
|
+
readFormats(el, slot, formatItems) {
|
1289
|
+
const formats = this.formatLoaders.filter(f => {
|
1289
1290
|
return f.match(el);
|
1290
|
-
}).
|
1291
|
-
|
1292
|
-
slot.applyFormat(v.formatter, {
|
1293
|
-
startIndex: 0,
|
1294
|
-
endIndex: slot.length,
|
1295
|
-
value: v.value
|
1296
|
-
});
|
1291
|
+
}).map(f => {
|
1292
|
+
return f.read(el);
|
1297
1293
|
});
|
1298
|
-
slot.
|
1294
|
+
const startIndex = slot.index;
|
1299
1295
|
Array.from(el.childNodes).forEach(child => {
|
1300
|
-
this.readComponent(child, slot);
|
1296
|
+
this.readComponent(child, slot, formatItems);
|
1301
1297
|
});
|
1302
|
-
|
1298
|
+
const endIndex = slot.index;
|
1299
|
+
formatItems.unshift(...formats.map(i => {
|
1300
|
+
return {
|
1301
|
+
formatter: i.formatter,
|
1302
|
+
value: i.value,
|
1303
|
+
startIndex,
|
1304
|
+
endIndex
|
1305
|
+
};
|
1306
|
+
}));
|
1307
|
+
return formatItems;
|
1303
1308
|
}
|
1304
1309
|
readSlot(childSlot, slotRootElement, slotContentElement) {
|
1305
1310
|
this.attributeLoaders.filter(a => {
|
@@ -1308,7 +1313,15 @@ exports.Parser = Parser_1 = class Parser {
|
|
1308
1313
|
const r = a.read(slotRootElement);
|
1309
1314
|
childSlot.setAttribute(r.attribute, r.value);
|
1310
1315
|
});
|
1311
|
-
|
1316
|
+
const childFormatItems = this.readFormats(slotContentElement, childSlot, []);
|
1317
|
+
this.applyFormats(childSlot, childFormatItems);
|
1318
|
+
return childSlot;
|
1319
|
+
}
|
1320
|
+
applyFormats(slot, formatItems) {
|
1321
|
+
formatItems.forEach(i => {
|
1322
|
+
slot.retain(i.startIndex);
|
1323
|
+
slot.retain(i.endIndex - i.startIndex, i.formatter, i.value, true);
|
1324
|
+
});
|
1312
1325
|
}
|
1313
1326
|
};
|
1314
1327
|
exports.Parser = Parser_1 = __decorate([
|
@@ -2185,145 +2198,6 @@ exports.OutputTranslator = OutputTranslator_1 = __decorate([
|
|
2185
2198
|
di.Injectable()
|
2186
2199
|
], exports.OutputTranslator);
|
2187
2200
|
|
2188
|
-
/**
|
2189
|
-
* Textbus PC 端默认按键绑定
|
2190
|
-
*/
|
2191
|
-
function setDefaultShortcut(injector) {
|
2192
|
-
const selection = injector.get(core.Selection);
|
2193
|
-
const keyboard = injector.get(core.Keyboard);
|
2194
|
-
const history = injector.get(core.History);
|
2195
|
-
const commander = injector.get(core.Commander);
|
2196
|
-
keyboard.addShortcut({
|
2197
|
-
keymap: {
|
2198
|
-
key: 'Enter'
|
2199
|
-
},
|
2200
|
-
action: () => {
|
2201
|
-
commander.break();
|
2202
|
-
}
|
2203
|
-
});
|
2204
|
-
keyboard.addShortcut({
|
2205
|
-
keymap: {
|
2206
|
-
key: 'Enter',
|
2207
|
-
shiftKey: true
|
2208
|
-
},
|
2209
|
-
action: () => {
|
2210
|
-
const startOffset = selection.startOffset;
|
2211
|
-
const startSlot = selection.startSlot;
|
2212
|
-
const isToEnd = startOffset === startSlot.length || startSlot.isEmpty;
|
2213
|
-
const content = isToEnd ? '\n\n' : '\n';
|
2214
|
-
const isInserted = commander.insert(content);
|
2215
|
-
if (isInserted && isToEnd) {
|
2216
|
-
selection.setPosition(startSlot, startOffset + 1);
|
2217
|
-
}
|
2218
|
-
}
|
2219
|
-
});
|
2220
|
-
keyboard.addShortcut({
|
2221
|
-
keymap: {
|
2222
|
-
key: ['Delete', 'Backspace']
|
2223
|
-
},
|
2224
|
-
action: (key) => {
|
2225
|
-
commander.delete(key === 'Backspace');
|
2226
|
-
}
|
2227
|
-
});
|
2228
|
-
keyboard.addShortcut({
|
2229
|
-
keymap: {
|
2230
|
-
key: ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown']
|
2231
|
-
},
|
2232
|
-
action: (key) => {
|
2233
|
-
switch (key) {
|
2234
|
-
case 'ArrowLeft':
|
2235
|
-
selection.toPrevious();
|
2236
|
-
break;
|
2237
|
-
case 'ArrowRight':
|
2238
|
-
selection.toNext();
|
2239
|
-
break;
|
2240
|
-
case 'ArrowUp':
|
2241
|
-
selection.toPreviousLine();
|
2242
|
-
break;
|
2243
|
-
case 'ArrowDown':
|
2244
|
-
selection.toNextLine();
|
2245
|
-
break;
|
2246
|
-
}
|
2247
|
-
}
|
2248
|
-
});
|
2249
|
-
keyboard.addShortcut({
|
2250
|
-
keymap: {
|
2251
|
-
key: ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'],
|
2252
|
-
shiftKey: true
|
2253
|
-
},
|
2254
|
-
action: (key) => {
|
2255
|
-
switch (key) {
|
2256
|
-
case 'ArrowLeft':
|
2257
|
-
selection.wrapToBefore();
|
2258
|
-
break;
|
2259
|
-
case 'ArrowRight':
|
2260
|
-
selection.wrapToAfter();
|
2261
|
-
break;
|
2262
|
-
case 'ArrowUp':
|
2263
|
-
selection.wrapToPreviousLine();
|
2264
|
-
break;
|
2265
|
-
case 'ArrowDown':
|
2266
|
-
selection.wrapToNextLine();
|
2267
|
-
break;
|
2268
|
-
}
|
2269
|
-
}
|
2270
|
-
});
|
2271
|
-
keyboard.addShortcut({
|
2272
|
-
keymap: {
|
2273
|
-
key: 'Tab'
|
2274
|
-
},
|
2275
|
-
action: () => {
|
2276
|
-
commander.insert(' ');
|
2277
|
-
}
|
2278
|
-
});
|
2279
|
-
keyboard.addShortcut({
|
2280
|
-
keymap: {
|
2281
|
-
key: 'a',
|
2282
|
-
ctrlKey: true
|
2283
|
-
},
|
2284
|
-
action: () => {
|
2285
|
-
selection.selectAll();
|
2286
|
-
}
|
2287
|
-
});
|
2288
|
-
keyboard.addShortcut({
|
2289
|
-
keymap: {
|
2290
|
-
key: 'c',
|
2291
|
-
ctrlKey: true
|
2292
|
-
},
|
2293
|
-
action: () => {
|
2294
|
-
commander.copy();
|
2295
|
-
}
|
2296
|
-
});
|
2297
|
-
keyboard.addShortcut({
|
2298
|
-
keymap: {
|
2299
|
-
key: 'x',
|
2300
|
-
ctrlKey: true
|
2301
|
-
},
|
2302
|
-
action: () => {
|
2303
|
-
commander.cut();
|
2304
|
-
}
|
2305
|
-
});
|
2306
|
-
keyboard.addShortcut({
|
2307
|
-
keymap: {
|
2308
|
-
key: 'z',
|
2309
|
-
ctrlKey: true
|
2310
|
-
},
|
2311
|
-
action: () => {
|
2312
|
-
history.back();
|
2313
|
-
}
|
2314
|
-
});
|
2315
|
-
keyboard.addShortcut({
|
2316
|
-
keymap: {
|
2317
|
-
key: 'z',
|
2318
|
-
ctrlKey: true,
|
2319
|
-
shiftKey: true
|
2320
|
-
},
|
2321
|
-
action: () => {
|
2322
|
-
history.forward();
|
2323
|
-
}
|
2324
|
-
});
|
2325
|
-
}
|
2326
|
-
|
2327
2201
|
const editorError = core.makeError('CoreEditor');
|
2328
2202
|
/**
|
2329
2203
|
* Textbus PC 端编辑器
|
@@ -2418,17 +2292,7 @@ class Viewer extends core.Starter {
|
|
2418
2292
|
const parser = this.get(exports.Parser);
|
2419
2293
|
const registry = this.get(core.Registry);
|
2420
2294
|
const doc = this.get(VIEW_DOCUMENT);
|
2421
|
-
|
2422
|
-
keyboard.addShortcut({
|
2423
|
-
keymap: {
|
2424
|
-
key: 's',
|
2425
|
-
ctrlKey: true
|
2426
|
-
},
|
2427
|
-
action: () => {
|
2428
|
-
this.saveEvent.next();
|
2429
|
-
}
|
2430
|
-
});
|
2431
|
-
setDefaultShortcut(this);
|
2295
|
+
this.initDefaultShortcut();
|
2432
2296
|
let component;
|
2433
2297
|
const content = this.options.content;
|
2434
2298
|
if (content) {
|
@@ -2577,6 +2441,150 @@ class Viewer extends core.Starter {
|
|
2577
2441
|
throw editorError('please wait for the editor to initialize before getting the content!');
|
2578
2442
|
}
|
2579
2443
|
}
|
2444
|
+
initDefaultShortcut() {
|
2445
|
+
const selection = this.get(core.Selection);
|
2446
|
+
const keyboard = this.get(core.Keyboard);
|
2447
|
+
const history = this.get(core.History);
|
2448
|
+
const commander = this.get(core.Commander);
|
2449
|
+
keyboard.addShortcut({
|
2450
|
+
keymap: {
|
2451
|
+
key: 's',
|
2452
|
+
ctrlKey: true
|
2453
|
+
},
|
2454
|
+
action: () => {
|
2455
|
+
this.saveEvent.next();
|
2456
|
+
}
|
2457
|
+
});
|
2458
|
+
keyboard.addShortcut({
|
2459
|
+
keymap: {
|
2460
|
+
key: 'Enter'
|
2461
|
+
},
|
2462
|
+
action: () => {
|
2463
|
+
commander.break();
|
2464
|
+
}
|
2465
|
+
});
|
2466
|
+
keyboard.addShortcut({
|
2467
|
+
keymap: {
|
2468
|
+
key: 'Enter',
|
2469
|
+
shiftKey: true
|
2470
|
+
},
|
2471
|
+
action: () => {
|
2472
|
+
const startOffset = selection.startOffset;
|
2473
|
+
const startSlot = selection.startSlot;
|
2474
|
+
const isToEnd = startOffset === startSlot.length || startSlot.isEmpty;
|
2475
|
+
const content = isToEnd ? '\n\n' : '\n';
|
2476
|
+
const isInserted = commander.insert(content);
|
2477
|
+
if (isInserted && isToEnd) {
|
2478
|
+
selection.setPosition(startSlot, startOffset + 1);
|
2479
|
+
}
|
2480
|
+
}
|
2481
|
+
});
|
2482
|
+
keyboard.addShortcut({
|
2483
|
+
keymap: {
|
2484
|
+
key: ['Delete', 'Backspace']
|
2485
|
+
},
|
2486
|
+
action: (key) => {
|
2487
|
+
commander.delete(key === 'Backspace');
|
2488
|
+
}
|
2489
|
+
});
|
2490
|
+
keyboard.addShortcut({
|
2491
|
+
keymap: {
|
2492
|
+
key: ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown']
|
2493
|
+
},
|
2494
|
+
action: (key) => {
|
2495
|
+
switch (key) {
|
2496
|
+
case 'ArrowLeft':
|
2497
|
+
selection.toPrevious();
|
2498
|
+
break;
|
2499
|
+
case 'ArrowRight':
|
2500
|
+
selection.toNext();
|
2501
|
+
break;
|
2502
|
+
case 'ArrowUp':
|
2503
|
+
selection.toPreviousLine();
|
2504
|
+
break;
|
2505
|
+
case 'ArrowDown':
|
2506
|
+
selection.toNextLine();
|
2507
|
+
break;
|
2508
|
+
}
|
2509
|
+
}
|
2510
|
+
});
|
2511
|
+
keyboard.addShortcut({
|
2512
|
+
keymap: {
|
2513
|
+
key: ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'],
|
2514
|
+
shiftKey: true
|
2515
|
+
},
|
2516
|
+
action: (key) => {
|
2517
|
+
switch (key) {
|
2518
|
+
case 'ArrowLeft':
|
2519
|
+
selection.wrapToBefore();
|
2520
|
+
break;
|
2521
|
+
case 'ArrowRight':
|
2522
|
+
selection.wrapToAfter();
|
2523
|
+
break;
|
2524
|
+
case 'ArrowUp':
|
2525
|
+
selection.wrapToPreviousLine();
|
2526
|
+
break;
|
2527
|
+
case 'ArrowDown':
|
2528
|
+
selection.wrapToNextLine();
|
2529
|
+
break;
|
2530
|
+
}
|
2531
|
+
}
|
2532
|
+
});
|
2533
|
+
keyboard.addShortcut({
|
2534
|
+
keymap: {
|
2535
|
+
key: 'Tab'
|
2536
|
+
},
|
2537
|
+
action: () => {
|
2538
|
+
commander.insert(' ');
|
2539
|
+
}
|
2540
|
+
});
|
2541
|
+
keyboard.addShortcut({
|
2542
|
+
keymap: {
|
2543
|
+
key: 'a',
|
2544
|
+
ctrlKey: true
|
2545
|
+
},
|
2546
|
+
action: () => {
|
2547
|
+
selection.selectAll();
|
2548
|
+
}
|
2549
|
+
});
|
2550
|
+
keyboard.addShortcut({
|
2551
|
+
keymap: {
|
2552
|
+
key: 'c',
|
2553
|
+
ctrlKey: true
|
2554
|
+
},
|
2555
|
+
action: () => {
|
2556
|
+
commander.copy();
|
2557
|
+
}
|
2558
|
+
});
|
2559
|
+
keyboard.addShortcut({
|
2560
|
+
keymap: {
|
2561
|
+
key: 'x',
|
2562
|
+
ctrlKey: true
|
2563
|
+
},
|
2564
|
+
action: () => {
|
2565
|
+
commander.cut();
|
2566
|
+
}
|
2567
|
+
});
|
2568
|
+
keyboard.addShortcut({
|
2569
|
+
keymap: {
|
2570
|
+
key: 'z',
|
2571
|
+
ctrlKey: true
|
2572
|
+
},
|
2573
|
+
action: () => {
|
2574
|
+
history.back();
|
2575
|
+
}
|
2576
|
+
});
|
2577
|
+
keyboard.addShortcut({
|
2578
|
+
keymap: {
|
2579
|
+
key: 'z',
|
2580
|
+
ctrlKey: true,
|
2581
|
+
shiftKey: true
|
2582
|
+
},
|
2583
|
+
action: () => {
|
2584
|
+
history.forward();
|
2585
|
+
}
|
2586
|
+
});
|
2587
|
+
}
|
2580
2588
|
initDocStyleSheetsAndScripts(options) {
|
2581
2589
|
var _a;
|
2582
2590
|
const loaders = [];
|
@@ -2689,4 +2697,3 @@ exports.getLayoutRectByRange = getLayoutRectByRange;
|
|
2689
2697
|
exports.isMac = isMac;
|
2690
2698
|
exports.isSafari = isSafari;
|
2691
2699
|
exports.isWindows = isWindows;
|
2692
|
-
exports.setDefaultShortcut = setDefaultShortcut;
|
package/bundles/public-api.d.ts
CHANGED
package/bundles/viewer.d.ts
CHANGED
@@ -84,6 +84,7 @@ export declare class Viewer extends Starter {
|
|
84
84
|
*/
|
85
85
|
replaceContent(content: string | ComponentLiteral): void;
|
86
86
|
protected guardReady(): void;
|
87
|
+
private initDefaultShortcut;
|
87
88
|
private initDocStyleSheetsAndScripts;
|
88
89
|
private static createLayout;
|
89
90
|
private static cssMin;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@textbus/platform-browser",
|
3
|
-
"version": "3.0.0-alpha.
|
3
|
+
"version": "3.0.0-alpha.45",
|
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",
|
@@ -27,7 +27,7 @@
|
|
27
27
|
"dependencies": {
|
28
28
|
"@tanbo/di": "^1.1.4",
|
29
29
|
"@tanbo/stream": "^1.1.8",
|
30
|
-
"@textbus/core": "^3.0.0-alpha.
|
30
|
+
"@textbus/core": "^3.0.0-alpha.45",
|
31
31
|
"reflect-metadata": "^0.1.13"
|
32
32
|
},
|
33
33
|
"devDependencies": {
|
@@ -48,5 +48,5 @@
|
|
48
48
|
"bugs": {
|
49
49
|
"url": "https://github.com/textbus/textbus.git/issues"
|
50
50
|
},
|
51
|
-
"gitHead": "
|
51
|
+
"gitHead": "d97dc3e2605dce64f15f2c75904f17a100f35ab7"
|
52
52
|
}
|
package/bundles/preset/_api.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export * from './default-shortcut';
|