@lv-x-software-house/x_view 1.2.8-dev.1 → 1.2.8-dev.2

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 +170 -93
  2. package/dist/index.mjs +170 -93
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2223,7 +2223,7 @@ var userActionHandlers = {
2223
2223
  }
2224
2224
  },
2225
2225
  handleSaveNodeDetails: async (context, updatedNode, keepOpen = false) => {
2226
- var _a, _b, _c;
2226
+ var _a, _b, _c, _d;
2227
2227
  const { graphDataRef, sceneDataRef, stateRef, setters } = context;
2228
2228
  if (!graphDataRef.current || !sceneDataRef.current) return;
2229
2229
  const {
@@ -2350,23 +2350,40 @@ var userActionHandlers = {
2350
2350
  ...nodeToSave
2351
2351
  };
2352
2352
  }
2353
- const viewFilePayload = {
2354
- parent_dbs: sceneDataRef.current.parent_dbs,
2355
- nodes: sceneDataRef.current.nodes,
2356
- links: sceneDataRef.current.links,
2357
- quest_counter: sceneDataRef.current.quest_counter || 1
2358
- };
2359
- const questFilePayload = {
2360
- nodes: specificParentData.nodes,
2361
- links: specificParentData.links,
2362
- milestones: sceneDataRef.current.milestones || []
2363
- };
2364
- await context.actions.save_view_data(
2365
- context.sceneSaveUrl,
2366
- viewFilePayload
2367
- );
2368
- const questSaveUrl = context.sceneSaveUrl.replace("x_view_scenes", "x_view_quests");
2369
- await context.actions.save_view_data(questSaveUrl, questFilePayload);
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
+ }
2370
2387
  } else {
2371
2388
  const filenameForSpecificParent = `x_view_dbs/${ownerId}/${parentFileId}`;
2372
2389
  await context.actions.save_view_data(
@@ -15477,7 +15494,14 @@ function XViewScene({
15477
15494
  check_user_permission,
15478
15495
  get_view_members,
15479
15496
  create_google_doc_action,
15480
- open_google_picker_action
15497
+ open_google_picker_action,
15498
+ // Firestore Atomic Actions (Quests & Milestones)
15499
+ save_quest_action,
15500
+ delete_quest_action,
15501
+ save_quest_link_action,
15502
+ delete_quest_link_action,
15503
+ save_milestone_action,
15504
+ delete_milestone_action
15481
15505
  }) {
15482
15506
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
15483
15507
  const { data: session, status } = (0, import_react34.useSession)();
@@ -17984,7 +18008,13 @@ function XViewScene({
17984
18008
  get_single_parent_file,
17985
18009
  get_scene_view_data,
17986
18010
  upload_file: upload_file_action,
17987
- delete_file: delete_file_action
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
17988
18018
  }
17989
18019
  };
17990
18020
  },
@@ -18003,7 +18033,13 @@ function XViewScene({
18003
18033
  get_single_parent_file,
18004
18034
  get_scene_view_data,
18005
18035
  upload_file_action,
18006
- delete_file_action
18036
+ delete_file_action,
18037
+ save_quest_action,
18038
+ delete_quest_action,
18039
+ save_quest_link_action,
18040
+ delete_quest_link_action,
18041
+ save_milestone_action,
18042
+ delete_milestone_action
18007
18043
  ]
18008
18044
  );
18009
18045
  const handleStartVersioning = (nodeData) => {
@@ -18209,23 +18245,28 @@ function XViewScene({
18209
18245
  parentDataRef.current[sceneConfigId].nodes[parentIndex].quest_abstraction_tree = formattedAbstractionTree;
18210
18246
  }
18211
18247
  }
18212
- const sceneFileData = {
18213
- ...sceneData,
18214
- nodes: sceneData.nodes || [],
18215
- links: sceneData.links || [],
18216
- quest_counter: sceneData.quest_counter || 1
18217
- };
18218
- const questFileData = {
18219
- nodes: sceneData.quest_nodes || [],
18220
- links: sceneData.quest_links || [],
18221
- milestones: sceneData.milestones || []
18222
- };
18223
- await save_view_data(sceneSaveUrl, sceneFileData);
18224
- const questSaveUrl = sceneSaveUrl.replace(
18225
- "x_view_scenes",
18226
- "x_view_quests"
18227
- );
18228
- await save_view_data(questSaveUrl, questFileData);
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
+ }
18229
18270
  }
18230
18271
  const updatedNodeData = sceneData.quest_nodes[questIndex];
18231
18272
  const nodeMesh = (_a2 = stateRef.current.nodeObjects) == null ? void 0 : _a2[String(questNodeId)];
@@ -18306,15 +18347,20 @@ function XViewScene({
18306
18347
  ...sceneDataRef2.current,
18307
18348
  quest_counter: currentCounter + 1
18308
18349
  };
18309
- const questFileData = {
18310
- nodes: graphDataRef2.current[sceneConfigId2].nodes,
18311
- links: graphDataRef2.current[sceneConfigId2].links,
18312
- milestones: sceneDataRef2.current.milestones || []
18313
- };
18314
18350
  try {
18315
- await actions.save_view_data(sceneSaveUrl2, sceneFileData);
18316
- const questSaveUrl = sceneSaveUrl2.replace("x_view_scenes", "x_view_quests");
18317
- await actions.save_view_data(questSaveUrl, questFileData);
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
+ }
18318
18364
  sceneDataRef2.current.quest_counter = currentCounter + 1;
18319
18365
  stateRef2.current.nodeIdToParentFileMap.set(String(newNode.id), {
18320
18366
  parentFileId: sceneConfigId2,
@@ -18390,21 +18436,25 @@ function XViewScene({
18390
18436
  if (parentFileIdToSave === sceneConfigId2) {
18391
18437
  const specificParentData = graphDataRef2.current[sceneConfigId2];
18392
18438
  specificParentData.links.push(newLink);
18393
- const viewFilePayload = {
18394
- ...sceneDataRef2.current,
18395
- quest_counter: sceneDataRef2.current.quest_counter || 1
18396
- };
18397
- const questFilePayload = {
18398
- nodes: specificParentData.nodes,
18399
- links: specificParentData.links,
18400
- milestones: sceneDataRef2.current.milestones || []
18401
- };
18402
- await context.actions.save_view_data(sceneSaveUrl2, viewFilePayload);
18403
- const questSaveUrl = sceneSaveUrl2.replace(
18404
- "x_view_scenes",
18405
- "x_view_quests"
18406
- );
18407
- await context.actions.save_view_data(questSaveUrl, questFilePayload);
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
+ }
18408
18458
  } else {
18409
18459
  const specificParentData = JSON.parse(
18410
18460
  JSON.stringify(graphDataRef2.current[parentFileIdToSave])
@@ -20112,33 +20162,58 @@ function XViewScene({
20112
20162
  async (newMilestones) => {
20113
20163
  var _a2, _b2, _c2;
20114
20164
  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
+ );
20115
20172
  sceneDataRef.current.milestones = newMilestones;
20116
20173
  setSceneVersion((v) => v + 1);
20117
20174
  const isView = ((_a2 = viewParams == null ? void 0 : viewParams.type) == null ? void 0 : _a2.toLowerCase()) === "view";
20118
20175
  if (!isView || !save_view_data || !sceneSaveUrl) return;
20119
- const sceneFileData = {
20120
- ...sceneDataRef.current,
20121
- nodes: sceneDataRef.current.nodes || [],
20122
- links: sceneDataRef.current.links || [],
20123
- quest_counter: sceneDataRef.current.quest_counter || 1
20124
- };
20125
- const questFileData = {
20126
- nodes: ((_b2 = parentDataRef.current[sceneConfigId]) == null ? void 0 : _b2.nodes) || sceneDataRef.current.quest_nodes || [],
20127
- links: ((_c2 = parentDataRef.current[sceneConfigId]) == null ? void 0 : _c2.links) || sceneDataRef.current.quest_links || [],
20128
- milestones: newMilestones
20129
- };
20130
20176
  try {
20131
- await save_view_data(sceneSaveUrl, sceneFileData);
20132
- const questSaveUrl = sceneSaveUrl.replace(
20133
- "x_view_scenes",
20134
- "x_view_quests"
20135
- );
20136
- await save_view_data(questSaveUrl, questFileData);
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
+ }
20137
20212
  } catch (error) {
20138
20213
  console.error("Erro ao salvar milestones:", error);
20139
20214
  }
20140
20215
  },
20141
- [sceneConfigId, sceneSaveUrl, save_view_data, viewParams == null ? void 0 : viewParams.type]
20216
+ [sceneConfigId, sceneSaveUrl, save_view_data, save_milestone_action, delete_milestone_action, viewParams == null ? void 0 : viewParams.type]
20142
20217
  );
20143
20218
  const handleSaveCurrentView = (0, import_react33.useCallback)(async () => {
20144
20219
  var _a2, _b2, _c2;
@@ -21044,7 +21119,7 @@ async function save_view_data_logic(db_services, filename, data) {
21044
21119
  }
21045
21120
  }
21046
21121
  async function get_scene_view_data_logic(db_services, scene_config, owner_id, type, session, focusNodeId = null, focusAncestryId = null) {
21047
- var _a, _b, _c;
21122
+ var _a, _b;
21048
21123
  try {
21049
21124
  if (!session || !session.user) {
21050
21125
  return { success: false, error: "Usu\xE1rio n\xE3o autenticado." };
@@ -21071,32 +21146,34 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21071
21146
  const parentResponsesPromises = parentDbObjects.map(
21072
21147
  (db_info) => db_services.get_file(`x_view_dbs/${db_info.owner_id}/${db_info.db_id}`)
21073
21148
  );
21074
- if (isView) {
21075
- parentResponsesPromises.push(
21076
- db_services.get_file(`x_view_quests/${owner_id}/${scene_config}`)
21077
- );
21078
- }
21079
21149
  const parentResponsesResults = await Promise.allSettled(parentResponsesPromises);
21080
21150
  const parentData = {};
21081
21151
  let questDataObj = null;
21082
21152
  for (let i = 0; i < parentResponsesResults.length; i++) {
21083
21153
  const result = parentResponsesResults[i];
21084
- if (isView && i === parentResponsesResults.length - 1) {
21085
- if (result.status === "fulfilled" && ((_a = result.value) == null ? void 0 : _a.success)) {
21086
- questDataObj = result.value.data;
21087
- }
21088
- continue;
21089
- }
21090
21154
  const db_info = parentDbObjects[i];
21091
- if (result.status === "fulfilled" && ((_b = result.value) == null ? void 0 : _b.success)) {
21155
+ if (result.status === "fulfilled" && ((_a = result.value) == null ? void 0 : _a.success)) {
21092
21156
  parentData[db_info.db_id] = result.value.data;
21093
21157
  } else {
21094
21158
  console.warn(
21095
21159
  `Arquivo pai n\xE3o carregado: ${db_info.db_id}. Pode ter sido deletado.`,
21096
- result.status === "rejected" ? result.reason : (_c = result.value) == null ? void 0 : _c.error
21160
+ result.status === "rejected" ? result.reason : (_b = result.value) == null ? void 0 : _b.error
21097
21161
  );
21098
21162
  }
21099
21163
  }
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
+ }
21100
21177
  const currentQuestNodes = (questDataObj == null ? void 0 : questDataObj.nodes) || [];
21101
21178
  const currentQuestLinks = (questDataObj == null ? void 0 : questDataObj.links) || [];
21102
21179
  const currentMilestones = (questDataObj == null ? void 0 : questDataObj.milestones) || [];
package/dist/index.mjs CHANGED
@@ -2184,7 +2184,7 @@ var userActionHandlers = {
2184
2184
  }
2185
2185
  },
2186
2186
  handleSaveNodeDetails: async (context, updatedNode, keepOpen = false) => {
2187
- var _a, _b, _c;
2187
+ var _a, _b, _c, _d;
2188
2188
  const { graphDataRef, sceneDataRef, stateRef, setters } = context;
2189
2189
  if (!graphDataRef.current || !sceneDataRef.current) return;
2190
2190
  const {
@@ -2311,23 +2311,40 @@ var userActionHandlers = {
2311
2311
  ...nodeToSave
2312
2312
  };
2313
2313
  }
2314
- const viewFilePayload = {
2315
- parent_dbs: sceneDataRef.current.parent_dbs,
2316
- nodes: sceneDataRef.current.nodes,
2317
- links: sceneDataRef.current.links,
2318
- quest_counter: sceneDataRef.current.quest_counter || 1
2319
- };
2320
- const questFilePayload = {
2321
- nodes: specificParentData.nodes,
2322
- links: specificParentData.links,
2323
- milestones: sceneDataRef.current.milestones || []
2324
- };
2325
- await context.actions.save_view_data(
2326
- context.sceneSaveUrl,
2327
- viewFilePayload
2328
- );
2329
- const questSaveUrl = context.sceneSaveUrl.replace("x_view_scenes", "x_view_quests");
2330
- await context.actions.save_view_data(questSaveUrl, questFilePayload);
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
+ }
2331
2348
  } else {
2332
2349
  const filenameForSpecificParent = `x_view_dbs/${ownerId}/${parentFileId}`;
2333
2350
  await context.actions.save_view_data(
@@ -15540,7 +15557,14 @@ function XViewScene({
15540
15557
  check_user_permission,
15541
15558
  get_view_members,
15542
15559
  create_google_doc_action,
15543
- open_google_picker_action
15560
+ open_google_picker_action,
15561
+ // Firestore Atomic Actions (Quests & Milestones)
15562
+ save_quest_action,
15563
+ delete_quest_action,
15564
+ save_quest_link_action,
15565
+ delete_quest_link_action,
15566
+ save_milestone_action,
15567
+ delete_milestone_action
15544
15568
  }) {
15545
15569
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
15546
15570
  const { data: session, status } = useSession();
@@ -18047,7 +18071,13 @@ function XViewScene({
18047
18071
  get_single_parent_file,
18048
18072
  get_scene_view_data,
18049
18073
  upload_file: upload_file_action,
18050
- delete_file: delete_file_action
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
18051
18081
  }
18052
18082
  };
18053
18083
  },
@@ -18066,7 +18096,13 @@ function XViewScene({
18066
18096
  get_single_parent_file,
18067
18097
  get_scene_view_data,
18068
18098
  upload_file_action,
18069
- delete_file_action
18099
+ delete_file_action,
18100
+ save_quest_action,
18101
+ delete_quest_action,
18102
+ save_quest_link_action,
18103
+ delete_quest_link_action,
18104
+ save_milestone_action,
18105
+ delete_milestone_action
18070
18106
  ]
18071
18107
  );
18072
18108
  const handleStartVersioning = (nodeData) => {
@@ -18272,23 +18308,28 @@ function XViewScene({
18272
18308
  parentDataRef.current[sceneConfigId].nodes[parentIndex].quest_abstraction_tree = formattedAbstractionTree;
18273
18309
  }
18274
18310
  }
18275
- const sceneFileData = {
18276
- ...sceneData,
18277
- nodes: sceneData.nodes || [],
18278
- links: sceneData.links || [],
18279
- quest_counter: sceneData.quest_counter || 1
18280
- };
18281
- const questFileData = {
18282
- nodes: sceneData.quest_nodes || [],
18283
- links: sceneData.quest_links || [],
18284
- milestones: sceneData.milestones || []
18285
- };
18286
- await save_view_data(sceneSaveUrl, sceneFileData);
18287
- const questSaveUrl = sceneSaveUrl.replace(
18288
- "x_view_scenes",
18289
- "x_view_quests"
18290
- );
18291
- await save_view_data(questSaveUrl, questFileData);
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
+ }
18292
18333
  }
18293
18334
  const updatedNodeData = sceneData.quest_nodes[questIndex];
18294
18335
  const nodeMesh = (_a2 = stateRef.current.nodeObjects) == null ? void 0 : _a2[String(questNodeId)];
@@ -18369,15 +18410,20 @@ function XViewScene({
18369
18410
  ...sceneDataRef2.current,
18370
18411
  quest_counter: currentCounter + 1
18371
18412
  };
18372
- const questFileData = {
18373
- nodes: graphDataRef2.current[sceneConfigId2].nodes,
18374
- links: graphDataRef2.current[sceneConfigId2].links,
18375
- milestones: sceneDataRef2.current.milestones || []
18376
- };
18377
18413
  try {
18378
- await actions.save_view_data(sceneSaveUrl2, sceneFileData);
18379
- const questSaveUrl = sceneSaveUrl2.replace("x_view_scenes", "x_view_quests");
18380
- await actions.save_view_data(questSaveUrl, questFileData);
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
+ }
18381
18427
  sceneDataRef2.current.quest_counter = currentCounter + 1;
18382
18428
  stateRef2.current.nodeIdToParentFileMap.set(String(newNode.id), {
18383
18429
  parentFileId: sceneConfigId2,
@@ -18453,21 +18499,25 @@ function XViewScene({
18453
18499
  if (parentFileIdToSave === sceneConfigId2) {
18454
18500
  const specificParentData = graphDataRef2.current[sceneConfigId2];
18455
18501
  specificParentData.links.push(newLink);
18456
- const viewFilePayload = {
18457
- ...sceneDataRef2.current,
18458
- quest_counter: sceneDataRef2.current.quest_counter || 1
18459
- };
18460
- const questFilePayload = {
18461
- nodes: specificParentData.nodes,
18462
- links: specificParentData.links,
18463
- milestones: sceneDataRef2.current.milestones || []
18464
- };
18465
- await context.actions.save_view_data(sceneSaveUrl2, viewFilePayload);
18466
- const questSaveUrl = sceneSaveUrl2.replace(
18467
- "x_view_scenes",
18468
- "x_view_quests"
18469
- );
18470
- await context.actions.save_view_data(questSaveUrl, questFilePayload);
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
+ }
18471
18521
  } else {
18472
18522
  const specificParentData = JSON.parse(
18473
18523
  JSON.stringify(graphDataRef2.current[parentFileIdToSave])
@@ -20175,33 +20225,58 @@ function XViewScene({
20175
20225
  async (newMilestones) => {
20176
20226
  var _a2, _b2, _c2;
20177
20227
  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
+ );
20178
20235
  sceneDataRef.current.milestones = newMilestones;
20179
20236
  setSceneVersion((v) => v + 1);
20180
20237
  const isView = ((_a2 = viewParams == null ? void 0 : viewParams.type) == null ? void 0 : _a2.toLowerCase()) === "view";
20181
20238
  if (!isView || !save_view_data || !sceneSaveUrl) return;
20182
- const sceneFileData = {
20183
- ...sceneDataRef.current,
20184
- nodes: sceneDataRef.current.nodes || [],
20185
- links: sceneDataRef.current.links || [],
20186
- quest_counter: sceneDataRef.current.quest_counter || 1
20187
- };
20188
- const questFileData = {
20189
- nodes: ((_b2 = parentDataRef.current[sceneConfigId]) == null ? void 0 : _b2.nodes) || sceneDataRef.current.quest_nodes || [],
20190
- links: ((_c2 = parentDataRef.current[sceneConfigId]) == null ? void 0 : _c2.links) || sceneDataRef.current.quest_links || [],
20191
- milestones: newMilestones
20192
- };
20193
20239
  try {
20194
- await save_view_data(sceneSaveUrl, sceneFileData);
20195
- const questSaveUrl = sceneSaveUrl.replace(
20196
- "x_view_scenes",
20197
- "x_view_quests"
20198
- );
20199
- await save_view_data(questSaveUrl, questFileData);
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
+ }
20200
20275
  } catch (error) {
20201
20276
  console.error("Erro ao salvar milestones:", error);
20202
20277
  }
20203
20278
  },
20204
- [sceneConfigId, sceneSaveUrl, save_view_data, viewParams == null ? void 0 : viewParams.type]
20279
+ [sceneConfigId, sceneSaveUrl, save_view_data, save_milestone_action, delete_milestone_action, viewParams == null ? void 0 : viewParams.type]
20205
20280
  );
20206
20281
  const handleSaveCurrentView = useCallback7(async () => {
20207
20282
  var _a2, _b2, _c2;
@@ -21107,7 +21182,7 @@ async function save_view_data_logic(db_services, filename, data) {
21107
21182
  }
21108
21183
  }
21109
21184
  async function get_scene_view_data_logic(db_services, scene_config, owner_id, type, session, focusNodeId = null, focusAncestryId = null) {
21110
- var _a, _b, _c;
21185
+ var _a, _b;
21111
21186
  try {
21112
21187
  if (!session || !session.user) {
21113
21188
  return { success: false, error: "Usu\xE1rio n\xE3o autenticado." };
@@ -21134,32 +21209,34 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21134
21209
  const parentResponsesPromises = parentDbObjects.map(
21135
21210
  (db_info) => db_services.get_file(`x_view_dbs/${db_info.owner_id}/${db_info.db_id}`)
21136
21211
  );
21137
- if (isView) {
21138
- parentResponsesPromises.push(
21139
- db_services.get_file(`x_view_quests/${owner_id}/${scene_config}`)
21140
- );
21141
- }
21142
21212
  const parentResponsesResults = await Promise.allSettled(parentResponsesPromises);
21143
21213
  const parentData = {};
21144
21214
  let questDataObj = null;
21145
21215
  for (let i = 0; i < parentResponsesResults.length; i++) {
21146
21216
  const result = parentResponsesResults[i];
21147
- if (isView && i === parentResponsesResults.length - 1) {
21148
- if (result.status === "fulfilled" && ((_a = result.value) == null ? void 0 : _a.success)) {
21149
- questDataObj = result.value.data;
21150
- }
21151
- continue;
21152
- }
21153
21217
  const db_info = parentDbObjects[i];
21154
- if (result.status === "fulfilled" && ((_b = result.value) == null ? void 0 : _b.success)) {
21218
+ if (result.status === "fulfilled" && ((_a = result.value) == null ? void 0 : _a.success)) {
21155
21219
  parentData[db_info.db_id] = result.value.data;
21156
21220
  } else {
21157
21221
  console.warn(
21158
21222
  `Arquivo pai n\xE3o carregado: ${db_info.db_id}. Pode ter sido deletado.`,
21159
- result.status === "rejected" ? result.reason : (_c = result.value) == null ? void 0 : _c.error
21223
+ result.status === "rejected" ? result.reason : (_b = result.value) == null ? void 0 : _b.error
21160
21224
  );
21161
21225
  }
21162
21226
  }
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
+ }
21163
21240
  const currentQuestNodes = (questDataObj == null ? void 0 : questDataObj.nodes) || [];
21164
21241
  const currentQuestLinks = (questDataObj == null ? void 0 : questDataObj.links) || [];
21165
21242
  const currentMilestones = (questDataObj == null ? void 0 : questDataObj.milestones) || [];
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.1",
3
+ "version": "1.2.8-dev.2",
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",