repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
project-lakechain | github_2023 | awslabs | typescript | Pointer.toJSON | toJSON() {
return (this.uri.toString());
} | /**
* @returns the JSON representation of the class.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/typescript-sdk/src/pointer/index.ts#L164-L166 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ReferenceResolver.constructor | constructor(private event: CloudEvent) {} | /**
* `ReferenceResolver` constructor.
* @param event the cloud event to resolve the
* reference against.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/typescript-sdk/src/references/index.ts#L41-L41 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ReferenceResolver.resolveUrl | private resolveUrl(reference: IReference<IUrlSubject>): Promise<Buffer> {
return (createDataSource(reference.subject.url).asBuffer());
} | /**
* Resolves a URL reference.
* @param reference the reference to resolve.
* @returns
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/typescript-sdk/src/references/index.ts#L48-L50 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ReferenceResolver.resolveAttribute | private resolveAttribute(reference: IReference<IAttributeSubject>): any {
const value = get(this.event.toJSON(), reference.subject.attribute);
if (!value) {
throw new Error(`Attribute ${reference.subject.attribute} not found.`);
}
return (value);
} | /**
* Resolves an attribute reference.
* @param reference the reference to resolve.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/typescript-sdk/src/references/index.ts#L56-L63 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ReferenceResolver.resolveValue | private resolveValue(reference: IReference<IValueSubject>): any {
return (reference.subject.value);
} | /**
* Resolves a value reference.
* @param reference the reference to resolve.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/typescript-sdk/src/references/index.ts#L69-L71 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ReferenceResolver.resolvePointer | private resolvePointer(reference: IReference<IPointerSubject>): Promise<Buffer> {
const value = get(this.event.toJSON(), reference.subject.pointer);
if (!value) {
throw new Error(`Attribute ${reference.subject.pointer} not found.`);
}
return (createDataSource(value).asBuffer());
} | /**
* Resolves a pointer reference.
* @param reference the reference to resolve.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/typescript-sdk/src/references/index.ts#L77-L84 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ReferenceResolver.resolve | public async resolve<T extends IReferenceSubject>(reference: IReference<T>): Promise<any> {
switch (reference.subject.type) {
case 'url':
return (this.resolveUrl(reference as IReference<IUrlSubject>));
case 'attribute':
return (this.resolveAttribute(reference as IReference<IAttributeSubject>));
case 'value':
return (this.resolveValue(reference as IReference<IValueSubject>));
case 'pointer':
return (this.resolvePointer(reference as IReference<IPointerSubject>));
default:
throw new Error('Invalid reference subject type');
}
} | /**
* Resolves the given reference against the
* cloud event.
* @param reference the reference to resolve.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/typescript-sdk/src/references/index.ts#L91-L104 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | readStreamInMemory | const readStreamInMemory = async (stream: Readable) => {
const chunks: any[] = [];
for await (const chunk of stream) {
chunks.push(chunk);
}
return (Buffer.concat(chunks));
}; | /**
* A helper function that buffers a readable stream in memory.
* @param stream the readable stream to buffer.
* @returns a promise resolved with the buffer.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/typescript-sdk/tests/data-sources/http-data-source.test.ts#L29-L35 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
continew-admin-ui | github_2023 | continew-org | typescript | updateValue | const updateValue = (value: any) => {
emit('change', value)
emit('update:modelValue', value)
} | // 更新值 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/components/GenCron/CronForm/component/use-mixin.ts#L107-L110 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | parseValue | const parseValue = (value: any) => {
if (value === computeValue.value) {
return
}
try {
if (!value || value === defaultValue.value) {
type.value = TypeEnum.every
} else if (value.includes('?')) {
type.value = TypeEnum.unset
} else if (value.includes('-')) {
type.value = TypeEnum.range
const values = value.split('-')
if (values.length >= 2) {
valueRange.start = Number.parseInt(values[0])
valueRange.end = Number.parseInt(values[1])
}
} else if (value.includes('/')) {
type.value = TypeEnum.loop
const values = value.split('/')
if (values.length >= 2) {
valueLoop.start = value[0] === '*' ? 0 : Number.parseInt(values[0])
valueLoop.interval = Number.parseInt(values[1])
}
} else if (value.includes('W')) {
type.value = TypeEnum.work
const values = value.split('W')
if (!values[0] && !Number.isNaN(values[0])) {
valueWork.value = Number.parseInt(values[0])
}
} else if (value.includes('L')) {
type.value = TypeEnum.last
} else if (value.includes(',') || !Number.isNaN(value)) {
type.value = TypeEnum.specify
valueList.value = value.split(',').map((item: any) => Number.parseInt(item))
} else {
type.value = TypeEnum.every
}
} catch (e) {
type.value = TypeEnum.every
}
} | // 解析值 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/components/GenCron/CronForm/component/use-mixin.ts#L113-L153 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | hexToRgb | function hexToRgb(hex: string) {
if (hex.includes('#')) {
hex = hex.slice(1)
}
const r = Number.parseInt(hex.slice(0, 2), 16)
const g = Number.parseInt(hex.slice(2, 4), 16)
const b = Number.parseInt(hex.slice(4, 6), 16)
return { r, g, b }
} | // 十六进制颜色 转 rgb | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/components/GiTag/index.tsx#L65-L73 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | checkPermission | function checkPermission(el: HTMLElement, binding: DirectiveBinding) {
const userStore = useUserStore()
const { value } = binding
const all_permission = '*:*:*'
if (value && Array.isArray(value) && value.length) {
const permissionValues: string[] = value
const hasPermission = userStore.permissions.some((perm) => {
return all_permission === perm || permissionValues.includes(perm)
})
if (!hasPermission) {
el.parentNode && el.parentNode.removeChild(el)
}
} else {
throw new Error(`need permission! Like v-hasPerm="['home:btn:edit','home:btn:delete']"`)
}
} | /**
* @desc v-permission 操作权限处理
* @desc 使用 v-permission="['system:user:add']"
*/ | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/directives/permission/hasPerm.ts#L8-L24 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | checkRole | function checkRole(el: HTMLElement, binding: DirectiveBinding) {
const userStore = useUserStore()
const { value } = binding
const super_admin = 'role_admin'
if (value && Array.isArray(value) && value.length) {
const roleValues: string[] = value
const hasRole = userStore.roles.some((role) => {
return super_admin === role || roleValues.includes(role)
})
if (!hasRole) {
el.parentNode && el.parentNode.removeChild(el)
}
} else {
throw new Error(`need role! Like v-hasRole="['admin','user']"`)
}
} | /**
* @desc v-hasRole 角色权限处理
* @desc 使用 v-hasRole="['admin', 'user]"
*/ | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/directives/permission/hasRole.ts#L8-L23 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | selectAll | const selectAll: TableInstance['onSelectAll'] = (checked) => {
const key = rowKey ?? 'id'
const arr = (tableData.value as TableData[]).filter((i) => !(i?.disabled ?? false))
selectedKeys.value = checked ? arr.map((i) => i[key as string]) : []
} | // 全选 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/hooks/modules/useTable.ts#L48-L52 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | search | const search = () => {
selectedKeys.value = []
pagination.onChange(1)
} | // 查询 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/hooks/modules/useTable.ts#L55-L58 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | refresh | const refresh = () => {
getTableData()
} | // 刷新 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/hooks/modules/useTable.ts#L61-L63 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | handleDelete | const handleDelete = async <T>(
deleteApi: () => Promise<ApiRes<T>>,
options?: { title?: string, content?: string, successTip?: string, showModal?: boolean },
): Promise<boolean | undefined> => {
const onDelete = async () => {
try {
const res = await deleteApi()
if (res.success) {
Message.success(options?.successTip || '删除成功')
selectedKeys.value = []
await getTableData()
}
return res.success
} catch (error) {
return false
}
}
const flag = options?.showModal ?? true // 是否显示对话框
if (!flag) {
return onDelete()
}
Modal.warning({
title: options?.title || '提示',
content: options?.content || '是否确定删除该条数据?',
okButtonProps: { status: 'danger' },
hideCancel: false,
maskClosable: false,
onBeforeOk: onDelete,
})
} | // 删除 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/hooks/modules/useTable.ts#L66-L95 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | onUpdateSystem | const onUpdateSystem = (id: string) => {
Notification.remove(id)
window.location.reload()
} | // 更新 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/router/guard.ts#L20-L23 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | onCloseUpdateSystem | const onCloseUpdateSystem = (id: string) => {
Notification.remove(id)
} | // 关闭更新弹窗 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/router/guard.ts#L25-L27 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | handleNotification | const handleNotification = () => {
const id = `updateModel`
Notification.info({
id,
title: '新版本更新',
content: '当前系统检测到有新的版本,请及时更新',
duration: 0,
closable: true,
position: 'bottomRight',
footer: () => {
return h(Space, {}, () => [h(Button, {
type: 'primary',
onClick: () => onUpdateSystem(id),
}, '更新'), h(Button, { type: 'secondary', onClick: () => onCloseUpdateSystem(id) }, '关闭')])
},
})
} | // 提示用户更新弹窗 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/router/guard.ts#L29-L45 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | getVersionTag | const getVersionTag = async () => {
const response = await fetch('/', {
cache: 'no-cache',
})
return response.headers.get('etag') || response.headers.get('last-modified')
} | /**
* 获取首页的 ETag 或 Last-Modified 值,作为当前版本标识
* @returns {Promise<string|null>} 返回 ETag 或 Last-Modified 值
*/ | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/router/guard.ts#L51-L56 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | compareTag | const compareTag = async () => {
const newVersionTag = await getVersionTag()
if (versionTag === null) {
versionTag = newVersionTag
} else if (versionTag !== newVersionTag) {
// 如果 ETag 或 Last-Modified 发生变化,则认为有更新
// 提示用户更新
handleNotification()
}
} | /**
* 比较当前的 ETag 或 Last-Modified 值与最新获取的值
*/ | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/router/guard.ts#L61-L70 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | Layout | const Layout = () => import('@/layout/index.vue') | /** 默认布局 */ | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/router/route.ts#L4-L4 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | setThemeColor | const setThemeColor = (color: string) => {
if (!color) return
settingConfig.themeColor = color
const list = generate(settingConfig.themeColor, { list: true, dark: settingConfig.theme === 'dark' }) as string[]
list.forEach((color, index) => {
const rgbStr = getRgbStr(color)
document.body.style.setProperty(`--primary-${index + 1}`, rgbStr)
})
} | // 设置主题色 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/app.ts#L24-L32 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | toggleTheme | const toggleTheme = (dark: boolean) => {
if (dark) {
settingConfig.theme = 'dark'
document.body.setAttribute('arco-theme', 'dark')
} else {
settingConfig.theme = 'light'
document.body.removeAttribute('arco-theme')
}
setThemeColor(settingConfig.themeColor)
} | // 切换主题 暗黑模式|简白模式 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/app.ts#L35-L44 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | initTheme | const initTheme = () => {
if (!settingConfig.themeColor) return
setThemeColor(settingConfig.themeColor)
} | // 初始化主题 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/app.ts#L47-L50 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | setMenuCollapse | const setMenuCollapse = (collapsed: boolean) => {
settingConfig.menuCollapse = collapsed
} | // 设置左侧菜单折叠状态 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/app.ts#L53-L55 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | initSiteConfig | const initSiteConfig = () => {
listSiteOptionDict().then((res) => {
const resMap = new Map()
res.data.forEach((item) => {
resMap.set(item.label, item.value)
})
siteConfig.SITE_FAVICON = resMap.get('SITE_FAVICON')
siteConfig.SITE_LOGO = resMap.get('SITE_LOGO')
siteConfig.SITE_TITLE = resMap.get('SITE_TITLE')
siteConfig.SITE_COPYRIGHT = resMap.get('SITE_COPYRIGHT')
siteConfig.SITE_BEIAN = resMap.get('SITE_BEIAN')
document.title = resMap.get('SITE_TITLE')
document
.querySelector('link[rel="shortcut icon"]')
?.setAttribute('href', resMap.get('SITE_FAVICON') || '/favicon.ico')
})
} | // 初始化系统配置 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/app.ts#L60-L76 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | setSiteConfig | const setSiteConfig = (config: BasicConfig) => {
Object.assign(siteConfig, config)
document.title = config.SITE_TITLE || ''
document.querySelector('link[rel="shortcut icon"]')?.setAttribute('href', config.SITE_FAVICON || '/favicon.ico')
} | // 设置系统配置 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/app.ts#L79-L83 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | setDict | const setDict = (code: string, items: App.DictItem[]) => {
if (code) {
dictData.value[code] = items
}
} | // 设置字典 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/dict.ts#L7-L11 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | getDict | const getDict = (code: string) => {
if (!code) {
return null
}
return dictData.value[code] || null
} | // 获取字典 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/dict.ts#L14-L19 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | deleteDict | const deleteDict = (code: string) => {
if (!code || !(code in dictData.value)) {
return false
}
delete dictData.value[code]
return true
} | // 删除字典 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/dict.ts#L22-L28 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | cleanDict | const cleanDict = () => {
dictData.value = {}
} | // 清空字典 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/dict.ts#L31-L33 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | transformComponentView | const transformComponentView = (component: string) => {
return layoutComponentMap[component as keyof typeof layoutComponentMap] || asyncRouteModules[component]
} | /** 将component由字符串转成真正的模块 */ | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/route.ts#L17-L19 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | formatAsyncRoutes | const formatAsyncRoutes = (menus: RouteItem[]) => {
if (!menus.length) return []
const pathMap = new Map()
return mapTree(menus, (item) => {
pathMap.set(item.id, item.path)
if (item.children?.length) {
item.children.sort((a, b) => (a?.sort ?? 0) - (b?.sort ?? 0))
}
// 部分子菜单,例如:通知公告新增、查看详情,需要选中其父菜单
if (item.parentId && item.type === 2 && item.permission) {
item.activeMenu = pathMap.get(item.parentId)
}
return {
path: item.path,
name: item.name ?? transformPathToName(item.path),
component: transformComponentView(item.component),
redirect: item.redirect,
meta: {
title: item.title,
hidden: item.isHidden,
keepAlive: item.isCache,
icon: item.icon,
showInTabs: item.showInTabs,
activeMenu: item.activeMenu,
},
}
}) as unknown as RouteRecordRaw[]
} | /**
* @description 前端来做排序、格式化
* @params {menus} 后端返回的路由数据,已经根据当前用户角色过滤掉了没权限的路由
* 1. 对后端返回的路由数据进行排序,格式化
* 2. 同时将component由字符串转成真正的模块
*/ | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/route.ts#L27-L58 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | setRoutes | const setRoutes = (data: RouteRecordRaw[]) => {
// 合并路由并排序
routes.value = [...constantRoutes, ...systemRoutes].concat(data)
.sort((a, b) => (a.meta?.sort ?? 0) - (b.meta?.sort ?? 0))
asyncRoutes.value = data
} | // 合并路由 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/route.ts#L84-L89 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | generateRoutes | const generateRoutes = async (): Promise<RouteRecordRaw[]> => {
const { data } = await getUserRoute()
const asyncRoutes = formatAsyncRoutes(data)
const flatRoutes = flatMultiLevelRoutes(cloneDeep(asyncRoutes))
setRoutes(asyncRoutes)
return flatRoutes
} | // 生成路由 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/route.ts#L92-L98 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | addTabItem | const addTabItem = (item: RouteLocationNormalized) => {
const index = tabList.value.findIndex((i) => i.path === item.path)
if (index >= 0) {
tabList.value[index].fullPath !== item.fullPath && (tabList.value[index] = item)
} else {
if (item.meta?.showInTabs ?? true) {
tabList.value.push(item)
}
}
} | // 添加一个页签, 如果当前路由已经打开, 则不再重复添加 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/tabs.ts#L13-L22 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | deleteTabItem | const deleteTabItem = (path: string) => {
const index = tabList.value.findIndex((item) => item.path === path && !item.meta?.affix)
if (index < 0) return
const isActive = router.currentRoute.value.path === tabList.value[index].path
tabList.value.splice(index, 1)
if (isActive) {
const lastObj = tabList.value[tabList.value.length - 1]
router.push(lastObj.fullPath || lastObj.path)
}
} | // 删除一个页签 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/tabs.ts#L25-L34 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | clearTabList | const clearTabList = () => {
const routeStore = useRouteStore()
const arr: RouteLocationNormalized[] = []
_XEUtils_.eachTree(routeStore.routes, (item) => {
if (item.meta?.affix ?? false) {
arr.push(item as unknown as RouteLocationNormalized)
}
})
tabList.value = arr
} | // 清空页签 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/tabs.ts#L37-L46 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | addCacheItem | const addCacheItem = (item: RouteLocationNormalized) => {
if (!item.name) return
if (cacheList.value.includes(item.name)) return
if (item.meta?.keepAlive) {
cacheList.value.push(item.name)
}
} | // 添加缓存页 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/tabs.ts#L49-L55 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | deleteCacheItem | const deleteCacheItem = (name: RouteRecordName) => {
const index = cacheList.value.findIndex((i) => i === name)
if (index >= 0) {
cacheList.value.splice(index, 1)
}
} | // 删除一个缓存页 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/tabs.ts#L58-L63 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | clearCacheList | const clearCacheList = () => {
cacheList.value = []
} | // 清空缓存页 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/tabs.ts#L66-L68 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | closeCurrent | const closeCurrent = (path: string) => {
const item = tabList.value.find((i) => i.path === path)
item?.name && deleteCacheItem(item.name)
deleteTabItem(path)
} | // 关闭当前 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/tabs.ts#L71-L75 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | closeOther | const closeOther = (path: string) => {
const arr = tabList.value.filter((i) => i.path !== path)
arr.forEach((item) => {
deleteTabItem(item.path)
item?.name && deleteCacheItem(item.name)
})
} | // 关闭其他 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/tabs.ts#L78-L84 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | closeLeft | const closeLeft = (path: string) => {
const index = tabList.value.findIndex((i) => i.path === path)
if (index < 0) return
const arr = tabList.value.filter((i, n) => n < index)
arr.forEach((item) => {
deleteTabItem(item.path)
item?.name && deleteCacheItem(item.name)
})
} | // 关闭左侧 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/tabs.ts#L87-L95 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | closeRight | const closeRight = (path: string) => {
const index = tabList.value.findIndex((i) => i.path === path)
if (index < 0) return
const arr = tabList.value.filter((i, n) => n > index)
arr.forEach((item) => {
deleteTabItem(item.path)
item?.name && deleteCacheItem(item.name)
})
} | // 关闭右侧 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/tabs.ts#L98-L106 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | closeAll | const closeAll = () => {
clearTabList()
clearCacheList()
router.push({ path: '/' })
} | // 关闭全部 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/tabs.ts#L109-L113 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | reset | const reset = () => {
clearTabList()
clearCacheList()
} | // 重置 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/tabs.ts#L116-L119 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | init | const init = () => {
if (tabList.value.some((i) => !i?.meta.affix)) return
reset()
} | // 初始化 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/tabs.ts#L122-L125 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | resetToken | const resetToken = () => {
token.value = ''
clearToken()
resetHasRouteFlag()
} | // 重置token | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/user.ts#L46-L50 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | accountLogin | const accountLogin = async (req: AccountLoginReq) => {
const res = await accountLoginApi({ ...req, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeEnum.ACCOUNT })
setToken(res.data.token)
token.value = res.data.token
} | // 登录 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/user.ts#L53-L57 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | emailLogin | const emailLogin = async (req: EmailLoginReq) => {
const res = await emailLoginApi({ ...req, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeEnum.EMAIL })
setToken(res.data.token)
token.value = res.data.token
} | // 邮箱登录 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/user.ts#L60-L64 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | phoneLogin | const phoneLogin = async (req: PhoneLoginReq) => {
const res = await phoneLoginApi({ ...req, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeEnum.PHONE })
setToken(res.data.token)
token.value = res.data.token
} | // 手机号登录 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/user.ts#L67-L71 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | socialLogin | const socialLogin = async (source: string, req: any) => {
const res = await socialLoginApi({ ...req, source, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeEnum.SOCIAL })
setToken(res.data.token)
token.value = res.data.token
} | // 三方账号登录 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/user.ts#L74-L78 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | logoutCallBack | const logoutCallBack = async () => {
roles.value = []
permissions.value = []
pwdExpiredShow.value = true
resetToken()
resetRouter()
} | // 退出登录回调 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/user.ts#L81-L87 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | logout | const logout = async () => {
try {
await logoutApi()
await logoutCallBack()
return true
} catch (error) {
return false
}
} | // 退出登录 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/user.ts#L90-L98 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | getInfo | const getInfo = async () => {
const res = await getUserInfoApi()
Object.assign(userInfo, res.data)
userInfo.avatar = res.data.avatar
if (res.data.roles && res.data.roles.length) {
roles.value = res.data.roles
permissions.value = res.data.permissions
}
} | // 获取用户信息 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/stores/modules/user.ts#L101-L109 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | getFileName | function getFileName(url: string) {
const num = url.lastIndexOf('/') + 1
let fileName = url.substring(num)
// 把参数和文件名分割开
fileName = decodeURI(fileName.split('?')[0])
return fileName
} | /**
* 根据文件url获取文件名
* @param url 文件url
*/ | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/utils/downloadFile.ts#L5-L11 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | expressionNoYear | const expressionNoYear = (cron: string) => {
const vs = cron.split(' ')
// 长度=== 7 包含年表达式 不解析
if (vs.length === 7) {
return vs.slice(0, vs.length - 1).join(' ')
}
return cron
} | /**
* 不含年的 cron 表达式
* @param cron
*/ | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/utils/index.ts#L327-L334 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | toggleMode | const toggleMode = () => {
mode.value = mode.value === 'grid' ? 'list' : 'grid'
} | // 切换视图 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/views/system/file/main/FileMain/useFileManage.ts#L12-L14 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
continew-admin-ui | github_2023 | continew-org | typescript | addSelectedFileItem | const addSelectedFileItem = (item: FileItem) => {
if (selectedFileIds.value.includes(item.id)) {
const index = selectedFileList.value.findIndex((i) => i.id === item.id)
selectedFileList.value.splice(index, 1)
} else {
selectedFileList.value.push(item)
}
} | // 添加选择的文件 | https://github.com/continew-org/continew-admin-ui/blob/3b1f1aaee47083f84f41557a00364d94c964b44e/src/views/system/file/main/FileMain/useFileManage.ts#L17-L24 | 3b1f1aaee47083f84f41557a00364d94c964b44e |
lighthouse | github_2023 | Jac0xb | typescript | InvalidInstructionDataError.constructor | constructor(program: Program, cause?: Error) {
super('Invalid instruction', program, cause);
} | // 6000 | https://github.com/Jac0xb/lighthouse/blob/03a17f0647afc8240b64caaf9c20f52c90cd851b/clients/js/src/generated/errors/lighthouse.ts#L24-L26 | 03a17f0647afc8240b64caaf9c20f52c90cd851b |
lighthouse | github_2023 | Jac0xb | typescript | AssertionFailedError.constructor | constructor(program: Program, cause?: Error) {
super('AssertionFailed', program, cause);
} | // 6001 | https://github.com/Jac0xb/lighthouse/blob/03a17f0647afc8240b64caaf9c20f52c90cd851b/clients/js/src/generated/errors/lighthouse.ts#L37-L39 | 03a17f0647afc8240b64caaf9c20f52c90cd851b |
lighthouse | github_2023 | Jac0xb | typescript | NotEnoughAccountsError.constructor | constructor(program: Program, cause?: Error) {
super('NotEnoughAccounts', program, cause);
} | // 6002 | https://github.com/Jac0xb/lighthouse/blob/03a17f0647afc8240b64caaf9c20f52c90cd851b/clients/js/src/generated/errors/lighthouse.ts#L50-L52 | 03a17f0647afc8240b64caaf9c20f52c90cd851b |
lighthouse | github_2023 | Jac0xb | typescript | BumpNotFoundError.constructor | constructor(program: Program, cause?: Error) {
super('BumpNotFound', program, cause);
} | // 6003 | https://github.com/Jac0xb/lighthouse/blob/03a17f0647afc8240b64caaf9c20f52c90cd851b/clients/js/src/generated/errors/lighthouse.ts#L63-L65 | 03a17f0647afc8240b64caaf9c20f52c90cd851b |
lighthouse | github_2023 | Jac0xb | typescript | AccountBorrowFailedError.constructor | constructor(program: Program, cause?: Error) {
super('AccountBorrowFailed', program, cause);
} | // 6004 | https://github.com/Jac0xb/lighthouse/blob/03a17f0647afc8240b64caaf9c20f52c90cd851b/clients/js/src/generated/errors/lighthouse.ts#L76-L78 | 03a17f0647afc8240b64caaf9c20f52c90cd851b |
lighthouse | github_2023 | Jac0xb | typescript | RangeOutOfBoundsError.constructor | constructor(program: Program, cause?: Error) {
super('RangeOutOfBounds', program, cause);
} | // 6005 | https://github.com/Jac0xb/lighthouse/blob/03a17f0647afc8240b64caaf9c20f52c90cd851b/clients/js/src/generated/errors/lighthouse.ts#L89-L91 | 03a17f0647afc8240b64caaf9c20f52c90cd851b |
lighthouse | github_2023 | Jac0xb | typescript | IndexOutOfBoundsError.constructor | constructor(program: Program, cause?: Error) {
super('IndexOutOfBounds', program, cause);
} | // 6006 | https://github.com/Jac0xb/lighthouse/blob/03a17f0647afc8240b64caaf9c20f52c90cd851b/clients/js/src/generated/errors/lighthouse.ts#L102-L104 | 03a17f0647afc8240b64caaf9c20f52c90cd851b |
lighthouse | github_2023 | Jac0xb | typescript | FailedToDeserializeError.constructor | constructor(program: Program, cause?: Error) {
super('FailedToDeserialize', program, cause);
} | // 6007 | https://github.com/Jac0xb/lighthouse/blob/03a17f0647afc8240b64caaf9c20f52c90cd851b/clients/js/src/generated/errors/lighthouse.ts#L115-L117 | 03a17f0647afc8240b64caaf9c20f52c90cd851b |
lighthouse | github_2023 | Jac0xb | typescript | FailedToSerializeError.constructor | constructor(program: Program, cause?: Error) {
super('FailedToSerialize', program, cause);
} | // 6008 | https://github.com/Jac0xb/lighthouse/blob/03a17f0647afc8240b64caaf9c20f52c90cd851b/clients/js/src/generated/errors/lighthouse.ts#L128-L130 | 03a17f0647afc8240b64caaf9c20f52c90cd851b |
lighthouse | github_2023 | Jac0xb | typescript | AccountOwnerMismatchError.constructor | constructor(program: Program, cause?: Error) {
super('AccountOwnerMismatch', program, cause);
} | // 6009 | https://github.com/Jac0xb/lighthouse/blob/03a17f0647afc8240b64caaf9c20f52c90cd851b/clients/js/src/generated/errors/lighthouse.ts#L141-L143 | 03a17f0647afc8240b64caaf9c20f52c90cd851b |
lighthouse | github_2023 | Jac0xb | typescript | AccountKeyMismatchError.constructor | constructor(program: Program, cause?: Error) {
super('AccountKeyMismatch', program, cause);
} | // 6010 | https://github.com/Jac0xb/lighthouse/blob/03a17f0647afc8240b64caaf9c20f52c90cd851b/clients/js/src/generated/errors/lighthouse.ts#L154-L156 | 03a17f0647afc8240b64caaf9c20f52c90cd851b |
lighthouse | github_2023 | Jac0xb | typescript | AccountNotInitializedError.constructor | constructor(program: Program, cause?: Error) {
super('AccountNotInitialized', program, cause);
} | // 6011 | https://github.com/Jac0xb/lighthouse/blob/03a17f0647afc8240b64caaf9c20f52c90cd851b/clients/js/src/generated/errors/lighthouse.ts#L167-L169 | 03a17f0647afc8240b64caaf9c20f52c90cd851b |
lighthouse | github_2023 | Jac0xb | typescript | AccountOwnerValidationFailedError.constructor | constructor(program: Program, cause?: Error) {
super('AccountOwnerValidationFailed', program, cause);
} | // 6012 | https://github.com/Jac0xb/lighthouse/blob/03a17f0647afc8240b64caaf9c20f52c90cd851b/clients/js/src/generated/errors/lighthouse.ts#L180-L182 | 03a17f0647afc8240b64caaf9c20f52c90cd851b |
lighthouse | github_2023 | Jac0xb | typescript | AccountFundedValidationFailedError.constructor | constructor(program: Program, cause?: Error) {
super('AccountFundedValidationFailed', program, cause);
} | // 6013 | https://github.com/Jac0xb/lighthouse/blob/03a17f0647afc8240b64caaf9c20f52c90cd851b/clients/js/src/generated/errors/lighthouse.ts#L196-L198 | 03a17f0647afc8240b64caaf9c20f52c90cd851b |
lighthouse | github_2023 | Jac0xb | typescript | AccountDiscriminatorValidationFailedError.constructor | constructor(program: Program, cause?: Error) {
super('AccountDiscriminatorValidationFailed', program, cause);
} | // 6014 | https://github.com/Jac0xb/lighthouse/blob/03a17f0647afc8240b64caaf9c20f52c90cd851b/clients/js/src/generated/errors/lighthouse.ts#L212-L214 | 03a17f0647afc8240b64caaf9c20f52c90cd851b |
lighthouse | github_2023 | Jac0xb | typescript | AccountValidationFailedError.constructor | constructor(program: Program, cause?: Error) {
super('AccountValidaitonFailed', program, cause);
} | // 6015 | https://github.com/Jac0xb/lighthouse/blob/03a17f0647afc8240b64caaf9c20f52c90cd851b/clients/js/src/generated/errors/lighthouse.ts#L228-L230 | 03a17f0647afc8240b64caaf9c20f52c90cd851b |
lighthouse | github_2023 | Jac0xb | typescript | CrossProgramInvokeViolationError.constructor | constructor(program: Program, cause?: Error) {
super('CrossProgramInvokeViolation', program, cause);
} | // 6016 | https://github.com/Jac0xb/lighthouse/blob/03a17f0647afc8240b64caaf9c20f52c90cd851b/clients/js/src/generated/errors/lighthouse.ts#L241-L243 | 03a17f0647afc8240b64caaf9c20f52c90cd851b |
browser-copilot | github_2023 | abstracta | typescript | AgentSession.activate | public async activate(msgSender: (msg: BrowserMessage) => void) {
let resp = await this.agent.createSession(await browser.i18n.getAcceptLanguages(), this.authService)
this.id = resp.id
let httpAction = this.agent.activationAction?.httpRequest
if (httpAction) {
await fetchJson(this.solveUrlTemplate(httpAction.url, this.url), { method: httpAction.method })
}
await this.updateRequestRules()
await this.startPolling(msgSender)
} | // cannot just import sendToTab from background.ts as it will re register listeners and cause requests to be processed twice and message duplication in ui | https://github.com/abstracta/browser-copilot/blob/e52fb006f4dd724fb1f3ba86abf82574b437753e/browser-extension/src/scripts/agent-session.ts#L29-L38 | e52fb006f4dd724fb1f3ba86abf82574b437753e |
reor | github_2023 | reorproject | typescript | createIPCHandler | function createIPCHandler<T extends (...args: any[]) => any>(channel: string): IPCHandler<T> {
return (...args: Parameters<T>) => ipcRenderer.invoke(channel, ...args) as Promise<ReturnType<T>>
} | // eslint-disable-next-line @typescript-eslint/no-explicit-any | https://github.com/reorproject/reor/blob/ae4bc6ed97cb43a905319b6f35e10a0fc59077b8/electron/preload/index.ts#L19-L21 | ae4bc6ed97cb43a905319b6f35e10a0fc59077b8 |
reor | github_2023 | reorproject | typescript | linkInputRule | function linkInputRule(config: Parameters<typeof markInputRule>[0]) {
const defaultMarkInputRule = markInputRule(config)
return new InputRule({
find: config.find,
handler(props) {
const { tr } = props.state
defaultMarkInputRule.handler(props)
tr.setMeta('preventAutolink', true)
},
})
} | /**
* Input rule built specifically for the `Link` extension, which ignores the auto-linked URL in
* parentheses (e.g., `(https://doist.dev)`).
*
* @see https://github.com/ueberdosis/tiptap/discussions/1865
*/ | https://github.com/reorproject/reor/blob/ae4bc6ed97cb43a905319b6f35e10a0fc59077b8/src/components/Editor/RichTextLink.tsx#L23-L35 | ae4bc6ed97cb43a905319b6f35e10a0fc59077b8 |
reor | github_2023 | reorproject | typescript | linkPasteRule | function linkPasteRule(config: Parameters<typeof markPasteRule>[0]) {
const defaultMarkPasteRule = markPasteRule(config)
return new PasteRule({
find: config.find,
handler(props) {
const { tr } = props.state
defaultMarkPasteRule.handler(props)
tr.setMeta('preventAutolink', true)
},
})
} | /**
* Paste rule built specifically for the `Link` extension, which ignores the auto-linked URL in
* parentheses (e.g., `(https://doist.dev)`). This extension was inspired from the multiple
* implementations found in a Tiptap discussion at GitHub.
*
* @see https://github.com/ueberdosis/tiptap/discussions/1865
*/ | https://github.com/reorproject/reor/blob/ae4bc6ed97cb43a905319b6f35e10a0fc59077b8/src/components/Editor/RichTextLink.tsx#L44-L56 | ae4bc6ed97cb43a905319b6f35e10a0fc59077b8 |
reor | github_2023 | reorproject | typescript | handleClick | const handleClick = () => {
onClick() // This calls the provided onClick handler
setShowArrow(true) // Show the arrow icon
} | // top -= 55; | https://github.com/reorproject/reor/blob/ae4bc6ed97cb43a905319b6f35e10a0fc59077b8/src/components/Sidebars/SemanticSidebar/HighlightButton.tsx#L31-L34 | ae4bc6ed97cb43a905319b6f35e10a0fc59077b8 |
reor | github_2023 | reorproject | typescript | useOrderedSet | const useOrderedSet = (initialValues: string[] = []) => {
const [set, setSet] = useState(new Set(initialValues))
const add = useCallback((value: string) => {
setSet((prevSet) => {
const newSet = new Set(prevSet)
if (newSet.has(value)) {
newSet.delete(value)
}
newSet.add(value)
return newSet
})
}, [])
const remove = useCallback((value: string) => {
setSet((prevSet) => {
const newSet = new Set(prevSet)
newSet.delete(value)
return newSet
})
}, [])
const clear = useCallback(() => {
setSet(new Set())
}, [])
return {
set,
add,
remove,
clear,
values: Array.from(set),
}
} | // Custom hook for managing ordered set | https://github.com/reorproject/reor/blob/ae4bc6ed97cb43a905319b6f35e10a0fc59077b8/src/lib/hooks/use-ordered-set.tsx#L4-L37 | ae4bc6ed97cb43a905319b6f35e10a0fc59077b8 |
iptv-sources | github_2023 | HerbertHe | typescript | matrixGen | const matrixGen = (
m: string
) => `| HTTP Protocol | URL | Auto-update Frequence | Latest Updated | IDC | Provider |
| ------------- | --- | --------------------- | --- | --- | -------- |
${m}
` | // 仅支持 GitHub Action 进行镜像站测试,降低镜像站负载压力 | https://github.com/HerbertHe/iptv-sources/blob/136e01a7bbd6c89560b603a0d8a5dd0bee3d4192/src/matrix.ts#L10-L15 | 136e01a7bbd6c89560b603a0d8a5dd0bee3d4192 |
frpc-desktop | github_2023 | luckjiawei | typescript | pathResolve | const pathResolve = (dir: string): string => {
return resolve(__dirname, ".", dir);
}; | /** 路径查找 */ | https://github.com/luckjiawei/frpc-desktop/blob/5d124c7efb46733c792e80f609e65873b3d587db/vite.config.ts#L13-L15 | 5d124c7efb46733c792e80f609e65873b3d587db |
frpc-desktop | github_2023 | luckjiawei | typescript | startFrpcProcess | const startFrpcProcess = (commandPath: string, configPath: string) => {
logInfo(
LogModule.FRP_CLIENT,
`Starting frpc process. Directory: ${app.getPath(
"userData"
)}, Command: ${commandPath}`
);
const command = `${commandPath} -c ${configPath}`;
frpcProcess = spawn(command, {
cwd: app.getPath("userData"),
shell: true
});
runningCmd.commandPath = commandPath;
runningCmd.configPath = configPath;
frpcProcess.stdout.on("data", data => {
logDebug(LogModule.FRP_CLIENT, `Frpc process output: ${data}`);
});
frpcProcess.stdout.on("error", data => {
logError(LogModule.FRP_CLIENT, `Frpc process error: ${data}`);
stopFrpcProcess(() => {});
});
frpcStatusListener = setInterval(() => {
const status = frpcProcessStatus();
logDebug(
LogModule.FRP_CLIENT,
`Monitoring frpc process status: ${status}, Listener ID: ${frpcStatusListener}`
);
if (!status) {
new Notification({
title: "Frpc Desktop",
body: "Connection lost, please check the logs for details."
}).show();
logError(
LogModule.FRP_CLIENT,
"Frpc process status check failed. Connection lost."
);
clearInterval(frpcStatusListener);
}
}, 3000);
}; | /**
* 启动frpc子进程
* @param cwd
* @param commandPath
* @param configPath
*/ | https://github.com/luckjiawei/frpc-desktop/blob/5d124c7efb46733c792e80f609e65873b3d587db/electron/api/frpc.ts#L481-L524 | 5d124c7efb46733c792e80f609e65873b3d587db |
frpc-desktop | github_2023 | luckjiawei | typescript | handleApiResponse | const handleApiResponse = (githubReleaseJsonStr: string) => {
const downloadPath = path.join(app.getPath("userData"), "download");
const frpPath = path.join(app.getPath("userData"), "frp");
logInfo(LogModule.GITHUB, "Parsing GitHub release JSON response.");
versions = JSON.parse(githubReleaseJsonStr);
if (versions) {
logInfo(
LogModule.GITHUB,
"Successfully parsed versions from GitHub response."
);
const returnVersionsData = versions
.filter(f => getAdaptiveAsset(f.id))
.map(m => {
const asset = getAdaptiveAsset(m.id);
const download_count = m.assets.reduce(
(sum, item) => sum + item.download_count,
0
);
if (asset) {
const absPath = path.join(
frpPath,
asset.name.replace(/(\.tar\.gz|\.zip)$/, "")
);
m.absPath = absPath;
m.download_completed = fs.existsSync(absPath);
m.download_count = download_count;
m.size = formatBytes(asset.size);
logInfo(
LogModule.GITHUB,
`Asset found: ${asset.name}, download count: ${download_count}`
);
} else {
logWarn(LogModule.GITHUB, `No asset found for version ID: ${m.id}`);
}
return m;
});
logDebug(
LogModule.GITHUB,
`Retrieved FRP versions: ${JSON.stringify(returnVersionsData)}`
);
return returnVersionsData;
} else {
logError(
LogModule.GITHUB,
"Failed to parse versions: No versions found in response."
);
return [];
}
}; | /**
* handle github api release json
* @param githubReleaseJsonStr jsonStr
* @returns versions
*/ | https://github.com/luckjiawei/frpc-desktop/blob/5d124c7efb46733c792e80f609e65873b3d587db/electron/api/github.ts#L200-L250 | 5d124c7efb46733c792e80f609e65873b3d587db |
frpc-desktop | github_2023 | luckjiawei | typescript | conventMirrorUrl | const conventMirrorUrl = (mirror: string) => {
switch (mirror) {
case "github":
return {
api: "https://api.github.com",
asset: "https://github.com"
};
default:
return {
api: "https://api.github.com",
asset: "https://github.com"
};
}
}; | /**
* conventMirrorUrl
* @param mirror mirror
* @returns mirrorUrl
*/ | https://github.com/luckjiawei/frpc-desktop/blob/5d124c7efb46733c792e80f609e65873b3d587db/electron/api/github.ts#L257-L270 | 5d124c7efb46733c792e80f609e65873b3d587db |
frpc-desktop | github_2023 | luckjiawei | typescript | useLoading | function useLoading() {
const className = `loaders-css__square-spin`
const styleContent = `
@keyframes square-spin {
25% { transform: perspective(100px) rotateX(180deg) rotateY(0); }
50% { transform: perspective(100px) rotateX(180deg) rotateY(180deg); }
75% { transform: perspective(100px) rotateX(0) rotateY(180deg); }
100% { transform: perspective(100px) rotateX(0) rotateY(0); }
}
.${className} > div {
animation-fill-mode: both;
width: 50px;
height: 50px;
background: #5F3BB0;
animation: square-spin 3s 0s cubic-bezier(0.09, 0.57, 0.49, 0.9) infinite;
}
.app-loading-wrap {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: #ffffff;
z-index: 9;
}
`
const oStyle = document.createElement('style')
const oDiv = document.createElement('div')
oStyle.id = 'app-loading-style'
oStyle.innerHTML = styleContent
oDiv.className = 'app-loading-wrap'
oDiv.innerHTML = `<div class="${className}"><div></div></div>`
return {
appendLoading() {
safeDOM.append(document.head, oStyle)
safeDOM.append(document.body, oDiv)
},
removeLoading() {
safeDOM.remove(document.head, oStyle)
safeDOM.remove(document.body, oDiv)
},
}
} | /**
* https://tobiasahlin.com/spinkit
* https://connoratherton.com/loaders
* https://projects.lukehaas.me/css-loaders
* https://matejkustec.github.io/SpinThatShit
*/ | https://github.com/luckjiawei/frpc-desktop/blob/5d124c7efb46733c792e80f609e65873b3d587db/electron/preload/index.ts#L34-L81 | 5d124c7efb46733c792e80f609e65873b3d587db |
GUI.for.Clash | github_2023 | GUI-for-Cores | typescript | updatePluginTrigger | const updatePluginTrigger = (plugin: PluginType, isUpdate = true) => {
const triggers = Object.keys(PluginsTriggerMap) as PluginTrigger[]
triggers.forEach((trigger) => {
PluginsTriggerMap[trigger].observers = PluginsTriggerMap[trigger].observers.filter(
(v) => v !== plugin.id,
)
})
if (isUpdate) {
plugin.triggers.forEach((trigger) => {
PluginsTriggerMap[trigger].observers.push(plugin.id)
})
}
} | // FIXME: Plug-in execution order is wrong | https://github.com/GUI-for-Cores/GUI.for.Clash/blob/abd6c7cf3d0b4534cdec5b0ad5f3d26145bb9764/frontend/src/stores/plugins.ts#L143-L155 | abd6c7cf3d0b4534cdec5b0ad5f3d26145bb9764 |
SecureAI-Tools | github_2023 | SecureAI-Tools | typescript | OrgMembershipService.hasReadPermission | async hasReadPermission(
userId: Id<IdType.User>,
orgIdOrSlug: string,
): Promise<boolean> {
return this.hasPermission(userId, orgIdOrSlug, [
OrgMembershipRole.ADMIN,
OrgMembershipRole.USER,
]);
} | // The user must be either an ADMIN or a USER of that organization | https://github.com/SecureAI-Tools/SecureAI-Tools/blob/260ddc5b190108ad7a2c70e273b0632e114d8ba1/apps/web/lib/api/services/org-membership-service.ts#L213-L221 | 260ddc5b190108ad7a2c70e273b0632e114d8ba1 |
SecureAI-Tools | github_2023 | SecureAI-Tools | typescript | OrgMembershipService.hasAdminPermission | async hasAdminPermission(
userId: Id<IdType.User>,
orgIdOrSlug: string,
): Promise<boolean> {
return this.hasPermission(userId, orgIdOrSlug, [OrgMembershipRole.ADMIN]);
} | // Checks if given userId has admin permission to orgId | https://github.com/SecureAI-Tools/SecureAI-Tools/blob/260ddc5b190108ad7a2c70e273b0632e114d8ba1/apps/web/lib/api/services/org-membership-service.ts#L224-L229 | 260ddc5b190108ad7a2c70e273b0632e114d8ba1 |
SecureAI-Tools | github_2023 | SecureAI-Tools | typescript | PermissionService.hasWriteChatPermission | async hasWriteChatPermission(
userId: Id<IdType.User>,
chatId: Id<IdType.Chat>,
): Promise<[boolean, Response | undefined]> {
// Only chat creators can write to a chat for now.
//
// Revisit this when allowing sharing!
return await this.isChatCreatorWithActiveMembership(userId, chatId);
} | // Checks whether userId has write permission to given chat! | https://github.com/SecureAI-Tools/SecureAI-Tools/blob/260ddc5b190108ad7a2c70e273b0632e114d8ba1/apps/web/lib/api/services/permission-service.ts#L31-L39 | 260ddc5b190108ad7a2c70e273b0632e114d8ba1 |
SecureAI-Tools | github_2023 | SecureAI-Tools | typescript | getUnit | function getUnit(byts: number): bytes.Unit {
if (byts < Math.pow(2, 10 * 1)) {
return "B";
} else if (byts < Math.pow(2, 10 * 2)) {
return "KB";
} else {
return "MB";
}
} | // Returns best suitable unit for bytes | https://github.com/SecureAI-Tools/SecureAI-Tools/blob/260ddc5b190108ad7a2c70e273b0632e114d8ba1/apps/web/lib/core/bytes-utils.ts#L20-L28 | 260ddc5b190108ad7a2c70e273b0632e114d8ba1 |
SecureAI-Tools | github_2023 | SecureAI-Tools | typescript | AppsLoggedInLayout | const AppsLoggedInLayout = ({
children,
onAuthenticated,
}: {
children: React.ReactNode;
onAuthenticated?: () => void;
}) => {
const { data: session, status } = useSession();
const router = useRouter();
if (status === "unauthenticated") {
// User is NOT logged in; Take them to the log in page
router.push(FrontendRoutes.LOG_IN);
return <p>Redirecting to log in page</p>;
}
useEffect(() => {
if (status === "authenticated") {
onAuthenticated?.();
}
}, [status]);
return (
<>
{status === "loading" ? (
<div className={styles.main}>
<div className={styles.container}>
<Spinner size="xl" />
</div>
</div>
) : (
children
)}
</>
);
}; | // LoggedInLayout but for apps directory | https://github.com/SecureAI-Tools/SecureAI-Tools/blob/260ddc5b190108ad7a2c70e273b0632e114d8ba1/apps/web/lib/fe/components/apps-logged-in-layout.tsx#L12-L47 | 260ddc5b190108ad7a2c70e273b0632e114d8ba1 |
SecureAI-Tools | github_2023 | SecureAI-Tools | typescript | renderLoadingSpinner | const renderLoadingSpinner = () => {
return (
<div className={tw("flex flex-col items-center justify-center h-screen")}>
<Spinner size="xl" />
<p className={tw("mt-4")}>Loading...</p>
</div>
);
}; | // Loading spinner for various doc preview elements | https://github.com/SecureAI-Tools/SecureAI-Tools/blob/260ddc5b190108ad7a2c70e273b0632e114d8ba1/apps/web/lib/fe/components/chat-with-docs.tsx#L112-L119 | 260ddc5b190108ad7a2c70e273b0632e114d8ba1 |
SecureAI-Tools | github_2023 | SecureAI-Tools | typescript | LoggedInLayout | const LoggedInLayout = ({
children,
title = PUBLIC_FACING_NAME,
description = PUBLIC_FACING_NAME,
}: {
children: React.ReactNode;
title?: string;
description?: string;
}) => {
const { data: session, status } = useSession();
const router = useRouter();
if (status === "unauthenticated") {
// User is NOT logged in; Take them to the log in page
router.push(FrontendRoutes.LOG_IN);
return <p>Redirecting to log in page</p>;
}
return (
<Layout title={title} description={description}>
{status === "loading" ? (
<div className={styles.main}>
<div className={styles.container}>
<Spinner size="xl" />
</div>
</div>
) : (
children
)}
</Layout>
);
}; | // TODO: Remove this once everything has moved to using apps dir routing! | https://github.com/SecureAI-Tools/SecureAI-Tools/blob/260ddc5b190108ad7a2c70e273b0632e114d8ba1/apps/web/lib/fe/components/logged-in-layout.tsx#L12-L43 | 260ddc5b190108ad7a2c70e273b0632e114d8ba1 |
SecureAI-Tools | github_2023 | SecureAI-Tools | typescript | generateInternalName | const generateInternalName = (): string => {
return customAlphabetNanoid();
}; | // Generates a compatible internal name of a doc collection | https://github.com/SecureAI-Tools/SecureAI-Tools/blob/260ddc5b190108ad7a2c70e273b0632e114d8ba1/packages/backend/src/services/document-collection-service.ts#L173-L175 | 260ddc5b190108ad7a2c70e273b0632e114d8ba1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.