@gemboss/gem-framework 0.16.1 → 0.18.13
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.
- package/README.md +84 -0
- package/dist/SOURCE.json +3 -3
- package/dist/editions.d.ts +9 -0
- package/dist/editions.js +24 -0
- package/dist/gem-framework.css +45 -8
- package/dist/index.js +289 -41
- package/dist/primitives.css +40 -3
- package/dist/section-gate.js +156 -27
- package/dist/sections.css +5 -5
- package/dist/settings-schema.js +70 -8
- package/package.json +1 -1
package/dist/settings-schema.js
CHANGED
|
@@ -11,12 +11,15 @@ var CONTROL_TYPES = Object.freeze([
|
|
|
11
11
|
"range",
|
|
12
12
|
"color",
|
|
13
13
|
"color_scheme",
|
|
14
|
+
// the dialect's word for a scheme picker; validateColorScheme requires it stored as a select (normalize converts)
|
|
14
15
|
"image_picker",
|
|
15
16
|
"video",
|
|
16
17
|
"url",
|
|
17
18
|
"link_list",
|
|
18
19
|
"collection",
|
|
19
20
|
"product",
|
|
21
|
+
"datetime",
|
|
22
|
+
// a moment with its offset, stored as ISO 8601 (2026-12-31T23:59:00+07:00); the panel draws a date-time picker
|
|
20
23
|
"edges",
|
|
21
24
|
// 4-side spacing box, value = {t,r,b,l}
|
|
22
25
|
"repeater",
|
|
@@ -24,6 +27,28 @@ var CONTROL_TYPES = Object.freeze([
|
|
|
24
27
|
"header"
|
|
25
28
|
// non-input group label
|
|
26
29
|
]);
|
|
30
|
+
var RENDERED_COLOR_SCHEMES = Object.freeze([
|
|
31
|
+
"default",
|
|
32
|
+
"scheme-1",
|
|
33
|
+
"surface",
|
|
34
|
+
"accent",
|
|
35
|
+
"inverse",
|
|
36
|
+
"scheme-2",
|
|
37
|
+
"scheme-3",
|
|
38
|
+
"scheme-4",
|
|
39
|
+
"scheme-5"
|
|
40
|
+
]);
|
|
41
|
+
var RENDERED_COLOR_SCHEME_SET = new Set(RENDERED_COLOR_SCHEMES);
|
|
42
|
+
var COLOR_SCHEME_OPTIONS = Object.freeze([
|
|
43
|
+
{ value: "default", label: "Default" },
|
|
44
|
+
{ value: "surface", label: "Surface" },
|
|
45
|
+
{ value: "accent", label: "Accent" },
|
|
46
|
+
{ value: "inverse", label: "Inverse" },
|
|
47
|
+
{ value: "scheme-2", label: "Scheme 2" },
|
|
48
|
+
{ value: "scheme-3", label: "Scheme 3" },
|
|
49
|
+
{ value: "scheme-4", label: "Scheme 4" },
|
|
50
|
+
{ value: "scheme-5", label: "Scheme 5" }
|
|
51
|
+
].map((o) => Object.freeze(o)));
|
|
27
52
|
var SETTING_GROUPS = Object.freeze(["content", "options", "design", "advanced"]);
|
|
28
53
|
var CONTROL_TYPE_SET = new Set(CONTROL_TYPES);
|
|
29
54
|
var GROUP_SET = new Set(SETTING_GROUPS);
|
|
@@ -32,6 +57,7 @@ var ADVANCED_ID_RE = /(^|_)(visibility|custom_css|custom_html|custom_class|class
|
|
|
32
57
|
var DESIGN_ID_RE = /(^|_)(colou?r|scheme|radius|shadow|border|spacing|padding|margin|weight|font|typography|align|alignment|card|divider|overlay|tone|price)(_|$)/i;
|
|
33
58
|
var CONTENT_TYPES = /* @__PURE__ */ new Set([
|
|
34
59
|
"text",
|
|
60
|
+
"datetime",
|
|
35
61
|
"textarea",
|
|
36
62
|
"richtext",
|
|
37
63
|
"inline_richtext",
|
|
@@ -119,16 +145,20 @@ function normalizeSetting(s = {}) {
|
|
|
119
145
|
const options = Array.isArray(s.options) ? s.options : Array.isArray(s.enum) ? s.enum.map((v) => ({ value: String(v), label: humanizeId(String(v)) || String(v) })) : void 0;
|
|
120
146
|
const min = s.min !== void 0 ? s.min : s.minimum;
|
|
121
147
|
const max = s.max !== void 0 ? s.max : s.maximum;
|
|
122
|
-
|
|
148
|
+
let type = resolveType(s, Boolean(options));
|
|
149
|
+
const schemeChoice = (type === "color_scheme" || id === "color_scheme") && !(options && options.length && options.every((o) => o && RENDERED_COLOR_SCHEME_SET.has(o.value)));
|
|
150
|
+
if (schemeChoice) type = "select";
|
|
123
151
|
const out = {
|
|
124
152
|
id,
|
|
125
153
|
type,
|
|
126
|
-
group: inferGroup({ ...s, type }),
|
|
154
|
+
group: inferGroup({ ...s, type: schemeChoice ? "color_scheme" : type }),
|
|
127
155
|
label: s.label || humanizeId(id)
|
|
128
156
|
};
|
|
129
157
|
if (s.info) out.info = s.info;
|
|
130
|
-
if (
|
|
131
|
-
if (
|
|
158
|
+
if (schemeChoice) out.default = RENDERED_COLOR_SCHEME_SET.has(s.default) && s.default !== "scheme-1" ? s.default : "default";
|
|
159
|
+
else if (s.default !== void 0) out.default = s.default;
|
|
160
|
+
if (schemeChoice) out.options = COLOR_SCHEME_OPTIONS.map((o) => ({ ...o }));
|
|
161
|
+
else if (options) out.options = options;
|
|
132
162
|
if (min !== void 0) out.min = min;
|
|
133
163
|
if (max !== void 0) out.max = max;
|
|
134
164
|
if (s.step !== void 0) out.step = s.step;
|
|
@@ -195,14 +225,30 @@ function validateRow(s, seen, push) {
|
|
|
195
225
|
if (!s.label) push("warn", "missing_label", `Setting "${s.id}" has no \`label\`.`, s.id);
|
|
196
226
|
if (!s.group) push("warn", "missing_group", `Setting "${s.id}" has no \`group\`.`, s.id);
|
|
197
227
|
else if (!GROUP_SET.has(s.group)) push("error", "unknown_group", `Setting "${s.id}" uses unknown group "${s.group}".`, s.id);
|
|
198
|
-
if ((s.type === "select" || s.type === "radio") && !Array.isArray(s.options))
|
|
199
|
-
push("
|
|
228
|
+
if ((s.type === "select" || s.type === "radio") && !(Array.isArray(s.options) && s.options.length))
|
|
229
|
+
push("error", "choice_without_options", `Setting "${s.id}" (${s.type}) has no \`options\`.`, s.id);
|
|
230
|
+
if (s.type === "range" && !(Number.isFinite(s.min) && Number.isFinite(s.max)))
|
|
231
|
+
push("error", "range_without_bounds", `Setting "${s.id}" (range) needs numeric \`min\` and \`max\`.`, s.id);
|
|
232
|
+
if (s.id === "color_scheme" || s.type === "color_scheme") validateColorScheme(s, push);
|
|
200
233
|
if (s.requires !== void 0) {
|
|
201
234
|
const r = s.requires;
|
|
202
|
-
const
|
|
203
|
-
|
|
235
|
+
const scalar = (v) => ["string", "number", "boolean"].includes(typeof v);
|
|
236
|
+
const ok = r && typeof r === "object" && typeof r.key === "string" && r.key && ("equals" in r && scalar(r.equals) || r.set === true || Array.isArray(r.in) && r.in.length > 0 && r.in.every(scalar));
|
|
237
|
+
if (!ok) push("error", "invalid_requires", `Setting "${s.id}" has a malformed \`requires\` (want {key, equals}, {key, in: [...]} or {key, set: true}).`, s.id);
|
|
204
238
|
}
|
|
205
239
|
}
|
|
240
|
+
function validateColorScheme(s, push) {
|
|
241
|
+
const options = Array.isArray(s.options) ? s.options : [];
|
|
242
|
+
if (s.type !== "select" || !options.length) {
|
|
243
|
+
push("error", "color_scheme_not_a_choice", `Setting "${s.id}" must be a select over the rendered schemes (${RENDERED_COLOR_SCHEMES.join(", ")}), not type "${s.type}".`, s.id);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const unknown = options.map((o) => o && o.value).filter((v) => !RENDERED_COLOR_SCHEME_SET.has(v));
|
|
247
|
+
if (unknown.length)
|
|
248
|
+
push("error", "color_scheme_unrendered_option", `Setting "${s.id}" offers ${unknown.map((v) => `"${v}"`).join(", ")}, which no store draws.`, s.id);
|
|
249
|
+
if (s.default !== void 0 && !options.some((o) => o && o.value === s.default))
|
|
250
|
+
push("error", "color_scheme_default_not_offered", `Setting "${s.id}" defaults to "${s.default}", which is not one of its options.`, s.id);
|
|
251
|
+
}
|
|
206
252
|
function validateRequires(rows, push) {
|
|
207
253
|
const byId = new Map(rows.filter((r) => r && r.id).map((r) => [r.id, r]));
|
|
208
254
|
for (const s of rows) {
|
|
@@ -215,6 +261,20 @@ function validateRequires(rows, push) {
|
|
|
215
261
|
}
|
|
216
262
|
if ("equals" in r && Array.isArray(gate.options) && !gate.options.some((o) => o && String(o.value) === String(r.equals)))
|
|
217
263
|
push("error", "requires_unknown_value", `Setting "${s.id}" requires ${r.key} = "${r.equals}", which is not one of its options.`, s.id);
|
|
264
|
+
if (Array.isArray(r.in) && r.in.every((v) => ["string", "number", "boolean"].includes(typeof v)) && Array.isArray(gate.options)) {
|
|
265
|
+
for (const v of r.in) if (!gate.options.some((o) => o && String(o.value) === String(v)))
|
|
266
|
+
push("error", "requires_unknown_value", `Setting "${s.id}" requires ${r.key} in [${r.in.join(", ")}], and "${v}" is not one of its options.`, s.id);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
for (const s of rows) {
|
|
270
|
+
const seenKeys = /* @__PURE__ */ new Set();
|
|
271
|
+
for (let at = s; at && at.requires && typeof at.requires.key === "string"; at = byId.get(at.requires.key)) {
|
|
272
|
+
if (seenKeys.has(at.id)) {
|
|
273
|
+
push("error", "requires_cycle", `Setting "${s.id}" is gated in a cycle (${[...seenKeys].join(" \u2192 ")} \u2192 ${at.id}): no value ever shows it.`, s.id);
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
seenKeys.add(at.id);
|
|
277
|
+
}
|
|
218
278
|
}
|
|
219
279
|
}
|
|
220
280
|
function validateSettingsSchema(raw) {
|
|
@@ -244,7 +304,9 @@ function isCanonical(raw) {
|
|
|
244
304
|
return validateSettingsSchema(raw).issues.every((i) => i.level !== "error");
|
|
245
305
|
}
|
|
246
306
|
export {
|
|
307
|
+
COLOR_SCHEME_OPTIONS,
|
|
247
308
|
CONTROL_TYPES,
|
|
309
|
+
RENDERED_COLOR_SCHEMES,
|
|
248
310
|
SETTING_GROUPS,
|
|
249
311
|
humanizeId,
|
|
250
312
|
inferGroup,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gemboss/gem-framework",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.13",
|
|
4
4
|
"description": "gem-framework của GemTheme (CSS, runtime, token, bộ kiểm) cộng đúng bộ kiểm section gemtheme dùng khi duyệt. Build từ gemtheme, không sửa ở đây.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|