|
1 | 1 | <script> |
2 | 2 | import logger from "@patternslib/patternslib/src/core/logging"; |
3 | 3 | import { getContext } from "svelte"; |
| 4 | + import { get } from "svelte/store"; |
4 | 5 | import ContentBrowser from "./ContentBrowser.svelte"; |
5 | 6 | import SelectedItems from "./SelectedItems.svelte"; |
6 | 7 | import { |
|
13 | 14 | setShowContentBrowser, |
14 | 15 | } from "./stores"; |
15 | 16 |
|
16 | | - export let maxDepth; |
17 | | - export let width; |
18 | | - export let attributes; |
19 | | - export let contextPath; |
20 | | - export let vocabularyUrl; |
21 | | - export let mode = "browse"; |
22 | | - export let layout = "list"; |
23 | | - export let rootPath = ""; |
24 | | - export let rootUrl = ""; |
25 | | - export let basePath = ""; |
26 | | - export let selectableTypes = []; |
27 | | - export let browseableTypes = []; |
28 | | - export let searchIndex = "SearchableText"; |
29 | | - export let maximumSelectionSize = -1; |
30 | | - export let separator; |
31 | | - export let selection = []; |
32 | | - export let query = {}; |
33 | | - export let fieldId; |
34 | | - export let upload; |
35 | | - export let uploadAddImmediately = true; |
36 | | - export let uploadAcceptedMimetypes; |
37 | | - export let favorites; |
38 | | - export let recentlyUsed; |
39 | | - export let recentlyUsedKey; |
40 | | - export let recentlyUsedMaxItems; |
41 | | - export let bSize = 20; |
42 | | - export let sortOn = "sortable_title"; |
43 | | - export let sortOrder = "ascending"; |
44 | | - export let componentRegistryKeys = {}; |
| 17 | + let { |
| 18 | + maxDepth, |
| 19 | + width, |
| 20 | + attributes, |
| 21 | + contextPath: contextPathProp, |
| 22 | + vocabularyUrl, |
| 23 | + mode = "browse", |
| 24 | + layout = "list", |
| 25 | + rootPath: rootPathProp = "", |
| 26 | + rootUrl = "", |
| 27 | + basePath = "", |
| 28 | + selectableTypes = [], |
| 29 | + browseableTypes = [], |
| 30 | + searchIndex = "SearchableText", |
| 31 | + maximumSelectionSize = -1, |
| 32 | + separator, |
| 33 | + selection = [], |
| 34 | + query = {}, |
| 35 | + fieldId, |
| 36 | + upload, |
| 37 | + uploadAddImmediately = true, |
| 38 | + uploadAcceptedMimetypes, |
| 39 | + favorites, |
| 40 | + recentlyUsed, |
| 41 | + recentlyUsedKey, |
| 42 | + recentlyUsedMaxItems, |
| 43 | + bSize = 20, |
| 44 | + sortOn = "sortable_title", |
| 45 | + sortOrder = "ascending", |
| 46 | + componentRegistryKeys = {}, |
| 47 | + } = $props(); |
| 48 | +
|
| 49 | + // Local mutable copies of the two props that may be reassigned locally |
| 50 | + let rootPath = $state(rootPathProp); |
| 51 | + let contextPath = $state(contextPathProp); |
45 | 52 |
|
46 | 53 | const log = logger.getLogger("pat-contentbrowser"); |
47 | 54 |
|
|
57 | 64 | // initially set current path |
58 | 65 | const currentPath = getContext("currentPath"); |
59 | 66 |
|
60 | | - if (!$currentPath) { |
| 67 | + if (!get(currentPath)) { |
| 68 | + let initialPath = ""; |
61 | 69 | if (basePath || rootPath) { |
62 | 70 | // if root path is not above base path we start at rootPath |
63 | | - $currentPath = basePath.indexOf(rootPath) != 0 ? rootPath : basePath; |
| 71 | + initialPath = basePath.indexOf(rootPath) != 0 ? rootPath : basePath; |
64 | 72 | if ( |
65 | 73 | rootPath && |
66 | | - $currentPath != rootPath && |
67 | | - $currentPath.indexOf(rootPath) == 0 |
| 74 | + initialPath != rootPath && |
| 75 | + initialPath.indexOf(rootPath) == 0 |
68 | 76 | ) { |
69 | 77 | // remove rootPath from $currentPath |
70 | | - $currentPath = $currentPath.replace(rootPath, ""); |
| 78 | + initialPath = initialPath.replace(rootPath, ""); |
71 | 79 | } |
72 | 80 | } else { |
73 | 81 | // no path available. try to determine path from vocabularyUrl |
74 | 82 | const vocabPath = new URL(vocabularyUrl).pathname.split("/"); |
75 | | - rootPath = |
| 83 | + initialPath = |
| 84 | + rootPath = |
76 | 85 | contextPath = |
77 | | - $currentPath = |
78 | 86 | vocabPath.slice(0, vocabPath.length - 1).join("/") || "/"; |
79 | 87 | } |
| 88 | + currentPath.set(initialPath); |
80 | 89 | } |
81 | 90 |
|
82 | | - let config = getContext("config"); |
83 | | - $config = { |
| 91 | + const config = getContext("config"); |
| 92 | + config.set({ |
84 | 93 | mode: mode, |
85 | 94 | layout: layout, |
86 | 95 | attributes: attributes, |
|
110 | 119 | sortOn: sortOn, |
111 | 120 | sortOrder: sortOrder, |
112 | 121 | componentRegistryKeys: componentRegistryKeys, |
113 | | - }; |
| 122 | + }); |
114 | 123 |
|
115 | | - log.debug(`Initialized App<${fieldId}> with config`, $config); |
| 124 | + log.debug(`Initialized App<${fieldId}> with config`, config); |
116 | 125 | </script> |
117 | 126 |
|
118 | 127 | <ContentBrowser /> |
|
0 commit comments