@unson/brainbase-mcp 0.50.26 → 0.50.28
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.
- package/package.json +2 -2
- package/ui/foundation-overview.js +3 -3
- package/ui/graph-projects-view.css +17 -0
- package/ui/graph-projects-view.js +224 -25
- package/ui/graph-registry-view.js +17 -17
- package/ui/graph-view-shared.js +50 -36
- package/ui/meeting-minutes.js +33 -21
- package/ui/objective-editor.js +6 -6
- package/ui/project-graph-entry.js +198 -19
- package/ui/project-graph.js +20 -0
- package/ui/project-overview.js +115 -3
- package/ui/project-workspace.css +132 -0
- package/ui/project-workspace.js +584 -44
- package/ui/workspace-kit.css +113 -3
- package/ui/workspace-kit.js +70 -9
package/ui/project-workspace.js
CHANGED
|
@@ -25,12 +25,12 @@ import {
|
|
|
25
25
|
typeLabel,
|
|
26
26
|
validityText,
|
|
27
27
|
} from './graph-view-shared.js';
|
|
28
|
-
import { workspaceDefinition, workspaceNotice } from './workspace-kit.js';
|
|
29
|
-
import { normalizeProjectOverview, renderProjectOverview } from './project-overview.js';
|
|
28
|
+
import { workspaceDefinition, workspaceNotice, workspaceCardRow, workspacePills, workspaceDotPill, workspaceSearchControl } from './workspace-kit.js';
|
|
29
|
+
import { normalizeProjectOverview, renderProjectOverview, renderProjectDetailOverview, renderProjectOverviewMaterials } from './project-overview.js';
|
|
30
30
|
|
|
31
31
|
export const PROJECT_WORKSPACE_CONTRACT_VERSION = 'brainbase.project-workspace.v1';
|
|
32
32
|
|
|
33
|
-
const CONTEXT_STATES = new Set(['ok', 'loading', 'unknown', 'unavailable', 'failed']);
|
|
33
|
+
const CONTEXT_STATES = new Set(['ok', 'partial', 'loading', 'unknown', 'unavailable', 'failed']);
|
|
34
34
|
|
|
35
35
|
function cleanId(value) {
|
|
36
36
|
return textOrNull(value);
|
|
@@ -64,11 +64,12 @@ function normalizeContextItem(item) {
|
|
|
64
64
|
const title = cleanName(item.title, item.name);
|
|
65
65
|
if (!id || !title) return null;
|
|
66
66
|
const normalized = { id, title };
|
|
67
|
-
for (const key of ['kind', 'status', 'statusKind', 'priority', 'summary', 'owner', 'assignee', 'dueAt', 'updatedAt', 'eventAt', 'body', 'description', 'sourceRecordId', 'relatedRecordId', 'relatedTaskId', 'sourcePath', 'provenance']) {
|
|
67
|
+
for (const key of ['kind', 'type', 'status', 'statusKind', 'priority', 'summary', 'owner', 'assignee', 'dueAt', 'updatedAt', 'eventAt', 'body', 'description', 'bodyState', 'contentAsOf', 'validFrom', 'validTo', 'relation', 'meaning', 'role', 'context', 'sourceRecordId', 'relatedRecordId', 'relatedTaskId', 'sourcePath', 'provenance']) {
|
|
68
68
|
const value = textOrNull(item[key]);
|
|
69
69
|
if (value) normalized[key] = value;
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
if (isRecord(item.provenance)) normalized.provenance = { ...item.provenance };
|
|
72
|
+
for (const key of ['recordIds', 'relatedTaskIds', 'unknowns']) {
|
|
72
73
|
if (Array.isArray(item[key])) {
|
|
73
74
|
const values = item[key].map((value) => textOrNull(value)).filter(Boolean);
|
|
74
75
|
if (values.length > 0) normalized[key] = values;
|
|
@@ -90,6 +91,8 @@ function normalizeContextSection(section) {
|
|
|
90
91
|
if (message) normalized.message = message;
|
|
91
92
|
const asOf = textOrNull(section.asOf);
|
|
92
93
|
if (asOf) normalized.asOf = asOf;
|
|
94
|
+
const source = sourceLabel(section.source);
|
|
95
|
+
if (source) normalized.source = source;
|
|
93
96
|
for (const key of ['total', 'totalCount', 'count']) {
|
|
94
97
|
const value = section[key];
|
|
95
98
|
if (Number.isFinite(value) || (typeof value === 'string' && /^\d+$/.test(value))) normalized[key] = Number(value);
|
|
@@ -104,8 +107,12 @@ function normalizeContextSection(section) {
|
|
|
104
107
|
*/
|
|
105
108
|
export function normalizeProjectContext(projectId, result) {
|
|
106
109
|
const id = cleanId(projectId) ?? '';
|
|
110
|
+
const cachedSections = () => {
|
|
111
|
+
const value = isRecord(result?.payload) ? result.payload : result;
|
|
112
|
+
return Array.isArray(value?.sections) ? value.sections.map(normalizeContextSection).filter(Boolean) : [];
|
|
113
|
+
};
|
|
107
114
|
if (result?.state === 'failed' || result?.state === 'error') {
|
|
108
|
-
return { projectId: id, state: 'failed', message: firstText(result.message, result.reason) ?? '補足情報を読み取れませんでした。', sections:
|
|
115
|
+
return { projectId: id, state: 'failed', message: firstText(result.message, result.reason) ?? '補足情報を読み取れませんでした。', sections: cachedSections() };
|
|
109
116
|
}
|
|
110
117
|
if (result?.state === 'loading') {
|
|
111
118
|
const partial = result?.payload && isRecord(result.payload) ? result.payload : result;
|
|
@@ -120,12 +127,12 @@ export function normalizeProjectContext(projectId, result) {
|
|
|
120
127
|
return normalized;
|
|
121
128
|
}
|
|
122
129
|
if (result?.state === 'unavailable') {
|
|
123
|
-
return { projectId: id, state: 'unavailable', message: firstText(result.message, result.reason) ?? '補足情報は接続されていません。', sections:
|
|
130
|
+
return { projectId: id, state: 'unavailable', message: firstText(result.message, result.reason) ?? '補足情報は接続されていません。', sections: cachedSections() };
|
|
124
131
|
}
|
|
125
132
|
if (result?.state === 'unknown') {
|
|
126
|
-
return { projectId: id, state: 'unknown', message: firstText(result.message, result.reason) ?? '補足情報の取得状態を確認できません。', sections:
|
|
133
|
+
return { projectId: id, state: 'unknown', message: firstText(result.message, result.reason) ?? '補足情報の取得状態を確認できません。', sections: cachedSections() };
|
|
127
134
|
}
|
|
128
|
-
const payload = result?.state
|
|
135
|
+
const payload = ['ok', 'partial'].includes(result?.state) && isRecord(result.payload) ? result.payload : result;
|
|
129
136
|
if (!isRecord(payload) || !Array.isArray(payload.sections)) {
|
|
130
137
|
return { projectId: id, state: 'unavailable', message: '補足情報の形式を確認できません。', sections: [] };
|
|
131
138
|
}
|
|
@@ -133,7 +140,8 @@ export function normalizeProjectContext(projectId, result) {
|
|
|
133
140
|
if (sections.length === 0 && payload.sections.length > 0) {
|
|
134
141
|
return { projectId: id, state: 'unavailable', message: '補足情報の形式を確認できません。', sections: [] };
|
|
135
142
|
}
|
|
136
|
-
|
|
143
|
+
const message = firstText(result?.message, payload.message);
|
|
144
|
+
return { projectId: id, state: sections.some((section) => section.state === 'loading') ? 'loading' : result?.state === 'partial' || sections.some(section => section.state === 'partial') ? 'partial' : 'ok', ...(message ? { message } : {}), sections };
|
|
137
145
|
}
|
|
138
146
|
|
|
139
147
|
function addEntity(map, candidate) {
|
|
@@ -245,6 +253,71 @@ function graphEvidenceEdges(detail) {
|
|
|
245
253
|
return projectKnowledgeEdges(detail);
|
|
246
254
|
}
|
|
247
255
|
|
|
256
|
+
const RECORD_TYPES = Object.freeze([
|
|
257
|
+
['', 'すべて'], ['person', '人物'], ['material', '資料'], ['decision', '判断'], ['knowledge', '知識'],
|
|
258
|
+
]);
|
|
259
|
+
const RECORD_COLOR_TOKENS = Object.freeze({
|
|
260
|
+
project: '--bb-color-action', person: '--bb-color-mint', material: '--bb-inbox-task-stripe',
|
|
261
|
+
decision: '--bb-color-review', knowledge: '--bb-color-action-hover', other: '--bb-color-muted',
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
function recordCategory(value) {
|
|
265
|
+
const type = String(value ?? '').toLowerCase();
|
|
266
|
+
if (['task', 'tasks', 'work', 'works', 'canonical_task'].includes(type)) return 'task';
|
|
267
|
+
if (['person', 'people', '人物'].includes(type)) return 'person';
|
|
268
|
+
if (['material', 'document', 'documents', 'evidence_document', 'source', 'artifact', '資料'].includes(type)) return 'material';
|
|
269
|
+
if (['decision', 'decisions', 'pendingdecisions', 'pending_decisions', 'judgment', 'judgments', 'judgement', 'judgements', '判断'].includes(type)) return 'decision';
|
|
270
|
+
if (['knowledge', 'glossary', 'term', 'terms', 'concept', '知識', '用語集'].includes(type)) return 'knowledge';
|
|
271
|
+
return type === 'project' ? 'project' : 'other';
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/** A directory of already supplied records, never an expansion of the Graph. */
|
|
275
|
+
export function projectKnowledgeRecordDirectory(detail, context, explored = []) {
|
|
276
|
+
const payload = projectDetailPayload(detail);
|
|
277
|
+
const projectId = payload?.project?.id;
|
|
278
|
+
const records = new Map();
|
|
279
|
+
const anonymousCounts = new Map();
|
|
280
|
+
const add = (candidate, { sectionId = null, sectionTitle = null, category = null, material = false, graph = false } = {}) => {
|
|
281
|
+
const id = cleanId(candidate?.id), name = firstText(candidate?.name, candidate?.title);
|
|
282
|
+
if (!name || id === projectId || (!id && !material)) return;
|
|
283
|
+
// This key identifies an unchanged UI row, never a canonical record. Keep
|
|
284
|
+
// its exact signature as well, so fresh payload restoration cannot select
|
|
285
|
+
// a different material merely because an index or hash was reused.
|
|
286
|
+
const signature = id ? null : JSON.stringify([sectionId, candidate], (_key, value) => isRecord(value) ? Object.fromEntries(Object.keys(value).sort().map(key => [key, value[key]])) : value);
|
|
287
|
+
let key = id;
|
|
288
|
+
if (!id) {
|
|
289
|
+
let hash = 2166136261;
|
|
290
|
+
for (const char of signature) hash = Math.imul(hash ^ char.charCodeAt(0), 16777619) >>> 0;
|
|
291
|
+
const occurrence = anonymousCounts.get(signature) ?? 0;
|
|
292
|
+
anonymousCounts.set(signature, occurrence + 1);
|
|
293
|
+
key = `material-ui:${hash.toString(16)}:${occurrence}`;
|
|
294
|
+
}
|
|
295
|
+
const candidateCategory = recordCategory(candidate.type ?? candidate.kind ?? sectionId);
|
|
296
|
+
const actualCategory = category ?? (candidateCategory === 'other' && sectionId ? recordCategory(sectionId) : candidateCategory);
|
|
297
|
+
if (actualCategory === 'task' || recordCategory(candidate.type ?? candidate.kind) === 'task') return;
|
|
298
|
+
let storeKey = id ? `record:${id}` : `anonymous:${key}`;
|
|
299
|
+
while (!id && records.has(storeKey) && records.get(storeKey).signature !== signature) { key += ':collision'; storeKey = `anonymous:${key}`; }
|
|
300
|
+
const existing = records.get(storeKey);
|
|
301
|
+
const entry = existing ?? { id, key, signature, name, type: candidate.type ?? candidate.kind ?? (material ? 'document' : sectionId) ?? 'unknown', category: actualCategory, directorySources: [] };
|
|
302
|
+
if (graph) Object.assign(entry, { ...candidate, id, name, category: actualCategory, directorySources: entry.directorySources });
|
|
303
|
+
else if (!existing) Object.assign(entry, candidate, { id, name });
|
|
304
|
+
if (!entry.directorySources.some(source => source.sectionId === sectionId && source.material === material && JSON.stringify(source.item) === JSON.stringify(candidate))) entry.directorySources.push({ item: candidate, sectionId, sectionTitle, material });
|
|
305
|
+
records.set(storeKey, entry);
|
|
306
|
+
};
|
|
307
|
+
for (const entity of projectKnowledgeEntities(payload)) add(entity, { graph: true });
|
|
308
|
+
const overview = normalizeProjectOverview(payload?.overview);
|
|
309
|
+
for (const [key, title] of [['directMaterials', '直接紐づく資料'], ['relatedMaterials', '関連資料']]) {
|
|
310
|
+
for (const item of overview?.[key]?.items ?? []) add(item, { sectionId: key, sectionTitle: title, category: 'material', material: true });
|
|
311
|
+
}
|
|
312
|
+
const taskSection = contextTaskSection(context);
|
|
313
|
+
for (const section of context?.sections ?? []) {
|
|
314
|
+
if (section === taskSection || recordCategory(section.id) === 'task') continue;
|
|
315
|
+
for (const item of section.items ?? []) add(item, { sectionId: section.id, sectionTitle: section.title });
|
|
316
|
+
}
|
|
317
|
+
for (const entity of explored instanceof Map ? explored.values() : explored) add(entity, { graph: true });
|
|
318
|
+
return [...records.values()];
|
|
319
|
+
}
|
|
320
|
+
|
|
248
321
|
/**
|
|
249
322
|
* Keep overview-only canonical IDs available for the existing detail action.
|
|
250
323
|
* These are loading placeholders, not Graph entities or inferred relations;
|
|
@@ -299,11 +372,11 @@ function recordLink(doc, label, id, onSelect, className = 'bb-pkw-record-link')
|
|
|
299
372
|
return button;
|
|
300
373
|
}
|
|
301
374
|
|
|
302
|
-
function relationEvidence(doc, edges, entityId, entities, asOf, onSelect) {
|
|
303
|
-
const list = makeElement(doc, 'ul', { className:
|
|
375
|
+
function relationEvidence(doc, edges, entityId, entities, asOf, onSelect, detailTitle = '記録の詳細', compact = false, emptyText = 'この画面で確認できる関係はありません。', rawEndpoints = false) {
|
|
376
|
+
const list = makeElement(doc, 'ul', { className: `bb-pkw-evidence-list${compact ? ' bb-pkw-root-relations' : ''}` });
|
|
304
377
|
const incident = edges.filter((edge) => edge.source === entityId || edge.target === entityId);
|
|
305
378
|
if (incident.length === 0) {
|
|
306
|
-
list.append(makeElement(doc, 'li', { className: 'bb-pkw-muted', text:
|
|
379
|
+
list.append(makeElement(doc, 'li', { className: 'bb-pkw-muted', text: emptyText }));
|
|
307
380
|
return list;
|
|
308
381
|
}
|
|
309
382
|
for (const edge of incident) {
|
|
@@ -312,6 +385,13 @@ function relationEvidence(doc, edges, entityId, entities, asOf, onSelect) {
|
|
|
312
385
|
const item = makeElement(doc, 'li', { className: 'bb-pkw-evidence-item' });
|
|
313
386
|
const head = makeElement(doc, 'div', { className: 'bb-pkw-evidence-head' });
|
|
314
387
|
head.append(badge(doc, relationLabel(edge.relation), 'muted'), recordLink(doc, other?.name ?? otherId, otherId, onSelect));
|
|
388
|
+
if (compact) {
|
|
389
|
+
const link = recordLink(doc, '', otherId, onSelect);
|
|
390
|
+
const dot = makeElement(doc, 'i', { attrs: { 'aria-hidden': 'true' } });
|
|
391
|
+
dot.style?.setProperty?.('background-color', `var(${RECORD_COLOR_TOKENS[recordCategory(other?.type)] ?? RECORD_COLOR_TOKENS.other})`);
|
|
392
|
+
link.append(dot, makeElement(doc, 'span', { text: other?.name ?? otherId }), makeElement(doc, 'small', { text: relationLabel(edge.relation) }));
|
|
393
|
+
item.append(link); list.append(item); continue;
|
|
394
|
+
}
|
|
315
395
|
if (edge.active !== undefined) head.append(activityBadge(doc, edge, asOf));
|
|
316
396
|
item.append(head);
|
|
317
397
|
item.append(workspaceDefinition(doc, [
|
|
@@ -321,7 +401,7 @@ function relationEvidence(doc, edges, entityId, entities, asOf, onSelect) {
|
|
|
321
401
|
['有効期間', validityText(edge.validFrom, edge.validTo)],
|
|
322
402
|
['出典', isRecord(edge.provenance) ? renderProvenance(doc, edge.provenance) : null],
|
|
323
403
|
]));
|
|
324
|
-
item.append(recordDetails(doc, [['関係ID', edge.id], ['起点', edge.source], ['終点', edge.target], ['digest', edge.digest]]));
|
|
404
|
+
item.append(recordDetails(doc, [['関係ID', edge.id], ['起点', rawEndpoints ? firstText(edge.fromId, edge.from_id, edge.rawSource, edge.source) : edge.source], ['終点', rawEndpoints ? firstText(edge.toId, edge.to_id, edge.rawTarget, edge.target) : edge.target], ['digest', edge.digest]], { title: detailTitle }));
|
|
325
405
|
list.append(item);
|
|
326
406
|
}
|
|
327
407
|
return list;
|
|
@@ -1205,12 +1285,25 @@ export function createProjectKnowledgeWorkspace({
|
|
|
1205
1285
|
readEntity,
|
|
1206
1286
|
onTabChange,
|
|
1207
1287
|
onRetryProject,
|
|
1288
|
+
detailPresentation,
|
|
1289
|
+
hostTabs = [],
|
|
1290
|
+
renderTabTools,
|
|
1291
|
+
overview: overviewConfig = {},
|
|
1292
|
+
recordNavigation = {},
|
|
1293
|
+
initialViewState,
|
|
1208
1294
|
} = {}) {
|
|
1209
1295
|
const doc = getDocument(explicitDocument);
|
|
1210
1296
|
const payload = projectDetailPayload(detail);
|
|
1211
1297
|
const project = payload?.project;
|
|
1212
1298
|
if (!project) throw new TypeError('project detail is required');
|
|
1213
1299
|
const workspaceProjectId = cleanId(project.id);
|
|
1300
|
+
const tabbedDetail = detailPresentation === 'tabs';
|
|
1301
|
+
const extraTabs = [];
|
|
1302
|
+
const tabIds = new Set(['overview', 'graph']);
|
|
1303
|
+
for (const tab of Array.isArray(hostTabs) ? hostTabs : []) {
|
|
1304
|
+
if (!tab || typeof tab.id !== 'string' || !/^[a-z][a-z0-9-]*$/u.test(tab.id) || tabIds.has(tab.id) || typeof tab.label !== 'string' || !tab.label.trim() || typeof tab.render !== 'function') continue;
|
|
1305
|
+
tabIds.add(tab.id); extraTabs.push(tab);
|
|
1306
|
+
}
|
|
1214
1307
|
// Keep the project-bound projection separate from the mutable exploration
|
|
1215
1308
|
// graph. Reading a related entity may reveal arbitrary neighboring records,
|
|
1216
1309
|
// but those records are not evidence that they belong to this project.
|
|
@@ -1218,11 +1311,28 @@ export function createProjectKnowledgeWorkspace({
|
|
|
1218
1311
|
const overviewEdges = graphEvidenceEdges(payload);
|
|
1219
1312
|
const overviewProjectionRecords = projectOverviewProjectionRecords(normalizeProjectOverview(payload?.overview));
|
|
1220
1313
|
const entities = new Map(overviewEntities);
|
|
1221
|
-
|
|
1314
|
+
function canonicalRootId() {
|
|
1315
|
+
if (!tabbedDetail || typeof recordNavigation.resolveProjectRecordId !== 'function') return null;
|
|
1316
|
+
try { return cleanId(recordNavigation.resolveProjectRecordId(project.id)); } catch { return null; }
|
|
1317
|
+
}
|
|
1318
|
+
function displayRecordId(id, rootId = canonicalRootId()) { return rootId && id === rootId ? project.id : id; }
|
|
1319
|
+
function displayEdge(edge) {
|
|
1320
|
+
const rootId = canonicalRootId();
|
|
1321
|
+
const source = displayRecordId(edge.source, rootId), target = displayRecordId(edge.target, rootId);
|
|
1322
|
+
return source === edge.source && target === edge.target ? edge : { ...edge, rawSource: edge.source, rawTarget: edge.target, source, target };
|
|
1323
|
+
}
|
|
1324
|
+
const edges = overviewEdges.map(displayEdge);
|
|
1222
1325
|
let destroyed = false;
|
|
1326
|
+
let hostTabHandle = null;
|
|
1223
1327
|
let selectedId = project.id;
|
|
1224
1328
|
let activeTab = 'overview';
|
|
1225
1329
|
let graphHandle = null;
|
|
1330
|
+
let graphCameraState = null;
|
|
1331
|
+
const graphFreshNodeIds = new Set();
|
|
1332
|
+
let graphResetPending = false;
|
|
1333
|
+
let graphEntryReveal = false;
|
|
1334
|
+
let graphRevealState = null;
|
|
1335
|
+
let pendingGraphFocus = null;
|
|
1226
1336
|
let graphTimer = null;
|
|
1227
1337
|
let graphMountToken = 0;
|
|
1228
1338
|
let graphFailure = null;
|
|
@@ -1230,6 +1340,22 @@ export function createProjectKnowledgeWorkspace({
|
|
|
1230
1340
|
let entityReadRequest = 0;
|
|
1231
1341
|
let graphSearch = '';
|
|
1232
1342
|
let graphType = '';
|
|
1343
|
+
let selectedAnonymous = null;
|
|
1344
|
+
if (initialViewState?.projectId === workspaceProjectId) {
|
|
1345
|
+
graphCameraState = initialViewState.graphCameraState ?? null;
|
|
1346
|
+
graphRevealState = initialViewState.graphRevealState ?? null;
|
|
1347
|
+
if (initialViewState.focusNodeId && entities.has(initialViewState.focusNodeId)) pendingGraphFocus = { nodeId: initialViewState.focusNodeId };
|
|
1348
|
+
if (tabIds.has(initialViewState.activeTab)) activeTab = initialViewState.activeTab;
|
|
1349
|
+
const requested = cleanId(initialViewState.selectedId);
|
|
1350
|
+
if (entities.has(requested) || overviewProjectionRecords.has(requested) || (tabbedDetail && projectKnowledgeRecordDirectory(payload, context).some(record => record.id === requested))) selectedId = requested;
|
|
1351
|
+
if (typeof initialViewState.graphSearch === 'string') graphSearch = initialViewState.graphSearch;
|
|
1352
|
+
if (typeof initialViewState.graphType === 'string' && (!tabbedDetail || RECORD_TYPES.some(([value]) => value === initialViewState.graphType))) graphType = initialViewState.graphType;
|
|
1353
|
+
const anonymous = initialViewState.selectedAnonymous;
|
|
1354
|
+
if (tabbedDetail && anonymous) {
|
|
1355
|
+
if (projectKnowledgeRecordDirectory(payload, context).some(record => !record.id && record.key === anonymous.key && record.signature === anonymous.signature)) selectedAnonymous = { ...anonymous };
|
|
1356
|
+
else selectedId = project.id;
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1233
1359
|
let currentContext = context;
|
|
1234
1360
|
let activeView = 'overview';
|
|
1235
1361
|
let selectedContextId = null;
|
|
@@ -1243,9 +1369,14 @@ export function createProjectKnowledgeWorkspace({
|
|
|
1243
1369
|
// intentionally has no querySelector implementation, and a host can replace
|
|
1244
1370
|
// the panel while a detail read is still in flight.
|
|
1245
1371
|
let selectedPanel = null;
|
|
1372
|
+
let recordTypeControls = null;
|
|
1373
|
+
let recordTypeSignature = '';
|
|
1374
|
+
let recordCount = null;
|
|
1375
|
+
let recordStates = null;
|
|
1376
|
+
let graphExit = null;
|
|
1246
1377
|
|
|
1247
1378
|
const root = makeElement(doc, 'section', {
|
|
1248
|
-
className: 'bb-pkw'
|
|
1379
|
+
className: `bb-pkw${tabbedDetail ? ' bb-pkw--tabbed-detail' : ''}`,
|
|
1249
1380
|
attrs: {
|
|
1250
1381
|
'data-contract-version': PROJECT_WORKSPACE_CONTRACT_VERSION,
|
|
1251
1382
|
'data-project-id': cleanId(project.id),
|
|
@@ -1254,21 +1385,28 @@ export function createProjectKnowledgeWorkspace({
|
|
|
1254
1385
|
});
|
|
1255
1386
|
const body = makeElement(doc, 'div', { className: 'bb-pkw-body' });
|
|
1256
1387
|
const tabs = makeElement(doc, 'div', { className: 'bb-pkw-tabs', attrs: { role: 'tablist', 'aria-label': 'プロジェクト情報の表示' } });
|
|
1257
|
-
const tabStrip = workspaceTabStrip(tabs);
|
|
1388
|
+
const tabStrip = workspaceTabStrip(tabs, tabbedDetail ? { appearance: 'header' } : {});
|
|
1258
1389
|
const panels = makeElement(doc, 'div', { className: 'bb-pkw-panels' });
|
|
1259
|
-
root.append(makeElement(doc, 'div', { className: 'bb-pkw-kicker', text: 'プロジェクトの記録' }));
|
|
1390
|
+
if (!tabbedDetail) root.append(makeElement(doc, 'div', { className: 'bb-pkw-kicker', text: 'プロジェクトの記録' }));
|
|
1260
1391
|
const header = makeElement(doc, 'header', { className: 'bb-pkw-header' });
|
|
1261
1392
|
header.append(makeElement(doc, 'h2', { text: project.name }), makeElement(doc, 'p', { className: 'bb-pkw-lead', text: '目的・関係・判断の根拠を、実際に記録された情報からたどれます。' }));
|
|
1262
1393
|
const metadata = makeElement(doc, 'div', { className: 'bb-pkw-meta' });
|
|
1263
1394
|
if (sourceLabel(payload.source)) metadata.append(badge(doc, `出典: ${sourceLabel(payload.source)}`, 'muted'));
|
|
1264
1395
|
if (payload.asOf) metadata.append(badge(doc, `読み取り: ${formatDateTime(payload.asOf)}`, 'muted'));
|
|
1265
1396
|
header.append(metadata);
|
|
1266
|
-
root.append(header);
|
|
1267
|
-
|
|
1268
|
-
|
|
1397
|
+
if (!tabbedDetail) root.append(header);
|
|
1398
|
+
const tabRow = makeElement(doc, 'div', { className: 'bb-pkw-tab-row' });
|
|
1399
|
+
const tools = makeElement(doc, 'div', { className: 'bb-pkw-tab-tools bb-ws-topbar-tools' });
|
|
1400
|
+
if (tabbedDetail || typeof renderTabTools === 'function') {
|
|
1401
|
+
tabRow.append(tabs, tools);
|
|
1402
|
+
root.append(tabRow, panels);
|
|
1403
|
+
} else root.append(tabs, panels);
|
|
1404
|
+
if (!tabbedDetail) root.append(body);
|
|
1269
1405
|
|
|
1270
1406
|
function setTab(tab) {
|
|
1271
|
-
|
|
1407
|
+
if (destroyed || !tabIds.has(tab)) return;
|
|
1408
|
+
activeTab = tab;
|
|
1409
|
+
if (tabbedDetail && tab === 'graph') resetDetailedGraphEntry();
|
|
1272
1410
|
if (activeTab === 'overview') {
|
|
1273
1411
|
activeView = 'overview';
|
|
1274
1412
|
selectedContextId = null;
|
|
@@ -1277,6 +1415,13 @@ export function createProjectKnowledgeWorkspace({
|
|
|
1277
1415
|
render();
|
|
1278
1416
|
}
|
|
1279
1417
|
|
|
1418
|
+
function resetDetailedGraphEntry() {
|
|
1419
|
+
selectedId = project.id; selectedAnonymous = null; entityRead = null; entityReadRequest += 1;
|
|
1420
|
+
graphSearch = ''; graphType = ''; graphCameraState = null; graphResetPending = true; graphEntryReveal = true; graphRevealState = null; pendingGraphFocus = null;
|
|
1421
|
+
graphFreshNodeIds.clear();
|
|
1422
|
+
for (const id of entities.keys()) if (id !== project.id) graphFreshNodeIds.add(id);
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1280
1425
|
function findContextItem(id, kind = null) {
|
|
1281
1426
|
const target = cleanId(id);
|
|
1282
1427
|
if (!target) return null;
|
|
@@ -1304,6 +1449,8 @@ export function createProjectKnowledgeWorkspace({
|
|
|
1304
1449
|
|
|
1305
1450
|
function openSectionList(id) {
|
|
1306
1451
|
if (destroyed) return;
|
|
1452
|
+
if (tabbedDetail && id !== 'tasks') { activeTab = 'graph'; const category = recordCategory(id); graphType = RECORD_TYPES.some(([value]) => value === category) ? category : ''; render(); return; }
|
|
1453
|
+
if (tabbedDetail && id === 'tasks' && tabIds.has('work')) { setTab('work'); return; }
|
|
1307
1454
|
if (id === 'tasks') return openWorkList();
|
|
1308
1455
|
activeTab = 'overview';
|
|
1309
1456
|
activeView = 'record-list';
|
|
@@ -1314,6 +1461,7 @@ export function createProjectKnowledgeWorkspace({
|
|
|
1314
1461
|
|
|
1315
1462
|
function openWorkDetail(id) {
|
|
1316
1463
|
if (destroyed) return;
|
|
1464
|
+
if (tabbedDetail && typeof recordNavigation.onOpenTask === 'function') { recordNavigation.onOpenTask(id, project.id); return; }
|
|
1317
1465
|
activeTab = 'overview';
|
|
1318
1466
|
activeView = 'work-detail';
|
|
1319
1467
|
selectedContextId = cleanId(id);
|
|
@@ -1322,6 +1470,7 @@ export function createProjectKnowledgeWorkspace({
|
|
|
1322
1470
|
|
|
1323
1471
|
function openRecordDetail(id) {
|
|
1324
1472
|
if (destroyed) return;
|
|
1473
|
+
if (tabbedDetail) { selectAndExplore(id); return; }
|
|
1325
1474
|
activeTab = 'overview';
|
|
1326
1475
|
activeView = 'record-detail';
|
|
1327
1476
|
selectedContextId = cleanId(id);
|
|
@@ -1332,39 +1481,58 @@ export function createProjectKnowledgeWorkspace({
|
|
|
1332
1481
|
|
|
1333
1482
|
function mergeEntityRead(read) {
|
|
1334
1483
|
if (!isRecord(read?.entity)) return;
|
|
1335
|
-
|
|
1484
|
+
const previousIds = tabbedDetail ? new Set(entities.keys()) : null;
|
|
1485
|
+
const canonicalRoot = canonicalRootId();
|
|
1486
|
+
if (!canonicalRoot || read.entity.id !== canonicalRoot || canonicalRoot === project.id) addEntity(entities, read.entity);
|
|
1487
|
+
else if (selectedId === canonicalRoot) selectedId = project.id;
|
|
1336
1488
|
for (const edge of [...(read.incoming ?? []), ...(read.outgoing ?? [])]) {
|
|
1337
|
-
|
|
1489
|
+
const counterpart = counterpartEntity(edge);
|
|
1490
|
+
if (!canonicalRoot || counterpart?.id !== canonicalRoot) addEntity(entities, counterpart);
|
|
1338
1491
|
const id = cleanId(edge?.id);
|
|
1339
1492
|
const { source, target } = edgeSourceTarget(edge, read.entity.id);
|
|
1340
1493
|
if (!id || !source || !target || edges.some((candidate) => candidate.id === id)) continue;
|
|
1341
|
-
edges.push({ ...edge, id, source, target, relation: cleanId(edge.relation) ?? 'unknown', label: edgeLabel(edge) });
|
|
1494
|
+
edges.push(displayEdge({ ...edge, id, source, target, relation: cleanId(edge.relation) ?? 'unknown', label: edgeLabel(edge) }));
|
|
1342
1495
|
}
|
|
1496
|
+
if (previousIds) for (const id of entities.keys()) if (!previousIds.has(id)) graphFreshNodeIds.add(id);
|
|
1343
1497
|
}
|
|
1344
1498
|
|
|
1345
1499
|
function select(id, { fromGraph = false } = {}) {
|
|
1346
|
-
const target = cleanId(id);
|
|
1347
|
-
const canReadOverviewProjection = overviewProjectionRecords.has(target) && typeof readEntity === 'function';
|
|
1500
|
+
const target = displayRecordId(cleanId(id));
|
|
1501
|
+
const canReadOverviewProjection = (overviewProjectionRecords.has(target) && typeof readEntity === 'function') || (tabbedDetail && directoryEntries().some(record => record.id === target));
|
|
1348
1502
|
if (!target || (!entities.has(target) && !canReadOverviewProjection) || destroyed) return;
|
|
1503
|
+
const hadAnonymous = selectedAnonymous !== null;
|
|
1504
|
+
selectedAnonymous = null;
|
|
1349
1505
|
// A list click synchronizes Sigma by calling its `select`, which notifies
|
|
1350
1506
|
// this workspace again. Keep the second notification from starting a
|
|
1351
1507
|
// duplicate entity read (or resetting a completed detail read).
|
|
1352
1508
|
if (selectedId === target) {
|
|
1353
|
-
if (
|
|
1509
|
+
if (hadAnonymous) { renderGraphList(); renderSelectedPanel(); }
|
|
1510
|
+
if (!fromGraph && graphHandle?.select && (!tabbedDetail || entities.has(target))) graphHandle.select(target);
|
|
1511
|
+
if (hadAnonymous && target !== project.id && typeof readEntity === 'function' && entityRead?.id !== target) void loadEntity(target);
|
|
1512
|
+
if (tabbedDetail && entityRead?.id === target && entityRead.state === 'failed' && typeof readEntity === 'function') void loadEntity(target);
|
|
1354
1513
|
return;
|
|
1355
1514
|
}
|
|
1356
1515
|
selectedId = target;
|
|
1357
1516
|
entityRead = null;
|
|
1358
1517
|
renderGraphList();
|
|
1359
1518
|
renderSelectedPanel();
|
|
1360
|
-
if (!fromGraph && graphHandle?.select) graphHandle.select(target);
|
|
1519
|
+
if (!fromGraph && graphHandle?.select && (!tabbedDetail || entities.has(target))) graphHandle.select(target);
|
|
1361
1520
|
if (target !== project.id && typeof readEntity === 'function') void loadEntity(target);
|
|
1362
1521
|
}
|
|
1363
1522
|
|
|
1523
|
+
function selectAnonymous(record) {
|
|
1524
|
+
if (destroyed || record.id) return;
|
|
1525
|
+
selectedAnonymous = { key: record.key, signature: record.signature };
|
|
1526
|
+
entityReadRequest += 1;
|
|
1527
|
+
entityRead = null;
|
|
1528
|
+
renderGraphList(); renderSelectedPanel();
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1364
1531
|
function selectAndExplore(id) {
|
|
1365
|
-
const target = cleanId(id);
|
|
1366
|
-
const canReadOverviewProjection = overviewProjectionRecords.has(target) && typeof readEntity === 'function';
|
|
1532
|
+
const target = displayRecordId(cleanId(id));
|
|
1533
|
+
const canReadOverviewProjection = (overviewProjectionRecords.has(target) && typeof readEntity === 'function') || (tabbedDetail && directoryEntries().some(record => record.id === target));
|
|
1367
1534
|
if (!target || (!entities.has(target) && !canReadOverviewProjection) || destroyed) return;
|
|
1535
|
+
if (tabbedDetail && activeTab === 'overview') resetDetailedGraphEntry();
|
|
1368
1536
|
activeTab = 'graph';
|
|
1369
1537
|
select(target);
|
|
1370
1538
|
render();
|
|
@@ -1379,6 +1547,7 @@ export function createProjectKnowledgeWorkspace({
|
|
|
1379
1547
|
function renderGraphList() {
|
|
1380
1548
|
const list = root.querySelector?.('.bb-pkw-graph-list') ?? graphList;
|
|
1381
1549
|
if (!list) return;
|
|
1550
|
+
if (tabbedDetail) { renderRecordDirectory(list); return; }
|
|
1382
1551
|
list.replaceChildren();
|
|
1383
1552
|
const visible = filteredGraphEntities();
|
|
1384
1553
|
if (visible.length === 0) {
|
|
@@ -1397,6 +1566,164 @@ export function createProjectKnowledgeWorkspace({
|
|
|
1397
1566
|
|
|
1398
1567
|
const graphList = makeElement(doc, 'ul', { className: 'bb-pkw-graph-list', attrs: { 'aria-label': 'グラフの記録一覧' } });
|
|
1399
1568
|
|
|
1569
|
+
function graphFocusSnapshot() {
|
|
1570
|
+
const focused = doc.activeElement;
|
|
1571
|
+
let node = focused;
|
|
1572
|
+
while (node && node !== root) node = node.parentNode;
|
|
1573
|
+
if (node !== root) return null;
|
|
1574
|
+
if (focused?.getAttribute?.('data-graph-node-id')) return { nodeId: focused.getAttribute('data-graph-node-id') };
|
|
1575
|
+
if (focused?.getAttribute?.('name') === 'project-record-search') return { search: true, start: focused.selectionStart, end: focused.selectionEnd };
|
|
1576
|
+
const row = focused?.closest?.('.bb-pkw-record-row');
|
|
1577
|
+
if (row) return { key: row.getAttribute('data-key') };
|
|
1578
|
+
const filter = recordTypeControls ? Array.from(recordTypeControls.children).indexOf(focused) : -1;
|
|
1579
|
+
if (filter >= 0) return { filter };
|
|
1580
|
+
if (focused?.getAttribute?.('role') === 'tab') return { tab: focused.getAttribute('aria-controls') };
|
|
1581
|
+
if (focused?.getAttribute?.('data-record-id')) return { key: selectedId };
|
|
1582
|
+
return null;
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
function restoreGraphFocus(snapshot) {
|
|
1586
|
+
if (!snapshot) return;
|
|
1587
|
+
const nodes = selector => Array.from(root.querySelectorAll?.(selector) ?? []);
|
|
1588
|
+
let target;
|
|
1589
|
+
if (snapshot.nodeId) target = nodes('[data-graph-node-id]').find(node => node.getAttribute('data-graph-node-id') === snapshot.nodeId);
|
|
1590
|
+
else if (snapshot.search) target = root.querySelector?.('[name="project-record-search"]');
|
|
1591
|
+
else if (snapshot.key) target = nodes('.bb-pkw-record-row').find(row => row.getAttribute('data-key') === snapshot.key);
|
|
1592
|
+
else if (snapshot.filter !== undefined) target = recordTypeControls?.children[snapshot.filter];
|
|
1593
|
+
else if (snapshot.tab) target = nodes('[role="tab"]').find(tab => tab.getAttribute('aria-controls') === snapshot.tab);
|
|
1594
|
+
target?.focus?.({ preventScroll: true });
|
|
1595
|
+
if (snapshot.nodeId) pendingGraphFocus = target ? null : snapshot;
|
|
1596
|
+
if (snapshot.search && typeof snapshot.start === 'number' && typeof target?.setSelectionRange === 'function') target.setSelectionRange(snapshot.start, snapshot.end);
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
function directoryEntries() { return projectKnowledgeRecordDirectory(payload, currentContext, entities); }
|
|
1600
|
+
|
|
1601
|
+
function recordSourceCertainty() {
|
|
1602
|
+
const complete = source => source?.state === 'ok' && explicitSectionTotal(source) === (source.items?.length ?? 0);
|
|
1603
|
+
const overview = normalizeProjectOverview(payload.overview);
|
|
1604
|
+
const sections = (currentContext?.sections ?? []).filter(section => section !== contextTaskSection(currentContext) && recordCategory(section.id) !== 'task');
|
|
1605
|
+
const byCategory = category => sections.filter(section => recordCategory(section.id) === category || section.items?.some(item => recordCategory(item.type ?? item.kind) === category));
|
|
1606
|
+
const contextComplete = category => currentContext?.state === 'ok' && byCategory(category).length > 0 && byCategory(category).every(complete);
|
|
1607
|
+
const snapshot = denseParticipantSnapshot(payload);
|
|
1608
|
+
const people = new Set((payload.participants ?? []).map(edge => edge.counterpart?.id).filter(Boolean));
|
|
1609
|
+
const known = {
|
|
1610
|
+
person: !snapshot.uncertain && (snapshot.confirmedEmpty || Number.isInteger(project.participantCount) && project.participantCount === people.size),
|
|
1611
|
+
material: complete(overview?.directMaterials) && complete(overview?.relatedMaterials) && byCategory('material').every(complete),
|
|
1612
|
+
knowledge: contextComplete('knowledge'), decision: contextComplete('decision'),
|
|
1613
|
+
};
|
|
1614
|
+
known.all = Object.values(known).every(Boolean) && currentContext?.state === 'ok' && sections.every(complete);
|
|
1615
|
+
return known;
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
function recordTypeItems(entries) {
|
|
1619
|
+
const known = recordSourceCertainty();
|
|
1620
|
+
return RECORD_TYPES.map(([value, label]) => {
|
|
1621
|
+
const count = value ? entries.filter(record => record.category === value).length : entries.length;
|
|
1622
|
+
return { value, label, count: count > 0 || known[value || 'all'] ? count : undefined, color: value ? `var(${RECORD_COLOR_TOKENS[value]})` : undefined };
|
|
1623
|
+
});
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
function recordDirectorySignature(entries) { return JSON.stringify([entries.map(record => [record.key, record.category]), recordTypeItems(entries).map(item => [item.value, item.count])]); }
|
|
1627
|
+
|
|
1628
|
+
function recordMatches(record) {
|
|
1629
|
+
const query = graphSearch.trim().toLocaleLowerCase();
|
|
1630
|
+
return (!graphType || record.category === graphType) && (!query || [record.name, record.type, record.summary, ...record.directorySources.map(source => source.item.summary)].filter(Boolean).some(value => String(value).toLocaleLowerCase().includes(query)));
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
function recordColor(record) { return `var(${RECORD_COLOR_TOKENS[record.category] ?? RECORD_COLOR_TOKENS.other})`; }
|
|
1634
|
+
|
|
1635
|
+
function recordRelation(record) {
|
|
1636
|
+
const actual = edges.filter(edge => (edge.source === project.id && edge.target === record.id) || (edge.target === project.id && edge.source === record.id));
|
|
1637
|
+
const labels = actual.map(edge => edge.label ?? relationLabel(edge.relation));
|
|
1638
|
+
for (const source of record.directorySources) if (source.item.relation) labels.push(source.item.relation);
|
|
1639
|
+
return [...new Set(labels.filter(Boolean))].join(' / ') || null;
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
function renderRecordDirectory(list) {
|
|
1643
|
+
const focus = graphFocusSnapshot();
|
|
1644
|
+
const entries = directoryEntries();
|
|
1645
|
+
const visible = entries.filter(recordMatches);
|
|
1646
|
+
list.replaceChildren();
|
|
1647
|
+
const signature = recordDirectorySignature(entries);
|
|
1648
|
+
if (recordTypeControls && recordTypeSignature !== signature) {
|
|
1649
|
+
const next = makeRecordTypeControls(entries);
|
|
1650
|
+
const focusIndex = Array.from(recordTypeControls.children).indexOf(doc.activeElement);
|
|
1651
|
+
recordTypeControls.replaceChildren(...Array.from(next.children));
|
|
1652
|
+
recordTypeControls.update = next.update;
|
|
1653
|
+
recordTypeSignature = signature;
|
|
1654
|
+
if (focusIndex >= 0) recordTypeControls.children[focusIndex]?.focus?.();
|
|
1655
|
+
}
|
|
1656
|
+
if (recordCount) recordCount.textContent = `${entries.length + 1}${!recordSourceCertainty().all ? '件取得済み・総数未確認' : '件の記録'}・図に${entities.size}件`;
|
|
1657
|
+
if (recordStates) renderRecordStates(recordStates);
|
|
1658
|
+
if (graphExit && typeof recordNavigation.canOpenGraph === 'function') {
|
|
1659
|
+
graphExit.disabled = recordNavigation.canOpenGraph(project.id) !== true;
|
|
1660
|
+
graphExit.setAttribute('aria-disabled', String(graphExit.disabled));
|
|
1661
|
+
graphExit.setAttribute('title', graphExit.disabled ? '対象のデータを確認できませんでした(ID不明)。' : '');
|
|
1662
|
+
}
|
|
1663
|
+
const matchingGraphIds = new Set([project.id, ...visible.map(record => record.id).filter(Boolean)]);
|
|
1664
|
+
graphHandle?.setFilter?.(graphSearch || graphType ? [...matchingGraphIds] : null);
|
|
1665
|
+
if (!visible.length) {
|
|
1666
|
+
const text = entries.length === 0 && !recordSourceCertainty().all ? '関連する情報を確認できませんでした。' : graphSearch || graphType ? '条件に一致する記録はありません。' : 'この画面で確認できる関係はありません。';
|
|
1667
|
+
list.append(makeElement(doc, 'li', { className: 'bb-pkw-record-empty', text }));
|
|
1668
|
+
restoreGraphFocus(focus);
|
|
1669
|
+
return;
|
|
1670
|
+
}
|
|
1671
|
+
for (const record of visible) {
|
|
1672
|
+
const wrapper = makeElement(doc, 'li');
|
|
1673
|
+
const onGraph = entities.has(record.id);
|
|
1674
|
+
const read = entityRead?.id === record.id ? entityRead : null;
|
|
1675
|
+
const marker = makeElement(doc, 'span', { className: 'bb-pkw-record-add', text: !record.id || onGraph || typeof readEntity !== 'function' ? '' : read?.state === 'loading' ? '…' : '+', attrs: { 'aria-hidden': 'true' } });
|
|
1676
|
+
const kindLabel = RECORD_TYPES.find(([id]) => id === record.category)?.[1] ?? typeLabel(record.type);
|
|
1677
|
+
const name = makeElement(doc, 'strong', { className: 'bb-pkw-record-title', text: record.name });
|
|
1678
|
+
const relation = recordRelation(record);
|
|
1679
|
+
const relationCell = makeElement(doc, 'span', { className: 'bb-pkw-record-relation', text: relation ?? '未確認', attrs: relation ? {} : { title: '関連する情報を確認できませんでした。', 'aria-label': 'このプロジェクトとの関係は未確認' } });
|
|
1680
|
+
const row = workspaceCardRow(doc, { cells: [name, workspaceDotPill(doc, { label: kindLabel, color: recordColor(record) }), relationCell, marker],
|
|
1681
|
+
selected: record.id ? !selectedAnonymous && selectedId === record.id : selectedAnonymous?.key === record.key && selectedAnonymous.signature === record.signature, stripe: onGraph ? recordColor(record) : 'var(--bb-color-border)', key: record.key,
|
|
1682
|
+
label: !record.id || onGraph || typeof readEntity !== 'function' ? `${record.name}を選択` : `${record.name}の詳細を取得して図に加える`, onSelect: () => record.id ? select(record.id) : selectAnonymous(record) });
|
|
1683
|
+
row.className += ' bb-pkw-record-row';
|
|
1684
|
+
wrapper.append(row); list.append(wrapper);
|
|
1685
|
+
}
|
|
1686
|
+
restoreGraphFocus(focus);
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
function makeRecordTypeControls(entries) {
|
|
1690
|
+
const controls = workspacePills(doc, { appearance: 'record-types', label: '種類で絞り込む', value: graphType,
|
|
1691
|
+
items: recordTypeItems(entries),
|
|
1692
|
+
onChange: value => { graphType = value; recordTypeControls?.update?.(value); resetRecordFilterSelection(); } });
|
|
1693
|
+
controls.setAttribute('aria-description', '件数は、この画面に取得できた記録の数です。');
|
|
1694
|
+
controls.setAttribute('title', '件数は、この画面に取得できた記録の数です。');
|
|
1695
|
+
return controls;
|
|
1696
|
+
}
|
|
1697
|
+
|
|
1698
|
+
function resetRecordFilterSelection() {
|
|
1699
|
+
selectedId = project.id; selectedAnonymous = null; entityRead = null; entityReadRequest += 1; pendingGraphFocus = null;
|
|
1700
|
+
graphHandle?.select?.(project.id);
|
|
1701
|
+
renderGraphList(); renderSelectedPanel();
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
function renderRecordStates(target) {
|
|
1705
|
+
target.replaceChildren();
|
|
1706
|
+
if (currentContext?.state && currentContext.state !== 'ok') target.append(workspaceNotice(doc, { label: currentContext.state === 'failed' ? '読み取り失敗' : currentContext.state === 'loading' ? '読み込み中' : '未確認', text: currentContext.message ?? '項目の取得状態を確認できません。', tone: currentContext.state === 'failed' ? 'danger' : 'info' }));
|
|
1707
|
+
const overview = normalizeProjectOverview(payload.overview);
|
|
1708
|
+
const states = [
|
|
1709
|
+
...[['directMaterials', '直接紐づく資料'], ['relatedMaterials', '関連資料']].filter(([key]) => payload.overview?.[key]).map(([key, title]) => ({ id: key, title, ...overview[key] })),
|
|
1710
|
+
...(currentContext?.sections ?? []).filter(section => section !== contextTaskSection(currentContext) && recordCategory(section.id) !== 'task'),
|
|
1711
|
+
];
|
|
1712
|
+
for (const source of states) {
|
|
1713
|
+
const row = makeElement(doc, 'div', { className: 'bb-pkw-record-source' });
|
|
1714
|
+
const known = source.state === 'ok';
|
|
1715
|
+
const count = source.items?.length ?? 0;
|
|
1716
|
+
const total = explicitSectionTotal(source);
|
|
1717
|
+
const label = known ? `${count}件取得済み${total === null ? '・総数未確認' : ` / ${total}件${total > count ? '・続き未取得' : ''}`}` : `${source.state === 'loading' ? '読み込み中' : source.state === 'failed' ? '読み取り失敗' : source.state === 'partial' ? '一部取得' : source.state === 'unavailable' ? '未接続' : '未確認'}${count ? `・${count}件取得済み` : ''}${total === null ? '' : ` / ${total}件`}`;
|
|
1718
|
+
row.append(makeElement(doc, 'strong', { text: source.title }), makeElement(doc, 'span', { text: label }));
|
|
1719
|
+
const note = firstText(source.note, source.message);
|
|
1720
|
+
if (note) row.append(makeElement(doc, 'span', { text: note }));
|
|
1721
|
+
if (source.source) row.append(makeElement(doc, 'span', { text: `出典: ${source.source}` }));
|
|
1722
|
+
if (source.asOf) row.append(makeElement(doc, 'span', { text: `取得日時: ${formatDateTime(source.asOf)}` }));
|
|
1723
|
+
target.append(row);
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1400
1727
|
function filteredGraphEntities() {
|
|
1401
1728
|
const query = graphSearch.trim().toLocaleLowerCase();
|
|
1402
1729
|
return [...entities.values()].filter((entity) => {
|
|
@@ -1410,10 +1737,12 @@ export function createProjectKnowledgeWorkspace({
|
|
|
1410
1737
|
const panel = root.querySelector?.('.bb-pkw-selection') ?? selectedPanel;
|
|
1411
1738
|
if (!panel) return;
|
|
1412
1739
|
panel.replaceChildren();
|
|
1413
|
-
const
|
|
1740
|
+
const anonymous = selectedAnonymous ? directoryEntries().find(record => !record.id && record.key === selectedAnonymous.key && record.signature === selectedAnonymous.signature) : null;
|
|
1741
|
+
if (selectedAnonymous && !anonymous) selectedAnonymous = null;
|
|
1742
|
+
const entity = anonymous ?? entities.get(selectedId) ?? overviewProjectionRecords.get(selectedId) ?? (tabbedDetail ? directoryEntries().find(record => record.id === selectedId) : null);
|
|
1414
1743
|
if (!entity) return;
|
|
1415
1744
|
const read = entityRead?.id === selectedId ? entityRead : null;
|
|
1416
|
-
const fetched = selectedId === project.id ? { entity: project, incoming: [], outgoing: [] } : read?.entity ? read : null;
|
|
1745
|
+
const fetched = anonymous ? null : selectedId === project.id ? { entity: project, incoming: [], outgoing: [] } : read?.entity ? read : null;
|
|
1417
1746
|
const selectedEntity = fetched?.entity ?? entity;
|
|
1418
1747
|
panel.append(makeElement(doc, 'h3', { text: '選択した記録' }), makeElement(doc, 'div', { className: 'bb-pkw-selected-head' }));
|
|
1419
1748
|
const head = panel.children[1];
|
|
@@ -1424,8 +1753,10 @@ export function createProjectKnowledgeWorkspace({
|
|
|
1424
1753
|
['目的', textOrNull(selectedEntity.goal)],
|
|
1425
1754
|
['有効期間', validityText(selectedEntity.validFrom, selectedEntity.validTo)],
|
|
1426
1755
|
]));
|
|
1427
|
-
|
|
1428
|
-
|
|
1756
|
+
const projectEdges = tabbedDetail ? edges.filter(edge => edge.source === project.id || edge.target === project.id) : overviewEdges;
|
|
1757
|
+
panel.append(makeElement(doc, 'h4', { text: 'このプロジェクトとの関係' }), relationEvidence(doc, projectEdges, anonymous ? null : selectedId, tabbedDetail ? entities : overviewEntities, payload.asOf, selectAndExplore, tabbedDetail ? '関係の詳細' : undefined, tabbedDetail && selectedId === project.id, tabbedDetail ? '関連する情報を確認できませんでした。' : undefined, tabbedDetail));
|
|
1758
|
+
if (anonymous) panel.append(workspaceNotice(doc, { label: '未確認', text: '対象のデータを確認できませんでした(ID不明)。', tone: 'info' }));
|
|
1759
|
+
else if (selectedId !== project.id && !fetched) {
|
|
1429
1760
|
const failed = read?.state === 'failed';
|
|
1430
1761
|
panel.append(workspaceNotice(doc, {
|
|
1431
1762
|
label: failed ? '読み取り失敗' : read?.state === 'loading' ? '読み込み中' : '未接続',
|
|
@@ -1433,16 +1764,71 @@ export function createProjectKnowledgeWorkspace({
|
|
|
1433
1764
|
tone: failed ? 'danger' : 'info',
|
|
1434
1765
|
role: failed ? 'alert' : 'status',
|
|
1435
1766
|
}));
|
|
1767
|
+
if (failed && typeof readEntity === 'function') panel.append(denseButton(doc, '再試行', 'bb-pkw-record-retry', () => loadEntity(selectedId)));
|
|
1436
1768
|
}
|
|
1437
1769
|
if (fetched?.entity) {
|
|
1438
1770
|
const incoming = renderEntityRelations(doc, fetched.incoming, 'incoming', fetched.entity, payload.asOf, selectAndExplore);
|
|
1439
1771
|
const outgoing = renderEntityRelations(doc, fetched.outgoing, 'outgoing', fetched.entity, payload.asOf, selectAndExplore);
|
|
1440
1772
|
if (incoming) panel.append(makeElement(doc, 'h4', { text: '入ってくる関係' }), incoming);
|
|
1441
1773
|
if (outgoing) panel.append(makeElement(doc, 'h4', { text: '出ていく関係' }), outgoing);
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1774
|
+
if (!tabbedDetail) {
|
|
1775
|
+
const metadataValues = isRecord(fetched.entity.metadata) ? Object.entries(fetched.entity.metadata).filter(([, value]) => ['string', 'number', 'boolean'].includes(typeof value)).map(([key, value]) => [key, String(value)]) : [];
|
|
1776
|
+
if (metadataValues.length > 0) panel.append(makeElement(doc, 'h4', { text: 'メタデータ' }), workspaceDefinition(doc, metadataValues));
|
|
1777
|
+
panel.append(recordDetails(doc, [['記録ID', fetched.entity.id], ['digest', fetched.entity.digest], ['読み取った時点', fetched.asOf ?? payload.asOf]]));
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
if (tabbedDetail) panel.append(renderSelectedRecordDetails(selectedEntity, fetched));
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
function renderSelectedRecordDetails(entity, fetched) {
|
|
1784
|
+
const directory = directoryEntries().find(record => selectedAnonymous ? !record.id && record.key === selectedAnonymous.key && record.signature === selectedAnonymous.signature : record.id === selectedId);
|
|
1785
|
+
const sourceItems = directory?.directorySources ?? [];
|
|
1786
|
+
const projected = sourceItems.map(source => source.item);
|
|
1787
|
+
const record = { ...(directory ?? {}), ...entity };
|
|
1788
|
+
const details = recordDetails(doc, [['記録ID', entity.id], ['digest', entity.digest], ['取得日時', fetched?.asOf ?? payload.asOf]]);
|
|
1789
|
+
details.open = true;
|
|
1790
|
+
const content = makeElement(doc, 'div', { className: 'bb-pkw-selected-record-body' });
|
|
1791
|
+
const body = firstText(...projected.flatMap(item => [item.body, item.description]), entity.body, entity.description, entity.summary, directory?.summary);
|
|
1792
|
+
content.append(makeElement(doc, 'h4', { text: '記録の要点' }), makeElement(doc, 'p', { className: body ? 'bb-pkw-detail-body' : 'bb-pkw-muted', text: body ?? '本文・要約は未確認です。' }));
|
|
1793
|
+
content.append(makeElement(doc, 'h4', { text: '出典と状態' }), detailDefinition(doc, record));
|
|
1794
|
+
const bodies = { retrieved: '本文取得済み', unretrieved: '本文未取得', unavailable: '本文未接続', failed: '本文読取失敗', unknown: '本文状態未確認' };
|
|
1795
|
+
for (const source of sourceItems) {
|
|
1796
|
+
const item = source.item;
|
|
1797
|
+
const rows = [
|
|
1798
|
+
['出典', sourceLabel(item.source) ?? textOrNull(item.sourcePath)],
|
|
1799
|
+
['本文', item.bodyState ? bodies[item.bodyState] ?? item.bodyState : null],
|
|
1800
|
+
['内容時点', item.contentAsOf ? formatDateTime(item.contentAsOf) : null],
|
|
1801
|
+
['記録更新', item.updatedAt ? formatDateTime(item.updatedAt) : null],
|
|
1802
|
+
].filter(([, value]) => value);
|
|
1803
|
+
if (rows.length) {
|
|
1804
|
+
const sourceBlock = makeElement(doc, 'section', { className: 'bb-pkw-selected-source' });
|
|
1805
|
+
if (source.sectionTitle) sourceBlock.append(makeElement(doc, 'h5', { text: source.sectionTitle }));
|
|
1806
|
+
sourceBlock.append(workspaceDefinition(doc, rows)); content.append(sourceBlock);
|
|
1807
|
+
}
|
|
1808
|
+
if (isRecord(item.provenance)) content.append(renderProvenance(doc, item.provenance));
|
|
1809
|
+
}
|
|
1810
|
+
const tasks = contextTaskItems(currentContext);
|
|
1811
|
+
const taskIds = new Set(projected.flatMap(item => [item.relatedTaskId, ...(item.relatedTaskIds ?? [])]).filter(Boolean));
|
|
1812
|
+
if (!selectedAnonymous) for (const task of tasks) if (task.sourceRecordId === selectedId || task.relatedRecordId === selectedId || task.relatedTaskId === selectedId || (task.recordIds ?? []).includes(selectedId)) taskIds.add(task.id);
|
|
1813
|
+
const related = makeElement(doc, 'section', { className: 'bb-pkw-selected-tasks', attrs: { 'aria-label': '関連する仕事' } });
|
|
1814
|
+
related.append(makeElement(doc, 'h4', { text: '関連する仕事' }));
|
|
1815
|
+
if (!taskIds.size) related.append(makeElement(doc, 'p', { className: 'bb-pkw-muted', text: '関連する仕事のIDは未接続です。' }));
|
|
1816
|
+
for (const id of taskIds) {
|
|
1817
|
+
const task = tasks.find(item => item.id === id);
|
|
1818
|
+
if (task && typeof recordNavigation.onOpenTask === 'function') related.append(denseButton(doc, task.title, 'bb-pkw-dense-link', () => recordNavigation.onOpenTask(task.id, project.id), { 'data-task-id': task.id }));
|
|
1819
|
+
else related.append(makeElement(doc, 'p', { className: 'bb-pkw-muted', text: `仕事ID ${id} は未確認です。` }));
|
|
1445
1820
|
}
|
|
1821
|
+
content.append(related);
|
|
1822
|
+
if (!selectedAnonymous && selectedId === project.id) {
|
|
1823
|
+
const about = normalizeProjectOverview(payload.overview)?.about;
|
|
1824
|
+
if (about?.definition && about.definition !== project.goal) content.append(makeElement(doc, 'h4', { text: 'サービス定義' }), makeElement(doc, 'p', { text: about.definition }));
|
|
1825
|
+
}
|
|
1826
|
+
const metadata = isRecord(entity.metadata) ? Object.entries(entity.metadata).filter(([, value]) => ['string', 'number', 'boolean'].includes(typeof value)).map(([key, value]) => [key, String(value)]) : [];
|
|
1827
|
+
if (metadata.length) content.append(makeElement(doc, 'h4', { text: 'メタデータ' }), workspaceDefinition(doc, metadata));
|
|
1828
|
+
const unknowns = [...new Set([...projected.flatMap(item => item.unknowns ?? []), ...(!selectedAnonymous && selectedId === project.id ? projectKnowledgeUnknowns(payload) : [])])];
|
|
1829
|
+
if (unknowns.length) content.append(makeElement(doc, 'h4', { text: '未確認' }), makeElement(doc, 'p', { className: 'bb-pkw-muted', text: unknowns.join(' · ') }));
|
|
1830
|
+
details.append(content);
|
|
1831
|
+
return details;
|
|
1446
1832
|
}
|
|
1447
1833
|
|
|
1448
1834
|
async function loadEntity(id) {
|
|
@@ -1453,16 +1839,18 @@ export function createProjectKnowledgeWorkspace({
|
|
|
1453
1839
|
const result = await readEntity(id);
|
|
1454
1840
|
if (destroyed || request !== entityReadRequest || selectedId !== id) return;
|
|
1455
1841
|
const normalized = resultEntity(result);
|
|
1456
|
-
|
|
1842
|
+
const validEntity = normalized && (!tabbedDetail || (normalized.entity.id === id && textOrNull(normalized.entity.name) && textOrNull(normalized.entity.type) && (!result.state || result.state === 'ok')));
|
|
1843
|
+
entityRead = validEntity ? { id, ...normalized } : { id, state: 'failed', message: normalized ? '表示しようとしたデータが、選択中のものと一致しません。' : resultFailure(result) };
|
|
1457
1844
|
} catch (error) {
|
|
1458
1845
|
if (destroyed || request !== entityReadRequest || selectedId !== id) return;
|
|
1459
1846
|
entityRead = { id, state: 'failed', message: firstText(error?.message) ?? 'この記録の詳細を読み取れませんでした。' };
|
|
1460
1847
|
}
|
|
1461
1848
|
if (entityRead?.entity) mergeEntityRead(entityRead);
|
|
1462
|
-
render();
|
|
1849
|
+
if (!tabbedDetail || activeTab === 'graph') render();
|
|
1463
1850
|
}
|
|
1464
1851
|
|
|
1465
1852
|
function renderGraphPanel() {
|
|
1853
|
+
if (tabbedDetail) return renderTabbedGraphPanel();
|
|
1466
1854
|
const panel = makeElement(doc, 'section', { className: 'bb-pkw-panel bb-pkw-graph-panel', attrs: { role: 'tabpanel', id: 'bb-pkw-panel-graph', 'aria-label': '情報を探す' } });
|
|
1467
1855
|
const intro = makeElement(doc, 'div', { className: 'bb-pkw-graph-intro' });
|
|
1468
1856
|
intro.append(makeElement(doc, 'div', { className: 'bb-pkw-section-title' }), makeElement(doc, 'p', { className: 'bb-pkw-muted', text: '線はGraphに記録された関係です。補足セクションの所属だけから線を作ることはありません。' }));
|
|
@@ -1533,17 +1921,98 @@ export function createProjectKnowledgeWorkspace({
|
|
|
1533
1921
|
return panel;
|
|
1534
1922
|
}
|
|
1535
1923
|
|
|
1924
|
+
function graphMountOptions(canvas) {
|
|
1925
|
+
const computed = typeof globalThis.getComputedStyle === 'function' ? globalThis.getComputedStyle(canvas) : null;
|
|
1926
|
+
const color = token => computed?.getPropertyValue(token)?.trim() || undefined;
|
|
1927
|
+
const typeColors = Object.create(null);
|
|
1928
|
+
for (const entity of entities.values()) typeColors[entity.type] = color(RECORD_COLOR_TOKENS[recordCategory(entity.type)] ?? RECORD_COLOR_TOKENS.other);
|
|
1929
|
+
return { rootId: project.id, layout: 'project-detail', visualTheme: { typeColors, fontFamily: computed?.fontFamily, paper: color('--bb-color-paper'), ink: color('--bb-color-ink'), slate: color('--bb-color-slate'), focus: color('--bb-color-mint'), preserveSelectedTypeColor: true, preserveRootLabel: true, selected: color('--bb-color-action'), edge: color('--bb-color-border'), unrelated: color('--bb-color-border'), unrelatedEdge: color('--bb-color-line-soft') } };
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
function renderTabbedGraphPanel() {
|
|
1933
|
+
const panel = makeElement(doc, 'section', { className: 'bb-pkw-panel bb-pkw-graph-panel bb-pkw-find', attrs: { role: 'tabpanel', id: 'bb-pkw-panel-graph', 'aria-label': '情報を探す' } });
|
|
1934
|
+
const filters = makeElement(doc, 'div', { className: 'bb-pkw-find-filters' });
|
|
1935
|
+
const search = makeElement(doc, 'input', { attrs: { type: 'search', name: 'project-record-search', placeholder: '記録を検索', 'aria-label': '記録を検索', autocomplete: 'off' } });
|
|
1936
|
+
search.value = graphSearch;
|
|
1937
|
+
search.addEventListener('input', () => { graphSearch = search.value ?? ''; resetRecordFilterSelection(); });
|
|
1938
|
+
recordTypeControls = makeRecordTypeControls(directoryEntries());
|
|
1939
|
+
recordTypeSignature = recordDirectorySignature(directoryEntries());
|
|
1940
|
+
recordCount = makeElement(doc, 'span', { className: 'bb-pkw-find-count' });
|
|
1941
|
+
filters.append(workspaceSearchControl(doc, { input: search, appearance: 'compact', width: 240 }), recordTypeControls, recordCount);
|
|
1942
|
+
panel.append(filters);
|
|
1943
|
+
const layout = makeElement(doc, 'div', { className: 'bb-pkw-find-layout' });
|
|
1944
|
+
const main = makeElement(doc, 'div', { className: 'bb-pkw-find-main' });
|
|
1945
|
+
const canvas = makeElement(doc, 'div', { className: 'bb-pkw-graph-canvas bb-pkw-find-canvas', attrs: { 'aria-label': 'プロジェクトの関係グラフ' } });
|
|
1946
|
+
canvas.append(denseButton(doc, project.name, 'bb-ws-button bb-ws-focus-only bb-pkw-record-root-access', () => select(project.id), { 'aria-label': `${project.name}を選択`, 'data-graph-root-fallback': '' }));
|
|
1947
|
+
main.append(canvas);
|
|
1948
|
+
const fallback = makeElement(doc, 'div', { className: 'bb-pkw-find-fallback' });
|
|
1949
|
+
fallback.hidden = typeof mountGraph === 'function' && !graphFailure;
|
|
1950
|
+
fallback.append(workspaceNotice(doc, { label: graphFailure ? 'グラフを表示できません' : '未接続', text: '一覧から関係を確認できます。', tone: 'warning' }),
|
|
1951
|
+
denseButton(doc, project.name, 'bb-pkw-record-root', () => select(project.id), { 'aria-label': `${project.name}を選択` }));
|
|
1952
|
+
main.append(fallback);
|
|
1953
|
+
const headings = makeElement(doc, 'div', { className: 'bb-pkw-record-head', attrs: { 'aria-hidden': 'true' } });
|
|
1954
|
+
for (const text of ['記録', '種類', '関係', '']) headings.append(makeElement(doc, 'span', { text }));
|
|
1955
|
+
main.append(headings, graphList);
|
|
1956
|
+
recordStates = makeElement(doc, 'div', { className: 'bb-pkw-record-sources', attrs: { 'aria-label': '記録一覧の取得状態' } });
|
|
1957
|
+
main.append(recordStates);
|
|
1958
|
+
const exits = makeElement(doc, 'div', { className: 'bb-pkw-record-exits' });
|
|
1959
|
+
for (const [label, callback] of [['知識で見る', recordNavigation.onOpenKnowledge], ['情報と関係で見る', recordNavigation.onOpenGraph]]) if (typeof callback === 'function') {
|
|
1960
|
+
const isGraph = label === '情報と関係で見る';
|
|
1961
|
+
const button = denseButton(doc, label, 'bb-project-overview-link', () => {
|
|
1962
|
+
if (isGraph && typeof recordNavigation.canOpenGraph === 'function' && recordNavigation.canOpenGraph(project.id) !== true) return;
|
|
1963
|
+
callback(project.id);
|
|
1964
|
+
});
|
|
1965
|
+
if (isGraph) graphExit = button;
|
|
1966
|
+
exits.append(button);
|
|
1967
|
+
}
|
|
1968
|
+
main.append(exits);
|
|
1969
|
+
const selected = makeElement(doc, 'section', { className: 'bb-pkw-selection bb-pkw-find-selection', attrs: { 'aria-label': '選択した記録', 'aria-live': 'polite' } });
|
|
1970
|
+
selectedPanel = selected;
|
|
1971
|
+
layout.append(main, selected); panel.append(layout);
|
|
1972
|
+
renderGraphList(); renderSelectedPanel();
|
|
1973
|
+
if (activeTab === 'graph' && typeof mountGraph === 'function' && !graphFailure) {
|
|
1974
|
+
const token = ++graphMountToken;
|
|
1975
|
+
const mount = () => {
|
|
1976
|
+
graphTimer = null;
|
|
1977
|
+
if (destroyed || token !== graphMountToken || graphHandle) return;
|
|
1978
|
+
const options = graphMountOptions(canvas);
|
|
1979
|
+
const nodes = [...entities.values()].map(entity => ({ id: entity.id, label: entity.name, type: entity.type, color: options.visualTheme.typeColors[entity.type] }));
|
|
1980
|
+
const freshNodeIds = [...graphFreshNodeIds];
|
|
1981
|
+
Promise.resolve().then(() => mountGraph(canvas, { ...options, nodes, edges, selectedId, cameraState: graphCameraState, revealState: graphRevealState, freshNodeIds, revealDelay: graphEntryReveal ? 80 : 0, revealStagger: graphEntryReveal ? 28 : 0, onSelect: id => select(id ?? project.id, { fromGraph: true }) })).then(handle => {
|
|
1982
|
+
if (destroyed || token !== graphMountToken || activeTab !== 'graph') { handle?.destroy?.(); return; }
|
|
1983
|
+
graphHandle = handle ?? null;
|
|
1984
|
+
for (const id of freshNodeIds) graphFreshNodeIds.delete(id);
|
|
1985
|
+
graphEntryReveal = false;
|
|
1986
|
+
graphRevealState = null;
|
|
1987
|
+
if (entities.has(selectedId)) graphHandle?.select?.(selectedId);
|
|
1988
|
+
renderGraphList();
|
|
1989
|
+
if (pendingGraphFocus) {
|
|
1990
|
+
if (!root.contains?.(doc.activeElement)) restoreGraphFocus(pendingGraphFocus);
|
|
1991
|
+
else pendingGraphFocus = null;
|
|
1992
|
+
}
|
|
1993
|
+
}).catch(() => { if (!destroyed && token === graphMountToken && activeTab === 'graph') { graphFailure = true; fallback.hidden = false; } });
|
|
1994
|
+
};
|
|
1995
|
+
graphTimer = typeof setTimeout === 'function' ? setTimeout(mount, 0) : null;
|
|
1996
|
+
if (graphTimer === null && typeof queueMicrotask === 'function') queueMicrotask(mount);
|
|
1997
|
+
}
|
|
1998
|
+
return panel;
|
|
1999
|
+
}
|
|
2000
|
+
|
|
1536
2001
|
function teardownGraph() {
|
|
1537
2002
|
graphMountToken += 1;
|
|
1538
2003
|
if (graphTimer !== null && typeof clearTimeout === 'function') clearTimeout(graphTimer);
|
|
1539
2004
|
graphTimer = null;
|
|
2005
|
+
if (tabbedDetail && !graphResetPending && graphHandle?.getCameraState) graphCameraState = graphHandle.getCameraState();
|
|
2006
|
+
if (tabbedDetail && !graphResetPending && graphHandle?.getRevealState) graphRevealState = graphHandle.getRevealState();
|
|
2007
|
+
graphResetPending = false;
|
|
1540
2008
|
if (graphHandle?.destroy) graphHandle.destroy();
|
|
1541
2009
|
graphHandle = null;
|
|
1542
2010
|
}
|
|
1543
2011
|
|
|
1544
2012
|
function replaceContextBlock(nextContext) {
|
|
1545
2013
|
currentContext = nextContext;
|
|
1546
|
-
if (destroyed
|
|
2014
|
+
if (destroyed) return;
|
|
2015
|
+
if (activeTab === 'graph') { if (tabbedDetail) { renderGraphList(); renderSelectedPanel(); } return; }
|
|
1547
2016
|
const focused = doc.activeElement;
|
|
1548
2017
|
const controlName = root.contains?.(focused) && focused?.closest?.('.bb-pkw-work-controls') ? focused.getAttribute?.('name') : null;
|
|
1549
2018
|
const restoreFocus = ['work-search', 'work-status', 'work-owner', 'work-due', 'record-search', 'record-status'].includes(controlName);
|
|
@@ -1557,41 +2026,112 @@ export function createProjectKnowledgeWorkspace({
|
|
|
1557
2026
|
}
|
|
1558
2027
|
}
|
|
1559
2028
|
|
|
2029
|
+
function refreshTabTools(slotContext = { document: doc, project, detail: payload, context: currentContext, activeTab, actions: { setTab, selectEntity: selectAndExplore } }) {
|
|
2030
|
+
tools.replaceChildren();
|
|
2031
|
+
if (typeof renderTabTools === 'function') {
|
|
2032
|
+
try {
|
|
2033
|
+
const content = renderTabTools(slotContext);
|
|
2034
|
+
for (const node of Array.isArray(content) ? content : [content]) if (node && typeof node === 'object' && typeof node.tagName === 'string') tools.append(node);
|
|
2035
|
+
} catch { tools.append(workspaceNotice(doc, { label: '表示できません', text: 'プロジェクトの操作を表示できませんでした。', tone: 'danger' })); }
|
|
2036
|
+
}
|
|
2037
|
+
tools.hidden = tools.children.length === 0;
|
|
2038
|
+
}
|
|
2039
|
+
|
|
2040
|
+
function refreshHost({ context: nextContext = currentContext, onTabChange: nextOnTabChange } = {}) {
|
|
2041
|
+
if (destroyed) return;
|
|
2042
|
+
currentContext = nextContext;
|
|
2043
|
+
if (typeof nextOnTabChange === 'function') onTabChange = nextOnTabChange;
|
|
2044
|
+
// Repainting host controls must not reset Sigma's viewport, its selected
|
|
2045
|
+
// record, or an entity read already in flight.
|
|
2046
|
+
if (activeTab === 'graph') {
|
|
2047
|
+
refreshTabTools();
|
|
2048
|
+
if (tabbedDetail) { renderGraphList(); renderSelectedPanel(); }
|
|
2049
|
+
if (typeof onTabChange === 'function') onTabChange(activeTab);
|
|
2050
|
+
} else render();
|
|
2051
|
+
}
|
|
2052
|
+
|
|
2053
|
+
function releaseHostTab() {
|
|
2054
|
+
const current = hostTabHandle;
|
|
2055
|
+
hostTabHandle = null;
|
|
2056
|
+
current?.destroy?.();
|
|
2057
|
+
}
|
|
2058
|
+
|
|
1560
2059
|
function render() {
|
|
1561
2060
|
if (destroyed) return;
|
|
2061
|
+
const graphFocus = tabbedDetail ? graphFocusSnapshot() : null;
|
|
2062
|
+
releaseHostTab();
|
|
1562
2063
|
if (typeof onTabChange === 'function') onTabChange(activeTab);
|
|
1563
2064
|
teardownGraph();
|
|
1564
|
-
tabs.replaceChildren(tabButton('概要', 'overview'), tabButton('情報を探す', 'graph'));
|
|
2065
|
+
tabs.replaceChildren(tabButton('概要', 'overview'), ...extraTabs.map(tab => tabButton(tab.label, tab.id)), tabButton('情報を探す', 'graph'));
|
|
1565
2066
|
tabStrip.update();
|
|
1566
2067
|
panels.replaceChildren();
|
|
1567
|
-
const actions = { openOverview, openWorkList, openWorkDetail, openRecordDetail, openSectionList, openGraphEntity: selectAndExplore,
|
|
2068
|
+
const actions = { setTab, selectEntity: selectAndExplore, openOverview, openWorkList, openWorkDetail, openRecordDetail, openSectionList, openGraphEntity: selectAndExplore,
|
|
1568
2069
|
retryParticipants: typeof onRetryProject === 'function' ? () => onRetryProject(workspaceProjectId) : null,
|
|
1569
2070
|
recordSectionId: selectedSectionId,
|
|
1570
2071
|
recordSectionTitle: CONTEXT_CATEGORIES.find(([id]) => id === selectedSectionId)?.[1] ?? contextSectionById(currentContext, [selectedSectionId])?.title,
|
|
1571
2072
|
};
|
|
2073
|
+
const slotContext = { document: doc, project, detail: payload, context: currentContext, activeTab, actions };
|
|
2074
|
+
refreshTabTools(slotContext);
|
|
1572
2075
|
let overview;
|
|
1573
2076
|
if (activeView === 'work-list') overview = renderWorkList(doc, currentContext, actions, listViewState('tasks'));
|
|
1574
2077
|
else if (activeView === 'record-list') overview = renderRecordList(doc, currentContext, selectedSectionId, actions, listViewState(selectedSectionId));
|
|
1575
2078
|
else if (activeView === 'work-detail') overview = renderWorkDetail(doc, findContextItem(selectedContextId, 'task'), currentContext, actions);
|
|
1576
2079
|
else if (activeView === 'record-detail') overview = renderRecordDetail(doc, findContextItem(selectedContextId, 'record') ?? entities.get(selectedContextId), currentContext, actions);
|
|
2080
|
+
else if (tabbedDetail) {
|
|
2081
|
+
overview = makeElement(doc, 'div', { className: 'bb-pkw-panel bb-pkw-overview', attrs: { role: 'tabpanel', 'aria-label': '概要' } });
|
|
2082
|
+
const snapshot = denseParticipantSnapshot(payload);
|
|
2083
|
+
const edges = [...new Map((payload.participants ?? []).filter(edge => edge?.counterpart?.id && (edge.counterpart.name || edge.counterpart.title)).map(edge => [edge.counterpart.id, edge])).values()];
|
|
2084
|
+
const participants = edges.length ? edges : denseParticipantStatus(payload) === 'available' ? denseProjectPeople(payload).map(person => ({ counterpart: person, role: person.accountable ? '責任者' : null })) : [];
|
|
2085
|
+
let participantNotice = null;
|
|
2086
|
+
if (snapshot.uncertain || denseParticipantCountMismatch(payload, edges, snapshot)) {
|
|
2087
|
+
participantNotice = workspaceNotice(doc, { label: snapshot.state === 'failed' ? '読み取り失敗' : '未確認', text: snapshot.uncertain ? snapshot.reason : '既知の件数と取得した関係者が一致しません。現在の関係者の詳細を読み取れていません。', tone: snapshot.state === 'failed' ? 'danger' : 'info' });
|
|
2088
|
+
if (actions.retryParticipants) participantNotice.append(denseButton(doc, '再試行', 'bb-project-overview-link', actions.retryParticipants));
|
|
2089
|
+
} else if (!participants.length) participantNotice = makeElement(doc, 'p', { className: 'bb-pkw-muted', text: snapshot.confirmedEmpty ? '確認できた関係者はありません。' : '関係者の詳細を未確認です。登録なしとは判断できません。' });
|
|
2090
|
+
const participantCount = !participantNotice && !snapshot.uncertain && Number.isInteger(project.participantCount) && project.participantCount === participants.length ? project.participantCount : null;
|
|
2091
|
+
try { overview.append(renderProjectDetailOverview(doc, payload, { actions, config: overviewConfig, context: currentContext, participants, participantNotice, participantCount })); }
|
|
2092
|
+
catch { overview.append(workspaceNotice(doc, { label: '表示できません', text: 'プロジェクトの概要を表示できませんでした。', tone: 'danger' })); }
|
|
2093
|
+
// Opt-in records and evidence now live in the explorer; the personal
|
|
2094
|
+
// default below retains its existing material tables and routes.
|
|
2095
|
+
}
|
|
1577
2096
|
else overview = renderOverview(doc, payload, currentContext, overviewEntities, actions);
|
|
1578
2097
|
overview.id = 'bb-pkw-panel-overview';
|
|
1579
2098
|
overview.hidden = activeTab !== 'overview';
|
|
1580
2099
|
panels.append(overview);
|
|
2100
|
+
for (const tab of extraTabs) {
|
|
2101
|
+
const panel = makeElement(doc, 'section', { className: 'bb-pkw-panel bb-pkw-host-panel', attrs: { role: 'tabpanel', id: `bb-pkw-panel-${tab.id}`, 'aria-label': tab.label } });
|
|
2102
|
+
panel.hidden = activeTab !== tab.id;
|
|
2103
|
+
if (!panel.hidden) {
|
|
2104
|
+
try {
|
|
2105
|
+
const content = tab.render(slotContext);
|
|
2106
|
+
if (content?.root && typeof content.root.tagName === 'string') {
|
|
2107
|
+
hostTabHandle = content;
|
|
2108
|
+
panel.append(content.root);
|
|
2109
|
+
} else if (content && typeof content.tagName === 'string') panel.append(content);
|
|
2110
|
+
}
|
|
2111
|
+
catch { panel.append(workspaceNotice(doc, { label: '表示できません', text: 'このタブの内容を表示できませんでした。', tone: 'danger' })); }
|
|
2112
|
+
}
|
|
2113
|
+
panels.append(panel);
|
|
2114
|
+
}
|
|
1581
2115
|
const graph = renderGraphPanel();
|
|
1582
2116
|
graph.hidden = activeTab !== 'graph';
|
|
1583
2117
|
panels.append(graph);
|
|
2118
|
+
if (tabbedDetail) restoreGraphFocus(graphFocus);
|
|
1584
2119
|
}
|
|
1585
2120
|
|
|
1586
2121
|
function destroy() {
|
|
1587
2122
|
destroyed = true;
|
|
2123
|
+
releaseHostTab();
|
|
1588
2124
|
entityReadRequest += 1;
|
|
1589
2125
|
teardownGraph();
|
|
2126
|
+
tabStrip.destroy();
|
|
1590
2127
|
if (typeof onTabChange === 'function') onTabChange('overview');
|
|
1591
2128
|
}
|
|
1592
2129
|
|
|
1593
2130
|
render();
|
|
1594
|
-
|
|
2131
|
+
if (!selectedAnonymous && selectedId !== project.id && typeof readEntity === 'function') void loadEntity(selectedId);
|
|
2132
|
+
return Object.freeze({ element: root, destroy, select, setTab, setContext: replaceContextBlock, refreshHost,
|
|
2133
|
+
getViewState: () => ({ projectId: workspaceProjectId, activeTab, selectedId, selectedAnonymous: selectedAnonymous ? { ...selectedAnonymous } : null, graphSearch, graphType, graphCameraState: graphHandle?.getCameraState?.() ?? graphCameraState, graphRevealState: graphHandle?.getRevealState?.() ?? graphRevealState, focusNodeId: graphFocusSnapshot()?.nodeId ?? pendingGraphFocus?.nodeId ?? null }),
|
|
2134
|
+
});
|
|
1595
2135
|
}
|
|
1596
2136
|
|
|
1597
2137
|
export default createProjectKnowledgeWorkspace;
|