figma-api-stub
Advanced tools
Comparing version 0.0.51 to 0.0.52
@@ -126,3 +126,4 @@ /// <reference types="plugin-typings" /> | ||
mainComponent: null | ComponentNodeStub; | ||
_orig: ComponentNodeStub | null; | ||
detachInstance(): void; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var cloneDeep = require("clone-deep"); | ||
var fonts_1 = require("./fonts"); | ||
@@ -332,2 +331,23 @@ var nanoid_1 = require("nanoid"); | ||
exports.BooleanOperationNodeStub = BooleanOperationNodeStub; | ||
function cloneChildren(node) { | ||
var clone = new node.constructor(); | ||
for (var key in node) { | ||
if (typeof node[key] === "function") { | ||
clone[key] = node[key].bind(clone); | ||
} | ||
else { | ||
clone[key] = node[key]; | ||
} | ||
} | ||
clone._orig = node; | ||
clone.pluginData = {}; | ||
clone.sharedPluginData = {}; | ||
if ("children" in node) { | ||
clone.children = node.children.map(function (child) { return cloneChildren(child); }); | ||
clone.children.forEach(function (child) { | ||
child.parent = clone; | ||
}); | ||
} | ||
return clone; | ||
} | ||
var ComponentNodeStub = /** @class */ (function () { | ||
@@ -341,4 +361,10 @@ function ComponentNodeStub(config) { | ||
ComponentNodeStub.prototype.createInstance = function () { | ||
var _this = this; | ||
var instance = new InstanceNodeStub(this.config); | ||
instance.children = cloneDeep(this.children); | ||
instance.children = this.children.map(function (child) { return cloneChildren(child); }); | ||
instance.children.forEach(function (child) { | ||
child.parent = _this; | ||
}); | ||
// instance.pluginData = {}; | ||
instance._orig = this; | ||
instance.mainComponent = this; | ||
@@ -345,0 +371,0 @@ return instance; |
@@ -35,2 +35,3 @@ /// <reference types="plugin-typings" /> | ||
}; | ||
_orig: BaseNodeMixin; | ||
setPluginData(key: string, value: string): void; | ||
@@ -37,0 +38,0 @@ getPluginData(key: string): string; |
@@ -102,2 +102,6 @@ "use strict"; | ||
function BaseNodeMixinStub() { | ||
// instance nodes that are cloned from components will have `_orig` set to | ||
// the value of the original node. This is used internally for inheriting | ||
// things like plugin data and relaunch data | ||
this._orig = null; | ||
} | ||
@@ -108,3 +112,8 @@ BaseNodeMixinStub.prototype.setPluginData = function (key, value) { | ||
} | ||
this.pluginData[key] = value; | ||
if (value === "") { | ||
delete this.pluginData[key]; | ||
} | ||
else { | ||
this.pluginData[key] = value; | ||
} | ||
}; | ||
@@ -115,6 +124,13 @@ BaseNodeMixinStub.prototype.getPluginData = function (key) { | ||
} | ||
if (!this.pluginData) { | ||
return; | ||
// first, try to retrieve the key from local plugin data | ||
if (this.pluginData && this.pluginData[key]) { | ||
return this.pluginData[key]; | ||
} | ||
return this.pluginData[key]; | ||
// if we don't find the key in local plugin data, try and retrieve it from | ||
// the original node it was cloned from, if it exists if | ||
if (this._orig) { | ||
return this._orig.getPluginData(key); | ||
} | ||
// otherwise, return nothing | ||
return; | ||
}; | ||
@@ -125,6 +141,8 @@ BaseNodeMixinStub.prototype.getPluginDataKeys = function () { | ||
} | ||
if (!this.pluginData) { | ||
return []; | ||
} | ||
return Object.keys(this.pluginData); | ||
// get all local and inherited keys | ||
var localKeys = this.pluginData ? Object.keys(this.pluginData) : []; | ||
var inheritedKeys = this._orig ? this._orig.getPluginDataKeys() : []; | ||
// combine them into one list and de-dupe any copies | ||
var combinedKeys = Array.from(new Set(localKeys.concat(inheritedKeys))); | ||
return combinedKeys; | ||
}; | ||
@@ -138,15 +156,38 @@ BaseNodeMixinStub.prototype.setSharedPluginData = function (namespace, key, value) { | ||
} | ||
this.sharedPluginData[namespace][key] = value; | ||
if (value === "") { | ||
delete this.sharedPluginData[namespace][key]; | ||
// if (Object.keys(this.sharedPluginData[namespace]).length === 0) { | ||
// delete this.sharedPluginData[namespace]; | ||
// } | ||
} | ||
else { | ||
this.sharedPluginData[namespace][key] = value; | ||
} | ||
}; | ||
BaseNodeMixinStub.prototype.getSharedPluginData = function (namespace, key) { | ||
if (!this.sharedPluginData || !this.sharedPluginData[namespace]) { | ||
return; | ||
// first, try to retrieve the key from local plugin data | ||
if (this.sharedPluginData && | ||
this.sharedPluginData[namespace] && | ||
this.sharedPluginData[namespace][key]) { | ||
return this.sharedPluginData[namespace][key]; | ||
} | ||
return this.sharedPluginData[namespace][key]; | ||
// if we don't find the key in local plugin data, try and retrieve it from | ||
// the original node it was cloned from, if it exists if | ||
if (this._orig) { | ||
return this._orig.getSharedPluginData(namespace, key); | ||
} | ||
// otherwise, return nothing | ||
return; | ||
}; | ||
BaseNodeMixinStub.prototype.getSharedPluginDataKeys = function (namespace) { | ||
if (!this.sharedPluginData || !this.sharedPluginData[namespace]) { | ||
return; | ||
} | ||
return Object.keys(this.sharedPluginData[namespace]); | ||
// get all local and inherited keys | ||
var localKeys = this.sharedPluginData && this.sharedPluginData[namespace] | ||
? Object.keys(this.sharedPluginData[namespace]) | ||
: []; | ||
var inheritedKeys = this._orig | ||
? this._orig.getSharedPluginDataKeys(namespace) | ||
: []; | ||
// combine them into one list and de-dupe any copies | ||
var combinedKeys = Array.from(new Set(localKeys.concat(inheritedKeys))); | ||
return combinedKeys; | ||
}; | ||
@@ -153,0 +194,0 @@ BaseNodeMixinStub.prototype.setRelaunchData = function (data) { |
@@ -93,3 +93,4 @@ "use strict"; | ||
mixins_1.ExportMixinStub, | ||
LayoutMixinStub | ||
LayoutMixinStub, | ||
ChildrenMixinStub | ||
]); | ||
@@ -96,0 +97,0 @@ var selectionChangeSubscribes = new Map(); |
{ | ||
"name": "figma-api-stub", | ||
"version": "0.0.51", | ||
"version": "0.0.52", | ||
"description": "Figma API stub", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
107713
1857
0