@atlaskit/adf-utils 19.26.2 → 19.26.3

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.
Files changed (39) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/validator/extractAllowedContent.js +42 -0
  3. package/dist/cjs/validator/validator.js +27 -0
  4. package/dist/es2019/validator/extractAllowedContent.js +27 -0
  5. package/dist/es2019/validator/validator.js +16 -1
  6. package/dist/esm/validator/extractAllowedContent.js +35 -0
  7. package/dist/esm/validator/validator.js +28 -1
  8. package/dist/types/builders/marks/annotation.d.ts +2 -2
  9. package/dist/types/builders/marks/background-color.d.ts +2 -2
  10. package/dist/types/builders/marks/border.d.ts +2 -2
  11. package/dist/types/builders/marks/code.d.ts +2 -1
  12. package/dist/types/builders/marks/em.d.ts +2 -1
  13. package/dist/types/builders/marks/link.d.ts +2 -2
  14. package/dist/types/builders/marks/strike.d.ts +2 -1
  15. package/dist/types/builders/marks/strong.d.ts +2 -1
  16. package/dist/types/builders/marks/subsup.d.ts +2 -2
  17. package/dist/types/builders/marks/text-color.d.ts +2 -2
  18. package/dist/types/builders/marks/underline.d.ts +2 -1
  19. package/dist/types/builders/utils/apply-mark.d.ts +2 -1
  20. package/dist/types/types/validatorTypes.d.ts +1 -0
  21. package/dist/types/validator/extractAllowedContent.d.ts +3 -0
  22. package/dist/types/validator/validator.d.ts +6 -1
  23. package/dist/types-ts4.5/builders/marks/annotation.d.ts +2 -2
  24. package/dist/types-ts4.5/builders/marks/background-color.d.ts +2 -2
  25. package/dist/types-ts4.5/builders/marks/border.d.ts +2 -2
  26. package/dist/types-ts4.5/builders/marks/code.d.ts +2 -1
  27. package/dist/types-ts4.5/builders/marks/em.d.ts +2 -1
  28. package/dist/types-ts4.5/builders/marks/link.d.ts +2 -2
  29. package/dist/types-ts4.5/builders/marks/strike.d.ts +2 -1
  30. package/dist/types-ts4.5/builders/marks/strong.d.ts +2 -1
  31. package/dist/types-ts4.5/builders/marks/subsup.d.ts +2 -2
  32. package/dist/types-ts4.5/builders/marks/text-color.d.ts +2 -2
  33. package/dist/types-ts4.5/builders/marks/underline.d.ts +2 -1
  34. package/dist/types-ts4.5/builders/utils/apply-mark.d.ts +2 -1
  35. package/dist/types-ts4.5/types/validatorTypes.d.ts +1 -0
  36. package/dist/types-ts4.5/validator/extractAllowedContent.d.ts +3 -0
  37. package/dist/types-ts4.5/validator/validator.d.ts +6 -1
  38. package/docs/0-intro.tsx +2 -1
  39. package/package.json +4 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/adf-utils
2
2
 
3
+ ## 19.26.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`ca40c603642c7`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ca40c603642c7) -
8
+ If validating individual nodes, by default test validation with all available specs as the default
9
+ spec may not support the configuration
10
+
3
11
  ## 19.26.2
4
12
 
5
13
  ### Patch Changes
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.extractAllowedContent = extractAllowedContent;
8
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
+ function extractAllowedContent(validatorSpecs, entity) {
11
+ // Filter out content type + irrelevant nodes
12
+ var potentialAllowedContent = Object.entries(validatorSpecs).filter(function (item) {
13
+ var _item = (0, _slicedToArray2.default)(item, 2),
14
+ node = _item[0],
15
+ value = _item[1];
16
+ if (isValidatorSpec(value)) {
17
+ return node === entity.type;
18
+ }
19
+ var _ref = [value[0], value[1]],
20
+ nodeName = _ref[0],
21
+ spec = _ref[1];
22
+ if (typeof spec === 'string' || (0, _typeof2.default)(spec) !== 'object') {
23
+ return false;
24
+ }
25
+ return nodeName === entity.type;
26
+ });
27
+
28
+ // Keep types such as `mediaSingle_full` which contain additional spec information
29
+ var contentArray = potentialAllowedContent.map(function (allowedContent) {
30
+ if (isValidatorSpec(allowedContent)) {
31
+ return undefined;
32
+ }
33
+ var value = allowedContent[1];
34
+ return !isValidatorSpec(value) ? [[value[0], value[1]]] : undefined;
35
+ });
36
+ return contentArray.filter(function (x) {
37
+ return !!x;
38
+ });
39
+ }
40
+ function isValidatorSpec(spec) {
41
+ return spec.props !== undefined || spec.required !== undefined || spec.maxItems !== undefined || spec.minItems !== undefined;
42
+ }
@@ -5,18 +5,24 @@ var _typeof3 = require("@babel/runtime/helpers/typeof");
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
+ exports.createSpec = createSpec;
8
9
  exports.validateAttrs = validateAttrs;
9
10
  exports.validator = validator;
10
11
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
11
12
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
12
13
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
14
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
15
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
14
16
  var specs = _interopRequireWildcard(require("./specs"));
15
17
  var _utils = require("./utils");
16
18
  var _rules = require("./rules");
19
+ var _extractAllowedContent = require("./extractAllowedContent");
17
20
  var _excluded = ["items"]; // Ignored via go/ees005
18
21
  // eslint-disable-next-line import/no-namespace
19
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); }
23
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
24
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
25
+ 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; }
20
26
  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
27
  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
28
  // Ignored via go/ees005
@@ -329,6 +335,27 @@ function validator(nodes, marks, options) {
329
335
  _ref2$allowPrivateAtt = _ref2.allowPrivateAttributes,
330
336
  allowPrivateAttributes = _ref2$allowPrivateAtt === void 0 ? false : _ref2$allowPrivateAtt;
331
337
  var validate = function validate(entity, errorCallback, allowed, parentSpec) {
338
+ if (!allowed && (0, _platformFeatureFlags.fg)('platform_editor_ai_aifc_patch_ga')) {
339
+ var _iterator = _createForOfIteratorHelper((0, _extractAllowedContent.extractAllowedContent)(validatorSpecs, entity)),
340
+ _step;
341
+ try {
342
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
343
+ var _allowed = _step.value;
344
+ var _validationResult = validateNode(entity, errorCallback, _allowed, parentSpec);
345
+ if (_validationResult.valid) {
346
+ return {
347
+ entity: _validationResult.entity,
348
+ valid: _validationResult.valid
349
+ };
350
+ }
351
+ }
352
+ } catch (err) {
353
+ _iterator.e(err);
354
+ } finally {
355
+ _iterator.f();
356
+ }
357
+ }
358
+ // If `allowed` was provided or we haven't passed yet, return the initial result
332
359
  var validationResult = validateNode(entity, errorCallback, allowed, parentSpec);
333
360
  return {
334
361
  entity: validationResult.entity,
@@ -0,0 +1,27 @@
1
+ export function extractAllowedContent(validatorSpecs, entity) {
2
+ // Filter out content type + irrelevant nodes
3
+ const potentialAllowedContent = Object.entries(validatorSpecs).filter(item => {
4
+ const [node, value] = item;
5
+ if (isValidatorSpec(value)) {
6
+ return node === entity.type;
7
+ }
8
+ const [nodeName, spec] = [value[0], value[1]];
9
+ if (typeof spec === 'string' || typeof spec !== 'object') {
10
+ return false;
11
+ }
12
+ return nodeName === entity.type;
13
+ });
14
+
15
+ // Keep types such as `mediaSingle_full` which contain additional spec information
16
+ const contentArray = potentialAllowedContent.map(allowedContent => {
17
+ if (isValidatorSpec(allowedContent)) {
18
+ return undefined;
19
+ }
20
+ const value = allowedContent[1];
21
+ return !isValidatorSpec(value) ? [[value[0], value[1]]] : undefined;
22
+ });
23
+ return contentArray.filter(x => !!x);
24
+ }
25
+ function isValidatorSpec(spec) {
26
+ return spec.props !== undefined || spec.required !== undefined || spec.maxItems !== undefined || spec.minItems !== undefined;
27
+ }
@@ -1,8 +1,11 @@
1
+ import { fg } from '@atlaskit/platform-feature-flags';
2
+
1
3
  // Ignored via go/ees005
2
4
  // eslint-disable-next-line import/no-namespace
3
5
  import * as specs from './specs';
4
6
  import { copy, isBoolean, isDefined, isInteger, isNumber, isPlainObject, isString, makeArray } from './utils';
5
7
  import { validatorFnMap } from './rules';
8
+ import { extractAllowedContent } from './extractAllowedContent';
6
9
 
7
10
  // Ignored via go/ees005
8
11
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -45,7 +48,7 @@ const partitionObject = (obj, predicate) => Object.keys(obj).reduce((acc, key) =
45
48
  * Normalizes the structure of files imported from './specs'.
46
49
  * We denormalised the spec to save bundle size.
47
50
  */
48
- function createSpec(nodes, marks) {
51
+ export function createSpec(nodes, marks) {
49
52
  // Ignored via go/ees005
50
53
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
54
  return Object.keys(specs).reduce((newSpecs, k) => {
@@ -293,6 +296,18 @@ export function validator(nodes, marks, options) {
293
296
  allowPrivateAttributes = false
294
297
  } = options || {};
295
298
  const validate = (entity, errorCallback, allowed, parentSpec) => {
299
+ if (!allowed && fg('platform_editor_ai_aifc_patch_ga')) {
300
+ for (const allowed of extractAllowedContent(validatorSpecs, entity)) {
301
+ const validationResult = validateNode(entity, errorCallback, allowed, parentSpec);
302
+ if (validationResult.valid) {
303
+ return {
304
+ entity: validationResult.entity,
305
+ valid: validationResult.valid
306
+ };
307
+ }
308
+ }
309
+ }
310
+ // If `allowed` was provided or we haven't passed yet, return the initial result
296
311
  const validationResult = validateNode(entity, errorCallback, allowed, parentSpec);
297
312
  return {
298
313
  entity: validationResult.entity,
@@ -0,0 +1,35 @@
1
+ import _typeof from "@babel/runtime/helpers/typeof";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ export function extractAllowedContent(validatorSpecs, entity) {
4
+ // Filter out content type + irrelevant nodes
5
+ var potentialAllowedContent = Object.entries(validatorSpecs).filter(function (item) {
6
+ var _item = _slicedToArray(item, 2),
7
+ node = _item[0],
8
+ value = _item[1];
9
+ if (isValidatorSpec(value)) {
10
+ return node === entity.type;
11
+ }
12
+ var _ref = [value[0], value[1]],
13
+ nodeName = _ref[0],
14
+ spec = _ref[1];
15
+ if (typeof spec === 'string' || _typeof(spec) !== 'object') {
16
+ return false;
17
+ }
18
+ return nodeName === entity.type;
19
+ });
20
+
21
+ // Keep types such as `mediaSingle_full` which contain additional spec information
22
+ var contentArray = potentialAllowedContent.map(function (allowedContent) {
23
+ if (isValidatorSpec(allowedContent)) {
24
+ return undefined;
25
+ }
26
+ var value = allowedContent[1];
27
+ return !isValidatorSpec(value) ? [[value[0], value[1]]] : undefined;
28
+ });
29
+ return contentArray.filter(function (x) {
30
+ return !!x;
31
+ });
32
+ }
33
+ function isValidatorSpec(spec) {
34
+ return spec.props !== undefined || spec.required !== undefined || spec.maxItems !== undefined || spec.minItems !== undefined;
35
+ }
@@ -3,13 +3,19 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
4
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
5
5
  var _excluded = ["items"];
6
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
7
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
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; }
6
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; }
7
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 { fg } from '@atlaskit/platform-feature-flags';
12
+
8
13
  // Ignored via go/ees005
9
14
  // eslint-disable-next-line import/no-namespace
10
15
  import * as specs from './specs';
11
16
  import { copy, isBoolean, isDefined, isInteger, isNumber, isPlainObject, isString, makeArray } from './utils';
12
17
  import { validatorFnMap } from './rules';
18
+ import { extractAllowedContent } from './extractAllowedContent';
13
19
 
14
20
  // Ignored via go/ees005
15
21
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -53,7 +59,7 @@ var partitionObject = function partitionObject(obj, predicate) {
53
59
  * Normalizes the structure of files imported from './specs'.
54
60
  * We denormalised the spec to save bundle size.
55
61
  */
56
- function createSpec(nodes, marks) {
62
+ export function createSpec(nodes, marks) {
57
63
  // Ignored via go/ees005
58
64
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
65
  return Object.keys(specs).reduce(function (newSpecs, k) {
@@ -321,6 +327,27 @@ export function validator(nodes, marks, options) {
321
327
  _ref2$allowPrivateAtt = _ref2.allowPrivateAttributes,
322
328
  allowPrivateAttributes = _ref2$allowPrivateAtt === void 0 ? false : _ref2$allowPrivateAtt;
323
329
  var validate = function validate(entity, errorCallback, allowed, parentSpec) {
330
+ if (!allowed && fg('platform_editor_ai_aifc_patch_ga')) {
331
+ var _iterator = _createForOfIteratorHelper(extractAllowedContent(validatorSpecs, entity)),
332
+ _step;
333
+ try {
334
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
335
+ var _allowed = _step.value;
336
+ var _validationResult = validateNode(entity, errorCallback, _allowed, parentSpec);
337
+ if (_validationResult.valid) {
338
+ return {
339
+ entity: _validationResult.entity,
340
+ valid: _validationResult.valid
341
+ };
342
+ }
343
+ }
344
+ } catch (err) {
345
+ _iterator.e(err);
346
+ } finally {
347
+ _iterator.f();
348
+ }
349
+ }
350
+ // If `allowed` was provided or we haven't passed yet, return the initial result
324
351
  var validationResult = validateNode(entity, errorCallback, allowed, parentSpec);
325
352
  return {
326
353
  entity: validationResult.entity,
@@ -1,3 +1,3 @@
1
- import { type AnnotationMarkAttributes } from '@atlaskit/adf-schema';
1
+ import { type AnnotationMarkAttributes, type TextDefinition } from '@atlaskit/adf-schema';
2
2
  import { type WithMark } from '../types';
3
- export declare const annotation: (attrs: AnnotationMarkAttributes) => (maybeNode: WithMark | string) => WithMark | import("@atlaskit/adf-schema").TextDefinition;
3
+ export declare const annotation: (attrs: AnnotationMarkAttributes) => (maybeNode: WithMark | string) => WithMark | TextDefinition;
@@ -1,3 +1,3 @@
1
- import type { TextColorAttributes } from '@atlaskit/adf-schema';
1
+ import type { TextColorAttributes, TextDefinition } from '@atlaskit/adf-schema';
2
2
  import type { WithMark } from '../types';
3
- export declare const backgroundColor: (attrs: TextColorAttributes) => (maybeNode: WithMark | string) => WithMark | import("@atlaskit/adf-schema").TextDefinition;
3
+ export declare const backgroundColor: (attrs: TextColorAttributes) => (maybeNode: WithMark | string) => WithMark | TextDefinition;
@@ -1,3 +1,3 @@
1
- import { type BorderMarkAttributes } from '@atlaskit/adf-schema';
1
+ import { type BorderMarkAttributes, type TextDefinition } from '@atlaskit/adf-schema';
2
2
  import { type WithMark } from '../types';
3
- export declare const border: (attrs: BorderMarkAttributes) => (maybeNode: WithMark | string) => WithMark | import("@atlaskit/adf-schema").TextDefinition;
3
+ export declare const border: (attrs: BorderMarkAttributes) => (maybeNode: WithMark | string) => WithMark | TextDefinition;
@@ -1,2 +1,3 @@
1
+ import { type TextDefinition } from '@atlaskit/adf-schema';
1
2
  import { type WithMark } from '../types';
2
- export declare const code: (maybeNode: WithMark | string) => WithMark | import("@atlaskit/adf-schema").TextDefinition;
3
+ export declare const code: (maybeNode: WithMark | string) => WithMark | TextDefinition;
@@ -1,2 +1,3 @@
1
+ import { type TextDefinition } from '@atlaskit/adf-schema';
1
2
  import { type WithMark } from '../types';
2
- export declare const em: (maybeNode: WithMark | string) => WithMark | import("@atlaskit/adf-schema").TextDefinition;
3
+ export declare const em: (maybeNode: WithMark | string) => WithMark | TextDefinition;
@@ -1,3 +1,3 @@
1
- import { type LinkAttributes } from '@atlaskit/adf-schema';
1
+ import { type LinkAttributes, type TextDefinition } from '@atlaskit/adf-schema';
2
2
  import { type WithMark } from '../types';
3
- export declare const link: (attrs: LinkAttributes) => (maybeNode: WithMark | string) => WithMark | import("@atlaskit/adf-schema").TextDefinition;
3
+ export declare const link: (attrs: LinkAttributes) => (maybeNode: WithMark | string) => WithMark | TextDefinition;
@@ -1,2 +1,3 @@
1
+ import { type TextDefinition } from '@atlaskit/adf-schema';
1
2
  import { type WithMark } from '../types';
2
- export declare const strike: (maybeNode: WithMark | string) => WithMark | import("@atlaskit/adf-schema").TextDefinition;
3
+ export declare const strike: (maybeNode: WithMark | string) => WithMark | TextDefinition;
@@ -1,2 +1,3 @@
1
+ import { type TextDefinition } from '@atlaskit/adf-schema';
1
2
  import { type WithMark } from '../types';
2
- export declare const strong: (maybeNode: WithMark | string) => WithMark | import("@atlaskit/adf-schema").TextDefinition;
3
+ export declare const strong: (maybeNode: WithMark | string) => WithMark | TextDefinition;
@@ -1,3 +1,3 @@
1
- import { type SubSupAttributes } from '@atlaskit/adf-schema';
1
+ import { type SubSupAttributes, type TextDefinition } from '@atlaskit/adf-schema';
2
2
  import { type WithMark } from '../types';
3
- export declare const subsup: (attrs: SubSupAttributes) => (maybeNode: WithMark | string) => WithMark | import("@atlaskit/adf-schema").TextDefinition;
3
+ export declare const subsup: (attrs: SubSupAttributes) => (maybeNode: WithMark | string) => WithMark | TextDefinition;
@@ -1,3 +1,3 @@
1
- import { type TextColorAttributes } from '@atlaskit/adf-schema';
1
+ import { type TextColorAttributes, type TextDefinition } from '@atlaskit/adf-schema';
2
2
  import { type WithMark } from '../types';
3
- export declare const textColor: (attrs: TextColorAttributes) => (maybeNode: WithMark | string) => WithMark | import("@atlaskit/adf-schema").TextDefinition;
3
+ export declare const textColor: (attrs: TextColorAttributes) => (maybeNode: WithMark | string) => WithMark | TextDefinition;
@@ -1,2 +1,3 @@
1
+ import { type TextDefinition } from '@atlaskit/adf-schema';
1
2
  import { type WithMark } from '../types';
2
- export declare const underline: (maybeNode: WithMark | string) => WithMark | import("@atlaskit/adf-schema").TextDefinition;
3
+ export declare const underline: (maybeNode: WithMark | string) => WithMark | TextDefinition;
@@ -1,4 +1,5 @@
1
1
  import { type WithMark } from '../types';
2
+ import type { TextDefinition } from '@atlaskit/adf-schema';
2
3
  export declare function applyMark<T>(mark: T & {
3
4
  type: string;
4
- }, maybeNode: WithMark | string): WithMark | import("@atlaskit/adf-schema").TextDefinition;
5
+ }, maybeNode: WithMark | string): WithMark | TextDefinition;
@@ -143,3 +143,4 @@ export interface ErrorCallbackOptions {
143
143
  isNodeAttribute?: boolean;
144
144
  }
145
145
  export type Validate = (entity: ADFEntity, errorCallback?: ErrorCallback, allowed?: Content, parentSpec?: ValidatorSpec) => Output;
146
+ export type CreateSpecReturn = Record<string, ValidatorSpec | Record<string, ValidatorSpec | string>>;
@@ -0,0 +1,3 @@
1
+ import type { ADFEntity } from '../types';
2
+ import type { Content, CreateSpecReturn } from '../types/validatorTypes';
3
+ export declare function extractAllowedContent(validatorSpecs: CreateSpecReturn, entity: ADFEntity): Content[];
@@ -1,3 +1,8 @@
1
- import type { AttributesSpec, ValidationOptions, Validate } from '../types/validatorTypes';
1
+ import type { AttributesSpec, ValidationOptions, Validate, CreateSpecReturn } from '../types/validatorTypes';
2
+ /**
3
+ * Normalizes the structure of files imported from './specs'.
4
+ * We denormalised the spec to save bundle size.
5
+ */
6
+ export declare function createSpec(nodes?: Array<string>, marks?: Array<string>): CreateSpecReturn;
2
7
  export declare function validateAttrs<T>(spec: AttributesSpec, value: T): boolean;
3
8
  export declare function validator(nodes?: Array<string>, marks?: Array<string>, options?: ValidationOptions): Validate;
@@ -1,3 +1,3 @@
1
- import { type AnnotationMarkAttributes } from '@atlaskit/adf-schema';
1
+ import { type AnnotationMarkAttributes, type TextDefinition } from '@atlaskit/adf-schema';
2
2
  import { type WithMark } from '../types';
3
- export declare const annotation: (attrs: AnnotationMarkAttributes) => (maybeNode: WithMark | string) => WithMark | import("@atlaskit/adf-schema").TextDefinition;
3
+ export declare const annotation: (attrs: AnnotationMarkAttributes) => (maybeNode: WithMark | string) => WithMark | TextDefinition;
@@ -1,3 +1,3 @@
1
- import type { TextColorAttributes } from '@atlaskit/adf-schema';
1
+ import type { TextColorAttributes, TextDefinition } from '@atlaskit/adf-schema';
2
2
  import type { WithMark } from '../types';
3
- export declare const backgroundColor: (attrs: TextColorAttributes) => (maybeNode: WithMark | string) => WithMark | import("@atlaskit/adf-schema").TextDefinition;
3
+ export declare const backgroundColor: (attrs: TextColorAttributes) => (maybeNode: WithMark | string) => WithMark | TextDefinition;
@@ -1,3 +1,3 @@
1
- import { type BorderMarkAttributes } from '@atlaskit/adf-schema';
1
+ import { type BorderMarkAttributes, type TextDefinition } from '@atlaskit/adf-schema';
2
2
  import { type WithMark } from '../types';
3
- export declare const border: (attrs: BorderMarkAttributes) => (maybeNode: WithMark | string) => WithMark | import("@atlaskit/adf-schema").TextDefinition;
3
+ export declare const border: (attrs: BorderMarkAttributes) => (maybeNode: WithMark | string) => WithMark | TextDefinition;
@@ -1,2 +1,3 @@
1
+ import { type TextDefinition } from '@atlaskit/adf-schema';
1
2
  import { type WithMark } from '../types';
2
- export declare const code: (maybeNode: WithMark | string) => WithMark | import("@atlaskit/adf-schema").TextDefinition;
3
+ export declare const code: (maybeNode: WithMark | string) => WithMark | TextDefinition;
@@ -1,2 +1,3 @@
1
+ import { type TextDefinition } from '@atlaskit/adf-schema';
1
2
  import { type WithMark } from '../types';
2
- export declare const em: (maybeNode: WithMark | string) => WithMark | import("@atlaskit/adf-schema").TextDefinition;
3
+ export declare const em: (maybeNode: WithMark | string) => WithMark | TextDefinition;
@@ -1,3 +1,3 @@
1
- import { type LinkAttributes } from '@atlaskit/adf-schema';
1
+ import { type LinkAttributes, type TextDefinition } from '@atlaskit/adf-schema';
2
2
  import { type WithMark } from '../types';
3
- export declare const link: (attrs: LinkAttributes) => (maybeNode: WithMark | string) => WithMark | import("@atlaskit/adf-schema").TextDefinition;
3
+ export declare const link: (attrs: LinkAttributes) => (maybeNode: WithMark | string) => WithMark | TextDefinition;
@@ -1,2 +1,3 @@
1
+ import { type TextDefinition } from '@atlaskit/adf-schema';
1
2
  import { type WithMark } from '../types';
2
- export declare const strike: (maybeNode: WithMark | string) => WithMark | import("@atlaskit/adf-schema").TextDefinition;
3
+ export declare const strike: (maybeNode: WithMark | string) => WithMark | TextDefinition;
@@ -1,2 +1,3 @@
1
+ import { type TextDefinition } from '@atlaskit/adf-schema';
1
2
  import { type WithMark } from '../types';
2
- export declare const strong: (maybeNode: WithMark | string) => WithMark | import("@atlaskit/adf-schema").TextDefinition;
3
+ export declare const strong: (maybeNode: WithMark | string) => WithMark | TextDefinition;
@@ -1,3 +1,3 @@
1
- import { type SubSupAttributes } from '@atlaskit/adf-schema';
1
+ import { type SubSupAttributes, type TextDefinition } from '@atlaskit/adf-schema';
2
2
  import { type WithMark } from '../types';
3
- export declare const subsup: (attrs: SubSupAttributes) => (maybeNode: WithMark | string) => WithMark | import("@atlaskit/adf-schema").TextDefinition;
3
+ export declare const subsup: (attrs: SubSupAttributes) => (maybeNode: WithMark | string) => WithMark | TextDefinition;
@@ -1,3 +1,3 @@
1
- import { type TextColorAttributes } from '@atlaskit/adf-schema';
1
+ import { type TextColorAttributes, type TextDefinition } from '@atlaskit/adf-schema';
2
2
  import { type WithMark } from '../types';
3
- export declare const textColor: (attrs: TextColorAttributes) => (maybeNode: WithMark | string) => WithMark | import("@atlaskit/adf-schema").TextDefinition;
3
+ export declare const textColor: (attrs: TextColorAttributes) => (maybeNode: WithMark | string) => WithMark | TextDefinition;
@@ -1,2 +1,3 @@
1
+ import { type TextDefinition } from '@atlaskit/adf-schema';
1
2
  import { type WithMark } from '../types';
2
- export declare const underline: (maybeNode: WithMark | string) => WithMark | import("@atlaskit/adf-schema").TextDefinition;
3
+ export declare const underline: (maybeNode: WithMark | string) => WithMark | TextDefinition;
@@ -1,4 +1,5 @@
1
1
  import { type WithMark } from '../types';
2
+ import type { TextDefinition } from '@atlaskit/adf-schema';
2
3
  export declare function applyMark<T>(mark: T & {
3
4
  type: string;
4
- }, maybeNode: WithMark | string): WithMark | import("@atlaskit/adf-schema").TextDefinition;
5
+ }, maybeNode: WithMark | string): WithMark | TextDefinition;
@@ -146,3 +146,4 @@ export interface ErrorCallbackOptions {
146
146
  isNodeAttribute?: boolean;
147
147
  }
148
148
  export type Validate = (entity: ADFEntity, errorCallback?: ErrorCallback, allowed?: Content, parentSpec?: ValidatorSpec) => Output;
149
+ export type CreateSpecReturn = Record<string, ValidatorSpec | Record<string, ValidatorSpec | string>>;
@@ -0,0 +1,3 @@
1
+ import type { ADFEntity } from '../types';
2
+ import type { Content, CreateSpecReturn } from '../types/validatorTypes';
3
+ export declare function extractAllowedContent(validatorSpecs: CreateSpecReturn, entity: ADFEntity): Content[];
@@ -1,3 +1,8 @@
1
- import type { AttributesSpec, ValidationOptions, Validate } from '../types/validatorTypes';
1
+ import type { AttributesSpec, ValidationOptions, Validate, CreateSpecReturn } from '../types/validatorTypes';
2
+ /**
3
+ * Normalizes the structure of files imported from './specs'.
4
+ * We denormalised the spec to save bundle size.
5
+ */
6
+ export declare function createSpec(nodes?: Array<string>, marks?: Array<string>): CreateSpecReturn;
2
7
  export declare function validateAttrs<T>(spec: AttributesSpec, value: T): boolean;
3
8
  export declare function validator(nodes?: Array<string>, marks?: Array<string>, options?: ValidationOptions): Validate;
package/docs/0-intro.tsx CHANGED
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { md, code, Props } from '@atlaskit/docs';
3
3
 
4
- export default md`
4
+ const _default_1: React.ReactElement = md`
5
5
  ## Why?
6
6
 
7
7
  Working with ADF might be tricky at times, especially extracting data or manipulating existing documents.
@@ -561,3 +561,4 @@ export default md`
561
561
  * strong -> b
562
562
  * underline -> u
563
563
  `;
564
+ export default _default_1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/adf-utils",
3
- "version": "19.26.2",
3
+ "version": "19.26.3",
4
4
  "description": "Set of utilities to traverse, modify and create ADF documents.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -52,6 +52,9 @@
52
52
  "platform-feature-flags": {
53
53
  "platform_adf-utils_fix-dummy-text-index-oob": {
54
54
  "type": "boolean"
55
+ },
56
+ "platform_editor_ai_aifc_patch_ga": {
57
+ "type": "boolean"
55
58
  }
56
59
  }
57
60
  }