Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(inspector): Allow including/excluding safelist in REPL #1532

Merged
merged 2 commits into from Sep 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/inspector/client/components/ReplPlayground.vue
Expand Up @@ -10,7 +10,8 @@ const input = useLocalStorage(
'<div class="text-sm hover:text-red">\nHello World\n</div>',
)

const { data: result } = fetchRepl(input)
const isSafelistIncluded = ref(false)
jd-solanki marked this conversation as resolved.
Show resolved Hide resolved
const { data: result } = fetchRepl(input, isSafelistIncluded)
</script>

<template>
Expand All @@ -23,6 +24,12 @@ const { data: result } = fetchRepl(input)
Edit your code below to test and play UnoCSS's matching and generating.
</div>
</StatusBar>
<TitleBar border="b gray-400/20" title="">
<label>
<input v-model="isSafelistIncluded" type="checkbox">
Include safelist
</label>
</TitleBar>
<div h-full of-hidden grid grid-cols-2>
<CodeMirror
v-model="input"
Expand Down
4 changes: 2 additions & 2 deletions packages/inspector/client/composables/fetch.ts
Expand Up @@ -32,9 +32,9 @@ export function fetchModule(id: string | Ref<string>) {
return result
}

export function fetchRepl(input: Ref<string>) {
export function fetchRepl(input: Ref<string>, includeSafelist: Ref<boolean>) {
const debounced = useDebounce(input, 500)
return useFetch(computed(() => `${API_ROOT}/repl?token=${encodeURIComponent(debounced.value)}`), { refetch: true })
return useFetch(computed(() => `${API_ROOT}/repl?token=${encodeURIComponent(debounced.value)}&include-safelist=${includeSafelist.value}`), { refetch: true })
jd-solanki marked this conversation as resolved.
Show resolved Hide resolved
.json<Result>()
}

Expand Down
3 changes: 2 additions & 1 deletion packages/inspector/node/index.ts
Expand Up @@ -65,8 +65,9 @@ export default function UnocssInspector(ctx: UnocssPluginContext): Plugin {
if (req.url.startsWith('/repl')) {
const query = new URLSearchParams(req.url.slice(5))
const token = query.get('token') || ''
const includeSafelist = JSON.parse(query.get('include-safelist') ?? 'false')
jd-solanki marked this conversation as resolved.
Show resolved Hide resolved

const result = await ctx.uno.generate(token, { preflights: false })
const result = await ctx.uno.generate(token, { preflights: false, safelist: includeSafelist })
const mod = {
...result,
matched: Array.from(result.matched),
Expand Down