@studio-west/component-sw 0.12.8 → 0.12.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@studio-west/component-sw",
3
- "version": "0.12.8",
3
+ "version": "0.12.10",
4
4
  "description": "Vue components of Component-SW collection.",
5
5
  "type": "module",
6
6
  "keywords": [
package/src/Alert.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { createApp, h, VNode } from 'vue'
2
- import alert from '@/components/SwAlert.vue'
1
+ import { createApp, h, type VNode } from 'vue'
2
+ import alert from './components/SwAlert.vue'
3
3
 
4
4
  // Alert options interface
5
5
  export interface AlertOptions {
@@ -14,9 +14,14 @@ export interface AlertOptions {
14
14
  footer?: string | (() => VNode | VNode[])
15
15
  }
16
16
 
17
- let container: HTMLDivElement | null = document.querySelector("div.sw-alert-wrapper")
17
+ let container: HTMLDivElement | null = null
18
18
 
19
19
  export function Alert(options: AlertOptions = {}): void {
20
+ if (typeof document === 'undefined') return
21
+
22
+ if (!container) {
23
+ container = document.querySelector("div.sw-alert-wrapper")
24
+ }
20
25
  if (!container) {
21
26
  container = document.createElement('div')
22
27
  container.className = 'sw-alert-wrapper'
@@ -13,7 +13,7 @@
13
13
 
14
14
  <script setup>
15
15
  import { ref, computed, onMounted, onUnmounted } from "vue"
16
- import SwIcon from "@/components/SwIcon.vue"
16
+ import SwIcon from "./SwIcon.vue"
17
17
  const props = defineProps({
18
18
  message: {type: String, default: "Default message"},
19
19
  before: {type: String, default: ''},
@@ -1,6 +1,6 @@
1
1
  <script setup>
2
2
  import {computed, ref} from 'vue'
3
- import { parseTime, parseDateString } from "@/utils/index.js"
3
+ import { parseTime, parseDateString } from "../utils/index.js"
4
4
 
5
5
  const props = defineProps({
6
6
  data: Object,
@@ -32,7 +32,7 @@ const days = ref([])
32
32
  const ind = ref(0)
33
33
  const startId = ref(-1)
34
34
  const endId = ref(-1)
35
- const locale = ref(navigator.language || 'ru')
35
+ const locale = ref((typeof navigator !== 'undefined' && navigator.language) || 'ru')
36
36
  const iso = (/en|zh|ja|he/.test(locale.value)) ? 0 : 1
37
37
  const months = computed(() => {
38
38
  return Array.from({ length: 12 }, (_, i) => {
@@ -7,7 +7,7 @@
7
7
 
8
8
  <script setup>
9
9
  import { computed } from "vue"
10
- import SwIcon from "@/components/SwIcon.vue"
10
+ import SwIcon from "./SwIcon.vue"
11
11
 
12
12
  const props = defineProps({
13
13
  class: {type: String, default: ''},
@@ -30,10 +30,10 @@
30
30
  </template>
31
31
 
32
32
  <script setup>
33
- import SwDropdown from "@/components/SwDropdown.vue"
34
- import SwButton from "@/components/SwButton.vue"
33
+ import SwDropdown from "./SwDropdown.vue"
34
+ import SwButton from "./SwButton.vue"
35
35
  import {watchEffect, ref, onMounted} from "vue"
36
- import SwIcon from "@/components/SwIcon.vue"
36
+ import SwIcon from "./SwIcon.vue"
37
37
  const swGide = ref(null)
38
38
  const visual = ref(true)
39
39
  const block = ref(null)
@@ -5,7 +5,7 @@
5
5
  </svg>
6
6
  </template>
7
7
  <script setup>
8
- import { isExternal } from '@/utils/index.js'
8
+ import { isExternal } from '../utils/index.js'
9
9
 
10
10
  const props = defineProps({
11
11
  prefix: {type: String, default: 'icon'},
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { computed, ref, watch } from "vue"
3
3
  import SwIcon from "./SwIcon.vue"
4
- import { formatPhoneNumber } from "@/utils/index"
4
+ import { formatPhoneNumber } from "../utils/index"
5
5
 
6
6
  // Define prop types - separate model from props
7
7
  interface InputProps {
@@ -38,10 +38,9 @@ const instance = getCurrentInstance()
38
38
  const createComponentWithSlots = (
39
39
  componentName: string | Component,
40
40
  config: MenuItemConfig,
41
- index: number | null = null,
42
- parentIndex: number | null = null
41
+ index: number | null = null
43
42
  ): VNode => {
44
- let component: Component | string
43
+ let component: Component | string | undefined
45
44
  let resolvedComponent: any = null
46
45
 
47
46
  try {
@@ -89,7 +88,7 @@ const createComponentWithSlots = (
89
88
  if (Array.isArray(compConfig)) {
90
89
  return compConfig.map(item => createComponentWithSlots(compName, item))
91
90
  } else {
92
- return createComponentWithSlots(compName, compConfig)
91
+ return createComponentWithSlots(compName, compConfig as MenuItemConfig)
93
92
  }
94
93
  }).flat()
95
94
  }
@@ -97,7 +96,7 @@ const createComponentWithSlots = (
97
96
  return value.map(item => {
98
97
  if (typeof item === 'object' && !Array.isArray(item)) {
99
98
  const [nestedComponentName, nestedConfig] = Object.entries(item)[0]
100
- return createComponentWithSlots(nestedComponentName, nestedConfig)
99
+ return createComponentWithSlots(nestedComponentName, nestedConfig as MenuItemConfig)
101
100
  }
102
101
  return item
103
102
  })
@@ -118,7 +117,7 @@ const createComponentWithSlots = (
118
117
  if (Array.isArray(compConfig)) {
119
118
  return compConfig.map(item => createComponentWithSlots(compName, item))
120
119
  } else {
121
- return createComponentWithSlots(compName, compConfig)
120
+ return createComponentWithSlots(compName, compConfig as MenuItemConfig)
122
121
  }
123
122
  }).flat()
124
123
  }
@@ -126,7 +125,7 @@ const createComponentWithSlots = (
126
125
  return value.map(item => {
127
126
  if (typeof item === 'object' && !Array.isArray(item)) {
128
127
  const [nestedComponentName, nestedConfig] = Object.entries(item)[0]
129
- return createComponentWithSlots(nestedComponentName, nestedConfig)
128
+ return createComponentWithSlots(nestedComponentName, nestedConfig as MenuItemConfig)
130
129
  }
131
130
  return item
132
131
  })
@@ -8,8 +8,8 @@
8
8
 
9
9
  <script setup>
10
10
  import {nextTick, onUnmounted, ref, watch, useSlots} from "vue"
11
- import SwButton from "@/components/SwButton.vue"
12
- import SwIcon from "@/components/SwIcon.vue"
11
+ import SwButton from "./SwButton.vue"
12
+ import SwIcon from "./SwIcon.vue"
13
13
 
14
14
  const model = defineModel()
15
15
  const props = defineProps({
@@ -43,7 +43,7 @@ const props = withDefaults(defineProps<Props>(), {
43
43
  watch(() => model.value?.text, (newValue) => {
44
44
  if (newValue && newValue.length > 3) address.value.fullText = newValue
45
45
  })
46
- watch(address.value.fullText,(newValue, oldValue) => {
46
+ watch(() => address.value.fullText, (newValue, oldValue) => {
47
47
  visible.value = (newValue.length > 3 && newValue.length > oldValue.length)
48
48
  if (newValue.length >3) getDadata()
49
49
  })
@@ -71,13 +71,14 @@ const getDadata = () => {
71
71
  console.log(error);
72
72
  })
73
73
  }
74
- const clickLi = (item) => {
74
+ const clickLi = (item: Suggestion) => {
75
75
  address.value.fullText = item.value
76
76
  visible.value = false
77
- const geo = {}
78
- geo.text = item.value
79
- geo.coords = [Number(item.data.geo_lat), Number(item.data.geo_lon)]
80
- geo.suggestion = item.data
77
+ const geo: GeoData = {
78
+ text: item.value,
79
+ coords: [Number(item.data.geo_lat), Number(item.data.geo_lon)],
80
+ suggestion: item.data
81
+ }
81
82
  model.value = geo
82
83
  }
83
84
  </script>
@@ -85,6 +86,7 @@ const clickLi = (item) => {
85
86
  <template>
86
87
  <div class="popup">
87
88
  <sw-input
89
+ name="address"
88
90
  :size="props.size"
89
91
  v-model="address.fullText"
90
92
  :placeholder="props.placeholder"
@@ -5,7 +5,7 @@
5
5
  </template>
6
6
 
7
7
  <script setup>
8
- import SwSkeletonItem from "@/components/SwSkeletonItem.vue"
8
+ import SwSkeletonItem from "./SwSkeletonItem.vue"
9
9
  const props = defineProps({
10
10
  class: {type:String, default: ''},
11
11
  visual: {type:Boolean, default: false}
@@ -33,7 +33,7 @@
33
33
 
34
34
  <script setup>
35
35
  import { ref, computed, onMounted, onUnmounted } from 'vue'
36
- import { calculateTooltipPosition } from '@/utils/index.js'
36
+ import { calculateTooltipPosition } from '../utils/index.js'
37
37
 
38
38
  const model = defineModel({type: [Number, Array], required: true})
39
39
  const props = defineProps({
@@ -71,7 +71,7 @@
71
71
  }
72
72
 
73
73
  const tooltipStyle = (index) => {
74
- const sliderElement = document.querySelector('.sw-slider')
74
+ const sliderElement = typeof document !== 'undefined' ? document.querySelector('.sw-slider') : null
75
75
  if (sliderElement) {
76
76
  return calculateTooltipPosition(sliderElement, props.vertical)
77
77
  }
package/src/index.ts CHANGED
@@ -1,9 +1,10 @@
1
- import { defineAsyncComponent, App } from 'vue'
1
+ /// <reference types="vite/client" />
2
+ import { defineAsyncComponent, type App, type Component } from 'vue'
2
3
  import './styles/main.scss'
3
4
  import { Alert } from './Alert'
4
5
 
5
6
  // Import all Vue components
6
- const modules = import.meta.glob('./components/*.vue')
7
+ const modules = import.meta.glob<{ default: Component }>('./components/*.vue')
7
8
 
8
9
  // Create components object with proper typing
9
10
  const components: Record<string, ReturnType<typeof defineAsyncComponent>> = {}
@@ -33,12 +34,5 @@ const Library = {
33
34
  }
34
35
  }
35
36
 
36
- // Type exports
37
- export type { SwButtonProps } from '@/types'
38
- export type { SwInputProps } from '@/types'
39
- export type { SwSwitchProps } from '@/types'
40
- export type { SwSelectProps } from '@/types'
41
- export type { SwMenuProps } from '@/types'
42
-
43
37
  // Named exports
44
38
  export { components, Alert, Library }
@@ -95,13 +95,13 @@ export function formatPhoneNumber(value: string, oldValue?: string): string {
95
95
  i = i < 5 ? 3 : i
96
96
  new_value = new_value.slice(0, i)
97
97
  }
98
- let reg = matrix.slice(0, value.length)
98
+ const regPattern = matrix.slice(0, value.length)
99
99
  .replace(
100
100
  /_+/g,
101
101
  (a) => `\\d{1,${a.length}}`
102
102
  )
103
103
  .replace(/[+()]/g, '\\$&')
104
- reg = new RegExp(`^${reg}$`)
104
+ const reg = new RegExp(`^${regPattern}$`)
105
105
  new_value = new_value.replace(/[-—]$|(\) )$/g, '')
106
106
 
107
107
  if ((!reg.test(value) || value.length < 5)) return new_value
@@ -0,0 +1,5 @@
1
+ declare module '*.vue' {
2
+ import type { DefineComponent } from 'vue'
3
+ const component: DefineComponent<Record<string, unknown>, Record<string, unknown>, unknown>
4
+ export default component
5
+ }