@lv-x-software-house/x_view 1.2.8-dev.3 → 1.2.8-dev.7

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 +208 -66
  2. package/dist/index.mjs +208 -66
  3. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -15459,7 +15459,9 @@ function XViewScene({
15459
15459
  save_quest_action,
15460
15460
  delete_quest_action,
15461
15461
  save_quest_link_action,
15462
- delete_quest_link_action
15462
+ delete_quest_link_action,
15463
+ get_view_quests_and_links_action,
15464
+ migrate_legacy_quests_action
15463
15465
  }) {
15464
15466
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
15465
15467
  const { data: session, status } = (0, import_react34.useSession)();
@@ -16018,7 +16020,7 @@ function XViewScene({
16018
16020
  obj.material.dispose();
16019
16021
  }
16020
16022
  }
16021
- Object.values(nodeObjects).forEach((mesh) => {
16023
+ Object.values(nodeObjects || {}).forEach((mesh) => {
16022
16024
  const oldLabel = mesh.getObjectByName("timelineLabel");
16023
16025
  if (oldLabel) {
16024
16026
  mesh.remove(oldLabel);
@@ -16042,7 +16044,7 @@ function XViewScene({
16042
16044
  }
16043
16045
  return null;
16044
16046
  };
16045
- Object.values(nodeObjects).forEach((mesh) => {
16047
+ Object.values(nodeObjects || {}).forEach((mesh) => {
16046
16048
  const dateProp = mesh.userData.Date;
16047
16049
  let nodeInfo = { mesh, type: "point", label: "", isUndated: true };
16048
16050
  if (dateProp) {
@@ -16323,19 +16325,40 @@ function XViewScene({
16323
16325
  focusAncestryId
16324
16326
  );
16325
16327
  const boardPromise = get_boards_action && session ? get_boards_action(configPath, sceneType, session, ownerId2) : Promise.resolve({ success: false, data: [] });
16326
- 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([
16327
16330
  scenePromise,
16328
- boardPromise
16331
+ boardPromise,
16332
+ questPromise
16329
16333
  ]);
16330
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) && Array.isArray(questResponse.quests) ? questResponse.quests : [];
16337
+ let firestoreLinks = (questResponse == null ? void 0 : questResponse.success) && Array.isArray(questResponse.links) ? 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
+ }
16331
16354
  if (focusNodeId) {
16332
16355
  let targetNode = sceneResponse.data.scene.nodes.find(
16333
16356
  (n) => String(n.id) === String(focusNodeId)
16334
16357
  );
16335
16358
  if (!targetNode) {
16336
16359
  const allParentNodes = Object.values(
16337
- sceneResponse.data.parent
16338
- ).flatMap((f) => f.nodes || []);
16360
+ sceneResponse.data.parent || {}
16361
+ ).flatMap((f) => (f == null ? void 0 : f.nodes) || []);
16339
16362
  targetNode = allParentNodes.find(
16340
16363
  (n) => String(n.id) === String(focusNodeId)
16341
16364
  );
@@ -16349,10 +16372,29 @@ function XViewScene({
16349
16372
  sceneResponse.data.scene.links = [];
16350
16373
  }
16351
16374
  sceneDataRef.current = {
16352
- ...sceneResponse.data.scene,
16353
- milestones: sceneResponse.data.scene.milestones || []
16375
+ ...sceneData,
16376
+ quests_migrated: sceneData.quests_migrated || false,
16377
+ milestones: sceneData.milestones || []
16354
16378
  };
16355
- 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;
16356
16398
  ancestryDataRef.current = sceneResponse.data.ancestry;
16357
16399
  console.log(
16358
16400
  "Console de sceneResponse.data.scene:",
@@ -16658,7 +16700,7 @@ function XViewScene({
16658
16700
  positionGroups.get(posKey).push(String(q.id));
16659
16701
  });
16660
16702
  });
16661
- Object.values(nodeObjects).forEach((mesh) => {
16703
+ Object.values(nodeObjects || {}).forEach((mesh) => {
16662
16704
  const oldLabel = mesh.getObjectByName("questDateLabel") || mesh.getObjectByName("timelineLabel");
16663
16705
  if (oldLabel) {
16664
16706
  mesh.remove(oldLabel);
@@ -17970,7 +18012,9 @@ function XViewScene({
17970
18012
  save_quest: save_quest_action,
17971
18013
  delete_quest: delete_quest_action,
17972
18014
  save_quest_link: save_quest_link_action,
17973
- delete_quest_link: delete_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
17974
18018
  }
17975
18019
  };
17976
18020
  },
@@ -17993,7 +18037,9 @@ function XViewScene({
17993
18037
  save_quest_action,
17994
18038
  delete_quest_action,
17995
18039
  save_quest_link_action,
17996
- delete_quest_link_action
18040
+ delete_quest_link_action,
18041
+ get_view_quests_and_links_action,
18042
+ migrate_legacy_quests_action
17997
18043
  ]
17998
18044
  );
17999
18045
  const handleStartVersioning = (nodeData) => {
@@ -18003,7 +18049,7 @@ function XViewScene({
18003
18049
  (questNode) => {
18004
18050
  var _a2, _b2, _c2;
18005
18051
  if (!questNode || !actionHandlerContext) return;
18006
- const allParentNodes = Object.values(parentDataRef.current).flatMap(
18052
+ const allParentNodes = Object.values(parentDataRef.current || {}).flatMap(
18007
18053
  (fileData) => fileData.nodes || []
18008
18054
  );
18009
18055
  const blockCheck = isQuestBlocked(questNode, allParentNodes);
@@ -18540,7 +18586,7 @@ function XViewScene({
18540
18586
  if (line.material) line.material.dispose();
18541
18587
  });
18542
18588
  }
18543
- const allParentNodes = Object.values(parentDataRef.current).flatMap(
18589
+ const allParentNodes = Object.values(parentDataRef.current || {}).flatMap(
18544
18590
  (fileData) => fileData.nodes
18545
18591
  );
18546
18592
  const allAncestries = ancestryDataRef.current || [];
@@ -18928,7 +18974,7 @@ function XViewScene({
18928
18974
  );
18929
18975
  if (!ancestryObject || !ancestryObject.abstraction_tree) return;
18930
18976
  const { ancestryGroup, nodeObjects, renderer, renderedAncestries } = stateRef.current;
18931
- const allParentNodes = Object.values(parentDataRef.current).flatMap(
18977
+ const allParentNodes = Object.values(parentDataRef.current || {}).flatMap(
18932
18978
  (f) => f.nodes
18933
18979
  );
18934
18980
  let fullTree = buildFullAncestryTree(
@@ -19016,7 +19062,7 @@ function XViewScene({
19016
19062
  const allAncestries = ancestryDataRef.current || [];
19017
19063
  const fullTree = buildFullAncestryTree(
19018
19064
  ancestry.tree,
19019
- Object.values(parentDataRef.current).flatMap((f) => f.nodes),
19065
+ Object.values(parentDataRef.current || {}).flatMap((f) => f.nodes),
19020
19066
  allAncestries
19021
19067
  );
19022
19068
  if (action === "open") {
@@ -19198,7 +19244,7 @@ function XViewScene({
19198
19244
  return null;
19199
19245
  const fullTree = buildFullAncestryTree(
19200
19246
  readingMode.ancestry.tree,
19201
- Object.values(parentDataRef.current).flatMap((f) => f.nodes),
19247
+ Object.values(parentDataRef.current || {}).flatMap((f) => f.nodes),
19202
19248
  ancestryDataRef.current
19203
19249
  );
19204
19250
  const findNodeInTree = (tree, targetId) => {
@@ -19263,7 +19309,7 @@ function XViewScene({
19263
19309
  }
19264
19310
  const fullTree = buildFullAncestryTree(
19265
19311
  readingMode.ancestry.tree,
19266
- Object.values(parentDataRef.current).flatMap((f) => f.nodes),
19312
+ Object.values(parentDataRef.current || {}).flatMap((f) => f.nodes),
19267
19313
  ancestryDataRef.current
19268
19314
  );
19269
19315
  let currentPtr = fullTree;
@@ -19360,7 +19406,7 @@ function XViewScene({
19360
19406
  let targetObj = ancestry;
19361
19407
  let targetTree = ancestry.tree;
19362
19408
  if (branchStack.length > 0) {
19363
- const allNodes = Object.values(parentDataRef.current).flatMap(
19409
+ const allNodes = Object.values(parentDataRef.current || {}).flatMap(
19364
19410
  (f) => f.nodes
19365
19411
  );
19366
19412
  const fullTree = buildFullAncestryTree(
@@ -19517,7 +19563,7 @@ function XViewScene({
19517
19563
  stateRef.current.maxAncestryRenderIndex = 0;
19518
19564
  const initialSections = /* @__PURE__ */ new Set(["preamble", 0]);
19519
19565
  await handleRenderAncestry(ancestryObject, initialSections);
19520
- const allParentNodes = Object.values(parentDataRef.current).flatMap(
19566
+ const allParentNodes = Object.values(parentDataRef.current || {}).flatMap(
19521
19567
  (fileData) => fileData.nodes
19522
19568
  );
19523
19569
  const allAncestries = ancestryDataRef.current || [];
@@ -19982,7 +20028,7 @@ function XViewScene({
19982
20028
  }, []);
19983
20029
  const allAvailableNodes = (0, import_react33.useMemo)(() => {
19984
20030
  if (!parentDataRef.current) return [];
19985
- return Object.values(parentDataRef.current).flatMap(
20031
+ return Object.values(parentDataRef.current || {}).flatMap(
19986
20032
  (fileData) => fileData.nodes || []
19987
20033
  );
19988
20034
  }, [sceneVersion, isInitialized]);
@@ -20071,7 +20117,7 @@ function XViewScene({
20071
20117
  if (!parentDataRef.current) {
20072
20118
  return [];
20073
20119
  }
20074
- const allTypes = Object.values(parentDataRef.current).flatMap(
20120
+ const allTypes = Object.values(parentDataRef.current || {}).flatMap(
20075
20121
  (fileData) => fileData.nodes.flatMap((node) => {
20076
20122
  if (Array.isArray(node.type)) return node.type;
20077
20123
  return [node.type];
@@ -20145,7 +20191,7 @@ function XViewScene({
20145
20191
  return;
20146
20192
  }
20147
20193
  if (!save_view_data) return;
20148
- const currentNodes = Object.values(nodeObjects).map((mesh) => {
20194
+ const currentNodes = Object.values(nodeObjects || {}).map((mesh) => {
20149
20195
  const {
20150
20196
  _baseEmissiveIntensity,
20151
20197
  labelObject,
@@ -20307,7 +20353,7 @@ function XViewScene({
20307
20353
  } = stateRef.current;
20308
20354
  if (graphGroup) {
20309
20355
  let ghostPosition = sceneControls.target.clone();
20310
- const existingNodes = Object.values(nodeObjects);
20356
+ const existingNodes = Object.values(nodeObjects || {});
20311
20357
  let isOccupied = true;
20312
20358
  let radius = 18;
20313
20359
  let angle = 0;
@@ -21050,20 +21096,35 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21050
21096
  if (!session || !session.user) {
21051
21097
  return { success: false, error: "Usu\xE1rio n\xE3o autenticado." };
21052
21098
  }
21053
- const membershipCheck = await db_services.check_membership(owner_id, type, scene_config, session.user.id);
21099
+ const membershipCheck = await db_services.check_membership(
21100
+ owner_id,
21101
+ type,
21102
+ scene_config,
21103
+ session.user.id
21104
+ );
21054
21105
  const isFullMember = membershipCheck.success && membershipCheck.isValidMember;
21055
21106
  if (!isFullMember && !focusNodeId && !focusAncestryId) {
21056
- return { success: false, error: "Acesso Negado: Voc\xEA n\xE3o possui permiss\xE3o para acessar este cen\xE1rio." };
21107
+ return {
21108
+ success: false,
21109
+ error: "Acesso Negado: Voc\xEA n\xE3o possui permiss\xE3o para acessar este cen\xE1rio."
21110
+ };
21057
21111
  }
21058
- const sceneResponse = await db_services.get_file(`x_view_scenes/${owner_id}/${scene_config}`);
21112
+ const sceneResponse = await db_services.get_file(
21113
+ `x_view_scenes/${owner_id}/${scene_config}`
21114
+ );
21059
21115
  if (!sceneResponse || !sceneResponse.success) {
21060
21116
  console.error("Falha ao buscar dados da cena:", sceneResponse == null ? void 0 : sceneResponse.error);
21061
- return { success: false, error: `N\xE3o foi poss\xEDvel carregar o arquivo da cena: ${scene_config}` };
21117
+ return {
21118
+ success: false,
21119
+ error: `N\xE3o foi poss\xEDvel carregar o arquivo da cena: ${scene_config}`
21120
+ };
21062
21121
  }
21063
21122
  const sceneData = sceneResponse.data;
21064
21123
  const parentDbObjects = sceneData.parent_dbs || [];
21065
21124
  if (type && type.toLowerCase().includes("database")) {
21066
- const selfExists = parentDbObjects.some((db) => String(db.db_id) === String(scene_config));
21125
+ const selfExists = parentDbObjects.some(
21126
+ (db) => String(db.db_id) === String(scene_config)
21127
+ );
21067
21128
  if (!selfExists) {
21068
21129
  parentDbObjects.push({ db_id: scene_config, owner_id });
21069
21130
  }
@@ -21072,13 +21133,18 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21072
21133
  const parentResponsesPromises = parentDbObjects.map(
21073
21134
  (db_info) => db_services.get_file(`x_view_dbs/${db_info.owner_id}/${db_info.db_id}`)
21074
21135
  );
21075
- const parentResponsesResults = await Promise.allSettled(parentResponsesPromises);
21136
+ const parentResponsesResults = await Promise.allSettled(
21137
+ parentResponsesPromises
21138
+ );
21076
21139
  const parentData = {};
21077
21140
  let currentQuestNodes = [];
21078
21141
  let currentQuestLinks = [];
21079
21142
  let currentMilestones = [];
21080
21143
  if (isView) {
21081
- const firestoreQuestsRes = await db_services.get_view_quests_and_links(owner_id, scene_config);
21144
+ const firestoreQuestsRes = await db_services.get_view_quests_and_links(
21145
+ owner_id,
21146
+ scene_config
21147
+ );
21082
21148
  const isMigrated = sceneData.quests_migrated === true;
21083
21149
  if (firestoreQuestsRes.success && (firestoreQuestsRes.data.nodes.length > 0 || isMigrated)) {
21084
21150
  currentQuestNodes = firestoreQuestsRes.data.nodes;
@@ -21086,14 +21152,20 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21086
21152
  currentMilestones = sceneData.milestones || [];
21087
21153
  } else {
21088
21154
  console.log(`Iniciando Lazy Migration para View ${scene_config}...`);
21089
- const legacyQuestsRes = await db_services.get_file(`x_view_quests/${owner_id}/${scene_config}`);
21155
+ const legacyQuestsRes = await db_services.get_file(
21156
+ `x_view_quests/${owner_id}/${scene_config}`
21157
+ );
21090
21158
  if (legacyQuestsRes.success && legacyQuestsRes.data) {
21091
21159
  const legacyData = legacyQuestsRes.data;
21092
21160
  currentQuestNodes = legacyData.nodes || [];
21093
21161
  currentQuestLinks = legacyData.links || [];
21094
21162
  currentMilestones = legacyData.milestones || [];
21095
21163
  sceneData.milestones = currentMilestones;
21096
- await db_services.migrate_legacy_quests(owner_id, scene_config, legacyData);
21164
+ await db_services.migrate_legacy_quests(
21165
+ owner_id,
21166
+ scene_config,
21167
+ legacyData
21168
+ );
21097
21169
  }
21098
21170
  }
21099
21171
  }
@@ -21116,15 +21188,21 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21116
21188
  links: currentQuestLinks
21117
21189
  };
21118
21190
  }
21119
- const allNodes = Object.values(parentData).flatMap((db) => db.nodes || []);
21120
- const allLinks = Object.values(parentData).flatMap((db) => db.links || []);
21121
- const parentNodeMap = new Map(allNodes.map((node) => [String(node.id), node]));
21122
- const parentLinkMap = new Map(allLinks.map((link) => [`${link.source}-${link.target}`, link]));
21191
+ const allNodes = Object.values(parentData).flatMap((db) => (db == null ? void 0 : db.nodes) || []);
21192
+ const allLinks = Object.values(parentData).flatMap((db) => (db == null ? void 0 : db.links) || []);
21193
+ const parentNodeMap = new Map(
21194
+ allNodes.map((node) => [String(node.id), node])
21195
+ );
21196
+ const parentLinkMap = new Map(
21197
+ allLinks.map((link) => [`${link.source}-${link.target}`, link])
21198
+ );
21123
21199
  const validatedNodes = (sceneData.nodes || []).map((sceneNode) => {
21124
21200
  var _a2, _b2;
21125
21201
  const nodeTypes = Array.isArray(sceneNode.type) ? sceneNode.type : [sceneNode.type];
21126
21202
  if (nodeTypes.includes("quest")) {
21127
- const dbQuestNode = (_b2 = (_a2 = parentData[scene_config]) == null ? void 0 : _a2.nodes) == null ? void 0 : _b2.find((qn) => String(qn.id) === String(sceneNode.id));
21203
+ const dbQuestNode = (_b2 = (_a2 = parentData[scene_config]) == null ? void 0 : _a2.nodes) == null ? void 0 : _b2.find(
21204
+ (qn) => String(qn.id) === String(sceneNode.id)
21205
+ );
21128
21206
  if (dbQuestNode) {
21129
21207
  return { ...sceneNode, ...dbQuestNode };
21130
21208
  }
@@ -21136,17 +21214,23 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21136
21214
  }
21137
21215
  return null;
21138
21216
  }).filter(Boolean);
21139
- const validNodeIdsInScene = new Set(validatedNodes.map((node) => String(node.id)));
21217
+ const validNodeIdsInScene = new Set(
21218
+ validatedNodes.map((node) => String(node.id))
21219
+ );
21140
21220
  const validatedLinks = (sceneData.links || []).filter((sceneLink) => {
21141
- const linkExistsInParent = parentLinkMap.has(`${sceneLink.source}-${sceneLink.target}`);
21221
+ const linkExistsInParent = parentLinkMap.has(
21222
+ `${sceneLink.source}-${sceneLink.target}`
21223
+ );
21142
21224
  const nodesAreValidForScene = validNodeIdsInScene.has(String(sceneLink.source)) && validNodeIdsInScene.has(String(sceneLink.target));
21143
21225
  return linkExistsInParent && nodesAreValidForScene;
21144
- }).map((sceneLink) => parentLinkMap.get(`${sceneLink.source}-${sceneLink.target}`));
21226
+ }).map(
21227
+ (sceneLink) => parentLinkMap.get(`${sceneLink.source}-${sceneLink.target}`)
21228
+ );
21145
21229
  const validatedSceneData = {
21146
21230
  ...sceneData,
21147
21231
  nodes: validatedNodes,
21148
21232
  links: validatedLinks,
21149
- // Re-injetando no validated para que o restante do sistema (e.g. XViewScene local state)
21233
+ // Re-injetando no validated para que o restante do sistema (e.g. XViewScene local state)
21150
21234
  // continue acessando as quests sem perceber a separação física
21151
21235
  quest_nodes: currentQuestNodes,
21152
21236
  quest_links: currentQuestLinks,
@@ -21167,7 +21251,9 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21167
21251
  isSceneFile: false
21168
21252
  });
21169
21253
  });
21170
- const ancestryPromises = ancestryFilePaths.map((file) => db_services.get_file(file.path));
21254
+ const ancestryPromises = ancestryFilePaths.map(
21255
+ (file) => db_services.get_file(file.path)
21256
+ );
21171
21257
  const ancestryResults = await Promise.allSettled(ancestryPromises);
21172
21258
  const ancestriesFromSceneFile = [];
21173
21259
  const ancestriesFromDbFiles = [];
@@ -21193,15 +21279,21 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21193
21279
  }
21194
21280
  });
21195
21281
  const ancestryMap = /* @__PURE__ */ new Map();
21196
- ancestriesFromDbFiles.forEach((anc) => ancestryMap.set(anc.ancestry_id, anc));
21197
- ancestriesFromSceneFile.forEach((anc) => ancestryMap.set(anc.ancestry_id, anc));
21282
+ ancestriesFromDbFiles.forEach(
21283
+ (anc) => ancestryMap.set(anc.ancestry_id, anc)
21284
+ );
21285
+ ancestriesFromSceneFile.forEach(
21286
+ (anc) => ancestryMap.set(anc.ancestry_id, anc)
21287
+ );
21198
21288
  let ancestryData = Array.from(ancestryMap.values());
21199
21289
  const externalSourcesToRefresh = /* @__PURE__ */ new Map();
21200
21290
  ancestryData.forEach((anc) => {
21201
21291
  const targetSourceId = anc._source_file_id || anc._imported_from_view_id;
21202
21292
  const targetOwnerId = anc._source_owner_id || anc._imported_from_view_owner_id;
21203
21293
  if (targetSourceId && targetSourceId !== scene_config && targetOwnerId) {
21204
- const isAlreadyLoadedAsParent = parentDbObjects.some((db) => String(db.db_id) === String(targetSourceId));
21294
+ const isAlreadyLoadedAsParent = parentDbObjects.some(
21295
+ (db) => String(db.db_id) === String(targetSourceId)
21296
+ );
21205
21297
  if (!isAlreadyLoadedAsParent) {
21206
21298
  const key = `${targetOwnerId}/${targetSourceId}`;
21207
21299
  externalSourcesToRefresh.set(key, {
@@ -21242,12 +21334,16 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21242
21334
  return false;
21243
21335
  }
21244
21336
  if (externalSourcesToRefresh.has(key) && successfullyFetchedSources.has(key)) {
21245
- const stillExists = freshAncestryMap.has(String(localAnc.ancestry_id));
21337
+ const stillExists = freshAncestryMap.has(
21338
+ String(localAnc.ancestry_id)
21339
+ );
21246
21340
  return stillExists;
21247
21341
  }
21248
21342
  return true;
21249
21343
  }).map((localAnc) => {
21250
- const freshVersion = freshAncestryMap.get(String(localAnc.ancestry_id));
21344
+ const freshVersion = freshAncestryMap.get(
21345
+ String(localAnc.ancestry_id)
21346
+ );
21251
21347
  if (freshVersion) {
21252
21348
  return {
21253
21349
  ...freshVersion,
@@ -21286,7 +21382,9 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21286
21382
  parallel_branches: validBranches
21287
21383
  };
21288
21384
  };
21289
- const originalAncestryDataString = JSON.stringify(Array.from(ancestryMap.values()));
21385
+ const originalAncestryDataString = JSON.stringify(
21386
+ Array.from(ancestryMap.values())
21387
+ );
21290
21388
  const cleanedAncestryData = ancestryData.map((ancestry) => {
21291
21389
  if (!parentNodeIds.has(String(ancestry.ancestral_node))) return null;
21292
21390
  const cleanedTree = pruneTree(ancestry.tree);
@@ -21306,7 +21404,10 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21306
21404
  try {
21307
21405
  await db_services.save_file(ancestryFilePath, ancestryData);
21308
21406
  } catch (saveError) {
21309
- console.error("Falha ao salvar o arquivo de ancestralidade da cena atualizado:", saveError);
21407
+ console.error(
21408
+ "Falha ao salvar o arquivo de ancestralidade da cena atualizado:",
21409
+ saveError
21410
+ );
21310
21411
  }
21311
21412
  }
21312
21413
  if (!isFullMember) {
@@ -21314,7 +21415,9 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21314
21415
  const requiredAncestryIds = /* @__PURE__ */ new Set();
21315
21416
  if (focusNodeId) requiredNodeIds.add(String(focusNodeId));
21316
21417
  if (focusAncestryId) requiredAncestryIds.add(String(focusAncestryId));
21317
- const allNodesFromDb = Object.values(parentData).flatMap((db) => db.nodes || []);
21418
+ const allNodesFromDb = Object.values(parentData).flatMap(
21419
+ (db) => db.nodes || []
21420
+ );
21318
21421
  const extractDependenciesFromText = (text) => {
21319
21422
  if (!text) return;
21320
21423
  const mentionRegex = /\[\[MENTION:node:([a-zA-Z0-9\-_]+)\]\]/g;
@@ -21341,9 +21444,12 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21341
21444
  if (branch.linked_ancestry_id) {
21342
21445
  requiredAncestryIds.add(String(branch.linked_ancestry_id));
21343
21446
  }
21344
- if (branch.description) extractDependenciesFromText(branch.description);
21447
+ if (branch.description)
21448
+ extractDependenciesFromText(branch.description);
21345
21449
  if (branch.description_sections) {
21346
- branch.description_sections.forEach((s) => extractDependenciesFromText(s.content));
21450
+ branch.description_sections.forEach(
21451
+ (s) => extractDependenciesFromText(s.content)
21452
+ );
21347
21453
  }
21348
21454
  extractTreeDependencies(branch.tree);
21349
21455
  });
@@ -21357,7 +21463,9 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21357
21463
  if (anc && !anc.is_private) {
21358
21464
  if (anc.description) extractDependenciesFromText(anc.description);
21359
21465
  if (anc.description_sections) {
21360
- anc.description_sections.forEach((s) => extractDependenciesFromText(s.content));
21466
+ anc.description_sections.forEach(
21467
+ (s) => extractDependenciesFromText(s.content)
21468
+ );
21361
21469
  }
21362
21470
  extractTreeDependencies(anc.tree);
21363
21471
  extractTreeDependencies(anc.abstraction_tree);
@@ -21368,22 +21476,38 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21368
21476
  if (node) {
21369
21477
  if (node.description) extractDependenciesFromText(node.description);
21370
21478
  if (node.description_sections) {
21371
- node.description_sections.forEach((s) => extractDependenciesFromText(s.content));
21479
+ node.description_sections.forEach(
21480
+ (s) => extractDependenciesFromText(s.content)
21481
+ );
21372
21482
  }
21373
21483
  }
21374
21484
  });
21375
21485
  } while (requiredNodeIds.size + requiredAncestryIds.size > previousSize);
21376
- const restrictedSceneData = { ...validatedSceneData, nodes: [], links: [] };
21486
+ const restrictedSceneData = {
21487
+ ...validatedSceneData,
21488
+ nodes: [],
21489
+ links: []
21490
+ };
21377
21491
  const restrictedParentData = {};
21378
- const restrictedAncestryData = ancestryData.filter((a) => requiredAncestryIds.has(String(a.ancestry_id)) && !a.is_private);
21492
+ const restrictedAncestryData = ancestryData.filter(
21493
+ (a) => requiredAncestryIds.has(String(a.ancestry_id)) && !a.is_private
21494
+ );
21379
21495
  for (const [dbId, dbContent] of Object.entries(parentData)) {
21380
- const filteredNodes = (dbContent.nodes || []).filter((n) => requiredNodeIds.has(String(n.id)));
21496
+ const filteredNodes = (dbContent.nodes || []).filter(
21497
+ (n) => requiredNodeIds.has(String(n.id))
21498
+ );
21381
21499
  if (filteredNodes.length > 0) {
21382
- restrictedParentData[dbId] = { ...dbContent, nodes: filteredNodes, links: [] };
21500
+ restrictedParentData[dbId] = {
21501
+ ...dbContent,
21502
+ nodes: filteredNodes,
21503
+ links: []
21504
+ };
21383
21505
  }
21384
21506
  }
21385
21507
  if (focusNodeId) {
21386
- const mainNode = allNodesFromDb.find((n) => String(n.id) === String(focusNodeId));
21508
+ const mainNode = allNodesFromDb.find(
21509
+ (n) => String(n.id) === String(focusNodeId)
21510
+ );
21387
21511
  if (mainNode) {
21388
21512
  restrictedSceneData.nodes = [mainNode];
21389
21513
  }
@@ -21399,7 +21523,11 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21399
21523
  }
21400
21524
  return {
21401
21525
  success: true,
21402
- data: { scene: validatedSceneData, parent: parentData, ancestry: ancestryData }
21526
+ data: {
21527
+ scene: validatedSceneData,
21528
+ parent: parentData,
21529
+ ancestry: ancestryData
21530
+ }
21403
21531
  };
21404
21532
  } catch (error) {
21405
21533
  console.error("Erro em get_scene_view_data_logic:", error);
@@ -21419,13 +21547,18 @@ async function import_parent_file_modal_get_logic(db_services, session) {
21419
21547
  }
21420
21548
  };
21421
21549
  } catch (error) {
21422
- console.error("catch (error) em import_parent_file_modal_get_logic:", error);
21550
+ console.error(
21551
+ "catch (error) em import_parent_file_modal_get_logic:",
21552
+ error
21553
+ );
21423
21554
  return { success: false, error: error.message };
21424
21555
  }
21425
21556
  }
21426
21557
  async function get_single_parent_file_logic(db_services, file_id, session) {
21427
21558
  try {
21428
- const call_GCP_cloud_storage_get_file = await db_services.get_file(`x_view_dbs/${session.user.id}/${file_id}`);
21559
+ const call_GCP_cloud_storage_get_file = await db_services.get_file(
21560
+ `x_view_dbs/${session.user.id}/${file_id}`
21561
+ );
21429
21562
  return call_GCP_cloud_storage_get_file;
21430
21563
  } catch (error) {
21431
21564
  console.error("catch (error) em get_single_parent_file_logic:", error);
@@ -21459,7 +21592,13 @@ async function get_ancestry_file_logic(db_services, file_id, owner_id) {
21459
21592
  async function save_boards_logic(db_services, scene_id, type, boardItems, session, owner_id) {
21460
21593
  try {
21461
21594
  const targetOwnerId = owner_id || session.user.id;
21462
- return await db_services.save_boards(session, scene_id, type, boardItems, targetOwnerId);
21595
+ return await db_services.save_boards(
21596
+ session,
21597
+ scene_id,
21598
+ type,
21599
+ boardItems,
21600
+ targetOwnerId
21601
+ );
21463
21602
  } catch (error) {
21464
21603
  console.error("Erro em save_boards_logic:", error);
21465
21604
  return { success: false, error: error.message };
@@ -21488,7 +21627,10 @@ async function delete_uploaded_file_logic(db_services, fileUrl) {
21488
21627
  async function get_view_members_logic(db_services, ownerId, type, itemId) {
21489
21628
  try {
21490
21629
  if (!db_services.get_view_members) {
21491
- return { success: false, error: "Servi\xE7o de busca de membros n\xE3o configurado." };
21630
+ return {
21631
+ success: false,
21632
+ error: "Servi\xE7o de busca de membros n\xE3o configurado."
21633
+ };
21492
21634
  }
21493
21635
  return await db_services.get_view_members(ownerId, type, itemId);
21494
21636
  } catch (error) {
package/dist/index.mjs CHANGED
@@ -15522,7 +15522,9 @@ function XViewScene({
15522
15522
  save_quest_action,
15523
15523
  delete_quest_action,
15524
15524
  save_quest_link_action,
15525
- delete_quest_link_action
15525
+ delete_quest_link_action,
15526
+ get_view_quests_and_links_action,
15527
+ migrate_legacy_quests_action
15526
15528
  }) {
15527
15529
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
15528
15530
  const { data: session, status } = useSession();
@@ -16081,7 +16083,7 @@ function XViewScene({
16081
16083
  obj.material.dispose();
16082
16084
  }
16083
16085
  }
16084
- Object.values(nodeObjects).forEach((mesh) => {
16086
+ Object.values(nodeObjects || {}).forEach((mesh) => {
16085
16087
  const oldLabel = mesh.getObjectByName("timelineLabel");
16086
16088
  if (oldLabel) {
16087
16089
  mesh.remove(oldLabel);
@@ -16105,7 +16107,7 @@ function XViewScene({
16105
16107
  }
16106
16108
  return null;
16107
16109
  };
16108
- Object.values(nodeObjects).forEach((mesh) => {
16110
+ Object.values(nodeObjects || {}).forEach((mesh) => {
16109
16111
  const dateProp = mesh.userData.Date;
16110
16112
  let nodeInfo = { mesh, type: "point", label: "", isUndated: true };
16111
16113
  if (dateProp) {
@@ -16386,19 +16388,40 @@ function XViewScene({
16386
16388
  focusAncestryId
16387
16389
  );
16388
16390
  const boardPromise = get_boards_action && session ? get_boards_action(configPath, sceneType, session, ownerId2) : Promise.resolve({ success: false, data: [] });
16389
- 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([
16390
16393
  scenePromise,
16391
- boardPromise
16394
+ boardPromise,
16395
+ questPromise
16392
16396
  ]);
16393
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) && Array.isArray(questResponse.quests) ? questResponse.quests : [];
16400
+ let firestoreLinks = (questResponse == null ? void 0 : questResponse.success) && Array.isArray(questResponse.links) ? 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
+ }
16394
16417
  if (focusNodeId) {
16395
16418
  let targetNode = sceneResponse.data.scene.nodes.find(
16396
16419
  (n) => String(n.id) === String(focusNodeId)
16397
16420
  );
16398
16421
  if (!targetNode) {
16399
16422
  const allParentNodes = Object.values(
16400
- sceneResponse.data.parent
16401
- ).flatMap((f) => f.nodes || []);
16423
+ sceneResponse.data.parent || {}
16424
+ ).flatMap((f) => (f == null ? void 0 : f.nodes) || []);
16402
16425
  targetNode = allParentNodes.find(
16403
16426
  (n) => String(n.id) === String(focusNodeId)
16404
16427
  );
@@ -16412,10 +16435,29 @@ function XViewScene({
16412
16435
  sceneResponse.data.scene.links = [];
16413
16436
  }
16414
16437
  sceneDataRef.current = {
16415
- ...sceneResponse.data.scene,
16416
- milestones: sceneResponse.data.scene.milestones || []
16438
+ ...sceneData,
16439
+ quests_migrated: sceneData.quests_migrated || false,
16440
+ milestones: sceneData.milestones || []
16417
16441
  };
16418
- 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;
16419
16461
  ancestryDataRef.current = sceneResponse.data.ancestry;
16420
16462
  console.log(
16421
16463
  "Console de sceneResponse.data.scene:",
@@ -16721,7 +16763,7 @@ function XViewScene({
16721
16763
  positionGroups.get(posKey).push(String(q.id));
16722
16764
  });
16723
16765
  });
16724
- Object.values(nodeObjects).forEach((mesh) => {
16766
+ Object.values(nodeObjects || {}).forEach((mesh) => {
16725
16767
  const oldLabel = mesh.getObjectByName("questDateLabel") || mesh.getObjectByName("timelineLabel");
16726
16768
  if (oldLabel) {
16727
16769
  mesh.remove(oldLabel);
@@ -18033,7 +18075,9 @@ function XViewScene({
18033
18075
  save_quest: save_quest_action,
18034
18076
  delete_quest: delete_quest_action,
18035
18077
  save_quest_link: save_quest_link_action,
18036
- delete_quest_link: delete_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
18037
18081
  }
18038
18082
  };
18039
18083
  },
@@ -18056,7 +18100,9 @@ function XViewScene({
18056
18100
  save_quest_action,
18057
18101
  delete_quest_action,
18058
18102
  save_quest_link_action,
18059
- delete_quest_link_action
18103
+ delete_quest_link_action,
18104
+ get_view_quests_and_links_action,
18105
+ migrate_legacy_quests_action
18060
18106
  ]
18061
18107
  );
18062
18108
  const handleStartVersioning = (nodeData) => {
@@ -18066,7 +18112,7 @@ function XViewScene({
18066
18112
  (questNode) => {
18067
18113
  var _a2, _b2, _c2;
18068
18114
  if (!questNode || !actionHandlerContext) return;
18069
- const allParentNodes = Object.values(parentDataRef.current).flatMap(
18115
+ const allParentNodes = Object.values(parentDataRef.current || {}).flatMap(
18070
18116
  (fileData) => fileData.nodes || []
18071
18117
  );
18072
18118
  const blockCheck = isQuestBlocked(questNode, allParentNodes);
@@ -18603,7 +18649,7 @@ function XViewScene({
18603
18649
  if (line.material) line.material.dispose();
18604
18650
  });
18605
18651
  }
18606
- const allParentNodes = Object.values(parentDataRef.current).flatMap(
18652
+ const allParentNodes = Object.values(parentDataRef.current || {}).flatMap(
18607
18653
  (fileData) => fileData.nodes
18608
18654
  );
18609
18655
  const allAncestries = ancestryDataRef.current || [];
@@ -18991,7 +19037,7 @@ function XViewScene({
18991
19037
  );
18992
19038
  if (!ancestryObject || !ancestryObject.abstraction_tree) return;
18993
19039
  const { ancestryGroup, nodeObjects, renderer, renderedAncestries } = stateRef.current;
18994
- const allParentNodes = Object.values(parentDataRef.current).flatMap(
19040
+ const allParentNodes = Object.values(parentDataRef.current || {}).flatMap(
18995
19041
  (f) => f.nodes
18996
19042
  );
18997
19043
  let fullTree = buildFullAncestryTree(
@@ -19079,7 +19125,7 @@ function XViewScene({
19079
19125
  const allAncestries = ancestryDataRef.current || [];
19080
19126
  const fullTree = buildFullAncestryTree(
19081
19127
  ancestry.tree,
19082
- Object.values(parentDataRef.current).flatMap((f) => f.nodes),
19128
+ Object.values(parentDataRef.current || {}).flatMap((f) => f.nodes),
19083
19129
  allAncestries
19084
19130
  );
19085
19131
  if (action === "open") {
@@ -19261,7 +19307,7 @@ function XViewScene({
19261
19307
  return null;
19262
19308
  const fullTree = buildFullAncestryTree(
19263
19309
  readingMode.ancestry.tree,
19264
- Object.values(parentDataRef.current).flatMap((f) => f.nodes),
19310
+ Object.values(parentDataRef.current || {}).flatMap((f) => f.nodes),
19265
19311
  ancestryDataRef.current
19266
19312
  );
19267
19313
  const findNodeInTree = (tree, targetId) => {
@@ -19326,7 +19372,7 @@ function XViewScene({
19326
19372
  }
19327
19373
  const fullTree = buildFullAncestryTree(
19328
19374
  readingMode.ancestry.tree,
19329
- Object.values(parentDataRef.current).flatMap((f) => f.nodes),
19375
+ Object.values(parentDataRef.current || {}).flatMap((f) => f.nodes),
19330
19376
  ancestryDataRef.current
19331
19377
  );
19332
19378
  let currentPtr = fullTree;
@@ -19423,7 +19469,7 @@ function XViewScene({
19423
19469
  let targetObj = ancestry;
19424
19470
  let targetTree = ancestry.tree;
19425
19471
  if (branchStack.length > 0) {
19426
- const allNodes = Object.values(parentDataRef.current).flatMap(
19472
+ const allNodes = Object.values(parentDataRef.current || {}).flatMap(
19427
19473
  (f) => f.nodes
19428
19474
  );
19429
19475
  const fullTree = buildFullAncestryTree(
@@ -19580,7 +19626,7 @@ function XViewScene({
19580
19626
  stateRef.current.maxAncestryRenderIndex = 0;
19581
19627
  const initialSections = /* @__PURE__ */ new Set(["preamble", 0]);
19582
19628
  await handleRenderAncestry(ancestryObject, initialSections);
19583
- const allParentNodes = Object.values(parentDataRef.current).flatMap(
19629
+ const allParentNodes = Object.values(parentDataRef.current || {}).flatMap(
19584
19630
  (fileData) => fileData.nodes
19585
19631
  );
19586
19632
  const allAncestries = ancestryDataRef.current || [];
@@ -20045,7 +20091,7 @@ function XViewScene({
20045
20091
  }, []);
20046
20092
  const allAvailableNodes = useMemo14(() => {
20047
20093
  if (!parentDataRef.current) return [];
20048
- return Object.values(parentDataRef.current).flatMap(
20094
+ return Object.values(parentDataRef.current || {}).flatMap(
20049
20095
  (fileData) => fileData.nodes || []
20050
20096
  );
20051
20097
  }, [sceneVersion, isInitialized]);
@@ -20134,7 +20180,7 @@ function XViewScene({
20134
20180
  if (!parentDataRef.current) {
20135
20181
  return [];
20136
20182
  }
20137
- const allTypes = Object.values(parentDataRef.current).flatMap(
20183
+ const allTypes = Object.values(parentDataRef.current || {}).flatMap(
20138
20184
  (fileData) => fileData.nodes.flatMap((node) => {
20139
20185
  if (Array.isArray(node.type)) return node.type;
20140
20186
  return [node.type];
@@ -20208,7 +20254,7 @@ function XViewScene({
20208
20254
  return;
20209
20255
  }
20210
20256
  if (!save_view_data) return;
20211
- const currentNodes = Object.values(nodeObjects).map((mesh) => {
20257
+ const currentNodes = Object.values(nodeObjects || {}).map((mesh) => {
20212
20258
  const {
20213
20259
  _baseEmissiveIntensity,
20214
20260
  labelObject,
@@ -20370,7 +20416,7 @@ function XViewScene({
20370
20416
  } = stateRef.current;
20371
20417
  if (graphGroup) {
20372
20418
  let ghostPosition = sceneControls.target.clone();
20373
- const existingNodes = Object.values(nodeObjects);
20419
+ const existingNodes = Object.values(nodeObjects || {});
20374
20420
  let isOccupied = true;
20375
20421
  let radius = 18;
20376
20422
  let angle = 0;
@@ -21113,20 +21159,35 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21113
21159
  if (!session || !session.user) {
21114
21160
  return { success: false, error: "Usu\xE1rio n\xE3o autenticado." };
21115
21161
  }
21116
- const membershipCheck = await db_services.check_membership(owner_id, type, scene_config, session.user.id);
21162
+ const membershipCheck = await db_services.check_membership(
21163
+ owner_id,
21164
+ type,
21165
+ scene_config,
21166
+ session.user.id
21167
+ );
21117
21168
  const isFullMember = membershipCheck.success && membershipCheck.isValidMember;
21118
21169
  if (!isFullMember && !focusNodeId && !focusAncestryId) {
21119
- return { success: false, error: "Acesso Negado: Voc\xEA n\xE3o possui permiss\xE3o para acessar este cen\xE1rio." };
21170
+ return {
21171
+ success: false,
21172
+ error: "Acesso Negado: Voc\xEA n\xE3o possui permiss\xE3o para acessar este cen\xE1rio."
21173
+ };
21120
21174
  }
21121
- const sceneResponse = await db_services.get_file(`x_view_scenes/${owner_id}/${scene_config}`);
21175
+ const sceneResponse = await db_services.get_file(
21176
+ `x_view_scenes/${owner_id}/${scene_config}`
21177
+ );
21122
21178
  if (!sceneResponse || !sceneResponse.success) {
21123
21179
  console.error("Falha ao buscar dados da cena:", sceneResponse == null ? void 0 : sceneResponse.error);
21124
- return { success: false, error: `N\xE3o foi poss\xEDvel carregar o arquivo da cena: ${scene_config}` };
21180
+ return {
21181
+ success: false,
21182
+ error: `N\xE3o foi poss\xEDvel carregar o arquivo da cena: ${scene_config}`
21183
+ };
21125
21184
  }
21126
21185
  const sceneData = sceneResponse.data;
21127
21186
  const parentDbObjects = sceneData.parent_dbs || [];
21128
21187
  if (type && type.toLowerCase().includes("database")) {
21129
- const selfExists = parentDbObjects.some((db) => String(db.db_id) === String(scene_config));
21188
+ const selfExists = parentDbObjects.some(
21189
+ (db) => String(db.db_id) === String(scene_config)
21190
+ );
21130
21191
  if (!selfExists) {
21131
21192
  parentDbObjects.push({ db_id: scene_config, owner_id });
21132
21193
  }
@@ -21135,13 +21196,18 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21135
21196
  const parentResponsesPromises = parentDbObjects.map(
21136
21197
  (db_info) => db_services.get_file(`x_view_dbs/${db_info.owner_id}/${db_info.db_id}`)
21137
21198
  );
21138
- const parentResponsesResults = await Promise.allSettled(parentResponsesPromises);
21199
+ const parentResponsesResults = await Promise.allSettled(
21200
+ parentResponsesPromises
21201
+ );
21139
21202
  const parentData = {};
21140
21203
  let currentQuestNodes = [];
21141
21204
  let currentQuestLinks = [];
21142
21205
  let currentMilestones = [];
21143
21206
  if (isView) {
21144
- const firestoreQuestsRes = await db_services.get_view_quests_and_links(owner_id, scene_config);
21207
+ const firestoreQuestsRes = await db_services.get_view_quests_and_links(
21208
+ owner_id,
21209
+ scene_config
21210
+ );
21145
21211
  const isMigrated = sceneData.quests_migrated === true;
21146
21212
  if (firestoreQuestsRes.success && (firestoreQuestsRes.data.nodes.length > 0 || isMigrated)) {
21147
21213
  currentQuestNodes = firestoreQuestsRes.data.nodes;
@@ -21149,14 +21215,20 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21149
21215
  currentMilestones = sceneData.milestones || [];
21150
21216
  } else {
21151
21217
  console.log(`Iniciando Lazy Migration para View ${scene_config}...`);
21152
- const legacyQuestsRes = await db_services.get_file(`x_view_quests/${owner_id}/${scene_config}`);
21218
+ const legacyQuestsRes = await db_services.get_file(
21219
+ `x_view_quests/${owner_id}/${scene_config}`
21220
+ );
21153
21221
  if (legacyQuestsRes.success && legacyQuestsRes.data) {
21154
21222
  const legacyData = legacyQuestsRes.data;
21155
21223
  currentQuestNodes = legacyData.nodes || [];
21156
21224
  currentQuestLinks = legacyData.links || [];
21157
21225
  currentMilestones = legacyData.milestones || [];
21158
21226
  sceneData.milestones = currentMilestones;
21159
- await db_services.migrate_legacy_quests(owner_id, scene_config, legacyData);
21227
+ await db_services.migrate_legacy_quests(
21228
+ owner_id,
21229
+ scene_config,
21230
+ legacyData
21231
+ );
21160
21232
  }
21161
21233
  }
21162
21234
  }
@@ -21179,15 +21251,21 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21179
21251
  links: currentQuestLinks
21180
21252
  };
21181
21253
  }
21182
- const allNodes = Object.values(parentData).flatMap((db) => db.nodes || []);
21183
- const allLinks = Object.values(parentData).flatMap((db) => db.links || []);
21184
- const parentNodeMap = new Map(allNodes.map((node) => [String(node.id), node]));
21185
- const parentLinkMap = new Map(allLinks.map((link) => [`${link.source}-${link.target}`, link]));
21254
+ const allNodes = Object.values(parentData).flatMap((db) => (db == null ? void 0 : db.nodes) || []);
21255
+ const allLinks = Object.values(parentData).flatMap((db) => (db == null ? void 0 : db.links) || []);
21256
+ const parentNodeMap = new Map(
21257
+ allNodes.map((node) => [String(node.id), node])
21258
+ );
21259
+ const parentLinkMap = new Map(
21260
+ allLinks.map((link) => [`${link.source}-${link.target}`, link])
21261
+ );
21186
21262
  const validatedNodes = (sceneData.nodes || []).map((sceneNode) => {
21187
21263
  var _a2, _b2;
21188
21264
  const nodeTypes = Array.isArray(sceneNode.type) ? sceneNode.type : [sceneNode.type];
21189
21265
  if (nodeTypes.includes("quest")) {
21190
- const dbQuestNode = (_b2 = (_a2 = parentData[scene_config]) == null ? void 0 : _a2.nodes) == null ? void 0 : _b2.find((qn) => String(qn.id) === String(sceneNode.id));
21266
+ const dbQuestNode = (_b2 = (_a2 = parentData[scene_config]) == null ? void 0 : _a2.nodes) == null ? void 0 : _b2.find(
21267
+ (qn) => String(qn.id) === String(sceneNode.id)
21268
+ );
21191
21269
  if (dbQuestNode) {
21192
21270
  return { ...sceneNode, ...dbQuestNode };
21193
21271
  }
@@ -21199,17 +21277,23 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21199
21277
  }
21200
21278
  return null;
21201
21279
  }).filter(Boolean);
21202
- const validNodeIdsInScene = new Set(validatedNodes.map((node) => String(node.id)));
21280
+ const validNodeIdsInScene = new Set(
21281
+ validatedNodes.map((node) => String(node.id))
21282
+ );
21203
21283
  const validatedLinks = (sceneData.links || []).filter((sceneLink) => {
21204
- const linkExistsInParent = parentLinkMap.has(`${sceneLink.source}-${sceneLink.target}`);
21284
+ const linkExistsInParent = parentLinkMap.has(
21285
+ `${sceneLink.source}-${sceneLink.target}`
21286
+ );
21205
21287
  const nodesAreValidForScene = validNodeIdsInScene.has(String(sceneLink.source)) && validNodeIdsInScene.has(String(sceneLink.target));
21206
21288
  return linkExistsInParent && nodesAreValidForScene;
21207
- }).map((sceneLink) => parentLinkMap.get(`${sceneLink.source}-${sceneLink.target}`));
21289
+ }).map(
21290
+ (sceneLink) => parentLinkMap.get(`${sceneLink.source}-${sceneLink.target}`)
21291
+ );
21208
21292
  const validatedSceneData = {
21209
21293
  ...sceneData,
21210
21294
  nodes: validatedNodes,
21211
21295
  links: validatedLinks,
21212
- // Re-injetando no validated para que o restante do sistema (e.g. XViewScene local state)
21296
+ // Re-injetando no validated para que o restante do sistema (e.g. XViewScene local state)
21213
21297
  // continue acessando as quests sem perceber a separação física
21214
21298
  quest_nodes: currentQuestNodes,
21215
21299
  quest_links: currentQuestLinks,
@@ -21230,7 +21314,9 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21230
21314
  isSceneFile: false
21231
21315
  });
21232
21316
  });
21233
- const ancestryPromises = ancestryFilePaths.map((file) => db_services.get_file(file.path));
21317
+ const ancestryPromises = ancestryFilePaths.map(
21318
+ (file) => db_services.get_file(file.path)
21319
+ );
21234
21320
  const ancestryResults = await Promise.allSettled(ancestryPromises);
21235
21321
  const ancestriesFromSceneFile = [];
21236
21322
  const ancestriesFromDbFiles = [];
@@ -21256,15 +21342,21 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21256
21342
  }
21257
21343
  });
21258
21344
  const ancestryMap = /* @__PURE__ */ new Map();
21259
- ancestriesFromDbFiles.forEach((anc) => ancestryMap.set(anc.ancestry_id, anc));
21260
- ancestriesFromSceneFile.forEach((anc) => ancestryMap.set(anc.ancestry_id, anc));
21345
+ ancestriesFromDbFiles.forEach(
21346
+ (anc) => ancestryMap.set(anc.ancestry_id, anc)
21347
+ );
21348
+ ancestriesFromSceneFile.forEach(
21349
+ (anc) => ancestryMap.set(anc.ancestry_id, anc)
21350
+ );
21261
21351
  let ancestryData = Array.from(ancestryMap.values());
21262
21352
  const externalSourcesToRefresh = /* @__PURE__ */ new Map();
21263
21353
  ancestryData.forEach((anc) => {
21264
21354
  const targetSourceId = anc._source_file_id || anc._imported_from_view_id;
21265
21355
  const targetOwnerId = anc._source_owner_id || anc._imported_from_view_owner_id;
21266
21356
  if (targetSourceId && targetSourceId !== scene_config && targetOwnerId) {
21267
- const isAlreadyLoadedAsParent = parentDbObjects.some((db) => String(db.db_id) === String(targetSourceId));
21357
+ const isAlreadyLoadedAsParent = parentDbObjects.some(
21358
+ (db) => String(db.db_id) === String(targetSourceId)
21359
+ );
21268
21360
  if (!isAlreadyLoadedAsParent) {
21269
21361
  const key = `${targetOwnerId}/${targetSourceId}`;
21270
21362
  externalSourcesToRefresh.set(key, {
@@ -21305,12 +21397,16 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21305
21397
  return false;
21306
21398
  }
21307
21399
  if (externalSourcesToRefresh.has(key) && successfullyFetchedSources.has(key)) {
21308
- const stillExists = freshAncestryMap.has(String(localAnc.ancestry_id));
21400
+ const stillExists = freshAncestryMap.has(
21401
+ String(localAnc.ancestry_id)
21402
+ );
21309
21403
  return stillExists;
21310
21404
  }
21311
21405
  return true;
21312
21406
  }).map((localAnc) => {
21313
- const freshVersion = freshAncestryMap.get(String(localAnc.ancestry_id));
21407
+ const freshVersion = freshAncestryMap.get(
21408
+ String(localAnc.ancestry_id)
21409
+ );
21314
21410
  if (freshVersion) {
21315
21411
  return {
21316
21412
  ...freshVersion,
@@ -21349,7 +21445,9 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21349
21445
  parallel_branches: validBranches
21350
21446
  };
21351
21447
  };
21352
- const originalAncestryDataString = JSON.stringify(Array.from(ancestryMap.values()));
21448
+ const originalAncestryDataString = JSON.stringify(
21449
+ Array.from(ancestryMap.values())
21450
+ );
21353
21451
  const cleanedAncestryData = ancestryData.map((ancestry) => {
21354
21452
  if (!parentNodeIds.has(String(ancestry.ancestral_node))) return null;
21355
21453
  const cleanedTree = pruneTree(ancestry.tree);
@@ -21369,7 +21467,10 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21369
21467
  try {
21370
21468
  await db_services.save_file(ancestryFilePath, ancestryData);
21371
21469
  } catch (saveError) {
21372
- console.error("Falha ao salvar o arquivo de ancestralidade da cena atualizado:", saveError);
21470
+ console.error(
21471
+ "Falha ao salvar o arquivo de ancestralidade da cena atualizado:",
21472
+ saveError
21473
+ );
21373
21474
  }
21374
21475
  }
21375
21476
  if (!isFullMember) {
@@ -21377,7 +21478,9 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21377
21478
  const requiredAncestryIds = /* @__PURE__ */ new Set();
21378
21479
  if (focusNodeId) requiredNodeIds.add(String(focusNodeId));
21379
21480
  if (focusAncestryId) requiredAncestryIds.add(String(focusAncestryId));
21380
- const allNodesFromDb = Object.values(parentData).flatMap((db) => db.nodes || []);
21481
+ const allNodesFromDb = Object.values(parentData).flatMap(
21482
+ (db) => db.nodes || []
21483
+ );
21381
21484
  const extractDependenciesFromText = (text) => {
21382
21485
  if (!text) return;
21383
21486
  const mentionRegex = /\[\[MENTION:node:([a-zA-Z0-9\-_]+)\]\]/g;
@@ -21404,9 +21507,12 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21404
21507
  if (branch.linked_ancestry_id) {
21405
21508
  requiredAncestryIds.add(String(branch.linked_ancestry_id));
21406
21509
  }
21407
- if (branch.description) extractDependenciesFromText(branch.description);
21510
+ if (branch.description)
21511
+ extractDependenciesFromText(branch.description);
21408
21512
  if (branch.description_sections) {
21409
- branch.description_sections.forEach((s) => extractDependenciesFromText(s.content));
21513
+ branch.description_sections.forEach(
21514
+ (s) => extractDependenciesFromText(s.content)
21515
+ );
21410
21516
  }
21411
21517
  extractTreeDependencies(branch.tree);
21412
21518
  });
@@ -21420,7 +21526,9 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21420
21526
  if (anc && !anc.is_private) {
21421
21527
  if (anc.description) extractDependenciesFromText(anc.description);
21422
21528
  if (anc.description_sections) {
21423
- anc.description_sections.forEach((s) => extractDependenciesFromText(s.content));
21529
+ anc.description_sections.forEach(
21530
+ (s) => extractDependenciesFromText(s.content)
21531
+ );
21424
21532
  }
21425
21533
  extractTreeDependencies(anc.tree);
21426
21534
  extractTreeDependencies(anc.abstraction_tree);
@@ -21431,22 +21539,38 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21431
21539
  if (node) {
21432
21540
  if (node.description) extractDependenciesFromText(node.description);
21433
21541
  if (node.description_sections) {
21434
- node.description_sections.forEach((s) => extractDependenciesFromText(s.content));
21542
+ node.description_sections.forEach(
21543
+ (s) => extractDependenciesFromText(s.content)
21544
+ );
21435
21545
  }
21436
21546
  }
21437
21547
  });
21438
21548
  } while (requiredNodeIds.size + requiredAncestryIds.size > previousSize);
21439
- const restrictedSceneData = { ...validatedSceneData, nodes: [], links: [] };
21549
+ const restrictedSceneData = {
21550
+ ...validatedSceneData,
21551
+ nodes: [],
21552
+ links: []
21553
+ };
21440
21554
  const restrictedParentData = {};
21441
- const restrictedAncestryData = ancestryData.filter((a) => requiredAncestryIds.has(String(a.ancestry_id)) && !a.is_private);
21555
+ const restrictedAncestryData = ancestryData.filter(
21556
+ (a) => requiredAncestryIds.has(String(a.ancestry_id)) && !a.is_private
21557
+ );
21442
21558
  for (const [dbId, dbContent] of Object.entries(parentData)) {
21443
- const filteredNodes = (dbContent.nodes || []).filter((n) => requiredNodeIds.has(String(n.id)));
21559
+ const filteredNodes = (dbContent.nodes || []).filter(
21560
+ (n) => requiredNodeIds.has(String(n.id))
21561
+ );
21444
21562
  if (filteredNodes.length > 0) {
21445
- restrictedParentData[dbId] = { ...dbContent, nodes: filteredNodes, links: [] };
21563
+ restrictedParentData[dbId] = {
21564
+ ...dbContent,
21565
+ nodes: filteredNodes,
21566
+ links: []
21567
+ };
21446
21568
  }
21447
21569
  }
21448
21570
  if (focusNodeId) {
21449
- const mainNode = allNodesFromDb.find((n) => String(n.id) === String(focusNodeId));
21571
+ const mainNode = allNodesFromDb.find(
21572
+ (n) => String(n.id) === String(focusNodeId)
21573
+ );
21450
21574
  if (mainNode) {
21451
21575
  restrictedSceneData.nodes = [mainNode];
21452
21576
  }
@@ -21462,7 +21586,11 @@ async function get_scene_view_data_logic(db_services, scene_config, owner_id, ty
21462
21586
  }
21463
21587
  return {
21464
21588
  success: true,
21465
- data: { scene: validatedSceneData, parent: parentData, ancestry: ancestryData }
21589
+ data: {
21590
+ scene: validatedSceneData,
21591
+ parent: parentData,
21592
+ ancestry: ancestryData
21593
+ }
21466
21594
  };
21467
21595
  } catch (error) {
21468
21596
  console.error("Erro em get_scene_view_data_logic:", error);
@@ -21482,13 +21610,18 @@ async function import_parent_file_modal_get_logic(db_services, session) {
21482
21610
  }
21483
21611
  };
21484
21612
  } catch (error) {
21485
- console.error("catch (error) em import_parent_file_modal_get_logic:", error);
21613
+ console.error(
21614
+ "catch (error) em import_parent_file_modal_get_logic:",
21615
+ error
21616
+ );
21486
21617
  return { success: false, error: error.message };
21487
21618
  }
21488
21619
  }
21489
21620
  async function get_single_parent_file_logic(db_services, file_id, session) {
21490
21621
  try {
21491
- const call_GCP_cloud_storage_get_file = await db_services.get_file(`x_view_dbs/${session.user.id}/${file_id}`);
21622
+ const call_GCP_cloud_storage_get_file = await db_services.get_file(
21623
+ `x_view_dbs/${session.user.id}/${file_id}`
21624
+ );
21492
21625
  return call_GCP_cloud_storage_get_file;
21493
21626
  } catch (error) {
21494
21627
  console.error("catch (error) em get_single_parent_file_logic:", error);
@@ -21522,7 +21655,13 @@ async function get_ancestry_file_logic(db_services, file_id, owner_id) {
21522
21655
  async function save_boards_logic(db_services, scene_id, type, boardItems, session, owner_id) {
21523
21656
  try {
21524
21657
  const targetOwnerId = owner_id || session.user.id;
21525
- return await db_services.save_boards(session, scene_id, type, boardItems, targetOwnerId);
21658
+ return await db_services.save_boards(
21659
+ session,
21660
+ scene_id,
21661
+ type,
21662
+ boardItems,
21663
+ targetOwnerId
21664
+ );
21526
21665
  } catch (error) {
21527
21666
  console.error("Erro em save_boards_logic:", error);
21528
21667
  return { success: false, error: error.message };
@@ -21551,7 +21690,10 @@ async function delete_uploaded_file_logic(db_services, fileUrl) {
21551
21690
  async function get_view_members_logic(db_services, ownerId, type, itemId) {
21552
21691
  try {
21553
21692
  if (!db_services.get_view_members) {
21554
- return { success: false, error: "Servi\xE7o de busca de membros n\xE3o configurado." };
21693
+ return {
21694
+ success: false,
21695
+ error: "Servi\xE7o de busca de membros n\xE3o configurado."
21696
+ };
21555
21697
  }
21556
21698
  return await db_services.get_view_members(ownerId, type, itemId);
21557
21699
  } catch (error) {
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.3",
3
+ "version": "1.2.8-dev.7",
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",
@@ -52,4 +52,4 @@
52
52
  "react-colorful": "^5.6.1",
53
53
  "uuid": "^13.0.0"
54
54
  }
55
- }
55
+ }