-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Stage progress bar - Fixed stage output loop - Scripture style template will also override created shows - Some dynamic values working in stage output - Opening edit section tabs will no longer apply preset styles to reduce confusion - Fixed edit values not always resetting
- Loading branch information
Showing
32 changed files
with
666 additions
and
350 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
266 changes: 131 additions & 135 deletions
266
src/frontend/components/edit/editbox/EditboxHelper.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,149 +1,145 @@ | ||
import type { Item, Line } from "../../../../types/Show" | ||
|
||
export class EditboxHelper { | ||
//Compare text of all the new lines to determine if it's truly a modification or just an index change. | ||
//Set the cursor to the start of the last line that was modified. | ||
static determineCaretLine(oldLines: Line[], newLines: Line[]) { | ||
const oldTexts: string[] = [] | ||
const newTexts: string[] = [] | ||
|
||
oldLines?.forEach((line) => { | ||
oldTexts.push(line.text[0].value) | ||
}) | ||
|
||
newLines.forEach((line) => { | ||
newTexts.push(line.text[0].value) | ||
}) | ||
|
||
|
||
//Compare text of all the new lines to determine if it's truly a modification or just an index change. | ||
//Set the cursor to the start of the last line that was modified. | ||
static determineCaretLine(oldLines:Line[], newLines: Line[]) { | ||
const oldTexts:string[] = []; | ||
const newTexts:string[] = []; | ||
|
||
oldLines?.forEach((line) => { | ||
oldTexts.push(line.text[0].value); | ||
}); | ||
|
||
newLines.forEach((line) => { | ||
newTexts.push(line.text[0].value); | ||
}); | ||
|
||
let lastLineChanged = -1; | ||
if (oldTexts.length === newTexts.length) return lastLineChanged; | ||
for (let i=0; i<newTexts.length; i++) { | ||
const nt = newTexts[i]; | ||
const index = oldTexts.indexOf(nt); | ||
if (index === -1) lastLineChanged = i; | ||
else oldTexts.splice(index, 1); | ||
let lastLineChanged = -1 | ||
if (oldTexts.length === newTexts.length) return lastLineChanged | ||
for (let i = 0; i < newTexts.length; i++) { | ||
const nt = newTexts[i] | ||
const index = oldTexts.indexOf(nt) | ||
if (index === -1) lastLineChanged = i | ||
else oldTexts.splice(index, 1) | ||
} | ||
return lastLineChanged | ||
} | ||
|
||
static splitAllCrlf(lines: Line[]) { | ||
let result: Line[] = [] | ||
lines.forEach((line) => { | ||
let splitLines = this.splitCrlf(line) | ||
result.push(...splitLines) | ||
}) | ||
return result | ||
} | ||
return lastLineChanged; | ||
} | ||
|
||
static splitAllCrlf(lines: Line[]) { | ||
let result: Line[] = [] | ||
lines.forEach((line) => { | ||
let splitLines = this.splitCrlf(line) | ||
result.push(...splitLines) | ||
}) | ||
return result | ||
} | ||
|
||
static splitCrlf(line: Line) { | ||
const result: Line[] = [] | ||
let newLine = { ...line } | ||
newLine.text = [] | ||
|
||
line.text.forEach((text) => { | ||
let value = text.value | ||
let parts = value.replace("\r", "").split("\n") | ||
newLine.text.push({ style: text.style, value: parts[0] }) | ||
if (parts.length > 1) { | ||
for (let i = 1; i < parts.length; i++) { | ||
result.push(newLine) | ||
newLine = { ...line } | ||
newLine.text = [{ style: text.style, value: parts[i] }] | ||
|
||
static splitCrlf(line: Line) { | ||
const result: Line[] = [] | ||
let newLine = { ...line } | ||
newLine.text = [] | ||
|
||
line.text.forEach((text) => { | ||
let value = text.value | ||
let parts = value.replace("\r", "").split("\n") | ||
newLine.text.push({ style: text.style, value: parts[0] }) | ||
if (parts.length > 1) { | ||
for (let i = 1; i < parts.length; i++) { | ||
result.push(newLine) | ||
newLine = { ...line } | ||
newLine.text = [{ style: text.style, value: parts[i] }] | ||
} | ||
} | ||
} | ||
}) | ||
result.push(newLine) | ||
return result | ||
} | ||
|
||
static cutLinesInTwo({ sel, lines, currentIndex, textPos, start }) { | ||
let firstLines: Line[] = [] | ||
let secondLines: Line[] = [] | ||
|
||
lines.forEach((line:Line, i:number) => { | ||
if (start > -1 && currentIndex >= start) secondLines.push({ align: line.align, text: [] }) | ||
else firstLines.push({ align: line.align, text: [] }) | ||
|
||
textPos = 0 | ||
line.text?.forEach((text) => { | ||
currentIndex += text.value.length | ||
if (sel[i]?.start !== undefined) start = sel[i].start | ||
|
||
if (start > -1 && currentIndex >= start) { | ||
if (!secondLines.length) secondLines.push({ align: line.align, text: [] }) | ||
let pos = sel[i].start - textPos | ||
if (pos > 0) | ||
}) | ||
result.push(newLine) | ||
return result | ||
} | ||
|
||
static cutLinesInTwo({ sel, lines, currentIndex, textPos, start }) { | ||
let firstLines: Line[] = [] | ||
let secondLines: Line[] = [] | ||
|
||
lines.forEach((line: Line, i: number) => { | ||
if (start > -1 && currentIndex >= start) secondLines.push({ align: line.align, text: [] }) | ||
else firstLines.push({ align: line.align, text: [] }) | ||
|
||
textPos = 0 | ||
line.text?.forEach((text) => { | ||
currentIndex += text.value.length | ||
if (sel[i]?.start !== undefined) start = sel[i].start | ||
|
||
if (start > -1 && currentIndex >= start) { | ||
if (!secondLines.length) secondLines.push({ align: line.align, text: [] }) | ||
let pos = sel[i].start - textPos | ||
if (pos > 0) | ||
firstLines[firstLines.length - 1].text.push({ | ||
style: text.style, | ||
value: text.value.slice(0, pos), | ||
}) | ||
secondLines[secondLines.length - 1].text.push({ | ||
style: text.style, | ||
value: text.value.slice(pos, text.value.length), | ||
}) | ||
} else { | ||
firstLines[firstLines.length - 1].text.push({ | ||
style: text.style, | ||
value: text.value.slice(0, pos), | ||
value: text.value, | ||
}) | ||
secondLines[secondLines.length - 1].text.push({ | ||
style: text.style, | ||
value: text.value.slice(pos, text.value.length), | ||
}) | ||
} else { | ||
firstLines[firstLines.length - 1].text.push({ | ||
style: text.style, | ||
value: text.value, | ||
}) | ||
} | ||
textPos += text.value.length | ||
}) | ||
} | ||
textPos += text.value.length | ||
}) | ||
|
||
if (!firstLines.at(-1)?.text.length) firstLines.pop() | ||
}) | ||
|
||
let defaultLine = [ | ||
{ | ||
align: lines[0].align || "", | ||
text: [{ style: lines[0].text[0]?.style || "", value: "" }], | ||
}, | ||
] | ||
if (!firstLines.length || !firstLines[0].text.length) firstLines = defaultLine | ||
if (!secondLines.length) secondLines = defaultLine | ||
return {firstLines, secondLines} | ||
} | ||
|
||
static getSyleHtml(item:Item, plain:boolean, currentStyle:string) { | ||
let html = "" | ||
let firstTextStyleArchive: string = "" | ||
let lineBg = item.specialStyle?.lineBg ? `background-color: ${item.specialStyle.lineBg};` : "" | ||
item?.lines?.forEach((line, i) => { | ||
let align = line.align.replaceAll(lineBg, "") | ||
currentStyle += align + lineBg | ||
let style = align || lineBg ? 'style="' + align + lineBg + '"' : "" | ||
html += `<div class="break" ${plain ? "" : style}>` | ||
|
||
// fix removing all text in a line | ||
if (i === 0 && line.text?.[0]?.style) firstTextStyleArchive = line.text?.[0]?.style || "" | ||
if (!line.text?.length) line.text = [{ style: firstTextStyleArchive || "", value: "" }] | ||
|
||
let currentChords = line.chords || [] | ||
let textIndex = 0 | ||
|
||
line.text?.forEach((a, tIndex) => { | ||
currentStyle += this.getTextStyle(a) | ||
|
||
// SAVE CHORDS (WIP does not work well with more "text" per line) | ||
let textEnd = textIndex + a.value.length | ||
let textChords = currentChords.filter((a) => a.pos >= textIndex && (a.pos <= textEnd || line.text.length - 1 >= tIndex)) | ||
textIndex = textEnd | ||
|
||
let style = a.style ? 'style="' + a.style + '"' : "" | ||
|
||
html += `<span class="${a.customType ? "custom" : ""}" ${plain ? "" : style} data-chords='${JSON.stringify(textChords)}'>` + (a.value.replaceAll("\n", "<br>") || "<br>") + "</span>" | ||
if (!firstLines.at(-1)?.text.length) firstLines.pop() | ||
}) | ||
html += "</div>" | ||
}) | ||
return {html, currentStyle}; | ||
} | ||
|
||
static getTextStyle(lineText:any) { | ||
let style = lineText.style || "" | ||
return style | ||
} | ||
let defaultLine = [ | ||
{ | ||
align: lines[0].align || "", | ||
text: [{ style: lines[0].text[0]?.style || "", value: "" }], | ||
}, | ||
] | ||
if (!firstLines.length || !firstLines[0].text.length) firstLines = defaultLine | ||
if (!secondLines.length) secondLines = defaultLine | ||
return { firstLines, secondLines } | ||
} | ||
|
||
static getSyleHtml(item: Item, plain: boolean, currentStyle: string) { | ||
let html = "" | ||
let firstTextStyleArchive: string = "" | ||
let lineBg = item.specialStyle?.lineBg ? `background-color: ${item.specialStyle.lineBg};` : "" | ||
item?.lines?.forEach((line, i) => { | ||
let align = line.align.replaceAll(lineBg, "") | ||
currentStyle += align + lineBg | ||
let style = align || lineBg ? 'style="' + align + ";" + lineBg + '"' : "" | ||
html += `<div class="break" ${plain ? "" : style}>` | ||
|
||
// fix removing all text in a line | ||
if (i === 0 && line.text?.[0]?.style) firstTextStyleArchive = line.text?.[0]?.style || "" | ||
if (!line.text?.length) line.text = [{ style: firstTextStyleArchive || "", value: "" }] | ||
|
||
let currentChords = line.chords || [] | ||
let textIndex = 0 | ||
|
||
line.text?.forEach((a, tIndex) => { | ||
currentStyle += this.getTextStyle(a) | ||
|
||
} | ||
// SAVE CHORDS (WIP does not work well with more "text" per line) | ||
let textEnd = textIndex + a.value.length | ||
let textChords = currentChords.filter((a) => a.pos >= textIndex && (a.pos <= textEnd || line.text.length - 1 >= tIndex)) | ||
textIndex = textEnd | ||
|
||
let style = a.style ? 'style="' + a.style + '"' : "" | ||
|
||
html += `<span class="${a.customType ? "custom" : ""}" ${plain ? "" : style} data-chords='${JSON.stringify(textChords)}'>` + (a.value.replaceAll("\n", "<br>") || "<br>") + "</span>" | ||
}) | ||
html += "</div>" | ||
}) | ||
return { html, currentStyle } | ||
} | ||
|
||
static getTextStyle(lineText: any) { | ||
let style = lineText.style || "" | ||
return style | ||
} | ||
} |
Oops, something went wrong.