@dosgato/dialog 0.0.1
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/ButtonGroup.svelte +74 -0
- package/ButtonGroup.svelte.d.ts +28 -0
- package/Checkbox.svelte +68 -0
- package/Checkbox.svelte.d.ts +25 -0
- package/Container.svelte +86 -0
- package/Container.svelte.d.ts +25 -0
- package/FieldCheckbox.svelte +28 -0
- package/FieldCheckbox.svelte.d.ts +23 -0
- package/FieldChoices.svelte +75 -0
- package/FieldChoices.svelte.d.ts +28 -0
- package/FieldChooserLink.svelte +100 -0
- package/FieldChooserLink.svelte.d.ts +30 -0
- package/FieldDate.svelte +19 -0
- package/FieldDate.svelte.d.ts +29 -0
- package/FieldDateTime.svelte +19 -0
- package/FieldDateTime.svelte.d.ts +29 -0
- package/FieldMultiple.svelte +83 -0
- package/FieldMultiple.svelte.d.ts +33 -0
- package/FieldMultiselect.svelte +50 -0
- package/FieldMultiselect.svelte.d.ts +25 -0
- package/FieldNumber.svelte +20 -0
- package/FieldNumber.svelte.d.ts +26 -0
- package/FieldRadio.svelte +52 -0
- package/FieldRadio.svelte.d.ts +29 -0
- package/FieldSelect.svelte +24 -0
- package/FieldSelect.svelte.d.ts +30 -0
- package/FieldStandard.svelte +19 -0
- package/FieldStandard.svelte.d.ts +36 -0
- package/FieldText.svelte +20 -0
- package/FieldText.svelte.d.ts +26 -0
- package/FileIcon.svelte +56 -0
- package/FileIcon.svelte.d.ts +21 -0
- package/Form.svelte +56 -0
- package/Form.svelte.d.ts +9 -0
- package/Icon.svelte +16 -0
- package/Icon.svelte.d.ts +22 -0
- package/InlineMessage.svelte +42 -0
- package/InlineMessage.svelte.d.ts +17 -0
- package/InlineMessages.svelte +21 -0
- package/InlineMessages.svelte.d.ts +18 -0
- package/Input.svelte +33 -0
- package/Input.svelte.d.ts +36 -0
- package/LICENSE +21 -0
- package/README.md +38 -0
- package/Radio.svelte +65 -0
- package/Radio.svelte.d.ts +25 -0
- package/Tab.svelte +57 -0
- package/Tab.svelte.d.ts +18 -0
- package/TabStore.d.ts +28 -0
- package/TabStore.js +42 -0
- package/Tabs.svelte +105 -0
- package/Tabs.svelte.d.ts +25 -0
- package/chooser/Asset.svelte +77 -0
- package/chooser/Asset.svelte.d.ts +25 -0
- package/chooser/AssetFolder.svelte +124 -0
- package/chooser/AssetFolder.svelte.d.ts +25 -0
- package/chooser/Chooser.svelte +169 -0
- package/chooser/Chooser.svelte.d.ts +30 -0
- package/chooser/ChooserAPI.d.ts +48 -0
- package/chooser/ChooserAPI.js +1 -0
- package/chooser/ChooserStore.d.ts +72 -0
- package/chooser/ChooserStore.js +200 -0
- package/chooser/Details.svelte +29 -0
- package/chooser/Details.svelte.d.ts +19 -0
- package/chooser/Page.svelte +118 -0
- package/chooser/Page.svelte.d.ts +25 -0
- package/chooser/Thumbnail.svelte +40 -0
- package/chooser/Thumbnail.svelte.d.ts +17 -0
- package/chooser/index.d.ts +6 -0
- package/chooser/index.js +6 -0
- package/index.d.ts +24 -0
- package/index.js +24 -0
- package/package.json +63 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<script >import { modifierKey } from '@txstate-mws/svelte-components';
|
|
2
|
+
import { createEventDispatcher, getContext } from 'svelte';
|
|
3
|
+
import { hashid } from 'txstate-utils';
|
|
4
|
+
import { ASSET_STORE_CONTEXT } from './ChooserStore';
|
|
5
|
+
import FileIcon from '../FileIcon.svelte';
|
|
6
|
+
export let asset;
|
|
7
|
+
export let level;
|
|
8
|
+
export let posinset;
|
|
9
|
+
export let setsize;
|
|
10
|
+
export let next;
|
|
11
|
+
export let prev;
|
|
12
|
+
export let parent = undefined;
|
|
13
|
+
const store = getContext(ASSET_STORE_CONTEXT);
|
|
14
|
+
$: id = hashid(asset.id);
|
|
15
|
+
$: haveFocus = $store?.focus === asset.id;
|
|
16
|
+
$: isPreview = $store.preview?.id === asset.id;
|
|
17
|
+
const dispatch = createEventDispatcher();
|
|
18
|
+
function onKeyDown(e) {
|
|
19
|
+
if (modifierKey(e))
|
|
20
|
+
return;
|
|
21
|
+
if (['Enter', ' '].includes(e.key)) {
|
|
22
|
+
e.preventDefault();
|
|
23
|
+
e.stopPropagation();
|
|
24
|
+
if ($store.preview?.id === asset.id)
|
|
25
|
+
dispatch('choose', asset);
|
|
26
|
+
else
|
|
27
|
+
store.preview(asset);
|
|
28
|
+
}
|
|
29
|
+
else if (e.key === 'ArrowDown') {
|
|
30
|
+
e.preventDefault();
|
|
31
|
+
e.stopPropagation();
|
|
32
|
+
if (next) {
|
|
33
|
+
store.setFocus(next);
|
|
34
|
+
document.getElementById(hashid(next.id)).focus();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else if (e.key === 'ArrowUp') {
|
|
38
|
+
e.preventDefault();
|
|
39
|
+
e.stopPropagation();
|
|
40
|
+
const anyprev = prev;
|
|
41
|
+
const myprev = anyprev?.open && anyprev.children?.length && anyprev.path === asset.path ? anyprev.children[anyprev.children.length - 1] : prev;
|
|
42
|
+
if (myprev) {
|
|
43
|
+
store.setFocus(myprev);
|
|
44
|
+
document.getElementById(hashid(myprev.id)).focus();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else if (e.key === 'ArrowLeft') {
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
e.stopPropagation();
|
|
50
|
+
if (parent) {
|
|
51
|
+
store.setFocus(parent);
|
|
52
|
+
document.getElementById(hashid(parent.id)).focus();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
<li
|
|
59
|
+
{id}
|
|
60
|
+
role="treeitem"
|
|
61
|
+
tabindex={haveFocus ? 0 : -1}
|
|
62
|
+
aria-setsize={setsize}
|
|
63
|
+
aria-posinset={posinset}
|
|
64
|
+
aria-level={level}
|
|
65
|
+
class="dialog-asset-file"
|
|
66
|
+
class:isPreview
|
|
67
|
+
on:keydown={onKeyDown}
|
|
68
|
+
on:click={() => store.preview(asset)}
|
|
69
|
+
>
|
|
70
|
+
<FileIcon mime={asset.mime} inline /> {asset.name}
|
|
71
|
+
</li>
|
|
72
|
+
|
|
73
|
+
<style>
|
|
74
|
+
li {
|
|
75
|
+
cursor: pointer;
|
|
76
|
+
}
|
|
77
|
+
</style>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { UIAsset, UIFolder, AnyUIItem } from './ChooserStore';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
asset: UIAsset;
|
|
6
|
+
level: number;
|
|
7
|
+
posinset: number;
|
|
8
|
+
setsize: number;
|
|
9
|
+
next: AnyUIItem | undefined;
|
|
10
|
+
prev: AnyUIItem | undefined;
|
|
11
|
+
parent?: UIFolder | undefined;
|
|
12
|
+
};
|
|
13
|
+
events: {
|
|
14
|
+
choose: CustomEvent<any>;
|
|
15
|
+
} & {
|
|
16
|
+
[evt: string]: CustomEvent<any>;
|
|
17
|
+
};
|
|
18
|
+
slots: {};
|
|
19
|
+
};
|
|
20
|
+
export declare type AssetProps = typeof __propDef.props;
|
|
21
|
+
export declare type AssetEvents = typeof __propDef.events;
|
|
22
|
+
export declare type AssetSlots = typeof __propDef.slots;
|
|
23
|
+
export default class Asset extends SvelteComponentTyped<AssetProps, AssetEvents, AssetSlots> {
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
<script >import folderOutline from '@iconify/icons-mdi/folder-outline.js';
|
|
2
|
+
import folderOpenOutline from '@iconify/icons-mdi/folder-open-outline.js';
|
|
3
|
+
import folderSyncOutline from '@iconify/icons-mdi/folder-sync-outline.js';
|
|
4
|
+
import { modifierKey } from '@txstate-mws/svelte-components';
|
|
5
|
+
import { createEventDispatcher, getContext } from 'svelte';
|
|
6
|
+
import { hashid } from 'txstate-utils';
|
|
7
|
+
import { ASSET_STORE_CONTEXT } from './ChooserStore';
|
|
8
|
+
import Asset from './Asset.svelte';
|
|
9
|
+
import Icon from '../Icon.svelte';
|
|
10
|
+
export let folder;
|
|
11
|
+
export let level;
|
|
12
|
+
export let posinset;
|
|
13
|
+
export let setsize;
|
|
14
|
+
export let next;
|
|
15
|
+
export let prev;
|
|
16
|
+
export let parent = undefined;
|
|
17
|
+
const store = getContext(ASSET_STORE_CONTEXT);
|
|
18
|
+
$: open = folder.open && folder.children?.length;
|
|
19
|
+
$: nextlevel = level + 1;
|
|
20
|
+
$: id = hashid(folder.id);
|
|
21
|
+
$: haveFocus = $store.focus === folder.id;
|
|
22
|
+
$: isPreview = $store.preview?.id === folder.id;
|
|
23
|
+
const dispatch = createEventDispatcher();
|
|
24
|
+
function onKeyDown(e) {
|
|
25
|
+
if (modifierKey(e))
|
|
26
|
+
return;
|
|
27
|
+
if (['Enter', ' '].includes(e.key)) {
|
|
28
|
+
onClick(e);
|
|
29
|
+
if ($store.preview?.id === folder.id)
|
|
30
|
+
dispatch('choose', folder);
|
|
31
|
+
else
|
|
32
|
+
store.preview(folder);
|
|
33
|
+
}
|
|
34
|
+
else if (e.key === 'ArrowRight') {
|
|
35
|
+
e.preventDefault();
|
|
36
|
+
e.stopPropagation();
|
|
37
|
+
if (folder.open && folder.children?.length) {
|
|
38
|
+
const child = folder.children[0];
|
|
39
|
+
store.setFocus(child);
|
|
40
|
+
document.getElementById(hashid(child.id)).focus();
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
store.open(folder);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else if (e.key === 'ArrowLeft') {
|
|
47
|
+
e.preventDefault();
|
|
48
|
+
e.stopPropagation();
|
|
49
|
+
if (folder.open) {
|
|
50
|
+
store.close(folder);
|
|
51
|
+
}
|
|
52
|
+
else if (parent) {
|
|
53
|
+
store.setFocus(parent);
|
|
54
|
+
document.getElementById(hashid(parent.id)).focus();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else if (e.key === 'ArrowDown') {
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
e.stopPropagation();
|
|
60
|
+
const mynext = open ? folder.children[0] : next;
|
|
61
|
+
if (mynext) {
|
|
62
|
+
store.setFocus(mynext);
|
|
63
|
+
document.getElementById(hashid(mynext.id)).focus();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else if (e.key === 'ArrowUp') {
|
|
67
|
+
e.preventDefault();
|
|
68
|
+
e.stopPropagation();
|
|
69
|
+
const anyprev = prev;
|
|
70
|
+
const myprev = anyprev?.open && anyprev.children?.length && anyprev.path === folder.path ? anyprev.children[anyprev.children.length - 1] : prev;
|
|
71
|
+
if (myprev) {
|
|
72
|
+
store.setFocus(myprev);
|
|
73
|
+
document.getElementById(hashid(myprev.id)).focus();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function onClick(e) {
|
|
78
|
+
e.preventDefault();
|
|
79
|
+
e.stopPropagation();
|
|
80
|
+
store.preview(folder);
|
|
81
|
+
store.toggle(folder);
|
|
82
|
+
}
|
|
83
|
+
</script>
|
|
84
|
+
|
|
85
|
+
<li
|
|
86
|
+
{id}
|
|
87
|
+
role="treeitem"
|
|
88
|
+
class:isPreview
|
|
89
|
+
aria-expanded={!!folder.open}
|
|
90
|
+
aria-level={level}
|
|
91
|
+
aria-setsize={setsize}
|
|
92
|
+
aria-posinset={posinset}
|
|
93
|
+
aria-busy={folder.loading}
|
|
94
|
+
tabindex={haveFocus ? 0 : -1}
|
|
95
|
+
on:keydown={onKeyDown}
|
|
96
|
+
on:click={onClick}
|
|
97
|
+
>
|
|
98
|
+
<Icon icon={folder.open ? folderOpenOutline : (folder.loading ? folderSyncOutline : folderOutline)} inline /> {folder.name}
|
|
99
|
+
</li>
|
|
100
|
+
{#if open}
|
|
101
|
+
<ul role="group" class="dialog-asset-sublist">
|
|
102
|
+
{#each folder.children as child, i (child.id)}
|
|
103
|
+
{@const setsize = folder.children.length}
|
|
104
|
+
{@const posinset = i + 1}
|
|
105
|
+
{@const subprev = i === 0 ? folder : folder.children[i - 1]}
|
|
106
|
+
{@const subnext = i === setsize - 1 ? next : folder.children[i + 1]}
|
|
107
|
+
{#if child.type === 'folder'}
|
|
108
|
+
<svelte:self folder={child} {setsize} {posinset} level={nextlevel} prev={subprev} next={subnext} parent={folder} on:choose />
|
|
109
|
+
{:else}
|
|
110
|
+
<Asset asset={child} {setsize} {posinset} level={nextlevel} prev={subprev} next={subnext} parent={folder} on:choose />
|
|
111
|
+
{/if}
|
|
112
|
+
{/each}
|
|
113
|
+
</ul>
|
|
114
|
+
{/if}
|
|
115
|
+
|
|
116
|
+
<style>
|
|
117
|
+
.dialog-asset-sublist {
|
|
118
|
+
list-style: none;
|
|
119
|
+
padding-left: 1em;
|
|
120
|
+
}
|
|
121
|
+
li {
|
|
122
|
+
cursor: pointer;
|
|
123
|
+
}
|
|
124
|
+
</style>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { UIFolder, AnyUIItem } from './ChooserStore';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
folder: UIFolder;
|
|
6
|
+
level: number;
|
|
7
|
+
posinset: number;
|
|
8
|
+
setsize: number;
|
|
9
|
+
next: AnyUIItem | undefined;
|
|
10
|
+
prev: AnyUIItem | undefined;
|
|
11
|
+
parent?: UIFolder | undefined;
|
|
12
|
+
};
|
|
13
|
+
events: {
|
|
14
|
+
choose: CustomEvent<any>;
|
|
15
|
+
} & {
|
|
16
|
+
[evt: string]: CustomEvent<any>;
|
|
17
|
+
};
|
|
18
|
+
slots: {};
|
|
19
|
+
};
|
|
20
|
+
export declare type AssetFolderProps = typeof __propDef.props;
|
|
21
|
+
export declare type AssetFolderEvents = typeof __propDef.events;
|
|
22
|
+
export declare type AssetFolderSlots = typeof __propDef.slots;
|
|
23
|
+
export default class AssetFolder extends SvelteComponentTyped<AssetFolderProps, AssetFolderEvents, AssetFolderSlots> {
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
<script >import fileTree from '@iconify/icons-mdi/file-tree.js';
|
|
2
|
+
import viewGrid from '@iconify/icons-mdi/view-grid.js';
|
|
3
|
+
import { Loading, Modal } from '@txstate-mws/svelte-components';
|
|
4
|
+
import { derivedStore } from '@txstate-mws/svelte-store';
|
|
5
|
+
import { createEventDispatcher, getContext, onMount, setContext } from 'svelte';
|
|
6
|
+
import { hashid, randomid } from 'txstate-utils';
|
|
7
|
+
import Asset from './Asset.svelte';
|
|
8
|
+
import AssetFolder from './AssetFolder.svelte';
|
|
9
|
+
import ButtonGroup from '../ButtonGroup.svelte';
|
|
10
|
+
import { ASSET_STORE_CONTEXT, ChooserStore } from './ChooserStore';
|
|
11
|
+
import Details from './Details.svelte';
|
|
12
|
+
import Icon from '../Icon.svelte';
|
|
13
|
+
import Page from './Page.svelte';
|
|
14
|
+
import Thumbnail from './Thumbnail.svelte';
|
|
15
|
+
import { ASSET_API_CONTEXT } from '../Form.svelte';
|
|
16
|
+
const chooserClient = getContext(ASSET_API_CONTEXT);
|
|
17
|
+
export let label = undefined;
|
|
18
|
+
export let images = false;
|
|
19
|
+
export let pages = false;
|
|
20
|
+
export let assets = images;
|
|
21
|
+
export let folders = false;
|
|
22
|
+
export let initialType = undefined;
|
|
23
|
+
export let initialSource = undefined;
|
|
24
|
+
export let initialPath = undefined;
|
|
25
|
+
export let activeSources = undefined;
|
|
26
|
+
export let store = new ChooserStore(chooserClient);
|
|
27
|
+
setContext(ASSET_STORE_CONTEXT, store);
|
|
28
|
+
$: if (!pages && !assets)
|
|
29
|
+
assets = true;
|
|
30
|
+
$: activeTypes = [...(assets ? ['asset'] : []), ...(pages ? ['page'] : [])];
|
|
31
|
+
const dispatch = createEventDispatcher();
|
|
32
|
+
const sources = derivedStore(store, v => v.sources?.[v.activetype] ?? []);
|
|
33
|
+
const source = derivedStore(store, v => store.getSource(v));
|
|
34
|
+
const preview = derivedStore(store, 'preview');
|
|
35
|
+
const chooserheadid = randomid();
|
|
36
|
+
const listid = randomid();
|
|
37
|
+
function onChoose() {
|
|
38
|
+
dispatch('change', $store.preview);
|
|
39
|
+
}
|
|
40
|
+
onMount(async () => {
|
|
41
|
+
await store.init({ activeTypes, activeSources, initialType, initialSource, initialPath, onlyImages: images, chooseFolder: folders });
|
|
42
|
+
if ($store.focus)
|
|
43
|
+
document.getElementById(hashid($store.focus))?.scrollIntoView();
|
|
44
|
+
});
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<Modal on:escape>
|
|
48
|
+
<section class="dialog-chooser-window">
|
|
49
|
+
<header>
|
|
50
|
+
<div class="dialog-chooser-controls">
|
|
51
|
+
{#if activeTypes.length > 1}
|
|
52
|
+
<ButtonGroup value={$store.activetype} choices={[{ value: 'asset', label: 'Assets' }, { value: 'page', label: 'Pages' }]} ariaControls={listid} on:change={e => store.setActiveType(e.detail)} />
|
|
53
|
+
{/if}
|
|
54
|
+
{#if $sources.length > 1}
|
|
55
|
+
<div class="dialog-chooser-source">
|
|
56
|
+
<select on:change={function () { store.changeSource(Number(this.value)) }}>
|
|
57
|
+
{#each $sources as source, i}
|
|
58
|
+
<option value={i}>{source.name}</option>
|
|
59
|
+
{/each}
|
|
60
|
+
</select>
|
|
61
|
+
</div>
|
|
62
|
+
{/if}
|
|
63
|
+
</div>
|
|
64
|
+
<div id={chooserheadid} class="dialog-chooser-label">
|
|
65
|
+
{label}
|
|
66
|
+
</div>
|
|
67
|
+
{#if $source?.type === 'asset'}
|
|
68
|
+
<div class="dialog-chooser-view">
|
|
69
|
+
<button type="button"><Icon icon={fileTree} /></button>
|
|
70
|
+
<button type="button"><Icon icon={viewGrid} /></button>
|
|
71
|
+
</div>
|
|
72
|
+
{/if}
|
|
73
|
+
</header>
|
|
74
|
+
<section class="dialog-chooser-chooser">
|
|
75
|
+
<Loading loading={!$source || !$source.children}>
|
|
76
|
+
<ul id={listid} class="dialog-chooser-list" role="tree" aria-labelledby={chooserheadid}>
|
|
77
|
+
{#each $source.children as child, i (child.id)}
|
|
78
|
+
{@const setsize = $source.children.length}
|
|
79
|
+
{@const posinset = i + 1}
|
|
80
|
+
{@const prev = $source.children[i - 1]}
|
|
81
|
+
{@const next = $source.children[i + 1]}
|
|
82
|
+
{#if child.type === 'folder'}
|
|
83
|
+
<AssetFolder folder={child} {setsize} {posinset} level={1} {prev} {next} on:choose={onChoose} />
|
|
84
|
+
{:else if child.type === 'page'}
|
|
85
|
+
<Page page={child} {setsize} {posinset} level={1} {prev} {next} on:choose={onChoose} />
|
|
86
|
+
{:else}
|
|
87
|
+
<Asset asset={child} {setsize} {posinset} level={1} {prev} {next} on:choose={onChoose} />
|
|
88
|
+
{/if}
|
|
89
|
+
{/each}
|
|
90
|
+
</ul>
|
|
91
|
+
</Loading>
|
|
92
|
+
</section>
|
|
93
|
+
<section class="dialog-chooser-preview" tabindex={$preview ? 0 : -1}>
|
|
94
|
+
{#if $preview}
|
|
95
|
+
<Thumbnail item={$preview} />
|
|
96
|
+
<Details item={$preview}>
|
|
97
|
+
{#if $preview.type === 'folder'}
|
|
98
|
+
<li>{$preview.children?.length || 0} sub-items</li>
|
|
99
|
+
{/if}
|
|
100
|
+
</Details>
|
|
101
|
+
{/if}
|
|
102
|
+
</section>
|
|
103
|
+
<footer>
|
|
104
|
+
<button type="button" on:click={() => dispatch('escape')}>Cancel</button>
|
|
105
|
+
<button type="button" disabled={!$store.preview} on:click={onChoose}>Choose</button>
|
|
106
|
+
</footer>
|
|
107
|
+
</section>
|
|
108
|
+
</Modal>
|
|
109
|
+
|
|
110
|
+
<style>
|
|
111
|
+
.dialog-chooser-window {
|
|
112
|
+
position: relative;
|
|
113
|
+
width: 80vw;
|
|
114
|
+
height: 80vh;
|
|
115
|
+
background-color: lightgray;
|
|
116
|
+
display: flex;
|
|
117
|
+
flex-wrap: wrap;
|
|
118
|
+
align-items: stretch;
|
|
119
|
+
justify-content: flex-end;
|
|
120
|
+
padding: 1em;
|
|
121
|
+
overflow: hidden;
|
|
122
|
+
}
|
|
123
|
+
.dialog-chooser-window * {
|
|
124
|
+
box-sizing: border-box;
|
|
125
|
+
}
|
|
126
|
+
.dialog-chooser-chooser {
|
|
127
|
+
position: relative;
|
|
128
|
+
width: 70%;
|
|
129
|
+
height: calc(100% - 4em);
|
|
130
|
+
background-color: white;
|
|
131
|
+
padding: 0.5em;
|
|
132
|
+
overflow: auto;
|
|
133
|
+
}
|
|
134
|
+
.dialog-chooser-preview {
|
|
135
|
+
width: 30%;
|
|
136
|
+
height: calc(100% - 4em);
|
|
137
|
+
padding: 1em;
|
|
138
|
+
overflow-y: auto;
|
|
139
|
+
}
|
|
140
|
+
header {
|
|
141
|
+
width: 100%;
|
|
142
|
+
height: 2em;
|
|
143
|
+
text-align: center;
|
|
144
|
+
font-weight: bold;
|
|
145
|
+
display: flex;
|
|
146
|
+
align-items: center;
|
|
147
|
+
}
|
|
148
|
+
.dialog-chooser-label {
|
|
149
|
+
flex-grow: 1;
|
|
150
|
+
}
|
|
151
|
+
.dialog-chooser-controls {
|
|
152
|
+
display: flex;
|
|
153
|
+
}
|
|
154
|
+
.dialog-chooser-list {
|
|
155
|
+
list-style: none;
|
|
156
|
+
padding: 0;
|
|
157
|
+
margin: 0;
|
|
158
|
+
}
|
|
159
|
+
.dialog-chooser-list :global(li) {
|
|
160
|
+
line-height: 1;
|
|
161
|
+
padding: 0.25em 0;
|
|
162
|
+
border-bottom: 1px solid var(--asset-chooser-border, #AAAAAA);
|
|
163
|
+
}
|
|
164
|
+
.dialog-chooser-list :global(.isPreview) {
|
|
165
|
+
background-color: var(--asset-chooser-active-bg, #333333);
|
|
166
|
+
color: var(--asset-chooser-active, #FFFFFF);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
</style>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { ChooserType } from './ChooserAPI';
|
|
3
|
+
import { ChooserStore } from './ChooserStore';
|
|
4
|
+
declare const __propDef: {
|
|
5
|
+
props: {
|
|
6
|
+
label?: string | undefined;
|
|
7
|
+
images?: boolean;
|
|
8
|
+
pages?: boolean;
|
|
9
|
+
assets?: boolean;
|
|
10
|
+
folders?: boolean;
|
|
11
|
+
initialType?: ChooserType | undefined;
|
|
12
|
+
initialSource?: string | undefined;
|
|
13
|
+
initialPath?: string | undefined;
|
|
14
|
+
activeSources?: string[] | undefined;
|
|
15
|
+
store?: ChooserStore;
|
|
16
|
+
};
|
|
17
|
+
events: {
|
|
18
|
+
escape: CustomEvent<any>;
|
|
19
|
+
change: CustomEvent<any>;
|
|
20
|
+
} & {
|
|
21
|
+
[evt: string]: CustomEvent<any>;
|
|
22
|
+
};
|
|
23
|
+
slots: {};
|
|
24
|
+
};
|
|
25
|
+
export declare type ChooserProps = typeof __propDef.props;
|
|
26
|
+
export declare type ChooserEvents = typeof __propDef.events;
|
|
27
|
+
export declare type ChooserSlots = typeof __propDef.slots;
|
|
28
|
+
export default class Chooser extends SvelteComponentTyped<ChooserProps, ChooserEvents, ChooserSlots> {
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export declare type ChooserType = 'asset' | 'page';
|
|
2
|
+
export declare type AnyItem = Asset | Folder | Page;
|
|
3
|
+
export interface Client {
|
|
4
|
+
getSources: (type: ChooserType) => Promise<Source[]>;
|
|
5
|
+
getChildren: (source: string, path: string, filter: (assetOrFolder: AnyItem) => boolean | Promise<boolean>) => Promise<(AnyItem)[]>;
|
|
6
|
+
find: (source: string, path: string, searchstring: string, filter: (asset: AnyItem) => boolean | Promise<boolean>) => Promise<(AnyItem)[]>;
|
|
7
|
+
findById: (id: string) => Promise<AnyItem>;
|
|
8
|
+
findByUrl?: (url: string) => Promise<AnyItem>;
|
|
9
|
+
urlToValue?: (url: string) => string;
|
|
10
|
+
upload: (source: string, path: string, files: FileList) => Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export interface Source {
|
|
13
|
+
type: ChooserType;
|
|
14
|
+
name: string;
|
|
15
|
+
rootAcceptsUpload?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface Item {
|
|
18
|
+
/**
|
|
19
|
+
* this is the identifier that will be added to the form's JSON payload
|
|
20
|
+
* when this folder is selected by the user
|
|
21
|
+
* for DosGato it will be a stringified AssetLink, AssetFolderLink, or
|
|
22
|
+
* PageLink (see dosgato-templating/src/links.ts)
|
|
23
|
+
*/
|
|
24
|
+
id: string;
|
|
25
|
+
path: string;
|
|
26
|
+
name: string;
|
|
27
|
+
}
|
|
28
|
+
export interface Folder extends Item {
|
|
29
|
+
type: 'folder';
|
|
30
|
+
acceptsUpload: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface Page extends Item {
|
|
33
|
+
type: 'page';
|
|
34
|
+
url: string;
|
|
35
|
+
title: string;
|
|
36
|
+
}
|
|
37
|
+
export interface Asset extends Item {
|
|
38
|
+
type: 'asset';
|
|
39
|
+
mime: string;
|
|
40
|
+
bytes: number;
|
|
41
|
+
url: string;
|
|
42
|
+
image?: {
|
|
43
|
+
width: number;
|
|
44
|
+
height: number;
|
|
45
|
+
thumbnailUrl?: string;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { SafeStore } from '@txstate-mws/svelte-store';
|
|
2
|
+
import type { AnyItem, Asset, Client, ChooserType, Folder, Page, Source } from './ChooserAPI.js';
|
|
3
|
+
export interface UISource extends Source {
|
|
4
|
+
children?: AnyUIItem[];
|
|
5
|
+
}
|
|
6
|
+
export interface UIFolder extends Folder {
|
|
7
|
+
children?: (UIFolder | UIAsset)[];
|
|
8
|
+
open?: boolean;
|
|
9
|
+
loading?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface UIPage extends Page {
|
|
12
|
+
children?: UIPage[];
|
|
13
|
+
open?: boolean;
|
|
14
|
+
loading?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface UIAsset extends Asset {
|
|
17
|
+
}
|
|
18
|
+
export interface RawURL {
|
|
19
|
+
type: 'raw';
|
|
20
|
+
id: string;
|
|
21
|
+
url: string;
|
|
22
|
+
}
|
|
23
|
+
export declare type AnyUIItem = UIPage | UIFolder | UIAsset;
|
|
24
|
+
export interface IAssetStore {
|
|
25
|
+
sources?: {
|
|
26
|
+
page: UISource[];
|
|
27
|
+
asset: UISource[];
|
|
28
|
+
};
|
|
29
|
+
activetype: ChooserType;
|
|
30
|
+
activesource: number;
|
|
31
|
+
preview?: AnyUIItem;
|
|
32
|
+
focus?: string;
|
|
33
|
+
focusPath?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface ChooserStoreOptions {
|
|
36
|
+
filter?: (itm: AnyItem) => boolean | Promise<boolean>;
|
|
37
|
+
activeTypes?: ChooserType[];
|
|
38
|
+
activeSources?: string[];
|
|
39
|
+
initialType?: ChooserType;
|
|
40
|
+
initialSource?: string;
|
|
41
|
+
initialPath?: string;
|
|
42
|
+
chooseFolder?: boolean;
|
|
43
|
+
onlyImages?: boolean;
|
|
44
|
+
}
|
|
45
|
+
interface InternalStoreOptions extends Omit<ChooserStoreOptions, 'activeSources'> {
|
|
46
|
+
activeSources?: Set<string>;
|
|
47
|
+
}
|
|
48
|
+
export declare const ASSET_STORE_CONTEXT: {};
|
|
49
|
+
export declare function combinePath(path: string, name: string): string;
|
|
50
|
+
export declare function bytesToHuman(bytes: number): string;
|
|
51
|
+
export declare class ChooserStore extends SafeStore<IAssetStore> {
|
|
52
|
+
client: Client;
|
|
53
|
+
options: InternalStoreOptions;
|
|
54
|
+
constructor(client: Client);
|
|
55
|
+
setOptions(options: ChooserStoreOptions): void;
|
|
56
|
+
getSource(state?: IAssetStore): UISource;
|
|
57
|
+
getSourceIndex(name: string, state?: IAssetStore, type?: ChooserType): number;
|
|
58
|
+
init(options: ChooserStoreOptions): Promise<void>;
|
|
59
|
+
itemByPath(state: IAssetStore, path: string): AnyUIItem;
|
|
60
|
+
open(folder: UIFolder | UIPage): Promise<void>;
|
|
61
|
+
openPath(path: string): Promise<void>;
|
|
62
|
+
openPathRecursive(path: string): Promise<void>;
|
|
63
|
+
close(folder: UIFolder | UIPage): Promise<void>;
|
|
64
|
+
closePath(path: string): Promise<void>;
|
|
65
|
+
toggle(folder: UIFolder | UIPage): Promise<void>;
|
|
66
|
+
preview(item?: AnyUIItem): void;
|
|
67
|
+
clearPreview(): void;
|
|
68
|
+
changeSource(idx: number): Promise<void>;
|
|
69
|
+
setActiveType(type: ChooserType): Promise<void>;
|
|
70
|
+
setFocus(itm: AnyUIItem): void;
|
|
71
|
+
}
|
|
72
|
+
export {};
|