@dosgato/dialog 0.0.53 → 0.0.54

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.
@@ -34,7 +34,7 @@ const store = new ChooserStore(chooserClient);
34
34
  const descid = randomid();
35
35
  let modalshown = false;
36
36
  async function show() {
37
- if (selectedAsset && selectedAsset.type !== 'raw')
37
+ if (selectedAsset && selectedAsset.type !== 'raw' && selectedAsset.type !== 'broken')
38
38
  store.setPreview(selectedAsset);
39
39
  modalshown = true;
40
40
  }
@@ -84,27 +84,23 @@ async function userUrlEntryDebounced() {
84
84
  }
85
85
  if (!found) {
86
86
  try {
87
- const _ = new URL(url);
88
87
  selectedAsset = {
89
88
  type: 'raw',
90
- id: chooserClient.urlToValue?.(url) ?? url,
89
+ id: urlToValueCache[url] ?? chooserClient.urlToValue?.(new URL(url).toString()),
91
90
  url
92
91
  };
93
92
  }
94
- catch (e) {
93
+ catch {
95
94
  // here we "select" a raw url so that we do not interrupt the users' typing, but
96
95
  // we set its id to 'undefined' so that nothing makes it into the form until it's
97
96
  // a valid URL
98
- selectedAsset = {
99
- type: 'raw',
100
- id: undefined,
101
- url
102
- };
97
+ selectedAsset = { type: 'raw', url, id: undefined };
103
98
  }
104
99
  }
105
100
  formStore.setField(finalPath, selectedAsset?.id);
106
101
  formStore.dirtyField(finalPath);
107
102
  }
103
+ const urlToValueCache = {};
108
104
  async function updateSelected(..._) {
109
105
  if ($value && selectedAsset?.id !== $value) {
110
106
  const valueBeforeFind = $value;
@@ -113,8 +109,16 @@ async function updateSelected(..._) {
113
109
  return;
114
110
  selectedAsset = asset;
115
111
  try {
116
- if (!selectedAsset)
117
- selectedAsset = { type: 'raw', id: $value, url: chooserClient.valueToUrl?.($value) ?? $value };
112
+ if (!selectedAsset) {
113
+ const urlFromValue = chooserClient.valueToUrl?.($value) ?? $value;
114
+ try {
115
+ selectedAsset = { type: 'raw', id: $value, url: new URL(urlFromValue).toString() };
116
+ }
117
+ catch {
118
+ selectedAsset = { type: 'broken', id: $value, url: $value };
119
+ }
120
+ }
121
+ urlToValueCache[selectedAsset.url] = $value;
118
122
  }
119
123
  catch (e) {
120
124
  console.error(e);
@@ -1,5 +1,5 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import { type RawURL } from './chooser';
2
+ import { type BrokenURL, type RawURL } from './chooser';
3
3
  import type { AnyItem } from './chooser/ChooserAPI';
4
4
  declare const __propDef: {
5
5
  props: {
@@ -19,7 +19,7 @@ declare const __propDef: {
19
19
  related?: number | true | undefined;
20
20
  extradescid?: string | undefined;
21
21
  helptext?: string | undefined;
22
- selectedAsset?: AnyItem | RawURL | undefined;
22
+ selectedAsset?: AnyItem | RawURL | BrokenURL | undefined;
23
23
  };
24
24
  events: {
25
25
  [evt: string]: CustomEvent<any>;
@@ -9,11 +9,22 @@ export interface Client<F = any> {
9
9
  findByUrl?: (url: string) => Promise<AnyItem | undefined>;
10
10
  urlToValue?: (url: string) => string;
11
11
  /**
12
- * If the form is preloaded with a raw URL, findById returns undefined, and the client implements
13
- * urlToValue, we will need a way to decode/reverse what urlToValue does. This function should
14
- * do that.
12
+ * If the form is preloaded with an id for which findById returns undefined (e.g. it's a raw URL or
13
+ * an id that points at a temporarily unavailable resource), we need to show something in
14
+ * the urlEntry field to signify that there is a value we are keeping around. This function
15
+ * should do that as well as it can based on the id passed to it.
16
+ *
17
+ * For instance, if the id looks like an asset, valueToUrl could return /.assets/{id}, which
18
+ * would communicate to the user that an asset is currently selected, even though they can't see
19
+ * its preview at the moment. If they save the form, their selection will be preserved in case
20
+ * the resource comes back at some point (or maybe they just didn't have permission to see it).
21
+ *
22
+ * If the id means nothing you can return undefined and the input will show it directly.
23
+ *
24
+ * Note: If urlToValue was provided, at minimum this function should be able to recognize and
25
+ * undo values it generates.
15
26
  */
16
- valueToUrl?: (value: string) => string;
27
+ valueToUrl?: (value: string) => string | undefined;
17
28
  upload: (source: string, path: string, files: FileList) => Promise<void>;
18
29
  }
19
30
  export interface Source {
@@ -77,6 +88,7 @@ export interface Asset extends Item {
77
88
  height: number;
78
89
  thumbnailUrl?: string;
79
90
  previewUrl?: string;
91
+ tinyUrl?: string;
80
92
  };
81
93
  }
82
94
  export {};
@@ -9,6 +9,11 @@ export interface RawURL {
9
9
  id: string | undefined;
10
10
  url: string;
11
11
  }
12
+ export interface BrokenURL {
13
+ type: 'broken';
14
+ id: string;
15
+ url: string;
16
+ }
12
17
  export type AnyUIItem = TypedTreeItem<Page | Asset | Folder>;
13
18
  export interface IAssetStore {
14
19
  sources?: {
@@ -3,16 +3,21 @@ export let item;
3
3
  </script>
4
4
 
5
5
  <dl class="dialog-chooser-info" aria-live="polite">
6
- {#if item.type !== 'raw'}
7
- <div class="top-row">
8
- <dt>Name:</dt>
9
- <dd>{item.path}</dd>
10
- </div>
11
- {:else if item.id}
6
+ {#if item.type === 'raw' && item.id}
12
7
  <div>
13
8
  <dt>External Link:</dt>
14
9
  <dd>{item.url}</dd>
15
10
  </div>
11
+ {:else if item.type === 'broken'}
12
+ <div>
13
+ <dt>Unknown Link (this resource may have been deleted):</dt>
14
+ <dd>{item.url}</dd>
15
+ </div>
16
+ {:else if item.type !== 'raw'}
17
+ <div class="top-row">
18
+ <dt>Name:</dt>
19
+ <dd>{item.path}</dd>
20
+ </div>
16
21
  {/if}
17
22
  {#if item.type === 'asset'}
18
23
  <div class="horizontal-group">
@@ -1,9 +1,9 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  import type { AnyItem } from './ChooserAPI';
3
- import { type RawURL } from './ChooserStore';
3
+ import { type BrokenURL, type RawURL } from './ChooserStore';
4
4
  declare const __propDef: {
5
5
  props: {
6
- item: AnyItem | RawURL;
6
+ item: AnyItem | RawURL | BrokenURL;
7
7
  };
8
8
  events: {
9
9
  [evt: string]: CustomEvent<any>;
@@ -1,9 +1,9 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  import type { AnyItem } from './ChooserAPI';
3
- import type { RawURL } from './ChooserStore';
3
+ import type { BrokenURL, RawURL } from './ChooserStore';
4
4
  declare const __propDef: {
5
5
  props: {
6
- item: AnyItem | RawURL;
6
+ item: AnyItem | RawURL | BrokenURL;
7
7
  larger?: boolean | undefined;
8
8
  };
9
9
  events: {
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.53",
4
+ "version": "0.0.54",
5
5
  "scripts": {
6
6
  "prepublishOnly": "svelte-package",
7
7
  "dev": "vite dev --force",