@atlaskit/editor-plugin-paste-options-toolbar 11.0.16 → 11.0.18

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @atlaskit/editor-plugin-paste-options-toolbar
2
2
 
3
+ ## 11.0.18
4
+
5
+ ### Patch Changes
6
+
7
+ - [`ded95ac7efcc4`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ded95ac7efcc4) -
8
+ Persist code block wrap state in ADF, default code blocks created across editor runtime paths to
9
+ wrapped, and update the wrap toolbar tooltip behind platform_editor_code_block_q4_lovability.
10
+ - Updated dependencies
11
+
12
+ ## 11.0.17
13
+
14
+ ### Patch Changes
15
+
16
+ - [`aa02fe7d81d17`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/aa02fe7d81d17) -
17
+ Add V2 experiment exposure function for paste_actions_menu_v2_multivariate, wired into
18
+ usePluginHook behind platform_editor_paste_actions_menu_v2_gate
19
+ - Updated dependencies
20
+
3
21
  ## 11.0.16
4
22
 
5
23
  ### Patch Changes
@@ -13,6 +13,7 @@ var _commands = require("./editor-commands/commands");
13
13
  var _main = require("./pm-plugins/main");
14
14
  var _types = require("./types/types");
15
15
  var _exposure = require("./ui/on-paste-actions-menu/exposure");
16
+ var _exposureV = require("./ui/on-paste-actions-menu/exposure-v2");
16
17
  var _PasteActionsMenu = require("./ui/on-paste-actions-menu/PasteActionsMenu");
17
18
  var _PasteMenuComponents = require("./ui/on-paste-actions-menu/PasteMenuComponents");
18
19
  var _toolbar = require("./ui/toolbar");
@@ -109,6 +110,12 @@ var pasteOptionsToolbarPlugin = exports.pasteOptionsToolbarPlugin = function pas
109
110
  var _lastContentPasted$te, _lastContentPasted$te2;
110
111
  (0, _exposure.firePasteActionsMenuExperimentExposure)((_lastContentPasted$te = lastContentPasted === null || lastContentPasted === void 0 || (_lastContentPasted$te2 = lastContentPasted.text) === null || _lastContentPasted$te2 === void 0 ? void 0 : _lastContentPasted$te2.length) !== null && _lastContentPasted$te !== void 0 ? _lastContentPasted$te : 0, editorView.state, lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.pasteStartPos, lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.pasteEndPos, lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.text, lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.pastedSlice);
111
112
  }
113
+
114
+ // These two need to be seperate to prevent them being dependant on each other
115
+ if (config !== null && config !== void 0 && config.usePopupBasedPasteActionsMenu && (0, _platformFeatureFlags.fg)('platform_editor_paste_actions_menu_v2_exposure')) {
116
+ var _lastContentPasted$te3, _lastContentPasted$te4;
117
+ (0, _exposureV.firePasteActionsMenuV2ExperimentExposure)((_lastContentPasted$te3 = lastContentPasted === null || lastContentPasted === void 0 || (_lastContentPasted$te4 = lastContentPasted.text) === null || _lastContentPasted$te4 === void 0 ? void 0 : _lastContentPasted$te4.length) !== null && _lastContentPasted$te3 !== void 0 ? _lastContentPasted$te3 : 0, editorView.state, lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.pasteStartPos, lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.pasteEndPos, lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.text, lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.pastedSlice);
118
+ }
112
119
  if (config !== null && config !== void 0 && config.usePopupBasedPasteActionsMenu && (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_paste_actions_menu', 'isEnabled', true)) {
113
120
  return;
114
121
  }
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.formatRichText = exports.formatPlainText = exports.formatMarkdown = void 0;
7
7
  exports.getMarkdownSlice = getMarkdownSlice;
8
+ var _codeBlock = require("@atlaskit/editor-common/code-block");
8
9
  var _monitoring = require("@atlaskit/editor-common/monitoring");
9
10
  var _paste = require("@atlaskit/editor-common/paste");
10
11
  var _editorMarkdownTransformer = require("@atlaskit/editor-markdown-transformer");
@@ -173,7 +174,7 @@ function getMarkdownSlice(text, schema, selection) {
173
174
  var $end = _state.Selection.atEnd(doc).$from;
174
175
  var openStart = canMergeOpenStart ? $start.depth : 0;
175
176
  var openEnd = canMergeOpenEnd ? $end.depth : 0;
176
- return new _model.Slice(doc.content, openStart, openEnd);
177
+ return (0, _codeBlock.defaultWrapForMarkdownCodeBlocksInSlice)(new _model.Slice(doc.content, openStart, openEnd), schema);
177
178
  } catch (error) {
178
179
  (0, _monitoring.logException)(error, {
179
180
  location: 'editor-plugin-paste-options-toolbar/util'
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.firePasteActionsMenuV2ExperimentExposure = void 0;
7
+ var _expVal = require("@atlaskit/tmp-editor-statsig/expVal");
8
+ // Remove this file when experiment 'platform_editor_paste_actions_menu_v2' is cleaned up.
9
+
10
+ var hasTableNode = function hasTableNode(slice) {
11
+ if (!slice) {
12
+ return false;
13
+ }
14
+ var found = false;
15
+ slice.content.descendants(function (node) {
16
+ if (node.type.name === 'table') {
17
+ found = true;
18
+ return false;
19
+ }
20
+ return true;
21
+ });
22
+ return found;
23
+ };
24
+ var isNotProse = function isNotProse(text) {
25
+ var trimmed = text.trim();
26
+ if (!trimmed) {
27
+ return false;
28
+ }
29
+ for (var i = 0; i < trimmed.length; i++) {
30
+ var code = trimmed.charCodeAt(i);
31
+ if (code === 0x20 || code === 0x09 || code === 0x0a || code === 0x0d) {
32
+ return false;
33
+ }
34
+ if (code > 0x7f) {
35
+ return false;
36
+ }
37
+ }
38
+ return true;
39
+ };
40
+ var firePasteActionsMenuV2ExperimentExposure = exports.firePasteActionsMenuV2ExperimentExposure = function firePasteActionsMenuV2ExperimentExposure(contentLength, state, pasteStartPos, pasteEndPos, pastedText, pastedSlice) {
41
+ if (contentLength < 100 || !pasteStartPos || !pasteEndPos || !pastedText) {
42
+ return;
43
+ }
44
+ if (isNotProse(pastedText)) {
45
+ return;
46
+ }
47
+ if (hasTableNode(pastedSlice)) {
48
+ return;
49
+ }
50
+ try {
51
+ var $pos = state.doc.resolve(pasteStartPos);
52
+ var pasteAncestorNodeNames = [];
53
+ for (var depth = $pos.depth; depth > 0; depth--) {
54
+ if (pasteEndPos <= $pos.end(depth)) {
55
+ pasteAncestorNodeNames.push($pos.node(depth).type.name);
56
+ }
57
+ }
58
+ var isInExcludedNode = pasteAncestorNodeNames.some(function (name) {
59
+ return ['codeBlock', 'heading'].includes(name);
60
+ });
61
+ if (!isInExcludedNode) {
62
+ (0, _expVal.expVal)('platform_editor_paste_actions_menu_v2', 'variant', 'control');
63
+ }
64
+ } catch (_unused) {
65
+ return;
66
+ }
67
+ };
@@ -6,6 +6,7 @@ import { hideToolbar, showToolbar } from './editor-commands/commands';
6
6
  import { createPlugin } from './pm-plugins/main';
7
7
  import { pasteOptionsPluginKey, ToolbarDropdownOption } from './types/types';
8
8
  import { firePasteActionsMenuExperimentExposure } from './ui/on-paste-actions-menu/exposure';
9
+ import { firePasteActionsMenuV2ExperimentExposure } from './ui/on-paste-actions-menu/exposure-v2';
9
10
  import { PasteActionsMenu } from './ui/on-paste-actions-menu/PasteActionsMenu';
10
11
  import { getPasteMenuComponents } from './ui/on-paste-actions-menu/PasteMenuComponents';
11
12
  import { buildToolbar, isToolbarVisible } from './ui/toolbar';
@@ -104,6 +105,12 @@ export const pasteOptionsToolbarPlugin = ({
104
105
  var _lastContentPasted$te, _lastContentPasted$te2;
105
106
  firePasteActionsMenuExperimentExposure((_lastContentPasted$te = lastContentPasted === null || lastContentPasted === void 0 ? void 0 : (_lastContentPasted$te2 = lastContentPasted.text) === null || _lastContentPasted$te2 === void 0 ? void 0 : _lastContentPasted$te2.length) !== null && _lastContentPasted$te !== void 0 ? _lastContentPasted$te : 0, editorView.state, lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.pasteStartPos, lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.pasteEndPos, lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.text, lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.pastedSlice);
106
107
  }
108
+
109
+ // These two need to be seperate to prevent them being dependant on each other
110
+ if (config !== null && config !== void 0 && config.usePopupBasedPasteActionsMenu && fg('platform_editor_paste_actions_menu_v2_exposure')) {
111
+ var _lastContentPasted$te3, _lastContentPasted$te4;
112
+ firePasteActionsMenuV2ExperimentExposure((_lastContentPasted$te3 = lastContentPasted === null || lastContentPasted === void 0 ? void 0 : (_lastContentPasted$te4 = lastContentPasted.text) === null || _lastContentPasted$te4 === void 0 ? void 0 : _lastContentPasted$te4.length) !== null && _lastContentPasted$te3 !== void 0 ? _lastContentPasted$te3 : 0, editorView.state, lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.pasteStartPos, lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.pasteEndPos, lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.text, lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.pastedSlice);
113
+ }
107
114
  if (config !== null && config !== void 0 && config.usePopupBasedPasteActionsMenu && expValEqualsNoExposure('platform_editor_paste_actions_menu', 'isEnabled', true)) {
108
115
  return;
109
116
  }
@@ -1,3 +1,4 @@
1
+ import { defaultWrapForMarkdownCodeBlocksInSlice } from '@atlaskit/editor-common/code-block';
1
2
  import { logException } from '@atlaskit/editor-common/monitoring';
2
3
  import { md } from '@atlaskit/editor-common/paste';
3
4
  import { MarkdownTransformer } from '@atlaskit/editor-markdown-transformer';
@@ -168,7 +169,7 @@ export function getMarkdownSlice(text, schema, selection) {
168
169
  const $end = Selection.atEnd(doc).$from;
169
170
  const openStart = canMergeOpenStart ? $start.depth : 0;
170
171
  const openEnd = canMergeOpenEnd ? $end.depth : 0;
171
- return new Slice(doc.content, openStart, openEnd);
172
+ return defaultWrapForMarkdownCodeBlocksInSlice(new Slice(doc.content, openStart, openEnd), schema);
172
173
  } catch (error) {
173
174
  logException(error, {
174
175
  location: 'editor-plugin-paste-options-toolbar/util'
@@ -0,0 +1,59 @@
1
+ // Remove this file when experiment 'platform_editor_paste_actions_menu_v2' is cleaned up.
2
+
3
+ import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
4
+ const hasTableNode = slice => {
5
+ if (!slice) {
6
+ return false;
7
+ }
8
+ let found = false;
9
+ slice.content.descendants(node => {
10
+ if (node.type.name === 'table') {
11
+ found = true;
12
+ return false;
13
+ }
14
+ return true;
15
+ });
16
+ return found;
17
+ };
18
+ const isNotProse = text => {
19
+ const trimmed = text.trim();
20
+ if (!trimmed) {
21
+ return false;
22
+ }
23
+ for (let i = 0; i < trimmed.length; i++) {
24
+ const code = trimmed.charCodeAt(i);
25
+ if (code === 0x20 || code === 0x09 || code === 0x0a || code === 0x0d) {
26
+ return false;
27
+ }
28
+ if (code > 0x7f) {
29
+ return false;
30
+ }
31
+ }
32
+ return true;
33
+ };
34
+ export const firePasteActionsMenuV2ExperimentExposure = (contentLength, state, pasteStartPos, pasteEndPos, pastedText, pastedSlice) => {
35
+ if (contentLength < 100 || !pasteStartPos || !pasteEndPos || !pastedText) {
36
+ return;
37
+ }
38
+ if (isNotProse(pastedText)) {
39
+ return;
40
+ }
41
+ if (hasTableNode(pastedSlice)) {
42
+ return;
43
+ }
44
+ try {
45
+ const $pos = state.doc.resolve(pasteStartPos);
46
+ const pasteAncestorNodeNames = [];
47
+ for (let depth = $pos.depth; depth > 0; depth--) {
48
+ if (pasteEndPos <= $pos.end(depth)) {
49
+ pasteAncestorNodeNames.push($pos.node(depth).type.name);
50
+ }
51
+ }
52
+ const isInExcludedNode = pasteAncestorNodeNames.some(name => ['codeBlock', 'heading'].includes(name));
53
+ if (!isInExcludedNode) {
54
+ expVal('platform_editor_paste_actions_menu_v2', 'variant', 'control');
55
+ }
56
+ } catch {
57
+ return;
58
+ }
59
+ };
@@ -6,6 +6,7 @@ import { hideToolbar, showToolbar } from './editor-commands/commands';
6
6
  import { createPlugin } from './pm-plugins/main';
7
7
  import { pasteOptionsPluginKey, ToolbarDropdownOption } from './types/types';
8
8
  import { firePasteActionsMenuExperimentExposure } from './ui/on-paste-actions-menu/exposure';
9
+ import { firePasteActionsMenuV2ExperimentExposure } from './ui/on-paste-actions-menu/exposure-v2';
9
10
  import { PasteActionsMenu } from './ui/on-paste-actions-menu/PasteActionsMenu';
10
11
  import { getPasteMenuComponents } from './ui/on-paste-actions-menu/PasteMenuComponents';
11
12
  import { buildToolbar, isToolbarVisible } from './ui/toolbar';
@@ -101,6 +102,12 @@ export var pasteOptionsToolbarPlugin = function pasteOptionsToolbarPlugin(_ref)
101
102
  var _lastContentPasted$te, _lastContentPasted$te2;
102
103
  firePasteActionsMenuExperimentExposure((_lastContentPasted$te = lastContentPasted === null || lastContentPasted === void 0 || (_lastContentPasted$te2 = lastContentPasted.text) === null || _lastContentPasted$te2 === void 0 ? void 0 : _lastContentPasted$te2.length) !== null && _lastContentPasted$te !== void 0 ? _lastContentPasted$te : 0, editorView.state, lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.pasteStartPos, lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.pasteEndPos, lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.text, lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.pastedSlice);
103
104
  }
105
+
106
+ // These two need to be seperate to prevent them being dependant on each other
107
+ if (config !== null && config !== void 0 && config.usePopupBasedPasteActionsMenu && fg('platform_editor_paste_actions_menu_v2_exposure')) {
108
+ var _lastContentPasted$te3, _lastContentPasted$te4;
109
+ firePasteActionsMenuV2ExperimentExposure((_lastContentPasted$te3 = lastContentPasted === null || lastContentPasted === void 0 || (_lastContentPasted$te4 = lastContentPasted.text) === null || _lastContentPasted$te4 === void 0 ? void 0 : _lastContentPasted$te4.length) !== null && _lastContentPasted$te3 !== void 0 ? _lastContentPasted$te3 : 0, editorView.state, lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.pasteStartPos, lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.pasteEndPos, lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.text, lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.pastedSlice);
110
+ }
104
111
  if (config !== null && config !== void 0 && config.usePopupBasedPasteActionsMenu && expValEqualsNoExposure('platform_editor_paste_actions_menu', 'isEnabled', true)) {
105
112
  return;
106
113
  }
@@ -1,3 +1,4 @@
1
+ import { defaultWrapForMarkdownCodeBlocksInSlice } from '@atlaskit/editor-common/code-block';
1
2
  import { logException } from '@atlaskit/editor-common/monitoring';
2
3
  import { md } from '@atlaskit/editor-common/paste';
3
4
  import { MarkdownTransformer } from '@atlaskit/editor-markdown-transformer';
@@ -166,7 +167,7 @@ export function getMarkdownSlice(text, schema, selection) {
166
167
  var $end = Selection.atEnd(doc).$from;
167
168
  var openStart = canMergeOpenStart ? $start.depth : 0;
168
169
  var openEnd = canMergeOpenEnd ? $end.depth : 0;
169
- return new Slice(doc.content, openStart, openEnd);
170
+ return defaultWrapForMarkdownCodeBlocksInSlice(new Slice(doc.content, openStart, openEnd), schema);
170
171
  } catch (error) {
171
172
  logException(error, {
172
173
  location: 'editor-plugin-paste-options-toolbar/util'
@@ -0,0 +1,61 @@
1
+ // Remove this file when experiment 'platform_editor_paste_actions_menu_v2' is cleaned up.
2
+
3
+ import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
4
+ var hasTableNode = function hasTableNode(slice) {
5
+ if (!slice) {
6
+ return false;
7
+ }
8
+ var found = false;
9
+ slice.content.descendants(function (node) {
10
+ if (node.type.name === 'table') {
11
+ found = true;
12
+ return false;
13
+ }
14
+ return true;
15
+ });
16
+ return found;
17
+ };
18
+ var isNotProse = function isNotProse(text) {
19
+ var trimmed = text.trim();
20
+ if (!trimmed) {
21
+ return false;
22
+ }
23
+ for (var i = 0; i < trimmed.length; i++) {
24
+ var code = trimmed.charCodeAt(i);
25
+ if (code === 0x20 || code === 0x09 || code === 0x0a || code === 0x0d) {
26
+ return false;
27
+ }
28
+ if (code > 0x7f) {
29
+ return false;
30
+ }
31
+ }
32
+ return true;
33
+ };
34
+ export var firePasteActionsMenuV2ExperimentExposure = function firePasteActionsMenuV2ExperimentExposure(contentLength, state, pasteStartPos, pasteEndPos, pastedText, pastedSlice) {
35
+ if (contentLength < 100 || !pasteStartPos || !pasteEndPos || !pastedText) {
36
+ return;
37
+ }
38
+ if (isNotProse(pastedText)) {
39
+ return;
40
+ }
41
+ if (hasTableNode(pastedSlice)) {
42
+ return;
43
+ }
44
+ try {
45
+ var $pos = state.doc.resolve(pasteStartPos);
46
+ var pasteAncestorNodeNames = [];
47
+ for (var depth = $pos.depth; depth > 0; depth--) {
48
+ if (pasteEndPos <= $pos.end(depth)) {
49
+ pasteAncestorNodeNames.push($pos.node(depth).type.name);
50
+ }
51
+ }
52
+ var isInExcludedNode = pasteAncestorNodeNames.some(function (name) {
53
+ return ['codeBlock', 'heading'].includes(name);
54
+ });
55
+ if (!isInExcludedNode) {
56
+ expVal('platform_editor_paste_actions_menu_v2', 'variant', 'control');
57
+ }
58
+ } catch (_unused) {
59
+ return;
60
+ }
61
+ };
@@ -0,0 +1,3 @@
1
+ import type { Slice } from '@atlaskit/editor-prosemirror/model';
2
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
3
+ export declare const firePasteActionsMenuV2ExperimentExposure: (contentLength: number, state: EditorState, pasteStartPos?: number, pasteEndPos?: number, pastedText?: string, pastedSlice?: Slice) => void;
@@ -0,0 +1,3 @@
1
+ import type { Slice } from '@atlaskit/editor-prosemirror/model';
2
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
3
+ export declare const firePasteActionsMenuV2ExperimentExposure: (contentLength: number, state: EditorState, pasteStartPos?: number, pasteEndPos?: number, pastedText?: string, pastedSlice?: Slice) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-paste-options-toolbar",
3
- "version": "11.0.16",
3
+ "version": "11.0.18",
4
4
  "description": "Paste options toolbar for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -42,14 +42,14 @@
42
42
  "@atlaskit/icon": "^34.4.0",
43
43
  "@atlaskit/platform-feature-flags": "^1.1.0",
44
44
  "@atlaskit/primitives": "^19.0.0",
45
- "@atlaskit/tmp-editor-statsig": "^77.0.0",
45
+ "@atlaskit/tmp-editor-statsig": "^77.2.0",
46
46
  "@atlaskit/tokens": "^13.0.0",
47
47
  "@babel/runtime": "^7.0.0",
48
48
  "@compiled/react": "^0.20.0",
49
49
  "@emotion/react": "^11.7.1"
50
50
  },
51
51
  "peerDependencies": {
52
- "@atlaskit/editor-common": "^114.20.0",
52
+ "@atlaskit/editor-common": "^114.25.0",
53
53
  "react": "^18.2.0",
54
54
  "react-dom": "^18.2.0",
55
55
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
@@ -65,6 +65,9 @@
65
65
  },
66
66
  "platform_editor_paste_actions_menu_exposure": {
67
67
  "type": "boolean"
68
+ },
69
+ "platform_editor_paste_actions_menu_v2_exposure": {
70
+ "type": "boolean"
68
71
  }
69
72
  },
70
73
  "techstack": {