@blokkli/editor 1.3.3 → 1.4.0-alpha.0

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.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "blokkli",
3
3
  "configKey": "blokkli",
4
- "version": "1.3.3",
4
+ "version": "1.4.0-alpha.0",
5
5
  "compatibility": {
6
6
  "nuxt": "^3.12.0"
7
7
  },
package/dist/module.mjs CHANGED
@@ -7,7 +7,7 @@ import MagicString from 'magic-string';
7
7
  import { walk } from 'estree-walker-ts';
8
8
  import { BK_VISIBLE_LANGUAGES, BK_HIDDEN_GLOBALLY } from '../dist/runtime/helpers/symbols.js';
9
9
 
10
- const version = "1.3.3";
10
+ const version = "1.4.0-alpha.0";
11
11
 
12
12
  function sortObjectKeys(obj) {
13
13
  if (Array.isArray(obj)) {
@@ -190,7 +190,7 @@ class BlockExtractor {
190
190
  icon,
191
191
  proxyComponent,
192
192
  diffComponent,
193
- chunkName: extracted.definition.chunkName || "global",
193
+ chunkName: this.isBuild ? extracted.definition.chunkName || "global" : "global",
194
194
  componentName: "BlokkliComponent_" + extracted.definition.bundle + "_" + componentFileName,
195
195
  source: extracted.source,
196
196
  fileSource,
@@ -203,7 +203,7 @@ class BlockExtractor {
203
203
  this.fragmentDefinitions[filePath2] = {
204
204
  filePath: filePath2,
205
205
  definition: extracted.definition,
206
- chunkName: extracted.definition.chunkName || "global",
206
+ chunkName: this.isBuild ? extracted.definition.chunkName || "global" : "global",
207
207
  componentName: "BlokkliFragmentComponent_" + extracted.definition.name,
208
208
  source: extracted.source,
209
209
  fileSource
@@ -399,7 +399,7 @@ export const getFragmentDefinition = (name: string): FragmentDefinitionInput<Rec
399
399
  generateDefaultGlobalOptions(globalOptions = {}) {
400
400
  const defaults = Object.entries(globalOptions).reduce(
401
401
  (acc, [key, option]) => {
402
- if (option.default) {
402
+ if (option.default !== void 0 && option.default !== null) {
403
403
  acc[key] = {
404
404
  default: option.default,
405
405
  type: option.type
@@ -561,20 +561,28 @@ const fragmentChunkMapping: Record<string, string> = ${JSON.stringify(
561
561
  2
562
562
  )}
563
563
 
564
+ function componentOrFunction(component: any) {
565
+ if (typeof component === 'object') {
566
+ return component
567
+ }
568
+
569
+ return defineAsyncComponent(() => component())
570
+ }
571
+
564
572
  export function getBlokkliItemComponent(bundle: string, fieldListType?: string, parentBundle?: string): any {
565
573
  const forFieldListType = 'block_' + bundle + '__field_list_type_' + fieldListType
566
574
  if (global[forFieldListType]) {
567
- return global[forFieldListType]
575
+ return componentOrFunction(global[forFieldListType])
568
576
  }
569
577
  if (parentBundle) {
570
578
  const forParentBundle = 'block_' + bundle + '__parent_block_' + parentBundle
571
579
  if (global[forParentBundle]) {
572
- return global[forParentBundle]
580
+ return componentOrFunction(global[forParentBundle])
573
581
  }
574
582
  }
575
583
  const key = 'block_' + bundle
576
584
  if (global[key]) {
577
- return global[key]
585
+ return componentOrFunction(global[key])
578
586
  }
579
587
  const chunkName = chunkMapping[key]
580
588
  if (chunkName) {
@@ -587,7 +595,7 @@ export function getBlokkliItemComponent(bundle: string, fieldListType?: string,
587
595
  export function getBlokkliFragmentComponent(name: string): any {
588
596
  const key = 'fragment_' + name
589
597
  if (globalFragments[key]) {
590
- return globalFragments[key]
598
+ return componentOrFunction(globalFragments[key])
591
599
  }
592
600
  const chunkName = fragmentChunkMapping[key]
593
601
  if (chunkName) {
@@ -606,7 +614,11 @@ export function getBlokkliFragmentComponent(name: string): any {
606
614
  return v?.chunkName === chunkName;
607
615
  }).filter(falsy);
608
616
  const imports = definitions.map((v) => {
609
- return `import ${v.componentName} from '${v.filePath}'`;
617
+ if (this.isBuild) {
618
+ return `import ${v.componentName} from '${v.filePath}'`;
619
+ } else {
620
+ return `const ${v.componentName} = () => import('${v.filePath}')`;
621
+ }
610
622
  });
611
623
  const map = definitions.reduce((acc, v) => {
612
624
  if ("bundle" in v.definition) {
@@ -6999,7 +7011,10 @@ const module = defineNuxtModule({
6999
7011
  moduleOptions.alterFeatures(featuresContext)
7000
7012
  );
7001
7013
  }
7002
- const allFeatureIds = extractedFeatures.map((v) => v.id);
7014
+ const allFeatureIds = [
7015
+ ...extractedFeatures.map((v) => v.id),
7016
+ ...featuresContext.features.map((v) => v.id)
7017
+ ].filter(onlyUnique);
7003
7018
  const featureComponents = addTemplate({
7004
7019
  write: true,
7005
7020
  filename: "blokkli/features.ts",
@@ -7327,7 +7342,7 @@ export const forceDefaultLanguage: boolean = ${JSON.stringify(
7327
7342
  };
7328
7343
  await generateOptionsSchema();
7329
7344
  getChunkNames().forEach((chunkName) => {
7330
- if (chunkName !== "global") {
7345
+ if (chunkName !== "global" && !nuxt.options.dev) {
7331
7346
  const template = addTemplate({
7332
7347
  write: true,
7333
7348
  filename: `blokkli/chunk-${chunkName}.ts`,
@@ -7345,7 +7360,9 @@ export const forceDefaultLanguage: boolean = ${JSON.stringify(
7345
7360
  write: true,
7346
7361
  filename: "blokkli/imports.ts",
7347
7362
  getContents: () => {
7348
- return blockExtractor.generateImportsTemplate(getChunkNames());
7363
+ return blockExtractor.generateImportsTemplate(
7364
+ nuxt.options.dev ? ["global"] : getChunkNames()
7365
+ );
7349
7366
  },
7350
7367
  options: {
7351
7368
  blokkli: true
@@ -34,7 +34,7 @@ import type {
34
34
  BlockBundleWithNested,
35
35
  ValidFieldListTypes,
36
36
  } from '#blokkli/generated-types'
37
- import { computed, useBlokkli, onMounted, onBeforeUnmount, ref } from '#imports'
37
+ import { computed, useBlokkli, ref } from '#imports'
38
38
  import {
39
39
  getDefinition,
40
40
  getBlokkliItemProxyComponent,
@@ -83,7 +83,7 @@ const proxyBundle = computed(
83
83
  () => libraryItemProps.value?.block?.bundle || props.bundle,
84
84
  )
85
85
 
86
- const { dom, types, runtimeConfig } = useBlokkli()
86
+ const { types, runtimeConfig } = useBlokkli()
87
87
 
88
88
  const root = ref<HTMLElement | null>(null)
89
89
 
@@ -125,18 +125,4 @@ const fieldLayout = computed<FieldConfig[][]>(() => {
125
125
  .forEntityTypeAndBundle(runtimeConfig.itemEntityType, proxyBundle.value)
126
126
  .map((config) => [config])
127
127
  })
128
-
129
- onMounted(() => {
130
- dom.registerBlock(
131
- props.uuid,
132
- root.value,
133
- props.bundle,
134
- props.fieldListType,
135
- props.parentType as BlockBundleWithNested,
136
- )
137
- })
138
-
139
- onBeforeUnmount(() => {
140
- dom.unregisterBlock(props.uuid)
141
- })
142
128
  </script>
@@ -37,7 +37,7 @@
37
37
  <DragInteractions v-if="!isInitializing" />
38
38
  <AnimationCanvas v-if="!isInitializing" />
39
39
  <SystemRequirements />
40
- <slot :mutated-entity="mutatedEntity" />
40
+ <slot v-if="!isInitializing" :mutated-entity="mutatedEntity" />
41
41
  </template>
42
42
 
43
43
  <script lang="ts" setup generic="T">
@@ -176,15 +176,13 @@ onMounted(() => {
176
176
  if (props.isolate) {
177
177
  document.documentElement.classList.add('bk-isolate-provider')
178
178
  }
179
- nextTick(() => {
180
- isInitializing.value = false
181
- })
182
179
 
183
180
  document.documentElement.addEventListener('touchmove', onTouchMove)
184
181
  document.documentElement.addEventListener('touchstart', onTouchStart)
185
182
  setRootClasses()
186
183
  baseLogger.log('EditProvider mounted')
187
184
  dom.init()
185
+ isInitializing.value = false
188
186
  broadcast.emit('editorLoaded', { uuid: props.entityUuid })
189
187
  })
190
188
 
@@ -17,7 +17,7 @@
17
17
  </template>
18
18
 
19
19
  <script setup lang="ts">
20
- import { type Artboard, type ArtboardPlugin, overview } from 'artboard-deluxe'
20
+ import { type Artboard, type PluginOverview, overview } from 'artboard-deluxe'
21
21
  import { onBeforeUnmount, onMounted, ref, useBlokkli, computed } from '#imports'
22
22
  import onBlokkliEvent from '#blokkli/helpers/composables/onBlokkliEvent'
23
23
 
@@ -40,7 +40,7 @@ const overviewArtboardEl = ref<HTMLDivElement>()
40
40
  const overviewVisibleEl = ref<HTMLDivElement>()
41
41
  const canvas = ref<HTMLCanvasElement>()
42
42
 
43
- let pluginOverview: ArtboardPlugin | null = null
43
+ let pluginOverview: PluginOverview | null = null
44
44
 
45
45
  function updateCanvas() {
46
46
  const ctx = canvas.value?.getContext('2d')
@@ -12,7 +12,7 @@
12
12
  </template>
13
13
 
14
14
  <script setup lang="ts">
15
- import { type Artboard, type ArtboardPlugin, scrollbar } from 'artboard-deluxe'
15
+ import { type Artboard, type PluginScrollbar, scrollbar } from 'artboard-deluxe'
16
16
  import { onBeforeUnmount, onMounted, ref } from '#imports'
17
17
 
18
18
  const props = defineProps<{
@@ -22,7 +22,7 @@ const props = defineProps<{
22
22
 
23
23
  const el = ref<HTMLDivElement>()
24
24
  const thumb = ref<HTMLButtonElement>()
25
- let scrollbarPlugin: ArtboardPlugin | null = null
25
+ let scrollbarPlugin: PluginScrollbar | null = null
26
26
 
27
27
  onMounted(() => {
28
28
  if (el.value && thumb.value) {
@@ -65,11 +65,11 @@ import {
65
65
  type ArtboardOptions,
66
66
  type Artboard,
67
67
  type PluginWheelOptions,
68
+ type PluginWheelFactory,
68
69
  touch,
69
70
  wheel,
70
71
  mouse,
71
72
  dom as domPlugin,
72
- type PluginWheel,
73
73
  } from 'artboard-deluxe'
74
74
  const { settings } = defineBlokkliFeature({
75
75
  id: 'artboard',
@@ -155,7 +155,7 @@ const saveState = () => {
155
155
  }
156
156
  }
157
157
 
158
- let pluginWheel: PluginWheel | null = null
158
+ let pluginWheel: PluginWheelFactory | null = null
159
159
 
160
160
  const wheelOptions = computed<PluginWheelOptions>(() => {
161
161
  return {
@@ -115,7 +115,7 @@ const groups = computed<GroupedSettings[]>(() => {
115
115
  }
116
116
 
117
117
  acc[group].settings.push({
118
- featureId: feature.id,
118
+ featureId: feature.id as ValidFeatureKey,
119
119
  settingsKey,
120
120
  setting,
121
121
  })
@@ -4,16 +4,9 @@ import {
4
4
  INJECT_FIELD_LIST_BLOCKS,
5
5
  INJECT_FIELD_LIST_TYPE,
6
6
  INJECT_REUSABLE_OPTIONS,
7
- INJECT_PROVIDER_BLOCKS,
8
- INJECT_FIELD_USES_PROXY
7
+ INJECT_PROVIDER_BLOCKS
9
8
  } from "../helpers/symbols.js";
10
- import {
11
- computed,
12
- inject,
13
- getCurrentInstance,
14
- onMounted,
15
- onBeforeUnmount
16
- } from "#imports";
9
+ import { computed, inject } from "#imports";
17
10
  import { globalOptionsDefaults } from "#blokkli/default-global-options";
18
11
  import { getRuntimeOptionValue } from "#blokkli/helpers/runtimeHelpers";
19
12
  export function defineBlokkli(config) {
@@ -82,30 +75,6 @@ export function defineBlokkli(config) {
82
75
  });
83
76
  const parentType = computed(() => item?.value.parentType);
84
77
  const isEditing = !!item?.value.isEditing;
85
- const fieldUsesProxy = inject(INJECT_FIELD_USES_PROXY, false);
86
- onMounted(() => {
87
- if (
88
- // If the field uses proxy mode we don't want to register the block here.
89
- fieldUsesProxy || !item?.value || !isEditing || !editContext || !editContext.dom || // Block is already registered by the from_library block.
90
- fromLibraryOptions || // The defineBlokkliFragment composable registers the block itself.
91
- config.bundle === "blokkli_fragment"
92
- ) {
93
- return;
94
- }
95
- const instance = getCurrentInstance();
96
- editContext.dom.registerBlock(
97
- uuid,
98
- instance,
99
- config.bundle,
100
- fieldListType.value,
101
- item.value.parentType
102
- );
103
- });
104
- onBeforeUnmount(() => {
105
- if (!fieldUsesProxy && isEditing && editContext && editContext.dom && uuid && config.bundle !== "blokkli_fragment") {
106
- editContext.dom.unregisterBlock(uuid);
107
- }
108
- });
109
78
  return {
110
79
  uuid,
111
80
  index,
@@ -1,22 +1,12 @@
1
- import {
2
- INJECT_EDIT_CONTEXT,
3
- INJECT_FRAGMENT_CONTEXT
4
- } from "../helpers/symbols.js";
1
+ import { INJECT_FRAGMENT_CONTEXT } from "../helpers/symbols.js";
5
2
  import { getRuntimeOptionValue } from "../helpers/runtimeHelpers/index.js";
6
- import {
7
- computed,
8
- getCurrentInstance,
9
- inject,
10
- onBeforeUnmount,
11
- onMounted
12
- } from "#imports";
3
+ import { computed, inject } from "#imports";
13
4
  import { globalOptionsDefaults } from "#blokkli/default-global-options";
14
5
  export function defineBlokkliFragment(config) {
15
6
  const ctx = inject(
16
7
  INJECT_FRAGMENT_CONTEXT,
17
8
  null
18
9
  );
19
- const editContext = inject(INJECT_EDIT_CONTEXT, null);
20
10
  const optionKeys = [
21
11
  ...Object.keys(config.options || {}),
22
12
  ...config.globalOptions || []
@@ -36,22 +26,5 @@ export function defineBlokkliFragment(config) {
36
26
  });
37
27
  return result;
38
28
  });
39
- onMounted(() => {
40
- if (editContext && editContext.dom && ctx) {
41
- const instance = getCurrentInstance();
42
- editContext.dom.registerBlock(
43
- ctx.uuid,
44
- instance,
45
- "blokkli_fragment",
46
- ctx.fieldListType.value,
47
- ctx.parentType.value
48
- );
49
- }
50
- });
51
- onBeforeUnmount(() => {
52
- if (editContext && ctx && ctx.uuid && editContext.dom) {
53
- editContext.dom.unregisterBlock(ctx.uuid);
54
- }
55
- });
56
29
  return { ...ctx, options };
57
30
  }
@@ -1,5 +1,11 @@
1
1
  import { INJECT_APP } from "../helpers/symbols.js";
2
2
  import { inject } from "#imports";
3
3
  export function useBlokkli() {
4
- return inject(INJECT_APP);
4
+ const app = inject(INJECT_APP);
5
+ if (!app) {
6
+ throw new Error(
7
+ "The useBlokkli composable was called while not in edit mode."
8
+ );
9
+ }
10
+ return app;
5
11
  }