@tekkare/romulus 0.1.260 → 0.1.262

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 (32) hide show
  1. package/dist/module.json +1 -1
  2. package/layer/app/components/oip-science/clinical-trials/Cards.vue +2 -0
  3. package/layer/app/components/oip-science/clinical-trials/CardsGlobal.vue +2 -0
  4. package/layer/app/components/oip-science/clinical-trials/LinkedList.vue +66 -35
  5. package/layer/app/components/oip-science/hcps/Pubmed.vue +48 -28
  6. package/layer/app/components/oip-science/pubmed/Cards.vue +2 -1
  7. package/layer/app/components/panels/OipPanelProjects.vue +70 -21
  8. package/layer/app/components/project/AddButton.vue +127 -0
  9. package/layer/app/components/project/Banner.vue +68 -0
  10. package/layer/app/components/project/Dashboard.vue +85 -0
  11. package/layer/app/components/project/DiscardConfirm.vue +74 -0
  12. package/layer/app/components/project/Documents.vue +611 -0
  13. package/layer/app/components/project/Export.vue +205 -0
  14. package/layer/app/components/project/Inbox.vue +1241 -0
  15. package/layer/app/components/project/ListPage.vue +102 -0
  16. package/layer/app/components/project/NewButton.vue +147 -0
  17. package/layer/app/components/project/Notes.vue +1158 -0
  18. package/layer/app/components/project/Page.vue +820 -0
  19. package/layer/app/components/project/Share.vue +135 -0
  20. package/layer/app/components/project/Watch.vue +273 -0
  21. package/layer/app/composables/useOipProjectKinds.ts +71 -0
  22. package/layer/app/composables/useOipResourceHooks.ts +8 -3
  23. package/layer/app/composables/useProjectDashboard.ts +22 -0
  24. package/layer/app/composables/useProjects.ts +646 -0
  25. package/layer/app/oip-defaults/projects.ts +175 -0
  26. package/layer/app/pages/projects/[id].vue +8 -0
  27. package/layer/app/pages/projects/index.vue +8 -0
  28. package/layer/app/types/projects.ts +168 -0
  29. package/layer/app/utils/projectNoteWelcome.ts +137 -0
  30. package/layer/nuxt.config.ts +16 -0
  31. package/layer/server/api/oip/sharing/artifacts.get.ts +44 -0
  32. package/package.json +2 -1
@@ -0,0 +1,1158 @@
1
+ <!--
2
+ Les notes d'un projet : des pages, des sous-pages, des tags et des liens,
3
+ dans l'esprit de Notion.
4
+
5
+ A gauche l'arbre des pages que je peux lire (les miennes, privees ou non,
6
+ et celles partagees au projet), filtrable par texte et par tag. A droite la
7
+ page ouverte : icone, titre, tags, visibilite, puis le texte dans
8
+ RmRichTextEditor.
9
+
10
+ Ce que l'editeur cite :
11
+ - `@` un membre (page partagee seulement : une page privee ne se lit que
12
+ par son auteur, y citer quelqu'un ne le previendrait de rien). L'API
13
+ ecrit un message dans son Inbox ;
14
+ - `@` une fiche rangee dans le projet, qui s'ouvre dans le tiroir de fiche ;
15
+ - `@` une autre page, ou une page a creer (elle nait sous la page ouverte).
16
+
17
+ Enregistrement automatique, une seconde apres la derniere frappe. Chaque
18
+ sauvegarde porte la version chargee : si quelqu'un a enregistre entre-temps,
19
+ l'API refuse (409) et la page le dit, plutot que d'ecraser son travail.
20
+
21
+ La page ouverte vit dans l'URL (`?note=`), comme l'onglet.
22
+ -->
23
+ <template>
24
+ <div class="project_notes">
25
+ <aside class="project_notes_side" :aria-label="en ? 'Notes' : 'Notes'">
26
+ <div class="project_notes_side_head">
27
+ <RmInput v-model="query" :placeholder="en ? 'Search the notes' : 'Chercher dans les notes'" />
28
+ <RmButton size="sm" prefix-icon="Plus" block :loading="creating" @click="createAndOpen()">
29
+ {{ en ? "New note" : "Nouvelle note" }}
30
+ </RmButton>
31
+ </div>
32
+
33
+ <div v-if="tags.length" class="project_notes_tags" :aria-label="en ? 'Filter by tag' : 'Filtrer par tag'">
34
+ <button
35
+ v-for="entry in tags"
36
+ :key="entry.tag"
37
+ type="button"
38
+ class="project_notes_tagfilter"
39
+ :class="{ 'is-on': tagFilter === entry.tag }"
40
+ :aria-pressed="tagFilter === entry.tag"
41
+ @click="tagFilter = tagFilter === entry.tag ? '' : entry.tag"
42
+ >
43
+ #{{ entry.tag }} <span>{{ entry.count }}</span>
44
+ </button>
45
+ </div>
46
+
47
+ <p v-if="listLoading && !notes.length" class="project_notes_hint">{{ en ? "Loading…" : "Chargement…" }}</p>
48
+ <p v-else-if="!rows.length" class="project_notes_hint">
49
+ {{ filtering ? (en ? "No note matches." : "Aucune note ne correspond.") : en ? "No note yet." : "Aucune note pour l'instant." }}
50
+ </p>
51
+
52
+ <ul class="project_notes_tree" role="tree">
53
+ <li
54
+ v-for="row in rows"
55
+ :key="row.note.id"
56
+ role="treeitem"
57
+ :aria-selected="row.note.id === openId"
58
+ :aria-expanded="row.hasChildren ? !collapsed.has(row.note.id) : undefined"
59
+ >
60
+ <div
61
+ class="project_notes_row"
62
+ :class="{ 'is-open': row.note.id === openId }"
63
+ :style="{ paddingLeft: `${8 + row.depth * 16}px` }"
64
+ >
65
+ <button
66
+ v-if="row.hasChildren && !filtering"
67
+ type="button"
68
+ class="project_notes_caret"
69
+ :aria-label="collapsed.has(row.note.id) ? (en ? 'Expand' : 'Déplier') : en ? 'Collapse' : 'Replier'"
70
+ @click="toggle(row.note.id)"
71
+ >
72
+ <RmIcon :name="collapsed.has(row.note.id) ? 'CaretRight' : 'CaretDown'" :size="12" />
73
+ </button>
74
+ <span v-else class="project_notes_caret" />
75
+ <button type="button" class="project_notes_link" @click="open(row.note.id)">
76
+ <span class="project_notes_icon">{{ row.note.icon || "📄" }}</span>
77
+ <span class="project_notes_name">{{ row.note.title || untitled }}</span>
78
+ <RmIcon
79
+ v-if="row.note.visibility === 'private'"
80
+ name="LockSimple"
81
+ :size="12"
82
+ class="project_notes_lock"
83
+ :aria-label="en ? 'Private' : 'Privée'"
84
+ />
85
+ </button>
86
+ <button
87
+ type="button"
88
+ class="project_notes_add"
89
+ :title="en ? 'Add a subnote' : 'Ajouter une sous-note'"
90
+ :aria-label="en ? 'Add a subnote' : 'Ajouter une sous-note'"
91
+ @click="createAndOpen({ parentId: row.note.id })"
92
+ >
93
+ <RmIcon name="Plus" :size="12" />
94
+ </button>
95
+ </div>
96
+ </li>
97
+ </ul>
98
+ </aside>
99
+
100
+ <section class="project_notes_main">
101
+ <RmEmptyState
102
+ v-if="!current && !pageLoading"
103
+ icon="Notebook"
104
+ tone="primary"
105
+ :title="en ? 'Write down what the project teaches you' : 'Notez ce que le projet vous apprend'"
106
+ :text="
107
+ en
108
+ ? 'Notes, subnotes, tags, tables. Type @ to cite a member, a record of the project or another note.'
109
+ : 'Des notes, des sous-notes, des tags, des tableaux. Tapez @ pour citer un membre, une fiche du projet ou une autre note.'
110
+ "
111
+ :action-label="en ? 'New note' : 'Nouvelle note'"
112
+ action-icon="Plus"
113
+ @action="createAndOpen()"
114
+ />
115
+
116
+ <p v-else-if="pageLoading && !current" class="project_notes_hint">{{ en ? "Loading…" : "Chargement…" }}</p>
117
+
118
+ <article v-else-if="current" class="project_note">
119
+ <RmCallout v-if="conflict" tone="warning" class="project_note_conflict">
120
+ {{
121
+ en
122
+ ? `${conflict.updatedByName || "Someone"} saved this note while you were editing it. Your last changes were not saved.`
123
+ : `${conflict.updatedByName || "Quelqu'un"} a enregistré cette note pendant que vous la modifiiez. Vos dernières modifications n'ont pas été enregistrées.`
124
+ }}
125
+ <template #actions>
126
+ <RmButton size="sm" variant="secondary" @click="reloadFromConflict">
127
+ {{ en ? "Load their version" : "Charger sa version" }}
128
+ </RmButton>
129
+ <RmButton size="sm" variant="tertiary" @click="overwriteConflict">
130
+ {{ en ? "Keep mine" : "Garder la mienne" }}
131
+ </RmButton>
132
+ </template>
133
+ </RmCallout>
134
+
135
+ <nav v-if="trail.length" class="project_note_trail" :aria-label="en ? 'Parent notes' : 'Notes parentes'">
136
+ <template v-for="(page, i) in trail" :key="page.id">
137
+ <button type="button" @click="open(page.id)">{{ page.icon || "📄" }} {{ page.title || untitled }}</button>
138
+ <RmIcon v-if="i < trail.length - 1" name="CaretRight" :size="10" />
139
+ </template>
140
+ </nav>
141
+
142
+ <div class="project_note_head">
143
+ <button
144
+ ref="iconButton"
145
+ type="button"
146
+ class="project_note_icon"
147
+ :title="en ? 'Change the icon' : 'Changer l\'icône'"
148
+ :aria-label="en ? 'Change the icon' : 'Changer l\'icône'"
149
+ :aria-expanded="pickingIcon"
150
+ @click="pickingIcon = !pickingIcon"
151
+ >
152
+ {{ draft.icon || "📄" }}
153
+ </button>
154
+ <input
155
+ v-model="draft.title"
156
+ class="project_note_title"
157
+ :placeholder="untitled"
158
+ :aria-label="en ? 'Note title' : 'Titre de la note'"
159
+ maxlength="300"
160
+ @input="schedule"
161
+ >
162
+ <RmFilterDropdown
163
+ v-if="current.canChangeVisibility"
164
+ class="project_note_filter project_note_access"
165
+ :label="en ? 'Access' : 'Accès'"
166
+ :multiple="false"
167
+ :searchable="false"
168
+ :options="[
169
+ { value: 'private', label: en ? 'Private' : 'Privée' },
170
+ { value: 'project', label: en ? 'Shared with the project' : 'Partagée au projet' },
171
+ ]"
172
+ :model-value="[draft.visibility]"
173
+ :lang="en ? 'en' : 'fr'"
174
+ @update:model-value="(value: string[]) => setVisibility(value[0])"
175
+ />
176
+ <RmBadge v-else class="project_note_access" variant="info">{{ en ? "Shared with the project" : "Partagée au projet" }}</RmBadge>
177
+ <RmButton
178
+ v-if="current.canDelete"
179
+ class="project_note_access"
180
+ size="sm"
181
+ variant="secondary"
182
+ icon-only
183
+ :aria-label="en ? 'Delete the note' : 'Supprimer la note'"
184
+ :title="en ? 'Delete the note' : 'Supprimer la note'"
185
+ @click="deleting = true"
186
+ >
187
+ <RmIcon name="Trash" :size="16" />
188
+ </RmButton>
189
+ <div
190
+ v-if="pickingIcon"
191
+ ref="iconPanel"
192
+ class="project_note_icons"
193
+ role="listbox"
194
+ :aria-label="en ? 'Icons' : 'Icônes'"
195
+ >
196
+ <template v-for="group in ICON_GROUPS" :key="group.fr">
197
+ <p class="project_note_icons_title">{{ en ? group.en : group.fr }}</p>
198
+ <button
199
+ v-for="emoji in group.icons"
200
+ :key="emoji"
201
+ type="button"
202
+ role="option"
203
+ :aria-selected="draft.icon === emoji"
204
+ @click="setIcon(emoji)"
205
+ >
206
+ {{ emoji }}
207
+ </button>
208
+ </template>
209
+ <button type="button" class="project_note_icons_none" @click="setIcon(null)">
210
+ {{ en ? "No icon" : "Sans icône" }}
211
+ </button>
212
+ </div>
213
+ </div>
214
+
215
+ <div class="project_note_meta">
216
+ <span class="project_note_by">
217
+ {{ editedLine }}
218
+ </span>
219
+ <span class="project_note_status" :class="`is-${status}`" role="status">{{ statusLabel }}</span>
220
+ </div>
221
+
222
+ <div class="project_note_tags">
223
+ <RmTag v-for="tag in draft.tags" :key="tag" variant="violet" closable @close="removeTag(tag)">#{{ tag }}</RmTag>
224
+ <RmFilterDropdown
225
+ trigger="add"
226
+ :label="en ? 'Add a tag' : 'Ajouter un tag'"
227
+ creatable
228
+ :options="tagOptions"
229
+ :model-value="draft.tags"
230
+ :search-placeholder="en ? 'Find or create a tag' : 'Chercher ou créer un tag'"
231
+ :lang="en ? 'en' : 'fr'"
232
+ @update:model-value="setTags"
233
+ @create="addTagOption"
234
+ />
235
+ </div>
236
+
237
+ <RmRichTextEditor
238
+ :key="current.id"
239
+ v-model="draft.content"
240
+ class="project_note_editor"
241
+ :members="draft.visibility === 'project' ? members : []"
242
+ :pages="linkablePages"
243
+ :search-resources="searchResources"
244
+ :create-page="createLinkedPage"
245
+ :mention-hint="mentionHint"
246
+ @update:model-value="schedule"
247
+ @open-page="open"
248
+ @open-resource="openResource"
249
+ />
250
+
251
+ <footer v-if="current.backlinks?.length" class="project_note_backlinks">
252
+ <h3>{{ en ? "Notes linking here" : "Notes qui renvoient ici" }}</h3>
253
+ <button v-for="page in current.backlinks" :key="page.id" type="button" @click="open(page.id)">
254
+ {{ page.icon || "📄" }} {{ page.title || untitled }}
255
+ </button>
256
+ </footer>
257
+ </article>
258
+ </section>
259
+
260
+ <RmModal v-model="deleting" size="sm" mode="free" :label="en ? 'Delete the note?' : 'Supprimer la note ?'">
261
+ <template #header>
262
+ <p class="project_notes_modal_title">{{ en ? "Delete the note?" : "Supprimer la note ?" }}</p>
263
+ </template>
264
+ <p class="project_notes_modal_text">
265
+ {{
266
+ en
267
+ ? "The note is deleted for everyone. Its subnotes are kept and move up one level."
268
+ : "La note est supprimée pour tout le monde. Ses sous-notes sont gardées et remontent d'un niveau."
269
+ }}
270
+ </p>
271
+ <template #footer>
272
+ <div class="project_notes_modal_actions">
273
+ <RmButton variant="tertiary" @click="deleting = false">{{ en ? "Cancel" : "Annuler" }}</RmButton>
274
+ <RmButton variant="danger" @click="removeCurrent">{{ en ? "Delete" : "Supprimer" }}</RmButton>
275
+ </div>
276
+ </template>
277
+ </RmModal>
278
+ </div>
279
+ </template>
280
+
281
+ <script setup lang="ts">
282
+ import { useOipApi } from "#oip-app/api";
283
+ import type { ProjectNote, ProjectNoteChange, ProjectNoteSummary, ProjectUser } from "../../types/projects";
284
+ import { projectNoteWelcome } from "../../utils/projectNoteWelcome";
285
+
286
+ type CitableResource = { type: string; id: string; label: string; family: string; path: string };
287
+
288
+ const props = defineProps<{
289
+ projectId: string;
290
+ /** Les membres du projet, pour `@`. */
291
+ users: ProjectUser[];
292
+ /** Les fiches rangees dans le projet, pour `@`. */
293
+ resources: CitableResource[];
294
+ }>();
295
+
296
+ const emit = defineEmits<{
297
+ /** Une fiche citee, a ouvrir dans le tiroir. */
298
+ "open-resource": [row: { type: string; id: string; label: string; path: string }];
299
+ }>();
300
+
301
+ const { locale } = useI18n();
302
+ const en = computed(() => locale.value === "en");
303
+ const untitled = computed(() => (en.value ? "Untitled" : "Sans titre"));
304
+ const route = useRoute();
305
+ const router = useRouter();
306
+ const api = useOipApi().projectNotes;
307
+ const { data: session } = useAuth();
308
+
309
+ /** Le choix d'icones, par theme : le medical d'abord, c'est le sujet des projets (essais, etablissements, investigateurs). */
310
+ const ICON_GROUPS = [
311
+ {
312
+ fr: "Médical",
313
+ en: "Medical",
314
+ icons: ["💊", "💉", "🩺", "🩸", "🩹", "🩻", "🧬", "🦠", "🧪", "🧫", "🔬", "🫀", "🫁", "🧠", "🦴", "🦷", "👁️", "🏥", "🚑", "⚕️", "🧑‍⚕️", "🧑‍🔬", "🥼", "♿"],
315
+ },
316
+ {
317
+ fr: "Recherche et données",
318
+ en: "Research and data",
319
+ icons: ["📊", "📈", "📉", "📚", "🏷️", "⚖️", "🏛️", "🌍", "📋", "📑", "🗂️", "📅"],
320
+ },
321
+ {
322
+ fr: "Suivi",
323
+ en: "Follow-up",
324
+ icons: ["📄", "📝", "✅", "⚠️", "💡", "🎯", "🚀", "📌", "🔔", "⭐", "🤝", "🧭"],
325
+ },
326
+ ];
327
+
328
+ // ------------------------------------------------------------------ liste
329
+
330
+ const notes = ref<ProjectNoteSummary[]>([]);
331
+ const tags = ref<Array<{ tag: string; count: number }>>([]);
332
+ const listLoading = ref(false);
333
+ const query = ref("");
334
+ const tagFilter = ref("");
335
+ const filtering = computed(() => !!query.value.trim() || !!tagFilter.value);
336
+ const matches = ref<Set<string> | null>(null);
337
+ const collapsed = ref(new Set<string>());
338
+
339
+ async function loadList() {
340
+ listLoading.value = true;
341
+ try {
342
+ const [list, tagList] = await Promise.all([api.list(props.projectId), api.tags(props.projectId)]);
343
+ notes.value = list.notes;
344
+ tags.value = tagList.tags;
345
+ } catch {
346
+ // La liste reste celle d'avant : mieux qu'un arbre vide.
347
+ } finally {
348
+ listLoading.value = false;
349
+ }
350
+ }
351
+
352
+ // La recherche porte aussi sur le texte des pages : c'est l'API qui la fait.
353
+ let searchTimer: ReturnType<typeof setTimeout> | undefined;
354
+ watch([query, tagFilter], () => {
355
+ clearTimeout(searchTimer);
356
+ if (!filtering.value) {
357
+ matches.value = null;
358
+ return;
359
+ }
360
+ searchTimer = setTimeout(async () => {
361
+ try {
362
+ const found = await api.list(props.projectId, { q: query.value.trim(), tag: tagFilter.value });
363
+ matches.value = new Set(found.notes.map((note) => note.id));
364
+ } catch {
365
+ matches.value = new Set();
366
+ }
367
+ }, 250);
368
+ });
369
+
370
+ /**
371
+ * L'arbre aplati, dans l'ordre de lecture. Une page dont le parent m'est
372
+ * invisible (privee d'un autre) se range a la racine. En recherche, la liste
373
+ * est plate : les pages trouvees, sans leurs parents.
374
+ */
375
+ const rows = computed(() => {
376
+ if (filtering.value) {
377
+ return notes.value
378
+ .filter((note) => matches.value?.has(note.id))
379
+ .map((note) => ({ note, depth: 0, hasChildren: false }));
380
+ }
381
+ const known = new Set(notes.value.map((note) => note.id));
382
+ const children = new Map<string | null, ProjectNoteSummary[]>();
383
+ for (const note of notes.value) {
384
+ const parent = note.parentId && known.has(note.parentId) ? note.parentId : null;
385
+ children.set(parent, [...(children.get(parent) ?? []), note]);
386
+ }
387
+ const out: Array<{ note: ProjectNoteSummary; depth: number; hasChildren: boolean }> = [];
388
+ const walk = (parent: string | null, depth: number) => {
389
+ for (const note of children.get(parent) ?? []) {
390
+ const kids = children.get(note.id)?.length ?? 0;
391
+ out.push({ note, depth, hasChildren: kids > 0 });
392
+ if (kids && !collapsed.value.has(note.id)) walk(note.id, depth + 1);
393
+ }
394
+ };
395
+ walk(null, 0);
396
+ return out;
397
+ });
398
+
399
+ function toggle(id: string) {
400
+ const next = new Set(collapsed.value);
401
+ if (next.has(id)) next.delete(id);
402
+ else next.add(id);
403
+ collapsed.value = next;
404
+ }
405
+
406
+ // ------------------------------------------------------------------ page ouverte
407
+
408
+ const openId = ref("");
409
+ const current = ref<ProjectNote | null>(null);
410
+ const pageLoading = ref(false);
411
+ const draft = reactive({
412
+ title: "",
413
+ icon: null as string | null,
414
+ visibility: "private" as "private" | "project",
415
+ tags: [] as string[],
416
+ content: null as Record<string, unknown> | null,
417
+ });
418
+ const pickingIcon = ref(false);
419
+
420
+ function fill(note: ProjectNote) {
421
+ current.value = note;
422
+ draft.title = note.title;
423
+ draft.icon = note.icon;
424
+ draft.visibility = note.visibility;
425
+ draft.tags = [...note.tags];
426
+ draft.content = note.content;
427
+ }
428
+
429
+ /** Les ancetres de la page ouverte, du plus haut au plus proche. */
430
+ const trail = computed(() => {
431
+ const byId = new Map(notes.value.map((note) => [note.id, note]));
432
+ const out: ProjectNoteSummary[] = [];
433
+ let parent = current.value?.parentId ? byId.get(current.value.parentId) : undefined;
434
+ while (parent && out.length < 20) {
435
+ out.unshift(parent);
436
+ parent = parent.parentId ? byId.get(parent.parentId) : undefined;
437
+ }
438
+ return out;
439
+ });
440
+
441
+ async function open(id: string) {
442
+ if (!id || id === openId.value) return;
443
+ await flush();
444
+ openId.value = id;
445
+ pickingIcon.value = false;
446
+ conflict.value = null;
447
+ router.replace({ query: { ...route.query, note: id } });
448
+ pageLoading.value = true;
449
+ try {
450
+ const { note } = await api.get(id);
451
+ if (openId.value === id) fill(note);
452
+ } catch {
453
+ // Page supprimee ou devenue privee : on revient a l'accueil des notes.
454
+ if (openId.value === id) close();
455
+ } finally {
456
+ pageLoading.value = false;
457
+ }
458
+ }
459
+
460
+ function close() {
461
+ openId.value = "";
462
+ current.value = null;
463
+ const { note: _note, ...rest } = route.query;
464
+ router.replace({ query: rest });
465
+ }
466
+
467
+ // ------------------------------------------------------------------ enregistrement
468
+
469
+ type Status = "idle" | "saving" | "saved" | "error" | "conflict";
470
+ const status = ref<Status>("idle");
471
+ const conflict = ref<ProjectNote | null>(null);
472
+ let saveTimer: ReturnType<typeof setTimeout> | undefined;
473
+ let saving: Promise<void> | null = null;
474
+ let dirty = false;
475
+
476
+ const statusLabel = computed(() => {
477
+ const labels: Record<Status, [string, string]> = {
478
+ idle: ["", ""],
479
+ saving: ["Saving…", "Enregistrement…"],
480
+ saved: ["Saved", "Enregistré"],
481
+ error: ["Not saved, retrying at the next change", "Non enregistré, nouvel essai à la prochaine modification"],
482
+ conflict: ["Not saved", "Non enregistré"],
483
+ };
484
+ return labels[status.value][en.value ? 0 : 1];
485
+ });
486
+
487
+ function schedule() {
488
+ if (!current.value || conflict.value) return;
489
+ dirty = true;
490
+ clearTimeout(saveTimer);
491
+ saveTimer = setTimeout(() => void save(), 1000);
492
+ }
493
+
494
+ /** Ce qui a change depuis la version chargee. */
495
+ function changes(): ProjectNoteChange {
496
+ const note = current.value!;
497
+ const out: ProjectNoteChange = {};
498
+ if (draft.title !== note.title) out.title = draft.title;
499
+ if (draft.icon !== note.icon) out.icon = draft.icon;
500
+ if (draft.visibility !== note.visibility) out.visibility = draft.visibility;
501
+ if (draft.tags.join("\u0000") !== note.tags.join("\u0000")) out.tags = draft.tags;
502
+ if (JSON.stringify(draft.content) !== JSON.stringify(note.content)) out.content = draft.content;
503
+ return out;
504
+ }
505
+
506
+ async function save(force = false) {
507
+ if (saving) await saving;
508
+ const note = current.value;
509
+ if (!note || (!dirty && !force)) return;
510
+ const change = changes();
511
+ dirty = false;
512
+ if (!Object.keys(change).length) return;
513
+ status.value = "saving";
514
+ saving = (async () => {
515
+ try {
516
+ const { note: saved } = await api.update(note.id, note.version, change);
517
+ // Le texte tape pendant l'envoi reste dans le brouillon : seule la
518
+ // version de reference avance.
519
+ current.value = { ...saved, backlinks: note.backlinks };
520
+ status.value = "saved";
521
+ syncSummary(saved);
522
+ } catch (error: any) {
523
+ if (error?.response?.status === 409 && error?.data?.note) {
524
+ conflict.value = error.data.note;
525
+ status.value = "conflict";
526
+ } else {
527
+ dirty = true;
528
+ status.value = "error";
529
+ }
530
+ } finally {
531
+ saving = null;
532
+ }
533
+ })();
534
+ await saving;
535
+ }
536
+
537
+ /** Enregistre tout de suite ce qui attend (changement de page, depart). */
538
+ async function flush() {
539
+ clearTimeout(saveTimer);
540
+ if (dirty) await save();
541
+ }
542
+
543
+ function reloadFromConflict() {
544
+ if (!conflict.value) return;
545
+ fill({ ...conflict.value, backlinks: current.value?.backlinks });
546
+ conflict.value = null;
547
+ status.value = "idle";
548
+ }
549
+
550
+ /** Garder ma version : on repart de la leur comme reference, avec mon brouillon par-dessus. */
551
+ async function overwriteConflict() {
552
+ if (!conflict.value) return;
553
+ current.value = { ...conflict.value, backlinks: current.value?.backlinks };
554
+ conflict.value = null;
555
+ await save(true);
556
+ }
557
+
558
+ /** Le titre, l'icone, les tags et la visibilite se relisent dans l'arbre. */
559
+ function syncSummary(note: ProjectNoteSummary) {
560
+ const index = notes.value.findIndex((entry) => entry.id === note.id);
561
+ const summary: ProjectNoteSummary = { ...note };
562
+ delete (summary as Partial<ProjectNote>).content;
563
+ if (index >= 0) notes.value.splice(index, 1, summary);
564
+ else notes.value.push(summary);
565
+ }
566
+
567
+ watch(
568
+ () => [draft.title, draft.icon, draft.visibility],
569
+ () => {
570
+ if (!current.value) return;
571
+ const index = notes.value.findIndex((entry) => entry.id === current.value!.id);
572
+ if (index >= 0) {
573
+ notes.value[index] = { ...notes.value[index]!, title: draft.title, icon: draft.icon, visibility: draft.visibility };
574
+ }
575
+ },
576
+ );
577
+
578
+ // Le choix d'icone flotte sous l'icone : il se ferme au clic a cote et a Echap.
579
+ const iconPanel = ref<HTMLElement | null>(null);
580
+ const iconButton = ref<HTMLElement | null>(null);
581
+ function onPointerOutside(event: PointerEvent) {
582
+ const target = event.target as Node;
583
+ if (iconPanel.value?.contains(target) || iconButton.value?.contains(target)) return;
584
+ pickingIcon.value = false;
585
+ }
586
+ function onEscape(event: KeyboardEvent) {
587
+ if (event.key === "Escape") pickingIcon.value = false;
588
+ }
589
+ watch(pickingIcon, (open) => {
590
+ if (open) {
591
+ document.addEventListener("pointerdown", onPointerOutside);
592
+ document.addEventListener("keydown", onEscape);
593
+ } else {
594
+ document.removeEventListener("pointerdown", onPointerOutside);
595
+ document.removeEventListener("keydown", onEscape);
596
+ }
597
+ });
598
+ onBeforeUnmount(() => {
599
+ document.removeEventListener("pointerdown", onPointerOutside);
600
+ document.removeEventListener("keydown", onEscape);
601
+ });
602
+
603
+ function setIcon(icon: string | null) {
604
+ draft.icon = icon;
605
+ pickingIcon.value = false;
606
+ schedule();
607
+ }
608
+
609
+ function setVisibility(value: string | undefined) {
610
+ draft.visibility = value === "project" ? "project" : "private";
611
+ schedule();
612
+ }
613
+
614
+ /** Les tags du projet, plus ceux de la page qui n'y seraient pas encore. */
615
+ const tagOptions = computed(() =>
616
+ [...new Set([...tags.value.map((entry) => entry.tag), ...draft.tags])].map((tag) => ({ value: tag, label: tag })),
617
+ );
618
+
619
+ function setTags(list: string[]) {
620
+ // Sans `#` et sans doublon a la casse pres, comme l'API les range.
621
+ const seen = new Set<string>();
622
+ draft.tags = list
623
+ .map((tag) => tag.trim().replace(/^#+/, ""))
624
+ .filter((tag) => tag && !seen.has(tag.toLowerCase()) && seen.add(tag.toLowerCase()));
625
+ schedule();
626
+ }
627
+
628
+ function addTagOption(tag: string) {
629
+ const clean = tag.trim().replace(/^#+/, "");
630
+ if (clean && !tags.value.some((entry) => entry.tag.toLowerCase() === clean.toLowerCase())) {
631
+ tags.value = [...tags.value, { tag: clean, count: 1 }];
632
+ }
633
+ }
634
+
635
+ function removeTag(tag: string) {
636
+ draft.tags = draft.tags.filter((t) => t !== tag);
637
+ schedule();
638
+ }
639
+
640
+ const editedLine = computed(() => {
641
+ const note = current.value;
642
+ if (!note) return "";
643
+ const date = new Date(note.updatedAt).toLocaleDateString(en.value ? "en-GB" : "fr-FR", {
644
+ day: "numeric",
645
+ month: "long",
646
+ hour: "2-digit",
647
+ minute: "2-digit",
648
+ });
649
+ const who = note.updatedByName || note.authorName || "";
650
+ return en.value ? `Edited${who ? ` by ${who}` : ""} on ${date}` : `Modifiée${who ? ` par ${who}` : ""} le ${date}`;
651
+ });
652
+
653
+ // ------------------------------------------------------------------ creation et suppression
654
+
655
+ const creating = ref(false);
656
+
657
+ async function createPage(input: { parentId?: string; title?: string } = {}): Promise<ProjectNote | null> {
658
+ creating.value = true;
659
+ try {
660
+ await flush();
661
+ const parent = input.parentId ? notes.value.find((note) => note.id === input.parentId) : undefined;
662
+ const { note } = await api.create(props.projectId, {
663
+ title: input.title ?? "",
664
+ ...(input.parentId && { parentId: input.parentId }),
665
+ // Une sous-page nait avec la visibilite de son parent (l'API le fait
666
+ // aussi) ; une page racine nait privee.
667
+ visibility: parent?.visibility ?? "private",
668
+ });
669
+ syncSummary(note);
670
+ if (input.parentId) {
671
+ const next = new Set(collapsed.value);
672
+ next.delete(input.parentId);
673
+ collapsed.value = next;
674
+ }
675
+ return note;
676
+ } catch {
677
+ return null;
678
+ } finally {
679
+ creating.value = false;
680
+ }
681
+ }
682
+
683
+ async function createAndOpen(input: { parentId?: string } = {}) {
684
+ const note = await createPage(input);
685
+ if (note) await open(note.id);
686
+ }
687
+
688
+ /** `@` « Créer la page … » : une sous-page de la page ouverte, que l'on ne quitte pas. */
689
+ async function createLinkedPage(title: string) {
690
+ const note = await createPage({ title, parentId: current.value?.id });
691
+ if (!note) throw new Error("create failed");
692
+ return { id: note.id, label: note.title, icon: note.icon };
693
+ }
694
+
695
+ const deleting = ref(false);
696
+
697
+ async function removeCurrent() {
698
+ const note = current.value;
699
+ deleting.value = false;
700
+ if (!note) return;
701
+ try {
702
+ clearTimeout(saveTimer);
703
+ dirty = false;
704
+ await api.remove(note.id);
705
+ // Les sous-pages remontent d'un niveau, comme cote API.
706
+ notes.value = notes.value
707
+ .filter((entry) => entry.id !== note.id)
708
+ .map((entry) => (entry.parentId === note.id ? { ...entry, parentId: note.parentId } : entry));
709
+ close();
710
+ loadTags();
711
+ } catch {
712
+ status.value = "error";
713
+ }
714
+ }
715
+
716
+ async function loadTags() {
717
+ try {
718
+ tags.value = (await api.tags(props.projectId)).tags;
719
+ } catch {
720
+ // Les tags d'avant restent proposes.
721
+ }
722
+ }
723
+
724
+ // ------------------------------------------------------------------ ce que `@` cite
725
+
726
+ const me = computed(() => (session.value as any)?.user?.email as string | undefined);
727
+
728
+ const members = computed(() =>
729
+ props.users
730
+ .filter((user) => user.userId && user.email !== me.value)
731
+ .map((user) => ({
732
+ id: user.userId!,
733
+ label: user.displayName || [user.firstName, user.lastName].filter(Boolean).join(" ") || user.email,
734
+ hint: user.email,
735
+ })),
736
+ );
737
+
738
+ /** Pourquoi le menu `@` ne propose personne, quand il ne propose personne. */
739
+ const mentionHint = computed(() => {
740
+ if (draft.visibility === "private") {
741
+ return en.value
742
+ ? "Share the note with the project to mention someone."
743
+ : "Partagez la note au projet pour citer quelqu'un.";
744
+ }
745
+ if (!members.value.length) {
746
+ return en.value
747
+ ? "Nobody else is in the project yet: share the project to mention your colleagues."
748
+ : "Personne d'autre n'est encore dans le projet : partagez le projet pour citer vos collègues.";
749
+ }
750
+ return "";
751
+ });
752
+
753
+ const linkablePages = computed(() =>
754
+ notes.value
755
+ .filter((note) => note.id !== current.value?.id)
756
+ .map((note) => ({ id: note.id, label: note.title || untitled.value, icon: note.icon })),
757
+ );
758
+
759
+ const fold = (text: string) => text.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase();
760
+
761
+ /** Les documents deposes dans le projet, citables comme les fiches. */
762
+ const documents = ref<CitableResource[]>([]);
763
+ async function loadDocuments() {
764
+ try {
765
+ const { documents: list } = await useOipApi().projectDocuments.list(props.projectId);
766
+ documents.value = list.map((doc) => ({
767
+ type: "UploadedDocument",
768
+ id: doc.id,
769
+ label: doc.title || doc.fileName,
770
+ family: doc.fileName && doc.fileName !== doc.title ? `Document · ${doc.fileName}` : "Document",
771
+ path: "",
772
+ }));
773
+ } catch {
774
+ documents.value = [];
775
+ }
776
+ }
777
+
778
+ async function searchResources(text: string) {
779
+ const wanted = fold(text);
780
+ return [...props.resources, ...documents.value]
781
+ .filter((row) => fold(row.label).includes(wanted))
782
+ .slice(0, 8)
783
+ .map((row) => ({ id: row.id, resourceType: row.type, label: row.label, hint: row.family }));
784
+ }
785
+
786
+ function openResource(resource: { id: string; resourceType: string }) {
787
+ const row = [...props.resources, ...documents.value].find(
788
+ (r) => r.id === resource.id && r.type === resource.resourceType,
789
+ );
790
+ emit("open-resource", {
791
+ type: resource.resourceType,
792
+ id: resource.id,
793
+ label: row?.label ?? resource.id,
794
+ path: row?.path ?? "",
795
+ });
796
+ }
797
+
798
+ // ------------------------------------------------------------------ cycle de vie
799
+
800
+ /**
801
+ * Premiere visite d'un projet sans page : une page d'accueil privee, qui montre
802
+ * l'editeur par l'exemple. Une fois par personne et par projet (memoire du
803
+ * navigateur) : supprimee, elle ne revient pas.
804
+ */
805
+ async function welcomeOnce(): Promise<string | null> {
806
+ if (notes.value.length) return null;
807
+ const key = `project-notes-welcome:${props.projectId}`;
808
+ try {
809
+ if (localStorage.getItem(key)) return null;
810
+ localStorage.setItem(key, "1");
811
+ } catch {
812
+ return null;
813
+ }
814
+ try {
815
+ const { note } = await api.create(props.projectId, {
816
+ ...projectNoteWelcome(en.value, props.resources[0]),
817
+ visibility: "private",
818
+ });
819
+ syncSummary(note);
820
+ loadTags();
821
+ return note.id;
822
+ } catch {
823
+ return null;
824
+ }
825
+ }
826
+
827
+ onMounted(async () => {
828
+ void loadDocuments();
829
+ await loadList();
830
+ const wanted = String(route.query.note ?? "");
831
+ if (wanted) return open(wanted);
832
+ const welcome = await welcomeOnce();
833
+ if (welcome) await open(welcome);
834
+ });
835
+
836
+ // Un message de l'Inbox peut ouvrir une page alors que l'onglet est deja la.
837
+ watch(
838
+ () => route.query.note,
839
+ (value) => {
840
+ if (typeof value === "string" && value && value !== openId.value) void open(value);
841
+ },
842
+ );
843
+
844
+ onBeforeRouteLeave(() => flush());
845
+ onBeforeUnmount(() => void flush());
846
+
847
+ </script>
848
+
849
+ <style scoped>
850
+ .project_notes {
851
+ display: grid;
852
+ grid-template-columns: 260px minmax(0, 1fr);
853
+ gap: 24px;
854
+ align-items: start;
855
+ }
856
+
857
+ .project_notes_side {
858
+ position: sticky;
859
+ top: 72px;
860
+ display: flex;
861
+ flex-direction: column;
862
+ gap: 12px;
863
+ max-height: calc(100vh - 120px);
864
+ overflow-y: auto;
865
+ padding: 12px;
866
+ border: 1px solid var(--border-soft);
867
+ border-radius: var(--radius-md);
868
+ background: var(--bg-surface);
869
+ }
870
+
871
+ .project_notes_side_head {
872
+ display: flex;
873
+ flex-direction: column;
874
+ gap: 8px;
875
+ }
876
+
877
+ .project_notes_hint {
878
+ margin: 0;
879
+ color: var(--text-muted);
880
+ font-size: var(--font-13);
881
+ }
882
+
883
+ .project_notes_tags {
884
+ display: flex;
885
+ flex-wrap: wrap;
886
+ gap: 4px;
887
+ }
888
+
889
+ .project_notes_tagfilter {
890
+ padding: 2px 8px;
891
+ border: 1px solid var(--border-soft);
892
+ border-radius: var(--radius-pill);
893
+ background: transparent;
894
+ color: var(--text-secondary);
895
+ font: inherit;
896
+ font-size: var(--font-12);
897
+ cursor: pointer;
898
+ }
899
+
900
+ .project_notes_tagfilter span { color: var(--text-muted); }
901
+ .project_notes_tagfilter.is-on { border-color: var(--color-primary); background: var(--color-accent-soft); color: var(--color-primary); }
902
+
903
+ /* main.css impose ul { list-style: circle !important; margin: 10px !important } */
904
+ .project_notes_tree {
905
+ margin: 0 !important;
906
+ padding: 0;
907
+ list-style: none !important;
908
+ }
909
+
910
+ .project_notes_row {
911
+ display: flex;
912
+ align-items: center;
913
+ gap: 2px;
914
+ border-radius: var(--radius-sm);
915
+ }
916
+
917
+ .project_notes_row:hover,
918
+ .project_notes_row.is-open { background: var(--bg-hover); }
919
+ .project_notes_row.is-open .project_notes_name { color: var(--text-primary); font-weight: var(--weight-semibold); }
920
+
921
+ .project_notes_caret {
922
+ display: inline-flex;
923
+ align-items: center;
924
+ justify-content: center;
925
+ flex: none;
926
+ width: 18px;
927
+ height: 18px;
928
+ padding: 0;
929
+ border: 0;
930
+ background: transparent;
931
+ color: var(--text-muted);
932
+ cursor: pointer;
933
+ }
934
+
935
+ .project_notes_link {
936
+ display: flex;
937
+ align-items: center;
938
+ gap: 6px;
939
+ flex: 1;
940
+ min-width: 0;
941
+ padding: 5px 4px;
942
+ border: 0;
943
+ background: transparent;
944
+ color: var(--text-secondary);
945
+ font: inherit;
946
+ font-size: var(--font-13);
947
+ text-align: left;
948
+ cursor: pointer;
949
+ }
950
+
951
+ .project_notes_icon { flex: none; }
952
+ .project_notes_name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
953
+ .project_notes_lock { flex: none; color: var(--text-muted); }
954
+
955
+ .project_notes_add {
956
+ display: inline-flex;
957
+ align-items: center;
958
+ justify-content: center;
959
+ flex: none;
960
+ width: 22px;
961
+ height: 22px;
962
+ margin-right: 4px;
963
+ border: 0;
964
+ border-radius: var(--radius-sm);
965
+ background: transparent;
966
+ color: var(--text-muted);
967
+ opacity: 0;
968
+ cursor: pointer;
969
+ }
970
+
971
+ .project_notes_row:hover .project_notes_add,
972
+ .project_notes_add:focus-visible { opacity: 1; }
973
+ .project_notes_add:hover { background: var(--bg-surface-3); color: var(--text-primary); }
974
+
975
+ .project_notes_main { min-width: 0; }
976
+
977
+ .project_note {
978
+ display: flex;
979
+ flex-direction: column;
980
+ gap: 12px;
981
+ max-width: 900px;
982
+ }
983
+
984
+ .project_note_trail {
985
+ display: flex;
986
+ flex-wrap: wrap;
987
+ align-items: center;
988
+ gap: 4px;
989
+ color: var(--text-muted);
990
+ font-size: var(--font-12);
991
+ }
992
+
993
+ .project_note_trail button {
994
+ padding: 2px 4px;
995
+ border: 0;
996
+ border-radius: var(--radius-sm);
997
+ background: transparent;
998
+ color: inherit;
999
+ font: inherit;
1000
+ cursor: pointer;
1001
+ }
1002
+
1003
+ .project_note_trail button:hover { background: var(--bg-hover); color: var(--text-primary); }
1004
+
1005
+ .project_note_head {
1006
+ position: relative;
1007
+ display: flex;
1008
+ align-items: center;
1009
+ gap: 8px;
1010
+ }
1011
+
1012
+ .project_note_icon {
1013
+ flex: none;
1014
+ width: 44px;
1015
+ height: 44px;
1016
+ border: 0;
1017
+ border-radius: var(--radius-md);
1018
+ background: transparent;
1019
+ font-size: 28px;
1020
+ cursor: pointer;
1021
+ }
1022
+
1023
+ .project_note_icon:hover { background: var(--bg-hover); }
1024
+
1025
+ .project_note_title {
1026
+ flex: 1;
1027
+ min-width: 0;
1028
+ padding: 4px 0;
1029
+ border: 0;
1030
+ outline: none;
1031
+ background: transparent;
1032
+ color: var(--text-primary);
1033
+ font-family: var(--font-serif);
1034
+ font-size: var(--font-32);
1035
+ font-weight: var(--weight-bold);
1036
+ }
1037
+
1038
+ /* L'acces se lit a cote du titre : c'est la premiere chose a savoir d'une page. */
1039
+ .project_note_access {
1040
+ flex: none;
1041
+ }
1042
+
1043
+ .project_note_title::placeholder { color: var(--text-muted); }
1044
+
1045
+ /* Flotte sous l'icone, par-dessus la page : ouvrir le choix ne decale rien. */
1046
+ .project_note_icons {
1047
+ position: absolute;
1048
+ top: calc(100% + 4px);
1049
+ left: 0;
1050
+ z-index: var(--z-popover, 1000);
1051
+ display: grid;
1052
+ grid-template-columns: repeat(12, 34px);
1053
+ gap: 4px;
1054
+ padding: 8px;
1055
+ border: 1px solid var(--border-soft);
1056
+ border-radius: var(--radius-md);
1057
+ background: var(--bg-surface);
1058
+ box-shadow: var(--shadow-lg);
1059
+ }
1060
+
1061
+ .project_note_icons button {
1062
+ width: 34px;
1063
+ height: 34px;
1064
+ border: 0;
1065
+ border-radius: var(--radius-sm);
1066
+ background: transparent;
1067
+ font-size: 20px;
1068
+ cursor: pointer;
1069
+ }
1070
+
1071
+ .project_note_icons button:hover,
1072
+ .project_note_icons button[aria-selected='true'] { background: var(--bg-hover); }
1073
+
1074
+ .project_note_icons_title {
1075
+ grid-column: 1 / -1;
1076
+ margin: 4px 2px 0;
1077
+ color: var(--text-muted);
1078
+ font-size: var(--font-11);
1079
+ font-weight: var(--weight-semibold);
1080
+ text-transform: uppercase;
1081
+ letter-spacing: .04em;
1082
+ }
1083
+
1084
+ .project_note_icons .project_note_icons_none {
1085
+ grid-column: 1 / -1;
1086
+ width: auto;
1087
+ padding: 0 10px;
1088
+ color: var(--text-secondary);
1089
+ font-size: var(--font-12);
1090
+ }
1091
+
1092
+ .project_note_meta {
1093
+ display: flex;
1094
+ flex-wrap: wrap;
1095
+ align-items: center;
1096
+ gap: 12px;
1097
+ color: var(--text-muted);
1098
+ font-size: var(--font-12);
1099
+ }
1100
+
1101
+ .project_note_status { margin-left: auto; }
1102
+ .project_note_status.is-error,
1103
+ .project_note_status.is-conflict { color: var(--color-danger); }
1104
+
1105
+ .project_note_tags {
1106
+ display: flex;
1107
+ flex-wrap: wrap;
1108
+ align-items: center;
1109
+ gap: 6px;
1110
+ }
1111
+
1112
+ /* La puce de filtre a une largeur fixe pensee pour la barre de filtres :
1113
+ ici elle prend celle de son libelle. */
1114
+ .project_note_filter :deep(.filter-chip) {
1115
+ width: auto;
1116
+ max-width: 280px;
1117
+ }
1118
+
1119
+ .project_note_backlinks {
1120
+ display: flex;
1121
+ flex-direction: column;
1122
+ align-items: flex-start;
1123
+ gap: 4px;
1124
+ padding-top: 16px;
1125
+ border-top: 1px solid var(--border-soft);
1126
+ }
1127
+
1128
+ .project_note_backlinks h3 {
1129
+ margin: 0 0 4px;
1130
+ color: var(--text-muted);
1131
+ font-size: var(--font-12);
1132
+ font-weight: var(--weight-semibold);
1133
+ text-transform: uppercase;
1134
+ letter-spacing: .04em;
1135
+ }
1136
+
1137
+ .project_note_backlinks button {
1138
+ padding: 2px 6px;
1139
+ border: 0;
1140
+ border-radius: var(--radius-sm);
1141
+ background: transparent;
1142
+ color: var(--text-secondary);
1143
+ font: inherit;
1144
+ font-size: var(--font-13);
1145
+ cursor: pointer;
1146
+ }
1147
+
1148
+ .project_note_backlinks button:hover { background: var(--bg-hover); color: var(--text-primary); }
1149
+
1150
+ .project_notes_modal_title { margin: 0; font-size: 16px; font-weight: 600; }
1151
+ .project_notes_modal_text { margin: 0; font-size: 14px; }
1152
+ .project_notes_modal_actions { display: flex; justify-content: flex-end; gap: 8px; }
1153
+
1154
+ @media (max-width: 900px) {
1155
+ .project_notes { grid-template-columns: 1fr; }
1156
+ .project_notes_side { position: static; max-height: none; }
1157
+ }
1158
+ </style>