@ones-editor/editor 3.0.3 → 3.0.4-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.d.ts CHANGED
@@ -30,6 +30,7 @@ export * from '../@ones-editor/layout-block';
30
30
  export * from '../@ones-editor/markdown-to-doc';
31
31
  export * from '../@ones-editor/html-to-doc';
32
32
  export * from '../@ones-editor/main-toolbar';
33
+ export * from '../@ones-editor/mention';
33
34
  export { Popup, ManualMenu, OnesEditorAutoSuggest, tippy, ManualToolbar, ManualCloseDialog, TextColorItem, shouldFocusToEditor, FixedToolbar, } from '../@ones-editor/ui-base';
34
35
  export * from '../@ones-editor/drawio-embed';
35
36
  export * from '../@ones-editor/block-resizer';
@@ -108,3 +109,4 @@ export interface ShowDocVersionsOptions2 {
108
109
  editorOptions?: CreateOnesEditorOptions;
109
110
  }
110
111
  export declare function showDocVersions2(parent: HTMLElement, options: ShowDocVersionsOptions2): Promise<OnesEditorVersionsDialog>;
112
+ export declare function createSimpleInput(root: HTMLElement, docData: DocObject | OnesEditorDoc, options: CreateLocalEditorOptions): Promise<OnesEditor>;
package/dist/index.js CHANGED
@@ -25193,20 +25193,20 @@ var __publicField = (obj, key, value) => {
25193
25193
  function textBlockToMarkdown(editor, blockData, doc2) {
25194
25194
  const richText2 = blockData.text || [];
25195
25195
  const text2 = textToMarkdownText(editor, richText2, doc2);
25196
- let markdown = text2;
25196
+ let markdown2 = text2;
25197
25197
  if (blockData.heading) {
25198
25198
  const heading = blockData.heading;
25199
25199
  const prefix = "#".repeat(heading);
25200
- markdown = `${prefix} ${markdown}`;
25200
+ markdown2 = `${prefix} ${markdown2}`;
25201
25201
  }
25202
25202
  if (blockData.quoted) {
25203
- markdown = `> ${markdown}`;
25203
+ markdown2 = `> ${markdown2}`;
25204
25204
  }
25205
25205
  if (blockData.type === "text") {
25206
- markdown = `${markdown}
25206
+ markdown2 = `${markdown2}
25207
25207
  `;
25208
25208
  }
25209
- return markdown;
25209
+ return markdown2;
25210
25210
  }
25211
25211
  function styleColorToColor$1(color) {
25212
25212
  switch (color) {
@@ -26870,8 +26870,8 @@ var __publicField = (obj, key, value) => {
26870
26870
  function docToMarkdown(editor, doc2) {
26871
26871
  const lines = doc2.blocks.root.map((b, index2) => blockToMarkdown(editor, b, doc2, [{ containerId: "root", blockIndex: index2 }]));
26872
26872
  lines[lines.length - 1] = lines[lines.length - 1].trimEnd();
26873
- const markdown = lines.join("\n");
26874
- return markdown;
26873
+ const markdown2 = lines.join("\n");
26874
+ return markdown2;
26875
26875
  }
26876
26876
  const logger$3O = getLogger("get-text-position");
26877
26877
  function editorGetTextPosition(editor, insertPos) {
@@ -29868,13 +29868,13 @@ ${codeText}
29868
29868
  addMetaToDoc(editor, doc2);
29869
29869
  const htmlFragment = docToHtmlFragment(editor, doc2);
29870
29870
  injectDocToHtmlFragment(htmlFragment, doc2);
29871
- let markdown = "";
29871
+ let markdown2 = "";
29872
29872
  if (isSelectedCodeTextBlock(editor)) {
29873
29873
  const selectBlock = editor.selection.range.getSelectedBlocks()[0];
29874
29874
  const container = getParentContainer(selectBlock.block);
29875
29875
  const codeBlock2 = getParentBlock(container);
29876
29876
  if (codeBlock2) {
29877
- markdown = getSelectedCodeBlockMarkdown(editor, docToText(editor, doc2));
29877
+ markdown2 = getSelectedCodeBlockMarkdown(editor, docToText(editor, doc2));
29878
29878
  }
29879
29879
  } else {
29880
29880
  const lines = [];
@@ -29882,11 +29882,11 @@ ${codeText}
29882
29882
  lines.push(blockToMarkdown(editor, b, doc2, [{ containerId: "root", blockIndex: index2 }]));
29883
29883
  });
29884
29884
  lines[lines.length - 1] = lines[lines.length - 1].trimEnd();
29885
- markdown = lines.join("\n");
29885
+ markdown2 = lines.join("\n");
29886
29886
  }
29887
29887
  setClipboardData([{
29888
29888
  type: "text/plain",
29889
- data: new Blob([markdown], { type: "text/plain" })
29889
+ data: new Blob([markdown2], { type: "text/plain" })
29890
29890
  }]);
29891
29891
  return true;
29892
29892
  }
@@ -42628,6 +42628,9 @@ ${codeText}
42628
42628
  function initMenuItem$1(item, elem) {
42629
42629
  var _a, _b;
42630
42630
  addClass(elem, "menu-item");
42631
+ if (item.className) {
42632
+ addClass(elem, ...item.className.split(" "));
42633
+ }
42631
42634
  if (item.element) {
42632
42635
  return;
42633
42636
  }
@@ -42703,6 +42706,9 @@ ${codeText}
42703
42706
  });
42704
42707
  }
42705
42708
  function initToolbarItem(item, elem, options) {
42709
+ if (item.className) {
42710
+ addClass(elem, ...item.className.split(" "));
42711
+ }
42706
42712
  elem.setAttribute("data-button-id", item.id);
42707
42713
  if (options.tooltipId && item.name && !item.disableTooltip) {
42708
42714
  elem.setAttribute(`data-editor-tooltip-${options.tooltipId}`, item.name);
@@ -66958,9 +66964,11 @@ ${codeText}
66958
66964
  });
66959
66965
  return true;
66960
66966
  }
66961
- function matchBlockStyle(editor, containerId, blockIndex, offset) {
66962
- if (matchHeading(editor, containerId, blockIndex, offset)) {
66963
- return true;
66967
+ function matchBlockStyle(editor, containerId, blockIndex, offset, options) {
66968
+ if ((options == null ? void 0 : options.disableHeadingShortcuts) !== true) {
66969
+ if (matchHeading(editor, containerId, blockIndex, offset)) {
66970
+ return true;
66971
+ }
66964
66972
  }
66965
66973
  if (matchBlockQuote(editor, containerId, blockIndex, offset)) {
66966
66974
  return true;
@@ -67065,12 +67073,15 @@ ${codeText}
67065
67073
  return false;
67066
67074
  }
67067
67075
  class MarkdownInputHandler {
67076
+ constructor(options) {
67077
+ this.options = options;
67078
+ }
67068
67079
  handleAfterInsertText(editor, containerId, blockIndex, offset, text2) {
67069
67080
  if (text2 === " ") {
67070
67081
  if (converterIntercept(editor, containerId)) {
67071
67082
  return false;
67072
67083
  }
67073
- if (matchBlockStyle(editor, containerId, blockIndex, offset)) {
67084
+ if (matchBlockStyle(editor, containerId, blockIndex, offset, this.options)) {
67074
67085
  return true;
67075
67086
  }
67076
67087
  if (matchTextStyle(editor, containerId, blockIndex, offset)) {
@@ -69548,8 +69559,8 @@ ${codeText}
69548
69559
  return images.map((image) => `<img data-embed-type="image" data-uuid="image:${image.src}" src="${editor.doc.buildResourceUrl(image.src, { withToken: true })}">`).join("");
69549
69560
  }
69550
69561
  if (type === "markdown") {
69551
- const markdown = images.map((image) => `![img](${editor.doc.buildResourceUrl(image.src, { withToken: true })})`).join("\n");
69552
- return `${markdown}
69562
+ const markdown2 = images.map((image) => `![img](${editor.doc.buildResourceUrl(image.src, { withToken: true })})`).join("\n");
69563
+ return `${markdown2}
69553
69564
  `;
69554
69565
  }
69555
69566
  return "";
@@ -74928,8 +74939,8 @@ ${codeText}
74928
74939
  }
74929
74940
  lines.push(rowText);
74930
74941
  }
74931
- const markdown = lines.join("\n");
74932
- return `${markdown}
74942
+ const markdown2 = lines.join("\n");
74943
+ return `${markdown2}
74933
74944
  `;
74934
74945
  }
74935
74946
  if (type === "html") {
@@ -75931,6 +75942,11 @@ ${codeText}
75931
75942
  }
75932
75943
  const logger$S = getLogger("custom-tag-to-text");
75933
75944
  function customTagToText(token, attributes, options) {
75945
+ var _a;
75946
+ const processed = (_a = options.customTagProcess) == null ? void 0 : _a.call(options, token, attributes);
75947
+ if (processed) {
75948
+ return processed;
75949
+ }
75934
75950
  const content = token.content;
75935
75951
  try {
75936
75952
  const base64 = content;
@@ -76138,7 +76154,7 @@ ${codeText}
76138
76154
  return createTextWithReplaceSoftReturn(htmlDecode(token.text), attributes);
76139
76155
  }
76140
76156
  if (token.type === "custom-tag") {
76141
- return customTagToText(token, attributes);
76157
+ return customTagToText(token, attributes, options);
76142
76158
  }
76143
76159
  if (token.type === "latex") {
76144
76160
  return [{
@@ -76575,9 +76591,9 @@ ${codeText}
76575
76591
  mangle: false
76576
76592
  });
76577
76593
  marked.marked.use(extendedCustomTag());
76578
- function markdownToDoc(markdown, options) {
76594
+ function markdownToDoc(markdown2, options) {
76579
76595
  const lexer = new marked.marked.Lexer();
76580
- const tokens = lexer.lex(markdown);
76596
+ const tokens = lexer.lex(markdown2);
76581
76597
  const doc2 = {
76582
76598
  blocks: {
76583
76599
  root: []
@@ -76592,7 +76608,8 @@ ${codeText}
76592
76608
  tokensToBlocks,
76593
76609
  tokensToTextWithChildren,
76594
76610
  htmlToDoc: options == null ? void 0 : options.htmlToDoc,
76595
- listLevel: 1
76611
+ listLevel: 1,
76612
+ customTagProcess: options == null ? void 0 : options.customTagProcess
76596
76613
  };
76597
76614
  const rootBlocks = tokensToBlocks(tokens, tokenToBlockOptions);
76598
76615
  if (rootBlocks.length === 0) {
@@ -76605,6 +76622,13 @@ ${codeText}
76605
76622
  doc2.blocks.root.push(...rootBlocks);
76606
76623
  return doc2;
76607
76624
  }
76625
+ const markdown = `
76626
+ [[cursor]]
76627
+ `;
76628
+ setTimeout(() => {
76629
+ const doc2 = markdownToDoc(markdown);
76630
+ console.log(doc2);
76631
+ }, 100);
76608
76632
  function extend(destination) {
76609
76633
  for (let i = 1; i < arguments.length; i++) {
76610
76634
  const source = arguments[i];
@@ -78156,9 +78180,9 @@ ${docStr}
78156
78180
  htmlFragment = html.substring(start + "<!--StartFragment-->".length, end);
78157
78181
  }
78158
78182
  }
78159
- const markdown = turndownService.turndown(htmlFragment);
78160
- logger$P.debug(markdown);
78161
- return markdownToDoc(markdown, {
78183
+ const markdown2 = turndownService.turndown(htmlFragment);
78184
+ logger$P.debug(markdown2);
78185
+ return markdownToDoc(markdown2, {
78162
78186
  htmlToDoc: (html2) => {
78163
78187
  const doc2 = htmlToDocByMarkdown(html2, options);
78164
78188
  return doc2;
@@ -95506,9 +95530,8 @@ ${JSON.stringify(error2, null, 2)}`);
95506
95530
  }
95507
95531
  const elem = node;
95508
95532
  const refId = elem.getAttribute("data-ref-id");
95509
- const refType = elem.getAttribute("data-ref-type");
95510
95533
  const uuid = elem.getAttribute("data-uuid");
95511
- return Boolean(refType === "task" && refId && uuid);
95534
+ return Boolean(refId && uuid);
95512
95535
  },
95513
95536
  replacement: (content, node) => {
95514
95537
  const refType = node.getAttribute("data-ref-type");
@@ -96046,7 +96069,7 @@ ${JSON.stringify(error2, null, 2)}`);
96046
96069
  }
96047
96070
  }
96048
96071
  });
96049
- editor.version = "3.0.3";
96072
+ editor.version = "3.0.4-beta.2";
96050
96073
  return editor;
96051
96074
  }
96052
96075
  function isDoc(doc2) {
@@ -96180,7 +96203,7 @@ ${JSON.stringify(error2, null, 2)}`);
96180
96203
  OnesEditorDropTarget.register(editor);
96181
96204
  OnesEditorTocProvider.register(editor);
96182
96205
  OnesEditorExclusiveBlock.register(editor);
96183
- editor.version = "3.0.3";
96206
+ editor.version = "3.0.4-beta.2";
96184
96207
  return editor;
96185
96208
  }
96186
96209
  async function showDocVersions(editor, options, serverUrl) {
@@ -96247,6 +96270,77 @@ ${JSON.stringify(error2, null, 2)}`);
96247
96270
  dialog.show(dialogOptions);
96248
96271
  return dialog;
96249
96272
  }
96273
+ async function createSimpleInput(root2, docData, options) {
96274
+ var _a, _b, _c, _d, _e, _f, _g, _h;
96275
+ assert(logger, root2, "app does not exists");
96276
+ const doc2 = isDoc(docData) ? docData : new LocalDoc(docData, {
96277
+ serverUrl: options.serverUrl || ""
96278
+ });
96279
+ if (options.lang) {
96280
+ i18n$1.setLang(options.lang);
96281
+ }
96282
+ Logger$2.level = (_a = options.logLevel) != null ? _a : LogLevel.DEBUG;
96283
+ const editor = createEditor(root2, doc2, {
96284
+ id: options.id,
96285
+ scrollContainer: options == null ? void 0 : options.scrollContainer,
96286
+ enableResolveComments: false,
96287
+ enableComments: false,
96288
+ dateTimeFormatter: options.dateTimeFormatter,
96289
+ components: {
96290
+ blocks: [ListBlock, ...(_c = (_b = options.components) == null ? void 0 : _b.blocks) != null ? _c : []],
96291
+ commandProviders: [],
96292
+ decorators: [],
96293
+ embeds: [...((_d = options.components) == null ? void 0 : _d.embeds) || []],
96294
+ boxes: [...((_e = options.components) == null ? void 0 : _e.boxes) || []],
96295
+ insertions: [],
96296
+ blockHooks: [...((_f = options.components) == null ? void 0 : _f.blockHooks) || []],
96297
+ textRenders: [
96298
+ ...((_g = options.components) == null ? void 0 : _g.textRenders) || []
96299
+ ].filter(Boolean),
96300
+ options: { ...options.componentsOptions }
96301
+ },
96302
+ shortcuts: [TextStyleShortcuts, DefaultShortcuts]
96303
+ });
96304
+ if (options.compact) {
96305
+ addClass(editor.rootElement, "compact");
96306
+ if (options.headingButton === false)
96307
+ addClass(editor.rootElement, "no-heading-collapse");
96308
+ if (options.blockMenuButton === false)
96309
+ addClass(editor.rootElement, "no-block-menu");
96310
+ }
96311
+ editor.input.addHandler(new MarkdownInputHandler({
96312
+ disableHeadingShortcuts: true
96313
+ }));
96314
+ editor.input.addHandler(new OnesEditorPasteHandler(editor));
96315
+ editor.input.addHandler(new ListPasteHandler());
96316
+ editor.doc.registerCallback(new HeadingBlockDocEvents(editor));
96317
+ if (!clientType.isMobile) {
96318
+ editor.addCustom("editor-tooltip", () => new OnesEditorTooltip(editor));
96319
+ }
96320
+ editor.addCustom("create-options", () => new OnesEditorCustomDataWrapper(editor, options));
96321
+ if ((_h = options.componentsOptions) == null ? void 0 : _h.mention) {
96322
+ const mentionOptions = options.componentsOptions.mention;
96323
+ editor.addCustom("mention", () => new OnesEditorMention(editor, mentionOptions));
96324
+ }
96325
+ if (options.autoNewLine) {
96326
+ editor.addCustom("auto-new-line", () => new AutoNewLine(editor));
96327
+ }
96328
+ editor.addListener("clickLink", (editor2, event, link2) => {
96329
+ var _a2;
96330
+ if ((_a2 = options == null ? void 0 : options.events) == null ? void 0 : _a2.onClickLink) {
96331
+ options.events.onClickLink(editor2, event, link2);
96332
+ return;
96333
+ }
96334
+ const href = link2.getAttribute("link") || link2.getAttribute("href");
96335
+ if (href) {
96336
+ if (editor2.readonly || event.ctrlKey || event.metaKey || !getParentBlock(link2)) {
96337
+ window.open(href, "_blank");
96338
+ }
96339
+ }
96340
+ });
96341
+ editor.version = "3.0.4-beta.2";
96342
+ return editor;
96343
+ }
96250
96344
  const emojis$1 = {
96251
96345
  smileysAndPeople: [
96252
96346
  "\u{1F600}",
@@ -142150,6 +142244,7 @@ ${JSON.stringify(error2, null, 2)}`);
142150
142244
  exports2.MathMenuIcon = MathMenuIcon;
142151
142245
  exports2.MaxUserError = MaxUserError;
142152
142246
  exports2.Mention2Icon = Mention2Icon;
142247
+ exports2.MentionBox = MentionBox;
142153
142248
  exports2.MentionIcon = MentionIcon;
142154
142249
  exports2.MergeCellIcon = MergeCellIcon;
142155
142250
  exports2.Mindmap = Mindmap;
@@ -142162,12 +142257,14 @@ ${JSON.stringify(error2, null, 2)}`);
142162
142257
  exports2.MoreItem = MoreItem;
142163
142258
  exports2.NextIcon = NextIcon;
142164
142259
  exports2.OnesEditorAutoSuggest = OnesEditorAutoSuggest;
142260
+ exports2.OnesEditorBlockMention = OnesEditorBlockMention;
142165
142261
  exports2.OnesEditorComments = OnesEditorComments;
142166
142262
  exports2.OnesEditorCommentsRender = OnesEditorCommentsRender;
142167
142263
  exports2.OnesEditorCustomDataWrapper = OnesEditorCustomDataWrapper;
142168
142264
  exports2.OnesEditorExclusiveBlock = OnesEditorExclusiveBlock;
142169
142265
  exports2.OnesEditorHoveringBlock = OnesEditorHoveringBlock;
142170
142266
  exports2.OnesEditorIcons = index$f;
142267
+ exports2.OnesEditorMention = OnesEditorMention;
142171
142268
  exports2.OnesEditorQuickMenu = OnesEditorQuickMenu;
142172
142269
  exports2.OnesEditorToc = OnesEditorToc;
142173
142270
  exports2.OnesEditorTocProvider = OnesEditorTocProvider;
@@ -142365,6 +142462,7 @@ ${JSON.stringify(error2, null, 2)}`);
142365
142462
  exports2.createSeparator = createSeparator;
142366
142463
  exports2.createSimpleBlockPosition = createSimpleBlockPosition;
142367
142464
  exports2.createSimpleDocPos = createSimpleDocPos;
142465
+ exports2.createSimpleInput = createSimpleInput;
142368
142466
  exports2.createTextBlockData = createTextBlockData;
142369
142467
  exports2.createTextButton = createTextButton;
142370
142468
  exports2.createTextOp = createTextOp;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "3.0.3",
3
+ "version": "3.0.4-beta.2",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "dependencies": {