@atlaskit/editor-prosemirror
Advanced tools
Comparing version 6.1.1 to 6.1.2
# @atlaskit/editor-prosemirror | ||
## 6.1.2 | ||
### Patch Changes | ||
- faee55a: Additional tests for metadata monkey patch | ||
## 6.1.1 | ||
@@ -4,0 +10,0 @@ |
@@ -22,21 +22,22 @@ "use strict"; | ||
var stepImplementation = originalFromJSON(schema, jsonStep); | ||
if (jsonStep.metadata) { | ||
return new Proxy(stepImplementation, { | ||
get: function get(target, prop, receiver) { | ||
if (prop === 'toJSON') { | ||
var toJSONfunc = target[prop]; | ||
return new Proxy(toJSONfunc, { | ||
apply: function apply(target, thisArg, argArray) { | ||
var originalResult = Reflect.apply(target, thisArg, argArray); | ||
return _objectSpread({ | ||
metadata: _objectSpread(_objectSpread({}, jsonStep.metadata), originalResult.metadata || {}) | ||
}, originalResult); | ||
} | ||
}); | ||
} | ||
return Reflect.get(target, prop, receiver); | ||
return new Proxy(stepImplementation, { | ||
get: function get(target, prop, receiver) { | ||
if (prop === 'toJSON') { | ||
var toJSONfunc = Reflect.get(target, prop, receiver); | ||
// @ts-expect-error Metadata may or may not exist at this stage, depending on step type, | ||
// but also additions outside of the type system that others may have done. | ||
var classMetadata = target.metadata; | ||
return new Proxy(toJSONfunc, { | ||
apply: function apply(target, thisArg, argArray) { | ||
var originalResult = Reflect.apply(target, thisArg, argArray); | ||
var metadata = _objectSpread(_objectSpread(_objectSpread({}, jsonStep.metadata), classMetadata), originalResult.metadata); | ||
return _objectSpread(_objectSpread({}, originalResult), Object.keys(metadata).length === 0 ? {} : { | ||
metadata: metadata | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
return stepImplementation; | ||
return Reflect.get(target, prop, receiver); | ||
} | ||
}); | ||
}; |
@@ -7,26 +7,30 @@ import { Step } from 'prosemirror-transform'; | ||
const stepImplementation = originalFromJSON(schema, jsonStep); | ||
if (jsonStep.metadata) { | ||
return new Proxy(stepImplementation, { | ||
get(target, prop, receiver) { | ||
if (prop === 'toJSON') { | ||
const toJSONfunc = target[prop]; | ||
return new Proxy(toJSONfunc, { | ||
apply(target, thisArg, argArray) { | ||
const originalResult = Reflect.apply(target, thisArg, argArray); | ||
return { | ||
metadata: { | ||
...jsonStep.metadata, | ||
...(originalResult.metadata || {}) | ||
}, | ||
...originalResult | ||
}; | ||
} | ||
}); | ||
} | ||
return Reflect.get(target, prop, receiver); | ||
return new Proxy(stepImplementation, { | ||
get(target, prop, receiver) { | ||
if (prop === 'toJSON') { | ||
const toJSONfunc = Reflect.get(target, prop, receiver); | ||
// @ts-expect-error Metadata may or may not exist at this stage, depending on step type, | ||
// but also additions outside of the type system that others may have done. | ||
const classMetadata = target.metadata; | ||
return new Proxy(toJSONfunc, { | ||
apply(target, thisArg, argArray) { | ||
const originalResult = Reflect.apply(target, thisArg, argArray); | ||
const metadata = { | ||
...jsonStep.metadata, | ||
...classMetadata, | ||
...originalResult.metadata | ||
}; | ||
return { | ||
...originalResult, | ||
...(Object.keys(metadata).length === 0 ? {} : { | ||
metadata | ||
}) | ||
}; | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
return stepImplementation; | ||
return Reflect.get(target, prop, receiver); | ||
} | ||
}); | ||
}; | ||
export { Step }; |
@@ -10,22 +10,23 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
var stepImplementation = originalFromJSON(schema, jsonStep); | ||
if (jsonStep.metadata) { | ||
return new Proxy(stepImplementation, { | ||
get: function get(target, prop, receiver) { | ||
if (prop === 'toJSON') { | ||
var toJSONfunc = target[prop]; | ||
return new Proxy(toJSONfunc, { | ||
apply: function apply(target, thisArg, argArray) { | ||
var originalResult = Reflect.apply(target, thisArg, argArray); | ||
return _objectSpread({ | ||
metadata: _objectSpread(_objectSpread({}, jsonStep.metadata), originalResult.metadata || {}) | ||
}, originalResult); | ||
} | ||
}); | ||
} | ||
return Reflect.get(target, prop, receiver); | ||
return new Proxy(stepImplementation, { | ||
get: function get(target, prop, receiver) { | ||
if (prop === 'toJSON') { | ||
var toJSONfunc = Reflect.get(target, prop, receiver); | ||
// @ts-expect-error Metadata may or may not exist at this stage, depending on step type, | ||
// but also additions outside of the type system that others may have done. | ||
var classMetadata = target.metadata; | ||
return new Proxy(toJSONfunc, { | ||
apply: function apply(target, thisArg, argArray) { | ||
var originalResult = Reflect.apply(target, thisArg, argArray); | ||
var metadata = _objectSpread(_objectSpread(_objectSpread({}, jsonStep.metadata), classMetadata), originalResult.metadata); | ||
return _objectSpread(_objectSpread({}, originalResult), Object.keys(metadata).length === 0 ? {} : { | ||
metadata: metadata | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
return stepImplementation; | ||
return Reflect.get(target, prop, receiver); | ||
} | ||
}); | ||
}; | ||
export { Step }; |
{ | ||
"name": "@atlaskit/editor-prosemirror", | ||
"version": "6.1.1", | ||
"version": "6.1.2", | ||
"description": "Package to group all prosemirror libraries in a single place ", | ||
@@ -5,0 +5,0 @@ "author": "Atlassian Pty Ltd", |
@@ -32,2 +32,52 @@ import { MetadataStep, Step } from '../transform-override'; | ||
}); | ||
it('should preserve class metadata when converting toJSON', () => { | ||
const json = { | ||
stepType: 'replace', | ||
to: 15, | ||
from: 10, | ||
}; | ||
const parsedStep = Step.fromJSON(defaultSchema, json) as MetadataStep; | ||
parsedStep.metadata = { testField: 'Im a test' }; | ||
const unparsedStep = parsedStep.toJSON(); | ||
expect(unparsedStep).toEqual({ | ||
from: 10, | ||
to: 15, | ||
stepType: 'replace', | ||
metadata: { testField: 'Im a test' }, | ||
}); | ||
}); | ||
it('should preserve class metadata when converting toJSON and json metadata is present', () => { | ||
const json = { | ||
stepType: 'replace', | ||
to: 15, | ||
from: 10, | ||
metadata: { source: 'synchrony' }, | ||
}; | ||
const parsedStep = Step.fromJSON(defaultSchema, json, true) as MetadataStep; | ||
parsedStep.metadata = { testField: 'Im a test' }; | ||
const unparsedStep = parsedStep.toJSON(); | ||
expect(unparsedStep).toEqual({ | ||
from: 10, | ||
to: 15, | ||
stepType: 'replace', | ||
metadata: { testField: 'Im a test', source: 'synchrony' }, | ||
}); | ||
}); | ||
it('should preserve data when converting toJSON and metadata is not present', () => { | ||
const json = { | ||
stepType: 'replace', | ||
to: 15, | ||
from: 10, | ||
}; | ||
const parsedStep = Step.fromJSON(defaultSchema, json) as MetadataStep; | ||
const unparsedStep = parsedStep.toJSON(); | ||
expect(unparsedStep).toEqual({ | ||
from: 10, | ||
to: 15, | ||
stepType: 'replace', | ||
}); | ||
}); | ||
}); |
@@ -14,30 +14,32 @@ import { Step } from 'prosemirror-transform'; | ||
if (jsonStep.metadata) { | ||
return new Proxy(stepImplementation, { | ||
get(target, prop, receiver) { | ||
if (prop === 'toJSON') { | ||
const toJSONfunc = target[prop]; | ||
return new Proxy(stepImplementation, { | ||
get(target, prop, receiver) { | ||
if (prop === 'toJSON') { | ||
const toJSONfunc = Reflect.get(target, prop, receiver); | ||
// @ts-expect-error Metadata may or may not exist at this stage, depending on step type, | ||
// but also additions outside of the type system that others may have done. | ||
const classMetadata = target.metadata; | ||
return new Proxy(toJSONfunc, { | ||
apply(target, thisArg, argArray) { | ||
const originalResult = Reflect.apply(target, thisArg, argArray); | ||
return new Proxy(toJSONfunc, { | ||
apply(target, thisArg, argArray) { | ||
const originalResult = Reflect.apply(target, thisArg, argArray); | ||
return { | ||
metadata: { | ||
...jsonStep.metadata, | ||
...(originalResult.metadata || {}), | ||
}, | ||
...originalResult, | ||
}; | ||
}, | ||
}); | ||
} | ||
return Reflect.get(target, prop, receiver); | ||
}, | ||
}); | ||
} | ||
const metadata = { | ||
...jsonStep.metadata, | ||
...classMetadata, | ||
...originalResult.metadata, | ||
}; | ||
return stepImplementation; | ||
return { | ||
...originalResult, | ||
...(Object.keys(metadata).length === 0 ? {} : { metadata }), | ||
}; | ||
}, | ||
}); | ||
} | ||
return Reflect.get(target, prop, receiver); | ||
}, | ||
}); | ||
}; | ||
export { Step }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71431
1761