stalefish 8.0.5 → 8.0.7

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.
@@ -117,8 +117,28 @@ export default ({ wrapperStyle = null, holdingPen, label, placeholder, property,
117
117
 
118
118
  // Create a stable id for the outer wrapper so we can query a real DOM node
119
119
  // after the template is rendered. Prefer the provided uniqueKey from callers
120
- // (report-pal already supplies it), otherwise fall back to property/name.
121
- const wrapperId = `sf-flatpickr-${uniqueKey || property || Math.random().toString(36).slice(2)}`
120
+ // but DO NOT require it. For robustness, memoize a per-(holdingPen, property)
121
+ // id so re-renders don't generate new ids and callers don't have to pass
122
+ // uniqueKey.
123
+ const ID_MAP_SYMBOL = Symbol.for('stalefish.flatpickr.idMap')
124
+ if (holdingPen && !holdingPen[ID_MAP_SYMBOL]) {
125
+ Object.defineProperty(holdingPen, ID_MAP_SYMBOL, {
126
+ value: {},
127
+ enumerable: false,
128
+ configurable: false,
129
+ writable: false
130
+ })
131
+ }
132
+ const memoId = (() => {
133
+ if (!holdingPen || !property) return null
134
+ const map = holdingPen[ID_MAP_SYMBOL]
135
+ if (!map) return null
136
+ if (!map[property]) {
137
+ map[property] = `sf-flatpickr-${property}-${Math.random().toString(36).slice(2)}`
138
+ }
139
+ return map[property]
140
+ })()
141
+ const wrapperId = `sf-flatpickr-${uniqueKey || memoId || property || Math.random().toString(36).slice(2)}`
122
142
 
123
143
  const inputType = resolvedDisableMobile ? 'text' : (detectTouchscreen() ? (timeOnly ? 'time' : 'date') : 'text')
124
144
 
@@ -134,20 +154,7 @@ export default ({ wrapperStyle = null, holdingPen, label, placeholder, property,
134
154
  e.target.parentNode.parentNode._flatpickr.close()
135
155
  return false
136
156
  }}>clear</div>` : ''}
137
- <input data-gramm="false" ?disabled=${disabled} style="${disabled ? 'cursor: not-allowed; opacity: 0.3;' : ''}" class="${styles.textfield} ${fieldIsTouched(holdingPen, property) === true ? styles.touched : ''}" ${required ? { required: 'required' } : ''} onfocus=${e => {
138
- e.target.parentNode.parentNode._flatpickr && e.target.parentNode.parentNode._flatpickr.set('onValueUpdate', (fpDate, dateString) => {
139
- const fauxE = {
140
- currentTarget: {
141
- validity: {
142
- valid: true
143
- },
144
- value: dateString
145
- }
146
- }
147
- formField(holdingPen, property)(fauxE)
148
- onchange && onchange(fauxE)
149
- })
150
- }} onchange=${e => { change({ e, holdingPen, property, label: styles.label }); onchange && onchange(e) }} oninput=${e => { e.target.defaultValue = ''; oninput && oninput(e) }} placeholder="${placeholder || ''}${required ? ' *' : ''}" type="${inputType}" ${pattern ? { pattern } : ''} value="${holdingPen[property] || ''}" data-input />
157
+ <input data-gramm="false" ?disabled=${disabled} style="${disabled ? 'cursor: not-allowed; opacity: 0.3;' : ''}" class="${styles.textfield} ${fieldIsTouched(holdingPen, property) === true ? styles.touched : ''}" ${required ? { required: 'required' } : ''} onchange=${e => { change({ e, holdingPen, property, label: styles.label }); onchange && onchange(e) }} oninput=${e => { e.target.defaultValue = ''; oninput && oninput(e) }} placeholder="${placeholder || ''}${required ? ' *' : ''}" type="${inputType}" ${pattern ? { pattern } : ''} .value=${holdingPen[property] || ''} data-input />
151
158
  </div>
152
159
  </div>
153
160
  `
@@ -166,15 +173,27 @@ export default ({ wrapperStyle = null, holdingPen, label, placeholder, property,
166
173
  Object.assign(
167
174
  {},
168
175
  { disableMobile: resolvedDisableMobile },
176
+ // Provide sensible defaults for time-only pickers; allow user config to override
177
+ timeOnly
178
+ ? {
179
+ dateFormat: flatpickrConfig && flatpickrConfig.dateFormat ? flatpickrConfig.dateFormat : 'H:i',
180
+ defaultDate:
181
+ flatpickrConfig && typeof flatpickrConfig.defaultDate !== 'undefined'
182
+ ? flatpickrConfig.defaultDate
183
+ : (holdingPen && property && holdingPen[property] ? holdingPen[property] : undefined)
184
+ }
185
+ : null,
169
186
  flatpickrConfig,
170
187
  {
171
188
  wrap: true,
172
- onValueUpdate: (fpDate, dateString) => {
189
+ // Avoid triggering rerenders on every spinner click which would
190
+ // destroy and recreate the popup, making it seem to "disappear".
191
+ // We update holdingPen once on close instead.
192
+ onValueUpdate: () => {},
193
+ onClose: (selectedDates, dateString) => {
173
194
  const fauxE = {
174
195
  currentTarget: {
175
- validity: {
176
- valid: true
177
- },
196
+ validity: { valid: true },
178
197
  value: dateString
179
198
  }
180
199
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stalefish",
3
- "version": "8.0.5",
3
+ "version": "8.0.7",
4
4
  "description": "Simple function based component library for halfcab tagged template literals",
5
5
  "main": "index.mjs",
6
6
  "module": "index.mjs",