From 80b1be89f59e38cf071cfef47f6053739898ae27 Mon Sep 17 00:00:00 2001 From: Cagatay Civici Date: Thu, 10 Dec 2020 11:03:08 +0300 Subject: [PATCH] Export locale config and typescript support --- exports/config.d.ts | 1 + exports/config.js | 2 ++ src/components/config/PrimeVue.d.ts | 38 ++++++++++++++++++++++++++++ src/components/config/PrimeVue.js | 13 +++++++++- src/components/config/usePrimeVue.js | 12 --------- 5 files changed, 53 insertions(+), 13 deletions(-) create mode 100644 exports/config.d.ts create mode 100644 exports/config.js create mode 100644 src/components/config/PrimeVue.d.ts delete mode 100644 src/components/config/usePrimeVue.js diff --git a/exports/config.d.ts b/exports/config.d.ts new file mode 100644 index 000000000..dd165821e --- /dev/null +++ b/exports/config.d.ts @@ -0,0 +1 @@ +export * from './components/config/PrimeVue'; \ No newline at end of file diff --git a/exports/config.js b/exports/config.js new file mode 100644 index 000000000..6bb30308e --- /dev/null +++ b/exports/config.js @@ -0,0 +1,2 @@ +'use strict'; +module.exports = require('./components/config/PrimeVue.js'); \ No newline at end of file diff --git a/src/components/config/PrimeVue.d.ts b/src/components/config/PrimeVue.d.ts new file mode 100644 index 000000000..024319b85 --- /dev/null +++ b/src/components/config/PrimeVue.d.ts @@ -0,0 +1,38 @@ +import Vue, { PluginFunction } from 'vue'; + +interface PrimeVueConfiguration { + ripple?: boolean; + locale?: PrimeVueLocaleOptions; +} + +interface PrimeVueLocaleOptions { + accept?: string; + reject?: string; + choose?: string; + upload?: string; + cancel?: string; + dayNames: string[]; + dayNamesShort: string[]; + dayNamesMin: string[]; + monthNames: string[]; + monthNamesShort: string[]; + today?: string; + clear?: string; + weekHeader?: string; + firstDayOfWeek?: number; + dateFormat?: string; + weak?: string; + medium?: string; + strong?: string; + passwordPrompt?: string; +} + +export declare function usePrimeVue(): PrimeVueConfiguration; + +export const install: PluginFunction<{}>; + +declare module 'vue/types/vue' { + interface Vue { + $primevue: PrimeVueConfiguration; + } +} \ No newline at end of file diff --git a/src/components/config/PrimeVue.js b/src/components/config/PrimeVue.js index a40683e87..4b2f9e799 100644 --- a/src/components/config/PrimeVue.js +++ b/src/components/config/PrimeVue.js @@ -1,5 +1,5 @@ import {PrimeVueSymbol} from './usePrimeVue'; -import {reactive} from 'vue'; +import {reactive,inject} from 'vue'; const defaultOptions = { ripple: false, @@ -26,6 +26,17 @@ const defaultOptions = { } }; +const PrimeVueSymbol = Symbol(); + +export function usePrimeVue() { + const PrimeVue = inject(PrimeVueSymbol); + if (!PrimeVue) { + throw new Error('PrimeVue is not installed!'); + } + + return PrimeVue; +} + export default { install: (app, options) => { let configOptions = options ? {...defaultOptions, ...options} : {...defaultOptions}; diff --git a/src/components/config/usePrimeVue.js b/src/components/config/usePrimeVue.js deleted file mode 100644 index 093f575ae..000000000 --- a/src/components/config/usePrimeVue.js +++ /dev/null @@ -1,12 +0,0 @@ -import { inject } from 'vue'; - -export const PrimeVueSymbol = Symbol(); - -export function usePrimeVue() { - const PrimeVue = inject(PrimeVueSymbol); - if (!PrimeVue) { - throw new Error('PrimeVue is not installed!'); - } - - return PrimeVue; -} \ No newline at end of file