mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Do not set insert: false for the root of the imported JSON.
This commit is contained in:
parent
ee7fd8cdbe
commit
1e57031811
1 changed files with 5 additions and 4 deletions
|
@ -381,7 +381,8 @@ 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.
|
||||||
|
@ -415,7 +416,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);
|
res = create(type, args, isRoot);
|
||||||
} else {
|
} else {
|
||||||
res = Base.create(type.prototype);
|
res = Base.create(type.prototype);
|
||||||
type.apply(res, args);
|
type.apply(res, args);
|
||||||
|
@ -439,7 +440,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) {
|
function(type, args, isRoot) {
|
||||||
// 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
|
||||||
|
@ -450,7 +451,7 @@ 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 (args.length === 1 && obj instanceof Item
|
if (!isRoot && args.length === 1 && obj instanceof Item
|
||||||
&& (!(obj instanceof Layer) || isTarget)) {
|
&& (!(obj instanceof Layer) || isTarget)) {
|
||||||
var arg = args[0];
|
var arg = args[0];
|
||||||
if (Base.isPlainObject(arg))
|
if (Base.isPlainObject(arg))
|
||||||
|
|
Loading…
Reference in a new issue