rimecms 0.27.2 → 0.27.3

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.
@@ -1,6 +1,6 @@
1
1
  import type { BuiltCollection } from '../../config/types.js';
2
2
  import type { RequestEvent } from '@sveltejs/kit';
3
- type DeleteArgs = {
3
+ type DuplicateArgs = {
4
4
  id: string;
5
5
  config: BuiltCollection;
6
6
  event: RequestEvent & {
@@ -8,5 +8,5 @@ type DeleteArgs = {
8
8
  };
9
9
  isSystemOperation?: boolean;
10
10
  };
11
- export declare const duplicate: (args: DeleteArgs) => Promise<string>;
11
+ export declare const duplicate: (args: DuplicateArgs) => Promise<string>;
12
12
  export {};
@@ -1,6 +1,8 @@
1
1
  import { VERSIONS_STATUS } from '../../constant.js';
2
2
  import { buildConfigMap } from '../../operations/configMap/index.js';
3
3
  import { isBlocksFieldRaw } from '../../../fields/blocks/index.js';
4
+ import { isJSONContent } from '../../../fields/rich-text';
5
+ import { richTextJSONToText } from '../../../fields/rich-text/index.js';
4
6
  import { isTreeFieldRaw } from '../../../fields/tree/index.js';
5
7
  import { getValueAtPath, isObjectLiteral, matchStructure, omitId, setValueAtPath } from '../../../util/object.js';
6
8
  // If block is localized should not keep its id so it created a new one
@@ -13,8 +15,13 @@ export const duplicate = async (args) => {
13
15
  * on the given document
14
16
  */
15
17
  function setCopyTitle(doc) {
16
- const title = getValueAtPath(config.asTitle, doc);
17
- const data = setValueAtPath(config.asTitle, doc, title + ' (copy)');
18
+ const getTitle = () => {
19
+ const title = getValueAtPath(config.asTitle, doc);
20
+ return isJSONContent(title)
21
+ ? richTextJSONToText(title) + ' (copy)'
22
+ : title + ' (copy)';
23
+ };
24
+ const data = setValueAtPath(config.asTitle, doc, getTitle());
18
25
  return data;
19
26
  }
20
27
  /**
@@ -1,5 +1,15 @@
1
1
  import type { AreaSlug, CollectionSlug, Config, PrototypeSlug } from '../../types.js';
2
2
  import type { BuildConfig } from './server/build-config.server.js';
3
+ /**
4
+ * Object passed to the locals.rime to access the configuration in the server context
5
+ * it is created once on server start and can be used in any server context (load, actions, hooks, etc) via `event.locals.rime.config`
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * // In +page.server.ts
10
+ * const config = event.locals.rime.config.raw;
11
+ * ```
12
+ */
3
13
  export declare function createConfigContext<const C extends Config>(config: BuildConfig<C>): {
4
14
  /**
5
15
  * Gets raw config object
@@ -1,5 +1,15 @@
1
1
  import { ensureMedias } from '../ensure.server.js';
2
2
  import { RimeError } from '../errors/index.js';
3
+ /**
4
+ * Object passed to the locals.rime to access the configuration in the server context
5
+ * it is created once on server start and can be used in any server context (load, actions, hooks, etc) via `event.locals.rime.config`
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * // In +page.server.ts
10
+ * const config = event.locals.rime.config.raw;
11
+ * ```
12
+ */
3
13
  export function createConfigContext(config) {
4
14
  //
5
15
  ensureMedias(config);
@@ -30,6 +30,14 @@ export declare class RichTextFieldBuilder extends FormFieldBuilder<RichTextField
30
30
  defaultValue(value: RichTextContent | DefaultValueFn<RichTextContent>): this;
31
31
  }
32
32
  export declare const richText: (name: string) => RichTextFieldBuilder;
33
+ /**
34
+ * Type guard to check if a value is a JSONContent object.
35
+ *
36
+ * @example
37
+ * isJSONContent({ type: 'paragraph', content: [] }) // true
38
+ * isJSONContent('Just a string') // false
39
+ */
40
+ export declare const isJSONContent: (value: any) => value is JSONContent;
33
41
  /**
34
42
  * Converts rich text JSON content to plain text.
35
43
  * Extracts text content from a TipTap/ProseMirror JSON structure.
@@ -101,6 +101,16 @@ export class RichTextFieldBuilder extends FormFieldBuilder {
101
101
  }
102
102
  }
103
103
  export const richText = (name) => new RichTextFieldBuilder(name);
104
+ /**
105
+ * Type guard to check if a value is a JSONContent object.
106
+ *
107
+ * @example
108
+ * isJSONContent({ type: 'paragraph', content: [] }) // true
109
+ * isJSONContent('Just a string') // false
110
+ */
111
+ export const isJSONContent = (value) => {
112
+ return typeof value === 'object' && value !== null && 'content' in value;
113
+ };
104
114
  /**
105
115
  * Converts rich text JSON content to plain text.
106
116
  * Extracts text content from a TipTap/ProseMirror JSON structure.
@@ -5,7 +5,7 @@ import { compileDocumentConfig } from '../../core/config/shared/compile.js';
5
5
  import { PARAMS, VERSIONS_STATUS } from '../../core/constant.js';
6
6
  import { getFieldConfigByPath } from '../../core/fields/util.js';
7
7
  import { buildConfigMap } from '../../core/operations/configMap/index.js';
8
- import { richTextJSONToText } from '../../fields/rich-text/index.js';
8
+ import { isJSONContent, richTextJSONToText } from '../../fields/rich-text/index.js';
9
9
  import { normalizeFieldPath } from '../../util/doc.js';
10
10
  import { random } from '../../util/index.js';
11
11
  import { isObjectLiteral, omit } from '../../util/object.js';
@@ -60,7 +60,7 @@ function createDocumentFormState({ initial, config, readOnly, key, onNestedDocum
60
60
  else {
61
61
  function computeTitleFromValue(value) {
62
62
  // Handle rich text value
63
- if (isObjectLiteral(value) && 'content' in value) {
63
+ if (isJSONContent(value)) {
64
64
  return richTextJSONToText(value);
65
65
  }
66
66
  if (typeof value === 'string') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rimecms",
3
- "version": "0.27.2",
3
+ "version": "0.27.3",
4
4
  "homepage": "https://github.com/bienbiendev/rime",
5
5
  "scripts": {
6
6
  "dev": "vite dev",