@lvce-editor/component-state-worker 0.2.0 → 0.3.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/README.md +19 -0
- package/dist/componentStateWorkerMain.js +30 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,3 +5,22 @@ Inspect and edit live LVCE Editor component state as JSON.
|
|
|
5
5
|
The worker provides the component-state grid view and the
|
|
6
6
|
`live-component-state:///<uid>.json` filesystem implementation used by LVCE
|
|
7
7
|
Editor.
|
|
8
|
+
|
|
9
|
+
## Development
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm ci
|
|
13
|
+
npm run dev
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Open `http://localhost:3000`, then run `Developer: Open Component State` from
|
|
17
|
+
the command palette. Select an editable component to open its live state as a
|
|
18
|
+
JSON file. Saving that file applies the new state to the running component.
|
|
19
|
+
|
|
20
|
+
Run the browser tests headlessly with:
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
npm run build
|
|
24
|
+
npm run build:static
|
|
25
|
+
npm run e2e:headless
|
|
26
|
+
```
|
|
@@ -1295,12 +1295,20 @@ const create = (uid, x, y, width, height) => {
|
|
|
1295
1295
|
set(uid, state, state);
|
|
1296
1296
|
};
|
|
1297
1297
|
|
|
1298
|
+
const cardGap = 8;
|
|
1299
|
+
const cardMinWidth = 180;
|
|
1300
|
+
const viewHorizontalPadding = 32;
|
|
1301
|
+
const getColumnCount = width => {
|
|
1302
|
+
const availableWidth = Math.max(0, width - viewHorizontalPadding);
|
|
1303
|
+
return Math.max(1, Math.floor((availableWidth + cardGap) / (cardMinWidth + cardGap)));
|
|
1304
|
+
};
|
|
1305
|
+
|
|
1298
1306
|
const diff2 = uid => {
|
|
1299
1307
|
const {
|
|
1300
1308
|
oldState,
|
|
1301
1309
|
scheduledState
|
|
1302
1310
|
} = get(uid);
|
|
1303
|
-
return oldState.components === scheduledState.components && oldState.loaded === scheduledState.loaded ? [] : [1];
|
|
1311
|
+
return oldState.components === scheduledState.components && oldState.loaded === scheduledState.loaded && getColumnCount(oldState.width) === getColumnCount(scheduledState.width) ? [] : [1];
|
|
1304
1312
|
};
|
|
1305
1313
|
|
|
1306
1314
|
const pattern = /^live-component-state:\/\/\/(\d+)\.json$/;
|
|
@@ -1365,8 +1373,9 @@ const CardStatus = 'ComponentStateCardStatus';
|
|
|
1365
1373
|
const CardTitle = 'ComponentStateCardTitle';
|
|
1366
1374
|
const CardUid = 'ComponentStateCardUid';
|
|
1367
1375
|
const Description = 'ComponentStateDescription';
|
|
1368
|
-
const Grid = 'ComponentStateGrid';
|
|
1369
1376
|
const Heading = 'ComponentStateHeading';
|
|
1377
|
+
const Row = 'ComponentStateRow';
|
|
1378
|
+
const Rows = 'ComponentStateRows';
|
|
1370
1379
|
const View = 'ComponentStateView';
|
|
1371
1380
|
|
|
1372
1381
|
const HandleClick = 1;
|
|
@@ -1413,13 +1422,27 @@ const descriptionNode = {
|
|
|
1413
1422
|
className: Description,
|
|
1414
1423
|
type: Div
|
|
1415
1424
|
};
|
|
1416
|
-
const
|
|
1425
|
+
const getRows = (components, columnCount) => {
|
|
1426
|
+
const rows = [];
|
|
1427
|
+
for (let index = 0; index < components.length; index += columnCount) {
|
|
1428
|
+
const row = components.slice(index, index + columnCount);
|
|
1429
|
+
rows.push({
|
|
1430
|
+
childCount: row.length,
|
|
1431
|
+
className: Row,
|
|
1432
|
+
type: Div
|
|
1433
|
+
}, ...row.flatMap(getCard));
|
|
1434
|
+
}
|
|
1435
|
+
return rows;
|
|
1436
|
+
};
|
|
1437
|
+
const getComponentStateVirtualDom = (components, loaded, width) => {
|
|
1417
1438
|
const description = loaded ? `${components.length} live components` : 'Loading live components…';
|
|
1439
|
+
const columnCount = getColumnCount(width);
|
|
1440
|
+
const rowCount = Math.ceil(components.length / columnCount);
|
|
1418
1441
|
return [viewNode, headingNode, text('Live Component State'), descriptionNode, text(description), {
|
|
1419
|
-
childCount:
|
|
1420
|
-
className:
|
|
1442
|
+
childCount: rowCount,
|
|
1443
|
+
className: Rows,
|
|
1421
1444
|
type: Div
|
|
1422
|
-
}, ...components
|
|
1445
|
+
}, ...getRows(components, columnCount)];
|
|
1423
1446
|
};
|
|
1424
1447
|
|
|
1425
1448
|
const render2 = (uid, diffResult) => {
|
|
@@ -1430,7 +1453,7 @@ const render2 = (uid, diffResult) => {
|
|
|
1430
1453
|
if (diffResult.length === 0) {
|
|
1431
1454
|
return [];
|
|
1432
1455
|
}
|
|
1433
|
-
return [[SetDom2, uid, getComponentStateVirtualDom(newState.components, newState.loaded)]];
|
|
1456
|
+
return [[SetDom2, uid, getComponentStateVirtualDom(newState.components, newState.loaded, newState.width)]];
|
|
1434
1457
|
};
|
|
1435
1458
|
|
|
1436
1459
|
const renderEventListeners = () => [{
|