Skip to content

Commit

Permalink
Prep pre-release
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaudcolas committed Jun 28, 2022
1 parent 915b048 commit 76c3652
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 7 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ coverage/
dist/
*.bundle.js
public/storybook
storybook-static
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ dist/
webpack-stats.json
public/webpack-stats.html
public/storybook
storybook-static
28 changes: 25 additions & 3 deletions examples/components/PrismDecorator.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from "react";
import type { Node } from "react";
import Prism from "prismjs";
import type { ContentBlock } from "draft-js";

Expand All @@ -15,6 +14,23 @@ type Options = {
* to use the CompositeDecorator strategy API.
*/
class PrismDecorator {
options: Options;

highlighted: Record<string, Record<string, { type: string }>> = {};

component: ({
children,
offsetKey,
}: {
children: React.ReactNode;
offsetKey: string;
}) => JSX.Element;

strategy: (
block: ContentBlock,
callback: (start: number, end: number) => void,
) => void;

constructor(options: Options) {
this.options = options;
this.highlighted = {};
Expand All @@ -24,7 +40,13 @@ class PrismDecorator {
}

// Renders the decorated tokens.
renderToken({ children, offsetKey }: { children: Node; offsetKey: string }) {
renderToken({
children,
offsetKey,
}: {
children: React.ReactNode;
offsetKey: string;
}) {
const type = this.getTokenTypeForKey(offsetKey);
return <span className={`token ${type}`}>{children}</span>;
}
Expand Down Expand Up @@ -69,7 +91,7 @@ class PrismDecorator {
this.highlighted[blockKey] = {};

let tokenCount = 0;
tokens.reduce((startOffset, token) => {
tokens.reduce((startOffset: number, token: string) => {
const endOffset = startOffset + token.length;

if (typeof token !== "string") {
Expand Down
3 changes: 1 addition & 2 deletions examples/entities/Document.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from "react";
import type { Node } from "react";
import { ContentState } from "draft-js";

import FontIcon from "../components/FontIcon";
Expand All @@ -10,7 +9,7 @@ export const DOCUMENT_ICON = <FontIcon icon="document" />;
type Props = {
entityKey: string;
contentState: ContentState;
children: Node;
children: React.ReactNode;
onEdit: (entityType: string) => void;
onRemove: (entityType: string) => void;
textDirectionality: "LTR" | "RTL";
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@types/enzyme": "^3.10.12",
"@types/jest": "^28.1.1",
"@types/jest-axe": "^3.5.3",
"@types/prismjs": "^1.26.0",
"@types/react": "^16.14.26",
"@types/react-dom": "^16.9.16",
"coveralls": "^3.1.1",
Expand Down
2 changes: 1 addition & 1 deletion src/api/behavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
getDefaultKeyBinding,
KeyBindingUtil,
EditorState,
ContentBlock,
} from "draft-js";
import type { ContentBlock } from "draft-js";
import { filterEditorState } from "draftjs-filters";
import { blockDepthStyleFn } from "draftjs-conductor";

Expand Down
2 changes: 1 addition & 1 deletion src/components/Toolbar/MetaToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const MetaToolbar = ({
))}
</ToolbarGroup>
) : null}
<ToolbarGroup>
<ToolbarGroup name="controls">
{controls.map((control, i) => {
if (control.inline || control.block) {
return null;
Expand Down

0 comments on commit 76c3652

Please sign in to comment.