-
-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pat-contentbrowser
component registry
#1396
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
572ccff
feat(pat contentbrowser): Register components with "@plone/registry"
petschki 8214023
fix empty href
petschki b4ebd4c
some updates to registered component
petschki 2b2945d
Fix loading external registered components using a wrapper function
petschki 6cf87d3
implement option to make components overridable with pattern_options
petschki 2a59d3b
update README
petschki 7c6eca4
refactor registering default components
petschki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
"@11ty/eleventy-upgrade-help": "2", | ||
"@patternslib/pat-code-editor": "4.0.1", | ||
"@patternslib/patternslib": "9.9.16", | ||
"@plone/registry": "^1.7.0", | ||
"@plone/registry": "^2.1.0", | ||
"backbone": "1.4.1", | ||
"backbone.paginator": "2.0.8", | ||
"bootstrap": "5.3.3", | ||
|
@@ -134,5 +134,6 @@ | |
], | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
}, | ||
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<script> | ||
import { getContext } from "svelte"; | ||
import { resolveIcon } from "./utils"; | ||
|
||
// current item index of parent iteration | ||
export let idx; | ||
// item data | ||
export let item; | ||
|
||
// parent method to remove selected item from list | ||
const unselectItem = getContext("unselectItem"); | ||
|
||
</script> | ||
|
||
<div class="selected-item border border-secondary-subtle rounded p-2 mb-1 bg-body-tertiary" data-uuid={item.UID}> | ||
<div class="item-info"> | ||
<!-- svelte-ignore a11y-missing-attribute --> | ||
<button | ||
class="btn btn-link btn-sm link-secondary" | ||
on:click={() => unselectItem(idx)} | ||
><svg use:resolveIcon={{ iconName: "x-circle" }} /></button | ||
> | ||
<div> | ||
<span class="item-title">{item.Title}</span><br /> | ||
<span class="small">{item.path}</span> | ||
</div> | ||
</div> | ||
{#if item.getURL && (item.getIcon || item.portal_type === "Image")}<img | ||
src="{item.getURL}/@@images/image/mini" | ||
alt={item.Title} | ||
/>{/if} | ||
</div> | ||
|
||
<style> | ||
.selected-item { | ||
display: flex; | ||
flex-wrap: nowrap; | ||
align-items: start; | ||
justify-content: space-between; | ||
cursor: move; | ||
} | ||
.selected-item > * { | ||
margin-right: 0.5rem; | ||
display: block; | ||
} | ||
.selected-item button { | ||
cursor: pointer; | ||
padding: 0 0.375rem 0.374rem 0; | ||
} | ||
.selected-item .item-info { | ||
display: flex; | ||
align-items: start; | ||
} | ||
.selected-item > img { | ||
object-fit: cover; | ||
width: 95px; | ||
height: 95px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,10 +1,10 @@ | ||||||||||||||
<script> | ||||||||||||||
import { getContext, onMount } from "svelte"; | ||||||||||||||
import { flip } from "svelte/animate"; | ||||||||||||||
import { get_items_from_uids, resolveIcon } from "./utils.js"; | ||||||||||||||
import { getContext, onMount, setContext } from "svelte"; | ||||||||||||||
import { get_items_from_uids } from "./utils.js"; | ||||||||||||||
import Sortable from "sortablejs"; | ||||||||||||||
import _t from "../../../core/i18n-wrapper"; | ||||||||||||||
import events from "@patternslib/patternslib/src/core/events"; | ||||||||||||||
import plone_registry from "@plone/registry"; | ||||||||||||||
|
||||||||||||||
let ref; | ||||||||||||||
let initializing = true; | ||||||||||||||
|
@@ -21,6 +21,13 @@ | |||||||||||||
// showContentBrowser reactive state | ||||||||||||||
const showContentBrowser = getContext("showContentBrowser"); | ||||||||||||||
|
||||||||||||||
// get selectedItem component from registry. | ||||||||||||||
// the registry key can be customized with pattern_options | ||||||||||||||
// if an addon registers a custom component to a custom key | ||||||||||||||
const RegisteredSelectedItem = plone_registry.getComponent( | ||||||||||||||
$config.componentRegistryKeys?.selectedItem || "pat-contentbrowser.SelectedItem" | ||||||||||||||
); | ||||||||||||||
|
||||||||||||||
onMount(async () => { | ||||||||||||||
await initializeSelectedItemsStore(); | ||||||||||||||
initializeSorting(); | ||||||||||||||
|
@@ -35,6 +42,10 @@ | |||||||||||||
selectedUids.update(() => $selectedItems.map((x) => x.UID)); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// use this function in "SelectedItem" component with | ||||||||||||||
// const unselectItem = getContext("unselectItem") | ||||||||||||||
setContext("unselectItem", unselectItem); | ||||||||||||||
|
||||||||||||||
async function initializeSelectedItemsStore() { | ||||||||||||||
const initialValue = $config.selection.length | ||||||||||||||
? $config.selection | ||||||||||||||
|
@@ -85,6 +96,10 @@ | |||||||||||||
selectedItemsNode.dispatchEvent(events.change_event()); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
function LoadSelectedItemComponent(node, props) { | ||||||||||||||
const component = new RegisteredSelectedItem.component({target: node, props: props}); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
NOTE: untested pseudo code |
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
$: { | ||||||||||||||
$selectedItems; | ||||||||||||||
if ($selectedItems.length || !initializing) { | ||||||||||||||
|
@@ -105,27 +120,7 @@ | |||||||||||||
on:click={() => $showContentBrowser = $selectedItems.length ? false : true }> | ||||||||||||||
{#if $selectedItems} | ||||||||||||||
{#each $selectedItems as selItem, i (selItem.UID)} | ||||||||||||||
<div | ||||||||||||||
class="selected-item" | ||||||||||||||
animate:flip={{ duration: 500 }} | ||||||||||||||
data-uuid={selItem.UID} | ||||||||||||||
> | ||||||||||||||
<div class="item-info"> | ||||||||||||||
<button | ||||||||||||||
class="btn btn-link btn-sm link-secondary" | ||||||||||||||
on:click|stopPropagation={() => unselectItem(i)} | ||||||||||||||
><svg use:resolveIcon={{ iconName: "x-circle" }} /></button | ||||||||||||||
> | ||||||||||||||
<div> | ||||||||||||||
<span class="item-title">{selItem.Title}</span><br /> | ||||||||||||||
<span class="small">{selItem.path}</span> | ||||||||||||||
</div> | ||||||||||||||
</div> | ||||||||||||||
{#if selItem.getURL && (selItem.getIcon || selItem.portal_type === "Image")}<img | ||||||||||||||
src="{selItem.getURL}/@@images/image/mini" | ||||||||||||||
alt={selItem.Title} | ||||||||||||||
/>{/if} | ||||||||||||||
</div> | ||||||||||||||
<div use:LoadSelectedItemComponent={{idx:i, item:selItem}} /> | ||||||||||||||
{/each} | ||||||||||||||
{/if} | ||||||||||||||
{#if !$selectedItems} | ||||||||||||||
|
@@ -155,33 +150,4 @@ | |||||||||||||
padding: 0.5rem 0.5rem 0 0.5rem; | ||||||||||||||
flex: 1 1 auto; | ||||||||||||||
} | ||||||||||||||
.content-browser-selected-items .selected-item { | ||||||||||||||
border-radius: var(--bs-border-radius); | ||||||||||||||
background-color: var(--bs-tertiary-bg); | ||||||||||||||
border: var(--bs-border-style) var(--bs-border-color) var(--bs-border-width); | ||||||||||||||
padding: 0.5rem; | ||||||||||||||
margin-bottom: 0.5rem; | ||||||||||||||
display: flex; | ||||||||||||||
flex-wrap: nowrap; | ||||||||||||||
align-items: start; | ||||||||||||||
justify-content: space-between; | ||||||||||||||
cursor: move; | ||||||||||||||
} | ||||||||||||||
.content-browser-selected-items .selected-item > * { | ||||||||||||||
margin-right: 0.5rem; | ||||||||||||||
display: block; | ||||||||||||||
} | ||||||||||||||
.content-browser-selected-items .selected-item button { | ||||||||||||||
cursor: pointer; | ||||||||||||||
padding: 0 0.375rem 0.374rem 0; | ||||||||||||||
} | ||||||||||||||
.content-browser-selected-items .selected-item .item-info { | ||||||||||||||
display: flex; | ||||||||||||||
align-items: start; | ||||||||||||||
} | ||||||||||||||
.content-browser-selected-items .selected-item > img { | ||||||||||||||
object-fit: cover; | ||||||||||||||
width: 95px; | ||||||||||||||
height: 95px; | ||||||||||||||
} | ||||||||||||||
</style> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@petschki @MrTango Regarding the custom component keys - isn't
selectedItem
the only component key which is supported yet?I'm a bit restrained to use JSON structures as pattern options - especially JSON objects. Until now I had the impression that JSON objects prevent us from using the Patterns options parser and thus prevent us currently from using the BasePattern (that can be fixed).
But your PR here shows that this is not entirely true - You're using both the Patterns Parser and BasePattern here. However, at least the
customComponentKeys
is currently not formally defined in the Patterns Parser.I'd have maybe made a flat single option out for the selectedItem component. Something like
selectedItemComponent
. Then we can use Patternslib CSS style Pattern option definition likedata-pat-contentbrowser="selectedItemComponent: my-component;"
.But since this seems to work fine, all is good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes it is for now, but the idea is to make more components customizable, like the previewColumn (last clicked item) or the toolbar above, or the column itself to tweak the column listings etc ... this is not very complicated, because those are already components inside the pattern ... we only need to implement the corresponding options and then call the customizations instead of the default ones... but this could also be implemented as "flat" options like you suggested ... I'm fine with that.