
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
@vue-layout/basic
Advanced tools
A package containing basic components, to build for example multi level navigation menus.
A package containing basic components, to build for example multi level navigation menus.
Note The package is still in development and the API is still subject to change. Besides, the documentation still needs to be expanded
Table of Contents
$ npm i --save @vue-layout/basic
To use the navigation component, a constant must be defined,
which satisfy the type: NavigationProvider
.
The implementation will provide different navigation elements for each tier
.
The tier
is a numeric value, which can reach from 0 to n (infinity).
module.ts
import {
NavigationElement,
NavigationProvider
} from "@vue-layout/basic";
const primaryItems : NavigationElement[] = [
{
name: 'Home',
url: '/',
icon: 'fa fa-home'
},
{
name: 'About',
url: '/about',
icon: 'fa fa-info'
}
]
export const navigationProvider : NavigationProvider = {
async hasTier(tier: number): Promise<boolean> {
// check if the tier exists.
return Promise.resolve(tier === 1);
},
async getElements(tier: number, items: NavigationElement[]): Promise<NavigationElement[]> {
// Return elements for a specific tier.
// The context provides the current active elements for
// the parent tiers.
switch (tier) {
case 0:
return primaryItems;
// ....
}
},
async getElementsActive(url: string): Promise<NavigationElement[]> {
// build element context for url
if (url === '/') {
return [
primaryItems[0]
]
}
if (url === '/about') {
return [
primaryItems[1]
]
}
return undefined;
}
};
The next step is to create the vue entrypoint.
index.ts
import {
buildNavigation,
createPlugin
} from '@vue-layout/basic';
import { createApp } from 'vue';
import { createRouter, createWebHistory } from 'vue-router';
import { navigationProvider } from './module';
const app = createApp();
app.use(createPlugin({
navigationProvider
}));
const router = createRouter({
history: createWebHistory(),
routes: [
/* ... */
],
});
app.use(router);
(async () => {
const url = router?.currentRoute?.value?.fullPath;
await buildNavigation({ url });
app.mount('#app');
})();
After those steps are completed, the NavigationComponents
SFC can be placed anywhere, if registered globally.
<template>
<div>
<navigation-components :tier="0" />
<navigation-components :tier="1" />
</div>
</template>
▸ function
buildNavigation(context?: NavigationBuildContext
): Promise
<void
>
Build all navigation tiers, by url
or active elements
.
URL
import { buildNavigation } from '@vue-layout/basic';
await buildNavigation({
url: '/'
});
This will call the getElementsActive
method of the NavigationProvider
implementation,
to calculate the active elements
.
items
import { buildNavigation } from '@vue-layout/basic';
await buildNavigation({
items: [
{id: 'default', tier: 0, name: 'Home'}
]
})
This element
array will be provided as second argument as context to the getElements
method of
the NavigationProvider
implementation, to build a specific tier navigation.
▸ function
buildNavigationWithRoute(context?: Partial<NavigationBuildRouteContext>
): Promise
<void
>
Build all navigation tiers, by route
(url) or by interpreting the metaKey
attribute of
a route component.
route
import { RouteLocation } from 'vue-router';
import { buildNavigationWithRoute } from '@vue-layout/basic';
const route : RouteLocation = {
fullPath: '/',
...
};
await buildNavigationWithRoute({
route
})
This method call is under the hood equal to: buildNavigation({url: '/'})
.
metaKey
import { defineComponent } from 'vue';
import { buildNavigationWithRoute } from '@vue-layout/basic';
const metaKey = 'navigation';
const pageComponent = defineComponent({
meta: {
[metaKey]: [
{id: 'default', tier: 0, name: 'Home'}
]
},
...
});
await buildNavigationWithRoute({
metaKey
})
This method call is under the hood equal to:
buildNavigation({items: [{id: 'default', tier: 0, name: 'Home'}]})
.
import { Component } from '@vue-layout/basic';
type NavigationBuildContext = {
items?: Component[],
url?: string
};
import { RouteLocationNormalized } from 'vue-router';
type NavigationBuildRouteContext = {
route: RouteLocationNormalized,
metaKey: string
};
type NavigationElement = {
id?: string | number,
tier?: number,
name?: string,
url?: string,
urlTarget?: '_self' | '_blank' | '_parent' | '_top' | string,
default?: boolean,
type?: 'separator' | 'link',
icon?: string,
environment?: 'development' | 'production' | 'testing',
display?: boolean,
displayChildren?: boolean,
rootLink?: boolean,
children?: NavigationElement[],
requireLoggedIn?: boolean,
requireLoggedOut?: boolean,
requirePermissions?: string | string[] | ((checker: (name: string) => boolean) => boolean)
[key: string]: any
};
import { NavigationElement } from '@vue-layout/basic';
declare type NavigationProvider = {
getElements: (tier: number, items: NavigationElement[]) => Promise<NavigationElement[]>,
getElementsActive: (url: string) => Promise<NavigationElement[]>,
hasTier: (tier: number) => Promise<boolean>
};
For an implementation example, on how to use this library, check out the example package.
Made with 💚
Published under MIT License.
FAQs
A package containing basic components, to build for example multi level navigation menus.
We found that @vue-layout/basic demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.