@blocknote/core 0.17.1 → 0.18.0

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.
Files changed (212) hide show
  1. package/dist/angular-html-HQGguTAE.js +33 -0
  2. package/dist/angular-html-HQGguTAE.js.map +1 -0
  3. package/dist/angular-ts-q9PqJiJb.js +22 -0
  4. package/dist/angular-ts-q9PqJiJb.js.map +1 -0
  5. package/dist/astro-0iWgpDaK.js +17 -0
  6. package/dist/astro-0iWgpDaK.js.map +1 -0
  7. package/dist/blade-C3Z8AhvY.js +19 -0
  8. package/dist/blade-C3Z8AhvY.js.map +1 -0
  9. package/dist/blocknote.js +2338 -1491
  10. package/dist/blocknote.js.map +1 -1
  11. package/dist/blocknote.umd.cjs +10 -7
  12. package/dist/blocknote.umd.cjs.map +1 -1
  13. package/dist/c-TKJGJdXV.js +7 -0
  14. package/dist/c-TKJGJdXV.js.map +1 -0
  15. package/dist/coffee-CN_y6cG3.js +9 -0
  16. package/dist/coffee-CN_y6cG3.js.map +1 -0
  17. package/dist/cpp-Be_e67JE.js +19 -0
  18. package/dist/cpp-Be_e67JE.js.map +1 -0
  19. package/dist/css-DHLSoXzW.js +7 -0
  20. package/dist/css-DHLSoXzW.js.map +1 -0
  21. package/dist/glsl-8qSUIm5B.js +9 -0
  22. package/dist/glsl-8qSUIm5B.js.map +1 -0
  23. package/dist/graphql-D7_Dk2ma.js +15 -0
  24. package/dist/graphql-D7_Dk2ma.js.map +1 -0
  25. package/dist/haml-S3dmcfEW.js +11 -0
  26. package/dist/haml-S3dmcfEW.js.map +1 -0
  27. package/dist/handlebars-DaIrqVg3.js +15 -0
  28. package/dist/handlebars-DaIrqVg3.js.map +1 -0
  29. package/dist/html-Bx3A18fV.js +11 -0
  30. package/dist/html-Bx3A18fV.js.map +1 -0
  31. package/dist/html-derivative-Cf3KTZBS.js +9 -0
  32. package/dist/html-derivative-Cf3KTZBS.js.map +1 -0
  33. package/dist/http-BphR83YX.js +15 -0
  34. package/dist/http-BphR83YX.js.map +1 -0
  35. package/dist/imba-CmP25v0O.js +9 -0
  36. package/dist/imba-CmP25v0O.js.map +1 -0
  37. package/dist/java-Dg4kxH6C.js +7 -0
  38. package/dist/java-Dg4kxH6C.js.map +1 -0
  39. package/dist/javascript-CipAzIn1.js +7 -0
  40. package/dist/javascript-CipAzIn1.js.map +1 -0
  41. package/dist/jinja-tioldiz6.js +12 -0
  42. package/dist/jinja-tioldiz6.js.map +1 -0
  43. package/dist/jison-DWJFEE_I.js +9 -0
  44. package/dist/jison-DWJFEE_I.js.map +1 -0
  45. package/dist/json-_04EL6MS.js +7 -0
  46. package/dist/json-_04EL6MS.js.map +1 -0
  47. package/dist/json5-Dwmp5XFI.js +7 -0
  48. package/dist/json5-Dwmp5XFI.js.map +1 -0
  49. package/dist/jsonc-LqD5auy0.js +7 -0
  50. package/dist/jsonc-LqD5auy0.js.map +1 -0
  51. package/dist/jsonl-B4yVuYQH.js +7 -0
  52. package/dist/jsonl-B4yVuYQH.js.map +1 -0
  53. package/dist/jsx-Mg4WaD5k.js +7 -0
  54. package/dist/jsx-Mg4WaD5k.js.map +1 -0
  55. package/dist/julia-CWi-ZdpN.js +17 -0
  56. package/dist/julia-CWi-ZdpN.js.map +1 -0
  57. package/dist/less-BBvTHIGe.js +7 -0
  58. package/dist/less-BBvTHIGe.js.map +1 -0
  59. package/dist/markdown-DAXqtk9a.js +7 -0
  60. package/dist/markdown-DAXqtk9a.js.map +1 -0
  61. package/dist/marko-0aaNgUGV.js +15 -0
  62. package/dist/marko-0aaNgUGV.js.map +1 -0
  63. package/dist/mdc-hXJ2B4O0.js +13 -0
  64. package/dist/mdc-hXJ2B4O0.js.map +1 -0
  65. package/dist/mdx-CSCKbb_f.js +7 -0
  66. package/dist/mdx-CSCKbb_f.js.map +1 -0
  67. package/dist/php-B_-4RJ09.js +19 -0
  68. package/dist/php-B_-4RJ09.js.map +1 -0
  69. package/dist/postcss-SJfTvo_B.js +7 -0
  70. package/dist/postcss-SJfTvo_B.js.map +1 -0
  71. package/dist/pug-3q2tx0nf.js +13 -0
  72. package/dist/pug-3q2tx0nf.js.map +1 -0
  73. package/dist/python-Dpup1-fE.js +7 -0
  74. package/dist/python-Dpup1-fE.js.map +1 -0
  75. package/dist/r-Chyv38Fv.js +7 -0
  76. package/dist/r-Chyv38Fv.js.map +1 -0
  77. package/dist/regexp-BF0hfxNW.js +7 -0
  78. package/dist/regexp-BF0hfxNW.js.map +1 -0
  79. package/dist/sass-p2RMoqDT.js +7 -0
  80. package/dist/sass-p2RMoqDT.js.map +1 -0
  81. package/dist/scss-DmlHSoOY.js +9 -0
  82. package/dist/scss-DmlHSoOY.js.map +1 -0
  83. package/dist/shellscript-CZpPN8_x.js +7 -0
  84. package/dist/shellscript-CZpPN8_x.js.map +1 -0
  85. package/dist/sql-DtlkUz2m.js +7 -0
  86. package/dist/sql-DtlkUz2m.js.map +1 -0
  87. package/dist/style.css +1 -1
  88. package/dist/stylus-DEr8eSLm.js +7 -0
  89. package/dist/stylus-DEr8eSLm.js.map +1 -0
  90. package/dist/svelte-BRIJF62h.js +15 -0
  91. package/dist/svelte-BRIJF62h.js.map +1 -0
  92. package/dist/ts-tags-qkUtuI0N.js +42 -0
  93. package/dist/ts-tags-qkUtuI0N.js.map +1 -0
  94. package/dist/tsx-DTfbgJxi.js +7 -0
  95. package/dist/tsx-DTfbgJxi.js.map +1 -0
  96. package/dist/typescript-CCd4aQHh.js +7 -0
  97. package/dist/typescript-CCd4aQHh.js.map +1 -0
  98. package/dist/vue-B3TdbERm.js +32 -0
  99. package/dist/vue-B3TdbERm.js.map +1 -0
  100. package/dist/vue-html-BGmTBZk0.js +11 -0
  101. package/dist/vue-html-BGmTBZk0.js.map +1 -0
  102. package/dist/wasm-VDIDph3E.js +7 -0
  103. package/dist/wasm-VDIDph3E.js.map +1 -0
  104. package/dist/webpack-stats.json +1 -1
  105. package/dist/wgsl-2np_U3Z8.js +7 -0
  106. package/dist/wgsl-2np_U3Z8.js.map +1 -0
  107. package/dist/xml-CNyphW9R.js +9 -0
  108. package/dist/xml-CNyphW9R.js.map +1 -0
  109. package/dist/yaml-DxFiVFcM.js +7 -0
  110. package/dist/yaml-DxFiVFcM.js.map +1 -0
  111. package/package.json +6 -4
  112. package/src/api/blockManipulation/commands/insertBlocks/__snapshots__/insertBlocks.test.ts.snap +30 -0
  113. package/src/api/blockManipulation/commands/mergeBlocks/__snapshots__/mergeBlocks.test.ts.snap +25 -0
  114. package/src/api/blockManipulation/commands/moveBlock/__snapshots__/moveBlock.test.ts.snap +40 -0
  115. package/src/api/blockManipulation/commands/removeBlocks/__snapshots__/removeBlocks.test.ts.snap +10 -0
  116. package/src/api/blockManipulation/commands/replaceBlocks/__snapshots__/replaceBlocks.test.ts.snap +40 -0
  117. package/src/api/blockManipulation/commands/splitBlock/__snapshots__/splitBlock.test.ts.snap +30 -0
  118. package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +87 -0
  119. package/src/api/clipboard/clipboard.test.ts +1 -1
  120. package/src/api/clipboard/fromClipboard/acceptedMIMETypes.ts +1 -0
  121. package/src/api/clipboard/fromClipboard/handleVSCodePaste.ts +49 -0
  122. package/src/api/clipboard/fromClipboard/pasteExtension.ts +6 -0
  123. package/src/api/exporters/html/__snapshots__/codeBlock/defaultLanguage/external.html +1 -0
  124. package/src/api/exporters/html/__snapshots__/codeBlock/defaultLanguage/internal.html +1 -0
  125. package/src/api/exporters/html/__snapshots__/codeBlock/empty/external.html +1 -0
  126. package/src/api/exporters/html/__snapshots__/codeBlock/empty/internal.html +1 -0
  127. package/src/api/exporters/html/__snapshots__/codeBlock/python/external.html +1 -0
  128. package/src/api/exporters/html/__snapshots__/codeBlock/python/internal.html +1 -0
  129. package/src/api/exporters/html/__snapshots__/image/basic/internal.html +1 -1
  130. package/src/api/exporters/html/__snapshots__/image/nested/internal.html +1 -1
  131. package/src/api/exporters/html/__snapshots__/image/noName/internal.html +1 -1
  132. package/src/api/exporters/html/__snapshots__/image/noPreview/internal.html +1 -1
  133. package/src/api/exporters/html/__snapshots__/lists/basic/internal.html +1 -1
  134. package/src/api/exporters/html/__snapshots__/lists/nested/internal.html +1 -1
  135. package/src/api/exporters/html/__snapshots__/simpleImage/basic/external.html +1 -1
  136. package/src/api/exporters/html/__snapshots__/simpleImage/basic/internal.html +1 -1
  137. package/src/api/exporters/html/__snapshots__/simpleImage/nested/external.html +1 -1
  138. package/src/api/exporters/html/__snapshots__/simpleImage/nested/internal.html +1 -1
  139. package/src/api/exporters/html/__snapshots__/simpleImage/noCaption/external.html +1 -1
  140. package/src/api/exporters/html/__snapshots__/simpleImage/noName/external.html +1 -1
  141. package/src/api/exporters/html/__snapshots__/simpleImage/noName/internal.html +1 -1
  142. package/src/api/exporters/html/__snapshots__/simpleImage/noPreview/external.html +1 -1
  143. package/src/api/exporters/html/__snapshots__/simpleImage/noPreview/internal.html +1 -1
  144. package/src/api/exporters/html/__snapshots__/table/allColWidths/external.html +1 -0
  145. package/src/api/exporters/html/__snapshots__/table/allColWidths/internal.html +1 -0
  146. package/src/api/exporters/html/__snapshots__/table/basic/external.html +1 -0
  147. package/src/api/exporters/html/__snapshots__/table/basic/internal.html +1 -0
  148. package/src/api/exporters/html/__snapshots__/table/mixedColWidths/external.html +1 -0
  149. package/src/api/exporters/html/__snapshots__/table/mixedColWidths/internal.html +1 -0
  150. package/src/api/exporters/html/internalHTMLSerializer.ts +2 -7
  151. package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +20 -15
  152. package/src/api/exporters/markdown/__snapshots__/codeBlock/defaultLanguage/markdown.md +3 -0
  153. package/src/api/exporters/markdown/__snapshots__/codeBlock/empty/markdown.md +2 -0
  154. package/src/api/exporters/markdown/__snapshots__/codeBlock/python/markdown.md +3 -0
  155. package/src/api/exporters/markdown/__snapshots__/table/allColWidths/markdown.md +5 -0
  156. package/src/api/exporters/markdown/__snapshots__/table/basic/markdown.md +5 -0
  157. package/src/api/exporters/markdown/__snapshots__/table/mixedColWidths/markdown.md +5 -0
  158. package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +711 -0
  159. package/src/api/nodeConversions/blockToNode.ts +13 -2
  160. package/src/api/nodeConversions/nodeToBlock.ts +11 -1
  161. package/src/api/parsers/html/__snapshots__/parse-notion-html.json +5 -0
  162. package/src/api/parsers/markdown/parseMarkdown.ts +1 -1
  163. package/src/api/testUtil/cases/defaultSchema.ts +95 -0
  164. package/src/api/testUtil/partialBlockTestUtil.ts +26 -1
  165. package/src/blocks/CodeBlockContent/CodeBlockContent.ts +369 -0
  166. package/src/blocks/CodeBlockContent/defaultSupportedLanguages.ts +96 -0
  167. package/src/blocks/FileBlockContent/fileBlockHelpers.ts +7 -0
  168. package/src/blocks/TableBlockContent/TableBlockContent.ts +83 -8
  169. package/src/blocks/TableBlockContent/TableExtension.ts +10 -1
  170. package/src/blocks/defaultBlocks.ts +4 -0
  171. package/src/editor/Block.css +49 -2
  172. package/src/editor/editor.css +33 -5
  173. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +8 -0
  174. package/src/extensions/Placeholder/PlaceholderPlugin.ts +5 -0
  175. package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +5 -0
  176. package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +2 -1
  177. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +18 -0
  178. package/src/extensions/TableHandles/TableHandlesPlugin.ts +224 -119
  179. package/src/i18n/locales/ar.ts +6 -0
  180. package/src/i18n/locales/de.ts +299 -294
  181. package/src/i18n/locales/en.ts +6 -0
  182. package/src/i18n/locales/es.ts +310 -274
  183. package/src/i18n/locales/fr.ts +6 -0
  184. package/src/i18n/locales/is.ts +6 -0
  185. package/src/i18n/locales/ja.ts +6 -0
  186. package/src/i18n/locales/ko.ts +6 -0
  187. package/src/i18n/locales/nl.ts +6 -0
  188. package/src/i18n/locales/pl.ts +6 -0
  189. package/src/i18n/locales/pt.ts +6 -0
  190. package/src/i18n/locales/ru.ts +6 -0
  191. package/src/i18n/locales/vi.ts +6 -0
  192. package/src/i18n/locales/zh.ts +6 -0
  193. package/src/index.ts +10 -5
  194. package/src/schema/blocks/types.ts +2 -0
  195. package/types/src/api/blockManipulation/setupTestEnv.d.ts +22 -8
  196. package/types/src/api/clipboard/fromClipboard/acceptedMIMETypes.d.ts +1 -1
  197. package/types/src/api/clipboard/fromClipboard/handleVSCodePaste.d.ts +3 -0
  198. package/types/src/api/exporters/html/util/serializeBlocksInternalHTML.d.ts +2 -3
  199. package/types/src/api/testUtil/cases/customBlocks.d.ts +22 -8
  200. package/types/src/api/testUtil/cases/customInlineContent.d.ts +22 -8
  201. package/types/src/api/testUtil/cases/customStyles.d.ts +22 -8
  202. package/types/src/blocks/CodeBlockContent/CodeBlockContent.d.ts +57 -0
  203. package/types/src/blocks/CodeBlockContent/defaultSupportedLanguages.d.ts +6 -0
  204. package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +0 -12
  205. package/types/src/blocks/TableBlockContent/TableExtension.d.ts +3 -0
  206. package/types/src/blocks/defaultBlocks.d.ts +45 -16
  207. package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +9 -5
  208. package/types/src/i18n/locales/de.d.ts +6 -0
  209. package/types/src/i18n/locales/en.d.ts +6 -0
  210. package/types/src/i18n/locales/es.d.ts +6 -0
  211. package/types/src/index.d.ts +7 -5
  212. package/types/src/schema/blocks/types.d.ts +2 -0
@@ -1,17 +1,22 @@
1
- import { mergeAttributes, Node } from "@tiptap/core";
1
+ import { Node } from "@tiptap/core";
2
2
  import { TableCell } from "@tiptap/extension-table-cell";
3
3
  import { TableHeader } from "@tiptap/extension-table-header";
4
4
  import { TableRow } from "@tiptap/extension-table-row";
5
+ import { Node as PMNode } from "prosemirror-model";
6
+ import { TableView } from "prosemirror-tables";
7
+
5
8
  import {
6
9
  createBlockSpecFromStronglyTypedTiptapNode,
7
10
  createStronglyTypedTiptapNode,
8
11
  } from "../../schema/index.js";
12
+ import { mergeCSSClasses } from "../../util/browser.js";
9
13
  import { createDefaultBlockDOMOutputSpec } from "../defaultBlockHelpers.js";
10
14
  import { defaultProps } from "../defaultProps.js";
11
- import { TableExtension } from "./TableExtension.js";
15
+ import { EMPTY_CELL_WIDTH, TableExtension } from "./TableExtension.js";
12
16
 
13
17
  export const tablePropSchema = {
14
- ...defaultProps,
18
+ backgroundColor: defaultProps.backgroundColor,
19
+ textColor: defaultProps.textColor,
15
20
  };
16
21
 
17
22
  export const TableBlockContent = createStronglyTypedTiptapNode({
@@ -37,6 +42,69 @@ export const TableBlockContent = createStronglyTypedTiptapNode({
37
42
  this.options.domAttributes?.inlineContent || {}
38
43
  );
39
44
  },
45
+
46
+ // This node view is needed for the `columnResizing` plugin. By default, the
47
+ // plugin adds its own node view, which overrides how the node is rendered vs
48
+ // `renderHTML`. This means that the wrapping `blockContent` HTML element is
49
+ // no longer rendered. The `columnResizing` plugin uses the `TableView` as its
50
+ // default node view. `BlockNoteTableView` extends it by wrapping it in a
51
+ // `blockContent` element, so the DOM structure is consistent with other block
52
+ // types.
53
+ addNodeView() {
54
+ return ({ node, HTMLAttributes }) => {
55
+ class BlockNoteTableView extends TableView {
56
+ constructor(
57
+ public node: PMNode,
58
+ public cellMinWidth: number,
59
+ public blockContentHTMLAttributes: Record<string, string>
60
+ ) {
61
+ super(node, cellMinWidth);
62
+
63
+ const blockContent = document.createElement("div");
64
+ blockContent.className = mergeCSSClasses(
65
+ "bn-block-content",
66
+ blockContentHTMLAttributes.class
67
+ );
68
+ blockContent.setAttribute("data-content-type", "table");
69
+ for (const [attribute, value] of Object.entries(
70
+ blockContentHTMLAttributes
71
+ )) {
72
+ if (attribute !== "class") {
73
+ blockContent.setAttribute(attribute, value);
74
+ }
75
+ }
76
+
77
+ const tableWrapper = this.dom;
78
+
79
+ const tableWrapperInner = document.createElement("div");
80
+ tableWrapperInner.className = "tableWrapper-inner";
81
+ tableWrapperInner.appendChild(tableWrapper.firstChild!);
82
+
83
+ tableWrapper.appendChild(tableWrapperInner);
84
+
85
+ blockContent.appendChild(tableWrapper);
86
+ const floatingContainer = document.createElement("div");
87
+ floatingContainer.className = "table-widgets-container";
88
+ floatingContainer.style.position = "relative";
89
+ tableWrapper.appendChild(floatingContainer);
90
+
91
+ this.dom = blockContent;
92
+ }
93
+
94
+ ignoreMutation(record: MutationRecord): boolean {
95
+ return (
96
+ !(record.target as HTMLElement).closest(".tableWrapper-inner") ||
97
+ super.ignoreMutation(record)
98
+ );
99
+ }
100
+ }
101
+
102
+ return new BlockNoteTableView(node, EMPTY_CELL_WIDTH, {
103
+ ...(this.options.domAttributes?.blockContent || {}),
104
+ ...HTMLAttributes,
105
+ });
106
+ };
107
+ },
40
108
  });
41
109
 
42
110
  const TableParagraph = Node.create({
@@ -46,6 +114,17 @@ const TableParagraph = Node.create({
46
114
 
47
115
  parseHTML() {
48
116
  return [
117
+ {
118
+ preserveWhitespace: "full",
119
+ // set this rule as high priority so it takes precedence over the default paragraph rule,
120
+ // but only if we're in the tableContent context
121
+ priority: 210,
122
+ context: "tableContent",
123
+ tag: "p",
124
+ getAttrs: (_element) => {
125
+ return {};
126
+ },
127
+ },
49
128
  {
50
129
  tag: "p",
51
130
  getAttrs: (element) => {
@@ -70,11 +149,7 @@ const TableParagraph = Node.create({
70
149
  },
71
150
 
72
151
  renderHTML({ HTMLAttributes }) {
73
- return [
74
- "p",
75
- mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
76
- 0,
77
- ];
152
+ return ["p", HTMLAttributes, 0];
78
153
  },
79
154
  });
80
155
 
@@ -1,13 +1,22 @@
1
1
  import { callOrReturn, Extension, getExtensionField } from "@tiptap/core";
2
2
  import { columnResizing, tableEditing } from "prosemirror-tables";
3
3
 
4
+ export const RESIZE_MIN_WIDTH = 35;
5
+ export const EMPTY_CELL_WIDTH = 120;
6
+ export const EMPTY_CELL_HEIGHT = 31;
7
+
4
8
  export const TableExtension = Extension.create({
5
9
  name: "BlockNoteTableExtension",
6
10
 
7
11
  addProseMirrorPlugins: () => {
8
12
  return [
9
13
  columnResizing({
10
- cellMinWidth: 100,
14
+ cellMinWidth: RESIZE_MIN_WIDTH,
15
+ defaultCellMinWidth: EMPTY_CELL_WIDTH,
16
+ // We set this to null as we implement our own node view in the table
17
+ // block content. This node view is the same as what's used by default,
18
+ // but is wrapped in a `blockContent` HTML element.
19
+ View: null,
11
20
  }),
12
21
  tableEditing(),
13
22
  ];
@@ -21,6 +21,7 @@ import {
21
21
  } from "../schema/index.js";
22
22
 
23
23
  import { AudioBlock } from "./AudioBlockContent/AudioBlockContent.js";
24
+ import { CodeBlock } from "./CodeBlockContent/CodeBlockContent.js";
24
25
  import { FileBlock } from "./FileBlockContent/FileBlockContent.js";
25
26
  import { Heading } from "./HeadingBlockContent/HeadingBlockContent.js";
26
27
  import { ImageBlock } from "./ImageBlockContent/ImageBlockContent.js";
@@ -31,9 +32,12 @@ import { Paragraph } from "./ParagraphBlockContent/ParagraphBlockContent.js";
31
32
  import { Table } from "./TableBlockContent/TableBlockContent.js";
32
33
  import { VideoBlock } from "./VideoBlockContent/VideoBlockContent.js";
33
34
 
35
+ export { customizeCodeBlock } from "./CodeBlockContent/CodeBlockContent.js";
36
+
34
37
  export const defaultBlockSpecs = {
35
38
  paragraph: Paragraph,
36
39
  heading: Heading,
40
+ codeBlock: CodeBlock,
37
41
  bulletListItem: BulletListItem,
38
42
  numberedListItem: NumberedListItem,
39
43
  checkListItem: CheckListItem,
@@ -196,7 +196,8 @@ NESTED BLOCKS
196
196
  cursor: pointer;
197
197
  }
198
198
 
199
- .bn-block-content[data-content-type="checkListItem"][data-checked="true"] .bn-inline-content {
199
+ .bn-block-content[data-content-type="checkListItem"][data-checked="true"]
200
+ .bn-inline-content {
200
201
  text-decoration: line-through;
201
202
  }
202
203
 
@@ -259,6 +260,51 @@ NESTED BLOCKS
259
260
  content: "▪";
260
261
  }
261
262
 
263
+ /* CODE BLOCKS */
264
+ .bn-block-content[data-content-type="codeBlock"] {
265
+ position: relative;
266
+
267
+ background-color: rgb(22 22 22);
268
+ color: white;
269
+ border-radius: 8px;
270
+ }
271
+ .bn-block-content[data-content-type="codeBlock"] > pre {
272
+ white-space: pre;
273
+ overflow-x: auto;
274
+ margin: 0;
275
+ width: 100%;
276
+ tab-size: 2;
277
+
278
+ padding: 24px;
279
+ }
280
+ .bn-block-content[data-content-type="codeBlock"] > div {
281
+ outline: none !important;
282
+ }
283
+ .bn-block-content[data-content-type="codeBlock"] > div > select {
284
+ outline: none !important;
285
+ appearance: none;
286
+ user-select: none;
287
+ border: none;
288
+ cursor: pointer;
289
+ background-color: transparent;
290
+
291
+ position: absolute;
292
+ top: 8px;
293
+ left: 18px;
294
+
295
+ font-size: 0.8em;
296
+ color: white;
297
+
298
+ opacity: 0;
299
+ transition: opacity 0.3s;
300
+ transition-delay: 1s;
301
+ }
302
+ .bn-block-content[data-content-type="codeBlock"]:hover > div > select,
303
+ .bn-block-content[data-content-type="codeBlock"] > div > select:focus {
304
+ opacity: 0.5;
305
+ transition-delay: 0.1s;
306
+ }
307
+
262
308
  /* FILES */
263
309
 
264
310
  /* Add block button & default preview */
@@ -349,7 +395,8 @@ NESTED BLOCKS
349
395
  cursor: ew-resize;
350
396
  }
351
397
 
352
- [data-content-type="audio"] > .bn-file-block-content-wrapper, .bn-audio {
398
+ [data-content-type="audio"] > .bn-file-block-content-wrapper,
399
+ .bn-audio {
353
400
  width: 100%;
354
401
  }
355
402
 
@@ -104,22 +104,50 @@ Tippy popups that are appended to document.body directly
104
104
  white-space: nowrap;
105
105
  }
106
106
 
107
+ /* .tableWrapper {
108
+ padding
109
+ } */
110
+
111
+ .ProseMirror .tableWrapper {
112
+ position: relative;
113
+ top: -16px;
114
+ left: -16px;
115
+ /* padding: 16px; */
116
+ min-width: calc(100% + 16px);
117
+ padding-bottom: 16px;
118
+ overflow-y: hidden;
119
+ }
120
+
121
+ .ProseMirror .tableWrapper-inner {
122
+ /* position: relative; */
123
+ /* top: -16px;
124
+ left: -16px; */
125
+ padding: 16px;
126
+ }
127
+
107
128
  /* table related: */
108
129
  .bn-editor table {
109
130
  width: auto !important;
131
+ word-break: break-word;
110
132
  }
111
133
  .bn-editor th,
112
134
  .bn-editor td {
113
- min-width: 1em;
114
135
  border: 1px solid #ddd;
115
136
  padding: 3px 5px;
116
137
  }
117
138
 
118
- .bn-editor .tableWrapper {
119
- margin: 1em 0;
120
- }
121
-
122
139
  .bn-editor th {
123
140
  font-weight: bold;
124
141
  text-align: left;
125
142
  }
143
+
144
+ /* tiptap uses colwidth instead of data-colwidth, se we need to adjust this style from prosemirror-tables */
145
+ .ProseMirror td,
146
+ .ProseMirror th {
147
+ min-width: auto !important;
148
+ }
149
+ .ProseMirror td:not([colwidth]):not(.column-resize-dragging),
150
+ .ProseMirror th:not([colwidth]):not(.column-resize-dragging) {
151
+ /* if there's no explicit width set and the column is not being resized, set a default width */
152
+ min-width: var(--default-cell-min-width) !important;
153
+ }
@@ -35,6 +35,14 @@ export class FormattingToolbarView implements PluginView {
35
35
  const isEmptyTextBlock =
36
36
  !doc.textBetween(from, to).length && isTextSelection(state.selection);
37
37
 
38
+ // Don't show toolbar inside code blocks
39
+ if (
40
+ selection.$from.parent.type.spec.code ||
41
+ (isNodeSelection(selection) && selection.node.type.spec.code)
42
+ ) {
43
+ return false;
44
+ }
45
+
38
46
  // check view.hasFocus so that the toolbar doesn't show up when the editor is not focused or when for example a code block is focused
39
47
  return !(!view.hasFocus() || empty || isEmptyTextBlock);
40
48
  };
@@ -88,6 +88,11 @@ export const PlaceholderPlugin = (
88
88
  return;
89
89
  }
90
90
 
91
+ // Don't show placeholder when the cursor is inside a code block
92
+ if (selection.$from.parent.type.spec.code) {
93
+ return;
94
+ }
95
+
91
96
  const $pos = selection.$anchor;
92
97
  const node = $pos.parent;
93
98
 
@@ -202,6 +202,11 @@ export class SuggestionMenuProseMirrorPlugin<
202
202
  return prev;
203
203
  }
204
204
 
205
+ // Ignore transactions in code blocks.
206
+ if (transaction.selection.$from.parent.type.spec.code) {
207
+ return prev;
208
+ }
209
+
205
210
  // Either contains the trigger character if the menu should be shown,
206
211
  // or null if it should be hidden.
207
212
  const suggestionPluginTransactionMeta: {
@@ -32,7 +32,8 @@ export async function getDefaultEmojiPickerItems<
32
32
  if (!data) {
33
33
  // use a dynamic import to encourage bundle-splitting
34
34
  // and a smaller initial client bundle size
35
- data = import("@emoji-mart/data", { assert: { type: "json" } }) as any;
35
+
36
+ data = import("@emoji-mart/data") as any;
36
37
 
37
38
  // load dynamically because emoji-mart doesn't specify type: module and breaks in nodejs
38
39
  emojiMart = await import("emoji-mart");
@@ -175,6 +175,24 @@ export function getDefaultSlashMenuItems<
175
175
  });
176
176
  }
177
177
 
178
+ if (checkDefaultBlockTypeInSchema("codeBlock", editor)) {
179
+ items.push({
180
+ onItemClick: () => {
181
+ const pos = editor._tiptapEditor.state.selection.from;
182
+
183
+ insertOrUpdateBlock(editor, {
184
+ type: "codeBlock",
185
+ });
186
+
187
+ // Move the cursor inside the code block
188
+ editor._tiptapEditor.commands.setTextSelection(pos);
189
+ },
190
+ badge: formatKeyboardShortcut("Mod-Alt-c"),
191
+ key: "code_block",
192
+ ...editor.dictionary.slash_menu.code_block,
193
+ });
194
+ }
195
+
178
196
  if (checkDefaultBlockTypeInSchema("table", editor)) {
179
197
  items.push({
180
198
  onItemClick: () => {