Add widget catalog and restore canvas preview tools
This commit is contained in:
1 parent
12a8c24441
commit
beeca041ef
13 files changed
+489
-35
No files matched your search
@@ -12,6 +12,8 @@ const props = defineProps<{
|
||||
selectedId?: string;
|
||||
editable?: boolean;
|
||||
guides?: boolean;
|
||||
dragGuides?: { x?: number; y?: number };
|
||||
showWhitespace?: boolean;
|
||||
}>();
|
||||
const emit = defineEmits<{
|
||||
startDrag: [event: PointerEvent, item: LayoutItem, resize: boolean];
|
||||
@@ -20,9 +22,20 @@ const emit = defineEmits<{
|
||||
const canvas = computed(() => props.layout.canvas);
|
||||
const width = computed(() => props.device?.w ?? canvas.value.designWidth);
|
||||
const height = computed(() => props.device?.h ?? canvas.value.designHeight);
|
||||
const mapper = computed(() => props.device
|
||||
const deviceMap = computed(() => props.device
|
||||
? deviceMapper(canvas.value, props.layout.fit, props.page.items, props.device)
|
||||
: { sx: 1, sy: 1, x: (n: number) => n, y: (n: number) => n });
|
||||
: undefined);
|
||||
const mapper = computed(() => deviceMap.value ?? { sx: 1, sy: 1, x: (n: number) => n, y: (n: number) => n });
|
||||
const whitespace = computed(() => {
|
||||
const insets = deviceMap.value?.insets;
|
||||
if (!props.showWhitespace || !insets || !Object.values(insets).some(value => value > 0.5)) return undefined;
|
||||
return {
|
||||
top: percent(insets.top, height.value),
|
||||
bottom: percent(insets.bottom, height.value),
|
||||
left: percent(insets.left, width.value),
|
||||
right: percent(insets.right, width.value),
|
||||
};
|
||||
});
|
||||
const items = computed(() => sortedItems(props.page));
|
||||
const known = new Set(["app_icon", "widget", "shortcut", "dock_bg"]);
|
||||
const visible = computed(() => props.editable ? items.value : items.value.filter(item => known.has(item.type)));
|
||||
@@ -63,5 +76,16 @@ function title(item: LayoutItem) {
|
||||
<span v-if="editable" class="resize-handle" aria-hidden="true"
|
||||
@pointerdown="emit('startDrag', $event, item, true)"></span>
|
||||
</div>
|
||||
<template v-if="editable && guides && dragGuides">
|
||||
<div v-if="dragGuides.x !== undefined" class="drag-guide vertical"
|
||||
:style="{ left: percent(dragGuides.x, width) }" aria-hidden="true" />
|
||||
<div v-if="dragGuides.y !== undefined" class="drag-guide horizontal"
|
||||
:style="{ top: percent(dragGuides.y, height) }" aria-hidden="true" />
|
||||
</template>
|
||||
<template v-if="whitespace">
|
||||
<div v-for="(size, side) in whitespace" :key="side" class="preview-gap" :class="side"
|
||||
:style="{ '--gap-size': size }" aria-hidden="true" />
|
||||
<div class="preview-content-boundary" :style="whitespace" aria-hidden="true" />
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user