@kystverket/styrbord 1.8.3 → 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.
- package/dist/src/components/kystverket/MarkdownToReact/markdownToReact.d.ts +6 -3
- package/dist/src/components/kystverket/MarkdownToReact/markdownToReact.stories.d.ts +1 -1
- package/dist/src/components/kystverket/RichTextArea/hooks/useRichTextImagePicker.d.ts +23 -0
- package/dist/src/components/kystverket/RichTextArea/hooks/useRichTextImageUpload.d.ts +5 -1
- package/dist/src/components/kystverket/RichTextArea/richTextArea.editorFactory.d.ts +15 -0
- package/dist/src/components/kystverket/RichTextArea/richTextArea.stories.d.ts +6 -3
- package/dist/src/components/kystverket/RichTextArea/richTextArea.types.d.ts +8 -3
- package/dist/src/components/kystverket/RichTextArea/utils/ImageRefUtils.d.ts +3 -1
- package/dist/src/utils/utility.types.d.ts +1 -0
- package/dist/style.js +2234 -2110
- package/dist/style.umd.cjs +7 -7
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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,
|
|
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,
|
|
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
|
-
* `
|
|
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 `` rather than the raw data URL,
|
|
22
|
-
*
|
|
25
|
+
* and a `MarkdownToReact` resolver can map that ref to a displayable URL.
|
|
23
26
|
*/
|
|
24
27
|
export declare const WithImageRef: Story;
|
|
@@ -1,4 +1,5 @@
|
|
|
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;
|
|
@@ -10,9 +11,12 @@ export type RichTextAreaProps = {
|
|
|
10
11
|
optional?: boolean | string;
|
|
11
12
|
required?: boolean | string;
|
|
12
13
|
error?: string;
|
|
13
|
-
/**
|
|
14
|
-
onImageUpload?:
|
|
15
|
-
|
|
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>>;
|
|
16
20
|
};
|
|
17
21
|
export type ToolbarCommand<T = unknown> = {
|
|
18
22
|
key: CmdKey<T>;
|
|
@@ -22,6 +26,7 @@ export type ImageMarkdown = {
|
|
|
22
26
|
src: string;
|
|
23
27
|
alt?: string;
|
|
24
28
|
};
|
|
29
|
+
export type ResolvedImageRef = ImageMarkdown | undefined;
|
|
25
30
|
export type ImageUploadResult = {
|
|
26
31
|
src: string;
|
|
27
32
|
ref?: string;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { MaybePromise } from '~/utils/utility.types';
|
|
1
2
|
type ResolvedImageRef = {
|
|
2
3
|
src: string;
|
|
3
4
|
alt?: string;
|
|
4
5
|
} | string | null | undefined;
|
|
5
|
-
export declare const
|
|
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>;
|
|
6
8
|
export declare const replaceImageUrlsWithRefs: (markdown: string, sasToRefMap: Map<string, string>) => string;
|
|
7
9
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type MaybePromise<T> = T | Promise<T>;
|