@modusoperandi/licit 0.13.3 → 0.13.10

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 (50) hide show
  1. package/.eslintrc.js +59 -55
  2. package/README.md +15 -1
  3. package/dist/bom.xml +5177 -8773
  4. package/dist/client/EditorConnection.js +2 -2
  5. package/dist/client/EditorConnection.js.flow +3 -3
  6. package/dist/client/Licit.js +63 -15
  7. package/dist/client/Licit.js.flow +81 -35
  8. package/dist/client/Licit.test.js +29 -2
  9. package/dist/client/Licit.test.js.flow +33 -2
  10. package/dist/client/http.js +12 -0
  11. package/dist/client/http.js.flow +4 -0
  12. package/dist/convertFromDOMElement.js.flow +2 -2
  13. package/dist/convertFromHTML.js +1 -4
  14. package/dist/convertFromHTML.js.flow +3 -5
  15. package/dist/convertFromJSON.js +12 -28
  16. package/dist/convertFromJSON.js.flow +9 -31
  17. package/dist/createEmptyEditorState.js +3 -6
  18. package/dist/createEmptyEditorState.js.flow +4 -8
  19. package/dist/index.js +11 -1
  20. package/dist/index.js.flow +1 -1
  21. package/dist/patchStyleElements.js +1 -3
  22. package/dist/patchStyleElements.js.flow +2 -2
  23. package/dist/ui/czi-link-tooltip.css +1 -1
  24. package/dist/ui/czi-vars.css +1 -1
  25. package/licit/client/index.js +2 -1
  26. package/licit/server/collab/instance.js +11 -8
  27. package/licit/server/collab/server.js +6 -6
  28. package/package.json +3 -8
  29. package/src/client/EditorConnection.js +3 -3
  30. package/src/client/Licit.js +81 -35
  31. package/src/client/Licit.test.js +33 -2
  32. package/src/client/http.js +4 -0
  33. package/src/convertFromDOMElement.js +2 -2
  34. package/src/convertFromHTML.js +3 -5
  35. package/src/convertFromJSON.js +9 -31
  36. package/src/createEmptyEditorState.js +4 -8
  37. package/src/index.js +1 -1
  38. package/src/patchStyleElements.js +2 -2
  39. package/src/ui/czi-link-tooltip.css +1 -1
  40. package/src/ui/czi-vars.css +1 -1
  41. package/node_modules/prosemirror-utils/LICENSE +0 -13
  42. package/node_modules/prosemirror-utils/README.md +0 -0
  43. package/node_modules/prosemirror-utils/dist/helpers.js +0 -119
  44. package/node_modules/prosemirror-utils/dist/index.js +0 -17
  45. package/node_modules/prosemirror-utils/dist/index.js.map +0 -1
  46. package/node_modules/prosemirror-utils/dist/node.js +0 -106
  47. package/node_modules/prosemirror-utils/dist/selection.js +0 -168
  48. package/node_modules/prosemirror-utils/dist/transforms.js +0 -257
  49. package/node_modules/prosemirror-utils/package.json +0 -81
  50. package/node_modules/prosemirror-utils/typings.d.ts +0 -79
package/src/index.js CHANGED
@@ -5,6 +5,6 @@ export { default as isEditorStateEmpty } from './isEditorStateEmpty';
5
5
  export { default as uuid } from './ui/uuid';
6
6
  // [FS] IRAD-978 2020-06-05
7
7
  // Export Licit as a component
8
- export { default as Licit } from './client/Licit.js';
8
+ export { default as Licit, DataType } from './client/Licit.js';
9
9
  export { ImageLike, EditorRuntime } from './Types';
10
10
  export { GET, POST, DELETE, PATCH } from './client/http';
@@ -1,6 +1,5 @@
1
1
  // @flow
2
2
 
3
- import stable from 'stable';
4
3
  import toCSSColor from './ui/toCSSColor';
5
4
  import { toCSSLineSpacing } from '@modusoperandi/licit-ui-commands';
6
5
 
@@ -94,7 +93,8 @@ export default function patchStyleElements(doc: Document): void {
94
93
  });
95
94
 
96
95
  // Sort selector by
97
- stable(selectorTextToCSSTexts, sortBySpecificity)
96
+ selectorTextToCSSTexts
97
+ .sort(sortBySpecificity)
98
98
  .reduce(buildElementToCSSTexts.bind(null, doc), new Map<any, any>())
99
99
  .forEach(applyInlineStyleSheetCSSTexts);
100
100
  }
@@ -1,4 +1,4 @@
1
- @import '../../node_modules/@modusoperandi/licit-ui-commands/dist/ui/czi-custom-button.css';
1
+ @import '@modusoperandi/licit-ui-commands/dist/ui/czi-custom-button.css';
2
2
  @import './czi-vars.css';
3
3
 
4
4
  .czi-link-tooltip {
@@ -1,2 +1,2 @@
1
- @import '../../node_modules/@modusoperandi/licit-ui-commands/dist/ui/czi-vars.css';
1
+ @import '@modusoperandi/licit-ui-commands/dist/ui/czi-vars.css';
2
2
 
@@ -1,13 +0,0 @@
1
- Copyright 2018 Atlassian Pty Ltd
2
-
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
-
7
- http://www.apache.org/licenses/LICENSE-2.0
8
-
9
- Unless required by applicable law or agreed to in writing, software
10
- distributed under the License is distributed on an "AS IS" BASIS,
11
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- See the License for the specific language governing permissions and
13
- limitations under the License.
File without changes
@@ -1,119 +0,0 @@
1
- import { NodeSelection } from 'prosemirror-state';
2
- import { Fragment, Node as PMNode } from 'prosemirror-model';
3
- import { setTextSelection } from './transforms';
4
- import { findParentNodeClosestToPos } from './selection';
5
-
6
- // :: (selection: Selection) → boolean
7
- // Checks if current selection is a `NodeSelection`.
8
- //
9
- // ```javascript
10
- // if (isNodeSelection(tr.selection)) {
11
- // // ...
12
- // }
13
- // ```
14
- export const isNodeSelection = selection => {
15
- return selection instanceof NodeSelection;
16
- };
17
-
18
- // (nodeType: union<NodeType, [NodeType]>) → boolean
19
- // Checks if the type a given `node` equals to a given `nodeType`.
20
- export const equalNodeType = (nodeType, node) => {
21
- return (
22
- (Array.isArray(nodeType) && nodeType.indexOf(node.type) > -1) ||
23
- node.type === nodeType
24
- );
25
- };
26
-
27
- // (tr: Transaction) → Transaction
28
- // Creates a new transaction object from a given transaction
29
- export const cloneTr = tr => {
30
- return Object.assign(Object.create(tr), tr).setTime(Date.now());
31
- };
32
-
33
- // (position: number, content: union<ProseMirrorNode, Fragment>) → (tr: Transaction) → Transaction
34
- // Returns a `replace` transaction that replaces a node at a given position with the given `content`.
35
- // It will return the original transaction if replacing is not possible.
36
- // `position` should point at the position immediately before the node.
37
- export const replaceNodeAtPos = (position, content) => tr => {
38
- const node = tr.doc.nodeAt(position);
39
- const $pos = tr.doc.resolve(position);
40
- if (canReplace($pos, content)) {
41
- tr = tr.replaceWith(position, position + node.nodeSize, content);
42
- const start = tr.selection.$from.pos - 1;
43
- // put cursor inside of the inserted node
44
- tr = setTextSelection(Math.max(start, 0), -1)(tr);
45
- // move cursor to the start of the node
46
- tr = setTextSelection(tr.selection.$from.start())(tr);
47
- return cloneTr(tr);
48
- }
49
- return tr;
50
- };
51
-
52
- // ($pos: ResolvedPos, doc: ProseMirrorNode, content: union<ProseMirrorNode, Fragment>, ) → boolean
53
- // Checks if replacing a node at a given `$pos` inside of the `doc` node with the given `content` is possible.
54
- export const canReplace = ($pos, content) => {
55
- const node = $pos.node($pos.depth);
56
- return (
57
- node &&
58
- node.type.validContent(
59
- content instanceof Fragment ? content : Fragment.from(content)
60
- )
61
- );
62
- };
63
-
64
- // (position: number) → (tr: Transaction) → Transaction
65
- // Returns a `delete` transaction that removes a node at a given position with the given `node`.
66
- // `position` should point at the position immediately before the node.
67
- export const removeNodeAtPos = position => tr => {
68
- const node = tr.doc.nodeAt(position);
69
- return cloneTr(tr.delete(position, position + node.nodeSize));
70
- };
71
-
72
- // :: ($pos: ResolvedPos, content: union<ProseMirrorNode, Fragment>) → boolean
73
- // Checks if a given `content` can be inserted at the given `$pos`
74
- //
75
- // ```javascript
76
- // const { selection: { $from } } = state;
77
- // const node = state.schema.nodes.atom.createChecked();
78
- // if (canInsert($from, node)) {
79
- // // ...
80
- // }
81
- // ```
82
- export const canInsert = ($pos, content) => {
83
- const index = $pos.index();
84
-
85
- if (content instanceof Fragment) {
86
- return $pos.parent.canReplace(index, index, content);
87
- } else if (content instanceof PMNode) {
88
- return $pos.parent.canReplaceWith(index, index, content.type);
89
- }
90
- return false;
91
- };
92
-
93
- // (node: ProseMirrorNode) → boolean
94
- // Checks if a given `node` is an empty paragraph
95
- export const isEmptyParagraph = node => {
96
- return !node || (node.type.name === 'paragraph' && node.nodeSize === 2);
97
- };
98
-
99
- export const checkInvalidMovements = (
100
- originIndex,
101
- targetIndex,
102
- targets,
103
- type
104
- ) => {
105
- const direction = originIndex > targetIndex ? -1 : 1;
106
- const errorMessage = `Target position is invalid, you can't move the ${type} ${originIndex} to ${targetIndex}, the target can't be split. You could use tryToFit option.`;
107
-
108
- if (direction === 1) {
109
- if (targets.slice(0, targets.length - 1).indexOf(targetIndex) !== -1) {
110
- throw new Error(errorMessage);
111
- }
112
- } else {
113
- if (targets.slice(1).indexOf(targetIndex) !== -1) {
114
- throw new Error(errorMessage);
115
- }
116
- }
117
-
118
- return true;
119
- };
@@ -1,17 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var selection_js = require('./selection.js');
6
- var node_js = require('./node.js');
7
- var transforms_js = require('./transforms.js');
8
- var helpers_js = require('./helpers.js');
9
-
10
-
11
-
12
- Object.keys(selection_js).forEach(function (key) { exports[key] = selection_js[key]; });
13
- Object.keys(node_js).forEach(function (key) { exports[key] = node_js[key]; });
14
- Object.keys(transforms_js).forEach(function (key) { exports[key] = transforms_js[key]; });
15
- exports.isNodeSelection = helpers_js.isNodeSelection;
16
- exports.canInsert = helpers_js.canInsert;
17
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}
@@ -1,106 +0,0 @@
1
- // :: (node: ProseMirrorNode, descend: ?boolean) → [{ node: ProseMirrorNode, pos: number }]
2
- // Flattens descendants of a given `node`. It doesn't descend into a node when descend argument is `false` (defaults to `true`).
3
- //
4
- // ```javascript
5
- // const children = flatten(node);
6
- // ```
7
- export const flatten = (node, descend = true) => {
8
- if (!node) {
9
- throw new Error('Invalid "node" parameter');
10
- }
11
- const result = [];
12
- node.descendants((child, pos) => {
13
- result.push({ node: child, pos });
14
- if (!descend) {
15
- return false;
16
- }
17
- });
18
- return result;
19
- };
20
-
21
- // :: (node: ProseMirrorNode, predicate: (node: ProseMirrorNode) → boolean, descend: ?boolean) → [{ node: ProseMirrorNode, pos: number }]
22
- // Iterates over descendants of a given `node`, returning child nodes predicate returns truthy for. It doesn't descend into a node when descend argument is `false` (defaults to `true`).
23
- //
24
- // ```javascript
25
- // const textNodes = findChildren(node, child => child.isText, false);
26
- // ```
27
- export const findChildren = (node, predicate, descend) => {
28
- if (!node) {
29
- throw new Error('Invalid "node" parameter');
30
- } else if (!predicate) {
31
- throw new Error('Invalid "predicate" parameter');
32
- }
33
- return flatten(node, descend).filter(child => predicate(child.node));
34
- };
35
-
36
- // :: (node: ProseMirrorNode, descend: ?boolean) → [{ node: ProseMirrorNode, pos: number }]
37
- // Returns text nodes of a given `node`. It doesn't descend into a node when descend argument is `false` (defaults to `true`).
38
- //
39
- // ```javascript
40
- // const textNodes = findTextNodes(node);
41
- // ```
42
- export const findTextNodes = (node, descend) => {
43
- return findChildren(node, child => child.isText, descend);
44
- };
45
-
46
- // :: (node: ProseMirrorNode, descend: ?boolean) → [{ node: ProseMirrorNode, pos: number }]
47
- // Returns inline nodes of a given `node`. It doesn't descend into a node when descend argument is `false` (defaults to `true`).
48
- //
49
- // ```javascript
50
- // const inlineNodes = findInlineNodes(node);
51
- // ```
52
- export const findInlineNodes = (node, descend) => {
53
- return findChildren(node, child => child.isInline, descend);
54
- };
55
-
56
- // :: (node: ProseMirrorNode, descend: ?boolean) → [{ node: ProseMirrorNode, pos: number }]
57
- // Returns block descendants of a given `node`. It doesn't descend into a node when descend argument is `false` (defaults to `true`).
58
- //
59
- // ```javascript
60
- // const blockNodes = findBlockNodes(node);
61
- // ```
62
- export const findBlockNodes = (node, descend) => {
63
- return findChildren(node, child => child.isBlock, descend);
64
- };
65
-
66
- // :: (node: ProseMirrorNode, predicate: (attrs: ?Object) → boolean, descend: ?boolean) → [{ node: ProseMirrorNode, pos: number }]
67
- // Iterates over descendants of a given `node`, returning child nodes predicate returns truthy for. It doesn't descend into a node when descend argument is `false` (defaults to `true`).
68
- //
69
- // ```javascript
70
- // const mergedCells = findChildrenByAttr(table, attrs => attrs.colspan === 2);
71
- // ```
72
- export const findChildrenByAttr = (node, predicate, descend) => {
73
- return findChildren(node, child => !!predicate(child.attrs), descend);
74
- };
75
-
76
- // :: (node: ProseMirrorNode, nodeType: NodeType, descend: ?boolean) → [{ node: ProseMirrorNode, pos: number }]
77
- // Iterates over descendants of a given `node`, returning child nodes of a given nodeType. It doesn't descend into a node when descend argument is `false` (defaults to `true`).
78
- //
79
- // ```javascript
80
- // const cells = findChildrenByType(table, schema.nodes.tableCell);
81
- // ```
82
- export const findChildrenByType = (node, nodeType, descend) => {
83
- return findChildren(node, child => child.type === nodeType, descend);
84
- };
85
-
86
- // :: (node: ProseMirrorNode, markType: markType, descend: ?boolean) → [{ node: ProseMirrorNode, pos: number }]
87
- // Iterates over descendants of a given `node`, returning child nodes that have a mark of a given markType. It doesn't descend into a `node` when descend argument is `false` (defaults to `true`).
88
- //
89
- // ```javascript
90
- // const nodes = findChildrenByMark(state.doc, schema.marks.strong);
91
- // ```
92
- export const findChildrenByMark = (node, markType, descend) => {
93
- return findChildren(node, child => markType.isInSet(child.marks), descend);
94
- };
95
-
96
- // :: (node: ProseMirrorNode, nodeType: NodeType) → boolean
97
- // Returns `true` if a given node contains nodes of a given `nodeType`
98
- //
99
- // ```javascript
100
- // if (contains(panel, schema.nodes.listItem)) {
101
- // // ...
102
- // }
103
- // ```
104
- export const contains = (node, nodeType) => {
105
- return !!findChildrenByType(node, nodeType).length;
106
- };
@@ -1,168 +0,0 @@
1
- import { Selection } from 'prosemirror-state';
2
- import { equalNodeType, isNodeSelection } from './helpers';
3
-
4
- // :: (predicate: (node: ProseMirrorNode) → boolean) → (selection: Selection) → ?{pos: number, start: number, depth: number, node: ProseMirrorNode}
5
- // Iterates over parent nodes, returning the closest node and its start position `predicate` returns truthy for. `start` points to the start position of the node, `pos` points directly before the node.
6
- //
7
- // ```javascript
8
- // const predicate = node => node.type === schema.nodes.blockquote;
9
- // const parent = findParentNode(predicate)(selection);
10
- // ```
11
- export const findParentNode = predicate => ({ $from }) =>
12
- findParentNodeClosestToPos($from, predicate);
13
-
14
- // :: ($pos: ResolvedPos, predicate: (node: ProseMirrorNode) → boolean) → ?{pos: number, start: number, depth: number, node: ProseMirrorNode}
15
- // Iterates over parent nodes starting from the given `$pos`, returning the closest node and its start position `predicate` returns truthy for. `start` points to the start position of the node, `pos` points directly before the node.
16
- //
17
- // ```javascript
18
- // const predicate = node => node.type === schema.nodes.blockquote;
19
- // const parent = findParentNodeClosestToPos(state.doc.resolve(5), predicate);
20
- // ```
21
- export const findParentNodeClosestToPos = ($pos, predicate) => {
22
- for (let i = $pos.depth; i > 0; i--) {
23
- const node = $pos.node(i);
24
- if (predicate(node)) {
25
- return {
26
- pos: i > 0 ? $pos.before(i) : 0,
27
- start: $pos.start(i),
28
- depth: i,
29
- node
30
- };
31
- }
32
- }
33
- };
34
-
35
- // :: (predicate: (node: ProseMirrorNode) → boolean, domAtPos: (pos: number) → {node: dom.Node, offset: number}) → (selection: Selection) → ?dom.Node
36
- // Iterates over parent nodes, returning DOM reference of the closest node `predicate` returns truthy for.
37
- //
38
- // ```javascript
39
- // const domAtPos = view.domAtPos.bind(view);
40
- // const predicate = node => node.type === schema.nodes.table;
41
- // const parent = findParentDomRef(predicate, domAtPos)(selection); // <table>
42
- // ```
43
- export const findParentDomRef = (predicate, domAtPos) => selection => {
44
- const parent = findParentNode(predicate)(selection);
45
- if (parent) {
46
- return findDomRefAtPos(parent.pos, domAtPos);
47
- }
48
- };
49
-
50
- // :: (predicate: (node: ProseMirrorNode) → boolean) → (selection: Selection) → boolean
51
- // Checks if there's a parent node `predicate` returns truthy for.
52
- //
53
- // ```javascript
54
- // if (hasParentNode(node => node.type === schema.nodes.table)(selection)) {
55
- // // ....
56
- // }
57
- // ```
58
- export const hasParentNode = predicate => selection => {
59
- return !!findParentNode(predicate)(selection);
60
- };
61
-
62
- // :: (nodeType: union<NodeType, [NodeType]>) → (selection: Selection) → ?{pos: number, start: number, depth: number, node: ProseMirrorNode}
63
- // Iterates over parent nodes, returning closest node of a given `nodeType`. `start` points to the start position of the node, `pos` points directly before the node.
64
- //
65
- // ```javascript
66
- // const parent = findParentNodeOfType(schema.nodes.paragraph)(selection);
67
- // ```
68
- export const findParentNodeOfType = nodeType => selection => {
69
- return findParentNode(node => equalNodeType(nodeType, node))(selection);
70
- };
71
-
72
- // :: ($pos: ResolvedPos, nodeType: union<NodeType, [NodeType]>) → ?{pos: number, start: number, depth: number, node: ProseMirrorNode}
73
- // Iterates over parent nodes starting from the given `$pos`, returning closest node of a given `nodeType`. `start` points to the start position of the node, `pos` points directly before the node.
74
- //
75
- // ```javascript
76
- // const parent = findParentNodeOfTypeClosestToPos(state.doc.resolve(10), schema.nodes.paragraph);
77
- // ```
78
- export const findParentNodeOfTypeClosestToPos = ($pos, nodeType) => {
79
- return findParentNodeClosestToPos($pos, node =>
80
- equalNodeType(nodeType, node)
81
- );
82
- };
83
-
84
- // :: (nodeType: union<NodeType, [NodeType]>) → (selection: Selection) → boolean
85
- // Checks if there's a parent node of a given `nodeType`.
86
- //
87
- // ```javascript
88
- // if (hasParentNodeOfType(schema.nodes.table)(selection)) {
89
- // // ....
90
- // }
91
- // ```
92
- export const hasParentNodeOfType = nodeType => selection => {
93
- return hasParentNode(node => equalNodeType(nodeType, node))(selection);
94
- };
95
-
96
- // :: (nodeType: union<NodeType, [NodeType]>, domAtPos: (pos: number) → {node: dom.Node, offset: number}) → (selection: Selection) → ?dom.Node
97
- // Iterates over parent nodes, returning DOM reference of the closest node of a given `nodeType`.
98
- //
99
- // ```javascript
100
- // const domAtPos = view.domAtPos.bind(view);
101
- // const parent = findParentDomRefOfType(schema.nodes.codeBlock, domAtPos)(selection); // <pre>
102
- // ```
103
- export const findParentDomRefOfType = (nodeType, domAtPos) => selection => {
104
- return findParentDomRef(node => equalNodeType(nodeType, node), domAtPos)(
105
- selection
106
- );
107
- };
108
-
109
- // :: (nodeType: union<NodeType, [NodeType]>) → (selection: Selection) → ?{pos: number, start: number, depth: number, node: ProseMirrorNode}
110
- // Returns a node of a given `nodeType` if it is selected. `start` points to the start position of the node, `pos` points directly before the node.
111
- //
112
- // ```javascript
113
- // const { extension, inlineExtension, bodiedExtension } = schema.nodes;
114
- // const selectedNode = findSelectedNodeOfType([
115
- // extension,
116
- // inlineExtension,
117
- // bodiedExtension,
118
- // ])(selection);
119
- // ```
120
- export const findSelectedNodeOfType = nodeType => selection => {
121
- if (isNodeSelection(selection)) {
122
- const { node, $from } = selection;
123
- if (equalNodeType(nodeType, node)) {
124
- return { node, pos: $from.pos, depth: $from.depth };
125
- }
126
- }
127
- };
128
-
129
- // :: (selection: Selection) → ?number
130
- // Returns position of the previous node.
131
- //
132
- // ```javascript
133
- // const pos = findPositionOfNodeBefore(tr.selection);
134
- // ```
135
- export const findPositionOfNodeBefore = selection => {
136
- const { nodeBefore } = selection.$from;
137
- const maybeSelection = Selection.findFrom(selection.$from, -1);
138
- if (maybeSelection && nodeBefore) {
139
- // leaf node
140
- const parent = findParentNodeOfType(nodeBefore.type)(maybeSelection);
141
- if (parent) {
142
- return parent.pos;
143
- }
144
- return maybeSelection.$from.pos;
145
- }
146
- };
147
-
148
- // :: (position: number, domAtPos: (pos: number) → {node: dom.Node, offset: number}) → dom.Node
149
- // Returns DOM reference of a node at a given `position`. If the node type is of type `TEXT_NODE` it will return the reference of the parent node.
150
- //
151
- // ```javascript
152
- // const domAtPos = view.domAtPos.bind(view);
153
- // const ref = findDomRefAtPos($from.pos, domAtPos);
154
- // ```
155
- export const findDomRefAtPos = (position, domAtPos) => {
156
- const dom = domAtPos(position);
157
- const node = dom.node.childNodes[dom.offset];
158
-
159
- if (dom.node.nodeType === Node.TEXT_NODE) {
160
- return dom.node.parentNode;
161
- }
162
-
163
- if (!node || node.nodeType === Node.TEXT_NODE) {
164
- return dom.node;
165
- }
166
-
167
- return node;
168
- };