Skip to content

Commit 130fa67

Browse files
committed
Default embed header
1 parent 54605c0 commit 130fa67

File tree

11 files changed

+78
-30
lines changed

11 files changed

+78
-30
lines changed

demo/app/Sharp/Utils/Embeds/RelatedPostEmbed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ public function buildEmbedConfig(): void
1515
$this
1616
->configureLabel('Related Post')
1717
->configureTagName('x-related-post')
18+
->configureIcon('fas-link')
1819
->configureTemplate(<<<'blade'
1920
<div style="display: flex; gap: .5rem; align-items: center">
2021
@if($online)
2122
<span style="color: blue">●</span>
2223
@else
2324
<span style="color: orange">●</span>
2425
@endif
25-
<x-fas-link style="width: 1rem; height: 1rem" />
2626
<em>{{ $title }}</em>
2727
</div>
2828
blade

demo/app/Sharp/Utils/Embeds/TableOfContentsEmbed.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ class TableOfContentsEmbed extends SharpFormEditorEmbed
1010
public function buildEmbedConfig(): void
1111
{
1212
$this->configureLabel('Table of contents')
13-
->configureTagName('x-table-of-contents')
14-
->configureTemplate('<em>- Table of contents -</em>');
13+
->configureTagName('x-table-of-contents');
1514
}
1615

1716
public function buildFormFields(FieldsContainer $formFields): void {}

docs/guide/form-editor-embeds.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ This is not required, but you should implement `buildEmbedConfig(): void`, where
6161
- `configureTemplate(string|View $template): self`: to define the blade as inline string or as a `view('my-template')` for both show & form. If you want to specify different templates between show & form you can use following methods :
6262
- `configureShowTemplate(string|View $template): self`
6363
- `configureFormTemplate(string|View $template): self`
64-
- `configureIcon(string $icon): self` define icon, place it in toolbar...
64+
- `configureIcon(string $icon): self`: to define an icon used when the embed is placed in the toolbar. The icon is also displayed in the embed header.
65+
- `configureDisplayEmbedHeader(bool $display = true, ?string $title = null): self`: to hide the default embed header. The title is the label defined in `configureLabel()` but it can be overridden here.
6566

6667
Here's a complete example:
6768

resources/css/content.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
@apply relative p-1.5 -m-1.5 text-primary underline underline-offset-4 decoration-primary/20 hover:decoration-inherit;
6666
}
6767
:where(strong) {
68-
@apply font-bold;
68+
@apply font-[650];
6969
}
7070
> :where(:first-child) {
7171
@apply mt-0;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<script setup lang="ts">
2+
import { EmbedData } from "@/types";
3+
import Icon from "@/components/ui/Icon.vue";
4+
5+
defineProps<{
6+
embed: EmbedData,
7+
}>()
8+
</script>
9+
10+
<template>
11+
<div class="flex mb-3 -mt-0.5 items-center gap-2 only:my-0" data-embed-title>
12+
<template v-if="embed.icon">
13+
<Icon class="size-3 text-accent-foreground" :icon="embed.icon" />
14+
</template>
15+
<h3 class="flex-1 min-w-0 truncate text-xs font-medium text-accent-foreground">
16+
{{ embed.embedHeaderTitle || embed.label }}
17+
</h3>
18+
</div>
19+
</template>

resources/js/form/components/fields/editor/extensions/embed/EmbedNode.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
DropdownMenuTrigger
1414
} from "@/components/ui/dropdown-menu";
1515
import { MoreHorizontal } from "lucide-vue-next";
16+
import EmbedHeader from "@/components/EmbedHeader.vue";
1617
1718
const props = defineProps<ExtensionNodeProps<typeof Embed, EmbedNodeAttributes>>();
1819
@@ -43,12 +44,13 @@
4344
:class="{ 'group-focus/editor:border-primary': props.selected }"
4445
:node="node"
4546
>
46-
<div class="flex-1" >
47-
<template v-if="embedData">
48-
<div v-html="embedData?._html"></div>
47+
<div class="flex-1 min-w-0">
48+
<template v-if="extension.options.embed.displayEmbedHeader">
49+
<EmbedHeader :embed="extension.options.embed" />
4950
</template>
50-
<template v-else>
51-
{{ extension.options.embed.label }}
51+
52+
<template v-if="embedData?._html">
53+
<div v-html="embedData?._html"></div>
5254
</template>
5355
</div>
5456
<template v-if="!parentEditor.props.field.readOnly">

resources/js/show/components/fields/text/nodes/Embed.vue

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { ContentEmbedManager } from "@/content/ContentEmbedManager";
44
import { Show } from "@/show/Show";
55
import { EmbedData } from "@/types";
6+
import EmbedHeader from "@/components/EmbedHeader.vue";
67
const props = defineProps<{
78
embed: EmbedData,
89
}>();
@@ -12,12 +13,13 @@
1213
</script>
1314

1415
<template>
15-
<div class="my-4 first:mt-0 last:mb-0 bg-background border rounded-md p-4">
16-
<component
17-
v-if="embedData"
18-
:is="embed.tag"
19-
v-html="embedData._html"
20-
/>
21-
</div>
16+
<component :is="embed.tag" class="block my-4 first:mt-0 last:mb-0 bg-background border rounded-md p-4">
17+
<template v-if="embed.displayEmbedHeader">
18+
<EmbedHeader :embed="embed" />
19+
</template>
20+
<template v-if="embedData?._html">
21+
<div v-html="embedData._html"></div>
22+
</template>
23+
</component>
2224
</template>
2325

resources/js/types/generated.d.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ export type EmbedData = {
114114
icon: IconData | null;
115115
attributes: Array<string>;
116116
fields: { [key: string]: FormFieldData };
117+
displayEmbedHeader: boolean;
118+
embedHeaderTitle: string | null;
117119
};
118120
export type EmbedFormData = {
119121
data: { [key: string]: FormFieldData["value"] };
@@ -143,13 +145,13 @@ export type EntityListConfigData = {
143145
state: EntityStateData | null;
144146
};
145147
export type EntityListData = {
148+
title: string | null;
146149
authorizations: EntityListAuthorizationsData;
147150
config: EntityListConfigData;
148151
fields: Array<EntityListFieldData>;
149152
data: Array<{ [key: string]: any }>;
150153
filterValues: FilterValuesData;
151154
query: EntityListQueryParamsData | null;
152-
title: string | null;
153155
forms: { [key: string]: EntityListMultiformData } | null;
154156
meta: PaginatorMetaData | null;
155157
pageAlert: PageAlertData | null;
@@ -288,13 +290,13 @@ export type FormCustomFieldData = {
288290
extraStyle: string | null;
289291
};
290292
export type FormData = {
293+
title: string | null;
291294
authorizations: InstanceAuthorizationsData;
292295
config: FormConfigData;
293296
data: { [key: string]: FormFieldData["value"] };
294297
fields: { [key: string]: FormFieldData };
295298
layout: FormLayoutData;
296299
locales: Array<string>;
297-
title: string | null;
298300
pageAlert: PageAlertData | null;
299301
};
300302
export type FormDateFieldData = {
@@ -756,13 +758,13 @@ export type ShowCustomFieldData = {
756758
emptyVisible: boolean;
757759
};
758760
export type ShowData = {
761+
title: string | { [locale: string]: string } | null;
759762
authorizations: InstanceAuthorizationsData;
760763
config: ShowConfigData;
761764
data: { [key: string]: ShowFieldData["value"] };
762765
fields: { [key: string]: ShowFieldData };
763766
layout: ShowLayoutData;
764767
locales: Array<string> | null;
765-
title: string | { [locale: string]: string } | null;
766768
pageAlert: PageAlertData | null;
767769
};
768770
export type ShowEntityListFieldData = {

resources/js/types/routes.d.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ declare module 'ziggy-js' {
2424
],
2525
"code16.sharp.single-show": [
2626
{
27-
"name": "entityKey"
27+
"name": "entityKey",
28+
"binding": "key"
2829
}
2930
],
3031
"code16.sharp.download.show": [
@@ -40,7 +41,8 @@ declare module 'ziggy-js' {
4041
"name": "parentUri"
4142
},
4243
{
43-
"name": "entityKey"
44+
"name": "entityKey",
45+
"binding": "key"
4446
},
4547
{
4648
"name": "instanceId"
@@ -62,23 +64,26 @@ declare module 'ziggy-js' {
6264
"name": "parentUri"
6365
},
6466
{
65-
"name": "entityKey"
67+
"name": "entityKey",
68+
"binding": "key"
6669
}
6770
],
6871
"code16.sharp.form.store": [
6972
{
7073
"name": "parentUri"
7174
},
7275
{
73-
"name": "entityKey"
76+
"name": "entityKey",
77+
"binding": "key"
7478
}
7579
],
7680
"code16.sharp.form.edit": [
7781
{
7882
"name": "parentUri"
7983
},
8084
{
81-
"name": "entityKey"
85+
"name": "entityKey",
86+
"binding": "key"
8287
},
8388
{
8489
"name": "instanceId"
@@ -89,7 +94,8 @@ declare module 'ziggy-js' {
8994
"name": "parentUri"
9095
},
9196
{
92-
"name": "entityKey"
97+
"name": "entityKey",
98+
"binding": "key"
9399
},
94100
{
95101
"name": "instanceId"
@@ -118,12 +124,14 @@ declare module 'ziggy-js' {
118124
],
119125
"code16.sharp.api.list.command.quick-creation-form.create": [
120126
{
121-
"name": "entityKey"
127+
"name": "entityKey",
128+
"binding": "key"
122129
}
123130
],
124131
"code16.sharp.api.list.command.quick-creation-form.store": [
125132
{
126-
"name": "entityKey"
133+
"name": "entityKey",
134+
"binding": "key"
127135
}
128136
],
129137
"code16.sharp.api.list": [
@@ -291,7 +299,8 @@ declare module 'ziggy-js' {
291299
"code16.sharp.api.form.upload": [],
292300
"code16.sharp.api.form.autocomplete.index": [
293301
{
294-
"name": "entityKey"
302+
"name": "entityKey",
303+
"binding": "key"
295304
},
296305
{
297306
"name": "autocompleteFieldKey"

src/Data/Embeds/EmbedData.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public function __construct(
2626
public array $attributes,
2727
/** @var array<string,FormFieldData> */
2828
public array $fields,
29+
public bool $displayEmbedHeader,
30+
public ?string $embedHeaderTitle,
2931
) {}
3032

3133
public static function from(array $embed): self

0 commit comments

Comments
 (0)