@veltra/desktop 1.7.17 → 1.7.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/batch-edit/batch-edit-form.js +6 -1
- package/dist/components/batch-edit/batch-edit-form.js.map +1 -1
- package/dist/components/batch-edit/batch-edit-list.js +45 -27
- package/dist/components/batch-edit/batch-edit-list.js.map +1 -1
- package/dist/components/batch-edit/batch-edit.js +2 -2
- package/dist/components/batch-edit/batch-edit.js.map +1 -1
- package/dist/components/batch-edit/di.js.map +1 -1
- package/dist/components/batch-edit/use-edit-state.js +14 -10
- package/dist/components/batch-edit/use-edit-state.js.map +1 -1
- package/dist/components/batch-edit/use-handlers.js +1 -0
- package/dist/components/batch-edit/use-handlers.js.map +1 -1
- package/dist/components/dialog/style2.css +1 -1
- package/dist/components/expression-editor/core/chip.js +1 -15
- package/dist/components/expression-editor/core/chip.js.map +1 -1
- package/dist/components/expression-editor/core/editor.js +0 -18
- package/dist/components/expression-editor/core/editor.js.map +1 -1
- package/dist/components/expression-editor/expression-editor.js +0 -4
- package/dist/components/expression-editor/expression-editor.js.map +1 -1
- package/dist/components/expression-editor/style2.css +0 -23
- package/dist/index.d.ts +2 -2
- package/dist/types/batch-edit.d.ts +0 -3
- package/dist/types/index.d.ts +2 -2
- package/package.json +1 -1
- package/src/components/batch-edit/__test__/batch-edit.test.ts +165 -38
- package/src/components/batch-edit/batch-edit-form.vue +7 -1
- package/src/components/batch-edit/batch-edit-list.vue +53 -22
- package/src/components/batch-edit/batch-edit.vue +2 -1
- package/src/components/batch-edit/di.ts +2 -0
- package/src/components/batch-edit/use-edit-state.ts +25 -32
- package/src/components/batch-edit/use-handlers.ts +2 -0
- package/src/components/dialog/style.scss +2 -1
- package/src/components/expression-editor/__test__/chip.test.ts +3 -14
- package/src/components/expression-editor/core/chip.ts +3 -29
- package/src/components/expression-editor/core/editor.ts +0 -21
- package/src/components/expression-editor/expression-editor.vue +0 -4
- package/src/components/expression-editor/style.scss +0 -29
- package/src/types/batch-edit.ts +0 -4
|
@@ -52,13 +52,18 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
52
52
|
return creatable.value || updatable.value || creatableChild.value;
|
|
53
53
|
});
|
|
54
54
|
const headerInfo = computed(() => FORM_ACTION_HEADER_MAP[state.formActionType]);
|
|
55
|
+
/** 头部图标色调修饰类:样式中 createChild 对应的修饰类为 is-child */
|
|
56
|
+
const iconToneCls = computed(() => {
|
|
57
|
+
const type = state.formActionType;
|
|
58
|
+
return bem.is(type === "createChild" ? "child" : type);
|
|
59
|
+
});
|
|
55
60
|
return (_ctx, _cache) => {
|
|
56
61
|
return openBlock(), createElementBlock(Fragment, null, [createCommentVNode(" 面板模式:表单常驻挂载(快照只在挂载时对传入的 model 拍一次),仅用 v-show 控制显隐;\n 弹框模式:表单随弹框挂载 / 卸载,model 初始快照由 use-edit-state 维护 "), !!unref(props).model ? withDirectives((openBlock(), createElementBlock("aside", {
|
|
57
62
|
key: 0,
|
|
58
63
|
class: normalizeClass([unref(cls).e("form"), unref(bem).is("dialog", unref(props).formMode === "dialog")])
|
|
59
64
|
}, [
|
|
60
65
|
createElementVNode("header", { class: normalizeClass(unref(cls).e("form-header")) }, [
|
|
61
|
-
createElementVNode("span", { class: normalizeClass([unref(cls).e("form-icon"),
|
|
66
|
+
createElementVNode("span", { class: normalizeClass([unref(cls).e("form-icon"), iconToneCls.value]) }, [createVNode(unref(_sfc_main$1), null, {
|
|
62
67
|
default: withCtx(() => [(openBlock(), createBlock(resolveDynamicComponent(headerInfo.value.icon)))]),
|
|
63
68
|
_: 1
|
|
64
69
|
})], 2),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-edit-form.js","names":[],"sources":["../../../src/components/batch-edit/batch-edit-form.vue"],"sourcesContent":["<template>\n <!-- 面板模式:表单常驻挂载(快照只在挂载时对传入的 model 拍一次),仅用 v-show 控制显隐;\n 弹框模式:表单随弹框挂载 / 卸载,model 初始快照由 use-edit-state 维护 -->\n <aside\n :class=\"[cls.e('form'), bem.is('dialog', props.formMode === 'dialog')]\"\n v-if=\"!!props.model\"\n v-show=\"state.formVisible\"\n >\n <header :class=\"cls.e('form-header')\">\n <span :class=\"[cls.e('form-icon'),
|
|
1
|
+
{"version":3,"file":"batch-edit-form.js","names":[],"sources":["../../../src/components/batch-edit/batch-edit-form.vue"],"sourcesContent":["<template>\n <!-- 面板模式:表单常驻挂载(快照只在挂载时对传入的 model 拍一次),仅用 v-show 控制显隐;\n 弹框模式:表单随弹框挂载 / 卸载,model 初始快照由 use-edit-state 维护 -->\n <aside\n :class=\"[cls.e('form'), bem.is('dialog', props.formMode === 'dialog')]\"\n v-if=\"!!props.model\"\n v-show=\"state.formVisible\"\n >\n <header :class=\"cls.e('form-header')\">\n <span :class=\"[cls.e('form-icon'), iconToneCls]\">\n <u-icon>\n <component :is=\"headerInfo.icon\" />\n </u-icon>\n </span>\n <div :class=\"cls.e('form-title')\">\n <h3 :class=\"cls.e('form-title-text')\">{{ headerInfo.title }}</h3>\n </div>\n <u-button\n :class=\"cls.e('form-close')\"\n :icon=\"Close\"\n text\n circle\n size=\"small\"\n title=\"关闭\"\n @click=\"handleClose\"\n />\n </header>\n\n <u-scroll always :class=\"cls.e('form-body')\">\n <transition name=\"fade\" appear mode=\"out-in\">\n <u-form\n ref=\"formComponentRef\"\n :model=\"props.model\"\n :readonly=\"props.readonly\"\n :label-width=\"props.labelWidth\"\n @field:update=\"handleFieldUpdate\"\n >\n <slot\n v-bind=\"{\n row: state.row,\n parentRow: state.parentRow,\n formActionType: state.formActionType,\n depth: state.depth,\n indexes: state.indexPath,\n index: state.row?.index\n }\"\n />\n </u-form>\n </transition>\n </u-scroll>\n\n <footer :class=\"cls.e('form-footer')\">\n <span :class=\"cls.e('form-hint')\">\n <template v-if=\"props.readonly\"> 只读模式 </template>\n\n <span :class=\"{ [bem.is('concealed')]: !shortcutActive }\">\n <template v-if=\"!(state.formActionType === 'update' && props.quickEdit)\">\n <u-kbd>Ctrl + S</u-kbd> 保存 ·\n </template>\n <u-kbd>Esc</u-kbd> 关闭\n </span>\n </span>\n\n <div :class=\"cls.e('form-actions')\">\n <u-button size=\"small\" text :loading=\"state.loading\" @click=\"handleClose\"> 取消 </u-button>\n <u-button\n v-if=\"showSaveBtn\"\n type=\"primary\"\n size=\"small\"\n title=\"保存\"\n :icon=\"Save\"\n :loading=\"state.loading\"\n @click=\"handleSave\"\n />\n </div>\n </footer>\n </aside>\n</template>\n\n<script lang=\"ts\" setup>\nimport { o } from '@cat-kit/core'\nimport { Close, Save } from '@veltra/icons/normal'\nimport { bem } from '@veltra/utils'\nimport { computed, inject, shallowRef, toRef } from 'vue'\n\nimport type { _FormExposed, FormExposed } from '../../types/form'\nimport { UButton } from '../button'\nimport { UForm } from '../form'\nimport { UIcon } from '../icon'\nimport { UKbd } from '../kbd'\nimport { UScroll } from '../scroll'\nimport { BatchEditDIKey } from './di'\nimport { FORM_ACTION_HEADER_MAP } from './form-action-header'\nimport { useDialogEffect } from './use-dialog-effect'\n\ndefineOptions({ name: 'UBatchEditForm' })\n\nconst batchEditCtx = inject(BatchEditDIKey)!\n\nconst { cls, props, state, handleClose, handleSave, staticFeatures, dynamicFeatures, syncing } =\n batchEditCtx\n\nconst focused = toRef(batchEditCtx, 'focused')\n\n// 弹框模式下,弹框自身关闭(遮罩点击 / 右上角关闭)时同步走 handleClose,不保存\nuseDialogEffect({ closeForm: handleClose })\n\n/** 快捷键提示是否可见:面板模式随聚焦显隐;弹框模式弹框打开期间快捷键始终可用 */\nconst shortcutActive = computed(() => {\n return props.formMode === 'dialog' ? state.formVisible : focused.value\n})\n\nconst formComponentRef = shallowRef<FormExposed>()\n\ndefineExpose<_FormExposed>({\n el: toRef(() => formComponentRef.value?.el),\n validate: () => formComponentRef.value?.validate() ?? Promise.resolve(true),\n clearValidate: () => formComponentRef.value?.clearValidate(),\n reset: () => formComponentRef.value?.reset()\n})\n\nfunction handleFieldUpdate(field: string, value: any) {\n // 编程方式重置/回显期间不写回行数据,避免默认值污染源数据\n if (syncing.value) return\n\n if (state.row && props.quickEdit) {\n o(state.row.data).set(field, value)\n }\n}\n\nconst creatable = computed(() => {\n if (state.formActionType !== 'create') return false\n return staticFeatures.value.has('create') || dynamicFeatures.value.create?.(state.row)\n})\n\nconst creatableChild = computed(() => {\n if (state.formActionType !== 'createChild') return false\n return (\n staticFeatures.value.has('createChild') || dynamicFeatures.value.createChild?.(state.parentRow)\n )\n})\n\nconst updatable = computed(() => {\n if (state.formActionType !== 'update') return false\n return staticFeatures.value.has('update') || dynamicFeatures.value.update?.(state.row)\n})\n\nconst showSaveBtn = computed(() => {\n if (props.readonly) return false\n if (props.quickEdit && state.formActionType === 'update') return false\n return creatable.value || updatable.value || creatableChild.value\n})\n\nconst headerInfo = computed(() => FORM_ACTION_HEADER_MAP[state.formActionType])\n\n/** 头部图标色调修饰类:样式中 createChild 对应的修饰类为 is-child */\nconst iconToneCls = computed(() => {\n const type = state.formActionType\n return bem.is(type === 'createChild' ? 'child' : type)\n})\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;EAiGA,MAAM,eAAe,OAAO,cAAc;EAE1C,MAAM,EAAE,KAAK,OAAO,OAAO,aAAa,YAAY,gBAAgB,iBAAiB,YACnF;EAEF,MAAM,UAAU,MAAM,cAAc,SAAS;EAG7C,gBAAgB,EAAE,WAAW,YAAY,CAAC;;EAG1C,MAAM,iBAAiB,eAAe;GACpC,OAAO,MAAM,aAAa,WAAW,MAAM,cAAc,QAAQ;EACnE,CAAC;EAED,MAAM,mBAAmB,WAAwB;EAEjD,SAA2B;GACzB,IAAI,YAAY,iBAAiB,OAAO,EAAE;GAC1C,gBAAgB,iBAAiB,OAAO,SAAS,KAAK,QAAQ,QAAQ,IAAI;GAC1E,qBAAqB,iBAAiB,OAAO,cAAc;GAC3D,aAAa,iBAAiB,OAAO,MAAM;EAC7C,CAAC;EAED,SAAS,kBAAkB,OAAe,OAAY;GAEpD,IAAI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CAAA,GAAA,mBAWM,OAAA,EAXA,OAAK,eAAE,MAAA,GAAA,CAAG,CAAC,EAAC,cAAA,CAAA,EAAA,GAChB,CAAA,YAAyF,MAAA,WAAA,GAAA;KAA/E,MAAK;KAAQ,MAAA;KAAM,SAAS,MAAA,KAAA,CAAK,CAAC;KAAU,SAAO,MAAA,WAAA;;KAAa,SAAA,cAAI,CAAA,GAAA,OAAA,OAAA,OAAA,KAAA,CAAJ,gBAAA,QAAI,EAAA,CAAA,EAAA,CAAA;;IAEtE,GAAA,GAAA,CAAA,WAAA,SAAA,CAAA,GAAA,YAAA,SADR,UAAA,GAAA,YAQE,MAAA,WAAA,GAAA;;KANA,MAAK;KACL,MAAK;KACL,OAAM;KACL,MAAM,MAAA,IAAA;KACN,SAAS,MAAA,KAAA,CAAK,CAAC;KACf,SAAO,MAAA,UAAA;;;;;;GAlEN,GAAA,CAAA,IAAA,CAAA,CAAA,OAAA,MAAA,KAAA,CAAK,CAAC,WAAW,CAAA,CAAA,IAAA,mBAAA,QAAA,IAAA,CAAA,GAAA,IAAA"}
|
|
@@ -4,7 +4,7 @@ import { BatchEditDIKey } from "./di.js";
|
|
|
4
4
|
import _sfc_main$3 from "../action/action.js";
|
|
5
5
|
import action_group_default from "../action/action-group.js";
|
|
6
6
|
import { computed, createBlock, createCommentVNode, createElementVNode, createSlots, createTextVNode, createVNode, defineComponent, inject, mergeProps, normalizeClass, openBlock, unref, withCtx, withModifiers } from "vue";
|
|
7
|
-
import { AddChild, Delete, InsertToNext, InsertToPrev, Plus } from "@veltra/icons/normal";
|
|
7
|
+
import { AddChild, Delete, EditPen, InsertToNext, InsertToPrev, Plus, View } from "@veltra/icons/normal";
|
|
8
8
|
import { o } from "@cat-kit/core";
|
|
9
9
|
//#region src/components/batch-edit/batch-edit-list.vue
|
|
10
10
|
const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
@@ -12,7 +12,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
12
12
|
__name: "batch-edit-list",
|
|
13
13
|
props: { slots: {} },
|
|
14
14
|
setup(__props) {
|
|
15
|
-
const { cls, state, props, emit, staticFeatures, dynamicFeatures, handleCreate, handleDelete, handleInsertToNext, handleInsertToPrev, handleInsertChild } = inject(BatchEditDIKey);
|
|
15
|
+
const { cls, state, props, emit, staticFeatures, dynamicFeatures, startEdit, handleClose, handleCreate, handleDelete, handleInsertToNext, handleInsertToPrev, handleInsertChild } = inject(BatchEditDIKey);
|
|
16
16
|
const tableProps = computed(() => {
|
|
17
17
|
return o(props).omit([
|
|
18
18
|
"model",
|
|
@@ -22,9 +22,11 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
22
22
|
"deleteMethod",
|
|
23
23
|
"saveMethod",
|
|
24
24
|
"features",
|
|
25
|
-
"mode",
|
|
26
25
|
"beforeCreate",
|
|
27
|
-
"formMode"
|
|
26
|
+
"formMode",
|
|
27
|
+
"quickEdit",
|
|
28
|
+
"labelWidth",
|
|
29
|
+
"actionsProps"
|
|
28
30
|
]);
|
|
29
31
|
});
|
|
30
32
|
const hasNot = (value) => value.every((v) => !staticFeatures.value.has(v));
|
|
@@ -32,12 +34,13 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
32
34
|
return staticFeatures.value.has(feature) || !!dynamicFeatures.value[feature]?.(row);
|
|
33
35
|
};
|
|
34
36
|
const columns = computed(() => {
|
|
35
|
-
|
|
37
|
+
const related = props.readonly ? ["update"] : [
|
|
36
38
|
"create",
|
|
37
39
|
"delete",
|
|
38
40
|
"createChild",
|
|
39
41
|
"update"
|
|
40
|
-
]
|
|
42
|
+
];
|
|
43
|
+
if (hasNot(related)) return props.columns;
|
|
41
44
|
return (props.columns ?? []).concat({
|
|
42
45
|
name: "操作",
|
|
43
46
|
key: "__action__",
|
|
@@ -47,12 +50,18 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
47
50
|
resizable: false
|
|
48
51
|
});
|
|
49
52
|
});
|
|
50
|
-
function handleUpdateCurrentRow(row) {
|
|
51
|
-
if (allowed("update", row)) state.row = row;
|
|
52
|
-
}
|
|
53
53
|
function canDelete(row) {
|
|
54
54
|
return !props.readonly && allowed("delete", row);
|
|
55
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* 点击行打开编辑/查看表单;再次点击当前行取消选中并关闭表单。
|
|
58
|
+
* update 特性关闭时点击行不响应
|
|
59
|
+
*/
|
|
60
|
+
function handleUpdateCurrentRow(row) {
|
|
61
|
+
if (!allowed("update", row)) return;
|
|
62
|
+
if (row) startEdit(row);
|
|
63
|
+
else handleClose();
|
|
64
|
+
}
|
|
56
65
|
const showCreateBtn = computed(() => {
|
|
57
66
|
if (props.readonly) return false;
|
|
58
67
|
const hasFeature = staticFeatures.value.has("create") || dynamicFeatures.value.create?.();
|
|
@@ -71,40 +80,49 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
71
80
|
"onUpdate:selected": _cache[2] || (_cache[2] = ($event) => unref(emit)("update:selected", $event))
|
|
72
81
|
}), createSlots({
|
|
73
82
|
"column:__action__": withCtx(({ row }) => [createVNode(unref(action_group_default), {
|
|
74
|
-
class: normalizeClass(unref(cls).e("row-actions")),
|
|
75
83
|
max: 5,
|
|
76
|
-
|
|
77
|
-
|
|
84
|
+
circle: "",
|
|
85
|
+
onClick: _cache[0] || (_cache[0] = withModifiers(() => {}, ["stop"]))
|
|
78
86
|
}, {
|
|
79
87
|
default: withCtx(() => [
|
|
80
|
-
allowed("
|
|
88
|
+
allowed("update", row) ? (openBlock(), createBlock(unref(_sfc_main$3), mergeProps({
|
|
81
89
|
key: 0,
|
|
82
|
-
icon: unref(
|
|
83
|
-
title: "
|
|
84
|
-
onRun: ($event) => unref(
|
|
85
|
-
}, null,
|
|
86
|
-
|
|
90
|
+
icon: unref(props).readonly ? unref(View) : unref(EditPen),
|
|
91
|
+
title: unref(props).readonly ? "查看" : "编辑",
|
|
92
|
+
onRun: ($event) => unref(startEdit)(row)
|
|
93
|
+
}, unref(props).actionsProps?.update), null, 16, [
|
|
94
|
+
"icon",
|
|
95
|
+
"title",
|
|
96
|
+
"onRun"
|
|
97
|
+
])) : createCommentVNode("v-if", true),
|
|
98
|
+
!unref(props).readonly && !!unref(props).tree && allowed("createChild", row) ? (openBlock(), createBlock(unref(_sfc_main$3), {
|
|
87
99
|
key: 1,
|
|
88
|
-
icon: unref(InsertToNext),
|
|
89
|
-
title: "在下方插入",
|
|
90
|
-
onRun: ($event) => unref(handleInsertToNext)(row)
|
|
91
|
-
}, null, 8, ["icon", "onRun"])) : createCommentVNode("v-if", true),
|
|
92
|
-
!!unref(props).tree && allowed("createChild", row) ? (openBlock(), createBlock(unref(_sfc_main$3), {
|
|
93
|
-
key: 2,
|
|
94
100
|
icon: unref(AddChild),
|
|
95
101
|
title: "添加子级",
|
|
96
102
|
onRun: ($event) => unref(handleInsertChild)(row)
|
|
97
103
|
}, null, 8, ["icon", "onRun"])) : createCommentVNode("v-if", true),
|
|
98
104
|
canDelete(row) ? (openBlock(), createBlock(unref(_sfc_main$3), mergeProps({
|
|
99
|
-
key:
|
|
105
|
+
key: 2,
|
|
100
106
|
icon: unref(Delete),
|
|
101
107
|
type: "danger",
|
|
102
108
|
title: "删除",
|
|
103
109
|
onRun: ($event) => unref(handleDelete)(row)
|
|
104
|
-
}, unref(props).actionsProps?.delete), null, 16, ["icon", "onRun"])) : createCommentVNode("v-if", true)
|
|
110
|
+
}, unref(props).actionsProps?.delete), null, 16, ["icon", "onRun"])) : createCommentVNode("v-if", true),
|
|
111
|
+
!unref(props).readonly && allowed("create", row) ? (openBlock(), createBlock(unref(_sfc_main$3), {
|
|
112
|
+
key: 3,
|
|
113
|
+
icon: unref(InsertToPrev),
|
|
114
|
+
title: "在上方插入",
|
|
115
|
+
onRun: ($event) => unref(handleInsertToPrev)(row)
|
|
116
|
+
}, null, 8, ["icon", "onRun"])) : createCommentVNode("v-if", true),
|
|
117
|
+
!unref(props).readonly && allowed("create", row) ? (openBlock(), createBlock(unref(_sfc_main$3), {
|
|
118
|
+
key: 4,
|
|
119
|
+
icon: unref(InsertToNext),
|
|
120
|
+
title: "在下方插入",
|
|
121
|
+
onRun: ($event) => unref(handleInsertToNext)(row)
|
|
122
|
+
}, null, 8, ["icon", "onRun"])) : createCommentVNode("v-if", true)
|
|
105
123
|
]),
|
|
106
124
|
_: 2
|
|
107
|
-
},
|
|
125
|
+
}, 1024)]),
|
|
108
126
|
_: 2
|
|
109
127
|
}, [showCreateBtn.value ? {
|
|
110
128
|
name: "append",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-edit-list.js","names":[],"sources":["../../../src/components/batch-edit/batch-edit-list.vue"],"sourcesContent":["<template>\n <u-table\n v-bind=\"tableProps\"\n :slots=\"slots\"\n :class=\"[cls.e('table')]\"\n :columns=\"columns\"\n highlight-current\n :current=\"state.row\"\n @update:current=\"handleUpdateCurrentRow\"\n @update:checked=\"emit('update:checked', $event)\"\n @update:selected=\"emit('update:selected', $event)\"\n >\n <template #column:__action__=\"{ row }\">\n <u-action-group :
|
|
1
|
+
{"version":3,"file":"batch-edit-list.js","names":[],"sources":["../../../src/components/batch-edit/batch-edit-list.vue"],"sourcesContent":["<template>\n <u-table\n v-bind=\"tableProps\"\n :slots=\"slots\"\n :class=\"[cls.e('table')]\"\n :columns=\"columns\"\n highlight-current\n :current=\"state.row\"\n @update:current=\"handleUpdateCurrentRow\"\n @update:checked=\"emit('update:checked', $event)\"\n @update:selected=\"emit('update:selected', $event)\"\n >\n <template #column:__action__=\"{ row }\">\n <u-action-group :max=\"5\" circle @click.stop>\n <u-action\n v-if=\"allowed('update', row)\"\n :icon=\"props.readonly ? View : EditPen\"\n :title=\"props.readonly ? '查看' : '编辑'\"\n @run=\"startEdit(row)\"\n v-bind=\"props.actionsProps?.update\"\n />\n <u-action\n v-if=\"!props.readonly && !!props.tree && allowed('createChild', row)\"\n :icon=\"AddChild\"\n title=\"添加子级\"\n @run=\"handleInsertChild(row)\"\n />\n <u-action\n v-if=\"canDelete(row)\"\n :icon=\"Delete\"\n type=\"danger\"\n title=\"删除\"\n @run=\"handleDelete(row)\"\n v-bind=\"props.actionsProps?.delete\"\n />\n <u-action\n v-if=\"!props.readonly && allowed('create', row)\"\n :icon=\"InsertToPrev\"\n title=\"在上方插入\"\n @run=\"handleInsertToPrev(row)\"\n />\n <u-action\n v-if=\"!props.readonly && allowed('create', row)\"\n :icon=\"InsertToNext\"\n title=\"在下方插入\"\n @run=\"handleInsertToNext(row)\"\n />\n </u-action-group>\n </template>\n\n <!-- 新增按钮 -->\n <template #append v-if=\"showCreateBtn\">\n <div :class=\"cls.e('add')\">\n <u-button\n :class=\"cls.e('add-btn')\"\n :icon=\"Plus\"\n :loading=\"state.loading\"\n type=\"primary\"\n plain\n @click.stop=\"handleCreate\"\n >\n 新增一行\n </u-button>\n </div>\n </template>\n </u-table>\n</template>\n\n<script setup lang=\"ts\">\nimport { o } from '@cat-kit/core'\nimport {\n AddChild,\n Delete,\n EditPen,\n InsertToNext,\n InsertToPrev,\n Plus,\n View\n} from '@veltra/icons/normal'\nimport { computed, inject, type Slots } from 'vue'\n\nimport type { BatchEditFeature, TableRow } from '../../types'\nimport { UAction, UActionGroup } from '../action'\nimport { UButton } from '../button'\nimport { UTable } from '../table'\nimport { BatchEditDIKey } from './di'\n\ndefineOptions({ name: 'UBatchEditList' })\n\ndefineProps<{ slots: Slots }>()\n\nconst {\n cls,\n state,\n props,\n emit,\n staticFeatures,\n dynamicFeatures,\n startEdit,\n handleClose,\n handleCreate,\n handleDelete,\n handleInsertToNext,\n handleInsertToPrev,\n handleInsertChild\n} = inject(BatchEditDIKey)!\n\nconst tableProps = computed(() => {\n return o(props as Record<string, any>).omit([\n 'model',\n 'columns',\n 'cols',\n 'readonly',\n 'deleteMethod',\n 'saveMethod',\n 'features',\n 'beforeCreate',\n 'formMode',\n 'quickEdit',\n 'labelWidth',\n 'actionsProps'\n ])\n})\n\nconst hasNot = (value: BatchEditFeature[]) => value.every((v) => !staticFeatures.value.has(v))\n\nconst allowed = (feature: BatchEditFeature, row?: TableRow) => {\n return staticFeatures.value.has(feature) || !!dynamicFeatures.value[feature]?.(row)\n}\n\nconst columns = computed(() => {\n // 只读模式的操作列只保留「查看」入口\n const related: BatchEditFeature[] = props.readonly\n ? ['update']\n : ['create', 'delete', 'createChild', 'update']\n if (hasNot(related)) return props.columns\n\n return (props.columns ?? []).concat({\n name: '操作',\n key: '__action__',\n align: 'center',\n width: 180,\n fixed: 'right',\n resizable: false\n })\n})\n\nfunction canDelete(row: TableRow) {\n return !props.readonly && allowed('delete', row)\n}\n\n/**\n * 点击行打开编辑/查看表单;再次点击当前行取消选中并关闭表单。\n * update 特性关闭时点击行不响应\n */\nfunction handleUpdateCurrentRow(row?: TableRow) {\n if (!allowed('update', row)) return\n\n if (row) {\n startEdit(row)\n } else {\n handleClose()\n }\n}\n\nconst showCreateBtn = computed(() => {\n if (props.readonly) return false\n\n const hasFeature = staticFeatures.value.has('create') || dynamicFeatures.value.create?.()\n const createActionVisible = state.formActionType === 'create' && state.formVisible\n return hasFeature && !createActionVisible\n})\n</script>\n"],"mappings":";;;;;;;;;;;;;;EA2FA,MAAM,EACJ,KACA,OACA,OACA,MACA,gBACA,iBACA,WACA,aACA,cACA,cACA,oBACA,oBACA,sBACE,OAAO,cAAc;EAEzB,MAAM,aAAa,eAAe;GAChC,OAAO,EAAE,KAA4B,CAAC,CAAC,KAAK;IAC1C;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;GACF,CAAC;EACH,CAAC;EAED,MAAM,UAAU,UAA8B,MAAM,OAAO,MAAM,CAAC,eAAe,MAAM,IAAI,CAAC,CAAC;EAE7F,MAAM,WAAW,SAA2B,QAAmB;GAC7D,OAAO,eAAe,MAAM,IAAI,OAAO,KAAK,CAAC,CAAC,gBAAgB,MAAM,QAAQ,GAAG,GAAG;EACpF;EAEA,MAAM,UAAU,eAAe;GAE7B,MAAM,UAA8B,MAAM,WACtC,CAAC,Q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;;;;;;GAMV,GAAA,CAAA,cAAA,QAAA;IAAb,MAAA;IACT,IAAA,cAWM,CAXN,mBAWM,OAAA,EAXA,OAAK,eAAE,MAAA,GAAA,CAAG,CAAC,EAAC,KAAA,CAAA,EAAA,GAChB,CAAA,YASW,MAAA,WAAA,GAAA;KARR,OAAK,eAAE,MAAA,GAAA,CAAG,CAAC,EAAC,SAAA,CAAA;KACZ,MAAM,MAAA,IAAA;KACN,SAAS,MAAA,KAAA,CAAK,CAAC;KAChB,MAAK;KACL,OAAA;KACC,SAAK,cAAO,MAAA,YAAA,GAAY,CAAA,MAAA,CAAA;;KAC1B,SAAA,cAED,CAAA,GAAA,OAAA,OAAA,OAAA,KAAA,CAFC,gBAAA,UAED,EAAA,CAAA,EAAA,CAAA"}
|
|
@@ -16,7 +16,6 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
16
16
|
__name: "batch-edit",
|
|
17
17
|
props: {
|
|
18
18
|
model: {},
|
|
19
|
-
title: {},
|
|
20
19
|
cols: { default: () => ["1fr", "420px"] },
|
|
21
20
|
readonly: { type: Boolean },
|
|
22
21
|
formMode: { default: "panel" },
|
|
@@ -68,7 +67,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
68
67
|
const slots = useSlots();
|
|
69
68
|
const cls = bem("batch-edit");
|
|
70
69
|
const formRef = useTemplateRef("form");
|
|
71
|
-
const { state, resetState, syncing } = useEditState({
|
|
70
|
+
const { state, resetState, startEdit, syncing } = useEditState({
|
|
72
71
|
props,
|
|
73
72
|
formRef
|
|
74
73
|
});
|
|
@@ -98,6 +97,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
98
97
|
dynamicFeatures,
|
|
99
98
|
focused,
|
|
100
99
|
syncing,
|
|
100
|
+
startEdit,
|
|
101
101
|
...handlers
|
|
102
102
|
});
|
|
103
103
|
return (_ctx, _cache) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-edit.js","names":["$attrs"],"sources":["../../../src/components/batch-edit/batch-edit.vue"],"sourcesContent":["<template>\n <u-layout\n :class=\"cls.b\"\n :cols=\"cols\"\n rows=\"minmax(0, 1fr) \"\n gap=\"8px\"\n resizable\n tabindex=\"-1\"\n @focusin=\"handleFocusIn\"\n @focusout=\"handleFocusOut\"\n @keydown.capture=\"handleKeydown\"\n v-bind=\"$attrs\"\n >\n <!-- 编辑列表 -->\n <BatchEditList :slots=\"slots\" />\n\n <!-- 编辑表单 -->\n <BatchEditForm v-if=\"props.formMode === 'panel'\" ref=\"form\" v-slot=\"scoped\">\n <slot name=\"form\" v-bind=\"scoped\" />\n </BatchEditForm>\n </u-layout>\n\n <!-- 弹框模式:表单经 UDialog 呈现(teleport 到 body),快捷键监听落在弹框上,Esc 与弹框自带的 keyup.esc 去重 -->\n <u-dialog\n v-if=\"props.formMode === 'dialog'\"\n v-model=\"state.formVisible\"\n :class=\"cls.e('form-dialog')\"\n @keydown.capture=\"handleKeydown\"\n @keyup.esc.stop\n >\n <BatchEditForm ref=\"form\" v-slot=\"scoped\">\n <slot name=\"form\" v-bind=\"scoped\" />\n </BatchEditForm>\n </u-dialog>\n</template>\n\n<script lang=\"ts\" setup>\nimport { bem } from '@veltra/utils'\nimport { computed, provide, useTemplateRef } from 'vue'\n\nimport type { BatchEditEmits, BatchEditProps, BatchEditSlots, FormExposed } from '../../types'\nimport { UDialog } from '../dialog'\nimport { ULayout } from '../layout'\nimport BatchEditForm from './batch-edit-form.vue'\nimport BatchEditList from './batch-edit-list.vue'\nimport { BatchEditDIKey } from './di'\nimport { useEditState } from './use-edit-state'\nimport { useFeatures } from './use-features'\nimport { useHandlers } from './use-handlers'\nimport { useShortcutKey } from './use-shortcut-key'\n\ndefineOptions({ name: 'UBatchEdit', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<BatchEditProps>(), {\n cols: () => ['1fr', '420px'],\n formMode: 'panel'\n})\n\nconst emit = defineEmits<BatchEditEmits>()\n\nconst slots = defineSlots<BatchEditSlots>()\n\nconst cls = bem('batch-edit')\n\nconst formRef = useTemplateRef<FormExposed>('form')\n\nconst { state, resetState, syncing } = useEditState({ props, formRef })\n\nconst { staticFeatures, dynamicFeatures } = useFeatures({ props })\n\nconst handlers = useHandlers({ props, emit, state, resetState, formRef })\n\n// 快捷键处理\nconst { handleFocusIn, handleFocusOut, handleKeydown, focused } = useShortcutKey({\n props,\n onSave: handlers.handleSave,\n onClose: handlers.handleClose,\n state\n})\n\nconst cols = computed(() => {\n return props.formMode === 'panel' && state.formVisible ? props.cols : undefined\n})\n\nprovide(BatchEditDIKey, {\n cls,\n props,\n emit,\n state,\n staticFeatures,\n dynamicFeatures,\n focused,\n syncing,\n ...handlers\n})\n</script>\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"batch-edit.js","names":["$attrs"],"sources":["../../../src/components/batch-edit/batch-edit.vue"],"sourcesContent":["<template>\n <u-layout\n :class=\"cls.b\"\n :cols=\"cols\"\n rows=\"minmax(0, 1fr) \"\n gap=\"8px\"\n resizable\n tabindex=\"-1\"\n @focusin=\"handleFocusIn\"\n @focusout=\"handleFocusOut\"\n @keydown.capture=\"handleKeydown\"\n v-bind=\"$attrs\"\n >\n <!-- 编辑列表 -->\n <BatchEditList :slots=\"slots\" />\n\n <!-- 编辑表单 -->\n <BatchEditForm v-if=\"props.formMode === 'panel'\" ref=\"form\" v-slot=\"scoped\">\n <slot name=\"form\" v-bind=\"scoped\" />\n </BatchEditForm>\n </u-layout>\n\n <!-- 弹框模式:表单经 UDialog 呈现(teleport 到 body),快捷键监听落在弹框上,Esc 与弹框自带的 keyup.esc 去重 -->\n <u-dialog\n v-if=\"props.formMode === 'dialog'\"\n v-model=\"state.formVisible\"\n :class=\"cls.e('form-dialog')\"\n @keydown.capture=\"handleKeydown\"\n @keyup.esc.stop\n >\n <BatchEditForm ref=\"form\" v-slot=\"scoped\">\n <slot name=\"form\" v-bind=\"scoped\" />\n </BatchEditForm>\n </u-dialog>\n</template>\n\n<script lang=\"ts\" setup>\nimport { bem } from '@veltra/utils'\nimport { computed, provide, useTemplateRef } from 'vue'\n\nimport type { BatchEditEmits, BatchEditProps, BatchEditSlots, FormExposed } from '../../types'\nimport { UDialog } from '../dialog'\nimport { ULayout } from '../layout'\nimport BatchEditForm from './batch-edit-form.vue'\nimport BatchEditList from './batch-edit-list.vue'\nimport { BatchEditDIKey } from './di'\nimport { useEditState } from './use-edit-state'\nimport { useFeatures } from './use-features'\nimport { useHandlers } from './use-handlers'\nimport { useShortcutKey } from './use-shortcut-key'\n\ndefineOptions({ name: 'UBatchEdit', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<BatchEditProps>(), {\n cols: () => ['1fr', '420px'],\n formMode: 'panel'\n})\n\nconst emit = defineEmits<BatchEditEmits>()\n\nconst slots = defineSlots<BatchEditSlots>()\n\nconst cls = bem('batch-edit')\n\nconst formRef = useTemplateRef<FormExposed>('form')\n\nconst { state, resetState, startEdit, syncing } = useEditState({ props, formRef })\n\nconst { staticFeatures, dynamicFeatures } = useFeatures({ props })\n\nconst handlers = useHandlers({ props, emit, state, resetState, formRef })\n\n// 快捷键处理\nconst { handleFocusIn, handleFocusOut, handleKeydown, focused } = useShortcutKey({\n props,\n onSave: handlers.handleSave,\n onClose: handlers.handleClose,\n state\n})\n\nconst cols = computed(() => {\n return props.formMode === 'panel' && state.formVisible ? props.cols : undefined\n})\n\nprovide(BatchEditDIKey, {\n cls,\n props,\n emit,\n state,\n staticFeatures,\n dynamicFeatures,\n focused,\n syncing,\n startEdit,\n ...handlers\n})\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqDA,MAAM,QAAQ;EAKd,MAAM,OAAO;EAEb,MAAM,QAAQ,SAAA;EAEd,MAAM,MAAM,IAAI,YAAY;EAE5B,MAAM,UAAU,eAA4B,MAAM;EAElD,MAAM,EAAE,OAAO,YAAY,WAAW,YAAY,aAAa;GAAE;GAAO;EA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jB,SAAK,OAAA,OAAA,OAAA,KAAA,SAAA,oBAAN,CAAA,GAAe,CAAA,MAAA,CAAA,GAAA,CAAA,KAAA,CAAA;;KAEf,SAAA,cAEgB,CAFhB,YAEgB,aAAA,EAFD,KAAI,OAAM,GAAA;MACvB,SAAA,SADgC,WAAM,CACtC,WAAoC,KAAA,QAAA,QAAA,eAAA,mBAAV,MAAM,CAAA,CAAA,CAAA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"di.js","names":[],"sources":["../../../src/components/batch-edit/di.ts"],"sourcesContent":["import type { BEM } from '@veltra/utils'\nimport type { ComputedRef, InjectionKey, ShallowRef } from 'vue'\n\nimport type {\n BatchEditEmits,\n BatchEditFeature,\n BatchEditProps,\n BatchEditStates,\n TableRow\n} from '../../types'\nimport type { EditReturned } from './use-handlers'\n\nexport const BatchEditDIKey: InjectionKey<\n {\n cls: BEM<'batch-edit', 'u-'>\n props: BatchEditProps\n emit: BatchEditEmits\n state: BatchEditStates\n staticFeatures: ComputedRef<Set<BatchEditFeature>>\n dynamicFeatures: ComputedRef<\n Record<BatchEditFeature, ((row?: TableRow) => boolean) | undefined>\n >\n /** 组件或其子节点是否处于聚焦状态 */\n focused: ShallowRef<boolean>\n /** 是否正在以编程方式重置/回显表单,此期间禁止 quick-edit 回写行数据 */\n syncing: ShallowRef<boolean>\n } & EditReturned\n> = Symbol('BatchEditDIKey')\n"],"mappings":";AAYA,MAAa,
|
|
1
|
+
{"version":3,"file":"di.js","names":[],"sources":["../../../src/components/batch-edit/di.ts"],"sourcesContent":["import type { BEM } from '@veltra/utils'\nimport type { ComputedRef, InjectionKey, ShallowRef } from 'vue'\n\nimport type {\n BatchEditEmits,\n BatchEditFeature,\n BatchEditProps,\n BatchEditStates,\n TableRow\n} from '../../types'\nimport type { EditReturned } from './use-handlers'\n\nexport const BatchEditDIKey: InjectionKey<\n {\n cls: BEM<'batch-edit', 'u-'>\n props: BatchEditProps\n emit: BatchEditEmits\n state: BatchEditStates\n staticFeatures: ComputedRef<Set<BatchEditFeature>>\n dynamicFeatures: ComputedRef<\n Record<BatchEditFeature, ((row?: TableRow) => boolean) | undefined>\n >\n /** 组件或其子节点是否处于聚焦状态 */\n focused: ShallowRef<boolean>\n /** 是否正在以编程方式重置/回显表单,此期间禁止 quick-edit 回写行数据 */\n syncing: ShallowRef<boolean>\n /** 开始编辑/查看一行(点击行或操作列「编辑」按钮触发) */\n startEdit: (row: TableRow) => void\n } & EditReturned\n> = Symbol('BatchEditDIKey')\n"],"mappings":";AAYA,MAAa,iBAiBT,OAAO,gBAAgB"}
|
|
@@ -34,29 +34,33 @@ function useEditState(options) {
|
|
|
34
34
|
}
|
|
35
35
|
function resetState() {
|
|
36
36
|
resetModel();
|
|
37
|
-
if (state.row) state.row.isCurrent = false;
|
|
38
37
|
Object.keys(state).forEach((key) => {
|
|
39
38
|
delete state[key];
|
|
40
39
|
});
|
|
41
40
|
Object.assign(state, defaultState);
|
|
42
41
|
}
|
|
43
|
-
|
|
42
|
+
/**
|
|
43
|
+
* 开始编辑/查看一行:先重置回 model 初始快照,再回显行数据。
|
|
44
|
+
* 同一 tick 内的连续写入会被表单字段 watcher 合并,
|
|
45
|
+
* 重置产生的默认值不会触发 field:update 回写行数据
|
|
46
|
+
*/
|
|
47
|
+
function startEdit(row) {
|
|
44
48
|
syncing.value = true;
|
|
45
49
|
resetModel();
|
|
46
|
-
if (row)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
} else resetState();
|
|
50
|
+
if (props.model) o(props.model).deepExtend(row.data);
|
|
51
|
+
state.row = row;
|
|
52
|
+
state.formActionType = props.readonly ? "view" : "update";
|
|
53
|
+
state.formVisible = true;
|
|
54
|
+
state.depth = row.depth;
|
|
55
|
+
state.indexPath = [...row.indexes];
|
|
53
56
|
nextTick(() => {
|
|
54
57
|
syncing.value = false;
|
|
55
58
|
});
|
|
56
|
-
}
|
|
59
|
+
}
|
|
57
60
|
return {
|
|
58
61
|
state,
|
|
59
62
|
resetState,
|
|
63
|
+
startEdit,
|
|
60
64
|
syncing
|
|
61
65
|
};
|
|
62
66
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-edit-state.js","names":[],"sources":["../../../src/components/batch-edit/use-edit-state.ts"],"sourcesContent":["import { copy, o } from '@cat-kit/core'\nimport { nextTick, shallowReactive, shallowRef, watch, type ShallowRef } from 'vue'\n\nimport type { BatchEditProps, BatchEditStates, FormExposed } from '../../types'\n\ninterface Options {\n props: BatchEditProps\n formRef: ShallowRef<FormExposed | null>\n}\n\nexport function useEditState(options: Options) {\n const { props, formRef } = options\n\n const defaultState: BatchEditStates = {\n depth: -1,\n formVisible: false,\n formActionType: 'create',\n loading: false,\n indexPath: []\n }\n\n const state = shallowReactive({ ...defaultState })\n\n /** 是否正在以编程方式重置/回显表单,此期间禁止 quick-edit 回写行数据 */\n const syncing = shallowRef(false)\n\n /**\n * model 初始快照。\n * 面板模式由常驻挂载的 UForm 自行维护快照;dialog 模式表单随弹框卸载,\n * UForm 快照会在每次打开时按已回显的 model 重拍,故这里单独保留一份供恢复\n */\n const initialModel = shallowRef<Record<string, any>>()\n\n watch(\n () => props.model,\n (model) => {\n initialModel.value = props.formMode === 'dialog' && model ? copy(model) : undefined\n },\n { immediate: true }\n )\n\n /** 重置表单数据到 model 初始快照 */\n function resetModel() {\n if (props.formMode !== 'dialog') {\n formRef.value?.reset()\n return\n }\n\n formRef.value?.clearValidate()\n if (!props.model || !initialModel.value) return\n for (const key of Object.keys(initialModel.value)) {\n o(props.model).set(key, copy(initialModel.value[key]))\n }\n }\n\n function resetState() {\n resetModel()\n\n
|
|
1
|
+
{"version":3,"file":"use-edit-state.js","names":[],"sources":["../../../src/components/batch-edit/use-edit-state.ts"],"sourcesContent":["import { copy, o } from '@cat-kit/core'\nimport { nextTick, shallowReactive, shallowRef, watch, type ShallowRef } from 'vue'\n\nimport type { BatchEditProps, BatchEditStates, FormExposed, TableRow } from '../../types'\n\ninterface Options {\n props: BatchEditProps\n formRef: ShallowRef<FormExposed | null>\n}\n\nexport function useEditState(options: Options) {\n const { props, formRef } = options\n\n const defaultState: BatchEditStates = {\n depth: -1,\n formVisible: false,\n formActionType: 'create',\n loading: false,\n indexPath: []\n }\n\n const state = shallowReactive({ ...defaultState })\n\n /** 是否正在以编程方式重置/回显表单,此期间禁止 quick-edit 回写行数据 */\n const syncing = shallowRef(false)\n\n /**\n * model 初始快照。\n * 面板模式由常驻挂载的 UForm 自行维护快照;dialog 模式表单随弹框卸载,\n * UForm 快照会在每次打开时按已回显的 model 重拍,故这里单独保留一份供恢复\n */\n const initialModel = shallowRef<Record<string, any>>()\n\n watch(\n () => props.model,\n (model) => {\n initialModel.value = props.formMode === 'dialog' && model ? copy(model) : undefined\n },\n { immediate: true }\n )\n\n /** 重置表单数据到 model 初始快照 */\n function resetModel() {\n if (props.formMode !== 'dialog') {\n formRef.value?.reset()\n return\n }\n\n formRef.value?.clearValidate()\n if (!props.model || !initialModel.value) return\n for (const key of Object.keys(initialModel.value)) {\n o(props.model).set(key, copy(initialModel.value[key]))\n }\n }\n\n function resetState() {\n resetModel()\n\n Object.keys(state).forEach((key) => {\n delete state[key]\n })\n\n Object.assign(state, defaultState)\n }\n\n /**\n * 开始编辑/查看一行:先重置回 model 初始快照,再回显行数据。\n * 同一 tick 内的连续写入会被表单字段 watcher 合并,\n * 重置产生的默认值不会触发 field:update 回写行数据\n */\n function startEdit(row: TableRow) {\n syncing.value = true\n\n resetModel()\n\n if (props.model) {\n o(props.model).deepExtend(row.data)\n }\n\n state.row = row\n state.formActionType = props.readonly ? 'view' : 'update'\n state.formVisible = true\n state.depth = row.depth\n state.indexPath = [...row.indexes]\n\n nextTick(() => {\n syncing.value = false\n })\n }\n\n return { state, resetState, startEdit, syncing }\n}\n"],"mappings":";;;AAUA,SAAgB,aAAa,SAAkB;CAC7C,MAAM,EAAE,OAAO,YAAY;CAE3B,MAAM,eA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ts"],"sourcesContent":["import { copy, last, o } from '@cat-kit/core'\nimport { computed, nextTick, type ShallowRef } from 'vue'\n\nimport type {\n TableRow,\n BatchEditEmits,\n BatchEditProps,\n BatchEditStates,\n FormExposed\n} from '../../types'\n\n/** 按索引路径在原始数据树中定位节点(等价于历史 Forest.visit 路径访问) */\nfunction visitDataByIndexPath<T extends Record<string, unknown>>(\n roots: T[],\n indexPath: number[],\n childrenKey: string\n): T | undefined {\n if (!indexPath.length) return undefined\n let currentList: T[] | undefined = roots\n let node: T | undefined\n for (let i = 0; i < indexPath.length; i++) {\n const idx = indexPath[i]!\n if (!currentList) return undefined\n node = currentList[idx]\n if (node === undefined) return undefined\n if (i < indexPath.length - 1) {\n const next = node[childrenKey]\n currentList = Array.isArray(next) ? (next as T[]) : undefined\n }\n }\n return node\n}\n\ninterface Options {\n props: BatchEditProps\n emit: BatchEditEmits\n state: BatchEditStates\n formRef: ShallowRef<FormExposed | null>\n resetState: () => void\n}\n\nexport interface EditReturned {\n handleSave: () => Promise<void>\n handleClose: () => void\n handleCreate: () => void\n handleDelete: (row: TableRow) => Promise<void>\n handleInsertToNext: (row: TableRow) => void\n handleInsertToPrev: (row: TableRow) => void\n handleInsertChild: (row: TableRow) => void\n}\n\nexport function useHandlers(options: Options): EditReturned {\n const { props, emit, state, resetState, formRef } = options\n\n const childrenKey = computed(() => {\n return typeof props.tree === 'string' ? props.tree : 'children'\n })\n\n function getInsertData(): Record<string, any> {\n return copy(props.model ?? {})\n }\n\n /**\n * 插入数据\n * @param item 数据\n */\n function insert(item: Record<string, any>) {\n const data = [...(props.data ?? [])]\n\n const parent = visitDataByIndexPath(data ?? [], state.indexPath.slice(0, -1), childrenKey.value)\n\n if (parent) {\n const children = parent[childrenKey.value]\n if (!children) {\n parent[childrenKey.value] = [item]\n } else {\n children.splice(last(state.indexPath), 0, item)\n }\n } else {\n data.splice(last(state.indexPath), 0, item)\n }\n\n emit('update:data', data)\n\n return item\n }\n\n /**\n * 点击新增按钮\n */\n function handleCreate() {\n const { data } = props\n\n resetState()\n\n nextTick(() => {\n state.formActionType = 'create'\n state.formVisible = true\n state.depth = 1\n state.indexPath = [data?.length ?? 0]\n emit('create')\n })\n }\n\n function handleInsertToPrev(row: TableRow) {\n resetState()\n state.formActionType = 'create'\n state.formVisible = true\n state.parentRow = row.parent\n state.depth = row.depth\n state.indexPath = [...row.indexes]\n emit('create-prev', row)\n }\n\n function handleInsertToNext(row: TableRow) {\n resetState()\n state.formActionType = 'create'\n state.formVisible = true\n state.parentRow = row.parent\n state.depth = row.depth\n state.indexPath = [...row.indexes.slice(0, -1), row.index + 1]\n emit('create-next', row)\n }\n\n function handleInsertChild(row: TableRow) {\n resetState()\n state.formActionType = 'createChild'\n state.formVisible = true\n state.parentRow = row\n state.depth = row.depth + 1\n row.expanded = true\n state.indexPath = [...row.indexes, row.children?.length ?? 0]\n emit('create-child', row)\n }\n\n function runWithLoading<Arg extends any[]>(fn: (...args: Arg) => Promise<void> | void) {\n return async (...args: Arg) => {\n state.loading = true\n if (state.row) {\n state.row.operating = true\n }\n try {\n await fn.apply(null, args)\n } catch (error) {\n console.error(error)\n }\n state.loading = false\n if (state.row) {\n state.row.operating = false\n }\n }\n }\n\n /** 保存 */\n const handleSave = runWithLoading(async () => {\n const { model, saveMethod } = props\n const valid = await formRef.value?.validate()\n if (!model || !valid) return\n\n let item = getInsertData()\n\n // 新增\n if (state.formActionType === 'create' || state.formActionType === 'createChild') {\n await props.beforeCreate?.(item, state.parentRow?.data)\n if (saveMethod) {\n const result = await saveMethod(item, state.formActionType, state.parentRow?.data)\n if (result) {\n item = result\n }\n }\n insert(item)\n\n // 弹框模式保存成功即关闭,不走面板的连续新增\n if (props.formMode === 'dialog') {\n resetState()\n return\n }\n\n // 推进插入点,便于连续新增;并重置表单到初始默认值\n const next = last(state.indexPath) + 1\n state.indexPath = [...state.indexPath.slice(0, -1), next]\n formRef.value?.reset()\n return\n }\n\n // 普通模式下的编辑\n if (saveMethod) {\n const result = await saveMethod(item, state.formActionType, state.parentRow?.data)\n if (result) {\n item = result\n }\n }\n\n const { row } = state\n row &&\n Object.keys(item).forEach((key) => {\n o(row.data).set(key, o(item).get(key))\n })\n\n if (props.formMode === 'dialog') {\n resetState()\n }\n })\n\n const handleDelete = runWithLoading(async (row: TableRow) => {\n const { deleteMethod } = props\n\n if (deleteMethod) {\n const result = await deleteMethod([row.data])\n if (result === false) {\n return\n }\n }\n\n const data = [...(props.data ?? [])]\n\n const parent = visitDataByIndexPath(data, row.indexes.slice(0, -1), childrenKey.value)\n\n if (parent) {\n const children = parent[childrenKey.value]\n if (children) {\n children.splice(row.index, 1)\n } else {\n console.error('行路径不正确')\n }\n } else {\n data.splice(row.index, 1)\n }\n\n if (state.row === row) {\n resetState()\n }\n\n emit('update:data', data)\n })\n\n function handleClose() {\n resetState()\n }\n\n return {\n handleDelete,\n handleInsertChild,\n handleInsertToNext,\n handleInsertToPrev,\n handleCreate,\n handleClose,\n handleSave\n }\n}\n"],"mappings":";;;;AAYA,SAAS,qBACP,OACA,WACA,aACe;CACf,IAAI,CAAC,UAAU,QAAQ,OAAO,KAAA;CAC9B,IAAI,cAA+B;CACnC,IAAI;CACJ,KAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;EACzC,MAAM,MAAM,UAAU;EACtB,IAAI,CAAC,aAAa,OAAO,KAAA;EACzB,OAAO,YAAY;EACnB,IAAI,SAAS,KAAA,GAAW,OAAO,KAAA;EAC/B,IAAI,IAAI,UAAU,SAAS,GAAG;GAC5B,MAAM,OAAO,KAAK;GAClB,cAAc,MAAM,QAAQ,IAAI,IAAK,OAAe,KAAA;EACtD;CACF;CACA,OAAO;AACT;AAoBA,SAAgB,YAAY,SAAgC;CAC1D,MAAM,EAAE,OAAO,MAAM,OAAO,YAAY,YAAY;CAEpD,MAAM,cAAc,eAAe;EACjC,OAAO,OAAO,MAAM,SAAS,WAAW,MAAM,OAAO;CACvD,CAAC;CAED,SAAS,gBAAqC;EAC5C,OAA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Q,IAAI,QAAQ;EAC1B,IAAI,WAAW;EACf,MAAM,YAAY,CAAC,GAAG,IAAI,SAAS,IAAI,UAAU,UAAU,CAAC;EAC5D,KAAK,gBAAgB,GAAG;CAC1B;CAEA,SAAS,eAAkC,IAA4C;EACrF,OAAO,OAAO,GAAG,SAAc;
|
|
1
|
+
{"version":3,"file":"use-handlers.js","names":[],"sources":["../../../src/components/batch-edit/use-handlers.ts"],"sourcesContent":["import { copy, last, o } from '@cat-kit/core'\nimport { computed, nextTick, type ShallowRef } from 'vue'\n\nimport type {\n TableRow,\n BatchEditEmits,\n BatchEditProps,\n BatchEditStates,\n FormExposed\n} from '../../types'\n\n/** 按索引路径在原始数据树中定位节点(等价于历史 Forest.visit 路径访问) */\nfunction visitDataByIndexPath<T extends Record<string, unknown>>(\n roots: T[],\n indexPath: number[],\n childrenKey: string\n): T | undefined {\n if (!indexPath.length) return undefined\n let currentList: T[] | undefined = roots\n let node: T | undefined\n for (let i = 0; i < indexPath.length; i++) {\n const idx = indexPath[i]!\n if (!currentList) return undefined\n node = currentList[idx]\n if (node === undefined) return undefined\n if (i < indexPath.length - 1) {\n const next = node[childrenKey]\n currentList = Array.isArray(next) ? (next as T[]) : undefined\n }\n }\n return node\n}\n\ninterface Options {\n props: BatchEditProps\n emit: BatchEditEmits\n state: BatchEditStates\n formRef: ShallowRef<FormExposed | null>\n resetState: () => void\n}\n\nexport interface EditReturned {\n handleSave: () => Promise<void>\n handleClose: () => void\n handleCreate: () => void\n handleDelete: (row: TableRow) => Promise<void>\n handleInsertToNext: (row: TableRow) => void\n handleInsertToPrev: (row: TableRow) => void\n handleInsertChild: (row: TableRow) => void\n}\n\nexport function useHandlers(options: Options): EditReturned {\n const { props, emit, state, resetState, formRef } = options\n\n const childrenKey = computed(() => {\n return typeof props.tree === 'string' ? props.tree : 'children'\n })\n\n function getInsertData(): Record<string, any> {\n return copy(props.model ?? {})\n }\n\n /**\n * 插入数据\n * @param item 数据\n */\n function insert(item: Record<string, any>) {\n const data = [...(props.data ?? [])]\n\n const parent = visitDataByIndexPath(data ?? [], state.indexPath.slice(0, -1), childrenKey.value)\n\n if (parent) {\n const children = parent[childrenKey.value]\n if (!children) {\n parent[childrenKey.value] = [item]\n } else {\n children.splice(last(state.indexPath), 0, item)\n }\n } else {\n data.splice(last(state.indexPath), 0, item)\n }\n\n emit('update:data', data)\n\n return item\n }\n\n /**\n * 点击新增按钮\n */\n function handleCreate() {\n const { data } = props\n\n resetState()\n\n nextTick(() => {\n state.formActionType = 'create'\n state.formVisible = true\n state.depth = 1\n state.indexPath = [data?.length ?? 0]\n emit('create')\n })\n }\n\n function handleInsertToPrev(row: TableRow) {\n resetState()\n state.formActionType = 'create'\n state.formVisible = true\n state.parentRow = row.parent\n state.depth = row.depth\n state.indexPath = [...row.indexes]\n emit('create-prev', row)\n }\n\n function handleInsertToNext(row: TableRow) {\n resetState()\n state.formActionType = 'create'\n state.formVisible = true\n state.parentRow = row.parent\n state.depth = row.depth\n state.indexPath = [...row.indexes.slice(0, -1), row.index + 1]\n emit('create-next', row)\n }\n\n function handleInsertChild(row: TableRow) {\n resetState()\n state.formActionType = 'createChild'\n state.formVisible = true\n state.parentRow = row\n state.depth = row.depth + 1\n row.expanded = true\n state.indexPath = [...row.indexes, row.children?.length ?? 0]\n emit('create-child', row)\n }\n\n function runWithLoading<Arg extends any[]>(fn: (...args: Arg) => Promise<void> | void) {\n return async (...args: Arg) => {\n // 重入保护:进行中(快捷键/按钮并发触发)直接忽略\n if (state.loading) return\n state.loading = true\n if (state.row) {\n state.row.operating = true\n }\n try {\n await fn.apply(null, args)\n } catch (error) {\n console.error(error)\n }\n state.loading = false\n if (state.row) {\n state.row.operating = false\n }\n }\n }\n\n /** 保存 */\n const handleSave = runWithLoading(async () => {\n const { model, saveMethod } = props\n const valid = await formRef.value?.validate()\n if (!model || !valid) return\n\n let item = getInsertData()\n\n // 新增\n if (state.formActionType === 'create' || state.formActionType === 'createChild') {\n await props.beforeCreate?.(item, state.parentRow?.data)\n if (saveMethod) {\n const result = await saveMethod(item, state.formActionType, state.parentRow?.data)\n if (result) {\n item = result\n }\n }\n insert(item)\n\n // 弹框模式保存成功即关闭,不走面板的连续新增\n if (props.formMode === 'dialog') {\n resetState()\n return\n }\n\n // 推进插入点,便于连续新增;并重置表单到初始默认值\n const next = last(state.indexPath) + 1\n state.indexPath = [...state.indexPath.slice(0, -1), next]\n formRef.value?.reset()\n return\n }\n\n // 普通模式下的编辑\n if (saveMethod) {\n const result = await saveMethod(item, state.formActionType, state.parentRow?.data)\n if (result) {\n item = result\n }\n }\n\n const { row } = state\n row &&\n Object.keys(item).forEach((key) => {\n o(row.data).set(key, o(item).get(key))\n })\n\n if (props.formMode === 'dialog') {\n resetState()\n }\n })\n\n const handleDelete = runWithLoading(async (row: TableRow) => {\n const { deleteMethod } = props\n\n if (deleteMethod) {\n const result = await deleteMethod([row.data])\n if (result === false) {\n return\n }\n }\n\n const data = [...(props.data ?? [])]\n\n const parent = visitDataByIndexPath(data, row.indexes.slice(0, -1), childrenKey.value)\n\n if (parent) {\n const children = parent[childrenKey.value]\n if (children) {\n children.splice(row.index, 1)\n } else {\n console.error('行路径不正确')\n }\n } else {\n data.splice(row.index, 1)\n }\n\n if (state.row === row) {\n resetState()\n }\n\n emit('update:data', data)\n })\n\n function handleClose() {\n resetState()\n }\n\n return {\n handleDelete,\n handleInsertChild,\n handleInsertToNext,\n handleInsertToPrev,\n handleCreate,\n handleClose,\n handleSave\n }\n}\n"],"mappings":";;;;AAYA,SAAS,qBACP,OACA,WACA,aACe;CACf,IAAI,CAAC,UAAU,QAAQ,OAAO,KAAA;CAC9B,IAAI,cAA+B;CACnC,IAAI;CACJ,KAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;EACzC,MAAM,MAAM,UAAU;EACtB,IAAI,CAAC,aAAa,OAAO,KAAA;EACzB,OAAO,YAAY;EACnB,IAAI,SAAS,KAAA,GAAW,OAAO,KAAA;EAC/B,IAAI,IAAI,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|
5
|
-
const CHIP_CLOSE_ATTR = "data-chip-close";
|
|
6
5
|
/** 判断一个 DOM 节点是否为 chip 元素(var 段渲染体) */
|
|
7
6
|
function isChipElement(node) {
|
|
8
7
|
return !!node && node.nodeType === 1 && node.getAttribute("data-seg") === CHIP_DATA_SEG;
|
|
9
8
|
}
|
|
10
|
-
/** 判断点击目标是否落在 × 删除区。 */
|
|
11
|
-
function isCloseTarget(target) {
|
|
12
|
-
if (!(target instanceof Element)) return false;
|
|
13
|
-
return !!target.closest(`[${CHIP_CLOSE_ATTR}]`);
|
|
14
|
-
}
|
|
15
9
|
/** 从给定 segment 创建一个 chip 元素(var 段渲染体)。 */
|
|
16
10
|
function createChip(segment, opts) {
|
|
17
11
|
const { cls } = opts;
|
|
@@ -25,19 +19,11 @@ function createChip(segment, opts) {
|
|
|
25
19
|
const label = document.createElement("span");
|
|
26
20
|
label.className = cls.e("chip-label");
|
|
27
21
|
label.textContent = segment.type ? `${segment.label} (${segment.type})` : segment.label;
|
|
28
|
-
const close = document.createElement("span");
|
|
29
|
-
close.className = cls.e("chip-close");
|
|
30
|
-
close.setAttribute(CHIP_CLOSE_ATTR, "true");
|
|
31
|
-
close.setAttribute("aria-label", "删除");
|
|
32
|
-
close.setAttribute("role", "button");
|
|
33
|
-
close.textContent = "×";
|
|
34
22
|
chip.appendChild(label);
|
|
35
|
-
chip.appendChild(close);
|
|
36
23
|
chip.addEventListener("mousedown", (e) => {
|
|
37
24
|
e.preventDefault();
|
|
38
25
|
e.stopPropagation();
|
|
39
|
-
|
|
40
|
-
else opts.onReselect(chip);
|
|
26
|
+
opts.onReselect(chip);
|
|
41
27
|
});
|
|
42
28
|
return chip;
|
|
43
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chip.js","names":[],"sources":["../../../../src/components/expression-editor/core/chip.ts"],"sourcesContent":["import type { BEM } from '@veltra/utils'\n\nimport type { Segment } from './model'\n\nexport interface ChipDeps {\n cls: BEM<'expression-editor'>\n}\n\nexport interface ChipFactoryOptions extends ChipDeps {\n /**\n * 当用户点击 chip
|
|
1
|
+
{"version":3,"file":"chip.js","names":[],"sources":["../../../../src/components/expression-editor/core/chip.ts"],"sourcesContent":["import type { BEM } from '@veltra/utils'\n\nimport type { Segment } from './model'\n\nexport interface ChipDeps {\n cls: BEM<'expression-editor'>\n}\n\nexport interface ChipFactoryOptions extends ChipDeps {\n /**\n * 当用户点击 chip 主体时回调,由调用方决定如何打开重选面板。\n * 收到的 chipEl 当前在 DOM 中的位置即为重选锚点。\n */\n onReselect: (chipEl: HTMLElement) => void\n}\n\nconst CHIP_DATA_SEG = 'var'\nconst CHIP_VALUE_ATTR = 'data-value'\nconst CHIP_TYPE_ATTR = 'data-var-type'\n\n/** 判断一个 DOM 节点是否为 chip 元素(var 段渲染体) */\nexport function isChipElement(node: Node | null): node is HTMLElement {\n return (\n !!node &&\n node.nodeType === 1 &&\n (node as HTMLElement).getAttribute('data-seg') === CHIP_DATA_SEG\n )\n}\n\n/** 从给定 segment 创建一个 chip 元素(var 段渲染体)。 */\nexport function createChip(\n segment: Extract<Segment, { kind: 'var' }>,\n opts: ChipFactoryOptions\n): HTMLElement {\n const { cls } = opts\n\n const chip = document.createElement('span')\n chip.setAttribute('data-seg', CHIP_DATA_SEG)\n chip.setAttribute(CHIP_VALUE_ATTR, segment.value)\n if (segment.type) chip.setAttribute(CHIP_TYPE_ATTR, segment.type)\n chip.setAttribute('contenteditable', 'false')\n chip.className = cls.e('chip')\n chip.title = segment.label\n\n const label = document.createElement('span')\n label.className = cls.e('chip-label')\n label.textContent = segment.type ? `${segment.label} (${segment.type})` : segment.label\n\n chip.appendChild(label)\n\n chip.addEventListener('mousedown', (e) => {\n e.preventDefault()\n // 阻止冒泡:避免宿主弹框(如 dialog)的 mousedown 层级提升逻辑把 chip 打开的重选面板盖住\n e.stopPropagation()\n opts.onReselect(chip)\n })\n\n return chip\n}\n\n/** 读取 chip 元素绑定的变量 value。 */\nexport function readChipValue(el: HTMLElement): string {\n return el.getAttribute(CHIP_VALUE_ATTR) ?? ''\n}\n\n/** 读取 chip 元素绑定的可选 type。 */\nexport function readChipType(el: HTMLElement): string | undefined {\n return el.getAttribute(CHIP_TYPE_ATTR) ?? undefined\n}\n\n/** 在 chip 上设置 / 取消选中(焦点)样式。 */\nexport function setChipFocused(el: HTMLElement, focused: boolean): void {\n el.classList.toggle('is-focused', focused)\n}\n\n/** 测试支持:暴露用于 DOM 选择器的属性常量。 */\nexport const ChipAttrs = { seg: 'data-seg', value: CHIP_VALUE_ATTR, type: CHIP_TYPE_ATTR } as const\n"],"mappings":";AAgBA,MAAM,gBAAgB;AACtB,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;;AAGvB,SAAgB,cAAc,MAAwC;CACpE,OACE,CAAC,CAAC,QACF,KAAK,aAAa,KACjB,KAAqB,aAAa,UAAU,MAAM;AAEvD;;AAGA,SAAgB,WACd,SACA,MACa;CACb,MAAM,EAAE,QAAQ;CAEhB,MAAM,OAAO,SAAS,cAAc,MAAM;CAC1C,KAAK,aAAa,YAAY,aAAa;CAC3C,KAAK,aAAa,iBAAiB,QAAQ,KAAK;CAChD,IAAI,QAAQ,MAAM,KAAK,aAAa,gBAAgB,QAAQ,IAAI;CAChE,KAAK,aAAa,mBAAmB,OAAO;CAC5C,KAAK,YAAY,IAAI,EAAE,MAAM;CAC7B,KAAK,QAAQ,QAAQ;CAErB,MAAM,QAAQ,SAAS,cAAc,MAAM;CAC3C,MAAM,YAAY,IAAI,EAAE,YAAY;CACpC,MAAM,cAAc,QAAQ,OAAO,GAAG,QAAQ,MAAM,IAAI,QAAQ,KAAK,KAAK,QAAQ;CAElF,KAAK,YAAY,KAAK;CAEtB,KAAK,iBAAiB,cAAc,MAAM;EACxC,EAAE,eAAe;EAEjB,EAAE,gBAAgB;EAClB,KAAK,WAAW,IAAI;CACtB,CAAC;CAED,OAAO;AACT;;AAGA,SAAgB,cAAc,IAAyB;CACrD,OAAO,GAAG,aAAa,eAAe,KAAK;AAC7C;;AAGA,SAAgB,aAAa,IAAqC;CAChE,OAAO,GAAG,aAAa,cAAc,KAAK,KAAA;AAC5C"}
|
|
@@ -27,14 +27,6 @@ function createEditor(opts) {
|
|
|
27
27
|
segIndex,
|
|
28
28
|
chipOffset
|
|
29
29
|
});
|
|
30
|
-
},
|
|
31
|
-
onRemove: (chipEl) => {
|
|
32
|
-
const { segIndex } = locateChip(chipEl);
|
|
33
|
-
if (segIndex < 0) return;
|
|
34
|
-
opts.onChipRemove?.({
|
|
35
|
-
chipEl,
|
|
36
|
-
segIndex
|
|
37
|
-
});
|
|
38
30
|
}
|
|
39
31
|
});
|
|
40
32
|
}
|
|
@@ -324,15 +316,6 @@ function createEditor(opts) {
|
|
|
324
316
|
]));
|
|
325
317
|
render(a + variable.value.length + 2);
|
|
326
318
|
}
|
|
327
|
-
function removeVarAt(segIndex) {
|
|
328
|
-
const target = doc[segIndex];
|
|
329
|
-
if (!target || target.kind !== "var") return;
|
|
330
|
-
const before = doc.slice(0, segIndex);
|
|
331
|
-
const after = doc.slice(segIndex + 1);
|
|
332
|
-
const caretOffset = sliceLength(before);
|
|
333
|
-
emitChange(normalize([...before, ...after]));
|
|
334
|
-
render(caretOffset);
|
|
335
|
-
}
|
|
336
319
|
function replaceVarAt(segIndex, variable) {
|
|
337
320
|
const target = doc[segIndex];
|
|
338
321
|
if (!target || target.kind !== "var") return;
|
|
@@ -406,7 +389,6 @@ function createEditor(opts) {
|
|
|
406
389
|
getCaretOffset,
|
|
407
390
|
setCaretOffset: setCaret,
|
|
408
391
|
replaceRangeWithVar,
|
|
409
|
-
removeVarAt,
|
|
410
392
|
replaceVarAt,
|
|
411
393
|
rerender: () => render(),
|
|
412
394
|
dispose: () => {
|