File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -233,6 +233,7 @@ function App() {
233233 ref . current
234234 ?. getHTML ( )
235235 . then ( ( html ) => {
236+ console . log ( 'getHtml' , html ) ;
236237 setEnrichedTextValue ( html ) ;
237238 } )
238239 . catch ( ( error : unknown ) => {
Original file line number Diff line number Diff line change 251251 flex-shrink : 0 ;
252252 accent-color : var (--et-checkbox-box-color , # 0000ff );
253253}
254+
255+ .et-view ul [data-type = "checkbox" ] {
256+ margin : 0 ;
257+ list-style : none;
258+ padding : 0 ;
259+ padding-left : calc (
260+ var (--et-checkbox-margin-left , 16px ) + var (--et-checkbox-gap-width , 16px )
261+ );
262+ }
263+
264+ .et-view ul [data-type = "checkbox" ] > li {
265+ position : relative;
266+ list-style : none;
267+ pointer-events : none;
268+ }
269+
270+ .et-view ul [data-type = "checkbox" ] > li > p {
271+ display : inline-flex;
272+ align-items : center;
273+ gap : 0 ;
274+ margin : 0 ;
275+ padding : 0 ;
276+ user-select : none;
277+ }
278+
279+ .et-view ul [data-type = "checkbox" ] > li > input [type = 'checkbox' ] {
280+ position : absolute;
281+ left : calc (
282+ -1 * var (--et-checkbox-gap-width , 16px ) - var (--et-checkbox-box-size , 24px )
283+ );
284+ width : var (--et-checkbox-box-size , 24px );
285+ height : var (--et-checkbox-box-size , 24px );
286+ margin : 0 var (--et-checkbox-gap-width , 16px ) 0 0 ;
287+ flex-shrink : 0 ;
288+ accent-color : var (--et-checkbox-box-color , # 0000ff );
289+ }
290+
291+ .et-view ul [data-type = "checkbox" ] > li > label {
292+ display : inline-flex;
293+ align-items : center;
294+ gap : 0 ;
295+ margin : 0 ;
296+ padding : 0 ;
297+ user-select : none;
298+ }
Original file line number Diff line number Diff line change @@ -6,13 +6,16 @@ import { htmlStyleToCSSVariables } from './styleConversion/htmlStyleToCSSVariabl
66import { ENRICHED_TEXT_CLASSNAME } from './consts/classNames' ;
77import { enrichedInputThemingToCSSProperties } from './styleConversion/enrichedInputThemingToCSSProperties' ;
88import { buildMentionRulesCSS } from './styleConversion/buildMentionRulesCSS' ;
9+ import { checkboxHtmlToWeb } from './checkboxHtmlToWeb' ;
910
1011export const EnrichedText = ( {
1112 children,
1213 htmlStyle,
1314 style,
1415 selectionColor,
1516} : EnrichedTextProps ) => {
17+ const html = useMemo ( ( ) => checkboxHtmlToWeb ( children ) , [ children ] ) ;
18+
1619 const textStyle : CSSProperties = useMemo (
1720 ( ) => enrichedTextStyleToCSSProperties ( style ?? { } ) ,
1821 [ style ]
@@ -44,7 +47,7 @@ export const EnrichedText = ({
4447 < div
4548 style = { finalStyle }
4649 className = { ENRICHED_TEXT_CLASSNAME }
47- dangerouslySetInnerHTML = { { __html : children } }
50+ dangerouslySetInnerHTML = { { __html : html } }
4851 />
4952 </ >
5053 ) ;
Original file line number Diff line number Diff line change 1+ /*
2+ * Native checkbox format (as produced by the editor):
3+ * <ul data-type="checkbox">
4+ * <li checked>foo</li>
5+ * <li>bar</li>
6+ * </ul>
7+ *
8+ * Web-native, display-only format:
9+ * <ul data-type="checkbox">
10+ * <li>
11+ * <input type="checkbox" id="…" checked>
12+ * <label for="…">foo</label>
13+ * </li>
14+ * <li>
15+ * <input type="checkbox" id="…">
16+ * <label for="…">bar</label>
17+ * </li>
18+ * </ul>
19+ */
20+ export function checkboxHtmlToWeb ( html : string ) : string {
21+ const parser = new DOMParser ( ) ;
22+ const doc = parser . parseFromString ( html , 'text/html' ) ;
23+
24+ let idCounter = 0 ;
25+
26+ doc . querySelectorAll ( 'ul[data-type="checkbox"]' ) . forEach ( ( ul ) => {
27+ ul . querySelectorAll ( 'li' ) . forEach ( ( li ) => {
28+ const checked = li . hasAttribute ( 'checked' ) ;
29+ const id = `enriched-checkbox-${ idCounter ++ } ` ;
30+ const labelContent = li . innerHTML ;
31+
32+ li . removeAttribute ( 'checked' ) ;
33+ li . innerHTML =
34+ `<input type="checkbox" id="${ id } "${ checked ? ' checked' : '' } >` +
35+ `<label for="${ id } ">${ labelContent } </label>` ;
36+ } ) ;
37+ } ) ;
38+
39+ return doc . body . innerHTML ;
40+ }
You can’t perform that action at this time.
0 commit comments