rimecms 1.1.4 → 1.1.6

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.
Files changed (29) hide show
  1. package/dist/adapter-sqlite/generate-schema/index.server.js +1 -7
  2. package/dist/adapter-sqlite/generate-schema/root.server.d.ts +2 -2
  3. package/dist/adapter-sqlite/generate-schema/root.server.js +2 -2
  4. package/dist/adapter-sqlite/generate-schema/templates.server.d.ts +0 -12
  5. package/dist/adapter-sqlite/generate-schema/templates.server.js +0 -24
  6. package/dist/adapter-sqlite/index.server.d.ts +0 -2
  7. package/dist/adapter-sqlite/index.server.js +0 -3
  8. package/dist/adapter-sqlite/select.server.js +2 -2
  9. package/dist/adapter-sqlite/where.server.js +2 -2
  10. package/dist/core/i18n/en/fields.d.ts +2 -0
  11. package/dist/core/i18n/en/fields.js +2 -0
  12. package/dist/core/i18n/fr/fields.d.ts +2 -0
  13. package/dist/core/i18n/fr/fields.js +2 -0
  14. package/dist/core/pipeline/hooks/set-default-values.server.js +2 -2
  15. package/dist/core/pipeline/persist/relations/extract.server.js +2 -2
  16. package/dist/core/prototype/collection/thumbnail/find-thumbnail.js +2 -2
  17. package/dist/core/prototype/shared/versions/hooks/handle-new-version.server.js +2 -2
  18. package/dist/fields/relation/component/upload/Upload.svelte +236 -46
  19. package/dist/fields/relation/index.d.ts +8 -0
  20. package/dist/fields/relation/index.js +6 -0
  21. package/dist/fields/rich-text/component/RichText.svelte +3 -9
  22. package/dist/fields/rich-text/component/bubble-menu/bubble-menu.css +0 -1
  23. package/dist/fields/rich-text/component/props.d.ts +0 -1
  24. package/dist/fields/rich-text/core/build-editor-config.d.ts +0 -1
  25. package/dist/fields/rich-text/core/features/resource/index.js +6 -1
  26. package/dist/fields/rich-text/core/features/resource/resource-extension.d.ts +0 -8
  27. package/dist/fields/rich-text/core/features/resource/resource-extension.js +0 -10
  28. package/dist/fields/tabs/component/Tabs.svelte +1 -9
  29. package/package.json +1 -1
@@ -3,7 +3,7 @@ import { baseTableName, declaredTableProperty, tableName } from '../naming.serve
3
3
  import { date } from '../../fields/date/index.js';
4
4
  import { generateJunctionTableDefinition } from './relations/junction.server.js';
5
5
  import buildRootTable, {} from './root.server.js';
6
- import { templateDeclaredTable, templateExportRelationsFieldsToTable, templateExportSchema, templateExportTables, templateHead, templateImports, templatePathsTable, templateRelations } from './templates.server.js';
6
+ import { templateDeclaredTable, templateExportSchema, templateExportTables, templateHead, templateImports, templatePathsTable, templateRelations } from './templates.server.js';
7
7
  import write from './write.server.js';
8
8
  export async function generateSchemaString(config) {
9
9
  // Every prototype config in the build, each paired with the features that extend its kind —
@@ -19,7 +19,6 @@ export async function generateSchemaString(config) {
19
19
  let enumTables = [];
20
20
  /** parent table -> its child tables, for the one `defineRelations` at the end. */
21
21
  const relationTree = {};
22
- let relationFieldsExportDic = {};
23
22
  const blocksRegister = [];
24
23
  /** Every resolved reference, joined onto its owner in the same `defineRelations`. */
25
24
  const referenceJoins = [];
@@ -82,10 +81,6 @@ export async function generateSchemaString(config) {
82
81
  for (const [parent, children] of Object.entries(relationsDic)) {
83
82
  (relationTree[parent] ??= []).push(...children);
84
83
  }
85
- relationFieldsExportDic = {
86
- ...relationFieldsExportDic,
87
- [rootTableName]: relationFieldsMap
88
- };
89
84
  schema.push(prototypeSchema, junctionTable);
90
85
  // A collection with `$url` keeps its pages' addresses in a table of their own, off the base
91
86
  // table: an address belongs to the page, not to one of its versions.
@@ -105,7 +100,6 @@ export async function generateSchemaString(config) {
105
100
  schema.push(templateExportTables(enumTables));
106
101
  // After `tables`, which `defineRelations` takes as its first argument.
107
102
  schema.push(templateRelations(relationTree, referenceJoins));
108
- schema.push(templateExportRelationsFieldsToTable(relationFieldsExportDic));
109
103
  schema.push(templateExportSchema({ enumTables }));
110
104
  return schema.join('\n').replace(/\n{3,}/g, '\n\n');
111
105
  }
@@ -1,8 +1,8 @@
1
- import type { LocaleConfig } from '../../core/locale/types.js';
1
+ import type { ColumnDeclaration } from '../../core/adapter.js';
2
2
  import type { FieldBuilder } from '../../core/fields/builders/field-builder.js';
3
+ import type { LocaleConfig } from '../../core/locale/types.js';
3
4
  import type { Field } from '../../fields/types.js';
4
5
  import type { TableName } from '../naming.server.js';
5
- import type { ColumnDeclaration } from '../../core/adapter.js';
6
6
  /** A relation field on a prototype: which collection it points at, and whether it is localized. */
7
7
  export type RelationFieldsMap = Record<string, {
8
8
  to: string;
@@ -1,6 +1,6 @@
1
1
  import { FormFieldBuilder } from '../../core/fields/builders/form-field-builder.js';
2
2
  import { walkFields } from '../../core/fields/walk.js';
3
- import { RelationFieldBuilder } from '../../fields/relation/index.js';
3
+ import { isRelationField } from '../../fields/relation/index.js';
4
4
  import { tableName as buildTableName, getSchemaColumnNames } from '../naming.server.js';
5
5
  import { toSchemaColumn } from './column.server.js';
6
6
  import { templateDeclaredColumn, templateLocale, templateParent, templateTable } from './templates.server.js';
@@ -63,7 +63,7 @@ const buildRootTable = async ({ fields: incomingFields, tableName, rootName, has
63
63
  };
64
64
  for (const field of fields) {
65
65
  // Junction rows: no column here, and the relations table wants to know it exists.
66
- if (field instanceof RelationFieldBuilder) {
66
+ if (isRelationField(field)) {
67
67
  if (field.get.localized) {
68
68
  relationFieldsHasLocale = true;
69
69
  }
@@ -179,18 +179,6 @@ export declare const templateFieldRelationColumn: (slug: string) => string;
179
179
  * ```
180
180
  */
181
181
  export declare const templateRelationFieldsTable: ({ table, junctionTable, relations, hasLocale }: FieldsRelationTableArgs) => string;
182
- /**
183
- * Generates an export of relation field mappings for runtime use
184
- * Creates a record mapping table names to their relation configurations
185
- *
186
- * @example
187
- * ```typescript
188
- * export const relationFieldsMap: Record<string, any> = {
189
- * pages: {"medias":{"to":"medias"},"categories":{"to":"categories"}}
190
- * }
191
- * ```
192
- */
193
- export declare const templateExportRelationsFieldsToTable: (relationFieldsDic: Record<string, string>) => string;
194
182
  /**
195
183
  * Generates an export of all tables for runtime use
196
184
  * Creates a record with all table definitions and proper TypeScript types
@@ -301,30 +301,6 @@ export const ${junctionTable} = sqliteTable('${junctionTable}', {
301
301
  ${hasLocale ? `locale: text('locale'),` : ''}
302
302
  }${templateIndexes(junctionTable, ['ownerId', ...relations.map((rel) => `${rel}Id`)])})
303
303
  `;
304
- /**
305
- * Generates an export of relation field mappings for runtime use
306
- * Creates a record mapping table names to their relation configurations
307
- *
308
- * @example
309
- * ```typescript
310
- * export const relationFieldsMap: Record<string, any> = {
311
- * pages: {"medias":{"to":"medias"},"categories":{"to":"categories"}}
312
- * }
313
- * ```
314
- */
315
- export const templateExportRelationsFieldsToTable = (relationFieldsDic) => {
316
- const content = [];
317
- for (const [table, dic] of Object.entries(relationFieldsDic)) {
318
- content.push(dedent `
319
- ${table} : ${JSON.stringify(dic)}
320
- `);
321
- }
322
- return dedent `
323
- export const relationFieldsMap: Record<string, any> = {
324
- ${content.join(',\n ')}
325
- }
326
- `;
327
- };
328
304
  /**
329
305
  * Generates an export of all tables for runtime use
330
306
  * Creates a record with all table definitions and proper TypeScript types
@@ -4,7 +4,6 @@ import type { ConfigContext } from '../core/rime.server.js';
4
4
  import type { GetRegisterType } from '../index.js';
5
5
  import { type SqliteDriver } from './connect.server.js';
6
6
  import generateSchema from './generate-schema/index.server.js';
7
- import type { RelationFieldsMap } from './generate-schema/root.server.js';
8
7
  import type { GenericTable, SqliteDatabase } from './types.server.js';
9
8
  type Schema = GetRegisterType<'Schema'>;
10
9
  export type { SqliteDriver };
@@ -37,5 +36,4 @@ export type SqliteAdapter = Adapter & {
37
36
  getTable<T>(key: string): T extends any ? GenericTable : T;
38
37
  tableForSlug<T>(slug: string): T extends any ? GenericTable : T;
39
38
  readonly schema: Schema;
40
- readonly relationFieldsMap: RelationFieldsMap;
41
39
  };
@@ -69,9 +69,6 @@ const createAdapter = async (args) => {
69
69
  },
70
70
  get schema() {
71
71
  return schema.default;
72
- },
73
- get relationFieldsMap() {
74
- return schema.relationFieldsMap;
75
72
  }
76
73
  };
77
74
  };
@@ -1,6 +1,6 @@
1
1
  import { getFieldAtPath, resolvedReferencesOf } from '../core/fields/util.js';
2
2
  import { getColumns } from 'drizzle-orm';
3
- import { RelationFieldBuilder } from '../fields/relation/index.js';
3
+ import { isRelationField } from '../fields/relation/index.js';
4
4
  import { baseTableName, childTableNames, joinName, tableName } from './naming.server.js';
5
5
  /** What a joined target is projected to, beside its `id`: whatever of these its table has. */
6
6
  const JOINED_COLUMNS = ['name', 'email', 'title', 'filename'];
@@ -95,7 +95,7 @@ export const buildWithParam = (args) => {
95
95
  const fieldConfig = getFieldAtPath(path, documentConfig.fields);
96
96
  // Each branch is where the field's rows are stored: the junction table, a child table, or a
97
97
  // column of the row itself.
98
- if (fieldConfig instanceof RelationFieldBuilder) {
98
+ if (isRelationField(fieldConfig)) {
99
99
  directRelationPaths.push(path);
100
100
  }
101
101
  else if (fieldConfig && storageKinds(fieldConfig).length) {
@@ -1,7 +1,7 @@
1
1
  import { RimeError } from '../core/errors/index.js';
2
2
  import { getFieldAtPath } from '../core/fields/util.js';
3
3
  import { logger } from '../core/logger.server.js';
4
- import { RelationFieldBuilder } from '../fields/relation/index.js';
4
+ import { isRelationField } from '../fields/relation/index.js';
5
5
  import {} from '../index.js';
6
6
  import * as drizzleORM from 'drizzle-orm';
7
7
  import { and, eq, getTableColumns, inArray, or } from 'drizzle-orm';
@@ -119,7 +119,7 @@ export const buildWhereParam = ({ query, slug, db, locale, tables, configCtx, ba
119
119
  }
120
120
  }
121
121
  // If still not found or not a relation field, log warning and return false condition
122
- if (!(fieldConfig instanceof RelationFieldBuilder)) {
122
+ if (!isRelationField(fieldConfig)) {
123
123
  const message = `the query contains the field "${column}", not found for ${documentConfig.slug} document`;
124
124
  logger.warn(message);
125
125
  // Return a condition that will always be false instead of returning false
@@ -55,6 +55,8 @@ declare namespace _default {
55
55
  let uploading: string;
56
56
  let upload_progress: string;
57
57
  let upload_failed: string;
58
+ let upload_another: string;
59
+ let drop_to_replace: string;
58
60
  let clear: string;
59
61
  let add_images: string;
60
62
  let add_files: string;
@@ -55,6 +55,8 @@ export default {
55
55
  uploading: 'Uploading $1 of $2…',
56
56
  upload_progress: '$1 of $2 uploaded',
57
57
  upload_failed: 'Not uploaded: $1',
58
+ upload_another: 'Upload another file',
59
+ drop_to_replace: 'Drop to replace',
58
60
  clear: 'Clear',
59
61
  add_images: 'Add $1 {image|image|images|images}',
60
62
  add_files: 'Add $1 {file|file|files|files}',
@@ -55,6 +55,8 @@ declare namespace _default {
55
55
  let uploading: string;
56
56
  let upload_progress: string;
57
57
  let upload_failed: string;
58
+ let upload_another: string;
59
+ let drop_to_replace: string;
58
60
  let clear: string;
59
61
  let add_images: string;
60
62
  let add_files: string;
@@ -55,6 +55,8 @@ export default {
55
55
  uploading: 'Import de $1 sur $2…',
56
56
  upload_progress: '$1 sur $2 importé(s)',
57
57
  upload_failed: 'Non importé(s) : $1',
58
+ upload_another: 'Importer un autre fichier',
59
+ drop_to_replace: 'Déposez pour remplacer',
58
60
  clear: 'Effacer',
59
61
  add_images: 'Ajouter $1 {image|image|images|images}',
60
62
  add_files: 'Ajouter $1 {fichier|fichier|fichiers|fichiers}',
@@ -3,7 +3,7 @@ import { getRequestEvent } from '$app/server';
3
3
  import { isFormField } from '../../fields/util.js';
4
4
  import { walkFields } from '../../fields/walk.js';
5
5
  import { logger } from '../../logger.server.js';
6
- import { RelationFieldBuilder } from '../../../fields/relation/index.js';
6
+ import { isRelationField } from '../../../fields/relation/index.js';
7
7
  import { getValueAtPath, setValueAtPath } from '../../../util/object.js';
8
8
  import { buildConfigMap } from '../config-map/index.js';
9
9
  /**
@@ -93,7 +93,7 @@ const defaultRelationValue = async (config, key, adapter) => {
93
93
  };
94
94
  /** A relation's default becomes junction rows, checked against the collection. */
95
95
  export const getDefaultValue = async ({ key, config, adapter }) => {
96
- if (config instanceof RelationFieldBuilder) {
96
+ if (isRelationField(config)) {
97
97
  return await defaultRelationValue(config, key, adapter);
98
98
  }
99
99
  return config.use.defaultValue({ event: getRequestEvent() });
@@ -1,4 +1,4 @@
1
- import { RelationFieldBuilder } from '../../../../fields/relation/index.js';
1
+ import { isRelationField } from '../../../../fields/relation/index.js';
2
2
  import { Relation } from '../../../../fields/relation/relation.js';
3
3
  import { getValueAtPath, isObjectLiteral } from '../../../../util/object.js';
4
4
  export const extractRelations = ({ ownerId, data, configMap, locale }) => {
@@ -6,7 +6,7 @@ export const extractRelations = ({ ownerId, data, configMap, locale }) => {
6
6
  // The config map keys every field the document holds; relations are the ones stored as junction
7
7
  // rows, and the key is the `path` those rows carry.
8
8
  for (const [path, config] of Object.entries(configMap)) {
9
- if (config instanceof RelationFieldBuilder) {
9
+ if (isRelationField(config)) {
10
10
  const value = getValueAtPath(path, data);
11
11
  // One value outside an array is a list of one.
12
12
  const entries = Array.isArray(value) ? value : value ? [value] : [];
@@ -1,9 +1,9 @@
1
1
  import { walkFields } from '../../../fields/walk.js';
2
- import { RelationFieldBuilder } from '../../../../fields/relation/index.js';
2
+ import { isRelationField } from '../../../../fields/relation/index.js';
3
3
  /** The first relation marked `isThumbnail()`, at a path a config alone can name. */
4
4
  export function findThumbnailField(fields = [], basePath = '') {
5
5
  for (const { field, path } of walkFields(fields, { path: basePath, determinate: true })) {
6
- if (field instanceof RelationFieldBuilder && field.get.isThumbnail === true) {
6
+ if (isRelationField(field) && field.get.isThumbnail === true) {
7
7
  return { field, path };
8
8
  }
9
9
  }
@@ -7,7 +7,7 @@ import { fileForDocument } from '../../../collection/upload/util/converter.serve
7
7
  import { VERSIONS_STATUS } from '../constant.js';
8
8
  import { withVersionsSuffix } from '../naming.js';
9
9
  import { VersionOperations } from '../strategy.js';
10
- import { RelationFieldBuilder } from '../../../../../fields/relation/index.js';
10
+ import { isRelationField } from '../../../../../fields/relation/index.js';
11
11
  import { Relation } from '../../../../../fields/relation/relation.js';
12
12
  import { getValueAtPath, isObjectLiteral, omit, recursiveRemoveKeys, setValueAtPath } from '../../../../../util/object.js';
13
13
  import { retireAutoSaves } from '../retire-auto-saves.server.js';
@@ -191,7 +191,7 @@ async function prepareDataForNewVersion(args) {
191
191
  // A relation sent back as documents, read at depth 1, keeps what it points to: the strip
192
192
  // below takes every `id`, a document's own included.
193
193
  for (const [path, field] of Object.entries(buildConfigMap(data, config.fields))) {
194
- if (!(field instanceof RelationFieldBuilder))
194
+ if (!isRelationField(field))
195
195
  continue;
196
196
  const value = getValueAtPath(path, data);
197
197
  if (!Array.isArray(value))
@@ -6,6 +6,7 @@
6
6
  import { getAPIProxyContext } from '../../../../panel/context/api-proxy.svelte.js';
7
7
  import {
8
8
  acceptLabel,
9
+ mediaMeta,
9
10
  typeLabel,
10
11
  uploadFiles,
11
12
  type UploadProgress
@@ -41,6 +42,8 @@
41
42
  const APIProxy = getAPIProxyContext();
42
43
  /** What the picker marks, in order. */
43
44
  const selected = $derived(selectedItems.map((item) => item.documentId));
45
+ /** A field of one: its pick, drawn as a card in the zone's place. */
46
+ const picked = $derived(many ? undefined : selectedItems[0]);
44
47
  const accept = $derived(relationConfig.upload?.accept);
45
48
 
46
49
  /* ------------------------------------------------------------ uploading */
@@ -93,7 +96,81 @@
93
96
  const slots = $derived(many ? (SLOTS - (selectedItems.length % SLOTS)) % SLOTS : 0);
94
97
  </script>
95
98
 
96
- {#if !readOnly}
99
+ {#snippet uploading(current: UploadProgress)}
100
+ {t__(
101
+ 'fields.uploading',
102
+ String(Math.min(current.uploaded + current.failed.length + 1, current.total)),
103
+ String(current.total)
104
+ )}
105
+ {/snippet}
106
+
107
+ {#if picked}
108
+ <!--
109
+ One pick: its image, name and size, then upload another file or remove it. A file dropped on
110
+ the card replaces the pick.
111
+ -->
112
+ <FileDrop
113
+ class="rz-relation-upload__card"
114
+ {accept}
115
+ disabled={readOnly || !!progress}
116
+ data-error={hasError ? '' : undefined}
117
+ onfiles={upload}
118
+ >
119
+ {#snippet children({ browse })}
120
+ <a
121
+ class="rz-relation-upload__card-thumb"
122
+ href={panelPath(relationConfig.kebab, picked.documentId)}
123
+ aria-label={picked.title}
124
+ >
125
+ {#if progress}
126
+ <SpinLoader />
127
+ {:else if picked.isImage && picked.url}
128
+ <img src={picked.url} alt="" />
129
+ {:else}
130
+ <span class="rz-relation-upload__type">{typeLabel(picked.mimeType)}</span>
131
+ {/if}
132
+ </a>
133
+ <div class="rz-relation-upload__card-info">
134
+ <a
135
+ class="rz-relation-upload__card-name"
136
+ href={panelPath(relationConfig.kebab, picked.documentId)}
137
+ >
138
+ {picked.title}
139
+ </a>
140
+ <span class="rz-relation-upload__card-meta" aria-live="polite">
141
+ {#if progress}{@render uploading(progress)}{:else}{mediaMeta(picked)}{/if}
142
+ </span>
143
+ </div>
144
+ {#if !readOnly && !progress}
145
+ <div class="rz-relation-upload__card-actions">
146
+ <button
147
+ type="button"
148
+ title={t__('fields.upload_another')}
149
+ aria-label={t__('fields.upload_another')}
150
+ onclick={browse}
151
+ >
152
+ <Upload size={15} />
153
+ </button>
154
+ <button
155
+ type="button"
156
+ title={t__('fields.remove_item', picked.title)}
157
+ aria-label={t__('fields.remove_item', picked.title)}
158
+ onclick={() => removeValue(picked.documentId)}
159
+ >
160
+ <X size={15} />
161
+ </button>
162
+ </div>
163
+ {/if}
164
+ <span class="rz-relation-upload__card-drop" aria-hidden="true">
165
+ <Upload size={15} />
166
+ {t__('fields.drop_to_replace')}
167
+ </span>
168
+ {/snippet}
169
+ </FileDrop>
170
+ {#if failed.length}
171
+ <p class="rz-relation-upload__failed">{t__('fields.upload_failed', failed.join(', '))}</p>
172
+ {/if}
173
+ {:else if !readOnly}
97
174
  <FileDrop
98
175
  class="rz-relation-upload__drop"
99
176
  multiple={many}
@@ -105,13 +182,7 @@
105
182
  {#snippet children({ browse })}
106
183
  {#if progress}
107
184
  <SpinLoader />
108
- <span aria-live="polite">
109
- {t__(
110
- 'fields.uploading',
111
- String(Math.min(progress.uploaded + progress.failed.length + 1, progress.total)),
112
- String(progress.total)
113
- )}
114
- </span>
185
+ <span aria-live="polite">{@render uploading(progress)}</span>
115
186
  {:else}
116
187
  <Upload size={18} />
117
188
  <span>
@@ -132,43 +203,40 @@
132
203
  {/if}
133
204
  {/if}
134
205
 
135
- {#key stamp}
136
- <div
137
- bind:this={list}
138
- class="rz-relation-upload__list"
139
- data-many={many ? '' : null}
140
- data-error={hasError ? '' : null}
141
- >
142
- {#each selectedItems as item (item.documentId)}
143
- <div class="rz-relation-upload__thumb" title={item.title}>
144
- <a
145
- href={panelPath(relationConfig.kebab, item.documentId)}
146
- aria-label={item.title}
147
- draggable="false"
148
- >
149
- {#if item.isImage && item.url}
150
- <img src={item.url} alt="" draggable="false" />
151
- {:else}
152
- <span class="rz-relation-upload__type">{typeLabel(item.mimeType)}</span>
153
- {/if}
154
- </a>
155
- {#if !readOnly}
156
- <button
157
- type="button"
158
- class="rz-relation-upload__remove"
159
- aria-label={t__('fields.remove_item', item.title)}
160
- onclick={() => removeValue(item.documentId)}
206
+ {#if many}
207
+ {#key stamp}
208
+ <div bind:this={list} class="rz-relation-upload__list" data-error={hasError ? '' : null}>
209
+ {#each selectedItems as item (item.documentId)}
210
+ <div class="rz-relation-upload__thumb" title={item.title}>
211
+ <a
212
+ href={panelPath(relationConfig.kebab, item.documentId)}
213
+ aria-label={item.title}
214
+ draggable="false"
161
215
  >
162
- <X size={11} />
163
- </button>
164
- {/if}
165
- </div>
166
- {/each}
167
- {#each { length: slots }, index (index)}
168
- <div class="rz-relation-upload__slot" aria-hidden="true"></div>
169
- {/each}
170
- </div>
171
- {/key}
216
+ {#if item.isImage && item.url}
217
+ <img src={item.url} alt="" draggable="false" />
218
+ {:else}
219
+ <span class="rz-relation-upload__type">{typeLabel(item.mimeType)}</span>
220
+ {/if}
221
+ </a>
222
+ {#if !readOnly}
223
+ <button
224
+ type="button"
225
+ class="rz-relation-upload__remove"
226
+ aria-label={t__('fields.remove_item', item.title)}
227
+ onclick={() => removeValue(item.documentId)}
228
+ >
229
+ <X size={11} />
230
+ </button>
231
+ {/if}
232
+ </div>
233
+ {/each}
234
+ {#each { length: slots }, index (index)}
235
+ <div class="rz-relation-upload__slot" aria-hidden="true"></div>
236
+ {/each}
237
+ </div>
238
+ {/key}
239
+ {/if}
172
240
 
173
241
  <Browse
174
242
  bind:open={browsing}
@@ -199,7 +267,7 @@
199
267
  border-color: var(--rz-danger);
200
268
  }
201
269
 
202
- /* Narrow, in a side panel: the zone on one line. */
270
+ /* Narrow, in a side panel: the zone on one line, the card's image smaller. */
203
271
  @container rz-field-root (max-width: 20rem) {
204
272
  :global(.rz-relation-upload__drop) {
205
273
  flex-direction: row;
@@ -213,6 +281,128 @@
213
281
  :global(.rz-relation-upload__drop small) {
214
282
  flex-basis: 100%;
215
283
  }
284
+ .rz-relation-upload__card-thumb {
285
+ width: var(--rz-size-11);
286
+ height: var(--rz-size-11);
287
+ }
288
+ }
289
+
290
+ /*
291
+ * One pick, in the zone's place: the media's image, its name and size, then its actions, on a
292
+ * well with a hairline. `div.` outweighs the zone's own look.
293
+ */
294
+ :global(div.rz-file-drop.rz-relation-upload__card) {
295
+ flex-direction: row;
296
+ justify-content: flex-start;
297
+ gap: var(--rz-size-3);
298
+ padding: var(--rz-size-2);
299
+ border: 0;
300
+ border-radius: var(--rz-radius-lg);
301
+ box-shadow: inset 0 0 0 1px var(--rz-border);
302
+ color: var(--rz-fg);
303
+ text-align: left;
304
+ }
305
+
306
+ :global(div.rz-file-drop.rz-relation-upload__card[data-over]) {
307
+ box-shadow: inset 0 0 0 1px var(--rz-accent-border);
308
+ }
309
+
310
+ .rz-relation-upload__card-thumb {
311
+ display: grid;
312
+ place-items: center;
313
+ flex-shrink: 0;
314
+ width: var(--rz-size-14);
315
+ height: var(--rz-size-14);
316
+ overflow: hidden;
317
+ border-radius: var(--rz-radius-md);
318
+ background-color: var(--rz-bg-well);
319
+
320
+ img {
321
+ width: 100%;
322
+ height: 100%;
323
+ -o-object-fit: cover;
324
+ object-fit: cover;
325
+ }
326
+ &:focus-visible {
327
+ outline: 2px solid var(--rz-accent-border);
328
+ outline-offset: 2px;
329
+ }
330
+ }
331
+
332
+ .rz-relation-upload__card-info {
333
+ display: flex;
334
+ flex-direction: column;
335
+ gap: var(--rz-size-0-5);
336
+ flex: 1;
337
+ min-width: 0;
338
+ }
339
+
340
+ .rz-relation-upload__card-name {
341
+ font-variation-settings: 'wght' 500;
342
+ font-weight: 500;
343
+ overflow: hidden;
344
+ text-overflow: ellipsis;
345
+ white-space: nowrap;
346
+ &:hover {
347
+ text-decoration: underline;
348
+ text-underline-offset: 2px;
349
+ }
350
+ &:focus-visible {
351
+ outline: 2px solid var(--rz-accent-border);
352
+ outline-offset: 2px;
353
+ border-radius: var(--rz-radius-sm);
354
+ }
355
+ }
356
+
357
+ .rz-relation-upload__card-meta {
358
+ color: var(--rz-fg-subtle);
359
+ font-size: var(--rz-text-sm);
360
+ }
361
+
362
+ .rz-relation-upload__card-actions {
363
+ display: flex;
364
+ gap: var(--rz-size-0-5);
365
+
366
+ button {
367
+ display: grid;
368
+ place-items: center;
369
+ width: var(--rz-size-7);
370
+ height: var(--rz-size-7);
371
+ border-radius: var(--rz-radius-sm);
372
+ color: var(--rz-fg-muted);
373
+ &:hover {
374
+ background-color: var(--rz-bg-hover);
375
+ color: var(--rz-fg);
376
+ }
377
+ &:focus-visible {
378
+ outline: 2px solid var(--rz-accent-border);
379
+ outline-offset: 2px;
380
+ }
381
+ }
382
+ }
383
+
384
+ /* A file over the card: the image dims, "Drop to replace" takes the name's place. */
385
+ .rz-relation-upload__card-drop {
386
+ display: none;
387
+ align-items: center;
388
+ gap: var(--rz-size-2);
389
+ flex: 1;
390
+ color: var(--rz-accent-text);
391
+ font-variation-settings: 'wght' 500;
392
+ font-weight: 500;
393
+ }
394
+
395
+ :global(.rz-relation-upload__card[data-over]) {
396
+ .rz-relation-upload__card-drop {
397
+ display: flex;
398
+ }
399
+ .rz-relation-upload__card-info,
400
+ .rz-relation-upload__card-actions {
401
+ display: none;
402
+ }
403
+ .rz-relation-upload__card-thumb {
404
+ opacity: 0.45;
405
+ }
216
406
  }
217
407
 
218
408
  .rz-relation-upload__failed {
@@ -276,7 +466,7 @@
276
466
  }
277
467
  }
278
468
 
279
- .rz-relation-upload__list[data-many] .rz-relation-upload__thumb {
469
+ .rz-relation-upload__list .rz-relation-upload__thumb {
280
470
  cursor: grab;
281
471
  }
282
472
 
@@ -39,6 +39,14 @@ export declare class RelationFieldBuilder<Doc extends GenericDoc = GenericDoc> e
39
39
  protected generateType(): string;
40
40
  }
41
41
  export declare const relation: (name: string) => RelationFieldBuilder<GenericDoc>;
42
+ /**
43
+ * A relation, told by its type. `instanceof` is not enough: a dev reload can load this class
44
+ * twice, and a relation built from the other copy then fails it. The schema generator once took
45
+ * such a relation for a text column, and dropped the junction table with every row in it.
46
+ */
47
+ export declare const isRelationField: (field: {
48
+ type?: string;
49
+ } | null | undefined) => field is RelationFieldBuilder;
42
50
  /****************************************************/
43
51
  export type RelationField<Doc extends GenericDoc = GenericDoc> = FormField & {
44
52
  type: 'relation';
@@ -76,3 +76,9 @@ export class RelationFieldBuilder extends FormFieldBuilder {
76
76
  }
77
77
  }
78
78
  export const relation = (name) => new RelationFieldBuilder(name);
79
+ /**
80
+ * A relation, told by its type. `instanceof` is not enough: a dev reload can load this class
81
+ * twice, and a relation built from the other copy then fails it. The schema generator once took
82
+ * such a relation for a text column, and dropped the junction table with every row in it.
83
+ */
84
+ export const isRelationField = (field) => field?.type === 'relation';
@@ -7,16 +7,12 @@
7
7
  import type { RichTextFieldProps } from './props.js';
8
8
  import './styles/field.css';
9
9
 
10
- const { path, config, form, standAlone, class: className }: RichTextFieldProps = $props();
10
+ const { path, config, form, class: className }: RichTextFieldProps = $props();
11
11
 
12
12
  const field = $derived(form.useField<JSONContent>(path, config));
13
13
  </script>
14
14
 
15
- <fieldset
16
- class:rz-field-rich-text--standalone={standAlone}
17
- class="rz-field-rich-text {config.get.className || ''}"
18
- use:fieldset={field}
19
- >
15
+ <fieldset class="rz-field-rich-text {config.get.className || ''}" use:fieldset={field}>
20
16
  <Field.Label {config} for={path || config.name} />
21
17
 
22
18
  <Field.Error error={field.error} />
@@ -31,9 +27,7 @@
31
27
  onUpdate={(json) => (field.value = json)}
32
28
  />
33
29
 
34
- {#if !standAlone}
35
- <Field.Hint {config} />
36
- {/if}
30
+ <Field.Hint {config} />
37
31
  </fieldset>
38
32
 
39
33
  <style>
@@ -14,5 +14,4 @@
14
14
  position: absolute;
15
15
  left: -9999px;
16
16
  top: -9999px;
17
- height: var(--rz-input-height);
18
17
  }
@@ -3,7 +3,6 @@ import type { RichTextFieldBuilder } from '../index.js';
3
3
  export type RichTextFieldProps = {
4
4
  class?: string;
5
5
  path: string;
6
- standAlone?: boolean;
7
6
  config: RichTextFieldBuilder;
8
7
  form: DocumentFormContext;
9
8
  };
@@ -1,7 +1,6 @@
1
1
  import type { RichTextEditorConfig, RichTextFeature } from './types.js';
2
2
  type BuildEditorConfigArgs = {
3
3
  features: Array<RichTextFeature>;
4
- standAlone?: boolean;
5
4
  };
6
5
  /**
7
6
  * Builds a rich text editor configuration based on the provided features
@@ -12,7 +12,12 @@ export const ResourceFeature = (args) => {
12
12
  icon: Images,
13
13
  isActive: ({ editor }) => editor.isActive('rich-text-resource-' + slug),
14
14
  suggestion: {
15
- command: ({ editor }) => editor.chain().focus().insertResource().run()
15
+ // This feature's own node: each `resource()` is a node type of its own.
16
+ command: ({ editor }) => editor
17
+ .chain()
18
+ .focus()
19
+ .insertContent({ type: 'rich-text-resource-' + slug, attrs: { _fresh: true } })
20
+ .run()
16
21
  }
17
22
  }
18
23
  ]
@@ -1,13 +1,5 @@
1
1
  import type { PrototypeSlug } from '../../../../../core/prototype/types.js';
2
- import type { Dic } from '../../../../../util/types.js';
3
2
  import { Node } from '@tiptap/core';
4
- declare module '@tiptap/core' {
5
- interface Commands<ReturnType> {
6
- resource: {
7
- insertResource: (attributes?: Dic) => ReturnType;
8
- };
9
- }
10
- }
11
3
  export interface ResourceFeatureExtensionOptions {
12
4
  label?: string;
13
5
  source: `${PrototypeSlug}${string}`;
@@ -15,16 +15,6 @@ export const Resource = Node.create({
15
15
  // A node just inserted opens its dialog; one read from stored content does not.
16
16
  { _fresh: { default: false } });
17
17
  },
18
- addCommands() {
19
- return {
20
- insertResource: (attributes = {}) => ({ commands }) => {
21
- return commands.insertContent({
22
- type: this.name,
23
- attrs: { _fresh: true, ...attributes }
24
- });
25
- }
26
- };
27
- },
28
18
  parseHTML() {
29
19
  return [{ tag: this.name }];
30
20
  },
@@ -86,12 +86,7 @@
86
86
  <!-- If the first and only field is a rich text field, render it directly -->
87
87
  {#if tab.get.fields.length === 1 && tab.get.fields[0].type === 'richText'}
88
88
  {@const firstField = tab.get.fields[0] as RichTextFieldBuilder}
89
- <RichText
90
- standAlone={true}
91
- path="{prependPath}{tab.name}.{firstField.name}"
92
- config={firstField}
93
- {form}
94
- />
89
+ <RichText path="{prependPath}{tab.name}.{firstField.name}" config={firstField} {form} />
95
90
  {:else}
96
91
  <!-- Otherwise, render the fields -->
97
92
  <RenderFields fields={tab.get.fields} path="{prependPath}{tab.name}" {form} />
@@ -104,9 +99,6 @@
104
99
 
105
100
  <style>
106
101
  .rz-tabs__bar {
107
- position: sticky;
108
- top: var(--rz-tabs-list-top, var(--rz-size-11));
109
- z-index: 40;
110
102
  margin-inline: calc(-1 * var(--rz-fields-padding));
111
103
  padding: var(--rz-size-2) var(--rz-fields-padding);
112
104
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rimecms",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "homepage": "https://github.com/bienbiendev/rime",
5
5
  "packageManager": "bun@1.3.0",
6
6
  "scripts": {