@makeswift/runtime 0.7.17 → 0.7.19
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 +1 -1
- package/dist/Box.es.js +1 -1
- package/dist/Button.cjs.js +2 -2
- package/dist/Button.es.js +2 -2
- package/dist/Carousel.cjs.js +3 -3
- package/dist/Carousel.es.js +3 -3
- package/dist/Countdown.cjs.js +3 -3
- package/dist/Countdown.es.js +3 -3
- package/dist/Divider.cjs.js +3 -3
- package/dist/Divider.es.js +3 -3
- package/dist/Embed.cjs.js +3 -3
- package/dist/Embed.es.js +3 -3
- package/dist/Form.cjs.js +1 -1
- package/dist/Form.es.js +1 -1
- package/dist/Image.cjs.js +3 -3
- package/dist/Image.es.js +3 -3
- package/dist/LiveProvider.cjs.js +3 -3
- package/dist/LiveProvider.es.js +3 -3
- package/dist/Navigation.cjs.js +3 -3
- package/dist/Navigation.es.js +3 -3
- package/dist/PreviewProvider.cjs.js +8 -8
- package/dist/PreviewProvider.cjs.js.map +1 -1
- package/dist/PreviewProvider.es.js +1 -1
- package/dist/ReadOnlyText.cjs.js +55 -55
- package/dist/ReadOnlyText.cjs.js.map +1 -1
- package/dist/ReadOnlyText.es.js +3 -3
- package/dist/Root.cjs.js +3 -3
- package/dist/Root.es.js +3 -3
- package/dist/SocialLinks.cjs.js +2 -2
- package/dist/SocialLinks.es.js +2 -2
- package/dist/Text.cjs.js +3 -3
- package/dist/Text.es.js +3 -3
- package/dist/Video.cjs.js +3 -3
- package/dist/Video.es.js +3 -3
- package/dist/builder.cjs.js +2 -2
- package/dist/builder.es.js +2 -2
- package/dist/components.cjs.js +1 -1
- package/dist/components.es.js +1 -1
- package/dist/constants.cjs.js +14 -14
- package/dist/constants.cjs.js.map +1 -1
- package/dist/constants.es.js +1 -1
- package/dist/control-serialization.cjs.js +41 -41
- package/dist/control-serialization.cjs.js.map +1 -1
- package/dist/control-serialization.es.js +1 -1
- package/dist/controls.cjs.js +46 -44
- package/dist/controls.cjs.js.map +1 -1
- package/dist/controls.es.js +2 -2
- package/dist/{rich-text.cjs.js → descriptors.cjs.js} +476 -459
- package/dist/descriptors.cjs.js.map +1 -0
- package/dist/{rich-text.es.js → descriptors.es.js} +467 -452
- package/dist/descriptors.es.js.map +1 -0
- package/dist/index.cjs.js +243 -210
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs2.js +1 -1
- package/dist/index.cjs5.js +16 -16
- package/dist/index.cjs5.js.map +1 -1
- package/dist/index.cjs6.js +3 -3
- package/dist/index.cjs7.js +35 -35
- package/dist/index.cjs7.js.map +1 -1
- package/dist/index.es.js +46 -13
- package/dist/index.es.js.map +1 -1
- package/dist/index.es2.js +1 -1
- package/dist/index.es5.js +1 -1
- package/dist/index.es6.js +3 -3
- package/dist/index.es7.js +1 -1
- package/dist/introspection.cjs.js +22 -22
- package/dist/introspection.cjs.js.map +1 -1
- package/dist/introspection.es.js +1 -1
- package/dist/main.cjs.js +1 -1
- package/dist/main.es.js +1 -1
- package/dist/next.cjs.js +3 -3
- package/dist/next.es.js +3 -3
- package/dist/prop-controllers.cjs.js +5 -5
- package/dist/prop-controllers.es.js +2 -2
- package/dist/react.cjs.js +3 -3
- package/dist/react.es.js +3 -3
- package/dist/slate.cjs.js +4 -4
- package/dist/slate.es.js +4 -4
- package/dist/types/src/components/builtin/Button/Button.d.ts +1 -1
- package/dist/types/src/components/builtin/Form/components/Field/components/Checkbox/index.d.ts +1 -1
- package/dist/types/src/components/builtin/Form/components/Field/components/PlaceholderTableField/index.d.ts +0 -1
- package/dist/types/src/components/builtin/Form/components/Field/components/PlaceholderTableField/index.d.ts.map +1 -1
- package/dist/types/src/components/builtin/Form/components/Field/index.d.ts +0 -1
- package/dist/types/src/components/builtin/Form/components/Field/index.d.ts.map +1 -1
- package/dist/types/src/components/builtin/Form/components/Spinner/index.d.ts +0 -1
- package/dist/types/src/components/builtin/Form/components/Spinner/index.d.ts.map +1 -1
- package/dist/types/src/components/builtin/Navigation/components/LinksPlaceholder/index.d.ts +0 -1
- package/dist/types/src/components/builtin/Navigation/components/LinksPlaceholder/index.d.ts.map +1 -1
- package/dist/types/src/components/builtin/Navigation/components/MobileMenu/index.d.ts +0 -1
- package/dist/types/src/components/builtin/Navigation/components/MobileMenu/index.d.ts.map +1 -1
- package/dist/types/src/components/builtin/SocialLinks/components/SocialLinksPlaceholder/index.d.ts +0 -1
- package/dist/types/src/components/builtin/SocialLinks/components/SocialLinksPlaceholder/index.d.ts.map +1 -1
- package/dist/types/src/components/builtin/SocialLinks/options.d.ts +0 -1
- package/dist/types/src/components/builtin/SocialLinks/options.d.ts.map +1 -1
- package/dist/types/src/components/builtin/Text/components/Element/block.d.ts +0 -1
- package/dist/types/src/components/builtin/Text/components/Element/block.d.ts.map +1 -1
- package/dist/types/src/components/builtin/Text/components/Element/element.d.ts +0 -1
- package/dist/types/src/components/builtin/Text/components/Element/element.d.ts.map +1 -1
- package/dist/types/src/components/builtin/Text/components/Element/inline.d.ts +0 -1
- package/dist/types/src/components/builtin/Text/components/Element/inline.d.ts.map +1 -1
- package/dist/types/src/components/builtin/Text/components/Leaf/leaf.d.ts +0 -1
- package/dist/types/src/components/builtin/Text/components/Leaf/leaf.d.ts.map +1 -1
- package/dist/types/src/components/page/Page.d.ts +0 -1
- package/dist/types/src/components/page/Page.d.ts.map +1 -1
- package/dist/types/src/components/shared/BackgroundsContainer/components/BackgroundVideo/index.d.ts +0 -1
- package/dist/types/src/components/shared/BackgroundsContainer/components/BackgroundVideo/index.d.ts.map +1 -1
- package/dist/types/src/components/shared/BackgroundsContainer/components/Backgrounds/index.d.ts +0 -1
- package/dist/types/src/components/shared/BackgroundsContainer/components/Backgrounds/index.d.ts.map +1 -1
- package/dist/types/src/controls/control.d.ts +3 -2
- package/dist/types/src/controls/control.d.ts.map +1 -1
- package/dist/types/src/controls/shape.d.ts +1 -1
- package/dist/types/src/controls/shape.d.ts.map +1 -1
- package/dist/types/src/controls/style.d.ts +17 -0
- package/dist/types/src/controls/style.d.ts.map +1 -1
- package/dist/types/src/next/api-handler.d.ts.map +1 -1
- package/dist/types/src/next/document.d.ts +0 -1
- package/dist/types/src/next/document.d.ts.map +1 -1
- package/dist/types/src/next/preview-mode.d.ts +0 -1
- package/dist/types/src/next/preview-mode.d.ts.map +1 -1
- package/dist/types/src/prop-controllers/descriptors.d.ts +1 -2
- package/dist/types/src/prop-controllers/descriptors.d.ts.map +1 -1
- package/dist/types/src/prop-controllers/instances.d.ts +3 -3
- package/dist/types/src/prop-controllers/instances.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/components/render-hook.d.ts +0 -1
- package/dist/types/src/runtimes/react/components/render-hook.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/controls/control.d.ts +3 -3
- package/dist/types/src/runtimes/react/controls/control.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/controls/list.d.ts +0 -1
- package/dist/types/src/runtimes/react/controls/list.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/controls/shape.d.ts +0 -1
- package/dist/types/src/runtimes/react/controls/shape.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/controls/style.d.ts +2 -2
- package/dist/types/src/runtimes/react/controls/style.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/controls.d.ts +0 -1
- package/dist/types/src/runtimes/react/controls.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/rich-text.cjs.js.map +0 -1
- package/dist/rich-text.es.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PreviewProvider.cjs.js","sources":["../src/state/modules/read-write-documents.ts","../src/state/modules/pointer.ts","../src/state/modules/element-imperative-handles.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 { Action, ActionTypes } from '../actions'\n\nexport type Point = { x: number; y: number }\n\ntype State = {\n pointer: Point | null\n}\n\nfunction getInitialState(): State {\n return { pointer: null }\n}\n\nexport function getPointer(state: State): Point | null {\n return state.pointer\n}\n\nexport function reducer(state: State = getInitialState(), action: Action): State {\n switch (action.type) {\n case ActionTypes.BUILDER_POINTER_MOVE:\n return { ...state, pointer: action.payload.pointer }\n\n default:\n return state\n }\n}\n","import { ElementImperativeHandle } from '../../runtimes/react/element-imperative-handle'\nimport { Action, ActionTypes } from '../actions'\n\ntype State = Map<string, Map<string, ElementImperativeHandle>>\n\nexport function getElementImperativeHandles(\n state: State,\n): Map<string, Map<string, ElementImperativeHandle>> {\n return state\n}\n\nfunction getInitialState(): State {\n return new Map()\n}\n\nexport function reducer(state: State = getInitialState(), action: Action): State {\n switch (action.type) {\n case ActionTypes.REGISTER_COMPONENT_HANDLE:\n return new Map(state).set(\n action.payload.documentKey,\n new Map(new Map(state.get(action.payload.documentKey) ?? [])).set(\n action.payload.elementKey,\n action.payload.componentHandle,\n ),\n )\n\n case ActionTypes.UNREGISTER_COMPONENT_HANDLE: {\n const byElementKey = new Map(state.get(action.payload.documentKey) ?? [])\n\n const deleted = byElementKey.delete(action.payload.elementKey)\n\n if (!deleted) return state\n\n return new Map(state).set(action.payload.documentKey, byElementKey)\n }\n\n default:\n return state\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 Router from 'next/router'\n\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 BuilderEditMode from './modules/builder-edit-mode'\nimport * as Pointer from './modules/pointer'\nimport * as ElementImperativeHandles from './modules/element-imperative-handles'\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 changePathnameStart,\n changePathnameComplete,\n elementFromPointChange,\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 builderEditMode: BuilderEditMode.reducer,\n pointer: Pointer.reducer,\n elementImperativeHandles: ElementImperativeHandles.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 getPointer(state: State): Pointer.Point | null {\n return Pointer.getPointer(state.pointer)\n}\n\nfunction getElementImperativeHandles(\n state: State,\n): Map<string, Map<string, ElementImperativeHandle>> {\n return ElementImperativeHandles.getElementImperativeHandles(state.elementImperativeHandles)\n}\n\nfunction getElementImperativeHandlesContainingElement(\n state: State,\n element: Element,\n): Map<string, Map<string, ElementImperativeHandle>> {\n const elementImperativeHandles = getElementImperativeHandles(state)\n const filteredElementImperativeHandles = new Map<string, Map<string, ElementImperativeHandle>>()\n\n for (const [documentKey, byElementKey] of elementImperativeHandles) {\n const filteredByElementKey = new Map<string, ElementImperativeHandle>()\n\n for (const [elementKey, elementImperativeHandle] of byElementKey) {\n const handleElement = elementImperativeHandle.getDomNode()\n\n if (handleElement?.contains(element)) {\n filteredByElementKey.set(elementKey, elementImperativeHandle)\n }\n }\n\n if (filteredByElementKey.size > 0) {\n filteredElementImperativeHandles.set(documentKey, filteredByElementKey)\n }\n }\n\n return filteredElementImperativeHandles\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(): ThunkAction<() => void, State, unknown, Action> {\n return (_dispatch, getState) => {\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 (ReactPage.getBuilderEditMode(getState()) === BuilderEditMode.BuilderEditMode.INTERACT) {\n return\n }\n\n if (!(event.target instanceof window.HTMLElement) || !event.target.isContentEditable) {\n window.parent.focus()\n }\n }\n\n function handleFocusOut(event: FocusEvent) {\n if (ReactPage.getBuilderEditMode(getState()) === BuilderEditMode.BuilderEditMode.INTERACT) {\n return\n }\n\n if (\n !(event.relatedTarget instanceof window.HTMLElement) ||\n !event.relatedTarget.isContentEditable\n ) {\n window.parent.focus()\n }\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\nfunction elementKeysFromElementFromPoint(\n elementFromPoint: Element | null,\n): ThunkAction<{ documentKey: string; elementKey: string } | null, State, unknown, Action> {\n return (_dispatch, getState) => {\n if (elementFromPoint == null) return null\n\n const elementImperativeHandles = getElementImperativeHandlesContainingElement(\n getState(),\n elementFromPoint,\n )\n const acendingDepthDocumentKeys = ReactPage.getDocumentKeysSortedByDepth(getState())\n const descendingDepthDocumentKeys = acendingDepthDocumentKeys.slice().reverse()\n\n let currentElement: Element | null = elementFromPoint\n let keys = null\n\n while (currentElement != null) {\n for (const documentKey of descendingDepthDocumentKeys) {\n const byElementKey = elementImperativeHandles.get(documentKey)\n\n if (byElementKey == null) continue\n\n for (const [elementKey, elementImperativeHandle] of byElementKey) {\n if (elementImperativeHandle.getDomNode() === currentElement) {\n return { documentKey, elementKey }\n }\n }\n }\n\n currentElement = currentElement.parentElement\n }\n\n return keys\n }\n}\n\nfunction startPollingElementFromPoint(): ThunkAction<() => void, State, unknown, Action> {\n return (dispatch, getState) => {\n let lastElementFromPoint: Element | null = null\n let animationFrameRequestId = requestAnimationFrame(handleAnimationFrameRequest)\n\n return () => {\n cancelAnimationFrame(animationFrameRequestId)\n }\n\n function handleAnimationFrameRequest() {\n const pointer = getPointer(getState())\n const elementFromPoint =\n pointer == null ? null : document.elementFromPoint(pointer.x, pointer.y)\n\n if (elementFromPoint !== lastElementFromPoint) {\n lastElementFromPoint = elementFromPoint\n\n const keys = dispatch(elementKeysFromElementFromPoint(elementFromPoint))\n\n dispatch(elementFromPointChange(keys))\n }\n\n animationFrameRequestId = 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 = dispatch(startHandlingFocusEvents())\n const unlockDocumentScroll = dispatch(lockDocumentScroll())\n const stopHandlingPointerMoveEvent = dispatch(startHandlingPointerMoveEvent())\n const stopPollingElementFromPoint = dispatch(startPollingElementFromPoint())\n dispatch(setIsInBuilder(true))\n\n return () => {\n stopMeasuringElements()\n stopMeasuringDocumentElement()\n stopHandlingFocusEvent()\n unlockDocumentScroll()\n stopHandlingPointerMoveEvent()\n stopPollingElementFromPoint()\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 Router.events.on('routeChangeStart', () => {\n messageChannel.port1.postMessage(changePathnameStart())\n })\n\n Router.events.on('routeChangeComplete', () => {\n messageChannel.port1.postMessage(changePathnameComplete())\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 case ActionTypes.ELEMENT_FROM_POINT_CHANGE:\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.SET_BUILDER_EDIT_MODE:\n messageChannel.port1.postMessage(action)\n window.getSelection()?.removeAllRanges()\n break\n\n case ActionTypes.CHANGE_PATHNAME: {\n const pathname = action.payload.pathname.replace(/^\\//, '')\n const currentPathname = Router.asPath.replace(/^\\//, '')\n\n if (pathname !== currentPathname) Router.push(pathname)\n break\n }\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":["removeIn","setIn","ReadOnlyDocuments.getInitialState","ReadOnlyDocuments.getDocument","getInitialState","ReadOnlyDocuments.reducer","ActionTypes","ReadOnlyDocuments.createDocument","combineReducers","Documents.reducer","ReactComponents.reducer","BoxModels.reducer","ComponentsMeta.reducer","PropControllers.reducer","PropControllerHandles.reducer","IsInBuilder.reducer","IsPreview.reducer","BuilderEditMode.reducer","Pointer.reducer","ElementImperativeHandles.reducer","BoxModels.getMeasurables","BoxModels.getBoxModels","BoxModels.getBoxModel","ComponentsMeta.getComponentsMeta","PropControllers.getComponentPropControllerDescriptors","Pointer.getPointer","ElementImperativeHandles.getElementImperativeHandles","BoxModels.measure","deepEqual","changeElementBoxModels","handleWheel","handlePointerMove","ReactPage.getBuilderEditMode","BuilderEditMode.BuilderEditMode","changeDocumentElementSize","ReactPage.getDocumentKeysSortedByDepth","elementFromPointChange","setIsInBuilder","BoxModels.isMeasurable","registerMeasurable","unregisterMeasurable","serializeControls","registerBuilderComponent","Router","changePathnameStart","changePathnameComplete","unregisterBuilderComponent","ReactPage.getElementPropControllerDescriptors","createPropController","messageBuilderPropController","registerPropControllers","ReactPage.getElement","ReactPage.isElementReference","PropControllerHandles.isPropControllersHandle","registerPropControllersHandle","PropControllerHandles.getPropControllersHandle","unregisterPropControllers","PropControllerHandles.getPropController","createStore","applyMiddleware","thunk","ElementImperativeHandle","registerDocument","ReactPage.createDocument","registerComponentHandle","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","StoreContext","MakeswiftProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,eAAe,MAAiC,WAAiD;AAC/F,MAAI,UAAU;AAEd,YAAU,QAAQ,CAAa,cAAA;AAE7B,QAAI,UAAU,MAAM;AAAgB,gBAAAA,UAAAA,SAAS,SAAS,UAAU,CAAC;AAGjE,QAAI,UAAU,MAAM;AAAgB,gBAAAA,UAAAA,SAAS,SAAS,UAAU,CAAC;AAGjE,QA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;AAAA,EACA;AAAA,GAKQ;AACR,QAAM,eAAsC,iCACvC,iBADuC;AAAA,IAE1C,WAAWC,kBAA0B,EAAE,cAAc;AAAA,IACrD,WAAWC,UAAU,kBAAgB,IAAI;AAAA,EAAA;AAG3C,SAAOR,MACL,YAAA,SACA,cACAC,MAAA,gBACEC,2BACA,2BAA2B,GAC3B,yBAAyB,GACzB,gCAAgC,GAChC,iCAAiC,MAAM,CACzC,CACF;AACF;AC1sBwC,yBAAA;AAAA,EAAEO;AAAAA,EAAQC;AAAAA,EAAUC;AAAAA,GAAoC;AACxFC,QAAAA,QAAQC,cACZ,MACEC,eAAmC;AAAA,IACjCC,gBAAgBC,8BAAyBC,SADR;AAAA,IAEjCN;AAAAA,IACAF;AAAAA,EAHF,CAAA,GAKF,CAACA,QAAQE,YAAT,CAPmB;AAUrBO,QAAAA,UAAU,MAAM;;AACRC,UAAAA,sBAAsBC,MAAMC,KAAKV,mDAAcW,cAAdX,YAA2B,CAAA,CAAtC,EAA0CY,IACpE,CAAC,CAACC,aAAaC,iBACbb,MAAMc,SAASC,QAAuBC,uBAAAA,yBAAyBJ,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,2BAAA,IAACC,kBAAa,UAAd;AAAA,IAAuB,OAAOpB;AAAAA,IAA9B,yCACGqB,wBAAD;AAAA,MAAmB;AAAA,MAAiBvB;AAAAA,IAAAA,CAApC;AAAA,EAAA,CAFJ;AAKD;;"}
|
|
1
|
+
{"version":3,"file":"PreviewProvider.cjs.js","sources":["../src/state/modules/read-write-documents.ts","../src/state/modules/pointer.ts","../src/state/modules/element-imperative-handles.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 { Action, ActionTypes } from '../actions'\n\nexport type Point = { x: number; y: number }\n\ntype State = {\n pointer: Point | null\n}\n\nfunction getInitialState(): State {\n return { pointer: null }\n}\n\nexport function getPointer(state: State): Point | null {\n return state.pointer\n}\n\nexport function reducer(state: State = getInitialState(), action: Action): State {\n switch (action.type) {\n case ActionTypes.BUILDER_POINTER_MOVE:\n return { ...state, pointer: action.payload.pointer }\n\n default:\n return state\n }\n}\n","import { ElementImperativeHandle } from '../../runtimes/react/element-imperative-handle'\nimport { Action, ActionTypes } from '../actions'\n\ntype State = Map<string, Map<string, ElementImperativeHandle>>\n\nexport function getElementImperativeHandles(\n state: State,\n): Map<string, Map<string, ElementImperativeHandle>> {\n return state\n}\n\nfunction getInitialState(): State {\n return new Map()\n}\n\nexport function reducer(state: State = getInitialState(), action: Action): State {\n switch (action.type) {\n case ActionTypes.REGISTER_COMPONENT_HANDLE:\n return new Map(state).set(\n action.payload.documentKey,\n new Map(new Map(state.get(action.payload.documentKey) ?? [])).set(\n action.payload.elementKey,\n action.payload.componentHandle,\n ),\n )\n\n case ActionTypes.UNREGISTER_COMPONENT_HANDLE: {\n const byElementKey = new Map(state.get(action.payload.documentKey) ?? [])\n\n const deleted = byElementKey.delete(action.payload.elementKey)\n\n if (!deleted) return state\n\n return new Map(state).set(action.payload.documentKey, byElementKey)\n }\n\n default:\n return state\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 Router from 'next/router'\n\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 BuilderEditMode from './modules/builder-edit-mode'\nimport * as Pointer from './modules/pointer'\nimport * as ElementImperativeHandles from './modules/element-imperative-handles'\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 changePathnameStart,\n changePathnameComplete,\n elementFromPointChange,\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 builderEditMode: BuilderEditMode.reducer,\n pointer: Pointer.reducer,\n elementImperativeHandles: ElementImperativeHandles.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 getPointer(state: State): Pointer.Point | null {\n return Pointer.getPointer(state.pointer)\n}\n\nfunction getElementImperativeHandles(\n state: State,\n): Map<string, Map<string, ElementImperativeHandle>> {\n return ElementImperativeHandles.getElementImperativeHandles(state.elementImperativeHandles)\n}\n\nfunction getElementImperativeHandlesContainingElement(\n state: State,\n element: Element,\n): Map<string, Map<string, ElementImperativeHandle>> {\n const elementImperativeHandles = getElementImperativeHandles(state)\n const filteredElementImperativeHandles = new Map<string, Map<string, ElementImperativeHandle>>()\n\n for (const [documentKey, byElementKey] of elementImperativeHandles) {\n const filteredByElementKey = new Map<string, ElementImperativeHandle>()\n\n for (const [elementKey, elementImperativeHandle] of byElementKey) {\n const handleElement = elementImperativeHandle.getDomNode()\n\n if (handleElement?.contains(element)) {\n filteredByElementKey.set(elementKey, elementImperativeHandle)\n }\n }\n\n if (filteredByElementKey.size > 0) {\n filteredElementImperativeHandles.set(documentKey, filteredByElementKey)\n }\n }\n\n return filteredElementImperativeHandles\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(): ThunkAction<() => void, State, unknown, Action> {\n return (_dispatch, getState) => {\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 (ReactPage.getBuilderEditMode(getState()) === BuilderEditMode.BuilderEditMode.INTERACT) {\n return\n }\n\n if (!(event.target instanceof window.HTMLElement) || !event.target.isContentEditable) {\n window.parent.focus()\n }\n }\n\n function handleFocusOut(event: FocusEvent) {\n if (ReactPage.getBuilderEditMode(getState()) === BuilderEditMode.BuilderEditMode.INTERACT) {\n return\n }\n\n if (\n !(event.relatedTarget instanceof window.HTMLElement) ||\n !event.relatedTarget.isContentEditable\n ) {\n window.parent.focus()\n }\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\nfunction elementKeysFromElementFromPoint(\n elementFromPoint: Element | null,\n): ThunkAction<{ documentKey: string; elementKey: string } | null, State, unknown, Action> {\n return (_dispatch, getState) => {\n if (elementFromPoint == null) return null\n\n const elementImperativeHandles = getElementImperativeHandlesContainingElement(\n getState(),\n elementFromPoint,\n )\n const acendingDepthDocumentKeys = ReactPage.getDocumentKeysSortedByDepth(getState())\n const descendingDepthDocumentKeys = acendingDepthDocumentKeys.slice().reverse()\n\n let currentElement: Element | null = elementFromPoint\n let keys = null\n\n while (currentElement != null) {\n for (const documentKey of descendingDepthDocumentKeys) {\n const byElementKey = elementImperativeHandles.get(documentKey)\n\n if (byElementKey == null) continue\n\n for (const [elementKey, elementImperativeHandle] of byElementKey) {\n if (elementImperativeHandle.getDomNode() === currentElement) {\n return { documentKey, elementKey }\n }\n }\n }\n\n currentElement = currentElement.parentElement\n }\n\n return keys\n }\n}\n\nfunction startPollingElementFromPoint(): ThunkAction<() => void, State, unknown, Action> {\n return (dispatch, getState) => {\n let lastElementFromPoint: Element | null = null\n let animationFrameRequestId = requestAnimationFrame(handleAnimationFrameRequest)\n\n return () => {\n cancelAnimationFrame(animationFrameRequestId)\n }\n\n function handleAnimationFrameRequest() {\n const pointer = getPointer(getState())\n const elementFromPoint =\n pointer == null ? null : document.elementFromPoint(pointer.x, pointer.y)\n\n if (elementFromPoint !== lastElementFromPoint) {\n lastElementFromPoint = elementFromPoint\n\n const keys = dispatch(elementKeysFromElementFromPoint(elementFromPoint))\n\n dispatch(elementFromPointChange(keys))\n }\n\n animationFrameRequestId = 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 = dispatch(startHandlingFocusEvents())\n const unlockDocumentScroll = dispatch(lockDocumentScroll())\n const stopHandlingPointerMoveEvent = dispatch(startHandlingPointerMoveEvent())\n const stopPollingElementFromPoint = dispatch(startPollingElementFromPoint())\n dispatch(setIsInBuilder(true))\n\n return () => {\n stopMeasuringElements()\n stopMeasuringDocumentElement()\n stopHandlingFocusEvent()\n unlockDocumentScroll()\n stopHandlingPointerMoveEvent()\n stopPollingElementFromPoint()\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 Router.events.on('routeChangeStart', () => {\n messageChannel.port1.postMessage(changePathnameStart())\n })\n\n Router.events.on('routeChangeComplete', () => {\n messageChannel.port1.postMessage(changePathnameComplete())\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 case ActionTypes.ELEMENT_FROM_POINT_CHANGE:\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.SET_BUILDER_EDIT_MODE:\n messageChannel.port1.postMessage(action)\n window.getSelection()?.removeAllRanges()\n break\n\n case ActionTypes.CHANGE_PATHNAME: {\n const pathname = action.payload.pathname.replace(/^\\//, '')\n const currentPathname = Router.asPath.replace(/^\\//, '')\n\n if (pathname !== currentPathname) Router.push(pathname)\n break\n }\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":["removeIn","setIn","ReadOnlyDocuments.getInitialState","ReadOnlyDocuments.getDocument","getInitialState","ReadOnlyDocuments.reducer","ActionTypes","ReadOnlyDocuments.createDocument","combineReducers","Documents.reducer","ReactComponents.reducer","BoxModels.reducer","ComponentsMeta.reducer","PropControllers.reducer","PropControllerHandles.reducer","IsInBuilder.reducer","IsPreview.reducer","BuilderEditMode.reducer","Pointer.reducer","ElementImperativeHandles.reducer","BoxModels.getMeasurables","BoxModels.getBoxModels","BoxModels.getBoxModel","ComponentsMeta.getComponentsMeta","PropControllers.getComponentPropControllerDescriptors","Pointer.getPointer","ElementImperativeHandles.getElementImperativeHandles","BoxModels.measure","deepEqual","changeElementBoxModels","handleWheel","handlePointerMove","ReactPage.getBuilderEditMode","BuilderEditMode.BuilderEditMode","changeDocumentElementSize","ReactPage.getDocumentKeysSortedByDepth","elementFromPointChange","setIsInBuilder","BoxModels.isMeasurable","registerMeasurable","unregisterMeasurable","serializeControls","registerBuilderComponent","Router","changePathnameStart","changePathnameComplete","unregisterBuilderComponent","descriptors","ReactPage.getElementPropControllerDescriptors","createPropController","messageBuilderPropController","registerPropControllers","ReactPage.getElement","ReactPage.isElementReference","PropControllerHandles.isPropControllersHandle","registerPropControllersHandle","PropControllerHandles.getPropControllersHandle","unregisterPropControllers","PropControllerHandles.getPropController","createStore","applyMiddleware","thunk","ElementImperativeHandle","registerDocument","ReactPage.createDocument","registerComponentHandle","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","StoreContext","MakeswiftProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,eAAe,MAAiC,WAAiD;AAC/F,MAAI,UAAU;AAEd,YAAU,QAAQ,CAAa,cAAA;AAE7B,QAAI,UAAU,MAAM;AAAgB,gBAAA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$4, q as getDocument$1, c as createDocument, s as getComponentsMeta$1, t as getComponentPropControllerDescriptors$1, o as getBuilderEditMode, u as getDocumentKeysSortedByDepth, v as getPropController, w as getPropControllersHandle, x as getElement, y as getElementPropControllerDescriptors, i as isElementReference, b as isPropControllersHandle, z as reducer$5, A as reducer$7, B as reducer$8, C as reducer$9, D as reducer$a, E as reducer$b, F as getInitialState$4 } from "./constants.es.js";
|
|
28
28
|
import { A as ActionTypes, q as unregisterMeasurable, v as registerMeasurable, w as registerBuilderComponent, x as changePathnameStart, y as changePathnameComplete, z as changeElementBoxModels, B as changeDocumentElementSize, C as handleWheel, D as handlePointerMove, E as elementFromPointChange, F as setIsInBuilder, G as unregisterBuilderComponent, H as unregisterPropControllers, I as registerPropControllers, J as registerPropControllersHandle, r as registerDocument, K as registerComponentHandle, L as messageBuilderPropController, M as registerDocumentEffect } from "./actions.es.js";
|
|
29
29
|
import { i as isMeasurable, a as getMeasurables$1, b as getBoxModels$1, m as measure, d as getBoxModel$1, r as reducer$6 } from "./box-models.es.js";
|
|
30
|
-
import {
|
|
30
|
+
import { az as BuilderEditMode, aA as createPropController, r as reducer$c } from "./descriptors.es.js";
|
|
31
31
|
import { a as serializeControls } from "./control-serialization.es.js";
|
|
32
32
|
import { jsx } from "react/jsx-runtime";
|
|
33
33
|
import "use-sync-external-store/shim/with-selector";
|
package/dist/ReadOnlyText.cjs.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
var css = require("@emotion/css");
|
|
4
4
|
var React = require("react");
|
|
5
|
-
var
|
|
5
|
+
var descriptors = require("./descriptors.cjs.js");
|
|
6
6
|
require("slate");
|
|
7
7
|
require("slate-react");
|
|
8
8
|
var next = require("./index.cjs.js");
|
|
@@ -22,10 +22,10 @@ require("./text-input.cjs.js");
|
|
|
22
22
|
require("./combobox.cjs.js");
|
|
23
23
|
require("use-sync-external-store/shim");
|
|
24
24
|
require("./types.cjs.js");
|
|
25
|
-
require("color");
|
|
26
|
-
require("scroll-into-view-if-needed");
|
|
27
25
|
require("./box-models.cjs.js");
|
|
28
26
|
require("css-box-model");
|
|
27
|
+
require("color");
|
|
28
|
+
require("scroll-into-view-if-needed");
|
|
29
29
|
require("react-dom");
|
|
30
30
|
require("html-react-parser");
|
|
31
31
|
require("next/head");
|
|
@@ -44,7 +44,7 @@ const ReadOnlyText = React.forwardRef(function ReadOnlyText2({
|
|
|
44
44
|
width,
|
|
45
45
|
margin
|
|
46
46
|
}, ref) {
|
|
47
|
-
const descendants = text == null ? [] :
|
|
47
|
+
const descendants = text == null ? [] : descriptors.richTextDTOtoDAO(text);
|
|
48
48
|
const descendantsAsString = getText(descendants);
|
|
49
49
|
return /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
50
50
|
ref,
|
|
@@ -87,25 +87,25 @@ function InlineElement({
|
|
|
87
87
|
textDecoration: "none"
|
|
88
88
|
});
|
|
89
89
|
switch (descendant.type) {
|
|
90
|
-
case
|
|
90
|
+
case descriptors.InlineType.Code:
|
|
91
91
|
return /* @__PURE__ */ jsxRuntime.jsx("code", {
|
|
92
92
|
children: /* @__PURE__ */ jsxRuntime.jsx(Descendants, {
|
|
93
93
|
descendants: descendant.children
|
|
94
94
|
})
|
|
95
95
|
});
|
|
96
|
-
case
|
|
96
|
+
case descriptors.InlineType.SuperScript:
|
|
97
97
|
return /* @__PURE__ */ jsxRuntime.jsx("sup", {
|
|
98
98
|
children: /* @__PURE__ */ jsxRuntime.jsx(Descendants, {
|
|
99
99
|
descendants: descendant.children
|
|
100
100
|
})
|
|
101
101
|
});
|
|
102
|
-
case
|
|
102
|
+
case descriptors.InlineType.SubScript:
|
|
103
103
|
return /* @__PURE__ */ jsxRuntime.jsx("sub", {
|
|
104
104
|
children: /* @__PURE__ */ jsxRuntime.jsx(Descendants, {
|
|
105
105
|
descendants: descendant.children
|
|
106
106
|
})
|
|
107
107
|
});
|
|
108
|
-
case
|
|
108
|
+
case descriptors.InlineType.Link:
|
|
109
109
|
return /* @__PURE__ */ jsxRuntime.jsx(index.Link, {
|
|
110
110
|
className: linkClassName,
|
|
111
111
|
link: descendant.link,
|
|
@@ -124,56 +124,56 @@ function BlockElement({
|
|
|
124
124
|
textAlign
|
|
125
125
|
})))];
|
|
126
126
|
switch (descendant.type) {
|
|
127
|
-
case
|
|
127
|
+
case descriptors.BlockType.Paragraph:
|
|
128
128
|
return /* @__PURE__ */ jsxRuntime.jsx("p", {
|
|
129
129
|
className: css.cx(...blockStyles),
|
|
130
130
|
children: /* @__PURE__ */ jsxRuntime.jsx(Descendants, {
|
|
131
131
|
descendants: descendant.children
|
|
132
132
|
})
|
|
133
133
|
});
|
|
134
|
-
case
|
|
134
|
+
case descriptors.BlockType.Heading1:
|
|
135
135
|
return /* @__PURE__ */ jsxRuntime.jsx("h1", {
|
|
136
136
|
className: css.cx(...blockStyles),
|
|
137
137
|
children: /* @__PURE__ */ jsxRuntime.jsx(Descendants, {
|
|
138
138
|
descendants: descendant.children
|
|
139
139
|
})
|
|
140
140
|
});
|
|
141
|
-
case
|
|
141
|
+
case descriptors.BlockType.Heading2:
|
|
142
142
|
return /* @__PURE__ */ jsxRuntime.jsx("h2", {
|
|
143
143
|
className: css.cx(...blockStyles),
|
|
144
144
|
children: /* @__PURE__ */ jsxRuntime.jsx(Descendants, {
|
|
145
145
|
descendants: descendant.children
|
|
146
146
|
})
|
|
147
147
|
});
|
|
148
|
-
case
|
|
148
|
+
case descriptors.BlockType.Heading3:
|
|
149
149
|
return /* @__PURE__ */ jsxRuntime.jsx("h3", {
|
|
150
150
|
className: css.cx(...blockStyles),
|
|
151
151
|
children: /* @__PURE__ */ jsxRuntime.jsx(Descendants, {
|
|
152
152
|
descendants: descendant.children
|
|
153
153
|
})
|
|
154
154
|
});
|
|
155
|
-
case
|
|
155
|
+
case descriptors.BlockType.Heading4:
|
|
156
156
|
return /* @__PURE__ */ jsxRuntime.jsx("h4", {
|
|
157
157
|
className: css.cx(...blockStyles),
|
|
158
158
|
children: /* @__PURE__ */ jsxRuntime.jsx(Descendants, {
|
|
159
159
|
descendants: descendant.children
|
|
160
160
|
})
|
|
161
161
|
});
|
|
162
|
-
case
|
|
162
|
+
case descriptors.BlockType.Heading5:
|
|
163
163
|
return /* @__PURE__ */ jsxRuntime.jsx("h5", {
|
|
164
164
|
className: css.cx(...blockStyles),
|
|
165
165
|
children: /* @__PURE__ */ jsxRuntime.jsx(Descendants, {
|
|
166
166
|
descendants: descendant.children
|
|
167
167
|
})
|
|
168
168
|
});
|
|
169
|
-
case
|
|
169
|
+
case descriptors.BlockType.Heading6:
|
|
170
170
|
return /* @__PURE__ */ jsxRuntime.jsx("h6", {
|
|
171
171
|
className: css.cx(...blockStyles),
|
|
172
172
|
children: /* @__PURE__ */ jsxRuntime.jsx(Descendants, {
|
|
173
173
|
descendants: descendant.children
|
|
174
174
|
})
|
|
175
175
|
});
|
|
176
|
-
case
|
|
176
|
+
case descriptors.BlockType.BlockQuote:
|
|
177
177
|
return /* @__PURE__ */ jsxRuntime.jsx("blockquote", {
|
|
178
178
|
className: css.cx(...blockStyles, next.useStyle({
|
|
179
179
|
padding: "0.5em 10px",
|
|
@@ -185,7 +185,7 @@ function BlockElement({
|
|
|
185
185
|
descendants: descendant.children
|
|
186
186
|
})
|
|
187
187
|
});
|
|
188
|
-
case
|
|
188
|
+
case descriptors.BlockType.OrderedList:
|
|
189
189
|
return /* @__PURE__ */ jsxRuntime.jsx("ol", {
|
|
190
190
|
className: css.cx(...blockStyles),
|
|
191
191
|
style: {
|
|
@@ -195,7 +195,7 @@ function BlockElement({
|
|
|
195
195
|
descendants: descendant.children
|
|
196
196
|
})
|
|
197
197
|
});
|
|
198
|
-
case
|
|
198
|
+
case descriptors.BlockType.UnorderedList:
|
|
199
199
|
return /* @__PURE__ */ jsxRuntime.jsx("ul", {
|
|
200
200
|
className: css.cx(...blockStyles),
|
|
201
201
|
style: {
|
|
@@ -205,14 +205,14 @@ function BlockElement({
|
|
|
205
205
|
descendants: descendant.children
|
|
206
206
|
})
|
|
207
207
|
});
|
|
208
|
-
case
|
|
208
|
+
case descriptors.BlockType.ListItem:
|
|
209
209
|
return /* @__PURE__ */ jsxRuntime.jsx("li", {
|
|
210
210
|
className: css.cx(...blockStyles),
|
|
211
211
|
children: /* @__PURE__ */ jsxRuntime.jsx(Descendants, {
|
|
212
212
|
descendants: descendant.children
|
|
213
213
|
})
|
|
214
214
|
});
|
|
215
|
-
case
|
|
215
|
+
case descriptors.BlockType.ListItemChild:
|
|
216
216
|
return /* @__PURE__ */ jsxRuntime.jsx("span", {
|
|
217
217
|
className: css.cx(...blockStyles),
|
|
218
218
|
children: /* @__PURE__ */ jsxRuntime.jsx(Descendants, {
|
|
@@ -232,22 +232,22 @@ function Descendants({
|
|
|
232
232
|
}, index2);
|
|
233
233
|
}
|
|
234
234
|
switch (descendant.type) {
|
|
235
|
-
case
|
|
236
|
-
case
|
|
237
|
-
case
|
|
238
|
-
case
|
|
235
|
+
case descriptors.InlineType.Link:
|
|
236
|
+
case descriptors.InlineType.Code:
|
|
237
|
+
case descriptors.InlineType.SubScript:
|
|
238
|
+
case descriptors.InlineType.SuperScript:
|
|
239
239
|
return /* @__PURE__ */ jsxRuntime.jsx(InlineElement, {
|
|
240
240
|
descendant
|
|
241
241
|
}, index2);
|
|
242
|
-
case
|
|
243
|
-
case
|
|
244
|
-
case
|
|
245
|
-
case
|
|
246
|
-
case
|
|
247
|
-
case
|
|
248
|
-
case
|
|
249
|
-
case
|
|
250
|
-
case
|
|
242
|
+
case descriptors.BlockType.Heading1:
|
|
243
|
+
case descriptors.BlockType.Heading2:
|
|
244
|
+
case descriptors.BlockType.Heading3:
|
|
245
|
+
case descriptors.BlockType.BlockQuote:
|
|
246
|
+
case descriptors.BlockType.Paragraph:
|
|
247
|
+
case descriptors.BlockType.OrderedList:
|
|
248
|
+
case descriptors.BlockType.UnorderedList:
|
|
249
|
+
case descriptors.BlockType.ListItem:
|
|
250
|
+
case descriptors.BlockType.ListItemChild:
|
|
251
251
|
return /* @__PURE__ */ jsxRuntime.jsx(BlockElement, {
|
|
252
252
|
descendant
|
|
253
253
|
}, index2);
|
|
@@ -261,15 +261,15 @@ function isBlock(descendant) {
|
|
|
261
261
|
if ("text" in descendant)
|
|
262
262
|
return false;
|
|
263
263
|
switch (descendant.type) {
|
|
264
|
-
case
|
|
265
|
-
case
|
|
266
|
-
case
|
|
267
|
-
case
|
|
268
|
-
case
|
|
269
|
-
case
|
|
270
|
-
case
|
|
271
|
-
case
|
|
272
|
-
case
|
|
264
|
+
case descriptors.BlockType.Heading1:
|
|
265
|
+
case descriptors.BlockType.Heading2:
|
|
266
|
+
case descriptors.BlockType.Heading3:
|
|
267
|
+
case descriptors.BlockType.BlockQuote:
|
|
268
|
+
case descriptors.BlockType.Paragraph:
|
|
269
|
+
case descriptors.BlockType.OrderedList:
|
|
270
|
+
case descriptors.BlockType.UnorderedList:
|
|
271
|
+
case descriptors.BlockType.ListItem:
|
|
272
|
+
case descriptors.BlockType.ListItemChild:
|
|
273
273
|
return true;
|
|
274
274
|
default:
|
|
275
275
|
return false;
|
|
@@ -281,20 +281,20 @@ function getTextByDescendant(descendant) {
|
|
|
281
281
|
return (_a = descendant.text) != null ? _a : "";
|
|
282
282
|
}
|
|
283
283
|
switch (descendant.type) {
|
|
284
|
-
case
|
|
285
|
-
case
|
|
286
|
-
case
|
|
287
|
-
case
|
|
284
|
+
case descriptors.InlineType.Link:
|
|
285
|
+
case descriptors.InlineType.Code:
|
|
286
|
+
case descriptors.InlineType.SubScript:
|
|
287
|
+
case descriptors.InlineType.SuperScript:
|
|
288
288
|
return (_b = descendant.children.map((descendant2) => getTextByDescendant(descendant2)).join("")) != null ? _b : "";
|
|
289
|
-
case
|
|
290
|
-
case
|
|
291
|
-
case
|
|
292
|
-
case
|
|
293
|
-
case
|
|
294
|
-
case
|
|
295
|
-
case
|
|
296
|
-
case
|
|
297
|
-
case
|
|
289
|
+
case descriptors.BlockType.Heading1:
|
|
290
|
+
case descriptors.BlockType.Heading2:
|
|
291
|
+
case descriptors.BlockType.Heading3:
|
|
292
|
+
case descriptors.BlockType.BlockQuote:
|
|
293
|
+
case descriptors.BlockType.Paragraph:
|
|
294
|
+
case descriptors.BlockType.OrderedList:
|
|
295
|
+
case descriptors.BlockType.UnorderedList:
|
|
296
|
+
case descriptors.BlockType.ListItem:
|
|
297
|
+
case descriptors.BlockType.ListItemChild:
|
|
298
298
|
return (_c = descendant.children.map((descendant2) => getTextByDescendant(descendant2)).join(descendant.children.every(isBlock) ? "\n" : "")) != null ? _c : "";
|
|
299
299
|
default:
|
|
300
300
|
return "";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReadOnlyText.cjs.js","sources":["../src/components/builtin/Text/ReadOnlyText.tsx"],"sourcesContent":["import { cx } from '@emotion/css'\nimport { ForwardedRef, forwardRef } from 'react'\nimport {\n Block,\n BlockType,\n Inline,\n InlineType,\n richTextDTOtoDAO,\n Text,\n Element,\n} from '../../../controls'\nimport type { ElementIDValue, RichTextValue } from '../../../prop-controllers/descriptors'\nimport { useStyle } from '../../../runtimes/react/use-style'\nimport { Link } from '../../shared/Link'\nimport { responsiveStyle } from '../../utils/responsive-style'\nimport { useTypographyClassName } from './components'\nimport useEnhancedTypography from './components/Leaf/leaf'\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 descendants = text == null ? [] : richTextDTOtoDAO(text)\n const descendantsAsString = getText(descendants)\n\n return (\n <div ref={ref} id={id} className={cx(width, margin)}>\n {descendantsAsString === '' ? <Placeholder /> : <Descendants descendants={descendants} />}\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\nexport interface TextProps {\n descendant: Text\n}\n\nexport function TextElement({ descendant }: TextProps) {\n const enhancedTypography = useEnhancedTypography(descendant.typography)\n const typographyClassName = useTypographyClassName(enhancedTypography)\n\n return (\n <span className={typographyClassName}>\n {descendant.text === '' ? '\\uFEFF' : descendant.text}\n </span>\n )\n}\n\nexport interface InlineProps {\n descendant: Inline\n}\n\nfunction InlineElement({ descendant }: InlineProps) {\n const linkClassName = useStyle({ textDecoration: 'none' })\n\n switch (descendant.type) {\n case InlineType.Code:\n return (\n <code>\n <Descendants descendants={descendant.children} />\n </code>\n )\n\n case InlineType.SuperScript:\n return (\n <sup>\n <Descendants descendants={descendant.children} />\n </sup>\n )\n\n case InlineType.SubScript:\n return (\n <sub>\n <Descendants descendants={descendant.children} />\n </sub>\n )\n\n case InlineType.Link:\n return (\n <Link className={linkClassName} link={descendant.link}>\n <Descendants descendants={descendant.children} />\n </Link>\n )\n }\n}\n\nexport interface BlockProps {\n descendant: Block\n}\n\nexport function BlockElement({ descendant }: BlockProps) {\n const blockStyles = [\n useStyle({ margin: 0 }),\n useStyle(responsiveStyle([descendant.textAlign], ([textAlign = 'left']) => ({ textAlign }))),\n ]\n\n switch (descendant.type) {\n case BlockType.Paragraph:\n return (\n <p className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </p>\n )\n case BlockType.Heading1:\n return (\n <h1 className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </h1>\n )\n case BlockType.Heading2:\n return (\n <h2 className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </h2>\n )\n case BlockType.Heading3:\n return (\n <h3 className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </h3>\n )\n case BlockType.Heading4:\n return (\n <h4 className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </h4>\n )\n case BlockType.Heading5:\n return (\n <h5 className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </h5>\n )\n case BlockType.Heading6:\n return (\n <h6 className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </h6>\n )\n case BlockType.BlockQuote:\n return (\n <blockquote\n className={cx(\n ...blockStyles,\n useStyle({\n padding: '0.5em 10px',\n fontSize: '1.25em',\n fontWeight: '300',\n borderLeft: '5px solid rgba(0, 0, 0, 0.1)',\n }),\n )}\n >\n <Descendants descendants={descendant.children} />\n </blockquote>\n )\n case BlockType.OrderedList:\n return (\n <ol className={cx(...blockStyles)} style={{ listStylePosition: 'inside' }}>\n <Descendants descendants={descendant.children} />\n </ol>\n )\n case BlockType.UnorderedList:\n return (\n <ul className={cx(...blockStyles)} style={{ listStylePosition: 'inside' }}>\n <Descendants descendants={descendant.children} />\n </ul>\n )\n case BlockType.ListItem:\n return (\n <li className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </li>\n )\n case BlockType.ListItemChild:\n return (\n <span className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </span>\n )\n }\n}\n\nfunction Descendants({ descendants }: { descendants: (Element | Text)[] }) {\n return (\n <>\n {descendants.map((descendant, index) => {\n if ('text' in descendant) {\n return <TextElement key={index} descendant={descendant} />\n }\n\n switch (descendant.type) {\n case InlineType.Link:\n case InlineType.Code:\n case InlineType.SubScript:\n case InlineType.SuperScript:\n return <InlineElement key={index} descendant={descendant} />\n case BlockType.Heading1:\n case BlockType.Heading2:\n case BlockType.Heading3:\n case BlockType.BlockQuote:\n case BlockType.Paragraph:\n case BlockType.OrderedList:\n case BlockType.UnorderedList:\n case BlockType.ListItem:\n case BlockType.ListItemChild:\n return <BlockElement key={index} descendant={descendant} />\n default:\n return null\n }\n })}\n </>\n )\n}\n\nfunction isBlock(descendant: Element | Text): descendant is Block {\n if ('text' in descendant) return false\n\n switch (descendant.type) {\n case BlockType.Heading1:\n case BlockType.Heading2:\n case BlockType.Heading3:\n case BlockType.BlockQuote:\n case BlockType.Paragraph:\n case BlockType.OrderedList:\n case BlockType.UnorderedList:\n case BlockType.ListItem:\n case BlockType.ListItemChild:\n return true\n\n default:\n return false\n }\n}\n\n/**\n * I am using `Element | Text` here to ensure that nothing from Slate \n * is imported so that the RichText maintains it's slim bundle size \n */\nfunction getTextByDescendant(descendant: Element | Text): string {\n if ('text' in descendant) {\n return descendant.text ?? ''\n }\n\n switch (descendant.type) {\n case InlineType.Link:\n case InlineType.Code:\n case InlineType.SubScript:\n case InlineType.SuperScript:\n return descendant.children.map(descendant => getTextByDescendant(descendant)).join('') ?? ''\n case BlockType.Heading1:\n case BlockType.Heading2:\n case BlockType.Heading3:\n case BlockType.BlockQuote:\n case BlockType.Paragraph:\n case BlockType.OrderedList:\n case BlockType.UnorderedList:\n case BlockType.ListItem:\n case BlockType.ListItemChild:\n return (\n descendant.children\n .map(descendant => getTextByDescendant(descendant))\n .join(descendant.children.every(isBlock) ? '\\n' : '') ?? ''\n )\n default:\n return ''\n }\n}\n\nfunction getText(descendant: (Element | Text)[]): string {\n return descendant.map(getTextByDescendant).join('\\n')\n}\n"],"names":["ReadOnlyText","forwardRef","id","text","width","margin","ref","descendants","richTextDTOtoDAO","descendantsAsString","getText","cx","_jsx","useStyle","display","maxWidth","whiteSpace","opacity","verticalAlign","descendant","enhancedTypography","useEnhancedTypography","typography","typographyClassName","useTypographyClassName","linkClassName","textDecoration","type","InlineType","Code","children","SuperScript","SubScript","Link","link","blockStyles","responsiveStyle","textAlign","BlockType","Paragraph","Heading1","Heading2","Heading3","Heading4","Heading5","Heading6","BlockQuote","padding","fontSize","fontWeight","borderLeft","OrderedList","listStylePosition","UnorderedList","ListItem","ListItemChild","_Fragment","map","index","getTextByDescendant","join","every","isBlock"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBMA,MAAAA,eAAeC,MAAAA,WAAW,uBAC9B;AAAA,EAAEC;AAAAA,EAAIC;AAAAA,EAAMC;AAA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Vb,SAAAA,UAAUe;AAAAA,SACVf,SAAAA,UAAUgB;AAAAA,SACVhB,SAAUiB,UAAAA;AAEXpC,aAAAA,iBAAWW,SACR2B,IAAItC,CAAcwC,gBAAAA,oBAAoBxC,WAAD,CADxC,EAEGyC,KAAKzC,WAAWW,SAAS+B,MAAMC,OAA1B,IAAqC,OAAO,EAFpD,MAAA3C,YAE2D;AAAA;AAGtD,aAAA;AAAA;AAEZ;AAED,iBAAiBA,YAAwC;AAChDA,SAAAA,WAAWsC,IAAIE,mBAAf,EAAoCC,KAAK,IAAzC;AACR;;;;"}
|
|
1
|
+
{"version":3,"file":"ReadOnlyText.cjs.js","sources":["../src/components/builtin/Text/ReadOnlyText.tsx"],"sourcesContent":["import { cx } from '@emotion/css'\nimport { ForwardedRef, forwardRef } from 'react'\nimport {\n Block,\n BlockType,\n Inline,\n InlineType,\n richTextDTOtoDAO,\n Text,\n Element,\n} from '../../../controls'\nimport type { ElementIDValue, RichTextValue } from '../../../prop-controllers/descriptors'\nimport { useStyle } from '../../../runtimes/react/use-style'\nimport { Link } from '../../shared/Link'\nimport { responsiveStyle } from '../../utils/responsive-style'\nimport { useTypographyClassName } from './components'\nimport useEnhancedTypography from './components/Leaf/leaf'\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 descendants = text == null ? [] : richTextDTOtoDAO(text)\n const descendantsAsString = getText(descendants)\n\n return (\n <div ref={ref} id={id} className={cx(width, margin)}>\n {descendantsAsString === '' ? <Placeholder /> : <Descendants descendants={descendants} />}\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\nexport interface TextProps {\n descendant: Text\n}\n\nexport function TextElement({ descendant }: TextProps) {\n const enhancedTypography = useEnhancedTypography(descendant.typography)\n const typographyClassName = useTypographyClassName(enhancedTypography)\n\n return (\n <span className={typographyClassName}>\n {descendant.text === '' ? '\\uFEFF' : descendant.text}\n </span>\n )\n}\n\nexport interface InlineProps {\n descendant: Inline\n}\n\nfunction InlineElement({ descendant }: InlineProps) {\n const linkClassName = useStyle({ textDecoration: 'none' })\n\n switch (descendant.type) {\n case InlineType.Code:\n return (\n <code>\n <Descendants descendants={descendant.children} />\n </code>\n )\n\n case InlineType.SuperScript:\n return (\n <sup>\n <Descendants descendants={descendant.children} />\n </sup>\n )\n\n case InlineType.SubScript:\n return (\n <sub>\n <Descendants descendants={descendant.children} />\n </sub>\n )\n\n case InlineType.Link:\n return (\n <Link className={linkClassName} link={descendant.link}>\n <Descendants descendants={descendant.children} />\n </Link>\n )\n }\n}\n\nexport interface BlockProps {\n descendant: Block\n}\n\nexport function BlockElement({ descendant }: BlockProps) {\n const blockStyles = [\n useStyle({ margin: 0 }),\n useStyle(responsiveStyle([descendant.textAlign], ([textAlign = 'left']) => ({ textAlign }))),\n ]\n\n switch (descendant.type) {\n case BlockType.Paragraph:\n return (\n <p className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </p>\n )\n case BlockType.Heading1:\n return (\n <h1 className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </h1>\n )\n case BlockType.Heading2:\n return (\n <h2 className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </h2>\n )\n case BlockType.Heading3:\n return (\n <h3 className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </h3>\n )\n case BlockType.Heading4:\n return (\n <h4 className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </h4>\n )\n case BlockType.Heading5:\n return (\n <h5 className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </h5>\n )\n case BlockType.Heading6:\n return (\n <h6 className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </h6>\n )\n case BlockType.BlockQuote:\n return (\n <blockquote\n className={cx(\n ...blockStyles,\n useStyle({\n padding: '0.5em 10px',\n fontSize: '1.25em',\n fontWeight: '300',\n borderLeft: '5px solid rgba(0, 0, 0, 0.1)',\n }),\n )}\n >\n <Descendants descendants={descendant.children} />\n </blockquote>\n )\n case BlockType.OrderedList:\n return (\n <ol className={cx(...blockStyles)} style={{ listStylePosition: 'inside' }}>\n <Descendants descendants={descendant.children} />\n </ol>\n )\n case BlockType.UnorderedList:\n return (\n <ul className={cx(...blockStyles)} style={{ listStylePosition: 'inside' }}>\n <Descendants descendants={descendant.children} />\n </ul>\n )\n case BlockType.ListItem:\n return (\n <li className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </li>\n )\n case BlockType.ListItemChild:\n return (\n <span className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </span>\n )\n }\n}\n\nfunction Descendants({ descendants }: { descendants: (Element | Text)[] }) {\n return (\n <>\n {descendants.map((descendant, index) => {\n if ('text' in descendant) {\n return <TextElement key={index} descendant={descendant} />\n }\n\n switch (descendant.type) {\n case InlineType.Link:\n case InlineType.Code:\n case InlineType.SubScript:\n case InlineType.SuperScript:\n return <InlineElement key={index} descendant={descendant} />\n case BlockType.Heading1:\n case BlockType.Heading2:\n case BlockType.Heading3:\n case BlockType.BlockQuote:\n case BlockType.Paragraph:\n case BlockType.OrderedList:\n case BlockType.UnorderedList:\n case BlockType.ListItem:\n case BlockType.ListItemChild:\n return <BlockElement key={index} descendant={descendant} />\n default:\n return null\n }\n })}\n </>\n )\n}\n\nfunction isBlock(descendant: Element | Text): descendant is Block {\n if ('text' in descendant) return false\n\n switch (descendant.type) {\n case BlockType.Heading1:\n case BlockType.Heading2:\n case BlockType.Heading3:\n case BlockType.BlockQuote:\n case BlockType.Paragraph:\n case BlockType.OrderedList:\n case BlockType.UnorderedList:\n case BlockType.ListItem:\n case BlockType.ListItemChild:\n return true\n\n default:\n return false\n }\n}\n\n/**\n * I am using `Element | Text` here to ensure that nothing from Slate \n * is imported so that the RichText maintains it's slim bundle size \n */\nfunction getTextByDescendant(descendant: Element | Text): string {\n if ('text' in descendant) {\n return descendant.text ?? ''\n }\n\n switch (descendant.type) {\n case InlineType.Link:\n case InlineType.Code:\n case InlineType.SubScript:\n case InlineType.SuperScript:\n return descendant.children.map(descendant => getTextByDescendant(descendant)).join('') ?? ''\n case BlockType.Heading1:\n case BlockType.Heading2:\n case BlockType.Heading3:\n case BlockType.BlockQuote:\n case BlockType.Paragraph:\n case BlockType.OrderedList:\n case BlockType.UnorderedList:\n case BlockType.ListItem:\n case BlockType.ListItemChild:\n return (\n descendant.children\n .map(descendant => getTextByDescendant(descendant))\n .join(descendant.children.every(isBlock) ? '\\n' : '') ?? ''\n )\n default:\n return ''\n }\n}\n\nfunction getText(descendant: (Element | Text)[]): string {\n return descendant.map(getTextByDescendant).join('\\n')\n}\n"],"names":["ReadOnlyText","forwardRef","id","text","width","margin","ref","descendants","richTextDTOtoDAO","descendantsAsString","getText","cx","_jsx","useStyle","display","maxWidth","whiteSpace","opacity","verticalAlign","descendant","enhancedTypography","useEnhancedTypography","typography","typographyClassName","useTypographyClassName","linkClassName","textDecoration","type","InlineType","Code","children","SuperScript","SubScript","Link","link","blockStyles","responsiveStyle","textAlign","BlockType","Paragraph","Heading1","Heading2","Heading3","Heading4","Heading5","Heading6","BlockQuote","padding","fontSize","fontWeight","borderLeft","OrderedList","listStylePosition","UnorderedList","ListItem","ListItemChild","_Fragment","map","index","getTextByDescendant","join","every","isBlock"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBMA,MAAAA,eAAeC,MAAAA,WAAW,uBAC9B;AAAA,EAAEC;AAAAA,EAAIC;AAAAA,EAAMC;AAAAA,EAAOC;AAAAA,GACnBC,KACA;AACMC,QAAAA,cAAcJ,QAAQ,OA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YAAUiB,UAAAA;AAEXpC,aAAAA,iBAAWW,SACR2B,IAAItC,CAAcwC,gBAAAA,oBAAoBxC,WAAD,CADxC,EAEGyC,KAAKzC,WAAWW,SAAS+B,MAAMC,OAA1B,IAAqC,OAAO,EAFpD,MAAA3C,YAE2D;AAAA;AAGtD,aAAA;AAAA;AAEZ;AAED,iBAAiBA,YAAwC;AAChDA,SAAAA,WAAWsC,IAAIE,mBAAf,EAAoCC,KAAK,IAAzC;AACR;;;;"}
|
package/dist/ReadOnlyText.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cx } from "@emotion/css";
|
|
2
2
|
import { forwardRef } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { at as richTextDTOtoDAO, aw as BlockType, ax as InlineType } from "./descriptors.es.js";
|
|
4
4
|
import "slate";
|
|
5
5
|
import "slate-react";
|
|
6
6
|
import { o as useStyle, r as responsiveStyle } from "./index.es.js";
|
|
@@ -20,10 +20,10 @@ import "./text-input.es.js";
|
|
|
20
20
|
import "./combobox.es.js";
|
|
21
21
|
import "use-sync-external-store/shim";
|
|
22
22
|
import "./types.es.js";
|
|
23
|
-
import "color";
|
|
24
|
-
import "scroll-into-view-if-needed";
|
|
25
23
|
import "./box-models.es.js";
|
|
26
24
|
import "css-box-model";
|
|
25
|
+
import "color";
|
|
26
|
+
import "scroll-into-view-if-needed";
|
|
27
27
|
import "react-dom";
|
|
28
28
|
import "html-react-parser";
|
|
29
29
|
import "next/head";
|
package/dist/Root.cjs.js
CHANGED
|
@@ -15,7 +15,7 @@ require("./constants.cjs.js");
|
|
|
15
15
|
require("redux");
|
|
16
16
|
require("redux-thunk");
|
|
17
17
|
require("./actions.cjs.js");
|
|
18
|
-
require("./
|
|
18
|
+
require("./descriptors.cjs.js");
|
|
19
19
|
require("slate");
|
|
20
20
|
require("slate-react");
|
|
21
21
|
require("./introspection.cjs.js");
|
|
@@ -23,10 +23,10 @@ require("./text-input.cjs.js");
|
|
|
23
23
|
require("./combobox.cjs.js");
|
|
24
24
|
require("use-sync-external-store/shim");
|
|
25
25
|
require("./types.cjs.js");
|
|
26
|
-
require("color");
|
|
27
|
-
require("scroll-into-view-if-needed");
|
|
28
26
|
require("./box-models.cjs.js");
|
|
29
27
|
require("css-box-model");
|
|
28
|
+
require("color");
|
|
29
|
+
require("scroll-into-view-if-needed");
|
|
30
30
|
require("react-dom");
|
|
31
31
|
require("html-react-parser");
|
|
32
32
|
require("next/head");
|