@atlaskit/adf-utils 19.19.0 → 19.20.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,17 @@
1
1
  # @atlaskit/adf-utils
2
2
 
3
+ ## 19.20.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#160422](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/160422)
8
+ [`83606959c73cd`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/83606959c73cd) -
9
+ EDITOR-719 Overrides adf validation of nested tables for nested renderers inside bodied extensions
10
+ and reverts a previous change to transformNestedTablesIncomingDocument which prevented nested
11
+ tables inside bodied extensions from being transformed by their parent renderer. This was due to a
12
+ bug with comment positions of nested tables inside bodied extensions which meant their positions
13
+ were not being calculated correctly due to not being transformed in the parent renderer.
14
+
3
15
  ## 19.19.0
4
16
 
5
17
  ### Minor Changes
@@ -34,6 +34,8 @@ var transformNestedTableExtension = function transformNestedTableExtension(neste
34
34
  throw new _errors.NodeNestingTransformError('Failed to parse nested table content');
35
35
  }
36
36
  };
37
+
38
+ // TODO: EDITOR-806 - Remove when cleaning feature gate platform_editor_nested_table_extension_comment_fix
37
39
  function isInsideBodiedExtension(parent) {
38
40
  var _parent$parent;
39
41
  if (parent.node === undefined) {
@@ -53,11 +55,12 @@ var transformNestedTablesIncomingDocument = exports.transformNestedTablesIncomin
53
55
  var transformedAdf = (0, _traverse.traverse)(adf, {
54
56
  extension: function extension(node, parent) {
55
57
  if (isNestedTableExtension(node)) {
58
+ // TODO: EDITOR-806 - Remove this block when cleaning feature gate platform_editor_nested_table_extension_comment_fix
56
59
  // Bodied extensions in renderer use their own nested renderer to render the content.
57
60
  // This results in the document being validated/transformed twice, once with untransformed content and again with transformed content.
58
61
  // Since the untransformed content is valid ADF (table as extension in table) but the transformed content is not valid ADF, (table in table)
59
62
  // we need to skip transforming nested tables inside bodied extensions in renderer on the first pass or else it will fail validation and render an unsupported block.
60
- if (options.environment === 'renderer' && isInsideBodiedExtension(parent)) {
63
+ if (options.environment === 'renderer' && isInsideBodiedExtension(parent) && !options.disableNestedRendererTreatment) {
61
64
  return undefined;
62
65
  }
63
66
  isTransformed = true;
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _typeof = require("@babel/runtime/helpers/typeof");
4
+ var _typeof3 = require("@babel/runtime/helpers/typeof");
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.validateAttrs = validateAttrs;
9
9
  exports.validator = validator;
10
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
10
11
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
13
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
@@ -16,7 +17,7 @@ var _rules = require("./rules");
16
17
  var _excluded = ["items"]; // Ignored via go/ees005
17
18
  // eslint-disable-next-line import/no-namespace
18
19
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
19
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
20
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
20
21
  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; }
21
22
  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) { (0, _defineProperty2.default)(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; }
22
23
  // Ignored via go/ees005
@@ -277,9 +278,13 @@ var invalidChildContent = function invalidChildContent(child, errorCallback, par
277
278
  if (!errorCallback) {
278
279
  throw new Error(message);
279
280
  } else {
281
+ var _parentSpec$props;
280
282
  return errorCallback(_objectSpread({}, child), {
281
283
  code: 'INVALID_CONTENT',
282
- message: message
284
+ message: message,
285
+ meta: {
286
+ parentType: parentSpec === null || parentSpec === void 0 || (_parentSpec$props = parentSpec.props) === null || _parentSpec$props === void 0 || (_parentSpec$props = _parentSpec$props.type) === null || _parentSpec$props === void 0 ? void 0 : _parentSpec$props.values[0]
287
+ }
283
288
  }, getUnsupportedOptions(parentSpec));
284
289
  }
285
290
  };
@@ -785,7 +790,7 @@ function validator(nodes, marks, options) {
785
790
  var _validatorSpec$requir;
786
791
  // if the validator is an array, then check
787
792
  // if the `required` field contains the key.
788
- var isOptional = Array.isArray(v) ? !((_validatorSpec$requir = validatorSpec.required) !== null && _validatorSpec$requir !== void 0 && _validatorSpec$requir.includes(k)) : v.optional;
793
+ var isOptional = Array.isArray(v) ? !((_validatorSpec$requir = validatorSpec.required) !== null && _validatorSpec$requir !== void 0 && _validatorSpec$requir.includes(k)) : (0, _typeof2.default)(v) === 'object' && v !== null && 'optional' in v ? v.optional : false;
789
794
  return isOptional || (0, _utils.isDefined)(prevEntity[k]);
790
795
  }),
791
796
  _partitionObject8 = (0, _slicedToArray2.default)(_partitionObject7, 2),
@@ -24,6 +24,8 @@ const transformNestedTableExtension = nestedTableExtension => {
24
24
  throw new NodeNestingTransformError('Failed to parse nested table content');
25
25
  }
26
26
  };
27
+
28
+ // TODO: EDITOR-806 - Remove when cleaning feature gate platform_editor_nested_table_extension_comment_fix
27
29
  function isInsideBodiedExtension(parent) {
28
30
  var _parent$parent;
29
31
  if (parent.node === undefined) {
@@ -37,16 +39,19 @@ function isInsideBodiedExtension(parent) {
37
39
  }
38
40
  return false;
39
41
  }
40
- export const transformNestedTablesIncomingDocument = (adf, options = {}) => {
42
+ export const transformNestedTablesIncomingDocument = (adf,
43
+ // TODO: EDITOR-806 - Remove options when cleaning feature gate platform_editor_nested_table_extension_comment_fix as no longer needed
44
+ options = {}) => {
41
45
  let isTransformed = false;
42
46
  const transformedAdf = traverse(adf, {
43
47
  extension: (node, parent) => {
44
48
  if (isNestedTableExtension(node)) {
49
+ // TODO: EDITOR-806 - Remove this block when cleaning feature gate platform_editor_nested_table_extension_comment_fix
45
50
  // Bodied extensions in renderer use their own nested renderer to render the content.
46
51
  // This results in the document being validated/transformed twice, once with untransformed content and again with transformed content.
47
52
  // Since the untransformed content is valid ADF (table as extension in table) but the transformed content is not valid ADF, (table in table)
48
53
  // we need to skip transforming nested tables inside bodied extensions in renderer on the first pass or else it will fail validation and render an unsupported block.
49
- if (options.environment === 'renderer' && isInsideBodiedExtension(parent)) {
54
+ if (options.environment === 'renderer' && isInsideBodiedExtension(parent) && !options.disableNestedRendererTreatment) {
50
55
  return undefined;
51
56
  }
52
57
  isTransformed = true;
@@ -238,11 +238,15 @@ const invalidChildContent = (child, errorCallback, parentSpec) => {
238
238
  if (!errorCallback) {
239
239
  throw new Error(message);
240
240
  } else {
241
+ var _parentSpec$props, _parentSpec$props$typ;
241
242
  return errorCallback({
242
243
  ...child
243
244
  }, {
244
245
  code: 'INVALID_CONTENT',
245
- message
246
+ message,
247
+ meta: {
248
+ parentType: parentSpec === null || parentSpec === void 0 ? void 0 : (_parentSpec$props = parentSpec.props) === null || _parentSpec$props === void 0 ? void 0 : (_parentSpec$props$typ = _parentSpec$props.type) === null || _parentSpec$props$typ === void 0 ? void 0 : _parentSpec$props$typ.values[0]
249
+ }
246
250
  }, getUnsupportedOptions(parentSpec));
247
251
  }
248
252
  };
@@ -749,7 +753,7 @@ export function validator(nodes, marks, options) {
749
753
  var _validatorSpec$requir;
750
754
  // if the validator is an array, then check
751
755
  // if the `required` field contains the key.
752
- const isOptional = Array.isArray(v) ? !((_validatorSpec$requir = validatorSpec.required) !== null && _validatorSpec$requir !== void 0 && _validatorSpec$requir.includes(k)) : v.optional;
756
+ const isOptional = Array.isArray(v) ? !((_validatorSpec$requir = validatorSpec.required) !== null && _validatorSpec$requir !== void 0 && _validatorSpec$requir.includes(k)) : typeof v === 'object' && v !== null && 'optional' in v ? v.optional : false;
753
757
  return isOptional || isDefined(prevEntity[k]);
754
758
  });
755
759
  if (missingProps.length) {
@@ -27,6 +27,8 @@ var transformNestedTableExtension = function transformNestedTableExtension(neste
27
27
  throw new NodeNestingTransformError('Failed to parse nested table content');
28
28
  }
29
29
  };
30
+
31
+ // TODO: EDITOR-806 - Remove when cleaning feature gate platform_editor_nested_table_extension_comment_fix
30
32
  function isInsideBodiedExtension(parent) {
31
33
  var _parent$parent;
32
34
  if (parent.node === undefined) {
@@ -46,11 +48,12 @@ export var transformNestedTablesIncomingDocument = function transformNestedTable
46
48
  var transformedAdf = traverse(adf, {
47
49
  extension: function extension(node, parent) {
48
50
  if (isNestedTableExtension(node)) {
51
+ // TODO: EDITOR-806 - Remove this block when cleaning feature gate platform_editor_nested_table_extension_comment_fix
49
52
  // Bodied extensions in renderer use their own nested renderer to render the content.
50
53
  // This results in the document being validated/transformed twice, once with untransformed content and again with transformed content.
51
54
  // Since the untransformed content is valid ADF (table as extension in table) but the transformed content is not valid ADF, (table in table)
52
55
  // we need to skip transforming nested tables inside bodied extensions in renderer on the first pass or else it will fail validation and render an unsupported block.
53
- if (options.environment === 'renderer' && isInsideBodiedExtension(parent)) {
56
+ if (options.environment === 'renderer' && isInsideBodiedExtension(parent) && !options.disableNestedRendererTreatment) {
54
57
  return undefined;
55
58
  }
56
59
  isTransformed = true;
@@ -1,3 +1,4 @@
1
+ import _typeof from "@babel/runtime/helpers/typeof";
1
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
4
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
@@ -268,9 +269,13 @@ var invalidChildContent = function invalidChildContent(child, errorCallback, par
268
269
  if (!errorCallback) {
269
270
  throw new Error(message);
270
271
  } else {
272
+ var _parentSpec$props;
271
273
  return errorCallback(_objectSpread({}, child), {
272
274
  code: 'INVALID_CONTENT',
273
- message: message
275
+ message: message,
276
+ meta: {
277
+ parentType: parentSpec === null || parentSpec === void 0 || (_parentSpec$props = parentSpec.props) === null || _parentSpec$props === void 0 || (_parentSpec$props = _parentSpec$props.type) === null || _parentSpec$props === void 0 ? void 0 : _parentSpec$props.values[0]
278
+ }
274
279
  }, getUnsupportedOptions(parentSpec));
275
280
  }
276
281
  };
@@ -776,7 +781,7 @@ export function validator(nodes, marks, options) {
776
781
  var _validatorSpec$requir;
777
782
  // if the validator is an array, then check
778
783
  // if the `required` field contains the key.
779
- var isOptional = Array.isArray(v) ? !((_validatorSpec$requir = validatorSpec.required) !== null && _validatorSpec$requir !== void 0 && _validatorSpec$requir.includes(k)) : v.optional;
784
+ var isOptional = Array.isArray(v) ? !((_validatorSpec$requir = validatorSpec.required) !== null && _validatorSpec$requir !== void 0 && _validatorSpec$requir.includes(k)) : _typeof(v) === 'object' && v !== null && 'optional' in v ? v.optional : false;
780
785
  return isOptional || isDefined(prevEntity[k]);
781
786
  }),
782
787
  _partitionObject8 = _slicedToArray(_partitionObject7, 2),
@@ -1,2 +1,2 @@
1
- import { type MediaDefinition, type MediaAttributes } from '@atlaskit/adf-schema';
2
- export declare const media: (attrs: MediaAttributes) => MediaDefinition;
1
+ import { type MediaDefinition, type MediaADFAttrs } from '@atlaskit/adf-schema';
2
+ export declare const media: (attrs: MediaADFAttrs) => MediaDefinition;
@@ -2,6 +2,7 @@ import type { ADFEntity } from '../types';
2
2
  export declare const isNestedTableExtension: (extensionNode: ADFEntity) => boolean;
3
3
  export declare const transformNestedTablesIncomingDocument: (adf: ADFEntity, options?: {
4
4
  environment?: 'renderer' | 'editor';
5
+ disableNestedRendererTreatment?: boolean;
5
6
  }) => {
6
7
  transformedAdf: ADFEntity;
7
8
  isTransformed: boolean;
@@ -67,6 +67,10 @@ export interface ValidatorSpecAttrs {
67
67
  }
68
68
  export interface ValidatorSpec {
69
69
  props?: {
70
+ type?: {
71
+ type: 'enum';
72
+ values: Array<string>;
73
+ };
70
74
  attrs?: ValidatorSpecAttrs;
71
75
  content?: ValidatorContent;
72
76
  text?: AttributesSpec;
@@ -96,7 +100,9 @@ export interface ValidationErrorMap {
96
100
  };
97
101
  INVALID_TYPE: never;
98
102
  INVALID_TEXT: never;
99
- INVALID_CONTENT: never;
103
+ INVALID_CONTENT: {
104
+ parentType?: string;
105
+ };
100
106
  INVALID_CONTENT_LENGTH: {
101
107
  length: number;
102
108
  requiredLength: number;
@@ -134,5 +140,6 @@ export interface ErrorCallbackOptions {
134
140
  isMark?: any;
135
141
  allowUnsupportedBlock?: boolean;
136
142
  allowUnsupportedInline?: boolean;
143
+ allowNestedTables?: boolean;
137
144
  }
138
145
  export type Validate = (entity: ADFEntity, errorCallback?: ErrorCallback, allowed?: Content, parentSpec?: ValidatorSpec) => Output;
@@ -1,2 +1,2 @@
1
- import { type MediaDefinition, type MediaAttributes } from '@atlaskit/adf-schema';
2
- export declare const media: (attrs: MediaAttributes) => MediaDefinition;
1
+ import { type MediaDefinition, type MediaADFAttrs } from '@atlaskit/adf-schema';
2
+ export declare const media: (attrs: MediaADFAttrs) => MediaDefinition;
@@ -2,6 +2,7 @@ import type { ADFEntity } from '../types';
2
2
  export declare const isNestedTableExtension: (extensionNode: ADFEntity) => boolean;
3
3
  export declare const transformNestedTablesIncomingDocument: (adf: ADFEntity, options?: {
4
4
  environment?: 'renderer' | 'editor';
5
+ disableNestedRendererTreatment?: boolean;
5
6
  }) => {
6
7
  transformedAdf: ADFEntity;
7
8
  isTransformed: boolean;
@@ -67,6 +67,10 @@ export interface ValidatorSpecAttrs {
67
67
  }
68
68
  export interface ValidatorSpec {
69
69
  props?: {
70
+ type?: {
71
+ type: 'enum';
72
+ values: Array<string>;
73
+ };
70
74
  attrs?: ValidatorSpecAttrs;
71
75
  content?: ValidatorContent;
72
76
  text?: AttributesSpec;
@@ -96,7 +100,9 @@ export interface ValidationErrorMap {
96
100
  };
97
101
  INVALID_TYPE: never;
98
102
  INVALID_TEXT: never;
99
- INVALID_CONTENT: never;
103
+ INVALID_CONTENT: {
104
+ parentType?: string;
105
+ };
100
106
  INVALID_CONTENT_LENGTH: {
101
107
  length: number;
102
108
  requiredLength: number;
@@ -137,5 +143,6 @@ export interface ErrorCallbackOptions {
137
143
  isMark?: any;
138
144
  allowUnsupportedBlock?: boolean;
139
145
  allowUnsupportedInline?: boolean;
146
+ allowNestedTables?: boolean;
140
147
  }
141
148
  export type Validate = (entity: ADFEntity, errorCallback?: ErrorCallback, allowed?: Content, parentSpec?: ValidatorSpec) => Output;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/adf-utils",
3
- "version": "19.19.0",
3
+ "version": "19.20.0",
4
4
  "description": "Set of utilities to traverse, modify and create ADF documents.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -23,7 +23,7 @@
23
23
  "sideEffects": false,
24
24
  "atlaskit:src": "src/index.ts",
25
25
  "atlassian": {
26
- "team": "Editor: ADF"
26
+ "team": "Editor: Collaboration"
27
27
  },
28
28
  "af:exports": {
29
29
  "./builders": "./src/builders.ts",