Skip to content

Commit

Permalink
wip: BTree & refactor structure
Browse files Browse the repository at this point in the history
  • Loading branch information
YunYouJun committed Dec 18, 2023
1 parent 3aa5849 commit bdcc7a5
Show file tree
Hide file tree
Showing 12 changed files with 221 additions and 32 deletions.
3 changes: 2 additions & 1 deletion examples/threejs/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import './style.css'
import { reactive } from 'vue'
import { createBUI } from 'blender-ui'
import { createBUI } from '@advjs/blender-ui'

Check failure on line 3 in examples/threejs/src/main.ts

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find module '@advjs/blender-ui' or its corresponding type declarations.
import '@advjs/blender-ui/dist/style.css'

import { createDemoScene } from './scene'

Expand Down
10 changes: 7 additions & 3 deletions examples/threejs/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import path from 'node:path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
// plugins: [vue()],

resolve: {
alias: {
'blender-ui': path.resolve(__dirname, '../../packages/blender-ui/index.ts'),
// '@advjs/blender-ui/': `${path.resolve(__dirname, '../../packages/blender-ui')}/`,
// '@advjs/blender-ui': path.resolve(__dirname, '../../packages/blender-ui/index.ts'),
'@advjs/blender-ui/': `${path.resolve(__dirname, '../../packages/blender-ui')}/`,
'@advjs/blender-ui': path.resolve(__dirname, '../../packages/blender-ui/dist/blender-ui.js'),
},
},
})
2 changes: 1 addition & 1 deletion examples/tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"paths": {
"blender-ui": ["../packages/blender-ui/index.ts"]
"@advjs/blender-ui": ["../packages/blender-ui/index.ts"]
}
}
}
1 change: 1 addition & 0 deletions examples/vue/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"target": "ES2020",
"jsx": "preserve",
Expand Down
8 changes: 2 additions & 6 deletions histoire.setup.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { defineSetupVue3 } from '@histoire/plugin-vue'
import { useStyleTag } from '@vueuse/core'
import './packages/blender-ui/styles/index.scss'
import './packages/blender-ui/client/styles/index.scss'
import './packages/blender-ui/dist/icons.css'
import './histoire/styles/index.css'

import { bCssVarsRootStyle } from './packages/blender-ui/styles/icons'

export const setupVue3 = defineSetupVue3((_handler) => {
// addWrapper(GlobalWrapper)
const style = bCssVarsRootStyle()
useStyleTag(style)
})
2 changes: 1 addition & 1 deletion packages/blender-ui/client/components/BPanel/BPanel.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { defineEmits, ref } from 'vue'
import { ref } from 'vue'
import BCheckbox from '../BCheckbox/BCheckbox.vue'
// You need to create this composable for the slide transition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ const el = ref<HTMLElement | null>(null)
.b-select {
position: relative;
outline: none;
.value {
font:
12px system-ui,
Expand Down Expand Up @@ -200,6 +202,8 @@ const el = ref<HTMLElement | null>(null)
border: 1px solid #242424;
border-radius: 4px;
outline: none !important;
.up & {
border-top-left-radius: 0;
border-top-right-radius: 0;
Expand Down
152 changes: 152 additions & 0 deletions packages/blender-ui/client/components/BTree/OutlineRow.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<script setup>
import { onBeforeUnmount, onMounted, ref, watch } from 'vue'

Check failure on line 2 in packages/blender-ui/client/components/BTree/OutlineRow.vue

View workflow job for this annotation

GitHub Actions / lint

'onBeforeUnmount' is defined but never used
import Toggle from './IconButton.vue'
const props = defineProps({
indent: Number,
title: String,
expanded: { type: Boolean, default: undefined },
active: Boolean,
selectable: Boolean,
parentUnselectable: { type: Boolean, default: undefined },
visible: { type: Boolean, default: undefined },
match: { type: Boolean, default: undefined },
muted: Boolean,
})
const emit = defineEmits(['activate', 'collapse', 'expand', 'log', 'unselectable', 'selectable', 'hide', 'show'])
const el = ref(null)
watch(() => props.active, (newActive) => {
if (newActive && el.value) {
// Focus or scroll into view logic goes here
}
})
onMounted(() => {
// Assign outlineRow or any other initialization logic
})
function activate() {
emit('activate')
}
function collapse() {
emit('collapse')
}
function expand() {
emit('expand')
}
function log() {
emit('log')
}
function unselectable() {
emit('unselectable')
}
function selectable() {
emit('selectable')
}
function hide() {
emit('hide')
}
function show() {
emit('show')
}
function onKeyDown(event) {

Check failure on line 61 in packages/blender-ui/client/components/BTree/OutlineRow.vue

View workflow job for this annotation

GitHub Actions / lint

'event' is defined but never used. Allowed unused args must match /^_/u
// The keyboard navigation logic goes here
// You'll need to handle focus and sibling element traversal in Vue 3 terms
}
</script>

<template>
<div
ref="el" class="outliner-row"
:class="[{ active, muted, match }]"
:style="{ '--indent': `${indent}px` }"
tabindex="0"
@click="activate"
@dblclick="log"
@keydown="onKeyDown"
>
<template v-if="typeof expanded === 'boolean'">
<Toggle
:icon="expanded ? 'expanded' : 'collapsed'"
@click="expanded ? collapse() : expand()"
/>
</template>
<template v-else>
<span class="toggle-spacer" />
</template>
<span class="title">{{ title }}</span>
<template v-if="selectable">
<Toggle
icon="selectable"
hint="Disable right-click selection"
:muted="parentUnselectable"
@click="unselectable"
/>
</template>
<template v-else>
<Toggle
icon="unselectable"
hint="Enable right-click selection"
:muted="parentUnselectable"
@click="selectable"
/>
</template>
<template v-if="typeof visible === 'boolean'">
<Toggle
:icon="visible ? 'eye-opened' : 'eye-closed'"
:hint="visible ? 'Hide (h)' : 'Show (h)'"
@click="visible ? hide() : show()"
/>
</template>
</div>
</template>

<style lang="scss">
.outliner-row {
display: flex;
align-items: center;
background: #282828;
color: #c2c2c2;
height: 20px;
padding-left: calc(var(--indent) * 20px);
outline: none;
padding-right: 4px;
&:nth-child(even) {
background-color: #2b2b2b;
}
&:focus {
background-color: #334d80;
}
&.match {
background-color: #2f552f;
&:focus {
background-color: #336659;
}
}
&.active {
color: #ffaf29;
}
}
.toggle-spacer {
width: 20px;
}
.title {
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
user-select: none;
position: default;
.muted & {
opacity: 0.5;
}
}
</style>
2 changes: 1 addition & 1 deletion packages/blender-ui/client/styles/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const svg = {
'text-justify': `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M1.4922 1.99999C1.42594 1.99905 1.36016 2.01129 1.29868 2.036C1.23719 2.06071 1.18123 2.09739 1.13404 2.14391C1.08686 2.19043 1.04939 2.24587 1.02382 2.307C0.998245 2.36812 0.985077 2.43373 0.985077 2.49999C0.985077 2.56625 0.998245 2.63185 1.02382 2.69298C1.04939 2.75411 1.08686 2.80955 1.13404 2.85607C1.18123 2.90259 1.23719 2.93927 1.29868 2.96398C1.36016 2.98869 1.42594 3.00093 1.4922 2.99999H14.4863C14.5526 3.00093 14.6184 2.98869 14.6799 2.96398C14.7413 2.93927 14.7973 2.90259 14.8445 2.85607C14.8917 2.80955 14.9291 2.75411 14.9547 2.69298C14.9803 2.63185 14.9935 2.56625 14.9935 2.49999C14.9935 2.43373 14.9803 2.36812 14.9547 2.307C14.9291 2.24587 14.8917 2.19043 14.8445 2.14391C14.7973 2.09739 14.7413 2.06071 14.6799 2.036C14.6184 2.01129 14.5526 1.99905 14.4863 1.99999H1.4922ZM1.4922 4.99999C1.42594 4.99905 1.36016 5.01129 1.29868 5.036C1.23719 5.06071 1.18123 5.09739 1.13404 5.14391C1.08686 5.19043 1.04939 5.24587 1.02382 5.307C0.998245 5.36812 0.985077 5.43373 0.985077 5.49999C0.985077 5.56625 0.998245 5.63185 1.02382 5.69298C1.04939 5.75411 1.08686 5.80955 1.13404 5.85607C1.18123 5.90259 1.23719 5.93927 1.29868 5.96398C1.36016 5.98869 1.42594 6.00093 1.4922 5.99999H14.4863C14.5526 6.00093 14.6184 5.98869 14.6799 5.96398C14.7413 5.93927 14.7973 5.90259 14.8445 5.85607C14.8917 5.80955 14.9291 5.75411 14.9547 5.69298C14.9803 5.63185 14.9935 5.56625 14.9935 5.49999C14.9935 5.43373 14.9803 5.36812 14.9547 5.307C14.9291 5.24587 14.8917 5.19043 14.8445 5.14391C14.7973 5.09739 14.7413 5.06071 14.6799 5.036C14.6184 5.01129 14.5526 4.99905 14.4863 4.99999H1.4922ZM1.4922 7.99999C1.42594 7.99905 1.36016 8.01129 1.29868 8.036C1.23719 8.06071 1.18123 8.09739 1.13404 8.14391C1.08686 8.19043 1.04939 8.24587 1.02382 8.307C0.998245 8.36812 0.985077 8.43373 0.985077 8.49999C0.985077 8.56625 0.998245 8.63185 1.02382 8.69298C1.04939 8.75411 1.08686 8.80955 1.13404 8.85607C1.18123 8.90259 1.23719 8.93927 1.29868 8.96398C1.36016 8.98869 1.42594 9.00093 1.4922 8.99999H14.4863C14.5526 9.00093 14.6184 8.98869 14.6799 8.96398C14.7413 8.93927 14.7973 8.90259 14.8445 8.85607C14.8917 8.80955 14.9291 8.75411 14.9547 8.69298C14.9803 8.63185 14.9935 8.56625 14.9935 8.49999C14.9935 8.43373 14.9803 8.36812 14.9547 8.307C14.9291 8.24587 14.8917 8.19043 14.8445 8.14391C14.7973 8.09739 14.7413 8.06071 14.6799 8.036C14.6184 8.01129 14.5526 7.99905 14.4863 7.99999H1.4922ZM1.4922 11C1.42594 10.9991 1.36016 11.0113 1.29868 11.036C1.23719 11.0607 1.18123 11.0974 1.13404 11.1439C1.08686 11.1904 1.04939 11.2459 1.02382 11.307C0.998245 11.3681 0.985077 11.4337 0.985077 11.5C0.985077 11.5663 0.998245 11.6319 1.02382 11.693C1.04939 11.7541 1.08686 11.8095 1.13404 11.8561C1.18123 11.9026 1.23719 11.9393 1.29868 11.964C1.36016 11.9887 1.42594 12.0009 1.4922 12H14.4863C14.5526 12.0009 14.6184 11.9887 14.6799 11.964C14.7413 11.9393 14.7973 11.9026 14.8445 11.8561C14.8917 11.8095 14.9291 11.7541 14.9547 11.693C14.9803 11.6319 14.9935 11.5663 14.9935 11.5C14.9935 11.4337 14.9803 11.3681 14.9547 11.307C14.9291 11.2459 14.8917 11.1904 14.8445 11.1439C14.7973 11.0974 14.7413 11.0607 14.6799 11.036C14.6184 11.0113 14.5526 10.9991 14.4863 11H1.4922ZM1.4922 14C1.42594 13.9991 1.36016 14.0113 1.29868 14.036C1.23719 14.0607 1.18123 14.0974 1.13404 14.1439C1.08686 14.1904 1.04939 14.2459 1.02382 14.307C0.998245 14.3681 0.985077 14.4337 0.985077 14.5C0.985077 14.5663 0.998245 14.6319 1.02382 14.693C1.04939 14.7541 1.08686 14.8095 1.13404 14.8561C1.18123 14.9026 1.23719 14.9393 1.29868 14.964C1.36016 14.9887 1.42594 15.0009 1.4922 15H14.4863C14.5526 15.0009 14.6184 14.9887 14.6799 14.964C14.7413 14.9393 14.7973 14.9026 14.8445 14.8561C14.8917 14.8095 14.9291 14.7541 14.9547 14.693C14.9803 14.6319 14.9935 14.5663 14.9935 14.5C14.9935 14.4337 14.9803 14.3681 14.9547 14.307C14.9291 14.2459 14.8917 14.1904 14.8445 14.1439C14.7973 14.0974 14.7413 14.0607 14.6799 14.036C14.6184 14.0113 14.5526 13.9991 14.4863 14H1.4922Z" fill="white"/>
</svg>`,
}
} as const

let cache: string
export function bCssVars(): string {
Expand Down
8 changes: 5 additions & 3 deletions packages/blender-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@
},
"exports": {
"./nuxt": "./nuxt.mjs",
"./*": "./*",
".": {
"import": "./dist/blender-ui.js",
"require": "./dist/blender-ui.umd.cjs"
},
"./*": "./*"
}
},
"main": "./dist/blender-ui.umd.cjs",
"module": "./dist/blender-ui.js",
"scripts": {
"dev": "vite",
"build": "vue-tsc --noEmit && vite build",
"build": "vue-tsc --noEmit && vite build && pnpm run build:icons",
"build:icons": "tsx scripts/build.ts",
"release": "bumpp && npm publish"
},
"devDependencies": {
"@vitejs/plugin-vue": "^4.5.2",
"tsx": "^4.6.2",
"vite": "^5.0.10"
}
}
23 changes: 23 additions & 0 deletions packages/blender-ui/scripts/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import fs from 'node:fs'
import path from 'node:path'
import { Buffer } from 'node:buffer'

Check failure on line 3 in packages/blender-ui/scripts/build.ts

View workflow job for this annotation

GitHub Actions / lint

'Buffer' is defined but never used
import { svg } from '../client/styles/icons'

const __dirname = path.dirname(new URL(import.meta.url).pathname)
const distFolder = path.resolve(__dirname, '../dist')

function bCssVarsRootStyle() {
const cssVars = Object.keys(svg)
.map(key =>
`--b-icon-${key}: url("data:image/svg+xml;utf8,${encodeURIComponent(svg[key as keyof typeof svg])}")`,
)
.join(';\n')

return `:root { ${cssVars} }`
}

fs.writeFileSync(
path.resolve(distFolder, 'icons.css')
, bCssVarsRootStyle(),
'utf-8',
)
38 changes: 22 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bdcc7a5

Please sign in to comment.