@kystverket/styrbord 1.8.2 → 1.8.4

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,10 +1,13 @@
1
+ import { MaybePromise } from '~/utils/utility.types';
2
+ type ResolvedImageRefs = Record<string, ResolvedImageRef>;
1
3
  export type MarkdownToReactProps = {
2
4
  markdown: string;
3
- resolveImageRef?: (ref: string) => ResolvedImageRef;
5
+ /** Optional sync/async resolver that receives all refs found in markdown. */
6
+ resolveImageRefs?: (refs?: string[]) => MaybePromise<ResolvedImageRefs>;
4
7
  };
5
8
  export type ResolvedImageRef = {
6
9
  src: string;
7
10
  alt?: string;
8
- } | undefined;
9
- declare const MarkdownToReact: ({ markdown, resolveImageRef }: MarkdownToReactProps) => React.JSX.Element;
11
+ } | string | null | undefined;
12
+ declare const MarkdownToReact: ({ markdown, resolveImageRefs }: MarkdownToReactProps) => React.JSX.Element;
10
13
  export default MarkdownToReact;
@@ -1,7 +1,7 @@
1
1
  import type { StoryObj } from '@storybook/react-vite';
2
2
  declare const meta: {
3
3
  title: string;
4
- component: ({ markdown, resolveImageRef }: import("./markdownToReact").MarkdownToReactProps) => React.JSX.Element;
4
+ component: ({ markdown, resolveImageRefs }: import("./markdownToReact").MarkdownToReactProps) => React.JSX.Element;
5
5
  decorators: ((Story: import("storybook/internal/csf").PartialStoryFn, context: import("storybook/internal/csf").StoryContext) => React.JSX.Element)[];
6
6
  tags: string[];
7
7
  argTypes: {
@@ -0,0 +1,23 @@
1
+ import type { Editor } from '@milkdown/core';
2
+ type UseRichTextImagePickerParams = {
3
+ disabled: boolean;
4
+ loading: boolean;
5
+ canUploadImage: boolean;
6
+ isUploadingImage: boolean;
7
+ get: () => Editor | undefined;
8
+ pendingImageSelectionRef: React.RefObject<{
9
+ from: number;
10
+ to: number;
11
+ } | null>;
12
+ onImageFileInputChange: (event: React.ChangeEvent<HTMLInputElement>) => Promise<{
13
+ success: boolean;
14
+ }>;
15
+ };
16
+ type UseRichTextImagePickerReturn = {
17
+ imageInputRef: React.RefObject<HTMLInputElement | null>;
18
+ imageUploadError: string | undefined;
19
+ openImageFilePicker: () => void;
20
+ handleImageFileInputChange: (event: React.ChangeEvent<HTMLInputElement>) => Promise<void>;
21
+ };
22
+ export declare const useRichTextImagePicker: ({ disabled, loading, canUploadImage, isUploadingImage, get, pendingImageSelectionRef, onImageFileInputChange, }: UseRichTextImagePickerParams) => UseRichTextImagePickerReturn;
23
+ export {};
@@ -8,6 +8,10 @@ type UseRichTextImageUploadParams = {
8
8
  updateToolbarState: (ctx: Ctx) => void;
9
9
  latestOnUploadRef: React.RefObject<UploadImageFn | undefined> | undefined;
10
10
  sasToRefMap: React.RefObject<Map<string, string>>;
11
+ pendingImageSelectionRef: React.RefObject<{
12
+ from: number;
13
+ to: number;
14
+ } | null>;
11
15
  };
12
16
  type UseRichTextImageUploadReturn = {
13
17
  isUploadingImage: boolean;
@@ -17,5 +21,5 @@ type UseRichTextImageUploadReturn = {
17
21
  success: boolean;
18
22
  }>;
19
23
  };
20
- export declare const useRichTextImageUpload: ({ disabled, get, updateToolbarState, latestOnUploadRef, sasToRefMap, }: UseRichTextImageUploadParams) => UseRichTextImageUploadReturn;
24
+ export declare const useRichTextImageUpload: ({ disabled, get, updateToolbarState, latestOnUploadRef, sasToRefMap, pendingImageSelectionRef, }: UseRichTextImageUploadParams) => UseRichTextImageUploadReturn;
21
25
  export {};
@@ -0,0 +1,15 @@
1
+ import { Editor } from '@milkdown/core';
2
+ import type { InlineImageConfig } from '@milkdown/components/image-inline';
3
+ import type { Ctx } from '@milkdown/ctx';
4
+ type CreateRichTextAreaEditorParams = {
5
+ root: HTMLElement;
6
+ disabled: boolean;
7
+ editorMarkdown: string;
8
+ canUploadImage: boolean;
9
+ dispatchImageFromFile: (file: File) => void;
10
+ updateInlineImageConfig: (config: InlineImageConfig) => InlineImageConfig;
11
+ updateToolbarState: (ctx: Ctx) => void;
12
+ onMarkdownUpdated: (ctx: Ctx, markdown: string) => void;
13
+ };
14
+ export declare const createRichTextAreaEditor: ({ root, disabled, editorMarkdown, canUploadImage, dispatchImageFromFile, updateInlineImageConfig, updateToolbarState, onMarkdownUpdated, }: CreateRichTextAreaEditorParams) => Editor;
15
+ export {};
@@ -14,11 +14,14 @@ export declare const WithError: Story;
14
14
  /**
15
15
  * Demonstrates stable image references in markdown.
16
16
  *
17
- * `onUpload` returns both:
17
+ * `onImageUpload` returns both:
18
18
  * - `src` — a data URL used by the editor to display the image immediately
19
- * - `ref` — a stable opaque ID (e.g. Azure blob path / UUID) stored in the markdown instead of the SAS URL
19
+ * - `ref` — a stable opaque ID (e.g. Azure blob path / UUID) stored in the markdown instead of the SAS URL.
20
+ *
21
+ * `onImageRemove` is called with the stable ref when an image is removed from the editor,
22
+ * so a backend can delete the persisted image resource.
20
23
  *
21
24
  * The `onChange` output will contain `![alt](image://uuid-...)` rather than the raw data URL,
22
- * which is what a `MarkdownToReact` or similar renderers would receive where you implement a resolver function to provide a SAS URI or similar.
25
+ * and a `MarkdownToReact` resolver can map that ref to a displayable URL.
23
26
  */
24
27
  export declare const WithImageRef: Story;
@@ -1,8 +1,8 @@
1
1
  import type { CmdKey } from '@milkdown/core';
2
+ import { MaybePromise } from '~/utils/utility.types';
2
3
  export type RichTextAreaProps = {
3
4
  value: string | null | undefined;
4
5
  onChange: (markdown: string) => void;
5
- onUpload?: UploadImageFn;
6
6
  placeholder?: string;
7
7
  disabled?: boolean;
8
8
  className?: string;
@@ -11,6 +11,12 @@ export type RichTextAreaProps = {
11
11
  optional?: boolean | string;
12
12
  required?: boolean | string;
13
13
  error?: string;
14
+ /** Optional upload handler that returns a display src and optional stable image ref. */
15
+ onImageUpload?: (file: File) => Promise<ImageUploadResult | null>;
16
+ /** Optional remove handler for deleting persisted images by stable ref. */
17
+ onImageRemove?: (ref: string) => Promise<void>;
18
+ /** Optional resolver that maps image refs in markdown to renderable image sources. */
19
+ resolveImageRefs?: (refs?: string[]) => MaybePromise<Record<string, ResolvedImageRef>>;
14
20
  };
15
21
  export type ToolbarCommand<T = unknown> = {
16
22
  key: CmdKey<T>;
@@ -19,13 +25,12 @@ export type ToolbarCommand<T = unknown> = {
19
25
  export type ImageMarkdown = {
20
26
  src: string;
21
27
  alt?: string;
22
- title?: string;
23
28
  };
29
+ export type ResolvedImageRef = ImageMarkdown | undefined;
24
30
  export type ImageUploadResult = {
25
31
  src: string;
26
32
  ref?: string;
27
33
  alt?: string;
28
- title?: string;
29
34
  };
30
35
  export type ImageInsertHandler = (file: File) => void;
31
36
  export type UploadImageFn = (file: File) => Promise<ImageUploadResult | string | null>;
@@ -0,0 +1,9 @@
1
+ import { MaybePromise } from '~/utils/utility.types';
2
+ type ResolvedImageRef = {
3
+ src: string;
4
+ alt?: string;
5
+ } | string | null | undefined;
6
+ export declare const getImageRefsFromMarkdown: (markdown: string) => string[];
7
+ export declare const convertFromRefToImage: (markdown: string, resolveImageRefs: (refs: string[]) => MaybePromise<Record<string, ResolvedImageRef>>, urlToRefMap?: Map<string, string>, previousRefToUrlMap?: Map<string, string>) => Promise<string>;
8
+ export declare const replaceImageUrlsWithRefs: (markdown: string, sasToRefMap: Map<string, string>) => string;
9
+ export {};
@@ -1,6 +1,5 @@
1
1
  import type { EditorState } from '@milkdown/prose/state';
2
2
  export declare const normalizeHref: (rawHref: string) => string;
3
- export declare const replaceUrlsWithRefs: (markdown: string, sasToRefMap: Map<string, string>) => string;
4
3
  export declare const getSelectionLinkRange: (state: EditorState) => {
5
4
  from: number;
6
5
  to: number;
@@ -0,0 +1 @@
1
+ export type MaybePromise<T> = T | Promise<T>;