@modusoperandi/licit 0.13.25 → 0.14.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/.eslintrc.js +1 -1
- package/README.md +1 -0
- package/dist/BlockquoteInsertNewLineCommand.js +3 -23
- package/dist/BlockquoteNodeSpec.js +3 -13
- package/dist/BlockquoteToggleCommand.js +3 -16
- package/dist/BookmarkNodeSpec.js +0 -6
- package/dist/BulletListNodeSpec.js +2 -16
- package/dist/CZIProseMirror.js +3 -27
- package/dist/CodeBlockCommand.js +3 -19
- package/dist/CodeBlockNodeSpec.js +3 -4
- package/dist/CodeMarkSpec.js +0 -4
- package/dist/ContentPlaceholderPlugin.js +6 -58
- package/dist/CursorPlaceholderPlugin.js +2 -32
- package/dist/DocLayoutCommand.js +5 -28
- package/dist/DocNodeSpec.js +0 -9
- package/dist/EMMarkSpec.js +0 -4
- package/dist/EditorCommands.js +5 -33
- package/dist/EditorKeyMap.js +4 -18
- package/dist/EditorMarks.js +2 -26
- package/dist/EditorNodes.js +4 -22
- package/dist/EditorPageLayoutPlugin.js +3 -15
- package/dist/EditorPlugins.js +0 -4
- package/dist/EditorSchema.js +0 -5
- package/dist/EditorState.js +0 -2
- package/dist/FontSizeMarkSpec.js +0 -12
- package/dist/FontTypeMarkSpec.js +15 -19
- package/dist/HTMLMutator.js +5 -24
- package/dist/HardBreakNodeSpec.js +0 -2
- package/dist/HeadingNodeSpec.js +6 -15
- package/dist/HistoryRedoCommand.js +3 -11
- package/dist/HistoryUndoCommand.js +3 -11
- package/dist/HorizontalRuleCommand.js +3 -22
- package/dist/HorizontalRuleNodeSpec.js +0 -10
- package/dist/ImageFromURLCommand.js +0 -9
- package/dist/ImageNodeSpec.js +2 -14
- package/dist/ImageSourceCommand.js +3 -39
- package/dist/ImageUploadCommand.js +3 -21
- package/dist/ImageUploadPlaceholderPlugin.js +10 -48
- package/dist/LinkMarkSpec.js +0 -4
- package/dist/LinkSetURLCommand.js +3 -28
- package/dist/LinkTooltipPlugin.js +6 -52
- package/dist/ListItemInsertNewLineCommand.js +3 -23
- package/dist/ListItemMergeCommand.js +15 -66
- package/dist/ListItemNodeSpec.js +0 -11
- package/dist/ListSplitCommand.js +3 -14
- package/dist/ListToggleCommand.js +5 -26
- package/dist/MarksClearCommand.js +6 -17
- package/dist/MathEditCommand.js +3 -38
- package/dist/MathNodeSpec.js +0 -10
- package/dist/OrderedListNodeSpec.js +0 -24
- package/dist/ParagraphNodeSpec.js +5 -26
- package/dist/ParagraphSpacingCommand.js +3 -32
- package/dist/PrintCommand.js +3 -13
- package/dist/SelectionPlaceholderPlugin.js +2 -31
- package/dist/SpacerMarkSpec.js +2 -6
- package/dist/StrikeMarkSpec.js +0 -4
- package/dist/StrongMarkSpec.js +2 -5
- package/dist/StyleView.js +1 -7
- package/dist/TableBackgroundColorCommand.js +3 -24
- package/dist/TableBorderColorCommand.js +3 -24
- package/dist/TableCellColorCommand.js +3 -23
- package/dist/TableCellMenuPlugin.js +9 -45
- package/dist/TableInsertCommand.js +7 -39
- package/dist/TableMergeCellsCommand.js +5 -30
- package/dist/TableNodesSpecs.js +4 -23
- package/dist/TablePlugins.js +0 -5
- package/dist/TableResizePlugin.js +54 -138
- package/dist/TextColorMarkSpec.js +0 -9
- package/dist/TextHighlightMarkSpec.js +0 -8
- package/dist/TextInsertTabSpaceCommand.js +3 -28
- package/dist/TextNoWrapMarkSpec.js +0 -4
- package/dist/TextSelectionMarkSpec.js +0 -5
- package/dist/TextSubMarkSpec.js +0 -4
- package/dist/TextSuperMarkSpec.js +0 -4
- package/dist/TextUnderlineMarkSpec.js +0 -4
- package/dist/Types.js +0 -6
- package/dist/WebFontLoader.js +3 -8
- package/dist/blockQuoteInputRule.js +0 -13
- package/dist/bom.xml +1492 -1645
- package/dist/buildEditorPlugins.js +5 -27
- package/dist/buildInputRules.js +12 -24
- package/dist/client/CollabConnector.js +6 -30
- package/dist/client/EditorConnection.js +23 -69
- package/dist/client/Licit.js +79 -163
- package/dist/client/Licit.js.flow +16 -2
- package/dist/client/Licit.test.js +6 -13
- package/dist/client/Reporter.js +1 -8
- package/dist/client/SimpleConnector.js +6 -26
- package/dist/client/http.js +8 -15
- package/dist/client/throttle.js +0 -2
- package/dist/convertFromDOMElement.js +2 -10
- package/dist/convertFromHTML.js +0 -5
- package/dist/convertFromJSON.js +3 -13
- package/dist/convertToCSSPTValue.js +0 -6
- package/dist/convertToJSON.js +0 -2
- package/dist/createCommand.js +3 -11
- package/dist/createEditorKeyMap.js +0 -13
- package/dist/createEmptyEditorState.js +0 -7
- package/dist/createTableResizingPlugin.js +5 -16
- package/dist/findActionableCell.js +0 -19
- package/dist/findActiveMark.js +0 -11
- package/dist/hyphenize.js +2 -4
- package/dist/index.js +0 -9
- package/dist/insertTable.js +0 -16
- package/dist/isEditorStateEmpty.js +0 -6
- package/dist/isTableNode.js +0 -3
- package/dist/joinDown.js +0 -7
- package/dist/joinListNode.js +0 -15
- package/dist/joinUp.js +0 -9
- package/dist/keymaps.js +0 -15
- package/dist/lookUpElement.js +0 -3
- package/dist/nodeAt.js +0 -3
- package/dist/normalizeHTML.js +9 -25
- package/dist/patchAnchorElements.js +5 -12
- package/dist/patchBreakElements.js +0 -6
- package/dist/patchElementInlineStyles.js +5 -15
- package/dist/patchListElements.js +20 -54
- package/dist/patchMathElements.js +11 -21
- package/dist/patchParagraphElements.js +0 -5
- package/dist/patchStyleElements.js +12 -41
- package/dist/patchTableElements.js +9 -37
- package/dist/rebaseDocWithSteps.js +0 -6
- package/dist/sanitizeURL.js +0 -3
- package/dist/splitListItem.js +12 -43
- package/dist/toClosestFontPtSize.js +1 -5
- package/dist/toSafeHTMLDocument.js +0 -1
- package/dist/toggleBlockquote.js +2 -19
- package/dist/toggleCodeBlock.js +2 -22
- package/dist/ui/AlertInfo.js +6 -22
- package/dist/ui/BookmarkNodeView.js +7 -28
- package/dist/ui/CommandButton.js +3 -19
- package/dist/ui/CommandMenu.js +3 -25
- package/dist/ui/CommandMenuButton.js +3 -36
- package/dist/ui/CustomEditorView.js +3 -16
- package/dist/ui/CustomMenu.js +0 -8
- package/dist/ui/CustomMenuItem.js +4 -18
- package/dist/ui/CustomNodeView.js +21 -67
- package/dist/ui/CustomRadioButton.js +14 -33
- package/dist/ui/DocLayoutEditor.js +5 -27
- package/dist/ui/Editor.js +18 -79
- package/dist/ui/EditorFrameset.js +3 -18
- package/dist/ui/EditorToolbar.js +10 -46
- package/dist/ui/EditorToolbarConfig.js +10 -20
- package/dist/ui/FontSizeCommandMenuButton.js +5 -19
- package/dist/ui/FontTypeCommandMenuButton.js +5 -22
- package/dist/ui/Frag.js +0 -7
- package/dist/ui/Icon.js +5 -25
- package/dist/ui/ImageAlignEditor.js +3 -16
- package/dist/ui/ImageInlineEditor.js +3 -16
- package/dist/ui/ImageNodeView.js +20 -109
- package/dist/ui/ImageResizeBox.js +3 -53
- package/dist/ui/ImageURLEditor.js +3 -28
- package/dist/ui/ImageUploadEditor.js +3 -35
- package/dist/ui/LinkTooltip.js +5 -25
- package/dist/ui/LinkURLEditor.js +3 -29
- package/dist/ui/ListItemNodeView.js +15 -30
- package/dist/ui/ListTypeButton.js +5 -37
- package/dist/ui/ListTypeCommandButton.js +3 -19
- package/dist/ui/ListTypeMenu.js +4 -25
- package/dist/ui/LoadingIndicator.js +0 -7
- package/dist/ui/MathEditor.js +3 -24
- package/dist/ui/MathInlineEditor.js +3 -26
- package/dist/ui/MathNodeView.js +9 -59
- package/dist/ui/PasteMenu.js +4 -20
- package/dist/ui/ResizeObserver.js +0 -18
- package/dist/ui/RichTextEditor.js +5 -27
- package/dist/ui/SelectionObserver.js +3 -29
- package/dist/ui/TableCellMenu.js +3 -18
- package/dist/ui/TableGridSizeEditor.js +5 -51
- package/dist/ui/TableNodeView.js +0 -11
- package/dist/ui/bindScrollHandler.js +2 -9
- package/dist/ui/canUseCSSFont.js +2 -8
- package/dist/ui/czi-icon.css +4 -4
- package/dist/ui/findActiveFontSize.js +2 -18
- package/dist/ui/findActiveFontType.js +0 -12
- package/dist/ui/handleEditorDrop.js +0 -9
- package/dist/ui/handleEditorKeyDown.js +0 -7
- package/dist/ui/handleEditorPaste.js +0 -9
- package/dist/ui/htmlElementToRect.js +0 -4
- package/dist/ui/injectStyleSheet.js +0 -10
- package/dist/ui/isElementFullyVisible.js +2 -8
- package/dist/ui/isOffline.js +0 -2
- package/dist/ui/isReactClass.js +0 -4
- package/dist/ui/mathquill-editor/MathQuillEditor.js +9 -44
- package/dist/ui/mathquill-editor/MathQuillEditorSymbols.js +1 -3
- package/dist/ui/mathquill-editor/MathQuillEditorSymbolsPanel.js +3 -16
- package/dist/ui/mathquill-editor/mathquill-import-kludge.js +5 -7
- package/dist/ui/renderLaTeXAsHTML.js +2 -13
- package/dist/ui/resolveImage.js +7 -32
- package/dist/ui/toCSSColor.js +0 -14
- package/dist/ui/toCSSLineSpacing.js +10 -11
- package/dist/ui/toHexColor.js +0 -8
- package/dist/ui/uuid.js +0 -2
- package/dist/uuid.js +0 -2
- package/package-lock.json.old +32889 -0
- package/package.json +45 -69
- package/src/client/Licit.js +16 -2
- package/src/ui/czi-icon.css +4 -4
- package/utils/build_web_server.js +1 -7
- package/webpack.config.js +3 -3
|
@@ -4,54 +4,45 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = patchElementInlineStyles;
|
|
7
|
-
|
|
8
7
|
var _hyphenize = _interopRequireDefault(require("./hyphenize"));
|
|
9
|
-
|
|
10
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
9
|
const BLOCK_TAG_SELECTOR = 'p,h1,h2,h3,h4,h5,h6,li'.replace(/\w+/g, m => `${m}[style]`);
|
|
13
|
-
|
|
14
10
|
function patchElementInlineStyles(doc) {
|
|
15
11
|
// Ensure that inline-styles can be correctly translated as inline marks.
|
|
16
12
|
// Workaround to patch inline styles added to block tags.
|
|
17
13
|
const bEls = Array.from(doc.querySelectorAll(BLOCK_TAG_SELECTOR));
|
|
18
14
|
bEls.forEach(patchBlockElement);
|
|
19
15
|
}
|
|
20
|
-
|
|
21
16
|
const NODE_TYPE_TEXT = 3;
|
|
22
17
|
const NODE_TYPE_ELEMENT = 1;
|
|
23
18
|
const INLINE_STYLE_NAMES = ['backgroundColor', 'color', 'fontFamily', 'fontSize', 'fontStyle', 'fontWeight', 'textDecoration', 'textIndent'];
|
|
24
19
|
const INLINE_ELEMENT_NODE_NAMES = new Set(['A', 'B', 'EM', 'I', 'SPAN', 'STRONG', 'U']);
|
|
25
|
-
|
|
26
20
|
function patchBlockElement(el) {
|
|
27
21
|
INLINE_STYLE_NAMES.forEach(name => patchBlockElementStyle(el, name));
|
|
28
|
-
}
|
|
29
|
-
// assumes that its child nodes are inline elements.
|
|
30
|
-
|
|
22
|
+
}
|
|
31
23
|
|
|
24
|
+
// Move the specified inline style of the element to its child nodes. This
|
|
25
|
+
// assumes that its child nodes are inline elements.
|
|
32
26
|
function patchBlockElementStyle(el, inlineStyleName) {
|
|
33
27
|
const element = el;
|
|
34
28
|
const elementStyle = element.style;
|
|
35
29
|
const value = elementStyle && elementStyle[inlineStyleName];
|
|
36
|
-
|
|
37
30
|
if (inlineStyleName === 'textIndent' && value) {
|
|
38
31
|
// This is the workaround to fix the issue that people with mix both
|
|
39
32
|
// text-indent and margin-left together.
|
|
40
33
|
// For instance, `margin-left: -100px` and `text-indent: 100px` shall
|
|
41
34
|
// offset each other.
|
|
42
35
|
const marginLeft = elementStyle.marginLeft || '';
|
|
43
|
-
|
|
44
36
|
if (value === '-' + marginLeft || marginLeft === '-' + value) {
|
|
45
37
|
elementStyle.marginLeft = '';
|
|
46
38
|
elementStyle.textIndent = '';
|
|
47
39
|
}
|
|
48
40
|
}
|
|
49
|
-
|
|
50
41
|
if (!value) {
|
|
51
42
|
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
43
|
+
}
|
|
54
44
|
|
|
45
|
+
// Remove the style.
|
|
55
46
|
elementStyle[inlineStyleName] = '';
|
|
56
47
|
const childNodes = Array.from(element.childNodes);
|
|
57
48
|
childNodes.forEach(node => {
|
|
@@ -62,7 +53,6 @@ function patchBlockElementStyle(el, inlineStyleName) {
|
|
|
62
53
|
ownerDocument,
|
|
63
54
|
parentElement
|
|
64
55
|
} = node;
|
|
65
|
-
|
|
66
56
|
if (nodeType === NODE_TYPE_ELEMENT) {
|
|
67
57
|
if (INLINE_ELEMENT_NODE_NAMES.has(nodeName)) {
|
|
68
58
|
const cssText = `${(0, _hyphenize.default)(inlineStyleName)}: ${value};` + style.cssText;
|
|
@@ -4,23 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = patchListElements;
|
|
7
|
-
|
|
8
7
|
var _HTMLMutator = _interopRequireDefault(require("./HTMLMutator"));
|
|
9
|
-
|
|
10
8
|
var _nullthrows = _interopRequireDefault(require("nullthrows"));
|
|
11
|
-
|
|
12
9
|
var _uuid = _interopRequireDefault(require("./ui/uuid"));
|
|
13
|
-
|
|
14
10
|
var _ListItemNodeSpec = require("./ListItemNodeSpec");
|
|
15
|
-
|
|
16
11
|
var _ParagraphNodeSpec = require("./ParagraphNodeSpec");
|
|
17
|
-
|
|
18
12
|
var _OrderedListNodeSpec = require("./OrderedListNodeSpec");
|
|
19
|
-
|
|
20
13
|
var _patchStyleElements = require("./patchStyleElements");
|
|
21
|
-
|
|
22
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
-
|
|
24
15
|
function patchListElements(doc) {
|
|
25
16
|
// In Google Doc, lists are exported as indented
|
|
26
17
|
// (e.g. style="margin-left: 48pt") list elements which is the default DOM
|
|
@@ -31,16 +22,15 @@ function patchListElements(doc) {
|
|
|
31
22
|
// into indented list elements.
|
|
32
23
|
liftNestedListElements(doc);
|
|
33
24
|
Array.from(doc.querySelectorAll('ol, ul')).forEach(patchListElementsElement);
|
|
34
|
-
}
|
|
35
|
-
|
|
25
|
+
}
|
|
36
26
|
|
|
27
|
+
// This assumes that every 36pt maps to one indent level.
|
|
37
28
|
const CHAR_BULLET = '\u25cf';
|
|
38
29
|
const CHAR_CIRCLE = '\u25cb';
|
|
39
30
|
const CHAR_SQUARE = '\u25a0';
|
|
40
31
|
const CHAR_BOX = '\u274f';
|
|
41
32
|
const CHAR_ZERO_SPACE = '\u200B';
|
|
42
33
|
const INLINE_NODE_NAME_PATTERN = /^(#text)|(A|SPAN|B|STRONG)$/;
|
|
43
|
-
|
|
44
34
|
function patchListElementsElement(listElement) {
|
|
45
35
|
// If the children of `listElement` all have teh same marginLeft, assume
|
|
46
36
|
// it to be indented.
|
|
@@ -49,103 +39,84 @@ function patchListElementsElement(listElement) {
|
|
|
49
39
|
const {
|
|
50
40
|
parentElement,
|
|
51
41
|
children
|
|
52
|
-
} = listElement;
|
|
42
|
+
} = listElement;
|
|
43
|
+
|
|
44
|
+
// A workaround to patch the issue when <ul /> or <ol /> is pasted as the
|
|
53
45
|
// first child of <body />, its first <li /> somehow can't be wrapped
|
|
54
46
|
// with the list. The hack is to prepend zero-width-space character
|
|
55
47
|
// before the list.
|
|
56
|
-
|
|
57
48
|
if (parentElement && parentElement.nodeName === 'BODY' && parentElement.firstChild === listElement) {
|
|
58
49
|
const tt = parentElement.ownerDocument.createTextNode(CHAR_ZERO_SPACE);
|
|
59
50
|
parentElement.insertBefore(tt, listElement);
|
|
60
51
|
}
|
|
61
|
-
|
|
62
52
|
Array.from(children).forEach(listItemElement => {
|
|
63
53
|
const {
|
|
64
54
|
style
|
|
65
55
|
} = listItemElement;
|
|
66
56
|
patchPaddingStyle(listItemElement);
|
|
67
57
|
const bc = listItemElement.getAttribute(_patchStyleElements.ATTRIBUTE_CSS_BEFORE_CONTENT) || '';
|
|
68
|
-
|
|
69
58
|
if (beforeContent === undefined) {
|
|
70
59
|
beforeContent = bc;
|
|
71
60
|
}
|
|
72
|
-
|
|
73
61
|
if (beforeContent !== bc) {
|
|
74
62
|
beforeContent = null;
|
|
75
63
|
}
|
|
76
|
-
|
|
77
64
|
const ml = style && style.marginLeft || '';
|
|
78
|
-
|
|
79
65
|
if (marginLeft === undefined) {
|
|
80
66
|
marginLeft = ml;
|
|
81
67
|
}
|
|
82
|
-
|
|
83
68
|
if (ml !== marginLeft) {
|
|
84
69
|
marginLeft = null;
|
|
85
70
|
}
|
|
86
71
|
});
|
|
87
|
-
|
|
88
72
|
if (marginLeft) {
|
|
89
73
|
const indent = (0, _ParagraphNodeSpec.convertMarginLeftToIndentValue)(marginLeft);
|
|
90
|
-
|
|
91
74
|
if (indent) {
|
|
92
75
|
listElement.setAttribute(_ParagraphNodeSpec.ATTRIBUTE_INDENT, String(indent));
|
|
93
76
|
}
|
|
94
77
|
}
|
|
95
|
-
|
|
96
78
|
if (beforeContent) {
|
|
97
79
|
beforeContent = String(beforeContent);
|
|
98
80
|
let listStyleType;
|
|
99
|
-
|
|
100
81
|
switch (true) {
|
|
101
82
|
case beforeContent.indexOf(CHAR_BULLET) > -1:
|
|
102
83
|
listStyleType = 'disc';
|
|
103
84
|
break;
|
|
104
|
-
|
|
105
85
|
case beforeContent.indexOf(CHAR_CIRCLE) > -1:
|
|
106
86
|
listStyleType = 'circle';
|
|
107
87
|
break;
|
|
108
|
-
|
|
109
88
|
case beforeContent.indexOf(CHAR_SQUARE) > -1:
|
|
110
89
|
listStyleType = 'square';
|
|
111
90
|
break;
|
|
112
|
-
|
|
113
91
|
case beforeContent.indexOf(CHAR_BOX) > -1:
|
|
114
92
|
listStyleType = 'box';
|
|
115
93
|
break;
|
|
116
|
-
|
|
117
94
|
case beforeContent.indexOf('lower-latin') > -1:
|
|
118
95
|
listStyleType = 'lower-latin';
|
|
119
96
|
break;
|
|
120
|
-
|
|
121
97
|
case beforeContent.indexOf('upper-latin') > -1:
|
|
122
98
|
listStyleType = 'upper-latin';
|
|
123
99
|
break;
|
|
124
|
-
|
|
125
100
|
case beforeContent.indexOf('lower-roman') > -1:
|
|
126
101
|
listStyleType = 'lower-roman';
|
|
127
102
|
break;
|
|
128
|
-
|
|
129
103
|
case beforeContent.indexOf('upper-roman') > -1:
|
|
130
104
|
listStyleType = 'upper-roman';
|
|
131
105
|
break;
|
|
132
|
-
|
|
133
106
|
case beforeContent.indexOf('-') > -1:
|
|
134
107
|
listStyleType = 'dash';
|
|
135
108
|
break;
|
|
136
|
-
|
|
137
109
|
default:
|
|
138
110
|
console.log('unknown list style type', beforeContent);
|
|
139
111
|
break;
|
|
140
112
|
}
|
|
141
|
-
|
|
142
113
|
if (listStyleType) {
|
|
143
114
|
listElement.setAttribute(_ListItemNodeSpec.ATTRIBUTE_LIST_STYLE_TYPE, listStyleType);
|
|
144
115
|
}
|
|
145
116
|
}
|
|
146
|
-
}
|
|
147
|
-
|
|
117
|
+
}
|
|
148
118
|
|
|
119
|
+
// This moves the styles of <li /> into its content <p />.
|
|
149
120
|
function patchPaddingStyle(listItemElement) {
|
|
150
121
|
const {
|
|
151
122
|
style,
|
|
@@ -156,11 +127,9 @@ function patchPaddingStyle(listItemElement) {
|
|
|
156
127
|
paddingBottom,
|
|
157
128
|
lineHeight
|
|
158
129
|
} = style;
|
|
159
|
-
|
|
160
130
|
if (!_ParagraphNodeSpec.EMPTY_CSS_VALUE.has(paddingBottom) && !_ParagraphNodeSpec.EMPTY_CSS_VALUE.has(paddingTop) && !_ParagraphNodeSpec.EMPTY_CSS_VALUE.has(lineHeight)) {
|
|
161
131
|
return;
|
|
162
132
|
}
|
|
163
|
-
|
|
164
133
|
const doc = listItemElement.ownerDocument;
|
|
165
134
|
const frag = doc.createDocumentFragment();
|
|
166
135
|
let contentIsInline = true;
|
|
@@ -168,7 +137,6 @@ function patchPaddingStyle(listItemElement) {
|
|
|
168
137
|
contentIsInline = contentIsInline && INLINE_NODE_NAME_PATTERN.test(cn.nodeName);
|
|
169
138
|
frag.appendChild(cn);
|
|
170
139
|
});
|
|
171
|
-
|
|
172
140
|
if (contentIsInline) {
|
|
173
141
|
// Wrap all inline content with <p /> with the padding style applied.
|
|
174
142
|
const pEl = doc.createElement('p');
|
|
@@ -183,7 +151,9 @@ function patchPaddingStyle(listItemElement) {
|
|
|
183
151
|
// Unable to patch the style.
|
|
184
152
|
listItemElement.appendChild(frag);
|
|
185
153
|
}
|
|
186
|
-
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// This converts all nested list elements into indented list elements.
|
|
187
157
|
// For instance,
|
|
188
158
|
// == UI ==
|
|
189
159
|
// 1. AA
|
|
@@ -212,8 +182,6 @@ function patchPaddingStyle(listItemElement) {
|
|
|
212
182
|
// <ol data-following="x" data-counter-reset-"none">
|
|
213
183
|
// <li>AA</li>
|
|
214
184
|
// </ol>
|
|
215
|
-
|
|
216
|
-
|
|
217
185
|
function liftNestedListElements(doc) {
|
|
218
186
|
const selector = 'li > ol, li > ul';
|
|
219
187
|
const els = Array.from(doc.querySelectorAll(selector));
|
|
@@ -225,11 +193,15 @@ function liftNestedListElements(doc) {
|
|
|
225
193
|
const parentList = (0, _nullthrows.default)(parentListItem.parentElement);
|
|
226
194
|
const parentListNodeName = parentList.nodeName.toLowerCase();
|
|
227
195
|
const isLast = parentList.lastElementChild === parentListItem;
|
|
228
|
-
const style = parentList.getAttribute('style') || '';
|
|
229
|
-
// follow the first list.
|
|
196
|
+
const style = parentList.getAttribute('style') || '';
|
|
230
197
|
|
|
198
|
+
// The parent list will be split into two lists and the second list should
|
|
199
|
+
// follow the first list.
|
|
231
200
|
const followingName = parentList.getAttribute('name') || (0, _uuid.default)();
|
|
232
|
-
parentList.setAttribute('name', followingName);
|
|
201
|
+
parentList.setAttribute('name', followingName);
|
|
202
|
+
|
|
203
|
+
// Stub HTML snippets that will lift the list.
|
|
204
|
+
|
|
233
205
|
// Before:
|
|
234
206
|
// <ol>
|
|
235
207
|
// <li>
|
|
@@ -242,16 +214,15 @@ function liftNestedListElements(doc) {
|
|
|
242
214
|
// <ol><li>AAA</li></ol>
|
|
243
215
|
// <ol><li>BBB</li></ol>
|
|
244
216
|
// <ol><li>CCC</li></ol>
|
|
245
|
-
// Close the parent list before the list.
|
|
246
|
-
|
|
247
|
-
htmlMutator.insertHTMLBefore(`<\/${parentListNodeName}>`, list); // Open a new list after list.
|
|
248
217
|
|
|
218
|
+
// Close the parent list before the list.
|
|
219
|
+
htmlMutator.insertHTMLBefore(`<\/${parentListNodeName}>`, list);
|
|
220
|
+
// Open a new list after list.
|
|
249
221
|
htmlMutator.insertHTMLAfter(`<${parentListNodeName}
|
|
250
222
|
style="${style}"
|
|
251
223
|
class="${parentList.className}"
|
|
252
224
|
${_OrderedListNodeSpec.ATTRIBUTE_COUNTER_RESET}="none"
|
|
253
225
|
${_OrderedListNodeSpec.ATTRIBUTE_FOLLOWING}="${followingName}">`, list);
|
|
254
|
-
|
|
255
226
|
if (isLast) {
|
|
256
227
|
// The new list after list is an empty list, comment it out.
|
|
257
228
|
htmlMutator.insertHTMLAfter('<!--', list).insertHTMLAfter('-->', parentList);
|
|
@@ -259,24 +230,19 @@ function liftNestedListElements(doc) {
|
|
|
259
230
|
});
|
|
260
231
|
htmlMutator.execute();
|
|
261
232
|
}
|
|
262
|
-
|
|
263
233
|
function findIndentLevel(el) {
|
|
264
234
|
let indent = 0;
|
|
265
235
|
let currentEl = el.parentElement;
|
|
266
|
-
|
|
267
236
|
while (currentEl) {
|
|
268
237
|
const {
|
|
269
238
|
nodeName
|
|
270
239
|
} = currentEl;
|
|
271
|
-
|
|
272
240
|
if (nodeName === 'OL' || nodeName === 'UL') {
|
|
273
241
|
indent++;
|
|
274
242
|
} else if (nodeName !== 'LI') {
|
|
275
243
|
break;
|
|
276
244
|
}
|
|
277
|
-
|
|
278
245
|
currentEl = currentEl.parentElement;
|
|
279
246
|
}
|
|
280
|
-
|
|
281
247
|
return indent;
|
|
282
248
|
}
|
|
@@ -4,20 +4,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = patchMathElements;
|
|
7
|
-
|
|
8
7
|
var _queryString = _interopRequireDefault(require("query-string"));
|
|
9
|
-
|
|
10
8
|
var _url = _interopRequireDefault(require("url"));
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
10
|
function patchMathElements(doc) {
|
|
15
11
|
Array.from(doc.querySelectorAll('img')).forEach(patchGoogleEquationElement);
|
|
16
|
-
}
|
|
17
|
-
|
|
12
|
+
}
|
|
18
13
|
|
|
14
|
+
// See https://developers.google.com/chart/image/docs/chart_params#gcharts_cht
|
|
19
15
|
const PARAM_CHART_CHART_TYPE = 'cht';
|
|
20
|
-
const PARAM_CHART_LABEL = 'chl';
|
|
16
|
+
const PARAM_CHART_LABEL = 'chl';
|
|
17
|
+
|
|
18
|
+
// Google Doc exports math equation content as single image element that loads
|
|
21
19
|
// its content from google. For example:
|
|
22
20
|
// <img src="https://www.google.com/chart?cht=tx&c...p;chl=m%E2%88%A0C" />
|
|
23
21
|
// Unfortunately, such image often fails to load because its url contains the
|
|
@@ -30,50 +28,42 @@ function patchGoogleEquationElement(el) {
|
|
|
30
28
|
ownerDocument,
|
|
31
29
|
parentElement
|
|
32
30
|
} = el;
|
|
33
|
-
|
|
34
31
|
if (!ownerDocument || !parentElement) {
|
|
35
32
|
return;
|
|
36
33
|
}
|
|
37
|
-
|
|
38
34
|
const src = el.getAttribute('src');
|
|
39
35
|
const content = getGoogleEquationContent(src);
|
|
40
|
-
|
|
41
36
|
if (!content) {
|
|
42
37
|
return;
|
|
43
|
-
}
|
|
44
|
-
// Note that this requires the schema to support `MathNodeSpec`.
|
|
45
|
-
|
|
38
|
+
}
|
|
46
39
|
|
|
40
|
+
// Replace `<img src="..." />` with `<math data-latex="..." />`.
|
|
41
|
+
// Note that this requires the schema to support `MathNodeSpec`.
|
|
47
42
|
const math = ownerDocument.createElement('math');
|
|
48
43
|
math.setAttribute('data-latex', content);
|
|
49
44
|
parentElement.insertBefore(math, el);
|
|
50
45
|
parentElement.removeChild(el);
|
|
51
46
|
}
|
|
52
|
-
|
|
53
47
|
function getGoogleEquationContent(src) {
|
|
54
48
|
if (!src) {
|
|
55
49
|
return null;
|
|
56
50
|
}
|
|
57
|
-
|
|
58
51
|
const {
|
|
59
52
|
host,
|
|
60
53
|
pathname,
|
|
61
54
|
query
|
|
62
55
|
} = _url.default.parse(src);
|
|
63
|
-
|
|
64
56
|
if (host !== 'www.google.com' || pathname !== '/chart') {
|
|
65
57
|
return null;
|
|
66
58
|
}
|
|
67
|
-
|
|
68
59
|
const params = _queryString.default.parse(query);
|
|
69
|
-
|
|
70
60
|
const chartType = params[PARAM_CHART_CHART_TYPE];
|
|
71
|
-
const label = params[PARAM_CHART_LABEL];
|
|
72
|
-
// contents.
|
|
61
|
+
const label = params[PARAM_CHART_LABEL];
|
|
73
62
|
|
|
63
|
+
// Google exports math equation as a special chart with plan text only
|
|
64
|
+
// contents.
|
|
74
65
|
if (chartType !== 'tx' || !label) {
|
|
75
66
|
return null;
|
|
76
67
|
}
|
|
77
|
-
|
|
78
68
|
return label;
|
|
79
69
|
}
|
|
@@ -4,21 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = patchParagraphElements;
|
|
7
|
-
|
|
8
7
|
var _ParagraphNodeSpec = require("./ParagraphNodeSpec");
|
|
9
|
-
|
|
10
8
|
function patchParagraphElements(doc) {
|
|
11
9
|
Array.from(doc.querySelectorAll('p')).forEach(patchParagraphElement);
|
|
12
10
|
}
|
|
13
|
-
|
|
14
11
|
function patchParagraphElement(pElement) {
|
|
15
12
|
const {
|
|
16
13
|
marginLeft
|
|
17
14
|
} = pElement.style;
|
|
18
|
-
|
|
19
15
|
if (marginLeft) {
|
|
20
16
|
const indent = (0, _ParagraphNodeSpec.convertMarginLeftToIndentValue)(marginLeft);
|
|
21
|
-
|
|
22
17
|
if (indent) {
|
|
23
18
|
pElement.setAttribute(_ParagraphNodeSpec.ATTRIBUTE_INDENT, String(indent));
|
|
24
19
|
}
|
|
@@ -5,88 +5,72 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.ATTRIBUTE_CSS_BEFORE_CONTENT = void 0;
|
|
7
7
|
exports.default = patchStyleElements;
|
|
8
|
-
|
|
9
8
|
var _toCSSColor = _interopRequireDefault(require("./ui/toCSSColor"));
|
|
10
|
-
|
|
11
9
|
var _licitUiCommands = require("@modusoperandi/licit-ui-commands");
|
|
12
|
-
|
|
13
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
11
|
const LIST_ITEM_PSEUDO_ELEMENT_BEFORE = /li:+before/;
|
|
16
12
|
const NODE_NAME_SELECTOR = /^[a-zA-Z]+\d*$/;
|
|
17
|
-
const PSEUDO_ELEMENT_ANY = /:+[a-z]+/;
|
|
13
|
+
const PSEUDO_ELEMENT_ANY = /:+[a-z]+/;
|
|
18
14
|
|
|
15
|
+
// Assume these className from Google doc has less specificity.
|
|
19
16
|
const WEAK_CLASS_SELECTOR = /\.title/;
|
|
20
|
-
const ATTRIBUTE_CSS_BEFORE_CONTENT = 'data-attribute-css-before-content';
|
|
21
|
-
// separately
|
|
17
|
+
const ATTRIBUTE_CSS_BEFORE_CONTENT = 'data-attribute-css-before-content';
|
|
22
18
|
|
|
19
|
+
// Node name only selector has less priority, we'll handle it
|
|
20
|
+
// separately
|
|
23
21
|
exports.ATTRIBUTE_CSS_BEFORE_CONTENT = ATTRIBUTE_CSS_BEFORE_CONTENT;
|
|
24
|
-
|
|
25
22
|
function patchStyleElements(doc) {
|
|
26
23
|
const els = Array.from(doc.querySelectorAll('style'));
|
|
27
|
-
|
|
28
24
|
if (!els.length) {
|
|
29
25
|
return;
|
|
30
26
|
}
|
|
31
|
-
|
|
32
27
|
const selectorTextToCSSTexts = [];
|
|
33
28
|
els.forEach(styleEl => {
|
|
34
29
|
const sheet = styleEl.sheet;
|
|
35
|
-
|
|
36
30
|
if (!sheet) {
|
|
37
31
|
// TODO: Find out why the browser does not support this.
|
|
38
32
|
console.error('styleEl.sheet undefined', styleEl);
|
|
39
33
|
return;
|
|
40
34
|
}
|
|
41
|
-
|
|
42
35
|
const cssRules = sheet.cssRules;
|
|
43
|
-
|
|
44
36
|
if (!cssRules) {
|
|
45
37
|
// TODO: Find out why the browser does not support this.
|
|
46
38
|
console.error('sheet.cssRules undefined', sheet);
|
|
47
39
|
return;
|
|
48
40
|
}
|
|
49
|
-
|
|
50
41
|
Array.from(cssRules).forEach((rule, cssRuleIndex) => {
|
|
51
42
|
const selectorText = String(rule.selectorText || '');
|
|
52
|
-
|
|
53
43
|
if (!selectorText) {
|
|
54
44
|
// This could be `CSSImportRule.` created by @import().
|
|
55
45
|
// ignore it.
|
|
56
46
|
return;
|
|
57
47
|
}
|
|
58
|
-
|
|
59
48
|
if (!rule.styleMap) {
|
|
60
49
|
// TODO: Find out why the browser does not support this.
|
|
61
50
|
console.error('rule.styleMap undefined', rule);
|
|
62
51
|
return;
|
|
63
52
|
}
|
|
64
|
-
|
|
65
53
|
let cssText = '';
|
|
66
54
|
rule.styleMap.forEach((cssStyleValue, key) => {
|
|
67
|
-
let cssStyleValueStr = String(cssStyleValue);
|
|
68
|
-
|
|
55
|
+
let cssStyleValueStr = String(cssStyleValue);
|
|
56
|
+
// e.g. rules['color'] = 'red'.
|
|
69
57
|
if (key === 'color') {
|
|
70
58
|
const color = (0, _toCSSColor.default)(cssStyleValueStr);
|
|
71
|
-
|
|
72
59
|
if (!color) {
|
|
73
60
|
return;
|
|
74
61
|
}
|
|
75
62
|
} else if (key === 'background-color') {
|
|
76
63
|
const color = (0, _toCSSColor.default)(cssStyleValueStr);
|
|
77
|
-
|
|
78
64
|
if (!color) {
|
|
79
65
|
return;
|
|
80
66
|
}
|
|
81
67
|
} else if (key === 'line-height') {
|
|
82
68
|
cssStyleValueStr = (0, _licitUiCommands.toCSSLineSpacing)(cssStyleValueStr);
|
|
83
69
|
}
|
|
84
|
-
|
|
85
70
|
if (cssStyleValueStr) {
|
|
86
71
|
cssText += `${key}: ${cssStyleValueStr};`;
|
|
87
72
|
}
|
|
88
73
|
});
|
|
89
|
-
|
|
90
74
|
if (selectorText.indexOf(',') > -1) {
|
|
91
75
|
selectorText.split(/\s*,\s*/).forEach(st => {
|
|
92
76
|
buildSelectorTextToCSSText(selectorTextToCSSTexts, st, cssText);
|
|
@@ -95,11 +79,11 @@ function patchStyleElements(doc) {
|
|
|
95
79
|
buildSelectorTextToCSSText(selectorTextToCSSTexts, selectorText, cssText);
|
|
96
80
|
}
|
|
97
81
|
});
|
|
98
|
-
});
|
|
82
|
+
});
|
|
99
83
|
|
|
84
|
+
// Sort selector by
|
|
100
85
|
selectorTextToCSSTexts.sort(sortBySpecificity).reduce(buildElementToCSSTexts.bind(null, doc), new Map()).forEach(applyInlineStyleSheetCSSTexts);
|
|
101
86
|
}
|
|
102
|
-
|
|
103
87
|
function buildElementToCSSTexts(doc, elementToCSSTexts, bag) {
|
|
104
88
|
const {
|
|
105
89
|
selectorText,
|
|
@@ -109,17 +93,14 @@ function buildElementToCSSTexts(doc, elementToCSSTexts, bag) {
|
|
|
109
93
|
const els = Array.from(doc.querySelectorAll(selectorText));
|
|
110
94
|
els.forEach(el => {
|
|
111
95
|
const style = el.style;
|
|
112
|
-
|
|
113
96
|
if (!style || !(el instanceof HTMLElement)) {
|
|
114
97
|
return;
|
|
115
98
|
}
|
|
116
|
-
|
|
117
99
|
if (cssText) {
|
|
118
100
|
const cssTexts = elementToCSSTexts.get(el) || [];
|
|
119
101
|
cssTexts.push(cssText);
|
|
120
102
|
elementToCSSTexts.set(el, cssTexts);
|
|
121
103
|
}
|
|
122
|
-
|
|
123
104
|
if (beforeContent) {
|
|
124
105
|
// This simply adds the custom attribute 'data-before-content' to element,
|
|
125
106
|
// developer must handle his attribute via NodeSpec separately if needed.
|
|
@@ -128,42 +109,34 @@ function buildElementToCSSTexts(doc, elementToCSSTexts, bag) {
|
|
|
128
109
|
});
|
|
129
110
|
return elementToCSSTexts;
|
|
130
111
|
}
|
|
131
|
-
|
|
132
112
|
function sortBySpecificity(one, two) {
|
|
133
113
|
// This is just the naive implementation of sorting selectors by css
|
|
134
114
|
// specificity.
|
|
135
115
|
// 1. NodeName selectors has less priority.
|
|
136
116
|
let aa = NODE_NAME_SELECTOR.test(one.selectorText);
|
|
137
117
|
let bb = NODE_NAME_SELECTOR.test(two.selectorText);
|
|
138
|
-
|
|
139
118
|
if (aa && !bb) {
|
|
140
119
|
return -1;
|
|
141
120
|
}
|
|
142
|
-
|
|
143
121
|
if (!aa && bb) {
|
|
144
122
|
return 1;
|
|
145
|
-
}
|
|
146
|
-
// Assume these className from Google doc has less specificity.
|
|
147
|
-
|
|
123
|
+
}
|
|
148
124
|
|
|
125
|
+
// Assume both are className selector.
|
|
126
|
+
// Assume these className from Google doc has less specificity.
|
|
149
127
|
aa = WEAK_CLASS_SELECTOR.test(one.selectorText);
|
|
150
128
|
bb = WEAK_CLASS_SELECTOR.test(two.selectorText);
|
|
151
|
-
|
|
152
129
|
if (aa && !bb) {
|
|
153
130
|
return -1;
|
|
154
131
|
}
|
|
155
|
-
|
|
156
132
|
if (!aa && bb) {
|
|
157
133
|
return 1;
|
|
158
134
|
}
|
|
159
|
-
|
|
160
135
|
return 0;
|
|
161
136
|
}
|
|
162
|
-
|
|
163
137
|
function buildSelectorTextToCSSText(result, selectorText, cssText) {
|
|
164
138
|
let afterContent;
|
|
165
139
|
let beforeContent;
|
|
166
|
-
|
|
167
140
|
if (LIST_ITEM_PSEUDO_ELEMENT_BEFORE.test(selectorText)) {
|
|
168
141
|
// Workaround to extract the list style content from HTML generated by
|
|
169
142
|
// Google.
|
|
@@ -175,7 +148,6 @@ function buildSelectorTextToCSSText(result, selectorText, cssText) {
|
|
|
175
148
|
// TODO: Handle this later.
|
|
176
149
|
return;
|
|
177
150
|
}
|
|
178
|
-
|
|
179
151
|
result.push({
|
|
180
152
|
selectorText,
|
|
181
153
|
cssText,
|
|
@@ -183,7 +155,6 @@ function buildSelectorTextToCSSText(result, selectorText, cssText) {
|
|
|
183
155
|
beforeContent
|
|
184
156
|
});
|
|
185
157
|
}
|
|
186
|
-
|
|
187
158
|
function applyInlineStyleSheetCSSTexts(cssTexts, el) {
|
|
188
159
|
if (cssTexts.length) {
|
|
189
160
|
el.style.cssText = cssTexts.join(';') + ';' + el.style.cssText;
|