@harbour-enterprises/superdoc 0.24.0-next.5 → 0.24.0-next.6

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.
@@ -35845,14 +35845,104 @@ Please report this to https://github.com/markedjs/marked.`, e) {
35845
35845
  }
35846
35846
  return {
35847
35847
  type: "tableCell",
35848
- content: nodeListHandler.handler({
35849
- ...params2,
35850
- nodes: node.elements,
35851
- path: [...params2.path || [], node]
35852
- }),
35848
+ content: normalizeTableCellContent(
35849
+ nodeListHandler.handler({
35850
+ ...params2,
35851
+ nodes: node.elements,
35852
+ path: [...params2.path || [], node]
35853
+ }),
35854
+ params2.editor
35855
+ ),
35853
35856
  attrs: attributes
35854
35857
  };
35855
35858
  }
35859
+ function normalizeTableCellContent(content, editor) {
35860
+ if (!Array.isArray(content) || content.length === 0) return content;
35861
+ const normalized = [];
35862
+ const pendingForNextBlock = [];
35863
+ const schema = editor?.schema;
35864
+ const cloneBlock = (node) => {
35865
+ if (!node) return node;
35866
+ const cloned = { ...node };
35867
+ if (Array.isArray(node.content)) {
35868
+ cloned.content = [...node.content];
35869
+ }
35870
+ return cloned;
35871
+ };
35872
+ const ensureArray = (node) => {
35873
+ if (!Array.isArray(node.content)) {
35874
+ node.content = [];
35875
+ }
35876
+ return node.content;
35877
+ };
35878
+ const isInlineNode = (node) => {
35879
+ if (!node || typeof node.type !== "string") return false;
35880
+ if (node.type === "text") return true;
35881
+ if (node.type === "bookmarkStart" || node.type === "bookmarkEnd") return true;
35882
+ const nodeType = schema?.nodes?.[node.type];
35883
+ if (nodeType) {
35884
+ if (typeof nodeType.isInline === "boolean") return nodeType.isInline;
35885
+ if (nodeType.spec?.group && typeof nodeType.spec.group === "string") {
35886
+ return nodeType.spec.group.split(" ").includes("inline");
35887
+ }
35888
+ }
35889
+ return false;
35890
+ };
35891
+ for (const node of content) {
35892
+ if (!node || typeof node.type !== "string") {
35893
+ normalized.push(node);
35894
+ continue;
35895
+ }
35896
+ if (!isInlineNode(node)) {
35897
+ const blockNode = cloneBlock(node);
35898
+ if (pendingForNextBlock.length) {
35899
+ const blockContent = ensureArray(blockNode);
35900
+ const leadingInline = pendingForNextBlock.splice(0);
35901
+ blockNode.content = [...leadingInline, ...blockContent];
35902
+ } else if (Array.isArray(blockNode.content)) {
35903
+ blockNode.content = [...blockNode.content];
35904
+ }
35905
+ normalized.push(blockNode);
35906
+ continue;
35907
+ }
35908
+ const targetIsNextBlock = node.type === "bookmarkStart" || normalized.length === 0;
35909
+ if (targetIsNextBlock) {
35910
+ pendingForNextBlock.push(node);
35911
+ } else {
35912
+ const lastIndex = normalized.length - 1;
35913
+ const lastNode = normalized[lastIndex];
35914
+ if (!lastNode || typeof lastNode.type !== "string" || isInlineNode(lastNode)) {
35915
+ pendingForNextBlock.push(node);
35916
+ continue;
35917
+ }
35918
+ const blockContent = ensureArray(lastNode);
35919
+ if (pendingForNextBlock.length) {
35920
+ blockContent.push(...pendingForNextBlock.splice(0));
35921
+ }
35922
+ blockContent.push(node);
35923
+ }
35924
+ }
35925
+ if (pendingForNextBlock.length) {
35926
+ if (normalized.length) {
35927
+ const lastIndex = normalized.length - 1;
35928
+ const lastNode = normalized[lastIndex];
35929
+ if (lastNode && typeof lastNode.type === "string" && !isInlineNode(lastNode)) {
35930
+ const blockContent = ensureArray(lastNode);
35931
+ blockContent.push(...pendingForNextBlock);
35932
+ pendingForNextBlock.length = 0;
35933
+ }
35934
+ }
35935
+ if (pendingForNextBlock.length) {
35936
+ normalized.push({
35937
+ type: "paragraph",
35938
+ attrs: {},
35939
+ content: [...pendingForNextBlock]
35940
+ });
35941
+ pendingForNextBlock.length = 0;
35942
+ }
35943
+ }
35944
+ return normalized;
35945
+ }
35856
35946
  const processInlineCellBorders = (borders, rowBorders) => {
35857
35947
  if (!borders) return null;
35858
35948
  return ["bottom", "top", "left", "right"].reduce((acc, direction) => {