2021-08-04 23:31:54 +00:00
|
|
|
//
|
|
|
|
// Copyright © 2020 Anticrm Platform Contributors.
|
|
|
|
//
|
|
|
|
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License. You may
|
|
|
|
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
//
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
|
|
|
|
import { SvelteComponent } from 'svelte'
|
2021-09-09 07:34:51 +00:00
|
|
|
import type { AnySvelteComponent, AnyComponent, PopupAlignment, LabelAndProps, TooltipAligment } from './types'
|
2021-12-08 09:09:51 +00:00
|
|
|
import { getResource, IntlString, addStringsLoader } from '@anticrm/platform'
|
|
|
|
import { uiId } from './plugin'
|
|
|
|
import { writable, readable } from 'svelte/store'
|
2021-08-04 23:31:54 +00:00
|
|
|
|
|
|
|
import Root from './components/internal/Root.svelte'
|
|
|
|
|
2021-09-09 07:34:51 +00:00
|
|
|
export type { AnyComponent, AnySvelteComponent, Action, LabelAndProps, TooltipAligment } from './types'
|
2021-08-04 23:31:54 +00:00
|
|
|
// export { applicationShortcutKey } from './utils'
|
2022-01-11 09:23:17 +00:00
|
|
|
export { getCurrentLocation, locationToUrl, navigate, location } from './location'
|
2021-08-04 23:31:54 +00:00
|
|
|
|
|
|
|
export { default as EditBox } from './components/EditBox.svelte'
|
|
|
|
export { default as Label } from './components/Label.svelte'
|
|
|
|
export { default as Button } from './components/Button.svelte'
|
2021-09-22 11:15:25 +00:00
|
|
|
export { default as Status } from './components/Status.svelte'
|
2021-08-04 23:31:54 +00:00
|
|
|
export { default as Component } from './components/Component.svelte'
|
|
|
|
export { default as Icon } from './components/Icon.svelte'
|
|
|
|
export { default as ActionIcon } from './components/ActionIcon.svelte'
|
|
|
|
export { default as Toggle } from './components/Toggle.svelte'
|
|
|
|
export { default as Dialog } from './components/Dialog.svelte'
|
|
|
|
export { default as ToggleWithLabel } from './components/ToggleWithLabel.svelte'
|
|
|
|
export { default as Tooltip } from './components/Tooltip.svelte'
|
2021-09-09 07:34:51 +00:00
|
|
|
export { default as TooltipInstance } from './components/TooltipInstance.svelte'
|
2021-08-04 23:31:54 +00:00
|
|
|
export { default as CheckBox } from './components/CheckBox.svelte'
|
|
|
|
export { default as Progress } from './components/Progress.svelte'
|
|
|
|
export { default as Tabs } from './components/Tabs.svelte'
|
|
|
|
export { default as ScrollBox } from './components/ScrollBox.svelte'
|
|
|
|
export { default as PopupMenu } from './components/PopupMenu.svelte'
|
2021-09-11 12:10:17 +00:00
|
|
|
// export { default as PopupItem } from './components/PopupItem.svelte'
|
2021-08-04 23:31:54 +00:00
|
|
|
export { default as TextArea } from './components/TextArea.svelte'
|
|
|
|
export { default as Section } from './components/Section.svelte'
|
|
|
|
export { default as DatePicker } from './components/DatePicker.svelte'
|
2021-12-02 09:09:37 +00:00
|
|
|
export { default as DatePopup } from './components/DatePopup.svelte'
|
2021-08-05 16:27:51 +00:00
|
|
|
export { default as StylishEdit } from './components/StylishEdit.svelte'
|
2021-08-04 23:31:54 +00:00
|
|
|
export { default as Grid } from './components/Grid.svelte'
|
|
|
|
export { default as Row } from './components/Row.svelte'
|
2021-09-11 12:10:17 +00:00
|
|
|
// export { default as CheckBoxWithLabel } from './components/CheckBoxWithLabel.svelte'
|
|
|
|
// export { default as CheckBoxList } from './components/CheckBoxList.svelte.txt'
|
2021-08-06 06:49:54 +00:00
|
|
|
export { default as EditWithIcon } from './components/EditWithIcon.svelte'
|
2022-01-19 09:05:40 +00:00
|
|
|
export { default as SearchEdit } from './components/SearchEdit.svelte'
|
2021-08-10 10:53:24 +00:00
|
|
|
export { default as Loading } from './components/Loading.svelte'
|
2021-09-15 17:03:34 +00:00
|
|
|
export { default as Spinner } from './components/Spinner.svelte'
|
2021-08-19 12:54:06 +00:00
|
|
|
export { default as Popup } from './components/Popup.svelte'
|
2021-08-28 10:06:28 +00:00
|
|
|
export { default as CircleButton } from './components/CircleButton.svelte'
|
2021-08-30 17:19:58 +00:00
|
|
|
export { default as Link } from './components/Link.svelte'
|
2021-09-11 13:18:54 +00:00
|
|
|
export { default as TimeSince } from './components/TimeSince.svelte'
|
2021-11-02 08:45:08 +00:00
|
|
|
export { default as Dropdown } from './components/Dropdown.svelte'
|
2021-12-23 09:03:35 +00:00
|
|
|
export { default as DropdownLabels } from './components/DropdownLabels.svelte'
|
2021-12-21 09:12:20 +00:00
|
|
|
export { default as ShowMore } from './components/ShowMore.svelte'
|
2022-01-12 09:01:54 +00:00
|
|
|
export { default as Menu } from './components/Menu.svelte'
|
|
|
|
export { default as ErrorPresenter } from './components/ErrorPresenter.svelte'
|
2021-08-04 23:31:54 +00:00
|
|
|
|
|
|
|
export { default as IconAdd } from './components/icons/Add.svelte'
|
2022-01-12 09:01:54 +00:00
|
|
|
export { default as IconBack } from './components/icons/Back.svelte'
|
|
|
|
export { default as IconForward } from './components/icons/Forward.svelte'
|
2021-08-30 07:17:26 +00:00
|
|
|
export { default as IconClose } from './components/icons/Close.svelte'
|
2021-08-04 23:31:54 +00:00
|
|
|
export { default as IconSearch } from './components/icons/Search.svelte'
|
2022-01-12 09:01:54 +00:00
|
|
|
export { default as IconCalendar } from './components/icons/Calendar.svelte'
|
2021-09-03 15:39:10 +00:00
|
|
|
export { default as IconFolder } from './components/icons/Folder.svelte'
|
2021-09-06 16:00:43 +00:00
|
|
|
export { default as IconMoreH } from './components/icons/MoreH.svelte'
|
2021-12-22 09:03:28 +00:00
|
|
|
export { default as IconMoreV } from './components/icons/MoreV.svelte'
|
2021-09-06 16:00:43 +00:00
|
|
|
export { default as IconFile } from './components/icons/File.svelte'
|
2021-09-07 07:48:41 +00:00
|
|
|
export { default as IconAttachment } from './components/icons/Attachment.svelte'
|
|
|
|
export { default as IconThread } from './components/icons/Thread.svelte'
|
2021-09-11 18:33:51 +00:00
|
|
|
export { default as IconExpand } from './components/icons/Expand.svelte'
|
|
|
|
export { default as IconActivity } from './components/icons/Activity.svelte'
|
2021-10-06 09:57:44 +00:00
|
|
|
export { default as IconUp } from './components/icons/Up.svelte'
|
|
|
|
export { default as IconDown } from './components/icons/Down.svelte'
|
2021-12-02 15:47:34 +00:00
|
|
|
export { default as IconShare } from './components/icons/Share.svelte'
|
2021-11-29 11:11:27 +00:00
|
|
|
export { default as IconDelete } from './components/icons/Delete.svelte'
|
2021-11-03 13:01:21 +00:00
|
|
|
export { default as IconEdit } from './components/icons/Edit.svelte'
|
2021-11-26 11:09:46 +00:00
|
|
|
export { default as IconInfo } from './components/icons/Info.svelte'
|
2021-12-23 09:03:35 +00:00
|
|
|
export { default as IconBlueCheck } from './components/icons/BlueCheck.svelte'
|
2022-01-12 09:01:54 +00:00
|
|
|
export { default as IconArrowLeft } from './components/icons/ArrowLeft.svelte'
|
2021-08-04 23:31:54 +00:00
|
|
|
|
2021-08-24 17:06:19 +00:00
|
|
|
export * from './utils'
|
|
|
|
|
2021-08-04 23:31:54 +00:00
|
|
|
export function createApp (target: HTMLElement): SvelteComponent {
|
|
|
|
return new Root({ target })
|
|
|
|
}
|
|
|
|
|
|
|
|
interface CompAndProps {
|
2021-09-22 10:43:25 +00:00
|
|
|
is: AnySvelteComponent
|
2021-08-04 23:31:54 +00:00
|
|
|
props: any
|
2021-09-01 16:31:05 +00:00
|
|
|
element?: PopupAlignment
|
2021-09-01 12:38:22 +00:00
|
|
|
onClose?: (result: any) => void
|
2021-08-04 23:31:54 +00:00
|
|
|
}
|
|
|
|
|
2021-09-11 12:10:17 +00:00
|
|
|
// export const store = writable<CompAndProps>({
|
|
|
|
// is: undefined,
|
|
|
|
// props: {},
|
|
|
|
// })
|
2021-08-04 23:31:54 +00:00
|
|
|
|
2021-08-31 17:07:28 +00:00
|
|
|
export const popupstore = writable<CompAndProps[]>([])
|
2021-08-19 12:54:06 +00:00
|
|
|
|
2022-01-11 09:23:17 +00:00
|
|
|
export function showPopup (
|
|
|
|
component: AnySvelteComponent | AnyComponent,
|
|
|
|
props: any,
|
|
|
|
element?: PopupAlignment,
|
|
|
|
onClose?: (result: any) => void
|
|
|
|
): void {
|
2021-09-22 10:43:25 +00:00
|
|
|
if (typeof component === 'string') {
|
2022-01-11 09:23:17 +00:00
|
|
|
getResource(component)
|
|
|
|
.then((resolved) => {
|
|
|
|
popupstore.update((popups) => {
|
|
|
|
popups.push({ is: resolved, props, element, onClose })
|
|
|
|
return popups
|
|
|
|
})
|
2021-12-30 09:04:32 +00:00
|
|
|
})
|
2022-01-11 09:23:17 +00:00
|
|
|
.catch((err) => console.log(err))
|
2021-09-22 10:43:25 +00:00
|
|
|
} else {
|
2022-01-11 09:23:17 +00:00
|
|
|
popupstore.update((popups) => {
|
2021-09-22 10:43:25 +00:00
|
|
|
popups.push({ is: component, props, element, onClose })
|
|
|
|
return popups
|
|
|
|
})
|
|
|
|
}
|
2021-08-19 12:54:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function closePopup (): void {
|
2022-01-11 09:23:17 +00:00
|
|
|
popupstore.update((popups) => {
|
2021-08-31 17:07:28 +00:00
|
|
|
popups.pop()
|
|
|
|
return popups
|
|
|
|
})
|
2021-08-19 12:54:06 +00:00
|
|
|
}
|
2021-09-09 07:34:51 +00:00
|
|
|
|
|
|
|
export const tooltipstore = writable<LabelAndProps>({
|
|
|
|
label: undefined,
|
|
|
|
element: undefined,
|
2021-09-27 08:06:05 +00:00
|
|
|
direction: undefined,
|
|
|
|
component: undefined,
|
2021-11-25 11:09:37 +00:00
|
|
|
props: undefined,
|
|
|
|
anchor: undefined
|
2021-09-09 07:34:51 +00:00
|
|
|
})
|
|
|
|
|
2022-01-11 09:23:17 +00:00
|
|
|
export function showTooltip (
|
|
|
|
label: IntlString | undefined,
|
|
|
|
element: HTMLElement,
|
|
|
|
direction?: TooltipAligment,
|
|
|
|
component?: AnySvelteComponent | AnyComponent,
|
|
|
|
props?: any,
|
|
|
|
anchor?: HTMLElement
|
|
|
|
): void {
|
|
|
|
tooltipstore.set({
|
|
|
|
label: label,
|
|
|
|
element: element,
|
|
|
|
direction: direction,
|
|
|
|
component: component,
|
|
|
|
props: props,
|
|
|
|
anchor: anchor
|
|
|
|
})
|
2021-09-09 07:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function closeTooltip (): void {
|
2022-01-11 09:23:17 +00:00
|
|
|
tooltipstore.set({
|
|
|
|
label: undefined,
|
|
|
|
element: undefined,
|
|
|
|
direction: undefined,
|
|
|
|
component: undefined,
|
|
|
|
props: undefined,
|
|
|
|
anchor: undefined
|
|
|
|
})
|
2021-09-09 07:34:51 +00:00
|
|
|
}
|
2021-09-11 13:18:54 +00:00
|
|
|
|
2022-01-11 09:23:17 +00:00
|
|
|
export const ticker = readable(Date.now(), (set) => {
|
|
|
|
setInterval(() => {
|
2021-12-30 09:04:32 +00:00
|
|
|
set(Date.now())
|
|
|
|
}, 10000)
|
2021-09-11 13:18:54 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
addStringsLoader(uiId, async (lang: string) => {
|
|
|
|
return await import(`../lang/${lang}.json`)
|
|
|
|
})
|
2021-12-13 09:05:46 +00:00
|
|
|
|
|
|
|
export { default } from './plugin'
|
2022-01-06 11:38:40 +00:00
|
|
|
export * from './colors'
|