inertia-bootstrap-forms 4.0.5 → 4.0.7

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.
@@ -1 +1 @@
1
- "use strict";var s=Object.create;var d=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var c=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var g=(e,n,a,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of f(n))!y.call(e,t)&&t!==a&&d(e,t,{get:()=>n[t],enumerable:!(o=m(n,t))||o.enumerable});return e};var v=(e,n,a)=>(a=e!=null?s(c(e)):{},g(n||!e||!e.__esModule?d(a,"default",{value:e,enumerable:!0}):a,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("vue"),u=require("./chunks/_plugin-vue_export-helper-BHyUve4F.cjs"),P=l.defineAsyncComponent(()=>import("vue3-persian-datetime-picker")),k=l.defineComponent({name:"PersianDatePickerInput",components:{Vue3PersianDatetimePicker:P},emits:["update:modelValue","change","open","close"],props:{...u.fieldProps,calendar:{type:String,default:"date"},view:{type:String,default:"date"},min:{type:String,default:null},max:{type:String,default:null},range:{type:Boolean,default:!1},locale:{type:String,default:"fa"},format:{type:String,default:"jYYYY/jMM/jDD"},inputFormat:{type:String,default:null},placeholder:{type:String,default:null},inputClass:{type:String,default:"form-control fanum"},pickerOptions:{type:Object,default:()=>({})}},setup(e,{emit:n,expose:a}){const o=u.useField(e,n),t=l.ref(!1);return l.onMounted(()=>{t.value=!0}),l.watch(()=>o.model.value,(p,r)=>n("change",p,r)),a({clear:()=>o.model.value=null}),{...o,ready:t}}}),S=["placeholder"];function b(e,n,a,o,t,p){const r=l.resolveComponent("Vue3PersianDatetimePicker");return e.ready?(l.openBlock(),l.createBlock(r,l.mergeProps({key:0,modelValue:e.model,"onUpdate:modelValue":n[0]||(n[0]=i=>e.model=i),name:e.name,id:e.inputId,type:e.calendar,view:e.view,min:e.min,max:e.max,range:e.range,locale:e.locale,format:e.format,"input-format":e.inputFormat||e.format,placeholder:e.placeholder,disabled:e.isDisabled||e.readonly,"input-class":[e.inputClass,{"is-invalid":e.isInvalid}],editable:"",jumpminute:"15",roundminute:!0,"show-now-btn":!0,"auto-submit":!0},e.pickerOptions,{onOpen:n[1]||(n[1]=i=>e.$emit("open")),onClose:n[2]||(n[2]=i=>e.$emit("close"))}),null,16,["modelValue","name","id","type","view","min","max","range","locale","format","input-format","placeholder","disabled","input-class"])):(l.openBlock(),l.createElementBlock("input",{key:1,type:"text",class:l.normalizeClass(["form-control",{"is-invalid":e.isInvalid}]),placeholder:e.placeholder,disabled:""},null,10,S))}const D=u._export_sfc(k,[["render",b]]);exports.PersianDatePickerInput=D;
1
+ "use strict";var f=Object.create;var u=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var k=(e,t,n,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of c(t))!g.call(e,o)&&o!==n&&u(e,o,{get:()=>t[o],enumerable:!(l=C(t,o))||l.enumerable});return e};var y=(e,t,n)=>(n=e!=null?f(h(e)):{},k(t||!e||!e.__esModule?u(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("vue"),s=require("./chunks/_plugin-vue_export-helper-BHyUve4F.cjs"),v=a.defineAsyncComponent(()=>import("vue3-persian-datetime-picker"));function w(){var o;if(typeof document>"u")return"en";const e=document.documentElement,t=(e.getAttribute("lang")||"").toLowerCase(),n=(e.getAttribute("dir")||((o=document.body)==null?void 0:o.getAttribute("dir"))||"").toLowerCase();return t?t.startsWith("fa")||n==="rtl"&&!t?"fa":"en":n==="rtl"||(typeof navigator<"u"&&navigator.language||"").toLowerCase().startsWith("fa")?"fa":"en"}const b=a.defineComponent({name:"PersianDatePickerInput",components:{Vue3PersianDatetimePicker:v},emits:["update:modelValue","change","open","close"],props:{...s.fieldProps,calendar:{type:String,default:"date"},view:{type:String,default:"date"},min:{type:String,default:null},max:{type:String,default:null},range:{type:Boolean,default:!1},locale:{type:String,default:"auto"},format:{type:String,default:"jYYYY/jMM/jDD"},inputFormat:{type:String,default:null},editable:{type:Boolean,default:!1},simple:{type:Boolean,default:!1},placeholder:{type:String,default:null},inputClass:{type:String,default:"fanum"},pickerOptions:{type:Object,default:()=>({})}},setup(e,{emit:t,expose:n}){const l=s.useField(e,t),o=l.inputId,d=a.ref(!1),i=a.ref("en");a.onMounted(()=>{i.value=w(),d.value=!0});const r=a.computed(()=>e.locale==="auto"?i.value:e.locale);return a.watch(()=>l.model.value,(p,m)=>t("change",p,m)),n({clear:()=>l.model.value=null}),{...l,inputID:o,ready:d,resolvedLocale:r,showCalendar:V}}});let V=a.ref(!1);const M={class:"form-control form-adorn form-persian-datepicker form-adorn-end"},P=["id","name","placeholder","disabled"];function D(e,t,n,l,o,d){const i=a.resolveComponent("Vue3PersianDatetimePicker");return a.openBlock(),a.createElementBlock("div",null,[a.createElementVNode("label",M,[a.createElementVNode("span",{onClick:t[0]||(t[0]=r=>e.showCalendar=!0),class:"form-adorn-icon","aria-hidden":"true"},t[4]||(t[4]=[a.createStaticVNode('<svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M14 22H10C6.22876 22 4.34315 22 3.17157 20.8284C2 19.6569 2 17.7712 2 14V12C2 8.22876 2 6.34315 3.17157 5.17157C4.34315 4 6.22876 4 10 4H14C17.7712 4 19.6569 4 20.8284 5.17157C22 6.34315 22 8.22876 22 12V14C22 17.7712 22 19.6569 20.8284 20.8284C20.1752 21.4816 19.3001 21.7706 18 21.8985" stroke="#1C274C" stroke-width="1.5" stroke-linecap="round"></path><path d="M7 4V2.5" stroke="#1C274C" stroke-width="1.5" stroke-linecap="round"></path><path d="M17 4V2.5" stroke="#1C274C" stroke-width="1.5" stroke-linecap="round"></path><path d="M21.5 9H16.625H10.75M2 9H5.875" stroke="#1C274C" stroke-width="1.5" stroke-linecap="round"></path><path d="M18 17C18 17.5523 17.5523 18 17 18C16.4477 18 16 17.5523 16 17C16 16.4477 16.4477 16 17 16C17.5523 16 18 16.4477 18 17Z" fill="#1C274C"></path><path d="M18 13C18 13.5523 17.5523 14 17 14C16.4477 14 16 13.5523 16 13C16 12.4477 16.4477 12 17 12C17.5523 12 18 12.4477 18 13Z" fill="#1C274C"></path><path d="M13 17C13 17.5523 12.5523 18 12 18C11.4477 18 11 17.5523 11 17C11 16.4477 11.4477 16 12 16C12.5523 16 13 16.4477 13 17Z" fill="#1C274C"></path><path d="M13 13C13 13.5523 12.5523 14 12 14C11.4477 14 11 13.5523 11 13C11 12.4477 11.4477 12 12 12C12.5523 12 13 12.4477 13 13Z" fill="#1C274C"></path><path d="M8 17C8 17.5523 7.55228 18 7 18C6.44772 18 6 17.5523 6 17C6 16.4477 6.44772 16 7 16C7.55228 16 8 16.4477 8 17Z" fill="#1C274C"></path><path d="M8 13C8 13.5523 7.55228 14 7 14C6.44772 14 6 13.5523 6 13C6 12.4477 6.44772 12 7 12C7.55228 12 8 12.4477 8 13Z" fill="#1C274C"></path></svg>',1)])),a.createElementVNode("input",{id:e.inputID,type:"text",autocomplete:"off",name:e.name,class:a.normalizeClass([e.inputClass,"form-ghost",{"is-invalid":e.isInvalid}]),placeholder:e.placeholder,disabled:e.isDisabled||e.readonly},null,10,P)]),e.ready?(a.openBlock(),a.createBlock(i,a.mergeProps({key:0,modelValue:e.model,"onUpdate:modelValue":t[1]||(t[1]=r=>e.model=r),"custom-input":"#"+e.inputID,type:e.calendar,view:e.view,min:e.min,max:e.max,show:e.showCalendar,range:e.range,locale:e.resolvedLocale,format:e.format,"input-format":e.inputFormat||e.format,disabled:e.isDisabled||e.readonly,editable:e.editable,simple:e.simple,jumpminute:"15",roundminute:!0,"show-now-btn":!0,"auto-submit":!0},e.pickerOptions,{onOpen:t[2]||(t[2]=r=>e.$emit("open")),onClose:t[3]||(t[3]=()=>{e.showCalendar=!1,e.$emit("close")})}),null,16,["modelValue","custom-input","type","view","min","max","show","range","locale","format","input-format","disabled","editable","simple"])):a.createCommentVNode("",!0)])}const S=s._export_sfc(b,[["render",D]]);exports.PersianDatePickerInput=S;
@@ -1,73 +1,98 @@
1
- import { defineComponent as d, resolveComponent as s, createBlock as u, createElementBlock as m, openBlock as p, mergeProps as f, normalizeClass as y, defineAsyncComponent as c, ref as g, onMounted as v, watch as k } from "vue";
2
- import { _ as P, f as S, u as b } from "./chunks/_plugin-vue_export-helper-13TPlHFF.js";
3
- const D = c(() => import("vue3-persian-datetime-picker")), $ = d({
1
+ import { defineComponent as f, resolveComponent as C, createElementBlock as h, openBlock as p, createElementVNode as d, createBlock as c, createCommentVNode as g, createStaticVNode as w, normalizeClass as k, mergeProps as v, defineAsyncComponent as y, ref as s, onMounted as b, computed as M, watch as V } from "vue";
2
+ import { _ as D, f as P, u as S } from "./chunks/_plugin-vue_export-helper-13TPlHFF.js";
3
+ const $ = y(() => import("vue3-persian-datetime-picker"));
4
+ function B() {
5
+ var o;
6
+ if (typeof document > "u") return "en";
7
+ const e = document.documentElement, t = (e.getAttribute("lang") || "").toLowerCase(), n = (e.getAttribute("dir") || ((o = document.body) == null ? void 0 : o.getAttribute("dir")) || "").toLowerCase();
8
+ return t ? t.startsWith("fa") || n === "rtl" && !t ? "fa" : "en" : n === "rtl" || (typeof navigator < "u" && navigator.language || "").toLowerCase().startsWith("fa") ? "fa" : "en";
9
+ }
10
+ const I = f({
4
11
  name: "PersianDatePickerInput",
5
- components: { Vue3PersianDatetimePicker: D },
12
+ components: { Vue3PersianDatetimePicker: $ },
6
13
  emits: ["update:modelValue", "change", "open", "close"],
7
14
  props: {
8
- ...S,
9
- /** date | datetime | time | year-month | month */
15
+ ...P,
10
16
  calendar: { type: String, default: "date" },
11
17
  view: { type: String, default: "date" },
12
18
  min: { type: String, default: null },
13
19
  max: { type: String, default: null },
14
20
  range: { type: Boolean, default: !1 },
15
- locale: { type: String, default: "fa" },
16
- /** Format of the stored value. */
21
+ /** 'auto' | 'fa' | 'en' */
22
+ locale: { type: String, default: "auto" },
17
23
  format: { type: String, default: "jYYYY/jMM/jDD" },
18
- /** Format shown in the input (defaults to `format`). */
19
24
  inputFormat: { type: String, default: null },
25
+ editable: { type: Boolean, default: !1 },
26
+ simple: { type: Boolean, default: !1 },
20
27
  placeholder: { type: String, default: null },
21
- inputClass: { type: String, default: "form-control fanum" },
22
- /** Extra props forwarded to vue3-persian-datetime-picker. */
28
+ inputClass: { type: String, default: "fanum" },
23
29
  pickerOptions: { type: Object, default: () => ({}) }
24
30
  },
25
- setup(e, { emit: n, expose: r }) {
26
- const a = b(e, n), l = g(!1);
27
- return v(() => {
28
- l.value = !0;
29
- }), k(
31
+ setup(e, { emit: t, expose: n }) {
32
+ const a = S(e, t), o = a.inputId, i = s(!1), r = s("en");
33
+ b(() => {
34
+ r.value = B(), i.value = !0;
35
+ });
36
+ const l = M(() => e.locale === "auto" ? r.value : e.locale);
37
+ return V(
30
38
  () => a.model.value,
31
- (i, t) => n("change", i, t)
32
- ), r({ clear: () => a.model.value = null }), { ...a, ready: l };
39
+ (u, m) => t("change", u, m)
40
+ ), n({ clear: () => a.model.value = null }), { ...a, inputID: o, ready: i, resolvedLocale: l, showCalendar: L };
33
41
  }
34
- }), h = ["placeholder"];
35
- function w(e, n, r, a, l, i) {
36
- const t = s("Vue3PersianDatetimePicker");
37
- return e.ready ? (p(), u(t, f({
38
- key: 0,
39
- modelValue: e.model,
40
- "onUpdate:modelValue": n[0] || (n[0] = (o) => e.model = o),
41
- name: e.name,
42
- id: e.inputId,
43
- type: e.calendar,
44
- view: e.view,
45
- min: e.min,
46
- max: e.max,
47
- range: e.range,
48
- locale: e.locale,
49
- format: e.format,
50
- "input-format": e.inputFormat || e.format,
51
- placeholder: e.placeholder,
52
- disabled: e.isDisabled || e.readonly,
53
- "input-class": [e.inputClass, { "is-invalid": e.isInvalid }],
54
- editable: "",
55
- jumpminute: "15",
56
- roundminute: !0,
57
- "show-now-btn": !0,
58
- "auto-submit": !0
59
- }, e.pickerOptions, {
60
- onOpen: n[1] || (n[1] = (o) => e.$emit("open")),
61
- onClose: n[2] || (n[2] = (o) => e.$emit("close"))
62
- }), null, 16, ["modelValue", "name", "id", "type", "view", "min", "max", "range", "locale", "format", "input-format", "placeholder", "disabled", "input-class"])) : (p(), m("input", {
63
- key: 1,
64
- type: "text",
65
- class: y(["form-control", { "is-invalid": e.isInvalid }]),
66
- placeholder: e.placeholder,
67
- disabled: ""
68
- }, null, 10, h));
42
+ });
43
+ let L = s(!1);
44
+ const Z = { class: "form-control form-adorn form-persian-datepicker form-adorn-end" }, j = ["id", "name", "placeholder", "disabled"];
45
+ function H(e, t, n, a, o, i) {
46
+ const r = C("Vue3PersianDatetimePicker");
47
+ return p(), h("div", null, [
48
+ d("label", Z, [
49
+ d("span", {
50
+ onClick: t[0] || (t[0] = (l) => e.showCalendar = !0),
51
+ class: "form-adorn-icon",
52
+ "aria-hidden": "true"
53
+ }, t[4] || (t[4] = [
54
+ w('<svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M14 22H10C6.22876 22 4.34315 22 3.17157 20.8284C2 19.6569 2 17.7712 2 14V12C2 8.22876 2 6.34315 3.17157 5.17157C4.34315 4 6.22876 4 10 4H14C17.7712 4 19.6569 4 20.8284 5.17157C22 6.34315 22 8.22876 22 12V14C22 17.7712 22 19.6569 20.8284 20.8284C20.1752 21.4816 19.3001 21.7706 18 21.8985" stroke="#1C274C" stroke-width="1.5" stroke-linecap="round"></path><path d="M7 4V2.5" stroke="#1C274C" stroke-width="1.5" stroke-linecap="round"></path><path d="M17 4V2.5" stroke="#1C274C" stroke-width="1.5" stroke-linecap="round"></path><path d="M21.5 9H16.625H10.75M2 9H5.875" stroke="#1C274C" stroke-width="1.5" stroke-linecap="round"></path><path d="M18 17C18 17.5523 17.5523 18 17 18C16.4477 18 16 17.5523 16 17C16 16.4477 16.4477 16 17 16C17.5523 16 18 16.4477 18 17Z" fill="#1C274C"></path><path d="M18 13C18 13.5523 17.5523 14 17 14C16.4477 14 16 13.5523 16 13C16 12.4477 16.4477 12 17 12C17.5523 12 18 12.4477 18 13Z" fill="#1C274C"></path><path d="M13 17C13 17.5523 12.5523 18 12 18C11.4477 18 11 17.5523 11 17C11 16.4477 11.4477 16 12 16C12.5523 16 13 16.4477 13 17Z" fill="#1C274C"></path><path d="M13 13C13 13.5523 12.5523 14 12 14C11.4477 14 11 13.5523 11 13C11 12.4477 11.4477 12 12 12C12.5523 12 13 12.4477 13 13Z" fill="#1C274C"></path><path d="M8 17C8 17.5523 7.55228 18 7 18C6.44772 18 6 17.5523 6 17C6 16.4477 6.44772 16 7 16C7.55228 16 8 16.4477 8 17Z" fill="#1C274C"></path><path d="M8 13C8 13.5523 7.55228 14 7 14C6.44772 14 6 13.5523 6 13C6 12.4477 6.44772 12 7 12C7.55228 12 8 12.4477 8 13Z" fill="#1C274C"></path></svg>', 1)
55
+ ])),
56
+ d("input", {
57
+ id: e.inputID,
58
+ type: "text",
59
+ autocomplete: "off",
60
+ name: e.name,
61
+ class: k([e.inputClass, "form-ghost", { "is-invalid": e.isInvalid }]),
62
+ placeholder: e.placeholder,
63
+ disabled: e.isDisabled || e.readonly
64
+ }, null, 10, j)
65
+ ]),
66
+ e.ready ? (p(), c(r, v({
67
+ key: 0,
68
+ modelValue: e.model,
69
+ "onUpdate:modelValue": t[1] || (t[1] = (l) => e.model = l),
70
+ "custom-input": "#" + e.inputID,
71
+ type: e.calendar,
72
+ view: e.view,
73
+ min: e.min,
74
+ max: e.max,
75
+ show: e.showCalendar,
76
+ range: e.range,
77
+ locale: e.resolvedLocale,
78
+ format: e.format,
79
+ "input-format": e.inputFormat || e.format,
80
+ disabled: e.isDisabled || e.readonly,
81
+ editable: e.editable,
82
+ simple: e.simple,
83
+ jumpminute: "15",
84
+ roundminute: !0,
85
+ "show-now-btn": !0,
86
+ "auto-submit": !0
87
+ }, e.pickerOptions, {
88
+ onOpen: t[2] || (t[2] = (l) => e.$emit("open")),
89
+ onClose: t[3] || (t[3] = () => {
90
+ e.showCalendar = !1, e.$emit("close");
91
+ })
92
+ }), null, 16, ["modelValue", "custom-input", "type", "view", "min", "max", "show", "range", "locale", "format", "input-format", "disabled", "editable", "simple"])) : g("", !0)
93
+ ]);
69
94
  }
70
- const j = /* @__PURE__ */ P($, [["render", w]]);
95
+ const Y = /* @__PURE__ */ D(I, [["render", H]]);
71
96
  export {
72
- j as PersianDatePickerInput
97
+ Y as PersianDatePickerInput
73
98
  };
package/dist/style.css CHANGED
@@ -1 +1 @@
1
- .form-field.is-invalid{border-color:var(--danger-border)}.voice-recorder-box audio,.voice-recorder-results audio{vertical-align:middle}.voice-recorder-box{display:block;background-color:var(--bg-1);border-radius:var(--border-radius);border:2px dashed var(--border-color)}
1
+ .form-persian-datepicker .form-adorn-icon{pointer-events:auto!important;cursor:pointer!important}.form-field.is-invalid{border-color:var(--danger-border)}.voice-recorder-box audio,.voice-recorder-results audio{vertical-align:middle}.voice-recorder-box{display:block;background-color:var(--bg-1);border-radius:var(--border-radius);border:2px dashed var(--border-color)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inertia-bootstrap-forms",
3
- "version": "4.0.5",
3
+ "version": "4.0.7",
4
4
  "description": "Bootstrap 6 form components for Vue 3 + Inertia.js (Laravel). Every field is bound to a single FormContainer v-model.",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -1,80 +1,134 @@
1
- <script>
2
- import { defineAsyncComponent, defineComponent, onMounted, ref, watch } from 'vue';
3
- import { fieldProps, useField } from './composables/useField.js';
4
-
5
- const Vue3PersianDatetimePicker = defineAsyncComponent(() => import('vue3-persian-datetime-picker'));
6
-
7
- /**
8
- * Jalali (Persian) date / time picker based on vue3-persian-datetime-picker.
9
- * Bootstrap 6's own Datepicker does not support the Jalali calendar, so this library is kept on purpose.
10
- */
11
- export default defineComponent({
12
- name: 'PersianDatePickerInput',
13
- components: { Vue3PersianDatetimePicker },
14
- emits: ['update:modelValue', 'change', 'open', 'close'],
15
- props: {
16
- ...fieldProps,
17
- /** date | datetime | time | year-month | month */
18
- calendar: { type: String, default: 'date' },
19
- view: { type: String, default: 'date' },
20
- min: { type: String, default: null },
21
- max: { type: String, default: null },
22
- range: { type: Boolean, default: false },
23
- locale: { type: String, default: 'fa' },
24
- /** Format of the stored value. */
25
- format: { type: String, default: 'jYYYY/jMM/jDD' },
26
- /** Format shown in the input (defaults to `format`). */
27
- inputFormat: { type: String, default: null },
28
- placeholder: { type: String, default: null },
29
- inputClass: { type: String, default: 'form-control fanum' },
30
- /** Extra props forwarded to vue3-persian-datetime-picker. */
31
- pickerOptions: { type: Object, default: () => ({}) },
32
- },
33
- setup(props, { emit, expose }) {
34
- const field = useField(props, emit);
35
- const ready = ref(false);
36
-
37
- onMounted(() => {
38
- ready.value = true; // the picker needs the DOM, so it is never rendered during SSR
39
- });
40
-
41
- watch(
42
- () => field.model.value,
43
- (now, before) => emit('change', now, before)
44
- );
45
-
46
- expose({ clear: () => (field.model.value = null) });
47
-
48
- return { ...field, ready };
49
- },
50
- });
51
- </script>
52
-
53
- <template>
54
- <Vue3PersianDatetimePicker
55
- v-if="ready"
56
- v-model="model"
57
- :name="name"
58
- :id="inputId"
59
- :type="calendar"
60
- :view="view"
61
- :min="min"
62
- :max="max"
63
- :range="range"
64
- :locale="locale"
65
- :format="format"
66
- :input-format="inputFormat || format"
67
- :placeholder="placeholder"
68
- :disabled="isDisabled || readonly"
69
- :input-class="[inputClass, { 'is-invalid': isInvalid }]"
70
- editable
71
- jumpminute="15"
72
- :roundminute="true"
73
- :show-now-btn="true"
74
- :auto-submit="true"
75
- v-bind="pickerOptions"
76
- @open="$emit('open')"
77
- @close="$emit('close')"
78
- />
79
- <input v-else type="text" class="form-control" :class="{ 'is-invalid': isInvalid }" :placeholder="placeholder" disabled />
80
- </template>
1
+ <script>
2
+ import {computed, defineAsyncComponent, defineComponent, onMounted, ref, watch} from 'vue';
3
+ import {fieldProps, useField} from './composables/useField.js';
4
+
5
+ const Vue3PersianDatetimePicker = defineAsyncComponent(() => import('vue3-persian-datetime-picker'));
6
+
7
+ /** Detects Persian from the page (lang / dir) or the browser language. Client-only. */
8
+ function detectLocale() {
9
+ if (typeof document === 'undefined') return 'en';
10
+
11
+ const html = document.documentElement;
12
+ const lang = (html.getAttribute('lang') || '').toLowerCase();
13
+ const dir = (html.getAttribute('dir') || document.body?.getAttribute('dir') || '').toLowerCase();
14
+ if (lang) return lang.startsWith('fa') ? 'fa' : dir === 'rtl' && !lang ? 'fa' : 'en';
15
+ if (dir === 'rtl') return 'fa';
16
+
17
+ const nav = (typeof navigator !== 'undefined' && navigator.language) || '';
18
+ return nav.toLowerCase().startsWith('fa') ? 'fa' : 'en';
19
+ }
20
+
21
+ export default defineComponent({
22
+ name: 'PersianDatePickerInput',
23
+ components: {Vue3PersianDatetimePicker},
24
+ emits: ['update:modelValue', 'change', 'open', 'close'],
25
+ props: {
26
+ ...fieldProps,
27
+ calendar: {type: String, default: 'date'},
28
+ view: {type: String, default: 'date'},
29
+ min: {type: String, default: null},
30
+ max: {type: String, default: null},
31
+ range: {type: Boolean, default: false},
32
+ /** 'auto' | 'fa' | 'en' */
33
+ locale: {type: String, default: 'auto'},
34
+ format: {type: String, default: 'jYYYY/jMM/jDD'},
35
+ inputFormat: {type: String, default: null},
36
+ editable: {type: Boolean, default: false},
37
+ simple: {type: Boolean, default: false},
38
+ placeholder: {type: String, default: null},
39
+ inputClass: {type: String, default: 'fanum'},
40
+ pickerOptions: {type: Object, default: () => ({})},
41
+ },
42
+ setup(props, {emit, expose}) {
43
+ const field = useField(props, emit);
44
+ const inputID = field.inputId;
45
+ const ready = ref(false);
46
+ const detected = ref('en'); // identical on server and client until mounted
47
+
48
+ onMounted(() => {
49
+ detected.value = detectLocale();
50
+ ready.value = true; // the picker needs the DOM, so it is never rendered during SSR
51
+ });
52
+
53
+ const resolvedLocale = computed(() => (props.locale === 'auto' ? detected.value : props.locale));
54
+
55
+ watch(
56
+ () => field.model.value,
57
+ (now, before) => emit('change', now, before)
58
+ );
59
+
60
+ expose({clear: () => (field.model.value = null)});
61
+
62
+
63
+ return {...field, inputID, ready, resolvedLocale, showCalendar};
64
+ },
65
+ });
66
+
67
+ let showCalendar = ref(false);
68
+ </script>
69
+
70
+ <template>
71
+ <div>
72
+ <label class="form-control form-adorn form-persian-datepicker form-adorn-end">
73
+ <span @click="showCalendar = true" class="form-adorn-icon" aria-hidden="true">
74
+ <svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
75
+ <path
76
+ d="M14 22H10C6.22876 22 4.34315 22 3.17157 20.8284C2 19.6569 2 17.7712 2 14V12C2 8.22876 2 6.34315 3.17157 5.17157C4.34315 4 6.22876 4 10 4H14C17.7712 4 19.6569 4 20.8284 5.17157C22 6.34315 22 8.22876 22 12V14C22 17.7712 22 19.6569 20.8284 20.8284C20.1752 21.4816 19.3001 21.7706 18 21.8985"
77
+ stroke="#1C274C" stroke-width="1.5" stroke-linecap="round"/>
78
+ <path d="M7 4V2.5" stroke="#1C274C" stroke-width="1.5" stroke-linecap="round"/>
79
+ <path d="M17 4V2.5" stroke="#1C274C" stroke-width="1.5" stroke-linecap="round"/>
80
+ <path d="M21.5 9H16.625H10.75M2 9H5.875" stroke="#1C274C" stroke-width="1.5" stroke-linecap="round"/>
81
+ <path d="M18 17C18 17.5523 17.5523 18 17 18C16.4477 18 16 17.5523 16 17C16 16.4477 16.4477 16 17 16C17.5523 16 18 16.4477 18 17Z" fill="#1C274C"/>
82
+ <path d="M18 13C18 13.5523 17.5523 14 17 14C16.4477 14 16 13.5523 16 13C16 12.4477 16.4477 12 17 12C17.5523 12 18 12.4477 18 13Z" fill="#1C274C"/>
83
+ <path d="M13 17C13 17.5523 12.5523 18 12 18C11.4477 18 11 17.5523 11 17C11 16.4477 11.4477 16 12 16C12.5523 16 13 16.4477 13 17Z" fill="#1C274C"/>
84
+ <path d="M13 13C13 13.5523 12.5523 14 12 14C11.4477 14 11 13.5523 11 13C11 12.4477 11.4477 12 12 12C12.5523 12 13 12.4477 13 13Z" fill="#1C274C"/>
85
+ <path d="M8 17C8 17.5523 7.55228 18 7 18C6.44772 18 6 17.5523 6 17C6 16.4477 6.44772 16 7 16C7.55228 16 8 16.4477 8 17Z" fill="#1C274C"/>
86
+ <path d="M8 13C8 13.5523 7.55228 14 7 14C6.44772 14 6 13.5523 6 13C6 12.4477 6.44772 12 7 12C7.55228 12 8 12.4477 8 13Z" fill="#1C274C"/>
87
+ </svg>
88
+ </span>
89
+ <input
90
+ :id="inputID"
91
+ type="text"
92
+ autocomplete="off"
93
+ :name="name"
94
+ :class="[inputClass, 'form-ghost', { 'is-invalid': isInvalid }]"
95
+ :placeholder="placeholder"
96
+ :disabled="isDisabled || readonly"
97
+ />
98
+ </label>
99
+ <Vue3PersianDatetimePicker
100
+ v-if="ready"
101
+ v-model="model"
102
+ :custom-input="'#' + inputID"
103
+ :type="calendar"
104
+ :view="view"
105
+ :min="min"
106
+ :max="max"
107
+ :show="showCalendar"
108
+ :range="range"
109
+ :locale="resolvedLocale"
110
+ :format="format"
111
+ :input-format="inputFormat || format"
112
+ :disabled="isDisabled || readonly"
113
+ :editable="editable"
114
+ :simple="simple"
115
+ jumpminute="15"
116
+ :roundminute="true"
117
+ :show-now-btn="true"
118
+ :auto-submit="true"
119
+ v-bind="pickerOptions"
120
+ @open="$emit('open')"
121
+ @close="() => {
122
+ showCalendar = false
123
+ $emit('close')
124
+ }"
125
+ />
126
+ </div>
127
+ </template>
128
+ <style>
129
+ .form-persian-datepicker .form-adorn-icon {
130
+ pointer-events: auto !important;
131
+ cursor: pointer !important;
132
+
133
+ }
134
+ </style>
@@ -1 +1 @@
1
- export { default as PersianDatePickerInput } from '../PersianDatePickerInput.vue';
1
+ export { default as PersianDatePickerInput } from '../PersianDatePickerInput.vue';
@@ -1,2 +1,2 @@
1
1
  import type { FieldComponent, Locale } from '../index.js';
2
- export declare const PersianDatePickerInput: FieldComponent<{ calendar?: string; view?: string; min?: string | null; max?: string | null; range?: boolean; locale?: string; format?: string; inputFormat?: string | null; placeholder?: string | null; inputClass?: string; pickerOptions?: object }>;
2
+ export declare const DatePickerInput: FieldComponent<{ calendar?: string; view?: string; min?: string | null; max?: string | null; range?: boolean; locale?: string; format?: string; inputFormat?: string | null; placeholder?: string | null; inputClass?: string; pickerOptions?: object }>;