@replohq/canopy-sdk 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_vendor/replo-utils/lib/errors.d.ts +83 -0
- package/_vendor/replo-utils/lib/fonts.mjs +2 -40
- package/_vendor/replo-utils/lib/json.mjs +1 -1
- package/_vendor/replo-utils/lib/misc.mjs +2 -2
- package/_vendor/schemas/agentTools/customIntegrations/loaders/levanta.d.ts +49 -0
- package/_vendor/schemas/agentTools/customIntegrations/loaders/levanta.mjs +36 -0
- package/_vendor/schemas/agentTools/customIntegrations/loaders/product.d.ts +340 -0
- package/_vendor/schemas/agentTools/customIntegrations/loaders/product.mjs +51 -0
- package/_vendor/schemas/agentTools/customIntegrations/loaders/yotpo.d.ts +37 -0
- package/_vendor/schemas/agentTools/customIntegrations/loaders/yotpo.mjs +37 -0
- package/{cart/cart-schema.js → _vendor/schemas/cart.mjs} +17 -26
- package/_vendor/schemas/designLibrary.d.ts +4 -4
- package/_vendor/schemas/errors.d.ts +438 -0
- package/_vendor/schemas/errors.mjs +932 -0
- package/_vendor/schemas/generated/errors.d.ts +61 -0
- package/_vendor/schemas/generated/selectMode.d.ts +102 -0
- package/{loaders/loader-keys.d.ts → _vendor/schemas/loaderKeys.d.ts} +4 -4
- package/{loaders/loader-keys.js → _vendor/schemas/loaderKeys.mjs} +7 -8
- package/_vendor/schemas/objectType.d.ts +1038 -0
- package/_vendor/schemas/objectType.mjs +2 -0
- package/_vendor/schemas/registry.d.ts +539 -0
- package/_vendor/schemas/sandboxFiles.d.ts +36 -0
- package/_vendor/schemas/savedStyles.d.ts +2 -2
- package/_vendor/schemas/selectMode.d.ts +471 -0
- package/_vendor/schemas/selectMode.mjs +120 -4
- package/_vendor/schemas/sellingPlan.d.ts +60 -0
- package/_vendor/schemas/sellingPlan.mjs +1 -0
- package/cart/buy-now-action.js +3 -3
- package/cart/buy-now-action.js.map +2 -2
- package/cart/cart-provider.js +2 -2
- package/cart/cart-provider.js.map +2 -2
- package/cart/cart-types.d.ts +2 -1
- package/cart/cart-types.js.map +2 -2
- package/cart/hooks/use-add-to-cart.js +1 -1
- package/cart/hooks/use-add-to-cart.js.map +2 -2
- package/cart/hooks/use-buy-now.js +2 -2
- package/cart/hooks/use-buy-now.js.map +2 -2
- package/cart/utils/variant-to-cart-line.d.ts +1 -2
- package/cart/utils/variant-to-cart-line.js.map +1 -1
- package/chunk-4XLTENDR.mjs +33 -0
- package/chunk-A7EUNWRQ.mjs +765 -0
- package/{chunk-ME5W2TJM.mjs → chunk-OCB5XQYL.mjs} +2 -2
- package/chunk-QFYIXADC.mjs +42 -0
- package/editor/LinkInterceptor.js +4 -0
- package/editor/LinkInterceptor.js.map +2 -2
- package/editor/select-mode/EditorSelection.js +74 -1
- package/editor/select-mode/EditorSelection.js.map +2 -2
- package/editor/select-mode/descriptor/elementDescriptor.d.ts +13 -2
- package/editor/select-mode/descriptor/elementDescriptor.js +19 -31
- package/editor/select-mode/descriptor/elementDescriptor.js.map +2 -2
- package/editor/select-mode/descriptor/styleExtraction.d.ts +3 -0
- package/editor/select-mode/descriptor/styleExtraction.js +271 -0
- package/editor/select-mode/descriptor/styleExtraction.js.map +7 -0
- package/editor/select-mode/displayModeStore.d.ts +10 -0
- package/editor/select-mode/displayModeStore.js +47 -0
- package/editor/select-mode/displayModeStore.js.map +7 -0
- package/editor/select-mode/fast-refresh-relay.d.ts +3 -0
- package/editor/select-mode/fast-refresh-relay.js +35 -0
- package/editor/select-mode/fast-refresh-relay.js.map +7 -0
- package/editor/select-mode/fiber.d.ts +17 -0
- package/editor/select-mode/fiber.js +103 -34
- package/editor/select-mode/fiber.js.map +2 -2
- package/editor/select-mode/hooks/useEditModeStateMachine.d.ts +20 -0
- package/editor/select-mode/hooks/useEditModeStateMachine.js +226 -0
- package/editor/select-mode/hooks/useEditModeStateMachine.js.map +7 -0
- package/editor/select-mode/hooks/useOptimisticOverrides.d.ts +20 -0
- package/editor/select-mode/hooks/useOptimisticOverrides.js +284 -0
- package/editor/select-mode/hooks/useOptimisticOverrides.js.map +7 -0
- package/editor/select-mode/hooks/useParentMessaging.d.ts +17 -2
- package/editor/select-mode/hooks/useParentMessaging.js +66 -1
- package/editor/select-mode/hooks/useParentMessaging.js.map +2 -2
- package/editor/select-mode/hooks/useSelectModeController.js +5 -6
- package/editor/select-mode/hooks/useSelectModeController.js.map +2 -2
- package/editor/select-mode/hooks/useSelectionHover.js +16 -1
- package/editor/select-mode/hooks/useSelectionHover.js.map +2 -2
- package/editor/select-mode/hooks/useSelectionInteractions.d.ts +7 -2
- package/editor/select-mode/hooks/useSelectionInteractions.js +57 -18
- package/editor/select-mode/hooks/useSelectionInteractions.js.map +2 -2
- package/editor/select-mode/hooks/useSiblingResolution.d.ts +6 -0
- package/editor/select-mode/hooks/useSiblingResolution.js +59 -0
- package/editor/select-mode/hooks/useSiblingResolution.js.map +7 -0
- package/editor/select-mode/inlineTextMarks.d.ts +6 -0
- package/editor/select-mode/inlineTextMarks.js +25 -0
- package/editor/select-mode/inlineTextMarks.js.map +7 -0
- package/editor/select-mode/interactions/selectionGeometry.js +4 -0
- package/editor/select-mode/interactions/selectionGeometry.js.map +2 -2
- package/editor/select-mode/selectionFrame.d.ts +5 -0
- package/editor/select-mode/selectionFrame.js +25 -1
- package/editor/select-mode/selectionFrame.js.map +2 -2
- package/editor/select-mode/symbolicate.js +32 -10
- package/editor/select-mode/symbolicate.js.map +2 -2
- package/editor/select-mode/tiptapInlineEditor.d.ts +23 -0
- package/editor/select-mode/tiptapInlineEditor.js +120 -0
- package/editor/select-mode/tiptapInlineEditor.js.map +7 -0
- package/gateways/canopy-api.d.ts +3 -3
- package/gateways/canopy-api.js +3 -3
- package/gateways/canopy-api.js.map +2 -2
- package/loaders/collection-loader.d.ts +1 -1
- package/loaders/collection-loader.js +1 -1
- package/loaders/collection-loader.js.map +2 -2
- package/loaders/collection-products-loader.d.ts +1 -1
- package/loaders/collection-products-loader.js +1 -1
- package/loaders/collection-products-loader.js.map +2 -2
- package/loaders/invoke-loader.d.ts +2 -2
- package/loaders/invoke-loader.js +2 -2
- package/loaders/invoke-loader.js.map +2 -2
- package/loaders/levanta-product-loader.d.ts +1 -1
- package/loaders/levanta-product-loader.js +1 -1
- package/loaders/levanta-product-loader.js.map +2 -2
- package/loaders/okendo-reviews-loader.js +1 -1
- package/loaders/okendo-reviews-loader.js.map +2 -2
- package/loaders/prefetch-loaders.d.ts +1 -1
- package/loaders/prefetch-loaders.js.map +1 -1
- package/loaders/product-loader.d.ts +1 -1
- package/loaders/product-loader.js +1 -1
- package/loaders/product-loader.js.map +2 -2
- package/loaders/rebuy-recommendations-loader.js +1 -1
- package/loaders/rebuy-recommendations-loader.js.map +2 -2
- package/loaders/yotpo-review-aggregate-loader.d.ts +1 -1
- package/loaders/yotpo-review-aggregate-loader.js +1 -1
- package/loaders/yotpo-review-aggregate-loader.js.map +2 -2
- package/loaders/yotpo-reviews-loader.d.ts +1 -1
- package/loaders/yotpo-reviews-loader.js +1 -1
- package/loaders/yotpo-reviews-loader.js.map +2 -2
- package/package.json +9 -1
- package/cart/cart-schema.js.map +0 -7
- package/lib/canopy-error.d.ts +0 -25
- package/lib/canopy-error.js +0 -24
- package/lib/canopy-error.js.map +0 -7
- package/loaders/loader-keys.js.map +0 -7
- package/loaders/loader-schemas.d.ts +0 -755
- package/loaders/loader-schemas.js +0 -257
- package/loaders/loader-schemas.js.map +0 -7
- package/{cart/cart-schema.d.ts → _vendor/schemas/cart.d.ts} +0 -0
- package/{chunk-NCKKAFF7.mjs → chunk-ILGEM42C.mjs} +7 -7
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../editor/select-mode/fiber.ts"],
|
|
4
|
-
"sourcesContent": ["// =============================================================================\n// React Fiber / Source Location Utilities\n// =============================================================================\n\nexport interface SourceLocation {\n filePath: string;\n lineNumber: number;\n columnNumber?: number;\n componentName?: string;\n}\n\nexport interface EventHandlers {\n onClick?: string;\n onMouseEnter?: string;\n onMouseLeave?: string;\n onFocus?: string;\n onBlur?: string;\n}\n\nexport interface ReactFiber {\n _debugSource?: {\n fileName: string;\n lineNumber: number;\n columnNumber?: number;\n };\n _debugStack?: unknown;\n _debugOwner?: ReactFiber;\n type?:\n | { name?: string; displayName?: string }\n | string\n | ((...args: unknown[]) => unknown)\n | null;\n return?: ReactFiber | null;\n memoizedProps?: Record<string, unknown>;\n pendingProps?: Record<string, unknown>;\n}\n\ninterface ReactFiberWithHandlers extends ReactFiber {\n memoizedProps?: Record<string, unknown>;\n pendingProps?: Record<string, unknown>;\n}\n\n// Frames produced by React's own JSX runtime \u2014 these come first in\n// `_debugStack.stack` because the `Error` is constructed inside `jsxDEV`. We\n// want the frame *above* them, which is the actual JSX call site.\n//\n// Turbopack rewrites `node_modules/next/dist/compiled/react-server-dom-*` and\n// friends into mangled chunk paths like\n// `_next/static/chunks/<hash>_next_dist_compiled_react-server-dom-turbopack_<hash>._.js`,\n// so we match both the human-readable module paths and the chunk-name forms.\n// Without this, `_debugStack`'s top frame inside React's RSC runtime gets\n// surfaced as the \"host\" source location for every text node on the page \u2014\n// which then symbolicates back to bundled React, not user code.\nconst REACT_INTERNAL_FRAME_PATTERNS = [\n /react.*jsx-dev-runtime/,\n /react.*jsx-runtime/,\n /react-dom\\//,\n /react\\/cjs\\/react\\./,\n /react-server-dom/,\n /react_server_dom/,\n /next[/_.]dist[/_.]compiled/,\n /\\/node_modules\\/(next|react|react-dom)\\//,\n];\n\nfunction isReactInternalFrame(fileName: string): boolean {\n return REACT_INTERNAL_FRAME_PATTERNS.some((pattern) => {\n return pattern.test(fileName);\n });\n}\n\nfunction parseDebugStackSource(\n debugStack: unknown,\n): ReactFiber[\"_debugSource\"] | null {\n let stackText: string | null = null;\n\n if (typeof debugStack === \"string\") {\n stackText = debugStack;\n } else if (\n typeof debugStack === \"object\" &&\n debugStack &&\n \"stack\" in debugStack\n ) {\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const stack = (debugStack as { stack?: unknown }).stack;\n if (typeof stack === \"string\") {\n stackText = stack;\n }\n }\n\n if (!stackText) {\n return null;\n }\n\n for (const rawLine of stackText.split(\"\\n\")) {\n const line = rawLine.trim();\n if (!line) {\n continue;\n }\n\n const stackFrameMatch =\n line.match(/^at\\s+(?:.*\\()?(.*):(\\d+):(\\d+)\\)?$/) ??\n line.match(/^(.*):(\\d+):(\\d+)$/);\n\n if (!stackFrameMatch) {\n continue;\n }\n\n const fileName = stackFrameMatch[1]?.trim();\n const lineNumber = Number.parseInt(stackFrameMatch[2] ?? \"\", 10);\n const columnNumber = Number.parseInt(stackFrameMatch[3] ?? \"\", 10);\n\n if (\n !fileName ||\n !Number.isFinite(lineNumber) ||\n !Number.isFinite(columnNumber)\n ) {\n continue;\n }\n\n if (isReactInternalFrame(fileName)) {\n continue;\n }\n\n return {\n fileName,\n lineNumber,\n columnNumber,\n };\n }\n\n return null;\n}\n\nexport function getFiberFromElement(element: HTMLElement): ReactFiber | null {\n if (!element || typeof element !== \"object\") {\n return null;\n }\n\n const symbolKeys = Object.getOwnPropertySymbols(element);\n const fiberSymbolKey = symbolKeys.find((symbolKey) => {\n return symbolKey.toString().includes(\"reactFiber\");\n });\n if (fiberSymbolKey) {\n return (\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n (element as unknown as Record<symbol, ReactFiber>)[fiberSymbolKey] ?? null\n );\n }\n\n const keys = Object.keys(element);\n const fiberKey = keys.find((key) => key.startsWith(\"__reactFiber$\"));\n if (fiberKey) {\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n return (element as unknown as Record<string, ReactFiber>)[fiberKey] ?? null;\n }\n const instanceKey = keys.find((key) => {\n return key.startsWith(\"__reactInternalInstance$\");\n });\n if (instanceKey) {\n return (\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n (element as unknown as Record<string, ReactFiber>)[instanceKey] ?? null\n );\n }\n\n const possibleFiberKey = keys.find((key) => {\n if (!key.startsWith(\"__react\")) {\n return false;\n }\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const value = (element as unknown as Record<string, unknown>)[key];\n return value && typeof value === \"object\" && \"_debugSource\" in value;\n });\n\n if (possibleFiberKey) {\n return (\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n (element as unknown as Record<string, ReactFiber>)[possibleFiberKey] ??\n null\n );\n }\n\n return null;\n}\n\nexport function getComponentName(\n fiber: ReactFiber | null | undefined,\n): string | undefined {\n if (!fiber?.type) {\n return undefined;\n }\n\n if (typeof fiber.type === \"string\") {\n return undefined;\n }\n\n if (typeof fiber.type === \"function\") {\n return fiber.type.name || undefined;\n }\n\n if (typeof fiber.type === \"object\") {\n return fiber.type.displayName ?? fiber.type.name ?? undefined;\n }\n\n return undefined;\n}\n\nexport function findDebugSource(\n fiber: ReactFiber,\n maxDepth = 50,\n): { source: ReactFiber[\"_debugSource\"]; componentName?: string } | null {\n let current: ReactFiber | null | undefined = fiber;\n let depth = 0;\n\n while (current && depth < maxDepth) {\n if (current._debugSource) {\n return {\n source: current._debugSource,\n componentName: getComponentName(current),\n };\n }\n\n if (current._debugOwner?._debugSource) {\n return {\n source: current._debugOwner._debugSource,\n componentName: getComponentName(current._debugOwner),\n };\n }\n\n current = current.return;\n depth++;\n }\n\n return null;\n}\n\n// NOTE (Derek, 2026-02-12): React 19 changed the internal fiber shape \u2014 _debugSource and\n// _debugOwner behave differently. We keep both versions so the scaffold works regardless\n// of the host project's React version. findDebugSource handles 18, this handles 19.\nexport function findDebugSourceReact19(\n fiber: ReactFiber,\n): { source: ReactFiber[\"_debugSource\"]; componentName?: string } | null {\n let current: ReactFiber | null | undefined = fiber;\n let depth = 0;\n const maxDepth = 50;\n\n while (current && depth < maxDepth) {\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const anyFiber = current as unknown as Record<string, unknown>;\n const possibleSourceKeys = [\n \"_debugSource\",\n \"__source\",\n \"_source\",\n \"debugSource\",\n ];\n\n for (const key of possibleSourceKeys) {\n const source = anyFiber[key];\n if (source && typeof source === \"object\" && \"fileName\" in source) {\n return {\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n source: source as ReactFiber[\"_debugSource\"],\n componentName: getComponentName(current),\n };\n }\n }\n\n if (current.memoizedProps) {\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const props = current.memoizedProps as Record<string, unknown>;\n if (props.__source && typeof props.__source === \"object\") {\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const source = props.__source as {\n fileName?: string;\n lineNumber?: number;\n columnNumber?: number;\n };\n if (source.fileName && source.lineNumber) {\n return {\n source: {\n fileName: source.fileName,\n lineNumber: source.lineNumber,\n columnNumber: source.columnNumber,\n },\n componentName: getComponentName(current),\n };\n }\n }\n }\n\n const debugStackSource =\n parseDebugStackSource(current._debugStack) ??\n parseDebugStackSource(current._debugOwner?._debugStack);\n if (debugStackSource) {\n return {\n source: debugStackSource,\n componentName: getComponentName(current),\n };\n }\n\n current = current.return;\n depth++;\n }\n\n return null;\n}\n\nexport function getSourceLocation(\n element: HTMLElement,\n): SourceLocation | undefined {\n let currentElement: HTMLElement | null = element;\n\n while (currentElement) {\n const fiber = getFiberFromElement(currentElement);\n if (fiber) {\n const debugInfo = findDebugSource(fiber) ?? findDebugSourceReact19(fiber);\n if (debugInfo?.source) {\n return {\n filePath: debugInfo.source.fileName,\n lineNumber: debugInfo.source.lineNumber,\n columnNumber: debugInfo.source.columnNumber,\n componentName: debugInfo.componentName ?? undefined,\n };\n }\n }\n\n currentElement = currentElement.parentElement;\n }\n\n return undefined;\n}\n\n/**\n * Extract event handlers from React fiber or DOM element\n *\n * @author Kevin O'Connell 2026-04-17\n */\nexport function extractEventHandlers(element: HTMLElement): EventHandlers {\n const handlers: EventHandlers = {};\n\n // Try to get handlers from React fiber\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const fiber = getFiberFromElement(element) as ReactFiberWithHandlers | null;\n if (fiber) {\n const props = fiber.memoizedProps ?? fiber.pendingProps;\n if (props) {\n // Extract onClick handler\n if (typeof props.onClick === \"function\") {\n handlers.onClick = stringifyHandler(props.onClick);\n }\n\n // Extract other handlers\n if (typeof props.onMouseEnter === \"function\") {\n handlers.onMouseEnter = stringifyHandler(props.onMouseEnter);\n }\n if (typeof props.onMouseLeave === \"function\") {\n handlers.onMouseLeave = stringifyHandler(props.onMouseLeave);\n }\n if (typeof props.onFocus === \"function\") {\n handlers.onFocus = stringifyHandler(props.onFocus);\n }\n if (typeof props.onBlur === \"function\") {\n handlers.onBlur = stringifyHandler(props.onBlur);\n }\n }\n }\n\n // Fallback: try to parse from outerHTML (less reliable)\n if (!handlers.onClick) {\n const onClickMatch = element.outerHTML.match(\n /onClick={([^}]+(?:{[^}]*}[^}]*)*)}/,\n );\n if (onClickMatch?.[1]) {\n handlers.onClick = onClickMatch[1].trim();\n }\n }\n\n return handlers;\n}\n\n/**\n * Convert a function to a readable string representation\n *\n * @author Kevin O'Connell 2026-04-17\n */\nexport function stringifyHandler(fn: unknown): string {\n if (typeof fn !== \"function\") {\n return \"\";\n }\n\n // Get function source\n const source = fn.toString();\n\n // Clean up arrow functions\n if (source.startsWith(\"(\") || source.startsWith(\"function\")) {\n // For arrow functions like () => setCount(c => c + 1)\n const arrowMatch = source.match(/^\\(\\)\\s*=>\\s*([\\S\\s]+)$/);\n if (arrowMatch) {\n return arrowMatch[1]!.trim();\n }\n\n // For arrow functions with params like (e) => handleClick(e)\n const arrowWithParamsMatch = source.match(/^\\([^)]*\\)\\s*=>\\s*([\\S\\s]+)$/);\n if (arrowWithParamsMatch) {\n return arrowWithParamsMatch[1]!.trim();\n }\n }\n\n // Return truncated source for regular functions\n if (source.length > 200) {\n return `${source.slice(0, 200)}...`;\n }\n\n return source;\n}\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["// =============================================================================\n// React Fiber / Source Location Utilities\n// =============================================================================\n\nimport { z } from \"zod\";\n\nexport interface SourceLocation {\n filePath: string;\n lineNumber: number;\n columnNumber?: number;\n componentName?: string;\n}\n\nexport interface EventHandlers {\n onClick?: string;\n onMouseEnter?: string;\n onMouseLeave?: string;\n onFocus?: string;\n onBlur?: string;\n}\n\nexport interface ReactFiber {\n _debugSource?: {\n fileName: string;\n lineNumber: number;\n columnNumber?: number;\n };\n _debugStack?: unknown;\n _debugOwner?: ReactFiber;\n type?:\n | { name?: string; displayName?: string }\n | string\n | ((...args: unknown[]) => unknown)\n | null;\n return?: ReactFiber | null;\n memoizedProps?: Record<string, unknown>;\n pendingProps?: Record<string, unknown>;\n}\n\nconst MAX_FIBER_CHAIN_DEPTH = 80;\nconst MAX_SERIALIZED_PROP_COUNT = 24;\nconst MAX_SERIALIZED_STRING_LENGTH = 500;\n\ninterface ReactFiberWithHandlers extends ReactFiber {\n memoizedProps?: Record<string, unknown>;\n pendingProps?: Record<string, unknown>;\n}\n\n// Frames produced by React's own JSX runtime \u2014 these come first in\n// `_debugStack.stack` because the `Error` is constructed inside `jsxDEV`. We\n// want the frame *above* them, which is the actual JSX call site.\n//\n// Turbopack rewrites `node_modules/next/dist/compiled/react-server-dom-*` and\n// friends into mangled chunk paths like\n// `_next/static/chunks/<hash>_next_dist_compiled_react-server-dom-turbopack_<hash>._.js`,\n// so we match both the human-readable module paths and the chunk-name forms.\n// Without this, `_debugStack`'s top frame inside React's RSC runtime gets\n// surfaced as the \"host\" source location for every text node on the page \u2014\n// which then symbolicates back to bundled React, not user code.\nconst REACT_INTERNAL_FRAME_PATTERNS = [\n /react.*jsx-dev-runtime/,\n /react.*jsx-runtime/,\n /react-dom\\//,\n /react\\/cjs\\/react\\./,\n /react-server-dom/,\n /react_server_dom/,\n /next[/_.]dist[/_.]compiled/,\n /\\/node_modules\\/(next|react|react-dom)\\//,\n];\n\nfunction isReactInternalFrame(fileName: string): boolean {\n return REACT_INTERNAL_FRAME_PATTERNS.some((pattern) => {\n return pattern.test(fileName);\n });\n}\n\nfunction parseDebugStackSource(\n debugStack: unknown,\n): ReactFiber[\"_debugSource\"] | null {\n let stackText: string | null = null;\n\n if (typeof debugStack === \"string\") {\n stackText = debugStack;\n } else if (\n typeof debugStack === \"object\" &&\n debugStack &&\n \"stack\" in debugStack\n ) {\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const stack = (debugStack as { stack?: unknown }).stack;\n if (typeof stack === \"string\") {\n stackText = stack;\n }\n }\n\n if (!stackText) {\n return null;\n }\n\n for (const rawLine of stackText.split(\"\\n\")) {\n const line = rawLine.trim();\n if (!line) {\n continue;\n }\n\n const stackFrameMatch =\n line.match(/^at\\s+(?:.*\\()?(.*):(\\d+):(\\d+)\\)?$/) ??\n line.match(/^(.*):(\\d+):(\\d+)$/);\n\n if (!stackFrameMatch) {\n continue;\n }\n\n const fileName = stackFrameMatch[1]?.trim();\n const lineNumber = Number.parseInt(stackFrameMatch[2] ?? \"\", 10);\n const columnNumber = Number.parseInt(stackFrameMatch[3] ?? \"\", 10);\n\n if (\n !fileName ||\n !Number.isFinite(lineNumber) ||\n !Number.isFinite(columnNumber)\n ) {\n continue;\n }\n\n if (isReactInternalFrame(fileName)) {\n continue;\n }\n\n return {\n fileName,\n lineNumber,\n columnNumber,\n };\n }\n\n return null;\n}\n\nexport function getFiberFromElement(element: HTMLElement): ReactFiber | null {\n if (!element || typeof element !== \"object\") {\n return null;\n }\n\n const symbolKeys = Object.getOwnPropertySymbols(element);\n const fiberSymbolKey = symbolKeys.find((symbolKey) => {\n return symbolKey.toString().includes(\"reactFiber\");\n });\n if (fiberSymbolKey) {\n return (\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n (element as unknown as Record<symbol, ReactFiber>)[fiberSymbolKey] ?? null\n );\n }\n\n const keys = Object.keys(element);\n const fiberKey = keys.find((key) => key.startsWith(\"__reactFiber$\"));\n if (fiberKey) {\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n return (element as unknown as Record<string, ReactFiber>)[fiberKey] ?? null;\n }\n const instanceKey = keys.find((key) => {\n return key.startsWith(\"__reactInternalInstance$\");\n });\n if (instanceKey) {\n return (\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n (element as unknown as Record<string, ReactFiber>)[instanceKey] ?? null\n );\n }\n\n const possibleFiberKey = keys.find((key) => {\n if (!key.startsWith(\"__react\")) {\n return false;\n }\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const value = (element as unknown as Record<string, unknown>)[key];\n return value && typeof value === \"object\" && \"_debugSource\" in value;\n });\n\n if (possibleFiberKey) {\n return (\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n (element as unknown as Record<string, ReactFiber>)[possibleFiberKey] ??\n null\n );\n }\n\n return null;\n}\n\nexport function getComponentName(\n fiber: ReactFiber | null | undefined,\n): string | undefined {\n if (!fiber?.type) {\n return undefined;\n }\n\n if (typeof fiber.type === \"string\") {\n return undefined;\n }\n\n if (typeof fiber.type === \"function\") {\n return fiber.type.name || undefined;\n }\n\n if (typeof fiber.type === \"object\") {\n return fiber.type.displayName ?? fiber.type.name ?? undefined;\n }\n\n return undefined;\n}\n\nexport function findDebugSource(\n fiber: ReactFiber,\n maxDepth = 50,\n): { source: ReactFiber[\"_debugSource\"]; componentName?: string } | null {\n let current: ReactFiber | null | undefined = fiber;\n let depth = 0;\n\n while (current && depth < maxDepth) {\n if (current._debugSource) {\n return {\n source: current._debugSource,\n componentName: getComponentName(current),\n };\n }\n\n if (current._debugOwner?._debugSource) {\n return {\n source: current._debugOwner._debugSource,\n componentName: getComponentName(current._debugOwner),\n };\n }\n\n current = current.return;\n depth++;\n }\n\n return null;\n}\n\n// React 19 removed `fiber._debugSource`. The only per-element source pointer\n// left is `fiber._debugStack`, an `Error` constructed inside `jsxDEV` at the\n// JSX call site. We pull the topmost non-React frame out of that stack; it\n// references a compiled SSR/client chunk (e.g. `.next-dev/.../ssr/*.js`).\n// `symbolicateSelectedElement` later resolves those compiled frames to\n// original `.tsx` locations via Next.js's `/__nextjs_original-stack-frames`\n// dev-server endpoint.\nexport function findDebugSourceReact19(\n fiber: ReactFiber,\n): { source: ReactFiber[\"_debugSource\"]; componentName?: string } | null {\n let current: ReactFiber | null | undefined = fiber;\n let depth = 0;\n const maxDepth = 50;\n\n while (current && depth < maxDepth) {\n const debugStackSource =\n parseDebugStackSource(current._debugStack) ??\n parseDebugStackSource(current._debugOwner?._debugStack);\n if (debugStackSource) {\n return {\n source: debugStackSource,\n componentName: getComponentName(current),\n };\n }\n\n current = current.return;\n depth++;\n }\n\n return null;\n}\n\nexport function getSourceLocation(\n element: HTMLElement,\n): SourceLocation | undefined {\n let currentElement: HTMLElement | null = element;\n\n while (currentElement) {\n const fiber = getFiberFromElement(currentElement);\n if (fiber) {\n const debugInfo = findDebugSource(fiber) ?? findDebugSourceReact19(fiber);\n if (debugInfo?.source) {\n return {\n filePath: debugInfo.source.fileName,\n lineNumber: debugInfo.source.lineNumber,\n columnNumber: debugInfo.source.columnNumber,\n componentName: debugInfo.componentName ?? undefined,\n };\n }\n }\n\n currentElement = currentElement.parentElement;\n }\n\n return undefined;\n}\n\nfunction getDebugSource(\n fiber: ReactFiber,\n): ReactFiber[\"_debugSource\"] | undefined {\n const debugInfo = findDebugSource(fiber) ?? findDebugSourceReact19(fiber);\n return debugInfo?.source;\n}\n\nfunction getTagName(fiber: ReactFiber): string | undefined {\n return z.string().safeParse(fiber.type).data?.toLowerCase();\n}\n\nexport function getHostSourceIdentity(element: HTMLElement) {\n const fiber = getFiberFromElement(element);\n if (!fiber) {\n return null;\n }\n const source = getDebugSource(fiber);\n if (!source) {\n return null;\n }\n return {\n filePath: source.fileName,\n lineNumber: source.lineNumber,\n columnNumber: source.columnNumber,\n tagName: element.tagName.toLowerCase(),\n };\n}\n\nfunction getSerializablePropValue(value: unknown): unknown {\n if (\n value === null ||\n typeof value === \"number\" ||\n typeof value === \"boolean\"\n ) {\n return value;\n }\n\n if (typeof value === \"string\") {\n return value.length > MAX_SERIALIZED_STRING_LENGTH\n ? `${value.slice(0, MAX_SERIALIZED_STRING_LENGTH)}...`\n : value;\n }\n\n if (Array.isArray(value)) {\n return value.slice(0, 20).map(getSerializablePropValue);\n }\n\n if (typeof value === \"object\") {\n return \"[object]\";\n }\n\n return undefined;\n}\n\nfunction getSerializableProps(\n props: Record<string, unknown> | undefined,\n): Record<string, unknown> | undefined {\n if (!props) {\n return undefined;\n }\n\n const serializedProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(props).slice(\n 0,\n MAX_SERIALIZED_PROP_COUNT,\n )) {\n if (\n key === \"children\" ||\n key === \"ref\" ||\n key.startsWith(\"on\") ||\n typeof value === \"function\" ||\n typeof value === \"symbol\"\n ) {\n continue;\n }\n\n const serializableValue = getSerializablePropValue(value);\n if (serializableValue !== undefined) {\n serializedProps[key] = serializableValue;\n }\n }\n\n return Object.keys(serializedProps).length > 0 ? serializedProps : undefined;\n}\n\nexport function getFiberChain(element: HTMLElement) {\n const rootFiber = getFiberFromElement(element);\n const fiberChain = [];\n const seenKeys = new Set<string>();\n let currentFiber: ReactFiber | null | undefined = rootFiber;\n let depth = 0;\n\n while (currentFiber && depth < MAX_FIBER_CHAIN_DEPTH) {\n const source = getDebugSource(currentFiber);\n if (source) {\n const tagName = getTagName(currentFiber);\n const componentName = getComponentName(currentFiber);\n const key = [\n source.fileName,\n source.lineNumber,\n source.columnNumber ?? \"\",\n tagName ?? \"\",\n componentName ?? \"\",\n ].join(\":\");\n\n if (!seenKeys.has(key)) {\n seenKeys.add(key);\n fiberChain.push({\n sourceLocation: {\n filePath: source.fileName,\n lineNumber: source.lineNumber,\n columnNumber: source.columnNumber,\n componentName,\n },\n tagName,\n componentName,\n props: getSerializableProps(\n currentFiber.memoizedProps ?? currentFiber.pendingProps,\n ),\n });\n }\n }\n\n currentFiber = currentFiber.return;\n depth += 1;\n }\n\n return fiberChain;\n}\n\n/**\n * Extract event handlers from React fiber or DOM element\n *\n * @author Kevin O'Connell 2026-04-17\n */\nexport function extractEventHandlers(element: HTMLElement): EventHandlers {\n const handlers: EventHandlers = {};\n\n // Try to get handlers from React fiber\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const fiber = getFiberFromElement(element) as ReactFiberWithHandlers | null;\n if (fiber) {\n const props = fiber.memoizedProps ?? fiber.pendingProps;\n if (props) {\n // Extract onClick handler\n if (typeof props.onClick === \"function\") {\n handlers.onClick = stringifyHandler(props.onClick);\n }\n\n // Extract other handlers\n if (typeof props.onMouseEnter === \"function\") {\n handlers.onMouseEnter = stringifyHandler(props.onMouseEnter);\n }\n if (typeof props.onMouseLeave === \"function\") {\n handlers.onMouseLeave = stringifyHandler(props.onMouseLeave);\n }\n if (typeof props.onFocus === \"function\") {\n handlers.onFocus = stringifyHandler(props.onFocus);\n }\n if (typeof props.onBlur === \"function\") {\n handlers.onBlur = stringifyHandler(props.onBlur);\n }\n }\n }\n\n // Fallback: try to parse from outerHTML (less reliable)\n if (!handlers.onClick) {\n const onClickMatch = element.outerHTML.match(\n /onClick={([^}]+(?:{[^}]*}[^}]*)*)}/,\n );\n if (onClickMatch?.[1]) {\n handlers.onClick = onClickMatch[1].trim();\n }\n }\n\n return handlers;\n}\n\n/**\n * Convert a function to a readable string representation\n *\n * @author Kevin O'Connell 2026-04-17\n */\nexport function stringifyHandler(fn: unknown): string {\n if (typeof fn !== \"function\") {\n return \"\";\n }\n\n // Get function source\n const source = fn.toString();\n\n // Clean up arrow functions\n if (source.startsWith(\"(\") || source.startsWith(\"function\")) {\n // For arrow functions like () => setCount(c => c + 1)\n const arrowMatch = source.match(/^\\(\\)\\s*=>\\s*([\\S\\s]+)$/);\n if (arrowMatch) {\n return arrowMatch[1]!.trim();\n }\n\n // For arrow functions with params like (e) => handleClick(e)\n const arrowWithParamsMatch = source.match(/^\\([^)]*\\)\\s*=>\\s*([\\S\\s]+)$/);\n if (arrowWithParamsMatch) {\n return arrowWithParamsMatch[1]!.trim();\n }\n }\n\n // Return truncated source for regular functions\n if (source.length > 200) {\n return `${source.slice(0, 200)}...`;\n }\n\n return source;\n}\n"],
|
|
5
|
+
"mappings": "AAIA,SAAS,SAAS;AAmClB,MAAM,wBAAwB;AAC9B,MAAM,4BAA4B;AAClC,MAAM,+BAA+B;AAkBrC,MAAM,gCAAgC;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,SAAS,qBAAqB,UAA2B;AACvD,SAAO,8BAA8B,KAAK,CAAC,YAAY;AACrD,WAAO,QAAQ,KAAK,QAAQ;AAAA,EAC9B,CAAC;AACH;AAEA,SAAS,sBACP,YACmC;AACnC,MAAI,YAA2B;AAE/B,MAAI,OAAO,eAAe,UAAU;AAClC,gBAAY;AAAA,EACd,WACE,OAAO,eAAe,YACtB,cACA,WAAW,YACX;AAGA,UAAM,QAAS,WAAmC;AAClD,QAAI,OAAO,UAAU,UAAU;AAC7B,kBAAY;AAAA,IACd;AAAA,EACF;AAEA,MAAI,CAAC,WAAW;AACd,WAAO;AAAA,EACT;AAEA,aAAW,WAAW,UAAU,MAAM,IAAI,GAAG;AAC3C,UAAM,OAAO,QAAQ,KAAK;AAC1B,QAAI,CAAC,MAAM;AACT;AAAA,IACF;AAEA,UAAM,kBACJ,KAAK,MAAM,qCAAqC,KAChD,KAAK,MAAM,oBAAoB;AAEjC,QAAI,CAAC,iBAAiB;AACpB;AAAA,IACF;AAEA,UAAM,WAAW,gBAAgB,CAAC,GAAG,KAAK;AAC1C,UAAM,aAAa,OAAO,SAAS,gBAAgB,CAAC,KAAK,IAAI,EAAE;AAC/D,UAAM,eAAe,OAAO,SAAS,gBAAgB,CAAC,KAAK,IAAI,EAAE;AAEjE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AAK;AAAA,IACvC;AAAA,EACF;AAGA,MAAI,OAAO,SAAS,KAAK;AACvB,WAAO,GAAG,OAAO,MAAM,GAAG,GAAG,CAAC;AAAA,EAChC;AAEA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MutableRefObject } from "react";
|
|
2
|
+
import type { DisplayMode, SelectableData, SelectModeFormatCommand } from "../../../_vendor/schemas/generated/selectMode";
|
|
3
|
+
import type { SelectModeInteractionSession } from "../selectModeSession";
|
|
4
|
+
export declare function isTextEditableElement(element: Element): element is HTMLElement;
|
|
5
|
+
export declare function useEditModeStateMachine({ displayMode, interactionSessionRef, }: {
|
|
6
|
+
displayMode: DisplayMode;
|
|
7
|
+
interactionSessionRef: MutableRefObject<SelectModeInteractionSession>;
|
|
8
|
+
}): {
|
|
9
|
+
beginEditing: ({ element, descriptorPromise, }: {
|
|
10
|
+
element: Element;
|
|
11
|
+
descriptorPromise: Promise<SelectableData>;
|
|
12
|
+
}) => void;
|
|
13
|
+
editingElementRef: import("react").RefObject<HTMLElement | null>;
|
|
14
|
+
formatCommand: (command: SelectModeFormatCommand) => void;
|
|
15
|
+
resolveEditRequest: ({ editId, allowed }: {
|
|
16
|
+
editId: string;
|
|
17
|
+
allowed: boolean;
|
|
18
|
+
}) => void;
|
|
19
|
+
revert: () => void;
|
|
20
|
+
};
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
2
|
+
import { setSelectionFrameEditing } from "../selectionFrame";
|
|
3
|
+
import { symbolicateSelectedElement } from "../symbolicate";
|
|
4
|
+
const EMPTY_ACTIVE_MARKS = {
|
|
5
|
+
bold: false,
|
|
6
|
+
italic: false,
|
|
7
|
+
underline: false,
|
|
8
|
+
strike: false
|
|
9
|
+
};
|
|
10
|
+
function postEditorState({
|
|
11
|
+
activeMarks,
|
|
12
|
+
isEditing
|
|
13
|
+
}) {
|
|
14
|
+
window.parent.postMessage(
|
|
15
|
+
{ type: "replo:select:editorStateUpdate", activeMarks, isEditing },
|
|
16
|
+
"*"
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
function isTextEditableElement(element) {
|
|
20
|
+
const tagName = element.tagName.toLowerCase();
|
|
21
|
+
return element instanceof HTMLElement && Boolean(element.textContent?.trim()) && ![
|
|
22
|
+
"input",
|
|
23
|
+
"textarea",
|
|
24
|
+
"select",
|
|
25
|
+
"option",
|
|
26
|
+
"img",
|
|
27
|
+
"video",
|
|
28
|
+
"canvas"
|
|
29
|
+
].includes(tagName);
|
|
30
|
+
}
|
|
31
|
+
const FOCUS_STEAL_GUARD_MS = 1500;
|
|
32
|
+
function useEditModeStateMachine({
|
|
33
|
+
displayMode,
|
|
34
|
+
interactionSessionRef
|
|
35
|
+
}) {
|
|
36
|
+
const editorRef = useRef(null);
|
|
37
|
+
const editingElementRef = useRef(null);
|
|
38
|
+
const editIdRef = useRef(null);
|
|
39
|
+
const pendingEditRef = useRef(null);
|
|
40
|
+
const originalInnerHTMLRef = useRef(null);
|
|
41
|
+
const initialHTMLRef = useRef(null);
|
|
42
|
+
const isCommittingRef = useRef(false);
|
|
43
|
+
const beginEditingAtRef = useRef(0);
|
|
44
|
+
const destroyEditor = useCallback(() => {
|
|
45
|
+
editorRef.current?.destroy();
|
|
46
|
+
editorRef.current = null;
|
|
47
|
+
editingElementRef.current = null;
|
|
48
|
+
editIdRef.current = null;
|
|
49
|
+
if (pendingEditRef.current) {
|
|
50
|
+
clearTimeout(pendingEditRef.current.timeout);
|
|
51
|
+
pendingEditRef.current = null;
|
|
52
|
+
}
|
|
53
|
+
originalInnerHTMLRef.current = null;
|
|
54
|
+
initialHTMLRef.current = null;
|
|
55
|
+
isCommittingRef.current = false;
|
|
56
|
+
setSelectionFrameEditing(false);
|
|
57
|
+
postEditorState({ activeMarks: EMPTY_ACTIVE_MARKS, isEditing: false });
|
|
58
|
+
}, []);
|
|
59
|
+
const commit = useCallback(() => {
|
|
60
|
+
const editor = editorRef.current;
|
|
61
|
+
const editingElement = editingElementRef.current;
|
|
62
|
+
const originalInnerHTML = originalInnerHTMLRef.current;
|
|
63
|
+
const editId = editIdRef.current;
|
|
64
|
+
if (!editor || !editId || originalInnerHTML === null || isCommittingRef.current) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
isCommittingRef.current = true;
|
|
68
|
+
const committedHTML = editor.getHTML();
|
|
69
|
+
if (committedHTML === initialHTMLRef.current) {
|
|
70
|
+
destroyEditor();
|
|
71
|
+
if (editingElement) {
|
|
72
|
+
editingElement.innerHTML = originalInnerHTML;
|
|
73
|
+
}
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const committedJSON = editor.getJSON();
|
|
77
|
+
window.parent.postMessage(
|
|
78
|
+
{
|
|
79
|
+
type: "replo:select:textCommitted",
|
|
80
|
+
editId,
|
|
81
|
+
html: committedHTML,
|
|
82
|
+
json: committedJSON,
|
|
83
|
+
originalInnerHTML
|
|
84
|
+
},
|
|
85
|
+
"*"
|
|
86
|
+
);
|
|
87
|
+
destroyEditor();
|
|
88
|
+
if (editingElement) {
|
|
89
|
+
editingElement.innerHTML = committedHTML;
|
|
90
|
+
}
|
|
91
|
+
}, [destroyEditor]);
|
|
92
|
+
const revert = useCallback(() => {
|
|
93
|
+
const editingElement = editingElementRef.current;
|
|
94
|
+
const originalInnerHTML = originalInnerHTMLRef.current;
|
|
95
|
+
destroyEditor();
|
|
96
|
+
if (editingElement && originalInnerHTML !== null) {
|
|
97
|
+
editingElement.innerHTML = originalInnerHTML;
|
|
98
|
+
}
|
|
99
|
+
}, [destroyEditor]);
|
|
100
|
+
const handleBlur = useCallback(() => {
|
|
101
|
+
if (isCommittingRef.current) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (typeof document !== "undefined" && document.hasFocus()) {
|
|
105
|
+
commit();
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (Date.now() - beginEditingAtRef.current < FOCUS_STEAL_GUARD_MS) {
|
|
109
|
+
editorRef.current?.focus();
|
|
110
|
+
}
|
|
111
|
+
}, [commit]);
|
|
112
|
+
const formatCommand = useCallback((command) => {
|
|
113
|
+
editorRef.current?.runFormatCommand(command);
|
|
114
|
+
}, []);
|
|
115
|
+
const beginEditing = useCallback(
|
|
116
|
+
({
|
|
117
|
+
element,
|
|
118
|
+
descriptorPromise
|
|
119
|
+
}) => {
|
|
120
|
+
if (editingElementRef.current === element) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (!isTextEditableElement(element)) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (pendingEditRef.current?.element === element) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
void descriptorPromise.then((descriptor) => {
|
|
130
|
+
if (descriptor.kind !== "react-element" || !element.isConnected) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
interactionSessionRef.current = {
|
|
134
|
+
type: "element",
|
|
135
|
+
element,
|
|
136
|
+
clickPosition: null,
|
|
137
|
+
data: descriptor
|
|
138
|
+
};
|
|
139
|
+
const editId = crypto.randomUUID();
|
|
140
|
+
if (pendingEditRef.current) {
|
|
141
|
+
clearTimeout(pendingEditRef.current.timeout);
|
|
142
|
+
}
|
|
143
|
+
const timeout = window.setTimeout(() => {
|
|
144
|
+
if (pendingEditRef.current?.editId === editId) {
|
|
145
|
+
pendingEditRef.current = null;
|
|
146
|
+
}
|
|
147
|
+
}, 5e3);
|
|
148
|
+
pendingEditRef.current = { editId, element, timeout };
|
|
149
|
+
void symbolicateSelectedElement(descriptor).then((symbolicated) => {
|
|
150
|
+
if (pendingEditRef.current?.editId !== editId) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
window.parent.postMessage(
|
|
154
|
+
{
|
|
155
|
+
type: "replo:select:doubleClicked",
|
|
156
|
+
editId,
|
|
157
|
+
element: symbolicated
|
|
158
|
+
},
|
|
159
|
+
"*"
|
|
160
|
+
);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
},
|
|
164
|
+
[interactionSessionRef]
|
|
165
|
+
);
|
|
166
|
+
const resolveEditRequest = useCallback(
|
|
167
|
+
({ editId, allowed }) => {
|
|
168
|
+
const pendingEdit = pendingEditRef.current;
|
|
169
|
+
if (!pendingEdit || pendingEdit.editId !== editId) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
clearTimeout(pendingEdit.timeout);
|
|
173
|
+
pendingEditRef.current = null;
|
|
174
|
+
if (!allowed || !pendingEdit.element.isConnected) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const { element } = pendingEdit;
|
|
178
|
+
const originalInnerHTML = element.innerHTML;
|
|
179
|
+
editingElementRef.current = element;
|
|
180
|
+
editIdRef.current = editId;
|
|
181
|
+
originalInnerHTMLRef.current = originalInnerHTML;
|
|
182
|
+
void import("../tiptapInlineEditor").then(({ createInlineTiptapEditor }) => {
|
|
183
|
+
if (editingElementRef.current !== element || editIdRef.current !== editId) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
editorRef.current = createInlineTiptapEditor({
|
|
187
|
+
element,
|
|
188
|
+
content: originalInnerHTML,
|
|
189
|
+
onCommit: commit,
|
|
190
|
+
onEscape: revert,
|
|
191
|
+
onBlur: handleBlur,
|
|
192
|
+
onSelectionUpdate: (activeMarks) => {
|
|
193
|
+
postEditorState({ activeMarks, isEditing: true });
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
initialHTMLRef.current = editorRef.current.getHTML();
|
|
197
|
+
beginEditingAtRef.current = Date.now();
|
|
198
|
+
editorRef.current.focusAndSelectAll();
|
|
199
|
+
setSelectionFrameEditing(true);
|
|
200
|
+
postEditorState({ activeMarks: EMPTY_ACTIVE_MARKS, isEditing: true });
|
|
201
|
+
}).catch(() => {
|
|
202
|
+
if (editingElementRef.current === element && editIdRef.current === editId) {
|
|
203
|
+
revert();
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
[commit, handleBlur, revert]
|
|
208
|
+
);
|
|
209
|
+
useEffect(() => {
|
|
210
|
+
if (displayMode !== "selection") {
|
|
211
|
+
revert();
|
|
212
|
+
}
|
|
213
|
+
}, [displayMode, revert]);
|
|
214
|
+
return {
|
|
215
|
+
beginEditing,
|
|
216
|
+
editingElementRef,
|
|
217
|
+
formatCommand,
|
|
218
|
+
resolveEditRequest,
|
|
219
|
+
revert
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
export {
|
|
223
|
+
isTextEditableElement,
|
|
224
|
+
useEditModeStateMachine
|
|
225
|
+
};
|
|
226
|
+
//# sourceMappingURL=useEditModeStateMachine.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../editor/select-mode/hooks/useEditModeStateMachine.ts"],
|
|
4
|
+
"sourcesContent": ["import type { MutableRefObject } from \"react\";\nimport type {\n DisplayMode,\n SelectableData,\n SelectModeFormatCommand,\n} from \"schemas/generated/selectMode\";\nimport type { SelectModeInteractionSession } from \"../selectModeSession\";\nimport type { InlineTiptapEditor } from \"../tiptapInlineEditor\";\n\nimport { useCallback, useEffect, useRef } from \"react\";\n\nimport { setSelectionFrameEditing } from \"../selectionFrame\";\nimport { symbolicateSelectedElement } from \"../symbolicate\";\n\ntype ActiveMarks = {\n bold: boolean;\n italic: boolean;\n underline: boolean;\n strike: boolean;\n};\n\nconst EMPTY_ACTIVE_MARKS: ActiveMarks = {\n bold: false,\n italic: false,\n underline: false,\n strike: false,\n};\n\n// Notify the parent of the inline editor's state so it can show the inline\n// formatting controls (and live mark state) only while editing.\nfunction postEditorState({\n activeMarks,\n isEditing,\n}: {\n activeMarks: ActiveMarks;\n isEditing: boolean;\n}) {\n window.parent.postMessage(\n { type: \"replo:select:editorStateUpdate\", activeMarks, isEditing },\n \"*\",\n );\n}\n\nexport function isTextEditableElement(\n element: Element,\n): element is HTMLElement {\n const tagName = element.tagName.toLowerCase();\n return (\n element instanceof HTMLElement &&\n Boolean(element.textContent?.trim()) &&\n ![\n \"input\",\n \"textarea\",\n \"select\",\n \"option\",\n \"img\",\n \"video\",\n \"canvas\",\n ].includes(tagName)\n );\n}\n\n// Window after entering an edit during which a focus loss to the parent frame\n// is treated as the select-mode panel's composer auto-focus stealing focus\n// (and is reclaimed) rather than a deliberate move into the editor UI.\nconst FOCUS_STEAL_GUARD_MS = 1500;\n\nexport function useEditModeStateMachine({\n displayMode,\n interactionSessionRef,\n}: {\n displayMode: DisplayMode;\n interactionSessionRef: MutableRefObject<SelectModeInteractionSession>;\n}) {\n const editorRef = useRef<InlineTiptapEditor | null>(null);\n const editingElementRef = useRef<HTMLElement | null>(null);\n const editIdRef = useRef<string | null>(null);\n const pendingEditRef = useRef<{\n editId: string;\n element: HTMLElement;\n timeout: number;\n } | null>(null);\n const originalInnerHTMLRef = useRef<string | null>(null);\n // The editor's HTML right after it parsed the original content. tiptap\n // re-serializes the markup, so this \u2014 not the raw `originalInnerHTML` \u2014 is the\n // apples-to-apples baseline for detecting whether a commit actually changed\n // anything.\n const initialHTMLRef = useRef<string | null>(null);\n const isCommittingRef = useRef(false);\n const beginEditingAtRef = useRef(0);\n\n const destroyEditor = useCallback(() => {\n editorRef.current?.destroy();\n editorRef.current = null;\n editingElementRef.current = null;\n editIdRef.current = null;\n if (pendingEditRef.current) {\n clearTimeout(pendingEditRef.current.timeout);\n pendingEditRef.current = null;\n }\n originalInnerHTMLRef.current = null;\n initialHTMLRef.current = null;\n isCommittingRef.current = false;\n setSelectionFrameEditing(false);\n postEditorState({ activeMarks: EMPTY_ACTIVE_MARKS, isEditing: false });\n }, []);\n\n const commit = useCallback(() => {\n const editor = editorRef.current;\n const editingElement = editingElementRef.current;\n const originalInnerHTML = originalInnerHTMLRef.current;\n const editId = editIdRef.current;\n if (\n !editor ||\n !editId ||\n originalInnerHTML === null ||\n isCommittingRef.current\n ) {\n return;\n }\n\n isCommittingRef.current = true;\n const committedHTML = editor.getHTML();\n\n // A blur or Shift-Enter with no actual change must not spawn an edit\n // session. When the content is untouched, restore the original markup and\n // tear down without notifying the parent.\n if (committedHTML === initialHTMLRef.current) {\n destroyEditor();\n if (editingElement) {\n editingElement.innerHTML = originalInnerHTML;\n }\n return;\n }\n\n const committedJSON = editor.getJSON();\n window.parent.postMessage(\n {\n type: \"replo:select:textCommitted\",\n editId,\n html: committedHTML,\n json: committedJSON,\n originalInnerHTML,\n },\n \"*\",\n );\n // NOTE (Noah Gilmore, 2026-07-16): A directly mounted ProseMirror view\n // clears its root during destroy, so final HTML must be restored afterward.\n destroyEditor();\n if (editingElement) {\n editingElement.innerHTML = committedHTML;\n }\n }, [destroyEditor]);\n\n const revert = useCallback(() => {\n const editingElement = editingElementRef.current;\n const originalInnerHTML = originalInnerHTMLRef.current;\n destroyEditor();\n if (editingElement && originalInnerHTML !== null) {\n editingElement.innerHTML = originalInnerHTML;\n }\n }, [destroyEditor]);\n\n const handleBlur = useCallback(() => {\n if (isCommittingRef.current) {\n return;\n }\n // Focus stayed inside the iframe \u2014 the user clicked elsewhere on the page,\n // so this is a real \"click away\": commit.\n if (typeof document !== \"undefined\" && document.hasFocus()) {\n commit();\n return;\n }\n // Focus left the iframe to the parent editor. When it happens right as the\n // edit opens, the select-mode panel's composer auto-focus stole it \u2014 pull\n // it back so a double-click keeps the caret in the text. A deliberate move\n // into the editor UI later is left alone, and never commits/destroys.\n if (Date.now() - beginEditingAtRef.current < FOCUS_STEAL_GUARD_MS) {\n editorRef.current?.focus();\n }\n }, [commit]);\n\n const formatCommand = useCallback((command: SelectModeFormatCommand) => {\n editorRef.current?.runFormatCommand(command);\n }, []);\n\n const beginEditing = useCallback(\n ({\n element,\n descriptorPromise,\n }: {\n element: Element;\n descriptorPromise: Promise<SelectableData>;\n }) => {\n // Already editing this element \u2014 re-entering would re-read the mid-edit\n // DOM as the \"original\" and rebuild the editor over itself, wiping the\n // content. The pointer-up guard prevents the usual trigger; this is the\n // backstop for any other path.\n if (editingElementRef.current === element) {\n return;\n }\n if (!isTextEditableElement(element)) {\n return;\n }\n if (pendingEditRef.current?.element === element) {\n return;\n }\n\n void descriptorPromise.then((descriptor) => {\n if (descriptor.kind !== \"react-element\" || !element.isConnected) {\n return;\n }\n interactionSessionRef.current = {\n type: \"element\",\n element,\n clickPosition: null,\n data: descriptor,\n };\n const editId = crypto.randomUUID();\n if (pendingEditRef.current) {\n clearTimeout(pendingEditRef.current.timeout);\n }\n const timeout = window.setTimeout(() => {\n if (pendingEditRef.current?.editId === editId) {\n pendingEditRef.current = null;\n }\n }, 5000);\n pendingEditRef.current = { editId, element, timeout };\n void symbolicateSelectedElement(descriptor).then((symbolicated) => {\n if (pendingEditRef.current?.editId !== editId) {\n return;\n }\n window.parent.postMessage(\n {\n type: \"replo:select:doubleClicked\",\n editId,\n element: symbolicated,\n },\n \"*\",\n );\n });\n });\n },\n [interactionSessionRef],\n );\n\n const resolveEditRequest = useCallback(\n ({ editId, allowed }: { editId: string; allowed: boolean }) => {\n const pendingEdit = pendingEditRef.current;\n if (!pendingEdit || pendingEdit.editId !== editId) {\n return;\n }\n clearTimeout(pendingEdit.timeout);\n pendingEditRef.current = null;\n if (!allowed || !pendingEdit.element.isConnected) {\n return;\n }\n\n const { element } = pendingEdit;\n const originalInnerHTML = element.innerHTML;\n editingElementRef.current = element;\n editIdRef.current = editId;\n originalInnerHTMLRef.current = originalInnerHTML;\n\n void import(\"../tiptapInlineEditor\")\n .then(({ createInlineTiptapEditor }) => {\n if (\n editingElementRef.current !== element ||\n editIdRef.current !== editId\n ) {\n return;\n }\n editorRef.current = createInlineTiptapEditor({\n element,\n content: originalInnerHTML,\n onCommit: commit,\n onEscape: revert,\n onBlur: handleBlur,\n onSelectionUpdate: (activeMarks) => {\n postEditorState({ activeMarks, isEditing: true });\n },\n });\n initialHTMLRef.current = editorRef.current.getHTML();\n beginEditingAtRef.current = Date.now();\n editorRef.current.focusAndSelectAll();\n setSelectionFrameEditing(true);\n postEditorState({ activeMarks: EMPTY_ACTIVE_MARKS, isEditing: true });\n })\n .catch(() => {\n if (\n editingElementRef.current === element &&\n editIdRef.current === editId\n ) {\n revert();\n }\n });\n },\n [commit, handleBlur, revert],\n );\n\n // eslint-disable-next-line replo/no-use-effect -- Tears down the inline editor when leaving selection mode.\n useEffect(() => {\n if (displayMode !== \"selection\") {\n revert();\n }\n }, [displayMode, revert]);\n\n return {\n beginEditing,\n editingElementRef,\n formatCommand,\n resolveEditRequest,\n revert,\n };\n}\n"],
|
|
5
|
+
"mappings": "AASA,SAAS,aAAa,WAAW,cAAc;AAE/C,SAAS,gCAAgC;AACzC,SAAS,kCAAkC;AAS3C,MAAM,qBAAkC;AAAA,EACtC,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,QAAQ;AACV;AAIA,SAAS,gBAAgB;AAAA,EACvB;AAAA,EACA;AACF,GAGG;AACD,SAAO,OAAO;AAAA,IACZ,EAAE,MAAM,kCAAkC,aAAa,UAAU;AAAA,IACjE;AAAA,EACF;AACF;AAEO,SAAS,sBACd,SACwB;AACxB,QAAM,UAAU,QAAQ,QAAQ,YAAY;AAC5C,SACE,mBAAmB,eACnB,QAAQ,QAAQ,aAAa,KAAK,CAAC,KACnC,CAAC;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,EAAE,SAAS,OAAO;AAEtB;AAKA,MAAM,uBAAuB;AAEtB,SAAS,wBAAwB;AAAA,EACtC;AAAA,EACA;AACF,GAGG;AACD,QAAM,YAAY,OAAkC,IAAI;AACxD,QAAM,oBAAoB,OAA2B,IAAI;AACzD,QAAM,YAAY,OAAsB,IAAI;AAC5C,QAAM,iBAAiB,OAIb,IAAI;AACd,QAAM,uBAAuB,OAAsB,IAAI;AAKvD,QAAM,iBAAiB,OAAsB,IAAI;AACjD,QAAM,kBAAkB,OAAO,KAAK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A,IACA,CAAC,QAAQ,YAAY,MAAM;AAAA,EAC7B;AAGA,YAAU,MAAM;AACd,QAAI,gBAAgB,aAAa;AAC/B,aAAO;AAAA,IACT;AAAA,EACF,GAAG,CAAC,aAAa,MAAM,CAAC;AAExB,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MutableRefObject } from "react";
|
|
2
|
+
import type { SelectModeOptimisticUpdatePayload } from "../../../_vendor/schemas/generated/selectMode";
|
|
3
|
+
import type { SelectModeInteractionSession } from "../selectModeSession";
|
|
4
|
+
type SessionOutcome = "persisted" | "failed";
|
|
5
|
+
export declare function useOptimisticOverrides({ interactionSessionRef, }: {
|
|
6
|
+
interactionSessionRef: MutableRefObject<SelectModeInteractionSession>;
|
|
7
|
+
}): {
|
|
8
|
+
applyOptimisticUpdate: ({ editId, payload, targetMode, }: {
|
|
9
|
+
editId: string;
|
|
10
|
+
payload: SelectModeOptimisticUpdatePayload;
|
|
11
|
+
targetMode: "primary" | "group";
|
|
12
|
+
}) => void;
|
|
13
|
+
markCommitted: (editId: string, sessionId: string) => void;
|
|
14
|
+
reapplyOverrides: ({ skipElement }: {
|
|
15
|
+
skipElement: HTMLElement | null;
|
|
16
|
+
}) => void;
|
|
17
|
+
resolveSessionOverrides: (sessionId: string, outcome: SessionOutcome) => void;
|
|
18
|
+
revertOverride: (editId: string) => void;
|
|
19
|
+
};
|
|
20
|
+
export {};
|