feat: wire global runtime injection and playground

This commit is contained in:
stanig2106
2025-11-14 06:15:33 +01:00
parent 534bc39197
commit f12bc0ce85
18 changed files with 516 additions and 54 deletions

View File

@@ -1,6 +1,82 @@
<template>
<div>basic</div>
<main>
<h1>basic</h1>
<section>
<button
id="can-view"
v-can="canProxy.employee.view"
>
Voir
</button>
<button
v-if="isReady"
id="can-edit"
v-can="canProxy.employee.edit"
>
Editer
</button>
<p
id="cannot-edit"
v-cannot
>
Refus
</p>
</section>
<section>
<template v-if="showContracts">
<p v-can="canProxy.contract.create">
Creation contrat
</p>
<p v-cannot>
Pas de creation
</p>
</template>
<p v-else>
Section contrats masquee, aucune directive appliquee.
</p>
</section>
<section>
<h2>Suppression</h2>
<button
id="can-delete"
v-can="canProxy.employee.delete"
>
Supprimer
</button>
<p
id="cannot-delete"
v-cannot
>
Suppression interdite
</p>
</section>
<section>
<p id="path-display">
{{ String(canProxy.employee.view) }}
</p>
</section>
</main>
</template>
<script setup>
<script setup lang="ts">
const isReady = true
const showContracts = true
interface FixturePermissions {
employee: {
view: boolean
edit: boolean
delete: boolean
}
contract: {
create: boolean
}
}
const nuxtApp = useNuxtApp()
const canProxy = nuxtApp.$can as unknown as FixturePermissions
</script>

View File

@@ -1,7 +1,14 @@
import MyModule from '../../../src/module'
import NuxtCan from '../../../src/module'
export default defineNuxtConfig({
modules: [
MyModule,
NuxtCan,
],
nuxtCan: {
permissions: {
employee: ['view', 'edit', 'delete'],
contract: ['create'],
},
canFunctionImport: '~/permissions/__can__',
},
})

View File

@@ -0,0 +1,10 @@
const granted = new Set([
'employee.view',
'employee.edit',
'contract.create',
])
export function __can__(path: string[]) {
const key = Array.isArray(path) ? path.join('.') : String(path)
return granted.has(key)
}