Skip to content

Commit

Permalink
Merge branch 'release/v0.21.19'
Browse files Browse the repository at this point in the history
  • Loading branch information
holtwick committed Jul 13, 2024
2 parents 4061d8f + 4bf45f6 commit 1a9b3d3
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 22 deletions.
8 changes: 6 additions & 2 deletions lib/basic/oui-checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { computed } from 'vue'
import './oui-form.styl'
defineOptions({
inheritAttrs: false,
})
const props = withDefaults(defineProps<{
title?: string
switch?: boolean
Expand Down Expand Up @@ -36,12 +40,12 @@ const klass = computed(() => {
<template>
<template v-if="title || $slots.default">
<label>
<input v-model="modelBool" type="checkbox" :class="klass">
<input v-model="modelBool" type="checkbox" :class="klass" v-bind="$attrs">
{{ ' ' }}
<slot>{{ title }}</slot>
</label>
</template>
<template v-else>
<input v-model="modelBool" type="checkbox" :class="klass">
<input v-model="modelBool" type="checkbox" :class="klass" v-bind="$attrs">
</template>
</template>
20 changes: 18 additions & 2 deletions lib/basic/oui-log.demo.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<script lang="ts" setup>
import { useIntervalFn } from '@vueuse/core'
import { uuid } from 'zeed'
import { OuiLog, OuiText, useLog } from '@/lib'
import { reactive } from 'vue'
import { OuiCheckbox, OuiDemo, OuiLog, OuiText, useLog } from '@/lib'
const log = useLog('test')
const state = reactive({
showTime: true,
showTag: true,
})
log('Hello World')
log.info('Info')
log.warn('Warning')
Expand All @@ -21,7 +27,17 @@ useIntervalFn(() => {
<OuiText>
<h2>Virtual List</h2>
<div>
<OuiLog :log="log" style="height: 200px;" />
<OuiLog
:key="`${state.showTag}-${state.showTime}`"
:log="log"
style="height: 200px;"
:show-tag="state.showTag"
:show-time="state.showTime"
/>
</div>
</OuiText>
<OuiDemo :state="state">
<OuiCheckbox v-model="state.showTime" switch title="showTime" />
<OuiCheckbox v-model="state.showTag" switch title="showTag" />
</OuiDemo>
</template>
24 changes: 24 additions & 0 deletions lib/basic/oui-log.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# oui-log

Use `zeed` logging infrastructure to show certain logs in the frontend. Great for development and debugging.

- `log`: `useLog` object
- `show-time`: show time column
- `show-tag`: show tag column

## Basic usage

In the Vue component setup use logging like this

```ts
const log = useLog('test')
log('This is the first entry')
```

Then register this log object with OuiLog

```vue
<OuiLog :log="log" />
```

OuiTableview is used for display, so notes there apply here as well.
31 changes: 20 additions & 11 deletions lib/basic/oui-log.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
<script lang="ts" setup>
import { ref, watch } from 'vue'
import { computed, ref, watch } from 'vue'
import type { LogMessage } from 'zeed'
import { Uint8ArrayToHexDump, browserSelectColorByName, formatMilliseconds, isArray, isString, logMessageFromCompact } from 'zeed'
import { Uint8ArrayToHexDump, browserSelectColorByName, formatMilliseconds, isArray, isNotEmpty, isNotNull, isString, logMessageFromCompact } from 'zeed'
import type { OuiTableColumn } from './_types'
import type { LogOui } from './log'
import OuiTableview from './oui-tableview.vue'
import './oui-log.styl'
const props = defineProps<{
const props = withDefaults(defineProps<{
log: LogOui
}>()
showTime?: boolean
showTag?: boolean
}>(), {
showTime: true,
showTag: true,
})
const selected = ref<number>()
Expand Down Expand Up @@ -43,7 +48,7 @@ function renderMessages(
messages: any[],
opt: RenderMessagesOptions = {},
): any[] {
return formatMessages(messages, opt)
return formatMessages(messages, opt) ?? '?'
}
function handlerLogInfo(msg: LogMessage) {
Expand All @@ -68,7 +73,7 @@ function handlerLogInfo(msg: LogMessage) {
const logs = ref<any>([])
function updateLogs() {
const ll: LogMessage[] = [...props.log.messages] ?? []
const ll: LogMessage[] = [...props.log.messages]
const first = ll[0]
const compact = isArray(first)
let timestamp = (compact ? first[0] : first?.timestamp) ?? 0
Expand Down Expand Up @@ -97,11 +102,15 @@ watch(() => props.log.messages.length, updateLogs)
updateLogs()
const columns: OuiTableColumn[] = [
{ title: 'Time', name: 'time', sortable: false, width: 96, align: 'right' },
// { title: 'Tag', name: 'tag', sortable: false },
{ title: 'Message', name: 'message', sortable: false },
]
const columns = computed(() => {
const cols: OuiTableColumn[] = []
if (props.showTime)
cols.push({ title: 'Time', name: 'time', sortable: false, width: 96, align: 'right' })
if (props.showTag)
cols.push({ title: 'Tag', name: 'tag', sortable: false })
cols.push({ title: 'Message', name: 'message', sortable: false })
return cols
})
// const selectedItem = computed(() => list.value[selected.value ?? -1])
</script>
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "oui-kit",
"type": "module",
"version": "0.21.18",
"version": "0.21.19",
"author": {
"email": "dirk.holtwick@gmail.com",
"name": "Dirk Holtwick",
Expand Down Expand Up @@ -76,23 +76,23 @@
"@floating-ui/vue": "^1.1.1",
"@vueuse/core": "^10.11.0",
"vue": "^3.4.31",
"zeed": "^0.21.0"
"zeed": "^0.22.8"
},
"devDependencies": {
"@antfu/eslint-config": "^2.21.2",
"@antfu/ni": "^0.21.12",
"@shikijs/markdown-it": "^1.10.1",
"@antfu/ni": "^0.22.0",
"@shikijs/markdown-it": "^1.10.3",
"@types/jest": "^29.5.12",
"@types/node": "^20.14.9",
"@types/node": "^20.14.10",
"@vitejs/plugin-vue": "^5.0.5",
"eslint": "<9",
"stylus": "^0.63.0",
"tsup": "^8.1.0",
"typescript": "<5.5",
"unplugin-vue-markdown": "^0.26.2",
"vite": "^5.3.2",
"vite": "^5.3.3",
"vite-plugin-dts": "^3.9.1",
"vite-plugin-qrcode": "^0.2.3",
"vitest": "^1.6.0"
"vitest": "^2.0.2"
}
}

0 comments on commit 1a9b3d3

Please sign in to comment.