@lattice-php/lattice 0.30.0 → 0.31.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/dist/action/components/action-form.js +26 -25
- package/dist/action/components/action-form.js.map +1 -1
- package/dist/action/components/action-group.js.map +1 -1
- package/dist/action/components/action-trigger-provider.js.map +1 -1
- package/dist/action/components/action.js.map +1 -1
- package/dist/action/lib/run-action.js +2 -1
- package/dist/action/lib/run-action.js.map +1 -1
- package/dist/appearance/index.js.map +1 -1
- package/dist/chat/components/chat-box.js +4 -2
- package/dist/chat/components/chat-box.js.map +1 -1
- package/dist/chat/components/message-list.js.map +1 -1
- package/dist/chat/components/message.js.map +1 -1
- package/dist/chat/components/prompt-input.js.map +1 -1
- package/dist/chat/hooks/use-chat.js +2 -1
- package/dist/chat/hooks/use-chat.js.map +1 -1
- package/dist/chat/lib/transport.js.map +1 -1
- package/dist/chat/parts/text.js.map +1 -1
- package/dist/chat/parts/tool-call.js.map +1 -1
- package/dist/core/api.js.map +1 -1
- package/dist/core/event-names.d.ts +1 -0
- package/dist/core/event-names.js +1 -0
- package/dist/core/event-names.js.map +1 -1
- package/dist/core/hooks/column-sizing.js.map +1 -1
- package/dist/core/hooks/use-column-resizing.js.map +1 -1
- package/dist/core/materialize.js.map +1 -1
- package/dist/core/registry-context.js.map +1 -1
- package/dist/core/renderer.js +2 -1
- package/dist/core/renderer.js.map +1 -1
- package/dist/core/test-id.js.map +1 -1
- package/dist/core/upload.js.map +1 -1
- package/dist/create-app.js +1 -1
- package/dist/create-app.js.map +1 -1
- package/dist/effects/registry.js +2 -1
- package/dist/effects/registry.js.map +1 -1
- package/dist/form/components/base/field.js.map +1 -1
- package/dist/form/components/base/submit-button.js.map +1 -1
- package/dist/form/components/fields/add-row-menu.js.map +1 -1
- package/dist/form/components/fields/builder.js +2 -1
- package/dist/form/components/fields/builder.js.map +1 -1
- package/dist/form/components/fields/checkbox.js.map +1 -1
- package/dist/form/components/fields/choice.js.map +1 -1
- package/dist/form/components/fields/color-picker-field.js.map +1 -1
- package/dist/form/components/fields/date-input.js.map +1 -1
- package/dist/form/components/fields/date-picker-field.js.map +1 -1
- package/dist/form/components/fields/date-picker-value.js.map +1 -1
- package/dist/form/components/fields/date-picker.js.map +1 -1
- package/dist/form/components/fields/date-time-input.js.map +1 -1
- package/dist/form/components/fields/file-upload.js +3 -2
- package/dist/form/components/fields/file-upload.js.map +1 -1
- package/dist/form/components/fields/number-input.js.map +1 -1
- package/dist/form/components/fields/otp-input.js.map +1 -1
- package/dist/form/components/fields/password-input.js.map +1 -1
- package/dist/form/components/fields/repeater.js +2 -1
- package/dist/form/components/fields/repeater.js.map +1 -1
- package/dist/form/components/fields/rich-editor-field.js +6 -5
- package/dist/form/components/fields/rich-editor-field.js.map +1 -1
- package/dist/form/components/fields/rich-editor.js.map +1 -1
- package/dist/form/components/fields/row-action-menu.js.map +1 -1
- package/dist/form/components/fields/row-actions.js.map +1 -1
- package/dist/form/components/fields/row-item.js.map +1 -1
- package/dist/form/components/fields/row-templates.js.map +1 -1
- package/dist/form/components/fields/select.js.map +1 -1
- package/dist/form/components/fields/simple-field.js.map +1 -1
- package/dist/form/components/fields/table-rows.js.map +1 -1
- package/dist/form/components/fields/text-input.js.map +1 -1
- package/dist/form/components/fields/textarea.js.map +1 -1
- package/dist/form/components/fields/time-input.js.map +1 -1
- package/dist/form/components/fields/time-picker-columns.js.map +1 -1
- package/dist/form/components/fields/time-picker.js +0 -1
- package/dist/form/components/fields/time-picker.js.map +1 -1
- package/dist/form/components/fields/toggle.js.map +1 -1
- package/dist/form/components/fields/use-flip-reorder.js.map +1 -1
- package/dist/form/components/form.js +7 -5
- package/dist/form/components/form.js.map +1 -1
- package/dist/form/components/wizard.js +1 -1
- package/dist/form/components/wizard.js.map +1 -1
- package/dist/form/hooks/resolved-nodes.js.map +1 -1
- package/dist/form/hooks/use-dependent-field.js +2 -1
- package/dist/form/hooks/use-dependent-field.js.map +1 -1
- package/dist/form/hooks/use-form-resolver.js +2 -1
- package/dist/form/hooks/use-form-resolver.js.map +1 -1
- package/dist/form/hooks/values.js +2 -1
- package/dist/form/hooks/values.js.map +1 -1
- package/dist/form/lib/conditions.js +1 -1
- package/dist/form/lib/conditions.js.map +1 -1
- package/dist/form/lib/field-dom-name.js.map +1 -1
- package/dist/form/lib/field-props.js +1 -1
- package/dist/form/lib/field-props.js.map +1 -1
- package/dist/form/lib/form-path.js.map +1 -1
- package/dist/form/lib/form-transport.js.map +1 -1
- package/dist/form/lib/prefill-targets.js.map +1 -1
- package/dist/form/lib/wizard-steps.js.map +1 -1
- package/dist/form/rich-editor/builtins.js.map +1 -1
- package/dist/format/date-time.d.ts +1 -0
- package/dist/format/date-time.js +5 -1
- package/dist/format/date-time.js.map +1 -1
- package/dist/format/number.js.map +1 -1
- package/dist/i18n/config.js.map +1 -1
- package/dist/i18n/date-time-formatter.d.ts +13 -0
- package/dist/i18n/date-time-formatter.js +28 -0
- package/dist/i18n/date-time-formatter.js.map +1 -0
- package/dist/i18n/date-time.js +1 -1
- package/dist/i18n/date-time.js.map +1 -1
- package/dist/i18n/index.js +1 -1
- package/dist/i18n/instance.js +2 -0
- package/dist/i18n/instance.js.map +1 -1
- package/dist/i18n/locale.js +1 -1
- package/dist/i18n/locale.js.map +1 -1
- package/dist/i18n/timezone.js.map +1 -1
- package/dist/i18n/translatable.js.map +1 -1
- package/dist/icons/icon-renderer.js.map +1 -1
- package/dist/icons/sprite.js.map +1 -1
- package/dist/layout/components/breadcrumbs.js.map +1 -1
- package/dist/layout/components/callouts.d.ts +2 -1
- package/dist/layout/components/callouts.js +6 -2
- package/dist/layout/components/callouts.js.map +1 -1
- package/dist/layout/components/dropdown.js.map +1 -1
- package/dist/layout/components/menu-item.js.map +1 -1
- package/dist/layout/components/menu.js.map +1 -1
- package/dist/layout/components/popover.js.map +1 -1
- package/dist/layout/components/schema-layout.js.map +1 -1
- package/dist/layout/components/sidebar.js.map +1 -1
- package/dist/lib/color.js +1 -1
- package/dist/lib/color.js.map +1 -1
- package/dist/lib/use-media-query.js.map +1 -1
- package/dist/notifications/components/empty-state.js.map +1 -1
- package/dist/notifications/components/notification-item.js.map +1 -1
- package/dist/notifications/components/notification-list.js.map +1 -1
- package/dist/notifications/components/notifications.js.map +1 -1
- package/dist/notifications/store.js.map +1 -1
- package/dist/page.js.map +1 -1
- package/dist/provider-base.js.map +1 -1
- package/dist/realtime/listeners.js.map +1 -1
- package/dist/remote/components/data-list.js.map +1 -1
- package/dist/table/components/bulk-bar.js.map +1 -1
- package/dist/table/components/cells/badge-cell.js.map +1 -1
- package/dist/table/components/cells/boolean-cell.js.map +1 -1
- package/dist/table/components/cells/icon-cell.js.map +1 -1
- package/dist/table/components/cells/numeric-cell.js.map +1 -1
- package/dist/table/components/cells/stack-cell.js.map +1 -1
- package/dist/table/components/cells/text-cell.js.map +1 -1
- package/dist/table/components/column-filter-control.js.map +1 -1
- package/dist/table/components/column-header.js.map +1 -1
- package/dist/table/components/column-visibility-menu.js +2 -1
- package/dist/table/components/column-visibility-menu.js.map +1 -1
- package/dist/table/components/filter-bar.js +2 -1
- package/dist/table/components/filter-bar.js.map +1 -1
- package/dist/table/components/filter-controls.js +6 -5
- package/dist/table/components/filter-controls.js.map +1 -1
- package/dist/table/components/filter-value-input.js.map +1 -1
- package/dist/table/components/pagination.d.ts +5 -1
- package/dist/table/components/pagination.js +25 -6
- package/dist/table/components/pagination.js.map +1 -1
- package/dist/table/components/sort-bar.js.map +1 -1
- package/dist/table/components/table-cell.js +2 -1
- package/dist/table/components/table-cell.js.map +1 -1
- package/dist/table/components/table-search.js.map +1 -1
- package/dist/table/components/table.js +6 -2
- package/dist/table/components/table.js.map +1 -1
- package/dist/table/hooks/use-column-visibility.js.map +1 -1
- package/dist/table/hooks/use-table-selection.js +2 -1
- package/dist/table/hooks/use-table-selection.js.map +1 -1
- package/dist/table/hooks/use-table.d.ts +2 -0
- package/dist/table/hooks/use-table.js +12 -0
- package/dist/table/hooks/use-table.js.map +1 -1
- package/dist/table/lib/bulk.js.map +1 -1
- package/dist/table/lib/filter-values.js.map +1 -1
- package/dist/table/lib/format.js.map +1 -1
- package/dist/table/lib/payload.d.ts +2 -0
- package/dist/table/lib/payload.js +18 -3
- package/dist/table/lib/payload.js.map +1 -1
- package/dist/table/lib/query.js +2 -1
- package/dist/table/lib/query.js.map +1 -1
- package/dist/toast/callout.d.ts +1 -0
- package/dist/toast/callout.js +9 -1
- package/dist/toast/callout.js.map +1 -1
- package/dist/toast/index.d.ts +1 -1
- package/dist/toast/index.js +2 -2
- package/dist/toast/toaster.js.map +1 -1
- package/dist/types/generated.d.ts +9 -1
- package/dist/ui/affix-group.js.map +1 -1
- package/dist/ui/avatar.js.map +1 -1
- package/dist/ui/badge.js.map +1 -1
- package/dist/ui/button.js.map +1 -1
- package/dist/ui/card.js.map +1 -1
- package/dist/ui/chart-view.js.map +1 -1
- package/dist/ui/chart.js.map +1 -1
- package/dist/ui/checkbox.js.map +1 -1
- package/dist/ui/collapsible.js.map +1 -1
- package/dist/ui/color-picker.js.map +1 -1
- package/dist/ui/combobox.js.map +1 -1
- package/dist/ui/confirm-dialog.js.map +1 -1
- package/dist/ui/copyable-text.js.map +1 -1
- package/dist/ui/dialog.js.map +1 -1
- package/dist/ui/dropdown-menu.js.map +1 -1
- package/dist/ui/floating-panel.js.map +1 -1
- package/dist/ui/fragment.js +2 -1
- package/dist/ui/fragment.js.map +1 -1
- package/dist/ui/heading.js.map +1 -1
- package/dist/ui/icon-button.js.map +1 -1
- package/dist/ui/icon.js.map +1 -1
- package/dist/ui/image-preview.js.map +1 -1
- package/dist/ui/info-tooltip.js.map +1 -1
- package/dist/ui/input-error.js.map +1 -1
- package/dist/ui/input-otp.js.map +1 -1
- package/dist/ui/link.js.map +1 -1
- package/dist/ui/modal.js.map +1 -1
- package/dist/ui/password-input.js.map +1 -1
- package/dist/ui/progress.js.map +1 -1
- package/dist/ui/section.js +4 -2
- package/dist/ui/section.js.map +1 -1
- package/dist/ui/segmented-control.js.map +1 -1
- package/dist/ui/segmented-pills.js.map +1 -1
- package/dist/ui/tabs.js.map +1 -1
- package/dist/ui/text.js.map +1 -1
- package/dist/ui/tooltip.js.map +1 -1
- package/dist/vite-typescript-refresh.js.map +1 -1
- package/dist/vite.js.map +1 -1
- package/dist-standalone/chunks/chart-view-ZCTbih8A.js +59 -0
- package/dist-standalone/chunks/date-picker-field-CCnkf4SC.js +1 -0
- package/dist-standalone/chunks/dist-CK9gk4iB.js +1 -0
- package/dist-standalone/chunks/dist-DqlcM-vw.js +2 -0
- package/dist-standalone/chunks/icon-button-DcP25cn4.js +41 -0
- package/dist-standalone/chunks/instance-t58Awajh.js +1 -0
- package/dist-standalone/chunks/jsx-runtime-CN5ucv1d.js +1 -0
- package/dist-standalone/chunks/locale-CgtcxthU.js +1 -0
- package/dist-standalone/chunks/materialize-CWqnSEHR.js +1 -0
- package/dist-standalone/chunks/{notifications-echo-DsfNc4Ge.js → notifications-echo-uU87iJAV.js} +1 -1
- package/dist-standalone/chunks/number-BvVKQqOG.js +1 -0
- package/dist-standalone/chunks/page-props-B4GewgLI.js +1 -0
- package/dist-standalone/chunks/react-SIfiwpqq.js +1 -0
- package/dist-standalone/chunks/rich-editor-field-BtbU5XFS.js +158 -0
- package/dist-standalone/chunks/shared-props-B_wT1GcG.js +1 -0
- package/dist-standalone/chunks/subscriptions-BdHDnVA3.js +1 -0
- package/dist-standalone/chunks/time-picker-DSs9fDWe.js +1 -0
- package/dist-standalone/chunks/timezone-BukvzD0d.js +1 -0
- package/dist-standalone/chunks/translatable-DLw4h3x8.js +1 -0
- package/dist-standalone/chunks/use-effect-dispatcher-CiWYRvsF.js +97 -0
- package/dist-standalone/chunks/{with-selector-BwDoCrJJ.js → with-selector-zFUY-tQj.js} +1 -1
- package/dist-standalone/lattice.css +2 -2
- package/dist-standalone/lattice.js +4 -48
- package/dist-standalone/manifest.json +24 -15
- package/dist-standalone/sprite.svg +1 -1
- package/package.json +6 -6
- package/resources/icons/align-center.svg +1 -1
- package/resources/icons/align-justify.svg +1 -1
- package/resources/icons/align-left.svg +1 -1
- package/resources/icons/align-right.svg +1 -1
- package/resources/icons/arrow-down.svg +1 -1
- package/resources/icons/arrow-up.svg +1 -1
- package/resources/icons/bell.svg +1 -1
- package/resources/icons/bold.svg +1 -1
- package/resources/icons/calendar.svg +5 -5
- package/resources/icons/check.svg +1 -1
- package/resources/icons/chevron-down.svg +1 -1
- package/resources/icons/chevron-left.svg +1 -1
- package/resources/icons/chevron-right.svg +1 -1
- package/resources/icons/chevrons-up-down.svg +1 -1
- package/resources/icons/circle-alert.svg +1 -1
- package/resources/icons/circle-check.svg +1 -1
- package/resources/icons/circle-help.svg +1 -1
- package/resources/icons/circle-x.svg +1 -1
- package/resources/icons/clock.svg +1 -1
- package/resources/icons/code-xml.svg +1 -1
- package/resources/icons/code.svg +1 -1
- package/resources/icons/columns-3.svg +1 -1
- package/resources/icons/copy.svg +1 -1
- package/resources/icons/external-link.svg +1 -1
- package/resources/icons/eye-off.svg +1 -1
- package/resources/icons/eye.svg +1 -1
- package/resources/icons/filter.svg +1 -1
- package/resources/icons/heading-1.svg +1 -1
- package/resources/icons/heading-2.svg +1 -1
- package/resources/icons/heading-3.svg +1 -1
- package/resources/icons/heading.svg +1 -1
- package/resources/icons/highlighter.svg +1 -1
- package/resources/icons/info.svg +1 -1
- package/resources/icons/italic.svg +1 -1
- package/resources/icons/layout-dashboard.svg +1 -1
- package/resources/icons/link.svg +1 -1
- package/resources/icons/list-ordered.svg +1 -1
- package/resources/icons/list.svg +1 -1
- package/resources/icons/loader-2.svg +1 -1
- package/resources/icons/minus.svg +1 -1
- package/resources/icons/more-horizontal.svg +1 -1
- package/resources/icons/panel-left.svg +1 -1
- package/resources/icons/pencil-line.svg +1 -1
- package/resources/icons/pencil.svg +1 -1
- package/resources/icons/plus.svg +1 -1
- package/resources/icons/quote.svg +1 -1
- package/resources/icons/rotate-ccw.svg +1 -1
- package/resources/icons/rows-3.svg +1 -1
- package/resources/icons/search.svg +1 -1
- package/resources/icons/send.svg +1 -1
- package/resources/icons/settings.svg +1 -1
- package/resources/icons/smile.svg +1 -1
- package/resources/icons/strikethrough.svg +1 -1
- package/resources/icons/table.svg +1 -1
- package/resources/icons/trash-2.svg +1 -1
- package/resources/icons/underline.svg +1 -1
- package/resources/icons/x.svg +1 -1
- package/dist-standalone/chunks/chart-view-CpYsLvzR.js +0 -36
- package/dist-standalone/chunks/date-picker-field-lX8N40Ii.js +0 -1
- package/dist-standalone/chunks/dist-PaT1gYi_.js +0 -2
- package/dist-standalone/chunks/jsx-runtime-Drll_-DD.js +0 -1
- package/dist-standalone/chunks/locale-CXqr7LPR.js +0 -1
- package/dist-standalone/chunks/page-props-ClpVjpOc.js +0 -1
- package/dist-standalone/chunks/react-B8IZ02wI.js +0 -1
- package/dist-standalone/chunks/rich-editor-field-C71csVJv.js +0 -154
- package/dist-standalone/chunks/subscriptions-B1STcwPE.js +0 -1
- package/dist-standalone/chunks/use-effect-dispatcher-I8So0l_I.js +0 -97
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-picker-value.js","names":[],"sources":["../../../../resources/js/form/components/fields/date-picker-value.ts"],"sourcesContent":["import {\n DateFormatter,\n type DateValue,\n parseAbsolute,\n parseDate,\n parseDateTime,\n parseZonedDateTime,\n toTimeZone,\n toZoned,\n} from \"@internationalized/date\";\n\nconst dateTimeWithZone = /^(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(?::\\d{2})?)\\s+(.+)$/;\nconst bareDateTime = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(?::\\d{2})?$/;\nconst dateTimeFormatOptions = {\n day: \"2-digit\",\n hour: \"2-digit\",\n hourCycle: \"h23\",\n minute: \"2-digit\",\n month: \"2-digit\",\n year: \"numeric\",\n} as const;\nconst dateFormatOptions = {\n day: \"2-digit\",\n month: \"2-digit\",\n year: \"numeric\",\n} as const;\n\nexport function parseDateValue(value: unknown): DateValue | undefined {\n if (typeof value !== \"string\" || value === \"\") {\n return undefined;\n }\n\n try {\n return parseDate(value.slice(0, 10));\n } catch {\n return undefined;\n }\n}\n\nexport function parseDateTimeValue(value: unknown, timezone: string): DateValue | undefined {\n if (typeof value !== \"string\" || value === \"\") {\n return undefined;\n }\n\n const zoned = dateTimeWithZone.exec(value);\n\n try {\n if (zoned) {\n return parseZonedDateTime(`${normalizeSeconds(zoned[1])}[${zoned[2]}]`);\n }\n\n if (bareDateTime.test(value)) {\n return toZoned(parseDateTime(normalizeSeconds(value)), timezone);\n }\n\n return parseAbsolute(value, timezone);\n } catch {\n return undefined;\n }\n}\n\nexport function parseDateDisplayValue(value: unknown, locale: string): DateValue | undefined {\n return parseDateValue(value) ?? parseLocalizedDate(value, locale);\n}\n\nexport function parseDateTimeDisplayValue(\n value: unknown,\n locale: string,\n timezone: string,\n): DateValue | undefined {\n return parseDateTimeValue(value, timezone) ?? parseLocalizedDateTime(value, locale, timezone);\n}\n\nexport function formatDateValue(value: DateValue | undefined): string {\n return value?.toString().slice(0, 10) ?? \"\";\n}\n\nexport function formatDateDisplayValue(value: DateValue | undefined, locale: string): string {\n if (!value) {\n return \"\";\n }\n\n return new DateFormatter(locale, { ...dateFormatOptions, timeZone: \"UTC\" }).format(\n value.toDate(\"UTC\"),\n );\n}\n\nexport function formatDateTimeValue(value: DateValue | undefined, timezone: string): string {\n if (!value) {\n return \"\";\n }\n\n const zoned = \"timeZone\" in value ? toTimeZone(value, timezone) : toZoned(value, timezone);\n const text = zoned.toString().replace(/\\[.+\\]$/, \"\");\n\n return `${normalizeSeconds(text).slice(0, 19)} ${timezone}`;\n}\n\nexport function formatDateTimeDisplayValue(\n value: DateValue | undefined,\n locale: string,\n timezone: string,\n): string {\n if (!value) {\n return \"\";\n }\n\n const zoned = \"timeZone\" in value ? toTimeZone(value, timezone) : toZoned(value, timezone);\n\n return new DateFormatter(locale, { ...dateTimeFormatOptions, timeZone: timezone }).format(\n zoned.toDate(),\n );\n}\n\nexport function formatTimeInputValue(value: DateValue | undefined, timezone: string): string {\n if (!value) {\n return \"\";\n }\n\n const zoned = \"timeZone\" in value ? toTimeZone(value, timezone) : toZoned(value, timezone);\n\n return [\n String(zoned.hour).padStart(2, \"0\"),\n String(zoned.minute).padStart(2, \"0\"),\n String(zoned.second).padStart(2, \"0\"),\n ].join(\":\");\n}\n\nfunction normalizeSeconds(value: string): string {\n return /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}$/.test(value) ? `${value}:00` : value;\n}\n\nfunction parseLocalizedDate(value: unknown, locale: string): DateValue | undefined {\n const parts = localizedParts(value, locale, \"date\");\n\n if (!parts) {\n return undefined;\n }\n\n try {\n return parseDate(\n `${parts.year.padStart(4, \"0\")}-${parts.month.padStart(2, \"0\")}-${parts.day.padStart(2, \"0\")}`,\n );\n } catch {\n return undefined;\n }\n}\n\nfunction parseLocalizedDateTime(\n value: unknown,\n locale: string,\n timezone: string,\n): DateValue | undefined {\n const parts = localizedParts(value, locale, \"date-time\");\n\n if (!parts || !parts.hour || !parts.minute) {\n return undefined;\n }\n\n try {\n return toZoned(\n parseDateTime(\n `${parts.year.padStart(4, \"0\")}-${parts.month.padStart(2, \"0\")}-${parts.day.padStart(2, \"0\")}T${parts.hour.padStart(2, \"0\")}:${parts.minute.padStart(2, \"0\")}:00`,\n ),\n timezone,\n );\n } catch {\n return undefined;\n }\n}\n\nfunction localizedParts(\n value: unknown,\n locale: string,\n mode: \"date\" | \"date-time\",\n):\n | {\n day: string;\n hour?: string;\n minute?: string;\n month: string;\n year: string;\n }\n | undefined {\n if (typeof value !== \"string\" || value.trim() === \"\") {\n return undefined;\n }\n\n const formatter = new DateFormatter(\n locale,\n mode === \"date\" ? dateFormatOptions : dateTimeFormatOptions,\n );\n const sample = new Date(Date.UTC(2006, 10, 22, 14, 30, 0));\n const pattern = formatter\n .formatToParts(sample)\n .map((part) => {\n if ([\"day\", \"hour\", \"minute\", \"month\", \"year\"].includes(part.type)) {\n return `(?<${part.type}>\\\\d{1,4})`;\n }\n\n return escapeRegExp(part.value).replace(/\\s+/g, \"\\\\s*\");\n })\n .join(\"\");\n const match = new RegExp(`^\\\\s*${pattern}\\\\s*$`).exec(value);\n const groups = match?.groups;\n\n if (!groups?.day || !groups.month || !groups.year) {\n return undefined;\n }\n\n return {\n day: groups.day,\n hour: groups.hour,\n minute: groups.minute,\n month: groups.month,\n year: groups.year,\n };\n}\n\nfunction escapeRegExp(value: string): string {\n return value.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n"],"mappings":";;AAWA,IAAM,mBAAmB;AACzB,IAAM,eAAe;AACrB,IAAM,wBAAwB;CAC5B,KAAK;CACL,MAAM;CACN,WAAW;CACX,QAAQ;CACR,OAAO;CACP,MAAM;AACR;AACA,IAAM,oBAAoB;CACxB,KAAK;CACL,OAAO;CACP,MAAM;AACR;AAEA,SAAgB,eAAe,OAAuC;CACpE,IAAI,OAAO,UAAU,YAAY,UAAU,IACzC;CAGF,IAAI;EACF,OAAO,UAAU,MAAM,MAAM,GAAG,EAAE,CAAC;CACrC,QAAQ;EACN;CACF;AACF;AAEA,SAAgB,mBAAmB,OAAgB,UAAyC;CAC1F,IAAI,OAAO,UAAU,YAAY,UAAU,IACzC;CAGF,MAAM,QAAQ,iBAAiB,KAAK,KAAK;CAEzC,IAAI;EACF,IAAI,OACF,OAAO,mBAAmB,GAAG,iBAAiB,MAAM,EAAE,EAAE,GAAG,MAAM,GAAG,EAAE;EAGxE,IAAI,aAAa,KAAK,KAAK,GACzB,OAAO,QAAQ,cAAc,iBAAiB,KAAK,CAAC,GAAG,QAAQ;EAGjE,OAAO,cAAc,OAAO,QAAQ;CACtC,QAAQ;EACN;CACF;AACF;AAEA,SAAgB,sBAAsB,OAAgB,QAAuC;CAC3F,OAAO,eAAe,KAAK,KAAK,mBAAmB,OAAO,MAAM;AAClE;AAEA,SAAgB,0BACd,OACA,QACA,UACuB;CACvB,OAAO,mBAAmB,OAAO,QAAQ,KAAK,uBAAuB,OAAO,QAAQ,QAAQ;AAC9F;AAEA,SAAgB,gBAAgB,OAAsC;CACpE,OAAO,OAAO,SAAS,
|
|
1
|
+
{"version":3,"file":"date-picker-value.js","names":[],"sources":["../../../../resources/js/form/components/fields/date-picker-value.ts"],"sourcesContent":["import {\n DateFormatter,\n type DateValue,\n parseAbsolute,\n parseDate,\n parseDateTime,\n parseZonedDateTime,\n toTimeZone,\n toZoned,\n} from \"@internationalized/date\";\n\nconst dateTimeWithZone = /^(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(?::\\d{2})?)\\s+(.+)$/;\nconst bareDateTime = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(?::\\d{2})?$/;\nconst dateTimeFormatOptions = {\n day: \"2-digit\",\n hour: \"2-digit\",\n hourCycle: \"h23\",\n minute: \"2-digit\",\n month: \"2-digit\",\n year: \"numeric\",\n} as const;\nconst dateFormatOptions = {\n day: \"2-digit\",\n month: \"2-digit\",\n year: \"numeric\",\n} as const;\n\nexport function parseDateValue(value: unknown): DateValue | undefined {\n if (typeof value !== \"string\" || value === \"\") {\n return undefined;\n }\n\n try {\n return parseDate(value.slice(0, 10));\n } catch {\n return undefined;\n }\n}\n\nexport function parseDateTimeValue(value: unknown, timezone: string): DateValue | undefined {\n if (typeof value !== \"string\" || value === \"\") {\n return undefined;\n }\n\n const zoned = dateTimeWithZone.exec(value);\n\n try {\n if (zoned) {\n return parseZonedDateTime(`${normalizeSeconds(zoned[1])}[${zoned[2]}]`);\n }\n\n if (bareDateTime.test(value)) {\n return toZoned(parseDateTime(normalizeSeconds(value)), timezone);\n }\n\n return parseAbsolute(value, timezone);\n } catch {\n return undefined;\n }\n}\n\nexport function parseDateDisplayValue(value: unknown, locale: string): DateValue | undefined {\n return parseDateValue(value) ?? parseLocalizedDate(value, locale);\n}\n\nexport function parseDateTimeDisplayValue(\n value: unknown,\n locale: string,\n timezone: string,\n): DateValue | undefined {\n return parseDateTimeValue(value, timezone) ?? parseLocalizedDateTime(value, locale, timezone);\n}\n\nexport function formatDateValue(value: DateValue | undefined): string {\n return value?.toString().slice(0, 10) ?? \"\";\n}\n\nexport function formatDateDisplayValue(value: DateValue | undefined, locale: string): string {\n if (!value) {\n return \"\";\n }\n\n return new DateFormatter(locale, { ...dateFormatOptions, timeZone: \"UTC\" }).format(\n value.toDate(\"UTC\"),\n );\n}\n\nexport function formatDateTimeValue(value: DateValue | undefined, timezone: string): string {\n if (!value) {\n return \"\";\n }\n\n const zoned = \"timeZone\" in value ? toTimeZone(value, timezone) : toZoned(value, timezone);\n const text = zoned.toString().replace(/\\[.+\\]$/, \"\");\n\n return `${normalizeSeconds(text).slice(0, 19)} ${timezone}`;\n}\n\nexport function formatDateTimeDisplayValue(\n value: DateValue | undefined,\n locale: string,\n timezone: string,\n): string {\n if (!value) {\n return \"\";\n }\n\n const zoned = \"timeZone\" in value ? toTimeZone(value, timezone) : toZoned(value, timezone);\n\n return new DateFormatter(locale, { ...dateTimeFormatOptions, timeZone: timezone }).format(\n zoned.toDate(),\n );\n}\n\nexport function formatTimeInputValue(value: DateValue | undefined, timezone: string): string {\n if (!value) {\n return \"\";\n }\n\n const zoned = \"timeZone\" in value ? toTimeZone(value, timezone) : toZoned(value, timezone);\n\n return [\n String(zoned.hour).padStart(2, \"0\"),\n String(zoned.minute).padStart(2, \"0\"),\n String(zoned.second).padStart(2, \"0\"),\n ].join(\":\");\n}\n\nfunction normalizeSeconds(value: string): string {\n return /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}$/.test(value) ? `${value}:00` : value;\n}\n\nfunction parseLocalizedDate(value: unknown, locale: string): DateValue | undefined {\n const parts = localizedParts(value, locale, \"date\");\n\n if (!parts) {\n return undefined;\n }\n\n try {\n return parseDate(\n `${parts.year.padStart(4, \"0\")}-${parts.month.padStart(2, \"0\")}-${parts.day.padStart(2, \"0\")}`,\n );\n } catch {\n return undefined;\n }\n}\n\nfunction parseLocalizedDateTime(\n value: unknown,\n locale: string,\n timezone: string,\n): DateValue | undefined {\n const parts = localizedParts(value, locale, \"date-time\");\n\n if (!parts || !parts.hour || !parts.minute) {\n return undefined;\n }\n\n try {\n return toZoned(\n parseDateTime(\n `${parts.year.padStart(4, \"0\")}-${parts.month.padStart(2, \"0\")}-${parts.day.padStart(2, \"0\")}T${parts.hour.padStart(2, \"0\")}:${parts.minute.padStart(2, \"0\")}:00`,\n ),\n timezone,\n );\n } catch {\n return undefined;\n }\n}\n\nfunction localizedParts(\n value: unknown,\n locale: string,\n mode: \"date\" | \"date-time\",\n):\n | {\n day: string;\n hour?: string;\n minute?: string;\n month: string;\n year: string;\n }\n | undefined {\n if (typeof value !== \"string\" || value.trim() === \"\") {\n return undefined;\n }\n\n const formatter = new DateFormatter(\n locale,\n mode === \"date\" ? dateFormatOptions : dateTimeFormatOptions,\n );\n const sample = new Date(Date.UTC(2006, 10, 22, 14, 30, 0));\n const pattern = formatter\n .formatToParts(sample)\n .map((part) => {\n if ([\"day\", \"hour\", \"minute\", \"month\", \"year\"].includes(part.type)) {\n return `(?<${part.type}>\\\\d{1,4})`;\n }\n\n return escapeRegExp(part.value).replace(/\\s+/g, \"\\\\s*\");\n })\n .join(\"\");\n const match = new RegExp(`^\\\\s*${pattern}\\\\s*$`).exec(value);\n const groups = match?.groups;\n\n if (!groups?.day || !groups.month || !groups.year) {\n return undefined;\n }\n\n return {\n day: groups.day,\n hour: groups.hour,\n minute: groups.minute,\n month: groups.month,\n year: groups.year,\n };\n}\n\nfunction escapeRegExp(value: string): string {\n return value.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n"],"mappings":";;AAWA,IAAM,mBAAmB;AACzB,IAAM,eAAe;AACrB,IAAM,wBAAwB;CAC5B,KAAK;CACL,MAAM;CACN,WAAW;CACX,QAAQ;CACR,OAAO;CACP,MAAM;AACR;AACA,IAAM,oBAAoB;CACxB,KAAK;CACL,OAAO;CACP,MAAM;AACR;AAEA,SAAgB,eAA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S,GAAG,GAAG,EAAE,GAAG,MAAM,IAAI,SAAS,GAAG,GAAG,EAAE,GAAG,MAAM,KAAK,SAAS,GAAG,GAAG,EAAE,GAAG,MAAM,OAAO,SAAS,GAAG,GAAG,EAAE,IAC/J,GACA,QACF;CACF,QAAQ;EACN;CACF;AACF;AAEA,SAAS,eACP,OACA,QACA,MASY;CACZ,IAAI,OAAO,UAAU,YAAY,MAAM,KAAK,MAAM,IAChD;CAGF,MAAM,YAAY,IAAI,cACpB,QACA,SAAS,SAAS,oBAAoB,qBACxC;CACA,MAAM,SAAS,IAAI,KAAK,KAAK,IAAI,MAAM,IAAI,IAAI,IAAI,IAAI,CAAC,CAAC;CACzD,MAAM,UAAU,UACb,cAAc,MAAM,CAAC,CACrB,KAAK,SAAS;EACb,IAAI;GAAC;GAAO;GAAQ;GAAU;GAAS;EAAM,CAAC,CAAC,SAAS,KAAK,IAAI,GAC/D,OAAO,MAAM,KAAK,KAAK;EAGzB,OAAO,aAAa,KAAK,KAAK,CAAC,CAAC,QAAQ,QAAQ,MAAM;CACxD,CAAC,CAAC,CACD,KAAK,EAAE;CAEV,MAAM,SADQ,IAAI,OAAO,QAAQ,QAAQ,MAAM,CAAC,CAAC,KAAK,KACvC,CAAA,EAAO;CAEtB,IAAI,CAAC,QAAQ,OAAO,CAAC,OAAO,SAAS,CAAC,OAAO,MAC3C;CAGF,OAAO;EACL,KAAK,OAAO;EACZ,MAAM,OAAO;EACb,QAAQ,OAAO;EACf,OAAO,OAAO;EACd,MAAM,OAAO;CACf;AACF;AAEA,SAAS,aAAa,OAAuB;CAC3C,OAAO,MAAM,QAAQ,uBAAuB,MAAM;AACpD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-picker.js","names":[],"sources":["../../../../resources/js/form/components/fields/date-picker.tsx"],"sourcesContent":["import { lazy, Suspense } from \"react\";\nimport type { DatePickerFieldProps } from \"./date-picker-field\";\n\nconst DatePickerField = lazy(async () => {\n const { DatePickerField } = await import(\"./date-picker-field\");\n\n return { default: DatePickerField };\n});\n\nexport function DatePicker(props: DatePickerFieldProps) {\n return (\n <Suspense fallback={null}>\n <DatePickerField {...props} />\n </Suspense>\n );\n}\n"],"mappings":";;;AAGA,IAAM,kBAAkB,KAAK,YAAY;CACvC,MAAM,EAAE,oBAAoB,MAAM,OAAO;CAEzC,OAAO,EAAE,SAAS,gBAAgB;AACpC,CAAC;AAED,SAAgB,WAAW,OAA6B;CACtD,OACE,oBAAC,UAAD;EAAU,UAAU;
|
|
1
|
+
{"version":3,"file":"date-picker.js","names":[],"sources":["../../../../resources/js/form/components/fields/date-picker.tsx"],"sourcesContent":["import { lazy, Suspense } from \"react\";\nimport type { DatePickerFieldProps } from \"./date-picker-field\";\n\nconst DatePickerField = lazy(async () => {\n const { DatePickerField } = await import(\"./date-picker-field\");\n\n return { default: DatePickerField };\n});\n\nexport function DatePicker(props: DatePickerFieldProps) {\n return (\n <Suspense fallback={null}>\n <DatePickerField {...props} />\n </Suspense>\n );\n}\n"],"mappings":";;;AAGA,IAAM,kBAAkB,KAAK,YAAY;CACvC,MAAM,EAAE,oBAAoB,MAAM,OAAO;CAEzC,OAAO,EAAE,SAAS,gBAAgB;AACpC,CAAC;AAED,SAAgB,WAAW,OAA6B;CACtD,OACE,oBAAC,UAAD;EAAU,UAAU;EAClB,UAAA,oBAAC,iBAAD,EAAiB,GAAI,MAAQ,CAAA;CACrB,CAAA;AAEd"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-time-input.js","names":[],"sources":["../../../../resources/js/form/components/fields/date-time-input.tsx"],"sourcesContent":["import type { RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport { useTimezone } from \"@lattice-php/lattice/i18n\";\nimport { DatePicker } from \"./date-picker\";\nimport { SimpleField } from \"./simple-field\";\n\nexport const DateTimeInputComponent: RendererComponent<\"field.date-time-input\"> = ({ node }) => {\n const props = node.props;\n const { timezone } = useTimezone();\n\n return (\n <SimpleField node={node} label={props.label ?? \"\"}>\n {({ name, testId, value, readOnly, disabled, change, blur }) => (\n <DatePicker\n autoFocus={props.autoFocus ?? false}\n disabled={disabled}\n label={props.label ?? props.name}\n max={props.max}\n min={props.min}\n mode=\"date-time\"\n name={name}\n onBlur={blur}\n onChange={change}\n readOnly={readOnly}\n step={props.step}\n tabIndex={props.tabIndex ?? undefined}\n testId={testId ?? props.name}\n timezone={timezone}\n value={value}\n />\n )}\n </SimpleField>\n );\n};\n"],"mappings":";;;;;AAKA,IAAa,0BAAsE,EAAE,WAAW;CAC9F,MAAM,QAAQ,KAAK;CACnB,MAAM,EAAE,aAAa,YAAY;CAEjC,OACE,oBAAC,aAAD;EAAmB;EAAM,OAAO,MAAM,SAAS;
|
|
1
|
+
{"version":3,"file":"date-time-input.js","names":[],"sources":["../../../../resources/js/form/components/fields/date-time-input.tsx"],"sourcesContent":["import type { RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport { useTimezone } from \"@lattice-php/lattice/i18n\";\nimport { DatePicker } from \"./date-picker\";\nimport { SimpleField } from \"./simple-field\";\n\nexport const DateTimeInputComponent: RendererComponent<\"field.date-time-input\"> = ({ node }) => {\n const props = node.props;\n const { timezone } = useTimezone();\n\n return (\n <SimpleField node={node} label={props.label ?? \"\"}>\n {({ name, testId, value, readOnly, disabled, change, blur }) => (\n <DatePicker\n autoFocus={props.autoFocus ?? false}\n disabled={disabled}\n label={props.label ?? props.name}\n max={props.max}\n min={props.min}\n mode=\"date-time\"\n name={name}\n onBlur={blur}\n onChange={change}\n readOnly={readOnly}\n step={props.step}\n tabIndex={props.tabIndex ?? undefined}\n testId={testId ?? props.name}\n timezone={timezone}\n value={value}\n />\n )}\n </SimpleField>\n );\n};\n"],"mappings":";;;;;AAKA,IAAa,0BAAsE,EAAE,WAAW;CAC9F,MAAM,QAAQ,KAAK;CACnB,MAAM,EAAE,aAAa,YAAY;CAEjC,OACE,oBAAC,aAAD;EAAmB;EAAM,OAAO,MAAM,SAAS;EAC3C,WAAA,EAAE,MAAM,QAAQ,OAAO,UAAU,UAAU,QAAQ,WACnD,oBAAC,YAAD;GACE,WAAW,MAAM,aAAa;GACpB;GACV,OAAO,MAAM,SAAS,MAAM;GAC5B,KAAK,MAAM;GACX,KAAK,MAAM;GACX,MAAK;GACC;GACN,QAAQ;GACR,UAAU;GACA;GACV,MAAM,MAAM;GACZ,UAAU,MAAM,YAAY,KAAA;GAC5B,QAAQ,UAAU,MAAM;GACd;GACH;EACR,CAAA;CAEQ,CAAA;AAEjB"}
|
|
@@ -33,7 +33,7 @@ var FileUploadComponent = ({ node }) => {
|
|
|
33
33
|
const signed = props.signed;
|
|
34
34
|
const multiple = props.multiple;
|
|
35
35
|
const fieldName = multiple ? `${domName}[]` : domName;
|
|
36
|
-
const
|
|
36
|
+
const initial = useMemo(() => (props.files ?? []).map((file) => ({
|
|
37
37
|
id: crypto.randomUUID(),
|
|
38
38
|
name: file.name,
|
|
39
39
|
size: file.size,
|
|
@@ -43,7 +43,8 @@ var FileUploadComponent = ({ node }) => {
|
|
|
43
43
|
url: file.url,
|
|
44
44
|
token: file.token,
|
|
45
45
|
existing: true
|
|
46
|
-
})), [props.files])
|
|
46
|
+
})), [props.files]);
|
|
47
|
+
const [items, setItems] = useState(initial);
|
|
47
48
|
const [removedTokens, setRemovedTokens] = useState([]);
|
|
48
49
|
useEffect(() => {
|
|
49
50
|
if (!signed) return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-upload.js","names":[],"sources":["../../../../resources/js/form/components/fields/file-upload.tsx"],"sourcesContent":["import { testIdentity } from \"@lattice-php/lattice/core/test-id\";\nimport { requestSignedUpload, xhrTransfer } from \"@lattice-php/lattice/core/upload\";\nimport type { RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport type { SignedUpload } from \"@lattice-php/lattice/types/generated\";\nimport { IconButton } from \"@lattice-php/lattice/ui/icon-button\";\nimport { useT } from \"@lattice-php/lattice/i18n\";\nimport { useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport { FormFieldFrame } from \"@lattice-php/lattice/form/components/base/field\";\nimport { useFormContext } from \"@lattice-php/lattice/form/hooks/context\";\nimport { useDependentField } from \"@lattice-php/lattice/form/hooks/use-dependent-field\";\nimport { useFieldScope } from \"@lattice-php/lattice/form/hooks/field-scope\";\nimport { useFormValues, useSetFormValue } from \"@lattice-php/lattice/form/hooks/values\";\n\ntype Item = {\n id: string;\n name: string;\n size: number | null;\n status: \"ready\" | \"uploading\" | \"error\";\n progress: number;\n file?: File;\n key?: string;\n url?: string | null;\n token?: string;\n existing: boolean;\n};\n\nfunction uploadValueEquals(current: unknown, next: string[] | string): boolean {\n if (Array.isArray(next)) {\n return (\n Array.isArray(current) &&\n current.length === next.length &&\n current.every((value, index) => value === next[index])\n );\n }\n\n return current === next;\n}\n\nexport const FileUploadComponent: RendererComponent<\"field.file-upload\"> = ({ node }) => {\n const { t } = useT(\"lattice\");\n const props = node.props;\n const { hidden, required, readOnly, disabled } = useDependentField(node);\n const { action, componentRef, errors } = useFormContext();\n const name = props.name;\n const scope = useFieldScope();\n const domName = scope ? scope.scopedName(name) : name;\n const errorKey = scope ? scope.errorKey(name) : name;\n const uploadKey = errorKey;\n const values = useFormValues();\n const setValue = useSetFormValue();\n const inputId = useId();\n const fileInputRef = useRef<HTMLInputElement>(null);\n const previewUrlsRef = useRef<Set<string>>(new Set());\n const locked = readOnly || disabled;\n const signed = props.signed;\n const multiple = props.multiple;\n const fieldName = multiple ? `${domName}[]` : domName;\n\n const initial = useMemo<Item[]>(\n () =>\n (props.files ?? []).map((file) => ({\n id: crypto.randomUUID(),\n name: file.name,\n size: file.size,\n status: \"ready\" as const,\n progress: 100,\n key: file.key,\n url: file.url,\n token: file.token,\n existing: true,\n })),\n [props.files],\n );\n const [items, setItems] = useState<Item[]>(initial);\n const [removedTokens, setRemovedTokens] = useState<string[]>([]);\n\n useEffect(() => {\n if (!signed) {\n return;\n }\n\n const keys = items\n .filter((item) => !item.existing && item.key && item.status === \"ready\")\n .map((item) => item.key as string);\n const next = multiple ? keys : (keys[0] ?? \"\");\n\n if (scope) {\n if (!uploadValueEquals(scope.getValue(name), next)) {\n scope.setValue(name, next);\n }\n\n return;\n }\n\n setValue(name, next);\n }, [items, multiple, name, scope, setValue, signed]);\n\n useEffect(() => {\n if (!signed || scope) {\n return;\n }\n\n setValue(`${name}__removed`, removedTokens);\n }, [name, removedTokens, scope, setValue, signed]);\n\n useEffect(\n () => () => {\n previewUrlsRef.current.forEach((url) => URL.revokeObjectURL(url));\n previewUrlsRef.current.clear();\n },\n [],\n );\n\n const multipartFiles = useMemo(\n () => items.filter((item) => item.file && !item.existing).map((item) => item.file as File),\n [items],\n );\n useEffect(() => {\n if (signed || !fileInputRef.current) {\n return;\n }\n\n const transfer = new DataTransfer();\n multipartFiles.forEach((file) => transfer.items.add(file));\n fileInputRef.current.files = transfer.files;\n }, [multipartFiles, signed]);\n\n function createPreviewUrl(file: File): string | undefined {\n if (!props.image) {\n return undefined;\n }\n\n const url = URL.createObjectURL(file);\n previewUrlsRef.current.add(url);\n\n return url;\n }\n\n function revokePreviewUrl(item: Item): void {\n if (!item.url || !previewUrlsRef.current.has(item.url)) {\n return;\n }\n\n URL.revokeObjectURL(item.url);\n previewUrlsRef.current.delete(item.url);\n }\n\n async function signAndUpload(item: Item, file: File): Promise<void> {\n const markFailed = (): void => {\n setItems((prev) =>\n prev.map((entry) => (entry.id === item.id ? { ...entry, status: \"error\" } : entry)),\n );\n };\n\n const response = await requestSignedUpload(action, {\n ref: componentRef,\n target: uploadKey,\n filename: file.name,\n contentType: file.type,\n values,\n });\n\n if (!response.ok) {\n markFailed();\n\n return;\n }\n\n const sign = (await response.json()) as SignedUpload;\n\n try {\n const put = await xhrTransfer({\n url: sign.url,\n method: sign.method.toUpperCase(),\n body: file,\n headers: sign.headers,\n onProgress: (progress) =>\n setItems((prev) =>\n prev.map((entry) => (entry.id === item.id ? { ...entry, progress } : entry)),\n ),\n });\n\n setItems((prev) =>\n prev.map((entry) =>\n entry.id === item.id\n ? {\n ...entry,\n status: put.ok ? \"ready\" : \"error\",\n key: sign.key,\n progress: 100,\n }\n : entry,\n ),\n );\n } catch {\n markFailed();\n }\n }\n\n function addFiles(fileList: FileList | null): void {\n if (!fileList || locked) {\n return;\n }\n\n const incoming = Array.from(fileList);\n const next = incoming.map<Item>((file) => ({\n id: crypto.randomUUID(),\n name: file.name,\n size: file.size,\n status: signed ? \"uploading\" : \"ready\",\n progress: 0,\n file,\n url: createPreviewUrl(file),\n existing: false,\n }));\n\n if (!multiple) {\n items.forEach(revokePreviewUrl);\n\n if (!scope) {\n const replacedTokens = items\n .filter((item) => item.existing && item.token)\n .map((item) => item.token as string);\n\n if (replacedTokens.length > 0) {\n setRemovedTokens((tokens) => [...tokens, ...replacedTokens]);\n }\n }\n }\n\n setItems((prev) => (multiple ? [...prev, ...next] : next));\n\n if (signed) {\n next.forEach((item, index) => void signAndUpload(item, incoming[index]));\n }\n }\n\n function removeItem(id: string): void {\n const target = items.find((item) => item.id === id);\n\n if (target) {\n revokePreviewUrl(target);\n }\n\n if (target?.existing && target.token && !scope) {\n setRemovedTokens((tokens) => [...tokens, target.token as string]);\n }\n\n setItems((prev) => prev.filter((i) => i.id !== id));\n }\n\n if (hidden) {\n return null;\n }\n\n return (\n <FormFieldFrame\n error={errors[errorKey]}\n helperText={props.helperText ?? undefined}\n tooltip={props.tooltip ?? undefined}\n label={props.label ?? \"\"}\n name={name}\n required={required}\n >\n <div\n className=\"flex flex-col gap-3 rounded-lt-sm border border-dashed border-lt-border bg-lt-surface px-4 py-6\"\n data-test={testIdentity(name)}\n onDragOver={(event) => event.preventDefault()}\n onDrop={(event) => {\n event.preventDefault();\n addFiles(event.dataTransfer.files);\n }}\n >\n <button\n className=\"text-sm text-lt-muted-fg\"\n disabled={locked}\n onClick={() => fileInputRef.current?.click()}\n type=\"button\"\n >\n {t(\"form.file-upload.dropzone\", \"Drop files here or click to browse\")}\n </button>\n\n <ul\n className={props.image ? \"grid grid-cols-1 gap-3 sm:grid-cols-2\" : \"flex flex-col gap-2\"}\n >\n {items.map((item) => (\n <li\n className={\n props.image\n ? \"flex min-w-0 items-center gap-3 rounded-lt-sm border border-lt-border bg-lt-bg p-2 text-sm\"\n : \"flex items-center justify-between gap-3 text-sm\"\n }\n key={item.id}\n >\n {props.image && item.url ? (\n <img\n alt={item.name}\n className=\"size-16 shrink-0 rounded-lt-sm border border-lt-border object-cover\"\n data-test={testIdentity(`${name}-preview`)}\n src={item.url}\n />\n ) : null}\n <div className=\"min-w-0 flex-1\">\n <span className=\"block truncate\" data-test={testIdentity(`${name}-item`)}>\n {item.name}\n </span>\n {item.status === \"uploading\" && (\n <span className=\"text-xs text-lt-muted-fg\">{item.progress}%</span>\n )}\n {item.status === \"error\" && (\n <span className=\"text-xs text-lt-danger\">\n {t(\"form.file-upload.failed\", \"Failed\")}\n </span>\n )}\n </div>\n {(!item.existing || !scope) && (\n <IconButton\n size=\"sm\"\n icon=\"x\"\n label={t(\"form.file-upload.remove\", \"Remove {{name}}\", { name: item.name })}\n data-test={testIdentity(\n item.existing ? `${name}-remove-existing` : `${name}-remove`,\n )}\n disabled={locked}\n onClick={() => removeItem(item.id)}\n />\n )}\n {signed && !item.existing && item.key && item.status === \"ready\" && (\n <input\n data-test={testIdentity(`${name}-uploaded`)}\n name={fieldName}\n type=\"hidden\"\n value={item.key}\n />\n )}\n </li>\n ))}\n </ul>\n\n {!scope &&\n removedTokens.map((token) => (\n <input key={token} name={`${name}__removed[]`} type=\"hidden\" value={token} />\n ))}\n\n <input\n accept={props.accept ?? undefined}\n aria-label={props.label ?? name}\n className=\"sr-only\"\n data-test={testIdentity(`${name}-input`)}\n id={inputId}\n multiple={multiple}\n name={signed ? undefined : fieldName}\n onChange={(event) => {\n addFiles(event.target.files);\n if (signed) {\n event.target.value = \"\";\n }\n }}\n ref={fileInputRef}\n type=\"file\"\n />\n </div>\n </FormFieldFrame>\n );\n};\n"],"mappings":";;;;;;;;;;;;AA0BA,SAAS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3,"file":"file-upload.js","names":[],"sources":["../../../../resources/js/form/components/fields/file-upload.tsx"],"sourcesContent":["import { testIdentity } from \"@lattice-php/lattice/core/test-id\";\nimport { requestSignedUpload, xhrTransfer } from \"@lattice-php/lattice/core/upload\";\nimport type { RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport type { SignedUpload } from \"@lattice-php/lattice/types/generated\";\nimport { IconButton } from \"@lattice-php/lattice/ui/icon-button\";\nimport { useT } from \"@lattice-php/lattice/i18n\";\nimport { useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport { FormFieldFrame } from \"@lattice-php/lattice/form/components/base/field\";\nimport { useFormContext } from \"@lattice-php/lattice/form/hooks/context\";\nimport { useDependentField } from \"@lattice-php/lattice/form/hooks/use-dependent-field\";\nimport { useFieldScope } from \"@lattice-php/lattice/form/hooks/field-scope\";\nimport { useFormValues, useSetFormValue } from \"@lattice-php/lattice/form/hooks/values\";\n\ntype Item = {\n id: string;\n name: string;\n size: number | null;\n status: \"ready\" | \"uploading\" | \"error\";\n progress: number;\n file?: File;\n key?: string;\n url?: string | null;\n token?: string;\n existing: boolean;\n};\n\nfunction uploadValueEquals(current: unknown, next: string[] | string): boolean {\n if (Array.isArray(next)) {\n return (\n Array.isArray(current) &&\n current.length === next.length &&\n current.every((value, index) => value === next[index])\n );\n }\n\n return current === next;\n}\n\nexport const FileUploadComponent: RendererComponent<\"field.file-upload\"> = ({ node }) => {\n const { t } = useT(\"lattice\");\n const props = node.props;\n const { hidden, required, readOnly, disabled } = useDependentField(node);\n const { action, componentRef, errors } = useFormContext();\n const name = props.name;\n const scope = useFieldScope();\n const domName = scope ? scope.scopedName(name) : name;\n const errorKey = scope ? scope.errorKey(name) : name;\n const uploadKey = errorKey;\n const values = useFormValues();\n const setValue = useSetFormValue();\n const inputId = useId();\n const fileInputRef = useRef<HTMLInputElement>(null);\n const previewUrlsRef = useRef<Set<string>>(new Set());\n const locked = readOnly || disabled;\n const signed = props.signed;\n const multiple = props.multiple;\n const fieldName = multiple ? `${domName}[]` : domName;\n\n const initial = useMemo<Item[]>(\n () =>\n (props.files ?? []).map((file) => ({\n id: crypto.randomUUID(),\n name: file.name,\n size: file.size,\n status: \"ready\" as const,\n progress: 100,\n key: file.key,\n url: file.url,\n token: file.token,\n existing: true,\n })),\n [props.files],\n );\n const [items, setItems] = useState<Item[]>(initial);\n const [removedTokens, setRemovedTokens] = useState<string[]>([]);\n\n useEffect(() => {\n if (!signed) {\n return;\n }\n\n const keys = items\n .filter((item) => !item.existing && item.key && item.status === \"ready\")\n .map((item) => item.key as string);\n const next = multiple ? keys : (keys[0] ?? \"\");\n\n if (scope) {\n if (!uploadValueEquals(scope.getValue(name), next)) {\n scope.setValue(name, next);\n }\n\n return;\n }\n\n setValue(name, next);\n }, [items, multiple, name, scope, setValue, signed]);\n\n useEffect(() => {\n if (!signed || scope) {\n return;\n }\n\n setValue(`${name}__removed`, removedTokens);\n }, [name, removedTokens, scope, setValue, signed]);\n\n useEffect(\n () => () => {\n previewUrlsRef.current.forEach((url) => URL.revokeObjectURL(url));\n previewUrlsRef.current.clear();\n },\n [],\n );\n\n const multipartFiles = useMemo(\n () => items.filter((item) => item.file && !item.existing).map((item) => item.file as File),\n [items],\n );\n useEffect(() => {\n if (signed || !fileInputRef.current) {\n return;\n }\n\n const transfer = new DataTransfer();\n multipartFiles.forEach((file) => transfer.items.add(file));\n fileInputRef.current.files = transfer.files;\n }, [multipartFiles, signed]);\n\n function createPreviewUrl(file: File): string | undefined {\n if (!props.image) {\n return undefined;\n }\n\n const url = URL.createObjectURL(file);\n previewUrlsRef.current.add(url);\n\n return url;\n }\n\n function revokePreviewUrl(item: Item): void {\n if (!item.url || !previewUrlsRef.current.has(item.url)) {\n return;\n }\n\n URL.revokeObjectURL(item.url);\n previewUrlsRef.current.delete(item.url);\n }\n\n async function signAndUpload(item: Item, file: File): Promise<void> {\n const markFailed = (): void => {\n setItems((prev) =>\n prev.map((entry) => (entry.id === item.id ? { ...entry, status: \"error\" } : entry)),\n );\n };\n\n const response = await requestSignedUpload(action, {\n ref: componentRef,\n target: uploadKey,\n filename: file.name,\n contentType: file.type,\n values,\n });\n\n if (!response.ok) {\n markFailed();\n\n return;\n }\n\n const sign = (await response.json()) as SignedUpload;\n\n try {\n const put = await xhrTransfer({\n url: sign.url,\n method: sign.method.toUpperCase(),\n body: file,\n headers: sign.headers,\n onProgress: (progress) =>\n setItems((prev) =>\n prev.map((entry) => (entry.id === item.id ? { ...entry, progress } : entry)),\n ),\n });\n\n setItems((prev) =>\n prev.map((entry) =>\n entry.id === item.id\n ? {\n ...entry,\n status: put.ok ? \"ready\" : \"error\",\n key: sign.key,\n progress: 100,\n }\n : entry,\n ),\n );\n } catch {\n markFailed();\n }\n }\n\n function addFiles(fileList: FileList | null): void {\n if (!fileList || locked) {\n return;\n }\n\n const incoming = Array.from(fileList);\n const next = incoming.map<Item>((file) => ({\n id: crypto.randomUUID(),\n name: file.name,\n size: file.size,\n status: signed ? \"uploading\" : \"ready\",\n progress: 0,\n file,\n url: createPreviewUrl(file),\n existing: false,\n }));\n\n if (!multiple) {\n items.forEach(revokePreviewUrl);\n\n if (!scope) {\n const replacedTokens = items\n .filter((item) => item.existing && item.token)\n .map((item) => item.token as string);\n\n if (replacedTokens.length > 0) {\n setRemovedTokens((tokens) => [...tokens, ...replacedTokens]);\n }\n }\n }\n\n setItems((prev) => (multiple ? [...prev, ...next] : next));\n\n if (signed) {\n next.forEach((item, index) => void signAndUpload(item, incoming[index]));\n }\n }\n\n function removeItem(id: string): void {\n const target = items.find((item) => item.id === id);\n\n if (target) {\n revokePreviewUrl(target);\n }\n\n if (target?.existing && target.token && !scope) {\n setRemovedTokens((tokens) => [...tokens, target.token as string]);\n }\n\n setItems((prev) => prev.filter((i) => i.id !== id));\n }\n\n if (hidden) {\n return null;\n }\n\n return (\n <FormFieldFrame\n error={errors[errorKey]}\n helperText={props.helperText ?? undefined}\n tooltip={props.tooltip ?? undefined}\n label={props.label ?? \"\"}\n name={name}\n required={required}\n >\n <div\n className=\"flex flex-col gap-3 rounded-lt-sm border border-dashed border-lt-border bg-lt-surface px-4 py-6\"\n data-test={testIdentity(name)}\n onDragOver={(event) => event.preventDefault()}\n onDrop={(event) => {\n event.preventDefault();\n addFiles(event.dataTransfer.files);\n }}\n >\n <button\n className=\"text-sm text-lt-muted-fg\"\n disabled={locked}\n onClick={() => fileInputRef.current?.click()}\n type=\"button\"\n >\n {t(\"form.file-upload.dropzone\", \"Drop files here or click to browse\")}\n </button>\n\n <ul\n className={props.image ? \"grid grid-cols-1 gap-3 sm:grid-cols-2\" : \"flex flex-col gap-2\"}\n >\n {items.map((item) => (\n <li\n className={\n props.image\n ? \"flex min-w-0 items-center gap-3 rounded-lt-sm border border-lt-border bg-lt-bg p-2 text-sm\"\n : \"flex items-center justify-between gap-3 text-sm\"\n }\n key={item.id}\n >\n {props.image && item.url ? (\n <img\n alt={item.name}\n className=\"size-16 shrink-0 rounded-lt-sm border border-lt-border object-cover\"\n data-test={testIdentity(`${name}-preview`)}\n src={item.url}\n />\n ) : null}\n <div className=\"min-w-0 flex-1\">\n <span className=\"block truncate\" data-test={testIdentity(`${name}-item`)}>\n {item.name}\n </span>\n {item.status === \"uploading\" && (\n <span className=\"text-xs text-lt-muted-fg\">{item.progress}%</span>\n )}\n {item.status === \"error\" && (\n <span className=\"text-xs text-lt-danger\">\n {t(\"form.file-upload.failed\", \"Failed\")}\n </span>\n )}\n </div>\n {(!item.existing || !scope) && (\n <IconButton\n size=\"sm\"\n icon=\"x\"\n label={t(\"form.file-upload.remove\", \"Remove {{name}}\", { name: item.name })}\n data-test={testIdentity(\n item.existing ? `${name}-remove-existing` : `${name}-remove`,\n )}\n disabled={locked}\n onClick={() => removeItem(item.id)}\n />\n )}\n {signed && !item.existing && item.key && item.status === \"ready\" && (\n <input\n data-test={testIdentity(`${name}-uploaded`)}\n name={fieldName}\n type=\"hidden\"\n value={item.key}\n />\n )}\n </li>\n ))}\n </ul>\n\n {!scope &&\n removedTokens.map((token) => (\n <input key={token} name={`${name}__removed[]`} type=\"hidden\" value={token} />\n ))}\n\n <input\n accept={props.accept ?? undefined}\n aria-label={props.label ?? name}\n className=\"sr-only\"\n data-test={testIdentity(`${name}-input`)}\n id={inputId}\n multiple={multiple}\n name={signed ? undefined : fieldName}\n onChange={(event) => {\n addFiles(event.target.files);\n if (signed) {\n event.target.value = \"\";\n }\n }}\n ref={fileInputRef}\n type=\"file\"\n />\n </div>\n </FormFieldFrame>\n );\n};\n"],"mappings":";;;;;;;;;;;;AA0BA,SAAS,kBAAkB,SAAkB,MAAkC;CAC7E,IAAI,MAAM,QAAQ,IAAI,GACpB,OACE,MAAM,QAAQ,OAAO,KACrB,QAAQ,WAAW,KAAK,UACxB,QAAQ,OAAO,OAAO,UAAU,UAAU,KAAK,MAAM;CAIzD,OAAO,YAAY;AACrB;AAEA,IAAa,uBAA+D,EAAE,WAAW;CACvF,MAAM,EAAE,MAAM,KAAK,SAAS;CAC5B,MAAM,QAAQ,KAAK;CACnB,MAAM,EAAE,QAAQ,UAAU,UAAU,aAAa,kBAAkB,IAAI;CACvE,MAAM,EAAE,QAAQ,cAAc,WAAW,eAAe;CACxD,MAAM,OAAO,MAAM;CACnB,MAAM,QAAQ,cAAc;CAC5B,MAAM,UAAU,QAAQ,MAAM,WAAW,IAAI,IAAI;CACjD,MAAM,WAAW,QAAQ,MAAM,SAAS,IAAI,IAAI;CAChD,MAAM,YAAY;CAClB,MAAM,SAAS,cAAc;CAC7B,MAAM,WAAW,gBAAgB;CACjC,MAAM,UAAU,MAAM;CACtB,MAAM,eAAe,OAAyB,IAAI;CAClD,MAAM,iBAAiB,uBAAoB,IAAI,IAAI,CAAC;CACpD,MAAM,SAAS,YAAY;CAC3B,MAAM,SAAS,MAAM;CACrB,MAAM,WAAW,MAAM;CACvB,MAAM,YAAY,WAAW,GAAG,QAAQ,MAAM;CAE9C,MAAM,UAAU,eAEX,MAAM,SAAS,CAAC,EAAA,CAAG,KAAK,UAAU;EACjC,I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,oBAAC,SAAD;KAAmB,MAAM,GAAG,KAAK;KAAc,MAAK;KAAS,OAAO;IAAQ,GAAhE,KAAgE,CAC7E;IAEH,oBAAC,SAAD;KACE,QAAQ,MAAM,UAAU,KAAA;KACxB,cAAY,MAAM,SAAS;KAC3B,WAAU;KACV,aAAW,aAAa,GAAG,KAAK,OAAO;KACvC,IAAI;KACM;KACV,MAAM,SAAS,KAAA,IAAY;KAC3B,WAAW,UAAU;MACnB,SAAS,MAAM,OAAO,KAAK;MAC3B,IAAI,QACF,MAAM,OAAO,QAAQ;KAEzB;KACA,KAAK;KACL,MAAK;IACN,CAAA;GACE;;CACS,CAAA;AAEpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number-input.js","names":[],"sources":["../../../../resources/js/form/components/fields/number-input.tsx"],"sourcesContent":["import type { RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport { AffixGroup } from \"@lattice-php/lattice/ui/affix-group\";\nimport { Input } from \"@lattice-php/lattice/ui/input\";\nimport { SimpleField } from \"./simple-field\";\n\nexport const NumberInputComponent: RendererComponent<\"field.number-input\"> = ({ node }) => {\n const props = node.props;\n\n return (\n <SimpleField node={node} label={props.label ?? \"\"}>\n {({ name, testId, value, readOnly, disabled, commit }) => {\n const onChange = (event: React.ChangeEvent<HTMLInputElement>): void =>\n commit(event.target.value);\n\n return props.slider ? (\n <div className=\"flex items-center gap-3\">\n <input\n aria-label={props.label ?? \"\"}\n className=\"h-2 w-full cursor-pointer appearance-none rounded-lt-sm bg-lt-muted accent-lt-primary disabled:cursor-not-allowed disabled:accent-lt-disabled\"\n data-test={testId}\n disabled={disabled || readOnly}\n id={name}\n max={props.max ?? undefined}\n min={props.min ?? undefined}\n name={name}\n onChange={onChange}\n step={props.step ?? undefined}\n tabIndex={props.tabIndex ?? undefined}\n type=\"range\"\n value={value}\n />\n <output className=\"w-10 shrink-0 text-right text-sm tabular-nums text-lt-fg\">\n {value}\n </output>\n </div>\n ) : (\n <AffixGroup prefix={props.prefix} suffix={props.suffix}>\n {(controlClassName) => (\n <Input\n autoFocus={props.autoFocus ?? false}\n className={controlClassName}\n data-test={testId}\n disabled={disabled}\n id={name}\n max={props.max ?? undefined}\n min={props.min ?? undefined}\n name={name}\n onChange={onChange}\n placeholder={props.placeholder ?? \"\"}\n readOnly={readOnly}\n step={props.step ?? undefined}\n tabIndex={props.tabIndex ?? undefined}\n type=\"number\"\n value={value}\n />\n )}\n </AffixGroup>\n );\n }}\n </SimpleField>\n );\n};\n"],"mappings":";;;;;AAKA,IAAa,wBAAiE,EAAE,WAAW;CACzF,MAAM,QAAQ,KAAK;CAEnB,OACE,oBAAC,aAAD;EAAmB;EAAM,OAAO,MAAM,SAAS;
|
|
1
|
+
{"version":3,"file":"number-input.js","names":[],"sources":["../../../../resources/js/form/components/fields/number-input.tsx"],"sourcesContent":["import type { RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport { AffixGroup } from \"@lattice-php/lattice/ui/affix-group\";\nimport { Input } from \"@lattice-php/lattice/ui/input\";\nimport { SimpleField } from \"./simple-field\";\n\nexport const NumberInputComponent: RendererComponent<\"field.number-input\"> = ({ node }) => {\n const props = node.props;\n\n return (\n <SimpleField node={node} label={props.label ?? \"\"}>\n {({ name, testId, value, readOnly, disabled, commit }) => {\n const onChange = (event: React.ChangeEvent<HTMLInputElement>): void =>\n commit(event.target.value);\n\n return props.slider ? (\n <div className=\"flex items-center gap-3\">\n <input\n aria-label={props.label ?? \"\"}\n className=\"h-2 w-full cursor-pointer appearance-none rounded-lt-sm bg-lt-muted accent-lt-primary disabled:cursor-not-allowed disabled:accent-lt-disabled\"\n data-test={testId}\n disabled={disabled || readOnly}\n id={name}\n max={props.max ?? undefined}\n min={props.min ?? undefined}\n name={name}\n onChange={onChange}\n step={props.step ?? undefined}\n tabIndex={props.tabIndex ?? undefined}\n type=\"range\"\n value={value}\n />\n <output className=\"w-10 shrink-0 text-right text-sm tabular-nums text-lt-fg\">\n {value}\n </output>\n </div>\n ) : (\n <AffixGroup prefix={props.prefix} suffix={props.suffix}>\n {(controlClassName) => (\n <Input\n autoFocus={props.autoFocus ?? false}\n className={controlClassName}\n data-test={testId}\n disabled={disabled}\n id={name}\n max={props.max ?? undefined}\n min={props.min ?? undefined}\n name={name}\n onChange={onChange}\n placeholder={props.placeholder ?? \"\"}\n readOnly={readOnly}\n step={props.step ?? undefined}\n tabIndex={props.tabIndex ?? undefined}\n type=\"number\"\n value={value}\n />\n )}\n </AffixGroup>\n );\n }}\n </SimpleField>\n );\n};\n"],"mappings":";;;;;AAKA,IAAa,wBAAiE,EAAE,WAAW;CACzF,MAAM,QAAQ,KAAK;CAEnB,OACE,oBAAC,aAAD;EAAmB;EAAM,OAAO,MAAM,SAAS;EAC3C,WAAA,EAAE,MAAM,QAAQ,OAAO,UAAU,UAAU,aAAa;GACxD,MAAM,YAAY,UAChB,OAAO,MAAM,OAAO,KAAK;GAE3B,OAAO,MAAM,SACX,qBAAC,OAAD;IAAK,WAAU;IAAf,UAAA,CACE,oBAAC,SAAD;KACE,cAAY,MAAM,SAAS;KAC3B,WAAU;KACV,aAAW;KACX,UAAU,YAAY;KACtB,IAAI;KACJ,KAAK,MAAM,OAAO,KAAA;KAClB,KAAK,MAAM,OAAO,KAAA;KACZ;KACI;KACV,MAAM,MAAM,QAAQ,KAAA;KACpB,UAAU,MAAM,YAAY,KAAA;KAC5B,MAAK;KACE;IACR,CAAA,GACD,oBAAC,UAAD;KAAQ,WAAU;KACf,UAAA;IACK,CAAA,CACL;GAEL,CAAA,IAAA,oBAAC,YAAD;IAAY,QAAQ,MAAM;IAAQ,QAAQ,MAAM;IAC5C,WAAA,qBACA,oBAAC,OAAD;KACE,WAAW,MAAM,aAAa;KAC9B,WAAW;KACX,aAAW;KACD;KACV,IAAI;KACJ,KAAK,MAAM,OAAO,KAAA;KAClB,KAAK,MAAM,OAAO,KAAA;KACZ;KACI;KACV,aAAa,MAAM,eAAe;KACxB;KACV,MAAM,MAAM,QAAQ,KAAA;KACpB,UAAU,MAAM,YAAY,KAAA;KAC5B,MAAK;KACE;IACR,CAAA;GAEO,CAAA;EAEhB;CACW,CAAA;AAEjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otp-input.js","names":[],"sources":["../../../../resources/js/form/components/fields/otp-input.tsx"],"sourcesContent":["import type { RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport { InputOTP } from \"@lattice-php/lattice/ui/input-otp\";\nimport { SimpleField } from \"./simple-field\";\n\nexport const OtpInputComponent: RendererComponent<\"field.otp\"> = ({ node }) => {\n const props = node.props;\n\n return (\n <SimpleField node={node} label={props.label ?? \"\"}>\n {({ name, testId, value, readOnly, disabled, commit }) => (\n <InputOTP\n autoFocus={props.autoFocus ?? false}\n data-test={testId}\n disabled={disabled || readOnly}\n id={name}\n length={props.length}\n name={name}\n onChange={(next) => commit(next)}\n value={value}\n />\n )}\n </SimpleField>\n );\n};\n"],"mappings":";;;;AAIA,IAAa,qBAAqD,EAAE,WAAW;CAC7E,MAAM,QAAQ,KAAK;CAEnB,OACE,oBAAC,aAAD;EAAmB;EAAM,OAAO,MAAM,SAAS;
|
|
1
|
+
{"version":3,"file":"otp-input.js","names":[],"sources":["../../../../resources/js/form/components/fields/otp-input.tsx"],"sourcesContent":["import type { RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport { InputOTP } from \"@lattice-php/lattice/ui/input-otp\";\nimport { SimpleField } from \"./simple-field\";\n\nexport const OtpInputComponent: RendererComponent<\"field.otp\"> = ({ node }) => {\n const props = node.props;\n\n return (\n <SimpleField node={node} label={props.label ?? \"\"}>\n {({ name, testId, value, readOnly, disabled, commit }) => (\n <InputOTP\n autoFocus={props.autoFocus ?? false}\n data-test={testId}\n disabled={disabled || readOnly}\n id={name}\n length={props.length}\n name={name}\n onChange={(next) => commit(next)}\n value={value}\n />\n )}\n </SimpleField>\n );\n};\n"],"mappings":";;;;AAIA,IAAa,qBAAqD,EAAE,WAAW;CAC7E,MAAM,QAAQ,KAAK;CAEnB,OACE,oBAAC,aAAD;EAAmB;EAAM,OAAO,MAAM,SAAS;EAC3C,WAAA,EAAE,MAAM,QAAQ,OAAO,UAAU,UAAU,aAC3C,oBAAC,UAAD;GACE,WAAW,MAAM,aAAa;GAC9B,aAAW;GACX,UAAU,YAAY;GACtB,IAAI;GACJ,QAAQ,MAAM;GACR;GACN,WAAW,SAAS,OAAO,IAAI;GACxB;EACR,CAAA;CAEQ,CAAA;AAEjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"password-input.js","names":[],"sources":["../../../../resources/js/form/components/fields/password-input.tsx"],"sourcesContent":["import type { RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport { testIdentity } from \"@lattice-php/lattice/core/test-id\";\nimport { AffixGroup } from \"@lattice-php/lattice/ui/affix-group\";\nimport { FormFieldFrame } from \"@lattice-php/lattice/form/components/base/field\";\nimport PasswordInput from \"@lattice-php/lattice/ui/password-input\";\nimport { useFieldScope } from \"@lattice-php/lattice/form/hooks/field-scope\";\nimport { useControlledField } from \"@lattice-php/lattice/form/hooks/use-controlled-field\";\nimport { useFieldCommit } from \"@lattice-php/lattice/form/hooks/use-field-commit\";\nimport { useFormContext } from \"@lattice-php/lattice/form/hooks/context\";\n\nexport const PasswordInputComponent: RendererComponent<\"field.password-input\"> = ({ node }) => {\n const props = node.props;\n const { errors } = useFormContext();\n const field = useControlledField(node);\n const { commit } = useFieldCommit();\n const scope = useFieldScope();\n const confirmation = props.confirmation;\n const confirmationLocalName = confirmation?.name ?? `${field.localName}_confirmation`;\n const confirmationName = scope ? scope.scopedName(confirmationLocalName) : confirmationLocalName;\n const confirmationErrorKey = scope\n ? scope.errorKey(confirmationLocalName)\n : confirmationLocalName;\n const passwordRules = (props.passwordRules ?? \"\") || undefined;\n\n if (field.hidden) {\n return null;\n }\n\n return (\n <div className=\"grid gap-6\">\n <FormFieldFrame\n error={field.error}\n helperText={props.helperText ?? undefined}\n tooltip={props.tooltip ?? undefined}\n label={props.label ?? \"\"}\n labelAction={props.labelAction ?? undefined}\n name={field.name}\n required={field.required}\n >\n <AffixGroup prefix={props.prefix} suffix={props.suffix}>\n {(controlClassName) => (\n <PasswordInput\n autoComplete={props.autoComplete ?? \"\"}\n autoFocus={props.autoFocus ?? false}\n className={controlClassName}\n data-test={field.testId}\n disabled={field.disabled}\n id={field.name}\n name={field.name}\n onChange={(event) => {\n field.commit(event.target.value);\n }}\n placeholder={props.placeholder ?? \"\"}\n passwordrules={passwordRules}\n readOnly={field.readOnly}\n tabIndex={props.tabIndex ?? undefined}\n value={field.value}\n />\n )}\n </AffixGroup>\n </FormFieldFrame>\n\n {confirmation && (\n <FormFieldFrame\n error={errors[confirmationErrorKey]}\n label={confirmation.label ?? \"Confirm password\"}\n name={confirmationName}\n required={field.required}\n >\n <PasswordInput\n autoComplete=\"new-password\"\n data-test={testIdentity(confirmationLocalName)}\n disabled={field.disabled}\n id={confirmationName}\n name={confirmationName}\n onChange={(event) => {\n commit(confirmationLocalName, event.target.value);\n }}\n placeholder={confirmation.placeholder ?? confirmation.label ?? \"Confirm password\"}\n passwordrules={passwordRules}\n readOnly={field.readOnly}\n tabIndex={props.tabIndex ?? undefined}\n />\n </FormFieldFrame>\n )}\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;AAUA,IAAa,0BAAqE,EAAE,WAAW;CAC7F,MAAM,QAAQ,KAAK;CACnB,MAAM,EAAE,WAAW,eAAe;CAClC,MAAM,QAAQ,mBAAmB,IAAI;CACrC,MAAM,EAAE,WAAW,eAAe;CAClC,MAAM,QAAQ,cAAc;CAC5B,MAAM,eAAe,MAAM;CAC3B,MAAM,wBAAwB,cAAc,QAAQ,GAAG,MAAM,UAAU;CACvE,MAAM,mBAAmB,QAAQ,MAAM,WAAW,qBAAqB,IAAI;CAC3E,MAAM,uBAAuB,QACzB,MAAM,SAAS,qBAAqB,IACpC;CACJ,MAAM,iBAAiB,MAAM,iBAAiB,OAAO,KAAA;CAErD,IAAI,MAAM,QACR,OAAO;CAGT,OACE,qBAAC,OAAD;EAAK,WAAU;
|
|
1
|
+
{"version":3,"file":"password-input.js","names":[],"sources":["../../../../resources/js/form/components/fields/password-input.tsx"],"sourcesContent":["import type { RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport { testIdentity } from \"@lattice-php/lattice/core/test-id\";\nimport { AffixGroup } from \"@lattice-php/lattice/ui/affix-group\";\nimport { FormFieldFrame } from \"@lattice-php/lattice/form/components/base/field\";\nimport PasswordInput from \"@lattice-php/lattice/ui/password-input\";\nimport { useFieldScope } from \"@lattice-php/lattice/form/hooks/field-scope\";\nimport { useControlledField } from \"@lattice-php/lattice/form/hooks/use-controlled-field\";\nimport { useFieldCommit } from \"@lattice-php/lattice/form/hooks/use-field-commit\";\nimport { useFormContext } from \"@lattice-php/lattice/form/hooks/context\";\n\nexport const PasswordInputComponent: RendererComponent<\"field.password-input\"> = ({ node }) => {\n const props = node.props;\n const { errors } = useFormContext();\n const field = useControlledField(node);\n const { commit } = useFieldCommit();\n const scope = useFieldScope();\n const confirmation = props.confirmation;\n const confirmationLocalName = confirmation?.name ?? `${field.localName}_confirmation`;\n const confirmationName = scope ? scope.scopedName(confirmationLocalName) : confirmationLocalName;\n const confirmationErrorKey = scope\n ? scope.errorKey(confirmationLocalName)\n : confirmationLocalName;\n const passwordRules = (props.passwordRules ?? \"\") || undefined;\n\n if (field.hidden) {\n return null;\n }\n\n return (\n <div className=\"grid gap-6\">\n <FormFieldFrame\n error={field.error}\n helperText={props.helperText ?? undefined}\n tooltip={props.tooltip ?? undefined}\n label={props.label ?? \"\"}\n labelAction={props.labelAction ?? undefined}\n name={field.name}\n required={field.required}\n >\n <AffixGroup prefix={props.prefix} suffix={props.suffix}>\n {(controlClassName) => (\n <PasswordInput\n autoComplete={props.autoComplete ?? \"\"}\n autoFocus={props.autoFocus ?? false}\n className={controlClassName}\n data-test={field.testId}\n disabled={field.disabled}\n id={field.name}\n name={field.name}\n onChange={(event) => {\n field.commit(event.target.value);\n }}\n placeholder={props.placeholder ?? \"\"}\n passwordrules={passwordRules}\n readOnly={field.readOnly}\n tabIndex={props.tabIndex ?? undefined}\n value={field.value}\n />\n )}\n </AffixGroup>\n </FormFieldFrame>\n\n {confirmation && (\n <FormFieldFrame\n error={errors[confirmationErrorKey]}\n label={confirmation.label ?? \"Confirm password\"}\n name={confirmationName}\n required={field.required}\n >\n <PasswordInput\n autoComplete=\"new-password\"\n data-test={testIdentity(confirmationLocalName)}\n disabled={field.disabled}\n id={confirmationName}\n name={confirmationName}\n onChange={(event) => {\n commit(confirmationLocalName, event.target.value);\n }}\n placeholder={confirmation.placeholder ?? confirmation.label ?? \"Confirm password\"}\n passwordrules={passwordRules}\n readOnly={field.readOnly}\n tabIndex={props.tabIndex ?? undefined}\n />\n </FormFieldFrame>\n )}\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;AAUA,IAAa,0BAAqE,EAAE,WAAW;CAC7F,MAAM,QAAQ,KAAK;CACnB,MAAM,EAAE,WAAW,eAAe;CAClC,MAAM,QAAQ,mBAAmB,IAAI;CACrC,MAAM,EAAE,WAAW,eAAe;CAClC,MAAM,QAAQ,cAAc;CAC5B,MAAM,eAAe,MAAM;CAC3B,MAAM,wBAAwB,cAAc,QAAQ,GAAG,MAAM,UAAU;CACvE,MAAM,mBAAmB,QAAQ,MAAM,WAAW,qBAAqB,IAAI;CAC3E,MAAM,uBAAuB,QACzB,MAAM,SAAS,qBAAqB,IACpC;CACJ,MAAM,iBAAiB,MAAM,iBAAiB,OAAO,KAAA;CAErD,IAAI,MAAM,QACR,OAAO;CAGT,OACE,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACE,oBAAC,gBAAD;GACE,OAAO,MAAM;GACb,YAAY,MAAM,cAAc,KAAA;GAChC,SAAS,MAAM,WAAW,KAAA;GAC1B,OAAO,MAAM,SAAS;GACtB,aAAa,MAAM,eAAe,KAAA;GAClC,MAAM,MAAM;GACZ,UAAU,MAAM;GAEhB,UAAA,oBAAC,YAAD;IAAY,QAAQ,MAAM;IAAQ,QAAQ,MAAM;IAC5C,WAAA,qBACA,oBAAC,eAAD;KACE,cAAc,MAAM,gBAAgB;KACpC,WAAW,MAAM,aAAa;KAC9B,WAAW;KACX,aAAW,MAAM;KACjB,UAAU,MAAM;KAChB,IAAI,MAAM;KACV,MAAM,MAAM;KACZ,WAAW,UAAU;MACnB,MAAM,OAAO,MAAM,OAAO,KAAK;KACjC;KACA,aAAa,MAAM,eAAe;KAClC,eAAe;KACf,UAAU,MAAM;KAChB,UAAU,MAAM,YAAY,KAAA;KAC5B,OAAO,MAAM;IACd,CAAA;GAEO,CAAA;EACE,CAAA,GAEf,gBACC,oBAAC,gBAAD;GACE,OAAO,OAAO;GACd,OAAO,aAAa,SAAS;GAC7B,MAAM;GACN,UAAU,MAAM;GAEhB,UAAA,oBAAC,eAAD;IACE,cAAa;IACb,aAAW,aAAa,qBAAqB;IAC7C,UAAU,MAAM;IAChB,IAAI;IACJ,MAAM;IACN,WAAW,UAAU;KACnB,OAAO,uBAAuB,MAAM,OAAO,KAAK;IAClD;IACA,aAAa,aAAa,eAAe,aAAa,SAAS;IAC/D,eAAe;IACf,UAAU,MAAM;IAChB,UAAU,MAAM,YAAY,KAAA;GAC7B,CAAA;EACa,CAAA,CAEf;;AAET"}
|
|
@@ -18,7 +18,8 @@ var RepeaterComponent = ({ node }) => {
|
|
|
18
18
|
const { hidden, required } = useDependentField(node);
|
|
19
19
|
const { path, rows, onField, onRemove, onMove, onDuplicate, append } = useRowCollection(name, props.defaultItems ?? 1);
|
|
20
20
|
const template = node.schema ?? EMPTY_TEMPLATE;
|
|
21
|
-
const
|
|
21
|
+
const orderSignature = rows.map((r) => String(r["rowId"] ?? "")).join(",");
|
|
22
|
+
const registerRow = useFlipReorder(orderSignature);
|
|
22
23
|
const atMax = props.maxItems != null && rows.length >= props.maxItems;
|
|
23
24
|
const atMin = props.minItems != null && rows.length <= props.minItems;
|
|
24
25
|
const isTable = props.layout === "table";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repeater.js","names":[],"sources":["../../../../resources/js/form/components/fields/repeater.tsx"],"sourcesContent":["import { Icon } from \"@lattice-php/lattice/icons\";\nimport type { Node, RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport { FormFieldFrame } from \"@lattice-php/lattice/form/components/base/field\";\nimport { useFormContext } from \"@lattice-php/lattice/form/hooks/context\";\nimport { useDependentField } from \"@lattice-php/lattice/form/hooks/use-dependent-field\";\nimport { ROW_ID_KEY } from \"./repeater-rows\";\nimport { RowKeyInputs } from \"./row-key-inputs\";\nimport { RowItem } from \"./row-item\";\nimport { columnsFromSchema, TableRows } from \"./table-rows\";\nimport { useFlipReorder } from \"./use-flip-reorder\";\nimport { useRowCollection } from \"./use-row-collection\";\n\nconst EMPTY_TEMPLATE: Node[] = [];\n\nexport const RepeaterComponent: RendererComponent<\"field.repeater\"> = ({ node }) => {\n const props = node.props;\n const name = props.name;\n const { errors } = useFormContext();\n const { hidden, required } = useDependentField(node);\n const { path, rows, onField, onRemove, onMove, onDuplicate, append } = useRowCollection(\n name,\n props.defaultItems ?? 1,\n );\n const template = node.schema ?? EMPTY_TEMPLATE;\n const orderSignature = rows.map((r) => String(r[ROW_ID_KEY] ?? \"\")).join(\",\");\n const registerRow = useFlipReorder(orderSignature);\n const atMax = props.maxItems != null && rows.length >= props.maxItems;\n const atMin = props.minItems != null && rows.length <= props.minItems;\n const isTable = props.layout === \"table\";\n const itemLabels = (props as { itemLabels?: Array<string | null> | null }).itemLabels;\n const rowHeading = (index: number) => {\n const label = itemLabels?.[index];\n\n if (typeof label === \"string\" && label !== \"\") {\n return label;\n }\n\n return props.itemLabel ? `${props.itemLabel} ${index + 1}` : `#${index + 1}`;\n };\n\n if (hidden) {\n return null;\n }\n\n const tableRows = rows.map((row, index) => ({\n key: String(row[ROW_ID_KEY] ?? index),\n index,\n row,\n template,\n span: false,\n heading: rowHeading(index),\n }));\n\n return (\n <FormFieldFrame\n error={errors[path]}\n helperText={props.helperText ?? undefined}\n tooltip={props.tooltip ?? undefined}\n label={props.label ?? \"\"}\n name={path}\n required={required}\n >\n <div className=\"flex flex-col gap-3\">\n <RowKeyInputs path={path} rows={rows} rowKey={ROW_ID_KEY} />\n {isTable ? (\n <TableRows\n base={path}\n columns={columnsFromSchema(template)}\n rows={tableRows}\n reorderable={props.reorderable ?? false}\n removable={() => !atMin}\n rowActions={props.rowActions}\n onField={onField}\n onMove={onMove}\n onRemove={onRemove}\n onDuplicate={onDuplicate}\n registerRow={registerRow}\n resizableColumns={props.resizableColumns === true}\n resizeIndicator={props.resizeIndicator === true}\n />\n ) : (\n rows.map((row, index) => {\n const key = String(row[ROW_ID_KEY] ?? index);\n return (\n <div key={key} ref={(el) => registerRow(key, el)} data-flip-key={key}>\n <RowItem\n base={path}\n index={index}\n row={row}\n template={template}\n heading={rowHeading(index)}\n reorderable={props.reorderable ?? false}\n isFirst={index === 0}\n isLast={index === rows.length - 1}\n removable={!atMin}\n rowActions={props.rowActions}\n onField={onField}\n onRemove={onRemove}\n onMove={onMove}\n onDuplicate={onDuplicate}\n />\n </div>\n );\n })\n )}\n\n {!atMax && (\n <button\n type=\"button\"\n data-test={`repeater-${name}-add`}\n className=\"inline-flex items-center gap-1.5 self-start rounded-lt-sm border border-lt-border px-3 py-1.5 text-sm hover:bg-lt-accent [&_svg]:size-lt-icon-sm\"\n onClick={() => append({})}\n >\n <Icon name=\"plus\" />\n {props.addLabel ?? \"Add\"}\n </button>\n )}\n </div>\n </FormFieldFrame>\n );\n};\n"],"mappings":";;;;;;;;;;;;AAYA,IAAM,iBAAyB,CAAC;AAEhC,IAAa,qBAA0D,EAAE,WAAW;CAClF,MAAM,QAAQ,KAAK;CACnB,MAAM,OAAO,MAAM;CACnB,MAAM,EAAE,WAAW,eAAe;CAClC,MAAM,EAAE,QAAQ,aAAa,kBAAkB,IAAI;CACnD,MAAM,EAAE,MAAM,MAAM,SAAS,UAAU,QAAQ,aAAa,WAAW,iBACrE,MACA,MAAM,gBAAgB,CACxB;CACA,MAAM,WAAW,KAAK,UAAU;
|
|
1
|
+
{"version":3,"file":"repeater.js","names":[],"sources":["../../../../resources/js/form/components/fields/repeater.tsx"],"sourcesContent":["import { Icon } from \"@lattice-php/lattice/icons\";\nimport type { Node, RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport { FormFieldFrame } from \"@lattice-php/lattice/form/components/base/field\";\nimport { useFormContext } from \"@lattice-php/lattice/form/hooks/context\";\nimport { useDependentField } from \"@lattice-php/lattice/form/hooks/use-dependent-field\";\nimport { ROW_ID_KEY } from \"./repeater-rows\";\nimport { RowKeyInputs } from \"./row-key-inputs\";\nimport { RowItem } from \"./row-item\";\nimport { columnsFromSchema, TableRows } from \"./table-rows\";\nimport { useFlipReorder } from \"./use-flip-reorder\";\nimport { useRowCollection } from \"./use-row-collection\";\n\nconst EMPTY_TEMPLATE: Node[] = [];\n\nexport const RepeaterComponent: RendererComponent<\"field.repeater\"> = ({ node }) => {\n const props = node.props;\n const name = props.name;\n const { errors } = useFormContext();\n const { hidden, required } = useDependentField(node);\n const { path, rows, onField, onRemove, onMove, onDuplicate, append } = useRowCollection(\n name,\n props.defaultItems ?? 1,\n );\n const template = node.schema ?? EMPTY_TEMPLATE;\n const orderSignature = rows.map((r) => String(r[ROW_ID_KEY] ?? \"\")).join(\",\");\n const registerRow = useFlipReorder(orderSignature);\n const atMax = props.maxItems != null && rows.length >= props.maxItems;\n const atMin = props.minItems != null && rows.length <= props.minItems;\n const isTable = props.layout === \"table\";\n const itemLabels = (props as { itemLabels?: Array<string | null> | null }).itemLabels;\n const rowHeading = (index: number) => {\n const label = itemLabels?.[index];\n\n if (typeof label === \"string\" && label !== \"\") {\n return label;\n }\n\n return props.itemLabel ? `${props.itemLabel} ${index + 1}` : `#${index + 1}`;\n };\n\n if (hidden) {\n return null;\n }\n\n const tableRows = rows.map((row, index) => ({\n key: String(row[ROW_ID_KEY] ?? index),\n index,\n row,\n template,\n span: false,\n heading: rowHeading(index),\n }));\n\n return (\n <FormFieldFrame\n error={errors[path]}\n helperText={props.helperText ?? undefined}\n tooltip={props.tooltip ?? undefined}\n label={props.label ?? \"\"}\n name={path}\n required={required}\n >\n <div className=\"flex flex-col gap-3\">\n <RowKeyInputs path={path} rows={rows} rowKey={ROW_ID_KEY} />\n {isTable ? (\n <TableRows\n base={path}\n columns={columnsFromSchema(template)}\n rows={tableRows}\n reorderable={props.reorderable ?? false}\n removable={() => !atMin}\n rowActions={props.rowActions}\n onField={onField}\n onMove={onMove}\n onRemove={onRemove}\n onDuplicate={onDuplicate}\n registerRow={registerRow}\n resizableColumns={props.resizableColumns === true}\n resizeIndicator={props.resizeIndicator === true}\n />\n ) : (\n rows.map((row, index) => {\n const key = String(row[ROW_ID_KEY] ?? index);\n return (\n <div key={key} ref={(el) => registerRow(key, el)} data-flip-key={key}>\n <RowItem\n base={path}\n index={index}\n row={row}\n template={template}\n heading={rowHeading(index)}\n reorderable={props.reorderable ?? false}\n isFirst={index === 0}\n isLast={index === rows.length - 1}\n removable={!atMin}\n rowActions={props.rowActions}\n onField={onField}\n onRemove={onRemove}\n onMove={onMove}\n onDuplicate={onDuplicate}\n />\n </div>\n );\n })\n )}\n\n {!atMax && (\n <button\n type=\"button\"\n data-test={`repeater-${name}-add`}\n className=\"inline-flex items-center gap-1.5 self-start rounded-lt-sm border border-lt-border px-3 py-1.5 text-sm hover:bg-lt-accent [&_svg]:size-lt-icon-sm\"\n onClick={() => append({})}\n >\n <Icon name=\"plus\" />\n {props.addLabel ?? \"Add\"}\n </button>\n )}\n </div>\n </FormFieldFrame>\n );\n};\n"],"mappings":";;;;;;;;;;;;AAYA,IAAM,iBAAyB,CAAC;AAEhC,IAAa,qBAA0D,EAAE,WAAW;CAClF,MAAM,QAAQ,KAAK;CACnB,MAAM,OAAO,MAAM;CACnB,MAAM,EAAE,WAAW,eAAe;CAClC,MAAM,EAAE,QAAQ,aAAa,kBAAkB,IAAI;CACnD,MAAM,EAAE,MA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KAAK,KAAK,KAAK,UAAU;KACvB,MAAM,MAAM,OAAO,IAAA,YAAmB,KAAK;KAC3C,OACE,oBAAC,OAAD;MAAe,MAAM,OAAO,YAAY,KAAK,EAAE;MAAG,iBAAe;MAC/D,UAAA,oBAAC,SAAD;OACE,MAAM;OACC;OACF;OACK;OACV,SAAS,WAAW,KAAK;OACzB,aAAa,MAAM,eAAe;OAClC,SAAS,UAAU;OACnB,QAAQ,UAAU,KAAK,SAAS;OAChC,WAAW,CAAC;OACZ,YAAY,MAAM;OACT;OACC;OACF;OACK;MACd,CAAA;KACE,GAjBK,GAiBL;IAET,CAAC;IAGF,CAAC,SACA,qBAAC,UAAD;KACE,MAAK;KACL,aAAW,YAAY,KAAK;KAC5B,WAAU;KACV,eAAe,OAAO,CAAC,CAAC;KAJ1B,UAAA,CAME,oBAAC,MAAD,EAAM,MAAK,OAAQ,CAAA,GAClB,MAAM,YAAY,KACb;;GAEP;;CACS,CAAA;AAEpB"}
|
|
@@ -52,12 +52,13 @@ var RichEditorField = ({ node }) => {
|
|
|
52
52
|
const initialContent = typeof storedValue === "object" && storedValue !== null ? storedValue : node.props.value ?? "";
|
|
53
53
|
const resolved = useMemo(() => resolveRichEditorExtensions(node.props.extensions), [node.props.extensions]);
|
|
54
54
|
const toolbar = useMemo(() => assembleToolbar(resolved), [resolved]);
|
|
55
|
+
const extensions = useMemo(() => [
|
|
56
|
+
StarterKit.configure(assembleStarterKitOptions(resolved)),
|
|
57
|
+
Placeholder.configure({ placeholder: node.props.placeholder ?? "" }),
|
|
58
|
+
...assembleTiptapExtensions(resolved)
|
|
59
|
+
], [resolved, node.props.placeholder]);
|
|
55
60
|
const editor = useEditor({
|
|
56
|
-
extensions
|
|
57
|
-
StarterKit.configure(assembleStarterKitOptions(resolved)),
|
|
58
|
-
Placeholder.configure({ placeholder: node.props.placeholder ?? "" }),
|
|
59
|
-
...assembleTiptapExtensions(resolved)
|
|
60
|
-
], [resolved, node.props.placeholder]),
|
|
61
|
+
extensions,
|
|
61
62
|
content: initialContent,
|
|
62
63
|
editable: !locked,
|
|
63
64
|
immediatelyRender: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rich-editor-field.js","names":[],"sources":["../../../../resources/js/form/components/fields/rich-editor-field.tsx"],"sourcesContent":["import { Placeholder } from \"@tiptap/extensions\";\nimport { type Editor, EditorContent, useEditor } from \"@tiptap/react\";\nimport { StarterKit } from \"@tiptap/starter-kit\";\nimport { useEffect, useMemo } from \"react\";\nimport { cn } from \"@lattice-php/lattice/lib/utils\";\nimport { useT } from \"@lattice-php/lattice/i18n\";\nimport type { RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport { FormFieldFrame } from \"@lattice-php/lattice/form/components/base/field\";\nimport { useFormContext } from \"@lattice-php/lattice/form/hooks/context\";\nimport { useFieldScope } from \"@lattice-php/lattice/form/hooks/field-scope\";\nimport { useDependentField } from \"@lattice-php/lattice/form/hooks/use-dependent-field\";\nimport { useFieldCommit } from \"@lattice-php/lattice/form/hooks/use-field-commit\";\nimport { useFormValue } from \"@lattice-php/lattice/form/hooks/values\";\nimport { registerBuiltinRichEditorExtensions } from \"@lattice-php/lattice/form/rich-editor/builtins\";\nimport {\n assembleStarterKitOptions,\n assembleTiptapExtensions,\n assembleToolbar,\n resolveRichEditorExtensions,\n type ToolbarEntry,\n} from \"@lattice-php/lattice/form/rich-editor/registry\";\nimport { ToolbarIconButton } from \"@lattice-php/lattice/form/rich-editor/toolbar-button\";\n\nregisterBuiltinRichEditorExtensions();\n\nfunction Toolbar({ editor, items }: { editor: Editor; items: ToolbarEntry[] }) {\n const { t } = useT(\"lattice\");\n\n return (\n <div className=\"flex flex-wrap items-center gap-0.5 border-b border-lt-border p-1\">\n {items.map((item, index) => {\n if (item === \"separator\") {\n // eslint-disable-next-line react/no-array-index-key\n return <span key={`sep-${index}`} className=\"mx-1 h-5 w-px bg-lt-border\" />;\n }\n\n if (\"component\" in item) {\n const Control = item.component;\n\n return <Control editor={editor} key={item.key} />;\n }\n\n const label = t(`form.editor.${item.key}`, item.label);\n\n return (\n <ToolbarIconButton\n active={item.isActive(editor)}\n disabled={item.isDisabled?.(editor) ?? false}\n icon={item.icon}\n key={item.key}\n label={label}\n onClick={() => item.run(editor)}\n testId={`editor-${item.key}`}\n />\n );\n })}\n </div>\n );\n}\n\nconst RichEditorField: RendererComponent<\"field.rich-editor\"> = ({ node }) => {\n const { errors } = useFormContext();\n const { hidden, required, readOnly, disabled } = useDependentField(node);\n const { change, blur } = useFieldCommit();\n const name = node.props.name;\n const scope = useFieldScope();\n const globalValue = useFormValue(name);\n const storedValue = scope ? scope.getValue(name) : globalValue;\n const domName = scope ? scope.scopedName(name) : name;\n const errorKey = scope ? scope.errorKey(name) : name;\n const locked = readOnly || disabled;\n const initialContent =\n typeof storedValue === \"object\" && storedValue !== null\n ? (storedValue as object)\n : ((node.props.value as object | undefined) ?? \"\");\n\n const resolved = useMemo(\n () => resolveRichEditorExtensions(node.props.extensions),\n [node.props.extensions],\n );\n const toolbar = useMemo(() => assembleToolbar(resolved), [resolved]);\n const extensions = useMemo(\n () => [\n StarterKit.configure(assembleStarterKitOptions(resolved)),\n Placeholder.configure({ placeholder: node.props.placeholder ?? \"\" }),\n ...assembleTiptapExtensions(resolved),\n ],\n [resolved, node.props.placeholder],\n );\n\n const editor = useEditor({\n extensions,\n content: initialContent,\n editable: !locked,\n immediatelyRender: false,\n // Tiptap v3 stops re-rendering per transaction by default, but the toolbar\n // reads isActive/isDisabled during render — without this, selection-only\n // transactions leave those states stale.\n shouldRerenderOnTransaction: true,\n editorProps: {\n attributes: {\n class: \"lattice-prose min-h-32 px-3 py-2 outline-none\",\n },\n },\n onUpdate: ({ editor: instance }) => {\n change(name, instance.isEmpty ? null : instance.getJSON());\n },\n onBlur: () => {\n blur(name);\n },\n });\n\n useEffect(() => {\n editor?.setEditable(!locked);\n }, [editor, locked]);\n\n if (hidden) {\n return null;\n }\n\n const submittedValue = storedValue ? JSON.stringify(storedValue) : \"\";\n\n return (\n <FormFieldFrame\n error={errors[errorKey]}\n helperText={node.props.helperText ?? undefined}\n tooltip={node.props.tooltip ?? undefined}\n label={node.props.label ?? \"\"}\n name={domName}\n required={required}\n >\n <div\n className={cn(\n \"overflow-hidden rounded-lt-sm border border-lt-input bg-transparent shadow-lt-xs focus-within:border-lt-ring focus-within:ring-[length:var(--lt-ring-width)] focus-within:ring-lt-ring/50\",\n locked && \"opacity-60\",\n )}\n >\n {editor && !locked && toolbar.length > 0 && <Toolbar editor={editor} items={toolbar} />}\n <EditorContent editor={editor} />\n </div>\n <input name={domName} type=\"hidden\" value={submittedValue} />\n </FormFieldFrame>\n );\n};\n\nexport default RichEditorField;\n"],"mappings":";;;;;;;;;;;;;;;;;AAuBA,oCAAoC;AAEpC,SAAS,QAAQ,EAAE,QAAQ,SAAoD;CAC7E,MAAM,EAAE,MAAM,KAAK,SAAS;CAE5B,OACE,oBAAC,OAAD;EAAK,WAAU;
|
|
1
|
+
{"version":3,"file":"rich-editor-field.js","names":[],"sources":["../../../../resources/js/form/components/fields/rich-editor-field.tsx"],"sourcesContent":["import { Placeholder } from \"@tiptap/extensions\";\nimport { type Editor, EditorContent, useEditor } from \"@tiptap/react\";\nimport { StarterKit } from \"@tiptap/starter-kit\";\nimport { useEffect, useMemo } from \"react\";\nimport { cn } from \"@lattice-php/lattice/lib/utils\";\nimport { useT } from \"@lattice-php/lattice/i18n\";\nimport type { RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport { FormFieldFrame } from \"@lattice-php/lattice/form/components/base/field\";\nimport { useFormContext } from \"@lattice-php/lattice/form/hooks/context\";\nimport { useFieldScope } from \"@lattice-php/lattice/form/hooks/field-scope\";\nimport { useDependentField } from \"@lattice-php/lattice/form/hooks/use-dependent-field\";\nimport { useFieldCommit } from \"@lattice-php/lattice/form/hooks/use-field-commit\";\nimport { useFormValue } from \"@lattice-php/lattice/form/hooks/values\";\nimport { registerBuiltinRichEditorExtensions } from \"@lattice-php/lattice/form/rich-editor/builtins\";\nimport {\n assembleStarterKitOptions,\n assembleTiptapExtensions,\n assembleToolbar,\n resolveRichEditorExtensions,\n type ToolbarEntry,\n} from \"@lattice-php/lattice/form/rich-editor/registry\";\nimport { ToolbarIconButton } from \"@lattice-php/lattice/form/rich-editor/toolbar-button\";\n\nregisterBuiltinRichEditorExtensions();\n\nfunction Toolbar({ editor, items }: { editor: Editor; items: ToolbarEntry[] }) {\n const { t } = useT(\"lattice\");\n\n return (\n <div className=\"flex flex-wrap items-center gap-0.5 border-b border-lt-border p-1\">\n {items.map((item, index) => {\n if (item === \"separator\") {\n // eslint-disable-next-line react/no-array-index-key\n return <span key={`sep-${index}`} className=\"mx-1 h-5 w-px bg-lt-border\" />;\n }\n\n if (\"component\" in item) {\n const Control = item.component;\n\n return <Control editor={editor} key={item.key} />;\n }\n\n const label = t(`form.editor.${item.key}`, item.label);\n\n return (\n <ToolbarIconButton\n active={item.isActive(editor)}\n disabled={item.isDisabled?.(editor) ?? false}\n icon={item.icon}\n key={item.key}\n label={label}\n onClick={() => item.run(editor)}\n testId={`editor-${item.key}`}\n />\n );\n })}\n </div>\n );\n}\n\nconst RichEditorField: RendererComponent<\"field.rich-editor\"> = ({ node }) => {\n const { errors } = useFormContext();\n const { hidden, required, readOnly, disabled } = useDependentField(node);\n const { change, blur } = useFieldCommit();\n const name = node.props.name;\n const scope = useFieldScope();\n const globalValue = useFormValue(name);\n const storedValue = scope ? scope.getValue(name) : globalValue;\n const domName = scope ? scope.scopedName(name) : name;\n const errorKey = scope ? scope.errorKey(name) : name;\n const locked = readOnly || disabled;\n const initialContent =\n typeof storedValue === \"object\" && storedValue !== null\n ? (storedValue as object)\n : ((node.props.value as object | undefined) ?? \"\");\n\n const resolved = useMemo(\n () => resolveRichEditorExtensions(node.props.extensions),\n [node.props.extensions],\n );\n const toolbar = useMemo(() => assembleToolbar(resolved), [resolved]);\n const extensions = useMemo(\n () => [\n StarterKit.configure(assembleStarterKitOptions(resolved)),\n Placeholder.configure({ placeholder: node.props.placeholder ?? \"\" }),\n ...assembleTiptapExtensions(resolved),\n ],\n [resolved, node.props.placeholder],\n );\n\n const editor = useEditor({\n extensions,\n content: initialContent,\n editable: !locked,\n immediatelyRender: false,\n // Tiptap v3 stops re-rendering per transaction by default, but the toolbar\n // reads isActive/isDisabled during render — without this, selection-only\n // transactions leave those states stale.\n shouldRerenderOnTransaction: true,\n editorProps: {\n attributes: {\n class: \"lattice-prose min-h-32 px-3 py-2 outline-none\",\n },\n },\n onUpdate: ({ editor: instance }) => {\n change(name, instance.isEmpty ? null : instance.getJSON());\n },\n onBlur: () => {\n blur(name);\n },\n });\n\n useEffect(() => {\n editor?.setEditable(!locked);\n }, [editor, locked]);\n\n if (hidden) {\n return null;\n }\n\n const submittedValue = storedValue ? JSON.stringify(storedValue) : \"\";\n\n return (\n <FormFieldFrame\n error={errors[errorKey]}\n helperText={node.props.helperText ?? undefined}\n tooltip={node.props.tooltip ?? undefined}\n label={node.props.label ?? \"\"}\n name={domName}\n required={required}\n >\n <div\n className={cn(\n \"overflow-hidden rounded-lt-sm border border-lt-input bg-transparent shadow-lt-xs focus-within:border-lt-ring focus-within:ring-[length:var(--lt-ring-width)] focus-within:ring-lt-ring/50\",\n locked && \"opacity-60\",\n )}\n >\n {editor && !locked && toolbar.length > 0 && <Toolbar editor={editor} items={toolbar} />}\n <EditorContent editor={editor} />\n </div>\n <input name={domName} type=\"hidden\" value={submittedValue} />\n </FormFieldFrame>\n );\n};\n\nexport default RichEditorField;\n"],"mappings":";;;;;;;;;;;;;;;;;AAuBA,oCAAoC;AAEpC,SAAS,QAAQ,EAAE,QAAQ,SAAoD;CAC7E,MAAM,EAAE,MAAM,KAAK,SAAS;CAE5B,OACE,oBAAC,OAAD;EAAK,WAAU;EACZ,UAAA,MAAM,KAAK,MAAM,UAAU;GAC1B,IAAI,SAAS,aAEX,OAAO,oBAAC,QAAD,EAA2B,WAAU,6BAA8B,GAAxD,OAAO,OAAiD;GAG5E,IAAI,eAAe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,SAAS,UAAU;EACvB;EACA,SAAS;EACT,UAAU,CAAC;EACX,mBAAmB;EAInB,6BAA6B;EAC7B,aAAa,EACX,YAAY,EACV,OAAO,gDACT,EACF;EACA,WAAW,EAAE,QAAQ,eAAe;GAClC,OAAO,MAAM,SAAS,UAAU,OAAO,SAAS,QAAQ,CAAC;EAC3D;EACA,cAAc;GACZ,KAAK,IAAI;EACX;CACF,CAAC;CAED,gBAAgB;EACd,QAAQ,YAAY,CAAC,MAAM;CAC7B,GAAG,CAAC,QAAQ,MAAM,CAAC;CAEnB,IAAI,QACF,OAAO;CAGT,MAAM,iBAAiB,cAAc,KAAK,UAAU,WAAW,IAAI;CAEnE,OACE,qBAAC,gBAAD;EACE,OAAO,OAAO;EACd,YAAY,KAAK,MAAM,cAAc,KAAA;EACrC,SAAS,KAAK,MAAM,WAAW,KAAA;EAC/B,OAAO,KAAK,MAAM,SAAS;EAC3B,MAAM;EACI;EANZ,UAAA,CAQE,qBAAC,OAAD;GACE,WAAW,GACT,6LACA,UAAU,YACZ;GAJF,UAAA,CAMG,UAAU,CAAC,UAAU,QAAQ,SAAS,KAAK,oBAAC,SAAD;IAAiB;IAAQ,OAAO;GAAU,CAAA,GACtF,oBAAC,eAAD,EAAuB,OAAS,CAAA,CAC7B;EACL,CAAA,GAAA,oBAAC,SAAD;GAAO,MAAM;GAAS,MAAK;GAAS,OAAO;EAAiB,CAAA,CAC9C;;AAEpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rich-editor.js","names":[],"sources":["../../../../resources/js/form/components/fields/rich-editor.tsx"],"sourcesContent":["import { lazy, Suspense } from \"react\";\nimport type { RendererComponent, RendererComponentModule } from \"@lattice-php/lattice/core/types\";\n\nconst RichEditorField = lazy(\n () => import(\"./rich-editor-field\") as unknown as Promise<RendererComponentModule>,\n);\n\nexport const RichEditorComponent: RendererComponent<\"field.rich-editor\"> = ({ children, node }) => (\n <Suspense fallback={null}>\n <RichEditorField node={node}>{children}</RichEditorField>\n </Suspense>\n);\n"],"mappings":";;;AAGA,IAAM,kBAAkB,WAChB,OAAO,yBACf;AAEA,IAAa,uBAA+D,EAAE,UAAU,WACtF,oBAAC,UAAD;CAAU,UAAU;
|
|
1
|
+
{"version":3,"file":"rich-editor.js","names":[],"sources":["../../../../resources/js/form/components/fields/rich-editor.tsx"],"sourcesContent":["import { lazy, Suspense } from \"react\";\nimport type { RendererComponent, RendererComponentModule } from \"@lattice-php/lattice/core/types\";\n\nconst RichEditorField = lazy(\n () => import(\"./rich-editor-field\") as unknown as Promise<RendererComponentModule>,\n);\n\nexport const RichEditorComponent: RendererComponent<\"field.rich-editor\"> = ({ children, node }) => (\n <Suspense fallback={null}>\n <RichEditorField node={node}>{children}</RichEditorField>\n </Suspense>\n);\n"],"mappings":";;;AAGA,IAAM,kBAAkB,WAChB,OAAO,yBACf;AAEA,IAAa,uBAA+D,EAAE,UAAU,WACtF,oBAAC,UAAD;CAAU,UAAU;CAClB,UAAA,oBAAC,iBAAD;EAAuB;EAAO;CAA0B,CAAA;AAChD,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"row-action-menu.js","names":[],"sources":["../../../../resources/js/form/components/fields/row-action-menu.ts"],"sourcesContent":["import type { RowAction as WireRowAction } from \"@lattice-php/lattice/types/generated\";\nimport type { RowAction } from \"./row-actions\";\n\ntype RowActionTranslate = (key: string, fallback: string) => string;\n\n/** Translation key + fallback and icon for each built-in; the server sends null labels. */\nconst BUILT_IN: Record<\"duplicate\" | \"remove\", { key: string; fallback: string; icon: string }> = {\n duplicate: { key: \"table.row-actions.duplicate\", fallback: \"Duplicate\", icon: \"copy\" },\n remove: { key: \"table.row-actions.remove\", fallback: \"Remove\", icon: \"trash-2\" },\n};\n\nexport type RowActionContext = {\n index: number;\n removable: boolean;\n onRemove: (index: number) => void;\n onDuplicate: (index: number) => void;\n t: RowActionTranslate;\n};\n\n/**\n * Resolves the declared wire row actions into the click-wired client actions the\n * kebab renders. `null` (undeclared) falls back to the built-in remove; an empty\n * array disables row actions entirely. Remove is dropped while the row is at its\n * minimum, and built-in labels resolve through i18n when the server sends none.\n */\nexport function buildRowActions(\n declared: WireRowAction[] | null,\n ctx: RowActionContext,\n): RowAction[] {\n const source = declared ?? defaultActions(ctx.removable);\n\n return source\n .map((action) => toClientAction(action, ctx))\n .filter((action): action is RowAction => action !== null);\n}\n\nfunction defaultActions(removable: boolean): WireRowAction[] {\n if (!removable) {\n return [];\n }\n\n return [{ type: \"remove\", key: \"remove\", label: null, icon: null, danger: true }];\n}\n\nfunction toClientAction(action: WireRowAction, ctx: RowActionContext): RowAction | null {\n if (action.type === \"duplicate\") {\n const builtIn = BUILT_IN.duplicate;\n\n return {\n key: action.key,\n label: action.label ?? ctx.t(builtIn.key, builtIn.fallback),\n icon: action.icon ?? builtIn.icon,\n danger: action.danger,\n onClick: () => ctx.onDuplicate(ctx.index),\n };\n }\n\n if (action.type === \"remove\") {\n if (!ctx.removable) {\n return null;\n }\n\n const builtIn = BUILT_IN.remove;\n\n return {\n key: action.key,\n label: action.label ?? ctx.t(builtIn.key, builtIn.fallback),\n icon: action.icon ?? builtIn.icon,\n danger: action.danger,\n onClick: () => ctx.onRemove(ctx.index),\n };\n }\n\n return null;\n}\n"],"mappings":";;AAMA,IAAM,WAA4F;CAChG,WAAW;EAAE,KAAK;EAA+B,UAAU;EAAa,MAAM;CAAO;CACrF,QAAQ;EAAE,KAAK;EAA4B,UAAU;EAAU,MAAM;CAAU;AACjF;;;;;;;AAgBA,SAAgB,gBACd,UACA,KACa;CAGb,QAFe,YAAY,eAAe,IAAI,SAAS,
|
|
1
|
+
{"version":3,"file":"row-action-menu.js","names":[],"sources":["../../../../resources/js/form/components/fields/row-action-menu.ts"],"sourcesContent":["import type { RowAction as WireRowAction } from \"@lattice-php/lattice/types/generated\";\nimport type { RowAction } from \"./row-actions\";\n\ntype RowActionTranslate = (key: string, fallback: string) => string;\n\n/** Translation key + fallback and icon for each built-in; the server sends null labels. */\nconst BUILT_IN: Record<\"duplicate\" | \"remove\", { key: string; fallback: string; icon: string }> = {\n duplicate: { key: \"table.row-actions.duplicate\", fallback: \"Duplicate\", icon: \"copy\" },\n remove: { key: \"table.row-actions.remove\", fallback: \"Remove\", icon: \"trash-2\" },\n};\n\nexport type RowActionContext = {\n index: number;\n removable: boolean;\n onRemove: (index: number) => void;\n onDuplicate: (index: number) => void;\n t: RowActionTranslate;\n};\n\n/**\n * Resolves the declared wire row actions into the click-wired client actions the\n * kebab renders. `null` (undeclared) falls back to the built-in remove; an empty\n * array disables row actions entirely. Remove is dropped while the row is at its\n * minimum, and built-in labels resolve through i18n when the server sends none.\n */\nexport function buildRowActions(\n declared: WireRowAction[] | null,\n ctx: RowActionContext,\n): RowAction[] {\n const source = declared ?? defaultActions(ctx.removable);\n\n return source\n .map((action) => toClientAction(action, ctx))\n .filter((action): action is RowAction => action !== null);\n}\n\nfunction defaultActions(removable: boolean): WireRowAction[] {\n if (!removable) {\n return [];\n }\n\n return [{ type: \"remove\", key: \"remove\", label: null, icon: null, danger: true }];\n}\n\nfunction toClientAction(action: WireRowAction, ctx: RowActionContext): RowAction | null {\n if (action.type === \"duplicate\") {\n const builtIn = BUILT_IN.duplicate;\n\n return {\n key: action.key,\n label: action.label ?? ctx.t(builtIn.key, builtIn.fallback),\n icon: action.icon ?? builtIn.icon,\n danger: action.danger,\n onClick: () => ctx.onDuplicate(ctx.index),\n };\n }\n\n if (action.type === \"remove\") {\n if (!ctx.removable) {\n return null;\n }\n\n const builtIn = BUILT_IN.remove;\n\n return {\n key: action.key,\n label: action.label ?? ctx.t(builtIn.key, builtIn.fallback),\n icon: action.icon ?? builtIn.icon,\n danger: action.danger,\n onClick: () => ctx.onRemove(ctx.index),\n };\n }\n\n return null;\n}\n"],"mappings":";;AAMA,IAAM,WAA4F;CAChG,WAAW;EAAE,KAAK;EAA+B,UAAU;EAAa,MAAM;CAAO;CACrF,QAAQ;EAAE,KAAK;EAA4B,UAAU;EAAU,MAAM;CAAU;AACjF;;;;;;;AAgBA,SAAgB,gBACd,UACA,KACa;CAGb,QAFe,YAAY,eAAe,IAAI,SAAS,EAAA,CAGpD,KAAK,WAAW,eAAe,QAAQ,GAAG,CAAC,CAAC,CAC5C,QAAQ,WAAgC,WAAW,IAAI;AAC5D;AAEA,SAAS,eAAe,WAAqC;CAC3D,IAAI,CAAC,WACH,OAAO,CAAC;CAGV,OAAO,CAAC;EAAE,MAAM;EAAU,KAAK;EAAU,OAAO;EAAM,MAAM;EAAM,QAAQ;CAAK,CAAC;AAClF;AAEA,SAAS,eAAe,QAAuB,KAAyC;CACtF,IAAI,OAAO,SAAS,aAAa;EAC/B,MAAM,UAAU,SAAS;EAEzB,OAAO;GACL,KAAK,OAAO;GACZ,OAAO,OAAO,SAAS,IAAI,EAAE,QAAQ,KAAK,QAAQ,QAAQ;GAC1D,MAAM,OAAO,QAAQ,QAAQ;GAC7B,QAAQ,OAAO;GACf,eAAe,IAAI,YAAY,IAAI,KAAK;EAC1C;CACF;CAEA,IAAI,OAAO,SAAS,UAAU;EAC5B,IAAI,CAAC,IAAI,WACP,OAAO;EAGT,MAAM,UAAU,SAAS;EAEzB,OAAO;GACL,KAAK,OAAO;GACZ,OAAO,OAAO,SAAS,IAAI,EAAE,QAAQ,KAAK,QAAQ,QAAQ;GAC1D,MAAM,OAAO,QAAQ,QAAQ;GAC7B,QAAQ,OAAO;GACf,eAAe,IAAI,SAAS,IAAI,KAAK;EACvC;CACF;CAEA,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"row-actions.js","names":[],"sources":["../../../../resources/js/form/components/fields/row-actions.tsx"],"sourcesContent":["import { Icon } from \"@lattice-php/lattice/icons\";\nimport { useT } from \"@lattice-php/lattice/i18n\";\nimport {\n DropdownMenu,\n DropdownMenuContent,\n DropdownMenuItem,\n DropdownMenuTrigger,\n} from \"@lattice-php/lattice/ui/dropdown-menu\";\n\nexport type RowAction = {\n key: string;\n label: string;\n icon: string;\n onClick: () => void;\n danger?: boolean;\n};\n\nfunction inlineClass(danger?: boolean): string {\n return danger\n ? \"text-lt-danger hover:text-lt-danger [&_svg]:size-lt-icon-sm\"\n : \"text-lt-muted-fg hover:text-lt-fg [&_svg]:size-lt-icon-sm\";\n}\n\nexport function RowActions({ actions }: { actions: RowAction[] }) {\n const { t } = useT(\"lattice\");\n if (actions.length === 0) {\n return null;\n }\n\n if (actions.length === 1) {\n const action = actions[0];\n return (\n <button\n type=\"button\"\n aria-label={action.label}\n data-test={`row-action-${action.key}`}\n className={inlineClass(action.danger)}\n onClick={action.onClick}\n >\n <Icon name={action.icon} />\n </button>\n );\n }\n\n return (\n <DropdownMenu>\n <DropdownMenuTrigger asChild>\n <button\n type=\"button\"\n aria-label={t(\"common.action-group.label\", \"Actions\")}\n data-test=\"row-actions-menu\"\n className=\"text-lt-muted-fg hover:text-lt-fg [&_svg]:size-lt-icon-sm\"\n >\n <Icon name=\"more-horizontal\" />\n </button>\n </DropdownMenuTrigger>\n <DropdownMenuContent align=\"end\" className=\"min-w-[10rem]\">\n {actions.map((action) => (\n <DropdownMenuItem\n key={action.key}\n data-test={`row-action-${action.key}`}\n danger={action.danger}\n icon={action.icon}\n onClick={action.onClick}\n >\n {action.label}\n </DropdownMenuItem>\n ))}\n </DropdownMenuContent>\n </DropdownMenu>\n );\n}\n"],"mappings":";;;;;AAiBA,SAAS,YAAY,QAA0B;CAC7C,OAAO,SACH,gEACA;AACN;AAEA,SAAgB,WAAW,EAAE,WAAqC;CAChE,MAAM,EAAE,MAAM,KAAK,SAAS;CAC5B,IAAI,QAAQ,WAAW,GACrB,OAAO;CAGT,IAAI,QAAQ,WAAW,GAAG;EACxB,MAAM,SAAS,QAAQ;EACvB,OACE,oBAAC,UAAD;GACE,MAAK;GACL,cAAY,OAAO;GACnB,aAAW,cAAc,OAAO;GAChC,WAAW,YAAY,OAAO,MAAM;GACpC,SAAS,OAAO;
|
|
1
|
+
{"version":3,"file":"row-actions.js","names":[],"sources":["../../../../resources/js/form/components/fields/row-actions.tsx"],"sourcesContent":["import { Icon } from \"@lattice-php/lattice/icons\";\nimport { useT } from \"@lattice-php/lattice/i18n\";\nimport {\n DropdownMenu,\n DropdownMenuContent,\n DropdownMenuItem,\n DropdownMenuTrigger,\n} from \"@lattice-php/lattice/ui/dropdown-menu\";\n\nexport type RowAction = {\n key: string;\n label: string;\n icon: string;\n onClick: () => void;\n danger?: boolean;\n};\n\nfunction inlineClass(danger?: boolean): string {\n return danger\n ? \"text-lt-danger hover:text-lt-danger [&_svg]:size-lt-icon-sm\"\n : \"text-lt-muted-fg hover:text-lt-fg [&_svg]:size-lt-icon-sm\";\n}\n\nexport function RowActions({ actions }: { actions: RowAction[] }) {\n const { t } = useT(\"lattice\");\n if (actions.length === 0) {\n return null;\n }\n\n if (actions.length === 1) {\n const action = actions[0];\n return (\n <button\n type=\"button\"\n aria-label={action.label}\n data-test={`row-action-${action.key}`}\n className={inlineClass(action.danger)}\n onClick={action.onClick}\n >\n <Icon name={action.icon} />\n </button>\n );\n }\n\n return (\n <DropdownMenu>\n <DropdownMenuTrigger asChild>\n <button\n type=\"button\"\n aria-label={t(\"common.action-group.label\", \"Actions\")}\n data-test=\"row-actions-menu\"\n className=\"text-lt-muted-fg hover:text-lt-fg [&_svg]:size-lt-icon-sm\"\n >\n <Icon name=\"more-horizontal\" />\n </button>\n </DropdownMenuTrigger>\n <DropdownMenuContent align=\"end\" className=\"min-w-[10rem]\">\n {actions.map((action) => (\n <DropdownMenuItem\n key={action.key}\n data-test={`row-action-${action.key}`}\n danger={action.danger}\n icon={action.icon}\n onClick={action.onClick}\n >\n {action.label}\n </DropdownMenuItem>\n ))}\n </DropdownMenuContent>\n </DropdownMenu>\n );\n}\n"],"mappings":";;;;;AAiBA,SAAS,YAAY,QAA0B;CAC7C,OAAO,SACH,gEACA;AACN;AAEA,SAAgB,WAAW,EAAE,WAAqC;CAChE,MAAM,EAAE,MAAM,KAAK,SAAS;CAC5B,IAAI,QAAQ,WAAW,GACrB,OAAO;CAGT,IAAI,QAAQ,WAAW,GAAG;EACxB,MAAM,SAAS,QAAQ;EACvB,OACE,oBAAC,UAAD;GACE,MAAK;GACL,cAAY,OAAO;GACnB,aAAW,cAAc,OAAO;GAChC,WAAW,YAAY,OAAO,MAAM;GACpC,SAAS,OAAO;GAEhB,UAAA,oBAAC,MAAD,EAAM,MAAM,OAAO,KAAO,CAAA;EACpB,CAAA;CAEZ;CAEA,OACE,qBAAC,cAAD,EAAA,UAAA,CACE,oBAAC,qBAAD;EAAqB,SAAA;EACnB,UAAA,oBAAC,UAAD;GACE,MAAK;GACL,cAAY,EAAE,6BAA6B,SAAS;GACpD,aAAU;GACV,WAAU;GAEV,UAAA,oBAAC,MAAD,EAAM,MAAK,kBAAmB,CAAA;EACxB,CAAA;CACW,CAAA,GACrB,oBAAC,qBAAD;EAAqB,OAAM;EAAM,WAAU;EACxC,UAAA,QAAQ,KAAK,WACZ,oBAAC,kBAAD;GAEE,aAAW,cAAc,OAAO;GAChC,QAAQ,OAAO;GACf,MAAM,OAAO;GACb,SAAS,OAAO;GAEf,UAAA,OAAO;EACQ,GAPX,OAAO,GAOI,CACnB;CACkB,CAAA,CACT,EAAA,CAAA;AAElB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"row-item.js","names":[],"sources":["../../../../resources/js/form/components/fields/row-item.tsx"],"sourcesContent":["import { Icon } from \"@lattice-php/lattice/icons\";\nimport type { ReactNode } from \"react\";\nimport { memo } from \"react\";\nimport type { Node } from \"@lattice-php/lattice/core/types\";\nimport { nodeKey } from \"@lattice-php/lattice/core/nodes\";\nimport { RenderNode } from \"@lattice-php/lattice/core/renderer\";\nimport { useT } from \"@lattice-php/lattice/i18n\";\nimport type { RowAction as WireRowAction } from \"@lattice-php/lattice/types/generated\";\nimport { FieldScopeProvider } from \"@lattice-php/lattice/form/hooks/field-scope\";\nimport { buildRowActions } from \"./row-action-menu\";\nimport { RowActions } from \"./row-actions\";\nimport type { RepeaterRow } from \"./repeater-rows\";\n\nexport function RowButton({\n label,\n testId,\n onClick,\n children,\n}: {\n label: string;\n testId: string;\n onClick: () => void;\n children: ReactNode;\n}) {\n return (\n <button\n type=\"button\"\n aria-label={label}\n data-test={testId}\n className=\"text-lt-muted-fg hover:text-lt-fg\"\n onClick={onClick}\n >\n {children}\n </button>\n );\n}\n\ntype RowItemProps = {\n base: string;\n index: number;\n row: RepeaterRow;\n template: Node[];\n heading: string;\n reorderable: boolean;\n isFirst: boolean;\n isLast: boolean;\n removable: boolean;\n rowActions: WireRowAction[] | null;\n onField: (index: number, field: string, value: unknown) => void;\n onRemove: (index: number) => void;\n onMove: (index: number, delta: number) => void;\n onDuplicate: (index: number) => void;\n};\n\n// Memoised so editing one row doesn't re-render its siblings. Its props are kept\n// referentially stable by the parent: `row` survives untouched via functional\n// store updates, and the handlers are `useCallback`-stable.\nexport const RowItem = memo(function RowItem({\n base,\n index,\n row,\n template,\n heading,\n reorderable,\n isFirst,\n isLast,\n removable,\n rowActions,\n onField,\n onRemove,\n onMove,\n onDuplicate,\n}: RowItemProps) {\n const { t } = useT(\"lattice\");\n\n return (\n <div\n data-test={`repeater-${base}-row-${index}`}\n className=\"rounded-lt border border-lt-border bg-lt-surface p-4\"\n >\n <div className=\"mb-2 flex items-center justify-between\">\n <span className=\"text-sm font-medium text-lt-muted-fg\">{heading}</span>\n <div className=\"flex items-center gap-1 [&_svg]:size-lt-icon-sm\">\n {reorderable && !isFirst && (\n <RowButton\n label=\"Move up\"\n testId={`repeater-${base}-up-${index}`}\n onClick={() => onMove(index, -1)}\n >\n <Icon name=\"arrow-up\" />\n </RowButton>\n )}\n {reorderable && !isLast && (\n <RowButton\n label=\"Move down\"\n testId={`repeater-${base}-down-${index}`}\n onClick={() => onMove(index, 1)}\n >\n <Icon name=\"arrow-down\" />\n </RowButton>\n )}\n <RowActions\n actions={buildRowActions(rowActions, { index, removable, onRemove, onDuplicate, t })}\n />\n </div>\n </div>\n\n <FieldScopeProvider\n base={base}\n index={index}\n row={row}\n onChange={(field, value) => onField(index, field, value)}\n >\n <div className=\"flex flex-col gap-4\">\n {template.map((child, childIndex) => (\n <RenderNode key={nodeKey(child, childIndex)} node={child} />\n ))}\n </div>\n </FieldScopeProvider>\n </div>\n );\n});\n"],"mappings":";;;;;;;;;;AAaA,SAAgB,UAAU,EACxB,OACA,QACA,SACA,YAMC;CACD,OACE,oBAAC,UAAD;EACE,MAAK;EACL,cAAY;EACZ,aAAW;EACX,WAAU;EACD;EAER;CACK,CAAA;AAEZ;AAsBA,IAAa,UAAU,KAAK,SAAS,QAAQ,EAC3C,MACA,OACA,KACA,UACA,SACA,aACA,SACA,QACA,WACA,YACA,SACA,UACA,QACA,eACe;CACf,MAAM,EAAE,MAAM,KAAK,SAAS;CAE5B,OACE,qBAAC,OAAD;EACE,aAAW,YAAY,KAAK,OAAO;EACnC,WAAU;
|
|
1
|
+
{"version":3,"file":"row-item.js","names":[],"sources":["../../../../resources/js/form/components/fields/row-item.tsx"],"sourcesContent":["import { Icon } from \"@lattice-php/lattice/icons\";\nimport type { ReactNode } from \"react\";\nimport { memo } from \"react\";\nimport type { Node } from \"@lattice-php/lattice/core/types\";\nimport { nodeKey } from \"@lattice-php/lattice/core/nodes\";\nimport { RenderNode } from \"@lattice-php/lattice/core/renderer\";\nimport { useT } from \"@lattice-php/lattice/i18n\";\nimport type { RowAction as WireRowAction } from \"@lattice-php/lattice/types/generated\";\nimport { FieldScopeProvider } from \"@lattice-php/lattice/form/hooks/field-scope\";\nimport { buildRowActions } from \"./row-action-menu\";\nimport { RowActions } from \"./row-actions\";\nimport type { RepeaterRow } from \"./repeater-rows\";\n\nexport function RowButton({\n label,\n testId,\n onClick,\n children,\n}: {\n label: string;\n testId: string;\n onClick: () => void;\n children: ReactNode;\n}) {\n return (\n <button\n type=\"button\"\n aria-label={label}\n data-test={testId}\n className=\"text-lt-muted-fg hover:text-lt-fg\"\n onClick={onClick}\n >\n {children}\n </button>\n );\n}\n\ntype RowItemProps = {\n base: string;\n index: number;\n row: RepeaterRow;\n template: Node[];\n heading: string;\n reorderable: boolean;\n isFirst: boolean;\n isLast: boolean;\n removable: boolean;\n rowActions: WireRowAction[] | null;\n onField: (index: number, field: string, value: unknown) => void;\n onRemove: (index: number) => void;\n onMove: (index: number, delta: number) => void;\n onDuplicate: (index: number) => void;\n};\n\n// Memoised so editing one row doesn't re-render its siblings. Its props are kept\n// referentially stable by the parent: `row` survives untouched via functional\n// store updates, and the handlers are `useCallback`-stable.\nexport const RowItem = memo(function RowItem({\n base,\n index,\n row,\n template,\n heading,\n reorderable,\n isFirst,\n isLast,\n removable,\n rowActions,\n onField,\n onRemove,\n onMove,\n onDuplicate,\n}: RowItemProps) {\n const { t } = useT(\"lattice\");\n\n return (\n <div\n data-test={`repeater-${base}-row-${index}`}\n className=\"rounded-lt border border-lt-border bg-lt-surface p-4\"\n >\n <div className=\"mb-2 flex items-center justify-between\">\n <span className=\"text-sm font-medium text-lt-muted-fg\">{heading}</span>\n <div className=\"flex items-center gap-1 [&_svg]:size-lt-icon-sm\">\n {reorderable && !isFirst && (\n <RowButton\n label=\"Move up\"\n testId={`repeater-${base}-up-${index}`}\n onClick={() => onMove(index, -1)}\n >\n <Icon name=\"arrow-up\" />\n </RowButton>\n )}\n {reorderable && !isLast && (\n <RowButton\n label=\"Move down\"\n testId={`repeater-${base}-down-${index}`}\n onClick={() => onMove(index, 1)}\n >\n <Icon name=\"arrow-down\" />\n </RowButton>\n )}\n <RowActions\n actions={buildRowActions(rowActions, { index, removable, onRemove, onDuplicate, t })}\n />\n </div>\n </div>\n\n <FieldScopeProvider\n base={base}\n index={index}\n row={row}\n onChange={(field, value) => onField(index, field, value)}\n >\n <div className=\"flex flex-col gap-4\">\n {template.map((child, childIndex) => (\n <RenderNode key={nodeKey(child, childIndex)} node={child} />\n ))}\n </div>\n </FieldScopeProvider>\n </div>\n );\n});\n"],"mappings":";;;;;;;;;;AAaA,SAAgB,UAAU,EACxB,OACA,Q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@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"row-templates.js","names":[],"sources":["../../../../resources/js/form/components/fields/row-templates.ts"],"sourcesContent":["import type { Node } from \"@lattice-php/lattice/core/types\";\n\nexport type RowTemplate = { type: string; label: string; schema: Node[] };\n\nexport function rowTemplatesOf(node: Node): RowTemplate[] | undefined {\n return (node as unknown as { templates?: RowTemplate[] }).templates;\n}\n\n/** The schema for a submitted row: its matching template, or the node's own schema when untyped. */\nexport function rowSchemaFor(node: Node, row: Record<string, unknown>): Node[] {\n const templates = rowTemplatesOf(node);\n\n if (!templates) {\n return node.schema ?? [];\n }\n\n return templates.find((template) => template.type === row.type)?.schema ?? [];\n}\n"],"mappings":";AAIA,SAAgB,eAAe,MAAuC;CACpE,OAAQ,KAAkD;AAC5D;;AAGA,SAAgB,aAAa,MAAY,KAAsC;CAC7E,MAAM,YAAY,eAAe,IAAI;CAErC,IAAI,CAAC,WACH,OAAO,KAAK,UAAU,CAAC;CAGzB,OAAO,UAAU,MAAM,aAAa,SAAS,SAAS,IAAI,IAAI,
|
|
1
|
+
{"version":3,"file":"row-templates.js","names":[],"sources":["../../../../resources/js/form/components/fields/row-templates.ts"],"sourcesContent":["import type { Node } from \"@lattice-php/lattice/core/types\";\n\nexport type RowTemplate = { type: string; label: string; schema: Node[] };\n\nexport function rowTemplatesOf(node: Node): RowTemplate[] | undefined {\n return (node as unknown as { templates?: RowTemplate[] }).templates;\n}\n\n/** The schema for a submitted row: its matching template, or the node's own schema when untyped. */\nexport function rowSchemaFor(node: Node, row: Record<string, unknown>): Node[] {\n const templates = rowTemplatesOf(node);\n\n if (!templates) {\n return node.schema ?? [];\n }\n\n return templates.find((template) => template.type === row.type)?.schema ?? [];\n}\n"],"mappings":";AAIA,SAAgB,eAAe,MAAuC;CACpE,OAAQ,KAAkD;AAC5D;;AAGA,SAAgB,aAAa,MAAY,KAAsC;CAC7E,MAAM,YAAY,eAAe,IAAI;CAErC,IAAI,CAAC,WACH,OAAO,KAAK,UAAU,CAAC;CAGzB,OAAO,UAAU,MAAM,aAAa,SAAS,SAAS,IAAI,IAAI,CAAC,EAAE,UAAU,CAAC;AAC9E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select.js","names":[],"sources":["../../../../resources/js/form/components/fields/select.tsx"],"sourcesContent":["import { Icon } from \"@lattice-php/lattice/icons\";\nimport { useCallback, useMemo, useRef, useState } from \"react\";\nimport { Combobox } from \"@lattice-php/lattice/ui/combobox\";\nimport { controlSurface } from \"@lattice-php/lattice/ui/control\";\nimport { coerceColor, colorValue } from \"@lattice-php/lattice/lib/color\";\nimport { cn } from \"@lattice-php/lattice/lib/utils\";\nimport { useT } from \"@lattice-php/lattice/i18n\";\nimport { Renderer } from \"@lattice-php/lattice/core/renderer\";\nimport { materializeSchema } from \"@lattice-php/lattice/core/materialize\";\nimport type { Node, Option, RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport { FormFieldFrame } from \"@lattice-php/lattice/form/components/base/field\";\nimport { useFormContext } from \"@lattice-php/lattice/form/hooks/context\";\nimport { fieldDomName } from \"@lattice-php/lattice/form/lib/field-dom-name\";\nimport { postFormAction } from \"@lattice-php/lattice/form/lib/form-transport\";\nimport { useResolvedNode } from \"@lattice-php/lattice/form/hooks/resolved-nodes\";\nimport { useDependentField } from \"@lattice-php/lattice/form/hooks/use-dependent-field\";\nimport { useFieldCommit } from \"@lattice-php/lattice/form/hooks/use-field-commit\";\nimport { useFieldScope } from \"@lattice-php/lattice/form/hooks/field-scope\";\nimport { useFormValue, useFormValues } from \"@lattice-php/lattice/form/hooks/values\";\n\nfunction toValues(stored: unknown, fallback: unknown): string[] {\n const source = stored ?? fallback;\n\n if (Array.isArray(source)) {\n return source.map(String);\n }\n\n if (source === undefined || source === null || source === \"\") {\n return [];\n }\n\n return [String(source)];\n}\n\nexport const SelectComponent: RendererComponent<\"field.select\"> = ({ node }) => {\n const { t } = useT(\"lattice\");\n const props = node.props;\n const { action, componentRef, errors, fieldIdPrefix, searchOptions } = useFormContext();\n const { hidden, required, readOnly, disabled } = useDependentField(node);\n const { change, blur } = useFieldCommit();\n const resolvedNode = useResolvedNode(node);\n const name = props.name;\n const scope = useFieldScope();\n const domName = fieldDomName(scope ? scope.scopedName(name) : name, fieldIdPrefix);\n const errorKey = scope ? scope.errorKey(name) : name;\n const searchKey = errorKey;\n const placeholder = props.placeholder || \"Select…\";\n const multiple = props.multiple;\n const searchable = props.searchable;\n const creatable = props.creatable;\n const staticOptions = useMemo(\n () => (resolvedNode.props as { options?: Option[] }).options ?? [],\n [resolvedNode.props],\n );\n const optionSchema = (resolvedNode.props as { optionSchema?: Node[] }).optionSchema;\n\n const globalValue = useFormValue(name);\n const values = useFormValues();\n const valuesRef = useRef(values);\n valuesRef.current = values;\n const storedValue = scope ? scope.getValue(name) : globalValue;\n const selected = useMemo(() => toValues(storedValue, props.value), [storedValue, props.value]);\n const selectedRef = useRef(selected);\n selectedRef.current = selected;\n\n const [open, setOpen] = useState(false);\n const [results, setResults] = useState<Option[] | null>(null);\n const [loading, setLoading] = useState(false);\n const searchAbort = useRef<AbortController | null>(null);\n\n const optionsByValue = useMemo(() => {\n const map = new Map<string, Option>();\n\n for (const option of [...staticOptions, ...(results ?? [])]) {\n map.set(option.value, option);\n }\n\n return map;\n }, [staticOptions, results]);\n const labelFor = (value: string) => optionsByValue.get(value)?.label ?? value;\n const colorFor = (value: string) =>\n coerceColor((optionsByValue.get(value)?.data as { color?: unknown } | undefined)?.color);\n\n const locked = readOnly || disabled;\n\n const search = useCallback(\n (query: string) => {\n searchAbort.current?.abort();\n\n if (query.trim() === \"\") {\n setResults(null);\n setLoading(false);\n\n return;\n }\n\n const controller = new AbortController();\n searchAbort.current = controller;\n setLoading(true);\n\n if (searchOptions) {\n void searchOptions(searchKey, query, valuesRef.current, controller.signal)\n .then((options) => {\n setResults(options);\n setLoading(false);\n })\n .catch(() => {});\n\n return;\n }\n\n void postFormAction<{ options?: Option[] }>(\n action,\n componentRef,\n { ...valuesRef.current, _sub: \"search\", _target: searchKey, _q: query },\n controller.signal,\n )\n .then((response) => {\n setResults(response?.options ?? []);\n setLoading(false);\n })\n .catch(() => {});\n },\n [action, componentRef, searchKey, searchOptions],\n );\n\n function commit(next: string[]): void {\n change(name, multiple ? next : (next[0] ?? \"\"));\n }\n\n function select(value: string): void {\n if (multiple) {\n const next = selectedRef.current.includes(value)\n ? selectedRef.current.filter((item) => item !== value)\n : [...selectedRef.current, value];\n selectedRef.current = next;\n commit(next);\n\n return;\n }\n\n selectedRef.current = [value];\n commit([value]);\n }\n\n function remove(value: string): void {\n commit(selected.filter((item) => item !== value));\n }\n\n function applyCreated(value: string): void {\n if (!multiple) {\n selectedRef.current = [value];\n commit([value]);\n\n return;\n }\n\n if (!selectedRef.current.includes(value)) {\n const next = [...selectedRef.current, value];\n selectedRef.current = next;\n commit(next);\n }\n }\n\n if (hidden) {\n return null;\n }\n\n const options = searchable ? (results ?? staticOptions) : staticOptions;\n\n const renderOption = optionSchema?.length\n ? (option: Option) => (\n <Renderer\n nodes={materializeSchema(optionSchema, {\n ...option.data,\n label: option.label,\n value: option.value,\n })}\n />\n )\n : undefined;\n\n return (\n <FormFieldFrame\n error={errors[errorKey]}\n helperText={props.helperText ?? undefined}\n tooltip={props.tooltip ?? undefined}\n label={props.label ?? \"\"}\n name={domName}\n required={required}\n >\n {multiple ? (\n selected.map((value) => (\n <input key={value} name={`${domName}[]`} type=\"hidden\" value={value} />\n ))\n ) : (\n <input name={domName} type=\"hidden\" value={selected[0] ?? \"\"} />\n )}\n\n <div>\n {multiple && selected.length > 0 && (\n <div className=\"mb-1.5 flex flex-wrap gap-1\">\n {selected.map((value) => {\n const color = colorFor(value);\n\n return (\n <span\n className=\"inline-flex items-center gap-1 rounded-lt-sm bg-lt-muted px-2 py-0.5 text-xs\"\n key={value}\n >\n {color && (\n <span\n aria-hidden=\"true\"\n className=\"size-2 shrink-0 rounded-full\"\n style={{ background: colorValue(color) }}\n />\n )}\n {labelFor(value)}\n {!locked && (\n <button\n aria-label={t(\"form.remove-option\", \"Remove {{label}}\", {\n label: labelFor(value),\n })}\n data-test={`select-${name}-remove-${value}`}\n className=\"text-lt-muted-fg hover:text-lt-fg [&_svg]:size-lt-icon-xs\"\n onClick={() => remove(value)}\n type=\"button\"\n >\n <Icon name=\"x\" />\n </button>\n )}\n </span>\n );\n })}\n </div>\n )}\n\n <Combobox\n creatable={creatable}\n emptyLabel={props.emptyLabel ?? undefined}\n loading={loading}\n multiple={multiple}\n onCommit={applyCreated}\n onCreate={applyCreated}\n onSearch={searchable ? search : undefined}\n onSelect={select}\n open={open && !locked}\n onOpenChange={(next) => {\n setOpen(next);\n\n if (!next) {\n blur(name);\n }\n }}\n options={options}\n renderOption={renderOption}\n searchPlaceholder={props.searchPlaceholder ?? undefined}\n showSearch={Boolean(searchable || creatable)}\n selected={selected}\n testId={`select-${name}`}\n trigger={\n <>\n {!multiple && selected.length > 0 ? (\n <span>{labelFor(selected[0])}</span>\n ) : (\n <span className=\"text-lt-muted-fg\">{placeholder}</span>\n )}\n <Icon name=\"chevrons-up-down\" className=\"size-lt-icon-md shrink-0 text-lt-muted-fg\" />\n </>\n }\n triggerClassName={cn(\n controlSurface(),\n \"flex items-center justify-between gap-2 text-left\",\n locked && \"cursor-not-allowed opacity-60\",\n )}\n triggerProps={{\n \"aria-haspopup\": \"listbox\",\n autoFocus: props.autoFocus ?? undefined,\n \"data-test\": `select-${name}`,\n disabled: locked,\n id: domName,\n tabIndex: props.tabIndex ?? undefined,\n }}\n />\n </div>\n </FormFieldFrame>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoBA,SAAS,SAAS,QAAiB,UAA6B;CAC9D,MAAM,SAAS,UAAU;CAEzB,IAAI,MAAM,QAAQ,MAAM,GACtB,OAAO,OAAO,IAAI,MAAM;CAG1B,IAAI,WAAW,KAAA,KAAa,WAAW,QAAQ,WAAW,IACxD,OAAO,CAAC;CAGV,OAAO,CAAC,OAAO,MAAM,C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;MAEF,SAAS,KAAK;MACd,CAAC,UACA,oBAAC,UAAD;OACE,cAAY,EAAE,sBAAsB,oBAAoB,EACtD,OAAO,SAAS,KAAK,EACvB,CAAC;OACD,aAAW,UAAU,KAAK,UAAU;OACpC,WAAU;OACV,eAAe,OAAO,KAAK;OAC3B,MAAK;iBAEL,oBAAC,MAAD,EAAM,MAAK,IAAK,CAAA;MACV,CAAA;KAEN;OAvBC,KAuBD;GAEV,CAAC;EACE,CAAA,GAGP,oBAAC,UAAD;GACa;GACX,YAAY,MAAM,cAAc,KAAA;GACvB;GACC;GACV,UAAU;GACV,UAAU;GACV,UAAU,aAAa,SAAS,KAAA;GAChC,UAAU;GACV,MAAM,QAAQ,CAAC;GACf,eAAe,SAAS;IACtB,QAAQ,IAAI;IAEZ,IAAI,CAAC,MACH,KAAK,IAAI;GAEb;GACS;GACK;GACd,mBAAmB,MAAM,qBAAqB,KAAA;GAC9C,YAAY,QAAQ,cAAc,SAAS;GACjC;GACV,QAAQ,UAAU;GAClB,SACE,qBAAA,YAAA,EAAA,UAAA,CACG,CAAC,YAAY,SAAS,SAAS,IAC9B,oBAAC,QAAD,EAAA,UAAO,SAAS,SAAS,EAAE,EAAQ,CAAA,IAEnC,oBAAC,QAAD;IAAM,WAAU;cAAoB;GAAkB,CAAA,GAExD,oBAAC,MAAD;IAAM,MAAK;IAAmB,WAAU;GAA6C,CAAA,CACrF,EAAA,CAAA;GAEJ,kBAAkB,GAChB,eAAe,GACf,qDACA,UAAU,+BACZ;GACA,cAAc;IACZ,iBAAiB;IACjB,WAAW,MAAM,aAAa,KAAA;IAC9B,aAAa,UAAU;IACvB,UAAU;IACV,IAAI;IACJ,UAAU,MAAM,YAAY,KAAA;GAC9B;EACD,CAAA,CACE,EAAA,CAAA,CACS;;AAEpB"}
|
|
1
|
+
{"version":3,"file":"select.js","names":[],"sources":["../../../../resources/js/form/components/fields/select.tsx"],"sourcesContent":["import { Icon } from \"@lattice-php/lattice/icons\";\nimport { useCallback, useMemo, useRef, useState } from \"react\";\nimport { Combobox } from \"@lattice-php/lattice/ui/combobox\";\nimport { controlSurface } from \"@lattice-php/lattice/ui/control\";\nimport { coerceColor, colorValue } from \"@lattice-php/lattice/lib/color\";\nimport { cn } from \"@lattice-php/lattice/lib/utils\";\nimport { useT } from \"@lattice-php/lattice/i18n\";\nimport { Renderer } from \"@lattice-php/lattice/core/renderer\";\nimport { materializeSchema } from \"@lattice-php/lattice/core/materialize\";\nimport type { Node, Option, RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport { FormFieldFrame } from \"@lattice-php/lattice/form/components/base/field\";\nimport { useFormContext } from \"@lattice-php/lattice/form/hooks/context\";\nimport { fieldDomName } from \"@lattice-php/lattice/form/lib/field-dom-name\";\nimport { postFormAction } from \"@lattice-php/lattice/form/lib/form-transport\";\nimport { useResolvedNode } from \"@lattice-php/lattice/form/hooks/resolved-nodes\";\nimport { useDependentField } from \"@lattice-php/lattice/form/hooks/use-dependent-field\";\nimport { useFieldCommit } from \"@lattice-php/lattice/form/hooks/use-field-commit\";\nimport { useFieldScope } from \"@lattice-php/lattice/form/hooks/field-scope\";\nimport { useFormValue, useFormValues } from \"@lattice-php/lattice/form/hooks/values\";\n\nfunction toValues(stored: unknown, fallback: unknown): string[] {\n const source = stored ?? fallback;\n\n if (Array.isArray(source)) {\n return source.map(String);\n }\n\n if (source === undefined || source === null || source === \"\") {\n return [];\n }\n\n return [String(source)];\n}\n\nexport const SelectComponent: RendererComponent<\"field.select\"> = ({ node }) => {\n const { t } = useT(\"lattice\");\n const props = node.props;\n const { action, componentRef, errors, fieldIdPrefix, searchOptions } = useFormContext();\n const { hidden, required, readOnly, disabled } = useDependentField(node);\n const { change, blur } = useFieldCommit();\n const resolvedNode = useResolvedNode(node);\n const name = props.name;\n const scope = useFieldScope();\n const domName = fieldDomName(scope ? scope.scopedName(name) : name, fieldIdPrefix);\n const errorKey = scope ? scope.errorKey(name) : name;\n const searchKey = errorKey;\n const placeholder = props.placeholder || \"Select…\";\n const multiple = props.multiple;\n const searchable = props.searchable;\n const creatable = props.creatable;\n const staticOptions = useMemo(\n () => (resolvedNode.props as { options?: Option[] }).options ?? [],\n [resolvedNode.props],\n );\n const optionSchema = (resolvedNode.props as { optionSchema?: Node[] }).optionSchema;\n\n const globalValue = useFormValue(name);\n const values = useFormValues();\n const valuesRef = useRef(values);\n valuesRef.current = values;\n const storedValue = scope ? scope.getValue(name) : globalValue;\n const selected = useMemo(() => toValues(storedValue, props.value), [storedValue, props.value]);\n const selectedRef = useRef(selected);\n selectedRef.current = selected;\n\n const [open, setOpen] = useState(false);\n const [results, setResults] = useState<Option[] | null>(null);\n const [loading, setLoading] = useState(false);\n const searchAbort = useRef<AbortController | null>(null);\n\n const optionsByValue = useMemo(() => {\n const map = new Map<string, Option>();\n\n for (const option of [...staticOptions, ...(results ?? [])]) {\n map.set(option.value, option);\n }\n\n return map;\n }, [staticOptions, results]);\n const labelFor = (value: string) => optionsByValue.get(value)?.label ?? value;\n const colorFor = (value: string) =>\n coerceColor((optionsByValue.get(value)?.data as { color?: unknown } | undefined)?.color);\n\n const locked = readOnly || disabled;\n\n const search = useCallback(\n (query: string) => {\n searchAbort.current?.abort();\n\n if (query.trim() === \"\") {\n setResults(null);\n setLoading(false);\n\n return;\n }\n\n const controller = new AbortController();\n searchAbort.current = controller;\n setLoading(true);\n\n if (searchOptions) {\n void searchOptions(searchKey, query, valuesRef.current, controller.signal)\n .then((options) => {\n setResults(options);\n setLoading(false);\n })\n .catch(() => {});\n\n return;\n }\n\n void postFormAction<{ options?: Option[] }>(\n action,\n componentRef,\n { ...valuesRef.current, _sub: \"search\", _target: searchKey, _q: query },\n controller.signal,\n )\n .then((response) => {\n setResults(response?.options ?? []);\n setLoading(false);\n })\n .catch(() => {});\n },\n [action, componentRef, searchKey, searchOptions],\n );\n\n function commit(next: string[]): void {\n change(name, multiple ? next : (next[0] ?? \"\"));\n }\n\n function select(value: string): void {\n if (multiple) {\n const next = selectedRef.current.includes(value)\n ? selectedRef.current.filter((item) => item !== value)\n : [...selectedRef.current, value];\n selectedRef.current = next;\n commit(next);\n\n return;\n }\n\n selectedRef.current = [value];\n commit([value]);\n }\n\n function remove(value: string): void {\n commit(selected.filter((item) => item !== value));\n }\n\n function applyCreated(value: string): void {\n if (!multiple) {\n selectedRef.current = [value];\n commit([value]);\n\n return;\n }\n\n if (!selectedRef.current.includes(value)) {\n const next = [...selectedRef.current, value];\n selectedRef.current = next;\n commit(next);\n }\n }\n\n if (hidden) {\n return null;\n }\n\n const options = searchable ? (results ?? staticOptions) : staticOptions;\n\n const renderOption = optionSchema?.length\n ? (option: Option) => (\n <Renderer\n nodes={materializeSchema(optionSchema, {\n ...option.data,\n label: option.label,\n value: option.value,\n })}\n />\n )\n : undefined;\n\n return (\n <FormFieldFrame\n error={errors[errorKey]}\n helperText={props.helperText ?? undefined}\n tooltip={props.tooltip ?? undefined}\n label={props.label ?? \"\"}\n name={domName}\n required={required}\n >\n {multiple ? (\n selected.map((value) => (\n <input key={value} name={`${domName}[]`} type=\"hidden\" value={value} />\n ))\n ) : (\n <input name={domName} type=\"hidden\" value={selected[0] ?? \"\"} />\n )}\n\n <div>\n {multiple && selected.length > 0 && (\n <div className=\"mb-1.5 flex flex-wrap gap-1\">\n {selected.map((value) => {\n const color = colorFor(value);\n\n return (\n <span\n className=\"inline-flex items-center gap-1 rounded-lt-sm bg-lt-muted px-2 py-0.5 text-xs\"\n key={value}\n >\n {color && (\n <span\n aria-hidden=\"true\"\n className=\"size-2 shrink-0 rounded-full\"\n style={{ background: colorValue(color) }}\n />\n )}\n {labelFor(value)}\n {!locked && (\n <button\n aria-label={t(\"form.remove-option\", \"Remove {{label}}\", {\n label: labelFor(value),\n })}\n data-test={`select-${name}-remove-${value}`}\n className=\"text-lt-muted-fg hover:text-lt-fg [&_svg]:size-lt-icon-xs\"\n onClick={() => remove(value)}\n type=\"button\"\n >\n <Icon name=\"x\" />\n </button>\n )}\n </span>\n );\n })}\n </div>\n )}\n\n <Combobox\n creatable={creatable}\n emptyLabel={props.emptyLabel ?? undefined}\n loading={loading}\n multiple={multiple}\n onCommit={applyCreated}\n onCreate={applyCreated}\n onSearch={searchable ? search : undefined}\n onSelect={select}\n open={open && !locked}\n onOpenChange={(next) => {\n setOpen(next);\n\n if (!next) {\n blur(name);\n }\n }}\n options={options}\n renderOption={renderOption}\n searchPlaceholder={props.searchPlaceholder ?? undefined}\n showSearch={Boolean(searchable || creatable)}\n selected={selected}\n testId={`select-${name}`}\n trigger={\n <>\n {!multiple && selected.length > 0 ? (\n <span>{labelFor(selected[0])}</span>\n ) : (\n <span className=\"text-lt-muted-fg\">{placeholder}</span>\n )}\n <Icon name=\"chevrons-up-down\" className=\"size-lt-icon-md shrink-0 text-lt-muted-fg\" />\n </>\n }\n triggerClassName={cn(\n controlSurface(),\n \"flex items-center justify-between gap-2 text-left\",\n locked && \"cursor-not-allowed opacity-60\",\n )}\n triggerProps={{\n \"aria-haspopup\": \"listbox\",\n autoFocus: props.autoFocus ?? undefined,\n \"data-test\": `select-${name}`,\n disabled: locked,\n id: domName,\n tabIndex: props.tabIndex ?? undefined,\n }}\n />\n </div>\n </FormFieldFrame>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoBA,SAAS,SAAS,QAAiB,UAA6B;CAC9D,MAAM,SAAS,UAAU;CAEzB,IAAI,MAAM,QAAQ,MAAM,GACtB,OAAO,OAAO,IAAI,MAAM;CAG1B,IAAI,WAAW,KAAA,KAAa,WAAW,QAAQ,WAAW,IACxD,OAAO,CAAC;CAGV,OAAO,CAAC,OAAO,MAAM,CAAC;AACxB;AAEA,IAAa,mBAAsD,EAAE,WAAW;CAC9E,MAAM,EAAE,MAAM,KAAK,SAAS;CAC5B,MAAM,QAAQ,KAAK;CACnB,MAAM,EAAE,QAAQ,cAAc,QAAQ,eAAe,kBAAkB,eAAe;CACtF,MAAM,EAAE,QAAQ,UAAU,UAAU,aAAa,kBAAkB,IAAI;CACvE,MAAM,EAAE,QAAQ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B,MAAK;OAEL,UAAA,oBAAC,MAAD,EAAM,MAAK,IAAK,CAAA;MACV,CAAA;KAEN;IAvBC,GAAA,KAuBD;GAEV,CAAC;EACE,CAAA,GAGP,oBAAC,UAAD;GACa;GACX,YAAY,MAAM,cAAc,KAAA;GACvB;GACC;GACV,UAAU;GACV,UAAU;GACV,UAAU,aAAa,SAAS,KAAA;GAChC,UAAU;GACV,MAAM,QAAQ,CAAC;GACf,eAAe,SAAS;IACtB,QAAQ,IAAI;IAEZ,IAAI,CAAC,MACH,KAAK,IAAI;GAEb;GACS;GACK;GACd,mBAAmB,MAAM,qBAAqB,KAAA;GAC9C,YAAY,QAAQ,cAAc,SAAS;GACjC;GACV,QAAQ,UAAU;GAClB,SACE,qBAAA,YAAA,EAAA,UAAA,CACG,CAAC,YAAY,SAAS,SAAS,IAC9B,oBAAC,QAAD,EAAA,UAAO,SAAS,SAAS,EAAE,EAAQ,CAAA,IAEnC,oBAAC,QAAD;IAAM,WAAU;IAAoB,UAAA;GAAkB,CAAA,GAExD,oBAAC,MAAD;IAAM,MAAK;IAAmB,WAAU;GAA6C,CAAA,CACrF,EAAA,CAAA;GAEJ,kBAAkB,GAChB,eAAe,GACf,qDACA,UAAU,+BACZ;GACA,cAAc;IACZ,iBAAiB;IACjB,WAAW,MAAM,aAAa,KAAA;IAC9B,aAAa,UAAU;IACvB,UAAU;IACV,IAAI;IACJ,UAAU,MAAM,YAAY,KAAA;GAC9B;EACD,CAAA,CACE,EAAA,CAAA,CACS;;AAEpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simple-field.js","names":[],"sources":["../../../../resources/js/form/components/fields/simple-field.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport type { Node } from \"@lattice-php/lattice/core/types\";\nimport { FormFieldFrame } from \"@lattice-php/lattice/form/components/base/field\";\nimport { fieldProps } from \"@lattice-php/lattice/form/lib/field-props\";\nimport {\n type ControlledField,\n useControlledField,\n} from \"@lattice-php/lattice/form/hooks/use-controlled-field\";\n\nexport function SimpleField({\n node,\n label,\n children,\n}: {\n node: Node;\n label: string;\n children: (field: ControlledField) => ReactNode;\n}) {\n const field = useControlledField(node);\n\n if (field.hidden) {\n return null;\n }\n\n return (\n <FormFieldFrame\n error={field.error}\n helperText={fieldProps(node).helperText ?? undefined}\n tooltip={fieldProps(node).tooltip ?? undefined}\n label={label}\n name={field.name}\n required={field.required}\n >\n {children(field)}\n </FormFieldFrame>\n );\n}\n"],"mappings":";;;;;AASA,SAAgB,YAAY,EAC1B,MACA,OACA,YAKC;CACD,MAAM,QAAQ,mBAAmB,IAAI;CAErC,IAAI,MAAM,QACR,OAAO;CAGT,OACE,oBAAC,gBAAD;EACE,OAAO,MAAM;EACb,YAAY,WAAW,IAAI,
|
|
1
|
+
{"version":3,"file":"simple-field.js","names":[],"sources":["../../../../resources/js/form/components/fields/simple-field.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport type { Node } from \"@lattice-php/lattice/core/types\";\nimport { FormFieldFrame } from \"@lattice-php/lattice/form/components/base/field\";\nimport { fieldProps } from \"@lattice-php/lattice/form/lib/field-props\";\nimport {\n type ControlledField,\n useControlledField,\n} from \"@lattice-php/lattice/form/hooks/use-controlled-field\";\n\nexport function SimpleField({\n node,\n label,\n children,\n}: {\n node: Node;\n label: string;\n children: (field: ControlledField) => ReactNode;\n}) {\n const field = useControlledField(node);\n\n if (field.hidden) {\n return null;\n }\n\n return (\n <FormFieldFrame\n error={field.error}\n helperText={fieldProps(node).helperText ?? undefined}\n tooltip={fieldProps(node).tooltip ?? undefined}\n label={label}\n name={field.name}\n required={field.required}\n >\n {children(field)}\n </FormFieldFrame>\n );\n}\n"],"mappings":";;;;;AASA,SAAgB,YAAY,EAC1B,MACA,OACA,YAKC;CACD,MAAM,QAAQ,mBAAmB,IAAI;CAErC,IAAI,MAAM,QACR,OAAO;CAGT,OACE,oBAAC,gBAAD;EACE,OAAO,MAAM;EACb,YAAY,WAAW,IAAI,CAAC,CAAC,cAAc,KAAA;EAC3C,SAAS,WAAW,IAAI,CAAC,CAAC,WAAW,KAAA;EAC9B;EACP,MAAM,MAAM;EACZ,UAAU,MAAM;EAEf,UAAA,SAAS,KAAK;CACD,CAAA;AAEpB"}
|