vite-plugin-automock 1.1.3 → 1.1.4

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.
@@ -1257,6 +1257,75 @@
1257
1257
  attachTreeEventListeners();
1258
1258
  }
1259
1259
 
1260
+ // Collect all mock keys affected by a checkbox toggle (from DOM)
1261
+ function collectAffectedKeys(nodeEl) {
1262
+ const deleteBtn = nodeEl.querySelector('.tree-node-delete');
1263
+ // File node: has data-mock-key
1264
+ if (deleteBtn && deleteBtn.dataset.mockKey) {
1265
+ return [deleteBtn.dataset.mockKey];
1266
+ }
1267
+ // Folder node: has data-mock-keys (JSON array)
1268
+ if (deleteBtn && deleteBtn.dataset.mockKeys) {
1269
+ try { return JSON.parse(deleteBtn.dataset.mockKeys); } catch { return []; }
1270
+ }
1271
+ // Fallback: collect from all child file nodes
1272
+ const keys = [];
1273
+ nodeEl.querySelectorAll('.tree-node-delete[data-is-folder="false"]').forEach(btn => {
1274
+ if (btn.dataset.mockKey) keys.push(btn.dataset.mockKey);
1275
+ });
1276
+ return keys;
1277
+ }
1278
+
1279
+ // Incremental DOM update for checkbox state changes
1280
+ function updateCheckboxStatesInDOM(nodeEl, checked) {
1281
+ // Update all descendant checkboxes
1282
+ nodeEl.querySelectorAll('.tree-node-checkbox').forEach(cb => {
1283
+ cb.checked = checked;
1284
+ cb.indeterminate = false;
1285
+ cb.removeAttribute('data-indeterminate');
1286
+ });
1287
+ // Update the clicked checkbox itself (it may not be a descendant selector match)
1288
+ const selfCb = nodeEl.querySelector(':scope > .tree-node-content > .tree-node-checkbox');
1289
+ if (selfCb) {
1290
+ selfCb.checked = checked;
1291
+ selfCb.indeterminate = false;
1292
+ selfCb.removeAttribute('data-indeterminate');
1293
+ }
1294
+
1295
+ // Update parent chain (indeterminate state)
1296
+ let current = nodeEl.parentElement;
1297
+ while (current) {
1298
+ const parentNode = current.closest('.tree-node');
1299
+ if (!parentNode) break;
1300
+
1301
+ const childContainer = parentNode.querySelector(':scope > .tree-children');
1302
+ if (!childContainer) break;
1303
+
1304
+ const childCheckboxes = childContainer.querySelectorAll(':scope > .tree-node > .tree-node-content > .tree-node-checkbox');
1305
+ if (childCheckboxes.length === 0) break;
1306
+
1307
+ let allChecked = true;
1308
+ let someChecked = false;
1309
+ childCheckboxes.forEach(cb => {
1310
+ if (cb.checked || cb.indeterminate) someChecked = true;
1311
+ if (!cb.checked || cb.indeterminate) allChecked = false;
1312
+ });
1313
+
1314
+ const parentCb = parentNode.querySelector(':scope > .tree-node-content > .tree-node-checkbox');
1315
+ if (parentCb) {
1316
+ parentCb.checked = allChecked;
1317
+ parentCb.indeterminate = !allChecked && someChecked;
1318
+ if (parentCb.indeterminate) {
1319
+ parentCb.setAttribute('data-indeterminate', 'true');
1320
+ } else {
1321
+ parentCb.removeAttribute('data-indeterminate');
1322
+ }
1323
+ }
1324
+
1325
+ current = parentNode.parentElement;
1326
+ }
1327
+ }
1328
+
1260
1329
  // Attach event listeners for tree interactions
1261
1330
  function attachTreeEventListeners() {
1262
1331
  const list = document.getElementById('mock-list');
@@ -1282,27 +1351,16 @@
1282
1351
  if (!nodeEl) return;
1283
1352
 
1284
1353
  const nodeId = nodeEl.dataset.nodeId;
1285
- const nodeType = nodeEl.dataset.nodeType;
1286
1354
  const checked = checkbox.checked;
1287
1355
 
1288
- // Get current tree data
1289
- const tree = buildMockTree(currentMocks);
1356
+ // Collect affected keys from DOM
1357
+ const affectedKeys = collectAffectedKeys(nodeEl);
1290
1358
 
1291
- // Find and update node
1292
- const node = findNodeById(tree, nodeId);
1293
- if (node) {
1294
- // Update children
1295
- updateTreeNodeState(node, checked, true);
1296
- // Update parents
1297
- updateParentNodeState(node, tree);
1359
+ // Send batch API request
1360
+ await batchToggleMockEnable(affectedKeys, checked);
1298
1361
 
1299
- // Apply changes to all affected file nodes
1300
- const affectedKeys = getAllFileKeys(node);
1301
- await batchToggleMockEnable(affectedKeys, checked);
1302
-
1303
- // Re-render tree with preserved expanded state
1304
- renderMockList(currentMocks, true);
1305
- }
1362
+ // Incremental DOM update (no full re-render)
1363
+ updateCheckboxStatesInDOM(nodeEl, checked);
1306
1364
  });
1307
1365
  });
1308
1366
 
@@ -1485,7 +1543,7 @@
1485
1543
  ' <h3>Response Data</h3>',
1486
1544
  ' ' + renderDataSection(mock),
1487
1545
  '</div>'
1488
- ].join('\\n');
1546
+ ].join('');
1489
1547
 
1490
1548
  const descriptionInput = document.getElementById('description-input');
1491
1549
  if (descriptionInput) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-automock",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {