@sixb/core 0.2.3 → 0.2.5
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/actions/index.js +28 -28
- package/dist/agents/cancel.d.ts +1 -1
- package/dist/agents/cancel.d.ts.map +1 -1
- package/dist/agents/child-question.d.ts +35 -2
- package/dist/agents/child-question.d.ts.map +1 -1
- package/dist/agents/execution.d.ts +35 -3
- package/dist/agents/execution.d.ts.map +1 -1
- package/dist/agents/ids.d.ts +4 -0
- package/dist/agents/ids.d.ts.map +1 -1
- package/dist/agents/index.d.ts +9 -7
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +59 -33
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/model-loop.d.ts.map +1 -1
- package/dist/agents/queued-turn.d.ts +16 -0
- package/dist/agents/queued-turn.d.ts.map +1 -0
- package/dist/agents/request.d.ts +79 -1
- package/dist/agents/request.d.ts.map +1 -1
- package/dist/agents/run-after-finish.d.ts +10 -0
- package/dist/agents/run-after-finish.d.ts.map +1 -1
- package/dist/agents/run-artifacts.d.ts +0 -38
- package/dist/agents/run-artifacts.d.ts.map +1 -1
- package/dist/agents/run-events.d.ts +6 -1
- package/dist/agents/run-events.d.ts.map +1 -1
- package/dist/agents/run-session-children.d.ts +9 -0
- package/dist/agents/run-session-children.d.ts.map +1 -1
- package/dist/agents/run-session-http.d.ts.map +1 -1
- package/dist/agents/run-session-serve.d.ts.map +1 -1
- package/dist/agents/run-session.d.ts +14 -1
- package/dist/agents/run-session.d.ts.map +1 -1
- package/dist/agents/run-turn.d.ts.map +1 -1
- package/dist/agents/streams/index.d.ts +1 -1
- package/dist/agents/streams/index.d.ts.map +1 -1
- package/dist/agents/streams/index.js +1 -1
- package/dist/agents/streams/internal.js +1 -1
- package/dist/agents/streams/protocol.d.ts +16 -0
- package/dist/agents/streams/protocol.d.ts.map +1 -1
- package/dist/agents/tool-files.d.ts +1 -1
- package/dist/agents/tool-files.d.ts.map +1 -1
- package/dist/agents/tool-input-coercion.d.ts +20 -0
- package/dist/agents/tool-input-coercion.d.ts.map +1 -0
- package/dist/agents/turn-answered.d.ts +7 -0
- package/dist/agents/turn-answered.d.ts.map +1 -0
- package/dist/agents/validation.d.ts +1 -1
- package/dist/agents/validation.d.ts.map +1 -1
- package/dist/artifacts/canvas-display.d.ts +3 -5
- package/dist/artifacts/canvas-display.d.ts.map +1 -1
- package/dist/artifacts/comments.d.ts +14 -3
- package/dist/artifacts/comments.d.ts.map +1 -1
- package/dist/artifacts/document-fill.d.ts +18 -0
- package/dist/artifacts/document-fill.d.ts.map +1 -0
- package/dist/artifacts/errors.d.ts +1 -1
- package/dist/artifacts/errors.d.ts.map +1 -1
- package/dist/artifacts/events.d.ts +3 -2
- package/dist/artifacts/events.d.ts.map +1 -1
- package/dist/artifacts/execution.d.ts +40 -4
- package/dist/artifacts/execution.d.ts.map +1 -1
- package/dist/artifacts/frames/assets.d.ts +8 -1
- package/dist/artifacts/frames/assets.d.ts.map +1 -1
- package/dist/artifacts/frames/document-data.d.ts +98 -0
- package/dist/artifacts/frames/document-data.d.ts.map +1 -0
- package/dist/artifacts/frames/entries.d.ts +12 -7
- package/dist/artifacts/frames/entries.d.ts.map +1 -1
- package/dist/artifacts/frames/index.d.ts +2 -1
- package/dist/artifacts/frames/index.d.ts.map +1 -1
- package/dist/artifacts/frames/index.js +22 -13
- package/dist/artifacts/frames/index.js.map +4 -4
- package/dist/artifacts/frames/kit.d.ts +15 -0
- package/dist/artifacts/frames/kit.d.ts.map +1 -1
- package/dist/artifacts/frames/protocol.d.ts +65 -3
- package/dist/artifacts/frames/protocol.d.ts.map +1 -1
- package/dist/artifacts/frames/runtime.d.ts +32 -5
- package/dist/artifacts/frames/runtime.d.ts.map +1 -1
- package/dist/artifacts/index.d.ts +4 -2
- package/dist/artifacts/index.d.ts.map +1 -1
- package/dist/artifacts/index.js +35 -3
- package/dist/artifacts/index.js.map +3 -3
- package/dist/artifacts/live/blocks.d.ts +62 -0
- package/dist/artifacts/live/blocks.d.ts.map +1 -0
- package/dist/artifacts/live/board.d.ts +6 -0
- package/dist/artifacts/live/board.d.ts.map +1 -1
- package/dist/artifacts/live/document.d.ts +12 -0
- package/dist/artifacts/live/document.d.ts.map +1 -1
- package/dist/artifacts/live/index.d.ts +2 -0
- package/dist/artifacts/live/index.d.ts.map +1 -1
- package/dist/artifacts/live/index.js +148 -44
- package/dist/artifacts/live/index.js.map +3 -3
- package/dist/artifacts/live/page.d.ts +49 -0
- package/dist/artifacts/live/page.d.ts.map +1 -0
- package/dist/artifacts/live/protocol.d.ts +5 -0
- package/dist/artifacts/live/protocol.d.ts.map +1 -1
- package/dist/artifacts/live/server.d.ts +2 -2
- package/dist/artifacts/live/server.d.ts.map +1 -1
- package/dist/artifacts/live/server.js +23 -19
- package/dist/artifacts/live/server.js.map +1 -1
- package/dist/artifacts/live/state.d.ts +4 -1
- package/dist/artifacts/live/state.d.ts.map +1 -1
- package/dist/artifacts/outline.d.ts +16 -0
- package/dist/artifacts/outline.d.ts.map +1 -1
- package/dist/artifacts/paper.d.ts +22 -0
- package/dist/artifacts/paper.d.ts.map +1 -0
- package/dist/artifacts/pdf-job.d.ts +9 -0
- package/dist/artifacts/pdf-job.d.ts.map +1 -0
- package/dist/artifacts/publish/fields.d.ts +25 -0
- package/dist/artifacts/publish/fields.d.ts.map +1 -0
- package/dist/artifacts/publish/index.d.ts +2 -1
- package/dist/artifacts/publish/index.d.ts.map +1 -1
- package/dist/artifacts/publish/index.js +26 -18
- package/dist/artifacts/publish/index.js.map +1 -1
- package/dist/artifacts/publish/merge.d.ts +5 -5
- package/dist/artifacts/publish/merge.d.ts.map +1 -1
- package/dist/artifacts/publish/pdf.d.ts +28 -0
- package/dist/artifacts/publish/pdf.d.ts.map +1 -0
- package/dist/artifacts/publish/previews.d.ts +12 -20
- package/dist/artifacts/publish/previews.d.ts.map +1 -1
- package/dist/artifacts/publish/publish.d.ts.map +1 -1
- package/dist/artifacts/publish/queries.d.ts +6 -1
- package/dist/artifacts/publish/queries.d.ts.map +1 -1
- package/dist/artifacts/publish/query-answers.d.ts +5 -2
- package/dist/artifacts/publish/query-answers.d.ts.map +1 -1
- package/dist/artifacts/publish/validate/document-html.d.ts +24 -0
- package/dist/artifacts/publish/validate/document-html.d.ts.map +1 -0
- package/dist/artifacts/publish/validate/document.d.ts +5 -3
- package/dist/artifacts/publish/validate/document.d.ts.map +1 -1
- package/dist/artifacts/queries.d.ts +16 -2
- package/dist/artifacts/queries.d.ts.map +1 -1
- package/dist/auth/index.js +2 -2
- package/dist/authorization/event-visibility.d.ts.map +1 -1
- package/dist/authorization/index.js +1 -1
- package/dist/blob-storage/index.js +1 -1
- package/dist/bootstrap/index.js +38 -38
- package/dist/{chunk-tqa68kj7.js → chunk-0hkdtwqk.js} +5 -5
- package/dist/{chunk-s5n9617r.js → chunk-0mvjpgvm.js} +5 -5
- package/dist/{chunk-k66rp2hr.js → chunk-1yh6jgtz.js} +1 -1
- package/dist/{chunk-26qet7wh.js → chunk-5t9gm5tt.js} +4 -4
- package/dist/{chunk-a6fjkcne.js → chunk-60662fyv.js} +54 -28
- package/dist/{chunk-a6fjkcne.js.map → chunk-60662fyv.js.map} +7 -6
- package/dist/{chunk-e0hnbb1m.js → chunk-61zptves.js} +1 -1
- package/dist/{chunk-hkaa807g.js → chunk-68hm50qh.js} +3 -3
- package/dist/{chunk-9nsjjd44.js → chunk-8tv3qd65.js} +2 -1
- package/dist/chunk-8tv3qd65.js.map +12 -0
- package/dist/{chunk-fe6r7yhg.js → chunk-92wrka15.js} +1 -1
- package/dist/{chunk-m7b9q5dk.js → chunk-aw1z0gre.js} +4 -4
- package/dist/chunk-az95tsh3.js.map +2 -2
- package/dist/{chunk-4j0sagwv.js → chunk-b4escq4c.js} +62 -14
- package/dist/{chunk-4j0sagwv.js.map → chunk-b4escq4c.js.map} +7 -7
- package/dist/chunk-bqr703h4.js +1799 -0
- package/dist/chunk-bqr703h4.js.map +13 -0
- package/dist/{chunk-eptrvnby.js → chunk-c29729me.js} +42 -3
- package/dist/chunk-c29729me.js.map +12 -0
- package/dist/{chunk-t24yktqr.js → chunk-dvgc56n2.js} +20 -4
- package/dist/{chunk-t24yktqr.js.map → chunk-dvgc56n2.js.map} +5 -5
- package/dist/{chunk-3014rfjz.js → chunk-ewqn51gr.js} +25 -7
- package/dist/{chunk-3014rfjz.js.map → chunk-ewqn51gr.js.map} +3 -3
- package/dist/{chunk-7z5rkf0m.js → chunk-ey1p8w68.js} +175 -5
- package/dist/chunk-ey1p8w68.js.map +13 -0
- package/dist/{chunk-z0t4p2sk.js → chunk-fpf57gca.js} +350 -61
- package/dist/chunk-fpf57gca.js.map +47 -0
- package/dist/{chunk-kv0kvknv.js → chunk-fzae1jpq.js} +7 -7
- package/dist/{chunk-b9qfh2ya.js → chunk-fzbhybya.js} +29 -2
- package/dist/chunk-fzbhybya.js.map +11 -0
- package/dist/{chunk-2by73sm2.js → chunk-gjhrz66x.js} +225 -17
- package/dist/{chunk-2by73sm2.js.map → chunk-gjhrz66x.js.map} +5 -5
- package/dist/chunk-hn2r7z41.js.map +1 -1
- package/dist/{chunk-6gtxshcc.js → chunk-k29n4176.js} +6 -6
- package/dist/{chunk-48c1z8nj.js → chunk-k3jh8gsg.js} +10 -2
- package/dist/chunk-k3jh8gsg.js.map +10 -0
- package/dist/{chunk-w9s23r24.js → chunk-m3qx2pns.js} +751 -93
- package/dist/chunk-m3qx2pns.js.map +34 -0
- package/dist/{chunk-smnt672s.js → chunk-m9ketb51.js} +20 -4
- package/dist/chunk-m9ketb51.js.map +10 -0
- package/dist/chunk-mbwsgjn7.js +40 -0
- package/dist/chunk-mbwsgjn7.js.map +11 -0
- package/dist/{chunk-sysnvjce.js → chunk-naxjka9v.js} +2 -2
- package/dist/{chunk-n4zzaf6q.js → chunk-nxysqbt0.js} +4 -2
- package/dist/chunk-nxysqbt0.js.map +10 -0
- package/dist/{chunk-vzkxqf8h.js → chunk-paxabbqd.js} +49 -5
- package/dist/chunk-paxabbqd.js.map +23 -0
- package/dist/{chunk-8tqnsx3q.js → chunk-pc7kra3k.js} +5 -3
- package/dist/{chunk-8tqnsx3q.js.map → chunk-pc7kra3k.js.map} +3 -3
- package/dist/{chunk-qafng88v.js → chunk-pqvvqc65.js} +4 -4
- package/dist/chunk-pvpq483h.js.map +2 -2
- package/dist/{chunk-mzx71snp.js → chunk-q7g9cqwt.js} +7 -2
- package/dist/{chunk-mzx71snp.js.map → chunk-q7g9cqwt.js.map} +3 -3
- package/dist/{chunk-8t2ynwg0.js → chunk-q8d9p0tb.js} +24 -1
- package/dist/{chunk-8t2ynwg0.js.map → chunk-q8d9p0tb.js.map} +3 -3
- package/dist/{chunk-wa05txmk.js → chunk-qavwr628.js} +49 -5
- package/dist/chunk-qavwr628.js.map +12 -0
- package/dist/{chunk-bkmnd7zq.js → chunk-rg725hry.js} +174 -30
- package/dist/{chunk-bkmnd7zq.js.map → chunk-rg725hry.js.map} +9 -8
- package/dist/{chunk-8p7bze4c.js → chunk-s1mqyqmm.js} +3 -3
- package/dist/{chunk-p351afzm.js → chunk-s5pj68fa.js} +2 -2
- package/dist/{chunk-855w9nvw.js → chunk-vehcr9eb.js} +1 -1
- package/dist/{chunk-qds484t8.js → chunk-vs2s3p8n.js} +932 -21
- package/dist/chunk-vs2s3p8n.js.map +20 -0
- package/dist/chunk-vtjzwymr.js.map +2 -2
- package/dist/{chunk-n68vz95m.js → chunk-wqe9shx2.js} +1 -1
- package/dist/{chunk-0k3r5kb3.js → chunk-xcrnrpfh.js} +1 -1
- package/dist/{chunk-cwdzcv37.js → chunk-xrmbhap8.js} +2 -2
- package/dist/{chunk-cwdzcv37.js.map → chunk-xrmbhap8.js.map} +2 -2
- package/dist/{chunk-f6ahf5gf.js → chunk-xxfj0rr2.js} +20 -5
- package/dist/chunk-xxfj0rr2.js.map +13 -0
- package/dist/{chunk-3hzhcfsv.js → chunk-y8fwm3z2.js} +2 -2
- package/dist/{chunk-3hzhcfsv.js.map → chunk-y8fwm3z2.js.map} +3 -3
- package/dist/{chunk-e9w4mgdh.js → chunk-z1njfqqs.js} +589 -53
- package/dist/{chunk-e9w4mgdh.js.map → chunk-z1njfqqs.js.map} +14 -11
- package/dist/{chunk-yv8hv4wq.js → chunk-z4jqb44a.js} +3 -1
- package/dist/chunk-z4jqb44a.js.map +10 -0
- package/dist/{chunk-s7xqfxs9.js → chunk-zft9bzbc.js} +2 -1
- package/dist/{chunk-s7xqfxs9.js.map → chunk-zft9bzbc.js.map} +3 -3
- package/dist/{chunk-38yvdqzd.js → chunk-zxhym8tr.js} +1 -1
- package/dist/connectors/connection-handles.d.ts +9 -0
- package/dist/connectors/connection-handles.d.ts.map +1 -0
- package/dist/connectors/connections/authorizations.d.ts +9 -0
- package/dist/connectors/connections/authorizations.d.ts.map +1 -1
- package/dist/connectors/connections/events.d.ts +17 -0
- package/dist/connectors/connections/events.d.ts.map +1 -0
- package/dist/connectors/connections/runs.d.ts +3 -0
- package/dist/connectors/connections/runs.d.ts.map +1 -1
- package/dist/connectors/connections/service.d.ts +4 -0
- package/dist/connectors/connections/service.d.ts.map +1 -1
- package/dist/connectors/execution.d.ts +7 -1
- package/dist/connectors/execution.d.ts.map +1 -1
- package/dist/connectors/index.d.ts +1 -1
- package/dist/connectors/index.d.ts.map +1 -1
- package/dist/connectors/types.d.ts +22 -1
- package/dist/connectors/types.d.ts.map +1 -1
- package/dist/datasets/write.js +1 -1
- package/dist/deploy/index.d.ts +1 -1
- package/dist/deploy/index.d.ts.map +1 -1
- package/dist/deploy/internal.js +3 -2
- package/dist/deploy/internal.js.map +3 -3
- package/dist/deploy/services.d.ts.map +1 -1
- package/dist/deploy/types.d.ts +18 -1
- package/dist/deploy/types.d.ts.map +1 -1
- package/dist/events/definitions.d.ts +4 -0
- package/dist/events/definitions.d.ts.map +1 -1
- package/dist/events/execution.d.ts.map +1 -1
- package/dist/events/index.d.ts +2 -2
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +3 -3
- package/dist/events/outbox-dispatcher.d.ts +7 -0
- package/dist/events/outbox-dispatcher.d.ts.map +1 -1
- package/dist/events/scope.d.ts +1 -0
- package/dist/events/scope.d.ts.map +1 -1
- package/dist/events/scope.js +1 -1
- package/dist/events/selectors/builder.d.ts +9 -1
- package/dist/events/selectors/builder.d.ts.map +1 -1
- package/dist/events/selectors/index.d.ts +2 -2
- package/dist/events/selectors/index.d.ts.map +1 -1
- package/dist/events/selectors/index.js +2 -2
- package/dist/events/selectors/predicate.d.ts.map +1 -1
- package/dist/events/selectors/types.d.ts +18 -3
- package/dist/events/selectors/types.d.ts.map +1 -1
- package/dist/events/types/artifacts.d.ts +7 -1
- package/dist/events/types/artifacts.d.ts.map +1 -1
- package/dist/events/types/connectors.d.ts +32 -0
- package/dist/events/types/connectors.d.ts.map +1 -0
- package/dist/events/types/index.d.ts +3 -1
- package/dist/events/types/index.d.ts.map +1 -1
- package/dist/execution/agent.js +28 -28
- package/dist/execution/authorization.d.ts +5 -0
- package/dist/execution/authorization.d.ts.map +1 -1
- package/dist/execution/primitive.js +28 -28
- package/dist/execution/request.js +29 -29
- package/dist/execution/scopes.d.ts +8 -0
- package/dist/execution/scopes.d.ts.map +1 -1
- package/dist/execution/script.d.ts +7 -0
- package/dist/execution/script.d.ts.map +1 -0
- package/dist/execution/types.d.ts +16 -1
- package/dist/execution/types.d.ts.map +1 -1
- package/dist/http/api-routes.d.ts.map +1 -1
- package/dist/http/index.js +1 -1
- package/dist/index.d.ts +9 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +46 -44
- package/dist/index.js.map +1 -1
- package/dist/lake-storage/index.js +1 -1
- package/dist/lineage/executors.d.ts +1 -1
- package/dist/lineage/executors.d.ts.map +1 -1
- package/dist/maintenance/index.js +1 -1
- package/dist/materialization/event-envelopes.d.ts +3 -3
- package/dist/materialization/event-envelopes.d.ts.map +1 -1
- package/dist/materialization/events.d.ts +6 -0
- package/dist/materialization/events.d.ts.map +1 -1
- package/dist/materialization/index.js +1 -1
- package/dist/materialization/model.d.ts +6 -0
- package/dist/materialization/model.d.ts.map +1 -1
- package/dist/materializer/index.js +13 -13
- package/dist/materializer/projections/replace.d.ts.map +1 -1
- package/dist/materializer/projections/replacement-plan.d.ts +2 -0
- package/dist/materializer/projections/replacement-plan.d.ts.map +1 -1
- package/dist/materializer/shared/normalize.d.ts +1 -0
- package/dist/materializer/shared/normalize.d.ts.map +1 -1
- package/dist/models/execution/index.js +12 -12
- package/dist/models/language-model.d.ts +6 -0
- package/dist/models/language-model.d.ts.map +1 -1
- package/dist/models/tools.d.ts +2 -0
- package/dist/models/tools.d.ts.map +1 -1
- package/dist/objects/index.js +28 -28
- package/dist/objects/query/index.js +12 -12
- package/dist/pipelines/index.js +18 -18
- package/dist/projections/builders.d.ts +7 -1
- package/dist/projections/builders.d.ts.map +1 -1
- package/dist/projections/index.d.ts +1 -1
- package/dist/projections/index.d.ts.map +1 -1
- package/dist/projections/internal.js +13 -13
- package/dist/projections/types.d.ts +10 -0
- package/dist/projections/types.d.ts.map +1 -1
- package/dist/projections/validation.d.ts.map +1 -1
- package/dist/queues/in-memory.d.ts +2 -1
- package/dist/queues/in-memory.d.ts.map +1 -1
- package/dist/queues/index.d.ts +1 -1
- package/dist/queues/index.d.ts.map +1 -1
- package/dist/queues/index.js +1 -1
- package/dist/queues/types.d.ts +40 -13
- package/dist/queues/types.d.ts.map +1 -1
- package/dist/runtime/host.d.ts +13 -0
- package/dist/runtime/host.d.ts.map +1 -1
- package/dist/runtime/internal.d.ts +1 -0
- package/dist/runtime/internal.d.ts.map +1 -1
- package/dist/runtime/internal.js +39 -18
- package/dist/runtime/internal.js.map +4 -3
- package/dist/runtime/resolve-definitions.d.ts +1 -1
- package/dist/runtime/resolve-definitions.d.ts.map +1 -1
- package/dist/runtime/script.d.ts +39 -0
- package/dist/runtime/script.d.ts.map +1 -0
- package/dist/runtime/sixb.d.ts +2 -2
- package/dist/runtime/sixb.d.ts.map +1 -1
- package/dist/schedules/builders.d.ts.map +1 -1
- package/dist/schedules/index.js +3 -3
- package/dist/schedules/runtime.d.ts.map +1 -1
- package/dist/schedules/validation.d.ts +2 -0
- package/dist/schedules/validation.d.ts.map +1 -1
- package/dist/shares/internal.js +12 -12
- package/dist/storage/agents/errors.d.ts +1 -1
- package/dist/storage/agents/errors.d.ts.map +1 -1
- package/dist/storage/agents/in-memory.d.ts +26 -1
- package/dist/storage/agents/in-memory.d.ts.map +1 -1
- package/dist/storage/agents/index.d.ts +2 -2
- package/dist/storage/agents/index.d.ts.map +1 -1
- package/dist/storage/agents/provider.d.ts +12 -3
- package/dist/storage/agents/provider.d.ts.map +1 -1
- package/dist/storage/agents/provider.js +25 -5
- package/dist/storage/agents/provider.js.map +1 -1
- package/dist/storage/agents/types.d.ts +156 -1
- package/dist/storage/agents/types.d.ts.map +1 -1
- package/dist/storage/artifacts/in-memory.d.ts +7 -1
- package/dist/storage/artifacts/in-memory.d.ts.map +1 -1
- package/dist/storage/artifacts/index.d.ts +1 -1
- package/dist/storage/artifacts/index.d.ts.map +1 -1
- package/dist/storage/artifacts/record.d.ts +2 -1
- package/dist/storage/artifacts/record.d.ts.map +1 -1
- package/dist/storage/artifacts/types.d.ts +34 -0
- package/dist/storage/artifacts/types.d.ts.map +1 -1
- package/dist/storage/executions/provider.d.ts +3 -3
- package/dist/storage/executions/provider.d.ts.map +1 -1
- package/dist/storage/executions/provider.js +1 -1
- package/dist/storage/executions/types.d.ts +6 -0
- package/dist/storage/executions/types.d.ts.map +1 -1
- package/dist/storage/executions/validation.d.ts.map +1 -1
- package/dist/storage/file-upload-sessions/provider.js +3 -3
- package/dist/storage/index.d.ts +3 -3
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +18 -14
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/internal.d.ts +1 -1
- package/dist/storage/internal.d.ts.map +1 -1
- package/dist/storage/internal.js +8 -6
- package/dist/storage/internal.js.map +2 -2
- package/dist/storage/ontology/in-memory/replacement-plans.d.ts +2 -0
- package/dist/storage/ontology/in-memory/replacement-plans.d.ts.map +1 -1
- package/dist/storage/ontology/provider.js +1 -1
- package/dist/storage/ontology/replacement-plans.d.ts +8 -0
- package/dist/storage/ontology/replacement-plans.d.ts.map +1 -1
- package/dist/storage/operation-scope.d.ts.map +1 -1
- package/dist/storage/operation-scope.js +1 -1
- package/dist/storage/workflow-runs/provider.js +3 -3
- package/dist/syncs/index.js +19 -19
- package/dist/testing/agent-execution.d.ts +3 -0
- package/dist/testing/agent-execution.d.ts.map +1 -1
- package/dist/testing/agent-inbox-storage-contract.d.ts +15 -0
- package/dist/testing/agent-inbox-storage-contract.d.ts.map +1 -0
- package/dist/testing/agent-storage-contract.d.ts.map +1 -1
- package/dist/testing/artifact-storage-contract.d.ts.map +1 -1
- package/dist/testing/execution-storage-contract.d.ts.map +1 -1
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +5524 -4555
- package/dist/testing/index.js.map +10 -9
- package/dist/testing/materializer-storage-contract.d.ts.map +1 -1
- package/dist/testing/queues-contract.d.ts.map +1 -1
- package/dist/webhooks/connections.d.ts +3 -4
- package/dist/webhooks/connections.d.ts.map +1 -1
- package/dist/webhooks/index.d.ts +1 -1
- package/dist/webhooks/index.d.ts.map +1 -1
- package/dist/webhooks/internal.js +16 -49
- package/dist/webhooks/internal.js.map +3 -3
- package/dist/webhooks/types.d.ts +2 -11
- package/dist/webhooks/types.d.ts.map +1 -1
- package/dist/workers/queued-run-dispatch.d.ts.map +1 -1
- package/dist/workflows/index.js +35 -35
- package/package.json +6 -1
- package/src/agents/README.md +6 -2
- package/src/agents/approval-outcome.ts +2 -2
- package/src/agents/cancel.ts +2 -2
- package/src/agents/child-question.ts +76 -8
- package/src/agents/execution.ts +168 -30
- package/src/agents/ids.ts +9 -1
- package/src/agents/index.ts +27 -6
- package/src/agents/model-loop.ts +3 -1
- package/src/agents/queued-turn.ts +46 -0
- package/src/agents/request.ts +517 -2
- package/src/agents/run-after-finish.ts +259 -2
- package/src/agents/run-artifacts.ts +3 -93
- package/src/agents/run-events.ts +26 -1
- package/src/agents/run-session-children.ts +33 -0
- package/src/agents/run-session-http.ts +10 -2
- package/src/agents/run-session-serve.ts +3 -8
- package/src/agents/run-session.ts +142 -3
- package/src/agents/run-turn.ts +8 -0
- package/src/agents/streams/index.ts +1 -0
- package/src/agents/streams/protocol.ts +41 -1
- package/src/agents/tool-files.ts +1 -1
- package/src/agents/tool-input-coercion.ts +140 -0
- package/src/agents/turn-answered.ts +31 -0
- package/src/agents/validation.ts +13 -3
- package/src/artifacts/canvas-display.ts +4 -6
- package/src/artifacts/comments.ts +70 -17
- package/src/artifacts/document-fill.ts +103 -0
- package/src/artifacts/errors.ts +2 -0
- package/src/artifacts/events.ts +4 -1
- package/src/artifacts/execution.ts +265 -31
- package/src/artifacts/frames/assets.ts +42 -7
- package/src/artifacts/frames/document-data.ts +353 -0
- package/src/artifacts/frames/entries.ts +22 -16
- package/src/artifacts/frames/grants.ts +2 -2
- package/src/artifacts/frames/index.ts +3 -0
- package/src/artifacts/frames/kit.ts +102 -0
- package/src/artifacts/frames/protocol.ts +96 -3
- package/src/artifacts/frames/runtime.ts +709 -19
- package/src/artifacts/index.ts +6 -0
- package/src/artifacts/live/blocks.ts +889 -0
- package/src/artifacts/live/board.ts +195 -42
- package/src/artifacts/live/document.ts +170 -5
- package/src/artifacts/live/index.ts +7 -0
- package/src/artifacts/live/page.ts +807 -0
- package/src/artifacts/live/protocol.ts +5 -0
- package/src/artifacts/live/server.ts +2 -2
- package/src/artifacts/live/state.ts +9 -4
- package/src/artifacts/outline.ts +17 -0
- package/src/artifacts/paper.ts +173 -0
- package/src/artifacts/pdf-job.ts +11 -0
- package/src/artifacts/publish/fields.ts +177 -0
- package/src/artifacts/publish/index.ts +6 -1
- package/src/artifacts/publish/merge.ts +14 -12
- package/src/artifacts/publish/pdf.ts +82 -0
- package/src/artifacts/publish/previews.ts +24 -34
- package/src/artifacts/publish/publish.ts +26 -3
- package/src/artifacts/publish/queries.ts +20 -4
- package/src/artifacts/publish/query-answers.ts +14 -3
- package/src/artifacts/publish/validate/document-html.ts +245 -0
- package/src/artifacts/publish/validate/document.ts +34 -3
- package/src/artifacts/queries.ts +59 -13
- package/src/authorization/event-visibility.ts +13 -0
- package/src/connectors/connection-handles.ts +71 -0
- package/src/connectors/connections/authorizations.ts +50 -2
- package/src/connectors/connections/events.ts +57 -0
- package/src/connectors/connections/runs.ts +5 -0
- package/src/connectors/connections/service.ts +19 -1
- package/src/connectors/execution.ts +30 -2
- package/src/connectors/index.ts +3 -0
- package/src/connectors/types.ts +29 -1
- package/src/deploy/index.ts +1 -0
- package/src/deploy/services.ts +1 -0
- package/src/deploy/types.ts +26 -1
- package/src/events/definitions.ts +14 -0
- package/src/events/execution.ts +9 -2
- package/src/events/index.ts +8 -0
- package/src/events/outbox-dispatcher.ts +12 -2
- package/src/events/scope.ts +3 -0
- package/src/events/selectors/builder.ts +49 -0
- package/src/events/selectors/index.ts +5 -0
- package/src/events/selectors/predicate.ts +2 -0
- package/src/events/selectors/types.ts +30 -1
- package/src/events/types/artifacts.ts +7 -1
- package/src/events/types/connectors.ts +36 -0
- package/src/events/types/index.ts +7 -0
- package/src/execution/authorization.ts +45 -0
- package/src/execution/durable.ts +2 -0
- package/src/execution/scopes.ts +24 -0
- package/src/execution/script.ts +27 -0
- package/src/execution/types.ts +7 -1
- package/src/http/api-routes.ts +26 -1
- package/src/index.ts +21 -2
- package/src/lineage/executors.ts +3 -1
- package/src/materialization/event-envelopes.ts +10 -5
- package/src/materialization/events.ts +2 -0
- package/src/materialization/model.ts +6 -0
- package/src/materializer/README.md +10 -0
- package/src/materializer/projections/replace.ts +42 -1
- package/src/materializer/projections/replacement-plan.ts +44 -4
- package/src/materializer/shared/normalize.ts +4 -0
- package/src/models/language-model.ts +6 -0
- package/src/models/tools.ts +2 -0
- package/src/projections/builders.ts +20 -0
- package/src/projections/index.ts +1 -0
- package/src/projections/registry.ts +1 -0
- package/src/projections/revision.ts +2 -0
- package/src/projections/types.ts +11 -0
- package/src/projections/validation.ts +6 -0
- package/src/queues/in-memory.ts +5 -0
- package/src/queues/index.ts +3 -1
- package/src/queues/types.ts +45 -14
- package/src/runtime/host.ts +112 -4
- package/src/runtime/internal.ts +1 -0
- package/src/runtime/resolve-definitions.ts +4 -1
- package/src/runtime/script.ts +62 -0
- package/src/runtime/sixb.ts +3 -3
- package/src/schedules/builders.ts +4 -1
- package/src/schedules/runtime.ts +3 -0
- package/src/schedules/validation.ts +20 -2
- package/src/storage/agents/errors.ts +1 -0
- package/src/storage/agents/in-memory.ts +229 -1
- package/src/storage/agents/index.ts +16 -0
- package/src/storage/agents/provider.ts +284 -2
- package/src/storage/agents/types.ts +168 -1
- package/src/storage/artifacts/in-memory.ts +32 -1
- package/src/storage/artifacts/index.ts +2 -0
- package/src/storage/artifacts/record.ts +25 -2
- package/src/storage/artifacts/types.ts +37 -0
- package/src/storage/executions/provider.ts +22 -2
- package/src/storage/executions/types.ts +2 -0
- package/src/storage/executions/validation.ts +27 -0
- package/src/storage/index.ts +18 -0
- package/src/storage/internal.ts +1 -0
- package/src/storage/ontology/in-memory/replacement-plans.ts +22 -0
- package/src/storage/ontology/replacement-plans.ts +6 -0
- package/src/storage/operation-scope.ts +1 -0
- package/src/testing/agent-execution.ts +45 -2
- package/src/testing/agent-inbox-storage-contract.ts +815 -0
- package/src/testing/agent-storage-contract.ts +103 -0
- package/src/testing/artifact-storage-contract.ts +72 -4
- package/src/testing/execution-storage-contract.ts +31 -0
- package/src/testing/index.ts +5 -0
- package/src/testing/materializer-storage-contract.ts +139 -1
- package/src/testing/queues-contract.ts +22 -0
- package/src/webhooks/connections.ts +9 -50
- package/src/webhooks/index.ts +0 -2
- package/src/webhooks/types.ts +2 -13
- package/src/workers/queued-run-dispatch.ts +8 -1
- package/dist/chunk-48c1z8nj.js.map +0 -10
- package/dist/chunk-58geavnf.js +0 -29
- package/dist/chunk-58geavnf.js.map +0 -10
- package/dist/chunk-7z5rkf0m.js.map +0 -13
- package/dist/chunk-9nsjjd44.js.map +0 -12
- package/dist/chunk-b9qfh2ya.js.map +0 -11
- package/dist/chunk-eptrvnby.js.map +0 -12
- package/dist/chunk-f6ahf5gf.js.map +0 -13
- package/dist/chunk-m2jerfef.js +0 -474
- package/dist/chunk-m2jerfef.js.map +0 -11
- package/dist/chunk-n4zzaf6q.js.map +0 -10
- package/dist/chunk-qds484t8.js.map +0 -18
- package/dist/chunk-smnt672s.js.map +0 -10
- package/dist/chunk-vzkxqf8h.js.map +0 -23
- package/dist/chunk-w9s23r24.js.map +0 -30
- package/dist/chunk-wa05txmk.js.map +0 -11
- package/dist/chunk-yv8hv4wq.js.map +0 -10
- package/dist/chunk-z0t4p2sk.js.map +0 -47
- /package/dist/{chunk-tqa68kj7.js.map → chunk-0hkdtwqk.js.map} +0 -0
- /package/dist/{chunk-s5n9617r.js.map → chunk-0mvjpgvm.js.map} +0 -0
- /package/dist/{chunk-k66rp2hr.js.map → chunk-1yh6jgtz.js.map} +0 -0
- /package/dist/{chunk-26qet7wh.js.map → chunk-5t9gm5tt.js.map} +0 -0
- /package/dist/{chunk-e0hnbb1m.js.map → chunk-61zptves.js.map} +0 -0
- /package/dist/{chunk-hkaa807g.js.map → chunk-68hm50qh.js.map} +0 -0
- /package/dist/{chunk-fe6r7yhg.js.map → chunk-92wrka15.js.map} +0 -0
- /package/dist/{chunk-m7b9q5dk.js.map → chunk-aw1z0gre.js.map} +0 -0
- /package/dist/{chunk-kv0kvknv.js.map → chunk-fzae1jpq.js.map} +0 -0
- /package/dist/{chunk-6gtxshcc.js.map → chunk-k29n4176.js.map} +0 -0
- /package/dist/{chunk-sysnvjce.js.map → chunk-naxjka9v.js.map} +0 -0
- /package/dist/{chunk-qafng88v.js.map → chunk-pqvvqc65.js.map} +0 -0
- /package/dist/{chunk-8p7bze4c.js.map → chunk-s1mqyqmm.js.map} +0 -0
- /package/dist/{chunk-p351afzm.js.map → chunk-s5pj68fa.js.map} +0 -0
- /package/dist/{chunk-855w9nvw.js.map → chunk-vehcr9eb.js.map} +0 -0
- /package/dist/{chunk-n68vz95m.js.map → chunk-wqe9shx2.js.map} +0 -0
- /package/dist/{chunk-0k3r5kb3.js.map → chunk-xcrnrpfh.js.map} +0 -0
- /package/dist/{chunk-38yvdqzd.js.map → chunk-zxhym8tr.js.map} +0 -0
|
@@ -0,0 +1,807 @@
|
|
|
1
|
+
import { type DefaultTreeAdapterTypes, defaultTreeAdapter, parse, parseFragment } from "parse5"
|
|
2
|
+
import * as Y from "yjs"
|
|
3
|
+
import {
|
|
4
|
+
type BlockMark,
|
|
5
|
+
type BlockNode,
|
|
6
|
+
blocksFromY,
|
|
7
|
+
blocksToY,
|
|
8
|
+
mergeBlockLists,
|
|
9
|
+
patchBlocks,
|
|
10
|
+
} from "./blocks"
|
|
11
|
+
import { mergeText } from "./diff"
|
|
12
|
+
|
|
13
|
+
// A designed document's page as blocks, which its editor edits in the document's frame: its
|
|
14
|
+
// `<body>` as a tree of the elements it is made of, each kept as its source wrote it, so that
|
|
15
|
+
// writing the blocks back gives the source again, byte for byte, until someone changes one.
|
|
16
|
+
//
|
|
17
|
+
// doc ─ box{tag, open, close, before, end} an element holding blocks: <section>, <ul>
|
|
18
|
+
// textBlock{tag, open, close, before, inner} an element holding words: <p>, <h2>, <li>
|
|
19
|
+
// image{source, before} an <img> among blocks
|
|
20
|
+
// raw{source, before} anything else, kept as it was
|
|
21
|
+
// inline ─ text · hardBreak{source} · rawInline{source}
|
|
22
|
+
// marks ─ one per inline tag (a, span, strong, em…){open, close}
|
|
23
|
+
//
|
|
24
|
+
// `open` and `close` are the element's tags as the source wrote them (`close` is empty where the
|
|
25
|
+
// end tag is implied), `before` the whitespace before it, `end` the whitespace before a box's end
|
|
26
|
+
// tag. A text's words are spaced as they show, each run of whitespace one space; `inner` keeps
|
|
27
|
+
// them as the source wrote them, and is written back for as long as they read the same.
|
|
28
|
+
//
|
|
29
|
+
// Whatever does not fit, words beside blocks, a field of live data, a list repeated per item, an
|
|
30
|
+
// element whose markup the parser mended, is a `raw` block or a `rawInline` written back as it
|
|
31
|
+
// was: editors move, copy and delete it, but not into it. Each element is written back and
|
|
32
|
+
// compared with its source as it is read; one that does not come back the same is read as raw, so
|
|
33
|
+
// what is not changed is never rewritten.
|
|
34
|
+
//
|
|
35
|
+
// The page is held live as `{ head, body, tail }` (`pageEntry`): what comes before the body's
|
|
36
|
+
// first block, the blocks as a `Y.XmlFragment`, and what follows its last.
|
|
37
|
+
|
|
38
|
+
type Node = DefaultTreeAdapterTypes.Node
|
|
39
|
+
type Element = DefaultTreeAdapterTypes.Element
|
|
40
|
+
type ChildNode = DefaultTreeAdapterTypes.ChildNode
|
|
41
|
+
|
|
42
|
+
/** A page as its editor holds it. */
|
|
43
|
+
export interface PageBlocks {
|
|
44
|
+
/** The source up to the body's first block: the head and the `<body>` tag. */
|
|
45
|
+
readonly head: string
|
|
46
|
+
readonly blocks: readonly BlockNode[]
|
|
47
|
+
/** The source after the body's last block. */
|
|
48
|
+
readonly tail: string
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The inline tags a text's words are formatted by, each a mark, outermost first: a link holds
|
|
53
|
+
* whatever formats its words.
|
|
54
|
+
*/
|
|
55
|
+
export const PAGE_MARK_TAGS = [
|
|
56
|
+
"a",
|
|
57
|
+
"span",
|
|
58
|
+
"strong",
|
|
59
|
+
"b",
|
|
60
|
+
"em",
|
|
61
|
+
"i",
|
|
62
|
+
"u",
|
|
63
|
+
"s",
|
|
64
|
+
"del",
|
|
65
|
+
"ins",
|
|
66
|
+
"mark",
|
|
67
|
+
"small",
|
|
68
|
+
"sub",
|
|
69
|
+
"sup",
|
|
70
|
+
"code",
|
|
71
|
+
"abbr",
|
|
72
|
+
"cite",
|
|
73
|
+
"q",
|
|
74
|
+
"dfn",
|
|
75
|
+
"kbd",
|
|
76
|
+
"samp",
|
|
77
|
+
"var",
|
|
78
|
+
"time",
|
|
79
|
+
"data",
|
|
80
|
+
"bdi",
|
|
81
|
+
"bdo",
|
|
82
|
+
] as const
|
|
83
|
+
|
|
84
|
+
/** Elements whose words are a block of text even when empty: an empty one takes typing. */
|
|
85
|
+
export const PAGE_TEXT_TAGS: ReadonlySet<string> = new Set([
|
|
86
|
+
"p",
|
|
87
|
+
"h1",
|
|
88
|
+
"h2",
|
|
89
|
+
"h3",
|
|
90
|
+
"h4",
|
|
91
|
+
"h5",
|
|
92
|
+
"h6",
|
|
93
|
+
"li",
|
|
94
|
+
"td",
|
|
95
|
+
"th",
|
|
96
|
+
"dt",
|
|
97
|
+
"dd",
|
|
98
|
+
"figcaption",
|
|
99
|
+
"blockquote",
|
|
100
|
+
"caption",
|
|
101
|
+
"pre",
|
|
102
|
+
"summary",
|
|
103
|
+
"legend",
|
|
104
|
+
"address",
|
|
105
|
+
])
|
|
106
|
+
|
|
107
|
+
/** Elements that are never edited inside: what they show is not words. */
|
|
108
|
+
const OPAQUE = new Set([
|
|
109
|
+
"script",
|
|
110
|
+
"style",
|
|
111
|
+
"template",
|
|
112
|
+
"noscript",
|
|
113
|
+
"svg",
|
|
114
|
+
"math",
|
|
115
|
+
"canvas",
|
|
116
|
+
"video",
|
|
117
|
+
"audio",
|
|
118
|
+
"iframe",
|
|
119
|
+
"object",
|
|
120
|
+
"embed",
|
|
121
|
+
"picture",
|
|
122
|
+
"select",
|
|
123
|
+
"textarea",
|
|
124
|
+
"input",
|
|
125
|
+
"button",
|
|
126
|
+
"form",
|
|
127
|
+
"hr",
|
|
128
|
+
"colgroup",
|
|
129
|
+
"col",
|
|
130
|
+
"wbr",
|
|
131
|
+
"br",
|
|
132
|
+
])
|
|
133
|
+
|
|
134
|
+
/** Elements that sit among words: inline content, as HTML lays it out. */
|
|
135
|
+
const PHRASING = new Set([
|
|
136
|
+
...PAGE_MARK_TAGS,
|
|
137
|
+
"br",
|
|
138
|
+
"wbr",
|
|
139
|
+
"img",
|
|
140
|
+
"svg",
|
|
141
|
+
"math",
|
|
142
|
+
"input",
|
|
143
|
+
"button",
|
|
144
|
+
"select",
|
|
145
|
+
"textarea",
|
|
146
|
+
"label",
|
|
147
|
+
"output",
|
|
148
|
+
"meter",
|
|
149
|
+
"progress",
|
|
150
|
+
"picture",
|
|
151
|
+
"canvas",
|
|
152
|
+
"video",
|
|
153
|
+
"audio",
|
|
154
|
+
"iframe",
|
|
155
|
+
"object",
|
|
156
|
+
"embed",
|
|
157
|
+
"font",
|
|
158
|
+
"nobr",
|
|
159
|
+
"ruby",
|
|
160
|
+
"rt",
|
|
161
|
+
"rp",
|
|
162
|
+
"slot",
|
|
163
|
+
])
|
|
164
|
+
|
|
165
|
+
const MARK_RANK: ReadonlyMap<string, number> = new Map(PAGE_MARK_TAGS.map((tag, at) => [tag, at]))
|
|
166
|
+
|
|
167
|
+
/** Whitespace as HTML collapses it: not the no-break space. */
|
|
168
|
+
const COLLAPSIBLE = /[ \t\n\r\f]+/g
|
|
169
|
+
|
|
170
|
+
// ── Source → blocks ─────────────────────────────────────────────────────
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* A page's blocks, or null when its source is not one an editor can hold whole: no `<body>` tag
|
|
174
|
+
* of its own, or markup the parser moved about at its top level.
|
|
175
|
+
*/
|
|
176
|
+
export function pageBlocks(source: string): PageBlocks | null {
|
|
177
|
+
const document = parse(source, { sourceCodeLocationInfo: true })
|
|
178
|
+
const html = document.childNodes.find(isElement)
|
|
179
|
+
const body = html?.childNodes.find(
|
|
180
|
+
(child): child is Element => isElement(child) && child.tagName === "body"
|
|
181
|
+
)
|
|
182
|
+
const start = body?.sourceCodeLocation?.startTag?.endOffset
|
|
183
|
+
if (!body || start === undefined) return null
|
|
184
|
+
|
|
185
|
+
const children = body.childNodes
|
|
186
|
+
for (const child of children) {
|
|
187
|
+
const location = child.sourceCodeLocation
|
|
188
|
+
if (!location || location.startOffset < start) return null
|
|
189
|
+
}
|
|
190
|
+
// The parser moves what follows `</body>` into the body: nothing but whitespace, which ends up
|
|
191
|
+
// in the tail, may sit past it.
|
|
192
|
+
const end = body.sourceCodeLocation?.endTag?.startOffset
|
|
193
|
+
const past = (child: ChildNode) =>
|
|
194
|
+
end !== undefined && endOf(child) > end && !(isText(child) && child.value.trim() === "")
|
|
195
|
+
if (children.some(past)) return null
|
|
196
|
+
|
|
197
|
+
const read = childBlocks(children, source, start, { stray: true })
|
|
198
|
+
if (!read) return null
|
|
199
|
+
const page = {
|
|
200
|
+
head: source.slice(0, start),
|
|
201
|
+
blocks: read.blocks,
|
|
202
|
+
tail: source.slice(start + read.length - read.trailing.length),
|
|
203
|
+
}
|
|
204
|
+
// Each block came back as its source; the whole page must too.
|
|
205
|
+
return pageHtml(page) === source ? page : null
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* The blocks among `children`, which start at `from` in the source: the whitespace between them
|
|
210
|
+
* goes to the block after it, and what follows the last is `trailing`. Words among blocks make
|
|
211
|
+
* the children unreadable as blocks, unless `stray` reads each run of them as a raw block.
|
|
212
|
+
*/
|
|
213
|
+
function childBlocks(
|
|
214
|
+
children: readonly ChildNode[],
|
|
215
|
+
source: string,
|
|
216
|
+
from: number,
|
|
217
|
+
options: { readonly stray: boolean }
|
|
218
|
+
): { blocks: BlockNode[]; trailing: string; length: number } | null {
|
|
219
|
+
const blocks: BlockNode[] = []
|
|
220
|
+
let at = from
|
|
221
|
+
let before = ""
|
|
222
|
+
let stray = null as { start: number; end: number } | null
|
|
223
|
+
const flushStray = () => {
|
|
224
|
+
if (!stray) return
|
|
225
|
+
blocks.push(rawBlock(source.slice(stray.start, stray.end), before))
|
|
226
|
+
before = ""
|
|
227
|
+
stray = null
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
for (const child of children) {
|
|
231
|
+
const start = startOf(child)
|
|
232
|
+
const end = endOf(child)
|
|
233
|
+
if (start !== at) return null
|
|
234
|
+
at = end
|
|
235
|
+
|
|
236
|
+
if (isText(child)) {
|
|
237
|
+
if (child.value.trim() === "" && !stray) {
|
|
238
|
+
before += source.slice(start, end)
|
|
239
|
+
continue
|
|
240
|
+
}
|
|
241
|
+
if (!options.stray) return null
|
|
242
|
+
stray = { start: stray?.start ?? start, end }
|
|
243
|
+
continue
|
|
244
|
+
}
|
|
245
|
+
if (stray) {
|
|
246
|
+
if (!options.stray) return null
|
|
247
|
+
flushStray()
|
|
248
|
+
}
|
|
249
|
+
const block = blockOf(child, source, before)
|
|
250
|
+
if (!block) return null
|
|
251
|
+
blocks.push(block)
|
|
252
|
+
before = ""
|
|
253
|
+
}
|
|
254
|
+
flushStray()
|
|
255
|
+
return { blocks, trailing: before, length: at - from }
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** A node among blocks as a block. */
|
|
259
|
+
function blockOf(node: ChildNode, source: string, before: string): BlockNode | null {
|
|
260
|
+
const slice = source.slice(startOf(node), endOf(node))
|
|
261
|
+
if (!isElement(node)) return rawBlock(slice, before)
|
|
262
|
+
|
|
263
|
+
const tag = node.tagName
|
|
264
|
+
const location = node.sourceCodeLocation
|
|
265
|
+
if (!location?.startTag || !locatedThroughout(node) || isOpaque(node)) {
|
|
266
|
+
return rawBlock(slice, before)
|
|
267
|
+
}
|
|
268
|
+
if (tag === "img") return { type: "image", attrs: { source: slice, before } }
|
|
269
|
+
|
|
270
|
+
const open = source.slice(location.startTag.startOffset, location.startTag.endOffset)
|
|
271
|
+
const close = location.endTag
|
|
272
|
+
? source.slice(location.endTag.startOffset, location.endTag.endOffset)
|
|
273
|
+
: ""
|
|
274
|
+
const innerStart = location.startTag.endOffset
|
|
275
|
+
const innerEnd = location.endTag?.startOffset ?? endOf(node)
|
|
276
|
+
const inner = source.slice(innerStart, innerEnd)
|
|
277
|
+
const empty = node.childNodes.every((child) => isText(child) && child.value.trim() === "")
|
|
278
|
+
|
|
279
|
+
// Words, with what formats them: a block of text, unless it holds no words, only pictures.
|
|
280
|
+
if (!empty || PAGE_TEXT_TAGS.has(tag)) {
|
|
281
|
+
const content = inlineOf(node.childNodes, source, tag === "pre")
|
|
282
|
+
const words = content?.some((each) => each.type === "text" && /[^ ]/.test(each.text ?? ""))
|
|
283
|
+
if (content && (words || PAGE_TEXT_TAGS.has(tag))) {
|
|
284
|
+
const block: BlockNode = {
|
|
285
|
+
type: "textBlock",
|
|
286
|
+
attrs: { tag, open, close, before, inner },
|
|
287
|
+
...(content.length > 0 ? { content } : {}),
|
|
288
|
+
}
|
|
289
|
+
// Read alone, its words must read as they did in the page.
|
|
290
|
+
return innerOf(block, tag) === inner ? block : rawBlock(slice, before)
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
if (empty) return rawBlock(slice, before)
|
|
294
|
+
|
|
295
|
+
// Blocks: each written back as its source, or the whole is raw.
|
|
296
|
+
const read = childBlocks(node.childNodes, source, innerStart, { stray: false })
|
|
297
|
+
if (!read || read.blocks.length === 0) return rawBlock(slice, before)
|
|
298
|
+
const box: BlockNode = {
|
|
299
|
+
type: "box",
|
|
300
|
+
attrs: { tag, open, close, before, end: read.trailing },
|
|
301
|
+
content: read.blocks,
|
|
302
|
+
}
|
|
303
|
+
return writeBlock(box, null) === before + slice ? box : rawBlock(slice, before)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function rawBlock(source: string, before: string): BlockNode {
|
|
307
|
+
return { type: "raw", attrs: { source, before } }
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* The inline content of `children`: words, with their marks, and the line breaks and anything
|
|
312
|
+
* else inline among them, raw; null when a block is among them. Words are spaced as they show,
|
|
313
|
+
* except in `<pre>`.
|
|
314
|
+
*/
|
|
315
|
+
function inlineOf(
|
|
316
|
+
children: readonly ChildNode[],
|
|
317
|
+
source: string,
|
|
318
|
+
pre: boolean
|
|
319
|
+
): BlockNode[] | null {
|
|
320
|
+
const nodes: BlockNode[] = []
|
|
321
|
+
const visit = (each: readonly ChildNode[], marks: readonly BlockMark[]): boolean => {
|
|
322
|
+
for (const child of each) {
|
|
323
|
+
const slice = () => source.slice(startOf(child), endOf(child))
|
|
324
|
+
if (isText(child)) {
|
|
325
|
+
nodes.push(textNode(child.value, marks))
|
|
326
|
+
continue
|
|
327
|
+
}
|
|
328
|
+
if (!isElement(child)) {
|
|
329
|
+
// A comment shows nothing: it parts no words.
|
|
330
|
+
nodes.push({ type: "rawInline", attrs: { source: slice(), hidden: true } })
|
|
331
|
+
continue
|
|
332
|
+
}
|
|
333
|
+
const tag = child.tagName
|
|
334
|
+
const location = child.sourceCodeLocation
|
|
335
|
+
if (!location?.startTag || (!PHRASING.has(tag) && !isCustom(tag))) return false
|
|
336
|
+
if (!locatedThroughout(child)) return false
|
|
337
|
+
if (tag === "br") {
|
|
338
|
+
nodes.push({ type: "hardBreak", attrs: { source: slice() } })
|
|
339
|
+
continue
|
|
340
|
+
}
|
|
341
|
+
const markable =
|
|
342
|
+
MARK_RANK.has(tag) &&
|
|
343
|
+
!isLive(child) &&
|
|
344
|
+
!marks.some((mark) => mark.type === tag) &&
|
|
345
|
+
child.childNodes.length > 0 &&
|
|
346
|
+
holdsOnlyInline(child) &&
|
|
347
|
+
formatsWords(child)
|
|
348
|
+
if (!markable) {
|
|
349
|
+
if (!holdsOnlyInline(child) && !isOpaque(child)) return false
|
|
350
|
+
nodes.push({ type: "rawInline", attrs: { source: slice() } })
|
|
351
|
+
continue
|
|
352
|
+
}
|
|
353
|
+
const open = source.slice(location.startTag.startOffset, location.startTag.endOffset)
|
|
354
|
+
const close = location.endTag
|
|
355
|
+
? source.slice(location.endTag.startOffset, location.endTag.endOffset)
|
|
356
|
+
: ""
|
|
357
|
+
if (!visit(child.childNodes, [...marks, { type: tag, attrs: { open, close } }])) return false
|
|
358
|
+
}
|
|
359
|
+
return true
|
|
360
|
+
}
|
|
361
|
+
if (!visit(children, [])) return null
|
|
362
|
+
return joinTexts(pre ? nodes : collapsed(nodes))
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Whether an inline element formats words alone: text, line breaks, and other marks that do too.
|
|
367
|
+
* The editor keeps marks on words only, so one around a field or a picture, `<a><img></a>`, would
|
|
368
|
+
* lose them once its block is edited: it is kept whole instead. So is a styled one around a mark
|
|
369
|
+
* written outside it, `<span class="badge"><a></a></span>`, which an edit would split in two.
|
|
370
|
+
*/
|
|
371
|
+
function formatsWords(node: Element): boolean {
|
|
372
|
+
// Marks are written in their rank's order: plain ones read the same either way round.
|
|
373
|
+
const rank = node.attrs.length > 0 ? (MARK_RANK.get(node.tagName) ?? -1) : -1
|
|
374
|
+
return node.childNodes.every((child) => {
|
|
375
|
+
if (!isElement(child)) return true
|
|
376
|
+
if (child.tagName === "br") return true
|
|
377
|
+
return (MARK_RANK.get(child.tagName) ?? -1) > rank && !isLive(child) && formatsWords(child)
|
|
378
|
+
})
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/** Whether an element holds inline content alone, all the way down. */
|
|
382
|
+
function holdsOnlyInline(node: Element): boolean {
|
|
383
|
+
if (isOpaque(node)) return true
|
|
384
|
+
return node.childNodes.every((child) => {
|
|
385
|
+
if (!isElement(child)) return true
|
|
386
|
+
return (PHRASING.has(child.tagName) || isCustom(child.tagName)) && holdsOnlyInline(child)
|
|
387
|
+
})
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Words spaced as HTML shows them: each run of whitespace one space, none at the start, before a
|
|
392
|
+
* line break, or at the end. A comment parts nothing; anything else inline is a word.
|
|
393
|
+
*/
|
|
394
|
+
function collapsed(nodes: readonly BlockNode[]): BlockNode[] {
|
|
395
|
+
const out: BlockNode[] = []
|
|
396
|
+
let after = true
|
|
397
|
+
const trimEnd = () => {
|
|
398
|
+
for (let at = out.length - 1; at >= 0; at -= 1) {
|
|
399
|
+
const node = out[at] as BlockNode
|
|
400
|
+
if (node.type === "rawInline" && node.attrs?.hidden) continue
|
|
401
|
+
if (node.type !== "text") return
|
|
402
|
+
const text = (node.text ?? "").replace(/ $/, "")
|
|
403
|
+
out[at] = { ...node, text }
|
|
404
|
+
return
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
for (const node of nodes) {
|
|
408
|
+
if (node.type === "text") {
|
|
409
|
+
let text = (node.text ?? "").replace(COLLAPSIBLE, " ")
|
|
410
|
+
if (after) text = text.replace(/^ /, "")
|
|
411
|
+
if (text === "") continue
|
|
412
|
+
after = text.endsWith(" ")
|
|
413
|
+
out.push({ ...node, text })
|
|
414
|
+
continue
|
|
415
|
+
}
|
|
416
|
+
if (node.type === "hardBreak") {
|
|
417
|
+
trimEnd()
|
|
418
|
+
after = true
|
|
419
|
+
} else if (!(node.type === "rawInline" && node.attrs?.hidden)) {
|
|
420
|
+
after = false
|
|
421
|
+
}
|
|
422
|
+
out.push(node)
|
|
423
|
+
}
|
|
424
|
+
trimEnd()
|
|
425
|
+
return out
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/** Adjacent words with the same marks as one text, as the editor holds them; none empty. */
|
|
429
|
+
function joinTexts(nodes: readonly BlockNode[]): BlockNode[] {
|
|
430
|
+
const out: BlockNode[] = []
|
|
431
|
+
for (const node of nodes) {
|
|
432
|
+
const last = out.at(-1)
|
|
433
|
+
if (node.type === "text" && node.text === "") continue
|
|
434
|
+
if (node.type === "text" && last?.type === "text" && sameMarks(last.marks, node.marks)) {
|
|
435
|
+
out[out.length - 1] = { ...last, text: `${last.text ?? ""}${node.text ?? ""}` }
|
|
436
|
+
continue
|
|
437
|
+
}
|
|
438
|
+
// A comment is no part of what the editor holds.
|
|
439
|
+
out.push(
|
|
440
|
+
node.type === "rawInline" ? { type: node.type, attrs: { source: node.attrs?.source } } : node
|
|
441
|
+
)
|
|
442
|
+
}
|
|
443
|
+
return out
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function textNode(text: string, marks: readonly BlockMark[]): BlockNode {
|
|
447
|
+
return marks.length > 0 ? { type: "text", text, marks } : { type: "text", text }
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// ── Blocks → source ─────────────────────────────────────────────────────
|
|
451
|
+
|
|
452
|
+
/** A page's source: its head, its blocks as they are now, and its tail. */
|
|
453
|
+
export function pageHtml(page: PageBlocks): string {
|
|
454
|
+
return page.head + writeChildren(page.blocks, null) + page.tail
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Blocks as source. A block an editor made has no `before`: it is spaced as the block before it
|
|
459
|
+
* is, or one step in from the box it starts.
|
|
460
|
+
*/
|
|
461
|
+
function writeChildren(blocks: readonly BlockNode[], parentBefore: string | null): string {
|
|
462
|
+
let previous: string | null = null
|
|
463
|
+
let out = ""
|
|
464
|
+
for (const block of blocks) {
|
|
465
|
+
const before: string =
|
|
466
|
+
stringAttr(block, "before") ?? previous ?? (parentBefore ? indented(parentBefore) : "")
|
|
467
|
+
out += writeBlock(block, before)
|
|
468
|
+
previous = before
|
|
469
|
+
}
|
|
470
|
+
return out
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
function writeBlock(block: BlockNode, spaced: string | null): string {
|
|
474
|
+
const before = spaced ?? stringAttr(block, "before") ?? ""
|
|
475
|
+
switch (block.type) {
|
|
476
|
+
case "box": {
|
|
477
|
+
const tag = stringAttr(block, "tag") ?? "div"
|
|
478
|
+
const end = stringAttr(block, "end") ?? (before.includes("\n") ? before : "")
|
|
479
|
+
const children = writeChildren(block.content ?? [], before)
|
|
480
|
+
return `${before}${openOf(block, tag)}${children}${end}${closeOf(block, tag)}`
|
|
481
|
+
}
|
|
482
|
+
case "textBlock": {
|
|
483
|
+
const tag = stringAttr(block, "tag") ?? "p"
|
|
484
|
+
return `${before}${openOf(block, tag)}${innerOf(block, tag)}${closeOf(block, tag)}`
|
|
485
|
+
}
|
|
486
|
+
default:
|
|
487
|
+
return `${before}${stringAttr(block, "source") ?? ""}`
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
function openOf(block: BlockNode, tag: string): string {
|
|
492
|
+
return stringAttr(block, "open") ?? `<${tag}>`
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
function closeOf(block: BlockNode, tag: string): string {
|
|
496
|
+
const close = stringAttr(block, "close")
|
|
497
|
+
return close === null ? `</${tag}>` : close
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/** A text block's words as source: as the source wrote them, while they read the same. */
|
|
501
|
+
function innerOf(block: BlockNode, tag: string): string {
|
|
502
|
+
// The parser drops a newline right after `<pre>`: one the words start with is written twice.
|
|
503
|
+
const words = inlineHtml(block.content ?? [])
|
|
504
|
+
const written = tag === "pre" && /^\r?\n/.test(words) ? `\n${words}` : words
|
|
505
|
+
const inner = stringAttr(block, "inner")
|
|
506
|
+
if (inner !== null && canonicalInner(inner, tag) === written) return inner
|
|
507
|
+
return written
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/** What `inner` reads as, written as the editor would write it; cached, as it is asked often. */
|
|
511
|
+
const canonical = new Map<string, string | null>()
|
|
512
|
+
const CANONICAL_LIMIT = 20_000
|
|
513
|
+
function canonicalInner(inner: string, tag: string): string | null {
|
|
514
|
+
const key = `${tag}\u0000${inner}`
|
|
515
|
+
const known = canonical.get(key)
|
|
516
|
+
if (known !== undefined) {
|
|
517
|
+
// The least recently read goes first.
|
|
518
|
+
canonical.delete(key)
|
|
519
|
+
canonical.set(key, known)
|
|
520
|
+
return known
|
|
521
|
+
}
|
|
522
|
+
if (canonical.size >= CANONICAL_LIMIT) canonical.delete(canonical.keys().next().value as string)
|
|
523
|
+
|
|
524
|
+
const content = wordsOf(inner, tag)
|
|
525
|
+
const html = content ? inlineHtml(content) : null
|
|
526
|
+
const written = html !== null && tag === "pre" && /^\r?\n/.test(html) ? `\n${html}` : html
|
|
527
|
+
canonical.set(key, written)
|
|
528
|
+
return written
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/** The words `inner` holds, read as the inside of a `tag`; null when a block is among them. */
|
|
532
|
+
function wordsOf(inner: string, tag: string): BlockNode[] | null {
|
|
533
|
+
// Read in place, the parser drops a newline right after `<pre>`; read alone, it would not.
|
|
534
|
+
const words = tag === "pre" ? inner.replace(/^\r?\n/, "") : inner
|
|
535
|
+
const context = defaultTreeAdapter.createElement(tag, HTML_NAMESPACE, [])
|
|
536
|
+
const fragment = parseFragment(context, words, { sourceCodeLocationInfo: true })
|
|
537
|
+
return inlineOf(fragment.childNodes, words, tag === "pre")
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/** Inline content as source, each mark opened where it starts and closed where it ends. */
|
|
541
|
+
function inlineHtml(nodes: readonly BlockNode[]): string {
|
|
542
|
+
let out = ""
|
|
543
|
+
let open: BlockMark[] = []
|
|
544
|
+
for (const node of nodes) {
|
|
545
|
+
const marks = sortedMarks(node.type === "text" ? (node.marks ?? []) : [])
|
|
546
|
+
let common = 0
|
|
547
|
+
while (common < open.length && common < marks.length && sameMark(open[common], marks[common])) {
|
|
548
|
+
common += 1
|
|
549
|
+
}
|
|
550
|
+
// Inline atoms close nothing that wraps them: they take the marks around them.
|
|
551
|
+
const keep = node.type === "text" ? common : open.length
|
|
552
|
+
for (const mark of open.slice(keep).reverse()) out += markClose(mark)
|
|
553
|
+
open = open.slice(0, keep)
|
|
554
|
+
if (node.type !== "text") {
|
|
555
|
+
out += stringAttr(node, "source") ?? (node.type === "hardBreak" ? "<br>" : "")
|
|
556
|
+
continue
|
|
557
|
+
}
|
|
558
|
+
for (const mark of marks.slice(common)) out += markOpen(mark)
|
|
559
|
+
open = [...open, ...marks.slice(common)]
|
|
560
|
+
out += escapeText(node.text ?? "")
|
|
561
|
+
}
|
|
562
|
+
for (const mark of open.reverse()) out += markClose(mark)
|
|
563
|
+
return out
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
function markOpen(mark: BlockMark): string {
|
|
567
|
+
const open = mark.attrs?.open
|
|
568
|
+
return typeof open === "string" && open !== "" ? open : `<${mark.type}>`
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
function markClose(mark: BlockMark): string {
|
|
572
|
+
const close = mark.attrs?.close
|
|
573
|
+
return typeof close === "string" && close !== "" ? close : `</${mark.type}>`
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
function sortedMarks(marks: readonly BlockMark[]): BlockMark[] {
|
|
577
|
+
return [...marks].sort(
|
|
578
|
+
(left, right) => (MARK_RANK.get(left.type) ?? 99) - (MARK_RANK.get(right.type) ?? 99)
|
|
579
|
+
)
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
function sameMark(left: BlockMark | undefined, right: BlockMark | undefined): boolean {
|
|
583
|
+
return (
|
|
584
|
+
left !== undefined &&
|
|
585
|
+
right !== undefined &&
|
|
586
|
+
left.type === right.type &&
|
|
587
|
+
left.attrs?.open === right.attrs?.open &&
|
|
588
|
+
left.attrs?.close === right.attrs?.close
|
|
589
|
+
)
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
function sameMarks(
|
|
593
|
+
left: readonly BlockMark[] | undefined,
|
|
594
|
+
right: readonly BlockMark[] | undefined
|
|
595
|
+
): boolean {
|
|
596
|
+
const a = sortedMarks(left ?? [])
|
|
597
|
+
const b = sortedMarks(right ?? [])
|
|
598
|
+
return a.length === b.length && a.every((mark, at) => sameMark(mark, b[at]))
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
function escapeText(text: string): string {
|
|
602
|
+
return text
|
|
603
|
+
.replace(/&/g, "&")
|
|
604
|
+
.replace(/</g, "<")
|
|
605
|
+
.replace(/>/g, ">")
|
|
606
|
+
.replace(/ /g, " ")
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/** One step in from `before`: its last line's indent, and two spaces more. */
|
|
610
|
+
function indented(before: string): string {
|
|
611
|
+
const line = before.lastIndexOf("\n")
|
|
612
|
+
return line < 0 ? "" : `${before.slice(line)} `
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
function stringAttr(node: BlockNode, name: string): string | null {
|
|
616
|
+
const value = node.attrs?.[name]
|
|
617
|
+
return typeof value === "string" ? value : null
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// ── The live page ───────────────────────────────────────────────────────
|
|
621
|
+
|
|
622
|
+
/** The fragment of a live page that holds its blocks. */
|
|
623
|
+
export const PAGE_BODY = "body"
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* A page held live: `{ head, body, tail }`, its blocks a `Y.XmlFragment` its editor's collaboration
|
|
627
|
+
* reads and writes. Null when its source is not one an editor can hold whole.
|
|
628
|
+
*/
|
|
629
|
+
export function pageEntry(source: string): Y.Map<unknown> | null {
|
|
630
|
+
const page = pageBlocks(source)
|
|
631
|
+
if (!page) return null
|
|
632
|
+
const entry = new Y.Map<unknown>()
|
|
633
|
+
const body = new Y.XmlFragment()
|
|
634
|
+
body.insert(0, blocksToY(page.blocks))
|
|
635
|
+
entry.set("head", page.head)
|
|
636
|
+
entry.set(PAGE_BODY, body)
|
|
637
|
+
entry.set("tail", page.tail)
|
|
638
|
+
return entry
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Two blocks are the same when they write the same source, whatever their spacing or the source
|
|
643
|
+
* their words were read from: a paragraph someone typed in reads the same as the source written
|
|
644
|
+
* from it, and stays the element they type in. A box is patched inside when its tags are the same.
|
|
645
|
+
*/
|
|
646
|
+
const PAGE_PATCH = {
|
|
647
|
+
key: (node: BlockNode) => writeBlock(node, ""),
|
|
648
|
+
shell: (node: BlockNode) =>
|
|
649
|
+
`${node.type}\u0000${stringAttr(node, "open")}\u0000${stringAttr(node, "close")}`,
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* Folds two changes of a page's source, `ours` and `theirs` of `base`, block by block, so the
|
|
654
|
+
* page's structure holds: as `mergeBlockLists` merges them, a text block both changed by its
|
|
655
|
+
* words. Null when one of them is not a page an editor holds.
|
|
656
|
+
*/
|
|
657
|
+
export function mergePageSources(
|
|
658
|
+
base: string,
|
|
659
|
+
ours: string | PageBlocks,
|
|
660
|
+
theirs: string
|
|
661
|
+
): string | null {
|
|
662
|
+
const oursHtml = typeof ours === "string" ? ours : pageHtml(ours)
|
|
663
|
+
if (oursHtml === base || oursHtml === theirs) return theirs
|
|
664
|
+
if (theirs === base) return oursHtml
|
|
665
|
+
const [b, o, t] = [
|
|
666
|
+
pageBlocks(base),
|
|
667
|
+
typeof ours === "string" ? pageBlocks(ours) : ours,
|
|
668
|
+
pageBlocks(theirs),
|
|
669
|
+
]
|
|
670
|
+
if (!b || !o || !t) return null
|
|
671
|
+
return pageHtml({
|
|
672
|
+
head: mergeText(b.head, o.head, t.head),
|
|
673
|
+
blocks: mergeBlockLists(b.blocks, o.blocks, t.blocks, { ...PAGE_PATCH, mergeLeaf: mergeWords }),
|
|
674
|
+
tail: mergeText(b.tail, o.tail, t.tail),
|
|
675
|
+
})
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
/** A text block both sides changed, merged by its words; null when it is not one. */
|
|
679
|
+
function mergeWords(base: BlockNode, ours: BlockNode, theirs: BlockNode): BlockNode | null {
|
|
680
|
+
if (theirs.type !== "textBlock") return null
|
|
681
|
+
const tag = stringAttr(theirs, "tag") ?? "p"
|
|
682
|
+
const inner = mergeText(innerOf(base, tag), innerOf(ours, tag), innerOf(theirs, tag))
|
|
683
|
+
const content = wordsOf(inner, tag)
|
|
684
|
+
if (!content) return null
|
|
685
|
+
const merged: BlockNode = {
|
|
686
|
+
type: "textBlock",
|
|
687
|
+
attrs: { ...theirs.attrs, inner },
|
|
688
|
+
...(content.length > 0 ? { content } : {}),
|
|
689
|
+
}
|
|
690
|
+
return innerOf(merged, tag) === inner ? merged : null
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
/** Whether a document's entry is a live page. */
|
|
694
|
+
export function isPageEntry(entry: unknown): entry is Y.Map<unknown> {
|
|
695
|
+
return entry instanceof Y.Map && entry.get(PAGE_BODY) instanceof Y.XmlFragment
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
/** The source a live page holds now. */
|
|
699
|
+
export function pageEntryHtml(entry: Y.Map<unknown>): string {
|
|
700
|
+
return pageHtml(pageEntryBlocks(entry))
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
/** The page a live page holds now, as blocks. */
|
|
704
|
+
export function pageEntryBlocks(entry: Y.Map<unknown>): PageBlocks {
|
|
705
|
+
const body = entry.get(PAGE_BODY) as Y.XmlFragment
|
|
706
|
+
return {
|
|
707
|
+
head: String(entry.get("head") ?? ""),
|
|
708
|
+
blocks: blocksFromY(body.toArray()),
|
|
709
|
+
tail: String(entry.get("tail") ?? ""),
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* Makes a live page hold `source` by the fewest changes to its blocks, as `patchBlocks` makes
|
|
715
|
+
* them. False, changing nothing, when `source` is not one an editor can hold whole.
|
|
716
|
+
*/
|
|
717
|
+
export function patchPageEntry(entry: Y.Map<unknown>, source: string): boolean {
|
|
718
|
+
const page = pageBlocks(source)
|
|
719
|
+
if (!page) return false
|
|
720
|
+
if (entry.get("head") !== page.head) entry.set("head", page.head)
|
|
721
|
+
if (entry.get("tail") !== page.tail) entry.set("tail", page.tail)
|
|
722
|
+
const body = entry.get(PAGE_BODY) as Y.XmlFragment
|
|
723
|
+
patchBlocks(body, page.blocks, PAGE_PATCH)
|
|
724
|
+
respace(body, page.blocks)
|
|
725
|
+
return true
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
/**
|
|
729
|
+
* Gives the blocks a patch kept the spacing `next` writes them with: blocks are compared without
|
|
730
|
+
* it, so the paragraph someone types in stays theirs, but a write that only spaces them anew still
|
|
731
|
+
* reaches the page.
|
|
732
|
+
*/
|
|
733
|
+
function respace(parent: Y.XmlFragment, next: readonly BlockNode[]): void {
|
|
734
|
+
const elements = parent.toArray()
|
|
735
|
+
if (elements.length !== next.length) return
|
|
736
|
+
elements.forEach((element, at) => {
|
|
737
|
+
const block = next[at] as BlockNode
|
|
738
|
+
if (!(element instanceof Y.XmlElement) || element.nodeName !== block.type) return
|
|
739
|
+
for (const name of ["before", "end"]) {
|
|
740
|
+
const value = block.attrs?.[name]
|
|
741
|
+
if (typeof value === "string" && element.getAttribute(name) !== value) {
|
|
742
|
+
element.setAttribute(name, value)
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
if (block.type === "box") respace(element, block.content ?? [])
|
|
746
|
+
})
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
// ── The parse tree ──────────────────────────────────────────────────────
|
|
750
|
+
|
|
751
|
+
const HTML_NAMESPACE =
|
|
752
|
+
"http://www.w3.org/1999/xhtml" as DefaultTreeAdapterTypes.Element["namespaceURI"]
|
|
753
|
+
|
|
754
|
+
function isElement(node: Node): node is Element {
|
|
755
|
+
return "tagName" in node
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
function isText(node: Node): node is DefaultTreeAdapterTypes.TextNode {
|
|
759
|
+
return node.nodeName === "#text"
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
function isCustom(tag: string): boolean {
|
|
763
|
+
return tag.includes("-")
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
/** A field of live data, or an element repeated per item: what it shows is not its words. */
|
|
767
|
+
function isLive(node: Element): boolean {
|
|
768
|
+
return node.attrs.some(
|
|
769
|
+
(attribute) => attribute.name === "data-sixb-field" || attribute.name === "data-sixb-each"
|
|
770
|
+
)
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
function isOpaque(node: Element): boolean {
|
|
774
|
+
return (
|
|
775
|
+
OPAQUE.has(node.tagName) ||
|
|
776
|
+
isCustom(node.tagName) ||
|
|
777
|
+
node.namespaceURI !== HTML_NAMESPACE ||
|
|
778
|
+
isLive(node)
|
|
779
|
+
)
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
/** Whether every node inside an element is where the source has it: none the parser made up. */
|
|
783
|
+
function locatedThroughout(node: Element): boolean {
|
|
784
|
+
return node.childNodes.every(
|
|
785
|
+
(child) =>
|
|
786
|
+
child.sourceCodeLocation !== undefined &&
|
|
787
|
+
child.sourceCodeLocation !== null &&
|
|
788
|
+
(!isElement(child) || locatedThroughout(child))
|
|
789
|
+
)
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
function startOf(node: ChildNode): number {
|
|
793
|
+
return node.sourceCodeLocation?.startOffset ?? -1
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* Where a node ends in the source. An element whose end tag is implied ends with what it holds:
|
|
798
|
+
* the parser would have it end where whatever closed it does, even past `</body>`.
|
|
799
|
+
*/
|
|
800
|
+
function endOf(node: ChildNode): number {
|
|
801
|
+
if (!isElement(node)) return node.sourceCodeLocation?.endOffset ?? -1
|
|
802
|
+
const location = node.sourceCodeLocation
|
|
803
|
+
if (!location) return -1
|
|
804
|
+
if (location.endTag || !location.startTag) return location.endOffset
|
|
805
|
+
const last = node.childNodes.at(-1)
|
|
806
|
+
return last ? Math.max(location.startTag.endOffset, endOf(last)) : location.startTag.endOffset
|
|
807
|
+
}
|