@makeswift/runtime 0.5.5 → 0.6.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.
- package/dist/Box.cjs.js +11 -6
- package/dist/Box.cjs.js.map +1 -1
- package/dist/Box.es.js +12 -7
- package/dist/Box.es.js.map +1 -1
- package/dist/Button.cjs.js +2 -1
- package/dist/Button.cjs.js.map +1 -1
- package/dist/Button.es.js +2 -1
- package/dist/Button.es.js.map +1 -1
- package/dist/Carousel.cjs.js +2 -1
- package/dist/Carousel.cjs.js.map +1 -1
- package/dist/Carousel.es.js +2 -1
- package/dist/Carousel.es.js.map +1 -1
- package/dist/Countdown.cjs.js +2 -1
- package/dist/Countdown.cjs.js.map +1 -1
- package/dist/Countdown.es.js +2 -1
- package/dist/Countdown.es.js.map +1 -1
- package/dist/Divider.cjs.js +2 -1
- package/dist/Divider.cjs.js.map +1 -1
- package/dist/Divider.es.js +2 -1
- package/dist/Divider.es.js.map +1 -1
- package/dist/EditableText.cjs.js +359 -0
- package/dist/EditableText.cjs.js.map +1 -0
- package/dist/EditableText.es.js +352 -0
- package/dist/EditableText.es.js.map +1 -0
- package/dist/Embed.cjs.js +2 -1
- package/dist/Embed.cjs.js.map +1 -1
- package/dist/Embed.es.js +2 -1
- package/dist/Embed.es.js.map +1 -1
- package/dist/Form.cjs.js +2 -1
- package/dist/Form.cjs.js.map +1 -1
- package/dist/Form.es.js +2 -1
- package/dist/Form.es.js.map +1 -1
- package/dist/Image.cjs.js +2 -1
- package/dist/Image.cjs.js.map +1 -1
- package/dist/Image.es.js +2 -1
- package/dist/Image.es.js.map +1 -1
- package/dist/LiveProvider.cjs.js +3 -11
- package/dist/LiveProvider.cjs.js.map +1 -1
- package/dist/LiveProvider.es.js +6 -14
- package/dist/LiveProvider.es.js.map +1 -1
- package/dist/Navigation.cjs.js +2 -1
- package/dist/Navigation.cjs.js.map +1 -1
- package/dist/Navigation.es.js +2 -1
- package/dist/Navigation.es.js.map +1 -1
- package/dist/PreviewProvider.cjs.js +6 -3
- package/dist/PreviewProvider.cjs.js.map +1 -1
- package/dist/PreviewProvider.es.js +8 -5
- package/dist/PreviewProvider.es.js.map +1 -1
- package/dist/ReadOnlyText.cjs.js +206 -0
- package/dist/ReadOnlyText.cjs.js.map +1 -0
- package/dist/ReadOnlyText.es.js +204 -0
- package/dist/ReadOnlyText.es.js.map +1 -0
- package/dist/Root.cjs.js +4 -3
- package/dist/Root.cjs.js.map +1 -1
- package/dist/Root.es.js +3 -2
- package/dist/Root.es.js.map +1 -1
- package/dist/SocialLinks.cjs.js +2 -1
- package/dist/SocialLinks.cjs.js.map +1 -1
- package/dist/SocialLinks.es.js +2 -1
- package/dist/SocialLinks.es.js.map +1 -1
- package/dist/Text.cjs.js +26 -405
- package/dist/Text.cjs.js.map +1 -1
- package/dist/Text.es.js +23 -405
- package/dist/Text.es.js.map +1 -1
- package/dist/Video.cjs.js +2 -1
- package/dist/Video.cjs.js.map +1 -1
- package/dist/Video.es.js +2 -1
- package/dist/Video.es.js.map +1 -1
- package/dist/actions.cjs.js.map +1 -1
- package/dist/actions.es.js.map +1 -1
- package/dist/components.cjs.js +2 -5
- package/dist/components.cjs.js.map +1 -1
- package/dist/components.es.js +2 -5
- package/dist/components.es.js.map +1 -1
- package/dist/constants.cjs.js +45 -26
- package/dist/constants.cjs.js.map +1 -1
- package/dist/constants.es.js +36 -20
- package/dist/constants.es.js.map +1 -1
- package/dist/index.cjs.js +78 -310
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs2.js +20 -21
- package/dist/index.cjs2.js.map +1 -1
- package/dist/index.cjs5.js +141 -0
- package/dist/index.cjs5.js.map +1 -0
- package/dist/index.es.js +77 -308
- package/dist/index.es.js.map +1 -1
- package/dist/index.es2.js +23 -24
- package/dist/index.es2.js.map +1 -1
- package/dist/index.es3.js +1 -1
- package/dist/index.es5.js +139 -0
- package/dist/index.es5.js.map +1 -0
- package/dist/next.cjs.js +2 -1
- package/dist/next.cjs.js.map +1 -1
- package/dist/next.es.js +3 -2
- package/dist/next.es.js.map +1 -1
- package/dist/react.cjs.js +2 -1
- package/dist/react.cjs.js.map +1 -1
- package/dist/react.es.js +2 -1
- package/dist/react.es.js.map +1 -1
- package/dist/types/src/api/react.d.ts.map +1 -1
- package/dist/types/src/components/builtin/Box/Box.d.ts.map +1 -1
- package/dist/types/src/components/builtin/Box/animations.d.ts +1 -1
- package/dist/types/src/components/builtin/Box/animations.d.ts.map +1 -1
- package/dist/types/src/components/builtin/Form/components/Field/components/Checkbox/index.d.ts +1 -1
- package/dist/types/src/components/builtin/Text/EditableText.d.ts +16 -0
- package/dist/types/src/components/builtin/Text/EditableText.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/ReadOnlyText.d.ts +11 -0
- package/dist/types/src/components/builtin/Text/ReadOnlyText.d.ts.map +1 -0
- package/dist/types/src/components/builtin/Text/Text.d.ts +3 -7
- package/dist/types/src/components/builtin/Text/Text.d.ts.map +1 -1
- package/dist/types/src/components/builtin/register.d.ts.map +1 -1
- package/dist/types/src/components/shared/BackgroundsContainer/index.d.ts.map +1 -1
- package/dist/types/src/next/document.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/components/LiveProvider.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/element-imperative-handle.d.ts +12 -0
- package/dist/types/src/runtimes/react/element-imperative-handle.d.ts.map +1 -0
- package/dist/types/src/runtimes/react/find-dom-node.d.ts +1 -1
- package/dist/types/src/runtimes/react/find-dom-node.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/index.d.ts +4 -2
- package/dist/types/src/runtimes/react/index.d.ts.map +1 -1
- package/dist/types/src/state/actions.d.ts +4 -3
- package/dist/types/src/state/actions.d.ts.map +1 -1
- package/dist/types/src/state/modules/is-preview.d.ts +6 -0
- package/dist/types/src/state/modules/is-preview.d.ts.map +1 -0
- package/dist/types/src/state/react-builder-preview.d.ts +1 -0
- package/dist/types/src/state/react-builder-preview.d.ts.map +1 -1
- package/dist/types/src/state/react-page.d.ts +2 -0
- package/dist/types/src/state/react-page.d.ts.map +1 -1
- package/package.json +4 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PreviewProvider.es.js","sources":["../src/state/modules/read-write-documents.ts","../src/state/react-builder-preview.ts","../src/runtimes/react/components/PreviewProvider.tsx"],"sourcesContent":["import { Operation } from 'ot-json0'\nimport { removeIn, setIn } from 'immutable'\n\nimport * as ReadOnlyDocuments from './read-only-documents'\nimport { Action, ActionTypes } from '../actions'\n\nexport type { Document, Element, ElementData, ElementReference } from './read-only-documents'\nexport { isElementReference } from './read-only-documents'\nexport type { Operation }\n\nfunction apply(data: ReadOnlyDocuments.Element, operation: Operation): ReadOnlyDocuments.Element {\n let applied = data\n\n operation.forEach(component => {\n // @ts-expect-error: `ld` isn't in all possible values of `component`\n if (component.ld != null) applied = removeIn(applied, component.p)\n\n // @ts-expect-error: `od` isn't in all possible values of `component`\n if (component.od != null) applied = removeIn(applied, component.p)\n\n // @ts-expect-error: `li` isn't in all possible values of `component`\n if (component.li != null) applied = setIn(applied, component.p, component.li)\n\n // @ts-expect-error: `oi` isn't in all possible values of `component`\n if (component.oi != null) applied = setIn(applied, component.p, component.oi)\n })\n\n return applied\n}\n\nexport type State = ReadOnlyDocuments.State\n\nexport function getInitialState({\n rootElements,\n}: {\n rootElements?: Map<string, ReadOnlyDocuments.Element>\n} = {}): State {\n return ReadOnlyDocuments.getInitialState({ rootElements })\n}\n\nfunction getReadOnlyDocumentsStateSlice(state: State): ReadOnlyDocuments.State {\n return state\n}\n\nexport function getDocument(state: State, documentKey: string): ReadOnlyDocuments.Document | null {\n return ReadOnlyDocuments.getDocument(getReadOnlyDocumentsStateSlice(state), documentKey)\n}\n\nexport function reducer(state: State = getInitialState(), action: Action): State {\n const nextState = ReadOnlyDocuments.reducer(state, action)\n\n switch (action.type) {\n case ActionTypes.CHANGE_DOCUMENT: {\n const currentRootElement = getDocument(nextState, action.payload.documentKey)?.rootElement\n\n if (currentRootElement == null) return nextState\n\n const nextRootElement = apply(currentRootElement, action.payload.operation)\n\n return currentRootElement === nextRootElement\n ? nextState\n : new Map(nextState).set(\n action.payload.documentKey,\n ReadOnlyDocuments.createDocument(action.payload.documentKey, nextRootElement),\n )\n }\n\n default:\n return nextState\n }\n}\n","import {\n applyMiddleware,\n combineReducers,\n createStore,\n Dispatch as ReduxDispatch,\n Middleware,\n MiddlewareAPI,\n PreloadedState,\n Store as ReduxStore,\n} from 'redux'\nimport thunk, { ThunkAction, ThunkDispatch } from 'redux-thunk'\nimport deepEqual from '../utils/deepEqual'\n\nimport * as Documents from './modules/read-write-documents'\nimport * as ReactComponents from './modules/react-components'\nimport * as BoxModels from './modules/box-models'\nimport * as ComponentsMeta from './modules/components-meta'\nimport * as PropControllers from './modules/prop-controllers'\nimport * as PropControllerHandles from './modules/prop-controller-handles'\nimport * as IsInBuilder from './modules/is-in-builder'\nimport * as ReactPage from './react-page'\nimport {\n Action,\n changeDocumentElementSize,\n changeElementBoxModels,\n messageBuilderPropController,\n registerBuilderComponent,\n registerMeasurable,\n registerPropControllers,\n registerPropControllersHandle,\n registerDocument,\n registerComponentHandle,\n unregisterBuilderComponent,\n unregisterMeasurable,\n unregisterPropControllers,\n setIsInBuilder,\n handleWheel,\n handlePointerMove,\n} from './actions'\nimport { ActionTypes } from './actions'\nimport { createPropController, PropController } from '../prop-controllers/instances'\nimport { serializeControls } from '../builder'\nimport { MakeswiftClient } from '../api/react'\n\nexport type { Operation } from './modules/read-write-documents'\nexport type { BoxModelHandle } from './modules/box-models'\nexport { createBox, getBox, parse } from './modules/box-models'\n\nconst reducer = combineReducers({\n documents: Documents.reducer,\n reactComponents: ReactComponents.reducer,\n boxModels: BoxModels.reducer,\n componentsMeta: ComponentsMeta.reducer,\n propControllers: PropControllers.reducer,\n propControllerHandles: PropControllerHandles.reducer,\n isInBuilder: IsInBuilder.reducer,\n})\n\nexport type State = ReturnType<typeof reducer>\n\nfunction getBoxModelsStateSlice(state: State): BoxModels.State {\n return state.boxModels\n}\n\nfunction getMeasurables(state: State): Map<string, Map<string, BoxModels.Measurable>> {\n return BoxModels.getMeasurables(getBoxModelsStateSlice(state))\n}\n\nfunction getBoxModels(state: State): Map<string, Map<string, BoxModels.BoxModel>> {\n return BoxModels.getBoxModels(getBoxModelsStateSlice(state))\n}\n\nfunction getBoxModel(\n state: State,\n documentKey: string,\n elementKey: string,\n): BoxModels.BoxModel | null {\n return BoxModels.getBoxModel(getBoxModelsStateSlice(state), documentKey, elementKey)\n}\n\nfunction getComponentsMetaStateSlice(state: State): ComponentsMeta.State {\n return state.componentsMeta\n}\n\nfunction getComponentsMeta(state: State): Map<string, ComponentsMeta.ComponentMeta> {\n return ComponentsMeta.getComponentsMeta(getComponentsMetaStateSlice(state))\n}\n\nfunction getPropControllersStateSlice(state: State): PropControllers.State {\n return state.propControllers\n}\n\nfunction getComponentPropControllerDescriptors(\n state: State,\n componentType: string,\n): Record<string, PropControllers.PropControllerDescriptor> | null {\n return PropControllers.getComponentPropControllerDescriptors(\n getPropControllersStateSlice(state),\n componentType,\n )\n}\n\nfunction getPropControllerHandlesStateSlice(state: State): PropControllerHandles.State {\n return state.propControllerHandles\n}\n\nfunction measureElements(): ThunkAction<void, State, unknown, Action> {\n return (dispatch, getState) => {\n const measurables = getMeasurables(getState())\n const currentBoxModels = getBoxModels(getState())\n const measuredBoxModels = new Map<string, Map<string, BoxModels.BoxModel>>()\n\n measurables.forEach((documentMeasurables, documentKey) => {\n const measuredDocumentBoxModels = new Map<string, BoxModels.BoxModel>()\n\n documentMeasurables.forEach((measurable, elementKey) => {\n const boxModel = BoxModels.measure(measurable)\n\n if (boxModel != null) measuredDocumentBoxModels.set(elementKey, boxModel)\n })\n\n if (measuredDocumentBoxModels.size > 0) {\n measuredBoxModels.set(documentKey, measuredDocumentBoxModels)\n }\n })\n\n const changedBoxModels = new Map<string, Map<string, BoxModels.BoxModel | null>>()\n\n currentBoxModels.forEach((currentDocumentBoxModels, documentKey) => {\n const changedDocumentBoxModels = new Map<string, BoxModels.BoxModel | null>()\n\n currentDocumentBoxModels.forEach((_boxModel, elementKey) => {\n if (!measuredBoxModels.get(documentKey)?.has(elementKey)) {\n changedDocumentBoxModels.set(elementKey, null)\n }\n\n if (changedDocumentBoxModels.size > 0) {\n changedBoxModels.set(documentKey, changedDocumentBoxModels)\n }\n })\n })\n\n measuredBoxModels.forEach((measuredDocumentBoxModels, documentKey) => {\n const changedDocumentBoxModels = new Map<string, BoxModels.BoxModel | null>()\n\n measuredDocumentBoxModels.forEach((measuredBoxModel, elementKey) => {\n const currentBoxModel = getBoxModel(getState(), documentKey, elementKey)\n\n if (currentBoxModel == null || !deepEqual(currentBoxModel, measuredBoxModel)) {\n changedDocumentBoxModels.set(elementKey, measuredBoxModel)\n }\n })\n\n if (changedDocumentBoxModels.size > 0) {\n changedBoxModels.set(documentKey, changedDocumentBoxModels)\n }\n })\n\n if (changedBoxModels.size > 0) dispatch(changeElementBoxModels(changedBoxModels))\n }\n}\n\nexport function startMeasuringElements(): ThunkAction<() => void, State, unknown, Action> {\n return dispatch => {\n let animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n\n return () => {\n cancelAnimationFrame(animationFrameHandle)\n }\n\n function handleAnimationFrameRequest() {\n dispatch(measureElements())\n\n animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n }\n }\n}\n\nexport type Size = {\n offsetWidth: number\n offsetHeight: number\n clientWidth: number\n clientHeight: number\n scrollWidth: number\n scrollHeight: number\n scrollTop: number\n scrollLeft: number\n}\n\nfunction getElementSize(element: HTMLElement): Size {\n return {\n offsetWidth: element.offsetWidth,\n offsetHeight: element.offsetHeight,\n clientWidth: element.clientWidth,\n clientHeight: element.clientHeight,\n scrollWidth: element.scrollWidth,\n scrollHeight: element.scrollHeight,\n scrollTop: element.scrollTop,\n scrollLeft: element.scrollLeft,\n }\n}\n\nfunction lockDocumentScroll(): ThunkAction<() => void, State, unknown, Action> {\n return dispatch => {\n const lastDocumentOverflow = window.document.documentElement.style.overflow\n window.document.documentElement.style.overflow = 'hidden'\n\n window.document.documentElement.addEventListener('wheel', handleWheelEvent)\n\n return () => {\n window.document.documentElement.style.overflow = lastDocumentOverflow\n window.document.documentElement.removeEventListener('wheel', handleWheelEvent)\n }\n\n function handleWheelEvent({ deltaX, deltaY }: WheelEvent) {\n dispatch(handleWheel({ deltaX, deltaY }))\n }\n }\n}\n\nfunction startHandlingPointerMoveEvent(): ThunkAction<() => void, State, unknown, Action> {\n return dispatch => {\n window.document.documentElement.addEventListener('pointermove', handlePointerMoveEvent)\n\n return () => {\n window.document.documentElement.removeEventListener('pointermove', handlePointerMoveEvent)\n }\n\n function handlePointerMoveEvent({ clientX, clientY }: PointerEvent) {\n dispatch(handlePointerMove({ clientX, clientY }))\n }\n }\n}\n\nfunction startHandlingFocusEvents(): () => void {\n window.addEventListener('focusin', handleFocusIn)\n window.addEventListener('focusout', handleFocusOut)\n\n return () => {\n window.removeEventListener('focusin', handleFocusIn)\n window.removeEventListener('focusout', handleFocusOut)\n }\n\n function handleFocusIn(event: FocusEvent) {\n if (!(event.target instanceof window.HTMLElement) || !event.target.isContentEditable) {\n window.parent.focus()\n }\n }\n\n function handleFocusOut(event: FocusEvent) {\n if (\n !(event.relatedTarget instanceof window.HTMLElement) ||\n !event.relatedTarget.isContentEditable\n ) {\n window.parent.focus()\n }\n }\n}\n\nfunction startMeasuringDocumentElement(): ThunkAction<() => void, unknown, unknown, Action> {\n return dispatch => {\n let animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n let lastSize: Size\n\n return () => {\n cancelAnimationFrame(animationFrameHandle)\n }\n\n function handleAnimationFrameRequest() {\n const nextSize = getElementSize(window.document.documentElement)\n\n if (!deepEqual(lastSize, nextSize)) {\n lastSize = nextSize\n\n dispatch(changeDocumentElementSize(nextSize))\n }\n\n animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n }\n }\n}\n\nexport function initialize(): ThunkAction<() => void, State, unknown, Action> {\n return dispatch => {\n const stopMeasuringElements = dispatch(startMeasuringElements())\n const stopMeasuringDocumentElement = dispatch(startMeasuringDocumentElement())\n const stopHandlingFocusEvent = startHandlingFocusEvents()\n const unlockDocumentScroll = dispatch(lockDocumentScroll())\n const stopHandlingPointerMoveEvent = dispatch(startHandlingPointerMoveEvent())\n dispatch(setIsInBuilder(true))\n\n return () => {\n stopMeasuringElements()\n stopMeasuringDocumentElement()\n stopHandlingFocusEvent()\n unlockDocumentScroll()\n stopHandlingPointerMoveEvent()\n dispatch(setIsInBuilder(false))\n }\n }\n}\n\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\n\nfunction measureBoxModelsMiddleware(): Middleware<Dispatch, State, Dispatch> {\n return ({ dispatch }: MiddlewareAPI<Dispatch>) =>\n (next: ReduxDispatch<Action>) => {\n return (action: Action): Action => {\n switch (action.type) {\n case ActionTypes.REGISTER_COMPONENT_HANDLE: {\n if (BoxModels.isMeasurable(action.payload.componentHandle)) {\n dispatch(\n registerMeasurable(\n action.payload.documentKey,\n action.payload.elementKey,\n action.payload.componentHandle,\n ),\n )\n }\n\n break\n }\n\n case ActionTypes.UNREGISTER_COMPONENT_HANDLE:\n dispatch(unregisterMeasurable(action.payload.documentKey, action.payload.elementKey))\n break\n }\n\n return next(action)\n }\n }\n}\n\nexport function messageChannelMiddleware(): Middleware<Dispatch, State, Dispatch> {\n return ({ dispatch, getState }: MiddlewareAPI<Dispatch, State>) =>\n (next: ReduxDispatch<Action>) => {\n let cleanUp = () => {}\n\n if (typeof window === 'undefined') return cleanUp\n\n const messageChannel = new window.MessageChannel()\n\n window.parent.postMessage(messageChannel.port2, '*', [messageChannel.port2])\n\n messageChannel.port1.onmessage = (event: MessageEvent<Action>) => dispatch(event.data)\n\n const state = getState()\n const registeredComponentsMeta = getComponentsMeta(state)\n\n registeredComponentsMeta.forEach((componentMeta, componentType) => {\n const propControllerDescriptors = getComponentPropControllerDescriptors(\n state,\n componentType,\n )\n\n if (propControllerDescriptors != null) {\n const [serializedControls, transferables] = serializeControls(propControllerDescriptors)\n\n messageChannel.port1.postMessage(\n registerBuilderComponent(componentType, componentMeta, serializedControls),\n transferables,\n )\n }\n })\n\n return (action: Action): Action => {\n switch (action.type) {\n case ActionTypes.CHANGE_ELEMENT_BOX_MODELS:\n case ActionTypes.MOUNT_COMPONENT:\n case ActionTypes.UNMOUNT_COMPONENT:\n case ActionTypes.CHANGE_DOCUMENT_ELEMENT_SIZE:\n case ActionTypes.MESSAGE_BUILDER_PROP_CONTROLLER:\n case ActionTypes.HANDLE_WHEEL:\n case ActionTypes.HANDLE_POINTER_MOVE:\n messageChannel.port1.postMessage(action)\n break\n\n case ActionTypes.REGISTER_COMPONENT: {\n const { type, meta, propControllerDescriptors } = action.payload\n const [serializedControls, transferables] = serializeControls(propControllerDescriptors)\n\n messageChannel.port1.postMessage(\n registerBuilderComponent(type, meta, serializedControls),\n transferables,\n )\n break\n }\n\n case ActionTypes.UNREGISTER_COMPONENT:\n messageChannel.port1.postMessage(unregisterBuilderComponent(action.payload.type))\n break\n\n case ActionTypes.CHANGE_DOCUMENT_ELEMENT_SCROLL_TOP:\n window.document.documentElement.scrollTop = action.payload.scrollTop\n break\n\n case ActionTypes.SCROLL_DOCUMENT_ELEMENT:\n window.document.documentElement.scrollTop += action.payload.scrollTopDelta\n break\n\n case ActionTypes.INIT:\n cleanUp = dispatch(initialize())\n break\n\n case ActionTypes.CLEAN_UP:\n cleanUp()\n break\n }\n\n return next(action)\n }\n }\n}\n\nfunction createAndRegisterPropControllers(\n documentKey: string,\n elementKey: string,\n): ThunkAction<Record<string, PropController> | null, State, unknown, Action> {\n return (dispatch, getState) => {\n const descriptors = ReactPage.getElementPropControllerDescriptors(\n getState(),\n documentKey,\n elementKey,\n )\n\n if (descriptors == null) return null\n\n const propControllers = Object.entries(descriptors).reduce((acc, [propName, descriptor]) => {\n const propController = createPropController(descriptor, message =>\n dispatch(messageBuilderPropController(documentKey, elementKey, propName, message)),\n ) as PropController\n\n return { ...acc, [propName]: propController }\n }, {} as Record<string, PropController>)\n\n dispatch(registerPropControllers(documentKey, elementKey, propControllers))\n\n return propControllers\n }\n}\n\nfunction propControllerHandlesMiddleware(): Middleware<Dispatch, State, Dispatch> {\n return ({ dispatch, getState }: MiddlewareAPI<Dispatch, State>) =>\n (next: ReduxDispatch<Action>) => {\n return (action: Action): Action => {\n switch (action.type) {\n case ActionTypes.REGISTER_COMPONENT_HANDLE: {\n const { documentKey, elementKey, componentHandle } = action.payload\n const element = ReactPage.getElement(getState(), documentKey, elementKey)\n const propControllers = dispatch(\n createAndRegisterPropControllers(documentKey, elementKey),\n )\n\n if (\n element != null &&\n !ReactPage.isElementReference(element) &&\n PropControllerHandles.isPropControllersHandle(componentHandle)\n ) {\n dispatch(registerPropControllersHandle(documentKey, elementKey, componentHandle))\n componentHandle.setPropControllers(propControllers)\n }\n\n break\n }\n\n case ActionTypes.UNREGISTER_COMPONENT_HANDLE: {\n const { documentKey, elementKey } = action.payload\n const handle = PropControllerHandles.getPropControllersHandle(\n getPropControllerHandlesStateSlice(getState()),\n documentKey,\n elementKey,\n )\n\n handle?.setPropControllers(null)\n\n dispatch(unregisterPropControllers(documentKey, elementKey))\n\n break\n }\n\n case ActionTypes.MESSAGE_HOST_PROP_CONTROLLER: {\n const propController = PropControllerHandles.getPropController(\n getPropControllerHandlesStateSlice(getState()),\n action.payload.documentKey,\n action.payload.elementKey,\n action.payload.propName,\n )\n\n if (propController) propController.recv(action.payload.message)\n }\n }\n\n return next(action)\n }\n }\n}\n\nif (import.meta.vitest) {\n const { describe, it, fn, expect } = import.meta.vitest\n\n describe('propControllerHandlesMiddleware', () => {\n it('registers prop controllers for element data', () => {\n // Arrange\n const documentKey = 'documentKey'\n const element: ReactPage.Element = { key: 'elementKey', type: 'type', props: {} }\n const store = createStore(reducer, applyMiddleware(thunk, propControllerHandlesMiddleware()))\n const handle = { setPropControllers: fn() }\n\n store.dispatch(registerDocument(ReactPage.createDocument(documentKey, element)))\n\n // Act\n store.dispatch(registerComponentHandle(documentKey, element.key, handle))\n\n // Assert\n expect(handle.setPropControllers).toHaveBeenCalled()\n })\n\n it(\"doesn't register prop controllers for element references\", () => {\n // Arrange\n const documentKey = 'documentKey'\n const element: ReactPage.Element = { type: 'reference', key: 'elementKey', value: 'value' }\n const store = createStore(reducer, applyMiddleware(thunk, propControllerHandlesMiddleware()))\n const handle = { setPropControllers: fn() }\n\n store.dispatch(registerDocument(ReactPage.createDocument(documentKey, element)))\n\n // Act\n store.dispatch(registerComponentHandle(documentKey, element.key, handle))\n\n // Assert\n expect(handle.setPropControllers).not.toHaveBeenCalled()\n })\n })\n}\n\nfunction makeswiftApiClientSyncMiddleware(\n client: MakeswiftClient,\n): Middleware<Dispatch, State, Dispatch> {\n return () => (next: ReduxDispatch<Action>) => {\n return (action: Action): Action => {\n client.makeswiftApiClient.dispatch(action)\n\n return next(action)\n }\n }\n}\n\nexport type Store = ReduxStore<State, Action> & { dispatch: Dispatch }\n\nexport function configureStore({\n rootElements,\n preloadedState,\n client,\n}: {\n rootElements?: Map<string, Documents.Element>\n preloadedState?: PreloadedState<State>\n client: MakeswiftClient\n}): Store {\n const initialState: PreloadedState<State> = {\n ...preloadedState,\n documents: Documents.getInitialState({ rootElements }),\n }\n\n return createStore(\n reducer,\n initialState,\n applyMiddleware(\n thunk,\n measureBoxModelsMiddleware(),\n messageChannelMiddleware(),\n propControllerHandlesMiddleware(),\n makeswiftApiClientSyncMiddleware(client),\n ),\n )\n}\n","import { ReactNode, useEffect, useMemo } from 'react'\n\nimport { StoreContext, storeContextDefaultValue } from '..'\nimport * as ReactBuilderPreview from '../../../state/react-builder-preview'\nimport * as ReactPage from '../../../state/react-page'\nimport { MakeswiftProvider, MakeswiftClient } from '../../../api/react'\nimport { registerDocumentEffect } from '../../../state/actions'\n\ntype Props = {\n client: MakeswiftClient\n rootElements?: Map<string, ReactPage.Element>\n children?: ReactNode\n}\n\nexport default function PreviewProvider({ client, children, rootElements }: Props): JSX.Element {\n const store = useMemo(\n () =>\n ReactBuilderPreview.configureStore({\n preloadedState: storeContextDefaultValue.getState(),\n rootElements,\n client,\n }),\n [client, rootElements],\n )\n\n useEffect(() => {\n const unregisterDocuments = Array.from(rootElements?.entries() ?? []).map(\n ([documentKey, rootElement]) =>\n store.dispatch(registerDocumentEffect(ReactPage.createDocument(documentKey, rootElement))),\n )\n\n return () => {\n unregisterDocuments.forEach(unregisterDocument => {\n unregisterDocument()\n })\n }\n }, [store, rootElements])\n\n return (\n <StoreContext.Provider value={store}>\n <MakeswiftProvider client={client}>{children}</MakeswiftProvider>\n </StoreContext.Provider>\n )\n}\n"],"names":["ReadOnlyDocuments.getInitialState","ReadOnlyDocuments.getDocument","ReadOnlyDocuments.reducer","ReadOnlyDocuments.createDocument","Documents.reducer","ReactComponents.reducer","BoxModels.reducer","ComponentsMeta.reducer","PropControllers.reducer","PropControllerHandles.reducer","IsInBuilder.reducer","BoxModels.getMeasurables","BoxModels.getBoxModels","BoxModels.getBoxModel","ComponentsMeta.getComponentsMeta","PropControllers.getComponentPropControllerDescriptors","BoxModels.measure","BoxModels.isMeasurable","ReactPage.getElementPropControllerDescriptors","ReactPage.getElement","ReactPage.isElementReference","PropControllerHandles.isPropControllersHandle","PropControllerHandles.getPropControllersHandle","PropControllerHandles.getPropController","Documents.getInitialState","client","children","rootElements","store","useMemo","ReactBuilderPreview","preloadedState","storeContextDefaultValue","getState","useEffect","unregisterDocuments","Array","from","entries","map","documentKey","rootElement","dispatch","registerDocumentEffect","ReactPage","forEach","unregisterDocument","_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,eAAe,MAAiC,WAAiD;AAC/F,MAAI,UAAU;AAEd,YAAU,QAAQ,CAAa,cAAA;AAE7B,QAAI,UAAU,MAAM;AAAgB,gBAAA,SAAS,SAAS,UAAU,CAAC;AAGjE,QAAI,UAAU,MAAM;AAAgB,gBAAA,SAAS,SAAS,UAAU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;AACR,QAAM,eAAsC,iCACvC,iBADuC;AAAA,IAE1C,WAAWC,gBAA0B,EAAE,cAAc;AAAA,EAAA;AAGvD,SAAO,YACL,SACA,cACA,gBACE,OACA,2BAA2B,GAC3B,yBAAyB,GACzB,gCAAgC,GAChC,iCAAiC,MAAM,CACzC,CACF;AACF;AChjBwC,yBAAA;AAAA,EAAEC;AAAAA,EAAQC;AAAAA,EAAUC;AAAAA,GAAoC;AACxFC,QAAAA,QAAQC,QACZ,MACEC,eAAmC;AAAA,IACjCC,gBAAgBC,yBAAyBC,SADR;AAAA,IAEjCN;AAAAA,IACAF;AAAAA,EAHF,CAAA,GAKF,CAACA,QAAQE,YAAT,CAPmB;AAUrBO,YAAU,MAAM;;AACRC,UAAAA,sBAAsBC,MAAMC,KAAKV,mDAAcW,cAAdX,YAA2B,CAAA,CAAtC,EAA0CY,IACpE,CAAC,CAACC,aAAaC,iBACbb,MAAMc,SAASC,uBAAuBC,eAAyBJ,aAAaC,WAAtC,CAAD,CAArC,CAFwB;AAK5B,WAAO,MAAM;AACXN,0BAAoBU,QAAQC,CAAsB,uBAAA;AAC9B;MAAA,CADpB;AAAA,IAAA;AAAA,EADF,GAKC,CAAClB,OAAOD,YAAR,CAXM;AAcP,SAAAoB,oBAAC,aAAa,UAAd;AAAA,IAAuB,OAAOnB;AAAAA,IAA9B,8BACG,mBAAD;AAAA,MAAmB;AAAA,MAAiBF;AAAAA,IAAAA,CAApC;AAAA,EAAA,CAFJ;AAKD;;"}
|
|
1
|
+
{"version":3,"file":"PreviewProvider.es.js","sources":["../src/state/modules/read-write-documents.ts","../src/state/react-builder-preview.ts","../src/runtimes/react/components/PreviewProvider.tsx"],"sourcesContent":["import { Operation } from 'ot-json0'\nimport { removeIn, setIn } from 'immutable'\n\nimport * as ReadOnlyDocuments from './read-only-documents'\nimport { Action, ActionTypes } from '../actions'\n\nexport type { Document, Element, ElementData, ElementReference } from './read-only-documents'\nexport { isElementReference } from './read-only-documents'\nexport type { Operation }\n\nfunction apply(data: ReadOnlyDocuments.Element, operation: Operation): ReadOnlyDocuments.Element {\n let applied = data\n\n operation.forEach(component => {\n // @ts-expect-error: `ld` isn't in all possible values of `component`\n if (component.ld != null) applied = removeIn(applied, component.p)\n\n // @ts-expect-error: `od` isn't in all possible values of `component`\n if (component.od != null) applied = removeIn(applied, component.p)\n\n // @ts-expect-error: `li` isn't in all possible values of `component`\n if (component.li != null) applied = setIn(applied, component.p, component.li)\n\n // @ts-expect-error: `oi` isn't in all possible values of `component`\n if (component.oi != null) applied = setIn(applied, component.p, component.oi)\n })\n\n return applied\n}\n\nexport type State = ReadOnlyDocuments.State\n\nexport function getInitialState({\n rootElements,\n}: {\n rootElements?: Map<string, ReadOnlyDocuments.Element>\n} = {}): State {\n return ReadOnlyDocuments.getInitialState({ rootElements })\n}\n\nfunction getReadOnlyDocumentsStateSlice(state: State): ReadOnlyDocuments.State {\n return state\n}\n\nexport function getDocument(state: State, documentKey: string): ReadOnlyDocuments.Document | null {\n return ReadOnlyDocuments.getDocument(getReadOnlyDocumentsStateSlice(state), documentKey)\n}\n\nexport function reducer(state: State = getInitialState(), action: Action): State {\n const nextState = ReadOnlyDocuments.reducer(state, action)\n\n switch (action.type) {\n case ActionTypes.CHANGE_DOCUMENT: {\n const currentRootElement = getDocument(nextState, action.payload.documentKey)?.rootElement\n\n if (currentRootElement == null) return nextState\n\n const nextRootElement = apply(currentRootElement, action.payload.operation)\n\n return currentRootElement === nextRootElement\n ? nextState\n : new Map(nextState).set(\n action.payload.documentKey,\n ReadOnlyDocuments.createDocument(action.payload.documentKey, nextRootElement),\n )\n }\n\n default:\n return nextState\n }\n}\n","import {\n applyMiddleware,\n combineReducers,\n createStore,\n Dispatch as ReduxDispatch,\n Middleware,\n MiddlewareAPI,\n PreloadedState,\n Store as ReduxStore,\n} from 'redux'\nimport thunk, { ThunkAction, ThunkDispatch } from 'redux-thunk'\nimport deepEqual from '../utils/deepEqual'\n\nimport * as Documents from './modules/read-write-documents'\nimport * as ReactComponents from './modules/react-components'\nimport * as BoxModels from './modules/box-models'\nimport * as ComponentsMeta from './modules/components-meta'\nimport * as PropControllers from './modules/prop-controllers'\nimport * as PropControllerHandles from './modules/prop-controller-handles'\nimport * as IsInBuilder from './modules/is-in-builder'\nimport * as IsPreview from './modules/is-preview'\nimport * as ReactPage from './react-page'\nimport {\n Action,\n changeDocumentElementSize,\n changeElementBoxModels,\n messageBuilderPropController,\n registerBuilderComponent,\n registerMeasurable,\n registerPropControllers,\n registerPropControllersHandle,\n registerDocument,\n registerComponentHandle,\n unregisterBuilderComponent,\n unregisterMeasurable,\n unregisterPropControllers,\n setIsInBuilder,\n handleWheel,\n handlePointerMove,\n} from './actions'\nimport { ActionTypes } from './actions'\nimport { createPropController, PropController } from '../prop-controllers/instances'\nimport { serializeControls } from '../builder'\nimport { MakeswiftClient } from '../api/react'\nimport { ElementImperativeHandle } from '../runtimes/react/element-imperative-handle'\n\nexport type { Operation } from './modules/read-write-documents'\nexport type { BoxModelHandle } from './modules/box-models'\nexport { createBox, getBox, parse } from './modules/box-models'\n\nconst reducer = combineReducers({\n documents: Documents.reducer,\n reactComponents: ReactComponents.reducer,\n boxModels: BoxModels.reducer,\n componentsMeta: ComponentsMeta.reducer,\n propControllers: PropControllers.reducer,\n propControllerHandles: PropControllerHandles.reducer,\n isInBuilder: IsInBuilder.reducer,\n isPreview: IsPreview.reducer,\n})\n\nexport type State = ReturnType<typeof reducer>\n\nfunction getBoxModelsStateSlice(state: State): BoxModels.State {\n return state.boxModels\n}\n\nfunction getMeasurables(state: State): Map<string, Map<string, BoxModels.Measurable>> {\n return BoxModels.getMeasurables(getBoxModelsStateSlice(state))\n}\n\nfunction getBoxModels(state: State): Map<string, Map<string, BoxModels.BoxModel>> {\n return BoxModels.getBoxModels(getBoxModelsStateSlice(state))\n}\n\nfunction getBoxModel(\n state: State,\n documentKey: string,\n elementKey: string,\n): BoxModels.BoxModel | null {\n return BoxModels.getBoxModel(getBoxModelsStateSlice(state), documentKey, elementKey)\n}\n\nfunction getComponentsMetaStateSlice(state: State): ComponentsMeta.State {\n return state.componentsMeta\n}\n\nfunction getComponentsMeta(state: State): Map<string, ComponentsMeta.ComponentMeta> {\n return ComponentsMeta.getComponentsMeta(getComponentsMetaStateSlice(state))\n}\n\nfunction getPropControllersStateSlice(state: State): PropControllers.State {\n return state.propControllers\n}\n\nfunction getComponentPropControllerDescriptors(\n state: State,\n componentType: string,\n): Record<string, PropControllers.PropControllerDescriptor> | null {\n return PropControllers.getComponentPropControllerDescriptors(\n getPropControllersStateSlice(state),\n componentType,\n )\n}\n\nfunction getPropControllerHandlesStateSlice(state: State): PropControllerHandles.State {\n return state.propControllerHandles\n}\n\nfunction measureElements(): ThunkAction<void, State, unknown, Action> {\n return (dispatch, getState) => {\n const measurables = getMeasurables(getState())\n const currentBoxModels = getBoxModels(getState())\n const measuredBoxModels = new Map<string, Map<string, BoxModels.BoxModel>>()\n\n measurables.forEach((documentMeasurables, documentKey) => {\n const measuredDocumentBoxModels = new Map<string, BoxModels.BoxModel>()\n\n documentMeasurables.forEach((measurable, elementKey) => {\n const boxModel = BoxModels.measure(measurable)\n\n if (boxModel != null) measuredDocumentBoxModels.set(elementKey, boxModel)\n })\n\n if (measuredDocumentBoxModels.size > 0) {\n measuredBoxModels.set(documentKey, measuredDocumentBoxModels)\n }\n })\n\n const changedBoxModels = new Map<string, Map<string, BoxModels.BoxModel | null>>()\n\n currentBoxModels.forEach((currentDocumentBoxModels, documentKey) => {\n const changedDocumentBoxModels = new Map<string, BoxModels.BoxModel | null>()\n\n currentDocumentBoxModels.forEach((_boxModel, elementKey) => {\n if (!measuredBoxModels.get(documentKey)?.has(elementKey)) {\n changedDocumentBoxModels.set(elementKey, null)\n }\n\n if (changedDocumentBoxModels.size > 0) {\n changedBoxModels.set(documentKey, changedDocumentBoxModels)\n }\n })\n })\n\n measuredBoxModels.forEach((measuredDocumentBoxModels, documentKey) => {\n const changedDocumentBoxModels = new Map<string, BoxModels.BoxModel | null>()\n\n measuredDocumentBoxModels.forEach((measuredBoxModel, elementKey) => {\n const currentBoxModel = getBoxModel(getState(), documentKey, elementKey)\n\n if (currentBoxModel == null || !deepEqual(currentBoxModel, measuredBoxModel)) {\n changedDocumentBoxModels.set(elementKey, measuredBoxModel)\n }\n })\n\n if (changedDocumentBoxModels.size > 0) {\n changedBoxModels.set(documentKey, changedDocumentBoxModels)\n }\n })\n\n if (changedBoxModels.size > 0) dispatch(changeElementBoxModels(changedBoxModels))\n }\n}\n\nexport function startMeasuringElements(): ThunkAction<() => void, State, unknown, Action> {\n return dispatch => {\n let animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n\n return () => {\n cancelAnimationFrame(animationFrameHandle)\n }\n\n function handleAnimationFrameRequest() {\n dispatch(measureElements())\n\n animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n }\n }\n}\n\nexport type Size = {\n offsetWidth: number\n offsetHeight: number\n clientWidth: number\n clientHeight: number\n scrollWidth: number\n scrollHeight: number\n scrollTop: number\n scrollLeft: number\n}\n\nfunction getElementSize(element: HTMLElement): Size {\n return {\n offsetWidth: element.offsetWidth,\n offsetHeight: element.offsetHeight,\n clientWidth: element.clientWidth,\n clientHeight: element.clientHeight,\n scrollWidth: element.scrollWidth,\n scrollHeight: element.scrollHeight,\n scrollTop: element.scrollTop,\n scrollLeft: element.scrollLeft,\n }\n}\n\nfunction lockDocumentScroll(): ThunkAction<() => void, State, unknown, Action> {\n return dispatch => {\n const lastDocumentOverflow = window.document.documentElement.style.overflow\n window.document.documentElement.style.overflow = 'hidden'\n\n window.document.documentElement.addEventListener('wheel', handleWheelEvent)\n\n return () => {\n window.document.documentElement.style.overflow = lastDocumentOverflow\n window.document.documentElement.removeEventListener('wheel', handleWheelEvent)\n }\n\n function handleWheelEvent({ deltaX, deltaY }: WheelEvent) {\n dispatch(handleWheel({ deltaX, deltaY }))\n }\n }\n}\n\nfunction startHandlingPointerMoveEvent(): ThunkAction<() => void, State, unknown, Action> {\n return dispatch => {\n window.document.documentElement.addEventListener('pointermove', handlePointerMoveEvent)\n\n return () => {\n window.document.documentElement.removeEventListener('pointermove', handlePointerMoveEvent)\n }\n\n function handlePointerMoveEvent({ clientX, clientY }: PointerEvent) {\n dispatch(handlePointerMove({ clientX, clientY }))\n }\n }\n}\n\nfunction startHandlingFocusEvents(): () => void {\n window.addEventListener('focusin', handleFocusIn)\n window.addEventListener('focusout', handleFocusOut)\n\n return () => {\n window.removeEventListener('focusin', handleFocusIn)\n window.removeEventListener('focusout', handleFocusOut)\n }\n\n function handleFocusIn(event: FocusEvent) {\n if (!(event.target instanceof window.HTMLElement) || !event.target.isContentEditable) {\n window.parent.focus()\n }\n }\n\n function handleFocusOut(event: FocusEvent) {\n if (\n !(event.relatedTarget instanceof window.HTMLElement) ||\n !event.relatedTarget.isContentEditable\n ) {\n window.parent.focus()\n }\n }\n}\n\nfunction startMeasuringDocumentElement(): ThunkAction<() => void, unknown, unknown, Action> {\n return dispatch => {\n let animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n let lastSize: Size\n\n return () => {\n cancelAnimationFrame(animationFrameHandle)\n }\n\n function handleAnimationFrameRequest() {\n const nextSize = getElementSize(window.document.documentElement)\n\n if (!deepEqual(lastSize, nextSize)) {\n lastSize = nextSize\n\n dispatch(changeDocumentElementSize(nextSize))\n }\n\n animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n }\n }\n}\n\nexport function initialize(): ThunkAction<() => void, State, unknown, Action> {\n return dispatch => {\n const stopMeasuringElements = dispatch(startMeasuringElements())\n const stopMeasuringDocumentElement = dispatch(startMeasuringDocumentElement())\n const stopHandlingFocusEvent = startHandlingFocusEvents()\n const unlockDocumentScroll = dispatch(lockDocumentScroll())\n const stopHandlingPointerMoveEvent = dispatch(startHandlingPointerMoveEvent())\n dispatch(setIsInBuilder(true))\n\n return () => {\n stopMeasuringElements()\n stopMeasuringDocumentElement()\n stopHandlingFocusEvent()\n unlockDocumentScroll()\n stopHandlingPointerMoveEvent()\n dispatch(setIsInBuilder(false))\n }\n }\n}\n\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\n\nfunction measureBoxModelsMiddleware(): Middleware<Dispatch, State, Dispatch> {\n return ({ dispatch }: MiddlewareAPI<Dispatch>) =>\n (next: ReduxDispatch<Action>) => {\n return (action: Action): Action => {\n switch (action.type) {\n case ActionTypes.REGISTER_COMPONENT_HANDLE: {\n if (BoxModels.isMeasurable(action.payload.componentHandle)) {\n dispatch(\n registerMeasurable(\n action.payload.documentKey,\n action.payload.elementKey,\n action.payload.componentHandle,\n ),\n )\n }\n\n break\n }\n\n case ActionTypes.UNREGISTER_COMPONENT_HANDLE:\n dispatch(unregisterMeasurable(action.payload.documentKey, action.payload.elementKey))\n break\n }\n\n return next(action)\n }\n }\n}\n\nexport function messageChannelMiddleware(): Middleware<Dispatch, State, Dispatch> {\n return ({ dispatch, getState }: MiddlewareAPI<Dispatch, State>) =>\n (next: ReduxDispatch<Action>) => {\n let cleanUp = () => {}\n\n if (typeof window === 'undefined') return cleanUp\n\n const messageChannel = new window.MessageChannel()\n\n window.parent.postMessage(messageChannel.port2, '*', [messageChannel.port2])\n\n messageChannel.port1.onmessage = (event: MessageEvent<Action>) => dispatch(event.data)\n\n const state = getState()\n const registeredComponentsMeta = getComponentsMeta(state)\n\n registeredComponentsMeta.forEach((componentMeta, componentType) => {\n const propControllerDescriptors = getComponentPropControllerDescriptors(\n state,\n componentType,\n )\n\n if (propControllerDescriptors != null) {\n const [serializedControls, transferables] = serializeControls(propControllerDescriptors)\n\n messageChannel.port1.postMessage(\n registerBuilderComponent(componentType, componentMeta, serializedControls),\n transferables,\n )\n }\n })\n\n return (action: Action): Action => {\n switch (action.type) {\n case ActionTypes.CHANGE_ELEMENT_BOX_MODELS:\n case ActionTypes.MOUNT_COMPONENT:\n case ActionTypes.UNMOUNT_COMPONENT:\n case ActionTypes.CHANGE_DOCUMENT_ELEMENT_SIZE:\n case ActionTypes.MESSAGE_BUILDER_PROP_CONTROLLER:\n case ActionTypes.HANDLE_WHEEL:\n case ActionTypes.HANDLE_POINTER_MOVE:\n messageChannel.port1.postMessage(action)\n break\n\n case ActionTypes.REGISTER_COMPONENT: {\n const { type, meta, propControllerDescriptors } = action.payload\n const [serializedControls, transferables] = serializeControls(propControllerDescriptors)\n\n messageChannel.port1.postMessage(\n registerBuilderComponent(type, meta, serializedControls),\n transferables,\n )\n break\n }\n\n case ActionTypes.UNREGISTER_COMPONENT:\n messageChannel.port1.postMessage(unregisterBuilderComponent(action.payload.type))\n break\n\n case ActionTypes.CHANGE_DOCUMENT_ELEMENT_SCROLL_TOP:\n window.document.documentElement.scrollTop = action.payload.scrollTop\n break\n\n case ActionTypes.SCROLL_DOCUMENT_ELEMENT:\n window.document.documentElement.scrollTop += action.payload.scrollTopDelta\n break\n\n case ActionTypes.INIT:\n cleanUp = dispatch(initialize())\n break\n\n case ActionTypes.CLEAN_UP:\n cleanUp()\n break\n }\n\n return next(action)\n }\n }\n}\n\nfunction createAndRegisterPropControllers(\n documentKey: string,\n elementKey: string,\n): ThunkAction<Record<string, PropController> | null, State, unknown, Action> {\n return (dispatch, getState) => {\n const descriptors = ReactPage.getElementPropControllerDescriptors(\n getState(),\n documentKey,\n elementKey,\n )\n\n if (descriptors == null) return null\n\n const propControllers = Object.entries(descriptors).reduce((acc, [propName, descriptor]) => {\n const propController = createPropController(descriptor, message =>\n dispatch(messageBuilderPropController(documentKey, elementKey, propName, message)),\n ) as PropController\n\n return { ...acc, [propName]: propController }\n }, {} as Record<string, PropController>)\n\n dispatch(registerPropControllers(documentKey, elementKey, propControllers))\n\n return propControllers\n }\n}\n\nfunction propControllerHandlesMiddleware(): Middleware<Dispatch, State, Dispatch> {\n return ({ dispatch, getState }: MiddlewareAPI<Dispatch, State>) =>\n (next: ReduxDispatch<Action>) => {\n return (action: Action): Action => {\n switch (action.type) {\n case ActionTypes.REGISTER_COMPONENT_HANDLE: {\n const { documentKey, elementKey, componentHandle } = action.payload\n const element = ReactPage.getElement(getState(), documentKey, elementKey)\n const propControllers = dispatch(\n createAndRegisterPropControllers(documentKey, elementKey),\n )\n\n if (\n element != null &&\n !ReactPage.isElementReference(element) &&\n PropControllerHandles.isPropControllersHandle(componentHandle)\n ) {\n dispatch(registerPropControllersHandle(documentKey, elementKey, componentHandle))\n componentHandle.setPropControllers(propControllers)\n }\n\n break\n }\n\n case ActionTypes.UNREGISTER_COMPONENT_HANDLE: {\n const { documentKey, elementKey } = action.payload\n const handle = PropControllerHandles.getPropControllersHandle(\n getPropControllerHandlesStateSlice(getState()),\n documentKey,\n elementKey,\n )\n\n handle?.setPropControllers(null)\n\n dispatch(unregisterPropControllers(documentKey, elementKey))\n\n break\n }\n\n case ActionTypes.MESSAGE_HOST_PROP_CONTROLLER: {\n const propController = PropControllerHandles.getPropController(\n getPropControllerHandlesStateSlice(getState()),\n action.payload.documentKey,\n action.payload.elementKey,\n action.payload.propName,\n )\n\n if (propController) propController.recv(action.payload.message)\n }\n }\n\n return next(action)\n }\n }\n}\n\nif (import.meta.vitest) {\n const { describe, it, fn, expect } = import.meta.vitest\n\n describe('propControllerHandlesMiddleware', () => {\n it('registers prop controllers for element data', () => {\n // Arrange\n const documentKey = 'documentKey'\n const element: ReactPage.Element = { key: 'elementKey', type: 'type', props: {} }\n const store = createStore(reducer, applyMiddleware(thunk, propControllerHandlesMiddleware()))\n const setPropControllers = fn()\n const handle = new ElementImperativeHandle()\n\n handle.callback(() => ({ setPropControllers }))\n\n store.dispatch(registerDocument(ReactPage.createDocument(documentKey, element)))\n\n // Act\n store.dispatch(registerComponentHandle(documentKey, element.key, handle))\n\n // Assert\n expect(setPropControllers).toHaveBeenCalled()\n })\n\n it(\"doesn't register prop controllers for element references\", () => {\n // Arrange\n const documentKey = 'documentKey'\n const element: ReactPage.Element = { type: 'reference', key: 'elementKey', value: 'value' }\n const store = createStore(reducer, applyMiddleware(thunk, propControllerHandlesMiddleware()))\n const setPropControllers = fn()\n const handle = new ElementImperativeHandle()\n\n handle.callback(() => ({ setPropControllers }))\n\n store.dispatch(registerDocument(ReactPage.createDocument(documentKey, element)))\n\n // Act\n store.dispatch(registerComponentHandle(documentKey, element.key, handle))\n\n // Assert\n expect(setPropControllers).not.toHaveBeenCalled()\n })\n })\n}\n\nfunction makeswiftApiClientSyncMiddleware(\n client: MakeswiftClient,\n): Middleware<Dispatch, State, Dispatch> {\n return () => (next: ReduxDispatch<Action>) => {\n return (action: Action): Action => {\n client.makeswiftApiClient.dispatch(action)\n\n return next(action)\n }\n }\n}\n\nexport type Store = ReduxStore<State, Action> & { dispatch: Dispatch }\n\nexport function configureStore({\n rootElements,\n preloadedState,\n client,\n}: {\n rootElements?: Map<string, Documents.Element>\n preloadedState?: PreloadedState<State>\n client: MakeswiftClient\n}): Store {\n const initialState: PreloadedState<State> = {\n ...preloadedState,\n documents: Documents.getInitialState({ rootElements }),\n isPreview: IsPreview.getInitialState(true),\n }\n\n return createStore(\n reducer,\n initialState,\n applyMiddleware(\n thunk,\n measureBoxModelsMiddleware(),\n messageChannelMiddleware(),\n propControllerHandlesMiddleware(),\n makeswiftApiClientSyncMiddleware(client),\n ),\n )\n}\n","import { ReactNode, useEffect, useMemo } from 'react'\n\nimport { StoreContext, storeContextDefaultValue } from '..'\nimport * as ReactBuilderPreview from '../../../state/react-builder-preview'\nimport * as ReactPage from '../../../state/react-page'\nimport { MakeswiftProvider, MakeswiftClient } from '../../../api/react'\nimport { registerDocumentEffect } from '../../../state/actions'\n\ntype Props = {\n client: MakeswiftClient\n rootElements?: Map<string, ReactPage.Element>\n children?: ReactNode\n}\n\nexport default function PreviewProvider({ client, children, rootElements }: Props): JSX.Element {\n const store = useMemo(\n () =>\n ReactBuilderPreview.configureStore({\n preloadedState: storeContextDefaultValue.getState(),\n rootElements,\n client,\n }),\n [client, rootElements],\n )\n\n useEffect(() => {\n const unregisterDocuments = Array.from(rootElements?.entries() ?? []).map(\n ([documentKey, rootElement]) =>\n store.dispatch(registerDocumentEffect(ReactPage.createDocument(documentKey, rootElement))),\n )\n\n return () => {\n unregisterDocuments.forEach(unregisterDocument => {\n unregisterDocument()\n })\n }\n }, [store, rootElements])\n\n return (\n <StoreContext.Provider value={store}>\n <MakeswiftProvider client={client}>{children}</MakeswiftProvider>\n </StoreContext.Provider>\n )\n}\n"],"names":["ReadOnlyDocuments.getInitialState","ReadOnlyDocuments.getDocument","ReadOnlyDocuments.reducer","ReadOnlyDocuments.createDocument","Documents.reducer","ReactComponents.reducer","BoxModels.reducer","ComponentsMeta.reducer","PropControllers.reducer","PropControllerHandles.reducer","IsInBuilder.reducer","IsPreview.reducer","BoxModels.getMeasurables","BoxModels.getBoxModels","BoxModels.getBoxModel","ComponentsMeta.getComponentsMeta","PropControllers.getComponentPropControllerDescriptors","BoxModels.measure","BoxModels.isMeasurable","ReactPage.getElementPropControllerDescriptors","ReactPage.getElement","ReactPage.isElementReference","PropControllerHandles.isPropControllersHandle","PropControllerHandles.getPropControllersHandle","PropControllerHandles.getPropController","Documents.getInitialState","IsPreview.getInitialState","client","children","rootElements","store","useMemo","ReactBuilderPreview","preloadedState","storeContextDefaultValue","getState","useEffect","unregisterDocuments","Array","from","entries","map","documentKey","rootElement","dispatch","registerDocumentEffect","ReactPage","forEach","unregisterDocument","_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,eAAe,MAAiC,WAAiD;AAC/F,MAAI,UAAU;AAEd,YAAU,QAAQ,CAAa,cAAA;AAE7B,QAAI,UAAU,MAAM;AAAgB,gBAAA,SAAS,SAAS,UAAU,CAAC;AAGjE,QAAI,UAAU,MAAM;AAAgB,gBAAA,SAAS,SAAS,UAAU,CAAC;AAGjE,QAAI,UAAU,MAAM;AAAM,gBAAU,MAAM,SAAS,UAAU,GAAG,UAAU,EAAE;AAG5E,QAAI,UAAU,MAAM;AAAM,gBAAU,MAAM,SAAS,UAAU,GAAG,UAAU,EAAE;AAAA,EAAA,CAC7E;AAEM,SA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B,GAC3B,yBAAyB,GACzB,gCAAgC,GAChC,iCAAiC,MAAM,CACzC,CACF;AACF;AC1jBwC,yBAAA;AAAA,EAAEC;AAAAA,EAAQC;AAAAA,EAAUC;AAAAA,GAAoC;AACxFC,QAAAA,QAAQC,QACZ,MACEC,eAAmC;AAAA,IACjCC,gBAAgBC,yBAAyBC,SADR;AAAA,IAEjCN;AAAAA,IACAF;AAAAA,EAHF,CAAA,GAKF,CAACA,QAAQE,YAAT,CAPmB;AAUrBO,YAAU,MAAM;;AACRC,UAAAA,sBAAsBC,MAAMC,KAAKV,mDAAcW,cAAdX,YAA2B,CAAA,CAAtC,EAA0CY,IACpE,CAAC,CAACC,aAAaC,iBACbb,MAAMc,SAASC,uBAAuBC,eAAyBJ,aAAaC,WAAtC,CAAD,CAArC,CAFwB;AAK5B,WAAO,MAAM;AACXN,0BAAoBU,QAAQC,CAAsB,uBAAA;AAC9B;MAAA,CADpB;AAAA,IAAA;AAAA,EADF,GAKC,CAAClB,OAAOD,YAAR,CAXM;AAcP,SAAAoB,oBAAC,aAAa,UAAd;AAAA,IAAuB,OAAOnB;AAAAA,IAA9B,8BACG,mBAAD;AAAA,MAAmB;AAAA,MAAiBF;AAAAA,IAAAA,CAApC;AAAA,EAAA,CAFJ;AAKD;;"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
22
|
+
var css = require("@emotion/css");
|
|
23
|
+
var React = require("react");
|
|
24
|
+
var next = require("./index.cjs.js");
|
|
25
|
+
var index$1 = require("./index.cjs3.js");
|
|
26
|
+
var index = require("./index.cjs5.js");
|
|
27
|
+
var jsxRuntime = require("react/jsx-runtime");
|
|
28
|
+
require("use-sync-external-store/shim/with-selector");
|
|
29
|
+
require("next/dynamic");
|
|
30
|
+
require("./constants.cjs.js");
|
|
31
|
+
require("redux");
|
|
32
|
+
require("redux-thunk");
|
|
33
|
+
require("./actions.cjs.js");
|
|
34
|
+
require("./slot.cjs.js");
|
|
35
|
+
require("./control.cjs.js");
|
|
36
|
+
require("@emotion/serialize");
|
|
37
|
+
require("@emotion/utils");
|
|
38
|
+
require("./text-input.cjs.js");
|
|
39
|
+
require("./combobox.cjs.js");
|
|
40
|
+
require("use-sync-external-store/shim");
|
|
41
|
+
require("./types.cjs.js");
|
|
42
|
+
require("color");
|
|
43
|
+
require("scroll-into-view-if-needed");
|
|
44
|
+
require("./box-models.cjs.js");
|
|
45
|
+
require("css-box-model");
|
|
46
|
+
require("react-dom");
|
|
47
|
+
require("html-react-parser");
|
|
48
|
+
require("next/head");
|
|
49
|
+
require("@emotion/server/create-instance");
|
|
50
|
+
require("next/document");
|
|
51
|
+
require("cookie");
|
|
52
|
+
require("cors");
|
|
53
|
+
require("http-proxy");
|
|
54
|
+
require("set-cookie-parser");
|
|
55
|
+
require("uuid/v4");
|
|
56
|
+
require("corporate-ipsum");
|
|
57
|
+
require("next/link");
|
|
58
|
+
const ReadOnlyText = React.forwardRef(function ReadOnlyText2({
|
|
59
|
+
id,
|
|
60
|
+
text,
|
|
61
|
+
width,
|
|
62
|
+
margin
|
|
63
|
+
}, ref) {
|
|
64
|
+
const plaintext = (text == null ? void 0 : text.document) == null ? "" : getNodeText(text.document);
|
|
65
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
66
|
+
ref,
|
|
67
|
+
id,
|
|
68
|
+
className: css.cx(width, margin),
|
|
69
|
+
children: plaintext === "" ? /* @__PURE__ */ jsxRuntime.jsx(Placeholder, {}) : /* @__PURE__ */ jsxRuntime.jsx(Node, __spreadValues({}, text == null ? void 0 : text.document))
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
function Placeholder({
|
|
73
|
+
text = "Write some text..."
|
|
74
|
+
}) {
|
|
75
|
+
return /* @__PURE__ */ jsxRuntime.jsx("span", {
|
|
76
|
+
className: next.useStyle({
|
|
77
|
+
display: "inline-block",
|
|
78
|
+
width: 0,
|
|
79
|
+
maxWidth: "100%",
|
|
80
|
+
whiteSpace: "nowrap",
|
|
81
|
+
opacity: 0.333,
|
|
82
|
+
verticalAlign: "text-top"
|
|
83
|
+
}),
|
|
84
|
+
children: text
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function Node(props) {
|
|
88
|
+
switch (props.object) {
|
|
89
|
+
case "document":
|
|
90
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Document, __spreadValues({}, props));
|
|
91
|
+
case "block":
|
|
92
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Block, __spreadValues({}, props));
|
|
93
|
+
case "inline":
|
|
94
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Inline, __spreadValues({}, props));
|
|
95
|
+
case "text":
|
|
96
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Text, __spreadValues({}, props));
|
|
97
|
+
default:
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function Document({
|
|
102
|
+
nodes
|
|
103
|
+
}) {
|
|
104
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
105
|
+
children: nodes == null ? void 0 : nodes.map((node, idx) => /* @__PURE__ */ jsxRuntime.jsx(Node, __spreadValues({}, node), idx.toString()))
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function Block({
|
|
109
|
+
type,
|
|
110
|
+
data,
|
|
111
|
+
nodes
|
|
112
|
+
}) {
|
|
113
|
+
const component = {
|
|
114
|
+
paragraph: "p",
|
|
115
|
+
"heading-one": "h1",
|
|
116
|
+
"heading-two": "h2",
|
|
117
|
+
"heading-three": "h3",
|
|
118
|
+
"heading-four": "h4",
|
|
119
|
+
"heading-five": "h5",
|
|
120
|
+
"heading-six": "h6",
|
|
121
|
+
blockquote: "blockquote"
|
|
122
|
+
}[type];
|
|
123
|
+
return /* @__PURE__ */ jsxRuntime.jsx(index.DeviceOverrideBlock, {
|
|
124
|
+
as: component,
|
|
125
|
+
textAlign: data == null ? void 0 : data.textAlign,
|
|
126
|
+
children: nodes == null ? void 0 : nodes.map((node, idx) => /* @__PURE__ */ jsxRuntime.jsx(Node, __spreadValues({}, node), idx.toString()))
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function Inline({
|
|
130
|
+
type,
|
|
131
|
+
nodes,
|
|
132
|
+
data
|
|
133
|
+
}) {
|
|
134
|
+
const children = nodes == null ? void 0 : nodes.map((node, idx) => /* @__PURE__ */ jsxRuntime.jsx(Node, __spreadValues({}, node), idx.toString()));
|
|
135
|
+
const linkClassName = next.useStyle({
|
|
136
|
+
textDecoration: "none"
|
|
137
|
+
});
|
|
138
|
+
switch (type) {
|
|
139
|
+
case "code":
|
|
140
|
+
return /* @__PURE__ */ jsxRuntime.jsx("code", {
|
|
141
|
+
children
|
|
142
|
+
});
|
|
143
|
+
case "superscript":
|
|
144
|
+
return /* @__PURE__ */ jsxRuntime.jsx("sup", {
|
|
145
|
+
children
|
|
146
|
+
});
|
|
147
|
+
case "subscript":
|
|
148
|
+
return /* @__PURE__ */ jsxRuntime.jsx("sub", {
|
|
149
|
+
children
|
|
150
|
+
});
|
|
151
|
+
case "link":
|
|
152
|
+
return /* @__PURE__ */ jsxRuntime.jsx(index$1.Link, {
|
|
153
|
+
className: linkClassName,
|
|
154
|
+
link: data,
|
|
155
|
+
children
|
|
156
|
+
});
|
|
157
|
+
default:
|
|
158
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
159
|
+
children
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function Text({
|
|
164
|
+
marks,
|
|
165
|
+
text = ""
|
|
166
|
+
}) {
|
|
167
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
168
|
+
children: (marks != null ? marks : []).reduce((element, mark) => /* @__PURE__ */ jsxRuntime.jsx(Mark, __spreadProps(__spreadValues({}, mark), {
|
|
169
|
+
children: element
|
|
170
|
+
})), /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
171
|
+
children: text === "" ? "\uFEFF" : text
|
|
172
|
+
}))
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
const TYPOGRAPHY_MARK_TYPE = "typography";
|
|
176
|
+
function Mark({
|
|
177
|
+
type,
|
|
178
|
+
children,
|
|
179
|
+
data
|
|
180
|
+
}) {
|
|
181
|
+
if (type !== TYPOGRAPHY_MARK_TYPE)
|
|
182
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
183
|
+
children
|
|
184
|
+
});
|
|
185
|
+
return /* @__PURE__ */ jsxRuntime.jsx(index.Mark, {
|
|
186
|
+
value: data == null ? void 0 : data.value,
|
|
187
|
+
children
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
function getNodeText(node) {
|
|
191
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
192
|
+
switch (node.object) {
|
|
193
|
+
case "document":
|
|
194
|
+
return (_b = (_a = node == null ? void 0 : node.nodes) == null ? void 0 : _a.map((node2) => getNodeText(node2)).join("\n")) != null ? _b : "";
|
|
195
|
+
case "block":
|
|
196
|
+
return (_d = (_c = node == null ? void 0 : node.nodes) == null ? void 0 : _c.map((node2) => getNodeText(node2)).join(node.nodes.every((node2) => node2.object === "block") ? "\n" : "")) != null ? _d : "";
|
|
197
|
+
case "inline":
|
|
198
|
+
return (_f = (_e = node == null ? void 0 : node.nodes) == null ? void 0 : _e.map((node2) => getNodeText(node2)).join("")) != null ? _f : "";
|
|
199
|
+
case "text":
|
|
200
|
+
return (_g = node.text) != null ? _g : "";
|
|
201
|
+
default:
|
|
202
|
+
return "";
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
exports["default"] = ReadOnlyText;
|
|
206
|
+
//# sourceMappingURL=ReadOnlyText.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReadOnlyText.cjs.js","sources":["../src/components/builtin/Text/ReadOnlyText.tsx"],"sourcesContent":["import { cx } from '@emotion/css'\nimport { ForwardedRef, forwardRef, ReactNode } from 'react'\nimport type { BlockJSON, DocumentJSON, InlineJSON, MarkJSON, NodeJSON, TextJSON } from 'slate'\nimport type {\n ElementIDValue,\n LinkValue,\n RichTextValue,\n} from '../../../prop-controllers/descriptors'\nimport { useStyle } from '../../../runtimes/react/use-style'\nimport { Link } from '../../shared/Link'\nimport DeviceOverrideBlock from './components/RichTextEditor/components/Block'\nimport DeviceOverrideMark from './components/RichTextEditor/components/Mark'\n\ntype Props = {\n id?: ElementIDValue\n text?: RichTextValue\n width?: string\n margin?: string\n}\n\nconst ReadOnlyText = forwardRef(function ReadOnlyText(\n { id, text, width, margin }: Props,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n const plaintext = text?.document == null ? '' : getNodeText(text.document)\n\n return (\n <div ref={ref} id={id} className={cx(width, margin)}>\n {plaintext === '' ? <Placeholder /> : <Node {...text?.document} />}\n </div>\n )\n})\n\nexport default ReadOnlyText\n\nfunction Placeholder({ text = 'Write some text...' }: { text?: string }) {\n return (\n <span\n className={useStyle({\n display: 'inline-block',\n width: 0,\n maxWidth: '100%',\n whiteSpace: 'nowrap',\n opacity: 0.333,\n verticalAlign: 'text-top',\n })}\n >\n {text}\n </span>\n )\n}\n\nfunction Node(props: NodeJSON) {\n switch (props.object) {\n case 'document':\n return <Document {...props} />\n\n case 'block':\n return <Block {...props} />\n\n case 'inline':\n return <Inline {...props} />\n\n case 'text':\n return <Text {...props} />\n\n default:\n return null\n }\n}\n\nfunction Document({ nodes }: DocumentJSON) {\n return (\n <>\n {nodes?.map((node, idx) => (\n <Node key={idx.toString()} {...node} />\n ))}\n </>\n )\n}\n\nfunction Block({ type, data, nodes }: BlockJSON) {\n const component = {\n paragraph: 'p',\n 'heading-one': 'h1',\n 'heading-two': 'h2',\n 'heading-three': 'h3',\n 'heading-four': 'h4',\n 'heading-five': 'h5',\n 'heading-six': 'h6',\n blockquote: 'blockquote',\n }[type]\n\n return (\n <DeviceOverrideBlock as={component} textAlign={data?.textAlign}>\n {nodes?.map((node, idx) => (\n <Node key={idx.toString()} {...node} />\n ))}\n </DeviceOverrideBlock>\n )\n}\n\nfunction Inline({ type, nodes, data }: InlineJSON) {\n const children = nodes?.map((node, idx) => <Node key={idx.toString()} {...node} />)\n const linkClassName = useStyle({ textDecoration: 'none' })\n\n switch (type) {\n case 'code':\n return <code>{children}</code>\n\n case 'superscript':\n return <sup>{children}</sup>\n\n case 'subscript':\n return <sub>{children}</sub>\n\n case 'link':\n return (\n <Link className={linkClassName} link={data as LinkValue | undefined}>\n {children}\n </Link>\n )\n\n default:\n return <>{children}</>\n }\n}\n\nfunction Text({ marks, text = '' }: TextJSON) {\n return (\n <>\n {(marks ?? []).reduce(\n (element, mark) => (\n <Mark {...mark}>{element}</Mark>\n ),\n <>{text === '' ? '\\uFEFF' : text}</>,\n )}\n </>\n )\n}\n\nconst TYPOGRAPHY_MARK_TYPE = 'typography'\n\nfunction Mark({ type, children, data }: MarkJSON & { children: ReactNode }) {\n if (type !== TYPOGRAPHY_MARK_TYPE) return <>{children}</>\n\n return <DeviceOverrideMark value={data?.value}>{children}</DeviceOverrideMark>\n}\n\nfunction getNodeText(node: NodeJSON): string {\n switch (node.object) {\n case 'document':\n return node?.nodes?.map(node => getNodeText(node)).join('\\n') ?? ''\n\n case 'block':\n return (\n node?.nodes\n ?.map(node => getNodeText(node))\n .join(node.nodes.every(node => node.object === 'block') ? '\\n' : '') ?? ''\n )\n\n case 'inline':\n return node?.nodes?.map(node => getNodeText(node)).join('') ?? ''\n\n case 'text':\n return node.text ?? ''\n\n default:\n return ''\n }\n}\n"],"names":["ReadOnlyText","forwardRef","id","text","width","margin","ref","plaintext","document","getNodeText","cx","_jsx","useStyle","display","maxWidth","whiteSpace","opacity","verticalAlign","props","object","nodes","_Fragment","map","node","idx","toString","type","data","component","paragraph","blockquote","DeviceOverrideBlock","textAlign","children","linkClassName","textDecoration","Link","marks","reduce","element","mark","TYPOGRAPHY_MARK_TYPE","DeviceOverrideMark","value","join","every"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBMA,MAAAA,eAAeC,MAAAA,WAAW,uBAC9B;AAAA,EAAEC;AAAAA,EAAIC;AAAAA,EAAMC;AAAAA,EAAOC;AAAAA,GACnBC,KACA;AACA,QAAMC,YAAYJ,8BAAMK,aAAY,OAAO,KAAKC,YAAYN,KAAKK,QAAN;AAGzD,wCAAA,OAAA;AAAA,IAAK;AAAA,IAAU;AAAA,IAAQ,WAAWE,IAAAA,GAAGN,OAAOC,MAAR;AAAA,IAApC,UACGE,cAAc,KAAKI,2BAAA,IAAC,aAApB,EAAA,IAAqCA,2BAAA,IAAC,MAASR,mBAAAA,6BAAMK,S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AED,qBAAqBV,MAAwB;;AACnCA,UAAAA,KAAKJ;AAAAA,SACN;AACII,aAAAA,yCAAMH,UAANG,mBAAaD,IAAIC,CAAQd,UAAAA,YAAYc,KAAD,GAAQqB,KAAK,UAAjDrB,YAA0D;AAAA,SAE9D;AACH,aACEA,yCAAMH,UAANG,mBACID,IAAIC,WAAQd,YAAYc,KAAD,GACxBqB,KAAKrB,KAAKH,MAAMyB,MAAMtB,WAAQA,MAAKJ,WAAW,OAAzC,IAAoD,OAAO,QAFnEI,YAE0E;AAAA,SAGzE;AACIA,aAAAA,yCAAMH,UAANG,mBAAaD,IAAIC,CAAQd,UAAAA,YAAYc,KAAD,GAAQqB,KAAK,QAAjDrB,YAAwD;AAAA,SAE5D;AACH,aAAOA,WAAKpB,SAALoB,YAAa;AAAA;AAGb,aAAA;AAAA;AAEZ;;"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import { cx } from "@emotion/css";
|
|
21
|
+
import { forwardRef } from "react";
|
|
22
|
+
import { o as useStyle } from "./index.es.js";
|
|
23
|
+
import { L as Link } from "./index.es3.js";
|
|
24
|
+
import { D as DeviceOverrideBlock, M as Mark$1 } from "./index.es5.js";
|
|
25
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
26
|
+
import "use-sync-external-store/shim/with-selector";
|
|
27
|
+
import "next/dynamic";
|
|
28
|
+
import "./constants.es.js";
|
|
29
|
+
import "redux";
|
|
30
|
+
import "redux-thunk";
|
|
31
|
+
import "./actions.es.js";
|
|
32
|
+
import "./slot.es.js";
|
|
33
|
+
import "./control.es.js";
|
|
34
|
+
import "@emotion/serialize";
|
|
35
|
+
import "@emotion/utils";
|
|
36
|
+
import "./text-input.es.js";
|
|
37
|
+
import "./combobox.es.js";
|
|
38
|
+
import "use-sync-external-store/shim";
|
|
39
|
+
import "./types.es.js";
|
|
40
|
+
import "color";
|
|
41
|
+
import "scroll-into-view-if-needed";
|
|
42
|
+
import "./box-models.es.js";
|
|
43
|
+
import "css-box-model";
|
|
44
|
+
import "react-dom";
|
|
45
|
+
import "html-react-parser";
|
|
46
|
+
import "next/head";
|
|
47
|
+
import "@emotion/server/create-instance";
|
|
48
|
+
import "next/document";
|
|
49
|
+
import "cookie";
|
|
50
|
+
import "cors";
|
|
51
|
+
import "http-proxy";
|
|
52
|
+
import "set-cookie-parser";
|
|
53
|
+
import "uuid/v4";
|
|
54
|
+
import "corporate-ipsum";
|
|
55
|
+
import "next/link";
|
|
56
|
+
const ReadOnlyText = forwardRef(function ReadOnlyText2({
|
|
57
|
+
id,
|
|
58
|
+
text,
|
|
59
|
+
width,
|
|
60
|
+
margin
|
|
61
|
+
}, ref) {
|
|
62
|
+
const plaintext = (text == null ? void 0 : text.document) == null ? "" : getNodeText(text.document);
|
|
63
|
+
return /* @__PURE__ */ jsx("div", {
|
|
64
|
+
ref,
|
|
65
|
+
id,
|
|
66
|
+
className: cx(width, margin),
|
|
67
|
+
children: plaintext === "" ? /* @__PURE__ */ jsx(Placeholder, {}) : /* @__PURE__ */ jsx(Node, __spreadValues({}, text == null ? void 0 : text.document))
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
function Placeholder({
|
|
71
|
+
text = "Write some text..."
|
|
72
|
+
}) {
|
|
73
|
+
return /* @__PURE__ */ jsx("span", {
|
|
74
|
+
className: useStyle({
|
|
75
|
+
display: "inline-block",
|
|
76
|
+
width: 0,
|
|
77
|
+
maxWidth: "100%",
|
|
78
|
+
whiteSpace: "nowrap",
|
|
79
|
+
opacity: 0.333,
|
|
80
|
+
verticalAlign: "text-top"
|
|
81
|
+
}),
|
|
82
|
+
children: text
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function Node(props) {
|
|
86
|
+
switch (props.object) {
|
|
87
|
+
case "document":
|
|
88
|
+
return /* @__PURE__ */ jsx(Document, __spreadValues({}, props));
|
|
89
|
+
case "block":
|
|
90
|
+
return /* @__PURE__ */ jsx(Block, __spreadValues({}, props));
|
|
91
|
+
case "inline":
|
|
92
|
+
return /* @__PURE__ */ jsx(Inline, __spreadValues({}, props));
|
|
93
|
+
case "text":
|
|
94
|
+
return /* @__PURE__ */ jsx(Text, __spreadValues({}, props));
|
|
95
|
+
default:
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function Document({
|
|
100
|
+
nodes
|
|
101
|
+
}) {
|
|
102
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
103
|
+
children: nodes == null ? void 0 : nodes.map((node, idx) => /* @__PURE__ */ jsx(Node, __spreadValues({}, node), idx.toString()))
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function Block({
|
|
107
|
+
type,
|
|
108
|
+
data,
|
|
109
|
+
nodes
|
|
110
|
+
}) {
|
|
111
|
+
const component = {
|
|
112
|
+
paragraph: "p",
|
|
113
|
+
"heading-one": "h1",
|
|
114
|
+
"heading-two": "h2",
|
|
115
|
+
"heading-three": "h3",
|
|
116
|
+
"heading-four": "h4",
|
|
117
|
+
"heading-five": "h5",
|
|
118
|
+
"heading-six": "h6",
|
|
119
|
+
blockquote: "blockquote"
|
|
120
|
+
}[type];
|
|
121
|
+
return /* @__PURE__ */ jsx(DeviceOverrideBlock, {
|
|
122
|
+
as: component,
|
|
123
|
+
textAlign: data == null ? void 0 : data.textAlign,
|
|
124
|
+
children: nodes == null ? void 0 : nodes.map((node, idx) => /* @__PURE__ */ jsx(Node, __spreadValues({}, node), idx.toString()))
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
function Inline({
|
|
128
|
+
type,
|
|
129
|
+
nodes,
|
|
130
|
+
data
|
|
131
|
+
}) {
|
|
132
|
+
const children = nodes == null ? void 0 : nodes.map((node, idx) => /* @__PURE__ */ jsx(Node, __spreadValues({}, node), idx.toString()));
|
|
133
|
+
const linkClassName = useStyle({
|
|
134
|
+
textDecoration: "none"
|
|
135
|
+
});
|
|
136
|
+
switch (type) {
|
|
137
|
+
case "code":
|
|
138
|
+
return /* @__PURE__ */ jsx("code", {
|
|
139
|
+
children
|
|
140
|
+
});
|
|
141
|
+
case "superscript":
|
|
142
|
+
return /* @__PURE__ */ jsx("sup", {
|
|
143
|
+
children
|
|
144
|
+
});
|
|
145
|
+
case "subscript":
|
|
146
|
+
return /* @__PURE__ */ jsx("sub", {
|
|
147
|
+
children
|
|
148
|
+
});
|
|
149
|
+
case "link":
|
|
150
|
+
return /* @__PURE__ */ jsx(Link, {
|
|
151
|
+
className: linkClassName,
|
|
152
|
+
link: data,
|
|
153
|
+
children
|
|
154
|
+
});
|
|
155
|
+
default:
|
|
156
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
157
|
+
children
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function Text({
|
|
162
|
+
marks,
|
|
163
|
+
text = ""
|
|
164
|
+
}) {
|
|
165
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
166
|
+
children: (marks != null ? marks : []).reduce((element, mark) => /* @__PURE__ */ jsx(Mark, __spreadProps(__spreadValues({}, mark), {
|
|
167
|
+
children: element
|
|
168
|
+
})), /* @__PURE__ */ jsx(Fragment, {
|
|
169
|
+
children: text === "" ? "\uFEFF" : text
|
|
170
|
+
}))
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
const TYPOGRAPHY_MARK_TYPE = "typography";
|
|
174
|
+
function Mark({
|
|
175
|
+
type,
|
|
176
|
+
children,
|
|
177
|
+
data
|
|
178
|
+
}) {
|
|
179
|
+
if (type !== TYPOGRAPHY_MARK_TYPE)
|
|
180
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
181
|
+
children
|
|
182
|
+
});
|
|
183
|
+
return /* @__PURE__ */ jsx(Mark$1, {
|
|
184
|
+
value: data == null ? void 0 : data.value,
|
|
185
|
+
children
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
function getNodeText(node) {
|
|
189
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
190
|
+
switch (node.object) {
|
|
191
|
+
case "document":
|
|
192
|
+
return (_b = (_a = node == null ? void 0 : node.nodes) == null ? void 0 : _a.map((node2) => getNodeText(node2)).join("\n")) != null ? _b : "";
|
|
193
|
+
case "block":
|
|
194
|
+
return (_d = (_c = node == null ? void 0 : node.nodes) == null ? void 0 : _c.map((node2) => getNodeText(node2)).join(node.nodes.every((node2) => node2.object === "block") ? "\n" : "")) != null ? _d : "";
|
|
195
|
+
case "inline":
|
|
196
|
+
return (_f = (_e = node == null ? void 0 : node.nodes) == null ? void 0 : _e.map((node2) => getNodeText(node2)).join("")) != null ? _f : "";
|
|
197
|
+
case "text":
|
|
198
|
+
return (_g = node.text) != null ? _g : "";
|
|
199
|
+
default:
|
|
200
|
+
return "";
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
export { ReadOnlyText as default };
|
|
204
|
+
//# sourceMappingURL=ReadOnlyText.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReadOnlyText.es.js","sources":["../src/components/builtin/Text/ReadOnlyText.tsx"],"sourcesContent":["import { cx } from '@emotion/css'\nimport { ForwardedRef, forwardRef, ReactNode } from 'react'\nimport type { BlockJSON, DocumentJSON, InlineJSON, MarkJSON, NodeJSON, TextJSON } from 'slate'\nimport type {\n ElementIDValue,\n LinkValue,\n RichTextValue,\n} from '../../../prop-controllers/descriptors'\nimport { useStyle } from '../../../runtimes/react/use-style'\nimport { Link } from '../../shared/Link'\nimport DeviceOverrideBlock from './components/RichTextEditor/components/Block'\nimport DeviceOverrideMark from './components/RichTextEditor/components/Mark'\n\ntype Props = {\n id?: ElementIDValue\n text?: RichTextValue\n width?: string\n margin?: string\n}\n\nconst ReadOnlyText = forwardRef(function ReadOnlyText(\n { id, text, width, margin }: Props,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n const plaintext = text?.document == null ? '' : getNodeText(text.document)\n\n return (\n <div ref={ref} id={id} className={cx(width, margin)}>\n {plaintext === '' ? <Placeholder /> : <Node {...text?.document} />}\n </div>\n )\n})\n\nexport default ReadOnlyText\n\nfunction Placeholder({ text = 'Write some text...' }: { text?: string }) {\n return (\n <span\n className={useStyle({\n display: 'inline-block',\n width: 0,\n maxWidth: '100%',\n whiteSpace: 'nowrap',\n opacity: 0.333,\n verticalAlign: 'text-top',\n })}\n >\n {text}\n </span>\n )\n}\n\nfunction Node(props: NodeJSON) {\n switch (props.object) {\n case 'document':\n return <Document {...props} />\n\n case 'block':\n return <Block {...props} />\n\n case 'inline':\n return <Inline {...props} />\n\n case 'text':\n return <Text {...props} />\n\n default:\n return null\n }\n}\n\nfunction Document({ nodes }: DocumentJSON) {\n return (\n <>\n {nodes?.map((node, idx) => (\n <Node key={idx.toString()} {...node} />\n ))}\n </>\n )\n}\n\nfunction Block({ type, data, nodes }: BlockJSON) {\n const component = {\n paragraph: 'p',\n 'heading-one': 'h1',\n 'heading-two': 'h2',\n 'heading-three': 'h3',\n 'heading-four': 'h4',\n 'heading-five': 'h5',\n 'heading-six': 'h6',\n blockquote: 'blockquote',\n }[type]\n\n return (\n <DeviceOverrideBlock as={component} textAlign={data?.textAlign}>\n {nodes?.map((node, idx) => (\n <Node key={idx.toString()} {...node} />\n ))}\n </DeviceOverrideBlock>\n )\n}\n\nfunction Inline({ type, nodes, data }: InlineJSON) {\n const children = nodes?.map((node, idx) => <Node key={idx.toString()} {...node} />)\n const linkClassName = useStyle({ textDecoration: 'none' })\n\n switch (type) {\n case 'code':\n return <code>{children}</code>\n\n case 'superscript':\n return <sup>{children}</sup>\n\n case 'subscript':\n return <sub>{children}</sub>\n\n case 'link':\n return (\n <Link className={linkClassName} link={data as LinkValue | undefined}>\n {children}\n </Link>\n )\n\n default:\n return <>{children}</>\n }\n}\n\nfunction Text({ marks, text = '' }: TextJSON) {\n return (\n <>\n {(marks ?? []).reduce(\n (element, mark) => (\n <Mark {...mark}>{element}</Mark>\n ),\n <>{text === '' ? '\\uFEFF' : text}</>,\n )}\n </>\n )\n}\n\nconst TYPOGRAPHY_MARK_TYPE = 'typography'\n\nfunction Mark({ type, children, data }: MarkJSON & { children: ReactNode }) {\n if (type !== TYPOGRAPHY_MARK_TYPE) return <>{children}</>\n\n return <DeviceOverrideMark value={data?.value}>{children}</DeviceOverrideMark>\n}\n\nfunction getNodeText(node: NodeJSON): string {\n switch (node.object) {\n case 'document':\n return node?.nodes?.map(node => getNodeText(node)).join('\\n') ?? ''\n\n case 'block':\n return (\n node?.nodes\n ?.map(node => getNodeText(node))\n .join(node.nodes.every(node => node.object === 'block') ? '\\n' : '') ?? ''\n )\n\n case 'inline':\n return node?.nodes?.map(node => getNodeText(node)).join('') ?? ''\n\n case 'text':\n return node.text ?? ''\n\n default:\n return ''\n }\n}\n"],"names":["ReadOnlyText","forwardRef","id","text","width","margin","ref","plaintext","document","getNodeText","cx","_jsx","useStyle","display","maxWidth","whiteSpace","opacity","verticalAlign","props","object","nodes","_Fragment","map","node","idx","toString","type","data","component","paragraph","blockquote","textAlign","children","linkClassName","textDecoration","marks","reduce","element","mark","TYPOGRAPHY_MARK_TYPE","DeviceOverrideMark","value","join","every"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBMA,MAAAA,eAAeC,WAAW,uBAC9B;AAAA,EAAEC;AAAAA,EAAIC;AAAAA,EAAMC;AAAAA,EAAOC;AAAAA,GACnBC,KACA;AACA,QAAMC,YAAYJ,8BAAMK,aAAY,OAAO,KAAKC,YAAYN,KAAKK,QAAN;AAGzD,6BAAA,OAAA;AAAA,IAAK;AAAA,IAAU;AAAA,IAAQ,WAAWE,GAAGN,OAAOC,MAAR;AAAA,IAApC,UACGE,cAAc,KAAKI,oBAAC,aAApB,EAAA,IAAqCA,oBAAC,MAASR,mBAAAA,6BAAMK,SAAhB;AAAA,EAAA,CAF1C;AAKD,CAX8B;AAe/B,qBAAqB;AAAA,EAAEL,OAAO;AAAA,GAA2C;AAErE,6BAAA,QAAA;AAAA,IACE,WAAWS,SAAS;AAAA,MAClBC,SAAS;AAAA,MACTT,OAAO;AAAA,MACPU,UAAU;AAAA,MACVC,YAAY;AAAA,MACZC,SAAS;AAAA,MACTC,eAAe;AAAA,IAAA,CANE;AAAA,IASlBd,UAAAA;AAAAA,EAAAA,CAXL;AAcD;AAED,cAAce,OAAiB;AACrBA,UAAAA,MAAMC;AAAAA,SACP;AACI,iCAAC,UAAaD,mBAAAA,MAArB;AAAA,SAEG;AACI,iCAAC,OAAUA,mBAAAA,MAAlB;AAAA,SAEG;AACI,iCAAC,QAAWA,mBAAAA,MAAnB;AAAA,SAEG;AACI,iCAAC,MAASA,mBAAAA,MAAjB;AAAA;AAGO,aAAA;AAAA;AAEZ;AAED,kBAAkB;AAAA,EAAEE;AAAAA,GAAuB;AAEvC,6BAAAC,UAAA;AAAA,IACGD,UAAAA,+BAAOE,IAAI,CAAC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AAkB,UAAA;AAAA,IAAA,mCACa,IAAIe,OACb,CAACC,SAASC,SACR3B,oBAAC,uCAAS2B;MAAOD,UAAAA;AAAAA,IAAAA,EAAjB,GAEF1B,oBAAAU,UAAA;AAAA,MAAA,UAAGlB,SAAS,KAAK,WAAWA;AAAAA,IAAAA,CAJ7B,CAAA;AAAA,EAAA,CAFL;AAUD;AAED,MAAMoC,uBAAuB;AAE7B,cAAc;AAAA,EAAEb;AAAAA,EAAMM;AAAAA,EAAUL;AAAAA,GAA4C;AAC1E,MAAID,SAASa;AAAsB,+BAAOlB,UAAA;AAAA,MAAGW;AAAAA,IAAAA,CAAV;AAEnC,6BAAQQ,QAAD;AAAA,IAAoB,OAAOb,6BAAMc;AAAAA,IAAQT;AAAAA,EAAAA,CAAhD;AACD;AAED,qBAAqBT,MAAwB;;AACnCA,UAAAA,KAAKJ;AAAAA,SACN;AACII,aAAAA,yCAAMH,UAANG,mBAAaD,IAAIC,CAAQd,UAAAA,YAAYc,KAAD,GAAQmB,KAAK,UAAjDnB,YAA0D;AAAA,SAE9D;AACH,aACEA,yCAAMH,UAANG,mBACID,IAAIC,WAAQd,YAAYc,KAAD,GACxBmB,KAAKnB,KAAKH,MAAMuB,MAAMpB,WAAQA,MAAKJ,WAAW,OAAzC,IAAoD,OAAO,QAFnEI,YAE0E;AAAA,SAGzE;AACIA,aAAAA,yCAAMH,UAANG,mBAAaD,IAAIC,CAAQd,UAAAA,YAAYc,KAAD,GAAQmB,KAAK,QAAjDnB,YAAwD;AAAA,SAE5D;AACH,aAAOA,WAAKpB,SAALoB,YAAa;AAAA;AAGb,aAAA;AAAA;AAEZ;;"}
|
package/dist/Root.cjs.js
CHANGED
|
@@ -7,6 +7,8 @@ var next = require("./index.cjs.js");
|
|
|
7
7
|
var jsxRuntime = require("react/jsx-runtime");
|
|
8
8
|
var index = require("./index.cjs2.js");
|
|
9
9
|
var css = require("@emotion/css");
|
|
10
|
+
var serialize = require("@emotion/serialize");
|
|
11
|
+
var utils = require("@emotion/utils");
|
|
10
12
|
require("use-sync-external-store/shim/with-selector");
|
|
11
13
|
require("next/dynamic");
|
|
12
14
|
require("./constants.cjs.js");
|
|
@@ -18,7 +20,6 @@ require("./control.cjs.js");
|
|
|
18
20
|
require("./text-input.cjs.js");
|
|
19
21
|
require("./combobox.cjs.js");
|
|
20
22
|
require("use-sync-external-store/shim");
|
|
21
|
-
require("slate");
|
|
22
23
|
require("./types.cjs.js");
|
|
23
24
|
require("color");
|
|
24
25
|
require("scroll-into-view-if-needed");
|
|
@@ -98,7 +99,7 @@ const useInsertionEffect = (_a = React__namespace[useInsertionEffectSpecifier])
|
|
|
98
99
|
function useGlobalStyle(...args) {
|
|
99
100
|
if (isServer)
|
|
100
101
|
return css.injectGlobal(args);
|
|
101
|
-
const serialized =
|
|
102
|
+
const serialized = serialize.serializeStyles(args, css.cache.registered);
|
|
102
103
|
const sheetRef = React.useRef();
|
|
103
104
|
useInsertionEffect(() => {
|
|
104
105
|
const key = `${css.cache.key}-global`;
|
|
@@ -134,7 +135,7 @@ function useGlobalStyle(...args) {
|
|
|
134
135
|
return;
|
|
135
136
|
}
|
|
136
137
|
if (serialized.next != null) {
|
|
137
|
-
|
|
138
|
+
utils.insertStyles(css.cache, serialized.next, true);
|
|
138
139
|
}
|
|
139
140
|
if (sheet.tags.length > 0) {
|
|
140
141
|
const element = sheet.tags[sheet.tags.length - 1].nextElementSibling;
|