@coze-editor/react-merge 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 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,103 @@
1
+ // src/renderer.tsx
2
+ import React, {
3
+ useRef,
4
+ useEffect
5
+ } from "react";
6
+ import {
7
+ create,
8
+ useInjector
9
+ } from "@coze-editor/react";
10
+ import { MergeView } from "@codemirror/merge";
11
+ function MergeViewRenderer(props) {
12
+ const {
13
+ plugins,
14
+ mergeConfig,
15
+ a,
16
+ b,
17
+ domProps = {},
18
+ didMount,
19
+ children
20
+ } = props;
21
+ const ref = useRef(null);
22
+ const apiRef = useRef(null);
23
+ const propsRef = useRef(null);
24
+ const injector = useInjector();
25
+ const mergeConfigRef = useRef(mergeConfig);
26
+ const aRef = useRef(a);
27
+ const bRef = useRef(b);
28
+ aRef.current = a;
29
+ bRef.current = b;
30
+ propsRef.current = props;
31
+ useEffect(() => {
32
+ const a2 = aRef.current;
33
+ const b2 = bRef.current;
34
+ const config = mergeConfigRef.current ?? {};
35
+ const { getExtensions, createAPI, createOptions, createEvents } = create({
36
+ plugins,
37
+ injector
38
+ });
39
+ const aOptions = createOptions();
40
+ const aEvents = createEvents();
41
+ const bOptions = createOptions();
42
+ const bEvents = createEvents();
43
+ const mergeView = new MergeView({
44
+ ...config,
45
+ a: {
46
+ doc: a2.defaultValue ?? "",
47
+ extensions: [
48
+ ...getExtensions(a2.options ?? {}, {
49
+ options: aOptions,
50
+ events: aEvents
51
+ }),
52
+ ...a2.extensions ?? []
53
+ ]
54
+ },
55
+ b: {
56
+ doc: b2.defaultValue ?? "",
57
+ extensions: [
58
+ ...getExtensions(b2.options ?? {}, {
59
+ options: bOptions,
60
+ events: bEvents
61
+ }),
62
+ ...b2.extensions ?? []
63
+ ]
64
+ },
65
+ parent: ref.current
66
+ });
67
+ const aAPI = createAPI({
68
+ view: mergeView.a,
69
+ options: aOptions,
70
+ events: aEvents
71
+ });
72
+ const bAPI = createAPI({
73
+ view: mergeView.b,
74
+ options: bOptions,
75
+ events: bEvents
76
+ });
77
+ apiRef.current = {
78
+ a: aAPI,
79
+ b: bAPI
80
+ };
81
+ if (typeof didMount === "function") {
82
+ didMount({ a: aAPI, b: bAPI });
83
+ }
84
+ return () => {
85
+ aAPI.$destroy();
86
+ bAPI.$destroy();
87
+ mergeView.destroy();
88
+ };
89
+ }, []);
90
+ useEffect(() => {
91
+ var _a;
92
+ (_a = apiRef.current) == null ? void 0 : _a.a.$set(props.a.options ?? {});
93
+ }, [props.a.options]);
94
+ useEffect(() => {
95
+ var _a;
96
+ (_a = apiRef.current) == null ? void 0 : _a.b.$set(props.b.options ?? {});
97
+ }, [props.b.options]);
98
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { ...domProps, ref }), children);
99
+ }
100
+ export {
101
+ MergeViewRenderer
102
+ };
103
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/renderer.tsx"],"sourcesContent":["// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nimport React, {\n useRef,\n useEffect,\n type CSSProperties,\n type ReactNode,\n} from 'react';\n\nimport {\n // from core\n create,\n type EditorPluginSpec,\n type InferEditorAPIFromPlugins,\n type InferValues,\n // from react\n useInjector,\n} from '@coze-editor/react';\nimport { type Extension } from '@codemirror/state';\nimport { type MergeConfig, MergeView } from '@codemirror/merge';\n\ninterface SingleEditorProps<T extends EditorPluginSpec<string, any, any>[]> {\n defaultValue?: string;\n options?: Partial<InferValues<T[number]>>;\n extensions?: Extension[];\n}\ninterface InferRendererProps<T extends EditorPluginSpec<string, any, any>[]> {\n domProps?: {\n style?: CSSProperties;\n className?: string;\n };\n mergeConfig?: MergeConfig;\n a: SingleEditorProps<T>;\n b: SingleEditorProps<T>;\n didMount?: (e: {\n a: InferEditorAPIFromPlugins<T>;\n b: InferEditorAPIFromPlugins<T>;\n }) => void;\n children?: ReactNode;\n}\n\nfunction MergeViewRenderer<T extends EditorPluginSpec<string, any, any>[]>(\n props: { plugins: T } & InferRendererProps<T>,\n) {\n const {\n plugins,\n mergeConfig,\n a,\n b,\n domProps = {},\n didMount,\n children,\n } = props;\n\n const ref = useRef(null);\n const apiRef = useRef<any>(null);\n const propsRef = useRef<any>(null);\n const injector = useInjector();\n const mergeConfigRef = useRef(mergeConfig);\n const aRef = useRef(a);\n const bRef = useRef(b);\n\n aRef.current = a;\n bRef.current = b;\n propsRef.current = props;\n\n useEffect(() => {\n const a = aRef.current;\n const b = bRef.current;\n const config = mergeConfigRef.current ?? {};\n\n const { getExtensions, createAPI, createOptions, createEvents } = create({\n plugins,\n injector,\n });\n\n const aOptions = createOptions();\n const aEvents = createEvents();\n\n const bOptions = createOptions();\n const bEvents = createEvents();\n\n const mergeView = new MergeView({\n ...config,\n a: {\n doc: a.defaultValue ?? '',\n extensions: [\n ...getExtensions(a.options ?? {}, {\n options: aOptions,\n events: aEvents,\n }),\n ...(a.extensions ?? []),\n ],\n },\n b: {\n doc: b.defaultValue ?? '',\n extensions: [\n ...getExtensions(b.options ?? {}, {\n options: bOptions,\n events: bEvents,\n }),\n ...(b.extensions ?? []),\n ],\n },\n parent: ref.current!,\n });\n\n const aAPI = createAPI({\n view: mergeView.a,\n options: aOptions,\n events: aEvents,\n });\n\n const bAPI = createAPI({\n view: mergeView.b,\n options: bOptions,\n events: bEvents,\n });\n\n apiRef.current = {\n a: aAPI,\n b: bAPI,\n };\n\n if (typeof didMount === 'function') {\n didMount({ a: aAPI, b: bAPI });\n }\n\n return () => {\n aAPI.$destroy();\n bAPI.$destroy();\n mergeView.destroy();\n };\n }, []);\n\n useEffect(() => {\n apiRef.current?.a.$set(props.a.options ?? {});\n }, [props.a.options]);\n\n useEffect(() => {\n apiRef.current?.b.$set(props.b.options ?? {});\n }, [props.b.options]);\n\n return (\n <>\n <div {...domProps} ref={ref} />\n {children}\n </>\n );\n}\n\nexport { MergeViewRenderer };\n"],"mappings":";AAGA,OAAO;AAAA,EACL;AAAA,EACA;AAAA,OAGK;AAEP;AAAA,EAEE;AAAA,EAKA;AAAA,OACK;AAEP,SAA2B,iBAAiB;AAsB5C,SAAS,kBACP,OACA;AACA,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW,CAAC;AAAA,IACZ;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,QAAM,MAAM,OAAO,IAAI;AACvB,QAAM,SAAS,OAAY,IAAI;AAC/B,QAAM,WAAW,OAAY,IAAI;AACjC,QAAM,WAAW,YAAY;AAC7B,QAAM,iBAAiB,OAAO,WAAW;AACzC,QAAM,OAAO,OAAO,CAAC;AACrB,QAAM,OAAO,OAAO,CAAC;AAErB,OAAK,UAAU;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A,WAAO,MAAM;AACX,WAAK,SAAS;AACd,WAAK,SAAS;AACd,gBAAU,QAAQ;AAAA,IACpB;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,YAAU,MAAM;AAxIlB;AAyII,iBAAO,YAAP,mBAAgB,EAAE,KAAK,MAAM,EAAE,WAAW,CAAC;AAAA,EAC7C,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;AAEpB,YAAU,MAAM;AA5IlB;AA6II,iBAAO,YAAP,mBAAgB,EAAE,KAAK,MAAM,EAAE,WAAW,CAAC;AAAA,EAC7C,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;AAEpB,SACE,0DACE,oCAAC,SAAK,GAAG,UAAU,KAAU,GAC5B,QACH;AAEJ;","names":["a","b"]}
@@ -0,0 +1,30 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { CSSProperties, ReactNode } from 'react';
3
+ import { EditorPluginSpec, InferValues, InferEditorAPIFromPlugins } from '@coze-editor/react';
4
+ import { Extension } from '@codemirror/state';
5
+ import { MergeConfig } from '@codemirror/merge';
6
+
7
+ interface SingleEditorProps<T extends EditorPluginSpec<string, any, any>[]> {
8
+ defaultValue?: string;
9
+ options?: Partial<InferValues<T[number]>>;
10
+ extensions?: Extension[];
11
+ }
12
+ interface InferRendererProps<T extends EditorPluginSpec<string, any, any>[]> {
13
+ domProps?: {
14
+ style?: CSSProperties;
15
+ className?: string;
16
+ };
17
+ mergeConfig?: MergeConfig;
18
+ a: SingleEditorProps<T>;
19
+ b: SingleEditorProps<T>;
20
+ didMount?: (e: {
21
+ a: InferEditorAPIFromPlugins<T>;
22
+ b: InferEditorAPIFromPlugins<T>;
23
+ }) => void;
24
+ children?: ReactNode;
25
+ }
26
+ declare function MergeViewRenderer<T extends EditorPluginSpec<string, any, any>[]>(props: {
27
+ plugins: T;
28
+ } & InferRendererProps<T>): react_jsx_runtime.JSX.Element;
29
+
30
+ export { MergeViewRenderer };
@@ -0,0 +1,30 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { CSSProperties, ReactNode } from 'react';
3
+ import { EditorPluginSpec, InferValues, InferEditorAPIFromPlugins } from '@coze-editor/react';
4
+ import { Extension } from '@codemirror/state';
5
+ import { MergeConfig } from '@codemirror/merge';
6
+
7
+ interface SingleEditorProps<T extends EditorPluginSpec<string, any, any>[]> {
8
+ defaultValue?: string;
9
+ options?: Partial<InferValues<T[number]>>;
10
+ extensions?: Extension[];
11
+ }
12
+ interface InferRendererProps<T extends EditorPluginSpec<string, any, any>[]> {
13
+ domProps?: {
14
+ style?: CSSProperties;
15
+ className?: string;
16
+ };
17
+ mergeConfig?: MergeConfig;
18
+ a: SingleEditorProps<T>;
19
+ b: SingleEditorProps<T>;
20
+ didMount?: (e: {
21
+ a: InferEditorAPIFromPlugins<T>;
22
+ b: InferEditorAPIFromPlugins<T>;
23
+ }) => void;
24
+ children?: ReactNode;
25
+ }
26
+ declare function MergeViewRenderer<T extends EditorPluginSpec<string, any, any>[]>(props: {
27
+ plugins: T;
28
+ } & InferRendererProps<T>): react_jsx_runtime.JSX.Element;
29
+
30
+ export { MergeViewRenderer };
package/dist/index.js ADDED
@@ -0,0 +1,133 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/index.ts
30
+ var index_exports = {};
31
+ __export(index_exports, {
32
+ MergeViewRenderer: () => MergeViewRenderer
33
+ });
34
+ module.exports = __toCommonJS(index_exports);
35
+
36
+ // src/renderer.tsx
37
+ var import_react = __toESM(require("react"));
38
+ var import_react2 = require("@coze-editor/react");
39
+ var import_merge = require("@codemirror/merge");
40
+ function MergeViewRenderer(props) {
41
+ const {
42
+ plugins,
43
+ mergeConfig,
44
+ a,
45
+ b,
46
+ domProps = {},
47
+ didMount,
48
+ children
49
+ } = props;
50
+ const ref = (0, import_react.useRef)(null);
51
+ const apiRef = (0, import_react.useRef)(null);
52
+ const propsRef = (0, import_react.useRef)(null);
53
+ const injector = (0, import_react2.useInjector)();
54
+ const mergeConfigRef = (0, import_react.useRef)(mergeConfig);
55
+ const aRef = (0, import_react.useRef)(a);
56
+ const bRef = (0, import_react.useRef)(b);
57
+ aRef.current = a;
58
+ bRef.current = b;
59
+ propsRef.current = props;
60
+ (0, import_react.useEffect)(() => {
61
+ const a2 = aRef.current;
62
+ const b2 = bRef.current;
63
+ const config = mergeConfigRef.current ?? {};
64
+ const { getExtensions, createAPI, createOptions, createEvents } = (0, import_react2.create)({
65
+ plugins,
66
+ injector
67
+ });
68
+ const aOptions = createOptions();
69
+ const aEvents = createEvents();
70
+ const bOptions = createOptions();
71
+ const bEvents = createEvents();
72
+ const mergeView = new import_merge.MergeView({
73
+ ...config,
74
+ a: {
75
+ doc: a2.defaultValue ?? "",
76
+ extensions: [
77
+ ...getExtensions(a2.options ?? {}, {
78
+ options: aOptions,
79
+ events: aEvents
80
+ }),
81
+ ...a2.extensions ?? []
82
+ ]
83
+ },
84
+ b: {
85
+ doc: b2.defaultValue ?? "",
86
+ extensions: [
87
+ ...getExtensions(b2.options ?? {}, {
88
+ options: bOptions,
89
+ events: bEvents
90
+ }),
91
+ ...b2.extensions ?? []
92
+ ]
93
+ },
94
+ parent: ref.current
95
+ });
96
+ const aAPI = createAPI({
97
+ view: mergeView.a,
98
+ options: aOptions,
99
+ events: aEvents
100
+ });
101
+ const bAPI = createAPI({
102
+ view: mergeView.b,
103
+ options: bOptions,
104
+ events: bEvents
105
+ });
106
+ apiRef.current = {
107
+ a: aAPI,
108
+ b: bAPI
109
+ };
110
+ if (typeof didMount === "function") {
111
+ didMount({ a: aAPI, b: bAPI });
112
+ }
113
+ return () => {
114
+ aAPI.$destroy();
115
+ bAPI.$destroy();
116
+ mergeView.destroy();
117
+ };
118
+ }, []);
119
+ (0, import_react.useEffect)(() => {
120
+ var _a;
121
+ (_a = apiRef.current) == null ? void 0 : _a.a.$set(props.a.options ?? {});
122
+ }, [props.a.options]);
123
+ (0, import_react.useEffect)(() => {
124
+ var _a;
125
+ (_a = apiRef.current) == null ? void 0 : _a.b.$set(props.b.options ?? {});
126
+ }, [props.b.options]);
127
+ return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("div", { ...domProps, ref }), children);
128
+ }
129
+ // Annotate the CommonJS export names for ESM import in node:
130
+ 0 && (module.exports = {
131
+ MergeViewRenderer
132
+ });
133
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/renderer.tsx"],"sourcesContent":["// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nexport { MergeViewRenderer } from './renderer';\n","// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nimport React, {\n useRef,\n useEffect,\n type CSSProperties,\n type ReactNode,\n} from 'react';\n\nimport {\n // from core\n create,\n type EditorPluginSpec,\n type InferEditorAPIFromPlugins,\n type InferValues,\n // from react\n useInjector,\n} from '@coze-editor/react';\nimport { type Extension } from '@codemirror/state';\nimport { type MergeConfig, MergeView } from '@codemirror/merge';\n\ninterface SingleEditorProps<T extends EditorPluginSpec<string, any, any>[]> {\n defaultValue?: string;\n options?: Partial<InferValues<T[number]>>;\n extensions?: Extension[];\n}\ninterface InferRendererProps<T extends EditorPluginSpec<string, any, any>[]> {\n domProps?: {\n style?: CSSProperties;\n className?: string;\n };\n mergeConfig?: MergeConfig;\n a: SingleEditorProps<T>;\n b: SingleEditorProps<T>;\n didMount?: (e: {\n a: InferEditorAPIFromPlugins<T>;\n b: InferEditorAPIFromPlugins<T>;\n }) => void;\n children?: ReactNode;\n}\n\nfunction MergeViewRenderer<T extends EditorPluginSpec<string, any, any>[]>(\n props: { plugins: T } & InferRendererProps<T>,\n) {\n const {\n plugins,\n mergeConfig,\n a,\n b,\n domProps = {},\n didMount,\n children,\n } = props;\n\n const ref = useRef(null);\n const apiRef = useRef<any>(null);\n const propsRef = useRef<any>(null);\n const injector = useInjector();\n const mergeConfigRef = useRef(mergeConfig);\n const aRef = useRef(a);\n const bRef = useRef(b);\n\n aRef.current = a;\n bRef.current = b;\n propsRef.current = props;\n\n useEffect(() => {\n const a = aRef.current;\n const b = bRef.current;\n const config = mergeConfigRef.current ?? {};\n\n const { getExtensions, createAPI, createOptions, createEvents } = create({\n plugins,\n injector,\n });\n\n const aOptions = createOptions();\n const aEvents = createEvents();\n\n const bOptions = createOptions();\n const bEvents = createEvents();\n\n const mergeView = new MergeView({\n ...config,\n a: {\n doc: a.defaultValue ?? '',\n extensions: [\n ...getExtensions(a.options ?? {}, {\n options: aOptions,\n events: aEvents,\n }),\n ...(a.extensions ?? []),\n ],\n },\n b: {\n doc: b.defaultValue ?? '',\n extensions: [\n ...getExtensions(b.options ?? {}, {\n options: bOptions,\n events: bEvents,\n }),\n ...(b.extensions ?? []),\n ],\n },\n parent: ref.current!,\n });\n\n const aAPI = createAPI({\n view: mergeView.a,\n options: aOptions,\n events: aEvents,\n });\n\n const bAPI = createAPI({\n view: mergeView.b,\n options: bOptions,\n events: bEvents,\n });\n\n apiRef.current = {\n a: aAPI,\n b: bAPI,\n };\n\n if (typeof didMount === 'function') {\n didMount({ a: aAPI, b: bAPI });\n }\n\n return () => {\n aAPI.$destroy();\n bAPI.$destroy();\n mergeView.destroy();\n };\n }, []);\n\n useEffect(() => {\n apiRef.current?.a.$set(props.a.options ?? {});\n }, [props.a.options]);\n\n useEffect(() => {\n apiRef.current?.b.$set(props.b.options ?? {});\n }, [props.b.options]);\n\n return (\n <>\n <div {...domProps} ref={ref} />\n {children}\n </>\n );\n}\n\nexport { MergeViewRenderer };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,mBAKO;AAEP,IAAAA,gBAQO;AAEP,mBAA4C;AAsB5C,SAAS,kBACP,OACA;AACA,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW,CAAC;AAAA,IACZ;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,QAAM,UAAM,qBAAO,IAAI;AACvB,QAAM,aAAS,qBAAY,IAAI;AAC/B,QAAM,eAAW,qBAAY,IAAI;AACjC,QAAM,eAAW,2BAAY;AAC7B,QAAM,qBAAiB,qBAAO,WAAW;AACzC,QAAM,WAAO,qBAAO,CAAC;AACrB,QAAM,WAAO,qBAAO,CAAC;AAErB,OAAK,UAAU;AACf,OAAK,UAAU;AACf,WAAS,UAAU;AAEnB,8BAAU,MAAM;AACd,UAAMC,KAAI,KAAK;AACf,UAAMC,KAAI,KAAK;AACf,UAAM,SAAS,eAAe,WAAW,CAAC;AAE1C,UAAM,EAAE,eAAe,WAAW,eAAe,aAAa,QAAI,sBAAO;AAAA,MACv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AAAA,EAC7C,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;AAEpB,8BAAU,MAAM;AA5IlB;AA6II,iBAAO,YAAP,mBAAgB,EAAE,KAAK,MAAM,EAAE,WAAW,CAAC;AAAA,EAC7C,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;AAEpB,SACE,6BAAAC,QAAA,2BAAAA,QAAA,gBACE,6BAAAA,QAAA,cAAC,SAAK,GAAG,UAAU,KAAU,GAC5B,QACH;AAEJ;","names":["import_react","a","b","React"]}
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@coze-editor/react-merge",
3
+ "version": "0.1.0-alpha.09ffeb",
4
+ "description": "react merge",
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
+ "dev": "vite --force",
23
+ "lint": "eslint && tsc --noEmit"
24
+ },
25
+ "dependencies": {},
26
+ "devDependencies": {
27
+ "@codemirror/merge": "^6.10.0",
28
+ "@codemirror/state": "^6.4.1",
29
+ "@codemirror/view": "^6.26.1",
30
+ "@coze-arch/ts-config": "workspace:*",
31
+ "@coze-editor/eslint-config": "workspace:*",
32
+ "@coze-editor/react": "workspace:*",
33
+ "@types/node": "^22",
34
+ "@types/react": "18.2.37",
35
+ "@types/react-dom": "18.2.15",
36
+ "eslint": "9.14.0",
37
+ "react": "~18.2.0",
38
+ "react-dom": "~18.2.0",
39
+ "tsup": "^8.0.1",
40
+ "typescript": "^5.8.2"
41
+ },
42
+ "peerDependencies": {
43
+ "@codemirror/merge": "^6.10.0",
44
+ "@codemirror/state": "^6.4.1",
45
+ "@codemirror/view": "^6.26.1",
46
+ "@coze-editor/react": "0.1.0-alpha.09ffeb",
47
+ "react": ">=16.8",
48
+ "react-dom": ">=16.8"
49
+ },
50
+ "packageManager": "pnpm@9.15.0",
51
+ "publishConfig": {
52
+ "access": "public",
53
+ "registry": "https://registry.npmjs.org"
54
+ },
55
+ "test:main": "./src/index.ts"
56
+ }