sveltacular 0.0.58 → 0.0.60
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/data/index.d.ts +1 -2
- package/dist/data/index.js +1 -2
- package/dist/helpers/anchor.d.ts +2 -0
- package/dist/helpers/anchor.js +14 -0
- package/dist/helpers/date.d.ts +1 -1
- package/dist/index.d.ts +8 -3
- package/dist/index.js +8 -3
- package/dist/navigation/tabs/tab-context.d.ts +1 -0
- package/dist/navigation/tabs/tab-group.svelte +26 -5
- package/dist/navigation/tabs/tab-group.svelte.d.ts +2 -0
- package/dist/navigation/tabs/tab.svelte +8 -4
- package/dist/navigation/tabs/tab.svelte.d.ts +2 -1
- package/dist/types/date.d.ts +1 -0
- package/package.json +1 -1
package/dist/data/index.d.ts
CHANGED
package/dist/data/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Canada_Provinces, Canada_ProvinceCodes } from './canada.js';
|
|
|
2
2
|
import { Countries, CountryCodes } from './countries.js';
|
|
3
3
|
import { US_States, US_StateCodes } from './united-states.js';
|
|
4
4
|
import { Colors } from './colors.js';
|
|
5
|
-
const Data = {
|
|
5
|
+
export const Data = {
|
|
6
6
|
US_States,
|
|
7
7
|
US_StateCodes,
|
|
8
8
|
Canada_Provinces,
|
|
@@ -11,4 +11,3 @@ const Data = {
|
|
|
11
11
|
CountryCodes,
|
|
12
12
|
Colors
|
|
13
13
|
};
|
|
14
|
-
export default Data;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { browser } from '$app/environment';
|
|
2
|
+
export const navigateToAnchor = (anchor) => {
|
|
3
|
+
if (browser) {
|
|
4
|
+
setTimeout(() => {
|
|
5
|
+
if (window.top)
|
|
6
|
+
window.top.location.hash = anchor;
|
|
7
|
+
else
|
|
8
|
+
window.location.href = anchor;
|
|
9
|
+
}, 0);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
export const getAnchor = () => {
|
|
13
|
+
return browser ? window.location.hash : null;
|
|
14
|
+
};
|
package/dist/helpers/date.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import type { DateUnit } from '../index.js';
|
|
2
2
|
export declare const currentDate: () => string;
|
|
3
3
|
export declare const currentDateTime: () => string;
|
|
4
4
|
export declare const addDays: (days: number, fromDate?: string | Date) => Date;
|
package/dist/index.d.ts
CHANGED
|
@@ -90,12 +90,17 @@ export { default as SkeletonText } from './placeholders/skeleton-text.svelte';
|
|
|
90
90
|
export * from './types/data.js';
|
|
91
91
|
export * from './types/date.js';
|
|
92
92
|
export * from './types/form.js';
|
|
93
|
+
export * from './helpers/ago.js';
|
|
94
|
+
export * from './helpers/anchor.js';
|
|
95
|
+
export * from './helpers/capitalize.js';
|
|
93
96
|
export * from './helpers/date.js';
|
|
97
|
+
export * from './helpers/debounce.js';
|
|
94
98
|
export * from './helpers/navigate-to.js';
|
|
99
|
+
export * from './helpers/nobr.js';
|
|
100
|
+
export * from './helpers/random.js';
|
|
95
101
|
export * from './helpers/round-to-decimals.js';
|
|
96
|
-
export * from './helpers/
|
|
102
|
+
export * from './helpers/split-new-lines.js';
|
|
97
103
|
export * from './helpers/subscribable.js';
|
|
98
104
|
export * from './helpers/ucfirst.js';
|
|
99
|
-
export * from './helpers/
|
|
100
|
-
export * from './helpers/split-new-lines.js';
|
|
105
|
+
export * from './helpers/unique-id.js';
|
|
101
106
|
export * from './data/index.js';
|
package/dist/index.js
CHANGED
|
@@ -101,13 +101,18 @@ export * from './types/data.js';
|
|
|
101
101
|
export * from './types/date.js';
|
|
102
102
|
export * from './types/form.js';
|
|
103
103
|
// Helpers
|
|
104
|
+
export * from './helpers/ago.js';
|
|
105
|
+
export * from './helpers/anchor.js';
|
|
106
|
+
export * from './helpers/capitalize.js';
|
|
104
107
|
export * from './helpers/date.js';
|
|
108
|
+
export * from './helpers/debounce.js';
|
|
105
109
|
export * from './helpers/navigate-to.js';
|
|
110
|
+
export * from './helpers/nobr.js';
|
|
111
|
+
export * from './helpers/random.js';
|
|
106
112
|
export * from './helpers/round-to-decimals.js';
|
|
107
|
-
export * from './helpers/
|
|
113
|
+
export * from './helpers/split-new-lines.js';
|
|
108
114
|
export * from './helpers/subscribable.js';
|
|
109
115
|
export * from './helpers/ucfirst.js';
|
|
110
|
-
export * from './helpers/
|
|
111
|
-
export * from './helpers/split-new-lines.js';
|
|
116
|
+
export * from './helpers/unique-id.js';
|
|
112
117
|
// Data
|
|
113
118
|
export * from './data/index.js';
|
|
@@ -1,17 +1,38 @@
|
|
|
1
1
|
<script>import { writable } from "svelte/store";
|
|
2
|
-
import { setContext } from "svelte";
|
|
2
|
+
import { createEventDispatcher, setContext } from "svelte";
|
|
3
3
|
import { tabContext } from "./tab-context.js";
|
|
4
|
-
import { subscribable } from "../../index.js";
|
|
4
|
+
import { getAnchor, navigateToAnchor, subscribable } from "../../index.js";
|
|
5
5
|
export let style = "traditional";
|
|
6
|
+
const dispatch = createEventDispatcher();
|
|
6
7
|
const tabs = writable([]);
|
|
7
8
|
const register = (id, name, isActive) => {
|
|
8
|
-
tabs.update((value) => [...value, { id, name }]);
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
tabs.update((value) => [...value, { id, name, defaultActive: isActive }]);
|
|
10
|
+
checkActive();
|
|
11
|
+
};
|
|
12
|
+
const tabExists = (id) => {
|
|
13
|
+
const value = $tabs;
|
|
14
|
+
return value.some((tab) => tab.id === id);
|
|
15
|
+
};
|
|
16
|
+
let timeout = null;
|
|
17
|
+
const checkActive = () => {
|
|
18
|
+
if (timeout)
|
|
19
|
+
clearTimeout(timeout);
|
|
20
|
+
timeout = setTimeout(() => {
|
|
21
|
+
const anchor = getAnchor();
|
|
22
|
+
if (anchor && tabExists(anchor))
|
|
23
|
+
active.set(anchor);
|
|
24
|
+
else {
|
|
25
|
+
const defaultActiveTab = $tabs.find((tab) => tab.defaultActive);
|
|
26
|
+
if (defaultActiveTab)
|
|
27
|
+
active.set(defaultActiveTab.id);
|
|
28
|
+
}
|
|
29
|
+
}, 10);
|
|
11
30
|
};
|
|
12
31
|
const active = writable(null);
|
|
13
32
|
const selectTab = (id) => {
|
|
14
33
|
active.set(id);
|
|
34
|
+
navigateToAnchor(id);
|
|
35
|
+
dispatch("change", id);
|
|
15
36
|
};
|
|
16
37
|
const ctx = {
|
|
17
38
|
active: subscribable(active),
|
|
@@ -5,13 +5,17 @@ import Loading from "../../placeholders/loading.svelte";
|
|
|
5
5
|
export let title;
|
|
6
6
|
export let href = void 0;
|
|
7
7
|
export let active = false;
|
|
8
|
+
export let id = void 0;
|
|
9
|
+
const getId = () => id || title.trim().toLocaleLowerCase().replaceAll(" ", "_") || uniqueId();
|
|
8
10
|
const dispatch = createEventDispatcher();
|
|
9
11
|
const ctx = getContext(tabContext);
|
|
10
12
|
const tabStyle = ctx.style || "traditional";
|
|
11
|
-
const
|
|
12
|
-
ctx.register(
|
|
13
|
+
const _id = getId();
|
|
14
|
+
ctx.register(_id, title, active);
|
|
13
15
|
const unsubscribe = ctx.active.subscribe((selectedId) => {
|
|
14
|
-
active = selectedId ===
|
|
16
|
+
active = selectedId === _id;
|
|
17
|
+
if (active)
|
|
18
|
+
dispatch("selected", _id);
|
|
15
19
|
if (active && href) {
|
|
16
20
|
console.log("Navigating to", href);
|
|
17
21
|
navigateTo(href);
|
|
@@ -20,7 +24,7 @@ const unsubscribe = ctx.active.subscribe((selectedId) => {
|
|
|
20
24
|
onDestroy(() => unsubscribe());
|
|
21
25
|
</script>
|
|
22
26
|
|
|
23
|
-
<article class:active>
|
|
27
|
+
<article class:active class={tabStyle}>
|
|
24
28
|
{#if active}
|
|
25
29
|
{#if $$slots.default}
|
|
26
30
|
<slot />
|
|
@@ -4,9 +4,10 @@ declare const __propDef: {
|
|
|
4
4
|
title: string;
|
|
5
5
|
href?: string | undefined;
|
|
6
6
|
active?: boolean | undefined;
|
|
7
|
+
id?: string | undefined;
|
|
7
8
|
};
|
|
8
9
|
events: {
|
|
9
|
-
|
|
10
|
+
selected: CustomEvent<string>;
|
|
10
11
|
} & {
|
|
11
12
|
[evt: string]: CustomEvent<any>;
|
|
12
13
|
};
|
package/dist/types/date.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export type DateTimeStyle = 'full' | 'long' | 'short' | 'medium';
|
|
2
2
|
export type TZStyle = 'long' | 'short' | 'shortOffset' | 'longOffset' | 'shortGeneric' | 'longGeneric';
|
|
3
3
|
export type DateType = 'date' | 'time' | 'datetime' | 'ago' | 'ymd' | 'ymdhm' | 'ymdhms' | 'ymdhmt' | 'ymdhmst';
|
|
4
|
+
export type DateUnit = 'day' | 'month' | 'year' | 'minute' | 'hour' | 'second';
|