qmap-forms 1.0.1 → 1.0.3

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.
@@ -0,0 +1,112 @@
1
+ import { Fragment as e, Teleport as t, createBlock as n, createCommentVNode as r, createElementBlock as i, createElementVNode as a, createTextVNode as o, createVNode as s, defineComponent as c, nextTick as l, normalizeClass as u, normalizeStyle as d, onBeforeUnmount as f, openBlock as p, ref as m, renderSlot as h, toDisplayString as g, withCtx as _, withKeys as v } from "vue";
2
+ //#endregion
3
+ //#region src/components/simple/BtnTooltip.vue
4
+ var y = /* @__PURE__ */ c({
5
+ __name: "BtnTooltip",
6
+ props: { label: {} },
7
+ setup(o) {
8
+ let s = m(!1), c = m({
9
+ top: "50px",
10
+ left: "50px",
11
+ position: "absolute",
12
+ zIndex: "999"
13
+ });
14
+ m(null);
15
+ let u = m(null), _ = m(null), y = `info-btn-tooltip-${Math.random().toString(36).slice(2)}`;
16
+ function b() {
17
+ s.value || (s.value = !0, l(() => {
18
+ C();
19
+ }), document.addEventListener("mousedown", S));
20
+ }
21
+ function x() {
22
+ s.value = !1, document.removeEventListener("mousedown", S);
23
+ }
24
+ function S(e) {
25
+ _.value && u.value && !_.value.contains(e.target) && !u.value.contains(e.target) && x();
26
+ }
27
+ function C() {
28
+ if (u.value && _.value) {
29
+ let e = u.value.getBoundingClientRect(), t = _.value.getBoundingClientRect(), n = e.bottom + window.scrollY + 8, r = Math.max(e.left + window.scrollX + e.width / 2 - t.width / 2, 0);
30
+ c.value = {
31
+ top: `${n}px`,
32
+ left: `${r}px`,
33
+ position: "absolute",
34
+ zIndex: "999"
35
+ };
36
+ }
37
+ }
38
+ return f(() => {
39
+ document.removeEventListener("mousedown", S);
40
+ }), (l, f) => (p(), i(e, null, [a("button", {
41
+ ref_key: "button",
42
+ ref: u,
43
+ onClick: b,
44
+ onBlur: x,
45
+ onMouseover: b,
46
+ class: "qmap-button",
47
+ onMouseleave: x,
48
+ onKeydown: v(x, ["esc"]),
49
+ style: {
50
+ border: "none",
51
+ background: "none"
52
+ },
53
+ "aria-describedby": y
54
+ }, [h(l.$slots, "default")], 544), (p(), n(t, { to: "body" }, [s.value ? (p(), i("div", {
55
+ key: 0,
56
+ id: y,
57
+ class: "tooltip",
58
+ style: d(c.value),
59
+ ref_key: "tooltip",
60
+ ref: _,
61
+ tabindex: "-1"
62
+ }, g(o.label), 5)) : r("", !0)]))], 64));
63
+ }
64
+ }), b = /* @__PURE__ */ c({
65
+ __name: "subtitle-button",
66
+ props: { qMap: {} },
67
+ setup(e) {
68
+ return (t, i) => e.qMap.subtitle ? (p(), n(y, {
69
+ key: 0,
70
+ label: e.qMap.subtitle
71
+ }, {
72
+ default: _(() => [...i[0] ||= [a("i", { class: "fa fa-question-circle" }, null, -1)]]),
73
+ _: 1
74
+ }, 8, ["label"])) : r("", !0);
75
+ }
76
+ }), x = { class: "block" }, S = /* @__PURE__ */ c({
77
+ __name: "title-block",
78
+ props: { qMap: {} },
79
+ setup(e) {
80
+ return (t, n) => (p(), i("span", x, [
81
+ o(g(e.qMap.title || (e.qMap.id !== "#" && e.qMap.type !== "col" && e.qMap.type !== "group" ? e.qMap.id : "")) + " ", 1),
82
+ h(t.$slots, "default"),
83
+ s(b, { "q-map": e.qMap }, null, 8, ["q-map"])
84
+ ]));
85
+ }
86
+ }), C = {
87
+ key: 0,
88
+ class: "inline-flex shrink-0 items-center gap-1 qmap-control-prepend"
89
+ }, w = {
90
+ key: 1,
91
+ class: "inline-flex shrink-0 items-center gap-1 qmap-control-append"
92
+ }, T = /* @__PURE__ */ c({
93
+ __name: "FieldControl",
94
+ props: {
95
+ invalid: { type: Boolean },
96
+ disabled: { type: Boolean },
97
+ multiline: { type: Boolean }
98
+ },
99
+ setup(e) {
100
+ return (t, n) => (p(), i("div", { class: u(["flex items-center gap-2 min-w-0 min-h-10 px-3 qmap-control", {
101
+ "items-start": e.multiline,
102
+ "qmap-control-invalid": e.invalid,
103
+ "qmap-control-disabled": e.disabled
104
+ }]) }, [
105
+ t.$slots.prepend ? (p(), i("div", C, [h(t.$slots, "prepend")])) : r("", !0),
106
+ h(t.$slots, "default"),
107
+ t.$slots.append ? (p(), i("div", w, [h(t.$slots, "append")])) : r("", !0)
108
+ ], 2));
109
+ }
110
+ });
111
+ //#endregion
112
+ export { S as n, b as r, T as t };
package/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # qmap-forms
2
+
3
+ QMap Forms is a dynamic form generator that will build a form capabile of manipulating a local json object.
4
+
5
+ It uses the qMap configuration specification defined [here](https://vasat.io/qmap)
6
+
7
+ # Installation
8
+
9
+ ## Using as UMD
10
+
11
+ Declare dependencies in html head
12
+
13
+ ```html
14
+ <!-- stylesheets -->
15
+ <link href="https://use.fontawesome.com/releases/v7.0.0/css/all.css" rel="stylesheet" type="text/css">
16
+ <link href="https://cdn.jsdelivr.net/npm/qmap-forms@latest/qmap-forms.css" rel="stylesheet" type="text/css">
17
+
18
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/7.8.2/rxjs.umd.js"></script>
19
+
20
+ <!-- Leaflet optional if your using a geo_map type compoennt -->
21
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.4/leaflet.js"></script>
22
+
23
+ ```
24
+
25
+ Then at the end of your body tag declare dependencies for `vue` and the `qmap` library
26
+
27
+ ```html
28
+
29
+ <script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script>
30
+ <script src="https://cdn.jsdelivr.net/npm/qmap-forms@latest/qmap.umd.js"></script>
31
+
32
+ ```
33
+
34
+ The UMD module exports a window variable `QMap`
35
+
36
+
37
+ ## Using as ES module
38
+
39
+ Install packages
40
+ ```sh
41
+ npm install --save rxjs qmap-forms
42
+ ```
43
+
44
+ Import the packaged stylesheet once in your app entry point:
45
+
46
+ ```ts
47
+ import 'qmap-forms/qmap-forms.css'
48
+ ```
49
+
50
+
51
+ # Using qMAP
52
+
53
+ The first thing needed is the form fields defined
54
+ ```js
55
+ // the qMAP of the form you want
56
+ const qmap = [
57
+ {
58
+ id: 'name',
59
+ type: 'string',
60
+ required: true
61
+ },
62
+ {
63
+ id: 'email',
64
+ type: 'string',
65
+ required: false,
66
+ },
67
+ {
68
+ id: 'accept',
69
+ type: 'boolean',
70
+ required: true,
71
+ },
72
+ ]
73
+ ```
74
+
75
+ Followed by the plain js object you wish to use as the model
76
+ ```js
77
+ // the model object, can be pre-populated
78
+ const model = {name:'Joe'}
79
+ ```
80
+
81
+ You then connect using the `mount` method
82
+
83
+ ```js
84
+ // initialise and mound the form at designated dom selector
85
+ const form = QMap.mount('#formNode',qmap,model)
86
+ ```
87
+
88
+ You can listen to state changes by subscribing
89
+ ```js
90
+ form.state.subscribe(a => {
91
+ console.log('Form altered', a) // this will be the 'model' object with changes
92
+ })
93
+
94
+ ```
95
+
96
+ ## Using Vue Form Component
97
+
98
+ When using vue you can use the vue component directly
99
+
100
+ ```ts
101
+ <script setup lang="ts">
102
+ import { onMounted, ref } from 'vue';
103
+ import {Form} from 'qmap-forms';
104
+
105
+ const qmap = ref([
106
+ {
107
+ id: 'name',
108
+ type: 'string',
109
+ required: true,
110
+ },
111
+ {
112
+ id: 'logoURL',
113
+ type: 'string',
114
+ required: false,
115
+ },
116
+ {
117
+ id: 'email',
118
+ type: 'string',
119
+ required: true,
120
+ },
121
+ ]);
122
+
123
+ const model = ref({})
124
+
125
+ </script>
126
+ <template>
127
+
128
+ <Form :questions=qmap v-model="model" />
129
+
130
+ </template>
131
+
132
+ ```
@@ -0,0 +1,8 @@
1
+ import "./FieldControl-D0e9k9sx.mjs";
2
+ import "vue";
3
+ import "leaflet-editable";
4
+ import "leaflet";
5
+ throw Error("Could not resolve \"leaflet-path-drag\" imported by \"qmap-forms\". Is it installed?");
6
+ //#endregion
7
+ export { e as default };
8
+ var e;