vueless 0.0.50 → 0.0.51

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.
@@ -0,0 +1,93 @@
1
+ import { onMounted, ref, watch, computed } from "vue";
2
+
3
+ const BREAKPOINT_NAME = {
4
+ xs: "xs",
5
+ sm: "sm",
6
+ md: "md",
7
+ lg: "lg",
8
+ xl: "xl",
9
+ "2xl": "2xl",
10
+ };
11
+
12
+ const BREAKPOINT = {
13
+ xs: 0,
14
+ sm: 640,
15
+ md: 768,
16
+ lg: 1024,
17
+ xl: 1280,
18
+ "2xl": 1536,
19
+ };
20
+
21
+ const mobileDevices = ["xs", "sm"];
22
+ const portableDevices = ["xs", "sm", "md"];
23
+
24
+ export default function useBreakpoint() {
25
+ let timeout;
26
+
27
+ const windowWidth = ref(undefined);
28
+ const currentBreakpoint = ref(BREAKPOINT_NAME.xs);
29
+
30
+ const isMobileBreakpoint = computed(() => {
31
+ return mobileDevices.includes(currentBreakpoint.value);
32
+ });
33
+
34
+ const isTabletBreakpoint = computed(() => {
35
+ return mobileDevices.includes(currentBreakpoint.value);
36
+ });
37
+
38
+ const isLaptopBreakpoint = computed(() => {
39
+ return currentBreakpoint.value === BREAKPOINT_NAME.lg;
40
+ });
41
+
42
+ const isPortableBreakpoint = computed(() => {
43
+ return portableDevices.includes(currentBreakpoint.value);
44
+ });
45
+
46
+ const elementSize = computed(() => {
47
+ return isMobileBreakpoint.value ? BREAKPOINT_NAME.md : BREAKPOINT_NAME.lg;
48
+ });
49
+
50
+ onMounted(() => {
51
+ windowWidth.value = window.innerWidth;
52
+
53
+ window.addEventListener(resizeListener, { passive: true });
54
+ });
55
+
56
+ watch(windowWidth, setBreakpoint, { immediate: true });
57
+
58
+ function resizeListener() {
59
+ if (timeout) {
60
+ window.cancelAnimationFrame(timeout);
61
+ }
62
+
63
+ timeout = window.requestAnimationFrame(() => {
64
+ windowWidth.value = window.innerWidth;
65
+ });
66
+ }
67
+
68
+ function setBreakpoint(newWindowWidth) {
69
+ if (newWindowWidth === undefined) return;
70
+
71
+ currentBreakpoint.value = "xs";
72
+
73
+ if (newWindowWidth >= BREAKPOINT.sm && newWindowWidth < BREAKPOINT.smd) {
74
+ currentBreakpoint.value = "sm";
75
+ } else if (newWindowWidth >= BREAKPOINT.md && newWindowWidth < BREAKPOINT.lg) {
76
+ currentBreakpoint.value = "md";
77
+ } else if (newWindowWidth >= BREAKPOINT.lg && newWindowWidth < BREAKPOINT.xl) {
78
+ currentBreakpoint.value = "lg";
79
+ } else if (newWindowWidth >= BREAKPOINT.xl && newWindowWidth < BREAKPOINT["2xl"]) {
80
+ currentBreakpoint.value = "xl";
81
+ } else if (newWindowWidth >= BREAKPOINT["2xl"]) {
82
+ currentBreakpoint.value = "2xl";
83
+ }
84
+ }
85
+
86
+ return {
87
+ isLaptopBreakpoint,
88
+ isTabletBreakpoint,
89
+ isMobileBreakpoint,
90
+ isPortableBreakpoint,
91
+ elementSize,
92
+ };
93
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vueless",
3
- "version": "0.0.50",
3
+ "version": "0.0.51",
4
4
  "license": "MIT",
5
5
  "description": "Vue Styleless Component Framework.",
6
6
  "homepage": "https://vueless.com",
@@ -4,7 +4,7 @@ import { cva, cx } from "../../service.ui";
4
4
  import defaultConfig from "../configs/default.config";
5
5
  import { computed } from "vue";
6
6
 
7
- export function useAttrs(props, { isMobileDevice }) {
7
+ export function useAttrs(props, { isMobileBreakpoint }) {
8
8
  const { config, getAttrs, hasSlotContent } = useUI(defaultConfig, () => props.config);
9
9
  const { wrapper } = config.value;
10
10
 
@@ -33,7 +33,7 @@ export function useAttrs(props, { isMobileDevice }) {
33
33
 
34
34
  const footerAttrs = computed(() => {
35
35
  const footerMobileReverseClasses =
36
- props.mobileFooterReverse && isMobileDevice.value && config.value.footerMobileReverse;
36
+ props.mobileFooterReverse && isMobileBreakpoint.value && config.value.footerMobileReverse;
37
37
 
38
38
  return {
39
39
  ...footerAttrsRaw.value,
@@ -40,7 +40,6 @@
40
40
 
41
41
  <script setup>
42
42
  import { computed, useSlots } from "vue";
43
- import { useStore } from "vuex";
44
43
 
45
44
  import UIService from "../service.ui";
46
45
  import UHeader from "../ui.text-header";
@@ -49,11 +48,11 @@ import UDivider from "../ui.container-divider";
49
48
  import { UCard } from "./constants";
50
49
  import defaultConfig from "./configs/default.config";
51
50
  import { useAttrs } from "./composable/attrs.composable";
51
+ import useBreakpoint from "../composable.breakpoint";
52
52
 
53
53
  /* Should be a string for correct web-types gen */
54
54
  defineOptions({ name: "UCard", inheritAttrs: false });
55
55
 
56
- const store = useStore();
57
56
  const slots = useSlots();
58
57
 
59
58
  const props = defineProps({
@@ -127,9 +126,7 @@ const isShownFooter = computed(() => {
127
126
  return hasSlotContent(slots["footer-left"]) || hasSlotContent(slots["footer-right"]);
128
127
  });
129
128
 
130
- const isMobileDevice = computed(() => {
131
- return store.getters["breakpoint/isMobileDevice"];
132
- });
129
+ const { isMobileBreakpoint } = useBreakpoint();
133
130
 
134
131
  const {
135
132
  hasSlotContent,
@@ -142,5 +139,5 @@ const {
142
139
  descriptionAttrs,
143
140
  contentAttrs,
144
141
  footerAttrs,
145
- } = useAttrs(props, { isMobileDevice });
142
+ } = useAttrs(props, { isMobileBreakpoint });
146
143
  </script>
@@ -2,13 +2,14 @@ import useUI from "../../composable.ui";
2
2
  import { cva, cx } from "../../service.ui";
3
3
 
4
4
  import defaultConfig from "../configs/default.config";
5
- import { useStore } from "vuex";
6
5
  import { computed } from "vue";
7
6
 
7
+ import useBreakpoint from "../../composable.breakpoint";
8
+
8
9
  export function useAttrs(props) {
9
- const store = useStore();
10
10
  const { config, getAttrs, hasSlotContent } = useUI(defaultConfig, () => props.config, "wrapper");
11
11
  const { modal } = config.value;
12
+ const { isMobileBreakpoint } = useBreakpoint();
12
13
 
13
14
  const cvaModal = cva({
14
15
  base: modal.base,
@@ -44,9 +45,7 @@ export function useAttrs(props) {
44
45
  ...headerAttrsRaw.value,
45
46
  class: cx([
46
47
  headerAttrsRaw.value.class,
47
- props.mobileFooterReverse &&
48
- store.getters["breakpoint/isMobileDevice"] &&
49
- config.value.footerMobileReverse,
48
+ props.mobileFooterReverse && isMobileBreakpoint.value && config.value.footerMobileReverse,
50
49
  ]),
51
50
  }));
52
51
 
@@ -54,9 +53,7 @@ export function useAttrs(props) {
54
53
  ...footerAttrsRaw.value,
55
54
  class: cx([
56
55
  footerAttrsRaw.value.class,
57
- props.mobileFooterReverse &&
58
- store.getters["breakpoint/isMobileDevice"] &&
59
- config.value.footerMobileReverse,
56
+ props.mobileFooterReverse && isMobileBreakpoint.value && config.value.footerMobileReverse,
60
57
  ]),
61
58
  }));
62
59
 
@@ -4,7 +4,7 @@ import { cva, cx, isMobileApp } from "../../service.ui";
4
4
  import defaultConfig from "../configs/default.config";
5
5
  import { computed } from "vue";
6
6
 
7
- export function useAttrs(props, { isMobileDevice }) {
7
+ export function useAttrs(props, { isMobileBreakpoint }) {
8
8
  const { config, getAttrs, hasSlotContent } = useUI(defaultConfig, () => props.config);
9
9
  const { wrapper, page, rightRounding } = config.value;
10
10
 
@@ -62,7 +62,7 @@ export function useAttrs(props, { isMobileDevice }) {
62
62
  ...wrapperAttrsRaw.value,
63
63
  class: cx([
64
64
  wrapperAttrsRaw.value.class,
65
- isMobileDevice.value && !isMobileApp && config.value.wrapperMobile,
65
+ isMobileBreakpoint.value && !isMobileApp && config.value.wrapperMobile,
66
66
  ]),
67
67
  }));
68
68
 
@@ -70,7 +70,7 @@ export function useAttrs(props, { isMobileDevice }) {
70
70
  ...footerAttrsRaw.value,
71
71
  class: cx([
72
72
  footerAttrsRaw.value.class,
73
- props.mobileFooterReverse && isMobileDevice.value && config.value.footerMobileReverse,
73
+ props.mobileFooterReverse && isMobileBreakpoint.value && config.value.footerMobileReverse,
74
74
  ]),
75
75
  }));
76
76
 
@@ -66,7 +66,8 @@
66
66
 
67
67
  <script setup>
68
68
  import { computed, useSlots, onMounted } from "vue";
69
- import { useStore } from "vuex";
69
+
70
+ import useBreakpoint from "../composable.breakpoint";
70
71
 
71
72
  import ULink from "../ui.button-link/index.vue";
72
73
  import UIcon from "../ui.image-icon/index.vue";
@@ -79,7 +80,6 @@ import { UPage } from "./constants";
79
80
  import { useAttrs } from "./composables/attrs.composable";
80
81
 
81
82
  const slots = useSlots();
82
- const store = useStore();
83
83
 
84
84
  /* Should be a string for correct web-types gen */
85
85
  defineOptions({ name: "UPage", inheritAttrs: false });
@@ -168,9 +168,7 @@ const props = defineProps({
168
168
  },
169
169
  });
170
170
 
171
- const isMobileDevice = computed(() => {
172
- return store.getters["breakpoint/isMobileDevice"];
173
- });
171
+ const { isMobileBreakpoint } = useBreakpoint();
174
172
 
175
173
  const {
176
174
  config,
@@ -190,7 +188,7 @@ const {
190
188
  footerRightAttrs,
191
189
  rightRoundingWrapperAttrs,
192
190
  hasSlotContent,
193
- } = useAttrs(props, { isMobileDevice });
191
+ } = useAttrs(props, { isMobileBreakpoint });
194
192
 
195
193
  const isShownHeader = computed(() => {
196
194
  const isHeaderLeftSlot = hasSlotContent(slots["header-left"]);
@@ -179,7 +179,6 @@
179
179
 
180
180
  <script setup>
181
181
  import { computed, watch, ref, nextTick } from "vue";
182
- import { useStore } from "vuex";
183
182
  import { merge } from "lodash-es";
184
183
 
185
184
  import UIcon from "../ui.image-icon";
@@ -227,6 +226,7 @@ import {
227
226
  import { wrongDateFormat, wrongMonthNumber, wrongDayNumber } from "./services/validation.service";
228
227
  import useAttrs from "./composables/attrs.composable";
229
228
  import { useLocale } from "../composable.locale";
229
+ import useBreakpoint from "../composable.breakpoint";
230
230
 
231
231
  import defaultConfig from "./configs/default.config";
232
232
  import {
@@ -385,7 +385,6 @@ const {
385
385
  rangeInputWrapperAttrs,
386
386
  inputRangeErrorAttrs,
387
387
  } = useAttrs(props, { isShownMenu });
388
- const store = useStore();
389
388
  const { tm } = useLocale();
390
389
 
391
390
  const calendarValue = ref(props.modelValue);
@@ -413,7 +412,7 @@ const localValue = computed({
413
412
  },
414
413
  });
415
414
 
416
- const isMobileDevice = computed(() => store.getters["breakpoint/isMobileDevice"]);
415
+ const { isMobileBreakpoint } = useBreakpoint();
417
416
  const rangeInputName = computed(() => `rangeInput-${props.id}`);
418
417
  const currentLocale = computed(() => merge(tm("UDatePickerRange"), props.config.i18n));
419
418
 
@@ -560,7 +559,7 @@ const userFormatDate = computed(() => {
560
559
  title = `${fromTitle} – ${toTitle}`;
561
560
  }
562
561
 
563
- if (isMobileDevice.value && !isPeriod.value.month && isVariant.value.button) {
562
+ if (isMobileBreakpoint.value && !isPeriod.value.month && isVariant.value.button) {
564
563
  const startDay = String(from.getDate()).padStart(2, "0");
565
564
  const endDay = String(to?.getDate())?.padStart(2, "0");
566
565
  const startMonth = String(from.getMonth()).padStart(2, "0");
@@ -25,7 +25,6 @@
25
25
 
26
26
  <script setup>
27
27
  import { computed } from "vue";
28
- import { useStore } from "vuex";
29
28
 
30
29
  import UIcon from "../ui.image-icon";
31
30
  import URadio from "../ui.form-radio";
@@ -34,12 +33,11 @@ import UIService, { getRandomId } from "../service.ui";
34
33
  import defaultConfig from "./configs/default.config";
35
34
  import { URadioCard } from "./constants";
36
35
  import { useAttrs } from "./composables/attrs.composable";
36
+ import useBreakpoint from "../composable.breakpoint";
37
37
 
38
38
  /* Should be a string for correct web-types gen */
39
39
  defineOptions({ name: "URadioCard", inheritAttrs: false });
40
40
 
41
- const store = useStore();
42
-
43
41
  const props = defineProps({
44
42
  /**
45
43
  * Set radio card name.
@@ -126,9 +124,7 @@ const emit = defineEmits(["update:modelValue"]);
126
124
 
127
125
  const { radioAttrs, iconAttrs, wrapperAttrs, labelAttrs, itemsAttrs } = useAttrs(props);
128
126
 
129
- const isMobileDevice = computed(() => {
130
- return store.getters["breakpoint/isMobileDevice"];
131
- });
127
+ const { isMobileBreakpoint } = useBreakpoint();
132
128
 
133
129
  const selectedItem = computed({
134
130
  get: () => props.modelValue,
@@ -137,10 +133,10 @@ const selectedItem = computed({
137
133
 
138
134
  const gridColsClass = computed(() => {
139
135
  return {
140
- "grid-cols-1": isMobileDevice,
141
- "grid-cols-2": props.gridCols === 2 && isMobileDevice,
142
- "grid-cols-3": props.gridCols === 3 && isMobileDevice,
143
- "grid-cols-4": props.gridCols === 4 && isMobileDevice,
136
+ "grid-cols-1": isMobileBreakpoint.value,
137
+ "grid-cols-2": props.gridCols === 2 && isMobileBreakpoint.value,
138
+ "grid-cols-3": props.gridCols === 3 && isMobileBreakpoint.value,
139
+ "grid-cols-4": props.gridCols === 4 && isMobileBreakpoint.value,
144
140
  };
145
141
  });
146
142
  </script>
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "framework": "vue",
3
3
  "name": "vueless",
4
- "version": "0.0.50",
4
+ "version": "0.0.51",
5
5
  "contributions": {
6
6
  "html": {
7
7
  "description-markup": "markdown",
@@ -6993,19 +6993,6 @@
6993
6993
  "symbol": "default"
6994
6994
  }
6995
6995
  },
6996
- {
6997
- "name": "UViewport",
6998
- "description": "",
6999
- "slots": [
7000
- {
7001
- "name": "default"
7002
- }
7003
- ],
7004
- "source": {
7005
- "module": "vueless/ui.viewport/index.vue",
7006
- "symbol": "default"
7007
- }
7008
- },
7009
6996
  {
7010
6997
  "name": "YearView",
7011
6998
  "description": "",
@@ -1,78 +0,0 @@
1
- <template>
2
- <div>
3
- <slot :breakpoint="breakpoint" />
4
- </div>
5
- </template>
6
-
7
- <script>
8
- import { mapMutations } from "vuex";
9
-
10
- export default {
11
- name: "UViewport",
12
-
13
- data() {
14
- return {
15
- windowWidth: 0,
16
- breakpoint: "",
17
- };
18
- },
19
-
20
- watch: {
21
- windowWidth: {
22
- immediate: true,
23
- handler: "setBreakpoint",
24
- },
25
- },
26
-
27
- mounted() {
28
- this.setWindowWidth();
29
- this.setListener();
30
- },
31
-
32
- methods: {
33
- ...mapMutations("breakpoint", ["SET_BREAKPOINT"]),
34
-
35
- setWindowWidth() {
36
- this.windowWidth = window.innerWidth;
37
- },
38
-
39
- setListener() {
40
- let timeout;
41
-
42
- window.addEventListener(
43
- "resize",
44
- () => {
45
- if (timeout) {
46
- window.cancelAnimationFrame(timeout);
47
- }
48
-
49
- timeout = window.requestAnimationFrame(() => {
50
- this.setWindowWidth();
51
- });
52
- },
53
- { passive: true },
54
- );
55
- },
56
-
57
- setBreakpoint(windowWidth) {
58
- if (!windowWidth) return;
59
-
60
- this.breakpoint = "xs";
61
-
62
- if (windowWidth >= 640 && windowWidth < 768) {
63
- this.breakpoint = "sm";
64
- } else if (windowWidth >= 768 && windowWidth < 1024) {
65
- this.breakpoint = "md";
66
- } else if (windowWidth >= 1024 && windowWidth < 1280) {
67
- this.breakpoint = "lg";
68
- } else if (windowWidth >= 1280 && windowWidth < 1536) {
69
- this.breakpoint = "xl";
70
- } else if (windowWidth >= 1536) {
71
- this.breakpoint = "2xl";
72
- }
73
-
74
- this.SET_BREAKPOINT(this.breakpoint);
75
- },
76
- },
77
- };
78
- </script>
@@ -1,47 +0,0 @@
1
- export default {
2
- namespaced: true,
3
-
4
- state: {
5
- breakpoint: "",
6
- mobileDevices: ["xs", "sm"],
7
- portableDevices: ["xs", "sm", "md"],
8
- },
9
-
10
- getters: {
11
- isLaptopDevice(state) {
12
- const { breakpoint } = state;
13
-
14
- return breakpoint === "lg";
15
- },
16
-
17
- isTabletDevice(state) {
18
- const { breakpoint } = state;
19
-
20
- return breakpoint === "md";
21
- },
22
-
23
- isMobileDevice(state) {
24
- const { breakpoint, mobileDevices } = state;
25
-
26
- return mobileDevices.includes(breakpoint);
27
- },
28
-
29
- isPortableDevice(state) {
30
- const { breakpoint, portableDevices } = state;
31
-
32
- return portableDevices.includes(breakpoint);
33
- },
34
-
35
- elementSize(state, getters) {
36
- const { isMobileDevice } = getters;
37
-
38
- return isMobileDevice ? "md" : "lg";
39
- },
40
- },
41
-
42
- mutations: {
43
- SET_BREAKPOINT(state, breakpoint) {
44
- state.breakpoint = breakpoint;
45
- },
46
- },
47
- };