rimecms 0.31.1 → 0.31.2

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.
@@ -3,7 +3,6 @@
3
3
  import type { GenericDoc } from '../../../core/types/doc.js';
4
4
  import { fieldset } from '../../../panel/components/fields/fieldset.svelte.js';
5
5
  import { Field } from '../../../panel/components/fields/index.js';
6
- import { getCollectionContext } from '../../../panel/context/collection.svelte.js';
7
6
  import { getConfigContext } from '../../../panel/context/config.svelte.js';
8
7
  import { type DocumentFormContext } from '../../../panel/context/documentForm.svelte.js';
9
8
  import type { FormContext } from '../../../panel/context/form.svelte.js';
@@ -33,7 +32,6 @@
33
32
  const field = $derived(form.useField(path, config));
34
33
  // svelte-ignore state_referenced_locally
35
34
  const relationConfig = getCollection(config.get.relationTo);
36
- const relationCollectionCtx = getCollectionContext(relationConfig.slug);
37
35
 
38
36
  let initialized = $state(false);
39
37
  // the fetched items
@@ -205,10 +203,6 @@
205
203
  }
206
204
  // update resssource
207
205
  ressource.data?.docs.push(doc);
208
- // update collection if present
209
- if (relationCollectionCtx) {
210
- relationCollectionCtx.addDoc(doc);
211
- }
212
206
  // Set value if not full
213
207
  if (isFull) return;
214
208
  selectedItems = [...selectedItems, documentToRelationFieldItem(doc)];
@@ -67,8 +67,7 @@ export function buildEditorConfig(args) {
67
67
  const titleContext = getTitleContext();
68
68
  contexts.set(TITLE_CTX, titleContext);
69
69
  contexts.set(CONFIG_CTX, configContext);
70
- contexts.set(CONFIG_CTX, configContext);
71
- contexts.set(API_PROXY.ROOT, apiProxyContext);
70
+ contexts.set(API_PROXY, apiProxyContext);
72
71
  contexts.set(USER_CTX, userContext);
73
72
  contexts.set(LOCALE_CTX, localeContext);
74
73
  feature.extension.config.addOptions = () => {
@@ -7,7 +7,7 @@
7
7
  } from '../../../../context/collection.svelte.js';
8
8
  import { LayoutGrid, List, TextQuote } from '@lucide/svelte';
9
9
 
10
- const collection = getCollectionContext('list');
10
+ const collection = getCollectionContext();
11
11
  const listIconClass = $derived(collection.isList() ? 'rz-header-display-mode__icon--active' : '');
12
12
  const gridIconClass = $derived(collection.isGrid() ? 'rz-header-display-mode__icon--active' : '');
13
13
  const nestedIconClass = $derived(
@@ -4,7 +4,7 @@
4
4
  import SelectUI from './SelectUI.svelte';
5
5
  import Separator from './Separator.svelte';
6
6
 
7
- const collection = getCollectionContext('list');
7
+ const collection = getCollectionContext();
8
8
  const showSelectUI = $derived(!collection.isNested());
9
9
  const showDisplayMode = $derived(collection.isUpload || collection.config.nested);
10
10
  </script>
@@ -4,7 +4,7 @@
4
4
  import { getCollectionContext } from '../../../../context/collection.svelte.js';
5
5
  import { Search } from '@lucide/svelte';
6
6
 
7
- const collection = getCollectionContext('list');
7
+ const collection = getCollectionContext();
8
8
  let searchValue = $state('');
9
9
 
10
10
  $effect(() => {
@@ -4,7 +4,7 @@
4
4
  import { getCollectionContext } from '../../../../context/collection.svelte.js';
5
5
  import { ListChecks, SquareCheck, SquareMinus, Trash } from '@lucide/svelte';
6
6
 
7
- const collection = getCollectionContext('list');
7
+ const collection = getCollectionContext();
8
8
  const selectedCount = $derived(collection.selected.length);
9
9
  const pluralSuffix = $derived(selectedCount > 1 ? 's' : '');
10
10
  const activeListClass = $derived(collection.selectMode ? 'rz-header-select__icon--active' : '');
@@ -6,7 +6,7 @@
6
6
 
7
7
  type TableColumn = Partial<FormField> & { name: string; label?: string };
8
8
 
9
- const collection = getCollectionContext('list');
9
+ const collection = getCollectionContext();
10
10
  let gridTemplateColumn = $state('grid-template-columns: 2fr repeat(1, minmax(0, 1fr));');
11
11
 
12
12
  $effect(() => {
@@ -1,18 +1,16 @@
1
- export declare function setAPIProxyContext(key?: symbol): {
1
+ export declare function setAPIProxyContext(): {
2
2
  getRessource: <T>(url: string, options?: GetResourcesOptions<T>) => Resource<T>;
3
3
  invalidateAll: () => void;
4
4
  invalidate: (pattern: string | RegExp) => void;
5
5
  readonly urls: string[];
6
6
  };
7
- export declare function getAPIProxyContext(key?: symbol): {
7
+ export declare function getAPIProxyContext(): {
8
8
  getRessource: <T>(url: string, options?: GetResourcesOptions<T>) => Resource<T>;
9
9
  invalidateAll: () => void;
10
10
  invalidate: (pattern: string | RegExp) => void;
11
11
  readonly urls: string[];
12
12
  };
13
- export declare const API_PROXY: {
14
- ROOT: symbol;
15
- };
13
+ export declare const API_PROXY: unique symbol;
16
14
  export type Resource<T = any> = {
17
15
  data: T | null;
18
16
  isLoading: boolean;
@@ -79,13 +79,11 @@ function createAPIProxy() {
79
79
  }
80
80
  };
81
81
  }
82
- export function setAPIProxyContext(key = API_PROXY.ROOT) {
82
+ export function setAPIProxyContext() {
83
83
  const apiProxy = createAPIProxy();
84
- return setContext(key, apiProxy);
84
+ return setContext(API_PROXY, apiProxy);
85
85
  }
86
- export function getAPIProxyContext(key = API_PROXY.ROOT) {
87
- return getContext(key);
86
+ export function getAPIProxyContext() {
87
+ return getContext(API_PROXY);
88
88
  }
89
- export const API_PROXY = {
90
- ROOT: Symbol('api-proxy.root')
91
- };
89
+ export const API_PROXY = Symbol('rime.api-proxy');
@@ -9,7 +9,8 @@ export declare const DISPLAY_MODE: {
9
9
  readonly GRID: "display_grid";
10
10
  readonly NESTED: "display_nested";
11
11
  };
12
- export declare function setCollectionContext(key: string, args: Args): {
12
+ export declare const COLLECTION_CTX: unique symbol;
13
+ export declare function setCollectionContext(args: Args): {
13
14
  readonly stamp: number;
14
15
  readonly title: string;
15
16
  readonly hasDraft: boolean | undefined;
@@ -43,9 +44,6 @@ export declare function setCollectionContext(key: string, args: Args): {
43
44
  currentPath: `root${string}`;
44
45
  parentDirectory: Directory | null;
45
46
  };
46
- addDoc: (doc: GenericDoc) => void;
47
- updateDoc: (incomingDoc: GenericDoc) => void;
48
- deleteDoc: (id: string) => Promise<void>;
49
47
  deleteDocs: (ids: string[]) => Promise<void>;
50
48
  docs: GenericDoc[];
51
49
  readonly length: number;
@@ -62,7 +60,7 @@ export declare function setCollectionContext(key: string, args: Args): {
62
60
  };
63
61
  }) => Promise<boolean | undefined>;
64
62
  };
65
- export declare function getCollectionContext(key?: string): {
63
+ export declare function getCollectionContext(): {
66
64
  readonly stamp: number;
67
65
  readonly title: string;
68
66
  readonly hasDraft: boolean | undefined;
@@ -96,9 +94,6 @@ export declare function getCollectionContext(key?: string): {
96
94
  currentPath: `root${string}`;
97
95
  parentDirectory: Directory | null;
98
96
  };
99
- addDoc: (doc: GenericDoc) => void;
100
- updateDoc: (incomingDoc: GenericDoc) => void;
101
- deleteDoc: (id: string) => Promise<void>;
102
97
  deleteDocs: (ids: string[]) => Promise<void>;
103
98
  docs: GenericDoc[];
104
99
  readonly length: number;
@@ -303,32 +303,6 @@ function createCollectionStore(args) {
303
303
  docs = [...initialDocs];
304
304
  }
305
305
  }
306
- async function deleteDoc(id) {
307
- const res = await fetch(`/api/${config.kebab}/${id}`, {
308
- method: 'DELETE',
309
- headers: {
310
- 'content-type': 'application/json'
311
- }
312
- });
313
- if (res.status === 200) {
314
- docs = [...docs].filter((doc) => doc.id !== id);
315
- }
316
- else if (res.status === 404) {
317
- console.error('not found');
318
- }
319
- }
320
- function addDoc(doc) {
321
- docs.push(doc);
322
- sortBy(sortingBy, false);
323
- }
324
- function updateDoc(incomingDoc) {
325
- for (const [index, doc] of docs.entries()) {
326
- if (doc.id === incomingDoc.id) {
327
- docs[index] = incomingDoc;
328
- return;
329
- }
330
- }
331
- }
332
306
  return {
333
307
  get stamp() {
334
308
  return stamp;
@@ -412,9 +386,6 @@ function createCollectionStore(args) {
412
386
  set upload(value) {
413
387
  upload = value;
414
388
  },
415
- addDoc,
416
- updateDoc,
417
- deleteDoc,
418
389
  deleteDocs,
419
390
  get docs() {
420
391
  return docs;
@@ -432,11 +403,11 @@ function createCollectionStore(args) {
432
403
  handleNestedDocumentMove
433
404
  };
434
405
  }
435
- const COLLECTION_KEY = 'rime.collection';
436
- export function setCollectionContext(key, args) {
406
+ export const COLLECTION_CTX = Symbol('rime.collection');
407
+ export function setCollectionContext(args) {
437
408
  const store = createCollectionStore(args);
438
- return setContext(`${COLLECTION_KEY}.${key}`, store);
409
+ return setContext(COLLECTION_CTX, store);
439
410
  }
440
- export function getCollectionContext(key = 'root') {
441
- return getContext(`${COLLECTION_KEY}.${key}`);
411
+ export function getCollectionContext() {
412
+ return getContext(COLLECTION_CTX);
442
413
  }
@@ -17,7 +17,6 @@ import { moveItem } from '../../util/array.js';
17
17
  import { getValueAtPath, setValueAtPath } from '../../util/object.js';
18
18
  import { snapshot } from '../../util/state.js';
19
19
  import { getAPIProxyContext } from './api-proxy.svelte.js';
20
- import { getCollectionContext } from './collection.svelte.js';
21
20
  import { setErrorsContext } from './errors.svelte.js';
22
21
  import { getLocaleContext } from './locale.svelte.js';
23
22
  import { getTitleContext } from './title.js';
@@ -35,7 +34,6 @@ function createDocumentFormState({ initial, config, readOnly, key, onNestedDocum
35
34
  const user = getUserContext();
36
35
  const errors = setErrorsContext(key);
37
36
  const isCollection = documentConfig.type === 'collection';
38
- const collection = isCollection ? getCollectionContext(documentConfig.slug) : null;
39
37
  const hasError = $derived(errors.length);
40
38
  const canSubmit = $derived(!isDisabled && !readOnly && Object.keys(changes).length > 0 && !hasError);
41
39
  const nestedLevel = initLevel();
@@ -103,8 +101,6 @@ function createDocumentFormState({ initial, config, readOnly, key, onNestedDocum
103
101
  };
104
102
  function setValue(path, value) {
105
103
  doc = setValueAtPath(path, doc, value);
106
- if (collection && operation === 'update')
107
- collection.updateDoc(doc);
108
104
  if (onDataChange)
109
105
  onDataChange({ path, value });
110
106
  }
@@ -1,4 +1,5 @@
1
1
  import type { FormErrors } from '../types.js';
2
+ export declare const ERRORS_KEY = "rime.errors";
2
3
  export declare function setErrorsContext(key?: string): {
3
4
  readonly length: number;
4
5
  value: FormErrors;
@@ -39,7 +39,7 @@ function createErrorsStore() {
39
39
  }
40
40
  };
41
41
  }
42
- const ERRORS_KEY = 'rime.errors';
42
+ export const ERRORS_KEY = 'rime.errors';
43
43
  export function setErrorsContext(key = 'root') {
44
44
  const errors = createErrorsStore();
45
45
  return setContext(`${ERRORS_KEY}.${key}`, errors);
@@ -1,5 +1,6 @@
1
1
  import type { GenericDoc } from '../../core/types/doc.js';
2
2
  import type { BeforeNavigate } from '@sveltejs/kit';
3
+ export declare const LIVE_KEY: unique symbol;
3
4
  /**
4
5
  * Creates and sets the live context for the current component
5
6
  */
@@ -5,7 +5,7 @@ import { apiUrl } from '../../util/index.js';
5
5
  import { toKebabCase } from '../../util/string.js';
6
6
  import { getContext, setContext } from 'svelte';
7
7
  import { getValueAtPath, isObjectLiteral, setValueAtPath } from '../../util/object.js';
8
- const LIVE_KEY = Symbol('rime.live');
8
+ export const LIVE_KEY = Symbol('rime.live');
9
9
  function createStore(href) {
10
10
  let enabled = $state(false);
11
11
  let doc = $state();
@@ -19,6 +19,14 @@ import Dashboard from './pages/dashboard/Dashboard.svelte';
19
19
  import Live from './pages/live/Live.svelte';
20
20
  import type { Route } from './types.js';
21
21
  export { Area, AreaVersionsDoc, Button, Collection, CollectionDoc, CollectionDocVersions, Dashboard, Doc, Field, ForgotPassword, Input, Live, Panel, ResetPassword, SignIn, SpinLoader };
22
+ export declare const CONTEXT: {
23
+ COLLECTION: symbol;
24
+ LIVE: symbol;
25
+ API_PROXY: symbol;
26
+ USER: symbol;
27
+ LOCALE: symbol;
28
+ TITLE: string;
29
+ };
22
30
  export type { DocumentFormContext } from './context/documentForm.svelte.js';
23
31
  export type CollectionProps = {
24
32
  data: {
@@ -4,6 +4,12 @@ import Doc from './components/sections/document/Document.svelte';
4
4
  import Button from './components/ui/button/button.svelte';
5
5
  import Input from './components/ui/input/input.svelte';
6
6
  import SpinLoader from './components/ui/spin-loader/SpinLoader.svelte';
7
+ import { API_PROXY } from './context/api-proxy.svelte.js';
8
+ import { COLLECTION_CTX } from './context/collection.svelte.js';
9
+ import { LIVE_KEY } from './context/live.svelte.js';
10
+ import { LOCALE_CTX } from './context/locale.svelte.js';
11
+ import { USER_CTX } from './context/user.svelte.js';
12
+ import { TITLE_CTX } from './context/title.js';
7
13
  import Area from './pages/area/Area.svelte';
8
14
  import AreaVersionsDoc from './pages/area/AreaVersionsDoc.svelte';
9
15
  import ForgotPassword from './pages/auth/forgot-password/ForgotPassword.svelte';
@@ -17,3 +23,12 @@ import Live from './pages/live/Live.svelte';
17
23
  export {
18
24
  // Components
19
25
  Area, AreaVersionsDoc, Button, Collection, CollectionDoc, CollectionDocVersions, Dashboard, Doc, Field, ForgotPassword, Input, Live, Panel, ResetPassword, SignIn, SpinLoader };
26
+ // Context keys, for a plugin/field that needs to read a context rime's own panel sets
27
+ export const CONTEXT = {
28
+ COLLECTION: COLLECTION_CTX,
29
+ LIVE: LIVE_KEY,
30
+ API_PROXY,
31
+ USER: USER_CTX,
32
+ LOCALE: LOCALE_CTX,
33
+ TITLE: TITLE_CTX
34
+ };
@@ -40,7 +40,7 @@
40
40
  let bulkDialogOpen = $state(false);
41
41
 
42
42
  const collection = $derived(
43
- setCollectionContext('list', {
43
+ setCollectionContext({
44
44
  initial: data.docs,
45
45
  config: collectionConfig,
46
46
  canCreate: data.canCreate,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rimecms",
3
- "version": "0.31.1",
3
+ "version": "0.31.2",
4
4
  "homepage": "https://github.com/bienbiendev/rime",
5
5
  "scripts": {
6
6
  "dev": "vite dev",