@stubber/form-fields 1.7.0 → 1.7.2
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.
|
@@ -11,10 +11,7 @@ export const code_field_param_spec = {
|
|
|
11
11
|
};
|
|
12
12
|
</script>
|
|
13
13
|
|
|
14
|
-
<script>import {
|
|
15
|
-
import FieldLabel from "../FieldLabel.svelte";
|
|
16
|
-
import FieldMessage from "../FieldMessage.svelte";
|
|
17
|
-
import {
|
|
14
|
+
<script>import {
|
|
18
15
|
acceptCompletion,
|
|
19
16
|
autocompletion,
|
|
20
17
|
CompletionContext,
|
|
@@ -25,7 +22,11 @@ import { javascript, javascriptLanguage } from "@codemirror/lang-javascript";
|
|
|
25
22
|
import { EditorState } from "@codemirror/state";
|
|
26
23
|
import { EditorView, keymap } from "@codemirror/view";
|
|
27
24
|
import { basicSetup } from "codemirror";
|
|
25
|
+
import { getContext } from "svelte";
|
|
26
|
+
import FieldLabel from "../FieldLabel.svelte";
|
|
27
|
+
import FieldMessage from "../FieldMessage.svelte";
|
|
28
28
|
export let fieldStore;
|
|
29
|
+
const code_fields_ctx_store = getContext("code_fields_ctx");
|
|
29
30
|
let value = $fieldStore.value || "";
|
|
30
31
|
let editor_view;
|
|
31
32
|
const custom_completion_keymap = completionKeymap.filter((binding) => binding.key != "Enter").concat([
|
|
@@ -54,16 +55,21 @@ function globalCompletions(ctx) {
|
|
|
54
55
|
const text = m?.text ?? "";
|
|
55
56
|
const trailingDot = text.endsWith(".");
|
|
56
57
|
const parts = (trailingDot ? text.slice(0, -1) : text).split(".").filter(Boolean);
|
|
57
|
-
let
|
|
58
|
+
let global_context = {};
|
|
59
|
+
if ($code_fields_ctx_store) {
|
|
60
|
+
global_context = $code_fields_ctx_store;
|
|
61
|
+
} else {
|
|
62
|
+
global_context = $fieldStore.params?.globals || {};
|
|
63
|
+
}
|
|
58
64
|
for (let i = 0; i < Math.max(0, parts.length - (trailingDot ? 0 : 1)); i++) {
|
|
59
|
-
|
|
60
|
-
if (!
|
|
65
|
+
global_context = global_context?.[parts[i]];
|
|
66
|
+
if (!global_context) break;
|
|
61
67
|
}
|
|
62
68
|
const last = trailingDot ? "" : parts[parts.length - 1] ?? "";
|
|
63
69
|
const from = ctx.pos - last.length;
|
|
64
70
|
return {
|
|
65
71
|
from,
|
|
66
|
-
options: keysFor(
|
|
72
|
+
options: keysFor(global_context).map((key) => ({
|
|
67
73
|
label: key,
|
|
68
74
|
type: "property"
|
|
69
75
|
// 👈 simplified
|
|
@@ -137,7 +143,7 @@ const sync_field_to_value = (new_value) => {
|
|
|
137
143
|
};
|
|
138
144
|
</script>
|
|
139
145
|
|
|
140
|
-
<div class="
|
|
146
|
+
<div class="my-2 flex w-full flex-col">
|
|
141
147
|
<FieldLabel {fieldStore} />
|
|
142
148
|
<div class="relative rounded-md">
|
|
143
149
|
<div use:bind_codemirror />
|
|
@@ -69,14 +69,15 @@ import {
|
|
|
69
69
|
import { find } from "lodash-es";
|
|
70
70
|
import FieldLabel from "../FieldLabel.svelte";
|
|
71
71
|
import FieldMessage from "../FieldMessage.svelte";
|
|
72
|
+
import { getContext } from "svelte";
|
|
72
73
|
export let fieldStore;
|
|
73
74
|
let editor_view;
|
|
74
75
|
$: validation_result = $fieldStore.validation_result;
|
|
75
76
|
$: type = validation_result?.type;
|
|
76
77
|
$: isValid = type !== "error";
|
|
77
78
|
$: is_object = typeof $fieldStore.value === "object";
|
|
79
|
+
const smart_text_fields_ctx_store = getContext("smart_text_fields_ctx");
|
|
78
80
|
$: parse_string = $fieldStore.params?.parse_string;
|
|
79
|
-
$: auto_completions = $fieldStore.params?.auto_completions || [];
|
|
80
81
|
$: code_language = $fieldStore.params?.code_language;
|
|
81
82
|
const setup_editor = (element) => {
|
|
82
83
|
const extensions = [
|
|
@@ -166,6 +167,7 @@ function fake_handlebars_lang() {
|
|
|
166
167
|
);
|
|
167
168
|
}
|
|
168
169
|
function myCompletions(context) {
|
|
170
|
+
const auto_completions = $smart_text_fields_ctx_store || $fieldStore.params?.auto_completions || [];
|
|
169
171
|
for (let completion of auto_completions) {
|
|
170
172
|
if (!completion.match_before) continue;
|
|
171
173
|
let before = context.matchBefore(new RegExp(completion.match_before));
|
package/dist/fields2/utils.js
CHANGED
|
@@ -54,10 +54,12 @@ export const build_field = (formStore, attachmentsStore, formDependencies, field
|
|
|
54
54
|
}
|
|
55
55
|
if (field.initvalue) {
|
|
56
56
|
const current_value = built_field.value;
|
|
57
|
-
if (current_value && field.initvalue.has_override) {
|
|
57
|
+
if (current_value && field.initvalue.has_override && field.initvalue.override !== undefined) {
|
|
58
58
|
built_field.value = field.initvalue.override;
|
|
59
59
|
}
|
|
60
|
-
else if (
|
|
60
|
+
else if (current_value === undefined &&
|
|
61
|
+
field.initvalue.has_default &&
|
|
62
|
+
field.initvalue.default !== undefined) {
|
|
61
63
|
built_field.value = field.initvalue.default;
|
|
62
64
|
}
|
|
63
65
|
}
|