@atlaskit/renderer 109.14.0 → 109.15.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,18 @@
1
1
  # @atlaskit/renderer
2
2
 
3
+ ## 109.15.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#87820](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/87820) [`120f76a32bf9`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/120f76a32bf9) - [ED-22819]
8
+
9
+ - Update ApplyAnnotation to return `step` of type AddNodeMarkStep for annotation on media and correct `doc` that includes newly add annotation mark
10
+ - Make media node read in data attributes so that it shows data-renderer-start-pos
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies
15
+
3
16
  ## 109.14.0
4
17
 
5
18
  ### Minor Changes
@@ -226,11 +226,24 @@ var RendererActions = exports.default = /*#__PURE__*/function () {
226
226
  to = pos.to;
227
227
  var annotationId = annotation.annotationId,
228
228
  annotationType = annotation.annotationType;
229
- var step = (0, _steps.createAnnotationStep)(from, to, {
230
- annotationId: annotationId,
231
- annotationType: annotationType,
232
- schema: this.schema
233
- });
229
+ var step;
230
+
231
+ // If from points to a node position,
232
+ // we need to 1 position before it for nodeAt to return the node itself
233
+ var beforeNodePos = Math.max(from - 1, 0);
234
+ var possibleNode = this.doc.nodeAt(beforeNodePos);
235
+ if ((possibleNode === null || possibleNode === void 0 ? void 0 : possibleNode.type.name) === 'media') {
236
+ step = new _transform.AddNodeMarkStep(beforeNodePos, this.schema.marks.annotation.create({
237
+ id: annotationId,
238
+ type: annotationType
239
+ }));
240
+ } else {
241
+ step = (0, _steps.createAnnotationStep)(from, to, {
242
+ annotationId: annotationId,
243
+ annotationType: annotationType,
244
+ schema: this.schema
245
+ });
246
+ }
234
247
  var _step$apply2 = step.apply(this.doc),
235
248
  doc = _step$apply2.doc,
236
249
  failed = _step$apply2.failed;
@@ -411,7 +411,7 @@ var ReactSerializer = exports.default = /*#__PURE__*/function () {
411
411
  var isBorderMark = function isBorderMark(mark) {
412
412
  return isChildOfMediaSingle && mark.type === border;
413
413
  };
414
- return _objectSpread(_objectSpread({}, this.getProps(node)), {}, {
414
+ return _objectSpread(_objectSpread({}, this.getProps(node, path)), {}, {
415
415
  marks: node.marks.filter(function (m) {
416
416
  return !isLinkMark(m) || _this6.allowMediaLinking === true;
417
417
  }),
@@ -10,6 +10,9 @@ var _transform = require("@atlaskit/editor-prosemirror/transform");
10
10
  function getStartPos(element) {
11
11
  return parseInt(element.dataset.rendererStartPos || '-1', 10);
12
12
  }
13
+ var getNodeType = function getNodeType(element) {
14
+ return element.dataset.nodeType;
15
+ };
13
16
  function isPositionPointer(element) {
14
17
  return getStartPos(element) > -1;
15
18
  }
@@ -114,6 +117,14 @@ function getPosFromRange(range) {
114
117
  startOffset = range.startOffset,
115
118
  endContainer = range.endContainer,
116
119
  endOffset = range.endOffset;
120
+ var parent = findParent(startContainer);
121
+ if (parent && getNodeType(parent) === 'media') {
122
+ var pos = getStartPos(parent);
123
+ return {
124
+ from: pos,
125
+ to: pos
126
+ };
127
+ }
117
128
  var from = resolvePos(startContainer, startOffset);
118
129
  var to = resolvePos(endContainer, endOffset);
119
130
  if (from === false || to === false) {
@@ -269,7 +269,8 @@ var MediaCardView = exports.MediaCardView = /*#__PURE__*/function (_Component) {
269
269
  shouldEnableDownloadButton = _this$props5.shouldEnableDownloadButton,
270
270
  ssr = _this$props5.ssr,
271
271
  mediaClient = _this$props5.mediaClient,
272
- setHoverTarget = _this$props5.setHoverTarget;
272
+ setHoverTarget = _this$props5.setHoverTarget,
273
+ dataAttributes = _this$props5.dataAttributes;
273
274
  var isMobile = rendererAppearance === 'mobile';
274
275
  var shouldPlayInline = useInlinePlayer !== undefined ? useInlinePlayer : true;
275
276
  var isInlinePlayer = isMobile ? false : shouldPlayInline;
@@ -304,7 +305,7 @@ var MediaCardView = exports.MediaCardView = /*#__PURE__*/function (_Component) {
304
305
  contextIdentifierProvider: contextIdentifierProvider,
305
306
  originalDimensions: originalDimensions,
306
307
  fileState: fileState
307
- }), {
308
+ }), dataAttributes, {
308
309
  onMouseEnter: function onMouseEnter(event) {
309
310
  // We will not allow a hover target to be set if any mouse button is depressed during the mouse enter state.
310
311
  // This could be due to the user trying to select text across the document.
@@ -55,7 +55,7 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
55
55
  var NORMAL_SEVERITY_THRESHOLD = exports.NORMAL_SEVERITY_THRESHOLD = 2000;
56
56
  var DEGRADED_SEVERITY_THRESHOLD = exports.DEGRADED_SEVERITY_THRESHOLD = 3000;
57
57
  var packageName = "@atlaskit/renderer";
58
- var packageVersion = "109.14.0";
58
+ var packageVersion = "109.15.0";
59
59
  var Renderer = exports.Renderer = /*#__PURE__*/function (_PureComponent) {
60
60
  (0, _inherits2.default)(Renderer, _PureComponent);
61
61
  var _super = _createSuper(Renderer);
@@ -2,7 +2,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import { JSONTransformer } from '@atlaskit/editor-json-transformer';
3
3
  import { canApplyAnnotationOnRange, getAnnotationIdsFromRange } from '@atlaskit/editor-common/utils';
4
4
  import { AnnotationTypes } from '@atlaskit/adf-schema';
5
- import { RemoveMarkStep, RemoveNodeMarkStep } from '@atlaskit/editor-prosemirror/transform';
5
+ import { AddNodeMarkStep, RemoveMarkStep, RemoveNodeMarkStep } from '@atlaskit/editor-prosemirror/transform';
6
6
  import { createAnnotationStep, getPosFromRange } from '../steps';
7
7
  import { ACTION, ACTION_SUBJECT, EVENT_TYPE, ACTION_SUBJECT_ID } from '@atlaskit/editor-common/analytics';
8
8
  import { getIndexMatch } from './matches-utils';
@@ -204,11 +204,24 @@ export default class RendererActions {
204
204
  annotationId,
205
205
  annotationType
206
206
  } = annotation;
207
- const step = createAnnotationStep(from, to, {
208
- annotationId,
209
- annotationType,
210
- schema: this.schema
211
- });
207
+ let step;
208
+
209
+ // If from points to a node position,
210
+ // we need to 1 position before it for nodeAt to return the node itself
211
+ const beforeNodePos = Math.max(from - 1, 0);
212
+ const possibleNode = this.doc.nodeAt(beforeNodePos);
213
+ if ((possibleNode === null || possibleNode === void 0 ? void 0 : possibleNode.type.name) === 'media') {
214
+ step = new AddNodeMarkStep(beforeNodePos, this.schema.marks.annotation.create({
215
+ id: annotationId,
216
+ type: annotationType
217
+ }));
218
+ } else {
219
+ step = createAnnotationStep(from, to, {
220
+ annotationId,
221
+ annotationType,
222
+ schema: this.schema
223
+ });
224
+ }
212
225
  const {
213
226
  doc,
214
227
  failed
@@ -361,7 +361,7 @@ export default class ReactSerializer {
361
361
  const isLinkMark = mark => mark.type === link;
362
362
  const isBorderMark = mark => isChildOfMediaSingle && mark.type === border;
363
363
  return {
364
- ...this.getProps(node),
364
+ ...this.getProps(node, path),
365
365
  marks: node.marks.filter(m => !isLinkMark(m) || this.allowMediaLinking === true),
366
366
  isLinkMark,
367
367
  isBorderMark,
@@ -2,6 +2,7 @@ import { AddMarkStep } from '@atlaskit/editor-prosemirror/transform';
2
2
  function getStartPos(element) {
3
3
  return parseInt(element.dataset.rendererStartPos || '-1', 10);
4
4
  }
5
+ const getNodeType = element => element.dataset.nodeType;
5
6
  function isPositionPointer(element) {
6
7
  return getStartPos(element) > -1;
7
8
  }
@@ -112,6 +113,14 @@ export function getPosFromRange(range) {
112
113
  endContainer,
113
114
  endOffset
114
115
  } = range;
116
+ const parent = findParent(startContainer);
117
+ if (parent && getNodeType(parent) === 'media') {
118
+ const pos = getStartPos(parent);
119
+ return {
120
+ from: pos,
121
+ to: pos
122
+ };
123
+ }
115
124
  const from = resolvePos(startContainer, startOffset);
116
125
  const to = resolvePos(endContainer, endOffset);
117
126
  if (from === false || to === false) {
@@ -201,7 +201,8 @@ export class MediaCardView extends Component {
201
201
  shouldEnableDownloadButton,
202
202
  ssr,
203
203
  mediaClient,
204
- setHoverTarget
204
+ setHoverTarget,
205
+ dataAttributes
205
206
  } = this.props;
206
207
  const isMobile = rendererAppearance === 'mobile';
207
208
  const shouldPlayInline = useInlinePlayer !== undefined ? useInlinePlayer : true;
@@ -237,7 +238,7 @@ export class MediaCardView extends Component {
237
238
  contextIdentifierProvider,
238
239
  originalDimensions,
239
240
  fileState
240
- }), {
241
+ }), dataAttributes, {
241
242
  onMouseEnter: event => {
242
243
  // We will not allow a hover target to be set if any mouse button is depressed during the mouse enter state.
243
244
  // This could be due to the user trying to select text across the document.
@@ -36,7 +36,7 @@ import { EditorMediaClientProvider } from '../../react/utils/EditorMediaClientPr
36
36
  export const NORMAL_SEVERITY_THRESHOLD = 2000;
37
37
  export const DEGRADED_SEVERITY_THRESHOLD = 3000;
38
38
  const packageName = "@atlaskit/renderer";
39
- const packageVersion = "109.14.0";
39
+ const packageVersion = "109.15.0";
40
40
  export class Renderer extends PureComponent {
41
41
  constructor(props) {
42
42
  super(props);
@@ -5,7 +5,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
5
5
  import { JSONTransformer } from '@atlaskit/editor-json-transformer';
6
6
  import { canApplyAnnotationOnRange, getAnnotationIdsFromRange } from '@atlaskit/editor-common/utils';
7
7
  import { AnnotationTypes } from '@atlaskit/adf-schema';
8
- import { RemoveMarkStep, RemoveNodeMarkStep } from '@atlaskit/editor-prosemirror/transform';
8
+ import { AddNodeMarkStep, RemoveMarkStep, RemoveNodeMarkStep } from '@atlaskit/editor-prosemirror/transform';
9
9
  import { createAnnotationStep, getPosFromRange } from '../steps';
10
10
  import { ACTION, ACTION_SUBJECT, EVENT_TYPE, ACTION_SUBJECT_ID } from '@atlaskit/editor-common/analytics';
11
11
  import { getIndexMatch } from './matches-utils';
@@ -219,11 +219,24 @@ var RendererActions = /*#__PURE__*/function () {
219
219
  to = pos.to;
220
220
  var annotationId = annotation.annotationId,
221
221
  annotationType = annotation.annotationType;
222
- var step = createAnnotationStep(from, to, {
223
- annotationId: annotationId,
224
- annotationType: annotationType,
225
- schema: this.schema
226
- });
222
+ var step;
223
+
224
+ // If from points to a node position,
225
+ // we need to 1 position before it for nodeAt to return the node itself
226
+ var beforeNodePos = Math.max(from - 1, 0);
227
+ var possibleNode = this.doc.nodeAt(beforeNodePos);
228
+ if ((possibleNode === null || possibleNode === void 0 ? void 0 : possibleNode.type.name) === 'media') {
229
+ step = new AddNodeMarkStep(beforeNodePos, this.schema.marks.annotation.create({
230
+ id: annotationId,
231
+ type: annotationType
232
+ }));
233
+ } else {
234
+ step = createAnnotationStep(from, to, {
235
+ annotationId: annotationId,
236
+ annotationType: annotationType,
237
+ schema: this.schema
238
+ });
239
+ }
227
240
  var _step$apply2 = step.apply(this.doc),
228
241
  doc = _step$apply2.doc,
229
242
  failed = _step$apply2.failed;
@@ -404,7 +404,7 @@ var ReactSerializer = /*#__PURE__*/function () {
404
404
  var isBorderMark = function isBorderMark(mark) {
405
405
  return isChildOfMediaSingle && mark.type === border;
406
406
  };
407
- return _objectSpread(_objectSpread({}, this.getProps(node)), {}, {
407
+ return _objectSpread(_objectSpread({}, this.getProps(node, path)), {}, {
408
408
  marks: node.marks.filter(function (m) {
409
409
  return !isLinkMark(m) || _this6.allowMediaLinking === true;
410
410
  }),
@@ -2,6 +2,9 @@ import { AddMarkStep } from '@atlaskit/editor-prosemirror/transform';
2
2
  function getStartPos(element) {
3
3
  return parseInt(element.dataset.rendererStartPos || '-1', 10);
4
4
  }
5
+ var getNodeType = function getNodeType(element) {
6
+ return element.dataset.nodeType;
7
+ };
5
8
  function isPositionPointer(element) {
6
9
  return getStartPos(element) > -1;
7
10
  }
@@ -106,6 +109,14 @@ export function getPosFromRange(range) {
106
109
  startOffset = range.startOffset,
107
110
  endContainer = range.endContainer,
108
111
  endOffset = range.endOffset;
112
+ var parent = findParent(startContainer);
113
+ if (parent && getNodeType(parent) === 'media') {
114
+ var pos = getStartPos(parent);
115
+ return {
116
+ from: pos,
117
+ to: pos
118
+ };
119
+ }
109
120
  var from = resolvePos(startContainer, startOffset);
110
121
  var to = resolvePos(endContainer, endOffset);
111
122
  if (from === false || to === false) {
@@ -259,7 +259,8 @@ export var MediaCardView = /*#__PURE__*/function (_Component) {
259
259
  shouldEnableDownloadButton = _this$props5.shouldEnableDownloadButton,
260
260
  ssr = _this$props5.ssr,
261
261
  mediaClient = _this$props5.mediaClient,
262
- setHoverTarget = _this$props5.setHoverTarget;
262
+ setHoverTarget = _this$props5.setHoverTarget,
263
+ dataAttributes = _this$props5.dataAttributes;
263
264
  var isMobile = rendererAppearance === 'mobile';
264
265
  var shouldPlayInline = useInlinePlayer !== undefined ? useInlinePlayer : true;
265
266
  var isInlinePlayer = isMobile ? false : shouldPlayInline;
@@ -294,7 +295,7 @@ export var MediaCardView = /*#__PURE__*/function (_Component) {
294
295
  contextIdentifierProvider: contextIdentifierProvider,
295
296
  originalDimensions: originalDimensions,
296
297
  fileState: fileState
297
- }), {
298
+ }), dataAttributes, {
298
299
  onMouseEnter: function onMouseEnter(event) {
299
300
  // We will not allow a hover target to be set if any mouse button is depressed during the mouse enter state.
300
301
  // This could be due to the user trying to select text across the document.
@@ -46,7 +46,7 @@ import { EditorMediaClientProvider } from '../../react/utils/EditorMediaClientPr
46
46
  export var NORMAL_SEVERITY_THRESHOLD = 2000;
47
47
  export var DEGRADED_SEVERITY_THRESHOLD = 3000;
48
48
  var packageName = "@atlaskit/renderer";
49
- var packageVersion = "109.14.0";
49
+ var packageVersion = "109.15.0";
50
50
  export var Renderer = /*#__PURE__*/function (_PureComponent) {
51
51
  _inherits(Renderer, _PureComponent);
52
52
  var _super = _createSuper(Renderer);
@@ -39,6 +39,7 @@ export interface MediaCardProps {
39
39
  featureFlags?: MediaFeatureFlags;
40
40
  shouldEnableDownloadButton?: boolean;
41
41
  ssr?: MediaSSR;
42
+ dataAttributes?: Record<string, any>;
42
43
  }
43
44
  export interface State {
44
45
  contextIdentifierProvider?: ContextIdentifierProvider;
@@ -39,6 +39,7 @@ export interface MediaCardProps {
39
39
  featureFlags?: MediaFeatureFlags;
40
40
  shouldEnableDownloadButton?: boolean;
41
41
  ssr?: MediaSSR;
42
+ dataAttributes?: Record<string, any>;
42
43
  }
43
44
  export interface State {
44
45
  contextIdentifierProvider?: ContextIdentifierProvider;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/renderer",
3
- "version": "109.14.0",
3
+ "version": "109.15.0",
4
4
  "description": "Renderer component",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -29,7 +29,7 @@
29
29
  "@atlaskit/analytics-listeners": "^8.9.0",
30
30
  "@atlaskit/analytics-namespaced-context": "^6.9.0",
31
31
  "@atlaskit/analytics-next": "^9.2.0",
32
- "@atlaskit/button": "^17.8.0",
32
+ "@atlaskit/button": "^17.10.0",
33
33
  "@atlaskit/code": "^15.1.0",
34
34
  "@atlaskit/editor-common": "^78.23.0",
35
35
  "@atlaskit/editor-json-transformer": "^8.10.0",
@@ -38,7 +38,7 @@
38
38
  "@atlaskit/editor-shared-styles": "^2.9.0",
39
39
  "@atlaskit/emoji": "^67.6.0",
40
40
  "@atlaskit/icon": "^22.1.0",
41
- "@atlaskit/link-datasource": "^1.24.0",
41
+ "@atlaskit/link-datasource": "^1.25.0",
42
42
  "@atlaskit/media-card": "^77.10.0",
43
43
  "@atlaskit/media-client": "^26.2.0",
44
44
  "@atlaskit/media-client-react": "^2.0.0",