@movvjs/svelte-schedule-view 0.4.20 → 0.4.21

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,27 +1,59 @@
1
1
  <script>export let emailList = [""];
2
2
  export let required = true;
3
+ const MAX_EMAIL_COUNT = 10;
4
+ let invalidIndexes = /* @__PURE__ */ new Set();
3
5
  $:
4
6
  if (!emailList || emailList.length === 0) {
5
7
  emailList = [""];
6
8
  }
9
+ function checkEmail3(email) {
10
+ const regEmail = /^[0-9a-zA-Z]([-_\.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_]?[0-9a-zA-Z])*(\.[0-9a-zA-Z]([-_]?[0-9a-zA-Z])*)*\.[a-zA-Z]{2,}$/;
11
+ return regEmail.test(email);
12
+ }
7
13
  function addEmail() {
14
+ if (emailList.length >= MAX_EMAIL_COUNT)
15
+ return;
8
16
  emailList = [...emailList, ""];
9
17
  }
10
18
  function removeEmail(index) {
11
19
  if (index === 0 && required)
12
20
  return;
13
21
  emailList = emailList.filter((_, i) => i !== index);
22
+ validateEmails();
14
23
  }
15
24
  function updateEmail(index, value) {
16
25
  emailList[index] = value;
17
26
  emailList = [...emailList];
27
+ validateEmails();
18
28
  }
19
29
  function keyAdd(e) {
20
30
  if (e.key === "Enter") {
21
31
  e.preventDefault();
22
- addEmail();
32
+ if (emailList.length < MAX_EMAIL_COUNT) {
33
+ addEmail();
34
+ }
23
35
  }
24
36
  }
37
+ function validateEmails() {
38
+ const newInvalid = /* @__PURE__ */ new Set();
39
+ const trimmed = emailList.map((e) => e?.trim() ?? "");
40
+ const seen = /* @__PURE__ */ new Set();
41
+ trimmed.forEach((email, index) => {
42
+ if (!email)
43
+ return;
44
+ const lower = email.toLowerCase();
45
+ if (!checkEmail3(email)) {
46
+ newInvalid.add(index);
47
+ return;
48
+ }
49
+ if (seen.has(lower)) {
50
+ newInvalid.add(index);
51
+ } else {
52
+ seen.add(lower);
53
+ }
54
+ });
55
+ invalidIndexes = newInvalid;
56
+ }
25
57
  </script>
26
58
 
27
59
  <div class="add_email_wrap">
@@ -30,15 +62,15 @@ function keyAdd(e) {
30
62
  <div class="item">
31
63
  <input
32
64
  type="text"
33
- class="indie_text_nor w100"
65
+ class={`indie_text_nor w100 ${invalidIndexes.has(index) ? 'error' : ''}`}
34
66
  placeholder="E-mail"
35
67
  value={email}
36
68
  on:input={e => updateEmail(index, e.currentTarget.value)}
37
69
  on:keydown={keyAdd} />
38
70
 
39
- {#if index === 0}
71
+ {#if index === 0 && emailList.length < MAX_EMAIL_COUNT}
40
72
  <button type="button" class="button_add" on:click={addEmail}> 추가 </button>
41
- {:else}
73
+ {:else if index !== 0}
42
74
  <button type="button" class="button_minus" on:click={() => removeEmail(index)}> 삭제 </button>
43
75
  {/if}
44
76
  </div>
@@ -206,7 +206,7 @@ async function save() {
206
206
  throw new Error($t("error.pleaseEnterTelNumber"));
207
207
  }
208
208
  if (hasDuplicateEmail($copiedBooking.emailList))
209
- throw new Error("error.dupliEmail");
209
+ throw new Error($t("error.dupliEmail"));
210
210
  const cleaned = $copiedBooking.emailList.map((e) => e?.trim()).filter(Boolean);
211
211
  $copiedBooking.email = cleaned[0] ?? "";
212
212
  $copiedBooking.emailList = cleaned.slice(1);