@meituan-nocode/nocode-design-mode-sandbox-script 0.1.0-beta.1
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/README.md +142 -0
- package/dist/index.js +1 -0
- package/package.json +42 -0
package/README.md
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# NoCode Design Mode Sandbox Script
|
|
2
|
+
|
|
3
|
+
这个包提供了一个沙箱脚本,用于在 iframe 中注入设计模式功能。
|
|
4
|
+
|
|
5
|
+
## 功能
|
|
6
|
+
|
|
7
|
+
- 通过 Penpal 与父窗口通信
|
|
8
|
+
- DOM 元素操作和查询
|
|
9
|
+
- 样式管理
|
|
10
|
+
- 拖拽功能
|
|
11
|
+
- 文本编辑
|
|
12
|
+
- 主题切换
|
|
13
|
+
|
|
14
|
+
## 构建
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# 开发环境构建
|
|
18
|
+
pnpm run build:dev
|
|
19
|
+
|
|
20
|
+
# 测试环境构建
|
|
21
|
+
pnpm run build:test
|
|
22
|
+
|
|
23
|
+
# 预发布环境构建
|
|
24
|
+
pnpm run build:pre
|
|
25
|
+
|
|
26
|
+
# 生产环境构建
|
|
27
|
+
pnpm run build:prod
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## 上传到 CDN
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# 上传到开发环境
|
|
34
|
+
pnpm run upload:dev
|
|
35
|
+
|
|
36
|
+
# 上传到测试环境
|
|
37
|
+
pnpm run upload:test
|
|
38
|
+
|
|
39
|
+
# 上传到预发布环境
|
|
40
|
+
pnpm run upload:pre
|
|
41
|
+
|
|
42
|
+
# 上传到生产环境
|
|
43
|
+
pnpm run upload:prod
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## 使用方式
|
|
47
|
+
|
|
48
|
+
### 在测试应用中使用
|
|
49
|
+
|
|
50
|
+
在 HTML 的 `<head>` 标签中引入脚本:
|
|
51
|
+
|
|
52
|
+
```html
|
|
53
|
+
<head>
|
|
54
|
+
<script src="../nocode-design-mode-sandbox-script/dist/sandbox-script.js"></script>
|
|
55
|
+
</head>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 在生产环境中使用
|
|
59
|
+
|
|
60
|
+
从 CDN 引入:
|
|
61
|
+
|
|
62
|
+
```html
|
|
63
|
+
<head>
|
|
64
|
+
<!-- 开发环境 -->
|
|
65
|
+
<script src="https://s3plus.meituan.net/nocode-external/artwork/dev/sandbox-script.js"></script>
|
|
66
|
+
|
|
67
|
+
<!-- 测试环境 -->
|
|
68
|
+
<script src="https://s3plus.meituan.net/nocode-external/artwork/test/sandbox-script.js"></script>
|
|
69
|
+
|
|
70
|
+
<!-- 生产环境 -->
|
|
71
|
+
<script src="https://s3plus.meituan.net/nocode-external/artwork/sandbox-script.js"></script>
|
|
72
|
+
</head>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## 架构说明
|
|
76
|
+
|
|
77
|
+
### 目录结构
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
nocode-design-mode-sandbox-script/
|
|
81
|
+
├── api/ # API 方法
|
|
82
|
+
│ ├── dom.ts # DOM 处理
|
|
83
|
+
│ ├── elements/ # 元素操作
|
|
84
|
+
│ ├── events/ # 事件处理
|
|
85
|
+
│ ├── style/ # 样式管理
|
|
86
|
+
│ └── theme/ # 主题管理
|
|
87
|
+
├── constants/ # 常量定义
|
|
88
|
+
├── helpers/ # 辅助函数
|
|
89
|
+
├── types/ # TypeScript 类型定义
|
|
90
|
+
├── index.ts # 入口文件
|
|
91
|
+
└── webpack.config.js
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### 通信机制
|
|
95
|
+
|
|
96
|
+
脚本使用 Penpal 库与父窗口(Design Mode Designer)进行通信:
|
|
97
|
+
|
|
98
|
+
1. **子窗口暴露的方法**:在 `api/index.ts` 中的 `preloadMethods` 定义
|
|
99
|
+
2. **父窗口方法调用**:通过 `penpalParent` 对象调用父窗口方法
|
|
100
|
+
|
|
101
|
+
### 主要功能模块
|
|
102
|
+
|
|
103
|
+
- **DOM 处理**:构建 Layer Tree,处理 DOM 变化
|
|
104
|
+
- **元素操作**:查询、插入、删除、移动元素
|
|
105
|
+
- **样式管理**:CSS 样式的读取和更新
|
|
106
|
+
- **拖拽功能**:元素拖拽和位置调整
|
|
107
|
+
- **文本编辑**:内联文本编辑
|
|
108
|
+
- **主题管理**:明暗主题切换
|
|
109
|
+
|
|
110
|
+
## 开发说明
|
|
111
|
+
|
|
112
|
+
### 依赖说明
|
|
113
|
+
|
|
114
|
+
- `penpal`: 用于 iframe 跨窗口通信
|
|
115
|
+
- `lodash`: 工具函数库
|
|
116
|
+
- `nanoid`: 生成唯一 ID
|
|
117
|
+
- `css-tree`: CSS 解析和操作
|
|
118
|
+
|
|
119
|
+
### 类型定义
|
|
120
|
+
|
|
121
|
+
所有类型定义在 `types/index.ts` 中,包括:
|
|
122
|
+
|
|
123
|
+
- `DomElement`: DOM 元素信息
|
|
124
|
+
- `LayerNode`: Layer Tree 节点
|
|
125
|
+
- `ActionElement`: 操作元素
|
|
126
|
+
- `StyleChange`: 样式变更
|
|
127
|
+
- 等等
|
|
128
|
+
|
|
129
|
+
### 常量定义
|
|
130
|
+
|
|
131
|
+
在 `constants/index.ts` 中定义了:
|
|
132
|
+
|
|
133
|
+
- `EditorAttributes`: 编辑器使用的 data 属性
|
|
134
|
+
- `DOM_IGNORE_TAGS`: 需要忽略的 DOM 标签
|
|
135
|
+
- `INLINE_ONLY_CONTAINERS`: 只能包含内联元素的容器
|
|
136
|
+
|
|
137
|
+
## 注意事项
|
|
138
|
+
|
|
139
|
+
1. 脚本必须在页面加载前引入(在 `<head>` 中)
|
|
140
|
+
2. 脚本会自动初始化并与父窗口建立连接
|
|
141
|
+
3. 确保父窗口也使用了 Penpal 进行通信
|
|
142
|
+
4. 上传到 CDN 后需要刷新 CDN 缓存
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{var e={6:(e,t,n)=>{var r=n(714).Symbol;e.exports=r},12:(e,t,n)=>{var r=n(400),o=n(835),i=n(639),s=Math.max,a=Math.min;e.exports=function(e,t,n){var c,u,l,d,f,h,p=0,g=!1,m=!1,v=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function y(t){var n=c,r=u;return c=u=void 0,p=t,d=e.apply(r,n)}function b(e){var n=e-h;return void 0===h||n>=t||n<0||m&&e-p>=l}function w(){var e=o();if(b(e))return E(e);f=setTimeout(w,function(e){var n=t-(e-h);return m?a(n,l-(e-p)):n}(e))}function E(e){return f=void 0,v&&c?y(e):(c=u=void 0,d)}function N(){var e=o(),n=b(e);if(c=arguments,u=this,h=e,n){if(void 0===f)return function(e){return p=e,f=setTimeout(w,t),g?y(e):d}(h);if(m)return clearTimeout(f),f=setTimeout(w,t),y(h)}return void 0===f&&(f=setTimeout(w,t)),d}return t=i(t)||0,r(n)&&(g=!!n.leading,l=(m="maxWait"in n)?s(i(n.maxWait)||0,t):l,v="trailing"in n?!!n.trailing:v),N.cancel=function(){void 0!==f&&clearTimeout(f),p=0,c=h=u=f=void 0},N.flush=function(){return void 0===f?d:E(o())},N}},103:(e,t,n)=>{var r=n(997),o=/^\s+/;e.exports=function(e){return e?e.slice(0,r(e)+1).replace(o,""):e}},271:(e,t,n)=>{var r=n(6),o=n(650),i=n(881),s=r?r.toStringTag:void 0;e.exports=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":s&&s in Object(e)?o(e):i(e)}},400:e=>{e.exports=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}},583:e=>{e.exports=function(e){return null!=e&&"object"==typeof e}},603:(e,t,n)=>{var r="object"==typeof n.g&&n.g&&n.g.Object===Object&&n.g;e.exports=r},639:(e,t,n)=>{var r=n(103),o=n(400),i=n(975),s=/^[-+]0x[0-9a-f]+$/i,a=/^0b[01]+$/i,c=/^0o[0-7]+$/i,u=parseInt;e.exports=function(e){if("number"==typeof e)return e;if(i(e))return NaN;if(o(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=o(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=r(e);var n=a.test(e);return n||c.test(e)?u(e.slice(2),n?2:8):s.test(e)?NaN:+e}},650:(e,t,n)=>{var r=n(6),o=Object.prototype,i=o.hasOwnProperty,s=o.toString,a=r?r.toStringTag:void 0;e.exports=function(e){var t=i.call(e,a),n=e[a];try{e[a]=void 0;var r=!0}catch(e){}var o=s.call(e);return r&&(t?e[a]=n:delete e[a]),o}},714:(e,t,n)=>{var r=n(603),o="object"==typeof self&&self&&self.Object===Object&&self,i=r||o||Function("return this")();e.exports=i},835:(e,t,n)=>{var r=n(714);e.exports=function(){return r.Date.now()}},881:e=>{var t=Object.prototype.toString;e.exports=function(e){return t.call(e)}},975:(e,t,n)=>{var r=n(271),o=n(583);e.exports=function(e){return"symbol"==typeof e||o(e)&&"[object Symbol]"==r(e)}},997:e=>{var t=/\s/;e.exports=function(e){for(var n=e.length;n--&&t.test(e.charAt(n)););return n}}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";var e=n(12),t=n.n(e),r=class extends Error{code;constructor(e,t){super(t),this.name="PenpalError",this.code=e}},o=e=>({name:e.name,message:e.message,stack:e.stack,penpalCode:e instanceof r?e.code:void 0}),i=Symbol("Reply"),s=class{value;transferables;#e=i;constructor(e,t){this.value=e,this.transferables=t?.transferables}},a="penpal",c=e=>"object"==typeof e&&null!==e,u=e=>"function"==typeof e,l=e=>"SYN"===e.type,d=e=>"ACK1"===e.type,f=e=>"ACK2"===e.type,h=e=>"CALL"===e.type,p=e=>"REPLY"===e.type,g=(e,t=[])=>{const n=[];for(const r of Object.keys(e)){const o=e[r];u(o)?n.push([...t,r]):c(o)&&n.push(...g(o,[...t,r]))}return n},m=e=>e.join("."),v=(e,t,n)=>({namespace:a,channel:e,type:"REPLY",callId:t,isError:!0,...n instanceof Error?{value:o(n),isSerializedErrorInstance:!0}:{value:n}}),y=crypto.randomUUID?.bind(crypto)??(()=>new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")),b=Symbol("CallOptions"),w=class{transferables;timeout;#e=b;constructor(e){this.transferables=e?.transferables,this.timeout=e?.timeout}},E=new Set(["apply","call","bind"]),N=(e,t,n=[])=>new Proxy(n.length?()=>{}:Object.create(null),{get(r,o){if("then"!==o)return n.length&&E.has(o)?Reflect.get(r,o):N(e,t,[...n,o])},apply:(t,r,o)=>e(n,o)}),S=e=>new r("CONNECTION_DESTROYED",`Method call ${m(e)}() failed due to destroyed connection`),C="deprecated-penpal",O=e=>e.join("."),x=e=>new r("TRANSMISSION_FAILED",`Unexpected message to translate: ${(e=>{try{return JSON.stringify(e)}catch(t){return String(e)}})(e)}`),T=({messenger:e,methods:t,timeout:n,channel:o,log:i})=>{const b=y();let E;const O=[];let x=!1;const T=g(t),{promise:I,resolve:M,reject:P}=(()=>{let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}})(),A=void 0!==n?setTimeout(()=>{P(new r("CONNECTION_TIMEOUT",`Connection timed out after ${n}ms`))},n):void 0,R=()=>{for(const e of O)e()},L=()=>{if(x)return;O.push(((e,t,n,o)=>{let i=!1;const l=async l=>{if(i)return;if(!h(l))return;o?.(`Received ${m(l.methodPath)}() call`,l);const{methodPath:d,args:f,id:p}=l;let g,y;try{const e=((e,t)=>{const n=e.reduce((e,t)=>c(e)?e[t]:void 0,t);return u(n)?n:void 0})(d,t);if(!e)throw new r("METHOD_NOT_FOUND",`Method \`${m(d)}\` is not found.`);let o=await e(...f);o instanceof s&&(y=o.transferables,o=await o.value),g={namespace:a,channel:n,type:"REPLY",callId:p,value:o}}catch(e){g=v(n,p,e)}if(!i)try{o?.(`Sending ${m(d)}() reply`,g),e.sendMessage(g,y)}catch(t){throw"DataCloneError"===t.name&&(g=v(n,p,t),o?.(`Sending ${m(d)}() reply`,g),e.sendMessage(g)),t}};return e.addMessageHandler(l),()=>{i=!0,e.removeMessageHandler(l)}})(e,t,o,i));const{remoteProxy:n,destroy:l}=((e,t,n)=>{let o=!1;const i=new Map,s=e=>{if(!p(e))return;const{callId:t,value:o,isError:s,isSerializedErrorInstance:a}=e,c=i.get(t);c&&(i.delete(t),n?.(`Received ${m(c.methodPath)}() call`,e),s?c.reject(a?(({name:e,message:t,stack:n,penpalCode:o})=>{const i=o?new r(o,t):new Error(t);return i.name=e,i.stack=n,i})(o):o):c.resolve(o))};return e.addMessageHandler(s),{remoteProxy:N((s,c)=>{if(o)throw S(s);const u=y(),l=c[c.length-1],d=l instanceof w,{timeout:f,transferables:h}=d?l:{},p=d?c.slice(0,-1):c;return new Promise((o,c)=>{const l=void 0!==f?window.setTimeout(()=>{i.delete(u),c(new r("METHOD_CALL_TIMEOUT",`Method call ${m(s)}() timed out after ${f}ms`))},f):void 0;i.set(u,{methodPath:s,resolve:o,reject:c,timeoutId:l});try{const r={namespace:a,channel:t,type:"CALL",id:u,methodPath:s,args:p};n?.(`Sending ${m(s)}() call`,r),e.sendMessage(r,h)}catch(e){c(new r("TRANSMISSION_FAILED",e.message))}})},n),destroy:()=>{o=!0,e.removeMessageHandler(s);for(const{methodPath:e,reject:t,timeoutId:n}of i.values())clearTimeout(n),t(S(e));i.clear()}}})(e,o,i);O.push(l),clearTimeout(A),x=!0,M({remoteProxy:n,destroy:R})},D=()=>{const t={namespace:a,type:"SYN",channel:o,participantId:b};i?.("Sending handshake SYN",t);try{e.sendMessage(t)}catch(e){P(new r("TRANSMISSION_FAILED",e.message))}},F=t=>{l(t)&&(t=>{if(i?.("Received handshake SYN",t),t.participantId===E&&E!==C)return;if(E=t.participantId,D(),!(b>E||E===C))return;const n={namespace:a,channel:o,type:"ACK1",methodPaths:T};i?.("Sending handshake ACK1",n);try{e.sendMessage(n)}catch(e){return void P(new r("TRANSMISSION_FAILED",e.message))}})(t),d(t)&&(t=>{i?.("Received handshake ACK1",t);const n={namespace:a,channel:o,type:"ACK2"};i?.("Sending handshake ACK2",n);try{e.sendMessage(n)}catch(e){return void P(new r("TRANSMISSION_FAILED",e.message))}L()})(t),f(t)&&(e=>{i?.("Received handshake ACK2",e),L()})(t)};return e.addMessageHandler(F),O.push(()=>e.removeMessageHandler(F)),D(),I},I=new WeakSet,M=class{#t;#n;#r;#o;#i;#s=new Set;#a;#c=!1;constructor({remoteWindow:e,allowedOrigins:t}){if(!e)throw new r("INVALID_ARGUMENT","remoteWindow must be defined");this.#t=e,this.#n=t?.length?t:[window.origin]}initialize=({log:e,validateReceivedMessage:t})=>{this.#r=e,this.#o=t,window.addEventListener("message",this.#u)};sendMessage=(e,t)=>{if(l(e)){const n=this.#l(e);return void this.#t.postMessage(e,{targetOrigin:n,transfer:t})}if(d(e)||this.#c){const n=this.#c?(e=>{if(d(e))return{penpal:"synAck",methodNames:e.methodPaths.map(O)};if(h(e))return{penpal:"call",id:e.id,methodName:O(e.methodPath),args:e.args};if(p(e))return e.isError?{penpal:"reply",id:e.callId,resolution:"rejected",...e.isSerializedErrorInstance?{returnValue:e.value,returnValueIsError:!0}:{returnValue:e.value}}:{penpal:"reply",id:e.callId,resolution:"fulfilled",returnValue:e.value};throw x(e)})(e):e,r=this.#l(e);return void this.#t.postMessage(n,{targetOrigin:r,transfer:t})}if(f(e)){const{port1:n,port2:r}=new MessageChannel;this.#a=n,n.addEventListener("message",this.#d),n.start();const o=[r,...t||[]],i=this.#l(e);return void this.#t.postMessage(e,{targetOrigin:i,transfer:o})}if(!this.#a)throw new r("TRANSMISSION_FAILED","Cannot send message because the MessagePort is not connected");this.#a.postMessage(e,{transfer:t})};addMessageHandler=e=>{this.#s.add(e)};removeMessageHandler=e=>{this.#s.delete(e)};destroy=()=>{window.removeEventListener("message",this.#u),this.#f(),this.#s.clear()};#h=e=>this.#n.some(t=>t instanceof RegExp?t.test(e):t===e||"*"===t);#l=e=>{if(l(e))return"*";if(!this.#i)throw new r("TRANSMISSION_FAILED","Cannot send message because the remote origin is not established");return"null"===this.#i&&this.#n.includes("*")?"*":this.#i};#f=()=>{this.#a?.removeEventListener("message",this.#d),this.#a?.close(),this.#a=void 0};#u=({source:e,origin:t,ports:n,data:r})=>{if(e===this.#t){if((e=>c(e)&&"penpal"in e)(r)){this.#r?.("Please upgrade the child window to the latest version of Penpal."),this.#c=!0;try{r=(e=>{if("syn"===e.penpal)return{namespace:a,channel:void 0,type:"SYN",participantId:C};if("ack"===e.penpal)return{namespace:a,channel:void 0,type:"ACK2"};if("call"===e.penpal)return{namespace:a,channel:void 0,type:"CALL",id:e.id,methodPath:(t=e.methodName,t.split(".")),args:e.args};var t;if("reply"===e.penpal)return"fulfilled"===e.resolution?{namespace:a,channel:void 0,type:"REPLY",callId:e.id,value:e.returnValue}:{namespace:a,channel:void 0,type:"REPLY",callId:e.id,isError:!0,...e.returnValueIsError?{value:e.returnValue,isSerializedErrorInstance:!0}:{value:e.returnValue}};throw x(e)})(r)}catch(e){return void this.#r?.(`Failed to translate deprecated message: ${e.message}`)}}if(this.#o?.(r))if(this.#h(t)){if(l(r)&&(this.#f(),this.#i=t),f(r)&&!this.#c){if(this.#a=n[0],!this.#a)return void this.#r?.("Ignoring ACK2 because it did not include a MessagePort");this.#a.addEventListener("message",this.#d),this.#a.start()}for(const e of this.#s)e(r)}else this.#r?.(`Received a message from origin \`${t}\` which did not match allowed origins \`[${this.#n.join(", ")}]\``)}};#d=({data:e})=>{if(this.#o?.(e))for(const t of this.#s)t(e)}},P=document,A=window,R=Array.prototype,L=R.filter,D=R.indexOf,F=R.map,j=R.push,_=R.reverse,$=R.slice,k=R.splice,W=/^#[\w-]*$/,z=/^\.[\w-]*$/,H=/<.+>/,U=/^\w+$/;function V(e,t){return void 0===t&&(t=P),z.test(e)?t.getElementsByClassName(e.slice(1)):U.test(e)?t.getElementsByTagName(e):t.querySelectorAll(e)}function B(e,t){if(void 0===t&&(t=P),e){if(e.__cash)return e;var n=e;if(te(e)){if(t.__cash&&(t=t[0]),!(n=W.test(e)?t.getElementById(e.slice(1)):H.test(e)?$e(e):V(e,t)))return}else if(ee(e))return this.ready(e);(n.nodeType||n===A)&&(n=[n]),this.length=n.length;for(var r=0,o=this.length;r<o;r++)this[r]=n[r]}}function Y(e,t){return new B(e,t)}var K=Y.fn=Y.prototype=B.prototype={constructor:Y,__cash:!0,length:0,splice:k};K.get=function(e){return void 0===e?$.call(this):this[e<0?e+this.length:e]},K.eq=function(e){return Y(this.get(e))},K.first=function(){return this.eq(0)},K.last=function(){return this.eq(-1)},K.map=function(e){return Y(F.call(this,function(t,n){return e.call(t,n,t)}))},K.slice=function(){return Y($.apply(this,arguments))};var q=/(?:^\w|[A-Z]|\b\w)/g,G=/[\s-_]+/g;function X(e){return e.replace(q,function(e,t){return e[t?"toUpperCase":"toLowerCase"]()}).replace(G,"")}function J(e,t){for(var n=0,r=e.length;n<r&&!1!==t.call(e[n],e[n],n,e);n++);}Y.camelCase=X,Y.each=J,K.each=function(e){return J(this,function(t,n){return e.call(t,n,t)}),this},K.removeProp=function(e){return this.each(function(t,n){delete n[e]})},Y.extend=K.extend=function(e){void 0===e&&(e=this);for(var t=arguments,n=t.length,r=n<2?0:1;r<n;r++)for(var o in t[r])e[o]=t[r][o];return e};var Z=1;function Q(e,t){var n=e&&(e.matches||e.webkitMatchesSelector||e.mozMatchesSelector||e.msMatchesSelector||e.oMatchesSelector);return!!n&&n.call(e,t)}function ee(e){return"function"==typeof e}function te(e){return"string"==typeof e}function ne(e){return!isNaN(parseFloat(e))&&isFinite(e)}Y.guid=Z,Y.matches=Q,Y.isFunction=ee,Y.isString=te,Y.isNumeric=ne;var re=Array.isArray;function oe(e){return te(e)?function(t,n){return Q(n,e)}:e.__cash?function(t,n){return e.is(n)}:function(e,t,n){return t===n}}Y.isArray=re,K.prop=function(e,t){if(e){if(te(e))return arguments.length<2?this[0]&&this[0][e]:this.each(function(n,r){r[e]=t});for(var n in e)this.prop(n,e[n]);return this}},K.filter=function(e){if(!e)return Y();var t=ee(e)?e:oe(e);return Y(L.call(this,function(n,r){return t.call(n,r,n,e)}))};var ie=/\S+/g;function se(e){return te(e)&&e.match(ie)||[]}function ae(e){return e.filter(function(e,t,n){return n.indexOf(e)===t})}function ce(e,t,n){if(1===e.nodeType){var r=A.getComputedStyle(e,null);return t?n?r.getPropertyValue(t):r[t]:r}}function ue(e,t){return parseInt(ce(e,t),10)||0}K.hasClass=function(e){var t=se(e),n=!1;return t.length&&this.each(function(e,r){return!(n=r.classList.contains(t[0]))}),n},K.removeAttr=function(e){var t=se(e);return t.length?this.each(function(e,n){J(t,function(e){n.removeAttribute(e)})}):this},K.attr=function(e,t){if(e){if(te(e)){if(arguments.length<2){if(!this[0])return;var n=this[0].getAttribute(e);return null===n?void 0:n}return null===t?this.removeAttr(e):this.each(function(n,r){r.setAttribute(e,t)})}for(var r in e)this.attr(r,e[r]);return this}},K.toggleClass=function(e,t){var n=se(e),r=void 0!==t;return n.length?this.each(function(e,o){J(n,function(e){r?t?o.classList.add(e):o.classList.remove(e):o.classList.toggle(e)})}):this},K.addClass=function(e){return this.toggleClass(e,!0)},K.removeClass=function(e){return arguments.length?this.toggleClass(e,!1):this.attr("class","")},Y.unique=ae,K.add=function(e,t){return Y(ae(this.get().concat(Y(e,t).get())))};var le=/^--/;function de(e){return le.test(e)}var fe={},he=P.createElement("div").style,pe=["webkit","moz","ms","o"];function ge(e,t){if(void 0===t&&(t=de(e)),t)return e;if(!fe[e]){var n=X(e),r=""+n.charAt(0).toUpperCase()+n.slice(1);J((n+" "+pe.join(r+" ")+r).split(" "),function(t){if(t in he)return fe[e]=t,!1})}return fe[e]}Y.prefixedProp=ge;var me={animationIterationCount:!0,columnCount:!0,flexGrow:!0,flexShrink:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0};function ve(e,t,n){return void 0===n&&(n=de(e)),n||me[e]||!ne(t)?t:t+"px"}K.css=function(e,t){if(te(e)){var n=de(e);return e=ge(e,n),arguments.length<2?this[0]&&ce(this[0],e,n):e?(t=ve(e,t,n),this.each(function(r,o){1===o.nodeType&&(n?o.style.setProperty(e,t):o.style[e]=t)})):this}for(var r in e)this.css(r,e[r]);return this};var ye="__cashData",be=/^data-(.*)/;function we(e){return e[ye]=e[ye]||{}}function Ee(e,t){var n=we(e);if(t){if(!(t in n)){var r=e.dataset?e.dataset[t]||e.dataset[X(t)]:Y(e).attr("data-"+t);if(void 0!==r){try{r=JSON.parse(r)}catch(e){}n[t]=r}}return n[t]}return n}function Ne(e,t){return ue(e,"border"+(t?"Left":"Top")+"Width")+ue(e,"padding"+(t?"Left":"Top"))+ue(e,"padding"+(t?"Right":"Bottom"))+ue(e,"border"+(t?"Right":"Bottom")+"Width")}function Se(e,t){for(var n=0,r=t.length;n<r;n++)if(e.indexOf(t[n])<0)return!1;return!0}function Ce(e,t,n){J(e[n],function(e){e[0];var r=e[1];t.removeEventListener(n,r)}),delete e[n]}Y.hasData=function(e){return ye in e},K.data=function(e,t){var n=this;if(!e){if(!this[0])return;return J(this[0].attributes,function(e){var t=e.name.match(be);t&&n.data(t[1])}),Ee(this[0])}if(te(e))return void 0===t?this[0]&&Ee(this[0],e):this.each(function(n,r){return function(e,t,n){we(e)[t]=n}(r,e,t)});for(var r in e)this.data(r,e[r]);return this},K.removeData=function(e){return this.each(function(t,n){return function(e,t){void 0===t?delete e[ye]:delete we(e)[t]}(n,e)})},J(["Width","Height"],function(e){K["inner"+e]=function(){if(this[0])return this[0]===A?A["inner"+e]:this[0]["client"+e]}}),J(["width","height"],function(e,t){K[e]=function(n){return this[0]?arguments.length?(n=parseInt(n,10),this.each(function(r,o){if(1===o.nodeType){var i=ce(o,"boxSizing");o.style[e]=ve(e,n+("border-box"===i?Ne(o,!t):0))}})):this[0]===A?this[0][X("outer-"+e)]:this[0].getBoundingClientRect()[e]-Ne(this[0],!t):void 0===n?void 0:this}}),J(["Width","Height"],function(e,t){K["outer"+e]=function(n){if(this[0])return this[0]===A?A["outer"+e]:this[0]["offset"+e]+(n?ue(this[0],"margin"+(t?"Top":"Left"))+ue(this[0],"margin"+(t?"Bottom":"Right")):0)}});var Oe="__cashEvents";function xe(e){return e[Oe]=e[Oe]||{}}function Te(e){var t=e.split(".");return[t[0],t.slice(1).sort()]}function Ie(e,t,n,r){var o=xe(e);if(t){var i=o[t];if(!i)return;r&&(r.guid=r.guid||Z++),o[t]=i.filter(function(o){var i=o[0],s=o[1];if(r&&s.guid!==r.guid||!Se(i,n))return!0;e.removeEventListener(t,s)})}else if(n&&n.length)for(t in o)Ie(e,t,n,r);else for(t in o)Ce(o,e,t)}K.off=function(e,t){var n=this;return void 0===e?this.each(function(e,t){return Ie(t)}):J(se(e),function(e){var r=Te(e),o=r[0],i=r[1];n.each(function(e,n){return Ie(n,o,i,t)})}),this},K.on=function(e,t,n,r){var o=this;if(!te(e)){for(var i in e)this.on(i,t,e[i]);return this}return ee(t)&&(n=t,t=!1),J(se(e),function(e){var i=Te(e),s=i[0],a=i[1];o.each(function(e,o){var i=function e(i){if(!i.namespace||Se(a,i.namespace.split("."))){var c=o;if(t){for(var u=i.target;!Q(u,t);){if(u===o)return;if(!(u=u.parentNode))return}c=u}i.namespace=i.namespace||"";var l=n.call(c,i,i.data);r&&Ie(o,s,a,e),!1===l&&(i.preventDefault(),i.stopPropagation())}};i.guid=n.guid=n.guid||Z++,function(e,t,n,r){r.guid=r.guid||Z++;var o=xe(e);o[t]=o[t]||[],o[t].push([n,r]),e.addEventListener(t,r)}(o,s,a,i)})}),this},K.one=function(e,t,n){return this.on(e,t,n,!0)},K.ready=function(e){var t=function(){return e(Y)};return"loading"!==P.readyState?setTimeout(t):P.addEventListener("DOMContentLoaded",t),this},K.trigger=function(e,t){var n=e;if(te(e)){var r=Te(e),o=r[0],i=r[1];(n=P.createEvent("HTMLEvents")).initEvent(o,!0,!0),n.namespace=i.join(".")}return n.data=t,this.each(function(e,t){t.dispatchEvent(n)})};var Me=/select-one/i,Pe=/select-multiple/i;function Ae(e){var t=e.type;return Me.test(t)?function(e){return e.selectedIndex<0?null:e.options[e.selectedIndex].value}(e):Pe.test(t)?function(e){var t=[];return J(e.options,function(e){!e.selected||e.disabled||e.parentNode.disabled||t.push(e.value)}),t}(e):e.value}var Re=/%20/g,Le=/file|reset|submit|button|image/i,De=/radio|checkbox/i;K.serialize=function(){var e="";return this.each(function(t,n){J(n.elements||[n],function(t){if(!t.disabled&&t.name&&"FIELDSET"!==t.tagName&&!Le.test(t.type)&&(!De.test(t.type)||t.checked)){var n=Ae(t);void 0!==n&&J(re(n)?n:[n],function(n){e+=function(e,t){return"&"+encodeURIComponent(e)+"="+encodeURIComponent(t).replace(Re,"+")}(t.name,n)})}})}),e.substr(1)},K.val=function(e){return void 0===e?this[0]&&Ae(this[0]):this.each(function(t,n){var r=Pe.test(n.type),o=null===e?r?[]:"":e;r&&re(o)?J(n.options,function(e){e.selected=o.indexOf(e.value)>=0}):n.value=o})},K.clone=function(){return this.map(function(e,t){return t.cloneNode(!0)})},K.detach=function(){return this.each(function(e,t){t.parentNode&&t.parentNode.removeChild(t)})};var Fe,je=/^\s*<(\w+)[^>]*>/,_e=/^\s*<(\w+)\s*\/?>(?:<\/\1>)?\s*$/;function $e(e){if(function(){if(!Fe){var e=P.createElement("table"),t=P.createElement("tr");Fe={"*":P.createElement("div"),tr:P.createElement("tbody"),td:t,th:t,thead:e,tbody:e,tfoot:e}}}(),!te(e))return[];if(_e.test(e))return[P.createElement(RegExp.$1)];var t=je.test(e)&&RegExp.$1,n=Fe[t]||Fe["*"];return n.innerHTML=e,Y(n.childNodes).detach().get()}function ke(e,t,n){if(void 0!==t){var r=te(t);!r&&t.length?J(t,function(t){return ke(e,t,n)}):J(e,r?function(e){e.insertAdjacentHTML(n?"afterbegin":"beforeend",t)}:function(e,r){return function(e,t,n){n?e.insertBefore(t,e.childNodes[0]):e.appendChild(t)}(e,r?t.cloneNode(!0):t,n)})}}Y.parseHTML=$e,K.empty=function(){var e=this[0];if(e)for(;e.firstChild;)e.removeChild(e.firstChild);return this},K.append=function(){var e=this;return J(arguments,function(t){ke(e,t)}),this},K.appendTo=function(e){return ke(Y(e),this),this},K.html=function(e){if(void 0===e)return this[0]&&this[0].innerHTML;var t=e.nodeType?e[0].outerHTML:e;return this.each(function(e,n){n.innerHTML=t})},K.insertAfter=function(e){var t=this;return Y(e).each(function(e,n){var r=n.parentNode;t.each(function(t,o){r.insertBefore(e?o.cloneNode(!0):o,n.nextSibling)})}),this},K.after=function(){var e=this;return J(_.apply(arguments),function(t){_.apply(Y(t).slice()).insertAfter(e)}),this},K.insertBefore=function(e){var t=this;return Y(e).each(function(e,n){var r=n.parentNode;t.each(function(t,o){r.insertBefore(e?o.cloneNode(!0):o,n)})}),this},K.before=function(){var e=this;return J(arguments,function(t){Y(t).insertBefore(e)}),this},K.prepend=function(){var e=this;return J(arguments,function(t){ke(e,t,!0)}),this},K.prependTo=function(e){return ke(Y(e),_.apply(this.slice()),!0),this},K.remove=function(){return this.detach().off()},K.replaceWith=function(e){var t=this;return this.each(function(n,r){var o=r.parentNode;if(o){var i=n?Y(e).clone():Y(e);if(!i[0])return t.remove(),!1;o.replaceChild(i[0],r),Y(i[0]).after(i.slice(1))}})},K.replaceAll=function(e){return Y(e).replaceWith(this),this},K.text=function(e){return void 0===e?this[0]?this[0].textContent:"":this.each(function(t,n){n.textContent=e})};var We=P.documentElement;K.offset=function(){var e=this[0];if(e){var t=e.getBoundingClientRect();return{top:t.top+A.pageYOffset-We.clientTop,left:t.left+A.pageXOffset-We.clientLeft}}},K.offsetParent=function(){return Y(this[0]&&this[0].offsetParent)},K.position=function(){var e=this[0];if(e)return{left:e.offsetLeft,top:e.offsetTop}},K.children=function(e){var t=[];return this.each(function(e,n){j.apply(t,n.children)}),t=Y(ae(t)),e?t.filter(function(t,n){return Q(n,e)}):t},K.contents=function(){var e=[];return this.each(function(t,n){j.apply(e,"IFRAME"===n.tagName?[n.contentDocument]:n.childNodes)}),Y(e.length&&ae(e))},K.find=function(e){for(var t=[],n=0,r=this.length;n<r;n++){var o=V(e,this[n]);o.length&&j.apply(t,o)}return Y(t.length&&ae(t))},K.has=function(e){var t=te(e)?function(t,n){return!!V(e,n).length}:function(t,n){return n.contains(e)};return this.filter(t)},K.is=function(e){if(!e||!this[0])return!1;var t=oe(e),n=!1;return this.each(function(r,o){return!(n=t(r,o,e))}),n},K.next=function(){return Y(this[0]&&this[0].nextElementSibling)},K.not=function(e){if(!e||!this[0])return this;var t=oe(e);return this.filter(function(n,r){return!t(n,r,e)})},K.parent=function(){var e=[];return this.each(function(t,n){n&&n.parentNode&&e.push(n.parentNode)}),Y(ae(e))},K.index=function(e){var t=e?Y(e)[0]:this[0],n=e?this:Y(t).parent().children();return D.call(n,t)},K.closest=function(e){return e&&this[0]?this.is(e)?this.filter(e):this.parent().closest(e):Y()},K.parents=function(e){var t,n=[];return this.each(function(r,o){for(t=o;t&&t.parentNode&&t!==P.body.parentNode;)t=t.parentNode,(!e||e&&Q(t,e))&&n.push(t)}),Y(ae(n))},K.prev=function(){return Y(this[0]&&this[0].previousElementSibling)},K.siblings=function(){var e=this[0];return this.parent().children().filter(function(t,n){return n!==e})};const ze=Y,He=new class{getFiberNode(e){try{const t=Object.keys(e).find(e=>e.startsWith("__reactFiber$")||e.startsWith("__reactInternalInstance$"));return t?e[t]:null}catch(e){return console.warn("[ReactFiberService] Error getting fiber node:",e),null}}getDebugOwner(e){const t=this.getFiberNode(e);return t?._debugOwner??null}getDebugSource(e){const t=this.getFiberNode(e);return t?._debugSource??null}getOwnerDebugSource(e){const t=this.getDebugOwner(e);return t?._debugSource??null}hasDirectSourceInfo(e){return!!e.getAttribute("data-nocode-id")||!!this.getDebugSource(e)}hasOwnerNocodeId(e){const t=this.getDebugOwner(e);if(!t?.memoizedProps)return!1;const n=t.memoizedProps["data-nocode-id"];return"string"==typeof n&&n.length>0}getOwnerNocodeId(e){const t=this.getDebugOwner(e);if(!t?.memoizedProps)return null;const n=t.memoizedProps["data-nocode-id"];return"string"==typeof n?n:null}isSelectableElement(e){if(this.hasDirectSourceInfo(e))return!0;const t=this.getFiberNode(e),n=this.getOwnerDebugSource(e);return!!(t?.return&&5!==t.return.tag&&this.hasOwnerNocodeId(e)&&n)}isComponent(e){if(!this.isSelectableElement(e))return!1;if(e.getAttribute("data-nocode-components-name"))return!0;if(this.getDebugSource(e))return!1;const t=this.getFiberNode(e);return!(!t?.return||5===t.return.tag)}getComponentName(e){const t=e.getAttribute("data-nocode-tag-name");if(t)return t;const n=this.getDebugOwner(e);if(n?.type){const e=n.type;if("function"==typeof e){const t=e.displayName||e.name||"Unknown";return this.normalizeComponentName(t)}if("string"==typeof e)return e}return e.tagName.toLowerCase()}normalizeComponentName(e){return e.replace(/\d+$/,"")}getComponentProps(e){if(!this.isComponent(e))return;const t=this.getDebugOwner(e);return t?.memoizedProps?this.sanitizeProps(t.memoizedProps):void 0}sanitizeProps(e){const t={};for(const[n,r]of Object.entries(e)){if("children"===n||n.startsWith("_"))continue;const e=this.sanitizeValue(r);void 0!==e&&(t[n]=e)}return t}sanitizeValue(e){if(null===e)return null;if(void 0===e)return;if("function"==typeof e)return;if("symbol"==typeof e)return;if("object"!=typeof e)return e;if("$$typeof"in e)return;if(e instanceof Node)return;if(Array.isArray(e)){const t=[];for(const n of e){const e=this.sanitizeValue(n);void 0!==e&&t.push(e)}return t}const t={};for(const[n,r]of Object.entries(e)){if(n.startsWith("_"))continue;const e=this.sanitizeValue(r);void 0!==e&&(t[n]=e)}return t}buildComponentInfo(e){const t=this.isComponent(e),n={isComponent:t,componentType:t?"component":"host",name:t?this.getComponentName(e):e.tagName.toLowerCase()},r=e.getAttribute("data-nocode-components-name"),o=e.getAttribute("data-nocode-components-version");if(r&&(n.componentsName=r),o&&(n.componentsVersion=o),t){const t=this.getComponentProps(e)??{},r=this.removeSpecialProps(t);n.props=r}return n}removeSpecialProps(e){const t={};for(const[n,r]of Object.entries(e))"componentsName"!==n&&"componentsVersion"!==n&&(n.startsWith("data-nocode-")||(t[n]=r));return t}},Ue="data-dnd",Ve=`[${Ue}]`;function Be(e){return document.querySelector(`[${Ue}="${e}"]`)}const Ye=(e,t)=>{const n=e.getBoundingClientRect(),{x:r,y:o}=((e,t)=>{let n=e.x,r=e.y;if(t){const e=t.getBoundingClientRect();n-=e.left,r-=e.top}return{x:n,y:r}})({x:n.left,y:n.top},t);return{width:e.offsetWidth,height:e.offsetHeight,top:o,left:r}},Ke=(e,t)=>{const n=Ye(e,t),r=function(e){return e.dataset}(e),o=qe(e),i=Ge(e),s=(e=>{const t=window.getComputedStyle(e);return{display:t.display,flexDirection:t.flexDirection,flexWrap:t.flexWrap,position:t.position}})(e),a=r.dnd||"",c=function(e){if(!e)return{};const t=e.split(":");if(t.length>=3){const n=t.pop(),r=t.pop(),o=t.join(":");return{id:e,filename:decodeURIComponent(o),component:r,codeId:n}}return 2===t.length?{id:e,component:t[0],codeId:t[1]}:{id:e}}(a),u=function(e){return He.buildComponentInfo(e)}(e),l=function(e){return"true"===e.getAttribute("data-nocode-container-placeholder")}(e),d=(e=>{const t=e.querySelectorAll(`:scope > ${Ve}`);if(!t.length)return[];const n=[];return t.forEach(e=>{const t=e;n.push(Ye(t))}),n})(e);return{id:a,codeId:c.codeId,name:c.component||e.tagName.toLowerCase(),filename:c.filename,bounding:n,display:o,computedStyle:s,text:i,containerPlaceholder:l||void 0,componentInfo:u,childrenBoundings:d.length>0?d:void 0}},qe=e=>ze(e).css("display"),Ge=e=>{const t=[];return e.childNodes.forEach(e=>{if(e.nodeType===Node.TEXT_NODE){const n=e.textContent?.trim()||"";n&&t.push(n)}}),t.join(" ")};function Xe(e){const t=["div","p","section","article","main","header","footer","nav","h1","h2","h3","h4","h5","h6","span","a","button","i","input","textarea","select","label","form","ul","ol","li","table","thead","tbody","tr","td","th","img","video","audio","canvas","svg"];try{const n=e.tagName.toLowerCase();if(!t.includes(n))return!1;const r=window.getComputedStyle(e);if("none"===r.display||"hidden"===r.visibility||"0"===r.opacity)return!1;const o=e.getBoundingClientRect();return!("inline"!==r.display&&"inline-block"!==r.display&&(0===o.width||0===o.height))}catch(e){return console.warn("Element validation failed:",e),!1}}function Je(e,t=20){let n=e,r=0;for(;n&&r<t;){if(n.getAttribute(Ue))return n;n=n.parentElement,r++}return null}function Ze(e){const t=window.getComputedStyle(e),n={};for(let e=0;e<t.length;e++){const r=t[e];n[r]=t.getPropertyValue(r)}return n}let Qe=null;function et(e){return(...t)=>{try{const n=e(...t);return n&&"function"==typeof n.then?n.catch(n=>(console.error(`Async error in ${e.name}:`,n),console.error("Error stack:",n.stack),console.error("Function arguments:",t),null)):n}catch(n){return console.error(`Sync error in ${e.name}:`,n),n instanceof Error&&console.error("Error stack:",n.stack),console.error("Function arguments:",t),null}}}const tt={getDraggableParentsData:(e,t)=>{const n=function(e,t){const n=((e,t)=>{const n=document.elementFromPoint(e,t);if(!n)return null;const r=n=>{if(n?.shadowRoot){const o=n.shadowRoot.elementFromPoint(e,t);return o===n?n:o?.shadowRoot?r(o):o||n}return n};return r(n)})(e,t);if(!n)return null;let r=n;if(!Xe(r)){let e=r.parentElement,t=0;const n=20;for(;e&&t<n;){if(Xe(e)){r=e;break}e=e.parentElement,t++}if(!Xe(r))return null}const o=Je(r);return o&&Xe(o)?o:null}(e.x,e.y);if(!n)return;const r=(e=>{const t=ze(e).closest(Ve).get(0),n=ze(e).parents(Ve).get();return n[0]!==t&&n.unshift(t),n})(n);if(r.length){if(t){const e=r.map(e=>Ke(e));return{...e[0],computedStyle:Ze(n),parents:e.slice(1)}}return{...Ke(r[0]),computedStyle:Ze(r[0])}}},getElementDataById:e=>{const t=Be(e);if(t)return{...Ke(t),computedStyle:Ze(t)};console.warn("[getElementDataById] Element not found for domId:",e)},getEditableTextElementAtPosition:e=>{const t=function(e,t){if(document.caretPositionFromPoint){const n=document.caretPositionFromPoint(e,t);return n?.offsetNode??null}if(document.caretRangeFromPoint){const n=document.caretRangeFromPoint(e,t);return n?.startContainer??null}return document.elementFromPoint(e,t)}(e.x,e.y);if(!t)return void console.log("[getEditableTextElementAtPosition] No node at point:",e);if(t.nodeType!==Node.TEXT_NODE)return void console.log("[getEditableTextElementAtPosition] Not a text node:",t.nodeType);const n=t.textContent?.trim();if(!n)return void console.log("[getEditableTextElementAtPosition] Empty text node");const r=t.parentElement;if(!r)return void console.log("[getEditableTextElementAtPosition] No parent element");const o=Je(r);if(o){if(function(e){const t=e.childNodes;let n=!1;for(let e=0;e<t.length;e++){const r=t[e];if(r.nodeType===Node.ELEMENT_NODE)return!1;if(r.nodeType===Node.TEXT_NODE){const e=r.textContent?.trim();e&&(n=!0)}}return n}(o))return console.log("[getEditableTextElementAtPosition] Found editable text element:",o.tagName,o.textContent),{...Ke(o),computedStyle:Ze(o)};console.log("[getEditableTextElementAtPosition] Element has child elements, cannot edit directly:",o.tagName)}else console.log("[getEditableTextElementAtPosition] No marked element found")},updateElementTextContent:(e,t)=>{const n=Be(e);return n?(n.textContent=t,!0):(console.warn("[updateElementTextContent] Element not found:",e),!1)},scrollToElement:e=>{const t=Be(e);return t?(t.scrollIntoView({behavior:"instant",block:"center",inline:"center"}),!0):(console.warn("[scrollToElement] Element not found for domId:",e),!1)},scrollPageBy:(e,t)=>(window.scrollBy(e,t),!0),highlightElement:e=>{if(Qe&&(Qe.style.outline="",Qe.style.outlineOffset="",Qe=null),!e)return!0;const t=Be(e);return t?(t.style.outline="2px solid rgba(54, 210, 190, 0.8)",t.style.outlineOffset="-1px",Qe=t,!0):(console.warn("[highlightElement] Element not found:",e),!1)},getProjectLibVersions:function(){try{const e=document.body;if(!e)return console.warn("[sandbox] document.body is not available"),null;const t=e.getAttribute("data-nocode-lib-versions");if(!t)return console.warn("[sandbox] data-nocode-lib-versions attribute not found on body"),null;const n=JSON.parse(t);return"object"!=typeof n||null===n?(console.warn("[sandbox] data-nocode-lib-versions is not a valid object"),null):n}catch(e){return console.error("[sandbox] Failed to parse data-nocode-lib-versions:",e),null}},getCompilerVersion:function(){try{const e=document.body;return e?e.getAttribute("data-nocode-compiler-version"):null}catch(e){return console.error("[sandbox] Failed to get compiler version:",e),null}}},nt=Object.fromEntries(Object.entries(tt).map(([e,t])=>[e,et(t)])),rt="nocode-design-mode";let ot=null,it=!1,st=null;const at=t()(()=>{ot?.onWindowMutated&&(console.log(`${rt} - Notifying parent of DOM mutation`),ot.onWindowMutated({added:{},removed:{}}))},100),ct=async()=>{if(it||ot)return ot;it=!0,console.log(`${rt} - Creating penpal connection`);const e=(({messenger:e,methods:t={},timeout:n,channel:o,log:i})=>{if(!e)throw new r("INVALID_ARGUMENT","messenger must be defined");if(I.has(e))throw new r("INVALID_ARGUMENT","A messenger can only be used for a single connection");I.add(e);const s=[e.destroy],u=(e=>{let t,n=!1;return(...r)=>(n||(n=!0,t=e(...r)),t)})(t=>{if(t){const t={namespace:a,channel:o,type:"DESTROY"};try{e.sendMessage(t)}catch(e){}}for(const e of s)e();i?.("Connection destroyed")}),l=e=>(e=>c(e)&&e.namespace===a)(e)&&e.channel===o;return{promise:(async()=>{try{e.initialize({log:i,validateReceivedMessage:l}),e.addMessageHandler(e=>{(e=>"DESTROY"===e.type)(e)&&u(!1)});const{remoteProxy:r,destroy:a}=await T({messenger:e,methods:t,timeout:n,channel:o,log:i});return s.push(a),r}catch(e){throw u(!0),e}})(),destroy:()=>{u(!0)}}})({messenger:new M({remoteWindow:window===window.top?(console.warn(`${rt} - Not in an iframe, using window.parent as fallback`),window.parent):window.parent===window.top?window.parent:window.top?(console.log(`${rt} - Using window.top for nested iframe scenario`),window.top):window.parent,allowedOrigins:["*"]}),methods:nt});return e.promise.then(e=>{if(!e)return console.error(`${rt} - Failed to setup penpal connection: child is null`),void ut();ot=e,console.log(`${rt} - Penpal connection set`),(()=>{if(st)return;st=new MutationObserver(e=>{e.some(e=>{const t=e.target;return"SCRIPT"!==t.tagName&&"STYLE"!==t.tagName&&("attributes"!==e.type||"style"===e.attributeName||"class"===e.attributeName)})&&at()});const e=()=>{document.body&&st&&(st.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class"],characterData:!0}),console.log(`${rt} - MutationObserver started`))};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",e):e()})()}).finally(()=>{it=!1}),e.promise.catch(e=>{console.error(`${rt} - Failed to setup penpal connection:`,e),ut()}),ot},ut=t()(()=>{it||(console.log(`${rt} - Reconnecting to penpal parent`),ot=null,ct())},1e3);ct()})()})();
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@meituan-nocode/nocode-design-mode-sandbox-script",
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
|
+
"description": "NoCode Design Mode Sandbox Script",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/index.js",
|
|
9
|
+
"require": "./dist/index.js",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/css-tree": "^2.3.8",
|
|
22
|
+
"@types/lodash": "^4.17.0",
|
|
23
|
+
"@types/node": "^20.0.0",
|
|
24
|
+
"cash-dom": "^2.0.2",
|
|
25
|
+
"cross-env": "^7.0.3",
|
|
26
|
+
"css-tree": "^2.3.1",
|
|
27
|
+
"lodash": "^4.17.21",
|
|
28
|
+
"nanoid": "^3.3.7",
|
|
29
|
+
"penpal": "^7.0.4",
|
|
30
|
+
"ts-loader": "^9.4.0",
|
|
31
|
+
"typescript": "^5.0.0",
|
|
32
|
+
"webpack": "^5.88.0",
|
|
33
|
+
"webpack-cli": "^5.1.0",
|
|
34
|
+
"webpack-dev-server": "^4.15.2",
|
|
35
|
+
"zod": "^4.1.13"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"dev": "webpack serve --mode=development",
|
|
39
|
+
"build": "npm run clean && webpack --mode=production",
|
|
40
|
+
"clean": "rm -rf dist"
|
|
41
|
+
}
|
|
42
|
+
}
|