Skip to content

Commit

Permalink
Merge pull request #3125 from udecode/fix/client-only
Browse files Browse the repository at this point in the history
Server bundle
  • Loading branch information
zbeyens committed May 6, 2024
2 parents cdaae01 + b570fc3 commit ec8886a
Show file tree
Hide file tree
Showing 2,142 changed files with 23,373 additions and 21,266 deletions.
6 changes: 6 additions & 0 deletions .changeset/core-minor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@udecode/plate-core': minor
---

- Use `editor.reset` instead of `resetEditor` to focus the editor after reset so it's decoupled from `slate-react`.
- Add a server bundle including `createPlateEditor`. It can be imported using `import { createPlateEditor } from '@udecode/plate-core/server'`.
5 changes: 5 additions & 0 deletions .changeset/csv-patch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@udecode/plate-serializer-csv': patch
---

- Remove `@udecode/plate-table` dependency.
5 changes: 5 additions & 0 deletions .changeset/docx-patch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@udecode/plate-serializer-docx': patch
---

- Remove plugin dependencies.
5 changes: 5 additions & 0 deletions .changeset/md-major.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@udecode/plate-serializer-md': major
---

- `serializeMd`: remove `nodes` option. `editor.children` is now serialized.
83 changes: 83 additions & 0 deletions .changeset/md-minor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
'@udecode/plate-serializer-md': minor
---

- Fixes #2716
- Fixes #2858
- Add default support for indent lists.
- Improved new lines around heading.
- Trim new lines.
- Add `serializeMdNodes`: serialize nodes to markdown without editor.
- Add options enabling much more control over the serialization:

```ts
type SerializeMdNodeOptions = {
/**
* Whether the node is enabled. If false, the node will be considered as
* paragraph.
*/
enabled?: boolean;

isLeaf?: boolean;

/**
* Whether the node is void. Required for empty void nodes to not be skipped.
* Default is true for `hr` and `img` nodes
*/
isVoid?: boolean;

/** Serialize node to markdown. */
serialize?: (
children: string,
node: MdNodeType,
opts: SerializeMdOptions
) => string;

/** Whether the node should be skipped (serialized to empty string). */
skip?: boolean;

/** The type of the node. */
type: string;
};


/** @default Options for each node type. */
{
/** @default Options for each node type. */
nodes: Record<keyof MdNodeTypes, SerializeMdNodeOptions>;

/**
* Tag to use for line breaks.
*
* @default '<br>'
*/
breakTag?: string;

/** Custom nodes to serialize. */
customNodes?: Record<string, SerializeMdNodeOptions>;

ignoreParagraphNewline?: boolean;

listDepth?: number;

/**
* Format for underline.
*
* @example
* {
* "underline": ["<u>", "</u>"]
* }
*/
markFormats?: Partial<MarkFormats>;

/**
* List of unordered list style types (when using indent list).
*
* @default ['disc', 'circle', 'square']
*/
ulListStyleTypes?: string[];
}
```

- Remove plugin dependencies.
- Remove `nodeTypes` option in favor of `nodes`.
5 changes: 5 additions & 0 deletions .changeset/react-utils.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@udecode/react-utils': patch
---

- Fix `withRef`: Component props should be excluded from extended props.
85 changes: 46 additions & 39 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
const {
getDefaultIgnorePatterns,
} = require('./config/eslint/helpers/getDefaultIgnorePatterns.cjs');
const { filePatterns } = require('./config/eslint/constants/file-patterns.cjs');

/** @type {import("eslint").Linter.Config} */
/** @type {import('eslint').Linter.Config} */
module.exports = {
root: true,
env: {
browser: true,
es6: true,
jest: true,
node: true,
webextensions: false,
},
extends: [
'turbo',

'./config/eslint/bases/javascript.cjs',
'./config/eslint/bases/typescript.cjs',
'./config/eslint/bases/regexp.cjs',
'./config/eslint/bases/jest.cjs',
Expand All @@ -18,6 +24,7 @@ module.exports = {
'./config/eslint/bases/next.cjs',

'./config/eslint/bases/unicorn.cjs',
'./config/eslint/bases/perfectionist.cjs',

'./config/eslint/bases/prettier.cjs',
],
Expand All @@ -26,80 +33,59 @@ module.exports = {
'.next',
'.out',
'**/__registry__',
'**/diff-match-patch-ts'
'**/diff-match-patch-ts',
],
env: {
browser: true,
es6: true,
jest: true,
node: true,
webextensions: false,
},
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
'import/resolver': {
node: {
moduleDirectory: ['node_modules'],
typescript: {
alwaysTryTypes: true,
},
overrides: [
{
files: ['*.ts', '*.tsx', '*.mts'],
parserOptions: {
project: true,
},
typescript: {},
},
react: { version: 'detect' },
next: {
rootDir: ['apps/www'],
},
},
rules: {},
overrides: [
{
files: ['apps/www/src/**/*'],
extends: ['plugin:@dword-design/import-alias/recommended'],
files: ['apps/www/src/**/*'],
rules: {
'import/no-relative-packages': 'off',
'@dword-design/import-alias/prefer-alias': [
'warn',
{
alias: {
'@/__registry__': './apps/www/src/__registry__',
'@/app': './apps/www/src/app',
'@/plate': './apps/www/src/lib/plate',
'@/components': './apps/www/src/components',
'@/hooks': './apps/www/src/hooks',
'@/__registry__': './apps/www/src/__registry__',
'@/lib': './apps/www/src/lib',
'@/plate': './apps/www/src/lib/plate',
'@/registry': './apps/www/src/registry',
'@/styles': './apps/www/src/styles',
'@/lib': './apps/www/src/lib',
},
},
],
'import/no-relative-packages': 'off',
},
},
{
files: ['**/*.spec.*'],
extends: ['./config/eslint/bases/prettier.cjs'],
files: filePatterns.test,
rules: {
'react/jsx-key': 'off',
'import/no-relative-packages': 'off',
'import/no-unresolved': 'off',
'react/jsx-key': 'off',
},
},
{
files: ['**/*.test.*', '**/*.spec.*', '**/*.fixture.*'],
env: {
jest: true,
},
files: filePatterns.test,
rules: {
'@typescript-eslint/no-unused-vars': 'off',
'react-hooks/rules-of-hooks': 'off',
'no-restricted-imports': [
'error',
{
paths: [],
},
],
'react-hooks/rules-of-hooks': 'off',
},
},
{
Expand All @@ -109,4 +95,25 @@ module.exports = {
},
},
],
parser: '@typescript-eslint/parser',
root: true,
rules: {},
settings: {
// 'import/parsers': {
// '@typescript-eslint/parser': ['.ts', '.tsx'],
// },
// 'import/resolver': {
// node: {
// moduleDirectory: ['node_modules'],
// typescript: {
// alwaysTryTypes: true,
// },
// },
// typescript: {},
// },
next: {
rootDir: ['apps/www'],
},
react: { version: 'detect' },
},
};
34 changes: 34 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,37 @@ After creating your package, install and build it:
yarn install
yarn build
```

### How to: Server bundle

The main bundle is client-side and is not tested in server environments. In general, a server bundle is necessary when the package has usages depending on `slate-react` or React. In that case, here is how to create a server bundle:

- Move all files with server support to `/src/shared`
- Move all files without server support to `/src/client`
- Create a new entry file in `/src/server.ts`, export with the following:

```ts
export * from './shared/index';
export * from './server/index'; // If needed
```

- (Optional) If needed, create server-side versions in `/src/server/`. For example, `withReact` in `/src/server/withReact` is a server-side version of `/src/client/withReact`
- Run `yarn brl` to synchronize the exports
- Update `package.json > exports`

```json
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"module": "./dist/index.mjs",
"require": "./dist/index.js"
},
"./server": {
"types": "./dist/server.d.ts",
"import": "./dist/server.mjs",
"module": "./dist/server.mjs",
"require": "./dist/server.js"
}
},
```
Loading

0 comments on commit ec8886a

Please sign in to comment.