11import React , {
2- useContext ,
32 useEffect ,
43 useRef ,
54 useState
@@ -11,8 +10,6 @@ import parse, { attributesToProps, domToReact } from 'html-react-parser';
1110import { throttle } from 'lodash' ;
1211import axios from 'axios' ;
1312import Handlebars from 'handlebars' ;
14- import { getFragmentsFromLocalStorage } from '../utils/fragment-tools' ;
15- import { GlobalStateContext } from '../context' ;
1613import { getAllFragmentStyleClasses , styleObjectToString } from '@carbon-builder/player-react' ;
1714import {
1815 AComponent ,
@@ -23,9 +20,8 @@ import {
2320 stateWithoutComponent ,
2421 updateComponentCounter ,
2522 updatedState
26- } from '@carbon-builder/sdk-react ' ;
23+ } from '../../index ' ;
2724import './fragment-preview.scss' ;
28- import { useRemoteCustomComponentsCollections } from '../utils/misc-tools' ;
2925
3026const canvas = css `
3127 border : 2px solid # d8d8d8 ;
@@ -101,12 +97,18 @@ const fetchCSS = async (urls: string[]) => {
10197 }
10298} ;
10399
104- export const Fragment = ( { fragment, setFragment, outline } : any ) => {
105- const globalState = useContext ( GlobalStateContext ) ;
100+ export const Fragment = ( {
101+ fragment,
102+ setFragment,
103+ fragments,
104+ outline,
105+ remoteCustomComponentsCollections,
106+ customComponentsCollections,
107+ styleClasses
108+ } : any ) => {
106109 const [ showDragOverIndicator , setShowDragOverIndicator ] = useState ( false ) ;
107110 const [ customComponentsStyles , setCustomComponentsStyles ] = useState ( css `` ) ;
108111 const [ customComponentsStylesUrls , _setCustomComponentsStylesUrls ] = useState < string [ ] > ( [ ] ) ;
109- const [ remoteCustomComponentsCollections ] = useRemoteCustomComponentsCollections ( ) ;
110112 const [ allCustomComponentsCollections , setAllCustomComponentsCollections ] = useState ( [ ] as any [ ] ) ;
111113 const containerRef = useRef ( null as any ) ;
112114 const holderRef = useRef ( null as any ) ;
@@ -139,9 +141,9 @@ export const Fragment = ({ fragment, setFragment, outline }: any) => {
139141 useEffect ( ( ) => {
140142 setAllCustomComponentsCollections ( [
141143 ...( remoteCustomComponentsCollections as any [ ] || [ ] ) . flat ( ) ,
142- ...globalState . customComponentsCollections
144+ ...customComponentsCollections
143145 ] ) ;
144- } , [ remoteCustomComponentsCollections , globalState . customComponentsCollections ] ) ;
146+ } , [ remoteCustomComponentsCollections , customComponentsCollections ] ) ;
145147
146148 const resize = throttle ( ( e : any ) => {
147149 const rect = containerRef . current . getBoundingClientRect ( ) ;
@@ -167,10 +169,6 @@ export const Fragment = ({ fragment, setFragment, outline }: any) => {
167169 return < SkeletonPlaceholder /> ;
168170 }
169171
170- // try to use the state but get the fragments from local storage if state is not available
171- // localStorage info is used when rendering and can't be used for interaction
172- const { fragments } = globalState || { fragments : getFragmentsFromLocalStorage ( ) } ;
173-
174172 // initialize component counter
175173 updateComponentCounter ( fragment . data ) ;
176174
@@ -365,7 +363,7 @@ export const Fragment = ({ fragment, setFragment, outline }: any) => {
365363 return null ;
366364 } ;
367365
368- const styles = css `${ getAllFragmentStyleClasses ( fragment , fragments , globalState ?. styleClasses ) . map ( ( styleClass : any ) => `.${ styleClass . id } {
366+ const styles = css `${ getAllFragmentStyleClasses ( fragment , fragments , styleClasses ) . map ( ( styleClass : any ) => `.${ styleClass . id } {
369367 ${ styleClass . content }
370368 }` )
371369 } `;
0 commit comments