rimecms 1.4.2 → 1.5.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.
@@ -20,7 +20,7 @@
20
20
  const rendered = $derived.by(() => {
21
21
  if (!row) return null;
22
22
  const { fields, path } = getFieldListAtPath(
23
- withBlockTypes(row.path, form.values),
23
+ withBlockTypes(row.path, form.values, form.config.fields),
24
24
  form.config.fields
25
25
  );
26
26
  return { fields: fields.filter((field) => field.type !== 'blocks'), path };
@@ -27,7 +27,7 @@
27
27
  // svelte-ignore state_referenced_locally
28
28
  let groupOpen = $state(readStored(key) === 'true');
29
29
 
30
- const field = $derived(form.useField(path));
30
+ const field = $derived(form.useField(path, config));
31
31
 
32
32
  function handleClick() {
33
33
  groupOpen = !groupOpen;
@@ -73,7 +73,7 @@
73
73
  <FieldsPreview
74
74
  preview={config.get.preview}
75
75
  fields={previewFields}
76
- getField={(field) => form.useField(basePath + field.name)}
76
+ getField={(field) => form.useField(basePath + field.name, field)}
77
77
  />
78
78
  </FieldsPreviewTrigger>
79
79
  {:else}
@@ -2,6 +2,7 @@
2
2
  import { fieldset } from '../../../panel/components/fields/fieldset.svelte.js';
3
3
  import { Field } from '../../../panel/components/fields/index.js';
4
4
  import { Label } from '../../../panel/components/ui/label/index.js';
5
+ import * as RadioCardGroup from '../../../panel/components/ui/radio-card-group/index.js';
5
6
  import * as RadioGroup from '../../../panel/components/ui/radio-group/index.js';
6
7
  import * as RadioRowGroup from '../../../panel/components/ui/radio-row-group/index.js';
7
8
  import { capitalize, slugify } from '../../../util/string.js';
@@ -33,6 +34,23 @@
33
34
  </div>
34
35
  {/each}
35
36
  </RadioRowGroup.Root>
37
+ {:else if config.get.layout === 'cards'}
38
+ <RadioCardGroup.Root
39
+ aria-label={config.get.label}
40
+ bind:value={field.value}
41
+ disabled={!field.editable}
42
+ >
43
+ {#each config.get.options as option, index (index)}
44
+ <RadioCardGroup.Item
45
+ value={option.value}
46
+ id="{fieldId}-{index}"
47
+ thumbnail={option.thumbnail}
48
+ class="rz-radio__input"
49
+ >
50
+ {option.label || capitalize(option.value)}
51
+ </RadioCardGroup.Item>
52
+ {/each}
53
+ </RadioCardGroup.Root>
36
54
  {:else}
37
55
  <RadioGroup.Root
38
56
  aria-label={config.get.label}
@@ -56,7 +74,7 @@
56
74
  </fieldset>
57
75
 
58
76
  <style>
59
- .rz-field-radio:not(.rz-field-radio--row) {
77
+ .rz-field-radio--default {
60
78
  display: flex;
61
79
  flex-direction: column;
62
80
 
@@ -1,19 +1,36 @@
1
1
  import type { DefaultValueFn, FormField, Option } from '../types.js';
2
+ import type { Component } from 'svelte';
2
3
  import { PickOneFieldBuilder } from '../../core/fields/builders/select-builder.js';
3
4
  export declare class RadioFieldBuilder extends PickOneFieldBuilder<RadioField> {
4
5
  constructor(name: string);
5
- get component(): import("svelte").Component<import("./component/props.js").RadioFieldProps, {}, "">;
6
- /** `row` shows the options as one segmented row, `default` as a list of radios. */
7
- layout(value: 'default' | 'row'): this;
8
- options(...options: (Option | string)[]): this;
6
+ get component(): Component<import("./component/props.js").RadioFieldProps, {}, "">;
7
+ /**
8
+ * `row` shows the options as one segmented row, `default` as a list of radios, `cards` as a grid
9
+ * of cards, each option's thumbnail above its label.
10
+ */
11
+ layout(value: 'default' | 'row' | 'cards'): this;
12
+ /**
13
+ * The options to pick from. With the `cards` layout, an option may carry a thumbnail: a Svelte
14
+ * component drawn above its label.
15
+ *
16
+ * ```ts
17
+ * import HeroSplit from './thumbnails/HeroSplit.svelte'
18
+ * radio('layout').layout('cards').options({ value: 'split', label: 'Côte à côte', thumbnail: HeroSplit })
19
+ * ```
20
+ */
21
+ options(...options: (RadioOption | string)[]): this;
9
22
  protected generateType(): string;
10
23
  }
11
24
  export declare const radio: (name: string) => RadioFieldBuilder;
12
25
  /****************************************************/
26
+ /** An option, with the thumbnail its card shows in the `cards` layout. */
27
+ export type RadioOption = Option & {
28
+ thumbnail?: Component;
29
+ };
13
30
  export type RadioField = FormField & {
14
31
  type: 'radio';
15
- options: Option[];
16
- layout: 'row' | 'default';
32
+ options: RadioOption[];
33
+ layout: 'row' | 'default' | 'cards';
17
34
  defaultValue: string | DefaultValueFn<string>;
18
35
  many: false;
19
36
  };
@@ -9,11 +9,23 @@ export class RadioFieldBuilder extends PickOneFieldBuilder {
9
9
  get component() {
10
10
  return Radio;
11
11
  }
12
- /** `row` shows the options as one segmented row, `default` as a list of radios. */
12
+ /**
13
+ * `row` shows the options as one segmented row, `default` as a list of radios, `cards` as a grid
14
+ * of cards, each option's thumbnail above its label.
15
+ */
13
16
  layout(value) {
14
17
  this.field.layout = value;
15
18
  return this;
16
19
  }
20
+ /**
21
+ * The options to pick from. With the `cards` layout, an option may carry a thumbnail: a Svelte
22
+ * component drawn above its label.
23
+ *
24
+ * ```ts
25
+ * import HeroSplit from './thumbnails/HeroSplit.svelte'
26
+ * radio('layout').layout('cards').options({ value: 'split', label: 'Côte à côte', thumbnail: HeroSplit })
27
+ * ```
28
+ */
17
29
  options(...options) {
18
30
  super.options(...options);
19
31
  // A radio starts on one of its options: its first, unless its default is one of them
@@ -106,7 +106,7 @@
106
106
  display: grid;
107
107
  gap: var(--rz-size-2);
108
108
  padding-block: var(--rz-size-3);
109
- padding-inline: max(var(--rz-page-gutter), calc((100% - var(--rz-page-width, 40rem)) / 2));
109
+ padding-inline: var(--rz-page-gutter);
110
110
  background-color: var(--rz-bg-page);
111
111
  }
112
112
  .rz-auto-save-banner {
@@ -413,32 +413,23 @@
413
413
  </form>
414
414
 
415
415
  <style>
416
- /**
417
- * The document: a centred column, its heading lined up with its fields.
418
- *
419
- * --rz-document-width: the column, 40rem
420
- */
416
+ /* The document: its heading lined up with its fields. */
421
417
  .rz-document {
422
- --rz-page-width: var(--rz-document-width, 40rem);
423
418
  container: rz-document / inline-size;
424
419
  position: relative;
425
420
  display: flex;
426
421
  flex-direction: column;
427
422
  }
428
423
 
429
- /* A page of its own is at least the window's height, so the metas sit at its bottom. Its top
430
- edge glows, as tall as the window whatever the page's length. */
424
+ /* A page of its own is at least the window's height, so the metas sit at its bottom. */
431
425
  .rz-document:not([data-nested]) {
432
426
  min-height: 100svh;
433
- background-image: var(--rz-glow);
434
- background-repeat: no-repeat;
435
- background-size: 100% 100svh;
436
427
  }
437
428
 
438
- /* The column stops growing and centres itself; the gutter is the floor. */
429
+ /* The full width inside the page's gutter, where the dashboard and the collection list start. */
439
430
  .rz-document__fields,
440
431
  .rz-document__infos {
441
- padding-inline: max(var(--rz-page-gutter), calc((100% - var(--rz-page-width)) / 2));
432
+ padding-inline: var(--rz-page-gutter);
442
433
  }
443
434
 
444
435
  .rz-document__fields {
@@ -103,7 +103,7 @@
103
103
  display: grid;
104
104
  gap: var(--rz-size-3);
105
105
  padding-block: var(--rz-size-6) var(--rz-size-10);
106
- padding-inline: max(var(--rz-page-gutter), calc((100% - var(--rz-page-width)) / 2));
106
+ padding-inline: var(--rz-page-gutter);
107
107
  border-top: 1px solid var(--rz-border);
108
108
  }
109
109
 
@@ -80,7 +80,7 @@
80
80
  height: var(--rz-size-11);
81
81
  margin-bottom: var(--rz-size-6);
82
82
  padding-inline: var(--rz-size-5) var(--rz-size-3);
83
- /* See-through, so the page's glow reaches the top; what scrolls under it blurs. */
83
+ /* See-through: what scrolls under it blurs. */
84
84
  background: oklch(from var(--rz-bg-page) l c h / 0.8);
85
85
  backdrop-filter: blur(12px);
86
86
  box-shadow: inset 0 -1px 0 var(--rz-border);
@@ -103,16 +103,10 @@
103
103
  justify-content: flex-end;
104
104
  }
105
105
 
106
- /*
107
- * The title and the toolbar line up with a page's content. A page narrows it with
108
- * `--rz-page-width`; else it runs the full width, inside the gutter.
109
- */
106
+ /* The title and the toolbar line up with a page's content: the full width, inside the gutter. */
110
107
  .rz-page-header__head,
111
108
  .rz-page-header__toolbar {
112
- padding-inline: max(
113
- var(--rz-page-gutter, var(--rz-size-6)),
114
- calc((100% - var(--rz-page-width, 100%)) / 2)
115
- );
109
+ padding-inline: var(--rz-page-gutter, var(--rz-size-6));
116
110
  }
117
111
 
118
112
  .rz-page-header__head {
@@ -0,0 +1,3 @@
1
+ import Item from './radio-card-group-item.svelte';
2
+ import Root from './radio-card-group.svelte';
3
+ export { Item, Root };
@@ -0,0 +1,3 @@
1
+ import Item from './radio-card-group-item.svelte';
2
+ import Root from './radio-card-group.svelte';
3
+ export { Item, Root };
@@ -0,0 +1,30 @@
1
+ <script lang="ts">
2
+ import { RadioGroup as RadioGroupPrimitive, type WithoutChildrenOrChild } from 'bits-ui';
3
+ import type { Component, Snippet } from 'svelte';
4
+
5
+ /** A card: its thumbnail, when it has one, above its label. */
6
+ let {
7
+ ref = $bindable(null),
8
+ class: className,
9
+ thumbnail: Thumbnail,
10
+ children,
11
+ ...restProps
12
+ }: WithoutChildrenOrChild<RadioGroupPrimitive.ItemProps> & {
13
+ thumbnail?: Component;
14
+ children: Snippet;
15
+ } = $props();
16
+ </script>
17
+
18
+ <RadioGroupPrimitive.Item
19
+ bind:ref
20
+ class="rz-radio-card-group-item {className}"
21
+ data-thumbnail={Thumbnail ? '' : null}
22
+ {...restProps}
23
+ >
24
+ {#if Thumbnail}
25
+ <span class="rz-radio-card-group-item__frame">
26
+ <Thumbnail />
27
+ </span>
28
+ {/if}
29
+ <span class="rz-radio-card-group-item__label">{@render children()}</span>
30
+ </RadioGroupPrimitive.Item>
@@ -0,0 +1,9 @@
1
+ import { RadioGroup as RadioGroupPrimitive, type WithoutChildrenOrChild } from 'bits-ui';
2
+ import type { Component, Snippet } from 'svelte';
3
+ type $$ComponentProps = WithoutChildrenOrChild<RadioGroupPrimitive.ItemProps> & {
4
+ thumbnail?: Component;
5
+ children: Snippet;
6
+ };
7
+ declare const RadioCardGroupItem: Component<$$ComponentProps, {}, "ref">;
8
+ type RadioCardGroupItem = ReturnType<typeof RadioCardGroupItem>;
9
+ export default RadioCardGroupItem;
@@ -0,0 +1,80 @@
1
+ /* As many cards per line as fit, each at least --rz-size-40 wide. */
2
+ .rz-radio-card-group {
3
+ display: grid;
4
+ grid-template-columns: repeat(auto-fill, minmax(var(--rz-size-40), 1fr));
5
+ gap: var(--rz-size-2-5);
6
+
7
+ &[data-disabled] {
8
+ opacity: 0.4;
9
+ cursor: not-allowed;
10
+ button {
11
+ cursor: not-allowed;
12
+ }
13
+ }
14
+ }
15
+
16
+ /* A raised card, muted until hovered or checked. */
17
+ .rz-radio-card-group-item {
18
+ display: flex;
19
+ flex-direction: column;
20
+ gap: var(--rz-size-1-5);
21
+ min-width: 0;
22
+ padding: var(--rz-size-1-5) var(--rz-size-1-5) var(--rz-size-2);
23
+ background-color: var(--rz-bg-raised);
24
+ box-shadow:
25
+ 0 0 0 1px var(--rz-border),
26
+ var(--rz-shadow-raised, 0 0 transparent);
27
+ border-radius: var(--rz-radius-xl);
28
+ color: var(--rz-fg-muted);
29
+ font-size: var(--rz-text-sm);
30
+ text-align: left;
31
+ cursor: pointer;
32
+ outline: none;
33
+
34
+ &:hover,
35
+ &[data-state='checked'] {
36
+ background-image: linear-gradient(var(--rz-bg-hover) 0 0);
37
+ color: var(--rz-fg);
38
+ }
39
+
40
+ &[data-state='checked'] {
41
+ box-shadow: 0 0 0 1px var(--rz-accent-border);
42
+ }
43
+
44
+ &:focus-visible {
45
+ outline: 2px solid var(--rz-accent-border);
46
+ outline-offset: 2px;
47
+ }
48
+
49
+ /* Without a thumbnail, the label spans the card's width, its text in the middle. */
50
+ &:not([data-thumbnail]) {
51
+ justify-content: center;
52
+ text-align: center;
53
+ }
54
+ }
55
+
56
+ /* 16:10, the thumbnail filling it. */
57
+ .rz-radio-card-group-item__frame {
58
+ display: block;
59
+ aspect-ratio: 16 / 10;
60
+ overflow: hidden;
61
+ border-radius: var(--rz-radius-lg);
62
+ background-color: var(--rz-bg-well);
63
+ color: var(--rz-fg-subtle);
64
+
65
+ > svg {
66
+ display: block;
67
+ width: 100%;
68
+ height: 100%;
69
+ }
70
+ }
71
+
72
+ .rz-radio-card-group-item:is(:hover, [data-state='checked']) .rz-radio-card-group-item__frame {
73
+ color: var(--rz-fg-muted);
74
+ }
75
+
76
+ .rz-radio-card-group-item__label {
77
+ padding-inline: var(--rz-size-1);
78
+ font-variation-settings: 'wght' 500;
79
+ font-weight: 500;
80
+ }
@@ -0,0 +1,18 @@
1
+ <script lang="ts">
2
+ import { RadioGroup as RadioGroupPrimitive } from 'bits-ui';
3
+ import './radio-card-group.css';
4
+
5
+ let {
6
+ ref = $bindable(null),
7
+ class: className,
8
+ value = $bindable(''),
9
+ ...restProps
10
+ }: RadioGroupPrimitive.RootProps = $props();
11
+ </script>
12
+
13
+ <RadioGroupPrimitive.Root
14
+ bind:ref
15
+ bind:value
16
+ class="rz-radio-card-group {className}"
17
+ {...restProps}
18
+ />
@@ -0,0 +1,5 @@
1
+ import { RadioGroup as RadioGroupPrimitive } from 'bits-ui';
2
+ import './radio-card-group.css';
3
+ declare const RadioCardGroup: import("svelte").Component<RadioGroupPrimitive.RootProps, {}, "value" | "ref">;
4
+ type RadioCardGroup = ReturnType<typeof RadioCardGroup>;
5
+ export default RadioCardGroup;
@@ -1,5 +1,6 @@
1
1
  .rz-radio-row-group {
2
2
  display: flex;
3
+ flex-wrap: wrap;
3
4
  justify-content: space-between;
4
5
  align-self: flex-start;
5
6
  width: auto;
@@ -9,8 +10,7 @@
9
10
  border-color: var(--rz-border-strong);
10
11
  }
11
12
  border-radius: var(--rz-radius-lg);
12
- max-height: var(--rz-input-height);
13
- height: var(--rz-input-height);
13
+ min-height: var(--rz-input-height);
14
14
  padding: var(--rz-size-0-5);
15
15
 
16
16
  &[data-disabled] {
@@ -33,7 +33,9 @@
33
33
  padding: 0 var(--rz-size-4);
34
34
  background-color: transparent;
35
35
  border-radius: var(--rz-radius-md);
36
- height: 100%;
36
+ /* One line of the row: the input height less the well's padding. */
37
+ height: var(--rz-size-8);
38
+ white-space: nowrap;
37
39
  color: var(--rz-fg-muted);
38
40
  font-variation-settings: 'wght' 500;
39
41
  font-weight: 500;
@@ -1,3 +1,4 @@
1
+ import type { FieldBuilder } from '../../core/fields/builders/index.js';
1
2
  import type { GenericBlock } from '../../core/prototype/types.js';
2
3
  import type { FormErrors } from '../types.js';
3
4
  import type { Dic } from '../../util/types.js';
@@ -40,13 +41,15 @@ export declare const blockPath: (at: BlockAt) => string;
40
41
  export declare const shiftListPath: (list: string, removed: BlockAt) => string;
41
42
  /**
42
43
  * The path with each block index carrying its type, read off the document: what
43
- * `getFieldAtPath` wants.
44
+ * `getFieldAtPath` wants. Only an index in a list of blocks takes a type; a tree row keeps its
45
+ * bare index, even when it holds a field named `type`.
44
46
  *
45
47
  * ```
46
- * withBlockTypes('sections.0.items.1', doc) // 'sections.0:grid.items.1:paragraph'
48
+ * withBlockTypes('sections.0.items.1', doc, fields) // 'sections.0:grid.items.1:paragraph'
49
+ * withBlockTypes('links.0.label', doc, fields) // 'links.0.label'
47
50
  * ```
48
51
  */
49
- export declare const withBlockTypes: (path: string, doc: Dic) => string;
52
+ export declare const withBlockTypes: (path: string, doc: Dic, fields: FieldBuilder[]) => string;
50
53
  /**
51
54
  * Every `path` and `position` under a list, rewritten from the list's own path: the block's, and
52
55
  * those of the lists nested in it.
@@ -1,3 +1,4 @@
1
+ import { getFieldAtPath } from '../../core/fields/util.js';
1
2
  import { getValueAtPath, isObjectLiteral, setValueAtPath } from '../../util/object.js';
2
3
  import { isWithin, normalizeFieldPath } from '../../util/string.js';
3
4
  import { isTempId, tempId } from '../../util/random.js';
@@ -36,20 +37,22 @@ export const shiftListPath = (list, removed) => {
36
37
  };
37
38
  /**
38
39
  * The path with each block index carrying its type, read off the document: what
39
- * `getFieldAtPath` wants.
40
+ * `getFieldAtPath` wants. Only an index in a list of blocks takes a type; a tree row keeps its
41
+ * bare index, even when it holds a field named `type`.
40
42
  *
41
43
  * ```
42
- * withBlockTypes('sections.0.items.1', doc) // 'sections.0:grid.items.1:paragraph'
44
+ * withBlockTypes('sections.0.items.1', doc, fields) // 'sections.0:grid.items.1:paragraph'
45
+ * withBlockTypes('links.0.label', doc, fields) // 'links.0.label'
43
46
  * ```
44
47
  */
45
- export const withBlockTypes = (path, doc) => {
48
+ export const withBlockTypes = (path, doc, fields) => {
46
49
  const parts = normalizeFieldPath(path).split('.');
47
50
  const typed = [];
48
51
  for (let i = 0; i < parts.length; i++) {
49
52
  const part = parts[i];
50
- const isIndex = /^\d+$/.test(part);
51
- if (isIndex) {
52
- const item = getValueAtPath([...parts.slice(0, i), part].join('.'), doc);
53
+ const isBlockIndex = /^\d+$/.test(part) && getFieldAtPath(typed.join('.'), fields)?.type === 'blocks';
54
+ if (isBlockIndex) {
55
+ const item = getValueAtPath(parts.slice(0, i + 1).join('.'), doc);
53
56
  const type = item && isObjectLiteral(item) && typeof item.type === 'string' ? item.type : '';
54
57
  typed.push(type ? `${part}:${type}` : part);
55
58
  }
@@ -166,7 +166,8 @@ function createDocumentFormState({ initial, config, readOnly, key, onNestedDocum
166
166
  },
167
167
  /** The `BlocksBuilder` a list path names, read through the document for the block types. */
168
168
  builder(list) {
169
- const field = getFieldAtPath(withBlockTypes(list, doc), documentConfig.fields);
169
+ const typed = withBlockTypes(list, doc, documentConfig.fields);
170
+ const field = getFieldAtPath(typed, documentConfig.fields);
170
171
  return field && field.type === 'blocks' ? field : undefined;
171
172
  },
172
173
  /** Whether the list's block set has this type. */
@@ -278,11 +279,13 @@ function createDocumentFormState({ initial, config, readOnly, key, onNestedDocum
278
279
  };
279
280
  /**
280
281
  * The field at `path`, read and written through the form. `config` is the field's builder;
281
- * without it, the builder is looked up in the document's fields by `path`.
282
+ * without it, the builder is looked up in the document's fields by `path`, the block types read
283
+ * off the document: `sections.0.title` -> `sections.0:hero.title`.
282
284
  */
283
285
  function useField(path, config) {
284
286
  if (!config) {
285
- const resolved = getFieldAtPath(path, documentConfig.fields);
287
+ const typed = withBlockTypes(path, doc, documentConfig.fields);
288
+ const resolved = getFieldAtPath(typed, documentConfig.fields);
286
289
  if (!resolved)
287
290
  throw new Error(`can't find config for field : ${path}`);
288
291
  config = resolved;
@@ -602,13 +602,6 @@ video {
602
602
 
603
603
  /* shadows: only what floats over the page casts one */
604
604
  --rz-shadow-float: 0 16px 36px -12px oklch(from var(--rz-gray-0) l c h / 0.16);
605
-
606
- /* gradients */
607
- --rz-glow: radial-gradient(
608
- 70% 38% at 50% 0%,
609
- oklch(from var(--rz-accent-solid) l c h / 0.035),
610
- transparent
611
- );
612
605
  }
613
606
 
614
607
  @media (prefers-color-scheme: dark) {
@@ -639,11 +632,6 @@ video {
639
632
  --rz-ring: oklch(from var(--rz-accent-soft) l c h / 0.2);
640
633
 
641
634
  --rz-shadow-float: 0 16px 40px -12px oklch(from var(--rz-gray-0) l c h / 0.6);
642
- --rz-glow: radial-gradient(
643
- 70% 38% at 50% 0%,
644
- oklch(from var(--rz-accent-solid) l c h / 0.07),
645
- transparent
646
- );
647
635
  }
648
636
  }
649
637
 
@@ -42,13 +42,6 @@
42
42
 
43
43
  /* shadows: only what floats over the page casts one */
44
44
  --rz-shadow-float: 0 16px 36px -12px oklch(from var(--rz-gray-0) l c h / 0.16);
45
-
46
- /* gradients */
47
- --rz-glow: radial-gradient(
48
- 70% 38% at 50% 0%,
49
- oklch(from var(--rz-accent-solid) l c h / 0.035),
50
- transparent
51
- );
52
45
  }
53
46
 
54
47
  @media (prefers-color-scheme: dark) {
@@ -79,10 +72,5 @@
79
72
  --rz-ring: oklch(from var(--rz-accent-soft) l c h / 0.2);
80
73
 
81
74
  --rz-shadow-float: 0 16px 40px -12px oklch(from var(--rz-gray-0) l c h / 0.6);
82
- --rz-glow: radial-gradient(
83
- 70% 38% at 50% 0%,
84
- oklch(from var(--rz-accent-solid) l c h / 0.07),
85
- transparent
86
- );
87
75
  }
88
76
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rimecms",
3
- "version": "1.4.2",
3
+ "version": "1.5.0",
4
4
  "homepage": "https://github.com/bienbiendev/rime",
5
5
  "packageManager": "bun@1.3.0",
6
6
  "scripts": {