Skip to content

Commit

Permalink
types: update types for v2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
pimlie committed Oct 9, 2019
1 parent 2231ec1 commit dae968b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 15 deletions.
6 changes: 3 additions & 3 deletions docs/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ Calling [`inject`](#meta-inject) will return an object on which you can call the

### head <Badge text="v2.3+"/>
- arguments
- ln (type `boolean`, default: `true`)
- ln (type `boolean`, default: `false`)

This is a convenience method which will retrieve the template string which should be added to the `head`.

Expand All @@ -737,15 +737,15 @@ By passing `ln = true` a line break will be added after each element. This could

### bodyPrepend <Badge text="v2.3+"/>
- arguments
- ln (type `boolean`, default: `true`)
- ln (type `boolean`, default: `false`)

This is a convenience method which will retrieve the template string which should be prepended to the body, i.e. listed just after `<body>`.

Elements will be printed in the same order as the menu below.

### bodyAppend <Badge text="v2.3+"/>
- arguments
- ln (type `boolean`, default: `true`)
- ln (type `boolean`, default: `false`)

This is a convenience method which will retrieve the template string which should be appended to the body, i.e. listed just before `</body>`.

Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default VueMeta
export {
VueMetaOptions,
VueMetaPlugin,
VueMetaApp,
MetaInfo,
MetaInfoSSR,
AttributeProperty,
Expand Down
19 changes: 18 additions & 1 deletion types/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import Vue, { ComponentOptions } from 'vue'
import VueMeta, { VueMetaPlugin, VueMetaOptions, MetaInfo, MetaInfoSSR } from '../index'
import VueMeta, {
VueMetaPlugin,
VueMetaOptions,
VueMetaApp,
MetaInfo,
MetaInfoSSR,
MetaPropertyCharset
} from '../index'

Vue.use(VueMeta, {
keyName: 'head'
Expand Down Expand Up @@ -67,6 +74,16 @@ if (metaDataSSR.script) {
metaDataSSR.script.text({ body: true })
}

// add app
const customApp: VueMetaApp = $meta.addApp('custom-app')

const metaCharset: MetaPropertyCharset = { charset: 'utf-8' }
const customAppInfo: MetaInfo = {
meta: [metaCharset]
}

customApp.set(customAppInfo)

// pausing & resuming
let resume
resume = $meta.pause()
Expand Down
43 changes: 32 additions & 11 deletions types/vue-meta.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ type Component = ComponentOptions<Vue> | typeof Vue
type CallbackFn = () => void
type elements = HTMLElement[]

export interface VueMetaOptions {
export interface VueMetaOptionsRuntime {
refreshOnceOnNavigation?: boolean
debounceWait?: number
waitOnDestroyed?: boolean
}

export interface VueMetaOptions extends VueMetaOptionsRuntime {
keyName: string, // the component option name that vue-meta looks for meta info on.
attribute: string, // the attribute name vue-meta adds to the tags it observes
ssrAppId: string, // the app id used for ssr app
ssrAttribute: string, // the attribute name that lets vue-meta know that meta info has already been server-rendered
tagIDKeyName: string // the property name that vue-meta uses to determine whether to overwrite or append a tag
refreshOnceOnNavigation: boolean
}

export declare class VueMeta {
Expand All @@ -21,17 +26,26 @@ export declare class VueMeta {
static generate(metaInfo: MetaInfo, options?: Object): MetaInfoSSR
}

interface RefreshedTags {
addedTags: elements
removedTags: elements
}

interface Refreshed {
vm: Component,
metaInfo: MetaInfo,
tags: {
addedTags: elements
removedTags: elements
}
tags: RefreshedTags
}

interface VueMetaApp {
set(metaInfo: MetaInfo): void | RefreshedTags
remove(): void
}

export interface VueMetaPlugin {
getOptions(): VueMetaOptions
setOptions(runtimeOptions: VueMetaOptionsRuntime): VueMetaOptions
addApp(appName: string): VueMetaApp
refresh(): Refreshed
inject(): MetaInfoSSR
pause(refresh: true): () => Refreshed
Expand Down Expand Up @@ -188,6 +202,10 @@ interface ToTextBooleanArg {
text(addSrrAttribute?: boolean): string
}

interface AddLineBreakOption {
ln: boolean
}

interface ToBodyTextOption {
body: boolean
}
Expand All @@ -197,18 +215,21 @@ interface ToPbodyTextOption {
}

interface ToBodyText {
text(options?: (ToBodyTextOption | ToPbodyTextOption)): string
text(options?: (ToBodyTextOption | ToPbodyTextOption | AddLineBreakOption)): string
}

export interface MetaInfoSSR {
head(ln?: boolean): string
bodyPrepend(ln?: boolean): string
bodyAppend(ln?: boolean): string
title?: ToText
htmlAttrs?: ToTextBooleanArg
headAttrs?: ToText
bodyAttrs?: ToText
base?: ToText
meta?: ToText
link?: ToText
style?: ToText
base?: ToBodyText
meta?: ToBodyText
link?: ToBodyText
style?: ToBodyText
script?: ToBodyText
noscript?: ToBodyText
}

0 comments on commit dae968b

Please sign in to comment.