@stencil/vue-output-target
Advanced tools
Comparing version 0.2.2 to 0.2.3-0
import { ComponentCompilerMeta } from '@stencil/core/internal'; | ||
import { ComponentModelConfig } from './types'; | ||
export declare const createComponentDefinition: (importTypes: string, componentModelConfig: ComponentModelConfig[] | undefined, routerLinkConfig: string[] | undefined) => (cmpMeta: Pick<ComponentCompilerMeta, 'properties' | 'tagName' | 'methods' | 'events'>) => string; | ||
export declare const createComponentDefinition: (importTypes: string, componentModelConfig: ComponentModelConfig[] | undefined) => (cmpMeta: Pick<ComponentCompilerMeta, 'properties' | 'tagName' | 'methods' | 'events'>) => string; |
import { dashToPascalCase } from './utils'; | ||
export const createComponentDefinition = (importTypes, componentModelConfig, routerLinkConfig) => (cmpMeta) => { | ||
export const createComponentDefinition = (importTypes, componentModelConfig) => (cmpMeta) => { | ||
const tagNameAsPascal = dashToPascalCase(cmpMeta.tagName); | ||
@@ -23,3 +23,2 @@ let props = []; | ||
const findModel = componentModelConfig && componentModelConfig.find(config => config.elements.includes(cmpMeta.tagName)); | ||
const findRouterLink = routerLinkConfig && routerLinkConfig.find(config => config.includes(cmpMeta.tagName)); | ||
if (findModel) { | ||
@@ -29,5 +28,2 @@ options.modelProp = findModel.targetAttr; | ||
} | ||
if (findRouterLink) { | ||
options.routerLinkComponent = true; | ||
} | ||
if (Object.keys(options).length > 0) { | ||
@@ -34,0 +30,0 @@ templateString += `,\n`; |
@@ -90,3 +90,3 @@ 'use strict'; | ||
const createComponentDefinition = (importTypes, componentModelConfig, routerLinkConfig) => (cmpMeta) => { | ||
const createComponentDefinition = (importTypes, componentModelConfig) => (cmpMeta) => { | ||
const tagNameAsPascal = dashToPascalCase(cmpMeta.tagName); | ||
@@ -112,3 +112,2 @@ let props = []; | ||
const findModel = componentModelConfig && componentModelConfig.find(config => config.elements.includes(cmpMeta.tagName)); | ||
const findRouterLink = routerLinkConfig && routerLinkConfig.find(config => config.includes(cmpMeta.tagName)); | ||
if (findModel) { | ||
@@ -118,5 +117,2 @@ options.modelProp = findModel.targetAttr; | ||
} | ||
if (findRouterLink) { | ||
options.routerLinkComponent = true; | ||
} | ||
if (Object.keys(options).length > 0) { | ||
@@ -169,3 +165,3 @@ templateString += `,\n`; | ||
components | ||
.map(createComponentDefinition(IMPORT_TYPES, outputTarget.componentModels, outputTarget.routerLinkComponents)) | ||
.map(createComponentDefinition(IMPORT_TYPES, outputTarget.componentModels)) | ||
.join('\n'), | ||
@@ -223,3 +219,3 @@ ]; | ||
var _a, _b; | ||
const results = Object.assign(Object.assign({}, outputTarget), { excludeComponents: outputTarget.excludeComponents || [], componentModels: outputTarget.componentModels || [], includePolyfills: (_a = outputTarget.includePolyfills) !== null && _a !== void 0 ? _a : true, includeDefineCustomElements: (_b = outputTarget.includeDefineCustomElements) !== null && _b !== void 0 ? _b : true, routerLinkComponents: outputTarget.routerLinkComponents || [] }); | ||
const results = Object.assign(Object.assign({}, outputTarget), { excludeComponents: outputTarget.excludeComponents || [], componentModels: outputTarget.componentModels || [], includePolyfills: (_a = outputTarget.includePolyfills) !== null && _a !== void 0 ? _a : true, includeDefineCustomElements: (_b = outputTarget.includeDefineCustomElements) !== null && _b !== void 0 ? _b : true }); | ||
if (config.rootDir == null) { | ||
@@ -226,0 +222,0 @@ throw new Error('rootDir is not set and it should be set by stencil itself'); |
@@ -81,3 +81,3 @@ import path from 'path'; | ||
const createComponentDefinition = (importTypes, componentModelConfig, routerLinkConfig) => (cmpMeta) => { | ||
const createComponentDefinition = (importTypes, componentModelConfig) => (cmpMeta) => { | ||
const tagNameAsPascal = dashToPascalCase(cmpMeta.tagName); | ||
@@ -103,3 +103,2 @@ let props = []; | ||
const findModel = componentModelConfig && componentModelConfig.find(config => config.elements.includes(cmpMeta.tagName)); | ||
const findRouterLink = routerLinkConfig && routerLinkConfig.find(config => config.includes(cmpMeta.tagName)); | ||
if (findModel) { | ||
@@ -109,5 +108,2 @@ options.modelProp = findModel.targetAttr; | ||
} | ||
if (findRouterLink) { | ||
options.routerLinkComponent = true; | ||
} | ||
if (Object.keys(options).length > 0) { | ||
@@ -160,3 +156,3 @@ templateString += `,\n`; | ||
components | ||
.map(createComponentDefinition(IMPORT_TYPES, outputTarget.componentModels, outputTarget.routerLinkComponents)) | ||
.map(createComponentDefinition(IMPORT_TYPES, outputTarget.componentModels)) | ||
.join('\n'), | ||
@@ -214,3 +210,3 @@ ]; | ||
var _a, _b; | ||
const results = Object.assign(Object.assign({}, outputTarget), { excludeComponents: outputTarget.excludeComponents || [], componentModels: outputTarget.componentModels || [], includePolyfills: (_a = outputTarget.includePolyfills) !== null && _a !== void 0 ? _a : true, includeDefineCustomElements: (_b = outputTarget.includeDefineCustomElements) !== null && _b !== void 0 ? _b : true, routerLinkComponents: outputTarget.routerLinkComponents || [] }); | ||
const results = Object.assign(Object.assign({}, outputTarget), { excludeComponents: outputTarget.excludeComponents || [], componentModels: outputTarget.componentModels || [], includePolyfills: (_a = outputTarget.includePolyfills) !== null && _a !== void 0 ? _a : true, includeDefineCustomElements: (_b = outputTarget.includeDefineCustomElements) !== null && _b !== void 0 ? _b : true }); | ||
if (config.rootDir == null) { | ||
@@ -217,0 +213,0 @@ throw new Error('rootDir is not set and it should be set by stencil itself'); |
@@ -43,3 +43,3 @@ import path from 'path'; | ||
components | ||
.map(createComponentDefinition(IMPORT_TYPES, outputTarget.componentModels, outputTarget.routerLinkComponents)) | ||
.map(createComponentDefinition(IMPORT_TYPES, outputTarget.componentModels)) | ||
.join('\n'), | ||
@@ -46,0 +46,0 @@ ]; |
@@ -18,3 +18,3 @@ import { normalizePath } from './utils'; | ||
var _a, _b; | ||
const results = Object.assign(Object.assign({}, outputTarget), { excludeComponents: outputTarget.excludeComponents || [], componentModels: outputTarget.componentModels || [], includePolyfills: (_a = outputTarget.includePolyfills) !== null && _a !== void 0 ? _a : true, includeDefineCustomElements: (_b = outputTarget.includeDefineCustomElements) !== null && _b !== void 0 ? _b : true, routerLinkComponents: outputTarget.routerLinkComponents || [] }); | ||
const results = Object.assign(Object.assign({}, outputTarget), { excludeComponents: outputTarget.excludeComponents || [], componentModels: outputTarget.componentModels || [], includePolyfills: (_a = outputTarget.includePolyfills) !== null && _a !== void 0 ? _a : true, includeDefineCustomElements: (_b = outputTarget.includeDefineCustomElements) !== null && _b !== void 0 ? _b : true }); | ||
if (config.rootDir == null) { | ||
@@ -21,0 +21,0 @@ throw new Error('rootDir is not set and it should be set by stencil itself'); |
@@ -9,3 +9,2 @@ export interface OutputTargetVue { | ||
includeDefineCustomElements?: boolean; | ||
routerLinkComponents?: string[]; | ||
} | ||
@@ -15,3 +14,2 @@ export interface ComponentOptions { | ||
modelUpdateEvent?: string; | ||
routerLinkComponent?: boolean; | ||
} | ||
@@ -18,0 +16,0 @@ export interface ComponentModelConfig { |
{ | ||
"name": "@stencil/vue-output-target", | ||
"version": "0.2.2", | ||
"version": "0.2.3-0", | ||
"description": "Vue output target for @stencil/core components.", | ||
@@ -35,3 +35,3 @@ "main": "dist/index.cjs.js", | ||
"peerDependencies": { | ||
"@stencil/core": ">=1.8.0 || ^2.0.0" | ||
"@stencil/core": ">=1.8.0" | ||
}, | ||
@@ -38,0 +38,0 @@ "jest": { |
@@ -20,3 +20,2 @@ import { VNode, defineComponent, getCurrentInstance, h, inject, ref, Ref } from 'vue'; | ||
modelUpdateEvent?: string; | ||
routerLinkComponent?: boolean; | ||
} | ||
@@ -45,3 +44,3 @@ | ||
export const defineContainer = <Props>(name: string, componentProps: string[] = [], componentOptions: ComponentOptions = {}) => { | ||
const { modelProp, modelUpdateEvent, routerLinkComponent } = componentOptions; | ||
const { modelProp, modelUpdateEvent } = componentOptions; | ||
@@ -65,20 +64,19 @@ /** | ||
let handleClick: (ev: Event) => void; | ||
if (routerLinkComponent) { | ||
const currentInstance = getCurrentInstance(); | ||
const hasRouter = currentInstance?.appContext?.provides[NAV_MANAGER]; | ||
const navManager: NavManager | undefined = hasRouter ? inject(NAV_MANAGER) : undefined; | ||
handleClick = (ev: Event) => { | ||
const routerProps = Object.keys(props).filter(p => p.startsWith(ROUTER_PROP_REFIX)); | ||
if (routerProps.length === 0) return; | ||
const currentInstance = getCurrentInstance(); | ||
const hasRouter = currentInstance?.appContext?.provides[NAV_MANAGER]; | ||
const navManager: NavManager | undefined = hasRouter ? inject(NAV_MANAGER) : undefined; | ||
const handleRouterLink = (ev: Event) => { | ||
const { routerLink } = props; | ||
if (!routerLink) return; | ||
if (navManager !== undefined) { | ||
let navigationPayload: any = { event: ev }; | ||
routerProps.forEach(prop => { | ||
navigationPayload[prop] = (props as any)[prop]; | ||
}); | ||
navManager.navigate(navigationPayload); | ||
} else { | ||
console.warn('Tried to navigate, but no router was found. Make sure you have mounted Vue Router.'); | ||
} | ||
const routerProps = Object.keys(props).filter(p => p.startsWith(ROUTER_PROP_REFIX)); | ||
if (navManager !== undefined) { | ||
let navigationPayload: any = { event: ev }; | ||
routerProps.forEach(prop => { | ||
navigationPayload[prop] = (props as any)[prop]; | ||
}); | ||
navManager.navigate(navigationPayload); | ||
} else { | ||
console.warn('Tried to navigate, but no router was found. Make sure you have mounted Vue Router.'); | ||
} | ||
@@ -92,2 +90,12 @@ } | ||
const oldClick = (props as any).onClick; | ||
const handleClick = (ev: Event) => { | ||
if (oldClick !== undefined) { | ||
oldClick(ev); | ||
} | ||
if (!ev.defaultPrevented) { | ||
handleRouterLink(ev); | ||
} | ||
} | ||
let propsToAdd = { | ||
@@ -97,16 +105,6 @@ ...props, | ||
class: getElementClasses(containerRef, classes), | ||
onClick: (routerLinkComponent) ? handleClick : (props as any).onClick, | ||
onClick: handleClick, | ||
onVnodeBeforeMount: (modelUpdateEvent) ? onVnodeBeforeMount : undefined | ||
}; | ||
if ((props as any).onClick) { | ||
const oldClick = (props as any).onClick; | ||
propsToAdd.onClick = (ev: Event) => { | ||
oldClick(ev); | ||
if (!ev.defaultPrevented) { | ||
handleClick(ev); | ||
} | ||
}; | ||
} | ||
if (modelProp) { | ||
@@ -129,7 +127,5 @@ propsToAdd = { | ||
} | ||
if (routerLinkComponent) { | ||
Container.props.push(ROUTER_LINK_VALUE); | ||
} | ||
Container.props.push(ROUTER_LINK_VALUE); | ||
return Container; | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37744
816