nitro-web 0.3.2 → 0.3.3
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/client/index.ts +6 -2
- package/client/use-fetch.ts +164 -0
- package/components/auth/auth.api.js +10 -1
- package/components/partials/element/content-wrapper.tsx +52 -0
- package/components/partials/element/form-modal.tsx +154 -0
- package/components/partials/element/pagination.tsx +61 -0
- package/components/partials/element/sidebar.tsx +30 -27
- package/components/partials/element/tooltip.tsx +157 -145
- package/package.json +1 -1
- package/server/email/invite-user.html +2 -2
- package/tsconfig.json +0 -1
- package/types/components/auth/auth.api.d.ts +6 -0
- package/types/components/auth/auth.api.d.ts.map +1 -1
- package/types/globals.d.ts +3 -0
- package/types/util.d.ts +24 -20
- package/types/util.d.ts.map +1 -1
- package/types.ts +14 -0
- package/util.js +45 -16
package/client/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ export * from '../types'
|
|
|
12
12
|
// Main app functions
|
|
13
13
|
export { setupApp, updateJwt, middleware } from './app'
|
|
14
14
|
export { createStore, exposedStoreData, preloadedStoreData, setStoreWrapper, getSignoutStore, getInitialStore } from './store'
|
|
15
|
+
export { useFetchDoc, useFetchCol, useFetchSharedCol, clearCache } from './use-fetch'
|
|
15
16
|
|
|
16
17
|
// Component Pages
|
|
17
18
|
export { Signin } from '../components/auth/signin'
|
|
@@ -27,16 +28,19 @@ export { Accordion } from '../components/partials/element/accordion'
|
|
|
27
28
|
export { Avatar } from '../components/partials/element/avatar'
|
|
28
29
|
export { Button, Spinner } from '../components/partials/element/button'
|
|
29
30
|
export { Calendar, type CalendarProps } from '../components/partials/element/calendar'
|
|
31
|
+
export { ContentWrapper, ErrorBanner, LoadingBanner } from '../components/partials/element/content-wrapper'
|
|
30
32
|
export { Dropdown, type DropdownProps, type DropdownOption } from '../components/partials/element/dropdown'
|
|
31
33
|
export { Filters, type FilterType, usePushChangesToPath } from '../components/partials/element/filters'
|
|
34
|
+
export { FormModal, ConfirmModal } from '../components/partials/element/form-modal'
|
|
32
35
|
export { GithubLink } from '../components/partials/element/github-link'
|
|
33
36
|
export { ImageDrop } from '../components/partials/element/image-drop'
|
|
34
37
|
export { Initials, getColorByLetter } from '../components/partials/element/initials'
|
|
35
38
|
export { Message, type MessageIcons } from '../components/partials/element/message'
|
|
36
39
|
export { Modal } from '../components/partials/element/modal'
|
|
37
|
-
export {
|
|
40
|
+
export { Pagination, type PaginationProps } from '../components/partials/element/pagination'
|
|
41
|
+
export { Sidebar, getIsActive, type SidebarProps } from '../components/partials/element/sidebar'
|
|
38
42
|
export { TimePicker, type TimePickerProps } from '../components/partials/element/timepicker'
|
|
39
|
-
export { Tooltip } from '../components/partials/element/tooltip'
|
|
43
|
+
export { Tooltip, type TooltipProps } from '../components/partials/element/tooltip'
|
|
40
44
|
export { Topbar } from '../components/partials/element/topbar'
|
|
41
45
|
export { Table, type TableColumn, type TableProps, type TableRow, type TableRowType } from '../components/partials/element/table'
|
|
42
46
|
export { LoadingWithDots, LoadingOverlay } from '../components/partials/element/loading'
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// Generally we avoid using external hooks inline with FP principles, except in rare cases
|
|
2
|
+
import { useState, useEffect, Dispatch, SetStateAction } from 'react'
|
|
3
|
+
import { request, showError, getResponseErrors, setTimeoutPromise } from 'nitro-web/util'
|
|
4
|
+
import { Errors, SharedCollection } from 'nitro-web/types'
|
|
5
|
+
import { injectedConfig } from 'nitro-web'
|
|
6
|
+
|
|
7
|
+
// Cache duration in milliseconds (5 minutes)
|
|
8
|
+
const CACHE_DURATION = 5 * 60 * 1000
|
|
9
|
+
const delay = () => injectedConfig.env === 'development' ? 0 : 0 // read lazily to avoid circular dependency
|
|
10
|
+
const delaySharedCollection = () => injectedConfig.env === 'development' ? 0 : 0 // read lazily to avoid circular dependency
|
|
11
|
+
|
|
12
|
+
// Typed from the project's useTracked global, i.e. the project's Store
|
|
13
|
+
type Store = ReturnType<typeof useTracked>[0]
|
|
14
|
+
type SharedCollections = NonNullable<Store['sharedCollections']>
|
|
15
|
+
type Col = SharedCollection<{ _id?: string }>
|
|
16
|
+
const emptyCol: Col = { rows: [], total: 0 }
|
|
17
|
+
type GetSharedCollectionFn = (prev: Col) => Col
|
|
18
|
+
|
|
19
|
+
type CollectionReturn<T> = {
|
|
20
|
+
rows: T[],
|
|
21
|
+
total: number,
|
|
22
|
+
errors?: Errors,
|
|
23
|
+
isLoading: boolean,
|
|
24
|
+
refetch: () => void,
|
|
25
|
+
setRows: React.Dispatch<React.SetStateAction<T[]>>
|
|
26
|
+
}
|
|
27
|
+
type DocumentReturn<T> = {
|
|
28
|
+
data?: T,
|
|
29
|
+
errors?: Errors,
|
|
30
|
+
isLoading: boolean,
|
|
31
|
+
refetch: () => void,
|
|
32
|
+
setData: React.Dispatch<React.SetStateAction<T>>
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Fetches a document */
|
|
36
|
+
export function useFetchDoc<T>(endpoint?: string, queryString?: string) {
|
|
37
|
+
return useFetchResource<T>(endpoint, queryString || '', true) as DocumentReturn<T>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Fetches a collection */
|
|
41
|
+
export function useFetchCol<T>(endpoint?: string, queryString?: string) {
|
|
42
|
+
return useFetchResource<T>(endpoint, queryString) as CollectionReturn<T>
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Fetches a shared collection (e.g. options), which is cached on the store */
|
|
46
|
+
export function useFetchSharedCol<K extends keyof SharedCollections>(endpoint: string | undefined, collectionKey: K) {
|
|
47
|
+
const [{ sharedCollections }, setStore] = useTracked()
|
|
48
|
+
const { rows: rows2, total, errors, isLoading, lastFetched = 0 } = (sharedCollections?.[collectionKey] ?? emptyCol) as Col
|
|
49
|
+
const [refreshCount, setRefreshCount] = useState(0)
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
let mounted = true
|
|
53
|
+
|
|
54
|
+
;(async function () {
|
|
55
|
+
try {
|
|
56
|
+
const cacheFresh = Date.now() - lastFetched < CACHE_DURATION
|
|
57
|
+
if (!endpoint || isLoading || (refreshCount === 0 && cacheFresh)) return
|
|
58
|
+
setResource((prev) => ({ ...prev, isLoading: true, errors: [] }))
|
|
59
|
+
const { rows, total } = await request(`get /api${endpoint}`)
|
|
60
|
+
if (delaySharedCollection()) await setTimeoutPromise(() => {}, delaySharedCollection())
|
|
61
|
+
if (!mounted) return
|
|
62
|
+
setResource((prev) => ({ ...prev, rows: rows, total: total, isLoading: false, lastFetched: Date.now(), errors: [] }))
|
|
63
|
+
} catch (error) {
|
|
64
|
+
if (!mounted) return
|
|
65
|
+
showError(setStore, error)
|
|
66
|
+
setResource((prev) => ({ ...prev, isLoading: false, lastFetched: Date.now(), errors: getResponseErrors(error) }))
|
|
67
|
+
}
|
|
68
|
+
})()
|
|
69
|
+
|
|
70
|
+
return () => {
|
|
71
|
+
mounted = false
|
|
72
|
+
}
|
|
73
|
+
}, [refreshCount, collectionKey, endpoint])
|
|
74
|
+
|
|
75
|
+
function refetch() {
|
|
76
|
+
setRefreshCount(prev => prev + 1)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function setResource(getSharedCollectionFn: GetSharedCollectionFn) {
|
|
80
|
+
setStore((prev) => ({
|
|
81
|
+
...prev,
|
|
82
|
+
sharedCollections: {
|
|
83
|
+
...prev.sharedCollections,
|
|
84
|
+
[collectionKey]: getSharedCollectionFn((prev.sharedCollections?.[collectionKey] ?? emptyCol) as Col),
|
|
85
|
+
},
|
|
86
|
+
}))
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const rows = rows2 as SharedCollections[K]['rows']
|
|
90
|
+
return { rows, total, errors, isLoading, refetch }
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Base hook to fetch a collection or document (does not persist the data in the data-store) */
|
|
94
|
+
function useFetchResource<T>(endpoint?: string, queryString?: string, isDocument?: boolean) {
|
|
95
|
+
const [, setStore] = useTracked()
|
|
96
|
+
const [rows, setRows] = useState<T[]>([])
|
|
97
|
+
const [data, setData] = useState<T | undefined>()
|
|
98
|
+
const [total, setTotal] = useState(0)
|
|
99
|
+
const [errors, setErrors] = useState<Errors>([])
|
|
100
|
+
const [isLoading, setIsLoading] = useState(!!endpoint)
|
|
101
|
+
const [refreshCount, setRefreshCount] = useState(0)
|
|
102
|
+
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
let mounted = true
|
|
105
|
+
|
|
106
|
+
;(async function () {
|
|
107
|
+
try {
|
|
108
|
+
if (!endpoint) return
|
|
109
|
+
setIsLoading(true)
|
|
110
|
+
const response = await request(`get /api${endpoint}${queryString}`)
|
|
111
|
+
if (delay()) await setTimeoutPromise(() => {}, delay())
|
|
112
|
+
if (mounted) {
|
|
113
|
+
if (isDocument) {
|
|
114
|
+
setData(response || undefined)
|
|
115
|
+
} else {
|
|
116
|
+
setRows(response.rows || [])
|
|
117
|
+
setTotal(response.total || 0)
|
|
118
|
+
}
|
|
119
|
+
setErrors([])
|
|
120
|
+
setIsLoading(false)
|
|
121
|
+
}
|
|
122
|
+
} catch (error) {
|
|
123
|
+
if (mounted) {
|
|
124
|
+
showError(setStore, error)
|
|
125
|
+
setErrors(getResponseErrors(error))
|
|
126
|
+
setIsLoading(false)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
})()
|
|
130
|
+
|
|
131
|
+
return () => {
|
|
132
|
+
mounted = false
|
|
133
|
+
}
|
|
134
|
+
}, [refreshCount, endpoint, queryString])
|
|
135
|
+
|
|
136
|
+
function refetch() {
|
|
137
|
+
setRefreshCount(prev => prev + 1)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return isDocument === true ? { data, errors, isLoading, refetch, setData } : { rows, total, errors, isLoading, refetch, setRows }
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Clears a shared collection's cache (without refetching). Optionally appends an item immediately. */
|
|
144
|
+
export function clearCache<K extends keyof SharedCollections>(
|
|
145
|
+
setStore: Dispatch<SetStateAction<Store>>,
|
|
146
|
+
collectionKey: K,
|
|
147
|
+
append?: SharedCollections[K]['rows'][number]
|
|
148
|
+
) {
|
|
149
|
+
setStore((prev) => {
|
|
150
|
+
const col = (prev.sharedCollections?.[collectionKey] ?? emptyCol) as Col
|
|
151
|
+
const id = (append as Col['rows'][number] | undefined)?._id
|
|
152
|
+
return {
|
|
153
|
+
...prev,
|
|
154
|
+
sharedCollections: {
|
|
155
|
+
...prev.sharedCollections,
|
|
156
|
+
[collectionKey]: {
|
|
157
|
+
...col,
|
|
158
|
+
rows: append && !col.rows.some((r) => r._id === id) ? [...col.rows, append as Col['rows'][number]] : col.rows,
|
|
159
|
+
lastFetched: 0,
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
}
|
|
@@ -433,10 +433,19 @@ export async function userSigninGetStore(user, isDesktop) {
|
|
|
433
433
|
export async function getStore(user, _req) {
|
|
434
434
|
// Initial store (req only passed from the /store route, not after signin)
|
|
435
435
|
return {
|
|
436
|
-
user: user
|
|
436
|
+
user: user ? { ...user, companyRole: getCompanyRole(user) } : undefined,
|
|
437
437
|
}
|
|
438
438
|
}
|
|
439
439
|
|
|
440
|
+
/**
|
|
441
|
+
* The user's role in their active company (expects user.company to be populated)
|
|
442
|
+
* @param {object} user
|
|
443
|
+
* @returns {string|undefined}
|
|
444
|
+
*/
|
|
445
|
+
export function getCompanyRole(user) {
|
|
446
|
+
return user?.company?.users?.find(u => String(u._id) === String(user._id))?.role
|
|
447
|
+
}
|
|
448
|
+
|
|
440
449
|
/* ---- Helpers (not easily overridable) ----- */
|
|
441
450
|
|
|
442
451
|
/**
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import type { Errors } from 'nitro-web/types'
|
|
3
|
+
import { Spinner, twMerge } from 'nitro-web'
|
|
4
|
+
|
|
5
|
+
interface ContentWrapperProps<T = unknown> {
|
|
6
|
+
children: (data: T) => React.ReactNode
|
|
7
|
+
data?: T
|
|
8
|
+
isLoading?: boolean
|
|
9
|
+
errors?: Errors | null
|
|
10
|
+
loadingMessage?: string
|
|
11
|
+
errorTitle?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Owns the loading and error states, so children only render once the data is there
|
|
15
|
+
export const ContentWrapper = <T,>({ children, data, isLoading, errors, loadingMessage, errorTitle }: ContentWrapperProps<T>) => {
|
|
16
|
+
return (
|
|
17
|
+
<React.Fragment>
|
|
18
|
+
{
|
|
19
|
+
isLoading
|
|
20
|
+
? <LoadingBanner loadingMessage={loadingMessage} />
|
|
21
|
+
: (errors && errors.length > 0)
|
|
22
|
+
? <ErrorBanner errors={errors} errorTitle={errorTitle} />
|
|
23
|
+
: (data ? children(data) : null)
|
|
24
|
+
}
|
|
25
|
+
</React.Fragment>
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function ErrorBanner({ errors, errorTitle='Something went wrong', className }: {
|
|
30
|
+
errors?: Errors | null,
|
|
31
|
+
errorTitle?: string,
|
|
32
|
+
className?: string,
|
|
33
|
+
}) {
|
|
34
|
+
if (!errors || errors.length === 0) return null
|
|
35
|
+
return (
|
|
36
|
+
<div className={twMerge('p-5 border bg-danger/[0.03] border-danger text-danger-foreground rounded', className)}>
|
|
37
|
+
<h3 className="mb-1 font-semibold">{errorTitle}</h3>
|
|
38
|
+
{errors.map((error, i) => (
|
|
39
|
+
<p key={i}>{error.detail}</p>
|
|
40
|
+
))}
|
|
41
|
+
</div>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function LoadingBanner({ loadingMessage='One moment...', className }: { loadingMessage?: string, className?: string }) {
|
|
46
|
+
return (
|
|
47
|
+
<div className={`p-8 flex flex-col items-center justify-center gap-4 ${className||''}`}>
|
|
48
|
+
<Spinner className="size-3.5" />
|
|
49
|
+
<p className="font-medium">{loadingMessage}</p>
|
|
50
|
+
</div>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { Fragment, useRef, useState } from 'react'
|
|
2
|
+
import { twMerge } from 'nitro-web'
|
|
3
|
+
import { Modal } from './modal'
|
|
4
|
+
import { Button as BaseButton } from './button'
|
|
5
|
+
|
|
6
|
+
interface ModalProps {
|
|
7
|
+
elements?: { Button?: typeof BaseButton } // pass your project's extended Button
|
|
8
|
+
isOpen: boolean
|
|
9
|
+
onClose: () => void
|
|
10
|
+
title: string
|
|
11
|
+
subtitle?: React.ReactNode
|
|
12
|
+
children?: React.ReactNode
|
|
13
|
+
maxWidth?: string
|
|
14
|
+
className?: string
|
|
15
|
+
titleClassName?: string
|
|
16
|
+
subtitleClassName?: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface ConfirmModalProps extends ModalProps {
|
|
20
|
+
onSubmit: () => Promise<void> | void
|
|
21
|
+
confirmText?: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface FormModalProps extends ModalProps {
|
|
25
|
+
onSubmit?: () => Promise<void> | void
|
|
26
|
+
submitText?: string
|
|
27
|
+
submitIcon?: React.ReactNode
|
|
28
|
+
footerNote?: React.ReactNode
|
|
29
|
+
xClassName?: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Confirm dialog, prevents double submissions and picks a danger button for remove/delete titles
|
|
33
|
+
export function ConfirmModal({
|
|
34
|
+
isOpen,
|
|
35
|
+
onClose,
|
|
36
|
+
onSubmit,
|
|
37
|
+
title = 'Warning',
|
|
38
|
+
subtitle = 'Are you sure you want to proceed?',
|
|
39
|
+
confirmText = 'Confirm',
|
|
40
|
+
children,
|
|
41
|
+
elements,
|
|
42
|
+
className,
|
|
43
|
+
titleClassName,
|
|
44
|
+
subtitleClassName,
|
|
45
|
+
}: ConfirmModalProps) {
|
|
46
|
+
const [isLoading, setIsLoading] = useState(false)
|
|
47
|
+
const Button = elements?.Button || BaseButton
|
|
48
|
+
|
|
49
|
+
// Cache the values to prevent flickering when closing
|
|
50
|
+
const cached = useRef({ title, subtitle, confirmText, children })
|
|
51
|
+
if (isOpen) cached.current = { title, subtitle, confirmText, children }
|
|
52
|
+
|
|
53
|
+
async function handleSubmit() {
|
|
54
|
+
if (isLoading) return
|
|
55
|
+
setIsLoading(true)
|
|
56
|
+
try {
|
|
57
|
+
await onSubmit()
|
|
58
|
+
} finally {
|
|
59
|
+
setIsLoading(false)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<Modal
|
|
65
|
+
show={isOpen}
|
|
66
|
+
setShow={onClose}
|
|
67
|
+
maxWidth="480px"
|
|
68
|
+
className={twMerge('p-9 pt-8 rounded-md flex flex-col items-center gap-4', className)}
|
|
69
|
+
>
|
|
70
|
+
<div className="text-center">
|
|
71
|
+
<h3 className={twMerge('h3 text-[18px] mb-2.5', titleClassName)}>{cached.current.title}</h3>
|
|
72
|
+
{cached.current.subtitle && <p className={twMerge('h5 text-gray-500 mb-0', subtitleClassName)}>{cached.current.subtitle}</p>}
|
|
73
|
+
</div>
|
|
74
|
+
{cached.current.children}
|
|
75
|
+
<div className="self-stretch flex mt-1.5">
|
|
76
|
+
<Button className="flex-1"
|
|
77
|
+
color={title.match(/remove|delete/i) ? 'danger' : 'primary'}
|
|
78
|
+
onClick={handleSubmit}
|
|
79
|
+
isLoading={isLoading}
|
|
80
|
+
>
|
|
81
|
+
{cached.current.confirmText}
|
|
82
|
+
</Button>
|
|
83
|
+
</div>
|
|
84
|
+
</Modal>
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Form dialog with a header, optional submit button and footer note, prevents double submissions
|
|
89
|
+
export function FormModal({
|
|
90
|
+
isOpen,
|
|
91
|
+
onClose,
|
|
92
|
+
title,
|
|
93
|
+
subtitle,
|
|
94
|
+
children,
|
|
95
|
+
onSubmit,
|
|
96
|
+
submitText = 'Submit',
|
|
97
|
+
submitIcon,
|
|
98
|
+
footerNote,
|
|
99
|
+
maxWidth = '560px',
|
|
100
|
+
elements,
|
|
101
|
+
className,
|
|
102
|
+
titleClassName,
|
|
103
|
+
subtitleClassName,
|
|
104
|
+
xClassName,
|
|
105
|
+
}: FormModalProps) {
|
|
106
|
+
const [isLoading, setIsLoading] = useState(false)
|
|
107
|
+
const Button = elements?.Button || BaseButton
|
|
108
|
+
|
|
109
|
+
// Cache the values to prevent flickering when closing
|
|
110
|
+
const cached = useRef({ title, subtitle, submitText, submitIcon, footerNote, children })
|
|
111
|
+
if (isOpen) cached.current = { title, subtitle, submitText, submitIcon, footerNote, children }
|
|
112
|
+
|
|
113
|
+
async function handleSubmit() {
|
|
114
|
+
if (isLoading || !onSubmit) return
|
|
115
|
+
setIsLoading(true)
|
|
116
|
+
try {
|
|
117
|
+
await onSubmit()
|
|
118
|
+
} finally {
|
|
119
|
+
setIsLoading(false)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<Modal
|
|
125
|
+
show={isOpen}
|
|
126
|
+
setShow={onClose}
|
|
127
|
+
maxWidth={maxWidth}
|
|
128
|
+
className={twMerge('p-8 rounded-md flex flex-col gap-5', className)}
|
|
129
|
+
xClassName={twMerge('bg-[rgba(62,68,140,0.06)] hover:bg-[rgba(62,68,140,0.11)] rounded-md right-0 p-2.5 m-[11px]', xClassName)}
|
|
130
|
+
>
|
|
131
|
+
{(cached.current.title || cached.current.subtitle) && (
|
|
132
|
+
<Fragment>
|
|
133
|
+
<div className={twMerge('-m-8 mb-0 px-8 py-[18px] bg-[rgba(63,68,142,0.06)] rounded-t-md', titleClassName)}>
|
|
134
|
+
<h3 className="h3 text-[15.5px] mb-0 pb-0">{cached.current.title}</h3>
|
|
135
|
+
</div>
|
|
136
|
+
{cached.current.subtitle && (
|
|
137
|
+
<p className={twMerge('h5 text-gray-500 mb-0 text-left', subtitleClassName)}>{cached.current.subtitle}</p>
|
|
138
|
+
)}
|
|
139
|
+
</Fragment>
|
|
140
|
+
)}
|
|
141
|
+
{cached.current.children}
|
|
142
|
+
{onSubmit && (
|
|
143
|
+
<div className="self-stretch flex mt-1.5">
|
|
144
|
+
<Button className="flex-1" color="primary" onClick={handleSubmit} isLoading={isLoading} IconRight={cached.current.submitIcon}>
|
|
145
|
+
{cached.current.submitText}
|
|
146
|
+
</Button>
|
|
147
|
+
</div>
|
|
148
|
+
)}
|
|
149
|
+
{cached.current.footerNote && (
|
|
150
|
+
<div className="-mt-1 text-xs text-gray-500 flex items-center justify-center gap-1.5">{cached.current.footerNote}</div>
|
|
151
|
+
)}
|
|
152
|
+
</Modal>
|
|
153
|
+
)
|
|
154
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from 'react'
|
|
2
|
+
import { useNavigate, useLocation } from 'react-router-dom'
|
|
3
|
+
import { queryObject, queryString, twMerge } from 'nitro-web'
|
|
4
|
+
import { ChevronLeft, ChevronRight, ChevronsLeft, ChevronsRight } from 'lucide-react'
|
|
5
|
+
import { Button as BaseButton } from './button'
|
|
6
|
+
|
|
7
|
+
export type PaginationProps = {
|
|
8
|
+
total: number
|
|
9
|
+
perPage?: number
|
|
10
|
+
className?: string
|
|
11
|
+
elements?: { Button?: typeof BaseButton } // pass your project's extended Button
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function Pagination({ total, perPage=16, className, elements }: PaginationProps) {
|
|
15
|
+
// Page controls driven by the `?page=` query param
|
|
16
|
+
const Button = elements?.Button || BaseButton
|
|
17
|
+
const navigate = useNavigate()
|
|
18
|
+
const location = useLocation()
|
|
19
|
+
const query = useMemo(() => ({ ...queryObject(location.search) }), [location.search])
|
|
20
|
+
const [currentPage, setCurrentPage] = useState(parseInt(query.page as string || '1'))
|
|
21
|
+
const totalPages = useMemo(() => Math.ceil(total / perPage), [total, perPage])
|
|
22
|
+
const locationRef = useRef(location)
|
|
23
|
+
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
setCurrentPage(parseInt(query.page as string || '1'))
|
|
26
|
+
}, [query.page])
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
locationRef.current = location
|
|
30
|
+
}, [location])
|
|
31
|
+
|
|
32
|
+
const goToPage = (page: number) => {
|
|
33
|
+
const updatedQuery = { ...query, page: String(page) }
|
|
34
|
+
navigate(`${locationRef.current.pathname}${queryString(updatedQuery)}`)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<div className={twMerge('flex items-center justify-center gap-7 text-xs font-medium', className)}>
|
|
39
|
+
<span>Page {currentPage} of {totalPages}</span>
|
|
40
|
+
|
|
41
|
+
<div className="flex items-center gap-[7px]">
|
|
42
|
+
{[
|
|
43
|
+
{ Icon: ChevronsLeft, page: 1, disabled: currentPage === 1 },
|
|
44
|
+
{ Icon: ChevronLeft, page: currentPage - 1, disabled: currentPage === 1 },
|
|
45
|
+
{ Icon: ChevronRight, page: currentPage + 1, disabled: currentPage === totalPages },
|
|
46
|
+
{ Icon: ChevronsRight, page: totalPages, disabled: currentPage === totalPages },
|
|
47
|
+
].map(({ Icon, page, disabled }, i) => (
|
|
48
|
+
<Button
|
|
49
|
+
key={i}
|
|
50
|
+
onClick={() => goToPage(page)}
|
|
51
|
+
disabled={disabled}
|
|
52
|
+
color="white"
|
|
53
|
+
size="sm"
|
|
54
|
+
IconCenter={<Icon size={16} strokeWidth={2.2} />}
|
|
55
|
+
className={`h-[31px] ${disabled ? 'opacity-50 cursor-not-allowed' : ''}`}
|
|
56
|
+
/>
|
|
57
|
+
))}
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
@@ -2,23 +2,19 @@
|
|
|
2
2
|
import { css } from 'twin.macro'
|
|
3
3
|
import avatarImg from 'nitro-web/client/imgs/avatar.jpg'
|
|
4
4
|
import { injectedConfig } from 'nitro-web'
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
HomeIcon,
|
|
8
|
-
UsersIcon,
|
|
9
|
-
ArrowLeftCircleIcon,
|
|
10
|
-
PaintBrushIcon,
|
|
11
|
-
} from '@heroicons/react/24/outline'
|
|
12
|
-
import { XIcon } from 'lucide-react'
|
|
5
|
+
import React from 'react'
|
|
6
|
+
import { House, LogOut, Menu, Paintbrush, Users, XIcon } from 'lucide-react'
|
|
13
7
|
|
|
14
8
|
const sidebarWidth = 'w-80'
|
|
15
9
|
|
|
16
10
|
export type SidebarProps = {
|
|
17
11
|
Logo?: React.FC<{ width?: string, height?: string }>;
|
|
18
|
-
menu?: { name: string; to: string; Icon: React.FC<{ className?: string }> }[]
|
|
19
|
-
links?: { name: string; to: string; initial: string }[]
|
|
12
|
+
menu?: { name: string; to: string; toMatcher?: ToMatcher; Icon: React.FC<{ className?: string }> }[]
|
|
13
|
+
links?: { name: string; to: string; toMatcher?: ToMatcher; initial: string }[]
|
|
20
14
|
}
|
|
21
15
|
|
|
16
|
+
type ToMatcher = (pathname: string, search?: string) => boolean
|
|
17
|
+
|
|
22
18
|
function classNames(...classes: string[]) {
|
|
23
19
|
return classes.filter(Boolean).join(' ')
|
|
24
20
|
}
|
|
@@ -26,7 +22,7 @@ function classNames(...classes: string[]) {
|
|
|
26
22
|
export function Sidebar({ Logo, menu, links }: SidebarProps) {
|
|
27
23
|
const [sidebarOpen, setSidebarOpen] = useState(false)
|
|
28
24
|
return (
|
|
29
|
-
|
|
25
|
+
<React.Fragment>
|
|
30
26
|
{/* desktop sidebar */}
|
|
31
27
|
<div css={style} className={
|
|
32
28
|
'fixed inset-y-0 z-50 flex flex-col ease-in-out lg:left-0 lg:translate-x-0 lg:!delay-0 lg:!duration-0 ' +
|
|
@@ -64,7 +60,7 @@ export function Sidebar({ Logo, menu, links }: SidebarProps) {
|
|
|
64
60
|
{/* mobile sidebar topbar */}
|
|
65
61
|
<div className="sticky top-0 z-40 flex items-center gap-x-6 bg-white px-4 py-4 shadow-sm sm:px-6 lg:hidden">
|
|
66
62
|
<button type="button" onClick={() => setSidebarOpen(true)} className="-m-2.5 p-2.5 text-gray-700 lg:hidden">
|
|
67
|
-
<
|
|
63
|
+
<Menu aria-hidden="true" className="size-6" />
|
|
68
64
|
</button>
|
|
69
65
|
<div className="flex-1 text-sm/6 font-semibold text-gray-900">Dashboard</div>
|
|
70
66
|
<Link to="#">
|
|
@@ -73,7 +69,7 @@ export function Sidebar({ Logo, menu, links }: SidebarProps) {
|
|
|
73
69
|
</div>
|
|
74
70
|
|
|
75
71
|
<div class={`${sidebarWidth}`} />
|
|
76
|
-
|
|
72
|
+
</React.Fragment>
|
|
77
73
|
)
|
|
78
74
|
}
|
|
79
75
|
|
|
@@ -82,17 +78,13 @@ function SidebarContents ({ Logo, menu, links }: SidebarProps) {
|
|
|
82
78
|
const [store] = useTracked()
|
|
83
79
|
const user = store.user
|
|
84
80
|
|
|
85
|
-
|
|
86
|
-
if (path == '/' && location.pathname == path) return 'is-active'
|
|
87
|
-
else if (path != '/' && location.pathname.match(`^${path}`)) return 'is-active'
|
|
88
|
-
else return ''
|
|
89
|
-
}
|
|
81
|
+
const isActive = (item: { to: string, toMatcher?: ToMatcher }) => getIsActive(location, item)
|
|
90
82
|
|
|
91
83
|
const _menu = menu || [
|
|
92
|
-
{ name: 'Dashboard', to: '/', Icon:
|
|
93
|
-
{ name: injectedConfig.isDemo ? 'Design System' : 'Style Guide', to: '/styleguide', Icon:
|
|
94
|
-
{ name: 'Pricing', to: '/pricing', Icon:
|
|
95
|
-
{ name: 'Signout', to: '/signout', Icon:
|
|
84
|
+
{ name: 'Dashboard', to: '/', Icon: House },
|
|
85
|
+
{ name: injectedConfig.isDemo ? 'Design System' : 'Style Guide', to: '/styleguide', Icon: Paintbrush },
|
|
86
|
+
{ name: 'Pricing', to: '/pricing', Icon: Users },
|
|
87
|
+
{ name: 'Signout', to: '/signout', Icon: LogOut },
|
|
96
88
|
]
|
|
97
89
|
|
|
98
90
|
const _links = links || [
|
|
@@ -103,7 +95,7 @@ function SidebarContents ({ Logo, menu, links }: SidebarProps) {
|
|
|
103
95
|
return (
|
|
104
96
|
<div className="flex grow flex-col gap-y-8 overflow-y-auto bg-white py-5 px-10 lg:border-r lg:border-gray-200">
|
|
105
97
|
{Logo && (
|
|
106
|
-
<div className="flex h-16 shrink-0 items-center gap-2 justify-
|
|
98
|
+
<div className="flex h-16 shrink-0 items-center gap-2 justify-between">
|
|
107
99
|
<Link to="/">
|
|
108
100
|
<Logo width="70" height={undefined} />
|
|
109
101
|
</Link>
|
|
@@ -119,7 +111,7 @@ function SidebarContents ({ Logo, menu, links }: SidebarProps) {
|
|
|
119
111
|
<Link
|
|
120
112
|
to={item.to}
|
|
121
113
|
className={classNames(
|
|
122
|
-
isActive(item
|
|
114
|
+
isActive(item)
|
|
123
115
|
? 'bg-gray-50 text-indigo-600'
|
|
124
116
|
: 'text-gray-700 hover:bg-gray-50 hover:text-indigo-600',
|
|
125
117
|
'group flex gap-x-3 items-center rounded-md p-2 text-md/6 font-semibold'
|
|
@@ -128,7 +120,7 @@ function SidebarContents ({ Logo, menu, links }: SidebarProps) {
|
|
|
128
120
|
{ item.Icon &&
|
|
129
121
|
<item.Icon
|
|
130
122
|
className={classNames(
|
|
131
|
-
isActive(item
|
|
123
|
+
isActive(item) ? 'text-indigo-600' : 'text-gray-400 group-hover:text-indigo-600',
|
|
132
124
|
'size-5 shrink-0'
|
|
133
125
|
)}
|
|
134
126
|
/>
|
|
@@ -147,7 +139,7 @@ function SidebarContents ({ Logo, menu, links }: SidebarProps) {
|
|
|
147
139
|
<Link
|
|
148
140
|
to={team.to}
|
|
149
141
|
className={classNames(
|
|
150
|
-
isActive(team
|
|
142
|
+
isActive(team)
|
|
151
143
|
? 'bg-gray-50 text-indigo-600'
|
|
152
144
|
: 'text-gray-700 hover:bg-gray-50 hover:text-indigo-600',
|
|
153
145
|
'group flex gap-x-3 rounded-md p-2 text-md/6 font-semibold'
|
|
@@ -155,7 +147,7 @@ function SidebarContents ({ Logo, menu, links }: SidebarProps) {
|
|
|
155
147
|
>
|
|
156
148
|
<span
|
|
157
149
|
className={classNames(
|
|
158
|
-
isActive(team
|
|
150
|
+
isActive(team)
|
|
159
151
|
? 'border-indigo-600 text-indigo-600'
|
|
160
152
|
: 'border-gray-200 text-gray-400 group-hover:border-indigo-600 group-hover:text-indigo-600',
|
|
161
153
|
'flex size-6 shrink-0 items-center justify-center rounded-lg border bg-white text-[0.625rem] font-medium'
|
|
@@ -193,3 +185,14 @@ const style = css`
|
|
|
193
185
|
transition: transform 300ms, opacity 300ms, left 0ms 0ms;
|
|
194
186
|
}
|
|
195
187
|
`
|
|
188
|
+
|
|
189
|
+
// Active class for a menu/tab item, `toMatcher` overrides the default path prefix match
|
|
190
|
+
export function getIsActive(
|
|
191
|
+
location: { pathname: string, search: string },
|
|
192
|
+
item?: { toMatcher?: ToMatcher, to?: string } | null
|
|
193
|
+
) {
|
|
194
|
+
if (item?.toMatcher) return item.toMatcher(location.pathname, location.search) ? 'is-active' : ''
|
|
195
|
+
else if (item?.to == '/' && location.pathname == item.to) return 'is-active'
|
|
196
|
+
else if (item?.to && item.to != '/' && location.pathname.match(`^${item.to}`)) return 'is-active'
|
|
197
|
+
else return ''
|
|
198
|
+
}
|
|
@@ -1,154 +1,166 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
|
|
2
|
+
import { twMerge } from 'nitro-web'
|
|
3
|
+
import { Info } from 'lucide-react'
|
|
3
4
|
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
type Side = 'top' | 'bottom' | 'left' | 'right'
|
|
6
|
+
type IconProps = { size?: number; className?: string; tabIndex?: number; onClick?: () => void }
|
|
7
|
+
|
|
8
|
+
// Position the bubble relative to the trigger (spacing adds the gap)
|
|
9
|
+
const pos = {
|
|
10
|
+
top: 'bottom-full left-1/2 -translate-x-1/2',
|
|
11
|
+
bottom: 'top-full left-1/2 -translate-x-1/2',
|
|
12
|
+
left: 'right-full top-1/2 -translate-y-1/2',
|
|
13
|
+
right: 'left-full top-1/2 -translate-y-1/2',
|
|
10
14
|
}
|
|
11
15
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
{
|
|
16
|
-
text
|
|
17
|
-
? <>
|
|
18
|
-
<div class="tooltip-trigger ">{children}</div>
|
|
19
|
-
<div class={`tooltip-popup ${classNamePopup||''} ${isSmall ? 'is-small' : ''}`}>{text}</div>
|
|
20
|
-
</>
|
|
21
|
-
: children
|
|
22
|
-
}
|
|
23
|
-
</div>
|
|
24
|
-
)
|
|
16
|
+
const opposite: Record<Side, Side> = { top: 'bottom', bottom: 'top', left: 'right', right: 'left' }
|
|
17
|
+
const perp: Record<Side, Side[]> = {
|
|
18
|
+
top: ['right', 'left'], bottom: ['right', 'left'], left: ['bottom', 'top'], right: ['bottom', 'top'],
|
|
25
19
|
}
|
|
26
20
|
|
|
27
|
-
|
|
28
|
-
.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
left: 50%;
|
|
85
|
-
transform: translateX(-50%) translateY(15px) ;
|
|
86
|
-
&:after {
|
|
87
|
-
bottom: 100%;
|
|
88
|
-
left: 50%;
|
|
89
|
-
margin-left: -6px;
|
|
90
|
-
border-color: transparent transparent black transparent;
|
|
91
|
-
}
|
|
92
|
-
&.is-bottom-left {
|
|
93
|
-
left: 0px;
|
|
94
|
-
transform: translateX(0%) translateY(15px);
|
|
95
|
-
&:after {
|
|
96
|
-
left: 28px;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
&.is-left {
|
|
101
|
-
top: 50%;
|
|
102
|
-
right: 100%;
|
|
103
|
-
transform: translateX(-15px) translateY(-50%);
|
|
104
|
-
&:after {
|
|
105
|
-
top: 50%;
|
|
106
|
-
right: -12px;
|
|
107
|
-
margin-top: -6px;
|
|
108
|
-
border-color: transparent transparent transparent black;
|
|
109
|
-
}
|
|
21
|
+
export type TooltipProps = {
|
|
22
|
+
content: React.ReactNode
|
|
23
|
+
/** let the mouse move onto the bubble without closing */
|
|
24
|
+
contentHoverable?: boolean
|
|
25
|
+
children?: React.ReactNode
|
|
26
|
+
className?: string
|
|
27
|
+
/** trigger used when no children, click pins it open */
|
|
28
|
+
DefaultIcon?: React.ComponentType<IconProps>
|
|
29
|
+
/** px the invisible trigger area extends past the icon/children */
|
|
30
|
+
hitbox?: number
|
|
31
|
+
/** class for the default icon, e.g. to change its colour */
|
|
32
|
+
iconClassName?: string
|
|
33
|
+
maxWidth?: number
|
|
34
|
+
/** force open, ignoring hover/focus */
|
|
35
|
+
open?: boolean
|
|
36
|
+
side?: Side
|
|
37
|
+
/** px gap between trigger and bubble */
|
|
38
|
+
spacing?: number
|
|
39
|
+
// Anything else lands on the wrapper, so a parent like Dropdown can attach its handlers to a wrapped trigger
|
|
40
|
+
} & Omit<React.HTMLAttributes<HTMLSpanElement>, 'content' | 'className' | 'children'>
|
|
41
|
+
|
|
42
|
+
// Hover/focus tooltip that flips to the side with room, and stays placed while scrolling
|
|
43
|
+
export function Tooltip({
|
|
44
|
+
content, contentHoverable, hitbox = 5, DefaultIcon = Info, maxWidth = 245, open, side = 'top', spacing = 6, className, iconClassName,
|
|
45
|
+
children,
|
|
46
|
+
...rest
|
|
47
|
+
}: TooltipProps) {
|
|
48
|
+
const [hover, setHover] = useState(false)
|
|
49
|
+
const [pinned, setPinned] = useState(false) // kept open by clicking the default icon
|
|
50
|
+
const [actualSide, setActualSide] = useState(side)
|
|
51
|
+
const wrapRef = useRef<HTMLSpanElement>(null)
|
|
52
|
+
const bubbleRef = useRef<HTMLSpanElement>(null)
|
|
53
|
+
const closeTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)
|
|
54
|
+
const isOpen = open ?? (pinned || hover)
|
|
55
|
+
const gap = {
|
|
56
|
+
top: { marginBottom: spacing },
|
|
57
|
+
bottom: { marginTop: spacing },
|
|
58
|
+
left: { marginRight: spacing },
|
|
59
|
+
right: { marginLeft: spacing },
|
|
60
|
+
}[actualSide]
|
|
61
|
+
|
|
62
|
+
useEffect(() => () => clearTimeout(closeTimer.current), [])
|
|
63
|
+
|
|
64
|
+
// Close the pinned tooltip when clicking outside the component
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (!pinned) return
|
|
67
|
+
const onDown = (e: MouseEvent) => { if (!wrapRef.current?.contains(e.target as Node)) setPinned(false) }
|
|
68
|
+
addEventListener('mousedown', onDown)
|
|
69
|
+
return () => removeEventListener('mousedown', onDown)
|
|
70
|
+
}, [pinned])
|
|
71
|
+
|
|
72
|
+
// Place on show, and keep placed while scrolling/resizing
|
|
73
|
+
useLayoutEffect(() => {
|
|
74
|
+
if (!isOpen) return
|
|
75
|
+
const place = () => {
|
|
76
|
+
const wrap = wrapRef.current, bubble = bubbleRef.current
|
|
77
|
+
if (wrap && bubble) setActualSide(pick(side, spacing, wrap.getBoundingClientRect(), bubble.getBoundingClientRect(), getClip(wrap)))
|
|
110
78
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
79
|
+
place()
|
|
80
|
+
// rAF throttle so each open tooltip only reflows once per frame while scrolling
|
|
81
|
+
let raf = 0
|
|
82
|
+
const onMove = () => { cancelAnimationFrame(raf); raf = requestAnimationFrame(place) }
|
|
83
|
+
addEventListener('scroll', onMove, true)
|
|
84
|
+
addEventListener('resize', onMove)
|
|
85
|
+
return () => {
|
|
86
|
+
cancelAnimationFrame(raf)
|
|
87
|
+
removeEventListener('scroll', onMove, true)
|
|
88
|
+
removeEventListener('resize', onMove)
|
|
121
89
|
}
|
|
90
|
+
}, [isOpen, side, spacing])
|
|
91
|
+
|
|
92
|
+
// Hover handlers; when contentHoverable, delay close so the mouse can cross the gap onto the bubble.
|
|
93
|
+
// Hover is tracked even while `open` controls the bubble, so handing control back doesn't restore a stale hover
|
|
94
|
+
const show = () => { clearTimeout(closeTimer.current); setHover(true) }
|
|
95
|
+
const hide = () => {
|
|
96
|
+
if (contentHoverable) closeTimer.current = setTimeout(() => setHover(false), 100)
|
|
97
|
+
else setHover(false)
|
|
122
98
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<span
|
|
102
|
+
{...rest}
|
|
103
|
+
ref={wrapRef}
|
|
104
|
+
className="relative inline-flex nitro-tooltip"
|
|
105
|
+
onMouseEnter={show}
|
|
106
|
+
onMouseLeave={hide}
|
|
107
|
+
onFocus={show}
|
|
108
|
+
onBlur={hide}
|
|
109
|
+
>
|
|
110
|
+
{/* invisible hitbox so the trigger is easier to hover/click */}
|
|
111
|
+
<span
|
|
112
|
+
aria-hidden
|
|
113
|
+
style={{ inset: -hitbox }}
|
|
114
|
+
className={`absolute ${children ? '' : 'cursor-help'}`}
|
|
115
|
+
onClick={children ? undefined : () => setPinned(p => !p)}
|
|
116
|
+
/>
|
|
117
|
+
{children ?? (
|
|
118
|
+
<DefaultIcon
|
|
119
|
+
size={14}
|
|
120
|
+
tabIndex={0}
|
|
121
|
+
className={twMerge('cursor-help outline-none', pinned ? 'text-primary' : 'text-[#9A9A9A]', iconClassName)}
|
|
122
|
+
onClick={() => setPinned(p => !p)}
|
|
123
|
+
/>
|
|
124
|
+
)}
|
|
125
|
+
{isOpen && (
|
|
126
|
+
<span
|
|
127
|
+
ref={bubbleRef}
|
|
128
|
+
role="tooltip"
|
|
129
|
+
style={{ maxWidth, ...gap }}
|
|
130
|
+
className={twMerge(
|
|
131
|
+
'absolute z-50 w-max px-4 py-3 rounded-lg bg-black text-white text-xs font-medium shadow-md',
|
|
132
|
+
// interactive when pinned or hoverable so links/text/hover work, else click-through
|
|
133
|
+
pinned || contentHoverable ? 'pointer-events-auto' : 'pointer-events-none',
|
|
134
|
+
pos[actualSide],
|
|
135
|
+
className
|
|
136
|
+
)}
|
|
137
|
+
>
|
|
138
|
+
{content}
|
|
139
|
+
</span>
|
|
140
|
+
)}
|
|
141
|
+
</span>
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Tightest clipping bounds: viewport intersected with scrollable/clipped ancestors
|
|
146
|
+
function getClip(el: HTMLElement) {
|
|
147
|
+
const clip = { left: 0, top: 0, right: innerWidth, bottom: innerHeight }
|
|
148
|
+
for (let p = el.parentElement; p; p = p.parentElement) {
|
|
149
|
+
const s = getComputedStyle(p)
|
|
150
|
+
if (!/auto|scroll|hidden|clip/.test(s.overflow + s.overflowX + s.overflowY)) continue
|
|
151
|
+
const r = p.getBoundingClientRect()
|
|
152
|
+
clip.left = Math.max(clip.left, r.left)
|
|
153
|
+
clip.top = Math.max(clip.top, r.top)
|
|
154
|
+
clip.right = Math.min(clip.right, r.right)
|
|
155
|
+
clip.bottom = Math.min(clip.bottom, r.bottom)
|
|
153
156
|
}
|
|
154
|
-
|
|
157
|
+
return clip
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Pick the first side that fits within clip, else the one with the most spare space
|
|
161
|
+
function pick(side: Side, gap: number, t: DOMRect, b: DOMRect, clip: ReturnType<typeof getClip>): Side {
|
|
162
|
+
const space = { top: t.top - clip.top, bottom: clip.bottom - t.bottom, left: t.left - clip.left, right: clip.right - t.right }
|
|
163
|
+
const need = { top: b.height + gap, bottom: b.height + gap, left: b.width + gap, right: b.width + gap }
|
|
164
|
+
const order: Side[] = [side, opposite[side], ...perp[side]]
|
|
165
|
+
return order.find(s => space[s] >= need[s]) || order.sort((a, c) => (space[c] - need[c]) - (space[a] - need[a]))[0]
|
|
166
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-web",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"repository": "github:boycce/nitro-web",
|
|
5
5
|
"homepage": "https://boycce.github.io/nitro-web/",
|
|
6
6
|
"description": "Nitro is a battle-tested, modular base project to turbocharge your projects, styled using Tailwind 🚀",
|
|
@@ -12,10 +12,10 @@ todo: change naming to:
|
|
|
12
12
|
<!-- block content is the content of the email -->
|
|
13
13
|
{% block content %}
|
|
14
14
|
|
|
15
|
-
[[ subject = You've been invited to join
|
|
15
|
+
[[ subject = You've been invited to join %recipient.companyName% ]]
|
|
16
16
|
<b>%recipient.greet%</b>,<br/>
|
|
17
17
|
<br/>
|
|
18
|
-
You've been invited to join <b>%recipient.
|
|
18
|
+
You've been invited to join <b>%recipient.companyName%</b>.<br/>
|
|
19
19
|
<br/>
|
|
20
20
|
If you didn't expect to receive this email, feel free to disregard this email.<br/>
|
|
21
21
|
<br/>
|
package/tsconfig.json
CHANGED
|
@@ -14,6 +14,12 @@ export function userSigninGetStore(user: any, isDesktop: any): Promise<{
|
|
|
14
14
|
export function getStore(user: any, _req: any): Promise<{
|
|
15
15
|
user: any;
|
|
16
16
|
}>;
|
|
17
|
+
/**
|
|
18
|
+
* The user's role in their active company (expects user.company to be populated)
|
|
19
|
+
* @param {object} user
|
|
20
|
+
* @returns {string|undefined}
|
|
21
|
+
*/
|
|
22
|
+
export function getCompanyRole(user: object): string | undefined;
|
|
17
23
|
/**
|
|
18
24
|
* Creates a new user and company (if multi tenant and `user.company` is not an id)
|
|
19
25
|
* @param {object} userData - user data
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.api.d.ts","sourceRoot":"","sources":["../../../components/auth/auth.api.js"],"names":[],"mappings":"AAqLA,qEAUC;AAED,qEAwEC;AAED,qEAGC;AAED,gEAMC;AAED,iEAgBC;AAED,oEAGC;AAED,oEA8BC;AAED,gEAgCC;AAID,qGAkDC;AAED;;;GAOC;AAED;;GAKC;AAID;;;;;;;;;GASG;AACH,8EAPG;IAA0B,QAAQ,GAA1B,MAAM;IACY,SAAS,GAA3B,MAAM;IACY,OAAO,GAAzB,MAAM;CACd,YAAQ,MAAM,+BACN,OAAO,GACL,OAAO,CAAC,MAAM,CAAC,CAqE3B;AAED,kFAiBC;AAED,mEAOC;AAED,+EAWC;AAED,sHAiBC;AAED;;;GAEC;AAED;;;GA0BC;AAED;;;;;;;;;GAmCC;AAED;;;;;;;;;;;;;;GAcG;AACH,mGAZG;IAAsD,IAAI,EAAlD,OAAO,GAAG,QAAQ,GAAG,eAAe;IACpB,EAAE,EAAlB,MAAM;IAKH,OAAO,EAJV;QACN,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,MAAM,CAAC;QACtB,CAAK,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB;IAC0B,YAAY;IACZ,eAAe;IACjB,OAAO,GAAxB,MAAM;CACd,GAAU,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;CAAC,CAAC,CAmEtE;AAED,0CAEC;AAED,8DA8BC;AAED,gFAKC;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"auth.api.d.ts","sourceRoot":"","sources":["../../../components/auth/auth.api.js"],"names":[],"mappings":"AAqLA,qEAUC;AAED,qEAwEC;AAED,qEAGC;AAED,gEAMC;AAED,iEAgBC;AAED,oEAGC;AAED,oEA8BC;AAED,gEAgCC;AAID,qGAkDC;AAED;;;GAOC;AAED;;GAKC;AAED;;;;GAIG;AACH,qCAHW,MAAM,GACJ,MAAM,GAAC,SAAS,CAI5B;AAID;;;;;;;;;GASG;AACH,8EAPG;IAA0B,QAAQ,GAA1B,MAAM;IACY,SAAS,GAA3B,MAAM;IACY,OAAO,GAAzB,MAAM;CACd,YAAQ,MAAM,+BACN,OAAO,GACL,OAAO,CAAC,MAAM,CAAC,CAqE3B;AAED,kFAiBC;AAED,mEAOC;AAED,+EAWC;AAED,sHAiBC;AAED;;;GAEC;AAED;;;GA0BC;AAED;;;;;;;;;GAmCC;AAED;;;;;;;;;;;;;;GAcG;AACH,mGAZG;IAAsD,IAAI,EAAlD,OAAO,GAAG,QAAQ,GAAG,eAAe;IACpB,EAAE,EAAlB,MAAM;IAKH,OAAO,EAJV;QACN,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,MAAM,CAAC;QACtB,CAAK,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB;IAC0B,YAAY;IACZ,eAAe;IACjB,OAAO,GAAxB,MAAM;CACd,GAAU,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;CAAC,CAAC,CAmEtE;AAED,0CAEC;AAED,8DA8BC;AAED,gFAKC;;;;;;;;;;;;;;;;;;;;AAnvBD;;;;;;;;;;;;;;;EAiBC;AA0ED,0DAEC;AAgCD,mDAEC;AAtBD,iDAkBC;AA5BD,2DAQC;AA0BD,2DAwBC;AAtID,0EAsEC"}
|
package/types/globals.d.ts
CHANGED
package/types/util.d.ts
CHANGED
|
@@ -571,6 +571,12 @@ export function onChange<T>(eventOrPathValue: EventOrPathValue, setState: React.
|
|
|
571
571
|
* @returns {string}
|
|
572
572
|
*/
|
|
573
573
|
export function pad(num?: number, padLeft?: number, fixedRight?: number): string;
|
|
574
|
+
/**
|
|
575
|
+
* Escape user input before it is interpolated into html, e.g. email templates
|
|
576
|
+
* @param {any} str
|
|
577
|
+
* @returns {string}
|
|
578
|
+
*/
|
|
579
|
+
export function escapeHtml(str: any): string;
|
|
574
580
|
/**
|
|
575
581
|
* Escapes a string for use in a regex
|
|
576
582
|
* @param {string} str
|
|
@@ -901,6 +907,20 @@ export function twMerge(...args: (string | null | undefined | false | 0 | 0n)[])
|
|
|
901
907
|
* @returns {string}
|
|
902
908
|
*/
|
|
903
909
|
export function ucFirst(string: string): string;
|
|
910
|
+
/**
|
|
911
|
+
* Ensures the saved document is in the select options, adding a "(Saved)" sentinel option when it's missing.
|
|
912
|
+
* Handy when the options list is filtered/paginated, but the form state still references a document.
|
|
913
|
+
* @template {{ value: any, label?: any }} T
|
|
914
|
+
* @param {T[]} [options]
|
|
915
|
+
* @param {{ [key: string]: any } | null} [optionToEnsure] - document to ensure is in the options list
|
|
916
|
+
* @returns {T[]}
|
|
917
|
+
*/
|
|
918
|
+
export function addSentinel<T extends {
|
|
919
|
+
value: any;
|
|
920
|
+
label?: any;
|
|
921
|
+
}>(options?: T[], optionToEnsure?: {
|
|
922
|
+
[key: string]: any;
|
|
923
|
+
} | null): T[];
|
|
904
924
|
export { TZDate } from "@date-fns/tz";
|
|
905
925
|
export function getIdFromObject(object: {
|
|
906
926
|
_id?: string;
|
|
@@ -937,33 +957,17 @@ export type Image = {
|
|
|
937
957
|
};
|
|
938
958
|
export type SetState = import("react").Dispatch<import("react").SetStateAction<any>>;
|
|
939
959
|
/**
|
|
940
|
-
*
|
|
960
|
+
* Axios types, `axios-retry` augments AxiosRequestConfig with the 'axios-retry' key itself
|
|
941
961
|
*/
|
|
942
962
|
export type AxiosInstance = import("axios").AxiosInstance;
|
|
943
963
|
/**
|
|
944
|
-
*
|
|
964
|
+
* Axios types, `axios-retry` augments AxiosRequestConfig with the 'axios-retry' key itself
|
|
945
965
|
*/
|
|
946
966
|
export type AxiosRequestConfig = import("axios").AxiosRequestConfig;
|
|
947
967
|
/**
|
|
948
|
-
*
|
|
949
|
-
*/
|
|
950
|
-
export type AxiosResponse = import("axios").AxiosResponse;
|
|
951
|
-
/**
|
|
952
|
-
* Extend the config to be used below
|
|
968
|
+
* Axios types, `axios-retry` augments AxiosRequestConfig with the 'axios-retry' key itself
|
|
953
969
|
*/
|
|
954
|
-
export type
|
|
955
|
-
/**
|
|
956
|
-
* We only need to fix the `get` method, the rest of the methods inherit the new extended config...
|
|
957
|
-
*/
|
|
958
|
-
export type AxiosRequestConfigWithRetry = AxiosRequestConfig & {
|
|
959
|
-
"axios-retry"?: IAxiosRetryConfigExtended;
|
|
960
|
-
};
|
|
961
|
-
/**
|
|
962
|
-
* Create an `axios` instance type that contains the `axios-retry` global declarations.
|
|
963
|
-
*/
|
|
964
|
-
export type AxiosInstanceWithRetry = Omit<AxiosInstance, "get"> & {
|
|
965
|
-
get<T = any, R = AxiosResponse, D = any>(url: string, config?: AxiosRequestConfigWithRetry): Promise<R>;
|
|
966
|
-
};
|
|
970
|
+
export type AxiosInstanceWithRetry = AxiosInstance;
|
|
967
971
|
export type ObjectId = object;
|
|
968
972
|
export type parseId = (value: string) => ObjectId;
|
|
969
973
|
/**
|
package/types/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../util.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../util.js"],"names":[],"mappings":"AA2CA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmCC;AAED;;;;;;;;;;;;GAYG;AACH,yCAVG;IAAsD,YAAY,GAA1D,OAAO,OAAO,EAAE,mBAAmB;CAE3C,GAAU,sBAAsB,CA6BlC;AAED;;;;;GAKG;AACH,8BAJW,MAAM,cACN;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAC,GACrB,MAAM,CAKlB;AAED;;;;;;GAMG;AACH,+BALW,MAAM,oBACN,OAAO,gBACP,OAAO,GACL,MAAM,CAelB;AAED;;;;;GAKG;AACH,sCAJW,MAAM,wBACN,OAAO,GACL,MAAM,CAMlB;AAED;;;;GAIG;AACH,sCAHW,MAAM,GACJ,MAAM,CAIlB;AAED;;;;;GAKG;AACH,sCAJW,MAAM,wBACN,OAAO,GACL,MAAM,CAKlB;AAED;;;;GAIG;AACH,iCAHW,MAAM,GACJ,MAAM,CAIlB;AAED;;;;GAIG;AACH,sCAHW,MAAM,GACJ,OAAO,CAAC,OAAO,CAAC,CAsB5B;AAED;;;;;;;;;;GAUG;AACH,gCATW,MAAM,YAEd;IAAyB,QAAQ,GAAzB,MAAM;IACW,QAAQ,GAAzB,MAAM;IACW,eAAe,GAAhC,MAAM;IACW,MAAM,GAAvB,MAAM;IACW,MAAM,GAAvB,MAAM;CACd,GAAU,MAAM,CAqBlB;AAED;;;;GAIG;AACH,0CAHW,MAAM,GACJ,MAAM,CAMlB;AAED;;;;;;GAMG;AACH,4BALW,MAAM,GAAC,IAAI,YACX,MAAM,aACN,MAAM,GACJ,MAAM,CAOlB;AAED;;;;;;;GAOG;AACH,qCANW,MAAM,GAAC,IAAI,aACX,MA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AAC,OAAO,CAAC,EAAE;;;;8BACzB;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE;yBACtB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE;yBACjC;IAAE,MAAM,EAAE,MAAM;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE;8BACrC;IAAE,QAAQ,EAAE;QAAE,IAAI,EAAE;YAAE,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,CAAC;YAAC,iBAAiB,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAA;CAAE"}
|
package/types.ts
CHANGED
|
@@ -31,6 +31,16 @@ export type User = {
|
|
|
31
31
|
name?: string
|
|
32
32
|
avatar?: MonasteryFile
|
|
33
33
|
isAdmin?: boolean
|
|
34
|
+
companyRole?: 'owner' | 'manager' // role in the active company, set by getStore
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// A collection cached on the store (see the example project's client/use-fetch.ts)
|
|
38
|
+
export type SharedCollection<T> = {
|
|
39
|
+
rows: T[]
|
|
40
|
+
total: number
|
|
41
|
+
errors?: Errors
|
|
42
|
+
isLoading?: boolean
|
|
43
|
+
lastFetched?: number
|
|
34
44
|
}
|
|
35
45
|
|
|
36
46
|
export type Error = { title: string, detail: string }
|
|
@@ -56,8 +66,12 @@ export type Store = {
|
|
|
56
66
|
jwt?: string
|
|
57
67
|
message?: MessageObject | string
|
|
58
68
|
user: User,
|
|
69
|
+
sharedCollections?: SharedCollections
|
|
59
70
|
}
|
|
60
71
|
|
|
72
|
+
// Collections cached on the store, fetched with useFetchSharedCol(). Extend this on your project's Store
|
|
73
|
+
export interface SharedCollections {} // eslint-disable-line @typescript-eslint/no-empty-object-type
|
|
74
|
+
|
|
61
75
|
// util.addressSchema
|
|
62
76
|
export type Address = {
|
|
63
77
|
city?: string
|
package/util.js
CHANGED
|
@@ -12,20 +12,11 @@ export { TZDate } from '@date-fns/tz'
|
|
|
12
12
|
/** @typedef {import('react').Dispatch<import('react').SetStateAction<any>>} SetState */
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Axios types, `axios-retry` augments AxiosRequestConfig with the 'axios-retry' key itself
|
|
16
16
|
* @typedef {import('axios').AxiosInstance} AxiosInstance
|
|
17
17
|
* @typedef {import('axios').AxiosRequestConfig} AxiosRequestConfig
|
|
18
|
-
* @typedef {
|
|
19
|
-
|
|
20
|
-
*
|
|
21
|
-
* Extend the config to be used below
|
|
22
|
-
* @typedef {AxiosRequestConfig & { 'axios-retry'?: IAxiosRetryConfigExtended }} AxiosRequestConfigWithRetry
|
|
23
|
-
*
|
|
24
|
-
* We only need to fix the `get` method, the rest of the methods inherit the new extended config...
|
|
25
|
-
* @typedef {Omit<AxiosInstance, 'get'> & {
|
|
26
|
-
* get<T = any, R = AxiosResponse, D = any>(url: string, config?: AxiosRequestConfigWithRetry): Promise<R>
|
|
27
|
-
* }} AxiosInstanceWithRetry
|
|
28
|
-
*/
|
|
18
|
+
* @typedef {AxiosInstance} AxiosInstanceWithRetry
|
|
19
|
+
*/
|
|
29
20
|
|
|
30
21
|
/** @typedef {object} ObjectId */
|
|
31
22
|
/** @typedef {(value: string) => ObjectId} parseId */
|
|
@@ -1417,6 +1408,16 @@ export function pad (num=0, padLeft=0, fixedRight) {
|
|
|
1417
1408
|
}
|
|
1418
1409
|
}
|
|
1419
1410
|
|
|
1411
|
+
/**
|
|
1412
|
+
* Escape user input before it is interpolated into html, e.g. email templates
|
|
1413
|
+
* @param {any} str
|
|
1414
|
+
* @returns {string}
|
|
1415
|
+
*/
|
|
1416
|
+
export function escapeHtml (str) {
|
|
1417
|
+
const map = /** @type {{ [key: string]: string }} */ ({ '&': '&', '<': '<', '>': '>', '"': '"', '\'': ''' })
|
|
1418
|
+
return String(str ?? '').replace(/[&<>"']/g, c => map[c])
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1420
1421
|
/**
|
|
1421
1422
|
* Escapes a string for use in a regex
|
|
1422
1423
|
* @param {string} str
|
|
@@ -1850,10 +1851,10 @@ export async function request (route, data, event, setIsLoading, setState, optio
|
|
|
1850
1851
|
const formData2 = hasFiles ? formData({ ...data }, { allowEmptyArrays: true, indices: true }) : undefined
|
|
1851
1852
|
|
|
1852
1853
|
// send the request
|
|
1853
|
-
const
|
|
1854
|
-
const axiosPromise = (method === 'get' || method === 'delete')
|
|
1855
|
-
?
|
|
1856
|
-
:
|
|
1854
|
+
const client = axios()
|
|
1855
|
+
const axiosPromise = (method === 'get' || method === 'delete')
|
|
1856
|
+
? client[method](uri, axiosConfig)
|
|
1857
|
+
: client[method](uri, formData2 || data, axiosConfig)
|
|
1857
1858
|
|
|
1858
1859
|
const [res] = await Promise.allSettled([
|
|
1859
1860
|
axiosPromise,
|
|
@@ -2237,3 +2238,31 @@ export function ucFirst (string) {
|
|
|
2237
2238
|
if (!string) return ''
|
|
2238
2239
|
return string.charAt(0).toUpperCase() + string.slice(1)
|
|
2239
2240
|
}
|
|
2241
|
+
|
|
2242
|
+
/**
|
|
2243
|
+
* Ensures the saved document is in the select options, adding a "(Saved)" sentinel option when it's missing.
|
|
2244
|
+
* Handy when the options list is filtered/paginated, but the form state still references a document.
|
|
2245
|
+
* @template {{ value: any, label?: any }} T
|
|
2246
|
+
* @param {T[]} [options]
|
|
2247
|
+
* @param {{ [key: string]: any } | null} [optionToEnsure] - document to ensure is in the options list
|
|
2248
|
+
* @returns {T[]}
|
|
2249
|
+
*/
|
|
2250
|
+
export function addSentinel (options=[], optionToEnsure) {
|
|
2251
|
+
if (!optionToEnsure || typeof optionToEnsure !== 'object') return options
|
|
2252
|
+
const value = optionToEnsure._id
|
|
2253
|
+
const label = optionToEnsure.name ?? optionToEnsure.business?.name
|
|
2254
|
+
if (options.some(o => o.value === value)) return options // option already exists
|
|
2255
|
+
|
|
2256
|
+
const sentinelOption = {
|
|
2257
|
+
value: value,
|
|
2258
|
+
label: label ? `${label} (Saved)` : 'Saved value',
|
|
2259
|
+
IconLeft: optionToEnsure.IconLeft,
|
|
2260
|
+
data: { ...optionToEnsure, IconLeft: undefined }, // original option/document data kept here
|
|
2261
|
+
}
|
|
2262
|
+
|
|
2263
|
+
// Add sentinel after the "none"/"new" option if it exists, otherwise prepend it
|
|
2264
|
+
const _options = [...options]
|
|
2265
|
+
const afterIndex = _options.findIndex(o => o.value === '' || (typeof o.value === 'string' && o.value.includes('__new__')))
|
|
2266
|
+
_options.splice(afterIndex >= 0 ? afterIndex + 1 : 0, 0, /** @type {any} */(sentinelOption))
|
|
2267
|
+
return _options
|
|
2268
|
+
}
|