@ecopages/radiant-ui 0.1.0-beta.7 → 0.1.0-beta.8
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/README.md +1 -1
- package/dist/components/ui/alert/alert.css +88 -50
- package/dist/components/ui/alert/alert.d.ts +43 -5
- package/dist/components/ui/alert/alert.script.d.ts +51 -4
- package/dist/components/ui/alert/index.d.ts +2 -2
- package/dist/components/ui/alert/index.js +1 -1
- package/dist/components/ui/alert/index.js.map +4 -4
- package/dist/components/ui/autocomplete/autocomplete.css +4 -4
- package/dist/components/ui/autocomplete/autocomplete.d.ts +15 -5
- package/dist/components/ui/autocomplete/autocomplete.script.d.ts +9 -0
- package/dist/components/ui/autocomplete/index.js +1 -1
- package/dist/components/ui/autocomplete/index.js.map +4 -4
- package/dist/components/ui/avatar/avatar.d.ts +15 -1
- package/dist/components/ui/avatar/index.js +1 -1
- package/dist/components/ui/avatar/index.js.map +4 -4
- package/dist/components/ui/breadcrumb/breadcrumb.d.ts +32 -6
- package/dist/components/ui/breadcrumb/index.js +1 -1
- package/dist/components/ui/breadcrumb/index.js.map +4 -4
- package/dist/{styles/components → components/ui/button}/button.css +45 -31
- package/dist/components/ui/button/button.d.ts +21 -4
- package/dist/components/ui/button-group/button-group.d.ts +7 -1
- package/dist/components/ui/button-group/index.js +1 -1
- package/dist/components/ui/button-group/index.js.map +4 -4
- package/dist/components/ui/calendar/calendar.css +7 -7
- package/dist/components/ui/calendar/calendar.d.ts +3 -2
- package/dist/components/ui/calendar/calendar.script.d.ts +39 -1
- package/dist/components/ui/calendar/index.js +1 -1
- package/dist/components/ui/calendar/index.js.map +4 -4
- package/dist/components/ui/carousel/carousel.d.ts +32 -6
- package/dist/components/ui/carousel/carousel.script.d.ts +44 -0
- package/dist/components/ui/carousel/index.js +1 -1
- package/dist/components/ui/carousel/index.js.map +4 -4
- package/dist/components/ui/checkbox/checkbox.css +1 -1
- package/dist/components/ui/checkbox/checkbox.d.ts +3 -2
- package/dist/components/ui/checkbox/checkbox.script.d.ts +4 -0
- package/dist/components/ui/checkbox/index.js +1 -1
- package/dist/components/ui/checkbox/index.js.map +4 -4
- package/dist/components/ui/chip/chip.d.ts +8 -0
- package/dist/components/ui/chip/index.js +1 -1
- package/dist/components/ui/chip/index.js.map +4 -4
- package/dist/components/ui/chip-list/chip-list.d.ts +10 -2
- package/dist/components/ui/chip-list/index.js +1 -1
- package/dist/components/ui/chip-list/index.js.map +4 -4
- package/dist/components/ui/combobox/combobox.css +39 -1
- package/dist/components/ui/combobox/combobox.d.ts +15 -5
- package/dist/components/ui/combobox/combobox.script.d.ts +13 -1
- package/dist/components/ui/combobox/index.js +1 -1
- package/dist/components/ui/combobox/index.js.map +4 -4
- package/dist/components/ui/cycle-toggle/cycle-toggle.css +15 -0
- package/dist/components/ui/cycle-toggle/cycle-toggle.d.ts +29 -0
- package/dist/components/ui/cycle-toggle/cycle-toggle.script.d.ts +61 -0
- package/dist/components/ui/cycle-toggle/index.d.ts +5 -0
- package/dist/components/ui/cycle-toggle/index.js +2 -0
- package/dist/components/ui/cycle-toggle/index.js.map +7 -0
- package/dist/components/ui/cycle-toggle/theme-preference-icons.d.ts +12 -0
- package/dist/components/ui/date-field/date-field.css +37 -0
- package/dist/components/ui/date-field/date-field.d.ts +22 -3
- package/dist/components/ui/date-field/date-field.script.d.ts +29 -5
- package/dist/components/ui/date-field/index.d.ts +1 -1
- package/dist/components/ui/date-field/index.js +1 -1
- package/dist/components/ui/date-field/index.js.map +4 -4
- package/dist/components/ui/date-range-picker/date-range-picker.css +37 -0
- package/dist/components/ui/date-range-picker/date-range-picker.d.ts +37 -4
- package/dist/components/ui/date-range-picker/date-range-picker.script.d.ts +31 -5
- package/dist/components/ui/date-range-picker/index.d.ts +1 -1
- package/dist/components/ui/date-range-picker/index.js +1 -1
- package/dist/components/ui/date-range-picker/index.js.map +4 -4
- package/dist/components/ui/dialog/dialog.css +1 -1
- package/dist/components/ui/dialog/dialog.d.ts +30 -5
- package/dist/components/ui/dialog/dialog.script.d.ts +3 -0
- package/dist/components/ui/dialog/index.js +1 -1
- package/dist/components/ui/dialog/index.js.map +4 -4
- package/dist/components/ui/disclosure/disclosure-group.css +1 -1
- package/dist/components/ui/disclosure/disclosure-group.script.d.ts +6 -0
- package/dist/components/ui/disclosure/disclosure.d.ts +26 -7
- package/dist/components/ui/disclosure/disclosure.script.d.ts +5 -0
- package/dist/components/ui/disclosure/index.js +1 -1
- package/dist/components/ui/disclosure/index.js.map +4 -4
- package/dist/components/ui/feed/feed.d.ts +37 -7
- package/dist/components/ui/feed/index.js +1 -1
- package/dist/components/ui/feed/index.js.map +4 -4
- package/dist/components/ui/field/field-description.d.ts +5 -1
- package/dist/components/ui/field/field-error.d.ts +5 -0
- package/dist/components/ui/field/field.d.ts +8 -1
- package/dist/components/ui/field/field.script.d.ts +35 -0
- package/dist/components/ui/field/index.js +1 -1
- package/dist/components/ui/field/index.js.map +4 -4
- package/dist/components/ui/form/control-protocol.d.ts +6 -0
- package/dist/components/ui/form/form.d.ts +2 -1
- package/dist/components/ui/form/form.script.d.ts +16 -1
- package/dist/components/ui/form/index.d.ts +1 -1
- package/dist/components/ui/form/index.js +1 -1
- package/dist/components/ui/form/index.js.map +4 -4
- package/dist/components/ui/grid/grid.d.ts +12 -2
- package/dist/components/ui/grid/grid.script.d.ts +14 -0
- package/dist/components/ui/grid/index.js +1 -1
- package/dist/components/ui/grid/index.js.map +4 -4
- package/dist/components/ui/heading/heading.d.ts +26 -4
- package/dist/components/ui/heading/index.js +1 -1
- package/dist/components/ui/heading/index.js.map +4 -4
- package/dist/components/ui/headline/headline.d.ts +9 -1
- package/dist/components/ui/headline/index.js +1 -1
- package/dist/components/ui/headline/index.js.map +4 -4
- package/dist/components/ui/input/index.d.ts +1 -1
- package/dist/components/ui/input/index.js +1 -1
- package/dist/components/ui/input/index.js.map +4 -4
- package/dist/components/ui/input/input.css +2 -7
- package/dist/components/ui/input/input.d.ts +7 -2
- package/dist/components/ui/label/index.js +1 -1
- package/dist/components/ui/label/index.js.map +4 -4
- package/dist/components/ui/label/label.d.ts +8 -1
- package/dist/components/ui/listbox/index.js +1 -1
- package/dist/components/ui/listbox/index.js.map +4 -4
- package/dist/components/ui/listbox/listbox.css +2 -5
- package/dist/components/ui/listbox/listbox.d.ts +7 -3
- package/dist/components/ui/listbox/listbox.script.d.ts +14 -1
- package/dist/components/ui/menu-button/index.d.ts +1 -1
- package/dist/components/ui/menu-button/index.js +1 -1
- package/dist/components/ui/menu-button/index.js.map +4 -4
- package/dist/components/ui/menu-button/menu-button.css +2 -2
- package/dist/components/ui/menu-button/menu-button.d.ts +27 -5
- package/dist/components/ui/menu-button/menu-button.script.d.ts +8 -3
- package/dist/components/ui/menubar/index.js +1 -1
- package/dist/components/ui/menubar/index.js.map +4 -4
- package/dist/components/ui/menubar/menubar.css +4 -4
- package/dist/components/ui/menubar/menubar.d.ts +14 -2
- package/dist/components/ui/menubar/menubar.script.d.ts +10 -1
- package/dist/components/ui/meter/index.js +1 -1
- package/dist/components/ui/meter/index.js.map +4 -4
- package/dist/components/ui/meter/meter.css +1 -1
- package/dist/components/ui/meter/meter.d.ts +7 -2
- package/dist/components/ui/meter/meter.script.d.ts +21 -0
- package/dist/components/ui/navigation-menu/index.js +1 -1
- package/dist/components/ui/navigation-menu/index.js.map +4 -4
- package/dist/components/ui/navigation-menu/navigation-menu.css +2 -2
- package/dist/components/ui/navigation-menu/navigation-menu.d.ts +3 -2
- package/dist/components/ui/navigation-menu/navigation-menu.script.d.ts +4 -0
- package/dist/components/ui/number-field/index.d.ts +1 -1
- package/dist/components/ui/number-field/index.js +1 -1
- package/dist/components/ui/number-field/index.js.map +4 -4
- package/dist/components/ui/number-field/number-field.css +18 -3
- package/dist/components/ui/number-field/number-field.d.ts +36 -8
- package/dist/components/ui/number-field/number-field.script.d.ts +28 -1
- package/dist/components/ui/popover/index.js +1 -1
- package/dist/components/ui/popover/index.js.map +4 -4
- package/dist/components/ui/popover/popover.d.ts +5 -4
- package/dist/components/ui/popover/popover.script.d.ts +4 -0
- package/dist/components/ui/radio-group/index.d.ts +1 -1
- package/dist/components/ui/radio-group/index.js +1 -1
- package/dist/components/ui/radio-group/index.js.map +4 -4
- package/dist/components/ui/radio-group/radio-group.d.ts +29 -4
- package/dist/components/ui/radio-group/radio-group.script.d.ts +14 -9
- package/dist/components/ui/select/index.js +1 -1
- package/dist/components/ui/select/index.js.map +4 -4
- package/dist/components/ui/select/select.css +48 -6
- package/dist/components/ui/select/select.d.ts +29 -8
- package/dist/components/ui/select/select.script.d.ts +7 -0
- package/dist/components/ui/sidebar/index.js +1 -1
- package/dist/components/ui/sidebar/index.js.map +4 -4
- package/dist/components/ui/sidebar/sidebar-trigger.script.d.ts +4 -0
- package/dist/components/ui/sidebar/sidebar.css +41 -24
- package/dist/components/ui/sidebar/sidebar.d.ts +68 -14
- package/dist/components/ui/sidebar/sidebar.docs.css +5 -2
- package/dist/components/ui/sidebar/sidebar.script.d.ts +9 -0
- package/dist/components/ui/slider/index.js +1 -1
- package/dist/components/ui/slider/index.js.map +4 -4
- package/dist/components/ui/slider/slider.d.ts +2 -1
- package/dist/components/ui/slider/slider.script.d.ts +29 -1
- package/dist/components/ui/switch/index.js +1 -1
- package/dist/components/ui/switch/index.js.map +4 -4
- package/dist/components/ui/switch/switch.css +3 -3
- package/dist/components/ui/switch/switch.d.ts +11 -2
- package/dist/components/ui/switch/switch.script.d.ts +5 -0
- package/dist/components/ui/tabs/index.js +1 -1
- package/dist/components/ui/tabs/index.js.map +4 -4
- package/dist/components/ui/tabs/tabs.css +9 -10
- package/dist/components/ui/tabs/tabs.d.ts +30 -9
- package/dist/components/ui/tag-group/index.js +1 -1
- package/dist/components/ui/tag-group/index.js.map +4 -4
- package/dist/components/ui/tag-group/tag-group.css +2 -11
- package/dist/components/ui/tag-group/tag-group.d.ts +18 -5
- package/dist/components/ui/tag-group/tag-group.script.d.ts +9 -2
- package/dist/components/ui/textarea/index.d.ts +1 -1
- package/dist/components/ui/textarea/index.js +1 -1
- package/dist/components/ui/textarea/index.js.map +4 -4
- package/dist/components/ui/textarea/textarea.d.ts +7 -2
- package/dist/components/ui/toast/index.d.ts +1 -1
- package/dist/components/ui/toast/index.js +1 -1
- package/dist/components/ui/toast/index.js.map +4 -4
- package/dist/components/ui/toast/stack-layout.d.ts +18 -0
- package/dist/components/ui/toast/toast-context.d.ts +10 -0
- package/dist/components/ui/toast/toast.css +30 -9
- package/dist/components/ui/toast/toast.d.ts +12 -2
- package/dist/components/ui/toast/toast.script.d.ts +60 -4
- package/dist/components/ui/toast/toaster.script.d.ts +71 -2
- package/dist/components/ui/toc/index.js +1 -1
- package/dist/components/ui/toc/index.js.map +4 -4
- package/dist/components/ui/toc/toc.css +3 -0
- package/dist/components/ui/toc/toc.d.ts +2 -1
- package/dist/components/ui/toc/toc.script.d.ts +15 -0
- package/dist/components/ui/toolbar/index.js +1 -1
- package/dist/components/ui/toolbar/index.js.map +4 -4
- package/dist/components/ui/toolbar/toolbar.d.ts +3 -2
- package/dist/components/ui/toolbar/toolbar.script.d.ts +8 -0
- package/dist/components/ui/tooltip/index.js +1 -1
- package/dist/components/ui/tooltip/index.js.map +4 -4
- package/dist/components/ui/tooltip/tooltip.d.ts +3 -2
- package/dist/components/ui/tooltip/tooltip.script.d.ts +3 -0
- package/dist/components/ui/tree/index.js +1 -1
- package/dist/components/ui/tree/index.js.map +4 -4
- package/dist/components/ui/tree/tree.d.ts +12 -2
- package/dist/components/ui/tree/tree.script.d.ts +18 -1
- package/dist/components/ui/treegrid/index.js +1 -1
- package/dist/components/ui/treegrid/index.js.map +4 -4
- package/dist/components/ui/treegrid/treegrid.d.ts +15 -2
- package/dist/components/ui/treegrid/treegrid.script.d.ts +22 -1
- package/dist/components/ui/window-splitter/index.js +1 -1
- package/dist/components/ui/window-splitter/index.js.map +4 -4
- package/dist/components/ui/window-splitter/window-splitter.css +1 -1
- package/dist/components/ui/window-splitter/window-splitter.d.ts +3 -2
- package/dist/components/ui/window-splitter/window-splitter.script.d.ts +22 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/lib/cycle-value.d.ts +8 -0
- package/dist/lib/intl-number/range.d.ts +8 -0
- package/dist/styles/radiant-ui-core.css +110 -341
- package/dist/styles/radiant-ui.css +413 -377
- package/dist/styles/styles.css +839 -2731
- package/dist/styles/tailwind.css +626 -530
- package/dist/styles/tokens/colors/aurora.css +2 -2
- package/dist/styles/tokens/colors/basalt.css +2 -1
- package/dist/styles/tokens/colors/glacier.css +2 -1
- package/dist/styles/tokens/presets/colors/aurora.css +42 -14
- package/dist/styles/tokens/presets/colors/basalt.css +28 -0
- package/dist/styles/tokens/presets/colors/ember.css +28 -0
- package/dist/styles/tokens/presets/colors/glacier.css +28 -0
- package/dist/styles/tokens/semantic.css +22 -2
- package/dist/styles/tokens/spacing/compact.css +12 -12
- package/package.json +21 -8
- package/dist/components/ui/dialog/dialog-registry.test.d.ts +0 -1
- package/dist/components/ui/field/field-ssr-hydration.test.d.ts +0 -1
- package/dist/components/ui/form/form-field.test.d.ts +0 -4
- package/dist/components/ui/form/form-store.test.d.ts +0 -1
- package/dist/components/ui/shared/collection-navigation.test.d.ts +0 -1
- package/dist/components/ui/shared/floating-position.test.d.ts +0 -1
- package/dist/components/ui/shared/listbox-popover-behavior.test.d.ts +0 -1
- package/dist/components/ui/shared/popover-controller.test.d.ts +0 -1
- package/dist/components/ui/shared/portal.test.d.ts +0 -1
- package/dist/components/ui/sidebar/sidebar.ssr.test.d.ts +0 -2
- package/dist/components/ui/sidebar/sidebar.test.d.ts +0 -1
- package/dist/components/ui/toast/toast.test.d.ts +0 -2
- package/dist/components/ui/toc/toc-helpers.test.d.ts +0 -1
- package/dist/components/ui/toc/toc.ssr.test.d.ts +0 -1
- package/dist/components/ui/toc/toc.test.d.ts +0 -1
- package/dist/lib/intl-date/parts.test.d.ts +0 -1
- package/dist/lib/intl-date/segments.test.d.ts +0 -1
- package/dist/lib/intl-date/selection.test.d.ts +0 -1
- package/dist/lib/mask/date-mask.test.d.ts +0 -1
- package/dist/lib/mask/input-mask.test.d.ts +0 -1
- package/dist/lib/radiant-view.d.ts +0 -43
- package/dist/lib/text-filter.test.d.ts +0 -1
- package/dist/styles/tokens/presets/radius.css +0 -45
- package/dist/styles/tokens/presets/spacing.css +0 -57
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import{jsx as f}from"@ecopages/jsx/jsx-runtime";function r(...e){return e.filter(Boolean).join(" ")}var t="data-rui-control";var l=new Set(["rui-combobox","rui-date-field","rui-date-range-picker","rui-select","rui-tag-group","rui-checkbox","rui-switch","rui-radio-group","rui-slider","rui-number-field","rui-listbox"]),s=`[${t}], ${Array.from(l).join(", ")}`;function c(e){let{size:i="md",class:n,rows:u=3,...a}=e;return f("textarea",{...a,rows:u,[t]:"","data-rui-control-type":"text",class:r("rui-textarea",`rui-textarea--${i}`,n)})}export{c as RuiTextarea};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/components/ui/textarea/textarea.tsx", "../../../../src/lib/cx.ts", "../../../../src/
|
|
4
|
-
"sourcesContent": ["import { jsx } from \"@ecopages/jsx/jsx-runtime\";\nimport { cx } from \"@/lib/cx\";\nimport { attachRadiantStylesheets } from \"@/lib/radiant-view\";\nimport { RUI_CONTROL_ATTR } from \"../form/control-protocol\";\nexport function RuiTextarea(props) {\n const {\n size = \"md\",\n class: className,\n rows = 3,\n ...host\n } = props;\n return /* @__PURE__ */jsx(\"textarea\", {\n ...host,\n rows,\n ...{\n [RUI_CONTROL_ATTR]: \"\"\n },\n \"data-rui-control-type\": \"text\",\n class: cx(\"rui-textarea\", `rui-textarea--${size}`, className)\n });\n}\nattachRadiantStylesheets(RuiTextarea, [\"./textarea.css\"], import.meta.url);", "export function cx(...parts) {\n return parts.filter(Boolean).join(\" \");\n}", "const RADIANT_VIEW_ELEMENT = /* @__PURE__ */Symbol.for(\"@ecopages/storybook-radiant.viewElement\");\nconst RADIANT_SCRIPT_MODULE = /* @__PURE__ */Symbol.for(\"@ecopages/storybook-radiant.scriptModule\");\nconst RADIANT_SCRIPT_EXPORT = /* @__PURE__ */Symbol.for(\"@ecopages/storybook-radiant.scriptExport\");\nconst RADIANT_VIEW_MODULE = /* @__PURE__ */Symbol.for(\"@ecopages/storybook-radiant.viewModule\");\nfunction linkViewToElement(view, element) {\n view[RADIANT_VIEW_ELEMENT] = element;\n const ssrModule = element[RADIANT_SCRIPT_MODULE];\n if (ssrModule) {\n view[RADIANT_SCRIPT_MODULE] = ssrModule;\n view[RADIANT_SCRIPT_EXPORT] = element[RADIANT_SCRIPT_EXPORT] ?? element.name;\n }\n}\nexport function defineRadiantView(element, render, _options) {\n const view = args => render(args);\n linkViewToElement(view, element);\n return view;\n}\nexport function attachRadiantStylesheets(target, _stylesheets, moduleUrl) {\n const view = target;\n view[RADIANT_VIEW_MODULE] = moduleUrl;\n return target;\n}\nexport function syncRadiantViewMetadata(view) {\n const element = view[RADIANT_VIEW_ELEMENT];\n if (element) {\n linkViewToElement(view, element);\n }\n}", "export const RUI_CONTROL_ATTR = \"data-rui-control\";\nexport const RUI_FIELD_MANAGED_ATTR = \"data-rui-field-managed\";\nexport const RUI_FIELD_LABEL_ATTR = \"data-rui-field-label\";\nexport const RUI_FIELD_DESCRIPTION_ATTR = \"data-rui-field-description\";\nexport const RUI_FIELD_ERROR_ATTR = \"data-rui-field-error\";\nexport const RUI_FIELD_DEFAULT_VALUE_ATTR = \"data-default-value\";\nexport const RUI_FORM_DEFAULT_VALUES_ATTR = \"data-default-values\";\nconst HOST_CONTROL_TAGS = /* @__PURE__ */new Set([\"rui-combobox\", \"rui-date-field\", \"rui-date-range-picker\", \"rui-select\", \"rui-tag-group\", \"rui-checkbox\", \"rui-switch\", \"rui-radio-group\", \"rui-slider\", \"rui-number-field\", \"rui-listbox\"]);\nconst CONTROL_SELECTOR = `[${RUI_CONTROL_ATTR}], ${Array.from(HOST_CONTROL_TAGS).join(\", \")}, input, textarea`;\nconst stringValueAdapter = {\n read: host => {\n const value = Reflect.get(host, \"value\");\n return typeof value === \"string\" ? value : host.getAttribute(\"value\") ?? \"\";\n },\n write: (host, value) => {\n const next = value == null ? \"\" : String(value);\n host.setAttribute(\"value\", next);\n if (\"value\" in host) {\n Reflect.set(host, \"value\", next);\n }\n }\n};\nconst numberValueAdapter = {\n read: host => {\n const value = Reflect.get(host, \"value\");\n if (typeof value === \"number\") {\n return value;\n }\n const raw = host.getAttribute(\"value\");\n return raw == null || raw === \"\" ? \"\" : Number(raw);\n },\n write: (host, value) => {\n const next = value == null ? \"\" : String(value);\n host.setAttribute(\"value\", next);\n if (\"value\" in host) {\n Reflect.set(host, \"value\", value);\n }\n }\n};\nconst booleanValueAdapter = {\n read: host => {\n const input = host.querySelector('input[type=\"checkbox\"]');\n return input?.checked ?? host.hasAttribute(\"checked\");\n },\n write: (host, value) => {\n if (value) {\n host.setAttribute(\"checked\", \"\");\n } else {\n host.removeAttribute(\"checked\");\n }\n }\n};\nconst CONTROL_VALUE_ADAPTERS = /* @__PURE__ */new Map([[\"rui-checkbox\", booleanValueAdapter], [\"rui-switch\", booleanValueAdapter], [\"rui-combobox\", stringValueAdapter], [\"rui-date-field\", stringValueAdapter], [\"rui-date-range-picker\", stringValueAdapter], [\"rui-select\", stringValueAdapter], [\"rui-radio-group\", stringValueAdapter], [\"rui-listbox\", stringValueAdapter], [\"rui-tag-group\", stringValueAdapter], [\"rui-slider\", numberValueAdapter], [\"rui-number-field\", numberValueAdapter]]);\nfunction forEachFieldContentNode(root, visit) {\n const slotHost = root;\n const visited = /* @__PURE__ */new Set();\n const safeVisit = node => {\n if (visited.has(node)) {\n return;\n }\n visited.add(node);\n visit(node);\n };\n if (typeof slotHost.getSlotElements === \"function\") {\n for (const node of slotHost.getSlotElements()) {\n safeVisit(node);\n }\n }\n const renderRoot = root.querySelector(\".rui-field\") ?? root;\n for (const child of Array.from(renderRoot.children)) {\n safeVisit(child);\n }\n for (const node of renderRoot.querySelectorAll(\"*\")) {\n safeVisit(node);\n }\n for (const child of Array.from(root.children)) {\n safeVisit(child);\n }\n const shadow = root.shadowRoot;\n if (shadow) {\n for (const child of Array.from(shadow.children)) {\n safeVisit(child);\n }\n }\n}\nfunction queryFieldContent(root, selector) {\n let found = null;\n forEachFieldContentNode(root, node => {\n if (found || !(node instanceof HTMLElement)) {\n return;\n }\n if (node.matches(selector)) {\n found = node;\n return;\n }\n found = node.querySelector(selector);\n });\n return found;\n}\nfunction pickPrimaryFieldControl(candidates) {\n if (candidates.length === 0) {\n return null;\n }\n if (candidates.length === 1) {\n return candidates[0];\n }\n const hostControl = candidates.find(candidate => HOST_CONTROL_TAGS.has(candidate.localName));\n const markedControl = candidates.find(candidate => candidate.hasAttribute(RUI_CONTROL_ATTR));\n if (markedControl) {\n return markedControl;\n }\n if (hostControl) {\n return hostControl;\n }\n const active = document.activeElement;\n if (active instanceof HTMLElement) {\n for (const candidate of candidates) {\n if (candidate === active || candidate.contains(active)) {\n return candidate;\n }\n }\n }\n const visible = candidates.filter(el => el.isConnected && el.getClientRects().length > 0 && !el.closest('[hidden],[aria-hidden=\"true\"]'));\n const pool = visible.length > 0 ? visible : candidates.filter(el => el.isConnected);\n return pool[pool.length - 1] ?? candidates[candidates.length - 1];\n}\nfunction listFieldControlsInRenderTree(root) {\n const renderRoot = root.querySelector(\".rui-field\");\n if (!(renderRoot instanceof HTMLElement)) {\n return [];\n }\n return Array.from(renderRoot.querySelectorAll(CONTROL_SELECTOR)).filter(el => root.contains(el));\n}\nexport function findFieldControl(root) {\n const fromRenderTree = pickPrimaryFieldControl(listFieldControlsInRenderTree(root));\n if (fromRenderTree) {\n return fromRenderTree;\n }\n let found = null;\n forEachFieldContentNode(root, node => {\n if (found) {\n return;\n }\n const match = findControlInSubtree(node);\n if (match) {\n found = match;\n }\n });\n if (found) {\n return found;\n }\n const renderRoot = root.querySelector(\".rui-field\") ?? root;\n return findControlInSubtree(renderRoot);\n}\nfunction findControlInSubtree(node) {\n if (!(node instanceof HTMLElement)) {\n return null;\n }\n if (node.matches(`[${RUI_CONTROL_ATTR}]`)) {\n return node;\n }\n if (HOST_CONTROL_TAGS.has(node.localName)) {\n return node;\n }\n if (node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement) {\n return node;\n }\n const nested = node.querySelector(CONTROL_SELECTOR);\n return nested;\n}\nexport function readControlValue(control) {\n if (control instanceof HTMLInputElement) {\n const host2 = resolveControlHost(control);\n const adapter = host2 === control ? void 0 : CONTROL_VALUE_ADAPTERS.get(host2.localName);\n if (adapter) {\n return adapter.read(host2);\n }\n if (control.type === \"checkbox\") {\n return control.checked;\n }\n if (control.type === \"number\" || control.type === \"range\") {\n return control.value === \"\" ? \"\" : Number(control.value);\n }\n return control.value;\n }\n if (control instanceof HTMLTextAreaElement) {\n return control.value;\n }\n const host = resolveControlHost(control);\n return CONTROL_VALUE_ADAPTERS.get(host.localName)?.read(host) ?? host.getAttribute(\"value\") ?? \"\";\n}\nexport function writeControlValue(control, value) {\n if (control instanceof HTMLInputElement) {\n const host2 = resolveControlHost(control);\n const adapter = host2 === control ? void 0 : CONTROL_VALUE_ADAPTERS.get(host2.localName);\n if (adapter) {\n adapter.write(host2, value);\n return;\n }\n if (control.type === \"checkbox\") {\n control.checked = Boolean(value);\n const ce = control.closest(\"rui-checkbox, rui-switch\");\n if (ce) {\n if (value) {\n ce.setAttribute(\"checked\", \"\");\n } else {\n ce.removeAttribute(\"checked\");\n }\n }\n return;\n }\n control.value = value == null ? \"\" : String(value);\n return;\n }\n if (control instanceof HTMLTextAreaElement) {\n control.value = value == null ? \"\" : String(value);\n return;\n }\n const host = resolveControlHost(control);\n CONTROL_VALUE_ADAPTERS.get(host.localName)?.write(host, value);\n}\nfunction resolveControlHost(control) {\n if (control.hasAttribute(RUI_CONTROL_ATTR)) {\n const host = control.closest(Array.from(HOST_CONTROL_TAGS).join(\",\"));\n return host ?? control;\n }\n return control;\n}\nexport function findFieldLabel(root) {\n return queryFieldContent(root, `[${RUI_FIELD_LABEL_ATTR}], label.rui-label`);\n}\nexport function findFieldDescription(root) {\n return queryFieldContent(root, `[${RUI_FIELD_DESCRIPTION_ATTR}]`);\n}\nexport function findFieldError(root) {\n const all = findFieldErrorElements(root);\n return all[0] ?? null;\n}\nexport function findFieldErrorElements(root) {\n const renderRoot = root.querySelector(\".rui-field\");\n if (renderRoot instanceof HTMLElement) {\n const inRender = Array.from(renderRoot.querySelectorAll(`[${RUI_FIELD_ERROR_ATTR}]`));\n const visible = inRender.filter(el => el.getClientRects().length > 0);\n if (visible.length > 0) {\n return visible;\n }\n if (inRender.length > 0) {\n return inRender;\n }\n }\n const fromDom = Array.from(root.querySelectorAll(`[${RUI_FIELD_ERROR_ATTR}]`));\n if (fromDom.length > 0) {\n return fromDom;\n }\n const single = queryFieldContent(root, `[${RUI_FIELD_ERROR_ATTR}]`);\n return single ? [single] : [];\n}\nexport function wireFieldControlName(controlHost, ariaTarget, name) {\n if (!name) {\n return;\n }\n if (ariaTarget instanceof HTMLInputElement || ariaTarget instanceof HTMLTextAreaElement) {\n ariaTarget.name = name;\n }\n if (!controlHost) {\n return;\n }\n if (controlHost === ariaTarget) {\n return;\n }\n if (HOST_CONTROL_TAGS.has(controlHost.localName)) {\n controlHost.setAttribute(\"name\", name);\n }\n}\nexport function getAriaControlTarget(control) {\n if (control instanceof HTMLInputElement || control instanceof HTMLTextAreaElement) {\n return control;\n }\n if (control.hasAttribute(RUI_CONTROL_ATTR)) {\n return control;\n }\n const marked = control.querySelector(`[${RUI_CONTROL_ATTR}]`);\n if (marked) {\n return marked;\n }\n if (control.localName === \"rui-combobox\") {\n return control.querySelector(\"[data-combobox-input]\") ?? control;\n }\n if (control.localName === \"rui-date-field\") {\n return control.querySelector(\"[data-date-field-input]\") ?? control;\n }\n if (control.localName === \"rui-date-range-picker\") {\n return control.querySelector(\"[data-range-start]\") ?? control;\n }\n if (control.localName === \"rui-select\") {\n return control.querySelector(\"[data-select-trigger]\") ?? control;\n }\n if (control.localName === \"rui-tag-group\") {\n return control.querySelector(\"[data-tag-list]\") ?? control;\n }\n if (control.localName === \"rui-number-field\") {\n return control.querySelector(\"[data-number-field-input], input\") ?? control;\n }\n if (control.localName === \"rui-slider\") {\n return control.querySelector('input[type=\"range\"]') ?? control;\n }\n if (control.localName === \"rui-checkbox\" || control.localName === \"rui-switch\") {\n return control.querySelector(\"input\") ?? control;\n }\n if (control.localName === \"rui-radio-group\") {\n const checked = control.querySelector('input[type=\"radio\"]:checked');\n const first = control.querySelector('input[type=\"radio\"]');\n return checked ?? first ?? control;\n }\n return control;\n}"],
|
|
5
|
-
"mappings": "AAAA,OAAS,OAAAA,MAAW,4BCAb,SAASC,KAAMC,EAAO,CAC3B,OAAOA,EAAM,OAAO,OAAO,EAAE,KAAK,GAAG,CACvC,
|
|
6
|
-
"names": ["jsx", "cx", "parts", "
|
|
3
|
+
"sources": ["../../../../src/components/ui/textarea/textarea.tsx", "../../../../src/lib/cx.ts", "../../../../src/components/ui/form/control-protocol.ts"],
|
|
4
|
+
"sourcesContent": ["import { jsx } from \"@ecopages/jsx/jsx-runtime\";\nimport { cx } from \"@/lib/cx\";\nimport { RUI_CONTROL_ATTR } from \"../form/control-protocol\";\nexport function RuiTextarea(props) {\n const {\n size = \"md\",\n class: className,\n rows = 3,\n ...host\n } = props;\n return /* @__PURE__ */jsx(\"textarea\", {\n ...host,\n rows,\n ...{\n [RUI_CONTROL_ATTR]: \"\"\n },\n \"data-rui-control-type\": \"text\",\n class: cx(\"rui-textarea\", `rui-textarea--${size}`, className)\n });\n}", "export function cx(...parts) {\n return parts.filter(Boolean).join(\" \");\n}", "export const RUI_CONTROL_ATTR = \"data-rui-control\";\nexport const RUI_FIELD_MANAGED_ATTR = \"data-rui-field-managed\";\nexport const RUI_FIELD_LABEL_ATTR = \"data-rui-field-label\";\nexport const RUI_FIELD_DESCRIPTION_ATTR = \"data-rui-field-description\";\nexport const RUI_FIELD_ERROR_ATTR = \"data-rui-field-error\";\nexport const RUI_FIELD_DEFAULT_VALUE_ATTR = \"data-default-value\";\nexport const RUI_FORM_DEFAULT_VALUES_ATTR = \"data-default-values\";\nconst HOST_CONTROL_TAGS = /* @__PURE__ */new Set([\"rui-combobox\", \"rui-date-field\", \"rui-date-range-picker\", \"rui-select\", \"rui-tag-group\", \"rui-checkbox\", \"rui-switch\", \"rui-radio-group\", \"rui-slider\", \"rui-number-field\", \"rui-listbox\"]);\nconst CONTROL_SELECTOR = `[${RUI_CONTROL_ATTR}], ${Array.from(HOST_CONTROL_TAGS).join(\", \")}`;\nexport function isNativeTextControl(node) {\n return node.localName === \"input\" || node.localName === \"textarea\";\n}\nfunction isNativeInput(node) {\n return node.localName === \"input\";\n}\nfunction isNativeTextarea(node) {\n return node.localName === \"textarea\";\n}\nconst stringValueAdapter = {\n read: host => {\n const value = Reflect.get(host, \"value\");\n return typeof value === \"string\" ? value : host.getAttribute(\"value\") ?? \"\";\n },\n write: (host, value) => {\n const next = value == null ? \"\" : String(value);\n host.setAttribute(\"value\", next);\n if (\"value\" in host) {\n Reflect.set(host, \"value\", next);\n }\n }\n};\nconst numberValueAdapter = {\n read: host => {\n const value = Reflect.get(host, \"value\");\n if (typeof value === \"number\") {\n return value;\n }\n const raw = host.getAttribute(\"value\");\n return raw == null || raw === \"\" ? \"\" : Number(raw);\n },\n write: (host, value) => {\n const next = value == null ? \"\" : String(value);\n host.setAttribute(\"value\", next);\n if (\"value\" in host) {\n Reflect.set(host, \"value\", value);\n }\n }\n};\nconst booleanValueAdapter = {\n read: host => {\n const input = host.querySelector('input[type=\"checkbox\"]');\n return input?.checked ?? host.hasAttribute(\"checked\");\n },\n write: (host, value) => {\n if (value) {\n host.setAttribute(\"checked\", \"\");\n } else {\n host.removeAttribute(\"checked\");\n }\n }\n};\nconst CONTROL_VALUE_ADAPTERS = /* @__PURE__ */new Map([[\"rui-checkbox\", booleanValueAdapter], [\"rui-switch\", booleanValueAdapter], [\"rui-combobox\", stringValueAdapter], [\"rui-date-field\", stringValueAdapter], [\"rui-date-range-picker\", stringValueAdapter], [\"rui-select\", stringValueAdapter], [\"rui-radio-group\", stringValueAdapter], [\"rui-listbox\", stringValueAdapter], [\"rui-tag-group\", stringValueAdapter], [\"rui-slider\", numberValueAdapter], [\"rui-number-field\", numberValueAdapter]]);\nfunction forEachFieldContentNode(root, visit) {\n const slotHost = root;\n const visited = /* @__PURE__ */new Set();\n const safeVisit = node => {\n if (visited.has(node)) {\n return;\n }\n visited.add(node);\n visit(node);\n };\n if (typeof slotHost.getSlotElements === \"function\") {\n for (const node of slotHost.getSlotElements()) {\n safeVisit(node);\n }\n }\n const renderRoot = root.querySelector(\".rui-field\") ?? root;\n for (const child of Array.from(renderRoot.children)) {\n safeVisit(child);\n }\n for (const node of renderRoot.querySelectorAll(\"*\")) {\n safeVisit(node);\n }\n for (const child of Array.from(root.children)) {\n safeVisit(child);\n }\n const shadow = root.shadowRoot;\n if (shadow) {\n for (const child of Array.from(shadow.children)) {\n safeVisit(child);\n }\n }\n}\nfunction queryFieldContent(root, selector) {\n let found = null;\n forEachFieldContentNode(root, node => {\n if (found || !(node instanceof HTMLElement)) {\n return;\n }\n if (node.matches(selector)) {\n found = node;\n return;\n }\n found = node.querySelector(selector);\n });\n return found;\n}\nfunction pickPrimaryFieldControl(candidates) {\n if (candidates.length === 0) {\n return null;\n }\n if (candidates.length === 1) {\n return candidates[0];\n }\n const hostControl = candidates.find(candidate => HOST_CONTROL_TAGS.has(candidate.localName));\n const markedControl = candidates.find(candidate => candidate.hasAttribute(RUI_CONTROL_ATTR));\n if (markedControl) {\n return markedControl;\n }\n if (hostControl) {\n return hostControl;\n }\n const active = document.activeElement;\n if (active instanceof HTMLElement) {\n for (const candidate of candidates) {\n if (candidate === active || candidate.contains(active)) {\n return candidate;\n }\n }\n }\n const visible = candidates.filter(el => el.isConnected && el.getClientRects().length > 0 && !el.closest('[hidden],[aria-hidden=\"true\"]'));\n const pool = visible.length > 0 ? visible : candidates.filter(el => el.isConnected);\n return pool[pool.length - 1] ?? candidates[candidates.length - 1];\n}\nfunction listFieldControlsInRenderTree(root) {\n const renderRoot = root.querySelector(\".rui-field\");\n if (!(renderRoot instanceof HTMLElement)) {\n return [];\n }\n return Array.from(renderRoot.querySelectorAll(CONTROL_SELECTOR)).filter(el => root.contains(el));\n}\nexport function findFieldControl(root) {\n const fromRenderTree = pickPrimaryFieldControl(listFieldControlsInRenderTree(root));\n if (fromRenderTree) {\n return fromRenderTree;\n }\n let found = null;\n forEachFieldContentNode(root, node => {\n if (found) {\n return;\n }\n const match = findControlInSubtree(node);\n if (match) {\n found = match;\n }\n });\n if (found) {\n return found;\n }\n const renderRoot = root.querySelector(\".rui-field\") ?? root;\n return findControlInSubtree(renderRoot);\n}\nfunction findControlInSubtree(node) {\n if (!(node instanceof HTMLElement)) {\n return null;\n }\n if (node.matches(`[${RUI_CONTROL_ATTR}]`) || HOST_CONTROL_TAGS.has(node.localName)) {\n return node;\n }\n return node.querySelector(CONTROL_SELECTOR);\n}\nexport function readControlValue(control) {\n if (isNativeInput(control)) {\n const host2 = resolveControlHost(control);\n const adapter = host2 === control ? void 0 : CONTROL_VALUE_ADAPTERS.get(host2.localName);\n if (adapter) {\n return adapter.read(host2);\n }\n if (control.type === \"checkbox\") {\n return control.checked;\n }\n if (control.type === \"number\" || control.type === \"range\") {\n return control.value === \"\" ? \"\" : Number(control.value);\n }\n return control.value;\n }\n if (isNativeTextarea(control)) {\n return control.value;\n }\n const host = resolveControlHost(control);\n return CONTROL_VALUE_ADAPTERS.get(host.localName)?.read(host) ?? host.getAttribute(\"value\") ?? \"\";\n}\nexport function writeControlValue(control, value) {\n if (isNativeInput(control)) {\n const host2 = resolveControlHost(control);\n const adapter = host2 === control ? void 0 : CONTROL_VALUE_ADAPTERS.get(host2.localName);\n if (adapter) {\n adapter.write(host2, value);\n return;\n }\n if (control.type === \"checkbox\") {\n control.checked = Boolean(value);\n const ce = control.closest(\"rui-checkbox, rui-switch\");\n if (ce) {\n if (value) {\n ce.setAttribute(\"checked\", \"\");\n } else {\n ce.removeAttribute(\"checked\");\n }\n }\n return;\n }\n control.value = value == null ? \"\" : String(value);\n return;\n }\n if (isNativeTextarea(control)) {\n control.value = value == null ? \"\" : String(value);\n return;\n }\n const host = resolveControlHost(control);\n CONTROL_VALUE_ADAPTERS.get(host.localName)?.write(host, value);\n}\nfunction resolveControlHost(control) {\n if (control.hasAttribute(RUI_CONTROL_ATTR)) {\n const host = control.closest(Array.from(HOST_CONTROL_TAGS).join(\",\"));\n return host ?? control;\n }\n return control;\n}\nexport function findFieldLabel(root) {\n return queryFieldContent(root, `[${RUI_FIELD_LABEL_ATTR}], label.rui-label`);\n}\nexport function findFieldDescription(root) {\n return queryFieldContent(root, `[${RUI_FIELD_DESCRIPTION_ATTR}]`);\n}\nexport function findFieldError(root) {\n const all = findFieldErrorElements(root);\n return all[0] ?? null;\n}\nexport function findFieldErrorElements(root) {\n const renderRoot = root.querySelector(\".rui-field\");\n if (renderRoot instanceof HTMLElement) {\n const inRender = Array.from(renderRoot.querySelectorAll(`[${RUI_FIELD_ERROR_ATTR}]`));\n const visible = inRender.filter(el => el.getClientRects().length > 0);\n if (visible.length > 0) {\n return visible;\n }\n if (inRender.length > 0) {\n return inRender;\n }\n }\n const fromDom = Array.from(root.querySelectorAll(`[${RUI_FIELD_ERROR_ATTR}]`));\n if (fromDom.length > 0) {\n return fromDom;\n }\n const single = queryFieldContent(root, `[${RUI_FIELD_ERROR_ATTR}]`);\n return single ? [single] : [];\n}\nexport function wireFieldControlName(controlHost, ariaTarget, name) {\n if (!name) {\n return;\n }\n if (ariaTarget && isNativeTextControl(ariaTarget)) {\n ariaTarget.name = name;\n }\n if (!controlHost) {\n return;\n }\n if (controlHost === ariaTarget) {\n return;\n }\n if (HOST_CONTROL_TAGS.has(controlHost.localName)) {\n controlHost.setAttribute(\"name\", name);\n }\n}\nfunction isChecked(input) {\n const checked = Reflect.get(input, \"checked\");\n return typeof checked === \"boolean\" ? checked : input.hasAttribute(\"checked\");\n}\nexport function getAriaControlTarget(control) {\n if (isNativeTextControl(control)) {\n return control;\n }\n if (control.hasAttribute(RUI_CONTROL_ATTR)) {\n return control;\n }\n const marked = control.querySelector(`[${RUI_CONTROL_ATTR}]`);\n if (marked) {\n return marked;\n }\n if (control.localName === \"rui-combobox\") {\n return control.querySelector(\"[data-combobox-input]\") ?? control;\n }\n if (control.localName === \"rui-date-field\") {\n return control.querySelector(\"[data-date-field-input]\") ?? control;\n }\n if (control.localName === \"rui-date-range-picker\") {\n return control.querySelector(\"[data-range-start]\") ?? control;\n }\n if (control.localName === \"rui-select\") {\n return control.querySelector(\"[data-select-trigger]\") ?? control;\n }\n if (control.localName === \"rui-tag-group\") {\n return control.querySelector(\"[data-tag-list]\") ?? control;\n }\n if (control.localName === \"rui-number-field\") {\n return control.querySelector(\"[data-number-field-input], input\") ?? control;\n }\n if (control.localName === \"rui-slider\") {\n return control.querySelector('input[type=\"range\"]') ?? control;\n }\n if (control.localName === \"rui-checkbox\" || control.localName === \"rui-switch\") {\n return control.querySelector(\"input\") ?? control;\n }\n if (control.localName === \"rui-radio-group\") {\n const radios = control.querySelectorAll('input[type=\"radio\"]');\n for (const radio of radios) {\n if (isChecked(radio)) {\n return radio;\n }\n }\n return radios[0] ?? control;\n }\n return control;\n}"],
|
|
5
|
+
"mappings": "AAAA,OAAS,OAAAA,MAAW,4BCAb,SAASC,KAAMC,EAAO,CAC3B,OAAOA,EAAM,OAAO,OAAO,EAAE,KAAK,GAAG,CACvC,CCFO,IAAMC,EAAmB,mBAOhC,IAAMC,EAAmC,IAAI,IAAI,CAAC,eAAgB,iBAAkB,wBAAyB,aAAc,gBAAiB,eAAgB,aAAc,kBAAmB,aAAc,mBAAoB,aAAa,CAAC,EACvOC,EAAmB,IAAIC,CAAgB,MAAM,MAAM,KAAKF,CAAiB,EAAE,KAAK,IAAI,CAAC,GFLpF,SAASG,EAAYC,EAAO,CACjC,GAAM,CACJ,KAAAC,EAAO,KACP,MAAOC,EACP,KAAAC,EAAO,EACP,GAAGC,CACL,EAAIJ,EACJ,OAAsBK,EAAI,WAAY,CACpC,GAAGD,EACH,KAAAD,EAEE,CAACG,CAAgB,EAAG,GAEtB,wBAAyB,OACzB,MAAOC,EAAG,eAAgB,iBAAiBN,CAAI,GAAIC,CAAS,CAC9D,CAAC,CACH",
|
|
6
|
+
"names": ["jsx", "cx", "parts", "RUI_CONTROL_ATTR", "HOST_CONTROL_TAGS", "CONTROL_SELECTOR", "RUI_CONTROL_ATTR", "RuiTextarea", "props", "size", "className", "rows", "host", "jsx", "RUI_CONTROL_ATTR", "cx"]
|
|
7
7
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { JsxHtmlProps } from '@ecopages/jsx';
|
|
2
|
-
|
|
2
|
+
export type RuiTextareaSize = 'sm' | 'md' | 'lg';
|
|
3
3
|
export type RuiTextareaProps = JsxHtmlProps<{
|
|
4
4
|
value?: string;
|
|
5
5
|
placeholder?: string;
|
|
6
6
|
disabled?: boolean;
|
|
7
7
|
name?: string;
|
|
8
8
|
rows?: number;
|
|
9
|
-
size?:
|
|
9
|
+
size?: RuiTextareaSize;
|
|
10
10
|
id?: string;
|
|
11
11
|
'aria-label'?: string;
|
|
12
12
|
'on:input'?: (event: Event) => void;
|
|
@@ -18,5 +18,10 @@ export type RuiTextareaProps = JsxHtmlProps<{
|
|
|
18
18
|
*
|
|
19
19
|
* No custom element — Field owns labeling, `aria-*`, and validation wiring.
|
|
20
20
|
* Marked with `data-rui-control` so `<rui-field>` can discover it.
|
|
21
|
+
*
|
|
22
|
+
* @cssclass rui-textarea - Bordered, resizable multi-line input.
|
|
23
|
+
* @cssclass rui-textarea--sm - Compact min-height.
|
|
24
|
+
* @cssclass rui-textarea--md - Default min-height.
|
|
25
|
+
* @cssclass rui-textarea--lg - Taller min-height.
|
|
21
26
|
*/
|
|
22
27
|
export declare function RuiTextarea(props: RuiTextareaProps): import("@ecopages/jsx").JsxRenderable;
|
|
@@ -2,4 +2,4 @@ export { RuiToast as RuiToastElement, type RuiToastProps } from './toast.script'
|
|
|
2
2
|
export { RuiToaster as RuiToasterElement, type RuiToasterProps } from './toaster.script';
|
|
3
3
|
export { RuiToast, RuiToaster, type RuiToastViewProps, type RuiToasterViewProps } from './toast';
|
|
4
4
|
export { toast, showToast, dismissToast, type ToastCallable } from './toast-api';
|
|
5
|
-
export { RUI_TOAST_SHOW_EVENT, RUI_TOAST_DISMISS_EVENT, TOAST_LIFETIME, TOAST_WIDTH, TOAST_GAP, TOAST_VIEWPORT_OFFSET, TOAST_VISIBLE_AMOUNT, TOAST_SWIPE_THRESHOLD, TOAST_EXIT_MS, DEFAULT_TOAST_POSITION, type ToastVariant, type ToastPosition, type ToastAction, type ToastId, type ToastOptions, type ToastRecord, type ToastDismissDetail, type ToastShowDetail, type PromiseToastMessages, } from './toast-context';
|
|
5
|
+
export { RUI_TOAST_SHOW_EVENT, RUI_TOAST_DISMISS_EVENT, TOAST_LIFETIME, TOAST_WIDTH, TOAST_GAP, TOAST_VIEWPORT_OFFSET, TOAST_VISIBLE_AMOUNT, TOAST_COLLAPSED_PEEK, TOAST_SWIPE_THRESHOLD, TOAST_EXIT_MS, DEFAULT_TOAST_POSITION, TOAST_POSITIONS, type ToastVariant, type ToastPosition, type ToastAction, type ToastId, type ToastOptions, type ToastRecord, type ToastDismissDetail, type ToastShowDetail, type PromiseToastMessages, } from './toast-context';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as z,jsxs as Qt}from"@ecopages/jsx/jsx-runtime";import{RadiantElement as Zt,bound as St,customElement as Me,onEvent as te,onUpdated as ht,prop as L,query as Ve}from"@ecopages/radiant";var at="rui-toast-show",ut="rui-toast-dismiss",ct=4e3,yt=356,vt=14,bt=24,Tt=3,lt=45,_t=200,dt="bottom-end";function Y(i){let[t,e]=i.split("-");return{y:t,x:e}}var Oe=1;function Ae(){return Oe++}function It(i,t){return typeof i=="function"?i(t):i}var gt=class{subscribers=[];toasts=[];subscribe=t=>(this.subscribers.push(t),t(this.toasts),()=>{let e=this.subscribers.indexOf(t);e>=0&&this.subscribers.splice(e,1)});getSnapshot=()=>this.toasts;publish(){let t=this.toasts;for(let e of this.subscribers)e(t)}create=(t,e={})=>{let o=e.id??Ae(),u=e.dismissible??!0,a=this.toasts.findIndex(s=>s.id===o),l={id:o,title:t,description:e.description,variant:e.variant??"default",duration:e.duration,action:e.action,dismissible:u,closeButton:e.closeButton,position:e.position,delete:!1};return a>=0?this.toasts=this.toasts.map(s=>s.id===o?{...s,...l,delete:!1}:s):this.toasts=[l,...this.toasts],this.publish(),o};dismiss=t=>{if(t==null){if(this.toasts.length===0)return;this.toasts=this.toasts.map(e=>({...e,delete:!0}))}else{let e=this.toasts.find(o=>o.id===t);if(!e||e.delete)return;this.toasts=this.toasts.map(o=>o.id===t?{...o,delete:!0}:o)}this.publish()};remove=t=>{this.toasts=this.toasts.filter(e=>e.id!==t),this.publish()};clear=()=>{this.toasts.length!==0&&(this.toasts=[],this.publish())};message=(t,e)=>this.create(t,e);success=(t,e)=>this.create(t,{...e,variant:"success"});error=(t,e)=>this.create(t,{...e,variant:"error"});info=(t,e)=>this.create(t,{...e,variant:"info"});warning=(t,e)=>this.create(t,{...e,variant:"warning"});loading=(t,e)=>this.create(t,{...e,variant:"loading",duration:e?.duration??Number.POSITIVE_INFINITY});promise=(t,e)=>{let o=this.loading(e.loading,{duration:Number.POSITIVE_INFINITY,action:e.action,closeButton:e.closeButton,position:e.position,description:typeof e.description=="string"?e.description:void 0});return(typeof t=="function"?t():t).then(a=>{let l=typeof e.description=="function"?e.description(a):e.description;this.create(It(e.success,a),{id:o,variant:"success",description:l,duration:e.duration,action:e.action,closeButton:e.closeButton,position:e.position})}).catch(a=>{let l=typeof e.description=="function"?e.description(a):e.description;this.create(It(e.error,a),{id:o,variant:"error",description:l,duration:e.duration,action:e.action,closeButton:e.closeButton,position:e.position})}),o}},g=new gt;var Ot,At,Pt,Dt,Rt,Lt,Mt,Vt,Ut,kt,Bt,Ct,jt,Ft,Nt,Ht,$t,qt,Wt,Yt,Xt,zt,Gt,Kt;function Pe(i,t,e,o,u,a){var l,s,y,A,h,m,I,C=Symbol.metadata||Symbol.for("Symbol.metadata"),j=Object.defineProperty,F=Object.create,G=[F(null),F(null)],K=t.length;function M(n,T,v){return function(r,c){T&&(c=r,r=i);for(var _=0;_<n.length;_++)c=n[_].apply(r,v?[c]:[]);return v?c:r}}function w(n,T,v,r){if(typeof n!="function"&&(r||n!==void 0))throw new TypeError(T+" must "+(v||"be")+" a function"+(r?"":" or undefined"));return n}function J(n,T,v,r,c,_,O,b,S,x,Z){function N(p){if(!Z(p))throw new TypeError("Attempted to access private element on non-instance")}var H=[].concat(T[0]),tt=T[3],$=!O,D=c===1,et=c===3,it=c===4,V=c===2;function U(p,P,nt){return function(B,rt){return P&&(rt=B,B=n),nt&&nt(B),d[p].call(B,rt)}}if(!$){var d={},q=[],E=et?"get":it||D?"set":"value";if(S?(x||D?d={get:Jt(function(){return tt(this)},r,"get"),set:function(p){T[4](this,p)}}:d[E]=tt,x||Jt(d[E],r,V?"":E)):x||(d=Object.getOwnPropertyDescriptor(n,r)),!x&&!S){if((s=G[+b][r])&&(s^c)!==7)throw Error("Decorating two elements with the same name ("+d[E].name+") is not supported yet");G[+b][r]=c<3?1:c}}for(var f=n,k=H.length-1;k>=0;k-=v?2:1){var st=w(H[k],"A decorator","be",!0),ot=v?H[k-1]:void 0,W={},R={kind:["field","accessor","method","getter","setter","class"][c],name:r,metadata:l,addInitializer:function(p,P){if(p.v)throw new TypeError("attempted to call addInitializer after decoration was finished");w(P,"An initializer","be",!0),_.push(P)}.bind(null,W)};if($)s=st.call(ot,f,R),W.v=1,w(s,"class decorators","return")&&(f=s);else if(R.static=b,R.private=S,s=R.access={has:S?Z.bind():function(p){return r in p}},it||(s.get=S?V?function(p){return N(p),d.value}:U("get",0,N):function(p){return p[r]}),V||et||(s.set=S?U("set",0,N):function(p,P){p[r]=P}),f=st.call(ot,D?{get:d.get,set:d.set}:d[E],R),W.v=1,D){if(typeof f=="object"&&f)(s=w(f.get,"accessor.get"))&&(d.get=s),(s=w(f.set,"accessor.set"))&&(d.set=s),(s=w(f.init,"accessor.init"))&&q.unshift(s);else if(f!==void 0)throw new TypeError("accessor decorators must return an object with get, set, or init properties or undefined")}else w(f,(x?"field":"method")+" decorators","return")&&(x?q.unshift(f):d[E]=f)}return c<2&&O.push(M(q,b,1),M(_,b,0)),x||$||(S?D?O.splice(-1,0,U("get",b),U("set",b)):O.push(V?d[E]:w.call.bind(d[E])):j(n,r,d)),f}function Q(n){return j(n,C,{configurable:!0,enumerable:!0,value:l})}return a!==void 0&&(l=a[C]),l=F(l??null),h=[],m=function(n){n&&h.push(M(n))},I=function(n,T){for(var v=0;v<e.length;v++){var r=e[v],c=r[1],_=7&c;if((8&c)==n&&!_==T){var O=r[2],b=!!r[3],S=16&c;J(n?i:i.prototype,r,S,b?"#"+O:De(O),_,_<2?[]:n?A=A||[]:y=y||[],h,!!n,b,T,n&&b?function(x){return Le(x)===i}:u)}}},I(8,0),I(0,0),I(8,1),I(0,1),m(y),m(A),s=h,K||Q(i),{e:s,get c(){var n=[];return K&&[Q(i=J(i,[t],o,i.name,5,n)),M(n,1)]}}}function De(i){var t=Re(i,"string");return typeof t=="symbol"?t:t+""}function Re(i,t){if(typeof i!="object"||!i)return i;var e=i[Symbol.toPrimitive];if(e!==void 0){var o=e.call(i,t||"default");if(typeof o!="object")return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(i)}function Jt(i,t,e){typeof t=="symbol"&&(t=(t=t.description)?"["+t+"]":"");try{Object.defineProperty(i,"name",{configurable:!0,value:e?e+" "+t:t})}catch{}return i}function Le(i){if(Object(i)!==i)throw TypeError("right-hand side of 'in' should be an object, got "+(i!==null?typeof i:"null"));return i}var pt,ee=class extends Zt{static{({e:[Pt,Dt,Rt,Lt,Mt,Vt,Ut,kt,Bt,Ct,jt,Ft,Nt,Ht,$t,qt,Wt,Yt,Xt,zt,Gt,Kt,Ot],c:[pt,At]}=Pe(this,[Me("rui-toast")],[[L({type:String,reflect:!0,defaultValue:""}),0,"toastId"],[L({type:String,defaultValue:""}),0,"title"],[L({type:String,defaultValue:""}),0,"description"],[L({type:String,reflect:!0,defaultValue:"default"}),0,"variant"],[L({type:Number,defaultValue:4e3}),0,"duration"],[L({type:Boolean,defaultValue:!0}),0,"dismissible"],[L({type:Boolean,defaultValue:!1}),0,"closeButton"],[L({type:String,defaultValue:""}),0,"actionLabel"],[L({type:String,defaultValue:dt}),0,"position"],[L({type:Boolean,defaultValue:!1}),0,"markedDelete"],[Ve({ref:"toast"}),0,"toastTarget"],[ht(["title","description","variant","actionLabel","closeButton"]),2,"onContentUpdated"],[ht("position"),2,"onPositionUpdated"],[ht("duration"),2,"onDurationUpdated"],[ht("markedDelete"),2,"onMarkedDeleteUpdated"],[St,2,"onPointerDown"],[St,2,"onPointerMove"],[St,2,"onPointerUp"],[te({selector:"[data-toast-close]",type:"click"}),2,"onCloseClick"],[te({selector:"[data-toast-action]",type:"click"}),2,"onActionClick"]],0,void 0,Zt))}toastId=(Ot(this),Pt(this));title=(Dt(this),Rt(this));description=(Lt(this),Mt(this));variant=(Vt(this),Ut(this));duration=(kt(this),Bt(this));dismissible=(Ct(this),jt(this));closeButton=(Ft(this),Nt(this));actionLabel=(Ht(this),$t(this));position=(qt(this),Wt(this));markedDelete=(Yt(this),Xt(this));toastTarget=(zt(this),Gt(this));mounted=(Kt(this),!1);removed=!1;swiping=!1;swipeOut=!1;swipeAxis=null;swipeOutDirection=null;held=!1;timerReady=!1;timeoutId=null;pointerStart=null;dragStartTime=null;exitTimer=null;connectedCallback(){super.connectedCallback();let t=this.mounted;if(this.addEventListener("pointerdown",this.onPointerDown),this.addEventListener("pointermove",this.onPointerMove),this.addEventListener("pointerup",this.onPointerUp),this.addEventListener("pointercancel",this.onPointerUp),t){this.syncDomState(),this.dispatchEvent(new CustomEvent("rui-toast-mounted",{bubbles:!0}));return}this.timerReady=!1,requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.isConnected&&(this.mounted=!0,this.timerReady=!0,this.syncDomState(),this.dispatchEvent(new CustomEvent("rui-toast-mounted",{bubbles:!0})))})}),this.syncDomState()}disconnectedCallback(){this.clearTimer(),this.exitTimer&&(clearTimeout(this.exitTimer),this.exitTimer=null);let t=this.resolvedId;t!==""&&this.removed&&g.remove(t),this.held=!1,this.timerReady=!1,this.removeEventListener("pointerdown",this.onPointerDown),this.removeEventListener("pointermove",this.onPointerMove),this.removeEventListener("pointerup",this.onPointerUp),this.removeEventListener("pointercancel",this.onPointerUp),super.disconnectedCallback()}onContentUpdated(){this.requestUpdate()}onPositionUpdated(){this.syncDomState()}setPaused(t){if(this.held===t){!t&&this.timerReady&&this.mounted&&!this.removed&&!this.timeoutId&&this.startTimer();return}this.held=t,!(!this.timerReady||!this.mounted||this.removed)&&(t||document.hidden?this.clearTimer():this.startTimer())}onDurationUpdated(){!this.timerReady||!this.mounted||this.removed||this.held||this.startTimer()}onMarkedDeleteUpdated(){this.markedDelete&&!this.removed&&this.beginRemove()}get resolvedId(){let t=this.toastId;if(t==null||t==="")return"";let e=Number(t);return Number.isFinite(e)&&String(e)===t?e:t}clearTimer(){this.timeoutId&&clearTimeout(this.timeoutId),this.timeoutId=null}startTimer(){if(!(this.held||this.removed||document.hidden)&&!(this.duration===Number.POSITIVE_INFINITY||this.variant==="loading")){if(this.duration<=0){this.beginRemove();return}this.clearTimer(),this.timeoutId=setTimeout(()=>this.beginRemove(),this.duration)}}beginRemove(){this.removed||(this.removed=!0,this.clearTimer(),this.syncDomState(),this.markedDelete||g.dismiss(this.resolvedId),this.exitTimer=setTimeout(()=>{this.exitTimer=null,g.remove(this.resolvedId)},200))}onPointerDown(t){!this.dismissible||this.variant==="loading"||t.button!==0||t.target?.closest("[data-toast-close], [data-toast-action], button, a")||(this.dragStartTime=Date.now(),this.pointerStart={x:t.clientX,y:t.clientY},this.swipeAxis=null,this.setPointerCapture(t.pointerId))}onPointerMove(t){if(!this.pointerStart)return;let{y:e,x:o}=Y(this.position),u=t.clientX-this.pointerStart.x,a=t.clientY-this.pointerStart.y;if(!this.swiping){if(Math.abs(u)<8&&Math.abs(a)<8)return;this.swiping=!0,this.syncDomState()}this.swipeAxis||(this.swipeAxis=Math.abs(u)>Math.abs(a)?"x":"y");let l=this.swipeAxis==="x"?u:0,s=this.swipeAxis==="y"?a:0;if(this.swipeAxis==="y"&&!(e==="bottom"?s>0:s<0)&&Math.abs(s)<45){this.style.setProperty("--swipe-amount-x","0px"),this.style.setProperty("--swipe-amount-y","0px");return}if(this.swipeAxis==="x"){let y=o==="start"?l<0:l>0;if(o!=="center"&&!y&&Math.abs(l)<45){this.style.setProperty("--swipe-amount-x","0px"),this.style.setProperty("--swipe-amount-y","0px");return}}this.style.setProperty("--swipe-amount-x",`${l}px`),this.style.setProperty("--swipe-amount-y",`${s}px`)}onPointerUp(t){if(!this.pointerStart)return;try{this.releasePointerCapture(t.pointerId)}catch{}let e=this.swiping;if(this.swiping=!1,!e){this.pointerStart=null,this.dragStartTime=null,this.swipeAxis=null;return}let o=Number.parseFloat(this.style.getPropertyValue("--swipe-amount-x")||"0"),u=Number.parseFloat(this.style.getPropertyValue("--swipe-amount-y")||"0"),a=this.swipeAxis==="x"?o:u,l=this.dragStartTime?Date.now()-this.dragStartTime:0,s=Math.abs(a)/Math.max(l,1);if((Math.abs(a)>=45||s>.11)&&this.dismissible){let{y:A,x:h}=Y(this.position);this.swipeAxis==="x"?(this.swipeOutDirection=o<0?"left":"right",h==="start"&&(this.swipeOutDirection="left"),h==="end"&&(this.swipeOutDirection="right")):this.swipeOutDirection=A==="bottom"?"down":"up",this.swipeOut=!0,this.syncDomState(),this.beginRemove()}else this.style.setProperty("--swipe-amount-x","0px"),this.style.setProperty("--swipe-amount-y","0px"),this.swipeAxis=null,this.syncDomState();this.pointerStart=null,this.dragStartTime=null}onCloseClick(t){t.stopPropagation(),this.dismissible&&this.beginRemove()}onActionClick(t){t.stopPropagation(),g.getSnapshot().find(o=>o.id===this.resolvedId)?.action?.onClick(t),this.dismissible&&this.beginRemove()}syncDomState(){let{y:t,x:e}=Y(this.position);this.setAttribute("role","listitem"),this.dataset.mounted=String(this.mounted),this.dataset.removed=String(this.removed),this.dataset.swiping=String(this.swiping),this.dataset.swipeOut=String(this.swipeOut),this.dataset.dismissible=String(this.dismissible),this.dataset.yPosition=t,this.dataset.xPosition=e,this.dataset.variant=this.variant??"default",this.swipeOutDirection?this.dataset.swipeDirection=this.swipeOutDirection:delete this.dataset.swipeDirection}iconForVariant(){switch(this.variant){case"success":return"\u2713";case"error":return"\u2715";case"warning":return"!";case"info":return"i";default:return""}}render(){let t=this.variant??"default",e=this.iconForVariant(),o=t!=="default";return Qt("div",{ref:"toast",class:`rui-toast rui-toast--${t}`,role:"status","aria-live":"off","data-ref":"toast",children:[this.closeButton&&t!=="loading"?z("button",{type:"button",class:"rui-toast__close","data-toast-close":!0,"aria-label":"Close toast",children:"\xD7"}):null,o?z("span",{class:"rui-toast__icon","data-icon":!0,"aria-hidden":"true",children:t==="loading"?z("span",{class:"rui-toast__loader"}):e}):null,Qt("div",{class:"rui-toast__content",children:[z("div",{class:"rui-toast__title","data-title":!0,children:this.$.title}),this.description?z("div",{class:"rui-toast__description","data-description":!0,children:this.$.description}):null]}),this.actionLabel?z("button",{type:"button",class:"rui-toast__action rui-button rui-button--outline rui-button--sm","data-toast-action":!0,children:this.$.actionLabel}):null]})}static{At()}};import{jsx as xt}from"@ecopages/jsx/jsx-runtime";import{RadiantElement as ge,bound as ft,customElement as je,onEvent as wt,onUpdated as Fe,prop as X,state as Ne}from"@ecopages/radiant";var ie,se,oe,ne,re,ae,ue,ce,le,de,he,pe,fe,me,ye,ve,be,Te;function Ue(i,t,e,o,u,a){var l,s,y,A,h,m,I,C=Symbol.metadata||Symbol.for("Symbol.metadata"),j=Object.defineProperty,F=Object.create,G=[F(null),F(null)],K=t.length;function M(n,T,v){return function(r,c){T&&(c=r,r=i);for(var _=0;_<n.length;_++)c=n[_].apply(r,v?[c]:[]);return v?c:r}}function w(n,T,v,r){if(typeof n!="function"&&(r||n!==void 0))throw new TypeError(T+" must "+(v||"be")+" a function"+(r?"":" or undefined"));return n}function J(n,T,v,r,c,_,O,b,S,x,Z){function N(p){if(!Z(p))throw new TypeError("Attempted to access private element on non-instance")}var H=[].concat(T[0]),tt=T[3],$=!O,D=c===1,et=c===3,it=c===4,V=c===2;function U(p,P,nt){return function(B,rt){return P&&(rt=B,B=n),nt&&nt(B),d[p].call(B,rt)}}if(!$){var d={},q=[],E=et?"get":it||D?"set":"value";if(S?(x||D?d={get:_e(function(){return tt(this)},r,"get"),set:function(p){T[4](this,p)}}:d[E]=tt,x||_e(d[E],r,V?"":E)):x||(d=Object.getOwnPropertyDescriptor(n,r)),!x&&!S){if((s=G[+b][r])&&(s^c)!==7)throw Error("Decorating two elements with the same name ("+d[E].name+") is not supported yet");G[+b][r]=c<3?1:c}}for(var f=n,k=H.length-1;k>=0;k-=v?2:1){var st=w(H[k],"A decorator","be",!0),ot=v?H[k-1]:void 0,W={},R={kind:["field","accessor","method","getter","setter","class"][c],name:r,metadata:l,addInitializer:function(p,P){if(p.v)throw new TypeError("attempted to call addInitializer after decoration was finished");w(P,"An initializer","be",!0),_.push(P)}.bind(null,W)};if($)s=st.call(ot,f,R),W.v=1,w(s,"class decorators","return")&&(f=s);else if(R.static=b,R.private=S,s=R.access={has:S?Z.bind():function(p){return r in p}},it||(s.get=S?V?function(p){return N(p),d.value}:U("get",0,N):function(p){return p[r]}),V||et||(s.set=S?U("set",0,N):function(p,P){p[r]=P}),f=st.call(ot,D?{get:d.get,set:d.set}:d[E],R),W.v=1,D){if(typeof f=="object"&&f)(s=w(f.get,"accessor.get"))&&(d.get=s),(s=w(f.set,"accessor.set"))&&(d.set=s),(s=w(f.init,"accessor.init"))&&q.unshift(s);else if(f!==void 0)throw new TypeError("accessor decorators must return an object with get, set, or init properties or undefined")}else w(f,(x?"field":"method")+" decorators","return")&&(x?q.unshift(f):d[E]=f)}return c<2&&O.push(M(q,b,1),M(_,b,0)),x||$||(S?D?O.splice(-1,0,U("get",b),U("set",b)):O.push(V?d[E]:w.call.bind(d[E])):j(n,r,d)),f}function Q(n){return j(n,C,{configurable:!0,enumerable:!0,value:l})}return a!==void 0&&(l=a[C]),l=F(l??null),h=[],m=function(n){n&&h.push(M(n))},I=function(n,T){for(var v=0;v<e.length;v++){var r=e[v],c=r[1],_=7&c;if((8&c)==n&&!_==T){var O=r[2],b=!!r[3],S=16&c;J(n?i:i.prototype,r,S,b?"#"+O:ke(O),_,_<2?[]:n?A=A||[]:y=y||[],h,!!n,b,T,n&&b?function(x){return Ce(x)===i}:u)}}},I(8,0),I(0,0),I(8,1),I(0,1),m(y),m(A),s=h,K||Q(i),{e:s,get c(){var n=[];return K&&[Q(i=J(i,[t],o,i.name,5,n)),M(n,1)]}}}function ke(i){var t=Be(i,"string");return typeof t=="symbol"?t:t+""}function Be(i,t){if(typeof i!="object"||!i)return i;var e=i[Symbol.toPrimitive];if(e!==void 0){var o=e.call(i,t||"default");if(typeof o!="object")return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(i)}function _e(i,t,e){typeof t=="symbol"&&(t=(t=t.description)?"["+t+"]":"");try{Object.defineProperty(i,"name",{configurable:!0,value:e?e+" "+t:t})}catch{}return i}function Ce(i){if(Object(i)!==i)throw TypeError("right-hand side of 'in' should be an object, got "+(i!==null?typeof i:"null"));return i}function Se(i,t){return i instanceof Node&&t.contains(i)}var mt,xe=class extends ge{static{({e:[oe,ne,re,ae,ue,ce,le,de,he,pe,fe,me,ye,ve,be,Te,ie],c:[mt,se]}=Ue(this,[je("rui-toaster")],[[X({type:String,reflect:!0,defaultValue:dt}),0,"position"],[X({type:Number,defaultValue:4e3}),0,"duration"],[X({type:Number,defaultValue:3}),0,"visibleToasts"],[X({type:Boolean,defaultValue:!1}),0,"closeButton"],[X({type:Boolean,defaultValue:!1}),0,"expand"],[X({type:Number,defaultValue:14}),0,"gap"],[X({type:Number,defaultValue:24}),0,"offset"],[Ne,0,"toasts"],[Fe(["position","duration","visibleToasts","closeButton","expand","gap","offset"]),2,"onConfigUpdated"],[wt({document:!0,type:at}),2,"onDocumentShow"],[wt({document:!0,type:ut}),2,"onDocumentDismiss"],[wt({selector:"rui-toast",type:"rui-toast-mounted"}),2,"onToastMounted"],[ft,2,"onPointerOver"],[ft,2,"onPointerOut"],[ft,2,"onPointerDown"],[ft,2,"onPointerUp"]],0,void 0,ge))}position=(ie(this),oe(this));duration=(ne(this),re(this));visibleToasts=(ae(this),ue(this));closeButton=(ce(this),le(this));expand=(de(this),he(this));gap=(pe(this),fe(this));offset=(me(this),ye(this));toasts=(ve(this),be(this,[]));expanded=(Te(this),!1);interacting=!1;unsubscribe=null;visibilityHandler=null;heights=new Map;observers=new Map;layoutFrame=null;connectedCallback(){super.connectedCallback(),this.syncHostPosition(),this.unsubscribe=g.subscribe(t=>{this.toasts=t,t.length===0&&this.resetLayoutState(),this.scheduleLayoutSync()}),this.visibilityHandler=()=>this.syncPauseState(),document.addEventListener("visibilitychange",this.visibilityHandler)}disconnectedCallback(){this.unsubscribe?.(),this.unsubscribe=null,this.visibilityHandler&&(document.removeEventListener("visibilitychange",this.visibilityHandler),this.visibilityHandler=null),document.removeEventListener("pointerup",this.onPointerUp),document.removeEventListener("pointercancel",this.onPointerUp),this.layoutFrame!=null&&cancelAnimationFrame(this.layoutFrame),this.resetLayoutState(),super.disconnectedCallback()}onConfigUpdated(){this.syncHostPosition(),this.scheduleLayoutSync()}onDocumentShow(t){let e=t.detail;e?.title&&g.create(e.title,{id:e.id,description:e.description,variant:e.variant,duration:e.duration,action:e.action,dismissible:e.dismissible,closeButton:e.closeButton,position:e.position})}onDocumentDismiss(t){let e=t.detail;g.dismiss(e?.id)}onToastMounted(){this.observeToasts(),this.syncPauseState()}filteredToasts(){let t=this.toasts.filter(u=>(u.position??this.position)===this.position),e=[],o=[];for(let u of t)u.delete?o.push(u):e.push(u);return[...e.slice(0,this.visibleToasts),...o]}syncHostPosition(){let{y:t,x:e}=Y(this.position);this.dataset.yPosition=t,this.dataset.xPosition=e,this.style.setProperty("--width",`${356}px`),this.style.setProperty("--gap",`${this.gap}px`),this.style.setProperty("--viewport-offset",`${this.offset}px`)}isStackExpanded(){return this.expanded||this.expand}isPaused(){return this.isStackExpanded()||this.interacting||document.hidden}resetLayoutState(){for(let e of this.observers.values())e.disconnect();this.observers.clear(),this.heights.clear(),this.expanded=!1,this.interacting=!1;let t=this.querySelector(".rui-toaster");t&&(t.style.height="0px",t.dataset.expanded="false"),this.dataset.expanded="false"}syncPauseState(){let t=this.isPaused();for(let e of this.querySelectorAll("rui-toast"))e.setPaused(t);this.patchStackLayout()}scheduleLayoutSync(){this.layoutFrame!=null&&cancelAnimationFrame(this.layoutFrame),this.layoutFrame=requestAnimationFrame(()=>{if(this.layoutFrame=null,this.toasts.length>0&&!this.interacting){let e=!!(this.querySelector(".rui-toaster")?.matches(":hover")||this.matches(":hover"));this.expanded=e}this.observeToasts(),this.syncPauseState()})}measureToast(t){let e=t.style.height,o=t.style.overflow;t.style.height="auto",t.style.overflow="visible";let u=t.querySelector(".rui-toast"),a=Math.round(u instanceof HTMLElement?u.offsetHeight:t.offsetHeight)||64;return t.style.height=e,t.style.overflow=o,a}observeToasts(){let t=this.querySelector(".rui-toaster");if(!t)return;let e=[...t.querySelectorAll("rui-toast")],o=new Set;for(let u of e){let a=u.toastId;if(!a)continue;o.add(a);let l=u.querySelector(".rui-toast")??u;if(!this.observers.has(a)){let s=new ResizeObserver(()=>{let y=this.measureToast(u);this.heights.get(a)!==y&&(this.heights.set(a,y),this.patchStackLayout())});s.observe(l),this.observers.set(a,s)}this.heights.set(a,this.measureToast(u))}for(let[u,a]of[...this.observers])o.has(u)||(a.disconnect(),this.observers.delete(u),this.heights.delete(u))}patchStackLayout(){let t=this.querySelector(".rui-toaster");if(!t)return;let e=this.isStackExpanded(),{y:o}=Y(this.position),u=o==="bottom"?-1:1;this.dataset.expanded=String(e),t.dataset.expanded=String(e);let a=[...t.querySelectorAll("rui-toast")].filter(h=>h.dataset.mounted==="true"&&h.dataset.removed!=="true");if(a.length===0){t.style.height="0px";return}let l=a.map(h=>{let m=this.heights.get(h.toastId)??this.measureToast(h);return this.heights.set(h.toastId,m),m}),s=l[0]??64,y=0;for(let h=0;h<a.length;h+=1){let m=a[h];if(!m)continue;let I=l[h]??64,C=h===0;if(m.dataset.index=String(h),m.dataset.front=String(C),m.dataset.expanded=String(e),m.style.setProperty("--z-index",String(a.length-h)),e)m.style.setProperty("--y",`translateY(${u*y}px)`),m.style.height=`${I}px`,m.style.overflow="visible",y+=I+this.gap;else if(C)m.style.setProperty("--y","translateY(0px)"),m.style.height=`${I}px`,m.style.overflow="visible";else{let j=Math.max(.7,1-h*.05);m.style.setProperty("--y",`translateY(${u*h*this.gap}px) scale(${j})`),m.style.height=`${s}px`,m.style.overflow="hidden"}}let A=e?Math.max(0,y>0?y-this.gap:s):s+Math.max(0,a.length-1)*this.gap;t.style.height=`${A}px`}onPointerOver(t){Se(t.relatedTarget,this)||(this.expanded=!0,this.syncPauseState())}onPointerOut(t){Se(t.relatedTarget,this)||this.interacting||(this.expanded=!1,this.syncPauseState())}onPointerDown(){this.interacting=!0,this.expanded=!0,this.syncPauseState(),document.addEventListener("pointerup",this.onPointerUp,{once:!0}),document.addEventListener("pointercancel",this.onPointerUp,{once:!0})}onPointerUp(){if(!this.interacting)return;this.interacting=!1,this.matches(":hover")||this.querySelector("rui-toast:hover")||(this.expanded=!1),this.syncPauseState()}render(){let t=this.filteredToasts();return xt("section",{class:"rui-toaster-region","aria-label":"Notifications","aria-live":"polite","aria-relevant":"additions text","aria-atomic":"false",tabIndex:-1,children:xt("ol",{class:"rui-toaster","data-rui-toaster":!0,"on:pointerover":this.onPointerOver,"on:pointerout":this.onPointerOut,"on:pointerdown":this.onPointerDown,children:t.map(e=>{let o=e.duration??(e.variant==="loading"?Number.POSITIVE_INFINITY:this.duration);return xt("rui-toast",{"prop:toastId":String(e.id),"prop:title":e.title,"prop:description":e.description??"","prop:variant":e.variant,"prop:duration":o,"prop:dismissible":e.dismissible,"prop:closeButton":e.closeButton??this.closeButton,"prop:actionLabel":e.action?.label??"","prop:position":e.position??this.position,"prop:markedDelete":!!e.delete},String(e.id))})})})}static{se()}};import{jsx as Ie}from"@ecopages/jsx/jsx-runtime";var He=Symbol.for("@ecopages/storybook-radiant.viewElement"),we=Symbol.for("@ecopages/storybook-radiant.scriptModule"),Ee=Symbol.for("@ecopages/storybook-radiant.scriptExport");function $e(i,t){i[He]=t;let e=t[we];e&&(i[we]=e,i[Ee]=t[Ee]??t.name)}function Et(i,t,e){let o=u=>t(u);return $e(o,i),o}var qe=Et(pt,({toastId:i,title:t,description:e,variant:o,duration:u,dismissible:a,closeButton:l,actionLabel:s,position:y,markedDelete:A,...h})=>Ie("rui-toast",{...h,"prop:toastId":i!=null?String(i):void 0,"prop:title":t,"prop:description":e,"prop:variant":o,"prop:duration":u,"prop:dismissible":a,"prop:closeButton":l,"prop:actionLabel":s,"prop:position":y,"prop:markedDelete":A}),{stylesheets:["./toast.css"]}),We=Et(mt,({children:i,position:t,duration:e,visibleToasts:o,closeButton:u,expand:a,gap:l,offset:s,...y})=>Ie("rui-toaster",{...y,"prop:position":t,"prop:duration":e,"prop:visibleToasts":o,"prop:closeButton":u,"prop:expand":a,"prop:gap":l,"prop:offset":s,children:i}),{stylesheets:["./toast.css"]});var Ye=Object.assign((i,t)=>g.create(i,t),{message:(i,t)=>g.message(i,t),success:(i,t)=>g.success(i,t),error:(i,t)=>g.error(i,t),info:(i,t)=>g.info(i,t),warning:(i,t)=>g.warning(i,t),loading:(i,t)=>g.loading(i,t),promise:(i,t)=>g.promise(i,t),dismiss:i=>g.dismiss(i),clear:()=>g.clear()});function Xe(i){document.dispatchEvent(new CustomEvent(at,{detail:i,bubbles:!0,composed:!0}))}function ze(i){let t=i==null?{}:{id:i};document.dispatchEvent(new CustomEvent(ut,{detail:t,bubbles:!0,composed:!0}))}export{dt as DEFAULT_TOAST_POSITION,ut as RUI_TOAST_DISMISS_EVENT,at as RUI_TOAST_SHOW_EVENT,qe as RuiToast,pt as RuiToastElement,We as RuiToaster,mt as RuiToasterElement,_t as TOAST_EXIT_MS,vt as TOAST_GAP,ct as TOAST_LIFETIME,lt as TOAST_SWIPE_THRESHOLD,bt as TOAST_VIEWPORT_OFFSET,Tt as TOAST_VISIBLE_AMOUNT,yt as TOAST_WIDTH,ze as dismissToast,Xe as showToast,Ye as toast};
|
|
1
|
+
import{jsx as K,jsxs as te}from"@ecopages/jsx/jsx-runtime";import{RadiantElement as ee,bound as wt,customElement as Fe,onEvent as ie,onUpdated as pt,prop as M,query as $e}from"@ecopages/radiant";var at="rui-toast-show",lt="rui-toast-dismiss",ke=["top-start","top-center","top-end","bottom-start","bottom-center","bottom-end"],ut=4e3,vt=356,bt=14,gt=24,Tt=3,_t=3,ct=45,St=200,ht="bottom-end";function z(i){let[t,e]=i.split("-");return{y:t,x:e}}var Ue=1;function Ve(){return Ue++}function Pt(i,t){return typeof i=="function"?i(t):i}var xt=class{subscribers=[];toasts=[];subscribe=t=>(this.subscribers.push(t),t(this.toasts),()=>{let e=this.subscribers.indexOf(t);e>=0&&this.subscribers.splice(e,1)});getSnapshot=()=>this.toasts;publish(){let t=this.toasts;for(let e of this.subscribers)e(t)}create=(t,e={})=>{let s=e.id??Ve(),o=e.dismissible??!0,l=this.toasts.findIndex(n=>n.id===s),u={id:s,title:t,description:e.description,variant:e.variant??"default",duration:e.duration,action:e.action,dismissible:o,closeButton:e.closeButton,position:e.position,delete:!1};return l>=0?this.toasts=this.toasts.map(n=>n.id===s?{...n,...u,delete:!1}:n):this.toasts=[u,...this.toasts],this.publish(),s};dismiss=t=>{if(t==null){if(this.toasts.length===0)return;this.toasts=this.toasts.map(e=>({...e,delete:!0}))}else{let e=this.toasts.find(s=>s.id===t);if(!e||e.delete)return;this.toasts=this.toasts.map(s=>s.id===t?{...s,delete:!0}:s)}this.publish()};remove=t=>{this.toasts=this.toasts.filter(e=>e.id!==t),this.publish()};clear=()=>{this.toasts.length!==0&&(this.toasts=[],this.publish())};message=(t,e)=>this.create(t,e);success=(t,e)=>this.create(t,{...e,variant:"success"});error=(t,e)=>this.create(t,{...e,variant:"error"});info=(t,e)=>this.create(t,{...e,variant:"info"});warning=(t,e)=>this.create(t,{...e,variant:"warning"});loading=(t,e)=>this.create(t,{...e,variant:"loading",duration:e?.duration??Number.POSITIVE_INFINITY});promise=(t,e)=>{let s=this.loading(e.loading,{duration:Number.POSITIVE_INFINITY,action:e.action,closeButton:e.closeButton,position:e.position,description:typeof e.description=="string"?e.description:void 0});return(typeof t=="function"?t():t).then(l=>{let u=typeof e.description=="function"?e.description(l):e.description;this.create(Pt(e.success,l),{id:s,variant:"success",description:u,duration:e.duration,action:e.action,closeButton:e.closeButton,position:e.position})}).catch(l=>{let u=typeof e.description=="function"?e.description(l):e.description;this.create(Pt(e.error,l),{id:s,variant:"error",description:u,duration:e.duration,action:e.action,closeButton:e.closeButton,position:e.position})}),s}},_=new xt;var At,Dt,Lt,Rt,Mt,kt,Ut,Vt,Ct,Bt,jt,Ht,Ft,$t,Nt,qt,Wt,Yt,Xt,zt,Kt,Gt,Jt,Qt;function Ce(i,t,e,s,o,l){var u,n,y,E,h,d,O,j=Symbol.metadata||Symbol.for("Symbol.metadata"),H=Object.defineProperty,R=Object.create,$=[R(null),R(null)],G=t.length;function k(r,g,v){return function(a,c){g&&(c=a,a=i);for(var T=0;T<r.length;T++)c=r[T].apply(a,v?[c]:[]);return v?c:a}}function w(r,g,v,a){if(typeof r!="function"&&(a||r!==void 0))throw new TypeError(g+" must "+(v||"be")+" a function"+(a?"":" or undefined"));return r}function J(r,g,v,a,c,T,P,b,S,x,Z){function N(f){if(!Z(f))throw new TypeError("Attempted to access private element on non-instance")}var q=[].concat(g[0]),tt=g[3],W=!P,D=c===1,et=c===3,it=c===4,U=c===2;function V(f,A,ot){return function(B,rt){return A&&(rt=B,B=r),ot&&ot(B),p[f].call(B,rt)}}if(!W){var p={},Y=[],I=et?"get":it||D?"set":"value";if(S?(x||D?p={get:Zt(function(){return tt(this)},a,"get"),set:function(f){g[4](this,f)}}:p[I]=tt,x||Zt(p[I],a,U?"":I)):x||(p=Object.getOwnPropertyDescriptor(r,a)),!x&&!S){if((n=$[+b][a])&&(n^c)!==7)throw Error("Decorating two elements with the same name ("+p[I].name+") is not supported yet");$[+b][a]=c<3?1:c}}for(var m=r,C=q.length-1;C>=0;C-=v?2:1){var st=w(q[C],"A decorator","be",!0),nt=v?q[C-1]:void 0,X={},L={kind:["field","accessor","method","getter","setter","class"][c],name:a,metadata:u,addInitializer:function(f,A){if(f.v)throw new TypeError("attempted to call addInitializer after decoration was finished");w(A,"An initializer","be",!0),T.push(A)}.bind(null,X)};if(W)n=st.call(nt,m,L),X.v=1,w(n,"class decorators","return")&&(m=n);else if(L.static=b,L.private=S,n=L.access={has:S?Z.bind():function(f){return a in f}},it||(n.get=S?U?function(f){return N(f),p.value}:V("get",0,N):function(f){return f[a]}),U||et||(n.set=S?V("set",0,N):function(f,A){f[a]=A}),m=st.call(nt,D?{get:p.get,set:p.set}:p[I],L),X.v=1,D){if(typeof m=="object"&&m)(n=w(m.get,"accessor.get"))&&(p.get=n),(n=w(m.set,"accessor.set"))&&(p.set=n),(n=w(m.init,"accessor.init"))&&Y.unshift(n);else if(m!==void 0)throw new TypeError("accessor decorators must return an object with get, set, or init properties or undefined")}else w(m,(x?"field":"method")+" decorators","return")&&(x?Y.unshift(m):p[I]=m)}return c<2&&P.push(k(Y,b,1),k(T,b,0)),x||W||(S?D?P.splice(-1,0,V("get",b),V("set",b)):P.push(U?p[I]:w.call.bind(p[I])):H(r,a,p)),m}function Q(r){return H(r,j,{configurable:!0,enumerable:!0,value:u})}return l!==void 0&&(u=l[j]),u=R(u??null),h=[],d=function(r){r&&h.push(k(r))},O=function(r,g){for(var v=0;v<e.length;v++){var a=e[v],c=a[1],T=7&c;if((8&c)==r&&!T==g){var P=a[2],b=!!a[3],S=16&c;J(r?i:i.prototype,a,S,b?"#"+P:Be(P),T,T<2?[]:r?E=E||[]:y=y||[],h,!!r,b,g,r&&b?function(x){return He(x)===i}:o)}}},O(8,0),O(0,0),O(8,1),O(0,1),d(y),d(E),n=h,G||Q(i),{e:n,get c(){var r=[];return G&&[Q(i=J(i,[t],s,i.name,5,r)),k(r,1)]}}}function Be(i){var t=je(i,"string");return typeof t=="symbol"?t:t+""}function je(i,t){if(typeof i!="object"||!i)return i;var e=i[Symbol.toPrimitive];if(e!==void 0){var s=e.call(i,t||"default");if(typeof s!="object")return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(i)}function Zt(i,t,e){typeof t=="symbol"&&(t=(t=t.description)?"["+t+"]":"");try{Object.defineProperty(i,"name",{configurable:!0,value:e?e+" "+t:t})}catch{}return i}function He(i){if(Object(i)!==i)throw TypeError("right-hand side of 'in' should be an object, got "+(i!==null?typeof i:"null"));return i}var dt=new Map,mt=new Map;function It(i){return String(i)}function ft(i){if(i==="")return;let t=It(i);dt.delete(t),mt.delete(t)}function Ne(i){if(i==="")return;let t=It(i),e=dt.get(t);e!=null&&(mt.set(t,Math.max(0,e-Date.now())),dt.delete(t))}var ne,se=class extends ee{static{({e:[Lt,Rt,Mt,kt,Ut,Vt,Ct,Bt,jt,Ht,Ft,$t,Nt,qt,Wt,Yt,Xt,zt,Kt,Gt,Jt,Qt,At],c:[ne,Dt]}=Ce(this,[Fe("rui-toast")],[[M({type:String,reflect:!0,defaultValue:""}),0,"toastId"],[M({type:String,defaultValue:""}),0,"title"],[M({type:String,defaultValue:""}),0,"description"],[M({type:String,reflect:!0,defaultValue:"default"}),0,"variant"],[M({type:Number,defaultValue:4e3}),0,"duration"],[M({type:Boolean,defaultValue:!0}),0,"dismissible"],[M({type:Boolean,defaultValue:!1}),0,"closeButton"],[M({type:String,defaultValue:""}),0,"actionLabel"],[M({type:String,defaultValue:ht}),0,"position"],[M({type:Boolean,defaultValue:!1}),0,"markedDelete"],[$e({ref:"toast"}),0,"toastTarget"],[pt(["title","description","variant","actionLabel","closeButton"]),2,"onContentUpdated"],[pt("position"),2,"onPositionUpdated"],[pt("duration"),2,"onDurationUpdated"],[pt("markedDelete"),2,"onMarkedDeleteUpdated"],[wt,2,"onPointerDown"],[wt,2,"onPointerMove"],[wt,2,"onPointerUp"],[ie({selector:"[data-toast-close]",type:"click"}),2,"onCloseClick"],[ie({selector:"[data-toast-action]",type:"click"}),2,"onActionClick"]],0,void 0,ee))}toastId=(At(this),Lt(this));title=(Rt(this),Mt(this));description=(kt(this),Ut(this));variant=(Vt(this),Ct(this));duration=(Bt(this),jt(this));dismissible=(Ht(this),Ft(this));closeButton=($t(this),Nt(this));actionLabel=(qt(this),Wt(this));position=(Yt(this),Xt(this));markedDelete=(zt(this),Kt(this));toastTarget=(Gt(this),Jt(this));mounted=(Qt(this),!1);removed=!1;swiping=!1;swipeOut=!1;swipeAxis=null;swipeOutDirection=null;held=!1;timerReady=!1;timeoutId=null;pointerStart=null;dragStartTime=null;exitTimer=null;connectedCallback(){super.connectedCallback();let t=this.mounted;if(this.addEventListener("pointerdown",this.onPointerDown),this.addEventListener("pointermove",this.onPointerMove),this.addEventListener("pointerup",this.onPointerUp),this.addEventListener("pointercancel",this.onPointerUp),t){this.timerReady=!0,this.syncDomState(),this.dispatchEvent(new CustomEvent("rui-toast-mounted",{bubbles:!0})),!this.held&&!this.removed&&this.startTimer();return}this.timerReady=!1,requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.isConnected&&(this.mounted=!0,this.timerReady=!0,this.syncDomState(),this.dispatchEvent(new CustomEvent("rui-toast-mounted",{bubbles:!0})),!this.held&&!this.removed&&this.startTimer())})}),this.syncDomState()}disconnectedCallback(){this.clearTimer(),this.exitTimer&&(clearTimeout(this.exitTimer),this.exitTimer=null);let t=this.resolvedId;t!==""&&this.removed&&_.remove(t),this.held=!1,this.timerReady=!1,this.removeEventListener("pointerdown",this.onPointerDown),this.removeEventListener("pointermove",this.onPointerMove),this.removeEventListener("pointerup",this.onPointerUp),this.removeEventListener("pointercancel",this.onPointerUp),super.disconnectedCallback()}onContentUpdated(){this.requestUpdate()}onPositionUpdated(){this.syncDomState()}setPaused(t){if(this.held===t){!t&&this.timerReady&&this.mounted&&!this.removed&&!this.timeoutId&&this.startTimer();return}this.held=t,!(!this.timerReady||!this.mounted||this.removed)&&(t||document.hidden?(Ne(this.resolvedId),this.clearTimer()):this.startTimer())}onDurationUpdated(){!this.timerReady||!this.mounted||this.removed||this.held||(ft(this.resolvedId),this.startTimer())}onMarkedDeleteUpdated(){this.markedDelete&&!this.removed&&this.beginRemove()}get resolvedId(){let t=this.toastId;if(t==null||t==="")return"";let e=Number(t);return Number.isFinite(e)&&String(e)===t?e:t}clearTimer(){this.timeoutId&&clearTimeout(this.timeoutId),this.timeoutId=null}startTimer(){if(this.held||this.removed||document.hidden||this.duration===Number.POSITIVE_INFINITY||this.variant==="loading")return;if(this.duration<=0){this.beginRemove();return}let t=this.resolvedId,e=It(t),s=Date.now(),o=mt.get(e);if(mt.delete(e),o==null){let l=dt.get(e);o=l!=null?l-s:this.duration}if(o<=0){ft(t),this.beginRemove();return}dt.set(e,s+o),this.clearTimer(),this.timeoutId=setTimeout(()=>{ft(t),this.beginRemove()},o)}beginRemove(){this.removed||(this.removed=!0,this.clearTimer(),ft(this.resolvedId),this.syncDomState(),this.markedDelete||_.dismiss(this.resolvedId),this.exitTimer=setTimeout(()=>{this.exitTimer=null,_.remove(this.resolvedId)},200))}onPointerDown(t){!this.dismissible||this.variant==="loading"||t.button!==0||t.target?.closest("[data-toast-close], [data-toast-action], button, a")||(this.dragStartTime=Date.now(),this.pointerStart={x:t.clientX,y:t.clientY},this.swipeAxis=null,this.setPointerCapture(t.pointerId))}onPointerMove(t){if(!this.pointerStart)return;let{y:e,x:s}=z(this.position),o=t.clientX-this.pointerStart.x,l=t.clientY-this.pointerStart.y;if(!this.swiping){if(Math.abs(o)<8&&Math.abs(l)<8)return;this.swiping=!0,this.syncDomState()}this.swipeAxis||(this.swipeAxis=Math.abs(o)>Math.abs(l)?"x":"y");let u=this.swipeAxis==="x"?o:0,n=this.swipeAxis==="y"?l:0;if(this.swipeAxis==="y"&&!(e==="bottom"?n>0:n<0)&&Math.abs(n)<45){this.style.setProperty("--swipe-amount-x","0px"),this.style.setProperty("--swipe-amount-y","0px");return}if(this.swipeAxis==="x"){let y=s==="start"?u<0:u>0;if(s!=="center"&&!y&&Math.abs(u)<45){this.style.setProperty("--swipe-amount-x","0px"),this.style.setProperty("--swipe-amount-y","0px");return}}this.style.setProperty("--swipe-amount-x",`${u}px`),this.style.setProperty("--swipe-amount-y",`${n}px`)}onPointerUp(t){if(!this.pointerStart)return;try{this.releasePointerCapture(t.pointerId)}catch{}let e=this.swiping;if(this.swiping=!1,!e){this.pointerStart=null,this.dragStartTime=null,this.swipeAxis=null;return}let s=Number.parseFloat(this.style.getPropertyValue("--swipe-amount-x")||"0"),o=Number.parseFloat(this.style.getPropertyValue("--swipe-amount-y")||"0"),l=this.swipeAxis==="x"?s:o,u=this.dragStartTime?Date.now()-this.dragStartTime:0,n=Math.abs(l)/Math.max(u,1);if((Math.abs(l)>=45||n>.11)&&this.dismissible){let{y:E,x:h}=z(this.position);this.swipeAxis==="x"?(this.swipeOutDirection=s<0?"left":"right",h==="start"&&(this.swipeOutDirection="left"),h==="end"&&(this.swipeOutDirection="right")):this.swipeOutDirection=E==="bottom"?"down":"up",this.swipeOut=!0,this.syncDomState(),this.beginRemove()}else this.style.setProperty("--swipe-amount-x","0px"),this.style.setProperty("--swipe-amount-y","0px"),this.swipeAxis=null,this.syncDomState();this.pointerStart=null,this.dragStartTime=null}onCloseClick(t){t.stopPropagation(),this.dismissible&&this.beginRemove()}onActionClick(t){t.stopPropagation(),_.getSnapshot().find(s=>s.id===this.resolvedId)?.action?.onClick(t),this.dismissible&&this.beginRemove()}syncDomState(){let{y:t,x:e}=z(this.position);this.setAttribute("role","listitem"),this.dataset.mounted=String(this.mounted),this.dataset.removed=String(this.removed),this.dataset.swiping=String(this.swiping),this.dataset.swipeOut=String(this.swipeOut),this.dataset.dismissible=String(this.dismissible),this.dataset.yPosition=t,this.dataset.xPosition=e,this.dataset.variant=this.variant??"default",this.swipeOutDirection?this.dataset.swipeDirection=this.swipeOutDirection:delete this.dataset.swipeDirection}iconForVariant(){switch(this.variant){case"success":return"\u2713";case"error":return"\u2715";case"warning":return"!";case"info":return"i";default:return""}}render(){let t=this.variant??"default",e=this.iconForVariant(),s=t!=="default";return te("div",{ref:"toast",class:`rui-toast rui-toast--${t}`,role:"status","aria-live":"off","data-ref":"toast",children:[this.closeButton&&t!=="loading"?K("button",{type:"button",class:"rui-toast__close","data-toast-close":!0,"aria-label":"Close toast",children:"\xD7"}):null,s?K("span",{class:"rui-toast__icon","data-icon":!0,"aria-hidden":"true",children:t==="loading"?K("span",{class:"rui-toast__loader"}):e}):null,te("div",{class:"rui-toast__content",children:[K("div",{class:"rui-toast__title","data-title":!0,children:this.$.title}),this.description?K("div",{class:"rui-toast__description","data-description":!0,children:this.$.description}):null]}),this.actionLabel?K("button",{type:"button",class:"rui-toast__action rui-button rui-button--outline rui-button--sm","data-toast-action":!0,children:this.$.actionLabel}):null]})}static{Dt()}};import{jsx as Et}from"@ecopages/jsx/jsx-runtime";import{RadiantElement as Ae,bound as yt,customElement as ze,onEvent as Ot,onUpdated as Ke,prop as F,state as Ge}from"@ecopages/radiant";function oe(i,t,e){let s=0;for(let o=0;o<i;o+=1)s+=t[o]??0;return s+i*e}function re(i,t){return i.length===0?0:i.reduce((s,o)=>s+o,0)+Math.max(0,i.length-1)*t}function ae(i,t,e){return t<=0?0:i+Math.max(0,t-1)*e}var le,ue,ce,he,de,pe,fe,me,ye,ve,be,ge,Te,_e,Se,xe,we,Ie,Ee,Oe;function qe(i,t,e,s,o,l){var u,n,y,E,h,d,O,j=Symbol.metadata||Symbol.for("Symbol.metadata"),H=Object.defineProperty,R=Object.create,$=[R(null),R(null)],G=t.length;function k(r,g,v){return function(a,c){g&&(c=a,a=i);for(var T=0;T<r.length;T++)c=r[T].apply(a,v?[c]:[]);return v?c:a}}function w(r,g,v,a){if(typeof r!="function"&&(a||r!==void 0))throw new TypeError(g+" must "+(v||"be")+" a function"+(a?"":" or undefined"));return r}function J(r,g,v,a,c,T,P,b,S,x,Z){function N(f){if(!Z(f))throw new TypeError("Attempted to access private element on non-instance")}var q=[].concat(g[0]),tt=g[3],W=!P,D=c===1,et=c===3,it=c===4,U=c===2;function V(f,A,ot){return function(B,rt){return A&&(rt=B,B=r),ot&&ot(B),p[f].call(B,rt)}}if(!W){var p={},Y=[],I=et?"get":it||D?"set":"value";if(S?(x||D?p={get:Pe(function(){return tt(this)},a,"get"),set:function(f){g[4](this,f)}}:p[I]=tt,x||Pe(p[I],a,U?"":I)):x||(p=Object.getOwnPropertyDescriptor(r,a)),!x&&!S){if((n=$[+b][a])&&(n^c)!==7)throw Error("Decorating two elements with the same name ("+p[I].name+") is not supported yet");$[+b][a]=c<3?1:c}}for(var m=r,C=q.length-1;C>=0;C-=v?2:1){var st=w(q[C],"A decorator","be",!0),nt=v?q[C-1]:void 0,X={},L={kind:["field","accessor","method","getter","setter","class"][c],name:a,metadata:u,addInitializer:function(f,A){if(f.v)throw new TypeError("attempted to call addInitializer after decoration was finished");w(A,"An initializer","be",!0),T.push(A)}.bind(null,X)};if(W)n=st.call(nt,m,L),X.v=1,w(n,"class decorators","return")&&(m=n);else if(L.static=b,L.private=S,n=L.access={has:S?Z.bind():function(f){return a in f}},it||(n.get=S?U?function(f){return N(f),p.value}:V("get",0,N):function(f){return f[a]}),U||et||(n.set=S?V("set",0,N):function(f,A){f[a]=A}),m=st.call(nt,D?{get:p.get,set:p.set}:p[I],L),X.v=1,D){if(typeof m=="object"&&m)(n=w(m.get,"accessor.get"))&&(p.get=n),(n=w(m.set,"accessor.set"))&&(p.set=n),(n=w(m.init,"accessor.init"))&&Y.unshift(n);else if(m!==void 0)throw new TypeError("accessor decorators must return an object with get, set, or init properties or undefined")}else w(m,(x?"field":"method")+" decorators","return")&&(x?Y.unshift(m):p[I]=m)}return c<2&&P.push(k(Y,b,1),k(T,b,0)),x||W||(S?D?P.splice(-1,0,V("get",b),V("set",b)):P.push(U?p[I]:w.call.bind(p[I])):H(r,a,p)),m}function Q(r){return H(r,j,{configurable:!0,enumerable:!0,value:u})}return l!==void 0&&(u=l[j]),u=R(u??null),h=[],d=function(r){r&&h.push(k(r))},O=function(r,g){for(var v=0;v<e.length;v++){var a=e[v],c=a[1],T=7&c;if((8&c)==r&&!T==g){var P=a[2],b=!!a[3],S=16&c;J(r?i:i.prototype,a,S,b?"#"+P:We(P),T,T<2?[]:r?E=E||[]:y=y||[],h,!!r,b,g,r&&b?function(x){return Xe(x)===i}:o)}}},O(8,0),O(0,0),O(8,1),O(0,1),d(y),d(E),n=h,G||Q(i),{e:n,get c(){var r=[];return G&&[Q(i=J(i,[t],s,i.name,5,r)),k(r,1)]}}}function We(i){var t=Ye(i,"string");return typeof t=="symbol"?t:t+""}function Ye(i,t){if(typeof i!="object"||!i)return i;var e=i[Symbol.toPrimitive];if(e!==void 0){var s=e.call(i,t||"default");if(typeof s!="object")return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(i)}function Pe(i,t,e){typeof t=="symbol"&&(t=(t=t.description)?"["+t+"]":"");try{Object.defineProperty(i,"name",{configurable:!0,value:e?e+" "+t:t})}catch{}return i}function Xe(i){if(Object(i)!==i)throw TypeError("right-hand side of 'in' should be an object, got "+(i!==null?typeof i:"null"));return i}function De(i,t){return i instanceof Node&&t.contains(i)}var Re,Le=class extends Ae{static{({e:[ce,he,de,pe,fe,me,ye,ve,be,ge,Te,_e,Se,xe,we,Ie,Ee,Oe,le],c:[Re,ue]}=qe(this,[ze("rui-toaster")],[[F({type:String,reflect:!0,defaultValue:ht}),0,"position"],[F({type:Number,defaultValue:4e3}),0,"duration"],[F({type:Number,defaultValue:3}),0,"visibleToasts"],[F({type:Boolean,defaultValue:!1}),0,"closeButton"],[F({type:Boolean,defaultValue:!1}),0,"expand"],[F({type:Number,defaultValue:14}),0,"gap"],[F({type:Number,defaultValue:24}),0,"offset"],[F({type:String,reflect:!0,defaultValue:""}),0,"container"],[Ge,0,"toasts"],[Ke(["position","duration","visibleToasts","closeButton","expand","gap","offset","container"]),2,"onConfigUpdated"],[Ot({document:!0,type:at}),2,"onDocumentShow"],[Ot({document:!0,type:lt}),2,"onDocumentDismiss"],[Ot({selector:"rui-toast",type:"rui-toast-mounted"}),2,"onToastMounted"],[yt,2,"onPointerOver"],[yt,2,"onPointerOut"],[yt,2,"onPointerDown"],[yt,2,"onPointerUp"]],0,void 0,Ae))}position=(le(this),ce(this));duration=(he(this),de(this));visibleToasts=(pe(this),fe(this));closeButton=(me(this),ye(this));expand=(ve(this),be(this));gap=(ge(this),Te(this));offset=(_e(this),Se(this));container=(xe(this),we(this));toasts=(Ie(this),Ee(this,[]));expanded=(Oe(this),!1);interacting=!1;unsubscribe=null;visibilityHandler=null;heights=new Map;observers=new Map;layoutFrame=null;measuring=!1;connectedCallback(){super.connectedCallback(),this.syncHostPosition(),this.syncContainer(),this.unsubscribe=_.subscribe(t=>{this.toasts=t,t.length===0&&this.resetLayoutState(),this.scheduleLayoutSync()}),this.visibilityHandler=()=>this.syncPauseState(),document.addEventListener("visibilitychange",this.visibilityHandler)}disconnectedCallback(){this.unsubscribe?.(),this.unsubscribe=null,this.visibilityHandler&&(document.removeEventListener("visibilitychange",this.visibilityHandler),this.visibilityHandler=null),document.removeEventListener("pointerup",this.onPointerUp),document.removeEventListener("pointercancel",this.onPointerUp),this.layoutFrame!=null&&cancelAnimationFrame(this.layoutFrame),this.resetLayoutState(),super.disconnectedCallback()}onConfigUpdated(){this.syncHostPosition(),this.syncContainer(),this.scheduleLayoutSync()}onDocumentShow(t){let e=t.detail;e?.title&&_.create(e.title,{id:e.id,description:e.description,variant:e.variant,duration:e.duration,action:e.action,dismissible:e.dismissible,closeButton:e.closeButton,position:e.position})}onDocumentDismiss(t){let e=t.detail;_.dismiss(e?.id)}onToastMounted(){this.scheduleLayoutSync()}filteredToasts(){let t=this.toasts.filter(o=>(o.position??this.position)===this.position),e=[],s=[];for(let o of t)o.delete?s.push(o):e.push(o);return[...e.slice(0,this.visibleToasts),...s]}syncHostPosition(){let{y:t,x:e}=z(this.position);this.dataset.yPosition=t,this.dataset.xPosition=e,this.style.setProperty("--width",`${356}px`),this.style.setProperty("--gap",`${this.gap}px`),this.style.setProperty("--viewport-offset",`${this.offset}px`)}syncContainer(){let t=this.container.trim();if(!t){this.removeAttribute("data-contained"),this.style.position="";return}let e=this.closest(t)??document.querySelector(t);if(!e){this.removeAttribute("data-contained"),this.style.position="";return}getComputedStyle(e).position==="static"&&(e.style.position="relative"),e.contains(this)||e.appendChild(this),this.dataset.contained="true",this.style.position="absolute"}isStackExpanded(){return this.expanded||this.expand}isPaused(){return this.expanded||this.interacting||document.hidden}resetLayoutState(){for(let e of this.observers.values())e.disconnect();this.observers.clear(),this.heights.clear(),this.expanded=!1,this.interacting=!1;let t=this.querySelector(".rui-toaster");t&&(t.style.height="0px",t.dataset.expanded="false"),this.dataset.expanded="false"}syncPauseState(){let t=this.isPaused();for(let e of this.querySelectorAll("rui-toast"))e.setPaused(t);this.patchStackLayout()}scheduleLayoutSync(){this.layoutFrame!=null&&cancelAnimationFrame(this.layoutFrame),this.layoutFrame=requestAnimationFrame(()=>{if(this.layoutFrame=null,this.toasts.length>0&&!this.interacting){let e=!!(this.querySelector(".rui-toaster")?.matches(":hover")||this.matches(":hover"));this.expanded=e}this.observeToasts(),this.syncPauseState()})}measureToast(t){this.measuring=!0;let e=t.style.height,s=t.style.overflow;t.style.height="auto",t.style.overflow="visible";let o=t.querySelector(".rui-toast"),l=Math.round(o instanceof HTMLElement?o.offsetHeight:t.offsetHeight)||64;return t.style.height=e,t.style.overflow=s,this.measuring=!1,l}observeToasts(){let t=this.querySelector(".rui-toaster");if(!t)return;let e=[...t.querySelectorAll("rui-toast")],s=new Set;for(let o of e){let l=o.toastId;if(!l)continue;s.add(l);let u=o.querySelector(".rui-toast")??o;if(!this.observers.has(l)){let n=new ResizeObserver(()=>{if(this.measuring)return;let y=this.measureToast(o);this.heights.get(l)!==y&&(this.heights.set(l,y),this.patchStackLayout())});n.observe(u),this.observers.set(l,n)}this.heights.set(l,this.measureToast(o))}for(let[o,l]of[...this.observers])s.has(o)||(l.disconnect(),this.observers.delete(o),this.heights.delete(o))}patchStackLayout(){let t=this.querySelector(".rui-toaster");if(!t)return;let e=this.isStackExpanded(),{y:s}=z(this.position),o=s==="bottom"?-1:1,l=Math.min(3,Math.max(1,this.visibleToasts));this.dataset.expanded=String(e),t.dataset.expanded=String(e),this.style.setProperty("--lift",String(o)),t.style.setProperty("--gap",`${this.gap}px`);let u=[...t.querySelectorAll("rui-toast")].filter(h=>h.dataset.mounted==="true"&&h.dataset.removed!=="true");if(u.length===0){t.style.height="0px";return}let n=u.map(h=>{let d=this.measureToast(h);return this.heights.set(h.toastId,d),d}),y=n[0]??64;this.style.setProperty("--front-toast-height",`${y}px`);for(let h=0;h<u.length;h+=1){let d=u[h];if(!d)continue;let O=n[h]??64,j=h===0,H=oe(h,n,this.gap),R=h<l;if(d.dataset.index=String(h),d.dataset.front=String(j),d.dataset.expanded=String(e),d.dataset.visible=String(e||R),d.style.setProperty("--z-index",String(u.length-h)),d.style.setProperty("--index",String(h)),d.style.setProperty("--offset",`${H}px`),d.style.setProperty("--initial-height",`${O}px`),d.style.setProperty("--gap",`${this.gap}px`),e)d.style.setProperty("--y",`translateY(${o*H}px)`),d.style.height=`${O}px`,d.style.overflow="visible";else if(!R)d.style.setProperty("--y",`translateY(${o*(l-1)*this.gap}px) scale(0.7)`),d.style.height=`${y}px`,d.style.overflow="hidden";else if(j)d.style.setProperty("--y","translateY(0px)"),d.style.height=`${O}px`,d.style.overflow="visible";else{let $=Math.max(.7,1-h*.05);d.style.setProperty("--y",`translateY(${o*h*this.gap}px) scale(${$})`),d.style.height=`${y}px`,d.style.overflow="hidden"}}let E=Math.min(l,u.length);t.style.height=`${e?re(n,this.gap):ae(y,E,this.gap)}px`}onPointerOver(t){De(t.relatedTarget,this)||(this.expanded=!0,this.syncPauseState())}onPointerOut(t){De(t.relatedTarget,this)||this.interacting||(this.expanded=!1,this.syncPauseState())}onPointerDown(){this.interacting=!0,this.expanded=!0,this.syncPauseState(),document.addEventListener("pointerup",this.onPointerUp,{once:!0}),document.addEventListener("pointercancel",this.onPointerUp,{once:!0})}onPointerUp(){if(!this.interacting)return;this.interacting=!1,this.querySelector(".rui-toaster")?.matches(":hover")||this.querySelector("rui-toast:hover")||(this.expanded=!1),this.syncPauseState()}render(){let t=this.filteredToasts();return Et("section",{class:"rui-toaster-region","aria-label":"Notifications","aria-live":"polite","aria-relevant":"additions text","aria-atomic":"false",tabIndex:-1,children:Et("ol",{class:"rui-toaster","data-rui-toaster":!0,"on:pointerover":this.onPointerOver,"on:pointerout":this.onPointerOut,"on:pointerdown":this.onPointerDown,children:t.map(e=>{let s=e.duration??(e.variant==="loading"?Number.POSITIVE_INFINITY:this.duration);return Et("rui-toast",{"prop:toastId":String(e.id),"prop:title":e.title,"prop:description":e.description??"","prop:variant":e.variant,"prop:duration":s,"prop:dismissible":e.dismissible,"prop:closeButton":e.closeButton??this.closeButton,"prop:actionLabel":e.action?.label??"","prop:position":e.position??this.position,"prop:markedDelete":!!e.delete},String(e.id))})})})}static{ue()}};import{jsx as Me}from"@ecopages/jsx/jsx-runtime";function Je({toastId:i,title:t,description:e,variant:s,duration:o,dismissible:l,closeButton:u,actionLabel:n,position:y,markedDelete:E,...h}){return Me("rui-toast",{...h,"prop:toastId":i!=null?String(i):void 0,"prop:title":t,"prop:description":e,"prop:variant":s,"prop:duration":o,"prop:dismissible":l,"prop:closeButton":u,"prop:actionLabel":n,"prop:position":y,"prop:markedDelete":E})}function Qe({children:i,position:t,duration:e,visibleToasts:s,closeButton:o,expand:l,gap:u,offset:n,container:y,...E}){return Me("rui-toaster",{...E,"prop:position":t,"prop:duration":e,"prop:visibleToasts":s,"prop:closeButton":o,"prop:expand":l,"prop:gap":u,"prop:offset":n,"prop:container":y,children:i})}var Ze=Object.assign((i,t)=>_.create(i,t),{message:(i,t)=>_.message(i,t),success:(i,t)=>_.success(i,t),error:(i,t)=>_.error(i,t),info:(i,t)=>_.info(i,t),warning:(i,t)=>_.warning(i,t),loading:(i,t)=>_.loading(i,t),promise:(i,t)=>_.promise(i,t),dismiss:i=>_.dismiss(i),clear:()=>_.clear()});function ti(i){document.dispatchEvent(new CustomEvent(at,{detail:i,bubbles:!0,composed:!0}))}function ei(i){let t=i==null?{}:{id:i};document.dispatchEvent(new CustomEvent(lt,{detail:t,bubbles:!0,composed:!0}))}export{ht as DEFAULT_TOAST_POSITION,lt as RUI_TOAST_DISMISS_EVENT,at as RUI_TOAST_SHOW_EVENT,Je as RuiToast,ne as RuiToastElement,Qe as RuiToaster,Re as RuiToasterElement,_t as TOAST_COLLAPSED_PEEK,St as TOAST_EXIT_MS,bt as TOAST_GAP,ut as TOAST_LIFETIME,ke as TOAST_POSITIONS,ct as TOAST_SWIPE_THRESHOLD,gt as TOAST_VIEWPORT_OFFSET,Tt as TOAST_VISIBLE_AMOUNT,vt as TOAST_WIDTH,ei as dismissToast,ti as showToast,Ze as toast};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|