@adminforth/rich-editor 2.0.9 → 2.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ import type { IAdminForth, IHttpServer, AdminForthResource } from "adminforth";
2
+ import type { PluginOptions } from './types.js';
3
+ import { AdminForthPlugin, RateLimiter } from "adminforth";
4
+ export default class RichEditorPlugin extends AdminForthPlugin {
5
+ options: PluginOptions;
6
+ resourceConfig: AdminForthResource;
7
+ uploadPlugin: AdminForthPlugin;
8
+ activationOrder: number;
9
+ attachmentResource: AdminForthResource;
10
+ adminforth: IAdminForth;
11
+ rateLimiter: RateLimiter;
12
+ constructor(options: PluginOptions);
13
+ modifyResourceConfig(adminforth: IAdminForth, resourceConfig: AdminForthResource): Promise<void>;
14
+ validateConfigAfterDiscover(adminforth: IAdminForth, resourceConfig: AdminForthResource): void;
15
+ instanceUniqueRepresentation(pluginOptions: any): string;
16
+ generateRecordContext(record: any, maxFields: number, inputFieldLimit: number, partsCount: number): string;
17
+ setupEndpoints(server: IHttpServer): void;
18
+ }
@@ -0,0 +1,130 @@
1
+ import { CompletionAdapter } from "adminforth";
2
+ import { type PluginsCommonOptions } from "adminforth";
3
+ export interface PluginOptions extends PluginsCommonOptions {
4
+ /**
5
+ * Field where plugin will auto-complete text. Should be string or text field.
6
+ */
7
+ htmlFieldName: string;
8
+ /**
9
+ * Quill toolbar setting, full toolbar:
10
+ *
11
+ * ```
12
+ * [
13
+ * ['bold', 'italic', 'underline', 'strike'], // toggled buttons
14
+ * ['blockquote', 'code-block', 'link'],
15
+ * // [ 'image', 'video', 'formula' ],
16
+ *
17
+ * [{ 'header': 2 }, { 'header': 3 }], // custom button values
18
+ * [{ 'list': 'ordered'}, { 'list': 'bullet' }, { 'list': 'check' }],
19
+ * // [{ 'script': 'sub'}, { 'script': 'super' }], // superscript/subscript
20
+ * // [{ 'indent': '-1'}, { 'indent': '+1' }], // outdent/indent
21
+ * // [{ 'direction': 'rtl' }], // text direction
22
+ * // [{ 'size': ['small', false, 'large', 'huge'] }], // custom dropdown
23
+ * // [{ 'header': [1, 2, 3, 4, 5, 6, false] }],
24
+ * // [{ 'color': [] }, { 'background': [] }], // dropdown with defaults from theme
25
+ * // [{ 'font': [] }],
26
+ * [{ 'align': [] }],
27
+ *
28
+ * ['clean']
29
+ * ]
30
+ *```
31
+ */
32
+ toolbar?: any[];
33
+ /**
34
+ * The completion section is used to define the completion provider and its parameters.
35
+ */
36
+ completion?: {
37
+ /**
38
+ * Adapter for completion.
39
+ */
40
+ adapter: CompletionAdapter;
41
+ /**
42
+ * Expert settings
43
+ */
44
+ expert?: {
45
+ /**
46
+ * Number of tokens to generate. Default is 50. 1 token ~= ¾ words
47
+ */
48
+ maxTokens?: number;
49
+ /**
50
+ * Maximum number of last characters which will be used for completion for target field. Default is 500.
51
+ * Higher value will give better context but will cost more.
52
+ */
53
+ promptInputLimit?: number;
54
+ /**
55
+ * Time in ms to wait after user stops typing before sending request to completion provider. Default is 300 ms.
56
+ */
57
+ debounceTime?: number;
58
+ /**
59
+ * When completion is made, this plugin passes non-empty fields of the record to the LLM model for record context understanding.
60
+ */
61
+ recordContext?: {
62
+ /**
63
+ * Using this field you can limit number of fields passed to the model.
64
+ * Default is 5.
65
+ * Completion field is not included in this limit.
66
+ * Set to 0 to disable context passing at all.
67
+ * If count of fields exceeds this number, longest fields will be selected.
68
+ * If some of values will exceed maxFieldLength, it will be smartly truncated by splitting ito splitParts, taking their
69
+ * starting substring and joining back with '...'.
70
+ */
71
+ maxFields?: number;
72
+ /**
73
+ * Limit of input field value. Default is 300. If field is longer, it will be truncated.
74
+ */
75
+ maxFieldLength?: number;
76
+ /**
77
+ * How many parts to split field value if it exceeds maxFieldLength. Default is 5.
78
+ */
79
+ splitParts?: number;
80
+ };
81
+ };
82
+ /**
83
+ * Since AI generation can be expensive, we can limit the number of requests per IP.
84
+ * Completion will simply stop working when limit is reached so user will not be bothered with error messages.
85
+ */
86
+ rateLimit?: {
87
+ /**
88
+ * E.g. 5/1d - 5 requests per day
89
+ * 3/1h - 3 requests per hour
90
+ */
91
+ limit: string;
92
+ /**
93
+ * Not used now
94
+ * Message shown to user when rate limit is reached
95
+ */
96
+ errorMessage: string;
97
+ };
98
+ };
99
+ /**
100
+ * Allows to attach images to the HTML text
101
+ * Requires to have a separate resource with Upload Plugin installed on attachment field.
102
+ * Each attachment used in HTML will create one record in the attachment resource.
103
+ */
104
+ attachments?: {
105
+ /**
106
+ * Resource name where images are stored. Should point to the existing resource.
107
+ */
108
+ attachmentResource: string;
109
+ /**
110
+ * Field name in the attachment resource where image is stored. Should point to the existing field in the attachment resource.
111
+ * Also there should be upload plugin installed on this field.
112
+ */
113
+ attachmentFieldName: string;
114
+ /**
115
+ * When attachment is created, it will be linked to the record, by storing id of the record with editor in attachment resource.
116
+ * Here you define the field name where this id will be stored.
117
+ *
118
+ * Linking is needed to remove all attachments when record is deleted.
119
+ *
120
+ * For example when RichEditor installed on description field of apartment resource,
121
+ * field in attachment resource described hear will store id of apartment record.
122
+ */
123
+ attachmentRecordIdFieldName: string;
124
+ /**
125
+ * When attachment is created, it will be linked to the resource, by storing id of the resource with editor in attachment resource.
126
+ * For example when RichEditor installed on description field of apartment resource, it will store id of apartment resource.
127
+ */
128
+ attachmentResourceIdFieldName: string;
129
+ };
130
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/rich-editor",
3
- "version": "2.0.9",
3
+ "version": "2.0.10",
4
4
  "description": "Rich editor plugin for adminforth",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/tsconfig.json CHANGED
@@ -51,7 +51,7 @@
51
51
  // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
52
52
 
53
53
  /* Emit */
54
- // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
54
+ "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
55
55
  // "declarationMap": true, /* Create sourcemaps for d.ts files. */
56
56
  // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
57
57
  // "sourceMap": true, /* Create source map files for emitted JavaScript files. */