Skip to content

Commit 0c10e0d

Browse files
committed
v0feat: better types
- Improved component types. - Also, small change, technically breaking, but half of it wasn't even working. LayoutWindow now takes edgesProps and frameProps instead of prefixed attributes (e.g. edges-class). Also there is no decosProps, they weren't actually passed down before anyways.
1 parent c78c894 commit 0c10e0d

7 files changed

Lines changed: 74 additions & 59 deletions

File tree

eslint.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export default createConfigForNuxt({
1212
{
1313
rules: {
1414
"jsdoc/check-tag-names": ["warn", { definedTags: [
15-
"experimental"
15+
"experimental",
16+
"@vue-ignore"
1617
] }]
1718
}
1819
},

src/runtime/components/LayoutDecos.vue

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
<template>
2-
<!-- <div -->
3-
<!-- v-bind="$attrs" -->
4-
<!-- class="decos" -->
5-
<!-- > -->
62
<template
73
v-for="(deco) of splitDecos"
84
:key="deco.id"
@@ -34,21 +30,15 @@
3430
:css="getShapeSquareCss( frames[deco.id], `var(--layoutEdgeWidth,2px)`)"
3531
/>
3632
</template>
37-
<!-- </div> -->
3833
</template>
3934
<script lang="ts" setup>
40-
import { twMerge } from "@witchcraft/ui/utils/twMerge"
41-
import type { PropType } from "vue"
42-
import { computed, inject, ref, useAttrs } from "vue"
4335
4436
import LayoutShapeSquare from "./LayoutShapeSquare.vue"
4537
46-
import { dirToOrientation } from "../helpers/dirToOrientation.js"
4738
import { getShapeSquareCss } from "../helpers/getShapeSquareCss"
4839
import { getVisualEdgeCss } from "../helpers/getVisualEdgeCss"
4940
import { type CloseDeco, type LayoutFrames, type Size, type SplitDeco } from "../types/index.js"
5041
51-
const $attrs = useAttrs()
5242
5343
const props = withDefaults(defineProps<{
5444
frames: LayoutFrames

src/runtime/components/LayoutEdges.vue

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
border-blue-500
1010
border
1111
`,
12+
($attrs as any).class
1213
)"
14+
v-bind="{...$attrs, class: undefined}"
1315
/>
1416

1517
<template
@@ -73,51 +75,42 @@
7375
</template>
7476
<script lang="ts" setup>
7577
import { twMerge } from "@witchcraft/ui/utils/twMerge"
76-
import { computed,type PropType, ref,useAttrs } from "vue"
78+
import { computed,useAttrs } from "vue"
7779
7880
import LayoutShapeSquare from "./LayoutShapeSquare.vue"
7981
80-
import { frameToEdges } from "../helpers/frameToEdges.js"
8182
import { getIntersectionsCss } from "../helpers/getIntersectionsCss.js"
8283
import { getShapeSquareCss } from "../helpers/getShapeSquareCss.js"
8384
import { getVisualEdgesCss } from "../helpers/getVisualEdgesCss.js"
8485
import { isEdgeEqual } from "../helpers/isEdgeEqual.js"
85-
import { toWindowCoord } from "../helpers/toWindowCoord.js"
8686
import {
8787
type Edge,
8888
type EdgeCss,
8989
type IntersectionEntry,
90-
type LayoutFrame,
91-
type LayoutWindow,
92-
type Point,
90+
type LayoutEdgesProps,
9391
} from "../types/index.js"
9492
const $attrs = useAttrs()
9593
94+
defineOptions({
95+
inheritAttrs: false,
96+
})
97+
9698
const emit = defineEmits<{
9799
dragStart: [e: PointerEvent, { edge?: Edge, intersection?: IntersectionEntry }]
98100
}>()
99-
const props = withDefaults(defineProps< {
100-
edges: Edge[]
101-
intersections: IntersectionEntry[]
102-
/** The owning window, needed so we can correctly scale coordinates. */
103-
win: LayoutWindow
104-
/** The active frame, used to render the active edges. Calculate it from the `frames` returned by `useFrames` composable because otherwise it will be the wrong size while dragging. */
105-
activeFrame?: LayoutFrame
106-
draggingEdge?: Edge
107-
draggingIntersection?: IntersectionEntry
108-
}>(), {
101+
const props = withDefaults(defineProps<LayoutEdgesProps>(), {
109102
activeFrame: undefined,
110103
draggingEdge: undefined,
111104
draggingIntersection: undefined,
112105
})
113106
114107
115-
const activeFrameCssEdges = computed(() => {
116-
if (!props.activeFrame) return []
117-
return getVisualEdgesCss(Object.values(frameToEdges(props.activeFrame)), {
118-
edgeWidth: `var(--layoutEdgeWidth, 2px)`,
119-
})
120-
})
108+
// const activeFrameCssEdges = computed(() => {
109+
// if (!props.activeFrame) return []
110+
// return getVisualEdgesCss(Object.values(frameToEdges(props.activeFrame)), {
111+
// edgeWidth: `var(--layoutEdgeWidth, 2px)`,
112+
// })
113+
// })
121114
122115
const cssDragEdges = computed(() => {
123116
const thickEdges = getVisualEdgesCss(

src/runtime/components/LayoutFrame.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<template>
2-
<!-- @vue-expect-error just let it inherit extra attrs -->
32
<!-- overflow-hidden is just in case, if the frame's css is not properly set to h-full, overflow-auto, or the border/padding are too large, we can still get overflows -->
43
<LayoutShapeSquare
54
tabindex="0"
@@ -9,7 +8,7 @@
98
p-[var(--layoutEdgeWidth,_2px)]
109
overflow-hidden
1110
`,
12-
$attrs.class
11+
($attrs as any).class
1312
)"
1413
v-bind="{...$attrs, class: undefined}"
1514
@focus="emit('focus')"
@@ -24,24 +23,25 @@
2423
</template>
2524
<script lang="ts" setup>
2625
import { twMerge } from "@witchcraft/ui/utils/twMerge"
27-
import { type PropType } from "vue"
2826
import { useAttrs } from "vue"
2927
const $attrs = useAttrs()
3028
29+
defineOptions({
30+
inheritAttrs: false,
31+
})
32+
3133
import LayoutShapeSquare from "./LayoutShapeSquare.vue"
3234
3335
import { getShapeSquareCss } from "../helpers/getShapeSquareCss"
3436
import { debugFrame } from "../layout/debugFrame.js"
35-
import { type LayoutFrame } from "../types/index.js"
37+
import { type LayoutFrameProps } from "../types/index.js"
3638
3739
3840
const emit = defineEmits<{
3941
/** Documentation #todo */
4042
(e: "focus"): void
4143
}>()
4244
43-
/* const props = */defineProps({
44-
frame: { type: Object as PropType<LayoutFrame>, required: true },
45-
isActiveFrame: { type: Boolean, required: true },
46-
})
45+
/* const props = */defineProps<LayoutFrameProps>(
46+
)
4747
</script>

src/runtime/components/LayoutShapeSquare.vue

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
left-[var(--posX)]
1616
`,
1717
css.translate && `[transform:var(--translate)]`,
18-
$attrs.class as any
18+
($attrs as any).class
1919
)"
2020
v-bind="{...$attrs, class: undefined}"
2121
>
@@ -24,15 +24,14 @@
2424
</template>
2525
<script setup lang="ts">
2626
import { twMerge } from "@witchcraft/ui/utils/twMerge"
27-
import { type PropType } from "vue"
2827
import { useAttrs } from "vue"
2928
30-
import type { BaseSquareCss } from "../types/index.js"
29+
import type { LayoutShapeSquareProps } from "../types/index.js"
3130
const $attrs = useAttrs()
3231
33-
34-
const props = defineProps({
35-
style: { type: String, required: false, default: "" },
36-
css: { type: Object as PropType<BaseSquareCss>, required: true },
32+
defineOptions({
33+
inheritAttrs: false,
3734
})
35+
36+
const props = defineProps<LayoutShapeSquareProps>()
3837
</script>

src/runtime/components/LayoutWindow.vue

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
`,
88
isDragging && `dragging cursor-pointer`,
99
requestType && `request-${requestType}`,
10-
$attrs.attrs.class
10+
($attrs as any).class
1111
)"
1212
ref="windowEl"
13-
v-bind="{...$attrs.attrs, class: undefined}"
13+
v-bind="{...$attrs, class: undefined}"
1414
>
1515
<template v-if="windowEl && win">
1616
<LayoutFrameComponent :frame="frame"
1717
:is-active-frame="frame.id === win.activeFrame"
1818
v-for="frame of frames"
1919
:key="frame.id"
20-
v-bind="$attrs.frameAttrs"
20+
v-bind="frameProps"
2121
@focus="windowSetActiveFrame(win, frame.id)"
2222
>
2323
<slot :name="`frame-${frame.id}`" v-bind="{frame}"/>
@@ -29,14 +29,13 @@
2929
:intersections="intersections"
3030
:dragging-edge="draggingEdges.length === 1 ? draggingEdges[0] : undefined"
3131
:dragging-intersection="draggingIntersection"
32-
v-bind="$attrs.edgesAttrs"
32+
v-bind="edgesProps"
3333
@drag-start="dragStart"
3434
/>
3535
<LayoutDecosComponent
3636
:frames="frames"
3737
:split-decos="splitDecos"
3838
:close-decos="closeDecos"
39-
v-bind="$attrs.decosAttrs"
4039
/>
4140
<slot name="extra-decos"/>
4241
</template>
@@ -45,7 +44,6 @@
4544
<span
4645
class="
4746
after:content-['┃']
48-
after:text-accent-500
4947
last:after:content-none
5048
after:mx-1
5149
after:text-gray-500
@@ -60,10 +58,10 @@
6058
</div>
6159
</template>
6260
<script lang="ts" setup>
63-
import { useDivideAttrs } from "@witchcraft/ui/composables/useDivideAttrs"
6461
import { useGlobalResizeObserver } from "@witchcraft/ui/composables/useGlobalResizeObserver"
6562
import { twMerge } from "@witchcraft/ui/utils/twMerge"
66-
import { computed, ref,watch } from "vue"
63+
import { computed, ref,useAttrs,watch } from "vue"
64+
import { type HTMLAttributes } from "vue"
6765
6866
import LayoutDecosComponent from "./LayoutDecos.vue"
6967
import LayoutEdgesComponent from "./LayoutEdges.vue"
@@ -76,10 +74,10 @@ import { SplitAction } from "../drag/SplitAction.js"
7674
import { type DragState, type IDragAction } from "../drag/types.js"
7775
import { updateWindowWithEvent } from "../helpers/updateWindowSizeWithEvent.js"
7876
import { windowSetActiveFrame } from "../layout/windowSetActiveFrame.js"
79-
import { type CloseDeco, type LayoutWindow, type SplitDeco } from "../types/index.js"
77+
import { type CloseDeco, type LayoutEdgesProps, type LayoutFrameProps, type LayoutWindow, type SplitDeco } from "../types/index.js"
8078
81-
const $attrs = useDivideAttrs(["frame", "edges", "decos"] as const)
8279
80+
const $attrs = useAttrs()
8381
const win = defineModel<LayoutWindow>("win", { required: true })
8482
8583
const props = withDefaults(defineProps<{
@@ -96,13 +94,15 @@ const props = withDefaults(defineProps<{
9694
* When this is turned back on again, it will trigger an update. You can also trigger updates manually with the exposed updateWindowSize function.
9795
*/
9896
allowWindowSizeUpdate?: boolean
97+
frameProps?: Partial<Omit<LayoutFrameProps, "frame" | "isActiveFrame" | "onFocus">>,
98+
edgesProps?: Partial<Omit<LayoutEdgesProps, "edges" | "intersections" | "win">>
9999
}>(), {
100100
additionalDragActions: () => ([]),
101101
splitKeyHandler: undefined,
102102
closeKeyHandler: undefined,
103103
usageInstructions: () => ({ }),
104104
instructionTeleportTo: undefined,
105-
allowWindowSizeUpdate: true
105+
allowWindowSizeUpdate: true,
106106
})
107107
const emit = defineEmits<{
108108
(e: "isShowingDrag", value: boolean): void

src/runtime/types/index.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { z } from "zod"
44

55
export * from "../drag/types.js"
66

7+
import type { HTMLAttributes, StyleValue } from "vue"
8+
79
import { getMaxInt } from "../settings.js"
810

911
export const zUuid = z.uuid()
@@ -289,3 +291,33 @@ export const zFrameCreate = zLayoutFrame.partial({
289291
width: true,
290292
height: true
291293
})
294+
295+
296+
export type LayoutShapeSquareProps
297+
= & {
298+
css: BaseSquareCss
299+
style?: StyleValue
300+
}
301+
& /** @vue-ignore */ Omit<HTMLAttributes, "class" | "onFocus"> & { class?: string }
302+
303+
304+
export type LayoutEdgesProps
305+
= & {
306+
edges: Edge[]
307+
intersections: IntersectionEntry[]
308+
/** The owning window, needed so we can correctly scale coordinates. */
309+
win: LayoutWindow
310+
/** The active frame, used to render the active edges. Calculate it from the `frames` returned by `useFrames` composable because otherwise it will be the wrong size while dragging. */
311+
activeFrame?: LayoutFrame
312+
draggingEdge?: Edge
313+
draggingIntersection?: IntersectionEntry
314+
}
315+
& Partial<LayoutShapeSquareProps>
316+
317+
318+
export type LayoutFrameProps
319+
= & {
320+
frame: LayoutFrame
321+
isActiveFrame: boolean
322+
}
323+
& Partial<LayoutShapeSquareProps>

0 commit comments

Comments
 (0)