@lvce-editor/ports-view 0.3.0 → 0.5.0

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.
@@ -557,7 +557,7 @@ const applyDirectProperties = (restoredError, error) => {
557
557
  }
558
558
  };
559
559
  const restoreMessageError = (error, _currentStack) => {
560
- const restoredError = constructError(error.message, error.type, error.name);
560
+ const restoredError = constructError(error.message, error.type || error.data?.type, error.name);
561
561
  if (typeof error.code === 'string' || typeof error.code === 'number') {
562
562
  Object.defineProperty(restoredError, 'code', {
563
563
  configurable: true,
@@ -645,7 +645,7 @@ const getErrorProperty = (error, prettyError) => {
645
645
  data: {
646
646
  code: prettyError.code ?? error?.code,
647
647
  codeFrame: prettyError.codeFrame,
648
- name: prettyError.name,
648
+ name: prettyError.name ?? error?.name,
649
649
  stack: getStack(prettyError),
650
650
  type: getErrorType(prettyError)
651
651
  },
@@ -1277,6 +1277,80 @@ const terminate = () => {
1277
1277
  globalThis.close();
1278
1278
  };
1279
1279
 
1280
+ const emptyObject = {};
1281
+ const i18nString = (key, placeholders = emptyObject) => {
1282
+ if (placeholders === emptyObject) {
1283
+ return key;
1284
+ }
1285
+ let result = key;
1286
+ for (const [placeholder, replacement] of Object.entries(placeholders)) {
1287
+ result = result.split(`{${placeholder}}`).join(String(replacement));
1288
+ }
1289
+ return result;
1290
+ };
1291
+
1292
+ const Add$1 = 'Add';
1293
+ const AddPort = 'Add Port';
1294
+ const Cancel = 'Cancel';
1295
+ const EnterAPortNumberBetween1And65535 = 'Enter a port number between 1 and 65535';
1296
+ const ForwardedAddress = 'Forwarded Address';
1297
+ const NoForwardedPorts = 'No forwarded ports';
1298
+ const Origin = 'Origin';
1299
+ const Port = 'Port';
1300
+ const PortIsActive = 'Port {PH1} is active';
1301
+ const PortIsInactive = 'Port {PH1} is inactive';
1302
+ const PortNumber = 'Port number';
1303
+ const Ports$1 = 'Ports';
1304
+ const RunningProcess = 'Running Process';
1305
+ const UserForwarded = 'User Forwarded';
1306
+
1307
+ const add = () => {
1308
+ return i18nString(Add$1);
1309
+ };
1310
+ const addPort$1 = () => {
1311
+ return i18nString(AddPort);
1312
+ };
1313
+ const cancel = () => {
1314
+ return i18nString(Cancel);
1315
+ };
1316
+ const enterAPortNumberBetween1And65535 = () => {
1317
+ return i18nString(EnterAPortNumberBetween1And65535);
1318
+ };
1319
+ const forwardedAddress = () => {
1320
+ return i18nString(ForwardedAddress);
1321
+ };
1322
+ const noForwardedPorts = () => {
1323
+ return i18nString(NoForwardedPorts);
1324
+ };
1325
+ const origin = () => {
1326
+ return i18nString(Origin);
1327
+ };
1328
+ const port = () => {
1329
+ return i18nString(Port);
1330
+ };
1331
+ const portIsActive = port => {
1332
+ return i18nString(PortIsActive, {
1333
+ PH1: String(port)
1334
+ });
1335
+ };
1336
+ const portIsInactive = port => {
1337
+ return i18nString(PortIsInactive, {
1338
+ PH1: String(port)
1339
+ });
1340
+ };
1341
+ const portNumber = () => {
1342
+ return i18nString(PortNumber);
1343
+ };
1344
+ const ports = () => {
1345
+ return i18nString(Ports$1);
1346
+ };
1347
+ const runningProcess = () => {
1348
+ return i18nString(RunningProcess);
1349
+ };
1350
+ const userForwarded = () => {
1351
+ return i18nString(UserForwarded);
1352
+ };
1353
+
1280
1354
  const assertString = (value, name) => {
1281
1355
  if (typeof value !== 'string') {
1282
1356
  throw new TypeError(`${name} must be a string`);
@@ -1294,7 +1368,7 @@ const normalizePort = input => {
1294
1368
  }
1295
1369
  const forwardedAddress = input.forwardedAddress ?? `localhost:${port}`;
1296
1370
  const runningProcess = input.runningProcess ?? '';
1297
- const origin = input.origin ?? 'User Forwarded';
1371
+ const origin = input.origin ?? userForwarded();
1298
1372
  assertString(forwardedAddress, 'forwardedAddress');
1299
1373
  assertString(runningProcess, 'runningProcess');
1300
1374
  assertString(origin, 'origin');
@@ -1410,7 +1484,7 @@ const submitAddPort = state => {
1410
1484
  if (!PortRegex.test(value) || !Number.isSafeInteger(port) || port < 1 || port > 65_535) {
1411
1485
  return {
1412
1486
  ...state,
1413
- addPortError: 'Enter a port number between 1 and 65535'
1487
+ addPortError: enterAPortNumberBetween1And65535()
1414
1488
  };
1415
1489
  }
1416
1490
  return {
@@ -2193,32 +2267,38 @@ const cancelButton = {
2193
2267
  onClick: HandleCancelAddPort,
2194
2268
  type: Button
2195
2269
  };
2196
- const getEditor = state => {
2197
- const {
2198
- addPortError,
2199
- addPortValue
2200
- } = state;
2270
+ const getPortInputDom = addPortValue => {
2201
2271
  return [{
2202
- childCount: addPortError ? 4 : 3,
2203
- className: AddPortEditor,
2204
- type: Div
2205
- }, {
2206
- ariaLabel: 'Port number',
2272
+ ariaLabel: portNumber(),
2207
2273
  childCount: 0,
2208
2274
  className: AddPortInput,
2209
2275
  inputMode: 'numeric',
2210
2276
  onInput: HandleAddPortInput,
2211
2277
  onKeyDown: HandleAddPortKeyDown,
2212
- placeholder: 'Port number',
2278
+ placeholder: portNumber(),
2213
2279
  type: Input,
2214
2280
  value: addPortValue
2215
- }, {
2281
+ }];
2282
+ };
2283
+ const getButtonsDom = addPortValue => {
2284
+ return [{
2216
2285
  childCount: 1,
2217
2286
  className: AddPortButton,
2218
2287
  disabled: addPortValue.length === 0,
2219
2288
  onClick: HandleSubmitAddPort,
2220
2289
  type: Button
2221
- }, text('Add'), cancelButton, text('Cancel'), ...getErrorDom(addPortError)];
2290
+ }, text(add()), cancelButton, text(cancel())];
2291
+ };
2292
+ const getEditor = state => {
2293
+ const {
2294
+ addPortError,
2295
+ addPortValue
2296
+ } = state;
2297
+ return [{
2298
+ childCount: addPortError ? 4 : 3,
2299
+ className: AddPortEditor,
2300
+ type: Div
2301
+ }, ...getPortInputDom(addPortValue), ...getButtonsDom(addPortValue), ...getErrorDom(addPortError)];
2222
2302
  };
2223
2303
 
2224
2304
  const addButton = {
@@ -2227,7 +2307,6 @@ const addButton = {
2227
2307
  onClick: HandleStartAddPort,
2228
2308
  type: Button
2229
2309
  };
2230
- const addButtonDom = [addButton, text('Add Port')];
2231
2310
  const footer = {
2232
2311
  childCount: 1,
2233
2312
  className: PortsFooter,
@@ -2241,26 +2320,30 @@ const getPortsFooterVirtualDom = state => {
2241
2320
  const {
2242
2321
  editing
2243
2322
  } = state;
2244
- const content = editing ? getEditor(state) : addButtonDom;
2323
+ const content = editing ? getEditor(state) : [addButton, text(addPort$1())];
2245
2324
  return [footer, footerContent, ...content];
2246
2325
  };
2247
2326
 
2327
+ const getPortStatusText = active => {
2328
+ return active ? '●' : '○';
2329
+ };
2248
2330
  const getPortsStatusVirtualDom = (active, port) => {
2249
- const state = active ? 'active' : 'inactive';
2331
+ const label = active ? portIsActive(port) : portIsInactive(port);
2250
2332
  const stateClass = active ? PortsStatusIconActive : PortsStatusIconInactive;
2333
+ const statusText = getPortStatusText(active);
2251
2334
  return [{
2252
- ariaLabel: `Port ${port} is ${state}`,
2335
+ ariaLabel: label,
2253
2336
  childCount: 1,
2254
2337
  className: PortsStatusButton,
2255
2338
  name: `port-status-${port}`,
2256
- title: `Port ${port} is ${state}`,
2339
+ title: label,
2257
2340
  type: Button
2258
2341
  }, {
2259
2342
  childCount: 1,
2260
2343
  className: mergeClassNames(PortsStatusIcon, stateClass),
2261
2344
  name: `port-status-${port}`,
2262
2345
  type: Span
2263
- }, text(active ? '●' : '○')];
2346
+ }, text(statusText)];
2264
2347
  };
2265
2348
 
2266
2349
  const getRowClassName = port => {
@@ -2353,7 +2436,7 @@ const getPortsTableBodyVirtualDom = state => {
2353
2436
  ports
2354
2437
  } = state;
2355
2438
  if (loaded && ports.length === 0) {
2356
- return [emptyBody, emptyMessage, text('No forwarded ports')];
2439
+ return [emptyBody, emptyMessage, text(noForwardedPorts())];
2357
2440
  }
2358
2441
  const visible = getVisiblePorts(state);
2359
2442
  return [{
@@ -2380,7 +2463,7 @@ const getHeaderCell = (label, className) => {
2380
2463
  }, text(label)];
2381
2464
  };
2382
2465
  const getPortsTableHeaderVirtualDom = () => {
2383
- return [headerRow, ...getHeaderCell('', 'PortsStatusColumn'), ...getHeaderCell('Port', 'PortsPortColumn'), ...getHeaderCell('Forwarded Address', 'PortsAddressColumn'), ...getHeaderCell('Running Process', 'PortsProcessColumn'), ...getHeaderCell('Origin', 'PortsOriginColumn')];
2466
+ return [headerRow, ...getHeaderCell('', 'PortsStatusColumn'), ...getHeaderCell(port(), 'PortsPortColumn'), ...getHeaderCell(forwardedAddress(), 'PortsAddressColumn'), ...getHeaderCell(runningProcess(), 'PortsProcessColumn'), ...getHeaderCell(origin(), 'PortsOriginColumn')];
2384
2467
  };
2385
2468
 
2386
2469
  const table = {
@@ -2390,11 +2473,11 @@ const table = {
2390
2473
  };
2391
2474
  const getPortsVirtualDom = state => {
2392
2475
  const {
2393
- ports
2476
+ ports: ports$1
2394
2477
  } = state;
2395
2478
  return [{
2396
- ariaLabel: 'Ports',
2397
- ariaRowCount: ports.length + 1,
2479
+ ariaLabel: ports(),
2480
+ ariaRowCount: ports$1.length + 1,
2398
2481
  childCount: 2,
2399
2482
  className: mergeClassNames(Viewlet, Ports),
2400
2483
  onBlur: HandleBlur,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/ports-view",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Ports View Worker",
5
5
  "repository": {
6
6
  "type": "git",