@ones-editor/editor 3.0.19-beta.1 → 3.0.19-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.
@@ -1,4 +1,4 @@
1
- import { DocBlock, DocBlockDelta, DocBlockText, DocBlockTextActions, DocObject, EventCallbacks, OnesEditorDoc, OnesEditorDocCallbacks, OnesEditorUser, UploadResourceResult, OnesEditorDocServerMeta, OnesEditorDocServer } from '../../../../@ones-editor/core';
1
+ import { BuildResourceUrlOptions, DocBlock, DocBlockDelta, DocBlockText, DocBlockTextActions, DocObject, EventCallbacks, OnesEditorDoc, OnesEditorDocCallbacks, OnesEditorUser, UploadResourceResult, OnesEditorDocServerMeta, OnesEditorDocServer } from '../../../../@ones-editor/core';
2
2
  import { HistoryUser } from '../types';
3
3
  export default class HistoryDoc extends EventCallbacks<OnesEditorDocCallbacks> implements OnesEditorDoc {
4
4
  private server;
@@ -21,7 +21,7 @@ export default class HistoryDoc extends EventCallbacks<OnesEditorDocCallbacks> i
21
21
  uploadResource(): Promise<UploadResourceResult>;
22
22
  addResources(resourceIds: string[]): Promise<string[]>;
23
23
  getServerMeta(): OnesEditorDocServerMeta;
24
- buildResourceUrl(src: string): string;
24
+ buildResourceUrl(src: string, options?: BuildResourceUrlOptions): string;
25
25
  request<T>(): Promise<T>;
26
26
  broadcastMessage(): void;
27
27
  getUser(): OnesEditorUser;
package/dist/index.js CHANGED
@@ -39402,40 +39402,41 @@ ${codeText}
39402
39402
  return false;
39403
39403
  }
39404
39404
  const firstOp = ops[0];
39405
- if (typeof firstOp !== "object") {
39405
+ if (!firstOp || typeof firstOp !== "object") {
39406
39406
  return false;
39407
39407
  }
39408
39408
  if (!firstOp.i || Object.keys(firstOp).length !== 1) {
39409
39409
  return false;
39410
39410
  }
39411
- for (let i = 1; i < ops.length; i++) {
39411
+ for (let i = 1; i < ops.length; ) {
39412
39412
  const nextOp = ops[i];
39413
- if (!Array.isArray(nextOp)) {
39413
+ const isArrayInsertOp = Array.isArray(nextOp);
39414
+ if (isArrayInsertOp && nextOp.length !== 2) {
39414
39415
  return false;
39415
39416
  }
39416
- if (nextOp.length !== 2) {
39417
- return false;
39418
- }
39419
- const key = nextOp[0];
39417
+ const key = isArrayInsertOp ? nextOp[0] : nextOp;
39420
39418
  if (typeof key !== "string") {
39421
39419
  return false;
39422
39420
  }
39423
- const op = nextOp[1];
39424
- if (typeof op !== "object") {
39421
+ const op = isArrayInsertOp ? nextOp[1] : ops[i + 1];
39422
+ if (!op || typeof op !== "object") {
39425
39423
  return false;
39426
39424
  }
39427
39425
  if (op.i === void 0 || Object.keys(op).length !== 1) {
39428
39426
  return false;
39429
39427
  }
39428
+ i += isArrayInsertOp ? 1 : 2;
39430
39429
  }
39431
39430
  const blockData = firstOp.i;
39432
39431
  assert(logger$2Y, blockData.id, "block id is required");
39433
39432
  assert(logger$2Y, blockData.type, "block type is required");
39434
- for (let i = 1; i < ops.length; i++) {
39433
+ for (let i = 1; i < ops.length; ) {
39435
39434
  const nextOp = ops[i];
39436
- const key = nextOp[0];
39437
- const op = nextOp[1];
39435
+ const isArrayInsertOp = Array.isArray(nextOp);
39436
+ const key = isArrayInsertOp ? nextOp[0] : nextOp;
39437
+ const op = isArrayInsertOp ? nextOp[1] : ops[i + 1];
39438
39438
  blockData[key] = op.i;
39439
+ i += isArrayInsertOp ? 1 : 2;
39439
39440
  }
39440
39441
  parser.onInsertBlock(containerId, blockIndex, blockData);
39441
39442
  return true;
@@ -39577,6 +39578,19 @@ ${codeText}
39577
39578
  }
39578
39579
  }
39579
39580
  }
39581
+ function parseBlockOps(containerId, ops, parseType, handler) {
39582
+ if (ops.length === 0) {
39583
+ return;
39584
+ }
39585
+ if (Array.isArray(ops[0])) {
39586
+ const blockOpsList = parseType === "remove" ? ops.concat().reverse() : ops;
39587
+ blockOpsList.forEach((op) => {
39588
+ parseBlockOp(containerId, op, parseType, handler);
39589
+ });
39590
+ return;
39591
+ }
39592
+ parseBlockOp(containerId, ops, parseType, handler);
39593
+ }
39580
39594
  function parseOp(ops, parseType, handler) {
39581
39595
  const firstOp = ops[0];
39582
39596
  if (Array.isArray(firstOp)) {
@@ -39597,15 +39611,7 @@ ${codeText}
39597
39611
  }
39598
39612
  const containerId = rootKey;
39599
39613
  if (Array.isArray(ops[1])) {
39600
- if (parseType === "remove") {
39601
- ops.slice(1).reverse().forEach((op) => {
39602
- parseBlockOp(containerId, op, parseType, handler);
39603
- });
39604
- } else {
39605
- ops.slice(1).forEach((op) => {
39606
- parseBlockOp(containerId, op, parseType, handler);
39607
- });
39608
- }
39614
+ parseBlockOps(containerId, ops.slice(1), parseType, handler);
39609
39615
  } else {
39610
39616
  if (typeof ops[1] === "object") {
39611
39617
  const action = ops[1];
@@ -39619,6 +39625,7 @@ ${codeText}
39619
39625
  handler.onCreateContainer(containerId, action.i);
39620
39626
  }
39621
39627
  }
39628
+ parseBlockOps(containerId, ops.slice(2), parseType, handler);
39622
39629
  } else {
39623
39630
  assert(logger$2Y, typeof ops[1] === "number", `invalid ops[1], not a number: ${JSON.stringify(ops)}`);
39624
39631
  parseBlockOp(containerId, ops.slice(1), parseType, handler);
@@ -83165,12 +83172,12 @@ ${docStr}
83165
83172
  var _a, _b, _c;
83166
83173
  return (_c = (_b = (_a = this.server).getServerMeta) == null ? void 0 : _b.call(_a)) != null ? _c : {};
83167
83174
  }
83168
- buildResourceUrl(src) {
83175
+ buildResourceUrl(src, options) {
83169
83176
  var _a;
83170
83177
  if ((_a = this.editorOptions) == null ? void 0 : _a.buildResourceUrl) {
83171
- return this.editorOptions.buildResourceUrl(this, src);
83178
+ return this.editorOptions.buildResourceUrl(this, src, options);
83172
83179
  }
83173
- return this.server.buildResourceUrl(src);
83180
+ return this.server.buildResourceUrl(src, options);
83174
83181
  }
83175
83182
  request() {
83176
83183
  disableLocalActions();
@@ -97108,6 +97115,24 @@ ${JSON.stringify(error2, null, 2)}`);
97108
97115
  const blocks = value.blocks;
97109
97116
  return Boolean(blocks && typeof blocks === "object" && Array.isArray(blocks.root));
97110
97117
  };
97118
+ const trimTrailingSlash = (value) => {
97119
+ return value.replace(/\/+$/, "");
97120
+ };
97121
+ const buildDocApiServer = (editorOptions) => {
97122
+ const serverUrl = trimTrailingSlash(editorOptions.serverUrl);
97123
+ const { appId, docId } = editorOptions;
97124
+ if (!serverUrl || !appId || !docId) {
97125
+ return editorOptions.serverUrl;
97126
+ }
97127
+ const docApiServer = serverUrl + "/" + appId + "/" + docId;
97128
+ if (docApiServer.startsWith("ws://")) {
97129
+ return `http://${docApiServer.substring(5)}`;
97130
+ }
97131
+ if (docApiServer.startsWith("wss://")) {
97132
+ return `https://${docApiServer.substring(6)}`;
97133
+ }
97134
+ return docApiServer;
97135
+ };
97111
97136
  const parseDocData = (data2) => {
97112
97137
  if (typeof data2 !== "string") {
97113
97138
  return data2;
@@ -97190,7 +97215,7 @@ ${JSON.stringify(error2, null, 2)}`);
97190
97215
  appId: this.editorOptions.appId,
97191
97216
  docId: this.editorOptions.docId,
97192
97217
  serverId: this.editorOptions.serverUrl,
97193
- apiServer: this.editorOptions.serverUrl
97218
+ apiServer: buildDocApiServer(this.editorOptions)
97194
97219
  };
97195
97220
  }
97196
97221
  }
@@ -97469,7 +97494,7 @@ ${JSON.stringify(error2, null, 2)}`);
97469
97494
  }
97470
97495
  }
97471
97496
  });
97472
- editor.version = "3.0.19-beta.1";
97497
+ editor.version = "3.0.19-beta.2";
97473
97498
  return editor;
97474
97499
  }
97475
97500
  function isDoc(doc2) {
@@ -97603,7 +97628,7 @@ ${JSON.stringify(error2, null, 2)}`);
97603
97628
  OnesEditorDropTarget.register(editor);
97604
97629
  OnesEditorTocProvider.register(editor);
97605
97630
  OnesEditorExclusiveBlock.register(editor);
97606
- editor.version = "3.0.19-beta.1";
97631
+ editor.version = "3.0.19-beta.2";
97607
97632
  return editor;
97608
97633
  }
97609
97634
  async function showDocVersions(editor, options, serverUrl) {
@@ -97738,7 +97763,7 @@ ${JSON.stringify(error2, null, 2)}`);
97738
97763
  }
97739
97764
  }
97740
97765
  });
97741
- editor.version = "3.0.19-beta.1";
97766
+ editor.version = "3.0.19-beta.2";
97742
97767
  return editor;
97743
97768
  }
97744
97769
  const emojis$1 = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "3.0.19-beta.1",
3
+ "version": "3.0.19-beta.2",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "dependencies": {