ace-oqc 1.4.14 → 1.4.16

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.
Files changed (3) hide show
  1. package/index.d.ts +19 -0
  2. package/index.esm.js +72 -0
  3. package/package.json +7 -3
package/index.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ // index.d.ts
2
+ declare module 'ace-oqc' {
3
+ export interface AceEditor {
4
+ edit(element: string | HTMLElement, options?: any): any;
5
+ config: any;
6
+ require(module: string): any;
7
+ version: string;
8
+ }
9
+
10
+ export function loadAce(): Promise<AceEditor>;
11
+ export const CDN_BASE: string;
12
+
13
+ const ace: AceEditor & {
14
+ load: typeof loadAce;
15
+ ready: typeof loadAce;
16
+ };
17
+
18
+ export default ace;
19
+ }
package/index.esm.js ADDED
@@ -0,0 +1,72 @@
1
+ // index.esm.js - ES Module 版本
2
+ const CDN_BASE = 'http://10.10.8.128/res/ace-builds/src-noconflict';
3
+
4
+ let aceInstance = null;
5
+ let isLoading = false;
6
+ const loadCallbacks = [];
7
+
8
+ function loadAce() {
9
+ if (typeof window === 'undefined') {
10
+ throw new Error('Ace editor only works in browser environment');
11
+ }
12
+
13
+ if (window.ace) {
14
+ aceInstance = window.ace;
15
+ loadCallbacks.forEach(cb => cb(aceInstance));
16
+ loadCallbacks.length = 0;
17
+ return Promise.resolve(aceInstance);
18
+ }
19
+
20
+ if (isLoading) {
21
+ return new Promise((resolve) => {
22
+ loadCallbacks.push(resolve);
23
+ });
24
+ }
25
+
26
+ isLoading = true;
27
+
28
+ return new Promise((resolve, reject) => {
29
+ const script = document.createElement('script');
30
+ script.src = `${CDN_BASE}/ace.js`;
31
+ script.onload = () => {
32
+ aceInstance = window.ace;
33
+ if (aceInstance && aceInstance.config) {
34
+ aceInstance.config.set('basePath', CDN_BASE);
35
+ aceInstance.config.set('modePath', CDN_BASE);
36
+ aceInstance.config.set('themePath', CDN_BASE);
37
+ aceInstance.config.set('workerPath', CDN_BASE);
38
+ }
39
+ isLoading = false;
40
+ loadCallbacks.forEach(cb => cb(aceInstance));
41
+ loadCallbacks.length = 0;
42
+ resolve(aceInstance);
43
+ };
44
+ script.onerror = () => {
45
+ isLoading = false;
46
+ reject(new Error('Failed to load Ace editor from CDN'));
47
+ };
48
+ document.head.appendChild(script);
49
+ });
50
+ }
51
+
52
+ // 默认导出:延迟加载的代理对象
53
+ const aceProxy = new Proxy({}, {
54
+ get(target, prop) {
55
+ if (prop === 'load' || prop === 'ready') {
56
+ return loadAce;
57
+ }
58
+ if (aceInstance) {
59
+ const value = aceInstance[prop];
60
+ return typeof value === 'function' ? value.bind(aceInstance) : value;
61
+ }
62
+ return function(...args) {
63
+ return loadAce().then(ace => {
64
+ const fn = ace[prop];
65
+ return typeof fn === 'function' ? fn.apply(ace, args) : ace[prop];
66
+ });
67
+ };
68
+ }
69
+ });
70
+
71
+ export default aceProxy;
72
+ export { loadAce, CDN_BASE };
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "ace-oqc",
3
- "version": "1.4.14",
3
+ "version": "1.4.16",
4
4
  "main": "index.js",
5
- "files": ["index.js"],
6
- "license": "MIT"
5
+ "module": "index.esm.js",
6
+ "types": "index.d.ts",
7
+ "files": ["index.js", "index.d.ts", "index.esm.js"],
8
+ "license": "MIT",
9
+ "unpkg": "http://10.10.8.128/res/ace-builds/src-noconflict/ace.js",
10
+ "jsdelivr": "http://10.10.8.128/res/ace-builds/src-noconflict/ace.js"
7
11
  }