@meta2d/core 1.0.33 → 1.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/core.d.ts CHANGED
@@ -196,8 +196,10 @@ export declare class Meta2d {
196
196
  connectNetwork(): void;
197
197
  randomString(e: number): string;
198
198
  penMock(pen: Pen): void;
199
+ penNetwork(pen: Pen): void;
199
200
  getDynamicParam(key: string): any;
200
201
  onNetworkConnect(https: Network[]): void;
202
+ requestHttp(_req: Network): Promise<void>;
201
203
  closeNetwork(): void;
202
204
  socketCallback(message: string, context?: {
203
205
  type?: string;
package/src/core.js CHANGED
@@ -144,6 +144,12 @@ var Meta2d = /** @class */ (function () {
144
144
  e.pen && e.pen.onClick && e.pen.onClick(e.pen, _this.canvas.mousePos);
145
145
  _this.store.data.locked && e.pen && _this.doEvent(e.pen, eventName);
146
146
  break;
147
+ case 'contextmenu':
148
+ e.pen &&
149
+ e.pen.onContextmenu &&
150
+ e.pen.onContextmenu(e.pen, _this.canvas.mousePos);
151
+ _this.store.data.locked && e.pen && _this.doEvent(e.pen, eventName);
152
+ break;
147
153
  case 'mousedown':
148
154
  e.pen &&
149
155
  e.pen.onMouseDown &&
@@ -745,7 +751,7 @@ var Meta2d = /** @class */ (function () {
745
751
  }
746
752
  }
747
753
  else {
748
- websocket_1 = new WebSocket(network.url, network.protocols);
754
+ websocket_1 = new WebSocket(network.url, network.protocols || undefined);
749
755
  websocket_1.onopen = function () {
750
756
  console.info('websocket连接成功');
751
757
  websocket_1.send(value);
@@ -1295,7 +1301,9 @@ var Meta2d = /** @class */ (function () {
1295
1301
  if (!idOrTagOrPens) {
1296
1302
  pens = this.store.data.pens.filter(function (pen) {
1297
1303
  return (((pen.type || pen.frames) && pen.autoPlay) ||
1298
- (pen.animations && pen.autoPlay));
1304
+ (pen.animations &&
1305
+ pen.animations.length &&
1306
+ pen.animations.findIndex(function (i) { return i.autoPlay; }) !== -1));
1299
1307
  });
1300
1308
  }
1301
1309
  else if (typeof idOrTagOrPens === 'string') {
@@ -1331,9 +1339,9 @@ var Meta2d = /** @class */ (function () {
1331
1339
  }
1332
1340
  }
1333
1341
  else if (params === undefined) {
1334
- index = ((_a = pen.animations) === null || _a === void 0 ? void 0 : _a.findIndex(function (i) { return i.autoPlay; })) || -1;
1342
+ index = (_a = pen.animations) === null || _a === void 0 ? void 0 : _a.findIndex(function (i) { return i.autoPlay; });
1335
1343
  }
1336
- if (index !== -1) {
1344
+ if (index !== -1 && index !== undefined) {
1337
1345
  var animate = deepClone(pen.animations[index]);
1338
1346
  delete animate.name;
1339
1347
  animate.currentAnimation = index;
@@ -1715,7 +1723,7 @@ var Meta2d = /** @class */ (function () {
1715
1723
  this.store.data.websocket = websocket;
1716
1724
  }
1717
1725
  if (this.store.data.websocket) {
1718
- this.websocket = new WebSocket(this.store.data.websocket, this.store.data.websocketProtocols);
1726
+ this.websocket = new WebSocket(this.store.data.websocket, this.store.data.websocketProtocols || undefined);
1719
1727
  this.websocket.onmessage = function (e) {
1720
1728
  _this.socketCallback(e.data, {
1721
1729
  type: 'websocket',
@@ -1910,7 +1918,7 @@ var Meta2d = /** @class */ (function () {
1910
1918
  mqttIndex_1 += 1;
1911
1919
  }
1912
1920
  else if (net.protocol === 'websocket') {
1913
- _this.websockets[websocketIndex_1] = new WebSocket(net.url, net.protocols);
1921
+ _this.websockets[websocketIndex_1] = new WebSocket(net.url, net.protocols || undefined);
1914
1922
  _this.websockets[websocketIndex_1].onmessage = function (e) {
1915
1923
  _this.socketCallback(e.data, { type: 'websocket', url: net.url });
1916
1924
  };
@@ -2065,6 +2073,22 @@ var Meta2d = /** @class */ (function () {
2065
2073
  }
2066
2074
  }
2067
2075
  };
2076
+ Meta2d.prototype.penNetwork = function (pen) {
2077
+ var penNetwork = {
2078
+ url: pen.apiUrl,
2079
+ method: pen.apiMethod,
2080
+ headers: pen.apiHeaders,
2081
+ body: pen.apiBody,
2082
+ };
2083
+ //临时请求一次
2084
+ this.requestHttp(penNetwork);
2085
+ if (pen.apiEnable) {
2086
+ if (!this.store.pensNetwork) {
2087
+ this.store.pensNetwork = {};
2088
+ }
2089
+ this.store.pensNetwork[pen.id] = penNetwork;
2090
+ }
2091
+ };
2068
2092
  //获取动态参数
2069
2093
  Meta2d.prototype.getDynamicParam = function (key) {
2070
2094
  function getCookie(name) {
@@ -2087,6 +2111,11 @@ var Meta2d = /** @class */ (function () {
2087
2111
  if (!(https && https.length) && !enable) {
2088
2112
  return;
2089
2113
  }
2114
+ if (this.store.pensNetwork) {
2115
+ for (var key in this.store.pensNetwork) {
2116
+ https.push(this.store.pensNetwork[key]);
2117
+ }
2118
+ }
2090
2119
  this.updateTimer = setInterval(function () {
2091
2120
  //模拟数据
2092
2121
  enable &&
@@ -2094,48 +2123,56 @@ var Meta2d = /** @class */ (function () {
2094
2123
  _this.penMock(pen);
2095
2124
  });
2096
2125
  https.forEach(function (_item) { return __awaiter(_this, void 0, void 0, function () {
2097
- var item, i, keys, i, keys, res, data;
2098
2126
  return __generator(this, function (_a) {
2099
- switch (_a.label) {
2100
- case 0:
2101
- item = deepClone(_item);
2102
- if (!item.url) return [3 /*break*/, 3];
2103
- if (typeof item.headers === 'object') {
2104
- for (i in item.headers) {
2105
- keys = item.headers[i].match(/(?<=\$\{).*?(?=\})/g);
2106
- if (keys) {
2107
- item.headers[i] = item.headers[i].replace("${" + keys[0] + "}", this.getDynamicParam(keys[0]));
2108
- }
2109
- }
2110
- }
2111
- if (typeof item.body === 'object') {
2112
- for (i in item.body) {
2113
- keys = item.body[i].match(/(?<=\$\{).*?(?=\})/g);
2114
- if (keys) {
2115
- item.body[i] = item.body[i].replace("${" + keys[0] + "}", this.getDynamicParam(keys[0]));
2116
- }
2117
- }
2118
- }
2119
- return [4 /*yield*/, fetch(item.url, {
2120
- headers: item.headers,
2121
- method: item.method,
2122
- body: item.method === 'GET' ? undefined : JSON.stringify(item.body),
2123
- })];
2124
- case 1:
2125
- res = _a.sent();
2126
- if (!res.ok) return [3 /*break*/, 3];
2127
- return [4 /*yield*/, res.text()];
2128
- case 2:
2129
- data = _a.sent();
2130
- this.socketCallback(data, { type: 'http', url: item.url });
2131
- _a.label = 3;
2132
- case 3: return [2 /*return*/];
2133
- }
2127
+ this.requestHttp(_item);
2128
+ return [2 /*return*/];
2134
2129
  });
2135
2130
  }); });
2136
2131
  _this.render();
2137
2132
  }, this.store.data.networkInterval || 1000);
2138
2133
  };
2134
+ Meta2d.prototype.requestHttp = function (_req) {
2135
+ return __awaiter(this, void 0, void 0, function () {
2136
+ var req, i, keys, i, keys, res, data;
2137
+ return __generator(this, function (_a) {
2138
+ switch (_a.label) {
2139
+ case 0:
2140
+ req = deepClone(_req);
2141
+ if (!req.url) return [3 /*break*/, 3];
2142
+ if (typeof req.headers === 'object') {
2143
+ for (i in req.headers) {
2144
+ keys = req.headers[i].match(/(?<=\$\{).*?(?=\})/g);
2145
+ if (keys) {
2146
+ req.headers[i] = req.headers[i].replace("${" + keys[0] + "}", this.getDynamicParam(keys[0]));
2147
+ }
2148
+ }
2149
+ }
2150
+ if (typeof req.body === 'object') {
2151
+ for (i in req.body) {
2152
+ keys = req.body[i].match(/(?<=\$\{).*?(?=\})/g);
2153
+ if (keys) {
2154
+ req.body[i] = req.body[i].replace("${" + keys[0] + "}", this.getDynamicParam(keys[0]));
2155
+ }
2156
+ }
2157
+ }
2158
+ return [4 /*yield*/, fetch(req.url, {
2159
+ headers: req.headers,
2160
+ method: req.method,
2161
+ body: req.method === 'GET' ? undefined : JSON.stringify(req.body),
2162
+ })];
2163
+ case 1:
2164
+ res = _a.sent();
2165
+ if (!res.ok) return [3 /*break*/, 3];
2166
+ return [4 /*yield*/, res.text()];
2167
+ case 2:
2168
+ data = _a.sent();
2169
+ this.socketCallback(data, { type: 'http', url: req.url });
2170
+ _a.label = 3;
2171
+ case 3: return [2 /*return*/];
2172
+ }
2173
+ });
2174
+ });
2175
+ };
2139
2176
  Meta2d.prototype.closeNetwork = function () {
2140
2177
  this.mqttClients &&
2141
2178
  this.mqttClients.forEach(function (mqttClient) {
@@ -2358,10 +2395,11 @@ var Meta2d = /** @class */ (function () {
2358
2395
  this.canvas.calcActiveRect();
2359
2396
  }
2360
2397
  if (history) {
2398
+ var _pens = deepClone(pens);
2361
2399
  this.pushHistory({
2362
2400
  type: EditType.Update,
2363
2401
  initPens: initPens,
2364
- pens: pens,
2402
+ pens: _pens,
2365
2403
  });
2366
2404
  }
2367
2405
  doEvent &&
@@ -3486,7 +3524,7 @@ var Meta2d = /** @class */ (function () {
3486
3524
  }
3487
3525
  //dom
3488
3526
  if (pen.externElement || pen.name === 'gif') {
3489
- var zIndex = 0;
3527
+ var zIndex = 1;
3490
3528
  // let zIndex = pen.calculative.zIndex === undefined ? 5 : pen.calculative.zIndex + 1;
3491
3529
  if (type === 'top') {
3492
3530
  pen.calculative.canvas.maxZindex += 1;
@@ -3499,8 +3537,8 @@ var Meta2d = /** @class */ (function () {
3499
3537
  else if (type === 'down') {
3500
3538
  zIndex =
3501
3539
  pen.calculative.zIndex === undefined ? 3 : pen.calculative.zIndex - 1;
3502
- if (zIndex < 0) {
3503
- zIndex = 0;
3540
+ if (zIndex < 1) {
3541
+ zIndex = 1;
3504
3542
  }
3505
3543
  }
3506
3544
  this.setValue({ id: pen.id, zIndex: zIndex }, { render: false, doEvent: false, history: false });