@atlaskit/prosemirror-input-rules 3.4.0 → 3.4.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @atlaskit/prosemirror-input-rules
2
2
 
3
+ ## 3.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`098cfbb01dc36`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/098cfbb01dc36) -
8
+ Add missing npmignore files to remove unnecessary files from published package
9
+
3
10
  ## 3.4.0
4
11
 
5
12
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/prosemirror-input-rules",
3
- "version": "3.4.0",
3
+ "version": "3.4.1",
4
4
  "description": "A package that contains helpers to create autoformatting rules for ProseMirror",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -31,7 +31,7 @@
31
31
  "@babel/runtime": "^7.0.0"
32
32
  },
33
33
  "devDependencies": {
34
- "@atlaskit/editor-common": "^107.17.0"
34
+ "@atlaskit/editor-common": "^107.28.0"
35
35
  },
36
36
  "techstack": {
37
37
  "@atlassian/frontend": {
@@ -1,26 +0,0 @@
1
- {
2
- "extends": "../../../../tsconfig.entry-points.confluence.json",
3
- "compilerOptions": {
4
- "declaration": true,
5
- "target": "es5",
6
- "composite": true,
7
- "outDir": "../../../../../confluence/tsDist/@atlaskit__prosemirror-input-rules",
8
- "rootDir": "../"
9
- },
10
- "include": [
11
- "../src/**/*.ts",
12
- "../src/**/*.tsx"
13
- ],
14
- "exclude": [
15
- "../src/**/__tests__/*",
16
- "../src/**/*.test.*",
17
- "../src/**/test.*",
18
- "../src/**/examples.*",
19
- "../src/**/examples/*",
20
- "../src/**/examples/**/*",
21
- "../src/**/*.stories.*",
22
- "../src/**/stories/*",
23
- "../src/**/stories/**/*"
24
- ],
25
- "references": []
26
- }
@@ -1,26 +0,0 @@
1
- {
2
- "extends": "../../../../tsconfig.entry-points.dev-agents.json",
3
- "compilerOptions": {
4
- "declaration": true,
5
- "target": "es5",
6
- "outDir": "../../../../../dev-agents/tsDist/@atlaskit__prosemirror-input-rules/app",
7
- "rootDir": "../",
8
- "composite": true
9
- },
10
- "include": [
11
- "../src/**/*.ts",
12
- "../src/**/*.tsx"
13
- ],
14
- "exclude": [
15
- "../src/**/__tests__/*",
16
- "../src/**/*.test.*",
17
- "../src/**/test.*",
18
- "../src/**/examples.*",
19
- "../src/**/examples/*",
20
- "../src/**/examples/**/*",
21
- "../src/**/*.stories.*",
22
- "../src/**/stories/*",
23
- "../src/**/stories/**/*"
24
- ],
25
- "references": []
26
- }
@@ -1,26 +0,0 @@
1
- {
2
- "extends": "../../../../tsconfig.entry-points.jira.json",
3
- "compilerOptions": {
4
- "declaration": true,
5
- "target": "es5",
6
- "outDir": "../../../../../tsDist/@atlaskit__prosemirror-input-rules/app",
7
- "rootDir": "../",
8
- "composite": true
9
- },
10
- "include": [
11
- "../src/**/*.ts",
12
- "../src/**/*.tsx"
13
- ],
14
- "exclude": [
15
- "../src/**/__tests__/*",
16
- "../src/**/*.test.*",
17
- "../src/**/test.*",
18
- "../src/**/examples.*",
19
- "../src/**/examples/*",
20
- "../src/**/examples/**/*",
21
- "../src/**/*.stories.*",
22
- "../src/**/stories/*",
23
- "../src/**/stories/**/*"
24
- ],
25
- "references": []
26
- }
@@ -1,26 +0,0 @@
1
- {
2
- "extends": "../../../../tsconfig.entry-points.post-office.json",
3
- "compilerOptions": {
4
- "declaration": true,
5
- "target": "es5",
6
- "outDir": "../../../../../post-office/tsDist/@atlaskit__prosemirror-input-rules/app",
7
- "rootDir": "../",
8
- "composite": true
9
- },
10
- "include": [
11
- "../src/**/*.ts",
12
- "../src/**/*.tsx"
13
- ],
14
- "exclude": [
15
- "../src/**/__tests__/*",
16
- "../src/**/*.test.*",
17
- "../src/**/test.*",
18
- "../src/**/examples.*",
19
- "../src/**/examples/*",
20
- "../src/**/examples/**/*",
21
- "../src/**/*.stories.*",
22
- "../src/**/stories/*",
23
- "../src/**/stories/**/*"
24
- ],
25
- "references": []
26
- }
@@ -1,26 +0,0 @@
1
- {
2
- "extends": "../../../../tsconfig.entry-points.rovo-extension.json",
3
- "compilerOptions": {
4
- "declaration": true,
5
- "target": "es5",
6
- "outDir": "../../../../../rovo-extension/tsDist/@atlaskit__prosemirror-input-rules/app",
7
- "rootDir": "../",
8
- "composite": true
9
- },
10
- "include": [
11
- "../src/**/*.ts",
12
- "../src/**/*.tsx"
13
- ],
14
- "exclude": [
15
- "../src/**/__tests__/*",
16
- "../src/**/*.test.*",
17
- "../src/**/test.*",
18
- "../src/**/examples.*",
19
- "../src/**/examples/*",
20
- "../src/**/examples/**/*",
21
- "../src/**/*.stories.*",
22
- "../src/**/stories/*",
23
- "../src/**/stories/**/*"
24
- ],
25
- "references": []
26
- }
@@ -1,26 +0,0 @@
1
- {
2
- "extends": "../../../../tsconfig.entry-points.townsquare.json",
3
- "compilerOptions": {
4
- "declaration": true,
5
- "target": "es5",
6
- "outDir": "../../../../../townsquare/tsDist/@atlaskit__prosemirror-input-rules/app",
7
- "rootDir": "../",
8
- "composite": true
9
- },
10
- "include": [
11
- "../src/**/*.ts",
12
- "../src/**/*.tsx"
13
- ],
14
- "exclude": [
15
- "../src/**/__tests__/*",
16
- "../src/**/*.test.*",
17
- "../src/**/test.*",
18
- "../src/**/examples.*",
19
- "../src/**/examples/*",
20
- "../src/**/examples/**/*",
21
- "../src/**/*.stories.*",
22
- "../src/**/stories/*",
23
- "../src/**/stories/**/*"
24
- ],
25
- "references": []
26
- }
@@ -1,20 +0,0 @@
1
- {
2
- "extends": "../../../../tsconfig.entry-points.volt.json",
3
- "compilerOptions": {
4
- "declaration": true,
5
- "target": "es5",
6
- "outDir": "../../../../../volt/tsDist/@atlaskit__prosemirror-input-rules/app",
7
- "rootDir": "../",
8
- "composite": true
9
- },
10
- "include": [
11
- "../src/**/*.ts",
12
- "../src/**/*.tsx"
13
- ],
14
- "exclude": [
15
- "../src/**/__tests__/*",
16
- "../src/**/*.test.*",
17
- "../src/**/test.*"
18
- ],
19
- "references": []
20
- }
@@ -1,23 +0,0 @@
1
- {
2
- "extends": "../tsconfig",
3
- "compilerOptions": {
4
- "declaration": true,
5
- "target": "es5",
6
- "paths": {}
7
- },
8
- "include": [
9
- "../src/**/*.ts",
10
- "../src/**/*.tsx"
11
- ],
12
- "exclude": [
13
- "../src/**/__tests__/*",
14
- "../src/**/*.test.*",
15
- "../src/**/test.*",
16
- "../src/**/examples.*",
17
- "../src/**/examples/*",
18
- "../src/**/examples/**/*",
19
- "../src/**/*.stories.*",
20
- "../src/**/stories/*",
21
- "../src/**/stories/**/*"
22
- ]
23
- }
@@ -1,390 +0,0 @@
1
- import type { Transaction } from '@atlaskit/editor-prosemirror/state';
2
- import { EditorState, PluginKey } from '@atlaskit/editor-prosemirror/state';
3
- import { EditorView } from '@atlaskit/editor-prosemirror/view';
4
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
5
- import { createEditorState } from '@atlaskit/editor-test-helpers/create-editor-state';
6
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
7
- import { code_block, doc, p } from '@atlaskit/editor-test-helpers/doc-builder';
8
-
9
- import type { InputRuleWrapper } from '../../editor-common';
10
- import { createInputEventHandler } from '../../handler';
11
- import type { HandleInputEvent } from '../../types';
12
-
13
- describe('input-tule/handles/createInputEventHandler', () => {
14
- let inputEvent: HandleInputEvent;
15
- let editorView: EditorView;
16
- let dispatchSpy: jest.SpyInstance<void, [Transaction]>;
17
- let rules: InputRuleWrapper[] = [];
18
- let initialEditorState: EditorState;
19
- let RULE_BEFORE: InputRuleWrapper;
20
-
21
- type FROM_TYPE = number;
22
- type TO_TYPE = number;
23
- let ruleHandlerMock: jest.Mock<
24
- Transaction | null,
25
- [EditorState, RegExpExecArray, FROM_TYPE, TO_TYPE]
26
- >;
27
-
28
- const pluginKey = new PluginKey('lol');
29
- const TEXT_INSERTED = 'a';
30
-
31
- beforeEach(() => {
32
- initialEditorState = createEditorState(doc(p('before{<>}')));
33
- editorView = new EditorView(null, {
34
- state: initialEditorState,
35
- });
36
-
37
- dispatchSpy = jest.spyOn(editorView, 'dispatch');
38
-
39
- ruleHandlerMock = jest.fn().mockImplementation((state) => {
40
- return state.tr;
41
- });
42
-
43
- RULE_BEFORE = {
44
- // Ignored via go/ees005
45
- // eslint-disable-next-line require-unicode-regexp
46
- match: /^(before).*/,
47
- handler: ruleHandlerMock,
48
- };
49
- });
50
-
51
- afterEach(() => {
52
- dispatchSpy.mockReset();
53
- rules = [];
54
- });
55
-
56
- describe('when selection is inside of code node', () => {
57
- let inputHandleResult: boolean;
58
- beforeEach(() => {
59
- const newEditorState = createEditorState(doc(code_block()('before{<>}')));
60
- editorView = new EditorView(null, {
61
- state: newEditorState,
62
- });
63
-
64
- dispatchSpy = jest.spyOn(editorView, 'dispatch');
65
-
66
- const {
67
- selection: { from, to },
68
- } = newEditorState;
69
-
70
- inputEvent = createInputEventHandler({
71
- rules,
72
- pluginKey,
73
- allowInsertTextOnDocument: true,
74
- });
75
-
76
- inputHandleResult = inputEvent({
77
- view: editorView,
78
- from,
79
- to,
80
- text: TEXT_INSERTED,
81
- });
82
- });
83
-
84
- it('should return false', () => {
85
- expect(inputHandleResult).toBeFalsy();
86
- });
87
-
88
- it('should not call the editorView dispatch function', () => {
89
- expect(dispatchSpy).not.toHaveBeenCalled();
90
- });
91
- });
92
-
93
- describe('when there is no rule match', () => {
94
- let inputHandleResult: boolean;
95
- beforeEach(() => {
96
- const RULE_AFTER = {
97
- // Ignored via go/ees005
98
- // eslint-disable-next-line require-unicode-regexp
99
- match: /^(after).*/,
100
- handler: jest.fn().mockImplementation((state) => {
101
- return state.tr;
102
- }),
103
- };
104
-
105
- rules = [RULE_AFTER];
106
-
107
- const {
108
- selection: { from, to },
109
- } = initialEditorState;
110
-
111
- inputEvent = createInputEventHandler({
112
- rules,
113
- pluginKey,
114
- allowInsertTextOnDocument: true,
115
- });
116
-
117
- inputHandleResult = inputEvent({
118
- view: editorView,
119
- from,
120
- to,
121
- text: TEXT_INSERTED,
122
- });
123
- });
124
-
125
- it('should return false', () => {
126
- expect(inputHandleResult).toBeFalsy();
127
- });
128
-
129
- it('should not call the editorView dispatch function', () => {
130
- expect(dispatchSpy).not.toHaveBeenCalled();
131
- });
132
- });
133
-
134
- describe('when there is rule match', () => {
135
- beforeEach(() => {
136
- rules = [RULE_BEFORE];
137
- });
138
-
139
- describe.each([true, false])(
140
- 'and when allowInsertTextOnDocument is %s',
141
- (allowInsertTextOnDocument) => {
142
- beforeEach(() => {
143
- const {
144
- selection: { from, to },
145
- } = initialEditorState;
146
-
147
- inputEvent = createInputEventHandler({
148
- rules,
149
- pluginKey,
150
- allowInsertTextOnDocument,
151
- });
152
-
153
- inputEvent({
154
- view: editorView,
155
- from,
156
- to,
157
- text: TEXT_INSERTED,
158
- });
159
- });
160
-
161
- it('should call the dispatch function', () => {
162
- expect(editorView.dispatch).toHaveBeenCalled();
163
- });
164
-
165
- it('should call the rule handler function', () => {
166
- expect(RULE_BEFORE.handler).toHaveBeenCalled();
167
- });
168
-
169
- it('should add the InputRulePluginState inside of the transaction', () => {
170
- const tr = dispatchSpy.mock.calls[0][0];
171
-
172
- expect(tr.getMeta(pluginKey)).toBeDefined();
173
- });
174
-
175
- it('should fill InputRulePluginState', () => {
176
- const tr = dispatchSpy.mock.calls[0][0];
177
-
178
- expect(tr.getMeta(pluginKey)).toEqual({
179
- from: 1,
180
- to: 7,
181
- textInserted: TEXT_INSERTED,
182
- matchedRule: {
183
- ...RULE_BEFORE,
184
- result: expect.any(Array),
185
- },
186
- });
187
- });
188
-
189
- it('should return true', () => {
190
- const {
191
- selection: { from, to },
192
- } = initialEditorState;
193
-
194
- inputEvent = createInputEventHandler({
195
- rules,
196
- pluginKey,
197
- allowInsertTextOnDocument: true,
198
- });
199
-
200
- const result = inputEvent({
201
- view: editorView,
202
- from,
203
- to,
204
- text: TEXT_INSERTED,
205
- });
206
-
207
- expect(result).toBeTruthy();
208
- });
209
-
210
- it('should call the rule handler with the from position calculated', () => {
211
- const handlerArgs = ruleHandlerMock.mock.calls[0];
212
- const fromArg: number = handlerArgs[2];
213
-
214
- expect(fromArg).toBe(1);
215
- });
216
-
217
- describe('when onBeforeRegexMatch is given', () => {
218
- let onBeforeRegexMatchMock: jest.Mock;
219
-
220
- beforeEach(() => {
221
- onBeforeRegexMatchMock = jest.fn();
222
- const {
223
- selection: { from, to },
224
- } = initialEditorState;
225
-
226
- inputEvent = createInputEventHandler({
227
- rules,
228
- pluginKey,
229
- allowInsertTextOnDocument,
230
- onBeforeRegexMatch: onBeforeRegexMatchMock,
231
- });
232
-
233
- inputEvent({
234
- view: editorView,
235
- from,
236
- to,
237
- text: TEXT_INSERTED,
238
- });
239
- });
240
-
241
- it('should be called', () => {
242
- expect(onBeforeRegexMatchMock).toHaveBeenCalled();
243
- });
244
- });
245
-
246
- describe('and when onInputEvent return false', () => {
247
- let inputHandleResult: boolean;
248
- let onInputEventMock: jest.Mock;
249
-
250
- beforeEach(() => {
251
- dispatchSpy.mockReset();
252
- onInputEventMock = jest.fn().mockReturnValue(false);
253
-
254
- const {
255
- selection: { from, to },
256
- } = initialEditorState;
257
-
258
- inputEvent = createInputEventHandler({
259
- rules,
260
- pluginKey,
261
- allowInsertTextOnDocument,
262
- onInputEvent: onInputEventMock,
263
- });
264
-
265
- inputHandleResult = inputEvent({
266
- view: editorView,
267
- from,
268
- to,
269
- text: TEXT_INSERTED,
270
- });
271
- });
272
-
273
- it('should return false', () => {
274
- expect(inputHandleResult).toBeFalsy();
275
- });
276
-
277
- it('should call onInputEvent', () => {
278
- expect(onInputEventMock).toHaveBeenCalled();
279
- });
280
-
281
- it('should not call the editorView dispatch function', () => {
282
- expect(dispatchSpy).not.toHaveBeenCalled();
283
- });
284
- });
285
- },
286
- );
287
-
288
- describe('and when allowInsertTextOnDocument is true', () => {
289
- beforeEach(() => {
290
- const {
291
- selection: { from, to },
292
- } = editorView.state;
293
-
294
- inputEvent = createInputEventHandler({
295
- rules,
296
- pluginKey,
297
- allowInsertTextOnDocument: true,
298
- });
299
-
300
- inputEvent({
301
- view: editorView,
302
- from,
303
- to,
304
- text: TEXT_INSERTED,
305
- });
306
- });
307
-
308
- it('should dispatch a transaction with the text inserted', () => {
309
- const tr = dispatchSpy.mock.calls[0][0];
310
-
311
- const { doc: docExpected } = createEditorState(doc(p(`before${TEXT_INSERTED}`)));
312
-
313
- expect(tr.doc.toJSON()).toEqual(docExpected.toJSON());
314
- });
315
-
316
- it('should call the rule handler with the original document', () => {
317
- const handlerArgs = ruleHandlerMock.mock.calls[0];
318
- const nextEditorState: EditorState = handlerArgs[0];
319
-
320
- const { doc: docExpected } = createEditorState(doc(p(`before`)));
321
-
322
- expect(nextEditorState.doc.toJSON()).toEqual(docExpected.toJSON());
323
- });
324
-
325
- it('should call the rule handler with the same to position', () => {
326
- const handlerArgs = ruleHandlerMock.mock.calls[0];
327
- const {
328
- selection: { to },
329
- } = initialEditorState;
330
-
331
- expect(handlerArgs).toEqual([
332
- expect.any(EditorState),
333
- expect.any(Array),
334
- expect.any(Number),
335
- to,
336
- ]);
337
- });
338
- });
339
-
340
- describe('and when allowInsertTextOnDocument is false', () => {
341
- beforeEach(() => {
342
- const {
343
- selection: { from, to },
344
- } = editorView.state;
345
-
346
- inputEvent = createInputEventHandler({
347
- rules,
348
- pluginKey,
349
- allowInsertTextOnDocument: false,
350
- });
351
-
352
- inputEvent({
353
- view: editorView,
354
- from,
355
- to,
356
- text: TEXT_INSERTED,
357
- });
358
- });
359
-
360
- it('should call the rule handler using the current editor state', () => {
361
- const handlerArgs = ruleHandlerMock.mock.calls[0];
362
- const nextEditorState: EditorState = handlerArgs[0];
363
-
364
- expect(nextEditorState).toBe(initialEditorState);
365
- });
366
-
367
- it('should call the rule handler without the text length at the end position', () => {
368
- const handlerArgs = ruleHandlerMock.mock.calls[0];
369
- const {
370
- selection: { to },
371
- } = initialEditorState;
372
-
373
- expect(handlerArgs).toEqual([
374
- expect.any(EditorState),
375
- expect.any(Array),
376
- expect.any(Number),
377
- to,
378
- ]);
379
- });
380
-
381
- it('should dispatch a transaction without', () => {
382
- const tr = dispatchSpy.mock.calls[0][0];
383
-
384
- const { doc: docExpected } = createEditorState(doc(p(`before`)));
385
-
386
- expect(tr.doc.toJSON()).toEqual(docExpected.toJSON());
387
- });
388
- });
389
- });
390
- });