fix nextId for components

This commit is contained in:
Ruben Fiszel
2023-01-31 20:48:36 +01:00
parent 8c78d7cddc
commit 3e7899677e
3 changed files with 10 additions and 6 deletions
@@ -56,7 +56,10 @@
function addComponent(appComponent: AppComponent) {
$dirtyStore = true
const grid = $app.grid ?? []
const id = getNextId(grid.map((gridItem) => gridItem.data.id))
const id = getNextId(
grid.map((gridItem) => gridItem.data.id),
true
)
appComponent.id = id
@@ -32,7 +32,7 @@ export async function loadFlowModuleState(flowModule: FlowModule): Promise<FlowM
export const idMutex = new Mutex()
export function getNextId(currentKeys: string[]): string {
export function getNextId(currentKeys: string[], skipTilde: boolean = false): string {
const max = currentKeys.reduce((acc, key) => {
if (key === 'failure' || key.includes('branch') || key.includes('loop')) {
return acc
+5 -4
View File
@@ -179,7 +179,7 @@ export function emptyFlowModuleState(): FlowModuleState {
const aCharCode = 'a'.charCodeAt(0)
export function numberToChars(n: number) {
export function numberToChars(n: number, skipTilde: boolean = false) {
var b = [n],
sp,
out,
@@ -187,11 +187,12 @@ export function numberToChars(n: number) {
div
sp = 0
const basisInc = skipTilde ? -1 : 0
while (sp < b.length) {
if (b[sp] > 25) {
div = Math.floor(b[sp] / 27)
if (b[sp] > (25 + basisInc)) {
div = Math.floor(b[sp] / (27 + basisInc))
b[sp + 1] = div - 1
b[sp] %= 27
b[sp] %= (27 + basisInc)
}
sp += 1
}