Skip to content

Commit

Permalink
chore: remove the word "flow" in names
Browse files Browse the repository at this point in the history
  • Loading branch information
KermanX committed Feb 12, 2024
1 parent f6a66f9 commit 9b405ee
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 427 deletions.
401 changes: 14 additions & 387 deletions demo/starter/slides.md

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions packages/client/builtin/CodeBlockWrapper.vue
Expand Up @@ -56,18 +56,18 @@ onMounted(() => {
const at = props.at
const atNum = safeParseNumber(at)
const inFlow = typeof at === 'string' && '+-'.includes(at[0])
const flowSize = inFlow
const isRelative = typeof at === 'string' && '+-'.includes(at[0])
const relativeDelta = isRelative
? atNum + props.ranges.length - 2
: 0
const start = inFlow
? clicks.flowSum + atNum - 1
const start = isRelative
? clicks.currentOffset + atNum - 1
: atNum
const end = start + props.ranges.length - 1
// register to the page click map
const id = makeId()
clicks.register(id, { max: end, flowSize })
clicks.register(id, { max: end, relativeDelta })
onUnmounted(() => clicks.unregister(id))
const index = computed(() => {
Expand Down
10 changes: 5 additions & 5 deletions packages/client/builtin/KaTexBlockWrapper.vue
Expand Up @@ -55,18 +55,18 @@ onMounted(() => {
const at = props.at
const atNum = safeParseNumber(at)
const inFlow = typeof at === 'string' && '+-'.includes(at[0])
const flowSize = inFlow
const isRelative = typeof at === 'string' && '+-'.includes(at[0])
const relativeDelta = isRelative
? atNum + props.ranges.length - 2
: 0
const start = inFlow
? clicks.flowSum + atNum - 1
const start = isRelative
? clicks.currentOffset + atNum - 1
: atNum
const end = start + props.ranges.length - 1
// register to the page click map
const id = makeId()
clicks.register(id, { max: end, flowSize })
clicks.register(id, { max: end, relativeDelta })
onUnmounted(() => clicks.unregister(id))
const index = computed(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/builtin/SlidevVideo.vue
Expand Up @@ -26,7 +26,7 @@ const matchRoute = computed(() => {
const matchClick = computed(() => {
if (!video.value || currentContext?.value !== 'slide' || clicks?.disabled || clicks?.current === undefined)
return false
return clicks.map.get(video.value)?.shows?.value ?? true
return clicks.map.get(video.value)?.isShown?.value ?? true
})
const matchRouteAndClick = computed(() => matchRoute.value && matchClick.value)
Expand Down
6 changes: 3 additions & 3 deletions packages/client/builtin/VClickGap.vue
Expand Up @@ -19,11 +19,11 @@ onMounted(() => {
if (!clicks || clicks.disabled)
return
const flowSize = safeParseNumber(props.size)
const max = clicks.flowSum + flowSize - 1
const relativeDelta = safeParseNumber(props.size)
const max = clicks.currentOffset + relativeDelta - 1
const id = makeId()
clicks.register(id, { max, flowSize })
clicks.register(id, { max, relativeDelta })
onCleanup(() => clicks.unregister(id))
})
})
Expand Down
4 changes: 2 additions & 2 deletions packages/client/builtin/VClicks.ts
Expand Up @@ -38,7 +38,7 @@ export default defineComponent({
render() {
const every = +this.every
const at = normalizeAtProp(this.at)
const inFlow = typeof at === 'string'
const isRelative = typeof at === 'string'

const click = resolveDirective('click')!

Expand Down Expand Up @@ -104,7 +104,7 @@ export default defineComponent({

return applyDirective(
vNode,
inFlow
isRelative
? delta >= 0 ? `+${delta}` : `${delta}`
: thisShowIdx,
)
Expand Down
24 changes: 12 additions & 12 deletions packages/client/logic/clicks.ts
Expand Up @@ -11,7 +11,7 @@ export function usePrimaryClicks(route: RouteRecordRaw | undefined): ClicksConte
return route.meta.__clicksContext
const thisPath = +(route?.path ?? 99999)

const flow = new Map()
const relativeOffsets = new Map()
const map = shallowReactive(new Map())

const context: ClicksContext = {
Expand All @@ -27,20 +27,20 @@ export function usePrimaryClicks(route: RouteRecordRaw | undefined): ClicksConte
else
return 0
},
flow,
relativeOffsets,
map,
register(el, resolved) {
flow.set(el, resolved.flowSize)
relativeOffsets.set(el, resolved.relativeDelta)
map.set(el, resolved)
},
unregister(el) {
flow.delete(el)
relativeOffsets.delete(el)
map.delete(el)
},
get flowSum() {
get currentOffset() {
// eslint-disable-next-line no-unused-expressions
routeForceRefresh.value
return sum(...flow.values())
return sum(...relativeOffsets.values())
},
get total() {
// eslint-disable-next-line no-unused-expressions
Expand All @@ -56,7 +56,7 @@ export function usePrimaryClicks(route: RouteRecordRaw | undefined): ClicksConte

export function useFixedClicks(route: RouteRecordRaw | undefined, currentInit = 0): [Ref<number>, ClicksContext] {
const current = ref(currentInit)
const flow = new Map()
const relativeOffsets = new Map()
const map = shallowReactive(new Map())

return [current, {
Expand All @@ -68,20 +68,20 @@ export function useFixedClicks(route: RouteRecordRaw | undefined, currentInit =
},
set current(_v) {
},
flow,
relativeOffsets,
map,
register(el, resolved) {
flow.set(el, resolved.flowSize)
relativeOffsets.set(el, resolved.relativeDelta)
map.set(el, resolved)
},
unregister(el) {
flow.delete(el)
relativeOffsets.delete(el)
map.delete(el)
},
get flowSum() {
get currentOffset() {
// eslint-disable-next-line no-unused-expressions
routeForceRefresh.value
return sum(...flow.values())
return sum(...relativeOffsets.values())
},
get total() {
// eslint-disable-next-line no-unused-expressions
Expand Down
14 changes: 7 additions & 7 deletions packages/client/modules/directives.ts
Expand Up @@ -146,34 +146,34 @@ function resolveClick(el: Element, dir: DirectiveBinding<any>, clickAfter = fals
else if (value == null || value === true || value === 'true')
value = '+1'

let flowSize: number
let relativeDelta: number
let thisClick: number | [number, number]
let maxClick: number
if (typeof value === 'string' && '+-'.includes(value[0])) {
// flow
flowSize = safeParseNumber(value)
thisClick = ctx.flowSum + flowSize
relativeDelta = safeParseNumber(value)
thisClick = ctx.currentOffset + relativeDelta
maxClick = thisClick
}
else if (Array.isArray(value)) {
// range (absolute)
flowSize = 0
relativeDelta = 0
thisClick = value as [number, number]
maxClick = value[1]
}
else {
// since (absolute)
flowSize = 0
relativeDelta = 0
thisClick = safeParseNumber(value)
maxClick = thisClick
}

const resolved = {
max: maxClick,
flowSize,
relativeDelta,
isActive: computed(() => isActive(thisClick, ctx.current)),
isCurrent: computed(() => isCurrent(thisClick, ctx.current)),
shows: computed(() => clickHide ? !isActive(thisClick, ctx.current) : isActive(thisClick, ctx.current)),
isShown: computed(() => clickHide ? !isActive(thisClick, ctx.current) : isActive(thisClick, ctx.current)),
clickHide,
CLASS_HIDE: fade ? CLASS_VCLICK_FADE : CLASS_VCLICK_HIDDEN,
}
Expand Down
10 changes: 5 additions & 5 deletions packages/types/src/types.ts
Expand Up @@ -78,25 +78,25 @@ export type LoadedSnippets = Record<string, string>

export type ClicksElement = Element | string

export type ClicksFlow = Map<ClicksElement, number>
export type ClicksRelativeEls = Map<ClicksElement, number>

export interface ResolvedClicksInfo {
max: number
flowSize: number
relativeDelta: number
isCurrent?: ComputedRef<boolean>
isActive?: ComputedRef<boolean>
shows?: ComputedRef<boolean>
isShown?: ComputedRef<boolean>
}

export type ClicksMap = Map<ClicksElement, ResolvedClicksInfo>

export interface ClicksContext {
readonly disabled: boolean
readonly current: number
readonly flow: ClicksFlow
readonly relativeOffsets: ClicksRelativeEls
readonly map: ClicksMap
register: (el: ClicksElement, resolved: ResolvedClicksInfo) => void
unregister: (el: ClicksElement) => void
readonly flowSum: number
readonly currentOffset: number
readonly total: number
}

0 comments on commit 9b405ee

Please sign in to comment.