@atlaskit/editor-core 182.0.3 → 182.1.1

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 (269) hide show
  1. package/.eslintrc.js +2 -0
  2. package/CHANGELOG.md +47 -0
  3. package/README.md +20 -0
  4. package/architecture/0001-record-architecture-decisions.md +25 -0
  5. package/architecture/0002-deep-equality-check-for-getsharedstate.md +67 -0
  6. package/architecture/0003-explicit-plugin-dependencies.md +291 -0
  7. package/dist/cjs/actions/index.js +17 -6
  8. package/dist/cjs/analytics-api/attach-payload-into-transaction.js +2 -1
  9. package/dist/cjs/create-editor/ErrorBoundary.js +1 -16
  10. package/dist/cjs/create-editor/ReactEditorViewInternal.js +3 -3
  11. package/dist/cjs/editor-next/editor-internal.js +2 -1
  12. package/dist/cjs/editor-next/index.js +5 -1
  13. package/dist/cjs/editor.js +9 -5
  14. package/dist/cjs/keymaps/index.js +12 -0
  15. package/dist/cjs/labs/next/internal/hooks/use-editor/index.js +5 -7
  16. package/dist/cjs/labs/next/presets/default.js +1 -2
  17. package/dist/cjs/plugins/card/index.js +16 -5
  18. package/dist/cjs/plugins/card/pm-plugins/actions.js +10 -1
  19. package/dist/cjs/plugins/card/pm-plugins/analytics/create-analytics-queue.js +48 -0
  20. package/dist/cjs/plugins/card/pm-plugins/analytics/events-from-tr.js +337 -0
  21. package/dist/cjs/plugins/card/pm-plugins/analytics/index.js +19 -0
  22. package/dist/cjs/plugins/card/pm-plugins/analytics/types.js +5 -0
  23. package/dist/cjs/plugins/card/pm-plugins/analytics/utils.js +139 -0
  24. package/dist/cjs/plugins/card/pm-plugins/doc.js +99 -22
  25. package/dist/cjs/plugins/card/pm-plugins/main.js +16 -10
  26. package/dist/cjs/plugins/card/pm-plugins/reducers.js +7 -0
  27. package/dist/cjs/plugins/card/pm-plugins/util/resolve.js +3 -7
  28. package/dist/cjs/plugins/card/toolbar.js +18 -8
  29. package/dist/cjs/plugins/card/ui/EditLinkToolbar.js +12 -8
  30. package/dist/cjs/plugins/card/ui/EditorSmartCardEventsNext.js +202 -0
  31. package/dist/cjs/plugins/card/ui/LinkToolbarAppearance.js +12 -4
  32. package/dist/cjs/plugins/card/utils.js +4 -2
  33. package/dist/cjs/plugins/extension/context-panel.js +3 -2
  34. package/dist/cjs/plugins/extension/index.js +4 -1
  35. package/dist/cjs/plugins/help-dialog/ui/index.js +29 -8
  36. package/dist/cjs/plugins/hyperlink/Toolbar.js +12 -2
  37. package/dist/cjs/plugins/hyperlink/commands.js +9 -5
  38. package/dist/cjs/plugins/hyperlink/pm-plugins/input-rule.js +4 -0
  39. package/dist/cjs/plugins/hyperlink/ui/HyperlinkAddToolbar/index.js +2 -2
  40. package/dist/cjs/plugins/index.js +0 -7
  41. package/dist/cjs/plugins/insert-block/index.js +5 -1
  42. package/dist/cjs/plugins/insert-block/ui/ToolbarInsertBlock/index.js +25 -23
  43. package/dist/cjs/plugins/media/index.js +9 -5
  44. package/dist/cjs/plugins/media/pm-plugins/main.js +5 -4
  45. package/dist/cjs/plugins/media/utils/media-single.js +1 -4
  46. package/dist/cjs/plugins/panel/pm-plugins/keymaps.js +2 -1
  47. package/dist/cjs/plugins/paste/handlers.js +5 -5
  48. package/dist/cjs/plugins/paste/index.js +4 -2
  49. package/dist/cjs/plugins/paste/pm-plugins/main.js +6 -4
  50. package/dist/cjs/plugins/rule/commands.js +2 -2
  51. package/dist/cjs/plugins/rule/index.js +5 -4
  52. package/dist/cjs/plugins/rule/pm-plugins/input-rule.js +6 -8
  53. package/dist/cjs/plugins/rule/pm-plugins/keymap.js +2 -2
  54. package/dist/cjs/plugins/text-color/index.js +5 -2
  55. package/dist/cjs/plugins/text-color/ui/ToolbarTextColor/index.js +3 -4
  56. package/dist/cjs/plugins/text-formatting/ui/Toolbar/toolbar-messages.js +10 -0
  57. package/dist/cjs/ui/Appearance/Comment/Comment.js +2 -0
  58. package/dist/cjs/ui/Appearance/FullPage/FullPage.js +2 -4
  59. package/dist/cjs/ui/Appearance/FullPage/FullPageToolbar.js +2 -0
  60. package/dist/cjs/ui/ColorPalette/index.js +6 -0
  61. package/dist/cjs/ui/ConfigPanel/ConfigPanel.js +15 -10
  62. package/dist/cjs/ui/ConfigPanel/ConfigPanelFieldsLoader.js +3 -1
  63. package/dist/cjs/ui/ConfigPanel/Fields/ColorPicker.js +248 -17
  64. package/dist/cjs/ui/ConfigPanel/FormContent.js +12 -6
  65. package/dist/cjs/ui/ConfigPanel/utils.js +2 -12
  66. package/dist/cjs/ui/ContentStyles/index.js +2 -5
  67. package/dist/cjs/ui/MediaAndEmbedsToolbar/index.js +16 -8
  68. package/dist/cjs/utils/document.js +5 -3
  69. package/dist/cjs/version-wrapper.js +1 -1
  70. package/dist/cjs/version.json +1 -1
  71. package/dist/es2019/actions/index.js +10 -4
  72. package/dist/es2019/analytics-api/attach-payload-into-transaction.js +2 -1
  73. package/dist/es2019/create-editor/ErrorBoundary.js +1 -13
  74. package/dist/es2019/create-editor/ReactEditorViewInternal.js +2 -2
  75. package/dist/es2019/editor-next/editor-internal.js +2 -1
  76. package/dist/es2019/editor-next/index.js +5 -1
  77. package/dist/es2019/editor.js +5 -2
  78. package/dist/es2019/keymaps/index.js +1 -1
  79. package/dist/es2019/labs/next/internal/hooks/use-editor/index.js +4 -6
  80. package/dist/es2019/labs/next/presets/default.js +1 -2
  81. package/dist/es2019/plugins/card/index.js +15 -5
  82. package/dist/es2019/plugins/card/pm-plugins/actions.js +4 -0
  83. package/dist/es2019/plugins/card/pm-plugins/analytics/create-analytics-queue.js +38 -0
  84. package/dist/es2019/plugins/card/pm-plugins/analytics/events-from-tr.js +316 -0
  85. package/dist/es2019/plugins/card/pm-plugins/analytics/index.js +2 -0
  86. package/dist/es2019/plugins/card/pm-plugins/analytics/types.js +1 -0
  87. package/dist/es2019/plugins/card/pm-plugins/analytics/utils.js +124 -0
  88. package/dist/es2019/plugins/card/pm-plugins/doc.js +94 -20
  89. package/dist/es2019/plugins/card/pm-plugins/main.js +17 -8
  90. package/dist/es2019/plugins/card/pm-plugins/reducers.js +8 -0
  91. package/dist/es2019/plugins/card/pm-plugins/util/resolve.js +3 -7
  92. package/dist/es2019/plugins/card/toolbar.js +16 -8
  93. package/dist/es2019/plugins/card/ui/EditLinkToolbar.js +13 -9
  94. package/dist/es2019/plugins/card/ui/EditorSmartCardEventsNext.js +180 -0
  95. package/dist/es2019/plugins/card/ui/LinkToolbarAppearance.js +11 -2
  96. package/dist/es2019/plugins/card/utils.js +6 -2
  97. package/dist/es2019/plugins/extension/context-panel.js +3 -2
  98. package/dist/es2019/plugins/extension/index.js +45 -41
  99. package/dist/es2019/plugins/help-dialog/ui/index.js +17 -1
  100. package/dist/es2019/plugins/hyperlink/Toolbar.js +13 -4
  101. package/dist/es2019/plugins/hyperlink/commands.js +9 -6
  102. package/dist/es2019/plugins/hyperlink/pm-plugins/input-rule.js +4 -0
  103. package/dist/es2019/plugins/hyperlink/ui/HyperlinkAddToolbar/index.js +2 -2
  104. package/dist/es2019/plugins/index.js +0 -1
  105. package/dist/es2019/plugins/insert-block/index.js +96 -91
  106. package/dist/es2019/plugins/insert-block/ui/ToolbarInsertBlock/index.js +3 -2
  107. package/dist/es2019/plugins/media/index.js +202 -198
  108. package/dist/es2019/plugins/media/pm-plugins/main.js +5 -4
  109. package/dist/es2019/plugins/media/utils/media-single.js +1 -5
  110. package/dist/es2019/plugins/panel/pm-plugins/keymaps.js +3 -2
  111. package/dist/es2019/plugins/paste/handlers.js +6 -6
  112. package/dist/es2019/plugins/paste/index.js +18 -14
  113. package/dist/es2019/plugins/paste/pm-plugins/main.js +7 -5
  114. package/dist/es2019/plugins/rule/commands.js +2 -2
  115. package/dist/es2019/plugins/rule/index.js +49 -46
  116. package/dist/es2019/plugins/rule/pm-plugins/input-rule.js +6 -7
  117. package/dist/es2019/plugins/rule/pm-plugins/keymap.js +2 -2
  118. package/dist/es2019/plugins/text-color/index.js +49 -44
  119. package/dist/es2019/plugins/text-color/ui/ToolbarTextColor/index.js +3 -3
  120. package/dist/es2019/plugins/text-formatting/ui/Toolbar/toolbar-messages.js +10 -0
  121. package/dist/es2019/ui/Appearance/Comment/Comment.js +2 -0
  122. package/dist/es2019/ui/Appearance/FullPage/FullPage.js +2 -4
  123. package/dist/es2019/ui/Appearance/FullPage/FullPageToolbar.js +2 -0
  124. package/dist/es2019/ui/ColorPalette/index.js +2 -2
  125. package/dist/es2019/ui/ConfigPanel/ConfigPanel.js +8 -4
  126. package/dist/es2019/ui/ConfigPanel/ConfigPanelFieldsLoader.js +3 -1
  127. package/dist/es2019/ui/ConfigPanel/Fields/ColorPicker.js +238 -13
  128. package/dist/es2019/ui/ConfigPanel/FormContent.js +12 -6
  129. package/dist/es2019/ui/ConfigPanel/utils.js +1 -11
  130. package/dist/es2019/ui/ContentStyles/index.js +2 -5
  131. package/dist/es2019/ui/MediaAndEmbedsToolbar/index.js +12 -10
  132. package/dist/es2019/utils/document.js +5 -3
  133. package/dist/es2019/version-wrapper.js +1 -1
  134. package/dist/es2019/version.json +1 -1
  135. package/dist/esm/actions/index.js +17 -6
  136. package/dist/esm/analytics-api/attach-payload-into-transaction.js +2 -1
  137. package/dist/esm/create-editor/ErrorBoundary.js +1 -16
  138. package/dist/esm/create-editor/ReactEditorViewInternal.js +2 -2
  139. package/dist/esm/editor-next/editor-internal.js +2 -1
  140. package/dist/esm/editor-next/index.js +5 -1
  141. package/dist/esm/editor.js +9 -5
  142. package/dist/esm/keymaps/index.js +1 -1
  143. package/dist/esm/labs/next/internal/hooks/use-editor/index.js +4 -6
  144. package/dist/esm/labs/next/presets/default.js +1 -2
  145. package/dist/esm/plugins/card/index.js +13 -5
  146. package/dist/esm/plugins/card/pm-plugins/actions.js +8 -0
  147. package/dist/esm/plugins/card/pm-plugins/analytics/create-analytics-queue.js +41 -0
  148. package/dist/esm/plugins/card/pm-plugins/analytics/events-from-tr.js +328 -0
  149. package/dist/esm/plugins/card/pm-plugins/analytics/index.js +2 -0
  150. package/dist/esm/plugins/card/pm-plugins/analytics/types.js +1 -0
  151. package/dist/esm/plugins/card/pm-plugins/analytics/utils.js +124 -0
  152. package/dist/esm/plugins/card/pm-plugins/doc.js +98 -22
  153. package/dist/esm/plugins/card/pm-plugins/main.js +16 -10
  154. package/dist/esm/plugins/card/pm-plugins/reducers.js +7 -0
  155. package/dist/esm/plugins/card/pm-plugins/util/resolve.js +3 -7
  156. package/dist/esm/plugins/card/toolbar.js +18 -8
  157. package/dist/esm/plugins/card/ui/EditLinkToolbar.js +13 -9
  158. package/dist/esm/plugins/card/ui/EditorSmartCardEventsNext.js +191 -0
  159. package/dist/esm/plugins/card/ui/LinkToolbarAppearance.js +12 -4
  160. package/dist/esm/plugins/card/utils.js +4 -2
  161. package/dist/esm/plugins/extension/context-panel.js +3 -2
  162. package/dist/esm/plugins/extension/index.js +4 -1
  163. package/dist/esm/plugins/help-dialog/ui/index.js +29 -8
  164. package/dist/esm/plugins/hyperlink/Toolbar.js +13 -3
  165. package/dist/esm/plugins/hyperlink/commands.js +9 -5
  166. package/dist/esm/plugins/hyperlink/pm-plugins/input-rule.js +4 -0
  167. package/dist/esm/plugins/hyperlink/ui/HyperlinkAddToolbar/index.js +2 -2
  168. package/dist/esm/plugins/index.js +0 -1
  169. package/dist/esm/plugins/insert-block/index.js +5 -1
  170. package/dist/esm/plugins/insert-block/ui/ToolbarInsertBlock/index.js +25 -23
  171. package/dist/esm/plugins/media/index.js +9 -5
  172. package/dist/esm/plugins/media/pm-plugins/main.js +5 -4
  173. package/dist/esm/plugins/media/utils/media-single.js +1 -4
  174. package/dist/esm/plugins/panel/pm-plugins/keymaps.js +3 -2
  175. package/dist/esm/plugins/paste/handlers.js +6 -6
  176. package/dist/esm/plugins/paste/index.js +4 -2
  177. package/dist/esm/plugins/paste/pm-plugins/main.js +7 -5
  178. package/dist/esm/plugins/rule/commands.js +2 -2
  179. package/dist/esm/plugins/rule/index.js +5 -4
  180. package/dist/esm/plugins/rule/pm-plugins/input-rule.js +6 -8
  181. package/dist/esm/plugins/rule/pm-plugins/keymap.js +2 -2
  182. package/dist/esm/plugins/text-color/index.js +5 -2
  183. package/dist/esm/plugins/text-color/ui/ToolbarTextColor/index.js +3 -4
  184. package/dist/esm/plugins/text-formatting/ui/Toolbar/toolbar-messages.js +10 -0
  185. package/dist/esm/ui/Appearance/Comment/Comment.js +2 -0
  186. package/dist/esm/ui/Appearance/FullPage/FullPage.js +2 -4
  187. package/dist/esm/ui/Appearance/FullPage/FullPageToolbar.js +2 -0
  188. package/dist/esm/ui/ColorPalette/index.js +2 -2
  189. package/dist/esm/ui/ConfigPanel/ConfigPanel.js +15 -10
  190. package/dist/esm/ui/ConfigPanel/ConfigPanelFieldsLoader.js +3 -1
  191. package/dist/esm/ui/ConfigPanel/Fields/ColorPicker.js +244 -19
  192. package/dist/esm/ui/ConfigPanel/FormContent.js +12 -6
  193. package/dist/esm/ui/ConfigPanel/utils.js +0 -10
  194. package/dist/esm/ui/ContentStyles/index.js +2 -5
  195. package/dist/esm/ui/MediaAndEmbedsToolbar/index.js +16 -8
  196. package/dist/esm/utils/document.js +5 -3
  197. package/dist/esm/version-wrapper.js +1 -1
  198. package/dist/esm/version.json +1 -1
  199. package/dist/types/actions/index.d.ts +3 -2
  200. package/dist/types/create-editor/ErrorBoundary.d.ts +2 -2
  201. package/dist/types/editor-next/index.d.ts +1 -0
  202. package/dist/types/editor.d.ts +1 -0
  203. package/dist/types/keymaps/index.d.ts +1 -1
  204. package/dist/types/labs/next/internal/hooks/use-editor/index.d.ts +2 -1
  205. package/dist/types/labs/next/presets/cxhtml.d.ts +1 -5
  206. package/dist/types/labs/next/presets/default.d.ts +2 -10
  207. package/dist/types/labs/next/presets/mobile.d.ts +1 -5
  208. package/dist/types/plugins/card/pm-plugins/actions.d.ts +2 -1
  209. package/dist/types/plugins/card/pm-plugins/analytics/create-analytics-queue.d.ts +10 -0
  210. package/dist/types/plugins/card/pm-plugins/analytics/events-from-tr.d.ts +17 -0
  211. package/dist/types/plugins/card/pm-plugins/analytics/index.d.ts +2 -0
  212. package/dist/types/plugins/card/pm-plugins/analytics/types.d.ts +10 -0
  213. package/dist/types/plugins/card/pm-plugins/analytics/utils.d.ts +26 -0
  214. package/dist/types/plugins/card/pm-plugins/doc.d.ts +8 -7
  215. package/dist/types/plugins/card/pm-plugins/main.d.ts +1 -1
  216. package/dist/types/plugins/card/pm-plugins/util/resolve.d.ts +2 -2
  217. package/dist/types/plugins/card/pm-plugins/util/state.d.ts +3 -0
  218. package/dist/types/plugins/card/types.d.ts +81 -7
  219. package/dist/types/plugins/card/ui/EditLinkToolbar.d.ts +2 -1
  220. package/dist/types/plugins/card/ui/EditorSmartCardEventsNext.d.ts +18 -0
  221. package/dist/types/plugins/card/utils.d.ts +1 -1
  222. package/dist/types/plugins/extension/context-panel.d.ts +2 -1
  223. package/dist/types/plugins/extension/index.d.ts +2 -0
  224. package/dist/types/plugins/hyperlink/commands.d.ts +3 -2
  225. package/dist/types/plugins/hyperlink/ui/HyperlinkAddToolbar/index.d.ts +2 -1
  226. package/dist/types/plugins/index.d.ts +0 -1
  227. package/dist/types/plugins/insert-block/index.d.ts +2 -0
  228. package/dist/types/plugins/insert-block/ui/ToolbarInsertBlock/types.d.ts +2 -1
  229. package/dist/types/plugins/media/index.d.ts +2 -0
  230. package/dist/types/plugins/media/pm-plugins/main.d.ts +3 -2
  231. package/dist/types/plugins/media/utils/media-single.d.ts +1 -1
  232. package/dist/types/plugins/paste/index.d.ts +2 -0
  233. package/dist/types/plugins/paste/pm-plugins/main.d.ts +2 -1
  234. package/dist/types/plugins/rule/commands.d.ts +2 -1
  235. package/dist/types/plugins/rule/index.d.ts +5 -1
  236. package/dist/types/plugins/rule/pm-plugins/input-rule.d.ts +1 -1
  237. package/dist/types/plugins/rule/pm-plugins/keymap.d.ts +2 -1
  238. package/dist/types/plugins/text-color/index.d.ts +2 -0
  239. package/dist/types/plugins/text-color/ui/ToolbarTextColor/index.d.ts +2 -0
  240. package/dist/types/plugins/text-formatting/ui/Toolbar/toolbar-messages.d.ts +10 -0
  241. package/dist/types/types/editor-appearance-component.d.ts +1 -1
  242. package/dist/types/types/editor-props.d.ts +1 -0
  243. package/dist/types/ui/Appearance/FullPage/FullPage.d.ts +2 -0
  244. package/dist/types/ui/ColorPalette/index.d.ts +2 -2
  245. package/dist/types/ui/ConfigPanel/ConfigPanel.d.ts +3 -1
  246. package/dist/types/ui/ConfigPanel/ConfigPanelFieldsLoader.d.ts +3 -1
  247. package/dist/types/ui/ConfigPanel/Fields/ColorPicker.d.ts +12 -1
  248. package/dist/types/ui/ConfigPanel/FormContent.d.ts +2 -2
  249. package/dist/types/ui/ConfigPanel/types.d.ts +3 -0
  250. package/dist/types/ui/ConfigPanel/utils.d.ts +0 -1
  251. package/dist/types/ui/MediaAndEmbedsToolbar/index.d.ts +1 -1
  252. package/package.json +15 -14
  253. package/report.api.md +10 -0
  254. package/dist/cjs/plugins/feature-flags-context/get-enabled-feature-flag-keys.js +0 -12
  255. package/dist/cjs/plugins/feature-flags-context/get-feature-flags.js +0 -11
  256. package/dist/cjs/plugins/feature-flags-context/index.js +0 -50
  257. package/dist/cjs/plugins/feature-flags-context/plugin-key.js +0 -9
  258. package/dist/es2019/plugins/feature-flags-context/get-enabled-feature-flag-keys.js +0 -1
  259. package/dist/es2019/plugins/feature-flags-context/get-feature-flags.js +0 -2
  260. package/dist/es2019/plugins/feature-flags-context/index.js +0 -29
  261. package/dist/es2019/plugins/feature-flags-context/plugin-key.js +0 -2
  262. package/dist/esm/plugins/feature-flags-context/get-enabled-feature-flag-keys.js +0 -1
  263. package/dist/esm/plugins/feature-flags-context/get-feature-flags.js +0 -4
  264. package/dist/esm/plugins/feature-flags-context/index.js +0 -40
  265. package/dist/esm/plugins/feature-flags-context/plugin-key.js +0 -2
  266. package/dist/types/plugins/feature-flags-context/get-enabled-feature-flag-keys.d.ts +0 -1
  267. package/dist/types/plugins/feature-flags-context/get-feature-flags.d.ts +0 -3
  268. package/dist/types/plugins/feature-flags-context/index.d.ts +0 -9
  269. package/dist/types/plugins/feature-flags-context/plugin-key.d.ts +0 -2
@@ -23,6 +23,7 @@ import { defaultProps, propTypes } from './editor-next/utils/editorPropTypes';
23
23
  import _trackEditorActions from './editor-next/utils/trackEditorActions';
24
24
  import _onEditorCreated from './editor-next/utils/onEditorCreated';
25
25
  import deprecationWarnings from './editor-next/utils/deprecationWarnings';
26
+ import { createFeatureFlagsFromProps } from './create-editor/feature-flags-from-props';
26
27
  import { fireAnalyticsEvent } from '@atlaskit/editor-common/analytics';
27
28
  import prepareQuickInsertProvider from './utils/prepare-quick-insert-provider';
28
29
  import prepareExtensionProvider from './utils/prepare-extension-provider';
@@ -62,6 +63,9 @@ var Editor = /*#__PURE__*/function (_React$Component) {
62
63
  _defineProperty(_assertThisInitialized(_this), "handleAnalyticsEvent", function (data) {
63
64
  return fireAnalyticsEvent(_this.createAnalyticsEvent)(data);
64
65
  });
66
+ _defineProperty(_assertThisInitialized(_this), "getFeatureFlags", function () {
67
+ return createFeatureFlagsFromProps(_this.props);
68
+ });
65
69
  _defineProperty(_assertThisInitialized(_this), "getExperienceStore", function () {
66
70
  return _this.experienceStore;
67
71
  });
@@ -258,18 +262,18 @@ var Editor = /*#__PURE__*/function (_React$Component) {
258
262
  * and need to find a workaround.
259
263
  */
260
264
  function registerEditorForActions(editorView, eventDispatcher, contentTransformer) {
261
- this.editorActions._privateRegisterEditor(editorView, eventDispatcher, contentTransformer);
265
+ this.editorActions._privateRegisterEditor(editorView, eventDispatcher, contentTransformer, this.getFeatureFlags);
262
266
  }
263
-
267
+ }, {
268
+ key: "unregisterEditorFromActions",
269
+ value:
264
270
  /**
265
271
  * @private
266
272
  * @deprecated - Do not override this at all, this is an antipattern.
267
273
  * Please reach out to the Editor team if you were previously using this
268
274
  * and need to find a workaround.
269
275
  */
270
- }, {
271
- key: "unregisterEditorFromActions",
272
- value: function unregisterEditorFromActions() {
276
+ function unregisterEditorFromActions() {
273
277
  this.editorActions._privateUnregisterEditor();
274
278
  }
275
279
  }, {
@@ -1 +1 @@
1
- export { addAltText, toggleBold, toggleItalic, toggleUnderline, toggleStrikethrough, toggleSubscript, toggleSuperscript, toggleCode, pastePlainText, clearFormatting, setNormalText, toggleHeading1, toggleHeading2, toggleHeading3, toggleHeading4, toggleHeading5, toggleHeading6, toggleOrderedList, ctrlBackSpace, toggleBulletList, toggleBlockQuote, insertNewLine, shiftBackspace, splitCodeBlock, splitListItem, insertRule, undo, moveUp, moveDown, moveLeft, moveRight, indentList, outdentList, redo, openHelp, addLink, addInlineComment, submit, enter, shiftEnter, tab, indent, outdent, backspace, deleteKey, forwardDelete, space, escape, nextCell, previousCell, shiftTab, toggleTable, addRowBefore, addRowAfter, addColumnAfter, addColumnBefore, cut, copy, paste, altPaste, find, alignLeft, tooltip, ToolTipContent, findKeymapByDescription, findShortcutByDescription, findShortcutByKeymap, makeKeymap, makeKeyMapWithCommon, bindKeymapWithCommand, findKeyMapForBrowser, DOWN, HEADING_KEYS, KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, LEFT, RIGHT, UP } from '@atlaskit/editor-common/keymaps';
1
+ export { addAltText, navToEditorToolbar, navToFloatingToolbar, toggleBold, toggleItalic, toggleUnderline, toggleStrikethrough, toggleSubscript, toggleSuperscript, toggleCode, pastePlainText, clearFormatting, setNormalText, toggleHeading1, toggleHeading2, toggleHeading3, toggleHeading4, toggleHeading5, toggleHeading6, toggleOrderedList, ctrlBackSpace, toggleBulletList, toggleBlockQuote, insertNewLine, shiftBackspace, splitCodeBlock, splitListItem, insertRule, undo, moveUp, moveDown, moveLeft, moveRight, indentList, outdentList, redo, openHelp, addLink, addInlineComment, submit, enter, shiftEnter, tab, indent, outdent, backspace, deleteKey, forwardDelete, space, escape, nextCell, previousCell, shiftTab, toggleTable, addRowBefore, addRowAfter, addColumnAfter, addColumnBefore, cut, copy, paste, altPaste, find, alignLeft, tooltip, ToolTipContent, findKeymapByDescription, findShortcutByDescription, findShortcutByKeymap, makeKeymap, makeKeyMapWithCommon, bindKeymapWithCommand, findKeyMapForBrowser, DOWN, HEADING_KEYS, KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, LEFT, RIGHT, UP } from '@atlaskit/editor-common/keymaps';
@@ -7,8 +7,7 @@ import { measureRender, getResponseEndTime, startMeasure, stopMeasure } from '@a
7
7
  import measurements from '../../../../../utils/performance/measure-enum';
8
8
  import { getNodesCount } from '../../../../../utils';
9
9
  import { ACTION, ACTION_SUBJECT, EVENT_TYPE, PLATFORMS } from '../../../../../plugins/analytics';
10
- import { getEnabledFeatureFlagKeys } from '../../../../../plugins/feature-flags-context/get-enabled-feature-flag-keys';
11
- import { getFeatureFlags } from '../../../../../plugins/feature-flags-context/';
10
+ import { getEnabledFeatureFlagKeys } from '@atlaskit/editor-common/normalize-feature-flags';
12
11
  import { useAnalyticsHandler } from '../use-analytics';
13
12
  import { createDispatchTransaction } from './create-dispatch-transaction';
14
13
  import { createEditor } from './create-editor';
@@ -20,7 +19,7 @@ export function useEditor(config) {
20
19
  editorSharedConfig = _useCreateEditor2[0],
21
20
  mountEditor = _useCreateEditor2[1];
22
21
  useApplyEditorViewProps(editorSharedConfig, config.disabled);
23
- useHandleEditorLifecycle(editorSharedConfig);
22
+ useHandleEditorLifecycle(editorSharedConfig, config.featureFlags);
24
23
  useAnalyticsHandler(editorSharedConfig);
25
24
  return [editorSharedConfig, mountEditor];
26
25
  }
@@ -119,7 +118,7 @@ function useApplyEditorViewProps(editorSharedConfig, disabled) {
119
118
  /**
120
119
  * Handles editor component unmount
121
120
  */
122
- export function useHandleEditorLifecycle(editorSharedConfig) {
121
+ export function useHandleEditorLifecycle(editorSharedConfig, featureFlags) {
123
122
  React.useEffect(function () {
124
123
  //#region Did mount
125
124
  if (editorSharedConfig) {
@@ -132,7 +131,6 @@ export function useHandleEditorLifecycle(editorSharedConfig) {
132
131
  if (onMount) {
133
132
  onMount(editorActions);
134
133
  }
135
- var featureFlags = getFeatureFlags(editorSharedConfig.editorView.state);
136
134
  var featureFlagsEnabled = featureFlags ? getEnabledFeatureFlagKeys(featureFlags) : [];
137
135
 
138
136
  // Fire editor started event
@@ -183,5 +181,5 @@ export function useHandleEditorLifecycle(editorSharedConfig) {
183
181
  editorView.destroy();
184
182
  }
185
183
  };
186
- }, [editorSharedConfig]);
184
+ }, [editorSharedConfig, featureFlags]);
187
185
  }
@@ -12,7 +12,6 @@ import editorDisabledPlugin from '../../../plugins/editor-disabled';
12
12
  import typeAheadPlugin from '../../../plugins/type-ahead';
13
13
  import submitEditorPlugin from '../../../plugins/submit-editor';
14
14
  import fakeTextCursorPlugin from '../../../plugins/fake-text-cursor';
15
- import featureFlagsContextPlugin from '../../../plugins/feature-flags-context';
16
15
  import featureFlagsPlugin from '@atlaskit/editor-plugin-feature-flags';
17
16
  import floatingToolbarPlugin from '../../../plugins/floating-toolbar';
18
17
  import clipboardPlugin from '../../../plugins/clipboard';
@@ -44,7 +43,7 @@ export function createDefaultPreset(options) {
44
43
  return builder;
45
44
  }).add([hyperlinkPlugin, options.hyperlinkOptions]).add([textFormattingPlugin, options.textFormatting]).add(widthPlugin).add([quickInsertPlugin, options.quickInsert]).add([typeAheadPlugin, options.typeAhead || {
46
45
  createAnalyticsEvent: options.createAnalyticsEvent
47
- }]).add(unsupportedContentPlugin).add(editorDisabledPlugin).add([submitEditorPlugin, options.submitEditor]).add(fakeTextCursorPlugin).add(floatingToolbarPlugin).add([featureFlagsContextPlugin, options.featureFlags || {}]).add([selectionPlugin, options.selection]).add([codeBlockPlugin, options.codeBlock || {
46
+ }]).add(unsupportedContentPlugin).add(editorDisabledPlugin).add([submitEditorPlugin, options.submitEditor]).add(fakeTextCursorPlugin).add(floatingToolbarPlugin).add([selectionPlugin, options.selection]).add([codeBlockPlugin, options.codeBlock || {
48
47
  appearance: 'full-page'
49
48
  }]);
50
49
  return preset;
@@ -1,12 +1,13 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
3
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
- import React from 'react';
4
+ import React, { Fragment } from 'react';
5
5
  import { inlineCard, blockCard, embedCard } from '@atlaskit/adf-schema';
6
6
  import { createPlugin } from './pm-plugins/main';
7
7
  import { floatingToolbar } from './toolbar';
8
8
  import { EditorSmartCardEvents } from './ui/EditorSmartCardEvents';
9
9
  import { cardKeymap } from './pm-plugins/keymap';
10
+ import { EditorSmartCardEventsNext } from './ui/EditorSmartCardEventsNext';
10
11
  var cardPlugin = function cardPlugin(options, api) {
11
12
  var _api$dependencies, _api$dependencies$fea;
12
13
  var featureFlags = (api === null || api === void 0 ? void 0 : (_api$dependencies = api.dependencies) === null || _api$dependencies === void 0 ? void 0 : (_api$dependencies$fea = _api$dependencies.featureFlags) === null || _api$dependencies$fea === void 0 ? void 0 : _api$dependencies$fea.sharedState.currentState()) || {};
@@ -29,16 +30,20 @@ var cardPlugin = function cardPlugin(options, api) {
29
30
  return nodes;
30
31
  },
31
32
  pmPlugins: function pmPlugins() {
32
- var _options$allowBlockCa, _options$allowResizin, _options$useAlternati;
33
+ var _options$allowBlockCa, _options$allowResizin, _options$useAlternati, _options$allowWrappin, _options$allowAlignme;
33
34
  var allowBlockCards = (_options$allowBlockCa = options.allowBlockCards) !== null && _options$allowBlockCa !== void 0 ? _options$allowBlockCa : true;
34
35
  var allowResizing = (_options$allowResizin = options.allowResizing) !== null && _options$allowResizin !== void 0 ? _options$allowResizin : true;
35
36
  var useAlternativePreloader = (_options$useAlternati = options.useAlternativePreloader) !== null && _options$useAlternati !== void 0 ? _options$useAlternati : true;
37
+ var allowWrapping = (_options$allowWrappin = options.allowWrapping) !== null && _options$allowWrappin !== void 0 ? _options$allowWrappin : true;
38
+ var allowAlignment = (_options$allowAlignme = options.allowAlignment) !== null && _options$allowAlignme !== void 0 ? _options$allowAlignme : true;
36
39
  var plugins = [{
37
40
  name: 'card',
38
41
  plugin: createPlugin(_objectSpread(_objectSpread({}, options), {}, {
39
42
  allowBlockCards: allowBlockCards,
40
43
  allowResizing: allowResizing,
41
- useAlternativePreloader: useAlternativePreloader
44
+ useAlternativePreloader: useAlternativePreloader,
45
+ allowWrapping: allowWrapping,
46
+ allowAlignment: allowAlignment
42
47
  }))
43
48
  }];
44
49
  plugins.push({
@@ -52,9 +57,12 @@ var cardPlugin = function cardPlugin(options, api) {
52
57
  },
53
58
  contentComponent: function contentComponent(_ref2) {
54
59
  var editorView = _ref2.editorView;
55
- return /*#__PURE__*/React.createElement(EditorSmartCardEvents, {
60
+ var lpAnalyticsEventsNext = featureFlags.lpAnalyticsEventsNext;
61
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(EditorSmartCardEvents, {
56
62
  editorView: editorView
57
- });
63
+ }), lpAnalyticsEventsNext && /*#__PURE__*/React.createElement(EditorSmartCardEventsNext, {
64
+ editorView: editorView
65
+ }));
58
66
  },
59
67
  pluginsOptions: {
60
68
  floatingToolbar: floatingToolbar(options, featureFlags, options.platform, options.linkPicker)
@@ -34,6 +34,14 @@ export var registerSmartCardEvents = function registerSmartCardEvents(smartLinkE
34
34
  });
35
35
  };
36
36
  };
37
+ export var registerSmartCardEventsNext = function registerSmartCardEventsNext(smartLinkEvents) {
38
+ return function (tr) {
39
+ return cardAction(tr, {
40
+ type: 'REGISTER_EVENTS_NEXT',
41
+ smartLinkEvents: smartLinkEvents
42
+ });
43
+ };
44
+ };
37
45
  export var setProvider = function setProvider(cardProvider) {
38
46
  return function (tr) {
39
47
  return cardAction(tr, {
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Simple mechanism to defer analytics related callbacks
3
+ */
4
+ export var createAnalyticsQueue = function createAnalyticsQueue() {
5
+ var enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
6
+ var queue = [];
7
+ var callbacksRef = {
8
+ current: null
9
+ };
10
+ var setCallbacks = function setCallbacks(callbacks) {
11
+ callbacksRef.current = callbacks;
12
+ };
13
+ var push = function push() {
14
+ var callbacks = callbacksRef.current;
15
+ if (!enabled || !callbacks) {
16
+ return;
17
+ }
18
+ queue.push.apply(queue, arguments);
19
+ };
20
+ var flush = function flush() {
21
+ var callbacks = callbacksRef.current;
22
+ if (!enabled || !callbacks) {
23
+ return;
24
+ }
25
+ while (queue.length) {
26
+ var event = queue.pop();
27
+ if (event) {
28
+ callbacks[event.type](event.data);
29
+ }
30
+ }
31
+ };
32
+ var getSize = function getSize() {
33
+ return queue.length;
34
+ };
35
+ return {
36
+ push: push,
37
+ flush: flush,
38
+ setCallbacks: setCallbacks,
39
+ getSize: getSize
40
+ };
41
+ };
@@ -0,0 +1,328 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _typeof from "@babel/runtime/helpers/typeof";
3
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
4
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
+ import { AddMarkStep, RemoveMarkStep } from 'prosemirror-transform';
7
+ import { ACTION } from '@atlaskit/editor-common/analytics';
8
+ import { isLinkMark } from '@atlaskit/editor-common/utils';
9
+ import { getLinkMetadataFromTransaction } from '@atlaskit/editor-common/card';
10
+ import { LinkMetaStep } from '@atlaskit/adf-schema/steps';
11
+ import { pmHistoryPluginKey } from '../../../history/pm-history-types';
12
+ import { getPluginState } from '../util/state';
13
+ import { pluginKey } from '../plugin-key';
14
+ import { isLink, linkObjectFromNode, getLinkUrl, appearanceForLink, findLinksAtPositions } from './utils';
15
+ var findLinksInNodeRange = function findLinksInNodeRange(node, schema, from, to) {
16
+ var links = [];
17
+ node.nodesBetween(from, to, function (node, pos) {
18
+ if (isLink(schema, node)) {
19
+ var entireLinkInRange = pos >= from && pos + node.nodeSize <= to;
20
+ if (entireLinkInRange) {
21
+ var link = linkObjectFromNode(schema, node, pos);
22
+ if (link) {
23
+ links.push(link);
24
+ }
25
+ }
26
+ }
27
+ });
28
+ return links;
29
+ };
30
+ export var findChangedLinks = function findChangedLinks(tr, state) {
31
+ var schema = tr.doc.type.schema;
32
+ var removed = [];
33
+ var inserted = [];
34
+ var updated = [];
35
+ var queuedForUpgrade = isTransactionQueuedForUpgrade(tr);
36
+ var isResolveReplace = isTransactionResolveReplace(tr);
37
+
38
+ // History
39
+ var historyMeta = tr.getMeta(pmHistoryPluginKey);
40
+ var isUndo = isHistoryMeta(historyMeta) && historyMeta.redo === false;
41
+ var isRedo = isHistoryMeta(historyMeta) && historyMeta.redo === true;
42
+ var isUpdate = isUpdateTr(tr, isUndo || isRedo);
43
+ var _loop = function _loop(i) {
44
+ var step = tr.steps[i];
45
+ var stepMap = step.getMap();
46
+ var removedInStep = [];
47
+ var insertedInStep = [];
48
+
49
+ /**
50
+ * AddMarkStep and RemoveMarkSteps don't produce stepMap ranges
51
+ * because there are no "changed tokens" only marks added/removed
52
+ * So have to check these manually
53
+ */
54
+ if (step instanceof AddMarkStep) {
55
+ var addMarkStep = step;
56
+ if (isLinkMark(addMarkStep.mark, schema)) {
57
+ /**
58
+ * For url text pasted on plain text
59
+ */
60
+ insertedInStep.push({
61
+ type: 'mark',
62
+ pos: addMarkStep.from,
63
+ mark: addMarkStep.mark
64
+ });
65
+ }
66
+ }
67
+ if (step instanceof RemoveMarkStep) {
68
+ var removeMarkStep = step;
69
+ if (isLinkMark(removeMarkStep.mark, schema)) {
70
+ /**
71
+ * For url text pasted on plain text
72
+ */
73
+ removedInStep.push({
74
+ type: 'mark',
75
+ pos: removeMarkStep.from,
76
+ mark: removeMarkStep.mark
77
+ });
78
+ }
79
+ }
80
+ stepMap.forEach(function (oldStart, oldEnd, newStart, newEnd) {
81
+ var _tr$docs;
82
+ var before = tr.docs[i];
83
+ var after = (_tr$docs = tr.docs[i + 1]) !== null && _tr$docs !== void 0 ? _tr$docs : tr.doc;
84
+ var removedInRange = [];
85
+ var insertedInRange = [];
86
+
87
+ // Removed
88
+ removedInRange.push.apply(removedInRange, _toConsumableArray(findLinksInNodeRange(before, schema, oldStart, oldEnd)));
89
+ // Inserted
90
+ insertedInRange.push.apply(insertedInRange, _toConsumableArray(findLinksInNodeRange(after, schema, newStart, newEnd)));
91
+ removedInStep.push.apply(removedInStep, removedInRange);
92
+ insertedInStep.push.apply(insertedInStep, insertedInRange);
93
+ });
94
+ var omitQueuedLinks = function omitQueuedLinks(links) {
95
+ if (!queuedForUpgrade) {
96
+ return links;
97
+ }
98
+ /**
99
+ * Skip/filter out links that have been queued, they will be tracked later
100
+ */
101
+ var queuedPositions = getQueuedPositions(tr);
102
+ return links.filter(function (link) {
103
+ return !queuedPositions.includes(link.pos);
104
+ });
105
+ };
106
+
107
+ /**
108
+ * Skip "deletions" when the transaction is relating to
109
+ * replacing links queued for upgrade to cards,
110
+ * because the "deleted" link has not actually been
111
+ * tracked as "created" yet
112
+ */
113
+ if (!isResolveReplace) {
114
+ removed.push.apply(removed, removedInStep);
115
+ }
116
+ inserted.push.apply(inserted, _toConsumableArray(omitQueuedLinks(insertedInStep)));
117
+ };
118
+ for (var i = 0; i < tr.steps.length; i++) {
119
+ _loop(i);
120
+ }
121
+
122
+ /**
123
+ * If there are no links changed but the transaction is a "resolve" action
124
+ * Then this means we have resolved a link but it has failed to upgrade
125
+ * We should track all resolved links as now being created
126
+ */
127
+ if (inserted.length === 0 && isResolveReplace) {
128
+ var positions = getResolvePositions(tr, state);
129
+ inserted.push.apply(inserted, _toConsumableArray(findLinksAtPositions(tr, positions)));
130
+ }
131
+ if (!isUpdate) {
132
+ return {
133
+ removed: removed,
134
+ inserted: inserted,
135
+ updated: updated
136
+ };
137
+ }
138
+ for (var _i = 0; _i < inserted.length; _i++) {
139
+ if (isResolveReplace) {
140
+ var newLink = inserted[_i];
141
+
142
+ // what is the 2nd argument 'assoc = -1' doing here exactly?
143
+ var mappedPos = tr.mapping.map(newLink.pos, -1);
144
+ var previousDisplay = getResolveLinkPrevDisplay(state, mappedPos);
145
+ updated.push({
146
+ inserted: inserted[_i],
147
+ previous: {
148
+ display: previousDisplay
149
+ }
150
+ });
151
+ continue;
152
+ }
153
+ if (inserted.length === removed.length) {
154
+ updated.push({
155
+ removed: removed[_i],
156
+ inserted: inserted[_i]
157
+ });
158
+ }
159
+ }
160
+ return {
161
+ inserted: [],
162
+ removed: [],
163
+ updated: updated
164
+ };
165
+ };
166
+
167
+ /**
168
+ * List of actions to be considered link "updates"
169
+ */
170
+ var UPDATE_ACTIONS = [ACTION.CHANGED_TYPE, ACTION.UPDATED];
171
+
172
+ /**
173
+ * Returns true if the transaction has LinkMetaSteps that indicate the transaction is
174
+ * intended to be perceived as an update to links, rather than insertion+deletion
175
+ */
176
+ var isUpdateTr = function isUpdateTr(tr, isUndoOrRedo) {
177
+ return !!tr.steps.find(function (step) {
178
+ if (!(step instanceof LinkMetaStep)) {
179
+ return false;
180
+ }
181
+ var _step$getMetadata = step.getMetadata(),
182
+ action = _step$getMetadata.action,
183
+ cardAction = _step$getMetadata.cardAction;
184
+
185
+ /**
186
+ * Undo of a resolve step should be considered an update
187
+ * because the user is choosing to update the url back to the un-upgraded display
188
+ */
189
+ if (cardAction === 'RESOLVE' && isUndoOrRedo) {
190
+ return true;
191
+ }
192
+ if (!action) {
193
+ return false;
194
+ }
195
+ return UPDATE_ACTIONS.includes(action);
196
+ });
197
+ };
198
+ var hasType = function hasType(pluginMeta) {
199
+ return _typeof(pluginMeta) === 'object' && pluginMeta !== null && 'type' in pluginMeta;
200
+ };
201
+ var isTransactionQueuedForUpgrade = function isTransactionQueuedForUpgrade(tr) {
202
+ var pluginMeta = tr.getMeta(pluginKey);
203
+ return hasType(pluginMeta) && pluginMeta.type === 'QUEUE';
204
+ };
205
+ var isTransactionResolveReplace = function isTransactionResolveReplace(tr) {
206
+ var pluginMeta = tr.getMeta(pluginKey);
207
+ return hasType(pluginMeta) && pluginMeta.type === 'RESOLVE';
208
+ };
209
+ var isHistoryMeta = function isHistoryMeta(meta) {
210
+ return _typeof(meta) === 'object' && meta !== null && 'redo' in meta;
211
+ };
212
+ var getQueuedPositions = function getQueuedPositions(tr) {
213
+ var pluginMeta = tr.getMeta(pluginKey);
214
+ if (!isTransactionQueuedForUpgrade(tr)) {
215
+ return [];
216
+ }
217
+ return pluginMeta.requests.map(function (_ref) {
218
+ var pos = _ref.pos;
219
+ return pos;
220
+ });
221
+ };
222
+ var getResolvePositions = function getResolvePositions(tr, state) {
223
+ var cardState = getPluginState(state);
224
+ if (!cardState) {
225
+ return [];
226
+ }
227
+ var pluginMeta = tr.getMeta(pluginKey);
228
+ if (!isTransactionResolveReplace(tr)) {
229
+ return [];
230
+ }
231
+ return cardState.requests.filter(function (request) {
232
+ return request.url === pluginMeta.url;
233
+ }).map(function (request) {
234
+ return request.pos;
235
+ });
236
+ };
237
+ var getResolveLinkPrevDisplay = function getResolveLinkPrevDisplay(state, pos) {
238
+ var _cardState$requests$f;
239
+ var cardState = getPluginState(state);
240
+ if (!cardState) {
241
+ return undefined;
242
+ }
243
+ return (_cardState$requests$f = cardState.requests.find(function (request) {
244
+ return request.pos === pos;
245
+ })) === null || _cardState$requests$f === void 0 ? void 0 : _cardState$requests$f.previousAppearance;
246
+ };
247
+ export function eventsFromTransaction(tr, state) {
248
+ var events = [];
249
+ try {
250
+ /**
251
+ * Skip transactions sent by collab (identified by 'isRemote' key)
252
+ * Skip entire document replace steps
253
+ * We are only concerned with transactions performed on the document directly by the user
254
+ */
255
+ var isRemote = tr.getMeta('isRemote');
256
+ var isReplaceDocument = tr.getMeta('replaceDocument');
257
+ if (isRemote || isReplaceDocument) {
258
+ return events;
259
+ }
260
+ var historyMeta = tr.getMeta(pmHistoryPluginKey);
261
+ var isUndo = isHistoryMeta(historyMeta) && historyMeta.redo === false;
262
+ var isRedo = isHistoryMeta(historyMeta) && historyMeta.redo === true;
263
+
264
+ /**
265
+ * Retrieve metadata from the LinkMetaStep(s) in the transaction
266
+ */
267
+ var _getLinkMetadataFromT = getLinkMetadataFromTransaction(tr),
268
+ action = _getLinkMetadataFromT.action,
269
+ inputMethod = _getLinkMetadataFromT.inputMethod,
270
+ sourceEvent = _getLinkMetadataFromT.sourceEvent;
271
+ var contextualData = {
272
+ action: action,
273
+ inputMethod: inputMethod,
274
+ sourceEvent: sourceEvent,
275
+ isUndo: isUndo,
276
+ isRedo: isRedo
277
+ };
278
+ var _findChangedLinks = findChangedLinks(tr, state),
279
+ removed = _findChangedLinks.removed,
280
+ inserted = _findChangedLinks.inserted,
281
+ updated = _findChangedLinks.updated;
282
+ var MAX_LINK_EVENTS = 10;
283
+ if ([removed, inserted, updated].some(function (arr) {
284
+ return arr.length > MAX_LINK_EVENTS;
285
+ })) {
286
+ return [];
287
+ }
288
+ for (var i = 0; i < updated.length; i++) {
289
+ var _update$previous$disp;
290
+ var update = updated[i];
291
+ var link = update.inserted;
292
+ var url = getLinkUrl(link);
293
+ var display = appearanceForLink(link);
294
+ var previousDisplay = 'removed' in update ? appearanceForLink(update.removed) : (_update$previous$disp = update.previous.display) !== null && _update$previous$disp !== void 0 ? _update$previous$disp : 'unknown';
295
+ if (url) {
296
+ events.push({
297
+ type: 'updated',
298
+ data: _objectSpread(_objectSpread({}, contextualData), {}, {
299
+ url: url,
300
+ display: display,
301
+ previousDisplay: previousDisplay
302
+ })
303
+ });
304
+ }
305
+ }
306
+ var pushEvents = function pushEvents(links, type) {
307
+ for (var _i2 = 0; _i2 < links.length; _i2++) {
308
+ var _link = links[_i2];
309
+ var _url = getLinkUrl(_link);
310
+ var _display = appearanceForLink(_link);
311
+ if (_url) {
312
+ events.push({
313
+ type: type,
314
+ data: _objectSpread(_objectSpread({}, contextualData), {}, {
315
+ url: _url,
316
+ display: _display
317
+ })
318
+ });
319
+ }
320
+ }
321
+ };
322
+ pushEvents(removed, 'deleted');
323
+ pushEvents(inserted, 'created');
324
+ return events;
325
+ } catch (err) {
326
+ return events;
327
+ }
328
+ }
@@ -0,0 +1,2 @@
1
+ export { createAnalyticsQueue } from './create-analytics-queue';
2
+ export { eventsFromTransaction } from './events-from-tr';
@@ -0,0 +1,124 @@
1
+ import { isLinkMark } from '@atlaskit/editor-common/utils';
2
+ import { appearanceForNodeType } from '../../utils';
3
+ /**
4
+ * Whether a node is a "link" node, ie inline card, block card, embed card
5
+ * (but not a text node with a link mark)
6
+ */
7
+ export function isLinkNode(node) {
8
+ return !!appearanceForNodeType(node.type);
9
+ }
10
+
11
+ /**
12
+ * Analytics appearance for link object
13
+ */
14
+ export function appearanceForLink(link) {
15
+ if (link.type === 'node') {
16
+ var appearance = appearanceForNodeType(link.node.type);
17
+ if (appearance) {
18
+ return appearance;
19
+ }
20
+ }
21
+ return 'url';
22
+ }
23
+ var nodeHasLinkMark = function nodeHasLinkMark(schema, node) {
24
+ if (node.marks) {
25
+ for (var i = 0; i < node.marks.length; i++) {
26
+ var mark = node.marks[i];
27
+ if (isLinkMark(mark, schema)) {
28
+ return true;
29
+ }
30
+ }
31
+ }
32
+ return false;
33
+ };
34
+
35
+ /**
36
+ * Determine if a node is considered to be a link
37
+ */
38
+ export var isLink = function isLink(schema, node) {
39
+ if (isLinkNode(node)) {
40
+ return true;
41
+ }
42
+ return nodeHasLinkMark(schema, node);
43
+ };
44
+
45
+ /**
46
+ * Given a node, find all nodes and marks that are considered "links"
47
+ * @param state EditorState
48
+ * @param fragment Fragment to search
49
+ * @returns Array of nodes and marks found in the fragment that are "links"
50
+ */
51
+ export function findLinksInNode(schema, node, offset) {
52
+ var links = [];
53
+ node.descendants(function (node, pos) {
54
+ // Nodes
55
+ if (isLinkNode(node)) {
56
+ links.push({
57
+ type: 'node',
58
+ pos: pos + offset,
59
+ node: node
60
+ });
61
+ }
62
+
63
+ // Marks
64
+ if (node.marks) {
65
+ for (var i = 0; i < node.marks.length; i++) {
66
+ var mark = node.marks[i];
67
+ if (isLinkMark(mark, schema)) {
68
+ links.push({
69
+ type: 'mark',
70
+ pos: pos + offset,
71
+ mark: mark
72
+ });
73
+ }
74
+ }
75
+ }
76
+ });
77
+ return links;
78
+ }
79
+ export function getLinkUrl(link) {
80
+ var _link$mark$attrs;
81
+ if (link.type === 'node') {
82
+ var _link$node$attrs;
83
+ return (_link$node$attrs = link.node.attrs) === null || _link$node$attrs === void 0 ? void 0 : _link$node$attrs.url;
84
+ }
85
+ return (_link$mark$attrs = link.mark.attrs) === null || _link$mark$attrs === void 0 ? void 0 : _link$mark$attrs.href;
86
+ }
87
+ export var linkObjectFromNode = function linkObjectFromNode(schema, node, pos) {
88
+ if (isLinkNode(node)) {
89
+ return {
90
+ type: 'node',
91
+ pos: pos,
92
+ node: node
93
+ };
94
+ }
95
+ if (node.marks) {
96
+ for (var i = 0; i < node.marks.length; i++) {
97
+ var mark = node.marks[i];
98
+ if (isLinkMark(mark, schema)) {
99
+ return {
100
+ type: 'mark',
101
+ pos: pos,
102
+ mark: mark
103
+ };
104
+ }
105
+ }
106
+ }
107
+ };
108
+ export var findLinksAtPositions = function findLinksAtPositions(tr, positions) {
109
+ var schema = tr.doc.type.schema;
110
+ var links = [];
111
+ for (var i = 0; i < positions.length; i++) {
112
+ var pos = positions[i];
113
+ var node = tr.doc.nodeAt(pos);
114
+ if (!node) {
115
+ continue;
116
+ }
117
+ var link = linkObjectFromNode(schema, node, pos);
118
+ if (!link) {
119
+ continue;
120
+ }
121
+ links.push(link);
122
+ }
123
+ return links;
124
+ };