@craftile/editor 0.3.1 → 0.4.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/ui.js
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ResponsiveValue } from '@craftile/types';
|
|
2
|
+
/**
|
|
3
|
+
* Check if a value is a responsive value object
|
|
4
|
+
*/
|
|
5
|
+
export declare function isResponsiveValue(value: any): value is ResponsiveValue;
|
|
6
|
+
/**
|
|
7
|
+
* Get value for a specific device, falling back to _default if not set
|
|
8
|
+
* @param value - The property value (responsive or simple)
|
|
9
|
+
* @param deviceId - The device preset ID
|
|
10
|
+
* @returns The value for the device or the base value
|
|
11
|
+
*/
|
|
12
|
+
export declare function getDeviceValue<T = any>(value: ResponsiveValue<T> | T, deviceId: string): T;
|
|
13
|
+
/**
|
|
14
|
+
* Set value for a specific device
|
|
15
|
+
* Converts simple values to responsive format if needed
|
|
16
|
+
* @param currentValue - The current property value
|
|
17
|
+
* @param deviceId - The device preset ID
|
|
18
|
+
* @param newValue - The new value to set for this device
|
|
19
|
+
* @returns Updated responsive value
|
|
20
|
+
*/
|
|
21
|
+
export declare function setDeviceValue<T = any>(currentValue: ResponsiveValue<T> | T, deviceId: string, newValue: T): ResponsiveValue<T>;
|
|
22
|
+
/**
|
|
23
|
+
* Check if a device has a custom override value
|
|
24
|
+
* @param value - The property value
|
|
25
|
+
* @param deviceId - The device preset ID
|
|
26
|
+
* @returns true if the device has a custom value
|
|
27
|
+
*/
|
|
28
|
+
export declare function hasDeviceOverride(value: any, deviceId: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Clear device override (remove device-specific value)
|
|
31
|
+
* The device will inherit from _default after this
|
|
32
|
+
* @param value - The responsive value
|
|
33
|
+
* @param deviceId - The device preset ID to clear
|
|
34
|
+
* @returns Updated responsive value without the device override
|
|
35
|
+
*/
|
|
36
|
+
export declare function clearDeviceOverride<T = any>(value: ResponsiveValue<T>, deviceId: string): ResponsiveValue<T>;
|
|
37
|
+
/**
|
|
38
|
+
* Get list of all devices that have custom overrides
|
|
39
|
+
* @param value - The responsive value
|
|
40
|
+
* @returns Array of device IDs that have custom values
|
|
41
|
+
*/
|
|
42
|
+
export declare function getOverriddenDevices(value: ResponsiveValue): string[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@craftile/editor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Vue.js-based editor UI components for craftile blocks engine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"craftile",
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"vue": "^3.5.17",
|
|
40
40
|
"vue-draggable-plus": "^0.6.0",
|
|
41
|
-
"@craftile/
|
|
42
|
-
"@craftile/
|
|
43
|
-
"@craftile/messenger": "0.
|
|
44
|
-
"@craftile/types": "0.
|
|
41
|
+
"@craftile/core": "0.4.0",
|
|
42
|
+
"@craftile/event-bus": "0.4.0",
|
|
43
|
+
"@craftile/messenger": "0.4.0",
|
|
44
|
+
"@craftile/types": "0.4.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@ark-ui/vue": "^5.24.1",
|
|
@@ -1,245 +0,0 @@
|
|
|
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
|
-
};
|