@markput/react 0.1.0 → 0.2.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 +10 -3
- package/index.d.ts +21 -84
- package/index.js +1196 -1088
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,7 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
<img width="521" alt="image" src="https://user-images.githubusercontent.com/37639183/182974441-49e4b247-449a-47ba-a090-2cb3aab7ce44.png">
|
|
4
4
|
|
|
5
|
-
A
|
|
5
|
+
A set of framework adapters that let you combine editable text with custom components using annotated text.
|
|
6
|
+
|
|
7
|
+
Currently supported packages:
|
|
8
|
+
|
|
9
|
+
- `@markput/react`
|
|
10
|
+
- `@markput/vue`
|
|
6
11
|
|
|
7
12
|
**[Documentation](https://markput.vercel.app)** **[Storybook](https://marked-input.vercel.app)**
|
|
8
13
|
|
|
@@ -24,10 +29,12 @@ A React component that lets you combine editable text with any component using a
|
|
|
24
29
|
|
|
25
30
|
## Installation
|
|
26
31
|
|
|
27
|
-
|
|
32
|
+
Install the package for your framework:
|
|
28
33
|
|
|
29
34
|
```
|
|
30
|
-
|
|
35
|
+
pnpm add @markput/react
|
|
36
|
+
# or
|
|
37
|
+
pnpm add @markput/vue
|
|
31
38
|
```
|
|
32
39
|
|
|
33
40
|
## Contributing
|
package/index.d.ts
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import { annotate } from '@markput/core';
|
|
2
2
|
import type { ComponentType } from 'react';
|
|
3
|
-
import type { CoreMarkputProps } from '@markput/core';
|
|
4
3
|
import type { CoreOption } from '@markput/core';
|
|
5
4
|
import type { CSSProperties } from 'react';
|
|
6
5
|
import { denote } from '@markput/core';
|
|
7
|
-
import type { DependencyList } from 'react';
|
|
8
6
|
import type { ElementType } from 'react';
|
|
9
|
-
import type { EventKey } from '@markput/core';
|
|
10
|
-
import type { ForwardedRef } from 'react';
|
|
11
7
|
import type { HTMLAttributes } from 'react';
|
|
12
|
-
import
|
|
8
|
+
import { JSX } from 'react/jsx-runtime';
|
|
9
|
+
import { MarkHandler } from '@markput/core';
|
|
10
|
+
import { MarkputHandler } from '@markput/core';
|
|
13
11
|
import { MarkToken } from '@markput/core';
|
|
14
12
|
import { Markup } from '@markput/core';
|
|
15
13
|
import type { OverlayMatch } from '@markput/core';
|
|
16
14
|
import type { OverlayTrigger } from '@markput/core';
|
|
17
15
|
import type { ReactNode } from 'react';
|
|
16
|
+
import type { Ref } from 'react';
|
|
18
17
|
import type { RefObject } from 'react';
|
|
19
|
-
import type { Store } from '@markput/core';
|
|
20
18
|
import { TextToken } from '@markput/core';
|
|
21
19
|
import { Token } from '@markput/core';
|
|
22
20
|
|
|
@@ -29,23 +27,7 @@ declare type DataAttributes = Record<`data${Capitalize<string>}`, string | numbe
|
|
|
29
27
|
|
|
30
28
|
export { denote }
|
|
31
29
|
|
|
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
|
-
}
|
|
30
|
+
export declare function MarkedInput<TMarkProps = MarkProps, TOverlayProps = OverlayProps>(props: MarkedInputProps<TMarkProps, TOverlayProps>): JSX.Element;
|
|
49
31
|
|
|
50
32
|
/**
|
|
51
33
|
* Props for MarkedInput component.
|
|
@@ -54,7 +36,7 @@ export declare interface MarkedInputHandler {
|
|
|
54
36
|
* @template TOverlayProps - Type of props for the global Overlay component
|
|
55
37
|
*
|
|
56
38
|
* @example
|
|
57
|
-
* ```
|
|
39
|
+
* ```tsx
|
|
58
40
|
* <MarkedInput<ChipProps>
|
|
59
41
|
* Mark={Chip}
|
|
60
42
|
* options={[{
|
|
@@ -64,9 +46,9 @@ export declare interface MarkedInputHandler {
|
|
|
64
46
|
* />
|
|
65
47
|
* ```
|
|
66
48
|
*/
|
|
67
|
-
export declare interface MarkedInputProps<TMarkProps = MarkProps, TOverlayProps = OverlayProps>
|
|
49
|
+
export declare interface MarkedInputProps<TMarkProps = MarkProps, TOverlayProps = OverlayProps> {
|
|
68
50
|
/** Ref to handler */
|
|
69
|
-
ref?:
|
|
51
|
+
ref?: Ref<MarkputHandler>;
|
|
70
52
|
/** Global component used for rendering markups (fallback for option.mark.slot) */
|
|
71
53
|
Mark?: ComponentType<TMarkProps>;
|
|
72
54
|
/** Global component used for rendering overlays (fallback for option.overlay.slot) */
|
|
@@ -83,14 +65,12 @@ export declare interface MarkedInputProps<TMarkProps = MarkProps, TOverlayProps
|
|
|
83
65
|
style?: CSSProperties;
|
|
84
66
|
/**
|
|
85
67
|
* Override internal components using slots
|
|
86
|
-
* @example
|
|
87
|
-
* slots={{ container: 'div', span: 'span' }}
|
|
68
|
+
* @example slots={{ container: 'div', span: 'span' }}
|
|
88
69
|
*/
|
|
89
70
|
slots?: Slots;
|
|
90
71
|
/**
|
|
91
72
|
* Props to pass to slot components
|
|
92
|
-
* @example
|
|
93
|
-
* slotProps={{ container: { onKeyDown: handler }, span: { className: 'custom' } }}
|
|
73
|
+
* @example slotProps={{ container: { onKeyDown: handler }, span: { className: 'custom' } }}
|
|
94
74
|
*/
|
|
95
75
|
slotProps?: SlotProps;
|
|
96
76
|
/**
|
|
@@ -98,48 +78,19 @@ export declare interface MarkedInputProps<TMarkProps = MarkProps, TOverlayProps
|
|
|
98
78
|
* @default 'change'
|
|
99
79
|
*/
|
|
100
80
|
showOverlayOn?: OverlayTrigger;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
81
|
+
/** Annotated text with markups */
|
|
82
|
+
value?: string;
|
|
83
|
+
/** Initial value for uncontrolled mode */
|
|
84
|
+
defaultValue?: string;
|
|
85
|
+
/** Change event handler */
|
|
86
|
+
onChange?: (value: string) => void;
|
|
87
|
+
/** Read-only mode */
|
|
106
88
|
readOnly?: boolean;
|
|
107
|
-
constructor(param: {
|
|
108
|
-
ref: RefObject<T>;
|
|
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;
|
|
137
89
|
}
|
|
138
90
|
|
|
91
|
+
export { MarkHandler }
|
|
92
|
+
|
|
139
93
|
declare interface MarkOptions {
|
|
140
|
-
/**
|
|
141
|
-
* @default false
|
|
142
|
-
*/
|
|
143
94
|
controlled?: boolean;
|
|
144
95
|
}
|
|
145
96
|
|
|
@@ -159,6 +110,8 @@ export declare interface MarkProps {
|
|
|
159
110
|
children?: ReactNode;
|
|
160
111
|
}
|
|
161
112
|
|
|
113
|
+
export { MarkputHandler }
|
|
114
|
+
|
|
162
115
|
export { MarkToken }
|
|
163
116
|
|
|
164
117
|
export { Markup }
|
|
@@ -189,27 +142,15 @@ declare interface Option_2<TMarkProps = MarkProps, TOverlayProps = OverlayProps>
|
|
|
189
142
|
export { Option_2 as Option }
|
|
190
143
|
|
|
191
144
|
export declare interface OverlayHandler {
|
|
192
|
-
/**
|
|
193
|
-
* Style with caret absolute position. Used for placing an overlay.
|
|
194
|
-
*/
|
|
195
145
|
style: {
|
|
196
146
|
left: number;
|
|
197
147
|
top: number;
|
|
198
148
|
};
|
|
199
|
-
/**
|
|
200
|
-
* Used for close overlay.
|
|
201
|
-
*/
|
|
202
149
|
close: () => void;
|
|
203
|
-
/**
|
|
204
|
-
* Used for insert an annotation instead a triggered value.
|
|
205
|
-
*/
|
|
206
150
|
select: (value: {
|
|
207
151
|
value: string;
|
|
208
152
|
meta?: string;
|
|
209
153
|
}) => void;
|
|
210
|
-
/**
|
|
211
|
-
* Overlay match details
|
|
212
|
-
*/
|
|
213
154
|
match: OverlayMatch<Option_2>;
|
|
214
155
|
ref: RefObject<HTMLElement>;
|
|
215
156
|
}
|
|
@@ -250,10 +191,6 @@ export { TextToken }
|
|
|
250
191
|
|
|
251
192
|
export { Token }
|
|
252
193
|
|
|
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
194
|
export declare const useMark: <T extends HTMLElement = HTMLElement>(options?: MarkOptions) => MarkHandler<T>;
|
|
258
195
|
|
|
259
196
|
export declare function useOverlay(): OverlayHandler;
|