Socket
Socket
Sign inDemoInstall

druxt-router

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

druxt-router - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

nuxt/component.js

63

dist/druxt-router.esm.js

@@ -0,1 +1,2 @@

import { resolve } from 'path';
import { mapState } from 'vuex';

@@ -290,2 +291,3 @@ import axios from 'axios';

actions: {
// @TODO - Change this to use the 'getRoute' and 'getEntity' actions.
get: async function get (ref, path) {

@@ -350,2 +352,17 @@ var commit = ref.commit;

return entity
},
getRoute: async function getRoute (ref, path) {
var commit = ref.commit;
var state = ref.state;
if (typeof state.routes[path] !== 'undefined') {
return state.routes[path]
}
var route = await this.$druxtRouter().getRoute(path);
commit('addRoute', { path: path, route: route });
return route
}

@@ -360,2 +377,48 @@ }

function index (moduleOptions) {
var this$1 = this;
if ( moduleOptions === void 0 ) moduleOptions = {};
var options = Object.assign({}, this.options['druxt-router'],
moduleOptions);
this.extendRoutes(function (routes, resolve) {
// Only add router component if custom component is undefined.
// @TODO - Validate custom component.
// @TODO - Add test for custom component.
if (!options.component) {
options.component = resolve(this$1.options.buildDir, 'components/druxt-router.js');
this$1.addTemplate({
src: resolve(__dirname, '../nuxt/component.js'),
fileName: 'components/druxt-router.js',
options: options
});
}
// Add Druxt router custom wildcard route.
routes.push({
name: 'druxt-router',
path: '*',
component: options.component,
chunkName: 'druxt-router'
});
});
// Add plugin.
this.addPlugin({
src: resolve(__dirname, '../nuxt/plugin.js'),
fileName: 'druxt-router.js',
options: options
});
// Add Vuex plugin.
// @TODO - Ensure Vuex store is available.
this.addPlugin({
src: resolve(__dirname, '../nuxt/store.js'),
fileName: 'store/druxt-router.js',
options: options
});
}
export default index;
export { DruxtRouter, DruxtRouterComponent, DruxtRouterEntityMixin, DruxtRouterStore };

2

dist/druxt-router.min.js

@@ -1,1 +0,1 @@

var DruxtRouter=function(t,e,r,i){"use strict";r=r&&r.hasOwnProperty("default")?r.default:r,i=i&&i.hasOwnProperty("default")?i.default:i;var o={name:"druxt-router",head:function(){return{title:this.title,link:[{rel:"canonical",href:this.canonical||this.route.entity.canonical}],meta:this.metatags||!1}},computed:Object.assign({},{title:function(){return this.route.label}},e.mapState({entity:function(t){return t.druxtRouter.entities[t.druxtRouter.route.entity.uuid]},redirect:function(t){return t.druxtRouter.redirect},route:function(t){return t.druxtRouter.route}})),render:function(t){return t("div",{key:this.route.entity.uuid,props:{type:""+this.route.jsonapi.resourceName,uuid:this.route.entity.uuid}},JSON.stringify(this.route))},fetch:async function(t){var e=t.store,r=t.redirect,i=t.route,o=await e.dispatch("druxtRouter/get",i.fullPath);o.redirect&&r(o.redirect)}},n=function(t,e){if(void 0===e&&(e={}),!t)throw new Error("The 'baseURL' parameter is required.");var i={baseURL:t};"object"==typeof e.axios&&(i=Object.assign(i,e.axios)),this.axios=r.create(i),this.setOptions(e)};n.prototype.setOptions=function(t){void 0===t&&(t={}),"function"==typeof t.preprocessEntity&&(this.preprocessEntity=t.preprocessEntity)},n.prototype.get=async function(t){var e=await this.getRoute(t),r=this.getRedirect(t,e);return{entity:await this.getResourceByRoute(e),redirect:r,route:e}},n.prototype.getRedirect=function(t,e){if(Array.isArray(e.redirect)&&void 0!==e.redirect[0].to)return e.redirect[0].to;if(e.isHomePath)return"/"!==t&&"/";if("string"==typeof e.resolved){var r=new i(e.resolved);if(t!==r.pathname)return r.pathname}return!1},n.prototype.getResource=async function(t){var e=t.id,r=t.type,i="/api/"+r.replace("--","/")+"/"+e,o=await this.axios.get(i),n={id:e,type:r,data:o.data};return this.preprocessEntity&&(n._raw=n.data,n.data=await this.preprocessEntity(o)),n},n.prototype.getResourceByRoute=function(t){return this.getResource({id:t.entity.uuid,type:t.jsonapi.resourceName})},n.prototype.getRoute=async function(t){var e="/router/translate-path?path="+t;return(await this.axios.get(e)).data};var u=require("vuex"),s={props:{uuid:{type:String,required:!0},type:{type:String,required:!0}},created:function(){var t=this;void 0===this.entities[this.uuid]&&(this.loading=!0,this.getEntity({id:this.uuid,type:this.type}).then((function(e){t.loading="function"==typeof t.onDruxtRouterLoad&&!!t.onDruxtRouterLoad(e)})))},data:function(){return{loading:!1}},computed:Object.assign({},{entity:function(){return this.entities[this.uuid]},ready:function(){return!this.loading&&!!this.entity}},u.mapState({entities:function(t){return t.druxtRouter.entities}})),methods:Object.assign({},u.mapActions({getEntity:"druxtRouter/getEntity"}))};return t.DruxtRouter=n,t.DruxtRouterComponent=o,t.DruxtRouterEntityMixin=s,t.DruxtRouterStore=function(t){var e=t.store;if(void 0===e)throw new TypeError("Vuex store not found.");e.registerModule("druxtRouter",{namespaced:!0,state:function(){return{entities:{},redirect:!1,route:{},routes:{}}},mutations:{addEntity:function(t,e){void 0!==e.id&&(t.entities[e.id]=e)},setRedirect:function(t,e){t.redirect=e},addRoute:function(t,e){var r=e.path,i=e.route;"string"==typeof r&&void 0!==i&&(t.routes[r]=i)},setRoute:function(t,e){"string"==typeof e&&void 0!==t.routes[e]&&(t.route=t.routes[e])}},actions:{get:async function(t,e){var r=t.commit,i=t.state;if(void 0!==i.routes[e]&&void 0!==i.entities[i.routes[e].entity.uuid]){var o=i.entities[i.routes[e].entity.uuid],n=this.$druxtRouter().getRedirect(e,o),u=i.entities[i.routes[e].entity.uuid];return r("setRoute",e),r("setRedirect",n),{entity:u,redirect:n,route:o}}try{var s=await this.$druxtRouter().get(e),a=s.entity,d=s.redirect,c=s.route;return r("addRoute",{path:e,redirect:d,route:c}),r("setRoute",e),r("setRedirect",d),r("addEntity",a),{entity:a,redirect:d,route:c}}catch(t){if(void 0===t.response)throw t;return this.app.context.error({statusCode:t.response.status,message:t.response.statusText})}},getEntity:async function(t,e){var r=t.commit,i=t.state;if(void 0!==i.entities[e.id])return i.entities[e.id];var o=await this.$druxtRouter().getResource(e);return r("addEntity",o),o}}},{preserveState:Boolean(e.state.druxtRouter)})},t}({},vuex,axios,Url);
var DruxtRouter=function(t,e,r,i,o){"use strict";i=i&&i.hasOwnProperty("default")?i.default:i,o=o&&o.hasOwnProperty("default")?o.default:o;var n={name:"druxt-router",head:function(){return{title:this.title,link:[{rel:"canonical",href:this.canonical||this.route.entity.canonical}],meta:this.metatags||!1}},computed:Object.assign({},{title:function(){return this.route.label}},r.mapState({entity:function(t){return t.druxtRouter.entities[t.druxtRouter.route.entity.uuid]},redirect:function(t){return t.druxtRouter.redirect},route:function(t){return t.druxtRouter.route}})),render:function(t){return t("div",{key:this.route.entity.uuid,props:{type:""+this.route.jsonapi.resourceName,uuid:this.route.entity.uuid}},JSON.stringify(this.route))},fetch:async function(t){var e=t.store,r=t.redirect,i=t.route,o=await e.dispatch("druxtRouter/get",i.fullPath);o.redirect&&r(o.redirect)}},u=function(t,e){if(void 0===e&&(e={}),!t)throw new Error("The 'baseURL' parameter is required.");var r={baseURL:t};"object"==typeof e.axios&&(r=Object.assign(r,e.axios)),this.axios=i.create(r),this.setOptions(e)};u.prototype.setOptions=function(t){void 0===t&&(t={}),"function"==typeof t.preprocessEntity&&(this.preprocessEntity=t.preprocessEntity)},u.prototype.get=async function(t){var e=await this.getRoute(t),r=this.getRedirect(t,e);return{entity:await this.getResourceByRoute(e),redirect:r,route:e}},u.prototype.getRedirect=function(t,e){if(Array.isArray(e.redirect)&&void 0!==e.redirect[0].to)return e.redirect[0].to;if(e.isHomePath)return"/"!==t&&"/";if("string"==typeof e.resolved){var r=new o(e.resolved);if(t!==r.pathname)return r.pathname}return!1},u.prototype.getResource=async function(t){var e=t.id,r=t.type,i="/api/"+r.replace("--","/")+"/"+e,o=await this.axios.get(i),n={id:e,type:r,data:o.data};return this.preprocessEntity&&(n._raw=n.data,n.data=await this.preprocessEntity(o)),n},u.prototype.getResourceByRoute=function(t){return this.getResource({id:t.entity.uuid,type:t.jsonapi.resourceName})},u.prototype.getRoute=async function(t){var e="/router/translate-path?path="+t;return(await this.axios.get(e)).data};var s=require("vuex"),a={props:{uuid:{type:String,required:!0},type:{type:String,required:!0}},created:function(){var t=this;void 0===this.entities[this.uuid]&&(this.loading=!0,this.getEntity({id:this.uuid,type:this.type}).then((function(e){t.loading="function"==typeof t.onDruxtRouterLoad&&!!t.onDruxtRouterLoad(e)})))},data:function(){return{loading:!1}},computed:Object.assign({},{entity:function(){return this.entities[this.uuid]},ready:function(){return!this.loading&&!!this.entity}},s.mapState({entities:function(t){return t.druxtRouter.entities}})),methods:Object.assign({},s.mapActions({getEntity:"druxtRouter/getEntity"}))};return t.DruxtRouter=u,t.DruxtRouterComponent=n,t.DruxtRouterEntityMixin=a,t.DruxtRouterStore=function(t){var e=t.store;if(void 0===e)throw new TypeError("Vuex store not found.");e.registerModule("druxtRouter",{namespaced:!0,state:function(){return{entities:{},redirect:!1,route:{},routes:{}}},mutations:{addEntity:function(t,e){void 0!==e.id&&(t.entities[e.id]=e)},setRedirect:function(t,e){t.redirect=e},addRoute:function(t,e){var r=e.path,i=e.route;"string"==typeof r&&void 0!==i&&(t.routes[r]=i)},setRoute:function(t,e){"string"==typeof e&&void 0!==t.routes[e]&&(t.route=t.routes[e])}},actions:{get:async function(t,e){var r=t.commit,i=t.state;if(void 0!==i.routes[e]&&void 0!==i.entities[i.routes[e].entity.uuid]){var o=i.entities[i.routes[e].entity.uuid],n=this.$druxtRouter().getRedirect(e,o),u=i.entities[i.routes[e].entity.uuid];return r("setRoute",e),r("setRedirect",n),{entity:u,redirect:n,route:o}}try{var s=await this.$druxtRouter().get(e),a=s.entity,d=s.redirect,c=s.route;return r("addRoute",{path:e,redirect:d,route:c}),r("setRoute",e),r("setRedirect",d),r("addEntity",a),{entity:a,redirect:d,route:c}}catch(t){if(void 0===t.response)throw t;return this.app.context.error({statusCode:t.response.status,message:t.response.statusText})}},getEntity:async function(t,e){var r=t.commit,i=t.state;if(void 0!==i.entities[e.id])return i.entities[e.id];var o=await this.$druxtRouter().getResource(e);return r("addEntity",o),o},getRoute:async function(t,e){var r=t.commit,i=t.state;if(void 0!==i.routes[e])return i.routes[e];var o=await this.$druxtRouter().getRoute(e);return r("addRoute",{path:e,route:o}),o}}},{preserveState:Boolean(e.state.druxtRouter)})},t.default=function(t){var r=this;void 0===t&&(t={});var i=Object.assign({},this.options["druxt-router"],t);this.extendRoutes((function(t,e){i.component||(i.component=e(r.options.buildDir,"components/druxt-router.js"),r.addTemplate({src:e(__dirname,"../nuxt/component.js"),fileName:"components/druxt-router.js",options:i})),t.push({name:"druxt-router",path:"*",component:i.component,chunkName:"druxt-router"})})),this.addPlugin({src:e.resolve(__dirname,"../nuxt/plugin.js"),fileName:"druxt-router.js",options:i}),this.addPlugin({src:e.resolve(__dirname,"../nuxt/store.js"),fileName:"store/druxt-router.js",options:i})},t}({},path,vuex,axios,Url);

@@ -1,2 +0,2 @@

'use strict';Object.defineProperty(exports,'__esModule',{value:true});function _interopDefault(e){return(e&&(typeof e==='object')&&'default'in e)?e['default']:e}var vuex$1=require('vuex'),axios=_interopDefault(require('axios')),Url=_interopDefault(require('url-parse'));var DruxtRouterComponent = {
'use strict';Object.defineProperty(exports,'__esModule',{value:true});function _interopDefault(e){return(e&&(typeof e==='object')&&'default'in e)?e['default']:e}var path=require('path'),vuex$1=require('vuex'),axios=_interopDefault(require('axios')),Url=_interopDefault(require('url-parse'));var DruxtRouterComponent = {
name: 'druxt-router',

@@ -280,2 +280,3 @@

actions: {
// @TODO - Change this to use the 'getRoute' and 'getEntity' actions.
get: async function get (ref, path) {

@@ -340,2 +341,17 @@ var commit = ref.commit;

return entity
},
getRoute: async function getRoute (ref, path) {
var commit = ref.commit;
var state = ref.state;
if (typeof state.routes[path] !== 'undefined') {
return state.routes[path]
}
var route = await this.$druxtRouter().getRoute(path);
commit('addRoute', { path: path, route: route });
return route
}

@@ -348,2 +364,45 @@ }

});
};exports.DruxtRouter=DruxtRouter;exports.DruxtRouterComponent=DruxtRouterComponent;exports.DruxtRouterEntityMixin=DruxtRouterEntityMixin;exports.DruxtRouterStore=DruxtRouterStore;
};function index (moduleOptions) {
var this$1 = this;
if ( moduleOptions === void 0 ) moduleOptions = {};
var options = Object.assign({}, this.options['druxt-router'],
moduleOptions);
this.extendRoutes(function (routes, resolve) {
// Only add router component if custom component is undefined.
// @TODO - Validate custom component.
// @TODO - Add test for custom component.
if (!options.component) {
options.component = resolve(this$1.options.buildDir, 'components/druxt-router.js');
this$1.addTemplate({
src: resolve(__dirname, '../nuxt/component.js'),
fileName: 'components/druxt-router.js',
options: options
});
}
// Add Druxt router custom wildcard route.
routes.push({
name: 'druxt-router',
path: '*',
component: options.component,
chunkName: 'druxt-router'
});
});
// Add plugin.
this.addPlugin({
src: path.resolve(__dirname, '../nuxt/plugin.js'),
fileName: 'druxt-router.js',
options: options
});
// Add Vuex plugin.
// @TODO - Ensure Vuex store is available.
this.addPlugin({
src: path.resolve(__dirname, '../nuxt/store.js'),
fileName: 'store/druxt-router.js',
options: options
});
}exports.DruxtRouter=DruxtRouter;exports.DruxtRouterComponent=DruxtRouterComponent;exports.DruxtRouterEntityMixin=DruxtRouterEntityMixin;exports.DruxtRouterStore=DruxtRouterStore;exports.default=index;
{
"name": "druxt-router",
"version": "0.6.0",
"version": "0.7.0",
"description": "Provides a Nuxt <-> Drupal router.",
"files": [
"dist",
"nuxt/index.js",
"nuxt/templates"
"nuxt"
],

@@ -10,0 +9,0 @@ "main": "dist/druxt-router.ssr.js",

@@ -21,3 +21,3 @@ # Druxt router

...
['druxt-router/nuxt', {
['druxt-router', {
baseUrl: 'https://example.com',

@@ -24,0 +24,0 @@ }]

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc