mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
758d4edbb9
* Upgrade @typescript-eslint dependencies from v6.21.0 to v8.33.0 - Updated @typescript-eslint/eslint-plugin from ^6.21.0 to ^8.33.0 - Updated @typescript-eslint/parser from ^6.21.0 to ^8.33.0 - Tested linting functionality to ensure compatibility - This brings the latest TypeScript ESLint features and bug fixes * lint * tsc --------- Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com> Co-authored-by: Tom Moor <tom@getoutline.com>
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import size from "lodash/size";
|
|
import { Node } from "prosemirror-model";
|
|
import { addAttributeOptions } from "sequelize-typescript";
|
|
import { ProsemirrorData } from "@shared/types";
|
|
import { ProsemirrorHelper } from "@shared/utils/ProsemirrorHelper";
|
|
import { schema } from "@server/editor";
|
|
|
|
/**
|
|
* A decorator that validates the size of the text within a prosemirror data
|
|
* object, taking into account unicode characters of variable lengths.
|
|
*/
|
|
export default function TextLength({
|
|
msg,
|
|
min = 0,
|
|
max,
|
|
}: {
|
|
msg?: string;
|
|
min?: number;
|
|
max: number;
|
|
}): (target: any, propertyName: string) => void {
|
|
return (target: any, propertyName: string) =>
|
|
addAttributeOptions(target, propertyName, {
|
|
validate: {
|
|
validLength(value: ProsemirrorData) {
|
|
let text;
|
|
|
|
try {
|
|
text = ProsemirrorHelper.toPlainText(
|
|
Node.fromJSON(schema, value),
|
|
schema
|
|
);
|
|
} catch (_err) {
|
|
throw new Error("Invalid data");
|
|
}
|
|
|
|
if (size(text) > max || size(text) < min) {
|
|
throw new Error(msg);
|
|
}
|
|
},
|
|
},
|
|
});
|
|
}
|