@atlaskit/editor-core 220.0.2 → 220.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 (216) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/codemods/createRenameVariableTransform.ts +17 -0
  3. package/codemods/findImportFromPackage.ts +54 -0
  4. package/codemods/migrates/createJSXRenameVariableToNestedKeyTransform.ts +43 -0
  5. package/codemods/migrates/createUpdateEditorToMigrationComponent.ts +25 -0
  6. package/codemods/migrates/next-remove-allow-more-text-colors-prop.ts +1 -1
  7. package/codemods/migrates/remove-config-panel-width-prop.ts +1 -1
  8. package/codemods/migrates/rename-editor-to-editor-migration-component.ts +1 -22
  9. package/codemods/migrates/rename-smartlinks-prop.ts +1 -40
  10. package/codemods/migrates/rename-unsafe-allowUndoRedoButtons-prop.ts +1 -1
  11. package/codemods/migrates/rename-unsafe-cards-prop.ts +1 -1
  12. package/codemods/utils.ts +0 -67
  13. package/dist/cjs/actions/isEmptyParagraph.js +12 -0
  14. package/dist/cjs/actions/temp-is-empty-document.js +2 -9
  15. package/dist/cjs/create-editor/ReactEditorView/useDispatchTransaction.js +2 -1
  16. package/dist/cjs/create-editor/ReactEditorView.js +6 -4
  17. package/dist/cjs/create-editor/addMetadataAttributes.js +36 -0
  18. package/dist/cjs/create-editor/create-editor.js +0 -62
  19. package/dist/cjs/create-editor/create-plugins-list.js +2 -15
  20. package/dist/cjs/create-editor/create-schema.js +4 -35
  21. package/dist/cjs/create-editor/createErrorReporter.js +14 -0
  22. package/dist/cjs/create-editor/createPMPlugins.js +39 -0
  23. package/dist/cjs/create-editor/fixExcludes.js +22 -0
  24. package/dist/cjs/create-editor/getScrollGutterOptions.js +19 -0
  25. package/dist/cjs/create-editor/sortByRank.js +9 -0
  26. package/dist/cjs/entry-points/test-utils.js +4 -2
  27. package/dist/cjs/isElementBySelectorInDocument.js +15 -0
  28. package/dist/cjs/setTextSelection.js +12 -0
  29. package/dist/cjs/test-utils.js +1 -18
  30. package/dist/cjs/ui/Addon/checkForModal.js +25 -0
  31. package/dist/cjs/ui/Addon/click-area-helper.js +5 -52
  32. package/dist/cjs/ui/Addon/outsideProsemirrorEditorClickHandler.js +35 -0
  33. package/dist/cjs/ui/Appearance/Chromeless.js +4 -16
  34. package/dist/cjs/ui/Appearance/ChromelessEditorContainer.js +19 -0
  35. package/dist/cjs/ui/Appearance/FullPage/CustomToolbarWrapperMigration.js +13 -0
  36. package/dist/cjs/ui/Appearance/FullPage/FullPageToolbar.js +5 -2
  37. package/dist/cjs/ui/Appearance/FullPage/MainToolbar.js +2 -15
  38. package/dist/cjs/ui/Appearance/FullPage/MainToolbarIconBeforeMigration.js +13 -0
  39. package/dist/cjs/ui/Appearance/FullPage/NonCustomToolbarWrapperMigration.js +13 -0
  40. package/dist/cjs/ui/EditorContentContainer/styles/mentions.js +19 -0
  41. package/dist/cjs/utils/combineQuickInsertProviders.js +16 -0
  42. package/dist/cjs/utils/extensions.js +0 -11
  43. package/dist/cjs/utils/getNodesVisibleInViewport.js +3 -12
  44. package/dist/cjs/utils/isNodeVisible.js +15 -0
  45. package/dist/cjs/utils/prepare-quick-insert-provider.js +2 -1
  46. package/dist/cjs/utils/validNode.js +14 -0
  47. package/dist/cjs/utils/validateNodes.js +3 -11
  48. package/dist/cjs/version-wrapper.js +1 -1
  49. package/dist/es2019/actions/isEmptyParagraph.js +6 -0
  50. package/dist/es2019/actions/temp-is-empty-document.js +1 -6
  51. package/dist/es2019/create-editor/ReactEditorView/useDispatchTransaction.js +2 -1
  52. package/dist/es2019/create-editor/ReactEditorView.js +3 -1
  53. package/dist/es2019/create-editor/addMetadataAttributes.js +29 -0
  54. package/dist/es2019/create-editor/create-editor.js +0 -53
  55. package/dist/es2019/create-editor/create-plugins-list.js +1 -13
  56. package/dist/es2019/create-editor/create-schema.js +2 -31
  57. package/dist/es2019/create-editor/createErrorReporter.js +8 -0
  58. package/dist/es2019/create-editor/createPMPlugins.js +30 -0
  59. package/dist/es2019/create-editor/fixExcludes.js +12 -0
  60. package/dist/es2019/create-editor/getScrollGutterOptions.js +13 -0
  61. package/dist/es2019/create-editor/sortByRank.js +3 -0
  62. package/dist/es2019/entry-points/test-utils.js +3 -1
  63. package/dist/es2019/isElementBySelectorInDocument.js +9 -0
  64. package/dist/es2019/setTextSelection.js +8 -0
  65. package/dist/es2019/test-utils.js +0 -18
  66. package/dist/es2019/ui/Addon/checkForModal.js +19 -0
  67. package/dist/es2019/ui/Addon/click-area-helper.js +2 -53
  68. package/dist/es2019/ui/Addon/outsideProsemirrorEditorClickHandler.js +33 -0
  69. package/dist/es2019/ui/Appearance/Chromeless.js +2 -12
  70. package/dist/es2019/ui/Appearance/ChromelessEditorContainer.js +12 -0
  71. package/dist/es2019/ui/Appearance/FullPage/CustomToolbarWrapperMigration.js +5 -0
  72. package/dist/es2019/ui/Appearance/FullPage/FullPageToolbar.js +4 -1
  73. package/dist/es2019/ui/Appearance/FullPage/MainToolbar.js +1 -8
  74. package/dist/es2019/ui/Appearance/FullPage/MainToolbarIconBeforeMigration.js +5 -0
  75. package/dist/es2019/ui/Appearance/FullPage/NonCustomToolbarWrapperMigration.js +5 -0
  76. package/dist/es2019/ui/EditorContentContainer/styles/mentions.js +19 -0
  77. package/dist/es2019/utils/combineQuickInsertProviders.js +11 -0
  78. package/dist/es2019/utils/extensions.js +0 -11
  79. package/dist/es2019/utils/getNodesVisibleInViewport.js +1 -9
  80. package/dist/es2019/utils/isNodeVisible.js +9 -0
  81. package/dist/es2019/utils/prepare-quick-insert-provider.js +2 -1
  82. package/dist/es2019/utils/validNode.js +8 -0
  83. package/dist/es2019/utils/validateNodes.js +1 -8
  84. package/dist/es2019/version-wrapper.js +1 -1
  85. package/dist/esm/actions/isEmptyParagraph.js +6 -0
  86. package/dist/esm/actions/temp-is-empty-document.js +1 -6
  87. package/dist/esm/create-editor/ReactEditorView/useDispatchTransaction.js +2 -1
  88. package/dist/esm/create-editor/ReactEditorView.js +3 -1
  89. package/dist/esm/create-editor/addMetadataAttributes.js +29 -0
  90. package/dist/esm/create-editor/create-editor.js +0 -58
  91. package/dist/esm/create-editor/create-plugins-list.js +1 -13
  92. package/dist/esm/create-editor/create-schema.js +2 -31
  93. package/dist/esm/create-editor/createErrorReporter.js +8 -0
  94. package/dist/esm/create-editor/createPMPlugins.js +32 -0
  95. package/dist/esm/create-editor/fixExcludes.js +16 -0
  96. package/dist/esm/create-editor/getScrollGutterOptions.js +13 -0
  97. package/dist/esm/create-editor/sortByRank.js +3 -0
  98. package/dist/esm/entry-points/test-utils.js +3 -1
  99. package/dist/esm/isElementBySelectorInDocument.js +9 -0
  100. package/dist/esm/setTextSelection.js +6 -0
  101. package/dist/esm/test-utils.js +0 -16
  102. package/dist/esm/ui/Addon/checkForModal.js +19 -0
  103. package/dist/esm/ui/Addon/click-area-helper.js +2 -49
  104. package/dist/esm/ui/Addon/outsideProsemirrorEditorClickHandler.js +29 -0
  105. package/dist/esm/ui/Appearance/Chromeless.js +2 -14
  106. package/dist/esm/ui/Appearance/ChromelessEditorContainer.js +14 -0
  107. package/dist/esm/ui/Appearance/FullPage/CustomToolbarWrapperMigration.js +7 -0
  108. package/dist/esm/ui/Appearance/FullPage/FullPageToolbar.js +4 -1
  109. package/dist/esm/ui/Appearance/FullPage/MainToolbar.js +1 -14
  110. package/dist/esm/ui/Appearance/FullPage/MainToolbarIconBeforeMigration.js +7 -0
  111. package/dist/esm/ui/Appearance/FullPage/NonCustomToolbarWrapperMigration.js +7 -0
  112. package/dist/esm/ui/EditorContentContainer/styles/mentions.js +19 -0
  113. package/dist/esm/utils/combineQuickInsertProviders.js +10 -0
  114. package/dist/esm/utils/extensions.js +0 -10
  115. package/dist/esm/utils/getNodesVisibleInViewport.js +1 -9
  116. package/dist/esm/utils/isNodeVisible.js +9 -0
  117. package/dist/esm/utils/prepare-quick-insert-provider.js +2 -1
  118. package/dist/esm/utils/validNode.js +8 -0
  119. package/dist/esm/utils/validateNodes.js +1 -8
  120. package/dist/esm/version-wrapper.js +1 -1
  121. package/dist/types/actions/isEmptyParagraph.d.ts +5 -0
  122. package/dist/types/actions/temp-is-empty-document.d.ts +0 -4
  123. package/dist/types/composable-editor/editor-internal.d.ts +1 -1
  124. package/dist/types/create-editor/ReactEditorView.d.ts +2 -2
  125. package/dist/types/create-editor/addMetadataAttributes.d.ts +16 -0
  126. package/dist/types/create-editor/create-editor.d.ts +1 -17
  127. package/dist/types/create-editor/create-plugins-list.d.ts +1 -4
  128. package/dist/types/create-editor/create-schema.d.ts +0 -15
  129. package/dist/types/create-editor/create-universal-preset.d.ts +1 -1
  130. package/dist/types/create-editor/createErrorReporter.d.ts +3 -0
  131. package/dist/types/create-editor/createPMPlugins.d.ts +3 -0
  132. package/dist/types/create-editor/fixExcludes.d.ts +6 -0
  133. package/dist/types/create-editor/get-ui-component.d.ts +1 -1
  134. package/dist/types/create-editor/getScrollGutterOptions.d.ts +3 -0
  135. package/dist/types/create-editor/sortByRank.d.ts +5 -0
  136. package/dist/types/editor.d.ts +1 -1
  137. package/dist/types/entry-points/editor.d.ts +10 -1
  138. package/dist/types/entry-points/test-utils.d.ts +5 -2
  139. package/dist/types/index.d.ts +3 -1
  140. package/dist/types/isElementBySelectorInDocument.d.ts +7 -0
  141. package/dist/types/presets/universal.d.ts +1 -2
  142. package/dist/types/setTextSelection.d.ts +2 -0
  143. package/dist/types/test-utils.d.ts +1 -10
  144. package/dist/types/types/with-appearance-component.d.ts +1 -1
  145. package/dist/types/ui/Addon/ClickAreaBlock/contentComponentWrapper.d.ts +1 -1
  146. package/dist/types/ui/Addon/checkForModal.d.ts +10 -0
  147. package/dist/types/ui/Addon/click-area-helper.d.ts +0 -11
  148. package/dist/types/ui/Addon/outsideProsemirrorEditorClickHandler.d.ts +2 -0
  149. package/dist/types/ui/Appearance/Chromeless.d.ts +2 -10
  150. package/dist/types/ui/Appearance/ChromelessEditorContainer.d.ts +9 -0
  151. package/dist/types/ui/Appearance/Comment/Comment.d.ts +1 -1
  152. package/dist/types/ui/Appearance/FullPage/CustomToolbarWrapperMigration.d.ts +4 -0
  153. package/dist/types/ui/Appearance/FullPage/FullPage.d.ts +1 -1
  154. package/dist/types/ui/Appearance/FullPage/FullPageContentArea.d.ts +1 -1
  155. package/dist/types/ui/Appearance/FullPage/FullPageToolbar.d.ts +1 -1
  156. package/dist/types/ui/Appearance/FullPage/FullPageToolbarNext.d.ts +1 -1
  157. package/dist/types/ui/Appearance/FullPage/MainToolbar.d.ts +0 -10
  158. package/dist/types/ui/Appearance/FullPage/MainToolbarIconBeforeMigration.d.ts +4 -0
  159. package/dist/types/ui/Appearance/FullPage/NonCustomToolbarWrapperMigration.d.ts +4 -0
  160. package/dist/types/utils/combineQuickInsertProviders.d.ts +2 -0
  161. package/dist/types/utils/extensions.d.ts +0 -1
  162. package/dist/types/utils/getNodesVisibleInViewport.d.ts +0 -5
  163. package/dist/types/utils/isNodeVisible.d.ts +5 -0
  164. package/dist/types/utils/validNode.d.ts +2 -0
  165. package/dist/types/utils/validateNodes.d.ts +0 -1
  166. package/dist/types-ts4.5/actions/isEmptyParagraph.d.ts +5 -0
  167. package/dist/types-ts4.5/actions/temp-is-empty-document.d.ts +0 -4
  168. package/dist/types-ts4.5/composable-editor/editor-internal.d.ts +1 -1
  169. package/dist/types-ts4.5/create-editor/ReactEditorView.d.ts +2 -2
  170. package/dist/types-ts4.5/create-editor/addMetadataAttributes.d.ts +16 -0
  171. package/dist/types-ts4.5/create-editor/create-editor.d.ts +1 -17
  172. package/dist/types-ts4.5/create-editor/create-plugins-list.d.ts +1 -4
  173. package/dist/types-ts4.5/create-editor/create-schema.d.ts +0 -15
  174. package/dist/types-ts4.5/create-editor/create-universal-preset.d.ts +1 -1
  175. package/dist/types-ts4.5/create-editor/createErrorReporter.d.ts +3 -0
  176. package/dist/types-ts4.5/create-editor/createPMPlugins.d.ts +3 -0
  177. package/dist/types-ts4.5/create-editor/fixExcludes.d.ts +6 -0
  178. package/dist/types-ts4.5/create-editor/get-ui-component.d.ts +1 -1
  179. package/dist/types-ts4.5/create-editor/getScrollGutterOptions.d.ts +3 -0
  180. package/dist/types-ts4.5/create-editor/sortByRank.d.ts +5 -0
  181. package/dist/types-ts4.5/editor.d.ts +1 -1
  182. package/dist/types-ts4.5/entry-points/editor.d.ts +10 -1
  183. package/dist/types-ts4.5/entry-points/test-utils.d.ts +5 -2
  184. package/dist/types-ts4.5/index.d.ts +3 -1
  185. package/dist/types-ts4.5/isElementBySelectorInDocument.d.ts +7 -0
  186. package/dist/types-ts4.5/presets/universal.d.ts +1 -2
  187. package/dist/types-ts4.5/setTextSelection.d.ts +2 -0
  188. package/dist/types-ts4.5/test-utils.d.ts +1 -10
  189. package/dist/types-ts4.5/types/with-appearance-component.d.ts +1 -1
  190. package/dist/types-ts4.5/ui/Addon/ClickAreaBlock/contentComponentWrapper.d.ts +1 -1
  191. package/dist/types-ts4.5/ui/Addon/checkForModal.d.ts +10 -0
  192. package/dist/types-ts4.5/ui/Addon/click-area-helper.d.ts +0 -11
  193. package/dist/types-ts4.5/ui/Addon/outsideProsemirrorEditorClickHandler.d.ts +2 -0
  194. package/dist/types-ts4.5/ui/Appearance/Chromeless.d.ts +2 -10
  195. package/dist/types-ts4.5/ui/Appearance/ChromelessEditorContainer.d.ts +9 -0
  196. package/dist/types-ts4.5/ui/Appearance/Comment/Comment.d.ts +1 -1
  197. package/dist/types-ts4.5/ui/Appearance/FullPage/CustomToolbarWrapperMigration.d.ts +4 -0
  198. package/dist/types-ts4.5/ui/Appearance/FullPage/FullPage.d.ts +1 -1
  199. package/dist/types-ts4.5/ui/Appearance/FullPage/FullPageContentArea.d.ts +1 -1
  200. package/dist/types-ts4.5/ui/Appearance/FullPage/FullPageToolbar.d.ts +1 -1
  201. package/dist/types-ts4.5/ui/Appearance/FullPage/FullPageToolbarNext.d.ts +1 -1
  202. package/dist/types-ts4.5/ui/Appearance/FullPage/MainToolbar.d.ts +0 -10
  203. package/dist/types-ts4.5/ui/Appearance/FullPage/MainToolbarIconBeforeMigration.d.ts +4 -0
  204. package/dist/types-ts4.5/ui/Appearance/FullPage/NonCustomToolbarWrapperMigration.d.ts +4 -0
  205. package/dist/types-ts4.5/utils/combineQuickInsertProviders.d.ts +2 -0
  206. package/dist/types-ts4.5/utils/extensions.d.ts +0 -1
  207. package/dist/types-ts4.5/utils/getNodesVisibleInViewport.d.ts +0 -5
  208. package/dist/types-ts4.5/utils/isNodeVisible.d.ts +5 -0
  209. package/dist/types-ts4.5/utils/validNode.d.ts +2 -0
  210. package/dist/types-ts4.5/utils/validateNodes.d.ts +0 -1
  211. package/package.json +11 -11
  212. package/dist/cjs/types/index.js +0 -1
  213. package/dist/es2019/types/index.js +0 -0
  214. package/dist/esm/types/index.js +0 -0
  215. package/dist/types/types/index.d.ts +0 -9
  216. package/dist/types-ts4.5/types/index.d.ts +0 -9
package/CHANGELOG.md CHANGED
@@ -1,5 +1,86 @@
1
1
  # @atlaskit/editor-core
2
2
 
3
+ ## 220.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`971e92e232624`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/971e92e232624) -
8
+ Added a new `DISABLED` visual variant for mention chips so rendering surfaces (such as the editor
9
+ mentions plugin) can render a chip in a non-interactive disabled state with an explanatory
10
+ tooltip. Includes optional `MentionProvider` hooks that let consumers drive the disabled state
11
+ reactively and observe mention deletions.
12
+
13
+ **`@atlaskit/mention`**
14
+ - New `MentionType.DISABLED` enum value and matching style on `PrimitiveMention`.
15
+ - New optional `isDisabled` and `disabledTooltip` props on the React `<Mention>` component. When
16
+ `isDisabled` is set the chip becomes non-clickable, exposes `aria-disabled="true"`, remains
17
+ keyboard-focusable (`tabindex="0"`), and — when `disabledTooltip` is also set — is wrapped in an
18
+ ADS `<Tooltip>` whose content is mirrored into `aria-label` for screen readers.
19
+ - New `MentionDisabledState` (`{ disabled: boolean; tooltip?: string }`) and
20
+ `MentionDisabledStateInput` (`{ id: string }`) types, re-exported from `@atlaskit/mention` and
21
+ `@atlaskit/mention/resource`.
22
+ - New optional `MentionResource` config option `getMentionDisabledState` (forwarded by
23
+ `ContextMentionResource`) that surfaces through three new optional methods on the
24
+ `MentionProvider` interface:
25
+ - `getMentionDisabledState?(mention)` — predicate the editor calls to determine whether a chip
26
+ should render disabled.
27
+ - `subscribeToDisabledStateChanges?(listener)` — lets the editor re-evaluate the predicate when
28
+ the consumer's inputs change.
29
+ - `notifyMentionDestroyed?(mention)` — lets the consumer observe chip removals (e.g. to update
30
+ its source of truth).
31
+
32
+ All three methods are optional so existing `MentionProvider` implementations continue to compile
33
+ and behave identically.
34
+
35
+ **`@atlaskit/editor-plugin-mentions` + `@atlaskit/editor-core`**
36
+ - The mention `NodeView` now reads `MentionProvider.getMentionDisabledState?.({ id })` on every
37
+ state update and re-evaluates whenever `subscribeToDisabledStateChanges` notifies. When the
38
+ predicate returns `{ disabled: true }` the chip gets a new `.mention-disabled` class,
39
+ `aria-disabled="true"`, and an ADS `<Tooltip>` (anchored to the chip via `portalProviderAPI`)
40
+ carrying the `tooltip` text. The chip remains keyboard-focusable.
41
+ - The mention `NodeView.destroy()` calls `notifyMentionDestroyed?.({ id })` on the subscribed
42
+ provider so consumers can react to chip removals without depending on the editor's `onChange`.
43
+ - Added a matching `.editor-mention-primitive.mention-disabled` style in `@atlaskit/editor-core`
44
+ so the new class renders correctly inside the editor content container.
45
+ - Providers that don't implement the new optional methods are entirely unaffected.
46
+
47
+ **`@atlassian/conversation-assistant`, `@atlassian/conversation-assistant-widget` (chat store)**
48
+ - New `addSelectedAgentId({ conversationId, agentId })` action — append-only, no-dedup push onto
49
+ the conversation's `selectedAgentIds` history. Each call adds exactly one entry; duplicates are
50
+ preserved so the history is a 1-to-1 log of every agent chip currently in the editor.
51
+ - New `removeSelectedAgentId({ conversationId, agentId })` action — removes the **rightmost**
52
+ occurrence of an id (preserving order of other entries) for use when a single agent chip is
53
+ deleted from the editor.
54
+ - `setSelectedAgentIds` retains its wholesale-replace semantics (unchanged externally).
55
+ - The picker callback in `chat-input-refresh` is now wired to `addSelectedAgentId`; chip-deletion
56
+ is wired to `removeSelectedAgentId`. The active agent is always `selectedAgentIds.at(-1)`.
57
+
58
+ **`@atlassian/conversation-assistant-chat-prompt-input`**
59
+ - `useChatMentionResource` accepts new options `getSelectedAgentIds`, `disabledAgentTooltip`, and
60
+ `onAgentMentionDestroyed` that wire the new `MentionProvider` capabilities described above.
61
+ - `withAgentSupport` extended with the same options, plus a `notifyMentionDestroyed`
62
+ implementation that forwards to the consumer when a known agent chip is destroyed (sourced from
63
+ the editor `NodeView` rather than from `onChange`, which is not reliably called on every chat
64
+ surface).
65
+ - `<RovoChatPromptInput>` exposes new optional `selectedAgentIds`, `disabledAgentTooltip`, and
66
+ `onAgentMentionDeleted` props for consumers that want to drive the disabled-agent chip state
67
+ from their own store.
68
+
69
+ **`@atlassian/conversation-assistant-store`**
70
+ - JSDoc on the `selectedAgentIds` conversation field updated to document the new append-only /
71
+ rightmost-remove semantics and the canonical read pattern (`.at(-1)` for the active agent). No
72
+ runtime or type-shape change.
73
+
74
+ ### Patch Changes
75
+
76
+ - Updated dependencies
77
+
78
+ ## 220.0.3
79
+
80
+ ### Patch Changes
81
+
82
+ - Updated dependencies
83
+
3
84
  ## 220.0.2
4
85
 
5
86
  ### Patch Changes
@@ -0,0 +1,17 @@
1
+ import type { default as core } from 'jscodeshift';
2
+ import type { Collection } from 'jscodeshift/src/Collection';
3
+
4
+ /**
5
+ * Renames a variable with the given name.
6
+ *
7
+ * @param from String
8
+ * @param toName String
9
+ */
10
+ export const createRenameVariableTransform = (from: string, toName: string) => {
11
+ return (j: core.JSCodeshift, source: Collection<unknown>): void => {
12
+ source.find(j.Identifier, { name: from }).forEach((x) => {
13
+ // eslint-disable-next-line @atlassian/perf-linting/no-expensive-split-replace -- Ignored via go/ees017 (to be fixed)
14
+ x.replace(j.identifier(toName));
15
+ });
16
+ };
17
+ };
@@ -0,0 +1,54 @@
1
+ import type { default as core } from 'jscodeshift';
2
+ import type { Collection } from 'jscodeshift/src/Collection';
3
+
4
+ /**
5
+ * Finds import from a particular path/package matching a particular name.
6
+ * Also deals with the case where import is renamed (ie. `import { X as Y } from 'Z';`)
7
+ *
8
+ * @param j
9
+ * @param source The source collection.
10
+ * @param pkg The path or package it came from.
11
+ * @param importName The import identifier.
12
+ * @returns String[] Array of result names which match the specified importName
13
+ */
14
+ export const findImportFromPackage = (
15
+ j: core.JSCodeshift,
16
+ source: Collection<unknown>,
17
+ pkg: string,
18
+ importName: string,
19
+ ): string[] => {
20
+ // Find regular or renamed imports
21
+ return (
22
+ source
23
+ // find all import statements which import from the given package
24
+ .find(j.ImportDeclaration, {
25
+ source: {
26
+ value: pkg,
27
+ },
28
+ })
29
+ // narrow down to imports related to 'component'
30
+ .filter(
31
+ (importDeclaration) =>
32
+ j(importDeclaration).find(j.ImportSpecifier, {
33
+ imported: {
34
+ type: 'Identifier',
35
+ name: importName,
36
+ },
37
+ }).length > 0,
38
+ )
39
+ .nodes()
40
+ .map((importDeclaration): string => {
41
+ const importSpecifier = j(importDeclaration)
42
+ .find(j.ImportSpecifier, {
43
+ imported: {
44
+ type: 'Identifier',
45
+ name: importName,
46
+ },
47
+ })
48
+ .nodes()[0];
49
+
50
+ return importSpecifier.local?.name || '';
51
+ })
52
+ .filter((name) => Boolean(name))
53
+ );
54
+ };
@@ -0,0 +1,43 @@
1
+ import type core from 'jscodeshift';
2
+ import type { Collection } from 'jscodeshift/src/Collection';
3
+
4
+ /**
5
+ * Renames a JSX attribute with the given name to be a key
6
+ * within the JSX attribute toObjectName of the name toObjectKey.
7
+ *
8
+ * @param from String
9
+ * @param toObjectName String
10
+ * @param toObjectKey String
11
+ */
12
+ export const createJSXRenameVariableToNestedKeyTransform = (
13
+ from: string,
14
+ toObjectName: string,
15
+ toObjectKey: string,
16
+ ) => {
17
+ return (j: core.JSCodeshift, source: Collection<unknown>): void => {
18
+ source
19
+ .find(j.JSXAttribute, { name: { type: 'JSXIdentifier', name: from } })
20
+ .forEach((fromAttribute) => {
21
+ // is there an existing destination prop
22
+ const isExistingAttribute =
23
+ source.find(j.JSXAttribute, {
24
+ name: { type: 'JSXIdentifier', name: toObjectName },
25
+ }).length !== 0;
26
+
27
+ if (
28
+ !isExistingAttribute &&
29
+ fromAttribute.node.value?.type === 'JSXExpressionContainer' &&
30
+ fromAttribute.node.value.expression.type === 'ObjectExpression'
31
+ ) {
32
+ const existingProperties = fromAttribute.node.value.expression.properties;
33
+ const newObject = j.objectExpression([
34
+ j.property('init', j.identifier(toObjectKey), j.objectExpression(existingProperties)),
35
+ ]);
36
+ // eslint-disable-next-line @atlassian/perf-linting/no-expensive-split-replace -- Ignored via go/ees017 (to be fixed)
37
+ fromAttribute.replace(
38
+ j.jsxAttribute(j.jsxIdentifier(toObjectName), j.jsxExpressionContainer(newObject)),
39
+ );
40
+ }
41
+ });
42
+ };
43
+ };
@@ -0,0 +1,25 @@
1
+ import type core from 'jscodeshift';
2
+ import type { Collection } from 'jscodeshift/src/Collection';
3
+
4
+ /**
5
+ * Generate a codemod to move component from Editor to
6
+ * EditorMigrationComponent
7
+ * Ref: ED-16826
8
+ */
9
+ export const createUpdateEditorToMigrationComponent = (pkg: string, component: string) => {
10
+ return (j: core.JSCodeshift, source: Collection<unknown>): void => {
11
+ source
12
+ .find(j.ImportDeclaration, { source: { value: pkg } })
13
+ .filter(
14
+ (path) =>
15
+ j(path).find(j.ImportSpecifier, {
16
+ imported: { type: 'Identifier', name: component },
17
+ }).length > 0,
18
+ )
19
+ .find(j.ImportSpecifier)
20
+ .filter((path) => path.node.imported.name === component)
21
+ .replaceWith((currentImport) =>
22
+ j.importSpecifier(j.identifier('EditorMigrationComponent'), currentImport.node.local),
23
+ );
24
+ };
25
+ };
@@ -1,7 +1,7 @@
1
1
  import type core from 'jscodeshift';
2
2
  import type { Collection } from 'jscodeshift/src/Collection';
3
3
 
4
- import { findImportFromPackage } from '../utils';
4
+ import { findImportFromPackage } from '../findImportFromPackage';
5
5
  /**
6
6
  * Generate a codemod to remove `allowMoreTextColors` field
7
7
  * from `allowTextColor` Editor prop.
@@ -1,7 +1,7 @@
1
1
  import type core from 'jscodeshift';
2
2
  import type { Collection } from 'jscodeshift/src/Collection';
3
3
 
4
- import { findImportFromPackage } from '../utils';
4
+ import { findImportFromPackage } from '../findImportFromPackage';
5
5
 
6
6
  const createRemoveComponentPropTransform = (pkg: string, component: string, propName: string) => {
7
7
  return (j: core.JSCodeshift, source: Collection<unknown>): void => {
@@ -1,28 +1,7 @@
1
1
  import type core from 'jscodeshift';
2
2
  import type { Collection } from 'jscodeshift/src/Collection';
3
3
 
4
- /**
5
- * Generate a codemod to move component from Editor to
6
- * EditorMigrationComponent
7
- * Ref: ED-16826
8
- */
9
- export const createUpdateEditorToMigrationComponent = (pkg: string, component: string) => {
10
- return (j: core.JSCodeshift, source: Collection<unknown>): void => {
11
- source
12
- .find(j.ImportDeclaration, { source: { value: pkg } })
13
- .filter(
14
- (path) =>
15
- j(path).find(j.ImportSpecifier, {
16
- imported: { type: 'Identifier', name: component },
17
- }).length > 0,
18
- )
19
- .find(j.ImportSpecifier)
20
- .filter((path) => path.node.imported.name === component)
21
- .replaceWith((currentImport) =>
22
- j.importSpecifier(j.identifier('EditorMigrationComponent'), currentImport.node.local),
23
- );
24
- };
25
- };
4
+ import { createUpdateEditorToMigrationComponent } from './createUpdateEditorToMigrationComponent';
26
5
 
27
6
  export const renameEditorToMigrationComponent: (
28
7
  j: core.JSCodeshift,
@@ -1,46 +1,7 @@
1
1
  import type core from 'jscodeshift';
2
2
  import type { Collection } from 'jscodeshift/src/Collection';
3
3
 
4
- /**
5
- * Renames a JSX attribute with the given name to be a key
6
- * within the JSX attribute toObjectName of the name toObjectKey.
7
- *
8
- * @param from String
9
- * @param toObjectName String
10
- * @param toObjectKey String
11
- */
12
- export const createJSXRenameVariableToNestedKeyTransform = (
13
- from: string,
14
- toObjectName: string,
15
- toObjectKey: string,
16
- ) => {
17
- return (j: core.JSCodeshift, source: Collection<unknown>): void => {
18
- source
19
- .find(j.JSXAttribute, { name: { type: 'JSXIdentifier', name: from } })
20
- .forEach((fromAttribute) => {
21
- // is there an existing destination prop
22
- const isExistingAttribute =
23
- source.find(j.JSXAttribute, {
24
- name: { type: 'JSXIdentifier', name: toObjectName },
25
- }).length !== 0;
26
-
27
- if (
28
- !isExistingAttribute &&
29
- fromAttribute.node.value?.type === 'JSXExpressionContainer' &&
30
- fromAttribute.node.value.expression.type === 'ObjectExpression'
31
- ) {
32
- const existingProperties = fromAttribute.node.value.expression.properties;
33
- const newObject = j.objectExpression([
34
- j.property('init', j.identifier(toObjectKey), j.objectExpression(existingProperties)),
35
- ]);
36
- // eslint-disable-next-line @atlassian/perf-linting/no-expensive-split-replace -- Ignored via go/ees017 (to be fixed)
37
- fromAttribute.replace(
38
- j.jsxAttribute(j.jsxIdentifier(toObjectName), j.jsxExpressionContainer(newObject)),
39
- );
40
- }
41
- });
42
- };
43
- };
4
+ import { createJSXRenameVariableToNestedKeyTransform } from './createJSXRenameVariableToNestedKeyTransform';
44
5
 
45
6
  export const renameSmartLinksProp: (j: core.JSCodeshift, source: Collection<unknown>) => void =
46
7
  createJSXRenameVariableToNestedKeyTransform('smartLinks', 'linking', 'smartLinks');
@@ -1,7 +1,7 @@
1
1
  import type { JSCodeshift } from 'jscodeshift';
2
2
  import type { Collection } from 'jscodeshift/src/Collection';
3
3
 
4
- import { createRenameVariableTransform } from '../utils';
4
+ import { createRenameVariableTransform } from '../createRenameVariableTransform';
5
5
 
6
6
  export const renameUnsafeAllowUndoRedoButtonsProp: (
7
7
  j: JSCodeshift,
@@ -1,7 +1,7 @@
1
1
  import type { JSCodeshift } from 'jscodeshift';
2
2
  import type { Collection } from 'jscodeshift/src/Collection';
3
3
 
4
- import { createRenameVariableTransform } from '../utils';
4
+ import { createRenameVariableTransform } from '../createRenameVariableTransform';
5
5
 
6
6
  export const renameUnsafeCardProp: (j: JSCodeshift, source: Collection<unknown>) => void =
7
7
  createRenameVariableTransform('UNSAFE_cards', 'smartLinks');
package/codemods/utils.ts CHANGED
@@ -36,70 +36,3 @@ export const createTransformer =
36
36
 
37
37
  return source.toSource(options.printOptions || { quote: 'single' });
38
38
  };
39
-
40
- /**
41
- * Finds import from a particular path/package matching a particular name.
42
- * Also deals with the case where import is renamed (ie. `import { X as Y } from 'Z';`)
43
- *
44
- * @param j
45
- * @param source The source collection.
46
- * @param pkg The path or package it came from.
47
- * @param importName The import identifier.
48
- * @returns String[] Array of result names which match the specified importName
49
- */
50
- export const findImportFromPackage = (
51
- j: core.JSCodeshift,
52
- source: Collection<unknown>,
53
- pkg: string,
54
- importName: string,
55
- ): string[] => {
56
- // Find regular or renamed imports
57
- return (
58
- source
59
- // find all import statements which import from the given package
60
- .find(j.ImportDeclaration, {
61
- source: {
62
- value: pkg,
63
- },
64
- })
65
- // narrow down to imports related to 'component'
66
- .filter(
67
- (importDeclaration) =>
68
- j(importDeclaration).find(j.ImportSpecifier, {
69
- imported: {
70
- type: 'Identifier',
71
- name: importName,
72
- },
73
- }).length > 0,
74
- )
75
- .nodes()
76
- .map((importDeclaration): string => {
77
- const importSpecifier = j(importDeclaration)
78
- .find(j.ImportSpecifier, {
79
- imported: {
80
- type: 'Identifier',
81
- name: importName,
82
- },
83
- })
84
- .nodes()[0];
85
-
86
- return importSpecifier.local?.name || '';
87
- })
88
- .filter((name) => Boolean(name))
89
- );
90
- };
91
-
92
- /**
93
- * Renames a variable with the given name.
94
- *
95
- * @param from String
96
- * @param toName String
97
- */
98
- export const createRenameVariableTransform = (from: string, toName: string) => {
99
- return (j: core.JSCodeshift, source: Collection<unknown>): void => {
100
- source.find(j.Identifier, { name: from }).forEach((x) => {
101
- // eslint-disable-next-line @atlassian/perf-linting/no-expensive-split-replace -- Ignored via go/ees017 (to be fixed)
102
- x.replace(j.identifier(toName));
103
- });
104
- };
105
- };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isEmptyParagraph = isEmptyParagraph;
7
+ /**
8
+ * Checks if node is an empty paragraph.
9
+ */
10
+ function isEmptyParagraph(node) {
11
+ return !!node && node.type.name === 'paragraph' && !node.childCount;
12
+ }
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.isEmptyDocument = isEmptyDocument;
7
- exports.isEmptyParagraph = isEmptyParagraph;
7
+ var _isEmptyParagraph = require("./isEmptyParagraph");
8
8
  /**
9
9
  * Temporary file which extracts function from `editor-common`.
10
10
  *
@@ -12,13 +12,6 @@ exports.isEmptyParagraph = isEmptyParagraph;
12
12
  * help decouple it from editor-common
13
13
  */
14
14
 
15
- /**
16
- * Checks if node is an empty paragraph.
17
- */
18
- function isEmptyParagraph(node) {
19
- return !!node && node.type.name === 'paragraph' && !node.childCount;
20
- }
21
-
22
15
  /**
23
16
  * Checks if a node looks like an empty document
24
17
  */
@@ -27,5 +20,5 @@ function isEmptyDocument(node) {
27
20
  if (node.childCount !== 1 || !nodeChild) {
28
21
  return false;
29
22
  }
30
- return isEmptyParagraph(nodeChild);
23
+ return (0, _isEmptyParagraph.isEmptyParagraph)(nodeChild);
31
24
  }
@@ -13,6 +13,7 @@ var _findChangedNodesFromTransaction = require("../../utils/findChangedNodesFrom
13
13
  var _saferTransactions = require("../../utils/performance/safer-transactions");
14
14
  var _trackTransactions = require("../../utils/performance/track-transactions");
15
15
  var _validateNodes = require("../../utils/validateNodes");
16
+ var _validNode = require("../../utils/validNode");
16
17
  var useDispatchTransaction = exports.useDispatchTransaction = function useDispatchTransaction(_ref) {
17
18
  var onChange = _ref.onChange,
18
19
  dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
@@ -69,7 +70,7 @@ var useDispatchTransaction = exports.useDispatchTransaction = function useDispat
69
70
  }
70
71
  if (!changedNodesValid) {
71
72
  var invalidNodes = nodes.filter(function (node) {
72
- return !(0, _validateNodes.validNode)(node);
73
+ return !(0, _validNode.validNode)(node);
73
74
  }).map(function (node) {
74
75
  return (0, _coreUtils.getDocStructure)(node, {
75
76
  compact: true
@@ -50,6 +50,8 @@ var _consts = require("./consts");
50
50
  var _createEditor = require("./create-editor");
51
51
  var _createPluginsList = _interopRequireDefault(require("./create-plugins-list"));
52
52
  var _createSchema = require("./create-schema");
53
+ var _createErrorReporter = require("./createErrorReporter");
54
+ var _createPMPlugins = require("./createPMPlugins");
53
55
  var _filterPluginsForReconfigure = require("./filter-plugins-for-reconfigure");
54
56
  var _messages = require("./messages");
55
57
  var _focusEditorElement = require("./ReactEditorView/focusEditorElement");
@@ -151,7 +153,7 @@ function ReactEditorView(props) {
151
153
  return (0, _eventDispatcher.createDispatch)(eventDispatcher);
152
154
  }, [eventDispatcher]);
153
155
  var errorReporter = (0, _react.useMemo)(function () {
154
- return (0, _createEditor.createErrorReporter)(errorReporterHandler);
156
+ return (0, _createErrorReporter.createErrorReporter)(errorReporterHandler);
155
157
  }, [errorReporterHandler]);
156
158
  var handleAnalyticsEvent = (0, _react.useCallback)(function (payload) {
157
159
  (0, _analytics.fireAnalyticsEvent)(props.createAnalyticsEvent)(payload);
@@ -213,7 +215,7 @@ function ReactEditorView(props) {
213
215
  schema = (0, _createSchema.createSchema)(config.current);
214
216
  }
215
217
  var contentTransformerProvider = options.props.editorProps.contentTransformerProvider;
216
- var plugins = (0, _createEditor.createPMPlugins)({
218
+ var plugins = (0, _createPMPlugins.createPMPlugins)({
217
219
  schema: schema,
218
220
  dispatch: dispatch,
219
221
  errorReporter: errorReporter,
@@ -511,7 +513,7 @@ function ReactEditorView(props) {
511
513
  // Old selection's positions / node types may not map onto the new schema.
512
514
  newSelection = _state2.Selection.atStart(newDoc);
513
515
  }
514
- var plugins = (0, _createEditor.createPMPlugins)({
516
+ var plugins = (0, _createPMPlugins.createPMPlugins)({
515
517
  schema: newSchema,
516
518
  dispatch: dispatch,
517
519
  errorReporter: errorReporter,
@@ -534,7 +536,7 @@ function ReactEditorView(props) {
534
536
  plugins: plugins
535
537
  });
536
538
  } else {
537
- var _plugins = (0, _createEditor.createPMPlugins)({
539
+ var _plugins = (0, _createPMPlugins.createPMPlugins)({
538
540
  schema: state.schema,
539
541
  dispatch: dispatch,
540
542
  errorReporter: errorReporter,
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.addMetadataAttributes = void 0;
8
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
9
+ var _prosemirrorDomMetadata = require("@atlaskit/editor-common/prosemirror-dom-metadata");
10
+ /**
11
+ * 🧱 Internal Helper Function: Editor FE Platform
12
+ *
13
+ * Adds generic metadata attributes to a DOMOutputSpec array based on the provided node or mark.
14
+ * This function ensures that the DOMOutputSpec is annotated with ProseMirror-specific metadata.
15
+ *
16
+ * @param {object} params - Parameters object.
17
+ * @param {PMNode | PMMark} params.nodeOrMark - The ProseMirror node or mark to extract metadata from.
18
+ * @param {DOMOutputSpec} params.domSpec - The DOMOutputSpec to which attributes will be added.
19
+ * @returns {DOMOutputSpec} The modified DOMOutputSpec with additional metadata.
20
+ */
21
+ var addMetadataAttributes = exports.addMetadataAttributes = function addMetadataAttributes(_ref) {
22
+ var nodeOrMark = _ref.nodeOrMark,
23
+ domSpec = _ref.domSpec;
24
+ if (!Array.isArray(domSpec)) {
25
+ return domSpec;
26
+ }
27
+ var maybeDefinedAttributes = domSpec[1];
28
+ var metadata = (0, _prosemirrorDomMetadata.createProseMirrorMetadata)(nodeOrMark);
29
+ var hasDefinedAttributes = (0, _typeof2.default)(maybeDefinedAttributes) === 'object' && !Array.isArray(maybeDefinedAttributes);
30
+ if (hasDefinedAttributes) {
31
+ domSpec[1] = Object.assign(maybeDefinedAttributes, metadata);
32
+ } else {
33
+ domSpec.splice(1, 0, metadata);
34
+ }
35
+ return domSpec;
36
+ };
@@ -4,36 +4,8 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.createErrorReporter = createErrorReporter;
8
- exports.createPMPlugins = createPMPlugins;
9
- exports.fixExcludes = fixExcludes;
10
7
  exports.processPluginsList = processPluginsList;
11
- exports.sortByRank = sortByRank;
12
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
- var _errorReporter = require("@atlaskit/editor-common/error-reporter");
14
- var _legacyRankPlugins = require("@atlaskit/editor-common/legacy-rank-plugins");
15
- var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
16
- var _editorNativeAnchorSupportPlugin = require("./editorNativeAnchorSupportPlugin");
17
- var _editorStateNotificationPlugin = require("./editorStateNotificationPlugin");
18
- function sortByRank(a, b) {
19
- return a.rank - b.rank;
20
- }
21
- function fixExcludes(marks) {
22
- var markKeys = Object.keys(marks);
23
- var markGroups = new Set(markKeys.map(function (mark) {
24
- return marks[mark].group;
25
- }));
26
- markKeys.forEach(function (markKey) {
27
- var mark = marks[markKey];
28
- if (mark.excludes) {
29
- // eslint-disable-next-line @atlassian/perf-linting/no-expensive-split-replace -- Ignored via go/ees017 (to be fixed)
30
- mark.excludes = mark.excludes.split(' ').filter(function (group) {
31
- return markGroups.has(group);
32
- }).join(' ');
33
- }
34
- });
35
- return marks;
36
- }
37
9
  function processPluginsList(plugins) {
38
10
  /**
39
11
  * First pass to collect pluginsOptions
@@ -102,38 +74,4 @@ function processPluginsList(plugins) {
102
74
  secondaryToolbarComponents: [],
103
75
  onEditorViewStateUpdatedCallbacks: []
104
76
  });
105
- }
106
- function createPMPlugins(config) {
107
- var editorConfig = config.editorConfig;
108
- var pmPlugins = editorConfig.pmPlugins.sort((0, _legacyRankPlugins.sortByOrder)('plugins')).map(function (_ref) {
109
- var plugin = _ref.plugin;
110
- return plugin({
111
- schema: config.schema,
112
- dispatch: config.dispatch,
113
- eventDispatcher: config.eventDispatcher,
114
- providerFactory: config.providerFactory,
115
- errorReporter: config.errorReporter,
116
- portalProviderAPI: config.portalProviderAPI,
117
- nodeViewPortalProviderAPI: config.nodeViewPortalProviderAPI,
118
- dispatchAnalyticsEvent: config.dispatchAnalyticsEvent,
119
- featureFlags: config.featureFlags || {},
120
- getIntl: config.getIntl
121
- });
122
- }).filter(function (plugin) {
123
- return typeof plugin !== 'undefined';
124
- });
125
- if ((0, _expValEquals.expValEquals)('platform_editor_native_anchor_with_dnd', 'isEnabled', true)) {
126
- pmPlugins.push((0, _editorNativeAnchorSupportPlugin.createEditorNativeAnchorSupportPlugin)(config.schema));
127
- }
128
- if (config.onEditorStateUpdated !== undefined) {
129
- return [(0, _editorStateNotificationPlugin.createEditorStateNotificationPlugin)(config.onEditorStateUpdated, config.editorConfig.onEditorViewStateUpdatedCallbacks)].concat((0, _toConsumableArray2.default)(pmPlugins));
130
- }
131
- return pmPlugins;
132
- }
133
- function createErrorReporter(errorReporterHandler) {
134
- var errorReporter = new _errorReporter.ErrorReporter();
135
- if (errorReporterHandler) {
136
- errorReporter.handler = errorReporterHandler;
137
- }
138
- return errorReporter;
139
77
  }