@dosgato/dialog 0.0.30 → 0.0.31
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/FieldChooserLink.svelte +42 -12
- package/chooser/ChooserAPI.d.ts +17 -0
- package/chooser/Details.svelte +4 -2
- package/chooser/Thumbnail.svelte +1 -1
- package/package.json +1 -1
package/FieldChooserLink.svelte
CHANGED
|
@@ -20,6 +20,8 @@ export let urlEntry = false;
|
|
|
20
20
|
export let initialSource = undefined;
|
|
21
21
|
export let initialPath = undefined;
|
|
22
22
|
export let helptext = undefined;
|
|
23
|
+
// TODO: add a mime type acceptance prop, maybe a regex or function, to prevent users from
|
|
24
|
+
// choosing unacceptable mime types
|
|
23
25
|
const formStore = getContext(FORM_CONTEXT);
|
|
24
26
|
const inheritedPath = getContext(FORM_INHERITED_PATH);
|
|
25
27
|
const finalPath = [inheritedPath, path].filter(isNotBlank).join('.');
|
|
@@ -45,19 +47,47 @@ function onChange(setVal) {
|
|
|
45
47
|
}
|
|
46
48
|
async function userUrlEntry() {
|
|
47
49
|
const url = this.value;
|
|
50
|
+
store.clearPreview();
|
|
51
|
+
let found = false;
|
|
48
52
|
if (chooserClient.findByUrl) {
|
|
49
53
|
const item = await chooserClient.findByUrl(url);
|
|
50
|
-
if (item)
|
|
51
|
-
|
|
54
|
+
if (item) {
|
|
55
|
+
found = true;
|
|
56
|
+
if ((item.type === 'page' && !pages) || // they typed the URL for a page but we don't allow pages right now
|
|
57
|
+
(item.type === 'folder' && !folders) || // they typed the URL for an asset folder but not allowed
|
|
58
|
+
(item.type === 'asset' && !assets) || // they typed the URL for an asset but not allowed
|
|
59
|
+
(item.type === 'asset' && !item.image && images) // they typed the URL for a non-image asset but we only want images
|
|
60
|
+
) {
|
|
61
|
+
selectedAsset = {
|
|
62
|
+
type: 'raw',
|
|
63
|
+
id: undefined,
|
|
64
|
+
url
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
selectedAsset = { ...item, url };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
52
71
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
72
|
+
if (!found) {
|
|
73
|
+
try {
|
|
74
|
+
const _ = new URL(url);
|
|
75
|
+
const newVal = chooserClient.urlToValue?.(url) ?? url;
|
|
76
|
+
selectedAsset = {
|
|
77
|
+
type: 'raw',
|
|
78
|
+
id: newVal,
|
|
79
|
+
url
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
selectedAsset = {
|
|
84
|
+
type: 'raw',
|
|
85
|
+
id: undefined,
|
|
86
|
+
url
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
formStore.setField(finalPath, selectedAsset?.id);
|
|
61
91
|
formStore.dirtyField(finalPath);
|
|
62
92
|
}
|
|
63
93
|
let selectedAsset;
|
|
@@ -76,8 +106,8 @@ $: updateSelected($value);
|
|
|
76
106
|
</div>
|
|
77
107
|
{/if}
|
|
78
108
|
<div class="dialog-chooser-entry">
|
|
79
|
-
{#if urlEntry
|
|
80
|
-
<input type="text" value={selectedAsset?.url ?? ''} on:change={userUrlEntry}>
|
|
109
|
+
{#if urlEntry}
|
|
110
|
+
<input type="text" value={selectedAsset?.url ?? ''} on:change={userUrlEntry} on:keyup={userUrlEntry}>
|
|
81
111
|
{/if}
|
|
82
112
|
<button type="button" on:click={show} aria-describedby={getDescribedBy([descid, messagesid, helptextid])}>Select {#if value}New{/if} {#if assets && pages}Link Target{:else if images}Image{:else if assets}Asset{:else}Page{/if}</button>
|
|
83
113
|
</div>
|
package/chooser/ChooserAPI.d.ts
CHANGED
|
@@ -30,11 +30,28 @@ interface Item {
|
|
|
30
30
|
path: string;
|
|
31
31
|
name: string;
|
|
32
32
|
source: string;
|
|
33
|
+
/**
|
|
34
|
+
* Identifier for the urlEntry input
|
|
35
|
+
*
|
|
36
|
+
* When urlEntry prop is true, the user gets a text field where they can freely
|
|
37
|
+
* enter a string to identify the object being chosen. This value will be
|
|
38
|
+
* placed in that field when they use the chooser.
|
|
39
|
+
*
|
|
40
|
+
* It should be reversible with the `findByUrl` function provided by your chooser
|
|
41
|
+
* client, but note that the `findByUrl` function can accept multiple URLs that
|
|
42
|
+
* all point to the same resource. If the user types anything that can identify
|
|
43
|
+
* a resource, the resource will show up in the "Details" area, but the URL the user
|
|
44
|
+
* typed will NOT change to the one provided by this property. We try not
|
|
45
|
+
* to rewrite values in the form fields where possible, because it can disrupt the
|
|
46
|
+
* user's interaction.
|
|
47
|
+
*/
|
|
48
|
+
url: string;
|
|
33
49
|
}
|
|
34
50
|
export interface Folder extends Item {
|
|
35
51
|
type: 'folder';
|
|
36
52
|
hasChildren: boolean;
|
|
37
53
|
acceptsUpload: boolean;
|
|
54
|
+
url: string;
|
|
38
55
|
}
|
|
39
56
|
export interface Page extends Item {
|
|
40
57
|
type: 'page';
|
package/chooser/Details.svelte
CHANGED
|
@@ -4,11 +4,13 @@ export let item;
|
|
|
4
4
|
|
|
5
5
|
<ul class="dialog-chooser-info" aria-live="polite">
|
|
6
6
|
{#if item.type !== 'raw'}
|
|
7
|
-
<li>{item.
|
|
7
|
+
<li>{item.path}</li>
|
|
8
|
+
{:else if item.id}
|
|
9
|
+
<li>External Link<br>{item.url}</li>
|
|
8
10
|
{/if}
|
|
9
11
|
{#if item.type === 'asset' && item.image}
|
|
10
12
|
<li>{item.image.width}x{item.image.height}</li>
|
|
11
|
-
{:else if item.type === 'page'}
|
|
13
|
+
{:else if item.type === 'page' && item.title}
|
|
12
14
|
<li>{item.title}</li>
|
|
13
15
|
{:else if item.type === 'folder'}
|
|
14
16
|
<li>{item.path}</li>
|
package/chooser/Thumbnail.svelte
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dosgato/dialog",
|
|
3
3
|
"description": "A component library for building forms that edit a JSON document.",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.31",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@txstate-mws/svelte-components": "^1.3.5",
|
|
7
7
|
"@txstate-mws/svelte-forms": "^1.2.1",
|