@ones-editor/editor 2.9.8-beta.46 → 2.9.8-beta.48

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,13 +1,13 @@
1
- import { OnesEditor, CommandItem, CommandItemWithSource, CommandFilterId, CommandFilter } from '../../../../@ones-editor/core';
1
+ import { OnesEditor, CommandItem, OnesEditorCommandProviders, CommandItemWithSource, CommandFilterId, CommandFilter } from '../../../../@ones-editor/core';
2
2
  import { OnesEditorAutoSuggest } from '../../../../@ones-editor/ui-base';
3
3
  import { QuickMenuOptions } from './types';
4
4
  export default class OnesEditorQuickMenu {
5
5
  protected editor: OnesEditor;
6
6
  private options;
7
7
  protected suggest: OnesEditorAutoSuggest;
8
- private items;
8
+ protected items: CommandItem[];
9
9
  private firstEmptyOffset;
10
- private quickCommandProviders;
10
+ quickCommandProviders: OnesEditorCommandProviders;
11
11
  constructor(editor: OnesEditor, options?: QuickMenuOptions);
12
12
  get menu(): import("@ones-editor/ui-base").ManualMenu | import("@ones-editor/ui-base/src/mobile-command-bar/mobile-bottom-menu").MobileBottomMenu;
13
13
  addFilter(id: CommandFilterId, filter: CommandFilter): void;
package/dist/index.d.ts CHANGED
@@ -54,6 +54,7 @@ export declare function getDefaultOnesEditorOptions(options: CreateOnesEditorOpt
54
54
  enableComments: boolean | undefined;
55
55
  enableResolveComments: boolean | undefined;
56
56
  enableContextMenu: boolean | undefined;
57
+ dateTimeFormatter: ((v: Date, source?: string | undefined) => string) | undefined;
57
58
  components: {
58
59
  blocks: import("@ones-editor/core").Block[];
59
60
  embeds: import("@ones-editor/core").Embed[];
package/dist/index.js CHANGED
@@ -31977,7 +31977,7 @@ ${codeText}
31977
31977
  const logger$38 = getLogger("editor");
31978
31978
  class Editor extends tinyTypedEmitter.TypedEmitter {
31979
31979
  constructor(parent, doc2, optionalOptions) {
31980
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
31980
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
31981
31981
  super();
31982
31982
  __publicField(this, "parent");
31983
31983
  __publicField(this, "rootElement");
@@ -32026,12 +32026,13 @@ ${codeText}
32026
32026
  scrollContainer: optionalOptions == null ? void 0 : optionalOptions.scrollContainer,
32027
32027
  enableComments: (_d = optionalOptions == null ? void 0 : optionalOptions.enableComments) != null ? _d : true,
32028
32028
  enableResolveComments: (_e = optionalOptions == null ? void 0 : optionalOptions.enableResolveComments) != null ? _e : true,
32029
- enableContextMenu: (_f = optionalOptions == null ? void 0 : optionalOptions.enableContextMenu) != null ? _f : true
32029
+ enableContextMenu: (_f = optionalOptions == null ? void 0 : optionalOptions.enableContextMenu) != null ? _f : true,
32030
+ dateTimeFormatter: (_g = optionalOptions == null ? void 0 : optionalOptions.dateTimeFormatter) != null ? _g : (v) => v.toLocaleString()
32030
32031
  };
32031
- this.settingsProvider = (_g = optionalOptions == null ? void 0 : optionalOptions.settingsProvider) != null ? _g : new DefaultSettingsProvider(this);
32032
+ this.settingsProvider = (_h = optionalOptions == null ? void 0 : optionalOptions.settingsProvider) != null ? _h : new DefaultSettingsProvider(this);
32032
32033
  registerComponents(this, optionalOptions == null ? void 0 : optionalOptions.components);
32033
- this.blockHooks.push(...(_i = (_h = optionalOptions == null ? void 0 : optionalOptions.components) == null ? void 0 : _h.blockHooks) != null ? _i : []);
32034
- this.id = (_j = optionalOptions == null ? void 0 : optionalOptions.id) != null ? _j : genId();
32034
+ this.blockHooks.push(...(_j = (_i = optionalOptions == null ? void 0 : optionalOptions.components) == null ? void 0 : _i.blockHooks) != null ? _j : []);
32035
+ this.id = (_k = optionalOptions == null ? void 0 : optionalOptions.id) != null ? _k : genId();
32035
32036
  this.clientId = genId();
32036
32037
  this.undoManager = new UndoManager(this);
32037
32038
  this.doc = new EditorDoc(this, doc2, this.undoManager);
@@ -42072,6 +42073,9 @@ ${codeText}
42072
42073
  if (parentEditor) {
42073
42074
  const input2 = parentEditor.querySelector(".editor-input");
42074
42075
  if (input2) {
42076
+ if (parentEditor.contains(document.activeElement)) {
42077
+ return;
42078
+ }
42075
42079
  input2.focus();
42076
42080
  }
42077
42081
  }
@@ -67309,6 +67313,17 @@ ${codeText}
67309
67313
  id: "empty-block-menu"
67310
67314
  });
67311
67315
  __publicField(this, "currentBlock", null);
67316
+ setTimeout(() => {
67317
+ const quickMenu = editor.findCustom("editor-quick-menu");
67318
+ if (quickMenu) {
67319
+ const filters = quickMenu.quickCommandProviders.commandFilters;
67320
+ if (filters) {
67321
+ filters.forEach((v, k) => {
67322
+ this.addFilter(k, v);
67323
+ });
67324
+ }
67325
+ }
67326
+ }, 100);
67312
67327
  }
67313
67328
  get isVisible() {
67314
67329
  return this.suggest.menu.isVisible;
@@ -79946,6 +79961,7 @@ ${docStr}
79946
79961
  });
79947
79962
  __publicField(this, "isSecureContext", window.isSecureContext);
79948
79963
  __publicField(this, "externalActionHandleMap", /* @__PURE__ */ new Map());
79964
+ __publicField(this, "target", null);
79949
79965
  __publicField(this, "handleActionByExternal", (item) => {
79950
79966
  const { data: data2 } = item;
79951
79967
  if (data2 && data2.externalType) {
@@ -79980,7 +79996,8 @@ ${docStr}
79980
79996
  disableReason
79981
79997
  };
79982
79998
  });
79983
- __publicField(this, "getCommandItems", async () => {
79999
+ __publicField(this, "getCommandItems", async (target) => {
80000
+ this.target = target || null;
79984
80001
  const pasteCommandItem = await this.getPasteCommandItem();
79985
80002
  const basicCommandItems = this.editor.readonly ? [] : [this.cutCommandItem, pasteCommandItem];
79986
80003
  const commandItems = [...this.copyTypeCommandItems, ...basicCommandItems];
@@ -80018,6 +80035,15 @@ ${docStr}
80018
80035
  const isFocusedImage = isEmbedBlock(focusedBlock) && getEmbedType(focusedBlock) === "image";
80019
80036
  return isFocusedImage && selection.range.getSelectedBlocks().length === 1;
80020
80037
  });
80038
+ __publicField(this, "getFocusImageBlock", () => {
80039
+ const selection = this.editor.selection;
80040
+ const focusedBlock = selection.focusedBlock;
80041
+ const isFocusedImage = isEmbedBlock(focusedBlock) && getEmbedType(focusedBlock) === "image";
80042
+ if (!isFocusedImage) {
80043
+ return null;
80044
+ }
80045
+ return focusedBlock;
80046
+ });
80021
80047
  __publicField(this, "isFocusImageTypeEmbed", () => {
80022
80048
  const selection = this.editor.selection;
80023
80049
  const focusedBlock = selection.focusedBlock;
@@ -80094,6 +80120,15 @@ ${docStr}
80094
80120
  return this.editor.selection.range.isCollapsed();
80095
80121
  }
80096
80122
  get imageTypeCommandItems() {
80123
+ const image = this.getFocusImageBlock();
80124
+ if (image) {
80125
+ if (hasClass(image, "load-error")) {
80126
+ return [];
80127
+ }
80128
+ if (image.querySelector(".load-error")) {
80129
+ return [];
80130
+ }
80131
+ }
80097
80132
  const canCopy = this.isSecureContext && this.hasClipboardWritePermission;
80098
80133
  return [{
80099
80134
  id: "copy-image",
@@ -80218,6 +80253,7 @@ ${docStr}
80218
80253
  constructor(editor) {
80219
80254
  __publicField(this, "contextMenu");
80220
80255
  __publicField(this, "contextMenuCommandItems");
80256
+ __publicField(this, "target", null);
80221
80257
  __publicField(this, "destroy", () => {
80222
80258
  this.contextMenuCommandItems.destroy();
80223
80259
  this.contextMenu.off("show", this.handleContextMenuShown);
@@ -80261,6 +80297,7 @@ ${docStr}
80261
80297
  return;
80262
80298
  }
80263
80299
  const target = event.target;
80300
+ this.target = target;
80264
80301
  if (this.editor.findCustom("toolbar-handler")) {
80265
80302
  const editorToolbar = this.editor.getCustom("toolbar-handler");
80266
80303
  if (editorToolbar.isInToolbar(event)) {
@@ -80308,12 +80345,12 @@ ${docStr}
80308
80345
  const isInInput = event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement;
80309
80346
  return isInCurEditor && !isInInput;
80310
80347
  });
80311
- __publicField(this, "handleContextMenuShown", async () => {
80348
+ __publicField(this, "handleContextMenuShown", async (bar2) => {
80312
80349
  if (this.editor.findCustom("toolbar-handler")) {
80313
80350
  const editorToolBar = this.editor.getCustom("toolbar-handler");
80314
80351
  editorToolBar.hide();
80315
80352
  }
80316
- const items = await this.contextMenuCommandItems.getCommandItems();
80353
+ const items = await this.contextMenuCommandItems.getCommandItems(this.target);
80317
80354
  this.contextMenu.updateItems(items);
80318
80355
  });
80319
80356
  __publicField(this, "handleContextMenuClick", (_2, item) => {
@@ -80750,7 +80787,7 @@ ${docStr}
80750
80787
  return UnknownFileIcon;
80751
80788
  }
80752
80789
  async function renderFileCard(editor, content, data2) {
80753
- var _a, _b;
80790
+ var _a, _b, _c, _d;
80754
80791
  const { fileName, fileType, fileSize, created, creator, src } = data2;
80755
80792
  const card = createElement("div", ["card-root"], content);
80756
80793
  const icon = createElement("div", ["file-icon"], card);
@@ -80777,14 +80814,14 @@ ${docStr}
80777
80814
  }
80778
80815
  nameElement.title = fileName;
80779
80816
  const infos = createElement("div", ["file-info"], detail);
80780
- const timeText = i18n$1.t("file.uploadedTime", { time: formatDate(new Date(created), "YYYY-MM-DD hh:mm") });
80817
+ const timeText = i18n$1.t("file.uploadedTime", { time: ((_c = (_b = editor.options) == null ? void 0 : _b.dateTimeFormatter) == null ? void 0 : _c.call(_b, new Date(created), "file-embed")) || formatDate(new Date(created), "YYYY-MM-DD hh:mm") });
80781
80818
  const sizeText = formatBytes(fileSize);
80782
80819
  const infoText = `${creator} ${timeText} ${sizeText}`;
80783
80820
  createElement("div", ["info"], infos, infoText);
80784
80821
  const actions2 = createElement("div", ["file-actions"], card);
80785
80822
  const options = editor.getComponentOptions("file");
80786
80823
  let copilotButton;
80787
- const checkCopilotMethod = (_b = editor.getComponentOptions("custom")) == null ? void 0 : _b.checkCopilotReadyItem;
80824
+ const checkCopilotMethod = (_d = editor.getComponentOptions("custom")) == null ? void 0 : _d.checkCopilotReadyItem;
80788
80825
  if (checkCopilotMethod) {
80789
80826
  const copilotEnabled = checkCopilotMethod(src);
80790
80827
  if (copilotEnabled) {
@@ -95387,6 +95424,7 @@ ${JSON.stringify(error2, null, 2)}`);
95387
95424
  enableComments: options == null ? void 0 : options.enableComments,
95388
95425
  enableResolveComments: options == null ? void 0 : options.enableResolveComments,
95389
95426
  enableContextMenu: options == null ? void 0 : options.enableContextMenu,
95427
+ dateTimeFormatter: options.dateTimeFormatter,
95390
95428
  components: {
95391
95429
  blocks: [...StandardBlocks, ...((_d = options == null ? void 0 : options.components) == null ? void 0 : _d.blocks) || []],
95392
95430
  embeds: [...StandardEmbeds, ...((_e = options.components) == null ? void 0 : _e.embeds) || []],
@@ -95619,7 +95657,7 @@ ${JSON.stringify(error2, null, 2)}`);
95619
95657
  }
95620
95658
  }
95621
95659
  });
95622
- editor.version = "2.9.8-beta.46";
95660
+ editor.version = "2.9.8-beta.48";
95623
95661
  return editor;
95624
95662
  }
95625
95663
  function isDoc(doc2) {
@@ -95643,6 +95681,7 @@ ${JSON.stringify(error2, null, 2)}`);
95643
95681
  scrollContainer: options == null ? void 0 : options.scrollContainer,
95644
95682
  enableResolveComments: options == null ? void 0 : options.enableResolveComments,
95645
95683
  enableComments,
95684
+ dateTimeFormatter: options.dateTimeFormatter,
95646
95685
  components: {
95647
95686
  blocks: [...StandardBlocks, ...(_f = (_e = options.components) == null ? void 0 : _e.blocks) != null ? _f : []],
95648
95687
  commandProviders: [new TableBlockCommandProvider()],
@@ -95751,7 +95790,7 @@ ${JSON.stringify(error2, null, 2)}`);
95751
95790
  OnesEditorDropTarget.register(editor);
95752
95791
  OnesEditorTocProvider.register(editor);
95753
95792
  OnesEditorExclusiveBlock.register(editor);
95754
- editor.version = "2.9.8-beta.46";
95793
+ editor.version = "2.9.8-beta.48";
95755
95794
  return editor;
95756
95795
  }
95757
95796
  async function showDocVersions(editor, options, serverUrl) {
package/dist/types.d.ts CHANGED
@@ -75,6 +75,7 @@ export interface CreateOnesEditorOptions {
75
75
  applyContentPlaceholder?: (editor: OnesEditor) => boolean;
76
76
  };
77
77
  onReauth?: (userId: string, docId: string, permission: OnesEditorUserPermission) => Promise<string>;
78
+ dateTimeFormatter?: (v: Date, source?: string) => string;
78
79
  user: {
79
80
  userId: string;
80
81
  displayName: string;
@@ -135,4 +136,5 @@ export interface CreateLocalEditorOptions {
135
136
  componentsOptions?: EditorComponentOptions;
136
137
  hideTitle?: boolean;
137
138
  autoNewLine?: boolean;
139
+ dateTimeFormatter?: (v: Date, source?: string) => string;
138
140
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "2.9.8-beta.46",
3
+ "version": "2.9.8-beta.48",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "dependencies": {