Merge branch 'update-wysiwyg' into 'develop'
feat: ✨ use @tiptap editor instead of reactjs-tiptap-editor
See merge request ldc-web/projets/ldc!118
This commit is contained in:
commit
416e2cf89d
27 changed files with 2408 additions and 4379 deletions
104
lang/en/back.php
104
lang/en/back.php
|
|
@ -191,28 +191,98 @@ return [
|
|||
"reset" => "reset the color",
|
||||
"delete" => "delete the color",
|
||||
],
|
||||
"wysiwyg_plugins" => [
|
||||
"link" => [
|
||||
"internal_link" => "Internal link",
|
||||
"external_link" => "External link",
|
||||
"tooltip" => "Link",
|
||||
"title" => "Insert a link",
|
||||
"subtitle" => "Configure or modify a link pointing to a specific project resource.",
|
||||
"enum" => "Select a content type",
|
||||
"entry" => "Select an entry",
|
||||
"url" => "Url to use",
|
||||
"access_url" => "Access this URL",
|
||||
"text" => "Link text",
|
||||
"switch" => "Open the link in a new tab ?",
|
||||
"link" => "Select an entry to display the associated URL",
|
||||
"delete" => "Remove this link",
|
||||
"add" => "Add this link",
|
||||
"cancel" => "Cancel adding this link",
|
||||
"wysiwyg" => [
|
||||
"undo" => "Undo",
|
||||
"redo" => "Redo",
|
||||
"bold" => "Bold",
|
||||
"italic" => "Italic",
|
||||
"strike" => "Strikethrough",
|
||||
"underline" => "Underline",
|
||||
"blockquote" => "Block quote",
|
||||
"heading" => "Heading",
|
||||
"heading_x" => "Title H:hx",
|
||||
"heading_paragraph" => "Paragraph",
|
||||
"bullet_list" => "Bullet list",
|
||||
"ordered_list" => "Numbered list",
|
||||
"task_list" => "Task list",
|
||||
"align" => "Alignement",
|
||||
"align_left" => "Align left",
|
||||
"align_center" => "Align center",
|
||||
"align_right" => "Align right",
|
||||
"align_justify" => "Justify",
|
||||
"subscript" => "Subscript",
|
||||
"superscript" => "Superscript",
|
||||
"select_all" => "Select all",
|
||||
"clear_selection" => "Clear formatting on the selection",
|
||||
"delete_selection" => "Delete the selection",
|
||||
"invisible_characters" => "Invisible characters",
|
||||
"horizontal_rule" => "Horizontal rule",
|
||||
"link" => [
|
||||
"tooltip" => "Link",
|
||||
"internal_link" => "Internal link",
|
||||
"external_link" => "External link",
|
||||
"title" => "Insert a link",
|
||||
"subtitle" => "Configure or modify a link pointing to a specific project resource.",
|
||||
"enum" => "Select a content type",
|
||||
"entry" => "Select an entry",
|
||||
"url" => "Url to use",
|
||||
"access_url" => "Access this URL",
|
||||
"text" => "Link text",
|
||||
"switch" => "Open the link in a new tab ?",
|
||||
"link" => "Select an entry to display the associated URL",
|
||||
"tooltip_delete" => "Remove this link",
|
||||
"insert" => "Insert",
|
||||
"tooltip_insert" => "Add this link",
|
||||
"cancel" => "Cancel",
|
||||
"tooltip_cancel" => "Cancel adding this link",
|
||||
"validation" => [
|
||||
"url" => "The URL must begin with http:// or https://",
|
||||
"use_internal" => "Use an internal link for this domain",
|
||||
],
|
||||
],
|
||||
"image" => [
|
||||
"tooltip" => "Image",
|
||||
"title" => "Insert an image",
|
||||
"subtitle" => "Add a new image to your content.",
|
||||
"insert" => "Insert",
|
||||
"tooltip_insert" => "Add this image",
|
||||
"cancel" => "Cancel",
|
||||
"tooltip_cancel" => "Cancel adding this image",
|
||||
"edit_title" => "Update an image",
|
||||
"edit_subtitle" => "Edit the attributes associated with the image.",
|
||||
"edit_apply" => "Apply",
|
||||
"edit_tooltip_apply" => "Update the image attributes",
|
||||
"edit_cancel" => "Cancel",
|
||||
"edit_tooltip_cancel" => "Cancel updating the image attributes",
|
||||
"alt" => "ALT attribute of the image",
|
||||
"caption" => "Caption of the image",
|
||||
],
|
||||
"table" => [
|
||||
"tooltip" => "Table",
|
||||
"title" => "Insert a table",
|
||||
"subtitle" => "Add a new table to you content.",
|
||||
"lines" => "Rows",
|
||||
"columns" => "Columns",
|
||||
"show_header" => "Show header",
|
||||
"use_arrow_keys" => "Use ↑ ↓ ← → to adjust",
|
||||
"enter_to_insert" => "Enter or click to insert",
|
||||
"insert" => "Insert",
|
||||
"tooltip_insert" => "Add the table",
|
||||
"cancel" => "Cancel",
|
||||
"tooltip_cancel" => "Cancel inserting the table",
|
||||
],
|
||||
"replace" => [
|
||||
"tooltip" => "Find and Replace",
|
||||
"title" => "Find and Replace",
|
||||
"subtitle" => "Replace specific text in your content",
|
||||
"target" => "Target text",
|
||||
"value" => "Replacement text",
|
||||
"match_case" => "Match case",
|
||||
"apply" => "Apply",
|
||||
"tooltip_apply" => "Replace the targeted content",
|
||||
"cancel" => "Cancel",
|
||||
"tooltip_cancel" => "Cancel the replacement",
|
||||
],
|
||||
],
|
||||
"json_editor" => [
|
||||
"item_single" => "1 item",
|
||||
|
|
|
|||
115
lang/fr/back.php
115
lang/fr/back.php
|
|
@ -192,38 +192,97 @@ return [
|
|||
"reset" => "réinitialiser la couleur",
|
||||
"delete" => "supprimer la couleur",
|
||||
],
|
||||
"wysiwyg_plugins" => [
|
||||
"link" => [
|
||||
"internal_link" => "Lien interne",
|
||||
"external_link" => "Lien externe",
|
||||
"tooltip" => "Lien",
|
||||
"title" => "Insérer un lien",
|
||||
"subtitle" => "Configurer ou modifier un lien pointant vers une ressource spécifique.",
|
||||
"enum" => "Sélectionner un type de contenu",
|
||||
"entry" => "Sélectionner une entrée",
|
||||
"url" => "Url à utiliser",
|
||||
"access_url" => "Accéder à cette URL",
|
||||
"text" => "Libellé",
|
||||
"switch" => "Ouvrir le lien dans un nouvel onglet ?",
|
||||
"link" => "Choisissez une entrée pour afficher l’URL associée",
|
||||
"delete" => "Supprimer ce lien",
|
||||
"add" => "Ajouter ce lien",
|
||||
"cancel" => "Annuler l’ajout de ce lien",
|
||||
"validation" => [
|
||||
"wysiwyg" => [
|
||||
"undo" => "Annuler",
|
||||
"redo" => "Rétablir",
|
||||
"bold" => "Gras",
|
||||
"italic" => "Italique",
|
||||
"strike" => "Barré",
|
||||
"underline" => "Souligné",
|
||||
"blockquote" => "Citation",
|
||||
"heading" => "Taille de police",
|
||||
"heading_paragraph" => "Paragraphe",
|
||||
"heading_x" => "Titre H:hx",
|
||||
"bullet_list" => "Liste à puces",
|
||||
"ordered_list" => "Liste numérotée",
|
||||
"task_list" => "Liste de tâches",
|
||||
"align" => "Alignement",
|
||||
"align_left" => "Aligner à gauche",
|
||||
"align_center" => "Centrer",
|
||||
"align_right" => "Aligner à droite",
|
||||
"align_justify" => "Justifier",
|
||||
"subscript" => "Indice",
|
||||
"superscript" => "Exposant",
|
||||
"select_all" => "Sélectionner tout",
|
||||
"clear_selection" => "Effacer la mise en forme sur la sélection",
|
||||
"delete_selection" => "Supprimer la sélection",
|
||||
"invisible_characters" => "Caractères invisibles",
|
||||
"horizontal_rule" => "Séparateur horizontal",
|
||||
"link" => [
|
||||
"tooltip" => "Lien",
|
||||
"internal_link" => "Lien interne",
|
||||
"external_link" => "Lien externe",
|
||||
"title" => "Insérer un lien",
|
||||
"subtitle" => "Configurer ou modifier un lien pointant vers une ressource spécifique.",
|
||||
"enum" => "Sélectionner un type de contenu",
|
||||
"entry" => "Sélectionner une entrée",
|
||||
"url" => "Url à utiliser",
|
||||
"access_url" => "Accéder à cette URL",
|
||||
"text" => "Libellé",
|
||||
"switch" => "Ouvrir le lien dans un nouvel onglet ?",
|
||||
"link" => "Choisissez une entrée pour afficher l’URL associée",
|
||||
"tooltip_delete" => "Supprimer ce lien",
|
||||
"insert" => "Insérer",
|
||||
"tooltip_insert" => "Ajouter ce lien",
|
||||
"cancel" => "Annuler",
|
||||
"tooltip_cancel" => "Annuler l’ajout de ce lien",
|
||||
"validation" => [
|
||||
"url" => "L’URL doit être un domaine valide avec protocole (https:// ou https://) et TLD (.com, .fr etc...)",
|
||||
"use_internal" => "Utilisez un lien interne pour ce domaine",
|
||||
],
|
||||
],
|
||||
"image" => [
|
||||
"tooltip" => "Image",
|
||||
"title" => "Insérer une image",
|
||||
"subtitle" => "Configurer ou modifier une image.",
|
||||
"add" => "Ajouter ce lien",
|
||||
"cancel" => "Annuler l’ajout de ce lien",
|
||||
"validation" => [
|
||||
"url" => "L’URL doit être un domaine valide avec protocole (https:// ou https://) et TLD (.com, .fr etc...)",
|
||||
"use_internal" => "Utilisez un lien interne pour ce domaine",
|
||||
],
|
||||
"image" => [
|
||||
"tooltip" => "Image",
|
||||
"title" => "Insérer une image",
|
||||
"subtitle" => "Ajouter une nouvelle image à votre contenu.",
|
||||
"insert" => "Insérer",
|
||||
"tooltip_insert" => "Ajouter cette image",
|
||||
"cancel" => "Annuler",
|
||||
"tooltip_cancel" => "Annuler l’ajout de cette image",
|
||||
"edit_title" => "Mise à jour d'une image",
|
||||
"edit_subtitle" => "Modifier les attributs associés à l'image.",
|
||||
"edit_apply" => "Appliquer",
|
||||
"edit_tooltip_apply" => "Mettre à jour les attributs de l'image",
|
||||
"edit_cancel" => "Annuler",
|
||||
"edit_tooltip_cancel" => "Annuler la mise à jour des attributs de l'image",
|
||||
"alt" => "Attribut ALT de l'image",
|
||||
"caption" => "Légende de l'image",
|
||||
],
|
||||
"table" => [
|
||||
"tooltip" => "Tableau",
|
||||
"title" => "Insérer un tableau",
|
||||
"subtitle" => "Ajouter un nouvelle tableau à votre contenu.",
|
||||
"lines" => "Lignes",
|
||||
"columns" => "Colonnes",
|
||||
"show_header" => "Afficher l'en-tête",
|
||||
"use_arrow_keys" => "Utiliser ↑ ↓ ← → pour ajuster",
|
||||
"enter_to_insert" => "Entrer ou cliquer pour insérer",
|
||||
"insert" => "Insérer",
|
||||
"tooltip_insert" => "Ajouter le tableau",
|
||||
"cancel" => "Annuler",
|
||||
"tooltip_cancel" => "Annuler l'insertion du tableau",
|
||||
],
|
||||
"replace" => [
|
||||
"tooltip" => "Chercher et remplacer",
|
||||
"title" => "Chercher et remplacer",
|
||||
"subtitle" => "Remplacement d'un texte spécifique dans votre contenu",
|
||||
"target" => "Texte ciblé",
|
||||
"value" => "Texte de remplacement",
|
||||
"match_case" => "Respecter la casse",
|
||||
"apply" => "Appliquer",
|
||||
"tooltip_apply" => "Remplacer le contenu ciblé",
|
||||
"cancel" => "Annuler",
|
||||
"tooltip_cancel" => "Annuler le remplacement",
|
||||
],
|
||||
],
|
||||
"json_editor" => [
|
||||
|
|
|
|||
4324
package-lock.json
generated
4324
package-lock.json
generated
File diff suppressed because it is too large
Load diff
34
package.json
34
package.json
|
|
@ -25,7 +25,7 @@
|
|||
"@radix-ui/react-toast": "^1.2.14",
|
||||
"@radix-ui/react-tooltip": "^1.2.7",
|
||||
"@tailwindcss/forms": "^0.5.10",
|
||||
"@tailwindcss/typography": "^0.5.16",
|
||||
"@tailwindcss/typography": "^0.5.19",
|
||||
"@tailwindcss/vite": "^4.1",
|
||||
"@types/react-color": "^3.0.13",
|
||||
"@typescript-eslint/eslint-plugin": "^8.39.0",
|
||||
|
|
@ -68,15 +68,41 @@
|
|||
"@inertiajs/react": "^2.0.17",
|
||||
"@ldc-web/cookie-notice": "^6.1.1",
|
||||
"@radix-ui/react-accordion": "^1.2.12",
|
||||
"@radix-ui/react-checkbox": "^1.3.3",
|
||||
"@radix-ui/react-popover": "^1.1.15",
|
||||
"@radix-ui/react-progress": "^1.1.7",
|
||||
"@radix-ui/react-scroll-area": "^1.2.10",
|
||||
"@radix-ui/react-slider": "^1.3.6",
|
||||
"@tanstack/react-table": "^8.21.3",
|
||||
"@tiptap/core": "^3.17.0",
|
||||
"@tiptap/extension-blockquote": "^3.17.0",
|
||||
"@tiptap/extension-bold": "^3.17.0",
|
||||
"@tiptap/extension-bullet-list": "^3.17.0",
|
||||
"@tiptap/extension-color": "^3.17.0",
|
||||
"@tiptap/extension-heading": "^3.17.0",
|
||||
"@tiptap/extension-history": "^3.17.0",
|
||||
"@tiptap/extension-horizontal-rule": "^3.17.0",
|
||||
"@tiptap/extension-image": "^3.17.0",
|
||||
"@tiptap/extension-invisible-characters": "^3.17.1",
|
||||
"@tiptap/extension-italic": "^3.17.0",
|
||||
"@tiptap/extension-list": "^3.17.1",
|
||||
"@tiptap/extension-ordered-list": "^3.17.0",
|
||||
"@tiptap/extension-placeholder": "^3.17.0",
|
||||
"@tiptap/extension-strike": "^3.17.0",
|
||||
"@tiptap/extension-subscript": "^3.17.1",
|
||||
"@tiptap/extension-superscript": "^3.17.1",
|
||||
"@tiptap/extension-table": "^3.17.1",
|
||||
"@tiptap/extension-table-cell": "^3.17.1",
|
||||
"@tiptap/extension-table-header": "^3.17.1",
|
||||
"@tiptap/extension-table-row": "^3.17.1",
|
||||
"@tiptap/extension-text-align": "^3.17.0",
|
||||
"@tiptap/extension-underline": "^3.17.0",
|
||||
"@tiptap/react": "^3.17.0",
|
||||
"@tiptap/starter-kit": "^3.17.0",
|
||||
"@types/pluralize": "^0.0.33",
|
||||
"@types/react": "^19.1.9",
|
||||
"@types/react-dom": "^19.1.7",
|
||||
"axios": "^1.11.0",
|
||||
"axios": "^1.13.2",
|
||||
"chart.js": "^4.5.1",
|
||||
"clsx": "^2.1.1",
|
||||
"cmdk": "^1.1.1",
|
||||
|
|
@ -89,11 +115,11 @@
|
|||
"react-color": "^2.19.3",
|
||||
"react-day-picker": "^9.11.1",
|
||||
"react-dropzone": "^14.3.8",
|
||||
"reactjs-tiptap-editor": "^0.3.23",
|
||||
"react-image-crop": "^11.0.10",
|
||||
"slugify": "^1.6.6",
|
||||
"tailwind-merge": "^3.3.1",
|
||||
"ziggy-js": "^2.5.3",
|
||||
"zod": "^4.2.0",
|
||||
"zod": "^4.3.6",
|
||||
"zustand": "^5.0.7"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -187,10 +187,6 @@
|
|||
font-size: 24px;
|
||||
}
|
||||
|
||||
.description {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
|
@ -922,16 +918,7 @@
|
|||
font-size: 34px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
.description {
|
||||
font-size: 17px;
|
||||
}
|
||||
.description h3 {
|
||||
line-height: 1.3;
|
||||
font-size: 24px;
|
||||
}
|
||||
.description ul li {
|
||||
font-size: 17px;
|
||||
}
|
||||
|
||||
.engagements__wrapper {
|
||||
text-align: center;
|
||||
}
|
||||
|
|
@ -2422,9 +2409,6 @@
|
|||
height: 20px;
|
||||
font-size: 11px;
|
||||
}
|
||||
.description ul li::before {
|
||||
color: white !important;
|
||||
}
|
||||
.page-contacts__title {
|
||||
margin: 0px 0 15px;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -459,111 +459,10 @@ iframe {
|
|||
text-align: center;
|
||||
}
|
||||
|
||||
.description {
|
||||
font-weight: 500;
|
||||
font-size: 14px;
|
||||
color: #666666;
|
||||
line-height: 1.75;
|
||||
}
|
||||
|
||||
.description.small {
|
||||
font-style: italic;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.description h2 {
|
||||
font-size: 28px;
|
||||
line-height: 1.2;
|
||||
margin-bottom: 0.7em;
|
||||
}
|
||||
|
||||
.description h3 {
|
||||
font-weight: 500;
|
||||
line-height: 1.3;
|
||||
font-size: 24px;
|
||||
color: #222222;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.description h4 {
|
||||
font-weight: 700;
|
||||
font-size: 18px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.description p {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.description p:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.description b {
|
||||
color: #222222;
|
||||
}
|
||||
|
||||
.description a:not(.btn) {
|
||||
display: contents;
|
||||
color: #ff4e4e;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.description a:hover {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.description .btn {
|
||||
margin: 25px 0;
|
||||
}
|
||||
|
||||
.description ul {
|
||||
padding: 20px 0 10px;
|
||||
}
|
||||
|
||||
.blocks-gallery-grid,
|
||||
.wp-block-columns,
|
||||
.wp-block-media-text {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.description ul li {
|
||||
display: flex;
|
||||
list-style: none;
|
||||
font-weight: 500;
|
||||
font-size: 16px;
|
||||
color: #222222;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.description ul li::before {
|
||||
content: "\2714 \fe0e";
|
||||
flex: 0 0 auto;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border-radius: 100%;
|
||||
background: #ff4e4e;
|
||||
font-size: 12px;
|
||||
color: white;
|
||||
line-height: 1;
|
||||
margin-right: 12px;
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
.blocks-gallery-item::before {
|
||||
content: none !important;
|
||||
}
|
||||
|
||||
.description img {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.clr::after {
|
||||
content: "";
|
||||
display: block;
|
||||
|
|
|
|||
|
|
@ -1,26 +1,32 @@
|
|||
.richtext-outline,
|
||||
.richtext-outline-1,
|
||||
.richtext-shadow {
|
||||
all: unset !important;
|
||||
}
|
||||
|
||||
.reactjs-tiptap-editor {
|
||||
@apply rounded-md border border-input bg-background;
|
||||
}
|
||||
// * Common css for @tiptap editor preview.
|
||||
@use './../../common/wysiwyg';
|
||||
|
||||
// * Custom css.
|
||||
.wysiwyg-error .reactjs-tiptap-editor {
|
||||
@apply border-destructive/50;
|
||||
}
|
||||
|
||||
.tiptap .link {
|
||||
cursor: pointer;
|
||||
}
|
||||
.tiptap {
|
||||
@apply px-3 py-2;
|
||||
|
||||
#tippy-4 {
|
||||
z-index: 1 !important;
|
||||
}
|
||||
min-height: 180px;
|
||||
|
||||
.link {
|
||||
@apply cursor-pointer;
|
||||
}
|
||||
|
||||
[data-type="taskList"] > li {
|
||||
@apply flex flex-row justify-start items-center gap-1.5;
|
||||
}
|
||||
|
||||
.is-editor-empty:first-child::before {
|
||||
@apply float-left text-muted-foreground h-0 pointer-events-none;
|
||||
|
||||
content: attr(data-placeholder);
|
||||
}
|
||||
}
|
||||
|
||||
/* stylelint-disable-next-line selector-class-pattern */
|
||||
.ProseMirror-focused {
|
||||
@apply rounded-b ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
133
resources/sass/common/_wysiwyg.scss
Normal file
133
resources/sass/common/_wysiwyg.scss
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
$primary-color: #ff4e4e;
|
||||
$secondary-color: #666666;
|
||||
$tertiary-color: #222222;
|
||||
|
||||
.description {
|
||||
font-weight: 500;
|
||||
font-size: 14px;
|
||||
color: $secondary-color;
|
||||
line-height: 1.75;
|
||||
}
|
||||
|
||||
.description.small {
|
||||
font-style: italic;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.description h2 {
|
||||
font-size: 28px;
|
||||
line-height: 1.2;
|
||||
margin-bottom: 0.7em;
|
||||
}
|
||||
|
||||
.description h3 {
|
||||
font-weight: 500;
|
||||
line-height: 1.3;
|
||||
font-size: 24px;
|
||||
color: $tertiary-color;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.description h4 {
|
||||
font-weight: 700;
|
||||
font-size: 18px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.description p {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.description p:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.description b {
|
||||
color: $tertiary-color;
|
||||
}
|
||||
|
||||
.description a:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.description a:not(.btn) {
|
||||
display: contents;
|
||||
color: $primary-color;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.description a:hover {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.description .btn {
|
||||
margin: 25px 0;
|
||||
}
|
||||
|
||||
.description ul {
|
||||
padding: 20px 0 10px;
|
||||
}
|
||||
|
||||
.blocks-gallery-grid,
|
||||
.wp-block-columns,
|
||||
.wp-block-media-text {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.description ul li {
|
||||
display: flex;
|
||||
list-style: none;
|
||||
font-weight: 500;
|
||||
font-size: 16px;
|
||||
color: $tertiary-color;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.description ul li::before {
|
||||
content: "\2714 \fe0e";
|
||||
flex: 0 0 auto;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border-radius: 100%;
|
||||
background: $primary-color;
|
||||
font-size: 12px;
|
||||
color: white;
|
||||
line-height: 1;
|
||||
margin-right: 12px;
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
.description img {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.description figure figcaption {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 1240px) {
|
||||
.description {
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
@media screen and (max-width: 767px) {
|
||||
.description {
|
||||
font-size: 17px;
|
||||
}
|
||||
.description h3 {
|
||||
line-height: 1.3;
|
||||
font-size: 24px;
|
||||
}
|
||||
.description ul li {
|
||||
font-size: 17px;
|
||||
}
|
||||
.description ul li::before {
|
||||
color: white !important;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,7 @@
|
|||
@charset 'UTF-8';
|
||||
|
||||
// * COMMON CSS.
|
||||
@use './../common/wysiwyg';
|
||||
|
||||
// * VENDOR
|
||||
@use './vendor/cookie-notice';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// * Packages
|
||||
import { Link } from "@inertiajs/react";
|
||||
import { CSSProperties, ReactNode } from "react";
|
||||
import { CSSProperties, MouseEventHandler, ReactNode } from "react";
|
||||
import { VariantProps } from "class-variance-authority";
|
||||
// * Components shadcn
|
||||
import { Button, buttonVariants } from "@/components/ui/button";
|
||||
|
|
@ -27,7 +27,7 @@ type BtnOptionnalLinkWithTooltipProps = {
|
|||
externalLink?: boolean;
|
||||
disabled?: boolean;
|
||||
style?: CSSProperties;
|
||||
onClick?: () => void;
|
||||
onClick?: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
||||
};
|
||||
|
||||
export default function BtnOptionnalLinkWithTooltip({
|
||||
|
|
|
|||
|
|
@ -0,0 +1,96 @@
|
|||
// * Packages
|
||||
import { Image as TiptapImage } from "@tiptap/extension-image";
|
||||
import { ReactNodeViewRenderer } from "@tiptap/react";
|
||||
// * Other
|
||||
import ImageNodeView, {
|
||||
ALIGN_STYLES,
|
||||
AllowedAligns,
|
||||
FLOAT_STYLES,
|
||||
FloatOption,
|
||||
} from "@/back/Components/Inputs/Wysiwyg/Extensions/Image/ImageNodeView";
|
||||
|
||||
export const Image = TiptapImage.extend({
|
||||
// Define attributes we need.
|
||||
addAttributes() {
|
||||
return {
|
||||
...this.parent?.(),
|
||||
width: null,
|
||||
height: null,
|
||||
alt: null,
|
||||
caption: null,
|
||||
style: null,
|
||||
float: null,
|
||||
};
|
||||
},
|
||||
// Rules for each tag.
|
||||
// Set all attributes if matching on simple image or figure structure.
|
||||
parseHTML() {
|
||||
return [
|
||||
{
|
||||
// Specific selector for a simple image.
|
||||
tag: "img[src]",
|
||||
getAttrs: (element: HTMLElement) => {
|
||||
const img = element as HTMLImageElement;
|
||||
|
||||
return {
|
||||
src: img.src,
|
||||
alt: img.getAttribute("alt"),
|
||||
width: img.width,
|
||||
height: img.height,
|
||||
style: null,
|
||||
caption: null,
|
||||
};
|
||||
},
|
||||
},
|
||||
{
|
||||
// Specific selector for a figure with his image.
|
||||
tag: "figure:has(img[src])",
|
||||
getAttrs: (element: HTMLElement) => {
|
||||
const img = element.querySelector(
|
||||
"img",
|
||||
) as HTMLImageElement;
|
||||
const figcaption = element.querySelector("figcaption");
|
||||
|
||||
return {
|
||||
src: img.src,
|
||||
alt: img.getAttribute("alt"),
|
||||
width: img.width,
|
||||
height: img.height,
|
||||
style: null,
|
||||
caption: figcaption?.textContent,
|
||||
};
|
||||
},
|
||||
},
|
||||
];
|
||||
},
|
||||
// Define the structure of the render.
|
||||
renderHTML({ node, HTMLAttributes }) {
|
||||
delete HTMLAttributes.caption;
|
||||
delete HTMLAttributes.float;
|
||||
|
||||
const style = [
|
||||
HTMLAttributes.style,
|
||||
node.attrs.float
|
||||
? FLOAT_STYLES[node.attrs.float as FloatOption]
|
||||
: ALIGN_STYLES[node.attrs.align as AllowedAligns] || "",
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(" ");
|
||||
|
||||
if (node.attrs.caption) {
|
||||
delete HTMLAttributes.style;
|
||||
return [
|
||||
"figure",
|
||||
{ style },
|
||||
["img", HTMLAttributes],
|
||||
["figcaption", node.attrs.caption],
|
||||
];
|
||||
}
|
||||
|
||||
return ["img", { ...HTMLAttributes, style }];
|
||||
},
|
||||
// Use a custom node view in the editor.
|
||||
addNodeView() {
|
||||
return ReactNodeViewRenderer(ImageNodeView);
|
||||
},
|
||||
});
|
||||
|
|
@ -3,7 +3,7 @@ import { useState } from "react";
|
|||
import axios from "axios";
|
||||
import { route } from "ziggy-js";
|
||||
import { ImageUpIcon } from "lucide-react";
|
||||
import { Editor } from "reactjs-tiptap-editor";
|
||||
import { Editor } from "@tiptap/react";
|
||||
import { z } from "zod";
|
||||
// * Components shadcn
|
||||
import {
|
||||
|
|
@ -24,11 +24,11 @@ import str from "@/hooks/use-string";
|
|||
type ImageProps = {
|
||||
/** Wysiwyg editor instance. */
|
||||
editor: Editor;
|
||||
/** Wysiwyg menu button tooltip. */
|
||||
tooltip: string;
|
||||
/** Disable trigger button. */
|
||||
disabled: boolean;
|
||||
};
|
||||
|
||||
export default function ImageButton({ editor, tooltip }: ImageProps) {
|
||||
export default function ImageButton({ editor, disabled }: ImageProps) {
|
||||
// Get all editor options define with customOptions in the parent SimpleWysiwyg.
|
||||
const editorOptions = editor.options.editorProps?.attributes as { [name: string]: string };
|
||||
|
||||
|
|
@ -47,6 +47,8 @@ export default function ImageButton({ editor, tooltip }: ImageProps) {
|
|||
// Duration of modal closing animation.
|
||||
const animationTime = 200;
|
||||
|
||||
const transTooltip = str(useTrans("back.wysiwyg.image.tooltip")).ucFirst().value();
|
||||
|
||||
// Zod image schema.
|
||||
const inputsSchema = z.object({
|
||||
inputFile: z
|
||||
|
|
@ -181,6 +183,11 @@ export default function ImageButton({ editor, tooltip }: ImageProps) {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set new alt attribute.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
const handleSetAlt = (name: string, value: string) => {
|
||||
setErrors((prev) => ({ ...prev, [name]: "" }));
|
||||
setInputAlt(value);
|
||||
|
|
@ -224,17 +231,17 @@ export default function ImageButton({ editor, tooltip }: ImageProps) {
|
|||
return (
|
||||
<Dialog
|
||||
open={open}
|
||||
onOpenChange={(v) => {
|
||||
setOpen(v);
|
||||
if (!v) setTimeout(() => resetComponent(), animationTime);
|
||||
onOpenChange={(status) => {
|
||||
setOpen(status);
|
||||
if (!status) setTimeout(() => resetComponent(), animationTime);
|
||||
}}
|
||||
>
|
||||
{/* Button trigger in wysiwyg navigation. */}
|
||||
<DialogTrigger asChild>
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={<ImageUpIcon className="w-4 h-4 m-auto" />}
|
||||
tooltipContent={tooltip}
|
||||
className="cursor-grab richtext-px-2 richtext-w-[32px] richtext-h-[32px]"
|
||||
tooltipContent={transTooltip}
|
||||
disabled={disabled}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
|
|
@ -243,18 +250,16 @@ export default function ImageButton({ editor, tooltip }: ImageProps) {
|
|||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
{useTrans("back.wysiwyg_plugins.image.title")}
|
||||
{useTrans("back.wysiwyg.image.title")}
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
{useTrans("back.wysiwyg_plugins.image.subtitle")}
|
||||
{useTrans("back.wysiwyg.image.subtitle")}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<CompleteInputFile
|
||||
fileName="image"
|
||||
name="image"
|
||||
label={str(useTrans("validation.custom.image"))
|
||||
.ucFirst()
|
||||
.value()}
|
||||
label={str(useTrans("validation.custom.image")).ucFirst().value()}
|
||||
setData={handleSetImage}
|
||||
reset={(name) => console.log("reset", name)}
|
||||
value={null}
|
||||
|
|
@ -269,9 +274,7 @@ export default function ImageButton({ editor, tooltip }: ImageProps) {
|
|||
/>
|
||||
<SimpleString
|
||||
name="alt"
|
||||
label={str(useTrans("validation.custom.image_alt"))
|
||||
.ucFirst()
|
||||
.value()}
|
||||
label={str(useTrans("validation.custom.image_alt")).ucFirst().value()}
|
||||
placeholder="ex: John Doe"
|
||||
required={true}
|
||||
value={inputAlt}
|
||||
|
|
@ -279,38 +282,32 @@ export default function ImageButton({ editor, tooltip }: ImageProps) {
|
|||
disabled={loading}
|
||||
parentErrors={errors}
|
||||
/>
|
||||
<div className="flex justify-between">
|
||||
<div className="flex justify-between gap-1.5">
|
||||
{/* Save button. */}
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={str(useTrans("crud.actions.save"))
|
||||
.ucFirst()
|
||||
.value()}
|
||||
tooltipContent={useTrans(
|
||||
"back.wysiwyg_plugins.image.add",
|
||||
)}
|
||||
className="cursor-pointer"
|
||||
type="button"
|
||||
size="default"
|
||||
disabled={loading}
|
||||
onClick={handleAddImage}
|
||||
/>
|
||||
{/* Cancel button. */}
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={str(useTrans("back.cancel"))
|
||||
.ucFirst()
|
||||
.value()}
|
||||
tooltipContent={useTrans(
|
||||
"back.wysiwyg_plugins.image.cancel",
|
||||
)}
|
||||
className="cursor-pointer"
|
||||
variant="secondary"
|
||||
type="button"
|
||||
size="default"
|
||||
disabled={loading}
|
||||
onClick={handleCancelImage}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex justify-center items-center gap-1.5">
|
||||
{/* Cancel button. */}
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={str(useTrans("back.wysiwyg.image.cancel")).ucFirst().value()}
|
||||
tooltipContent={useTrans(
|
||||
"back.wysiwyg.image.tooltip_cancel",
|
||||
)}
|
||||
className="cursor-pointer"
|
||||
variant="secondary"
|
||||
type="button"
|
||||
size="default"
|
||||
disabled={loading}
|
||||
onClick={handleCancelImage}
|
||||
/>
|
||||
{/* Save button. */}
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={str(useTrans("back.wysiwyg.image.insert")).ucFirst().value()}
|
||||
tooltipContent={useTrans(
|
||||
"back.wysiwyg.image.tooltip_insert",
|
||||
)}
|
||||
className="cursor-pointer"
|
||||
type="button"
|
||||
size="default"
|
||||
disabled={loading}
|
||||
onClick={handleAddImage}
|
||||
/>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
|
@ -0,0 +1,390 @@
|
|||
// * Packages
|
||||
import { NodeViewProps, NodeViewWrapper } from "@tiptap/react";
|
||||
import {
|
||||
MoveDiagonal2Icon,
|
||||
PencilIcon,
|
||||
AlignLeftIcon,
|
||||
AlignCenterIcon,
|
||||
AlignRightIcon,
|
||||
ArrowLeftRightIcon,
|
||||
ArrowRightLeftIcon,
|
||||
LayoutIcon,
|
||||
} from "lucide-react";
|
||||
import { CSSProperties, useEffect, useRef, useState } from "react";
|
||||
// * Components shadcn
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogDescription,
|
||||
} from "@/components/ui/dialog";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
} from "@/components/ui/select";
|
||||
// * Other
|
||||
import BtnOptionnalLinkWithTooltip from "@/back/Components/BtnOptionnalLinkWithTooltip";
|
||||
import SimpleString from "@/back/Components/Inputs/SimpleString";
|
||||
import useTrans from "@/hooks/use-translations";
|
||||
import str from "@/hooks/use-string";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
type ImageAttrs = {
|
||||
src: string;
|
||||
alt: string;
|
||||
width: number;
|
||||
height: number;
|
||||
caption: string | null;
|
||||
style: string;
|
||||
float: FloatOption;
|
||||
};
|
||||
|
||||
export type AllowedAligns = "left" | "center" | "right";
|
||||
|
||||
export type FloatOption = "left" | "right";
|
||||
|
||||
export const ALIGN_STYLES: Record<AllowedAligns, string> = {
|
||||
left: "margin: 0 auto 0 0; width: fit-content;",
|
||||
center: "margin: 0 auto 0 auto; width: fit-content;",
|
||||
right: "margin: 0 0 0 auto; width: fit-content;",
|
||||
};
|
||||
|
||||
export const FLOAT_STYLES: Record<FloatOption, string> = {
|
||||
left: "float: left; margin: 0 1rem 0 0;",
|
||||
right: "float: right; margin: 0 0 0 1rem;",
|
||||
};
|
||||
|
||||
type PlacementValue =
|
||||
| "align-left"
|
||||
| "align-center"
|
||||
| "align-right"
|
||||
| "float-left"
|
||||
| "float-right";
|
||||
|
||||
const PLACEMENT_OPTIONS: PlacementValue[] = [
|
||||
"align-left",
|
||||
"align-center",
|
||||
"align-right",
|
||||
"float-left",
|
||||
"float-right",
|
||||
];
|
||||
|
||||
const PLACEMENT_STYLES: Record<PlacementValue, string> = {
|
||||
"align-left": ALIGN_STYLES.left,
|
||||
"align-center": ALIGN_STYLES.center,
|
||||
"align-right": ALIGN_STYLES.right,
|
||||
"float-left": FLOAT_STYLES.left,
|
||||
"float-right": FLOAT_STYLES.right,
|
||||
};
|
||||
|
||||
export default function ImageNodeView(props: NodeViewProps) {
|
||||
const { node, updateAttributes, selected } = props;
|
||||
const attrs = node.attrs as ImageAttrs;
|
||||
|
||||
const minSizeImgAllowed = 100;
|
||||
const imgRef = useRef<HTMLImageElement>(null);
|
||||
const resizeState = useRef<{
|
||||
startX: number;
|
||||
startWidth: number;
|
||||
ratio: number;
|
||||
} | null>(null);
|
||||
|
||||
const [isResizing, setIsResizing] = useState<boolean>(false);
|
||||
const [open, setOpen] = useState<boolean>(false);
|
||||
const [altValue, setAltValue] = useState<string>(attrs.alt);
|
||||
const [captionValue, setCaptionValue] = useState<string | null>(
|
||||
attrs.caption,
|
||||
);
|
||||
|
||||
const getCurrentPlacement = (): PlacementValue | null => {
|
||||
if (attrs.float === "left") return "float-left";
|
||||
if (attrs.float === "right") return "float-right";
|
||||
if (attrs.style?.includes(ALIGN_STYLES.left)) return "align-left";
|
||||
if (attrs.style?.includes(ALIGN_STYLES.center)) return "align-center";
|
||||
if (attrs.style?.includes(ALIGN_STYLES.right)) return "align-right";
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
const handlePlacementChange = (value: PlacementValue) => {
|
||||
updateAttributes({
|
||||
style: PLACEMENT_STYLES[value],
|
||||
float: value.startsWith("float-")
|
||||
? (value.split("-")[1] as FloatOption)
|
||||
: null,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Set resize state.
|
||||
*
|
||||
* @param event MouseEvent
|
||||
* @returns
|
||||
*/
|
||||
const onMouseDown = (event: React.MouseEvent) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
const img = imgRef.current;
|
||||
if (!img) return;
|
||||
|
||||
resizeState.current = {
|
||||
startX: event.clientX,
|
||||
startWidth: img.offsetWidth,
|
||||
ratio: img.offsetWidth / img.offsetHeight,
|
||||
};
|
||||
setIsResizing(true);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update image sizes when resizing.
|
||||
*
|
||||
* @param event MouseEvent
|
||||
* @return void
|
||||
*/
|
||||
const onMouseMove = (event: MouseEvent): void => {
|
||||
if (!isResizing || !resizeState.current) return;
|
||||
|
||||
const { startX, startWidth, ratio } = resizeState.current;
|
||||
let newWidth = startWidth + (event.clientX - startX);
|
||||
let newHeight = newWidth / ratio;
|
||||
|
||||
if (newHeight < minSizeImgAllowed) {
|
||||
newHeight = minSizeImgAllowed;
|
||||
newWidth = newHeight * ratio;
|
||||
}
|
||||
if (newWidth < minSizeImgAllowed) {
|
||||
newWidth = minSizeImgAllowed;
|
||||
newHeight = newWidth / ratio;
|
||||
}
|
||||
|
||||
updateAttributes({
|
||||
width: Math.round(newWidth),
|
||||
height: Math.round(newHeight),
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Reset resize state.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
const onMouseUp = (): void => {
|
||||
setIsResizing(false);
|
||||
resizeState.current = null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Update image attributes.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
const saveDialog = (): void => {
|
||||
updateAttributes({
|
||||
alt: altValue,
|
||||
caption: captionValue,
|
||||
});
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
/**
|
||||
* Close modal and reset component.
|
||||
*
|
||||
* @param status boolean
|
||||
* @return void
|
||||
*/
|
||||
const closeModal = (status: boolean = false): void => {
|
||||
setOpen(status);
|
||||
};
|
||||
|
||||
// Convertit une string CSS en objet React style
|
||||
const parseStyleString = (
|
||||
styleString: string | null | undefined,
|
||||
): CSSProperties => {
|
||||
if (!styleString) return {};
|
||||
|
||||
const style: CSSProperties = {};
|
||||
styleString.split(";").forEach((rule) => {
|
||||
const [property, value] = rule.split(":").map((s) => s.trim());
|
||||
if (property && value) {
|
||||
// Conversion kebab-case → camelCase
|
||||
const camelProperty = property.replace(/-([a-z])/g, (g) =>
|
||||
g[1].toUpperCase(),
|
||||
);
|
||||
style[camelProperty as keyof CSSProperties] = value as any;
|
||||
}
|
||||
});
|
||||
|
||||
return style;
|
||||
};
|
||||
|
||||
// Reset events when resizing.
|
||||
useEffect(() => {
|
||||
if (!isResizing) return;
|
||||
|
||||
window.addEventListener("mousemove", onMouseMove);
|
||||
window.addEventListener("mouseup", onMouseUp);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("mousemove", onMouseMove);
|
||||
window.removeEventListener("mouseup", onMouseUp);
|
||||
};
|
||||
}, [isResizing]);
|
||||
|
||||
return (
|
||||
<NodeViewWrapper
|
||||
as={attrs.caption ? "figure" : "div"}
|
||||
data-type="image"
|
||||
style={parseStyleString(attrs.style)}
|
||||
className={cn("relative w-fit", {
|
||||
"outline outline-2 outline-dashed": selected,
|
||||
})}
|
||||
>
|
||||
<img
|
||||
ref={imgRef}
|
||||
src={attrs.src}
|
||||
alt={attrs.alt}
|
||||
width={attrs.width}
|
||||
height={attrs.height}
|
||||
draggable={false}
|
||||
/>
|
||||
{selected && (
|
||||
<div className="absolute bottom-2 right-2 flex flex-col gap-1 p-1 bg-background/90 backdrop-blur-sm rounded-md border shadow-md">
|
||||
{/* Placement dropdown */}
|
||||
<Select
|
||||
value={getCurrentPlacement() || undefined}
|
||||
onValueChange={handlePlacementChange}
|
||||
>
|
||||
<SelectTrigger className="w-10 h-10 hover:bg-accent hover:text-accent-foreground p-0">
|
||||
<LayoutIcon className="w-4 h-4 mx-auto" />
|
||||
</SelectTrigger>
|
||||
<SelectContent align="end">
|
||||
{PLACEMENT_OPTIONS.map((value) => {
|
||||
const [type, dir] = value.split("-") as [
|
||||
"align" | "float",
|
||||
string,
|
||||
];
|
||||
const label =
|
||||
type === "align"
|
||||
? `Align ${dir}`
|
||||
: `Wrap ${dir}`;
|
||||
return (
|
||||
<SelectItem key={value} value={value}>
|
||||
<div className="flex flex-row items-center gap-2">
|
||||
{value === "align-left" && (
|
||||
<AlignLeftIcon className="w-4 h-4" />
|
||||
)}
|
||||
{value === "align-center" && (
|
||||
<AlignCenterIcon className="w-4 h-4" />
|
||||
)}
|
||||
{value === "align-right" && (
|
||||
<AlignRightIcon className="w-4 h-4" />
|
||||
)}
|
||||
{value === "float-left" && (
|
||||
<ArrowLeftRightIcon className="w-4 h-4" />
|
||||
)}
|
||||
{value === "float-right" && (
|
||||
<ArrowRightLeftIcon className="w-4 h-4" />
|
||||
)}
|
||||
{label}
|
||||
</div>
|
||||
</SelectItem>
|
||||
);
|
||||
})}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{/* Edit button */}
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setOpen(true);
|
||||
}}
|
||||
>
|
||||
<PencilIcon className="w-4 h-4" />
|
||||
</Button>
|
||||
{/* Resize button */}
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onMouseDown={onMouseDown}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
className={cn("cursor-nw-resize", {
|
||||
"bg-accent text-accent-foreground": isResizing,
|
||||
})}
|
||||
>
|
||||
<MoveDiagonal2Icon className="w-4 h-4" />
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
{/* Caption */}
|
||||
{attrs.caption && <figcaption>{attrs.caption}</figcaption>}
|
||||
{/* Dialog Shadcn */}
|
||||
<Dialog open={open} onOpenChange={(status) => closeModal(status)}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
{useTrans("back.wysiwyg.image.edit_title")}
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
{useTrans("back.wysiwyg.image.edit_subtitle")}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
{/* Inputs */}
|
||||
<SimpleString
|
||||
name="image-alt"
|
||||
label={useTrans("back.wysiwyg.image.alt")}
|
||||
value={altValue}
|
||||
setData={(_, value) => setAltValue(value)}
|
||||
/>
|
||||
<SimpleString
|
||||
name="image-caption"
|
||||
label={useTrans("back.wysiwyg.image.caption")}
|
||||
value={captionValue ?? ""}
|
||||
required={false}
|
||||
setData={(_, value) => setCaptionValue(value)}
|
||||
/>
|
||||
{/* Action buttons */}
|
||||
<div className="flex justify-center items-center gap-1.5">
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={useTrans("back.wysiwyg.image.edit_cancel")}
|
||||
tooltipContent={str(
|
||||
useTrans(
|
||||
"back.wysiwyg.image.edit_tooltip_cancel",
|
||||
),
|
||||
)
|
||||
.ucFirst()
|
||||
.value()}
|
||||
onClick={() => closeModal()}
|
||||
type="button"
|
||||
variant="secondary"
|
||||
size="default"
|
||||
/>
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={useTrans("back.wysiwyg.image.edit_apply")}
|
||||
tooltipContent={str(
|
||||
useTrans(
|
||||
"back.wysiwyg.image.edit_tooltip_apply",
|
||||
),
|
||||
)
|
||||
.ucFirst()
|
||||
.value()}
|
||||
onClick={saveDialog}
|
||||
type="button"
|
||||
variant="default"
|
||||
size="default"
|
||||
/>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</NodeViewWrapper>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,33 +1,23 @@
|
|||
// * Packages
|
||||
import { Plugin, PluginKey } from 'prosemirror-state';
|
||||
import { Editor, mergeAttributes, getMarkRange, CommandProps } from '@tiptap/core';
|
||||
import { mergeAttributes, getMarkRange, CommandProps } from "@tiptap/react";
|
||||
import type { LinkOptions as TiptapLinkOptions } from '@tiptap/extension-link';
|
||||
import { Link as TiptapLink } from '@tiptap/extension-link';
|
||||
import { TextSelection } from 'prosemirror-state';
|
||||
// * Other
|
||||
import LinkButton from '@/back/Components/Inputs/Wysiwyg/Plugins/Link/LinkButton';
|
||||
import useTrans from '@/hooks/use-translations';
|
||||
|
||||
export interface LinkOptions extends TiptapLinkOptions {}
|
||||
|
||||
export type LinkAttrs = {
|
||||
text: string;
|
||||
blank: boolean;
|
||||
modelToken: string | null;
|
||||
};
|
||||
|
||||
export const Link = TiptapLink.extend<LinkOptions>({
|
||||
name: "Link",
|
||||
addOptions() {
|
||||
return {
|
||||
...this.parent?.(),
|
||||
openOnClick: false,
|
||||
button: ({ editor }: { editor: Editor }) => ({
|
||||
component: LinkButton,
|
||||
componentProps: {
|
||||
editor,
|
||||
tooltip: useTrans('back.wysiwyg_plugins.link.tooltip'),
|
||||
},
|
||||
}),
|
||||
};
|
||||
},
|
||||
addCommands() {
|
||||
return {
|
||||
setLink: attrs => ({ state, commands }) => {
|
||||
const linkAttrs = attrs as LinkAttrs;
|
||||
const { from, to } = state.selection;
|
||||
|
||||
// Check if there is a selected link.
|
||||
|
|
@ -56,13 +46,13 @@ export const Link = TiptapLink.extend<LinkOptions>({
|
|||
tr.delete(from, to);
|
||||
|
||||
// Insert the new text.
|
||||
tr.insertText(attrs.text, from);
|
||||
tr.insertText(linkAttrs.text, from);
|
||||
|
||||
// Set the mark with new attributes.
|
||||
tr.addMark(
|
||||
from,
|
||||
from + attrs.text.length,
|
||||
state.schema.marks[this.name].create(attrs)
|
||||
from + linkAttrs.text.length,
|
||||
state.schema.marks[this.name].create(linkAttrs)
|
||||
);
|
||||
|
||||
// Apply the modification.
|
||||
|
|
@ -75,26 +65,26 @@ export const Link = TiptapLink.extend<LinkOptions>({
|
|||
// Otherwise, create a new link like before.
|
||||
return commands.insertContent({
|
||||
type: "text",
|
||||
text: attrs.text,
|
||||
marks: [{ type: this.name, attrs }],
|
||||
text: linkAttrs.text,
|
||||
marks: [{ type: this.name, attrs: linkAttrs }],
|
||||
});
|
||||
},
|
||||
unsetLink: () => ({ state, commands }: CommandProps) => {
|
||||
const { from, to } = state.selection;
|
||||
|
||||
unsetLink: () => ({ state, dispatch, tr, commands }) => {
|
||||
const { $from } = state.selection;
|
||||
const markType = state.schema.marks[this.name];
|
||||
|
||||
// Check there is a link mark.
|
||||
let hasLink = false;
|
||||
state.doc.nodesBetween(from, to, node => {
|
||||
if (node.marks?.some(m => m.type.name === this.name)) {
|
||||
hasLink = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (!hasLink) return false;
|
||||
|
||||
const markRange = getMarkRange($from, markType);
|
||||
if (!markRange) return false;
|
||||
|
||||
// Remove the mark from the selection.
|
||||
return commands.unsetMark(this.name);
|
||||
},
|
||||
if (dispatch) {
|
||||
tr.removeMark(markRange.from, markRange.to, markType);
|
||||
dispatch(tr);
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
};
|
||||
},
|
||||
addAttributes() {
|
||||
|
|
@ -128,7 +118,6 @@ export const Link = TiptapLink.extend<LinkOptions>({
|
|||
},
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return ['a', mergeAttributes({
|
||||
class: 'link',
|
||||
'data-model': HTMLAttributes.modelToken,
|
||||
}, HTMLAttributes), 0];
|
||||
},
|
||||
|
|
@ -3,7 +3,7 @@ import { useEffect, useState } from "react";
|
|||
import axios from "axios";
|
||||
import { route } from "ziggy-js";
|
||||
import { ExternalLinkIcon, LinkIcon, TrashIcon } from "lucide-react";
|
||||
import { Editor } from "reactjs-tiptap-editor";
|
||||
import { Editor } from "@tiptap/react";
|
||||
import { usePage } from "@inertiajs/react";
|
||||
import { z } from "zod";
|
||||
// * Components shadcn
|
||||
|
|
@ -15,6 +15,7 @@ import {
|
|||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
// * Other
|
||||
import BtnOptionnalLinkWithTooltip from "@/back/Components/BtnOptionnalLinkWithTooltip";
|
||||
import EnumSelect from "@/back/Components/Inputs/EnumSelect";
|
||||
|
|
@ -24,7 +25,6 @@ import GoToFrontView from "@/back/Components/GoToFrontView";
|
|||
import useTrans from "@/hooks/use-translations";
|
||||
import str from "@/hooks/use-string";
|
||||
import { AppEnv, LaravelEnum } from "@/back/types/global";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { ModelSelect } from "../../../ModelSelect";
|
||||
|
||||
|
|
@ -64,11 +64,11 @@ enum LinkType {
|
|||
type LinkProps = {
|
||||
/** Wysiwyg editor instance. */
|
||||
editor: Editor,
|
||||
/** Wysiwyg menu button tooltip. */
|
||||
tooltip: string,
|
||||
/** Disable trigger button. */
|
||||
disabled: boolean;
|
||||
}
|
||||
|
||||
export default function LinkButton({ editor, tooltip }: LinkProps) {
|
||||
export default function LinkButton({ editor, disabled } : LinkProps) {
|
||||
// Current domain of the projet.
|
||||
const { url } = usePage().props.appEnv as AppEnv;
|
||||
// All models from global enum.
|
||||
|
|
@ -114,10 +114,11 @@ export default function LinkButton({ editor, tooltip }: LinkProps) {
|
|||
const createMinRule = (attribute: string, min: number) => useTrans('validation.min.string', { params: { attribute, min: min.toString() } });
|
||||
const createMaxRule = (attribute: string, max: number) => useTrans('validation.max.string', { params: { attribute, max: max.toString() } });
|
||||
|
||||
// Attributes translations.
|
||||
const textAttribute = useTrans('back.wysiwyg_plugins.link.text');
|
||||
const urlAttribute = useTrans('back.wysiwyg_plugins.link.url');
|
||||
|
||||
// Translations.
|
||||
const textAttribute = useTrans('back.wysiwyg.link.text');
|
||||
const urlAttribute = useTrans('back.wysiwyg.link.url');
|
||||
const transTooltip = str(useTrans("back.wysiwyg.link.tooltip")).ucFirst().value();
|
||||
|
||||
// Zod internal link schema.
|
||||
const internalLinkSchema = z.object({
|
||||
inputText: z.string().min(3, createMinRule(textAttribute, 3)).max(255, createMaxRule(textAttribute, 255))
|
||||
|
|
@ -136,7 +137,7 @@ export default function LinkButton({ editor, tooltip }: LinkProps) {
|
|||
return false;
|
||||
}
|
||||
}, {
|
||||
message: useTrans('back.wysiwyg_plugins.link.validation.use_internal')
|
||||
message: useTrans('back.wysiwyg.link.validation.use_internal')
|
||||
})
|
||||
// Assert it's a valid url.
|
||||
.refine((val) => {
|
||||
|
|
@ -147,11 +148,11 @@ export default function LinkButton({ editor, tooltip }: LinkProps) {
|
|||
return false;
|
||||
}
|
||||
}, {
|
||||
message: useTrans('back.wysiwyg_plugins.link.validation.url')
|
||||
message: useTrans('back.wysiwyg.link.validation.url')
|
||||
})
|
||||
// Assert there is domain and tld.
|
||||
.refine((val) => /^(?:https?:\/\/)?([a-z0-9-]+\.)+[a-z]{2,}$/i.test(val), {
|
||||
message: useTrans('back.wysiwyg_plugins.link.validation.url')
|
||||
message: useTrans('back.wysiwyg.link.validation.url')
|
||||
}),
|
||||
});
|
||||
|
||||
|
|
@ -410,17 +411,18 @@ export default function LinkButton({ editor, tooltip }: LinkProps) {
|
|||
return (
|
||||
<Dialog
|
||||
open={open}
|
||||
onOpenChange={(v) => {
|
||||
setOpen(v);
|
||||
if (!v) setTimeout(() => resetComponent(), animationTime);
|
||||
onOpenChange={(status) => {
|
||||
setOpen(status);
|
||||
if (!status) setTimeout(() => resetComponent(), animationTime);
|
||||
}}
|
||||
>
|
||||
{/* Button trigger in wysiwyg navigation. */}
|
||||
<DialogTrigger asChild>
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={<LinkIcon className="w-4 h-4 m-auto" />}
|
||||
tooltipContent={tooltip}
|
||||
className="cursor-grab richtext-px-2 richtext-w-[32px] richtext-h-[32px]"
|
||||
tooltipContent={transTooltip}
|
||||
className="richtext-px-2 richtext-w-[32px] richtext-h-[32px]"
|
||||
disabled={disabled}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
|
|
@ -428,8 +430,8 @@ export default function LinkButton({ editor, tooltip }: LinkProps) {
|
|||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>{useTrans('back.wysiwyg_plugins.link.title')}</DialogTitle>
|
||||
<DialogDescription>{useTrans('back.wysiwyg_plugins.link.subtitle')}</DialogDescription>
|
||||
<DialogTitle>{useTrans('back.wysiwyg.link.title')}</DialogTitle>
|
||||
<DialogDescription>{useTrans('back.wysiwyg.link.subtitle')}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div>
|
||||
<div className="flex justify-center items-center bg-muted rounded-md w-full p-1 mb-1 gap-1.5">
|
||||
|
|
@ -444,7 +446,7 @@ export default function LinkButton({ editor, tooltip }: LinkProps) {
|
|||
: "text-muted-foreground hover:bg-transparent hover:text-foreground"
|
||||
)}
|
||||
>
|
||||
{useTrans('back.wysiwyg_plugins.link.external_link')}
|
||||
{useTrans('back.wysiwyg.link.external_link')}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
|
|
@ -457,7 +459,7 @@ export default function LinkButton({ editor, tooltip }: LinkProps) {
|
|||
: "text-muted-foreground hover:bg-transparent hover:text-foreground"
|
||||
)}
|
||||
>
|
||||
{useTrans('back.wysiwyg_plugins.link.internal_link')}
|
||||
{useTrans('back.wysiwyg.link.internal_link')}
|
||||
</Button>
|
||||
</div>
|
||||
<div className="flex flex-col border rounded-md p-6 gap-4">
|
||||
|
|
@ -467,7 +469,7 @@ export default function LinkButton({ editor, tooltip }: LinkProps) {
|
|||
<EnumSelect
|
||||
key={resetState}
|
||||
name="modelName"
|
||||
label={useTrans('back.wysiwyg_plugins.link.enum')}
|
||||
label={useTrans('back.wysiwyg.link.enum')}
|
||||
placeholder="ex: page dynamique"
|
||||
selected={selectedEnumValue}
|
||||
options={enumModelsList}
|
||||
|
|
@ -485,7 +487,7 @@ export default function LinkButton({ editor, tooltip }: LinkProps) {
|
|||
multiple={false}
|
||||
targetModel={selectedEnum?.name}
|
||||
field={selectedEnum?.field}
|
||||
label={useTrans('back.wysiwyg_plugins.link.entry')}
|
||||
label={useTrans('back.wysiwyg.link.entry')}
|
||||
placeholder="ex: John Doe"
|
||||
defaultValues={selectedModelId ? [selectedModelId] : []}
|
||||
required={true}
|
||||
|
|
@ -509,7 +511,7 @@ export default function LinkButton({ editor, tooltip }: LinkProps) {
|
|||
addLocale={false}
|
||||
/>
|
||||
) : (
|
||||
<small className="text-start">{useTrans('back.wysiwyg_plugins.link.link')}</small>
|
||||
<small className="text-start">{useTrans('back.wysiwyg.link.link')}</small>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
|
|
@ -517,7 +519,7 @@ export default function LinkButton({ editor, tooltip }: LinkProps) {
|
|||
{/* Url input. */}
|
||||
<SimpleString
|
||||
name="link-url"
|
||||
label={useTrans('back.wysiwyg_plugins.link.url')}
|
||||
label={useTrans('back.wysiwyg.link.url')}
|
||||
value={inputUrl}
|
||||
type="url"
|
||||
disabled={loading}
|
||||
|
|
@ -529,7 +531,7 @@ export default function LinkButton({ editor, tooltip }: LinkProps) {
|
|||
{/* Url to go to the url. */}
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={<ExternalLinkIcon className="w-4 h-4 m-auto" />}
|
||||
tooltipContent={useTrans('back.wysiwyg_plugins.link.access_url')}
|
||||
tooltipContent={useTrans('back.wysiwyg.link.access_url')}
|
||||
className="cursor-pointer"
|
||||
variant="secondary"
|
||||
type="button"
|
||||
|
|
@ -543,7 +545,7 @@ export default function LinkButton({ editor, tooltip }: LinkProps) {
|
|||
{/* String input. */}
|
||||
<SimpleString
|
||||
name="link-text"
|
||||
label={useTrans('back.wysiwyg_plugins.link.text')}
|
||||
label={useTrans('back.wysiwyg.link.text')}
|
||||
value={inputText}
|
||||
disabled={loading}
|
||||
setData={(_, value) => handleUpdateText(value)}
|
||||
|
|
@ -551,7 +553,7 @@ export default function LinkButton({ editor, tooltip }: LinkProps) {
|
|||
/>
|
||||
{/* Boolean input. */}
|
||||
<SimpleSwitch
|
||||
label={useTrans("back.wysiwyg_plugins.link.switch")}
|
||||
label={useTrans("back.wysiwyg.link.switch")}
|
||||
name="link-blank"
|
||||
checked={inputBlank}
|
||||
disabled={loading}
|
||||
|
|
@ -559,34 +561,32 @@ export default function LinkButton({ editor, tooltip }: LinkProps) {
|
|||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<div className="flex justify-between gap-1.5">
|
||||
{/* Save button. */}
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={str(useTrans('crud.actions.save')).ucFirst().value()}
|
||||
tooltipContent={useTrans('back.wysiwyg_plugins.link.add')}
|
||||
className="cursor-pointer"
|
||||
type="button"
|
||||
size="default"
|
||||
disabled={loading}
|
||||
onClick={handleAddLink}
|
||||
/>
|
||||
{/* Cancel button. */}
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={str(useTrans('back.cancel')).ucFirst().value()}
|
||||
tooltipContent={useTrans('back.wysiwyg_plugins.link.cancel')}
|
||||
className="cursor-pointer"
|
||||
variant="secondary"
|
||||
type="button"
|
||||
size="default"
|
||||
disabled={loading}
|
||||
onClick={handleCancelLink}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex justify-center items-center gap-1.5">
|
||||
{/* Cancel button. */}
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={str(useTrans('back.wysiwyg.link.cancel')).ucFirst().value()}
|
||||
tooltipContent={useTrans('back.wysiwyg.link.tooltip_cancel')}
|
||||
className="cursor-pointer"
|
||||
variant="secondary"
|
||||
type="button"
|
||||
size="default"
|
||||
disabled={loading}
|
||||
onClick={handleCancelLink}
|
||||
/>
|
||||
{/* Save button. */}
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={str(useTrans('back.wysiwyg.link.insert')).ucFirst().value()}
|
||||
tooltipContent={useTrans('back.wysiwyg.link.tooltip_insert')}
|
||||
className="cursor-pointer"
|
||||
type="button"
|
||||
size="default"
|
||||
disabled={loading}
|
||||
onClick={handleAddLink}
|
||||
/>
|
||||
{/* Delete button. */}
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={<TrashIcon className="w-4 h-4 m-auto" />}
|
||||
tooltipContent={useTrans('back.wysiwyg_plugins.link.delete')}
|
||||
tooltipContent={useTrans('back.wysiwyg.link.tooltip_delete')}
|
||||
className="cursor-pointer"
|
||||
variant='destructive'
|
||||
type="button"
|
||||
|
|
@ -0,0 +1,160 @@
|
|||
// * Packages
|
||||
import { useState } from "react";
|
||||
import { Editor } from "@tiptap/react";
|
||||
import { ReplaceIcon } from "lucide-react";
|
||||
// * Components shadcn
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogDescription,
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { Label } from "@/components/ui/label";
|
||||
// * Other
|
||||
import SimpleString from "@/back/Components/Inputs/SimpleString";
|
||||
import BtnOptionnalLinkWithTooltip from "@/back/Components/BtnOptionnalLinkWithTooltip";
|
||||
import useTrans from "@/hooks/use-translations";
|
||||
import str from "@/hooks/use-string";
|
||||
|
||||
export default function FindReplaceButton({ editor }: { editor: Editor }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [searchText, setSearchText] = useState("");
|
||||
const [replaceText, setReplaceText] = useState("");
|
||||
const [matchCase, setMatchCase] = useState(false);
|
||||
|
||||
// Duration of modal closing animation.
|
||||
const animationTime = 200;
|
||||
|
||||
/**
|
||||
* Search and replace specific text.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
const handleReplaceAll = (): void => {
|
||||
if (!editor || !searchText) return;
|
||||
|
||||
// Get all editor content.
|
||||
const html = editor.getHTML();
|
||||
|
||||
// Set dynamic regex depending on match case value.
|
||||
const flags = matchCase ? "g" : "gi";
|
||||
const regex = new RegExp(searchText, flags);
|
||||
|
||||
// Replace the text.
|
||||
const newHtml = html.replace(regex, replaceText);
|
||||
|
||||
// Update editor content.
|
||||
editor.commands.setContent(newHtml);
|
||||
|
||||
closeModal();
|
||||
};
|
||||
|
||||
/**
|
||||
* Reset the component.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
const resetComponent = (): void => {
|
||||
setSearchText("");
|
||||
setReplaceText("");
|
||||
setMatchCase(false);
|
||||
};
|
||||
|
||||
/**
|
||||
* Close modal and reset component.
|
||||
*
|
||||
* @param status boolean
|
||||
* @return void
|
||||
*/
|
||||
const closeModal = (status: boolean = false): void => {
|
||||
setOpen(status);
|
||||
setTimeout(() => resetComponent(), animationTime);
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
open={open}
|
||||
onOpenChange={(status) => closeModal(status)}
|
||||
>
|
||||
<DialogTrigger asChild>
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={<ReplaceIcon className="w-4 h-4 m-auto" />}
|
||||
tooltipContent={useTrans("back.wysiwyg.replace.tooltip")}
|
||||
disabled={editor.getText().trim() === ""}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
/>
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>{useTrans("back.wysiwyg.replace.title")}</DialogTitle>
|
||||
<DialogDescription>
|
||||
{useTrans("back.wysiwyg.replace.subtitle")}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
{/* Inputs text */}
|
||||
<SimpleString
|
||||
name="target"
|
||||
label={useTrans("back.wysiwyg.replace.target")}
|
||||
placeholder="ex: John Doe"
|
||||
required={true}
|
||||
value={searchText}
|
||||
setData={(_, value) => setSearchText(value)}
|
||||
/>
|
||||
<SimpleString
|
||||
name="value"
|
||||
label={useTrans("back.wysiwyg.replace.value")}
|
||||
placeholder="ex: John Doe"
|
||||
required={true}
|
||||
value={replaceText}
|
||||
setData={(_, value) => setReplaceText(value)}
|
||||
/>
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
id="match-case"
|
||||
checked={matchCase}
|
||||
onCheckedChange={(val) => setMatchCase(Boolean(val))}
|
||||
/>
|
||||
<Label htmlFor="match-case">
|
||||
{useTrans("back.wysiwyg.replace.match_case")}
|
||||
</Label>
|
||||
</div>
|
||||
{/* Action buttons */}
|
||||
<div className="flex justify-center items-center gap-1.5">
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={useTrans("back.wysiwyg.replace.cancel")}
|
||||
tooltipContent={str(
|
||||
useTrans(
|
||||
"back.wysiwyg.replace.tooltip_cancel",
|
||||
),
|
||||
)
|
||||
.ucFirst()
|
||||
.value()}
|
||||
onClick={() => closeModal()}
|
||||
type="button"
|
||||
variant="secondary"
|
||||
size="default"
|
||||
/>
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={useTrans("back.wysiwyg.replace.apply")}
|
||||
tooltipContent={str(
|
||||
useTrans(
|
||||
"back.wysiwyg.replace.tooltip_apply",
|
||||
),
|
||||
)
|
||||
.ucFirst()
|
||||
.value()}
|
||||
onClick={handleReplaceAll}
|
||||
type="button"
|
||||
variant="default"
|
||||
size="default"
|
||||
/>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,322 @@
|
|||
// * Packages
|
||||
import { useEffect, useState } from "react";
|
||||
import { Editor } from "@tiptap/react";
|
||||
import { TableIcon } from "lucide-react";
|
||||
// * Components shadcn
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogDescription,
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { Label } from "@/components/ui/label";
|
||||
// * Other
|
||||
import BtnOptionnalLinkWithTooltip from "@/back/Components/BtnOptionnalLinkWithTooltip";
|
||||
import str from "@/hooks/use-string";
|
||||
import useTrans from "@/hooks/use-translations";
|
||||
|
||||
const BASE = 5;
|
||||
const MAX = 12;
|
||||
|
||||
type TableProps = {
|
||||
editor: Editor,
|
||||
disabled: boolean,
|
||||
}
|
||||
|
||||
export default function TableButton({ editor, disabled }: TableProps) {
|
||||
const [rows, setRows] = useState(3);
|
||||
const [cols, setCols] = useState(3);
|
||||
const [hover, setHover] = useState<{
|
||||
row: number;
|
||||
column: number;
|
||||
} | null>(null);
|
||||
const [header, setHeader] = useState(true);
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
// Duration of modal closing animation.
|
||||
const animationTime = 200;
|
||||
|
||||
// Set size of the table.
|
||||
const gridSize = Math.min(
|
||||
MAX,
|
||||
Math.max(
|
||||
BASE,
|
||||
rows + 1,
|
||||
cols + 1,
|
||||
hover?.row ? hover.row + 1 : 0,
|
||||
hover?.column ? hover.column + 1 : 0,
|
||||
),
|
||||
);
|
||||
|
||||
const insert = (
|
||||
rows: number | undefined = undefined,
|
||||
cols: number | undefined = undefined,
|
||||
): void => {
|
||||
if (!editor.can().insertTable()) return;
|
||||
|
||||
// Insert the current table in the editor.
|
||||
editor
|
||||
.chain()
|
||||
.focus()
|
||||
.insertTable({
|
||||
rows: rows,
|
||||
cols: cols,
|
||||
withHeaderRow: header,
|
||||
})
|
||||
.run();
|
||||
|
||||
// Close the modal.
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
/**
|
||||
* Reset the component.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
const resetComponent = (): void => {
|
||||
setRows(3);
|
||||
setCols(3);
|
||||
setHover({ row: 3, column: 3 });
|
||||
setHeader(true);
|
||||
};
|
||||
|
||||
/**
|
||||
* Insert tableClose modal and reset component.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
const handleInsertTable = (): void => {
|
||||
insert();
|
||||
closeModal();
|
||||
};
|
||||
|
||||
/**
|
||||
* Close modal and reset component.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
const closeModal = (): void => {
|
||||
setOpen(false);
|
||||
setTimeout(() => resetComponent(), animationTime);
|
||||
};
|
||||
|
||||
// Set size of the current table on hover.
|
||||
useEffect(() => {
|
||||
setHover({ row: rows, column: cols });
|
||||
}, [rows, cols]);
|
||||
|
||||
// Press the key event to use the arrow keys to set the table size.
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
|
||||
const onKeyDown = (event: KeyboardEvent) => {
|
||||
const active = document.activeElement as HTMLInputElement;
|
||||
|
||||
// Check if the focus is on inputs to get the basic behavior.
|
||||
if (active?.tagName === "INPUT" && active.type === "number") {
|
||||
if (event.key === "ArrowUp") {
|
||||
event.preventDefault();
|
||||
if (active.id === "rows-input")
|
||||
setRows((row) => Math.min(MAX, row + 1));
|
||||
if (active.id === "cols-input")
|
||||
setCols((column) => Math.min(MAX, column + 1));
|
||||
}
|
||||
if (event.key === "ArrowDown") {
|
||||
event.preventDefault();
|
||||
if (active.id === "rows-input")
|
||||
setRows((row) => Math.max(1, row - 1));
|
||||
if (active.id === "cols-input")
|
||||
setCols((column) => Math.max(1, column - 1));
|
||||
}
|
||||
// Stop propagation if focus on inputs.
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, use arrow keys to resize the table.
|
||||
switch (event.key) {
|
||||
case "ArrowUp":
|
||||
event.preventDefault();
|
||||
setRows((row) => Math.max(1, row - 1));
|
||||
break;
|
||||
case "ArrowDown":
|
||||
event.preventDefault();
|
||||
setRows((row) => Math.min(MAX, row + 1));
|
||||
break;
|
||||
case "ArrowLeft":
|
||||
event.preventDefault();
|
||||
setCols((column) => Math.max(1, column - 1));
|
||||
break;
|
||||
case "ArrowRight":
|
||||
event.preventDefault();
|
||||
setCols((column) => Math.min(MAX, column + 1));
|
||||
break;
|
||||
case "Enter":
|
||||
event.preventDefault();
|
||||
insert();
|
||||
break;
|
||||
case "Escape":
|
||||
event.preventDefault();
|
||||
setOpen(false);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
// Redefine the keydown event due to table resize.
|
||||
window.addEventListener("keydown", onKeyDown);
|
||||
return () => window.removeEventListener("keydown", onKeyDown);
|
||||
}, [open, insert]);
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
open={open}
|
||||
onOpenChange={(status) => {
|
||||
setOpen(status);
|
||||
if (!status) setTimeout(() => resetComponent(), animationTime);
|
||||
}}
|
||||
>
|
||||
<DialogTrigger asChild>
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={<TableIcon className="w-4 h-4 m-auto" />}
|
||||
tooltipContent={useTrans(
|
||||
"back.wysiwyg.table.tooltip",
|
||||
)}
|
||||
disabled={disabled || !editor.can().insertTable()}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
/>
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
{useTrans("back.wysiwyg.table.title")}
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
{useTrans("back.wysiwyg.table.subtitle")}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
{/* Inputs */}
|
||||
<div className="flex gap-2">
|
||||
<div className="flex-1">
|
||||
<Label htmlFor="rows-input">
|
||||
{useTrans("back.wysiwyg.table.lines")}
|
||||
</Label>
|
||||
<Input
|
||||
id="rows-input"
|
||||
type="number"
|
||||
min={1}
|
||||
max={MAX}
|
||||
value={rows}
|
||||
onChange={(event) =>
|
||||
setRows(Number(event.target.value) || 1)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<Label htmlFor="cols-input">
|
||||
{useTrans("back.wysiwyg.table.columns")}
|
||||
</Label>
|
||||
<Input
|
||||
id="cols-input"
|
||||
type="number"
|
||||
min={1}
|
||||
max={MAX}
|
||||
value={cols}
|
||||
onChange={(event) =>
|
||||
setCols(Number(event.target.value) || 1)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex-1 flex justify-center items-center gap-1.5">
|
||||
<Checkbox
|
||||
id="header-input"
|
||||
checked={header}
|
||||
onCheckedChange={(event) =>
|
||||
setHeader(Boolean(event))
|
||||
}
|
||||
/>
|
||||
<Label htmlFor="header-input">
|
||||
{useTrans("back.wysiwyg.table.show_header")}
|
||||
</Label>
|
||||
</div>
|
||||
</div>
|
||||
{/* Keys notice */}
|
||||
<p className="flex justify-between items-center text-sm text-muted-foreground">
|
||||
<span>
|
||||
{useTrans("back.wysiwyg.table.use_arrow_keys")}
|
||||
</span>
|
||||
<span>
|
||||
{useTrans("back.wysiwyg.table.enter_to_insert")}
|
||||
</span>
|
||||
</p>
|
||||
{/* Preview grid */}
|
||||
<div
|
||||
className="grid gap-1"
|
||||
style={{ gridTemplateColumns: `repeat(${gridSize}, 1fr)` }}
|
||||
>
|
||||
{Array.from({ length: gridSize * gridSize }).map((_, i) => {
|
||||
const row = Math.floor(i / gridSize) + 1;
|
||||
const column = (i % gridSize) + 1;
|
||||
const active =
|
||||
hover && row <= hover.row && column <= hover.column;
|
||||
return (
|
||||
<div
|
||||
key={i}
|
||||
onMouseEnter={() => {
|
||||
setHover({ row, column });
|
||||
setRows(row);
|
||||
setCols(column);
|
||||
}}
|
||||
onClick={() => insert(row, column)}
|
||||
className={[
|
||||
"aspect-square border cursor-pointer",
|
||||
active
|
||||
? "bg-primary/30 border-primary"
|
||||
: "bg-muted",
|
||||
].join(" ")}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
{/* Action buttons */}
|
||||
<div className="flex justify-center items-center gap-1.5">
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={useTrans("back.wysiwyg.table.cancel")}
|
||||
tooltipContent={str(
|
||||
useTrans(
|
||||
"back.wysiwyg.table.tooltip_cancel",
|
||||
),
|
||||
)
|
||||
.ucFirst()
|
||||
.value()}
|
||||
onClick={closeModal}
|
||||
disabled={!editor.can().insertTable()}
|
||||
type="button"
|
||||
variant="secondary"
|
||||
size="default"
|
||||
/>
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={useTrans("back.wysiwyg.table.insert")}
|
||||
tooltipContent={str(
|
||||
useTrans(
|
||||
"back.wysiwyg.table.tooltip_insert",
|
||||
),
|
||||
)
|
||||
.ucFirst()
|
||||
.value()}
|
||||
onClick={handleInsertTable}
|
||||
disabled={!editor.can().insertTable()}
|
||||
type="button"
|
||||
variant="default"
|
||||
size="default"
|
||||
/>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
// * Packages
|
||||
import type { ImageOptions as TiptapImageOptions } from '@tiptap/extension-image';
|
||||
import { Image as TiptapImage } from 'reactjs-tiptap-editor/image';
|
||||
import { Editor } from 'reactjs-tiptap-editor';
|
||||
// * Other
|
||||
import ImageButton from '@/back/Components/Inputs/Wysiwyg/Plugins/Image/ImageButton';
|
||||
import useTrans from '@/hooks/use-translations';
|
||||
|
||||
export const Image = TiptapImage.extend<TiptapImageOptions>({
|
||||
addOptions() {
|
||||
return {
|
||||
...this.parent?.(),
|
||||
openOnClick: false,
|
||||
button: ({ editor }: { editor: Editor }) => ({
|
||||
component: ImageButton,
|
||||
componentProps: {
|
||||
editor,
|
||||
tooltip: useTrans('back.wysiwyg_plugins.image.tooltip'),
|
||||
},
|
||||
}),
|
||||
};
|
||||
},
|
||||
});
|
||||
|
|
@ -1,32 +1,27 @@
|
|||
// * Packages
|
||||
import { Editor, EditorContent } from "@tiptap/react";
|
||||
import { Table } from "@tiptap/extension-table";
|
||||
import { TaskItem } from "@tiptap/extension-list/task-item";
|
||||
import { TaskList } from "@tiptap/extension-list/task-list";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { usePage } from "@inertiajs/react";
|
||||
import { useEffect, useState } from "react";
|
||||
import RichTextEditor, { BaseKit, UseEditorOptions } from "reactjs-tiptap-editor";
|
||||
import { Blockquote } from "reactjs-tiptap-editor/blockquote";
|
||||
import { Bold } from "reactjs-tiptap-editor/bold";
|
||||
import { BulletList } from "reactjs-tiptap-editor/bulletlist";
|
||||
import { Clear } from "reactjs-tiptap-editor/clear";
|
||||
import { FontSize } from "reactjs-tiptap-editor/fontsize";
|
||||
import { Heading } from "reactjs-tiptap-editor/heading";
|
||||
import { History } from "reactjs-tiptap-editor/history";
|
||||
import { HorizontalRule } from "reactjs-tiptap-editor/horizontalrule";
|
||||
import { Indent } from "reactjs-tiptap-editor/indent";
|
||||
import { Italic } from "reactjs-tiptap-editor/italic";
|
||||
import { OrderedList } from "reactjs-tiptap-editor/orderedlist";
|
||||
import { SearchAndReplace } from "reactjs-tiptap-editor/searchandreplace";
|
||||
import { Strike } from "reactjs-tiptap-editor/strike";
|
||||
import { TextAlign } from "reactjs-tiptap-editor/textalign";
|
||||
import { TextUnderline } from "reactjs-tiptap-editor/textunderline";
|
||||
import { Color } from "reactjs-tiptap-editor/color";
|
||||
import "react-image-crop/dist/ReactCrop.css";
|
||||
import "reactjs-tiptap-editor/lib/style.css";
|
||||
import InvisibleCharacters from "@tiptap/extension-invisible-characters";
|
||||
import Placeholder from "@tiptap/extension-placeholder";
|
||||
import StarterKit from "@tiptap/starter-kit";
|
||||
import Subscript from "@tiptap/extension-subscript";
|
||||
import Superscript from "@tiptap/extension-superscript";
|
||||
import TableCell from "@tiptap/extension-table-cell";
|
||||
import TableHeader from "@tiptap/extension-table-header";
|
||||
import TableRow from "@tiptap/extension-table-row";
|
||||
import TextAlign from "@tiptap/extension-text-align";
|
||||
// * Components shadcn
|
||||
import { Label } from "@/components/ui/label";
|
||||
// * Other
|
||||
import { Link } from "@/back/Components/Inputs/Wysiwyg/Plugins/Link/Link";
|
||||
import { Image } from "@/back/Components/Inputs/Wysiwyg/Plugins/Image/Image";
|
||||
import { Link } from "@/back/Components/Inputs/Wysiwyg/Extensions/Link/Link";
|
||||
import { Image } from "@/back/Components/Inputs/Wysiwyg/Extensions/Image/Image";
|
||||
import InputError from "@/back/Components/InputError";
|
||||
import WordCounter from "@/back/Components/WordCounter";
|
||||
import Toolbar from "@/back/Components/Inputs/Wysiwyg/Toolbar";
|
||||
import useTrans from "@/hooks/use-translations";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
|
|
@ -41,14 +36,13 @@ type SimpleWysiwygProps = {
|
|||
wordCounter?: boolean;
|
||||
required?: boolean;
|
||||
disabled?: boolean;
|
||||
parentErrors?: Record<string, string> | null,
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
parentErrors?: Record<string, string> | null;
|
||||
setData: (name: string, value: string) => void;
|
||||
};
|
||||
|
||||
export default function SimpleWysiwyg({
|
||||
className,
|
||||
value = "",
|
||||
value = undefined,
|
||||
model,
|
||||
name,
|
||||
label,
|
||||
|
|
@ -63,93 +57,103 @@ export default function SimpleWysiwyg({
|
|||
const { errors } = usePage().props;
|
||||
const localErrors = parentErrors ?? errors;
|
||||
|
||||
const extensions = [
|
||||
BaseKit.configure({
|
||||
placeholder: {
|
||||
showOnlyCurrent: true,
|
||||
placeholder: useTrans(placeholder),
|
||||
},
|
||||
characterCount: false,
|
||||
const [editor, setEditor] = useState<Editor | null>(null);
|
||||
const [content, setContent] = useState(value);
|
||||
|
||||
/**
|
||||
* Remove html tags from content string.
|
||||
*
|
||||
* @param html string
|
||||
* @return string|null
|
||||
*/
|
||||
const stripHtmlTags = (html: string): string|null => {
|
||||
const temp = document.createElement("div");
|
||||
temp.innerHTML = html;
|
||||
const text = temp.textContent || temp.innerText || "";
|
||||
return text.trim() === "" ? null : text;
|
||||
};
|
||||
|
||||
/**
|
||||
* Update values when content is changing.
|
||||
*
|
||||
* @param editorContent string
|
||||
* @return void
|
||||
*/
|
||||
const onChangeContent = (editorContent: string): void => {
|
||||
const val = stripHtmlTags(editorContent) ? editorContent : "";
|
||||
setContent(val);
|
||||
setData(name, val);
|
||||
};
|
||||
|
||||
// Tiptap extensions.
|
||||
const extensions = useMemo(() => [
|
||||
// Starterkit contains: heading, bold, italic, strike, underline, ordered list, item list, blockquote.
|
||||
StarterKit.configure({
|
||||
link: false, // Custom link extension.
|
||||
}),
|
||||
// Specific extensions.
|
||||
TaskList,
|
||||
TaskItem.configure({
|
||||
nested: true,
|
||||
}),
|
||||
Table.configure({
|
||||
resizable: true,
|
||||
}),
|
||||
TableRow,
|
||||
TableHeader,
|
||||
TableCell,
|
||||
Placeholder.configure({
|
||||
placeholder: useTrans(placeholder),
|
||||
}),
|
||||
TextAlign.configure({
|
||||
types: ["heading", "paragraph"],
|
||||
}),
|
||||
Subscript,
|
||||
Superscript,
|
||||
InvisibleCharacters.configure({
|
||||
visible: false,
|
||||
}),
|
||||
History,
|
||||
SearchAndReplace,
|
||||
Clear,
|
||||
Heading,
|
||||
Bold,
|
||||
Italic,
|
||||
TextUnderline,
|
||||
Strike,
|
||||
Color,
|
||||
FontSize,
|
||||
BulletList,
|
||||
OrderedList,
|
||||
Indent,
|
||||
TextAlign,
|
||||
Blockquote,
|
||||
HorizontalRule,
|
||||
// Custom plugins.
|
||||
Image,
|
||||
Link,
|
||||
];
|
||||
|
||||
const [content, setContent] = useState(value);
|
||||
const [version, setVersion] = useState(1);
|
||||
|
||||
function stripHtmlTags(html: string) {
|
||||
const temp = document.createElement('div');
|
||||
temp.innerHTML = html;
|
||||
const text = temp.textContent || temp.innerText || '';
|
||||
return text.trim() === '' ? null : text;
|
||||
}
|
||||
|
||||
const onChangeContent = (changedValue: string) => {
|
||||
const value = stripHtmlTags(changedValue) ? changedValue : "";
|
||||
setContent(value);
|
||||
setData(name, value);
|
||||
};
|
||||
|
||||
// Define some custom attributes in the editor options,
|
||||
// so that we can access them from plugins.
|
||||
const customOptions: UseEditorOptions = {
|
||||
editorProps: {
|
||||
attributes: {
|
||||
// Required status.
|
||||
required: String(required),
|
||||
// Target field name.
|
||||
id,
|
||||
// Target model name.
|
||||
model,
|
||||
},
|
||||
},
|
||||
};
|
||||
], []);
|
||||
|
||||
// Init editor only once.
|
||||
useEffect(() => {
|
||||
if (content !== value) {
|
||||
setContent(value);
|
||||
setVersion(version + 1);
|
||||
const e = new Editor({
|
||||
content: value || undefined,
|
||||
extensions,
|
||||
editable: !disabled,
|
||||
editorProps: { attributes: { id, required: String(required), model } },
|
||||
onUpdate: ({ editor }) => onChangeContent(editor.getHTML()),
|
||||
});
|
||||
setEditor(e);
|
||||
|
||||
return () => e.destroy();
|
||||
}, []);
|
||||
|
||||
// Sync content if parent change.
|
||||
useEffect(() => {
|
||||
if (!editor) return;
|
||||
|
||||
if (!value) {
|
||||
editor.commands.clearContent(true);
|
||||
return;
|
||||
}
|
||||
}, [value]);
|
||||
|
||||
if (editor.getHTML() !== value) {
|
||||
editor.commands.setContent(value);
|
||||
}
|
||||
}, [value, editor]);
|
||||
|
||||
if (!editor) return null;
|
||||
|
||||
return (
|
||||
<div className={cn("col-span-2", { "wysiwyg-error": localErrors[name] }, className)}>
|
||||
<Label htmlFor={name}>
|
||||
{label + (required ? " *" : "")}
|
||||
</Label>
|
||||
{wordCounter && (
|
||||
<WordCounter value={content.replace(/<[^>]*>/g, "")} />
|
||||
)}
|
||||
<div className={cn("mt-1.5", { "mb-1.5": localErrors[name] })}>
|
||||
<RichTextEditor
|
||||
// Force re-render.
|
||||
key={version}
|
||||
output="html"
|
||||
content={content}
|
||||
onChangeContent={onChangeContent}
|
||||
extensions={extensions}
|
||||
disabled={disabled}
|
||||
useEditorOptions={customOptions}
|
||||
dark={false}
|
||||
/>
|
||||
<Label htmlFor={name}>{label + (required ? " *" : "")}</Label>
|
||||
{wordCounter && <WordCounter value={stripHtmlTags(content ?? "") ?? ""} />}
|
||||
<div className="border rounded-md mt-1.5">
|
||||
<Toolbar editor={editor} />
|
||||
<EditorContent editor={editor} className="description w-full max-w-full" />
|
||||
</div>
|
||||
<InputError message={localErrors[name]} />
|
||||
</div>
|
||||
|
|
|
|||
423
resources/ts/back/Components/Inputs/Wysiwyg/Toolbar.tsx
Normal file
423
resources/ts/back/Components/Inputs/Wysiwyg/Toolbar.tsx
Normal file
|
|
@ -0,0 +1,423 @@
|
|||
// * Packages
|
||||
import { Editor } from "@tiptap/react";
|
||||
import { ElementType, useEffect, useState } from "react";
|
||||
import {
|
||||
AlignCenterIcon,
|
||||
AlignJustifyIcon,
|
||||
AlignLeftIcon,
|
||||
AlignRightIcon,
|
||||
BoldIcon,
|
||||
DeleteIcon,
|
||||
HeadingIcon,
|
||||
ItalicIcon,
|
||||
ListIcon,
|
||||
ListOrderedIcon,
|
||||
ListTodoIcon,
|
||||
MinusIcon,
|
||||
PilcrowIcon,
|
||||
QuoteIcon,
|
||||
RedoIcon,
|
||||
RemoveFormattingIcon,
|
||||
StrikethroughIcon,
|
||||
SubscriptIcon,
|
||||
SuperscriptIcon,
|
||||
TextSelectIcon,
|
||||
UnderlineIcon,
|
||||
UndoIcon,
|
||||
} from "lucide-react";
|
||||
// * Components shadcn
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import {
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
TooltipTrigger,
|
||||
} from "@/components/ui/tooltip";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
// * Other
|
||||
import ImageButton from "@/back/Components/Inputs/Wysiwyg/Extensions/Image/ImageButton";
|
||||
import LinkButton from "@/back/Components/Inputs/Wysiwyg/Extensions/Link/LinkButton";
|
||||
import TableButton from "@/back/Components/Inputs/Wysiwyg/Extensions/Table/TableButton";
|
||||
import FindReplaceButton from "@/back/Components/Inputs/Wysiwyg/Extensions/Replace/FindReplaceButton";
|
||||
import BtnOptionnalLinkWithTooltip from "@/back/Components/BtnOptionnalLinkWithTooltip";
|
||||
import useTrans from "@/hooks/use-translations";
|
||||
import str from "@/hooks/use-string";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
type AllowedHeadings = 1 | 2 | 3 | 4 | 5 | 6;
|
||||
|
||||
type AllowedAlignements = "left" | "center" | "right" | "justify";
|
||||
|
||||
type ToolbarProps = {
|
||||
editor: Editor;
|
||||
};
|
||||
|
||||
export default function Toolbar({ editor }: ToolbarProps) {
|
||||
const [, forceUpdate] = useState<number>(0);
|
||||
const [docSelected, setDocSelected] = useState<boolean>(false);
|
||||
|
||||
const headingLevels: AllowedHeadings[] = [1, 2, 3, 4, 5, 6];
|
||||
const currentHeadingLevel = headingLevels.find(level =>
|
||||
editor.isActive("heading", { level })
|
||||
) ?? "";
|
||||
|
||||
const textAligns: { icon: ElementType, value: AllowedAlignements }[] = [
|
||||
{
|
||||
icon: AlignLeftIcon,
|
||||
value: "left",
|
||||
},
|
||||
{
|
||||
icon: AlignCenterIcon,
|
||||
value: "center",
|
||||
},
|
||||
{
|
||||
icon: AlignRightIcon,
|
||||
value: "right",
|
||||
},
|
||||
{
|
||||
icon: AlignJustifyIcon,
|
||||
value: "justify",
|
||||
},
|
||||
];
|
||||
const currentTextAlign = textAligns.find(align => editor.isActive({ textAlign: align })) ?? "left";
|
||||
|
||||
/**
|
||||
* Set heading to the selected content.
|
||||
*
|
||||
* @param value string
|
||||
* @return void
|
||||
*/
|
||||
const handleHeadingChange = (value: string): void => {
|
||||
editor.chain().focus();
|
||||
|
||||
if (value === "paragraph") {
|
||||
editor.chain().focus().setParagraph().run();
|
||||
return;
|
||||
}
|
||||
|
||||
const level = Number(value) as AllowedHeadings;
|
||||
editor.chain().focus().toggleHeading({ level }).run();
|
||||
}
|
||||
|
||||
// Force re-render editor on select to update activated extensions.
|
||||
useEffect(() => {
|
||||
if (!editor) return;
|
||||
|
||||
const update = () => forceUpdate(value => value + 1);
|
||||
|
||||
editor.on("selectionUpdate", () => {
|
||||
update();
|
||||
setDocSelected(editor.state.selection.$anchor.parent.type.name === "doc")
|
||||
});
|
||||
|
||||
return () => {
|
||||
editor.off("selectionUpdate", update);
|
||||
};
|
||||
}, [editor]);
|
||||
|
||||
return (
|
||||
<div className="sticky top-[72px] flex flex-wrap justify-start items-stretch bg-background gap-1 border-b rounded-t-md p-1.5 z-10">
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={<UndoIcon className="w-4 h-4 m-auto" />}
|
||||
tooltipContent={str(useTrans("back.wysiwyg.undo")).ucFirst().value()}
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
editor.chain().focus().undo().run();
|
||||
}}
|
||||
disabled={!editor.can().chain().focus().undo().run()}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
/>
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={<RedoIcon className="w-4 h-4 m-auto" />}
|
||||
tooltipContent={str(useTrans("back.wysiwyg.redo")).ucFirst().value()}
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
editor.chain().focus().redo().run();
|
||||
}}
|
||||
disabled={!editor.can().chain().focus().redo().run()}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
/>
|
||||
<Separator orientation="vertical" className="!h-auto" />
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={<BoldIcon className="w-4 h-4 m-auto" />}
|
||||
tooltipContent={str(useTrans("back.wysiwyg.bold")).ucFirst().value()}
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
editor.chain().focus().toggleBold().run();
|
||||
}}
|
||||
className={editor.isActive("bold") ? "bg-accent" : ""}
|
||||
disabled={docSelected}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
/>
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={<ItalicIcon className="w-4 h-4 m-auto" />}
|
||||
tooltipContent={str(useTrans("back.wysiwyg.italic")).ucFirst().value()}
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
editor.chain().focus().toggleItalic().run();
|
||||
}}
|
||||
className={editor.isActive("italic") ? "bg-accent" : ""}
|
||||
disabled={docSelected}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
/>
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={<StrikethroughIcon className="w-4 h-4 m-auto" />}
|
||||
tooltipContent={str(useTrans("back.wysiwyg.strike")).ucFirst().value()}
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
editor.chain().focus().toggleStrike().run();
|
||||
}}
|
||||
className={editor.isActive("strike") ? "bg-accent" : ""}
|
||||
disabled={docSelected}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
/>
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={<UnderlineIcon className="w-4 h-4 m-auto" />}
|
||||
tooltipContent={str(useTrans("back.wysiwyg.underline")).ucFirst().value()}
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
editor.chain().focus().toggleUnderline().run();
|
||||
}}
|
||||
className={editor.isActive("underline") ? "bg-accent" : ""}
|
||||
disabled={docSelected}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
/>
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={<QuoteIcon className="w-4 h-4 m-auto" />}
|
||||
tooltipContent={str(useTrans("back.wysiwyg.blockquote")).ucFirst().value()}
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
editor.chain().focus().toggleBlockquote().run();
|
||||
}}
|
||||
className={editor.isActive("blockquote") ? "bg-accent" : ""}
|
||||
disabled={docSelected}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
/>
|
||||
<Separator orientation="vertical" className="!h-auto" />
|
||||
<Select
|
||||
value={currentHeadingLevel.toString()}
|
||||
onValueChange={(value) => handleHeadingChange(value)}
|
||||
disabled={docSelected}
|
||||
>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<SelectTrigger className={cn(
|
||||
"w-auto border-none transition-colors",
|
||||
{ "hover:bg-accent hover:text-accent-foreground" : !docSelected },
|
||||
{ "!cursor-default": docSelected },
|
||||
)}>
|
||||
<HeadingIcon className="w-4 h-4" />
|
||||
{currentHeadingLevel && (
|
||||
<SelectValue>{currentHeadingLevel?.toString()}</SelectValue>
|
||||
)}
|
||||
</SelectTrigger>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{useTrans("back.wysiwyg.heading")}</TooltipContent>
|
||||
</Tooltip>
|
||||
<SelectContent>
|
||||
{/* Define default paragraph value to reset heading */}
|
||||
<SelectItem value="paragraph">
|
||||
{useTrans("back.wysiwyg.heading_paragraph")}
|
||||
</SelectItem>
|
||||
{/* List of headings */}
|
||||
{headingLevels.map(level => (
|
||||
<SelectItem key={level} value={level.toString()}>
|
||||
{useTrans("back.wysiwyg.heading_x", { params: { hx: String(level) } })}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Separator orientation="vertical" className="!h-auto" />
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={<ListIcon className="w-4 h-4 m-auto" />}
|
||||
tooltipContent={str(useTrans("back.wysiwyg.bullet_list")).ucFirst().value()}
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
editor.chain().focus().toggleBulletList().run();
|
||||
}}
|
||||
className={editor.isActive("bulletList") ? "bg-accent" : ""}
|
||||
disabled={docSelected}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
/>
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={<ListOrderedIcon className="w-4 h-4 m-auto" />}
|
||||
tooltipContent={str(useTrans("back.wysiwyg.ordered_list")).ucFirst().value()}
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
editor.chain().focus().toggleOrderedList().run();
|
||||
}}
|
||||
className={editor.isActive("orderedList") ? "bg-accent" : ""}
|
||||
disabled={docSelected}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
/>
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={<ListTodoIcon className="w-4 h-4 m-auto" />}
|
||||
tooltipContent={str(useTrans("back.wysiwyg.task_list")).ucFirst().value()}
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
editor.chain().focus().toggleTaskList().run();
|
||||
}}
|
||||
className={editor.isActive("taskList") ? "bg-accent" : ""}
|
||||
disabled={docSelected}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
/>
|
||||
<Separator orientation="vertical" className="!h-auto" />
|
||||
<Select
|
||||
value={currentTextAlign.toString()}
|
||||
onValueChange={(value) => {
|
||||
const align = value as AllowedAlignements;
|
||||
editor.chain().focus().setTextAlign(align).run();
|
||||
}}
|
||||
disabled={docSelected}
|
||||
>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<SelectTrigger className={cn(
|
||||
"w-auto border-none transition-colors",
|
||||
{ "hover:bg-accent hover:text-accent-foreground" : !docSelected },
|
||||
{ "!cursor-default": docSelected },
|
||||
)}>
|
||||
<AlignLeftIcon className="w-4 h-4" />
|
||||
</SelectTrigger>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{useTrans("back.wysiwyg.align")}</TooltipContent>
|
||||
</Tooltip>
|
||||
<SelectContent>
|
||||
{textAligns.map(align => (
|
||||
<SelectItem
|
||||
key={align.value}
|
||||
value={align.value.toString()}
|
||||
>
|
||||
<div className="flex flex-row jsutify-center items-center gap-1.5">
|
||||
{<align.icon className="w-4 h-4" />}
|
||||
{useTrans(`back.wysiwyg.align_${align.value}`)}
|
||||
</div>
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Separator orientation="vertical" className="!h-auto" />
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={<SubscriptIcon className="w-4 h-4 m-auto" />}
|
||||
tooltipContent={str(useTrans("back.wysiwyg.subscript")).ucFirst().value()}
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
editor.chain().focus().toggleSubscript().run();
|
||||
}}
|
||||
className={editor.isActive("subscript") ? "bg-accent" : ""}
|
||||
disabled={docSelected}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
/>
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={<SuperscriptIcon className="w-4 h-4 m-auto" />}
|
||||
tooltipContent={str(useTrans("back.wysiwyg.superscript")).ucFirst().value()}
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
editor.chain().focus().toggleSuperscript().run();
|
||||
}}
|
||||
className={editor.isActive("superscript") ? "bg-accent" : ""}
|
||||
disabled={docSelected}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
/>
|
||||
<Separator orientation="vertical" className="!h-auto" />
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={<MinusIcon className="w-4 h-4 m-auto" />}
|
||||
tooltipContent={str(useTrans("back.wysiwyg.horizontal_rule")).ucFirst().value()}
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
editor.chain().focus().setHorizontalRule().run();
|
||||
}}
|
||||
className={editor.isActive("horizontalRule") ? "bg-accent" : ""}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
/>
|
||||
<TableButton editor={editor} disabled={docSelected} />
|
||||
<ImageButton editor={editor} disabled={docSelected} />
|
||||
<LinkButton editor={editor} disabled={docSelected} />
|
||||
<Separator orientation="vertical" className="!h-auto" />
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={<PilcrowIcon className="w-4 h-4 m-auto" />}
|
||||
tooltipContent={str(useTrans("back.wysiwyg.invisible_characters")).ucFirst().value()}
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
editor.commands.toggleInvisibleCharacters();
|
||||
}}
|
||||
className={editor.storage.invisibleCharacters?.visibility() ? "bg-accent" : ""}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
/>
|
||||
<FindReplaceButton editor={editor} />
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={<TextSelectIcon className="w-4 h-4 m-auto" />}
|
||||
tooltipContent={str(useTrans("back.wysiwyg.select_all")).ucFirst().value()}
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
editor.chain().focus().selectAll().run();
|
||||
}}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
/>
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={<RemoveFormattingIcon className="w-4 h-4 m-auto" />}
|
||||
tooltipContent={str(useTrans("back.wysiwyg.clear_selection")).ucFirst().value()}
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
editor.chain().focus()
|
||||
.unsetAllMarks()
|
||||
.clearNodes()
|
||||
.setParagraph()
|
||||
.setTextAlign("left")
|
||||
.run();
|
||||
}}
|
||||
disabled={editor.getText().trim() === "" && editor.state.selection.empty}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
/>
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={<DeleteIcon className="w-4 h-4 m-auto" />}
|
||||
tooltipContent={str(useTrans("back.wysiwyg.delete_selection")).ucFirst().value()}
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
editor.chain().focus().deleteSelection().run();
|
||||
}}
|
||||
disabled={editor.getText().trim() === "" && editor.state.selection.empty}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
9
resources/ts/back/Components/Inputs/Wysiwyg/tiptap.d.ts
vendored
Normal file
9
resources/ts/back/Components/Inputs/Wysiwyg/tiptap.d.ts
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import '@tiptap/core'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Storage {
|
||||
invisibleCharacters?: {
|
||||
visibility: () => boolean
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -15,7 +15,9 @@
|
|||
])
|
||||
@else
|
||||
@if (!is_array($dynamicPageModel->content))
|
||||
{!! $dynamicPageModel->content !!}
|
||||
<div class="description">
|
||||
{!! $dynamicPageModel->content !!}
|
||||
</div>
|
||||
@endif
|
||||
@endif
|
||||
<p>created_at (Date de création): {{ $dynamicPageModel->created_at }}</p>
|
||||
|
|
|
|||
|
|
@ -15,7 +15,9 @@
|
|||
|
||||
@case(\App\Enums\DynamicFieldTypes::wysiwyg->value())
|
||||
<p>{{ $filteredArray->first()['key'] }} ({{ $filteredArray->first()['label'] }}):</p>
|
||||
{!! $value !!}
|
||||
<div class="description">
|
||||
{!! $value !!}
|
||||
</div>
|
||||
@break
|
||||
|
||||
@case(\App\Enums\DynamicFieldTypes::number->value())
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import defaultTheme from 'tailwindcss/defaultTheme';
|
||||
import forms from '@tailwindcss/forms';
|
||||
import defaultTheme from "tailwindcss/defaultTheme";
|
||||
import forms from "@tailwindcss/forms";
|
||||
import typography from "@tailwindcss/typography";
|
||||
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
export default {
|
||||
|
|
@ -129,5 +130,6 @@ export default {
|
|||
forms,
|
||||
require("tailwindcss-animate"),
|
||||
require('@tailwindcss/typography'),
|
||||
typography,
|
||||
],
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue