|
5965 | 5965 | return r ? r[ReactiveFlags.IS_REF] === true : false; |
5966 | 5966 | } |
5967 | 5967 |
|
| 5968 | + var nodeValueSymbol = Symbol.for("devtool-node-value"); |
5968 | 5969 | var isInBrowser = typeof window !== "undefined" && typeof window.document !== "undefined"; |
5969 | 5970 | var emptyConstructor = {}.constructor; |
5970 | 5971 | var id = 1; |
|
6017 | 6018 | value !== "WeakMap" && |
6018 | 6019 | value !== "WeakSet"); |
6019 | 6020 | }; |
| 6021 | + // serialized any obj to devtool protocol obj |
6020 | 6022 | var getTargetNode = function (value, type, deep) { |
6021 | 6023 | if (deep === void 0) { deep = 3; } |
6022 | 6024 | var existId = valueToIdMap.get(value); |
|
6037 | 6039 | // full deep to load |
6038 | 6040 | if (deep === 0) { |
6039 | 6041 | return { |
| 6042 | + s: nodeValueSymbol, |
6040 | 6043 | i: currentId, |
6041 | 6044 | t: type, |
6042 | 6045 | _t: wrapperType, |
|
6049 | 6052 | else { |
6050 | 6053 | if (type === "Array") { |
6051 | 6054 | return { |
| 6055 | + s: nodeValueSymbol, |
6052 | 6056 | i: currentId, |
6053 | 6057 | t: type, |
6054 | 6058 | _t: wrapperType, |
|
6058 | 6062 | } |
6059 | 6063 | else if (type === "Iterable") { |
6060 | 6064 | return { |
| 6065 | + s: nodeValueSymbol, |
6061 | 6066 | i: currentId, |
6062 | 6067 | t: type, |
6063 | 6068 | _t: wrapperType, |
|
6067 | 6072 | } |
6068 | 6073 | else if (type === "Map") { |
6069 | 6074 | return { |
| 6075 | + s: nodeValueSymbol, |
6070 | 6076 | i: currentId, |
6071 | 6077 | t: type, |
6072 | 6078 | _t: wrapperType, |
|
6083 | 6089 | } |
6084 | 6090 | else if (type === "Set") { |
6085 | 6091 | return { |
| 6092 | + s: nodeValueSymbol, |
6086 | 6093 | i: currentId, |
6087 | 6094 | t: type, |
6088 | 6095 | _t: wrapperType, |
|
6092 | 6099 | } |
6093 | 6100 | else if (type === "Object") { |
6094 | 6101 | return { |
| 6102 | + s: nodeValueSymbol, |
6095 | 6103 | i: currentId, |
6096 | 6104 | t: type, |
6097 | 6105 | _t: wrapperType, |
|
6105 | 6113 | } |
6106 | 6114 | else if (type === "ReactElement") { |
6107 | 6115 | return { |
| 6116 | + s: nodeValueSymbol, |
6108 | 6117 | i: currentId, |
6109 | 6118 | t: type, |
6110 | 6119 | _t: wrapperType, |
|
6118 | 6127 | } |
6119 | 6128 | else { |
6120 | 6129 | return { |
| 6130 | + s: nodeValueSymbol, |
6121 | 6131 | i: currentId, |
6122 | 6132 | t: type, |
6123 | 6133 | _t: wrapperType || "Object", |
|
6160 | 6170 | valueToIdMap.set(value, currentId); |
6161 | 6171 | if (type === "Element") { |
6162 | 6172 | return { |
| 6173 | + s: nodeValueSymbol, |
6163 | 6174 | i: currentId, |
6164 | 6175 | t: type, |
6165 | 6176 | _t: wrapperType, |
|
6169 | 6180 | } |
6170 | 6181 | if (type === "Error") { |
6171 | 6182 | return { |
| 6183 | + s: nodeValueSymbol, |
6172 | 6184 | i: currentId, |
6173 | 6185 | t: type, |
6174 | 6186 | _t: wrapperType, |
|
6178 | 6190 | } |
6179 | 6191 | if (typeof value === "object" && value !== null) { |
6180 | 6192 | return { |
| 6193 | + s: nodeValueSymbol, |
6181 | 6194 | i: currentId, |
6182 | 6195 | t: type, |
6183 | 6196 | _t: wrapperType, |
|
6187 | 6200 | } |
6188 | 6201 | else { |
6189 | 6202 | return { |
| 6203 | + s: nodeValueSymbol, |
6190 | 6204 | i: currentId, |
6191 | 6205 | t: type, |
6192 | 6206 | _t: wrapperType, |
|
6198 | 6212 | } |
6199 | 6213 | catch (e) { |
6200 | 6214 | return { |
| 6215 | + s: nodeValueSymbol, |
6201 | 6216 | i: NaN, |
6202 | 6217 | t: "ReadError", |
6203 | 6218 | v: "Read data error: " + e.message, |
6204 | 6219 | e: false, |
6205 | 6220 | }; |
6206 | 6221 | } |
6207 | 6222 | }; |
| 6223 | + var getObj = function (value) { |
| 6224 | + var _a = value || {}, t = _a.t, v = _a.v, i = _a.i, s = _a.s; |
| 6225 | + if (!s || s !== nodeValueSymbol) { |
| 6226 | + return value; |
| 6227 | + } |
| 6228 | + // If we have the original object cached, return it |
| 6229 | + if (idToValueMap.has(i)) { |
| 6230 | + return idToValueMap.get(i); |
| 6231 | + } |
| 6232 | + switch (t) { |
| 6233 | + case "Array": |
| 6234 | + return v.map(getObj); |
| 6235 | + case "Iterable": |
| 6236 | + return v.map(getObj); |
| 6237 | + case "Map": { |
| 6238 | + var map_1 = new Map(); |
| 6239 | + v.forEach(function (entry) { |
| 6240 | + var _a = entry.v, key = _a[0], val = _a[1]; |
| 6241 | + map_1.set(getObj(key), getObj(val)); |
| 6242 | + }); |
| 6243 | + return map_1; |
| 6244 | + } |
| 6245 | + case "Set": { |
| 6246 | + var set_1 = new Set(); |
| 6247 | + v.forEach(function (item) { |
| 6248 | + set_1.add(getObj(item)); |
| 6249 | + }); |
| 6250 | + return set_1; |
| 6251 | + } |
| 6252 | + case "Object": |
| 6253 | + case "ReactElement": |
| 6254 | + case "Module": { |
| 6255 | + var obj_1 = {}; |
| 6256 | + Object.keys(v).forEach(function (key) { |
| 6257 | + obj_1[key] = getObj(v[key]); |
| 6258 | + }); |
| 6259 | + return obj_1; |
| 6260 | + } |
| 6261 | + case "String": |
| 6262 | + return v; |
| 6263 | + case "Number": |
| 6264 | + return Number(v); |
| 6265 | + case "Boolean": |
| 6266 | + return v === "true" || v === true; |
| 6267 | + case "Date": |
| 6268 | + return new Date(v); |
| 6269 | + case "Null": |
| 6270 | + return null; |
| 6271 | + case "Undefined": |
| 6272 | + return undefined; |
| 6273 | + case "Function": |
| 6274 | + case "AsyncFunction": |
| 6275 | + case "GeneratorFunction": |
| 6276 | + // Cannot reconstruct functions, return a placeholder or the string representation |
| 6277 | + return v; |
| 6278 | + case "Symbol": |
| 6279 | + return Symbol(v); |
| 6280 | + case "RegExp": { |
| 6281 | + // v is like "/pattern/flags" |
| 6282 | + var match = String(v).match(/^\/(.*)\/([gimsuy]*)$/); |
| 6283 | + if (match) { |
| 6284 | + return new RegExp(match[1], match[2]); |
| 6285 | + } |
| 6286 | + return new RegExp(v); |
| 6287 | + } |
| 6288 | + case "Promise": |
| 6289 | + // Cannot reconstruct promises, return the value representation |
| 6290 | + return v; |
| 6291 | + case "Element": |
| 6292 | + // DOM elements cannot be reconstructed from string, return the string representation |
| 6293 | + return v; |
| 6294 | + case "Error": |
| 6295 | + return new Error(v); |
| 6296 | + case "WeakMap": |
| 6297 | + case "WeakSet": |
| 6298 | + // WeakMap/WeakSet cannot be reconstructed |
| 6299 | + return v; |
| 6300 | + case "ReadError": |
| 6301 | + return new Error(v); |
| 6302 | + default: |
| 6303 | + return v; |
| 6304 | + } |
| 6305 | + }; |
6208 | 6306 | var getNodeFromId = function (id) { |
6209 | 6307 | var value = idToValueMap.get(id); |
6210 | 6308 | if (value) { |
|
9474 | 9572 | data.map(function (item) { return _this._notify({ type: exports.DevToolMessageEnum.record, data: item }); }); |
9475 | 9573 | this._notify({ type: exports.DevToolMessageEnum.record, data: true }); |
9476 | 9574 | }; |
| 9575 | + DevToolCore.prototype.getNode = function (v) { |
| 9576 | + return getNode(v); |
| 9577 | + }; |
| 9578 | + DevToolCore.prototype.getObj = function (v) { |
| 9579 | + return getObj(v); |
| 9580 | + }; |
9477 | 9581 | // TODO support multiple connect agent |
9478 | 9582 | DevToolCore.prototype.connect = function () { |
9479 | 9583 | if (this._enabled) |
|
9549 | 9653 | exports.getMockFiberFromElement = getMockFiberFromElement; |
9550 | 9654 | exports.getNode = getNode; |
9551 | 9655 | exports.getNodeFromId = getNodeFromId; |
| 9656 | + exports.getObj = getObj; |
9552 | 9657 | exports.getPlainNodeByFiber = getPlainNodeByFiber; |
9553 | 9658 | exports.getPlainNodeIdByFiber = getPlainNodeIdByFiber; |
9554 | 9659 | exports.getProps = getProps; |
|
0 commit comments