@nocopypaste/vue-grid-renderer-template 0.0.0-stage → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,47 @@
1
- # Temporary Holding Version
1
+ # @nocopypaste/vue-grid-renderer-template
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Boilerplate for a **3rd-party cell renderer** for [`@nocopypaste/vue-grid`](../vue-grid): a star `rating`
4
+ renderer. Copy this package, rename it, and replace `RatingCell.vue`.
5
+
6
+ ## Use it
7
+
8
+ ```ts
9
+ import { createVueGrid } from '@nocopypaste/vue-grid'
10
+ import { ratingRenderer } from '@nocopypaste/vue-grid-renderer-template'
11
+ import '@nocopypaste/vue-grid/style.css'
12
+ import '@nocopypaste/vue-grid-renderer-template/style.css'
13
+
14
+ app.use(createVueGrid({ renderers: [ratingRenderer] }))
15
+ ```
16
+
17
+ ```ts
18
+ const col = createColumnHelper<Product>()
19
+ const columns = [col({ key: 'stars', header: 'Rating', renderer: 'rating', rendererOptions: { max: 5 } })]
20
+ ```
21
+
22
+ ```vue
23
+ <VGrid :rows :columns row-key="id" @cell-action="(e) => e.name === 'rate' && save(e.rowKey, e.payload)" />
24
+ ```
25
+
26
+ ## Anatomy
27
+
28
+ | File | What it shows |
29
+ |---|---|
30
+ | `src/RatingCell.vue` | The renderer component: `defineProps<CellRendererProps<Row, Value, Options>>()`, `defineEmits<CellRendererEmits>()`, `useGridContext()` for locale, emitting `action('rate', n)`, accessible markup. |
31
+ | `src/types.ts` | The options interface. |
32
+ | `src/index.ts` | `defineCellRenderer({ name, component, defaults, align, sortValue, format })` and the **module augmentation** that makes `renderer: 'rating'` and its `rendererOptions` type-checked. |
33
+ | `src/rating.css` | Styles in `@layer vue-grid-addons`, built only from grid tokens (`--vg-color-*`, `--vg-radius-sm`, …) plus the addon's own `--vg-rating-*` tokens. |
34
+ | `vite.config.ts` | Library build; `vue` and `@nocopypaste/vue-grid` stay external (peer dependencies). |
35
+ | `test/rating.spec.ts` | Unit test of the component, and an integration test inside `<VGrid>` — including a `@ts-expect-error` proving the options are typed. |
36
+
37
+ ## Rules of thumb
38
+
39
+ - Render values as text (`{{ }}`), never `v-html`.
40
+ - Don't emit DOM-ish events for grid logic; emit `action(name, payload)` and let the app handle `cell-action`.
41
+ - Interactive elements (buttons, links, inputs) inside a cell don't trigger `row-click`.
42
+ - Prefer `(value, row) => …` options for per-row behaviour.
43
+ - Use grid tokens so your renderer follows the host theme and dark mode.
44
+
45
+ ## Scripts
46
+
47
+ `npm run build` · `npm test` · `npm run typecheck`
package/dist/index.js ADDED
@@ -0,0 +1,66 @@
1
+ import { defineCellRenderer as e, useGridContext as t } from "@nocopypaste/vue-grid";
2
+ import { Fragment as n, computed as r, createElementBlock as i, defineComponent as a, normalizeClass as o, openBlock as s, renderList as c } from "vue";
3
+ // src/RatingCell.vue?vue&type=script&setup=true&lang.ts
4
+ var l = ["aria-label", "title"], u = ["aria-label"], d = [
5
+ "aria-checked",
6
+ "aria-label",
7
+ "onClick"
8
+ ], f = /* @__PURE__ */ a({
9
+ __name: "RatingCell",
10
+ props: {
11
+ value: {},
12
+ row: {},
13
+ rowKey: {},
14
+ rowIndex: {},
15
+ depth: {},
16
+ column: {},
17
+ options: {}
18
+ },
19
+ emits: ["action"],
20
+ setup(e, { emit: a }) {
21
+ let f = e, p = a, m = t(), h = r(() => Math.max(1, Math.round(f.options.max ?? 5))), g = r(() => {
22
+ let e = Number(f.value);
23
+ return Number.isFinite(e) ? Math.min(Math.max(e, 0), h.value) : 0;
24
+ }), _ = r(() => `${new Intl.NumberFormat(m.value.locale).format(g.value)} of ${h.value}`);
25
+ function v(e) {
26
+ f.options.readonly || p("action", "rate", e);
27
+ }
28
+ return (t, r) => e.options.readonly ? (s(), i("span", {
29
+ key: 0,
30
+ class: "vg-rating",
31
+ role: "img",
32
+ "aria-label": _.value,
33
+ title: _.value
34
+ }, [(s(!0), i(n, null, c(h.value, (e) => (s(), i("span", {
35
+ key: e,
36
+ class: o(["vg-rating-star", { "vg-rating-star-on": e <= Math.round(g.value) }]),
37
+ "aria-hidden": "true"
38
+ }, "★", 2))), 128))], 8, l)) : (s(), i("span", {
39
+ key: 1,
40
+ class: "vg-rating",
41
+ role: "radiogroup",
42
+ "aria-label": `Rating, ${_.value}`
43
+ }, [(s(!0), i(n, null, c(h.value, (e) => (s(), i("button", {
44
+ key: e,
45
+ type: "button",
46
+ role: "radio",
47
+ class: o(["vg-rating-star", { "vg-rating-star-on": e <= Math.round(g.value) }]),
48
+ "aria-checked": e === Math.round(g.value),
49
+ "aria-label": `${e} of ${h.value}`,
50
+ onClick: (t) => v(e)
51
+ }, " ★ ", 10, d))), 128))], 8, u));
52
+ }
53
+ }), p = e({
54
+ name: "rating",
55
+ component: f,
56
+ defaults: {
57
+ max: 5,
58
+ readonly: !1
59
+ },
60
+ align: "start",
61
+ sortValue: (e) => e == null ? null : Number(e),
62
+ format: (e, t) => `${Number(e ?? 0)} of ${t.max ?? 5}`
63
+ });
64
+ export { f as RatingCell, p as ratingRenderer };
65
+
66
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["_openBlock","_createElementBlock","_Fragment","_renderList","_normalizeClass","RatingCell","_hoisted_1","_hoisted_2","_hoisted_3","RatingCell_default","defineComponent","__emit","props","__props","emit","ctx","useGridContext","max","computed","rating","n","label","rate","value","openBlock","createElementBlock","Fragment","renderList","normalizeClass","ratingRenderer","defineCellRenderer","options"],"sources":["../src/RatingCell.vue","../src/index.ts"],"sourcesContent":["<!--\n Boilerplate cell renderer.\n\n Contract (from @nocopypaste/vue-grid):\n - props: CellRendererProps<Row, Value, Options> → value, row, rowKey, rowIndex, depth, column, options\n - emits: `action(name, payload)` — the grid re-emits it as `cell-action` with row + column attached\n - styling: only --vg-* tokens (plus this addon's own --vg-rating-* tokens), inside a cascade layer\n-->\n<script setup lang=\"ts\">\nimport { computed } from 'vue'\nimport { useGridContext, type CellRendererEmits, type CellRendererProps } from '@nocopypaste/vue-grid'\nimport type { RatingOptions } from './types'\n\nconst props = defineProps<CellRendererProps<unknown, number | null | undefined, RatingOptions>>()\nconst emit = defineEmits<CellRendererEmits>()\n\n// Locale, currency and time zone of the surrounding grid (props → plugin config → browser).\nconst ctx = useGridContext()\n\nconst max = computed(() => Math.max(1, Math.round(props.options.max ?? 5)))\nconst rating = computed(() => {\n const n = Number(props.value)\n return Number.isFinite(n) ? Math.min(Math.max(n, 0), max.value) : 0\n})\nconst label = computed(\n () => `${new Intl.NumberFormat(ctx.value.locale).format(rating.value)} of ${max.value}`,\n)\n\nfunction rate(value: number) {\n if (props.options.readonly) return\n emit('action', 'rate', value)\n}\n</script>\n\n<template>\n <span v-if=\"options.readonly\" class=\"vg-rating\" role=\"img\" :aria-label=\"label\" :title=\"label\">\n <span\n v-for=\"n in max\"\n :key=\"n\"\n class=\"vg-rating-star\"\n :class=\"{ 'vg-rating-star-on': n <= Math.round(rating) }\"\n aria-hidden=\"true\"\n >★</span\n >\n </span>\n <span v-else class=\"vg-rating\" role=\"radiogroup\" :aria-label=\"`Rating, ${label}`\">\n <button\n v-for=\"n in max\"\n :key=\"n\"\n type=\"button\"\n role=\"radio\"\n class=\"vg-rating-star\"\n :class=\"{ 'vg-rating-star-on': n <= Math.round(rating) }\"\n :aria-checked=\"n === Math.round(rating)\"\n :aria-label=\"`${n} of ${max}`\"\n @click=\"rate(n)\"\n >\n ★\n </button>\n </span>\n</template>\n","import { defineCellRenderer } from '@nocopypaste/vue-grid'\nimport RatingCell from './RatingCell.vue'\nimport type { RatingOptions } from './types'\n\n// 1. Register the renderer name and its options with the grid's type registry, so\n// `renderer: 'rating'` autocompletes and `rendererOptions` is type-checked.\ndeclare module '@nocopypaste/vue-grid' {\n interface CellRendererRegistry {\n rating: RatingOptions\n }\n}\n\n// 2. Describe the renderer. Everything except `name` and `component` is optional.\nexport const ratingRenderer = defineCellRenderer<RatingOptions>({\n name: 'rating',\n component: RatingCell,\n defaults: { max: 5, readonly: false },\n align: 'start',\n // Used by `sortMode=\"client\"` so ratings sort numerically.\n sortValue: (value) => (value === null || value === undefined ? null : Number(value)),\n // Plain-text form: what Ctrl+C and formatted CSV exports copy (export feature).\n format: (value, options) => `${Number(value ?? 0)} of ${options.max ?? 5}`,\n})\n\nexport { RatingCell }\nexport type { RatingOptions }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;EAaA,IAAMY,IAAQC,GACRC,IAAOH,GAGPI,IAAMC,EAAe,GAErBC,IAAMC,QAAe,KAAK,IAAI,GAAG,KAAK,MAAMN,EAAM,QAAQ,OAAO,CAAC,CAAC,CAAC,GACpEO,IAASD,QAAe;GAC5B,IAAME,IAAI,OAAOR,EAAM,KAAK;GAC5B,OAAO,OAAO,SAASQ,CAAC,IAAI,KAAK,IAAI,KAAK,IAAIA,GAAG,CAAC,GAAGH,EAAI,KAAK,IAAI;EACpE,CAAC,GACKI,IAAQH,QACN,GAAG,IAAI,KAAK,aAAaH,EAAI,MAAM,MAAM,CAAC,CAAC,OAAOI,EAAO,KAAK,EAAE,MAAMF,EAAI,OAClF;EAEA,SAASK,EAAK,GAAe;GAC3B,AAAIV,EAAM,QAAQ,YAClBE,EAAK,UAAU,QAAQS,CAAK;EAC9B;E,iBAIcV,EAAA,QAAQ,YAApBb,EAAA,GAAAC,EASO,QAAA;;GATuB,OAAM;GAAY,MAAK;GAAO,cAAYoB,EAAA;GAAQ,OAAOA,EAAA;E,KACrFrB,EAAA,EAAA,GAAAC,EAOCC,GAAA,MAAAC,EANac,EAAA,QAAL,OADTjB,EAAA,GAAAC,EAOC,QAAA;GALE,KAAKmB;GACN,OAAKhB,EAAA,CAAC,kBAAgB,EAAA,qBACSgB,KAAK,KAAK,MAAMD,EAAA,KAAM,EAAA,CAAA,CAAA;GACrD,eAAY;EACX,GAAA,KAAC,CAAA,E,qBAGNnB,EAAA,GAAAC,EAcO,QAAA;;GAdM,OAAM;GAAY,MAAK;GAAc,cAAU,WAAaoB,EAAA;E,KACvErB,EAAA,EAAA,GAAAC,EAYSC,GAAA,MAAAC,EAXKc,EAAA,QAAL,OADTjB,EAAA,GAAAC,EAYS,UAAA;GAVN,KAAKmB;GACN,MAAK;GACL,MAAK;GACL,OAAKhB,EAAA,CAAC,kBAAgB,EAAA,qBACSgB,KAAK,KAAK,MAAMD,EAAA,KAAM,EAAA,CAAA,CAAA;GACpD,gBAAcC,MAAM,KAAK,MAAMD,EAAA,KAAM;GACrC,cAAU,GAAKC,EAAC,MAAOH,EAAA;GACvB,UAAK,MAAEK,EAAKF,CAAC;EACf,GAAA,OAED,IAAAZ,CAAA,E;;A,IC7CSqB,IAAiBC,EAAkC;CAC9D,MAAM;CACN,WAAWzB;CACX,UAAU;EAAE,KAAK;EAAG,UAAU;CAAM;CACpC,OAAO;CAEP,YAAY,MAAWkB,KAAU,OAA8B,OAAO,OAAOA,CAAK;CAElF,SAAS,GAAO,MAAY,GAAG,OAAOA,KAAS,CAAC,EAAE,MAAMQ,EAAQ,OAAO;AACzE,CAAC"}
@@ -0,0 +1,48 @@
1
+ /*
2
+ * Addon styles live in their own layer, declared after the grid's, so they can build on grid
3
+ * tokens while consumers' unlayered CSS still overrides both.
4
+ */
5
+ @layer vue-grid, vue-grid-addons;
6
+
7
+ @layer vue-grid-addons {
8
+ :root {
9
+ --vg-rating-color: var(--vg-color-warning);
10
+ --vg-rating-empty-color: var(--vg-color-border-strong);
11
+ --vg-rating-size: 1.125rem;
12
+ --vg-rating-gap: 0.0625rem;
13
+ }
14
+
15
+ .vg-rating {
16
+ display: inline-flex;
17
+ gap: var(--vg-rating-gap);
18
+ line-height: 1;
19
+ }
20
+
21
+ .vg-rating-star {
22
+ padding: 0;
23
+ border: 0;
24
+ background: none;
25
+ color: var(--vg-rating-empty-color);
26
+ font-size: var(--vg-rating-size);
27
+ line-height: 1;
28
+ }
29
+
30
+ button.vg-rating-star {
31
+ cursor: pointer;
32
+ border-radius: var(--vg-radius-sm);
33
+ transition: transform var(--vg-transition);
34
+ }
35
+
36
+ button.vg-rating-star:hover {
37
+ transform: scale(1.15);
38
+ }
39
+
40
+ button.vg-rating-star:focus-visible {
41
+ outline: 2px solid var(--vg-color-focus-ring);
42
+ outline-offset: 1px;
43
+ }
44
+
45
+ .vg-rating-star-on {
46
+ color: var(--vg-rating-color);
47
+ }
48
+ }
@@ -0,0 +1,10 @@
1
+ import { type CellRendererProps } from '@nocopypaste/vue-grid';
2
+ import type { RatingOptions } from './types';
3
+ type __VLS_Props = CellRendererProps<unknown, number | null | undefined, RatingOptions>;
4
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
5
+ action: (name: string, payload?: unknown) => any;
6
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
7
+ onAction?: ((name: string, payload?: unknown) => any) | undefined;
8
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
9
+ declare const _default: typeof __VLS_export;
10
+ export default _default;
@@ -0,0 +1,10 @@
1
+ import RatingCell from './RatingCell.vue';
2
+ import type { RatingOptions } from './types';
3
+ declare module '@nocopypaste/vue-grid' {
4
+ interface CellRendererRegistry {
5
+ rating: RatingOptions;
6
+ }
7
+ }
8
+ export declare const ratingRenderer: import("@nocopypaste/vue-grid").CellRendererDefinition<RatingOptions>;
9
+ export { RatingCell };
10
+ export type { RatingOptions };
@@ -0,0 +1,6 @@
1
+ export interface RatingOptions {
2
+ /** Number of stars. Default 5. */
3
+ max?: number;
4
+ /** Display only; no `rate` action. */
5
+ readonly?: boolean;
6
+ }
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
2
  "name": "@nocopypaste/vue-grid-renderer-template",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.3.0",
4
+ "description": "Boilerplate cell-renderer addon for @nocopypaste/vue-grid: a star rating renderer. Copy this package to start your own.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "files": [
8
+ "dist",
9
+ "README.md"
10
+ ],
11
+ "main": "./dist/index.js",
12
+ "types": "./dist/types/index.d.ts",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/types/index.d.ts",
16
+ "import": "./dist/index.js"
17
+ },
18
+ "./style.css": "./dist/rating.css"
19
+ },
20
+ "sideEffects": [
21
+ "**/*.css"
22
+ ],
23
+ "scripts": {
24
+ "build": "vite build && vue-tsc -p tsconfig.build.json",
25
+ "test": "vitest run",
26
+ "typecheck": "vue-tsc -p tsconfig.json --noEmit"
27
+ },
28
+ "peerDependencies": {
29
+ "@nocopypaste/vue-grid": "^0.3.0",
30
+ "vue": "^3.5.0"
31
+ },
32
+ "devDependencies": {
33
+ "@nocopypaste/vue-grid": "*"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/eboye/eboye-vue-grid.git",
38
+ "directory": "packages/cell-renderer-template"
39
+ },
40
+ "homepage": "https://github.com/eboye/eboye-vue-grid/tree/main/packages/cell-renderer-template#readme",
41
+ "bugs": {
42
+ "url": "https://github.com/eboye/eboye-vue-grid/issues"
43
+ },
44
+ "author": "eboye"
45
+ }