@ones-editor/editor 0.0.9-beta.6 → 0.0.9-beta.8

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
@@ -2126,8 +2126,8 @@ div.editor-root:not(.readonly) div.editor-content div[data-type=editor-container
2126
2126
  div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content] > span.math-box .mathjax-tex-text.mathjax-error {
2127
2127
  color: var(--color-0);
2128
2128
  }
2129
- div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content] img.mathjax {
2130
- max-width: 100%;
2129
+ div.editor-root div.editor-content div[data-type=editor-container] .embed-block.selected[data-embed-type=math] > div[data-type=block-content].mathjax-overflow::before {
2130
+ width: var(--mathjax-width, "100%");
2131
2131
  }
2132
2132
  div.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-embed-type=math] > div[data-type=block-content] {
2133
2133
  align-items: center;
@@ -21492,6 +21492,62 @@ var __publicField = (obj, key, value) => {
21492
21492
  }
21493
21493
  return markdown;
21494
21494
  }
21495
+ function styleColorToColor$1(color) {
21496
+ switch (color) {
21497
+ case "style-color-0":
21498
+ return "#e52727";
21499
+ case "style-color-1":
21500
+ return "#eb6414";
21501
+ case "style-color-2":
21502
+ return "#f0a100";
21503
+ case "style-color-3":
21504
+ return "#24b47e";
21505
+ case "style-color-4":
21506
+ return "#0064ff";
21507
+ case "style-color-5":
21508
+ return "#9678d3";
21509
+ case "style-color-6":
21510
+ return "#909090";
21511
+ default:
21512
+ return void 0;
21513
+ }
21514
+ }
21515
+ function styleBackgroundColorToHighlight$1(color) {
21516
+ switch (color) {
21517
+ case "style-bg-color-0":
21518
+ return "#fad4d4";
21519
+ case "style-bg-color-1":
21520
+ return "#fbe0d0";
21521
+ case "style-bg-color-2":
21522
+ return "#fceccc";
21523
+ case "style-bg-color-3":
21524
+ return "#d3f0e5";
21525
+ case "style-bg-color-4":
21526
+ return "#d6e9fa";
21527
+ case "style-bg-color-5":
21528
+ return "#eae4f6";
21529
+ case "style-bg-color-6":
21530
+ return "#dedede";
21531
+ case "style-bg-color-7":
21532
+ return "#e52727";
21533
+ case "style-bg-color-8":
21534
+ return "#eb6414";
21535
+ case "style-bg-color-9":
21536
+ return "#f0a100";
21537
+ case "style-bg-color-10":
21538
+ return "#24b47e";
21539
+ case "style-bg-color-11":
21540
+ return "#0064ff";
21541
+ case "style-bg-color-12":
21542
+ return "#9678d3";
21543
+ case "style-bg-color-13":
21544
+ return "#909090";
21545
+ case "style-bg-color-14":
21546
+ return "#e8e8e8";
21547
+ default:
21548
+ return void 0;
21549
+ }
21550
+ }
21495
21551
  const logger$3h = getLogger("block-to-text");
21496
21552
  function textBlockToHtml(editor, ops, doc2) {
21497
21553
  let html = "";
@@ -21513,27 +21569,48 @@ var __publicField = (obj, key, value) => {
21513
21569
  const attributes = op.attributes;
21514
21570
  if (attributes) {
21515
21571
  let string = op.insert;
21516
- if (attributes.link) {
21517
- string = `<a href="${attributes.link}">${string}</a>`;
21518
- }
21519
21572
  const tags = [];
21520
- if (attributes.bold) {
21573
+ let styles = "";
21574
+ if (attributes["style-bold"]) {
21521
21575
  tags.push("strong");
21522
21576
  }
21523
- if (attributes.italic) {
21577
+ if (attributes["style-italic"]) {
21524
21578
  tags.push("em");
21525
21579
  }
21526
- if (attributes.underline) {
21580
+ if (attributes["style-underline"]) {
21527
21581
  tags.push("u");
21528
21582
  }
21529
- if (attributes.strike) {
21583
+ if (attributes["style-strikethrough"]) {
21530
21584
  tags.push("s");
21531
21585
  }
21532
- if (attributes.code) {
21586
+ if (attributes["style-code"]) {
21533
21587
  tags.push("code");
21534
21588
  }
21535
- const prefix = tags.map((s) => `<${s}>`).join("");
21536
- const suffix = tags.reverse().map((s) => `</${s}>`).join("");
21589
+ const fontBgColor = Object.keys(attributes).find((k) => k.startsWith("style-bg-color-"));
21590
+ if (fontBgColor) {
21591
+ styles += `background-color: ${styleBackgroundColorToHighlight$1(fontBgColor)};`;
21592
+ }
21593
+ const fontColor = Object.keys(attributes).find((k) => k.startsWith("style-color-"));
21594
+ if (fontColor) {
21595
+ styles += `color: ${styleColorToColor$1(fontColor)};`;
21596
+ }
21597
+ if (attributes.link) {
21598
+ string = `<a href="${attributes.link}">${string}</a>`;
21599
+ }
21600
+ let prefix = tags.map((s) => `<${s}>`).join("");
21601
+ let suffix = tags.reverse().map((s) => `</${s}>`).join("");
21602
+ if (styles) {
21603
+ if (attributes.link) {
21604
+ string = `<a href="${attributes.link}" style="${styles}">${op.insert}</a>`;
21605
+ } else {
21606
+ if (prefix) {
21607
+ prefix = prefix.replace(">", ` style="${styles}">`);
21608
+ } else {
21609
+ prefix = `<span style="${styles}">`;
21610
+ suffix = "</span>";
21611
+ }
21612
+ }
21613
+ }
21537
21614
  html += prefix + string + suffix;
21538
21615
  return;
21539
21616
  }
@@ -23352,6 +23429,9 @@ var __publicField = (obj, key, value) => {
23352
23429
  const currentBlock = editor.getBlockByIndex(containerId, blockIndex2);
23353
23430
  if (currentBlock && isTextKindBlock(editor, currentBlock) && isEmptyTextBlock(editor, currentBlock) && blocks[i].type === "text") {
23354
23431
  editor.insertTextToBlock(block, 0, (_a = blocks[i].text) != null ? _a : []);
23432
+ if (Object.prototype.hasOwnProperty.call(blocks[i], "heading")) {
23433
+ editor.updateBlockData(currentBlock, blocks[i]);
23434
+ }
23355
23435
  continue;
23356
23436
  }
23357
23437
  if (isTitleBlock$2(currentBlock)) {
@@ -44085,6 +44165,8 @@ var __publicField = (obj, key, value) => {
44085
44165
  }
44086
44166
  const logger$1x = getLogger("mathjax-converter");
44087
44167
  const MATHJAX_SCRIPT_ID = "MathJax-script";
44168
+ const MATHJAX_BUFFER = 30;
44169
+ const REDUCED_UNIT = 8;
44088
44170
  async function initMathjax(editor) {
44089
44171
  var _a;
44090
44172
  if (!window.MathJax) {
@@ -44136,6 +44218,23 @@ var __publicField = (obj, key, value) => {
44136
44218
  lockers.release(lockId);
44137
44219
  }
44138
44220
  }
44221
+ function analyzeMathjaxSvgWidth(svg) {
44222
+ const dom = new DOMParser().parseFromString(svg, "image/svg+xml");
44223
+ const expect = {
44224
+ width: 0,
44225
+ height: 0
44226
+ };
44227
+ if (dom && dom.firstChild) {
44228
+ const svgElement = dom.firstChild;
44229
+ const height = svgElement.getAttribute("height");
44230
+ const width = svgElement.style.minWidth;
44231
+ if (height) {
44232
+ expect.width = parseInt(width, 10) * REDUCED_UNIT + MATHJAX_BUFFER;
44233
+ expect.height = parseInt(height, 10) * REDUCED_UNIT;
44234
+ }
44235
+ }
44236
+ return expect;
44237
+ }
44139
44238
  async function mathjax2DataUrl(editor, tex) {
44140
44239
  const svg = await mathjax2Svg(editor, tex);
44141
44240
  if (!svg)
@@ -44150,6 +44249,17 @@ var __publicField = (obj, key, value) => {
44150
44249
  const path = await editor.doc.uploadResource(file2);
44151
44250
  return path.resourceId;
44152
44251
  }
44252
+ async function convertAndUploadMathjaxForEmbed(editor, tex) {
44253
+ const svg = await mathjax2Svg(editor, tex);
44254
+ const perfectState = analyzeMathjaxSvgWidth(svg);
44255
+ const data = svg;
44256
+ const file2 = new File([data], "math.svg");
44257
+ const path = await editor.doc.uploadResource(file2);
44258
+ return {
44259
+ resourceId: path.resourceId,
44260
+ ...perfectState
44261
+ };
44262
+ }
44153
44263
  const logger$1w = getLogger("edit-mathjax");
44154
44264
  class MathjaxEditor {
44155
44265
  constructor() {
@@ -44182,15 +44292,17 @@ var __publicField = (obj, key, value) => {
44182
44292
  (_a = this.onChange) == null ? void 0 : _a.call(this, text2, false);
44183
44293
  }, 300));
44184
44294
  }
44185
- editMathjax(elem, tex, onChange) {
44295
+ editMathjax(elem, tex, onChange, options) {
44186
44296
  if (!this.editMathjaxPopup) {
44187
- this.editMathjaxPopup = new Popup(this.createPopupContent(tex));
44297
+ this.editMathjaxPopup = new Popup(this.createPopupContent(tex), {
44298
+ id: "mathjax-popover"
44299
+ });
44188
44300
  } else {
44189
44301
  const textarea2 = this.getTextarea();
44190
44302
  textarea2.value = tex;
44191
44303
  }
44192
44304
  this.tex = tex;
44193
- this.editMathjaxPopup.manualShow(elem, { theme: "light" });
44305
+ this.editMathjaxPopup.manualShow(elem, { theme: "light", placement: options == null ? void 0 : options.placement });
44194
44306
  this.editMathjaxPopup.removeAllListeners("close");
44195
44307
  this.editMathjaxPopup.addListener("close", this.handleClose);
44196
44308
  this.onChange = onChange;
@@ -44231,9 +44343,9 @@ var __publicField = (obj, key, value) => {
44231
44343
  (_b = this.editMathjaxPopup) == null ? void 0 : _b.removeAllListeners();
44232
44344
  }
44233
44345
  }
44234
- function editMathjax(editor, elem, tex, onChange) {
44346
+ function editMathjax(editor, elem, tex, onChange, options) {
44235
44347
  const mathjaxEditor = editor.addCustom("mathjax-editor", () => new MathjaxEditor());
44236
- mathjaxEditor.editMathjax(elem, tex.trim(), onChange);
44348
+ mathjaxEditor.editMathjax(elem, tex.trim(), onChange, options);
44237
44349
  }
44238
44350
  function createEmptyMathjaxBox() {
44239
44351
  const id = genId();
@@ -44446,25 +44558,45 @@ var __publicField = (obj, key, value) => {
44446
44558
  const data = editor.getBlockData(block);
44447
44559
  const embedData = data.embedData;
44448
44560
  editMathjax(editor, elem, embedData.mathjaxText, async (tex) => {
44449
- const src = await convertAndUploadMathjax(editor, tex);
44561
+ const { resourceId: src, width, height } = await convertAndUploadMathjaxForEmbed(editor, tex);
44450
44562
  const newData = {
44451
44563
  mathjaxText: tex,
44452
- src
44564
+ src,
44565
+ width,
44566
+ height
44453
44567
  };
44454
44568
  editor.updateEmbedData(block, newData);
44569
+ }, {
44570
+ placement: "bottom"
44455
44571
  });
44456
44572
  }
44457
44573
  function createEmbedContent$9(editor, content, block) {
44458
44574
  const mathData = block.embedData;
44575
+ const { src, width } = mathData;
44459
44576
  const state = editor.addCustom(`mathjax-block-${block.id}`, () => new MathjaxStateData());
44460
44577
  editor.domEvents.addEventListener(content, "click", handleClickContent);
44461
44578
  if (!mathData.mathjaxText.trim()) {
44462
44579
  createElement("span", ["mathjax-tex-text"], content, i18n$1.t("mathjax.emptyText"));
44463
44580
  return;
44464
44581
  }
44465
- if (mathData.src || state.dataUrl) {
44582
+ if (src || state.dataUrl) {
44466
44583
  const img = createElement("img", ["mathjax"], content);
44467
- img.src = editor.doc.buildResourceUrl(mathData.src || state.dataUrl);
44584
+ img.src = editor.doc.buildResourceUrl(src || state.dataUrl);
44585
+ if (width) {
44586
+ img.style.minWidth = `${width}px`;
44587
+ setTimeout(() => {
44588
+ const contentWidth = content.getBoundingClientRect().width;
44589
+ if (width > contentWidth) {
44590
+ addClass(content, "mathjax-overflow");
44591
+ content.style.overflow = "auto";
44592
+ content.style.setProperty("--mathjax-width", `${width}px`);
44593
+ } else {
44594
+ removeClass(content, "mathjax-overflow");
44595
+ content.removeAttribute("data-mathjax-width");
44596
+ content.style.removeProperty("--mathjax-width");
44597
+ }
44598
+ });
44599
+ }
44468
44600
  return;
44469
44601
  }
44470
44602
  if (state.error)
@@ -55617,8 +55749,9 @@ ${codeText}
55617
55749
  if (html.indexOf("<ones-editor-doc") > 0) {
55618
55750
  return false;
55619
55751
  }
55752
+ const text2 = data.getData("text/plain");
55620
55753
  const images = getImages(files);
55621
- if (images.length > 0) {
55754
+ if (images.length > 0 && !text2) {
55622
55755
  if (!docs["text/office-html"]) {
55623
55756
  await this.handleInsertImages(editor, images);
55624
55757
  return true;
@@ -59754,7 +59887,11 @@ ${codeText}
59754
59887
  }
59755
59888
  return this._commands;
59756
59889
  }
59757
- return this._commands.filter((command) => command.id !== "to-link" && command.id !== "to-card");
59890
+ const ret = this._commands.filter((command) => command.id !== "to-link" && command.id !== "to-card");
59891
+ if (ret[ret.length - 1].id === "sep") {
59892
+ ret.pop();
59893
+ }
59894
+ return ret;
59758
59895
  }
59759
59896
  executeCommand(editor, block, box, item) {
59760
59897
  if (item.id === "to-card") {
@@ -62818,7 +62955,7 @@ ${codeText}
62818
62955
  return false;
62819
62956
  }
62820
62957
  const listBlockType = getListBlockType(block);
62821
- if (listBlockType === "ordered" || listBlockType === "unordered") {
62958
+ if (listBlockType === "ordered" || listBlockType === "unordered" || listBlockType === "text-only") {
62822
62959
  return false;
62823
62960
  }
62824
62961
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "0.0.9-beta.6",
3
+ "version": "0.0.9-beta.8",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",