sveltacular 0.0.48 → 0.0.49

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,40 @@
1
+ <script>import { nobr } from "../../helpers/nobr.js";
2
+ import { splitNewLines } from "../../helpers/split-new-lines.js";
3
+ export let streetAddress = "";
4
+ export let city = "";
5
+ export let region = "";
6
+ export let postalCode = "";
7
+ export let country = "";
8
+ $:
9
+ streetAddressArray = splitNewLines(streetAddress);
10
+ $:
11
+ flatAddress = nobr(
12
+ `${streetAddress}, ${city}, ${region} ${postalCode}, ${country}`.replace(/,\s+/g, ", ")
13
+ );
14
+ </script>
15
+
16
+ <address>
17
+ <a href="https://maps.google.com/?q={flatAddress}" target="_blank" rel="noopener">
18
+ {#each streetAddressArray as line}
19
+ <div>{line}</div>
20
+ {/each}
21
+ <div>
22
+ {city}, {region}
23
+ {country}
24
+ {postalCode}
25
+ </div>
26
+ </a>
27
+ </address>
28
+
29
+ <style>address {
30
+ display: block;
31
+ margin-bottom: 1rem;
32
+ font-style: normal;
33
+ }
34
+ address a {
35
+ color: inherit;
36
+ text-decoration: none;
37
+ }
38
+ address a:hover {
39
+ text-decoration: underline;
40
+ }</style>
@@ -0,0 +1,20 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ streetAddress?: string | undefined;
5
+ city?: string | undefined;
6
+ region?: string | undefined;
7
+ postalCode?: string | undefined;
8
+ country?: string | undefined;
9
+ };
10
+ events: {
11
+ [evt: string]: CustomEvent<any>;
12
+ };
13
+ slots: {};
14
+ };
15
+ export type AddressProps = typeof __propDef.props;
16
+ export type AddressEvents = typeof __propDef.events;
17
+ export type AddressSlots = typeof __propDef.slots;
18
+ export default class Address extends SvelteComponent<AddressProps, AddressEvents, AddressSlots> {
19
+ }
20
+ export {};
@@ -0,0 +1,30 @@
1
+ <script>import EnvelopeIcon from "../../icons/envelope-icon.svelte";
2
+ export let emailAddress = "";
3
+ </script>
4
+
5
+ <a href="mailto:{emailAddress}" title="Email Address">
6
+ <span class="icon">
7
+ <EnvelopeIcon />
8
+ </span>
9
+ <span class="address">
10
+ {emailAddress}
11
+ </span>
12
+ </a>
13
+
14
+ <style>a {
15
+ color: inherit;
16
+ text-decoration: none;
17
+ }
18
+ a span {
19
+ display: inline-block;
20
+ vertical-align: middle;
21
+ line-height: 1.5rem;
22
+ }
23
+ a .icon {
24
+ width: 1rem;
25
+ height: 1rem;
26
+ position: relative;
27
+ }
28
+ a:hover .address {
29
+ text-decoration: underline;
30
+ }</style>
@@ -0,0 +1,16 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ emailAddress?: string | undefined;
5
+ };
6
+ events: {
7
+ [evt: string]: CustomEvent<any>;
8
+ };
9
+ slots: {};
10
+ };
11
+ export type EmailProps = typeof __propDef.props;
12
+ export type EmailEvents = typeof __propDef.events;
13
+ export type EmailSlots = typeof __propDef.slots;
14
+ export default class Email extends SvelteComponent<EmailProps, EmailEvents, EmailSlots> {
15
+ }
16
+ export {};
@@ -0,0 +1,56 @@
1
+ <script>import { capitalize } from "../../helpers/capitalize.js";
2
+ import MobilePhoneIcon from "../../icons/mobile-phone-icon.svelte";
3
+ import PhoneIcon from "../../icons/phone-icon.svelte";
4
+ export let phoneNumber;
5
+ export let type = "mobile";
6
+ const getDigits = (phoneNumber2) => {
7
+ return phoneNumber2.replace(/[^0-9]/g, "");
8
+ };
9
+ const formatPhoneNumber = (phoneNumber2) => {
10
+ const cleaned = getDigits(phoneNumber2);
11
+ const match = cleaned.match(/^(\d{3})(\d{3})(\d{4})$/);
12
+ if (match) {
13
+ return "(" + match[1] + ") " + match[2] + "-" + match[3];
14
+ }
15
+ return phoneNumber2;
16
+ };
17
+ $:
18
+ formattedPhoneNumber = formatPhoneNumber(phoneNumber);
19
+ $:
20
+ phoneNumberDigits = getDigits(phoneNumber);
21
+ $:
22
+ protocol = type === "sms" ? "sms:" : "tel:";
23
+ $:
24
+ isCellPhone = type == "mobile" || type == "sms";
25
+ </script>
26
+
27
+ <a href="{protocol}:{phoneNumberDigits}" title={capitalize(type)}>
28
+ <span class="icon">
29
+ {#if isCellPhone}
30
+ <MobilePhoneIcon />
31
+ {:else}
32
+ <PhoneIcon />
33
+ {/if}
34
+ </span>
35
+ <span class="number">
36
+ {formattedPhoneNumber}
37
+ </span>
38
+ </a>
39
+
40
+ <style>a {
41
+ color: inherit;
42
+ text-decoration: none;
43
+ }
44
+ a span {
45
+ display: inline-block;
46
+ vertical-align: middle;
47
+ line-height: 1.5rem;
48
+ }
49
+ a .icon {
50
+ width: 1rem;
51
+ height: 1rem;
52
+ position: relative;
53
+ }
54
+ a:hover .number {
55
+ text-decoration: underline;
56
+ }</style>
@@ -0,0 +1,17 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ phoneNumber: string;
5
+ type?: "sms" | "mobile" | "home" | "work" | "fax" | "other" | undefined;
6
+ };
7
+ events: {
8
+ [evt: string]: CustomEvent<any>;
9
+ };
10
+ slots: {};
11
+ };
12
+ export type PhoneProps = typeof __propDef.props;
13
+ export type PhoneEvents = typeof __propDef.events;
14
+ export type PhoneSlots = typeof __propDef.slots;
15
+ export default class Phone extends SvelteComponent<PhoneProps, PhoneEvents, PhoneSlots> {
16
+ }
17
+ export {};
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Capitalize the first letter of each word in a string, unless the word only has one letter
3
+ */
4
+ export declare const capitalize: (str: string) => string;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Capitalize the first letter of each word in a string, unless the word only has one letter
3
+ */
4
+ export const capitalize = (str) => {
5
+ return str
6
+ .split(' ')
7
+ .map((word) => {
8
+ if (word.length === 1)
9
+ return word;
10
+ return word.charAt(0).toUpperCase() + word.slice(1);
11
+ })
12
+ .join(' ');
13
+ };
@@ -2,8 +2,20 @@ import { browser } from '$app/environment';
2
2
  import { goto } from '$app/navigation';
3
3
  import { redirect } from '@sveltejs/kit';
4
4
  export const navigateTo = (url) => {
5
- if (browser)
6
- setTimeout(() => goto(url), 0);
7
- else
5
+ if (browser) {
6
+ setTimeout(() => {
7
+ try {
8
+ goto(url);
9
+ }
10
+ catch {
11
+ if (window.top)
12
+ window.top.location.href = url;
13
+ else
14
+ window.location.href = url;
15
+ }
16
+ }, 0);
17
+ }
18
+ else {
8
19
  redirect(303, url);
20
+ }
9
21
  };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Remove line breaks
3
+ */
4
+ export declare const nobr: (str: string) => string;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Remove line breaks
3
+ */
4
+ export const nobr = (str) => str.replace(/\n/g, ' ');
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Split a string by new line
3
+ */
4
+ export declare const splitNewLines: (str: string) => string[];
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Split a string by new line
3
+ */
4
+ export const splitNewLines = (str) => str.split('\n');
@@ -0,0 +1 @@
1
+ export declare const ucfirst: (str: string) => string;
@@ -0,0 +1,3 @@
1
+ export const ucfirst = (str) => {
2
+ return str.charAt(0).toUpperCase() + str.slice(1);
3
+ };
@@ -0,0 +1,8 @@
1
+ <svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
2
+ <path
3
+ d="m10.036 8.278 9.258-7.79A1.979 1.979 0 0 0 18 0H2A1.987 1.987 0 0 0 .641.541l9.395 7.737Z"
4
+ />
5
+ <path
6
+ d="M11.241 9.817c-.36.275-.801.425-1.255.427-.428 0-.845-.138-1.187-.395L0 2.6V14a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V2.5l-8.759 7.317Z"
7
+ />
8
+ </svg>
@@ -0,0 +1,23 @@
1
+ /** @typedef {typeof __propDef.props} EnvelopeIconProps */
2
+ /** @typedef {typeof __propDef.events} EnvelopeIconEvents */
3
+ /** @typedef {typeof __propDef.slots} EnvelopeIconSlots */
4
+ export default class EnvelopeIcon extends SvelteComponent<{
5
+ [x: string]: never;
6
+ }, {
7
+ [evt: string]: CustomEvent<any>;
8
+ }, {}> {
9
+ }
10
+ export type EnvelopeIconProps = typeof __propDef.props;
11
+ export type EnvelopeIconEvents = typeof __propDef.events;
12
+ export type EnvelopeIconSlots = typeof __propDef.slots;
13
+ import { SvelteComponent } from "svelte";
14
+ declare const __propDef: {
15
+ props: {
16
+ [x: string]: never;
17
+ };
18
+ events: {
19
+ [evt: string]: CustomEvent<any>;
20
+ };
21
+ slots: {};
22
+ };
23
+ export {};
@@ -0,0 +1,5 @@
1
+ <svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
2
+ <path
3
+ d="M12 0H2a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2ZM7.5 17.5h-1a1 1 0 0 1 0-2h1a1 1 0 0 1 0 2ZM12 13H2V4h10v9Z"
4
+ />
5
+ </svg>
@@ -0,0 +1,23 @@
1
+ /** @typedef {typeof __propDef.props} MobilePhoneIconProps */
2
+ /** @typedef {typeof __propDef.events} MobilePhoneIconEvents */
3
+ /** @typedef {typeof __propDef.slots} MobilePhoneIconSlots */
4
+ export default class MobilePhoneIcon extends SvelteComponent<{
5
+ [x: string]: never;
6
+ }, {
7
+ [evt: string]: CustomEvent<any>;
8
+ }, {}> {
9
+ }
10
+ export type MobilePhoneIconProps = typeof __propDef.props;
11
+ export type MobilePhoneIconEvents = typeof __propDef.events;
12
+ export type MobilePhoneIconSlots = typeof __propDef.slots;
13
+ import { SvelteComponent } from "svelte";
14
+ declare const __propDef: {
15
+ props: {
16
+ [x: string]: never;
17
+ };
18
+ events: {
19
+ [evt: string]: CustomEvent<any>;
20
+ };
21
+ slots: {};
22
+ };
23
+ export {};
@@ -0,0 +1,9 @@
1
+ <svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 18">
2
+ <path
3
+ stroke="currentColor"
4
+ stroke-linecap="round"
5
+ stroke-linejoin="round"
6
+ stroke-width="2"
7
+ d="m16.344 12.168-1.4-1.4a1.98 1.98 0 0 0-2.8 0l-.7.7a1.98 1.98 0 0 1-2.8 0l-2.1-2.1a1.98 1.98 0 0 1 0-2.8l.7-.7a1.981 1.981 0 0 0 0-2.8l-1.4-1.4a1.828 1.828 0 0 0-2.8 0C-.638 5.323 1.1 9.542 4.78 13.22c3.68 3.678 7.9 5.418 11.564 1.752a1.828 1.828 0 0 0 0-2.804Z"
8
+ />
9
+ </svg>
@@ -0,0 +1,23 @@
1
+ /** @typedef {typeof __propDef.props} PhoneIconProps */
2
+ /** @typedef {typeof __propDef.events} PhoneIconEvents */
3
+ /** @typedef {typeof __propDef.slots} PhoneIconSlots */
4
+ export default class PhoneIcon extends SvelteComponent<{
5
+ [x: string]: never;
6
+ }, {
7
+ [evt: string]: CustomEvent<any>;
8
+ }, {}> {
9
+ }
10
+ export type PhoneIconProps = typeof __propDef.props;
11
+ export type PhoneIconEvents = typeof __propDef.events;
12
+ export type PhoneIconSlots = typeof __propDef.slots;
13
+ import { SvelteComponent } from "svelte";
14
+ declare const __propDef: {
15
+ props: {
16
+ [x: string]: never;
17
+ };
18
+ events: {
19
+ [evt: string]: CustomEvent<any>;
20
+ };
21
+ slots: {};
22
+ };
23
+ export {};
package/dist/index.d.ts CHANGED
@@ -39,6 +39,9 @@ export { default as Header } from './generic/header/header.svelte';
39
39
  export { default as Dot } from './generic/dot/dot.svelte';
40
40
  export { default as Notice } from './generic/notice/notice.svelte';
41
41
  export { default as Empty } from './generic/empty/empty.svelte';
42
+ export { default as Email } from './generic/email/email.svelte';
43
+ export { default as Phone } from './generic/phone/phone.svelte';
44
+ export { default as Address } from './generic/address/address.svelte';
42
45
  export { default as FlexCol } from './layout/flex-col.svelte';
43
46
  export { default as FlexRow } from './layout/flex-row.svelte';
44
47
  export { default as FlexItem } from './layout/flex-item.svelte';
@@ -91,4 +94,7 @@ export * from './helpers/navigate-to.js';
91
94
  export * from './helpers/round-to-decimals.js';
92
95
  export * from './helpers/unique-id.js';
93
96
  export * from './helpers/subscribable.js';
97
+ export * from './helpers/ucfirst.js';
98
+ export * from './helpers/capitalize.js';
99
+ export * from './helpers/split-new-lines.js';
94
100
  export * as Data from './data/index.js';
package/dist/index.js CHANGED
@@ -41,6 +41,9 @@ export { default as Header } from './generic/header/header.svelte';
41
41
  export { default as Dot } from './generic/dot/dot.svelte';
42
42
  export { default as Notice } from './generic/notice/notice.svelte';
43
43
  export { default as Empty } from './generic/empty/empty.svelte';
44
+ export { default as Email } from './generic/email/email.svelte';
45
+ export { default as Phone } from './generic/phone/phone.svelte';
46
+ export { default as Address } from './generic/address/address.svelte';
44
47
  // Layout
45
48
  export { default as FlexCol } from './layout/flex-col.svelte';
46
49
  export { default as FlexRow } from './layout/flex-row.svelte';
@@ -102,5 +105,8 @@ export * from './helpers/navigate-to.js';
102
105
  export * from './helpers/round-to-decimals.js';
103
106
  export * from './helpers/unique-id.js';
104
107
  export * from './helpers/subscribable.js';
108
+ export * from './helpers/ucfirst.js';
109
+ export * from './helpers/capitalize.js';
110
+ export * from './helpers/split-new-lines.js';
105
111
  // Data
106
112
  export * as Data from './data/index.js';
@@ -1,7 +1,9 @@
1
1
  <script>import { createEventDispatcher, getContext, onDestroy } from "svelte";
2
2
  import { tabContext } from "./tab-context.js";
3
- import { uniqueId } from "../../index.js";
3
+ import { navigateTo, uniqueId } from "../../index.js";
4
+ import Loading from "../../placeholders/loading.svelte";
4
5
  export let title;
6
+ export let href = void 0;
5
7
  export let active = false;
6
8
  const dispatch = createEventDispatcher();
7
9
  const ctx = getContext(tabContext);
@@ -10,13 +12,21 @@ const id = uniqueId();
10
12
  ctx.register(id, title, active);
11
13
  const unsubscribe = ctx.active.subscribe((selectedId) => {
12
14
  active = selectedId === id;
15
+ if (active && href) {
16
+ console.log("Navigating to", href);
17
+ navigateTo(href);
18
+ }
13
19
  });
14
20
  onDestroy(() => unsubscribe());
15
21
  </script>
16
22
 
17
23
  <article class:active>
18
24
  {#if active}
19
- <slot />
25
+ {#if $$slots.default}
26
+ <slot />
27
+ {:else}
28
+ <Loading />
29
+ {/if}
20
30
  {/if}
21
31
  </article>
22
32
 
@@ -2,6 +2,7 @@ import { SvelteComponent } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
4
  title: string;
5
+ href?: string | undefined;
5
6
  active?: boolean | undefined;
6
7
  };
7
8
  events: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sveltacular",
3
- "version": "0.0.48",
3
+ "version": "0.0.49",
4
4
  "description": "A Svelte component library",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",