@atlaskit/editor-plugin-block-controls 8.6.3 → 8.7.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 (35) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/block-decoration-utils/package.json +17 -0
  3. package/dist/cjs/blockControlsPlugin.js +15 -1
  4. package/dist/cjs/pm-plugins/main.js +56 -29
  5. package/dist/cjs/ui/block-decoration-utils.js +53 -0
  6. package/dist/cjs/ui/consts.js +1 -9
  7. package/dist/es2019/blockControlsPlugin.js +273 -259
  8. package/dist/es2019/pm-plugins/main.js +25 -29
  9. package/dist/es2019/ui/block-decoration-utils.js +9 -0
  10. package/dist/es2019/ui/consts.js +0 -8
  11. package/dist/esm/blockControlsPlugin.js +15 -1
  12. package/dist/esm/pm-plugins/main.js +56 -29
  13. package/dist/esm/ui/block-decoration-utils.js +9 -0
  14. package/dist/esm/ui/consts.js +0 -8
  15. package/dist/types/blockControlsPluginType.d.ts +20 -2
  16. package/dist/types/index.d.ts +1 -1
  17. package/dist/types/pm-plugins/main.d.ts +3 -3
  18. package/dist/types/ui/block-decoration-utils.d.ts +6 -0
  19. package/dist/types/ui/consts.d.ts +0 -8
  20. package/dist/types-ts4.5/blockControlsPluginType.d.ts +20 -2
  21. package/dist/types-ts4.5/index.d.ts +1 -1
  22. package/dist/types-ts4.5/pm-plugins/main.d.ts +3 -3
  23. package/dist/types-ts4.5/ui/block-decoration-utils.d.ts +6 -0
  24. package/dist/types-ts4.5/ui/consts.d.ts +0 -8
  25. package/package.json +6 -3
  26. package/dist/cjs/pm-plugins/decorations-remix-button.js +0 -67
  27. package/dist/cjs/ui/remix-button.js +0 -163
  28. package/dist/es2019/pm-plugins/decorations-remix-button.js +0 -56
  29. package/dist/es2019/ui/remix-button.js +0 -144
  30. package/dist/esm/pm-plugins/decorations-remix-button.js +0 -59
  31. package/dist/esm/ui/remix-button.js +0 -154
  32. package/dist/types/pm-plugins/decorations-remix-button.d.ts +0 -21
  33. package/dist/types/ui/remix-button.d.ts +0 -17
  34. package/dist/types-ts4.5/pm-plugins/decorations-remix-button.d.ts +0 -21
  35. package/dist/types-ts4.5/ui/remix-button.d.ts +0 -17
@@ -23,7 +23,6 @@ import { dragHandleDecoration, emptyParagraphNodeDecorations, findHandleDec } fr
23
23
  import { dropTargetDecorations, findDropTargetDecs } from './decorations-drop-target';
24
24
  import { getActiveDropTargetDecorations } from './decorations-drop-target-active';
25
25
  import { findQuickInsertInsertButtonDecoration, quickInsertButtonDecoration } from './decorations-quick-insert-button';
26
- import { findRemixButtonDecoration, remixButtonDecoration } from './decorations-remix-button';
27
26
  import { handleMouseDown } from './handle-mouse-down';
28
27
  import { handleMouseOver } from './handle-mouse-over';
29
28
  import { boundKeydownHandler } from './keymap';
@@ -235,7 +234,7 @@ const getDecorationAtPos = (state, decorations, pos, to) => {
235
234
  const nodeDecAtActivePos = nodeDecsAtActivePos.pop();
236
235
  return nodeDecAtActivePos;
237
236
  };
238
- export const apply = (api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, anchorRectCache, resizeObserverWidth, pragmaticCleanup) => {
237
+ export const apply = (api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, nodeDecorationRegistry, anchorRectCache, resizeObserverWidth, pragmaticCleanup) => {
239
238
  var _api$limitedMode, _api$limitedMode$shar, _api$limitedMode$shar2, _meta$multiSelectDnD, _activeNode, _activeNode2, _meta$activeNode$hand, _activeNode3, _activeNode4, _meta$isDragging2, _meta$isDragging3, _meta$toggleMenu, _meta$toggleMenu2, _meta$toggleMenu3, _meta$toggleMenu4, _meta$toggleMenu5, _meta$toggleMenu6, _meta$toggleMenu7, _meta$toggleMenu8, _meta$editorHeight, _meta$editorWidthLeft, _meta$editorWidthRigh, _meta$isPMDragging, _meta$isShiftDown, _meta$lastDragCancell;
240
239
  let {
241
240
  activeNode,
@@ -437,10 +436,12 @@ export const apply = (api, formatMessage, tr, currentState, newState, flags, nod
437
436
  var _activeNode7, _activeNode8;
438
437
  const oldQuickInsertButton = findQuickInsertInsertButtonDecoration(decorations, (_activeNode7 = activeNode) === null || _activeNode7 === void 0 ? void 0 : _activeNode7.rootPos, (_activeNode8 = activeNode) === null || _activeNode8 === void 0 ? void 0 : _activeNode8.rootPos);
439
438
  decorations = decorations.remove(oldQuickInsertButton);
440
- if (expValEquals('confluence_remix_icon_right_side', 'isEnabled', true)) {
441
- var _activeNode9, _activeNode0;
442
- const oldRemixButton = findRemixButtonDecoration(decorations, (_activeNode9 = activeNode) === null || _activeNode9 === void 0 ? void 0 : _activeNode9.rootPos, (_activeNode0 = activeNode) === null || _activeNode0 === void 0 ? void 0 : _activeNode0.rootPos);
443
- decorations = decorations.remove(oldRemixButton);
439
+ if (fg('platform_editor_expose_block_controls_deco_api')) {
440
+ for (const factory of nodeDecorationRegistry) {
441
+ var _activeNode9, _activeNode0;
442
+ const old = decorations.find((_activeNode9 = activeNode) === null || _activeNode9 === void 0 ? void 0 : _activeNode9.rootPos, (_activeNode0 = activeNode) === null || _activeNode0 === void 0 ? void 0 : _activeNode0.rootPos, spec => spec.type === factory.type);
443
+ decorations = decorations.remove(old);
444
+ }
444
445
  }
445
446
  }
446
447
  } else if (api) {
@@ -481,27 +482,22 @@ export const apply = (api, formatMessage, tr, currentState, newState, flags, nod
481
482
  editorState: newState
482
483
  });
483
484
  decorations = decorations.add(newState.doc, [quickInsertButton]);
484
- if (expValEquals('confluence_remix_icon_right_side', 'isEnabled', true)) {
485
- var _activeNode13, _activeNode14, _latestActiveNode1, _latestActiveNode10, _latestActiveNode11, _latestActiveNode12, _latestActiveNode13;
486
- const oldRemixButton = findRemixButtonDecoration(decorations, (_activeNode13 = activeNode) === null || _activeNode13 === void 0 ? void 0 : _activeNode13.rootPos, (_activeNode14 = activeNode) === null || _activeNode14 === void 0 ? void 0 : _activeNode14.rootPos);
487
- decorations = decorations.remove(oldRemixButton);
488
- const remixButton = remixButtonDecoration({
489
- api,
490
- formatMessage,
491
- anchorName: (_latestActiveNode1 = latestActiveNode) === null || _latestActiveNode1 === void 0 ? void 0 : _latestActiveNode1.anchorName,
492
- nodeType: (_latestActiveNode10 = latestActiveNode) === null || _latestActiveNode10 === void 0 ? void 0 : _latestActiveNode10.nodeType,
493
- nodeViewPortalProviderAPI,
494
- rootPos: (_latestActiveNode11 = latestActiveNode) === null || _latestActiveNode11 === void 0 ? void 0 : _latestActiveNode11.rootPos,
495
- rootAnchorName: (_latestActiveNode12 = latestActiveNode) === null || _latestActiveNode12 === void 0 ? void 0 : _latestActiveNode12.rootAnchorName,
496
- rootNodeType: (_latestActiveNode13 = latestActiveNode) === null || _latestActiveNode13 === void 0 ? void 0 : _latestActiveNode13.rootNodeType,
497
- editorState: newState
498
- });
499
- decorations = decorations.add(newState.doc, [remixButton]);
500
- } else {
501
- var _activeNode15, _activeNode16;
502
- // Remove remix decoration when experiment is off so it disappears when flag is toggled
503
- const oldRemixButton = findRemixButtonDecoration(decorations, (_activeNode15 = activeNode) === null || _activeNode15 === void 0 ? void 0 : _activeNode15.rootPos, (_activeNode16 = activeNode) === null || _activeNode16 === void 0 ? void 0 : _activeNode16.rootPos);
504
- decorations = decorations.remove(oldRemixButton);
485
+ if (fg('platform_editor_expose_block_controls_deco_api')) {
486
+ for (const factory of nodeDecorationRegistry) {
487
+ var _activeNode13, _activeNode14, _latestActiveNode1, _latestActiveNode10, _latestActiveNode11, _latestActiveNode12, _latestActiveNode13;
488
+ const old = decorations.find((_activeNode13 = activeNode) === null || _activeNode13 === void 0 ? void 0 : _activeNode13.rootPos, (_activeNode14 = activeNode) === null || _activeNode14 === void 0 ? void 0 : _activeNode14.rootPos, spec => spec.type === factory.type);
489
+ decorations = decorations.remove(old);
490
+ const dec = factory.create({
491
+ editorState: newState,
492
+ nodeViewPortalProviderAPI,
493
+ anchorName: (_latestActiveNode1 = latestActiveNode) === null || _latestActiveNode1 === void 0 ? void 0 : _latestActiveNode1.anchorName,
494
+ nodeType: (_latestActiveNode10 = latestActiveNode) === null || _latestActiveNode10 === void 0 ? void 0 : _latestActiveNode10.nodeType,
495
+ rootPos: (_latestActiveNode11 = latestActiveNode) === null || _latestActiveNode11 === void 0 ? void 0 : _latestActiveNode11.rootPos,
496
+ rootAnchorName: (_latestActiveNode12 = latestActiveNode) === null || _latestActiveNode12 === void 0 ? void 0 : _latestActiveNode12.rootAnchorName,
497
+ rootNodeType: (_latestActiveNode13 = latestActiveNode) === null || _latestActiveNode13 === void 0 ? void 0 : _latestActiveNode13.rootNodeType
498
+ });
499
+ decorations = decorations.add(newState.doc, [dec]);
500
+ }
505
501
  }
506
502
  }
507
503
  }
@@ -600,7 +596,7 @@ export const apply = (api, formatMessage, tr, currentState, newState, flags, nod
600
596
  isSelectedViaDragHandle: isSelectedViaDragHandleNew
601
597
  };
602
598
  };
603
- export const createPlugin = (api, getIntl, nodeViewPortalProviderAPI) => {
599
+ export const createPlugin = (api, getIntl, nodeViewPortalProviderAPI, nodeDecorationRegistry) => {
604
600
  const {
605
601
  formatMessage
606
602
  } = getIntl();
@@ -627,7 +623,7 @@ export const createPlugin = (api, getIntl, nodeViewPortalProviderAPI) => {
627
623
  init() {
628
624
  return initialState;
629
625
  },
630
- apply: (tr, currentState, _, newState) => apply(api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, anchorRectCache, resizeObserverWidth, pragmaticCleanup)
626
+ apply: (tr, currentState, _, newState) => apply(api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, nodeDecorationRegistry, anchorRectCache, resizeObserverWidth, pragmaticCleanup)
631
627
  },
632
628
  props: {
633
629
  decorations: state => {
@@ -0,0 +1,9 @@
1
+ // Disable no-re-export rule for entry point files
2
+ /* eslint-disable @atlaskit/editor/no-re-export */
3
+
4
+ export { VisibilityContainer } from './visibility-container';
5
+ export { refreshAnchorName } from './utils/anchor-name';
6
+ export { getAnchorAttrName } from './utils/dom-attr-name';
7
+ export { rootElementGap, topPositionAdjustment } from './consts';
8
+ export { getTopPosition } from '../pm-plugins/utils/drag-handle-positions';
9
+ export { getRightPositionForRootElement } from '../pm-plugins/utils/widget-positions';
@@ -35,14 +35,6 @@ export const QUICK_INSERT_DIMENSIONS = {
35
35
  height: QUICK_INSERT_HEIGHT
36
36
  };
37
37
  export const QUICK_INSERT_LEFT_OFFSET = 16;
38
- export const REMIX_BUTTON_HEIGHT = 24;
39
- export const REMIX_BUTTON_WIDTH = 24;
40
- export const REMIX_BUTTON_DIMENSIONS = {
41
- width: REMIX_BUTTON_WIDTH,
42
- height: REMIX_BUTTON_HEIGHT
43
- };
44
- /** Extra offset to the right for the right-side Remix button (px) */
45
- export const REMIX_BUTTON_RIGHT_OFFSET = 55;
46
38
  const nodeTypeExcludeList = ['embedCard', 'mediaSingle', 'table'];
47
39
  const breakoutResizableNodes = ['expand', 'layoutSection', 'codeBlock'];
48
40
  export const dragHandleGap = (nodeType, parentNodeType) => {
@@ -24,15 +24,29 @@ import { selectNode } from './pm-plugins/utils/getSelection';
24
24
  import { GlobalStylesWrapper } from './ui/global-styles';
25
25
  export var blockControlsPlugin = function blockControlsPlugin(_ref) {
26
26
  var api = _ref.api;
27
+ var nodeDecorationRegistry = [];
27
28
  return {
28
29
  name: 'blockControls',
30
+ actions: {
31
+ registerNodeDecoration: function registerNodeDecoration(factory) {
32
+ nodeDecorationRegistry.push(factory);
33
+ },
34
+ unregisterNodeDecoration: function unregisterNodeDecoration(type) {
35
+ var idx = nodeDecorationRegistry.findIndex(function (f) {
36
+ return f.type === type;
37
+ });
38
+ if (idx !== -1) {
39
+ nodeDecorationRegistry.splice(idx, 1);
40
+ }
41
+ }
42
+ },
29
43
  pmPlugins: function pmPlugins() {
30
44
  var pmPlugins = [{
31
45
  name: 'blockControlsPmPlugin',
32
46
  plugin: function plugin(_ref2) {
33
47
  var getIntl = _ref2.getIntl,
34
48
  nodeViewPortalProviderAPI = _ref2.nodeViewPortalProviderAPI;
35
- return createPlugin(api, getIntl, nodeViewPortalProviderAPI);
49
+ return createPlugin(api, getIntl, nodeViewPortalProviderAPI, nodeDecorationRegistry);
36
50
  }
37
51
  }];
38
52
  if (editorExperiment('platform_editor_controls', 'variant1')) {
@@ -1,4 +1,7 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
3
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
4
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
2
5
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
6
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
7
  import rafSchedule from 'raf-schd';
@@ -26,7 +29,6 @@ import { dragHandleDecoration, emptyParagraphNodeDecorations, findHandleDec } fr
26
29
  import { dropTargetDecorations, findDropTargetDecs } from './decorations-drop-target';
27
30
  import { getActiveDropTargetDecorations } from './decorations-drop-target-active';
28
31
  import { findQuickInsertInsertButtonDecoration, quickInsertButtonDecoration } from './decorations-quick-insert-button';
29
- import { findRemixButtonDecoration, remixButtonDecoration } from './decorations-remix-button';
30
32
  import { handleMouseDown } from './handle-mouse-down';
31
33
  import { handleMouseOver } from './handle-mouse-over';
32
34
  import { boundKeydownHandler } from './keymap';
@@ -234,7 +236,7 @@ var getDecorationAtPos = function getDecorationAtPos(state, decorations, pos, to
234
236
  var nodeDecAtActivePos = nodeDecsAtActivePos.pop();
235
237
  return nodeDecAtActivePos;
236
238
  };
237
- var _apply = function apply(api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, anchorRectCache, resizeObserverWidth, pragmaticCleanup) {
239
+ var _apply = function apply(api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, nodeDecorationRegistry, anchorRectCache, resizeObserverWidth, pragmaticCleanup) {
238
240
  var _api$limitedMode, _meta$multiSelectDnD, _activeNode, _activeNode2, _meta$activeNode$hand, _activeNode3, _activeNode4, _meta$isDragging2, _meta$isDragging3, _meta$toggleMenu, _meta$toggleMenu2, _meta$toggleMenu3, _meta$toggleMenu4, _meta$toggleMenu5, _meta$toggleMenu6, _meta$toggleMenu7, _meta$toggleMenu8, _meta$editorHeight, _meta$editorWidthLeft, _meta$editorWidthRigh, _meta$isPMDragging, _meta$isShiftDown, _meta$lastDragCancell;
239
241
  var activeNode = currentState.activeNode,
240
242
  decorations = currentState.decorations,
@@ -433,10 +435,26 @@ var _apply = function apply(api, formatMessage, tr, currentState, newState, flag
433
435
  var _activeNode7, _activeNode8;
434
436
  var oldQuickInsertButton = findQuickInsertInsertButtonDecoration(decorations, (_activeNode7 = activeNode) === null || _activeNode7 === void 0 ? void 0 : _activeNode7.rootPos, (_activeNode8 = activeNode) === null || _activeNode8 === void 0 ? void 0 : _activeNode8.rootPos);
435
437
  decorations = decorations.remove(oldQuickInsertButton);
436
- if (expValEquals('confluence_remix_icon_right_side', 'isEnabled', true)) {
437
- var _activeNode9, _activeNode0;
438
- var oldRemixButton = findRemixButtonDecoration(decorations, (_activeNode9 = activeNode) === null || _activeNode9 === void 0 ? void 0 : _activeNode9.rootPos, (_activeNode0 = activeNode) === null || _activeNode0 === void 0 ? void 0 : _activeNode0.rootPos);
439
- decorations = decorations.remove(oldRemixButton);
438
+ if (fg('platform_editor_expose_block_controls_deco_api')) {
439
+ var _iterator = _createForOfIteratorHelper(nodeDecorationRegistry),
440
+ _step;
441
+ try {
442
+ var _loop = function _loop() {
443
+ var _activeNode9, _activeNode0;
444
+ var factory = _step.value;
445
+ var old = decorations.find((_activeNode9 = activeNode) === null || _activeNode9 === void 0 ? void 0 : _activeNode9.rootPos, (_activeNode0 = activeNode) === null || _activeNode0 === void 0 ? void 0 : _activeNode0.rootPos, function (spec) {
446
+ return spec.type === factory.type;
447
+ });
448
+ decorations = decorations.remove(old);
449
+ };
450
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
451
+ _loop();
452
+ }
453
+ } catch (err) {
454
+ _iterator.e(err);
455
+ } finally {
456
+ _iterator.f();
457
+ }
440
458
  }
441
459
  }
442
460
  } else if (api) {
@@ -477,27 +495,36 @@ var _apply = function apply(api, formatMessage, tr, currentState, newState, flag
477
495
  editorState: newState
478
496
  });
479
497
  decorations = decorations.add(newState.doc, [quickInsertButton]);
480
- if (expValEquals('confluence_remix_icon_right_side', 'isEnabled', true)) {
481
- var _activeNode13, _activeNode14, _latestActiveNode1, _latestActiveNode10, _latestActiveNode11, _latestActiveNode12, _latestActiveNode13;
482
- var _oldRemixButton = findRemixButtonDecoration(decorations, (_activeNode13 = activeNode) === null || _activeNode13 === void 0 ? void 0 : _activeNode13.rootPos, (_activeNode14 = activeNode) === null || _activeNode14 === void 0 ? void 0 : _activeNode14.rootPos);
483
- decorations = decorations.remove(_oldRemixButton);
484
- var remixButton = remixButtonDecoration({
485
- api: api,
486
- formatMessage: formatMessage,
487
- anchorName: (_latestActiveNode1 = latestActiveNode) === null || _latestActiveNode1 === void 0 ? void 0 : _latestActiveNode1.anchorName,
488
- nodeType: (_latestActiveNode10 = latestActiveNode) === null || _latestActiveNode10 === void 0 ? void 0 : _latestActiveNode10.nodeType,
489
- nodeViewPortalProviderAPI: nodeViewPortalProviderAPI,
490
- rootPos: (_latestActiveNode11 = latestActiveNode) === null || _latestActiveNode11 === void 0 ? void 0 : _latestActiveNode11.rootPos,
491
- rootAnchorName: (_latestActiveNode12 = latestActiveNode) === null || _latestActiveNode12 === void 0 ? void 0 : _latestActiveNode12.rootAnchorName,
492
- rootNodeType: (_latestActiveNode13 = latestActiveNode) === null || _latestActiveNode13 === void 0 ? void 0 : _latestActiveNode13.rootNodeType,
493
- editorState: newState
494
- });
495
- decorations = decorations.add(newState.doc, [remixButton]);
496
- } else {
497
- var _activeNode15, _activeNode16;
498
- // Remove remix decoration when experiment is off so it disappears when flag is toggled
499
- var _oldRemixButton2 = findRemixButtonDecoration(decorations, (_activeNode15 = activeNode) === null || _activeNode15 === void 0 ? void 0 : _activeNode15.rootPos, (_activeNode16 = activeNode) === null || _activeNode16 === void 0 ? void 0 : _activeNode16.rootPos);
500
- decorations = decorations.remove(_oldRemixButton2);
498
+ if (fg('platform_editor_expose_block_controls_deco_api')) {
499
+ var _iterator2 = _createForOfIteratorHelper(nodeDecorationRegistry),
500
+ _step2;
501
+ try {
502
+ var _loop2 = function _loop2() {
503
+ var _activeNode13, _activeNode14, _latestActiveNode1, _latestActiveNode10, _latestActiveNode11, _latestActiveNode12, _latestActiveNode13;
504
+ var factory = _step2.value;
505
+ var old = decorations.find((_activeNode13 = activeNode) === null || _activeNode13 === void 0 ? void 0 : _activeNode13.rootPos, (_activeNode14 = activeNode) === null || _activeNode14 === void 0 ? void 0 : _activeNode14.rootPos, function (spec) {
506
+ return spec.type === factory.type;
507
+ });
508
+ decorations = decorations.remove(old);
509
+ var dec = factory.create({
510
+ editorState: newState,
511
+ nodeViewPortalProviderAPI: nodeViewPortalProviderAPI,
512
+ anchorName: (_latestActiveNode1 = latestActiveNode) === null || _latestActiveNode1 === void 0 ? void 0 : _latestActiveNode1.anchorName,
513
+ nodeType: (_latestActiveNode10 = latestActiveNode) === null || _latestActiveNode10 === void 0 ? void 0 : _latestActiveNode10.nodeType,
514
+ rootPos: (_latestActiveNode11 = latestActiveNode) === null || _latestActiveNode11 === void 0 ? void 0 : _latestActiveNode11.rootPos,
515
+ rootAnchorName: (_latestActiveNode12 = latestActiveNode) === null || _latestActiveNode12 === void 0 ? void 0 : _latestActiveNode12.rootAnchorName,
516
+ rootNodeType: (_latestActiveNode13 = latestActiveNode) === null || _latestActiveNode13 === void 0 ? void 0 : _latestActiveNode13.rootNodeType
517
+ });
518
+ decorations = decorations.add(newState.doc, [dec]);
519
+ };
520
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
521
+ _loop2();
522
+ }
523
+ } catch (err) {
524
+ _iterator2.e(err);
525
+ } finally {
526
+ _iterator2.f();
527
+ }
501
528
  }
502
529
  }
503
530
  }
@@ -596,7 +623,7 @@ var _apply = function apply(api, formatMessage, tr, currentState, newState, flag
596
623
  };
597
624
  };
598
625
  export { _apply as apply };
599
- export var createPlugin = function createPlugin(api, getIntl, nodeViewPortalProviderAPI) {
626
+ export var createPlugin = function createPlugin(api, getIntl, nodeViewPortalProviderAPI, nodeDecorationRegistry) {
600
627
  var _getIntl = getIntl(),
601
628
  formatMessage = _getIntl.formatMessage;
602
629
  var isAdvancedLayoutEnabled = editorExperiment('advanced_layouts', true, {
@@ -623,7 +650,7 @@ export var createPlugin = function createPlugin(api, getIntl, nodeViewPortalProv
623
650
  return initialState;
624
651
  },
625
652
  apply: function apply(tr, currentState, _, newState) {
626
- return _apply(api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, anchorRectCache, resizeObserverWidth, pragmaticCleanup);
653
+ return _apply(api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, nodeDecorationRegistry, anchorRectCache, resizeObserverWidth, pragmaticCleanup);
627
654
  }
628
655
  },
629
656
  props: {
@@ -0,0 +1,9 @@
1
+ // Disable no-re-export rule for entry point files
2
+ /* eslint-disable @atlaskit/editor/no-re-export */
3
+
4
+ export { VisibilityContainer } from './visibility-container';
5
+ export { refreshAnchorName } from './utils/anchor-name';
6
+ export { getAnchorAttrName } from './utils/dom-attr-name';
7
+ export { rootElementGap, topPositionAdjustment } from './consts';
8
+ export { getTopPosition } from '../pm-plugins/utils/drag-handle-positions';
9
+ export { getRightPositionForRootElement } from '../pm-plugins/utils/widget-positions';
@@ -37,14 +37,6 @@ export var QUICK_INSERT_DIMENSIONS = {
37
37
  height: QUICK_INSERT_HEIGHT
38
38
  };
39
39
  export var QUICK_INSERT_LEFT_OFFSET = 16;
40
- export var REMIX_BUTTON_HEIGHT = 24;
41
- export var REMIX_BUTTON_WIDTH = 24;
42
- export var REMIX_BUTTON_DIMENSIONS = {
43
- width: REMIX_BUTTON_WIDTH,
44
- height: REMIX_BUTTON_HEIGHT
45
- };
46
- /** Extra offset to the right for the right-side Remix button (px) */
47
- export var REMIX_BUTTON_RIGHT_OFFSET = 55;
48
40
  var nodeTypeExcludeList = ['embedCard', 'mediaSingle', 'table'];
49
41
  var breakoutResizableNodes = ['expand', 'layoutSection', 'codeBlock'];
50
42
  export var dragHandleGap = function dragHandleGap(nodeType, parentNodeType) {
@@ -1,5 +1,6 @@
1
1
  import type { IntlShape } from 'react-intl-next';
2
2
  import type { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
+ import type { PortalProviderAPI } from '@atlaskit/editor-common/portal';
3
4
  import type { DIRECTION, EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
4
5
  import type { AccessibilityUtilsPlugin } from '@atlaskit/editor-plugin-accessibility-utils';
5
6
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
@@ -14,9 +15,9 @@ import type { ToolbarPlugin } from '@atlaskit/editor-plugin-toolbar';
14
15
  import type { TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead';
15
16
  import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent';
16
17
  import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
17
- import type { Selection } from '@atlaskit/editor-prosemirror/state';
18
+ import type { EditorState, Selection } from '@atlaskit/editor-prosemirror/state';
18
19
  import type { Mapping } from '@atlaskit/editor-prosemirror/transform';
19
- import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
20
+ import type { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
20
21
  export type ActiveNode = {
21
22
  anchorName: string;
22
23
  handleOptions?: HandleOptions;
@@ -100,6 +101,19 @@ export type BlockControlsSharedState = {
100
101
  export type HandleOptions = {
101
102
  isFocused: boolean;
102
103
  } | undefined;
104
+ export type NodeDecorationFactoryParams = {
105
+ anchorName: string;
106
+ editorState: EditorState;
107
+ nodeType: string;
108
+ nodeViewPortalProviderAPI: PortalProviderAPI;
109
+ rootAnchorName?: string;
110
+ rootNodeType?: string;
111
+ rootPos: number;
112
+ };
113
+ export type NodeDecorationFactory = {
114
+ create: (params: NodeDecorationFactoryParams) => Decoration;
115
+ type: string;
116
+ };
103
117
  export type MoveNode = (start: number, to: number, inputMethod?: MoveNodeMethod, formatMessage?: IntlShape['formatMessage']) => EditorCommand;
104
118
  export type BlockControlsPluginDependencies = [
105
119
  OptionalPlugin<LimitedModePlugin>,
@@ -117,6 +131,10 @@ export type BlockControlsPluginDependencies = [
117
131
  OptionalPlugin<ToolbarPlugin>
118
132
  ];
119
133
  export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
134
+ actions: {
135
+ registerNodeDecoration: (factory: NodeDecorationFactory) => void;
136
+ unregisterNodeDecoration: (type: string) => void;
137
+ };
120
138
  commands: {
121
139
  handleKeyDownWithPreservedSelection: (event: KeyboardEvent) => EditorCommand;
122
140
  mapPreservedSelection: (mapping: Mapping) => EditorCommand;
@@ -1,2 +1,2 @@
1
1
  export { blockControlsPlugin } from './blockControlsPlugin';
2
- export type { BlockControlsPlugin, BlockControlsSharedState, HandleOptions, MoveNodeMethod, BlockControlsPluginDependencies, PluginState, MoveNode, } from './blockControlsPluginType';
2
+ export type { BlockControlsPlugin, BlockControlsSharedState, HandleOptions, MoveNodeMethod, BlockControlsPluginDependencies, NodeDecorationFactory, NodeDecorationFactoryParams, PluginState, MoveNode, } from './blockControlsPluginType';
@@ -5,7 +5,7 @@ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
5
5
  import type { EditorState, ReadonlyTransaction, Transaction } from '@atlaskit/editor-prosemirror/state';
6
6
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
7
7
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
8
- import type { ActiveDropTargetNode, BlockControlsMeta, BlockControlsPlugin, MultiSelectDnD, PluginState } from '../blockControlsPluginType';
8
+ import type { ActiveDropTargetNode, BlockControlsMeta, BlockControlsPlugin, MultiSelectDnD, NodeDecorationFactory, PluginState } from '../blockControlsPluginType';
9
9
  import { AnchorRectCache } from './utils/anchor-utils';
10
10
  export declare const key: PluginKey<PluginState>;
11
11
  export interface FlagType {
@@ -13,7 +13,7 @@ export interface FlagType {
13
13
  toolbarFlagsEnabled: boolean;
14
14
  }
15
15
  export declare const getDecorations: (state: EditorState) => DecorationSet | undefined;
16
- export declare const apply: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, formatMessage: IntlShape["formatMessage"], tr: ReadonlyTransaction, currentState: PluginState, newState: EditorState, flags: FlagType, nodeViewPortalProviderAPI: PortalProviderAPI, anchorRectCache?: AnchorRectCache, resizeObserverWidth?: ResizeObserver, pragmaticCleanup?: (() => void) | null) => PluginState | {
16
+ export declare const apply: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, formatMessage: IntlShape["formatMessage"], tr: ReadonlyTransaction, currentState: PluginState, newState: EditorState, flags: FlagType, nodeViewPortalProviderAPI: PortalProviderAPI, nodeDecorationRegistry: NodeDecorationFactory[], anchorRectCache?: AnchorRectCache, resizeObserverWidth?: ResizeObserver, pragmaticCleanup?: (() => void) | null) => PluginState | {
17
17
  activeDropTargetNode: ActiveDropTargetNode | undefined;
18
18
  activeNode: any;
19
19
  blockMenuOptions: {
@@ -37,7 +37,7 @@ export declare const apply: (api: ExtractInjectionAPI<BlockControlsPlugin> | und
37
37
  menuTriggerByNode: any;
38
38
  multiSelectDnD: MultiSelectDnD | undefined;
39
39
  };
40
- export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, getIntl: () => IntlShape, nodeViewPortalProviderAPI: PortalProviderAPI) => SafePlugin<PluginState | {
40
+ export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, getIntl: () => IntlShape, nodeViewPortalProviderAPI: PortalProviderAPI, nodeDecorationRegistry: NodeDecorationFactory[]) => SafePlugin<PluginState | {
41
41
  activeDropTargetNode: ActiveDropTargetNode | undefined;
42
42
  activeNode: any;
43
43
  blockMenuOptions: {
@@ -0,0 +1,6 @@
1
+ export { VisibilityContainer } from './visibility-container';
2
+ export { refreshAnchorName } from './utils/anchor-name';
3
+ export { getAnchorAttrName } from './utils/dom-attr-name';
4
+ export { rootElementGap, topPositionAdjustment } from './consts';
5
+ export { getTopPosition } from '../pm-plugins/utils/drag-handle-positions';
6
+ export { getRightPositionForRootElement } from '../pm-plugins/utils/widget-positions';
@@ -30,14 +30,6 @@ export declare const QUICK_INSERT_DIMENSIONS: {
30
30
  height: number;
31
31
  };
32
32
  export declare const QUICK_INSERT_LEFT_OFFSET = 16;
33
- export declare const REMIX_BUTTON_HEIGHT = 24;
34
- export declare const REMIX_BUTTON_WIDTH = 24;
35
- export declare const REMIX_BUTTON_DIMENSIONS: {
36
- width: number;
37
- height: number;
38
- };
39
- /** Extra offset to the right for the right-side Remix button (px) */
40
- export declare const REMIX_BUTTON_RIGHT_OFFSET = 55;
41
33
  export declare const dragHandleGap: (nodeType: string, parentNodeType?: string) => number;
42
34
  export declare const rootElementGap: (nodeType: string) => number;
43
35
  export declare const getNestedNodeLeftPaddingMargin: (nodeType?: string) => "8px" | "16px" | "20px" | "24px" | "28px" | "40px";
@@ -1,5 +1,6 @@
1
1
  import type { IntlShape } from 'react-intl-next';
2
2
  import type { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
+ import type { PortalProviderAPI } from '@atlaskit/editor-common/portal';
3
4
  import type { DIRECTION, EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
4
5
  import type { AccessibilityUtilsPlugin } from '@atlaskit/editor-plugin-accessibility-utils';
5
6
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
@@ -14,9 +15,9 @@ import type { ToolbarPlugin } from '@atlaskit/editor-plugin-toolbar';
14
15
  import type { TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead';
15
16
  import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent';
16
17
  import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
17
- import type { Selection } from '@atlaskit/editor-prosemirror/state';
18
+ import type { EditorState, Selection } from '@atlaskit/editor-prosemirror/state';
18
19
  import type { Mapping } from '@atlaskit/editor-prosemirror/transform';
19
- import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
20
+ import type { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
20
21
  export type ActiveNode = {
21
22
  anchorName: string;
22
23
  handleOptions?: HandleOptions;
@@ -100,6 +101,19 @@ export type BlockControlsSharedState = {
100
101
  export type HandleOptions = {
101
102
  isFocused: boolean;
102
103
  } | undefined;
104
+ export type NodeDecorationFactoryParams = {
105
+ anchorName: string;
106
+ editorState: EditorState;
107
+ nodeType: string;
108
+ nodeViewPortalProviderAPI: PortalProviderAPI;
109
+ rootAnchorName?: string;
110
+ rootNodeType?: string;
111
+ rootPos: number;
112
+ };
113
+ export type NodeDecorationFactory = {
114
+ create: (params: NodeDecorationFactoryParams) => Decoration;
115
+ type: string;
116
+ };
103
117
  export type MoveNode = (start: number, to: number, inputMethod?: MoveNodeMethod, formatMessage?: IntlShape['formatMessage']) => EditorCommand;
104
118
  export type BlockControlsPluginDependencies = [
105
119
  OptionalPlugin<LimitedModePlugin>,
@@ -117,6 +131,10 @@ export type BlockControlsPluginDependencies = [
117
131
  OptionalPlugin<ToolbarPlugin>
118
132
  ];
119
133
  export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
134
+ actions: {
135
+ registerNodeDecoration: (factory: NodeDecorationFactory) => void;
136
+ unregisterNodeDecoration: (type: string) => void;
137
+ };
120
138
  commands: {
121
139
  handleKeyDownWithPreservedSelection: (event: KeyboardEvent) => EditorCommand;
122
140
  mapPreservedSelection: (mapping: Mapping) => EditorCommand;
@@ -1,2 +1,2 @@
1
1
  export { blockControlsPlugin } from './blockControlsPlugin';
2
- export type { BlockControlsPlugin, BlockControlsSharedState, HandleOptions, MoveNodeMethod, BlockControlsPluginDependencies, PluginState, MoveNode, } from './blockControlsPluginType';
2
+ export type { BlockControlsPlugin, BlockControlsSharedState, HandleOptions, MoveNodeMethod, BlockControlsPluginDependencies, NodeDecorationFactory, NodeDecorationFactoryParams, PluginState, MoveNode, } from './blockControlsPluginType';
@@ -5,7 +5,7 @@ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
5
5
  import type { EditorState, ReadonlyTransaction, Transaction } from '@atlaskit/editor-prosemirror/state';
6
6
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
7
7
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
8
- import type { ActiveDropTargetNode, BlockControlsMeta, BlockControlsPlugin, MultiSelectDnD, PluginState } from '../blockControlsPluginType';
8
+ import type { ActiveDropTargetNode, BlockControlsMeta, BlockControlsPlugin, MultiSelectDnD, NodeDecorationFactory, PluginState } from '../blockControlsPluginType';
9
9
  import { AnchorRectCache } from './utils/anchor-utils';
10
10
  export declare const key: PluginKey<PluginState>;
11
11
  export interface FlagType {
@@ -13,7 +13,7 @@ export interface FlagType {
13
13
  toolbarFlagsEnabled: boolean;
14
14
  }
15
15
  export declare const getDecorations: (state: EditorState) => DecorationSet | undefined;
16
- export declare const apply: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, formatMessage: IntlShape["formatMessage"], tr: ReadonlyTransaction, currentState: PluginState, newState: EditorState, flags: FlagType, nodeViewPortalProviderAPI: PortalProviderAPI, anchorRectCache?: AnchorRectCache, resizeObserverWidth?: ResizeObserver, pragmaticCleanup?: (() => void) | null) => PluginState | {
16
+ export declare const apply: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, formatMessage: IntlShape["formatMessage"], tr: ReadonlyTransaction, currentState: PluginState, newState: EditorState, flags: FlagType, nodeViewPortalProviderAPI: PortalProviderAPI, nodeDecorationRegistry: NodeDecorationFactory[], anchorRectCache?: AnchorRectCache, resizeObserverWidth?: ResizeObserver, pragmaticCleanup?: (() => void) | null) => PluginState | {
17
17
  activeDropTargetNode: ActiveDropTargetNode | undefined;
18
18
  activeNode: any;
19
19
  blockMenuOptions: {
@@ -37,7 +37,7 @@ export declare const apply: (api: ExtractInjectionAPI<BlockControlsPlugin> | und
37
37
  menuTriggerByNode: any;
38
38
  multiSelectDnD: MultiSelectDnD | undefined;
39
39
  };
40
- export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, getIntl: () => IntlShape, nodeViewPortalProviderAPI: PortalProviderAPI) => SafePlugin<PluginState | {
40
+ export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, getIntl: () => IntlShape, nodeViewPortalProviderAPI: PortalProviderAPI, nodeDecorationRegistry: NodeDecorationFactory[]) => SafePlugin<PluginState | {
41
41
  activeDropTargetNode: ActiveDropTargetNode | undefined;
42
42
  activeNode: any;
43
43
  blockMenuOptions: {
@@ -0,0 +1,6 @@
1
+ export { VisibilityContainer } from './visibility-container';
2
+ export { refreshAnchorName } from './utils/anchor-name';
3
+ export { getAnchorAttrName } from './utils/dom-attr-name';
4
+ export { rootElementGap, topPositionAdjustment } from './consts';
5
+ export { getTopPosition } from '../pm-plugins/utils/drag-handle-positions';
6
+ export { getRightPositionForRootElement } from '../pm-plugins/utils/widget-positions';
@@ -30,14 +30,6 @@ export declare const QUICK_INSERT_DIMENSIONS: {
30
30
  height: number;
31
31
  };
32
32
  export declare const QUICK_INSERT_LEFT_OFFSET = 16;
33
- export declare const REMIX_BUTTON_HEIGHT = 24;
34
- export declare const REMIX_BUTTON_WIDTH = 24;
35
- export declare const REMIX_BUTTON_DIMENSIONS: {
36
- width: number;
37
- height: number;
38
- };
39
- /** Extra offset to the right for the right-side Remix button (px) */
40
- export declare const REMIX_BUTTON_RIGHT_OFFSET = 55;
41
33
  export declare const dragHandleGap: (nodeType: string, parentNodeType?: string) => number;
42
34
  export declare const rootElementGap: (nodeType: string) => number;
43
35
  export declare const getNestedNodeLeftPaddingMargin: (nodeType?: string) => "8px" | "16px" | "20px" | "24px" | "28px" | "40px";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "8.6.3",
3
+ "version": "8.7.0",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -28,7 +28,7 @@
28
28
  ],
29
29
  "atlaskit:src": "src/index.ts",
30
30
  "dependencies": {
31
- "@atlaskit/adf-schema": "^51.5.0",
31
+ "@atlaskit/adf-schema": "^52.0.0",
32
32
  "@atlaskit/browser-apis": "^0.0.1",
33
33
  "@atlaskit/button": "^23.9.0",
34
34
  "@atlaskit/editor-plugin-accessibility-utils": "^7.0.0",
@@ -56,7 +56,7 @@
56
56
  "@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "^3.2.0",
57
57
  "@atlaskit/primitives": "^18.0.0",
58
58
  "@atlaskit/theme": "^21.0.0",
59
- "@atlaskit/tmp-editor-statsig": "^31.0.0",
59
+ "@atlaskit/tmp-editor-statsig": "^31.3.0",
60
60
  "@atlaskit/tokens": "^11.0.0",
61
61
  "@atlaskit/tooltip": "^20.14.0",
62
62
  "@babel/runtime": "^7.0.0",
@@ -144,6 +144,9 @@
144
144
  "platform_editor_table_sticky_header_patch_6": {
145
145
  "type": "boolean"
146
146
  },
147
+ "platform_editor_expose_block_controls_deco_api": {
148
+ "type": "boolean"
149
+ },
147
150
  "platform_editor_native_anchor_patch_1": {
148
151
  "type": "boolean"
149
152
  },