@former-ui/former 0.1.0 → 0.2.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/README.md +15 -3
- package/dist/components/FormAdd.d.ts +8 -9
- package/dist/components/FormContent.d.ts +2 -1
- package/dist/components/FormDataProvider.d.ts +12 -15
- package/dist/components/FormDragContainer.d.ts +11 -13
- package/dist/components/FormNode.d.ts +11 -13
- package/dist/components/FormNodeProps.d.ts +18 -15
- package/dist/components/FormRenderer.d.ts +4 -4
- package/dist/components/Former.d.ts +18 -19
- package/dist/compositions/injectProvide.d.ts +2 -2
- package/dist/compositions/useHasContent.d.ts +1 -1
- package/dist/compositions/useNode.d.ts +1 -1
- package/dist/compositions/useSchema.d.ts +1 -1
- package/dist/index.css +397 -239
- package/dist/index.js +92 -28
- package/dist/index.umd.cjs +91 -27
- package/dist/utils.d.ts +1 -0
- package/dist/validation.d.ts +1 -1
- package/package.json +19 -19
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getCurrentInstance, inject as inject$1, provide as provide$1, defineComponent, ref, computed,
|
|
1
|
+
import { getCurrentInstance, inject as inject$1, provide as provide$1, defineComponent, ref, computed, unref, openBlock, createElementBlock, createElementVNode, Fragment, renderList, toDisplayString, createBlock, resolveDynamicComponent, withCtx, renderSlot, createCommentVNode, normalizeClass, shallowRef, watch, toRaw, toValue, onBeforeUnmount, toRef, withModifiers, mergeProps, isRef, onMounted, onUnmounted, useModel, createVNode, mergeModels } from "vue";
|
|
2
2
|
function inject(key, failIfNotProvided = true) {
|
|
3
3
|
if (!getCurrentInstance()) {
|
|
4
4
|
return void 0;
|
|
@@ -137,7 +137,11 @@ function deleteNode(schema, nodeId) {
|
|
|
137
137
|
function nodePosition(schema, nodeId, anchor, parentId, category) {
|
|
138
138
|
for (let i = 0; i < schema.length; i++) {
|
|
139
139
|
if (schema[i]._id === nodeId) {
|
|
140
|
-
return {
|
|
140
|
+
return {
|
|
141
|
+
parentId: parentId || null,
|
|
142
|
+
index: anchor === "above" ? i : i + 1,
|
|
143
|
+
category: category || null
|
|
144
|
+
};
|
|
141
145
|
}
|
|
142
146
|
const children = schema[i].children;
|
|
143
147
|
if (children) {
|
|
@@ -212,6 +216,18 @@ function getNode(schema, nodeId) {
|
|
|
212
216
|
}
|
|
213
217
|
return null;
|
|
214
218
|
}
|
|
219
|
+
function getNodePath(schema, nodeId) {
|
|
220
|
+
for (const node of schema) {
|
|
221
|
+
if (node._id === nodeId) {
|
|
222
|
+
return [];
|
|
223
|
+
}
|
|
224
|
+
const path = getNodePath(nodeChildren(node), nodeId);
|
|
225
|
+
if (path) {
|
|
226
|
+
return [node, ...path];
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
215
231
|
function propsOf(node) {
|
|
216
232
|
return Object.fromEntries(Object.entries(node.props ?? {}).filter(([, value]) => value !== null));
|
|
217
233
|
}
|
|
@@ -248,12 +264,29 @@ function dataScopesOfChildren(node, data, scopes, components) {
|
|
|
248
264
|
if (isListNode(node, nodeData, components)) {
|
|
249
265
|
return scopes;
|
|
250
266
|
}
|
|
251
|
-
return [
|
|
267
|
+
return [
|
|
268
|
+
{
|
|
269
|
+
node,
|
|
270
|
+
data: nodeData,
|
|
271
|
+
path: dataPathOfNode(node, scopes, components)
|
|
272
|
+
},
|
|
273
|
+
...scopes
|
|
274
|
+
];
|
|
252
275
|
}
|
|
253
276
|
function dataScopesOfListItem(list, item, index, scopes) {
|
|
254
277
|
var _a;
|
|
255
|
-
const listPath = [
|
|
256
|
-
|
|
278
|
+
const listPath = [
|
|
279
|
+
...((_a = scopes[0]) == null ? void 0 : _a.path) ?? [],
|
|
280
|
+
...(list == null ? void 0 : list.name) ? [list.name] : []
|
|
281
|
+
];
|
|
282
|
+
return [
|
|
283
|
+
{
|
|
284
|
+
node: list,
|
|
285
|
+
data: item,
|
|
286
|
+
path: [...listPath, index]
|
|
287
|
+
},
|
|
288
|
+
...scopes
|
|
289
|
+
];
|
|
257
290
|
}
|
|
258
291
|
function unsetDataOfNode(node, data, components) {
|
|
259
292
|
if (data === void 0 || data === null || typeof data !== "object" || Array.isArray(data)) {
|
|
@@ -486,7 +519,7 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
|
|
|
486
519
|
"former-drag-container min-h-24 w-full border-2 dark:border-zinc-400 border-dashed rounded-md border-zinc-200 empty:before:block empty:bg-zinc-100 empty:dark:bg-zinc-700": unref(mode) === "build"
|
|
487
520
|
}]),
|
|
488
521
|
"data-parent-node": (_a = unref(node)) == null ? void 0 : _a._id,
|
|
489
|
-
"data-category":
|
|
522
|
+
"data-category": __props.category,
|
|
490
523
|
"data-drag-hint": unref(texts).dragHint
|
|
491
524
|
}, [
|
|
492
525
|
renderSlot(_ctx.$slots, "default")
|
|
@@ -2396,7 +2429,7 @@ function requireLodash() {
|
|
|
2396
2429
|
return symbolToString ? symbolToString.call(value) : "";
|
|
2397
2430
|
}
|
|
2398
2431
|
var result2 = value + "";
|
|
2399
|
-
return result2 == "0" && 1 / value == -
|
|
2432
|
+
return result2 == "0" && 1 / value == -INFINITY ? "-0" : result2;
|
|
2400
2433
|
}
|
|
2401
2434
|
function baseUniq(array, iteratee2, comparator) {
|
|
2402
2435
|
var index = -1, includes2 = arrayIncludes, length = array.length, isCommon = true, result2 = [], seen = result2;
|
|
@@ -3616,7 +3649,7 @@ function requireLodash() {
|
|
|
3616
3649
|
return value;
|
|
3617
3650
|
}
|
|
3618
3651
|
var result2 = value + "";
|
|
3619
|
-
return result2 == "0" && 1 / value == -
|
|
3652
|
+
return result2 == "0" && 1 / value == -INFINITY ? "-0" : result2;
|
|
3620
3653
|
}
|
|
3621
3654
|
function toSource(func) {
|
|
3622
3655
|
if (func != null) {
|
|
@@ -4680,7 +4713,7 @@ function requireLodash() {
|
|
|
4680
4713
|
}
|
|
4681
4714
|
var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
|
|
4682
4715
|
function isSafeInteger(value) {
|
|
4683
|
-
return isInteger(value) && value >= -
|
|
4716
|
+
return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
|
|
4684
4717
|
}
|
|
4685
4718
|
var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
|
|
4686
4719
|
function isString(value) {
|
|
@@ -4721,7 +4754,7 @@ function requireLodash() {
|
|
|
4721
4754
|
return value === 0 ? value : 0;
|
|
4722
4755
|
}
|
|
4723
4756
|
value = toNumber(value);
|
|
4724
|
-
if (value === INFINITY || value === -
|
|
4757
|
+
if (value === INFINITY || value === -INFINITY) {
|
|
4725
4758
|
var sign = value < 0 ? -1 : 1;
|
|
4726
4759
|
return sign * MAX_INTEGER;
|
|
4727
4760
|
}
|
|
@@ -4756,7 +4789,7 @@ function requireLodash() {
|
|
|
4756
4789
|
return copyObject(value, keysIn(value));
|
|
4757
4790
|
}
|
|
4758
4791
|
function toSafeInteger(value) {
|
|
4759
|
-
return value ? baseClamp(toInteger(value), -
|
|
4792
|
+
return value ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER) : value === 0 ? value : 0;
|
|
4760
4793
|
}
|
|
4761
4794
|
function toString(value) {
|
|
4762
4795
|
return value == null ? "" : baseToString(value);
|
|
@@ -6037,7 +6070,11 @@ function areNodesValid(nodes, data, scopes, components) {
|
|
|
6037
6070
|
var _a, _b;
|
|
6038
6071
|
const nodeData = dataOfNode(node, data, components);
|
|
6039
6072
|
const results = [
|
|
6040
|
-
validateComponent(components, node, nodeData, {
|
|
6073
|
+
validateComponent(components, node, nodeData, {
|
|
6074
|
+
node,
|
|
6075
|
+
path: dataPathOfNode(node, scopes, components),
|
|
6076
|
+
scopes
|
|
6077
|
+
})
|
|
6041
6078
|
];
|
|
6042
6079
|
const children = ((_b = (_a = components[node.type]) == null ? void 0 : _a.shownChildren) == null ? void 0 : _b.call(_a, node)) ?? nodeChildren(node);
|
|
6043
6080
|
if (isListNode(node, nodeData, components)) {
|
|
@@ -6055,7 +6092,9 @@ function isNodeValid(node, components) {
|
|
|
6055
6092
|
return false;
|
|
6056
6093
|
}
|
|
6057
6094
|
const propsData = { $name: node.name, ...node.props };
|
|
6058
|
-
return areNodesValid(component.propsSchema, propsData, [
|
|
6095
|
+
return areNodesValid(component.propsSchema, propsData, [
|
|
6096
|
+
{ data: propsData, path: [] }
|
|
6097
|
+
], components);
|
|
6059
6098
|
}
|
|
6060
6099
|
function errorMessage(error) {
|
|
6061
6100
|
return error instanceof Error ? error.message : String(error);
|
|
@@ -6074,9 +6113,13 @@ function useMaybeAsync(getter, initial, onError) {
|
|
|
6074
6113
|
let latestRun = 0;
|
|
6075
6114
|
watch(() => {
|
|
6076
6115
|
try {
|
|
6077
|
-
return {
|
|
6116
|
+
return {
|
|
6117
|
+
value: getter()
|
|
6118
|
+
};
|
|
6078
6119
|
} catch (error) {
|
|
6079
|
-
return {
|
|
6120
|
+
return {
|
|
6121
|
+
value: Promise.reject(error)
|
|
6122
|
+
};
|
|
6080
6123
|
}
|
|
6081
6124
|
}, ({ value }) => {
|
|
6082
6125
|
const run = ++latestRun;
|
|
@@ -6172,7 +6215,9 @@ function useNode(node) {
|
|
|
6172
6215
|
});
|
|
6173
6216
|
provide("hasDataKey", hasDataKey);
|
|
6174
6217
|
const parentDataScopes = inject("dataScopes", false);
|
|
6175
|
-
const dataScopes = computed(() => (parentDataScopes == null ? void 0 : parentDataScopes.value) ?? [
|
|
6218
|
+
const dataScopes = computed(() => (parentDataScopes == null ? void 0 : parentDataScopes.value) ?? [
|
|
6219
|
+
{ data: data.value, path: [] }
|
|
6220
|
+
]);
|
|
6176
6221
|
const dataPath = computed(() => dataPathOfNode(node.value, dataScopes.value, components.value));
|
|
6177
6222
|
provide("dataScopes", computed(() => dataScopesOfChildren(node.value, data.value, dataScopes.value, components.value)));
|
|
6178
6223
|
const validationContext = computed(() => ({
|
|
@@ -6520,7 +6565,9 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
|
|
|
6520
6565
|
type: newNodeType,
|
|
6521
6566
|
props: {}
|
|
6522
6567
|
};
|
|
6523
|
-
const _schema = [
|
|
6568
|
+
const _schema = [
|
|
6569
|
+
...toValue(schema.value)
|
|
6570
|
+
];
|
|
6524
6571
|
addNode(_schema, newPosition, newNode);
|
|
6525
6572
|
schema.value = _schema;
|
|
6526
6573
|
selectedNode.value = newNode;
|
|
@@ -6547,7 +6594,9 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
|
|
|
6547
6594
|
isDropping.value = false;
|
|
6548
6595
|
return;
|
|
6549
6596
|
}
|
|
6550
|
-
const _schema = [
|
|
6597
|
+
const _schema = [
|
|
6598
|
+
...toValue(schema.value)
|
|
6599
|
+
];
|
|
6551
6600
|
deleteNode(_schema, nodeId);
|
|
6552
6601
|
if (currentPosition.parentId === newPosition.parentId && currentPosition.index < newPosition.index) {
|
|
6553
6602
|
newPosition.index--;
|
|
@@ -6619,7 +6668,9 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
|
|
|
6619
6668
|
});
|
|
6620
6669
|
function useSchema(schema, components) {
|
|
6621
6670
|
const { result, isPending } = useMaybeAsync(() => {
|
|
6622
|
-
const nodes = [
|
|
6671
|
+
const nodes = [
|
|
6672
|
+
...schemaIterator(schema.value)
|
|
6673
|
+
];
|
|
6623
6674
|
const results = nodes.map((node) => propsValidityOfNode(node, toValue(components)));
|
|
6624
6675
|
const byId = (resolved) => Object.fromEntries(nodes.map((node, index) => [node._id, resolved[index]]));
|
|
6625
6676
|
return results.some(isPromiseLike) ? Promise.all(results).then(byId) : byId(results);
|
|
@@ -6634,20 +6685,19 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
6634
6685
|
components: {},
|
|
6635
6686
|
showIf: {},
|
|
6636
6687
|
mode: { default: "edit" },
|
|
6637
|
-
texts: { default: () => ({}) }
|
|
6638
|
-
isUpdating: { type: Boolean, default: false }
|
|
6688
|
+
texts: { default: () => ({}) }
|
|
6639
6689
|
}, {
|
|
6640
6690
|
"schema": { required: true },
|
|
6641
6691
|
"schemaModifiers": {},
|
|
6642
|
-
"data": {
|
|
6692
|
+
"data": {
|
|
6693
|
+
default: () => ({})
|
|
6694
|
+
},
|
|
6643
6695
|
"dataModifiers": {}
|
|
6644
6696
|
}),
|
|
6645
6697
|
emits: /* @__PURE__ */ mergeModels(["valid", "schemaValid"], ["update:schema", "update:data"]),
|
|
6646
6698
|
setup(__props, { emit: __emit }) {
|
|
6647
6699
|
const props = __props;
|
|
6648
6700
|
const emit = __emit;
|
|
6649
|
-
const isUpdating = toRef(props, "isUpdating");
|
|
6650
|
-
provide("formerIsUpdating", isUpdating);
|
|
6651
6701
|
const schema = useModel(__props, "schema");
|
|
6652
6702
|
const internalSchema = ref([]);
|
|
6653
6703
|
provide("schema", internalSchema);
|
|
@@ -6687,7 +6737,9 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
6687
6737
|
}
|
|
6688
6738
|
return props.showIf(node, wrappedData.value, schema.value);
|
|
6689
6739
|
});
|
|
6690
|
-
provide("dataScopes", computed(() => [
|
|
6740
|
+
provide("dataScopes", computed(() => [
|
|
6741
|
+
{ data: wrappedData.value, path: [] }
|
|
6742
|
+
]));
|
|
6691
6743
|
const { isValid: isSchemaValid, propsValidity } = useSchema(internalSchema, toRef(props, "components"));
|
|
6692
6744
|
provide("propsValidity", propsValidity);
|
|
6693
6745
|
watch(isSchemaValid, () => {
|
|
@@ -6709,10 +6761,15 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
6709
6761
|
);
|
|
6710
6762
|
const selectedNode = ref(void 0);
|
|
6711
6763
|
provide("selectedNode", selectedNode);
|
|
6764
|
+
const selectedNodePath = computed(() => selectedNode.value ? getNodePath(internalSchema.value, selectedNode.value._id) ?? [] : []);
|
|
6765
|
+
provide("selectedNodePath", selectedNodePath);
|
|
6712
6766
|
const texts = toRef(props, "texts");
|
|
6713
6767
|
provide("texts", computed(() => ({ dragHint: "Here you can drag elements", invalidSchema: "Invalid schema", ...texts.value })));
|
|
6714
6768
|
return (_ctx, _cache) => {
|
|
6715
|
-
return renderSlot(_ctx.$slots, "default", {
|
|
6769
|
+
return renderSlot(_ctx.$slots, "default", {
|
|
6770
|
+
selectedNode: selectedNode.value,
|
|
6771
|
+
selectedNodePath: selectedNodePath.value
|
|
6772
|
+
}, () => [
|
|
6716
6773
|
createVNode(_sfc_main$3)
|
|
6717
6774
|
]);
|
|
6718
6775
|
};
|
|
@@ -6737,6 +6794,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
6737
6794
|
const components = inject("components");
|
|
6738
6795
|
const schema = inject("schema");
|
|
6739
6796
|
const selectedNode = inject("selectedNode");
|
|
6797
|
+
const selectedNodePath = computed(() => selectedNode.value ? getNodePath(schema.value, selectedNode.value._id) ?? [] : []);
|
|
6740
6798
|
const selectedNodeType = computed(() => selectedNode.value ? components.value[selectedNode.value.type] : void 0);
|
|
6741
6799
|
const selectedNodePropsSchema = ref();
|
|
6742
6800
|
watch(
|
|
@@ -6810,6 +6868,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
6810
6868
|
]),
|
|
6811
6869
|
renderSlot(_ctx.$slots, "node-actions", {
|
|
6812
6870
|
node: unref(toSchemaNode)(unref(selectedNode)),
|
|
6871
|
+
path: selectedNodePath.value.map(unref(toSchemaNode)),
|
|
6813
6872
|
addNode: addNode$1,
|
|
6814
6873
|
removeNode
|
|
6815
6874
|
})
|
|
@@ -6831,7 +6890,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
6831
6890
|
components: unref(components),
|
|
6832
6891
|
onValid: _cache[1] || (_cache[1] = ($event) => _ctx.$emit("valid", $event))
|
|
6833
6892
|
}, null, 8, ["data", "schema", "components"])) : (openBlock(), createElementBlock("pre", _hoisted_6, toDisplayString(unref(selectedNode)), 1))
|
|
6834
|
-
])) : renderSlot(_ctx.$slots, "nothing-selected", {
|
|
6893
|
+
])) : renderSlot(_ctx.$slots, "nothing-selected", {}, void 0, void 0, 1);
|
|
6835
6894
|
};
|
|
6836
6895
|
}
|
|
6837
6896
|
});
|
|
@@ -6850,7 +6909,12 @@ function usePresetValue(modelValue, preset) {
|
|
|
6850
6909
|
}
|
|
6851
6910
|
}
|
|
6852
6911
|
onMounted(applyPreset);
|
|
6853
|
-
watch([
|
|
6912
|
+
watch([
|
|
6913
|
+
() => toValue(preset),
|
|
6914
|
+
() => mode == null ? void 0 : mode.value,
|
|
6915
|
+
() => hasDataKey == null ? void 0 : hasDataKey.value,
|
|
6916
|
+
() => isShown == null ? void 0 : isShown.value
|
|
6917
|
+
], applyPreset);
|
|
6854
6918
|
}
|
|
6855
6919
|
export {
|
|
6856
6920
|
_sfc_main$7 as FormAdd,
|
package/dist/index.umd.cjs
CHANGED
|
@@ -140,7 +140,11 @@
|
|
|
140
140
|
function nodePosition(schema, nodeId, anchor, parentId, category) {
|
|
141
141
|
for (let i = 0; i < schema.length; i++) {
|
|
142
142
|
if (schema[i]._id === nodeId) {
|
|
143
|
-
return {
|
|
143
|
+
return {
|
|
144
|
+
parentId: parentId || null,
|
|
145
|
+
index: anchor === "above" ? i : i + 1,
|
|
146
|
+
category: category || null
|
|
147
|
+
};
|
|
144
148
|
}
|
|
145
149
|
const children = schema[i].children;
|
|
146
150
|
if (children) {
|
|
@@ -215,6 +219,18 @@
|
|
|
215
219
|
}
|
|
216
220
|
return null;
|
|
217
221
|
}
|
|
222
|
+
function getNodePath(schema, nodeId) {
|
|
223
|
+
for (const node of schema) {
|
|
224
|
+
if (node._id === nodeId) {
|
|
225
|
+
return [];
|
|
226
|
+
}
|
|
227
|
+
const path = getNodePath(nodeChildren(node), nodeId);
|
|
228
|
+
if (path) {
|
|
229
|
+
return [node, ...path];
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
218
234
|
function propsOf(node) {
|
|
219
235
|
return Object.fromEntries(Object.entries(node.props ?? {}).filter(([, value]) => value !== null));
|
|
220
236
|
}
|
|
@@ -251,12 +267,29 @@
|
|
|
251
267
|
if (isListNode(node, nodeData, components)) {
|
|
252
268
|
return scopes;
|
|
253
269
|
}
|
|
254
|
-
return [
|
|
270
|
+
return [
|
|
271
|
+
{
|
|
272
|
+
node,
|
|
273
|
+
data: nodeData,
|
|
274
|
+
path: dataPathOfNode(node, scopes, components)
|
|
275
|
+
},
|
|
276
|
+
...scopes
|
|
277
|
+
];
|
|
255
278
|
}
|
|
256
279
|
function dataScopesOfListItem(list, item, index, scopes) {
|
|
257
280
|
var _a;
|
|
258
|
-
const listPath = [
|
|
259
|
-
|
|
281
|
+
const listPath = [
|
|
282
|
+
...((_a = scopes[0]) == null ? void 0 : _a.path) ?? [],
|
|
283
|
+
...(list == null ? void 0 : list.name) ? [list.name] : []
|
|
284
|
+
];
|
|
285
|
+
return [
|
|
286
|
+
{
|
|
287
|
+
node: list,
|
|
288
|
+
data: item,
|
|
289
|
+
path: [...listPath, index]
|
|
290
|
+
},
|
|
291
|
+
...scopes
|
|
292
|
+
];
|
|
260
293
|
}
|
|
261
294
|
function unsetDataOfNode(node, data, components) {
|
|
262
295
|
if (data === void 0 || data === null || typeof data !== "object" || Array.isArray(data)) {
|
|
@@ -489,7 +522,7 @@
|
|
|
489
522
|
"former-drag-container min-h-24 w-full border-2 dark:border-zinc-400 border-dashed rounded-md border-zinc-200 empty:before:block empty:bg-zinc-100 empty:dark:bg-zinc-700": vue.unref(mode) === "build"
|
|
490
523
|
}]),
|
|
491
524
|
"data-parent-node": (_a = vue.unref(node)) == null ? void 0 : _a._id,
|
|
492
|
-
"data-category":
|
|
525
|
+
"data-category": __props.category,
|
|
493
526
|
"data-drag-hint": vue.unref(texts).dragHint
|
|
494
527
|
}, [
|
|
495
528
|
vue.renderSlot(_ctx.$slots, "default")
|
|
@@ -2399,7 +2432,7 @@
|
|
|
2399
2432
|
return symbolToString ? symbolToString.call(value) : "";
|
|
2400
2433
|
}
|
|
2401
2434
|
var result2 = value + "";
|
|
2402
|
-
return result2 == "0" && 1 / value == -
|
|
2435
|
+
return result2 == "0" && 1 / value == -INFINITY ? "-0" : result2;
|
|
2403
2436
|
}
|
|
2404
2437
|
function baseUniq(array, iteratee2, comparator) {
|
|
2405
2438
|
var index = -1, includes2 = arrayIncludes, length = array.length, isCommon = true, result2 = [], seen = result2;
|
|
@@ -3619,7 +3652,7 @@
|
|
|
3619
3652
|
return value;
|
|
3620
3653
|
}
|
|
3621
3654
|
var result2 = value + "";
|
|
3622
|
-
return result2 == "0" && 1 / value == -
|
|
3655
|
+
return result2 == "0" && 1 / value == -INFINITY ? "-0" : result2;
|
|
3623
3656
|
}
|
|
3624
3657
|
function toSource(func) {
|
|
3625
3658
|
if (func != null) {
|
|
@@ -4683,7 +4716,7 @@
|
|
|
4683
4716
|
}
|
|
4684
4717
|
var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
|
|
4685
4718
|
function isSafeInteger(value) {
|
|
4686
|
-
return isInteger(value) && value >= -
|
|
4719
|
+
return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
|
|
4687
4720
|
}
|
|
4688
4721
|
var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
|
|
4689
4722
|
function isString(value) {
|
|
@@ -4724,7 +4757,7 @@
|
|
|
4724
4757
|
return value === 0 ? value : 0;
|
|
4725
4758
|
}
|
|
4726
4759
|
value = toNumber(value);
|
|
4727
|
-
if (value === INFINITY || value === -
|
|
4760
|
+
if (value === INFINITY || value === -INFINITY) {
|
|
4728
4761
|
var sign = value < 0 ? -1 : 1;
|
|
4729
4762
|
return sign * MAX_INTEGER;
|
|
4730
4763
|
}
|
|
@@ -4759,7 +4792,7 @@
|
|
|
4759
4792
|
return copyObject(value, keysIn(value));
|
|
4760
4793
|
}
|
|
4761
4794
|
function toSafeInteger(value) {
|
|
4762
|
-
return value ? baseClamp(toInteger(value), -
|
|
4795
|
+
return value ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER) : value === 0 ? value : 0;
|
|
4763
4796
|
}
|
|
4764
4797
|
function toString(value) {
|
|
4765
4798
|
return value == null ? "" : baseToString(value);
|
|
@@ -6040,7 +6073,11 @@
|
|
|
6040
6073
|
var _a, _b;
|
|
6041
6074
|
const nodeData = dataOfNode(node, data, components);
|
|
6042
6075
|
const results = [
|
|
6043
|
-
validateComponent(components, node, nodeData, {
|
|
6076
|
+
validateComponent(components, node, nodeData, {
|
|
6077
|
+
node,
|
|
6078
|
+
path: dataPathOfNode(node, scopes, components),
|
|
6079
|
+
scopes
|
|
6080
|
+
})
|
|
6044
6081
|
];
|
|
6045
6082
|
const children = ((_b = (_a = components[node.type]) == null ? void 0 : _a.shownChildren) == null ? void 0 : _b.call(_a, node)) ?? nodeChildren(node);
|
|
6046
6083
|
if (isListNode(node, nodeData, components)) {
|
|
@@ -6058,7 +6095,9 @@
|
|
|
6058
6095
|
return false;
|
|
6059
6096
|
}
|
|
6060
6097
|
const propsData = { $name: node.name, ...node.props };
|
|
6061
|
-
return areNodesValid(component.propsSchema, propsData, [
|
|
6098
|
+
return areNodesValid(component.propsSchema, propsData, [
|
|
6099
|
+
{ data: propsData, path: [] }
|
|
6100
|
+
], components);
|
|
6062
6101
|
}
|
|
6063
6102
|
function errorMessage(error) {
|
|
6064
6103
|
return error instanceof Error ? error.message : String(error);
|
|
@@ -6077,9 +6116,13 @@
|
|
|
6077
6116
|
let latestRun = 0;
|
|
6078
6117
|
vue.watch(() => {
|
|
6079
6118
|
try {
|
|
6080
|
-
return {
|
|
6119
|
+
return {
|
|
6120
|
+
value: getter()
|
|
6121
|
+
};
|
|
6081
6122
|
} catch (error) {
|
|
6082
|
-
return {
|
|
6123
|
+
return {
|
|
6124
|
+
value: Promise.reject(error)
|
|
6125
|
+
};
|
|
6083
6126
|
}
|
|
6084
6127
|
}, ({ value }) => {
|
|
6085
6128
|
const run = ++latestRun;
|
|
@@ -6175,7 +6218,9 @@
|
|
|
6175
6218
|
});
|
|
6176
6219
|
provide("hasDataKey", hasDataKey);
|
|
6177
6220
|
const parentDataScopes = inject("dataScopes", false);
|
|
6178
|
-
const dataScopes = vue.computed(() => (parentDataScopes == null ? void 0 : parentDataScopes.value) ?? [
|
|
6221
|
+
const dataScopes = vue.computed(() => (parentDataScopes == null ? void 0 : parentDataScopes.value) ?? [
|
|
6222
|
+
{ data: data.value, path: [] }
|
|
6223
|
+
]);
|
|
6179
6224
|
const dataPath = vue.computed(() => dataPathOfNode(node.value, dataScopes.value, components.value));
|
|
6180
6225
|
provide("dataScopes", vue.computed(() => dataScopesOfChildren(node.value, data.value, dataScopes.value, components.value)));
|
|
6181
6226
|
const validationContext = vue.computed(() => ({
|
|
@@ -6523,7 +6568,9 @@
|
|
|
6523
6568
|
type: newNodeType,
|
|
6524
6569
|
props: {}
|
|
6525
6570
|
};
|
|
6526
|
-
const _schema = [
|
|
6571
|
+
const _schema = [
|
|
6572
|
+
...vue.toValue(schema.value)
|
|
6573
|
+
];
|
|
6527
6574
|
addNode(_schema, newPosition, newNode);
|
|
6528
6575
|
schema.value = _schema;
|
|
6529
6576
|
selectedNode.value = newNode;
|
|
@@ -6550,7 +6597,9 @@
|
|
|
6550
6597
|
isDropping.value = false;
|
|
6551
6598
|
return;
|
|
6552
6599
|
}
|
|
6553
|
-
const _schema = [
|
|
6600
|
+
const _schema = [
|
|
6601
|
+
...vue.toValue(schema.value)
|
|
6602
|
+
];
|
|
6554
6603
|
deleteNode(_schema, nodeId);
|
|
6555
6604
|
if (currentPosition.parentId === newPosition.parentId && currentPosition.index < newPosition.index) {
|
|
6556
6605
|
newPosition.index--;
|
|
@@ -6622,7 +6671,9 @@
|
|
|
6622
6671
|
});
|
|
6623
6672
|
function useSchema(schema, components) {
|
|
6624
6673
|
const { result, isPending } = useMaybeAsync(() => {
|
|
6625
|
-
const nodes = [
|
|
6674
|
+
const nodes = [
|
|
6675
|
+
...schemaIterator(schema.value)
|
|
6676
|
+
];
|
|
6626
6677
|
const results = nodes.map((node) => propsValidityOfNode(node, vue.toValue(components)));
|
|
6627
6678
|
const byId = (resolved) => Object.fromEntries(nodes.map((node, index) => [node._id, resolved[index]]));
|
|
6628
6679
|
return results.some(isPromiseLike) ? Promise.all(results).then(byId) : byId(results);
|
|
@@ -6637,20 +6688,19 @@
|
|
|
6637
6688
|
components: {},
|
|
6638
6689
|
showIf: {},
|
|
6639
6690
|
mode: { default: "edit" },
|
|
6640
|
-
texts: { default: () => ({}) }
|
|
6641
|
-
isUpdating: { type: Boolean, default: false }
|
|
6691
|
+
texts: { default: () => ({}) }
|
|
6642
6692
|
}, {
|
|
6643
6693
|
"schema": { required: true },
|
|
6644
6694
|
"schemaModifiers": {},
|
|
6645
|
-
"data": {
|
|
6695
|
+
"data": {
|
|
6696
|
+
default: () => ({})
|
|
6697
|
+
},
|
|
6646
6698
|
"dataModifiers": {}
|
|
6647
6699
|
}),
|
|
6648
6700
|
emits: /* @__PURE__ */ vue.mergeModels(["valid", "schemaValid"], ["update:schema", "update:data"]),
|
|
6649
6701
|
setup(__props, { emit: __emit }) {
|
|
6650
6702
|
const props = __props;
|
|
6651
6703
|
const emit = __emit;
|
|
6652
|
-
const isUpdating = vue.toRef(props, "isUpdating");
|
|
6653
|
-
provide("formerIsUpdating", isUpdating);
|
|
6654
6704
|
const schema = vue.useModel(__props, "schema");
|
|
6655
6705
|
const internalSchema = vue.ref([]);
|
|
6656
6706
|
provide("schema", internalSchema);
|
|
@@ -6690,7 +6740,9 @@
|
|
|
6690
6740
|
}
|
|
6691
6741
|
return props.showIf(node, wrappedData.value, schema.value);
|
|
6692
6742
|
});
|
|
6693
|
-
provide("dataScopes", vue.computed(() => [
|
|
6743
|
+
provide("dataScopes", vue.computed(() => [
|
|
6744
|
+
{ data: wrappedData.value, path: [] }
|
|
6745
|
+
]));
|
|
6694
6746
|
const { isValid: isSchemaValid, propsValidity } = useSchema(internalSchema, vue.toRef(props, "components"));
|
|
6695
6747
|
provide("propsValidity", propsValidity);
|
|
6696
6748
|
vue.watch(isSchemaValid, () => {
|
|
@@ -6712,10 +6764,15 @@
|
|
|
6712
6764
|
);
|
|
6713
6765
|
const selectedNode = vue.ref(void 0);
|
|
6714
6766
|
provide("selectedNode", selectedNode);
|
|
6767
|
+
const selectedNodePath = vue.computed(() => selectedNode.value ? getNodePath(internalSchema.value, selectedNode.value._id) ?? [] : []);
|
|
6768
|
+
provide("selectedNodePath", selectedNodePath);
|
|
6715
6769
|
const texts = vue.toRef(props, "texts");
|
|
6716
6770
|
provide("texts", vue.computed(() => ({ dragHint: "Here you can drag elements", invalidSchema: "Invalid schema", ...texts.value })));
|
|
6717
6771
|
return (_ctx, _cache) => {
|
|
6718
|
-
return vue.renderSlot(_ctx.$slots, "default", {
|
|
6772
|
+
return vue.renderSlot(_ctx.$slots, "default", {
|
|
6773
|
+
selectedNode: selectedNode.value,
|
|
6774
|
+
selectedNodePath: selectedNodePath.value
|
|
6775
|
+
}, () => [
|
|
6719
6776
|
vue.createVNode(_sfc_main$3)
|
|
6720
6777
|
]);
|
|
6721
6778
|
};
|
|
@@ -6740,6 +6797,7 @@
|
|
|
6740
6797
|
const components = inject("components");
|
|
6741
6798
|
const schema = inject("schema");
|
|
6742
6799
|
const selectedNode = inject("selectedNode");
|
|
6800
|
+
const selectedNodePath = vue.computed(() => selectedNode.value ? getNodePath(schema.value, selectedNode.value._id) ?? [] : []);
|
|
6743
6801
|
const selectedNodeType = vue.computed(() => selectedNode.value ? components.value[selectedNode.value.type] : void 0);
|
|
6744
6802
|
const selectedNodePropsSchema = vue.ref();
|
|
6745
6803
|
vue.watch(
|
|
@@ -6813,6 +6871,7 @@
|
|
|
6813
6871
|
]),
|
|
6814
6872
|
vue.renderSlot(_ctx.$slots, "node-actions", {
|
|
6815
6873
|
node: vue.unref(toSchemaNode)(vue.unref(selectedNode)),
|
|
6874
|
+
path: selectedNodePath.value.map(vue.unref(toSchemaNode)),
|
|
6816
6875
|
addNode: addNode$1,
|
|
6817
6876
|
removeNode
|
|
6818
6877
|
})
|
|
@@ -6834,7 +6893,7 @@
|
|
|
6834
6893
|
components: vue.unref(components),
|
|
6835
6894
|
onValid: _cache[1] || (_cache[1] = ($event) => _ctx.$emit("valid", $event))
|
|
6836
6895
|
}, null, 8, ["data", "schema", "components"])) : (vue.openBlock(), vue.createElementBlock("pre", _hoisted_6, vue.toDisplayString(vue.unref(selectedNode)), 1))
|
|
6837
|
-
])) : vue.renderSlot(_ctx.$slots, "nothing-selected", {
|
|
6896
|
+
])) : vue.renderSlot(_ctx.$slots, "nothing-selected", {}, void 0, void 0, 1);
|
|
6838
6897
|
};
|
|
6839
6898
|
}
|
|
6840
6899
|
});
|
|
@@ -6853,7 +6912,12 @@
|
|
|
6853
6912
|
}
|
|
6854
6913
|
}
|
|
6855
6914
|
vue.onMounted(applyPreset);
|
|
6856
|
-
vue.watch([
|
|
6915
|
+
vue.watch([
|
|
6916
|
+
() => vue.toValue(preset),
|
|
6917
|
+
() => mode == null ? void 0 : mode.value,
|
|
6918
|
+
() => hasDataKey == null ? void 0 : hasDataKey.value,
|
|
6919
|
+
() => isShown == null ? void 0 : isShown.value
|
|
6920
|
+
], applyPreset);
|
|
6857
6921
|
}
|
|
6858
6922
|
exports2.FormAdd = _sfc_main$7;
|
|
6859
6923
|
exports2.FormContent = _sfc_main$3;
|
package/dist/utils.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ type NodePosition = {
|
|
|
16
16
|
export declare function nodePosition(schema: InternalSchemaNode[], nodeId: string, anchor: 'above' | 'below', parentId?: string, category?: string): NodePosition | null;
|
|
17
17
|
export declare function addNode(schema: InternalSchemaNode[], position: NodePosition, node: InternalSchemaNode): void;
|
|
18
18
|
export declare function getNode(schema: InternalSchemaNode[], nodeId: string): InternalSchemaNode | null;
|
|
19
|
+
export declare function getNodePath(schema: InternalSchemaNode[], nodeId: string): InternalSchemaNode[] | null;
|
|
19
20
|
export declare function propsOf(node: SchemaNode): {
|
|
20
21
|
[key: string]: any;
|
|
21
22
|
};
|
package/dist/validation.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
-
import { FieldData, FormComponents, FormData, InternalSchemaNode, SchemaNode, ValidationContext } from './types';
|
|
3
2
|
import { Ref } from 'vue';
|
|
3
|
+
import { FieldData, FormComponents, FormData, InternalSchemaNode, SchemaNode, ValidationContext } from './types';
|
|
4
4
|
export type { StandardSchemaV1 };
|
|
5
5
|
export type MaybePromise<T> = T | PromiseLike<T>;
|
|
6
6
|
export declare function isPromiseLike<T>(value: MaybePromise<T>): value is PromiseLike<T>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@former-ui/former",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -33,27 +33,27 @@
|
|
|
33
33
|
"vue": "^3.3.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@standard-schema/spec": "
|
|
37
|
-
"lodash": "
|
|
36
|
+
"@standard-schema/spec": "1.1.0",
|
|
37
|
+
"lodash": "4.18.1"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@
|
|
41
|
-
"@
|
|
42
|
-
"@types/
|
|
43
|
-
"@
|
|
44
|
-
"@
|
|
45
|
-
"@
|
|
46
|
-
"@vue/
|
|
47
|
-
"
|
|
48
|
-
"happy-dom": "
|
|
49
|
-
"tailwindcss": "3.
|
|
50
|
-
"typescript": "
|
|
40
|
+
"@tailwindcss/vite": "4.3.5",
|
|
41
|
+
"@tsconfig/node26": "26.0.2",
|
|
42
|
+
"@types/lodash": "4.17.27",
|
|
43
|
+
"@types/node": "26.6.6",
|
|
44
|
+
"@vitejs/plugin-vue": "6.0.11",
|
|
45
|
+
"@vitest/coverage-v8": "5.1.0",
|
|
46
|
+
"@vue/test-utils": "2.5.1",
|
|
47
|
+
"@vue/tsconfig": "0.9.1",
|
|
48
|
+
"happy-dom": "21.0.4",
|
|
49
|
+
"tailwindcss": "4.3.5",
|
|
50
|
+
"typescript": "6.0.3",
|
|
51
51
|
"valibot": "1.5.0",
|
|
52
|
-
"vite": "6.4.
|
|
53
|
-
"vite-plugin-dts": "
|
|
54
|
-
"vitest": "
|
|
55
|
-
"vue": "3.5.
|
|
56
|
-
"vue-tsc": "3.
|
|
52
|
+
"vite": "6.4.4",
|
|
53
|
+
"vite-plugin-dts": "5.1.2",
|
|
54
|
+
"vitest": "5.1.0",
|
|
55
|
+
"vue": "3.5.45",
|
|
56
|
+
"vue-tsc": "3.3.14",
|
|
57
57
|
"yup": "1.7.1",
|
|
58
58
|
"zod": "4.6.7"
|
|
59
59
|
},
|