@stonecrop/code-editor 0.13.2 → 0.13.4

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.
@@ -1 +1 @@
1
- #editor-container{width:100%;height:100%}
1
+ .a-code-editor[data-v-27d090ea]{width:100%;overflow:hidden}
@@ -1,39 +1,39 @@
1
- import { defineComponent as C, useTemplateRef as $, onMounted as x, openBlock as q, createElementBlock as D } from "vue";
2
- function y(e, n) {
1
+ import { defineComponent as x, useModel as $, useTemplateRef as D, shallowRef as q, watch as k, onMounted as M, onUnmounted as B, openBlock as R, createElementBlock as L, normalizeStyle as V, mergeModels as z } from "vue";
2
+ function O(e, n) {
3
3
  (n == null || n > e.length) && (n = e.length);
4
4
  for (var r = 0, t = Array(n); r < n; r++) t[r] = e[r];
5
5
  return t;
6
6
  }
7
- function B(e) {
7
+ function H(e) {
8
8
  if (Array.isArray(e)) return e;
9
9
  }
10
- function L(e, n, r) {
11
- return (n = W(n)) in e ? Object.defineProperty(e, n, {
10
+ function N(e, n, r) {
11
+ return (n = Y(n)) in e ? Object.defineProperty(e, n, {
12
12
  value: r,
13
13
  enumerable: !0,
14
14
  configurable: !0,
15
15
  writable: !0
16
16
  }) : e[n] = r, e;
17
17
  }
18
- function R(e, n) {
18
+ function F(e, n) {
19
19
  var r = e == null ? null : typeof Symbol < "u" && e[Symbol.iterator] || e["@@iterator"];
20
20
  if (r != null) {
21
- var t, o, i, c, u = [], a = !0, d = !1;
21
+ var t, o, i, a, c = [], u = !0, d = !1;
22
22
  try {
23
- if (i = (r = r.call(e)).next, n !== 0) for (; !(a = (t = i.call(r)).done) && (u.push(t.value), u.length !== n); a = !0) ;
23
+ if (i = (r = r.call(e)).next, n !== 0) for (; !(u = (t = i.call(r)).done) && (c.push(t.value), c.length !== n); u = !0) ;
24
24
  } catch (h) {
25
25
  d = !0, o = h;
26
26
  } finally {
27
27
  try {
28
- if (!a && r.return != null && (c = r.return(), Object(c) !== c)) return;
28
+ if (!u && r.return != null && (a = r.return(), Object(a) !== a)) return;
29
29
  } finally {
30
30
  if (d) throw o;
31
31
  }
32
32
  }
33
- return u;
33
+ return c;
34
34
  }
35
35
  }
36
- function H() {
36
+ function U() {
37
37
  throw new TypeError(`Invalid attempt to destructure non-iterable instance.
38
38
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`);
39
39
  }
@@ -51,23 +51,23 @@ function j(e) {
51
51
  for (var n = 1; n < arguments.length; n++) {
52
52
  var r = arguments[n] != null ? arguments[n] : {};
53
53
  n % 2 ? w(Object(r), !0).forEach(function(t) {
54
- L(e, t, r[t]);
54
+ N(e, t, r[t]);
55
55
  }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(r)) : w(Object(r)).forEach(function(t) {
56
56
  Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(r, t));
57
57
  });
58
58
  }
59
59
  return e;
60
60
  }
61
- function M(e, n) {
61
+ function W(e, n) {
62
62
  if (e == null) return {};
63
- var r, t, o = z(e, n);
63
+ var r, t, o = G(e, n);
64
64
  if (Object.getOwnPropertySymbols) {
65
65
  var i = Object.getOwnPropertySymbols(e);
66
66
  for (t = 0; t < i.length; t++) r = i[t], n.indexOf(r) === -1 && {}.propertyIsEnumerable.call(e, r) && (o[r] = e[r]);
67
67
  }
68
68
  return o;
69
69
  }
70
- function z(e, n) {
70
+ function G(e, n) {
71
71
  if (e == null) return {};
72
72
  var r = {};
73
73
  for (var t in e) if ({}.hasOwnProperty.call(e, t)) {
@@ -76,10 +76,10 @@ function z(e, n) {
76
76
  }
77
77
  return r;
78
78
  }
79
- function _(e, n) {
80
- return B(e) || R(e, n) || G(e, n) || H();
79
+ function K(e, n) {
80
+ return H(e) || F(e, n) || Q(e, n) || U();
81
81
  }
82
- function F(e, n) {
82
+ function J(e, n) {
83
83
  if (typeof e != "object" || !e) return e;
84
84
  var r = e[Symbol.toPrimitive];
85
85
  if (r !== void 0) {
@@ -89,18 +89,18 @@ function F(e, n) {
89
89
  }
90
90
  return (n === "string" ? String : Number)(e);
91
91
  }
92
- function W(e) {
93
- var n = F(e, "string");
92
+ function Y(e) {
93
+ var n = J(e, "string");
94
94
  return typeof n == "symbol" ? n : n + "";
95
95
  }
96
- function G(e, n) {
96
+ function Q(e, n) {
97
97
  if (e) {
98
- if (typeof e == "string") return y(e, n);
98
+ if (typeof e == "string") return O(e, n);
99
99
  var r = {}.toString.call(e).slice(8, -1);
100
- return r === "Object" && e.constructor && (r = e.constructor.name), r === "Map" || r === "Set" ? Array.from(e) : r === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r) ? y(e, n) : void 0;
100
+ return r === "Object" && e.constructor && (r = e.constructor.name), r === "Map" || r === "Set" ? Array.from(e) : r === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r) ? O(e, n) : void 0;
101
101
  }
102
102
  }
103
- function K(e, n, r) {
103
+ function X(e, n, r) {
104
104
  return n in e ? Object.defineProperty(e, n, {
105
105
  value: r,
106
106
  enumerable: !0,
@@ -108,7 +108,7 @@ function K(e, n, r) {
108
108
  writable: !0
109
109
  }) : e[n] = r, e;
110
110
  }
111
- function O(e, n) {
111
+ function S(e, n) {
112
112
  var r = Object.keys(e);
113
113
  if (Object.getOwnPropertySymbols) {
114
114
  var t = Object.getOwnPropertySymbols(e);
@@ -118,18 +118,18 @@ function O(e, n) {
118
118
  }
119
119
  return r;
120
120
  }
121
- function S(e) {
121
+ function P(e) {
122
122
  for (var n = 1; n < arguments.length; n++) {
123
123
  var r = arguments[n] != null ? arguments[n] : {};
124
- n % 2 ? O(Object(r), !0).forEach(function(t) {
125
- K(e, t, r[t]);
126
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(r)) : O(Object(r)).forEach(function(t) {
124
+ n % 2 ? S(Object(r), !0).forEach(function(t) {
125
+ X(e, t, r[t]);
126
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(r)) : S(Object(r)).forEach(function(t) {
127
127
  Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(r, t));
128
128
  });
129
129
  }
130
130
  return e;
131
131
  }
132
- function N() {
132
+ function Z() {
133
133
  for (var e = arguments.length, n = new Array(e), r = 0; r < e; r++)
134
134
  n[r] = arguments[r];
135
135
  return function(t) {
@@ -143,44 +143,44 @@ function l(e) {
143
143
  for (var r = this, t = arguments.length, o = new Array(t), i = 0; i < t; i++)
144
144
  o[i] = arguments[i];
145
145
  return o.length >= e.length ? e.apply(this, o) : function() {
146
- for (var c = arguments.length, u = new Array(c), a = 0; a < c; a++)
147
- u[a] = arguments[a];
148
- return n.apply(r, [].concat(o, u));
146
+ for (var a = arguments.length, c = new Array(a), u = 0; u < a; u++)
147
+ c[u] = arguments[u];
148
+ return n.apply(r, [].concat(o, c));
149
149
  };
150
150
  };
151
151
  }
152
- function m(e) {
152
+ function p(e) {
153
153
  return {}.toString.call(e).includes("Object");
154
154
  }
155
- function U(e) {
155
+ function _(e) {
156
156
  return !Object.keys(e).length;
157
157
  }
158
158
  function s(e) {
159
159
  return typeof e == "function";
160
160
  }
161
- function Y(e, n) {
161
+ function ee(e, n) {
162
162
  return Object.prototype.hasOwnProperty.call(e, n);
163
163
  }
164
- function J(e, n) {
165
- return m(n) || f("changeType"), Object.keys(n).some(function(r) {
166
- return !Y(e, r);
164
+ function ne(e, n) {
165
+ return p(n) || f("changeType"), Object.keys(n).some(function(r) {
166
+ return !ee(e, r);
167
167
  }) && f("changeField"), n;
168
168
  }
169
- function Q(e) {
169
+ function re(e) {
170
170
  s(e) || f("selectorType");
171
171
  }
172
- function V(e) {
173
- s(e) || m(e) || f("handlerType"), m(e) && Object.values(e).some(function(n) {
172
+ function te(e) {
173
+ s(e) || p(e) || f("handlerType"), p(e) && Object.values(e).some(function(n) {
174
174
  return !s(n);
175
175
  }) && f("handlersType");
176
176
  }
177
- function X(e) {
178
- e || f("initialIsRequired"), m(e) || f("initialType"), U(e) && f("initialContent");
177
+ function oe(e) {
178
+ e || f("initialIsRequired"), p(e) || f("initialType"), _(e) && f("initialContent");
179
179
  }
180
- function Z(e, n) {
180
+ function ie(e, n) {
181
181
  throw new Error(e[n] || e.default);
182
182
  }
183
- var ee = {
183
+ var ae = {
184
184
  initialIsRequired: "initial state is required",
185
185
  initialType: "initial state should be an object",
186
186
  initialContent: "initial state shouldn't be an empty object",
@@ -190,76 +190,76 @@ var ee = {
190
190
  changeType: "provided value of changes should be an object",
191
191
  changeField: 'it seams you want to change a field in the state which is not specified in the "initial" state',
192
192
  default: "an unknown error accured in `state-local` package"
193
- }, f = l(Z)(ee), p = {
194
- changes: J,
195
- selector: Q,
196
- handler: V,
197
- initial: X
193
+ }, f = l(ie)(ae), m = {
194
+ changes: ne,
195
+ selector: re,
196
+ handler: te,
197
+ initial: oe
198
198
  };
199
- function ne(e) {
199
+ function ue(e) {
200
200
  var n = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
201
- p.initial(e), p.handler(n);
201
+ m.initial(e), m.handler(n);
202
202
  var r = {
203
203
  current: e
204
- }, t = l(oe)(r, n), o = l(te)(r), i = l(p.changes)(e), c = l(re)(r);
205
- function u() {
204
+ }, t = l(de)(r, n), o = l(fe)(r), i = l(m.changes)(e), a = l(ce)(r);
205
+ function c() {
206
206
  var d = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : function(h) {
207
207
  return h;
208
208
  };
209
- return p.selector(d), d(r.current);
209
+ return m.selector(d), d(r.current);
210
210
  }
211
- function a(d) {
212
- N(t, o, i, c)(d);
211
+ function u(d) {
212
+ Z(t, o, i, a)(d);
213
213
  }
214
- return [u, a];
214
+ return [c, u];
215
215
  }
216
- function re(e, n) {
216
+ function ce(e, n) {
217
217
  return s(n) ? n(e.current) : n;
218
218
  }
219
- function te(e, n) {
220
- return e.current = S(S({}, e.current), n), n;
219
+ function fe(e, n) {
220
+ return e.current = P(P({}, e.current), n), n;
221
221
  }
222
- function oe(e, n, r) {
222
+ function de(e, n, r) {
223
223
  return s(n) ? n(e.current) : Object.keys(r).forEach(function(t) {
224
224
  var o;
225
225
  return (o = n[t]) === null || o === void 0 ? void 0 : o.call(n, e.current[t]);
226
226
  }), r;
227
227
  }
228
- var ie = {
229
- create: ne
230
- }, ae = {
228
+ var le = {
229
+ create: ue
230
+ }, se = {
231
231
  paths: {
232
232
  vs: "https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs"
233
233
  }
234
234
  };
235
- function ce(e) {
235
+ function ge(e) {
236
236
  return function n() {
237
237
  for (var r = this, t = arguments.length, o = new Array(t), i = 0; i < t; i++)
238
238
  o[i] = arguments[i];
239
239
  return o.length >= e.length ? e.apply(this, o) : function() {
240
- for (var c = arguments.length, u = new Array(c), a = 0; a < c; a++)
241
- u[a] = arguments[a];
242
- return n.apply(r, [].concat(o, u));
240
+ for (var a = arguments.length, c = new Array(a), u = 0; u < a; u++)
241
+ c[u] = arguments[u];
242
+ return n.apply(r, [].concat(o, c));
243
243
  };
244
244
  };
245
245
  }
246
- function ue(e) {
246
+ function me(e) {
247
247
  return {}.toString.call(e).includes("Object");
248
248
  }
249
- function fe(e) {
250
- return e || P("configIsRequired"), ue(e) || P("configType"), e.urls ? (de(), {
249
+ function pe(e) {
250
+ return e || I("configIsRequired"), me(e) || I("configType"), e.urls ? (be(), {
251
251
  paths: {
252
252
  vs: e.urls.monacoBase
253
253
  }
254
254
  }) : e;
255
255
  }
256
- function de() {
257
- console.warn(I.deprecation);
256
+ function be() {
257
+ console.warn(E.deprecation);
258
258
  }
259
- function le(e, n) {
259
+ function he(e, n) {
260
260
  throw new Error(e[n] || e.default);
261
261
  }
262
- var I = {
262
+ var E = {
263
263
  configIsRequired: "the configuration object is required",
264
264
  configType: "the configuration object should be an object",
265
265
  default: "an unknown error accured in `@monaco-editor/loader` package",
@@ -273,53 +273,53 @@ var I = {
273
273
 
274
274
  For more please check the link https://github.com/suren-atoyan/monaco-loader#config
275
275
  `
276
- }, P = ce(le)(I), se = {
277
- config: fe
278
- }, ge = function() {
276
+ }, I = ge(he)(E), ve = {
277
+ config: pe
278
+ }, ye = function() {
279
279
  for (var n = arguments.length, r = new Array(n), t = 0; t < n; t++)
280
280
  r[t] = arguments[t];
281
281
  return function(o) {
282
- return r.reduceRight(function(i, c) {
283
- return c(i);
282
+ return r.reduceRight(function(i, a) {
283
+ return a(i);
284
284
  }, o);
285
285
  };
286
286
  };
287
- function E(e, n) {
287
+ function T(e, n) {
288
288
  return Object.keys(n).forEach(function(r) {
289
- n[r] instanceof Object && e[r] && Object.assign(n[r], E(e[r], n[r]));
289
+ n[r] instanceof Object && e[r] && Object.assign(n[r], T(e[r], n[r]));
290
290
  }), j(j({}, e), n);
291
291
  }
292
- var pe = {
292
+ var ke = {
293
293
  type: "cancelation",
294
294
  msg: "operation is manually canceled"
295
295
  };
296
296
  function v(e) {
297
297
  var n = !1, r = new Promise(function(t, o) {
298
298
  e.then(function(i) {
299
- return n ? o(pe) : t(i);
299
+ return n ? o(ke) : t(i);
300
300
  }), e.catch(o);
301
301
  });
302
302
  return r.cancel = function() {
303
303
  return n = !0;
304
304
  }, r;
305
305
  }
306
- var me = ["monaco"], be = ie.create({
307
- config: ae,
306
+ var Oe = ["monaco"], we = le.create({
307
+ config: se,
308
308
  isInitialized: !1,
309
309
  resolve: null,
310
310
  reject: null,
311
311
  monaco: null
312
- }), T = _(be, 2), g = T[0], b = T[1];
313
- function he(e) {
314
- var n = se.config(e), r = n.monaco, t = M(n, me);
312
+ }), A = K(we, 2), g = A[0], b = A[1];
313
+ function je(e) {
314
+ var n = ve.config(e), r = n.monaco, t = W(n, Oe);
315
315
  b(function(o) {
316
316
  return {
317
- config: E(o.config, t),
317
+ config: T(o.config, t),
318
318
  monaco: r
319
319
  };
320
320
  });
321
321
  }
322
- function ve() {
322
+ function Se() {
323
323
  var e = g(function(n) {
324
324
  var r = n.monaco, t = n.isInitialized, o = n.resolve;
325
325
  return {
@@ -332,33 +332,33 @@ function ve() {
332
332
  if (b({
333
333
  isInitialized: !0
334
334
  }), e.monaco)
335
- return e.resolve(e.monaco), v(k);
335
+ return e.resolve(e.monaco), v(y);
336
336
  if (window.monaco && window.monaco.editor)
337
- return A(window.monaco), e.resolve(window.monaco), v(k);
338
- ge(ke, we)(je);
337
+ return C(window.monaco), e.resolve(window.monaco), v(y);
338
+ ye(Pe, Ee)(Te);
339
339
  }
340
- return v(k);
340
+ return v(y);
341
341
  }
342
- function ke(e) {
342
+ function Pe(e) {
343
343
  return document.body.appendChild(e);
344
344
  }
345
- function ye(e) {
345
+ function Ie(e) {
346
346
  var n = document.createElement("script");
347
347
  return e && (n.src = e), n;
348
348
  }
349
- function we(e) {
349
+ function Ee(e) {
350
350
  var n = g(function(t) {
351
351
  var o = t.config, i = t.reject;
352
352
  return {
353
353
  config: o,
354
354
  reject: i
355
355
  };
356
- }), r = ye("".concat(n.config.paths.vs, "/loader.js"));
356
+ }), r = Ie("".concat(n.config.paths.vs, "/loader.js"));
357
357
  return r.onload = function() {
358
358
  return e();
359
359
  }, r.onerror = n.reject, r;
360
360
  }
361
- function je() {
361
+ function Te() {
362
362
  var e = g(function(r) {
363
363
  var t = r.config, o = r.resolve, i = r.reject;
364
364
  return {
@@ -369,33 +369,33 @@ function je() {
369
369
  }), n = window.require;
370
370
  n.config(e.config), n(["vs/editor/editor.main"], function(r) {
371
371
  var t = r.m || r;
372
- A(t), e.resolve(t);
372
+ C(t), e.resolve(t);
373
373
  }, function(r) {
374
374
  e.reject(r);
375
375
  });
376
376
  }
377
- function A(e) {
377
+ function C(e) {
378
378
  g().monaco || b({
379
379
  monaco: e
380
380
  });
381
381
  }
382
- function Oe() {
382
+ function Ae() {
383
383
  return g(function(e) {
384
384
  var n = e.monaco;
385
385
  return n;
386
386
  });
387
387
  }
388
- var k = new Promise(function(e, n) {
388
+ var y = new Promise(function(e, n) {
389
389
  return b({
390
390
  resolve: e,
391
391
  reject: n
392
392
  });
393
- }), Se = {
394
- config: he,
395
- init: ve,
396
- __getMonacoInstance: Oe
393
+ }), Ce = {
394
+ config: je,
395
+ init: Se,
396
+ __getMonacoInstance: Ae
397
397
  };
398
- const Pe = {
398
+ const xe = {
399
399
  base: "vs",
400
400
  inherit: !0,
401
401
  colors: {
@@ -742,33 +742,76 @@ const Pe = {
742
742
  token: "string.other.link"
743
743
  }
744
744
  ]
745
- }, Ie = {
746
- id: "editor-container",
747
- ref: "aCodeEditor"
748
- }, Ee = /* @__PURE__ */ C({
745
+ };
746
+ function $e(e, n) {
747
+ return e === "JSON" ? "json" : e === "Code" ? n ?? "typescript" : n ?? "plaintext";
748
+ }
749
+ function De(e, n) {
750
+ return e == null ? "" : typeof e == "string" ? e : JSON.stringify(e, null, 2);
751
+ }
752
+ const qe = /* @__PURE__ */ x({
749
753
  __name: "ACodeEditor",
750
- props: {
751
- options: { default: () => ({}) }
752
- },
754
+ props: /* @__PURE__ */ z({
755
+ height: { default: "300px" },
756
+ mode: { default: "edit" },
757
+ schema: { default: () => {
758
+ } },
759
+ language: { default: () => {
760
+ } },
761
+ options: { default: () => {
762
+ } }
763
+ }, {
764
+ modelValue: {},
765
+ modelModifiers: {}
766
+ }),
767
+ emits: ["update:modelValue"],
753
768
  setup(e) {
754
- const n = $("aCodeEditor"), r = {
755
- ...e.options,
756
- automaticLayout: !0,
757
- colorDecorators: !0,
758
- lineHeight: 24,
759
- scrollBeyondLastLine: !1
760
- };
761
- return x(async () => {
762
- const o = (await Se.init()).editor;
763
- o.defineTheme("agritheory", Pe), o.setTheme("agritheory"), n.value && o.create(n.value, r);
764
- }), (t, o) => (q(), D("div", Ie, null, 512));
769
+ const n = $(e, "modelValue"), r = D("aCodeEditor"), t = q(null);
770
+ return k(n, (o) => {
771
+ const i = t.value;
772
+ i && o !== i.getValue() && i.setValue(o ?? "");
773
+ }), k(
774
+ () => e.mode,
775
+ (o) => {
776
+ t.value?.updateOptions({ readOnly: o !== "edit" });
777
+ }
778
+ ), M(async () => {
779
+ const o = await Ce.init(), i = $e(e.schema?.fieldtype, e.language);
780
+ o.editor.defineTheme("agritheory", xe), o.editor.setTheme("agritheory");
781
+ const a = o.editor.create(r.value, {
782
+ automaticLayout: !0,
783
+ colorDecorators: !0,
784
+ lineHeight: 24,
785
+ scrollBeyondLastLine: !1,
786
+ ...e.options,
787
+ value: De(n.value, e.schema?.fieldtype),
788
+ language: i,
789
+ readOnly: e.mode !== "edit"
790
+ });
791
+ a.onDidChangeModelContent(() => {
792
+ n.value = a.getValue();
793
+ }), t.value = a;
794
+ const c = n.value ?? "";
795
+ c !== a.getValue() && a.setValue(c);
796
+ }), B(() => {
797
+ t.value?.dispose(), t.value = null;
798
+ }), (o, i) => (R(), L("div", {
799
+ ref: "aCodeEditor",
800
+ class: "a-code-editor",
801
+ style: V({ height: e.height })
802
+ }, null, 4));
765
803
  }
766
- });
767
- function Ae(e) {
768
- e.component("ACodeEditor", Ee);
804
+ }), Me = (e, n) => {
805
+ const r = e.__vccOpts || e;
806
+ for (const [t, o] of n)
807
+ r[t] = o;
808
+ return r;
809
+ }, Be = /* @__PURE__ */ Me(qe, [["__scopeId", "data-v-27d090ea"]]);
810
+ function Le(e) {
811
+ e.component("ACodeEditor", Be);
769
812
  }
770
813
  export {
771
- Ee as ACodeEditor,
772
- Ae as install
814
+ Be as ACodeEditor,
815
+ Le as install
773
816
  };
774
817
  //# sourceMappingURL=code-editor.js.map