@lvce-editor/ports-view 0.3.0 → 0.4.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 {
@@ -2203,13 +2277,13 @@ const getEditor = state => {
2203
2277
  className: AddPortEditor,
2204
2278
  type: Div
2205
2279
  }, {
2206
- ariaLabel: 'Port number',
2280
+ ariaLabel: portNumber(),
2207
2281
  childCount: 0,
2208
2282
  className: AddPortInput,
2209
2283
  inputMode: 'numeric',
2210
2284
  onInput: HandleAddPortInput,
2211
2285
  onKeyDown: HandleAddPortKeyDown,
2212
- placeholder: 'Port number',
2286
+ placeholder: portNumber(),
2213
2287
  type: Input,
2214
2288
  value: addPortValue
2215
2289
  }, {
@@ -2218,7 +2292,7 @@ const getEditor = state => {
2218
2292
  disabled: addPortValue.length === 0,
2219
2293
  onClick: HandleSubmitAddPort,
2220
2294
  type: Button
2221
- }, text('Add'), cancelButton, text('Cancel'), ...getErrorDom(addPortError)];
2295
+ }, text(add()), cancelButton, text(cancel()), ...getErrorDom(addPortError)];
2222
2296
  };
2223
2297
 
2224
2298
  const addButton = {
@@ -2227,7 +2301,6 @@ const addButton = {
2227
2301
  onClick: HandleStartAddPort,
2228
2302
  type: Button
2229
2303
  };
2230
- const addButtonDom = [addButton, text('Add Port')];
2231
2304
  const footer = {
2232
2305
  childCount: 1,
2233
2306
  className: PortsFooter,
@@ -2241,19 +2314,19 @@ const getPortsFooterVirtualDom = state => {
2241
2314
  const {
2242
2315
  editing
2243
2316
  } = state;
2244
- const content = editing ? getEditor(state) : addButtonDom;
2317
+ const content = editing ? getEditor(state) : [addButton, text(addPort$1())];
2245
2318
  return [footer, footerContent, ...content];
2246
2319
  };
2247
2320
 
2248
2321
  const getPortsStatusVirtualDom = (active, port) => {
2249
- const state = active ? 'active' : 'inactive';
2322
+ const label = active ? portIsActive(port) : portIsInactive(port);
2250
2323
  const stateClass = active ? PortsStatusIconActive : PortsStatusIconInactive;
2251
2324
  return [{
2252
- ariaLabel: `Port ${port} is ${state}`,
2325
+ ariaLabel: label,
2253
2326
  childCount: 1,
2254
2327
  className: PortsStatusButton,
2255
2328
  name: `port-status-${port}`,
2256
- title: `Port ${port} is ${state}`,
2329
+ title: label,
2257
2330
  type: Button
2258
2331
  }, {
2259
2332
  childCount: 1,
@@ -2353,7 +2426,7 @@ const getPortsTableBodyVirtualDom = state => {
2353
2426
  ports
2354
2427
  } = state;
2355
2428
  if (loaded && ports.length === 0) {
2356
- return [emptyBody, emptyMessage, text('No forwarded ports')];
2429
+ return [emptyBody, emptyMessage, text(noForwardedPorts())];
2357
2430
  }
2358
2431
  const visible = getVisiblePorts(state);
2359
2432
  return [{
@@ -2380,7 +2453,7 @@ const getHeaderCell = (label, className) => {
2380
2453
  }, text(label)];
2381
2454
  };
2382
2455
  const getPortsTableHeaderVirtualDom = () => {
2383
- return [headerRow, ...getHeaderCell('', 'PortsStatusColumn'), ...getHeaderCell('Port', 'PortsPortColumn'), ...getHeaderCell('Forwarded Address', 'PortsAddressColumn'), ...getHeaderCell('Running Process', 'PortsProcessColumn'), ...getHeaderCell('Origin', 'PortsOriginColumn')];
2456
+ return [headerRow, ...getHeaderCell('', 'PortsStatusColumn'), ...getHeaderCell(port(), 'PortsPortColumn'), ...getHeaderCell(forwardedAddress(), 'PortsAddressColumn'), ...getHeaderCell(runningProcess(), 'PortsProcessColumn'), ...getHeaderCell(origin(), 'PortsOriginColumn')];
2384
2457
  };
2385
2458
 
2386
2459
  const table = {
@@ -2390,11 +2463,11 @@ const table = {
2390
2463
  };
2391
2464
  const getPortsVirtualDom = state => {
2392
2465
  const {
2393
- ports
2466
+ ports: ports$1
2394
2467
  } = state;
2395
2468
  return [{
2396
- ariaLabel: 'Ports',
2397
- ariaRowCount: ports.length + 1,
2469
+ ariaLabel: ports(),
2470
+ ariaRowCount: ports$1.length + 1,
2398
2471
  childCount: 2,
2399
2472
  className: mergeClassNames(Viewlet, Ports),
2400
2473
  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.4.0",
4
4
  "description": "Ports View Worker",
5
5
  "repository": {
6
6
  "type": "git",