@portaki/module-sections 1.3.0 → 1.3.1
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 +5 -1
- package/portaki.catalog.json +2 -2
- package/portaki.module.json +2 -2
- package/src/host/SectionCreateModal.tsx +159 -0
- package/src/host/SectionsHostWorkspace.tsx +497 -0
- package/src/host/section-tiptap-presets.ts +156 -0
- package/src/host/sections-editor-design.ts +79 -0
- package/src/host/sections-host.types.ts +53 -0
- package/src/host/sections-toast-copy.ts +9 -0
- package/src/module.test.tsx +19 -4
- package/src/{sections-module-definition.ts → sections-module-definition.tsx} +4 -0
- package/src/test/mock-host-module-context.ts +35 -0
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portaki/module-sections",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Portaki module — editorial sections (TipTap)",
|
|
5
5
|
"license": "AGPL-3.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./src/index.tsx",
|
|
8
8
|
"dependencies": {
|
|
9
|
+
"@dnd-kit/core": "^6.3.1",
|
|
10
|
+
"@dnd-kit/sortable": "^10.0.0",
|
|
11
|
+
"@dnd-kit/utilities": "^3.2.2",
|
|
9
12
|
"@portaki/sdk": "^3.0.0",
|
|
13
|
+
"lucide-react": "^1.14.0",
|
|
10
14
|
"@tiptap/core": "^3.0.0",
|
|
11
15
|
"@tiptap/html": "^3.0.0",
|
|
12
16
|
"@tiptap/starter-kit": "^3.0.0",
|
package/portaki.catalog.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"fr": "Blocs de contenu riches (TipTap) pour le carnet d’accueil invité.",
|
|
10
10
|
"en": "Rich content blocks (TipTap) for the guest welcome book."
|
|
11
11
|
},
|
|
12
|
-
"version": "1.3.
|
|
12
|
+
"version": "1.3.1",
|
|
13
13
|
"releaseNotesUrl": "https://github.com/PortakiApp/portaki-modules/releases",
|
|
14
14
|
"changelog": [
|
|
15
15
|
{
|
|
@@ -122,6 +122,6 @@
|
|
|
122
122
|
},
|
|
123
123
|
"artifacts": {
|
|
124
124
|
"wasmUrl": "oci://ghcr.io/portakiapp/portaki-module-sections",
|
|
125
|
-
"guestEsmUrl": "https://esm.sh/@portaki/module-sections@1.3.
|
|
125
|
+
"guestEsmUrl": "https://esm.sh/@portaki/module-sections@1.3.1"
|
|
126
126
|
}
|
|
127
127
|
}
|
package/portaki.module.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"fr": "Blocs de contenu riches (TipTap) pour le carnet d’accueil invité.",
|
|
10
10
|
"en": "Rich content blocks (TipTap) for the guest welcome book."
|
|
11
11
|
},
|
|
12
|
-
"version": "1.3.
|
|
12
|
+
"version": "1.3.1",
|
|
13
13
|
"releaseNotesUrl": "https://github.com/PortakiApp/portaki-modules/releases",
|
|
14
14
|
"changelog": [
|
|
15
15
|
{
|
|
@@ -122,6 +122,6 @@
|
|
|
122
122
|
},
|
|
123
123
|
"artifacts": {
|
|
124
124
|
"wasmUrl": "oci://ghcr.io/portakiapp/portaki-module-sections",
|
|
125
|
-
"guestEsmUrl": "https://esm.sh/@portaki/module-sections@1.3.
|
|
125
|
+
"guestEsmUrl": "https://esm.sh/@portaki/module-sections@1.3.1"
|
|
126
126
|
}
|
|
127
127
|
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import type { HostModuleContext } from '@portaki/sdk'
|
|
4
|
+
import { useEffect, useState } from 'react'
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
SectionContentPresetId,
|
|
8
|
+
SectionCreateModalDesign,
|
|
9
|
+
SectionTemplateDesign,
|
|
10
|
+
} from './sections-host.types'
|
|
11
|
+
|
|
12
|
+
export type SectionCreatePayload = {
|
|
13
|
+
titleFr: string
|
|
14
|
+
titleEn: string
|
|
15
|
+
contentPreset: SectionContentPresetId
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type Props = {
|
|
19
|
+
open: boolean
|
|
20
|
+
onOpenChange: (open: boolean) => void
|
|
21
|
+
design: SectionCreateModalDesign
|
|
22
|
+
onCreate: (payload: SectionCreatePayload) => Promise<void>
|
|
23
|
+
creating?: boolean
|
|
24
|
+
shell: HostModuleContext['shell']
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function SectionCreateModal({
|
|
28
|
+
open,
|
|
29
|
+
onOpenChange,
|
|
30
|
+
design,
|
|
31
|
+
onCreate,
|
|
32
|
+
creating = false,
|
|
33
|
+
shell,
|
|
34
|
+
}: Props) {
|
|
35
|
+
const {
|
|
36
|
+
Dialog,
|
|
37
|
+
DialogContent,
|
|
38
|
+
DialogDescription,
|
|
39
|
+
DialogFooter,
|
|
40
|
+
DialogHeader,
|
|
41
|
+
DialogTitle,
|
|
42
|
+
Button,
|
|
43
|
+
Input,
|
|
44
|
+
cn,
|
|
45
|
+
} = shell
|
|
46
|
+
|
|
47
|
+
const defaultTemplate =
|
|
48
|
+
design.templates.find((t) => t.id === design.defaultTemplateId) ?? design.templates[0]
|
|
49
|
+
|
|
50
|
+
const [selectedId, setSelectedId] = useState(defaultTemplate?.id ?? '')
|
|
51
|
+
const [titleFr, setTitleFr] = useState(defaultTemplate?.titleFr ?? '')
|
|
52
|
+
|
|
53
|
+
const selected = design.templates.find((t) => t.id === selectedId) ?? defaultTemplate
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (!open || !defaultTemplate) {
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
setSelectedId(defaultTemplate.id)
|
|
60
|
+
setTitleFr(defaultTemplate.titleFr)
|
|
61
|
+
}, [open, defaultTemplate])
|
|
62
|
+
|
|
63
|
+
function selectTemplate(template: SectionTemplateDesign) {
|
|
64
|
+
setSelectedId(template.id)
|
|
65
|
+
setTitleFr(template.titleFr)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function handleSubmit() {
|
|
69
|
+
if (!selected || !titleFr.trim()) {
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
await onCreate({
|
|
73
|
+
titleFr: titleFr.trim(),
|
|
74
|
+
titleEn: selected.titleEn,
|
|
75
|
+
contentPreset: selected.contentPreset,
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
81
|
+
<DialogContent className="flex max-h-[min(92vh,calc(100%-80px))] max-w-[min(96vw,920px)] flex-col gap-0 overflow-hidden p-0">
|
|
82
|
+
<DialogHeader className="shrink-0 px-[26px] pb-4 pt-6">
|
|
83
|
+
<DialogTitle className="font-heading text-[22px] font-semibold tracking-tight">
|
|
84
|
+
{design.titleFr}
|
|
85
|
+
</DialogTitle>
|
|
86
|
+
<DialogDescription className="text-[13px] leading-relaxed text-[var(--text-muted)]">
|
|
87
|
+
{design.subtitleFr}
|
|
88
|
+
</DialogDescription>
|
|
89
|
+
</DialogHeader>
|
|
90
|
+
|
|
91
|
+
<div className="min-h-0 flex-1 overflow-y-auto px-[26px] pb-4">
|
|
92
|
+
<div className="grid grid-cols-1 gap-2.5 sm:grid-cols-2 lg:grid-cols-3">
|
|
93
|
+
{design.templates.map((template) => {
|
|
94
|
+
const active = template.id === selectedId
|
|
95
|
+
return (
|
|
96
|
+
<button
|
|
97
|
+
key={template.id}
|
|
98
|
+
type="button"
|
|
99
|
+
onClick={() => selectTemplate(template)}
|
|
100
|
+
className={cn(
|
|
101
|
+
'rounded-xl border px-3 py-3 text-left transition-colors',
|
|
102
|
+
active
|
|
103
|
+
? 'border-[var(--amber)] bg-[var(--color-amber-soft)] shadow-[inset_0_0_0_1px_rgba(245,158,11,0.35)]'
|
|
104
|
+
: 'border-[var(--border)] bg-white hover:border-[var(--border-md)] hover:bg-[var(--bg-muted)]/40',
|
|
105
|
+
)}
|
|
106
|
+
>
|
|
107
|
+
<span className="text-[22px] leading-none" aria-hidden>
|
|
108
|
+
{template.icon}
|
|
109
|
+
</span>
|
|
110
|
+
<p className="mt-2 font-heading text-[14px] font-semibold leading-snug text-[var(--text)]">
|
|
111
|
+
{template.titleFr}
|
|
112
|
+
</p>
|
|
113
|
+
<p className="mt-1 text-[12px] leading-snug text-[var(--text-muted)]">
|
|
114
|
+
{template.descriptionFr}
|
|
115
|
+
</p>
|
|
116
|
+
</button>
|
|
117
|
+
)
|
|
118
|
+
})}
|
|
119
|
+
</div>
|
|
120
|
+
|
|
121
|
+
<div className="mt-5">
|
|
122
|
+
<label className="mb-1.5 block text-[13px] font-medium text-[var(--text)]">
|
|
123
|
+
{design.titleFieldLabelFr}
|
|
124
|
+
</label>
|
|
125
|
+
<Input
|
|
126
|
+
value={titleFr}
|
|
127
|
+
onChange={(e) => setTitleFr(e.target.value)}
|
|
128
|
+
placeholder={selected?.titleFr}
|
|
129
|
+
className="h-11"
|
|
130
|
+
/>
|
|
131
|
+
<p className="mt-1.5 text-[12px] text-[var(--text-muted)]">{design.titleFieldHintFr}</p>
|
|
132
|
+
</div>
|
|
133
|
+
|
|
134
|
+
<p className="mt-4 text-[12px] text-[var(--text-muted)]">{design.footerHintFr}</p>
|
|
135
|
+
</div>
|
|
136
|
+
|
|
137
|
+
<DialogFooter className="shrink-0 flex-row items-center justify-end gap-2 border-t border-[var(--border)] bg-[var(--bg-surface)] px-[26px] py-4">
|
|
138
|
+
<Button
|
|
139
|
+
type="button"
|
|
140
|
+
variant="ghost"
|
|
141
|
+
className="text-[var(--text-muted)]"
|
|
142
|
+
disabled={creating}
|
|
143
|
+
onClick={() => onOpenChange(false)}
|
|
144
|
+
>
|
|
145
|
+
{design.cancelLabelFr}
|
|
146
|
+
</Button>
|
|
147
|
+
<Button
|
|
148
|
+
type="button"
|
|
149
|
+
className="bg-[var(--amber)] font-semibold text-[var(--text)] hover:bg-[var(--amber-solid-hover)]"
|
|
150
|
+
disabled={creating || !titleFr.trim()}
|
|
151
|
+
onClick={() => void handleSubmit()}
|
|
152
|
+
>
|
|
153
|
+
{creating ? 'Création…' : design.submitLabelFr}
|
|
154
|
+
</Button>
|
|
155
|
+
</DialogFooter>
|
|
156
|
+
</DialogContent>
|
|
157
|
+
</Dialog>
|
|
158
|
+
)
|
|
159
|
+
}
|
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import type { HostModuleContext } from '@portaki/sdk'
|
|
4
|
+
import {
|
|
5
|
+
DndContext,
|
|
6
|
+
closestCenter,
|
|
7
|
+
KeyboardSensor,
|
|
8
|
+
PointerSensor,
|
|
9
|
+
useSensor,
|
|
10
|
+
useSensors,
|
|
11
|
+
type DragEndEvent,
|
|
12
|
+
} from '@dnd-kit/core'
|
|
13
|
+
import {
|
|
14
|
+
SortableContext,
|
|
15
|
+
arrayMove,
|
|
16
|
+
sortableKeyboardCoordinates,
|
|
17
|
+
useSortable,
|
|
18
|
+
verticalListSortingStrategy,
|
|
19
|
+
} from '@dnd-kit/sortable'
|
|
20
|
+
import { CSS } from '@dnd-kit/utilities'
|
|
21
|
+
import { FileText, GripVertical, Plus, Trash2 } from 'lucide-react'
|
|
22
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
|
23
|
+
|
|
24
|
+
import { SectionCreateModal, type SectionCreatePayload } from './SectionCreateModal'
|
|
25
|
+
import { sectionsEditorDesign } from './sections-editor-design'
|
|
26
|
+
import type { SectionsEditorDesign } from './sections-host.types'
|
|
27
|
+
import { buildSectionTipTapPreset } from './section-tiptap-presets'
|
|
28
|
+
import { sectionsToastCopy } from './sections-toast-copy'
|
|
29
|
+
|
|
30
|
+
type SectionRow = {
|
|
31
|
+
id: string;
|
|
32
|
+
sortOrder: number;
|
|
33
|
+
titleFr: string;
|
|
34
|
+
titleEn: string;
|
|
35
|
+
contentFr: unknown;
|
|
36
|
+
contentEn: unknown;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
type LangTab = "fr" | "en";
|
|
40
|
+
|
|
41
|
+
const DEFAULT_DESIGN = sectionsEditorDesign
|
|
42
|
+
|
|
43
|
+
function unwrapJsonbField(raw: unknown): unknown {
|
|
44
|
+
if (raw == null) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
if (typeof raw === "string") {
|
|
48
|
+
return parseTipTapDoc(raw);
|
|
49
|
+
}
|
|
50
|
+
if (typeof raw === "object" && !Array.isArray(raw)) {
|
|
51
|
+
const record = raw as Record<string, unknown>;
|
|
52
|
+
if (record.type === "jsonb" && record.value != null) {
|
|
53
|
+
return unwrapJsonbField(record.value);
|
|
54
|
+
}
|
|
55
|
+
if (record.type === "doc") {
|
|
56
|
+
return record;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return raw;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function normalizeSectionRow(row: Record<string, unknown>): SectionRow {
|
|
63
|
+
return {
|
|
64
|
+
id: String(row.id ?? ""),
|
|
65
|
+
sortOrder: Number(row.sortOrder ?? row.sort_order ?? 0),
|
|
66
|
+
titleFr: String(row.titleFr ?? row.title_fr ?? ""),
|
|
67
|
+
titleEn: String(row.titleEn ?? row.title_en ?? ""),
|
|
68
|
+
contentFr: unwrapJsonbField(row.contentFr ?? row.content_fr),
|
|
69
|
+
contentEn: unwrapJsonbField(row.contentEn ?? row.content_en),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function tipTapValue(raw: unknown): string {
|
|
74
|
+
const doc = unwrapJsonbField(raw);
|
|
75
|
+
if (doc && typeof doc === "object") {
|
|
76
|
+
return serializeTipTapDoc(doc as Record<string, unknown>);
|
|
77
|
+
}
|
|
78
|
+
return serializeTipTapDoc(parseTipTapDoc(null));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function SortableSectionItem({
|
|
82
|
+
section,
|
|
83
|
+
selected,
|
|
84
|
+
onSelect,
|
|
85
|
+
cn,
|
|
86
|
+
}: {
|
|
87
|
+
section: SectionRow
|
|
88
|
+
selected: boolean
|
|
89
|
+
onSelect: () => void
|
|
90
|
+
cn: HostModuleContext['shell']['cn']
|
|
91
|
+
}) {
|
|
92
|
+
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
|
|
93
|
+
id: section.id,
|
|
94
|
+
});
|
|
95
|
+
const style = {
|
|
96
|
+
transform: CSS.Transform.toString(transform),
|
|
97
|
+
transition,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<li ref={setNodeRef} style={style} className={cn(isDragging && "z-10 opacity-90")}>
|
|
102
|
+
<div
|
|
103
|
+
className={cn(
|
|
104
|
+
"flex items-center gap-1 rounded-lg px-1 py-0.5",
|
|
105
|
+
selected ? "bg-[var(--amber)]/12" : "hover:bg-black/[0.03]",
|
|
106
|
+
)}
|
|
107
|
+
>
|
|
108
|
+
<button
|
|
109
|
+
type="button"
|
|
110
|
+
className="touch-none rounded p-1 text-[var(--text-muted)] hover:text-[var(--text)]"
|
|
111
|
+
aria-label="Réordonner"
|
|
112
|
+
{...attributes}
|
|
113
|
+
{...listeners}
|
|
114
|
+
>
|
|
115
|
+
<GripVertical className="size-4" aria-hidden />
|
|
116
|
+
</button>
|
|
117
|
+
<button
|
|
118
|
+
type="button"
|
|
119
|
+
onClick={onSelect}
|
|
120
|
+
className={cn(
|
|
121
|
+
"min-w-0 flex-1 rounded-md px-2 py-2 text-left text-[13px] transition-colors",
|
|
122
|
+
selected ? "font-medium text-[var(--text)]" : "text-[var(--text-muted)] hover:text-[var(--text)]",
|
|
123
|
+
)}
|
|
124
|
+
>
|
|
125
|
+
{section.titleFr || "Sans titre"}
|
|
126
|
+
</button>
|
|
127
|
+
</div>
|
|
128
|
+
</li>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function SectionsHostWorkspace({
|
|
133
|
+
ctx,
|
|
134
|
+
design = DEFAULT_DESIGN,
|
|
135
|
+
}: {
|
|
136
|
+
ctx: HostModuleContext
|
|
137
|
+
design?: SectionsEditorDesign
|
|
138
|
+
}) {
|
|
139
|
+
const { propertyId, gateway, shell } = ctx
|
|
140
|
+
const {
|
|
141
|
+
NotionLikeEditor,
|
|
142
|
+
HostEmptyPlaceholder,
|
|
143
|
+
HostUnderlineTabs,
|
|
144
|
+
Button,
|
|
145
|
+
Input,
|
|
146
|
+
cn,
|
|
147
|
+
toast,
|
|
148
|
+
parseTipTapDoc,
|
|
149
|
+
serializeTipTapDoc,
|
|
150
|
+
} = shell
|
|
151
|
+
const gatewayOps = design.gateway
|
|
152
|
+
|
|
153
|
+
const [sections, setSections] = useState<SectionRow[]>([]);
|
|
154
|
+
const [selectedId, setSelectedId] = useState<string | null>(null);
|
|
155
|
+
const [lang, setLang] = useState<LangTab>("fr");
|
|
156
|
+
const [loading, setLoading] = useState(true);
|
|
157
|
+
const [saving, setSaving] = useState(false);
|
|
158
|
+
const [creating, setCreating] = useState(false);
|
|
159
|
+
const [createModalOpen, setCreateModalOpen] = useState(false);
|
|
160
|
+
const [lastSavedAt, setLastSavedAt] = useState<Date | null>(null);
|
|
161
|
+
|
|
162
|
+
const sensors = useSensors(
|
|
163
|
+
useSensor(PointerSensor, { activationConstraint: { distance: 6 } }),
|
|
164
|
+
useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }),
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
const selected = useMemo(
|
|
168
|
+
() => sections.find((s) => s.id === selectedId) ?? null,
|
|
169
|
+
[sections, selectedId],
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
const load = useCallback(async () => {
|
|
173
|
+
setLoading(true);
|
|
174
|
+
try {
|
|
175
|
+
const data = await gateway.query<SectionRow[]>(gatewayOps.listQuery)
|
|
176
|
+
const list = data.map((row) => normalizeSectionRow(row as Record<string, unknown>));
|
|
177
|
+
setSections(list);
|
|
178
|
+
setSelectedId((prev) => {
|
|
179
|
+
if (prev && list.some((s) => s.id === prev)) {
|
|
180
|
+
return prev;
|
|
181
|
+
}
|
|
182
|
+
return list[0]?.id ?? null;
|
|
183
|
+
});
|
|
184
|
+
} catch {
|
|
185
|
+
toast.error(sectionsToastCopy.loadError)
|
|
186
|
+
} finally {
|
|
187
|
+
setLoading(false);
|
|
188
|
+
}
|
|
189
|
+
}, [propertyId, gateway, gatewayOps.listQuery, toast])
|
|
190
|
+
|
|
191
|
+
useEffect(() => {
|
|
192
|
+
void load();
|
|
193
|
+
}, [load]);
|
|
194
|
+
|
|
195
|
+
const saveSelected = useCallback(
|
|
196
|
+
async (draft: SectionRow) => {
|
|
197
|
+
setSaving(true);
|
|
198
|
+
try {
|
|
199
|
+
await gateway.command(gatewayOps.saveCommand, {
|
|
200
|
+
id: draft.id,
|
|
201
|
+
titleFr: draft.titleFr,
|
|
202
|
+
titleEn: draft.titleEn || draft.titleFr,
|
|
203
|
+
contentFr: draft.contentFr,
|
|
204
|
+
contentEn: draft.contentEn,
|
|
205
|
+
sortOrder: draft.sortOrder,
|
|
206
|
+
});
|
|
207
|
+
setLastSavedAt(new Date());
|
|
208
|
+
await load();
|
|
209
|
+
} catch {
|
|
210
|
+
toast.error(sectionsToastCopy.saveError)
|
|
211
|
+
} finally {
|
|
212
|
+
setSaving(false);
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
[gateway, gatewayOps.saveCommand, load, toast],
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
const debounceRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
219
|
+
|
|
220
|
+
const scheduleSave = useCallback(
|
|
221
|
+
(draft: SectionRow) => {
|
|
222
|
+
if (debounceRef.current) {
|
|
223
|
+
clearTimeout(debounceRef.current);
|
|
224
|
+
}
|
|
225
|
+
debounceRef.current = setTimeout(() => {
|
|
226
|
+
void saveSelected(draft);
|
|
227
|
+
}, 1200);
|
|
228
|
+
},
|
|
229
|
+
[saveSelected],
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
const updateDraft = useCallback(
|
|
233
|
+
(patch: Partial<SectionRow>) => {
|
|
234
|
+
if (!selected) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const next = { ...selected, ...patch };
|
|
238
|
+
setSections((prev) => prev.map((s) => (s.id === next.id ? next : s)));
|
|
239
|
+
scheduleSave(next);
|
|
240
|
+
},
|
|
241
|
+
[selected, scheduleSave],
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
const persistOrder = useCallback(
|
|
245
|
+
async (ordered: SectionRow[]) => {
|
|
246
|
+
try {
|
|
247
|
+
await gateway.command(gatewayOps.reorderCommand, {
|
|
248
|
+
orderedIds: ordered.map((s) => s.id),
|
|
249
|
+
});
|
|
250
|
+
} catch {
|
|
251
|
+
toast.error(sectionsToastCopy.reorderError)
|
|
252
|
+
await load();
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
[gateway, gatewayOps.reorderCommand, load, toast]
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
const onDragEnd = useCallback(
|
|
259
|
+
(event: DragEndEvent) => {
|
|
260
|
+
const { active, over } = event;
|
|
261
|
+
if (!over || active.id === over.id) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
setSections((items) => {
|
|
265
|
+
const oldIndex = items.findIndex((s) => s.id === active.id);
|
|
266
|
+
const newIndex = items.findIndex((s) => s.id === over.id);
|
|
267
|
+
const moved = arrayMove(items, oldIndex, newIndex).map((s, index) => ({
|
|
268
|
+
...s,
|
|
269
|
+
sortOrder: index,
|
|
270
|
+
}));
|
|
271
|
+
void persistOrder(moved);
|
|
272
|
+
return moved;
|
|
273
|
+
});
|
|
274
|
+
},
|
|
275
|
+
[persistOrder],
|
|
276
|
+
);
|
|
277
|
+
|
|
278
|
+
const createSection = useCallback(
|
|
279
|
+
async (payload: SectionCreatePayload) => {
|
|
280
|
+
setCreating(true);
|
|
281
|
+
const sortOrder = sections.length;
|
|
282
|
+
const id = crypto.randomUUID();
|
|
283
|
+
const { contentFr, contentEn } = buildSectionTipTapPreset(payload.contentPreset);
|
|
284
|
+
try {
|
|
285
|
+
await gateway.command(gatewayOps.saveCommand, {
|
|
286
|
+
id,
|
|
287
|
+
titleFr: payload.titleFr,
|
|
288
|
+
titleEn: payload.titleEn,
|
|
289
|
+
contentFr,
|
|
290
|
+
contentEn,
|
|
291
|
+
sortOrder,
|
|
292
|
+
});
|
|
293
|
+
setCreateModalOpen(false);
|
|
294
|
+
await load();
|
|
295
|
+
setSelectedId(id);
|
|
296
|
+
toast.success(sectionsToastCopy.createSuccess)
|
|
297
|
+
} catch {
|
|
298
|
+
toast.error(sectionsToastCopy.createError)
|
|
299
|
+
} finally {
|
|
300
|
+
setCreating(false);
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
[gateway, gatewayOps.saveCommand, sections.length, load, toast]
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
const deleteSelected = useCallback(async () => {
|
|
307
|
+
if (!selected) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
try {
|
|
311
|
+
await gateway.command(gatewayOps.deleteCommand, {
|
|
312
|
+
id: selected.id,
|
|
313
|
+
});
|
|
314
|
+
toast.success(sectionsToastCopy.deleteSuccess)
|
|
315
|
+
await load();
|
|
316
|
+
} catch {
|
|
317
|
+
toast.error(sectionsToastCopy.deleteError)
|
|
318
|
+
}
|
|
319
|
+
}, [gateway, gatewayOps.deleteCommand, selected, load, toast])
|
|
320
|
+
|
|
321
|
+
if (loading) {
|
|
322
|
+
return <p className="text-sm text-[var(--text-muted)]">Chargement des sections…</p>;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (sections.length === 0) {
|
|
326
|
+
return (
|
|
327
|
+
<>
|
|
328
|
+
<HostEmptyPlaceholder
|
|
329
|
+
icon={FileText}
|
|
330
|
+
title={design.emptyState.titleFr}
|
|
331
|
+
description={design.emptyState.descriptionFr}
|
|
332
|
+
primaryAction={{
|
|
333
|
+
label: design.emptyState.primaryActionLabelFr,
|
|
334
|
+
onClick: () => setCreateModalOpen(true),
|
|
335
|
+
}}
|
|
336
|
+
/>
|
|
337
|
+
<SectionCreateModal
|
|
338
|
+
open={createModalOpen}
|
|
339
|
+
onOpenChange={setCreateModalOpen}
|
|
340
|
+
design={design.createModal}
|
|
341
|
+
onCreate={createSection}
|
|
342
|
+
creating={creating}
|
|
343
|
+
shell={shell}
|
|
344
|
+
/>
|
|
345
|
+
</>
|
|
346
|
+
)
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const editorValue =
|
|
350
|
+
selected == null
|
|
351
|
+
? serializeTipTapDoc(parseTipTapDoc(null))
|
|
352
|
+
: lang === "fr"
|
|
353
|
+
? tipTapValue(selected.contentFr)
|
|
354
|
+
: tipTapValue(selected.contentEn);
|
|
355
|
+
|
|
356
|
+
return (
|
|
357
|
+
<div className="flex min-h-[min(70vh,720px)] flex-col gap-4 lg:flex-row">
|
|
358
|
+
<aside className="w-full shrink-0 rounded-xl border border-[var(--border)] bg-white lg:w-72">
|
|
359
|
+
<div className="flex items-center justify-between border-b border-[var(--border)] px-3 py-2.5">
|
|
360
|
+
<span className="text-[13px] font-medium text-[var(--text)]">Sections</span>
|
|
361
|
+
<Button
|
|
362
|
+
type="button"
|
|
363
|
+
variant="secondary"
|
|
364
|
+
className="min-h-8 px-3 text-xs"
|
|
365
|
+
onClick={() => setCreateModalOpen(true)}
|
|
366
|
+
>
|
|
367
|
+
<Plus className="size-4" aria-hidden />
|
|
368
|
+
Nouvelle
|
|
369
|
+
</Button>
|
|
370
|
+
</div>
|
|
371
|
+
<DndContext sensors={sensors} collisionDetection={closestCenter} onDragEnd={onDragEnd}>
|
|
372
|
+
<SortableContext items={sections.map((s) => s.id)} strategy={verticalListSortingStrategy}>
|
|
373
|
+
<ul className="max-h-[min(60vh,560px)] overflow-y-auto p-2">
|
|
374
|
+
{sections.length === 0 ? (
|
|
375
|
+
<li className="px-2 py-8 text-center">
|
|
376
|
+
<p className="text-[13px] text-[var(--text-muted)]">Aucune section pour l'instant.</p>
|
|
377
|
+
<Button
|
|
378
|
+
type="button"
|
|
379
|
+
variant="secondary"
|
|
380
|
+
className="mt-3 min-h-9 px-4 text-xs"
|
|
381
|
+
onClick={() => setCreateModalOpen(true)}
|
|
382
|
+
>
|
|
383
|
+
<Plus className="size-4" aria-hidden />
|
|
384
|
+
Nouvelle section
|
|
385
|
+
</Button>
|
|
386
|
+
</li>
|
|
387
|
+
) : (
|
|
388
|
+
sections.map((s) => (
|
|
389
|
+
<SortableSectionItem
|
|
390
|
+
key={s.id}
|
|
391
|
+
section={s}
|
|
392
|
+
selected={selectedId === s.id}
|
|
393
|
+
onSelect={() => setSelectedId(s.id)}
|
|
394
|
+
cn={cn}
|
|
395
|
+
/>
|
|
396
|
+
))
|
|
397
|
+
)}
|
|
398
|
+
</ul>
|
|
399
|
+
</SortableContext>
|
|
400
|
+
</DndContext>
|
|
401
|
+
</aside>
|
|
402
|
+
|
|
403
|
+
<div className="min-w-0 flex-1 rounded-xl border border-[var(--border)] bg-white">
|
|
404
|
+
{selected ? (
|
|
405
|
+
<>
|
|
406
|
+
<div className="flex flex-col gap-3 border-b border-[var(--border)] px-4 py-3">
|
|
407
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
408
|
+
<Input
|
|
409
|
+
value={selected.titleFr}
|
|
410
|
+
onChange={(e) => updateDraft({ titleFr: e.target.value })}
|
|
411
|
+
placeholder="Titre (FR)"
|
|
412
|
+
className="max-w-xs"
|
|
413
|
+
/>
|
|
414
|
+
<Input
|
|
415
|
+
value={selected.titleEn}
|
|
416
|
+
onChange={(e) => updateDraft({ titleEn: e.target.value })}
|
|
417
|
+
placeholder="Title (EN)"
|
|
418
|
+
className="max-w-xs"
|
|
419
|
+
/>
|
|
420
|
+
<div className="ml-auto flex items-center gap-2">
|
|
421
|
+
<span className="text-[11px] text-[var(--text-muted)]">
|
|
422
|
+
{saving
|
|
423
|
+
? "Enregistrement…"
|
|
424
|
+
: lastSavedAt
|
|
425
|
+
? `Auto-sauvegardé — ${formatRelative(lastSavedAt)}`
|
|
426
|
+
: ""}
|
|
427
|
+
</span>
|
|
428
|
+
<Button
|
|
429
|
+
type="button"
|
|
430
|
+
variant="ghost"
|
|
431
|
+
className="min-h-8 px-3 text-xs text-destructive"
|
|
432
|
+
onClick={() => void deleteSelected()}
|
|
433
|
+
>
|
|
434
|
+
<Trash2 className="size-4" aria-hidden />
|
|
435
|
+
Supprimer
|
|
436
|
+
</Button>
|
|
437
|
+
</div>
|
|
438
|
+
</div>
|
|
439
|
+
<HostUnderlineTabs
|
|
440
|
+
options={[
|
|
441
|
+
{ value: 'fr', label: 'Contenu FR' },
|
|
442
|
+
{ value: 'en', label: 'Content EN' },
|
|
443
|
+
]}
|
|
444
|
+
value={lang}
|
|
445
|
+
onChange={(value) => setLang(value as LangTab)}
|
|
446
|
+
ariaLabel="Langue du contenu"
|
|
447
|
+
/>
|
|
448
|
+
</div>
|
|
449
|
+
<div className="p-4">
|
|
450
|
+
<NotionLikeEditor
|
|
451
|
+
key={`${selected.id}-${lang}`}
|
|
452
|
+
value={editorValue}
|
|
453
|
+
onChange={(json) => {
|
|
454
|
+
try {
|
|
455
|
+
const node = JSON.parse(json) as unknown;
|
|
456
|
+
if (lang === "fr") {
|
|
457
|
+
updateDraft({ contentFr: node });
|
|
458
|
+
} else {
|
|
459
|
+
updateDraft({ contentEn: node });
|
|
460
|
+
}
|
|
461
|
+
} catch {
|
|
462
|
+
/* ignore */
|
|
463
|
+
}
|
|
464
|
+
}}
|
|
465
|
+
/>
|
|
466
|
+
</div>
|
|
467
|
+
</>
|
|
468
|
+
) : (
|
|
469
|
+
<div className="flex min-h-[320px] items-center justify-center p-8 text-[13px] text-[var(--text-muted)]">
|
|
470
|
+
Sélectionnez ou créez une section.
|
|
471
|
+
</div>
|
|
472
|
+
)}
|
|
473
|
+
</div>
|
|
474
|
+
|
|
475
|
+
<SectionCreateModal
|
|
476
|
+
open={createModalOpen}
|
|
477
|
+
onOpenChange={setCreateModalOpen}
|
|
478
|
+
design={design.createModal}
|
|
479
|
+
onCreate={createSection}
|
|
480
|
+
creating={creating}
|
|
481
|
+
shell={shell}
|
|
482
|
+
/>
|
|
483
|
+
</div>
|
|
484
|
+
)
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
function formatRelative(d: Date): string {
|
|
488
|
+
const sec = Math.round((Date.now() - d.getTime()) / 1000);
|
|
489
|
+
if (sec < 8) {
|
|
490
|
+
return "à l’instant";
|
|
491
|
+
}
|
|
492
|
+
if (sec < 60) {
|
|
493
|
+
return `il y a ${sec} s`;
|
|
494
|
+
}
|
|
495
|
+
const min = Math.round(sec / 60);
|
|
496
|
+
return `il y a ${min} min`;
|
|
497
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import type { SectionContentPresetId } from "./sections-host.types";
|
|
2
|
+
|
|
3
|
+
export type SectionTipTapPreset = {
|
|
4
|
+
contentFr: Record<string, unknown>;
|
|
5
|
+
contentEn: Record<string, unknown>;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
function textNode(value: string): Record<string, unknown> {
|
|
9
|
+
return { type: "text", text: value };
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function paragraph(...parts: string[]): Record<string, unknown> {
|
|
13
|
+
const joined = parts.filter(Boolean).join(" ");
|
|
14
|
+
return {
|
|
15
|
+
type: "paragraph",
|
|
16
|
+
content: joined ? [textNode(joined)] : [],
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function heading(level: 2 | 3, text: string): Record<string, unknown> {
|
|
21
|
+
return {
|
|
22
|
+
type: "heading",
|
|
23
|
+
attrs: { level },
|
|
24
|
+
content: text ? [textNode(text)] : [],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function bulletItem(text: string): Record<string, unknown> {
|
|
29
|
+
return {
|
|
30
|
+
type: "listItem",
|
|
31
|
+
content: [paragraph(text)],
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function bulletList(items: string[]): Record<string, unknown> {
|
|
36
|
+
return {
|
|
37
|
+
type: "bulletList",
|
|
38
|
+
content: items.map(bulletItem),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function doc(...blocks: Record<string, unknown>[]): Record<string, unknown> {
|
|
43
|
+
return { type: "doc", content: blocks };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const PRESETS: Record<SectionContentPresetId, SectionTipTapPreset> = {
|
|
47
|
+
welcome: {
|
|
48
|
+
contentFr: doc(
|
|
49
|
+
paragraph(
|
|
50
|
+
"Bienvenue ! Nous sommes ravis de vous accueillir. Voici quelques informations utiles pour profiter pleinement du logement.",
|
|
51
|
+
),
|
|
52
|
+
paragraph(
|
|
53
|
+
"N'hésitez pas à nous écrire ou à nous appeler si vous avez la moindre question pendant votre séjour.",
|
|
54
|
+
),
|
|
55
|
+
),
|
|
56
|
+
contentEn: doc(
|
|
57
|
+
paragraph(
|
|
58
|
+
"Welcome! We're delighted to host you. Here is some useful information to help you make the most of your stay.",
|
|
59
|
+
),
|
|
60
|
+
paragraph("Feel free to message or call us if you have any questions during your visit."),
|
|
61
|
+
),
|
|
62
|
+
},
|
|
63
|
+
beaches: {
|
|
64
|
+
contentFr: doc(
|
|
65
|
+
heading(2, "Plages & criques"),
|
|
66
|
+
paragraph("Nos spots préférés aux alentours :"),
|
|
67
|
+
bulletList([
|
|
68
|
+
"Plage principale — accès facile, idéale en famille",
|
|
69
|
+
"Crique sauvage — 10 min à pied, prévoir des chaussures",
|
|
70
|
+
"Spot snorkeling — eau calme le matin",
|
|
71
|
+
]),
|
|
72
|
+
),
|
|
73
|
+
contentEn: doc(
|
|
74
|
+
heading(2, "Beaches & coves"),
|
|
75
|
+
paragraph("Our favourite spots nearby:"),
|
|
76
|
+
bulletList([
|
|
77
|
+
"Main beach — easy access, great for families",
|
|
78
|
+
"Hidden cove — 10 min walk, bring suitable shoes",
|
|
79
|
+
"Snorkelling spot — calm water in the morning",
|
|
80
|
+
]),
|
|
81
|
+
),
|
|
82
|
+
},
|
|
83
|
+
restaurants: {
|
|
84
|
+
contentFr: doc(
|
|
85
|
+
heading(2, "Restaurants"),
|
|
86
|
+
paragraph("Quelques adresses que nous recommandons, par budget :"),
|
|
87
|
+
bulletList([
|
|
88
|
+
"Bistrot du port — cuisine locale, réservation conseillée",
|
|
89
|
+
"Pizzeria du village — décontracté, terrasse ombragée",
|
|
90
|
+
"Marché du samedi matin — produits frais et spécialités",
|
|
91
|
+
]),
|
|
92
|
+
),
|
|
93
|
+
contentEn: doc(
|
|
94
|
+
heading(2, "Restaurants"),
|
|
95
|
+
paragraph("A few places we recommend, by budget:"),
|
|
96
|
+
bulletList([
|
|
97
|
+
"Harbour bistro — local cuisine, booking recommended",
|
|
98
|
+
"Village pizzeria — casual, shaded terrace",
|
|
99
|
+
"Saturday market — fresh produce and regional treats",
|
|
100
|
+
]),
|
|
101
|
+
),
|
|
102
|
+
},
|
|
103
|
+
transport: {
|
|
104
|
+
contentFr: doc(
|
|
105
|
+
heading(2, "Venir & repartir"),
|
|
106
|
+
paragraph("Pour vous déplacer facilement :"),
|
|
107
|
+
bulletList([
|
|
108
|
+
"Gare la plus proche — liaisons régulières vers les grandes villes",
|
|
109
|
+
"Bus — arrêt à quelques minutes à pied",
|
|
110
|
+
"Parking — place disponible sur la propriété",
|
|
111
|
+
"Taxi / VTC — nous pouvons partager nos contacts",
|
|
112
|
+
]),
|
|
113
|
+
),
|
|
114
|
+
contentEn: doc(
|
|
115
|
+
heading(2, "Getting here & leaving"),
|
|
116
|
+
paragraph("Getting around:"),
|
|
117
|
+
bulletList([
|
|
118
|
+
"Nearest train station — regular connections to major cities",
|
|
119
|
+
"Bus — stop a few minutes' walk away",
|
|
120
|
+
"Parking — space available on the property",
|
|
121
|
+
"Taxi / ride-hailing — we can share our contacts",
|
|
122
|
+
]),
|
|
123
|
+
),
|
|
124
|
+
},
|
|
125
|
+
emergencies: {
|
|
126
|
+
contentFr: doc(
|
|
127
|
+
heading(2, "Urgences"),
|
|
128
|
+
paragraph("En cas d'urgence :"),
|
|
129
|
+
bulletList([
|
|
130
|
+
"112 — numéro d'urgence européen",
|
|
131
|
+
"Médecin / pharmacie de garde — contactez-nous",
|
|
132
|
+
"Pompiers / police — composez le 112",
|
|
133
|
+
]),
|
|
134
|
+
paragraph("Adresse du logement et codes d'accès : à compléter selon votre situation."),
|
|
135
|
+
),
|
|
136
|
+
contentEn: doc(
|
|
137
|
+
heading(2, "Emergencies"),
|
|
138
|
+
paragraph("In an emergency:"),
|
|
139
|
+
bulletList([
|
|
140
|
+
"112 — European emergency number",
|
|
141
|
+
"Doctor / on-call pharmacy — contact us",
|
|
142
|
+
"Fire / police — dial 112",
|
|
143
|
+
]),
|
|
144
|
+
paragraph("Property address and access codes: please complete for your guests."),
|
|
145
|
+
),
|
|
146
|
+
},
|
|
147
|
+
empty: {
|
|
148
|
+
contentFr: doc(paragraph("")),
|
|
149
|
+
contentEn: doc(paragraph("")),
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
/** TipTap JSON presets keyed by {@link SectionContentPresetId} (sections editor design). */
|
|
154
|
+
export function buildSectionTipTapPreset(preset: SectionContentPresetId): SectionTipTapPreset {
|
|
155
|
+
return PRESETS[preset] ?? PRESETS.empty;
|
|
156
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { SectionsEditorDesign } from './sections-host.types'
|
|
2
|
+
|
|
3
|
+
export const sectionsEditorDesign = {
|
|
4
|
+
id: 'sections-editor-v1',
|
|
5
|
+
moduleId: 'sections',
|
|
6
|
+
layout: 'sections-split-panel',
|
|
7
|
+
gateway: {
|
|
8
|
+
listQuery: 'sections.list',
|
|
9
|
+
saveCommand: 'sections.section.save',
|
|
10
|
+
deleteCommand: 'sections.section.delete',
|
|
11
|
+
reorderCommand: 'sections.reorder',
|
|
12
|
+
},
|
|
13
|
+
createModal: {
|
|
14
|
+
titleFr: 'Nouvelle section',
|
|
15
|
+
subtitleFr: 'Choisissez un modèle pour partir vite, ou créez une section vide.',
|
|
16
|
+
titleFieldLabelFr: 'Titre',
|
|
17
|
+
titleFieldHintFr: 'Visible par le voyageur, en haut de la section.',
|
|
18
|
+
footerHintFr: 'Vous pourrez renommer et réordonner ensuite.',
|
|
19
|
+
cancelLabelFr: 'Annuler',
|
|
20
|
+
submitLabelFr: 'Créer la section',
|
|
21
|
+
defaultTemplateId: 'welcome',
|
|
22
|
+
templates: [
|
|
23
|
+
{
|
|
24
|
+
id: 'welcome',
|
|
25
|
+
icon: '👋',
|
|
26
|
+
titleFr: 'Mot de bienvenue',
|
|
27
|
+
titleEn: 'Welcome message',
|
|
28
|
+
descriptionFr: "Un paragraphe d'accueil personnalisé",
|
|
29
|
+
contentPreset: 'welcome',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: 'beaches',
|
|
33
|
+
icon: '🏖️',
|
|
34
|
+
titleFr: 'Plages & criques',
|
|
35
|
+
titleEn: 'Beaches & coves',
|
|
36
|
+
descriptionFr: 'Liste de plages avec accès & distance',
|
|
37
|
+
contentPreset: 'beaches',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
id: 'restaurants',
|
|
41
|
+
icon: '🍝',
|
|
42
|
+
titleFr: 'Nos restaurants préférés',
|
|
43
|
+
titleEn: 'Our favourite restaurants',
|
|
44
|
+
descriptionFr: 'Recommandations par budget',
|
|
45
|
+
contentPreset: 'restaurants',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: 'transport',
|
|
49
|
+
icon: '🚂',
|
|
50
|
+
titleFr: 'Comment venir & repartir',
|
|
51
|
+
titleEn: 'Getting here & leaving',
|
|
52
|
+
descriptionFr: 'Train, bus, voiture, taxi',
|
|
53
|
+
contentPreset: 'transport',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
id: 'emergencies',
|
|
57
|
+
icon: '🆘',
|
|
58
|
+
titleFr: 'Urgences & numéros utiles',
|
|
59
|
+
titleEn: 'Emergencies & useful numbers',
|
|
60
|
+
descriptionFr: '112, médecin, police',
|
|
61
|
+
contentPreset: 'emergencies',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: 'empty',
|
|
65
|
+
icon: '📋',
|
|
66
|
+
titleFr: 'Vide · personnalisée',
|
|
67
|
+
titleEn: 'Empty · custom',
|
|
68
|
+
descriptionFr: "Démarrer d'une page blanche",
|
|
69
|
+
contentPreset: 'empty',
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
emptyState: {
|
|
74
|
+
titleFr: 'Aucune section pour l’instant',
|
|
75
|
+
descriptionFr:
|
|
76
|
+
'Structurez le carnet d’accueil en blocs (plages, restaurants, consignes…) visibles par vos voyageurs dans le livret.',
|
|
77
|
+
primaryActionLabelFr: 'Créer une section',
|
|
78
|
+
},
|
|
79
|
+
} satisfies SectionsEditorDesign
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export const SECTION_CONTENT_PRESET_IDS = [
|
|
2
|
+
'welcome',
|
|
3
|
+
'beaches',
|
|
4
|
+
'restaurants',
|
|
5
|
+
'transport',
|
|
6
|
+
'emergencies',
|
|
7
|
+
'empty',
|
|
8
|
+
] as const
|
|
9
|
+
|
|
10
|
+
export type SectionContentPresetId = (typeof SECTION_CONTENT_PRESET_IDS)[number]
|
|
11
|
+
|
|
12
|
+
export type SectionTemplateId = SectionContentPresetId
|
|
13
|
+
|
|
14
|
+
export type SectionsEditorEmptyStateDesign = {
|
|
15
|
+
titleFr: string
|
|
16
|
+
descriptionFr: string
|
|
17
|
+
primaryActionLabelFr: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type SectionCreateModalDesign = {
|
|
21
|
+
titleFr: string
|
|
22
|
+
subtitleFr: string
|
|
23
|
+
titleFieldLabelFr: string
|
|
24
|
+
titleFieldHintFr: string
|
|
25
|
+
footerHintFr: string
|
|
26
|
+
cancelLabelFr: string
|
|
27
|
+
submitLabelFr: string
|
|
28
|
+
defaultTemplateId: SectionTemplateId
|
|
29
|
+
templates: readonly SectionTemplateDesign[]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type SectionTemplateDesign = {
|
|
33
|
+
id: SectionTemplateId
|
|
34
|
+
icon: string
|
|
35
|
+
titleFr: string
|
|
36
|
+
titleEn: string
|
|
37
|
+
descriptionFr: string
|
|
38
|
+
contentPreset: SectionContentPresetId
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type SectionsEditorDesign = {
|
|
42
|
+
id: 'sections-editor-v1'
|
|
43
|
+
moduleId: 'sections'
|
|
44
|
+
layout: 'sections-split-panel'
|
|
45
|
+
gateway: {
|
|
46
|
+
listQuery: 'sections.list'
|
|
47
|
+
saveCommand: 'sections.section.save'
|
|
48
|
+
deleteCommand: 'sections.section.delete'
|
|
49
|
+
reorderCommand: 'sections.reorder'
|
|
50
|
+
}
|
|
51
|
+
createModal: SectionCreateModalDesign
|
|
52
|
+
emptyState: SectionsEditorEmptyStateDesign
|
|
53
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const sectionsToastCopy = {
|
|
2
|
+
loadError: 'Impossible de charger les sections.',
|
|
3
|
+
saveError: 'Enregistrement impossible.',
|
|
4
|
+
reorderError: 'Réordonnancement impossible.',
|
|
5
|
+
createSuccess: 'Section créée.',
|
|
6
|
+
createError: 'Création impossible.',
|
|
7
|
+
deleteSuccess: 'Section supprimée.',
|
|
8
|
+
deleteError: 'Suppression impossible.',
|
|
9
|
+
} as const
|
package/src/module.test.tsx
CHANGED
|
@@ -1,17 +1,32 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
import { waitFor } from '@testing-library/react'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
assertGuestSurface,
|
|
5
|
+
renderGuestModule,
|
|
6
|
+
renderHostModule,
|
|
7
|
+
} from '@portaki/sdk-test-support'
|
|
4
8
|
|
|
5
9
|
import moduleDef from './index'
|
|
10
|
+
import { createSectionsTestHostContext } from './test/mock-host-module-context'
|
|
6
11
|
|
|
7
12
|
describe('@portaki/module-sections', () => {
|
|
8
13
|
it('exposes a valid guest module definition', () => {
|
|
9
14
|
assertGuestSurface(moduleDef)
|
|
10
15
|
})
|
|
11
16
|
|
|
12
|
-
it('renders without crashing', async () => {
|
|
13
|
-
const view =
|
|
14
|
-
|
|
17
|
+
it('renders guest surface without crashing', async () => {
|
|
18
|
+
const view = renderGuestModule(moduleDef)
|
|
19
|
+
await waitFor(() => {
|
|
20
|
+
expect(view.container).toBeTruthy()
|
|
21
|
+
})
|
|
22
|
+
view.unmount()
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('renders host surface without crashing', async () => {
|
|
26
|
+
if (moduleDef.renderHost == null) {
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
const view = renderHostModule(moduleDef, createSectionsTestHostContext())
|
|
15
30
|
await waitFor(() => {
|
|
16
31
|
expect(view.container).toBeTruthy()
|
|
17
32
|
})
|
|
@@ -10,11 +10,14 @@ import {
|
|
|
10
10
|
timestamptz,
|
|
11
11
|
uuid,
|
|
12
12
|
uuidPrimaryKey,
|
|
13
|
+
type HostModuleContext,
|
|
13
14
|
type ModuleContext,
|
|
14
15
|
type PortakiFullModule,
|
|
15
16
|
} from '@portaki/sdk'
|
|
16
17
|
import type { ReactNode } from 'react'
|
|
17
18
|
|
|
19
|
+
import { SectionsHostWorkspace } from './host/SectionsHostWorkspace'
|
|
20
|
+
|
|
18
21
|
const sectionsSchema = moduleSchema([
|
|
19
22
|
table('items', 't_e_module_sections_item', {
|
|
20
23
|
columns: [
|
|
@@ -297,5 +300,6 @@ export function defineSectionsModule(render: (ctx: ModuleContext) => ReactNode):
|
|
|
297
300
|
},
|
|
298
301
|
|
|
299
302
|
render,
|
|
303
|
+
renderHost: (ctx: HostModuleContext) => <SectionsHostWorkspace ctx={ctx} />,
|
|
300
304
|
})
|
|
301
305
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { HostModuleContext, HostModuleShellComponents } from '@portaki/sdk'
|
|
2
|
+
import { createMockHostModuleContext } from '@portaki/sdk-test-support'
|
|
3
|
+
|
|
4
|
+
/** Stubs until published `@portaki/sdk-test-support` includes `shell` / `gateway`. */
|
|
5
|
+
export const mockHostShell: HostModuleShellComponents = {
|
|
6
|
+
NotionLikeEditor: () => null,
|
|
7
|
+
HostEmptyPlaceholder: () => null,
|
|
8
|
+
HostUnderlineTabs: () => null,
|
|
9
|
+
Button: () => null,
|
|
10
|
+
Input: () => null,
|
|
11
|
+
Dialog: ({ children }) => children ?? null,
|
|
12
|
+
DialogContent: ({ children }) => children ?? null,
|
|
13
|
+
DialogHeader: ({ children }) => children ?? null,
|
|
14
|
+
DialogTitle: ({ children }) => children ?? null,
|
|
15
|
+
DialogDescription: ({ children }) => children ?? null,
|
|
16
|
+
DialogFooter: ({ children }) => children ?? null,
|
|
17
|
+
cn: (...parts) => parts.filter(Boolean).join(' '),
|
|
18
|
+
toast: { success: () => {}, error: () => {} },
|
|
19
|
+
parseTipTapDoc: () => ({ type: 'doc', content: [{ type: 'paragraph' }] }),
|
|
20
|
+
serializeTipTapDoc: (doc) => JSON.stringify(doc),
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function createSectionsTestHostContext(
|
|
24
|
+
overrides: Partial<HostModuleContext> = {},
|
|
25
|
+
): HostModuleContext {
|
|
26
|
+
const base = createMockHostModuleContext(overrides)
|
|
27
|
+
return {
|
|
28
|
+
...base,
|
|
29
|
+
gateway: overrides.gateway ?? base.gateway ?? {
|
|
30
|
+
query: async <T,>() => [] as T,
|
|
31
|
+
command: async () => {},
|
|
32
|
+
},
|
|
33
|
+
shell: overrides.shell ?? base.shell ?? mockHostShell,
|
|
34
|
+
}
|
|
35
|
+
}
|