@atlaskit/editor-plugin-paste 6.2.0 → 6.4.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @atlaskit/editor-plugin-paste
2
2
 
3
+ ## 6.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`687c1b8fa7801`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/687c1b8fa7801) -
8
+ EDITOR-1566 bump adf-schema + update validator
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies
13
+
14
+ ## 6.3.0
15
+
16
+ ### Minor Changes
17
+
18
+ - [`26c7c41aa7f61`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/26c7c41aa7f61) -
19
+ [ux] DTR-3123: Apply link on Select-All when doc has single textblock (behind fg
20
+ platform_editor_link_paste_select_all)
21
+
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies
25
+
3
26
  ## 6.2.0
4
27
 
5
28
  ### Minor Changes
@@ -489,7 +489,7 @@ function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFlags, pl
489
489
 
490
490
  // Special handling for SharePoint URLs generated from Share button
491
491
  // eslint-disable-next-line @atlaskit/platform/no-preconditioning
492
- if ((0, _platformFeatureFlags.fg)('platform_editor_sharepoint_url_smart_card_fallback') && isSharePointUrl(text)) {
492
+ if (isSharePointUrl(text) && ((0, _platformFeatureFlags.fg)('platform_editor_sharepoint_url_smart_card_fallback') || (0, _platformFeatureFlags.fg)('platform_editor_sharepoint_url_smart_card_jira'))) {
493
493
  // Create an inline card directly for SharePoint URLs to show the "Connect" button
494
494
  var inlineCardNode = schema.nodes.inlineCard.create({
495
495
  url: text
@@ -41,6 +41,7 @@ var _model = require("@atlaskit/editor-prosemirror/model");
41
41
  var _state = require("@atlaskit/editor-prosemirror/state");
42
42
  var _utils2 = require("@atlaskit/editor-prosemirror/utils");
43
43
  var _utils3 = require("@atlaskit/editor-tables/utils");
44
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
44
45
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
45
46
  var _commands = require("../../editor-commands/commands");
46
47
  var _pluginFactory = require("../plugin-factory");
@@ -376,10 +377,64 @@ function handlePastePanelOrDecisionContentIntoList(slice, findRootParentListNode
376
377
  return true;
377
378
  };
378
379
  }
380
+ var innerTextRangeOfTextblock = function innerTextRangeOfTextblock(doc, posOfBlock) {
381
+ var block = doc.nodeAt(posOfBlock);
382
+ if (!block || !block.isTextblock) {
383
+ return null;
384
+ }
385
+
386
+ // raw content bounds
387
+ var contentStart = posOfBlock + 1; // +1 to move from node's start token to content start
388
+ var contentEnd = contentStart + block.content.size;
389
+
390
+ // clamp to doc coord space
391
+ var start = Math.max(0, Math.min(contentStart, doc.content.size));
392
+ var end = Math.max(0, Math.min(contentEnd, doc.content.size));
393
+ if (end <= start) {
394
+ return null;
395
+ }
396
+
397
+ // snap to nearest valid text positions
398
+ var startSel = _state.TextSelection.findFrom(doc.resolve(start), 1, true);
399
+ var endSel = _state.TextSelection.findFrom(doc.resolve(end), -1, true);
400
+ if (!startSel || !endSel) {
401
+ return null;
402
+ }
403
+ var from = startSel.$from.pos;
404
+ var to = endSel.$to.pos;
405
+ return to > from ? {
406
+ from: from,
407
+ to: to
408
+ } : null;
409
+ };
410
+ function resolveSingleTextblockRangeIfAllSelected(state) {
411
+ var sel = state.selection;
412
+ if (!(sel instanceof _state.AllSelection)) {
413
+ return null;
414
+ }
415
+ var count = 0;
416
+ var posOfBlock = -1;
417
+ state.doc.nodesBetween(sel.from, sel.to, function (node, pos) {
418
+ if (!node.isTextblock) {
419
+ return true;
420
+ }
421
+ count++;
422
+ if (count > 1) {
423
+ return false;
424
+ }
425
+ posOfBlock = pos;
426
+ return true;
427
+ });
428
+ if (count !== 1) {
429
+ return null;
430
+ }
431
+ return innerTextRangeOfTextblock(state.doc, posOfBlock);
432
+ }
379
433
 
380
434
  // If we paste a link onto some selected text, apply the link as a mark
381
435
  function handlePasteLinkOnSelectedText(slice) {
382
436
  return function (state, dispatch) {
437
+ var _selectAllRange$from, _selectAllRange$to;
383
438
  var schema = state.schema,
384
439
  selection = state.selection,
385
440
  _state$selection = state.selection,
@@ -409,9 +464,14 @@ function handlePasteLinkOnSelectedText(slice) {
409
464
  }
410
465
  }
411
466
 
467
+ // derive a linkable range if possible for Select‑All over a single textblock
468
+ var selectAllRange = (0, _platformFeatureFlags.fg)('platform_editor_link_paste_select_all') ? resolveSingleTextblockRangeIfAllSelected(state) : null;
469
+ var rangeFrom = (_selectAllRange$from = selectAllRange === null || selectAllRange === void 0 ? void 0 : selectAllRange.from) !== null && _selectAllRange$from !== void 0 ? _selectAllRange$from : from;
470
+ var rangeTo = (_selectAllRange$to = selectAllRange === null || selectAllRange === void 0 ? void 0 : selectAllRange.to) !== null && _selectAllRange$to !== void 0 ? _selectAllRange$to : to;
471
+
412
472
  // if we have a link, apply it to the selected text if we have any and it's allowed
413
- if (linkMark && selection instanceof _state.TextSelection && !selection.empty && (0, _utils.canLinkBeCreatedInRange)(from, to)(state)) {
414
- tr.addMark(from, to, linkMark);
473
+ if (linkMark && (selection instanceof _state.TextSelection || Boolean(selectAllRange)) && !selection.empty && (0, _utils.canLinkBeCreatedInRange)(rangeFrom, rangeTo)(state)) {
474
+ tr.addMark(rangeFrom, rangeTo, linkMark);
415
475
  if (dispatch) {
416
476
  dispatch(tr);
417
477
  }
@@ -452,7 +452,7 @@ export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFl
452
452
 
453
453
  // Special handling for SharePoint URLs generated from Share button
454
454
  // eslint-disable-next-line @atlaskit/platform/no-preconditioning
455
- if (fg('platform_editor_sharepoint_url_smart_card_fallback') && isSharePointUrl(text)) {
455
+ if (isSharePointUrl(text) && (fg('platform_editor_sharepoint_url_smart_card_fallback') || fg('platform_editor_sharepoint_url_smart_card_jira'))) {
456
456
  // Create an inline card directly for SharePoint URLs to show the "Connect" button
457
457
  const inlineCardNode = schema.nodes.inlineCard.create({
458
458
  url: text
@@ -7,9 +7,10 @@ import { GapCursorSelection, Side } from '@atlaskit/editor-common/selection';
7
7
  import { canLinkBeCreatedInRange, insideTableCell, isInListItem, isLinkMark, isListItemNode, isListNode, isNodeEmpty, isParagraph, isText, linkifyContent, mapSlice } from '@atlaskit/editor-common/utils';
8
8
  import { closeHistory } from '@atlaskit/editor-prosemirror/history';
9
9
  import { Fragment, Node as PMNode, Slice } from '@atlaskit/editor-prosemirror/model';
10
- import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
10
+ import { AllSelection, NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
11
11
  import { canInsert, contains, findParentNodeOfType, findParentNodeOfTypeClosestToPos, hasParentNode, hasParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
12
12
  import { replaceSelectedTable } from '@atlaskit/editor-tables/utils';
13
+ import { fg } from '@atlaskit/platform-feature-flags';
13
14
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
14
15
  // TODO: ED-20519 - Needs Macro extraction
15
16
 
@@ -360,10 +361,64 @@ export function handlePastePanelOrDecisionContentIntoList(slice, findRootParentL
360
361
  return true;
361
362
  };
362
363
  }
364
+ const innerTextRangeOfTextblock = (doc, posOfBlock) => {
365
+ const block = doc.nodeAt(posOfBlock);
366
+ if (!block || !block.isTextblock) {
367
+ return null;
368
+ }
369
+
370
+ // raw content bounds
371
+ const contentStart = posOfBlock + 1; // +1 to move from node's start token to content start
372
+ const contentEnd = contentStart + block.content.size;
373
+
374
+ // clamp to doc coord space
375
+ const start = Math.max(0, Math.min(contentStart, doc.content.size));
376
+ const end = Math.max(0, Math.min(contentEnd, doc.content.size));
377
+ if (end <= start) {
378
+ return null;
379
+ }
380
+
381
+ // snap to nearest valid text positions
382
+ const startSel = TextSelection.findFrom(doc.resolve(start), 1, true);
383
+ const endSel = TextSelection.findFrom(doc.resolve(end), -1, true);
384
+ if (!startSel || !endSel) {
385
+ return null;
386
+ }
387
+ const from = startSel.$from.pos;
388
+ const to = endSel.$to.pos;
389
+ return to > from ? {
390
+ from,
391
+ to
392
+ } : null;
393
+ };
394
+ function resolveSingleTextblockRangeIfAllSelected(state) {
395
+ const sel = state.selection;
396
+ if (!(sel instanceof AllSelection)) {
397
+ return null;
398
+ }
399
+ let count = 0;
400
+ let posOfBlock = -1;
401
+ state.doc.nodesBetween(sel.from, sel.to, (node, pos) => {
402
+ if (!node.isTextblock) {
403
+ return true;
404
+ }
405
+ count++;
406
+ if (count > 1) {
407
+ return false;
408
+ }
409
+ posOfBlock = pos;
410
+ return true;
411
+ });
412
+ if (count !== 1) {
413
+ return null;
414
+ }
415
+ return innerTextRangeOfTextblock(state.doc, posOfBlock);
416
+ }
363
417
 
364
418
  // If we paste a link onto some selected text, apply the link as a mark
365
419
  export function handlePasteLinkOnSelectedText(slice) {
366
420
  return (state, dispatch) => {
421
+ var _selectAllRange$from, _selectAllRange$to;
367
422
  const {
368
423
  schema,
369
424
  selection,
@@ -394,9 +449,14 @@ export function handlePasteLinkOnSelectedText(slice) {
394
449
  }
395
450
  }
396
451
 
452
+ // derive a linkable range if possible for Select‑All over a single textblock
453
+ const selectAllRange = fg('platform_editor_link_paste_select_all') ? resolveSingleTextblockRangeIfAllSelected(state) : null;
454
+ const rangeFrom = (_selectAllRange$from = selectAllRange === null || selectAllRange === void 0 ? void 0 : selectAllRange.from) !== null && _selectAllRange$from !== void 0 ? _selectAllRange$from : from;
455
+ const rangeTo = (_selectAllRange$to = selectAllRange === null || selectAllRange === void 0 ? void 0 : selectAllRange.to) !== null && _selectAllRange$to !== void 0 ? _selectAllRange$to : to;
456
+
397
457
  // if we have a link, apply it to the selected text if we have any and it's allowed
398
- if (linkMark && selection instanceof TextSelection && !selection.empty && canLinkBeCreatedInRange(from, to)(state)) {
399
- tr.addMark(from, to, linkMark);
458
+ if (linkMark && (selection instanceof TextSelection || Boolean(selectAllRange)) && !selection.empty && canLinkBeCreatedInRange(rangeFrom, rangeTo)(state)) {
459
+ tr.addMark(rangeFrom, rangeTo, linkMark);
400
460
  if (dispatch) {
401
461
  dispatch(tr);
402
462
  }
@@ -480,7 +480,7 @@ export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFl
480
480
 
481
481
  // Special handling for SharePoint URLs generated from Share button
482
482
  // eslint-disable-next-line @atlaskit/platform/no-preconditioning
483
- if (fg('platform_editor_sharepoint_url_smart_card_fallback') && isSharePointUrl(text)) {
483
+ if (isSharePointUrl(text) && (fg('platform_editor_sharepoint_url_smart_card_fallback') || fg('platform_editor_sharepoint_url_smart_card_jira'))) {
484
484
  // Create an inline card directly for SharePoint URLs to show the "Connect" button
485
485
  var inlineCardNode = schema.nodes.inlineCard.create({
486
486
  url: text
@@ -15,9 +15,10 @@ import { GapCursorSelection, Side } from '@atlaskit/editor-common/selection';
15
15
  import { canLinkBeCreatedInRange, insideTableCell, isInListItem, isLinkMark, isListItemNode, isListNode, isNodeEmpty, isParagraph, isText, linkifyContent, mapSlice } from '@atlaskit/editor-common/utils';
16
16
  import { closeHistory } from '@atlaskit/editor-prosemirror/history';
17
17
  import { Fragment, Node as PMNode, Slice } from '@atlaskit/editor-prosemirror/model';
18
- import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
18
+ import { AllSelection, NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
19
19
  import { canInsert, contains, findParentNodeOfType, findParentNodeOfTypeClosestToPos, hasParentNode, hasParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
20
20
  import { replaceSelectedTable } from '@atlaskit/editor-tables/utils';
21
+ import { fg } from '@atlaskit/platform-feature-flags';
21
22
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
22
23
  // TODO: ED-20519 - Needs Macro extraction
23
24
 
@@ -350,10 +351,64 @@ export function handlePastePanelOrDecisionContentIntoList(slice, findRootParentL
350
351
  return true;
351
352
  };
352
353
  }
354
+ var innerTextRangeOfTextblock = function innerTextRangeOfTextblock(doc, posOfBlock) {
355
+ var block = doc.nodeAt(posOfBlock);
356
+ if (!block || !block.isTextblock) {
357
+ return null;
358
+ }
359
+
360
+ // raw content bounds
361
+ var contentStart = posOfBlock + 1; // +1 to move from node's start token to content start
362
+ var contentEnd = contentStart + block.content.size;
363
+
364
+ // clamp to doc coord space
365
+ var start = Math.max(0, Math.min(contentStart, doc.content.size));
366
+ var end = Math.max(0, Math.min(contentEnd, doc.content.size));
367
+ if (end <= start) {
368
+ return null;
369
+ }
370
+
371
+ // snap to nearest valid text positions
372
+ var startSel = TextSelection.findFrom(doc.resolve(start), 1, true);
373
+ var endSel = TextSelection.findFrom(doc.resolve(end), -1, true);
374
+ if (!startSel || !endSel) {
375
+ return null;
376
+ }
377
+ var from = startSel.$from.pos;
378
+ var to = endSel.$to.pos;
379
+ return to > from ? {
380
+ from: from,
381
+ to: to
382
+ } : null;
383
+ };
384
+ function resolveSingleTextblockRangeIfAllSelected(state) {
385
+ var sel = state.selection;
386
+ if (!(sel instanceof AllSelection)) {
387
+ return null;
388
+ }
389
+ var count = 0;
390
+ var posOfBlock = -1;
391
+ state.doc.nodesBetween(sel.from, sel.to, function (node, pos) {
392
+ if (!node.isTextblock) {
393
+ return true;
394
+ }
395
+ count++;
396
+ if (count > 1) {
397
+ return false;
398
+ }
399
+ posOfBlock = pos;
400
+ return true;
401
+ });
402
+ if (count !== 1) {
403
+ return null;
404
+ }
405
+ return innerTextRangeOfTextblock(state.doc, posOfBlock);
406
+ }
353
407
 
354
408
  // If we paste a link onto some selected text, apply the link as a mark
355
409
  export function handlePasteLinkOnSelectedText(slice) {
356
410
  return function (state, dispatch) {
411
+ var _selectAllRange$from, _selectAllRange$to;
357
412
  var schema = state.schema,
358
413
  selection = state.selection,
359
414
  _state$selection = state.selection,
@@ -383,9 +438,14 @@ export function handlePasteLinkOnSelectedText(slice) {
383
438
  }
384
439
  }
385
440
 
441
+ // derive a linkable range if possible for Select‑All over a single textblock
442
+ var selectAllRange = fg('platform_editor_link_paste_select_all') ? resolveSingleTextblockRangeIfAllSelected(state) : null;
443
+ var rangeFrom = (_selectAllRange$from = selectAllRange === null || selectAllRange === void 0 ? void 0 : selectAllRange.from) !== null && _selectAllRange$from !== void 0 ? _selectAllRange$from : from;
444
+ var rangeTo = (_selectAllRange$to = selectAllRange === null || selectAllRange === void 0 ? void 0 : selectAllRange.to) !== null && _selectAllRange$to !== void 0 ? _selectAllRange$to : to;
445
+
386
446
  // if we have a link, apply it to the selected text if we have any and it's allowed
387
- if (linkMark && selection instanceof TextSelection && !selection.empty && canLinkBeCreatedInRange(from, to)(state)) {
388
- tr.addMark(from, to, linkMark);
447
+ if (linkMark && (selection instanceof TextSelection || Boolean(selectAllRange)) && !selection.empty && canLinkBeCreatedInRange(rangeFrom, rangeTo)(state)) {
448
+ tr.addMark(rangeFrom, rangeTo, linkMark);
389
449
  if (dispatch) {
390
450
  dispatch(tr);
391
451
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-paste",
3
- "version": "6.2.0",
3
+ "version": "6.4.0",
4
4
  "description": "Paste plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -27,38 +27,38 @@
27
27
  "sideEffects": false,
28
28
  "atlaskit:src": "src/index.ts",
29
29
  "dependencies": {
30
- "@atlaskit/adf-schema": "^51.1.2",
30
+ "@atlaskit/adf-schema": "^51.2.0",
31
31
  "@atlaskit/code": "^17.2.0",
32
- "@atlaskit/editor-markdown-transformer": "^5.18.0",
33
- "@atlaskit/editor-plugin-analytics": "^5.2.0",
34
- "@atlaskit/editor-plugin-annotation": "^5.3.0",
32
+ "@atlaskit/editor-markdown-transformer": "^5.19.0",
33
+ "@atlaskit/editor-plugin-analytics": "^5.3.0",
34
+ "@atlaskit/editor-plugin-annotation": "^5.6.0",
35
35
  "@atlaskit/editor-plugin-better-type-history": "^5.0.0",
36
- "@atlaskit/editor-plugin-card": "^10.1.0",
36
+ "@atlaskit/editor-plugin-card": "^10.2.0",
37
37
  "@atlaskit/editor-plugin-feature-flags": "^4.0.0",
38
- "@atlaskit/editor-plugin-list": "^7.2.0",
39
- "@atlaskit/editor-plugin-media": "^7.2.0",
40
- "@atlaskit/editor-plugin-mentions": "^7.2.0",
38
+ "@atlaskit/editor-plugin-list": "^7.3.0",
39
+ "@atlaskit/editor-plugin-media": "^7.3.0",
40
+ "@atlaskit/editor-plugin-mentions": "^7.3.0",
41
41
  "@atlaskit/editor-prosemirror": "7.0.0",
42
42
  "@atlaskit/editor-tables": "^2.9.0",
43
43
  "@atlaskit/insm": "^0.1.0",
44
44
  "@atlaskit/media-client": "^35.3.0",
45
45
  "@atlaskit/media-common": "^12.3.0",
46
46
  "@atlaskit/platform-feature-flags": "^1.1.0",
47
- "@atlaskit/tmp-editor-statsig": "^12.18.0",
47
+ "@atlaskit/tmp-editor-statsig": "^12.30.0",
48
48
  "@babel/runtime": "^7.0.0",
49
49
  "lodash": "^4.17.21",
50
50
  "uuid": "^3.1.0"
51
51
  },
52
52
  "peerDependencies": {
53
- "@atlaskit/editor-common": "^109.5.0",
53
+ "@atlaskit/editor-common": "^109.16.0",
54
54
  "react": "^18.2.0",
55
55
  "react-dom": "^18.2.0"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@af/visual-regression": "workspace:^",
59
- "@atlaskit/editor-plugin-block-type": "^8.2.0",
59
+ "@atlaskit/editor-plugin-block-type": "^8.3.0",
60
60
  "@atlaskit/editor-plugin-history": "^5.0.0",
61
- "@atlaskit/editor-plugin-type-ahead": "^5.2.0",
61
+ "@atlaskit/editor-plugin-type-ahead": "^5.3.0",
62
62
  "@atlaskit/ssr": "workspace:^",
63
63
  "@testing-library/react": "^13.4.0",
64
64
  "wait-for-expect": "^1.2.0"
@@ -117,6 +117,12 @@
117
117
  },
118
118
  "platform_editor_sharepoint_url_smart_card_fallback": {
119
119
  "type": "boolean"
120
+ },
121
+ "platform_editor_sharepoint_url_smart_card_jira": {
122
+ "type": "boolean"
123
+ },
124
+ "platform_editor_link_paste_select_all": {
125
+ "type": "boolean"
120
126
  }
121
127
  }
122
128
  }