@atlaskit/editor-core 187.34.1 → 187.35.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 (94) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/index.js +10 -42
  3. package/dist/cjs/plugins/block-type/commands/block-type.js +19 -211
  4. package/dist/cjs/plugins/block-type/commands/index.js +2 -28
  5. package/dist/cjs/plugins/block-type/index.js +21 -4
  6. package/dist/cjs/plugins/block-type/pm-plugins/input-rule.js +9 -64
  7. package/dist/cjs/plugins/block-type/pm-plugins/keymap.js +1 -1
  8. package/dist/cjs/plugins/code-block/actions.js +83 -6
  9. package/dist/cjs/plugins/code-block/index.js +27 -12
  10. package/dist/cjs/plugins/code-block/pm-plugins/input-rule.js +68 -0
  11. package/dist/cjs/plugins/copy-button/commands.js +2 -1
  12. package/dist/cjs/plugins/date/ui/DatePicker/index.js +3 -2
  13. package/dist/cjs/plugins/expand/commands.js +3 -3
  14. package/dist/cjs/plugins/expand/index.js +2 -2
  15. package/dist/cjs/plugins/index.js +1 -7
  16. package/dist/cjs/plugins/insert-block/index.js +34 -29
  17. package/dist/cjs/plugins/panel/actions.js +26 -2
  18. package/dist/cjs/plugins/panel/index.js +9 -5
  19. package/dist/cjs/version-wrapper.js +1 -1
  20. package/dist/es2019/index.js +16 -2
  21. package/dist/es2019/plugins/block-type/commands/block-type.js +15 -217
  22. package/dist/es2019/plugins/block-type/commands/index.js +1 -3
  23. package/dist/es2019/plugins/block-type/index.js +21 -4
  24. package/dist/es2019/plugins/block-type/pm-plugins/input-rule.js +3 -56
  25. package/dist/es2019/plugins/block-type/pm-plugins/keymap.js +2 -2
  26. package/dist/es2019/plugins/code-block/actions.js +84 -3
  27. package/dist/es2019/plugins/code-block/index.js +22 -7
  28. package/dist/es2019/plugins/code-block/pm-plugins/input-rule.js +60 -0
  29. package/dist/es2019/plugins/copy-button/commands.js +2 -1
  30. package/dist/es2019/plugins/date/ui/DatePicker/index.js +3 -2
  31. package/dist/es2019/plugins/expand/commands.js +1 -1
  32. package/dist/es2019/plugins/expand/index.js +1 -1
  33. package/dist/es2019/plugins/index.js +0 -1
  34. package/dist/es2019/plugins/insert-block/index.js +47 -42
  35. package/dist/es2019/plugins/panel/actions.js +26 -2
  36. package/dist/es2019/plugins/panel/index.js +8 -4
  37. package/dist/es2019/version-wrapper.js +1 -1
  38. package/dist/esm/index.js +16 -2
  39. package/dist/esm/plugins/block-type/commands/block-type.js +17 -205
  40. package/dist/esm/plugins/block-type/commands/index.js +1 -3
  41. package/dist/esm/plugins/block-type/index.js +21 -4
  42. package/dist/esm/plugins/block-type/pm-plugins/input-rule.js +3 -58
  43. package/dist/esm/plugins/block-type/pm-plugins/keymap.js +2 -2
  44. package/dist/esm/plugins/code-block/actions.js +76 -3
  45. package/dist/esm/plugins/code-block/index.js +25 -11
  46. package/dist/esm/plugins/code-block/pm-plugins/input-rule.js +62 -0
  47. package/dist/esm/plugins/copy-button/commands.js +2 -1
  48. package/dist/esm/plugins/date/ui/DatePicker/index.js +3 -2
  49. package/dist/esm/plugins/expand/commands.js +1 -1
  50. package/dist/esm/plugins/expand/index.js +1 -1
  51. package/dist/esm/plugins/index.js +0 -1
  52. package/dist/esm/plugins/insert-block/index.js +27 -22
  53. package/dist/esm/plugins/panel/actions.js +24 -2
  54. package/dist/esm/plugins/panel/index.js +8 -4
  55. package/dist/esm/version-wrapper.js +1 -1
  56. package/dist/types/index.d.ts +16 -3
  57. package/dist/types/labs/next/presets/default.d.ts +6 -0
  58. package/dist/types/plugins/block-type/commands/block-type.d.ts +1 -25
  59. package/dist/types/plugins/block-type/commands/index.d.ts +1 -3
  60. package/dist/types/plugins/block-type/index.d.ts +10 -2
  61. package/dist/types/plugins/code-block/actions.d.ts +11 -0
  62. package/dist/types/plugins/code-block/index.d.ts +6 -1
  63. package/dist/types/plugins/code-block/pm-plugins/input-rule.d.ts +3 -0
  64. package/dist/types/plugins/date/ui/DatePicker/index.d.ts +2 -2
  65. package/dist/types/plugins/index.d.ts +0 -2
  66. package/dist/types/plugins/insert-block/types.d.ts +7 -1
  67. package/dist/types/plugins/panel/actions.d.ts +4 -1
  68. package/dist/types/plugins/panel/index.d.ts +11 -2
  69. package/dist/types-ts4.5/index.d.ts +16 -3
  70. package/dist/types-ts4.5/labs/next/presets/default.d.ts +6 -0
  71. package/dist/types-ts4.5/plugins/block-type/commands/block-type.d.ts +1 -25
  72. package/dist/types-ts4.5/plugins/block-type/commands/index.d.ts +1 -3
  73. package/dist/types-ts4.5/plugins/block-type/index.d.ts +10 -2
  74. package/dist/types-ts4.5/plugins/code-block/actions.d.ts +11 -0
  75. package/dist/types-ts4.5/plugins/code-block/index.d.ts +6 -1
  76. package/dist/types-ts4.5/plugins/code-block/pm-plugins/input-rule.d.ts +3 -0
  77. package/dist/types-ts4.5/plugins/date/ui/DatePicker/index.d.ts +2 -2
  78. package/dist/types-ts4.5/plugins/index.d.ts +0 -2
  79. package/dist/types-ts4.5/plugins/insert-block/types.d.ts +7 -1
  80. package/dist/types-ts4.5/plugins/panel/actions.d.ts +4 -1
  81. package/dist/types-ts4.5/plugins/panel/index.d.ts +9 -2
  82. package/package.json +5 -5
  83. package/report.api.md +62 -23
  84. package/tmp/api-report-tmp.d.ts +49 -15
  85. package/dist/cjs/plugins/block-type/commands/insert-block.js +0 -60
  86. package/dist/es2019/plugins/block-type/commands/insert-block.js +0 -55
  87. package/dist/esm/plugins/block-type/commands/insert-block.js +0 -53
  88. package/dist/types/plugins/block-type/commands/insert-block.d.ts +0 -5
  89. package/dist/types-ts4.5/plugins/block-type/commands/insert-block.d.ts +0 -5
  90. /package/dist/cjs/plugins/{block-type/commands → code-block}/transform-to-code-block.js +0 -0
  91. /package/dist/es2019/plugins/{block-type/commands → code-block}/transform-to-code-block.js +0 -0
  92. /package/dist/esm/plugins/{block-type/commands → code-block}/transform-to-code-block.js +0 -0
  93. /package/dist/types/plugins/{block-type/commands → code-block}/transform-to-code-block.d.ts +0 -0
  94. /package/dist/types-ts4.5/plugins/{block-type/commands → code-block}/transform-to-code-block.d.ts +0 -0
package/report.api.md CHANGED
@@ -28,6 +28,7 @@ import type { AllowedBlockTypes } from '@atlaskit/editor-common/types';
28
28
  import { AnalyticsEventPayload } from '@atlaskit/editor-common/analytics';
29
29
  import type { AnalyticsEventPayload as AnalyticsEventPayload_2 } from '@atlaskit/analytics-next/AnalyticsEvent';
30
30
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
31
+ import type { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
31
32
  import type { AnnotationTypes } from '@atlaskit/adf-schema';
32
33
  import { BrowserFreezetracking } from '@atlaskit/editor-common/types';
33
34
  import type { CardOptions } from '@atlaskit/editor-common/card';
@@ -37,6 +38,7 @@ import type { CollabEditOptions } from '@atlaskit/editor-common/collab';
37
38
  import { Color } from '@atlaskit/status/element';
38
39
  import { Command as Command_2 } from '@atlaskit/editor-common/types';
39
40
  import { ComponentType } from 'react';
41
+ import type { compositionPlugin } from '@atlaskit/editor-plugin-composition';
40
42
  import type { ConfigWithNodeInfo } from '@atlaskit/editor-plugin-floating-toolbar';
41
43
  import type { ContextIdentifierProvider } from '@atlaskit/editor-common/provider-factory';
42
44
  import type { ContextUpdateHandler } from '@atlaskit/editor-common/types';
@@ -45,6 +47,7 @@ import type { CreateUIAnalyticsEvent } from '@atlaskit/analytics-next';
45
47
  import { darkModeStatusColorPalette } from '@atlaskit/editor-common/ui-color';
46
48
  import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
47
49
  import type { DecorationsPlugin } from '@atlaskit/editor-plugin-decorations';
50
+ import type { decorationsPlugin } from '@atlaskit/editor-plugin-decorations';
48
51
  import { dedupe } from '@atlaskit/editor-common/utils';
49
52
  import { DEFAULT_BORDER_COLOR } from '@atlaskit/editor-common/ui-color';
50
53
  import type { DirectEditorProps } from '@atlaskit/editor-prosemirror/view';
@@ -270,9 +273,6 @@ type BeforeAndAfterToolbarComponents = {
270
273
  after: ReactComponents;
271
274
  };
272
275
 
273
- // @public (undocumented)
274
- export const blockPluginStateKey: PluginKey<BlockTypeState>;
275
-
276
276
  // @public (undocumented)
277
277
  interface BlockType {
278
278
  // (undocumented)
@@ -295,6 +295,23 @@ export type BlockTypeInputMethod =
295
295
  | INPUT_METHOD.SHORTCUT
296
296
  | INPUT_METHOD.TOOLBAR;
297
297
 
298
+ // @public (undocumented)
299
+ export type BlockTypePlugin = NextEditorPlugin<
300
+ 'blockType',
301
+ {
302
+ pluginConfiguration: BlockTypePluginOptions | undefined;
303
+ dependencies: [OptionalPlugin<typeof analyticsPlugin>];
304
+ sharedState: BlockTypeState | undefined;
305
+ actions: {
306
+ insertBlockQuote: (inputMethod: BlockTypeInputMethod) => Command_2;
307
+ setBlockType: (
308
+ name: string,
309
+ inputMethod: BlockTypeInputMethod,
310
+ ) => Command_2;
311
+ };
312
+ }
313
+ >;
314
+
298
315
  // @public (undocumented)
299
316
  interface BlockTypePluginOptions {
300
317
  // (undocumented)
@@ -348,6 +365,25 @@ interface CodeBlockOptions extends LongPressSelectionPluginOptions {
348
365
  appearance?: EditorAppearance | undefined;
349
366
  }
350
367
 
368
+ // @public (undocumented)
369
+ export type CodeBlockPlugin = typeof codeBlockPlugin;
370
+
371
+ // @public (undocumented)
372
+ const codeBlockPlugin: NextEditorPlugin<
373
+ 'codeBlock',
374
+ {
375
+ pluginConfiguration: CodeBlockOptions;
376
+ dependencies: [
377
+ typeof decorationsPlugin,
378
+ typeof compositionPlugin,
379
+ OptionalPlugin<typeof analyticsPlugin>,
380
+ ];
381
+ actions: {
382
+ insertCodeBlock: (inputMethod: INPUT_METHOD) => Command_2;
383
+ };
384
+ }
385
+ >;
386
+
351
387
  // @public (undocumented)
352
388
  export class CollapsedEditor extends React_2.Component<Props, State> {
353
389
  // (undocumented)
@@ -1097,16 +1133,6 @@ export type InsertBlockInputMethodToolbar =
1097
1133
  | INPUT_METHOD.INSERT_MENU
1098
1134
  | INPUT_METHOD.TOOLBAR;
1099
1135
 
1100
- // @public (undocumented)
1101
- export function insertBlockType(name: string): Command_2;
1102
-
1103
- // @public (undocumented)
1104
- export const insertBlockTypesWithAnalytics: (
1105
- name: string,
1106
- inputMethod: BlockTypeInputMethod,
1107
- editorAnalyticsApi: EditorAnalyticsAPI | undefined,
1108
- ) => Command_2;
1109
-
1110
1136
  // @public (undocumented)
1111
1137
  export const insertDate: (
1112
1138
  date?: DateType,
@@ -1557,6 +1583,24 @@ export const openDatePicker: () => Command;
1557
1583
 
1558
1584
  export { PaletteColor };
1559
1585
 
1586
+ // @public (undocumented)
1587
+ export type PanelPlugin = typeof panelPlugin;
1588
+
1589
+ // @public (undocumented)
1590
+ const panelPlugin: NextEditorPlugin<
1591
+ 'panel',
1592
+ {
1593
+ pluginConfiguration: PanelPluginOptions | undefined;
1594
+ dependencies: [
1595
+ typeof decorationsPlugin,
1596
+ OptionalPlugin<typeof analyticsPlugin>,
1597
+ ];
1598
+ actions: {
1599
+ insertPanel: (inputMethod: INPUT_METHOD) => Command_2;
1600
+ };
1601
+ }
1602
+ >;
1603
+
1560
1604
  // @public (undocumented)
1561
1605
  interface PanelPluginConfig {
1562
1606
  // (undocumented)
@@ -1565,6 +1609,11 @@ interface PanelPluginConfig {
1565
1609
  allowCustomPanelEdit?: boolean;
1566
1610
  }
1567
1611
 
1612
+ // @public (undocumented)
1613
+ interface PanelPluginOptions
1614
+ extends LongPressSelectionPluginOptions,
1615
+ PanelPluginConfig {}
1616
+
1568
1617
  // @public (undocumented)
1569
1618
  type PastePluginOptions = {
1570
1619
  cardOptions?: CardOptions;
@@ -1849,16 +1898,6 @@ export const selectionPluginKey: PluginKey<any>;
1849
1898
  // @public (undocumented)
1850
1899
  interface SelectionPluginOptions extends LongPressSelectionPluginOptions {}
1851
1900
 
1852
- // @public (undocumented)
1853
- export function setBlockType(name: string): Command_2;
1854
-
1855
- // @public (undocumented)
1856
- export function setBlockTypeWithAnalytics(
1857
- name: string,
1858
- inputMethod: BlockTypeInputMethod,
1859
- editorAnalyticsApi: EditorAnalyticsAPI | undefined,
1860
- ): Command_2;
1861
-
1862
1901
  // @public (undocumented)
1863
1902
  type SetEditorAPI = (editorApi: PublicPluginAPI<any>) => void;
1864
1903
 
@@ -17,6 +17,7 @@ import type { AllowedBlockTypes } from '@atlaskit/editor-common/types';
17
17
  import { AnalyticsEventPayload } from '@atlaskit/editor-common/analytics';
18
18
  import type { AnalyticsEventPayload as AnalyticsEventPayload_2 } from '@atlaskit/analytics-next/AnalyticsEvent';
19
19
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
20
+ import type { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
20
21
  import type { AnnotationTypes } from '@atlaskit/adf-schema';
21
22
  import { BrowserFreezetracking } from '@atlaskit/editor-common/types';
22
23
  import type { CardOptions } from '@atlaskit/editor-common/card';
@@ -26,6 +27,7 @@ import type { CollabEditOptions } from '@atlaskit/editor-common/collab';
26
27
  import { Color } from '@atlaskit/status/element';
27
28
  import { Command as Command_2 } from '@atlaskit/editor-common/types';
28
29
  import { ComponentType } from 'react';
30
+ import type { compositionPlugin } from '@atlaskit/editor-plugin-composition';
29
31
  import type { ConfigWithNodeInfo } from '@atlaskit/editor-plugin-floating-toolbar';
30
32
  import type { ContextIdentifierProvider } from '@atlaskit/editor-common/provider-factory';
31
33
  import type { ContextUpdateHandler } from '@atlaskit/editor-common/types';
@@ -34,6 +36,7 @@ import type { CreateUIAnalyticsEvent } from '@atlaskit/analytics-next';
34
36
  import { darkModeStatusColorPalette } from '@atlaskit/editor-common/ui-color';
35
37
  import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
36
38
  import type { DecorationsPlugin } from '@atlaskit/editor-plugin-decorations';
39
+ import type { decorationsPlugin } from '@atlaskit/editor-plugin-decorations';
37
40
  import { dedupe } from '@atlaskit/editor-common/utils';
38
41
  import { DEFAULT_BORDER_COLOR } from '@atlaskit/editor-common/ui-color';
39
42
  import type { DirectEditorProps } from '@atlaskit/editor-prosemirror/view';
@@ -258,9 +261,6 @@ type BeforeAndAfterToolbarComponents = {
258
261
  after: ReactComponents;
259
262
  };
260
263
 
261
- // @public (undocumented)
262
- export const blockPluginStateKey: PluginKey<BlockTypeState>;
263
-
264
264
  // @public (undocumented)
265
265
  interface BlockType {
266
266
  // (undocumented)
@@ -278,6 +278,17 @@ interface BlockType {
278
278
  // @public (undocumented)
279
279
  export type BlockTypeInputMethod = INPUT_METHOD.FORMATTING | INPUT_METHOD.INSERT_MENU | INPUT_METHOD.KEYBOARD | INPUT_METHOD.SHORTCUT | INPUT_METHOD.TOOLBAR;
280
280
 
281
+ // @public (undocumented)
282
+ export type BlockTypePlugin = NextEditorPlugin<'blockType', {
283
+ pluginConfiguration: BlockTypePluginOptions | undefined;
284
+ dependencies: [OptionalPlugin<typeof analyticsPlugin>];
285
+ sharedState: BlockTypeState | undefined;
286
+ actions: {
287
+ insertBlockQuote: (inputMethod: BlockTypeInputMethod) => Command_2;
288
+ setBlockType: (name: string, inputMethod: BlockTypeInputMethod) => Command_2;
289
+ };
290
+ }>;
291
+
281
292
  // @public (undocumented)
282
293
  interface BlockTypePluginOptions {
283
294
  // (undocumented)
@@ -331,6 +342,22 @@ interface CodeBlockOptions extends LongPressSelectionPluginOptions {
331
342
  appearance?: EditorAppearance | undefined;
332
343
  }
333
344
 
345
+ // @public (undocumented)
346
+ export type CodeBlockPlugin = typeof codeBlockPlugin;
347
+
348
+ // @public (undocumented)
349
+ const codeBlockPlugin: NextEditorPlugin<'codeBlock', {
350
+ pluginConfiguration: CodeBlockOptions;
351
+ dependencies: [
352
+ typeof decorationsPlugin,
353
+ typeof compositionPlugin,
354
+ OptionalPlugin<typeof analyticsPlugin>
355
+ ];
356
+ actions: {
357
+ insertCodeBlock: (inputMethod: INPUT_METHOD) => Command_2;
358
+ };
359
+ }>;
360
+
334
361
  // @public (undocumented)
335
362
  export class CollapsedEditor extends React_2.Component<Props, State> {
336
363
  // (undocumented)
@@ -1012,12 +1039,6 @@ export { INPUT_METHOD }
1012
1039
  // @public (undocumented)
1013
1040
  export type InsertBlockInputMethodToolbar = INPUT_METHOD.INSERT_MENU | INPUT_METHOD.TOOLBAR;
1014
1041
 
1015
- // @public (undocumented)
1016
- export function insertBlockType(name: string): Command_2;
1017
-
1018
- // @public (undocumented)
1019
- export const insertBlockTypesWithAnalytics: (name: string, inputMethod: BlockTypeInputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined) => Command_2;
1020
-
1021
1042
  // @public (undocumented)
1022
1043
  export const insertDate: (date?: DateType, inputMethod?: InsertBlockInputMethodToolbar, commitMethod?: INPUT_METHOD.KEYBOARD | INPUT_METHOD.PICKER, enterPressed?: boolean) => Command;
1023
1044
 
@@ -1394,6 +1415,21 @@ export const openDatePicker: () => Command;
1394
1415
 
1395
1416
  export { PaletteColor }
1396
1417
 
1418
+ // @public (undocumented)
1419
+ export type PanelPlugin = typeof panelPlugin;
1420
+
1421
+ // @public (undocumented)
1422
+ const panelPlugin: NextEditorPlugin<'panel', {
1423
+ pluginConfiguration: PanelPluginOptions | undefined;
1424
+ dependencies: [
1425
+ typeof decorationsPlugin,
1426
+ OptionalPlugin<typeof analyticsPlugin>
1427
+ ];
1428
+ actions: {
1429
+ insertPanel: (inputMethod: INPUT_METHOD) => Command_2;
1430
+ };
1431
+ }>;
1432
+
1397
1433
  // @public (undocumented)
1398
1434
  interface PanelPluginConfig {
1399
1435
  // (undocumented)
@@ -1402,6 +1438,10 @@ interface PanelPluginConfig {
1402
1438
  allowCustomPanelEdit?: boolean;
1403
1439
  }
1404
1440
 
1441
+ // @public (undocumented)
1442
+ interface PanelPluginOptions extends LongPressSelectionPluginOptions, PanelPluginConfig {
1443
+ }
1444
+
1405
1445
  // @public (undocumented)
1406
1446
  type PastePluginOptions = {
1407
1447
  cardOptions?: CardOptions;
@@ -1655,12 +1695,6 @@ export const selectionPluginKey: PluginKey<any>;
1655
1695
  interface SelectionPluginOptions extends LongPressSelectionPluginOptions {
1656
1696
  }
1657
1697
 
1658
- // @public (undocumented)
1659
- export function setBlockType(name: string): Command_2;
1660
-
1661
- // @public (undocumented)
1662
- export function setBlockTypeWithAnalytics(name: string, inputMethod: BlockTypeInputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined): Command_2;
1663
-
1664
1698
  // @public (undocumented)
1665
1699
  type SetEditorAPI = (editorApi: PublicPluginAPI<any>) => void;
1666
1700
 
@@ -1,60 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.insertBlock = void 0;
7
- var _utils = require("@atlaskit/editor-prosemirror/utils");
8
- var _state = require("@atlaskit/editor-prosemirror/state");
9
- var insertBlock = function insertBlock(state, nodeType, nodeName, start, end, attrs) {
10
- // To ensure that match is done after HardBreak.
11
- var _state$schema$nodes = state.schema.nodes,
12
- hardBreak = _state$schema$nodes.hardBreak,
13
- codeBlock = _state$schema$nodes.codeBlock,
14
- listItem = _state$schema$nodes.listItem;
15
- var $pos = state.doc.resolve(start);
16
- if ($pos.nodeAfter.type !== hardBreak) {
17
- return null;
18
- }
19
-
20
- // To ensure no nesting is done. (unless we're inserting a codeBlock inside lists)
21
- if ($pos.depth > 1 && !(nodeType === codeBlock && (0, _utils.hasParentNodeOfType)(listItem)(state.selection))) {
22
- return null;
23
- }
24
-
25
- // Split at the start of autoformatting and delete formatting characters.
26
- var tr = state.tr.delete(start, end).split(start);
27
- var currentNode = tr.doc.nodeAt(start + 1);
28
-
29
- // If node has more content split at the end of autoformatting.
30
- var nodeHasMoreContent = false;
31
- tr.doc.nodesBetween(start, start + currentNode.nodeSize, function (node, pos) {
32
- if (!nodeHasMoreContent && node.type === hardBreak) {
33
- nodeHasMoreContent = true;
34
- tr = tr.split(pos + 1).delete(pos, pos + 1);
35
- }
36
- });
37
- if (nodeHasMoreContent) {
38
- currentNode = tr.doc.nodeAt(start + 1);
39
- }
40
-
41
- // Create new node and fill with content of current node.
42
- var _state$schema$nodes2 = state.schema.nodes,
43
- blockquote = _state$schema$nodes2.blockquote,
44
- paragraph = _state$schema$nodes2.paragraph;
45
- var content;
46
- var depth;
47
- if (nodeType === blockquote) {
48
- depth = 3;
49
- content = [paragraph.create({}, currentNode.content)];
50
- } else {
51
- depth = 2;
52
- content = currentNode.content;
53
- }
54
- var newNode = nodeType.create(attrs, content);
55
-
56
- // Add new node.
57
- tr = tr.setSelection(new _state.NodeSelection(tr.doc.resolve(start + 1))).replaceSelectionWith(newNode).setSelection(new _state.TextSelection(tr.doc.resolve(start + depth)));
58
- return tr;
59
- };
60
- exports.insertBlock = insertBlock;
@@ -1,55 +0,0 @@
1
- import { hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
2
- import { TextSelection, NodeSelection } from '@atlaskit/editor-prosemirror/state';
3
- export const insertBlock = (state, nodeType, nodeName, start, end, attrs) => {
4
- // To ensure that match is done after HardBreak.
5
- const {
6
- hardBreak,
7
- codeBlock,
8
- listItem
9
- } = state.schema.nodes;
10
- const $pos = state.doc.resolve(start);
11
- if ($pos.nodeAfter.type !== hardBreak) {
12
- return null;
13
- }
14
-
15
- // To ensure no nesting is done. (unless we're inserting a codeBlock inside lists)
16
- if ($pos.depth > 1 && !(nodeType === codeBlock && hasParentNodeOfType(listItem)(state.selection))) {
17
- return null;
18
- }
19
-
20
- // Split at the start of autoformatting and delete formatting characters.
21
- let tr = state.tr.delete(start, end).split(start);
22
- let currentNode = tr.doc.nodeAt(start + 1);
23
-
24
- // If node has more content split at the end of autoformatting.
25
- let nodeHasMoreContent = false;
26
- tr.doc.nodesBetween(start, start + currentNode.nodeSize, (node, pos) => {
27
- if (!nodeHasMoreContent && node.type === hardBreak) {
28
- nodeHasMoreContent = true;
29
- tr = tr.split(pos + 1).delete(pos, pos + 1);
30
- }
31
- });
32
- if (nodeHasMoreContent) {
33
- currentNode = tr.doc.nodeAt(start + 1);
34
- }
35
-
36
- // Create new node and fill with content of current node.
37
- const {
38
- blockquote,
39
- paragraph
40
- } = state.schema.nodes;
41
- let content;
42
- let depth;
43
- if (nodeType === blockquote) {
44
- depth = 3;
45
- content = [paragraph.create({}, currentNode.content)];
46
- } else {
47
- depth = 2;
48
- content = currentNode.content;
49
- }
50
- const newNode = nodeType.create(attrs, content);
51
-
52
- // Add new node.
53
- tr = tr.setSelection(new NodeSelection(tr.doc.resolve(start + 1))).replaceSelectionWith(newNode).setSelection(new TextSelection(tr.doc.resolve(start + depth)));
54
- return tr;
55
- };
@@ -1,53 +0,0 @@
1
- import { hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
2
- import { TextSelection, NodeSelection } from '@atlaskit/editor-prosemirror/state';
3
- export var insertBlock = function insertBlock(state, nodeType, nodeName, start, end, attrs) {
4
- // To ensure that match is done after HardBreak.
5
- var _state$schema$nodes = state.schema.nodes,
6
- hardBreak = _state$schema$nodes.hardBreak,
7
- codeBlock = _state$schema$nodes.codeBlock,
8
- listItem = _state$schema$nodes.listItem;
9
- var $pos = state.doc.resolve(start);
10
- if ($pos.nodeAfter.type !== hardBreak) {
11
- return null;
12
- }
13
-
14
- // To ensure no nesting is done. (unless we're inserting a codeBlock inside lists)
15
- if ($pos.depth > 1 && !(nodeType === codeBlock && hasParentNodeOfType(listItem)(state.selection))) {
16
- return null;
17
- }
18
-
19
- // Split at the start of autoformatting and delete formatting characters.
20
- var tr = state.tr.delete(start, end).split(start);
21
- var currentNode = tr.doc.nodeAt(start + 1);
22
-
23
- // If node has more content split at the end of autoformatting.
24
- var nodeHasMoreContent = false;
25
- tr.doc.nodesBetween(start, start + currentNode.nodeSize, function (node, pos) {
26
- if (!nodeHasMoreContent && node.type === hardBreak) {
27
- nodeHasMoreContent = true;
28
- tr = tr.split(pos + 1).delete(pos, pos + 1);
29
- }
30
- });
31
- if (nodeHasMoreContent) {
32
- currentNode = tr.doc.nodeAt(start + 1);
33
- }
34
-
35
- // Create new node and fill with content of current node.
36
- var _state$schema$nodes2 = state.schema.nodes,
37
- blockquote = _state$schema$nodes2.blockquote,
38
- paragraph = _state$schema$nodes2.paragraph;
39
- var content;
40
- var depth;
41
- if (nodeType === blockquote) {
42
- depth = 3;
43
- content = [paragraph.create({}, currentNode.content)];
44
- } else {
45
- depth = 2;
46
- content = currentNode.content;
47
- }
48
- var newNode = nodeType.create(attrs, content);
49
-
50
- // Add new node.
51
- tr = tr.setSelection(new NodeSelection(tr.doc.resolve(start + 1))).replaceSelectionWith(newNode).setSelection(new TextSelection(tr.doc.resolve(start + depth)));
52
- return tr;
53
- };
@@ -1,5 +0,0 @@
1
- import type { NodeType } from '@atlaskit/editor-prosemirror/model';
2
- import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
3
- export declare const insertBlock: (state: EditorState, nodeType: NodeType, nodeName: string, start: number, end: number, attrs?: {
4
- [key: string]: any;
5
- } | undefined) => Transaction | null;
@@ -1,5 +0,0 @@
1
- import type { NodeType } from '@atlaskit/editor-prosemirror/model';
2
- import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
3
- export declare const insertBlock: (state: EditorState, nodeType: NodeType, nodeName: string, start: number, end: number, attrs?: {
4
- [key: string]: any;
5
- } | undefined) => Transaction | null;