Skip to content

Commit

Permalink
chore: merge branch 'dev' into v3
Browse files Browse the repository at this point in the history
  • Loading branch information
haoziqaq committed Feb 3, 2024
2 parents f835b3d + 2d1973e commit c23f0ae
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 43 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## [2.22.2](https://github.com/varletjs/varlet/compare/v2.22.1...v2.22.2) (2024-02-03)


### Bug Fixes

* fix defineProps limited to a type literal or a reference to a local interface and close [#1458](https://github.com/varletjs/varlet/issues/1458) ([64ba155](https://github.com/varletjs/varlet/commit/64ba155a5b3e2a9e828ed60dbb38b8d30b067070))
* **index-bar:** init scroller when start to scroll for nuxt ([#1460](https://github.com/varletjs/varlet/issues/1460)) ([9b9ad8c](https://github.com/varletjs/varlet/commit/9b9ad8c35c15cc9fce14536d9f80ff14fe8592b7))
* **index-bar:** recollect anchor name that is empty from anchors when length changes ([#1459](https://github.com/varletjs/varlet/issues/1459)) ([e61d046](https://github.com/varletjs/varlet/commit/e61d046b55e4e4e84822aec352d88737c1fac544))
* **sticky:** init scroller when start scrolling to avoid the value of scroller becomes window for nuxt ([#1456](https://github.com/varletjs/varlet/issues/1456)) ([43637b9](https://github.com/varletjs/varlet/commit/43637b9d440ec7bdf601e3f0b1e89eef36ed86d5))



## [2.22.1](https://github.com/varletjs/varlet/compare/v2.22.0...v2.22.1) (2024-01-29)


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"private": true,
"version": "2.22.1",
"version": "2.22.2",
"scripts": {
"preinstall": "npx only-allow pnpm",
"postinstall": "simple-git-hooks",
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@varlet/cli",
"version": "2.22.1",
"version": "2.22.2",
"type": "module",
"description": "cli of varlet",
"bin": {
Expand Down
31 changes: 28 additions & 3 deletions packages/varlet-cli/src/node/compiler/compileSFC.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import fse from 'fs-extra'
import hash from 'hash-sum'
import { parse, resolve } from 'path'
import { parse as parseSFC, compileTemplate, compileStyle, compileScript as compileScriptSFC } from '@vue/compiler-sfc'
import {
parse as parseSFC,
compileTemplate,
compileStyle,
compileScript as compileScriptSFC,
registerTS,
} from '@vue/compiler-sfc'
import { replaceExt, smartAppendFileSync } from '../shared/fsUtils.js'
import { CWD, SRC_DIR, ES_DIR } from '../shared/constant.js'
import { compileScript, getScriptExtname } from './compileScript.js'
import ts from 'typescript'
import {
clearEmptyLine,
compileLess,
Expand All @@ -13,7 +21,9 @@ import {
} from './compileStyle.js'
import type { SFCStyleBlock } from '@vue/compiler-sfc'

const { readFile, writeFileSync } = fse
const { readFile, existsSync, readFileSync, writeFileSync } = fse

registerTS(() => ts)

const EXPORT = 'export default'
const SFC = '__sfc__'
Expand Down Expand Up @@ -49,6 +59,14 @@ export function injectRender(script: string, render: string): string {
return script
}

export function getFsPath(sfc: string, fsFile: string) {
if (fsFile === 'tsconfig.json' || fsFile.startsWith('node_modules')) {
return resolve(CWD, fsFile)
}

return resolve(sfc.replace(ES_DIR, SRC_DIR), '..', fsFile)
}

export async function compileSFC(sfc: string) {
const sources: string = await readFile(sfc, 'utf-8')
const id = hash(sources)
Expand All @@ -60,7 +78,14 @@ export async function compileSFC(sfc: string) {

if (script || scriptSetup) {
if (scriptSetup) {
const { content, bindings } = compileScriptSFC(descriptor, { id })
const { content, bindings } = compileScriptSFC(descriptor, {
id,
// issue https://github.com/varletjs/varlet/issues/1458
fs: {
fileExists: (file) => existsSync(getFsPath(sfc, file)),
readFile: (file) => readFileSync(getFsPath(sfc, file), 'utf-8'),
},
})
scriptContent = content
bindingMetadata = bindings
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@varlet/eslint-config",
"version": "2.22.1",
"version": "2.22.2",
"description": "eslint config of varlet",
"keywords": [
"eslint",
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-icons/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@varlet/icons",
"version": "2.22.1",
"version": "2.22.2",
"description": "Icons of varlet",
"type": "module",
"main": "dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@varlet/shared",
"version": "2.22.1",
"version": "2.22.2",
"type": "module",
"main": "lib/index.cjs",
"module": "lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-touch-emulator/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@varlet/touch-emulator",
"version": "2.22.1",
"version": "2.22.2",
"description": "touch-emulator",
"keywords": [
"emulator",
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-ui-playground/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@varlet/ui-playground",
"private": true,
"version": "2.22.1",
"version": "2.22.2",
"description": "varlet ui playground",
"type": "module",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@varlet/ui",
"version": "2.22.1",
"version": "2.22.2",
"description": "A material like components library",
"main": "lib/varlet.cjs.js",
"module": "es/index.mjs",
Expand Down
25 changes: 11 additions & 14 deletions packages/varlet-ui/src/index-bar/IndexBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,13 @@ export default defineComponent({
() => length.value,
async () => {
await doubleRaf()
indexAnchors.forEach(({ name }) => {
if (name.value) anchorNameList.value.push(name.value)
})
anchorNameList.value = indexAnchors
.filter(({ name }) => name.value != null)
.map(({ name }) => name.value) as Array<string | number>
}
)
onSmartMounted(async () => {
await setScroller()
addScrollerListener()
})
onSmartMounted(setupScroller)
onBeforeUnmount(removeScrollerListener)
Expand Down Expand Up @@ -170,17 +167,17 @@ export default defineComponent({
clickedName.value = ''
}
async function setScroller() {
await doubleRaf()
function setupScroller() {
scroller = getParentScroller(barEl.value as HTMLElement)
}
function addScrollerListener() {
scroller!.addEventListener('scroll', handleScroll)
scroller.addEventListener('scroll', handleScroll)
}
function removeScrollerListener() {
scroller!.removeEventListener('scroll', handleScroll)
if (!scroller) {
return
}
scroller.removeEventListener('scroll', handleScroll)
}
// expose
Expand Down
35 changes: 20 additions & 15 deletions packages/varlet-ui/src/sticky/Sticky.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ export default defineComponent({
watch(() => props.disabled, resize)
onSmartMounted(addScrollListener)
onSmartMounted(async () => {
await doubleRaf()
setupScroller()
handleScroll()
})
onSmartUnmounted(removeScrollListener)
Expand Down Expand Up @@ -114,11 +118,15 @@ export default defineComponent({
}
}
function handleScroll() {
if (!scroller) {
return
function setupScroller() {
scroller = getParentScroller(stickyEl.value as HTMLElement)
if (scroller !== window) {
scroller.addEventListener('scroll', handleScroll)
}
}
function handleScroll() {
// returns undefined when disabled = true
const fixedParams = computeFixedParams()
Expand All @@ -127,24 +135,21 @@ export default defineComponent({
}
}
function removeScrollListener() {
if (!scroller || scroller === window) {
return
}
scroller.removeEventListener('scroll', handleScroll)
}
// expose
async function resize() {
isFixed.value = false
await raf()
computeFixedParams()
}
async function addScrollListener() {
await doubleRaf()
scroller = getParentScroller(stickyEl.value as HTMLElement)
scroller !== window && scroller.addEventListener('scroll', handleScroll)
handleScroll()
}
function removeScrollListener() {
scroller !== window && scroller.removeEventListener('scroll', handleScroll)
}
return {
stickyEl,
wrapperEl,
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-use/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@varlet/use",
"version": "2.22.1",
"version": "2.22.2",
"type": "module",
"main": "lib/index.cjs",
"module": "lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-vite-plugins/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@varlet/vite-plugins",
"version": "2.22.1",
"version": "2.22.2",
"type": "module",
"description": "vite plugins of varlet",
"main": "lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"displayName": "varlet-vscode-extension",
"description": "varlet extension for vscode",
"publisher": "haoziqaq",
"version": "2.22.1",
"version": "2.22.2",
"engines": {
"vscode": "^1.56.0"
},
Expand Down

0 comments on commit c23f0ae

Please sign in to comment.