@prismicio/editor-fields 0.4.30 → 0.4.31

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.
@@ -1,12 +1,12 @@
1
1
  /// <reference types="react" />
2
2
  import type { MediaAssetType } from "./core/MediaLibrary/hooks/mediaLibraryData";
3
3
  export type EditorConfig = {
4
+ baseUrl: URL;
4
5
  embedApiEndpoint: URL;
5
6
  unsplashApiBaseUrl: URL;
6
7
  authStrategy: AuthStrategy;
7
- baseUrl: URL;
8
8
  } & OptionalConfigs;
9
- type OptionalConfigs = SearchDocuments & MediaLibrary & UIDField & Analytics & ErrorTracking & IntegrationFields;
9
+ type OptionalConfigs = SearchDocuments & MediaLibrary & UIDField & Analytics & ErrorTracking & IntegrationFields & LayoutConfig;
10
10
  type MediaLibrary = {
11
11
  mediaLibrary?: never;
12
12
  } | {
@@ -43,6 +43,12 @@ type IntegrationFields = {
43
43
  integrationFieldsApiBaseUrl: URL;
44
44
  repository: string;
45
45
  };
46
+ interface LayoutConfig {
47
+ /**
48
+ * Teaches fields about their containing scrolling element.
49
+ */
50
+ scrollOffsetTop?: number;
51
+ }
46
52
  interface OnAnalyticsEvent {
47
53
  (event: "Media Library Search", args: {
48
54
  useOpenSearch: "1" | "0";
@@ -18,10 +18,6 @@ interface MediaLibraryContextValue {
18
18
  onFilesUpload: (files: File[]) => void;
19
19
  isUploading: boolean;
20
20
  uploadingFiles: UploadFile[];
21
- selectedMediaIds: Set<string>;
22
- addMediaItemSelection: (id: string) => void;
23
- removeMediaItemSelection: (id: string) => void;
24
- replaceMediaItemSelection: (id: string) => void;
25
21
  isMediaCacheInvalid: boolean;
26
22
  isMediaRevalidationInProgress: boolean;
27
23
  revalidateMedia: () => void;
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import type { SelectionManagerProviderProps, SelectionStateListener, UseSelectionManager } from "./SelectionManagerTypes";
3
+ export declare function SelectionManagerProvider(props: SelectionManagerProviderProps): JSX.Element;
4
+ interface useSelectionManagerArgs {
5
+ totalItemCount?: number;
6
+ onChangeSelection?: SelectionStateListener;
7
+ }
8
+ export declare function useSelectionManager(args?: useSelectionManagerArgs): UseSelectionManager;
9
+ export {};
@@ -0,0 +1,93 @@
1
+ import type { PropsWithChildren } from "react";
2
+ export type ID = string;
3
+ export interface ToggleSelectionArgs {
4
+ /**
5
+ * The ID of the item to toggle selection for.
6
+ */
7
+ id: ID;
8
+ /**
9
+ * Indicates if the selection is a single selection.
10
+ * @default false
11
+ */
12
+ isSingleSelection?: boolean;
13
+ /**
14
+ * Indicates if the meta key (e.g., Command on Mac, Ctrl on Windows) was pressed.
15
+ * When `true`, single selection gets ignored if enabled.
16
+ * @default false
17
+ */
18
+ metaKey?: boolean;
19
+ /**
20
+ * Indicates if the shift key was pressed.
21
+ * When `true`, and `ids` are defined - range selection gets enabled.
22
+ * @default false
23
+ */
24
+ shiftKey?: boolean;
25
+ /**
26
+ * A sorted array of the item IDs. This is required with range selection.
27
+ */
28
+ ids?: ID[];
29
+ }
30
+ export type SelectionManager = {
31
+ /**
32
+ * Checks if an item is selected.
33
+ * @param id - The ID of the item to check.
34
+ * @returns `true` if the item is selected, otherwise `false`.
35
+ */
36
+ isSelected: (id: ID) => boolean;
37
+ /**
38
+ * Toggles the selection state of an item.
39
+ * @param args - Arguments for toggling selection.
40
+ * @returns `true` if the item state is selected, otherwise `false`.
41
+ */
42
+ toggleSelection: (args: ToggleSelectionArgs) => boolean;
43
+ /**
44
+ * Toggles the select all state.
45
+ */
46
+ toggleSelectAll: () => void;
47
+ /**
48
+ * Clears all the selection.
49
+ */
50
+ clearSelection: () => void;
51
+ /**
52
+ * Sets the total count of items available for the selectable entity.
53
+ * @param count - The total item count.
54
+ */
55
+ setTotalItemCount: (count: number) => void;
56
+ /**
57
+ * Gets the current selection state. This is used when performing any action with the selection.
58
+ * @returns The selection state object.
59
+ */
60
+ getSelectionState: () => {
61
+ selectedIds: ID[];
62
+ excludedIds: ID[];
63
+ isAllSelected: boolean;
64
+ selectedCount: number;
65
+ };
66
+ /**
67
+ * Count of selected items.
68
+ */
69
+ selectedCount: number;
70
+ totalItemCount: number;
71
+ isSelectAllEnabled: boolean;
72
+ state: CoreSelectionState;
73
+ };
74
+ export interface CoreSelectionState {
75
+ /**
76
+ * Set of selected IDs.
77
+ */
78
+ selectedIds: Set<ID>;
79
+ /**
80
+ * Set of excluded IDs - only aplicable when `isAllSelected=true`
81
+ */
82
+ excludedIds: Set<ID>;
83
+ /**
84
+ * Indicates if all items are selected.
85
+ */
86
+ isAllSelected: boolean;
87
+ }
88
+ export interface SelectionManagerProviderProps extends PropsWithChildren {
89
+ initialTotalItemCount?: number;
90
+ isSelectAllEnabled?: boolean;
91
+ }
92
+ export type UseSelectionManager = Omit<SelectionManager, "registerListener" | "setTotalItemCount" | "totalItemCount" | "state"> & Pick<CoreSelectionState, "isAllSelected">;
93
+ export type SelectionStateListener = (state: ReturnType<SelectionManager["getSelectionState"]>) => void;
@@ -0,0 +1 @@
1
+ export * from "./SelectionManager";
@@ -1,4 +1,4 @@
1
- import type { ImageContent, ImageContentView } from "@prismicio/types-internal/lib/content";
1
+ import type { ImageBlock, ImageContent, ImageContentView } from "@prismicio/types-internal/lib/content";
2
2
  import type { Image, ImageConstraint } from "@prismicio/types-internal/lib/customtypes";
3
3
  import type { MediaAsset, MediaAssetOrExternalImage } from "./MediaLibrary/hooks/mediaLibraryData";
4
4
  /**
@@ -20,7 +20,7 @@ export interface CropperImage {
20
20
  labels: ImageLabel;
21
21
  }
22
22
  type ImageLabel = [thumbnailName: string | undefined, size: string | undefined];
23
- export declare function getImageLabel(thumbnail: Thumbnail, content: ImageContent | undefined, contentView: ImageContentView | undefined): ImageLabel;
23
+ export declare function getImageLabel(thumbnail: Thumbnail, content: ImageContent | ImageBlockData | undefined, contentView: ImageContentView | undefined): ImageLabel;
24
24
  export declare function getImageThumbnails(field: Image): readonly Thumbnail[];
25
25
  export declare function getImageContentViews(field: Image, content: ImageContent): readonly [ImageContentView, ...(ImageContentView | undefined)[]];
26
26
  export declare function updateImageContentAlt(thumbnailName: string, content: ImageContent, contentView: ImageContentView, value: string): ImageContent;
@@ -54,4 +54,5 @@ export declare function fitImage(extImage: {
54
54
  };
55
55
  };
56
56
  export declare function getTitleWithoutExtension(selectedMedia?: MediaAsset): string;
57
+ export type ImageBlockData = ImageBlock["data"];
57
58
  export {};
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  interface ImageAltControlProps {
3
3
  id?: string;
4
- readOnly: boolean;
4
+ readOnly?: boolean;
5
5
  altText: string;
6
6
  onValueChange: (value: string) => void;
7
7
  selected?: boolean;
@@ -1,10 +1,9 @@
1
- import type { ImageContent } from "@prismicio/types-internal/lib/content";
2
1
  import { type ReactNode } from "react";
3
2
  import type { CropperImage } from "../../../core/imageUtils";
4
3
  import type { MediaAssetOrExternalImage } from "../../../core/MediaLibrary/hooks/mediaLibraryData";
5
4
  import { type CroppedImages } from "../CropperDialog";
6
5
  interface ImageFieldCardProps {
7
- content: ImageContent | undefined;
6
+ url: string | undefined;
8
7
  selected?: boolean;
9
8
  fieldLabel: string;
10
9
  readOnly: boolean;
@@ -1,5 +1,6 @@
1
1
  import type { ImageContent, ImageContentView } from "@prismicio/types-internal/lib/content";
2
2
  import type { Image } from "@prismicio/types-internal/lib/customtypes";
3
+ import { type ImageBlockData } from "../../../core/imageUtils";
3
4
  export interface Point {
4
5
  x: number;
5
6
  y: number;
@@ -30,12 +31,67 @@ export interface CroppedImage {
30
31
  height: number;
31
32
  }
32
33
  interface UpdateImageArgs {
33
- field?: Image;
34
+ field: Image;
34
35
  content: ImageContent;
35
36
  thumbnail: string;
36
37
  croppedImage: CroppedImage;
37
38
  }
38
- export declare function updateImage(args: UpdateImageArgs): ImageContent;
39
+ export declare function updateImage(args: UpdateImageArgs): {
40
+ origin: {
41
+ id: string;
42
+ url: string;
43
+ width: number;
44
+ height: number;
45
+ };
46
+ width: number;
47
+ height: number;
48
+ edit: {
49
+ zoom: number;
50
+ crop: {
51
+ x: number;
52
+ y: number;
53
+ };
54
+ background: string;
55
+ };
56
+ } & {
57
+ url?: string | undefined;
58
+ credits?: string | null | undefined;
59
+ alt?: string | null | undefined;
60
+ provider?: string | null | undefined;
61
+ } & {
62
+ thumbnails?: {
63
+ [x: string]: {
64
+ origin: {
65
+ id: string;
66
+ url: string;
67
+ width: number;
68
+ height: number;
69
+ };
70
+ width: number;
71
+ height: number;
72
+ edit: {
73
+ zoom: number;
74
+ crop: {
75
+ x: number;
76
+ y: number;
77
+ };
78
+ background: string;
79
+ };
80
+ } & {
81
+ url?: string | undefined;
82
+ credits?: string | null | undefined;
83
+ alt?: string | null | undefined;
84
+ provider?: string | null | undefined;
85
+ };
86
+ } | undefined;
87
+ } & {
88
+ __TYPE__: "ImageContent";
89
+ };
90
+ interface UpdateImageMainThumbnailArgs<T> {
91
+ content: T;
92
+ croppedImage: CroppedImage;
93
+ }
94
+ export declare function updateImageMainThumbnail<T extends ImageContent | ImageBlockData>(args: UpdateImageMainThumbnailArgs<T>): T;
39
95
  interface BuildCropUrlArgs {
40
96
  origin: ImageContent["origin"];
41
97
  /** Image crop parameters */
@@ -2,9 +2,9 @@
2
2
  import type { LinkContent } from "@prismicio/types-internal/lib/content";
3
3
  import type { Link } from "@prismicio/types-internal/lib/customtypes";
4
4
  interface LinkFieldProps {
5
- id: string;
5
+ id?: string;
6
6
  field: Link;
7
- readOnly: boolean;
7
+ readOnly?: boolean;
8
8
  content: LinkContent | undefined;
9
9
  onContentChange: (content: LinkContent | undefined) => void;
10
10
  }
@@ -2,6 +2,13 @@ import type { TextBlock } from "@prismicio/types-internal/lib/content";
2
2
  import type { RichTextNodeType } from "@prismicio/types-internal/lib/customtypes";
3
3
  import type { Node as ProsemirrorNode, Schema } from "prosemirror-model";
4
4
  import type { Direction } from "../globalExtensions/TextDirection";
5
+ export declare const prismicToProsemirrorMark: {
6
+ strong: "bold";
7
+ label: "label";
8
+ em: "em";
9
+ hyperlink: "hyperlink";
10
+ "list-item": undefined;
11
+ };
5
12
  declare const EditorText: {
6
13
  name: string;
7
14
  component: import("@tiptap/core").Node<any, any>;
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import type { ImageBlockData } from "../../../../core/imageUtils";
3
+ type LinkTo = ImageBlockData["linkTo"];
4
+ interface ImageLinkControlProps {
5
+ linkTo: LinkTo;
6
+ onLinkToChange: (linkTo: LinkTo) => void;
7
+ }
8
+ export declare function ImageLinkControl(props: ImageLinkControlProps): JSX.Element;
9
+ export {};
@@ -1,10 +1,10 @@
1
1
  /// <reference types="react" />
2
- import type { ImageContent } from "@prismicio/types-internal/lib/content";
3
2
  import type { Node as ProseMirrorNode } from "@tiptap/pm/model";
4
3
  import { type NodeViewProps } from "@tiptap/react";
4
+ import { type ImageBlockData } from "../../../../core/imageUtils";
5
5
  interface ImageNode extends ProseMirrorNode {
6
6
  attrs: {
7
- content: ImageContent | undefined;
7
+ content: ImageBlockData | undefined;
8
8
  };
9
9
  }
10
10
  export interface ImageViewProps extends NodeViewProps {
@@ -1,9 +1,9 @@
1
- import type { ImageContent } from "@prismicio/types-internal/lib/content";
1
+ import { type ImageBlockData } from "../../../../core/imageUtils";
2
2
  import type { MediaAssetOrExternalImage } from "../../../../core/MediaLibrary/hooks/mediaLibraryData";
3
3
  import type { CroppedImages } from "../../../ImageField/CropperDialog";
4
4
  import type { ImageViewProps } from "./ImageView";
5
5
  interface useImageViewProps {
6
- content: ImageContent | undefined;
6
+ content: ImageBlockData | undefined;
7
7
  thumbnail: {
8
8
  width: number | undefined;
9
9
  height: number | undefined;
@@ -17,7 +17,7 @@ export declare function useImageView(props: useImageViewProps): {
17
17
  croppedImages: CroppedImages;
18
18
  }) => void;
19
19
  isUpdating: boolean;
20
- updateContent: (content?: ImageContent) => void;
20
+ updateContent: (content?: ImageBlockData) => void;
21
21
  onClear: () => void;
22
22
  };
23
23
  export {};
@@ -11,7 +11,7 @@ import { Label } from "./Label/Label";
11
11
  import { Link } from "./Link/Link";
12
12
  import { default as OrderedList } from "./OrderedList/OrderedList";
13
13
  import { default as Paragraph } from "./Paragraph/Paragraph";
14
- export declare const DefaultTextExtension: import("../models").TextExtension;
15
14
  export declare const MarkExtensions: (import("./Bold/BoldModel").BoldExtension | import("./Italic/ItalicModel").ItalicExtension | import("./Link/LinkModel").LinkExtension | import("./Label/LabelModel").LabelExtension)[];
15
+ export type MarkExtensionName = typeof MarkExtensions[number]["name"];
16
16
  export declare function getAllExtensions(nodeTypes?: Set<RichTextNodeType>): WidgetExtension[];
17
17
  export { Bold, BulletList, CodeBlock, Embed, Heading, Image, Italic, Label, Link, OrderedList, Paragraph };
@@ -24,13 +24,13 @@ export declare class DocumentExtension {
24
24
  readonly name: string;
25
25
  readonly component: (multiLines: boolean) => Node;
26
26
  readonly converter: (extensions: NodeExtension[]) => {
27
- fromPrismic(schema: Schema, defaultTextConverter?: (block: TextBlock) => ProsemirrorNode | undefined): (elmt: RichTextContent) => ProsemirrorNode | undefined;
28
- toPrismic(elmt: ProsemirrorNode): RichTextContent | undefined;
27
+ fromPrismic(schema: Schema, nodeTypes: Set<RichTextNodeType>, content: RichTextContent): ProsemirrorNode | undefined;
28
+ toPrismic(node: ProsemirrorNode): RichTextContent | undefined;
29
29
  };
30
30
  extType: ExtensionType.Document;
31
31
  constructor(name: string, component: (multiLines: boolean) => Node, converter: (extensions: NodeExtension[]) => {
32
- fromPrismic(schema: Schema, defaultTextConverter?: (block: TextBlock) => ProsemirrorNode | undefined): (elmt: RichTextContent) => ProsemirrorNode | undefined;
33
- toPrismic(elmt: ProsemirrorNode): RichTextContent | undefined;
32
+ fromPrismic(schema: Schema, nodeTypes: Set<RichTextNodeType>, content: RichTextContent): ProsemirrorNode | undefined;
33
+ toPrismic(node: ProsemirrorNode): RichTextContent | undefined;
34
34
  });
35
35
  }
36
36
  export type MarkExtension = LinkExtension | BoldExtension | ItalicExtension | LabelExtension;
@@ -1,72 +1,8 @@
1
- import { RichTextConfig } from "@prismicio/types-internal/lib/customtypes";
2
- import type { Node as ProsemirrorNode, Schema } from "prosemirror-model";
1
+ import { RichTextConfig, type RichTextNodeType } from "@prismicio/types-internal/lib/customtypes";
3
2
  import { type WidgetExtension } from "./EditorExtension";
4
- export declare function composeExtensions(config?: RichTextConfig): {
3
+ export declare function composeExtensions(config?: RichTextConfig): Extensions;
4
+ interface Extensions {
5
5
  extensions: WidgetExtension[];
6
- defaultTextConverter: undefined;
7
- } | {
8
- extensions: WidgetExtension[];
9
- defaultTextConverter: (schema: Schema<any, any>) => (block: {
10
- type: "image" | "em" | "embed" | "strong" | "list-item" | "paragraph" | "rtl" | "heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "preformatted" | "hyperlink" | "o-list-item";
11
- content: {
12
- text: string;
13
- } & {
14
- spans?: ({
15
- data: ({
16
- __TYPE__: "ImageLink";
17
- } & {
18
- id: string;
19
- url: string;
20
- height: string;
21
- width: string;
22
- size: string;
23
- name: string;
24
- kind: string;
25
- } & {
26
- date?: string | null | undefined;
27
- }) | ({
28
- id: string;
29
- url: string;
30
- name: string;
31
- kind: string;
32
- size: string;
33
- } & {
34
- date?: string | null | undefined;
35
- } & {
36
- __TYPE__: "FileLink";
37
- } & {
38
- size?: string | undefined;
39
- }) | ({
40
- __TYPE__: "DocumentLink";
41
- } & {
42
- id: string;
43
- }) | ({
44
- __TYPE__: "ExternalLink";
45
- } & {
46
- url: string;
47
- } & {
48
- kind?: "web" | undefined;
49
- target?: string | null | undefined;
50
- preview?: {
51
- title?: string | undefined;
52
- } | null | undefined;
53
- });
54
- start: number;
55
- end: number;
56
- type: "hyperlink";
57
- } | {
58
- data: string;
59
- start: number;
60
- end: number;
61
- type: "label";
62
- } | {
63
- start: number;
64
- end: number;
65
- type: "em" | "strong" | "list-item";
66
- })[] | undefined;
67
- };
68
- } & {
69
- label?: string | undefined;
70
- direction?: string | undefined;
71
- }) => ProsemirrorNode | undefined;
72
- };
6
+ nodeTypes: Set<RichTextNodeType>;
7
+ }
8
+ export {};