mirror of
https://github.com/hcengineering/platform.git
synced 2025-06-05 15:24:22 +00:00
Fix formatting warnings in text-editor package (#4128)
Signed-off-by: Alexander Onnikov <alexander.onnikov@xored.com>
This commit is contained in:
parent
d3f0ae9667
commit
2e4b6c5fc5
@ -48,8 +48,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
const updateDecorations = () => {
|
||||
if (editor?.schema && comparedYdoc) {
|
||||
const updateDecorations = (): void => {
|
||||
if (editor?.schema !== undefined && comparedYdoc !== undefined) {
|
||||
updateEditor(editor, comparedYdoc, comparedField)
|
||||
}
|
||||
}
|
||||
@ -70,7 +70,7 @@
|
||||
}
|
||||
})
|
||||
|
||||
$: if (editor && comparedYdoc) {
|
||||
$: if (editor !== undefined && comparedYdoc !== undefined) {
|
||||
updateEditor(editor, comparedYdoc, comparedField)
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@
|
||||
})
|
||||
|
||||
onDestroy(() => {
|
||||
if (editor) {
|
||||
if (editor !== undefined) {
|
||||
editor.destroy()
|
||||
}
|
||||
})
|
||||
|
@ -109,21 +109,21 @@
|
||||
}
|
||||
|
||||
export function getHTML (): string | undefined {
|
||||
if (editor) {
|
||||
if (editor !== undefined) {
|
||||
return editor.getHTML()
|
||||
}
|
||||
}
|
||||
|
||||
export function getNodeElement (uuid: string): Element | null {
|
||||
if (!editor || !uuid) {
|
||||
if (editor === undefined || uuid === '') {
|
||||
return null
|
||||
}
|
||||
|
||||
return editor.view.dom.querySelector(nodeElementQuerySelector(uuid))
|
||||
}
|
||||
|
||||
export function selectNode (uuid: string) {
|
||||
if (!editor) {
|
||||
export function selectNode (uuid: string): void {
|
||||
if (editor === undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
@ -138,7 +138,7 @@
|
||||
(mark) => mark.type.name === NodeUuidExtension.name && mark.attrs[NodeUuidExtension.name] === uuid
|
||||
)
|
||||
|
||||
if (!nodeUuidMark) {
|
||||
if (nodeUuidMark === undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
@ -147,7 +147,7 @@
|
||||
// the first pos does not contain the mark, so we need to add 1 (pos + 1) to get the correct range
|
||||
const range = getMarkRange(doc.resolve(pos + 1), schema.marks[NodeUuidExtension.name])
|
||||
|
||||
if (!range) {
|
||||
if (range === undefined) {
|
||||
return false
|
||||
}
|
||||
|
||||
@ -157,8 +157,8 @@
|
||||
})
|
||||
}
|
||||
|
||||
export function selectRange (from: number, to: number) {
|
||||
if (!editor) {
|
||||
export function selectRange (from: number, to: number): void {
|
||||
if (editor === undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
@ -169,18 +169,18 @@
|
||||
}
|
||||
|
||||
export function setNodeUuid (nodeId: string): boolean {
|
||||
if (!editor || editor.view.state.selection.empty || !nodeId) {
|
||||
if (editor === undefined || editor.view.state.selection.empty || nodeId === '') {
|
||||
return false
|
||||
}
|
||||
|
||||
return editor.chain().setNodeUuid(nodeId).run()
|
||||
}
|
||||
|
||||
export function takeSnapshot (snapshotId: string) {
|
||||
export function takeSnapshot (snapshotId: string): void {
|
||||
copyDocumentContent(documentId, snapshotId, { provider }, initialContentId)
|
||||
}
|
||||
|
||||
export function copyField (srcFieldId: string, dstFieldId: string) {
|
||||
export function copyField (srcFieldId: string, dstFieldId: string): void {
|
||||
copyDocumentField(documentId, srcFieldId, dstFieldId, { provider }, initialContentId)
|
||||
}
|
||||
|
||||
@ -193,7 +193,7 @@
|
||||
needFocus = true
|
||||
}
|
||||
|
||||
$: if (editor && needFocus) {
|
||||
$: if (editor !== undefined && needFocus) {
|
||||
if (!focused) {
|
||||
editor.commands.focus(posFocus)
|
||||
posFocus = undefined
|
||||
@ -236,7 +236,7 @@
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
ph.then(() => {
|
||||
void ph.then(() => {
|
||||
editor = new Editor({
|
||||
element,
|
||||
editable: true,
|
||||
@ -309,14 +309,14 @@
|
||||
}
|
||||
})
|
||||
|
||||
if (initialContent) {
|
||||
if (initialContent !== undefined) {
|
||||
editor.commands.insertContent(initialContent)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
onDestroy(() => {
|
||||
if (editor) {
|
||||
if (editor !== undefined) {
|
||||
try {
|
||||
editor.destroy()
|
||||
} catch (err: any) {}
|
||||
@ -337,16 +337,16 @@
|
||||
isFocus: () => document.activeElement === element,
|
||||
canBlur: () => false
|
||||
})
|
||||
const updateFocus = () => {
|
||||
const updateFocus = (): void => {
|
||||
if (focusIndex !== -1) {
|
||||
focusManager?.setFocus(idx)
|
||||
}
|
||||
}
|
||||
$: if (element) {
|
||||
$: if (element !== undefined) {
|
||||
element.addEventListener('focus', updateFocus, { once: true })
|
||||
}
|
||||
|
||||
function handleFocus () {
|
||||
function handleFocus (): void {
|
||||
needFocus = true
|
||||
}
|
||||
</script>
|
||||
|
@ -37,7 +37,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
function openImage () {
|
||||
function openImage (): void {
|
||||
const attributes = textEditor.getAttributes('image')
|
||||
const fileId = attributes['file-id'] ?? attributes.src
|
||||
const fileName = attributes.alt ?? ''
|
||||
@ -51,14 +51,14 @@
|
||||
)
|
||||
}
|
||||
|
||||
function openOriginalImage () {
|
||||
function openOriginalImage (): void {
|
||||
const attributes = textEditor.getAttributes('image')
|
||||
const fileId = attributes['file-id'] ?? attributes.src
|
||||
const url = getFileUrl(fileId, 'full')
|
||||
window.open(url, '_blank')
|
||||
}
|
||||
|
||||
function moreOptions (event: MouseEvent) {
|
||||
function moreOptions (event: MouseEvent): void {
|
||||
const widthActions = ['25%', '50%', '75%', '100%', plugin.string.Unset].map((it) => {
|
||||
return {
|
||||
id: `#imageWidth${it}`,
|
||||
@ -81,7 +81,7 @@
|
||||
(val) => {
|
||||
if (val !== undefined) {
|
||||
const op = actions.find((it) => it.id === val)
|
||||
if (op) {
|
||||
if (op !== undefined) {
|
||||
op.action()
|
||||
dispatch('focus')
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
const dispatch = createEventDispatcher()
|
||||
const linkPlaceholder = getEmbeddedLabel('http://my.link.net')
|
||||
|
||||
function save () {
|
||||
function save (): void {
|
||||
dispatch('update', link)
|
||||
}
|
||||
</script>
|
||||
|
@ -35,7 +35,7 @@
|
||||
let oldContent = ''
|
||||
|
||||
function updateEditor (editor: Editor, comparedVersion?: Markup): void {
|
||||
if (!comparedVersion) {
|
||||
if (comparedVersion === undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
@ -46,8 +46,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
const updateDecorations = () => {
|
||||
if (editor?.schema) {
|
||||
const updateDecorations = (): void => {
|
||||
if (editor?.schema !== undefined) {
|
||||
updateEditor(editor, comparedVersion)
|
||||
}
|
||||
}
|
||||
@ -68,7 +68,7 @@
|
||||
}
|
||||
})
|
||||
|
||||
$: if (editor && comparedVersion) {
|
||||
$: if (editor !== undefined && comparedVersion !== undefined) {
|
||||
updateEditor(editor, comparedVersion)
|
||||
}
|
||||
|
||||
@ -87,7 +87,7 @@
|
||||
})
|
||||
|
||||
onDestroy(() => {
|
||||
if (editor) {
|
||||
if (editor !== undefined) {
|
||||
editor.destroy()
|
||||
}
|
||||
})
|
||||
|
@ -61,7 +61,7 @@
|
||||
$: devSize = $deviceInfo.size
|
||||
$: shrinkButtons = checkAdaptiveMatching(devSize, 'sm')
|
||||
|
||||
function setContent (content: string) {
|
||||
function setContent (content: string): void {
|
||||
textEditor?.setContent(content)
|
||||
}
|
||||
|
||||
@ -106,7 +106,7 @@
|
||||
export let focusIndex = -1
|
||||
const { idx, focusManager } = registerFocus(focusIndex, {
|
||||
focus: () => {
|
||||
const editable = textEditor?.isEditable() ?? false
|
||||
const editable: boolean = textEditor?.isEditable() ?? false
|
||||
if (editable) {
|
||||
focused = true
|
||||
textEditor?.focus()
|
||||
@ -115,7 +115,7 @@
|
||||
},
|
||||
isFocus: () => focused
|
||||
})
|
||||
const updateFocus = () => {
|
||||
const updateFocus = (): void => {
|
||||
if (focusIndex !== -1) {
|
||||
focusManager?.setFocus(idx)
|
||||
}
|
||||
@ -184,7 +184,7 @@
|
||||
showTooltip={{ label: a.label }}
|
||||
size={buttonSize}
|
||||
on:click={handler(a, (a, evt) => {
|
||||
if (!a.disabled) {
|
||||
if (a.disabled !== true) {
|
||||
handleAction(a, evt)
|
||||
}
|
||||
})}
|
||||
|
@ -21,7 +21,7 @@
|
||||
export let compareTo: string
|
||||
export let method: 'diffChars' | 'diffWords' | 'diffWordsWithSpace' = 'diffChars'
|
||||
|
||||
const handleDiff = (oldValue: string, newValue: string) => Diff[method](oldValue, newValue)
|
||||
const handleDiff = (oldValue: string, newValue: string): Diff.Change[] => Diff[method](oldValue, newValue)
|
||||
|
||||
$: changes = handleDiff(compareTo, value)
|
||||
</script>
|
||||
|
@ -24,7 +24,7 @@
|
||||
let rawValue: string
|
||||
let oldContent = ''
|
||||
|
||||
$: if (content && oldContent !== content) {
|
||||
$: if (content !== undefined && oldContent !== content) {
|
||||
oldContent = content
|
||||
rawValue = content
|
||||
}
|
||||
@ -44,12 +44,12 @@
|
||||
|
||||
let needFocus = focus
|
||||
|
||||
$: if (textEditor && needFocus) {
|
||||
$: if (textEditor !== undefined && needFocus) {
|
||||
textEditor.focus()
|
||||
needFocus = false
|
||||
}
|
||||
|
||||
function configureExtensions () {
|
||||
function configureExtensions (): AnyExtension[] {
|
||||
const completionPlugin = Completion.configure({
|
||||
...completionConfig,
|
||||
showDoc (event: MouseEvent, _id: string, _class: string) {
|
||||
|
@ -69,12 +69,16 @@
|
||||
mode = Mode.View
|
||||
}
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
|
||||
let canBlur = true
|
||||
let focused = false
|
||||
let rawValue: string
|
||||
let oldContent = ''
|
||||
let modified: boolean = false
|
||||
|
||||
let textEditor: StyledTextEditor
|
||||
|
||||
$: if (oldContent !== content) {
|
||||
oldContent = content
|
||||
if (rawValue !== content) {
|
||||
@ -86,8 +90,6 @@
|
||||
$: if (!modified && rawValue !== content) modified = true
|
||||
$: dispatch('change', modified)
|
||||
|
||||
let textEditor: StyledTextEditor
|
||||
|
||||
export function submit (): void {
|
||||
textEditor.submit()
|
||||
}
|
||||
@ -103,14 +105,13 @@
|
||||
export function setContent (data: string): void {
|
||||
textEditor.setContent(data)
|
||||
}
|
||||
const dispatch = createEventDispatcher()
|
||||
|
||||
export function isFocused (): boolean {
|
||||
return focused
|
||||
}
|
||||
let needFocus = false
|
||||
|
||||
$: if (textEditor && needFocus) {
|
||||
$: if (textEditor !== undefined && needFocus) {
|
||||
textEditor.focus()
|
||||
needFocus = false
|
||||
}
|
||||
@ -119,7 +120,7 @@
|
||||
export let focusIndex = -1
|
||||
const { idx, focusManager } = registerFocus(focusIndex, {
|
||||
focus: () => {
|
||||
const editable = textEditor?.isEditable()
|
||||
const editable = textEditor?.isEditable() ?? false
|
||||
if (editable) {
|
||||
focused = true
|
||||
focus()
|
||||
@ -134,13 +135,13 @@
|
||||
return true
|
||||
}
|
||||
})
|
||||
const updateFocus = () => {
|
||||
const updateFocus = (): void => {
|
||||
if (focusIndex !== -1) {
|
||||
focusManager?.setFocus(idx)
|
||||
}
|
||||
}
|
||||
|
||||
const handleFocus = (value: boolean) => {
|
||||
const handleFocus = (value: boolean): void => {
|
||||
focused = value
|
||||
if (focused) {
|
||||
updateFocus()
|
||||
@ -166,7 +167,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
function configureExtensions () {
|
||||
function configureExtensions (): AnyExtension[] {
|
||||
const imagePlugin = ImageExtension.configure({
|
||||
inline: true,
|
||||
HTMLAttributes: {},
|
||||
|
@ -125,7 +125,7 @@
|
||||
let needFocus = autofocus
|
||||
const focused = false
|
||||
|
||||
$: if (textEditor && needFocus) {
|
||||
$: if (textEditor !== undefined && needFocus) {
|
||||
if (!focused) textEditor.focus()
|
||||
needFocus = false
|
||||
}
|
||||
|
@ -55,7 +55,9 @@
|
||||
return editor.isEditable
|
||||
}
|
||||
export function setEditable (editable: boolean): void {
|
||||
if (editor) editor.setEditable(editable)
|
||||
if (editor !== undefined) {
|
||||
editor.setEditable(editable)
|
||||
}
|
||||
}
|
||||
export function submit (): void {
|
||||
content = editor.getHTML()
|
||||
@ -104,7 +106,7 @@
|
||||
needFocus = true
|
||||
}
|
||||
|
||||
$: if (editor && needFocus) {
|
||||
$: if (editor != null && needFocus) {
|
||||
if (!focused) {
|
||||
editor.commands.focus(posFocus)
|
||||
posFocus = undefined
|
||||
@ -146,7 +148,7 @@
|
||||
})
|
||||
|
||||
onMount(() => {
|
||||
ph.then(() => {
|
||||
void ph.then(() => {
|
||||
editor = new Editor({
|
||||
element,
|
||||
editorProps: { attributes: mergeAttributes(defaultEditorAttributes, editorAttributes) },
|
||||
@ -197,16 +199,14 @@
|
||||
})
|
||||
|
||||
onDestroy(() => {
|
||||
if (editor) {
|
||||
editor.destroy()
|
||||
}
|
||||
editor?.destroy()
|
||||
})
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export function removeNode (nde: ProseMirrorNode): void {
|
||||
const deleteOp = (n: ProseMirrorNode, pos: number) => {
|
||||
const deleteOp = (n: ProseMirrorNode, pos: number): void => {
|
||||
if (nde === n) {
|
||||
// const pos = editor.view.posAtDOM(nde, 0)
|
||||
editor.view.dispatch(editor.view.state.tr.delete(pos, pos + 1))
|
||||
|
@ -79,7 +79,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
function insertTable (event: MouseEvent) {
|
||||
function insertTable (event: MouseEvent): void {
|
||||
showPopup(
|
||||
SelectPopup,
|
||||
{
|
||||
@ -97,7 +97,7 @@
|
||||
return
|
||||
}
|
||||
const tab = mInsertTable.find((it) => it.label === val)
|
||||
if (tab) {
|
||||
if (tab !== undefined) {
|
||||
textEditor.commands.insertTable({
|
||||
cols: tab.cols,
|
||||
rows: tab.rows,
|
||||
@ -111,7 +111,7 @@
|
||||
)
|
||||
}
|
||||
|
||||
function tableOptions (event: MouseEvent) {
|
||||
function tableOptions (event: MouseEvent): void {
|
||||
const ops = [
|
||||
{
|
||||
id: '#addColumnBefore',
|
||||
@ -188,7 +188,7 @@
|
||||
(val) => {
|
||||
if (val !== undefined) {
|
||||
const op = ops.find((it) => it.id === val)
|
||||
if (op) {
|
||||
if (op !== undefined) {
|
||||
op.action()
|
||||
dispatch('focus')
|
||||
}
|
||||
|
@ -28,13 +28,13 @@
|
||||
$: minLevel = items.reduce((p, v) => Math.min(p, v.level), Infinity)
|
||||
$: maxLevel = items.reduce((p, v) => Math.max(p, v.level), 0)
|
||||
|
||||
function getLevelWidth (level: number) {
|
||||
function getLevelWidth (level: number): number {
|
||||
return (100 * (maxLevel - level + 1)) / (maxLevel - minLevel + 1)
|
||||
}
|
||||
|
||||
let hovered = false
|
||||
|
||||
function handleOpenToc (ev: MouseEvent) {
|
||||
function handleOpenToc (ev: MouseEvent): void {
|
||||
ev.preventDefault()
|
||||
ev.stopPropagation()
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
getPopupPositionElement(ev.target as HTMLElement, { v: 'top', h: 'right' }),
|
||||
(res) => {
|
||||
hovered = false
|
||||
if (res) {
|
||||
if (res != null) {
|
||||
dispatch('select', res)
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
$: minLevel = items.reduce((p, v) => Math.min(p, v.level), Infinity)
|
||||
|
||||
function getIndentLevel (level: number) {
|
||||
function getIndentLevel (level: number): number {
|
||||
return 1 * (level - minLevel)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user