@splendidlabz/svelte 4.8.3 → 4.8.5

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 (51) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/components/Accordion/Accordion.svelte +17 -21
  3. package/components/Breadcrumbs/Breadcrumbs.svelte +8 -19
  4. package/components/Breadcrumbs/Crumb.svelte +19 -14
  5. package/components/BrowserFrame/BrowserFrame.svelte +8 -16
  6. package/components/Codepen/Codepen.svelte +2 -1
  7. package/components/ContentList/ContentList.svelte +6 -7
  8. package/components/Copyright.svelte +6 -7
  9. package/components/Disclosure/Disclosure/DisclosureContent.svelte +21 -21
  10. package/components/Disclosure/Disclosure/DisclosureTrigger.svelte +23 -22
  11. package/components/Disclosure/Drawer/DrawerCloseButton.svelte +2 -2
  12. package/components/Disclosure/Drawer/DrawerContent.svelte +20 -18
  13. package/components/Disclosure/Modal/ModalCloseButton.svelte +3 -6
  14. package/components/Disclosure/Modal/ModalContent.svelte +18 -19
  15. package/components/Disclosure/Modal/ModalTrigger.svelte +9 -11
  16. package/components/Disclosure/Popover/PopoverCloseButton.svelte +4 -5
  17. package/components/Disclosure/Popover/PopoverContent.svelte +12 -23
  18. package/components/Disclosure/Popover/PopoverTrigger.svelte +9 -13
  19. package/components/FancyList/FancyList.svelte +3 -6
  20. package/components/Form/ButtonGroup.svelte +30 -22
  21. package/components/Form/Checkbox.svelte +23 -18
  22. package/components/Form/Checkboxes.svelte +29 -27
  23. package/components/Form/Form.svelte +3 -6
  24. package/components/Form/Radio.svelte +11 -14
  25. package/components/Form/Radios.svelte +27 -27
  26. package/components/Form/Select.svelte +48 -60
  27. package/components/Form/TextInput.svelte +13 -15
  28. package/components/Form/Textarea.svelte +13 -20
  29. package/components/Image/Figure.svelte +13 -0
  30. package/components/Image/Image-old.svelte +58 -0
  31. package/components/Image/Image.svelte +41 -0
  32. package/components/Image/Picture.svelte +71 -0
  33. package/components/Image/image.js +61 -0
  34. package/components/LocalStorage/LocalStoragePush.svelte +1 -2
  35. package/components/LocalStorage/LocalStorageRemove.svelte +1 -2
  36. package/components/Markdown/Markdown.svelte +1 -1
  37. package/components/Resizer/Resizer.svelte +24 -23
  38. package/components/SVG/SVG.svelte +23 -21
  39. package/components/SVG/SVGGradient.svelte +7 -5
  40. package/components/Scrambler/Scrambler.svelte +1 -2
  41. package/components/Status.svelte +1 -3
  42. package/components/Tabs/Tablist.svelte +7 -8
  43. package/components/Tabs/Tabpanels.svelte +5 -1
  44. package/components/Tabs/Tabs.svelte +2 -3
  45. package/components/Youtube.svelte +7 -10
  46. package/package.json +2 -1
  47. package/utils/index.js +1 -0
  48. package/utils/init.js +3 -0
  49. package/utils/loadscripts.js +2 -0
  50. package/vitest.config.js +8 -0
  51. package/components/Image.svelte +0 -24
@@ -1,31 +1,29 @@
1
1
  <script>
2
2
  import { delay } from '@splendidlabz/utils'
3
3
  import { onMount } from 'svelte'
4
+ import { init } from '../../../utils'
4
5
  import Icon from '../../Icon/Icon.svelte'
5
- let { show = $bindable(false), ref = $bindable(null), ...p } = $props()
6
6
 
7
- const {
7
+ let {
8
+ show = $bindable(false),
9
+ ref = $bindable(null),
8
10
  componentName = 'ModalTrigger',
9
11
  class: klass = '',
10
12
  icon = 'tabler:menu',
11
13
  iconClass,
12
-
13
- // Props
14
14
  target,
15
-
16
- // Slots
17
15
  children,
18
-
19
- // Event listeners
20
16
  onclick = null,
21
17
  ontoggle = null,
22
18
  ...rest
23
- } = p
19
+ } = $props()
24
20
 
25
21
  let dialog = $state(null)
26
22
 
27
- if (!target)
28
- throw new Error(`${componentName} must contain a target property`)
23
+ init(() => {
24
+ if (!target)
25
+ throw new Error(`${componentName} must contain a target property`)
26
+ })
29
27
 
30
28
  onMount(async _ => {
31
29
  await delay(0) // Gives time for modal to mount
@@ -1,18 +1,17 @@
1
1
  <script>
2
2
  import Icon from '../../Icon/Icon.svelte'
3
3
 
4
- let { ref = $bindable(null), ...p } = $props()
5
-
6
- const {
4
+ let {
5
+ ref = $bindable(null),
7
6
  class: klass = '',
8
7
  icon = 'tabler:x',
9
8
  iconClass = '',
10
9
  target = null,
11
10
  children,
12
11
  ...rest
13
- } = p
12
+ } = $props()
14
13
 
15
- const targetAction = target ? 'hide' : null
14
+ const targetAction = $derived(target ? 'hide' : null)
16
15
 
17
16
  function closeDrawer() {
18
17
  const popover =
@@ -1,7 +1,7 @@
1
1
  <script>
2
2
  import { splitObject } from '@splendidlabz/utils'
3
3
  import { checkForAccessibleName } from '@splendidlabz/utils/dom'
4
- import { mergeOpts } from '../../../utils/merge-opts.js'
4
+ import { init } from '../../../utils'
5
5
  import { getTrigger, passEventToTrigger } from '../shared.js'
6
6
  import { FLOATING_OPTS_KEYS, initFloating } from './floating.js'
7
7
 
@@ -10,42 +10,30 @@
10
10
  as = 'dialog',
11
11
  ref = $bindable(null),
12
12
  referenceNode = $bindable(null),
13
- ...p
14
- } = $props()
15
-
16
- p = mergeOpts(p)
17
-
18
- const {
19
13
  componentName = 'Popover',
20
14
  'aria-label': ariaLabel,
21
15
  'aria-labelledBy': ariaLabelledBy,
22
16
  'aria-describedby': ariaDescribedBy,
23
-
24
- // Props
25
17
  id,
26
- popover = 'auto', // manual, hint
27
-
28
- // Event listeners
18
+ popover = 'auto',
29
19
  onbeforetoggle = null,
30
20
  ontoggle = null,
31
21
  onopen = null,
32
22
  onclose = null,
33
-
34
- // Slots
35
23
  children,
36
24
  ...rest
37
- } = p
25
+ } = $props()
38
26
 
39
27
  // ========================
40
28
  // Checks
41
29
  // ========================
42
- if (!id) throw new Error(`${componentName} requires an id`)
43
-
44
- // Accessible name warning
45
- checkForAccessibleName({
46
- name: `${componentName} (id: ${id})`,
47
- ariaLabel,
48
- ariaLabelledBy,
30
+ init(() => {
31
+ if (!id) throw new Error(`${componentName} requires an id`)
32
+ checkForAccessibleName({
33
+ name: `${componentName} (id: ${id})`,
34
+ ariaLabel,
35
+ ariaLabelledBy,
36
+ })
49
37
  })
50
38
 
51
39
  // ========================================
@@ -54,7 +42,8 @@
54
42
  let trigger = null
55
43
  let floating = null
56
44
 
57
- const { picked: floatingOpts } = splitObject(rest, FLOATING_OPTS_KEYS)
45
+ const floatingSplit = $derived(splitObject(rest, FLOATING_OPTS_KEYS))
46
+ const floatingOpts = $derived(floatingSplit.picked)
58
47
 
59
48
  // ========================================
60
49
  // Event Listeners
@@ -1,35 +1,31 @@
1
1
  <script>
2
2
  import { delay } from '@splendidlabz/utils'
3
3
  import { onMount } from 'svelte'
4
+ import { init } from '../../../utils'
4
5
  import Icon from '../../Icon/Icon.svelte'
5
6
 
6
- let { show = $bindable(null), ref = $bindable(null), ...p } = $props()
7
-
8
- const {
7
+ let {
8
+ show = $bindable(null),
9
+ ref = $bindable(null),
9
10
  class: klass = '',
10
11
  componentName = 'PopoverTrigger',
11
12
  icon = 'tabler:menu',
12
13
  iconClass,
13
-
14
- // Props
15
14
  target,
16
- // actions, // Don't think I used this
17
-
18
- // Slots
19
15
  children,
20
-
21
- // Event listeners
22
16
  onclick = null,
23
17
  ontoggle = null,
24
18
  onopen = null,
25
19
  onclose = null,
26
20
  ...rest
27
- } = p
21
+ } = $props()
28
22
 
29
23
  let popover = $state(null)
30
24
 
31
- if (!target)
32
- throw new Error(`${componentName} must contain a target property`)
25
+ init(() => {
26
+ if (!target)
27
+ throw new Error(`${componentName} must contain a target property`)
28
+ })
33
29
 
34
30
  onMount(async _ => {
35
31
  await delay(0) // Gives time for popover to mount
@@ -14,21 +14,18 @@
14
14
  import Icon from '../Icon/Icon.svelte'
15
15
  import Markdown from '../Markdown/Markdown.svelte'
16
16
 
17
- const {
17
+ let {
18
18
  class: klass = '',
19
19
  sublistClass = '',
20
20
  icon = '',
21
21
  iconClass,
22
22
  emoji,
23
23
  emojiClass,
24
+ items: rawItems = [],
24
25
  ...rest
25
26
  } = $props()
26
27
 
27
- let { items: _items = [] } = rest
28
-
29
- const items = _items.map(item => {
30
- return createItemStructure(item)
31
- })
28
+ const items = $derived(rawItems.map(item => createItemStructure(item)))
32
29
 
33
30
  function createItemStructure(item) {
34
31
  if (typeof item === 'string')
@@ -3,40 +3,48 @@
3
3
  // - https://lea0.verou.me/2022/07/button-group/
4
4
  // - https://tink.uk/perceived-affordances-and-the-functionality-mismatch/
5
5
  //
6
- import { checkForAccessibleName } from '../../utils'
6
+ import { checkForAccessibleName, init } from '../../utils'
7
7
 
8
- let { items = $bindable([]), selected = $bindable(null), ...p } = $props()
9
- const { class: klass = '', direction = 'horizontal', ...rest } = p
8
+ let {
9
+ items = $bindable([]),
10
+ selected = $bindable(null),
11
+ class: klass = '',
12
+ direction = 'horizontal',
13
+ ...rest
14
+ } = $props()
10
15
 
11
16
  // Accessible name warning
12
- checkForAccessibleName('Button Group', rest)
17
+ init(() => checkForAccessibleName('Button Group', rest))
13
18
 
14
19
  // Create divider class if direction is provided.
15
- let dividerClass = $state('')
16
- if (!klass.includes('card-divided-')) {
17
- if (direction === 'horizontal') dividerClass = 'card-divided-horizontal'
18
- if (direction === 'vertical') dividerClass = 'card-divided-vertical'
19
- }
20
+ const dividerClass = $derived(
21
+ klass.includes('card-divided-')
22
+ ? ''
23
+ : direction === 'horizontal'
24
+ ? 'card-divided-horizontal'
25
+ : direction === 'vertical'
26
+ ? 'card-divided-vertical'
27
+ : '',
28
+ )
20
29
 
21
30
  // Normalize items
22
- let normalizedItems = $derived.by(() => {
23
- let _items = items.map(item => {
24
- const base = {
25
- pressed: false,
26
- onclick: handleClick,
31
+ const normalizedItems = $derived.by(() => {
32
+ const mapped = items.map(item => {
33
+ if (typeof item === 'string') {
34
+ return { value: item, pressed: false, onclick: handleClick }
27
35
  }
28
36
 
29
- if (typeof item === 'string') return { ...base, value: item }
30
37
  const { selected, onclick, ...rest } = item
31
- const pressed = selected ?? false
32
- return { ...base, ...rest, pressed, userClickEvent: onclick }
38
+ return {
39
+ onclick: handleClick,
40
+ ...rest,
41
+ pressed: selected ?? false,
42
+ userClickEvent: onclick,
43
+ }
33
44
  })
34
45
 
35
- if (!_items.find(item => item.pressed)) {
36
- _items[0].pressed = true
37
- }
38
-
39
- return _items
46
+ if (!mapped.some(item => item.pressed)) mapped[0].pressed = true
47
+ return mapped
40
48
  })
41
49
 
42
50
  function handleClick(event) {
@@ -1,45 +1,50 @@
1
1
  <script>
2
2
  import { toSentence } from '@splendidlabz/utils'
3
3
  import { randomString } from '@splendidlabz/utils/dom'
4
+ import { init } from '../../utils'
4
5
  import SVG from '../Icon/Icon.svelte'
5
6
  import TextInput from './TextInput.svelte'
6
7
 
7
8
  let {
8
- name = '',
9
- label = null,
10
- value = 'on',
9
+ name: nameProp = '',
10
+ label: labelProp = null,
11
+ value: valueProp = 'on',
11
12
  checked = $bindable(false),
12
13
  ref = $bindable(null),
13
- ...p
14
- } = $props()
15
-
16
- const {
17
14
  class: klass = '',
18
15
  icon = null,
19
16
  iconClass = null,
20
17
  fieldClass = '',
21
18
  labelClass = '',
22
-
23
19
  id = randomString(8),
24
- required = null,
25
20
  readonly = null,
26
21
  disabled = null,
27
22
  alwaysSend = false,
28
23
  hasInput = false,
29
24
  ...rest
30
- } = p
25
+ } = $props()
26
+
27
+ // Local mutable state initialized from props
28
+ let name = $state('')
29
+ let label = $state(null)
30
+ let value = $state('on')
31
+ let ov = $state('on')
31
32
 
32
- // Original value
33
- const ov = value
33
+ init(() => {
34
+ name = nameProp
35
+ label = labelProp
36
+ value = valueProp
37
+ ov = valueProp
34
38
 
35
- // Name and value are often confused for checkboxes. Value should be on, but user mistake value as name. If so, we swap it for them
36
- if (value !== 'on' && !name) name = value
39
+ // Name and value are often confused. Value should be 'on', but users mistake value as name — swap it for them
40
+ if (value !== 'on' && !name) name = value
37
41
 
38
- // Safety check
39
- if (!name) throw new Error('Checkbox requires a name')
42
+ // Safety check
43
+ if (!name) throw new Error('Checkbox requires a name')
40
44
 
41
- // Create label from name if not provided
42
- if (name && !label && label !== '') label = toSentence(name)
45
+ // Create label from name if not provided
46
+ if (name && !label && label !== '') label = toSentence(name)
47
+ })
43
48
 
44
49
  $effect(() => {
45
50
  // Sends the checked value upwards
@@ -1,60 +1,62 @@
1
1
  <script>
2
2
  import Checkbox from './Checkbox.svelte'
3
3
 
4
+ import { init } from '../../utils'
5
+
4
6
  let {
5
- legend = '',
6
- legendClass = '',
7
+ legend: legendProp = '',
8
+ legendClass: legendClassProp = '',
7
9
  label = '',
8
10
  labelClass = '',
9
11
  items = $bindable([]),
10
12
  checkboxes = $bindable([]),
11
13
  ref = $bindable(null),
12
14
  checked = false,
13
- ...p
14
- } = $props()
15
-
16
- // Let users use either items or checkboxes. Does this work?
17
- if (checkboxes.length) items = checkboxes
18
- if (!items.length && !checkboxes.length) {
19
- console.warn('No checkboxes or items provided to <Checkboxes />')
20
- }
21
-
22
- // Let users use either label or legend
23
- if (label) legend = label
24
- if (labelClass) legendClass = labelClass
25
-
26
- const {
27
15
  class: klass = '',
28
16
  checkboxesClass = '',
29
17
  disabled = null,
30
18
  readonly = null,
31
19
  alwaysSend = null,
32
20
  ...rest
33
- } = p
21
+ } = $props()
22
+
23
+ let legend = $state('')
24
+ let legendClass = $state('')
25
+
26
+ init(() => {
27
+ legend = legendProp
28
+ legendClass = legendClassProp
34
29
 
35
- const staticCheckboxProps = {
36
- disabled,
37
- readonly,
38
- alwaysSend,
39
- }
30
+ // Let users use either items or checkboxes
31
+ if (checkboxes.length) items = checkboxes
32
+ if (!items.length && !checkboxes.length) {
33
+ console.warn('No checkboxes or items provided to <Checkboxes />')
34
+ }
40
35
 
41
- items = items.map(checkbox => {
42
- if (typeof checkbox === 'string') checkbox = { name: checkbox }
43
- return { checked, ref: null, ...checkbox }
36
+ // Let users use either label or legend
37
+ if (label) legend = label
38
+ if (labelClass) legendClass = labelClass
39
+
40
+ items = items.map(checkbox => {
41
+ if (typeof checkbox === 'string') checkbox = { name: checkbox }
42
+ return { checked, ref: null, ...checkbox }
43
+ })
44
44
  })
45
45
 
46
+ const staticCheckboxProps = $derived({ disabled, readonly, alwaysSend })
47
+
46
48
  // TODO Later: Indeterminate checkboxes
47
49
  // Useful for groups of checkboxes.
48
50
  // inputInstance.indeterminate = true
49
51
  </script>
50
52
 
51
- <fieldset {...rest} class="fieldset {klass}" bind:this={ref}>
53
+ <fieldset {...rest} bind:this={ref} class="fieldset {klass}">
52
54
  {#if legend}
53
55
  <legend class="legend {legendClass}">{legend}</legend>
54
56
  {/if}
55
57
 
56
58
  <div class="checkboxes {checkboxesClass}">
57
- {#each items as checkbox}
59
+ {#each items as checkbox (checkbox.name)}
58
60
  <Checkbox
59
61
  {...staticCheckboxProps}
60
62
  {...checkbox}
@@ -3,22 +3,19 @@
3
3
  import { sanitize as sanitizeFn } from '@splendidlabz/utils/dom'
4
4
  import Honeypot from './Honeypot.svelte'
5
5
 
6
- let { ref = $bindable(null), ...p } = $props()
7
-
8
- const {
6
+ let {
7
+ ref = $bindable(null),
9
8
  class: klass = '',
10
9
  method = 'post',
11
10
  action = null,
12
-
13
11
  sanitize = true,
14
12
  preventSpam = true,
15
13
  honeypotName = 'hp',
16
14
  honeypotDuration = 2000,
17
-
18
15
  onsubmit = null,
19
16
  children,
20
17
  ...rest
21
- } = p
18
+ } = $props()
22
19
 
23
20
  let honeypotValue = $state('')
24
21
  let formStartTime = $state(Date.now())
@@ -1,42 +1,39 @@
1
1
  <script>
2
2
  import { toSentence } from '@splendidlabz/utils'
3
3
  import { randomString } from '@splendidlabz/utils/dom'
4
+ import { init } from '../../utils'
4
5
  import SVG from '../Icon/Icon.svelte'
5
6
  import TextInput from './TextInput.svelte'
6
7
 
7
8
  let {
8
- label = null,
9
+ label: labelProp = null,
9
10
  group = $bindable(null),
10
11
  ref = $bindable(null),
11
12
  checked = $bindable(false),
12
- ...p
13
- } = $props()
14
-
15
- const {
16
13
  class: klass = '',
17
14
  icon = null,
18
15
  iconClass = null,
19
16
  fieldClass = '',
20
17
  labelClass = '',
21
-
22
18
  id = randomString(8),
23
19
  name,
24
20
  value = null,
25
21
  readonly = null,
26
22
  disabled = null,
27
23
  hasInput = false,
28
-
29
- // Event listeners
30
24
  onchange = null,
31
-
32
25
  ...rest
33
- } = p
26
+ } = $props()
34
27
 
35
- if (!name) throw new Error('Radio requires a name')
36
- if (!value) throw new Error('Radio requires a value')
28
+ let label = $state(null)
37
29
 
38
- // Create label if not provided
39
- if (!label && label !== '') label = toSentence(value)
30
+ init(() => {
31
+ label = labelProp
32
+ if (!name) throw new Error('Radio requires a name')
33
+ if (!value) throw new Error('Radio requires a value')
34
+ // Create label if not provided
35
+ if (!label && label !== '') label = toSentence(value)
36
+ })
40
37
 
41
38
  // Sends the checked value upwards
42
39
  function handleChange(event) {
@@ -1,29 +1,16 @@
1
1
  <script>
2
+ import { init } from '../../utils'
2
3
  import Radio from './Radio.svelte'
3
4
 
4
5
  let {
5
- legend = '',
6
- legendClass = '',
6
+ legend: legendProp = '',
7
+ legendClass: legendClassProp = '',
7
8
  label = '',
8
9
  labelClass = '',
9
10
  items = $bindable([]),
10
11
  radios = $bindable([]),
11
12
  ref = $bindable(null),
12
13
  checked = $bindable(null),
13
- ...p
14
- } = $props()
15
-
16
- // Let users use either items or radios
17
- if (radios.length) items = radios
18
- if (!items.length && !radios.length) {
19
- console.warn('No radios or items provided to <Radios />')
20
- }
21
-
22
- // Let users use either label or legend
23
- if (label) legend = label
24
- if (labelClass) legendClass = labelClass
25
-
26
- const {
27
14
  class: klass = '',
28
15
  radiosClass = '',
29
16
  icon,
@@ -32,21 +19,34 @@
32
19
  disabled = null,
33
20
  readonly = null,
34
21
  ...rest
35
- } = p
22
+ } = $props()
36
23
 
37
- const radioProps = {
38
- icon,
39
- iconClass,
40
- disabled,
41
- readonly,
42
- }
24
+ let legend = $state('')
25
+ let legendClass = $state('')
26
+
27
+ init(() => {
28
+ legend = legendProp
29
+ legendClass = legendClassProp
30
+
31
+ // Let users use either items or radios
32
+ if (radios.length) items = radios
33
+ if (!items.length && !radios.length) {
34
+ console.warn('No radios or items provided to <Radios />')
35
+ }
36
+
37
+ // Let users use either label or legend
38
+ if (label) legend = label
39
+ if (labelClass) legendClass = labelClass
40
+
41
+ items = items.map(radio => {
42
+ if (typeof radio === 'string') radio = { value: radio }
43
+ return { ref: null, ...radio }
44
+ })
43
45
 
44
- items = items.map(radio => {
45
- if (typeof radio === 'string') radio = { value: radio }
46
- return { ref: null, ...radio }
46
+ checked = items.find(radio => radio.checked)?.value
47
47
  })
48
48
 
49
- checked = items.find(radio => radio.checked)?.value
49
+ const radioProps = $derived({ icon, iconClass, disabled, readonly })
50
50
  </script>
51
51
 
52
52
  <fieldset {...rest} bind:this={ref} class="fieldset {klass}">