@sckyzo/cosmos-react 0.5.0 → 0.6.0

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.
@@ -4,11 +4,18 @@ import { JSONContent } from '@tiptap/react';
4
4
  import { FieldSize } from '../index.cjs';
5
5
 
6
6
  /** The buttons a toolbar can hold, in the order `RICH_TEXT_ACTIONS` lists them. */
7
- type RichTextAction = 'bold' | 'italic' | 'strike' | 'heading' | 'bulletList' | 'orderedList' | 'blockquote' | 'code' | 'link' | 'undo' | 'redo';
7
+ type RichTextAction = 'bold' | 'italic' | 'underline' | 'strike' | 'heading' | 'bulletList' | 'orderedList' | 'blockquote' | 'code' | 'codeBlock' | 'align' | 'link' | 'image' | 'undo' | 'redo';
8
8
  declare const RICH_TEXT_ACTIONS: readonly RichTextAction[];
9
+ /** The items of the menus a button opens: one of them is checked. */
10
+ type RichTextChoice = 'paragraph' | 'heading1' | 'heading2' | 'heading3' | 'alignStart' | 'alignCenter' | 'alignEnd';
9
11
 
10
- /** Every text the editor draws itself, so a host can translate it. All optional. */
11
- type RichTextLabels = Partial<Record<RichTextAction, string>> & {
12
+ type Named = RichTextAction | RichTextChoice;
13
+ /**
14
+ * Every text the editor draws itself, so a host can translate it. All optional. The buttons are
15
+ * named by their action (`bold`, `heading`, `align`, `image`…) and the items of the heading and
16
+ * alignment menus by their choice (`paragraph`, `heading1`, `alignCenter`…).
17
+ */
18
+ type RichTextLabels = Partial<Record<Named, string>> & {
12
19
  /** Accessible name of the toolbar. Default `Text formatting`. */
13
20
  toolbar?: string;
14
21
  /** Accessible name of the field where a link's URL is typed. Default `Link URL`. */
@@ -21,6 +28,20 @@ type RichTextLabels = Partial<Record<RichTextAction, string>> & {
21
28
  linkRemove?: string;
22
29
  /** Shown when the URL is refused. Default `Enter an http(s), mailto or relative link.` */
23
30
  linkInvalid?: string;
31
+ /** Accessible name of the image popover. Default `Image details`. */
32
+ imageDialog?: string;
33
+ /** Label of the field where an image's URL is typed. Default `Image URL`. */
34
+ imageUrl?: string;
35
+ /** Label of the description field, the image's `alt`. Default `Description (alt text)`. */
36
+ imageAlt?: string;
37
+ /** Label of the box that marks an image as decorative. Default `Decorative image, no description`. */
38
+ imageDecorative?: string;
39
+ /** Default `Apply`. */
40
+ imageApply?: string;
41
+ /** Shown when the URL is refused. Default `Enter an http(s) image address.` */
42
+ imageInvalid?: string;
43
+ /** Shown when an image has no description and is not marked decorative. Default `Describe the image, or mark it decorative.` */
44
+ imageAltRequired?: string;
24
45
  };
25
46
 
26
47
  /** What `value` and `onChange` carry: the HTML string, or the ProseMirror JSON document. */
@@ -47,7 +68,7 @@ type RichTextEditorProps<F extends RichTextFormat = 'html'> = {
47
68
  * the link for `bubble`. Ignored by `minimal`.
48
69
  */
49
70
  toolbar?: readonly RichTextAction[];
50
- /** Replaces any text the editor draws itself: the buttons, their tooltips, the link field. */
71
+ /** Replaces any text the editor draws itself: the buttons, their tooltips and menus, the link and image fields. */
51
72
  labels?: RichTextLabels;
52
73
  label?: string;
53
74
  description?: string;
@@ -84,15 +105,20 @@ type RichTextEditorProps<F extends RichTextFormat = 'html'> = {
84
105
  className?: string;
85
106
  };
86
107
  /**
87
- * A formatted text field, built on Tiptap: bold, italic, strike, headings, lists, quote, code,
88
- * links, undo and redo, behind a toolbar, a bubble over the selection, or only keyboard shortcuts.
89
- * Part of the `@sckyzo/cosmos-react/editor` entry, which needs the optional peer dependencies
90
- * (`@tiptap/react`, `@tiptap/starter-kit`, `@tiptap/extensions`, `@tiptap/core`, `@tiptap/pm`).
108
+ * A formatted text field, built on Tiptap: bold, italic, underline, strike, headings, lists,
109
+ * quote, code and code blocks, alignment, links, images, undo and redo, behind a toolbar, a bubble
110
+ * over the selection, or only keyboard shortcuts. Part of the `@sckyzo/cosmos-react/editor` entry,
111
+ * which needs the optional peer dependencies (`@tiptap/react`, `@tiptap/starter-kit`,
112
+ * `@tiptap/extensions`, `@tiptap/extension-text-align`, `@tiptap/extension-image`,
113
+ * `@tiptap/core`, `@tiptap/pm`).
91
114
  *
92
- * The schema holds paragraphs, headings (2 and 3), bullet and numbered lists, quotes, hard
93
- * breaks and the marks above: nothing else survives a paste or `value`. Links go through
94
- * `isSafeLinkUrl` (http(s), mailto, relative). That is the editor's guarantee, not the server's:
95
- * the HTML a host stores has to be sanitised again where it is read back.
115
+ * The schema holds paragraphs, headings (1 to 3), bullet and numbered lists, quotes, code blocks,
116
+ * hard breaks, images and the marks above: nothing else survives a paste or `value`, and no image
117
+ * comes in by paste or drop (the toolbar's field and the host's `value` are its ways in). Links go
118
+ * through `isSafeLinkUrl` (http(s), mailto, relative) and an image's source through `isHttpUrl`
119
+ * (http(s) only); alignment is `center` or `end`, written as `style="text-align: …"`. That is the
120
+ * editor's guarantee, not the server's: the HTML a host stores has to be sanitised again where it
121
+ * is read back.
96
122
  */
97
123
  declare function RichTextEditor<F extends RichTextFormat = 'html'>({ format, value, defaultValue, onChange, variant, toolbar, labels: labelProps, label, description, error, required, labelTrailing, size, placeholder, readOnly, disabled, maxLength, rows, autoFocus, id, name, 'aria-label': ariaLabel, className, }: RichTextEditorProps<F>): react.JSX.Element;
98
124
 
@@ -4,11 +4,18 @@ import { JSONContent } from '@tiptap/react';
4
4
  import { FieldSize } from '../index.js';
5
5
 
6
6
  /** The buttons a toolbar can hold, in the order `RICH_TEXT_ACTIONS` lists them. */
7
- type RichTextAction = 'bold' | 'italic' | 'strike' | 'heading' | 'bulletList' | 'orderedList' | 'blockquote' | 'code' | 'link' | 'undo' | 'redo';
7
+ type RichTextAction = 'bold' | 'italic' | 'underline' | 'strike' | 'heading' | 'bulletList' | 'orderedList' | 'blockquote' | 'code' | 'codeBlock' | 'align' | 'link' | 'image' | 'undo' | 'redo';
8
8
  declare const RICH_TEXT_ACTIONS: readonly RichTextAction[];
9
+ /** The items of the menus a button opens: one of them is checked. */
10
+ type RichTextChoice = 'paragraph' | 'heading1' | 'heading2' | 'heading3' | 'alignStart' | 'alignCenter' | 'alignEnd';
9
11
 
10
- /** Every text the editor draws itself, so a host can translate it. All optional. */
11
- type RichTextLabels = Partial<Record<RichTextAction, string>> & {
12
+ type Named = RichTextAction | RichTextChoice;
13
+ /**
14
+ * Every text the editor draws itself, so a host can translate it. All optional. The buttons are
15
+ * named by their action (`bold`, `heading`, `align`, `image`…) and the items of the heading and
16
+ * alignment menus by their choice (`paragraph`, `heading1`, `alignCenter`…).
17
+ */
18
+ type RichTextLabels = Partial<Record<Named, string>> & {
12
19
  /** Accessible name of the toolbar. Default `Text formatting`. */
13
20
  toolbar?: string;
14
21
  /** Accessible name of the field where a link's URL is typed. Default `Link URL`. */
@@ -21,6 +28,20 @@ type RichTextLabels = Partial<Record<RichTextAction, string>> & {
21
28
  linkRemove?: string;
22
29
  /** Shown when the URL is refused. Default `Enter an http(s), mailto or relative link.` */
23
30
  linkInvalid?: string;
31
+ /** Accessible name of the image popover. Default `Image details`. */
32
+ imageDialog?: string;
33
+ /** Label of the field where an image's URL is typed. Default `Image URL`. */
34
+ imageUrl?: string;
35
+ /** Label of the description field, the image's `alt`. Default `Description (alt text)`. */
36
+ imageAlt?: string;
37
+ /** Label of the box that marks an image as decorative. Default `Decorative image, no description`. */
38
+ imageDecorative?: string;
39
+ /** Default `Apply`. */
40
+ imageApply?: string;
41
+ /** Shown when the URL is refused. Default `Enter an http(s) image address.` */
42
+ imageInvalid?: string;
43
+ /** Shown when an image has no description and is not marked decorative. Default `Describe the image, or mark it decorative.` */
44
+ imageAltRequired?: string;
24
45
  };
25
46
 
26
47
  /** What `value` and `onChange` carry: the HTML string, or the ProseMirror JSON document. */
@@ -47,7 +68,7 @@ type RichTextEditorProps<F extends RichTextFormat = 'html'> = {
47
68
  * the link for `bubble`. Ignored by `minimal`.
48
69
  */
49
70
  toolbar?: readonly RichTextAction[];
50
- /** Replaces any text the editor draws itself: the buttons, their tooltips, the link field. */
71
+ /** Replaces any text the editor draws itself: the buttons, their tooltips and menus, the link and image fields. */
51
72
  labels?: RichTextLabels;
52
73
  label?: string;
53
74
  description?: string;
@@ -84,15 +105,20 @@ type RichTextEditorProps<F extends RichTextFormat = 'html'> = {
84
105
  className?: string;
85
106
  };
86
107
  /**
87
- * A formatted text field, built on Tiptap: bold, italic, strike, headings, lists, quote, code,
88
- * links, undo and redo, behind a toolbar, a bubble over the selection, or only keyboard shortcuts.
89
- * Part of the `@sckyzo/cosmos-react/editor` entry, which needs the optional peer dependencies
90
- * (`@tiptap/react`, `@tiptap/starter-kit`, `@tiptap/extensions`, `@tiptap/core`, `@tiptap/pm`).
108
+ * A formatted text field, built on Tiptap: bold, italic, underline, strike, headings, lists,
109
+ * quote, code and code blocks, alignment, links, images, undo and redo, behind a toolbar, a bubble
110
+ * over the selection, or only keyboard shortcuts. Part of the `@sckyzo/cosmos-react/editor` entry,
111
+ * which needs the optional peer dependencies (`@tiptap/react`, `@tiptap/starter-kit`,
112
+ * `@tiptap/extensions`, `@tiptap/extension-text-align`, `@tiptap/extension-image`,
113
+ * `@tiptap/core`, `@tiptap/pm`).
91
114
  *
92
- * The schema holds paragraphs, headings (2 and 3), bullet and numbered lists, quotes, hard
93
- * breaks and the marks above: nothing else survives a paste or `value`. Links go through
94
- * `isSafeLinkUrl` (http(s), mailto, relative). That is the editor's guarantee, not the server's:
95
- * the HTML a host stores has to be sanitised again where it is read back.
115
+ * The schema holds paragraphs, headings (1 to 3), bullet and numbered lists, quotes, code blocks,
116
+ * hard breaks, images and the marks above: nothing else survives a paste or `value`, and no image
117
+ * comes in by paste or drop (the toolbar's field and the host's `value` are its ways in). Links go
118
+ * through `isSafeLinkUrl` (http(s), mailto, relative) and an image's source through `isHttpUrl`
119
+ * (http(s) only); alignment is `center` or `end`, written as `style="text-align: …"`. That is the
120
+ * editor's guarantee, not the server's: the HTML a host stores has to be sanitised again where it
121
+ * is read back.
96
122
  */
97
123
  declare function RichTextEditor<F extends RichTextFormat = 'html'>({ format, value, defaultValue, onChange, variant, toolbar, labels: labelProps, label, description, error, required, labelTrailing, size, placeholder, readOnly, disabled, maxLength, rows, autoFocus, id, name, 'aria-label': ariaLabel, className, }: RichTextEditorProps<F>): react.JSX.Element;
98
124