@popcraft/cli 0.53.14 → 0.53.16

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.
Files changed (2) hide show
  1. package/dist/popcraft.mjs +160 -53
  2. package/package.json +2 -2
package/dist/popcraft.mjs CHANGED
@@ -1198,7 +1198,7 @@ function operations(spec = openapi) {
1198
1198
  }
1199
1199
  async function call(target2, method, path, opts = {}) {
1200
1200
  const qs = new URLSearchParams(opts.query ?? {}).toString();
1201
- const headers = { "user-agent": `popcraft-cli/${"0.53.14"}`, ...opts.headers };
1201
+ const headers = { "user-agent": `popcraft-cli/${"0.53.16"}`, ...opts.headers };
1202
1202
  if (target2.token) headers.authorization = `Bearer ${target2.token}`;
1203
1203
  if (opts.contentType) headers["content-type"] = opts.contentType;
1204
1204
  try {
@@ -8179,6 +8179,8 @@ function duplicateNode(document2, nodeId2, offset = { x: 10, y: 10 }) {
8179
8179
  }
8180
8180
  const newNode = cloneNode(node2);
8181
8181
  let doc2 = addNode(document2, newNode, node2.parentId);
8182
+ const at4 = document2.nodes[node2.parentId]?.childIds.indexOf(nodeId2) ?? -1;
8183
+ if (at4 >= 0) doc2 = reparentNode(doc2, newNode.id, node2.parentId, at4 + 1);
8182
8184
  function cloneChildren(originalId, newParentId) {
8183
8185
  const original = document2.nodes[originalId];
8184
8186
  if (!original) return;
@@ -8188,6 +8190,7 @@ function duplicateNode(document2, nodeId2, offset = { x: 10, y: 10 }) {
8188
8190
  const newChild = cloneNode(child);
8189
8191
  newChild.x = child.x;
8190
8192
  newChild.y = child.y;
8193
+ newChild.name = child.name;
8191
8194
  doc2 = addNode(doc2, newChild, newParentId);
8192
8195
  cloneChildren(childId, newChild.id);
8193
8196
  }
@@ -29182,6 +29185,73 @@ var init_flags = __esm({
29182
29185
  }
29183
29186
  });
29184
29187
 
29188
+ // lib/document/z-order.ts
29189
+ function reorderSelection(doc2, ids2, dir) {
29190
+ const selected = new Set(ids2);
29191
+ const parents = /* @__PURE__ */ new Set();
29192
+ for (const id3 of ids2) {
29193
+ const p2 = doc2.nodes[id3]?.parentId;
29194
+ if (p2 && doc2.nodes[p2]) parents.add(p2);
29195
+ }
29196
+ if (!parents.size) return doc2;
29197
+ const nodes = { ...doc2.nodes };
29198
+ let changed = false;
29199
+ for (const pid of parents) {
29200
+ const list2 = [...nodes[pid].childIds];
29201
+ if (dir === "top" || dir === "bottom") {
29202
+ const sel = list2.filter((id3) => selected.has(id3)), rest = list2.filter((id3) => !selected.has(id3));
29203
+ const next2 = dir === "top" ? [...rest, ...sel] : [...sel, ...rest];
29204
+ if (next2.some((id3, i2) => id3 !== list2[i2])) {
29205
+ nodes[pid] = { ...nodes[pid], childIds: next2 };
29206
+ changed = true;
29207
+ }
29208
+ continue;
29209
+ }
29210
+ let moved3 = false;
29211
+ if (dir === "up") {
29212
+ for (let i2 = list2.length - 2; i2 >= 0; i2--) {
29213
+ if (selected.has(list2[i2]) && !selected.has(list2[i2 + 1])) {
29214
+ [list2[i2], list2[i2 + 1]] = [list2[i2 + 1], list2[i2]];
29215
+ moved3 = true;
29216
+ }
29217
+ }
29218
+ } else {
29219
+ for (let i2 = 1; i2 < list2.length; i2++) {
29220
+ if (selected.has(list2[i2]) && !selected.has(list2[i2 - 1])) {
29221
+ [list2[i2], list2[i2 - 1]] = [list2[i2 - 1], list2[i2]];
29222
+ moved3 = true;
29223
+ }
29224
+ }
29225
+ }
29226
+ if (moved3) {
29227
+ nodes[pid] = { ...nodes[pid], childIds: list2 };
29228
+ changed = true;
29229
+ }
29230
+ }
29231
+ return changed ? { ...doc2, nodes } : doc2;
29232
+ }
29233
+ var init_z_order = __esm({
29234
+ "lib/document/z-order.ts"() {
29235
+ }
29236
+ });
29237
+
29238
+ // lib/editor/selection-drill.ts
29239
+ function selectAllTargets(doc2, pageId2, selection) {
29240
+ const parentId = (selection.length ? resolveVirtualNode2(doc2.nodes, selection[0])?.parentId : null) ?? pageId2;
29241
+ const parent = doc2.nodes[parentId] ?? doc2.nodes[pageId2];
29242
+ return (parent?.childIds ?? []).filter((id3) => selectable(doc2, id3));
29243
+ }
29244
+ var selectable;
29245
+ var init_selection_drill = __esm({
29246
+ "lib/editor/selection-drill.ts"() {
29247
+ init_scene_graph();
29248
+ selectable = (doc2, id3) => {
29249
+ const n = doc2.nodes[id3];
29250
+ return !!n && n.visible !== false && !n.locked;
29251
+ };
29252
+ }
29253
+ });
29254
+
29185
29255
  // lib/document/history-group.ts
29186
29256
  function withHistoryGroup(group2, fn) {
29187
29257
  if (!group2) return fn();
@@ -94515,7 +94585,6 @@ function hasMessage(key5) {
94515
94585
  var current2, loading, listeners, formats, asts;
94516
94586
  var init_runtime = __esm({
94517
94587
  "lib/i18n/runtime.ts"() {
94518
- "use strict";
94519
94588
  init_intl_messageformat();
94520
94589
  init_icu_messageformat_parser();
94521
94590
  init_catalogs();
@@ -96875,6 +96944,7 @@ function releaseMediaMemory(hash3) {
96875
96944
  var key2, peaksKey, objectUrls, sourceKey, remoteResolver, MEDIA_FETCH_TIMEOUT_MS, SHIPPED_MEDIA_PATH, notShipped, MEDIA_SCHEME, isImageDataUrl, memory, pendingLoads, sourceAliases, PAINT_KEYS, URL_KEYS;
96876
96945
  var init_media_store = __esm({
96877
96946
  "lib/storage/media-store.ts"() {
96947
+ "use strict";
96878
96948
  init_media_types();
96879
96949
  init_idb();
96880
96950
  init_media_hash();
@@ -248032,6 +248102,7 @@ function repairCompositions(comps, nodes) {
248032
248102
  var isObj5, finite6, optFinite, isVec2, TIMELINE_COLOR_IDS, TIMELINE_COLORS, UNITS, ORDERS, PROP_KEYS, ANIMATOR_ID, MOTION_TYPES, TRANSITIONS, isFraction, MEDIA_HASH;
248033
248103
  var init_invariants = __esm({
248034
248104
  "lib/motion/invariants.ts"() {
248105
+ "use strict";
248035
248106
  init_easing();
248036
248107
  init_properties();
248037
248108
  init_markers();
@@ -252666,7 +252737,6 @@ function resizeWindow(doc2, target2, rect) {
252666
252737
  }
252667
252738
  var init_crop = __esm({
252668
252739
  "lib/editor/crop.ts"() {
252669
- "use strict";
252670
252740
  init_dist_node();
252671
252741
  init_scene_graph();
252672
252742
  init_photo_frames();
@@ -262770,7 +262840,6 @@ function formatDate(date5, opts = { month: "short", day: "numeric", year: "numer
262770
262840
  var cache5, nf;
262771
262841
  var init_format = __esm({
262772
262842
  "lib/i18n/format.ts"() {
262773
- "use strict";
262774
262843
  init_runtime();
262775
262844
  cache5 = /* @__PURE__ */ new Map();
262776
262845
  nf = (opts) => cached2("n", opts, (l) => new Intl.NumberFormat(l, opts));
@@ -262790,6 +262859,7 @@ function formatLimit(key5, max3) {
262790
262859
  var formatBytes;
262791
262860
  var init_limits2 = __esm({
262792
262861
  "lib/billing/limits.ts"() {
262862
+ "use strict";
262793
262863
  init_format();
262794
262864
  init_plans();
262795
262865
  formatBytes = formatFileSize;
@@ -312396,7 +312466,6 @@ function creditLine(c2) {
312396
312466
  var MAX_PHOTO_PAGE, MAX_PHOTO_QUERY, UUID, isPhotoId, photoImagePath;
312397
312467
  var init_stock = __esm({
312398
312468
  "lib/photos/stock.ts"() {
312399
- "use strict";
312400
312469
  MAX_PHOTO_PAGE = 12;
312401
312470
  MAX_PHOTO_QUERY = 200;
312402
312471
  UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
@@ -313058,7 +313127,6 @@ function applyTextPath(layout2, path, tp, rebase = true) {
313058
313127
  var defaultCircleRadius, ownsPath, mapPoint;
313059
313128
  var init_text_path = __esm({
313060
313129
  "lib/engine/text/text-path.ts"() {
313061
- "use strict";
313062
313130
  init_scene_graph();
313063
313131
  init_transform();
313064
313132
  init_shape_to_path();
@@ -313176,7 +313244,6 @@ function areaBounds(rings) {
313176
313244
  }
313177
313245
  var init_text_area = __esm({
313178
313246
  "lib/engine/text/text-area.ts"() {
313179
- "use strict";
313180
313247
  }
313181
313248
  });
313182
313249
 
@@ -319305,7 +319372,7 @@ function placeSvgLayers(doc2, parentId, svg, place4) {
319305
319372
  }
319306
319373
  const minX = Math.min(...kids.map((k3) => k3.x)), minY = Math.min(...kids.map((k3) => k3.y));
319307
319374
  const maxX = Math.max(...kids.map((k3) => k3.x + k3.width)), maxY = Math.max(...kids.map((k3) => k3.y + k3.height));
319308
- for (const k3 of kids) nodes[k3.id] = { ...nodes[k3.id], x: k3.x - minX, y: k3.y - minY };
319375
+ for (const k3 of kids) nodes[k3.id] = { ...nodes[k3.id], x: k3.x - minX, y: k3.y - minY, constraints: { horizontal: "SCALE", vertical: "SCALE" } };
319309
319376
  let w = Math.max(1, maxX - minX), h = Math.max(1, maxY - minY);
319310
319377
  const f2 = place4.fit;
319311
319378
  const k2 = f2 && (f2.width || f2.height) ? Math.min(f2.width ? f2.width / w : Infinity, f2.height ? f2.height / h : Infinity) : 1;
@@ -319391,6 +319458,7 @@ var nodeFind, nodeGet, nodeMeasure, docOutline, CREATABLE, nodeCreate, FORBIDDEN
319391
319458
  var init_node = __esm({
319392
319459
  "lib/commands/node.ts"() {
319393
319460
  "use strict";
319461
+ init_z_order();
319394
319462
  init_zod();
319395
319463
  init_limits();
319396
319464
  init_search();
@@ -319920,12 +319988,20 @@ var init_node = __esm({
319920
319988
  capped(args2.ids, "reparent");
319921
319989
  const parent = nodeOrThrow(doc2, args2.parentId);
319922
319990
  let next2 = doc2;
319923
- for (const id3 of args2.ids) {
319991
+ const stackIndex = (id3) => {
319992
+ const n = doc2.nodes[id3];
319993
+ const p2 = n?.parentId ? doc2.nodes[n.parentId] : void 0;
319994
+ return p2 ? p2.childIds.indexOf(id3) : 0;
319995
+ };
319996
+ const ordered2 = [...args2.ids].sort((a, b) => doc2.nodes[a]?.parentId === doc2.nodes[b]?.parentId ? stackIndex(a) - stackIndex(b) : 0);
319997
+ let insertAt = args2.index;
319998
+ for (const id3 of ordered2) {
319924
319999
  nodeOrThrow(doc2, id3);
319925
320000
  if (id3 === args2.parentId) throw new ToolError("A layer cannot be its own parent.");
319926
320001
  const placed2 = placementUnder(next2, id3, args2.parentId);
319927
320002
  if (placed2) next2 = updateNode(next2, id3, placed2);
319928
- next2 = reparentNode(next2, id3, args2.parentId, args2.index);
320003
+ next2 = reparentNode(next2, id3, args2.parentId, insertAt);
320004
+ if (insertAt !== void 0) insertAt = next2.nodes[args2.parentId].childIds.indexOf(id3) + 1;
319929
320005
  }
319930
320006
  ctx2.commit(applyInvariants(next2, [...args2.ids, args2.parentId]));
319931
320007
  return { summary: `Moved ${plural2(args2.ids.length, "layer")} into "${parent.name}"`, data: { ids: args2.ids, parentId: args2.parentId } };
@@ -319954,10 +320030,12 @@ var init_node = __esm({
319954
320030
  const box2 = localBox(doc2, ids2);
319955
320031
  const g = createGroup();
319956
320032
  const node2 = { ...g, name: args2.name ?? g.name, x: box2.minX, y: box2.minY, width: box2.maxX - box2.minX, height: box2.maxY - box2.minY };
319957
- const index2 = Math.min(...ids2.map((id3) => doc2.nodes[parentId].childIds.indexOf(id3)).filter((i2) => i2 >= 0));
320033
+ const siblings = doc2.nodes[parentId].childIds;
320034
+ const ordered2 = [...ids2].sort((a, b) => siblings.indexOf(a) - siblings.indexOf(b));
320035
+ const top = Math.max(...ordered2.map((id3) => siblings.indexOf(id3)));
319958
320036
  let next2 = addNode(doc2, node2, parentId);
319959
- next2 = reparentNode(next2, node2.id, parentId, index2);
319960
- for (const id3 of ids2) {
320037
+ next2 = reparentNode(next2, node2.id, parentId, top + 1);
320038
+ for (const id3 of ordered2) {
319961
320039
  const n = next2.nodes[id3];
319962
320040
  next2 = reparentNode(next2, id3, node2.id);
319963
320041
  next2 = updateNode(next2, id3, { x: n.x - box2.minX, y: n.y - box2.minY });
@@ -320038,7 +320116,7 @@ var init_node = __esm({
320038
320116
  run: (args2, ctx2) => {
320039
320117
  const { doc: doc2, ids: ids2 } = resolveTargets(ctx2, args2.ids, "order");
320040
320118
  let next2 = doc2;
320041
- for (const id3 of ids2) next2 = moveNodeInZOrder(next2, id3, args2.direction);
320119
+ next2 = reorderSelection(next2, ids2, args2.direction);
320042
320120
  ctx2.commit(next2);
320043
320121
  return { summary: `Moved ${plural2(ids2.length, "layer")} ${args2.direction}`, data: { ids: ids2 } };
320044
320122
  }
@@ -328830,7 +328908,7 @@ var init_package = __esm({
328830
328908
  "packages/runtime/package.json"() {
328831
328909
  package_default = {
328832
328910
  name: "@popcraft/runtime",
328833
- version: "0.53.14",
328911
+ version: "0.53.16",
328834
328912
  description: "What code exported from PopCraft shares: the meaning of expressions (operators and functions) and, as it grows, the parts of a design's behaviour that are common code rather than generated React.",
328835
328913
  license: "MIT",
328836
328914
  homepage: "https://popcraft.app/docs/exporting/nextjs",
@@ -353496,7 +353574,6 @@ function exportsOf(source3) {
353496
353574
  var CODE_LIMITS, packageOf;
353497
353575
  var init_source2 = __esm({
353498
353576
  "lib/code/source.ts"() {
353499
- "use strict";
353500
353577
  CODE_LIMITS = { modules: 100, sourceLength: 2e5, packages: 12 };
353501
353578
  packageOf = (spec) => spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
353502
353579
  }
@@ -353539,7 +353616,6 @@ function compileModule(module2) {
353539
353616
  var import_sucrase, BUILT_IN, memo4;
353540
353617
  var init_compile2 = __esm({
353541
353618
  "lib/code/compile.ts"() {
353542
- "use strict";
353543
353619
  import_sucrase = __toESM(require_dist2());
353544
353620
  init_source2();
353545
353621
  init_source2();
@@ -360424,6 +360500,13 @@ var init_cell_text = __esm({
360424
360500
  }
360425
360501
  });
360426
360502
 
360503
+ // lib/document/resize-children.ts
360504
+ var init_resize_children = __esm({
360505
+ "lib/document/resize-children.ts"() {
360506
+ init_scale_geometry();
360507
+ }
360508
+ });
360509
+
360427
360510
  // lib/editor/pointer/move/snap.ts
360428
360511
  var init_snap = __esm({
360429
360512
  "lib/editor/pointer/move/snap.ts"() {
@@ -360435,6 +360518,7 @@ var init_snap = __esm({
360435
360518
  // lib/editor/pointer/move/group-resize.ts
360436
360519
  var init_group_resize = __esm({
360437
360520
  "lib/editor/pointer/move/group-resize.ts"() {
360521
+ init_resize_children();
360438
360522
  init_scene_graph();
360439
360523
  init_selection_bounds();
360440
360524
  init_snap();
@@ -408076,6 +408160,8 @@ function placeInstance(document2, mainComponentId, pageId2, x2, y) {
408076
408160
  var STICKY_PROP_KEYS, initialDocument, initialPageId, TABS_PREFS_KEY, isUnsavedPlaceholder, libraryDocs, markLibraryDocument, isPersistableDocument, resetLibraryDocuments, MAX_OPEN_NODES, sessionDocumentInLibrary, saveFailureNotified, saveTimeout, latestValue, isSaving, firstPendingAt, SAVE_IDLE_MS, SAVE_MAX_WAIT_MS, pendingSave, customIdbPersistStorage, readOnlyToldAt, useEditorStore, useSelection, useActiveTool, useCamera, useCurrentPageId, useDocument, glideToken, useMode;
408077
408161
  var init_editor_store = __esm({
408078
408162
  "lib/store/editor-store.ts"() {
408163
+ init_z_order();
408164
+ init_selection_drill();
408079
408165
  init_history_group();
408080
408166
  init_pixel_art();
408081
408167
  init_runtime();
@@ -409291,12 +409377,29 @@ var init_editor_store = __esm({
409291
409377
  const topLevelNodes = nodes.filter((n) => !n.parentId || !clipboardIds.has(n.parentId));
409292
409378
  const newNodes = { ...doc2.nodes };
409293
409379
  const updatedParents = /* @__PURE__ */ new Map();
409380
+ const PASTE_INTO = /* @__PURE__ */ new Set(["FRAME", "COMPONENT", "SECTION"]);
409381
+ const sel = state.selection.length === 1 ? doc2.nodes[state.selection[0]] : void 0;
409382
+ const into = sel && PASTE_INTO.has(sel.type) && !clipboardIds.has(sel.id) ? sel : void 0;
409383
+ const pageOf4 = (d, id3) => {
409384
+ let n = d.nodes[id3];
409385
+ for (let guard2 = 0; n && n.type !== "PAGE" && guard2 < 64; guard2++) n = n.parentId ? d.nodes[n.parentId] : void 0;
409386
+ return n?.id;
409387
+ };
409388
+ const parentFor = (n) => {
409389
+ if (into) return into.id;
409390
+ if (n.parentId && doc2.nodes[n.parentId] && doc2.nodes[n.parentId].type !== "PAGE" && pageOf4(doc2, n.parentId) === state.currentPageId) return n.parentId;
409391
+ return state.currentPageId;
409392
+ };
409294
409393
  nodes.forEach((n) => {
409295
409394
  const newNode = { ...n, id: idMap.get(n.id) };
409296
409395
  if (topLevelNodes.includes(n)) {
409297
409396
  newNode.x += offset.x;
409298
409397
  newNode.y += offset.y;
409299
- newNode.parentId = state.currentPageId;
409398
+ newNode.parentId = parentFor(n);
409399
+ if (into && n.parentId !== into.id && (newNode.x < 0 || newNode.y < 0 || newNode.x > into.width || newNode.y > into.height)) {
409400
+ newNode.x = (into.width - newNode.width) / 2;
409401
+ newNode.y = (into.height - newNode.height) / 2;
409402
+ }
409300
409403
  newSelection.push(newNode.id);
409301
409404
  } else {
409302
409405
  newNode.parentId = idMap.get(n.parentId);
@@ -409470,10 +409573,7 @@ var init_editor_store = __esm({
409470
409573
  })),
409471
409574
  selectAll: () => {
409472
409575
  const state = get4();
409473
- const page = state.document.nodes[state.currentPageId];
409474
- if (page) {
409475
- set4({ selection: [...page.childIds] });
409476
- }
409576
+ set4({ selection: selectAllTargets(state.document, state.currentPageId, state.selection) });
409477
409577
  },
409478
409578
  deselectAll: () => set4({ selection: [] }),
409479
409579
  toggleSelectionVisibility: () => {
@@ -410238,55 +410338,61 @@ var init_editor_store = __esm({
410238
410338
  }
410239
410339
  };
410240
410340
  }),
410241
- // Z-order actions
410242
- bringToFront: () => {
410341
+ // Z-order actions: the selection moves as a block, keeps its own order, and can be undone (lib/document/z-order.ts).
410342
+ bringToFront: () => get4().reorderSelectionZ("top"),
410343
+ sendToBack: () => get4().reorderSelectionZ("bottom"),
410344
+ bringForward: () => get4().reorderSelectionZ("up"),
410345
+ sendBackward: () => get4().reorderSelectionZ("down"),
410346
+ reorderSelectionZ: (dir) => {
410243
410347
  const state = get4();
410244
- state.selection.forEach((id3) => {
410245
- set4({ document: moveNodeInZOrder(get4().document, id3, "top") });
410246
- });
410247
- },
410248
- sendToBack: () => {
410249
- const state = get4();
410250
- state.selection.forEach((id3) => {
410251
- set4({ document: moveNodeInZOrder(get4().document, id3, "bottom") });
410252
- });
410253
- },
410254
- bringForward: () => {
410255
- const state = get4();
410256
- state.selection.forEach((id3) => {
410257
- set4({ document: moveNodeInZOrder(get4().document, id3, "up") });
410258
- });
410259
- },
410260
- sendBackward: () => {
410261
- const state = get4();
410262
- state.selection.forEach((id3) => {
410263
- set4({ document: moveNodeInZOrder(get4().document, id3, "down") });
410264
- });
410348
+ const next2 = reorderSelection(state.document, state.selection, dir);
410349
+ if (next2 === state.document) return;
410350
+ const label3 = { top: "Bring to front", bottom: "Send to back", up: "Bring forward", down: "Send backward" }[dir];
410351
+ set4({ document: next2, history: pushCommand(state.history, createCommand("REORDER", label3, state.document, next2)) });
410265
410352
  },
410266
410353
  // Group actions
410267
410354
  groupSelection: () => {
410268
410355
  const state = get4();
410269
410356
  if (state.selection.length < 2) return;
410270
410357
  const documentBefore = state.document;
410358
+ let base = state.document;
410359
+ const order2 = /* @__PURE__ */ new Map();
410360
+ const walk4 = (id3) => {
410361
+ order2.set(id3, order2.size);
410362
+ for (const c2 of base.nodes[id3]?.childIds ?? []) walk4(c2);
410363
+ };
410364
+ walk4(state.currentPageId);
410365
+ const topmost = [...state.selection].sort((x2, y) => (order2.get(y) ?? 0) - (order2.get(x2) ?? 0))[0];
410366
+ const target2 = base.nodes[topmost]?.parentId ?? state.currentPageId;
410367
+ for (const id3 of state.selection) {
410368
+ const n = base.nodes[id3];
410369
+ if (!n || n.parentId === target2) continue;
410370
+ const placed2 = placementUnder(base, id3, target2);
410371
+ if (placed2) base = updateNode(base, id3, placed2);
410372
+ base = reparentNode(base, id3, target2);
410373
+ }
410271
410374
  let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
410272
410375
  state.selection.forEach((id3) => {
410273
- const n = state.document.nodes[id3];
410376
+ const n = base.nodes[id3];
410274
410377
  if (!n) return;
410275
410378
  minX = Math.min(minX, n.x);
410276
410379
  minY = Math.min(minY, n.y);
410277
410380
  maxX = Math.max(maxX, n.x + n.width);
410278
410381
  maxY = Math.max(maxY, n.y + n.height);
410279
410382
  });
410280
- const firstNode = state.document.nodes[state.selection[0]];
410281
- const parentId = firstNode?.parentId ?? state.currentPageId;
410383
+ const parentId = target2;
410282
410384
  const group2 = createGroup([]);
410283
410385
  group2.x = minX;
410284
410386
  group2.y = minY;
410285
410387
  group2.width = maxX - minX;
410286
410388
  group2.height = maxY - minY;
410287
410389
  group2.name = "Group";
410288
- let doc2 = addNode(state.document, group2, parentId);
410289
- state.selection.forEach((id3) => {
410390
+ const siblings = base.nodes[parentId]?.childIds ?? [];
410391
+ const ordered2 = [...state.selection].sort((a, b) => siblings.indexOf(a) - siblings.indexOf(b));
410392
+ const top = Math.max(...ordered2.map((id3) => siblings.indexOf(id3)));
410393
+ let doc2 = addNode(base, group2, parentId);
410394
+ if (top >= 0) doc2 = reparentNode(doc2, group2.id, parentId, top + 1);
410395
+ ordered2.forEach((id3) => {
410290
410396
  doc2 = reparentNode(doc2, id3, group2.id);
410291
410397
  const child = doc2.nodes[id3];
410292
410398
  if (child) {
@@ -410316,8 +410422,9 @@ var init_editor_store = __esm({
410316
410422
  return;
410317
410423
  }
410318
410424
  const parentId = node2.parentId ?? state.currentPageId;
410319
- node2.childIds.forEach((childId) => {
410320
- doc2 = reparentNode(doc2, childId, parentId);
410425
+ const slot2 = doc2.nodes[parentId]?.childIds.indexOf(id3) ?? -1;
410426
+ node2.childIds.forEach((childId, i2) => {
410427
+ doc2 = reparentNode(doc2, childId, parentId, slot2 >= 0 ? slot2 + i2 : void 0);
410321
410428
  const child = doc2.nodes[childId];
410322
410429
  if (child) {
410323
410430
  doc2.nodes[childId] = {
@@ -414425,7 +414532,7 @@ init_resources();
414425
414532
  init_desktop();
414426
414533
  init_hypery();
414427
414534
  import { createInterface } from "node:readline";
414428
- var VERSION2 = "0.53.14";
414535
+ var VERSION2 = "0.53.16";
414429
414536
  var HELP = `popcraft ${VERSION2} \u2014 the PopCraft command line
414430
414537
 
414431
414538
  Files (headless, on .popcraft files):
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@popcraft/cli",
3
- "version": "0.53.14",
3
+ "version": "0.53.16",
4
4
  "description": "The PopCraft command line: edit .popcraft files headlessly, call the REST API, publish to the marketplace and manage the desktop app's local plugins, themes, fonts, skills and agents.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://popcraft.app/docs/api/cli",
@@ -34,7 +34,7 @@
34
34
  "esbuild": "0.28.2"
35
35
  },
36
36
  "dependencies": {
37
- "@popcraft/kit": "0.53.14"
37
+ "@popcraft/kit": "0.53.16"
38
38
  },
39
39
  "scripts": {
40
40
  "build": "node build.mjs",