maz-ui 4.7.5 → 4.7.6
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/dist/chunks/MazAccordion.CKnz73h4.js +1 -0
- package/dist/chunks/MazAlert.B8hE7wet.js +1 -0
- package/dist/chunks/MazAnimatedCounter.GLLYbZAz.js +1 -0
- package/dist/chunks/MazAnimatedElement._8NY8WgC.js +1 -0
- package/dist/chunks/MazAnimatedText.BSZ8FNf-.js +1 -0
- package/dist/chunks/MazAvatar.vO5VNPi8.js +1 -0
- package/dist/chunks/MazBackdrop.Cjbwi8-V.js +1 -0
- package/dist/chunks/MazBadge.BBZJgHXm.js +1 -0
- package/dist/chunks/MazBottomSheet.WgZ6qobx.js +1 -0
- package/dist/chunks/MazBtn.Cc9C1v2l.js +1 -0
- package/dist/chunks/MazBtnGroup.3B1XcqWM.js +1 -0
- package/dist/chunks/MazCard.YYC0LaHY.js +1 -0
- package/dist/chunks/MazCardSpotlight.SpZF61hl.js +1 -0
- package/dist/chunks/MazCarousel.1NT4jcvR.js +1 -0
- package/dist/chunks/MazChart.CDZ2PBTC.js +1 -0
- package/dist/chunks/MazCheckbox.DurIbKdf.js +1 -0
- package/dist/chunks/MazChecklist.D9ezwGpQ.js +1 -0
- package/dist/chunks/MazCircularProgressBar.rATx_hD9.js +1 -0
- package/dist/chunks/MazContainer.zXcfMOs-.js +1 -0
- package/dist/chunks/MazDatePicker.KUP34cbV.js +1 -0
- package/dist/chunks/MazDialog.CtKF3Xzo.js +1 -0
- package/dist/chunks/MazDialogConfirm.CAAHeBPE.js +1 -0
- package/dist/chunks/MazDrawer.Dc_RGG8a.js +1 -0
- package/dist/chunks/MazDropdown.2DUcivzO.js +1 -0
- package/dist/chunks/MazDropzone.CiWiPcFM.js +1 -0
- package/dist/chunks/MazExpandAnimation.CMMwtuQA.js +1 -0
- package/dist/chunks/MazFullscreenLoader.BIVRcZJ8.js +1 -0
- package/dist/chunks/MazGallery.CEmGy0K9.js +1 -0
- package/dist/chunks/MazIcon.ZWAk25ZX.js +1 -0
- package/dist/chunks/MazInput.DJjWLaKg.js +1 -0
- package/dist/chunks/MazInputCode.DKnl3i-X.js +1 -0
- package/dist/chunks/MazInputNumber.B42Mn-9h.js +1 -0
- package/dist/chunks/MazInputPhoneNumber.CLivThtK.js +1 -0
- package/dist/chunks/MazInputPrice.BeL-M944.js +1 -0
- package/dist/chunks/MazInputTags.CIVT9F6Q.js +1 -0
- package/dist/chunks/MazLazyImg.-EMwandx.js +1 -0
- package/dist/chunks/MazLink.BOpxMATj.js +1 -0
- package/dist/chunks/MazLoadingBar.C86AX2Tk.js +1 -0
- package/dist/chunks/MazPagination.CNNKXBsg.js +1 -0
- package/dist/chunks/MazPickerCalendarDays.CSZZbk5Z.js +1 -0
- package/dist/chunks/MazPickerCalendarGrid.DrUHBH6-.js +1 -0
- package/dist/chunks/MazPickerContainer.BZ74M74V.js +1 -0
- package/dist/chunks/MazPopover.Co8BEopX.js +1 -0
- package/dist/chunks/MazPullToRefresh.DMtb6Oa3.js +1 -0
- package/dist/chunks/MazRadio.75ipjTw2.js +1 -0
- package/dist/chunks/MazRadioButtons.DenHCgB3.js +1 -0
- package/dist/chunks/MazReadMore.CDXacQIw.js +1 -0
- package/dist/chunks/MazReadingProgressBar.828Y0mxA.js +1 -0
- package/dist/chunks/MazSelect.yYFAbBb5.js +1 -0
- package/dist/chunks/MazSelectCountry.DvVgk2es.js +1 -0
- package/dist/chunks/MazSkeleton.BewTYJC2.js +1 -0
- package/dist/chunks/MazSlider.BS5QHWK6.js +1 -0
- package/dist/chunks/MazSpinner.D3NN2pow.js +1 -0
- package/dist/chunks/MazStepper.DTu8HG9T.js +1 -0
- package/dist/chunks/MazSwitch.Dvmj-rTW.js +1 -0
- package/dist/chunks/MazTable.DnOehvN6.js +1 -0
- package/dist/chunks/MazTableCell.xbm2NGWL.js +1 -0
- package/dist/chunks/MazTableRow.B5dJiXk1.js +1 -0
- package/dist/chunks/MazTableTitle.DNA_1mCy.js +1 -0
- package/dist/chunks/MazTabs.-0-YP3QQ.js +1 -0
- package/dist/chunks/MazTabsBar.D2JVKMS7.js +1 -0
- package/dist/chunks/MazTabsContent.C9omK25X.js +1 -0
- package/dist/chunks/MazTabsContentItem.mJEAS5R8.js +1 -0
- package/dist/chunks/MazTextarea.BliEP5G5.js +1 -0
- package/dist/chunks/MazUiProvider.BgN8V0lD.js +1 -0
- package/dist/chunks/_plugin-vue_export-helper.ChmETRGw.js +1 -0
- package/dist/chunks/dialog.DexeIC3K.js +1 -0
- package/dist/chunks/dom-events.BPrKJiCz.js +1 -0
- package/dist/chunks/resolveLinkComponent.DAc3sqGH.js +1 -0
- package/dist/chunks/toast.UQ8RRuT9.js +1 -0
- package/dist/chunks/types.DDbvTVqf.js +1 -0
- package/dist/chunks/useMazInputPhoneNumber.B_qQ0ldP.js +1 -0
- package/dist/chunks/utils.B8bfGQxN.js +1 -0
- package/dist/chunks/vFullscreenImg.CZeRh3mw.js +1 -0
- package/dist/chunks/vLazyImg.CXmd3Lp0.js +1 -0
- package/dist/chunks/vZoomImg.CaAHb98S.js +124 -0
- package/dist/components/MazAccordion.js +1 -86
- package/dist/components/MazAlert.js +1 -85
- package/dist/components/MazAnimatedCounter.js +1 -73
- package/dist/components/MazAnimatedElement.js +1 -44
- package/dist/components/MazAnimatedText.js +1 -103
- package/dist/components/MazAvatar.js +1 -125
- package/dist/components/MazBackdrop.js +1 -163
- package/dist/components/MazBadge.js +1 -29
- package/dist/components/MazBottomSheet.js +1 -55
- package/dist/components/MazBtn.js +1 -109
- package/dist/components/MazBtnGroup.js +1 -44
- package/dist/components/MazCard.js +1 -184
- package/dist/components/MazCardSpotlight.js +1 -81
- package/dist/components/MazCarousel.js +1 -104
- package/dist/components/MazChart.js +1 -4
- package/dist/components/MazCheckbox.js +1 -128
- package/dist/components/MazChecklist.js +1 -133
- package/dist/components/MazCircularProgressBar.js +1 -131
- package/dist/components/MazContainer.js +1 -71
- package/dist/components/MazDatePicker/MazPickerCalendar.js +1 -113
- package/dist/components/MazDatePicker/MazPickerCalendarMonth/MazPickerCalendarDays.js +1 -19
- package/dist/components/MazDatePicker/MazPickerCalendarMonth/MazPickerCalendarGrid.js +1 -181
- package/dist/components/MazDatePicker/MazPickerCalendarMonth/MazPickerCalendarMonth.js +1 -75
- package/dist/components/MazDatePicker/MazPickerCalendarSwitcher.js +1 -90
- package/dist/components/MazDatePicker/MazPickerContainer.js +1 -116
- package/dist/components/MazDatePicker/MazPickerHeader.js +1 -126
- package/dist/components/MazDatePicker/MazPickerMonthSwitcher.js +1 -82
- package/dist/components/MazDatePicker/MazPickerShortcuts.js +1 -55
- package/dist/components/MazDatePicker/MazPickerTime.js +1 -178
- package/dist/components/MazDatePicker/MazPickerYearSwitcher.js +1 -95
- package/dist/components/MazDatePicker.js +1 -466
- package/dist/components/MazDatePicker.vue.d.ts +2 -6
- package/dist/components/MazDialog.js +1 -115
- package/dist/components/MazDialog.vue.d.ts +2 -6
- package/dist/components/MazDialogConfirm.js +1 -6
- package/dist/components/MazDialogConfirm.vue.d.ts +2 -6
- package/dist/components/MazDrawer.js +1 -70
- package/dist/components/MazDropdown.js +1 -277
- package/dist/components/MazDropdown.vue.d.ts +2 -6
- package/dist/components/MazDropzone.js +1 -533
- package/dist/components/MazExpandAnimation.js +1 -46
- package/dist/components/MazFullscreenLoader.js +1 -38
- package/dist/components/MazGallery.js +1 -105
- package/dist/components/MazIcon.js +1 -114
- package/dist/components/MazInput.js +1 -256
- package/dist/components/MazInputCode.js +1 -152
- package/dist/components/MazInputNumber.js +1 -152
- package/dist/components/MazInputPhoneNumber/PhoneInput.js +1 -114
- package/dist/components/MazInputPhoneNumber.js +1 -253
- package/dist/components/MazInputPrice.js +1 -4
- package/dist/components/MazInputTags.js +1 -145
- package/dist/components/MazLazyImg.js +1 -62
- package/dist/components/MazLink.js +1 -80
- package/dist/components/MazLoadingBar.js +1 -24
- package/dist/components/MazPagination.js +1 -184
- package/dist/components/MazPopover.js +1 -326
- package/dist/components/MazPullToRefresh.js +1 -145
- package/dist/components/MazRadio.js +1 -103
- package/dist/components/MazRadioButtons.js +1 -135
- package/dist/components/MazReadMore.js +1 -110
- package/dist/components/MazReadingProgressBar.js +1 -68
- package/dist/components/MazSelect.js +1 -413
- package/dist/components/MazSelectCountry.js +1 -192
- package/dist/components/MazSkeleton.js +1 -50
- package/dist/components/MazSlider.js +1 -205
- package/dist/components/MazSpinner.js +1 -27
- package/dist/components/MazStepper.js +1 -170
- package/dist/components/MazSwitch.js +1 -4
- package/dist/components/MazTable.js +1 -8
- package/dist/components/MazTableCell.js +1 -18
- package/dist/components/MazTableRow.js +1 -26
- package/dist/components/MazTableTitle.js +1 -18
- package/dist/components/MazTabs.js +1 -4
- package/dist/components/MazTabsBar.js +1 -138
- package/dist/components/MazTabsContent.js +1 -4
- package/dist/components/MazTabsContentItem.js +1 -37
- package/dist/components/MazTextarea.js +1 -147
- package/dist/components/MazUiProvider.js +1 -4
- package/dist/components/index.js +1 -127
- package/dist/composables/index.js +1 -44
- package/dist/composables/useAos.js +1 -7
- package/dist/composables/useBreakpoints.js +1 -34
- package/dist/composables/useDialog.js +1 -7
- package/dist/composables/useDisplayNames.js +1 -111
- package/dist/composables/useDropzone.js +1 -66
- package/dist/composables/useFormField.js +1 -101
- package/dist/composables/useFormValidator.js +1 -163
- package/dist/composables/useFreezeValue.js +1 -8
- package/dist/composables/useIdleTimeout.js +1 -10
- package/dist/composables/useInjectStrict.js +1 -10
- package/dist/composables/useInstanceUniqId.js +1 -12
- package/dist/composables/useMountComponent.js +1 -16
- package/dist/composables/useMutationObserver.js +1 -37
- package/dist/composables/useReadingTime.js +1 -33
- package/dist/composables/useStringMatching.js +1 -42
- package/dist/composables/useSwipe.js +1 -26
- package/dist/composables/useTimer.js +1 -36
- package/dist/composables/useToast.js +1 -14
- package/dist/composables/useUserVisibility.js +1 -10
- package/dist/composables/useWait.js +1 -7
- package/dist/composables/useWindowSize.js +1 -21
- package/dist/directives/index.js +1 -19
- package/dist/directives/vClickOutside.js +1 -104
- package/dist/directives/vFullscreenImg.js +1 -10
- package/dist/directives/vLazyImg.js +1 -23
- package/dist/directives/vTooltip.js +1 -161
- package/dist/directives/vZoomImg.js +1 -286
- package/dist/index.js +1 -1
- package/dist/plugins/aos.js +1 -89
- package/dist/plugins/dialog.js +1 -61
- package/dist/plugins/index.js +1 -17
- package/dist/plugins/maz-ui.js +1 -11
- package/dist/plugins/toast.js +1 -261
- package/dist/plugins/wait.js +1 -43
- package/dist/resolvers/MazComponentsResolver.js +1 -18
- package/dist/resolvers/MazDirectivesResolver.js +1 -14
- package/dist/resolvers/MazModulesResolver.js +1 -76
- package/dist/resolvers/index.js +1 -8
- package/dist/tailwindcss/index.js +1 -20
- package/dist/tailwindcss/tailwind.config.js +1 -35
- package/dist/tailwindcss/utils/colors.js +1 -25
- package/dist/tailwindcss/variables/breakpoints.js +1 -29
- package/dist/tailwindcss/variables/colors.js +1 -33
- package/dist/tailwindcss/variables/design-tokens.js +1 -42
- package/dist/tailwindcss/variables/utilities.js +1 -20
- package/dist/tailwindcss/variables/z-indexes.js +1 -17
- package/package.json +12 -13
- package/dist/chunks/MazChart.vue_vue_type_script_setup_true_lang.DpG9UYdm.js +0 -50
- package/dist/chunks/MazDialogConfirm.vue_vue_type_script_setup_true_lang.BB2rYkwY.js +0 -215
- package/dist/chunks/MazInputPrice.vue_vue_type_script_setup_true_lang.DcNkyw1C.js +0 -77
- package/dist/chunks/MazSwitch.vue_vue_type_style_index_0_lang.lYfYsI0R.js +0 -84
- package/dist/chunks/MazTable.vue_vue_type_script_setup_true_lang.ycpSYFvJ.js +0 -517
- package/dist/chunks/MazTabs.vue_vue_type_script_setup_true_lang.CiIFxs7J.js +0 -28
- package/dist/chunks/MazTabsContent.vue_vue_type_script_setup_true_lang.MO7zA8LZ.js +0 -26
- package/dist/chunks/MazUiProvider.vue_vue_type_script_setup_true_lang.DtnM1DOn.js +0 -34
- package/dist/chunks/_plugin-vue_export-helper.B--vMWp3.js +0 -9
- package/dist/chunks/dom-events.DTx6Kblx.js +0 -368
- package/dist/chunks/fullscreen-img.directive.BJieSSIt.js +0 -321
- package/dist/chunks/lazy-img.directive.GRfYbidn.js +0 -174
- package/dist/chunks/resolveLinkComponent.CKR2McYy.js +0 -8
- package/dist/chunks/types.D0Bp_UhS.js +0 -6
- package/dist/chunks/useMazInputPhoneNumber.Os-2y9bz.js +0 -157
- package/dist/chunks/utils.D89Q5cCP.js +0 -207
- /package/dist/assets/{fullscreen-img.DFp1SMPU.css → vFullscreenImg.DFp1SMPU.css} +0 -0
|
@@ -1,66 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ref, shallowRef, watch, toValue, onBeforeUnmount, unref } from "vue";
|
|
3
|
-
const isSafariRegex = /^(?:(?!chrome|android).)*safari/i;
|
|
4
|
-
function useDropzone(target, options = {}) {
|
|
5
|
-
const isOverDropZone = ref(!1), isOverError = ref(!1), files = shallowRef(null);
|
|
6
|
-
let counter = 0, isValid = !0;
|
|
7
|
-
if (isClient()) {
|
|
8
|
-
let getFiles = function(event) {
|
|
9
|
-
const list = [...event.dataTransfer?.files ?? []];
|
|
10
|
-
return list.length === 0 ? null : multiple ? list : [list[0]];
|
|
11
|
-
}, checkDataTypes = function(types) {
|
|
12
|
-
const dataTypes = unref(_options.dataTypes);
|
|
13
|
-
if (typeof dataTypes == "function")
|
|
14
|
-
return dataTypes(types);
|
|
15
|
-
if (!dataTypes || dataTypes?.length === 0)
|
|
16
|
-
return !0;
|
|
17
|
-
const mimeTypes = dataTypes.filter((type) => !type.startsWith("."));
|
|
18
|
-
if (mimeTypes.length === 0)
|
|
19
|
-
return !0;
|
|
20
|
-
const validTypes = types.filter(Boolean);
|
|
21
|
-
return validTypes.length === 0 ? !0 : validTypes.every(
|
|
22
|
-
(type) => mimeTypes?.some((allowedType) => type.includes(allowedType))
|
|
23
|
-
);
|
|
24
|
-
}, checkValidity = function(items) {
|
|
25
|
-
const types = Array.from(items ?? [], (item) => item.type), dataTypesValid = checkDataTypes(types), multipleFilesValid = multiple || items.length <= 1;
|
|
26
|
-
return dataTypesValid && multipleFilesValid;
|
|
27
|
-
}, isSafari = function() {
|
|
28
|
-
return isSafariRegex.test(navigator.userAgent) && !("chrome" in globalThis);
|
|
29
|
-
}, handleDragEvent = function(event, eventType) {
|
|
30
|
-
const dataTransferItemList = event.dataTransfer?.items;
|
|
31
|
-
isValid = (dataTransferItemList && checkValidity(dataTransferItemList)) ?? !1, preventDefaultForUnhandled && event.preventDefault();
|
|
32
|
-
const currentFiles = getFiles(event);
|
|
33
|
-
switch (!isSafari() && !isValid && event.dataTransfer && (event.dataTransfer.dropEffect = "none"), event.preventDefault(), event.dataTransfer && (event.dataTransfer.dropEffect = "copy"), eventType) {
|
|
34
|
-
case "enter":
|
|
35
|
-
counter += 1, isOverDropZone.value = !0, isOverError.value = !isValid, _options.onEnter?.(null, event);
|
|
36
|
-
break;
|
|
37
|
-
case "over":
|
|
38
|
-
_options.onOver?.(null, event);
|
|
39
|
-
break;
|
|
40
|
-
case "leave":
|
|
41
|
-
counter -= 1, counter === 0 && (isOverDropZone.value = !1, isOverError.value = !1), _options.onLeave?.(null, event);
|
|
42
|
-
break;
|
|
43
|
-
case "drop":
|
|
44
|
-
counter = 0, isOverDropZone.value = !1, isOverError.value = !1, isValid ? (files.value = currentFiles, _options.onDrop?.(currentFiles, event)) : _options.onError?.(currentFiles, event);
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
}, removeEventListeners = function() {
|
|
48
|
-
const targetElement = toValue(target);
|
|
49
|
-
targetElement && (targetElement.removeEventListener("dragenter", dragEnterHandler), targetElement.removeEventListener("dragover", dragOverHandler), targetElement.removeEventListener("dragleave", dragLeaveHandler), targetElement.removeEventListener("drop", dropHandler));
|
|
50
|
-
};
|
|
51
|
-
const _options = typeof options == "function" ? { onDrop: options } : options, multiple = _options.multiple ?? !0, preventDefaultForUnhandled = _options.preventDefaultForUnhandled ?? !1, dragEnterHandler = (event) => handleDragEvent(event, "enter"), dragOverHandler = (event) => handleDragEvent(event, "over"), dragLeaveHandler = (event) => handleDragEvent(event, "leave"), dropHandler = (event) => handleDragEvent(event, "drop");
|
|
52
|
-
watch(() => toValue(target), (element, oldElement) => {
|
|
53
|
-
oldElement && (oldElement.removeEventListener("dragenter", dragEnterHandler), oldElement.removeEventListener("dragover", dragOverHandler), oldElement.removeEventListener("dragleave", dragLeaveHandler), oldElement.removeEventListener("drop", dropHandler)), element && (element.addEventListener("dragenter", dragEnterHandler), element.addEventListener("dragover", dragOverHandler), element.addEventListener("dragleave", dragLeaveHandler), element.addEventListener("drop", dropHandler));
|
|
54
|
-
}, { immediate: !0 }), onBeforeUnmount(() => {
|
|
55
|
-
removeEventListeners();
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
files,
|
|
60
|
-
isOverDropZone,
|
|
61
|
-
isOverError
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
export {
|
|
65
|
-
useDropzone
|
|
66
|
-
};
|
|
1
|
+
import{onBeforeUnmount,ref,shallowRef,toValue,unref,watch}from"vue";import{isClient}from"@maz-ui/utils/helpers/isClient";var isSafariRegex=/^(?:(?!chrome|android).)*safari/i;function useDropzone(target,options={}){let isOverDropZone=ref(!1);let isOverError=ref(!1);let files=shallowRef(null);let counter=0;let isValid=!0;if(isClient()){let _options=typeof options==`function`?{onDrop:options}:options;let multiple=_options.multiple??!0;let preventDefaultForUnhandled=_options.preventDefaultForUnhandled??!1;function getFiles(event){let list=[...event.dataTransfer?.files??[]];return list.length===0?null:multiple?list:[list[0]]}function checkDataTypes(types){let dataTypes=unref(_options.dataTypes);if(typeof dataTypes==`function`)return dataTypes(types);if(!dataTypes||dataTypes?.length===0)return!0;let mimeTypes=dataTypes.filter(type=>!type.startsWith(`.`));if(mimeTypes.length===0)return!0;let validTypes=types.filter(Boolean);return validTypes.length===0?!0:validTypes.every(type=>mimeTypes?.some(allowedType=>type.includes(allowedType)))}function checkValidity(items){return checkDataTypes(Array.from(items??[],item=>item.type))&&(multiple||items.length<=1)}function isSafari(){return isSafariRegex.test(navigator.userAgent)&&!(`chrome`in globalThis)}function handleDragEvent(event,eventType){let dataTransferItemList=event.dataTransfer?.items;isValid=(dataTransferItemList&&checkValidity(dataTransferItemList))??!1,preventDefaultForUnhandled&&event.preventDefault();let currentFiles=getFiles(event);switch(!isSafari()&&!isValid&&event.dataTransfer&&(event.dataTransfer.dropEffect=`none`),event.preventDefault(),event.dataTransfer&&(event.dataTransfer.dropEffect=`copy`),eventType){case`enter`:counter+=1,isOverDropZone.value=!0,isOverError.value=!isValid,_options.onEnter?.(null,event);break;case`over`:_options.onOver?.(null,event);break;case`leave`:--counter,counter===0&&(isOverDropZone.value=!1,isOverError.value=!1),_options.onLeave?.(null,event);break;case`drop`:counter=0,isOverDropZone.value=!1,isOverError.value=!1,isValid?(files.value=currentFiles,_options.onDrop?.(currentFiles,event)):_options.onError?.(currentFiles,event);break}}let dragEnterHandler=event=>handleDragEvent(event,`enter`);let dragOverHandler=event=>handleDragEvent(event,`over`);let dragLeaveHandler=event=>handleDragEvent(event,`leave`);let dropHandler=event=>handleDragEvent(event,`drop`);function removeEventListeners(){let targetElement=toValue(target);targetElement&&(targetElement.removeEventListener(`dragenter`,dragEnterHandler),targetElement.removeEventListener(`dragover`,dragOverHandler),targetElement.removeEventListener(`dragleave`,dragLeaveHandler),targetElement.removeEventListener(`drop`,dropHandler))}watch(()=>toValue(target),(element,oldElement)=>{oldElement&&(oldElement.removeEventListener(`dragenter`,dragEnterHandler),oldElement.removeEventListener(`dragover`,dragOverHandler),oldElement.removeEventListener(`dragleave`,dragLeaveHandler),oldElement.removeEventListener(`drop`,dropHandler)),element&&(element.addEventListener(`dragenter`,dragEnterHandler),element.addEventListener(`dragover`,dragOverHandler),element.addEventListener(`dragleave`,dragLeaveHandler),element.addEventListener(`drop`,dropHandler))},{immediate:!0}),onBeforeUnmount(()=>{removeEventListeners()})}return{files,isOverDropZone,isOverError}}export{useDropzone};
|
|
@@ -1,101 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { computed, onMounted, onUnmounted } from "vue";
|
|
3
|
-
import { e as getContext, f as fieldHasValidation, i as updateFieldState, j as setFieldValidationState, k as getValidationEvents, h as hasModeIncludes, r as removeEventFromInteractiveElements, l as findInteractiveElements, m as addEventToInteractiveElements, n as handleFieldBlur } from "../chunks/dom-events.DTx6Kblx.js";
|
|
4
|
-
import { useFreezeValue } from "./useFreezeValue.js";
|
|
5
|
-
function useFormField(name, options) {
|
|
6
|
-
const opts = {
|
|
7
|
-
formIdentifier: "main-form-validator",
|
|
8
|
-
...options
|
|
9
|
-
}, {
|
|
10
|
-
fieldsStates,
|
|
11
|
-
payload,
|
|
12
|
-
options: formOptions,
|
|
13
|
-
internalSchema,
|
|
14
|
-
errorMessages,
|
|
15
|
-
isSubmitted
|
|
16
|
-
} = getContext(opts.formIdentifier, "useFormField"), finalOpts = opts, fieldMode = fieldHasValidation(name, internalSchema.value) ? options?.mode ?? formOptions.mode : void 0;
|
|
17
|
-
finalOpts.mode = fieldMode;
|
|
18
|
-
const fieldState = computed(() => fieldsStates.value[name]);
|
|
19
|
-
if (fieldsStates.value[name] = updateFieldState({
|
|
20
|
-
name,
|
|
21
|
-
fieldState: fieldState.value,
|
|
22
|
-
payload: payload.value,
|
|
23
|
-
schema: internalSchema.value,
|
|
24
|
-
options: { ...formOptions, ...finalOpts }
|
|
25
|
-
}), finalOpts.defaultValue !== void 0 && !isEqual(payload.value[name], finalOpts.defaultValue)) {
|
|
26
|
-
const initialValue = finalOpts.defaultValue;
|
|
27
|
-
payload.value[name] = initialValue, fieldsStates.value[name].initialValue = useFreezeValue(initialValue);
|
|
28
|
-
}
|
|
29
|
-
fieldMode && setFieldValidationState({
|
|
30
|
-
name,
|
|
31
|
-
fieldState: fieldState.value,
|
|
32
|
-
payload: payload.value,
|
|
33
|
-
schema: internalSchema.value,
|
|
34
|
-
setError: fieldMode === "aggressive",
|
|
35
|
-
setErrorIfInvalidAndNotEmpty: fieldMode === "lazy"
|
|
36
|
-
});
|
|
37
|
-
function onBlur() {
|
|
38
|
-
handleFieldBlur({
|
|
39
|
-
name,
|
|
40
|
-
fieldState: fieldState.value,
|
|
41
|
-
payload: payload.value,
|
|
42
|
-
schema: internalSchema.value,
|
|
43
|
-
isSubmitted: isSubmitted.value
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
const validationEvents = computed(
|
|
47
|
-
() => getValidationEvents({
|
|
48
|
-
hasRef: !!finalOpts.ref?.value,
|
|
49
|
-
onBlur,
|
|
50
|
-
fieldState: fieldState.value
|
|
51
|
-
})
|
|
52
|
-
);
|
|
53
|
-
if (finalOpts.ref && fieldMode && hasModeIncludes(["eager", "blur", "progressive"], fieldMode)) {
|
|
54
|
-
let interactiveElements = [];
|
|
55
|
-
const handleInteractiveElements = (element) => {
|
|
56
|
-
interactiveElements.length > 0 && removeEventFromInteractiveElements({
|
|
57
|
-
interactiveElements,
|
|
58
|
-
onBlur
|
|
59
|
-
}), interactiveElements = findInteractiveElements(element), addEventToInteractiveElements({
|
|
60
|
-
interactiveElements,
|
|
61
|
-
onBlur,
|
|
62
|
-
mode: fieldMode
|
|
63
|
-
});
|
|
64
|
-
};
|
|
65
|
-
onMounted(() => {
|
|
66
|
-
const element = finalOpts.ref?.value, elementToBind = element instanceof HTMLElement ? element : element?.$el;
|
|
67
|
-
if (elementToBind instanceof HTMLElement) {
|
|
68
|
-
handleInteractiveElements(elementToBind);
|
|
69
|
-
return;
|
|
70
|
-
} else if (elementToBind instanceof Text && elementToBind.nextElementSibling instanceof HTMLElement) {
|
|
71
|
-
handleInteractiveElements(elementToBind.nextElementSibling);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
console.warn(`[maz-ui](useFormField) No element found for ref in field '${String(name)}'. Make sure the ref is properly bound to an HTMLElement or Vue component (form identifier: ${String(formOptions.identifier)})`);
|
|
75
|
-
}), onUnmounted(() => {
|
|
76
|
-
removeEventFromInteractiveElements({
|
|
77
|
-
interactiveElements,
|
|
78
|
-
onBlur
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
hasError: computed(() => fieldState.value.error),
|
|
84
|
-
errors: computed(() => fieldState.value.errors),
|
|
85
|
-
errorMessage: computed(() => errorMessages.value[name]),
|
|
86
|
-
isValid: computed(() => fieldState.value.valid),
|
|
87
|
-
isDirty: computed(() => fieldState.value.dirty),
|
|
88
|
-
isBlurred: computed(() => fieldState.value.blurred),
|
|
89
|
-
isValidated: computed(() => fieldState.value.validated),
|
|
90
|
-
isValidating: computed(() => fieldState.value.validating),
|
|
91
|
-
mode: computed(() => fieldState.value.mode),
|
|
92
|
-
value: computed({
|
|
93
|
-
get: () => payload.value[name],
|
|
94
|
-
set: (value) => payload.value[name] = value
|
|
95
|
-
}),
|
|
96
|
-
validationEvents
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
export {
|
|
100
|
-
useFormField
|
|
101
|
-
};
|
|
1
|
+
import{_ as setFieldValidationState,f as hasModeIncludes,i as removeEventFromInteractiveElements,n as findInteractiveElements,o as fieldHasValidation,p as updateFieldState,r as getValidationEvents,s as getContext,t as addEventToInteractiveElements,u as handleFieldBlur}from"../chunks/dom-events.BPrKJiCz.js";import{useFreezeValue}from"./useFreezeValue.js";import{computed,onMounted,onUnmounted}from"vue";import{isEqual}from"@maz-ui/utils/helpers/isEqual";function useFormField(name,options){let opts={formIdentifier:`main-form-validator`,...options};let{fieldsStates,payload,options:formOptions,internalSchema,errorMessages,isSubmitted}=getContext(opts.formIdentifier,`useFormField`);let finalOpts=opts;let fieldMode=fieldHasValidation(name,internalSchema.value)?options?.mode??formOptions.mode:void 0;finalOpts.mode=fieldMode;let fieldState=computed(()=>fieldsStates.value[name]);if(fieldsStates.value[name]=updateFieldState({name,fieldState:fieldState.value,payload:payload.value,schema:internalSchema.value,options:{...formOptions,...finalOpts}}),finalOpts.defaultValue!==void 0&&!isEqual(payload.value[name],finalOpts.defaultValue)){let initialValue=finalOpts.defaultValue;payload.value[name]=initialValue,fieldsStates.value[name].initialValue=useFreezeValue(initialValue)}fieldMode&&setFieldValidationState({name,fieldState:fieldState.value,payload:payload.value,schema:internalSchema.value,setError:fieldMode===`aggressive`,setErrorIfInvalidAndNotEmpty:fieldMode===`lazy`});function onBlur(){handleFieldBlur({name,fieldState:fieldState.value,payload:payload.value,schema:internalSchema.value,isSubmitted:isSubmitted.value})}let validationEvents=computed(()=>getValidationEvents({hasRef:!!finalOpts.ref?.value,onBlur,fieldState:fieldState.value}));if(finalOpts.ref&&fieldMode&&hasModeIncludes([`eager`,`blur`,`progressive`],fieldMode)){let interactiveElements=[];let handleInteractiveElements=element=>{interactiveElements.length>0&&removeEventFromInteractiveElements({interactiveElements,onBlur}),interactiveElements=findInteractiveElements(element),addEventToInteractiveElements({interactiveElements,onBlur,mode:fieldMode})};onMounted(()=>{let element=finalOpts.ref?.value;let elementToBind=element instanceof HTMLElement?element:element?.$el;if(elementToBind instanceof HTMLElement){handleInteractiveElements(elementToBind);return}else if(elementToBind instanceof Text&&elementToBind.nextElementSibling instanceof HTMLElement){handleInteractiveElements(elementToBind.nextElementSibling);return}console.warn(`[maz-ui](useFormField) No element found for ref in field '${String(name)}'. Make sure the ref is properly bound to an HTMLElement or Vue component (form identifier: ${String(formOptions.identifier)})`)}),onUnmounted(()=>{removeEventFromInteractiveElements({interactiveElements,onBlur})})}return{hasError:computed(()=>fieldState.value.error),errors:computed(()=>fieldState.value.errors),errorMessage:computed(()=>errorMessages.value[name]),isValid:computed(()=>fieldState.value.valid),isDirty:computed(()=>fieldState.value.dirty),isBlurred:computed(()=>fieldState.value.blurred),isValidated:computed(()=>fieldState.value.validated),isValidating:computed(()=>fieldState.value.validating),mode:computed(()=>fieldState.value.mode),value:computed({get:()=>payload.value[name],set:value=>payload.value[name]=value}),validationEvents}}export{useFormField};
|
|
@@ -1,163 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { g as getInstance, a as getFieldsStates, b as getFieldsErrors, c as getErrorMessages, u as updateFieldsStates, v as validateForm, C as CONFIG, s as scrollToError, h as hasModeIncludes, d as handleFieldInput } from "../chunks/dom-events.DTx6Kblx.js";
|
|
3
|
-
function createValidationProcessor(fieldsToValidate, fieldsStates, payload, internalSchema, isSubmitted) {
|
|
4
|
-
return () => {
|
|
5
|
-
fieldsToValidate.forEach((name) => {
|
|
6
|
-
const fieldState = fieldsStates.value[name];
|
|
7
|
-
handleFieldInput({
|
|
8
|
-
name,
|
|
9
|
-
fieldState,
|
|
10
|
-
payload: payload.value,
|
|
11
|
-
schema: internalSchema.value,
|
|
12
|
-
isSubmitted: isSubmitted.value,
|
|
13
|
-
forceValidation: !0
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
function useFormValidator({ schema, defaultValues, model, options }) {
|
|
19
|
-
const instance = getInstance("useFormValidator"), opts = {
|
|
20
|
-
mode: CONFIG.mode,
|
|
21
|
-
scrollToError: CONFIG.scrollToErrorSelector,
|
|
22
|
-
debouncedFields: null,
|
|
23
|
-
throttledFields: null,
|
|
24
|
-
identifier: "main-form-validator",
|
|
25
|
-
resetOnSuccess: !0,
|
|
26
|
-
...options
|
|
27
|
-
}, internalDefaultValues = ref(toValue(defaultValues)), payload = ref({ ...internalDefaultValues.value, ...model?.value }), internalSchema = ref(toValue(schema)), fieldsStates = ref(
|
|
28
|
-
getFieldsStates({
|
|
29
|
-
schema: internalSchema.value,
|
|
30
|
-
payload: payload.value,
|
|
31
|
-
options: opts
|
|
32
|
-
})
|
|
33
|
-
), isSubmitting = ref(!1), isSubmitted = ref(!1), isValid = computed(() => {
|
|
34
|
-
for (const key in fieldsStates.value)
|
|
35
|
-
if (!fieldsStates.value[key].valid)
|
|
36
|
-
return !1;
|
|
37
|
-
return !0;
|
|
38
|
-
}), isDirty = computed(() => {
|
|
39
|
-
for (const key in fieldsStates.value)
|
|
40
|
-
if (fieldsStates.value[key].dirty)
|
|
41
|
-
return !0;
|
|
42
|
-
return !1;
|
|
43
|
-
}), errors = computed(() => getFieldsErrors(fieldsStates.value)), errorMessages = computed(() => getErrorMessages(errors.value, fieldsStates.value));
|
|
44
|
-
model && (watch(
|
|
45
|
-
payload,
|
|
46
|
-
(newPayload) => {
|
|
47
|
-
model.value = { ...internalDefaultValues.value, ...newPayload };
|
|
48
|
-
},
|
|
49
|
-
{ deep: !0 }
|
|
50
|
-
), watch(
|
|
51
|
-
model,
|
|
52
|
-
(newModel) => {
|
|
53
|
-
newModel && Object.assign(payload.value, newModel);
|
|
54
|
-
},
|
|
55
|
-
{ deep: !0 }
|
|
56
|
-
)), watch(
|
|
57
|
-
internalDefaultValues,
|
|
58
|
-
(newDefaultValues) => {
|
|
59
|
-
payload.value = { ...newDefaultValues, ...payload.value };
|
|
60
|
-
},
|
|
61
|
-
{ deep: !0 }
|
|
62
|
-
), watch(
|
|
63
|
-
internalSchema,
|
|
64
|
-
(schema2) => {
|
|
65
|
-
updateFieldsStates({
|
|
66
|
-
schema: schema2,
|
|
67
|
-
fieldsStates: fieldsStates.value,
|
|
68
|
-
payload: payload.value,
|
|
69
|
-
options: opts
|
|
70
|
-
}), internalValidateForm();
|
|
71
|
-
},
|
|
72
|
-
{ deep: !0 }
|
|
73
|
-
), internalValidateForm();
|
|
74
|
-
function internalValidateForm(setErrors = opts.mode === "aggressive") {
|
|
75
|
-
return validateForm({
|
|
76
|
-
fieldsStates: fieldsStates.value,
|
|
77
|
-
payload: payload.value,
|
|
78
|
-
schema: internalSchema.value,
|
|
79
|
-
setErrors
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
let payloadWatchStop = null;
|
|
83
|
-
function setupOptimizedWatch() {
|
|
84
|
-
payloadWatchStop && payloadWatchStop();
|
|
85
|
-
const payloadSnapshot = computed(() => {
|
|
86
|
-
const snapshot = {};
|
|
87
|
-
for (const key of Object.keys(internalSchema.value))
|
|
88
|
-
snapshot[key] = payload.value[key];
|
|
89
|
-
return snapshot;
|
|
90
|
-
});
|
|
91
|
-
payloadWatchStop = watch(
|
|
92
|
-
payloadSnapshot,
|
|
93
|
-
(newSnapshot, oldSnapshot) => {
|
|
94
|
-
const fieldsToValidate = Object.keys(internalSchema.value).filter((name) => {
|
|
95
|
-
const fieldState = fieldsStates.value[name];
|
|
96
|
-
return fieldState && newSnapshot[name] !== oldSnapshot?.[name] && hasModeIncludes(["aggressive", "lazy", "progressive"], fieldState.mode);
|
|
97
|
-
});
|
|
98
|
-
if (fieldsToValidate.length > 0) {
|
|
99
|
-
const processValidations = createValidationProcessor(
|
|
100
|
-
fieldsToValidate,
|
|
101
|
-
fieldsStates,
|
|
102
|
-
payload,
|
|
103
|
-
internalSchema,
|
|
104
|
-
isSubmitted
|
|
105
|
-
);
|
|
106
|
-
typeof requestIdleCallback < "u" ? requestIdleCallback(processValidations, { timeout: 100 }) : nextTick(processValidations);
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
{ deep: !0 }
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
function resetForm() {
|
|
113
|
-
payloadWatchStop && payloadWatchStop(), isSubmitting.value = !1, isSubmitted.value = !1, payload.value = { ...internalDefaultValues.value }, fieldsStates.value = getFieldsStates({
|
|
114
|
-
schema: internalSchema.value,
|
|
115
|
-
payload: payload.value,
|
|
116
|
-
options: opts
|
|
117
|
-
}), internalValidateForm(!1), setupOptimizedWatch();
|
|
118
|
-
}
|
|
119
|
-
function handleSubmit(successCallback, enableScrollOrSelector, options2) {
|
|
120
|
-
const finalOptions = {
|
|
121
|
-
resetOnSuccess: options2?.resetOnSuccess ?? opts.resetOnSuccess
|
|
122
|
-
};
|
|
123
|
-
return async (event) => {
|
|
124
|
-
if (event?.preventDefault(), !isSubmitting.value) {
|
|
125
|
-
isSubmitted.value = !0, isSubmitting.value = !0;
|
|
126
|
-
try {
|
|
127
|
-
await internalValidateForm(!0);
|
|
128
|
-
const scrollToErrorParam = typeof enableScrollOrSelector == "string" ? enableScrollOrSelector : opts.scrollToError;
|
|
129
|
-
let response;
|
|
130
|
-
return isValid.value ? (response = await successCallback(payload.value), (finalOptions.resetOnSuccess || options2?.resetOnSuccess) && resetForm()) : typeof scrollToErrorParam != "boolean" && (options2?.onError?.({ model: payload.value, errorMessages: errorMessages.value, errors: errors.value }), scrollToError(scrollToErrorParam)), isSubmitting.value = !1, response;
|
|
131
|
-
} finally {
|
|
132
|
-
isSubmitting.value = !1;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
const context = {
|
|
138
|
-
fieldsStates,
|
|
139
|
-
payload,
|
|
140
|
-
options: opts,
|
|
141
|
-
internalSchema,
|
|
142
|
-
errorMessages,
|
|
143
|
-
isSubmitted
|
|
144
|
-
};
|
|
145
|
-
return instance.formContexts ??= /* @__PURE__ */ new Map(), instance.formContexts.set(opts.identifier, context), provide(opts.identifier, context), setupOptimizedWatch(), {
|
|
146
|
-
identifier: opts.identifier,
|
|
147
|
-
isDirty,
|
|
148
|
-
isSubmitting,
|
|
149
|
-
isSubmitted,
|
|
150
|
-
isValid,
|
|
151
|
-
errors,
|
|
152
|
-
model: payload,
|
|
153
|
-
fieldsStates,
|
|
154
|
-
validateForm: internalValidateForm,
|
|
155
|
-
scrollToError,
|
|
156
|
-
resetForm,
|
|
157
|
-
handleSubmit,
|
|
158
|
-
errorMessages
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
export {
|
|
162
|
-
useFormValidator
|
|
163
|
-
};
|
|
1
|
+
import{a as scrollToError,c as getFieldsStates,d as handleFieldInput,f as hasModeIncludes,g as getFieldsErrors,h as getErrorMessages,l as getInstance,m as updateFieldsStates,v as validateForm,y as CONFIG}from"../chunks/dom-events.BPrKJiCz.js";import{computed,nextTick,provide,ref,toValue,watch}from"vue";function createValidationProcessor(fieldsToValidate,fieldsStates,payload,internalSchema,isSubmitted){return()=>{fieldsToValidate.forEach(name=>{let fieldState=fieldsStates.value[name];handleFieldInput({name,fieldState,payload:payload.value,schema:internalSchema.value,isSubmitted:isSubmitted.value,forceValidation:!0})})}}function useFormValidator({schema,defaultValues,model,options}){let instance=getInstance(`useFormValidator`);let opts={mode:CONFIG.mode,scrollToError:CONFIG.scrollToErrorSelector,debouncedFields:null,throttledFields:null,identifier:`main-form-validator`,resetOnSuccess:!0,...options};let internalDefaultValues=ref(toValue(defaultValues));let payload=ref({...internalDefaultValues.value,...model?.value});let internalSchema=ref(toValue(schema));let fieldsStates=ref(getFieldsStates({schema:internalSchema.value,payload:payload.value,options:opts}));let isSubmitting=ref(!1);let isSubmitted=ref(!1);let isValid=computed(()=>{for(let key in fieldsStates.value)if(!fieldsStates.value[key].valid)return!1;return!0});let isDirty=computed(()=>{for(let key in fieldsStates.value)if(fieldsStates.value[key].dirty)return!0;return!1});let errors=computed(()=>getFieldsErrors(fieldsStates.value));let errorMessages=computed(()=>getErrorMessages(errors.value,fieldsStates.value));model&&(watch(payload,newPayload=>{model.value={...internalDefaultValues.value,...newPayload}},{deep:!0}),watch(model,newModel=>{newModel&&Object.assign(payload.value,newModel)},{deep:!0})),watch(internalDefaultValues,newDefaultValues=>{payload.value={...newDefaultValues,...payload.value}},{deep:!0}),watch(internalSchema,schema=>{updateFieldsStates({schema,fieldsStates:fieldsStates.value,payload:payload.value,options:opts}),internalValidateForm()},{deep:!0}),internalValidateForm();function internalValidateForm(setErrors=opts.mode===`aggressive`){return validateForm({fieldsStates:fieldsStates.value,payload:payload.value,schema:internalSchema.value,setErrors})}let payloadWatchStop=null;function setupOptimizedWatch(){payloadWatchStop&&payloadWatchStop(),payloadWatchStop=watch(computed(()=>{let snapshot={};for(let key of Object.keys(internalSchema.value))snapshot[key]=payload.value[key];return snapshot}),(newSnapshot,oldSnapshot)=>{let fieldsToValidate=Object.keys(internalSchema.value).filter(name=>{let fieldState=fieldsStates.value[name];return fieldState&&newSnapshot[name]!==oldSnapshot?.[name]&&hasModeIncludes([`aggressive`,`lazy`,`progressive`],fieldState.mode)});if(fieldsToValidate.length>0){let processValidations=createValidationProcessor(fieldsToValidate,fieldsStates,payload,internalSchema,isSubmitted);typeof requestIdleCallback<`u`?requestIdleCallback(processValidations,{timeout:100}):nextTick(processValidations)}},{deep:!0})}function resetForm(){payloadWatchStop&&payloadWatchStop(),isSubmitting.value=!1,isSubmitted.value=!1,payload.value={...internalDefaultValues.value},fieldsStates.value=getFieldsStates({schema:internalSchema.value,payload:payload.value,options:opts}),internalValidateForm(!1),setupOptimizedWatch()}function handleSubmit(successCallback,enableScrollOrSelector,options){let finalOptions={resetOnSuccess:options?.resetOnSuccess??opts.resetOnSuccess};return async event=>{if(event?.preventDefault(),!isSubmitting.value){isSubmitted.value=!0,isSubmitting.value=!0;try{await internalValidateForm(!0);let scrollToErrorParam=typeof enableScrollOrSelector==`string`?enableScrollOrSelector:opts.scrollToError;let response;return isValid.value?(response=await successCallback(payload.value),(finalOptions.resetOnSuccess||options?.resetOnSuccess)&&resetForm()):typeof scrollToErrorParam!=`boolean`&&(options?.onError?.({model:payload.value,errorMessages:errorMessages.value,errors:errors.value}),scrollToError(scrollToErrorParam)),isSubmitting.value=!1,response}finally{isSubmitting.value=!1}}}}let context={fieldsStates,payload,options:opts,internalSchema,errorMessages,isSubmitted};return instance.formContexts??=new Map,instance.formContexts.set(opts.identifier,context),provide(opts.identifier,context),setupOptimizedWatch(),{identifier:opts.identifier,isDirty,isSubmitting,isSubmitted,isValid,errors,model:payload,fieldsStates,validateForm:internalValidateForm,scrollToError,resetForm,handleSubmit,errorMessages}}export{useFormValidator};
|
|
@@ -1,8 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
function useFreezeValue(value) {
|
|
3
|
-
const rawValue = toValue(value);
|
|
4
|
-
return Array.isArray(rawValue) ? Object.freeze([...rawValue]) : typeof rawValue == "object" && rawValue !== null ? Object.freeze({ ...rawValue }) : rawValue;
|
|
5
|
-
}
|
|
6
|
-
export {
|
|
7
|
-
useFreezeValue
|
|
8
|
-
};
|
|
1
|
+
import{toValue}from"vue";function useFreezeValue(value){let rawValue=toValue(value);return Array.isArray(rawValue)?Object.freeze([...rawValue]):typeof rawValue==`object`&&rawValue?Object.freeze({...rawValue}):rawValue}export{useFreezeValue};
|
|
@@ -1,10 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
function useIdleTimeout({
|
|
3
|
-
callback,
|
|
4
|
-
options
|
|
5
|
-
}) {
|
|
6
|
-
return new IdleTimeout(callback, options);
|
|
7
|
-
}
|
|
8
|
-
export {
|
|
9
|
-
useIdleTimeout
|
|
10
|
-
};
|
|
1
|
+
import{IdleTimeout}from"@maz-ui/utils/helpers/idleTimeout";function useIdleTimeout({callback,options}){return new IdleTimeout(callback,options)}export{useIdleTimeout};
|
|
@@ -1,10 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
function useInjectStrict(key, fallback, errorMessage) {
|
|
3
|
-
const resolved = inject(key, fallback);
|
|
4
|
-
if (!resolved)
|
|
5
|
-
throw new TypeError(errorMessage || `[maz-ui](injectStrict) Could not resolve ${key.toString()}`);
|
|
6
|
-
return resolved;
|
|
7
|
-
}
|
|
8
|
-
export {
|
|
9
|
-
useInjectStrict
|
|
10
|
-
};
|
|
1
|
+
import{inject}from"vue";function useInjectStrict(key,fallback,errorMessage){let resolved=inject(key,fallback);if(!resolved)throw TypeError(errorMessage||`[maz-ui](injectStrict) Could not resolve ${key.toString()}`);return resolved}export{useInjectStrict};
|
|
@@ -1,12 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
const pointRegex = /:/g;
|
|
3
|
-
function useInstanceUniqId({
|
|
4
|
-
componentName,
|
|
5
|
-
providedId
|
|
6
|
-
}) {
|
|
7
|
-
const generatedId = useId();
|
|
8
|
-
return computed(() => providedId || `${componentName}-${generatedId.replace(pointRegex, "")}`);
|
|
9
|
-
}
|
|
10
|
-
export {
|
|
11
|
-
useInstanceUniqId
|
|
12
|
-
};
|
|
1
|
+
import{computed,useId}from"vue";var pointRegex=/:/g;function useInstanceUniqId({componentName,providedId}){let generatedId=useId();return computed(()=>providedId||`${componentName}-${generatedId.replace(pointRegex,``)}`)}export{useInstanceUniqId};
|
|
@@ -1,16 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
function useMountComponent(component, options) {
|
|
3
|
-
const el = options?.element ?? document.createElement("div");
|
|
4
|
-
function destroy() {
|
|
5
|
-
el && render(null, el);
|
|
6
|
-
}
|
|
7
|
-
const props = { ...options?.props, destroy }, vNode = createVNode(
|
|
8
|
-
component,
|
|
9
|
-
props,
|
|
10
|
-
options?.children
|
|
11
|
-
);
|
|
12
|
-
return options?.app && (vNode.appContext = options.app._context), options?.noRender || render(vNode, el), { vNode, destroy, el };
|
|
13
|
-
}
|
|
14
|
-
export {
|
|
15
|
-
useMountComponent
|
|
16
|
-
};
|
|
1
|
+
import{createVNode,render}from"vue";function useMountComponent(component,options){let el=options?.element??document.createElement(`div`);function destroy(){el&&render(null,el)}let vNode=createVNode(component,{...options?.props,destroy},options?.children);return options?.app&&(vNode.appContext=options.app._context),options?.noRender||render(vNode,el),{vNode,destroy,el}}export{useMountComponent};
|
|
@@ -1,37 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { truthyFilter } from "@maz-ui/utils/helpers/truthyFilter";
|
|
3
|
-
import { ref, onMounted, computed, toValue, watch } from "vue";
|
|
4
|
-
function useMutationObserver(target, callback, options = {}) {
|
|
5
|
-
const {
|
|
6
|
-
internalWindow = isClient() ? globalThis : void 0,
|
|
7
|
-
...mutationOptions
|
|
8
|
-
} = options;
|
|
9
|
-
let observer;
|
|
10
|
-
const isSupported = ref((internalWindow && "MutationObserver" in internalWindow) ?? !1);
|
|
11
|
-
isSupported.value || onMounted(() => {
|
|
12
|
-
isSupported.value = (internalWindow && "MutationObserver" in internalWindow) ?? !1;
|
|
13
|
-
});
|
|
14
|
-
const cleanup = () => {
|
|
15
|
-
observer && (observer.disconnect(), observer = void 0);
|
|
16
|
-
}, targets = computed(() => {
|
|
17
|
-
const value = toValue(target);
|
|
18
|
-
let element;
|
|
19
|
-
return value && "$el" in value ? element = value.$el : value && (element = value), new Set([element].filter(truthyFilter));
|
|
20
|
-
}), stopWatch = watch(
|
|
21
|
-
[targets, isSupported],
|
|
22
|
-
([newTargets, isSupported2]) => {
|
|
23
|
-
cleanup(), isSupported2 && newTargets.size && (observer = new MutationObserver(callback), newTargets.forEach((el) => observer?.observe(el, mutationOptions)));
|
|
24
|
-
},
|
|
25
|
-
{ immediate: !0, flush: "post" }
|
|
26
|
-
);
|
|
27
|
-
return {
|
|
28
|
-
isSupported,
|
|
29
|
-
stop: () => {
|
|
30
|
-
stopWatch(), cleanup();
|
|
31
|
-
},
|
|
32
|
-
takeRecords: () => observer?.takeRecords()
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
export {
|
|
36
|
-
useMutationObserver
|
|
37
|
-
};
|
|
1
|
+
import{computed,onMounted,ref,toValue,watch}from"vue";import{truthyFilter}from"@maz-ui/utils/helpers/truthyFilter";import{isClient}from"@maz-ui/utils/helpers/isClient";function useMutationObserver(target,callback,options={}){let{internalWindow=isClient()?globalThis:void 0,...mutationOptions}=options;let observer;let isSupported=ref((internalWindow&&`MutationObserver`in internalWindow)??!1);isSupported.value||onMounted(()=>{isSupported.value=(internalWindow&&`MutationObserver`in internalWindow)??!1});let cleanup=()=>{observer&&=(observer.disconnect(),void 0)};let stopWatch=watch([computed(()=>{let value=toValue(target);let element;return value&&`$el`in value?element=value.$el:value&&(element=value),new Set([element].filter(truthyFilter))}),isSupported],([newTargets,isSupported])=>{cleanup(),isSupported&&newTargets.size&&(observer=new MutationObserver(callback),newTargets.forEach(el=>observer?.observe(el,mutationOptions)))},{immediate:!0,flush:`post`});return{isSupported,stop:()=>{stopWatch(),cleanup()},takeRecords:()=>observer?.takeRecords()}}export{useMutationObserver};
|
|
@@ -1,33 +1 @@
|
|
|
1
|
-
import { computed }
|
|
2
|
-
const wordRegex = /\b\w+\b/g;
|
|
3
|
-
function countWords(text) {
|
|
4
|
-
const words = text.join(", ").match(wordRegex);
|
|
5
|
-
return words ? words.length : 0;
|
|
6
|
-
}
|
|
7
|
-
function getReadTimeInMinutes(content, velocity = 150) {
|
|
8
|
-
const words = countWords([content]);
|
|
9
|
-
return Math.ceil(words / velocity);
|
|
10
|
-
}
|
|
11
|
-
function useReadingTime(options) {
|
|
12
|
-
const velocity = computed(
|
|
13
|
-
() => typeof options.velocity == "number" ? options.velocity : options.velocity?.value ?? 150
|
|
14
|
-
), selector = computed(() => typeof options.contentSelector == "string" ? options.contentSelector : options.contentSelector?.value), content = computed(() => {
|
|
15
|
-
if (typeof options.contentRef?.value == "object")
|
|
16
|
-
return options.contentRef.value?.textContent;
|
|
17
|
-
if (selector.value && typeof document < "u") {
|
|
18
|
-
const contentElement = document.querySelector(selector.value);
|
|
19
|
-
if (contentElement)
|
|
20
|
-
return contentElement.textContent;
|
|
21
|
-
}
|
|
22
|
-
return typeof options.content == "string" ? options.content : options.content?.value;
|
|
23
|
-
}), duration = computed(() => getReadTimeInMinutes(content.value, velocity.value)), wordCount = computed(() => countWords([content.value]));
|
|
24
|
-
return {
|
|
25
|
-
content,
|
|
26
|
-
wordCount,
|
|
27
|
-
velocity,
|
|
28
|
-
duration
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
export {
|
|
32
|
-
useReadingTime
|
|
33
|
-
};
|
|
1
|
+
import{computed}from"vue";var wordRegex=/\b\w+\b/g;function countWords(text){let words=text.join(`, `).match(wordRegex);return words?words.length:0}function getReadTimeInMinutes(content,velocity=150){let words=countWords([content]);return Math.ceil(words/velocity)}function useReadingTime(options){let velocity=computed(()=>typeof options.velocity==`number`?options.velocity:options.velocity?.value??150);let selector=computed(()=>typeof options.contentSelector==`string`?options.contentSelector:options.contentSelector?.value);let content=computed(()=>{if(typeof options.contentRef?.value==`object`)return options.contentRef.value?.textContent;if(selector.value&&typeof document<`u`){let contentElement=document.querySelector(selector.value);if(contentElement)return contentElement.textContent}return typeof options.content==`string`?options.content:options.content?.value});let duration=computed(()=>getReadTimeInMinutes(content.value,velocity.value));return{content,wordCount:computed(()=>countWords([content.value])),velocity,duration}}export{useReadingTime};
|
|
@@ -1,42 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { computed, toValue } from "vue";
|
|
3
|
-
function levenshteinDistance(string1, string2) {
|
|
4
|
-
const length1 = string1.length, length2 = string2.length, matrix = [];
|
|
5
|
-
for (let index = 0; index <= length1; index++)
|
|
6
|
-
matrix[index] = [index];
|
|
7
|
-
for (let index = 0; index <= length2; index++)
|
|
8
|
-
matrix[0][index] = index;
|
|
9
|
-
for (let index = 1; index <= length1; index++)
|
|
10
|
-
for (let index_ = 1; index_ <= length2; index_++) {
|
|
11
|
-
const cost = string1[index - 1] === string2[index_ - 1] ? 0 : 1;
|
|
12
|
-
matrix[index][index_] = Math.min(
|
|
13
|
-
matrix[index - 1][index_] + 1,
|
|
14
|
-
matrix[index][index_ - 1] + 1,
|
|
15
|
-
matrix[index - 1][index_ - 1] + cost
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
return matrix[length1][length2];
|
|
19
|
-
}
|
|
20
|
-
function getMatchingScore(string1, string2) {
|
|
21
|
-
const distance = levenshteinDistance(string1, string2), maxLength = Math.max(string1.length, string2.length);
|
|
22
|
-
return maxLength === 0 ? 1 : 1 - distance / maxLength;
|
|
23
|
-
}
|
|
24
|
-
function getMatchingResults(string1, string2, threshold = 0.75) {
|
|
25
|
-
return getMatchingScore(string1, string2) >= threshold;
|
|
26
|
-
}
|
|
27
|
-
function useStringMatching(string1, string2, threshold = 0.75) {
|
|
28
|
-
const _string1 = computed(
|
|
29
|
-
() => normalizeString(toValue(string1))
|
|
30
|
-
), _string2 = computed(
|
|
31
|
-
() => normalizeString(toValue(string2))
|
|
32
|
-
), score = computed(() => getMatchingScore(_string1.value, _string2.value));
|
|
33
|
-
return {
|
|
34
|
-
isMatching: computed(
|
|
35
|
-
() => getMatchingResults(_string1.value, _string2.value, toValue(threshold))
|
|
36
|
-
),
|
|
37
|
-
score
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
export {
|
|
41
|
-
useStringMatching
|
|
42
|
-
};
|
|
1
|
+
import{computed,toValue}from"vue";import{normalizeString}from"@maz-ui/utils/helpers/normalizeString";function levenshteinDistance(string1,string2){let length1=string1.length;let length2=string2.length;let matrix=[];for(let index=0;index<=length1;index++)matrix[index]=[index];for(let index=0;index<=length2;index++)matrix[0][index]=index;for(let index=1;index<=length1;index++)for(let index_=1;index_<=length2;index_++){let cost=string1[index-1]===string2[index_-1]?0:1;matrix[index][index_]=Math.min(matrix[index-1][index_]+1,matrix[index][index_-1]+1,matrix[index-1][index_-1]+cost)}return matrix[length1][length2]}function getMatchingScore(string1,string2){let distance=levenshteinDistance(string1,string2);let maxLength=Math.max(string1.length,string2.length);return maxLength===0?1:1-distance/maxLength}function getMatchingResults(string1,string2,threshold=.75){return getMatchingScore(string1,string2)>=threshold}function useStringMatching(string1,string2,threshold=.75){let _string1=computed(()=>normalizeString(toValue(string1)));let _string2=computed(()=>normalizeString(toValue(string2)));let score=computed(()=>getMatchingScore(_string1.value,_string2.value));return{isMatching:computed(()=>getMatchingResults(_string1.value,_string2.value,toValue(threshold))),score}}export{useStringMatching};
|
|
@@ -1,26 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ref, computed, toValue } from "vue";
|
|
3
|
-
function useSwipe(options) {
|
|
4
|
-
const xDiff = ref(), yDiff = ref(), xStart = ref(), xEnd = ref(), yStart = ref(), yEnd = ref(), element = computed(() => toValue(options.element)), swiper = new Swipe({
|
|
5
|
-
...options,
|
|
6
|
-
element: element.value,
|
|
7
|
-
onValuesChanged(values) {
|
|
8
|
-
xDiff.value = values.xDiff, yDiff.value = values.yDiff, xStart.value = values.xStart, xEnd.value = values.xEnd, yStart.value = values.yStart, yEnd.value = values.yEnd;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
return {
|
|
12
|
-
xDiff,
|
|
13
|
-
yDiff,
|
|
14
|
-
xStart,
|
|
15
|
-
xEnd,
|
|
16
|
-
yStart,
|
|
17
|
-
yEnd,
|
|
18
|
-
start: () => {
|
|
19
|
-
element.value && (swiper.options.element = element.value), swiper.start();
|
|
20
|
-
},
|
|
21
|
-
stop: swiper.stop
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
export {
|
|
25
|
-
useSwipe
|
|
26
|
-
};
|
|
1
|
+
import{computed,ref,toValue}from"vue";import{Swipe}from"@maz-ui/utils/helpers/swipeHandler";function useSwipe(options){let xDiff=ref();let yDiff=ref();let xStart=ref();let xEnd=ref();let yStart=ref();let yEnd=ref();let element=computed(()=>toValue(options.element));let swiper=new Swipe({...options,element:element.value,onValuesChanged(values){xDiff.value=values.xDiff,yDiff.value=values.yDiff,xStart.value=values.xStart,xEnd.value=values.xEnd,yStart.value=values.yStart,yEnd.value=values.yEnd}});return{xDiff,yDiff,xStart,xEnd,yStart,yEnd,start:()=>{element.value&&(swiper.options.element=element.value),swiper.start()},stop:swiper.stop}}export{useSwipe};
|
|
@@ -1,36 +1 @@
|
|
|
1
|
-
import { ref }
|
|
2
|
-
function useTimer({ timeout = 1e3, callback, remainingTimeUpdate = 200, callbackOffsetTime = 0 }) {
|
|
3
|
-
const internalTimeout = ref(timeout), remainingTime = ref(timeout);
|
|
4
|
-
let timerId;
|
|
5
|
-
function start(timeout2) {
|
|
6
|
-
typeof timeout2 == "number" && (remainingTime.value = timeout2), typeof timeout2 == "number" && (internalTimeout.value = timeout2), startInterval();
|
|
7
|
-
}
|
|
8
|
-
function startInterval() {
|
|
9
|
-
timerId || (timerId = setInterval(() => {
|
|
10
|
-
remainingTime.value -= remainingTimeUpdate, remainingTime.value <= 0 && (stop(), setTimeout(() => callback?.(), callbackOffsetTime));
|
|
11
|
-
}, remainingTimeUpdate));
|
|
12
|
-
}
|
|
13
|
-
function pause() {
|
|
14
|
-
timerId && (clearInterval(timerId), timerId = void 0);
|
|
15
|
-
}
|
|
16
|
-
function resume() {
|
|
17
|
-
!timerId && remainingTime.value > 0 && startInterval();
|
|
18
|
-
}
|
|
19
|
-
function stop() {
|
|
20
|
-
setTimeout(() => remainingTime.value = internalTimeout.value, callbackOffsetTime * 2), pause();
|
|
21
|
-
}
|
|
22
|
-
function reset() {
|
|
23
|
-
remainingTime.value = internalTimeout.value;
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
remainingTime,
|
|
27
|
-
start,
|
|
28
|
-
pause,
|
|
29
|
-
resume,
|
|
30
|
-
stop,
|
|
31
|
-
reset
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
export {
|
|
35
|
-
useTimer
|
|
36
|
-
};
|
|
1
|
+
import{ref}from"vue";function useTimer({timeout=1e3,callback,remainingTimeUpdate=200,callbackOffsetTime=0}){let internalTimeout=ref(timeout);let remainingTime=ref(timeout);let timerId;function start(timeout){typeof timeout==`number`&&(remainingTime.value=timeout),typeof timeout==`number`&&(internalTimeout.value=timeout),startInterval()}function startInterval(){timerId||=setInterval(()=>{remainingTime.value-=remainingTimeUpdate,remainingTime.value<=0&&(stop(),setTimeout(()=>callback?.(),callbackOffsetTime))},remainingTimeUpdate)}function pause(){timerId&&=(clearInterval(timerId),void 0)}function resume(){!timerId&&remainingTime.value>0&&startInterval()}function stop(){setTimeout(()=>remainingTime.value=internalTimeout.value,callbackOffsetTime*2),pause()}function reset(){remainingTime.value=internalTimeout.value}return{remainingTime,start,pause,resume,stop,reset}}export{useTimer};
|
|
@@ -1,14 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
function useToast() {
|
|
3
|
-
const toast = useInjectStrict("mazToast", void 0, "[maz-ui](useToast) ToastPlugin is not installed");
|
|
4
|
-
return {
|
|
5
|
-
message: toast.message.bind(toast),
|
|
6
|
-
success: toast.success.bind(toast),
|
|
7
|
-
error: toast.error.bind(toast),
|
|
8
|
-
info: toast.info.bind(toast),
|
|
9
|
-
warning: toast.warning.bind(toast)
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
export {
|
|
13
|
-
useToast
|
|
14
|
-
};
|
|
1
|
+
import{useInjectStrict}from"./useInjectStrict.js";function useToast(){let toast=useInjectStrict(`mazToast`,void 0,`[maz-ui](useToast) ToastPlugin is not installed`);return{message:toast.message.bind(toast),success:toast.success.bind(toast),error:toast.error.bind(toast),info:toast.info.bind(toast),warning:toast.warning.bind(toast)}}export{useToast};
|
|
@@ -1,10 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
function useUserVisibility({
|
|
3
|
-
callback,
|
|
4
|
-
options
|
|
5
|
-
}) {
|
|
6
|
-
return new UserVisibility(callback, options);
|
|
7
|
-
}
|
|
8
|
-
export {
|
|
9
|
-
useUserVisibility
|
|
10
|
-
};
|
|
1
|
+
import{UserVisibility}from"@maz-ui/utils/helpers/userVisibility";function useUserVisibility({callback,options}){return new UserVisibility(callback,options)}export{useUserVisibility};
|