@atlaskit/adf-schema 26.3.0 → 26.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/adf-schema
2
2
 
3
+ ## 26.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`1bab0faa2c8`](https://bitbucket.org/atlassian/atlassian-frontend/commits/1bab0faa2c8) - Add a new custom ProseMirror step OverrideDocumentStep for easy document replacing.
8
+
3
9
  ## 26.3.0
4
10
 
5
11
  ### Minor Changes
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.overrideDocumentStepType = exports.OverrideDocumentStep = void 0;
8
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
11
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
12
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
13
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
14
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
15
+ var _prosemirrorTransform = require("prosemirror-transform");
16
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
17
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
18
+ var overrideDocumentStepType = 'override-document';
19
+ exports.overrideDocumentStepType = overrideDocumentStepType;
20
+ var OverrideDocumentStep = /*#__PURE__*/function (_Step) {
21
+ (0, _inherits2.default)(OverrideDocumentStep, _Step);
22
+ var _super = _createSuper(OverrideDocumentStep);
23
+ function OverrideDocumentStep(opts) {
24
+ var _this;
25
+ (0, _classCallCheck2.default)(this, OverrideDocumentStep);
26
+ _this = _super.call(this);
27
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "inverted", false);
28
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "oldDocumentSize", 0);
29
+ var inverted = opts.inverted,
30
+ nextDocument = opts.nextDocument;
31
+ if (nextDocument.type.name !== 'doc') {
32
+ throw new Error('nextDocument should be the entire prosemirror doc node and not only its content.');
33
+ }
34
+ _this.nextDocument = nextDocument;
35
+ _this.inverted = Boolean(inverted);
36
+ return _this;
37
+ }
38
+ (0, _createClass2.default)(OverrideDocumentStep, [{
39
+ key: "apply",
40
+ value: function apply(doc) {
41
+ this.oldDocumentSize = doc.content.size;
42
+ return _prosemirrorTransform.StepResult.ok(this.nextDocument);
43
+ }
44
+ }, {
45
+ key: "map",
46
+ value: function map() {
47
+ return new OverrideDocumentStep({
48
+ nextDocument: this.nextDocument,
49
+ inverted: this.inverted
50
+ });
51
+ }
52
+ }, {
53
+ key: "getMap",
54
+ value: function getMap() {
55
+ if (!this.nextDocument || !this.oldDocumentSize) {
56
+ return new _prosemirrorTransform.StepMap([0, 0, 0]);
57
+ }
58
+ var oldSize = this.oldDocumentSize;
59
+ var nextDocumentSize = this.nextDocument.content.size;
60
+ return new _prosemirrorTransform.StepMap([0, oldSize, nextDocumentSize]);
61
+ }
62
+ }, {
63
+ key: "invert",
64
+ value: function invert(doc) {
65
+ return new OverrideDocumentStep({
66
+ nextDocument: doc,
67
+ inverted: true
68
+ });
69
+ }
70
+ }, {
71
+ key: "toJSON",
72
+ value: function toJSON() {
73
+ return {
74
+ stepType: overrideDocumentStepType,
75
+ inverted: this.inverted,
76
+ nextDocument: this.nextDocument.toJSON()
77
+ };
78
+ }
79
+ }], [{
80
+ key: "fromJSON",
81
+ value: function fromJSON(schema, json) {
82
+ if (!json || json.stepType !== overrideDocumentStepType) {
83
+ throw new RangeError('Invalid overrideDocument step OverrideDocumentStep.fromJSON');
84
+ }
85
+ return new OverrideDocumentStep({
86
+ inverted: json.inverted,
87
+ nextDocument: schema.nodeFromJSON(json.nextDocument)
88
+ });
89
+ }
90
+ }]);
91
+ return OverrideDocumentStep;
92
+ }(_prosemirrorTransform.Step);
93
+ exports.OverrideDocumentStep = OverrideDocumentStep;
94
+ _prosemirrorTransform.Step.jsonID(overrideDocumentStepType, OverrideDocumentStep);
package/dist/cjs/steps.js CHANGED
@@ -33,6 +33,12 @@ Object.defineProperty(exports, "LinkMetaStep", {
33
33
  return _linkMetaStep.LinkMetaStep;
34
34
  }
35
35
  });
36
+ Object.defineProperty(exports, "OverrideDocumentStep", {
37
+ enumerable: true,
38
+ get: function get() {
39
+ return _overrideDocumentStep.OverrideDocumentStep;
40
+ }
41
+ });
36
42
  Object.defineProperty(exports, "SetAttrsStep", {
37
43
  enumerable: true,
38
44
  get: function get() {
@@ -57,4 +63,5 @@ var _typeAhead = require("./steps/type-ahead");
57
63
  var _addColumn = require("./steps/table/add-column");
58
64
  var _setAttrs = require("./steps/set-attrs");
59
65
  var _analytics = require("./steps/analytics");
60
- var _linkMetaStep = require("./steps/link-meta-step");
66
+ var _linkMetaStep = require("./steps/link-meta-step");
67
+ var _overrideDocumentStep = require("./steps/override-document-step");
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/adf-schema",
3
- "version": "26.3.0",
3
+ "version": "26.4.0",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,60 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import { Step, StepResult, StepMap } from 'prosemirror-transform';
3
+ export const overrideDocumentStepType = 'override-document';
4
+ export class OverrideDocumentStep extends Step {
5
+ constructor(opts) {
6
+ super();
7
+ _defineProperty(this, "inverted", false);
8
+ _defineProperty(this, "oldDocumentSize", 0);
9
+ const {
10
+ inverted,
11
+ nextDocument
12
+ } = opts;
13
+ if (nextDocument.type.name !== 'doc') {
14
+ throw new Error('nextDocument should be the entire prosemirror doc node and not only its content.');
15
+ }
16
+ this.nextDocument = nextDocument;
17
+ this.inverted = Boolean(inverted);
18
+ }
19
+ apply(doc) {
20
+ this.oldDocumentSize = doc.content.size;
21
+ return StepResult.ok(this.nextDocument);
22
+ }
23
+ map() {
24
+ return new OverrideDocumentStep({
25
+ nextDocument: this.nextDocument,
26
+ inverted: this.inverted
27
+ });
28
+ }
29
+ getMap() {
30
+ if (!this.nextDocument || !this.oldDocumentSize) {
31
+ return new StepMap([0, 0, 0]);
32
+ }
33
+ const oldSize = this.oldDocumentSize;
34
+ const nextDocumentSize = this.nextDocument.content.size;
35
+ return new StepMap([0, oldSize, nextDocumentSize]);
36
+ }
37
+ invert(doc) {
38
+ return new OverrideDocumentStep({
39
+ nextDocument: doc,
40
+ inverted: true
41
+ });
42
+ }
43
+ toJSON() {
44
+ return {
45
+ stepType: overrideDocumentStepType,
46
+ inverted: this.inverted,
47
+ nextDocument: this.nextDocument.toJSON()
48
+ };
49
+ }
50
+ static fromJSON(schema, json) {
51
+ if (!json || json.stepType !== overrideDocumentStepType) {
52
+ throw new RangeError('Invalid overrideDocument step OverrideDocumentStep.fromJSON');
53
+ }
54
+ return new OverrideDocumentStep({
55
+ inverted: json.inverted,
56
+ nextDocument: schema.nodeFromJSON(json.nextDocument)
57
+ });
58
+ }
59
+ }
60
+ Step.jsonID(overrideDocumentStepType, OverrideDocumentStep);
@@ -4,4 +4,5 @@ export { InsertTypeAheadStages, InsertTypeAheadStep } from './steps/type-ahead';
4
4
  export { AddColumnStep } from './steps/table/add-column';
5
5
  export { SetAttrsStep } from './steps/set-attrs';
6
6
  export { AnalyticsStep } from './steps/analytics';
7
- export { LinkMetaStep } from './steps/link-meta-step';
7
+ export { LinkMetaStep } from './steps/link-meta-step';
8
+ export { OverrideDocumentStep } from './steps/override-document-step';
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/adf-schema",
3
- "version": "26.3.0",
3
+ "version": "26.4.0",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,85 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
4
+ import _inherits from "@babel/runtime/helpers/inherits";
5
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
9
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
10
+ import { Step, StepResult, StepMap } from 'prosemirror-transform';
11
+ export var overrideDocumentStepType = 'override-document';
12
+ export var OverrideDocumentStep = /*#__PURE__*/function (_Step) {
13
+ _inherits(OverrideDocumentStep, _Step);
14
+ var _super = _createSuper(OverrideDocumentStep);
15
+ function OverrideDocumentStep(opts) {
16
+ var _this;
17
+ _classCallCheck(this, OverrideDocumentStep);
18
+ _this = _super.call(this);
19
+ _defineProperty(_assertThisInitialized(_this), "inverted", false);
20
+ _defineProperty(_assertThisInitialized(_this), "oldDocumentSize", 0);
21
+ var inverted = opts.inverted,
22
+ nextDocument = opts.nextDocument;
23
+ if (nextDocument.type.name !== 'doc') {
24
+ throw new Error('nextDocument should be the entire prosemirror doc node and not only its content.');
25
+ }
26
+ _this.nextDocument = nextDocument;
27
+ _this.inverted = Boolean(inverted);
28
+ return _this;
29
+ }
30
+ _createClass(OverrideDocumentStep, [{
31
+ key: "apply",
32
+ value: function apply(doc) {
33
+ this.oldDocumentSize = doc.content.size;
34
+ return StepResult.ok(this.nextDocument);
35
+ }
36
+ }, {
37
+ key: "map",
38
+ value: function map() {
39
+ return new OverrideDocumentStep({
40
+ nextDocument: this.nextDocument,
41
+ inverted: this.inverted
42
+ });
43
+ }
44
+ }, {
45
+ key: "getMap",
46
+ value: function getMap() {
47
+ if (!this.nextDocument || !this.oldDocumentSize) {
48
+ return new StepMap([0, 0, 0]);
49
+ }
50
+ var oldSize = this.oldDocumentSize;
51
+ var nextDocumentSize = this.nextDocument.content.size;
52
+ return new StepMap([0, oldSize, nextDocumentSize]);
53
+ }
54
+ }, {
55
+ key: "invert",
56
+ value: function invert(doc) {
57
+ return new OverrideDocumentStep({
58
+ nextDocument: doc,
59
+ inverted: true
60
+ });
61
+ }
62
+ }, {
63
+ key: "toJSON",
64
+ value: function toJSON() {
65
+ return {
66
+ stepType: overrideDocumentStepType,
67
+ inverted: this.inverted,
68
+ nextDocument: this.nextDocument.toJSON()
69
+ };
70
+ }
71
+ }], [{
72
+ key: "fromJSON",
73
+ value: function fromJSON(schema, json) {
74
+ if (!json || json.stepType !== overrideDocumentStepType) {
75
+ throw new RangeError('Invalid overrideDocument step OverrideDocumentStep.fromJSON');
76
+ }
77
+ return new OverrideDocumentStep({
78
+ inverted: json.inverted,
79
+ nextDocument: schema.nodeFromJSON(json.nextDocument)
80
+ });
81
+ }
82
+ }]);
83
+ return OverrideDocumentStep;
84
+ }(Step);
85
+ Step.jsonID(overrideDocumentStepType, OverrideDocumentStep);
package/dist/esm/steps.js CHANGED
@@ -4,4 +4,5 @@ export { InsertTypeAheadStages, InsertTypeAheadStep } from './steps/type-ahead';
4
4
  export { AddColumnStep } from './steps/table/add-column';
5
5
  export { SetAttrsStep } from './steps/set-attrs';
6
6
  export { AnalyticsStep } from './steps/analytics';
7
- export { LinkMetaStep } from './steps/link-meta-step';
7
+ export { LinkMetaStep } from './steps/link-meta-step';
8
+ export { OverrideDocumentStep } from './steps/override-document-step';
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/adf-schema",
3
- "version": "26.3.0",
3
+ "version": "26.4.0",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,27 @@
1
+ import { Step, StepResult, StepMap } from 'prosemirror-transform';
2
+ import { Node as PMNode, Schema } from 'prosemirror-model';
3
+ type Options = {
4
+ nextDocument: PMNode;
5
+ inverted?: boolean;
6
+ };
7
+ export declare const overrideDocumentStepType = "override-document";
8
+ export declare class OverrideDocumentStep extends Step {
9
+ inverted: boolean;
10
+ private nextDocument;
11
+ private oldDocumentSize;
12
+ constructor(opts: Options);
13
+ apply(doc: PMNode): StepResult;
14
+ map(): OverrideDocumentStep;
15
+ getMap(): StepMap;
16
+ invert(doc: PMNode): OverrideDocumentStep;
17
+ toJSON(): OverrideDocumentStepJSON;
18
+ static fromJSON(schema: Schema, json: OverrideDocumentStepJSON): OverrideDocumentStep;
19
+ }
20
+ export type OverrideDocumentStepJSON = {
21
+ stepType: 'override-document';
22
+ inverted: boolean;
23
+ nextDocument: {
24
+ [key: string]: any;
25
+ };
26
+ };
27
+ export {};
@@ -8,3 +8,5 @@ export type { TableColumnOrdering } from './steps/table/types';
8
8
  export type { AnalyticsInvertStep, AnalyticsWithChannel, AnalyticsPayload, } from './steps/analytics';
9
9
  export { LinkMetaStep } from './steps/link-meta-step';
10
10
  export type { LinkStepMetadata } from './steps/link-meta-step';
11
+ export { OverrideDocumentStep } from './steps/override-document-step';
12
+ export type { OverrideDocumentStepJSON } from './steps/override-document-step';
@@ -0,0 +1,27 @@
1
+ import { Step, StepResult, StepMap } from 'prosemirror-transform';
2
+ import { Node as PMNode, Schema } from 'prosemirror-model';
3
+ type Options = {
4
+ nextDocument: PMNode;
5
+ inverted?: boolean;
6
+ };
7
+ export declare const overrideDocumentStepType = "override-document";
8
+ export declare class OverrideDocumentStep extends Step {
9
+ inverted: boolean;
10
+ private nextDocument;
11
+ private oldDocumentSize;
12
+ constructor(opts: Options);
13
+ apply(doc: PMNode): StepResult;
14
+ map(): OverrideDocumentStep;
15
+ getMap(): StepMap;
16
+ invert(doc: PMNode): OverrideDocumentStep;
17
+ toJSON(): OverrideDocumentStepJSON;
18
+ static fromJSON(schema: Schema, json: OverrideDocumentStepJSON): OverrideDocumentStep;
19
+ }
20
+ export type OverrideDocumentStepJSON = {
21
+ stepType: 'override-document';
22
+ inverted: boolean;
23
+ nextDocument: {
24
+ [key: string]: any;
25
+ };
26
+ };
27
+ export {};
@@ -8,3 +8,5 @@ export type { TableColumnOrdering } from './steps/table/types';
8
8
  export type { AnalyticsInvertStep, AnalyticsWithChannel, AnalyticsPayload, } from './steps/analytics';
9
9
  export { LinkMetaStep } from './steps/link-meta-step';
10
10
  export type { LinkStepMetadata } from './steps/link-meta-step';
11
+ export { OverrideDocumentStep } from './steps/override-document-step';
12
+ export type { OverrideDocumentStepJSON } from './steps/override-document-step';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/adf-schema",
3
- "version": "26.3.0",
3
+ "version": "26.4.0",
4
4
  "description": "Shared package that contains the ADF-schema (json) and ProseMirror node/mark specs",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"