okno 1.0.0-beta.37 → 1.0.0-beta.39
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/astro/index.d.ts +13 -0
- package/dist/astro/index.d.ts.map +1 -0
- package/dist/astro/index.js +15 -0
- package/dist/codegen/generate.d.ts.map +1 -1
- package/dist/codegen/modules.d.ts.map +1 -1
- package/dist/dispatch-BifB_3GO.js +955 -0
- package/dist/editor/index.js +16807 -15811
- package/dist/index.js +1 -1
- package/dist/init.d.ts +24 -4
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +167 -147
- package/dist/local/dispatch.d.ts.map +1 -1
- package/dist/next/index.js +1 -1
- package/dist/{plugin-CPb37kty.js → plugin-BdiBIiAv.js} +167 -139
- package/dist/runtime/wrap.d.ts +23 -0
- package/dist/runtime/wrap.d.ts.map +1 -1
- package/dist/runtime/wrap.js +344 -226
- package/dist/types/schema.d.ts +23 -12
- package/dist/types/schema.d.ts.map +1 -1
- package/dist/vite/index.js +1 -1
- package/dist/vite/plugin.d.ts.map +1 -1
- package/package.json +5 -1
- package/src/runtime/wrap.ts +288 -33
- package/dist/dispatch-dIjAypRM.js +0 -934
package/dist/types/schema.d.ts
CHANGED
|
@@ -19,19 +19,22 @@ export interface CollectionDef {
|
|
|
19
19
|
* items prepend, so the default reads newest-first. Maintained by the editor
|
|
20
20
|
* (drag-to-reorder, create, delete); drives `okno:collections` iteration. */
|
|
21
21
|
order?: string[];
|
|
22
|
-
/**
|
|
23
|
-
* the editor toggles, and items with
|
|
24
|
-
* `okno:collections` at build (so
|
|
25
|
-
*
|
|
26
|
-
*
|
|
22
|
+
/** Draft workflow. ON by default — set `false` to opt OUT. Items carry a
|
|
23
|
+
* `status` ("draft" | "live") the editor toggles, and items with
|
|
24
|
+
* `status: "draft"` are EXCLUDED from `okno:collections` at build (so
|
|
25
|
+
* references to them resolve to nothing too). A missing status counts as live,
|
|
26
|
+
* so nothing disappears from an existing collection. `false` → the collection
|
|
27
|
+
* has no status concept at all. Orthogonal to git publish: a draft item still
|
|
28
|
+
* lives in the repo, it just isn't served. */
|
|
27
29
|
drafts?: boolean;
|
|
28
|
-
/**
|
|
29
|
-
* `unpublishAt` ISO timestamps the editor sets, and an item
|
|
30
|
-
* `okno:collections` at build while `publishAt` is in the
|
|
31
|
-
* `unpublishAt` has passed (evaluated at build time — a rebuild past
|
|
32
|
-
* boundary reveals/retires it; the backend scheduler fires that rebuild).
|
|
33
|
-
*
|
|
34
|
-
*
|
|
30
|
+
/** Scheduled publishing. ON by default — set `false` to opt OUT. Items may carry
|
|
31
|
+
* `publishAt` and/or `unpublishAt` ISO timestamps the editor sets, and an item
|
|
32
|
+
* is EXCLUDED from `okno:collections` at build while `publishAt` is in the
|
|
33
|
+
* future or `unpublishAt` has passed (evaluated at build time — a rebuild past
|
|
34
|
+
* the boundary reveals/retires it; the backend scheduler fires that rebuild).
|
|
35
|
+
* Items with neither timestamp are always visible, so nothing disappears from an
|
|
36
|
+
* existing collection. Same filter point as `drafts`, so hidden items also
|
|
37
|
+
* vanish from references. Orthogonal to `drafts` (an item can be both) and to
|
|
35
38
|
* git publish (a scheduled item still lives in the repo, just isn't served). */
|
|
36
39
|
scheduling?: boolean;
|
|
37
40
|
/** Route pattern for this collection's items, with field-key tokens — e.g.
|
|
@@ -145,6 +148,14 @@ export interface OknoConfig {
|
|
|
145
148
|
apiUrl?: string;
|
|
146
149
|
/** Whether this is the editor build (disables HMR on content changes) */
|
|
147
150
|
isEditor?: boolean;
|
|
151
|
+
/** Force the prebuilt editor bundle even when the editor SOURCE is present
|
|
152
|
+
* next to it (i.e. okno symlinked from its monorepo via `bun link`). Without
|
|
153
|
+
* this, `vite dev` serves the editor's raw Svelte for HMR — which needs the
|
|
154
|
+
* consumer's Vite to compile Svelte + resolve the editor's deps. A plain
|
|
155
|
+
* consumer app (e.g. Astro without `@astrojs/svelte`) can't, so it sets this
|
|
156
|
+
* to load `dist/editor` instead. Rebuild okno (`bun run build:pkg`) to pick up
|
|
157
|
+
* editor changes. No-op for a normal `npm install` (no source present). */
|
|
158
|
+
builtEditor?: boolean;
|
|
148
159
|
/** Public demo mode: the editor boots login-less, reads content from a
|
|
149
160
|
* static `okno-demo.json` snapshot, and no-ops every write (nothing is
|
|
150
161
|
* persisted; a reload resets). For showcasing okno on a marketing site —
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/types/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEtD,iEAAiE;AACjE,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;AAE7C,iDAAiD;AACjD,MAAM,WAAW,OAAO;IACvB,8EAA8E;IAC9E,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;+EAC2E;IAC3E,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACd;AAED,gEAAgE;AAChE,MAAM,WAAW,aAAa;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;;kFAI8E;IAC9E,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/types/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEtD,iEAAiE;AACjE,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;AAE7C,iDAAiD;AACjD,MAAM,WAAW,OAAO;IACvB,8EAA8E;IAC9E,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;+EAC2E;IAC3E,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACd;AAED,gEAAgE;AAChE,MAAM,WA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iCAAiC;IACjC,OAAO,CAAC,EAAE;QACT,2CAA2C;QAC3C,OAAO,EAAE,MAAM,CAAA;QACf,uDAAuD;QACvD,SAAS,EAAE,MAAM,EAAE,CAAA;KACnB,CAAA;CACD"}
|
package/dist/vite/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/vite/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AA8DpD,wBAAgB,IAAI,CAAC,MAAM,GAAE,UAAe,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/vite/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AA8DpD,wBAAgB,IAAI,CAAC,MAAM,GAAE,UAAe,GAAG,MAAM,CAqbpD"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "okno",
|
|
3
3
|
"description": "Git-backed CMS with live editing for any Vite framework",
|
|
4
4
|
"author": "Gabriel Uhlíř",
|
|
5
|
-
"version": "1.0.0-beta.
|
|
5
|
+
"version": "1.0.0-beta.39",
|
|
6
6
|
"homepage": "https://okno.build",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
@@ -20,6 +20,10 @@
|
|
|
20
20
|
"types": "./dist/vite/index.d.ts",
|
|
21
21
|
"default": "./dist/vite/index.js"
|
|
22
22
|
},
|
|
23
|
+
"./astro": {
|
|
24
|
+
"types": "./dist/astro/index.d.ts",
|
|
25
|
+
"default": "./dist/astro/index.js"
|
|
26
|
+
},
|
|
23
27
|
"./next": {
|
|
24
28
|
"types": "./dist/next/index.d.ts",
|
|
25
29
|
"default": "./dist/next/index.js"
|
package/src/runtime/wrap.ts
CHANGED
|
@@ -36,6 +36,55 @@ export function __oknoSetImages(map: Record<string, unknown>): void {
|
|
|
36
36
|
if (map && typeof map === "object") imageMap = map
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Collection name → route pattern (`references` → `/ref/[slug]`), lifted from
|
|
41
|
+
* the schema by each content module. Powers a collection item's `.href`, so the
|
|
42
|
+
* route you declare once in the entry's settings is the one every template
|
|
43
|
+
* reads — instead of the same string hand-written at every link site. Empty
|
|
44
|
+
* until a content module registers it; collections without a pattern are absent.
|
|
45
|
+
*/
|
|
46
|
+
let routeMap: Record<string, string> = {}
|
|
47
|
+
|
|
48
|
+
/** Register the collection route patterns from the project schema (idempotent —
|
|
49
|
+
* every content module passes the same schema). */
|
|
50
|
+
export function __oknoSetRoutes(schema: unknown): void {
|
|
51
|
+
const colls = (schema as { collections?: Record<string, { url?: unknown }> } | null)?.collections
|
|
52
|
+
if (!colls || typeof colls !== "object") return
|
|
53
|
+
const next: Record<string, string> = {}
|
|
54
|
+
for (const [name, def] of Object.entries(colls)) {
|
|
55
|
+
const url = def?.url
|
|
56
|
+
if (typeof url === "string" && url.trim()) next[name] = url.trim()
|
|
57
|
+
}
|
|
58
|
+
routeMap = next
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Resolve a collection item's route from its pattern. Each `[token]` names a
|
|
63
|
+
* FIELD on the item — usually `slug`, but `/blog/[category]/[slug]` pulls the
|
|
64
|
+
* `category` field too. At runtime a reference field is already hydrated into
|
|
65
|
+
* the linked item's object, so an object token value contributes its `.slug`
|
|
66
|
+
* (the editor's `resolveItemUrl` sees the raw slug string instead — same
|
|
67
|
+
* result). Returns "" when a token has no value, mirroring an unset link's
|
|
68
|
+
* `.href` rather than emitting a half-built path.
|
|
69
|
+
*/
|
|
70
|
+
function resolveRoute(pattern: string, raw: Record<string, unknown>): string {
|
|
71
|
+
const parts: string[] = []
|
|
72
|
+
for (const seg of pattern.split("/")) {
|
|
73
|
+
if (!seg) continue
|
|
74
|
+
const token = seg.match(/^\[(.+)\]$/)?.[1]
|
|
75
|
+
if (!token) {
|
|
76
|
+
parts.push(seg)
|
|
77
|
+
continue
|
|
78
|
+
}
|
|
79
|
+
let v: unknown = raw[token]
|
|
80
|
+
if (Array.isArray(v)) v = v[0]
|
|
81
|
+
if (v && typeof v === "object") v = (v as { slug?: unknown }).slug
|
|
82
|
+
if (v === null || v === undefined || v === "") return ""
|
|
83
|
+
parts.push(String(v))
|
|
84
|
+
}
|
|
85
|
+
return "/" + parts.join("/")
|
|
86
|
+
}
|
|
87
|
+
|
|
39
88
|
/**
|
|
40
89
|
* Scheduled-publishing visibility gate. An item is visible unless its
|
|
41
90
|
* `publishAt` is still in the future or its `unpublishAt` has already passed.
|
|
@@ -476,6 +525,17 @@ export function __oknoWrap(data: unknown, prefix: string, drag?: string): any {
|
|
|
476
525
|
// named "exists" is shadowed by this — rename it if you hit that.)
|
|
477
526
|
if (prop === "exists") return target.__raw !== null && target.__raw !== undefined
|
|
478
527
|
|
|
528
|
+
// `.value` — the RAW, correctly-typed primitive (string / number / boolean),
|
|
529
|
+
// for the few spots that need a real string and won't coerce a wrapper: a
|
|
530
|
+
// typed `<meta content={x.value}>` / `href`, `new URL(x.value)`, a
|
|
531
|
+
// `title?: string` prop. `{x}` in markup already renders fine — this is only
|
|
532
|
+
// for typed-string slots. Mirrors a signal's `.value` (Vue/Solid) and okno's
|
|
533
|
+
// own enum `{name, value}`. Primitive leaves ONLY: an object raw (block /
|
|
534
|
+
// enum / media) falls through to normal field access, so a content field
|
|
535
|
+
// literally named "value" still resolves. (Reserved key on leaves.)
|
|
536
|
+
if (prop === "value" && (target.__raw === null || typeof target.__raw !== "object"))
|
|
537
|
+
return target.__raw
|
|
538
|
+
|
|
479
539
|
// `.image` — a spreadable bundle for a framework image component
|
|
480
540
|
// (Astro `<Image {...cover.image}>`): `src` is the build-optimized asset
|
|
481
541
|
// resolved from `okno/files` (via the injected glob), plus alt/dimensions
|
|
@@ -495,6 +555,26 @@ export function __oknoWrap(data: unknown, prefix: string, drag?: string): any {
|
|
|
495
555
|
}
|
|
496
556
|
}
|
|
497
557
|
|
|
558
|
+
// `.href` — a collection ITEM's own route, resolved from the pattern set on
|
|
559
|
+
// the collection (`/ref/[slug]` → `/ref/my-project`). Lets a template link to
|
|
560
|
+
// an item without hand-writing the path at every link site: the route is
|
|
561
|
+
// declared once in the entry's settings and read everywhere. Returns a
|
|
562
|
+
// string, matching `.href` on a link value — `<a href={ref.href}>`.
|
|
563
|
+
//
|
|
564
|
+
// Only fires for an ITEM proxy: a path of exactly `<collection>.<slug>` whose
|
|
565
|
+
// collection has a pattern. A resolved reference is wrapped at that same
|
|
566
|
+
// shape, so `ref.category.href` works too. An item carrying its own `href`
|
|
567
|
+
// FIELD keeps it — reserved keys never shadow real content (same rule as
|
|
568
|
+
// `.image`). A patternless collection yields "", like an unset link.
|
|
569
|
+
if (prop === "href" && !isLinkObject(target.__raw) && !isMediaObject(target.__raw)) {
|
|
570
|
+
const raw = target.__raw
|
|
571
|
+
const parts = target.__path.split(".")
|
|
572
|
+
if (raw && typeof raw === "object" && !Array.isArray(raw) && !("href" in raw) && parts.length === 2) {
|
|
573
|
+
const pattern = routeMap[parts[0]!]
|
|
574
|
+
if (pattern) return resolveRoute(pattern, raw as Record<string, unknown>)
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
498
578
|
// String coercion for template rendering: {value}
|
|
499
579
|
if (
|
|
500
580
|
prop === Symbol.toPrimitive ||
|
|
@@ -921,14 +1001,26 @@ export interface OknoStructureDetail {
|
|
|
921
1001
|
* item's text leaves (so a new reference shows the linked item's content;
|
|
922
1002
|
* block defaults are empty so the clone is just cleared). */
|
|
923
1003
|
values?: Record<string, string>
|
|
1004
|
+
/** insert (references only): re-point the clone's links from the TEMPLATE
|
|
1005
|
+
* item's route to the new item's. A card usually links to the item it renders
|
|
1006
|
+
* (`<a href={`/ref/${ref.slug}`}>`), but that href is a plain template
|
|
1007
|
+
* expression — okno never sees it as a field, so the clone would keep pointing
|
|
1008
|
+
* at the neighbour it was cloned from. The editor resolves both routes from
|
|
1009
|
+
* the collection's `url` pattern. */
|
|
1010
|
+
href?: { from: string; to: string }
|
|
924
1011
|
}
|
|
925
1012
|
|
|
926
1013
|
const ITEM_ATTR = "data-okno-item"
|
|
927
1014
|
const CONTENT_ATTR = "data-okno"
|
|
928
1015
|
const PREFIX_ATTRS = [CONTENT_ATTR, ITEM_ATTR]
|
|
929
1016
|
|
|
930
|
-
/**
|
|
931
|
-
|
|
1017
|
+
/** Escape a list path for embedding in a `data-okno(-item)` matcher regex. */
|
|
1018
|
+
export function escapeReg(s: string): string {
|
|
1019
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
/** A render location: one parent element holding the reorder UNITS of the list
|
|
1023
|
+
* (the siblings that get moved/added/removed), sorted by array index. */
|
|
932
1024
|
interface ItemGroup {
|
|
933
1025
|
parent: Element
|
|
934
1026
|
wrappers: HTMLElement[]
|
|
@@ -960,33 +1052,106 @@ function rewritePrefix(
|
|
|
960
1052
|
for (const attr of attrs) el.querySelectorAll(`[${attr}]`).forEach(apply)
|
|
961
1053
|
}
|
|
962
1054
|
|
|
963
|
-
/**
|
|
964
|
-
*
|
|
965
|
-
*
|
|
966
|
-
*
|
|
967
|
-
function
|
|
1055
|
+
/** Every direct-member boundary of `list` in the document (`<list>.<integer>`,
|
|
1056
|
+
* no deeper segment). Skips an inner duplicate when an ancestor already carries
|
|
1057
|
+
* the same boundary (the `.drag`-on-wrapper + inner `{...item}` case — outermost
|
|
1058
|
+
* wins), so one array member is never counted twice. */
|
|
1059
|
+
function listBoundaries(list: string): HTMLElement[] {
|
|
968
1060
|
if (typeof document === "undefined") return []
|
|
969
|
-
const re = new RegExp(`^${list
|
|
970
|
-
const
|
|
971
|
-
|
|
1061
|
+
const re = new RegExp(`^${escapeReg(list)}\\.(\\d+)$`)
|
|
1062
|
+
const items: HTMLElement[] = []
|
|
1063
|
+
// Prefix-narrowed selector: the browser filters to this list's members instead
|
|
1064
|
+
// of JS regex-testing every marker on the page (this runs on hover in the
|
|
1065
|
+
// editor's grip logic). The regex then only rejects deeper-nested paths.
|
|
1066
|
+
const quoted = list.replace(/["\\]/g, "\\$&")
|
|
1067
|
+
document.querySelectorAll(`[${ITEM_ATTR}^="${quoted}."]`).forEach((el) => {
|
|
972
1068
|
const attr = el.getAttribute(ITEM_ATTR)
|
|
973
1069
|
if (!attr || !re.test(attr) || !el.parentElement || !(el instanceof HTMLElement)) return
|
|
974
|
-
// Outermost wins: the `.drag` escape hatch puts the SAME boundary on a semantic
|
|
975
|
-
// wrapper AND its inner `{...item}` child. Skip the inner duplicate (an ancestor
|
|
976
|
-
// already carries this exact `data-okno-item`), so the op runs once, on the
|
|
977
|
-
// wrapper — not twice, which would double-move/insert/remove the row.
|
|
978
1070
|
if (el.parentElement.closest(`[${ITEM_ATTR}]`)?.getAttribute(ITEM_ATTR) === attr) return
|
|
979
|
-
|
|
980
|
-
arr.push(el)
|
|
981
|
-
byParent.set(el.parentElement, arr)
|
|
1071
|
+
items.push(el)
|
|
982
1072
|
})
|
|
983
|
-
|
|
984
|
-
|
|
1073
|
+
return items
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
/** Climb a boundary to its REORDER UNIT.
|
|
1077
|
+
*
|
|
1078
|
+
* The `data-okno-item` boundary is emitted wherever the dev spreads `{...item}`
|
|
1079
|
+
* / `{...item.drag}` — which may be a semantic element nested inside the element
|
|
1080
|
+
* the map actually repeats (e.g. a card inside the `w-dyn-item` wrapper Webflow
|
|
1081
|
+
* generates). That inner element isn't a sibling of the other items, so treating
|
|
1082
|
+
* it as the unit splits the list into singletons: a silent no-op on reorder, a
|
|
1083
|
+
* clone-into-every-row on insert, and a grip that only appears on item 0. The
|
|
1084
|
+
* unit is the outermost ancestor that still contains only this one item — we
|
|
1085
|
+
* stop as soon as the parent would pull in a second, because that parent is the
|
|
1086
|
+
* shared list container and the child we're on is the sibling to reorder. With a
|
|
1087
|
+
* single item there's no sibling signal (and no reorder anyway), so the boundary
|
|
1088
|
+
* is used as-is. */
|
|
1089
|
+
function unitOfBoundary(items: HTMLElement[], el: HTMLElement): HTMLElement {
|
|
1090
|
+
if (items.length < 2) return el
|
|
1091
|
+
const countIn = (n: Element) => items.reduce((c, it) => c + (n === it || n.contains(it) ? 1 : 0), 0)
|
|
1092
|
+
let unit = el
|
|
1093
|
+
while (unit.parentElement && countIn(unit.parentElement) === countIn(unit)) unit = unit.parentElement
|
|
1094
|
+
return unit
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
/** The reorder unit for an element that is (or sits inside/around) a member of
|
|
1098
|
+
* `list`. Exported so the editor's grip logic groups by the SAME unit the
|
|
1099
|
+
* structural ops move — otherwise the grip and the move disagree. */
|
|
1100
|
+
export function __oknoUnitOf(list: string, member: Element): HTMLElement | null {
|
|
1101
|
+
if (!(member instanceof HTMLElement)) return null
|
|
1102
|
+
const items = listBoundaries(list)
|
|
1103
|
+
const boundary =
|
|
1104
|
+
items.find((it) => it === member) ??
|
|
1105
|
+
items.find((it) => it.contains(member) || member.contains(it))
|
|
1106
|
+
if (!boundary) return null
|
|
1107
|
+
return unitOfBoundary(items, boundary)
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
/** The array index a unit carries — read from the unit itself when it holds the
|
|
1111
|
+
* marker, otherwise from the boundary nested inside it. Null when the element
|
|
1112
|
+
* isn't a member of `list` at all (so it can double as a membership test). */
|
|
1113
|
+
export function __oknoUnitIndex(list: string, unit: Element): number | null {
|
|
1114
|
+
const re = new RegExp(`^${escapeReg(list)}\\.(\\d+)$`)
|
|
1115
|
+
const self = unit.getAttribute(ITEM_ATTR)?.match(re)
|
|
1116
|
+
if (self) return Number(self[1])
|
|
1117
|
+
for (const el of Array.from(unit.querySelectorAll(`[${ITEM_ATTR}]`))) {
|
|
1118
|
+
const m = el.getAttribute(ITEM_ATTR)?.match(re)
|
|
1119
|
+
if (m) return Number(m[1])
|
|
1120
|
+
}
|
|
1121
|
+
return null
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
/** Collect the render locations of a list: each unit grouped by its parent (so
|
|
1125
|
+
* every render location — header + footer … — clusters on its own container),
|
|
1126
|
+
* sorted by array index. */
|
|
1127
|
+
function collectGroups(list: string): ItemGroup[] {
|
|
1128
|
+
const items = listBoundaries(list)
|
|
1129
|
+
if (items.length === 0) return []
|
|
1130
|
+
const seen = new Set<HTMLElement>()
|
|
1131
|
+
const byParent = new Map<Element, { unit: HTMLElement; index: number }[]>()
|
|
1132
|
+
for (const item of items) {
|
|
1133
|
+
const unit = unitOfBoundary(items, item)
|
|
1134
|
+
if (seen.has(unit) || !unit.parentElement) continue
|
|
1135
|
+
seen.add(unit)
|
|
1136
|
+
const index = __oknoUnitIndex(list, item)
|
|
1137
|
+
if (index == null) continue
|
|
1138
|
+
const arr = byParent.get(unit.parentElement) ?? []
|
|
1139
|
+
arr.push({ unit, index })
|
|
1140
|
+
byParent.set(unit.parentElement, arr)
|
|
1141
|
+
}
|
|
1142
|
+
return [...byParent.entries()].map(([parent, entries]) => ({
|
|
985
1143
|
parent,
|
|
986
|
-
wrappers:
|
|
1144
|
+
wrappers: entries.sort((a, b) => a.index - b.index).map((e) => e.unit),
|
|
987
1145
|
}))
|
|
988
1146
|
}
|
|
989
1147
|
|
|
1148
|
+
/** The `data-okno-item` value carried by a reorder unit — used to read a unit's
|
|
1149
|
+
* CURRENT array prefix before renumbering it. */
|
|
1150
|
+
function boundaryPrefix(unit: HTMLElement, list: string): string {
|
|
1151
|
+
const i = __oknoUnitIndex(list, unit)
|
|
1152
|
+
return `${list}.${i ?? 0}`
|
|
1153
|
+
}
|
|
1154
|
+
|
|
990
1155
|
/** Every `data-okno` content leaf in a cloned item, INCLUDING the root element
|
|
991
1156
|
* itself. `querySelectorAll` only matches descendants, but for a primitive item
|
|
992
1157
|
* the item-boundary element IS the content leaf (`<span {...item} data-okno>
|
|
@@ -1016,11 +1181,56 @@ function clearLeaves(root: Element): void {
|
|
|
1016
1181
|
}
|
|
1017
1182
|
}
|
|
1018
1183
|
|
|
1019
|
-
/** Fill a cloned item's
|
|
1184
|
+
/** Fill a cloned item's leaves from absolute-path → value pairs, and CLEAR any
|
|
1185
|
+
* leaf the map doesn't cover — so a fresh clone shows the linked item's real
|
|
1186
|
+
* content (title, cover image, a referenced item's title) and never the
|
|
1187
|
+
* neighbour it was cloned from. Text leaves get `textContent`; media leaves
|
|
1188
|
+
* (`<img>`/`<video>`/`<source>`) get their `src`; a link leaf with no value is
|
|
1189
|
+
* emptied like `clearLeaves`. Leaves with element children (richtext) are left
|
|
1190
|
+
* as-is (best-effort; they settle on the next save+reload). */
|
|
1020
1191
|
function fillLeaves(root: Element, values: Record<string, string>): void {
|
|
1021
1192
|
for (const el of contentLeaves(root)) {
|
|
1193
|
+
if (el.children.length > 0) continue
|
|
1022
1194
|
const path = el.getAttribute(CONTENT_ATTR)
|
|
1023
|
-
|
|
1195
|
+
const has = path != null && path in values
|
|
1196
|
+
const tag = el.tagName
|
|
1197
|
+
if (tag === "IMG" || tag === "VIDEO" || tag === "SOURCE") {
|
|
1198
|
+
el.setAttribute("src", has ? (values[path!] ?? "") : "")
|
|
1199
|
+
continue
|
|
1200
|
+
}
|
|
1201
|
+
if (tag === "A" && !has) {
|
|
1202
|
+
el.textContent = ""
|
|
1203
|
+
el.setAttribute("href", "")
|
|
1204
|
+
el.removeAttribute("target")
|
|
1205
|
+
el.removeAttribute("rel")
|
|
1206
|
+
continue
|
|
1207
|
+
}
|
|
1208
|
+
el.textContent = has ? (values[path!] ?? "") : ""
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
/** Re-point a cloned item's links from the template item's route to the new
|
|
1213
|
+
* item's. Matches on the resolved PATH (so relative, root-relative and absolute
|
|
1214
|
+
* same-origin hrefs all work) and preserves any query/hash. A trailing slash is
|
|
1215
|
+
* ignored on both sides; cross-origin links are never touched. */
|
|
1216
|
+
function remapHrefs(root: Element, from: string, to: string): void {
|
|
1217
|
+
if (!from || !to || from === to || typeof document === "undefined") return
|
|
1218
|
+
const trim = (p: string) => (p.length > 1 && p.endsWith("/") ? p.slice(0, -1) : p)
|
|
1219
|
+
const target = trim(from)
|
|
1220
|
+
const anchors = Array.from(root.querySelectorAll("a[href]"))
|
|
1221
|
+
if (root.matches("a[href]")) anchors.unshift(root)
|
|
1222
|
+
for (const a of anchors) {
|
|
1223
|
+
const raw = a.getAttribute("href")
|
|
1224
|
+
if (!raw) continue
|
|
1225
|
+
let u: URL
|
|
1226
|
+
try {
|
|
1227
|
+
u = new URL(raw, document.baseURI)
|
|
1228
|
+
} catch {
|
|
1229
|
+
continue
|
|
1230
|
+
}
|
|
1231
|
+
if (u.origin !== new URL(document.baseURI).origin) continue
|
|
1232
|
+
if (trim(u.pathname) !== target) continue
|
|
1233
|
+
a.setAttribute("href", to + u.search + u.hash)
|
|
1024
1234
|
}
|
|
1025
1235
|
}
|
|
1026
1236
|
|
|
@@ -1082,14 +1292,16 @@ export function __oknoApplyStructure(detail: OknoStructureDetail): void {
|
|
|
1082
1292
|
const docEl = document.documentElement
|
|
1083
1293
|
docEl.classList.add("okno-vt-active")
|
|
1084
1294
|
|
|
1085
|
-
//
|
|
1086
|
-
//
|
|
1087
|
-
//
|
|
1088
|
-
//
|
|
1089
|
-
//
|
|
1090
|
-
//
|
|
1091
|
-
//
|
|
1092
|
-
//
|
|
1295
|
+
// Lift the editor into its OWN snapshot group, painted above the moving items.
|
|
1296
|
+
// Unnamed it rides the `root` group, and every named group paints above root —
|
|
1297
|
+
// so reordering a list from inside the editor sent the moving rows over the top
|
|
1298
|
+
// of the window you dragged them in. The earlier attempt at this DID snapshot
|
|
1299
|
+
// empty, because the host is a 0-height `relative` box (its UI is `fixed` inside
|
|
1300
|
+
// the shadow root) — the fix is to give it a real viewport box for the capture,
|
|
1301
|
+
// exactly as `boot.ts` does for cross-document navigation. Transient + inline,
|
|
1302
|
+
// restored the moment the transition settles.
|
|
1303
|
+
const unpin = pinEditorForCapture()
|
|
1304
|
+
|
|
1093
1305
|
const mutate = () => {
|
|
1094
1306
|
for (const g of groups) {
|
|
1095
1307
|
if (op === "reorder") applyReorder(g, list, detail.from!, detail.to!)
|
|
@@ -1100,10 +1312,51 @@ export function __oknoApplyStructure(detail: OknoStructureDetail): void {
|
|
|
1100
1312
|
|
|
1101
1313
|
withTransition(mutate).finally(() => {
|
|
1102
1314
|
for (const w of tagged) w.style.viewTransitionName = ""
|
|
1315
|
+
unpin()
|
|
1103
1316
|
docEl.classList.remove("okno-vt-active")
|
|
1104
1317
|
})
|
|
1105
1318
|
}
|
|
1106
1319
|
|
|
1320
|
+
/** Editor host id — the shadow host that carries the whole editor UI. */
|
|
1321
|
+
const SHELL_ID = "okno-shadow-root"
|
|
1322
|
+
|
|
1323
|
+
/**
|
|
1324
|
+
* Give the editor host a real viewport box + its own `view-transition-name`
|
|
1325
|
+
* (`okno-editor`) for the duration of a structural transition, so it captures as
|
|
1326
|
+
* a group of its own instead of riding `root` underneath the moving items. The
|
|
1327
|
+
* group is held still and pushed above them by `:root.okno-vt-active` rules in
|
|
1328
|
+
* the editor's global CSS.
|
|
1329
|
+
*
|
|
1330
|
+
* `pointer-events:none` for the same reason as in `boot.ts`: a viewport-sized
|
|
1331
|
+
* host must not start swallowing clicks meant for the page. Returns the undo.
|
|
1332
|
+
*/
|
|
1333
|
+
function pinEditorForCapture(): () => void {
|
|
1334
|
+
const host = document.getElementById(SHELL_ID)
|
|
1335
|
+
if (!(host instanceof HTMLElement)) return () => {}
|
|
1336
|
+
const prev = host.style.cssText
|
|
1337
|
+
// `height:auto` is not optional: the host ships `height:0` (it must contribute
|
|
1338
|
+
// no page-flow height), and `inset:0` does NOT beat an explicit height — the box
|
|
1339
|
+
// stays 0px tall, the group captures nothing, and the guard below throws the fix
|
|
1340
|
+
// away. This is exactly what "snapshots EMPTY" meant the first time round.
|
|
1341
|
+
host.style.cssText = `${prev};position:fixed;inset:0;height:auto;pointer-events:none;view-transition-name:okno-editor`
|
|
1342
|
+
// A named group that captures an EMPTY box takes the editor off screen for the
|
|
1343
|
+
// whole transition — the exact regression this replaced. If the box didn't take
|
|
1344
|
+
// (a browser that lays the host out differently), drop the name and fall back to
|
|
1345
|
+
// the old behaviour: editor under the moving items, but visible.
|
|
1346
|
+
const r = host.getBoundingClientRect()
|
|
1347
|
+
// Readable from the console (`window.__oknoVtPin`) — tells you whether the
|
|
1348
|
+
// editor rode its own group for the last structural transition or fell back.
|
|
1349
|
+
;(globalThis as Record<string, unknown>).__oknoVtPin =
|
|
1350
|
+
r.width < 1 || r.height < 1 ? `fallback (${Math.round(r.width)}×${Math.round(r.height)})` : "ok"
|
|
1351
|
+
if (r.width < 1 || r.height < 1) {
|
|
1352
|
+
host.style.cssText = prev
|
|
1353
|
+
return () => {}
|
|
1354
|
+
}
|
|
1355
|
+
return () => {
|
|
1356
|
+
host.style.cssText = prev
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1107
1360
|
function applyReorder(g: ItemGroup, list: string, from: number, to: number): void {
|
|
1108
1361
|
const w = g.wrappers
|
|
1109
1362
|
const n = w.length
|
|
@@ -1111,8 +1364,9 @@ function applyReorder(g: ItemGroup, list: string, from: number, to: number): voi
|
|
|
1111
1364
|
const order = w.slice()
|
|
1112
1365
|
const [moved] = order.splice(from, 1)
|
|
1113
1366
|
order.splice(to, 0, moved!)
|
|
1114
|
-
// Capture current prefixes, then renumber each
|
|
1115
|
-
|
|
1367
|
+
// Capture current prefixes, then renumber each unit to its new index. Read the
|
|
1368
|
+
// prefix off the boundary (unit, or the nested element carrying the marker).
|
|
1369
|
+
const olds = order.map((el) => boundaryPrefix(el, list))
|
|
1116
1370
|
order.forEach((el, i) => rewritePrefix(el, olds[i]!, `${list}.${i}`))
|
|
1117
1371
|
// Reinsert in the new order, anchored to whatever followed the list (so the
|
|
1118
1372
|
// block keeps its place relative to surrounding, non-item siblings).
|
|
@@ -1141,7 +1395,7 @@ function applyInsert(
|
|
|
1141
1395
|
// Clone the item nearest the insertion point as a template (capture its
|
|
1142
1396
|
// prefix BEFORE we renumber the live siblings).
|
|
1143
1397
|
const tplIdx = at < n ? at : n - 1
|
|
1144
|
-
const tplPrefix = w[tplIdx]
|
|
1398
|
+
const tplPrefix = boundaryPrefix(w[tplIdx]!, list)
|
|
1145
1399
|
const clone = w[tplIdx]!.cloneNode(true) as HTMLElement
|
|
1146
1400
|
|
|
1147
1401
|
// Shift existing members at/after the insertion point up by one (descending
|
|
@@ -1151,6 +1405,7 @@ function applyInsert(
|
|
|
1151
1405
|
// Point the clone at the new index, then (references) remap its content paths.
|
|
1152
1406
|
rewritePrefix(clone, tplPrefix, `${list}.${at}`)
|
|
1153
1407
|
if (detail.remap) rewritePrefix(clone, detail.remap.from, detail.remap.to, [CONTENT_ATTR])
|
|
1408
|
+
if (detail.href) remapHrefs(clone, detail.href.from, detail.href.to)
|
|
1154
1409
|
|
|
1155
1410
|
if (detail.values) fillLeaves(clone, detail.values)
|
|
1156
1411
|
else clearLeaves(clone)
|