@craftile/editor 0.2.1 → 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.
- package/dist/PropertyField.vue_vue_type_script_setup_true_lang-D1Yv2X4j.js +245 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3534 -3410
- package/dist/ui.js +1 -1
- package/dist/utils.d.ts +27 -0
- package/package.json +5 -5
- package/dist/PropertyField.vue_vue_type_script_setup_true_lang-DgXjnxE2.js +0 -197
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { inject as C, computed as l, defineComponent as m, createElementBlock as f, openBlock as d, unref as u, normalizeClass as y, createCommentVNode as _, createElementVNode as c, renderSlot as A, ref as F, onMounted as P, watch as S, createBlock as g, resolveDynamicComponent as w, createTextVNode as B, toDisplayString as V } from "vue";
|
|
2
|
+
const k = Symbol.for("craftile-editor");
|
|
3
|
+
function v(e) {
|
|
4
|
+
return e && typeof e == "object" && (e.setup || e.render || e.__vccOpts || e.name || e.__v_skip);
|
|
5
|
+
}
|
|
6
|
+
function x(e) {
|
|
7
|
+
return typeof e == "string";
|
|
8
|
+
}
|
|
9
|
+
function N(e) {
|
|
10
|
+
return typeof e == "function" && !v(e);
|
|
11
|
+
}
|
|
12
|
+
function M(e) {
|
|
13
|
+
return "field" in e && "operator" in e;
|
|
14
|
+
}
|
|
15
|
+
function R(e) {
|
|
16
|
+
return "and" in e || "or" in e;
|
|
17
|
+
}
|
|
18
|
+
function z(e, t) {
|
|
19
|
+
const { field: r, operator: s, value: i } = e, n = t?.[r];
|
|
20
|
+
switch (s) {
|
|
21
|
+
case "equals":
|
|
22
|
+
return n === i;
|
|
23
|
+
case "not_equals":
|
|
24
|
+
return n !== i;
|
|
25
|
+
case "in":
|
|
26
|
+
return Array.isArray(i) ? i.includes(n) : !1;
|
|
27
|
+
case "not_in":
|
|
28
|
+
return Array.isArray(i) ? !i.includes(n) : !0;
|
|
29
|
+
case "contains":
|
|
30
|
+
return Array.isArray(n) || typeof n == "string" && typeof i == "string" ? n.includes(i) : !1;
|
|
31
|
+
case "greater_than": {
|
|
32
|
+
const o = Number(n), a = Number(i);
|
|
33
|
+
return !Number.isFinite(o) || !Number.isFinite(a) ? !1 : o > a;
|
|
34
|
+
}
|
|
35
|
+
case "less_than": {
|
|
36
|
+
const o = Number(n), a = Number(i);
|
|
37
|
+
return !Number.isFinite(o) || !Number.isFinite(a) ? !1 : o < a;
|
|
38
|
+
}
|
|
39
|
+
case "truthy":
|
|
40
|
+
return !!n;
|
|
41
|
+
case "falsy":
|
|
42
|
+
return !n;
|
|
43
|
+
default:
|
|
44
|
+
return !1;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function p(e, t = {}) {
|
|
48
|
+
if (Array.isArray(e))
|
|
49
|
+
return e.every((r) => p(r, t));
|
|
50
|
+
if (!e || typeof e != "object") return !0;
|
|
51
|
+
if (R(e)) {
|
|
52
|
+
if (e.and)
|
|
53
|
+
return Array.isArray(e.and) ? e.and.every((r) => p(r, t)) : !0;
|
|
54
|
+
if (e.or)
|
|
55
|
+
return Array.isArray(e.or) ? e.or.some((r) => p(r, t)) : !1;
|
|
56
|
+
}
|
|
57
|
+
return M(e) ? z(e, t) : !0;
|
|
58
|
+
}
|
|
59
|
+
function H() {
|
|
60
|
+
const e = C(k);
|
|
61
|
+
if (!e)
|
|
62
|
+
throw new Error("useUI must be used within a component that has access to CraftileEditor");
|
|
63
|
+
const t = (r) => {
|
|
64
|
+
e.ui.state.activeSidebarPanel = r;
|
|
65
|
+
};
|
|
66
|
+
return {
|
|
67
|
+
toaster: e.ui.toaster,
|
|
68
|
+
sidebarPanels: l(
|
|
69
|
+
() => Array.from(e.ui.state.sidebarPanels.values()).sort((r, s) => (r.order ?? 0) - (s.order ?? 0))
|
|
70
|
+
),
|
|
71
|
+
activeSidebarPanel: l(() => e.ui.state.activeSidebarPanel),
|
|
72
|
+
registerSidebarPanel: e.ui.registerSidebarPanel.bind(e.ui),
|
|
73
|
+
removeSidebarPanel: e.ui.removeSidebarPanel.bind(e.ui),
|
|
74
|
+
setActiveSidebarPanel: t,
|
|
75
|
+
headerActions: l(
|
|
76
|
+
() => Array.from(e.ui.state.headerActions.values()).sort((r, s) => (r.order ?? 0) - (s.order ?? 0))
|
|
77
|
+
),
|
|
78
|
+
registerHeaderAction: e.ui.registerHeaderAction.bind(e.ui),
|
|
79
|
+
removeHeaderAction: e.ui.removeHeaderAction.bind(e.ui),
|
|
80
|
+
configurationPanels: l(
|
|
81
|
+
() => Array.from(e.ui.state.configurationPanels.values()).sort((r, s) => (r.order ?? 0) - (s.order ?? 0))
|
|
82
|
+
),
|
|
83
|
+
registerConfigurationPanel: e.ui.registerConfigurationPanel.bind(e.ui),
|
|
84
|
+
removeConfigurationPanel: e.ui.removeConfigurationPanel.bind(e.ui),
|
|
85
|
+
modals: l(() => e.ui.state.modals),
|
|
86
|
+
openModals: l(() => e.ui.state.openModals),
|
|
87
|
+
openModal: e.ui.openModal.bind(e.ui),
|
|
88
|
+
closeModal: e.ui.closeModal.bind(e.ui),
|
|
89
|
+
propertyFields: l(() => e.ui.state.propertyFields),
|
|
90
|
+
registerPropertyField: e.ui.registerPropertyField.bind(e.ui),
|
|
91
|
+
removePropertyField: e.ui.removePropertyField.bind(e.ui),
|
|
92
|
+
keyboardShortcuts: l(() => e.ui.state.keyboardShortcuts),
|
|
93
|
+
registerKeyboardShortcut: e.ui.registerKeyboardShortcut.bind(e.ui),
|
|
94
|
+
removeKeyboardShortcut: e.ui.removeKeyboardShortcut.bind(e.ui)
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const E = ["type", "disabled"], q = {
|
|
98
|
+
key: 0,
|
|
99
|
+
class: "animate-spin h-4 w-4 absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2",
|
|
100
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
101
|
+
fill: "none",
|
|
102
|
+
viewBox: "0 0 24 24"
|
|
103
|
+
}, L = /* @__PURE__ */ m({
|
|
104
|
+
__name: "Button",
|
|
105
|
+
props: {
|
|
106
|
+
variant: { default: "default" },
|
|
107
|
+
size: { default: "md" },
|
|
108
|
+
type: { default: "button" },
|
|
109
|
+
disabled: { type: Boolean, default: !1 },
|
|
110
|
+
fullWidth: { type: Boolean, default: !1 },
|
|
111
|
+
square: { type: Boolean, default: !1 },
|
|
112
|
+
loading: { type: Boolean, default: !1 }
|
|
113
|
+
},
|
|
114
|
+
setup(e) {
|
|
115
|
+
const t = {
|
|
116
|
+
default: "bg-white text-gray-900 hover:bg-gray-50 border border-gray-200",
|
|
117
|
+
primary: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
118
|
+
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/90",
|
|
119
|
+
accent: "bg-accent text-accent-foreground hover:bg-accent/90",
|
|
120
|
+
sutble: "bg-accent-foreground text-accent",
|
|
121
|
+
destructive: "bg-red-600 text-white hover:bg-red-700"
|
|
122
|
+
}, r = {
|
|
123
|
+
sm: "h-6 px-3 text-xs",
|
|
124
|
+
md: "h-8 px-4",
|
|
125
|
+
lg: "h-10 px-6 text-base"
|
|
126
|
+
}, s = {
|
|
127
|
+
sm: "w-6 h-6 text-xs p-0",
|
|
128
|
+
md: "w-8 h-8 p-0",
|
|
129
|
+
lg: "w-10 h-10 text-base p-0"
|
|
130
|
+
}, i = e, n = l(() => i.disabled || i.loading);
|
|
131
|
+
return (o, a) => (d(), f("button", {
|
|
132
|
+
class: y(["inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:opacity-50 disabled:pointer-events-none cursor-pointer relative", [
|
|
133
|
+
t[o.variant],
|
|
134
|
+
i.square ? s[o.size] : r[o.size],
|
|
135
|
+
o.fullWidth && "w-full"
|
|
136
|
+
]]),
|
|
137
|
+
type: o.type,
|
|
138
|
+
disabled: u(n)
|
|
139
|
+
}, [
|
|
140
|
+
o.loading ? (d(), f("svg", q, [...a[0] || (a[0] = [
|
|
141
|
+
c("circle", {
|
|
142
|
+
class: "opacity-25",
|
|
143
|
+
cx: "12",
|
|
144
|
+
cy: "12",
|
|
145
|
+
r: "10",
|
|
146
|
+
stroke: "currentColor",
|
|
147
|
+
"stroke-width": "4"
|
|
148
|
+
}, null, -1),
|
|
149
|
+
c("path", {
|
|
150
|
+
class: "opacity-75",
|
|
151
|
+
fill: "currentColor",
|
|
152
|
+
d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
|
153
|
+
}, null, -1)
|
|
154
|
+
])])) : _("", !0),
|
|
155
|
+
c("span", {
|
|
156
|
+
class: y(["inline-flex items-center gap-2", { invisible: o.loading }])
|
|
157
|
+
}, [
|
|
158
|
+
A(o.$slots, "default")
|
|
159
|
+
], 2)
|
|
160
|
+
], 10, E));
|
|
161
|
+
}
|
|
162
|
+
}), I = /* @__PURE__ */ m({
|
|
163
|
+
__name: "PropertyFieldRenderWrapper",
|
|
164
|
+
props: {
|
|
165
|
+
renderFn: { type: Function },
|
|
166
|
+
field: {},
|
|
167
|
+
value: {},
|
|
168
|
+
onChange: { type: Function },
|
|
169
|
+
onBlur: { type: Function },
|
|
170
|
+
class: {}
|
|
171
|
+
},
|
|
172
|
+
setup(e) {
|
|
173
|
+
const t = e, r = F(), s = () => {
|
|
174
|
+
if (r.value && t.renderFn) {
|
|
175
|
+
r.value.innerHTML = "";
|
|
176
|
+
const i = t.renderFn({
|
|
177
|
+
field: t.field,
|
|
178
|
+
value: t.value,
|
|
179
|
+
onChange: t.onChange,
|
|
180
|
+
onBlur: t.onBlur
|
|
181
|
+
});
|
|
182
|
+
r.value.appendChild(i);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
return P(() => {
|
|
186
|
+
s();
|
|
187
|
+
}), S(
|
|
188
|
+
() => t.value,
|
|
189
|
+
() => {
|
|
190
|
+
s();
|
|
191
|
+
}
|
|
192
|
+
), (i, n) => (d(), f("div", {
|
|
193
|
+
ref_key: "containerRef",
|
|
194
|
+
ref: r,
|
|
195
|
+
class: y(t.class)
|
|
196
|
+
}, null, 2));
|
|
197
|
+
}
|
|
198
|
+
}), $ = {
|
|
199
|
+
key: 2,
|
|
200
|
+
class: "mb-4 p-3 bg-red-50 border border-red-200 rounded-md"
|
|
201
|
+
}, j = { class: "text-sm text-red-600" }, D = { class: "font-mono" }, T = /* @__PURE__ */ m({
|
|
202
|
+
__name: "PropertyField",
|
|
203
|
+
props: {
|
|
204
|
+
field: {},
|
|
205
|
+
modelValue: {}
|
|
206
|
+
},
|
|
207
|
+
emits: ["update:modelValue"],
|
|
208
|
+
setup(e, { emit: t }) {
|
|
209
|
+
const r = e, s = t, { propertyFields: i } = H(), n = l(() => i.value.get(r.field.type)?.render), o = (a) => {
|
|
210
|
+
s("update:modelValue", a);
|
|
211
|
+
};
|
|
212
|
+
return (a, b) => {
|
|
213
|
+
const h = I;
|
|
214
|
+
return d(), f("div", null, [
|
|
215
|
+
u(v)(u(n)) || u(x)(u(n)) ? (d(), g(w(u(n)), {
|
|
216
|
+
key: 0,
|
|
217
|
+
field: a.field,
|
|
218
|
+
"model-value": a.modelValue,
|
|
219
|
+
"onUpdate:modelValue": o
|
|
220
|
+
}, null, 8, ["field", "model-value"])) : u(N)(u(n)) ? (d(), g(h, {
|
|
221
|
+
key: 1,
|
|
222
|
+
"render-fn": u(n),
|
|
223
|
+
field: a.field,
|
|
224
|
+
value: a.modelValue,
|
|
225
|
+
"on-change": o
|
|
226
|
+
}, null, 8, ["render-fn", "field", "value"])) : (d(), f("div", $, [
|
|
227
|
+
c("p", j, [
|
|
228
|
+
b[0] || (b[0] = B(" Unknown field type: ", -1)),
|
|
229
|
+
c("code", D, V(a.field.type), 1)
|
|
230
|
+
])
|
|
231
|
+
]))
|
|
232
|
+
]);
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
export {
|
|
237
|
+
k as C,
|
|
238
|
+
L as _,
|
|
239
|
+
T as a,
|
|
240
|
+
x as b,
|
|
241
|
+
N as c,
|
|
242
|
+
p as e,
|
|
243
|
+
v as i,
|
|
244
|
+
H as u
|
|
245
|
+
};
|
package/dist/index.d.ts
CHANGED