@redneckz/wildless-cms-uni-blocks 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +25 -0
- package/.gitattributes +15 -0
- package/.prettierignore +3 -0
- package/package.json +25 -0
- package/src/Blocks.ts +11 -0
- package/src/ContentPage.tsx +31 -0
- package/src/Placeholder.tsx +12 -0
- package/src/Text.tsx +20 -0
- package/src/common.css +2 -0
- package/src/gatsby/GatsbyPage.tsx +18 -0
- package/src/gatsby/index.ts +2 -0
- package/src/index.ts +6 -0
- package/src/types.ts +36 -0
- package/tailwind.config.js +7 -0
- package/tsconfig.json +26 -0
package/.editorconfig
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
root = true
|
|
2
|
+
|
|
3
|
+
[*]
|
|
4
|
+
charset = utf-8
|
|
5
|
+
end_of_line = lf
|
|
6
|
+
indent_style = space
|
|
7
|
+
indent_size = 2
|
|
8
|
+
insert_final_newline = true
|
|
9
|
+
trim_trailing_whitespace = true
|
|
10
|
+
|
|
11
|
+
[*.ts]
|
|
12
|
+
quote_type = single
|
|
13
|
+
|
|
14
|
+
[*.js]
|
|
15
|
+
quote_type = single
|
|
16
|
+
|
|
17
|
+
[*.md]
|
|
18
|
+
max_line_length = off
|
|
19
|
+
trim_trailing_whitespace = false
|
|
20
|
+
|
|
21
|
+
[*.{json,yml}]
|
|
22
|
+
charset = utf-8
|
|
23
|
+
end_of_line = lf
|
|
24
|
+
indent_style = space
|
|
25
|
+
indent_size = 2
|
package/.gitattributes
ADDED
package/.prettierignore
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@redneckz/wildless-cms-uni-blocks",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"style": "./dist/common.css",
|
|
7
|
+
"module": "./lib/index.js",
|
|
8
|
+
"types": "./lib/index.d.ts",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "rimraf ./lib && tsc --build --verbose && npm run build:commonjs && npm run build:style",
|
|
11
|
+
"build:commonjs": "rimraf ./dist && tsc --module commonjs --noImplicitUseStrict --outDir dist",
|
|
12
|
+
"build:style": "tailwindcss -i ./src/common.css -o ./dist/common.css --minify"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@redneckz/uni-jsx": "^0.1.2"
|
|
16
|
+
},
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"gatsby": "^4.11.2"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"rimraf": "^3.0.2",
|
|
22
|
+
"typescript": "^4.6.3",
|
|
23
|
+
"tailwindcss": "^3.0.23"
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/Blocks.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PlaceholderContent } from './Placeholder';
|
|
2
|
+
import { Placeholder } from './Placeholder';
|
|
3
|
+
import type { TextContent } from './Text';
|
|
4
|
+
import { Text } from './Text';
|
|
5
|
+
|
|
6
|
+
export type BlockContent = PlaceholderContent | TextContent;
|
|
7
|
+
|
|
8
|
+
export const Blocks = {
|
|
9
|
+
Text,
|
|
10
|
+
Placeholder
|
|
11
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { JSX } from '@redneckz/uni-jsx';
|
|
2
|
+
import { Blocks } from './Blocks';
|
|
3
|
+
import type { BlockContent } from './Blocks';
|
|
4
|
+
import type { BlockDef, ContentPageDef } from './types';
|
|
5
|
+
|
|
6
|
+
export const ContentPage = JSX<ContentPageDef<BlockContent>>(({ style: pageStyle, blocks }) => (
|
|
7
|
+
<section className={`grid grid-cols-12 ${style2className(pageStyle)}`}>
|
|
8
|
+
{blocks && blocks.map(renderBlock)}
|
|
9
|
+
</section>
|
|
10
|
+
));
|
|
11
|
+
|
|
12
|
+
function renderBlock({ type, style, content, blocks }: BlockDef<BlockContent>, i: number) {
|
|
13
|
+
if (!(type in Blocks)) {
|
|
14
|
+
console.warn(`No block with "${type}" is registered`);
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const BlockComponent = Blocks[type as keyof typeof Blocks];
|
|
18
|
+
return (
|
|
19
|
+
<BlockComponent
|
|
20
|
+
key={`${type}-${i}`}
|
|
21
|
+
className={`border-dashed border-2 border-sky-500 p-4 ${style2className(style)}`}
|
|
22
|
+
{...content}
|
|
23
|
+
>
|
|
24
|
+
{blocks && blocks.map(renderBlock)}
|
|
25
|
+
</BlockComponent>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function style2className(style: string[] | undefined | null): string {
|
|
30
|
+
return style ? style.join(' ') : '';
|
|
31
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { JSX } from '@redneckz/uni-jsx';
|
|
2
|
+
|
|
3
|
+
export interface PlaceholderContent {
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface PlaceholderProps extends PlaceholderContent {
|
|
7
|
+
className?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const Placeholder = JSX<PlaceholderProps>(({ className, children }) => {
|
|
11
|
+
return <div className={className || ''}>{children}</div>;
|
|
12
|
+
});
|
package/src/Text.tsx
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { JSX } from '@redneckz/uni-jsx';
|
|
2
|
+
|
|
3
|
+
export interface TextContent {
|
|
4
|
+
primary?: string;
|
|
5
|
+
secondary?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface TextProps extends TextContent {
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const Text = JSX<TextProps>(({ className, primary, secondary, children }) => {
|
|
13
|
+
return (
|
|
14
|
+
<div className={className || ''}>
|
|
15
|
+
{primary && <p className="font-bold text-slate-700 leading-snug">{primary}</p>}
|
|
16
|
+
{secondary && <p className="mt-2 text-sm text-slate-600">{secondary}</p>}
|
|
17
|
+
{children}
|
|
18
|
+
</div>
|
|
19
|
+
);
|
|
20
|
+
});
|
package/src/common.css
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { setup } from '@redneckz/uni-jsx';
|
|
2
|
+
import type { PageProps } from 'gatsby';
|
|
3
|
+
import runtime from 'react/jsx-runtime';
|
|
4
|
+
import type { BlockContent } from '../Blocks';
|
|
5
|
+
import { ContentPage } from '../ContentPage';
|
|
6
|
+
import type { ContentPageDef } from '../types';
|
|
7
|
+
|
|
8
|
+
import '@demo/ui-kit/dist/common.css';
|
|
9
|
+
|
|
10
|
+
const { jsx, jsxs } = runtime as any;
|
|
11
|
+
setup(jsx, jsxs);
|
|
12
|
+
|
|
13
|
+
type PageData<D extends string> = Record<D, ContentPageDef<BlockContent>>;
|
|
14
|
+
|
|
15
|
+
export const GatsbyPage =
|
|
16
|
+
<D extends string>(discriminator: D) =>
|
|
17
|
+
({ data }: PageProps<PageData<D>>) =>
|
|
18
|
+
<ContentPage {...data[discriminator]} />;
|
package/src/index.ts
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface BlockDef<BlockContent> {
|
|
2
|
+
type: string;
|
|
3
|
+
style?: string[];
|
|
4
|
+
content?: BlockContent;
|
|
5
|
+
blocks?: BlockDef<BlockContent>[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ContentPageDef<BlockContent> {
|
|
9
|
+
title: string;
|
|
10
|
+
slug: string;
|
|
11
|
+
style?: string[];
|
|
12
|
+
blocks?: BlockDef<BlockContent>[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const GraphQL = {
|
|
16
|
+
Block: `
|
|
17
|
+
type BlockContent {
|
|
18
|
+
primary: String
|
|
19
|
+
secondary: String
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type Block {
|
|
23
|
+
type: String!
|
|
24
|
+
style: [String!]
|
|
25
|
+
content: BlockContent
|
|
26
|
+
blocks: [Block!]
|
|
27
|
+
}
|
|
28
|
+
`,
|
|
29
|
+
Page: `
|
|
30
|
+
title: String!
|
|
31
|
+
slug: String
|
|
32
|
+
date: Date
|
|
33
|
+
style: [String!]
|
|
34
|
+
blocks: [Block!]
|
|
35
|
+
`
|
|
36
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNEXT",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"jsx": "react-jsx",
|
|
6
|
+
"jsxImportSource": "@redneckz/uni-jsx",
|
|
7
|
+
"allowJs": true,
|
|
8
|
+
"lib": ["ESNext", "DOM", "DOM.Iterable"],
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"outDir": "./lib",
|
|
12
|
+
|
|
13
|
+
/* Strict Type-Checking Options */
|
|
14
|
+
"strict": true,
|
|
15
|
+
"noImplicitAny": false,
|
|
16
|
+
"alwaysStrict": false,
|
|
17
|
+
|
|
18
|
+
/* Module Resolution Options */
|
|
19
|
+
"rootDir": "src",
|
|
20
|
+
"moduleResolution": "node",
|
|
21
|
+
"esModuleInterop": true,
|
|
22
|
+
/* Advanced Options */
|
|
23
|
+
"skipLibCheck": true
|
|
24
|
+
},
|
|
25
|
+
"include": ["./src/**/*.ts", "./src/**/*.tsx"]
|
|
26
|
+
}
|