-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve a bit more with design and usablility
- Loading branch information
Stefan Werner
committed
Nov 11, 2023
1 parent
28056ef
commit 8b8dc32
Showing
19 changed files
with
249 additions
and
149 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import ReactMarkdown from 'react-markdown' | ||
import React from 'react' | ||
import { postProcessTitle } from './position' | ||
|
||
export const generateExpandedKeys = (path) => { | ||
const segments = path.split('-') | ||
const keys = [] | ||
|
||
for (let i = 1; i <= segments.length; i++) { | ||
keys.push(segments.slice(0, i).join('-')) | ||
} | ||
|
||
return keys | ||
} | ||
const customSort = (a, b) => { | ||
if (a === '.text') return -1 | ||
if (b === '.text') return 1 | ||
if (a === '_text') return 1 | ||
if (b === '_text') return -1 | ||
return Number(a) - Number(b) | ||
} | ||
export const convertToAntdTreeData = (node, prefix = '') => { | ||
const result = [] | ||
|
||
if (!node) return [] | ||
const sortedKeys = Object.keys(node).sort(customSort) | ||
for (let key of sortedKeys) { | ||
if (key === '.' || key === '_') continue | ||
const childNode = node[key] | ||
const currentKey = prefix ? `${prefix}-${key}` : key | ||
const isObject = typeof childNode === 'object' | ||
|
||
let title = key | ||
if (key.includes('text')) { | ||
title = ( | ||
<div | ||
style={{ | ||
textAlign: 'justify', | ||
textAlignLast: 'none', | ||
background: '#fff2d4', | ||
}} | ||
> | ||
{' '} | ||
<ReactMarkdown>{postProcessTitle(node[key])}</ReactMarkdown> | ||
</div> | ||
) | ||
} | ||
if (isObject) { | ||
title = postProcessTitle(childNode?.['.']) ?? '' | ||
} | ||
|
||
let treeNode = { | ||
title: title, | ||
key: currentKey, | ||
icon: isObject ? key : key === 'text' ? '◬' : '▰', | ||
} | ||
|
||
// Check if the node has children (ignoring special keys like "." and "_") | ||
if ( | ||
typeof childNode === 'object' && | ||
key !== '.' && | ||
key !== '_' && | ||
!key.includes('text') | ||
) { | ||
treeNode.children = convertToAntdTreeData(childNode, currentKey) | ||
} | ||
|
||
result.push(treeNode) | ||
} | ||
|
||
return result | ||
} | ||
|
||
export const nestTexts = (path, texts) => { | ||
if (!texts) return {} | ||
if (!path) return texts | ||
|
||
const keys = path.split('/').filter(Boolean) // Split by '/' and filter out empty strings | ||
let currentObject = {} | ||
|
||
keys.reduce((obj, key, index) => { | ||
if (index === keys.length - 1) { | ||
// If we are at the last key in the path | ||
obj[key] = Object.fromEntries( | ||
Object.entries(texts).map(([key, value]) => [ | ||
['.', '_'].includes(key) ? key + 'text' : key, | ||
['.', '_'].includes(key) ? value : { text: value }, | ||
]), | ||
) | ||
} else { | ||
obj[key] = {} // Else create an empty object for the next level | ||
} | ||
return obj[key] // Return the nested object for the next iteration | ||
}, currentObject) | ||
|
||
return currentObject | ||
} |
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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import React, { useEffect, useRef } from 'react' | ||
import Muuri from 'muuri' | ||
import '../../muuri.css' | ||
|
||
const areas = { | ||
leftTriangle: { | ||
vertices: [ | ||
{ x: 0, y: window.innerHeight }, // Bottom left | ||
{ x: 0, y: 0 }, // Top left | ||
{ x: window.innerWidth / 2, y: 0 }, // Middle top | ||
], | ||
}, | ||
rightTriangle: { | ||
vertices: [ | ||
{ x: window.innerWidth, y: window.innerHeight }, // right left | ||
{ x: window.innerWidth, y: 0 }, // Top right | ||
{ x: window.innerWidth / 2, y: 0 }, // Middle top | ||
], | ||
}, | ||
} | ||
|
||
function calculatePositionInArea(item, area) { | ||
if (area.vertices) { | ||
// Assuming area is a triangle | ||
const [v1, v2, v3] = area.vertices | ||
|
||
// Randomly choose a point inside the triangle | ||
const r1 = Math.random() | ||
const r2 = Math.random() | ||
const sqrtR1 = Math.sqrt(r1) | ||
|
||
const x = | ||
(1 - sqrtR1) * v1.x + sqrtR1 * (1 - r2) * v2.x + sqrtR1 * r2 * v3.x | ||
const y = | ||
(1 - sqrtR1) * v1.y + sqrtR1 * (1 - r2) * v2.y + sqrtR1 * r2 * v3.y | ||
|
||
return { x, y } | ||
} | ||
} | ||
|
||
function determineAreaForItem(item, areas, index, totalItems) { | ||
// Example: Alternate between left and right triangles | ||
if (index % 2 === 0) { | ||
return areas.leftTriangle | ||
} else { | ||
return areas.rightTriangle | ||
} | ||
} | ||
|
||
function layout(grid) { | ||
const items = grid.getItems() | ||
|
||
items.forEach((item) => { | ||
// Decide in which area the item should be | ||
const area = determineAreaForItem(item, areas) | ||
|
||
// Calculate position based on the area | ||
const position = calculatePositionInArea(item, area) | ||
|
||
// Set the item's left and top CSS properties | ||
item.getElement().style.left = `${position.x}px` | ||
item.getElement().style.top = `${position.y}px` | ||
}) | ||
|
||
// Update the grid after positioning items | ||
grid.refreshItems().layout() | ||
} | ||
|
||
const ControlContainer = ({ children }) => { | ||
const gridRef = useRef(null) | ||
|
||
useEffect(() => { | ||
if (!gridRef.current) return | ||
const grid = new Muuri(gridRef.current, { | ||
dragEnabled: true, | ||
rounding: true, | ||
width: 1000, | ||
layout, | ||
}) | ||
|
||
return () => grid.destroy() | ||
}, [gridRef]) | ||
|
||
return ( | ||
<div ref={gridRef} className="grid"> | ||
{children} | ||
</div> | ||
) | ||
} | ||
|
||
export { ControlContainer } |
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
File renamed without changes.
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
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
2 changes: 1 addition & 1 deletion
2
web/src/ui/MobileControls.jsx → web/src/ui/viewer/MobileControls.jsx
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
2 changes: 1 addition & 1 deletion
2
web/src/ui/MuuriComponent.js → web/src/ui/viewer/MuuriComponent.js
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.