mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -05:00
Avoid double-insertion of root layer when importing JSON directly into it.
This commit is contained in:
parent
397c81e060
commit
dafdd0ae28
1 changed files with 5 additions and 6 deletions
|
@ -381,8 +381,7 @@ Base.inject(/** @lends Base# */{
|
||||||
* first
|
* first
|
||||||
*/
|
*/
|
||||||
deserialize: function(json, create, _data) {
|
deserialize: function(json, create, _data) {
|
||||||
var res = json,
|
var res = json;
|
||||||
isRoot = !_data;
|
|
||||||
// A _data side-car to deserialize that can hold any kind of
|
// A _data side-car to deserialize that can hold any kind of
|
||||||
// 'global' data across a deserialization. It's currently only used
|
// 'global' data across a deserialization. It's currently only used
|
||||||
// to hold dictionary definitions.
|
// to hold dictionary definitions.
|
||||||
|
@ -416,7 +415,7 @@ Base.inject(/** @lends Base# */{
|
||||||
// creation. This is used in #importJSON() to pass
|
// creation. This is used in #importJSON() to pass
|
||||||
// on insert = false to all items except layers.
|
// on insert = false to all items except layers.
|
||||||
if (create) {
|
if (create) {
|
||||||
res = create(type, args, isRoot);
|
res = create(type, args);
|
||||||
} else {
|
} else {
|
||||||
res = Base.create(type.prototype);
|
res = Base.create(type.prototype);
|
||||||
type.apply(res, args);
|
type.apply(res, args);
|
||||||
|
@ -442,7 +441,7 @@ Base.inject(/** @lends Base# */{
|
||||||
typeof json === 'string' ? JSON.parse(json) : json,
|
typeof json === 'string' ? JSON.parse(json) : json,
|
||||||
// Provide our own create function to handle target and
|
// Provide our own create function to handle target and
|
||||||
// insertion
|
// insertion
|
||||||
function(type, args, isRoot) {
|
function(type, args) {
|
||||||
// If a target is provided and its of the right type,
|
// If a target is provided and its of the right type,
|
||||||
// import right into it.
|
// import right into it.
|
||||||
var obj = target && target.constructor === type
|
var obj = target && target.constructor === type
|
||||||
|
@ -453,8 +452,8 @@ Base.inject(/** @lends Base# */{
|
||||||
// we want these to be created on the fly in the active
|
// we want these to be created on the fly in the active
|
||||||
// project into which we're importing (except for if
|
// project into which we're importing (except for if
|
||||||
// it's a preexisting target layer).
|
// it's a preexisting target layer).
|
||||||
if (!isRoot && args.length === 1 && obj instanceof Item
|
if (args.length === 1 && obj instanceof Item
|
||||||
&& (!(obj instanceof Layer) || isTarget)) {
|
&& (isTarget || !(obj instanceof Layer))) {
|
||||||
var arg = args[0];
|
var arg = args[0];
|
||||||
if (Base.isPlainObject(arg))
|
if (Base.isPlainObject(arg))
|
||||||
arg.insert = false;
|
arg.insert = false;
|
||||||
|
|
Loading…
Reference in a new issue