@ones-editor/editor 2.9.8-beta.7 → 2.9.8-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.d.ts CHANGED
@@ -46,6 +46,7 @@ export { ShareDBDocVersionsProvider, OnesEditorIcons, isLayoutBlock, LayoutQuick
46
46
  export type { FileBoxData, FileEmbedData } from '../@ones-editor/file';
47
47
  export * from './helper';
48
48
  export { OnesEditorComments, OnesEditorCommentsRender } from '../@ones-editor/comments';
49
+ export * from '../@ones-editor/cke-html';
49
50
  export { type DocListBlock } from '../@ones-editor/list-block';
50
51
  export declare function getDefaultOnesEditorOptions(options: CreateOnesEditorOptions): {
51
52
  id: string | undefined;
package/dist/index.js CHANGED
@@ -24898,18 +24898,11 @@ var __publicField = (obj, key, value) => {
24898
24898
  };
24899
24899
  }
24900
24900
  function isEmptyDoc(doc2) {
24901
- const root2 = doc2.blocks.root;
24902
- if (root2.length !== 1) {
24903
- return false;
24904
- }
24905
- const block = root2[0];
24906
- if (!block.text) {
24907
- return false;
24908
- }
24909
- if (getTextLength(block.text)) {
24910
- return false;
24911
- }
24912
- return true;
24901
+ const blocks = doc2.blocks.root;
24902
+ const ret = blocks.every((block) => {
24903
+ return block.type === "text" && getTextLength(block.text || []) === 0;
24904
+ });
24905
+ return ret;
24913
24906
  }
24914
24907
  function createContainer$1(doc2, docsOrDocObject) {
24915
24908
  const containerId = genId();
@@ -94761,6 +94754,294 @@ ${JSON.stringify(error2, null, 2)}`);
94761
94754
  }
94762
94755
  });
94763
94756
  }
94757
+ const CkeImageConverter = {
94758
+ filter: (node) => {
94759
+ if (node.nodeName !== "IMG") {
94760
+ return false;
94761
+ }
94762
+ const elem = node;
94763
+ const refId = elem.getAttribute("data-ref-id");
94764
+ const refType = elem.getAttribute("data-ref-type");
94765
+ const uuid = elem.getAttribute("data-uuid");
94766
+ return Boolean(refType === "task" && refId && uuid);
94767
+ },
94768
+ replacement: (content, node) => {
94769
+ const refType = node.getAttribute("data-ref-type");
94770
+ const refId = node.getAttribute("data-ref-id");
94771
+ const uuid = node.getAttribute("data-uuid");
94772
+ const src = `ones-file:${refType}/${refId}/${uuid}`;
94773
+ return `![${refType}](${src})`;
94774
+ }
94775
+ };
94776
+ const ckeHtmlConverters = /* @__PURE__ */ new Map();
94777
+ function registerCKEHtmlConvert(name, converter) {
94778
+ if (ckeHtmlConverters.has(name)) {
94779
+ return;
94780
+ }
94781
+ ckeHtmlConverters.set(name, converter);
94782
+ turndownService.use((ts) => {
94783
+ ts.addRule(name, converter);
94784
+ });
94785
+ }
94786
+ function getTurndownRootElement(node) {
94787
+ let parent = node;
94788
+ while (parent) {
94789
+ if (parent instanceof HTMLElement && parent.tagName === "BODY") {
94790
+ return parent;
94791
+ }
94792
+ if (!parent.parentNode) {
94793
+ return parent;
94794
+ }
94795
+ parent = parent.parentNode;
94796
+ }
94797
+ return node;
94798
+ }
94799
+ function patchForEmptyBlock(key, node, className) {
94800
+ const root2 = getTurndownRootElement(node);
94801
+ if (root2 && root2 instanceof HTMLElement) {
94802
+ const attributeKey = `data-${key}-processed`;
94803
+ if (!root2.getAttribute(attributeKey)) {
94804
+ root2.setAttribute(attributeKey, "true");
94805
+ const elements = root2.querySelectorAll(className);
94806
+ elements.forEach((elem) => {
94807
+ var _a;
94808
+ const text2 = (_a = elem.textContent) == null ? void 0 : _a.trim();
94809
+ if (!text2) {
94810
+ elem.innerText = "--temp-data--";
94811
+ }
94812
+ });
94813
+ }
94814
+ }
94815
+ }
94816
+ const CkeCommentConverter = {
94817
+ filter: (node) => {
94818
+ if (node.nodeName === "SPAN") {
94819
+ const span = node;
94820
+ const ref = span.getAttribute("data-annotate-ref");
94821
+ return Boolean(ref);
94822
+ }
94823
+ return false;
94824
+ },
94825
+ replacement: (content, node) => {
94826
+ var _a;
94827
+ const span = node;
94828
+ const ref = span.getAttribute("data-annotate-ref");
94829
+ const text2 = (_a = span.textContent) != null ? _a : "";
94830
+ return `[${text2}](comment://${ref})`;
94831
+ }
94832
+ };
94833
+ function processCkeCommentsLink(doc2) {
94834
+ const containers = doc2.blocks;
94835
+ Object.values(containers).forEach((blocks) => {
94836
+ blocks.forEach((block) => {
94837
+ const text2 = block.text;
94838
+ if (text2) {
94839
+ text2.forEach((op) => {
94840
+ if (op.attributes) {
94841
+ const attributes = op.attributes;
94842
+ const link2 = attributes.link;
94843
+ if (link2 == null ? void 0 : link2.startsWith("comment://")) {
94844
+ delete attributes.link;
94845
+ const commentId = link2.replace("comment://", "");
94846
+ const key = `comment-${commentId.toLocaleLowerCase()}`;
94847
+ attributes[key] = commentId;
94848
+ }
94849
+ }
94850
+ });
94851
+ }
94852
+ });
94853
+ });
94854
+ }
94855
+ const CkeMentionConverter = {
94856
+ filter: (node) => {
94857
+ patchForEmptyBlock("mention", node, ".ones-at-user-block");
94858
+ if (node.nodeName === "SPAN") {
94859
+ const span = node;
94860
+ if (hasClass(span, "ones-at-user-block")) {
94861
+ const name = span.getAttribute("data-default-name");
94862
+ const refId = span.getAttribute("data-ref-id");
94863
+ return Boolean(name) && Boolean(refId);
94864
+ }
94865
+ }
94866
+ return false;
94867
+ },
94868
+ replacement: (content, node) => {
94869
+ const span = node;
94870
+ const name = span.getAttribute("data-default-name") || "";
94871
+ const refId = span.getAttribute("data-ref-id") || "";
94872
+ if (name && refId) {
94873
+ const box = {
94874
+ id: genId(),
94875
+ type: "mention",
94876
+ box: true,
94877
+ created: Date.now(),
94878
+ iconUrl: "",
94879
+ text: name,
94880
+ mentionId: refId
94881
+ };
94882
+ const text2 = [
94883
+ {
94884
+ insert: " ",
94885
+ attributes: box
94886
+ }
94887
+ ];
94888
+ const obj = {
94889
+ text: text2
94890
+ };
94891
+ const base64 = toBase64URL(JSON.stringify(obj));
94892
+ return `[[${base64}]]`;
94893
+ }
94894
+ return name;
94895
+ }
94896
+ };
94897
+ function convertMentionToCkeMention(editor, boxData, doc2, type) {
94898
+ const data2 = boxData;
94899
+ if (type === "html") {
94900
+ return `<ones-at-user data-ref-name="${data2.text}" data-ref-id="${data2.mentionId}" data-default-name="${data2.text}" class="ones-at-user-block" data-viewer="1"><span>@${data2.text}</span></ones-at-user>`;
94901
+ }
94902
+ return `@${data2.text}`;
94903
+ }
94904
+ function patchMentionConverter(editor) {
94905
+ const mentionBox = editor.editorBoxes.getBoxClass("mention");
94906
+ if (mentionBox) {
94907
+ const oldConvertTo = mentionBox.convertTo;
94908
+ if (oldConvertTo !== convertMentionToCkeMention) {
94909
+ mentionBox.convertTo = convertMentionToCkeMention;
94910
+ }
94911
+ }
94912
+ }
94913
+ function processLinks(doc2) {
94914
+ const containers = doc2.blocks;
94915
+ Object.values(containers).forEach((blocks) => {
94916
+ blocks.forEach((block) => {
94917
+ if (block.text) {
94918
+ const text2 = block.text;
94919
+ text2.forEach((op) => {
94920
+ const attributes = op.attributes;
94921
+ if (attributes) {
94922
+ attributes.link;
94923
+ }
94924
+ });
94925
+ }
94926
+ });
94927
+ });
94928
+ }
94929
+ const CkeMarkdownConverter = {
94930
+ filter: (node) => {
94931
+ if (node.nodeName !== "DIV") {
94932
+ return false;
94933
+ }
94934
+ const div = node;
94935
+ return hasClass(div, "ones-marked-card");
94936
+ },
94937
+ replacement: (content, node) => {
94938
+ const textToCodeBlock2 = (text2, language) => {
94939
+ const codeBlocks = text2.split("\n").map((line) => {
94940
+ const block = {
94941
+ type: "text",
94942
+ id: genId(),
94943
+ text: createRichText(line)
94944
+ };
94945
+ return block;
94946
+ });
94947
+ const containerId = genId();
94948
+ const doc22 = {
94949
+ blocks: {
94950
+ root: [
94951
+ {
94952
+ id: genId(),
94953
+ type: "code",
94954
+ language,
94955
+ children: [containerId]
94956
+ }
94957
+ ],
94958
+ [containerId]: codeBlocks
94959
+ },
94960
+ meta: {},
94961
+ comments: {}
94962
+ };
94963
+ return toBase64URL(JSON.stringify(doc22));
94964
+ };
94965
+ const nodeToCodeBlock2 = (node2, lang) => {
94966
+ const text2 = node2.textContent || "";
94967
+ return textToCodeBlock2(text2, lang);
94968
+ };
94969
+ const doc2 = nodeToCodeBlock2(node, "markdown");
94970
+ const fence = "```";
94971
+ return "\n\n" + fence + "\n" + doc2 + "\n" + fence + "\n\n";
94972
+ }
94973
+ };
94974
+ registerCKEHtmlConvert("image", CkeImageConverter);
94975
+ registerCKEHtmlConvert("comment", CkeCommentConverter);
94976
+ registerCKEHtmlConvert("mention", CkeMentionConverter);
94977
+ registerCKEHtmlConvert("markdown", CkeMarkdownConverter);
94978
+ function ckeHtml2Doc(html) {
94979
+ const doc2 = htmlToDoc(html) || createEmptyDoc$1();
94980
+ processCkeCommentsLink(doc2);
94981
+ processLinks(doc2);
94982
+ return doc2;
94983
+ }
94984
+ function injectDocToCkeHtmlFragment(htmlFragment, doc2, text2) {
94985
+ const meta = `<meta charset="utf-8"><ones-editor-doc data-source="ones-editor-doc::${toBase64URL(
94986
+ JSON.stringify(doc2)
94987
+ )}::ones-editor-doc" />`;
94988
+ let textMeta = "";
94989
+ if (text2) {
94990
+ textMeta = `<meta name="ones-editor-text" content="${toBase64URL(text2)}" />`;
94991
+ }
94992
+ const html = `<!doctype html><html><head>${meta}${textMeta}</head><body>${htmlFragment}</body></html>`;
94993
+ return html;
94994
+ }
94995
+ function editorToCKEHtml(editor) {
94996
+ patchMentionConverter(editor);
94997
+ const docObject = editor.doc.toJSON();
94998
+ if (isEmptyDoc(docObject)) {
94999
+ return "";
95000
+ }
95001
+ let html = docToHtmlFragment(editor, docObject);
95002
+ const text2 = docToText(editor, docObject);
95003
+ html = injectDocToCkeHtmlFragment(html, docObject, text2);
95004
+ return html;
95005
+ }
95006
+ function combineDoc(doc1, doc2) {
95007
+ if (isEmptyDoc(doc1)) {
95008
+ return doc2;
95009
+ }
95010
+ if (isEmptyDoc(doc2)) {
95011
+ return doc1;
95012
+ }
95013
+ const splitterDoc = createEmptyDoc$1("", {
95014
+ firstLineAsTitle: false
95015
+ });
95016
+ return mergeDocs([doc1, splitterDoc, doc2]);
95017
+ }
95018
+ function mergeHTMLBodiesOnly(htmlA, htmlB) {
95019
+ const parser = new DOMParser();
95020
+ const docA = parser.parseFromString(htmlA, "text/html");
95021
+ const docB = parser.parseFromString(htmlB, "text/html");
95022
+ const mergedDoc = document.implementation.createHTMLDocument("Merged");
95023
+ const bodyA = docA.body;
95024
+ const bodyB = docB.body;
95025
+ const mergedBody = mergedDoc.body;
95026
+ Array.from(bodyA.childNodes).forEach((node) => {
95027
+ mergedBody.appendChild(mergedDoc.importNode(node, true));
95028
+ });
95029
+ Array.from(bodyB.childNodes).forEach((node) => {
95030
+ mergedBody.appendChild(mergedDoc.importNode(node, true));
95031
+ });
95032
+ return mergedBody.innerHTML;
95033
+ }
95034
+ function combineCkeHtml(html1, html2) {
95035
+ const doc1 = ckeHtml2Doc(html1);
95036
+ const doc2 = ckeHtml2Doc(html2);
95037
+ const newDoc = combineDoc(doc1, doc2);
95038
+ const newHtml = mergeHTMLBodiesOnly(html1, html2);
95039
+ const ret = injectDocToCkeHtmlFragment(newHtml, newDoc);
95040
+ return ret;
95041
+ }
95042
+ function combineRichTextValue(value1, value2) {
95043
+ return combineCkeHtml(value1, value2);
95044
+ }
94764
95045
  const logger = getLogger("create-editor");
94765
95046
  function getHooks(options, local) {
94766
95047
  var _a;
@@ -95019,7 +95300,7 @@ ${JSON.stringify(error2, null, 2)}`);
95019
95300
  }
95020
95301
  }
95021
95302
  });
95022
- editor.version = "2.9.8-beta.7";
95303
+ editor.version = "2.9.8-beta.8";
95023
95304
  return editor;
95024
95305
  }
95025
95306
  function isDoc(doc2) {
@@ -95151,7 +95432,7 @@ ${JSON.stringify(error2, null, 2)}`);
95151
95432
  OnesEditorDropTarget.register(editor);
95152
95433
  OnesEditorTocProvider.register(editor);
95153
95434
  OnesEditorExclusiveBlock.register(editor);
95154
- editor.version = "2.9.8-beta.7";
95435
+ editor.version = "2.9.8-beta.8";
95155
95436
  return editor;
95156
95437
  }
95157
95438
  async function showDocVersions(editor, options, serverUrl) {
@@ -141253,12 +141534,15 @@ ${JSON.stringify(error2, null, 2)}`);
141253
141534
  exports2.blockToText = blockToText;
141254
141535
  exports2.blocksToDoc = blocksToDoc;
141255
141536
  exports2.changeButtonName = changeButtonName;
141537
+ exports2.ckeHtml2Doc = ckeHtml2Doc;
141256
141538
  exports2.clearAllSelection = clearAllSelection;
141257
141539
  exports2.clientType = clientType;
141258
141540
  exports2.cloneBlock = cloneBlock;
141259
141541
  exports2.cloneChildContainer = cloneChildContainer;
141260
141542
  exports2.cloneDoc = cloneDoc;
141261
141543
  exports2.cloneText = cloneText;
141544
+ exports2.combineCkeHtml = combineCkeHtml;
141545
+ exports2.combineRichTextValue = combineRichTextValue;
141262
141546
  exports2.commentToShareDbComment = commentToShareDbComment;
141263
141547
  exports2.compareElement = compareElement;
141264
141548
  exports2.comparePosition = comparePosition;
@@ -141414,6 +141698,7 @@ ${JSON.stringify(error2, null, 2)}`);
141414
141698
  exports2.editorSelectWordLeft = editorSelectWordLeft;
141415
141699
  exports2.editorSetTextColor = editorSetTextColor;
141416
141700
  exports2.editorShowFindDialog = editorShowFindDialog;
141701
+ exports2.editorToCKEHtml = editorToCKEHtml;
141417
141702
  exports2.editorToDocx = editorToDocx;
141418
141703
  exports2.editorUpdateBlockData = editorUpdateBlockData;
141419
141704
  exports2.editorUpdateCompositionText = editorUpdateCompositionText;
@@ -141580,6 +141865,7 @@ ${JSON.stringify(error2, null, 2)}`);
141580
141865
  exports2.i18n = i18n$1;
141581
141866
  exports2.includeBigTable = includeBigTable;
141582
141867
  exports2.injectBlockOptions = injectBlockOptions;
141868
+ exports2.injectDocToCkeHtmlFragment = injectDocToCkeHtmlFragment;
141583
141869
  exports2.injectDocToHtmlFragment = injectDocToHtmlFragment;
141584
141870
  exports2.injectSource = injectSource;
141585
141871
  exports2.injectStyle = injectStyle;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "2.9.8-beta.7",
3
+ "version": "2.9.8-beta.8",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "dependencies": {