npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@weaverse/hydrogen

v3.1.6

Published

Components, hooks, and utilities for building Shopify Hydrogen websites with Weaverse

Downloads

829

Readme

@weaverse/hydrogen

Overview

@weaverse/hydrogen is a crucial package within the Weaverse ecosystem, designed to facilitate the integration of Shopify Hydrogen and Remix projects with the Weaverse CMS. It leverages @weaverse/react for rendering content and provides a client for easy setup and data fetching from Weaverse CMS.

Key Features

  • Weaverse Client Integration: Enables seamless integration with Weaverse CMS, allowing for efficient data fetching and rendering in Hydrogen/Remix projects.
  • Dynamic Data Fetching: Fetch and render page data and global theme settings server-side, ensuring dynamic and consistent content delivery.
  • Component Registration and Rendering: Register React components with Weaverse and render them using the WeaverseHydrogenRoot component.
  • Flexible Schema Definition: Define behavior and interactivity of components within Weaverse Studio through the HydrogenComponentSchema.
  • Customizable Input Settings: Specify configurations for merchant-customizable component settings in Weaverse Studio.

Installation

npm install @weaverse/hydrogen

Setup and Usage

Weaverse Client Setup

Initialize the Weaverse Client to establish a connection between your Hydrogen project and Weaverse CMS:

// <root>/server.ts

import { createWeaverseClient } from '~/weaverse/create-weaverse.server'

const handleRequest = createRequestHandler({
  // ...
  getLoadContext: () => ({
    // Injecting the Weaverse client into the loader context.
    weaverse: createWeaverseClient({
      storefront,
      request,
      env,
      cache,
      waitUntil,
    }),
    // ... more app context properties
  }),
})

Data Fetching and Rendering

Use the Weaverse Client to fetch data such as page content and global theme settings:

// <root>/app/routes/($locale)._index.tsx

import { json } from '@shopify/remix-oxygen'
import { type RouteLoaderArgs } from '@weaverse/hydrogen'

export async function loader({ context }: RouteLoaderArgs) {
  let { weaverse } = context

  return json({
    // The key prop for a Weaverse page must always be `weaverseData`
    weaverseData: await weaverse.loadPage(),
    // Additional page data...
  })
}

Implement the WeaverseHydrogenRoot component to render the fetched content:

// <root>/app/weaverse/index.tsx

import { WeaverseHydrogenRoot } from '@weaverse/hydrogen'
import { GenericError } from '~/components/GenericError'
import { components } from './components'

export function WeaverseContent() {
  return (
    <WeaverseHydrogenRoot
      components={components}
      errorComponent={GenericError}
    />
  )
}

// <root>/app/routes/($locale)._index.tsx

import { WeaverseContent } from '~/weaverse'

export default function Homepage() {
  return <WeaverseContent />
}

Defining Component Schema

Define your component's schema to control its behavior and interactivity within Weaverse Studio:

import type { HydrogenComponentSchema } from '@weaverse/hydrogen'

export let schema: HydrogenComponentSchema = {
  title: 'Product Card',
  type: 'product-card',
  inspector: [
    {
      group: 'Settings',
      inputs: [], // Defining input settings
    },
  ],
  childTypes: ['image', 'product-title', 'price'],
  presets: {
    type: 'product-card',
    children: [{ type: 'image' }, { type: 'product-title' }, { type: 'price' }],
  },
  limit: 3,
  enabledOn: {
    pages: ['INDEX', 'PRODUCT', 'ALL_PRODUCTS'],
    groups: ['body'],
  },
  toolbar: ['general-settings', ['duplicate', 'delete']],
}

Customizing Input Settings

Customize input settings for merchant-adjustable component configurations in Weaverse Studio:

{
  type: "select",
  label: "Image aspect ratio",
  name: "imageAspectRatio",
  configs: {
    options: [
      { value: "auto", label: "Adapt to image" },
      { value: "1/1", label: "1/1" },
      { value: "3/4", label: "3/4" },
      { value: "4/3", label: "4/3" },
    ]
  },
  defaultValue: "auto"
}

Contributing

Contributions to the @weaverse/hydrogen package are highly appreciated. Please refer to our contributing guidelines for more details on how to contribute effectively.

License

This package is created by The Weaverse Team (https://weaverse.io) and is licensed under the MIT License.