Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added richtext support for pagevariables #3392

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 43 additions & 19 deletions src/components/richTextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,32 @@
floatLabel,
} = options;
const isDev = env === 'dev';

const [currentValue, setCurrentValue] = useState(
useText(valueProp, { rawValue: true }),
);
const optionValue = useText(valueProp, { rawValue: true });
const [currentValue, setCurrentValue] = useState(optionValue);
const [valueKey, setValueKey] = useState(0);
const labelText = useText(label);
const [showDropdown, setShowDropdown] = useState(false);
const [multipleStyles, setMultipleStyles] = useState(false);
const [activeStyleName, setActiveStyleName] = useState('Body 1');
const placeholderText = useText(placeholder);
const helperTextResolved = useText(helperText);

useEffect(() => {
setCurrentValue(optionValue);
setValueKey(valueKey + 1);
}, [optionValue]);

const KeyCode = {
Digit1: 49,
Digit2: 50,
Digit3: 51,
Digit4: 52,
Digit5: 53,
Digit6: 54,
Digit7: 55,
Digit8: 56,
};

const isMarkActive = (editor, format) => {
const marks = Editor.marks(editor);
return marks ? marks[format] === true : false;
Expand Down Expand Up @@ -381,7 +397,18 @@
return <span {...attributes}>{children}</span>;
}

const checkMultipleStyles = (value) => {
const diverseStyle = value.filter(({ type }) => type !== value[0].type);
return diverseStyle.length > 0;
};

const onChangeHandler = (value) => {
if (value.length > 1) {
const hasMultipleStyles = checkMultipleStyles(value);
if (hasMultipleStyles) {
setMultipleStyles(true);
}
}
setCurrentValue(value.map((row) => serialize(row)).join(''));
B.triggerEvent('onChange', currentValue);
};
Expand Down Expand Up @@ -527,35 +554,32 @@

if (event.altKey) {
switch (event.keyCode) {
case 49:
case KeyCode.Digit1:
event.preventDefault();
toggleBlock(editor, 'heading-one');
break;
case 50:
case KeyCode.Digit2:
event.preventDefault();
toggleBlock(editor, 'heading-two');
break;
case 51:
case KeyCode.Digit3:
event.preventDefault();
toggleBlock(editor, 'heading-three');
break;
case 52:
case KeyCode.Digit4:
event.preventDefault();
toggleBlock(editor, 'heading-four');
break;
case 53:
case KeyCode.Digit5:
event.preventDefault();
toggleBlock(editor, 'heading-five');
break;
case 54:
case KeyCode.Digit6:
event.preventDefault();
toggleBlock(editor, 'heading-six');
break;
case 55:
event.preventDefault();
toggleBlock(editor, 'paragraph');
break;
case 56:
case KeyCode.Digit7:
case KeyCode.Digit8:
event.preventDefault();
toggleBlock(editor, 'paragraph');
break;
Expand Down Expand Up @@ -791,9 +815,6 @@
setAmountOfHeadersInSelection(Math.abs(anchor - focus) + 1);
}
}
} else {
setAmountOfHeadersInSelection(0);
setAmountOfHeadersInSelection(1);
}
}, 500);
}
Expand All @@ -813,6 +834,8 @@
activeStyleName !== '\u00A0'
) {
setActiveStyleName('\u00A0');
} else if (multipleStyles) {
setActiveStyleName('\u00A0');
}
return (
<li
Expand Down Expand Up @@ -909,6 +932,7 @@
)}
<div className={classes.editorWrapper}>
<Slate
key={valueKey}
editor={editor}
value={fragment}
onChange={(value) => {
Expand Down Expand Up @@ -1145,7 +1169,7 @@
},
dropdownButton: {
display: 'inline-flex',
maxWitdh: '100%',
maxWidth: '100%',
cursor: 'pointer',
backgroundColor: 'transparent',
padding: '4px',
Expand Down
Loading