-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(contributions): transformation des H3 et H4 des contributions en…
… titre et sous-titres (#1259)
- Loading branch information
1 parent
335bf4f
commit f1fdaa1
Showing
11 changed files
with
213 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
targets/frontend/src/components/forms/EditionField/extensions/Titles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { mergeAttributes, Node, textblockTypeInputRule } from "@tiptap/core"; | ||
|
||
export type Level = "title" | "sub-title"; | ||
|
||
export interface TitleOptions { | ||
levels: Level[]; | ||
HTMLAttributes: Record<string, any>; | ||
} | ||
|
||
declare module "@tiptap/core" { | ||
interface Commands<ReturnType> { | ||
title: { | ||
setTitle: (attributes: { level: Level }) => ReturnType; | ||
toggleTitle: (attributes: { level: Level }) => ReturnType; | ||
unsetTitle: () => ReturnType; | ||
}; | ||
} | ||
} | ||
|
||
export const Title = Node.create<TitleOptions>({ | ||
name: "title", | ||
|
||
addOptions() { | ||
return { | ||
levels: ["title", "sub-title"], | ||
HTMLAttributes: {}, | ||
}; | ||
}, | ||
|
||
content: "inline*", | ||
|
||
group: "block", | ||
|
||
defining: true, | ||
|
||
addAttributes() { | ||
return { | ||
level: { | ||
default: "title", | ||
rendered: false, | ||
}, | ||
}; | ||
}, | ||
|
||
parseHTML() { | ||
return this.options.levels.map((level: Level) => ({ | ||
tag: `span`, | ||
attrs: { level }, | ||
})); | ||
}, | ||
|
||
renderHTML({ node, HTMLAttributes }) { | ||
const hasLevel = this.options.levels.includes(node.attrs.level); | ||
const level = hasLevel ? node.attrs.level : this.options.levels[0]; | ||
|
||
return ["span", mergeAttributes({ class: `${level}` }, HTMLAttributes), 0]; | ||
}, | ||
|
||
addCommands() { | ||
return { | ||
setTitle: | ||
(attributes) => | ||
({ commands }) => { | ||
if (!this.options.levels.includes(attributes.level)) { | ||
return false; | ||
} | ||
|
||
return commands.setNode(this.name, attributes); | ||
}, | ||
toggleTitle: | ||
(attributes) => | ||
({ commands }) => { | ||
if (!this.options.levels.includes(attributes.level)) { | ||
return false; | ||
} | ||
|
||
return commands.toggleNode(this.name, "paragraph", attributes); | ||
}, | ||
unsetTitle: () => ({ commands }) => { | ||
return commands.lift(this.name) | ||
}, | ||
}; | ||
}, | ||
|
||
addInputRules() { | ||
return this.options.levels.map((level) => { | ||
return textblockTypeInputRule({ | ||
find: new RegExp(`^(#{${level}})\\s$`), | ||
type: this.type, | ||
getAttributes: { | ||
level, | ||
}, | ||
}); | ||
}); | ||
}, | ||
}); |
1 change: 1 addition & 0 deletions
1
targets/frontend/src/components/forms/EditionField/extensions/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./Alert"; | ||
export * from "./Titles"; |
Empty file.
Oops, something went wrong.