@stubber/form-fields 1.0.3 → 1.0.4

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.
@@ -10,12 +10,15 @@
10
10
  MatchDecorator,
11
11
  Decoration,
12
12
  ViewPlugin,
13
- keymap
13
+ keymap,
14
14
  } from "@codemirror/view";
15
15
  import { EditorState, StateField } from "@codemirror/state";
16
16
  import { history, defaultKeymap, historyKeymap } from "@codemirror/commands";
17
17
  import { autocompletion } from "@codemirror/autocomplete";
18
18
 
19
+ import { Input } from "@stubber/ui/input";
20
+ import { Label } from "@stubber/ui/label";
21
+
19
22
  export let field;
20
23
 
21
24
  const internal = writable();
@@ -59,6 +62,17 @@
59
62
  // set field state if changed
60
63
  if (!deepEqual(a?.state?.internal, _clone)) {
61
64
  $field.state.internal = _clone;
65
+
66
+ // update the editor content if it's different
67
+ if (editor_view?.state.doc.toString() !== _clone.raw) {
68
+ editor_view?.dispatch({
69
+ changes: {
70
+ from: 0,
71
+ to: editor_view.state.doc.length,
72
+ insert: _clone.raw,
73
+ },
74
+ });
75
+ }
62
76
  }
63
77
 
64
78
  return _clone;
@@ -191,6 +205,9 @@
191
205
  });
192
206
 
193
207
  let editor_parent;
208
+ /**
209
+ * @type {EditorView}
210
+ */
194
211
  let editor_view;
195
212
 
196
213
  $: is_string = typeof $internal?.raw === "string";
@@ -208,10 +225,7 @@
208
225
  EditorView.contentAttributes.of({
209
226
  spellcheck: "true",
210
227
  }),
211
- keymap.of([
212
- ...defaultKeymap,
213
- ...historyKeymap,
214
- ])
228
+ keymap.of([...defaultKeymap, ...historyKeymap]),
215
229
  ];
216
230
 
217
231
  if (code_language === "handlebars") {
@@ -235,24 +249,24 @@
235
249
 
236
250
  {#if $internal && is_string}
237
251
  <div class="flex flex-col w-full text-surface-900">
238
- <label for="input_{state_key}" class="block text-label {hide_label ? 'hidden' : ''}">
252
+ <Label for="input_{state_key}" class="block{hide_label ? 'hidden' : ''}">
239
253
  {label}
240
- </label>
254
+ </Label>
241
255
  <div
242
256
  bind:this={editor_parent}
243
257
  class="stubber-cm text-field {isValid ? 'stubber-valid' : 'stubber-invalid'}"
244
258
  />
245
259
  {#if validationMessage}
246
- <p class="text-label {!isValid ? `text-danger-500` : `text-success-500`}">
260
+ <Label class="text-label {!isValid ? `text-danger-500` : `text-success-500`}">
247
261
  {validationMessage}
248
- </p>
262
+ </Label>
249
263
  {/if}
250
264
  </div>
251
265
  {:else}
252
266
  <div class="flex flex-col w-full text-surface-900">
253
- <label for="input_{state_key}" class="block text-label {hide_label ? 'hidden' : ''}">
267
+ <Label for="input_{state_key}" class="block {hide_label ? 'hidden' : ''}">
254
268
  {label}
255
- </label>
269
+ </Label>
256
270
  <p class="text-surface-400">The value of this field is not a string.</p>
257
271
  </div>
258
272
  {/if}
@@ -7,6 +7,8 @@
7
7
  import intlTelInput from "intl-tel-input";
8
8
  import "intl-tel-input/build/css/intlTelInput.css";
9
9
 
10
+ import { Label } from "@stubber/ui/label";
11
+
10
12
  export let field;
11
13
 
12
14
  const internal = writable();
@@ -128,9 +130,9 @@
128
130
 
129
131
  {#if $internal}
130
132
  <div class="flex flex-col w-full text-surface-900">
131
- <label for="input_{state_key}" class="block text-label {hide_label ? 'hidden' : ''}">
133
+ <Label for="input_{state_key}" class="block {hide_label ? 'hidden' : ''}">
132
134
  {label}
133
- </label>
135
+ </Label>
134
136
  <div
135
137
  class="w-full bg-surface-100 flex space-x-4 focus:outline-primary-400 relative mt-2 rounded-md"
136
138
  >
@@ -139,15 +141,18 @@
139
141
  bind:value={$internal.raw}
140
142
  type="tel"
141
143
  id="input_{state_key}"
142
- class="w-full text-field rounded-md border-0 py-2 pl-3 text-surface-900 ring-1 ring-inset {!isValid
143
- ? 'ring-danger-500'
144
- : 'ring-surface-300 focus:ring-primary-400'} focus:outline-none placeholder:text-surface-400 focus:ring-2 focus:ring-inset"
144
+ class="bg-gradient-to-b from-[#2727271F] to-[#27272719] shadow-select
145
+ flex h-7 w-full items-center justify-between rounded px-3 py-2
146
+ text-sm
147
+ [&>span]:line-clamp-1 aria-[invalid]:border-destructive
148
+ placeholder:text-black
149
+ {!isValid ? 'ring-danger-500' : 'ring-surface-300 focus:ring-primary-400'}"
145
150
  />
146
151
  </div>
147
152
  {#if validationMessage}
148
- <p class="text-label {!isValid ? `text-danger-500` : `text-success-500`}">
149
- {validationMessage}
150
- </p>
153
+ <div class="mt-1">
154
+ <Label class={!isValid ? `text-danger-500` : `text-success-500`}>{validationMessage}</Label>
155
+ </div>
151
156
  {/if}
152
157
  </div>
153
158
  {/if}
@@ -5,6 +5,9 @@
5
5
  import { onMount } from "svelte";
6
6
  import { writable } from "svelte/store";
7
7
 
8
+ import { Input } from "@stubber/ui/input";
9
+ import { Label } from "@stubber/ui/label";
10
+
8
11
  export let field;
9
12
 
10
13
  const internal = writable();
@@ -77,11 +80,11 @@
77
80
 
78
81
  {#if $internal}
79
82
  <div class="flex flex-col w-full text-surface-900">
80
- <label for="input_{state_key}" class="block text-label {hide_label ? 'hidden' : ''}">
83
+ <Label for="input_{state_key}" class="block py-2 {hide_label ? 'hidden' : ''}">
81
84
  {label}
82
- </label>
85
+ </Label>
83
86
  <div class="relative rounded-md">
84
- <input
87
+ <Input
85
88
  on:keydown={(e) => {
86
89
  if (e.key === "Enter") {
87
90
  e.preventDefault();
@@ -90,17 +93,15 @@
90
93
  type="text"
91
94
  id="input_{state_key}"
92
95
  placeholder={label}
93
- class="block w-full text-field rounded-md border-0 py-2 pl-3 text-surface-900 ring-1 ring-inset {!isValid
94
- ? 'ring-danger-500'
95
- : 'ring-surface-300 focus:ring-primary-400'} focus:outline-none placeholder:text-surface-400 focus:ring-2 focus:ring-inset"
96
+ class="block w-full {!isValid ? 'ring-danger-500' : 'ring-surface-300 '} "
96
97
  name={state_key}
97
98
  bind:value={$internal.raw}
98
99
  />
99
100
  </div>
100
101
  {#if validationMessage}
101
- <p class="text-label {!isValid ? `text-danger-500` : `text-success-500`}">
102
- {validationMessage}
103
- </p>
102
+ <Label class="mt-1.5 {!isValid ? `text-danger-500` : `text-success-500`}"
103
+ >{validationMessage}</Label
104
+ >
104
105
  {/if}
105
106
  </div>
106
107
  {/if}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stubber/form-fields",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "An automatic form builder based on field specifications",
5
5
  "keywords": [
6
6
  "components",
@@ -57,7 +57,7 @@
57
57
  "@codemirror/commands": "^6.7.1",
58
58
  "@codemirror/state": "^6.4.1",
59
59
  "@codemirror/view": "^6.34.1",
60
- "@stubber/ui": "^1.0.11",
60
+ "@stubber/ui": "^1.0.18",
61
61
  "ag-grid-community": "^31.0.2",
62
62
  "ag-grid-enterprise": "^31.0.2",
63
63
  "currency-symbol-map": "^5.1.0",