@pie-lib/editable-html-tip-tap 0.1.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.
Files changed (158) hide show
  1. package/dist/components/CharacterPicker.d.ts +31 -0
  2. package/dist/components/CharacterPicker.d.ts.map +1 -0
  3. package/dist/components/CharacterPicker.js +129 -0
  4. package/dist/components/EditableHtml.d.ts +11 -0
  5. package/dist/components/EditableHtml.d.ts.map +1 -0
  6. package/dist/components/EditableHtml.js +270 -0
  7. package/dist/components/MenuBar.d.ts +11 -0
  8. package/dist/components/MenuBar.d.ts.map +1 -0
  9. package/dist/components/MenuBar.js +460 -0
  10. package/dist/components/TiptapContainer.d.ts +11 -0
  11. package/dist/components/TiptapContainer.d.ts.map +1 -0
  12. package/dist/components/TiptapContainer.js +157 -0
  13. package/dist/components/characters/characterUtils.d.ts +36 -0
  14. package/dist/components/characters/characterUtils.d.ts.map +1 -0
  15. package/dist/components/characters/characterUtils.js +465 -0
  16. package/dist/components/characters/custom-popper.d.ts +14 -0
  17. package/dist/components/characters/custom-popper.d.ts.map +1 -0
  18. package/dist/components/characters/custom-popper.js +32 -0
  19. package/dist/components/common/done-button.d.ts +30 -0
  20. package/dist/components/common/done-button.d.ts.map +1 -0
  21. package/dist/components/common/done-button.js +26 -0
  22. package/dist/components/common/toolbar-buttons.d.ts +39 -0
  23. package/dist/components/common/toolbar-buttons.d.ts.map +1 -0
  24. package/dist/components/common/toolbar-buttons.js +91 -0
  25. package/dist/components/icons/CssIcon.d.ts +11 -0
  26. package/dist/components/icons/CssIcon.d.ts.map +1 -0
  27. package/dist/components/icons/CssIcon.js +14 -0
  28. package/dist/components/icons/RespArea.d.ts +26 -0
  29. package/dist/components/icons/RespArea.d.ts.map +1 -0
  30. package/dist/components/icons/RespArea.js +42 -0
  31. package/dist/components/icons/TableIcons.d.ts +14 -0
  32. package/dist/components/icons/TableIcons.d.ts.map +1 -0
  33. package/dist/components/icons/TableIcons.js +32 -0
  34. package/dist/components/icons/TextAlign.d.ts +18 -0
  35. package/dist/components/icons/TextAlign.d.ts.map +1 -0
  36. package/dist/components/icons/TextAlign.js +134 -0
  37. package/dist/components/image/AltDialog.d.ts +23 -0
  38. package/dist/components/image/AltDialog.d.ts.map +1 -0
  39. package/dist/components/image/AltDialog.js +61 -0
  40. package/dist/components/image/ImageToolbar.d.ts +25 -0
  41. package/dist/components/image/ImageToolbar.d.ts.map +1 -0
  42. package/dist/components/image/ImageToolbar.js +80 -0
  43. package/dist/components/image/InsertImageHandler.d.ts +33 -0
  44. package/dist/components/image/InsertImageHandler.d.ts.map +1 -0
  45. package/dist/components/image/InsertImageHandler.js +55 -0
  46. package/dist/components/media/MediaDialog.d.ts +44 -0
  47. package/dist/components/media/MediaDialog.d.ts.map +1 -0
  48. package/dist/components/media/MediaDialog.js +389 -0
  49. package/dist/components/media/MediaToolbar.d.ts +20 -0
  50. package/dist/components/media/MediaToolbar.d.ts.map +1 -0
  51. package/dist/components/media/MediaToolbar.js +41 -0
  52. package/dist/components/media/MediaWrapper.d.ts +20 -0
  53. package/dist/components/media/MediaWrapper.d.ts.map +1 -0
  54. package/dist/components/respArea/DragInTheBlank/DragInTheBlank.d.ts +23 -0
  55. package/dist/components/respArea/DragInTheBlank/DragInTheBlank.d.ts.map +1 -0
  56. package/dist/components/respArea/DragInTheBlank/DragInTheBlank.js +58 -0
  57. package/dist/components/respArea/DragInTheBlank/choice.d.ts +56 -0
  58. package/dist/components/respArea/DragInTheBlank/choice.d.ts.map +1 -0
  59. package/dist/components/respArea/DragInTheBlank/choice.js +156 -0
  60. package/dist/components/respArea/ExplicitConstructedResponse.d.ts +20 -0
  61. package/dist/components/respArea/ExplicitConstructedResponse.d.ts.map +1 -0
  62. package/dist/components/respArea/ExplicitConstructedResponse.js +67 -0
  63. package/dist/components/respArea/InlineDropdown.d.ts +18 -0
  64. package/dist/components/respArea/InlineDropdown.d.ts.map +1 -0
  65. package/dist/components/respArea/InlineDropdown.js +91 -0
  66. package/dist/components/respArea/MathTemplated.d.ts +19 -0
  67. package/dist/components/respArea/MathTemplated.d.ts.map +1 -0
  68. package/dist/components/respArea/MathTemplated.js +97 -0
  69. package/dist/components/respArea/ToolbarIcon.d.ts +14 -0
  70. package/dist/components/respArea/ToolbarIcon.d.ts.map +1 -0
  71. package/dist/components/respArea/ToolbarIcon.js +17 -0
  72. package/dist/constants.d.ts +14 -0
  73. package/dist/constants.d.ts.map +1 -0
  74. package/dist/constants.js +4 -0
  75. package/dist/extensions/css.d.ts +12 -0
  76. package/dist/extensions/css.d.ts.map +1 -0
  77. package/dist/extensions/css.js +115 -0
  78. package/dist/extensions/custom-toolbar-wrapper.d.ts +11 -0
  79. package/dist/extensions/custom-toolbar-wrapper.d.ts.map +1 -0
  80. package/dist/extensions/custom-toolbar-wrapper.js +58 -0
  81. package/dist/extensions/div-node.d.ts +11 -0
  82. package/dist/extensions/div-node.d.ts.map +1 -0
  83. package/dist/extensions/div-node.js +25 -0
  84. package/dist/extensions/extended-table.d.ts +11 -0
  85. package/dist/extensions/extended-table.d.ts.map +1 -0
  86. package/dist/extensions/extended-table.js +15 -0
  87. package/dist/extensions/image-component.d.ts +22 -0
  88. package/dist/extensions/image-component.d.ts.map +1 -0
  89. package/dist/extensions/image-component.js +200 -0
  90. package/dist/extensions/image.d.ts +11 -0
  91. package/dist/extensions/image.d.ts.map +1 -0
  92. package/dist/extensions/image.js +42 -0
  93. package/dist/extensions/index.d.ts +17 -0
  94. package/dist/extensions/index.d.ts.map +1 -0
  95. package/dist/extensions/index.js +65 -0
  96. package/dist/extensions/math.d.ts +15 -0
  97. package/dist/extensions/math.d.ts.map +1 -0
  98. package/dist/extensions/math.js +150 -0
  99. package/dist/extensions/media.d.ts +19 -0
  100. package/dist/extensions/media.d.ts.map +1 -0
  101. package/dist/extensions/media.js +147 -0
  102. package/dist/extensions/responseArea.d.ts +28 -0
  103. package/dist/extensions/responseArea.d.ts.map +1 -0
  104. package/dist/extensions/responseArea.js +259 -0
  105. package/dist/index.d.ts +13 -0
  106. package/dist/index.d.ts.map +1 -0
  107. package/dist/index.js +6 -0
  108. package/dist/styles/editorContainerStyles.d.ts +135 -0
  109. package/dist/styles/editorContainerStyles.d.ts.map +1 -0
  110. package/dist/theme.d.ts +10 -0
  111. package/dist/theme.d.ts.map +1 -0
  112. package/dist/utils/helper.d.ts +10 -0
  113. package/dist/utils/helper.d.ts.map +1 -0
  114. package/dist/utils/helper.js +7 -0
  115. package/dist/utils/size.d.ts +10 -0
  116. package/dist/utils/size.d.ts.map +1 -0
  117. package/dist/utils/size.js +14 -0
  118. package/package.json +71 -0
  119. package/src/components/CharacterPicker.tsx +210 -0
  120. package/src/components/EditableHtml.tsx +416 -0
  121. package/src/components/MenuBar.tsx +558 -0
  122. package/src/components/TiptapContainer.tsx +228 -0
  123. package/src/components/characters/characterUtils.ts +457 -0
  124. package/src/components/characters/custom-popper.tsx +48 -0
  125. package/src/components/common/done-button.tsx +37 -0
  126. package/src/components/common/toolbar-buttons.tsx +132 -0
  127. package/src/components/icons/CssIcon.tsx +25 -0
  128. package/src/components/icons/RespArea.tsx +81 -0
  129. package/src/components/icons/TableIcons.tsx +62 -0
  130. package/src/components/icons/TextAlign.tsx +124 -0
  131. package/src/components/image/AltDialog.tsx +92 -0
  132. package/src/components/image/ImageToolbar.tsx +109 -0
  133. package/src/components/image/InsertImageHandler.ts +121 -0
  134. package/src/components/media/MediaDialog.tsx +606 -0
  135. package/src/components/media/MediaToolbar.tsx +59 -0
  136. package/src/components/media/MediaWrapper.tsx +49 -0
  137. package/src/components/respArea/DragInTheBlank/DragInTheBlank.tsx +86 -0
  138. package/src/components/respArea/DragInTheBlank/choice.tsx +266 -0
  139. package/src/components/respArea/ExplicitConstructedResponse.tsx +122 -0
  140. package/src/components/respArea/InlineDropdown.tsx +152 -0
  141. package/src/components/respArea/MathTemplated.tsx +134 -0
  142. package/src/components/respArea/ToolbarIcon.tsx +76 -0
  143. package/src/constants.ts +15 -0
  144. package/src/extensions/css.tsx +230 -0
  145. package/src/extensions/custom-toolbar-wrapper.tsx +88 -0
  146. package/src/extensions/div-node.tsx +46 -0
  147. package/src/extensions/extended-table.ts +34 -0
  148. package/src/extensions/image-component.tsx +303 -0
  149. package/src/extensions/image.tsx +64 -0
  150. package/src/extensions/index.tsx +91 -0
  151. package/src/extensions/math.tsx +285 -0
  152. package/src/extensions/media.tsx +198 -0
  153. package/src/extensions/responseArea.tsx +404 -0
  154. package/src/index.tsx +15 -0
  155. package/src/styles/editorContainerStyles.ts +155 -0
  156. package/src/theme.ts +11 -0
  157. package/src/utils/helper.tsx +27 -0
  158. package/src/utils/size.ts +42 -0
@@ -0,0 +1,134 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @synced-from pie-lib/packages/editable-html-tip-tap/src/components/respArea/MathTemplated.jsx
4
+ * @auto-generated
5
+ *
6
+ * This file is automatically synced from pie-elements and converted to TypeScript.
7
+ * Manual edits will be overwritten on next sync.
8
+ * To make changes, edit the upstream JavaScript file and run sync again.
9
+ */
10
+
11
+ import React from 'react';
12
+ import PropTypes from 'prop-types';
13
+ import { NodeViewWrapper } from '@tiptap/react';
14
+ import { mq } from '@pie-lib/math-input';
15
+ import { styled } from '@mui/material/styles';
16
+
17
+ const StyledSpanContainer: any = styled('span')(() => ({
18
+ display: 'inline-flex',
19
+ border: '1px solid #C0C3CF',
20
+ margin: '1px 5px',
21
+ cursor: 'pointer',
22
+ alignItems: 'center',
23
+ justifyContent: 'center',
24
+ minWidth: '50px',
25
+ minHeight: '36px',
26
+ height: 'fit-content',
27
+ }));
28
+
29
+ const StyledResponseBox: any = styled('div')(({ theme }) => ({
30
+ background: theme.palette.grey['A100'],
31
+ color: theme.palette.grey['A700'],
32
+ display: 'inline-flex',
33
+ borderRight: '2px solid #C0C3CF',
34
+ boxSizing: 'border-box',
35
+ overflow: 'hidden',
36
+ fontSize: '12px',
37
+ minHeight: '36px',
38
+ height: '100%',
39
+ alignItems: 'center',
40
+ fontFamily: 'Symbola, Times New Roman, serif',
41
+ padding: '0 2px',
42
+ }));
43
+
44
+ const StyledMathBlock: any = styled('div')(() => ({
45
+ flex: 8,
46
+ color: 'var(--pie-text, black)',
47
+ padding: '4px !important',
48
+ display: 'flex',
49
+ alignItems: 'center',
50
+ justifyContent: 'center',
51
+ backgroundColor: 'var(--pie-background, rgba(255, 255, 255, 0))',
52
+ '& > .mq-math-mode sup.mq-nthroot': {
53
+ fontSize: '70% !important',
54
+ verticalAlign: '1em !important',
55
+ },
56
+ '& > .mq-math-mode .mq-sqrt-stem': {
57
+ borderTop: '0.07em solid',
58
+ marginLeft: '-1.5px',
59
+ marginTop: '-2px !important',
60
+ paddingTop: '5px !important',
61
+ },
62
+ '& .mq-overarrow-inner': {
63
+ paddingTop: '0 !important',
64
+ border: 'none !important',
65
+ },
66
+ '& .mq-overarrow.mq-arrow-both': {
67
+ marginTop: '0px',
68
+ minWidth: '1.23em',
69
+ '& *': {
70
+ lineHeight: '1 !important',
71
+ },
72
+ '&:before': {
73
+ top: '-0.4em',
74
+ left: '-1px',
75
+ },
76
+ '&:after': {
77
+ top: '0px !important',
78
+ position: 'absolute !important',
79
+ right: '-2px',
80
+ },
81
+ '&.mq-empty:after': {
82
+ top: '-0.45em',
83
+ },
84
+ },
85
+ '& .mq-overarrow.mq-arrow-right': {
86
+ '&:before': {
87
+ top: '-0.4em',
88
+ right: '-1px',
89
+ },
90
+ },
91
+ '& .mq-overarrow-inner-right': {
92
+ display: 'none !important',
93
+ },
94
+ '& .mq-overarrow-inner-left': {
95
+ display: 'none !important',
96
+ },
97
+ }));
98
+ const MathTemplated = (props) => {
99
+ const { node, options, selected } = props;
100
+ const { attrs: attributes } = node;
101
+ const { value, index } = attributes;
102
+
103
+ // add 1 to index to display R 1 instead of R 0
104
+ const keyToDisplay = `R ${parseInt(index) + 1}`;
105
+
106
+ // console.log({nodeProps.children})
107
+ return (
108
+ <NodeViewWrapper
109
+ className="math-templated"
110
+ data-selected={selected}
111
+ style={{
112
+ display: 'inline-flex',
113
+ minHeight: '36px',
114
+ minWidth: '50px',
115
+ cursor: 'pointer',
116
+ }}
117
+ >
118
+ <StyledSpanContainer {...attributes}>
119
+ <StyledResponseBox>{keyToDisplay}</StyledResponseBox>
120
+ <StyledMathBlock>
121
+ <mq.Static latex={value} />
122
+ </StyledMathBlock>
123
+ </StyledSpanContainer>
124
+ </NodeViewWrapper>
125
+ );
126
+ };
127
+
128
+ MathTemplated.propTypes = {
129
+ attributes: PropTypes.object,
130
+ value: PropTypes.string,
131
+ keyToDisplay: PropTypes.string,
132
+ };
133
+
134
+ export default MathTemplated;
@@ -0,0 +1,76 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @synced-from pie-lib/packages/editable-html-tip-tap/src/components/respArea/ToolbarIcon.jsx
4
+ * @auto-generated
5
+ *
6
+ * This file is automatically synced from pie-elements and converted to TypeScript.
7
+ * Manual edits will be overwritten on next sync.
8
+ * To make changes, edit the upstream JavaScript file and run sync again.
9
+ */
10
+
11
+ import React from 'react';
12
+ import { styled } from '@mui/material/styles';
13
+
14
+ export const Chevron = (props) => {
15
+ const { direction, style } = props;
16
+ const rotate = (() => {
17
+ switch (direction) {
18
+ case 'down':
19
+ return 90;
20
+ case 'up':
21
+ return -90;
22
+ case 'left':
23
+ return 180;
24
+ default:
25
+ return 0;
26
+ }
27
+ })();
28
+
29
+ return (
30
+ <svg
31
+ style={{
32
+ transform: `rotate(${rotate}deg)`,
33
+ ...style,
34
+ }}
35
+ width="24"
36
+ height="24"
37
+ viewBox="0 0 24 24"
38
+ xmlns="http://www.w3.org/2000/svg"
39
+ >
40
+ <path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z" fill="currentColor" />
41
+ </svg>
42
+ );
43
+ };
44
+
45
+ export const GripIcon = ({ style }) => (
46
+ <span style={style}>
47
+ <svg
48
+ style={{
49
+ margin: '0 -16px',
50
+ }}
51
+ width="24"
52
+ height="24"
53
+ viewBox="0 0 24 24"
54
+ xmlns="http://www.w3.org/2000/svg"
55
+ >
56
+ <path d="M9 3H7v2h2V3zm0 4H7v2h2V7zm0 4H7v2h2v-2zm0 4H7v2h2v-2zm0 4H7v2h2v-2zm4-16h-2v2h2V3zm0 4h-2v2h2V7zm0 4h-2v2h2v-2zm0 4h-2v2h2v-2zm0 4h-2v2h2v-2z" />
57
+ </svg>
58
+ <svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
59
+ <path d="M9 3H7v2h2V3zm0 4H7v2h2V7zm0 4H7v2h2v-2zm0 4H7v2h2v-2zm0 4H7v2h2v-2zm4-16h-2v2h2V3zm0 4h-2v2h2V7zm0 4h-2v2h2v-2zm0 4h-2v2h2v-2zm0 4h-2v2h2v-2z" />
60
+ </svg>
61
+ </span>
62
+ );
63
+
64
+ const StyledToolbarIcon: any = styled('div')(({ theme }) => ({
65
+ fontFamily: 'Cerebri Sans !important',
66
+ fontSize: theme.typography.fontSize,
67
+ fontWeight: 'bold',
68
+ lineHeight: '14px',
69
+ position: 'relative',
70
+ top: '7px',
71
+ width: '110px',
72
+ height: '28px',
73
+ whiteSpace: 'nowrap',
74
+ }));
75
+
76
+ export const ToolbarIcon = () => <StyledToolbarIcon>+ Response Area</StyledToolbarIcon>;
@@ -0,0 +1,15 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @synced-from pie-lib/packages/editable-html-tip-tap/src/constants.js
4
+ * @auto-generated
5
+ *
6
+ * This file is automatically synced from pie-elements and converted to TypeScript.
7
+ * Manual edits will be overwritten on next sync.
8
+ * To make changes, edit the upstream JavaScript file and run sync again.
9
+ */
10
+
11
+ export const PIE_TOOLBAR__CLASS = 'pie-toolbar';
12
+
13
+ export default {
14
+ PIE_TOOLBAR__CLASS,
15
+ };
@@ -0,0 +1,230 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @synced-from pie-lib/packages/editable-html-tip-tap/src/extensions/css.js
4
+ * @auto-generated
5
+ *
6
+ * This file is automatically synced from pie-elements and converted to TypeScript.
7
+ * Manual edits will be overwritten on next sync.
8
+ * To make changes, edit the upstream JavaScript file and run sync again.
9
+ */
10
+
11
+ import React from 'react';
12
+ import ReactDOM from 'react-dom';
13
+ import { Mark, mergeAttributes } from '@tiptap/core';
14
+ import List from '@mui/material/List';
15
+ import ListItem from '@mui/material/ListItem';
16
+
17
+ export const removeDialogs = () => {
18
+ const prevDialogs = document.querySelectorAll('.insert-css-dialog');
19
+
20
+ prevDialogs.forEach((s) => s.remove());
21
+ };
22
+
23
+ const insertDialog = ({ editor, callback, opts, selectedText, parentNode }) => {
24
+ const editorDOM = editor.options.element;
25
+ const newEl = document.createElement('div');
26
+ const { selection } = editor.state;
27
+
28
+ removeDialogs();
29
+
30
+ newEl.className = 'insert-css-dialog';
31
+
32
+ let popoverEl;
33
+
34
+ const closePopOver = () => {
35
+ if (popoverEl) {
36
+ popoverEl.remove();
37
+ }
38
+ };
39
+
40
+ let firstCallMade = false;
41
+
42
+ const listener = (e) => {
43
+ // this will be triggered right after setting it because
44
+ // this toolbar is added on the mousedown event
45
+ // so right after mouseup, the click will be triggered
46
+ if (firstCallMade) {
47
+ const focusIsInModals = newEl.contains(e.target) || (popoverEl && popoverEl.contains(e.target));
48
+ const focusIsInEditor = editorDOM.contains(e.target);
49
+
50
+ if (!(focusIsInModals || focusIsInEditor)) {
51
+ handleClose();
52
+ }
53
+ } else {
54
+ firstCallMade = true;
55
+ }
56
+ };
57
+
58
+ const handleClose = () => {
59
+ callback(undefined, true);
60
+ newEl.remove();
61
+ closePopOver();
62
+ document.body.removeEventListener('click', listener);
63
+ };
64
+
65
+ const handleChange = (name) => {
66
+ callback(name, true);
67
+ newEl.remove();
68
+ closePopOver();
69
+ document.body.removeEventListener('click', listener);
70
+ };
71
+
72
+ const parentNodeClass = parentNode?.attrs.class;
73
+ const createHTML = (name) => {
74
+ let html = `<span class="${name}">${selectedText}</span>`;
75
+
76
+ if (parentNode) {
77
+ let tag = 'span';
78
+
79
+ if (parentNode?.object === 'inline') {
80
+ tag = 'span';
81
+ }
82
+
83
+ if (parentNode?.object === 'block') {
84
+ tag = 'div';
85
+ }
86
+
87
+ html = `<${tag} class="${parentNodeClass}">${parentNode.text.slice(
88
+ 0,
89
+ selection.$anchor.textOffset,
90
+ )}${html}${parentNode.text.slice(selection.$head.textOffset)}</${tag}>`;
91
+ }
92
+
93
+ return html;
94
+ };
95
+
96
+ const el = (
97
+ <div
98
+ style={{ background: 'white', height: 500, padding: 20, overflow: 'hidden', display: 'flex', flexFlow: 'column' }}
99
+ >
100
+ <h2>Please choose a css class</h2>
101
+ {parentNodeClass && <div>The current parent has this class {parentNodeClass}</div>}
102
+ <List component="nav" style={{ overflow: 'scroll' }}>
103
+ {opts.names.map((name, i) => (
104
+ <ListItem key={`rule-${i}`} button onClick={() => handleChange(name)}>
105
+ <div style={{ marginRight: 20 }}>{name}</div>
106
+ <div
107
+ dangerouslySetInnerHTML={{
108
+ __html: createHTML(name),
109
+ }}
110
+ />
111
+ </ListItem>
112
+ ))}
113
+ </List>
114
+ </div>
115
+ );
116
+
117
+ ReactDOM.render(el, newEl, () => {
118
+ const cursorItem = editor.view.nodeDOM(editor.state.selection.from);
119
+ const cursorNode = cursorItem?.parentNode;
120
+
121
+ if (cursorNode) {
122
+ const bodyRect = editorDOM.parentElement.parentElement.parentElement.getBoundingClientRect();
123
+ const boundRect = cursorNode.getBoundingClientRect();
124
+
125
+ editorDOM.parentElement.parentElement.parentElement.appendChild(newEl);
126
+
127
+ newEl.style.maxWidth = '500px';
128
+ newEl.style.position = 'absolute';
129
+ newEl.style.top = 0;
130
+ newEl.style.zIndex = 99999;
131
+
132
+ const leftValue = `${boundRect.left + Math.abs(bodyRect.left) + cursorNode.offsetWidth + 10}px`;
133
+
134
+ const rightValue = `${boundRect.x}px`;
135
+
136
+ newEl.style.left = leftValue;
137
+
138
+ const leftAlignedWidth = newEl.offsetWidth;
139
+
140
+ newEl.style.left = 'unset';
141
+ newEl.style.right = rightValue;
142
+
143
+ const rightAlignedWidth = newEl.offsetWidth;
144
+
145
+ newEl.style.left = 'unset';
146
+ newEl.style.right = 'unset';
147
+
148
+ if (leftAlignedWidth >= rightAlignedWidth) {
149
+ newEl.style.left = leftValue;
150
+ } else {
151
+ newEl.style.right = rightValue;
152
+ }
153
+
154
+ document.body.addEventListener('click', listener);
155
+ }
156
+ });
157
+ };
158
+
159
+ export const CSSMark = Mark.create({
160
+ name: 'cssmark',
161
+
162
+ addOptions() {
163
+ return {
164
+ classes: [],
165
+ };
166
+ },
167
+
168
+ addAttributes() {
169
+ return {
170
+ class: {
171
+ default: null,
172
+ parseHTML: (el) => el.getAttribute('class'),
173
+ renderHTML: (attributes) => {
174
+ if (!attributes.class) return {};
175
+ return { class: attributes.class };
176
+ },
177
+ },
178
+ };
179
+ },
180
+
181
+ parseHTML() {
182
+ // Any span with a class that matches one of allowed classes
183
+ return [
184
+ {
185
+ tag: 'span[class]',
186
+ getAttrs: (el) => {
187
+ const cls = el.getAttribute('class') || '';
188
+ const match = this.options.classes.find((name) => cls.includes(name));
189
+ return match ? { class: match } : false;
190
+ },
191
+ },
192
+ ];
193
+ },
194
+
195
+ renderHTML({ HTMLAttributes }) {
196
+ return ['span', mergeAttributes(HTMLAttributes), 0];
197
+ },
198
+
199
+ addCommands() {
200
+ return {
201
+ setCSSClass:
202
+ (className) =>
203
+ ({ commands }) => {
204
+ return commands.setMark(this.name, { class: className });
205
+ },
206
+
207
+ unsetCSSClass:
208
+ () =>
209
+ ({ commands }) => {
210
+ return commands.unsetMark(this.name);
211
+ },
212
+
213
+ openCSSClassDialog:
214
+ () =>
215
+ ({ editor }) => {
216
+ insertDialog({
217
+ editor,
218
+ selectedText: editor.state.doc.textBetween(editor.state.selection.from, editor.state.selection.to),
219
+ parentNode: editor.state.selection.$from.nodeAfter,
220
+ opts: this.options.extraCSSRules,
221
+ callback: (className) => {
222
+ if (className) {
223
+ editor.chain().focus().setCSSClass(className).run();
224
+ }
225
+ },
226
+ });
227
+ },
228
+ };
229
+ },
230
+ });
@@ -0,0 +1,88 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @synced-from pie-lib/packages/editable-html-tip-tap/src/extensions/custom-toolbar-wrapper.jsx
4
+ * @auto-generated
5
+ *
6
+ * This file is automatically synced from pie-elements and converted to TypeScript.
7
+ * Manual edits will be overwritten on next sync.
8
+ * To make changes, edit the upstream JavaScript file and run sync again.
9
+ */
10
+
11
+ import React from 'react';
12
+ import IconButton from '@mui/material/IconButton';
13
+ import Delete from '@mui/icons-material/Delete';
14
+ import { PIE_TOOLBAR__CLASS } from '../constants.js';
15
+ import { styled } from '@mui/material/styles';
16
+ import { DoneButton } from '../components/common/done-button.js';
17
+
18
+ const StyledToolbar: any = styled('div', {
19
+ shouldForwardProp: (prop) => !['showDone', 'toolbarAlignment', 'isFocused', 'autoWidth', 'isHidden'].includes(prop),
20
+ })(({ showDone, toolbarAlignment, isFocused, autoWidth, isHidden }) => ({
21
+ position: 'absolute',
22
+ zIndex: 10,
23
+ cursor: 'pointer',
24
+ justifyContent: 'space-between',
25
+ background: 'var(--editable-html-toolbar-bg, #efefef)',
26
+ minWidth: showDone ? '280px' : '265px',
27
+ margin: '5px 0 0 0',
28
+ padding: '2px',
29
+ boxShadow:
30
+ '0px 1px 5px 0px rgba(0, 0, 0, 0.2), 0px 2px 2px 0px rgba(0, 0, 0, 0.14), 0px 3px 1px -2px rgba(0, 0, 0, 0.12)',
31
+ boxSizing: 'border-box',
32
+ display: 'flex',
33
+ opacity: 1,
34
+ ...(toolbarAlignment === 'right' && {
35
+ right: 0,
36
+ }),
37
+ ...(autoWidth
38
+ ? {
39
+ width: 'auto',
40
+ }
41
+ : {
42
+ width: '100%',
43
+ }),
44
+ ...(isHidden && {
45
+ visibility: 'hidden',
46
+ }),
47
+ }));
48
+
49
+ const StyledIconButton: any = styled(IconButton)({
50
+ width: '28px',
51
+ height: '28px',
52
+ padding: '4px',
53
+ verticalAlign: 'top',
54
+ });
55
+
56
+ const SharedContainer: any = styled('div')({
57
+ display: 'flex',
58
+ });
59
+
60
+ function CustomToolbarWrapper(props) {
61
+ const { children, deletable, toolbarOpts, autoWidth, isFocused, doneButtonRef, onDelete, showDone, onDone } = props;
62
+ const customStyles = toolbarOpts.minWidth !== undefined ? { minWidth: toolbarOpts.minWidth } : {};
63
+
64
+ return (
65
+ <StyledToolbar
66
+ className={PIE_TOOLBAR__CLASS}
67
+ showDone={showDone}
68
+ toolbarAlignment={toolbarOpts.alignment}
69
+ isFocused={toolbarOpts.alwaysVisible || isFocused}
70
+ autoWidth={autoWidth}
71
+ isHidden={toolbarOpts.isHidden === true}
72
+ style={{ ...customStyles }}
73
+ >
74
+ {children}
75
+
76
+ <SharedContainer>
77
+ {deletable && (
78
+ <StyledIconButton aria-label="Delete" onMouseDown={(e) => onDelete?.(e)}>
79
+ <Delete />
80
+ </StyledIconButton>
81
+ )}
82
+ {showDone && <DoneButton doneButtonRef={doneButtonRef} onClick={onDone} />}
83
+ </SharedContainer>
84
+ </StyledToolbar>
85
+ );
86
+ }
87
+
88
+ export default CustomToolbarWrapper;
@@ -0,0 +1,46 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @synced-from pie-lib/packages/editable-html-tip-tap/src/extensions/div-node.js
4
+ * @auto-generated
5
+ *
6
+ * This file is automatically synced from pie-elements and converted to TypeScript.
7
+ * Manual edits will be overwritten on next sync.
8
+ * To make changes, edit the upstream JavaScript file and run sync again.
9
+ */
10
+
11
+ // DivNode.ts
12
+ import { Node } from '@tiptap/core';
13
+
14
+ export const DivNode = Node.create({
15
+ name: 'div',
16
+ group: 'block',
17
+ content: 'inline*',
18
+
19
+ parseHTML() {
20
+ return [{ tag: 'div' }];
21
+ },
22
+
23
+ renderHTML({ HTMLAttributes }) {
24
+ return ['div', HTMLAttributes, 0];
25
+ },
26
+
27
+ addKeyboardShortcuts() {
28
+ return {
29
+ Enter: () => {
30
+ const { state } = this.editor;
31
+ const { $from } = state.selection;
32
+
33
+ if ($from.parent.type.name !== 'div') {
34
+ return false;
35
+ }
36
+
37
+ return this.editor
38
+ .chain()
39
+ .focus()
40
+ .setNode('paragraph') // current div becomes <p>
41
+ .splitBlock() // create another <p>
42
+ .run();
43
+ },
44
+ };
45
+ },
46
+ });
@@ -0,0 +1,34 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @synced-from pie-lib/packages/editable-html-tip-tap/src/extensions/extended-table.js
4
+ * @auto-generated
5
+ *
6
+ * This file is automatically synced from pie-elements and converted to TypeScript.
7
+ * Manual edits will be overwritten on next sync.
8
+ * To make changes, edit the upstream JavaScript file and run sync again.
9
+ */
10
+
11
+ import { Table } from '@tiptap/extension-table';
12
+
13
+ const ExtendedTable = Table.extend({
14
+ addAttributes() {
15
+ return {
16
+ border: { default: '1' },
17
+ };
18
+ },
19
+ renderHTML(props) {
20
+ const originalTable = this.parent(props);
21
+ const { border } = props.HTMLAttributes;
22
+
23
+ const previousStyle = `${originalTable[1].style}${originalTable[1].style.match(/.*; */) ? '' : ';'}`;
24
+
25
+ originalTable[1].style = `${previousStyle}
26
+ color: var(--pie-text, black);
27
+ background-color: var(--pie-background, rgba(255, 255, 255))`;
28
+ originalTable[1].border = border ? border : '1';
29
+
30
+ return originalTable;
31
+ },
32
+ });
33
+
34
+ export default ExtendedTable;