@meta-cms/next
Advanced tools
Comparing version 1.0.60 to 1.0.61
import * as _meta_cms_core from '@meta-cms/core'; | ||
import { Schema, Content, GetContentParams, ItemAttributes, Field, ModelSchema, toList2, ObjectField, GetType2, MetaCMSConfig, MetaCms, IdAccessors, Paths, GetField } from '@meta-cms/core'; | ||
import { Field, TextField, Schema, Content, GetContentParams, ItemAttributes, ModelSchema, toList2, ObjectField, GetType2, MetaCMSConfig, MetaCms, IdAccessors, Paths, GetField } from '@meta-cms/core'; | ||
import * as React$1 from 'react'; | ||
import { SetRequired } from 'type-fest'; | ||
declare type TOptions = { | ||
toString?: boolean; | ||
plural?: boolean; | ||
variables?: Record<string, string>; | ||
}; | ||
declare type TOptions<F extends Field> = F extends TextField ? { | ||
variables?: F extends TextField ? F["templates"] extends undefined ? never : F["templates"] extends Readonly<string[]> ? Record<F["templates"][number], string | number | boolean> : never : never; | ||
} : never; | ||
declare type CMSPayload<S extends Schema> = { | ||
@@ -50,3 +48,3 @@ content: Content<S>; | ||
}>; | ||
useContent: (idAccessors?: IdAccessors) => <P_1 extends Paths<S>, O_1 extends TOptions>(p: P_1, options?: O_1 | undefined) => GetNextType<GetField<S, P_1>, GetType2<GetField<S, P_1>>>; | ||
useContent: (idAccessors?: IdAccessors) => <P_1 extends Paths<S>, O_1 extends TOptions<GetField<S, P_1>>>(p: P_1, options?: O_1 | undefined) => GetNextType<GetField<S, P_1>, GetType2<GetField<S, P_1>>>; | ||
ContentProvider: ({ children, content }: { | ||
@@ -53,0 +51,0 @@ content: CMSPayload<S>; |
47
index.js
@@ -1070,2 +1070,43 @@ "use strict"; | ||
// ../core/interpolation.ts | ||
var regexpMustache = /{{([\:\/\-\\\,\.a-zA-Z0-9\s])*}}/g; | ||
var mustaching = (string, variables) => { | ||
if (!variables) | ||
return string.replace(regexpMustache, ""); | ||
Object.keys(variables).forEach((option) => { | ||
string = string.replace(`{{${option}}}`, String(variables[option])); | ||
}); | ||
return string.replace(regexpMustache, ""); | ||
}; | ||
var regexpPlural = /\(\(([\:\/\-\\\,\s\u0030-\u4351\u4e00-\u9fa5])*\)\)/g; | ||
var pluralizing = (string, variables) => { | ||
if (!variables) { | ||
return string; | ||
} | ||
let matches = string.matchAll(regexpPlural); | ||
Array.from(matches).forEach((match) => { | ||
const [value] = match; | ||
let [variable, singularValue, pluralValue] = value.replace("((", "").replace("))", "").split(","); | ||
const isPlural = typeof variables[variable] === "number" ? variables[variable] > 1 : !!variables[variable]; | ||
if (!pluralValue) { | ||
if (isPlural === true) { | ||
pluralValue = singularValue; | ||
string = string.replace(value, pluralValue.trim()); | ||
} else { | ||
string = string.replace(regexpPlural, ""); | ||
} | ||
} else { | ||
if (isPlural === true) { | ||
string = string.replace(value, pluralValue.trim()); | ||
} else { | ||
string = string.replace(value, singularValue.trim()); | ||
} | ||
} | ||
}); | ||
return string; | ||
}; | ||
var templating = (value, variables) => { | ||
return pluralizing(mustaching(value, variables), variables); | ||
}; | ||
// adapter.ts | ||
@@ -1219,3 +1260,2 @@ var transformField = (data, field, isTop = true) => { | ||
if (event.data.action === "set_content") { | ||
console.log("updatedContent", event.data.data, nextJsAdapter(event.data.data, schema)); | ||
return setUpdatedContent(nextJsAdapter(event.data.data, schema)); | ||
@@ -1327,2 +1367,7 @@ } | ||
); | ||
if ((options2 == null ? void 0 : options2.variables) && "dangerouslySetInnerHTML" in value) { | ||
if ("__html" in (value == null ? void 0 : value.dangerouslySetInnerHTML)) { | ||
value.dangerouslySetInnerHTML.__html = templating(value.dangerouslySetInnerHTML.__html, options2.variables); | ||
} | ||
} | ||
return value; | ||
@@ -1329,0 +1374,0 @@ }; |
{ | ||
"name": "@meta-cms/next", | ||
"version": "1.0.60", | ||
"version": "1.0.61", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Possible typosquat attack
Supply chain riskThere is a package with a similar name that is downloaded much more often.
Did you mean |
---|
@payloadcms/next |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42697
1419
1