@lvce-editor/ports-view 0.4.0 → 0.6.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.
- package/dist/portsViewWorkerMain.js +45 -12
- package/package.json +1 -1
|
@@ -1632,6 +1632,10 @@ const focusLast = state => {
|
|
|
1632
1632
|
return focusIndex(state, ports.length - 1);
|
|
1633
1633
|
};
|
|
1634
1634
|
|
|
1635
|
+
const getComponentState = uid => {
|
|
1636
|
+
return get(uid).newState;
|
|
1637
|
+
};
|
|
1638
|
+
|
|
1635
1639
|
const mergeClassNames = (...classNames) => {
|
|
1636
1640
|
return classNames.filter(Boolean).join(' ');
|
|
1637
1641
|
};
|
|
@@ -2267,16 +2271,8 @@ const cancelButton = {
|
|
|
2267
2271
|
onClick: HandleCancelAddPort,
|
|
2268
2272
|
type: Button
|
|
2269
2273
|
};
|
|
2270
|
-
const
|
|
2271
|
-
const {
|
|
2272
|
-
addPortError,
|
|
2273
|
-
addPortValue
|
|
2274
|
-
} = state;
|
|
2274
|
+
const getPortInputDom = addPortValue => {
|
|
2275
2275
|
return [{
|
|
2276
|
-
childCount: addPortError ? 4 : 3,
|
|
2277
|
-
className: AddPortEditor,
|
|
2278
|
-
type: Div
|
|
2279
|
-
}, {
|
|
2280
2276
|
ariaLabel: portNumber(),
|
|
2281
2277
|
childCount: 0,
|
|
2282
2278
|
className: AddPortInput,
|
|
@@ -2286,13 +2282,27 @@ const getEditor = state => {
|
|
|
2286
2282
|
placeholder: portNumber(),
|
|
2287
2283
|
type: Input,
|
|
2288
2284
|
value: addPortValue
|
|
2289
|
-
}
|
|
2285
|
+
}];
|
|
2286
|
+
};
|
|
2287
|
+
const getButtonsDom = addPortValue => {
|
|
2288
|
+
return [{
|
|
2290
2289
|
childCount: 1,
|
|
2291
2290
|
className: AddPortButton,
|
|
2292
2291
|
disabled: addPortValue.length === 0,
|
|
2293
2292
|
onClick: HandleSubmitAddPort,
|
|
2294
2293
|
type: Button
|
|
2295
|
-
}, text(add()), cancelButton, text(cancel())
|
|
2294
|
+
}, text(add()), cancelButton, text(cancel())];
|
|
2295
|
+
};
|
|
2296
|
+
const getEditor = state => {
|
|
2297
|
+
const {
|
|
2298
|
+
addPortError,
|
|
2299
|
+
addPortValue
|
|
2300
|
+
} = state;
|
|
2301
|
+
return [{
|
|
2302
|
+
childCount: addPortError ? 4 : 3,
|
|
2303
|
+
className: AddPortEditor,
|
|
2304
|
+
type: Div
|
|
2305
|
+
}, ...getPortInputDom(addPortValue), ...getButtonsDom(addPortValue), ...getErrorDom(addPortError)];
|
|
2296
2306
|
};
|
|
2297
2307
|
|
|
2298
2308
|
const addButton = {
|
|
@@ -2318,9 +2328,13 @@ const getPortsFooterVirtualDom = state => {
|
|
|
2318
2328
|
return [footer, footerContent, ...content];
|
|
2319
2329
|
};
|
|
2320
2330
|
|
|
2331
|
+
const getPortStatusText = active => {
|
|
2332
|
+
return active ? '●' : '○';
|
|
2333
|
+
};
|
|
2321
2334
|
const getPortsStatusVirtualDom = (active, port) => {
|
|
2322
2335
|
const label = active ? portIsActive(port) : portIsInactive(port);
|
|
2323
2336
|
const stateClass = active ? PortsStatusIconActive : PortsStatusIconInactive;
|
|
2337
|
+
const statusText = getPortStatusText(active);
|
|
2324
2338
|
return [{
|
|
2325
2339
|
ariaLabel: label,
|
|
2326
2340
|
childCount: 1,
|
|
@@ -2333,7 +2347,7 @@ const getPortsStatusVirtualDom = (active, port) => {
|
|
|
2333
2347
|
className: mergeClassNames(PortsStatusIcon, stateClass),
|
|
2334
2348
|
name: `port-status-${port}`,
|
|
2335
2349
|
type: Span
|
|
2336
|
-
}, text(
|
|
2350
|
+
}, text(statusText)];
|
|
2337
2351
|
};
|
|
2338
2352
|
|
|
2339
2353
|
const getRowClassName = port => {
|
|
@@ -2559,6 +2573,23 @@ const resize = (state, dimensions) => {
|
|
|
2559
2573
|
});
|
|
2560
2574
|
};
|
|
2561
2575
|
|
|
2576
|
+
const applyComponentState = (currentState, state) => {
|
|
2577
|
+
if (!state || typeof state !== 'object' || Array.isArray(state)) {
|
|
2578
|
+
throw new TypeError('Ports state must be an object');
|
|
2579
|
+
}
|
|
2580
|
+
const {
|
|
2581
|
+
uid
|
|
2582
|
+
} = state;
|
|
2583
|
+
const {
|
|
2584
|
+
uid: currentUid
|
|
2585
|
+
} = currentState;
|
|
2586
|
+
if (uid !== currentUid) {
|
|
2587
|
+
throw new Error(`Ports state uid must remain ${currentUid}`);
|
|
2588
|
+
}
|
|
2589
|
+
return state;
|
|
2590
|
+
};
|
|
2591
|
+
const setComponentState = wrapCommand(applyComponentState);
|
|
2592
|
+
|
|
2562
2593
|
const toggleFocusedPort = state => {
|
|
2563
2594
|
const {
|
|
2564
2595
|
editing,
|
|
@@ -2584,6 +2615,7 @@ const commandMap = {
|
|
|
2584
2615
|
'Ports.focusNext': wrapCommand(focusNext),
|
|
2585
2616
|
'Ports.focusPrevious': wrapCommand(focusPrevious),
|
|
2586
2617
|
'Ports.getCommandIds': getCommandIds,
|
|
2618
|
+
'Ports.getComponentState': getComponentState,
|
|
2587
2619
|
'Ports.getKeyBindings': getKeyBindings,
|
|
2588
2620
|
'Ports.handleAddPortInput': wrapCommand(handleAddPortInput),
|
|
2589
2621
|
'Ports.handleAddPortKeyDown': wrapCommand(handleAddPortKeyDown),
|
|
@@ -2600,6 +2632,7 @@ const commandMap = {
|
|
|
2600
2632
|
'Ports.render2': render2,
|
|
2601
2633
|
'Ports.renderEventListeners': renderEventListeners,
|
|
2602
2634
|
'Ports.resize': wrapCommand(resize),
|
|
2635
|
+
'Ports.setComponentState': setComponentState,
|
|
2603
2636
|
'Ports.setDeltaY': wrapCommand(setDeltaY),
|
|
2604
2637
|
'Ports.setPorts': wrapCommand(setPorts),
|
|
2605
2638
|
'Ports.startAddPort': wrapCommand(startAddPort),
|