fix(primitives): eslint/tsconfig migration, asChild refactor, type fixes
- Migrate to eslint flat config + composite tsconfig. - Complete the asChild→as="template" refactor (remove asChild prop + :as-child bindings across components, matching Primitive's slot model). - Fix test type errors and source type-safety (useGraceArea hull/point math, FocusScope/util ref typing). Note: ~53 vue-tsc errors remain (HTML attr/event passthrough typing on transparent wrapper components + a couple of duplicate-export naming collisions) — not gated by CI (build/lint/test green); pending a component-attribute-typing design decision.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<script lang="ts">
|
||||
import type { PrimitiveProps } from '../primitive';
|
||||
|
||||
export interface EditablePreviewProps extends PrimitiveProps {}
|
||||
</script>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { Primitive } from '../primitive';
|
||||
import { computed } from 'vue';
|
||||
import { useEditableContext } from './context';
|
||||
import { useForwardExpose } from '@robonen/vue';
|
||||
|
||||
const { as = 'span' } = defineProps<EditablePreviewProps>();
|
||||
|
||||
const ctx = useEditableContext();
|
||||
const { forwardRef } = useForwardExpose();
|
||||
|
||||
const text = computed(() => ctx.modelValue.value || ctx.placeholder.value.preview);
|
||||
const showPlaceholder = computed(() => ctx.isEmpty.value);
|
||||
|
||||
function onFocus(): void {
|
||||
if (ctx.activationMode.value === 'focus') ctx.edit();
|
||||
}
|
||||
|
||||
function onDoubleClick(): void {
|
||||
if (ctx.activationMode.value === 'dblclick') ctx.edit();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Primitive
|
||||
:ref="forwardRef"
|
||||
:as="as"
|
||||
tabindex="0"
|
||||
:hidden="ctx.autoResize.value ? undefined : ctx.isEditing.value"
|
||||
:data-placeholder-shown="showPlaceholder ? '' : undefined"
|
||||
:data-state="ctx.isEditing.value ? 'edit' : 'preview'"
|
||||
:data-disabled="ctx.disabled.value ? '' : undefined"
|
||||
:data-readonly="ctx.readonly.value ? '' : undefined"
|
||||
:style="ctx.autoResize.value ? {
|
||||
whiteSpace: 'pre',
|
||||
userSelect: 'none',
|
||||
gridArea: '1 / 1 / auto / auto',
|
||||
visibility: ctx.isEditing.value ? 'hidden' : undefined,
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
} : undefined"
|
||||
@focusin="onFocus"
|
||||
@dblclick="onDoubleClick"
|
||||
>
|
||||
<slot>{{ text }}</slot>
|
||||
</Primitive>
|
||||
</template>
|
||||
Reference in New Issue
Block a user