@linked.archi/kernel 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/NOTICE +11 -0
- package/README.md +96 -2
- package/assets/arch-decision/arch-decision-metamodel.ttl +44 -0
- package/assets/arch-decision/arch-decision-onto.ttl +1566 -0
- package/assets/arch-decision/arch-decision-shapes.ttl +582 -0
- package/assets/arch-decision/arch-decision-tax.ttl +129 -0
- package/assets/arch-processes/arch-processes-metamodel.ttl +42 -0
- package/assets/arch-processes/arch-processes-tax.ttl +136 -0
- package/assets/arch-processes/archProcesses-shapes.ttl +189 -0
- package/assets/arch-processes/archProcesses.ttl +953 -0
- package/assets/archimate3/archimate3.2-element-shapes.ttl +379 -0
- package/assets/archimate3/archimate3.2-metamodel.ttl +205 -0
- package/assets/archimate3/archimate3.2-notation.ttl +1503 -0
- package/assets/archimate3/archimate3.2-onto.ttl +1579 -0
- package/assets/archimate3/archimate3.2-presentation-contexts.ttl +90 -0
- package/assets/archimate3/archimate3.2-principle-shapes.ttl +923 -0
- package/assets/archimate3/archimate3.2-questions.ttl +1125 -0
- package/assets/archimate3/archimate3.2-reference-data.ttl +74 -0
- package/assets/archimate3/archimate3.2-relationship-shapes.ttl +30956 -0
- package/assets/archimate3/archimate3.2-relationship-tables.ttl +5992 -0
- package/assets/archimate3/archimate3.2-tax.ttl +724 -0
- package/assets/archimate3/archimate3.2-viewpoint-shapes.ttl +59 -0
- package/assets/archimate3/archimate3.2-viewpoints.ttl +793 -0
- package/assets/archimate3/icons/and-junction.svg +3 -0
- package/assets/archimate3/icons/application-collaboration.svg +22 -0
- package/assets/archimate3/icons/application-component.svg +18 -0
- package/assets/archimate3/icons/application-event.svg +15 -0
- package/assets/archimate3/icons/application-function.svg +14 -0
- package/assets/archimate3/icons/application-interaction.svg +17 -0
- package/assets/archimate3/icons/application-interface.svg +16 -0
- package/assets/archimate3/icons/application-process.svg +14 -0
- package/assets/archimate3/icons/application-service.svg +14 -0
- package/assets/archimate3/icons/artifact.svg +16 -0
- package/assets/archimate3/icons/assessment.svg +17 -0
- package/assets/archimate3/icons/business-actor.svg +22 -0
- package/assets/archimate3/icons/business-collaboration.svg +21 -0
- package/assets/archimate3/icons/business-event.svg +15 -0
- package/assets/archimate3/icons/business-function.svg +14 -0
- package/assets/archimate3/icons/business-interaction.svg +18 -0
- package/assets/archimate3/icons/business-interface.svg +16 -0
- package/assets/archimate3/icons/business-object.svg +14 -0
- package/assets/archimate3/icons/business-process.svg +15 -0
- package/assets/archimate3/icons/business-role.svg +16 -0
- package/assets/archimate3/icons/business-service.svg +14 -0
- package/assets/archimate3/icons/capability.svg +40 -0
- package/assets/archimate3/icons/communication-network.svg +18 -0
- package/assets/archimate3/icons/constraint.svg +18 -0
- package/assets/archimate3/icons/contract.svg +13 -0
- package/assets/archimate3/icons/course-of-action.svg +20 -0
- package/assets/archimate3/icons/data-object.svg +14 -0
- package/assets/archimate3/icons/deliverable.svg +11 -0
- package/assets/archimate3/icons/device.svg +18 -0
- package/assets/archimate3/icons/distribution-network.svg +19 -0
- package/assets/archimate3/icons/driver.svg +24 -0
- package/assets/archimate3/icons/equipment.svg +31 -0
- package/assets/archimate3/icons/facility.svg +16 -0
- package/assets/archimate3/icons/gap.svg +22 -0
- package/assets/archimate3/icons/glyphs/activity.svg +3 -0
- package/assets/archimate3/icons/glyphs/actor.svg +14 -0
- package/assets/archimate3/icons/glyphs/application-component.svg +12 -0
- package/assets/archimate3/icons/glyphs/artifact.svg +9 -0
- package/assets/archimate3/icons/glyphs/assessment.svg +9 -0
- package/assets/archimate3/icons/glyphs/capability.svg +32 -0
- package/assets/archimate3/icons/glyphs/cloud-gear.svg +3 -0
- package/assets/archimate3/icons/glyphs/collaboration.svg +15 -0
- package/assets/archimate3/icons/glyphs/communication-network.svg +12 -0
- package/assets/archimate3/icons/glyphs/constraint.svg +10 -0
- package/assets/archimate3/icons/glyphs/contract.svg +5 -0
- package/assets/archimate3/icons/glyphs/course-of-action.svg +12 -0
- package/assets/archimate3/icons/glyphs/data-object.svg +4 -0
- package/assets/archimate3/icons/glyphs/deliverable.svg +3 -0
- package/assets/archimate3/icons/glyphs/device.svg +10 -0
- package/assets/archimate3/icons/glyphs/distribution-network.svg +11 -0
- package/assets/archimate3/icons/glyphs/driver.svg +16 -0
- package/assets/archimate3/icons/glyphs/equipment.svg +22 -0
- package/assets/archimate3/icons/glyphs/event.svg +6 -0
- package/assets/archimate3/icons/glyphs/facility.svg +7 -0
- package/assets/archimate3/icons/glyphs/function.svg +6 -0
- package/assets/archimate3/icons/glyphs/gap.svg +14 -0
- package/assets/archimate3/icons/glyphs/goal.svg +10 -0
- package/assets/archimate3/icons/glyphs/grouping.svg +4 -0
- package/assets/archimate3/icons/glyphs/interaction.svg +10 -0
- package/assets/archimate3/icons/glyphs/interface.svg +8 -0
- package/assets/archimate3/icons/glyphs/location.svg +6 -0
- package/assets/archimate3/icons/glyphs/material.svg +12 -0
- package/assets/archimate3/icons/glyphs/meaning.svg +3 -0
- package/assets/archimate3/icons/glyphs/node.svg +8 -0
- package/assets/archimate3/icons/glyphs/object.svg +4 -0
- package/assets/archimate3/icons/glyphs/outcome.svg +16 -0
- package/assets/archimate3/icons/glyphs/path.svg +10 -0
- package/assets/archimate3/icons/glyphs/person-silhouette.svg +3 -0
- package/assets/archimate3/icons/glyphs/plateau.svg +8 -0
- package/assets/archimate3/icons/glyphs/principle.svg +12 -0
- package/assets/archimate3/icons/glyphs/process.svg +6 -0
- package/assets/archimate3/icons/glyphs/product.svg +4 -0
- package/assets/archimate3/icons/glyphs/representation.svg +4 -0
- package/assets/archimate3/icons/glyphs/requirement.svg +6 -0
- package/assets/archimate3/icons/glyphs/resource.svg +14 -0
- package/assets/archimate3/icons/glyphs/role.svg +6 -0
- package/assets/archimate3/icons/glyphs/service.svg +6 -0
- package/assets/archimate3/icons/glyphs/stakeholder.svg +6 -0
- package/assets/archimate3/icons/glyphs/system-software.svg +14 -0
- package/assets/archimate3/icons/glyphs/value-stream.svg +3 -0
- package/assets/archimate3/icons/glyphs/value.svg +3 -0
- package/assets/archimate3/icons/glyphs/work-package.svg +4 -0
- package/assets/archimate3/icons/goal.svg +18 -0
- package/assets/archimate3/icons/grouping.svg +12 -0
- package/assets/archimate3/icons/implementation-event.svg +15 -0
- package/assets/archimate3/icons/location.svg +14 -0
- package/assets/archimate3/icons/material.svg +21 -0
- package/assets/archimate3/icons/meaning.svg +11 -0
- package/assets/archimate3/icons/node.svg +14 -0
- package/assets/archimate3/icons/or-junction.svg +3 -0
- package/assets/archimate3/icons/outcome.svg +25 -0
- package/assets/archimate3/icons/path.svg +18 -0
- package/assets/archimate3/icons/plateau.svg +16 -0
- package/assets/archimate3/icons/principle.svg +21 -0
- package/assets/archimate3/icons/product.svg +12 -0
- package/assets/archimate3/icons/representation.svg +12 -0
- package/assets/archimate3/icons/requirement.svg +14 -0
- package/assets/archimate3/icons/resource.svg +23 -0
- package/assets/archimate3/icons/stakeholder.svg +15 -0
- package/assets/archimate3/icons/system-software.svg +22 -0
- package/assets/archimate3/icons/technology-collaboration.svg +22 -0
- package/assets/archimate3/icons/technology-event.svg +15 -0
- package/assets/archimate3/icons/technology-function.svg +14 -0
- package/assets/archimate3/icons/technology-interaction.svg +18 -0
- package/assets/archimate3/icons/technology-interface.svg +16 -0
- package/assets/archimate3/icons/technology-process.svg +14 -0
- package/assets/archimate3/icons/technology-service.svg +14 -0
- package/assets/archimate3/icons/value-stream.svg +11 -0
- package/assets/archimate3/icons/value.svg +11 -0
- package/assets/archimate3/icons/work-package.svg +12 -0
- package/assets/archimate4/archimate4-element-shapes.ttl +404 -0
- package/assets/archimate4/archimate4-metamodel.ttl +179 -0
- package/assets/archimate4/archimate4-notation.ttl +1147 -0
- package/assets/archimate4/archimate4-onto.ttl +1559 -0
- package/assets/archimate4/archimate4-presentation-contexts.ttl +60 -0
- package/assets/archimate4/archimate4-principle-shapes.ttl +893 -0
- package/assets/archimate4/archimate4-questions.ttl +1224 -0
- package/assets/archimate4/archimate4-reference-data.ttl +56 -0
- package/assets/archimate4/archimate4-relationship-shapes.ttl +16920 -0
- package/assets/archimate4/archimate4-relationship-tables.ttl +3200 -0
- package/assets/archimate4/archimate4-tax.ttl +749 -0
- package/assets/archimate4/archimate4-viewpoint-shapes.ttl +55 -0
- package/assets/archimate4/archimate4-viewpoints.ttl +777 -0
- package/assets/archimate4/icons/and-junction.svg +3 -0
- package/assets/archimate4/icons/application-component.svg +18 -0
- package/assets/archimate4/icons/application-interface.svg +16 -0
- package/assets/archimate4/icons/artifact.svg +16 -0
- package/assets/archimate4/icons/assessment.svg +17 -0
- package/assets/archimate4/icons/business-actor.svg +22 -0
- package/assets/archimate4/icons/business-interface.svg +16 -0
- package/assets/archimate4/icons/business-object.svg +14 -0
- package/assets/archimate4/icons/capability.svg +40 -0
- package/assets/archimate4/icons/collaboration.svg +21 -0
- package/assets/archimate4/icons/communication-network.svg +18 -0
- package/assets/archimate4/icons/course-of-action.svg +20 -0
- package/assets/archimate4/icons/data-object.svg +14 -0
- package/assets/archimate4/icons/deliverable.svg +11 -0
- package/assets/archimate4/icons/device.svg +18 -0
- package/assets/archimate4/icons/distribution-network.svg +19 -0
- package/assets/archimate4/icons/driver.svg +24 -0
- package/assets/archimate4/icons/equipment.svg +31 -0
- package/assets/archimate4/icons/event.svg +15 -0
- package/assets/archimate4/icons/facility.svg +16 -0
- package/assets/archimate4/icons/function.svg +13 -0
- package/assets/archimate4/icons/glyphs/activity.svg +3 -0
- package/assets/archimate4/icons/glyphs/actor.svg +14 -0
- package/assets/archimate4/icons/glyphs/application-component.svg +12 -0
- package/assets/archimate4/icons/glyphs/artifact.svg +9 -0
- package/assets/archimate4/icons/glyphs/assessment.svg +9 -0
- package/assets/archimate4/icons/glyphs/capability.svg +32 -0
- package/assets/archimate4/icons/glyphs/cloud-gear.svg +3 -0
- package/assets/archimate4/icons/glyphs/collaboration.svg +15 -0
- package/assets/archimate4/icons/glyphs/communication-network.svg +12 -0
- package/assets/archimate4/icons/glyphs/constraint.svg +10 -0
- package/assets/archimate4/icons/glyphs/contract.svg +5 -0
- package/assets/archimate4/icons/glyphs/course-of-action.svg +12 -0
- package/assets/archimate4/icons/glyphs/data-object.svg +4 -0
- package/assets/archimate4/icons/glyphs/deliverable.svg +3 -0
- package/assets/archimate4/icons/glyphs/device.svg +10 -0
- package/assets/archimate4/icons/glyphs/distribution-network.svg +11 -0
- package/assets/archimate4/icons/glyphs/driver.svg +16 -0
- package/assets/archimate4/icons/glyphs/equipment.svg +22 -0
- package/assets/archimate4/icons/glyphs/event.svg +6 -0
- package/assets/archimate4/icons/glyphs/facility.svg +7 -0
- package/assets/archimate4/icons/glyphs/function.svg +6 -0
- package/assets/archimate4/icons/glyphs/gap.svg +14 -0
- package/assets/archimate4/icons/glyphs/goal.svg +10 -0
- package/assets/archimate4/icons/glyphs/grouping.svg +4 -0
- package/assets/archimate4/icons/glyphs/interaction.svg +10 -0
- package/assets/archimate4/icons/glyphs/interface.svg +8 -0
- package/assets/archimate4/icons/glyphs/location.svg +6 -0
- package/assets/archimate4/icons/glyphs/material.svg +12 -0
- package/assets/archimate4/icons/glyphs/meaning.svg +3 -0
- package/assets/archimate4/icons/glyphs/node.svg +8 -0
- package/assets/archimate4/icons/glyphs/object.svg +4 -0
- package/assets/archimate4/icons/glyphs/outcome.svg +16 -0
- package/assets/archimate4/icons/glyphs/path.svg +10 -0
- package/assets/archimate4/icons/glyphs/person-silhouette.svg +3 -0
- package/assets/archimate4/icons/glyphs/plateau.svg +8 -0
- package/assets/archimate4/icons/glyphs/principle.svg +12 -0
- package/assets/archimate4/icons/glyphs/process.svg +6 -0
- package/assets/archimate4/icons/glyphs/product.svg +4 -0
- package/assets/archimate4/icons/glyphs/representation.svg +4 -0
- package/assets/archimate4/icons/glyphs/requirement.svg +6 -0
- package/assets/archimate4/icons/glyphs/resource.svg +14 -0
- package/assets/archimate4/icons/glyphs/role.svg +6 -0
- package/assets/archimate4/icons/glyphs/service.svg +6 -0
- package/assets/archimate4/icons/glyphs/stakeholder.svg +6 -0
- package/assets/archimate4/icons/glyphs/system-software.svg +14 -0
- package/assets/archimate4/icons/glyphs/value-stream.svg +3 -0
- package/assets/archimate4/icons/glyphs/value.svg +3 -0
- package/assets/archimate4/icons/glyphs/work-package.svg +4 -0
- package/assets/archimate4/icons/goal.svg +18 -0
- package/assets/archimate4/icons/grouping.svg +12 -0
- package/assets/archimate4/icons/location.svg +14 -0
- package/assets/archimate4/icons/material.svg +21 -0
- package/assets/archimate4/icons/meaning.svg +11 -0
- package/assets/archimate4/icons/node.svg +14 -0
- package/assets/archimate4/icons/or-junction.svg +3 -0
- package/assets/archimate4/icons/outcome.svg +25 -0
- package/assets/archimate4/icons/path.svg +18 -0
- package/assets/archimate4/icons/plateau.svg +16 -0
- package/assets/archimate4/icons/principle.svg +21 -0
- package/assets/archimate4/icons/process.svg +15 -0
- package/assets/archimate4/icons/product.svg +12 -0
- package/assets/archimate4/icons/requirement.svg +14 -0
- package/assets/archimate4/icons/resource.svg +23 -0
- package/assets/archimate4/icons/role.svg +16 -0
- package/assets/archimate4/icons/service.svg +13 -0
- package/assets/archimate4/icons/stakeholder.svg +15 -0
- package/assets/archimate4/icons/system-software.svg +22 -0
- package/assets/archimate4/icons/technology-interface.svg +16 -0
- package/assets/archimate4/icons/value-stream.svg +11 -0
- package/assets/archimate4/icons/value.svg +11 -0
- package/assets/archimate4/icons/work-package.svg +12 -0
- package/assets/basic/basic-metamodel.ttl +100 -0
- package/assets/basic/basic-notation-bubble.ttl +175 -0
- package/assets/basic/basic-notation.ttl +172 -0
- package/assets/basic/basic-onto.ttl +171 -0
- package/assets/basic/basic-presentation-contexts.ttl +70 -0
- package/assets/basic/basic-tax.ttl +130 -0
- package/assets/basic/icons/aggregation.svg +7 -0
- package/assets/basic/icons/association.svg +6 -0
- package/assets/basic/icons/element.svg +5 -0
- package/assets/basic/icons/glyphs/aggregation.svg +6 -0
- package/assets/basic/icons/glyphs/association.svg +5 -0
- package/assets/basic/icons/glyphs/element.svg +5 -0
- package/assets/basic/icons/glyphs/relationship.svg +5 -0
- package/assets/basic/icons/relationship.svg +7 -0
- package/assets/basic/notation-bubble/icons/aggregation.svg +7 -0
- package/assets/basic/notation-bubble/icons/association.svg +6 -0
- package/assets/basic/notation-bubble/icons/element.svg +5 -0
- package/assets/basic/notation-bubble/icons/glyphs/aggregation.svg +6 -0
- package/assets/basic/notation-bubble/icons/glyphs/association.svg +5 -0
- package/assets/basic/notation-bubble/icons/glyphs/element.svg +5 -0
- package/assets/basic/notation-bubble/icons/glyphs/relationship.svg +5 -0
- package/assets/basic/notation-bubble/icons/relationship.svg +7 -0
- package/assets/catalog.ttl +7302 -0
- package/assets/core/core-notation.ttl +131 -0
- package/assets/core/core-onto.ttl +2811 -0
- package/assets/core/core-questions.ttl +957 -0
- package/assets/core/core-shapes.ttl +915 -0
- package/assets/core/core-vis-onto.ttl +1408 -0
- package/assets/core/core-vis-shapes.ttl +840 -0
- package/assets/core-vis/markers/circle-dot.svg +3 -0
- package/assets/core-vis/markers/closed-arrowhead.svg +3 -0
- package/assets/core-vis/markers/filled-diamond.svg +3 -0
- package/assets/core-vis/markers/half-arrowhead.svg +3 -0
- package/assets/core-vis/markers/hollow-arrowhead.svg +3 -0
- package/assets/core-vis/markers/hollow-diamond.svg +3 -0
- package/assets/core-vis/markers/open-arrowhead.svg +3 -0
- package/fixtures/interoperability/archimate4-demo.trig +259 -0
- package/fixtures/interoperability/expected-findings.json +26 -0
- package/fixtures/interoperability/shop-seed.ttl +225 -0
- package/package.json +136 -4
- package/scripts/sync-assets.mjs +252 -0
- package/src/conformance.ts +66 -0
- package/src/import-export/model-io.ts +426 -0
- package/src/index.ts +11 -0
- package/src/metamodel-manager/asset-sources.ts +754 -0
- package/src/metamodel-manager/bundled-assets.ts +599 -0
- package/src/metamodel-manager/catalogue.ts +114 -0
- package/src/metamodel-manager/class-hierarchy.ts +155 -0
- package/src/metamodel-manager/index.ts +65 -0
- package/src/metamodel-manager/interfaces.ts +422 -0
- package/src/metamodel-manager/metamodel-completeness.ts +162 -0
- package/src/metamodel-manager/metamodel-loader.ts +864 -0
- package/src/metamodel-manager/notation-resolver.ts +284 -0
- package/src/metamodel-manager/notation.ts +659 -0
- package/src/metamodel-manager/palette-generator.ts +882 -0
- package/src/metamodel-manager/property-shapes.ts +290 -0
- package/src/metamodel-manager/taxonomy.ts +904 -0
- package/src/metamodel-manager/type-guide.ts +241 -0
- package/src/metamodel-manager/viewpoint-manager.ts +147 -0
- package/src/model-manager/appearance.ts +389 -0
- package/src/model-manager/cascade.ts +246 -0
- package/src/model-manager/clipboard.ts +566 -0
- package/src/model-manager/context-names.ts +108 -0
- package/src/model-manager/custom-properties.ts +549 -0
- package/src/model-manager/derivations.ts +166 -0
- package/src/model-manager/direct-permissions.ts +182 -0
- package/src/model-manager/drawing-order.ts +119 -0
- package/src/model-manager/element-manager.ts +69 -0
- package/src/model-manager/element-pictures.ts +118 -0
- package/src/model-manager/field-names.ts +42 -0
- package/src/model-manager/folders.ts +354 -0
- package/src/model-manager/grid.ts +6 -0
- package/src/model-manager/index.ts +43 -0
- package/src/model-manager/interfaces.ts +417 -0
- package/src/model-manager/iri-conformance.ts +183 -0
- package/src/model-manager/label-expression.ts +233 -0
- package/src/model-manager/legacy-migration.ts +200 -0
- package/src/model-manager/missing-references.ts +86 -0
- package/src/model-manager/model-diff-text.ts +150 -0
- package/src/model-manager/model-diff.ts +534 -0
- package/src/model-manager/model-merge.ts +1160 -0
- package/src/model-manager/model-namespace.ts +199 -0
- package/src/model-manager/model-operations.ts +132 -0
- package/src/model-manager/model-queries.ts +616 -0
- package/src/model-manager/model-session.ts +759 -0
- package/src/model-manager/multiplicity.ts +74 -0
- package/src/model-manager/nested-resources.ts +145 -0
- package/src/model-manager/own-metamodel.ts +157 -0
- package/src/model-manager/placement-copy.ts +116 -0
- package/src/model-manager/property-catalog.ts +787 -0
- package/src/model-manager/proposal-order.ts +203 -0
- package/src/model-manager/provenance.ts +396 -0
- package/src/model-manager/questions.ts +470 -0
- package/src/model-manager/rdf-scope.ts +97 -0
- package/src/model-manager/relationship-graph.ts +462 -0
- package/src/model-manager/relationship-manager.ts +962 -0
- package/src/model-manager/relationship-table.ts +189 -0
- package/src/model-manager/relationship-validity.ts +261 -0
- package/src/model-manager/resource-edits.ts +28 -0
- package/src/model-manager/short-hash.ts +104 -0
- package/src/model-manager/snapshot-lines.ts +88 -0
- package/src/model-manager/version-history.ts +205 -0
- package/src/model-manager/view-from-results.ts +81 -0
- package/src/model-manager/view-manager.ts +1410 -0
- package/src/model-manager/vocabulary.ts +279 -0
- package/src/rdf-engine/finding-shape.ts +23 -0
- package/src/rdf-engine/graph-scope.ts +163 -0
- package/src/rdf-engine/index.ts +7 -0
- package/src/rdf-engine/interfaces.ts +144 -0
- package/src/rdf-engine/iri.ts +203 -0
- package/src/rdf-engine/localized-text.ts +13 -0
- package/src/rdf-engine/namespaces.ts +41 -0
- package/src/rdf-engine/observable-store.ts +631 -0
- package/src/rdf-engine/rdf-store.ts +508 -0
- package/src/rdf-engine/shacl-validator.ts +602 -0
- package/src/rdf-engine/shape-reach.ts +140 -0
- package/src/rdf-engine/shape-switches.ts +165 -0
- package/src/rdf-engine/single-valued.ts +219 -0
- package/src/rdf-engine/sparql-constraints.ts +334 -0
- package/src/rdf-engine/term-codec.ts +51 -0
- package/src/rdf-engine/ttl-parser.ts +51 -0
- package/src/rdf-engine/ttl-serializer.ts +79 -0
- package/src/rdf-engine/turtle-writer.ts +284 -0
- package/src/rdf-engine/validation-engine.ts +682 -0
- package/src/rdf-engine/validation-service.ts +184 -0
- package/src/rdf-engine/validation.worker.ts +47 -0
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy and paste, store-side (copy-paste task, `.agents/tasks/copy-paste/`): what is copied, how it is held
|
|
3
|
+
* on the clipboard, and what a paste writes. No canvas here — the canvas says what is selected and where the
|
|
4
|
+
* pointer is, and runs a paste as one recorded change (`recordChange`), then draws what the store holds.
|
|
5
|
+
*
|
|
6
|
+
* ## The copy
|
|
7
|
+
*
|
|
8
|
+
* RDF, not canvas state: each copied concept's own triples — its types, name, definition and other
|
|
9
|
+
* properties, with its folder — each copied relationship's resource and its triple, and each copied
|
|
10
|
+
* placement's triples and what hangs off it (its route, its moved name's label node, its styles, looks and
|
|
11
|
+
* label expressions), as the source view holds them; with where it came from. A placement's nested
|
|
12
|
+
* placements go with it; a link goes when both its ends do.
|
|
13
|
+
*
|
|
14
|
+
* ## The paste
|
|
15
|
+
*
|
|
16
|
+
* Into another view of the model it came from, the same concepts are placed again; into the same view, or
|
|
17
|
+
* another model, new copies are made — unless the mode is forced. A copy keeps its type, name and
|
|
18
|
+
* definition only; in the same model it goes into the original's folder. The placements are read back
|
|
19
|
+
* through a view manager over the copy and placed by the code *Duplicate view* uses (`placement-copy.ts`).
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { DataFactory } from 'n3';
|
|
23
|
+
import type { NamedNode, Quad, Term } from '@rdfjs/types';
|
|
24
|
+
import type { RdfStore, PrefixMap } from '../rdf-engine/interfaces.js';
|
|
25
|
+
import { OxigraphRdfStore } from '../rdf-engine/rdf-store.js';
|
|
26
|
+
import { N3TtlSerializer } from '../rdf-engine/ttl-serializer.js';
|
|
27
|
+
import { NAMESPACES } from '../rdf-engine/namespaces.js';
|
|
28
|
+
import { OxigraphViewManager } from './view-manager.js';
|
|
29
|
+
import { copyPlacements } from './placement-copy.js';
|
|
30
|
+
import { isFolder, membershipQuads } from './folders.js';
|
|
31
|
+
import { AUTO_LAYOUT } from './grid.js';
|
|
32
|
+
import { quadsOf, snapshotOf } from './version-history.js';
|
|
33
|
+
import { IRI, T, dedupe, nn, relationshipClassAmong, triple, tripleTerm } from './vocabulary.js';
|
|
34
|
+
import type { ElementManager, Point, RelationshipManager, ViewManager } from './interfaces.js';
|
|
35
|
+
|
|
36
|
+
/** The default graph: the model. */
|
|
37
|
+
const MODEL_GRAPH = DataFactory.defaultGraph() as unknown as NamedNode;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The type la-gram's copies are put on the clipboard as, beside `text/plain` Turtle — through the
|
|
41
|
+
* browser's copy and paste events, which need no permission and carry it to another la-gram window.
|
|
42
|
+
*/
|
|
43
|
+
export const CLIPBOARD_MIME = 'application/x-la-gram-clipboard+json';
|
|
44
|
+
|
|
45
|
+
/** The envelope's own name and version, so an older or newer la-gram knows what it reads. */
|
|
46
|
+
const ENVELOPE = 'la-gram-clipboard/1';
|
|
47
|
+
|
|
48
|
+
/** Where a copy came from. */
|
|
49
|
+
export interface ClipboardSource {
|
|
50
|
+
modelIri: string;
|
|
51
|
+
namespace?: string;
|
|
52
|
+
/** The view it was copied from; none for a copy from the model tree. */
|
|
53
|
+
viewIri?: string;
|
|
54
|
+
metamodelIris: string[];
|
|
55
|
+
/** la-gram's version, as About says it. */
|
|
56
|
+
version?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** What is copied: concepts, placements, and their triples. */
|
|
60
|
+
export interface ClipboardFragment {
|
|
61
|
+
source: ClipboardSource;
|
|
62
|
+
/** The elements and relationships copied. */
|
|
63
|
+
concepts: string[];
|
|
64
|
+
/** The source view's nodes copied; none from the model tree. */
|
|
65
|
+
nodes: string[];
|
|
66
|
+
/** The source view's links copied. */
|
|
67
|
+
links: string[];
|
|
68
|
+
quads: Quad[];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** What a paste does with the concepts: places them again, or makes new ones; `auto` by the context. */
|
|
72
|
+
export type PasteMode = 'auto' | 'copies' | 'references';
|
|
73
|
+
|
|
74
|
+
export interface PasteTarget {
|
|
75
|
+
modelIri: string;
|
|
76
|
+
viewIri: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface PasteOptions {
|
|
80
|
+
mode?: PasteMode;
|
|
81
|
+
/** Where the copy's top-left goes, in the view's coordinates — the pointer. */
|
|
82
|
+
at?: Point;
|
|
83
|
+
/** Otherwise, how far from where it was copied. */
|
|
84
|
+
offset?: Point;
|
|
85
|
+
/** Into another model, an element whose type no loaded metamodel defines: pasted as it is (`keep`), or left out. */
|
|
86
|
+
unknownTypes?: 'keep' | 'skip';
|
|
87
|
+
/** From the model tree: the size an element of a type is placed at; the default size otherwise. */
|
|
88
|
+
sizeOf?: (typeIri: string) => { width: number; height: number } | undefined;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Why a concept was not pasted, or not as asked. */
|
|
92
|
+
export type PasteNoteReason =
|
|
93
|
+
/** Into another model: its type is in no loaded metamodel, and the modeller chose to leave such out. */
|
|
94
|
+
| 'unknown-type'
|
|
95
|
+
/** Into another model: the target's rules do not permit it between its ends. */
|
|
96
|
+
| 'not-permitted'
|
|
97
|
+
/** An end of it was left out. */
|
|
98
|
+
| 'end-left-out'
|
|
99
|
+
/** Asked as a reference, it is no longer in the model: pasted as a copy. */
|
|
100
|
+
| 'no-longer-in-model';
|
|
101
|
+
|
|
102
|
+
export interface PasteResult {
|
|
103
|
+
/** What the paste did with the concepts. */
|
|
104
|
+
mode: 'copies' | 'references';
|
|
105
|
+
/** References asked for into another model: copies were made. */
|
|
106
|
+
referencesImpossible: boolean;
|
|
107
|
+
/** Elements and relationships made, by the original each copies. */
|
|
108
|
+
copied: Map<string, string>;
|
|
109
|
+
elementsCopied: number;
|
|
110
|
+
relationshipsCopied: number;
|
|
111
|
+
elementsPlaced: number;
|
|
112
|
+
relationshipsPlaced: number;
|
|
113
|
+
/** The placements made — the new selection. */
|
|
114
|
+
nodes: string[];
|
|
115
|
+
links: string[];
|
|
116
|
+
/** Properties of the originals a copy does not keep. */
|
|
117
|
+
propertiesLeftOut: number;
|
|
118
|
+
notes: Array<{ iri: string; reason: PasteNoteReason }>;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** What a copy of a concept keeps of it besides its types: its names and definitions. */
|
|
122
|
+
const KEPT_BY_A_COPY = new Set([IRI.prefLabel, IRI.definition]);
|
|
123
|
+
|
|
124
|
+
/** What places or files a concept: written by the paste itself, never copied as a property. */
|
|
125
|
+
const PLACING = new Set([IRI.inView, IRI.inModel, IRI.dctermsIsPartOf]);
|
|
126
|
+
|
|
127
|
+
/** What a relationship's resource holds as a relationship, rather than as a property. */
|
|
128
|
+
const RELATIONSHIP_STRUCTURE = new Set([IRI.rdfType, IRI.source, IRI.target, IRI.reifies]);
|
|
129
|
+
|
|
130
|
+
/** Types every element or relationship may carry besides its own. */
|
|
131
|
+
const GENERIC_TYPES = new Set([IRI.Element, IRI.ModelConcept, IRI.QualifiedRelationship]);
|
|
132
|
+
|
|
133
|
+
// ── Copying ─────────────────────────────────────────────────────────────
|
|
134
|
+
|
|
135
|
+
/** Whether a resource is a relationship: it has ends. */
|
|
136
|
+
function isRelationship(store: RdfStore, iri: string): boolean {
|
|
137
|
+
return store.getQuads(nn(iri), T.source, null, MODEL_GRAPH).length > 0;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Whether a concept's triple is a relationship statement — the triple of a relationship (its predicate a
|
|
142
|
+
* relationship type's unqualified form, or a relationship reifying it) or the qualified predicate leading to
|
|
143
|
+
* a relationship — rather than a property of the concept.
|
|
144
|
+
*/
|
|
145
|
+
function isRelationshipStatement(store: RdfStore, q: Quad): boolean {
|
|
146
|
+
if (q.object.termType === 'NamedNode' && store.getQuads(q.object, T.source, q.subject as NamedNode, MODEL_GRAPH).length > 0) return true;
|
|
147
|
+
if (store.getQuads(null, T.unqualifiedForm, q.predicate as NamedNode).length > 0) return true;
|
|
148
|
+
return store.getQuads(null, T.reifies, tripleTerm(q.subject, q.predicate, q.object) as NamedNode, MODEL_GRAPH).length > 0;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** The folder a concept is in, either way a folder holds a member. */
|
|
152
|
+
function folderOf(store: RdfStore, iri: string, modelIri: string): string | undefined {
|
|
153
|
+
for (const q of membershipQuads(store, iri, modelIri)) {
|
|
154
|
+
if (q.subject.value === iri && q.predicate.value === IRI.dctermsIsPartOf) return q.object.value;
|
|
155
|
+
if (q.subject.value !== iri && q.subject.termType === 'NamedNode' && isFolder(store, q.subject.value)) return q.subject.value;
|
|
156
|
+
}
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** A concept's triples as a copy holds them: its own, without what places it or relates it, its folder, a relationship's triple. */
|
|
161
|
+
function conceptQuads(store: RdfStore, iri: string, modelIri: string): Quad[] {
|
|
162
|
+
const subject = nn(iri);
|
|
163
|
+
const relationship = isRelationship(store, iri);
|
|
164
|
+
const quads = store
|
|
165
|
+
.getQuads(subject, null, null, MODEL_GRAPH)
|
|
166
|
+
.filter((q) => !PLACING.has(q.predicate.value) && (relationship || !isRelationshipStatement(store, q)));
|
|
167
|
+
const folder = folderOf(store, iri, modelIri);
|
|
168
|
+
if (folder) quads.push(triple(subject, T.dctermsIsPartOf, nn(folder)));
|
|
169
|
+
if (relationship) {
|
|
170
|
+
// Its triple, as it reifies it.
|
|
171
|
+
for (const q of store.getQuads(subject, T.reifies, null, MODEL_GRAPH)) {
|
|
172
|
+
if (q.object.termType !== 'Quad') continue;
|
|
173
|
+
const stated = q.object as unknown as Quad;
|
|
174
|
+
quads.push(triple(stated.subject as NamedNode, stated.predicate as NamedNode, stated.object as NamedNode));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return quads;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* A placement's triples and everything that hangs off it: followed through objects that are blank nodes or
|
|
182
|
+
* named under the placement — `{node}-style`, `{link}-points-0`, `{link}-label` (DD-41, and as la-gram named
|
|
183
|
+
* them before), or `{node}/style`, `{link}/points/0`, `{link}/label` — and through its style, its label
|
|
184
|
+
* expressions, its moved name and its route's cells and points, which may be named otherwise (another
|
|
185
|
+
* tool's, or shared).
|
|
186
|
+
*/
|
|
187
|
+
function placementQuads(store: RdfStore, placementIri: string): Quad[] {
|
|
188
|
+
const FOLLOWED = new Set([IRI.visStyle, IRI.labelExpression, IRI.visLabel, IRI.points, IRI.rdfFirst, IRI.rdfRest]);
|
|
189
|
+
const quads: Quad[] = [];
|
|
190
|
+
const seen = new Set<string>();
|
|
191
|
+
const queue: Term[] = [nn(placementIri)];
|
|
192
|
+
while (queue.length > 0) {
|
|
193
|
+
const subject = queue.shift()!;
|
|
194
|
+
const key = `${subject.termType}:${subject.value}`;
|
|
195
|
+
if (seen.has(key)) continue;
|
|
196
|
+
seen.add(key);
|
|
197
|
+
for (const q of store.getQuads(subject as NamedNode, null, null, MODEL_GRAPH)) {
|
|
198
|
+
quads.push(q);
|
|
199
|
+
const o = q.object;
|
|
200
|
+
const owned =
|
|
201
|
+
o.termType === 'BlankNode' ||
|
|
202
|
+
(o.termType === 'NamedNode' &&
|
|
203
|
+
o.value !== IRI.rdfNil &&
|
|
204
|
+
(o.value.startsWith(`${placementIri}/`) || o.value.startsWith(`${placementIri}-`) || FOLLOWED.has(q.predicate.value)));
|
|
205
|
+
if (owned) queue.push(o);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return quads;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Placements nested in these, at any depth, with them. */
|
|
212
|
+
function withNested(views: ViewManager, viewIri: string, nodeIris: Iterable<string>): Set<string> {
|
|
213
|
+
const nodes = views.getNodes(viewIri);
|
|
214
|
+
const selected = new Set(nodeIris);
|
|
215
|
+
for (let grown = true; grown; ) {
|
|
216
|
+
grown = false;
|
|
217
|
+
for (const node of nodes) {
|
|
218
|
+
if (!selected.has(node.nodeIri) && node.parentNodeIri && selected.has(node.parentNodeIri)) {
|
|
219
|
+
selected.add(node.nodeIri);
|
|
220
|
+
grown = true;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return selected;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Copy what is selected in a view (R1, R3): the nodes, with what is nested in them; every link whose two
|
|
229
|
+
* ends are copied — a node, or a link copied — the concepts they draw, and the triples of all of it.
|
|
230
|
+
*/
|
|
231
|
+
export function copyFromView(
|
|
232
|
+
store: RdfStore,
|
|
233
|
+
views: ViewManager,
|
|
234
|
+
source: ClipboardSource & { viewIri: string },
|
|
235
|
+
selectedNodes: Iterable<string>,
|
|
236
|
+
): ClipboardFragment {
|
|
237
|
+
const viewIri = source.viewIri;
|
|
238
|
+
const nodeSet = withNested(views, viewIri, selectedNodes);
|
|
239
|
+
const nodes = views.getNodes(viewIri).filter((n) => nodeSet.has(n.nodeIri));
|
|
240
|
+
const allLinks = views.getLinks(viewIri);
|
|
241
|
+
const linkSet = new Set<string>();
|
|
242
|
+
for (let grown = true; grown; ) {
|
|
243
|
+
grown = false;
|
|
244
|
+
for (const link of allLinks) {
|
|
245
|
+
if (linkSet.has(link.linkIri)) continue;
|
|
246
|
+
const kept = (end: string) => nodeSet.has(end) || linkSet.has(end);
|
|
247
|
+
if (kept(link.sourceNodeIri) && kept(link.targetNodeIri)) {
|
|
248
|
+
linkSet.add(link.linkIri);
|
|
249
|
+
grown = true;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const links = allLinks.filter((l) => linkSet.has(l.linkIri));
|
|
254
|
+
const concepts = [
|
|
255
|
+
...new Set([...nodes.filter((n) => !n.figure).map((n) => n.elementIri), ...links.filter((l) => !l.connector).map((l) => l.relationshipIri)]),
|
|
256
|
+
];
|
|
257
|
+
const quads: Quad[] = [];
|
|
258
|
+
for (const concept of concepts) quads.push(...conceptQuads(store, concept, source.modelIri));
|
|
259
|
+
for (const placement of [...nodes.map((n) => n.nodeIri), ...links.map((l) => l.linkIri)]) quads.push(...placementQuads(store, placement));
|
|
260
|
+
// The view's own types, so that a view manager over the copy reads its placements back.
|
|
261
|
+
quads.push(...store.getQuads(nn(viewIri), T.rdfType, null, MODEL_GRAPH));
|
|
262
|
+
return { source, concepts, nodes: nodes.map((n) => n.nodeIri), links: links.map((l) => l.linkIri), quads: dedupe(quads) };
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Copy concepts chosen in the model tree (R14), without placements: the elements and relationships chosen,
|
|
267
|
+
* and every relationship between two of the elements.
|
|
268
|
+
*/
|
|
269
|
+
export function copyConcepts(store: RdfStore, source: ClipboardSource, conceptIris: Iterable<string>): ClipboardFragment {
|
|
270
|
+
const chosen = new Set(conceptIris);
|
|
271
|
+
const elements = [...chosen].filter((iri) => !isRelationship(store, iri));
|
|
272
|
+
const elementSet = new Set(elements);
|
|
273
|
+
const between = store
|
|
274
|
+
.getQuads(null, T.source, null, MODEL_GRAPH)
|
|
275
|
+
.filter((q) => elementSet.has(q.object.value) && store.getQuads(q.subject as NamedNode, T.target, null, MODEL_GRAPH).some((t) => elementSet.has(t.object.value)))
|
|
276
|
+
.map((q) => q.subject.value);
|
|
277
|
+
const concepts = [...new Set([...chosen, ...between])];
|
|
278
|
+
const quads = concepts.flatMap((iri) => conceptQuads(store, iri, source.modelIri));
|
|
279
|
+
return { source: { ...source, viewIri: undefined } as ClipboardSource, concepts, nodes: [], links: [], quads: dedupe(quads) };
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// ── On the clipboard ────────────────────────────────────────────────────
|
|
283
|
+
|
|
284
|
+
/** A copy in la-gram's clipboard format: a JSON envelope holding its triples as canonical N-Triples. */
|
|
285
|
+
export function writeFragment(fragment: ClipboardFragment): string {
|
|
286
|
+
const { quads, ...rest } = fragment;
|
|
287
|
+
return JSON.stringify({ format: ENVELOPE, ...rest, ntriples: snapshotOf(quads).join('\n') });
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** A copy back from la-gram's clipboard format; `undefined` for anything else. */
|
|
291
|
+
export function readFragment(text: string): ClipboardFragment | undefined {
|
|
292
|
+
try {
|
|
293
|
+
const data = JSON.parse(text) as Partial<ClipboardFragment> & { format?: string; ntriples?: string };
|
|
294
|
+
if (data.format !== ENVELOPE || !data.source?.modelIri || typeof data.ntriples !== 'string') return undefined;
|
|
295
|
+
const strings = (v: unknown) => (Array.isArray(v) ? v.filter((s): s is string => typeof s === 'string') : []);
|
|
296
|
+
return {
|
|
297
|
+
source: { ...data.source, metamodelIris: strings(data.source.metamodelIris) },
|
|
298
|
+
concepts: strings(data.concepts),
|
|
299
|
+
nodes: strings(data.nodes),
|
|
300
|
+
links: strings(data.links),
|
|
301
|
+
quads: data.ntriples ? quadsOf(data.ntriples.split('\n')) : [],
|
|
302
|
+
};
|
|
303
|
+
} catch {
|
|
304
|
+
return undefined;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* A copy as Turtle, for pasting into a text editor (R4): the model it was copied from written as a saved
|
|
310
|
+
* model is, with the prefixes per kind and per view (DD-41), when `prefixes` names its namespace.
|
|
311
|
+
*/
|
|
312
|
+
export function fragmentTurtle(fragment: ClipboardFragment, prefixes: PrefixMap): string {
|
|
313
|
+
const namespace = fragment.source.namespace;
|
|
314
|
+
const prefix = namespace ? Object.keys(prefixes).find((label) => prefixes[label] === namespace) : undefined;
|
|
315
|
+
return new N3TtlSerializer().serialize(fragment.quads, prefixes, namespace && prefix ? { namespace, prefix } : undefined);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// ── Pasting ─────────────────────────────────────────────────────────────
|
|
319
|
+
|
|
320
|
+
export interface PasteDeps {
|
|
321
|
+
store: RdfStore;
|
|
322
|
+
elements: ElementManager;
|
|
323
|
+
relationships: RelationshipManager;
|
|
324
|
+
views: ViewManager;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/** Whether a type is a class some loaded metamodel defines. */
|
|
328
|
+
function isKnownClass(store: RdfStore, typeIri: string): boolean {
|
|
329
|
+
const type = nn(typeIri);
|
|
330
|
+
return (
|
|
331
|
+
store.getQuads(type, T.rdfType, nn(NAMESPACES.owl + 'Class')).length > 0 ||
|
|
332
|
+
store.getQuads(type, T.rdfType, nn(NAMESPACES.rdfs + 'Class')).length > 0 ||
|
|
333
|
+
store.getQuads(type, nn(NAMESPACES.rdfs + 'subClassOf'), null).length > 0
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* The types of the elements a paste into another model would bring that no loaded metamodel defines —
|
|
339
|
+
* what to ask the modeller about (R9). None into the model the copy came from.
|
|
340
|
+
*/
|
|
341
|
+
export function unknownTypesIn(store: RdfStore, fragment: ClipboardFragment, targetModelIri: string): string[] {
|
|
342
|
+
if (fragment.source.modelIri === targetModelIri) return [];
|
|
343
|
+
const types = new Set<string>();
|
|
344
|
+
const relationships = new Set(fragment.quads.filter((q) => q.predicate.value === IRI.source).map((q) => q.subject.value));
|
|
345
|
+
for (const iri of fragment.concepts) {
|
|
346
|
+
if (relationships.has(iri)) continue;
|
|
347
|
+
const type = elementTypeAmong(fragment.quads.filter((q) => q.subject.value === iri && q.predicate.value === IRI.rdfType).map((q) => q.object.value));
|
|
348
|
+
if (type && !isKnownClass(store, type)) types.add(type);
|
|
349
|
+
}
|
|
350
|
+
return [...types];
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/** An element's own type: the first that is not one every element may carry. */
|
|
354
|
+
function elementTypeAmong(types: string[]): string | undefined {
|
|
355
|
+
return types.find((t) => !GENERIC_TYPES.has(t)) ?? types[0];
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Paste a copy into a view (R5–R10, R14): the concepts placed again or copied, as the mode and the context
|
|
360
|
+
* say, then their placements. Every change goes through the managers; the caller runs it as one recorded
|
|
361
|
+
* change and draws the view again.
|
|
362
|
+
*/
|
|
363
|
+
export function pasteFragment(deps: PasteDeps, fragment: ClipboardFragment, target: PasteTarget, options: PasteOptions = {}): PasteResult {
|
|
364
|
+
const { store, elements, relationships, views } = deps;
|
|
365
|
+
const sameModel = fragment.source.modelIri === target.modelIri;
|
|
366
|
+
const asked = options.mode ?? 'auto';
|
|
367
|
+
const referencesWanted = asked === 'references' || (asked === 'auto' && sameModel && fragment.source.viewIri !== target.viewIri);
|
|
368
|
+
const mode: PasteResult['mode'] = referencesWanted && sameModel ? 'references' : 'copies';
|
|
369
|
+
const result: PasteResult = {
|
|
370
|
+
mode,
|
|
371
|
+
referencesImpossible: asked === 'references' && !sameModel,
|
|
372
|
+
copied: new Map(),
|
|
373
|
+
elementsCopied: 0,
|
|
374
|
+
relationshipsCopied: 0,
|
|
375
|
+
elementsPlaced: 0,
|
|
376
|
+
relationshipsPlaced: 0,
|
|
377
|
+
nodes: [],
|
|
378
|
+
links: [],
|
|
379
|
+
propertiesLeftOut: 0,
|
|
380
|
+
notes: [],
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
const scratch = new OxigraphRdfStore();
|
|
384
|
+
try {
|
|
385
|
+
scratch.addQuads(fragment.quads);
|
|
386
|
+
const own = (iri: string) => scratch.getQuads(nn(iri), null, null, MODEL_GRAPH);
|
|
387
|
+
const typesOf = (iri: string) => scratch.getQuads(nn(iri), T.rdfType, null, MODEL_GRAPH).map((q) => q.object.value);
|
|
388
|
+
const endOf = (iri: string, end: NamedNode) => scratch.getQuads(nn(iri), end, null, MODEL_GRAPH)[0]?.object.value;
|
|
389
|
+
const relationshipSet = new Set(fragment.concepts.filter((iri) => endOf(iri, T.source) !== undefined));
|
|
390
|
+
const elementList = fragment.concepts.filter((iri) => !relationshipSet.has(iri));
|
|
391
|
+
|
|
392
|
+
// What is left out, across models: elements of types no metamodel defines (when so chosen), relationships
|
|
393
|
+
// the target does not permit, and whatever ends on something left out.
|
|
394
|
+
const leftOut = new Set<string>();
|
|
395
|
+
const leave = (iri: string, reason: PasteNoteReason) => {
|
|
396
|
+
if (leftOut.has(iri)) return;
|
|
397
|
+
leftOut.add(iri);
|
|
398
|
+
result.notes.push({ iri, reason });
|
|
399
|
+
};
|
|
400
|
+
if (!sameModel) {
|
|
401
|
+
for (const iri of elementList) {
|
|
402
|
+
const type = elementTypeAmong(typesOf(iri));
|
|
403
|
+
if (options.unknownTypes === 'skip' && (!type || !isKnownClass(store, type))) leave(iri, 'unknown-type');
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
// A concept asked as a reference that is no longer in the model is copied.
|
|
407
|
+
const existing = (iri: string) => store.getQuads(nn(iri), T.inModel, nn(target.modelIri), MODEL_GRAPH).length > 0;
|
|
408
|
+
const copyIt = (iri: string) => mode === 'copies' || !existing(iri);
|
|
409
|
+
for (let changed = true; changed; ) {
|
|
410
|
+
changed = false;
|
|
411
|
+
for (const iri of relationshipSet) {
|
|
412
|
+
if (leftOut.has(iri)) continue;
|
|
413
|
+
const [s, t] = [endOf(iri, T.source)!, endOf(iri, T.target)!];
|
|
414
|
+
const endMissing = (end: string) => leftOut.has(end) || (!fragment.concepts.includes(end) && (!sameModel || !existing(end)));
|
|
415
|
+
if (endMissing(s) || endMissing(t)) {
|
|
416
|
+
leave(iri, 'end-left-out');
|
|
417
|
+
changed = true;
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
if (!sameModel && !relationshipSet.has(s) && !relationshipSet.has(t)) {
|
|
421
|
+
const typeIri = relationshipClassAmong(typesOf(iri));
|
|
422
|
+
const [sourceType, targetType] = [elementTypeAmong(typesOf(s)), elementTypeAmong(typesOf(t))];
|
|
423
|
+
if (typeIri && sourceType && targetType && isKnownClass(store, sourceType) && isKnownClass(store, targetType)) {
|
|
424
|
+
const permitted = relationships.getValidRelationships(sourceType, targetType).some((r) => r.iri === typeIri);
|
|
425
|
+
if (!permitted) {
|
|
426
|
+
leave(iri, 'not-permitted');
|
|
427
|
+
changed = true;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// The elements: copied, or the same.
|
|
435
|
+
const conceptIn = (iri: string) => result.copied.get(iri) ?? iri;
|
|
436
|
+
// The copied relationships' triples, held on their source elements: relationships, not properties.
|
|
437
|
+
const statements = new Set<string>();
|
|
438
|
+
for (const iri of relationshipSet) {
|
|
439
|
+
for (const q of scratch.getQuads(nn(iri), T.reifies, null, MODEL_GRAPH)) {
|
|
440
|
+
if (q.object.termType !== 'Quad') continue;
|
|
441
|
+
const t = q.object as unknown as Quad;
|
|
442
|
+
statements.add(`${t.subject.value} ${t.predicate.value} ${t.object.value}`);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
const keep = (from: string, to: NamedNode, structure: Set<string>) => {
|
|
446
|
+
const add: Quad[] = [];
|
|
447
|
+
for (const q of own(from)) {
|
|
448
|
+
const p = q.predicate.value;
|
|
449
|
+
if (structure.has(p) || PLACING.has(p)) continue;
|
|
450
|
+
if (statements.has(`${q.subject.value} ${p} ${q.object.value}`)) continue;
|
|
451
|
+
if (KEPT_BY_A_COPY.has(p)) add.push(triple(to, q.predicate as NamedNode, q.object as NamedNode));
|
|
452
|
+
else result.propertiesLeftOut++;
|
|
453
|
+
}
|
|
454
|
+
return add;
|
|
455
|
+
};
|
|
456
|
+
for (const iri of elementList) {
|
|
457
|
+
if (leftOut.has(iri)) continue;
|
|
458
|
+
if (!copyIt(iri)) continue;
|
|
459
|
+
if (mode === 'references') result.notes.push({ iri, reason: 'no-longer-in-model' });
|
|
460
|
+
const types = typesOf(iri);
|
|
461
|
+
const copy = elements.createElement(elementTypeAmong(types) ?? IRI.Element, target.modelIri);
|
|
462
|
+
result.copied.set(iri, copy.value);
|
|
463
|
+
result.elementsCopied++;
|
|
464
|
+
const add = types.map((t) => triple(copy, T.rdfType, nn(t)));
|
|
465
|
+
add.push(...keep(iri, copy, new Set([IRI.rdfType])));
|
|
466
|
+
const folder = sameModel ? scratch.getQuads(nn(iri), T.dctermsIsPartOf, null, MODEL_GRAPH)[0]?.object : undefined;
|
|
467
|
+
if (folder && isFolder(store, folder.value)) add.push(triple(copy, T.dctermsIsPartOf, folder as NamedNode));
|
|
468
|
+
store.addQuads(dedupe(add));
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// The relationships: copied between their ends' copies (or the ends themselves), a relationship ending
|
|
472
|
+
// on a relationship after that one.
|
|
473
|
+
let pending = [...relationshipSet].filter((iri) => !leftOut.has(iri) && copyIt(iri));
|
|
474
|
+
for (;;) {
|
|
475
|
+
const waiting = pending.filter((iri) => {
|
|
476
|
+
const [s, t] = [endOf(iri, T.source)!, endOf(iri, T.target)!];
|
|
477
|
+
const ready = (end: string) => !relationshipSet.has(end) || leftOut.has(end) || result.copied.has(end) || !copyIt(end);
|
|
478
|
+
if (!ready(s) || !ready(t)) return true;
|
|
479
|
+
if (mode === 'references') result.notes.push({ iri, reason: 'no-longer-in-model' });
|
|
480
|
+
const types = typesOf(iri);
|
|
481
|
+
const typeIri = relationshipClassAmong(types) ?? IRI.QualifiedRelationship;
|
|
482
|
+
const stated = scratch.getQuads(nn(iri), T.reifies, null, MODEL_GRAPH).map((q) => q.object).find((o) => o.termType === 'Quad') as Quad | undefined;
|
|
483
|
+
const made = relationships.createQualifiedRelationship!({
|
|
484
|
+
typeIri,
|
|
485
|
+
...(stated ? { predicateIri: stated.predicate.value } : {}),
|
|
486
|
+
sourceIri: conceptIn(s),
|
|
487
|
+
targetIri: conceptIn(t),
|
|
488
|
+
modelIri: target.modelIri,
|
|
489
|
+
});
|
|
490
|
+
const copy = nn(made.iri);
|
|
491
|
+
result.copied.set(iri, made.iri);
|
|
492
|
+
result.relationshipsCopied++;
|
|
493
|
+
const add = types.filter((t2) => t2 !== typeIri).map((t2) => triple(copy, T.rdfType, nn(t2)));
|
|
494
|
+
add.push(...keep(iri, copy, RELATIONSHIP_STRUCTURE));
|
|
495
|
+
const folder = sameModel ? scratch.getQuads(nn(iri), T.dctermsIsPartOf, null, MODEL_GRAPH)[0]?.object : undefined;
|
|
496
|
+
if (folder && isFolder(store, folder.value)) add.push(triple(copy, T.dctermsIsPartOf, folder as NamedNode));
|
|
497
|
+
store.addQuads(dedupe(add));
|
|
498
|
+
return false;
|
|
499
|
+
});
|
|
500
|
+
if (waiting.length === 0 || waiting.length === pending.length) break;
|
|
501
|
+
pending = waiting;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// The placements.
|
|
505
|
+
const leftOutPlacement = (concept: string) => leftOut.has(concept);
|
|
506
|
+
if (fragment.nodes.length > 0 && fragment.source.viewIri) {
|
|
507
|
+
const source = new OxigraphViewManager(scratch);
|
|
508
|
+
const sourceView = fragment.source.viewIri;
|
|
509
|
+
const nodes = source.getNodes(sourceView).filter((n) => fragment.nodes.includes(n.nodeIri) && (n.figure || !leftOutPlacement(n.elementIri)));
|
|
510
|
+
const links = source.getLinks(sourceView).filter((l) => fragment.links.includes(l.linkIri) && (l.connector || !leftOutPlacement(l.relationshipIri)));
|
|
511
|
+
let offset = options.offset ?? { x: 0, y: 0 };
|
|
512
|
+
if (options.at && nodes.length > 0) {
|
|
513
|
+
const x = Math.min(...nodes.map((n) => n.bounds.x));
|
|
514
|
+
const y = Math.min(...nodes.map((n) => n.bounds.y));
|
|
515
|
+
offset = { x: options.at.x - x, y: options.at.y - y };
|
|
516
|
+
}
|
|
517
|
+
const placed = copyPlacements(source, sourceView, views, target.viewIri, {
|
|
518
|
+
nodes: new Set(nodes.map((n) => n.nodeIri)),
|
|
519
|
+
links: new Set(links.map((l) => l.linkIri)),
|
|
520
|
+
concept: conceptIn,
|
|
521
|
+
offset,
|
|
522
|
+
});
|
|
523
|
+
result.nodes = [...placed.nodes.values()];
|
|
524
|
+
result.links = [...placed.links.values()];
|
|
525
|
+
result.elementsPlaced = nodes.filter((n) => !n.figure && placed.nodes.has(n.nodeIri)).length;
|
|
526
|
+
result.relationshipsPlaced = links.filter((l) => !l.connector && placed.links.has(l.linkIri)).length;
|
|
527
|
+
} else {
|
|
528
|
+
// From the model tree: the elements in rows of six from where the copy goes, then the relationships
|
|
529
|
+
// whose two ends were placed.
|
|
530
|
+
const at = options.at ?? { x: AUTO_LAYOUT.x0, y: AUTO_LAYOUT.y0 };
|
|
531
|
+
const placedNodes = new Map<string, string>();
|
|
532
|
+
elementList
|
|
533
|
+
.filter((iri) => !leftOut.has(iri))
|
|
534
|
+
.forEach((iri, i) => {
|
|
535
|
+
const size = options.sizeOf?.(elementTypeAmong(typesOf(iri)) ?? IRI.Element) ?? { width: AUTO_LAYOUT.width, height: AUTO_LAYOUT.height };
|
|
536
|
+
const bounds = {
|
|
537
|
+
x: at.x + (i % AUTO_LAYOUT.columns) * AUTO_LAYOUT.dx,
|
|
538
|
+
y: at.y + Math.floor(i / AUTO_LAYOUT.columns) * AUTO_LAYOUT.dy,
|
|
539
|
+
...size,
|
|
540
|
+
};
|
|
541
|
+
placedNodes.set(iri, views.addElementToView(target.viewIri, conceptIn(iri), bounds, { another: true }));
|
|
542
|
+
});
|
|
543
|
+
const placedLinks = new Map<string, string>();
|
|
544
|
+
let waiting = [...relationshipSet].filter((iri) => !leftOut.has(iri));
|
|
545
|
+
for (;;) {
|
|
546
|
+
const still = waiting.filter((iri) => {
|
|
547
|
+
const end = (e: string) => placedNodes.get(e) ?? placedLinks.get(e);
|
|
548
|
+
const [sourceNodeIri, targetNodeIri] = [end(endOf(iri, T.source)!), end(endOf(iri, T.target)!)];
|
|
549
|
+
if (!sourceNodeIri || !targetNodeIri) return true;
|
|
550
|
+
const link = views.addRelationshipToView(target.viewIri, conceptIn(iri), undefined, { sourceNodeIri, targetNodeIri }, { another: true });
|
|
551
|
+
if (link) placedLinks.set(iri, link);
|
|
552
|
+
return false;
|
|
553
|
+
});
|
|
554
|
+
if (still.length === 0 || still.length === waiting.length) break;
|
|
555
|
+
waiting = still;
|
|
556
|
+
}
|
|
557
|
+
result.nodes = [...placedNodes.values()];
|
|
558
|
+
result.links = [...placedLinks.values()];
|
|
559
|
+
result.elementsPlaced = placedNodes.size;
|
|
560
|
+
result.relationshipsPlaced = placedLinks.size;
|
|
561
|
+
}
|
|
562
|
+
return result;
|
|
563
|
+
} finally {
|
|
564
|
+
scratch.dispose();
|
|
565
|
+
}
|
|
566
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Names for an audience (core 0.5.0): what an element is called in one
|
|
3
|
+
* presentation context, beside its canonical `skos:prefLabel`.
|
|
4
|
+
*
|
|
5
|
+
* A name is a SKOS-XL label — `skosxl:Label`, its text `skosxl:literalForm`,
|
|
6
|
+
* language tagged, `arch:inPresentationContext` the context — given to the
|
|
7
|
+
* element as `skosxl:altLabel`, never `skosxl:prefLabel` (that would be a
|
|
8
|
+
* second canonical name). Its literal form is also written as the element's
|
|
9
|
+
* plain `skos:altLabel`, so that tools reading plain SKOS find it. The label is
|
|
10
|
+
* named after the element and the context (`{element}/name/{hash}`, DD-41), so
|
|
11
|
+
* that a merge can match it; an element has one name per context and language.
|
|
12
|
+
* A label named as la-gram named it before (`{element}-name-{hash}`) keeps its
|
|
13
|
+
* name when its text changes.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { DataFactory } from 'n3';
|
|
17
|
+
import type { NamedNode, Quad, Term } from '@rdfjs/types';
|
|
18
|
+
import type { RdfStore } from '../rdf-engine/interfaces.js';
|
|
19
|
+
import { isPartNamed, partIri } from '../rdf-engine/iri.js';
|
|
20
|
+
import { shortHash } from './short-hash.js';
|
|
21
|
+
import { T, netChange } from './vocabulary.js';
|
|
22
|
+
|
|
23
|
+
const { namedNode, literal, quad } = DataFactory;
|
|
24
|
+
|
|
25
|
+
/** One name an element has for one presentation context. */
|
|
26
|
+
export interface ContextName {
|
|
27
|
+
context: string;
|
|
28
|
+
name: string;
|
|
29
|
+
/** The name's language; '' for none. */
|
|
30
|
+
language: string;
|
|
31
|
+
/** The SKOS-XL label that holds it. */
|
|
32
|
+
label: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Every name `iri` has for a presentation context. */
|
|
36
|
+
export function contextNamesOf(store: RdfStore, iri: string): ContextName[] {
|
|
37
|
+
const names: ContextName[] = [];
|
|
38
|
+
for (const link of store.getQuads(namedNode(iri) as never, T.skosxlAltLabel as never)) {
|
|
39
|
+
const label = link.object;
|
|
40
|
+
if (label.termType === 'Literal') continue;
|
|
41
|
+
const context = store.getQuads(label as never, T.inPresentationContext as never)[0]?.object.value;
|
|
42
|
+
if (!context) continue;
|
|
43
|
+
for (const form of store.getQuads(label as never, T.skosxlLiteralForm as never)) {
|
|
44
|
+
if (form.object.termType !== 'Literal') continue;
|
|
45
|
+
names.push({ context, name: form.object.value, language: (form.object as { language?: string }).language ?? '', label: label.value });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return names;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** `iri`'s name for `context`: in `language`, else in none, else in any — `undefined` when it has none. */
|
|
52
|
+
export function contextNameOf(store: RdfStore, iri: string, context: string | undefined, language = 'en'): string | undefined {
|
|
53
|
+
if (!context) return undefined;
|
|
54
|
+
const names = contextNamesOf(store, iri).filter((n) => n.context === context);
|
|
55
|
+
return (names.find((n) => n.language === language) ?? names.find((n) => n.language === '') ?? names[0])?.name;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The IRI of `iri`'s name for `context` in `language`: `{iri}/name/{hash}`, then `/{language}` when it is not English. */
|
|
59
|
+
export function contextNameIri(iri: string, context: string, language: string): string {
|
|
60
|
+
return partIri(iri, 'name', shortHash(context), ...(language && language !== 'en' ? [language] : []));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** A presentation context's key and, after it, a language: what follows `name` in a name's IRI, either form. */
|
|
64
|
+
const NAME_KEY = /[0-9a-f]{8}(?:[-/][A-Za-z0-9-]+)?/;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* What changes to give `iri` the name `name` for `context` in `language` —
|
|
68
|
+
* or, `null` or empty, to take it away: the label it has for that context and
|
|
69
|
+
* language goes, with its plain `skos:altLabel` unless another of its names
|
|
70
|
+
* has that text too.
|
|
71
|
+
*/
|
|
72
|
+
export function contextNameChange(
|
|
73
|
+
store: RdfStore,
|
|
74
|
+
iri: string,
|
|
75
|
+
context: string,
|
|
76
|
+
name: string | null,
|
|
77
|
+
language = 'en',
|
|
78
|
+
): { remove: Quad[]; add: Quad[] } {
|
|
79
|
+
const element = namedNode(iri);
|
|
80
|
+
const remove: Quad[] = [];
|
|
81
|
+
const names = contextNamesOf(store, iri);
|
|
82
|
+
const replaced = names.filter((n) => n.context === context && n.language === language);
|
|
83
|
+
const kept = names.filter((n) => !replaced.includes(n));
|
|
84
|
+
for (const old of replaced) {
|
|
85
|
+
const label = namedNode(old.label);
|
|
86
|
+
remove.push(...(store.getQuads(element as never, T.skosxlAltLabel as never, label as never) as Quad[]));
|
|
87
|
+
remove.push(...(store.getQuads(label as never) as Quad[]));
|
|
88
|
+
// Its plain form goes too, unless another of its names says the same.
|
|
89
|
+
if (!kept.some((n) => n.name === old.name && n.language === old.language)) {
|
|
90
|
+
remove.push(...(store.getQuads(element as never, T.altLabel as never, literal(old.name, old.language || undefined) as never) as Quad[]));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const text = name?.trim() ?? '';
|
|
94
|
+
if (text === '') return { remove, add: [] };
|
|
95
|
+
// The label it replaces keeps its name when it is the element's own, either way it was named.
|
|
96
|
+
const own = replaced.find((n) => isPartNamed(iri, n.label, 'name', NAME_KEY));
|
|
97
|
+
const label = namedNode(own?.label ?? contextNameIri(iri, context, language));
|
|
98
|
+
const form = literal(text, language || undefined);
|
|
99
|
+
const add: Quad[] = [
|
|
100
|
+
quad(element, T.skosxlAltLabel as NamedNode, label) as Quad,
|
|
101
|
+
quad(label, T.rdfType as NamedNode, T.skosxlLabel as Term as NamedNode) as Quad,
|
|
102
|
+
quad(label, T.skosxlLiteralForm as NamedNode, form) as Quad,
|
|
103
|
+
quad(label, T.inPresentationContext as NamedNode, namedNode(context)) as Quad,
|
|
104
|
+
quad(element, T.altLabel as NamedNode, form) as Quad,
|
|
105
|
+
];
|
|
106
|
+
// A label that keeps its name changes only in what differs.
|
|
107
|
+
return netChange({ remove, add });
|
|
108
|
+
}
|