@atlaskit/editor-core 191.0.9 → 191.1.3

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 (85) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/afm-cc/tsconfig.json +3 -6
  3. package/dist/cjs/plugins/index.js +1 -8
  4. package/dist/cjs/presets/universal.js +10 -13
  5. package/dist/cjs/ui/Addon/click-area-helper.js +2 -0
  6. package/dist/cjs/ui/Appearance/Comment/Comment.js +6 -3
  7. package/dist/cjs/ui/Appearance/Comment/Toolbar.js +19 -6
  8. package/dist/cjs/ui/Appearance/FullPage/FullPageToolbar.js +6 -12
  9. package/dist/cjs/version-wrapper.js +1 -1
  10. package/dist/es2019/plugins/index.js +1 -2
  11. package/dist/es2019/presets/universal.js +11 -14
  12. package/dist/es2019/ui/Addon/click-area-helper.js +2 -0
  13. package/dist/es2019/ui/Appearance/Comment/Comment.js +6 -3
  14. package/dist/es2019/ui/Appearance/Comment/Toolbar.js +38 -6
  15. package/dist/es2019/ui/Appearance/FullPage/FullPageToolbar.js +4 -10
  16. package/dist/es2019/version-wrapper.js +1 -1
  17. package/dist/esm/plugins/index.js +1 -2
  18. package/dist/esm/presets/universal.js +11 -14
  19. package/dist/esm/ui/Addon/click-area-helper.js +2 -0
  20. package/dist/esm/ui/Appearance/Comment/Comment.js +6 -3
  21. package/dist/esm/ui/Appearance/Comment/Toolbar.js +19 -6
  22. package/dist/esm/ui/Appearance/FullPage/FullPageToolbar.js +4 -10
  23. package/dist/esm/version-wrapper.js +1 -1
  24. package/dist/types/plugins/index.d.ts +0 -1
  25. package/dist/types/presets/default.d.ts +6 -36
  26. package/dist/types/ui/Appearance/Comment/Toolbar.d.ts +2 -1
  27. package/dist/types-ts4.5/plugins/index.d.ts +0 -1
  28. package/dist/types-ts4.5/presets/default.d.ts +6 -36
  29. package/dist/types-ts4.5/ui/Appearance/Comment/Toolbar.d.ts +2 -1
  30. package/docs/0-intro.tsx +252 -174
  31. package/docs/1-legacy-editor.tsx +268 -0
  32. package/package.json +7 -7
  33. package/dist/cjs/plugins/avatar-group/index.js +0 -40
  34. package/dist/cjs/plugins/avatar-group/messages.js +0 -14
  35. package/dist/cjs/plugins/avatar-group/ui/AvatarGroupPluginWrapper.js +0 -49
  36. package/dist/cjs/plugins/avatar-group/ui/avatars-with-plugin-state.js +0 -42
  37. package/dist/cjs/plugins/avatar-group/ui/avatars.js +0 -70
  38. package/dist/cjs/plugins/avatar-group/ui/colored-avatar-item.js +0 -20
  39. package/dist/cjs/plugins/avatar-group/ui/index.js +0 -9
  40. package/dist/cjs/plugins/avatar-group/ui/invite-to-edit.js +0 -45
  41. package/dist/cjs/plugins/avatar-group/ui/styles.js +0 -17
  42. package/dist/cjs/plugins/avatar-group/ui/to-avatar.js +0 -30
  43. package/dist/es2019/plugins/avatar-group/index.js +0 -35
  44. package/dist/es2019/plugins/avatar-group/messages.js +0 -8
  45. package/dist/es2019/plugins/avatar-group/ui/AvatarGroupPluginWrapper.js +0 -53
  46. package/dist/es2019/plugins/avatar-group/ui/avatars-with-plugin-state.js +0 -38
  47. package/dist/es2019/plugins/avatar-group/ui/avatars.js +0 -62
  48. package/dist/es2019/plugins/avatar-group/ui/colored-avatar-item.js +0 -13
  49. package/dist/es2019/plugins/avatar-group/ui/index.js +0 -2
  50. package/dist/es2019/plugins/avatar-group/ui/invite-to-edit.js +0 -32
  51. package/dist/es2019/plugins/avatar-group/ui/styles.js +0 -46
  52. package/dist/es2019/plugins/avatar-group/ui/to-avatar.js +0 -16
  53. package/dist/esm/plugins/avatar-group/index.js +0 -33
  54. package/dist/esm/plugins/avatar-group/messages.js +0 -8
  55. package/dist/esm/plugins/avatar-group/ui/AvatarGroupPluginWrapper.js +0 -42
  56. package/dist/esm/plugins/avatar-group/ui/avatars-with-plugin-state.js +0 -35
  57. package/dist/esm/plugins/avatar-group/ui/avatars.js +0 -62
  58. package/dist/esm/plugins/avatar-group/ui/colored-avatar-item.js +0 -13
  59. package/dist/esm/plugins/avatar-group/ui/index.js +0 -2
  60. package/dist/esm/plugins/avatar-group/ui/invite-to-edit.js +0 -34
  61. package/dist/esm/plugins/avatar-group/ui/styles.js +0 -10
  62. package/dist/esm/plugins/avatar-group/ui/to-avatar.js +0 -23
  63. package/dist/types/plugins/avatar-group/index.d.ts +0 -19
  64. package/dist/types/plugins/avatar-group/messages.d.ts +0 -7
  65. package/dist/types/plugins/avatar-group/ui/AvatarGroupPluginWrapper.d.ts +0 -18
  66. package/dist/types/plugins/avatar-group/ui/avatars-with-plugin-state.d.ts +0 -81
  67. package/dist/types/plugins/avatar-group/ui/avatars.d.ts +0 -17
  68. package/dist/types/plugins/avatar-group/ui/colored-avatar-item.d.ts +0 -10
  69. package/dist/types/plugins/avatar-group/ui/index.d.ts +0 -2
  70. package/dist/types/plugins/avatar-group/ui/invite-to-edit.d.ts +0 -10
  71. package/dist/types/plugins/avatar-group/ui/styles.d.ts +0 -3
  72. package/dist/types/plugins/avatar-group/ui/to-avatar.d.ts +0 -30
  73. package/dist/types-ts4.5/plugins/avatar-group/index.d.ts +0 -19
  74. package/dist/types-ts4.5/plugins/avatar-group/messages.d.ts +0 -7
  75. package/dist/types-ts4.5/plugins/avatar-group/ui/AvatarGroupPluginWrapper.d.ts +0 -18
  76. package/dist/types-ts4.5/plugins/avatar-group/ui/avatars-with-plugin-state.d.ts +0 -97
  77. package/dist/types-ts4.5/plugins/avatar-group/ui/avatars.d.ts +0 -19
  78. package/dist/types-ts4.5/plugins/avatar-group/ui/colored-avatar-item.d.ts +0 -12
  79. package/dist/types-ts4.5/plugins/avatar-group/ui/index.d.ts +0 -2
  80. package/dist/types-ts4.5/plugins/avatar-group/ui/invite-to-edit.d.ts +0 -10
  81. package/dist/types-ts4.5/plugins/avatar-group/ui/styles.d.ts +0 -3
  82. package/dist/types-ts4.5/plugins/avatar-group/ui/to-avatar.d.ts +0 -37
  83. /package/docs/{1-labs.tsx → 2-labs.tsx} +0 -0
  84. /package/docs/{2-autoformatting.tsx → 3-autoformatting.tsx} +0 -0
  85. /package/docs/{3-annotations.tsx → 4-annotations.tsx} +0 -0
package/docs/0-intro.tsx CHANGED
@@ -9,252 +9,329 @@ import {
9
9
 
10
10
  export default md`
11
11
  ${(<AtlassianInternalWarning />)}
12
+ ## Introduction
12
13
 
13
- ### Note:
14
+ The \`@atlaskit/editor-core\` package is part of the Atlassian front-end platform and provides core functionality for the rich text editor. It provides an easy-to-use and highly customizable editing experience, built on React as our primary rendering approach. It relies on the ProseMirror libraries, which offer a wide range of out-of-the-box features, including support for text formatting, lists, and more.
14
15
 
15
- Don't forget to add these polyfills to your product build if you're using emoji or mentions in the editor and you want to target older browsers:
16
+ There is a separate Renderer package that caters for rendering the edited content without the editing experience.
16
17
 
17
- * Promise ([polyfill](https://www.npmjs.com/package/es6-promise), [browser support](http://caniuse.com/#feat=promises))
18
- * Fetch API ([polyfill](https://www.npmjs.com/package/whatwg-fetch), [browser support](http://caniuse.com/#feat=fetch))
19
- * Element.closest ([polyfill](https://www.npmjs.com/package/element-closest), [browser support](http://caniuse.com/#feat=element-closest))
18
+ This documentation will provide you with everything you need to get started using the Atlassian Editor, including:
20
19
 
21
- # Installing the editor package
20
+ * Installation instructions
21
+ * Basic usage examples
22
+ * Advanced customization options
22
23
 
23
- The dependencies of editor is a complex beast and can confuse some package managers (\`npm\` does not seem to result in duplicates, but \`yarn\` does).
24
+ ## Prerequisites
24
25
 
25
- We have encountered many strange bugs that were caused by duplicated packages in a product codebase. It is highly recommend to deduplicate packages to work around the yarn bug.
26
+ * **React 16:** at the time of writing, the Atlassian Editor is built on top of React 16 and doesn’t explicitly support any higher versions of React yet, which means both the \`react\` and \`react-dom\` libraries and their dependencies need to be set to React 16 compatible version.
27
+ * **Singleton:** the ProseMirror libraries in use and the document format \(Atlassian Document Format, ADF\) demand that some of the libraries using them are singletons, as multiple versions of the library will cause breaking issues. So, consumers of the Atlassian Editor need to enforce these singletons; this is usually done by deduplicating after installing the dependencies or by setting libraries to specific versions through resolutions to avoid multiple versions. Our recommendation is to use [yarn-deduplicate](https://www.npmjs.com/package/yarn-deduplicate).
26
28
 
27
- Be sure to dedupe your packages after adding or upgrading \`@atlaskit/editor-core\` in your package.json file. Our recommendation is to use [yarn-deduplicate](https://www.npmjs.com/package/yarn-deduplicate).
29
+ ## Installation
28
30
 
29
- # Starting to use the editor
31
+ 1. Install the editor libraries
32
+ - **npm:** \`npm install --save @atlaskit/editor-core @atlaskit/css-reset\`
33
+ - **yarn:** \`yarn add @atlaskit/editor-core @atlaskit/css-reset\`
30
34
 
31
- ## Simplest Editor
35
+ 2. Deduplicate the dependencies \(if necessary\) by setting resolutions to avoid multiple versions of the editor libraries or by running [npm dedupe](https://docs.npmjs.com/cli/v6/commands/npm-dedupe) or [yarn dedupe](https://yarnpkg.com/cli/dedupe) after installation.
36
+ 3. Setup the CSS reset in your application
37
+ \`import '@atlaskit/css-reset';\`
32
38
 
33
- The simplest editor in the world is just:
39
+ ## Usage
40
+
41
+ ### [Legacy Editor](editor-core/docs/legacy-editor)
42
+
43
+
44
+ ### Composable Editor
45
+
46
+ #### Simplest implementation
47
+
48
+ The following code example will render the comment editor with only basic text formatting enabled.
34
49
 
35
50
  ${code`
36
- import { Editor } from '@atlaskit/editor-core';
51
+ import { ComposableEditor } from '@atlaskit/editor-core/composable-editor';
52
+ import { EditorPresetBuilder } from '@atlaskit/editor-common/preset';
53
+ import { usePreset } from '@atlaskit/editor-core/use-preset';
54
+ import { basePlugin } from '@atlaskit/editor-plugin-base';
55
+
56
+ const CommentEditor = () => {
57
+ const { preset } = usePreset(() =>
58
+ new EditorPresetBuilder().add(basePlugin)
59
+ , []);
60
+
61
+ return <ComposableEditor preset={preset} />;
62
+ };
63
+ `}
64
+
65
+ You can enable more editor functionality by passing extra plugins to the preset as discussed below.
37
66
 
38
- <Editor appearance="comment" />;
67
+ If coming from the legacy editor, the simplest migration would be via the \`universal\` preset.
68
+
69
+ **Warning**: The \`universal\` preset brings in all editor plugins which can impact heavily bundle size. It is generally recommended to build your own custom preset as will be discussed.
70
+
71
+ ${code`
72
+ import { ComposableEditor } from '@atlaskit/editor-core/composable-editor';
73
+ import { useUniversalPreset } from '@atlaskit/editor-core/preset-universal';
74
+
75
+ const CommentEditor = () => {
76
+ const presetProps = {
77
+ props: {},
78
+ };
79
+ const universalPreset = useUniversalPreset(presetProps);
80
+
81
+ return <ComposableEditor preset={universalPreset} />;
82
+ };
39
83
  `}
40
84
 
41
- This will render the comment editor with only text formatting (bold / italics / underline / superscript/subscript) enabled.
85
+ ## Configuration
86
+
87
+ ### Presets
42
88
 
43
- You can enable more functionality in the editor via passing extra props.
89
+ The Atlassian Editor employs a plugin system to extend its capabilities, offering a wide range of plugins to enhance its feature set. Plugins can also have dependencies on one another to deliver their functionality \(for example, the table plugin depends on the guideline plugin\). To simplify the process of including and configuring these plugins, we've introduced the concept of presets. Presets are a collection of plugins that work seamlessly together.
44
90
 
45
- ## Editor with mentions
91
+ You can start with one of the preset provided with \`editor-core\` and extend their functionality, or build your own using \`EditorPresetBuilder\`. You always need the \`basePlugin\` in any preset.
46
92
 
47
- To add mention capabilities to the editor, you will need to pass in a "Mention Provider". At a high level, this is simply an object that will allow us to interface whatever mention source you want to use with the editor. This looks like:
93
+ #### Using the Pre-defined Default Preset
48
94
 
49
95
  ${code`
50
- import { Editor } from '@atlaskit/editor-core';
51
- import mentionProvider from './mentionProvider';
96
+ import { createDefaultPreset } from '@atlaskit/editor-core/preset-default';
97
+ import { usePreset } from '@atlaskit/editor-core/use-preset';
52
98
 
53
- <Editor
54
- appearance="comment"
55
- mentionProvider={mentionProvider.get()}
56
- />;
99
+ const createPreset = () =>
100
+ createDefaultPreset({ featureFlags: {}, paste: {} });
101
+ const { preset } = usePreset(createPreset, []);
57
102
  `}
58
103
 
59
- ## Collapsed Editor
104
+ The default preset encompasses all the essentials needed for the Editor to function, representing the minimum set of plugins. It includes core Atlassian libraries essential for editor development \(feature flags, analytics, editor state management\), as well as common editor features \(copy/paste, clipboard support, focus, composition, decorations, undo/redo, block elements, annotations, hyperlink support, basic text formatting, responsive width support, quick-insert, type-ahead, placeholder text, editor controls, selections, code blocks\). Some of these core plugins can be disabled through the configuration object passed into \`createDefaultPreset\`.
60
105
 
61
- Sometimes we don't want to show the whole editor at the start and instead show a collapsed state for a user to click on to start typing. This looks like:
106
+
107
+ #### Using the Pre-defined Universal Preset
62
108
 
63
109
  ${code`
64
- import { Editor, CollapsedEditor } from '@atlaskit/editor-core';
65
-
66
- class CollapsibleEditor extends React.Component {
67
- state = { isExpanded: false };
68
-
69
- expandEditor = () => this.setState({ isExpanded: true });
70
- collapseEditor = () => this.setState({ isExpanded: false });
71
-
72
- onSave = () => {
73
- /* do something */
74
- };
75
-
76
- render() {
77
- return (
78
- <CollapsedEditor
79
- placeholder="What would you like to say?"
80
- isExpanded={this.state.isExpanded}
81
- onFocus={this.expandEditor}
82
- >
83
- <Editor
84
- appearance="comment"
85
- onSave={this.onSave}
86
- onCancel={this.collapseEditor}
87
- />
88
- </CollapsedEditor>
89
- );
90
- }
91
- }
110
+ import { useUniversalPreset } from '@atlaskit/editor-core/preset-universal';
111
+
112
+ const presetProps = {
113
+ props: {},
114
+ };
115
+ const universalPreset = useUniversalPreset(presetProps);
92
116
  `}
93
117
 
94
- ## What is EditorContext?!?!
118
+ In addition to the default preset, the universal preset contains a comprehensive set of features for a fully-featured editor. It supports functionalities like data consumers, content insertion, breakout, alignment, text color, lists, rules, expands, guidelines, media, captions, mentions, emoji, tables, tasks & decisions, feedback dialogs, help dialogs, collaborative editing, maximum content size restrictions, Jira issue linking, panels, context panels, extensions, macros, annotations, dates, placeholder text, layouts, cards, auto-formatting rules, status elements, indentation, scroll-into-view behavior, complex history behavior, mobile support, and advanced toolbar support.
119
+
95
120
 
96
- EditorContext allows you, in conjunction with WithEditorActions, to manipulate the editor from anywhere inside the EditorContext. In the example below, notice that no reference is kept to the editor instance.
121
+ #### Adding a plugin to a preset
122
+
123
+ To add a plugin to a preset, use the following methods:
124
+
125
+ * Use \`maybeAdd\` to conditionally add the plugin.
126
+ * Use \`add\` for plugins that should always be included.
97
127
 
98
128
  ${code`
99
- import { EditorContext, WithEditorActions } from '@atlaskit/editor-core';
100
- import { CollapsibleEditor } from 'previous-example';
101
-
102
- <EditorContext>
103
- <div>
104
- <CollapsibleEditor />
105
- <WithEditorActions
106
- render={actions => (
107
- <ButtonGroup>
108
- <Button onClick={() => actions.clear()}>Clear Editor</Button>
109
- <Button onClick={() => actions.focus()}>Focus Editor</Button>
110
- </ButtonGroup>
111
- )}
112
- />
113
- </div>
114
- </EditorContext>;
129
+ import { createDefaultPreset } from '@atlaskit/editor-core/preset-default';
130
+ import { usePreset } from '@atlaskit/editor-core/use-preset';
131
+
132
+ const createPreset = () =>
133
+ createDefaultPreset({ featureFlags: {}, paste: {} })
134
+ .add(listPlugin)
135
+ .maybeAdd(NextEditorPluginAI, (plugin, builder) => {
136
+ if (editorPluginAIProvider) {
137
+ return builder.add([plugin, { editorPluginAIProvider }]); // Add the plugin
138
+ }
139
+ return builder; // Don't add the plugin
140
+ });
141
+
142
+ const { preset } = usePreset(createPreset, []);
143
+ `}
144
+
145
+ Some plugins are dependent on others. If you encounter type issues with a specific plugin, it's crucial to verify that all necessary dependencies have been added. These can be cross-checked within the individual documentation of each plugin.
146
+
147
+ #### Create a custom preset
148
+
149
+ Create your custom preset using the \`default\` preset as a base (extending with card and list functionality).
150
+
151
+ ${code`
152
+ import { usePreset } from '@atlaskit/editor-core/use-preset';
153
+ import { createDefaultPreset } from '@atlaskit/editor-core/labs-next';
154
+
155
+ const createPreset = () =>
156
+ createDefaultPreset({ featureFlags: {}, paste: {} })
157
+ .add(gridPlugin)
158
+ .add([cardPlugin, { platform: 'web' }])
159
+ .add(listPlugin);
160
+
161
+ const { preset } = usePreset(createPreset, []);
115
162
  `}
116
163
 
117
- ## How can I set the content of the editor?
164
+ Or from scratch (simple preset with basic text formatting, list, analytics, and headings):
165
+
166
+ ${code`
167
+ import { ComposableEditor } from '@atlaskit/editor-core/composable-editor';
168
+ import { EditorPresetBuilder } from '@atlaskit/editor-common/preset';
169
+ import { usePreset } from '@atlaskit/editor-core/use-preset';
170
+ import { basePlugin } from '@atlaskit/editor-plugin-base';
171
+ import { blockTypePlugin } from '@atlaskit/editor-plugin-block-type';
172
+ import { listPlugin } from '@atlaskit/editor-plugin-list';
173
+ import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
174
+
175
+ const createPreset = () =>
176
+ new EditorPresetBuilder()
177
+ .add(basePlugin)
178
+ .add(analyticsPlugin)
179
+ .add(blockTypePlugin)
180
+ .add(listPlugin)
181
+
182
+ const { preset } = usePreset(createPreset, []);
183
+ `}
118
184
 
119
- There's two ways at the moment. It depends on whether the editor is mounted yet or not.
185
+ To keep your integrated editor running smoothly, it's important to have a stable preset. If you generate a new preset every time the editor re-renders, it can slow things down significantly. The best way to maintain a stable preset across re-renders is to use the \`usePreset\` hook or similar memoization techniques. This helps your editor run efficiently without unnecessary recalculations.
120
186
 
121
- ### If the editor is not mounted
187
+ ---
122
188
 
123
- You can just pass through the value you want to set the editor to, as the \`defaultValue\` prop
189
+ ### Appearances
124
190
 
125
- ### If the Editor is Mounted
191
+ Appearances determine how the editor's user interface \(UI\) is displayed and can be configured using a property passed into the editor component.
126
192
 
127
- You can use \`WithEditorActions\` and \`actions.replaceDocument(documentValueHere)\` together
128
193
 
129
- ## Using a non-'Atlassian Document Format' storage format
194
+ #### Comment
130
195
 
131
- Using a custom storage format is fairly straightforward - you simply have to import the relevant transformer and pass it through to the editor. That's all!
196
+ The comment editor appearance provides a contained editor UI with a simple toolbar. It is best used when the Editor isn't the primary focus area of the page, such as when it's used for editing comments on a page. This editor appearance still includes a toolbar with editor controls.
132
197
 
133
198
  ${code`
134
- import { Editor, BitbucketTransformer } from '@atlaskit/editor-core';
135
199
 
136
- <Editor
137
- appearance="comment"
138
- contentTransformerProvider={schema => new BitbucketTransformer(schema)}
139
- />;
200
+ const createPreset = () =>
201
+ createDefaultPreset({ featureFlags: {}, paste: {} });
202
+ const { preset } = usePreset(createPreset, []);
203
+
204
+ // 'comment' is the default appearance, you don't need to pass it
205
+ return <ComposableEditor appearance='comment' preset={preset} />;
140
206
  `}
141
207
 
142
- ## Example saving content
208
+ Comment is the default appearance so this is equivalent:
143
209
 
144
- If you want an example of actually using \`WithEditorActions\` to save content, you've got it!
210
+ ${code`
211
+
212
+ const createPreset = () =>
213
+ createDefaultPreset({ featureFlags: {}, paste: {} });
214
+ const { preset } = usePreset(createPreset, []);
215
+
216
+ return <ComposableEditor preset={preset} />;
217
+ `}
218
+
219
+
220
+ #### Full Page and Full Width
221
+
222
+ The full-page and full-width editor appearances provide an editor UI that stretches to fill the entire page. They are suitable when the Editor is the main focus area on the page.
145
223
 
146
224
  ${code`
147
- class SaveExample extends React.Component {
148
- onSubmit = actions => editorView => {
149
- actions.getValue().then(value => {
150
- if (value != null) {
151
- dispatch({ type: 'SAVE_COMMENT', payload: value });
152
- }
153
- })
154
- }
155
-
156
- render() {
157
- return (
158
- <EditorContext>
159
- <WithEditorActions
160
- render={actions => (
161
- <Editor
162
- appearance="comment"
163
- onSave={this.onSubmit(actions)}
164
- />
165
- )}
166
- />
167
- </EditorContext>
168
- )
169
- }
225
+ const createPreset = () =>
226
+ createDefaultPreset({ featureFlags: {}, paste: {} });
227
+ const { preset } = usePreset(createPreset, []);
228
+
229
+ return <ComposableEditor appearance='full-page' preset={preset} />;
230
+ // Or full-width
231
+ return <ComposableEditor appearance='full-width' preset={preset} />;
170
232
  `}
171
233
 
172
- alternatively
234
+
235
+ #### Chromeless
236
+
237
+ The chromeless editor appearance provides the Editor without any of the standard UI features. It's ideal for cases where the integrator wants complete control and responsibility over the editor UI.
173
238
 
174
239
  ${code`
175
- class EditorWrapper extends React.Component {
176
- propTypes = { actions: PropTypes.object };
177
-
178
- onSubmit = () => {
179
- this.props.actions.getValue().then(value => {
180
- if (value != null) {
181
- dispatch({ type: 'SAVE_COMMENT', payload: value });
182
- }
183
- });
184
- };
185
-
186
- render() {
187
- return (
188
- <Editor
189
- appearance="comment"
190
- onSave={this.onSubmit}
191
- />
192
- );
193
- }
194
- }
195
-
196
- class SaveExample extends React.Component {
197
- render() {
198
- return (
199
- <EditorContext>
200
- <WithEditorActions
201
- render={actions => <EditorWrapper actions={actions} />}
202
- />
203
- </EditorContext>
204
- );
205
- }
206
- }
240
+ const createPreset = () =>
241
+ createDefaultPreset({ featureFlags: {}, paste: {} });
242
+ const { preset } = usePreset(createPreset, []);
243
+ return <ComposableEditor appearance='chromeless' preset={preset} />;
207
244
  `}
208
245
 
209
- We’d love to hear your feedback.
246
+ #### Mobile
210
247
 
211
- ## Theming and dark mode support
212
- To render certain ADF content correctly in different color themes, such as light and dark mode, this package utilise
213
- the \`@atlaskit/editor-palette\` package, which converts colors stored in ADF to Atlassian Design Tokens.
214
- Learn more about this utility in the [Editor Palette docs](/packages/editor/editor-palette).
248
+ The mobile editor appearance is tailored to deliver a mobile experience through a mobile web view. It's essentially a full-page editor version for mobile.
215
249
 
216
- Full light and dark mode support for the Editor is a work in progress. Currently, the following experiences do not yet support theming:
217
- - Custom table backgrounds
250
+ ${code`
251
+ const createPreset = () =>
252
+ createDefaultPreset({ featureFlags: {}, paste: {} });
253
+ const { preset } = usePreset(createPreset, []);
254
+ return <ComposableEditor appearance='mobile' preset={preset} />;
255
+ `}
218
256
 
219
- ## Tab indexing / focus
220
- If you are displaying a title you may need to listen for a tab event to
221
- explicitly enable and focus the editor.
222
257
 
223
- Shift + Tab will move from the title bar to the toolbar preserving tab order.
258
+ ### Collapsible Editor
224
259
 
225
- See the Full Page Example code for a complete implementation.
260
+ Sometimes, you may not want to display the whole Editor initially, and you'd prefer to show it in a collapsed state so that users can expand it when needed.
226
261
 
227
- For example:
262
+ Here's how you can implement this behavior:
228
263
 
229
264
  ${code`
230
- <WithEditorActions
231
-
232
- render={actions => (
233
- <TitleInput
234
- placeholder="Give this page a title..."
235
- onKeyDown={(e: KeyboardEvent) =>
236
- this.onKeyPressed(e, actions)
237
- }
265
+ import { useState } from 'react';
266
+ import { CollapsedEditor } from '@atlaskit/editor-core';
267
+ import { ComposableEditor } from '@atlaskit/editor-core/composable-editor';
268
+ import { useUniversalPreset } from '@atlaskit/editor-core/preset-universal';
269
+
270
+ const CollapsibleEditor = () => {
271
+ const [isExpanded, setIsExpanded] = useState(false);
272
+
273
+ const createPreset = () =>
274
+ createDefaultPreset({ featureFlags: {}, paste: {} });
275
+ const { preset } = usePreset(createPreset, []);
276
+
277
+ return (
278
+ <CollapsedEditor
279
+ placeholder='What would you like to say?'
280
+ onFocus={() => setIsExpanded(true)}
281
+ isExpanded={isExpanded}>
282
+ <ComposableEditor
283
+ preset={preset}
284
+ // TODO: We don't actually want people to use onSave
285
+ onSave={(_editorView) => alert('The save button is a lie.')}
286
+ onCancel={() => setIsExpanded(false)}
238
287
  />
239
- )}
240
- />
288
+ </CollapsedEditor>
289
+ );
290
+ };
241
291
  `}
242
292
 
293
+
294
+ ### Editor with providers
295
+
296
+ The Editor can't access information from its context by default. Instead, specific plugins provide a mechanism to allow you to supply custom logic for accessing environment variables.
297
+
298
+ An excellent example of this is mentions, where you would want to provide user information the Editor can access and define how it should be presented inside the Editor. To enable the capability of mentioning users inside the Editor, you need to pass in a "mention provider." This object allows you to define the logic used to determine which users can be mentioned in the Editor.
299
+
300
+ This could look something like this:
301
+
243
302
  ${code`
244
- private onKeyPressed = (e: KeyboardEvent, actions: EditorActions) => {
245
- if (e.key === 'Tab' && !e.shiftKey) {
246
- actions.focus();
303
+ import { ComposableEditor } from '@atlaskit/editor-core/composable-editor';
304
+ import { useUniversalPreset } from '@atlaskit/editor-core/preset-universal';
305
+ import { MentionDescription, MentionProvider } from '@atlaskit/mention';
306
+
307
+ const CommentEditorWithMentions = () => {
308
+ const exampleMentionProvider: MentionProvider = {
309
+ filter(_query?: string): void {},
310
+ recordMentionSelection(_mention: MentionDescription): void {},
311
+ shouldHighlightMention(_mention: MentionDescription): boolean {
312
+ return false;
313
+ },
314
+ isFiltering(_query: string): boolean {
247
315
  return false;
248
- }
316
+ },
317
+ subscribe(): void {},
318
+ unsubscribe(_key: string): void {},
249
319
  };
320
+
321
+ const createPreset = () =>
322
+ createDefaultPreset({ featureFlags: {}, paste: {} });
323
+ const { preset } = usePreset(createPreset, []);
324
+
325
+ return <ComposableEditor preset={preset} mentionProvider={presetProps.props.mentionProvider} />;
326
+ };
250
327
  `}
251
328
 
252
329
  ${(
253
330
  <Example
254
- packageName="@atlaskit/editor-core"
255
- Component={require('../examples/1-basic').default}
331
+ packageName="@atlaskit/editor-core/composable-editor"
332
+ Component={require('../examples/1-basic-composable-editor').default}
256
333
  title="Basic"
257
- source={require('!!raw-loader!../examples/1-basic')}
334
+ source={require('!!raw-loader!../examples/1-basic-composable-editor')}
258
335
  />
259
336
  )}
260
337
 
@@ -262,7 +339,8 @@ ${(
262
339
  <Props
263
340
  shouldCollapseProps
264
341
  heading="Props"
265
- props={require('!!extract-react-types-loader!../src/editor')}
342
+ props={require('!!extract-react-types-loader!../src/composable-editor')}
266
343
  />
267
344
  )}
345
+
268
346
  `;