@kdesigner/amis-vue 0.0.0-alpha.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/dist/index.cjs ADDED
@@ -0,0 +1,1037 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __exportAll = (all, no_symbols) => {
10
+ let target = {};
11
+ for (var name in all) __defProp(target, name, {
12
+ get: all[name],
13
+ enumerable: true
14
+ });
15
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
16
+ return target;
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
20
+ key = keys[i];
21
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
22
+ get: ((k) => from[k]).bind(null, key),
23
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
24
+ });
25
+ }
26
+ return to;
27
+ };
28
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
29
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
30
+ value: mod,
31
+ enumerable: true
32
+ }) : target, mod));
33
+ //#endregion
34
+ let _kdesigner_core = require("@kdesigner/core");
35
+ let _kdesigner_shared = require("@kdesigner/shared");
36
+ let vue = require("vue");
37
+ let amis = require("amis");
38
+ let react = require("react");
39
+ react = __toESM(react, 1);
40
+ let veaury = require("veaury");
41
+ let vue_router = require("vue-router");
42
+ let copy_to_clipboard = require("copy-to-clipboard");
43
+ copy_to_clipboard = __toESM(copy_to_clipboard, 1);
44
+ let react_dom_client = require("react-dom/client");
45
+ require("moment/locale/zh-cn");
46
+ let js_yaml = require("js-yaml");
47
+ js_yaml = __toESM(js_yaml);
48
+ let amis_core = require("amis-core");
49
+ require("@kdesigner/amis-extensions/style.css");
50
+ require("@kdesigner/components/style");
51
+ //#region src/editor/AmisPageEditor.vue?vue&type=script&lang.ts
52
+ var AmisPageEditor_vue_vue_type_script_lang_default = (0, vue.defineComponent)({
53
+ props: {
54
+ schema: Object,
55
+ rollbackPageSource: Function,
56
+ getPageSource: {
57
+ type: Function,
58
+ required: true
59
+ },
60
+ savePageSource: {
61
+ type: Function,
62
+ required: true
63
+ }
64
+ },
65
+ emits: ["exit"],
66
+ setup(props, { emit }) {
67
+ const editorRef = (0, vue.ref)(null);
68
+ let fetched = false;
69
+ let editorInited = false;
70
+ const { savePageSource, rollbackPageSource, getPageSource } = props;
71
+ function pushSchema(schema) {
72
+ postMsg({
73
+ type: "setSchema",
74
+ data: schema
75
+ });
76
+ }
77
+ /** 首次初始化:有 schema 直接推;否则自行拉取(宿主已去掉前置 loading) */
78
+ function applyInitialSchema() {
79
+ if (fetched) return;
80
+ if (props.schema != null) {
81
+ fetched = true;
82
+ pushSchema(props.schema);
83
+ return;
84
+ }
85
+ fetched = true;
86
+ getPageSource(true).then((page) => {
87
+ pushSchema(page);
88
+ }).catch((e) => {
89
+ fetched = false;
90
+ postMsg({
91
+ type: "toast",
92
+ level: "error",
93
+ message: e.message || e.toString()
94
+ });
95
+ });
96
+ }
97
+ function handleEvent(event) {
98
+ if (event.data == "amis-editor-inited") {
99
+ editorInited = true;
100
+ applyInitialSchema();
101
+ } else if (event.data === "amis-editor-reload") {
102
+ fetched = false;
103
+ startFetch();
104
+ } else if (event.data === "amis-editor-exit") emit("exit");
105
+ else if (event.data === "amis-editor-rollback") {
106
+ if (rollbackPageSource) rollbackPageSource().then(() => {
107
+ postMsg({
108
+ type: "toast",
109
+ level: "info",
110
+ message: "回滚成功"
111
+ });
112
+ }).catch((e) => {
113
+ postMsg({
114
+ type: "toast",
115
+ level: "error",
116
+ message: e.message || e.toString()
117
+ });
118
+ }).then(() => {
119
+ fetched = false;
120
+ return startFetch();
121
+ });
122
+ } else if ((0, _kdesigner_shared.isString)(event.data) && event.data.startsWith("{")) {
123
+ var data = JSON.parse(event.data);
124
+ if (data.type == "save") savePageSource(data.data).then(() => {
125
+ postMsg({
126
+ type: "toast",
127
+ message: "保存成功"
128
+ });
129
+ }).catch((e) => {
130
+ postMsg({
131
+ type: "toast",
132
+ level: "error",
133
+ message: e.message || e.toString()
134
+ });
135
+ });
136
+ else if (data.type == "ajaxFetch") (0, _kdesigner_core.ajaxFetch)(data.data).then((result) => {
137
+ postMsg({
138
+ type: "ajaxComplete",
139
+ reqId: data.reqId,
140
+ result
141
+ });
142
+ });
143
+ } else console.log("unknown-message", event.data);
144
+ }
145
+ function postMsg(msg) {
146
+ const frame = editorRef.value;
147
+ if (!frame) return;
148
+ const str = (0, _kdesigner_shared.isString)(msg) ? msg : JSON.stringify(msg);
149
+ frame.contentWindow.postMessage(str, "*");
150
+ }
151
+ function startFetch() {
152
+ if (!editorRef.value) return;
153
+ fetched = true;
154
+ return getPageSource(true).then((page) => {
155
+ postMsg({
156
+ type: "toast",
157
+ level: "info",
158
+ message: "页面加载成功"
159
+ });
160
+ postMsg({
161
+ type: "setSchema",
162
+ data: page
163
+ });
164
+ }).catch((e) => {
165
+ postMsg({
166
+ type: "toast",
167
+ level: "error",
168
+ message: e.message || e.toString()
169
+ });
170
+ throw e;
171
+ });
172
+ }
173
+ window.addEventListener("message", handleEvent);
174
+ (0, vue.watch)(() => props.schema, (schema) => {
175
+ if (!editorInited || schema == null) return;
176
+ fetched = true;
177
+ pushSchema(schema);
178
+ });
179
+ (0, vue.onUnmounted)(() => {
180
+ console.log("editor unmounted");
181
+ window.removeEventListener("message", handleEvent);
182
+ });
183
+ return { editorRef };
184
+ }
185
+ });
186
+ //#endregion
187
+ //#region \0plugin-vue:export-helper
188
+ var _plugin_vue_export_helper_default = (sfc, props) => {
189
+ const target = sfc.__vccOpts || sfc;
190
+ for (const [key, val] of props) target[key] = val;
191
+ return target;
192
+ };
193
+ //#endregion
194
+ //#region src/editor/AmisPageEditor.vue
195
+ const _hoisted_1$3 = {
196
+ style: {
197
+ "width": "100%",
198
+ "height": "100%",
199
+ "border": "none"
200
+ },
201
+ ref: "editorRef",
202
+ src: "/amis-editor/index.html"
203
+ };
204
+ function _sfc_render$3(_ctx, _cache, $props, $setup, $data, $options) {
205
+ return (0, vue.openBlock)(), (0, vue.createElementBlock)("iframe", _hoisted_1$3, null, 512);
206
+ }
207
+ var AmisPageEditor_default = /*#__PURE__*/ _plugin_vue_export_helper_default(AmisPageEditor_vue_vue_type_script_lang_default, [["render", _sfc_render$3]]);
208
+ //#endregion
209
+ //#region src/editor/XuiPageEditor.vue
210
+ var XuiPageEditor_default = /* @__PURE__ */ (0, vue.defineComponent)({
211
+ __name: "XuiPageEditor",
212
+ props: {
213
+ rollbackPageSource: Function,
214
+ getPageSource: {
215
+ type: Function,
216
+ required: true
217
+ },
218
+ savePageSource: {
219
+ type: Function,
220
+ required: true
221
+ }
222
+ },
223
+ emits: ["exit"],
224
+ setup(__props, { emit: __emit }) {
225
+ const props = __props;
226
+ const { getPageSource } = props;
227
+ const { useI18n } = (0, _kdesigner_core.useAdapter)();
228
+ const emit = __emit;
229
+ function handleExit() {
230
+ emit("exit");
231
+ }
232
+ const componentType = (0, vue.shallowRef)((0, vue.markRaw)(AmisPageEditor_default));
233
+ const schemaRef = (0, vue.shallowRef)();
234
+ (0, vue.watchEffect)(() => {
235
+ getPageSource(false).then((schema) => {
236
+ if (!schema) schema = {};
237
+ schemaRef.value = (0, vue.markRaw)(schema);
238
+ const schemaTypeName = schema["xui:schema-type"];
239
+ if (!schemaTypeName) {
240
+ componentType.value = (0, vue.markRaw)(AmisPageEditor_default);
241
+ return;
242
+ }
243
+ const schemaType = (0, _kdesigner_core.getSchemaProcessorType)(schemaTypeName);
244
+ if (!schemaType) {
245
+ const { t } = useI18n();
246
+ (0, _kdesigner_core.useAdapter)().notify("error", t("nop.err.unknown-schema-type"));
247
+ throw new Error("nop.err.unknown-schema-type");
248
+ }
249
+ componentType.value = (0, vue.markRaw)(schemaType.editorComponentType);
250
+ });
251
+ });
252
+ return (_ctx, _cache) => {
253
+ return (0, vue.openBlock)(), (0, vue.createBlock)((0, vue.resolveDynamicComponent)(componentType.value), (0, vue.mergeProps)(props, {
254
+ schema: schemaRef.value,
255
+ onExit: handleExit
256
+ }), null, 16, ["schema"]);
257
+ };
258
+ }
259
+ });
260
+ //#endregion
261
+ //#region src/editor/XuiPageEditorDialog.vue?vue&type=script&setup=true&lang.ts
262
+ const _hoisted_1$2 = {
263
+ key: 0,
264
+ class: "page-editor-root",
265
+ role: "dialog",
266
+ "aria-modal": "true"
267
+ };
268
+ //#endregion
269
+ //#region src/editor/XuiPageEditorDialog.vue
270
+ var XuiPageEditorDialog_default = /* @__PURE__ */ (0, vue.defineComponent)({
271
+ __name: "XuiPageEditorDialog",
272
+ props: {
273
+ modelValue: Boolean,
274
+ rollbackPageSource: Function,
275
+ getPageSource: {
276
+ type: Function,
277
+ required: true
278
+ },
279
+ savePageSource: {
280
+ type: Function,
281
+ required: true
282
+ }
283
+ },
284
+ emits: ["update:modelValue", "exit"],
285
+ setup(__props, { emit: __emit }) {
286
+ const props = __props;
287
+ const emit = __emit;
288
+ let prevBodyOverflow = "";
289
+ (0, vue.watch)(() => props.modelValue, (open) => {
290
+ if (open) {
291
+ prevBodyOverflow = document.body.style.overflow;
292
+ document.body.style.overflow = "hidden";
293
+ } else document.body.style.overflow = prevBodyOverflow;
294
+ });
295
+ (0, vue.onUnmounted)(() => {
296
+ document.body.style.overflow = prevBodyOverflow;
297
+ });
298
+ function handleEditorExit() {
299
+ emit("update:modelValue", false);
300
+ emit("exit");
301
+ }
302
+ return (_ctx, _cache) => {
303
+ return (0, vue.openBlock)(), (0, vue.createElementBlock)(vue.Fragment, null, [(0, vue.createCommentVNode)(" 自绘全屏层:不依赖 element-plus 样式(宿主常未引入) "), ((0, vue.openBlock)(), (0, vue.createBlock)(vue.Teleport, { to: "body" }, [__props.modelValue ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("div", _hoisted_1$2, [(0, vue.createVNode)(XuiPageEditor_default, {
304
+ savePageSource: __props.savePageSource,
305
+ rollbackPageSource: __props.rollbackPageSource,
306
+ getPageSource: __props.getPageSource,
307
+ onExit: handleEditorExit
308
+ }, null, 8, [
309
+ "savePageSource",
310
+ "rollbackPageSource",
311
+ "getPageSource"
312
+ ])])) : (0, vue.createCommentVNode)("v-if", true)]))], 2112);
313
+ };
314
+ }
315
+ });
316
+ //#endregion
317
+ //#region src/editor/XuiLoading.vue
318
+ const _sfc_main = {};
319
+ const _hoisted_1$1 = {
320
+ class: "app-loading",
321
+ role: "status",
322
+ "aria-live": "polite",
323
+ "aria-label": "Loading"
324
+ };
325
+ function _sfc_render$2(_ctx, _cache) {
326
+ return (0, vue.openBlock)(), (0, vue.createElementBlock)("div", _hoisted_1$1, [..._cache[0] || (_cache[0] = [(0, vue.createElementVNode)("div", { class: "app-loading-spinner" }, null, -1)])]);
327
+ }
328
+ var XuiLoading_default = /*#__PURE__*/ _plugin_vue_export_helper_default(_sfc_main, [["render", _sfc_render$2], ["__scopeId", "data-v-a382f6ec"]]);
329
+ //#endregion
330
+ //#region src/runtime/env.ts
331
+ function createEnv(page) {
332
+ const { debug } = (0, _kdesigner_core.useDebug)();
333
+ const adapter = (0, _kdesigner_core.useAdapter)();
334
+ const env = {
335
+ session: page.id,
336
+ affixOffsetTop: 0,
337
+ fetcher(options) {
338
+ (0, _kdesigner_core.providePage)(page);
339
+ options._page = page;
340
+ return (0, _kdesigner_core.ajaxFetch)(options);
341
+ },
342
+ jumpTo(to, _action, _ctx) {
343
+ const router = adapter.useRouter();
344
+ return (0, _kdesigner_core.default_jumpTo)(router, to);
345
+ },
346
+ isCancel: _kdesigner_core.isCancel,
347
+ isCurrentUrl: _kdesigner_core.default_isCurrentUrl,
348
+ updateLocation(to, replace) {
349
+ (0, _kdesigner_core.default_updateLocation)(to, !!replace);
350
+ },
351
+ notify: adapter.notify,
352
+ enableAMISDebug: debug.value,
353
+ alert: adapter.alert,
354
+ confirm: adapter.confirm,
355
+ copy: (contents, options) => {
356
+ if (options === void 0) options = {};
357
+ const { t } = adapter.useI18n();
358
+ const ret = (0, copy_to_clipboard.default)(contents, options);
359
+ if (ret && (!options || options.shutup !== true)) amis.toast.info(t("Copy To Clipboard"));
360
+ return ret;
361
+ }
362
+ };
363
+ env._page = page;
364
+ page.env = env;
365
+ return env;
366
+ }
367
+ //#endregion
368
+ //#region src/runtime/react-adapter.ts
369
+ function defineReactPageComponent(builder) {
370
+ return (0, vue.defineComponent)({
371
+ props: {
372
+ schema: Object,
373
+ data: Object,
374
+ registerPage: Function,
375
+ actions: Object
376
+ },
377
+ setup(props) {
378
+ const domRef = (0, vue.ref)();
379
+ let root;
380
+ const options = builder({ actions: props.actions });
381
+ const page = (0, _kdesigner_core.createPage)(options);
382
+ props.registerPage?.(page);
383
+ function destroyPage() {
384
+ if (root) {
385
+ root.unmount();
386
+ options.onDestroyPage?.(page);
387
+ root = void 0;
388
+ }
389
+ }
390
+ function renderPage() {
391
+ const schema = (0, _kdesigner_shared.deepClone)(props.schema);
392
+ root = (0, react_dom_client.createRoot)(domRef.value);
393
+ const r = root;
394
+ Promise.resolve(options.onRenderPage(schema, props.data, page)).then((v) => r.render(v));
395
+ }
396
+ (0, vue.watchEffect)(() => {
397
+ destroyPage();
398
+ if (props.schema && domRef.value) renderPage();
399
+ });
400
+ (0, vue.onBeforeUnmount)(() => {
401
+ destroyPage();
402
+ return { domRef };
403
+ });
404
+ return () => (0, vue.h)("div", {
405
+ ref: domRef,
406
+ style: {
407
+ width: "100%",
408
+ height: "100%"
409
+ },
410
+ class: "nop-page"
411
+ });
412
+ }
413
+ });
414
+ }
415
+ //#endregion
416
+ //#region src/page/AmisSchemaPage.ts
417
+ var AmisSchemaPage_default = defineReactPageComponent((props) => {
418
+ let amisScoped;
419
+ const route = (0, vue_router.useRoute)();
420
+ return {
421
+ actions: props.actions,
422
+ getComponent(name) {
423
+ return get_component(name);
424
+ },
425
+ getScopedStore(name) {
426
+ return get_component(name)?.props?.store;
427
+ },
428
+ getState(name) {
429
+ return get_root_store().get(name);
430
+ },
431
+ setState(name, value) {
432
+ get_root_store().set(name, value);
433
+ },
434
+ onDestroyPage(page) {
435
+ (0, amis.clearStoresCache)(page.id);
436
+ },
437
+ async onRenderPage(schema, data, page) {
438
+ const env = createEnv(page);
439
+ const locale = (0, _kdesigner_core.useAdapter)().useLocale();
440
+ let globalScopeData = {};
441
+ try {
442
+ globalScopeData = await _kdesigner_core.UserApis.LoginApi__getLoginUserInfo();
443
+ } catch (e) {
444
+ console.error(e);
445
+ }
446
+ const opts = {
447
+ data: {
448
+ ...data,
449
+ globalScopeData,
450
+ route: {
451
+ meta: route.meta,
452
+ path: route.path,
453
+ name: route.name,
454
+ query: route.query,
455
+ params: route.params,
456
+ fullPath: route.fullPath,
457
+ hash: route.hash
458
+ }
459
+ },
460
+ onConfirm: page.getAction("ok") || function() {},
461
+ onClose: function(b) {
462
+ if (b) page.getAction("ok")?.();
463
+ else page.getAction("cancel")?.();
464
+ },
465
+ scopeRef: (scoped) => {
466
+ amisScoped = scoped;
467
+ },
468
+ locale,
469
+ theme: "cxd"
470
+ };
471
+ (0, amis.setDefaultLocale)(locale);
472
+ schema = await (0, _kdesigner_core.transformPageJson)(schema.__baseUrl, schema);
473
+ await (0, _kdesigner_core.bindActions)(schema.__baseUrl, schema, page);
474
+ return (0, amis.render)(schema, opts, env);
475
+ }
476
+ };
477
+ function get_root() {
478
+ return amisScoped?.getComponents()[0];
479
+ }
480
+ function get_root_store() {
481
+ return get_root()?.context.store;
482
+ }
483
+ function get_component(name) {
484
+ if (name[0] == "#") {
485
+ const pos = name.indexOf(".");
486
+ if (pos < 0) return get_root()?.context.getComponentById(name.substring(1));
487
+ else return get_root()?.context.getComponentById(name.substring(1)).getComponentByName(name.substring(pos + 1));
488
+ } else return get_root()?.context.getComponentByName(name);
489
+ }
490
+ });
491
+ //#endregion
492
+ //#region src/page/XuiSchemaPage.vue?vue&type=script&lang.ts
493
+ /**
494
+ * 嵌入到vue中的amis页面。每个AmisSchemaPage都对应一个ReactRooot。schema发生变化时会重新创建react组件
495
+ */
496
+ var XuiSchemaPage_vue_vue_type_script_lang_default = (0, vue.defineComponent)({
497
+ props: {
498
+ schema: Object,
499
+ data: Object,
500
+ registerPage: Function,
501
+ actions: Object
502
+ },
503
+ setup(props) {
504
+ const { useI18n } = (0, _kdesigner_core.useAdapter)();
505
+ let componentType = (0, vue.ref)((0, vue.markRaw)(AmisSchemaPage_default));
506
+ (0, vue.watchEffect)(() => {
507
+ const schemaTypeName = props.schema?.["xui:schema-type"];
508
+ if (!schemaTypeName) componentType.value = (0, vue.markRaw)(AmisSchemaPage_default);
509
+ else {
510
+ const schemaType = (0, _kdesigner_core.getSchemaProcessorType)(schemaTypeName);
511
+ if (!schemaType) {
512
+ const { t } = useI18n();
513
+ (0, _kdesigner_core.useAdapter)().notify("error", t("nop.err.unknown-schema-type"));
514
+ throw new Error("nop.err.unknown-schema-type");
515
+ }
516
+ componentType.value = (0, vue.markRaw)(schemaType.componentType);
517
+ }
518
+ });
519
+ return { componentType };
520
+ }
521
+ });
522
+ //#endregion
523
+ //#region src/page/XuiSchemaPage.vue
524
+ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
525
+ return (0, vue.openBlock)(), (0, vue.createBlock)((0, vue.resolveDynamicComponent)(_ctx.componentType), (0, vue.normalizeProps)((0, vue.guardReactiveProps)(_ctx.$props)), null, 16);
526
+ }
527
+ var XuiSchemaPage_default = /*#__PURE__*/ _plugin_vue_export_helper_default(XuiSchemaPage_vue_vue_type_script_lang_default, [["render", _sfc_render$1]]);
528
+ //#endregion
529
+ //#region src/debug/debugger.ts
530
+ var debugger_default = {
531
+ type: "page",
532
+ "xui:schema": "amis",
533
+ body: {
534
+ type: "form",
535
+ title: null,
536
+ actions: [
537
+ {
538
+ label: "Cancel",
539
+ type: "action",
540
+ actionType: "ajax",
541
+ level: "default",
542
+ api: {
543
+ url: "action://cancel",
544
+ messages: { success: "_" }
545
+ }
546
+ },
547
+ {
548
+ label: "Apply",
549
+ type: "action",
550
+ actionType: "ajax",
551
+ level: "success",
552
+ api: "action://change"
553
+ },
554
+ {
555
+ label: "Yaml/JSON",
556
+ type: "action",
557
+ actionType: "ajax",
558
+ level: "primary",
559
+ api: "action://toggleYaml"
560
+ },
561
+ {
562
+ label: "Submit",
563
+ type: "action",
564
+ actionType: "ajax",
565
+ level: "primary",
566
+ api: "action://ok"
567
+ }
568
+ ],
569
+ body: [{
570
+ type: "editor",
571
+ name: "schema",
572
+ placeholder: "{}",
573
+ visibleOn: "this.lang !='yaml'"
574
+ }, {
575
+ type: "yaml-editor",
576
+ name: "schema",
577
+ placeholder: {},
578
+ visibleOn: "this.lang == 'yaml'"
579
+ }]
580
+ }
581
+ };
582
+ //#endregion
583
+ //#region src/debug/XuiDebugger.vue?vue&type=script&setup=true&lang.ts
584
+ const _hoisted_1 = { class: "schema-modal-panel" };
585
+ const _hoisted_2 = { class: "schema-modal-body" };
586
+ const POSITION_KEY = "kdesigner:xui-debugger-pos";
587
+ //#endregion
588
+ //#region src/debug/XuiDebugger.vue
589
+ var XuiDebugger_default = /* @__PURE__ */ (0, vue.defineComponent)({
590
+ __name: "XuiDebugger",
591
+ props: {
592
+ path: {
593
+ type: String,
594
+ required: true
595
+ },
596
+ schema: Object
597
+ },
598
+ emits: ["update:schema", "rebuild"],
599
+ setup(__props, { emit: __emit }) {
600
+ const props = __props;
601
+ const emit = __emit;
602
+ const schemaVisible = (0, vue.ref)(false);
603
+ const designerVisible = (0, vue.ref)(false);
604
+ const dragging = (0, vue.ref)(false);
605
+ const pos = (0, vue.ref)(null);
606
+ let prevBodyOverflow = "";
607
+ const positionStyle = (0, vue.computed)(() => {
608
+ if (!pos.value) return void 0;
609
+ return {
610
+ left: `${pos.value.left}px`,
611
+ top: `${pos.value.top}px`,
612
+ right: "auto"
613
+ };
614
+ });
615
+ (0, vue.onMounted)(() => {
616
+ try {
617
+ const raw = sessionStorage.getItem(POSITION_KEY);
618
+ if (!raw) return;
619
+ const parsed = JSON.parse(raw);
620
+ if (Number.isFinite(parsed.left) && Number.isFinite(parsed.top)) pos.value = clampPos(parsed.left, parsed.top);
621
+ } catch {}
622
+ });
623
+ (0, vue.onUnmounted)(() => {
624
+ restoreBodyScroll();
625
+ });
626
+ (0, vue.watch)(schemaVisible, (open) => {
627
+ if (open) lockBodyScroll();
628
+ else restoreBodyScroll();
629
+ });
630
+ function lockBodyScroll() {
631
+ prevBodyOverflow = document.body.style.overflow;
632
+ document.body.style.overflow = "hidden";
633
+ }
634
+ function restoreBodyScroll() {
635
+ document.body.style.overflow = prevBodyOverflow;
636
+ }
637
+ function clampPos(left, top) {
638
+ const maxLeft = Math.max(8, window.innerWidth - 100);
639
+ const maxTop = Math.max(8, window.innerHeight - 48);
640
+ return {
641
+ left: Math.min(Math.max(8, left), maxLeft),
642
+ top: Math.min(Math.max(8, top), maxTop)
643
+ };
644
+ }
645
+ /** 仅手柄可拖;S/V 保持正常 click,避免 pointer capture 吞事件 */
646
+ function onPointerDown(e) {
647
+ if (e.button !== 0 && e.pointerType === "mouse") return;
648
+ e.preventDefault();
649
+ const handle = e.currentTarget;
650
+ const panel = handle.closest(".page-debugger");
651
+ if (!panel) return;
652
+ const rect = panel.getBoundingClientRect();
653
+ const startX = e.clientX;
654
+ const startY = e.clientY;
655
+ const originLeft = rect.left;
656
+ const originTop = rect.top;
657
+ dragging.value = true;
658
+ handle.setPointerCapture(e.pointerId);
659
+ const onMove = (ev) => {
660
+ pos.value = clampPos(originLeft + (ev.clientX - startX), originTop + (ev.clientY - startY));
661
+ };
662
+ const onUp = (ev) => {
663
+ dragging.value = false;
664
+ handle.releasePointerCapture(ev.pointerId);
665
+ handle.removeEventListener("pointermove", onMove);
666
+ handle.removeEventListener("pointerup", onUp);
667
+ handle.removeEventListener("pointercancel", onUp);
668
+ if (pos.value) try {
669
+ sessionStorage.setItem(POSITION_KEY, JSON.stringify(pos.value));
670
+ } catch {}
671
+ };
672
+ handle.addEventListener("pointermove", onMove);
673
+ handle.addEventListener("pointerup", onUp);
674
+ handle.addEventListener("pointercancel", onUp);
675
+ }
676
+ const schemaData = (0, vue.shallowRef)({
677
+ schema: "",
678
+ lang: "json"
679
+ });
680
+ const { PageProvider__getPageSource, PageProvider__rollbackPageSource, PageProvider__savePageSource } = _kdesigner_core.PageApis;
681
+ function getPageSource(silent) {
682
+ return PageProvider__getPageSource(props.path, silent);
683
+ }
684
+ function savePageSource(data) {
685
+ (0, _kdesigner_core.deletePageCache)(props.path);
686
+ PageProvider__savePageSource(props.path, data, true);
687
+ }
688
+ function rollbackPageSource() {
689
+ PageProvider__rollbackPageSource(props.path, true);
690
+ }
691
+ function openSchemaEditor() {
692
+ schemaData.value = {
693
+ schema: js_yaml.default.dump(props.schema),
694
+ lang: "yaml"
695
+ };
696
+ schemaVisible.value = true;
697
+ }
698
+ const schemaActions = {
699
+ ok: handleOk,
700
+ cancel: handleCancel,
701
+ change: handleChange,
702
+ rebuild: handleRebuild,
703
+ toggleYaml: handleToggleYaml
704
+ };
705
+ function handleChange(options) {
706
+ const data = options.data;
707
+ let json = schemaData.value.lang == "yaml" ? js_yaml.default.load(data.schema) : JSON.parse(data.schema);
708
+ emit("update:schema", json);
709
+ }
710
+ function handleOk(data) {
711
+ handleChange(data);
712
+ schemaVisible.value = false;
713
+ }
714
+ function handleCancel() {
715
+ schemaVisible.value = false;
716
+ }
717
+ function handleRebuild() {
718
+ emit("rebuild");
719
+ }
720
+ function handleToggleYaml(options) {
721
+ let schema = options.data.schema;
722
+ if (options.data.lang == "yaml") schemaData.value = {
723
+ lang: "json",
724
+ schema: JSON.stringify(js_yaml.default.load(schema), null, " ")
725
+ };
726
+ else schemaData.value = {
727
+ lang: "yaml",
728
+ schema: js_yaml.default.dump(JSON.parse(schema))
729
+ };
730
+ }
731
+ function openXuiPageEditor() {
732
+ designerVisible.value = true;
733
+ }
734
+ return (_ctx, _cache) => {
735
+ return (0, vue.openBlock)(), (0, vue.createElementBlock)(vue.Fragment, null, [
736
+ (0, vue.createElementVNode)("span", {
737
+ class: (0, vue.normalizeClass)(["page-debugger", { "is-dragging": dragging.value }]),
738
+ style: (0, vue.normalizeStyle)(positionStyle.value)
739
+ }, [
740
+ (0, vue.createElementVNode)("button", {
741
+ type: "button",
742
+ class: "debug-handle",
743
+ title: "拖动",
744
+ "aria-label": "拖动调试工具",
745
+ onPointerdown: onPointerDown
746
+ }, " ⋮⋮ ", 32),
747
+ (0, vue.createElementVNode)("button", {
748
+ type: "button",
749
+ class: "debug-btn",
750
+ title: "Schema Json Editor",
751
+ onClick: openSchemaEditor
752
+ }, " S "),
753
+ __props.path ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("button", {
754
+ key: 0,
755
+ type: "button",
756
+ class: "debug-btn",
757
+ title: "Page Visual Designer",
758
+ onClick: openXuiPageEditor
759
+ }, " V ")) : (0, vue.createCommentVNode)("v-if", true)
760
+ ], 6),
761
+ (0, vue.createCommentVNode)(" 自绘浮层:宿主未必引入 element-plus 样式,el-dialog 会掉进文档流撑高页面 "),
762
+ ((0, vue.openBlock)(), (0, vue.createBlock)(vue.Teleport, { to: "body" }, [schemaVisible.value ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("div", {
763
+ key: 0,
764
+ class: "schema-modal-root",
765
+ role: "dialog",
766
+ "aria-modal": "true",
767
+ "aria-label": "Page Schema",
768
+ onKeydown: (0, vue.withKeys)(handleCancel, ["esc"])
769
+ }, [(0, vue.createElementVNode)("div", {
770
+ class: "schema-modal-mask",
771
+ onClick: handleCancel
772
+ }), (0, vue.createElementVNode)("div", _hoisted_1, [(0, vue.createElementVNode)("header", { class: "schema-modal-header" }, [_cache[1] || (_cache[1] = (0, vue.createElementVNode)("h2", { class: "schema-modal-title" }, "Page Schema", -1)), (0, vue.createElementVNode)("button", {
773
+ type: "button",
774
+ class: "schema-modal-close",
775
+ "aria-label": "关闭",
776
+ onClick: handleCancel
777
+ }, " × ")]), (0, vue.createElementVNode)("div", _hoisted_2, [(0, vue.createVNode)((0, vue.unref)(AmisSchemaPage_default), {
778
+ schema: (0, vue.unref)(debugger_default),
779
+ actions: schemaActions,
780
+ data: schemaData.value
781
+ }, null, 8, ["schema", "data"])])])], 32)) : (0, vue.createCommentVNode)("v-if", true)])),
782
+ (0, vue.createVNode)(XuiPageEditorDialog_default, {
783
+ modelValue: designerVisible.value,
784
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => designerVisible.value = $event),
785
+ savePageSource,
786
+ rollbackPageSource,
787
+ getPageSource
788
+ }, null, 8, ["modelValue"])
789
+ ], 64);
790
+ };
791
+ }
792
+ });
793
+ //#endregion
794
+ //#region src/page/XuiPage.vue?vue&type=script&lang.ts
795
+ /**
796
+ * 在AmisSchemaPage的基础上增加AmisDebugger调试功能,以及根据path动态加载schema的功能
797
+ */
798
+ var XuiPage_vue_vue_type_script_lang_default = (0, vue.defineComponent)({
799
+ name: "amis-page",
800
+ props: {
801
+ path: {
802
+ type: String,
803
+ required: true
804
+ },
805
+ data: Object,
806
+ config: Object,
807
+ registerPage: Function,
808
+ actions: Object
809
+ },
810
+ components: {
811
+ XuiDebugger: XuiDebugger_default,
812
+ XuiSchemaPage: XuiSchemaPage_default
813
+ },
814
+ setup(props) {
815
+ const { getPage } = (0, _kdesigner_core.useAdapter)();
816
+ let pageSchema = (0, vue.shallowRef)();
817
+ function registerPage(p) {
818
+ props.registerPage?.(p);
819
+ }
820
+ (0, vue.watchEffect)(() => {
821
+ getPage(props.path).then((res) => {
822
+ res.__baseUrl = props.path;
823
+ updateSchema(res);
824
+ });
825
+ });
826
+ function updateSchema(value) {
827
+ pageSchema.value = value;
828
+ }
829
+ function rebuild() {
830
+ pageSchema.value = (0, _kdesigner_shared.deepClone)(pageSchema.value);
831
+ }
832
+ const { debug } = (0, _kdesigner_core.useDebug)();
833
+ return {
834
+ pageSchema,
835
+ updateSchema,
836
+ rebuild,
837
+ registerPage,
838
+ debug,
839
+ actions: { ...props.actions },
840
+ data: props.data
841
+ };
842
+ }
843
+ });
844
+ //#endregion
845
+ //#region src/page/XuiPage.vue
846
+ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
847
+ const _component_xui_debugger = (0, vue.resolveComponent)("xui-debugger");
848
+ const _component_XuiSchemaPage = (0, vue.resolveComponent)("XuiSchemaPage");
849
+ return (0, vue.openBlock)(), (0, vue.createElementBlock)(vue.Fragment, null, [_ctx.debug ? ((0, vue.openBlock)(), (0, vue.createBlock)(_component_xui_debugger, {
850
+ key: 0,
851
+ path: _ctx.path,
852
+ schema: _ctx.pageSchema,
853
+ "onUpdate:schema": _ctx.updateSchema,
854
+ onRebuild: _ctx.rebuild
855
+ }, null, 8, [
856
+ "path",
857
+ "schema",
858
+ "onUpdate:schema",
859
+ "onRebuild"
860
+ ])) : (0, vue.createCommentVNode)("v-if", true), (0, vue.createVNode)(_component_XuiSchemaPage, {
861
+ schema: _ctx.pageSchema,
862
+ registerPage: _ctx.registerPage,
863
+ action: _ctx.actions,
864
+ data: _ctx.data
865
+ }, null, 8, [
866
+ "schema",
867
+ "registerPage",
868
+ "action",
869
+ "data"
870
+ ])], 64);
871
+ }
872
+ var XuiPage_default = /*#__PURE__*/ _plugin_vue_export_helper_default(XuiPage_vue_vue_type_script_lang_default, [["render", _sfc_render]]);
873
+ //#endregion
874
+ //#region src/toast/AmisToast.vue
875
+ var AmisToast_default = /* @__PURE__ */ (0, vue.defineComponent)({
876
+ __name: "AmisToast",
877
+ setup(__props) {
878
+ const domRef = (0, vue.ref)();
879
+ let root;
880
+ (0, vue.onMounted)(() => {
881
+ root = (0, react_dom_client.createRoot)(domRef.value);
882
+ root.render((0, react.createElement)(react.Fragment, {}, (0, react.createElement)(amis.ToastComponent, { position: "top-right" })));
883
+ });
884
+ (0, vue.onBeforeUnmount)(() => {
885
+ if (root) {
886
+ root.unmount();
887
+ root = void 0;
888
+ }
889
+ });
890
+ return (_ctx, _cache) => {
891
+ return (0, vue.openBlock)(), (0, vue.createElementBlock)("div", {
892
+ ref_key: "domRef",
893
+ ref: domRef
894
+ }, null, 512);
895
+ };
896
+ }
897
+ });
898
+ //#endregion
899
+ //#region src/runtime/AmisVueComponent.ts
900
+ var VueControl = class extends react.default.Component {
901
+ constructor(props) {
902
+ super(props);
903
+ const { resolveVueComponent } = (0, _kdesigner_core.useAdapter)();
904
+ const name = props.vueComponent || props.componentName;
905
+ const resolved = typeof name === "string" && name ? resolveVueComponent(name) : name;
906
+ if (!resolved) {
907
+ this.missingComponentName = String(name || "unknown");
908
+ this.vueComponent = null;
909
+ console.error(`[amis-vue] Vue component not registered: ${this.missingComponentName}`);
910
+ return;
911
+ }
912
+ this.vueComponent = (0, veaury.applyPureVueInReact)(resolved);
913
+ }
914
+ doAction(action, _data, _throwErrors) {
915
+ const { resetValue, onChange } = this.props;
916
+ const actionType = action?.actionType;
917
+ if (actionType === "clear") onChange(void 0);
918
+ else if (actionType === "reset") onChange(resetValue);
919
+ }
920
+ async dispatchChangeEvent(eventData = {}) {
921
+ const { dispatchEvent, data, onChange } = this.props;
922
+ if ((await dispatchEvent("change", (0, amis_core.createObject)(data, { value: eventData })))?.prevented) return;
923
+ onChange?.(eventData);
924
+ }
925
+ render() {
926
+ if (!this.vueComponent) return react.default.createElement("div", {
927
+ className: "cxd-Form-label",
928
+ style: {
929
+ color: "var(--colors-error-5, #ff4d4f)",
930
+ padding: "4px 0"
931
+ }
932
+ }, `Vue 组件未注册: ${this.missingComponentName}`);
933
+ let { props, value, env, store } = this.props;
934
+ if (props) {
935
+ props = { ...props };
936
+ for (const key of Object.keys(props)) if (typeof props[key] === "string") props[key] = (0, amis_core.resolveVariableAndFilter)(props[key], this.props.data, "| raw");
937
+ }
938
+ const mergedProps = {
939
+ env,
940
+ store,
941
+ ...props,
942
+ value,
943
+ "onUpdate:value": (value) => this.dispatchChangeEvent(value)
944
+ };
945
+ return react.default.createElement(this.vueComponent, mergedProps);
946
+ }
947
+ };
948
+ var VueRenderer = class extends VueControl {
949
+ constructor(props) {
950
+ super(props);
951
+ const scoped = this.context;
952
+ if (scoped) scoped.registerComponent(this);
953
+ }
954
+ componentWillUnmount() {
955
+ const scoped = this.context;
956
+ if (scoped) scoped.unRegisterComponent(this);
957
+ }
958
+ };
959
+ VueRenderer.contextType = amis.ScopedContext;
960
+ (0, amis.Renderer)({
961
+ type: "vue-renderer",
962
+ autoVar: false
963
+ })(VueRenderer);
964
+ var VueFormItem = class extends VueControl {};
965
+ (0, amis.FormItem)({
966
+ type: "vue-form-item",
967
+ autoVar: false
968
+ })(VueFormItem);
969
+ //#endregion
970
+ //#region src/lib.ts
971
+ var lib_exports = /* @__PURE__ */ __exportAll({
972
+ AmisPageEditor: () => AmisPageEditor_default,
973
+ AmisSchemaPage: () => AmisSchemaPage_default,
974
+ AmisToast: () => AmisToast_default,
975
+ AmisVueComponent: () => VueControl,
976
+ XuiLoading: () => XuiLoading_default,
977
+ XuiPage: () => XuiPage_default,
978
+ XuiPageEditor: () => XuiPageEditor_default,
979
+ XuiSchemaPage: () => XuiSchemaPage_default,
980
+ createEnv: () => createEnv,
981
+ defineReactPageComponent: () => defineReactPageComponent
982
+ });
983
+ __reExport(lib_exports, require("@kdesigner/core"));
984
+ __reExport(lib_exports, require("@kdesigner/components"));
985
+ __reExport(lib_exports, require("@kdesigner/amis-extensions"));
986
+ __reExport(/* @__PURE__ */ __exportAll({
987
+ AmisPageEditor: () => AmisPageEditor_default,
988
+ AmisSchemaPage: () => AmisSchemaPage_default,
989
+ AmisToast: () => AmisToast_default,
990
+ AmisVueComponent: () => VueControl,
991
+ XuiLoading: () => XuiLoading_default,
992
+ XuiPage: () => XuiPage_default,
993
+ XuiPageEditor: () => XuiPageEditor_default,
994
+ XuiSchemaPage: () => XuiSchemaPage_default,
995
+ createEnv: () => createEnv,
996
+ defineReactPageComponent: () => defineReactPageComponent
997
+ }), lib_exports);
998
+ lib_exports.registerModule?.("@kdesigner/amis-vue", lib_exports);
999
+ //#endregion
1000
+ exports.AmisPageEditor = AmisPageEditor_default;
1001
+ exports.AmisSchemaPage = AmisSchemaPage_default;
1002
+ exports.AmisToast = AmisToast_default;
1003
+ exports.AmisVueComponent = VueControl;
1004
+ exports.XuiLoading = XuiLoading_default;
1005
+ exports.XuiPage = XuiPage_default;
1006
+ exports.XuiPageEditor = XuiPageEditor_default;
1007
+ exports.XuiSchemaPage = XuiSchemaPage_default;
1008
+ exports.createEnv = createEnv;
1009
+ exports.defineReactPageComponent = defineReactPageComponent;
1010
+ Object.keys(_kdesigner_core).forEach(function(k) {
1011
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
1012
+ enumerable: true,
1013
+ get: function() {
1014
+ return _kdesigner_core[k];
1015
+ }
1016
+ });
1017
+ });
1018
+ var _kdesigner_components = require("@kdesigner/components");
1019
+ Object.keys(_kdesigner_components).forEach(function(k) {
1020
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
1021
+ enumerable: true,
1022
+ get: function() {
1023
+ return _kdesigner_components[k];
1024
+ }
1025
+ });
1026
+ });
1027
+ var _kdesigner_amis_extensions = require("@kdesigner/amis-extensions");
1028
+ Object.keys(_kdesigner_amis_extensions).forEach(function(k) {
1029
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
1030
+ enumerable: true,
1031
+ get: function() {
1032
+ return _kdesigner_amis_extensions[k];
1033
+ }
1034
+ });
1035
+ });
1036
+
1037
+ //# sourceMappingURL=index.cjs.map