@coze-editor/extension-regexp-decorator 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 +110 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +124 -0
- package/dist/index.js.map +1 -0
- package/package.json +43 -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,110 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import {
|
|
3
|
+
Decoration,
|
|
4
|
+
EditorView,
|
|
5
|
+
keymap,
|
|
6
|
+
MatchDecorator,
|
|
7
|
+
ViewPlugin
|
|
8
|
+
} from "@codemirror/view";
|
|
9
|
+
import {
|
|
10
|
+
EditorSelection,
|
|
11
|
+
Prec,
|
|
12
|
+
StateEffect
|
|
13
|
+
} from "@codemirror/state";
|
|
14
|
+
var updateEffect = StateEffect.define();
|
|
15
|
+
function regexpDecorator(options) {
|
|
16
|
+
const decorator = new MatchDecorator(options);
|
|
17
|
+
const plugin = ViewPlugin.fromClass(
|
|
18
|
+
class {
|
|
19
|
+
constructor(view) {
|
|
20
|
+
this.view = view;
|
|
21
|
+
this.decorations = decorator.createDeco(view);
|
|
22
|
+
}
|
|
23
|
+
decorations;
|
|
24
|
+
update(update) {
|
|
25
|
+
const hasUpdateEffect = update.transactions.some(
|
|
26
|
+
(tr) => tr.effects.some((effect) => effect.is(updateEffect))
|
|
27
|
+
);
|
|
28
|
+
if (hasUpdateEffect || update.selectionSet) {
|
|
29
|
+
this.decorations = decorator.createDeco(update.view);
|
|
30
|
+
} else if (update.docChanged) {
|
|
31
|
+
this.decorations = decorator.updateDeco(update, this.decorations);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
provide(plugin2) {
|
|
37
|
+
return [
|
|
38
|
+
EditorView.decorations.of(
|
|
39
|
+
(view) => {
|
|
40
|
+
var _a;
|
|
41
|
+
return ((_a = view.plugin(plugin2)) == null ? void 0 : _a.decorations) ?? Decoration.none;
|
|
42
|
+
}
|
|
43
|
+
),
|
|
44
|
+
EditorView.atomicRanges.of((view) => {
|
|
45
|
+
const p = view.plugin(plugin2);
|
|
46
|
+
if (!p) {
|
|
47
|
+
return Decoration.none;
|
|
48
|
+
}
|
|
49
|
+
return p.decorations.update({
|
|
50
|
+
filter(from, to, value) {
|
|
51
|
+
return Boolean(value.spec.atomicRange);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
})
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
function runnable(side) {
|
|
60
|
+
return function run(view) {
|
|
61
|
+
var _a;
|
|
62
|
+
const { head, anchor } = view.state.selection.main;
|
|
63
|
+
if (head !== anchor) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
const decorations = ((_a = view.plugin(plugin)) == null ? void 0 : _a.decorations) ?? Decoration.none;
|
|
67
|
+
let handled = false;
|
|
68
|
+
decorations.between(0, view.state.doc.length, (from, to, value) => {
|
|
69
|
+
const pos = side === "from" ? from : to;
|
|
70
|
+
if (pos === head && value.spec.selectable) {
|
|
71
|
+
handled = true;
|
|
72
|
+
view.dispatch({
|
|
73
|
+
selection: side === "to" ? EditorSelection.range(to, from) : EditorSelection.range(from, to)
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
return handled;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return [
|
|
81
|
+
plugin,
|
|
82
|
+
Prec.high(
|
|
83
|
+
keymap.of([
|
|
84
|
+
{
|
|
85
|
+
key: "Backspace",
|
|
86
|
+
run: runnable("to")
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
key: "ArrowLeft",
|
|
90
|
+
run: runnable("to")
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
key: "ArrowRight",
|
|
94
|
+
run: runnable("from")
|
|
95
|
+
}
|
|
96
|
+
])
|
|
97
|
+
)
|
|
98
|
+
];
|
|
99
|
+
}
|
|
100
|
+
function updateRegexpDecorations(view) {
|
|
101
|
+
view.dispatch({
|
|
102
|
+
effects: updateEffect.of(null)
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
var index_default = regexpDecorator;
|
|
106
|
+
export {
|
|
107
|
+
index_default as default,
|
|
108
|
+
updateRegexpDecorations
|
|
109
|
+
};
|
|
110
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nimport {\n Decoration,\n EditorView,\n keymap,\n MatchDecorator,\n ViewPlugin,\n type ViewUpdate,\n} from '@codemirror/view';\nimport {\n EditorSelection,\n type Extension,\n Prec,\n type RangeSet,\n StateEffect,\n} from '@codemirror/state';\n\ntype RegexpDecoratorOptions = ConstructorParameters<typeof MatchDecorator>[0];\n\nconst updateEffect = StateEffect.define();\n\nfunction regexpDecorator(options: RegexpDecoratorOptions): Extension {\n const decorator = new MatchDecorator(options);\n\n const plugin = ViewPlugin.fromClass(\n class {\n public decorations: RangeSet<Decoration>;\n\n constructor(private view: EditorView) {\n this.decorations = decorator.createDeco(view);\n }\n\n update(update: ViewUpdate) {\n const hasUpdateEffect = update.transactions.some(tr =>\n tr.effects.some(effect => effect.is(updateEffect)),\n );\n\n if (hasUpdateEffect || update.selectionSet) {\n this.decorations = decorator.createDeco(update.view);\n } else if (update.docChanged) {\n // updateDeco 只有同一行存在 变更 时才会更新\n this.decorations = decorator.updateDeco(update, this.decorations);\n }\n }\n },\n {\n provide(plugin) {\n return [\n EditorView.decorations.of(\n view => view.plugin(plugin)?.decorations ?? Decoration.none,\n ),\n EditorView.atomicRanges.of(view => {\n const p = view.plugin(plugin);\n if (!p) {\n return Decoration.none;\n }\n return p.decorations.update({\n filter(from, to, value) {\n return Boolean(value.spec.atomicRange);\n },\n });\n }),\n ];\n },\n },\n );\n\n function runnable(side: 'to' | 'from') {\n return function run(view: EditorView) {\n const { head, anchor } = view.state.selection.main;\n\n if (head !== anchor) {\n return false;\n }\n\n const decorations = view.plugin(plugin)?.decorations ?? Decoration.none;\n\n let handled = false;\n decorations.between(0, view.state.doc.length, (from, to, value) => {\n const pos = side === 'from' ? from : to;\n if (pos === head && value.spec.selectable) {\n handled = true;\n view.dispatch({\n selection:\n side === 'to'\n ? EditorSelection.range(to, from)\n : EditorSelection.range(from, to),\n });\n }\n });\n\n return handled;\n };\n }\n\n return [\n plugin,\n Prec.high(\n keymap.of([\n {\n key: 'Backspace',\n run: runnable('to'),\n },\n {\n key: 'ArrowLeft',\n run: runnable('to'),\n },\n {\n key: 'ArrowRight',\n run: runnable('from'),\n },\n ]),\n ),\n ];\n}\n\nfunction updateRegexpDecorations(view: EditorView) {\n view.dispatch({\n effects: updateEffect.of(null),\n });\n}\n\nexport default regexpDecorator;\n\nexport { updateRegexpDecorations };\n"],"mappings":";AAGA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EAEA;AAAA,EAEA;AAAA,OACK;AAIP,IAAM,eAAe,YAAY,OAAO;AAExC,SAAS,gBAAgB,SAA4C;AACnE,QAAM,YAAY,IAAI,eAAe,OAAO;AAE5C,QAAM,SAAS,WAAW;AAAA,IACxB,MAAM;AAAA,MAGJ,YAAoB,MAAkB;AAAlB;AAClB,aAAK,cAAc,UAAU,WAAW,IAAI;AAAA,MAC9C;AAAA,MAJO;AAAA,MAMP,OAAO,QAAoB;AACzB,cAAM,kBAAkB,OAAO,aAAa;AAAA,UAAK,QAC/C,GAAG,QAAQ,KAAK,YAAU,OAAO,GAAG,YAAY,CAAC;AAAA,QACnD;AAEA,YAAI,mBAAmB,OAAO,cAAc;AAC1C,eAAK,cAAc,UAAU,WAAW,OAAO,IAAI;AAAA,QACrD,WAAW,OAAO,YAAY;AAE5B,eAAK,cAAc,UAAU,WAAW,QAAQ,KAAK,WAAW;AAAA,QAClE;AAAA,MACF;AAAA,IACF;AAAA,IACA;AAAA,MACE,QAAQA,SAAQ;AACd,eAAO;AAAA,UACL,WAAW,YAAY;AAAA,YACrB,UAAK;AAnDjB;AAmDoB,iCAAK,OAAOA,OAAM,MAAlB,mBAAqB,gBAAe,WAAW;AAAA;AAAA,UACzD;AAAA,UACA,WAAW,aAAa,GAAG,UAAQ;AACj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AACjD,OAAK,SAAS;AAAA,IACZ,SAAS,aAAa,GAAG,IAAI;AAAA,EAC/B,CAAC;AACH;AAEA,IAAO,gBAAQ;","names":["plugin"]}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MatchDecorator, EditorView } from '@codemirror/view';
|
|
2
|
+
import { Extension } from '@codemirror/state';
|
|
3
|
+
|
|
4
|
+
type RegexpDecoratorOptions = ConstructorParameters<typeof MatchDecorator>[0];
|
|
5
|
+
declare function regexpDecorator(options: RegexpDecoratorOptions): Extension;
|
|
6
|
+
declare function updateRegexpDecorations(view: EditorView): void;
|
|
7
|
+
|
|
8
|
+
export { regexpDecorator as default, updateRegexpDecorations };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MatchDecorator, EditorView } from '@codemirror/view';
|
|
2
|
+
import { Extension } from '@codemirror/state';
|
|
3
|
+
|
|
4
|
+
type RegexpDecoratorOptions = ConstructorParameters<typeof MatchDecorator>[0];
|
|
5
|
+
declare function regexpDecorator(options: RegexpDecoratorOptions): Extension;
|
|
6
|
+
declare function updateRegexpDecorations(view: EditorView): void;
|
|
7
|
+
|
|
8
|
+
export { regexpDecorator as default, updateRegexpDecorations };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
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
|
+
default: () => index_default,
|
|
23
|
+
updateRegexpDecorations: () => updateRegexpDecorations
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var import_view = require("@codemirror/view");
|
|
27
|
+
var import_state = require("@codemirror/state");
|
|
28
|
+
var updateEffect = import_state.StateEffect.define();
|
|
29
|
+
function regexpDecorator(options) {
|
|
30
|
+
const decorator = new import_view.MatchDecorator(options);
|
|
31
|
+
const plugin = import_view.ViewPlugin.fromClass(
|
|
32
|
+
class {
|
|
33
|
+
constructor(view) {
|
|
34
|
+
this.view = view;
|
|
35
|
+
this.decorations = decorator.createDeco(view);
|
|
36
|
+
}
|
|
37
|
+
decorations;
|
|
38
|
+
update(update) {
|
|
39
|
+
const hasUpdateEffect = update.transactions.some(
|
|
40
|
+
(tr) => tr.effects.some((effect) => effect.is(updateEffect))
|
|
41
|
+
);
|
|
42
|
+
if (hasUpdateEffect || update.selectionSet) {
|
|
43
|
+
this.decorations = decorator.createDeco(update.view);
|
|
44
|
+
} else if (update.docChanged) {
|
|
45
|
+
this.decorations = decorator.updateDeco(update, this.decorations);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
provide(plugin2) {
|
|
51
|
+
return [
|
|
52
|
+
import_view.EditorView.decorations.of(
|
|
53
|
+
(view) => {
|
|
54
|
+
var _a;
|
|
55
|
+
return ((_a = view.plugin(plugin2)) == null ? void 0 : _a.decorations) ?? import_view.Decoration.none;
|
|
56
|
+
}
|
|
57
|
+
),
|
|
58
|
+
import_view.EditorView.atomicRanges.of((view) => {
|
|
59
|
+
const p = view.plugin(plugin2);
|
|
60
|
+
if (!p) {
|
|
61
|
+
return import_view.Decoration.none;
|
|
62
|
+
}
|
|
63
|
+
return p.decorations.update({
|
|
64
|
+
filter(from, to, value) {
|
|
65
|
+
return Boolean(value.spec.atomicRange);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
})
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
function runnable(side) {
|
|
74
|
+
return function run(view) {
|
|
75
|
+
var _a;
|
|
76
|
+
const { head, anchor } = view.state.selection.main;
|
|
77
|
+
if (head !== anchor) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
const decorations = ((_a = view.plugin(plugin)) == null ? void 0 : _a.decorations) ?? import_view.Decoration.none;
|
|
81
|
+
let handled = false;
|
|
82
|
+
decorations.between(0, view.state.doc.length, (from, to, value) => {
|
|
83
|
+
const pos = side === "from" ? from : to;
|
|
84
|
+
if (pos === head && value.spec.selectable) {
|
|
85
|
+
handled = true;
|
|
86
|
+
view.dispatch({
|
|
87
|
+
selection: side === "to" ? import_state.EditorSelection.range(to, from) : import_state.EditorSelection.range(from, to)
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return handled;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return [
|
|
95
|
+
plugin,
|
|
96
|
+
import_state.Prec.high(
|
|
97
|
+
import_view.keymap.of([
|
|
98
|
+
{
|
|
99
|
+
key: "Backspace",
|
|
100
|
+
run: runnable("to")
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
key: "ArrowLeft",
|
|
104
|
+
run: runnable("to")
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
key: "ArrowRight",
|
|
108
|
+
run: runnable("from")
|
|
109
|
+
}
|
|
110
|
+
])
|
|
111
|
+
)
|
|
112
|
+
];
|
|
113
|
+
}
|
|
114
|
+
function updateRegexpDecorations(view) {
|
|
115
|
+
view.dispatch({
|
|
116
|
+
effects: updateEffect.of(null)
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
var index_default = regexpDecorator;
|
|
120
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
121
|
+
0 && (module.exports = {
|
|
122
|
+
updateRegexpDecorations
|
|
123
|
+
});
|
|
124
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nimport {\n Decoration,\n EditorView,\n keymap,\n MatchDecorator,\n ViewPlugin,\n type ViewUpdate,\n} from '@codemirror/view';\nimport {\n EditorSelection,\n type Extension,\n Prec,\n type RangeSet,\n StateEffect,\n} from '@codemirror/state';\n\ntype RegexpDecoratorOptions = ConstructorParameters<typeof MatchDecorator>[0];\n\nconst updateEffect = StateEffect.define();\n\nfunction regexpDecorator(options: RegexpDecoratorOptions): Extension {\n const decorator = new MatchDecorator(options);\n\n const plugin = ViewPlugin.fromClass(\n class {\n public decorations: RangeSet<Decoration>;\n\n constructor(private view: EditorView) {\n this.decorations = decorator.createDeco(view);\n }\n\n update(update: ViewUpdate) {\n const hasUpdateEffect = update.transactions.some(tr =>\n tr.effects.some(effect => effect.is(updateEffect)),\n );\n\n if (hasUpdateEffect || update.selectionSet) {\n this.decorations = decorator.createDeco(update.view);\n } else if (update.docChanged) {\n // updateDeco 只有同一行存在 变更 时才会更新\n this.decorations = decorator.updateDeco(update, this.decorations);\n }\n }\n },\n {\n provide(plugin) {\n return [\n EditorView.decorations.of(\n view => view.plugin(plugin)?.decorations ?? Decoration.none,\n ),\n EditorView.atomicRanges.of(view => {\n const p = view.plugin(plugin);\n if (!p) {\n return Decoration.none;\n }\n return p.decorations.update({\n filter(from, to, value) {\n return Boolean(value.spec.atomicRange);\n },\n });\n }),\n ];\n },\n },\n );\n\n function runnable(side: 'to' | 'from') {\n return function run(view: EditorView) {\n const { head, anchor } = view.state.selection.main;\n\n if (head !== anchor) {\n return false;\n }\n\n const decorations = view.plugin(plugin)?.decorations ?? Decoration.none;\n\n let handled = false;\n decorations.between(0, view.state.doc.length, (from, to, value) => {\n const pos = side === 'from' ? from : to;\n if (pos === head && value.spec.selectable) {\n handled = true;\n view.dispatch({\n selection:\n side === 'to'\n ? EditorSelection.range(to, from)\n : EditorSelection.range(from, to),\n });\n }\n });\n\n return handled;\n };\n }\n\n return [\n plugin,\n Prec.high(\n keymap.of([\n {\n key: 'Backspace',\n run: runnable('to'),\n },\n {\n key: 'ArrowLeft',\n run: runnable('to'),\n },\n {\n key: 'ArrowRight',\n run: runnable('from'),\n },\n ]),\n ),\n ];\n}\n\nfunction updateRegexpDecorations(view: EditorView) {\n view.dispatch({\n effects: updateEffect.of(null),\n });\n}\n\nexport default regexpDecorator;\n\nexport { updateRegexpDecorations };\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAOO;AACP,mBAMO;AAIP,IAAM,eAAe,yBAAY,OAAO;AAExC,SAAS,gBAAgB,SAA4C;AACnE,QAAM,YAAY,IAAI,2BAAe,OAAO;AAE5C,QAAM,SAAS,uBAAW;AAAA,IACxB,MAAM;AAAA,MAGJ,YAAoB,MAAkB;AAAlB;AAClB,aAAK,cAAc,UAAU,WAAW,IAAI;AAAA,MAC9C;AAAA,MAJO;AAAA,MAMP,OAAO,QAAoB;AACzB,cAAM,kBAAkB,OAAO,aAAa;AAAA,UAAK,QAC/C,GAAG,QAAQ,KAAK,YAAU,OAAO,GAAG,YAAY,CAAC;AAAA,QACnD;AAEA,YAAI,mBAAmB,OAAO,cAAc;AAC1C,eAAK,cAAc,UAAU,WAAW,OAAO,IAAI;AAAA,QACrD,WAAW,OAAO,YAAY;AAE5B,eAAK,cAAc,UAAU,WAAW,Q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,QACR;AAAA,UACE,KAAK;AAAA,UACL,KAAK,SAAS,IAAI;AAAA,QACpB;AAAA,QACA;AAAA,UACE,KAAK;AAAA,UACL,KAAK,SAAS,IAAI;AAAA,QACpB;AAAA,QACA;AAAA,UACE,KAAK;AAAA,UACL,KAAK,SAAS,MAAM;AAAA,QACtB;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,SAAS,wBAAwB,MAAkB;AACjD,OAAK,SAAS;AAAA,IACZ,SAAS,aAAa,GAAG,IAAI;AAAA,EAC/B,CAAC;AACH;AAEA,IAAO,gBAAQ;","names":["plugin"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@coze-editor/extension-regexp-decorator",
|
|
3
|
+
"version": "0.1.0-alpha.09ffeb",
|
|
4
|
+
"description": "extension-regexp-decorator",
|
|
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
|
+
"devDependencies": {
|
|
25
|
+
"@codemirror/state": "^6.4.1",
|
|
26
|
+
"@codemirror/view": "^6.26.1",
|
|
27
|
+
"@coze-arch/ts-config": "workspace:*",
|
|
28
|
+
"@coze-editor/eslint-config": "workspace:*",
|
|
29
|
+
"@types/node": "^22",
|
|
30
|
+
"eslint": "9.14.0",
|
|
31
|
+
"tsup": "^8.0.1",
|
|
32
|
+
"typescript": "^5.8.2"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@codemirror/state": "^6.4.1",
|
|
36
|
+
"@codemirror/view": "^6.26.1"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public",
|
|
40
|
+
"registry": "https://registry.npmjs.org"
|
|
41
|
+
},
|
|
42
|
+
"test:main": "./src/index.ts"
|
|
43
|
+
}
|