deployment fix

This commit is contained in:
Jeff Emmett 2025-11-11 22:42:38 -08:00
parent 2528ad4726
commit 04f6fe5192
1 changed files with 34 additions and 36 deletions

View File

@ -65,44 +65,42 @@ export function usePinnedToView(editor: Editor | null, shapeId: string | undefin
// Bring the shape to the front by manually setting index // Bring the shape to the front by manually setting index
// Note: sendToFront doesn't exist in this version of tldraw, so we use manual index setting // Note: sendToFront doesn't exist in this version of tldraw, so we use manual index setting
try { // Try to set a safe index value
// Try to set a safe index value // Use conservative values that are known to work (a1, a2, b1, etc.)
// Use conservative values that are known to work (a1, a2, b1, etc.) let newIndex: string = 'a2' // Safe default
let newIndex: string = 'a2' // Safe default
// Try to find a valid index higher than existing ones // Try to find a valid index higher than existing ones
const allIndices = allShapes const allIndices = allShapes
.map(s => s.index) .map(s => s.index)
.filter((idx): idx is string => typeof idx === 'string' && /^[a-z]\d+$/.test(idx)) .filter((idx): idx is string => typeof idx === 'string' && /^[a-z]\d+$/.test(idx))
.sort() .sort()
if (allIndices.length > 0) { if (allIndices.length > 0) {
const highest = allIndices[allIndices.length - 1] const highest = allIndices[allIndices.length - 1]
const match = highest.match(/^([a-z])(\d+)$/) const match = highest.match(/^([a-z])(\d+)$/)
if (match) { if (match) {
const letter = match[1] const letter = match[1]
const num = parseInt(match[2], 10) const num = parseInt(match[2], 10)
// Increment number, or move to next letter if number gets too high // Increment number, or move to next letter if number gets too high
if (num < 100) { if (num < 100) {
newIndex = `${letter}${num + 1}` newIndex = `${letter}${num + 1}`
} else if (letter < 'y') { } else if (letter < 'y') {
const nextLetter = String.fromCharCode(letter.charCodeAt(0) + 1) const nextLetter = String.fromCharCode(letter.charCodeAt(0) + 1)
newIndex = `${nextLetter}1` newIndex = `${nextLetter}1`
} else { } else {
// Use a safe value if we're running out of letters // Use a safe value if we're running out of letters
newIndex = 'a2' newIndex = 'a2'
}
} }
} }
}
// Validate before using // Validate before using
if (/^[a-z]\d+$/.test(newIndex)) { if (/^[a-z]\d+$/.test(newIndex)) {
editor.updateShape({ editor.updateShape({
id: shapeId as TLShapeId, id: shapeId as TLShapeId,
type: shape.type, type: shape.type,
index: newIndex as any, index: newIndex as any,
}) })
}
} }
} catch (error) { } catch (error) {
console.error('Error bringing pinned shape to front:', error) console.error('Error bringing pinned shape to front:', error)