@prismora/elements 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +21 -2
- package/components.json +15600 -0
- package/custom-elements.json +56320 -0
- package/dist/base.d.ts +42 -0
- package/dist/base.js +62 -0
- package/dist/catalog.d.ts +33 -0
- package/dist/catalog.js +803 -0
- package/dist/components/accordion.d.ts +31 -0
- package/dist/components/accordion.js +63 -0
- package/dist/components/alert.d.ts +27 -0
- package/dist/components/alert.js +40 -0
- package/dist/components/avatar-group.d.ts +23 -0
- package/dist/components/avatar-group.js +43 -0
- package/dist/components/avatar.d.ts +24 -0
- package/dist/components/avatar.js +43 -0
- package/dist/components/back-to-top.d.ts +32 -0
- package/dist/components/back-to-top.js +50 -0
- package/dist/components/badge.d.ts +17 -0
- package/dist/components/badge.js +20 -0
- package/dist/components/banner.d.ts +34 -0
- package/dist/components/banner.js +54 -0
- package/dist/components/breadcrumb.d.ts +42 -0
- package/dist/components/breadcrumb.js +63 -0
- package/dist/components/button-group.d.ts +14 -0
- package/dist/components/button-group.js +28 -0
- package/dist/components/button.d.ts +59 -0
- package/dist/components/button.js +162 -0
- package/dist/components/calendar.d.ts +48 -0
- package/dist/components/calendar.js +296 -0
- package/dist/components/card.d.ts +23 -0
- package/dist/components/card.js +44 -0
- package/dist/components/carousel.d.ts +41 -0
- package/dist/components/carousel.js +156 -0
- package/dist/components/cascader.d.ts +70 -0
- package/dist/components/cascader.js +220 -0
- package/dist/components/chart.d.ts +59 -0
- package/dist/components/chart.js +267 -0
- package/dist/components/chat.d.ts +98 -0
- package/dist/components/chat.js +134 -0
- package/dist/components/checkbox-group.d.ts +48 -0
- package/dist/components/checkbox-group.js +111 -0
- package/dist/components/checkbox.d.ts +23 -0
- package/dist/components/checkbox.js +70 -0
- package/dist/components/code-block.d.ts +46 -0
- package/dist/components/code-block.js +86 -0
- package/dist/components/color-picker.d.ts +46 -0
- package/dist/components/color-picker.js +292 -0
- package/dist/components/combobox.d.ts +89 -0
- package/dist/components/combobox.js +384 -0
- package/dist/components/command.d.ts +96 -0
- package/dist/components/command.js +289 -0
- package/dist/components/context-menu.d.ts +23 -0
- package/dist/components/context-menu.js +110 -0
- package/dist/components/copy-button.d.ts +33 -0
- package/dist/components/copy-button.js +62 -0
- package/dist/components/countdown.d.ts +36 -0
- package/dist/components/countdown.js +56 -0
- package/dist/components/data-table.d.ts +180 -0
- package/dist/components/data-table.js +1060 -0
- package/dist/components/date-picker.d.ts +47 -0
- package/dist/components/date-picker.js +267 -0
- package/dist/components/description-list.d.ts +38 -0
- package/dist/components/description-list.js +41 -0
- package/dist/components/dialog.d.ts +47 -0
- package/dist/components/dialog.js +189 -0
- package/dist/components/divider.d.ts +16 -0
- package/dist/components/divider.js +23 -0
- package/dist/components/drawer.d.ts +19 -0
- package/dist/components/drawer.js +27 -0
- package/dist/components/editor.d.ts +50 -0
- package/dist/components/editor.js +474 -0
- package/dist/components/empty-state.d.ts +24 -0
- package/dist/components/empty-state.js +27 -0
- package/dist/components/file-upload.d.ts +56 -0
- package/dist/components/file-upload.js +176 -0
- package/dist/components/form-control.d.ts +69 -0
- package/dist/components/form-control.js +134 -0
- package/dist/components/form.d.ts +38 -0
- package/dist/components/form.js +161 -0
- package/dist/components/format-number.d.ts +37 -0
- package/dist/components/format-number.js +86 -0
- package/dist/components/icon.d.ts +34 -0
- package/dist/components/icon.js +47 -0
- package/dist/components/image.d.ts +44 -0
- package/dist/components/image.js +53 -0
- package/dist/components/indicator.d.ts +41 -0
- package/dist/components/indicator.js +65 -0
- package/dist/components/inline-edit.d.ts +45 -0
- package/dist/components/inline-edit.js +129 -0
- package/dist/components/input.d.ts +55 -0
- package/dist/components/input.js +186 -0
- package/dist/components/kbd.d.ts +15 -0
- package/dist/components/kbd.js +18 -0
- package/dist/components/list.d.ts +68 -0
- package/dist/components/list.js +180 -0
- package/dist/components/menu.d.ts +22 -0
- package/dist/components/menu.js +182 -0
- package/dist/components/menubar.d.ts +20 -0
- package/dist/components/menubar.js +120 -0
- package/dist/components/meter.d.ts +38 -0
- package/dist/components/meter.js +48 -0
- package/dist/components/nav.d.ts +91 -0
- package/dist/components/nav.js +228 -0
- package/dist/components/number-input.d.ts +26 -0
- package/dist/components/number-input.js +70 -0
- package/dist/components/pagination.d.ts +44 -0
- package/dist/components/pagination.js +94 -0
- package/dist/components/pin-input.d.ts +25 -0
- package/dist/components/pin-input.js +128 -0
- package/dist/components/popover.d.ts +23 -0
- package/dist/components/popover.js +140 -0
- package/dist/components/progress.d.ts +26 -0
- package/dist/components/progress.js +66 -0
- package/dist/components/pull-refresh.d.ts +41 -0
- package/dist/components/pull-refresh.js +101 -0
- package/dist/components/qr-code.d.ts +33 -0
- package/dist/components/qr-code.js +54 -0
- package/dist/components/radio-group.d.ts +37 -0
- package/dist/components/radio-group.js +82 -0
- package/dist/components/range-slider.d.ts +46 -0
- package/dist/components/range-slider.js +95 -0
- package/dist/components/rating.d.ts +38 -0
- package/dist/components/rating.js +80 -0
- package/dist/components/relative-time.d.ts +31 -0
- package/dist/components/relative-time.js +51 -0
- package/dist/components/scheduler.d.ts +84 -0
- package/dist/components/scheduler.js +187 -0
- package/dist/components/segmented.d.ts +58 -0
- package/dist/components/segmented.js +129 -0
- package/dist/components/select.d.ts +62 -0
- package/dist/components/select.js +140 -0
- package/dist/components/share-button.d.ts +37 -0
- package/dist/components/share-button.js +60 -0
- package/dist/components/signature.d.ts +54 -0
- package/dist/components/signature.js +152 -0
- package/dist/components/skeleton.d.ts +21 -0
- package/dist/components/skeleton.js +26 -0
- package/dist/components/slider.d.ts +31 -0
- package/dist/components/slider.js +80 -0
- package/dist/components/sortable.d.ts +22 -0
- package/dist/components/sortable.js +196 -0
- package/dist/components/sparkline.d.ts +28 -0
- package/dist/components/sparkline.js +46 -0
- package/dist/components/spinner.d.ts +16 -0
- package/dist/components/spinner.js +22 -0
- package/dist/components/splitter.d.ts +28 -0
- package/dist/components/splitter.js +89 -0
- package/dist/components/stat.d.ts +28 -0
- package/dist/components/stat.js +33 -0
- package/dist/components/steps.d.ts +53 -0
- package/dist/components/steps.js +91 -0
- package/dist/components/switch.d.ts +12 -0
- package/dist/components/switch.js +18 -0
- package/dist/components/table.d.ts +58 -0
- package/dist/components/table.js +96 -0
- package/dist/components/tabs.d.ts +62 -0
- package/dist/components/tabs.js +310 -0
- package/dist/components/tag.d.ts +32 -0
- package/dist/components/tag.js +58 -0
- package/dist/components/textarea.d.ts +25 -0
- package/dist/components/textarea.js +56 -0
- package/dist/components/theme-switch.d.ts +51 -0
- package/dist/components/theme-switch.js +85 -0
- package/dist/components/time-picker.d.ts +39 -0
- package/dist/components/time-picker.js +257 -0
- package/dist/components/timeline.d.ts +38 -0
- package/dist/components/timeline.js +56 -0
- package/dist/components/toaster.d.ts +25 -0
- package/dist/components/toaster.js +44 -0
- package/dist/components/toggle-group.d.ts +70 -0
- package/dist/components/toggle-group.js +172 -0
- package/dist/components/toolbar.d.ts +23 -0
- package/dist/components/toolbar.js +81 -0
- package/dist/components/tooltip.d.ts +18 -0
- package/dist/components/tooltip.js +92 -0
- package/dist/components/tour.d.ts +41 -0
- package/dist/components/tour.js +197 -0
- package/dist/components/transfer.d.ts +57 -0
- package/dist/components/transfer.js +161 -0
- package/dist/components/tree-select.d.ts +66 -0
- package/dist/components/tree-select.js +282 -0
- package/dist/components/tree.d.ts +129 -0
- package/dist/components/tree.js +427 -0
- package/dist/components/virtual-list.d.ts +41 -0
- package/dist/components/virtual-list.js +77 -0
- package/dist/confirm.d.ts +21 -0
- package/dist/confirm.js +69 -0
- package/dist/count.d.ts +5 -0
- package/dist/count.js +12 -0
- package/dist/data-table/icons.d.ts +8 -0
- package/dist/data-table/icons.js +10 -0
- package/dist/data-table/logic.d.ts +33 -0
- package/dist/data-table/logic.js +141 -0
- package/dist/data-table/strings.d.ts +37 -0
- package/dist/data-table/strings.js +36 -0
- package/dist/data-table/types.d.ts +76 -0
- package/dist/data-table/types.js +1 -0
- package/dist/define.d.ts +2 -0
- package/dist/define.js +2 -0
- package/dist/field-validity.d.ts +42 -0
- package/dist/field-validity.js +58 -0
- package/dist/floating.d.ts +13 -0
- package/dist/floating.js +65 -0
- package/dist/highlight.d.ts +11 -0
- package/dist/highlight.js +103 -0
- package/dist/id.d.ts +2 -0
- package/dist/id.js +3 -0
- package/dist/index.d.ts +102 -0
- package/dist/index.js +102 -0
- package/dist/manifest.d.ts +51 -0
- package/dist/manifest.js +11 -0
- package/dist/named-icon.d.ts +8 -0
- package/dist/named-icon.js +8 -0
- package/dist/patterns/account.d.ts +6 -0
- package/dist/patterns/account.js +137 -0
- package/dist/patterns/app.d.ts +7 -0
- package/dist/patterns/app.js +351 -0
- package/dist/patterns/commerce.d.ts +4 -0
- package/dist/patterns/commerce.js +200 -0
- package/dist/patterns/flows.d.ts +3 -0
- package/dist/patterns/flows.js +100 -0
- package/dist/patterns/index.d.ts +9 -0
- package/dist/patterns/index.js +29 -0
- package/dist/patterns/marketing.d.ts +4 -0
- package/dist/patterns/marketing.js +173 -0
- package/dist/patterns/more.d.ts +15 -0
- package/dist/patterns/more.js +581 -0
- package/dist/patterns/shell.d.ts +9 -0
- package/dist/patterns/shell.js +48 -0
- package/dist/patterns/types.d.ts +19 -0
- package/dist/patterns/types.js +1 -0
- package/dist/position.d.ts +2 -0
- package/dist/position.js +33 -0
- package/dist/prismora.standalone.js +5222 -0
- package/dist/prismora.standalone.js.map +199 -0
- package/dist/qr.d.ts +14 -0
- package/dist/qr.js +258 -0
- package/dist/register.d.ts +8 -0
- package/dist/register.js +21 -0
- package/dist/registry.d.ts +203 -0
- package/dist/registry.js +203 -0
- package/dist/remote.d.ts +58 -0
- package/dist/remote.js +130 -0
- package/dist/sheet.d.ts +34 -0
- package/dist/sheet.js +153 -0
- package/dist/styles/accordion.d.ts +2 -0
- package/dist/styles/accordion.js +3 -0
- package/dist/styles/alert.d.ts +2 -0
- package/dist/styles/alert.js +3 -0
- package/dist/styles/avatar.d.ts +2 -0
- package/dist/styles/avatar.js +3 -0
- package/dist/styles/badge.d.ts +2 -0
- package/dist/styles/badge.js +3 -0
- package/dist/styles/banner.d.ts +2 -0
- package/dist/styles/banner.js +3 -0
- package/dist/styles/breadcrumb.d.ts +2 -0
- package/dist/styles/breadcrumb.js +3 -0
- package/dist/styles/button.d.ts +2 -0
- package/dist/styles/button.js +3 -0
- package/dist/styles/calendar.d.ts +2 -0
- package/dist/styles/calendar.js +3 -0
- package/dist/styles/card.d.ts +2 -0
- package/dist/styles/card.js +3 -0
- package/dist/styles/carousel.d.ts +2 -0
- package/dist/styles/carousel.js +3 -0
- package/dist/styles/chart.d.ts +2 -0
- package/dist/styles/chart.js +3 -0
- package/dist/styles/chat.d.ts +2 -0
- package/dist/styles/chat.js +3 -0
- package/dist/styles/checkbox.d.ts +2 -0
- package/dist/styles/checkbox.js +3 -0
- package/dist/styles/color-picker.d.ts +2 -0
- package/dist/styles/color-picker.js +3 -0
- package/dist/styles/combobox.d.ts +2 -0
- package/dist/styles/combobox.js +3 -0
- package/dist/styles/command.d.ts +2 -0
- package/dist/styles/command.js +3 -0
- package/dist/styles/data-table.d.ts +2 -0
- package/dist/styles/data-table.js +3 -0
- package/dist/styles/description-list.d.ts +2 -0
- package/dist/styles/description-list.js +3 -0
- package/dist/styles/dialog.d.ts +2 -0
- package/dist/styles/dialog.js +3 -0
- package/dist/styles/drawer.d.ts +2 -0
- package/dist/styles/drawer.js +3 -0
- package/dist/styles/editor.d.ts +2 -0
- package/dist/styles/editor.js +3 -0
- package/dist/styles/empty-state.d.ts +2 -0
- package/dist/styles/empty-state.js +3 -0
- package/dist/styles/extras.d.ts +2 -0
- package/dist/styles/extras.js +3 -0
- package/dist/styles/field.d.ts +2 -0
- package/dist/styles/field.js +3 -0
- package/dist/styles/file-upload.d.ts +2 -0
- package/dist/styles/file-upload.js +3 -0
- package/dist/styles/foundation.d.ts +2 -0
- package/dist/styles/foundation.js +3 -0
- package/dist/styles/helpers.d.ts +2 -0
- package/dist/styles/helpers.js +3 -0
- package/dist/styles/icon.d.ts +2 -0
- package/dist/styles/icon.js +3 -0
- package/dist/styles/image.d.ts +2 -0
- package/dist/styles/image.js +3 -0
- package/dist/styles/indicator.d.ts +2 -0
- package/dist/styles/indicator.js +3 -0
- package/dist/styles/input.d.ts +2 -0
- package/dist/styles/input.js +3 -0
- package/dist/styles/kbd.d.ts +2 -0
- package/dist/styles/kbd.js +3 -0
- package/dist/styles/list.d.ts +2 -0
- package/dist/styles/list.js +3 -0
- package/dist/styles/listbox.d.ts +2 -0
- package/dist/styles/listbox.js +3 -0
- package/dist/styles/meter.d.ts +2 -0
- package/dist/styles/meter.js +3 -0
- package/dist/styles/nav.d.ts +2 -0
- package/dist/styles/nav.js +3 -0
- package/dist/styles/number-input.d.ts +2 -0
- package/dist/styles/number-input.js +3 -0
- package/dist/styles/overlay.d.ts +2 -0
- package/dist/styles/overlay.js +3 -0
- package/dist/styles/pagination.d.ts +2 -0
- package/dist/styles/pagination.js +3 -0
- package/dist/styles/pickers.d.ts +2 -0
- package/dist/styles/pickers.js +3 -0
- package/dist/styles/pin-input.d.ts +2 -0
- package/dist/styles/pin-input.js +3 -0
- package/dist/styles/popover.d.ts +2 -0
- package/dist/styles/popover.js +3 -0
- package/dist/styles/progress.d.ts +2 -0
- package/dist/styles/progress.js +3 -0
- package/dist/styles/pull-refresh.d.ts +2 -0
- package/dist/styles/pull-refresh.js +3 -0
- package/dist/styles/range-slider.d.ts +2 -0
- package/dist/styles/range-slider.js +3 -0
- package/dist/styles/rating.d.ts +2 -0
- package/dist/styles/rating.js +3 -0
- package/dist/styles/scheduler.d.ts +2 -0
- package/dist/styles/scheduler.js +3 -0
- package/dist/styles/segmented.d.ts +2 -0
- package/dist/styles/segmented.js +3 -0
- package/dist/styles/select.d.ts +2 -0
- package/dist/styles/select.js +3 -0
- package/dist/styles/separator.d.ts +2 -0
- package/dist/styles/separator.js +3 -0
- package/dist/styles/sheet.d.ts +2 -0
- package/dist/styles/sheet.js +3 -0
- package/dist/styles/skeleton.d.ts +2 -0
- package/dist/styles/skeleton.js +3 -0
- package/dist/styles/slider.d.ts +2 -0
- package/dist/styles/slider.js +3 -0
- package/dist/styles/sortable.d.ts +2 -0
- package/dist/styles/sortable.js +3 -0
- package/dist/styles/spinner.d.ts +2 -0
- package/dist/styles/spinner.js +3 -0
- package/dist/styles/splitter.d.ts +2 -0
- package/dist/styles/splitter.js +3 -0
- package/dist/styles/stat.d.ts +2 -0
- package/dist/styles/stat.js +3 -0
- package/dist/styles/steps.d.ts +2 -0
- package/dist/styles/steps.js +3 -0
- package/dist/styles/surface.d.ts +2 -0
- package/dist/styles/surface.js +3 -0
- package/dist/styles/switch.d.ts +2 -0
- package/dist/styles/switch.js +3 -0
- package/dist/styles/table.d.ts +2 -0
- package/dist/styles/table.js +3 -0
- package/dist/styles/tabs.d.ts +2 -0
- package/dist/styles/tabs.js +3 -0
- package/dist/styles/tag.d.ts +2 -0
- package/dist/styles/tag.js +3 -0
- package/dist/styles/time-picker.d.ts +2 -0
- package/dist/styles/time-picker.js +3 -0
- package/dist/styles/timeline.d.ts +2 -0
- package/dist/styles/timeline.js +3 -0
- package/dist/styles/toast.d.ts +2 -0
- package/dist/styles/toast.js +3 -0
- package/dist/styles/toggle.d.ts +2 -0
- package/dist/styles/toggle.js +3 -0
- package/dist/styles/toolbar.d.ts +2 -0
- package/dist/styles/toolbar.js +3 -0
- package/dist/styles/tooltip.d.ts +2 -0
- package/dist/styles/tooltip.js +3 -0
- package/dist/styles/tree.d.ts +2 -0
- package/dist/styles/tree.js +3 -0
- package/dist/table-core.d.ts +75 -0
- package/dist/table-core.js +205 -0
- package/dist/toast.d.ts +42 -0
- package/dist/toast.js +206 -0
- package/dist/top-layer.d.ts +4 -0
- package/dist/top-layer.js +33 -0
- package/package.json +101 -4
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Inline icons used by `<pm-data-table>` (no icon registry needed). */
|
|
2
|
+
import { html } from 'lit';
|
|
3
|
+
export const ICON = {
|
|
4
|
+
dots: html `<svg viewBox="0 0 24 24" width="1em" height="1em" fill="currentColor" aria-hidden="true"><circle cx="12" cy="5" r="1.6"/><circle cx="12" cy="12" r="1.6"/><circle cx="12" cy="19" r="1.6"/></svg>`,
|
|
5
|
+
chev: html `<svg viewBox="0 0 24 24" width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 6l6 6-6 6"/></svg>`,
|
|
6
|
+
search: html `<svg viewBox="0 0 24 24" width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="M20 20l-3.5-3.5"/></svg>`,
|
|
7
|
+
columns: html `<svg viewBox="0 0 24 24" width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="4" width="18" height="16" rx="2"/><path d="M9 4v16M15 4v16"/></svg>`,
|
|
8
|
+
download: html `<svg viewBox="0 0 24 24" width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 4v11M7 10l5 5 5-5M5 20h14"/></svg>`,
|
|
9
|
+
pin: html `<svg viewBox="0 0 24 24" width="0.85em" height="0.85em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 17v4M8 3h8l-1 6 3 3v2H6v-2l3-3z"/></svg>`,
|
|
10
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOM-free data logic of `<pm-data-table>`: column filters, grouping, merged cells, aggregates and CSV.
|
|
3
|
+
* Pure functions, so they are unit-tested without a browser and reusable server-side (e.g. the same CSV on export).
|
|
4
|
+
*/
|
|
5
|
+
import { type Row } from '../table-core.js';
|
|
6
|
+
import type { DataTableColumn, DataTableItem, DataTableQuery } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Number filter. Accepts `>10`, `<=5`, `!=0`, `=3`, `3`, and ranges `10..20` (either end optional).
|
|
9
|
+
* Anything else falls back to a case-insensitive text match.
|
|
10
|
+
*/
|
|
11
|
+
export declare function matchNumber(v: unknown, q: string): boolean;
|
|
12
|
+
/** Rows interleaved with group headers for `groupBy` (rows must already be sorted by it). Collapsed groups hide their rows. */
|
|
13
|
+
export declare function groupItems<R extends Row>(rows: R[], groupBy: string | undefined, collapsed?: ReadonlySet<string>): DataTableItem<R>[];
|
|
14
|
+
/**
|
|
15
|
+
* Row spans for columns with `merge`: per column, `spans[i]` is the rowspan of item i (0 = covered by the cell above).
|
|
16
|
+
* Runs stop at group headers and after rows for which `breakAfter(row)` is true (e.g. an expanded detail row).
|
|
17
|
+
*/
|
|
18
|
+
export declare function mergeSpans<R extends Row>(cols: DataTableColumn<R>[], items: DataTableItem<R>[], breakAfter?: (row: R) => boolean): Map<string, number[]>;
|
|
19
|
+
/**
|
|
20
|
+
* Raw footer/group summary for a column's `aggregate` (before formatting): a number for the built-ins, whatever a
|
|
21
|
+
* custom function returns, or `undefined` when there is nothing to summarise.
|
|
22
|
+
*/
|
|
23
|
+
export declare function aggregateValue<R extends Row>(c: DataTableColumn<R>, rows: R[]): unknown;
|
|
24
|
+
/** One CSV field. Formula-like text (`=`, `+`, `-`, `@`, tab, CR) is prefixed with `'` so spreadsheets do not run it. */
|
|
25
|
+
export declare function csvField(v: unknown): string;
|
|
26
|
+
/** RFC 4180 CSV (CRLF line ends) with a header row of column labels; `exportValue` overrides a column's raw value. */
|
|
27
|
+
export declare function toCsv<R extends Row>(cols: DataTableColumn<R>[], rows: R[]): string;
|
|
28
|
+
/**
|
|
29
|
+
* URL parameters for a server request (`src`): `q`, `page`, `pageSize`, `sort` + `order` (first level),
|
|
30
|
+
* `sorts` (`key:dir,key:dir` for all levels) and `filter[key]` per column filter. Empty values are omitted.
|
|
31
|
+
* Use any of them as `{placeholders}` in the `src` template; the rest are appended as query parameters.
|
|
32
|
+
*/
|
|
33
|
+
export declare function queryParams(q: DataTableQuery): Record<string, string | number | undefined>;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOM-free data logic of `<pm-data-table>`: column filters, grouping, merged cells, aggregates and CSV.
|
|
3
|
+
* Pure functions, so they are unit-tested without a browser and reusable server-side (e.g. the same CSV on export).
|
|
4
|
+
*/
|
|
5
|
+
import { compare } from '../table-core.js';
|
|
6
|
+
/**
|
|
7
|
+
* Number filter. Accepts `>10`, `<=5`, `!=0`, `=3`, `3`, and ranges `10..20` (either end optional).
|
|
8
|
+
* Anything else falls back to a case-insensitive text match.
|
|
9
|
+
*/
|
|
10
|
+
export function matchNumber(v, q) {
|
|
11
|
+
const n = typeof v === 'number' ? v : Number(v);
|
|
12
|
+
const s = q.replace(/\s+/g, '');
|
|
13
|
+
if (s.includes('..')) {
|
|
14
|
+
const [a, b] = s.split('..');
|
|
15
|
+
return Number.isFinite(n) && (!a || n >= Number(a)) && (!b || n <= Number(b));
|
|
16
|
+
}
|
|
17
|
+
const m = s.match(/^(>=|<=|!=|>|<|=)?(-?\d*\.?\d+)$/);
|
|
18
|
+
if (!m)
|
|
19
|
+
return String(v ?? '').toLowerCase().includes(q.toLowerCase());
|
|
20
|
+
if (!Number.isFinite(n))
|
|
21
|
+
return false;
|
|
22
|
+
const x = Number(m[2]);
|
|
23
|
+
switch (m[1]) {
|
|
24
|
+
case '>': return n > x;
|
|
25
|
+
case '<': return n < x;
|
|
26
|
+
case '>=': return n >= x;
|
|
27
|
+
case '<=': return n <= x;
|
|
28
|
+
case '!=': return n !== x;
|
|
29
|
+
default: return n === x;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** Rows interleaved with group headers for `groupBy` (rows must already be sorted by it). Collapsed groups hide their rows. */
|
|
33
|
+
export function groupItems(rows, groupBy, collapsed = new Set()) {
|
|
34
|
+
if (!groupBy)
|
|
35
|
+
return rows.map((row) => ({ type: 'row', row }));
|
|
36
|
+
const groups = [];
|
|
37
|
+
for (const row of rows) {
|
|
38
|
+
const v = String(row[groupBy] ?? '');
|
|
39
|
+
const last = groups[groups.length - 1];
|
|
40
|
+
if (last && last.value === v) {
|
|
41
|
+
last.rows.push(row);
|
|
42
|
+
last.count++;
|
|
43
|
+
}
|
|
44
|
+
else
|
|
45
|
+
groups.push({ type: 'group', value: v, first: row, count: 1, rows: [row] });
|
|
46
|
+
}
|
|
47
|
+
const out = [];
|
|
48
|
+
for (const grp of groups) {
|
|
49
|
+
out.push(grp);
|
|
50
|
+
if (!collapsed.has(grp.value))
|
|
51
|
+
for (const row of grp.rows)
|
|
52
|
+
out.push({ type: 'row', row });
|
|
53
|
+
}
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Row spans for columns with `merge`: per column, `spans[i]` is the rowspan of item i (0 = covered by the cell above).
|
|
58
|
+
* Runs stop at group headers and after rows for which `breakAfter(row)` is true (e.g. an expanded detail row).
|
|
59
|
+
*/
|
|
60
|
+
export function mergeSpans(cols, items, breakAfter = () => false) {
|
|
61
|
+
const spans = new Map();
|
|
62
|
+
for (const c of cols) {
|
|
63
|
+
if (!c.merge)
|
|
64
|
+
continue;
|
|
65
|
+
const eq = typeof c.merge === 'function' ? c.merge : (a, b) => compare(a[c.key], b[c.key]) === 0;
|
|
66
|
+
const arr = new Array(items.length).fill(1);
|
|
67
|
+
for (let i = 0; i < items.length; i++) {
|
|
68
|
+
const it = items[i];
|
|
69
|
+
if (it.type !== 'row' || arr[i] === 0)
|
|
70
|
+
continue;
|
|
71
|
+
let j = i + 1;
|
|
72
|
+
while (j < items.length) {
|
|
73
|
+
const next = items[j];
|
|
74
|
+
const prev = items[j - 1];
|
|
75
|
+
if (next.type !== 'row' || (prev.type === 'row' && breakAfter(prev.row)) || !eq(it.row, next.row))
|
|
76
|
+
break;
|
|
77
|
+
arr[j] = 0;
|
|
78
|
+
j++;
|
|
79
|
+
}
|
|
80
|
+
arr[i] = j - i;
|
|
81
|
+
}
|
|
82
|
+
spans.set(c.key, arr);
|
|
83
|
+
}
|
|
84
|
+
return spans;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Raw footer/group summary for a column's `aggregate` (before formatting): a number for the built-ins, whatever a
|
|
88
|
+
* custom function returns, or `undefined` when there is nothing to summarise.
|
|
89
|
+
*/
|
|
90
|
+
export function aggregateValue(c, rows) {
|
|
91
|
+
const a = c.aggregate;
|
|
92
|
+
if (!a)
|
|
93
|
+
return undefined;
|
|
94
|
+
if (typeof a === 'function')
|
|
95
|
+
return a(rows);
|
|
96
|
+
if (a === 'count')
|
|
97
|
+
return rows.length;
|
|
98
|
+
// Blank cells are skipped (Number(null) and Number('') would otherwise count as 0).
|
|
99
|
+
const nums = rows
|
|
100
|
+
.map((r) => (c.sortValue ? c.sortValue(r) : r[c.key]))
|
|
101
|
+
.filter((v) => v != null && v !== '')
|
|
102
|
+
.map(Number)
|
|
103
|
+
.filter(Number.isFinite);
|
|
104
|
+
if (!nums.length)
|
|
105
|
+
return undefined;
|
|
106
|
+
const sum = () => nums.reduce((s, x) => s + x, 0);
|
|
107
|
+
return a === 'sum' ? sum() : a === 'avg' ? sum() / nums.length : a === 'min' ? Math.min(...nums) : Math.max(...nums);
|
|
108
|
+
}
|
|
109
|
+
/** One CSV field. Formula-like text (`=`, `+`, `-`, `@`, tab, CR) is prefixed with `'` so spreadsheets do not run it. */
|
|
110
|
+
export function csvField(v) {
|
|
111
|
+
let s = v == null ? '' : v instanceof Date ? v.toISOString() : String(v);
|
|
112
|
+
if (typeof v === 'string' && /^[=+\-@\t\r]/.test(s))
|
|
113
|
+
s = `'${s}`;
|
|
114
|
+
return /[",\n\r]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s;
|
|
115
|
+
}
|
|
116
|
+
/** RFC 4180 CSV (CRLF line ends) with a header row of column labels; `exportValue` overrides a column's raw value. */
|
|
117
|
+
export function toCsv(cols, rows) {
|
|
118
|
+
return [
|
|
119
|
+
cols.map((c) => csvField(c.label)).join(','),
|
|
120
|
+
...rows.map((r) => cols.map((c) => csvField(c.exportValue ? c.exportValue(r) : r[c.key])).join(',')),
|
|
121
|
+
].join('\r\n');
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* URL parameters for a server request (`src`): `q`, `page`, `pageSize`, `sort` + `order` (first level),
|
|
125
|
+
* `sorts` (`key:dir,key:dir` for all levels) and `filter[key]` per column filter. Empty values are omitted.
|
|
126
|
+
* Use any of them as `{placeholders}` in the `src` template; the rest are appended as query parameters.
|
|
127
|
+
*/
|
|
128
|
+
export function queryParams(q) {
|
|
129
|
+
const out = {
|
|
130
|
+
q: q.filter.trim() || undefined,
|
|
131
|
+
page: q.page,
|
|
132
|
+
pageSize: q.pageSize || undefined,
|
|
133
|
+
sort: q.sorts[0]?.key,
|
|
134
|
+
order: q.sorts[0]?.direction,
|
|
135
|
+
sorts: q.sorts.length > 1 ? q.sorts.map((s) => `${s.key}:${s.direction}`).join(',') : undefined,
|
|
136
|
+
};
|
|
137
|
+
for (const [k, v] of Object.entries(q.filters))
|
|
138
|
+
if (v?.trim())
|
|
139
|
+
out[`filter[${k}]`] = v.trim();
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** UI text; override any of it with the `strings` property (e.g. for translations). `{n}`-style placeholders are filled in. */
|
|
2
|
+
export declare const DATA_TABLE_STRINGS: {
|
|
3
|
+
search: string;
|
|
4
|
+
empty: string;
|
|
5
|
+
selectAll: string;
|
|
6
|
+
selectRow: string;
|
|
7
|
+
selected: string;
|
|
8
|
+
selectAllMatching: string;
|
|
9
|
+
clearSelection: string;
|
|
10
|
+
columns: string;
|
|
11
|
+
resetColumns: string;
|
|
12
|
+
exportCsv: string;
|
|
13
|
+
sortAsc: string;
|
|
14
|
+
sortDesc: string;
|
|
15
|
+
clearSort: string;
|
|
16
|
+
pinStart: string;
|
|
17
|
+
pinEnd: string;
|
|
18
|
+
unpin: string;
|
|
19
|
+
hide: string;
|
|
20
|
+
moveLeft: string;
|
|
21
|
+
moveRight: string;
|
|
22
|
+
groupBy: string;
|
|
23
|
+
ungroup: string;
|
|
24
|
+
columnActions: string;
|
|
25
|
+
filter: string;
|
|
26
|
+
all: string;
|
|
27
|
+
resize: string;
|
|
28
|
+
expand: string;
|
|
29
|
+
total: string;
|
|
30
|
+
range: string;
|
|
31
|
+
pages: string;
|
|
32
|
+
loadError: string;
|
|
33
|
+
retry: string;
|
|
34
|
+
};
|
|
35
|
+
export type DataTableStrings = typeof DATA_TABLE_STRINGS;
|
|
36
|
+
/** Fill `{name}` placeholders in a UI string. */
|
|
37
|
+
export declare const fillString: (s: string, v: Record<string, unknown>) => string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** UI text; override any of it with the `strings` property (e.g. for translations). `{n}`-style placeholders are filled in. */
|
|
2
|
+
export const DATA_TABLE_STRINGS = {
|
|
3
|
+
search: 'Search',
|
|
4
|
+
empty: 'No results',
|
|
5
|
+
selectAll: 'Select all rows on this page',
|
|
6
|
+
selectRow: 'Select row',
|
|
7
|
+
selected: '{n} selected',
|
|
8
|
+
selectAllMatching: 'Select all {n}',
|
|
9
|
+
clearSelection: 'Clear selection',
|
|
10
|
+
columns: 'Columns',
|
|
11
|
+
resetColumns: 'Reset columns',
|
|
12
|
+
exportCsv: 'Export CSV',
|
|
13
|
+
sortAsc: 'Sort ascending',
|
|
14
|
+
sortDesc: 'Sort descending',
|
|
15
|
+
clearSort: 'Clear sort',
|
|
16
|
+
pinStart: 'Pin to start',
|
|
17
|
+
pinEnd: 'Pin to end',
|
|
18
|
+
unpin: 'Unpin',
|
|
19
|
+
hide: 'Hide column',
|
|
20
|
+
moveLeft: 'Move left',
|
|
21
|
+
moveRight: 'Move right',
|
|
22
|
+
groupBy: 'Group by this column',
|
|
23
|
+
ungroup: 'Remove grouping',
|
|
24
|
+
columnActions: '{label} column actions',
|
|
25
|
+
filter: 'Filter {label}',
|
|
26
|
+
all: 'All',
|
|
27
|
+
resize: 'Resize {label}',
|
|
28
|
+
expand: 'Show details',
|
|
29
|
+
total: 'Total',
|
|
30
|
+
range: '{from}–{to} of {total}',
|
|
31
|
+
pages: '{label} pages',
|
|
32
|
+
loadError: "Couldn't load data.",
|
|
33
|
+
retry: 'Retry',
|
|
34
|
+
};
|
|
35
|
+
/** Fill `{name}` placeholders in a UI string. */
|
|
36
|
+
export const fillString = (s, v) => s.replace(/\{(\w+)\}/g, (_, k) => String(v[k] ?? ''));
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/** Public types of `<pm-data-table>`: column definitions, saved view state and render items. */
|
|
2
|
+
import type { Row, SortState, TableColumn } from '../table-core.js';
|
|
3
|
+
export interface DataTableColumn<R extends Row = Row> extends TableColumn<R> {
|
|
4
|
+
/** Filter control in the header's filter row. `number` accepts `>10`, `<=5`, `10..20`, `!=0`. */
|
|
5
|
+
filter?: 'text' | 'select' | 'number' | false;
|
|
6
|
+
/** Choices for `filter: 'select'` and the cell editor (default: the column's distinct values). */
|
|
7
|
+
options?: (string | {
|
|
8
|
+
value: string;
|
|
9
|
+
label: string;
|
|
10
|
+
})[];
|
|
11
|
+
/** Custom filter test. */
|
|
12
|
+
filterFn?: (row: R, query: string) => boolean;
|
|
13
|
+
/** Freeze the column at the start or end edge while scrolling sideways. */
|
|
14
|
+
pin?: 'start' | 'end';
|
|
15
|
+
/** Start hidden (users can show it from the Columns menu). */
|
|
16
|
+
hidden?: boolean;
|
|
17
|
+
/** Allow hiding from the Columns menu (default true). */
|
|
18
|
+
hideable?: boolean;
|
|
19
|
+
/** Drag the header edge to resize (default true). */
|
|
20
|
+
resizable?: boolean;
|
|
21
|
+
/** Minimum width in px when resizing (default 56). */
|
|
22
|
+
minWidth?: number;
|
|
23
|
+
/** Header group: consecutive columns with the same group share a merged header cell. */
|
|
24
|
+
group?: string;
|
|
25
|
+
/** Merge consecutive equal cells vertically (rowspan). Pass a function to decide what "equal" means. */
|
|
26
|
+
merge?: boolean | ((a: R, b: R) => boolean);
|
|
27
|
+
/** Merge this cell across the next N-1 columns for a row (colspan). */
|
|
28
|
+
colSpan?: (row: R) => number;
|
|
29
|
+
/** Footer summary over all filtered rows. */
|
|
30
|
+
aggregate?: 'sum' | 'avg' | 'min' | 'max' | 'count' | ((rows: R[]) => unknown);
|
|
31
|
+
/** Inline editing (double-click, Enter or F2). Commits fire a cancelable `pm-cell-edit`. */
|
|
32
|
+
editable?: boolean | ((row: R) => boolean);
|
|
33
|
+
/** Value written by `toCsv()` (default: the raw value). */
|
|
34
|
+
exportValue?: (row: R) => unknown;
|
|
35
|
+
}
|
|
36
|
+
/** Everything a user can change; save it (or set `persist`) to restore their view. */
|
|
37
|
+
export interface DataTableState {
|
|
38
|
+
sorts: SortState[];
|
|
39
|
+
filters: Record<string, string>;
|
|
40
|
+
filter: string;
|
|
41
|
+
hidden: string[];
|
|
42
|
+
pins: Record<string, 'start' | 'end' | null>;
|
|
43
|
+
widths: Record<string, number>;
|
|
44
|
+
order: string[];
|
|
45
|
+
groupBy?: string;
|
|
46
|
+
pageSize: number;
|
|
47
|
+
}
|
|
48
|
+
/** A row to render, or a group header (with its rows) when `group-by` is set. */
|
|
49
|
+
export type DataTableItem<R> = {
|
|
50
|
+
type: 'group';
|
|
51
|
+
value: string;
|
|
52
|
+
first: R;
|
|
53
|
+
count: number;
|
|
54
|
+
rows: R[];
|
|
55
|
+
} | {
|
|
56
|
+
type: 'row';
|
|
57
|
+
row: R;
|
|
58
|
+
};
|
|
59
|
+
/** What a server needs to return one page: sent to `loader`, or turned into `src` URL parameters. */
|
|
60
|
+
export interface DataTableQuery {
|
|
61
|
+
/** 1-based page. */
|
|
62
|
+
page: number;
|
|
63
|
+
/** Rows per page (0 = no paging). */
|
|
64
|
+
pageSize: number;
|
|
65
|
+
/** Global search text. */
|
|
66
|
+
filter: string;
|
|
67
|
+
/** Per-column filter text by column key. */
|
|
68
|
+
filters: Record<string, string>;
|
|
69
|
+
/** Sort levels, most important first. */
|
|
70
|
+
sorts: SortState[];
|
|
71
|
+
}
|
|
72
|
+
/** A page of rows, with the total row count on the server (for paging). A bare array means "these are all the rows". */
|
|
73
|
+
export type DataTableResult<R> = R[] | {
|
|
74
|
+
rows: R[];
|
|
75
|
+
total?: number;
|
|
76
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/define.d.ts
ADDED
package/dist/define.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hint, error message and required validation for form-associated elements that build their own field markup
|
|
3
|
+
* (rating, segmented, toggle group, range slider, file upload). Matches `FormControl`: the same `pm-hint` /
|
|
4
|
+
* `pm-error` markup and ids for `aria-describedby`, a custom `error` that always shows, and a required/invalid
|
|
5
|
+
* message that appears only after the user has tried to submit (the form's `invalid` event) or interacted.
|
|
6
|
+
*/
|
|
7
|
+
import { type ReactiveController, type ReactiveControllerHost } from 'lit';
|
|
8
|
+
export interface FieldValidityOptions {
|
|
9
|
+
hint: () => string | undefined;
|
|
10
|
+
/** Custom error message; while set, the field is invalid and the message shows. */
|
|
11
|
+
error: () => string | undefined;
|
|
12
|
+
/** Required but empty. */
|
|
13
|
+
missing: () => boolean;
|
|
14
|
+
/** Message for `missing` (shown and reported to the form). */
|
|
15
|
+
missingMessage: string;
|
|
16
|
+
/** Focus target the browser uses when reporting the error. */
|
|
17
|
+
anchor: () => HTMLElement | null | undefined;
|
|
18
|
+
}
|
|
19
|
+
export declare class FieldValidity implements ReactiveController {
|
|
20
|
+
#private;
|
|
21
|
+
private readonly host;
|
|
22
|
+
private readonly internals;
|
|
23
|
+
private readonly opts;
|
|
24
|
+
readonly id: string;
|
|
25
|
+
readonly hintId: string;
|
|
26
|
+
readonly errorId: string;
|
|
27
|
+
constructor(host: ReactiveControllerHost & HTMLElement, internals: ElementInternals, opts: FieldValidityOptions);
|
|
28
|
+
hostConnected(): void;
|
|
29
|
+
hostDisconnected(): void;
|
|
30
|
+
hostUpdated(): void;
|
|
31
|
+
/** The user has interacted: show problems from now on. */
|
|
32
|
+
touch(): void;
|
|
33
|
+
/** Form reset: hide problems again until the next submit or interaction. */
|
|
34
|
+
reset(): void;
|
|
35
|
+
/** Message currently shown (custom errors always; required only after submit/interaction). */
|
|
36
|
+
get message(): string;
|
|
37
|
+
get invalid(): boolean;
|
|
38
|
+
/** Ids for `aria-describedby` on the focusable control(s). */
|
|
39
|
+
get describedBy(): string | undefined;
|
|
40
|
+
/** Hint and error lines to render under the control. */
|
|
41
|
+
messages(): import("lit").TemplateResult<1>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hint, error message and required validation for form-associated elements that build their own field markup
|
|
3
|
+
* (rating, segmented, toggle group, range slider, file upload). Matches `FormControl`: the same `pm-hint` /
|
|
4
|
+
* `pm-error` markup and ids for `aria-describedby`, a custom `error` that always shows, and a required/invalid
|
|
5
|
+
* message that appears only after the user has tried to submit (the form's `invalid` event) or interacted.
|
|
6
|
+
*/
|
|
7
|
+
import { html, nothing } from 'lit';
|
|
8
|
+
import { nextId } from './id.js';
|
|
9
|
+
export class FieldValidity {
|
|
10
|
+
#touched;
|
|
11
|
+
constructor(host, internals, opts) {
|
|
12
|
+
this.host = host;
|
|
13
|
+
this.internals = internals;
|
|
14
|
+
this.opts = opts;
|
|
15
|
+
this.id = nextId('fld');
|
|
16
|
+
this.hintId = `${this.id}-hint`;
|
|
17
|
+
this.errorId = `${this.id}-err`;
|
|
18
|
+
this.#touched = false;
|
|
19
|
+
this.#onInvalid = () => { this.#touched = true; this.host.requestUpdate(); };
|
|
20
|
+
host.addController(this);
|
|
21
|
+
}
|
|
22
|
+
hostConnected() { this.host.addEventListener('invalid', this.#onInvalid); }
|
|
23
|
+
hostDisconnected() { this.host.removeEventListener('invalid', this.#onInvalid); }
|
|
24
|
+
hostUpdated() {
|
|
25
|
+
const msg = this.#problem();
|
|
26
|
+
const anchor = this.opts.anchor() ?? undefined;
|
|
27
|
+
if (!msg)
|
|
28
|
+
this.internals.setValidity({});
|
|
29
|
+
else if (this.opts.error())
|
|
30
|
+
this.internals.setValidity({ customError: true }, msg, anchor);
|
|
31
|
+
else
|
|
32
|
+
this.internals.setValidity({ valueMissing: true }, msg, anchor);
|
|
33
|
+
}
|
|
34
|
+
#onInvalid;
|
|
35
|
+
#problem() { return this.opts.error() || (this.opts.missing() ? this.opts.missingMessage : ''); }
|
|
36
|
+
/** The user has interacted: show problems from now on. */
|
|
37
|
+
touch() { if (!this.#touched) {
|
|
38
|
+
this.#touched = true;
|
|
39
|
+
this.host.requestUpdate();
|
|
40
|
+
} }
|
|
41
|
+
/** Form reset: hide problems again until the next submit or interaction. */
|
|
42
|
+
reset() { this.#touched = false; this.host.requestUpdate(); }
|
|
43
|
+
/** Message currently shown (custom errors always; required only after submit/interaction). */
|
|
44
|
+
get message() { return this.opts.error() || (this.#touched ? this.#problem() : ''); }
|
|
45
|
+
get invalid() { return !!this.message; }
|
|
46
|
+
/** Ids for `aria-describedby` on the focusable control(s). */
|
|
47
|
+
get describedBy() {
|
|
48
|
+
const ids = [this.opts.hint() ? this.hintId : '', this.message ? this.errorId : ''].filter(Boolean);
|
|
49
|
+
return ids.length ? ids.join(' ') : undefined;
|
|
50
|
+
}
|
|
51
|
+
/** Hint and error lines to render under the control. */
|
|
52
|
+
messages() {
|
|
53
|
+
const hint = this.opts.hint();
|
|
54
|
+
const msg = this.message;
|
|
55
|
+
return html `${hint ? html `<span class="pm-hint" id=${this.hintId} part="hint">${hint}</span>` : nothing}<span class="pm-error"
|
|
56
|
+
id=${this.errorId} part="error" ?hidden=${!msg} role=${msg ? 'alert' : nothing}>${msg}</span>`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Positions a `popover="manual"` element (top layer: never clipped by overflow or dialogs) next to an anchor,
|
|
3
|
+
* flipping above when there is no room below, and follows the anchor on scroll/resize. Returns a cleanup.
|
|
4
|
+
*/
|
|
5
|
+
export declare function attachBelow(popup: HTMLElement, anchor: HTMLElement, opts?: {
|
|
6
|
+
matchWidth?: boolean;
|
|
7
|
+
gap?: number;
|
|
8
|
+
align?: 'start' | 'end';
|
|
9
|
+
sheet?: boolean;
|
|
10
|
+
}): () => void;
|
|
11
|
+
/** showPopover/hidePopover that tolerate unsupported browsers and repeated calls. */
|
|
12
|
+
export declare function showPopup(el: HTMLElement): void;
|
|
13
|
+
export declare function hidePopup(el: HTMLElement): void;
|
package/dist/floating.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { isCompact } from './sheet.js';
|
|
2
|
+
/**
|
|
3
|
+
* Positions a `popover="manual"` element (top layer: never clipped by overflow or dialogs) next to an anchor,
|
|
4
|
+
* flipping above when there is no room below, and follows the anchor on scroll/resize. Returns a cleanup.
|
|
5
|
+
*/
|
|
6
|
+
export function attachBelow(popup, anchor, opts = {}) {
|
|
7
|
+
const gap = opts.gap ?? 4;
|
|
8
|
+
const place = () => {
|
|
9
|
+
// Phones: pickers become bottom sheets (styled by sheet.css) instead of anchored dropdowns.
|
|
10
|
+
if (opts.sheet && isCompact(popup)) {
|
|
11
|
+
popup.setAttribute('data-sheet', '');
|
|
12
|
+
for (const k of ['top', 'left', 'minWidth', 'maxWidth'])
|
|
13
|
+
popup.style[k] = '';
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
popup.removeAttribute('data-sheet');
|
|
17
|
+
const r = anchor.getBoundingClientRect();
|
|
18
|
+
const vw = document.documentElement.clientWidth;
|
|
19
|
+
const vh = document.documentElement.clientHeight;
|
|
20
|
+
if (opts.matchWidth !== false)
|
|
21
|
+
popup.style.minWidth = `${r.width}px`;
|
|
22
|
+
popup.style.maxWidth = `${Math.max(200, vw - 16)}px`;
|
|
23
|
+
const h = popup.offsetHeight;
|
|
24
|
+
const w = popup.offsetWidth;
|
|
25
|
+
const below = vh - r.bottom - gap;
|
|
26
|
+
const top = below >= h || below >= r.top ? r.bottom + gap : Math.max(8, r.top - gap - h);
|
|
27
|
+
const rtl = getComputedStyle(anchor).direction === 'rtl';
|
|
28
|
+
const alignEnd = (opts.align === 'end') !== rtl;
|
|
29
|
+
let left = alignEnd ? r.right - w : r.left;
|
|
30
|
+
left = Math.min(Math.max(8, left), vw - w - 8);
|
|
31
|
+
popup.style.top = `${Math.round(top)}px`;
|
|
32
|
+
popup.style.left = `${Math.round(left)}px`;
|
|
33
|
+
};
|
|
34
|
+
place();
|
|
35
|
+
const onMove = () => requestAnimationFrame(place);
|
|
36
|
+
addEventListener('scroll', onMove, { capture: true, passive: true });
|
|
37
|
+
addEventListener('resize', onMove, { passive: true });
|
|
38
|
+
const ro = typeof ResizeObserver !== 'undefined' ? new ResizeObserver(onMove) : undefined;
|
|
39
|
+
ro?.observe(popup);
|
|
40
|
+
ro?.observe(anchor);
|
|
41
|
+
return () => {
|
|
42
|
+
removeEventListener('scroll', onMove, { capture: true });
|
|
43
|
+
removeEventListener('resize', onMove);
|
|
44
|
+
ro?.disconnect();
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** showPopover/hidePopover that tolerate unsupported browsers and repeated calls. */
|
|
48
|
+
export function showPopup(el) {
|
|
49
|
+
try {
|
|
50
|
+
if (!el.matches(':popover-open'))
|
|
51
|
+
el.showPopover();
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
el.style.display = 'block';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export function hidePopup(el) {
|
|
58
|
+
try {
|
|
59
|
+
if (el.matches(':popover-open'))
|
|
60
|
+
el.hidePopover();
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
el.style.display = 'none';
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Small syntax highlighter (no dependency, runs on the server and in the browser). Used by `<pm-code-block>` and the
|
|
3
|
+
* documentation site. Tokens are spans with `t-*` classes that map to theme colours, so every theme and mode works.
|
|
4
|
+
* Not a parser: ordered regular expressions per language, good enough for short snippets.
|
|
5
|
+
*/
|
|
6
|
+
export type Lang = 'markup' | 'js' | 'css' | 'shell' | 'json' | 'text';
|
|
7
|
+
/** Guess the language from the code when the caller does not say. */
|
|
8
|
+
export declare function detectLang(code: string): Lang;
|
|
9
|
+
/** Highlighted HTML (escaped) for `code`. */
|
|
10
|
+
export declare function highlight(code: string, lang?: Lang): string;
|
|
11
|
+
export declare const LANG_LABEL: Record<Lang, string>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
const esc = (s) => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
2
|
+
const span = (cls, text) => `<span class="t-${cls}">${esc(text)}</span>`;
|
|
3
|
+
/** Guess the language from the code when the caller does not say. */
|
|
4
|
+
export function detectLang(code) {
|
|
5
|
+
const c = code.trim();
|
|
6
|
+
if (/^(\$ |#!|npx |bunx? |npm |pnpm |yarn |cd |claude |git |curl |Content-Security-Policy)/m.test(c) && !/^(import|export|const|<)/.test(c))
|
|
7
|
+
return 'shell';
|
|
8
|
+
if (/^[[{]/.test(c) && /^[\s\S]*[\]}]$/.test(c) && /"\s*:/.test(c))
|
|
9
|
+
return 'json';
|
|
10
|
+
if (/^(<script|<template|<[a-zA-Z!])/.test(c))
|
|
11
|
+
return 'markup';
|
|
12
|
+
if (/^(@layer|@import|@media|@theme|:root|[.#]?[\w-]+(\[[^\]]*\])?\s*\{|\/\*)/.test(c) && /[{;}]\s*$/m.test(c) && !/\b(import|const|function|=>)\b/.test(c))
|
|
13
|
+
return 'css';
|
|
14
|
+
if (/\b(import|export|const|let|function|return|await|class|interface|type)\b|=>/.test(c))
|
|
15
|
+
return 'js';
|
|
16
|
+
if (/<\/?[a-zA-Z][\w-]*[\s>]/.test(c))
|
|
17
|
+
return 'markup';
|
|
18
|
+
return 'text';
|
|
19
|
+
}
|
|
20
|
+
const JS_KEYWORDS = /\b(?:import|export|from|default|const|let|var|function|return|if|else|for|while|of|in|new|class|extends|async|await|try|catch|finally|throw|typeof|instanceof|interface|type|as|satisfies|declare|true|false|null|undefined|this|void|yield|switch|case|break|continue)\b/y;
|
|
21
|
+
const js = [
|
|
22
|
+
['c', /\/\/[^\n]*|\/\*[\s\S]*?\*\//y],
|
|
23
|
+
['s', /`(?:\\[\s\S]|[^`\\])*`|'(?:\\.|[^'\\\n])*'|"(?:\\.|[^"\\\n])*"/y],
|
|
24
|
+
// JSX / component tags inside script code
|
|
25
|
+
['x', /<\/?[A-Za-z][\w.-]*(?=[\s/>])|\/?>/y],
|
|
26
|
+
['k', JS_KEYWORDS],
|
|
27
|
+
['n', /\b\d[\d_]*(?:\.\d+)?(?:e[+-]?\d+)?\b/y],
|
|
28
|
+
['f', /\b[A-Za-z_$][\w$]*(?=\s*\()/y],
|
|
29
|
+
['a', /\b[a-zA-Z_][\w-]*(?==["{'])/y],
|
|
30
|
+
];
|
|
31
|
+
const css = [
|
|
32
|
+
['c', /\/\*[\s\S]*?\*\//y],
|
|
33
|
+
['s', /'(?:\\.|[^'\\\n])*'|"(?:\\.|[^"\\\n])*"/y],
|
|
34
|
+
['k', /@[\w-]+/y],
|
|
35
|
+
['a', /--[\w-]+|[a-z-]+(?=\s*:(?!:)[^{}]*[;}\n])/y],
|
|
36
|
+
['n', /#[0-9a-fA-F]{3,8}\b|-?\b\d*\.?\d+(?:%|[a-z]+)?\b/y],
|
|
37
|
+
['f', /\b[a-z-]+(?=\()/y],
|
|
38
|
+
];
|
|
39
|
+
const shell = [
|
|
40
|
+
['c', /#[^\n]*/y],
|
|
41
|
+
['s', /'[^'\n]*'|"(?:\\.|[^"\\\n])*"/y],
|
|
42
|
+
['k', /(?<=^|\n|&& |\| )\s*(?:npx|bunx|bun|npm|pnpm|yarn|git|cd|curl|claude|node|sudo)\b/y],
|
|
43
|
+
['a', /(?<=\s)--?[A-Za-z][\w-]*/y],
|
|
44
|
+
];
|
|
45
|
+
const json = [
|
|
46
|
+
['a', /"(?:\\.|[^"\\\n])*"(?=\s*:)/y],
|
|
47
|
+
['s', /"(?:\\.|[^"\\\n])*"/y],
|
|
48
|
+
['n', /-?\b\d+(?:\.\d+)?\b/y],
|
|
49
|
+
['k', /\b(?:true|false|null)\b/y],
|
|
50
|
+
];
|
|
51
|
+
function run(code, rules) {
|
|
52
|
+
let out = '';
|
|
53
|
+
let plain = '';
|
|
54
|
+
let i = 0;
|
|
55
|
+
scan: while (i < code.length) {
|
|
56
|
+
for (const [cls, re, sub] of rules) {
|
|
57
|
+
re.lastIndex = i;
|
|
58
|
+
const m = re.exec(code);
|
|
59
|
+
if (m && m[0]) {
|
|
60
|
+
if (plain) {
|
|
61
|
+
out += esc(plain);
|
|
62
|
+
plain = '';
|
|
63
|
+
}
|
|
64
|
+
out += sub ? sub(m[0]) : span(cls, m[0]);
|
|
65
|
+
i += m[0].length;
|
|
66
|
+
continue scan;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
plain += code[i++];
|
|
70
|
+
}
|
|
71
|
+
return out + esc(plain);
|
|
72
|
+
}
|
|
73
|
+
/** A tag: name, attributes (name, quoted value or {expression}), closing bracket. */
|
|
74
|
+
function tag(text) {
|
|
75
|
+
const m = /^(<\/?)([^\s/>]+)([\s\S]*?)(\/?>)$/.exec(text);
|
|
76
|
+
if (!m)
|
|
77
|
+
return esc(text);
|
|
78
|
+
const attrs = run(m[3], [
|
|
79
|
+
['s', /"[^"]*"|'[^']*'/y],
|
|
80
|
+
['e', /\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\}/y, (t) => `<span class="t-e">${run(t, js)}</span>`],
|
|
81
|
+
['a', /[^\s=>/"'{}]+/y],
|
|
82
|
+
]);
|
|
83
|
+
return `${span('p', m[1])}${span('x', m[2])}${attrs}${span('p', m[4])}`;
|
|
84
|
+
}
|
|
85
|
+
const TAG = /<\/?[A-Za-z][\w:.-]*(?:\s+(?:[^\s=>/"'{}]+(?:=(?:"[^"]*"|'[^']*'|\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\}|[^\s>]+))?|\{[^{}]*\}))*\s*\/?>/y;
|
|
86
|
+
const markup = [
|
|
87
|
+
['c', /<!--[\s\S]*?-->/y],
|
|
88
|
+
// <script> and <style> blocks use their own language
|
|
89
|
+
['', /<script\b[^>]*>[\s\S]*?<\/script>/y, (t) => { const m = /^(<script\b[^>]*>)([\s\S]*?)(<\/script>)$/.exec(t); return tag(m[1]) + run(m[2], js) + tag(m[3]); }],
|
|
90
|
+
['', /<style\b[^>]*>[\s\S]*?<\/style>/y, (t) => { const m = /^(<style\b[^>]*>)([\s\S]*?)(<\/style>)$/.exec(t); return tag(m[1]) + run(m[2], css) + tag(m[3]); }],
|
|
91
|
+
['', TAG, tag],
|
|
92
|
+
['k', /\{[#:/@][a-z]+|\{\/[a-z]+\}/y],
|
|
93
|
+
];
|
|
94
|
+
/** Highlighted HTML (escaped) for `code`. */
|
|
95
|
+
export function highlight(code, lang = detectLang(code)) {
|
|
96
|
+
if (lang === 'text')
|
|
97
|
+
return esc(code);
|
|
98
|
+
if (lang === 'markup')
|
|
99
|
+
return run(code, markup);
|
|
100
|
+
// Framework snippets: script code that returns markup (JSX) is handled by the js rules' tag tokens.
|
|
101
|
+
return run(code, lang === 'js' ? js : lang === 'css' ? css : lang === 'shell' ? shell : json);
|
|
102
|
+
}
|
|
103
|
+
export const LANG_LABEL = { markup: 'HTML', js: 'JS / TS', css: 'CSS', shell: 'Terminal', json: 'JSON', text: 'Text' };
|
package/dist/id.d.ts
ADDED
package/dist/id.js
ADDED