@coze-editor/vue-components 0.1.0-alpha.09ffeb
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/LICENSE +21 -0
- package/dist/esm/index.js +130 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +149 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 coze-dev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// src/placeholder.ts
|
|
2
|
+
import { h, defineComponent, onBeforeMount, onUnmounted, Teleport } from "vue";
|
|
3
|
+
import { useInjector } from "@coze-editor/vue";
|
|
4
|
+
import { placeholder } from "@coze-editor/extension-placeholder";
|
|
5
|
+
var Placeholder = defineComponent({
|
|
6
|
+
setup(_props, { slots }) {
|
|
7
|
+
const element = document.createElement("span");
|
|
8
|
+
const injector = useInjector();
|
|
9
|
+
let eject = null;
|
|
10
|
+
onBeforeMount(() => {
|
|
11
|
+
eject = injector.inject([placeholder(() => element)]);
|
|
12
|
+
});
|
|
13
|
+
onUnmounted(() => {
|
|
14
|
+
if (eject) {
|
|
15
|
+
eject();
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return () => h(Teleport, { to: element }, [
|
|
19
|
+
slots.default ? slots.default() : void 0
|
|
20
|
+
]);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// src/cursor-mirror.ts
|
|
25
|
+
import {
|
|
26
|
+
defineComponent as defineComponent2,
|
|
27
|
+
onBeforeMount as onBeforeMount2,
|
|
28
|
+
onMounted,
|
|
29
|
+
onUnmounted as onUnmounted2
|
|
30
|
+
} from "vue";
|
|
31
|
+
import { autoUpdate } from "@floating-ui/dom";
|
|
32
|
+
import { useEditorRef, useInjector as useInjector2 } from "@coze-editor/vue";
|
|
33
|
+
import {
|
|
34
|
+
elementAtPosition,
|
|
35
|
+
positionElementLayer,
|
|
36
|
+
SelectionSide
|
|
37
|
+
} from "@coze-editor/extensions";
|
|
38
|
+
var CursorMirror = defineComponent2({
|
|
39
|
+
props: {
|
|
40
|
+
side: String,
|
|
41
|
+
onChange: Function,
|
|
42
|
+
onVisibleChange: Function
|
|
43
|
+
},
|
|
44
|
+
setup({ side, onChange, onVisibleChange }, { expose }) {
|
|
45
|
+
const injector = useInjector2();
|
|
46
|
+
const editor = useEditorRef();
|
|
47
|
+
const dom = document.createElement("div");
|
|
48
|
+
expose({ element: dom });
|
|
49
|
+
let eject = null;
|
|
50
|
+
onBeforeMount2(() => {
|
|
51
|
+
eject = injector.inject([
|
|
52
|
+
elementAtPosition.of({
|
|
53
|
+
dom,
|
|
54
|
+
pos: side
|
|
55
|
+
}),
|
|
56
|
+
positionElementLayer
|
|
57
|
+
]);
|
|
58
|
+
});
|
|
59
|
+
onUnmounted2(() => {
|
|
60
|
+
if (typeof eject === "function") {
|
|
61
|
+
eject();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
let disposeUpdateWatcher = null;
|
|
65
|
+
onMounted(() => {
|
|
66
|
+
const floating = document.createElement("div");
|
|
67
|
+
document.body.appendChild(floating);
|
|
68
|
+
const dispose = autoUpdate(
|
|
69
|
+
dom,
|
|
70
|
+
floating,
|
|
71
|
+
() => {
|
|
72
|
+
if (typeof onChange === "function") {
|
|
73
|
+
onChange();
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
{ animationFrame: true }
|
|
77
|
+
);
|
|
78
|
+
disposeUpdateWatcher = () => {
|
|
79
|
+
document.body.removeChild(floating);
|
|
80
|
+
dispose();
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
onUnmounted2(() => {
|
|
84
|
+
if (typeof disposeUpdateWatcher === "function") {
|
|
85
|
+
disposeUpdateWatcher();
|
|
86
|
+
disposeUpdateWatcher = null;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
let disposeVisibleWatcher = null;
|
|
90
|
+
onMounted(() => {
|
|
91
|
+
if (!editor) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const view = editor.value.$view;
|
|
95
|
+
const observer = new IntersectionObserver(
|
|
96
|
+
(entries) => {
|
|
97
|
+
entries.forEach((entry) => {
|
|
98
|
+
if (typeof onVisibleChange === "function") {
|
|
99
|
+
onVisibleChange(entry.isIntersecting);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
root: view.scrollDOM,
|
|
105
|
+
threshold: 0
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
observer.observe(dom);
|
|
109
|
+
disposeVisibleWatcher = () => {
|
|
110
|
+
observer.disconnect();
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
onUnmounted2(() => {
|
|
114
|
+
if (typeof disposeVisibleWatcher === "function") {
|
|
115
|
+
disposeVisibleWatcher();
|
|
116
|
+
disposeVisibleWatcher = null;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
return {};
|
|
120
|
+
},
|
|
121
|
+
render() {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
export {
|
|
126
|
+
CursorMirror,
|
|
127
|
+
Placeholder,
|
|
128
|
+
SelectionSide
|
|
129
|
+
};
|
|
130
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/placeholder.ts","../../src/cursor-mirror.ts"],"sourcesContent":["// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nimport { h, defineComponent, onBeforeMount, onUnmounted, Teleport } from 'vue';\nimport { useInjector } from '@coze-editor/vue';\nimport { placeholder } from '@coze-editor/extension-placeholder';\n\nconst Placeholder = defineComponent({\n setup(_props, { slots }) {\n const element = document.createElement('span');\n\n const injector = useInjector();\n\n let eject: (() => void) | null = null;\n\n onBeforeMount(() => {\n eject = injector.inject([placeholder(() => element)]);\n });\n\n onUnmounted(() => {\n if (eject) {\n eject();\n }\n });\n\n return () =>\n h(Teleport, { to: element }, [\n slots.default ? slots.default() : undefined,\n ]);\n },\n});\n\nexport { Placeholder };\n","// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nimport {\n defineComponent,\n onBeforeMount,\n onMounted,\n onUnmounted,\n type PropType,\n} from 'vue';\nimport { autoUpdate } from '@floating-ui/dom';\nimport { type BuiltinEditorAPI } from '@coze-editor/vue';\nimport { useEditorRef, useInjector } from '@coze-editor/vue';\nimport {\n elementAtPosition,\n positionElementLayer,\n SelectionSide,\n} from '@coze-editor/extensions';\n\nconst CursorMirror = defineComponent({\n props: {\n side: String as PropType<SelectionSide>,\n onChange: Function as PropType<() => void>,\n onVisibleChange: Function as PropType<(visible: boolean) => void>,\n },\n\n setup({ side, onChange, onVisibleChange }, { expose }) {\n const injector = useInjector();\n const editor = useEditorRef<BuiltinEditorAPI>();\n const dom = document.createElement('div');\n\n expose({ element: dom });\n\n let eject: (() => void) | null = null;\n onBeforeMount(() => {\n eject = injector.inject([\n elementAtPosition.of({\n dom,\n pos: side!,\n }),\n positionElementLayer,\n ]);\n });\n onUnmounted(() => {\n if (typeof eject === 'function') {\n eject();\n }\n });\n\n // watch for position change\n let disposeUpdateWatcher: (() => void) | null = null;\n onMounted(() => {\n const floating = document.createElement('div');\n document.body.appendChild(floating);\n\n const dispose = autoUpdate(\n dom,\n floating,\n () => {\n if (typeof onChange === 'function') {\n onChange();\n }\n },\n { animationFrame: true },\n );\n\n disposeUpdateWatcher = () => {\n document.body.removeChild(floating);\n dispose();\n };\n });\n onUnmounted(() => {\n if (typeof disposeUpdateWatcher === 'function') {\n disposeUpdateWatcher();\n disposeUpdateWatcher = null;\n }\n });\n\n // watch for visible change\n let disposeVisibleWatcher: (() => void) | null = null;\n onMounted(() => {\n if (!editor) {\n return;\n }\n\n const view = editor.value!.$view;\n\n const observer = new IntersectionObserver(\n entries => {\n entries.forEach(entry => {\n if (typeof onVisibleChange === 'function') {\n onVisibleChange(entry.isIntersecting);\n }\n });\n },\n {\n root: view.scrollDOM,\n threshold: 0,\n },\n );\n\n observer.observe(dom);\n\n disposeVisibleWatcher = () => {\n observer.disconnect();\n };\n });\n onUnmounted(() => {\n if (typeof disposeVisibleWatcher === 'function') {\n disposeVisibleWatcher();\n disposeVisibleWatcher = null;\n }\n });\n\n return {};\n },\n\n render() {\n return null;\n },\n});\n\nexport { CursorMirror, SelectionSide };\n"],"mappings":";AAGA,SAAS,GAAG,iBAAiB,eAAe,aAAa,gBAAgB;AACzE,SA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
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { PropType } from 'vue';
|
|
3
|
+
import { SelectionSide } from '@coze-editor/extensions';
|
|
4
|
+
export { SelectionSide } from '@coze-editor/extensions';
|
|
5
|
+
|
|
6
|
+
declare const Placeholder: vue.DefineComponent<{}, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
9
|
+
|
|
10
|
+
declare const CursorMirror: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
11
|
+
side: PropType<SelectionSide>;
|
|
12
|
+
onChange: PropType<() => void>;
|
|
13
|
+
onVisibleChange: PropType<(visible: boolean) => void>;
|
|
14
|
+
}>, {}, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
15
|
+
side: PropType<SelectionSide>;
|
|
16
|
+
onChange: PropType<() => void>;
|
|
17
|
+
onVisibleChange: PropType<(visible: boolean) => void>;
|
|
18
|
+
}>> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
19
|
+
|
|
20
|
+
export { CursorMirror, Placeholder };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { PropType } from 'vue';
|
|
3
|
+
import { SelectionSide } from '@coze-editor/extensions';
|
|
4
|
+
export { SelectionSide } from '@coze-editor/extensions';
|
|
5
|
+
|
|
6
|
+
declare const Placeholder: vue.DefineComponent<{}, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
9
|
+
|
|
10
|
+
declare const CursorMirror: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
11
|
+
side: PropType<SelectionSide>;
|
|
12
|
+
onChange: PropType<() => void>;
|
|
13
|
+
onVisibleChange: PropType<(visible: boolean) => void>;
|
|
14
|
+
}>, {}, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
15
|
+
side: PropType<SelectionSide>;
|
|
16
|
+
onChange: PropType<() => void>;
|
|
17
|
+
onVisibleChange: PropType<(visible: boolean) => void>;
|
|
18
|
+
}>> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
19
|
+
|
|
20
|
+
export { CursorMirror, Placeholder };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/index.ts
|
|
20
|
+
var index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
22
|
+
CursorMirror: () => CursorMirror,
|
|
23
|
+
Placeholder: () => Placeholder,
|
|
24
|
+
SelectionSide: () => import_extensions.SelectionSide
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/placeholder.ts
|
|
29
|
+
var import_vue = require("vue");
|
|
30
|
+
var import_vue2 = require("@coze-editor/vue");
|
|
31
|
+
var import_extension_placeholder = require("@coze-editor/extension-placeholder");
|
|
32
|
+
var Placeholder = (0, import_vue.defineComponent)({
|
|
33
|
+
setup(_props, { slots }) {
|
|
34
|
+
const element = document.createElement("span");
|
|
35
|
+
const injector = (0, import_vue2.useInjector)();
|
|
36
|
+
let eject = null;
|
|
37
|
+
(0, import_vue.onBeforeMount)(() => {
|
|
38
|
+
eject = injector.inject([(0, import_extension_placeholder.placeholder)(() => element)]);
|
|
39
|
+
});
|
|
40
|
+
(0, import_vue.onUnmounted)(() => {
|
|
41
|
+
if (eject) {
|
|
42
|
+
eject();
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return () => (0, import_vue.h)(import_vue.Teleport, { to: element }, [
|
|
46
|
+
slots.default ? slots.default() : void 0
|
|
47
|
+
]);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// src/cursor-mirror.ts
|
|
52
|
+
var import_vue3 = require("vue");
|
|
53
|
+
var import_dom = require("@floating-ui/dom");
|
|
54
|
+
var import_vue4 = require("@coze-editor/vue");
|
|
55
|
+
var import_extensions = require("@coze-editor/extensions");
|
|
56
|
+
var CursorMirror = (0, import_vue3.defineComponent)({
|
|
57
|
+
props: {
|
|
58
|
+
side: String,
|
|
59
|
+
onChange: Function,
|
|
60
|
+
onVisibleChange: Function
|
|
61
|
+
},
|
|
62
|
+
setup({ side, onChange, onVisibleChange }, { expose }) {
|
|
63
|
+
const injector = (0, import_vue4.useInjector)();
|
|
64
|
+
const editor = (0, import_vue4.useEditorRef)();
|
|
65
|
+
const dom = document.createElement("div");
|
|
66
|
+
expose({ element: dom });
|
|
67
|
+
let eject = null;
|
|
68
|
+
(0, import_vue3.onBeforeMount)(() => {
|
|
69
|
+
eject = injector.inject([
|
|
70
|
+
import_extensions.elementAtPosition.of({
|
|
71
|
+
dom,
|
|
72
|
+
pos: side
|
|
73
|
+
}),
|
|
74
|
+
import_extensions.positionElementLayer
|
|
75
|
+
]);
|
|
76
|
+
});
|
|
77
|
+
(0, import_vue3.onUnmounted)(() => {
|
|
78
|
+
if (typeof eject === "function") {
|
|
79
|
+
eject();
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
let disposeUpdateWatcher = null;
|
|
83
|
+
(0, import_vue3.onMounted)(() => {
|
|
84
|
+
const floating = document.createElement("div");
|
|
85
|
+
document.body.appendChild(floating);
|
|
86
|
+
const dispose = (0, import_dom.autoUpdate)(
|
|
87
|
+
dom,
|
|
88
|
+
floating,
|
|
89
|
+
() => {
|
|
90
|
+
if (typeof onChange === "function") {
|
|
91
|
+
onChange();
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
{ animationFrame: true }
|
|
95
|
+
);
|
|
96
|
+
disposeUpdateWatcher = () => {
|
|
97
|
+
document.body.removeChild(floating);
|
|
98
|
+
dispose();
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
(0, import_vue3.onUnmounted)(() => {
|
|
102
|
+
if (typeof disposeUpdateWatcher === "function") {
|
|
103
|
+
disposeUpdateWatcher();
|
|
104
|
+
disposeUpdateWatcher = null;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
let disposeVisibleWatcher = null;
|
|
108
|
+
(0, import_vue3.onMounted)(() => {
|
|
109
|
+
if (!editor) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const view = editor.value.$view;
|
|
113
|
+
const observer = new IntersectionObserver(
|
|
114
|
+
(entries) => {
|
|
115
|
+
entries.forEach((entry) => {
|
|
116
|
+
if (typeof onVisibleChange === "function") {
|
|
117
|
+
onVisibleChange(entry.isIntersecting);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
root: view.scrollDOM,
|
|
123
|
+
threshold: 0
|
|
124
|
+
}
|
|
125
|
+
);
|
|
126
|
+
observer.observe(dom);
|
|
127
|
+
disposeVisibleWatcher = () => {
|
|
128
|
+
observer.disconnect();
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
(0, import_vue3.onUnmounted)(() => {
|
|
132
|
+
if (typeof disposeVisibleWatcher === "function") {
|
|
133
|
+
disposeVisibleWatcher();
|
|
134
|
+
disposeVisibleWatcher = null;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
return {};
|
|
138
|
+
},
|
|
139
|
+
render() {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
144
|
+
0 && (module.exports = {
|
|
145
|
+
CursorMirror,
|
|
146
|
+
Placeholder,
|
|
147
|
+
SelectionSide
|
|
148
|
+
});
|
|
149
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/placeholder.ts","../src/cursor-mirror.ts"],"sourcesContent":["// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nexport { Placeholder } from './placeholder';\n\nexport { CursorMirror, SelectionSide } from './cursor-mirror';\n","// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nimport { h, defineComponent, onBeforeMount, onUnmounted, Teleport } from 'vue';\nimport { useInjector } from '@coze-editor/vue';\nimport { placeholder } from '@coze-editor/extension-placeholder';\n\nconst Placeholder = defineComponent({\n setup(_props, { slots }) {\n const element = document.createElement('span');\n\n const injector = useInjector();\n\n let eject: (() => void) | null = null;\n\n onBeforeMount(() => {\n eject = injector.inject([placeholder(() => element)]);\n });\n\n onUnmounted(() => {\n if (eject) {\n eject();\n }\n });\n\n return () =>\n h(Teleport, { to: element }, [\n slots.default ? slots.default() : undefined,\n ]);\n },\n});\n\nexport { Placeholder };\n","// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nimport {\n defineComponent,\n onBeforeMount,\n onMounted,\n onUnmounted,\n type PropType,\n} from 'vue';\nimport { autoUpdate } from '@floating-ui/dom';\nimport { type BuiltinEditorAPI } from '@coze-editor/vue';\nimport { useEditorRef, useInjector } from '@coze-editor/vue';\nimport {\n elementAtPosition,\n positionElementLayer,\n SelectionSide,\n} from '@coze-editor/extensions';\n\nconst CursorMirror = defineComponent({\n props: {\n side: String as PropType<SelectionSide>,\n onChange: Function as PropType<() => void>,\n onVisibleChange: Function as PropType<(visible: boolean) => void>,\n },\n\n setup({ side, onChange, onVisibleChange }, { expose }) {\n const injector = useInjector();\n const editor = useEditorRef<BuiltinEditorAPI>();\n const dom = document.createElement('div');\n\n expose({ element: dom });\n\n let eject: (() => void) | null = null;\n onBeforeMount(() => {\n eject = injector.inject([\n elementAtPosition.of({\n dom,\n pos: side!,\n }),\n positionElementLayer,\n ]);\n });\n onUnmounted(() => {\n if (typeof eject === 'function') {\n eject();\n }\n });\n\n // watch for position change\n let disposeUpdateWatcher: (() => void) | null = null;\n onMounted(() => {\n const floating = document.createElement('div');\n document.body.appendChild(floating);\n\n const dispose = autoUpdate(\n dom,\n floating,\n () => {\n if (typeof onChange === 'function') {\n onChange();\n }\n },\n { animationFrame: true },\n );\n\n disposeUpdateWatcher = () => {\n document.body.removeChild(floating);\n dispose();\n };\n });\n onUnmounted(() => {\n if (typeof disposeUpdateWatcher === 'function') {\n disposeUpdateWatcher();\n disposeUpdateWatcher = null;\n }\n });\n\n // watch for visible change\n let disposeVisibleWatcher: (() => void) | null = null;\n onMounted(() => {\n if (!editor) {\n return;\n }\n\n const view = editor.value!.$view;\n\n const observer = new IntersectionObserver(\n entries => {\n entries.forEach(entry => {\n if (typeof onVisibleChange === 'function') {\n onVisibleChange(entry.isIntersecting);\n }\n });\n },\n {\n root: view.scrollDOM,\n threshold: 0,\n },\n );\n\n observer.observe(dom);\n\n disposeVisibleWatcher = () => {\n observer.disconnect();\n };\n });\n onUnmounted(() => {\n if (typeof disposeVisibleWatcher === 'function') {\n disposeVisibleWatcher();\n disposeVisibleWatcher = null;\n }\n });\n\n return {};\n },\n\n render() {\n return null;\n },\n});\n\nexport { CursorMirror, SelectionSide };\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,iBAAyE;AACzE,IAAAA,cAA4B;AAC5B,mCAA4B;AAE5B,IAAM,kBAAc,4BAAgB;AAAA,EAClC,MAAM,QAAQ,EAAE,MAAM,GAAG;AACvB,UAAM,UAAU,SAAS,cAAc,MAAM;AAE7C,UAAM,eAAW,yBAAY;AAE7B,QAAI,QAA6B;AAEjC,kCAAc,MAAM;AAClB,cAAQ,SAAS,OAAO,KAAC,0CAAY,MAAM,OAAO,CAAC,CAAC;AAAA,IACtD,CAAC;AAED,gCAAY,MAAM;AAChB,UAAI,OAAO;AACT,cAAM;AAAA,MACR;AAAA,IACF,CAAC;AAED,WAAO,UACL,cAAE,qBAAU,EAAE,IAAI,QAAQ,GAAG;AAAA,MAC3B,MAAM,UAAU,MAAM,QAAQ,IAAI;AAAA,IACpC,CAAC;AAAA,EACL;AACF,CAAC;;;AC3BD,IAAAC,cAMO;AACP,iBAA2B;AAE3B,IAAAA,cAA0C;AAC1C,wBAIO;AAEP,IAAM,mBAAe,6BAAgB;AAAA,EACnC,OAAO;AAAA,IACL,MAAM;AAAA,IACN,UAAU;AAAA,IACV,iBAAiB;AAAA,EACnB;AAAA,EAEA,MAAM,EAAE,MAAM,UAAU,gBAAgB,GAAG,EAAE,OAAO,GAAG;AACrD,UAAM,eAAW,yBAAY;AAC7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AwB,MAAM;AAC5B,iBAAS,WAAW;AAAA,MACtB;AAAA,IACF,CAAC;AACD,iCAAY,MAAM;AAChB,UAAI,OAAO,0BAA0B,YAAY;AAC/C,8BAAsB;AACtB,gCAAwB;AAAA,MAC1B;AAAA,IACF,CAAC;AAED,WAAO,CAAC;AAAA,EACV;AAAA,EAEA,SAAS;AACP,WAAO;AAAA,EACT;AACF,CAAC;","names":["import_vue","import_vue"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@coze-editor/vue-components",
|
|
3
|
+
"version": "0.1.0-alpha.09ffeb",
|
|
4
|
+
"description": "vue-components",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "fengzilong",
|
|
7
|
+
"maintainers": [],
|
|
8
|
+
"sideEffects": [
|
|
9
|
+
"**/*.css",
|
|
10
|
+
"**/*.less",
|
|
11
|
+
"**/*.sass",
|
|
12
|
+
"**/*.scss"
|
|
13
|
+
],
|
|
14
|
+
"main": "./dist/esm/index.js",
|
|
15
|
+
"module": "./dist/esm/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsup",
|
|
22
|
+
"lint": "eslint && tsc --noEmit"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@coze-editor/extension-placeholder": "0.1.0-alpha.09ffeb",
|
|
26
|
+
"@coze-editor/extensions": "0.1.0-alpha.09ffeb",
|
|
27
|
+
"@coze-editor/utils": "0.1.0-alpha.09ffeb",
|
|
28
|
+
"@floating-ui/dom": "^1.6.3"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@codemirror/state": "^6.4.1",
|
|
32
|
+
"@codemirror/view": "^6.26.1",
|
|
33
|
+
"@coze-arch/ts-config": "workspace:*",
|
|
34
|
+
"@coze-editor/eslint-config": "workspace:*",
|
|
35
|
+
"@coze-editor/vue": "workspace:*",
|
|
36
|
+
"@types/node": "^22",
|
|
37
|
+
"eslint": "9.14.0",
|
|
38
|
+
"tsup": "^8.0.1",
|
|
39
|
+
"typescript": "^5.8.2",
|
|
40
|
+
"vue": "^3.5.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@codemirror/state": "^6.4.1",
|
|
44
|
+
"@codemirror/view": "^6.26.1",
|
|
45
|
+
"@coze-editor/vue": "0.1.0-alpha.09ffeb",
|
|
46
|
+
"vue": "^3.5.0"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public",
|
|
50
|
+
"registry": "https://registry.npmjs.org"
|
|
51
|
+
},
|
|
52
|
+
"test:main": "./src/index.ts"
|
|
53
|
+
}
|