Skip to content

Commit

Permalink
refactor: simplify project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
lihbr committed Dec 5, 2024
1 parent de2cb68 commit 0cb1ca7
Show file tree
Hide file tree
Showing 18 changed files with 107 additions and 722 deletions.
2 changes: 1 addition & 1 deletion src/components/PrismicEmbed.vue → src/PrismicEmbed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { EmbedField } from "@prismicio/client"
import { isFilled } from "@prismicio/client"
import type { ComponentOrTagName } from "../types"
import type { ComponentOrTagName } from "./types"
/**
* The default component rendered to wrap the embed.
Expand Down
4 changes: 2 additions & 2 deletions src/components/PrismicImage.vue → src/PrismicImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
} from "@prismicio/client"
import { computed, watchEffect } from "vue"
import { devMsg } from "../lib/devMsg"
import { devMsg } from "./lib/devMsg"
import { usePrismic } from "../usePrismic"
import { usePrismic } from "./usePrismic"
/**
* Props for `<PrismicImage />`.
Expand Down
8 changes: 4 additions & 4 deletions src/components/PrismicRichText.ts → src/PrismicRichText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import {
} from "vue"
import { routerKey } from "vue-router"

import { isInternalURL } from "../lib/isInternalURL"
import { simplyResolveComponent } from "../lib/simplyResolveComponent"
import { isInternalURL } from "./lib/isInternalURL"
import { simplyResolveComponent } from "./lib/simplyResolveComponent"

import type { VueUseOptions } from "../types"
import type { VueUseOptions } from "./types"

import { usePrismic } from "../usePrismic"
import { usePrismic } from "./usePrismic"

/**
* The default component rendered to wrap the HTML output.
Expand Down
4 changes: 2 additions & 2 deletions src/components/PrismicText.vue → src/PrismicText.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import type { RichTextField } from "@prismicio/client"
import { asText, isFilled } from "@prismicio/client"
import { watchEffect } from "vue"
import { devMsg } from "../lib/devMsg"
import { devMsg } from "./lib/devMsg"
import type { ComponentOrTagName } from "../types"
import type { ComponentOrTagName } from "./types"
/**
* Props for `<PrismicText />`.
Expand Down
83 changes: 43 additions & 40 deletions src/components/SliceZone.ts → src/SliceZone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import type {
} from "vue"
import { computed, defineComponent, h, markRaw, watchEffect } from "vue"

import { __PRODUCTION__ } from "../lib/__PRODUCTION__"
import { simplyResolveComponent } from "../lib/simplyResolveComponent"
import { simplyResolveComponent } from "./lib/simplyResolveComponent"

import { usePrismic } from "../usePrismic"
import { usePrismic } from "./usePrismic"

/**
* Returns the type of a `SliceLike` type.
Expand Down Expand Up @@ -249,44 +248,45 @@ export type SliceComponentType<
* This is also the default Vue component rendered when a component mapping
* cannot be found in `<SliceZone />`.
*/
export const TODOSliceComponent = __PRODUCTION__
? ((() => null) as FunctionalComponent<{
slice: SliceLike
}>)
: /*#__PURE__*/ (defineComponent({
name: "TODOSliceComponent",
props: {
slice: {
type: Object as PropType<SliceLike>,
required: true,
export const TODOSliceComponent =
typeof process !== "undefined" && process.env.NODE_ENV === "development"
? /*#__PURE__*/ (defineComponent({
name: "TODOSliceComponent",
props: {
slice: {
type: Object as PropType<SliceLike>,
required: true,
},
},
},
setup(props) {
const type = computed(() => {
return "slice_type" in props.slice
? props.slice.slice_type
: props.slice.type
})

watchEffect(() => {
console.warn(
`[SliceZone] Could not find a component for Slice type "${type.value}"`,
props.slice,
)
})
setup(props) {
const type = computed(() => {
return "slice_type" in props.slice
? props.slice.slice_type
: props.slice.type
})

return () => {
return h(
"section",
{
"data-slice-zone-todo-component": "",
"data-slice-type": type.value,
},
[`Could not find a component for Slice type "${type.value}"`],
)
}
},
}) as SliceComponentType)
watchEffect(() => {
console.warn(
`[SliceZone] Could not find a component for Slice type "${type.value}"`,
props.slice,
)
})

return () => {
return h(
"section",
{
"data-slice-zone-todo-component": "",
"data-slice-type": type.value,
},
[`Could not find a component for Slice type "${type.value}"`],
)
}
},
}) as SliceComponentType)
: ((() => null) as FunctionalComponent<{
slice: SliceLike
}>)

/**
* A record of Slice types mapped to Vue components. Each components will be
Expand Down Expand Up @@ -518,7 +518,10 @@ export const SliceZoneImpl = /*#__PURE__*/ defineComponent({
}

// TODO: Remove in v3 when the `resolver` prop is removed.
if (!__PRODUCTION__) {
if (
typeof process !== "undefined" &&
process.env.NODE_ENV === "development"
) {
if (props.resolver) {
console.warn(
"The `resolver` prop is deprecated. Please replace it with a components map using the `components` prop.",
Expand Down
Loading

0 comments on commit 0cb1ca7

Please sign in to comment.