Skip to content

Commit

Permalink
added packages
Browse files Browse the repository at this point in the history
  • Loading branch information
nikoloza committed Oct 22, 2021
1 parent 8ebe47c commit dbdf373
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/cookie/index.js
@@ -0,0 +1,22 @@
'use strict'

export const isMobile = (() => /Mobi/.test(navigator.userAgent))()

export const setCookie = (cname, cvalue, exdays = 365) => {
const d = new Date()
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000))
const expires = `expires=${d.toUTCString()}`
document.cookie = `${cname}=${cvalue};${expires};path=/`
}

export const getCookie = (cname) => {
const name = `${cname}=`
const decodedCookie = decodeURIComponent(document.cookie)
const ca = decodedCookie.split(';')
for (let i = 0; i < ca.length; i++) {
let c = ca[i]
while (c.charAt(0) === ' ') c = c.substring(1)
if (c.indexOf(name) === 0) return c.substring(name.length, c.length)
}
return ''
}
34 changes: 34 additions & 0 deletions packages/emotion/index.js
@@ -0,0 +1,34 @@
'use strict'

import DOM from '../../src'
import { isObjectLike, exec } from '../../src/utils'
import { classList } from '../../src/element/mixins'

import { css } from 'emotion'

const style = (params, element, node) => {
if (params) {
if (isObjectLike(element.class)) element.class.style = params
else element.class = { style: params }
}
classf(element.class, element, node)
}

const classf = (params, element, node) => {
if (isObjectLike(params)) {
const classObjHelper = {}
for (const key in params) {
const prop = exec(params[key], element)
const CSSed = css(prop)
classObjHelper[key] = CSSed
}
classList(classObjHelper, element, node)
}
}

DOM.define({
style,
class: classf
}, {
overwrite: true
})
23 changes: 23 additions & 0 deletions packages/routeLink/index.js
@@ -0,0 +1,23 @@
'use strict'

import { Link } from '@rackai/symbols'
import { deepMerge } from '../../src/utils'
import route from './router'

const RouteLink = {
on: {
click: (event, element, state) => {
const root = element.lookup('app')
const { href } = element.props
const firstThree = href[0] + href[1] + href[2]
if (href && firstThree !== 'htt' && firstThree !== 'ske') {
route(root, href, {})
event.preventDefault()
}
}
}
}

deepMerge(Link, RouteLink)

export default RouteLink
18 changes: 18 additions & 0 deletions packages/router/index.js
@@ -0,0 +1,18 @@
'use strict'

export const splitRoute = (route = window.location.pathname) => route.slice(1).split('/')

export default (rootElement, path, state = {}, level = 0, pushState = true) => {
const route = path || window.location.pathname
const routes = splitRoute(route)

const content = rootElement.routes[`/${routes[level]}`]

if (content) {
if (pushState) window.history.pushState(state, null, route)
rootElement.set({ proto: content })
.node.scrollIntoView({ behavior: 'smooth' })
}

if (level === 0) rootElement.state.update({ activePage: routes[level] })
}

0 comments on commit dbdf373

Please sign in to comment.