@atlaskit/adf-utils 19.27.47 → 19.29.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,36 @@
1
1
  # @atlaskit/adf-utils
2
2
 
3
+ ## 19.29.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`2fb1c8a74a856`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2fb1c8a74a856) -
8
+ ADF Change 101: Add wrap and hideLineNumbers attributes to codeBlock stage-0 variants
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies
13
+
14
+ ## 19.28.0
15
+
16
+ ### Minor Changes
17
+
18
+ - [`9ea3b02135766`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/9ea3b02135766) -
19
+ EDITOR-5613: Remove flexible list variants and consolidate into base list types.
20
+
21
+ The `listItem` and `taskList` node specs now natively support the flexible content model (allowing
22
+ lists as first child of listItem, and nested taskLists without requiring taskItem first). The
23
+ separate `listItemWithFlexibleFirstChildStage0` and `taskListWithFlexibleFirstChildStage0`
24
+ variants have been removed from public exports — the flexible behavior is now the default for all
25
+ schema stages. Consumers importing these removed exports should switch to `listItem` / `taskList`.
26
+
27
+ This is a schema simplification: the flexible content spec is a strict superset of the old
28
+ restrictive spec, so all previously valid content remains valid.
29
+
30
+ ### Patch Changes
31
+
32
+ - Updated dependencies
33
+
3
34
  ## 19.27.47
4
35
 
5
36
  ### Patch Changes
@@ -111,6 +111,18 @@ Object.defineProperty(exports, "codeBlock_root_only", {
111
111
  return _schemaValidator.codeBlock_root_only;
112
112
  }
113
113
  });
114
+ Object.defineProperty(exports, "codeBlock_root_only_with_extended_attributes", {
115
+ enumerable: true,
116
+ get: function get() {
117
+ return _schemaValidator.codeBlock_root_only_with_extended_attributes;
118
+ }
119
+ });
120
+ Object.defineProperty(exports, "codeBlock_with_extended_attributes", {
121
+ enumerable: true,
122
+ get: function get() {
123
+ return _schemaValidator.codeBlock_with_extended_attributes;
124
+ }
125
+ });
114
126
  Object.defineProperty(exports, "confluenceInlineComment", {
115
127
  enumerable: true,
116
128
  get: function get() {
@@ -303,12 +315,6 @@ Object.defineProperty(exports, "listItem", {
303
315
  return _schemaValidator.listItem;
304
316
  }
305
317
  });
306
- Object.defineProperty(exports, "listItem_with_flexible_first_child", {
307
- enumerable: true,
308
- get: function get() {
309
- return _schemaValidator.listItem_with_flexible_first_child;
310
- }
311
- });
312
318
  Object.defineProperty(exports, "media", {
313
319
  enumerable: true,
314
320
  get: function get() {
@@ -513,12 +519,6 @@ Object.defineProperty(exports, "taskList", {
513
519
  return _schemaValidator.taskList;
514
520
  }
515
521
  });
516
- Object.defineProperty(exports, "taskList_with_flexible_first_child", {
517
- enumerable: true,
518
- get: function get() {
519
- return _schemaValidator.taskList_with_flexible_first_child;
520
- }
521
- });
522
522
  Object.defineProperty(exports, "text", {
523
523
  enumerable: true,
524
524
  get: function get() {
@@ -12,11 +12,11 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
12
12
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
13
13
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
14
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
15
- var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
16
15
  var specs = _interopRequireWildcard(require("./specs"));
17
16
  var _utils = require("./utils");
18
17
  var _extractAllowedContent = require("./extractAllowedContent");
19
18
  var _rules = require("./rules");
19
+ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
20
20
  var _excluded = ["items"]; // Ignored via go/ees005
21
21
  // eslint-disable-next-line import/no-namespace
22
22
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
@@ -67,9 +67,6 @@ var partitionObject = function partitionObject(obj, predicate) {
67
67
  * Checks if a spec is a variant spec.
68
68
  * A variant spec is an array where the first element is a string (base spec name)
69
69
  * and the second element is a ValidatorSpec object { props: { ... } }
70
- *
71
- * @param spec - The spec to check
72
- * @returns true if the spec is a variant spec, false otherwise
73
70
  */
74
71
  var isVariant = function isVariant(spec) {
75
72
  return (0, _typeof2.default)(spec) === 'object' && !!spec && 0 in spec && 1 in spec && typeof spec[0] === 'string' && (0, _typeof2.default)(spec[1]) === 'object';
@@ -80,19 +77,16 @@ var isVariant = function isVariant(spec) {
80
77
  * We denormalised the spec to save bundle size.
81
78
  */
82
79
  function createSpec(nodes, marks) {
80
+ var variantOverrides = getVariantSpecOverrides();
83
81
  // Ignored via go/ees005
84
82
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
85
83
  return Object.keys(specs).reduce(function (newSpecs, k) {
86
84
  // Ignored via go/ees005
87
85
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
88
86
  var spec = _objectSpread({}, specs[k]);
89
- if ((0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_flexible_list_schema', 'isEnabled', true) && isVariant(spec) &&
90
- // Only apply to variants which are explicitly marked for override in `variantSpecOverrides`
91
- Object.values(variantSpecOverrides).includes(k)) {
92
- // This allows the variant spec to also have the content normalization applied to it
87
+ if (isVariant(spec) && Object.values(variantOverrides).includes(k)) {
93
88
  // When the spec is a variant it will be in the form of ['base_spec_name', { props: { ... } }]
94
- // So the actual validator spec of the variant will be the second item in the array
95
- // We also need to shallow clone this to ensure we don't mutate the original spec
89
+ // The actual validator spec of the variant will be the second item in the array
96
90
  spec = _objectSpread({}, spec[1]);
97
91
  }
98
92
  if (spec.props) {
@@ -212,6 +206,10 @@ function getOptionsForType(type, list) {
212
206
  var isValidatorSpecAttrs = function isValidatorSpecAttrs(spec) {
213
207
  return !!spec.props;
214
208
  };
209
+
210
+ /**
211
+ * Validates attributes against the provided attribute specification.
212
+ */
215
213
  function validateAttrs(spec, value) {
216
214
  if (!(0, _utils.isDefined)(value)) {
217
215
  return !!spec.optional;
@@ -350,21 +348,26 @@ var unsupportedNodeAttributesContent = function unsupportedNodeAttributesContent
350
348
  };
351
349
 
352
350
  /**
353
- * Map of base spec names to a preferred variant spec that should be used in their place during validation.
351
+ * Returns a map of base spec names to a preferred variant spec that should be used
352
+ * in their place during validation. Implemented as a getter function so that entries
353
+ * can be conditionally included behind feature gates.
354
354
  *
355
355
  * WARNING: The variant spec must be a strict superset of the base spec, i.e. any content valid
356
- * under the base spec must also be valid under the variant
356
+ * under the base spec must also be valid under the variant.
357
357
  */
358
- var variantSpecOverrides = {
359
- listItem: 'listItem_with_flexible_first_child',
360
- taskList: 'taskList_with_flexible_first_child'
358
+ var getVariantSpecOverrides = function getVariantSpecOverrides() {
359
+ var overrides = {};
360
+ if ((0, _expValEquals.expValEquals)('platform_editor_code_block_q4_lovability', 'isEnabled', true)) {
361
+ overrides.codeBlock = 'codeBlock_with_extended_attributes';
362
+ }
363
+ return overrides;
361
364
  };
362
365
 
363
366
  /**
364
- * Replaces base validator specs with their designated variant overrides
367
+ * Replaces base validator specs with their designated variant overrides.
365
368
  */
366
369
  var applyVariantSpecOverrides = function applyVariantSpecOverrides(validatorSpecs) {
367
- Object.entries(variantSpecOverrides).forEach(function (_ref2) {
370
+ Object.entries(getVariantSpecOverrides()).forEach(function (_ref2) {
368
371
  var _ref3 = (0, _slicedToArray2.default)(_ref2, 2),
369
372
  base = _ref3[0],
370
373
  variant = _ref3[1];
@@ -376,11 +379,14 @@ var applyVariantSpecOverrides = function applyVariantSpecOverrides(validatorSpec
376
379
  }
377
380
  });
378
381
  };
382
+
383
+ /**
384
+ * Creates a validator function for ADF documents.
385
+ * Validates document structure against the ADF specification.
386
+ */
379
387
  function validator(nodes, marks, options) {
380
388
  var validatorSpecs = createSpec(nodes, marks);
381
- if ((0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_flexible_list_schema', 'isEnabled', true)) {
382
- applyVariantSpecOverrides(validatorSpecs);
383
- }
389
+ applyVariantSpecOverrides(validatorSpecs);
384
390
  var _ref4 = options || {},
385
391
  _ref4$mode = _ref4.mode,
386
392
  mode = _ref4$mode === void 0 ? 'strict' : _ref4$mode,
@@ -1,2 +1,2 @@
1
1
  /* eslint-disable @atlaskit/editor/no-re-export */
2
- export { alignment, annotation, backgroundColor, blockCard, block_content, blockRootOnly, blockquote, blockTaskItem, bodiedExtension, bodiedExtension_with_marks, border, breakout, bulletList, caption, code, codeBlock, codeBlock_root_only, text_with_no_marks, confluenceInlineComment, dataConsumer, date, decisionItem, decisionList, doc, em, embedCard, emoji, expand, expand_root_only, extension, extensionFrame, extension_with_marks, fontSize, fragment, hardBreak, heading, heading_with_alignment, heading_with_indentation, heading_with_no_marks, indentation, inlineCard, inlineExtension, inlineExtension_with_marks, inline_content, layoutColumn, layoutSection, layoutSection_full, layoutSection_with_single_column, link, listItem, listItem_with_flexible_first_child, media, mediaGroup, mediaInline, mediaSingle, mediaSingle_caption, mediaSingle_full, mention, multiBodiedExtension, nestedExpand, nestedExpand_content, nestedExpand_with_no_marks, non_nestable_block_content, orderedList, panel, paragraph, paragraph_with_alignment, paragraph_with_font_size, paragraph_with_font_size_and_alignment, paragraph_with_font_size_and_indentation, paragraph_with_indentation, paragraph_with_no_marks, placeholder, rule, status, strike, strong, subsup, table, tableCell, tableHeader, tableRow, taskItem, taskList, taskList_with_flexible_first_child, text, textColor, text_code_inline, text_formatted, text_link_inline, underline, syncBlock, bodiedSyncBlock } from '@atlaskit/adf-schema/schema-validator';
2
+ export { alignment, annotation, backgroundColor, blockCard, block_content, blockRootOnly, blockquote, blockTaskItem, bodiedExtension, bodiedExtension_with_marks, border, breakout, bulletList, caption, code, codeBlock, codeBlock_root_only, codeBlock_with_extended_attributes, codeBlock_root_only_with_extended_attributes, text_with_no_marks, confluenceInlineComment, dataConsumer, date, decisionItem, decisionList, doc, em, embedCard, emoji, expand, expand_root_only, extension, extensionFrame, extension_with_marks, fontSize, fragment, hardBreak, heading, heading_with_alignment, heading_with_indentation, heading_with_no_marks, indentation, inlineCard, inlineExtension, inlineExtension_with_marks, inline_content, layoutColumn, layoutSection, layoutSection_full, layoutSection_with_single_column, link, listItem, media, mediaGroup, mediaInline, mediaSingle, mediaSingle_caption, mediaSingle_full, mention, multiBodiedExtension, nestedExpand, nestedExpand_content, nestedExpand_with_no_marks, non_nestable_block_content, orderedList, panel, paragraph, paragraph_with_alignment, paragraph_with_font_size, paragraph_with_font_size_and_alignment, paragraph_with_font_size_and_indentation, paragraph_with_indentation, paragraph_with_no_marks, placeholder, rule, status, strike, strong, subsup, table, tableCell, tableHeader, tableRow, taskItem, taskList, text, textColor, text_code_inline, text_formatted, text_link_inline, underline, syncBlock, bodiedSyncBlock } from '@atlaskit/adf-schema/schema-validator';
@@ -1,10 +1,10 @@
1
- import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
2
1
  // Ignored via go/ees005
3
2
  // eslint-disable-next-line import/no-namespace
4
3
  import * as specs from './specs';
5
4
  import { copy, isBoolean, isDefined, isInteger, isNumber, isPlainObject, isString, makeArray } from './utils';
6
5
  import { extractAllowedContent } from './extractAllowedContent';
7
6
  import { validatorFnMap } from './rules';
7
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
8
8
 
9
9
  // Ignored via go/ees005
10
10
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -47,9 +47,6 @@ const partitionObject = (obj, predicate) => Object.keys(obj).reduce((acc, key) =
47
47
  * Checks if a spec is a variant spec.
48
48
  * A variant spec is an array where the first element is a string (base spec name)
49
49
  * and the second element is a ValidatorSpec object { props: { ... } }
50
- *
51
- * @param spec - The spec to check
52
- * @returns true if the spec is a variant spec, false otherwise
53
50
  */
54
51
  const isVariant = spec => typeof spec === 'object' && !!spec && 0 in spec && 1 in spec && typeof spec[0] === 'string' && typeof spec[1] === 'object';
55
52
 
@@ -58,6 +55,7 @@ const isVariant = spec => typeof spec === 'object' && !!spec && 0 in spec && 1 i
58
55
  * We denormalised the spec to save bundle size.
59
56
  */
60
57
  export function createSpec(nodes, marks) {
58
+ const variantOverrides = getVariantSpecOverrides();
61
59
  // Ignored via go/ees005
62
60
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
61
  return Object.keys(specs).reduce((newSpecs, k) => {
@@ -66,13 +64,9 @@ export function createSpec(nodes, marks) {
66
64
  let spec = {
67
65
  ...specs[k]
68
66
  };
69
- if (expValEqualsNoExposure('platform_editor_flexible_list_schema', 'isEnabled', true) && isVariant(spec) &&
70
- // Only apply to variants which are explicitly marked for override in `variantSpecOverrides`
71
- Object.values(variantSpecOverrides).includes(k)) {
72
- // This allows the variant spec to also have the content normalization applied to it
67
+ if (isVariant(spec) && Object.values(variantOverrides).includes(k)) {
73
68
  // When the spec is a variant it will be in the form of ['base_spec_name', { props: { ... } }]
74
- // So the actual validator spec of the variant will be the second item in the array
75
- // We also need to shallow clone this to ensure we don't mutate the original spec
69
+ // The actual validator spec of the variant will be the second item in the array
76
70
  spec = {
77
71
  ...spec[1]
78
72
  };
@@ -183,6 +177,10 @@ function getOptionsForType(type, list) {
183
177
  const isValidatorSpecAttrs = spec => {
184
178
  return !!spec.props;
185
179
  };
180
+
181
+ /**
182
+ * Validates attributes against the provided attribute specification.
183
+ */
186
184
  export function validateAttrs(spec, value) {
187
185
  if (!isDefined(value)) {
188
186
  return !!spec.optional;
@@ -311,21 +309,26 @@ const unsupportedNodeAttributesContent = (entity, errorCode, invalidAttributes,
311
309
  };
312
310
 
313
311
  /**
314
- * Map of base spec names to a preferred variant spec that should be used in their place during validation.
312
+ * Returns a map of base spec names to a preferred variant spec that should be used
313
+ * in their place during validation. Implemented as a getter function so that entries
314
+ * can be conditionally included behind feature gates.
315
315
  *
316
316
  * WARNING: The variant spec must be a strict superset of the base spec, i.e. any content valid
317
- * under the base spec must also be valid under the variant
317
+ * under the base spec must also be valid under the variant.
318
318
  */
319
- const variantSpecOverrides = {
320
- listItem: 'listItem_with_flexible_first_child',
321
- taskList: 'taskList_with_flexible_first_child'
319
+ const getVariantSpecOverrides = () => {
320
+ const overrides = {};
321
+ if (expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true)) {
322
+ overrides.codeBlock = 'codeBlock_with_extended_attributes';
323
+ }
324
+ return overrides;
322
325
  };
323
326
 
324
327
  /**
325
- * Replaces base validator specs with their designated variant overrides
328
+ * Replaces base validator specs with their designated variant overrides.
326
329
  */
327
330
  const applyVariantSpecOverrides = validatorSpecs => {
328
- Object.entries(variantSpecOverrides).forEach(([base, variant]) => {
331
+ Object.entries(getVariantSpecOverrides()).forEach(([base, variant]) => {
329
332
  const baseSpec = validatorSpecs[base];
330
333
  const variantOverride = validatorSpecs[variant];
331
334
  if (baseSpec !== null && baseSpec !== void 0 && baseSpec.props && variantOverride !== null && variantOverride !== void 0 && variantOverride.props && typeof baseSpec.props === 'object' && typeof variantOverride.props === 'object') {
@@ -338,11 +341,14 @@ const applyVariantSpecOverrides = validatorSpecs => {
338
341
  }
339
342
  });
340
343
  };
344
+
345
+ /**
346
+ * Creates a validator function for ADF documents.
347
+ * Validates document structure against the ADF specification.
348
+ */
341
349
  export function validator(nodes, marks, options) {
342
350
  const validatorSpecs = createSpec(nodes, marks);
343
- if (expValEqualsNoExposure('platform_editor_flexible_list_schema', 'isEnabled', true)) {
344
- applyVariantSpecOverrides(validatorSpecs);
345
- }
351
+ applyVariantSpecOverrides(validatorSpecs);
346
352
  const {
347
353
  mode = 'strict',
348
354
  allowPrivateAttributes = false
@@ -1,2 +1,2 @@
1
1
  /* eslint-disable @atlaskit/editor/no-re-export */
2
- export { alignment, annotation, backgroundColor, blockCard, block_content, blockRootOnly, blockquote, blockTaskItem, bodiedExtension, bodiedExtension_with_marks, border, breakout, bulletList, caption, code, codeBlock, codeBlock_root_only, text_with_no_marks, confluenceInlineComment, dataConsumer, date, decisionItem, decisionList, doc, em, embedCard, emoji, expand, expand_root_only, extension, extensionFrame, extension_with_marks, fontSize, fragment, hardBreak, heading, heading_with_alignment, heading_with_indentation, heading_with_no_marks, indentation, inlineCard, inlineExtension, inlineExtension_with_marks, inline_content, layoutColumn, layoutSection, layoutSection_full, layoutSection_with_single_column, link, listItem, listItem_with_flexible_first_child, media, mediaGroup, mediaInline, mediaSingle, mediaSingle_caption, mediaSingle_full, mention, multiBodiedExtension, nestedExpand, nestedExpand_content, nestedExpand_with_no_marks, non_nestable_block_content, orderedList, panel, paragraph, paragraph_with_alignment, paragraph_with_font_size, paragraph_with_font_size_and_alignment, paragraph_with_font_size_and_indentation, paragraph_with_indentation, paragraph_with_no_marks, placeholder, rule, status, strike, strong, subsup, table, tableCell, tableHeader, tableRow, taskItem, taskList, taskList_with_flexible_first_child, text, textColor, text_code_inline, text_formatted, text_link_inline, underline, syncBlock, bodiedSyncBlock } from '@atlaskit/adf-schema/schema-validator';
2
+ export { alignment, annotation, backgroundColor, blockCard, block_content, blockRootOnly, blockquote, blockTaskItem, bodiedExtension, bodiedExtension_with_marks, border, breakout, bulletList, caption, code, codeBlock, codeBlock_root_only, codeBlock_with_extended_attributes, codeBlock_root_only_with_extended_attributes, text_with_no_marks, confluenceInlineComment, dataConsumer, date, decisionItem, decisionList, doc, em, embedCard, emoji, expand, expand_root_only, extension, extensionFrame, extension_with_marks, fontSize, fragment, hardBreak, heading, heading_with_alignment, heading_with_indentation, heading_with_no_marks, indentation, inlineCard, inlineExtension, inlineExtension_with_marks, inline_content, layoutColumn, layoutSection, layoutSection_full, layoutSection_with_single_column, link, listItem, media, mediaGroup, mediaInline, mediaSingle, mediaSingle_caption, mediaSingle_full, mention, multiBodiedExtension, nestedExpand, nestedExpand_content, nestedExpand_with_no_marks, non_nestable_block_content, orderedList, panel, paragraph, paragraph_with_alignment, paragraph_with_font_size, paragraph_with_font_size_and_alignment, paragraph_with_font_size_and_indentation, paragraph_with_indentation, paragraph_with_no_marks, placeholder, rule, status, strike, strong, subsup, table, tableCell, tableHeader, tableRow, taskItem, taskList, text, textColor, text_code_inline, text_formatted, text_link_inline, underline, syncBlock, bodiedSyncBlock } from '@atlaskit/adf-schema/schema-validator';
@@ -8,13 +8,13 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
8
8
  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; }
9
9
  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; }
10
10
  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; }
11
- import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
12
11
  // Ignored via go/ees005
13
12
  // eslint-disable-next-line import/no-namespace
14
13
  import * as specs from './specs';
15
14
  import { copy, isBoolean, isDefined, isInteger, isNumber, isPlainObject, isString, makeArray } from './utils';
16
15
  import { extractAllowedContent } from './extractAllowedContent';
17
16
  import { validatorFnMap } from './rules';
17
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
18
18
 
19
19
  // Ignored via go/ees005
20
20
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -58,9 +58,6 @@ var partitionObject = function partitionObject(obj, predicate) {
58
58
  * Checks if a spec is a variant spec.
59
59
  * A variant spec is an array where the first element is a string (base spec name)
60
60
  * and the second element is a ValidatorSpec object { props: { ... } }
61
- *
62
- * @param spec - The spec to check
63
- * @returns true if the spec is a variant spec, false otherwise
64
61
  */
65
62
  var isVariant = function isVariant(spec) {
66
63
  return _typeof(spec) === 'object' && !!spec && 0 in spec && 1 in spec && typeof spec[0] === 'string' && _typeof(spec[1]) === 'object';
@@ -71,19 +68,16 @@ var isVariant = function isVariant(spec) {
71
68
  * We denormalised the spec to save bundle size.
72
69
  */
73
70
  export function createSpec(nodes, marks) {
71
+ var variantOverrides = getVariantSpecOverrides();
74
72
  // Ignored via go/ees005
75
73
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
74
  return Object.keys(specs).reduce(function (newSpecs, k) {
77
75
  // Ignored via go/ees005
78
76
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
79
77
  var spec = _objectSpread({}, specs[k]);
80
- if (expValEqualsNoExposure('platform_editor_flexible_list_schema', 'isEnabled', true) && isVariant(spec) &&
81
- // Only apply to variants which are explicitly marked for override in `variantSpecOverrides`
82
- Object.values(variantSpecOverrides).includes(k)) {
83
- // This allows the variant spec to also have the content normalization applied to it
78
+ if (isVariant(spec) && Object.values(variantOverrides).includes(k)) {
84
79
  // When the spec is a variant it will be in the form of ['base_spec_name', { props: { ... } }]
85
- // So the actual validator spec of the variant will be the second item in the array
86
- // We also need to shallow clone this to ensure we don't mutate the original spec
80
+ // The actual validator spec of the variant will be the second item in the array
87
81
  spec = _objectSpread({}, spec[1]);
88
82
  }
89
83
  if (spec.props) {
@@ -203,6 +197,10 @@ function getOptionsForType(type, list) {
203
197
  var isValidatorSpecAttrs = function isValidatorSpecAttrs(spec) {
204
198
  return !!spec.props;
205
199
  };
200
+
201
+ /**
202
+ * Validates attributes against the provided attribute specification.
203
+ */
206
204
  export function validateAttrs(spec, value) {
207
205
  if (!isDefined(value)) {
208
206
  return !!spec.optional;
@@ -341,21 +339,26 @@ var unsupportedNodeAttributesContent = function unsupportedNodeAttributesContent
341
339
  };
342
340
 
343
341
  /**
344
- * Map of base spec names to a preferred variant spec that should be used in their place during validation.
342
+ * Returns a map of base spec names to a preferred variant spec that should be used
343
+ * in their place during validation. Implemented as a getter function so that entries
344
+ * can be conditionally included behind feature gates.
345
345
  *
346
346
  * WARNING: The variant spec must be a strict superset of the base spec, i.e. any content valid
347
- * under the base spec must also be valid under the variant
347
+ * under the base spec must also be valid under the variant.
348
348
  */
349
- var variantSpecOverrides = {
350
- listItem: 'listItem_with_flexible_first_child',
351
- taskList: 'taskList_with_flexible_first_child'
349
+ var getVariantSpecOverrides = function getVariantSpecOverrides() {
350
+ var overrides = {};
351
+ if (expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true)) {
352
+ overrides.codeBlock = 'codeBlock_with_extended_attributes';
353
+ }
354
+ return overrides;
352
355
  };
353
356
 
354
357
  /**
355
- * Replaces base validator specs with their designated variant overrides
358
+ * Replaces base validator specs with their designated variant overrides.
356
359
  */
357
360
  var applyVariantSpecOverrides = function applyVariantSpecOverrides(validatorSpecs) {
358
- Object.entries(variantSpecOverrides).forEach(function (_ref2) {
361
+ Object.entries(getVariantSpecOverrides()).forEach(function (_ref2) {
359
362
  var _ref3 = _slicedToArray(_ref2, 2),
360
363
  base = _ref3[0],
361
364
  variant = _ref3[1];
@@ -367,11 +370,14 @@ var applyVariantSpecOverrides = function applyVariantSpecOverrides(validatorSpec
367
370
  }
368
371
  });
369
372
  };
373
+
374
+ /**
375
+ * Creates a validator function for ADF documents.
376
+ * Validates document structure against the ADF specification.
377
+ */
370
378
  export function validator(nodes, marks, options) {
371
379
  var validatorSpecs = createSpec(nodes, marks);
372
- if (expValEqualsNoExposure('platform_editor_flexible_list_schema', 'isEnabled', true)) {
373
- applyVariantSpecOverrides(validatorSpecs);
374
- }
380
+ applyVariantSpecOverrides(validatorSpecs);
375
381
  var _ref4 = options || {},
376
382
  _ref4$mode = _ref4.mode,
377
383
  mode = _ref4$mode === void 0 ? 'strict' : _ref4$mode,
@@ -1 +1 @@
1
- export { alignment, annotation, backgroundColor, blockCard, block_content, blockRootOnly, blockquote, blockTaskItem, bodiedExtension, bodiedExtension_with_marks, border, breakout, bulletList, caption, code, codeBlock, codeBlock_root_only, text_with_no_marks, confluenceInlineComment, dataConsumer, date, decisionItem, decisionList, doc, em, embedCard, emoji, expand, expand_root_only, extension, extensionFrame, extension_with_marks, fontSize, fragment, hardBreak, heading, heading_with_alignment, heading_with_indentation, heading_with_no_marks, indentation, inlineCard, inlineExtension, inlineExtension_with_marks, inline_content, layoutColumn, layoutSection, layoutSection_full, layoutSection_with_single_column, link, listItem, listItem_with_flexible_first_child, media, mediaGroup, mediaInline, mediaSingle, mediaSingle_caption, mediaSingle_full, mention, multiBodiedExtension, nestedExpand, nestedExpand_content, nestedExpand_with_no_marks, non_nestable_block_content, orderedList, panel, paragraph, paragraph_with_alignment, paragraph_with_font_size, paragraph_with_font_size_and_alignment, paragraph_with_font_size_and_indentation, paragraph_with_indentation, paragraph_with_no_marks, placeholder, rule, status, strike, strong, subsup, table, tableCell, tableHeader, tableRow, taskItem, taskList, taskList_with_flexible_first_child, text, textColor, text_code_inline, text_formatted, text_link_inline, underline, syncBlock, bodiedSyncBlock, } from '@atlaskit/adf-schema/schema-validator';
1
+ export { alignment, annotation, backgroundColor, blockCard, block_content, blockRootOnly, blockquote, blockTaskItem, bodiedExtension, bodiedExtension_with_marks, border, breakout, bulletList, caption, code, codeBlock, codeBlock_root_only, codeBlock_with_extended_attributes, codeBlock_root_only_with_extended_attributes, text_with_no_marks, confluenceInlineComment, dataConsumer, date, decisionItem, decisionList, doc, em, embedCard, emoji, expand, expand_root_only, extension, extensionFrame, extension_with_marks, fontSize, fragment, hardBreak, heading, heading_with_alignment, heading_with_indentation, heading_with_no_marks, indentation, inlineCard, inlineExtension, inlineExtension_with_marks, inline_content, layoutColumn, layoutSection, layoutSection_full, layoutSection_with_single_column, link, listItem, media, mediaGroup, mediaInline, mediaSingle, mediaSingle_caption, mediaSingle_full, mention, multiBodiedExtension, nestedExpand, nestedExpand_content, nestedExpand_with_no_marks, non_nestable_block_content, orderedList, panel, paragraph, paragraph_with_alignment, paragraph_with_font_size, paragraph_with_font_size_and_alignment, paragraph_with_font_size_and_indentation, paragraph_with_indentation, paragraph_with_no_marks, placeholder, rule, status, strike, strong, subsup, table, tableCell, tableHeader, tableRow, taskItem, taskList, text, textColor, text_code_inline, text_formatted, text_link_inline, underline, syncBlock, bodiedSyncBlock, } from '@atlaskit/adf-schema/schema-validator';
@@ -4,5 +4,12 @@ import type { AttributesSpec, CreateSpecReturn, Validate, ValidationOptions } fr
4
4
  * We denormalised the spec to save bundle size.
5
5
  */
6
6
  export declare function createSpec(nodes?: Array<string>, marks?: Array<string>): CreateSpecReturn;
7
+ /**
8
+ * Validates attributes against the provided attribute specification.
9
+ */
7
10
  export declare function validateAttrs<T>(spec: AttributesSpec, value: T): boolean;
11
+ /**
12
+ * Creates a validator function for ADF documents.
13
+ * Validates document structure against the ADF specification.
14
+ */
8
15
  export declare function validator(nodes?: Array<string>, marks?: Array<string>, options?: ValidationOptions): Validate;
@@ -1 +1 @@
1
- export { alignment, annotation, backgroundColor, blockCard, block_content, blockRootOnly, blockquote, blockTaskItem, bodiedExtension, bodiedExtension_with_marks, border, breakout, bulletList, caption, code, codeBlock, codeBlock_root_only, text_with_no_marks, confluenceInlineComment, dataConsumer, date, decisionItem, decisionList, doc, em, embedCard, emoji, expand, expand_root_only, extension, extensionFrame, extension_with_marks, fontSize, fragment, hardBreak, heading, heading_with_alignment, heading_with_indentation, heading_with_no_marks, indentation, inlineCard, inlineExtension, inlineExtension_with_marks, inline_content, layoutColumn, layoutSection, layoutSection_full, layoutSection_with_single_column, link, listItem, listItem_with_flexible_first_child, media, mediaGroup, mediaInline, mediaSingle, mediaSingle_caption, mediaSingle_full, mention, multiBodiedExtension, nestedExpand, nestedExpand_content, nestedExpand_with_no_marks, non_nestable_block_content, orderedList, panel, paragraph, paragraph_with_alignment, paragraph_with_font_size, paragraph_with_font_size_and_alignment, paragraph_with_font_size_and_indentation, paragraph_with_indentation, paragraph_with_no_marks, placeholder, rule, status, strike, strong, subsup, table, tableCell, tableHeader, tableRow, taskItem, taskList, taskList_with_flexible_first_child, text, textColor, text_code_inline, text_formatted, text_link_inline, underline, syncBlock, bodiedSyncBlock, } from '@atlaskit/adf-schema/schema-validator';
1
+ export { alignment, annotation, backgroundColor, blockCard, block_content, blockRootOnly, blockquote, blockTaskItem, bodiedExtension, bodiedExtension_with_marks, border, breakout, bulletList, caption, code, codeBlock, codeBlock_root_only, codeBlock_with_extended_attributes, codeBlock_root_only_with_extended_attributes, text_with_no_marks, confluenceInlineComment, dataConsumer, date, decisionItem, decisionList, doc, em, embedCard, emoji, expand, expand_root_only, extension, extensionFrame, extension_with_marks, fontSize, fragment, hardBreak, heading, heading_with_alignment, heading_with_indentation, heading_with_no_marks, indentation, inlineCard, inlineExtension, inlineExtension_with_marks, inline_content, layoutColumn, layoutSection, layoutSection_full, layoutSection_with_single_column, link, listItem, media, mediaGroup, mediaInline, mediaSingle, mediaSingle_caption, mediaSingle_full, mention, multiBodiedExtension, nestedExpand, nestedExpand_content, nestedExpand_with_no_marks, non_nestable_block_content, orderedList, panel, paragraph, paragraph_with_alignment, paragraph_with_font_size, paragraph_with_font_size_and_alignment, paragraph_with_font_size_and_indentation, paragraph_with_indentation, paragraph_with_no_marks, placeholder, rule, status, strike, strong, subsup, table, tableCell, tableHeader, tableRow, taskItem, taskList, text, textColor, text_code_inline, text_formatted, text_link_inline, underline, syncBlock, bodiedSyncBlock, } from '@atlaskit/adf-schema/schema-validator';
@@ -4,5 +4,12 @@ import type { AttributesSpec, CreateSpecReturn, Validate, ValidationOptions } fr
4
4
  * We denormalised the spec to save bundle size.
5
5
  */
6
6
  export declare function createSpec(nodes?: Array<string>, marks?: Array<string>): CreateSpecReturn;
7
+ /**
8
+ * Validates attributes against the provided attribute specification.
9
+ */
7
10
  export declare function validateAttrs<T>(spec: AttributesSpec, value: T): boolean;
11
+ /**
12
+ * Creates a validator function for ADF documents.
13
+ * Validates document structure against the ADF specification.
14
+ */
8
15
  export declare function validator(nodes?: Array<string>, marks?: Array<string>, options?: ValidationOptions): Validate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/adf-utils",
3
- "version": "19.27.47",
3
+ "version": "19.29.0",
4
4
  "description": "Set of utilities to traverse, modify and create ADF documents.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -26,9 +26,9 @@
26
26
  "team": "Editor: Collaboration"
27
27
  },
28
28
  "dependencies": {
29
- "@atlaskit/adf-schema": "^52.6.0",
29
+ "@atlaskit/adf-schema": "^52.8.0",
30
30
  "@atlaskit/platform-feature-flags": "^1.1.0",
31
- "@atlaskit/tmp-editor-statsig": "^73.0.0",
31
+ "@atlaskit/tmp-editor-statsig": "^74.7.0",
32
32
  "@babel/runtime": "^7.0.0"
33
33
  },
34
34
  "devDependencies": {