Skip to content

Commit

Permalink
Merge branch 'develop' of gurusainath:makeplane/plane into feat-displ…
Browse files Browse the repository at this point in the history
…ay-properties-module-cycle
  • Loading branch information
gurusainath committed Feb 21, 2024
2 parents 9fbc00d + 56f4df4 commit 49c7c90
Show file tree
Hide file tree
Showing 3 changed files with 249 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/editor/core/src/ui/extensions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import { DeleteImage } from "src/types/delete-image";
import { IMentionSuggestion } from "src/types/mention-suggestion";
import { RestoreImage } from "src/types/restore-image";
import { CustomLinkExtension } from "src/ui/extensions/custom-link";
import { CustomCodeInlineExtension } from "./code-inline";
import { CustomCodeInlineExtension } from "src/ui/extensions/code-inline";
import { CustomTypographyExtension } from "src/ui/extensions/typography";

export const CoreEditorExtensions = (
mentionConfig: {
Expand Down Expand Up @@ -79,6 +80,7 @@ export const CoreEditorExtensions = (
"text-custom-primary-300 underline underline-offset-[3px] hover:text-custom-primary-500 transition-colors cursor-pointer",
},
}),
CustomTypographyExtension,
ImageExtension(deleteFile, restoreFile, cancelUploadImage).configure({
HTMLAttributes: {
class: "rounded-lg border border-custom-border-300",
Expand Down
109 changes: 109 additions & 0 deletions packages/editor/core/src/ui/extensions/typography/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { Extension } from "@tiptap/core";
import {
TypographyOptions,
emDash,
ellipsis,
leftArrow,
rightArrow,
copyright,
trademark,
servicemark,
registeredTrademark,
oneHalf,
plusMinus,
notEqual,
laquo,
raquo,
multiplication,
superscriptTwo,
superscriptThree,
oneQuarter,
threeQuarters,
impliesArrowRight,
} from "src/ui/extensions/typography/inputRules";

export const CustomTypographyExtension = Extension.create<TypographyOptions>({
name: "typography",

addInputRules() {
const rules = [];

if (this.options.emDash !== false) {
rules.push(emDash(this.options.emDash));
}

if (this.options.impliesArrowRight !== false) {
rules.push(impliesArrowRight(this.options.impliesArrowRight));
}

if (this.options.ellipsis !== false) {
rules.push(ellipsis(this.options.ellipsis));
}

if (this.options.leftArrow !== false) {
rules.push(leftArrow(this.options.leftArrow));
}

if (this.options.rightArrow !== false) {
rules.push(rightArrow(this.options.rightArrow));
}

if (this.options.copyright !== false) {
rules.push(copyright(this.options.copyright));
}

if (this.options.trademark !== false) {
rules.push(trademark(this.options.trademark));
}

if (this.options.servicemark !== false) {
rules.push(servicemark(this.options.servicemark));
}

if (this.options.registeredTrademark !== false) {
rules.push(registeredTrademark(this.options.registeredTrademark));
}

if (this.options.oneHalf !== false) {
rules.push(oneHalf(this.options.oneHalf));
}

if (this.options.plusMinus !== false) {
rules.push(plusMinus(this.options.plusMinus));
}

if (this.options.notEqual !== false) {
rules.push(notEqual(this.options.notEqual));
}

if (this.options.laquo !== false) {
rules.push(laquo(this.options.laquo));
}

if (this.options.raquo !== false) {
rules.push(raquo(this.options.raquo));
}

if (this.options.multiplication !== false) {
rules.push(multiplication(this.options.multiplication));
}

if (this.options.superscriptTwo !== false) {
rules.push(superscriptTwo(this.options.superscriptTwo));
}

if (this.options.superscriptThree !== false) {
rules.push(superscriptThree(this.options.superscriptThree));
}

if (this.options.oneQuarter !== false) {
rules.push(oneQuarter(this.options.oneQuarter));
}

if (this.options.threeQuarters !== false) {
rules.push(threeQuarters(this.options.threeQuarters));
}

return rules;
},
});
137 changes: 137 additions & 0 deletions packages/editor/core/src/ui/extensions/typography/inputRules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import { textInputRule } from "@tiptap/core";

export interface TypographyOptions {
emDash: false | string;
ellipsis: false | string;
leftArrow: false | string;
rightArrow: false | string;
copyright: false | string;
trademark: false | string;
servicemark: false | string;
registeredTrademark: false | string;
oneHalf: false | string;
plusMinus: false | string;
notEqual: false | string;
laquo: false | string;
raquo: false | string;
multiplication: false | string;
superscriptTwo: false | string;
superscriptThree: false | string;
oneQuarter: false | string;
threeQuarters: false | string;
impliesArrowRight: false | string;
}

export const emDash = (override?: string) =>
textInputRule({
find: /--$/,
replace: override ?? "—",
});

export const impliesArrowRight = (override?: string) =>
textInputRule({
find: /=>$/,
replace: override ?? "⇒",
});

export const leftArrow = (override?: string) =>
textInputRule({
find: /<-$/,
replace: override ?? "←",
});

export const rightArrow = (override?: string) =>
textInputRule({
find: /->$/,
replace: override ?? "→",
});

export const ellipsis = (override?: string) =>
textInputRule({
find: /\.\.\.$/,
replace: override ?? "…",
});

export const copyright = (override?: string) =>
textInputRule({
find: /\(c\)$/,
replace: override ?? "©",
});

export const trademark = (override?: string) =>
textInputRule({
find: /\(tm\)$/,
replace: override ?? "™",
});

export const servicemark = (override?: string) =>
textInputRule({
find: /\(sm\)$/,
replace: override ?? "℠",
});

export const registeredTrademark = (override?: string) =>
textInputRule({
find: /\(r\)$/,
replace: override ?? "®",
});

export const oneHalf = (override?: string) =>
textInputRule({
find: /(?:^|\s)(1\/2)\s$/,
replace: override ?? "½",
});

export const plusMinus = (override?: string) =>
textInputRule({
find: /\+\/-$/,
replace: override ?? "±",
});

export const notEqual = (override?: string) =>
textInputRule({
find: /!=$/,
replace: override ?? "≠",
});

export const laquo = (override?: string) =>
textInputRule({
find: /<<$/,
replace: override ?? "«",
});

export const raquo = (override?: string) =>
textInputRule({
find: />>$/,
replace: override ?? "»",
});

export const multiplication = (override?: string) =>
textInputRule({
find: /\d+\s?([*x])\s?\d+$/,
replace: override ?? "×",
});

export const superscriptTwo = (override?: string) =>
textInputRule({
find: /\^2$/,
replace: override ?? "²",
});

export const superscriptThree = (override?: string) =>
textInputRule({
find: /\^3$/,
replace: override ?? "³",
});

export const oneQuarter = (override?: string) =>
textInputRule({
find: /(?:^|\s)(1\/4)\s$/,
replace: override ?? "¼",
});

export const threeQuarters = (override?: string) =>
textInputRule({
find: /(?:^|\s)(3\/4)\s$/,
replace: override ?? "¾",
});

0 comments on commit 49c7c90

Please sign in to comment.