-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into task/wr-426-display-new-comment-notif…
…ication-on-all-pages
- Loading branch information
Showing
29 changed files
with
402 additions
and
102 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
frontend/src/libs/components/text-editor/libs/extensions/extensions.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
126 changes: 126 additions & 0 deletions
126
frontend/src/libs/components/text-editor/libs/extensions/indent/indent.extension.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,126 @@ | ||
import { Extension } from '@tiptap/core'; | ||
|
||
import { type ExtensionName } from '../libs/enums/extension-name.enum.js'; | ||
import { | ||
DEFAULT_INDENT_LEVEL, | ||
DEFAULT_OPTIONS_TYPES, | ||
INDENT_LEVELS, | ||
} from './libs/constants/constants.js'; | ||
import { IndentProperty } from './libs/enums/enums.js'; | ||
import { updateIndentLevel } from './libs/helpers/helpers.js'; | ||
import { | ||
type IndentOptions, | ||
type IndentParseHTML, | ||
type IndentRenderHTML, | ||
type NodeAttributesIndent, | ||
} from './libs/types/types.js'; | ||
|
||
declare module '@tiptap/core' { | ||
interface Commands<ReturnType> { | ||
[ExtensionName.INDENT]: { | ||
indent: () => ReturnType; | ||
outdent: () => ReturnType; | ||
}; | ||
} | ||
} | ||
|
||
const Indent = Extension.create<IndentOptions>({ | ||
name: 'indent', | ||
|
||
defaultOptions: { | ||
types: DEFAULT_OPTIONS_TYPES, | ||
indentLevels: [...INDENT_LEVELS], | ||
defaultIndentLevel: DEFAULT_INDENT_LEVEL, | ||
}, | ||
|
||
addGlobalAttributes() { | ||
return [ | ||
{ | ||
types: this.options.types, | ||
attributes: { | ||
indent: { | ||
default: this.options.defaultIndentLevel, | ||
renderHTML: (attributes): IndentRenderHTML => { | ||
const attributesIndent = | ||
attributes.indent as NodeAttributesIndent; | ||
const indent = | ||
typeof attributesIndent === 'object' | ||
? attributesIndent.indent | ||
: attributesIndent; | ||
|
||
return { | ||
style: `text-indent: ${indent}px;`, | ||
}; | ||
}, | ||
parseHTML: (element): IndentParseHTML => { | ||
return { | ||
indent: | ||
Number.parseInt(element.style.textIndent) || | ||
this.options.defaultIndentLevel, | ||
}; | ||
}, | ||
}, | ||
}, | ||
}, | ||
]; | ||
}, | ||
|
||
addCommands() { | ||
return { | ||
indent: () => { | ||
return ({ tr: transaction, state, dispatch, editor }): boolean => { | ||
const { selection } = state; | ||
transaction = transaction.setSelection(selection); | ||
transaction = updateIndentLevel( | ||
transaction, | ||
IndentProperty.MORE, | ||
editor.extensionManager.extensions, | ||
); | ||
|
||
if (transaction.docChanged) { | ||
dispatch && dispatch(transaction); | ||
return true; | ||
} | ||
|
||
return false; | ||
}; | ||
}, | ||
|
||
outdent: () => { | ||
return ({ tr: transaction, state, dispatch, editor }): boolean => { | ||
const { selection } = state; | ||
if (!selection.$anchor.parentOffset) { | ||
transaction = transaction.setSelection(selection); | ||
} | ||
transaction = updateIndentLevel( | ||
transaction, | ||
IndentProperty.LESS, | ||
editor.extensionManager.extensions, | ||
); | ||
|
||
if (transaction.docChanged) { | ||
dispatch && dispatch(transaction); | ||
return true; | ||
} | ||
|
||
return false; | ||
}; | ||
}, | ||
}; | ||
}, | ||
|
||
addKeyboardShortcuts() { | ||
return { | ||
Tab: (): boolean => this.editor.commands.indent(), | ||
'Shift-Tab': (): boolean => this.editor.commands.outdent(), | ||
Backspace: (): boolean => { | ||
if (this.editor.state.selection.$anchor.parentOffset) { | ||
return false; | ||
} | ||
return this.editor.commands.outdent(); | ||
}, | ||
}; | ||
}, | ||
}); | ||
|
||
export { Indent }; |
3 changes: 3 additions & 0 deletions
3
frontend/src/libs/components/text-editor/libs/extensions/indent/libs/constants/constants.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,3 @@ | ||
export { DEFAULT_INDENT_LEVEL } from './default-indent-level.constant.js'; | ||
export { DEFAULT_OPTIONS_TYPES } from './default-options-types.constant.js'; | ||
export { INDENT_LEVELS } from './indent-levels.constant.js'; |
3 changes: 3 additions & 0 deletions
3
...onents/text-editor/libs/extensions/indent/libs/constants/default-indent-level.constant.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,3 @@ | ||
const DEFAULT_INDENT_LEVEL = 0; | ||
|
||
export { DEFAULT_INDENT_LEVEL }; |
3 changes: 3 additions & 0 deletions
3
...nents/text-editor/libs/extensions/indent/libs/constants/default-options-types.constant.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,3 @@ | ||
const DEFAULT_OPTIONS_TYPES = ['heading', 'paragraph']; | ||
|
||
export { DEFAULT_OPTIONS_TYPES }; |
5 changes: 5 additions & 0 deletions
5
...bs/components/text-editor/libs/extensions/indent/libs/constants/indent-levels.constant.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,5 @@ | ||
const INDENT_LEVELS = [ | ||
0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, | ||
] as const; | ||
|
||
export { INDENT_LEVELS }; |
1 change: 1 addition & 0 deletions
1
frontend/src/libs/components/text-editor/libs/extensions/indent/libs/enums/enums.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 @@ | ||
export { IndentProperty } from './indent-properties.enum.js'; |
9 changes: 9 additions & 0 deletions
9
...c/libs/components/text-editor/libs/extensions/indent/libs/enums/indent-properties.enum.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,9 @@ | ||
const IndentProperty = { | ||
MIN: 0, | ||
MAX: 300, | ||
|
||
MORE: 30, | ||
LESS: -30, | ||
} as const; | ||
|
||
export { IndentProperty }; |
2 changes: 2 additions & 0 deletions
2
frontend/src/libs/components/text-editor/libs/extensions/indent/libs/helpers/helpers.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,2 @@ | ||
export { setNodeIndentMarkup } from './set-node-indent-markup.helper.js'; | ||
export { updateIndentLevel } from './update-indent-level.helper.js'; |
51 changes: 51 additions & 0 deletions
51
...mponents/text-editor/libs/extensions/indent/libs/helpers/set-node-indent-markup.helper.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,51 @@ | ||
import { type Transaction } from 'prosemirror-state'; | ||
|
||
import { DEFAULT_INDENT_LEVEL } from '../constants/default-indent-level.constant.js'; | ||
import { IndentProperty } from '../enums/enums.js'; | ||
import { type NodeAttributesIndent } from '../types/types.js'; | ||
|
||
const setNodeIndentMarkup = ( | ||
transaction: Transaction, | ||
position: number, | ||
delta: number, | ||
): Transaction => { | ||
if (!transaction.doc) { | ||
return transaction; | ||
} | ||
|
||
const node = transaction.doc.nodeAt(position); | ||
if (!node) { | ||
return transaction; | ||
} | ||
|
||
const nodeAttributesIndent = node.attrs.indent as NodeAttributesIndent; | ||
|
||
const nodeIndent = | ||
typeof nodeAttributesIndent === 'object' | ||
? nodeAttributesIndent.indent | ||
: nodeAttributesIndent; | ||
|
||
const newIndent = (nodeIndent || DEFAULT_INDENT_LEVEL) + delta; | ||
const indent = Math.min( | ||
Math.max(newIndent, IndentProperty.MIN), | ||
IndentProperty.MAX, | ||
); | ||
|
||
if (indent === node.attrs.indent) { | ||
return transaction; | ||
} | ||
|
||
const nodeAttributes = { | ||
...node.attrs, | ||
indent, | ||
}; | ||
|
||
return transaction.setNodeMarkup( | ||
position, | ||
node.type, | ||
nodeAttributes, | ||
node.marks, | ||
); | ||
}; | ||
|
||
export { setNodeIndentMarkup }; |
39 changes: 39 additions & 0 deletions
39
.../components/text-editor/libs/extensions/indent/libs/helpers/update-indent-level.helper.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,39 @@ | ||
import { type Extensions, isList } from '@tiptap/core'; | ||
import { type Transaction } from 'prosemirror-state'; | ||
import { AllSelection, TextSelection } from 'prosemirror-state'; | ||
|
||
import { DEFAULT_OPTIONS_TYPES } from '../constants/constants.js'; | ||
import { setNodeIndentMarkup } from './set-node-indent-markup.helper.js'; | ||
|
||
const updateIndentLevel = ( | ||
transaction: Transaction, | ||
delta: number, | ||
extensions: Extensions, | ||
): Transaction => { | ||
const { doc, selection } = transaction; | ||
|
||
if (!doc || !selection) { | ||
return transaction; | ||
} | ||
|
||
if ( | ||
!(selection instanceof TextSelection || selection instanceof AllSelection) | ||
) { | ||
return transaction; | ||
} | ||
|
||
const { from, to } = selection; | ||
|
||
doc.nodesBetween(from, to, (node, position) => { | ||
if (DEFAULT_OPTIONS_TYPES.includes(node.type.name)) { | ||
transaction = setNodeIndentMarkup(transaction, position, delta); | ||
return false; | ||
} | ||
|
||
return !isList(node.type.name, extensions); | ||
}); | ||
|
||
return transaction; | ||
}; | ||
|
||
export { updateIndentLevel }; |
7 changes: 7 additions & 0 deletions
7
.../src/libs/components/text-editor/libs/extensions/indent/libs/types/indent-options.type.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,7 @@ | ||
type IndentOptions = { | ||
types: string[]; | ||
indentLevels: number[]; | ||
defaultIndentLevel: number; | ||
}; | ||
|
||
export { type IndentOptions }; |
3 changes: 3 additions & 0 deletions
3
...c/libs/components/text-editor/libs/extensions/indent/libs/types/indent-parse-html.type.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,3 @@ | ||
type IndentParseHTML = { indent: number } | null | undefined; | ||
|
||
export { type IndentParseHTML }; |
3 changes: 3 additions & 0 deletions
3
.../libs/components/text-editor/libs/extensions/indent/libs/types/indent-render-html.type.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,3 @@ | ||
type IndentRenderHTML = { style: string } | null | undefined; | ||
|
||
export { type IndentRenderHTML }; |
7 changes: 7 additions & 0 deletions
7
...s/components/text-editor/libs/extensions/indent/libs/types/node-attributes-indent.type.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,7 @@ | ||
type NodeAttributesIndent = | ||
| number | ||
| { | ||
indent: number; | ||
}; | ||
|
||
export { type NodeAttributesIndent }; |
4 changes: 4 additions & 0 deletions
4
frontend/src/libs/components/text-editor/libs/extensions/indent/libs/types/types.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,4 @@ | ||
export { type IndentOptions } from './indent-options.type.js'; | ||
export { type IndentParseHTML } from './indent-parse-html.type.js'; | ||
export { type IndentRenderHTML } from './indent-render-html.type.js'; | ||
export { type NodeAttributesIndent } from './node-attributes-indent.type.js'; |
1 change: 1 addition & 0 deletions
1
frontend/src/libs/components/text-editor/libs/extensions/libs/enums/extension-name.enum.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,6 +1,7 @@ | ||
const ExtensionName = { | ||
FONT_SIZE: 'fontSize', | ||
UPPERLINE: 'upperline', | ||
INDENT: 'indent', | ||
} as const; | ||
|
||
export { ExtensionName }; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
gap: 20px; | ||
height: 100%; | ||
padding: 20px; | ||
text-align: center; | ||
} | ||
|
||
.emptyArticlesIcon { | ||
|
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
Oops, something went wrong.