@splendidlabz/svelte 0.4.0
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/.eslintrc.cjs +3 -0
- package/CHANGELOG.md +91 -0
- package/actions/breakpoint-observer.js +71 -0
- package/actions/index.js +6 -0
- package/actions/portal.js +20 -0
- package/actions/resize-observer.js +43 -0
- package/actions/scroll-observer.js +47 -0
- package/common.js +21 -0
- package/components/Accordion/Accordion.svelte +108 -0
- package/components/Accordion/index.js +3 -0
- package/components/Breadcrumbs/Breadcrumbs.svelte +69 -0
- package/components/Breadcrumbs/Crumb.svelte +37 -0
- package/components/Breadcrumbs/CrumbCustom.svelte +14 -0
- package/components/Breadcrumbs/index.js +5 -0
- package/components/BrowserFrame.svelte +37 -0
- package/components/BrowserWithTabs.svelte +28 -0
- package/components/CQChecker/CQChecker.astro +20 -0
- package/components/CQChecker/CQChecker.svelte +89 -0
- package/components/Callout/Callout.svelte +17 -0
- package/components/Callout/index.js +3 -0
- package/components/Codepen/Codepen.astro +29 -0
- package/components/Codepen/Codepen.svelte +24 -0
- package/components/Codepen/index.js +3 -0
- package/components/ContentList/ContentList-old.svelte +117 -0
- package/components/ContentList/ContentList.svelte +68 -0
- package/components/ContentList/index.js +3 -0
- package/components/Disclosure/Drawer/Drawer.svelte +35 -0
- package/components/Disclosure/Drawer/DrawerCloseButton.svelte +31 -0
- package/components/Disclosure/Drawer/DrawerContent-wrecked.svelte +198 -0
- package/components/Disclosure/Drawer/DrawerContent.svelte +164 -0
- package/components/Disclosure/Drawer/DrawerTrigger.svelte +32 -0
- package/components/Disclosure/Drawer/drawer.js +112 -0
- package/components/Disclosure/Drawer/index.js +6 -0
- package/components/Disclosure/Dropdown/DropdownContent.svelte +15 -0
- package/components/Disclosure/Dropdown/DropdownTrigger.svelte +14 -0
- package/components/Disclosure/Dropdown/dropdown.js +4 -0
- package/components/Disclosure/Dropdown/index.js +4 -0
- package/components/Disclosure/Modal/ModalContent.svelte +3 -0
- package/components/Disclosure/Modal/ModalTrigger.svelte +33 -0
- package/components/Disclosure/Modal/exit-intent.js +17 -0
- package/components/Disclosure/Modal/modal.js +13 -0
- package/components/Disclosure/Popover/PopoverCloseButton.svelte +29 -0
- package/components/Disclosure/Popover/PopoverContent.svelte +107 -0
- package/components/Disclosure/Popover/PopoverTrigger.svelte +33 -0
- package/components/Disclosure/Popover/floating.js +171 -0
- package/components/Disclosure/Popover/index.js +5 -0
- package/components/Disclosure/Popover/popover.js +18 -0
- package/components/Disclosure/Popover/references/FollowTheMouse.svelte +45 -0
- package/components/Disclosure/Tooltip/Tooltip.svelte +14 -0
- package/components/Disclosure/Tooltip/TooltipContent.svelte +7 -0
- package/components/Disclosure/Tooltip/TooltipTrigger.svelte +33 -0
- package/components/Disclosure/Tooltip/index.js +5 -0
- package/components/Disclosure/Tooltip/tooltip.js +22 -0
- package/components/Disclosure/disclosure-store.js +48 -0
- package/components/Disclosure/disclosure.js +439 -0
- package/components/Disclosure/index.js +3 -0
- package/components/Disclosure/state.svelte.js +138 -0
- package/components/FancyList/FancyList.svelte +49 -0
- package/components/FancyList/index.js +3 -0
- package/components/Form/Button.svelte +24 -0
- package/components/Form/Checkbox.svelte +80 -0
- package/components/Form/Checkboxes.svelte +48 -0
- package/components/Form/Combobox/AutocompleteInput.svelte +63 -0
- package/components/Form/Combobox/AutocompleteOptions.svelte +74 -0
- package/components/Form/Combobox/TimepickerInput.svelte +81 -0
- package/components/Form/Combobox/TimepickerOptions.svelte +100 -0
- package/components/Form/Combobox/autocomplete-matching.js +114 -0
- package/components/Form/Combobox/autocomplete.js +393 -0
- package/components/Form/Combobox/combobox-store.js +65 -0
- package/components/Form/Combobox/combobox.js +359 -0
- package/components/Form/Combobox/index.js +14 -0
- package/components/Form/Combobox/timepicker.js +119 -0
- package/components/Form/Form.svelte +62 -0
- package/components/Form/Hidden.svelte +16 -0
- package/components/Form/Radio.svelte +69 -0
- package/components/Form/Radios.svelte +50 -0
- package/components/Form/Select.svelte +127 -0
- package/components/Form/Switch.svelte +50 -0
- package/components/Form/TextInput.svelte +87 -0
- package/components/Form/Textarea.svelte +103 -0
- package/components/Form/check.svg +3 -0
- package/components/Form/index.js +12 -0
- package/components/Highlight/Highlight.svelte +27 -0
- package/components/Highlight/_Highlight.scss +19 -0
- package/components/Highlight/index.js +2 -0
- package/components/Image.svelte +24 -0
- package/components/InteractiveRegion/InteractiveRegion.svelte +47 -0
- package/components/InteractiveRegion/index.js +3 -0
- package/components/List/Lia.svelte +12 -0
- package/components/List/NestedListItem.svelte +50 -0
- package/components/List/index.js +3 -0
- package/components/Markdown/Markdown.svelte +35 -0
- package/components/Masonry/Masonry.svelte +79 -0
- package/components/Masonry/index.js +3 -0
- package/components/PerspectiveHover/PerspectiveHover.svelte +10 -0
- package/components/PerspectiveHover/perspective-hover.js +46 -0
- package/components/Populate/ConditionalPopulate.svelte +33 -0
- package/components/Populate/Populate.svelte +45 -0
- package/components/Populate/actions.js +29 -0
- package/components/Populate/get-value.js +17 -0
- package/components/Populate/index.js +4 -0
- package/components/Portal.svelte +27 -0
- package/components/PushToLocalStorage.svelte +30 -0
- package/components/Resizer/Resizer.svelte +32 -0
- package/components/Resizer/draggable.js +23 -0
- package/components/Resizer/index.js +3 -0
- package/components/Resizer/resizer.js +133 -0
- package/components/SVG/SVG.svelte +120 -0
- package/components/Scrambler/Scrambler.svelte +27 -0
- package/components/Scrambler/index.js +3 -0
- package/components/Spotlight/PointerPosition.js +32 -0
- package/components/Spotlight/Spotlight.svelte +9 -0
- package/components/Status.svelte +27 -0
- package/components/Switcheroo/Switcheroo.svelte +71 -0
- package/components/Switcheroo/index.js +3 -0
- package/components/Table/RowGroup.svelte +8 -0
- package/components/Table/Table.svelte +23 -0
- package/components/Table/Td.svelte +20 -0
- package/components/Table/Th.svelte +27 -0
- package/components/Table/Thead.svelte +8 -0
- package/components/Table/Tr.svelte +8 -0
- package/components/Table/index.js +17 -0
- package/components/Table/table.js +35 -0
- package/components/Tabs/Tab.svelte +12 -0
- package/components/Tabs/Tablist.svelte +62 -0
- package/components/Tabs/Tabpanel.svelte +10 -0
- package/components/Tabs/Tabpanels.svelte +12 -0
- package/components/Tabs/index.js +6 -0
- package/components/Tabs/tab-store.js +60 -0
- package/components/Tabs/tabs.js +364 -0
- package/components/Tabs-Old/Tab.svelte +9 -0
- package/components/Tabs-Old/Tablist.svelte +13 -0
- package/components/Tabs-Old/Tabpanel.svelte +10 -0
- package/components/Tabs-Old/Tabpanels.svelte +14 -0
- package/components/Tabs-Old/Tabs.svelte +83 -0
- package/components/Tabs-Old/index.js +7 -0
- package/components/Tabs-Old/tabs.js +306 -0
- package/components/Textwall/Repeat.svelte +10 -0
- package/components/Textwall/Textwall.svelte +30 -0
- package/components/Textwall/index.js +4 -0
- package/components/Typewriter/Typewriter.svelte +70 -0
- package/components/Typewriter/index.js +3 -0
- package/components/Video.svelte +46 -0
- package/components/Vimeo.svelte +18 -0
- package/components/Wrapper.svelte +22 -0
- package/components/Youtube.svelte +15 -0
- package/components/_shared/accessibility.js +9 -0
- package/components/_shared/key.js +1 -0
- package/components/_shared/transitions.js +48 -0
- package/components/_shared/use-actions.js +31 -0
- package/index.js +35 -0
- package/jsconfig.json +5 -0
- package/package.json +39 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import {
|
|
2
|
+
arrow,
|
|
3
|
+
autoUpdate,
|
|
4
|
+
computePosition,
|
|
5
|
+
flip,
|
|
6
|
+
offset,
|
|
7
|
+
shift,
|
|
8
|
+
} from '@floating-ui/dom'
|
|
9
|
+
import { mix, splitUnit } from '@splendidlabz/utils'
|
|
10
|
+
import { em, rem } from '@splendidlabz/utils/dom'
|
|
11
|
+
|
|
12
|
+
// TODO: Add inline for tooltips
|
|
13
|
+
export const DEFAULT_FLOATING_CONTENT_OPTS = {
|
|
14
|
+
placement: 'top',
|
|
15
|
+
strategy: 'absolute',
|
|
16
|
+
offset: '0.5rem',
|
|
17
|
+
arrow: false,
|
|
18
|
+
arrowWidth: '0.6rem',
|
|
19
|
+
arrowDelta: 0,
|
|
20
|
+
inline: false,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const FLOATING_CONTENT_OPT_KEYS = Object.keys(
|
|
24
|
+
DEFAULT_FLOATING_CONTENT_OPTS,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
export function floatingContent(node, options) {
|
|
28
|
+
const floatingNode = node
|
|
29
|
+
const referenceNode = document.querySelector(`[target="${node.id}"]`)
|
|
30
|
+
let arrowNode
|
|
31
|
+
|
|
32
|
+
options = mix(DEFAULT_FLOATING_CONTENT_OPTS, options)
|
|
33
|
+
|
|
34
|
+
if (options.arrow) {
|
|
35
|
+
arrowNode = node.querySelector('.PopoverArrow')
|
|
36
|
+
arrowNode.style.width = calculateArrowWidth(options.arrowWidth) + 'px'
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const offsetValue = calculateOffsetValue({ ...options, arrowNode })
|
|
40
|
+
|
|
41
|
+
options.middleware = [
|
|
42
|
+
offset(offsetValue),
|
|
43
|
+
// options.middleware.push(inline()), // Should be placed here. Padding option might be useful.
|
|
44
|
+
flip({ fallbackAxisSideDirection: 'start' }),
|
|
45
|
+
shift(),
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
if (options.arrow) {
|
|
49
|
+
options.middleware.push(arrow({ element: arrowNode }))
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
autoUpdate(referenceNode, floatingNode, () => {
|
|
53
|
+
computePosition(referenceNode, floatingNode, options).then(
|
|
54
|
+
middlewareState => {
|
|
55
|
+
const { x, y } = middlewareState
|
|
56
|
+
// Position Popover
|
|
57
|
+
Object.assign(floatingNode.style, {
|
|
58
|
+
left: `${x}px`,
|
|
59
|
+
top: `${y}px`,
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
if (options.arrow) {
|
|
63
|
+
const arrowPosStyle = calculateArrowPosition({
|
|
64
|
+
middlewareState,
|
|
65
|
+
floatingNode,
|
|
66
|
+
arrowNode,
|
|
67
|
+
arrowDelta: options.arrowDelta,
|
|
68
|
+
})
|
|
69
|
+
Object.assign(arrowNode.style, arrowPosStyle)
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
)
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function calculateOffsetValue({ offset, arrow, arrowNode }) {
|
|
77
|
+
// SSR Ready
|
|
78
|
+
if (typeof window === 'undefined') return
|
|
79
|
+
if (!offset) offset = 0
|
|
80
|
+
|
|
81
|
+
const [value, unit] = splitUnit(offset)
|
|
82
|
+
|
|
83
|
+
let finalValue = 0
|
|
84
|
+
|
|
85
|
+
if (unit === 'rem') finalValue = value * rem()
|
|
86
|
+
if (unit === 'em') finalValue = value * em()
|
|
87
|
+
if (unit === 'px') finalValue = value
|
|
88
|
+
if (!unit) finalValue = value // Default to px offsets
|
|
89
|
+
|
|
90
|
+
if (!arrow) return finalValue
|
|
91
|
+
|
|
92
|
+
// Arrow Offset compensation
|
|
93
|
+
const arrowWidth = arrowNode.offsetWidth
|
|
94
|
+
const half = arrowWidth / 2
|
|
95
|
+
const arrowOffsetCompensation = Math.floor(Math.sqrt(half * half * 2))
|
|
96
|
+
|
|
97
|
+
return finalValue + arrowOffsetCompensation
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function calculateArrowWidth(givenWidth) {
|
|
101
|
+
const remValue = rem()
|
|
102
|
+
const [value, unit] = splitUnit(givenWidth)
|
|
103
|
+
let finalValue = 0
|
|
104
|
+
|
|
105
|
+
if (unit === 'rem') finalValue = value * remValue
|
|
106
|
+
if (unit === 'px') finalValue = value
|
|
107
|
+
if (!unit) finalValue = value // Default to px offsets
|
|
108
|
+
|
|
109
|
+
return finalValue
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function calculateArrowPosition({
|
|
113
|
+
middlewareState,
|
|
114
|
+
floatingNode,
|
|
115
|
+
arrowNode,
|
|
116
|
+
arrowDelta,
|
|
117
|
+
}) {
|
|
118
|
+
const { placement, middlewareData } = middlewareState
|
|
119
|
+
|
|
120
|
+
let x = middlewareData.arrow?.x
|
|
121
|
+
let y = middlewareData.arrow?.y
|
|
122
|
+
|
|
123
|
+
const staticSide = {
|
|
124
|
+
top: 'bottom',
|
|
125
|
+
right: 'left',
|
|
126
|
+
bottom: 'top',
|
|
127
|
+
left: 'right',
|
|
128
|
+
}[placement.split('-')[0]]
|
|
129
|
+
|
|
130
|
+
// Calculates arrow direction
|
|
131
|
+
let rotate = 45
|
|
132
|
+
// prettier-ignore
|
|
133
|
+
switch (staticSide) {
|
|
134
|
+
case 'top': rotate = 45; break;
|
|
135
|
+
case 'right': rotate = 135; break;
|
|
136
|
+
case 'bottom': rotate = 225; break;
|
|
137
|
+
case 'left': rotate = 315; break;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Calculates maximum X and Y on cross-axis
|
|
141
|
+
const { width, height } = floatingNode.getBoundingClientRect()
|
|
142
|
+
const borderRadius = parseFloat(getComputedStyle(floatingNode).borderRadius)
|
|
143
|
+
const borderWidth = parseFloat(getComputedStyle(floatingNode).borderWidth)
|
|
144
|
+
const arrowWidth = arrowNode.offsetWidth
|
|
145
|
+
|
|
146
|
+
if (x || x === 0) {
|
|
147
|
+
const startEdge = borderRadius
|
|
148
|
+
const endEdge = width - borderRadius - arrowWidth
|
|
149
|
+
|
|
150
|
+
if (x <= startEdge) x = startEdge
|
|
151
|
+
if (x >= endEdge) x = endEdge
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (y || y === 0) {
|
|
155
|
+
const startEdge = borderRadius
|
|
156
|
+
const endEdge = height - borderRadius - arrowWidth
|
|
157
|
+
|
|
158
|
+
if (y <= startEdge) y = startEdge
|
|
159
|
+
if (y >= endEdge) y = endEdge
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Centers the arrow on the static side
|
|
163
|
+
const staticSideOffset = Math.round((arrowNode.offsetWidth + borderWidth) / 2)
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
left: x != null ? `${x}px` : '',
|
|
167
|
+
top: y != null ? `${y}px` : '',
|
|
168
|
+
[staticSide]: `-${staticSideOffset + arrowDelta}px`,
|
|
169
|
+
transform: `rotate(${rotate}deg)`,
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const DEFAULT_POPOVER_TRIGGER_OPTS = {
|
|
2
|
+
closeOthers: true,
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export const DEFAULT_POPOVER_CONTENT_OPTS = {
|
|
6
|
+
disclosure: {
|
|
7
|
+
focusTarget: 'content',
|
|
8
|
+
},
|
|
9
|
+
popover: {
|
|
10
|
+
portal: true,
|
|
11
|
+
},
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const DEFAULT_POPOVER_TRANSITION_OPTS = {
|
|
15
|
+
delay: 0,
|
|
16
|
+
duration: 250,
|
|
17
|
+
easing: 'cubicOut',
|
|
18
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<!-- <script lang="ts">
|
|
2
|
+
import type {
|
|
3
|
+
ClientRectObject,
|
|
4
|
+
VirtualElement,
|
|
5
|
+
} from 'svelte-floating-ui/core'
|
|
6
|
+
import { createFloatingActions } from 'svelte-floating-ui'
|
|
7
|
+
import { writable } from 'svelte/store'
|
|
8
|
+
|
|
9
|
+
const [floatingRef, floatingContent] = createFloatingActions({
|
|
10
|
+
strategy: 'fixed', //or absolute
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
let x = 0
|
|
14
|
+
let y = 0
|
|
15
|
+
|
|
16
|
+
const mousemove = (ev: MouseEvent) => {
|
|
17
|
+
x = ev.clientX
|
|
18
|
+
y = ev.clientY
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
$: getBoundingClientRect = (): ClientRectObject => {
|
|
22
|
+
return {
|
|
23
|
+
x,
|
|
24
|
+
y,
|
|
25
|
+
top: y,
|
|
26
|
+
left: x,
|
|
27
|
+
bottom: y,
|
|
28
|
+
right: x,
|
|
29
|
+
width: 0,
|
|
30
|
+
height: 0,
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const virtualElement = writable<VirtualElement>({ getBoundingClientRect })
|
|
35
|
+
|
|
36
|
+
$: virtualElement.set({ getBoundingClientRect })
|
|
37
|
+
|
|
38
|
+
floatingRef(virtualElement)
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<svelte:window on:mousemove={mousemove} />
|
|
42
|
+
|
|
43
|
+
<main>
|
|
44
|
+
<h2 use:floatingContent>Magic</h2>
|
|
45
|
+
</main> -->
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!-- NOT DONE YET -->
|
|
2
|
+
<!-- https://zoebijl.github.io/apg-tooltip/ -->
|
|
3
|
+
<script>
|
|
4
|
+
import { randomString } from '@splendidlabz/utils/dom'
|
|
5
|
+
import TooltipContent from './TooltipContent.svelte'
|
|
6
|
+
import TooltipTrigger from './TooltipTrigger.svelte'
|
|
7
|
+
|
|
8
|
+
export let content
|
|
9
|
+
|
|
10
|
+
const id = randomString()
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<TooltipTrigger target={id} />
|
|
14
|
+
<TooltipContent {id}>{content}</TooltipContent>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<!-- NOT DONE YET -->
|
|
2
|
+
|
|
3
|
+
<script>
|
|
4
|
+
import { disclosures, initDisclosure } from '../disclosure-store.js'
|
|
5
|
+
import { disclosureTrigger } from '../disclosure.js'
|
|
6
|
+
import { defaultTooltipTriggerOpts } from './tooltip.js'
|
|
7
|
+
|
|
8
|
+
// let klass
|
|
9
|
+
// export { klass as class }
|
|
10
|
+
export let elem = 'span'
|
|
11
|
+
export let target = null
|
|
12
|
+
export let show = false
|
|
13
|
+
export let options = {}
|
|
14
|
+
|
|
15
|
+
const opts = {
|
|
16
|
+
...defaultTooltipTriggerOpts,
|
|
17
|
+
...options,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
initDisclosure(target, opts, { show })
|
|
21
|
+
$: d = $disclosures.find(d => d.id === target)
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<svelte:element
|
|
25
|
+
this={elem}
|
|
26
|
+
inert
|
|
27
|
+
role="tooltip"
|
|
28
|
+
bind:this={d.nodes.triggerNode}
|
|
29
|
+
use:disclosureTrigger
|
|
30
|
+
{...$$restProps}
|
|
31
|
+
>
|
|
32
|
+
<slot />
|
|
33
|
+
</svelte:element>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const defaultTooltipTriggerOpts = {
|
|
2
|
+
showOnHover: true,
|
|
3
|
+
showOnFocus: true,
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export const defaultTooltipContentOpts = {
|
|
7
|
+
closeOnOutsideClick: true,
|
|
8
|
+
closeOnEscapeButton: true,
|
|
9
|
+
preventBodyScroll: false,
|
|
10
|
+
trapFocus: false,
|
|
11
|
+
focusTarget: null, // || 'first',
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const defaultTooltipFloatingOpts = {
|
|
15
|
+
placement: 'top',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const defaultTransitionOpts = {
|
|
19
|
+
delay: 0,
|
|
20
|
+
duration: 250,
|
|
21
|
+
easing: 'cubicOut',
|
|
22
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { get, writable } from 'svelte/store'
|
|
2
|
+
|
|
3
|
+
import { omitEmpty } from '@splendidlabz/utils'
|
|
4
|
+
|
|
5
|
+
export const disclosures = writable([])
|
|
6
|
+
const { update } = disclosures
|
|
7
|
+
|
|
8
|
+
export function getDisclosures() {
|
|
9
|
+
return get(disclosures)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getDisclosure(id) {
|
|
13
|
+
return get(disclosures).find(disclosure => disclosure.id === id)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function addDisclosure({ id, state = {}, nodes = {}, options = {} }) {
|
|
17
|
+
update(ds => {
|
|
18
|
+
const d = { id, state, options, nodes }
|
|
19
|
+
return [...ds, d]
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function updateDisclosure({ id, state = {}, options = {}, nodes = {} }) {
|
|
24
|
+
update(disclosures => {
|
|
25
|
+
const index = disclosures.findIndex(d => d.id === id)
|
|
26
|
+
const d = disclosures[index]
|
|
27
|
+
|
|
28
|
+
d.state = { ...d.state, ...omitEmpty(state) }
|
|
29
|
+
d.options = { ...d.options, ...omitEmpty(options) }
|
|
30
|
+
d.nodes = { ...d.nodes, ...omitEmpty(nodes, { shallow: true }) }
|
|
31
|
+
|
|
32
|
+
return disclosures.with(index, d)
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function initDisclosure({ id, options = {}, state = {}, nodes = {} }) {
|
|
37
|
+
const d = getDisclosure(id)
|
|
38
|
+
|
|
39
|
+
if (!d) {
|
|
40
|
+
addDisclosure({ id, options, state, nodes })
|
|
41
|
+
} else {
|
|
42
|
+
updateDisclosure({ id, options, state, nodes })
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return getDisclosure(id)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Might need to add remove disclosure for cleanup
|