Skip to content

Commit c49fdd0

Browse files
committed
Merge branch 'seven' into image-alignment
2 parents f3323ec + d8a9ff1 commit c49fdd0

13 files changed

Lines changed: 42 additions & 32 deletions

File tree

packages/blocks/Teaser/schema.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ export function TeaserSchema({
2323
href: {
2424
title: 'Target',
2525
widget: 'object_browser',
26-
mode: 'link',
26+
mode: 'single',
2727
selectedItemAttrs: [
28+
'@id',
2829
'Title',
2930
'title',
3031
'Description',
@@ -59,7 +60,7 @@ export function TeaserSchema({
5960
widget: 'object_browser',
6061
mode: 'image',
6162
allowExternals: true,
62-
selectedItemAttrs: ['image_field', 'image_scales'],
63+
selectedItemAttrs: ['@id', 'image_field', 'image_scales'],
6364
},
6465
openLinkInNewTab: {
6566
title: 'Open in a new tab',
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix Teaser block object browser configuration: the target field now uses single selection mode, and the required item identifier is included in the selected attributes for both the target and image fields. @iFlameing

packages/cmsui/components/ContentForm/ContentForm.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,12 @@ export default function ContentForm({
153153
<Checkbox />
154154
</button>
155155
</Plug>
156-
<Plug pluggable="toolbar-top" id="button-cancel">
157-
<Link aria-label="Cancel" href="/">
156+
<Plug
157+
pluggable="toolbar-top"
158+
id="button-cancel"
159+
dependencies={[content['@id']] as any}
160+
>
161+
<Link aria-label="Cancel" href={content['@id']}>
158162
<Close />
159163
</Link>
160164
</Plug>

packages/cmsui/components/ImageWidget/ImageWidget.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ function ImageInputBase({
389389
<ObjectBrowserProvider
390390
config={{
391391
mode: objectBrowserMode,
392-
selectedAttrs: ['@id', 'title'],
392+
selectedItemAttrs: ['@id', 'title'],
393393
onChange: onSelectInternalImage,
394394
initialPath: resolvedCurrentPath,
395395
title: 'Pick an existing image',

packages/cmsui/components/ObjectBrowserWidget/ObjectBrowserContext.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export interface UseObjectBrowserConfig {
3737
widgetOptions?: {
3838
pattern_options?: PatternOptions;
3939
};
40-
selectedAttrs?: Array<keyof Brain>;
40+
selectedItemAttrs?: Array<keyof Brain>;
4141
// TODO: Also add blockchange/slate signature compat
4242
onChange?: (selected: Partial<Brain>[]) => void;
4343
defaultValue?: Brain[];
@@ -50,7 +50,7 @@ const useObjectBrowserInternal = (config: UseObjectBrowserConfig = {}) => {
5050
const {
5151
mode = 'multiple',
5252
widgetOptions = {},
53-
selectedAttrs = ['@id', 'title', 'description', '@type', 'UID'],
53+
selectedItemAttrs = ['@id', 'title', 'description', '@type', 'UID'],
5454
onChange,
5555
defaultValue = [],
5656
title,
@@ -72,13 +72,13 @@ const useObjectBrowserInternal = (config: UseObjectBrowserConfig = {}) => {
7272
return brains.map(
7373
(item) =>
7474
Object.fromEntries(
75-
selectedAttrs
75+
selectedItemAttrs
7676
.filter((attr) => attr in item)
7777
.map((attr) => [attr, item[attr]]),
7878
) as Partial<Brain>,
7979
);
8080
},
81-
[selectedAttrs],
81+
[selectedItemAttrs],
8282
);
8383

8484
const handleSelectionChange = useCallback(
@@ -184,7 +184,7 @@ const useObjectBrowserInternal = (config: UseObjectBrowserConfig = {}) => {
184184

185185
// Config
186186
mode,
187-
selectedAttrs,
187+
selectedItemAttrs,
188188
title,
189189
widgetOptions,
190190
};

packages/cmsui/components/ObjectBrowserWidget/ObjectBrowserWidgetBody.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export function ObjectBrowserWidgetBody() {
5454
}, [currentPath, loading, items]);
5555

5656
const handleNavigation = (item: Brain) => {
57+
if (!item.is_folderish) return;
5758
navigateTo(item['@id']);
5859
setSearchMode(false);
5960
};
@@ -142,10 +143,11 @@ export function ObjectBrowserWidgetBody() {
142143
count: items?.length ?? 0,
143144
})}`}
144145
key={`${viewMode}-${currentPath}`} // Force re-render on viewMode or path change
145-
selectionMode={'multiple'}
146+
selectionMode={mode === 'single' ? 'single' : 'multiple'}
146147
disabledBehavior="selection"
147148
escapeKeyBehavior="none"
148-
selectionBehavior={'toggle'}
149+
selectionBehavior={mode === 'single' ? 'replace' : 'toggle'}
150+
dependencies={[selectedItems]}
149151
items={items ?? []}
150152
layout={viewMode ? 'grid' : 'stack'}
151153
// Todo: better styling
@@ -181,15 +183,10 @@ export function ObjectBrowserWidgetBody() {
181183
}
182184
>
183185
{(item) => {
184-
// Convert selectedItems IDs to actual Brain objects for isSelectable
185-
const selectedItemObjects = selectedItems
186-
.map((id) => items?.find((item) => item['@id'] === id))
187-
.filter(Boolean) as Brain[];
188-
189186
const disabled = !isSelectable(item, {
190187
...widgetOptions,
191188
mode,
192-
items: selectedItemObjects,
189+
selectedItemIds: selectedItems,
193190
});
194191
const isSelected = selectedItems.includes(item['@id']);
195192
const reviewState = item.review_state || undefined;
@@ -200,7 +197,9 @@ export function ObjectBrowserWidgetBody() {
200197
textValue={getItemLabel(t, item, isSelected, disabled)}
201198
aria-label={getItemLabel(t, item, isSelected, disabled)}
202199
data-selectable={!disabled}
203-
onAction={() => handleNavigation(item)}
200+
onAction={
201+
mode !== 'single' ? () => handleNavigation(item) : undefined
202+
}
204203
isDisabled={disabled}
205204
className={itemVariants({
206205
viewMode: viewMode ? 'grid' : 'list',

packages/cmsui/components/ObjectBrowserWidget/utils.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export type WidgetPatternOptions = {
3131
selectableTypes?: Content['@type'][];
3232
[key: string]: any;
3333
};
34-
items: PartialBrainWithRequired[];
34+
selectedItemIds: string[];
3535
mode: ObjectBrowserWidgetMode;
3636
};
3737

@@ -96,7 +96,7 @@ const isSelectable = (
9696
item: PartialBrainWithRequired,
9797
options: WidgetPatternOptions,
9898
) => {
99-
const { pattern_options, items } = options;
99+
const { pattern_options, selectedItemIds, mode } = options;
100100
const { maximumSelectionSize, selectableTypes } = pattern_options || {
101101
maximumSelectionSize: undefined,
102102
selectableTypes: [],
@@ -111,10 +111,14 @@ const isSelectable = (
111111
return false;
112112
}
113113

114-
// Second check: respect maximum selection limit
115-
if (maximumSelectionSize && items && maximumSelectionSize <= items.length) {
114+
// Second check: respect maximum selection limit (multiple mode only)
115+
if (
116+
isMultipleMode(mode) &&
117+
maximumSelectionSize &&
118+
maximumSelectionSize <= selectedItemIds.length
119+
) {
116120
// At limit: only already selected items are selectable (for deselection)
117-
return items.some((i) => i['@id'] === item['@id']);
121+
return selectedItemIds.includes(item['@id']);
118122
}
119123

120124
// All checks passed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix toolbar cancel button navigating to site root instead of current content page. @iFlameing
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix several issues in the Object Browser widget: single selection mode now behaves correctly, clicking a non-folder item no longer attempts navigation, the maximum selection limit is ignored in single mode, and the API for specifying which item attributes to return has been renamed for consistency across the codebase. @iFlameing

packages/plate/components/editor/plugins/slash-menu.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
Heading2Icon,
1313
Heading3Icon,
1414
Heading4Icon,
15-
ImageIcon,
1615
LightbulbIcon,
1716
ListIcon,
1817
ListOrdered,
@@ -139,12 +138,6 @@ const createStaticGroups = (): SlashMenuGroup[] => [
139138
label: 'Text',
140139
value: KEYS.p,
141140
},
142-
{
143-
icon: <ImageIcon />,
144-
keywords: ['img', 'picture', 'photo'],
145-
label: 'Image',
146-
value: KEYS.img,
147-
},
148141
{
149142
icon: <Heading2Icon />,
150143
keywords: ['subtitle', 'h2'],

0 commit comments

Comments
 (0)