@pure-ds/core 0.6.8 → 0.6.10
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/custom-elements.json +71 -28
- package/dist/types/pds.d.ts +30 -0
- package/dist/types/public/assets/js/pds-manager.d.ts +146 -429
- package/dist/types/public/assets/js/pds-manager.d.ts.map +1 -1
- package/dist/types/public/assets/js/pds.d.ts +3 -4
- package/dist/types/public/assets/js/pds.d.ts.map +1 -1
- package/dist/types/public/assets/pds/components/pds-form.d.ts.map +1 -1
- package/dist/types/public/assets/pds/components/pds-live-edit.d.ts +1 -169
- package/dist/types/public/assets/pds/components/pds-live-edit.d.ts.map +1 -1
- package/dist/types/public/assets/pds/components/pds-omnibox.d.ts +0 -2
- package/dist/types/public/assets/pds/components/pds-omnibox.d.ts.map +1 -1
- package/dist/types/src/js/pds-core/pds-config.d.ts +1306 -13
- package/dist/types/src/js/pds-core/pds-config.d.ts.map +1 -1
- package/dist/types/src/js/pds-core/pds-enhancers-meta.d.ts.map +1 -1
- package/dist/types/src/js/pds-core/pds-enhancers.d.ts.map +1 -1
- package/dist/types/src/js/pds-core/pds-generator.d.ts.map +1 -1
- package/dist/types/src/js/pds-core/pds-live.d.ts.map +1 -1
- package/dist/types/src/js/pds-core/pds-ontology.d.ts.map +1 -1
- package/dist/types/src/js/pds-core/pds-start-helpers.d.ts +1 -4
- package/dist/types/src/js/pds-core/pds-start-helpers.d.ts.map +1 -1
- package/dist/types/src/js/pds-manager.d.ts +1 -0
- package/dist/types/src/js/pds.d.ts.map +1 -1
- package/package.json +2 -2
- package/packages/pds-cli/bin/pds-static.js +16 -1
- package/public/assets/js/app.js +21 -21
- package/public/assets/js/pds-manager.js +291 -161
- package/public/assets/js/pds.js +16 -16
- package/public/assets/pds/components/pds-form.js +124 -27
- package/public/assets/pds/components/pds-live-edit.js +1214 -104
- package/public/assets/pds/components/pds-omnibox.js +10 -18
- package/public/assets/pds/custom-elements.json +71 -28
- package/public/assets/pds/pds-css-complete.json +1 -6
- package/public/assets/pds/pds.css-data.json +5 -35
- package/src/js/pds-core/pds-config.js +822 -31
- package/src/js/pds-core/pds-enhancers-meta.js +11 -0
- package/src/js/pds-core/pds-enhancers.js +113 -5
- package/src/js/pds-core/pds-generator.js +183 -23
- package/src/js/pds-core/pds-live.js +177 -2
- package/src/js/pds-core/pds-ontology.js +6 -0
- package/src/js/pds-core/pds-start-helpers.js +14 -6
- package/src/js/pds.d.ts +30 -0
- package/src/js/pds.js +36 -60
|
@@ -4,7 +4,18 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { Generator } from "./pds-generator.js";
|
|
6
6
|
import { applyStyles, adoptLayers, adoptPrimitives } from "./pds-runtime.js";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
presets,
|
|
9
|
+
defaultLog,
|
|
10
|
+
PDS_CONFIG_RELATIONS,
|
|
11
|
+
PDS_DESIGN_CONFIG_SPEC,
|
|
12
|
+
PDS_DEFAULT_CONFIG_EDITOR_METADATA,
|
|
13
|
+
PDS_DEFAULT_CONFIG_FORM_SCHEMA,
|
|
14
|
+
buildDesignConfigFormSchema,
|
|
15
|
+
getDesignConfigEditorMetadata,
|
|
16
|
+
validateDesignConfig,
|
|
17
|
+
validateInitConfig,
|
|
18
|
+
} from "./pds-config.js";
|
|
8
19
|
import { defaultPDSEnhancers } from "./pds-enhancers.js";
|
|
9
20
|
import { defaultPDSEnhancerMetadata } from "./pds-enhancers-meta.js";
|
|
10
21
|
import { resolvePublicAssetURL } from "./pds-paths.js";
|
|
@@ -21,6 +32,7 @@ import {
|
|
|
21
32
|
} from "./pds-start-helpers.js";
|
|
22
33
|
import {
|
|
23
34
|
isPresetThemeCompatible,
|
|
35
|
+
normalizePresetThemes,
|
|
24
36
|
resolveThemePreference,
|
|
25
37
|
} from "./pds-theme-utils.js";
|
|
26
38
|
|
|
@@ -90,6 +102,142 @@ function applyStoredConfigOverrides(baseConfig) {
|
|
|
90
102
|
return nextConfig;
|
|
91
103
|
}
|
|
92
104
|
|
|
105
|
+
function buildPresetOmniboxSettings(PDS, options = {}) {
|
|
106
|
+
const {
|
|
107
|
+
hideCategory = true,
|
|
108
|
+
itemGrid = "45px 1fr",
|
|
109
|
+
includeIncompatible = true,
|
|
110
|
+
disableIncompatible = true,
|
|
111
|
+
categoryName = "Presets",
|
|
112
|
+
theme,
|
|
113
|
+
onSelect,
|
|
114
|
+
iconHandler,
|
|
115
|
+
} = options || {};
|
|
116
|
+
|
|
117
|
+
const resolvedTheme = resolveThemePreference(theme ?? PDS?.theme);
|
|
118
|
+
|
|
119
|
+
const defaultIconHandler = (item) => {
|
|
120
|
+
const preset = findPresetById(item?.id);
|
|
121
|
+
const colors = preset?.colors || {};
|
|
122
|
+
const primary = colors?.primary;
|
|
123
|
+
const secondary = colors?.secondary;
|
|
124
|
+
const accent = colors?.accent;
|
|
125
|
+
|
|
126
|
+
if (primary && secondary && accent) {
|
|
127
|
+
return `<span style="display:flex;gap:1px;flex-shrink:0;" aria-hidden="true">
|
|
128
|
+
<span style="display:inline-block;width:10px;height:20px;background-color:${primary};"> </span>
|
|
129
|
+
<span style="display:inline-block;width:10px;height:20px;background-color:${secondary};"> </span>
|
|
130
|
+
<span style="display:inline-block;width:10px;height:20px;background-color:${accent};"> </span>
|
|
131
|
+
</span>`;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (item?.icon) {
|
|
135
|
+
return `<pds-icon icon="${item.icon}" size="sm"></pds-icon>`;
|
|
136
|
+
}
|
|
137
|
+
return "";
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const getPresetEntries = () => {
|
|
141
|
+
const source = PDS?.presets || {};
|
|
142
|
+
return Object.values(source || {}).filter((preset) => {
|
|
143
|
+
const presetId = preset?.id || preset?.name;
|
|
144
|
+
return Boolean(presetId);
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const findPresetById = (presetId) => {
|
|
149
|
+
if (!presetId) return null;
|
|
150
|
+
const entries = getPresetEntries();
|
|
151
|
+
return (
|
|
152
|
+
entries.find((preset) => String(preset?.id || preset?.name) === String(presetId)) ||
|
|
153
|
+
null
|
|
154
|
+
);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
hideCategory,
|
|
159
|
+
itemGrid,
|
|
160
|
+
iconHandler:
|
|
161
|
+
typeof iconHandler === "function" ? iconHandler : defaultIconHandler,
|
|
162
|
+
categories: {
|
|
163
|
+
[categoryName]: {
|
|
164
|
+
trigger: () => true,
|
|
165
|
+
getItems: (context = {}) => {
|
|
166
|
+
const query = String(context?.search || "").toLowerCase().trim();
|
|
167
|
+
const entries = getPresetEntries();
|
|
168
|
+
|
|
169
|
+
return entries
|
|
170
|
+
.filter((preset) => {
|
|
171
|
+
const name = String(preset?.name || preset?.id || "").toLowerCase();
|
|
172
|
+
const description = String(preset?.description || "").toLowerCase();
|
|
173
|
+
const tags = Array.isArray(preset?.tags)
|
|
174
|
+
? preset.tags.map((tag) => String(tag).toLowerCase())
|
|
175
|
+
: [];
|
|
176
|
+
|
|
177
|
+
if (query) {
|
|
178
|
+
const matchesQuery =
|
|
179
|
+
name.includes(query) ||
|
|
180
|
+
description.includes(query) ||
|
|
181
|
+
tags.some((tag) => tag.includes(query));
|
|
182
|
+
if (!matchesQuery) return false;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const compatible = isPresetThemeCompatible(preset, resolvedTheme);
|
|
186
|
+
if (!includeIncompatible && !compatible) return false;
|
|
187
|
+
return true;
|
|
188
|
+
})
|
|
189
|
+
.map((preset) => {
|
|
190
|
+
const presetId = preset?.id || preset?.name;
|
|
191
|
+
const compatible = isPresetThemeCompatible(preset, resolvedTheme);
|
|
192
|
+
const supportedThemes = normalizePresetThemes(preset);
|
|
193
|
+
const themeHint =
|
|
194
|
+
supportedThemes.length === 1
|
|
195
|
+
? `${supportedThemes[0]} only`
|
|
196
|
+
: `Not available in ${resolvedTheme} mode`;
|
|
197
|
+
const baseDescription = String(preset?.description || "").trim();
|
|
198
|
+
const description = compatible
|
|
199
|
+
? baseDescription
|
|
200
|
+
: baseDescription
|
|
201
|
+
? `${baseDescription} - ${themeHint}`
|
|
202
|
+
: themeHint;
|
|
203
|
+
|
|
204
|
+
return {
|
|
205
|
+
id: presetId,
|
|
206
|
+
text: preset?.name || String(presetId),
|
|
207
|
+
description,
|
|
208
|
+
icon: "palette",
|
|
209
|
+
class:
|
|
210
|
+
!compatible && disableIncompatible ? "disabled" : "",
|
|
211
|
+
disabled: !compatible && disableIncompatible,
|
|
212
|
+
tooltip: !compatible ? themeHint : "",
|
|
213
|
+
};
|
|
214
|
+
})
|
|
215
|
+
.sort((a, b) =>
|
|
216
|
+
String(a.text || "").localeCompare(String(b.text || ""))
|
|
217
|
+
);
|
|
218
|
+
},
|
|
219
|
+
action: async (selection) => {
|
|
220
|
+
if (!selection?.id) return selection?.id;
|
|
221
|
+
if (selection?.disabled) return selection?.id;
|
|
222
|
+
|
|
223
|
+
const preset = findPresetById(selection.id);
|
|
224
|
+
if (!preset) return selection?.id;
|
|
225
|
+
|
|
226
|
+
if (typeof onSelect === "function") {
|
|
227
|
+
return await onSelect({ preset, selection, resolvedTheme });
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (typeof PDS?.applyLivePreset === "function") {
|
|
231
|
+
await PDS.applyLivePreset(preset.id || selection.id);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return preset.id || selection.id;
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
93
241
|
async function __attachLiveAPIs(PDS, { applyResolvedTheme, setupSystemListenerIfNeeded }) {
|
|
94
242
|
if (__liveApiReady) return;
|
|
95
243
|
|
|
@@ -113,6 +261,11 @@ async function __attachLiveAPIs(PDS, { applyResolvedTheme, setupSystemListenerIf
|
|
|
113
261
|
PDS.common = commonModule || {};
|
|
114
262
|
PDS.presets = presets;
|
|
115
263
|
PDS.configRelations = PDS_CONFIG_RELATIONS;
|
|
264
|
+
PDS.configSpec = PDS_DESIGN_CONFIG_SPEC;
|
|
265
|
+
PDS.configEditorMetadata = PDS_DEFAULT_CONFIG_EDITOR_METADATA;
|
|
266
|
+
PDS.configFormSchema = PDS_DEFAULT_CONFIG_FORM_SCHEMA;
|
|
267
|
+
PDS.buildConfigFormSchema = buildDesignConfigFormSchema;
|
|
268
|
+
PDS.getConfigEditorMetadata = getDesignConfigEditorMetadata;
|
|
116
269
|
PDS.enhancerMetadata = defaultPDSEnhancerMetadata;
|
|
117
270
|
PDS.applyStyles = function(generator) {
|
|
118
271
|
return applyStyles(generator || Generator.instance);
|
|
@@ -140,6 +293,9 @@ async function __attachLiveAPIs(PDS, { applyResolvedTheme, setupSystemListenerIf
|
|
|
140
293
|
const queryEngine = new __queryClass(PDS);
|
|
141
294
|
return await queryEngine.search(question);
|
|
142
295
|
};
|
|
296
|
+
PDS.buildPresetOmniboxSettings = function(options = {}) {
|
|
297
|
+
return buildPresetOmniboxSettings(PDS, options);
|
|
298
|
+
};
|
|
143
299
|
|
|
144
300
|
PDS.applyLivePreset = async function(presetId, options = {}) {
|
|
145
301
|
if (!presetId) return false;
|
|
@@ -158,6 +314,8 @@ async function __attachLiveAPIs(PDS, { applyResolvedTheme, setupSystemListenerIf
|
|
|
158
314
|
const normalized = normalizeInitConfig(inputConfig, {}, {
|
|
159
315
|
presets,
|
|
160
316
|
defaultLog,
|
|
317
|
+
validateDesignConfig,
|
|
318
|
+
validateInitConfig,
|
|
161
319
|
});
|
|
162
320
|
|
|
163
321
|
const resolvedTheme = resolveThemePreference(PDS.theme);
|
|
@@ -199,6 +357,12 @@ async function __attachLiveAPIs(PDS, { applyResolvedTheme, setupSystemListenerIf
|
|
|
199
357
|
design: structuredClone(normalized.generatorConfig.design),
|
|
200
358
|
theme: normalized.generatorConfig.theme || baseConfig.theme,
|
|
201
359
|
});
|
|
360
|
+
PDS.configEditorMetadata = getDesignConfigEditorMetadata(
|
|
361
|
+
normalized.generatorConfig.design
|
|
362
|
+
);
|
|
363
|
+
PDS.configFormSchema = buildDesignConfigFormSchema(
|
|
364
|
+
normalized.generatorConfig.design
|
|
365
|
+
);
|
|
202
366
|
|
|
203
367
|
const persist = options?.persist !== false;
|
|
204
368
|
if (persist && typeof window !== "undefined") {
|
|
@@ -351,7 +515,12 @@ export async function startLive(PDS, config, { emitReady, applyResolvedTheme, se
|
|
|
351
515
|
});
|
|
352
516
|
|
|
353
517
|
// 2) Normalize first-arg API: support { preset, design, enhancers }
|
|
354
|
-
const normalized = normalizeInitConfig(config, {}, {
|
|
518
|
+
const normalized = normalizeInitConfig(config, {}, {
|
|
519
|
+
presets,
|
|
520
|
+
defaultLog,
|
|
521
|
+
validateDesignConfig,
|
|
522
|
+
validateInitConfig,
|
|
523
|
+
});
|
|
355
524
|
if (manageTheme && !isPresetThemeCompatible(normalized.generatorConfig.design, resolvedTheme)) {
|
|
356
525
|
const presetName =
|
|
357
526
|
normalized.presetInfo?.name ||
|
|
@@ -509,6 +678,12 @@ export async function startLive(PDS, config, { emitReady, applyResolvedTheme, se
|
|
|
509
678
|
theme: resolvedTheme,
|
|
510
679
|
enhancers: mergedEnhancers,
|
|
511
680
|
});
|
|
681
|
+
PDS.configEditorMetadata = getDesignConfigEditorMetadata(
|
|
682
|
+
normalized.generatorConfig.design
|
|
683
|
+
);
|
|
684
|
+
PDS.configFormSchema = buildDesignConfigFormSchema(
|
|
685
|
+
normalized.generatorConfig.design
|
|
686
|
+
);
|
|
512
687
|
|
|
513
688
|
|
|
514
689
|
if (config?.liveEdit && typeof document !== "undefined") {
|
|
@@ -461,6 +461,12 @@ export const ontology = {
|
|
|
461
461
|
description: "Toggle switch from checkbox",
|
|
462
462
|
tags: ["switch", "boolean", "form"]
|
|
463
463
|
},
|
|
464
|
+
{
|
|
465
|
+
id: "color-input",
|
|
466
|
+
selector: "label[data-color]",
|
|
467
|
+
description: "Enhanced color input with swatch shell and hex output",
|
|
468
|
+
tags: ["color", "input", "form"]
|
|
469
|
+
},
|
|
464
470
|
{
|
|
465
471
|
id: "range",
|
|
466
472
|
selector: 'input[type="range"]',
|
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
* Kept separate to avoid pulling live-only logic into the base runtime bundle.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { validateDesignConfig, validateInitConfig } from "./pds-config.js";
|
|
7
|
-
|
|
8
6
|
const __ABSOLUTE_URL_PATTERN__ = /^[a-z][a-z0-9+\-.]*:\/\//i;
|
|
9
7
|
const __MODULE_URL__ = (() => {
|
|
10
8
|
try {
|
|
@@ -131,7 +129,11 @@ export function stripFunctions(obj) {
|
|
|
131
129
|
}
|
|
132
130
|
|
|
133
131
|
// Internal: normalize first-arg config to a full generator config and extract enhancers if provided inline
|
|
134
|
-
export function normalizeInitConfig(
|
|
132
|
+
export function normalizeInitConfig(
|
|
133
|
+
inputConfig = {},
|
|
134
|
+
options = {},
|
|
135
|
+
{ presets, defaultLog, validateDesignConfig, validateInitConfig } = {}
|
|
136
|
+
) {
|
|
135
137
|
const logFn =
|
|
136
138
|
inputConfig && typeof inputConfig.log === "function"
|
|
137
139
|
? inputConfig.log
|
|
@@ -174,7 +176,7 @@ export function normalizeInitConfig(inputConfig = {}, options = {}, { presets, d
|
|
|
174
176
|
"design" in (inputConfig || {}) ||
|
|
175
177
|
"enhancers" in (inputConfig || {});
|
|
176
178
|
|
|
177
|
-
if (inputConfig && typeof inputConfig === "object") {
|
|
179
|
+
if (inputConfig && typeof inputConfig === "object" && typeof validateInitConfig === "function") {
|
|
178
180
|
validateInitConfig(inputConfig, { log: logFn, context: "PDS.start" });
|
|
179
181
|
}
|
|
180
182
|
|
|
@@ -182,7 +184,11 @@ export function normalizeInitConfig(inputConfig = {}, options = {}, { presets, d
|
|
|
182
184
|
let presetInfo = null;
|
|
183
185
|
|
|
184
186
|
if (hasNewShape) {
|
|
185
|
-
if (
|
|
187
|
+
if (
|
|
188
|
+
designOverrides &&
|
|
189
|
+
typeof designOverrides === "object" &&
|
|
190
|
+
typeof validateDesignConfig === "function"
|
|
191
|
+
) {
|
|
186
192
|
validateDesignConfig(designOverrides, { log: logFn, context: "PDS.start" });
|
|
187
193
|
}
|
|
188
194
|
// Always resolve a preset; default if none provided
|
|
@@ -242,7 +248,9 @@ export function normalizeInitConfig(inputConfig = {}, options = {}, { presets, d
|
|
|
242
248
|
log: userLog || defaultLog,
|
|
243
249
|
};
|
|
244
250
|
} else if (hasDesignKeys) {
|
|
245
|
-
|
|
251
|
+
if (typeof validateDesignConfig === "function") {
|
|
252
|
+
validateDesignConfig(inputConfig, { log: logFn, context: "PDS.start" });
|
|
253
|
+
}
|
|
246
254
|
// Back-compat: treat the provided object as the full design, wrap it
|
|
247
255
|
const { log: userLog, ...designConfig } = inputConfig;
|
|
248
256
|
generatorConfig = {
|
package/src/js/pds.d.ts
CHANGED
|
@@ -174,6 +174,35 @@ export class PDS extends EventTarget {
|
|
|
174
174
|
static isLiveMode: () => boolean;
|
|
175
175
|
static findComponentForElement?: (el: Element) => ComponentDef | null;
|
|
176
176
|
static presets?: Record<string, any>;
|
|
177
|
+
static configRelations?: Record<string, any>;
|
|
178
|
+
static configSpec?: Record<string, any> | null;
|
|
179
|
+
static configEditorMetadata?: Record<string, any>;
|
|
180
|
+
static configFormSchema?: {
|
|
181
|
+
schema: Record<string, any>;
|
|
182
|
+
uiSchema: Record<string, any>;
|
|
183
|
+
values: Record<string, any>;
|
|
184
|
+
metadata: Record<string, any>;
|
|
185
|
+
} | null;
|
|
186
|
+
static buildConfigFormSchema?: (designConfig?: Record<string, any>) => {
|
|
187
|
+
schema: Record<string, any>;
|
|
188
|
+
uiSchema: Record<string, any>;
|
|
189
|
+
values: Record<string, any>;
|
|
190
|
+
metadata: Record<string, any>;
|
|
191
|
+
};
|
|
192
|
+
static buildPresetOmniboxSettings?: (options?: {
|
|
193
|
+
hideCategory?: boolean;
|
|
194
|
+
includeIncompatible?: boolean;
|
|
195
|
+
disableIncompatible?: boolean;
|
|
196
|
+
categoryName?: string;
|
|
197
|
+
theme?: string | null;
|
|
198
|
+
onSelect?: (context: {
|
|
199
|
+
preset: Record<string, any>;
|
|
200
|
+
selection: Record<string, any>;
|
|
201
|
+
resolvedTheme: string;
|
|
202
|
+
}) => Promise<any> | any;
|
|
203
|
+
iconHandler?: (item: Record<string, any>) => string;
|
|
204
|
+
}) => Record<string, any>;
|
|
205
|
+
static getConfigEditorMetadata?: (designConfig?: Record<string, any>) => Record<string, any>;
|
|
177
206
|
static enhancerMetadata?: Array<{ selector: string; description?: string; demoHtml?: string }>;
|
|
178
207
|
static defaultEnhancers?: Array<any>;
|
|
179
208
|
static ontology?: any;
|
|
@@ -328,6 +357,7 @@ export interface JsonFormOptions {
|
|
|
328
357
|
icons?: boolean;
|
|
329
358
|
datalists?: boolean;
|
|
330
359
|
rangeOutput?: boolean;
|
|
360
|
+
colorInput?: boolean;
|
|
331
361
|
};
|
|
332
362
|
validation?: {
|
|
333
363
|
showErrors?: boolean;
|
package/src/js/pds.js
CHANGED
|
@@ -62,24 +62,15 @@ import {
|
|
|
62
62
|
ensureAbsoluteAssetURL,
|
|
63
63
|
ensureTrailingSlash,
|
|
64
64
|
attachFoucListener,
|
|
65
|
-
normalizeInitConfig,
|
|
66
65
|
resolveRuntimeAssetRoot,
|
|
67
66
|
resolveThemeAndApply,
|
|
68
67
|
setupAutoDefinerAndEnhancers,
|
|
69
|
-
stripFunctions,
|
|
70
68
|
} from "./pds-core/pds-start-helpers.js";
|
|
71
69
|
import {
|
|
72
70
|
isPresetThemeCompatible,
|
|
73
71
|
resolveThemePreference,
|
|
74
72
|
} from "./pds-core/pds-theme-utils.js";
|
|
75
73
|
|
|
76
|
-
const __slugifyPreset = (str = "") =>
|
|
77
|
-
String(str)
|
|
78
|
-
.toLowerCase()
|
|
79
|
-
.replace(/&/g, " and ")
|
|
80
|
-
.replace(/[^a-z0-9]+/g, "-")
|
|
81
|
-
.replace(/^-+|-+$/g, "");
|
|
82
|
-
|
|
83
74
|
const __defaultLog = function (level = "log", message, ...data) {
|
|
84
75
|
const isStaticMode = Boolean(PDS.registry && !PDS.registry.isLive);
|
|
85
76
|
const debug =
|
|
@@ -99,6 +90,27 @@ const __defaultLog = function (level = "log", message, ...data) {
|
|
|
99
90
|
}
|
|
100
91
|
};
|
|
101
92
|
|
|
93
|
+
function __stripFunctionsForClone(value) {
|
|
94
|
+
if (value === null || value === undefined) return value;
|
|
95
|
+
if (typeof value === "function") return undefined;
|
|
96
|
+
if (typeof value !== "object") return value;
|
|
97
|
+
|
|
98
|
+
if (Array.isArray(value)) {
|
|
99
|
+
return value
|
|
100
|
+
.map((item) => __stripFunctionsForClone(item))
|
|
101
|
+
.filter((item) => item !== undefined);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const result = {};
|
|
105
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
106
|
+
const stripped = __stripFunctionsForClone(entry);
|
|
107
|
+
if (stripped !== undefined) {
|
|
108
|
+
result[key] = stripped;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
|
|
102
114
|
async function __loadRuntimeConfig(assetRootURL, config = {}) {
|
|
103
115
|
if (config?.runtimeConfig === false) return null;
|
|
104
116
|
if (typeof fetch !== "function") return null;
|
|
@@ -435,57 +447,21 @@ async function staticInit(config) {
|
|
|
435
447
|
setupSystemListenerIfNeeded: __setupSystemListenerIfNeeded,
|
|
436
448
|
});
|
|
437
449
|
|
|
438
|
-
//
|
|
450
|
+
// Load runtime config for static assets; config metadata remains live-mode only
|
|
439
451
|
const runtimeConfig = await __loadRuntimeConfig(assetRootURL, config);
|
|
440
|
-
const
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
const runtimePresets = runtimeDesign
|
|
447
|
-
? {
|
|
448
|
-
[String(runtimePresetId).toLowerCase()]: runtimeDesign,
|
|
449
|
-
...(String(runtimePresetId).toLowerCase() !== "default"
|
|
450
|
-
? { default: runtimeDesign }
|
|
451
|
-
: {}),
|
|
452
|
-
}
|
|
453
|
-
: null;
|
|
454
|
-
|
|
455
|
-
const inlineDesign =
|
|
456
|
-
config?.design && typeof config.design === "object"
|
|
457
|
-
? stripFunctions(config.design)
|
|
458
|
-
: null;
|
|
459
|
-
const inlinePresetId = __slugifyPreset(config?.preset || "default") || "default";
|
|
460
|
-
const inlinePresets = inlineDesign
|
|
461
|
-
? {
|
|
462
|
-
[String(inlinePresetId).toLowerCase()]: inlineDesign,
|
|
463
|
-
...(String(inlinePresetId).toLowerCase() !== "default"
|
|
464
|
-
? { default: inlineDesign }
|
|
465
|
-
: {}),
|
|
466
|
-
}
|
|
467
|
-
: null;
|
|
468
|
-
|
|
469
|
-
const presets = runtimePresets || config?.presets || inlinePresets || {};
|
|
470
|
-
if (!Object.keys(presets || {}).length) {
|
|
471
|
-
throw new Error(
|
|
472
|
-
"PDS static mode requires preset data. Run pds:build or provide config.presets/config.design."
|
|
473
|
-
);
|
|
474
|
-
}
|
|
475
|
-
const normalizedInput = runtimeConfig?.config
|
|
452
|
+
const userEnhancers = Array.isArray(config?.enhancers)
|
|
453
|
+
? config.enhancers
|
|
454
|
+
: config?.enhancers && typeof config.enhancers === "object"
|
|
455
|
+
? Object.values(config.enhancers)
|
|
456
|
+
: [];
|
|
457
|
+
const resolvedConfig = runtimeConfig?.config
|
|
476
458
|
? {
|
|
477
459
|
...runtimeConfig.config,
|
|
478
460
|
...config,
|
|
479
|
-
|
|
480
|
-
|
|
461
|
+
design: config?.design || runtimeConfig.config.design,
|
|
462
|
+
preset: config?.preset || runtimeConfig.config.preset,
|
|
481
463
|
}
|
|
482
|
-
: config;
|
|
483
|
-
|
|
484
|
-
const normalized = normalizeInitConfig(normalizedInput, {}, {
|
|
485
|
-
presets,
|
|
486
|
-
defaultLog: __defaultLog,
|
|
487
|
-
});
|
|
488
|
-
const userEnhancers = normalized.enhancers;
|
|
464
|
+
: { ...config };
|
|
489
465
|
|
|
490
466
|
|
|
491
467
|
// 2) Derive static asset URLs from the normalized public root
|
|
@@ -545,12 +521,12 @@ async function staticInit(config) {
|
|
|
545
521
|
|
|
546
522
|
// Expose current config as frozen read-only on PDS, preserving input shape
|
|
547
523
|
// Strip functions before cloning to avoid DataCloneError
|
|
548
|
-
const cloneableConfig =
|
|
524
|
+
const cloneableConfig = __stripFunctionsForClone(config);
|
|
549
525
|
PDS.currentConfig = Object.freeze({
|
|
550
526
|
mode: "static",
|
|
551
527
|
...structuredClone(cloneableConfig),
|
|
552
|
-
design: structuredClone(
|
|
553
|
-
preset:
|
|
528
|
+
design: structuredClone(resolvedConfig.design || {}),
|
|
529
|
+
preset: resolvedConfig.preset,
|
|
554
530
|
theme: resolvedTheme,
|
|
555
531
|
enhancers: mergedEnhancers,
|
|
556
532
|
});
|
|
@@ -558,12 +534,12 @@ async function staticInit(config) {
|
|
|
558
534
|
// 6) Emit ready event (unified)
|
|
559
535
|
__emitPDSReady({
|
|
560
536
|
mode: "static",
|
|
561
|
-
config:
|
|
537
|
+
config: resolvedConfig,
|
|
562
538
|
theme: resolvedTheme,
|
|
563
539
|
autoDefiner,
|
|
564
540
|
});
|
|
565
541
|
return {
|
|
566
|
-
config:
|
|
542
|
+
config: resolvedConfig,
|
|
567
543
|
theme: resolvedTheme,
|
|
568
544
|
autoDefiner,
|
|
569
545
|
};
|