Skip to content

Commit

Permalink
wip: plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
cole committed Jul 31, 2024
1 parent c2bf812 commit 8927fa5
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 2 deletions.
Empty file.
41 changes: 41 additions & 0 deletions packages/plugins/loading/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { h, Transition, onMounted } from 'vue'
import { Spin } from 'ant-design-vue'
import { createReactivePlugin, createGlobalNode, createChildApp } from '../../utils/create'

let uid = 0

const defaults = {
group: '__default_group__',
delay: 0
}

const Plugin = createReactivePlugin({
isActive: false
}, {
show (options) {
Plugin.isActive = true
const el = createGlobalNode('pro-loading')
const app = createChildApp({
setup () {
function onAfterLeave () {

}

return () => {
const props = {
onAfterLeave: onAfterLeave
}
return h(Transition, props, Spin)
}
}
})
},
hide () {

},
install () {

}
})

export default Plugin
3 changes: 1 addition & 2 deletions packages/plugins/screen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import { addClass, getWindowSize, removeClass } from '../../utils/dom'
import { addEvt } from '../../utils/event'
import { debounce, pick } from 'lodash-es'

const SIZE_LIST = ['xs', 'sm', 'md', 'lg', 'xl', 'xxl']

const BaseKey = Symbol('Screen')

export function createScreen (options) {
const { sizes = {}, delay = 16, classes } = options || {}

const SIZE_LIST = ['xs', 'sm', 'md', 'lg', 'xl', 'xxl']
const baseSizes = {
xs: 0,
sm: 576,
Expand Down
50 changes: 50 additions & 0 deletions packages/utils/create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { createApp, reactive } from 'vue'
import { omit } from 'lodash-es'

const bodyNode = document.body
const nodes = []

export function createChildApp (rootComponent, parentApp) {
const appContext = omit(parentApp._context, ['reload'])

const app = createApp(rootComponent)
app.config.globalProperties = parentApp.config.globalProperties

Object.assign(app._context, appContext)
return app
}

export function createGlobalNode (id, className) {
const el = document.createElement('div')
if (className !== undefined) {
el.className = className
}
el.id = id
bodyNode.appendChild(el)
nodes.push(el)
return el
}

export function removeGlobalNode (el) {
const index = nodes.indexOf(el)
nodes.splice(index, 1)
el.remove()
}

export function createReactivePlugin (state, plugin) {
const pluginState = reactive(state)

for (const name in pluginState) {
Object.defineProperty(plugin, name, {
enumerable: true,
get () {
return pluginState[name]
},
set (value) {
pluginState[name] = value
}
})
}

return plugin
}

0 comments on commit 8927fa5

Please sign in to comment.