Skip to content

Commit

Permalink
eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
zbeyens committed May 6, 2024
1 parent 3d3485d commit b4c0d70
Show file tree
Hide file tree
Showing 833 changed files with 8,449 additions and 8,248 deletions.
47 changes: 24 additions & 23 deletions apps/e2e-examples/src/TableApp.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
import { createPlateUI } from '@/plate/create-plate-ui';
import {
createPlugins,
createTablePlugin,
Plate,
PlateContent,
createPlugins,
createTablePlugin,
} from '@udecode/plate';

import { createPlateUI } from '@/plate/create-plate-ui';

import { useVariant } from './useVariant';

export function TableApp() {
const {
initialTableWidth,
colSizes,
readOnly = false,
disableMarginLeft = false,
initialTableWidth,
readOnly = false,
} = useVariant({
auto: {
initialTableWidth: undefined,
colSizes: undefined,
initialTableWidth: undefined,
},
fixed: {
disableMarginLeft: {
colSizes: [350, 150],
disableMarginLeft: true,
initialTableWidth: 500,
},
fixed: {
colSizes: [350, 150],
initialTableWidth: 500,
},
readOnly: {
initialTableWidth: 500,
colSizes: [350, 150],
readOnly: true,
},
disableMarginLeft: {
initialTableWidth: 500,
colSizes: [350, 150],
disableMarginLeft: true,
readOnly: true,
},
});

const plugins = createPlugins(
[
createTablePlugin({
options: {
initialTableWidth,
disableMarginLeft,
initialTableWidth,
},
}),
],
Expand All @@ -51,41 +52,41 @@ export function TableApp() {

const initialValue = [
{
type: 'table',
colSizes,
children: [
{
type: 'tr',
children: [
{
type: 'th',
children: [{ text: 'Row 1, Cell 1' }],
type: 'th',
},
{
type: 'th',
children: [{ text: 'Row 1, Cell 2' }],
type: 'th',
},
],
type: 'tr',
},
{
type: 'tr',
children: [
{
type: 'td',
children: [{ text: 'Row 2, Cell 1' }],
type: 'td',
},
{
type: 'td',
children: [{ text: 'Row 2, Cell 2' }],
type: 'td',
},
],
type: 'tr',
},
],
colSizes,
type: 'table',
},
];

return (
<Plate plugins={plugins} initialValue={initialValue}>
<Plate initialValue={initialValue} plugins={plugins}>
<PlateContent readOnly={readOnly} />
</Plate>
);
Expand Down
7 changes: 4 additions & 3 deletions apps/e2e-examples/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
import { RouterProvider, createBrowserRouter } from 'react-router-dom';

import { TableApp } from './TableApp';
import { TableApp } from './TableApp.js';

const router = createBrowserRouter([
{
path: '/table/:variant',
element: <TableApp />,
path: '/table/:variant',
},
]);

const rootElement = document.querySelector('#root');

// eslint-disable-next-line react/no-deprecated
ReactDOM.render(
<React.StrictMode>
<RouterProvider router={router} />
Expand Down
2 changes: 1 addition & 1 deletion apps/e2e-examples/src/useVariant.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useParams } from 'react-router-dom';

export const useVariant = <T>(variants: { [key: string]: T }) => {
export const useVariant = <T>(variants: Record<string, T>) => {
const { variant } = useParams<{ variant: string }>();
const activeVariant = variants[variant!];

Expand Down
79 changes: 40 additions & 39 deletions apps/www/contentlayer.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path from 'node:path';
import {
defineDocumentType,
defineNestedType,
makeSource,
} from 'contentlayer/source-files';
import path from 'node:path';
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
import rehypePrettyCode from 'rehype-pretty-code';
import rehypeSlug from 'rehype-slug';
Expand All @@ -18,29 +18,28 @@ import { rehypeNpmCommand } from './src/lib/rehype-npm-command';
/** @type {import('contentlayer/source-files').ComputedFields} */
const computedFields = {
slug: {
type: 'string',
resolve: (doc) => `/${doc._raw.flattenedPath}`,
type: 'string',
},
slugAsParams: {
type: 'string',
resolve: (doc) => doc._raw.flattenedPath.split('/').slice(1).join('/'),
type: 'string',
},
};

const LinksProperties = defineNestedType(() => ({
name: 'LinksProperties',
fields: {
doc: {
api: {
type: 'string',
},
api: {
doc: {
type: 'string',
},
},
name: 'LinksProperties',
}));

const DocProperties = defineNestedType(() => ({
name: 'DocProperties',
fields: {
route: {
type: 'string',
Expand All @@ -49,72 +48,73 @@ const DocProperties = defineNestedType(() => ({
type: 'string',
},
},
name: 'DocProperties',
}));

export const Doc = defineDocumentType(() => ({
name: 'Doc',
filePathPattern: `docs/**/*.mdx`,
computedFields,
contentType: 'mdx',
fields: {
title: {
type: 'string',
required: true,
component: {
default: false,
required: false,
type: 'boolean',
},
description: {
type: 'string',
required: true,
},
published: {
type: 'boolean',
default: true,
},
links: {
type: 'nested',
of: LinksProperties,
type: 'string',
},
docs: {
type: 'list',
of: DocProperties,
type: 'list',
},
featured: {
type: 'boolean',
default: false,
required: false,
type: 'boolean',
},
component: {
links: {
of: LinksProperties,
type: 'nested',
},
published: {
default: true,
type: 'boolean',
default: false,
required: false,
},
title: {
required: true,
type: 'string',
},
toc: {
type: 'boolean',
default: true,
required: false,
type: 'boolean',
},
},
computedFields,
filePathPattern: `docs/**/*.mdx`,
name: 'Doc',
}));

export default makeSource({
contentDirPath: './content',
documentTypes: [Doc],
mdx: {
remarkPlugins: [remarkGfm, codeImport],
rehypePlugins: [
rehypeSlug,
rehypeComponent,
() => (tree) => {
visit(tree, (node) => {
if (node?.type === 'element' && node?.tagName === 'pre') {
const [codeEl] = node.children;

if (codeEl.tagName !== 'code') {
return;
}

if (codeEl.data?.meta) {
// Extract event from meta and pass it down the tree.
const regex = /event="([^"]*)"/;
const match = codeEl.data?.meta.match(regex);

if (match) {
node.__event__ = match ? match[1] : null;
codeEl.data.meta = codeEl.data.meta.replace(regex, '');
Expand All @@ -134,21 +134,22 @@ export default makeSource({
const theme = await loadTheme(
path.join(process.cwd(), '/src/lib/themes/dark.json')
);

return await getHighlighter({ theme });
},
onVisitHighlightedLine(node) {
node.properties.className.push('line--highlighted');
},
onVisitHighlightedWord(node) {
node.properties.className = ['word--highlighted'];
},
onVisitLine(node) {
// Prevent lines from collapsing in `display: grid` mode, and allow empty
// lines to be copy/pasted
if (node.children.length === 0) {
node.children = [{ type: 'text', value: ' ' }];
}
},
onVisitHighlightedLine(node) {
node.properties.className.push('line--highlighted');
},
onVisitHighlightedWord(node) {
node.properties.className = ['word--highlighted'];
},
},
],
() => (tree) => {
Expand All @@ -159,6 +160,7 @@ export default makeSource({
}

const preElement = node.children.at(-1);

if (preElement.tagName !== 'pre') {
return;
}
Expand All @@ -170,11 +172,9 @@ export default makeSource({
if (node.__src__) {
preElement.properties.__src__ = node.__src__;
}

if (node.__event__) {
preElement.properties.__event__ = node.__event__;
}

if (node.__style__) {
preElement.properties['__style__'] = node.__style__;
}
Expand All @@ -186,11 +186,12 @@ export default makeSource({
rehypeAutolinkHeadings,
{
properties: {
className: ['subheading-anchor'],
ariaLabel: 'Link to section',
className: ['subheading-anchor'],
},
},
],
],
remarkPlugins: [remarkGfm, codeImport],
},
});
Loading

0 comments on commit b4c0d70

Please sign in to comment.