@upstart.gg/vite-plugins 0.0.38 → 0.0.40

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.
Files changed (64) hide show
  1. package/dist/upstart-editor-api.d.ts +79 -0
  2. package/dist/upstart-editor-api.d.ts.map +1 -0
  3. package/dist/upstart-editor-api.js +208 -0
  4. package/dist/upstart-editor-api.js.map +1 -0
  5. package/dist/vite-plugin-upstart-attrs.d.ts +3 -3
  6. package/dist/vite-plugin-upstart-attrs.d.ts.map +1 -1
  7. package/dist/vite-plugin-upstart-attrs.js +227 -25
  8. package/dist/vite-plugin-upstart-attrs.js.map +1 -1
  9. package/dist/vite-plugin-upstart-branding/plugin.d.ts +17 -0
  10. package/dist/vite-plugin-upstart-branding/plugin.d.ts.map +1 -0
  11. package/dist/vite-plugin-upstart-branding/plugin.js +41 -0
  12. package/dist/vite-plugin-upstart-branding/plugin.js.map +1 -0
  13. package/dist/vite-plugin-upstart-branding/runtime.d.ts +10 -0
  14. package/dist/vite-plugin-upstart-branding/runtime.d.ts.map +1 -0
  15. package/dist/vite-plugin-upstart-branding/runtime.js +118 -0
  16. package/dist/vite-plugin-upstart-branding/runtime.js.map +1 -0
  17. package/dist/vite-plugin-upstart-branding/types.d.ts +14 -0
  18. package/dist/vite-plugin-upstart-branding/types.d.ts.map +1 -0
  19. package/dist/vite-plugin-upstart-branding/types.js +1 -0
  20. package/dist/vite-plugin-upstart-editor/plugin.d.ts +3 -3
  21. package/dist/vite-plugin-upstart-editor/plugin.d.ts.map +1 -1
  22. package/dist/vite-plugin-upstart-editor/plugin.js +3 -16
  23. package/dist/vite-plugin-upstart-editor/plugin.js.map +1 -1
  24. package/dist/vite-plugin-upstart-editor/runtime/click-handler.js +25 -11
  25. package/dist/vite-plugin-upstart-editor/runtime/click-handler.js.map +1 -1
  26. package/dist/vite-plugin-upstart-editor/runtime/error-handler.d.ts +5 -0
  27. package/dist/vite-plugin-upstart-editor/runtime/error-handler.d.ts.map +1 -0
  28. package/dist/vite-plugin-upstart-editor/runtime/error-handler.js +16 -0
  29. package/dist/vite-plugin-upstart-editor/runtime/error-handler.js.map +1 -0
  30. package/dist/vite-plugin-upstart-editor/runtime/hover-overlay.js +1 -1
  31. package/dist/vite-plugin-upstart-editor/runtime/hover-overlay.js.map +1 -1
  32. package/dist/vite-plugin-upstart-editor/runtime/index.d.ts +2 -1
  33. package/dist/vite-plugin-upstart-editor/runtime/index.d.ts.map +1 -1
  34. package/dist/vite-plugin-upstart-editor/runtime/index.js +42 -7
  35. package/dist/vite-plugin-upstart-editor/runtime/index.js.map +1 -1
  36. package/dist/vite-plugin-upstart-editor/runtime/text-editor.d.ts +6 -1
  37. package/dist/vite-plugin-upstart-editor/runtime/text-editor.d.ts.map +1 -1
  38. package/dist/vite-plugin-upstart-editor/runtime/text-editor.js +423 -129
  39. package/dist/vite-plugin-upstart-editor/runtime/text-editor.js.map +1 -1
  40. package/dist/vite-plugin-upstart-editor/runtime/types.d.ts +18 -10
  41. package/dist/vite-plugin-upstart-editor/runtime/types.d.ts.map +1 -1
  42. package/dist/vite-plugin-upstart-theme.d.ts +3 -3
  43. package/dist/vite-plugin-upstart-theme.d.ts.map +1 -1
  44. package/dist/vite-plugin-upstart-theme.js +1 -3
  45. package/dist/vite-plugin-upstart-theme.js.map +1 -1
  46. package/package.json +12 -4
  47. package/src/tests/upstart-editor-api.test.ts +98 -174
  48. package/src/tests/vite-plugin-upstart-attrs.test.ts +408 -105
  49. package/src/tests/vite-plugin-upstart-branding.test.ts +90 -0
  50. package/src/tests/vite-plugin-upstart-editor.test.ts +1 -2
  51. package/src/upstart-editor-api.ts +90 -29
  52. package/src/vite-plugin-upstart-attrs.ts +376 -38
  53. package/src/vite-plugin-upstart-branding/plugin.ts +59 -0
  54. package/src/vite-plugin-upstart-branding/runtime.ts +128 -0
  55. package/src/vite-plugin-upstart-branding/types.ts +10 -0
  56. package/src/vite-plugin-upstart-editor/plugin.ts +4 -19
  57. package/src/vite-plugin-upstart-editor/runtime/click-handler.ts +25 -12
  58. package/src/vite-plugin-upstart-editor/runtime/error-handler.ts +12 -0
  59. package/src/vite-plugin-upstart-editor/runtime/hover-overlay.ts +1 -1
  60. package/src/vite-plugin-upstart-editor/runtime/index.ts +39 -5
  61. package/src/vite-plugin-upstart-editor/runtime/text-editor.ts +518 -141
  62. package/src/vite-plugin-upstart-editor/runtime/types.ts +18 -4
  63. package/src/vite-plugin-upstart-theme.ts +0 -3
  64. package/src/vite-plugin-upstart-editor/PLAN.md +0 -1391
@@ -33,7 +33,7 @@ function handleMouseOver(event) {
33
33
  const target = event.target;
34
34
  if (!target) return;
35
35
  const component = target.closest("[data-upstart-component]");
36
- if (!component) return;
36
+ if (!component || component.dataset.upstartEditorActive) return;
37
37
  if (!overlay) createOverlay();
38
38
  currentTarget = component;
39
39
  positionOverlay(component);
@@ -1 +1 @@
1
- {"version":3,"file":"hover-overlay.js","names":["overlay: HTMLDivElement | null","currentTarget: HTMLElement | null","rafId: number | null"],"sources":["../../../src/vite-plugin-upstart-editor/runtime/hover-overlay.ts"],"sourcesContent":["import { getCurrentMode } from \"./index.js\";\nimport { sendToParent } from \"./utils.js\";\n\nlet overlay: HTMLDivElement | null = null;\nlet currentTarget: HTMLElement | null = null;\nlet isInitialized = false;\nlet rafId: number | null = null;\n\n/**\n * Initialize hover overlay.\n */\nexport function initHoverOverlay(): void {\n if (typeof document === \"undefined\") {\n return;\n }\n\n if (isInitialized) {\n return;\n }\n\n console.log(\"[Upstart Editor] Initializing hover overlay...\");\n\n document.addEventListener(\"mouseover\", handleMouseOver);\n document.addEventListener(\"mouseout\", handleMouseOut);\n window.addEventListener(\"scroll\", scheduleOverlayUpdate, { passive: true });\n window.addEventListener(\"resize\", scheduleOverlayUpdate, { passive: true });\n\n isInitialized = true;\n}\n\n/**\n * Hide all overlays.\n */\nexport function hideOverlays(): void {\n if (overlay) {\n overlay.style.display = \"none\";\n currentTarget = null;\n }\n}\n\nfunction handleMouseOver(event: MouseEvent): void {\n if (getCurrentMode() !== \"edit\") {\n return;\n }\n\n const target = event.target as HTMLElement | null;\n if (!target) {\n return;\n }\n\n const component = target.closest<HTMLElement>(\"[data-upstart-component]\");\n if (!component) {\n return;\n }\n\n if (!overlay) {\n createOverlay();\n }\n\n currentTarget = component;\n positionOverlay(component);\n\n const hash = component.dataset.upstartHash;\n if (hash) {\n const rect = component.getBoundingClientRect();\n sendToParent({\n type: \"element-hovered\",\n hash,\n bounds: {\n top: rect.top,\n left: rect.left,\n width: rect.width,\n height: rect.height,\n right: rect.right,\n bottom: rect.bottom,\n },\n });\n }\n}\n\nfunction handleMouseOut(event: MouseEvent): void {\n const target = event.target as HTMLElement | null;\n const relatedTarget = event.relatedTarget as HTMLElement | null;\n\n if (!target) {\n return;\n }\n\n const component = target.closest<HTMLElement>(\"[data-upstart-component]\");\n if (!component) {\n return;\n }\n\n if (relatedTarget && component.contains(relatedTarget)) {\n return;\n }\n\n hideOverlays();\n}\n\nfunction createOverlay(): void {\n overlay = document.createElement(\"div\");\n overlay.id = \"upstart-hover-overlay\";\n overlay.style.cssText =\n \"position: absolute; pointer-events: none; border: 2px solid #3b82f6; \" +\n \"background: rgba(59, 130, 246, 0.05); border-radius: 4px; z-index: 9999; \" +\n \"transition: all 0.1s ease; display: none;\";\n document.body.appendChild(overlay);\n}\n\nfunction positionOverlay(element: HTMLElement): void {\n if (!overlay) {\n return;\n }\n\n const rect = element.getBoundingClientRect();\n overlay.style.top = `${rect.top + window.scrollY}px`;\n overlay.style.left = `${rect.left + window.scrollX}px`;\n overlay.style.width = `${rect.width}px`;\n overlay.style.height = `${rect.height}px`;\n overlay.style.display = \"block\";\n}\n\nfunction scheduleOverlayUpdate(): void {\n if (rafId !== null) {\n return;\n }\n\n rafId = requestAnimationFrame(() => {\n rafId = null;\n if (currentTarget && overlay && overlay.style.display === \"block\") {\n positionOverlay(currentTarget);\n }\n });\n}\n"],"mappings":";;;;AAGA,IAAIA,UAAiC;AACrC,IAAIC,g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M,UACZ;AAGF,UAAS,KAAK,YAAY,QAAQ;;AAGpC,SAAS,gBAAgB,SAA4B;AACnD,KAAI,CAAC,QACH;CAGF,MAAM,OAAO,QAAQ,uBAAuB;AAC5C,SAAQ,MAAM,MAAM,GAAG,KAAK,MAAM,OAAO,QAAQ;AACjD,SAAQ,MAAM,OAAO,GAAG,KAAK,OAAO,OAAO,QAAQ;AACnD,SAAQ,MAAM,QAAQ,GAAG,KAAK,MAAM;AACpC,SAAQ,MAAM,SAAS,GAAG,KAAK,OAAO;AACtC,SAAQ,MAAM,UAAU;;AAG1B,SAAS,wBAA8B;AACrC,KAAI,UAAU,KACZ;AAGF,SAAQ,4BAA4B;AAClC,UAAQ;AACR,MAAI,iBAAiB,WAAW,QAAQ,MAAM,YAAY,QACxD,iBAAgB,cAAc;GAEhC"}
1
+ {"version":3,"file":"hover-overlay.js","names":["overlay: HTMLDivElement | null","currentTarget: HTMLElement | null","rafId: number | null"],"sources":["../../../src/vite-plugin-upstart-editor/runtime/hover-overlay.ts"],"sourcesContent":["import { getCurrentMode } from \"./index.js\";\nimport { sendToParent } from \"./utils.js\";\n\nlet overlay: HTMLDivElement | null = null;\nlet currentTarget: HTMLElement | null = null;\nlet isInitialized = false;\nlet rafId: number | null = null;\n\n/**\n * Initialize hover overlay.\n */\nexport function initHoverOverlay(): void {\n if (typeof document === \"undefined\") {\n return;\n }\n\n if (isInitialized) {\n return;\n }\n\n console.log(\"[Upstart Editor] Initializing hover overlay...\");\n\n document.addEventListener(\"mouseover\", handleMouseOver);\n document.addEventListener(\"mouseout\", handleMouseOut);\n window.addEventListener(\"scroll\", scheduleOverlayUpdate, { passive: true });\n window.addEventListener(\"resize\", scheduleOverlayUpdate, { passive: true });\n\n isInitialized = true;\n}\n\n/**\n * Hide all overlays.\n */\nexport function hideOverlays(): void {\n if (overlay) {\n overlay.style.display = \"none\";\n currentTarget = null;\n }\n}\n\nfunction handleMouseOver(event: MouseEvent): void {\n if (getCurrentMode() !== \"edit\") {\n return;\n }\n\n const target = event.target as HTMLElement | null;\n if (!target) {\n return;\n }\n\n const component = target.closest<HTMLElement>(\"[data-upstart-component]\");\n if (!component || component.dataset.upstartEditorActive) {\n return;\n }\n\n if (!overlay) {\n createOverlay();\n }\n\n currentTarget = component;\n positionOverlay(component);\n\n const hash = component.dataset.upstartHash;\n if (hash) {\n const rect = component.getBoundingClientRect();\n sendToParent({\n type: \"element-hovered\",\n hash,\n bounds: {\n top: rect.top,\n left: rect.left,\n width: rect.width,\n height: rect.height,\n right: rect.right,\n bottom: rect.bottom,\n },\n });\n }\n}\n\nfunction handleMouseOut(event: MouseEvent): void {\n const target = event.target as HTMLElement | null;\n const relatedTarget = event.relatedTarget as HTMLElement | null;\n\n if (!target) {\n return;\n }\n\n const component = target.closest<HTMLElement>(\"[data-upstart-component]\");\n if (!component) {\n return;\n }\n\n if (relatedTarget && component.contains(relatedTarget)) {\n return;\n }\n\n hideOverlays();\n}\n\nfunction createOverlay(): void {\n overlay = document.createElement(\"div\");\n overlay.id = \"upstart-hover-overlay\";\n overlay.style.cssText =\n \"position: absolute; pointer-events: none; border: 2px solid #3b82f6; \" +\n \"background: rgba(59, 130, 246, 0.05); border-radius: 4px; z-index: 9999; \" +\n \"transition: all 0.1s ease; display: none;\";\n document.body.appendChild(overlay);\n}\n\nfunction positionOverlay(element: HTMLElement): void {\n if (!overlay) {\n return;\n }\n\n const rect = element.getBoundingClientRect();\n overlay.style.top = `${rect.top + window.scrollY}px`;\n overlay.style.left = `${rect.left + window.scrollX}px`;\n overlay.style.width = `${rect.width}px`;\n overlay.style.height = `${rect.height}px`;\n overlay.style.display = \"block\";\n}\n\nfunction scheduleOverlayUpdate(): void {\n if (rafId !== null) {\n return;\n }\n\n rafId = requestAnimationFrame(() => {\n rafId = null;\n if (currentTarget && overlay && overlay.style.display === \"block\") {\n positionOverlay(currentTarget);\n }\n });\n}\n"],"mappings":";;;;AAGA,IAAIA,UAAiC;AACrC,IAAIC,gBAAoC;AACxC,IAAI,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AAM,UACZ;AAGF,UAAS,KAAK,YAAY,QAAQ;;AAGpC,SAAS,gBAAgB,SAA4B;AACnD,KAAI,CAAC,QACH;CAGF,MAAM,OAAO,QAAQ,uBAAuB;AAC5C,SAAQ,MAAM,MAAM,GAAG,KAAK,MAAM,OAAO,QAAQ;AACjD,SAAQ,MAAM,OAAO,GAAG,KAAK,OAAO,OAAO,QAAQ;AACnD,SAAQ,MAAM,QAAQ,GAAG,KAAK,MAAM;AACpC,SAAQ,MAAM,SAAS,GAAG,KAAK,OAAO;AACtC,SAAQ,MAAM,UAAU;;AAG1B,SAAS,wBAA8B;AACrC,KAAI,UAAU,KACZ;AAGF,SAAQ,4BAA4B;AAClC,UAAQ;AACR,MAAI,iBAAiB,WAAW,QAAQ,MAAM,YAAY,QACxD,iBAAgB,cAAc;GAEhC"}
@@ -1,5 +1,6 @@
1
1
  import { EditorMessage, EditorMode, UpstartEditorMessage } from "./types.js";
2
2
  import { initClickHandler } from "./click-handler.js";
3
+ import { initErrorHandler } from "./error-handler.js";
3
4
  import { initHoverOverlay } from "./hover-overlay.js";
4
5
  import { initTextEditor } from "./text-editor.js";
5
6
  import { sendToParent } from "./utils.js";
@@ -18,5 +19,5 @@ declare function setMode(mode: EditorMode): void;
18
19
  */
19
20
  declare function initUpstartEditor(): void;
20
21
  //#endregion
21
- export { type EditorMessage, type UpstartEditorMessage, getCurrentMode, initClickHandler, initHoverOverlay, initTextEditor, initUpstartEditor, sendToParent, setMode };
22
+ export { type EditorMessage, type UpstartEditorMessage, getCurrentMode, initClickHandler, initErrorHandler, initHoverOverlay, initTextEditor, initUpstartEditor, sendToParent, setMode };
22
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/vite-plugin-upstart-editor/runtime/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;iBAYgB,cAAA,CAAA,GAAkB;;;AAAlC;AAOgB,iBAAA,OAAA,CAAc,IAAU,EAAV,UAAU,CAAA,EAAA,IAAA;AAaxC;;;iBAAgB,iBAAA,CAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/vite-plugin-upstart-editor/runtime/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;iBAagB,cAAA,CAAA,GAAkB;;;;AAAlB,iBAOA,OAAA,CAPc,IAAI,EAOJ,UAPc,CAAA,EAAA,IAAA;AAO5C;AAaA;;iBAAgB,iBAAA,CAAA"}
@@ -1,7 +1,8 @@
1
1
  import { sendToParent } from "./utils.js";
2
2
  import { initClickHandler } from "./click-handler.js";
3
3
  import { hideOverlays, initHoverOverlay } from "./hover-overlay.js";
4
- import { destroyAllActiveEditors, initTextEditor } from "./text-editor.js";
4
+ import { initErrorHandler } from "./error-handler.js";
5
+ import { activateAllEditors, destroyAllActiveEditors, initTextEditor } from "./text-editor.js";
5
6
 
6
7
  //#region src/vite-plugin-upstart-editor/runtime/index.ts
7
8
  let currentMode = "preview";
@@ -17,6 +18,7 @@ function getCurrentMode() {
17
18
  */
18
19
  function setMode(mode) {
19
20
  currentMode = mode;
21
+ console.log(`[Upstart Editor] Setting mode to: ${mode}`);
20
22
  if (mode === "edit") enableEditMode();
21
23
  else disableEditMode();
22
24
  }
@@ -24,16 +26,22 @@ function setMode(mode) {
24
26
  * Initialize the Upstart editor runtime.
25
27
  */
26
28
  function initUpstartEditor() {
27
- if (typeof window === "undefined") return;
28
- if (isInitialized) return;
29
+ if (typeof window === "undefined") {
30
+ console.warn("[Upstart Editor] Cannot initialize editor: not running in a browser environment");
31
+ return;
32
+ }
33
+ if (isInitialized) {
34
+ console.log("[Upstart Editor] Editor is already initialized");
35
+ return;
36
+ }
29
37
  try {
30
38
  console.log("[Upstart Editor] Initializing...");
31
- currentMode = "preview";
32
39
  isInitialized = true;
33
40
  window.addEventListener("message", handleParentMessage);
34
41
  initTextEditor();
35
42
  initClickHandler();
36
43
  initHoverOverlay();
44
+ initErrorHandler();
37
45
  sendToParent({ type: "editor-ready" });
38
46
  } catch (error) {
39
47
  console.error("[Upstart Editor] Initialization failed:", error);
@@ -43,13 +51,40 @@ function initUpstartEditor() {
43
51
  });
44
52
  }
45
53
  }
54
+ const ALLOWED_ORIGINS = ["http://localhost:8080", /upstart.gg$/];
55
+ const matchAllowedOrigins = (origin) => {
56
+ return ALLOWED_ORIGINS.some((allowedOrigin) => {
57
+ if (typeof allowedOrigin === "string") return origin === allowedOrigin;
58
+ else if (allowedOrigin instanceof RegExp) return allowedOrigin.test(origin);
59
+ return false;
60
+ });
61
+ };
46
62
  function handleParentMessage(event) {
47
63
  const message = event.data;
48
- if (!message || message.source !== "upstart-editor-parent") return;
49
- if (message.type === "set-mode") setMode(message.mode);
64
+ console.log("[Upstart Editor] Received message from parent:", {
65
+ event,
66
+ message
67
+ });
68
+ if (!message || !matchAllowedOrigins(event.origin)) {
69
+ console.warn("[Upstart Editor] Ignoring message from unknown source:", event.origin);
70
+ return;
71
+ }
72
+ if (message.type === "set-mode") {
73
+ console.log("Setting editor mode to:", message.mode);
74
+ if ("scheduler" in globalThis) globalThis.scheduler.postTask(() => {
75
+ setMode(message.mode);
76
+ }, {
77
+ delay: 250,
78
+ priority: "background"
79
+ });
80
+ else setTimeout(() => {
81
+ setMode(message.mode);
82
+ }, 250);
83
+ }
50
84
  }
51
85
  function enableEditMode() {
52
86
  console.log("[Upstart Editor] Edit mode enabled");
87
+ activateAllEditors();
53
88
  }
54
89
  function disableEditMode() {
55
90
  console.log("[Upstart Editor] Preview mode enabled");
@@ -58,5 +93,5 @@ function disableEditMode() {
58
93
  }
59
94
 
60
95
  //#endregion
61
- export { getCurrentMode, initClickHandler, initHoverOverlay, initTextEditor, initUpstartEditor, sendToParent, setMode };
96
+ export { getCurrentMode, initClickHandler, initErrorHandler, initHoverOverlay, initTextEditor, initUpstartEditor, sendToParent, setMode };
62
97
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["currentMode: EditorMode"],"sources":["../../../src/vite-plugin-upstart-editor/runtime/index.ts"],"sourcesContent":["import { initClickHandler } from \"./click-handler.js\";\nimport { initHoverOverlay, hideOverlays } from \"./hover-overlay.js\";\nimport { initTextEditor, destroyAllActiveEditors } from \"./text-editor.js\";\nimport { sendToParent } from \"./utils.js\";\nimport type { EditorMode, UpstartParentMessage } from \"./types.js\";\n\nlet currentMode: EditorMode = \"preview\";\nlet isInitialized = false;\n\n/**\n * Get the current editor mode.\n */\nexport function getCurrentMode(): EditorMode {\n return currentMode;\n}\n\n/**\n * Set the current editor mode.\n */\nexport function setMode(mode: EditorMode): void {\n currentMode = mode;\n\n if (mode === \"edit\") {\n enableEditMode();\n } else {\n disableEditMode();\n }\n}\n\n/**\n * Initialize the Upstart editor runtime.\n */\nexport function initUpstartEditor(): void {\n if (typeof window === \"undefined\") {\n return;\n }\n\n if (isInitialized) {\n return;\n }\n\n try {\n console.log(\"[Upstart Editor] Initializing...\");\n\n currentMode = \"preview\";\n isInitialized = true;\n\n window.addEventListener(\"message\", handleParentMessage);\n\n initTextEditor();\n initClickHandler();\n initHoverOverlay();\n\n sendToParent({ type: \"editor-ready\" });\n } catch (error) {\n console.error(\"[Upstart Editor] Initialization failed:\", error);\n sendToParent({\n type: \"editor-error\",\n error: error instanceof Error ? error.message : \"Unknown error\",\n });\n }\n}\n\nfunction handleParentMessage(event: MessageEvent): void {\n const message = event.data as UpstartParentMessage | undefined;\n\n if (!message || message.source !== \"upstart-editor-parent\") {\n return;\n }\n\n if (message.type === \"set-mode\") {\n setMode(message.mode);\n }\n}\n\nfunction enableEditMode(): void {\n console.log(\"[Upstart Editor] Edit mode enabled\");\n}\n\nfunction disableEditMode(): void {\n console.log(\"[Upstart Editor] Preview mode enabled\");\n destroyAllActiveEditors();\n hideOverlays();\n}\n\nexport { initTextEditor } from \"./text-editor.js\";\nexport { initClickHandler } from \"./click-handler.js\";\nexport { initHoverOverlay } from \"./hover-overlay.js\";\nexport { sendToParent } from \"./utils.js\";\nexport type { EditorMessage, UpstartEditorMessage } from \"./types.js\";\n"],"mappings":";;;;;;AAMA,IAAIA,cAA0B;AAC9B,IAAI,gBAAgB;;;;AAKpB,SAAgB,iBAA6B;AAC3C,QAAO;;;;;AAMT,SAAgB,QAAQ,MAAwB;AAC9C,eAAc;AAEd,KAAI,SAAS,OACX,iBAAgB;KAEhB,kBAAiB;;;;;AAOrB,SAAgB,oBAA0B;AACxC,KAAI,OAAO,WAAW,YACpB;AAGF,KAAI,cACF;AAGF,KAAI;AACF,UAAQ,IAAI,mCAAmC;AAE/C,gBAAc;AACd,kBAAgB;AAEhB,SAAO,iBAAiB,WAAW,oBAAoB;AAEvD,kBAAgB;AAChB,oBAAkB;AAClB,oBAAkB;AAElB,eAAa,EAAE,MAAM,gBAAgB,CAAC;UAC/B,OAAO;AACd,UAAQ,MAAM,2CAA2C,MAAM;AAC/D,eAAa;GACX,MAAM;GACN,OAAO,iBAAiB,QAAQ,MAAM,UAAU;GACjD,CAAC;;;AAIN,SAAS,oBAAoB,OAA2B;CACtD,MAAM,UAAU,MAAM;AAEtB,KAAI,CAAC,WAAW,QAAQ,WAAW,wBACjC;AAGF,KAAI,QAAQ,SAAS,WACnB,SAAQ,QAAQ,KAAK;;AAIzB,SAAS,iBAAuB;AAC9B,SAAQ,IAAI,qCAAqC;;AAGnD,SAAS,kBAAwB;AAC/B,SAAQ,IAAI,wCAAwC;AACpD,0BAAyB;AACzB,eAAc"}
1
+ {"version":3,"file":"index.js","names":["currentMode: EditorMode"],"sources":["../../../src/vite-plugin-upstart-editor/runtime/index.ts"],"sourcesContent":["import { initClickHandler } from \"./click-handler.js\";\nimport { initHoverOverlay, hideOverlays } from \"./hover-overlay.js\";\nimport { initErrorHandler } from \"./error-handler.js\";\nimport { initTextEditor, activateAllEditors, destroyAllActiveEditors } from \"./text-editor.js\";\nimport { sendToParent } from \"./utils.js\";\nimport type { EditorMode, UpstartParentMessage } from \"./types.js\";\n\nlet currentMode: EditorMode = \"preview\";\nlet isInitialized = false;\n\n/**\n * Get the current editor mode.\n */\nexport function getCurrentMode(): EditorMode {\n return currentMode;\n}\n\n/**\n * Set the current editor mode.\n */\nexport function setMode(mode: EditorMode): void {\n currentMode = mode;\n console.log(`[Upstart Editor] Setting mode to: ${mode}`);\n if (mode === \"edit\") {\n enableEditMode();\n } else {\n disableEditMode();\n }\n}\n\n/**\n * Initialize the Upstart editor runtime.\n */\nexport function initUpstartEditor(): void {\n if (typeof window === \"undefined\") {\n console.warn(\"[Upstart Editor] Cannot initialize editor: not running in a browser environment\");\n return;\n }\n\n if (isInitialized) {\n console.log(\"[Upstart Editor] Editor is already initialized\");\n return;\n }\n\n try {\n console.log(\"[Upstart Editor] Initializing...\");\n\n isInitialized = true;\n\n window.addEventListener(\"message\", handleParentMessage);\n\n initTextEditor();\n initClickHandler();\n initHoverOverlay();\n initErrorHandler();\n\n sendToParent({ type: \"editor-ready\" });\n } catch (error) {\n console.error(\"[Upstart Editor] Initialization failed:\", error);\n sendToParent({\n type: \"editor-error\",\n error: error instanceof Error ? error.message : \"Unknown error\",\n });\n }\n}\n\nconst ALLOWED_ORIGINS = [\"http://localhost:8080\", /upstart.gg$/];\n\nconst matchAllowedOrigins = (origin: string) => {\n return ALLOWED_ORIGINS.some((allowedOrigin) => {\n if (typeof allowedOrigin === \"string\") {\n return origin === allowedOrigin;\n } else if (allowedOrigin instanceof RegExp) {\n return allowedOrigin.test(origin);\n }\n return false;\n });\n};\n\nfunction handleParentMessage(event: MessageEvent): void {\n const message = event.data as UpstartParentMessage | undefined;\n\n console.log(\"[Upstart Editor] Received message from parent:\", { event, message });\n\n if (!message || !matchAllowedOrigins(event.origin)) {\n console.warn(\"[Upstart Editor] Ignoring message from unknown source:\", event.origin);\n return;\n }\n\n if (message.type === \"set-mode\") {\n console.log(\"Setting editor mode to:\", message.mode);\n if (\"scheduler\" in globalThis) {\n // @ts-expect-error not yet in TS types\n globalThis.scheduler.postTask(\n () => {\n setMode(message.mode);\n },\n { delay: 250, priority: \"background\" },\n );\n } else {\n setTimeout(() => {\n setMode(message.mode);\n }, 250);\n }\n }\n}\n\nfunction enableEditMode(): void {\n console.log(\"[Upstart Editor] Edit mode enabled\");\n activateAllEditors();\n}\n\nfunction disableEditMode(): void {\n console.log(\"[Upstart Editor] Preview mode enabled\");\n destroyAllActiveEditors();\n hideOverlays();\n}\n\nexport { initTextEditor } from \"./text-editor.js\";\nexport { initClickHandler } from \"./click-handler.js\";\nexport { initErrorHandler } from \"./error-handler.js\";\nexport { initHoverOverlay } from \"./hover-overlay.js\";\nexport { sendToParent } from \"./utils.js\";\nexport type { EditorMessage, UpstartEditorMessage } from \"./types.js\";\n"],"mappings":";;;;;;;AAOA,IAAIA,cAA0B;AAC9B,IAAI,gBAAgB;;;;AAKpB,SAAgB,iBAA6B;AAC3C,QAAO;;;;;AAMT,SAAgB,QAAQ,MAAwB;AAC9C,eAAc;AACd,SAAQ,IAAI,qCAAqC,OAAO;AACxD,KAAI,SAAS,OACX,iBAAgB;KAEhB,kBAAiB;;;;;AAOrB,SAAgB,oBAA0B;AACxC,KAAI,OAAO,WAAW,aAAa;AACjC,UAAQ,KAAK,kFAAkF;AAC/F;;AAGF,KAAI,eAAe;AACjB,UAAQ,IAAI,iDAAiD;AAC7D;;AAGF,KAAI;AACF,UAAQ,IAAI,mCAAmC;AAE/C,kBAAgB;AAEhB,SAAO,iBAAiB,WAAW,oBAAoB;AAEvD,kBAAgB;AAChB,oBAAkB;AAClB,oBAAkB;AAClB,oBAAkB;AAElB,eAAa,EAAE,MAAM,gBAAgB,CAAC;UAC/B,OAAO;AACd,UAAQ,MAAM,2CAA2C,MAAM;AAC/D,eAAa;GACX,MAAM;GACN,OAAO,iBAAiB,QAAQ,MAAM,UAAU;GACjD,CAAC;;;AAIN,MAAM,kBAAkB,CAAC,yBAAyB,cAAc;AAEhE,MAAM,uBAAuB,WAAmB;AAC9C,QAAO,gBAAgB,MAAM,kBAAkB;AAC7C,MAAI,OAAO,kBAAkB,SAC3B,QAAO,WAAW;WACT,yBAAyB,OAClC,QAAO,cAAc,KAAK,OAAO;AAEnC,SAAO;GACP;;AAGJ,SAAS,oBAAoB,OAA2B;CACtD,MAAM,UAAU,MAAM;AAEtB,SAAQ,IAAI,kDAAkD;EAAE;EAAO;EAAS,CAAC;AAEjF,KAAI,CAAC,WAAW,CAAC,oBAAoB,MAAM,OAAO,EAAE;AAClD,UAAQ,KAAK,0DAA0D,MAAM,OAAO;AACpF;;AAGF,KAAI,QAAQ,SAAS,YAAY;AAC/B,UAAQ,IAAI,2BAA2B,QAAQ,KAAK;AACpD,MAAI,eAAe,WAEjB,YAAW,UAAU,eACb;AACJ,WAAQ,QAAQ,KAAK;KAEvB;GAAE,OAAO;GAAK,UAAU;GAAc,CACvC;MAED,kBAAiB;AACf,WAAQ,QAAQ,KAAK;KACpB,IAAI;;;AAKb,SAAS,iBAAuB;AAC9B,SAAQ,IAAI,qCAAqC;AACjD,qBAAoB;;AAGtB,SAAS,kBAAwB;AAC/B,SAAQ,IAAI,wCAAwC;AACpD,0BAAyB;AACzB,eAAc"}
@@ -4,12 +4,17 @@ import { UpstartEditorOptions } from "./types.js";
4
4
 
5
5
  /**
6
6
  * Initialize TipTap text editing for elements marked as editable.
7
+ * Activation is deferred to avoid conflicting with React hydration.
7
8
  */
8
9
  declare function initTextEditor(options?: UpstartEditorOptions): void;
10
+ /**
11
+ * Activate editors on all editable elements. Safe to call multiple times.
12
+ */
13
+ declare function activateAllEditors(): void;
9
14
  /**
10
15
  * Destroy all active editors.
11
16
  */
12
17
  declare function destroyAllActiveEditors(): void;
13
18
  //#endregion
14
- export { destroyAllActiveEditors, initTextEditor };
19
+ export { activateAllEditors, destroyAllActiveEditors, initTextEditor };
15
20
  //# sourceMappingURL=text-editor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"text-editor.d.ts","names":[],"sources":["../../../src/vite-plugin-upstart-editor/runtime/text-editor.ts"],"sourcesContent":[],"mappings":";;;;;;AA6BA;AA+BgB,iBA/BA,cAAA,CA+BuB,OAAA,CAAA,EA/BC,oBA+BD,CAAA,EAAA,IAAA;;;;iBAAvB,uBAAA,CAAA"}
1
+ {"version":3,"file":"text-editor.d.ts","names":[],"sources":["../../../src/vite-plugin-upstart-editor/runtime/text-editor.ts"],"sourcesContent":[],"mappings":";;;;;;AAuDA;AA6FA;AAkBgB,iBA/GA,cAAA,CA+GuB,OAAA,CAAA,EA/GC,oBA+GD,CAAA,EAAA,IAAA;;;;iBAlBvB,kBAAA,CAAA;;;;iBAkBA,uBAAA,CAAA"}