@nuxt-atelier/editor 0.1.0 → 0.1.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.json +1 -1
- package/dist/runtime/VisualEditor.vue +18 -7
- package/dist/runtime/editor.css +1 -1
- package/dist/runtime/tree.d.ts +1 -3
- package/dist/runtime/tree.js +1 -10
- package/package.json +1 -1
package/dist/module.json
CHANGED
|
@@ -36,6 +36,15 @@ const src = ref("");
|
|
|
36
36
|
const failure = ref("");
|
|
37
37
|
const width = ref(presets[0]?.width ?? 1280);
|
|
38
38
|
const presetOptions = computed(() => presets.map((p) => ({ value: String(p.width), label: `${p.label} (${p.width}px)` })));
|
|
39
|
+
const stage = ref(null);
|
|
40
|
+
const stageWidth = ref(0);
|
|
41
|
+
const scale = computed(() => stageWidth.value && width.value > stageWidth.value ? stageWidth.value / width.value : 1);
|
|
42
|
+
let resizes;
|
|
43
|
+
onMounted(() => {
|
|
44
|
+
resizes = new ResizeObserver(([entry]) => stageWidth.value = entry.contentRect.width);
|
|
45
|
+
resizes.observe(stage.value);
|
|
46
|
+
});
|
|
47
|
+
onBeforeUnmount(() => resizes?.disconnect());
|
|
39
48
|
onMounted(async () => {
|
|
40
49
|
try {
|
|
41
50
|
src.value = (await api("/editor/token", { method: "POST", body: { type: name, ...id ? { id } : {} } })).url;
|
|
@@ -206,8 +215,8 @@ const overlay = ref(null);
|
|
|
206
215
|
const previewLine = ref(null);
|
|
207
216
|
function blocksUnder(event) {
|
|
208
217
|
const origin = overlay.value.getBoundingClientRect();
|
|
209
|
-
const x = event.clientX - origin.left;
|
|
210
|
-
const y = event.clientY - origin.top;
|
|
218
|
+
const x = (event.clientX - origin.left) / scale.value;
|
|
219
|
+
const y = (event.clientY - origin.top) / scale.value;
|
|
211
220
|
const under = (geometry.value?.blocks ?? []).filter((b) => x >= b.rect.x && x <= b.rect.x + b.rect.width && y >= b.rect.y && y <= b.rect.y + b.rect.height).sort((a, b) => a.rect.width * a.rect.height - b.rect.width * b.rect.height);
|
|
212
221
|
return { under, y };
|
|
213
222
|
}
|
|
@@ -514,10 +523,11 @@ const targetLabel = computed(() => (target.value && listAt(target.value.list)?.l
|
|
|
514
523
|
:model-value="String(width)"
|
|
515
524
|
:label="t('editor.viewport')"
|
|
516
525
|
:options="presetOptions"
|
|
526
|
+
size="sm"
|
|
517
527
|
@update:model-value="(v) => width = Number(v)"
|
|
518
528
|
/>
|
|
519
|
-
<label class="ate-editor__width">
|
|
520
|
-
<span>{{ t("editor.custom") }}</span>
|
|
529
|
+
<label class="cn-field ate-editor__width">
|
|
530
|
+
<span class="cn-field__label">{{ t("editor.custom") }}</span>
|
|
521
531
|
<input
|
|
522
532
|
v-model.number="width"
|
|
523
533
|
type="number"
|
|
@@ -636,6 +646,7 @@ const targetLabel = computed(() => (target.value && listAt(target.value.list)?.l
|
|
|
636
646
|
</template>
|
|
637
647
|
</nav>
|
|
638
648
|
<div
|
|
649
|
+
ref="stage"
|
|
639
650
|
class="ate-editor__stage"
|
|
640
651
|
role="region"
|
|
641
652
|
tabindex="0"
|
|
@@ -643,7 +654,7 @@ const targetLabel = computed(() => (target.value && listAt(target.value.list)?.l
|
|
|
643
654
|
>
|
|
644
655
|
<div
|
|
645
656
|
class="ate-editor__viewport"
|
|
646
|
-
:style="{ width: `${width}px
|
|
657
|
+
:style="{ 'width': `${width}px`, '--ate-scale': scale }"
|
|
647
658
|
>
|
|
648
659
|
<iframe
|
|
649
660
|
v-if="src"
|
|
@@ -809,8 +820,8 @@ const targetLabel = computed(() => (target.value && listAt(target.value.list)?.l
|
|
|
809
820
|
class="ate-editor__reuse"
|
|
810
821
|
>
|
|
811
822
|
<summary>{{ t("editor.reuse") }}</summary>
|
|
812
|
-
<label class="
|
|
813
|
-
<span>{{ t("editor.reuseTitle") }}</span>
|
|
823
|
+
<label class="cn-field">
|
|
824
|
+
<span class="cn-field__label">{{ t("editor.reuseTitle") }}</span>
|
|
814
825
|
<input
|
|
815
826
|
v-model="reuseTitle"
|
|
816
827
|
class="cn-input cn-input--size-sm"
|
package/dist/runtime/editor.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.ate-editor{display:grid;gap:var(--space-3);grid-template-rows:auto auto 1fr;min-block-size:80vh}.ate-editor__bar{align-items:end;display:flex;flex-wrap:wrap;gap:var(--space-2)}.ate-editor__width
|
|
1
|
+
.ate-editor{--ate-scale:1;display:grid;gap:var(--space-3);grid-template-rows:auto auto 1fr;min-block-size:80vh}.ate-editor__bar{align-items:end;display:flex;flex-wrap:wrap;gap:var(--space-2)}.ate-editor__width input{inline-size:6rem}.ate-editor__body{display:grid;gap:var(--space-3);grid-template-columns:minmax(12rem,16rem) 1fr minmax(16rem,22rem);min-block-size:0}.ate-editor__panel,.ate-editor__structure{max-block-size:80vh;overflow:auto}.ate-editor__stage{background:var(--surface-sunken,transparent);border-radius:var(--radius-md);overflow:hidden}.ate-editor__viewport{block-size:calc(80vh/var(--ate-scale));margin-block-end:calc(80vh - 80vh/var(--ate-scale));margin-inline:auto;max-inline-size:none;position:relative;transform:scale(var(--ate-scale));transform-origin:0 0}.ate-editor__frame{background:#fff;block-size:100%;border:0;display:block;inline-size:100%}.ate-editor__overlay{inset:0;overflow:hidden;pointer-events:none;position:absolute}.ate-editor__box{border-radius:2px;box-sizing:border-box;position:absolute}.ate-editor__box--hover{--ate-line:calc(2px/var(--ate-scale));outline:var(--ate-line) dashed var(--accent-primary-base);outline-offset:calc(var(--ate-line)*-1)}.ate-editor__box--selected{--ate-line:calc(2px/var(--ate-scale));outline:var(--ate-line) solid var(--accent-primary-strong);outline-offset:calc(var(--ate-line)*-1)}.ate-editor__tag{background:var(--accent-primary-strong);color:var(--content-on-accent);cursor:grab;font-size:.75rem;inset-block-end:100%;inset-inline-start:-2px;line-height:1.5;padding:0 .4em;position:absolute;transform:scale(calc(1/var(--ate-scale)));transform-origin:0 100%}.ate-editor__overlay--dropping,.ate-editor__tag{pointer-events:auto}.ate-editor__drop{background:var(--accent-primary-strong);block-size:calc(3px/var(--ate-scale));border-radius:2px;margin-block-start:calc(-1px/var(--ate-scale));position:absolute}.ate-editor__box--top .ate-editor__tag{inset-block:0 auto;inset-inline-start:0;transform-origin:0 0}.ate-editor__tabs [aria-pressed=true]{background:var(--accent-primary-soft);color:var(--content-primary)}.ate-editor__markers{inset:0;overflow:hidden;pointer-events:none;position:absolute}.ate-editor__marker{background:var(--accent-secondary-strong);block-size:1.5rem;border:0;border-radius:.75rem .75rem .75rem .15rem;color:var(--content-on-accent);cursor:pointer;font:inherit;font-size:.75rem;font-weight:600;margin:2px;min-inline-size:1.5rem;padding:0 .35em;pointer-events:auto;position:absolute;transform:scale(calc(1/var(--ate-scale))) translate(-.25rem,-.25rem);transform-origin:0 0}.ate-editor__marker:focus-visible{outline:2px solid var(--accent-primary-strong);outline-offset:2px}.ate-editor__panel [data-highlighted]{outline:2px solid var(--accent-primary-strong)}.ate-editor__reuse{display:grid;gap:var(--space-2);margin-block:var(--space-2)}.ate-editor__reuse>summary{color:var(--content-secondary);cursor:pointer}.ate-tree{list-style:none;margin:0;padding:0}.ate-tree__block{background:transparent;border:0;border-radius:var(--radius-sm);color:var(--content-primary);cursor:pointer;display:block;font:inherit;inline-size:100%;padding-block:var(--space-1);padding-inline-end:var(--space-2);text-align:start}.ate-tree__block[aria-pressed=true]{background:var(--accent-primary-soft)}.ate-tree__block:hover,.ate-tree__block[data-hovered]{background:var(--accent-primary-subtle)}.ate-tree__block:focus-visible{outline:2px solid var(--accent-primary-strong);outline-offset:-2px}.ate-tree__item[data-drop-before]>.ate-tree__block{box-shadow:inset 0 2px 0 var(--accent-primary-strong)}.ate-tree__item[data-drop-after]>.ate-tree__block{box-shadow:inset 0 -2px 0 var(--accent-primary-strong)}.ate-tree__empty{border:1px dashed var(--border-default,currentColor);border-radius:var(--radius-sm);color:var(--content-secondary);font-size:.85em;padding-block:var(--space-1)}.ate-tree__empty[data-drop-before]{border-color:var(--accent-primary-strong)}.ate-palette{display:flex;flex-wrap:wrap;gap:var(--space-1);list-style:none;margin:var(--space-1) 0 0;padding:0}.ate-palette__block{background:var(--surface-raised,transparent);border:1px solid var(--border-default,currentColor);border-radius:var(--radius-sm);color:var(--content-primary);cursor:grab;font:inherit;font-size:.85em;padding:var(--space-1) var(--space-2)}.ate-palette__block:disabled{cursor:not-allowed;opacity:.5}.ate-palette__block:focus-visible{outline:2px solid var(--accent-primary-strong);outline-offset:1px}.ate-tree__area{color:var(--content-secondary);font-size:.75rem;letter-spacing:.04em;margin:var(--space-1) 0 0;text-transform:uppercase}@media (max-width:64rem){.ate-editor__body{grid-template-columns:1fr}}
|
package/dist/runtime/tree.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AreaRules, BlockSchema } from '#atelier/shared/blocks';
|
|
2
|
+
export { newBlock } from '#atelier/shared/blocks';
|
|
2
3
|
export interface Block {
|
|
3
4
|
id: string;
|
|
4
5
|
type: string;
|
|
@@ -53,6 +54,3 @@ export declare function duplicate<T>(data: T, lists: BlockList[], registry: Regi
|
|
|
53
54
|
data: T;
|
|
54
55
|
id: string;
|
|
55
56
|
} | undefined;
|
|
56
|
-
/** A new block of `type`: its fields' and options' defaults, and empty areas. */
|
|
57
|
-
export declare function newBlock(type: string, registry: Registry): Block;
|
|
58
|
-
export {};
|
package/dist/runtime/tree.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { copyBlocks } from "#atelier/shared/blocks";
|
|
2
2
|
import { placeable } from "#atelier/shared/fields";
|
|
3
|
+
export { newBlock } from "#atelier/shared/blocks";
|
|
3
4
|
const isBlock = (x) => !!x && typeof x === "object" && typeof x.id === "string" && typeof x.type === "string";
|
|
4
5
|
function list(path, label, rules, value, registry) {
|
|
5
6
|
const blocks = (Array.isArray(value) ? value : []).filter(isBlock).map((block, i) => {
|
|
@@ -71,13 +72,3 @@ export function duplicate(data, lists, registry, id) {
|
|
|
71
72
|
const [copy] = copyBlocks([get(data, at.block.path)]);
|
|
72
73
|
return { data: insert(data, at.list.path, at.index + 1, copy), id: copy.id };
|
|
73
74
|
}
|
|
74
|
-
export function newBlock(type, registry) {
|
|
75
|
-
const schema = registry[type];
|
|
76
|
-
const props = {};
|
|
77
|
-
for (const [key, field] of Object.entries({ ...schema?.fields, ...schema?.options }))
|
|
78
|
-
if (field.default !== void 0)
|
|
79
|
-
props[key] = structuredClone(field.default);
|
|
80
|
-
for (const area of Object.keys(schema?.areas ?? {}))
|
|
81
|
-
props[area] = [];
|
|
82
|
-
return { id: crypto.randomUUID(), type, props };
|
|
83
|
-
}
|