@ones-editor/editor 2.2.16-beta.1 → 2.2.16-beta.2
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/index.js
CHANGED
|
@@ -25882,25 +25882,97 @@ var __publicField = (obj, key, value) => {
|
|
|
25882
25882
|
offset
|
|
25883
25883
|
};
|
|
25884
25884
|
}
|
|
25885
|
+
class BlockAttributesHandler {
|
|
25886
|
+
constructor(editor) {
|
|
25887
|
+
__publicField(this, "textBlockAttributes", /* @__PURE__ */ new Map());
|
|
25888
|
+
__publicField(this, "activeBlockAttributes", /* @__PURE__ */ new Map());
|
|
25889
|
+
__publicField(this, "lastRange");
|
|
25890
|
+
__publicField(this, "clear", () => {
|
|
25891
|
+
this.activeBlockAttributes.clear();
|
|
25892
|
+
});
|
|
25893
|
+
__publicField(this, "handleSelectionChanged", () => {
|
|
25894
|
+
var _a, _b, _c, _d;
|
|
25895
|
+
const range = this.editor.selection.range;
|
|
25896
|
+
if (range.isSimple() && ((_a = this.lastRange) == null ? void 0 : _a.start.blockId) === range.start.blockId && ((_b = this.lastRange) == null ? void 0 : _b.end.blockId) === range.end.blockId && ((_c = this.lastRange) == null ? void 0 : _c.start.offset) === range.start.offset && ((_d = this.lastRange) == null ? void 0 : _d.end.offset) === range.end.offset) {
|
|
25897
|
+
return;
|
|
25898
|
+
}
|
|
25899
|
+
this.lastRange = range;
|
|
25900
|
+
this.clear();
|
|
25901
|
+
});
|
|
25902
|
+
__publicField(this, "setActiveBlockAttributes", (attributes) => {
|
|
25903
|
+
Array.from(this.activeBlockAttributes).forEach(([key, value]) => {
|
|
25904
|
+
const op = { attributes, insert: "" };
|
|
25905
|
+
if (key === "color" || key === "backgroundColor") {
|
|
25906
|
+
if (value === null || value === void 0) {
|
|
25907
|
+
deleteColor(op, key);
|
|
25908
|
+
} else {
|
|
25909
|
+
addColor(op, key, value);
|
|
25910
|
+
}
|
|
25911
|
+
return;
|
|
25912
|
+
}
|
|
25913
|
+
if (!value) {
|
|
25914
|
+
delete attributes[key];
|
|
25915
|
+
} else {
|
|
25916
|
+
const scriptKeys = ["style-sub", "style-super"];
|
|
25917
|
+
if (scriptKeys.includes(key)) {
|
|
25918
|
+
const [another] = scriptKeys.filter((keys) => keys !== key);
|
|
25919
|
+
delete attributes[another];
|
|
25920
|
+
}
|
|
25921
|
+
attributes[key] = value;
|
|
25922
|
+
}
|
|
25923
|
+
});
|
|
25924
|
+
});
|
|
25925
|
+
__publicField(this, "setEmptyBlockTextAttributes", (blockId, attributes) => {
|
|
25926
|
+
this.textBlockAttributes.set(blockId, attributes);
|
|
25927
|
+
});
|
|
25928
|
+
__publicField(this, "setActiveAttribute", (attribute, value) => {
|
|
25929
|
+
this.activeBlockAttributes.set(attribute, value);
|
|
25930
|
+
});
|
|
25931
|
+
this.editor = editor;
|
|
25932
|
+
this.editor.addListener("docChanged", this.clear);
|
|
25933
|
+
this.editor.addListener("selectionChanged", this.handleSelectionChanged);
|
|
25934
|
+
}
|
|
25935
|
+
static get(editor) {
|
|
25936
|
+
return editor.addCustom("BlockAttributesHandler", () => new BlockAttributesHandler(editor));
|
|
25937
|
+
}
|
|
25938
|
+
destroy() {
|
|
25939
|
+
this.editor.removeListener("docChanged", this.clear);
|
|
25940
|
+
this.editor.removeListener("selectionChanged", this.handleSelectionChanged);
|
|
25941
|
+
}
|
|
25942
|
+
getEmptyBlockTextAttributes(blockId) {
|
|
25943
|
+
var _a;
|
|
25944
|
+
const attributes = cloneDeep__default.default((_a = this.textBlockAttributes.get(blockId)) != null ? _a : {});
|
|
25945
|
+
Array.from(Object.entries(attributes)).forEach(([key, value]) => {
|
|
25946
|
+
if (!value) {
|
|
25947
|
+
delete attributes[key];
|
|
25948
|
+
}
|
|
25949
|
+
});
|
|
25950
|
+
this.setActiveBlockAttributes(attributes);
|
|
25951
|
+
if (Object.keys(attributes).length === 0) {
|
|
25952
|
+
return void 0;
|
|
25953
|
+
}
|
|
25954
|
+
return attributes;
|
|
25955
|
+
}
|
|
25956
|
+
}
|
|
25885
25957
|
const logger$3y = getLogger("insert-text");
|
|
25886
25958
|
function getTextAttributes(editor, containerId, blockIndex, offset) {
|
|
25887
|
-
var _a, _b
|
|
25959
|
+
var _a, _b;
|
|
25888
25960
|
const blockData = editor.doc.getBlockData(containerId, blockIndex);
|
|
25889
25961
|
assert(logger$3y, blockData, "no block data");
|
|
25890
25962
|
assert(logger$3y, blockData.text, "no block text");
|
|
25891
25963
|
if (getTextLength(blockData.text) === 0) {
|
|
25892
25964
|
assert(logger$3y, offset === 0, "invalid text offset");
|
|
25893
|
-
return (
|
|
25965
|
+
return BlockAttributesHandler.get(editor).getEmptyBlockTextAttributes(blockData.id);
|
|
25894
25966
|
}
|
|
25895
25967
|
if (offset === 0) {
|
|
25896
25968
|
return void 0;
|
|
25897
25969
|
}
|
|
25898
25970
|
const prev = splitToThree(blockData.text, offset - 1, 1).middle;
|
|
25899
|
-
if ((
|
|
25971
|
+
if ((_a = prev[0].attributes) == null ? void 0 : _a.box) {
|
|
25900
25972
|
return void 0;
|
|
25901
25973
|
}
|
|
25902
|
-
const attributes = (
|
|
25903
|
-
(
|
|
25974
|
+
const attributes = (_b = prev[0].attributes) != null ? _b : {};
|
|
25975
|
+
BlockAttributesHandler.get(editor).setActiveBlockAttributes(attributes);
|
|
25904
25976
|
if (Object.keys(attributes).length === 0) {
|
|
25905
25977
|
return void 0;
|
|
25906
25978
|
}
|
|
@@ -31085,75 +31157,6 @@ ${codeText}
|
|
|
31085
31157
|
const editor = new Editor(parent, doc2, options);
|
|
31086
31158
|
return editor;
|
|
31087
31159
|
}
|
|
31088
|
-
class BlockAttributesHandler {
|
|
31089
|
-
constructor(editor) {
|
|
31090
|
-
__publicField(this, "textBlockAttributes", /* @__PURE__ */ new Map());
|
|
31091
|
-
__publicField(this, "activeBlockAttributes", /* @__PURE__ */ new Map());
|
|
31092
|
-
__publicField(this, "lastRange");
|
|
31093
|
-
__publicField(this, "clear", () => {
|
|
31094
|
-
this.activeBlockAttributes.clear();
|
|
31095
|
-
});
|
|
31096
|
-
__publicField(this, "handleSelectionChanged", () => {
|
|
31097
|
-
var _a, _b, _c, _d;
|
|
31098
|
-
const range = this.editor.selection.range;
|
|
31099
|
-
if (range.isSimple() && ((_a = this.lastRange) == null ? void 0 : _a.start.blockId) === range.start.blockId && ((_b = this.lastRange) == null ? void 0 : _b.end.blockId) === range.end.blockId && ((_c = this.lastRange) == null ? void 0 : _c.start.offset) === range.start.offset && ((_d = this.lastRange) == null ? void 0 : _d.end.offset) === range.end.offset) {
|
|
31100
|
-
return;
|
|
31101
|
-
}
|
|
31102
|
-
this.lastRange = range;
|
|
31103
|
-
this.clear();
|
|
31104
|
-
});
|
|
31105
|
-
__publicField(this, "setActiveBlockAttributes", (attributes) => {
|
|
31106
|
-
Array.from(this.activeBlockAttributes).forEach(([key, value]) => {
|
|
31107
|
-
const op = { attributes, insert: "" };
|
|
31108
|
-
if (key === "color" || key === "backgroundColor") {
|
|
31109
|
-
if (value === null || value === void 0) {
|
|
31110
|
-
deleteColor(op, key);
|
|
31111
|
-
} else {
|
|
31112
|
-
addColor(op, key, value);
|
|
31113
|
-
}
|
|
31114
|
-
return;
|
|
31115
|
-
}
|
|
31116
|
-
if (!value) {
|
|
31117
|
-
delete attributes[key];
|
|
31118
|
-
} else {
|
|
31119
|
-
const scriptKeys = ["style-sub", "style-super"];
|
|
31120
|
-
if (scriptKeys.includes(key)) {
|
|
31121
|
-
const [another] = scriptKeys.filter((keys) => keys !== key);
|
|
31122
|
-
delete attributes[another];
|
|
31123
|
-
}
|
|
31124
|
-
attributes[key] = value;
|
|
31125
|
-
}
|
|
31126
|
-
});
|
|
31127
|
-
});
|
|
31128
|
-
__publicField(this, "setEmptyBlockTextAttributes", (blockId, attributes) => {
|
|
31129
|
-
this.textBlockAttributes.set(blockId, attributes);
|
|
31130
|
-
});
|
|
31131
|
-
__publicField(this, "setActiveAttribute", (attribute, value) => {
|
|
31132
|
-
this.activeBlockAttributes.set(attribute, value);
|
|
31133
|
-
});
|
|
31134
|
-
this.editor = editor;
|
|
31135
|
-
this.editor.addListener("docChanged", this.clear);
|
|
31136
|
-
this.editor.addListener("selectionChanged", this.handleSelectionChanged);
|
|
31137
|
-
}
|
|
31138
|
-
destroy() {
|
|
31139
|
-
this.editor.removeListener("docChanged", this.clear);
|
|
31140
|
-
this.editor.removeListener("selectionChanged", this.handleSelectionChanged);
|
|
31141
|
-
}
|
|
31142
|
-
getEmptyBlockTextAttributes(blockId) {
|
|
31143
|
-
var _a;
|
|
31144
|
-
const attributes = cloneDeep__default.default((_a = this.textBlockAttributes.get(blockId)) != null ? _a : {});
|
|
31145
|
-
Array.from(Object.entries(attributes)).forEach(([key, value]) => {
|
|
31146
|
-
if (!value) {
|
|
31147
|
-
delete attributes[key];
|
|
31148
|
-
}
|
|
31149
|
-
});
|
|
31150
|
-
this.setActiveBlockAttributes(attributes);
|
|
31151
|
-
if (Object.keys(attributes).length === 0) {
|
|
31152
|
-
return void 0;
|
|
31153
|
-
}
|
|
31154
|
-
return attributes;
|
|
31155
|
-
}
|
|
31156
|
-
}
|
|
31157
31160
|
const DefaultColors = ["#B21B57", "#008796", "#7241CC", "#CC4C08", "#5D8F00", "#BD2C1C", "#D17D00"];
|
|
31158
31161
|
class RemoteUsers extends tinyTypedEmitter.TypedEmitter {
|
|
31159
31162
|
constructor(colors) {
|
|
@@ -41974,7 +41977,7 @@ ${codeText}
|
|
|
41974
41977
|
destroy() {
|
|
41975
41978
|
this.colorPaletteItem.destroy();
|
|
41976
41979
|
this.element.removeEventListener("click", this.handleButtonClick);
|
|
41977
|
-
this.element.removeEventListener("
|
|
41980
|
+
this.element.removeEventListener("touchend", this.handleButtonClick);
|
|
41978
41981
|
this.removeAllListeners();
|
|
41979
41982
|
}
|
|
41980
41983
|
updatePaletteColor() {
|
|
@@ -60408,9 +60411,8 @@ $$${mathData.mathjaxText}$$
|
|
|
60408
60411
|
return styles1;
|
|
60409
60412
|
}
|
|
60410
60413
|
function mergeActiveStyle(editor, style2) {
|
|
60411
|
-
var _a;
|
|
60412
60414
|
const attributes = Object.fromEntries(style2.entries());
|
|
60413
|
-
(
|
|
60415
|
+
BlockAttributesHandler.get(editor).setActiveBlockAttributes(attributes);
|
|
60414
60416
|
return new Map(Object.entries(attributes));
|
|
60415
60417
|
}
|
|
60416
60418
|
function applyTextStyle(editor, block, range, style2, value) {
|
|
@@ -60610,7 +60612,7 @@ $$${mathData.mathjaxText}$$
|
|
|
60610
60612
|
this.colorItem.addListener("onClick", this.handleChangeColor);
|
|
60611
60613
|
}
|
|
60612
60614
|
get blockAttributesHandler() {
|
|
60613
|
-
return this.editor
|
|
60615
|
+
return BlockAttributesHandler.get(this.editor);
|
|
60614
60616
|
}
|
|
60615
60617
|
getAvailableCommands(editor, block, range, params) {
|
|
60616
60618
|
const disable = !isTextKindBlock(editor, block) || isSelectBoxOnly(editor) || isSelectedTitleBlock(editor);
|
|
@@ -60767,7 +60769,7 @@ $$${mathData.mathjaxText}$$
|
|
|
60767
60769
|
return commands.map(TextCommandProvider.toTextCommand);
|
|
60768
60770
|
}
|
|
60769
60771
|
executeCommand(editor, block, range, item, params, result) {
|
|
60770
|
-
var _a;
|
|
60772
|
+
var _a, _b;
|
|
60771
60773
|
if (!isTextKindBlock(editor, block)) {
|
|
60772
60774
|
return false;
|
|
60773
60775
|
}
|
|
@@ -60786,7 +60788,7 @@ $$${mathData.mathjaxText}$$
|
|
|
60786
60788
|
const commandId = TextCommandProvider.fromTextCommandId(item.id);
|
|
60787
60789
|
if (commandId.startsWith("style-")) {
|
|
60788
60790
|
if (editor.selection.range.isCollapsed()) {
|
|
60789
|
-
this.blockAttributesHandler.setActiveAttribute(commandId, value);
|
|
60791
|
+
(_a = this.blockAttributesHandler) == null ? void 0 : _a.setActiveAttribute(commandId, value);
|
|
60790
60792
|
return true;
|
|
60791
60793
|
}
|
|
60792
60794
|
if (getBlockTextLength$6(editor, block) === 0) {
|
|
@@ -60794,20 +60796,21 @@ $$${mathData.mathjaxText}$$
|
|
|
60794
60796
|
}
|
|
60795
60797
|
}
|
|
60796
60798
|
for (const provider of this.providers) {
|
|
60797
|
-
if ((
|
|
60799
|
+
if ((_b = provider.executeCommand) == null ? void 0 : _b.call(provider, editor, block, range, { ...item, id: commandId }, params, result)) {
|
|
60798
60800
|
return true;
|
|
60799
60801
|
}
|
|
60800
60802
|
}
|
|
60801
60803
|
return false;
|
|
60802
60804
|
}
|
|
60803
60805
|
get blockAttributesHandler() {
|
|
60804
|
-
return this.editor
|
|
60806
|
+
return BlockAttributesHandler.get(this.editor);
|
|
60805
60807
|
}
|
|
60806
60808
|
executeCommandOnEmptyText(block, item, params) {
|
|
60807
|
-
|
|
60809
|
+
var _a, _b;
|
|
60810
|
+
let attributes = (_a = this.blockAttributesHandler) == null ? void 0 : _a.getEmptyBlockTextAttributes(getBlockId(block));
|
|
60808
60811
|
if (!attributes) {
|
|
60809
60812
|
attributes = {};
|
|
60810
|
-
this.blockAttributesHandler.setEmptyBlockTextAttributes(getBlockId(block), attributes);
|
|
60813
|
+
(_b = this.blockAttributesHandler) == null ? void 0 : _b.setEmptyBlockTextAttributes(getBlockId(block), attributes);
|
|
60811
60814
|
}
|
|
60812
60815
|
const command = TextCommandProvider.fromTextCommandId(item.id);
|
|
60813
60816
|
const value = params.value;
|
|
@@ -60819,9 +60822,9 @@ $$${mathData.mathjaxText}$$
|
|
|
60819
60822
|
return true;
|
|
60820
60823
|
}
|
|
60821
60824
|
setCommandsStates(commands, block) {
|
|
60822
|
-
var _a;
|
|
60825
|
+
var _a, _b;
|
|
60823
60826
|
const blockId = getBlockId(block);
|
|
60824
|
-
const attributes = (_a = this.blockAttributesHandler.getEmptyBlockTextAttributes(blockId)) != null ?
|
|
60827
|
+
const attributes = (_b = (_a = this.blockAttributesHandler) == null ? void 0 : _a.getEmptyBlockTextAttributes(blockId)) != null ? _b : {};
|
|
60825
60828
|
return commands.map((item) => {
|
|
60826
60829
|
var _a2;
|
|
60827
60830
|
const value = attributes[item.id];
|
|
@@ -88297,7 +88300,6 @@ ${data2.flowchartText}
|
|
|
88297
88300
|
editor.input.addHandler(new ListPasteHandler());
|
|
88298
88301
|
editor.doc.registerCallback(new HeadingBlockDocEvents(editor));
|
|
88299
88302
|
editor.addCustom("remote-cursor", () => new RemoteCarets(editor));
|
|
88300
|
-
editor.addCustom("block-attributes-handler", () => new BlockAttributesHandler(editor));
|
|
88301
88303
|
if (!clientType.isMobile) {
|
|
88302
88304
|
editor.addCustom("editor-quick-menu", () => {
|
|
88303
88305
|
var _a2;
|
|
@@ -88382,7 +88384,7 @@ ${data2.flowchartText}
|
|
|
88382
88384
|
}
|
|
88383
88385
|
}
|
|
88384
88386
|
});
|
|
88385
|
-
editor.version = "2.2.16-beta.
|
|
88387
|
+
editor.version = "2.2.16-beta.2";
|
|
88386
88388
|
return editor;
|
|
88387
88389
|
}
|
|
88388
88390
|
function isDoc(doc2) {
|
|
@@ -88434,7 +88436,6 @@ ${data2.flowchartText}
|
|
|
88434
88436
|
editor.input.addHandler(new OnesEditorPasteHandler(editor));
|
|
88435
88437
|
editor.input.addHandler(new BlockLockerPasteHandler());
|
|
88436
88438
|
editor.input.addHandler(new ListPasteHandler());
|
|
88437
|
-
editor.addCustom("block-attributes-handler", () => new BlockAttributesHandler(editor));
|
|
88438
88439
|
if (!clientType.isMobile) {
|
|
88439
88440
|
editor.addCustom("editor-quick-menu", () => {
|
|
88440
88441
|
var _a2;
|
|
@@ -88477,7 +88478,7 @@ ${data2.flowchartText}
|
|
|
88477
88478
|
});
|
|
88478
88479
|
editor.addCustom(DOC_RE_AUTH_KEYS, (editor2) => new DocReAuthCallbacks(editor2));
|
|
88479
88480
|
OnesEditorToolbar.register(editor);
|
|
88480
|
-
editor.version = "2.2.16-beta.
|
|
88481
|
+
editor.version = "2.2.16-beta.2";
|
|
88481
88482
|
return editor;
|
|
88482
88483
|
}
|
|
88483
88484
|
async function showDocVersions(editor, options, serverUrl) {
|