@blokkli/editor 1.4.0-alpha.0 → 1.4.0-alpha.1
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/module.d.mts +71 -2
- package/dist/module.d.ts +71 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +293 -115
- package/dist/runtime/blokkliPlugins/AddAction/index.vue +1 -1
- package/dist/runtime/blokkliPlugins/DroppableEdit/index.vue +1 -1
- package/dist/runtime/blokkliPlugins/ItemAction/index.vue +1 -1
- package/dist/runtime/blokkliPlugins/MenuButton/index.vue +1 -1
- package/dist/runtime/blokkliPlugins/Sidebar/Detached/index.vue +1 -1
- package/dist/runtime/blokkliPlugins/Sidebar/index.vue +1 -1
- package/dist/runtime/blokkliPlugins/ToolbarButton/index.vue +1 -1
- package/dist/runtime/blokkliPlugins/ViewOption/index.vue +1 -1
- package/dist/runtime/components/Blocks/Fragment/index.vue +7 -4
- package/dist/runtime/components/Blocks/FromLibrary/index.vue +8 -5
- package/dist/runtime/components/BlokkliField.vue +2 -2
- package/dist/runtime/components/BlokkliItem.vue +2 -2
- package/dist/runtime/components/Edit/Actions/index.vue +1 -1
- package/dist/runtime/components/Edit/AddListItem/index.vue +1 -1
- package/dist/runtime/components/Edit/AppMenu/index.vue +1 -1
- package/dist/runtime/components/Edit/BlockProxy/index.vue +3 -5
- package/dist/runtime/components/Edit/Dialog/index.vue +1 -1
- package/dist/runtime/components/Edit/DraggableList.vue +2 -2
- package/dist/runtime/components/Edit/EditIndicator.vue +2 -2
- package/dist/runtime/components/Edit/EditProvider.vue +3 -4
- package/dist/runtime/components/Edit/Features/Artboard/index.vue +9 -8
- package/dist/runtime/components/Edit/Features/BlockAddList/index.vue +1 -1
- package/dist/runtime/components/Edit/Features/Debug/index.vue +2 -2
- package/dist/runtime/components/Edit/Features/Diff/DiffView/index.vue +1 -1
- package/dist/runtime/components/Edit/Features/DraggingOverlay/index.vue +1 -1
- package/dist/runtime/components/Edit/Features/Edit/index.vue +1 -1
- package/dist/runtime/components/Edit/Features/EditForm/index.vue +1 -1
- package/dist/runtime/components/Edit/Features/Fragments/Dialog/Item/index.vue +2 -2
- package/dist/runtime/components/Edit/Features/Fragments/Dialog/index.vue +38 -32
- package/dist/runtime/components/Edit/Features/Library/LibraryDialog/Item/index.vue +13 -6
- package/dist/runtime/components/Edit/Features/Library/LibraryDialog/index.vue +65 -67
- package/dist/runtime/components/Edit/Features/Library/index.vue +1 -1
- package/dist/runtime/components/Edit/Features/MediaLibrary/Library/Item.vue +1 -1
- package/dist/runtime/components/Edit/Features/MediaLibrary/Library/index.vue +3 -11
- package/dist/runtime/components/Edit/Features/MediaLibrary/types.d.ts +1 -1
- package/dist/runtime/components/Edit/Features/Options/Form/index.vue +28 -3
- package/dist/runtime/components/Edit/Features/Options/index.vue +4 -1
- package/dist/runtime/components/Edit/Features/Publish/index.vue +1 -1
- package/dist/runtime/components/Edit/Features/ResponsivePreview/index.vue +1 -1
- package/dist/runtime/components/Edit/Features/Settings/Dialog/FeatureSetting/index.vue +1 -1
- package/dist/runtime/components/Edit/Features/Settings/Dialog/index.vue +3 -3
- package/dist/runtime/components/Edit/Features/Theme/Color/index.vue +1 -1
- package/dist/runtime/components/Edit/Features/Theme/index.vue +1 -1
- package/dist/runtime/components/Edit/Features/Translations/index.vue +1 -1
- package/dist/runtime/components/Edit/Features/index.vue +1 -1
- package/dist/runtime/components/Edit/FormOverlay/Header/index.vue +1 -1
- package/dist/runtime/components/Edit/FormOverlay/index.vue +1 -1
- package/dist/runtime/components/Edit/Icon/index.vue +2 -2
- package/dist/runtime/components/Edit/ItemIcon/index.vue +1 -1
- package/dist/runtime/components/Edit/Pagination/index.vue +21 -0
- package/dist/runtime/components/Edit/PreviewProvider.vue +2 -2
- package/dist/runtime/components/Edit/ScaleToFit/index.vue +37 -6
- package/dist/runtime/components/Edit/index.d.ts +2 -1
- package/dist/runtime/components/Edit/index.js +3 -1
- package/dist/runtime/composables/defineBlokkli.d.ts +2 -2
- package/dist/runtime/composables/defineBlokkli.js +17 -22
- package/dist/runtime/composables/defineBlokkliFeature.d.ts +1 -1
- package/dist/runtime/composables/defineBlokkliFeature.js +1 -1
- package/dist/runtime/composables/defineBlokkliFragment.d.ts +1 -1
- package/dist/runtime/composables/defineBlokkliFragment.js +1 -1
- package/dist/runtime/css/output.css +1 -1
- package/dist/runtime/helpers/domProvider.js +1 -1
- package/dist/runtime/helpers/featuresProvider.d.ts +1 -1
- package/dist/runtime/helpers/featuresProvider.js +1 -1
- package/dist/runtime/helpers/index.d.ts +1 -0
- package/dist/runtime/helpers/index.js +7 -1
- package/dist/runtime/helpers/runtimeHelpers/index.d.ts +23 -2
- package/dist/runtime/helpers/runtimeHelpers/index.js +83 -10
- package/dist/runtime/helpers/storageProvider.js +1 -1
- package/dist/runtime/helpers/textProvider.js +2 -2
- package/dist/runtime/helpers/themeProvider.js +1 -1
- package/dist/runtime/types/index.d.ts +7 -4
- package/package.json +2 -2
- package/dist/runtime/helpers/options.d.ts +0 -2
- package/dist/runtime/helpers/options.js +0 -21
package/dist/module.mjs
CHANGED
|
@@ -2,12 +2,13 @@ import path, { basename, extname } from 'node:path';
|
|
|
2
2
|
import fs, { promises, existsSync } from 'node:fs';
|
|
3
3
|
import { defineNuxtModule, createResolver, resolveFiles, addTemplate, addComponent, addBuildPlugin, addImports, addPlugin, updateTemplates } from '@nuxt/kit';
|
|
4
4
|
import { defu, createDefu } from 'defu';
|
|
5
|
+
import { relative } from 'pathe';
|
|
5
6
|
import { createUnplugin } from 'unplugin';
|
|
6
7
|
import MagicString from 'magic-string';
|
|
7
8
|
import { walk } from 'estree-walker-ts';
|
|
8
9
|
import { BK_VISIBLE_LANGUAGES, BK_HIDDEN_GLOBALLY } from '../dist/runtime/helpers/symbols.js';
|
|
9
10
|
|
|
10
|
-
const version = "1.4.0-alpha.
|
|
11
|
+
const version = "1.4.0-alpha.1";
|
|
11
12
|
|
|
12
13
|
function sortObjectKeys(obj) {
|
|
13
14
|
if (Array.isArray(obj)) {
|
|
@@ -51,24 +52,9 @@ function estreeToObject(expression) {
|
|
|
51
52
|
);
|
|
52
53
|
}
|
|
53
54
|
function buildRuntimeDefinition(definition) {
|
|
54
|
-
|
|
55
|
+
return {
|
|
55
56
|
bundle: definition.bundle
|
|
56
57
|
};
|
|
57
|
-
if (definition.options) {
|
|
58
|
-
runtimeDefinition.options = {};
|
|
59
|
-
Object.entries(definition.options).forEach(
|
|
60
|
-
([optionKey, optionDefinition]) => {
|
|
61
|
-
runtimeDefinition.options[optionKey] = {
|
|
62
|
-
type: optionDefinition.type,
|
|
63
|
-
default: optionDefinition.default
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
if (definition.globalOptions) {
|
|
69
|
-
runtimeDefinition.globalOptions = definition.globalOptions;
|
|
70
|
-
}
|
|
71
|
-
return runtimeDefinition;
|
|
72
58
|
}
|
|
73
59
|
const DefinitionPlugin = (nuxt, composableName = "defineBlokkli") => createUnplugin(() => {
|
|
74
60
|
return {
|
|
@@ -125,8 +111,12 @@ class BlockExtractor {
|
|
|
125
111
|
isBuild = false;
|
|
126
112
|
composableName;
|
|
127
113
|
fragmentComposableName;
|
|
128
|
-
|
|
114
|
+
buildDir;
|
|
115
|
+
imports;
|
|
116
|
+
constructor(isBuild = false, buildDir, imports) {
|
|
129
117
|
this.isBuild = isBuild;
|
|
118
|
+
this.buildDir = buildDir;
|
|
119
|
+
this.imports = imports;
|
|
130
120
|
this.composableName = "defineBlokkli";
|
|
131
121
|
this.fragmentComposableName = "defineBlokkliFragment";
|
|
132
122
|
}
|
|
@@ -279,45 +269,16 @@ class BlockExtractor {
|
|
|
279
269
|
}
|
|
280
270
|
return acc;
|
|
281
271
|
}, {});
|
|
282
|
-
const buildContextComponents = (name) => {
|
|
283
|
-
const proxyComponents = Object.values(this.definitions).reduce((acc, v) => {
|
|
284
|
-
if (v?.[name]) {
|
|
285
|
-
acc[v.definition.bundle] = v[name];
|
|
286
|
-
}
|
|
287
|
-
return acc;
|
|
288
|
-
}, {});
|
|
289
|
-
const imports = Object.entries(proxyComponents).map(([bundle, proxyComponentPath]) => {
|
|
290
|
-
return `import ${name}_${bundle} from '${proxyComponentPath}'`;
|
|
291
|
-
}).join("\n");
|
|
292
|
-
const maps = Object.keys(proxyComponents).map((bundle) => {
|
|
293
|
-
return `'${bundle}': ${name}_${bundle}`;
|
|
294
|
-
}).join(", \n");
|
|
295
|
-
return {
|
|
296
|
-
imports,
|
|
297
|
-
maps
|
|
298
|
-
};
|
|
299
|
-
};
|
|
300
|
-
const proxy = buildContextComponents("proxyComponent");
|
|
301
|
-
const diff = buildContextComponents("diffComponent");
|
|
302
272
|
const allFragmentNames = Object.values(this.fragmentDefinitions).filter(falsy).map((v) => `'${v.definition.name}'`).join(" | ");
|
|
303
|
-
return `
|
|
304
|
-
import type {
|
|
273
|
+
return `
|
|
274
|
+
import type { GlobalOptionsKey, ValidFieldListTypes, BlockBundleWithNested } from './generated-types'
|
|
275
|
+
import type { BlockDefinitionInput, BlockDefinitionOptionsInput, FragmentDefinitionInput } from '${this.imports.TYPES}'
|
|
305
276
|
export const globalOptions = ${JSON.stringify(globalOptions, null, 2)} as const
|
|
306
|
-
${proxy.imports}
|
|
307
|
-
${diff.imports}
|
|
308
277
|
|
|
309
278
|
type DefinitionItem = BlockDefinitionInput<BlockDefinitionOptionsInput, GlobalOptionsKey[]>
|
|
310
279
|
|
|
311
280
|
${definitionDeclarations.join("\n")}
|
|
312
281
|
|
|
313
|
-
const PROXY_COMPONENTS: Record<string, any> = {
|
|
314
|
-
${proxy.maps}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
const DIFF_COMPONENTS: Record<string, any> = {
|
|
318
|
-
${diff.maps}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
282
|
export const icons: Record<string, string> = ${JSON.stringify(icons)}
|
|
322
283
|
|
|
323
284
|
export const definitionsMap: Record<string, DefinitionItem> = {
|
|
@@ -351,14 +312,6 @@ export function getDefinition(bundle: string, fieldListType: ValidFieldListTypes
|
|
|
351
312
|
return definitionsMap[bundle]
|
|
352
313
|
}
|
|
353
314
|
|
|
354
|
-
export function getBlokkliItemProxyComponent(bundle: string): any {
|
|
355
|
-
return PROXY_COMPONENTS[bundle]
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
export function getBlokkliItemDiffComponent(bundle: string): any {
|
|
359
|
-
return DIFF_COMPONENTS[bundle]
|
|
360
|
-
}
|
|
361
|
-
|
|
362
315
|
/**
|
|
363
316
|
* Get the definition of the default block component.
|
|
364
317
|
*/
|
|
@@ -366,6 +319,128 @@ export function getDefaultDefinition(bundle: string): BlockDefinitionInput<Recor
|
|
|
366
319
|
return definitionsMap[bundle]
|
|
367
320
|
}
|
|
368
321
|
export const getFragmentDefinition = (name: string): FragmentDefinitionInput<Record<string, any>, GlobalOptionsKey[]>|undefined => fragmentDefinitionsMap[name]
|
|
322
|
+
`;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Generate the template for the block item options used for runtime (e.g. not during editing).
|
|
326
|
+
*/
|
|
327
|
+
generateRuntimeOptionsTemplate(globalOptions = {}) {
|
|
328
|
+
const bundles = Object.values(this.definitions).filter(falsy).reduce((acc, definition2) => {
|
|
329
|
+
if (definition2.definition.renderFor) {
|
|
330
|
+
return acc;
|
|
331
|
+
}
|
|
332
|
+
const bundle = definition2.definition.bundle;
|
|
333
|
+
const optionDefinitions = Object.entries(
|
|
334
|
+
definition2.definition.options || {}
|
|
335
|
+
);
|
|
336
|
+
const options = {};
|
|
337
|
+
if (definition2.definition.globalOptions) {
|
|
338
|
+
definition2.definition.globalOptions.forEach((name) => {
|
|
339
|
+
const option = globalOptions[name];
|
|
340
|
+
options[name] = [option.type, option.default];
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
optionDefinitions.forEach(([name, option]) => {
|
|
344
|
+
options[name] = [option.type, option.default];
|
|
345
|
+
});
|
|
346
|
+
if (Object.values(options).length) {
|
|
347
|
+
acc[bundle] = options;
|
|
348
|
+
}
|
|
349
|
+
return acc;
|
|
350
|
+
}, {});
|
|
351
|
+
function getOptionTypes(definition2) {
|
|
352
|
+
const definedOptions = definition2.options || {};
|
|
353
|
+
const blockGlobalOptions = definition2.globalOptions || [];
|
|
354
|
+
blockGlobalOptions.forEach((key) => {
|
|
355
|
+
if (globalOptions[key]) {
|
|
356
|
+
definedOptions[key] = globalOptions[key];
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
return Object.entries(definedOptions || {}).map(([key, option]) => {
|
|
360
|
+
if (option.type === "text") {
|
|
361
|
+
return `${key}: string`;
|
|
362
|
+
} else if (option.type === "checkbox") {
|
|
363
|
+
return `${key}: boolean`;
|
|
364
|
+
} else if (option.type === "checkboxes") {
|
|
365
|
+
const possibleValues = Object.keys(option.options).map((v) => `'${v}'`).join(" | ") || "string";
|
|
366
|
+
return `${key}: Array<${possibleValues}>`;
|
|
367
|
+
} else if (option.type === "radios") {
|
|
368
|
+
const possibleValues = Object.keys(option.options).map((v) => `'${v}'`).join(" | ") || "string";
|
|
369
|
+
return `${key}: ${possibleValues}`;
|
|
370
|
+
} else if (option.type === "color") {
|
|
371
|
+
return key + ": `#${string}`";
|
|
372
|
+
} else if (option.type === "range" || option.type === "number") {
|
|
373
|
+
return `${key}: number`;
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
const runtimeMappedOptionTypes = Object.values(this.definitions).filter(falsy).map((definition2) => {
|
|
378
|
+
if (definition2.definition.renderFor) {
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
const bundle = definition2.definition.bundle;
|
|
382
|
+
const options = getOptionTypes(definition2.definition).join("\n ");
|
|
383
|
+
if (!options) {
|
|
384
|
+
return ` ${bundle}: {}`;
|
|
385
|
+
}
|
|
386
|
+
return ` ${bundle}: {
|
|
387
|
+
${options}
|
|
388
|
+
}`;
|
|
389
|
+
}).filter(falsy).join(",\n");
|
|
390
|
+
return `
|
|
391
|
+
import type { BlockOptionDefinition } from '${this.imports.TYPES_BLOKK_OPTIONS}'
|
|
392
|
+
|
|
393
|
+
export type RuntimeBlockOptionArray = {
|
|
394
|
+
[T in BlockOptionDefinition as T['type']]: [T['type'], T['default']]
|
|
395
|
+
}[BlockOptionDefinition['type']]
|
|
396
|
+
|
|
397
|
+
export type RuntimeBlockOptions = {
|
|
398
|
+
${runtimeMappedOptionTypes}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
export const BLOCK_OPTIONS: Record<string, Record<string, RuntimeBlockOptionArray>> = ${JSON.stringify(bundles, null, 2)}
|
|
402
|
+
`;
|
|
403
|
+
}
|
|
404
|
+
generateEditComponents() {
|
|
405
|
+
const buildContextComponents = (name) => {
|
|
406
|
+
const proxyComponents = Object.values(this.definitions).reduce((acc, v) => {
|
|
407
|
+
if (v?.[name]) {
|
|
408
|
+
acc[v.definition.bundle] = v[name];
|
|
409
|
+
}
|
|
410
|
+
return acc;
|
|
411
|
+
}, {});
|
|
412
|
+
const imports = Object.entries(proxyComponents).map(([bundle, proxyComponentPath]) => {
|
|
413
|
+
return `import ${name}_${bundle} from '${this.toBuildRelativePath(proxyComponentPath)}'`;
|
|
414
|
+
}).join("\n");
|
|
415
|
+
const maps = Object.keys(proxyComponents).map((bundle) => {
|
|
416
|
+
return `'${bundle}': ${name}_${bundle}`;
|
|
417
|
+
}).join(", \n");
|
|
418
|
+
return {
|
|
419
|
+
imports,
|
|
420
|
+
maps
|
|
421
|
+
};
|
|
422
|
+
};
|
|
423
|
+
const proxy = buildContextComponents("proxyComponent");
|
|
424
|
+
const diff = buildContextComponents("diffComponent");
|
|
425
|
+
return `
|
|
426
|
+
${proxy.imports}
|
|
427
|
+
${diff.imports}
|
|
428
|
+
|
|
429
|
+
const PROXY_COMPONENTS: Record<string, any> = {
|
|
430
|
+
${proxy.maps}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
const DIFF_COMPONENTS: Record<string, any> = {
|
|
434
|
+
${diff.maps}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
export function getBlokkliItemProxyComponent(bundle: string): any {
|
|
438
|
+
return PROXY_COMPONENTS[bundle]
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
export function getBlokkliItemDiffComponent(bundle: string): any {
|
|
442
|
+
return DIFF_COMPONENTS[bundle]
|
|
443
|
+
}
|
|
369
444
|
`;
|
|
370
445
|
}
|
|
371
446
|
/**
|
|
@@ -388,7 +463,8 @@ export const getFragmentDefinition = (name: string): FragmentDefinitionInput<Rec
|
|
|
388
463
|
}
|
|
389
464
|
getBundlesWithGlobalOptions(key) {
|
|
390
465
|
return Object.values(this.definitions).map((definition2) => {
|
|
391
|
-
|
|
466
|
+
const globalOptions = definition2?.definition.globalOptions;
|
|
467
|
+
if (definition2 && globalOptions && globalOptions.includes(key)) {
|
|
392
468
|
return definition2.definition.bundle;
|
|
393
469
|
}
|
|
394
470
|
}).filter(falsy);
|
|
@@ -409,7 +485,7 @@ export const getFragmentDefinition = (name: string): FragmentDefinitionInput<Rec
|
|
|
409
485
|
},
|
|
410
486
|
{}
|
|
411
487
|
);
|
|
412
|
-
return `import type { BlockOptionDefinition } from '
|
|
488
|
+
return `import type { BlockOptionDefinition } from '${this.imports.TYPES_BLOKK_OPTIONS}'
|
|
413
489
|
|
|
414
490
|
type GlobalOptionsDefaults = {
|
|
415
491
|
type: BlockOptionDefinition['type']
|
|
@@ -425,7 +501,7 @@ export const globalOptionsDefaults: Record<string, GlobalOptionsDefaults> = ${JS
|
|
|
425
501
|
2
|
|
426
502
|
)} as const`;
|
|
427
503
|
}
|
|
428
|
-
generateTypesTemplate(globalOptions, chunkNames, fieldListTypes) {
|
|
504
|
+
generateTypesTemplate(globalOptions, chunkNames, fieldListTypes, getBundlePropsType) {
|
|
429
505
|
const allDefintions = Object.values(
|
|
430
506
|
this.definitions
|
|
431
507
|
).map((v) => v?.definition).filter(falsy);
|
|
@@ -444,12 +520,9 @@ export const globalOptionsDefaults: Record<string, GlobalOptionsDefaults> = ${JS
|
|
|
444
520
|
const validBlockBundles = allDefintions.filter((v) => v.bundle !== "from_library").map((v) => {
|
|
445
521
|
return `'${v.bundle}'`;
|
|
446
522
|
}).join(" | ");
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
}
|
|
451
|
-
const definedOptions = v.definition.options;
|
|
452
|
-
const blockGlobalOptions = v.globalOptions || [];
|
|
523
|
+
function getOptionTypes(definition2) {
|
|
524
|
+
const definedOptions = definition2.options || {};
|
|
525
|
+
const blockGlobalOptions = definition2.globalOptions || [];
|
|
453
526
|
blockGlobalOptions.forEach((key) => {
|
|
454
527
|
if (globalOptions[key]) {
|
|
455
528
|
definedOptions[key] = globalOptions[key];
|
|
@@ -461,33 +534,73 @@ export const globalOptionsDefaults: Record<string, GlobalOptionsDefaults> = ${JS
|
|
|
461
534
|
} else if (option.type === "checkbox") {
|
|
462
535
|
return `${key}: '1' | '0' | undefined`;
|
|
463
536
|
} else if (option.type === "radios" || option.type === "checkboxes") {
|
|
464
|
-
|
|
465
|
-
|
|
537
|
+
return `${key}: string | undefined`;
|
|
538
|
+
} else if (option.type === "color") {
|
|
539
|
+
return `${key}: string | undefined`;
|
|
540
|
+
} else if (option.type === "range" || option.type === "number") {
|
|
541
|
+
return `${key}: number | string | undefined`;
|
|
466
542
|
}
|
|
467
543
|
}).join("\n ");
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
const
|
|
476
|
-
(
|
|
477
|
-
const typeName = `FieldListItem_${bundle}`;
|
|
478
|
-
const typeDefinition = `
|
|
479
|
-
type ${typeName} = {
|
|
480
|
-
bundle: '${bundle}'
|
|
481
|
-
options: ${options.join(" | ")}
|
|
482
|
-
}`;
|
|
544
|
+
return `{
|
|
545
|
+
${options}
|
|
546
|
+
}`;
|
|
547
|
+
}
|
|
548
|
+
const propTypeImports = {};
|
|
549
|
+
const typedFieldListItems = [];
|
|
550
|
+
const definitions = Object.entries(this.definitions);
|
|
551
|
+
const mappedGetBundlePropsType = (bundle, definition2) => {
|
|
552
|
+
if (bundle === "from_library" || bundle === "blokkli_fragment") {
|
|
483
553
|
return {
|
|
484
|
-
typeName,
|
|
485
|
-
|
|
554
|
+
typeName: "Props",
|
|
555
|
+
from: definition2.filePath
|
|
486
556
|
};
|
|
557
|
+
} else if (getBundlePropsType) {
|
|
558
|
+
return getBundlePropsType(bundle, definition2);
|
|
487
559
|
}
|
|
488
|
-
|
|
560
|
+
return null;
|
|
561
|
+
};
|
|
562
|
+
for (let i = 0; i < definitions.length; i++) {
|
|
563
|
+
const [_, definition2] = definitions[i];
|
|
564
|
+
if (!definition2) {
|
|
565
|
+
continue;
|
|
566
|
+
}
|
|
567
|
+
if (definition2.definition.renderFor) {
|
|
568
|
+
continue;
|
|
569
|
+
}
|
|
570
|
+
const bundle = definition2.definition.bundle;
|
|
571
|
+
const options = getOptionTypes(definition2.definition);
|
|
572
|
+
const generatedTypeName = `FieldListItem_${bundle}`;
|
|
573
|
+
const lines = [` bundle: '${bundle}'`, `options: ${options}`];
|
|
574
|
+
const bundlePropsType = mappedGetBundlePropsType(bundle, definition2);
|
|
575
|
+
if (bundlePropsType) {
|
|
576
|
+
const { typeName, from } = bundlePropsType;
|
|
577
|
+
if (!propTypeImports[from]) {
|
|
578
|
+
propTypeImports[from] = [];
|
|
579
|
+
}
|
|
580
|
+
propTypeImports[from].push({ bundle, typeName });
|
|
581
|
+
lines.push(`props: Bundle_${bundle}_Props`);
|
|
582
|
+
}
|
|
583
|
+
const typeDefinition = `
|
|
584
|
+
type ${generatedTypeName} = {
|
|
585
|
+
${lines.join("\n ")}
|
|
586
|
+
}`;
|
|
587
|
+
typedFieldListItems.push({
|
|
588
|
+
typeName: generatedTypeName,
|
|
589
|
+
typeDefinition
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
const propTypeImportStatements = Object.entries(propTypeImports).map(([from, items]) => {
|
|
593
|
+
const imports = items.map((v) => {
|
|
594
|
+
return `${v.typeName} as Bundle_${v.bundle}_Props`;
|
|
595
|
+
}).join(",\n ");
|
|
596
|
+
const importPath = this.toBuildRelativePath(from);
|
|
597
|
+
return `import type {
|
|
598
|
+
${imports}
|
|
599
|
+
} from '${importPath}'`;
|
|
600
|
+
}).join("\n");
|
|
489
601
|
return `
|
|
490
|
-
|
|
602
|
+
${propTypeImportStatements}
|
|
603
|
+
import type { FieldListItem } from "${this.imports.TYPES}"
|
|
491
604
|
|
|
492
605
|
export type ValidFieldListTypes = ${validFieldListTypes}
|
|
493
606
|
|
|
@@ -503,7 +616,7 @@ export type ValidGlobalConfigKeys = Array<GlobalOptionsKey>
|
|
|
503
616
|
|
|
504
617
|
${typedFieldListItems.map((v) => v.typeDefinition).join("\n\n")}
|
|
505
618
|
|
|
506
|
-
export type FieldListItemTyped = FieldListItem & (${typedFieldListItems.map((v) => v.typeName).join(" | ")})
|
|
619
|
+
export type FieldListItemTyped = Omit<FieldListItem, 'props'> & (${typedFieldListItems.map((v) => v.typeName).join(" | ")})
|
|
507
620
|
export type FieldListItemTypedArray = Array<FieldListItemTyped>
|
|
508
621
|
`;
|
|
509
622
|
}
|
|
@@ -520,7 +633,7 @@ export type FieldListItemTypedArray = Array<FieldListItemTyped>
|
|
|
520
633
|
*/
|
|
521
634
|
generateImportsTemplate(chunkNames) {
|
|
522
635
|
const chunkImports = chunkNames.filter((v) => v !== "global").map((chunkName) => {
|
|
523
|
-
return `${chunkName}: () => import('
|
|
636
|
+
return `${chunkName}: () => import('./chunk-${chunkName}')`;
|
|
524
637
|
});
|
|
525
638
|
const nonGlobalChunkMapping = Object.values(this.definitions).reduce((acc, v) => {
|
|
526
639
|
if (v && v.chunkName !== "global") {
|
|
@@ -606,6 +719,12 @@ export function getBlokkliFragmentComponent(name: string): any {
|
|
|
606
719
|
}
|
|
607
720
|
`;
|
|
608
721
|
}
|
|
722
|
+
toBuildRelativePath(path2) {
|
|
723
|
+
if (!path2.startsWith("/")) {
|
|
724
|
+
return path2;
|
|
725
|
+
}
|
|
726
|
+
return relative(this.buildDir, path2);
|
|
727
|
+
}
|
|
609
728
|
/**
|
|
610
729
|
* Generate the template.
|
|
611
730
|
*/
|
|
@@ -615,9 +734,9 @@ export function getBlokkliFragmentComponent(name: string): any {
|
|
|
615
734
|
}).filter(falsy);
|
|
616
735
|
const imports = definitions.map((v) => {
|
|
617
736
|
if (this.isBuild) {
|
|
618
|
-
return `import ${v.componentName} from '${v.filePath}'`;
|
|
737
|
+
return `import ${v.componentName} from '${this.toBuildRelativePath(v.filePath)}'`;
|
|
619
738
|
} else {
|
|
620
|
-
return `const ${v.componentName} = () => import('${v.filePath}')`;
|
|
739
|
+
return `const ${v.componentName} = () => import('${this.toBuildRelativePath(v.filePath)}')`;
|
|
621
740
|
}
|
|
622
741
|
});
|
|
623
742
|
const map = definitions.reduce((acc, v) => {
|
|
@@ -6990,6 +7109,34 @@ const module = defineNuxtModule({
|
|
|
6990
7109
|
const srcResolver = createResolver(srcDir);
|
|
6991
7110
|
const moduleDir = import.meta.url;
|
|
6992
7111
|
const resolver = createResolver(moduleDir);
|
|
7112
|
+
const buildResolver = createResolver(nuxt.options.buildDir);
|
|
7113
|
+
const blokkliBuildDir = buildResolver.resolve("blokkli");
|
|
7114
|
+
const IMPORTS = {
|
|
7115
|
+
TYPES: relative(
|
|
7116
|
+
blokkliBuildDir,
|
|
7117
|
+
resolver.resolve("./runtime/types/index.ts")
|
|
7118
|
+
),
|
|
7119
|
+
CONSTANTS: relative(
|
|
7120
|
+
blokkliBuildDir,
|
|
7121
|
+
resolver.resolve("./runtime/constants/index.ts")
|
|
7122
|
+
),
|
|
7123
|
+
ADAPTER: relative(
|
|
7124
|
+
blokkliBuildDir,
|
|
7125
|
+
resolver.resolve("./runtime/adapter/index.ts")
|
|
7126
|
+
),
|
|
7127
|
+
TYPES_THEME: relative(
|
|
7128
|
+
blokkliBuildDir,
|
|
7129
|
+
resolver.resolve("./runtime/types/theme.ts")
|
|
7130
|
+
),
|
|
7131
|
+
TYPES_GENERATED_MODULE_TYPED: relative(
|
|
7132
|
+
blokkliBuildDir,
|
|
7133
|
+
resolver.resolve("./runtime/types/generatedModuleTypes.ts")
|
|
7134
|
+
),
|
|
7135
|
+
TYPES_BLOKK_OPTIONS: relative(
|
|
7136
|
+
blokkliBuildDir,
|
|
7137
|
+
resolver.resolve("./runtime/types/blokkOptions.ts")
|
|
7138
|
+
)
|
|
7139
|
+
};
|
|
6993
7140
|
const featureFolder = resolver.resolve("./runtime/components/Edit/Features");
|
|
6994
7141
|
const featureExtractor = new Extractor(!nuxt.options.dev);
|
|
6995
7142
|
const builtinFeatures = await resolveFiles(featureFolder, ["*/index.vue"], {
|
|
@@ -7025,7 +7172,7 @@ const module = defineNuxtModule({
|
|
|
7025
7172
|
id: v.id,
|
|
7026
7173
|
componentName: v.componentPath,
|
|
7027
7174
|
importName,
|
|
7028
|
-
importStatement: `import ${importName} from '${v.componentPath}'`,
|
|
7175
|
+
importStatement: `import ${importName} from '${relative(blokkliBuildDir, v.componentPath)}'`,
|
|
7029
7176
|
definition: v.definition
|
|
7030
7177
|
};
|
|
7031
7178
|
});
|
|
@@ -7050,8 +7197,8 @@ const module = defineNuxtModule({
|
|
|
7050
7197
|
}`;
|
|
7051
7198
|
}).join(",\n");
|
|
7052
7199
|
return `${imports}
|
|
7053
|
-
import type { BlokkliAdapter } from '
|
|
7054
|
-
import type { Viewport } from '
|
|
7200
|
+
import type { BlokkliAdapter } from '${IMPORTS.ADAPTER}'
|
|
7201
|
+
import type { Viewport } from '${IMPORTS.CONSTANTS}'
|
|
7055
7202
|
type AdapterMethods = keyof BlokkliAdapter<any>
|
|
7056
7203
|
|
|
7057
7204
|
export const availableFeaturesAtBuild = ${JSON.stringify(
|
|
@@ -7080,7 +7227,7 @@ ${featuresArray}
|
|
|
7080
7227
|
blokkli: true
|
|
7081
7228
|
}
|
|
7082
7229
|
});
|
|
7083
|
-
nuxt.options.alias["#blokkli-
|
|
7230
|
+
nuxt.options.alias["#blokkli-build/features"] = featureComponents.dst;
|
|
7084
7231
|
addTemplate({
|
|
7085
7232
|
write: true,
|
|
7086
7233
|
filename: "blokkli/features.json",
|
|
@@ -7134,7 +7281,11 @@ ${featuresArray}
|
|
|
7134
7281
|
const files = await resolveFiles(srcDir, importPattern, {
|
|
7135
7282
|
followSymbolicLinks: false
|
|
7136
7283
|
});
|
|
7137
|
-
const blockExtractor = new BlockExtractor(
|
|
7284
|
+
const blockExtractor = new BlockExtractor(
|
|
7285
|
+
!nuxt.options.dev,
|
|
7286
|
+
blokkliBuildDir,
|
|
7287
|
+
IMPORTS
|
|
7288
|
+
);
|
|
7138
7289
|
await blockExtractor.addFiles(files);
|
|
7139
7290
|
const templateDefinitions = addTemplate({
|
|
7140
7291
|
write: true,
|
|
@@ -7148,7 +7299,31 @@ ${featuresArray}
|
|
|
7148
7299
|
blokkli: true
|
|
7149
7300
|
}
|
|
7150
7301
|
});
|
|
7151
|
-
nuxt.options.alias["#blokkli/definitions"] = templateDefinitions.dst;
|
|
7302
|
+
nuxt.options.alias["#blokkli-build/definitions"] = templateDefinitions.dst;
|
|
7303
|
+
const templateRuntimeOptions = addTemplate({
|
|
7304
|
+
write: true,
|
|
7305
|
+
filename: "blokkli/runtime-options.ts",
|
|
7306
|
+
getContents: () => {
|
|
7307
|
+
return blockExtractor.generateRuntimeOptionsTemplate(
|
|
7308
|
+
moduleOptions.globalOptions
|
|
7309
|
+
);
|
|
7310
|
+
},
|
|
7311
|
+
options: {
|
|
7312
|
+
blokkli: true
|
|
7313
|
+
}
|
|
7314
|
+
});
|
|
7315
|
+
nuxt.options.alias["#blokkli-build/runtime-options"] = templateRuntimeOptions.dst;
|
|
7316
|
+
const templateEditComponents = addTemplate({
|
|
7317
|
+
write: true,
|
|
7318
|
+
filename: "blokkli/edit-components.ts",
|
|
7319
|
+
getContents: () => {
|
|
7320
|
+
return blockExtractor.generateEditComponents();
|
|
7321
|
+
},
|
|
7322
|
+
options: {
|
|
7323
|
+
blokkli: true
|
|
7324
|
+
}
|
|
7325
|
+
});
|
|
7326
|
+
nuxt.options.alias["#blokkli-build/edit-components"] = templateEditComponents.dst;
|
|
7152
7327
|
const templateTranslations = addTemplate({
|
|
7153
7328
|
write: true,
|
|
7154
7329
|
filename: "blokkli/translations.ts",
|
|
@@ -7167,14 +7342,14 @@ ${featuresArray}
|
|
|
7167
7342
|
blokkli: true
|
|
7168
7343
|
}
|
|
7169
7344
|
});
|
|
7170
|
-
nuxt.options.alias["#blokkli/translations"] = templateTranslations.dst;
|
|
7345
|
+
nuxt.options.alias["#blokkli-build/translations"] = templateTranslations.dst;
|
|
7171
7346
|
nuxt.options.runtimeConfig.public.blokkli = {
|
|
7172
7347
|
itemEntityType: moduleOptions.itemEntityType || "",
|
|
7173
7348
|
defaultLanguage: moduleOptions.defaultLanguage || "en"
|
|
7174
7349
|
};
|
|
7175
7350
|
const resolvedPath = "~/app/blokkli.editAdapter".replace(/^(~~|@@)/, nuxt.options.rootDir).replace(/^(~|@)/, nuxt.options.srcDir);
|
|
7176
7351
|
const adapterTemplate = (() => {
|
|
7177
|
-
const resolvedFilename = `blokkli
|
|
7352
|
+
const resolvedFilename = `blokkli/editAdapter.ts`;
|
|
7178
7353
|
const maybeUserFile = fileExists(resolvedPath, ["ts"]);
|
|
7179
7354
|
if (!maybeUserFile) {
|
|
7180
7355
|
throw new Error(
|
|
@@ -7185,14 +7360,14 @@ ${featuresArray}
|
|
|
7185
7360
|
filename: resolvedFilename,
|
|
7186
7361
|
write: true,
|
|
7187
7362
|
getContents: () => `
|
|
7188
|
-
import type { BlokkliAdapterFactory } from '
|
|
7189
|
-
import adapter from '${resolvedPath}'
|
|
7363
|
+
import type { BlokkliAdapterFactory } from '${IMPORTS.ADAPTER}'
|
|
7364
|
+
import adapter from '${relative(blokkliBuildDir, resolvedPath)}'
|
|
7190
7365
|
|
|
7191
7366
|
export default adapter as BlokkliAdapterFactory<any>
|
|
7192
7367
|
`
|
|
7193
7368
|
});
|
|
7194
7369
|
})();
|
|
7195
|
-
nuxt.options.alias["#blokkli/compiled-edit-adapter"] = adapterTemplate.dst;
|
|
7370
|
+
nuxt.options.alias["#blokkli-build/compiled-edit-adapter"] = adapterTemplate.dst;
|
|
7196
7371
|
nuxt.options.build.transpile.push(resolver.resolve("runtime"));
|
|
7197
7372
|
addComponent({
|
|
7198
7373
|
filePath: resolver.resolve("./runtime/components/BlokkliField"),
|
|
@@ -7235,7 +7410,7 @@ ${featuresArray}
|
|
|
7235
7410
|
from: resolver.resolve("./runtime/composables/useBlokkli"),
|
|
7236
7411
|
as: "useBlokkli"
|
|
7237
7412
|
});
|
|
7238
|
-
nuxt.options.alias["#blokkli/styles"] = resolver.resolve(
|
|
7413
|
+
nuxt.options.alias["#blokkli-build/styles"] = resolver.resolve(
|
|
7239
7414
|
"./runtime/css/output.css"
|
|
7240
7415
|
);
|
|
7241
7416
|
const templateGeneratedTypes = addTemplate({
|
|
@@ -7245,14 +7420,15 @@ ${featuresArray}
|
|
|
7245
7420
|
return blockExtractor.generateTypesTemplate(
|
|
7246
7421
|
moduleOptions.globalOptions || {},
|
|
7247
7422
|
getChunkNames(),
|
|
7248
|
-
getFieldListTypes()
|
|
7423
|
+
getFieldListTypes(),
|
|
7424
|
+
moduleOptions.getBundlePropsType
|
|
7249
7425
|
);
|
|
7250
7426
|
},
|
|
7251
7427
|
options: {
|
|
7252
7428
|
blokkli: true
|
|
7253
7429
|
}
|
|
7254
7430
|
});
|
|
7255
|
-
nuxt.options.alias["#blokkli/generated-types"] = templateGeneratedTypes.dst;
|
|
7431
|
+
nuxt.options.alias["#blokkli-build/generated-types"] = templateGeneratedTypes.dst;
|
|
7256
7432
|
const { themeCss, fullTheme, hasCustomTheme } = buildThemeData(
|
|
7257
7433
|
moduleOptions.theme
|
|
7258
7434
|
);
|
|
@@ -7266,14 +7442,14 @@ ${featuresArray}
|
|
|
7266
7442
|
blokkli: true
|
|
7267
7443
|
}
|
|
7268
7444
|
});
|
|
7269
|
-
nuxt.options.alias["#blokkli/theme"] = templateThemeCss.dst;
|
|
7445
|
+
nuxt.options.alias["#blokkli-build/theme"] = templateThemeCss.dst;
|
|
7270
7446
|
const templateConfig = addTemplate({
|
|
7271
7447
|
write: true,
|
|
7272
7448
|
filename: "blokkli/config.ts",
|
|
7273
7449
|
getContents: () => {
|
|
7274
7450
|
const settingsOverride = moduleOptions.settingsOverride || {};
|
|
7275
|
-
return `import type { Theme } from '
|
|
7276
|
-
import type { ModuleOptionsSettings } from '
|
|
7451
|
+
return `import type { Theme } from '${IMPORTS.TYPES_THEME}'
|
|
7452
|
+
import type { ModuleOptionsSettings } from '${IMPORTS.TYPES_GENERATED_MODULE_TYPED}'
|
|
7277
7453
|
|
|
7278
7454
|
export const hasCustomTheme = ${JSON.stringify(hasCustomTheme)}
|
|
7279
7455
|
export const themes: Record<string, Theme> = ${JSON.stringify(themes, null, 2)}
|
|
@@ -7300,7 +7476,7 @@ export const forceDefaultLanguage: boolean = ${JSON.stringify(
|
|
|
7300
7476
|
blokkli: true
|
|
7301
7477
|
}
|
|
7302
7478
|
});
|
|
7303
|
-
nuxt.options.alias["#blokkli/config"] = templateConfig.dst;
|
|
7479
|
+
nuxt.options.alias["#blokkli-build/config"] = templateConfig.dst;
|
|
7304
7480
|
const templateDefaultGlobalOptions = addTemplate({
|
|
7305
7481
|
write: true,
|
|
7306
7482
|
filename: "blokkli/default-global-options.ts",
|
|
@@ -7313,7 +7489,7 @@ export const forceDefaultLanguage: boolean = ${JSON.stringify(
|
|
|
7313
7489
|
blokkli: true
|
|
7314
7490
|
}
|
|
7315
7491
|
});
|
|
7316
|
-
nuxt.options.alias["#blokkli/default-global-options"] = templateDefaultGlobalOptions.dst;
|
|
7492
|
+
nuxt.options.alias["#blokkli-build/default-global-options"] = templateDefaultGlobalOptions.dst;
|
|
7317
7493
|
let optionsSchemaTemplate = null;
|
|
7318
7494
|
const generateOptionsSchema = async () => {
|
|
7319
7495
|
const outputPath = moduleOptions.schemaOptionsPath;
|
|
@@ -7343,7 +7519,7 @@ export const forceDefaultLanguage: boolean = ${JSON.stringify(
|
|
|
7343
7519
|
await generateOptionsSchema();
|
|
7344
7520
|
getChunkNames().forEach((chunkName) => {
|
|
7345
7521
|
if (chunkName !== "global" && !nuxt.options.dev) {
|
|
7346
|
-
|
|
7522
|
+
addTemplate({
|
|
7347
7523
|
write: true,
|
|
7348
7524
|
filename: `blokkli/chunk-${chunkName}.ts`,
|
|
7349
7525
|
getContents: () => {
|
|
@@ -7353,7 +7529,6 @@ export const forceDefaultLanguage: boolean = ${JSON.stringify(
|
|
|
7353
7529
|
blokkli: true
|
|
7354
7530
|
}
|
|
7355
7531
|
});
|
|
7356
|
-
nuxt.options.alias["#blokkli/chunk-" + chunkName] = template.dst;
|
|
7357
7532
|
}
|
|
7358
7533
|
});
|
|
7359
7534
|
const templateImports = addTemplate({
|
|
@@ -7400,8 +7575,8 @@ export type BlokkliIcon = keyof typeof icons`;
|
|
|
7400
7575
|
blokkli: true
|
|
7401
7576
|
}
|
|
7402
7577
|
});
|
|
7403
|
-
nuxt.options.alias["#blokkli/icons"] = templateIcons.dst;
|
|
7404
|
-
nuxt.options.alias["#blokkli/imports"] = templateImports.dst;
|
|
7578
|
+
nuxt.options.alias["#blokkli-build/icons"] = templateIcons.dst;
|
|
7579
|
+
nuxt.options.alias["#blokkli-build/imports"] = templateImports.dst;
|
|
7405
7580
|
nuxt.options.alias["#blokkli/types"] = resolver.resolve("runtime/types");
|
|
7406
7581
|
nuxt.options.alias["#blokkli/constants"] = resolver.resolve("runtime/constants");
|
|
7407
7582
|
nuxt.options.alias["#blokkli/plugins"] = resolver.resolve(
|
|
@@ -7412,6 +7587,9 @@ export type BlokkliIcon = keyof typeof icons`;
|
|
|
7412
7587
|
);
|
|
7413
7588
|
nuxt.options.alias["#blokkli/helpers"] = resolver.resolve("runtime/helpers");
|
|
7414
7589
|
nuxt.options.alias["#blokkli/adapter"] = resolver.resolve("runtime/adapter");
|
|
7590
|
+
nuxt.options.alias["#blokkli/runtime-helpers"] = resolver.resolve(
|
|
7591
|
+
"runtime/helpers/runtimeHelpers"
|
|
7592
|
+
);
|
|
7415
7593
|
nuxt.hook("nitro:config", (nitroConfig) => {
|
|
7416
7594
|
nitroConfig.publicAssets ||= [];
|
|
7417
7595
|
nitroConfig.publicAssets.push({
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
<script lang="ts" setup>
|
|
20
20
|
import { computed, useBlokkli, nextTick, ref } from '#imports'
|
|
21
|
-
import type { BlokkliIcon } from '#blokkli/icons'
|
|
21
|
+
import type { BlokkliIcon } from '#blokkli-build/icons'
|
|
22
22
|
import type { ActionPlacedEvent } from '#blokkli/types'
|
|
23
23
|
import { AddListItem } from '#blokkli/components'
|
|
24
24
|
import onBlokkliEvent from '#blokkli/helpers/composables/onBlokkliEvent'
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
<script setup lang="ts">
|
|
23
23
|
import { FormOverlay } from '#blokkli/components'
|
|
24
24
|
import onBlokkliEvent from '#blokkli/helpers/composables/onBlokkliEvent'
|
|
25
|
-
import type { BlokkliIcon } from '#blokkli/icons'
|
|
25
|
+
import type { BlokkliIcon } from '#blokkli-build/icons'
|
|
26
26
|
import type { DroppableEntityField, DroppableFieldConfig } from '#blokkli/types'
|
|
27
27
|
import { ref, useBlokkli } from '#imports'
|
|
28
28
|
|