@modusoperandi/licit 0.13.3 → 0.13.20

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.
Files changed (62) hide show
  1. package/.eslintrc.js +59 -55
  2. package/README.md +15 -1
  3. package/dist/ListItemNodeSpec.js +1 -1
  4. package/dist/ListItemNodeSpec.js.flow +1 -1
  5. package/dist/bom.xml +5147 -8743
  6. package/dist/client/CollabConnector.js +5 -1
  7. package/dist/client/CollabConnector.js.flow +6 -2
  8. package/dist/client/EditorConnection.js +5 -4
  9. package/dist/client/EditorConnection.js.flow +10 -5
  10. package/dist/client/Licit.js +105 -30
  11. package/dist/client/Licit.js.flow +120 -47
  12. package/dist/client/Licit.test.js +29 -2
  13. package/dist/client/Licit.test.js.flow +33 -2
  14. package/dist/client/SimpleConnector.js +7 -0
  15. package/dist/client/SimpleConnector.js.flow +6 -0
  16. package/dist/client/http.js +12 -0
  17. package/dist/client/http.js.flow +4 -0
  18. package/dist/convertFromDOMElement.js.flow +2 -2
  19. package/dist/convertFromHTML.js +1 -4
  20. package/dist/convertFromHTML.js.flow +3 -5
  21. package/dist/convertFromJSON.js +12 -28
  22. package/dist/convertFromJSON.js.flow +9 -31
  23. package/dist/createEmptyEditorState.js +3 -6
  24. package/dist/createEmptyEditorState.js.flow +4 -8
  25. package/dist/index.js +11 -1
  26. package/dist/index.js.flow +1 -1
  27. package/dist/patchStyleElements.js +1 -3
  28. package/dist/patchStyleElements.js.flow +2 -2
  29. package/dist/ui/czi-link-tooltip.css +1 -1
  30. package/dist/ui/czi-vars.css +1 -1
  31. package/licit/client/index.js +2 -1
  32. package/licit/server/collab/instance.js +21 -6
  33. package/licit/server/collab/server.js +25 -5
  34. package/licit/server/collab/start.js +1 -1
  35. package/package.json +5 -10
  36. package/src/ListItemNodeSpec.js +1 -1
  37. package/src/client/CollabConnector.js +6 -2
  38. package/src/client/EditorConnection.js +10 -5
  39. package/src/client/Licit.js +120 -47
  40. package/src/client/Licit.test.js +33 -2
  41. package/src/client/SimpleConnector.js +6 -0
  42. package/src/client/http.js +4 -0
  43. package/src/convertFromDOMElement.js +2 -2
  44. package/src/convertFromHTML.js +3 -5
  45. package/src/convertFromJSON.js +9 -31
  46. package/src/createEmptyEditorState.js +4 -8
  47. package/src/index.js +1 -1
  48. package/src/patchStyleElements.js +2 -2
  49. package/src/ui/czi-link-tooltip.css +1 -1
  50. package/src/ui/czi-vars.css +1 -1
  51. package/utils/build_licit_collab_server.js +1 -1
  52. package/webpack.config.js +1 -1
  53. package/node_modules/prosemirror-utils/LICENSE +0 -13
  54. package/node_modules/prosemirror-utils/README.md +0 -0
  55. package/node_modules/prosemirror-utils/dist/helpers.js +0 -119
  56. package/node_modules/prosemirror-utils/dist/index.js +0 -17
  57. package/node_modules/prosemirror-utils/dist/index.js.map +0 -1
  58. package/node_modules/prosemirror-utils/dist/node.js +0 -106
  59. package/node_modules/prosemirror-utils/dist/selection.js +0 -168
  60. package/node_modules/prosemirror-utils/dist/transforms.js +0 -257
  61. package/node_modules/prosemirror-utils/package.json +0 -81
  62. package/node_modules/prosemirror-utils/typings.d.ts +0 -79
@@ -1,257 +0,0 @@
1
- import { NodeSelection, Selection } from 'prosemirror-state';
2
- import { Fragment } from 'prosemirror-model';
3
- import { findParentNodeOfType, findPositionOfNodeBefore } from './selection';
4
- import {
5
- cloneTr,
6
- isNodeSelection,
7
- replaceNodeAtPos,
8
- removeNodeAtPos,
9
- canInsert,
10
- isEmptyParagraph
11
- } from './helpers';
12
-
13
- // :: (nodeType: union<NodeType, [NodeType]>) → (tr: Transaction) → Transaction
14
- // Returns a new transaction that removes a node of a given `nodeType`. It will return an original transaction if parent node hasn't been found.
15
- //
16
- // ```javascript
17
- // dispatch(
18
- // removeParentNodeOfType(schema.nodes.table)(tr)
19
- // );
20
- // ```
21
- export const removeParentNodeOfType = nodeType => tr => {
22
- const parent = findParentNodeOfType(nodeType)(tr.selection);
23
- if (parent) {
24
- return removeNodeAtPos(parent.pos)(tr);
25
- }
26
- return tr;
27
- };
28
-
29
- // :: (nodeType: union<NodeType, [NodeType]>, content: union<ProseMirrorNode, Fragment>) → (tr: Transaction) → Transaction
30
- // Returns a new transaction that replaces parent node of a given `nodeType` with the given `content`. It will return an original transaction if either parent node hasn't been found or replacing is not possible.
31
- //
32
- // ```javascript
33
- // const node = schema.nodes.paragraph.createChecked({}, schema.text('new'));
34
- //
35
- // dispatch(
36
- // replaceParentNodeOfType(schema.nodes.table, node)(tr)
37
- // );
38
- // ```
39
- export const replaceParentNodeOfType = (nodeType, content) => tr => {
40
- if (!Array.isArray(nodeType)) {
41
- nodeType = [nodeType];
42
- }
43
- for (let i = 0, count = nodeType.length; i < count; i++) {
44
- const parent = findParentNodeOfType(nodeType[i])(tr.selection);
45
- if (parent) {
46
- const newTr = replaceNodeAtPos(parent.pos, content)(tr);
47
- if (newTr !== tr) {
48
- return newTr;
49
- }
50
- }
51
- }
52
- return tr;
53
- };
54
-
55
- // :: (tr: Transaction) → Transaction
56
- // Returns a new transaction that removes selected node. It will return an original transaction if current selection is not a `NodeSelection`.
57
- //
58
- // ```javascript
59
- // dispatch(
60
- // removeSelectedNode(tr)
61
- // );
62
- // ```
63
- export const removeSelectedNode = tr => {
64
- if (isNodeSelection(tr.selection)) {
65
- const from = tr.selection.$from.pos;
66
- const to = tr.selection.$to.pos;
67
- return cloneTr(tr.delete(from, to));
68
- }
69
- return tr;
70
- };
71
-
72
- // :: (content: union<ProseMirrorNode, ProseMirrorFragment>) → (tr: Transaction) → Transaction
73
- // Returns a new transaction that replaces selected node with a given `node`, keeping NodeSelection on the new `node`.
74
- // It will return the original transaction if either current selection is not a NodeSelection or replacing is not possible.
75
- //
76
- // ```javascript
77
- // const node = schema.nodes.paragraph.createChecked({}, schema.text('new'));
78
- // dispatch(
79
- // replaceSelectedNode(node)(tr)
80
- // );
81
- // ```
82
- export const replaceSelectedNode = content => tr => {
83
- if (isNodeSelection(tr.selection)) {
84
- const { $from, $to } = tr.selection;
85
- if (
86
- (content instanceof Fragment &&
87
- $from.parent.canReplace($from.index(), $from.indexAfter(), content)) ||
88
- $from.parent.canReplaceWith(
89
- $from.index(),
90
- $from.indexAfter(),
91
- content.type
92
- )
93
- ) {
94
- return cloneTr(
95
- tr
96
- .replaceWith($from.pos, $to.pos, content)
97
- // restore node selection
98
- .setSelection(new NodeSelection(tr.doc.resolve($from.pos)))
99
- );
100
- }
101
- }
102
- return tr;
103
- };
104
-
105
- // :: (position: number, dir: ?number) → (tr: Transaction) → Transaction
106
- // Returns a new transaction that tries to find a valid cursor selection starting at the given `position`
107
- // and searching back if `dir` is negative, and forward if positive.
108
- // If a valid cursor position hasn't been found, it will return the original transaction.
109
- //
110
- // ```javascript
111
- // dispatch(
112
- // setTextSelection(5)(tr)
113
- // );
114
- // ```
115
- export const setTextSelection = (position, dir = 1) => tr => {
116
- const nextSelection = Selection.findFrom(tr.doc.resolve(position), dir, true);
117
- if (nextSelection) {
118
- return tr.setSelection(nextSelection);
119
- }
120
- return tr;
121
- };
122
-
123
- const isSelectableNode = node => node.type && node.type.spec.selectable;
124
- const shouldSelectNode = node => isSelectableNode(node) && node.type.isLeaf;
125
-
126
- const setSelection = (node, pos, tr) => {
127
- if (shouldSelectNode(node)) {
128
- return tr.setSelection(new NodeSelection(tr.doc.resolve(pos)));
129
- }
130
- return setTextSelection(pos)(tr);
131
- };
132
-
133
- // :: (content: union<ProseMirrorNode, Fragment>, position: ?number, tryToReplace?: boolean) → (tr: Transaction) → Transaction
134
- // Returns a new transaction that inserts a given `content` at the current cursor position, or at a given `position`, if it is allowed by schema. If schema restricts such nesting, it will try to find an appropriate place for a given node in the document, looping through parent nodes up until the root document node.
135
- // If `tryToReplace` is true and current selection is a NodeSelection, it will replace selected node with inserted content if its allowed by schema.
136
- // If cursor is inside of an empty paragraph, it will try to replace that paragraph with the given content. If insertion is successful and inserted node has content, it will set cursor inside of that content.
137
- // It will return an original transaction if the place for insertion hasn't been found.
138
- //
139
- // ```javascript
140
- // const node = schema.nodes.extension.createChecked({});
141
- // dispatch(
142
- // safeInsert(node)(tr)
143
- // );
144
- // ```
145
- export const safeInsert = (content, position, tryToReplace) => tr => {
146
- const hasPosition = typeof position === 'number';
147
- const { $from } = tr.selection;
148
- const $insertPos = hasPosition
149
- ? tr.doc.resolve(position)
150
- : isNodeSelection(tr.selection)
151
- ? tr.doc.resolve($from.pos + 1)
152
- : $from;
153
- const { parent } = $insertPos;
154
-
155
- // try to replace selected node
156
- if (isNodeSelection(tr.selection) && tryToReplace) {
157
- const oldTr = tr;
158
- tr = replaceSelectedNode(content)(tr);
159
- if (oldTr !== tr) {
160
- return tr;
161
- }
162
- }
163
-
164
- // try to replace an empty paragraph
165
- if (isEmptyParagraph(parent)) {
166
- const oldTr = tr;
167
- tr = replaceParentNodeOfType(parent.type, content)(tr);
168
- if (oldTr !== tr) {
169
- const pos = isSelectableNode(content)
170
- ? // for selectable node, selection position would be the position of the replaced parent
171
- $insertPos.before($insertPos.depth)
172
- : $insertPos.pos;
173
- return setSelection(content, pos, tr);
174
- }
175
- }
176
-
177
- // given node is allowed at the current cursor position
178
- if (canInsert($insertPos, content)) {
179
- tr.insert($insertPos.pos, content);
180
- const pos = hasPosition
181
- ? $insertPos.pos
182
- : isSelectableNode(content)
183
- ? // for atom nodes selection position after insertion is the previous pos
184
- tr.selection.$anchor.pos - 1
185
- : tr.selection.$anchor.pos;
186
- return cloneTr(setSelection(content, pos, tr));
187
- }
188
-
189
- // looking for a place in the doc where the node is allowed
190
- for (let i = $insertPos.depth; i > 0; i--) {
191
- const pos = $insertPos.after(i);
192
- const $pos = tr.doc.resolve(pos);
193
- if (canInsert($pos, content)) {
194
- tr.insert(pos, content);
195
- return cloneTr(setSelection(content, pos, tr));
196
- }
197
- }
198
- return tr;
199
- };
200
-
201
- // :: (nodeType: union<NodeType, [NodeType]>, type: ?union<NodeType, null>, attrs: ?union<Object, null>, marks?: [Mark]) → (tr: Transaction) → Transaction
202
- // Returns a transaction that changes the type, attributes, and/or marks of the parent node of a given `nodeType`.
203
- //
204
- // ```javascript
205
- // const node = schema.nodes.extension.createChecked({});
206
- // dispatch(
207
- // setParentNodeMarkup(schema.nodes.panel, null, { panelType })(tr);
208
- // );
209
- // ```
210
- export const setParentNodeMarkup = (nodeType, type, attrs, marks) => tr => {
211
- const parent = findParentNodeOfType(nodeType)(tr.selection);
212
- if (parent) {
213
- return cloneTr(
214
- tr.setNodeMarkup(
215
- parent.pos,
216
- type,
217
- Object.assign({}, parent.node.attrs, attrs),
218
- marks
219
- )
220
- );
221
- }
222
- return tr;
223
- };
224
-
225
- // :: (nodeType: union<NodeType, [NodeType]>) → (tr: Transaction) → Transaction
226
- // Returns a new transaction that sets a `NodeSelection` on a parent node of a `given nodeType`.
227
- //
228
- // ```javascript
229
- // dispatch(
230
- // selectParentNodeOfType([tableCell, tableHeader])(state.tr)
231
- // );
232
- // ```
233
- export const selectParentNodeOfType = nodeType => tr => {
234
- if (!isNodeSelection(tr.selection)) {
235
- const parent = findParentNodeOfType(nodeType)(tr.selection);
236
- if (parent) {
237
- return cloneTr(tr.setSelection(NodeSelection.create(tr.doc, parent.pos)));
238
- }
239
- }
240
- return tr;
241
- };
242
-
243
- // :: (tr: Transaction) → Transaction
244
- // Returns a new transaction that deletes previous node.
245
- //
246
- // ```javascript
247
- // dispatch(
248
- // removeNodeBefore(state.tr)
249
- // );
250
- // ```
251
- export const removeNodeBefore = tr => {
252
- const position = findPositionOfNodeBefore(tr.selection);
253
- if (typeof position === 'number') {
254
- return removeNodeAtPos(position)(tr);
255
- }
256
- return tr;
257
- };
@@ -1,81 +0,0 @@
1
- {
2
- "name": "prosemirror-utils",
3
- "version": "1.0.0-0",
4
- "description": "Utils library for ProseMirror",
5
- "main": "dist/index.js",
6
- "author": {
7
- "name": "Eduard Shvedai",
8
- "email": "eshvedai@gmail.com",
9
- "url": "https://github.com/eshvedai"
10
- },
11
- "maintainers": [
12
- {
13
- "name": "Eduard Shvedai",
14
- "email": "eshvedai@atlassian.com"
15
- }
16
- ],
17
- "license": "Apache-2.0",
18
- "repository": {
19
- "type": "git",
20
- "url": "git://github.com/atlassian/prosemirror-utils.git"
21
- },
22
- "keywords": [
23
- "ProseMirror",
24
- "utils",
25
- "helpers"
26
- ],
27
- "jest": {
28
- "transform": {
29
- "^.+\\.js$": "babel-jest"
30
- },
31
- "setupTestFrameworkScriptFile": "./jestFrameworkSetup.js",
32
- "testURL": "http://localhost/"
33
- },
34
- "typings": "typings.d.ts",
35
- "files": [
36
- "dist",
37
- "typings.d.ts"
38
- ],
39
- "scripts": {
40
- "build": "rollup -c",
41
- "build_readme": "builddocs --name utils --format markdown --main src/README.md src/*.js > README.md",
42
- "build_all": "npm run build && npm run build_readme",
43
- "test": "NODE_ENV=testing jest",
44
- "test-ci": "NODE_ENV=testing jest --coverage && codecov",
45
- "prepare": "npm run build",
46
- "precommit": "lint-staged"
47
- },
48
- "peerDependencies": {
49
- "prosemirror-model": "^1.0.0",
50
- "prosemirror-state": "^1.0.1"
51
- },
52
- "devDependencies": {
53
- "babel-core": "^6.26.3",
54
- "babel-jest": "^23.6.0",
55
- "babel-preset-env": "^1.7.0",
56
- "builddocs": "^0.3.2",
57
- "codecov": "^3.1.0",
58
- "husky": "^1.3.0",
59
- "jest": "^23.6.0",
60
- "jest-diff": "^23.6.0",
61
- "lint-staged": "^8.1.0",
62
- "prettier": "^1.15.3",
63
- "prosemirror-model": "^1.0.0",
64
- "prosemirror-schema-basic": "^1.0.0",
65
- "prosemirror-state": "^1.0.1",
66
- "prosemirror-test-builder": "^1.0.1",
67
- "prosemirror-view": "^1.1.1",
68
- "rollup": "^0.56.3",
69
- "rollup-plugin-babel": "^3.0.3"
70
- },
71
- "lint-staged": {
72
- "*.{js, md}": [
73
- "prettier --write",
74
- "git add"
75
- ]
76
- },
77
- "prettier": {
78
- "singleQuote": true,
79
- "trailing-comma": "es5"
80
- }
81
- }
@@ -1,79 +0,0 @@
1
- import { Node as ProsemirrorNode, Schema, NodeType, Mark, MarkType, ResolvedPos, Fragment } from 'prosemirror-model';
2
- import { Selection, Transaction } from 'prosemirror-state';
3
-
4
- export type Predicate = (node: ProsemirrorNode) => boolean;
5
-
6
- export type DomAtPos = (pos: number) => {node: Node, offset: number};
7
-
8
- export type ContentNodeWithPos = {pos: number, start: number, depth: number, node: ProsemirrorNode};
9
-
10
- export type NodeWithPos = {pos: number, node: ProsemirrorNode};
11
-
12
- export type CellTransform = (cell: ContentNodeWithPos, tr: Transaction) => Transaction;
13
-
14
- export type MovementOptions = { tryToFit: boolean, direction?: -1 | 0 | 1 };
15
-
16
- // Selection
17
- export function findParentNode(predicate: Predicate): (selection: Selection) => ContentNodeWithPos | undefined;
18
-
19
- export function findParentNodeClosestToPos($pos: ResolvedPos, predicate: Predicate): ContentNodeWithPos | undefined;
20
-
21
- export function findParentDomRef(predicate: Predicate, domAtPos: DomAtPos): (selection: Selection) => Node | undefined;
22
-
23
- export function hasParentNode(predicate: Predicate): (selection: Selection) => boolean;
24
-
25
- export function findParentNodeOfType(nodeType: NodeType | NodeType[]): (selection: Selection) => ContentNodeWithPos | undefined;
26
-
27
- export function findParentNodeOfTypeClosestToPos($pos: ResolvedPos, nodeType: NodeType | NodeType[]): ContentNodeWithPos | undefined;
28
-
29
- export function hasParentNodeOfType(nodeType: NodeType | NodeType[]): (selection: Selection) => boolean;
30
-
31
- export function findParentDomRefOfType(nodeType: NodeType | NodeType[], domAtPos: DomAtPos): (selection: Selection) => Node | undefined;
32
-
33
- export function findSelectedNodeOfType(nodeType: NodeType | NodeType[]): (selection: Selection) => ContentNodeWithPos | undefined;
34
-
35
- export function isNodeSelection(selection: Selection): boolean;
36
-
37
- export function findPositionOfNodeBefore(selection: Selection): number | undefined;
38
-
39
- export function findDomRefAtPos(position: number, domAtPos: DomAtPos): Node;
40
-
41
- // Node
42
- export function flatten(node: ProsemirrorNode, descend?: boolean): NodeWithPos[];
43
-
44
- export function findChildren(node: ProsemirrorNode, predicate: Predicate, descend?: boolean): NodeWithPos[];
45
-
46
- export function findTextNodes(node: ProsemirrorNode, descend?: boolean): NodeWithPos[];
47
-
48
- export function findInlineNodes(node: ProsemirrorNode, descend?: boolean): NodeWithPos[];
49
-
50
- export function findBlockNodes(node: ProsemirrorNode, descend?: boolean): NodeWithPos[];
51
-
52
- export function findChildrenByAttr(node: ProsemirrorNode, predicate: Predicate, descend?: boolean): NodeWithPos[];
53
-
54
- export function findChildrenByType(node: ProsemirrorNode, nodeType: NodeType, descend?: boolean): NodeWithPos[];
55
-
56
- export function findChildrenByMark(node: ProsemirrorNode, markType: MarkType, descend?: boolean): NodeWithPos[];
57
-
58
- export function contains(node: ProsemirrorNode, nodeType: NodeType): boolean;
59
-
60
- // Transforms
61
- export function removeParentNodeOfType(nodeType: NodeType | NodeType[]): (tr: Transaction) => Transaction;
62
-
63
- export function replaceParentNodeOfType(nodeType: NodeType | NodeType[], node: ProsemirrorNode): (tr: Transaction) => Transaction;
64
-
65
- export function removeSelectedNode(tr: Transaction): Transaction;
66
-
67
- export function replaceSelectedNode(node: ProsemirrorNode): (tr: Transaction) => Transaction;
68
-
69
- export function canInsert($pos: ResolvedPos, node: ProsemirrorNode | Fragment): boolean;
70
-
71
- export function safeInsert(node: ProsemirrorNode | Fragment, position?: number, tryToReplace?: boolean): (tr: Transaction) => Transaction;
72
-
73
- export function setParentNodeMarkup(nodeType: NodeType | NodeType[], type?: NodeType | null, attrs?: { [key: string]: any } | null, marks?: Mark[]): (tr: Transaction) => Transaction;
74
-
75
- export function selectParentNodeOfType(nodeType: NodeType | NodeType[]): (tr: Transaction) => Transaction;
76
-
77
- export function removeNodeBefore(tr: Transaction): Transaction;
78
-
79
- export function setTextSelection(position: number, dir?: number): (tr: Transaction) => Transaction;