@markput/react 0.1.0 → 0.3.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.
- package/README.md +13 -4
- package/index.d.ts +32 -84
- package/index.js +1455 -1073
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
# [Marked Input](https://marked-input.vercel.app)
|
|
1
|
+
# [Marked Input](https://marked-input.vercel.app)
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@markput/react) [](https://www.npmjs.com/package/@markput/vue) [](https://bundlephobia.com/package/@markput/react) [](https://bundlephobia.com/package/@markput/vue) [](https://marked-input.vercel.app)
|
|
2
4
|
|
|
3
5
|
<img width="521" alt="image" src="https://user-images.githubusercontent.com/37639183/182974441-49e4b247-449a-47ba-a090-2cb3aab7ce44.png">
|
|
4
6
|
|
|
5
|
-
A
|
|
7
|
+
A set of framework adapters that let you combine editable text with custom components using annotated text.
|
|
8
|
+
|
|
9
|
+
Currently supported packages:
|
|
10
|
+
|
|
11
|
+
- `@markput/react`
|
|
12
|
+
- `@markput/vue`
|
|
6
13
|
|
|
7
14
|
**[Documentation](https://markput.vercel.app)** **[Storybook](https://marked-input.vercel.app)**
|
|
8
15
|
|
|
@@ -24,10 +31,12 @@ A React component that lets you combine editable text with any component using a
|
|
|
24
31
|
|
|
25
32
|
## Installation
|
|
26
33
|
|
|
27
|
-
|
|
34
|
+
Install the package for your framework:
|
|
28
35
|
|
|
29
36
|
```
|
|
30
|
-
|
|
37
|
+
pnpm add @markput/react
|
|
38
|
+
# or
|
|
39
|
+
pnpm add @markput/vue
|
|
31
40
|
```
|
|
32
41
|
|
|
33
42
|
## Contributing
|
package/index.d.ts
CHANGED
|
@@ -1,27 +1,30 @@
|
|
|
1
1
|
import { annotate } from '@markput/core';
|
|
2
|
+
import { Block } from '@markput/core';
|
|
2
3
|
import type { ComponentType } from 'react';
|
|
3
|
-
import type { CoreMarkputProps } from '@markput/core';
|
|
4
4
|
import type { CoreOption } from '@markput/core';
|
|
5
5
|
import type { CSSProperties } from 'react';
|
|
6
6
|
import { denote } from '@markput/core';
|
|
7
|
-
import type { DependencyList } from 'react';
|
|
8
7
|
import type { ElementType } from 'react';
|
|
9
|
-
import type { EventKey } from '@markput/core';
|
|
10
|
-
import type { ForwardedRef } from 'react';
|
|
11
8
|
import type { HTMLAttributes } from 'react';
|
|
12
|
-
import
|
|
9
|
+
import { JSX } from 'react/jsx-runtime';
|
|
10
|
+
import { MarkHandler } from '@markput/core';
|
|
11
|
+
import { MarkputHandler } from '@markput/core';
|
|
13
12
|
import { MarkToken } from '@markput/core';
|
|
14
13
|
import { Markup } from '@markput/core';
|
|
15
14
|
import type { OverlayMatch } from '@markput/core';
|
|
16
15
|
import type { OverlayTrigger } from '@markput/core';
|
|
17
16
|
import type { ReactNode } from 'react';
|
|
17
|
+
import type { Ref } from 'react';
|
|
18
18
|
import type { RefObject } from 'react';
|
|
19
|
-
import
|
|
19
|
+
import { reorderBlocks } from '@markput/core';
|
|
20
|
+
import { splitTokensIntoBlocks } from '@markput/core';
|
|
20
21
|
import { TextToken } from '@markput/core';
|
|
21
22
|
import { Token } from '@markput/core';
|
|
22
23
|
|
|
23
24
|
export { annotate }
|
|
24
25
|
|
|
26
|
+
export { Block }
|
|
27
|
+
|
|
25
28
|
/**
|
|
26
29
|
* Data attributes with automatic camelCase to kebab-case conversion
|
|
27
30
|
*/
|
|
@@ -29,23 +32,7 @@ declare type DataAttributes = Record<`data${Capitalize<string>}`, string | numbe
|
|
|
29
32
|
|
|
30
33
|
export { denote }
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
* @function
|
|
34
|
-
*/
|
|
35
|
-
export declare const MarkedInput: MarkedInputComponent;
|
|
36
|
-
|
|
37
|
-
export declare interface MarkedInputComponent {
|
|
38
|
-
<TMarkProps = MarkProps, TOverlayProps = OverlayProps>(props: MarkedInputProps<TMarkProps, TOverlayProps>): JSX.Element | null;
|
|
39
|
-
displayName?: string;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export declare interface MarkedInputHandler {
|
|
43
|
-
/** Container element */
|
|
44
|
-
readonly container: HTMLDivElement | null;
|
|
45
|
-
/** Overlay element if exists */
|
|
46
|
-
readonly overlay: HTMLElement | null;
|
|
47
|
-
focus(): void;
|
|
48
|
-
}
|
|
35
|
+
export declare function MarkedInput<TMarkProps = MarkProps, TOverlayProps = OverlayProps>(props: MarkedInputProps<TMarkProps, TOverlayProps>): JSX.Element;
|
|
49
36
|
|
|
50
37
|
/**
|
|
51
38
|
* Props for MarkedInput component.
|
|
@@ -54,7 +41,7 @@ export declare interface MarkedInputHandler {
|
|
|
54
41
|
* @template TOverlayProps - Type of props for the global Overlay component
|
|
55
42
|
*
|
|
56
43
|
* @example
|
|
57
|
-
* ```
|
|
44
|
+
* ```tsx
|
|
58
45
|
* <MarkedInput<ChipProps>
|
|
59
46
|
* Mark={Chip}
|
|
60
47
|
* options={[{
|
|
@@ -64,9 +51,9 @@ export declare interface MarkedInputHandler {
|
|
|
64
51
|
* />
|
|
65
52
|
* ```
|
|
66
53
|
*/
|
|
67
|
-
export declare interface MarkedInputProps<TMarkProps = MarkProps, TOverlayProps = OverlayProps>
|
|
54
|
+
export declare interface MarkedInputProps<TMarkProps = MarkProps, TOverlayProps = OverlayProps> {
|
|
68
55
|
/** Ref to handler */
|
|
69
|
-
ref?:
|
|
56
|
+
ref?: Ref<MarkputHandler>;
|
|
70
57
|
/** Global component used for rendering markups (fallback for option.mark.slot) */
|
|
71
58
|
Mark?: ComponentType<TMarkProps>;
|
|
72
59
|
/** Global component used for rendering overlays (fallback for option.overlay.slot) */
|
|
@@ -83,14 +70,12 @@ export declare interface MarkedInputProps<TMarkProps = MarkProps, TOverlayProps
|
|
|
83
70
|
style?: CSSProperties;
|
|
84
71
|
/**
|
|
85
72
|
* Override internal components using slots
|
|
86
|
-
* @example
|
|
87
|
-
* slots={{ container: 'div', span: 'span' }}
|
|
73
|
+
* @example slots={{ container: 'div', span: 'span' }}
|
|
88
74
|
*/
|
|
89
75
|
slots?: Slots;
|
|
90
76
|
/**
|
|
91
77
|
* Props to pass to slot components
|
|
92
|
-
* @example
|
|
93
|
-
* slotProps={{ container: { onKeyDown: handler }, span: { className: 'custom' } }}
|
|
78
|
+
* @example slotProps={{ container: { onKeyDown: handler }, span: { className: 'custom' } }}
|
|
94
79
|
*/
|
|
95
80
|
slotProps?: SlotProps;
|
|
96
81
|
/**
|
|
@@ -98,48 +83,21 @@ export declare interface MarkedInputProps<TMarkProps = MarkProps, TOverlayProps
|
|
|
98
83
|
* @default 'change'
|
|
99
84
|
*/
|
|
100
85
|
showOverlayOn?: OverlayTrigger;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
86
|
+
/** Annotated text with markups */
|
|
87
|
+
value?: string;
|
|
88
|
+
/** Initial value for uncontrolled mode */
|
|
89
|
+
defaultValue?: string;
|
|
90
|
+
/** Change event handler */
|
|
91
|
+
onChange?: (value: string) => void;
|
|
92
|
+
/** Read-only mode */
|
|
106
93
|
readOnly?: boolean;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
store: Store;
|
|
110
|
-
token: MarkToken;
|
|
111
|
-
});
|
|
112
|
-
/** Displayed text of the mark */
|
|
113
|
-
get content(): string;
|
|
114
|
-
set content(value: string);
|
|
115
|
-
/** Data value associated with the mark */
|
|
116
|
-
get value(): string | undefined;
|
|
117
|
-
set value(value: string | undefined);
|
|
118
|
-
/** Optional metadata for the mark */
|
|
119
|
-
get meta(): string | undefined;
|
|
120
|
-
set meta(value: string | undefined);
|
|
121
|
-
/** Nesting depth (0 for root-level marks) */
|
|
122
|
-
get depth(): number;
|
|
123
|
-
/** Whether this mark has nested children */
|
|
124
|
-
get hasChildren(): boolean;
|
|
125
|
-
/** Parent mark token (undefined for root-level marks) */
|
|
126
|
-
get parent(): MarkToken | undefined;
|
|
127
|
-
/** Child tokens of this mark */
|
|
128
|
-
get tokens(): Token[];
|
|
129
|
-
/** Update multiple properties in a single operation */
|
|
130
|
-
change: (props: {
|
|
131
|
-
content: string;
|
|
132
|
-
value?: string;
|
|
133
|
-
meta?: string;
|
|
134
|
-
}) => void;
|
|
135
|
-
/** Delete this mark from the editor */
|
|
136
|
-
remove: () => void;
|
|
94
|
+
/** Enable Notion-like draggable blocks with drag handles for reordering */
|
|
95
|
+
block?: boolean;
|
|
137
96
|
}
|
|
138
97
|
|
|
98
|
+
export { MarkHandler }
|
|
99
|
+
|
|
139
100
|
declare interface MarkOptions {
|
|
140
|
-
/**
|
|
141
|
-
* @default false
|
|
142
|
-
*/
|
|
143
101
|
controlled?: boolean;
|
|
144
102
|
}
|
|
145
103
|
|
|
@@ -159,6 +117,8 @@ export declare interface MarkProps {
|
|
|
159
117
|
children?: ReactNode;
|
|
160
118
|
}
|
|
161
119
|
|
|
120
|
+
export { MarkputHandler }
|
|
121
|
+
|
|
162
122
|
export { MarkToken }
|
|
163
123
|
|
|
164
124
|
export { Markup }
|
|
@@ -189,27 +149,15 @@ declare interface Option_2<TMarkProps = MarkProps, TOverlayProps = OverlayProps>
|
|
|
189
149
|
export { Option_2 as Option }
|
|
190
150
|
|
|
191
151
|
export declare interface OverlayHandler {
|
|
192
|
-
/**
|
|
193
|
-
* Style with caret absolute position. Used for placing an overlay.
|
|
194
|
-
*/
|
|
195
152
|
style: {
|
|
196
153
|
left: number;
|
|
197
154
|
top: number;
|
|
198
155
|
};
|
|
199
|
-
/**
|
|
200
|
-
* Used for close overlay.
|
|
201
|
-
*/
|
|
202
156
|
close: () => void;
|
|
203
|
-
/**
|
|
204
|
-
* Used for insert an annotation instead a triggered value.
|
|
205
|
-
*/
|
|
206
157
|
select: (value: {
|
|
207
158
|
value: string;
|
|
208
159
|
meta?: string;
|
|
209
160
|
}) => void;
|
|
210
|
-
/**
|
|
211
|
-
* Overlay match details
|
|
212
|
-
*/
|
|
213
161
|
match: OverlayMatch<Option_2>;
|
|
214
162
|
ref: RefObject<HTMLElement>;
|
|
215
163
|
}
|
|
@@ -226,6 +174,8 @@ export declare interface OverlayProps {
|
|
|
226
174
|
data?: string[];
|
|
227
175
|
}
|
|
228
176
|
|
|
177
|
+
export { reorderBlocks }
|
|
178
|
+
|
|
229
179
|
/**
|
|
230
180
|
* Props for each slot component
|
|
231
181
|
*/
|
|
@@ -246,14 +196,12 @@ declare interface Slots {
|
|
|
246
196
|
span?: ElementType<HTMLAttributes<HTMLSpanElement>>;
|
|
247
197
|
}
|
|
248
198
|
|
|
199
|
+
export { splitTokensIntoBlocks }
|
|
200
|
+
|
|
249
201
|
export { TextToken }
|
|
250
202
|
|
|
251
203
|
export { Token }
|
|
252
204
|
|
|
253
|
-
export declare function useListener<T>(key: EventKey<T>, listener: Listener<T>, deps?: DependencyList): void;
|
|
254
|
-
|
|
255
|
-
export declare function useListener<K extends keyof HTMLElementEventMap>(key: K, listener: Listener<HTMLElementEventMap[K]>, deps?: DependencyList): void;
|
|
256
|
-
|
|
257
205
|
export declare const useMark: <T extends HTMLElement = HTMLElement>(options?: MarkOptions) => MarkHandler<T>;
|
|
258
206
|
|
|
259
207
|
export declare function useOverlay(): OverlayHandler;
|