Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions resources/js/components/entries/PublishForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
:track-dirty-state="trackDirtyState"
:sync-field-confirmation-text="syncFieldConfirmationText"
:remember-tab="!isInline"
:provide="{ isWorkingCopy, revisionsEnabled }"
>
<LivePreview
:enabled="isPreviewing"
Expand Down
23 changes: 22 additions & 1 deletion resources/js/components/ui/Publish/Container.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ const props = defineProps({
type: Boolean,
default: false,
},
/** Extra values to be provided through the context. */
provide: {
type: Object,
default: () => ({})
},
});

const parentContainer = injectContainerContext(containerContextKey);
Expand Down Expand Up @@ -176,6 +181,7 @@ watch(

const avoidTrackingDirtyState = ref(false);
const trackingDirtyState = computed(() => props.trackDirtyState && !avoidTrackingDirtyState.value)
const isDirty = computed(() => Statamic.$dirty.has(props.name));

function dirty() {
if (trackingDirtyState.value) Statamic.$dirty.add(props.name);
Expand Down Expand Up @@ -236,7 +242,11 @@ function pushComponent(name, { props }) {
return component;
}

const provided = {
const additionalProvides = Object.fromEntries(
Object.entries(props.provide).map(([key]) => [key, toRef(() => props.provide[key])])
);

const builtInProvides = {
name: toRef(() => props.name),
parentContainer,
blueprint: toRef(() => props.blueprint),
Expand Down Expand Up @@ -268,9 +278,20 @@ const provided = {
setRevealerField,
unsetRevealerField,
setHiddenField,
isDirty,
withoutDirtying,
};

if (import.meta.env.DEV) {
for (const key of Object.keys(additionalProvides)) {
if (key in builtInProvides) {
console.warn(`PublishContainer: provide key "${key}" collides with a built-in context key, which takes precedence.`);
}
}
}

const provided = { ...additionalProvides, ...builtInProvides };

provideContainerContext({ ...provided, container: provided });

defineExpose({
Expand Down