@atlaskit/editor-plugin-code-block 0.1.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 (126) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/LICENSE.md +13 -0
  3. package/README.md +30 -0
  4. package/dist/cjs/actions.js +201 -0
  5. package/dist/cjs/ide-ux/bracket-handling.js +35 -0
  6. package/dist/cjs/ide-ux/commands.js +115 -0
  7. package/dist/cjs/ide-ux/line-handling.js +81 -0
  8. package/dist/cjs/ide-ux/paired-character-handling.js +23 -0
  9. package/dist/cjs/ide-ux/quote-handling.js +40 -0
  10. package/dist/cjs/index.js +13 -0
  11. package/dist/cjs/language-list.js +62 -0
  12. package/dist/cjs/nodeviews/code-block.js +153 -0
  13. package/dist/cjs/plugin-key.js +8 -0
  14. package/dist/cjs/plugin.js +120 -0
  15. package/dist/cjs/pm-plugins/actions.js +10 -0
  16. package/dist/cjs/pm-plugins/codeBlockCopySelectionPlugin.js +113 -0
  17. package/dist/cjs/pm-plugins/ide-ux.js +132 -0
  18. package/dist/cjs/pm-plugins/input-rule.js +68 -0
  19. package/dist/cjs/pm-plugins/keymaps.js +66 -0
  20. package/dist/cjs/pm-plugins/main-state.js +10 -0
  21. package/dist/cjs/pm-plugins/main.js +114 -0
  22. package/dist/cjs/refresh-browser-selection.js +29 -0
  23. package/dist/cjs/toolbar.js +131 -0
  24. package/dist/cjs/transform-to-code-block.js +84 -0
  25. package/dist/cjs/types.js +5 -0
  26. package/dist/cjs/ui/class-names.js +15 -0
  27. package/dist/cjs/utils.js +28 -0
  28. package/dist/es2019/actions.js +211 -0
  29. package/dist/es2019/ide-ux/bracket-handling.js +27 -0
  30. package/dist/es2019/ide-ux/commands.js +115 -0
  31. package/dist/es2019/ide-ux/line-handling.js +75 -0
  32. package/dist/es2019/ide-ux/paired-character-handling.js +12 -0
  33. package/dist/es2019/ide-ux/quote-handling.js +32 -0
  34. package/dist/es2019/index.js +1 -0
  35. package/dist/es2019/language-list.js +51 -0
  36. package/dist/es2019/nodeviews/code-block.js +126 -0
  37. package/dist/es2019/plugin-key.js +2 -0
  38. package/dist/es2019/plugin.js +104 -0
  39. package/dist/es2019/pm-plugins/actions.js +4 -0
  40. package/dist/es2019/pm-plugins/codeBlockCopySelectionPlugin.js +101 -0
  41. package/dist/es2019/pm-plugins/ide-ux.js +135 -0
  42. package/dist/es2019/pm-plugins/input-rule.js +60 -0
  43. package/dist/es2019/pm-plugins/keymaps.js +58 -0
  44. package/dist/es2019/pm-plugins/main-state.js +2 -0
  45. package/dist/es2019/pm-plugins/main.js +102 -0
  46. package/dist/es2019/refresh-browser-selection.js +25 -0
  47. package/dist/es2019/toolbar.js +108 -0
  48. package/dist/es2019/transform-to-code-block.js +79 -0
  49. package/dist/es2019/types.js +1 -0
  50. package/dist/es2019/ui/class-names.js +9 -0
  51. package/dist/es2019/utils.js +4 -0
  52. package/dist/esm/actions.js +191 -0
  53. package/dist/esm/ide-ux/bracket-handling.js +29 -0
  54. package/dist/esm/ide-ux/commands.js +107 -0
  55. package/dist/esm/ide-ux/line-handling.js +73 -0
  56. package/dist/esm/ide-ux/paired-character-handling.js +16 -0
  57. package/dist/esm/ide-ux/quote-handling.js +34 -0
  58. package/dist/esm/index.js +1 -0
  59. package/dist/esm/language-list.js +52 -0
  60. package/dist/esm/nodeviews/code-block.js +146 -0
  61. package/dist/esm/plugin-key.js +2 -0
  62. package/dist/esm/plugin.js +113 -0
  63. package/dist/esm/pm-plugins/actions.js +4 -0
  64. package/dist/esm/pm-plugins/codeBlockCopySelectionPlugin.js +103 -0
  65. package/dist/esm/pm-plugins/ide-ux.js +126 -0
  66. package/dist/esm/pm-plugins/input-rule.js +62 -0
  67. package/dist/esm/pm-plugins/keymaps.js +59 -0
  68. package/dist/esm/pm-plugins/main-state.js +4 -0
  69. package/dist/esm/pm-plugins/main.js +107 -0
  70. package/dist/esm/refresh-browser-selection.js +25 -0
  71. package/dist/esm/toolbar.js +121 -0
  72. package/dist/esm/transform-to-code-block.js +77 -0
  73. package/dist/esm/types.js +1 -0
  74. package/dist/esm/ui/class-names.js +9 -0
  75. package/dist/esm/utils.js +4 -0
  76. package/dist/types/actions.d.ts +18 -0
  77. package/dist/types/ide-ux/bracket-handling.d.ts +12 -0
  78. package/dist/types/ide-ux/commands.d.ts +7 -0
  79. package/dist/types/ide-ux/line-handling.d.ts +25 -0
  80. package/dist/types/ide-ux/paired-character-handling.d.ts +2 -0
  81. package/dist/types/ide-ux/quote-handling.d.ts +12 -0
  82. package/dist/types/index.d.ts +3 -0
  83. package/dist/types/language-list.d.ts +942 -0
  84. package/dist/types/nodeviews/code-block.d.ts +21 -0
  85. package/dist/types/plugin-key.d.ts +2 -0
  86. package/dist/types/plugin.d.ts +19 -0
  87. package/dist/types/pm-plugins/actions.d.ts +4 -0
  88. package/dist/types/pm-plugins/codeBlockCopySelectionPlugin.d.ts +11 -0
  89. package/dist/types/pm-plugins/ide-ux.d.ts +5 -0
  90. package/dist/types/pm-plugins/input-rule.d.ts +3 -0
  91. package/dist/types/pm-plugins/keymaps.d.ts +4 -0
  92. package/dist/types/pm-plugins/main-state.d.ts +8 -0
  93. package/dist/types/pm-plugins/main.d.ts +10 -0
  94. package/dist/types/refresh-browser-selection.d.ts +5 -0
  95. package/dist/types/toolbar.d.ts +14 -0
  96. package/dist/types/transform-to-code-block.d.ts +3 -0
  97. package/dist/types/types.d.ts +6 -0
  98. package/dist/types/ui/class-names.d.ts +8 -0
  99. package/dist/types/utils.d.ts +4 -0
  100. package/dist/types-ts4.5/actions.d.ts +18 -0
  101. package/dist/types-ts4.5/ide-ux/bracket-handling.d.ts +12 -0
  102. package/dist/types-ts4.5/ide-ux/commands.d.ts +7 -0
  103. package/dist/types-ts4.5/ide-ux/line-handling.d.ts +25 -0
  104. package/dist/types-ts4.5/ide-ux/paired-character-handling.d.ts +2 -0
  105. package/dist/types-ts4.5/ide-ux/quote-handling.d.ts +12 -0
  106. package/dist/types-ts4.5/index.d.ts +3 -0
  107. package/dist/types-ts4.5/language-list.d.ts +1641 -0
  108. package/dist/types-ts4.5/nodeviews/code-block.d.ts +21 -0
  109. package/dist/types-ts4.5/plugin-key.d.ts +2 -0
  110. package/dist/types-ts4.5/plugin.d.ts +19 -0
  111. package/dist/types-ts4.5/pm-plugins/actions.d.ts +4 -0
  112. package/dist/types-ts4.5/pm-plugins/codeBlockCopySelectionPlugin.d.ts +14 -0
  113. package/dist/types-ts4.5/pm-plugins/ide-ux.d.ts +5 -0
  114. package/dist/types-ts4.5/pm-plugins/input-rule.d.ts +3 -0
  115. package/dist/types-ts4.5/pm-plugins/keymaps.d.ts +4 -0
  116. package/dist/types-ts4.5/pm-plugins/main-state.d.ts +8 -0
  117. package/dist/types-ts4.5/pm-plugins/main.d.ts +10 -0
  118. package/dist/types-ts4.5/refresh-browser-selection.d.ts +5 -0
  119. package/dist/types-ts4.5/toolbar.d.ts +14 -0
  120. package/dist/types-ts4.5/transform-to-code-block.d.ts +3 -0
  121. package/dist/types-ts4.5/types.d.ts +6 -0
  122. package/dist/types-ts4.5/ui/class-names.d.ts +8 -0
  123. package/dist/types-ts4.5/utils.d.ts +4 -0
  124. package/package.json +99 -0
  125. package/report.api.md +73 -0
  126. package/tmp/api-report-tmp.d.ts +45 -0
@@ -0,0 +1,21 @@
1
+ import type { getPosHandler, getPosHandlerNode } from '@atlaskit/editor-common/types';
2
+ import type { Node } from '@atlaskit/editor-prosemirror/model';
3
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
+ export declare class CodeBlockView {
5
+ node: Node;
6
+ dom: HTMLElement;
7
+ contentDOM: HTMLElement;
8
+ lineNumberGutter: HTMLElement;
9
+ getPos: getPosHandlerNode;
10
+ view: EditorView;
11
+ constructor(node: Node, view: EditorView, getPos: getPosHandlerNode);
12
+ updateDOMAndSelection(savedInnerHTML: string, newCursorPosition: number): void;
13
+ coalesceDOMElements(): void;
14
+ private ensureLineNumbers;
15
+ update(node: Node): boolean;
16
+ ignoreMutation(record: MutationRecord | {
17
+ type: 'selection';
18
+ target: Element;
19
+ }): boolean;
20
+ }
21
+ export declare const codeBlockNodeView: (node: Node, view: EditorView, getPos: getPosHandler) => CodeBlockView;
@@ -0,0 +1,2 @@
1
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const pluginKey: PluginKey<any>;
@@ -0,0 +1,19 @@
1
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
+ import type { Command, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
3
+ import type { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
4
+ import type { compositionPlugin } from '@atlaskit/editor-plugin-composition';
5
+ import type { decorationsPlugin } from '@atlaskit/editor-plugin-decorations';
6
+ import type { CodeBlockOptions } from './types';
7
+ export type CodeBlockPlugin = NextEditorPlugin<'codeBlock', {
8
+ pluginConfiguration: CodeBlockOptions;
9
+ dependencies: [
10
+ typeof decorationsPlugin,
11
+ typeof compositionPlugin,
12
+ OptionalPlugin<typeof analyticsPlugin>
13
+ ];
14
+ actions: {
15
+ insertCodeBlock: (inputMethod: INPUT_METHOD) => Command;
16
+ };
17
+ }>;
18
+ declare const codeBlockPlugin: CodeBlockPlugin;
19
+ export default codeBlockPlugin;
@@ -0,0 +1,4 @@
1
+ export declare const ACTIONS: {
2
+ SET_COPIED_TO_CLIPBOARD: string;
3
+ SET_SHOULD_IGNORE_FOLLOWING_MUTATIONS: string;
4
+ };
@@ -0,0 +1,11 @@
1
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
+ import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
4
+ export declare const copySelectionPluginKey: PluginKey<any>;
5
+ type CodeBlockCopySelectionPluginState = {
6
+ decorationStartAndEnd?: [start: number, end: number];
7
+ };
8
+ export declare function codeBlockCopySelectionPlugin(): SafePlugin<CodeBlockCopySelectionPluginState>;
9
+ export declare function provideVisualFeedbackForCopyButton(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
10
+ export declare function removeVisualFeedbackForCopyButton(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
11
+ export {};
@@ -0,0 +1,5 @@
1
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { CodeBlockPlugin } from '../index';
4
+ declare const ideUX: (pluginInjectionApi: ExtractInjectionAPI<CodeBlockPlugin> | undefined) => SafePlugin<any>;
5
+ export default ideUX;
@@ -0,0 +1,3 @@
1
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
+ import type { Schema } from '@atlaskit/editor-prosemirror/model';
3
+ export declare function createCodeBlockInputRule(schema: Schema, editorAnalyticsAPI?: EditorAnalyticsAPI): import("@atlaskit/editor-common/safe-plugin").SafePlugin<any>;
@@ -0,0 +1,4 @@
1
+ import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import type { Schema } from '@atlaskit/editor-prosemirror/model';
3
+ export declare function keymapPlugin(schema: Schema): SafePlugin | undefined;
4
+ export default keymapPlugin;
@@ -0,0 +1,8 @@
1
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
2
+ export type CodeBlockState = {
3
+ pos: number | null;
4
+ contentCopied: boolean;
5
+ isNodeSelected: boolean;
6
+ shouldIgnoreFollowingMutations: boolean;
7
+ };
8
+ export declare const getPluginState: (state: EditorState) => CodeBlockState;
@@ -0,0 +1,10 @@
1
+ import type { IntlShape } from 'react-intl-next';
2
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import type { EditorAppearance } from '@atlaskit/editor-common/types';
4
+ import type { CodeBlockState } from './main-state';
5
+ export declare const createPlugin: ({ useLongPressSelection, getIntl, appearance, allowCompositionInputOverride, }: {
6
+ useLongPressSelection?: boolean | undefined;
7
+ getIntl: () => IntlShape;
8
+ appearance: EditorAppearance;
9
+ allowCompositionInputOverride?: boolean | undefined;
10
+ }) => SafePlugin<CodeBlockState>;
@@ -0,0 +1,5 @@
1
+ import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ declare const refreshBrowserSelection: () => void;
3
+ declare const refreshBrowserSelectionOnChange: (transaction: Readonly<Transaction>, editorState: EditorState) => void;
4
+ export default refreshBrowserSelectionOnChange;
5
+ export { refreshBrowserSelection };
@@ -0,0 +1,14 @@
1
+ import type { ExtractInjectionAPI, FloatingToolbarHandler, SelectOption } from '@atlaskit/editor-common/types';
2
+ import type { CodeBlockPlugin } from './index';
3
+ export declare const messages: {
4
+ selectLanguage: {
5
+ id: string;
6
+ defaultMessage: string;
7
+ description: string;
8
+ };
9
+ };
10
+ export declare const getToolbarConfig: (allowCopyToClipboard: boolean | undefined, api: ExtractInjectionAPI<CodeBlockPlugin> | undefined) => FloatingToolbarHandler;
11
+ /**
12
+ * Filters language list based on both name and alias properties.
13
+ */
14
+ export declare const languageListFilter: (option: SelectOption, rawInput: string) => any;
@@ -0,0 +1,3 @@
1
+ import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ export declare function transformToCodeBlockAction(state: EditorState, start: number, attrs?: any): Transaction;
3
+ export declare function isConvertableToCodeBlock(state: EditorState): boolean;
@@ -0,0 +1,6 @@
1
+ import type { EditorAppearance, LongPressSelectionPluginOptions } from '@atlaskit/editor-common/types';
2
+ export interface CodeBlockOptions extends LongPressSelectionPluginOptions {
3
+ allowCopyToClipboard?: boolean;
4
+ allowCompositionInputOverride?: boolean;
5
+ appearance?: EditorAppearance | undefined;
6
+ }
@@ -0,0 +1,8 @@
1
+ export declare const codeBlockClassNames: {
2
+ container: string;
3
+ start: string;
4
+ end: string;
5
+ contentWrapper: string;
6
+ gutter: string;
7
+ content: string;
8
+ };
@@ -0,0 +1,4 @@
1
+ export { findCodeBlock, transformSliceToJoinAdjacentCodeBlocks, transformSingleLineCodeBlockToCodeMark, } from '@atlaskit/editor-common/transforms';
2
+ import type { ResolvedPos } from '@atlaskit/editor-prosemirror/model';
3
+ import type { Selection } from '@atlaskit/editor-prosemirror/state';
4
+ export declare function getCursor(selection: Selection): ResolvedPos | undefined;
@@ -0,0 +1,18 @@
1
+ import type { EditorAnalyticsAPI, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
+ import type { Command } from '@atlaskit/editor-common/types';
3
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
4
+ export declare const removeCodeBlock: Command;
5
+ export declare const changeLanguage: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (language: string) => Command;
6
+ export declare const copyContentToClipboard: Command;
7
+ export declare const resetCopiedState: Command;
8
+ export declare const ignoreFollowingMutations: Command;
9
+ export declare const resetShouldIgnoreFollowingMutations: Command;
10
+ /**
11
+ * This function creates a new transaction that inserts a code block,
12
+ * if there is text selected it will wrap the current selection if not it will
13
+ * append the codeblock to the end of the document.
14
+ */
15
+ export declare function createInsertCodeBlockTransaction({ state, }: {
16
+ state: EditorState;
17
+ }): import("prosemirror-state").Transaction;
18
+ export declare function insertCodeBlockWithAnalytics(inputMethod: INPUT_METHOD, analyticsAPI?: EditorAnalyticsAPI): Command;
@@ -0,0 +1,12 @@
1
+ export declare const BRACKET_MAP: {
2
+ '{': string;
3
+ '[': string;
4
+ '(': string;
5
+ };
6
+ export type BracketMapKey = keyof typeof BRACKET_MAP;
7
+ export declare const shouldAutoCloseBracket: (before: string, after: string) => boolean;
8
+ export declare const getAutoClosingBracketInfo: (before: string, after: string) => {
9
+ left: "{" | "[" | "(" | undefined;
10
+ right: string | undefined;
11
+ hasTrailingMatchingBracket: boolean;
12
+ };
@@ -0,0 +1,7 @@
1
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
+ import type { CommandDispatch } from '@atlaskit/editor-common/types';
3
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
4
+ export declare const indent: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (state: EditorState, dispatch?: CommandDispatch) => boolean;
5
+ export declare const outdent: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (state: EditorState, dispatch?: CommandDispatch) => boolean;
6
+ export declare function insertIndent(state: EditorState, dispatch: CommandDispatch): boolean;
7
+ export declare function insertNewlineWithIndent(state: EditorState, dispatch?: CommandDispatch): boolean;
@@ -0,0 +1,25 @@
1
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const isSelectionEntirelyInsideCodeBlock: (state: EditorState) => boolean;
3
+ export declare const isCursorInsideCodeBlock: (state: EditorState) => boolean;
4
+ export declare const getStartOfCurrentLine: (state: EditorState) => {
5
+ text: string;
6
+ pos: number;
7
+ };
8
+ export declare const getEndOfCurrentLine: (state: EditorState) => {
9
+ text: string;
10
+ pos: number;
11
+ };
12
+ export declare function getLinesFromSelection(state: EditorState): {
13
+ text: string;
14
+ start: number;
15
+ end: number;
16
+ };
17
+ export declare const forEachLine: (text: string, callback: (line: string, offset: number) => void) => void;
18
+ export declare const getLineInfo: (line: string) => {
19
+ indentToken: {
20
+ token: string;
21
+ size: number;
22
+ regex: RegExp;
23
+ };
24
+ indentText: string;
25
+ };
@@ -0,0 +1,2 @@
1
+ export declare const isCursorBeforeClosingCharacter: (after: string) => boolean;
2
+ export declare const isClosingCharacter: (text: string) => boolean;
@@ -0,0 +1,12 @@
1
+ export declare const QUOTE_MAP: {
2
+ "'": string;
3
+ '"': string;
4
+ '`': string;
5
+ };
6
+ export type QuoteMapKey = keyof typeof QUOTE_MAP;
7
+ export declare const shouldAutoCloseQuote: (before: string, after: string) => boolean;
8
+ export declare const getAutoClosingQuoteInfo: (before: string, after: string) => {
9
+ left: "'" | "\"" | "`" | undefined;
10
+ right: string | undefined;
11
+ hasTrailingMatchingQuote: boolean;
12
+ };
@@ -0,0 +1,3 @@
1
+ export { default as codeBlockPlugin } from './plugin';
2
+ export type { CodeBlockPlugin } from './plugin';
3
+ export type { CodeBlockOptions } from './types';