@webmaster-droid/web 0.3.1 → 0.3.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/dist/index.d.ts CHANGED
@@ -23,6 +23,7 @@ type EditableMetaInput = {
23
23
  kind: SelectedElementKind;
24
24
  relatedPaths?: string[];
25
25
  preview?: string;
26
+ componentName?: string;
26
27
  };
27
28
  declare function editableMeta(input: EditableMetaInput): Record<string, string>;
28
29
  declare function parseSelectedEditableFromTarget(target: EventTarget | null, pagePath: string): SelectedElementContext | null;
package/dist/index.js CHANGED
@@ -12,6 +12,7 @@ var EDITABLE_ROOTS = ["pages.", "layout.", "seo.", "themeTokens."];
12
12
  var MAX_PATH_LENGTH = 320;
13
13
  var MAX_LABEL_LENGTH = 120;
14
14
  var MAX_PREVIEW_LENGTH = 140;
15
+ var warnedInvalidPaths = /* @__PURE__ */ new Set();
15
16
  var RICH_TEXT_ALLOWED_TAGS = [
16
17
  "a",
17
18
  "b",
@@ -92,6 +93,26 @@ function normalizeEditablePath(value) {
92
93
  }
93
94
  return trimmed;
94
95
  }
96
+ function warnInvalidEditablePath(componentName, propName, value) {
97
+ if (process.env.NODE_ENV === "production") {
98
+ return;
99
+ }
100
+ const rawValue = typeof value === "string" ? value : (() => {
101
+ try {
102
+ return JSON.stringify(value);
103
+ } catch {
104
+ return String(value);
105
+ }
106
+ })();
107
+ const key = `${componentName}:${propName}:${rawValue}`;
108
+ if (warnedInvalidPaths.has(key)) {
109
+ return;
110
+ }
111
+ warnedInvalidPaths.add(key);
112
+ console.warn(
113
+ `[webmaster-droid] ${componentName} received ${propName}="${rawValue}", but editable paths must start with one of: ${EDITABLE_ROOTS.join(", ")}. This field will stay fallback-only and will be skipped by \`webmaster-droid seed\`.`
114
+ );
115
+ }
95
116
  function normalizeShortText(value, maxLength) {
96
117
  if (typeof value !== "string") {
97
118
  return null;
@@ -111,7 +132,7 @@ function normalizeKind(value) {
111
132
  }
112
133
  return null;
113
134
  }
114
- function normalizeRelatedPaths(value) {
135
+ function normalizeRelatedPaths(value, componentName) {
115
136
  if (!Array.isArray(value)) {
116
137
  return [];
117
138
  }
@@ -120,6 +141,10 @@ function normalizeRelatedPaths(value) {
120
141
  const normalized = normalizeEditablePath(item);
121
142
  if (normalized) {
122
143
  out.add(normalized);
144
+ continue;
145
+ }
146
+ if (componentName) {
147
+ warnInvalidEditablePath(componentName, "relatedPaths", item);
123
148
  }
124
149
  }
125
150
  return Array.from(out);
@@ -139,6 +164,9 @@ function editableMeta(input) {
139
164
  const path = normalizeEditablePath(input.path);
140
165
  const label = normalizeShortText(input.label, MAX_LABEL_LENGTH);
141
166
  const kind = normalizeKind(input.kind);
167
+ if (!path && input.componentName) {
168
+ warnInvalidEditablePath(input.componentName, "path", input.path);
169
+ }
142
170
  if (!path || !label || !kind) {
143
171
  return {};
144
172
  }
@@ -147,7 +175,7 @@ function editableMeta(input) {
147
175
  "data-wmd-label": label,
148
176
  "data-wmd-kind": kind
149
177
  };
150
- const relatedPaths = normalizeRelatedPaths(input.relatedPaths ?? []);
178
+ const relatedPaths = normalizeRelatedPaths(input.relatedPaths ?? [], input.componentName);
151
179
  if (relatedPaths.length > 0) {
152
180
  attrs["data-wmd-related-paths"] = JSON.stringify(relatedPaths);
153
181
  }
@@ -232,8 +260,16 @@ function EditableText({
232
260
  ...rest
233
261
  }) {
234
262
  const { document: document2, enabled } = useEditableDocument();
235
- const value = pickStringValue(document2, path, fallback, "EditableText", "fallback", "empty");
263
+ const value = pickStringValue(
264
+ document2,
265
+ path,
266
+ fallback,
267
+ "EditableText",
268
+ "fallback",
269
+ "empty"
270
+ );
236
271
  const attrs = enabled ? editableMeta({
272
+ componentName: "EditableText",
237
273
  path,
238
274
  label: label ?? path,
239
275
  kind: "text",
@@ -260,6 +296,7 @@ function EditableRichText({
260
296
  );
261
297
  const sanitizedHtml = sanitizeRichTextHtml(value);
262
298
  const attrs = enabled ? editableMeta({
299
+ componentName: "EditableRichText",
263
300
  path,
264
301
  label: label ?? path,
265
302
  kind: "section",
@@ -297,6 +334,7 @@ function EditableImage({
297
334
  "empty"
298
335
  ) : fallbackAlt ?? "";
299
336
  const attrs = enabled ? editableMeta({
337
+ componentName: "EditableImage",
300
338
  path,
301
339
  label: label ?? path,
302
340
  kind: "image",
@@ -331,6 +369,7 @@ function EditableLink({
331
369
  "empty"
332
370
  );
333
371
  const attrs = enabled ? editableMeta({
372
+ componentName: "EditableLink",
334
373
  path: labelPath,
335
374
  label: label ?? labelPath,
336
375
  kind: "link",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webmaster-droid/web",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",