@splendidlabz/svelte 4.0.0-alpha.0 → 4.0.0-alpha.2

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/actions/breakpoint-observer.js +1 -1
  3. package/components/Accordion/Accordion.svelte +33 -37
  4. package/components/BrowserFrame/BrowserFrame.svelte +81 -24
  5. package/components/BrowserFrame/BrowserWithTabs.svelte +12 -3
  6. package/components/Disclosure/DrawerNew/Drawer.svelte +12 -8
  7. package/components/Disclosure/DrawerNew/DrawerClose.svelte +19 -0
  8. package/components/Disclosure/DrawerNew/DrawerTrigger.svelte +3 -4
  9. package/components/Disclosure/ModalNew/Modal.svelte +24 -18
  10. package/components/Disclosure/ModalNew/ModalTrigger.svelte +2 -2
  11. package/components/Disclosure/Popover/PopoverTrigger.svelte +1 -1
  12. package/components/Disclosure/PopoverNew/Popover.svelte +17 -3
  13. package/components/Disclosure/PopoverNew/floating.js +1 -1
  14. package/components/Form/Radio.svelte +5 -5
  15. package/components/Icon/Icon.svelte +4 -3
  16. package/components/Icon/IconSnippet.svelte +11 -4
  17. package/components/Icon/index.js +2 -1
  18. package/components/Markdown/Markdown.svelte +10 -6
  19. package/components/Markdown/MarkdownSnippet.svelte +27 -0
  20. package/components/Masonry/Masonry.svelte +1 -1
  21. package/components/Switcheroo/Switcheroo.svelte +1 -2
  22. package/components/Tabs/Tab.svelte +2 -7
  23. package/components/Tabs/Tablist.svelte +31 -14
  24. package/components/Tabs/Tabpanel.svelte +2 -5
  25. package/components/Tabs/Tabpanels.svelte +2 -5
  26. package/components/Tabs/Tabs.svelte +46 -0
  27. package/components/Tabs/index.js +2 -1
  28. package/components/Tabs/tab-store.js +1 -2
  29. package/components/Tabs/tabs.js +17 -14
  30. package/components/Textwall/Repeat.svelte +1 -1
  31. package/components/Textwall/Textwall.svelte +1 -2
  32. package/index.js +3 -0
  33. package/package.json +4 -5
  34. package/utils/index.js +1 -0
  35. package/utils/is-slot.js +3 -0
  36. package/utils/loadscripts.js +58 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @splendidlabz/svelte
2
2
 
3
+ ## 4.0.0-alpha.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @splendidlabz/styles@4.0.0-alpha.2
9
+
10
+ ## 4.0.0-alpha.1
11
+
12
+ ### Patch Changes
13
+
14
+ - Updates
15
+ - Updated dependencies
16
+ - @splendidlabz/styles@4.0.0-alpha.1
17
+ - @splendidlabz/utils@1.5.0-alpha.4
18
+
3
19
  ## 3.0.0-alpha.9
4
20
 
5
21
  ### Patch Changes
@@ -1,5 +1,5 @@
1
1
  import { isEmpty, omitEmpty } from '@splendidlabz/utils'
2
- import { resizeObserver } from '@splendidlabz/utils/actions'
2
+ import { resizeObserver } from '@splendidlabz/utils/dom'
3
3
 
4
4
  const DEFAULT_BREAKPOINT_OPTIONS = {
5
5
  breakpoints: {},
@@ -1,36 +1,35 @@
1
1
  <script>
2
2
  import { randomString } from '@splendidlabz/utils/dom'
3
3
  import { applyTransition, mergeOpts } from '../../utils/index.js'
4
- import Icon from '../Icon/Icon.svelte'
5
-
4
+ import { reloadScripts } from '../../utils/loadscripts.js'
5
+ import { IconSnippet } from '../Icon/IconSnippet.svelte'
6
+ import { MarkdownSnippet } from '../Markdown/MarkdownSnippet.svelte'
6
7
  const p = $props()
7
8
  const DEFAULT_OPTIONS = {
8
9
  titleTag: 'h3',
9
10
  icon: 'tabler:chevron-right',
10
- iconLocation: 'end',
11
+ iconPosition: 'end',
11
12
  transition: 'slide',
12
13
  }
13
14
  const opts = mergeOpts(DEFAULT_OPTIONS, p)
14
15
 
15
16
  // Classes
16
17
  const {
18
+ id = randomString(9),
17
19
  class: klass,
18
20
  titleClass,
21
+ contentClass,
19
22
  buttonClass,
20
23
  icon,
21
24
  iconClass,
22
- contentClass,
25
+ useMarkdown = true,
23
26
  } = opts
24
27
 
25
- // Slots
26
- const { title, iconSlot, content, children } = opts
27
-
28
- if (!title) console.warn('Accordion: No title slot provided')
29
- if (!content && !children)
30
- console.warn('Accordion: No content or default slot provided')
31
-
32
- const id = opts.id || randomString(9)
33
28
  let show = $state(false)
29
+ const { title, content, children } = opts
30
+
31
+ if (!title) console.warn('Accordion: No title provided')
32
+ if (!content && !children) console.warn('Accordion: No content provided')
34
33
 
35
34
  // ========================================
36
35
  // Event Handlers
@@ -62,54 +61,51 @@
62
61
  }
63
62
  </script>
64
63
 
65
- <!-- Renders the iconSlot or use the icon -->
66
- {#snippet iconBlock()}
67
- {#if iconSlot}
68
- {@render iconSlot()}
69
- {:else}
70
- <Icon {icon} class={iconClass} />
71
- {/if}
72
- {/snippet}
73
-
74
- <!-- The output -->
75
-
64
+ <!-- Accordion HTML -->
76
65
  <div class="accordion {klass}" class:open={show}>
77
66
  <svelte:element this={opts.titleTag} class="accordion-title {titleClass}">
78
67
  <button
79
68
  class="accordion-button {buttonClass}"
69
+ aria-controls={id}
70
+ aria-expanded={show}
80
71
  onclick={handleClick}
81
72
  onkeydown={handleKeydown}
82
- aria-expanded={show}
83
- aria-controls={id}
84
73
  >
85
- <!-- Icon start -->
86
- {#if opts.iconLocation === 'start'}{@render iconBlock()}{/if}
87
- {@render title()}
88
- {#if opts.iconLocation === 'end'}{@render iconBlock()}{/if}
74
+ <!-- Icon (if start) -->
75
+ {#if opts.iconPosition === 'start'}
76
+ {@render IconSnippet.block({ icon, iconClass })}
77
+ {/if}
78
+
79
+ <!-- Title -->
80
+ {@render MarkdownSnippet.inline(title, useMarkdown)}
81
+
82
+ <!-- Icon (if end) -->
83
+ {#if opts.iconPosition === 'end'}
84
+ {@render IconSnippet.block({ icon, iconClass })}
85
+ {/if}
89
86
  </button>
90
87
  </svelte:element>
91
88
 
92
- {#if show === true}
89
+ {#if show}
93
90
  <div
94
91
  {id}
95
92
  class="accordion-content {contentClass}"
93
+ use:reloadScripts
96
94
  transition:applyTransition={{
97
95
  transition: opts.transition,
98
96
  }}
99
97
  >
100
- {#if content}{@render content()}{/if}
101
- {#if children}{@render children()}{/if}
98
+ {@render MarkdownSnippet.block(content || children, useMarkdown)}
102
99
  </div>
103
100
  {/if}
104
101
 
105
- <!-- Hidden button for closing multiple accordions only, only accessible via JS -->
106
- <!-- svelte-ignore a11y_consider_explicit_label a11y_incorrect_aria_attribute_type_boolean -->
102
+ <!-- Hidden button for closing multiple accordions. Accessible via JS only -->
107
103
  <button
108
- onclick={closeAccordion}
109
- class="accordion-close-button"
110
104
  style="display:none"
111
- hidden
105
+ class="accordion-close-button"
112
106
  aria-hidden="true"
107
+ hidden
108
+ onclick={closeAccordion}
113
109
  tabindex="-1"
114
110
  ></button>
115
111
  </div>
@@ -1,36 +1,93 @@
1
1
  <script>
2
+ import { randomString } from '@splendidlabz/utils/dom'
2
3
  import { Resizer } from '../Resizer/index.js'
4
+ import { Tab, Tablist, Tabpanels } from '../Tabs/index.js'
5
+ let { elem = $bindable(null), ...p } = $props()
3
6
 
4
- let klass = ''
5
- export { klass as class }
6
- export let frameContentClass = ''
7
- export let contentClass = ''
8
- export let options = {}
9
- export let elem = null
7
+ const {
8
+ class: klass = '',
9
+
10
+ frameContentClass = '',
11
+ contentClass = '',
12
+ options = {},
13
+
14
+ // Tablist options
15
+ tablistClass = null,
16
+ tablistTarget = randomString(8),
17
+ selectedTabIndex = 0,
18
+
19
+ // Slots
20
+ children,
21
+ background,
22
+ } = p
23
+
24
+ let { tablistItems = [] } = p
25
+ const tabs = tablistItems.length > 0
26
+ if (tablistItems.length > 0) {
27
+ tablistItems = tablistItems.map(tab => {
28
+ if (typeof tab === 'string') return { text: tab }
29
+ return tab
30
+ })
31
+ }
32
+
33
+ // Parse tablistItems so they're easier to use
10
34
  </script>
11
35
 
12
- <div class="BrowserFrame {klass}" bind:this={elem}>
13
- <div class="Vertical gap-0">
14
- <div class="FrameHeader">
15
- <div class="FrameHeaderDots">
16
- <div class="FrameHeaderDot"></div>
17
- <div class="FrameHeaderDot"></div>
18
- <div class="FrameHeaderDot"></div>
19
- </div>
20
- <div class="FrameHeaderTabs">
21
- <slot name="tablist" />
36
+ {#snippet tablist()}
37
+ <div class="frame-tabs">
38
+ <Tablist
39
+ class="tablist-tab tablist-top {tablistClass}"
40
+ target={tablistTarget}
41
+ >
42
+ {#each tablistItems as tab, index (tab)}
43
+ {@const { text, ...tabRest } = tab}
44
+ <Tab {...tabRest} active={index === selectedTabIndex}>
45
+ {text}
46
+ </Tab>
47
+ {/each}
48
+ </Tablist>
49
+ </div>
50
+ {/snippet}
51
+
52
+ {#snippet tabpanels()}
53
+ <Tabpanels id={tablistTarget} class="border-0 p-0">
54
+ {#if children}{@render children()}{/if}
55
+ </Tabpanels>
56
+ {/snippet}
57
+
58
+ {#snippet dot()}
59
+ <svg class="frame-dot" viewBox="0 0 24 24">
60
+ <circle cx="12" cy="12" r="12" />
61
+ </svg>
62
+ {/snippet}
63
+
64
+ <div bind:this={elem} class="browserframe {klass}">
65
+ <div class="vertical gap-0">
66
+ <div class="frame-header">
67
+ <div class="frame-dots">
68
+ {@render dot()}
69
+ {@render dot()}
70
+ {@render dot()}
22
71
  </div>
72
+ {#if tabs}
73
+ {@render tablist()}
74
+ {/if}
23
75
  </div>
24
- <div class="FrameContent Stack {frameContentClass}">
25
- <div class="Background">
26
- <slot name="background" />
27
- </div>
28
- <div class="Content Vertical {contentClass}">
29
- <slot name="tabpanels" />
30
- <slot />
76
+ <div class="frame-content stack {frameContentClass}">
77
+ {#if background}
78
+ <div class="background">
79
+ {@render background()}
80
+ </div>
81
+ {/if}
82
+
83
+ <div class="content vertical {contentClass}">
84
+ {#if tabs}
85
+ {@render tabpanels()}
86
+ {:else if children}{@render children()}{/if}
31
87
  </div>
88
+
32
89
  {#if options.resize}
33
- <Resizer options={{ target: '.BrowserFrame', ...options.resize }} />
90
+ <Resizer options={{ target: '.browserframe', ...options.resize }} />
34
91
  {/if}
35
92
  </div>
36
93
  </div>
@@ -1,9 +1,15 @@
1
1
  <script>
2
+ import { Resizer } from '../Resizer/index.js'
3
+
2
4
  let klass = ''
3
5
  export { klass as class }
6
+ export let frameContentClass = ''
7
+ export let contentClass = ''
8
+ export let options = {}
9
+ export let elem = null
4
10
  </script>
5
11
 
6
- <div class="BrowserFrame {klass}">
12
+ <div class="BrowserFrame {klass}" bind:this={elem}>
7
13
  <div class="Vertical gap-0">
8
14
  <div class="FrameHeader">
9
15
  <div class="FrameHeaderDots">
@@ -15,14 +21,17 @@
15
21
  <slot name="tablist" />
16
22
  </div>
17
23
  </div>
18
- <div class="FrameContent Stack">
24
+ <div class="FrameContent Stack {frameContentClass}">
19
25
  <div class="Background">
20
26
  <slot name="background" />
21
27
  </div>
22
- <div class="Content Vertical">
28
+ <div class="Content Vertical {contentClass}">
23
29
  <slot name="tabpanels" />
24
30
  <slot />
25
31
  </div>
32
+ {#if options.resize}
33
+ <Resizer options={{ target: '.BrowserFrame', ...options.resize }} />
34
+ {/if}
26
35
  </div>
27
36
  </div>
28
37
  </div>
@@ -2,20 +2,25 @@
2
2
  import { delay } from '@splendidlabz/utils'
3
3
  import { getParentElement } from '@splendidlabz/utils/dom'
4
4
  import { onMount } from 'svelte'
5
- import { getEntry, mergeEntry } from '../../../actions/sync.svelte.js'
5
+ import { mergeEntry, setEntry } from '../../../actions/sync.svelte.js'
6
6
  import Modal from '../ModalNew/Modal.svelte'
7
7
  import Popover from '../PopoverNew/Popover.svelte'
8
8
 
9
- let { class: klass = '', ref = $bindable(null), ...p } = $props()
10
- const { id, position, useReferenceBoundaries, ...rest } = p
9
+ let {
10
+ class: klass = '',
11
+ type = 'modal',
12
+ ref = $bindable(null),
13
+ ...p
14
+ } = $props()
15
+
16
+ const { id, ...rest } = p
17
+ const useReferenceBoundaries = type === 'popover'
11
18
 
12
19
  const localRef = $state(null)
13
20
  if (!ref) ref = () => localRef
14
21
 
15
22
  let referenceNode = $state(null)
16
-
17
- const sync = $derived(getEntry(id))
18
- const type = $derived(sync?.type)
23
+ setEntry(id, { type })
19
24
 
20
25
  onMount(async _ => {
21
26
  await delay(0)
@@ -25,7 +30,6 @@
25
30
 
26
31
  const propsToPass = {
27
32
  id,
28
- position,
29
33
  ...rest,
30
34
  componentName: 'Drawer',
31
35
  class: `drawer ${klass}`,
@@ -35,5 +39,5 @@
35
39
  {#if type === 'modal'}
36
40
  <Modal bind:ref {...propsToPass} />
37
41
  {:else}
38
- <Popover bind:ref {...propsToPass} {referenceNode} {useReferenceBoundaries} />
42
+ <Popover {referenceNode} {useReferenceBoundaries} bind:ref {...propsToPass} />
39
43
  {/if}
@@ -0,0 +1,19 @@
1
+ <script>
2
+ import { getEntry } from '../../../actions/sync.svelte.js'
3
+ import ModalClose from '../ModalNew/ModalClose.svelte'
4
+ import PopoverClose from '../PopoverNew/PopoverClose.svelte'
5
+
6
+ const { target, ...p } = $props()
7
+
8
+ let sync = $derived(getEntry(target))
9
+ let type = $derived(sync?.type)
10
+
11
+ $inspect(sync)
12
+ </script>
13
+
14
+ <!-- FUCK THIS DOESN'T WORK -->
15
+ {#if type === 'popover'}
16
+ <PopoverClose {...p} {target} />
17
+ {:else}
18
+ <ModalClose {...p} {target} />
19
+ {/if}
@@ -1,12 +1,11 @@
1
1
  <script>
2
- import { getEntry, setEntry } from '../../../actions/sync.svelte.js'
2
+ import { getEntry } from '../../../actions/sync.svelte.js'
3
3
  import ModalTrigger from '../ModalNew/ModalTrigger.svelte'
4
4
  import PopoverTrigger from '../PopoverNew/PopoverTrigger.svelte'
5
+ let { show = $bindable(false), target, ...p } = $props()
5
6
 
6
- let { show = $bindable(false), type = 'modal', target, ...p } = $props()
7
-
8
- setEntry(target, { type })
9
7
  const sync = $derived(getEntry(target))
8
+ const type = $derived(sync?.type)
10
9
  </script>
11
10
 
12
11
  {#if type === 'modal'}
@@ -14,7 +14,7 @@
14
14
 
15
15
  // Props
16
16
  // scrollToAnchor = false,
17
- lightDismiss = true, // TODO: Allow light dismiss
17
+ lightDismiss = true,
18
18
 
19
19
  // Event listeners
20
20
  onclick = null,
@@ -27,10 +27,21 @@
27
27
  ...rest
28
28
  } = p
29
29
 
30
- const placementClass = `fixed-${placement}full`
31
- const transitionClass = `fly-from-${placement}`
32
- // const animationInClass = `animation-fly-in-${placement}`
33
- // const animationOutClass = `animation-fly-out-${placement}`
30
+ const placementClass = {
31
+ top: 'fixed-topfull',
32
+ bottom: 'fixed-bottomfull',
33
+ left: 'fixed-leftfull',
34
+ right: 'fixed-rightfull',
35
+ center: '',
36
+ }[placement]
37
+
38
+ const transitionClass = {
39
+ top: 'fly-from-top',
40
+ bottom: 'fly-from-bottom',
41
+ left: 'fly-from-left',
42
+ right: 'fly-from-right',
43
+ center: '',
44
+ }[placement]
34
45
 
35
46
  // ========================
36
47
  // Checks
@@ -63,11 +74,16 @@
63
74
  }
64
75
 
65
76
  function handleClick(event) {
77
+ // Don't activate any clicks from within the modal
78
+ if (event.target !== ref) return
79
+
80
+ // Calculates whether to light dismiss based on clicked location
66
81
  if (lightDismiss) {
67
82
  const { x, y } = event
68
83
  // https://codepen.io/aslhnates/pen/KKKpmpd?editors=0010
69
84
  if (clickOutsideRect(ref, { x, y })) ref.close('click')
70
85
  }
86
+
71
87
  if (onclick) onclick(event)
72
88
  }
73
89
 
@@ -76,15 +92,6 @@
76
92
  if (onkeydown) onkeydown(event)
77
93
  }
78
94
 
79
- function onanimationend(event) {
80
- // console.log('animationend')
81
- // const classes = Array.from(ref.classList)
82
- // const animationClasses = classes.filter(c => c.startsWith('animation-'))
83
- // console.log(animationClasses)
84
- // animationClasses.forEach(c => ref.classList.remove(c))
85
- // console.log(ref.classList)
86
- }
87
-
88
95
  function clickOutsideRect(element, clickedPos) {
89
96
  const { x, y } = clickedPos
90
97
  const rect = element.getBoundingClientRect()
@@ -94,17 +101,16 @@
94
101
 
95
102
  <dialog
96
103
  {...rest}
97
- {id}
98
104
  bind:this={ref}
105
+ {id}
99
106
  class="modal {placementClass} {transitionClass} {klass}"
107
+ aria-describedby={ariaDescribedBy}
100
108
  aria-label={ariaLabel}
101
109
  aria-labelledby={ariaLabelledBy}
102
- aria-describedby={ariaDescribedBy}
103
- ontoggle={handleToggle}
104
110
  onbeforetoggle={beforetoggle}
105
111
  onclick={handleClick}
106
112
  onkeydown={handleKeydown}
107
- {onanimationend}
113
+ ontoggle={handleToggle}
108
114
  >
109
115
  {#if children}{@render children()}{/if}
110
116
  </dialog>
@@ -55,9 +55,9 @@
55
55
  bind:this={ref}
56
56
  class="button {klass}"
57
57
  aria-haspopup="dialog"
58
- onclick={handleClick}
59
- data-show={show}
60
58
  data-modal-trigger={target}
59
+ data-show={show}
60
+ onclick={handleClick}
61
61
  ontoggle={handleToggle}
62
62
  >
63
63
  {#if children}
@@ -1,5 +1,5 @@
1
1
  <script>
2
- import { isInvalidAriaPopup } from '../../../actions/accessibility.js'
2
+ import { isInvalidAriaPopup } from '@splendidlabz/utils/dom'
3
3
  import { disclosureTrigger } from '../disclosure.js'
4
4
  import { DEFAULT_POPOVER_TRIGGER_OPTS } from './popover.js'
5
5
 
@@ -28,6 +28,8 @@
28
28
  // Event listeners
29
29
  onbeforetoggle = null,
30
30
  ontoggle = null,
31
+ onopen = null,
32
+ onclose = null,
31
33
 
32
34
  // Slots
33
35
  children,
@@ -82,7 +84,19 @@
82
84
  function handleToggle(event) {
83
85
  passEventToTrigger(event, trigger)
84
86
  const { newState } = event
85
- if (newState === 'closed') floating.cleanup()
87
+
88
+ // Send open event
89
+ if (newState === 'open') {
90
+ if (onopen) onopen(event)
91
+ }
92
+
93
+ if (newState === 'closed') {
94
+ floating.cleanup()
95
+ // Send close event
96
+ if (onclose) onclose(event)
97
+ }
98
+
99
+ // Send toggle event
86
100
  if (ontoggle) ontoggle(event)
87
101
  }
88
102
  </script>
@@ -93,13 +107,13 @@
93
107
  bind:this={ref}
94
108
  {...rest}
95
109
  {id}
96
- {popover}
97
110
  class={klass}
111
+ aria-describedby={ariaDescribedBy}
98
112
  aria-label={ariaLabel}
99
113
  aria-labelledby={ariaLabelledBy}
100
- aria-describedby={ariaDescribedBy}
101
114
  onbeforetoggle={beforetoggle}
102
115
  ontoggle={handleToggle}
116
+ {popover}
103
117
  >
104
118
  {#if children}{@render children()}{/if}
105
119
  </svelte:element>
@@ -6,8 +6,8 @@ import {
6
6
  offset as offsetFn,
7
7
  shift,
8
8
  } from '@floating-ui/dom'
9
- import { getCSSVar, setCSSVar, toPx } from '@splendidlabz/utils/dom'
10
9
  import { mix, splitUnit, toRadians } from '@splendidlabz/utils'
10
+ import { getCSSVar, setCSSVar, toPx } from '@splendidlabz/utils/dom'
11
11
 
12
12
  // TODO: Add inline for tooltips
13
13
  export const FLOATING_OPTS = {
@@ -50,20 +50,20 @@
50
50
  <div class="radiomark-container">
51
51
  <input
52
52
  {...rest}
53
- class="input {fieldClass}"
54
- type="radio"
53
+ bind:this={ref}
55
54
  {id}
56
55
  {name}
56
+ class="input {fieldClass}"
57
57
  {checked}
58
58
  disabled={disabled || readonly}
59
+ onchange={handleChange}
60
+ type="radio"
59
61
  {value}
60
62
  bind:group
61
- bind:this={ref}
62
- onchange={handleChange}
63
63
  />
64
64
 
65
65
  {#if readonly && checked}
66
- <input type="hidden" {name} {value} {checked} />
66
+ <input {name} {checked} type="hidden" {value} />
67
67
  {/if}
68
68
 
69
69
  {#if icon}
@@ -11,7 +11,7 @@
11
11
 
12
12
  let iconData
13
13
  let innerHTML
14
- let attributes = {
14
+ const attributes = {
15
15
  class: `${icon.split(':')[1]}`,
16
16
  role: 'img',
17
17
  xmlns: 'http://www.w3.org/2000/svg',
@@ -37,7 +37,8 @@
37
37
  </script>
38
38
 
39
39
  {#if innerHTML}
40
- <svg {...attributes}> {@html innerHTML} </svg>
40
+ <!-- eslint-disable-next-line svelte/no-at-html-tags -->
41
+ <svg aria-hidden="true" {...attributes}> {@html innerHTML} </svg>
41
42
  {:else}
42
- <svg {...attributes} />
43
+ <svg aria-hidden="true" {...attributes} />
43
44
  {/if}
@@ -1,7 +1,14 @@
1
- <script>
2
- export { IconSnippet }
1
+ <script module>
2
+ import { isSlot } from '../../utils'
3
+ import Icon from './Icon.svelte'
4
+ export const IconSnippet = { block }
3
5
  </script>
4
6
 
5
- {#snippet IconSnippet({ icon, iconClass, children })}
6
- aoeunsthaoeusnthaoeu
7
+ <!-- Icon block -->
8
+ {#snippet block({ icon, iconClass })}
9
+ {#if isSlot(icon)}
10
+ {@render icon()}
11
+ {:else}
12
+ <Icon class={iconClass} {icon} />
13
+ {/if}
7
14
  {/snippet}
@@ -1,2 +1,3 @@
1
1
  import Icon from './Icon.svelte'
2
- export { Icon }
2
+ import IconSnippet from './IconSnippet.svelte'
3
+ export { Icon, IconSnippet }
@@ -9,13 +9,17 @@
9
9
  import { markdown } from '@splendidlabz/utils'
10
10
 
11
11
  const { content, inline = false } = $props()
12
- let html = $state('')
13
12
 
14
- // My hunch is effects isn't needed here.
15
- $effect(_ => {
16
- html = markdown(content, { inline })
17
- if (inline) html = html.replace('<p>', '').replace('</p>', '')
18
- })
13
+ // svelte-ignore non_reactive_update
14
+ let html = ''
15
+ html = markdown(content, { inline })
16
+ if (inline) {
17
+ // Replace enclosing <p> tags with <span> tags
18
+ // Makes it possible to use other tags like <em> without disrupting the layout
19
+ html = html.replace('<p>', '<span>').replace('</p>', '</span>')
20
+ html = `<span> ${html} </span>`
21
+ }
19
22
  </script>
20
23
 
24
+ <!-- eslint-disable-next-line svelte/no-at-html-tags -->
21
25
  {@html html}
@@ -0,0 +1,27 @@
1
+ <script module>
2
+ import { isSlot } from '../../utils'
3
+ import Markdown from './Markdown.svelte'
4
+ export const MarkdownSnippet = { block, inline }
5
+ </script>
6
+
7
+ <!-- Inline -->
8
+ {#snippet inline(content, useMarkdown = true)}
9
+ {#if isSlot(content)}
10
+ {@render content()}
11
+ {:else if useMarkdown}
12
+ <Markdown {content} inline />
13
+ {:else}
14
+ {content}
15
+ {/if}
16
+ {/snippet}
17
+
18
+ <!-- Standard -->
19
+ {#snippet block(content, useMarkdown = true)}
20
+ {#if isSlot(content)}
21
+ {@render content()}
22
+ {:else if useMarkdown}
23
+ <Markdown {content} />
24
+ {:else}
25
+ {content}
26
+ {/if}
27
+ {/snippet}
@@ -1,6 +1,6 @@
1
1
  <script>
2
+ import { resizeObserver } from '@splendidlabz/utils/dom'
2
3
  import { onMount } from 'svelte'
3
- import { resizeObserver } from '../../actions'
4
4
 
5
5
  let klass = ''
6
6
  export { klass as class }
@@ -1,7 +1,6 @@
1
1
  <script>
2
- import { resizeObserver } from '../../actions'
3
2
  import { notEmpty } from '@splendidlabz/utils'
4
- import { getElement } from '@splendidlabz/utils/dom'
3
+ import { getElement, resizeObserver } from '@splendidlabz/utils/dom'
5
4
 
6
5
  let klass = ''
7
6
  export { klass as class }
@@ -1,12 +1,7 @@
1
1
  <script>
2
- export let klass = ''
3
- export let active = null
4
- export { klass as class }
5
-
6
- // Easier API for users
7
- if (active === false) active = null
2
+ const { class: klass = '', active, ...rest } = $props()
8
3
  </script>
9
4
 
10
- <button aria-selected={active} class="Tab {klass}" role="tab" {...$$restProps}>
5
+ <button {...rest} class="tab {klass}" aria-selected={active} role="tab">
11
6
  <slot />
12
7
  </button>
@@ -1,5 +1,5 @@
1
1
  <script>
2
- import { preferHorizontalScroll as preferHorizontalScrollAction } from '@splendidlabz/utils/actions'
2
+ import { preferHorizontalScroll as preferHorizontalScrollAction } from '@splendidlabz/utils/dom'
3
3
  import { breakpointObserver } from '../../actions/breakpoint-observer.js'
4
4
  import { tabs } from './tab-store.js'
5
5
  import { tablist, updatePlacement } from './tabs.js'
@@ -24,7 +24,31 @@
24
24
  let placement = initialPlacement || 'top'
25
25
 
26
26
  let tab
27
+ let tablistClasses
27
28
  $: tab = $tabs.find(t => t.id === target)
29
+ $: tablistClasses = getTablistClasses(tab)
30
+
31
+ function getTablistClasses(tab) {
32
+ if (!tab) return ''
33
+ const { placement } = tab.state
34
+
35
+ const tablistClass = {
36
+ top: 'tablist-top',
37
+ left: 'tablist-left',
38
+ right: 'tablist-right',
39
+ }[placement]
40
+
41
+ // Gah these need to change according to the placement
42
+ const scrollableClass = [
43
+ placement === 'top' && scrollable && 'scrollable-horizontal',
44
+ placement === 'top' &&
45
+ preferHorizontalScroll &&
46
+ 'scrollable-preferHorizontalScroll',
47
+ placement === 'top' && preserveOutlines && 'preserve-outlines',
48
+ ].join(' ')
49
+
50
+ return `${tablistClass} ${scrollableClass}`
51
+ }
28
52
 
29
53
  function breakpointCB({ value }) {
30
54
  placement = value.placement
@@ -33,22 +57,11 @@
33
57
  </script>
34
58
 
35
59
  <div
60
+ {style}
61
+ class="tablist {tablistClasses} {klass}"
36
62
  role="tablist"
37
63
  {target}
38
- class="Tablist {klass}"
39
- class:Tablist-top={placement === 'top'}
40
- class:Tablist-left={placement === 'left'}
41
- class:Tablist-right={placement === 'right'}
42
- class:Scrollable-horizontal={placement === 'top' && scrollable}
43
- class:Scrollable-preferHorizontalScroll={placement === 'top' &&
44
- preferHorizontalScroll}
45
- class:Scrollable-preserveOutlines={preserveOutlines}
46
- {style}
47
64
  {...$$restProps}
48
- use:tablist={{
49
- state: { placement },
50
- options: rest,
51
- }}
52
65
  on:tab-change
53
66
  use:breakpointObserver={{
54
67
  breakpoints,
@@ -56,6 +69,10 @@
56
69
  callback: breakpointCB,
57
70
  }}
58
71
  use:preferHorizontalScrollAction
72
+ use:tablist={{
73
+ state: { placement },
74
+ options: rest,
75
+ }}
59
76
  >
60
77
  <!-- Need to add callback to breakpoint opts -->
61
78
  <slot />
@@ -1,10 +1,7 @@
1
1
  <script>
2
- export let klass = ''
3
- export let id = ''
4
- export let active = false
5
- export { klass as class }
2
+ const { id, class: klass = '', active = false, ...rest } = $props()
6
3
  </script>
7
4
 
8
- <div hidden={!active} {id} class="Tabpanel {klass}" role="tabpanel">
5
+ <div {...rest} {id} class="tabpanel {klass}" role="tabpanel" hidden={!active}>
9
6
  <slot />
10
7
  </div>
@@ -1,12 +1,9 @@
1
1
  <script>
2
2
  import { tabpanels } from './tabs.js'
3
3
 
4
- export let klass = ''
5
- export { klass as class }
6
-
7
- export let id = null
4
+ const { id = null, class: klass = '', ...rest } = $props()
8
5
  </script>
9
6
 
10
- <div {id} class="Tabpanels {klass}" use:tabpanels>
7
+ <div {...rest} {id} class="tabpanels {klass}" use:tabpanels>
11
8
  <slot />
12
9
  </div>
@@ -0,0 +1,46 @@
1
+ <script>
2
+ import { randomString } from '@splendidlabz/utils/dom'
3
+ import Tab from './Tab.svelte'
4
+ import Tablist from './Tablist.svelte'
5
+ import Tabpanels from './Tabpanels.svelte'
6
+ const { tabs, ...p } = $props()
7
+
8
+ const {
9
+ id = randomString(),
10
+ class: klass = '',
11
+ activeIndex = 0,
12
+ tablistClass = '',
13
+ tabClass = '',
14
+ tabpanelsClass = '',
15
+ tablistOptions,
16
+ tabOptions,
17
+ tabpanelsOptions,
18
+ children,
19
+ ...rest
20
+ } = p
21
+ </script>
22
+
23
+ <Tablist
24
+ {...rest}
25
+ class="{klass} {tablistClass}"
26
+ target={id}
27
+ {...tablistOptions}
28
+ >
29
+ {#each tabs as tab, index (tab)}
30
+ {@const { text, ...tabRest } = tab}
31
+ <Tab
32
+ class={tabClass}
33
+ active={index === activeIndex}
34
+ {tabpanelsOptions}
35
+ {...tabRest}
36
+ >
37
+ {text}
38
+ </Tab>
39
+ {/each}
40
+ </Tablist>
41
+
42
+ {#if children}
43
+ <Tabpanels {id} class={tabpanelsClass} {...tabpanelsOptions}>
44
+ {children()}
45
+ </Tabpanels>
46
+ {/if}
@@ -2,5 +2,6 @@ import Tab from './Tab.svelte'
2
2
  import Tablist from './Tablist.svelte'
3
3
  import Tabpanel from './Tabpanel.svelte'
4
4
  import Tabpanels from './Tabpanels.svelte'
5
+ import Tabs from './Tabs.svelte'
5
6
 
6
- export { Tab, Tablist, Tabpanel, Tabpanels }
7
+ export { Tab, Tablist, Tabpanel, Tabpanels, Tabs }
@@ -1,6 +1,5 @@
1
- import { get, writable } from 'svelte/store'
2
-
3
1
  import { omitEmpty } from '@splendidlabz/utils'
2
+ import { get, writable } from 'svelte/store'
4
3
 
5
4
  export const tabs = writable([])
6
5
  const { update } = tabs
@@ -1,3 +1,5 @@
1
+ import { all as layoutScripts } from '@splendidlabz/styles/scripts'
2
+ import { omitEmpty } from '@splendidlabz/utils'
1
3
  import {
2
4
  Focusable,
3
5
  addListeners,
@@ -8,9 +10,6 @@ import {
8
10
  } from '@splendidlabz/utils/dom'
9
11
  import { initTab, updateTab } from './tab-store'
10
12
 
11
- import LayoutScripts from '@splendidlabz/styles/scripts/all'
12
- import { omitEmpty } from '@splendidlabz/utils'
13
-
14
13
  export const DEFAULT_TABLIST_OPTIONS = {
15
14
  state: {
16
15
  placement: 'top', // top, left, right
@@ -37,11 +36,11 @@ export function tablist(node, props) {
37
36
 
38
37
  // The filter allows us to nest tabs in tabs
39
38
  const tablistItems = Array.from(node.querySelectorAll('[role="tab"]')).filter(
40
- tab => tab.closest('.Tablist') === node
39
+ tab => tab.closest('.tablist') === node,
41
40
  )
42
41
  let activeTabIndex
43
42
  activeTabIndex = tablistItems.findIndex(tab =>
44
- tab.hasAttribute('aria-selected')
43
+ tab.hasAttribute('aria-selected'),
45
44
  )
46
45
  if (activeTabIndex === -1) activeTabIndex = 0
47
46
 
@@ -130,12 +129,12 @@ export function tabpanels(node, props) {
130
129
 
131
130
  // The filter allows us to nest tabs in tabs
132
131
  const tabpanelItems = Array.from(
133
- node.querySelectorAll('[role="tabpanel"]')
134
- ).filter(tab => tab.closest('.Tabpanels') === node)
132
+ node.querySelectorAll('[role="tabpanel"]'),
133
+ ).filter(tab => tab.closest('.tabpanels') === node)
135
134
 
136
135
  let activeTabIndex
137
136
  activeTabIndex = tabpanelItems.findIndex(
138
- tabpanel => !tabpanel.hasAttribute('hidden')
137
+ tabpanel => !tabpanel.hasAttribute('hidden'),
139
138
  )
140
139
  if (activeTabIndex === -1) activeTabIndex = 0
141
140
 
@@ -166,9 +165,9 @@ export function tabpanels(node, props) {
166
165
  }
167
166
 
168
167
  function handleKeydown(event) {
169
- if (!event.target.matches('.Tabpanel')) return
168
+ if (!event.target.matches('.tabpanel')) return
170
169
 
171
- if (event.target.closest('.Tabpanels') !== node) return
170
+ if (event.target.closest('.tabpanels') !== node) return
172
171
 
173
172
  const { placement } = Tab.state
174
173
  const { key } = event
@@ -204,10 +203,10 @@ function setInitialState(Tab) {
204
203
  // Hash-based initiation
205
204
  // Activates tab and tabpanel if hashed ID is within the tabpanel.
206
205
  const element = document.querySelector(hash)
207
- const inTabpanel = element?.closest('.Tabpanels') === tabpanels
206
+ const inTabpanel = element?.closest('.tabpanels') === tabpanels
208
207
  if (!inTabpanel) return
209
208
 
210
- const closestTabpanel = element.closest('.Tabpanel')
209
+ const closestTabpanel = element.closest('.tabpanel')
211
210
  const index = getSelfIndex(closestTabpanel)
212
211
  selectTab(Tab, index, { shouldUpdateHash: false, shouldScroll: false })
213
212
 
@@ -224,7 +223,11 @@ function setInitialState(Tab) {
224
223
  export function selectTab(
225
224
  Tab,
226
225
  index,
227
- { shouldFocusOnTab = true, shouldUpdateHash = true, shouldScroll = true } = {}
226
+ {
227
+ shouldFocusOnTab = true,
228
+ shouldUpdateHash = true,
229
+ shouldScroll = true,
230
+ } = {},
228
231
  ) {
229
232
  Tab.state.activeTabIndex = index
230
233
  updateTab(Tab)
@@ -246,7 +249,7 @@ export function selectTab(
246
249
  // If it does, we need to import layout scripts with await import.
247
250
  // Then we'll have to turn `selectTab` into an async function and manage the rest accordingly
248
251
  if (Tab.options.runLayoutScripts) {
249
- setTimeout(_ => LayoutScripts(activePanel), 0)
252
+ setTimeout(_ => layoutScripts(activePanel), 0)
250
253
  }
251
254
 
252
255
  const { useHash, autoplay } = Tab.options
@@ -1,6 +1,6 @@
1
1
  <script>
2
2
  export let times = 1
3
- let ariaHidden = $$restProps['aria-hidden']
3
+ const ariaHidden = $$restProps['aria-hidden']
4
4
  </script>
5
5
 
6
6
  <div aria-hidden={ariaHidden}>
@@ -6,8 +6,7 @@
6
6
  export let contentClass
7
7
  export let repeat = 100
8
8
 
9
- let ariaLabel = $$restProps['aria-label']
10
-
9
+ const ariaLabel = $$restProps['aria-label']
11
10
  if (!ariaLabel) throw new Error('aria-label is required for text wall')
12
11
  </script>
13
12
 
package/index.js CHANGED
@@ -21,7 +21,10 @@ export * from './components/Scrambler/index.js'
21
21
  export * from './components/Switcheroo/index.js'
22
22
  export * from './components/Table/index.js'
23
23
  export * from './components/Tabs/index.js'
24
+
25
+ // TO REMOVE AFTER SHIFTING TO ASTRO
24
26
  export * from './components/Textwall/index.js'
27
+
25
28
  export * from './components/Typewriter/index.js'
26
29
 
27
30
  export { default as Copyright } from './components/Copyright.svelte'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@splendidlabz/svelte",
3
3
  "type": "module",
4
- "version": "4.0.0-alpha.0",
4
+ "version": "4.0.0-alpha.2",
5
5
  "sideEffects": false,
6
6
  "scripts": {
7
7
  "lint": "eslint . --fix",
@@ -18,15 +18,14 @@
18
18
  "dependencies": {
19
19
  "@floating-ui/dom": "^1.6.13",
20
20
  "@iconify/svelte": "^4.2.0",
21
- "@splendidlabz/layouts": "*",
22
- "@splendidlabz/styles": "3.0.0-alpha.8",
23
- "@splendidlabz/utils": "1.5.0-alpha.3",
21
+ "@splendidlabz/styles": "4.0.0-alpha.2",
22
+ "@splendidlabz/utils": "1.5.0-alpha.4",
24
23
  "autosuggest-highlight": "^3.3.4",
25
24
  "lodash-es": "^4.17.21",
26
25
  "node-html-parser": "^7.0.1"
27
26
  },
28
27
  "devDependencies": {
29
- "@splendidlabz/eslint-config": "2.0.0-alpha.0",
28
+ "@splendidlabz/eslint-config": "2.0.0-alpha.1",
30
29
  "svelte": "^5.25.6",
31
30
  "vitest": "^3.1.1"
32
31
  }
package/utils/index.js CHANGED
@@ -1,2 +1,3 @@
1
+ export * from './is-slot.js'
1
2
  export * from './merge-opts.js'
2
3
  export * from './transitions.js'
@@ -0,0 +1,3 @@
1
+ export function isSlot(value) {
2
+ return typeof value === 'function'
3
+ }
@@ -0,0 +1,58 @@
1
+ export function reloadScripts(node) {
2
+ let scripts = []
3
+ const scriptElements = Array.from(node.querySelectorAll('script'))
4
+
5
+ scriptElements.forEach(origScript => {
6
+ const script = document.createElement('script')
7
+ Array.from(origScript.attributes).forEach(attr => {
8
+ script.setAttribute(attr.name, attr.value)
9
+ })
10
+ scripts.push(script)
11
+ origScript.remove()
12
+ })
13
+
14
+ // Only execute scripts when shown
15
+ scripts.forEach(script => {
16
+ node.appendChild(script)
17
+ })
18
+ scripts = [] // Clear after execution
19
+ }
20
+
21
+ // function loadScript(s, element = document.body) {
22
+ // const script = document.createElement('script')
23
+ // Object.assign(script, s)
24
+ // element.append(script)
25
+ // }
26
+
27
+ // // // Action
28
+ // // // Loads immediately
29
+ // // export function loadScripts(node, scripts = null) {
30
+ // // if (!scripts) return
31
+ // // if (!Array.isArray(scripts)) scripts = [scripts]
32
+ // // scripts.forEach(s => loadScript(s, node))
33
+ // // }
34
+
35
+ // // ScriptLoader for preloading / prefetching
36
+ // export function createScriptLoader(scripts, strategy = 'prefetch') {
37
+ // if (!scripts) return
38
+
39
+ // let loaded = false
40
+ // if (strategy === 'prefetch' || strategy === 'preload') {
41
+ // scripts.forEach(s => {
42
+ // const link = document.createElement('link')
43
+ // link.rel = strategy
44
+ // link.as = 'script'
45
+ // link.href = s.src
46
+ // document.head.append(link)
47
+ // link.remove()
48
+ // })
49
+ // }
50
+
51
+ // return {
52
+ // load() {
53
+ // if (loaded) return
54
+ // loaded = true
55
+ // scripts.forEach(s => loadScript(s))
56
+ // },
57
+ // }
58
+ // }