@lv-x-software-house/x_view 1.2.8-dev.2 → 1.2.8-dev.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.
Files changed (3) hide show
  1. package/dist/index.js +178 -200
  2. package/dist/index.mjs +178 -200
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1545,17 +1545,11 @@ var userActionHandlers = {
1545
1545
  links: sceneDataRef.current.links,
1546
1546
  quest_counter: sceneDataRef.current.quest_counter || 1
1547
1547
  };
1548
- const questFilePayload = {
1549
- nodes: specificParentData.nodes,
1550
- links: specificParentData.links,
1551
- milestones: sceneDataRef.current.milestones || []
1552
- };
1553
1548
  await context.actions.save_view_data(
1554
1549
  context.sceneSaveUrl,
1555
1550
  viewFilePayload
1556
1551
  );
1557
- const questSaveUrl = context.sceneSaveUrl.replace("x_view_scenes", "x_view_quests");
1558
- await context.actions.save_view_data(questSaveUrl, questFilePayload);
1552
+ await context.actions.save_quest_link(context.ownerId, context.sceneConfigId, newLink);
1559
1553
  } else {
1560
1554
  const specificParentData = JSON.parse(
1561
1555
  JSON.stringify(graphDataRef.current[parentFileIdToSave])
@@ -1842,20 +1836,14 @@ var userActionHandlers = {
1842
1836
  links: sceneDataRef.current.links,
1843
1837
  quest_counter: sceneDataRef.current.quest_counter || 1
1844
1838
  };
1845
- questSaveUrl = context.sceneSaveUrl.replace("x_view_scenes", "x_view_quests");
1846
- questFilePayload = {
1847
- nodes: specificParentData.nodes,
1848
- links: specificParentData.links,
1849
- milestones: sceneDataRef.current.milestones || []
1850
- };
1851
1839
  } else {
1852
1840
  filenameToSave = `x_view_dbs/${ownerId}/${parentFileId}`;
1853
1841
  payloadToSave = specificParentData;
1854
1842
  }
1855
1843
  try {
1856
1844
  await context.actions.save_view_data(filenameToSave, payloadToSave);
1857
- if (questSaveUrl && questFilePayload) {
1858
- await context.actions.save_view_data(questSaveUrl, questFilePayload);
1845
+ if (isView && parentFileId === context.sceneConfigId && context.actions.delete_quest_link) {
1846
+ await context.actions.delete_quest_link(ownerId, context.sceneConfigId, linkIdToDelete);
1859
1847
  }
1860
1848
  graphDataRef.current[parentFileId] = specificParentData;
1861
1849
  setters.setDetailsLink(
@@ -2087,13 +2075,15 @@ var userActionHandlers = {
2087
2075
  links: sceneDataRef.current.links,
2088
2076
  quest_counter: sceneDataRef.current.quest_counter || 1
2089
2077
  };
2090
- const questFilePayload = {
2091
- nodes: originalData.nodes,
2092
- links: originalData.links,
2093
- milestones: sceneDataRef.current.milestones || []
2094
- };
2095
- const questSaveUrl = context.sceneSaveUrl.replace("x_view_scenes", "x_view_quests");
2096
- savePromises.push(context.actions.save_view_data(questSaveUrl, questFilePayload));
2078
+ for (const nodeId of nodesToDelete) {
2079
+ const questNode = (originalData.nodes || []).find((n) => String(n.id) === String(nodeId));
2080
+ if (questNode && questNode.is_quest) {
2081
+ await context.actions.delete_quest(ownerId, context.sceneConfigId, nodeId);
2082
+ }
2083
+ }
2084
+ for (const linkId of linksToDelete) {
2085
+ await context.actions.delete_quest_link(ownerId, context.sceneConfigId, linkId);
2086
+ }
2097
2087
  } else {
2098
2088
  filenameToSave = `x_view_dbs/${ownerId}/${parentFileId}`;
2099
2089
  payloadToSave = originalData;
@@ -2185,15 +2175,9 @@ var userActionHandlers = {
2185
2175
  links: newVisualLinks,
2186
2176
  quest_counter: sceneDataRef.current.quest_counter || 1
2187
2177
  };
2188
- const questFilePayload = {
2189
- nodes: specificParentData.nodes,
2190
- links: specificParentData.links,
2191
- milestones: sceneDataRef.current.milestones || []
2192
- };
2193
- const questSaveUrl = context.sceneSaveUrl.replace("x_view_scenes", "x_view_quests");
2194
2178
  try {
2195
2179
  await context.actions.save_view_data(filenameToSave, payloadToSave);
2196
- await context.actions.save_view_data(questSaveUrl, questFilePayload);
2180
+ await context.actions.delete_quest(ownerId, context.sceneConfigId, nodeIdToDelete);
2197
2181
  graphDataRef.current[parentFileId] = specificParentData;
2198
2182
  setters.setDetailsNode(
2199
2183
  (prev) => String(prev == null ? void 0 : prev.id) === String(nodeIdToDelete) ? null : prev
@@ -2223,7 +2207,7 @@ var userActionHandlers = {
2223
2207
  }
2224
2208
  },
2225
2209
  handleSaveNodeDetails: async (context, updatedNode, keepOpen = false) => {
2226
- var _a, _b, _c, _d;
2210
+ var _a, _b, _c;
2227
2211
  const { graphDataRef, sceneDataRef, stateRef, setters } = context;
2228
2212
  if (!graphDataRef.current || !sceneDataRef.current) return;
2229
2213
  const {
@@ -2350,40 +2334,17 @@ var userActionHandlers = {
2350
2334
  ...nodeToSave
2351
2335
  };
2352
2336
  }
2353
- if (nodeToSave.is_quest && context.actions.save_quest_action) {
2354
- await context.actions.save_quest_action(context.ownerId, context.sceneConfigId, nodeToSave, sceneDataRef.current.quest_counter);
2355
- if (isNewDone && ((_d = nodeToSave.recurrence_config) == null ? void 0 : _d.enabled)) {
2356
- const createdRecurrenceQuest = specificParentData.nodes[specificParentData.nodes.length - 1];
2357
- if (createdRecurrenceQuest && String(createdRecurrenceQuest.id) !== String(nodeToSave.id)) {
2358
- await context.actions.save_quest_action(context.ownerId, context.sceneConfigId, createdRecurrenceQuest, sceneDataRef.current.quest_counter);
2359
- }
2360
- }
2361
- const viewFilePayload = {
2362
- parent_dbs: sceneDataRef.current.parent_dbs,
2363
- nodes: sceneDataRef.current.nodes,
2364
- links: sceneDataRef.current.links,
2365
- quest_counter: sceneDataRef.current.quest_counter || 1
2366
- };
2367
- await context.actions.save_view_data(context.sceneSaveUrl, viewFilePayload);
2368
- } else {
2369
- const viewFilePayload = {
2370
- parent_dbs: sceneDataRef.current.parent_dbs,
2371
- nodes: sceneDataRef.current.nodes,
2372
- links: sceneDataRef.current.links,
2373
- quest_counter: sceneDataRef.current.quest_counter || 1
2374
- };
2375
- const questFilePayload = {
2376
- nodes: specificParentData.nodes,
2377
- links: specificParentData.links,
2378
- milestones: sceneDataRef.current.milestones || []
2379
- };
2380
- await context.actions.save_view_data(
2381
- context.sceneSaveUrl,
2382
- viewFilePayload
2383
- );
2384
- const questSaveUrl = context.sceneSaveUrl.replace("x_view_scenes", "x_view_quests");
2385
- await context.actions.save_view_data(questSaveUrl, questFilePayload);
2386
- }
2337
+ const viewFilePayload = {
2338
+ parent_dbs: sceneDataRef.current.parent_dbs,
2339
+ nodes: sceneDataRef.current.nodes,
2340
+ links: sceneDataRef.current.links,
2341
+ quest_counter: sceneDataRef.current.quest_counter || 1
2342
+ };
2343
+ await context.actions.save_view_data(
2344
+ context.sceneSaveUrl,
2345
+ viewFilePayload
2346
+ );
2347
+ await context.actions.save_quest(ownerId, context.sceneConfigId, nodeToSave);
2387
2348
  } else {
2388
2349
  const filenameForSpecificParent = `x_view_dbs/${ownerId}/${parentFileId}`;
2389
2350
  await context.actions.save_view_data(
@@ -15495,13 +15456,12 @@ function XViewScene({
15495
15456
  get_view_members,
15496
15457
  create_google_doc_action,
15497
15458
  open_google_picker_action,
15498
- // Firestore Atomic Actions (Quests & Milestones)
15499
15459
  save_quest_action,
15500
15460
  delete_quest_action,
15501
15461
  save_quest_link_action,
15502
15462
  delete_quest_link_action,
15503
- save_milestone_action,
15504
- delete_milestone_action
15463
+ get_view_quests_and_links_action,
15464
+ migrate_legacy_quests_action
15505
15465
  }) {
15506
15466
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
15507
15467
  const { data: session, status } = (0, import_react34.useSession)();
@@ -16365,11 +16325,32 @@ function XViewScene({
16365
16325
  focusAncestryId
16366
16326
  );
16367
16327
  const boardPromise = get_boards_action && session ? get_boards_action(configPath, sceneType, session, ownerId2) : Promise.resolve({ success: false, data: [] });
16368
- const [sceneResponse, boardResponse] = await Promise.all([
16328
+ const questPromise = get_view_quests_and_links_action && session ? get_view_quests_and_links_action(ownerId2, sceneConfigId) : Promise.resolve({ success: false, quests: [], links: [] });
16329
+ const [sceneResponse, boardResponse, questResponse] = await Promise.all([
16369
16330
  scenePromise,
16370
- boardPromise
16331
+ boardPromise,
16332
+ questPromise
16371
16333
  ]);
16372
16334
  if ((sceneResponse == null ? void 0 : sceneResponse.success) && ((_a2 = sceneResponse.data) == null ? void 0 : _a2.scene) && ((_b2 = sceneResponse.data) == null ? void 0 : _b2.parent)) {
16335
+ const sceneData = sceneResponse.data.scene;
16336
+ let firestoreQuests = (questResponse == null ? void 0 : questResponse.success) ? questResponse.quests : [];
16337
+ let firestoreLinks = (questResponse == null ? void 0 : questResponse.success) ? questResponse.links : [];
16338
+ if (!sceneData.quests_migrated && firestoreQuests.length === 0) {
16339
+ const legacyQuests = sceneData.quest_nodes || [];
16340
+ const legacyLinks = sceneData.quest_links || [];
16341
+ if ((legacyQuests.length > 0 || legacyLinks.length > 0) && migrate_legacy_quests_action) {
16342
+ console.log(
16343
+ "X-View: Iniciando Lazy Migration de Quests para Firestore..."
16344
+ );
16345
+ await migrate_legacy_quests_action(ownerId2, sceneConfigId, {
16346
+ nodes: legacyQuests,
16347
+ links: legacyLinks
16348
+ });
16349
+ firestoreQuests = legacyQuests;
16350
+ firestoreLinks = legacyLinks;
16351
+ sceneData.quests_migrated = true;
16352
+ }
16353
+ }
16373
16354
  if (focusNodeId) {
16374
16355
  let targetNode = sceneResponse.data.scene.nodes.find(
16375
16356
  (n) => String(n.id) === String(focusNodeId)
@@ -16391,10 +16372,29 @@ function XViewScene({
16391
16372
  sceneResponse.data.scene.links = [];
16392
16373
  }
16393
16374
  sceneDataRef.current = {
16394
- ...sceneResponse.data.scene,
16395
- milestones: sceneResponse.data.scene.milestones || []
16375
+ ...sceneData,
16376
+ quests_migrated: sceneData.quests_migrated || false,
16377
+ milestones: sceneData.milestones || []
16396
16378
  };
16397
- parentDataRef.current = sceneResponse.data.parent;
16379
+ const currentParentData = sceneResponse.data.parent;
16380
+ if (currentParentData && currentParentData[sceneConfigId]) {
16381
+ const existingNodes = currentParentData[sceneConfigId].nodes || [];
16382
+ const firestoreQuestIds = new Set(firestoreQuests.map((q) => String(q.id)));
16383
+ const filteredExisting = existingNodes.filter(
16384
+ (n) => !firestoreQuestIds.has(String(n.id))
16385
+ );
16386
+ currentParentData[sceneConfigId].nodes = [
16387
+ ...filteredExisting,
16388
+ ...firestoreQuests
16389
+ ];
16390
+ if (firestoreLinks && firestoreLinks.length > 0) {
16391
+ currentParentData[sceneConfigId].links = [
16392
+ ...currentParentData[sceneConfigId].links || [],
16393
+ ...firestoreLinks
16394
+ ];
16395
+ }
16396
+ }
16397
+ parentDataRef.current = currentParentData;
16398
16398
  ancestryDataRef.current = sceneResponse.data.ancestry;
16399
16399
  console.log(
16400
16400
  "Console de sceneResponse.data.scene:",
@@ -18009,12 +18009,12 @@ function XViewScene({
18009
18009
  get_scene_view_data,
18010
18010
  upload_file: upload_file_action,
18011
18011
  delete_file: delete_file_action,
18012
- save_quest_action,
18013
- delete_quest_action,
18014
- save_quest_link_action,
18015
- delete_quest_link_action,
18016
- save_milestone_action,
18017
- delete_milestone_action
18012
+ save_quest: save_quest_action,
18013
+ delete_quest: delete_quest_action,
18014
+ save_quest_link: save_quest_link_action,
18015
+ delete_quest_link: delete_quest_link_action,
18016
+ get_view_quests_and_links: get_view_quests_and_links_action,
18017
+ migrate_legacy_quests: migrate_legacy_quests_action
18018
18018
  }
18019
18019
  };
18020
18020
  },
@@ -18038,8 +18038,8 @@ function XViewScene({
18038
18038
  delete_quest_action,
18039
18039
  save_quest_link_action,
18040
18040
  delete_quest_link_action,
18041
- save_milestone_action,
18042
- delete_milestone_action
18041
+ get_view_quests_and_links_action,
18042
+ migrate_legacy_quests_action
18043
18043
  ]
18044
18044
  );
18045
18045
  const handleStartVersioning = (nodeData) => {
@@ -18245,28 +18245,19 @@ function XViewScene({
18245
18245
  parentDataRef.current[sceneConfigId].nodes[parentIndex].quest_abstraction_tree = formattedAbstractionTree;
18246
18246
  }
18247
18247
  }
18248
- if (save_quest_action) {
18249
- const updatedNodeData2 = sceneData.quest_nodes[questIndex];
18250
- await save_quest_action(ownerId, sceneConfigId, updatedNodeData2, sceneData.quest_counter || 1);
18251
- } else {
18252
- const sceneFileData = {
18253
- ...sceneData,
18254
- nodes: sceneData.nodes || [],
18255
- links: sceneData.links || [],
18256
- quest_counter: sceneData.quest_counter || 1
18257
- };
18258
- const questFileData = {
18259
- nodes: sceneData.quest_nodes || [],
18260
- links: sceneData.quest_links || [],
18261
- milestones: sceneData.milestones || []
18262
- };
18263
- await save_view_data(sceneSaveUrl, sceneFileData);
18264
- const questSaveUrl = sceneSaveUrl.replace(
18265
- "x_view_scenes",
18266
- "x_view_quests"
18267
- );
18268
- await save_view_data(questSaveUrl, questFileData);
18269
- }
18248
+ const sceneFileData = {
18249
+ ...sceneData,
18250
+ nodes: sceneData.nodes || [],
18251
+ links: sceneData.links || [],
18252
+ quest_counter: sceneData.quest_counter || 1
18253
+ };
18254
+ const questFileData = {
18255
+ nodes: sceneData.quest_nodes || [],
18256
+ links: sceneData.quest_links || [],
18257
+ milestones: sceneData.milestones || []
18258
+ };
18259
+ await save_view_data(sceneSaveUrl, sceneFileData);
18260
+ await save_quest_action(ownerId, sceneConfigId, updatedNodeData);
18270
18261
  }
18271
18262
  const updatedNodeData = sceneData.quest_nodes[questIndex];
18272
18263
  const nodeMesh = (_a2 = stateRef.current.nodeObjects) == null ? void 0 : _a2[String(questNodeId)];
@@ -18347,20 +18338,14 @@ function XViewScene({
18347
18338
  ...sceneDataRef2.current,
18348
18339
  quest_counter: currentCounter + 1
18349
18340
  };
18341
+ const questFileData = {
18342
+ nodes: graphDataRef2.current[sceneConfigId2].nodes,
18343
+ links: graphDataRef2.current[sceneConfigId2].links,
18344
+ milestones: sceneDataRef2.current.milestones || []
18345
+ };
18350
18346
  try {
18351
- if (actions.save_quest_action) {
18352
- await actions.save_quest_action(ownerId2, sceneConfigId2, newNode, currentCounter + 1);
18353
- await actions.save_view_data(sceneSaveUrl2, sceneFileData);
18354
- } else {
18355
- const questFileData = {
18356
- nodes: graphDataRef2.current[sceneConfigId2].nodes,
18357
- links: graphDataRef2.current[sceneConfigId2].links,
18358
- milestones: sceneDataRef2.current.milestones || []
18359
- };
18360
- await actions.save_view_data(sceneSaveUrl2, sceneFileData);
18361
- const questSaveUrl = sceneSaveUrl2.replace("x_view_scenes", "x_view_quests");
18362
- await actions.save_view_data(questSaveUrl, questFileData);
18363
- }
18347
+ await actions.save_view_data(sceneSaveUrl2, sceneFileData);
18348
+ await actions.save_quest(ownerId2, sceneConfigId2, newNode);
18364
18349
  sceneDataRef2.current.quest_counter = currentCounter + 1;
18365
18350
  stateRef2.current.nodeIdToParentFileMap.set(String(newNode.id), {
18366
18351
  parentFileId: sceneConfigId2,
@@ -18436,25 +18421,21 @@ function XViewScene({
18436
18421
  if (parentFileIdToSave === sceneConfigId2) {
18437
18422
  const specificParentData = graphDataRef2.current[sceneConfigId2];
18438
18423
  specificParentData.links.push(newLink);
18439
- if (context.actions.save_quest_link_action && (isSourceQuest || isTargetQuest)) {
18440
- await context.actions.save_quest_link_action(ownerId2, sceneConfigId2, newLink);
18441
- } else {
18442
- const viewFilePayload = {
18443
- ...sceneDataRef2.current,
18444
- quest_counter: sceneDataRef2.current.quest_counter || 1
18445
- };
18446
- const questFilePayload = {
18447
- nodes: specificParentData.nodes,
18448
- links: specificParentData.links,
18449
- milestones: sceneDataRef2.current.milestones || []
18450
- };
18451
- await context.actions.save_view_data(sceneSaveUrl2, viewFilePayload);
18452
- const questSaveUrl = sceneSaveUrl2.replace(
18453
- "x_view_scenes",
18454
- "x_view_quests"
18455
- );
18456
- await context.actions.save_view_data(questSaveUrl, questFilePayload);
18457
- }
18424
+ const viewFilePayload = {
18425
+ ...sceneDataRef2.current,
18426
+ quest_counter: sceneDataRef2.current.quest_counter || 1
18427
+ };
18428
+ const questFilePayload = {
18429
+ nodes: specificParentData.nodes,
18430
+ links: specificParentData.links,
18431
+ milestones: sceneDataRef2.current.milestones || []
18432
+ };
18433
+ await context.actions.save_view_data(sceneSaveUrl2, viewFilePayload);
18434
+ const questSaveUrl = sceneSaveUrl2.replace(
18435
+ "x_view_scenes",
18436
+ "x_view_quests"
18437
+ );
18438
+ await context.actions.save_view_data(questSaveUrl, questFilePayload);
18458
18439
  } else {
18459
18440
  const specificParentData = JSON.parse(
18460
18441
  JSON.stringify(graphDataRef2.current[parentFileIdToSave])
@@ -18487,7 +18468,9 @@ function XViewScene({
18487
18468
  if (line.material) line.material.dispose();
18488
18469
  });
18489
18470
  renderedAncestries.splice(renderIndex, 1);
18490
- stateRef.current.ancestryLinks = renderedAncestries.flatMap((a) => a.lines);
18471
+ stateRef.current.ancestryLinks = renderedAncestries.flatMap(
18472
+ (a) => a.lines
18473
+ );
18491
18474
  }
18492
18475
  }, []);
18493
18476
  const handleRenderAncestry = (0, import_react33.useCallback)(
@@ -19060,7 +19043,9 @@ function XViewScene({
19060
19043
  });
19061
19044
  };
19062
19045
  renderVertical(fullTree, rootNodeMesh, rootTargetPos, 1);
19063
- stateRef.current.ancestryLinks = renderedAncestries.flatMap((a) => a.lines);
19046
+ stateRef.current.ancestryLinks = renderedAncestries.flatMap(
19047
+ (a) => a.lines
19048
+ );
19064
19049
  tweenToTarget(rootTargetPos, 0.7);
19065
19050
  },
19066
19051
  [
@@ -19195,7 +19180,10 @@ function XViewScene({
19195
19180
  };
19196
19181
  const descriptionText = targetAncestryInfo.description || "";
19197
19182
  const savedSections = targetAncestryInfo.description_sections || [];
19198
- const sections = parseDescriptionSections(descriptionText, savedSections);
19183
+ const sections = parseDescriptionSections(
19184
+ descriptionText,
19185
+ savedSections
19186
+ );
19199
19187
  let focusTargetId = null;
19200
19188
  if (popped && popped.nodeId) {
19201
19189
  const mentionTag = `[[MENTION:node:${popped.nodeId}]]`;
@@ -19972,7 +19960,10 @@ function XViewScene({
19972
19960
  }
19973
19961
  if (ancestry_save_url && isExternalSave && get_ancestry_file) {
19974
19962
  try {
19975
- const viewDbResponse = await get_ancestry_file(sceneConfigId, ownerId);
19963
+ const viewDbResponse = await get_ancestry_file(
19964
+ sceneConfigId,
19965
+ ownerId
19966
+ );
19976
19967
  if (viewDbResponse.success && Array.isArray(viewDbResponse.data)) {
19977
19968
  const hasInViewDb = viewDbResponse.data.some(
19978
19969
  (anc) => String(anc.ancestry_id) === String(ancestryIdToDelete)
@@ -20162,58 +20153,33 @@ function XViewScene({
20162
20153
  async (newMilestones) => {
20163
20154
  var _a2, _b2, _c2;
20164
20155
  if (!sceneDataRef.current) return;
20165
- const oldMilestones = sceneDataRef.current.milestones || [];
20166
- const removedMilestones = oldMilestones.filter(
20167
- (oldM) => !newMilestones.some((newM) => String(newM.id) === String(oldM.id))
20168
- );
20169
- const addedOrUpdatedMilestones = newMilestones.filter(
20170
- (newM) => !oldMilestones.some((oldM) => JSON.stringify(oldM) === JSON.stringify(newM))
20171
- );
20172
20156
  sceneDataRef.current.milestones = newMilestones;
20173
20157
  setSceneVersion((v) => v + 1);
20174
20158
  const isView = ((_a2 = viewParams == null ? void 0 : viewParams.type) == null ? void 0 : _a2.toLowerCase()) === "view";
20175
20159
  if (!isView || !save_view_data || !sceneSaveUrl) return;
20160
+ const sceneFileData = {
20161
+ ...sceneDataRef.current,
20162
+ nodes: sceneDataRef.current.nodes || [],
20163
+ links: sceneDataRef.current.links || [],
20164
+ quest_counter: sceneDataRef.current.quest_counter || 1
20165
+ };
20166
+ const questFileData = {
20167
+ nodes: ((_b2 = parentDataRef.current[sceneConfigId]) == null ? void 0 : _b2.nodes) || sceneDataRef.current.quest_nodes || [],
20168
+ links: ((_c2 = parentDataRef.current[sceneConfigId]) == null ? void 0 : _c2.links) || sceneDataRef.current.quest_links || [],
20169
+ milestones: newMilestones
20170
+ };
20176
20171
  try {
20177
- if (save_milestone_action) {
20178
- const promises = [];
20179
- if (delete_milestone_action) {
20180
- removedMilestones.forEach((m) => promises.push(delete_milestone_action(ownerId, sceneConfigId, m.id)));
20181
- }
20182
- if (addedOrUpdatedMilestones.length > 0) {
20183
- addedOrUpdatedMilestones.forEach((m) => promises.push(save_milestone_action(ownerId, sceneConfigId, m)));
20184
- }
20185
- await Promise.all(promises);
20186
- const sceneFileData = {
20187
- ...sceneDataRef.current,
20188
- nodes: sceneDataRef.current.nodes || [],
20189
- links: sceneDataRef.current.links || [],
20190
- quest_counter: sceneDataRef.current.quest_counter || 1
20191
- };
20192
- await save_view_data(sceneSaveUrl, sceneFileData);
20193
- } else {
20194
- const sceneFileData = {
20195
- ...sceneDataRef.current,
20196
- nodes: sceneDataRef.current.nodes || [],
20197
- links: sceneDataRef.current.links || [],
20198
- quest_counter: sceneDataRef.current.quest_counter || 1
20199
- };
20200
- const questFileData = {
20201
- nodes: ((_b2 = parentDataRef.current[sceneConfigId]) == null ? void 0 : _b2.nodes) || sceneDataRef.current.quest_nodes || [],
20202
- links: ((_c2 = parentDataRef.current[sceneConfigId]) == null ? void 0 : _c2.links) || sceneDataRef.current.quest_links || [],
20203
- milestones: newMilestones
20204
- };
20205
- await save_view_data(sceneSaveUrl, sceneFileData);
20206
- const questSaveUrl = sceneSaveUrl.replace(
20207
- "x_view_scenes",
20208
- "x_view_quests"
20209
- );
20210
- await save_view_data(questSaveUrl, questFileData);
20211
- }
20172
+ await save_view_data(sceneSaveUrl, sceneFileData);
20173
+ const questSaveUrl = sceneSaveUrl.replace(
20174
+ "x_view_scenes",
20175
+ "x_view_quests"
20176
+ );
20177
+ await save_view_data(questSaveUrl, questFileData);
20212
20178
  } catch (error) {
20213
20179
  console.error("Erro ao salvar milestones:", error);
20214
20180
  }
20215
20181
  },
20216
- [sceneConfigId, sceneSaveUrl, save_view_data, save_milestone_action, delete_milestone_action, viewParams == null ? void 0 : viewParams.type]
20182
+ [sceneConfigId, sceneSaveUrl, save_view_data, viewParams == null ? void 0 : viewParams.type]
20217
20183
  );
20218
20184
  const handleSaveCurrentView = (0, import_react33.useCallback)(async () => {
20219
20185
  var _a2, _b2, _c2;
@@ -20961,12 +20927,18 @@ function XViewScene({
20961
20927
  data: multiContextMenu,
20962
20928
  userRole: userPermissionRole,
20963
20929
  onClose: () => setMultiContextMenu((prev) => ({ ...prev, visible: false })),
20964
- onDismissNodes: (ids) => userActionHandlers.handleDismissMultipleNodes(actionHandlerContext, ids),
20930
+ onDismissNodes: (ids) => userActionHandlers.handleDismissMultipleNodes(
20931
+ actionHandlerContext,
20932
+ ids
20933
+ ),
20965
20934
  onDismissOtherNodes: (ids) => userActionHandlers.handleDismissOtherMultipleNodes(
20966
20935
  actionHandlerContext,
20967
20936
  ids
20968
20937
  ),
20969
- onDeleteNodes: (ids) => userActionHandlers.handleDeleteMultipleNodes(actionHandlerContext, ids)
20938
+ onDeleteNodes: (ids) => userActionHandlers.handleDeleteMultipleNodes(
20939
+ actionHandlerContext,
20940
+ ids
20941
+ )
20970
20942
  }
20971
20943
  ),
20972
20944
  /* @__PURE__ */ import_react33.default.createElement(
@@ -21148,7 +21120,29 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21148
21120
  );
21149
21121
  const parentResponsesResults = await Promise.allSettled(parentResponsesPromises);
21150
21122
  const parentData = {};
21151
- let questDataObj = null;
21123
+ let currentQuestNodes = [];
21124
+ let currentQuestLinks = [];
21125
+ let currentMilestones = [];
21126
+ if (isView) {
21127
+ const firestoreQuestsRes = await db_services.get_view_quests_and_links(owner_id, scene_config);
21128
+ const isMigrated = sceneData.quests_migrated === true;
21129
+ if (firestoreQuestsRes.success && (firestoreQuestsRes.data.nodes.length > 0 || isMigrated)) {
21130
+ currentQuestNodes = firestoreQuestsRes.data.nodes;
21131
+ currentQuestLinks = firestoreQuestsRes.data.links;
21132
+ currentMilestones = sceneData.milestones || [];
21133
+ } else {
21134
+ console.log(`Iniciando Lazy Migration para View ${scene_config}...`);
21135
+ const legacyQuestsRes = await db_services.get_file(`x_view_quests/${owner_id}/${scene_config}`);
21136
+ if (legacyQuestsRes.success && legacyQuestsRes.data) {
21137
+ const legacyData = legacyQuestsRes.data;
21138
+ currentQuestNodes = legacyData.nodes || [];
21139
+ currentQuestLinks = legacyData.links || [];
21140
+ currentMilestones = legacyData.milestones || [];
21141
+ sceneData.milestones = currentMilestones;
21142
+ await db_services.migrate_legacy_quests(owner_id, scene_config, legacyData);
21143
+ }
21144
+ }
21145
+ }
21152
21146
  for (let i = 0; i < parentResponsesResults.length; i++) {
21153
21147
  const result = parentResponsesResults[i];
21154
21148
  const db_info = parentDbObjects[i];
@@ -21161,22 +21155,6 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21161
21155
  );
21162
21156
  }
21163
21157
  }
21164
- if (isView) {
21165
- if (db_services.get_x_view_quests_data) {
21166
- const questDataRes = await db_services.get_x_view_quests_data(session, owner_id, scene_config);
21167
- if (questDataRes && questDataRes.success) {
21168
- questDataObj = questDataRes.data;
21169
- }
21170
- } else {
21171
- const questDataRes = await db_services.get_file(`x_view_quests/${owner_id}/${scene_config}`);
21172
- if (questDataRes && questDataRes.success) {
21173
- questDataObj = questDataRes.data;
21174
- }
21175
- }
21176
- }
21177
- const currentQuestNodes = (questDataObj == null ? void 0 : questDataObj.nodes) || [];
21178
- const currentQuestLinks = (questDataObj == null ? void 0 : questDataObj.links) || [];
21179
- const currentMilestones = (questDataObj == null ? void 0 : questDataObj.milestones) || [];
21180
21158
  if (isView) {
21181
21159
  parentData[scene_config] = {
21182
21160
  dataset_name: "Quests Internas (View)",
package/dist/index.mjs CHANGED
@@ -1506,17 +1506,11 @@ var userActionHandlers = {
1506
1506
  links: sceneDataRef.current.links,
1507
1507
  quest_counter: sceneDataRef.current.quest_counter || 1
1508
1508
  };
1509
- const questFilePayload = {
1510
- nodes: specificParentData.nodes,
1511
- links: specificParentData.links,
1512
- milestones: sceneDataRef.current.milestones || []
1513
- };
1514
1509
  await context.actions.save_view_data(
1515
1510
  context.sceneSaveUrl,
1516
1511
  viewFilePayload
1517
1512
  );
1518
- const questSaveUrl = context.sceneSaveUrl.replace("x_view_scenes", "x_view_quests");
1519
- await context.actions.save_view_data(questSaveUrl, questFilePayload);
1513
+ await context.actions.save_quest_link(context.ownerId, context.sceneConfigId, newLink);
1520
1514
  } else {
1521
1515
  const specificParentData = JSON.parse(
1522
1516
  JSON.stringify(graphDataRef.current[parentFileIdToSave])
@@ -1803,20 +1797,14 @@ var userActionHandlers = {
1803
1797
  links: sceneDataRef.current.links,
1804
1798
  quest_counter: sceneDataRef.current.quest_counter || 1
1805
1799
  };
1806
- questSaveUrl = context.sceneSaveUrl.replace("x_view_scenes", "x_view_quests");
1807
- questFilePayload = {
1808
- nodes: specificParentData.nodes,
1809
- links: specificParentData.links,
1810
- milestones: sceneDataRef.current.milestones || []
1811
- };
1812
1800
  } else {
1813
1801
  filenameToSave = `x_view_dbs/${ownerId}/${parentFileId}`;
1814
1802
  payloadToSave = specificParentData;
1815
1803
  }
1816
1804
  try {
1817
1805
  await context.actions.save_view_data(filenameToSave, payloadToSave);
1818
- if (questSaveUrl && questFilePayload) {
1819
- await context.actions.save_view_data(questSaveUrl, questFilePayload);
1806
+ if (isView && parentFileId === context.sceneConfigId && context.actions.delete_quest_link) {
1807
+ await context.actions.delete_quest_link(ownerId, context.sceneConfigId, linkIdToDelete);
1820
1808
  }
1821
1809
  graphDataRef.current[parentFileId] = specificParentData;
1822
1810
  setters.setDetailsLink(
@@ -2048,13 +2036,15 @@ var userActionHandlers = {
2048
2036
  links: sceneDataRef.current.links,
2049
2037
  quest_counter: sceneDataRef.current.quest_counter || 1
2050
2038
  };
2051
- const questFilePayload = {
2052
- nodes: originalData.nodes,
2053
- links: originalData.links,
2054
- milestones: sceneDataRef.current.milestones || []
2055
- };
2056
- const questSaveUrl = context.sceneSaveUrl.replace("x_view_scenes", "x_view_quests");
2057
- savePromises.push(context.actions.save_view_data(questSaveUrl, questFilePayload));
2039
+ for (const nodeId of nodesToDelete) {
2040
+ const questNode = (originalData.nodes || []).find((n) => String(n.id) === String(nodeId));
2041
+ if (questNode && questNode.is_quest) {
2042
+ await context.actions.delete_quest(ownerId, context.sceneConfigId, nodeId);
2043
+ }
2044
+ }
2045
+ for (const linkId of linksToDelete) {
2046
+ await context.actions.delete_quest_link(ownerId, context.sceneConfigId, linkId);
2047
+ }
2058
2048
  } else {
2059
2049
  filenameToSave = `x_view_dbs/${ownerId}/${parentFileId}`;
2060
2050
  payloadToSave = originalData;
@@ -2146,15 +2136,9 @@ var userActionHandlers = {
2146
2136
  links: newVisualLinks,
2147
2137
  quest_counter: sceneDataRef.current.quest_counter || 1
2148
2138
  };
2149
- const questFilePayload = {
2150
- nodes: specificParentData.nodes,
2151
- links: specificParentData.links,
2152
- milestones: sceneDataRef.current.milestones || []
2153
- };
2154
- const questSaveUrl = context.sceneSaveUrl.replace("x_view_scenes", "x_view_quests");
2155
2139
  try {
2156
2140
  await context.actions.save_view_data(filenameToSave, payloadToSave);
2157
- await context.actions.save_view_data(questSaveUrl, questFilePayload);
2141
+ await context.actions.delete_quest(ownerId, context.sceneConfigId, nodeIdToDelete);
2158
2142
  graphDataRef.current[parentFileId] = specificParentData;
2159
2143
  setters.setDetailsNode(
2160
2144
  (prev) => String(prev == null ? void 0 : prev.id) === String(nodeIdToDelete) ? null : prev
@@ -2184,7 +2168,7 @@ var userActionHandlers = {
2184
2168
  }
2185
2169
  },
2186
2170
  handleSaveNodeDetails: async (context, updatedNode, keepOpen = false) => {
2187
- var _a, _b, _c, _d;
2171
+ var _a, _b, _c;
2188
2172
  const { graphDataRef, sceneDataRef, stateRef, setters } = context;
2189
2173
  if (!graphDataRef.current || !sceneDataRef.current) return;
2190
2174
  const {
@@ -2311,40 +2295,17 @@ var userActionHandlers = {
2311
2295
  ...nodeToSave
2312
2296
  };
2313
2297
  }
2314
- if (nodeToSave.is_quest && context.actions.save_quest_action) {
2315
- await context.actions.save_quest_action(context.ownerId, context.sceneConfigId, nodeToSave, sceneDataRef.current.quest_counter);
2316
- if (isNewDone && ((_d = nodeToSave.recurrence_config) == null ? void 0 : _d.enabled)) {
2317
- const createdRecurrenceQuest = specificParentData.nodes[specificParentData.nodes.length - 1];
2318
- if (createdRecurrenceQuest && String(createdRecurrenceQuest.id) !== String(nodeToSave.id)) {
2319
- await context.actions.save_quest_action(context.ownerId, context.sceneConfigId, createdRecurrenceQuest, sceneDataRef.current.quest_counter);
2320
- }
2321
- }
2322
- const viewFilePayload = {
2323
- parent_dbs: sceneDataRef.current.parent_dbs,
2324
- nodes: sceneDataRef.current.nodes,
2325
- links: sceneDataRef.current.links,
2326
- quest_counter: sceneDataRef.current.quest_counter || 1
2327
- };
2328
- await context.actions.save_view_data(context.sceneSaveUrl, viewFilePayload);
2329
- } else {
2330
- const viewFilePayload = {
2331
- parent_dbs: sceneDataRef.current.parent_dbs,
2332
- nodes: sceneDataRef.current.nodes,
2333
- links: sceneDataRef.current.links,
2334
- quest_counter: sceneDataRef.current.quest_counter || 1
2335
- };
2336
- const questFilePayload = {
2337
- nodes: specificParentData.nodes,
2338
- links: specificParentData.links,
2339
- milestones: sceneDataRef.current.milestones || []
2340
- };
2341
- await context.actions.save_view_data(
2342
- context.sceneSaveUrl,
2343
- viewFilePayload
2344
- );
2345
- const questSaveUrl = context.sceneSaveUrl.replace("x_view_scenes", "x_view_quests");
2346
- await context.actions.save_view_data(questSaveUrl, questFilePayload);
2347
- }
2298
+ const viewFilePayload = {
2299
+ parent_dbs: sceneDataRef.current.parent_dbs,
2300
+ nodes: sceneDataRef.current.nodes,
2301
+ links: sceneDataRef.current.links,
2302
+ quest_counter: sceneDataRef.current.quest_counter || 1
2303
+ };
2304
+ await context.actions.save_view_data(
2305
+ context.sceneSaveUrl,
2306
+ viewFilePayload
2307
+ );
2308
+ await context.actions.save_quest(ownerId, context.sceneConfigId, nodeToSave);
2348
2309
  } else {
2349
2310
  const filenameForSpecificParent = `x_view_dbs/${ownerId}/${parentFileId}`;
2350
2311
  await context.actions.save_view_data(
@@ -15558,13 +15519,12 @@ function XViewScene({
15558
15519
  get_view_members,
15559
15520
  create_google_doc_action,
15560
15521
  open_google_picker_action,
15561
- // Firestore Atomic Actions (Quests & Milestones)
15562
15522
  save_quest_action,
15563
15523
  delete_quest_action,
15564
15524
  save_quest_link_action,
15565
15525
  delete_quest_link_action,
15566
- save_milestone_action,
15567
- delete_milestone_action
15526
+ get_view_quests_and_links_action,
15527
+ migrate_legacy_quests_action
15568
15528
  }) {
15569
15529
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
15570
15530
  const { data: session, status } = useSession();
@@ -16428,11 +16388,32 @@ function XViewScene({
16428
16388
  focusAncestryId
16429
16389
  );
16430
16390
  const boardPromise = get_boards_action && session ? get_boards_action(configPath, sceneType, session, ownerId2) : Promise.resolve({ success: false, data: [] });
16431
- const [sceneResponse, boardResponse] = await Promise.all([
16391
+ const questPromise = get_view_quests_and_links_action && session ? get_view_quests_and_links_action(ownerId2, sceneConfigId) : Promise.resolve({ success: false, quests: [], links: [] });
16392
+ const [sceneResponse, boardResponse, questResponse] = await Promise.all([
16432
16393
  scenePromise,
16433
- boardPromise
16394
+ boardPromise,
16395
+ questPromise
16434
16396
  ]);
16435
16397
  if ((sceneResponse == null ? void 0 : sceneResponse.success) && ((_a2 = sceneResponse.data) == null ? void 0 : _a2.scene) && ((_b2 = sceneResponse.data) == null ? void 0 : _b2.parent)) {
16398
+ const sceneData = sceneResponse.data.scene;
16399
+ let firestoreQuests = (questResponse == null ? void 0 : questResponse.success) ? questResponse.quests : [];
16400
+ let firestoreLinks = (questResponse == null ? void 0 : questResponse.success) ? questResponse.links : [];
16401
+ if (!sceneData.quests_migrated && firestoreQuests.length === 0) {
16402
+ const legacyQuests = sceneData.quest_nodes || [];
16403
+ const legacyLinks = sceneData.quest_links || [];
16404
+ if ((legacyQuests.length > 0 || legacyLinks.length > 0) && migrate_legacy_quests_action) {
16405
+ console.log(
16406
+ "X-View: Iniciando Lazy Migration de Quests para Firestore..."
16407
+ );
16408
+ await migrate_legacy_quests_action(ownerId2, sceneConfigId, {
16409
+ nodes: legacyQuests,
16410
+ links: legacyLinks
16411
+ });
16412
+ firestoreQuests = legacyQuests;
16413
+ firestoreLinks = legacyLinks;
16414
+ sceneData.quests_migrated = true;
16415
+ }
16416
+ }
16436
16417
  if (focusNodeId) {
16437
16418
  let targetNode = sceneResponse.data.scene.nodes.find(
16438
16419
  (n) => String(n.id) === String(focusNodeId)
@@ -16454,10 +16435,29 @@ function XViewScene({
16454
16435
  sceneResponse.data.scene.links = [];
16455
16436
  }
16456
16437
  sceneDataRef.current = {
16457
- ...sceneResponse.data.scene,
16458
- milestones: sceneResponse.data.scene.milestones || []
16438
+ ...sceneData,
16439
+ quests_migrated: sceneData.quests_migrated || false,
16440
+ milestones: sceneData.milestones || []
16459
16441
  };
16460
- parentDataRef.current = sceneResponse.data.parent;
16442
+ const currentParentData = sceneResponse.data.parent;
16443
+ if (currentParentData && currentParentData[sceneConfigId]) {
16444
+ const existingNodes = currentParentData[sceneConfigId].nodes || [];
16445
+ const firestoreQuestIds = new Set(firestoreQuests.map((q) => String(q.id)));
16446
+ const filteredExisting = existingNodes.filter(
16447
+ (n) => !firestoreQuestIds.has(String(n.id))
16448
+ );
16449
+ currentParentData[sceneConfigId].nodes = [
16450
+ ...filteredExisting,
16451
+ ...firestoreQuests
16452
+ ];
16453
+ if (firestoreLinks && firestoreLinks.length > 0) {
16454
+ currentParentData[sceneConfigId].links = [
16455
+ ...currentParentData[sceneConfigId].links || [],
16456
+ ...firestoreLinks
16457
+ ];
16458
+ }
16459
+ }
16460
+ parentDataRef.current = currentParentData;
16461
16461
  ancestryDataRef.current = sceneResponse.data.ancestry;
16462
16462
  console.log(
16463
16463
  "Console de sceneResponse.data.scene:",
@@ -18072,12 +18072,12 @@ function XViewScene({
18072
18072
  get_scene_view_data,
18073
18073
  upload_file: upload_file_action,
18074
18074
  delete_file: delete_file_action,
18075
- save_quest_action,
18076
- delete_quest_action,
18077
- save_quest_link_action,
18078
- delete_quest_link_action,
18079
- save_milestone_action,
18080
- delete_milestone_action
18075
+ save_quest: save_quest_action,
18076
+ delete_quest: delete_quest_action,
18077
+ save_quest_link: save_quest_link_action,
18078
+ delete_quest_link: delete_quest_link_action,
18079
+ get_view_quests_and_links: get_view_quests_and_links_action,
18080
+ migrate_legacy_quests: migrate_legacy_quests_action
18081
18081
  }
18082
18082
  };
18083
18083
  },
@@ -18101,8 +18101,8 @@ function XViewScene({
18101
18101
  delete_quest_action,
18102
18102
  save_quest_link_action,
18103
18103
  delete_quest_link_action,
18104
- save_milestone_action,
18105
- delete_milestone_action
18104
+ get_view_quests_and_links_action,
18105
+ migrate_legacy_quests_action
18106
18106
  ]
18107
18107
  );
18108
18108
  const handleStartVersioning = (nodeData) => {
@@ -18308,28 +18308,19 @@ function XViewScene({
18308
18308
  parentDataRef.current[sceneConfigId].nodes[parentIndex].quest_abstraction_tree = formattedAbstractionTree;
18309
18309
  }
18310
18310
  }
18311
- if (save_quest_action) {
18312
- const updatedNodeData2 = sceneData.quest_nodes[questIndex];
18313
- await save_quest_action(ownerId, sceneConfigId, updatedNodeData2, sceneData.quest_counter || 1);
18314
- } else {
18315
- const sceneFileData = {
18316
- ...sceneData,
18317
- nodes: sceneData.nodes || [],
18318
- links: sceneData.links || [],
18319
- quest_counter: sceneData.quest_counter || 1
18320
- };
18321
- const questFileData = {
18322
- nodes: sceneData.quest_nodes || [],
18323
- links: sceneData.quest_links || [],
18324
- milestones: sceneData.milestones || []
18325
- };
18326
- await save_view_data(sceneSaveUrl, sceneFileData);
18327
- const questSaveUrl = sceneSaveUrl.replace(
18328
- "x_view_scenes",
18329
- "x_view_quests"
18330
- );
18331
- await save_view_data(questSaveUrl, questFileData);
18332
- }
18311
+ const sceneFileData = {
18312
+ ...sceneData,
18313
+ nodes: sceneData.nodes || [],
18314
+ links: sceneData.links || [],
18315
+ quest_counter: sceneData.quest_counter || 1
18316
+ };
18317
+ const questFileData = {
18318
+ nodes: sceneData.quest_nodes || [],
18319
+ links: sceneData.quest_links || [],
18320
+ milestones: sceneData.milestones || []
18321
+ };
18322
+ await save_view_data(sceneSaveUrl, sceneFileData);
18323
+ await save_quest_action(ownerId, sceneConfigId, updatedNodeData);
18333
18324
  }
18334
18325
  const updatedNodeData = sceneData.quest_nodes[questIndex];
18335
18326
  const nodeMesh = (_a2 = stateRef.current.nodeObjects) == null ? void 0 : _a2[String(questNodeId)];
@@ -18410,20 +18401,14 @@ function XViewScene({
18410
18401
  ...sceneDataRef2.current,
18411
18402
  quest_counter: currentCounter + 1
18412
18403
  };
18404
+ const questFileData = {
18405
+ nodes: graphDataRef2.current[sceneConfigId2].nodes,
18406
+ links: graphDataRef2.current[sceneConfigId2].links,
18407
+ milestones: sceneDataRef2.current.milestones || []
18408
+ };
18413
18409
  try {
18414
- if (actions.save_quest_action) {
18415
- await actions.save_quest_action(ownerId2, sceneConfigId2, newNode, currentCounter + 1);
18416
- await actions.save_view_data(sceneSaveUrl2, sceneFileData);
18417
- } else {
18418
- const questFileData = {
18419
- nodes: graphDataRef2.current[sceneConfigId2].nodes,
18420
- links: graphDataRef2.current[sceneConfigId2].links,
18421
- milestones: sceneDataRef2.current.milestones || []
18422
- };
18423
- await actions.save_view_data(sceneSaveUrl2, sceneFileData);
18424
- const questSaveUrl = sceneSaveUrl2.replace("x_view_scenes", "x_view_quests");
18425
- await actions.save_view_data(questSaveUrl, questFileData);
18426
- }
18410
+ await actions.save_view_data(sceneSaveUrl2, sceneFileData);
18411
+ await actions.save_quest(ownerId2, sceneConfigId2, newNode);
18427
18412
  sceneDataRef2.current.quest_counter = currentCounter + 1;
18428
18413
  stateRef2.current.nodeIdToParentFileMap.set(String(newNode.id), {
18429
18414
  parentFileId: sceneConfigId2,
@@ -18499,25 +18484,21 @@ function XViewScene({
18499
18484
  if (parentFileIdToSave === sceneConfigId2) {
18500
18485
  const specificParentData = graphDataRef2.current[sceneConfigId2];
18501
18486
  specificParentData.links.push(newLink);
18502
- if (context.actions.save_quest_link_action && (isSourceQuest || isTargetQuest)) {
18503
- await context.actions.save_quest_link_action(ownerId2, sceneConfigId2, newLink);
18504
- } else {
18505
- const viewFilePayload = {
18506
- ...sceneDataRef2.current,
18507
- quest_counter: sceneDataRef2.current.quest_counter || 1
18508
- };
18509
- const questFilePayload = {
18510
- nodes: specificParentData.nodes,
18511
- links: specificParentData.links,
18512
- milestones: sceneDataRef2.current.milestones || []
18513
- };
18514
- await context.actions.save_view_data(sceneSaveUrl2, viewFilePayload);
18515
- const questSaveUrl = sceneSaveUrl2.replace(
18516
- "x_view_scenes",
18517
- "x_view_quests"
18518
- );
18519
- await context.actions.save_view_data(questSaveUrl, questFilePayload);
18520
- }
18487
+ const viewFilePayload = {
18488
+ ...sceneDataRef2.current,
18489
+ quest_counter: sceneDataRef2.current.quest_counter || 1
18490
+ };
18491
+ const questFilePayload = {
18492
+ nodes: specificParentData.nodes,
18493
+ links: specificParentData.links,
18494
+ milestones: sceneDataRef2.current.milestones || []
18495
+ };
18496
+ await context.actions.save_view_data(sceneSaveUrl2, viewFilePayload);
18497
+ const questSaveUrl = sceneSaveUrl2.replace(
18498
+ "x_view_scenes",
18499
+ "x_view_quests"
18500
+ );
18501
+ await context.actions.save_view_data(questSaveUrl, questFilePayload);
18521
18502
  } else {
18522
18503
  const specificParentData = JSON.parse(
18523
18504
  JSON.stringify(graphDataRef2.current[parentFileIdToSave])
@@ -18550,7 +18531,9 @@ function XViewScene({
18550
18531
  if (line.material) line.material.dispose();
18551
18532
  });
18552
18533
  renderedAncestries.splice(renderIndex, 1);
18553
- stateRef.current.ancestryLinks = renderedAncestries.flatMap((a) => a.lines);
18534
+ stateRef.current.ancestryLinks = renderedAncestries.flatMap(
18535
+ (a) => a.lines
18536
+ );
18554
18537
  }
18555
18538
  }, []);
18556
18539
  const handleRenderAncestry = useCallback7(
@@ -19123,7 +19106,9 @@ function XViewScene({
19123
19106
  });
19124
19107
  };
19125
19108
  renderVertical(fullTree, rootNodeMesh, rootTargetPos, 1);
19126
- stateRef.current.ancestryLinks = renderedAncestries.flatMap((a) => a.lines);
19109
+ stateRef.current.ancestryLinks = renderedAncestries.flatMap(
19110
+ (a) => a.lines
19111
+ );
19127
19112
  tweenToTarget(rootTargetPos, 0.7);
19128
19113
  },
19129
19114
  [
@@ -19258,7 +19243,10 @@ function XViewScene({
19258
19243
  };
19259
19244
  const descriptionText = targetAncestryInfo.description || "";
19260
19245
  const savedSections = targetAncestryInfo.description_sections || [];
19261
- const sections = parseDescriptionSections(descriptionText, savedSections);
19246
+ const sections = parseDescriptionSections(
19247
+ descriptionText,
19248
+ savedSections
19249
+ );
19262
19250
  let focusTargetId = null;
19263
19251
  if (popped && popped.nodeId) {
19264
19252
  const mentionTag = `[[MENTION:node:${popped.nodeId}]]`;
@@ -20035,7 +20023,10 @@ function XViewScene({
20035
20023
  }
20036
20024
  if (ancestry_save_url && isExternalSave && get_ancestry_file) {
20037
20025
  try {
20038
- const viewDbResponse = await get_ancestry_file(sceneConfigId, ownerId);
20026
+ const viewDbResponse = await get_ancestry_file(
20027
+ sceneConfigId,
20028
+ ownerId
20029
+ );
20039
20030
  if (viewDbResponse.success && Array.isArray(viewDbResponse.data)) {
20040
20031
  const hasInViewDb = viewDbResponse.data.some(
20041
20032
  (anc) => String(anc.ancestry_id) === String(ancestryIdToDelete)
@@ -20225,58 +20216,33 @@ function XViewScene({
20225
20216
  async (newMilestones) => {
20226
20217
  var _a2, _b2, _c2;
20227
20218
  if (!sceneDataRef.current) return;
20228
- const oldMilestones = sceneDataRef.current.milestones || [];
20229
- const removedMilestones = oldMilestones.filter(
20230
- (oldM) => !newMilestones.some((newM) => String(newM.id) === String(oldM.id))
20231
- );
20232
- const addedOrUpdatedMilestones = newMilestones.filter(
20233
- (newM) => !oldMilestones.some((oldM) => JSON.stringify(oldM) === JSON.stringify(newM))
20234
- );
20235
20219
  sceneDataRef.current.milestones = newMilestones;
20236
20220
  setSceneVersion((v) => v + 1);
20237
20221
  const isView = ((_a2 = viewParams == null ? void 0 : viewParams.type) == null ? void 0 : _a2.toLowerCase()) === "view";
20238
20222
  if (!isView || !save_view_data || !sceneSaveUrl) return;
20223
+ const sceneFileData = {
20224
+ ...sceneDataRef.current,
20225
+ nodes: sceneDataRef.current.nodes || [],
20226
+ links: sceneDataRef.current.links || [],
20227
+ quest_counter: sceneDataRef.current.quest_counter || 1
20228
+ };
20229
+ const questFileData = {
20230
+ nodes: ((_b2 = parentDataRef.current[sceneConfigId]) == null ? void 0 : _b2.nodes) || sceneDataRef.current.quest_nodes || [],
20231
+ links: ((_c2 = parentDataRef.current[sceneConfigId]) == null ? void 0 : _c2.links) || sceneDataRef.current.quest_links || [],
20232
+ milestones: newMilestones
20233
+ };
20239
20234
  try {
20240
- if (save_milestone_action) {
20241
- const promises = [];
20242
- if (delete_milestone_action) {
20243
- removedMilestones.forEach((m) => promises.push(delete_milestone_action(ownerId, sceneConfigId, m.id)));
20244
- }
20245
- if (addedOrUpdatedMilestones.length > 0) {
20246
- addedOrUpdatedMilestones.forEach((m) => promises.push(save_milestone_action(ownerId, sceneConfigId, m)));
20247
- }
20248
- await Promise.all(promises);
20249
- const sceneFileData = {
20250
- ...sceneDataRef.current,
20251
- nodes: sceneDataRef.current.nodes || [],
20252
- links: sceneDataRef.current.links || [],
20253
- quest_counter: sceneDataRef.current.quest_counter || 1
20254
- };
20255
- await save_view_data(sceneSaveUrl, sceneFileData);
20256
- } else {
20257
- const sceneFileData = {
20258
- ...sceneDataRef.current,
20259
- nodes: sceneDataRef.current.nodes || [],
20260
- links: sceneDataRef.current.links || [],
20261
- quest_counter: sceneDataRef.current.quest_counter || 1
20262
- };
20263
- const questFileData = {
20264
- nodes: ((_b2 = parentDataRef.current[sceneConfigId]) == null ? void 0 : _b2.nodes) || sceneDataRef.current.quest_nodes || [],
20265
- links: ((_c2 = parentDataRef.current[sceneConfigId]) == null ? void 0 : _c2.links) || sceneDataRef.current.quest_links || [],
20266
- milestones: newMilestones
20267
- };
20268
- await save_view_data(sceneSaveUrl, sceneFileData);
20269
- const questSaveUrl = sceneSaveUrl.replace(
20270
- "x_view_scenes",
20271
- "x_view_quests"
20272
- );
20273
- await save_view_data(questSaveUrl, questFileData);
20274
- }
20235
+ await save_view_data(sceneSaveUrl, sceneFileData);
20236
+ const questSaveUrl = sceneSaveUrl.replace(
20237
+ "x_view_scenes",
20238
+ "x_view_quests"
20239
+ );
20240
+ await save_view_data(questSaveUrl, questFileData);
20275
20241
  } catch (error) {
20276
20242
  console.error("Erro ao salvar milestones:", error);
20277
20243
  }
20278
20244
  },
20279
- [sceneConfigId, sceneSaveUrl, save_view_data, save_milestone_action, delete_milestone_action, viewParams == null ? void 0 : viewParams.type]
20245
+ [sceneConfigId, sceneSaveUrl, save_view_data, viewParams == null ? void 0 : viewParams.type]
20280
20246
  );
20281
20247
  const handleSaveCurrentView = useCallback7(async () => {
20282
20248
  var _a2, _b2, _c2;
@@ -21024,12 +20990,18 @@ function XViewScene({
21024
20990
  data: multiContextMenu,
21025
20991
  userRole: userPermissionRole,
21026
20992
  onClose: () => setMultiContextMenu((prev) => ({ ...prev, visible: false })),
21027
- onDismissNodes: (ids) => userActionHandlers.handleDismissMultipleNodes(actionHandlerContext, ids),
20993
+ onDismissNodes: (ids) => userActionHandlers.handleDismissMultipleNodes(
20994
+ actionHandlerContext,
20995
+ ids
20996
+ ),
21028
20997
  onDismissOtherNodes: (ids) => userActionHandlers.handleDismissOtherMultipleNodes(
21029
20998
  actionHandlerContext,
21030
20999
  ids
21031
21000
  ),
21032
- onDeleteNodes: (ids) => userActionHandlers.handleDeleteMultipleNodes(actionHandlerContext, ids)
21001
+ onDeleteNodes: (ids) => userActionHandlers.handleDeleteMultipleNodes(
21002
+ actionHandlerContext,
21003
+ ids
21004
+ )
21033
21005
  }
21034
21006
  ),
21035
21007
  /* @__PURE__ */ React32.createElement(
@@ -21211,7 +21183,29 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21211
21183
  );
21212
21184
  const parentResponsesResults = await Promise.allSettled(parentResponsesPromises);
21213
21185
  const parentData = {};
21214
- let questDataObj = null;
21186
+ let currentQuestNodes = [];
21187
+ let currentQuestLinks = [];
21188
+ let currentMilestones = [];
21189
+ if (isView) {
21190
+ const firestoreQuestsRes = await db_services.get_view_quests_and_links(owner_id, scene_config);
21191
+ const isMigrated = sceneData.quests_migrated === true;
21192
+ if (firestoreQuestsRes.success && (firestoreQuestsRes.data.nodes.length > 0 || isMigrated)) {
21193
+ currentQuestNodes = firestoreQuestsRes.data.nodes;
21194
+ currentQuestLinks = firestoreQuestsRes.data.links;
21195
+ currentMilestones = sceneData.milestones || [];
21196
+ } else {
21197
+ console.log(`Iniciando Lazy Migration para View ${scene_config}...`);
21198
+ const legacyQuestsRes = await db_services.get_file(`x_view_quests/${owner_id}/${scene_config}`);
21199
+ if (legacyQuestsRes.success && legacyQuestsRes.data) {
21200
+ const legacyData = legacyQuestsRes.data;
21201
+ currentQuestNodes = legacyData.nodes || [];
21202
+ currentQuestLinks = legacyData.links || [];
21203
+ currentMilestones = legacyData.milestones || [];
21204
+ sceneData.milestones = currentMilestones;
21205
+ await db_services.migrate_legacy_quests(owner_id, scene_config, legacyData);
21206
+ }
21207
+ }
21208
+ }
21215
21209
  for (let i = 0; i < parentResponsesResults.length; i++) {
21216
21210
  const result = parentResponsesResults[i];
21217
21211
  const db_info = parentDbObjects[i];
@@ -21224,22 +21218,6 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21224
21218
  );
21225
21219
  }
21226
21220
  }
21227
- if (isView) {
21228
- if (db_services.get_x_view_quests_data) {
21229
- const questDataRes = await db_services.get_x_view_quests_data(session, owner_id, scene_config);
21230
- if (questDataRes && questDataRes.success) {
21231
- questDataObj = questDataRes.data;
21232
- }
21233
- } else {
21234
- const questDataRes = await db_services.get_file(`x_view_quests/${owner_id}/${scene_config}`);
21235
- if (questDataRes && questDataRes.success) {
21236
- questDataObj = questDataRes.data;
21237
- }
21238
- }
21239
- }
21240
- const currentQuestNodes = (questDataObj == null ? void 0 : questDataObj.nodes) || [];
21241
- const currentQuestLinks = (questDataObj == null ? void 0 : questDataObj.links) || [];
21242
- const currentMilestones = (questDataObj == null ? void 0 : questDataObj.milestones) || [];
21243
21221
  if (isView) {
21244
21222
  parentData[scene_config] = {
21245
21223
  dataset_name: "Quests Internas (View)",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lv-x-software-house/x_view",
3
- "version": "1.2.8-dev.2",
3
+ "version": "1.2.8-dev.4",
4
4
  "description": "Pacote privado contendo os componentes e lógica de renderização 3D do X View.",
5
5
  "author": "iv.x - Engenharia de Software - ivxsoftwarehouse@gmail.com",
6
6
  "license": "UNLICENSED",