@blokkli/editor 1.3.4 → 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 +315 -123
- 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 +5 -21
- 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 +5 -8
- 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 +19 -55
- 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 +3 -30
- package/dist/runtime/css/output.css +1 -1
- package/dist/runtime/helpers/domProvider.d.ts +0 -4
- package/dist/runtime/helpers/domProvider.js +63 -67
- 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
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import type { ComponentInternalInstance } from 'vue';
|
|
2
1
|
import { type ComputedRef } from '#imports';
|
|
3
2
|
import type { DraggableExistingBlock, BlokkliFieldElement, DraggableItem, DroppableEntityField, EntityContext, Rectangle } from '#blokkli/types';
|
|
4
3
|
import type { UiProvider } from './uiProvider.js';
|
|
5
|
-
import type { BlockBundleWithNested, ValidFieldListTypes } from '#blokkli/generated-types';
|
|
6
4
|
import type { DebugProvider } from './debugProvider.js';
|
|
7
5
|
type RegisteredFieldType = {
|
|
8
6
|
entityType: string;
|
|
@@ -21,8 +19,6 @@ export type DomProvider = {
|
|
|
21
19
|
*/
|
|
22
20
|
getDropElementMarkup(item: DraggableItem, checkSize?: boolean): string;
|
|
23
21
|
findField(entityUuid: string, fieldName: string): BlokkliFieldElement | undefined;
|
|
24
|
-
registerBlock: (uuid: string, instance: ComponentInternalInstance | null | HTMLElement, bundle: string, fieldListType: ValidFieldListTypes, parentBlockBundle?: BlockBundleWithNested) => void;
|
|
25
|
-
unregisterBlock: (uuid: string) => void;
|
|
26
22
|
registerField: (entity: EntityContext, fieldName: string, instance: HTMLElement) => void;
|
|
27
23
|
updateFieldElement: (entity: EntityContext, fieldName: string, element: HTMLElement) => void;
|
|
28
24
|
unregisterField: (entity: EntityContext, fieldName: string) => void;
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
import { cloneElementWithStyles } from "./dom/index.js";
|
|
10
10
|
import onBlokkliEvent from "./composables/onBlokkliEvent.js";
|
|
11
11
|
import useDelayedIntersectionObserver from "./composables/useDelayedIntersectionObserver.js";
|
|
12
|
-
import { getDefinition } from "#blokkli/definitions";
|
|
12
|
+
import { getDefinition } from "#blokkli-build/definitions";
|
|
13
13
|
const buildFieldElement = (element) => {
|
|
14
14
|
const key = element.dataset.fieldKey;
|
|
15
15
|
const name = element.dataset.fieldName;
|
|
@@ -43,16 +43,6 @@ const buildFieldElement = (element) => {
|
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
|
-
const getVisibleBlockElement = (instance) => {
|
|
47
|
-
if (instance instanceof HTMLElement) {
|
|
48
|
-
return instance;
|
|
49
|
-
}
|
|
50
|
-
if (instance.vnode.el instanceof HTMLElement) {
|
|
51
|
-
return instance.vnode.el;
|
|
52
|
-
} else if (instance?.vnode.el instanceof Text && instance?.vnode.el.nextElementSibling instanceof HTMLElement) {
|
|
53
|
-
return instance.vnode.el.nextElementSibling;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
46
|
function rectWithTime(rect, time) {
|
|
57
47
|
return {
|
|
58
48
|
...rect,
|
|
@@ -60,6 +50,7 @@ function rectWithTime(rect, time) {
|
|
|
60
50
|
};
|
|
61
51
|
}
|
|
62
52
|
export default function(ui, debug) {
|
|
53
|
+
const artboardElement = ui.artboardElement();
|
|
63
54
|
const logger = debug.createLogger("DomProvider");
|
|
64
55
|
const mutationsReady = ref(true);
|
|
65
56
|
const intersectionReady = ref(false);
|
|
@@ -136,7 +127,7 @@ export default function(ui, debug) {
|
|
|
136
127
|
}
|
|
137
128
|
}
|
|
138
129
|
}
|
|
139
|
-
const
|
|
130
|
+
const intersectionObserver = useDelayedIntersectionObserver(intersectionCallback);
|
|
140
131
|
const registeredBlocks = reactive({});
|
|
141
132
|
const registeredFields = reactive({});
|
|
142
133
|
const registeredFieldTypes = computed(() => {
|
|
@@ -162,22 +153,22 @@ export default function(ui, debug) {
|
|
|
162
153
|
const registerField = (entity, fieldName, element) => {
|
|
163
154
|
const key = `${entity.uuid}:${fieldName}`;
|
|
164
155
|
registeredFields[key] = { element, entity, fieldName };
|
|
165
|
-
|
|
156
|
+
intersectionObserver.observe(element);
|
|
166
157
|
};
|
|
167
158
|
const updateFieldElement = (entity, fieldName, element) => {
|
|
168
159
|
const key = `${entity.uuid}:${fieldName}`;
|
|
169
160
|
const existingElement = registeredFields[key]?.element;
|
|
170
161
|
if (existingElement) {
|
|
171
|
-
|
|
162
|
+
intersectionObserver.unobserve(existingElement);
|
|
172
163
|
}
|
|
173
164
|
registeredFields[key] = { entity, fieldName, element };
|
|
174
|
-
|
|
165
|
+
intersectionObserver.observe(element);
|
|
175
166
|
};
|
|
176
167
|
const unregisterField = (entity, fieldName) => {
|
|
177
168
|
const key = `${entity.uuid}:${fieldName}`;
|
|
178
169
|
const el = registeredFields[key]?.element;
|
|
179
170
|
if (el) {
|
|
180
|
-
|
|
171
|
+
intersectionObserver.unobserve(el);
|
|
181
172
|
}
|
|
182
173
|
visibleFields.delete(key);
|
|
183
174
|
registeredFields[key] = void 0;
|
|
@@ -196,45 +187,6 @@ export default function(ui, debug) {
|
|
|
196
187
|
}
|
|
197
188
|
return el;
|
|
198
189
|
}
|
|
199
|
-
const registerBlock = (uuid, instance, bundle, fieldListType, parentBlockBundle) => {
|
|
200
|
-
if (registeredBlocks[uuid]) {
|
|
201
|
-
console.error(
|
|
202
|
-
"Trying to register block with already existing UUID: " + uuid
|
|
203
|
-
);
|
|
204
|
-
}
|
|
205
|
-
if (!instance) {
|
|
206
|
-
console.error(
|
|
207
|
-
`Failed to get component instance of block with UUID "${uuid}"`
|
|
208
|
-
);
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
const el = getVisibleBlockElement(instance);
|
|
212
|
-
if (!el) {
|
|
213
|
-
console.error(
|
|
214
|
-
`Failed to locate block component element for UUID "${uuid}". Make sure the block renders at least one root element that is always visible.`
|
|
215
|
-
);
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
const observableElement = getElementToObserve(
|
|
219
|
-
el,
|
|
220
|
-
bundle,
|
|
221
|
-
fieldListType,
|
|
222
|
-
parentBlockBundle
|
|
223
|
-
);
|
|
224
|
-
observer.observe(observableElement);
|
|
225
|
-
resizeObserver.observe(observableElement);
|
|
226
|
-
registeredBlocks[uuid] = el;
|
|
227
|
-
};
|
|
228
|
-
const unregisterBlock = (uuid) => {
|
|
229
|
-
const el = registeredBlocks[uuid];
|
|
230
|
-
if (el) {
|
|
231
|
-
observer.unobserve(el);
|
|
232
|
-
resizeObserver.unobserve(el);
|
|
233
|
-
}
|
|
234
|
-
registeredBlocks[uuid] = void 0;
|
|
235
|
-
delete blockRects[uuid];
|
|
236
|
-
visibleBlocks.delete(uuid);
|
|
237
|
-
};
|
|
238
190
|
const findBlock = (uuid) => {
|
|
239
191
|
const cached = draggableBlockCache[uuid];
|
|
240
192
|
if (cached) {
|
|
@@ -399,26 +351,72 @@ export default function(ui, debug) {
|
|
|
399
351
|
logger.log("Refreshed all visible rects");
|
|
400
352
|
});
|
|
401
353
|
function init() {
|
|
402
|
-
|
|
354
|
+
intersectionObserver.init();
|
|
403
355
|
intersectionReady.value = true;
|
|
404
356
|
logger.log("IntersectionObserver initialized");
|
|
405
357
|
}
|
|
406
358
|
const dragElementUuidMap = /* @__PURE__ */ new WeakMap();
|
|
407
359
|
const dragElementCache = /* @__PURE__ */ new Map();
|
|
408
|
-
|
|
360
|
+
function handleNodeAdded(node) {
|
|
361
|
+
if (!(node instanceof HTMLElement)) {
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
if (node.dataset.uuid) {
|
|
365
|
+
const item = buildDraggableItem(node);
|
|
366
|
+
if (item && item.itemType === "existing") {
|
|
367
|
+
const observableElement = getElementToObserve(
|
|
368
|
+
node,
|
|
369
|
+
item.itemBundle,
|
|
370
|
+
item.hostFieldListType,
|
|
371
|
+
item.hostBundle
|
|
372
|
+
);
|
|
373
|
+
intersectionObserver.observe(observableElement);
|
|
374
|
+
resizeObserver.observe(observableElement);
|
|
375
|
+
registeredBlocks[item.uuid] = node;
|
|
376
|
+
}
|
|
377
|
+
} else if (node.dataset.fieldName && node.dataset.fieldKey && node.dataset.fieldCardinality) {
|
|
378
|
+
const blocks = node.querySelectorAll('[data-element-type="existing"]');
|
|
379
|
+
for (const block of blocks) {
|
|
380
|
+
handleNodeAdded(block);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
function handleNodeRemoved(node) {
|
|
385
|
+
if (node instanceof HTMLElement && node.dataset.uuid) {
|
|
386
|
+
const uuid = node.dataset.uuid;
|
|
387
|
+
const el = registeredBlocks[uuid];
|
|
388
|
+
if (el !== node) {
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
if (el) {
|
|
392
|
+
intersectionObserver.unobserve(el);
|
|
393
|
+
resizeObserver.unobserve(el);
|
|
394
|
+
dragElementUuidMap.delete(el);
|
|
395
|
+
}
|
|
396
|
+
dragElementUuidMap.delete(node);
|
|
397
|
+
dragElementCache.delete(uuid);
|
|
398
|
+
registeredBlocks[uuid] = void 0;
|
|
399
|
+
delete blockRects[uuid];
|
|
400
|
+
visibleBlocks.delete(uuid);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
const mutationObserverCallback = function(mutationsList) {
|
|
409
404
|
for (const mutation of mutationsList) {
|
|
410
405
|
if (mutation.type === "childList") {
|
|
411
|
-
mutation.removedNodes
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
});
|
|
406
|
+
for (const node of mutation.removedNodes) {
|
|
407
|
+
handleNodeRemoved(node);
|
|
408
|
+
}
|
|
409
|
+
for (const node of mutation.addedNodes) {
|
|
410
|
+
handleNodeAdded(node);
|
|
411
|
+
}
|
|
418
412
|
}
|
|
419
413
|
}
|
|
420
414
|
};
|
|
421
|
-
const mutationObserver = new MutationObserver(
|
|
415
|
+
const mutationObserver = new MutationObserver(mutationObserverCallback);
|
|
416
|
+
mutationObserver.observe(artboardElement, {
|
|
417
|
+
subtree: true,
|
|
418
|
+
childList: true
|
|
419
|
+
});
|
|
422
420
|
function getDragElement(block) {
|
|
423
421
|
const cached = dragElementCache.get(block.uuid);
|
|
424
422
|
if (cached && document.body.contains(cached)) {
|
|
@@ -444,8 +442,6 @@ export default function(ui, debug) {
|
|
|
444
442
|
findClosestBlock,
|
|
445
443
|
getDropElementMarkup,
|
|
446
444
|
findField,
|
|
447
|
-
registerBlock,
|
|
448
|
-
unregisterBlock,
|
|
449
445
|
getAllDroppableFields,
|
|
450
446
|
findClosestEntityContext,
|
|
451
447
|
getVisibleBlocks,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FeatureDefinition, AdapterMethods } from '#blokkli/types';
|
|
2
|
-
import { type ValidFeatureKey } from '#blokkli-
|
|
2
|
+
import { type ValidFeatureKey } from '#blokkli-build/features';
|
|
3
3
|
import { type ComputedRef } from '#imports';
|
|
4
4
|
import type { StorageProvider } from './storageProvider.js';
|
|
5
5
|
export type FeaturesProvider = {
|
|
@@ -86,3 +86,4 @@ export declare function getInteractionCoordinates(e: MouseEvent | TouchEvent): C
|
|
|
86
86
|
export declare function toShaderColor(rgba: RGB): RGB;
|
|
87
87
|
export declare function generateUUID(): string;
|
|
88
88
|
export declare function buildAttributesForLibraryItem(props: LibraryItemProps): Record<string, string | undefined>;
|
|
89
|
+
export declare function asValidNumber(v: unknown, defaultValue: number): number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { easeOutSine } from "./easing.js";
|
|
2
2
|
import { useRuntimeConfig } from "#imports";
|
|
3
|
-
import { getDefinition } from "#blokkli/definitions";
|
|
3
|
+
import { getDefinition } from "#blokkli-build/definitions";
|
|
4
4
|
export function falsy(value) {
|
|
5
5
|
return value !== null && value !== void 0;
|
|
6
6
|
}
|
|
@@ -474,3 +474,9 @@ export function buildAttributesForLibraryItem(props) {
|
|
|
474
474
|
"data-blokkli-is-reusable": "true"
|
|
475
475
|
};
|
|
476
476
|
}
|
|
477
|
+
export function asValidNumber(v, defaultValue) {
|
|
478
|
+
if (typeof v === "number" && !Number.isNaN(v)) {
|
|
479
|
+
return v;
|
|
480
|
+
}
|
|
481
|
+
return defaultValue;
|
|
482
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This file should contain all helpers that are meant for runtime functionality, such as defineBlokkli composable or <BlokkliProvider>.
|
|
3
3
|
*/
|
|
4
|
-
import type
|
|
4
|
+
import { type RuntimeBlockOptionArray, type RuntimeBlockOptions } from '#blokkli-build/runtime-options';
|
|
5
|
+
import type { FieldListItemTyped } from '#blokkli-build/generated-types';
|
|
5
6
|
import type { BlockOptionDefinition } from '#blokkli/types/blokkOptions';
|
|
6
7
|
import type { FieldListItem } from '#blokkli/types';
|
|
7
8
|
/**
|
|
@@ -14,8 +15,28 @@ export declare function mapCheckboxTrue(v?: unknown): '1' | '0';
|
|
|
14
15
|
*
|
|
15
16
|
* Internally, all option values are stored as strings. This function maps the stored data to the runtime value.
|
|
16
17
|
*/
|
|
17
|
-
export declare function getRuntimeOptionValue(definition: Pick<BlockOptionDefinition, 'type' | 'default'
|
|
18
|
+
export declare function getRuntimeOptionValue(definition: Pick<BlockOptionDefinition, 'type' | 'default'> | RuntimeBlockOptionArray, value: string | string[] | boolean | undefined | null | number): string | string[] | boolean | number;
|
|
18
19
|
/**
|
|
19
20
|
* Determines whether an item is visible.
|
|
20
21
|
*/
|
|
21
22
|
export declare function isVisibleByOptions(item?: FieldListItemTyped | FieldListItem, language?: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Returns the runtime options for a block.
|
|
25
|
+
*
|
|
26
|
+
* If the provided item's bundle is 'from_library', the method will merge the
|
|
27
|
+
* options defined in the reusable block with the options defined in the
|
|
28
|
+
* from_library block.
|
|
29
|
+
*/
|
|
30
|
+
export declare function getRuntimeOptions<K extends keyof RuntimeBlockOptions>(item: FieldListItemTyped & {
|
|
31
|
+
bundle: K;
|
|
32
|
+
}, fromLibraryOptions?: Record<string, any>): RuntimeBlockOptions[K];
|
|
33
|
+
/**
|
|
34
|
+
* Get the actual block for reusable blocks.
|
|
35
|
+
*
|
|
36
|
+
* If the provided bundle is 'from_library', the method will merge the options
|
|
37
|
+
* from both the from_library block and the actual block.
|
|
38
|
+
*/
|
|
39
|
+
export declare function getActualBlock(item: FieldListItemTyped): FieldListItemTyped | null;
|
|
40
|
+
export declare function getItemsforBundles<K extends FieldListItemTyped['bundle']>(items: FieldListItemTyped[], bundles: K[]): Extract<FieldListItemTyped, {
|
|
41
|
+
bundle: K;
|
|
42
|
+
}>[];
|
|
@@ -1,27 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BLOCK_OPTIONS
|
|
3
|
+
} from "#blokkli-build/runtime-options";
|
|
1
4
|
import {
|
|
2
5
|
bundlesWithVisibleLanguage,
|
|
3
6
|
bundlesWithHiddenGlobally
|
|
4
|
-
} from "#blokkli/default-global-options";
|
|
7
|
+
} from "#blokkli-build/default-global-options";
|
|
5
8
|
import { BK_HIDDEN_GLOBALLY, BK_VISIBLE_LANGUAGES } from "../symbols.js";
|
|
6
9
|
export function mapCheckboxTrue(v) {
|
|
7
10
|
return v === true || v === "1" || v === 1 || v === "true" ? "1" : "0";
|
|
8
11
|
}
|
|
9
12
|
export function getRuntimeOptionValue(definition, value) {
|
|
10
|
-
|
|
13
|
+
const type = Array.isArray(definition) ? definition[0] : definition.type;
|
|
14
|
+
const defaultValue = Array.isArray(definition) ? definition[1] : definition.default;
|
|
15
|
+
if (value === null || value === void 0) {
|
|
16
|
+
return defaultValue;
|
|
17
|
+
}
|
|
18
|
+
if (type === "checkbox") {
|
|
11
19
|
return mapCheckboxTrue(value) === "1";
|
|
12
|
-
} else if (
|
|
20
|
+
} else if (type === "radios") {
|
|
13
21
|
if (typeof value === "string") {
|
|
14
22
|
return value;
|
|
15
23
|
}
|
|
16
|
-
|
|
17
|
-
} else if (definition.type === "checkboxes") {
|
|
24
|
+
} else if (type === "checkboxes") {
|
|
18
25
|
if (typeof value === "string") {
|
|
19
26
|
return value.split(",");
|
|
20
27
|
} else if (Array.isArray(value)) {
|
|
21
28
|
return value;
|
|
22
29
|
}
|
|
23
|
-
|
|
24
|
-
} else if (definition.type === "range" || definition.type === "number") {
|
|
30
|
+
} else if (type === "range" || type === "number") {
|
|
25
31
|
if (typeof value === "number" && !Number.isNaN(value)) {
|
|
26
32
|
return value;
|
|
27
33
|
} else if (typeof value === "string") {
|
|
@@ -30,11 +36,18 @@ export function getRuntimeOptionValue(definition, value) {
|
|
|
30
36
|
return parsed;
|
|
31
37
|
}
|
|
32
38
|
}
|
|
33
|
-
}
|
|
34
|
-
|
|
39
|
+
} else if (type === "color") {
|
|
40
|
+
if (typeof value === "string") {
|
|
41
|
+
if (value.startsWith("#")) {
|
|
42
|
+
return value;
|
|
43
|
+
} else if (value.length === 6) {
|
|
44
|
+
return `#${value}`;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
} else if (type === "text" && typeof value === "string") {
|
|
35
48
|
return value;
|
|
36
49
|
}
|
|
37
|
-
return
|
|
50
|
+
return defaultValue;
|
|
38
51
|
}
|
|
39
52
|
export function isVisibleByOptions(item, language) {
|
|
40
53
|
if (!item) {
|
|
@@ -56,3 +69,63 @@ export function isVisibleByOptions(item, language) {
|
|
|
56
69
|
}
|
|
57
70
|
return true;
|
|
58
71
|
}
|
|
72
|
+
export function getRuntimeOptions(item, fromLibraryOptions) {
|
|
73
|
+
if (item.bundle === "from_library" && "libraryItem" in item.props) {
|
|
74
|
+
const actualBlock = item.props.libraryItem?.block;
|
|
75
|
+
if (!actualBlock) {
|
|
76
|
+
throw new Error("Missing block");
|
|
77
|
+
}
|
|
78
|
+
return getRuntimeOptions(
|
|
79
|
+
actualBlock,
|
|
80
|
+
item.options
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
const availableOptions = BLOCK_OPTIONS[item.bundle] || {};
|
|
84
|
+
return Object.entries(availableOptions).reduce(
|
|
85
|
+
(acc, [key, definition]) => {
|
|
86
|
+
if (fromLibraryOptions && fromLibraryOptions[key] !== void 0 && fromLibraryOptions[key] !== null) {
|
|
87
|
+
acc[key] = getRuntimeOptionValue(
|
|
88
|
+
definition,
|
|
89
|
+
fromLibraryOptions.value[key]
|
|
90
|
+
);
|
|
91
|
+
return acc;
|
|
92
|
+
}
|
|
93
|
+
if (item.options && item.options[key] !== void 0 && item.options[key] !== null) {
|
|
94
|
+
acc[key] = getRuntimeOptionValue(definition, item.options[key]);
|
|
95
|
+
return acc;
|
|
96
|
+
}
|
|
97
|
+
acc[key] = definition[1];
|
|
98
|
+
return acc;
|
|
99
|
+
},
|
|
100
|
+
{}
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
export function getActualBlock(item) {
|
|
104
|
+
if (item.bundle === "from_library") {
|
|
105
|
+
const block = item.props.libraryItem?.block;
|
|
106
|
+
if (!block) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
const mergedOptions = {
|
|
110
|
+
...item.options || {},
|
|
111
|
+
...block.options || {}
|
|
112
|
+
};
|
|
113
|
+
return { ...block, options: mergedOptions };
|
|
114
|
+
}
|
|
115
|
+
return item;
|
|
116
|
+
}
|
|
117
|
+
export function getItemsforBundles(items, bundles) {
|
|
118
|
+
const filtered = [];
|
|
119
|
+
for (let i = 0; i < items.length; i++) {
|
|
120
|
+
const item = items[i];
|
|
121
|
+
if (item.bundle === "from_library") {
|
|
122
|
+
const actual = getActualBlock(item);
|
|
123
|
+
if (actual && bundles.includes(actual.bundle)) {
|
|
124
|
+
filtered.push(actual);
|
|
125
|
+
}
|
|
126
|
+
} else if (bundles.includes(item.bundle)) {
|
|
127
|
+
filtered.push(item);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return filtered;
|
|
131
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { computed } from "vue";
|
|
2
|
-
import { translations } from "#blokkli/translations";
|
|
3
|
-
import { defaultLanguage, forceDefaultLanguage } from "#blokkli/config";
|
|
2
|
+
import { translations } from "#blokkli-build/translations";
|
|
3
|
+
import { defaultLanguage, forceDefaultLanguage } from "#blokkli-build/config";
|
|
4
4
|
export default function(context) {
|
|
5
5
|
const language = computed(() => {
|
|
6
6
|
if (forceDefaultLanguage) {
|
|
@@ -14,10 +14,10 @@ import type { BlockOptionDefinition } from './blokkOptions.js';
|
|
|
14
14
|
import type { BlokkliAdapter, AdapterContext, MutationResponseLike } from './../adapter.js';
|
|
15
15
|
import type { BroadcastProvider } from '#blokkli/helpers/broadcastProvider';
|
|
16
16
|
import type { FeaturesProvider } from '#blokkli/helpers/featuresProvider';
|
|
17
|
-
import type { BlokkliIcon } from '#blokkli/icons';
|
|
17
|
+
import type { BlokkliIcon } from '#blokkli-build/icons';
|
|
18
18
|
import type { SettingsGroup, Viewport } from '#blokkli/constants';
|
|
19
|
-
import type { BlockBundleWithNested, FieldListItemTyped, GlobalOptionsKey, ValidChunkNames, ValidFieldListTypes, ValidGlobalConfigKeys } from '#blokkli/generated-types';
|
|
20
|
-
import type { globalOptions } from '#blokkli/definitions';
|
|
19
|
+
import type { BlockBundleWithNested, FieldListItemTyped, GlobalOptionsKey, ValidChunkNames, ValidFieldListTypes, ValidGlobalConfigKeys } from '#blokkli-build/generated-types';
|
|
20
|
+
import type { globalOptions } from '#blokkli-build/definitions';
|
|
21
21
|
import type { ThemeProvider } from '#blokkli/helpers/themeProvider';
|
|
22
22
|
import type { CommandsProvider } from '#blokkli/helpers/commandsProvider';
|
|
23
23
|
import type { TourProvider } from '#blokkli/helpers/tourProvider';
|
|
@@ -244,7 +244,7 @@ export type BlockDefinitionRenderForFieldListType = {
|
|
|
244
244
|
fieldListType: ValidFieldListTypes;
|
|
245
245
|
};
|
|
246
246
|
export type BlockDefinitionRenderFor = BlockDefinitionRenderForParent | BlockDefinitionRenderForFieldList | BlockDefinitionRenderForFieldListType;
|
|
247
|
-
export type BlockDefinitionInput<Options extends BlockDefinitionOptionsInput = BlockDefinitionOptionsInput, GlobalOptions extends GlobalOptionsKey[] | undefined =
|
|
247
|
+
export type BlockDefinitionInput<Options extends BlockDefinitionOptionsInput = BlockDefinitionOptionsInput, GlobalOptions extends GlobalOptionsKey[] | undefined = []> = {
|
|
248
248
|
/**
|
|
249
249
|
* The bundle ID of the block, e.g. "text" or "section_title".
|
|
250
250
|
*/
|
|
@@ -279,6 +279,9 @@ export type BlockDefinitionInput<Options extends BlockDefinitionOptionsInput = B
|
|
|
279
279
|
*/
|
|
280
280
|
editor?: BlokkliDefinitionInputEditor<Options, GlobalOptions>;
|
|
281
281
|
};
|
|
282
|
+
export type RuntimeBlockDefinitionInput = {
|
|
283
|
+
bundle: string;
|
|
284
|
+
};
|
|
282
285
|
export type InjectedBlokkliItem = ComputedRef<{
|
|
283
286
|
index: ComputedRef<number>;
|
|
284
287
|
uuid: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blokkli/editor",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0-alpha.1",
|
|
4
4
|
"description": "Interactive page building experience for Nuxt",
|
|
5
5
|
"repository": "blokkli/editor",
|
|
6
6
|
"type": "module",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"eslint-plugin-tailwindcss": "^3.17.4",
|
|
82
82
|
"gettext-parser": "^8.0.0",
|
|
83
83
|
"happy-dom": "^15.7.4",
|
|
84
|
-
"nuxt": "^3.
|
|
84
|
+
"nuxt": "^3.15.4",
|
|
85
85
|
"nuxt-svg-icon-sprite": "^1.0.2",
|
|
86
86
|
"openai": "^4.59.0",
|
|
87
87
|
"playwright-core": "^1.47.0",
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export function optionValueToStorable(definition, value) {
|
|
2
|
-
if (definition.type === "checkbox") {
|
|
3
|
-
if (typeof value === "string" && (value === "1" || value === "0")) {
|
|
4
|
-
return value;
|
|
5
|
-
} else if (typeof value === "boolean") {
|
|
6
|
-
return value === true ? "1" : "0";
|
|
7
|
-
}
|
|
8
|
-
return "0";
|
|
9
|
-
} else if (definition.type === "text" || definition.type === "radios") {
|
|
10
|
-
if (typeof value === "string") {
|
|
11
|
-
return value;
|
|
12
|
-
}
|
|
13
|
-
} else if (definition.type === "checkboxes") {
|
|
14
|
-
if (Array.isArray(value)) {
|
|
15
|
-
return value.join(",");
|
|
16
|
-
} else if (typeof value === "string") {
|
|
17
|
-
return value;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return "";
|
|
21
|
-
}
|