-
Notifications
You must be signed in to change notification settings - Fork 16
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
RFC: @prismicio/vue refresh and Vue 3 support #46
Comments
Outdated - First alpha announcement based on old kitsHey everyone, I'm happy to announce that we released an alpha reflecting our first sprint of work on this kit 🎉 Few Highlights
Try the Alpha Nowyarn add @prismicio/vue@alpha
# or with npm
npm install @prismicio/vue@alpha RFC StatusThe above RFC will be updated soon with more details. Right now one of our top questions is related to the plugin's configuration interface: interface PrismicPluginOptions {
endpoint: string;
apiOptions?: ApiOptions;
linkResolver?: LinkResolver;
htmlSerializer?: HtmlSerializer<string>;
client?: boolean | ClientOptions;
dom?: boolean | DOMOptions;
components?: boolean | ComponentsOptions;
} And whether or not it makes sense to move the Source CodeSource code is available on the v3 branch. As always we're more than happy to discuss the ongoing work on the Vue.js kit with you all! Cheers! |
Update One thing I'm unsure is about the naming of
Maybe having the latter named |
Released 🎉 |
Status
🕵️♀️ Second implementation has been made and fully tested, the associated PR is awaiting for review, QA, and documentation. Vue 2 support is still hanging.
Overview
This request for comments (RFC) presents a new interface for the Vue plugin, but also components, and now composables, to make presenting and fetching Prismic content easy and extendable. Most of the interface described below is inspired by the existing
@prismicio/vue
library. Some enhancements and new features made possible by Vue 3 are new.The proposals defined in this RFC are designed for all Vue.js users. Higher-level kits like
@nuxtjs/prismic
are meant to take advantage of this kit to provide more in-depth integration with their specific meta-framework.Background Information
@prismicio/vue
currently includes the following:Plugin
PrismicVue
: Plugins to inject Prismic client, helpers, and components into Vue applications.Client
client
: Provides access to a Prismic client instance inside the Vue application.Helpers
asHtml()
: Serializes a Prismic rich text field to an HTML string;asText()
&richTextAsPlain
: Serializers a Prismic rich text field to a plain text string;asDate()
: Transforms a Prismic date or timestamp field into a JavaScript Date object;asLink()
: Resolves a Prismic link field to a URL.Components
<prismic-embed />
: Renders a Prismic embed field;<prismic-image />
: Renders a Prismic image field;<prismic-rich-text />
: Renders a Prismic rich text field;<prismic-link />
: Renders a Prismic link field.While carrying a bit of legacy architecture and interface, the current
@prismicio/vue
kit is robust and working well with Vue 2. Reworking this kit will allow taking advantage of the new kits we've worked on (@prismicio/client
&@prismicio/helpers
), provide first-class TypeScript integration (with the new@prismicio/types
package), and support for Vue 3.Thanks to the knowledge we acquired supporting Vue at Prismic, this new version will also allow standardizing the interface offered by higher level Vue.js kits (
@nuxtjs/prismic
), making the development with Vue.js & Prismic consistent across meta-frameworks.Proposal
The
@prismicio/vue
kit will still be architecture around a main Vue.js plugin. Alongside it, the following components and composables make for a robust Vue integration with Prismic:<prismic-embed />
: Renders a Prismic embed field;<prismic-image />
: Renders a Prismic image field;<prismic-link />
: Renders a Prismic link field;<prismic-rich-text />
: Renders a Prismic rich text field;<prismic-text />
: Renders a Prismic rich text field as text;<slice-zone />
: Renders Slices a Prismic Slice Zone;usePrismicDocuments()
& alternatives: Prismic document fetching composables.The following are described below, each of them now being available through the package export.
Plugin
createPrismic()
This factory function makes for the only way to create a
@prismicio/vue
plugin instance to use with Vue.js. It supports the following options (simplified TypeScript interface):Installing the plugin then looks like this:
usePrismic()
This composable gives access to the API exposed by the plugin when using the composition API, it's an alternative to
this.$prismic
when using the option API:Injected Client
A Prismic client and necessary properties are injected by the plugin:
client
: A@prismicio/client
instance;predicate
: Query predicates from@prismicio/client
;cookie
: Prismic cookies from@prismicio/client
.Those methods and properties are accessible through
this
with the options API andusePrismic()
with the composition API:Injected Helpers
Injected helpers now are the ones exported by
@prismicio/helpers
:asText()
: Serializers a Prismic rich text field to a plain text string;asHTML()
(now capitalized): Serializes a Prismic rich text field to an HTML string;asLink()
: Resolves a Prismic link field to a URL;asDate()
: Transforms a Prismic date or timestamp field into a JavaScript Date object;documentToLinkField()
(internal): Converts a document into a link field.Those helpers are accessible through
this
with the options API andusePrismic()
with the composition API:Injected Components
All components described in this proposal are injected and made available globally to the Vue application by the plugin by default. Injection can be disabled by turning the
injectComponents
plugin option tofalse
, components will still take advantage of options provided through thecomponents
option object to the plugin though.Components
Each of the following components can either be injected globally using the plugin (see above) or imported manually:
<prismic-embed />
This component renders a Prismic embed field:
The output will be wrapped by an HTML
div
tag by default. A custom wrapper tag, component, or functional component can be supplied using thewrapper
prop:<prismic-image />
This component renders a Prismic image field:
The image will be rendered using a standard
img
tag. A custom image component or functional component can be supplied directly or configured at the Prismic plugin level. Additional props can also be supplied directly to the component:<prismic-link />
This component renders a Prismic link field or document:
The link or document will be resolved using the link resolver provided to the Prismic plugin if available, otherwise, a link resolver can be directly supplied:
The link will be rendered using Vue Router
<router-link />
component if internal or HTML anchor tag if external. Custom HTML tags, components, or functional components can be supplied directly or configured at the Prismic plugin level to handle internal and external links as desired:target
andrel
attributes can be explicitly supplied to be rendered indifferently:Links with blank target will have their
rel
attribute set to"noopener noreferrer"
. Another value can be supplied directly or configured at the Prismic plugin level:A low level
usePrismicLink
composable is also exported:<prismic-rich-text />
This component renders a Prismic rich text or title field as HTML:
Links within the rich text field will be resolved using the link resolver provided to the Prismic plugin if available, otherwise, a link resolver can be directly supplied. Similarly, the rich text field will be serialized using the HTML serializer provided to the Prismic plugin if available, otherwise, an HTML serializer can also be directly supplied.
The output will be wrapped by an HTML
div
tag by default. A custom wrapper tag, component, or functional component can be supplied using thewrapper
prop:A low level
usePrismicRichText
composable is also exported:<prismic-text />
This component renders a Prismic rich text or title field as plain text:
The output will be wrapped by an HTML
div
tag by default. A custom wrapper tag, component, or functional component can be supplied using thewrapper
prop:Similar to the
asText()
function from@prismicio/helpers
, aseparator
prop is also accepted and default to" "
(a space):A low level
usePrismicText
composable is also exported:<slice-zone />
This component renders a Prismic Slice Zone:
Additional data can be made available to each rendered slices using the
context
prop:A default component will be rendered if a component mapping from the
components
prop cannot be found. This component can be overridden by providing one to the Prismic plugin or by supplying one directly:The output will not be wrapped by default. A custom wrapper tag, component, or functional component can be supplied using the
wrapper
prop:Defining the
components
prop object can have some gotchas, therefore agetSliceZoneComponents()
helper function is made available:getSliceZoneComponents()
is a helper function for:In a similar fashion, defining slice props can be daunting, therefore a
getSliceComponentProps()
helper function is made available:getSliceComponentProps()
is a helper function for:usePrismicDocuments()
& alternativesA collection of Vue composables, including
usePrismicDocuments()
,usePrismicDocumentByID()
, andusePrismicDocumentsByType()
, queries the Prismic REST API for content from a Prismic repository.The API mirrors that of the
@prismicio/client
library in composable form. It handles different states automatically, such as loading states and data persistence between re-renders. API parameters, such aslang
andorderings
, are provided as each composable's last parameter, just like using the client directly.The following composables fetch one or more documents. They return Prismic's paginated API responses which can be helpful when displaying paginated content.
usePrismicDocuments()
usePrismicDocumentsByIDs()
usePrismicDocumentsByTag()
usePrismicDocumentsByTags()
usePrismicDocumentsByType()
The following list of composables is a variation of the previous list. These composables automatically fetch all documents from a paginated response and may make multiple network requests in order to fetch all matching documents.
useAllPrismicDocuments()
useAllPrismicDocumentsByIDs()
useAllPrismicDocumentsByTag()
useAllPrismicDocumentsByTags()
useAllPrismicDocumentsByType()
The following composables return one document.
usePrismicDocumentByID()
usePrismicDocumentByUID()
useFirstPrismicDocument()
: Returns only the first matching documentuseSinglePrismicDocument()
: Returns a singleton document of a given typeAll composables return the following data shape:
Where:
state
is the composable state from thePrismicClientComposableState
export;data
is the API response depending on the composable ornull
when loading it;error
is the thrown error if in an error state;refresh()
is a function to perform again the composable's API request.When using the Prismic plugin, each composable will use the plugin exposed
@prismicio/client
instance. A custom@prismicio/client
instance can be provided as part of the composable'sparams
object to override it. When not using the plugin it is mandatory to provide a@prismicio/client
instance this way:How to Provide Feedback
This is a public request for comments on the proposed ideas. If you have any feedback or suggestions, please feel free to reply below.
We would like to hear from potential users of these ideas whether the ideas positively or negatively impact workflows. If you have any additional ideas as well, please share them here.
Everything posted here is open for feedback and is not final. Development may have already begun by the time you are reading this, but please do not let that stop you from providing feedback.
Thank you!
History
Outdated - First iteration based on old kits
🎉 Vue 3 Kit RFC 🎉
📣 Vue 3 Kit Suggestion Thread — 📖 Vue 2 Kit Reference
RFC Process
This RFC will be used as a specification to know what needs to be implemented. It's a place for everyone to:
@prismicio/vue
;This RFC is a collaborative and iterative process. We will do our best to take into account everyone's opinion about it. A related Suggestion Thread has also been created to discuss the present and future of this kit.
Specification
Interface
Stay tuned! We're still in the process of defining a base interface for the next version of this kit. In the meantime, you can expect current components and helpers to remain similar in the next version.
TypeScript
The next version of
@prismicio/vue
will be written in TypeScript. This will allow us to provide a more robust kit while also providing a better developer experience for:This change is motivated by an increasing number of requests around TypeScript for Prismic kits. At Prismic one of our goals this year is to improve TypeScript support across all our kits.
Q&A
Will the next major version still support Vue 2?
We're aiming to make this kit still compatible with Vue 2. However, to take advantage of the latest and greatest coming with Vue 3, it's more than possible that Vue 2 support will be available through a compatibility, eventually feature-restrained, build. You can think of it in this fashion:
Closing #5, #41
Please be respectful and friendly to everyone's ideas and point of view. Thanks for contributing! 💙
The text was updated successfully, but these errors were encountered: