Skip to content
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

Universal Blocks #679

Open
wants to merge 49 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
c514e47
feat: primitives scaffolding
nicholasio Jan 23, 2024
3156938
Merge branch 'develop' into feature/gutenberg-primitives
nicholasio Feb 19, 2024
de04f84
Merge branch 'develop' into feature/gutenberg-primitives
nicholasio Mar 12, 2024
fd9ca7e
feat: introducing the RichText Primitive
nicholasio Mar 13, 2024
eba91cb
test: basic tests
nicholasio Mar 14, 2024
c15c16d
test: one more test
nicholasio Mar 14, 2024
e6aa3f7
test: default save handler
nicholasio Mar 14, 2024
280a344
fix: ts types
nicholasio Mar 14, 2024
951ad63
fix: types
nicholasio Mar 14, 2024
340f15b
fix: build
nicholasio Mar 14, 2024
9041f9d
Merge branch 'develop' into feature/gutenberg-primitives
nicholasio Mar 14, 2024
42b9f96
Merge branch 'develop' into feature/gutenberg-primitives
nicholasio Mar 14, 2024
344e464
feat: first poc
nicholasio Mar 14, 2024
454f782
chore: remove test from the theme
nicholasio Mar 14, 2024
e2de4a6
feat: initial pass at an image primitive with MediaReplaceFlow
nicholasio Mar 20, 2024
ac6afee
docs: add jsdoc
nicholasio Mar 21, 2024
6920541
Merge branch 'develop' into feature/gutenberg-primitives
nicholasio Apr 5, 2024
c6592a0
chore: remove docs project
nicholasio Apr 5, 2024
45b8a7c
chore: removing express
nicholasio Apr 5, 2024
b9afe47
chore: component library project for testing primitives
nicholasio Apr 5, 2024
caf83ac
chore: fix storybook version
nicholasio Apr 9, 2024
fbb5234
feat: attributes
nicholasio May 7, 2024
2f4c5fd
Merge branch 'develop' into feature/gutenberg-primitives
nicholasio Oct 14, 2024
b2fdcb0
chore: more fixes
nicholasio Oct 14, 2024
25609da
chore: remove wp-nextjs-ts project
nicholasio Oct 14, 2024
9f894e0
feat: hero example
nicholasio Oct 14, 2024
1d91e64
chore: commands
nicholasio Oct 16, 2024
d7e933e
feat: vanilla-extract for css
nicholasio Oct 23, 2024
6f66b6e
renaming package
nicholasio Oct 24, 2024
148f7a3
fix: tests
nicholasio Oct 28, 2024
887819f
Merge branch 'develop' into feature/gutenberg-primitives
nicholasio Oct 28, 2024
0b47d5a
fix: lint
nicholasio Oct 28, 2024
225ba51
fix: linting fixes
nicholasio Oct 28, 2024
e37be5e
fix: builds
nicholasio Oct 28, 2024
9b06fb0
chore: fix bundle analyzer
nicholasio Oct 28, 2024
3ef9fd5
chore: anoter fix
nicholasio Oct 28, 2024
e8a7c95
fix: build issues
nicholasio Oct 28, 2024
686ea35
feat: link component
nicholasio Oct 29, 2024
00d2f87
feat: introducing InnerBlocks Primitive
nicholasio Oct 30, 2024
a3e72f2
feat: inner-blocks change
nicholasio Oct 31, 2024
5752792
feat: interating on rendering blocks on Gutenberg
nicholasio Oct 31, 2024
2ec474f
feat: various improvements
nicholasio Nov 4, 2024
05ebde2
fix: tests
nicholasio Nov 4, 2024
19a4f4c
chore: remove unused code
nicholasio Nov 5, 2024
4c180ad
feat: use next.js components
nicholasio Nov 5, 2024
7974091
feat: refactoring
nicholasio Nov 6, 2024
b91cb04
fix: fixes
nicholasio Nov 7, 2024
f85b8ee
fix: build error
nicholasio Nov 7, 2024
bb2a2c1
chore: comments
nicholasio Nov 8, 2024
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
42,117 changes: 31,292 additions & 10,825 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/core/src/react/components/Link.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { FC } from 'react';
import { PropsWithChildren } from 'react';

interface RawLinkProps {
href: string;
children: React.ReactNode;
}

export const RawLink: FC<RawLinkProps> = ({ children, href, ...props }) => {
export const RawLink = ({ children, href, ...props }: PropsWithChildren<RawLinkProps>) => {
return (
<a href={href} {...props}>
{children}
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/react/provider/DataFetchingProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { FC } from 'react';
import { PropsWithChildren } from 'react';
import { SWRConfig, SWRConfiguration } from 'swr';

export { unstable_serialize as serializeKey } from 'swr';
Expand All @@ -18,10 +18,10 @@ export type DataFetchingProviderProps = {
children: React.ReactNode;
};

export const DataFetchingProvider: FC<DataFetchingProviderProps> = ({
export const DataFetchingProvider = ({
swrConfig,
data,
children,
}) => {
}: PropsWithChildren<DataFetchingProviderProps>) => {
return <SWRConfig value={{ fallback: data, ...swrConfig }}>{children}</SWRConfig>;
};
4 changes: 2 additions & 2 deletions packages/core/src/react/provider/Provider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import React, { FC, createContext, useMemo } from 'react';
import { PropsWithChildren, createContext, useMemo } from 'react';
import { getHeadlessConfig } from '../../utils/config';
import { SettingsContextProps } from './types';

Expand All @@ -11,7 +11,7 @@ interface ProviderProps {
children: React.ReactNode;
}

export const SettingsProvider: FC<ProviderProps> = ({ settings, children }) => {
export const SettingsProvider = ({ settings, children }: PropsWithChildren<ProviderProps>) => {
const settingsValue = useMemo(
() => ({
...getHeadlessConfig(),
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/react/provider/ThemeSettingsProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { FC, createContext } from 'react';
import { PropsWithChildren, createContext } from 'react';
import { ThemeJSON } from './types';

export const ThemeSettingsContext = createContext<ThemeJSON>({});
Expand All @@ -10,6 +10,6 @@ interface ProviderProps {
children: React.ReactNode;
}

export const ThemeSettingsProvider: FC<ProviderProps> = ({ data, children }) => {
export const ThemeSettingsProvider = ({ data, children }: PropsWithChildren<ProviderProps>) => {
return <ThemeSettingsContext.Provider value={data}>{children}</ThemeSettingsContext.Provider>;
};
2 changes: 1 addition & 1 deletion packages/next/src/rsc/data/seo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function fromYoastToMetadata(yoast: YoastJSON, config: HeadlessConfig = {
},
twitter: {
creator: yoast.twitter_creator,
card: yoast.twitter_card,
card: yoast.twitter_card ?? 'summary',
title: yoast.twitter_title,
description: yoast.twitter_description,
images: yoast.twitter_image,
Expand Down
12 changes: 12 additions & 0 deletions packages/primitives/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
parser: '@typescript-eslint/parser',
extends: ['@10up/eslint-config/react', '@10up/eslint-config/jest'],
plugins: ['@typescript-eslint'],
rules: {
'import/no-unresolved': 'off',
'import/extensions': 'off',
},
settings: {
'import/resolver': 'typescript',
},
};
8 changes: 8 additions & 0 deletions packages/primitives/.lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"*.[tj]s": [
"eslint"
],
"*.[tj]sx": [
"eslint"
]
}
19 changes: 19 additions & 0 deletions packages/primitives/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
The MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
17 changes: 17 additions & 0 deletions packages/primitives/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# @headstartwp/blocks-primitives
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicholasio I'd love it if we could rename this to @headstart/block-primitives to be more aligned with how core names all the packages. :)

[![Support Level](https://img.shields.io/badge/support-active-green.svg)](#support-level) [![Next Package MIT License](https://img.shields.io/badge/next%20package-MIT-green)](https://github.com/10up/headstartwp/blob/develop/packages/next/LICENSE.md)


## Installation

```
npm install --save @headstartwp/blocks-primitives
```

## Support Level

**Active:** 10up is actively working on this, and we expect to continue work for the foreseeable future including keeping tested up to the most recent version of WordPress. Bug reports, feature requests, questions, and pull requests are welcome.

## Like what you see?

<a href="http://10up.com/contact/"><img src="https://10up.com/uploads/2016/10/10up-Github-Banner.png" width="850" alt="10up"></a>
14 changes: 14 additions & 0 deletions packages/primitives/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
export default {
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
transform: {
'\\.[jt]sx?$': ['ts-jest', { preset: 'ts-jest/presets/js-with-ts', useESM: true }],
},
testEnvironment: 'jsdom',
testPathIgnorePatterns: ['dist'],
collectCoverage: true,
setupFilesAfterEnv: ['./jest.setup.ts'],
};
1 change: 1 addition & 0 deletions packages/primitives/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'whatwg-fetch';
94 changes: 94 additions & 0 deletions packages/primitives/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"name": "@headstartwp/blocks-primitives",
"version": "0.0.1",
"description": "A set of Gutenberg Primitives for authoring react components that can be shared with the block editor",
"homepage": "https://github.com/10up/headstartwp/blob/develop/packages/primitives/README.md",
"license": "MIT",
"author": "10up <[email protected]> (https://10up.com/)",
"type": "module",
"exports": {
".": {
"types": "./dist/src/index.d.ts",
"default": "./dist/src/index.js"
},
"./rich-text": {
"block-editor": "./dist/src/block-editor/rich-text.js",
"types": "./dist/src/primitives/rich-text.d.ts",
"default": "./dist/src/primitives/rich-text.js"
},
"./image": {
"block-editor": "./dist/src/block-editor/image.js",
"types": "./dist/src/primitives/image.d.ts",
"default": "./dist/src/primitives/image.js"
},
"./block": {
"block-editor": "./dist/src/block-editor/block.js",
"types": "./dist/src/primitives/block.d.ts",
"default": "./dist/src/primitives/block.js"
}
},
"imports": {
"#/*": {
"block-editor": "./src/block-editor/*",
"default": "./src/primitives/*"
},
"#shared/*": "./src/shared/*"
},
"publishConfig": {
"access": "public"
},
"files": [
"dist"
],
"sideEffects": false,
"scripts": {
"build": "npm run ts",
"ts": "tsc -b",
"dev": "npm run watch:ts",
"watch:ts": "npm run ts -- --watch",
"test": "node --experimental-vm-modules ../../node_modules/jest/bin/jest",
"test:watch": "node --experimental-vm-modules ../../node_modules/jest/bin/jest --watch",
"lint": "eslint src"
},
"dependencies": {
"@headstartwp/core": "^1.5.0-next.5",
"@types/wordpress__block-library": "^2.6.3",
"@types/wordpress__block-editor": "^11.5.12",
"@types/wordpress__components": "^23.0.11"
},
"devDependencies": {
"@testing-library/dom": "^9.3.4",
"@testing-library/react": "^14.2.1",
"@testing-library/user-event": "^14.5.2",
"@types/jest": "^29.0.3",
"jest": "^29.0.3",
"ts-jest": "^29.0.1",
"typescript": "^5.4.2",
"whatwg-fetch": "^3.6.2"
},
"peerDependencies": {
"react": ">= 17.0.2",
"@wordpress/block-editor": "^12.21.0",
"@wordpress/data": "^9.23.0",
"@wordpress/components": "^27.1.0",
"@10up/block-components" : "^1.18.0",
"@wordpress/blob": "^3.53.0"
},
"peerDependenciesMeta": {
"@wordpress/block-editor": {
"optional": true
},
"@wordpress/data": {
"optional": true
},
"@wordpress/components": {
"optional": true
},
"@wordpress/blob": {
"optional": true
},
"@10up/block-components": {
"optional": true
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<Block> allow consumers to call setAttributes 1`] = `
<DocumentFragment>
<h1
aria-label="Heading..."
aria-multiline="true"
aria-readonly="false"
class="block-editor-rich-text__editable rich-text"
contenteditable="true"
data-wp-block-attribute-key="0"
role="textbox"
style="white-space: pre-wrap; min-width: 1px;"
>

<span
data-rich-text-placeholder="Heading..."
style="pointer-events:none;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;"
/>
</h1>
</DocumentFragment>
`;

exports[`<Block> allow consumers to call setAttributes 2`] = `
<DocumentFragment>
<h1
aria-label="Heading..."
aria-multiline="true"
aria-readonly="false"
class="block-editor-rich-text__editable rich-text"
contenteditable="true"
data-wp-block-attribute-key="0"
role="textbox"
style="white-space: pre-wrap; min-width: 1px;"
>
heading
</h1>
</DocumentFragment>
`;

exports[`<Block> simply render childrens 1`] = `
<DocumentFragment>
<p>
children
</p>
</DocumentFragment>
`;
57 changes: 57 additions & 0 deletions packages/primitives/src/block-editor/__tests__/block.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { render, renderHook, screen, waitFor } from '@testing-library/react';
import { userEvent } from '@testing-library/user-event';
import Block, { useBlockPrimitiveProps } from '../block.js';
import RichText from '../rich-text.js';

describe('<Block>', () => {
let attributes = {};
const setAttributes = jest.fn((newAttributes) => {
attributes = { ...attributes, ...newAttributes };
return attributes;
});

it('simply render childrens', () => {
const { asFragment } = render(
<Block attributes={attributes} setAttributes={setAttributes}>
<p>children</p>
</Block>,
);

expect(asFragment()).toMatchSnapshot();
});

it('allow consumers to call setAttributes', async () => {
const user = userEvent.setup();

const { asFragment } = render(
<Block attributes={attributes} setAttributes={setAttributes}>
<RichText
name="heading"
tagName="h1"
placeholder="Heading..."
onPrimitiveChange={(name, value, setAttributes) => {
setAttributes({ [name]: value });
}}
/>
</Block>,
);

expect(asFragment()).toMatchSnapshot();
await user.click(screen.getByLabelText('Heading...'));
await waitFor(() => user.keyboard('heading'));

expect(setAttributes).toHaveBeenCalled();
expect(screen.getByText('heading')).toBeDefined();
expect(asFragment()).toMatchSnapshot();
});
});

describe('useBlockPrimitiveProps', () => {
it('does throws an error without context', () => {
const { result } = renderHook(() => useBlockPrimitiveProps());

expect(() => result.current.setAttributes({})).toThrow(
'You need to wrap your Block with `<Block />` before you can use `setAttributes`',
);
});
});
Loading
Loading