@nocopypaste/vue-grid-renderer-template 0.3.1 → 0.4.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
@@ -16,23 +16,30 @@ app.use(createVueGrid({ renderers: [ratingRenderer] }))
16
16
 
17
17
  ```ts
18
18
  const col = createColumnHelper<Product>()
19
- const columns = [col({ key: 'stars', header: 'Rating', renderer: 'rating', rendererOptions: { max: 5 } })]
19
+ const columns = [
20
+ col({ key: 'stars', header: 'Rating', renderer: 'rating', rendererOptions: { max: 5 } }),
21
+ ]
20
22
  ```
21
23
 
22
24
  ```vue
23
- <VGrid :rows :columns row-key="id" @cell-action="(e) => e.name === 'rate' && save(e.rowKey, e.payload)" />
25
+ <VGrid
26
+ :rows
27
+ :columns
28
+ row-key="id"
29
+ @cell-action="(e) => e.name === 'rate' && save(e.rowKey, e.payload)"
30
+ />
24
31
  ```
25
32
 
26
33
  ## Anatomy
27
34
 
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. |
35
+ | File | What it shows |
36
+ | --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
37
+ | `src/RatingCell.vue` | The renderer component: `defineProps<CellRendererProps<Row, Value, Options>>()`, `defineEmits<CellRendererEmits>()`, `useGridContext()` for locale, emitting `action('rate', n)`, accessible markup. |
38
+ | `src/types.ts` | The options interface. |
39
+ | `src/index.ts` | `defineCellRenderer({ name, component, defaults, align, sortValue, format })` and the **module augmentation** that makes `renderer: 'rating'` and its `rendererOptions` type-checked. |
40
+ | `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. |
41
+ | `vite.config.ts` | Library build; `vue` and `@nocopypaste/vue-grid` stay external (peer dependencies). |
42
+ | `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
43
 
37
44
  ## Rules of thumb
38
45
 
package/dist/index.js.map CHANGED
@@ -1 +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}`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gB,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"}
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 {\n useGridContext,\n type CellRendererEmits,\n type CellRendererProps,\n} 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":";;;;;;;;;;;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gBAAcC,MAAM,KAAK,MAAMD,EAAA,KAAM;GACrC,cAAU,GAAKC,EAAC,MAAOH,EAAA;GACvB,UAAK,MAAEK,EAAKF,CAAC;EACf,GAAA,OAED,IAAAZ,CAAA,E;;A,ICjDSqB,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocopypaste/vue-grid-renderer-template",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Boilerplate cell-renderer addon for @nocopypaste/vue-grid: a star rating renderer. Copy this package to start your own.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -26,7 +26,7 @@
26
26
  "typecheck": "vue-tsc -p tsconfig.json --noEmit"
27
27
  },
28
28
  "peerDependencies": {
29
- "@nocopypaste/vue-grid": "^0.3.1",
29
+ "@nocopypaste/vue-grid": "^0.4.0",
30
30
  "vue": "^3.5.0"
31
31
  },
32
32
  "devDependencies": {