@hankchen/canvas-editor-vue 0.2.0 → 0.3.0

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,273 +0,0 @@
1
- import { Fragment as e, Teleport as t, createBlock as n, createCommentVNode as r, createElementBlock as i, createElementVNode as a, defineComponent as o, mergeProps as s, nextTick as c, normalizeClass as l, normalizeStyle as u, openBlock as d, ref as f, renderList as p, resolveDynamicComponent as m, toDisplayString as h, watch as g, withModifiers as _ } from "vue";
2
- //#region ../canvas-editor/src/shared/expressionSchema.ts
3
- function v(e) {
4
- let t = e;
5
- for (; t !== void 0;) {
6
- if (t.properties !== void 0) return t.properties;
7
- t = t.items;
8
- }
9
- return null;
10
- }
11
- function y(e, t) {
12
- let n = e;
13
- for (let e of t) {
14
- let t = v(n)?.get(e);
15
- if (t === void 0) return null;
16
- n = t;
17
- }
18
- return n;
19
- }
20
- function b(e) {
21
- if (e.type === "array" || e.items !== void 0) return { entries: [] };
22
- let t = e.properties === void 0 ? [] : [...e.properties].map(([e, t]) => ({
23
- key: e,
24
- node: t
25
- }));
26
- return e.open === !0 ? {
27
- entries: t,
28
- open: !0
29
- } : { entries: t };
30
- }
31
- function x(e, t) {
32
- let n = t.split(".");
33
- return t === "" || n.includes("") ? null : y(e, n)?.items ?? null;
34
- }
35
- //#endregion
36
- //#region ../canvas-editor/src/shared/expressionPath.ts
37
- function S(e) {
38
- if (e === "") return {
39
- ok: !1,
40
- error: "expression_syntax_error"
41
- };
42
- let t = e.split(".");
43
- if (t.includes("")) return {
44
- ok: !1,
45
- error: "expression_syntax_error"
46
- };
47
- let n = t[0], r = t.slice(1);
48
- return n === "row" ? {
49
- ok: !0,
50
- head: { kind: "row" },
51
- rest: r
52
- } : n === "$root" ? {
53
- ok: !0,
54
- head: { kind: "root" },
55
- rest: r
56
- } : {
57
- ok: !0,
58
- head: {
59
- kind: "bare",
60
- name: n
61
- },
62
- rest: r
63
- };
64
- }
65
- function C(e) {
66
- let t = 0, n = e.length;
67
- for (; t < n && " \n\r\0\v".includes(e[t]);) t += 1;
68
- for (; n > t && " \n\r\0\v".includes(e[n - 1]);) --n;
69
- return e.slice(t, n);
70
- }
71
- function w(e) {
72
- let t = [], n = 0, r = e.indexOf("{{");
73
- for (; r !== -1;) {
74
- let i = e.indexOf("}}", r + 2);
75
- if (i === -1) {
76
- r > n && t.push({
77
- kind: "literal",
78
- start: n,
79
- end: r,
80
- text: e.slice(n, r)
81
- });
82
- let i = e.slice(r);
83
- return t.push({
84
- kind: "open",
85
- start: r,
86
- end: e.length,
87
- text: i,
88
- expr: C(i.slice(2))
89
- }), {
90
- template: e,
91
- parts: t
92
- };
93
- }
94
- r > n && t.push({
95
- kind: "literal",
96
- start: n,
97
- end: r,
98
- text: e.slice(n, r)
99
- });
100
- let a = e.slice(r + 2, i), o = C(a), s = S(o).ok ? null : "expression_syntax_error";
101
- t.push({
102
- kind: "fragment",
103
- start: r,
104
- end: i + 2,
105
- raw: a,
106
- expr: o,
107
- error: s
108
- }), n = i + 2, r = e.indexOf("{{", n);
109
- }
110
- return n < e.length && t.push({
111
- kind: "literal",
112
- start: n,
113
- end: e.length,
114
- text: e.slice(n)
115
- }), {
116
- template: e,
117
- parts: t
118
- };
119
- }
120
- function T(e, t) {
121
- for (let n of e.parts) if (n.kind !== "literal" && (n.kind === "open" ? t > n.start && t <= n.end : t > n.start && t < n.end)) return n;
122
- return null;
123
- }
124
- //#endregion
125
- //#region src/shared/PanelIcon.vue
126
- var E = /* @__PURE__ */ o({
127
- inheritAttrs: !1,
128
- __name: "PanelIcon",
129
- props: {
130
- icon: {},
131
- size: { default: 14 },
132
- strokeWidth: { default: 2 }
133
- },
134
- setup(e) {
135
- return (t, r) => (d(), n(m(e.icon), s({
136
- size: e.size,
137
- "stroke-width": e.strokeWidth
138
- }, t.$attrs), null, 16, ["size", "stroke-width"]));
139
- }
140
- }), D = {
141
- role: "listbox",
142
- "aria-label": "表达式路径候选"
143
- }, O = [
144
- "aria-selected",
145
- "title",
146
- "onClick"
147
- ], k = { class: "cn-completion__segment font-mono text-cn-fg" }, A = {
148
- key: 0,
149
- class: "shrink-0 rounded-sm bg-cn-field px-1 py-0.5 text-[9px] leading-none text-cn-muted"
150
- }, j = {
151
- key: 1,
152
- class: "truncate text-[10px] leading-none text-cn-muted"
153
- }, M = {
154
- key: 0,
155
- class: "cn-completion__hint px-2 py-1.5 text-[10px] leading-none text-cn-muted"
156
- }, N = /* @__PURE__ */ o({
157
- __name: "ExpressionCompletionPopup",
158
- props: { state: {} },
159
- emits: ["select"],
160
- setup(o, { expose: s, emit: m }) {
161
- let v = o, y = m, b = f(null);
162
- return s({ rootEl: b }), g(() => v.state.activeIndex, async () => {
163
- await c(), b.value?.querySelector(".cn-completion__option--active")?.scrollIntoView?.({ block: "nearest" });
164
- }), (s, c) => (d(), n(t, { to: "body" }, [o.state.open ? (d(), i("div", {
165
- key: 0,
166
- ref_key: "rootRef",
167
- ref: b,
168
- class: "cn-props cn-completion fixed z-50 max-h-[200px] min-w-[140px] max-w-[280px] overflow-y-auto rounded-md border border-cn-field-line py-1 text-[11px] leading-none",
169
- style: u({
170
- top: `${o.state.top}px`,
171
- left: `${o.state.left}px`
172
- }),
173
- onMousedown: c[0] ||= _(() => {}, ["prevent", "stop"]),
174
- onPointerdown: c[1] ||= _(() => {}, ["stop"])
175
- }, [a("div", D, [(d(!0), i(e, null, p(o.state.items, (e, t) => (d(), i("button", {
176
- key: `${t}:${e.segment}`,
177
- type: "button",
178
- role: "option",
179
- class: l(["cn-completion__option flex w-full items-center gap-1.5 px-2 py-1.5 text-left", t === o.state.activeIndex ? "cn-completion__option--active" : ""]),
180
- "aria-selected": t === o.state.activeIndex,
181
- title: e.path ?? e.segment,
182
- onClick: (e) => y("select", t)
183
- }, [
184
- a("span", k, h(e.segment), 1),
185
- e.type ? (d(), i("span", A, h(e.type), 1)) : r("", !0),
186
- e.description ?? e.title ? (d(), i("span", j, h(e.description ?? e.title), 1)) : r("", !0)
187
- ], 10, O))), 128))]), o.state.openMapping ? (d(), i("div", M, " 动态字段,键由模板定义 ")) : r("", !0)], 36)) : r("", !0)]));
188
- }
189
- });
190
- //#endregion
191
- //#region src/shared/completion.ts
192
- function P(e, t, n, r) {
193
- let i = t.start + 2, a = t.kind === "open" ? t.end : t.end - 2, o = 0;
194
- for (; a - o > i && " \n\r\0\v".includes(e[a - 1 - o]);) o += 1;
195
- let s = a - o, c = s - n.length;
196
- return c < i || e.slice(c, s) !== n ? null : {
197
- value: e.slice(0, c) + r + e.slice(s),
198
- cursor: c + r.length
199
- };
200
- }
201
- //#endregion
202
- //#region src/shared/completionAnchor.ts
203
- function F(e, t) {
204
- return parseFloat(e.getPropertyValue(t)) || 0;
205
- }
206
- function I(e, t, n) {
207
- for (let r of n) {
208
- let n = e.getPropertyValue(r);
209
- n && t.setProperty(r, n);
210
- }
211
- }
212
- var L = [
213
- "font-family",
214
- "font-size",
215
- "font-weight",
216
- "font-style",
217
- "font-stretch",
218
- "letter-spacing",
219
- "word-spacing",
220
- "line-height",
221
- "text-transform",
222
- "text-indent",
223
- "tab-size"
224
- ];
225
- function R(e) {
226
- return F(e, "line-height") || F(e, "font-size") * 1.4;
227
- }
228
- function z(e) {
229
- let t = document.createElement("div"), n = t.style;
230
- return n.position = "fixed", n.top = "0", n.left = "0", n.visibility = "hidden", e(t, n), document.body.appendChild(t), t;
231
- }
232
- function B(e, t) {
233
- let n = e.selectionStart ?? e.value.length, r = e.getBoundingClientRect(), i = getComputedStyle(e), a = F(i, "padding-left"), o = F(i, "padding-top"), s = null, c = z((t, r) => {
234
- r.whiteSpace = i.whiteSpace || "pre-wrap", r.boxSizing = "content-box", r.width = `${Math.max(0, e.clientWidth - a - F(i, "padding-right"))}px`, I(i, r, [
235
- "padding-left",
236
- "padding-right",
237
- "padding-top",
238
- "padding-bottom",
239
- "word-break",
240
- "overflow-wrap"
241
- ]), I(i, r, L), s = document.createElement("span"), s.textContent = "​", t.append(document.createTextNode(e.value.slice(0, n)), s);
242
- });
243
- try {
244
- let n = r.left + F(i, "border-left-width") + a + s.offsetLeft * t - e.scrollLeft, c = r.top + F(i, "border-top-width") + o + s.offsetTop * t - e.scrollTop;
245
- return {
246
- left: n,
247
- top: c,
248
- bottom: c + R(i) * t
249
- };
250
- } finally {
251
- c.remove();
252
- }
253
- }
254
- function V(e, t) {
255
- let n = e.selectionStart ?? e.value.length, r = e.getBoundingClientRect(), i = getComputedStyle(e), a = z((t, r) => {
256
- r.display = "inline-block", r.whiteSpace = "pre", I(i, r, L), t.textContent = e.value.slice(0, n);
257
- });
258
- try {
259
- let n = a.getBoundingClientRect().width || a.offsetWidth;
260
- return {
261
- left: r.left + F(i, "border-left-width") + F(i, "padding-left") + n * t - e.scrollLeft,
262
- top: r.top + F(i, "border-top-width"),
263
- bottom: r.bottom - F(i, "border-bottom-width")
264
- };
265
- } finally {
266
- a.remove();
267
- }
268
- }
269
- function H(e, t = 1) {
270
- return e instanceof HTMLTextAreaElement ? B(e, t) : V(e, t);
271
- }
272
- //#endregion
273
- export { T as a, x as c, E as i, b as l, P as n, w as o, N as r, S as s, H as t, y as u };
@@ -1,331 +0,0 @@
1
- import { a as e, r as t } from "./layerPath-uy2ywyld.js";
2
- import { a as n, c as r, l as i, n as a, o, s, t as c, u as l } from "./completionAnchor-CDR5YZhu.js";
3
- import { nextTick as u, onMounted as d, onScopeDispose as f, reactive as p, toValue as m, watch as h } from "vue";
4
- //#region ../canvas-editor/src/shared/expressionCandidates.ts
5
- function g(e) {
6
- return e.kind === "row" ? "row" : e.kind === "root" ? "$root" : e.name;
7
- }
8
- function _(e) {
9
- let t = {};
10
- return e.description !== void 0 && (t.description = e.description), e.title !== void 0 && (t.title = e.title), e.type !== void 0 && (t.type = e.type), t;
11
- }
12
- function v(e, t) {
13
- return {
14
- path: t === "" ? e.key : `${t}.${e.key}`,
15
- segment: e.key,
16
- ..._(e.node)
17
- };
18
- }
19
- function y(e, t, n) {
20
- let r = i(e), a = r.entries.map((e) => v(e, ""));
21
- return a.push({
22
- path: "$root",
23
- segment: "$root"
24
- }), t === "row" && (a.push(n ? {
25
- path: "row",
26
- segment: "row",
27
- ..._(n)
28
- } : {
29
- path: "row",
30
- segment: "row"
31
- }), a.push({
32
- path: "$index",
33
- segment: "$index"
34
- })), r.open === !0 ? {
35
- candidates: a,
36
- open: !0
37
- } : { candidates: a };
38
- }
39
- function b(e, t) {
40
- if (e === null) return {
41
- ok: !0,
42
- prefix: "",
43
- partial: "",
44
- candidates: []
45
- };
46
- let n = t.expr.endsWith("."), r = n ? t.expr.slice(0, -1) : t.expr;
47
- if (r === "") return t.expr === "" ? {
48
- ok: !0,
49
- prefix: "",
50
- partial: "",
51
- ...y(e, t.context, t.rowSchema)
52
- } : {
53
- ok: !1,
54
- reason: "expression_syntax_error"
55
- };
56
- let a = s(r);
57
- if (!a.ok) return {
58
- ok: !1,
59
- reason: "expression_syntax_error"
60
- };
61
- let { head: o, rest: c } = a, u, d;
62
- if (n ? (u = [g(o), ...c], d = "") : c.length > 0 ? (u = [g(o), ...c.slice(0, -1)], d = c[c.length - 1]) : (u = [], d = g(o)), u.length === 0) return {
63
- ok: !0,
64
- prefix: "",
65
- partial: d,
66
- ...y(e, t.context, t.rowSchema)
67
- };
68
- let f, p;
69
- if (o.kind === "row") {
70
- if (t.context !== "row") return {
71
- ok: !0,
72
- prefix: u.join("."),
73
- partial: d,
74
- candidates: []
75
- };
76
- f = t.rowSchema ?? null, p = u.slice(1);
77
- } else if (o.kind === "root") f = e, p = u.slice(1);
78
- else if (o.name === "$index") return {
79
- ok: !0,
80
- prefix: u.join("."),
81
- partial: d,
82
- candidates: []
83
- };
84
- else f = e, p = u;
85
- let m = f === null ? null : l(f, p), h = u.join(".");
86
- if (m === null) return {
87
- ok: !0,
88
- prefix: h,
89
- partial: d,
90
- candidates: []
91
- };
92
- let _ = i(m);
93
- return {
94
- ok: !0,
95
- prefix: h,
96
- partial: d,
97
- candidates: _.entries.map((e) => v(e, h)),
98
- ..._.open === !0 ? { open: !0 } : {}
99
- };
100
- }
101
- //#endregion
102
- //#region src/shared/expressionContext.ts
103
- function x(t, n, i) {
104
- let a = null;
105
- for (let o = 0; o < n.length; o += 1) {
106
- if (n[o] !== "template") continue;
107
- let s = e(t, n.slice(0, o));
108
- if (s === null || s.type !== "TableLayer" || (a = r(a ?? i, s.rowsPath), a === null)) return null;
109
- }
110
- return a;
111
- }
112
- function S(e) {
113
- return e[e.length - 1] === "content" && t(e);
114
- }
115
- function C(e, t, n) {
116
- return e === null || t === null || n === null || !S(n) ? {
117
- kind: "root",
118
- rowSchema: null
119
- } : {
120
- kind: "row",
121
- rowSchema: x(t, n, e)
122
- };
123
- }
124
- function w(e, t) {
125
- return e === null ? null : (n) => {
126
- let r = b(e, {
127
- context: t.kind,
128
- expr: n,
129
- rowSchema: t.rowSchema
130
- });
131
- return r.ok ? {
132
- partial: r.partial,
133
- candidates: r.candidates,
134
- ...r.open === !0 ? { open: !0 } : {}
135
- } : null;
136
- };
137
- }
138
- //#endregion
139
- //#region src/shared/useExpressionCompletion.ts
140
- var T = 4, E = [
141
- "ArrowLeft",
142
- "ArrowRight",
143
- "Home",
144
- "End",
145
- "PageUp",
146
- "PageDown"
147
- ];
148
- function D(e) {
149
- let t = p({
150
- open: !1,
151
- items: [],
152
- activeIndex: 0,
153
- top: 0,
154
- left: 0,
155
- openMapping: !1
156
- }), r = null, i = !1, s = null;
157
- function l() {
158
- t.open = !1, t.items = [], t.activeIndex = 0, t.openMapping = !1, s = null;
159
- }
160
- function g() {
161
- if (!t.open || !r) return;
162
- let n = c(r, m(e.scale ?? 1));
163
- t.top = n.bottom + T, t.left = _(n.left);
164
- }
165
- function _(t) {
166
- let n = (e.popupEl ? m(e.popupEl) : null)?.offsetWidth ?? 0;
167
- return n <= 0 ? t : Math.max(0, Math.min(t, window.innerWidth - 4 - n));
168
- }
169
- function v(i, a = !1) {
170
- if (!m(e.enabled)) {
171
- l();
172
- return;
173
- }
174
- let c = r;
175
- if (!c) {
176
- l();
177
- return;
178
- }
179
- let d = c.value, f = c.selectionStart ?? d.length, p = n(o(d), f);
180
- if (!p) {
181
- l();
182
- return;
183
- }
184
- let h = e.resolve(p.expr);
185
- if (!h) {
186
- l();
187
- return;
188
- }
189
- let _ = a ? h.candidates : h.candidates.filter((e) => e.segment.startsWith(h.partial));
190
- if (_.length === 0 && h.open !== !0) {
191
- l();
192
- return;
193
- }
194
- s = {
195
- fragment: p,
196
- partial: h.partial
197
- }, (t.open || i) && (t.items = _, t.activeIndex = 0, t.openMapping = h.open === !0, t.open = !0, g(), u(g));
198
- }
199
- function y(e) {
200
- let n = r;
201
- if (!t.open || i || !n || !s) return;
202
- let o = t.items[e ?? t.activeIndex];
203
- if (!o) return;
204
- let c = a(n.value, s.fragment, s.partial, o.segment);
205
- if (!c) {
206
- l();
207
- return;
208
- }
209
- n.value = c.value, n.setSelectionRange(c.cursor, c.cursor), n.dispatchEvent(new Event("input", { bubbles: !0 })), n.dispatchEvent(new Event("change", { bubbles: !0 })), l();
210
- }
211
- function b() {
212
- return m(e.pairing ?? e.enabled);
213
- }
214
- function x(e) {
215
- let t = e.selectionStart;
216
- return t === null || t !== e.selectionEnd ? null : t;
217
- }
218
- let S = !1;
219
- function C(e) {
220
- if (S || !b()) return;
221
- let t = r;
222
- if (!t) return;
223
- let n = e.inputType;
224
- if (n !== void 0 && n !== "" && n !== "insertText") return;
225
- let i = x(t);
226
- if (i === null || i < 2) return;
227
- let a = t.value;
228
- a.startsWith("{{", i - 2) && (a.includes("}}", i) || (S = !0, t.value = `${a.slice(0, i)}}}${a.slice(i)}`, t.setSelectionRange(i, i), t.dispatchEvent(new Event("input", { bubbles: !0 })), S = !1));
229
- }
230
- function w(e) {
231
- if (!b()) return !1;
232
- let t = r;
233
- if (!t) return !1;
234
- let n = x(t);
235
- if (n === null || n < 2) return !1;
236
- let i = t.value;
237
- return !i.startsWith("{{", n - 2) || !i.startsWith("}}", n) ? !1 : (e.preventDefault(), S = !0, t.value = i.slice(0, n - 2) + i.slice(n + 2), t.setSelectionRange(n - 2, n - 2), t.dispatchEvent(new Event("input", { bubbles: !0 })), S = !1, !0);
238
- }
239
- function D(e) {
240
- if (!b()) return !1;
241
- let t = r;
242
- if (!t) return !1;
243
- let n = x(t);
244
- return n === null || t.value[n] !== "}" ? !1 : (e.preventDefault(), t.setSelectionRange(n + 1, n + 1), v(!1), !0);
245
- }
246
- function O(e) {
247
- i || e.isComposing || (C(e), v(!0));
248
- }
249
- function k() {
250
- i = !0;
251
- }
252
- function A() {
253
- i = !1, v(!0);
254
- }
255
- function j(e) {
256
- return i || e.isComposing || e.keyCode === 229;
257
- }
258
- function M(e) {
259
- if (!j(e)) {
260
- if (e.key === " " && (e.ctrlKey || e.metaKey)) {
261
- e.preventDefault(), v(!0, !0);
262
- return;
263
- }
264
- if (!(e.key === "Backspace" && w(e)) && !(e.key === "}" && D(e)) && t.open) {
265
- if (e.key === "ArrowDown" || e.key === "ArrowUp") {
266
- e.preventDefault();
267
- let n = t.items.length;
268
- n > 0 && (t.activeIndex = (t.activeIndex + (e.key === "ArrowDown" ? 1 : n - 1)) % n);
269
- return;
270
- }
271
- if (e.key === "Enter" || e.key === "Tab") {
272
- e.preventDefault(), y();
273
- return;
274
- }
275
- e.key === "Escape" && (e.preventDefault(), l());
276
- }
277
- }
278
- }
279
- function N(e) {
280
- t.open && !j(e) && E.includes(e.key) && v(!1);
281
- }
282
- function P() {
283
- i || v(!1);
284
- }
285
- function F() {
286
- l();
287
- }
288
- function I(e) {
289
- t.open && e.target !== r && l();
290
- }
291
- function L() {
292
- g();
293
- }
294
- let R = [
295
- ["input", O],
296
- ["keydown", M],
297
- ["keyup", N],
298
- ["click", P],
299
- ["blur", F],
300
- ["compositionstart", k],
301
- ["compositionend", A]
302
- ];
303
- function z(e) {
304
- for (let [t, n] of R) e.addEventListener(t, n);
305
- }
306
- function B(e) {
307
- for (let [t, n] of R) e.removeEventListener(t, n);
308
- }
309
- function V(e) {
310
- r !== e && (r && B(r), r = e, e && z(e));
311
- }
312
- return d(() => V(e.target.value)), h(e.target, (e) => V(e)), h(() => m(e.enabled), (e) => {
313
- e || l();
314
- }), document.addEventListener("mousedown", I), window.addEventListener("scroll", L, !0), window.addEventListener("resize", L), f(() => {
315
- r && B(r), document.removeEventListener("mousedown", I), window.removeEventListener("scroll", L, !0), window.removeEventListener("resize", L);
316
- }), {
317
- popup: t,
318
- accept: y
319
- };
320
- }
321
- //#endregion
322
- //#region src/shared/uploadFile.ts
323
- async function O(e) {
324
- return {
325
- name: e.name,
326
- mime: e.type,
327
- bytes: new Uint8Array(await e.arrayBuffer())
328
- };
329
- }
330
- //#endregion
331
- export { C as i, D as n, w as r, O as t };