2023-06-10 20:33:34 +02:00
|
|
|
import { useState, useEffect } from 'react'
|
|
|
|
import { useTranslation } from 'next-i18next'
|
2023-06-02 18:21:40 +02:00
|
|
|
import { PanZoomPattern as ShowPattern } from 'shared/components/workbench/pan-zoom-pattern.mjs'
|
|
|
|
import { InspectorPattern } from './inspector/pattern.mjs'
|
2023-05-13 14:17:47 +02:00
|
|
|
import { DraftMenu, ns as menuNs } from './menu.mjs'
|
2023-06-02 18:21:40 +02:00
|
|
|
import { objUpdate } from 'shared/utils.mjs'
|
2023-05-11 19:14:48 +02:00
|
|
|
|
2023-05-13 14:17:47 +02:00
|
|
|
export const ns = menuNs
|
|
|
|
|
|
|
|
export const DraftView = ({
|
|
|
|
design,
|
|
|
|
pattern,
|
|
|
|
patternConfig,
|
|
|
|
settings,
|
|
|
|
ui,
|
|
|
|
update,
|
|
|
|
language,
|
|
|
|
account,
|
2023-05-18 15:25:40 +02:00
|
|
|
DynamicDocs,
|
2023-06-10 20:33:34 +02:00
|
|
|
setView,
|
|
|
|
view,
|
2023-06-01 17:01:48 +02:00
|
|
|
}) => {
|
2023-06-02 18:21:40 +02:00
|
|
|
// State for inspector
|
|
|
|
const [inspect, setInspect] = useState({
|
|
|
|
show: {},
|
|
|
|
reveal: {},
|
|
|
|
})
|
2023-06-10 20:33:34 +02:00
|
|
|
|
2023-06-02 18:21:40 +02:00
|
|
|
const inspector = {
|
|
|
|
show: (data) => {
|
|
|
|
const newInspect = { ...inspect }
|
|
|
|
newInspect.show[data.id] = data
|
|
|
|
setInspect(newInspect)
|
|
|
|
},
|
|
|
|
hide: (id) => {
|
|
|
|
const newInspect = { ...inspect }
|
|
|
|
delete newInspect.show[id]
|
|
|
|
delete newInspect.reveal[id]
|
|
|
|
setInspect(newInspect)
|
|
|
|
},
|
|
|
|
reveal: (id) => {
|
|
|
|
const newInspect = { ...inspect }
|
|
|
|
if (newInspect.reveal[id]) delete newInspect.reveal[id]
|
|
|
|
else newInspect.reveal[id] = 1
|
|
|
|
setInspect(newInspect)
|
|
|
|
},
|
|
|
|
update: (path, val) => {
|
|
|
|
const newInspect = objUpdate({ ...inspect }, path, val)
|
|
|
|
setInspect(newInspect)
|
|
|
|
},
|
|
|
|
data: inspect,
|
2023-06-03 16:59:19 +02:00
|
|
|
pattern: pattern,
|
2023-06-02 18:21:40 +02:00
|
|
|
}
|
|
|
|
|
2023-06-01 17:01:48 +02:00
|
|
|
let output = null
|
2023-06-05 19:16:53 +02:00
|
|
|
let renderProps = false
|
2023-06-01 17:01:48 +02:00
|
|
|
if (ui.renderer === 'svg') {
|
|
|
|
try {
|
|
|
|
const __html = pattern.render()
|
|
|
|
output = <div dangerouslySetInnerHTML={{ __html }} />
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err)
|
|
|
|
}
|
2023-06-02 18:21:40 +02:00
|
|
|
} else {
|
2023-06-05 19:16:53 +02:00
|
|
|
renderProps = pattern.getRenderProps()
|
2023-06-02 18:21:40 +02:00
|
|
|
output = ui.inspect ? (
|
2023-06-05 19:16:53 +02:00
|
|
|
<InspectorPattern {...{ renderProps, inspector }} />
|
2023-06-02 18:21:40 +02:00
|
|
|
) : (
|
2023-06-05 19:16:53 +02:00
|
|
|
<ShowPattern {...{ renderProps, inspector }} />
|
2023-06-02 18:21:40 +02:00
|
|
|
)
|
|
|
|
}
|
2023-06-01 17:01:48 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="flex flex-row">
|
2023-06-02 18:21:40 +02:00
|
|
|
<div className="w-2/3 shrink-0 grow lg:p-4 sticky top-0">{output}</div>
|
2023-06-01 17:01:48 +02:00
|
|
|
<div className="w-1/3 shrink grow-0 lg:p-4 max-w-2xl h-screen overflow-scroll">
|
|
|
|
<DraftMenu
|
|
|
|
{...{
|
|
|
|
design,
|
|
|
|
pattern,
|
|
|
|
patternConfig,
|
|
|
|
settings,
|
|
|
|
ui,
|
|
|
|
update,
|
|
|
|
language,
|
|
|
|
account,
|
|
|
|
DynamicDocs,
|
2023-06-02 18:21:40 +02:00
|
|
|
inspector,
|
2023-06-05 19:16:53 +02:00
|
|
|
renderProps,
|
2023-06-10 20:33:34 +02:00
|
|
|
view,
|
|
|
|
setView,
|
2023-06-01 17:01:48 +02:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
2023-05-11 19:14:48 +02:00
|
|
|
</div>
|
2023-06-01 17:01:48 +02:00
|
|
|
)
|
|
|
|
}
|