@portabletext/plugin-input-rule 6.0.13 → 6.0.15

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/index.d.ts CHANGED
@@ -1,253 +1,117 @@
1
- import {Behavior} from '@portabletext/editor/behaviors'
2
- import type {BehaviorActionSet} from '@portabletext/editor/behaviors'
3
- import {BehaviorEvent} from '@portabletext/editor/behaviors'
4
- import type {BehaviorGuard} from '@portabletext/editor/behaviors'
5
- import {BlockOffset} from '@portabletext/editor'
6
- import type {BlockPath} from '@portabletext/editor'
7
- import {EditorSelection} from '@portabletext/editor'
8
- import type {PortableTextBlock} from '@portabletext/editor'
9
-
1
+ import { BlockOffset, BlockPath, EditorSelection, PortableTextBlock } from "@portabletext/editor";
2
+ import { BehaviorActionSet, BehaviorGuard } from "@portabletext/editor/behaviors";
10
3
  /**
11
4
  * @public
12
5
  */
13
- export declare function defineInputRule<TGuardResponse = true>(
14
- config: InputRule<TGuardResponse>,
15
- ): InputRule<TGuardResponse>
16
-
17
- /**
18
- * @public
19
- */
20
- export declare function defineInputRuleBehavior(config: {
21
- rules: Array<InputRule<any>>
22
- onApply?: ({
23
- endOffsets,
24
- endSelection,
25
- }: {
26
- endOffsets:
27
- | {
28
- start: BlockOffset
29
- end: BlockOffset
30
- }
31
- | undefined
32
- endSelection: EditorSelection
33
- }) => void
34
- }): Behavior<
35
- | '*'
36
- | 'insert.text'
37
- | 'annotation.add'
38
- | 'annotation.remove'
39
- | 'block.set'
40
- | 'block.unset'
41
- | 'child.set'
42
- | 'child.unset'
43
- | 'decorator.add'
44
- | 'decorator.remove'
45
- | 'delete'
46
- | 'history.redo'
47
- | 'history.undo'
48
- | 'insert'
49
- | 'insert.block'
50
- | 'insert.child'
51
- | 'move.backward'
52
- | 'move.forward'
53
- | 'remove.text'
54
- | 'select'
55
- | 'set'
56
- | 'unset'
57
- | 'annotation.set'
58
- | 'annotation.toggle'
59
- | 'decorator.toggle'
60
- | 'delete.backward'
61
- | 'delete.block'
62
- | 'delete.child'
63
- | 'delete.forward'
64
- | 'delete.text'
65
- | 'deserialize'
66
- | 'deserialize.data'
67
- | 'deserialization.success'
68
- | 'deserialization.failure'
69
- | 'insert.blocks'
70
- | 'insert.break'
71
- | 'insert.inline object'
72
- | 'insert.soft break'
73
- | 'insert.span'
74
- | 'list item.add'
75
- | 'list item.remove'
76
- | 'list item.toggle'
77
- | 'move.block'
78
- | 'move.block down'
79
- | 'move.block up'
80
- | 'select.block'
81
- | 'select.previous block'
82
- | 'select.next block'
83
- | 'serialize'
84
- | 'serialize.data'
85
- | 'serialization.success'
86
- | 'serialization.failure'
87
- | 'split'
88
- | 'style.add'
89
- | 'style.remove'
90
- | 'style.toggle'
91
- | 'clipboard.copy'
92
- | 'clipboard.cut'
93
- | 'clipboard.paste'
94
- | 'drag.dragstart'
95
- | 'drag.drag'
96
- | 'drag.dragend'
97
- | 'drag.dragenter'
98
- | 'drag.dragover'
99
- | 'drag.dragleave'
100
- | 'drag.drop'
101
- | 'input.*'
102
- | 'keyboard.keydown'
103
- | 'keyboard.keyup'
104
- | 'mouse.click'
105
- | 'delete.*'
106
- | 'insert.*'
107
- | 'select.*'
108
- | 'set.*'
109
- | 'unset.*'
110
- | 'deserialize.*'
111
- | 'serialize.*'
112
- | 'split.*'
113
- | 'annotation.*'
114
- | 'remove.*'
115
- | 'block.*'
116
- | 'child.*'
117
- | 'decorator.*'
118
- | 'history.*'
119
- | 'move.*'
120
- | 'deserialization.*'
121
- | 'list item.*'
122
- | 'serialization.*'
123
- | 'style.*'
124
- | 'clipboard.*'
125
- | 'drag.*'
126
- | 'keyboard.*'
127
- | 'mouse.*'
128
- | `custom.${string}`,
129
- true,
130
- BehaviorEvent
131
- >
132
-
133
- /**
134
- * Define an `InputRule` specifically designed to transform matched text into
135
- * some other text.
136
- *
137
- * @example
138
- * ```tsx
139
- * const transformRule = defineTextTransformRule({
140
- * on: /--/,
141
- * transform: () => '—',
142
- * })
143
- * ```
144
- *
145
- * @public
146
- */
147
- export declare function defineTextTransformRule<TGuardResponse = true>(
148
- config: TextTransformRule<TGuardResponse>,
149
- ): InputRule<TGuardResponse>
150
-
6
+ type InputRuleMatchLocation = {
7
+ /**
8
+ * The matched text
9
+ */
10
+ text: string;
11
+ /**
12
+ * Estimated selection of where in the original text the match is located.
13
+ * The selection is estimated since the match is found in the text after
14
+ * insertion.
15
+ */
16
+ selection: NonNullable<EditorSelection>;
17
+ /**
18
+ * Block offsets of the match in the text after the insertion
19
+ */
20
+ targetOffsets: {
21
+ anchor: BlockOffset;
22
+ focus: BlockOffset;
23
+ backward: boolean;
24
+ };
25
+ };
151
26
  /**
27
+ * Match found in the text after the insertion
152
28
  * @public
153
29
  */
154
- export declare type InputRule<TGuardResponse = true> = {
155
- on: RegExp
30
+ type InputRuleMatch = InputRuleMatchLocation & {
156
31
  /**
157
- * Named capture groups inside which an inline object may sit without
158
- * dropping the match.
159
- *
160
- * Inline objects contribute nothing to the text the RegExp matches
161
- * against, so a match can span one invisibly. By default any such match
162
- * is dropped: rules commonly delete the matched range, and deleting
163
- * across an inline object destroys it. Listing a group allows inline
164
- * objects within that group's matched span (inclusive of its edges,
165
- * so an object adjacent to the span does not drop the match); everything
166
- * else in the match, unlisted groups and the text between groups, stays
167
- * protected. To allow inline objects anywhere in the match, capture the
168
- * whole pattern in a named group and list it.
32
+ * Locations of the match's named capture groups, keyed by group name.
33
+ * Only groups that participated in the match are present, and a capture
34
+ * group must be named (`(?<name>...)`) for its location to be exposed;
35
+ * unnamed groups remain usable for regex mechanics (alternation) but get
36
+ * no location.
169
37
  */
170
- inlineObjects?: {
171
- allow: Array<string>
172
- }
173
- guard?: InputRuleGuard<TGuardResponse>
174
- actions: Array<BehaviorActionSet<InputRuleEvent, TGuardResponse>>
175
- }
176
-
38
+ groups: Record<string, InputRuleMatchLocation | undefined>;
39
+ };
177
40
  /**
178
41
  * @public
179
42
  */
180
- export declare type InputRuleEvent = {
181
- type: 'custom.input rule'
43
+ type InputRuleEvent = {
44
+ type: 'custom.input rule';
182
45
  /**
183
46
  * Matches found by the input rule
184
47
  */
185
- matches: Array<InputRuleMatch>
48
+ matches: Array<InputRuleMatch>;
186
49
  /**
187
50
  * The focus block's text from its start to the caret, as it was before
188
51
  * the insertion
189
52
  */
190
- textBefore: string
53
+ textBefore: string;
191
54
  /**
192
55
  * The text carried by the triggering `insert.text` event
193
56
  */
194
- textInserted: string
57
+ textInserted: string;
195
58
  /**
196
59
  * The block where the insertion takes place
197
60
  */
198
61
  focusBlock: {
199
- path: BlockPath
200
- node: PortableTextBlock
201
- }
202
- }
203
-
62
+ path: BlockPath;
63
+ node: PortableTextBlock;
64
+ };
65
+ };
204
66
  /**
205
67
  * @public
206
68
  */
207
- export declare type InputRuleGuard<TGuardResponse = true> = BehaviorGuard<
208
- InputRuleEvent,
209
- TGuardResponse
210
- >
211
-
69
+ type InputRuleGuard<TGuardResponse = true> = BehaviorGuard<InputRuleEvent, TGuardResponse>;
212
70
  /**
213
- * Match found in the text after the insertion
214
71
  * @public
215
72
  */
216
- export declare type InputRuleMatch = InputRuleMatchLocation & {
73
+ type InputRule<TGuardResponse = true> = {
74
+ on: RegExp;
217
75
  /**
218
- * Locations of the match's named capture groups, keyed by group name.
219
- * Only groups that participated in the match are present, and a capture
220
- * group must be named (`(?<name>...)`) for its location to be exposed;
221
- * unnamed groups remain usable for regex mechanics (alternation) but get
222
- * no location.
76
+ * Named capture groups inside which an inline object may sit without
77
+ * dropping the match.
78
+ *
79
+ * Inline objects contribute nothing to the text the RegExp matches
80
+ * against, so a match can span one invisibly. By default any such match
81
+ * is dropped: rules commonly delete the matched range, and deleting
82
+ * across an inline object destroys it. Listing a group allows inline
83
+ * objects within that group's matched span (inclusive of its edges,
84
+ * so an object adjacent to the span does not drop the match); everything
85
+ * else in the match, unlisted groups and the text between groups, stays
86
+ * protected. To allow inline objects anywhere in the match, capture the
87
+ * whole pattern in a named group and list it.
223
88
  */
224
- groups: Record<string, InputRuleMatchLocation | undefined>
225
- }
226
-
89
+ inlineObjects?: {
90
+ allow: Array<string>;
91
+ };
92
+ guard?: InputRuleGuard<TGuardResponse>;
93
+ actions: Array<BehaviorActionSet<InputRuleEvent, TGuardResponse>>;
94
+ };
227
95
  /**
228
96
  * @public
229
97
  */
230
- export declare type InputRuleMatchLocation = {
231
- /**
232
- * The matched text
233
- */
234
- text: string
235
- /**
236
- * Estimated selection of where in the original text the match is located.
237
- * The selection is estimated since the match is found in the text after
238
- * insertion.
239
- */
240
- selection: NonNullable<EditorSelection>
241
- /**
242
- * Block offsets of the match in the text after the insertion
243
- */
244
- targetOffsets: {
245
- anchor: BlockOffset
246
- focus: BlockOffset
247
- backward: boolean
248
- }
249
- }
250
-
98
+ declare function defineInputRule<TGuardResponse = true>(config: InputRule<TGuardResponse>): InputRule<TGuardResponse>;
99
+ /**
100
+ * @public
101
+ */
102
+ declare function defineInputRuleBehavior(config: {
103
+ rules: Array<InputRule<any>>;
104
+ onApply?: ({ endOffsets, endSelection }: {
105
+ endOffsets: {
106
+ start: BlockOffset;
107
+ end: BlockOffset;
108
+ } | undefined;
109
+ endSelection: EditorSelection;
110
+ }) => void;
111
+ }): import("@portabletext/editor/behaviors").Behavior<"*" | "insert.text" | "annotation.add" | "annotation.remove" | "block.set" | "block.unset" | "child.set" | "child.unset" | "decorator.add" | "decorator.remove" | "delete" | "history.redo" | "history.undo" | "insert" | "insert.block" | "insert.child" | "move.backward" | "move.forward" | "remove.text" | "select" | "set" | "unset" | "annotation.set" | "annotation.toggle" | "decorator.toggle" | "delete.backward" | "delete.block" | "delete.child" | "delete.forward" | "delete.text" | "deserialize" | "deserialize.data" | "deserialization.success" | "deserialization.failure" | "insert.blocks" | "insert.break" | "insert.inline object" | "insert.soft break" | "insert.span" | "list item.add" | "list item.remove" | "list item.toggle" | "move.block" | "move.block down" | "move.block up" | "select.block" | "select.previous block" | "select.next block" | "serialize" | "serialize.data" | "serialization.success" | "serialization.failure" | "split" | "style.add" | "style.remove" | "style.toggle" | "clipboard.copy" | "clipboard.cut" | "clipboard.paste" | "drag.dragstart" | "drag.drag" | "drag.dragend" | "drag.dragenter" | "drag.dragover" | "drag.dragleave" | "drag.drop" | "input.*" | "keyboard.keydown" | "keyboard.keyup" | "mouse.click" | "delete.*" | "insert.*" | "select.*" | "set.*" | "unset.*" | "deserialize.*" | "serialize.*" | "split.*" | "annotation.*" | "remove.*" | "block.*" | "child.*" | "decorator.*" | "history.*" | "move.*" | "deserialization.*" | "list item.*" | "serialization.*" | "style.*" | "clipboard.*" | "drag.*" | "keyboard.*" | "mouse.*" | `custom.${string}`, true, import("@portabletext/editor/behaviors").BehaviorEvent>;
112
+ type InputRulePluginProps = {
113
+ rules: Array<InputRule<any>>;
114
+ };
251
115
  /**
252
116
  * Turn an array of `InputRule`s into a Behavior that can be used to apply the
253
117
  * rules to the editor.
@@ -262,30 +126,19 @@ export declare type InputRuleMatchLocation = {
262
126
  *
263
127
  * @public
264
128
  */
265
- export declare function InputRulePlugin(props: InputRulePluginProps): null
266
-
267
- declare type InputRulePluginProps = {
268
- rules: Array<InputRule<any>>
269
- }
270
-
129
+ declare function InputRulePlugin(props: InputRulePluginProps): null;
271
130
  /**
272
131
  * @public
273
132
  */
274
- export declare type TextTransform<TGuardResponse = true> = (
275
- {
276
- location,
277
- }: {
278
- location: InputRuleMatchLocation
279
- },
280
- guardResponse: TGuardResponse,
281
- ) => string
282
-
133
+ type TextTransform<TGuardResponse = true> = ({ location }: {
134
+ location: InputRuleMatchLocation;
135
+ }, guardResponse: TGuardResponse) => string;
283
136
  /**
284
137
  * @public
285
138
  */
286
- export declare type TextTransformRule<TGuardResponse = true> = {
287
- on: RegExp
288
- guard?: InputRuleGuard<TGuardResponse>
139
+ type TextTransformRule<TGuardResponse = true> = {
140
+ on: RegExp;
141
+ guard?: InputRuleGuard<TGuardResponse>;
289
142
  /**
290
143
  * What to replace, and with what.
291
144
  *
@@ -303,9 +156,22 @@ export declare type TextTransformRule<TGuardResponse = true> = {
303
156
  * `defineTextTransformRule` throws otherwise. A match in which none of
304
157
  * the keys participated has nothing to replace and is skipped.
305
158
  */
306
- transform:
307
- | TextTransform<TGuardResponse>
308
- | Record<string, TextTransform<TGuardResponse>>
309
- }
310
-
311
- export {}
159
+ transform: TextTransform<TGuardResponse> | Record<string, TextTransform<TGuardResponse>>;
160
+ };
161
+ /**
162
+ * Define an `InputRule` specifically designed to transform matched text into
163
+ * some other text.
164
+ *
165
+ * @example
166
+ * ```tsx
167
+ * const transformRule = defineTextTransformRule({
168
+ * on: /--/,
169
+ * transform: () => '—',
170
+ * })
171
+ * ```
172
+ *
173
+ * @public
174
+ */
175
+ declare function defineTextTransformRule<TGuardResponse = true>(config: TextTransformRule<TGuardResponse>): InputRule<TGuardResponse>;
176
+ export { InputRule, InputRuleEvent, InputRuleGuard, InputRuleMatch, type InputRuleMatchLocation, InputRulePlugin, TextTransform, TextTransformRule, defineInputRule, defineInputRuleBehavior, defineTextTransformRule };
177
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/input-rule-match-location.ts","../src/input-rule.ts","../src/plugin.input-rule.tsx","../src/text-transform-rule.ts"],"mappings":";;;;;KAkBY;;;;EAIV;;;;;;EAMA,WAAW,YAAY;;;;EAIvB;IACE,QAAQ;IACR,OAAO;IACP;;;;;;;KCxBQ,iBAAiB;;;;;;;;EAQ3B,QAAQ,eAAe;;;;;KAMb;EACV;;;;EAIA,SAAS,MAAM;;;;;EAKf;;;;EAIA;;;;EAIA;IACE,MAAM;IACN,MAAM;;;;;;KAOE,eAAe,yBAAyB,cAClD,gBACA;;;;KAMU,UAAU;EACpB,IAAI;;;;;;;;;;;;;;;EAeJ;IAAiB,OAAO;;EACxB,QAAQ,eAAe;EACvB,SAAS,MAAM,kBAAkB,gBAAgB;;;;;iBAMnC,gBAAgB,uBAC9B,QAAQ,UAAU,kBACjB,UAAU;;;;iBC/CG,wBAAwB;EACtC,OAAO,MAAM;EACb,aACE,YACA;IAEA;MAAa,OAAO;MAAa,KAAK;;IACtC,cAAc;;6CAEjB,0mDAAA;KAmOI;EACH,OAAO,MAAM;;;;;;;;;;;;;;;;iBAiBC,gBAAgB,OAAO;;;;KC7R3B,cAAc,4BACvB;EAAY,UAAU;GACvB,eAAe;;;;KAML,kBAAkB;EAC5B,IAAI;EACJ,QAAQ,eAAe;;;;;;;;;;;;;;;;;;EAkBvB,WACI,cAAc,kBACd,eAAe,cAAc;;;;;;;;;;;;;;;;iBAiBnB,wBAAwB,uBACtC,QAAQ,kBAAkB,kBACzB,UAAU"}