@wikex/admin-kit 0.2.0 → 0.2.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.
- package/CHANGELOG.md +4 -0
- package/dist/admin/before-login.d.ts +5 -0
- package/dist/admin/before-login.js +27 -0
- package/dist/admin/brand.d.ts +19 -0
- package/dist/admin/brand.js +16 -0
- package/dist/admin/header.d.ts +5 -0
- package/dist/admin/header.js +96 -0
- package/dist/admin/logout-button.d.ts +8 -0
- package/dist/admin/logout-button.js +8 -0
- package/dist/admin/nav-client.d.ts +16 -0
- package/dist/admin/nav-client.js +258 -0
- package/dist/admin/nav.d.ts +16 -0
- package/dist/admin/nav.js +31 -0
- package/dist/admin/theme-toggle.d.ts +5 -0
- package/dist/admin/theme-toggle.js +8 -0
- package/dist/admin/view-site.d.ts +5 -0
- package/dist/admin/view-site.js +11 -0
- package/dist/chunk-7FEACJUN.js +151 -0
- package/dist/chunk-BUD6BMFV.js +117 -0
- package/dist/chunk-GMPR6LHH.js +2063 -0
- package/dist/chunk-GZ2B5BTH.js +39 -0
- package/dist/chunk-JJLHSZ3T.js +40 -0
- package/dist/chunk-LC2CP5SR.js +13 -0
- package/dist/chunk-SAI5SWZA.js +29 -0
- package/dist/chunk-SM6CCKQQ.js +62 -0
- package/dist/chunk-VK4EFLWH.js +119 -0
- package/dist/chunk-X7VETFVD.js +52 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +104 -0
- package/dist/live-preview.d.ts +118 -0
- package/dist/live-preview.js +20 -0
- package/dist/project-ClCmpyeX.d.ts +54 -0
- package/dist/project.d.ts +1 -0
- package/dist/project.js +8 -0
- package/dist/rich-text-client.d.ts +5 -0
- package/dist/rich-text-client.js +166 -0
- package/dist/rich-text.d.ts +5 -0
- package/dist/rich-text.js +6 -0
- package/dist/runtimeConfig-BwjQepcW.d.ts +30 -0
- package/dist/starter-client.d.ts +56 -0
- package/dist/starter-client.js +26 -0
- package/dist/starter.d.ts +39 -0
- package/dist/starter.js +62 -0
- package/dist/text-style-runtime.d.ts +5 -0
- package/dist/text-style-runtime.js +74 -0
- package/dist/text-styles.d.ts +86 -0
- package/dist/text-styles.js +22 -0
- package/package.json +24 -19
- package/src/TextStyleRuntime.tsx +0 -90
- package/src/admin/BeforeLogin.tsx +0 -19
- package/src/admin/Brand.tsx +0 -74
- package/src/admin/Header.tsx +0 -87
- package/src/admin/LogoutButton.tsx +0 -41
- package/src/admin/Nav.tsx +0 -35
- package/src/admin/NavClient.tsx +0 -288
- package/src/admin/ThemeToggle.tsx +0 -31
- package/src/admin/ViewSite.tsx +0 -11
- package/src/admin/useAdminBrand.ts +0 -81
- package/src/adminExperience.ts +0 -117
- package/src/index.ts +0 -11
- package/src/live-preview/GlobalInlineInspector.tsx +0 -334
- package/src/live-preview/LivePreviewEditor.tsx +0 -2088
- package/src/live-preview/TextStyleInspector.tsx +0 -289
- package/src/live-preview/index.ts +0 -23
- package/src/live-preview/runtimeConfig.ts +0 -52
- package/src/plugin.ts +0 -70
- package/src/project.ts +0 -82
- package/src/rich-text/client.tsx +0 -202
- package/src/rich-text/index.ts +0 -10
- package/src/starter/client.tsx +0 -22
- package/src/starter.ts +0 -95
- package/src/textStyles.ts +0 -161
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// src/adminExperience.ts
|
|
2
|
+
var IMAGE_UPLOAD_GUIDANCE = "Y\xEAu c\u1EA7u \u0111\u1EC3 \u1EA3nh hi\u1EC3n th\u1ECB r\xF5: hero/banner n\xEAn t\u1EEB 1920 \xD7 1080 px; \u1EA3nh n\u1ED9i dung n\xEAn r\u1ED9ng t\u1ED1i thi\u1EC3u 1200 px. \u01AFu ti\xEAn WebP ho\u1EB7c JPEG, dung l\u01B0\u1EE3ng d\u01B0\u1EDBi 500 KB.";
|
|
3
|
+
var labelTranslations = {
|
|
4
|
+
"Archive Block": "Kh\u1ED1i l\u01B0u tr\u1EEF",
|
|
5
|
+
Content: "N\u1ED9i dung",
|
|
6
|
+
Description: "M\xF4 t\u1EA3",
|
|
7
|
+
Hero: "M\u1EDF \u0111\u1EA7u",
|
|
8
|
+
"Hero Image": "\u1EA2nh \u0111\u1EA1i di\u1EC7n",
|
|
9
|
+
Image: "H\xECnh \u1EA3nh",
|
|
10
|
+
Layout: "B\u1ED1 c\u1EE5c",
|
|
11
|
+
Link: "Li\xEAn k\u1EBFt",
|
|
12
|
+
Media: "H\xECnh \u1EA3nh",
|
|
13
|
+
Meta: "Th\xF4ng tin b\u1ED5 sung",
|
|
14
|
+
Title: "Ti\xEAu \u0111\u1EC1"
|
|
15
|
+
};
|
|
16
|
+
var fieldNameLabels = {
|
|
17
|
+
alt: "V\u0103n b\u1EA3n thay th\u1EBF",
|
|
18
|
+
authors: "T\xE1c gi\u1EA3",
|
|
19
|
+
caption: "Ch\xFA th\xEDch",
|
|
20
|
+
categories: "Chuy\xEAn m\u1EE5c",
|
|
21
|
+
content: "N\u1ED9i dung",
|
|
22
|
+
coverImage: "\u1EA2nh b\xECa",
|
|
23
|
+
defaultOgImage: "\u1EA2nh chia s\u1EBB m\u1EB7c \u0111\u1ECBnh",
|
|
24
|
+
description: "M\xF4 t\u1EA3",
|
|
25
|
+
excerpt: "T\xF3m t\u1EAFt",
|
|
26
|
+
featuredImage: "\u1EA2nh n\u1ED5i b\u1EADt",
|
|
27
|
+
heroImage: "\u1EA2nh \u0111\u1EA1i di\u1EC7n",
|
|
28
|
+
image: "H\xECnh \u1EA3nh",
|
|
29
|
+
logo: "Logo",
|
|
30
|
+
media: "H\xECnh \u1EA3nh",
|
|
31
|
+
appearance: "Ki\u1EC3u hi\u1EC3n th\u1ECB",
|
|
32
|
+
links: "Li\xEAn k\u1EBFt",
|
|
33
|
+
newTab: "M\u1EDF trong tab m\u1EDBi",
|
|
34
|
+
publishedAt: "Ng\xE0y xu\u1EA5t b\u1EA3n",
|
|
35
|
+
relatedPosts: "B\xE0i vi\u1EBFt li\xEAn quan",
|
|
36
|
+
slug: "\u0110\u01B0\u1EDDng d\u1EABn",
|
|
37
|
+
summary: "M\xF4 t\u1EA3 ng\u1EAFn",
|
|
38
|
+
title: "Ti\xEAu \u0111\u1EC1",
|
|
39
|
+
type: "Lo\u1EA1i"
|
|
40
|
+
};
|
|
41
|
+
var entityLabels = {
|
|
42
|
+
"form-submissions": { plural: "D\u1EEF li\u1EC7u bi\u1EC3u m\u1EABu", singular: "D\u1EEF li\u1EC7u bi\u1EC3u m\u1EABu" },
|
|
43
|
+
forms: { plural: "Bi\u1EC3u m\u1EABu", singular: "Bi\u1EC3u m\u1EABu" },
|
|
44
|
+
redirects: { plural: "Chuy\u1EC3n h\u01B0\u1EDBng", singular: "Chuy\u1EC3n h\u01B0\u1EDBng" },
|
|
45
|
+
search: { plural: "K\u1EBFt qu\u1EA3 t\xECm ki\u1EBFm", singular: "K\u1EBFt qu\u1EA3 t\xECm ki\u1EBFm" }
|
|
46
|
+
};
|
|
47
|
+
var translateLabel = (label) => typeof label === "string" ? labelTranslations[label] || label : label;
|
|
48
|
+
var enhanceFields = (fields) => {
|
|
49
|
+
for (const field of fields) {
|
|
50
|
+
if ("name" in field) {
|
|
51
|
+
field.label = field.label === void 0 ? fieldNameLabels[field.name] : translateLabel(field.label);
|
|
52
|
+
} else if ("label" in field) {
|
|
53
|
+
field.label = translateLabel(field.label);
|
|
54
|
+
}
|
|
55
|
+
if (field.type === "upload" && field.relationTo === "media") {
|
|
56
|
+
const currentDescription = field.admin?.description;
|
|
57
|
+
field.admin = {
|
|
58
|
+
...field.admin,
|
|
59
|
+
description: typeof currentDescription === "string" && !currentDescription.includes(IMAGE_UPLOAD_GUIDANCE) ? `${currentDescription} ${IMAGE_UPLOAD_GUIDANCE}` : IMAGE_UPLOAD_GUIDANCE
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
if (field.type === "tabs") {
|
|
63
|
+
for (const tab of field.tabs) {
|
|
64
|
+
tab.label = translateLabel(tab.label);
|
|
65
|
+
enhanceFields(tab.fields);
|
|
66
|
+
}
|
|
67
|
+
} else if ("fields" in field && Array.isArray(field.fields)) {
|
|
68
|
+
enhanceFields(field.fields);
|
|
69
|
+
}
|
|
70
|
+
if (field.type === "blocks") {
|
|
71
|
+
for (const block of field.blocks ?? []) {
|
|
72
|
+
if (block.labels) {
|
|
73
|
+
block.labels = {
|
|
74
|
+
plural: translateLabel(block.labels.plural),
|
|
75
|
+
singular: translateLabel(block.labels.singular)
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
enhanceFields(block.fields);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
var adminExperiencePlugin = (config) => {
|
|
84
|
+
for (const collection of config.collections ?? []) {
|
|
85
|
+
const translatedLabels = entityLabels[collection.slug];
|
|
86
|
+
if (translatedLabels) collection.labels = translatedLabels;
|
|
87
|
+
enhanceFields(collection.fields);
|
|
88
|
+
if (collection.slug === "media") {
|
|
89
|
+
collection.admin = {
|
|
90
|
+
...collection.admin,
|
|
91
|
+
description: IMAGE_UPLOAD_GUIDANCE
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
for (const global of config.globals ?? []) enhanceFields(global.fields);
|
|
96
|
+
return config;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// src/plugin.ts
|
|
100
|
+
var appendUnique = (current, additions) => [
|
|
101
|
+
.../* @__PURE__ */ new Set([...current ?? [], ...additions])
|
|
102
|
+
];
|
|
103
|
+
var wikexAdminPlugin = (options = {}) => {
|
|
104
|
+
return (config) => {
|
|
105
|
+
if (options.enabled === false) return config;
|
|
106
|
+
const admin = config.admin ?? {};
|
|
107
|
+
const components = admin.components ?? {};
|
|
108
|
+
const beforeDashboard = options.components?.beforeDashboard;
|
|
109
|
+
const provider = options.components?.provider;
|
|
110
|
+
return {
|
|
111
|
+
...config,
|
|
112
|
+
admin: {
|
|
113
|
+
...admin,
|
|
114
|
+
components: {
|
|
115
|
+
...components,
|
|
116
|
+
Nav: components.Nav ?? "@wikex/admin-kit/admin/nav",
|
|
117
|
+
actions: appendUnique(components.actions, [
|
|
118
|
+
"@wikex/admin-kit/admin/theme-toggle",
|
|
119
|
+
"@wikex/admin-kit/admin/view-site"
|
|
120
|
+
]),
|
|
121
|
+
beforeDashboard: typeof beforeDashboard !== "string" ? components.beforeDashboard : appendUnique(components.beforeDashboard, [beforeDashboard]),
|
|
122
|
+
beforeLogin: appendUnique(components.beforeLogin, [
|
|
123
|
+
"@wikex/admin-kit/admin/before-login"
|
|
124
|
+
]),
|
|
125
|
+
graphics: {
|
|
126
|
+
Icon: components.graphics?.Icon ?? "@wikex/admin-kit/admin/brand#AdminIcon",
|
|
127
|
+
Logo: components.graphics?.Logo ?? "@wikex/admin-kit/admin/brand#AdminLogo"
|
|
128
|
+
},
|
|
129
|
+
header: appendUnique(components.header, ["@wikex/admin-kit/admin/header"]),
|
|
130
|
+
logout: {
|
|
131
|
+
Button: components.logout?.Button ?? "@wikex/admin-kit/admin/logout-button"
|
|
132
|
+
},
|
|
133
|
+
providers: typeof provider !== "string" ? components.providers : appendUnique(components.providers, [provider])
|
|
134
|
+
},
|
|
135
|
+
livePreview: admin.livePreview ?? {
|
|
136
|
+
breakpoints: [
|
|
137
|
+
{ height: 667, label: "\u0110i\u1EC7n tho\u1EA1i", name: "mobile", width: 375 },
|
|
138
|
+
{ height: 1024, label: "M\xE1y t\xEDnh b\u1EA3ng", name: "tablet", width: 768 },
|
|
139
|
+
{ height: 900, label: "M\xE1y t\xEDnh", name: "desktop", width: 1440 }
|
|
140
|
+
]
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export {
|
|
148
|
+
IMAGE_UPLOAD_GUIDANCE,
|
|
149
|
+
adminExperiencePlugin,
|
|
150
|
+
wikexAdminPlugin
|
|
151
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// src/textStyles.ts
|
|
2
|
+
var TEXT_FONT_OPTIONS = [
|
|
3
|
+
{ css: "", label: "M\u1EB7c \u0111\u1ECBnh", value: "default" },
|
|
4
|
+
{ css: "var(--font-manrope), sans-serif", label: "Manrope", value: "manrope" },
|
|
5
|
+
{ css: "var(--font-inter), sans-serif", label: "Inter", value: "inter" },
|
|
6
|
+
{ css: "var(--font-roboto), sans-serif", label: "Roboto", value: "roboto" },
|
|
7
|
+
{ css: "var(--font-montserrat), sans-serif", label: "Montserrat", value: "montserrat" },
|
|
8
|
+
{ css: "var(--font-lora), serif", label: "Lora", value: "lora" },
|
|
9
|
+
{
|
|
10
|
+
css: "var(--font-playfair-display), serif",
|
|
11
|
+
label: "Playfair Display",
|
|
12
|
+
value: "playfair-display"
|
|
13
|
+
}
|
|
14
|
+
];
|
|
15
|
+
var TEXT_LINE_HEIGHT_OPTIONS = [
|
|
16
|
+
{ css: "", label: "M\u1EB7c \u0111\u1ECBnh", value: "default" },
|
|
17
|
+
{ css: "0.9", label: "R\u1EA5t ch\u1EB7t \xB7 0.9", value: "0.9" },
|
|
18
|
+
{ css: "1", label: "Ch\u1EB7t \xB7 1.0", value: "1" },
|
|
19
|
+
{ css: "1.15", label: "G\u1ECDn \xB7 1.15", value: "1.15" },
|
|
20
|
+
{ css: "1.35", label: "Ti\xEAu chu\u1EA9n \xB7 1.35", value: "1.35" },
|
|
21
|
+
{ css: "1.5", label: "Tho\xE1ng \xB7 1.5", value: "1.5" },
|
|
22
|
+
{ css: "1.7", label: "R\u1ED9ng \xB7 1.7", value: "1.7" }
|
|
23
|
+
];
|
|
24
|
+
var EDITABLE_INTERACTIVE_SELECTOR = [
|
|
25
|
+
"a",
|
|
26
|
+
"button",
|
|
27
|
+
'input:not([type="hidden"])',
|
|
28
|
+
"select",
|
|
29
|
+
"textarea",
|
|
30
|
+
'[role="button"]',
|
|
31
|
+
'[role="link"]',
|
|
32
|
+
'[tabindex]:not([tabindex="-1"])'
|
|
33
|
+
].join(",");
|
|
34
|
+
var EDITABLE_PREVIEW_SELECTOR = [
|
|
35
|
+
"h1",
|
|
36
|
+
"h2",
|
|
37
|
+
"h3",
|
|
38
|
+
"h4",
|
|
39
|
+
"h5",
|
|
40
|
+
"h6",
|
|
41
|
+
"p",
|
|
42
|
+
"li",
|
|
43
|
+
"span",
|
|
44
|
+
"strong",
|
|
45
|
+
EDITABLE_INTERACTIVE_SELECTOR
|
|
46
|
+
].join(",");
|
|
47
|
+
var isSyntheticElementStyleKey = (value) => value.startsWith("@element:");
|
|
48
|
+
var getEditableElementStyleKey = (element) => {
|
|
49
|
+
const scopedRoot = element.closest("[data-wikex-scope]");
|
|
50
|
+
const root = scopedRoot ?? element.ownerDocument.body;
|
|
51
|
+
const scope = scopedRoot?.dataset.wikexScope || "body";
|
|
52
|
+
const segments = [];
|
|
53
|
+
let current = element;
|
|
54
|
+
while (current && current !== root) {
|
|
55
|
+
const parentElement = current.parentElement;
|
|
56
|
+
if (!parentElement) break;
|
|
57
|
+
const tagName = current.tagName.toLowerCase();
|
|
58
|
+
const sameTagSiblings = Array.from(parentElement.children).filter(
|
|
59
|
+
(sibling) => sibling.tagName === current?.tagName
|
|
60
|
+
);
|
|
61
|
+
const index = sameTagSiblings.indexOf(current) + 1;
|
|
62
|
+
segments.push(`${tagName}:nth-of-type(${Math.max(index, 1)})`);
|
|
63
|
+
current = parentElement;
|
|
64
|
+
}
|
|
65
|
+
return `@element:${scope}:${segments.reverse().join(">")}`;
|
|
66
|
+
};
|
|
67
|
+
var fontValues = new Set(TEXT_FONT_OPTIONS.map((option) => option.value));
|
|
68
|
+
var lineHeightValues = new Set(TEXT_LINE_HEIGHT_OPTIONS.map((option) => option.value));
|
|
69
|
+
var isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
70
|
+
var normalizeTextStyleValue = (value) => {
|
|
71
|
+
if (!isRecord(value)) return {};
|
|
72
|
+
const fontFamily = typeof value.fontFamily === "string" && fontValues.has(value.fontFamily) ? value.fontFamily : void 0;
|
|
73
|
+
const lineHeight = typeof value.lineHeight === "string" && lineHeightValues.has(value.lineHeight) ? value.lineHeight : void 0;
|
|
74
|
+
const legacyWidth = typeof value.width === "string" && /^\d+(?:\.\d+)?%$/.test(value.width) ? Number.parseFloat(value.width) : void 0;
|
|
75
|
+
const widthValue = typeof value.width === "number" ? value.width : legacyWidth;
|
|
76
|
+
const width = typeof widthValue === "number" && Number.isFinite(widthValue) ? Math.min(100, Math.max(5, widthValue)) : void 0;
|
|
77
|
+
const widthOffset = typeof value.widthOffset === "number" && Number.isFinite(value.widthOffset) ? Math.min(width ? 100 - width : 95, Math.max(0, value.widthOffset)) : void 0;
|
|
78
|
+
return { fontFamily, lineHeight, width, widthOffset };
|
|
79
|
+
};
|
|
80
|
+
var normalizeTextStyleMap = (value) => {
|
|
81
|
+
if (!isRecord(value)) return {};
|
|
82
|
+
return Object.fromEntries(
|
|
83
|
+
Object.entries(value).map(([fieldPath, fieldStyle]) => [
|
|
84
|
+
fieldPath,
|
|
85
|
+
normalizeTextStyleValue(fieldStyle)
|
|
86
|
+
])
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
var getTextStyleCSS = (value) => {
|
|
90
|
+
const fontFamily = TEXT_FONT_OPTIONS.find((option) => option.value === value.fontFamily)?.css;
|
|
91
|
+
const lineHeight = TEXT_LINE_HEIGHT_OPTIONS.find(
|
|
92
|
+
(option) => option.value === value.lineHeight
|
|
93
|
+
)?.css;
|
|
94
|
+
const width = typeof value.width === "number" ? `${value.width}%` : void 0;
|
|
95
|
+
const widthOffset = typeof value.widthOffset === "number" ? `${value.widthOffset}%` : void 0;
|
|
96
|
+
return {
|
|
97
|
+
boxSizing: width ? "border-box" : void 0,
|
|
98
|
+
fontFamily: fontFamily || void 0,
|
|
99
|
+
lineHeight: lineHeight || void 0,
|
|
100
|
+
marginLeft: width ? widthOffset || "0%" : void 0,
|
|
101
|
+
marginRight: width ? "auto" : void 0,
|
|
102
|
+
maxWidth: width ? "none" : void 0,
|
|
103
|
+
width
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export {
|
|
108
|
+
TEXT_FONT_OPTIONS,
|
|
109
|
+
TEXT_LINE_HEIGHT_OPTIONS,
|
|
110
|
+
EDITABLE_INTERACTIVE_SELECTOR,
|
|
111
|
+
EDITABLE_PREVIEW_SELECTOR,
|
|
112
|
+
isSyntheticElementStyleKey,
|
|
113
|
+
getEditableElementStyleKey,
|
|
114
|
+
normalizeTextStyleValue,
|
|
115
|
+
normalizeTextStyleMap,
|
|
116
|
+
getTextStyleCSS
|
|
117
|
+
};
|