@onu-ui/utils
Advanced tools
Comparing version 1.0.10 to 1.0.11
import * as vue from 'vue'; | ||
import { Plugin, AppContext, ComponentPublicInstance, VNode, VNodeTypes, Component } from 'vue'; | ||
import { Plugin, AppContext, Ref, ComponentPublicInstance, VNode, VNodeTypes, Component, App } from 'vue'; | ||
@@ -8,2 +8,3 @@ declare type SFCWithInstall<T> = T & Plugin; | ||
}; | ||
declare type MaybeRef<T> = T | Ref<T>; | ||
@@ -19,2 +20,7 @@ declare const withInstall: <T, E extends Record<string, any>>(main: T, extra?: E | undefined) => SFCWithInstall<T> & E; | ||
declare const generateId: () => number; | ||
/** | ||
* Merge object from T & U | ||
*/ | ||
declare function mergeObjects<T extends Record<string, any>, U extends Record<string, any>>(sourceObj: T, targetObj: U): Record<string, any>; | ||
declare function deepGet(target: any, path: string | string[], defaultValue: any): any; | ||
@@ -37,3 +43,3 @@ declare const toTypeString: (v: any) => string; | ||
declare const isValue: (val: any) => val is boolean; | ||
declare const isComponentInstance: (val: any) => val is ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, vue.ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>>; | ||
declare const isComponentInstance: (val: any) => val is ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, vue.ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string>, {}>; | ||
declare const isComponent: (vn: VNode, type?: VNodeTypes) => type is Component<any, any, any, vue.ComputedOptions, vue.MethodOptions>; | ||
@@ -82,2 +88,64 @@ declare const isElement: (vn: VNode) => boolean; | ||
export { generateId, getChildrenArray, getElement, getFirstElementFromChildren, getFirstElementFromVNode, hash, isArray, isArrayChildren, isBoolean, isComponent, isComponentInstance, isDate, isDef, isElement, isEmptyChildren, isFunction, isMap, isNumber, isObject, isPlainObject, isPromise, isRegExp, isServerRendering, isSet, isSlotsChildren, isString, isSymbol, isText, isValue, mergeFirstChild, off, on, querySelector, toTypeString, withInstall, withInstallFunction }; | ||
declare const _default$1: { | ||
name: string; | ||
locales: { | ||
empty: { | ||
emptyText: string; | ||
}; | ||
}; | ||
}; | ||
declare const _default: { | ||
name: string; | ||
locales: { | ||
empty: { | ||
emptyText: string; | ||
}; | ||
}; | ||
}; | ||
interface TranslatePair { | ||
[key: string]: string | string[] | TranslatePair; | ||
} | ||
interface language { | ||
name: string; | ||
locales: TranslatePair; | ||
} | ||
interface InstallOptions { | ||
prefix?: string; | ||
namespace?: MaybeRef<string>; | ||
locale?: MaybeRef<language>; | ||
zIndex?: MaybeRef<number>; | ||
size?: MaybeRef<string>; | ||
} | ||
declare const configProviderContextKey = "__onu_config_provider"; | ||
/** | ||
* 获取全局配置 Hooks | ||
* @param key | ||
* @param defaultValue | ||
*/ | ||
declare function useGlobalConfig<T extends keyof InstallOptions, U extends InstallOptions[T]>(key: T, defaultValue?: U): Ref<Exclude<InstallOptions[T], undefined | U>>; | ||
declare function useGlobalConfig(): Ref<InstallOptions>; | ||
/** | ||
* 注入配置 | ||
* @param config | ||
* @param app | ||
* @param global | ||
*/ | ||
declare function provideGlobalConfig(config: MaybeRef<InstallOptions>, app?: App, global?: boolean): vue.ComputedRef<Record<string, any>> | undefined; | ||
declare type OnuTranslatorOption = Record<string, string | number>; | ||
declare type OnuTranslator = (path: string, option?: OnuTranslatorOption) => string; | ||
interface OnuLocaleContext { | ||
locale: Ref<language>; | ||
lang: Ref<string>; | ||
t: OnuTranslator; | ||
} | ||
declare const translate: (path: string, option: OnuTranslatorOption | undefined, locale: language) => string; | ||
declare const buildTranslator: (locale: MaybeRef<language>) => OnuTranslator; | ||
declare const buildLocaleContext: (locale: MaybeRef<language>) => OnuLocaleContext; | ||
declare function useLocale(): OnuLocaleContext; | ||
export { InstallOptions, OnuLocaleContext, OnuTranslator, OnuTranslatorOption, TranslatePair, buildLocaleContext, buildTranslator, configProviderContextKey, deepGet, _default$1 as en, generateId, getChildrenArray, getElement, getFirstElementFromChildren, getFirstElementFromVNode, hash, isArray, isArrayChildren, isBoolean, isComponent, isComponentInstance, isDate, isDef, isElement, isEmptyChildren, isFunction, isMap, isNumber, isObject, isPlainObject, isPromise, isRegExp, isServerRendering, isSet, isSlotsChildren, isString, isSymbol, isText, isValue, language, mergeFirstChild, mergeObjects, off, on, provideGlobalConfig, querySelector, toTypeString, translate, useGlobalConfig, useLocale, withInstall, withInstallFunction, _default as zhCn }; |
@@ -1,1 +0,1 @@ | ||
"use strict";var a=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var S=(e,t)=>{for(var n in t)a(e,n,{get:t[n],enumerable:!0})},F=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of L(t))!M.call(e,r)&&r!==n&&a(e,r,{get:()=>t[r],enumerable:!(o=N(t,r))||o.enumerable});return e};var V=e=>F(a({},"__esModule",{value:!0}),e);var Q={};S(Q,{generateId:()=>I,getChildrenArray:()=>m,getElement:()=>z,getFirstElementFromChildren:()=>g,getFirstElementFromVNode:()=>y,hash:()=>v,isArray:()=>d,isArrayChildren:()=>f,isBoolean:()=>j,isComponent:()=>l,isComponentInstance:()=>$,isDate:()=>W,isDef:()=>w,isElement:()=>c,isEmptyChildren:()=>Y,isFunction:()=>s,isMap:()=>k,isNumber:()=>A,isObject:()=>h,isPlainObject:()=>R,isPromise:()=>_,isRegExp:()=>B,isServerRendering:()=>p,isSet:()=>D,isSlotsChildren:()=>X,isString:()=>u,isSymbol:()=>K,isText:()=>q,isValue:()=>P,mergeFirstChild:()=>b,off:()=>J,on:()=>G,querySelector:()=>C,toTypeString:()=>i,withInstall:()=>H,withInstallFunction:()=>O});module.exports=V(Q);var H=(e,t)=>{if(e.install=n=>{for(let o of[e,...Object.values(t??{})])n.component(o.name,o)},t)for(let[n,o]of Object.entries(t))e[n]=o;return e},O=(e,t)=>(e.install=n=>{e._context=n._context,n.config.globalProperties[t]=e},e);function v(e){let t,n,o=2166136261;for(t=0,n=e.length;t<n;t++)o^=e.charCodeAt(t),o+=(o<<1)+(o<<4)+(o<<7)+(o<<8)+(o<<24);return`00000${(o>>>0).toString(36)}`.slice(-6)}var I=()=>Math.floor(Math.random()*1e4);var i=e=>Object.prototype.toString.call(e),w=e=>typeof e<"u",j=e=>typeof e=="boolean",s=e=>typeof e=="function",A=e=>typeof e=="number",u=e=>typeof e=="string",h=e=>e!==null&&typeof e=="object",R=e=>i(e)==="[object Object]",d=Array.isArray,k=e=>i(e)==="[object Map]",D=e=>i(e)==="[object Set]",W=e=>e instanceof Date,B=e=>e instanceof RegExp,K=e=>typeof e=="symbol",_=e=>h(e)&&s(e.then)&&s(e.catch),P=e=>e!=null,$=e=>(e==null?void 0:e.$)!==void 0,l=(e,t)=>Boolean(e&&e.shapeFlag&6),c=e=>Boolean(e&&e.shapeFlag&1),q=(e,t)=>Boolean(e&&e.shapeFlag&8),X=(e,t)=>Boolean(e&&e.shapeFlag&32),f=(e,t)=>Boolean(e&&e.shapeFlag&16);var T=require("vue");var m=e=>{if(f(e,e.children))return e.children;if(d(e))return e},g=e=>{if(e&&e.length>0)for(let t of e){let n=y(t);if(n)return n}},y=e=>{var t;if(c(e))return e.el;if(l(e)){if(e.el.nodeType===1)return e.el;if((t=e.component)!=null&&t.subTree){let n=y(e.component.subTree);if(n)return n}}else{let n=m(e);return g(n)}},b=(e,t)=>{if(e&&e.length>0)for(let n=0;n<e.length;n++){let o=e[n];if(c(o)||l(o)){let E=s(t)?t(o):t;return e[n]=(0,T.cloneVNode)(o,E,!0),!0}let r=m(o);if(r&&r.length>0&&b(r,t))return!0}return!1},Y=e=>{if(!e)return!0;for(let t of e)if(t.children)return!1;return!0};var p=(()=>{try{return!(typeof window<"u"&&document!==void 0)}catch{return!0}})(),x=()=>{},C=(e,t)=>p?x():(t??document).querySelector(e)??void 0,z=(e,t)=>{if(u(e)){let n=e[0]==="#"?`[id='${e.slice(1)}']`:e;return C(n,t)}return e},G=(()=>p?x:(e,t,n,o=!1)=>{e.addEventListener(t,n,o)})(),J=(()=>p?x:(e,t,n,o=!1)=>{e.removeEventListener(t,n,o)})();0&&(module.exports={generateId,getChildrenArray,getElement,getFirstElementFromChildren,getFirstElementFromVNode,hash,isArray,isArrayChildren,isBoolean,isComponent,isComponentInstance,isDate,isDef,isElement,isEmptyChildren,isFunction,isMap,isNumber,isObject,isPlainObject,isPromise,isRegExp,isServerRendering,isSet,isSlotsChildren,isString,isSymbol,isText,isValue,mergeFirstChild,off,on,querySelector,toTypeString,withInstall,withInstallFunction}); | ||
"use strict";var x=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var D=(e,t)=>{for(var o in t)x(e,o,{get:t[o],enumerable:!0})},W=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of P(t))!_.call(e,r)&&r!==o&&x(e,r,{get:()=>t[r],enumerable:!(n=k(t,r))||n.enumerable});return e};var K=e=>W(x({},"__esModule",{value:!0}),e);var de={};D(de,{buildLocaleContext:()=>j,buildTranslator:()=>H,configProviderContextKey:()=>a,deepGet:()=>b,en:()=>m,generateId:()=>U,getChildrenArray:()=>O,getElement:()=>ae,getFirstElementFromChildren:()=>S,getFirstElementFromVNode:()=>v,hash:()=>$,isArray:()=>h,isArrayChildren:()=>C,isBoolean:()=>q,isComponent:()=>f,isComponentInstance:()=>re,isDate:()=>Z,isDef:()=>z,isElement:()=>u,isEmptyChildren:()=>le,isFunction:()=>p,isMap:()=>J,isNumber:()=>X,isObject:()=>N,isPlainObject:()=>Y,isPromise:()=>ne,isRegExp:()=>ee,isServerRendering:()=>d,isSet:()=>Q,isSlotsChildren:()=>ie,isString:()=>E,isSymbol:()=>te,isText:()=>se,isValue:()=>oe,mergeFirstChild:()=>F,mergeObjects:()=>T,off:()=>ce,on:()=>pe,provideGlobalConfig:()=>fe,querySelector:()=>w,toTypeString:()=>c,translate:()=>A,useGlobalConfig:()=>y,useLocale:()=>ue,withInstall:()=>G,withInstallFunction:()=>B,zhCn:()=>V});module.exports=K(de);var G=(e,t)=>{if(e.install=o=>{for(let n of[e,...Object.values(t??{})])o.component(n.name,n)},t)for(let[o,n]of Object.entries(t))e[o]=n;return e},B=(e,t)=>(e.install=o=>{e._context=o._context,o.config.globalProperties[t]=e},e);function $(e){let t,o,n=2166136261;for(t=0,o=e.length;t<o;t++)n^=e.charCodeAt(t),n+=(n<<1)+(n<<4)+(n<<7)+(n<<8)+(n<<24);return`00000${(n>>>0).toString(36)}`.slice(-6)}var U=()=>Math.floor(Math.random()*1e4);function T(e,t){let o=[...new Set([...Object.keys(e),...Object.keys(t)])],n={};return o.forEach(r=>{n[r]=t[r]??e[r]}),n}function b(e,t,o){if(!Array.isArray(t)&&typeof t!="string")throw new TypeError("path must be string or array");if(e===null)return o;let n=t;typeof t=="string"&&(t=t.replace(/\[(\w*)\]/g,".$1"),t=t.startsWith(".")?t.slice(1):t,n=t.split("."));let r=0,l;for(;e!==null&&r<n.length;)l=n[r++],e=e[l];return r===n.length?e:o}var c=e=>Object.prototype.toString.call(e),z=e=>typeof e<"u",q=e=>typeof e=="boolean",p=e=>typeof e=="function",X=e=>typeof e=="number",E=e=>typeof e=="string",N=e=>e!==null&&typeof e=="object",Y=e=>c(e)==="[object Object]",h=Array.isArray,J=e=>c(e)==="[object Map]",Q=e=>c(e)==="[object Set]",Z=e=>e instanceof Date,ee=e=>e instanceof RegExp,te=e=>typeof e=="symbol",ne=e=>N(e)&&p(e.then)&&p(e.catch),oe=e=>e!=null,re=e=>e?.$!==void 0,f=(e,t)=>Boolean(e&&e.shapeFlag&6),u=e=>Boolean(e&&e.shapeFlag&1),se=(e,t)=>Boolean(e&&e.shapeFlag&8),ie=(e,t)=>Boolean(e&&e.shapeFlag&32),C=(e,t)=>Boolean(e&&e.shapeFlag&16);var I=require("vue");var O=e=>{if(C(e,e.children))return e.children;if(h(e))return e},S=e=>{if(e&&e.length>0)for(let t of e){let o=v(t);if(o)return o}},v=e=>{if(u(e))return e.el;if(f(e)){if(e.el.nodeType===1)return e.el;if(e.component?.subTree){let t=v(e.component.subTree);if(t)return t}}else{let t=O(e);return S(t)}},F=(e,t)=>{if(e&&e.length>0)for(let o=0;o<e.length;o++){let n=e[o];if(u(n)||f(n)){let l=p(t)?t(n):t;return e[o]=(0,I.cloneVNode)(n,l,!0),!0}let r=O(n);if(r&&r.length>0&&F(r,t))return!0}return!1},le=e=>{if(!e)return!0;for(let t of e)if(t.children)return!1;return!0};var d=(()=>{try{return!(typeof window<"u"&&document!==void 0)}catch{return!0}})(),R=()=>{},w=(e,t)=>d?R():(t??document).querySelector(e)??void 0,ae=(e,t)=>{if(E(e)){let o=e[0]==="#"?`[id='${e.slice(1)}']`:e;return w(o,t)}return e},pe=(()=>d?R:(e,t,o,n=!1)=>{e.addEventListener(t,o,n)})(),ce=(()=>d?R:(e,t,o,n=!1)=>{e.removeEventListener(t,o,n)})();var m={name:"en",locales:{empty:{emptyText:"No data"}}};var V={name:"zh-cn",locales:{empty:{emptyText:"\u6682\u65E0\u6570\u636E"}}};var a="__onu_config_provider";var s=require("vue");var M=(0,s.ref)();function y(e,t=void 0){let o=(0,s.getCurrentInstance)(),n=(0,s.inject)(a);return unref(n)||(n=(0,s.ref)(o?o.appContext.provides[a]:M.value),(0,s.provide)(a,n)),e?(0,s.computed)(()=>n.value?.[e]??t):n}function fe(e,t,o=!1){let n=!!(0,s.getCurrentInstance)(),r=n?y():void 0,l=t?.provide??(n?s.provide:void 0);if(!l)return;let g=(0,s.computed)(()=>{let L=unref(e);return r?.value?T(r.value,L):L});return l(a,g),(o||!M.value)&&(M.value=g.value),g}var i=require("vue");var A=(e,t,o)=>b(o,e,e).replace(/\{(\w+)\}/g,(n,r)=>`${t?.[r]??`{${r}}`}`),H=e=>(t,o)=>A(t,o,(0,i.unref)(e)),j=e=>{let t=(0,i.computed)(()=>(0,i.unref)(e).name);return{locale:(0,i.isRef)(e)?e:(0,i.ref)(e),lang:t,t:H(e)}};function ue(){let e=y("locale");return j((0,i.computed)(()=>e.value||m))}0&&(module.exports={buildLocaleContext,buildTranslator,configProviderContextKey,deepGet,en,generateId,getChildrenArray,getElement,getFirstElementFromChildren,getFirstElementFromVNode,hash,isArray,isArrayChildren,isBoolean,isComponent,isComponentInstance,isDate,isDef,isElement,isEmptyChildren,isFunction,isMap,isNumber,isObject,isPlainObject,isPromise,isRegExp,isServerRendering,isSet,isSlotsChildren,isString,isSymbol,isText,isValue,mergeFirstChild,mergeObjects,off,on,provideGlobalConfig,querySelector,toTypeString,translate,useGlobalConfig,useLocale,withInstall,withInstallFunction,zhCn}); |
{ | ||
"name": "@onu-ui/utils", | ||
"version": "1.0.10", | ||
"description": "Onu-UI utils library", | ||
"version": "1.0.11", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "onu-ui", |
Sorry, the diff of this file is not supported yet
18477
173