@pie-lib/editable-html-tip-tap 1.0.2 → 1.0.4

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 (165) hide show
  1. package/lib/components/CharacterPicker.js +221 -0
  2. package/lib/components/CharacterPicker.js.map +1 -0
  3. package/lib/components/EditableHtml.js +323 -0
  4. package/lib/components/EditableHtml.js.map +1 -0
  5. package/lib/components/MenuBar.js +694 -0
  6. package/lib/components/MenuBar.js.map +1 -0
  7. package/lib/components/TiptapContainer.js +90 -0
  8. package/lib/components/TiptapContainer.js.map +1 -0
  9. package/lib/components/buttons/done-button.js +53 -0
  10. package/lib/components/characters/characterUtils.js +112 -0
  11. package/lib/components/characters/characterUtils.js.map +1 -0
  12. package/lib/components/characters/custom-popper.js +73 -0
  13. package/lib/components/characters/custom-popper.js.map +1 -0
  14. package/lib/components/common/done-button.js +53 -0
  15. package/lib/components/common/done-button.js.map +1 -0
  16. package/lib/components/common/toolbar-buttons.js +194 -0
  17. package/lib/components/icons/CssIcon.js +37 -0
  18. package/lib/components/icons/CssIcon.js.map +1 -0
  19. package/lib/components/icons/RespArea.js +95 -0
  20. package/lib/components/icons/RespArea.js.map +1 -0
  21. package/lib/components/icons/TableIcons.js +69 -0
  22. package/lib/components/icons/TableIcons.js.map +1 -0
  23. package/lib/components/icons/TextAlign.js +194 -0
  24. package/lib/components/icons/TextAlign.js.map +1 -0
  25. package/lib/components/icons/index.js +194 -0
  26. package/lib/components/image/AltDialog.js +129 -0
  27. package/lib/components/image/ImageToolbar.js +177 -0
  28. package/lib/components/image/ImageToolbar.js.map +1 -0
  29. package/lib/components/image/InsertImageHandler.js +115 -0
  30. package/lib/components/image/InsertImageHandler.js.map +1 -0
  31. package/lib/components/image/alt-dialog.js +2 -0
  32. package/lib/components/media/MediaDialog.js +709 -0
  33. package/lib/components/media/MediaDialog.js.map +1 -0
  34. package/lib/components/media/MediaToolbar.js +101 -0
  35. package/lib/components/media/MediaToolbar.js.map +1 -0
  36. package/lib/components/media/MediaWrapper.js +93 -0
  37. package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js +94 -0
  38. package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js.map +1 -0
  39. package/lib/components/respArea/DragInTheBlank/choice.js +289 -0
  40. package/lib/components/respArea/DragInTheBlank/choice.js.map +1 -0
  41. package/lib/components/respArea/DragInTheBlank.js +94 -0
  42. package/lib/components/respArea/ExplicitConstructedResponse.js +120 -0
  43. package/lib/components/respArea/ExplicitConstructedResponse.js.map +1 -0
  44. package/lib/components/respArea/InlineDropdown.js +126 -0
  45. package/lib/components/respArea/InlineDropdown.js.map +1 -0
  46. package/lib/components/respArea/ToolbarIcon.js +105 -0
  47. package/lib/components/respArea/ToolbarIcon.js.map +1 -0
  48. package/lib/components/respArea/choice.js +2 -0
  49. package/lib/constants.js.map +1 -0
  50. package/lib/extensions/component.js +5 -5
  51. package/lib/extensions/component.js.map +1 -0
  52. package/lib/extensions/css.js.map +1 -0
  53. package/lib/extensions/custom-toolbar-wrapper.js +2 -4
  54. package/lib/extensions/custom-toolbar-wrapper.js.map +1 -0
  55. package/lib/extensions/extended-table.js +30 -0
  56. package/lib/extensions/extended-table.js.map +1 -0
  57. package/lib/extensions/image.js +2 -8
  58. package/lib/extensions/image.js.map +1 -0
  59. package/lib/extensions/index.js +52 -0
  60. package/lib/extensions/index.js.map +1 -0
  61. package/lib/extensions/math.js.map +1 -0
  62. package/lib/extensions/media.js +7 -7
  63. package/lib/extensions/media.js.map +1 -0
  64. package/lib/extensions/responseArea.js +7 -7
  65. package/lib/extensions/responseArea.js.map +1 -0
  66. package/lib/index.js +16 -1481
  67. package/lib/index.js.map +1 -0
  68. package/lib/plugins/index.js +8 -80
  69. package/lib/styles/editorContainerStyles.js +200 -0
  70. package/lib/styles/editorContainerStyles.js.map +1 -0
  71. package/lib/theme.js.map +1 -0
  72. package/lib/utils/size.js +34 -0
  73. package/lib/utils/size.js.map +1 -0
  74. package/package.json +1 -1
  75. package/src/components/CharacterPicker.jsx +185 -0
  76. package/src/components/EditableHtml.jsx +306 -0
  77. package/src/components/MenuBar.jsx +630 -0
  78. package/src/components/TiptapContainer.jsx +96 -0
  79. package/src/components/characters/characterUtils.js +127 -0
  80. package/src/{plugins/image/image-toolbar.jsx → components/image/ImageToolbar.jsx} +2 -2
  81. package/src/{plugins/image/insert-image-handler.js → components/image/InsertImageHandler.js} +0 -1
  82. package/src/{plugins/media/media-dialog.js → components/media/MediaDialog.js} +2 -2
  83. package/src/{plugins/respArea/drag-in-the-blank → components/respArea/DragInTheBlank}/choice.jsx +1 -1
  84. package/src/{plugins/respArea/inline-dropdown/index.jsx → components/respArea/InlineDropdown.jsx} +1 -1
  85. package/src/components/respArea/ToolbarIcon.jsx +68 -0
  86. package/src/extensions/component.jsx +2 -2
  87. package/src/extensions/custom-toolbar-wrapper.jsx +6 -7
  88. package/src/extensions/extended-table.js +27 -0
  89. package/src/extensions/image.js +2 -2
  90. package/src/extensions/index.js +76 -0
  91. package/src/extensions/media.js +12 -7
  92. package/src/extensions/responseArea.js +7 -7
  93. package/src/index.jsx +3 -1440
  94. package/src/styles/editorContainerStyles.js +203 -0
  95. package/src/utils/size.js +32 -0
  96. package/src/__tests__/editor.test.jsx +0 -363
  97. package/src/__tests__/serialization.test.js +0 -291
  98. package/src/block-tags.js +0 -17
  99. package/src/editor.jsx +0 -1197
  100. package/src/extensions/characters.js +0 -46
  101. package/src/old-index.jsx +0 -162
  102. package/src/parse-html.js +0 -8
  103. package/src/plugins/README.md +0 -27
  104. package/src/plugins/characters/index.jsx +0 -284
  105. package/src/plugins/characters/utils.js +0 -447
  106. package/src/plugins/css/index.jsx +0 -340
  107. package/src/plugins/customPlugin/index.jsx +0 -85
  108. package/src/plugins/html/icons/index.jsx +0 -19
  109. package/src/plugins/html/index.jsx +0 -72
  110. package/src/plugins/image/__tests__/__snapshots__/component.test.jsx.snap +0 -51
  111. package/src/plugins/image/__tests__/__snapshots__/image-toolbar-logic.test.jsx.snap +0 -27
  112. package/src/plugins/image/__tests__/__snapshots__/image-toolbar.test.jsx.snap +0 -44
  113. package/src/plugins/image/__tests__/component.test.jsx +0 -41
  114. package/src/plugins/image/__tests__/image-toolbar-logic.test.jsx +0 -42
  115. package/src/plugins/image/__tests__/image-toolbar.test.jsx +0 -11
  116. package/src/plugins/image/__tests__/index.test.js +0 -95
  117. package/src/plugins/image/__tests__/insert-image-handler.test.js +0 -113
  118. package/src/plugins/image/__tests__/mock-change.js +0 -15
  119. package/src/plugins/image/component.jsx +0 -343
  120. package/src/plugins/image/index.jsx +0 -227
  121. package/src/plugins/index.jsx +0 -377
  122. package/src/plugins/list/__tests__/index.test.js +0 -54
  123. package/src/plugins/list/index.jsx +0 -305
  124. package/src/plugins/math/__tests__/__snapshots__/index.test.jsx.snap +0 -48
  125. package/src/plugins/math/__tests__/index.test.jsx +0 -245
  126. package/src/plugins/math/index.jsx +0 -379
  127. package/src/plugins/media/__tests__/index.test.js +0 -75
  128. package/src/plugins/media/index.jsx +0 -325
  129. package/src/plugins/rendering/index.js +0 -31
  130. package/src/plugins/respArea/index.jsx +0 -299
  131. package/src/plugins/respArea/math-templated/index.jsx +0 -104
  132. package/src/plugins/respArea/utils.jsx +0 -90
  133. package/src/plugins/table/CustomTablePlugin.js +0 -113
  134. package/src/plugins/table/__tests__/__snapshots__/table-toolbar.test.jsx.snap +0 -44
  135. package/src/plugins/table/__tests__/index.test.jsx +0 -401
  136. package/src/plugins/table/__tests__/table-toolbar.test.jsx +0 -42
  137. package/src/plugins/table/index.jsx +0 -427
  138. package/src/plugins/table/table-toolbar.jsx +0 -136
  139. package/src/plugins/textAlign/index.jsx +0 -23
  140. package/src/plugins/toolbar/__tests__/__snapshots__/default-toolbar.test.jsx.snap +0 -923
  141. package/src/plugins/toolbar/__tests__/__snapshots__/editor-and-toolbar.test.jsx.snap +0 -20
  142. package/src/plugins/toolbar/__tests__/__snapshots__/toolbar-buttons.test.jsx.snap +0 -36
  143. package/src/plugins/toolbar/__tests__/__snapshots__/toolbar.test.jsx.snap +0 -46
  144. package/src/plugins/toolbar/__tests__/default-toolbar.test.jsx +0 -94
  145. package/src/plugins/toolbar/__tests__/editor-and-toolbar.test.jsx +0 -37
  146. package/src/plugins/toolbar/__tests__/toolbar-buttons.test.jsx +0 -51
  147. package/src/plugins/toolbar/__tests__/toolbar.test.jsx +0 -106
  148. package/src/plugins/toolbar/default-toolbar.jsx +0 -206
  149. package/src/plugins/toolbar/editor-and-toolbar.jsx +0 -257
  150. package/src/plugins/toolbar/index.jsx +0 -23
  151. package/src/plugins/toolbar/toolbar.jsx +0 -338
  152. package/src/plugins/utils.js +0 -31
  153. package/src/serialization.jsx +0 -621
  154. /package/src/{plugins → components}/characters/custom-popper.js +0 -0
  155. /package/src/{plugins/toolbar → components/common}/done-button.jsx +0 -0
  156. /package/src/{plugins/toolbar → components/common}/toolbar-buttons.jsx +0 -0
  157. /package/src/{plugins/css/icons/index.jsx → components/icons/CssIcon.jsx} +0 -0
  158. /package/src/{plugins/respArea/icons/index.jsx → components/icons/RespArea.jsx} +0 -0
  159. /package/src/{plugins/table/icons/index.jsx → components/icons/TableIcons.jsx} +0 -0
  160. /package/src/{plugins/textAlign/icons/index.jsx → components/icons/TextAlign.jsx} +0 -0
  161. /package/src/{plugins/image/alt-dialog.jsx → components/image/AltDialog.jsx} +0 -0
  162. /package/src/{plugins/media/media-toolbar.jsx → components/media/MediaToolbar.jsx} +0 -0
  163. /package/src/{plugins/media/media-wrapper.jsx → components/media/MediaWrapper.jsx} +0 -0
  164. /package/src/{plugins/respArea/drag-in-the-blank/index.jsx → components/respArea/DragInTheBlank/DragInTheBlank.jsx} +0 -0
  165. /package/src/{plugins/respArea/explicit-constructed-response/index.jsx → components/respArea/ExplicitConstructedResponse.jsx} +0 -0
@@ -1,104 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { withStyles } from '@material-ui/core/styles';
4
- import { mq } from '@pie-lib/math-input';
5
-
6
- const MathTemplated = ({ attributes, value, classes, keyToDisplay }) => (
7
- <span {...attributes} className={classes.spanContainer}>
8
- <div className={classes.responseBox}>{keyToDisplay}</div>
9
- <div className={classes.mathBlock}>
10
- <mq.Static latex={value} />
11
- </div>
12
- </span>
13
- );
14
-
15
- MathTemplated.propTypes = {
16
- attributes: PropTypes.object,
17
- classes: PropTypes.object.isRequired,
18
- value: PropTypes.string,
19
- keyToDisplay: PropTypes.string,
20
- };
21
-
22
- const styles = (theme) => ({
23
- responseBox: {
24
- background: theme.palette.grey['A100'],
25
- color: theme.palette.grey['A700'],
26
- display: 'inline-flex',
27
- borderRight: '2px solid #C0C3CF',
28
- boxSizing: 'border-box',
29
- overflow: 'hidden',
30
- fontSize: '12px',
31
- minHeight: '36px',
32
- height: '100%',
33
- alignItems: 'center',
34
- fontFamily: 'Symbola, Times New Roman, serif',
35
- padding: '0 2px',
36
- },
37
- spanContainer: {
38
- display: 'inline-flex',
39
- border: '1px solid #C0C3CF',
40
- margin: '1px 5px',
41
- cursor: 'pointer',
42
- alignItems: 'center',
43
- justifyContent: 'center',
44
- minWidth: '50px',
45
- minHeight: '36px',
46
- height: 'fit-content',
47
- },
48
- mathBlock: {
49
- flex: 8,
50
- color: 'var(--pie-text, black)',
51
- padding: '4px !important',
52
- display: 'flex',
53
- alignItems: 'center',
54
- justifyContent: 'center',
55
- backgroundColor: 'var(--pie-background, rgba(255, 255, 255, 0))',
56
- '& > .mq-math-mode sup.mq-nthroot': {
57
- fontSize: '70% !important',
58
- verticalAlign: '1em !important',
59
- },
60
- '& > .mq-math-mode .mq-sqrt-stem': {
61
- borderTop: '0.07em solid',
62
- marginLeft: '-1.5px',
63
- marginTop: '-2px !important',
64
- paddingTop: '5px !important',
65
- },
66
- '& .mq-overarrow-inner': {
67
- paddingTop: '0 !important',
68
- border: 'none !important',
69
- },
70
- '& .mq-overarrow.mq-arrow-both': {
71
- marginTop: '0px',
72
- minWidth: '1.23em',
73
- '& *': {
74
- lineHeight: '1 !important',
75
- },
76
- '&:before': {
77
- top: '-0.4em',
78
- left: '-1px',
79
- },
80
- '&:after': {
81
- top: '0px !important',
82
- position: 'absolute !important',
83
- right: '-2px',
84
- },
85
- '&.mq-empty:after': {
86
- top: '-0.45em',
87
- },
88
- },
89
- '& .mq-overarrow.mq-arrow-right': {
90
- '&:before': {
91
- top: '-0.4em',
92
- right: '-1px',
93
- },
94
- },
95
- '& .mq-overarrow-inner-right': {
96
- display: 'none !important',
97
- },
98
- '& .mq-overarrow-inner-left': {
99
- display: 'none !important',
100
- },
101
- },
102
- });
103
-
104
- export default withStyles(styles)(MathTemplated);
@@ -1,90 +0,0 @@
1
- import React from 'react';
2
- import ReactDOM from 'react-dom';
3
- import { Inline } from 'slate';
4
- import Snackbar from '@material-ui/core/Snackbar';
5
-
6
- export const isNumber = (val) => !isNaN(parseFloat(val)) && isFinite(val);
7
-
8
- export const insertSnackBar = (message) => {
9
- const prevSnacks = document.querySelectorAll('.response-area-alert');
10
-
11
- prevSnacks.forEach((s) => s.remove());
12
-
13
- const newEl = document.createElement('div');
14
-
15
- newEl.className = 'response-area-alert';
16
-
17
- const el = (
18
- <Snackbar
19
- anchorOrigin={{ vertical: 'top', horizontal: 'center' }}
20
- open={true}
21
- ContentProps={{
22
- 'aria-describedby': 'message-id',
23
- }}
24
- message={<span id="message-id">{message}</span>}
25
- />
26
- );
27
-
28
- ReactDOM.render(el, newEl);
29
-
30
- document.body.appendChild(newEl);
31
-
32
- setTimeout(() => {
33
- newEl.remove();
34
- }, 2000);
35
- };
36
-
37
- export const defaultECR = (index) =>
38
- Inline.create({
39
- type: 'explicit_constructed_response',
40
- isVoid: true,
41
- data: {
42
- index,
43
- },
44
- });
45
- export const defaultMT = (index) =>
46
- Inline.create({
47
- type: 'math_templated',
48
- isVoid: true,
49
- data: {
50
- index,
51
- },
52
- });
53
-
54
- export const defaultDIB = (opts, index) =>
55
- Inline.create({
56
- type: 'drag_in_the_blank',
57
- isVoid: true,
58
- data: {
59
- index,
60
- duplicates: opts.options.duplicates,
61
- value: null,
62
- },
63
- });
64
-
65
- export const defaultIDD = (index) =>
66
- Inline.create({
67
- object: 'inline',
68
- type: 'inline_dropdown',
69
- isVoid: true,
70
- data: {
71
- index,
72
- },
73
- });
74
-
75
- export const getDefaultElement = (opts, index) => {
76
- switch (opts.type) {
77
- case 'explicit-constructed-response':
78
- return defaultECR(index);
79
-
80
- case 'math-templated':
81
- return defaultMT(index);
82
-
83
- case 'drag-in-the-blank':
84
- return defaultDIB(opts, index);
85
-
86
- default:
87
- // inline-dropdown
88
- return defaultIDD(index);
89
- }
90
- };
@@ -1,113 +0,0 @@
1
- import EditTable from 'slate-edit-table';
2
- import { isSelectionInTable } from 'slate-edit-table/dist/utils';
3
- import { onEnter, onModEnter, onTab, onUpDown } from 'slate-edit-table/dist/handlers';
4
- import TableOptions from 'slate-edit-table/dist/options';
5
- import { clearCell } from 'slate-edit-table/dist/changes';
6
-
7
- function onBackspace(event, change, editor, opts) {
8
- const { value } = change;
9
- const { startBlock, endBlock, selection, document } = value;
10
-
11
- const startCell = document.getClosest(startBlock.key, opts.isCell);
12
- const endCell = document.getClosest(endBlock.key, opts.isCell);
13
-
14
- const startBlockIndex = startCell?.nodes?.findIndex((block) => block.key == startBlock.key);
15
-
16
- // If a cursor is collapsed at the start of the first block, do nothing
17
- if (startBlockIndex === 0 && selection.isAtStartOf(startBlock)) {
18
- if (startBlock.isVoid) {
19
- // Delete the block normally if it is a void block
20
- return undefined;
21
- }
22
-
23
- event.preventDefault();
24
- return change;
25
- }
26
-
27
- // If "normal" deletion, we continue
28
- if (startCell === endCell) {
29
- return undefined;
30
- }
31
-
32
- // If cursor is between multiple blocks,
33
- // we clear the content of the cells.
34
- event.preventDefault();
35
-
36
- const { blocks } = value;
37
-
38
- // Get all cells that contains the selection
39
- const cells = blocks
40
- .map((node) =>
41
- node.type === opts.typeCell ? node : document.getClosest(node.key, (a) => a.type === opts.typeCell),
42
- )
43
- .toSet();
44
-
45
- // If the cursor is at the very end of the first cell, ignore it.
46
- // If the cursor is at the very start of the last cell, ignore it.
47
- // This behavior is to compensate hanging selection behaviors:
48
- // https://github.com/ianstormtaylor/slate/pull/1605
49
- const ignoreFirstCell = value.selection.collapseToStart().isAtEndOf(cells.first());
50
- const ignoreLastCell = value.selection.collapseToEnd().isAtStartOf(cells.last());
51
-
52
- let cellsToClear = cells;
53
- if (ignoreFirstCell) {
54
- cellsToClear = cellsToClear.rest();
55
- }
56
- if (ignoreLastCell) {
57
- cellsToClear = cellsToClear.butLast();
58
- }
59
-
60
- // Clear all the selection
61
- cellsToClear.forEach((cell) => clearCell(opts, change, cell));
62
-
63
- // Update the selection properly, and avoid reset of selection
64
- const updatedStartCell = change.value.document.getDescendant(cellsToClear.first().key);
65
- return change.collapseToStartOf(updatedStartCell);
66
- }
67
-
68
- const KEY_ENTER = 'Enter';
69
- const KEY_TAB = 'Tab';
70
- const KEY_BACKSPACE = 'Backspace';
71
- const KEY_DOWN = 'ArrowDown';
72
- const KEY_UP = 'ArrowUp';
73
-
74
- /**
75
- * User is pressing a key in the editor
76
- */
77
- function onKeyDown(opts, event, change, editor) {
78
- // Only handle events in cells
79
- if (!isSelectionInTable(opts, change.value)) {
80
- return undefined;
81
- }
82
-
83
- // Build arguments list
84
- const args = [event, change, editor, opts];
85
-
86
- switch (event.key) {
87
- case KEY_ENTER:
88
- if (event.metaKey && opts.exitBlockType) {
89
- return onModEnter(...args);
90
- }
91
- return onEnter(...args);
92
-
93
- case KEY_TAB:
94
- return onTab(...args);
95
- case KEY_BACKSPACE:
96
- return onBackspace(...args);
97
- case KEY_DOWN:
98
- case KEY_UP:
99
- return onUpDown(...args);
100
- default:
101
- return undefined;
102
- }
103
- }
104
-
105
- export default (opts) => {
106
- const core = EditTable(opts);
107
-
108
- const tableOpts = new TableOptions(opts);
109
-
110
- core.onKeyDown = onKeyDown.bind(null, tableOpts);
111
-
112
- return core;
113
- };
@@ -1,44 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`table-toolbar snapshot renders 1`] = `
4
- <div
5
- className="table-toolbar"
6
- >
7
- <div>
8
- <WithStyles(RawButton)
9
- onClick={[MockFunction]}
10
- >
11
- <WithStyles(Component) />
12
- </WithStyles(RawButton)>
13
- <WithStyles(RawButton)
14
- onClick={[MockFunction]}
15
- >
16
- <WithStyles(Component) />
17
- </WithStyles(RawButton)>
18
- <WithStyles(RawButton)
19
- onClick={[MockFunction]}
20
- >
21
- <WithStyles(Component) />
22
- </WithStyles(RawButton)>
23
- <WithStyles(RawButton)
24
- onClick={[MockFunction]}
25
- >
26
- <WithStyles(Component) />
27
- </WithStyles(RawButton)>
28
- <WithStyles(RawButton)
29
- onClick={[MockFunction]}
30
- >
31
- <WithStyles(Component) />
32
- </WithStyles(RawButton)>
33
- <WithStyles(RawButton)
34
- active={true}
35
- onClick={[MockFunction]}
36
- >
37
- <pure(BorderAllIcon) />
38
- </WithStyles(RawButton)>
39
- </div>
40
- <WithStyles(RawDoneButton)
41
- onClick={[Function]}
42
- />
43
- </div>
44
- `;